<commit_before>/*
 * ipmi_poweroff.c
 *
 * MontaVista IPMI Poweroff extension to sys_reboot
 *
 * Author: MontaVista Software, Inc.
 *         <NAME> <<EMAIL>>
 *         <NAME> <<EMAIL>>
 *         <EMAIL>
 *
 * Copyright 2002,2004 MontaVista Software Inc.
 *
 *  This program is free software; you can redistribute it and/or modify it
 *  under the terms of the GNU General Public License as published by the
 *  Free Software Foundation; either version 2 of the License, or (at your
 *  option) any later version.
 *
 *
 *  THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
 *  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 *  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
 *  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
 *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
 *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
 *  OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 *  ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
 *  TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
 *  USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 *  You should have received a copy of the GNU General Public License along
 *  with this program; if not, write to the Free Software Foundation, Inc.,
 *  675 Mass Ave, Cambridge, MA 02139, USA.
 */
#include <asm/semaphore.h>
#include <linux/kdev_t.h>
#include <linux/module.h>
#include <linux/moduleparam.h>
#include <linux/proc_fs.h>
#include <linux/string.h>
#include <linux/ipmi.h>
#include <linux/ipmi_smi.h>

#define PFX "IPMI poweroff: "
#define IPMI_POWEROFF_VERSION	"v33"

/* Where to we insert our poweroff function? */
extern void (*pm_power_off)(void);

/* Definitions for controlling power off (if the system supports it).  It
 * conveniently matches the IPMI chassis control values. */
#define IPMI_CHASSIS_POWER_DOWN		0	/* power down, the default. */
#define IPMI_CHASSIS_POWER_CYCLE	0x02	/* power cycle */

/* the IPMI data command */
static int poweroff_control = IPMI_CHASSIS_POWER_DOWN;

/* parameter definition to allow user to flag power cycle */
module_param(poweroff_control, int, IPMI_CHASSIS_POWER_DOWN);
MODULE_PARM_DESC(poweroff_control, " Set to 2 to enable power cycle instead of power down. Power cycle is contingent on hardware support, otherwise it defaults back to power down.");

/* Stuff from the get device id command. */
static unsigned int mfg_id;
static unsigned int prod_id;
static unsigned char capabilities;

/* We use our own messages for this operation, we don't let the system
   allocate them, since we may be in a panic situation.  The whole
   thing is single-threaded, anyway, so multiple messages are not
   required. */
static void dummy_smi_free(struct ipmi_smi_msg *msg)
{
}
static void dummy_recv_free(struct ipmi_recv_msg *msg)
{
}
static struct ipmi_smi_msg halt_smi_msg =
{
	.done = dummy_smi_free
};
static struct ipmi_recv_msg halt_recv_msg =
{
	.done = dummy_recv_free
};


/*
 * Code to send a message and wait for the reponse.
 */

static void receive_handler(struct ipmi_recv_msg *recv_msg, void *handler_data)
{
	struct semaphore *sem = recv_msg->user_msg_data;

	if (sem)
		up(sem);
}

static struct ipmi_user_hndl ipmi_poweroff_handler =
{
	.ipmi_recv_hndl = receive_handler
};


static int ipmi_request_wait_for_response(ipmi_user_t            user,
					  struct ipmi_addr       *addr,
					  struct kernel_ipmi_msg *send_msg)
{
	int              rv;
	struct semaphore sem;

	sema_init (&sem, 0);

	rv = ipmi_request_supply_msgs(user, addr, 0, send_msg, &sem,
				      &halt_smi_msg, &halt_recv_msg, 0);
	if (rv)
		return rv;

	down (&sem);

	return halt_recv_msg.msg.data[0];
}

/* We are in run-to-completion mode, no semaphore is desired. */
static int ipmi_request_in_rc_mode(ipmi_user_t            user,
				   struct ipmi_addr       *addr,
				   struct kernel_ipmi_msg *send_msg)
{
	int              rv;

	rv = ipmi_request_supply_msgs(user, addr, 0, send_msg, NULL,
				      &halt_smi_msg, &halt_recv_msg, 0);
	if (rv)
		return rv;

	return halt_recv_msg.msg.data[0];
}

/*
 * ATCA Support
 */

#define IPMI_NETFN_ATCA			0x2c
#define IPMI_ATCA_SET_POWER_CMD		0x11
#define IPMI_ATCA_GET_ADDR_INFO_CMD	0x01
#define IPMI_PICMG_ID			0

static int ipmi_atca_detect (ipmi_user_t user)
{
	struct ipmi_system_interface_addr smi_addr;
	struct kernel_ipmi_msg            send_msg;
	int                               rv;
	unsigned char                     data[1];

        /*
         * Configure IPMI address for local access
         */
        smi_addr.addr_type = IPMI_SYSTEM_INTERFACE_ADDR_TYPE;<commit_msg>[PATCH] ipmi: use completions, not semaphores, in powerdown code<commit_after>/*
 * ipmi_poweroff.c
 *
 * MontaVista IPMI Poweroff extension to sys_reboot
 *
 * Author: MontaVista Software, Inc.
 *         <NAME> <<EMAIL>>
 *         <NAME> <<EMAIL>>
 *         <EMAIL>
 *
 * Copyright 2002,2004 MontaVista Software Inc.
 *
 *  This program is free software; you can redistribute it and/or modify it
 *  under the terms of the GNU General Public License as published by the
 *  Free Software Foundation; either version 2 of the License, or (at your
 *  option) any later version.
 *
 *
 *  THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
 *  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 *  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
 *  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
 *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
 *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
 *  OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 *  ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
 *  TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
 *  USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 *  You should have received a copy of the GNU General Public License along
 *  with this program; if not, write to the Free Software Foundation, Inc.,
 *  675 Mass Ave, Cambridge, MA 02139, USA.
 */
#include <linux/config.h>
#include <linux/module.h>
#include <linux/moduleparam.h>
#include <linux/proc_fs.h>
#include <linux/string.h>
#include <linux/completion.h>
#include <linux/kdev_t.h>
#include <linux/ipmi.h>
#include <linux/ipmi_smi.h>

#define PFX "IPMI poweroff: "
#define IPMI_POWEROFF_VERSION	"v33"

/* Where to we insert our poweroff function? */
extern void (*pm_power_off)(void);

/* Definitions for controlling power off (if the system supports it).  It
 * conveniently matches the IPMI chassis control values. */
#define IPMI_CHASSIS_POWER_DOWN		0	/* power down, the default. */
#define IPMI_CHASSIS_POWER_CYCLE	0x02	/* power cycle */

/* the IPMI data command */
static int poweroff_control = IPMI_CHASSIS_POWER_DOWN;

/* parameter definition to allow user to flag power cycle */
module_param(poweroff_control, int, IPMI_CHASSIS_POWER_DOWN);
MODULE_PARM_DESC(poweroff_control, " Set to 2 to enable power cycle instead of power down. Power cycle is contingent on hardware support, otherwise it defaults back to power down.");

/* Stuff from the get device id command. */
static unsigned int mfg_id;
static unsigned int prod_id;
static unsigned char capabilities;

/* We use our own messages for this operation, we don't let the system
   allocate them, since we may be in a panic situation.  The whole
   thing is single-threaded, anyway, so multiple messages are not
   required. */
static void dummy_smi_free(struct ipmi_smi_msg *msg)
{
}
static void dummy_recv_free(struct ipmi_recv_msg *msg)
{
}
static struct ipmi_smi_msg halt_smi_msg =
{
	.done = dummy_smi_free
};
static struct ipmi_recv_msg halt_recv_msg =
{
	.done = dummy_recv_free
};


/*
 * Code to send a message and wait for the reponse.
 */

static void receive_handler(struct ipmi_recv_msg *recv_msg, void *handler_data)
{
	struct completion *comp = recv_msg->user_msg_data;

	if (comp)
		complete(comp);
}

static struct ipmi_user_hndl ipmi_poweroff_handler =
{
	.ipmi_recv_hndl = receive_handler
};


static int ipmi_request_wait_for_response(ipmi_user_t            user,
					  struct ipmi_addr       *addr,
					  struct kernel_ipmi_msg *send_msg)
{
	int               rv;
	struct completion comp;

	init_completion(&comp);

	rv = ipmi_request_supply_msgs(user, addr, 0, send_msg, &comp,
				      &halt_smi_msg, &halt_recv_msg, 0);
	if (rv)
		return rv;

	wait_for_completion(&comp);

	return halt_recv_msg.msg.data[0];
}

/* We are in run-to-completion mode, no completion is desired. */
static int ipmi_request_in_rc_mode(ipmi_user_t            user,
				   struct ipmi_addr       *addr,
				   struct kernel_ipmi_msg *send_msg)
{
	int rv;

	rv = ipmi_request_supply_msgs(user, addr, 0, send_msg, NULL,
				      &halt_smi_msg, &halt_recv_msg, 0);
	if (rv)
		return rv;

	return halt_recv_msg.msg.data[0];
}

/*
 * ATCA Support
 */

#define IPMI_NETFN_ATCA			0x2c
#define IPMI_ATCA_SET_POWER_CMD		0x11
#define IPMI_ATCA_GET_ADDR_INFO_CMD	0x01
#define IPMI_PICMG_ID			0

static int ipmi_atca_detect (ipmi_user_t user)
{
	struct ipmi_system_interface_addr smi_addr;
	struct kernel_ipmi_msg            send_msg;
	int                               rv;
	unsigned char                     data[1];

        /*
         * Configure IPMI address for local access
         */
        smi_addr.addr_type = IPMI_SYSTEM_INTERFACE_ADDR_TYPE;
{'fraction_non_alphanumeric': 0.08053060371840401, 'fraction_numerical': 0.008460413620221433, 'mean_word_length': 3.621138996138996, 'pattern_counts': {'":': 0, '<': 34, '<?xml version=': 0, '>': 36, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3847183', 'n_tokens_mistral': 3326, 'n_tokens_neox': 3114, 'n_words': 1058}