Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0+
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * Standard Hot Plug Controller Driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * Copyright (C) 1995,2001 Compaq Computer Corporation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  * Copyright (C) 2001 Greg Kroah-Hartman (greg@kroah.com)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  * Copyright (C) 2001 IBM Corp.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  * Copyright (C) 2003-2004 Intel Corporation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10)  * All rights reserved.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12)  * Send feedback to <greg@kroah.com>, <kristen.c.accardi@intel.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #include <linux/pci.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #include "../pci.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) #include "shpchp.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) static void interrupt_event_handler(struct work_struct *work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) static int shpchp_enable_slot(struct slot *p_slot);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) static int shpchp_disable_slot(struct slot *p_slot);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) static int queue_interrupt_event(struct slot *p_slot, u32 event_type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 	struct event_info *info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 	info = kmalloc(sizeof(*info), GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 	if (!info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 	info->event_type = event_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 	info->p_slot = p_slot;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 	INIT_WORK(&info->work, interrupt_event_handler);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 	queue_work(p_slot->wq, &info->work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) u8 shpchp_handle_attention_button(u8 hp_slot, struct controller *ctrl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 	struct slot *p_slot;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	u32 event_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 	/* Attention Button Change */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 	ctrl_dbg(ctrl, "Attention button interrupt received\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	p_slot = shpchp_find_slot(ctrl, hp_slot + ctrl->slot_device_offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	p_slot->hpc_ops->get_adapter_status(p_slot, &(p_slot->presence_save));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	 *  Button pressed - See if need to TAKE ACTION!!!
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	ctrl_info(ctrl, "Button pressed on Slot(%s)\n", slot_name(p_slot));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	event_type = INT_BUTTON_PRESS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	queue_interrupt_event(p_slot, event_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) u8 shpchp_handle_switch_change(u8 hp_slot, struct controller *ctrl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	struct slot *p_slot;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	u8 getstatus;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	u32 event_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	/* Switch Change */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	ctrl_dbg(ctrl, "Switch interrupt received\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	p_slot = shpchp_find_slot(ctrl, hp_slot + ctrl->slot_device_offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	p_slot->hpc_ops->get_adapter_status(p_slot, &(p_slot->presence_save));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	p_slot->hpc_ops->get_latch_status(p_slot, &getstatus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 	ctrl_dbg(ctrl, "Card present %x Power status %x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 		 p_slot->presence_save, p_slot->pwr_save);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	if (getstatus) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 		 * Switch opened
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 		ctrl_info(ctrl, "Latch open on Slot(%s)\n", slot_name(p_slot));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 		event_type = INT_SWITCH_OPEN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 		if (p_slot->pwr_save && p_slot->presence_save) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 			event_type = INT_POWER_FAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 			ctrl_err(ctrl, "Surprise Removal of card\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 		 *  Switch closed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 		ctrl_info(ctrl, "Latch close on Slot(%s)\n", slot_name(p_slot));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 		event_type = INT_SWITCH_CLOSE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 	queue_interrupt_event(p_slot, event_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) u8 shpchp_handle_presence_change(u8 hp_slot, struct controller *ctrl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	struct slot *p_slot;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 	u32 event_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 	/* Presence Change */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 	ctrl_dbg(ctrl, "Presence/Notify input change\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	p_slot = shpchp_find_slot(ctrl, hp_slot + ctrl->slot_device_offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	 * Save the presence state
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	p_slot->hpc_ops->get_adapter_status(p_slot, &(p_slot->presence_save));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 	if (p_slot->presence_save) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 		 * Card Present
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 		ctrl_info(ctrl, "Card present on Slot(%s)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 			  slot_name(p_slot));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 		event_type = INT_PRESENCE_ON;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 		 * Not Present
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 		ctrl_info(ctrl, "Card not present on Slot(%s)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 			  slot_name(p_slot));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 		event_type = INT_PRESENCE_OFF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 	queue_interrupt_event(p_slot, event_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 	return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) u8 shpchp_handle_power_fault(u8 hp_slot, struct controller *ctrl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 	struct slot *p_slot;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 	u32 event_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 	/* Power fault */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 	ctrl_dbg(ctrl, "Power fault interrupt received\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 	p_slot = shpchp_find_slot(ctrl, hp_slot + ctrl->slot_device_offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 	if (!(p_slot->hpc_ops->query_power_fault(p_slot))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 		 * Power fault Cleared
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 		ctrl_info(ctrl, "Power fault cleared on Slot(%s)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 			  slot_name(p_slot));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 		p_slot->status = 0x00;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 		event_type = INT_POWER_FAULT_CLEAR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 		 *   Power fault
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 		ctrl_info(ctrl, "Power fault on Slot(%s)\n", slot_name(p_slot));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 		event_type = INT_POWER_FAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 		/* set power fault status for this board */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 		p_slot->status = 0xFF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 		ctrl_info(ctrl, "Power fault bit %x set\n", hp_slot);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 	queue_interrupt_event(p_slot, event_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 	return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) /* The following routines constitute the bulk of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176)    hotplug controller logic
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) static int change_bus_speed(struct controller *ctrl, struct slot *p_slot,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 		enum pci_bus_speed speed)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 	int rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 	ctrl_dbg(ctrl, "Change speed to %d\n", speed);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 	rc = p_slot->hpc_ops->set_bus_speed_mode(p_slot, speed);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 	if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 		ctrl_err(ctrl, "%s: Issue of set bus speed mode command failed\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 			 __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 		return WRONG_BUS_FREQUENCY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) static int fix_bus_speed(struct controller *ctrl, struct slot *pslot,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 		u8 flag, enum pci_bus_speed asp, enum pci_bus_speed bsp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 		enum pci_bus_speed msp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 	int rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 	 * If other slots on the same bus are occupied, we cannot
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 	 * change the bus speed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 	if (flag) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 		if (asp < bsp) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 			ctrl_err(ctrl, "Speed of bus %x and adapter %x mismatch\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 				 bsp, asp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 			rc = WRONG_BUS_FREQUENCY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 		return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 	if (asp < msp) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 		if (bsp != asp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 			rc = change_bus_speed(ctrl, pslot, asp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 		if (bsp != msp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 			rc = change_bus_speed(ctrl, pslot, msp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223)  * board_added - Called after a board has been added to the system.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224)  * @p_slot: target &slot
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226)  * Turns power on for the board.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227)  * Configures board.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) static int board_added(struct slot *p_slot)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 	u8 hp_slot;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 	u8 slots_not_empty = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 	int rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 	enum pci_bus_speed asp, bsp, msp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 	struct controller *ctrl = p_slot->ctrl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 	struct pci_bus *parent = ctrl->pci_dev->subordinate;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 	hp_slot = p_slot->device - ctrl->slot_device_offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 	ctrl_dbg(ctrl, "%s: p_slot->device, slot_offset, hp_slot = %d, %d ,%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 		 __func__, p_slot->device, ctrl->slot_device_offset, hp_slot);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 	/* Power on slot without connecting to bus */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 	rc = p_slot->hpc_ops->power_on_slot(p_slot);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 	if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 		ctrl_err(ctrl, "Failed to power on slot\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 		return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 	if ((ctrl->pci_dev->vendor == 0x8086) && (ctrl->pci_dev->device == 0x0332)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 		rc = p_slot->hpc_ops->set_bus_speed_mode(p_slot, PCI_SPEED_33MHz);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 		if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 			ctrl_err(ctrl, "%s: Issue of set bus speed mode command failed\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 				 __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 			return WRONG_BUS_FREQUENCY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 		/* turn on board, blink green LED, turn off Amber LED */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 		rc = p_slot->hpc_ops->slot_enable(p_slot);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 		if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 			ctrl_err(ctrl, "Issue of Slot Enable command failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 			return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 	rc = p_slot->hpc_ops->get_adapter_speed(p_slot, &asp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 	if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 		ctrl_err(ctrl, "Can't get adapter speed or bus mode mismatch\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 		return WRONG_BUS_FREQUENCY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 	bsp = ctrl->pci_dev->subordinate->cur_bus_speed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 	msp = ctrl->pci_dev->subordinate->max_bus_speed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 	/* Check if there are other slots or devices on the same bus */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 	if (!list_empty(&ctrl->pci_dev->subordinate->devices))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 		slots_not_empty = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 	ctrl_dbg(ctrl, "%s: slots_not_empty %d, adapter_speed %d, bus_speed %d, max_bus_speed %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 		 __func__, slots_not_empty, asp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 		 bsp, msp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 	rc = fix_bus_speed(ctrl, p_slot, slots_not_empty, asp, bsp, msp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 	if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 		return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 	/* turn on board, blink green LED, turn off Amber LED */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 	rc = p_slot->hpc_ops->slot_enable(p_slot);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 	if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 		ctrl_err(ctrl, "Issue of Slot Enable command failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 		return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 	/* Wait for ~1 second */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 	msleep(1000);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 	ctrl_dbg(ctrl, "%s: slot status = %x\n", __func__, p_slot->status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 	/* Check for a power fault */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 	if (p_slot->status == 0xFF) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 		/* power fault occurred, but it was benign */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 		ctrl_dbg(ctrl, "%s: Power fault\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 		p_slot->status = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 		goto err_exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 	if (shpchp_configure_device(p_slot)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 		ctrl_err(ctrl, "Cannot add device at %04x:%02x:%02x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 			 pci_domain_nr(parent), p_slot->bus, p_slot->device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 		goto err_exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 	p_slot->status = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 	p_slot->is_a_board = 0x01;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 	p_slot->pwr_save = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 	p_slot->hpc_ops->green_led_on(p_slot);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) err_exit:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 	/* turn off slot, turn on Amber LED, turn off Green LED */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 	rc = p_slot->hpc_ops->slot_disable(p_slot);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 	if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 		ctrl_err(ctrl, "%s: Issue of Slot Disable command failed\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 			 __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 		return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 	return(rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334)  * remove_board - Turns off slot and LEDs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335)  * @p_slot: target &slot
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) static int remove_board(struct slot *p_slot)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 	struct controller *ctrl = p_slot->ctrl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 	u8 hp_slot;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 	int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 	shpchp_unconfigure_device(p_slot);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 	hp_slot = p_slot->device - ctrl->slot_device_offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 	p_slot = shpchp_find_slot(ctrl, hp_slot + ctrl->slot_device_offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 	ctrl_dbg(ctrl, "%s: hp_slot = %d\n", __func__, hp_slot);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) 	/* Change status to shutdown */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 	if (p_slot->is_a_board)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) 		p_slot->status = 0x01;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) 	/* turn off slot, turn on Amber LED, turn off Green LED */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) 	rc = p_slot->hpc_ops->slot_disable(p_slot);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) 	if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) 		ctrl_err(ctrl, "%s: Issue of Slot Disable command failed\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 			 __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) 		return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) 	rc = p_slot->hpc_ops->set_attention_status(p_slot, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) 	if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) 		ctrl_err(ctrl, "Issue of Set Attention command failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 		return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) 	p_slot->pwr_save = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) 	p_slot->is_a_board = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) struct pushbutton_work_info {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) 	struct slot *p_slot;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) 	struct work_struct work;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381)  * shpchp_pushbutton_thread - handle pushbutton events
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382)  * @work: &struct work_struct to be handled
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384)  * Scheduled procedure to handle blocking stuff for the pushbuttons.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385)  * Handles all pending events and exits.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) static void shpchp_pushbutton_thread(struct work_struct *work)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) 	struct pushbutton_work_info *info =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) 		container_of(work, struct pushbutton_work_info, work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) 	struct slot *p_slot = info->p_slot;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) 	mutex_lock(&p_slot->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) 	switch (p_slot->state) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) 	case POWEROFF_STATE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) 		mutex_unlock(&p_slot->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) 		shpchp_disable_slot(p_slot);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) 		mutex_lock(&p_slot->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) 		p_slot->state = STATIC_STATE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) 	case POWERON_STATE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) 		mutex_unlock(&p_slot->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) 		if (shpchp_enable_slot(p_slot))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) 			p_slot->hpc_ops->green_led_off(p_slot);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) 		mutex_lock(&p_slot->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) 		p_slot->state = STATIC_STATE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) 	mutex_unlock(&p_slot->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) 	kfree(info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) void shpchp_queue_pushbutton_work(struct work_struct *work)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) 	struct slot *p_slot = container_of(work, struct slot, work.work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) 	struct pushbutton_work_info *info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) 	info = kmalloc(sizeof(*info), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) 	if (!info) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) 		ctrl_err(p_slot->ctrl, "%s: Cannot allocate memory\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) 			 __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) 	info->p_slot = p_slot;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) 	INIT_WORK(&info->work, shpchp_pushbutton_thread);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) 	mutex_lock(&p_slot->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) 	switch (p_slot->state) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) 	case BLINKINGOFF_STATE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) 		p_slot->state = POWEROFF_STATE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) 	case BLINKINGON_STATE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) 		p_slot->state = POWERON_STATE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) 		kfree(info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) 	queue_work(p_slot->wq, &info->work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443)  out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) 	mutex_unlock(&p_slot->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) static void update_slot_info(struct slot *slot)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) 	slot->hpc_ops->get_power_status(slot, &slot->pwr_save);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) 	slot->hpc_ops->get_attention_status(slot, &slot->attention_save);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) 	slot->hpc_ops->get_latch_status(slot, &slot->latch_save);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) 	slot->hpc_ops->get_adapter_status(slot, &slot->presence_save);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456)  * Note: This function must be called with slot->lock held
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) static void handle_button_press_event(struct slot *p_slot)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) 	u8 getstatus;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) 	struct controller *ctrl = p_slot->ctrl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) 	switch (p_slot->state) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) 	case STATIC_STATE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) 		p_slot->hpc_ops->get_power_status(p_slot, &getstatus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) 		if (getstatus) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) 			p_slot->state = BLINKINGOFF_STATE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) 			ctrl_info(ctrl, "PCI slot #%s - powering off due to button press\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) 				  slot_name(p_slot));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) 			p_slot->state = BLINKINGON_STATE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) 			ctrl_info(ctrl, "PCI slot #%s - powering on due to button press\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) 				  slot_name(p_slot));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) 		/* blink green LED and turn off amber */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) 		p_slot->hpc_ops->green_led_blink(p_slot);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) 		p_slot->hpc_ops->set_attention_status(p_slot, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) 		queue_delayed_work(p_slot->wq, &p_slot->work, 5*HZ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) 	case BLINKINGOFF_STATE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) 	case BLINKINGON_STATE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) 		 * Cancel if we are still blinking; this means that we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) 		 * press the attention again before the 5 sec. limit
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) 		 * expires to cancel hot-add or hot-remove
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) 		ctrl_info(ctrl, "Button cancel on Slot(%s)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) 			  slot_name(p_slot));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) 		cancel_delayed_work(&p_slot->work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) 		if (p_slot->state == BLINKINGOFF_STATE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) 			p_slot->hpc_ops->green_led_on(p_slot);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) 			p_slot->hpc_ops->green_led_off(p_slot);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) 		p_slot->hpc_ops->set_attention_status(p_slot, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) 		ctrl_info(ctrl, "PCI slot #%s - action canceled due to button press\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) 			  slot_name(p_slot));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) 		p_slot->state = STATIC_STATE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) 	case POWEROFF_STATE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) 	case POWERON_STATE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) 		 * Ignore if the slot is on power-on or power-off state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) 		 * this means that the previous attention button action
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) 		 * to hot-add or hot-remove is undergoing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) 		ctrl_info(ctrl, "Button ignore on Slot(%s)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) 			  slot_name(p_slot));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) 		update_slot_info(p_slot);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) 		ctrl_warn(ctrl, "Not a valid state\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) static void interrupt_event_handler(struct work_struct *work)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) 	struct event_info *info = container_of(work, struct event_info, work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) 	struct slot *p_slot = info->p_slot;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) 	mutex_lock(&p_slot->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) 	switch (info->event_type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) 	case INT_BUTTON_PRESS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) 		handle_button_press_event(p_slot);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) 	case INT_POWER_FAULT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) 		ctrl_dbg(p_slot->ctrl, "%s: Power fault\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) 		p_slot->hpc_ops->set_attention_status(p_slot, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) 		p_slot->hpc_ops->green_led_off(p_slot);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) 		update_slot_info(p_slot);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) 	mutex_unlock(&p_slot->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) 	kfree(info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) static int shpchp_enable_slot (struct slot *p_slot)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) 	u8 getstatus = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) 	int rc, retval = -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) 	struct controller *ctrl = p_slot->ctrl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) 	/* Check to see if (latch closed, card present, power off) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) 	mutex_lock(&p_slot->ctrl->crit_sect);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) 	rc = p_slot->hpc_ops->get_adapter_status(p_slot, &getstatus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) 	if (rc || !getstatus) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) 		ctrl_info(ctrl, "No adapter on slot(%s)\n", slot_name(p_slot));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) 	rc = p_slot->hpc_ops->get_latch_status(p_slot, &getstatus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) 	if (rc || getstatus) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) 		ctrl_info(ctrl, "Latch open on slot(%s)\n", slot_name(p_slot));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) 	rc = p_slot->hpc_ops->get_power_status(p_slot, &getstatus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) 	if (rc || getstatus) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) 		ctrl_info(ctrl, "Already enabled on slot(%s)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) 			  slot_name(p_slot));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) 	p_slot->is_a_board = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) 	/* We have to save the presence info for these slots */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) 	p_slot->hpc_ops->get_adapter_status(p_slot, &(p_slot->presence_save));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) 	p_slot->hpc_ops->get_power_status(p_slot, &(p_slot->pwr_save));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) 	ctrl_dbg(ctrl, "%s: p_slot->pwr_save %x\n", __func__, p_slot->pwr_save);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) 	p_slot->hpc_ops->get_latch_status(p_slot, &getstatus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) 	if ((p_slot->ctrl->pci_dev->vendor == PCI_VENDOR_ID_AMD &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) 	     p_slot->ctrl->pci_dev->device == PCI_DEVICE_ID_AMD_POGO_7458)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) 	     && p_slot->ctrl->num_slots == 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) 		/* handle AMD POGO errata; this must be done before enable  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) 		amd_pogo_errata_save_misc_reg(p_slot);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) 		retval = board_added(p_slot);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) 		/* handle AMD POGO errata; this must be done after enable  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) 		amd_pogo_errata_restore_misc_reg(p_slot);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) 	} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) 		retval = board_added(p_slot);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) 	if (retval) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) 		p_slot->hpc_ops->get_adapter_status(p_slot,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) 				&(p_slot->presence_save));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) 		p_slot->hpc_ops->get_latch_status(p_slot, &getstatus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) 	update_slot_info(p_slot);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593)  out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) 	mutex_unlock(&p_slot->ctrl->crit_sect);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) 	return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) static int shpchp_disable_slot (struct slot *p_slot)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) 	u8 getstatus = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) 	int rc, retval = -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) 	struct controller *ctrl = p_slot->ctrl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) 	if (!p_slot->ctrl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) 	/* Check to see if (latch closed, card present, power on) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) 	mutex_lock(&p_slot->ctrl->crit_sect);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) 	rc = p_slot->hpc_ops->get_adapter_status(p_slot, &getstatus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) 	if (rc || !getstatus) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) 		ctrl_info(ctrl, "No adapter on slot(%s)\n", slot_name(p_slot));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) 	rc = p_slot->hpc_ops->get_latch_status(p_slot, &getstatus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) 	if (rc || getstatus) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) 		ctrl_info(ctrl, "Latch open on slot(%s)\n", slot_name(p_slot));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) 	rc = p_slot->hpc_ops->get_power_status(p_slot, &getstatus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) 	if (rc || !getstatus) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) 		ctrl_info(ctrl, "Already disabled on slot(%s)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) 			  slot_name(p_slot));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) 	retval = remove_board(p_slot);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) 	update_slot_info(p_slot);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630)  out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) 	mutex_unlock(&p_slot->ctrl->crit_sect);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) 	return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) int shpchp_sysfs_enable_slot(struct slot *p_slot)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) 	int retval = -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) 	struct controller *ctrl = p_slot->ctrl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) 	mutex_lock(&p_slot->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) 	switch (p_slot->state) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) 	case BLINKINGON_STATE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) 		cancel_delayed_work(&p_slot->work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) 		fallthrough;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) 	case STATIC_STATE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) 		p_slot->state = POWERON_STATE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) 		mutex_unlock(&p_slot->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) 		retval = shpchp_enable_slot(p_slot);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) 		mutex_lock(&p_slot->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) 		p_slot->state = STATIC_STATE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) 	case POWERON_STATE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) 		ctrl_info(ctrl, "Slot %s is already in powering on state\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) 			  slot_name(p_slot));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) 	case BLINKINGOFF_STATE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) 	case POWEROFF_STATE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) 		ctrl_info(ctrl, "Already enabled on slot %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) 			  slot_name(p_slot));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) 		ctrl_err(ctrl, "Not a valid state on slot %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) 			 slot_name(p_slot));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) 	mutex_unlock(&p_slot->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) 	return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) int shpchp_sysfs_disable_slot(struct slot *p_slot)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673) 	int retval = -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) 	struct controller *ctrl = p_slot->ctrl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) 	mutex_lock(&p_slot->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) 	switch (p_slot->state) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) 	case BLINKINGOFF_STATE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) 		cancel_delayed_work(&p_slot->work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) 		fallthrough;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) 	case STATIC_STATE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) 		p_slot->state = POWEROFF_STATE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) 		mutex_unlock(&p_slot->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) 		retval = shpchp_disable_slot(p_slot);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) 		mutex_lock(&p_slot->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686) 		p_slot->state = STATIC_STATE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688) 	case POWEROFF_STATE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689) 		ctrl_info(ctrl, "Slot %s is already in powering off state\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690) 			  slot_name(p_slot));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692) 	case BLINKINGON_STATE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693) 	case POWERON_STATE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) 		ctrl_info(ctrl, "Already disabled on slot %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) 			  slot_name(p_slot));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698) 		ctrl_err(ctrl, "Not a valid state on slot %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699) 			 slot_name(p_slot));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702) 	mutex_unlock(&p_slot->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704) 	return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705) }