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)  * ipmi_ssif.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    5)  * The interface to the IPMI driver for SMBus access to a SMBus
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    6)  * compliant device.  Called SSIF by the IPMI spec.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    7)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    8)  * Author: Intel Corporation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    9)  *         Todd Davis <todd.c.davis@intel.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   10)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   11)  * Rewritten by Corey Minyard <minyard@acm.org> to support the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   12)  * non-blocking I2C interface, add support for multi-part
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   13)  * transactions, add PEC support, and general clenaup.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   14)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   15)  * Copyright 2003 Intel Corporation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   16)  * Copyright 2005 MontaVista Software
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   17)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   18) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   19) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   20)  * This file holds the "policy" for the interface to the SSIF state
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   21)  * machine.  It does the configuration, handles timers and interrupts,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   22)  * and drives the real SSIF state machine.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   23)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   24) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   25) #define pr_fmt(fmt) "ipmi_ssif: " fmt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   26) #define dev_fmt(fmt) "ipmi_ssif: " fmt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   27) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   28) #if defined(MODVERSIONS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   29) #include <linux/modversions.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   30) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   31) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   32) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   33) #include <linux/moduleparam.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   34) #include <linux/sched.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   35) #include <linux/seq_file.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   36) #include <linux/timer.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   37) #include <linux/delay.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   38) #include <linux/errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   39) #include <linux/spinlock.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   40) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   41) #include <linux/list.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   42) #include <linux/i2c.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   43) #include <linux/ipmi_smi.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   44) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   45) #include <linux/dmi.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   46) #include <linux/kthread.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   47) #include <linux/acpi.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   48) #include <linux/ctype.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   49) #include <linux/time64.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   50) #include "ipmi_dmi.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   51) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   52) #define DEVICE_NAME "ipmi_ssif"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   53) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   54) #define IPMI_GET_SYSTEM_INTERFACE_CAPABILITIES_CMD	0x57
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   55) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   56) #define	SSIF_IPMI_REQUEST			2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   57) #define	SSIF_IPMI_MULTI_PART_REQUEST_START	6
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   58) #define	SSIF_IPMI_MULTI_PART_REQUEST_MIDDLE	7
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   59) #define	SSIF_IPMI_MULTI_PART_REQUEST_END	8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   60) #define	SSIF_IPMI_RESPONSE			3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   61) #define	SSIF_IPMI_MULTI_PART_RESPONSE_MIDDLE	9
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   62) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   63) /* ssif_debug is a bit-field
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   64)  *	SSIF_DEBUG_MSG -	commands and their responses
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   65)  *	SSIF_DEBUG_STATES -	message states
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   66)  *	SSIF_DEBUG_TIMING -	 Measure times between events in the driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   67)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   68) #define SSIF_DEBUG_TIMING	4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   69) #define SSIF_DEBUG_STATE	2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   70) #define SSIF_DEBUG_MSG		1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   71) #define SSIF_NODEBUG		0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   72) #define SSIF_DEFAULT_DEBUG	(SSIF_NODEBUG)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   73) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   74) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   75)  * Timer values
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   76)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   77) #define SSIF_MSG_USEC		20000	/* 20ms between message tries. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   78) #define SSIF_MSG_PART_USEC	5000	/* 5ms for a message part */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   79) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   80) /* How many times to we retry sending/receiving the message. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   81) #define	SSIF_SEND_RETRIES	5
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   82) #define	SSIF_RECV_RETRIES	250
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   83) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   84) #define SSIF_MSG_MSEC		(SSIF_MSG_USEC / 1000)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   85) #define SSIF_MSG_JIFFIES	((SSIF_MSG_USEC * 1000) / TICK_NSEC)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   86) #define SSIF_MSG_PART_JIFFIES	((SSIF_MSG_PART_USEC * 1000) / TICK_NSEC)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   87) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   88) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   89)  * Timeout for the watch, only used for get flag timer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   90)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   91) #define SSIF_WATCH_MSG_TIMEOUT		msecs_to_jiffies(10)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   92) #define SSIF_WATCH_WATCHDOG_TIMEOUT	msecs_to_jiffies(250)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   93) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   94) enum ssif_intf_state {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   95) 	SSIF_NORMAL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   96) 	SSIF_GETTING_FLAGS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   97) 	SSIF_GETTING_EVENTS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   98) 	SSIF_CLEARING_FLAGS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   99) 	SSIF_GETTING_MESSAGES,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  100) 	/* FIXME - add watchdog stuff. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  101) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  102) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  103) #define SSIF_IDLE(ssif)	 ((ssif)->ssif_state == SSIF_NORMAL \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  104) 			  && (ssif)->curr_msg == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  105) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  106) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  107)  * Indexes into stats[] in ssif_info below.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  108)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  109) enum ssif_stat_indexes {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  110) 	/* Number of total messages sent. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  111) 	SSIF_STAT_sent_messages = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  112) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  113) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  114) 	 * Number of message parts sent.  Messages may be broken into
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  115) 	 * parts if they are long.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  116) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  117) 	SSIF_STAT_sent_messages_parts,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  118) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  119) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  120) 	 * Number of time a message was retried.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  121) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  122) 	SSIF_STAT_send_retries,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  123) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  124) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  125) 	 * Number of times the send of a message failed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  126) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  127) 	SSIF_STAT_send_errors,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  128) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  129) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  130) 	 * Number of message responses received.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  131) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  132) 	SSIF_STAT_received_messages,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  133) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  134) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  135) 	 * Number of message fragments received.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  136) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  137) 	SSIF_STAT_received_message_parts,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  138) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  139) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  140) 	 * Number of times the receive of a message was retried.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  141) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  142) 	SSIF_STAT_receive_retries,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  143) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  144) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  145) 	 * Number of errors receiving messages.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  146) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  147) 	SSIF_STAT_receive_errors,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  148) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  149) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  150) 	 * Number of times a flag fetch was requested.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  151) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  152) 	SSIF_STAT_flag_fetches,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  153) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  154) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  155) 	 * Number of times the hardware didn't follow the state machine.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  156) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  157) 	SSIF_STAT_hosed,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  158) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  159) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  160) 	 * Number of received events.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  161) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  162) 	SSIF_STAT_events,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  163) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  164) 	/* Number of asyncronous messages received. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  165) 	SSIF_STAT_incoming_messages,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  166) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  167) 	/* Number of watchdog pretimeouts. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  168) 	SSIF_STAT_watchdog_pretimeouts,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  169) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  170) 	/* Number of alers received. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  171) 	SSIF_STAT_alerts,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  172) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  173) 	/* Always add statistics before this value, it must be last. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  174) 	SSIF_NUM_STATS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  175) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  176) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  177) struct ssif_addr_info {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  178) 	struct i2c_board_info binfo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  179) 	char *adapter_name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  180) 	int debug;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  181) 	int slave_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  182) 	enum ipmi_addr_src addr_src;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  183) 	union ipmi_smi_info_union addr_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  184) 	struct device *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  185) 	struct i2c_client *client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  186) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  187) 	struct mutex clients_mutex;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  188) 	struct list_head clients;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  189) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  190) 	struct list_head link;
^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) struct ssif_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  194) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  195) typedef void (*ssif_i2c_done)(struct ssif_info *ssif_info, int result,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  196) 			     unsigned char *data, unsigned int len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  197) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  198) struct ssif_info {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  199) 	struct ipmi_smi     *intf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  200) 	spinlock_t	    lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  201) 	struct ipmi_smi_msg *waiting_msg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  202) 	struct ipmi_smi_msg *curr_msg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  203) 	enum ssif_intf_state ssif_state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  204) 	unsigned long       ssif_debug;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  205) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  206) 	struct ipmi_smi_handlers handlers;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  207) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  208) 	enum ipmi_addr_src addr_source; /* ACPI, PCI, SMBIOS, hardcode, etc. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  209) 	union ipmi_smi_info_union addr_info;
^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) 	 * Flags from the last GET_MSG_FLAGS command, used when an ATTN
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  213) 	 * is set to hold the flags until we are done handling everything
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  214) 	 * from the flags.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  215) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  216) #define RECEIVE_MSG_AVAIL	0x01
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  217) #define EVENT_MSG_BUFFER_FULL	0x02
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  218) #define WDT_PRE_TIMEOUT_INT	0x08
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  219) 	unsigned char       msg_flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  220) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  221) 	u8		    global_enables;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  222) 	bool		    has_event_buffer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  223) 	bool		    supports_alert;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  224) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  225) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  226) 	 * Used to tell what we should do with alerts.  If we are
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  227) 	 * waiting on a response, read the data immediately.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  228) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  229) 	bool		    got_alert;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  230) 	bool		    waiting_alert;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  231) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  232) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  233) 	 * If set to true, this will request events the next time the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  234) 	 * state machine is idle.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  235) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  236) 	bool                req_events;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  237) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  238) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  239) 	 * If set to true, this will request flags the next time the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  240) 	 * state machine is idle.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  241) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  242) 	bool                req_flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  243) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  244) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  245) 	 * Used to perform timer operations when run-to-completion
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  246) 	 * mode is on.  This is a countdown timer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  247) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  248) 	int                 rtc_us_timer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  249) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  250) 	/* Used for sending/receiving data.  +1 for the length. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  251) 	unsigned char data[IPMI_MAX_MSG_LENGTH + 1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  252) 	unsigned int  data_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  253) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  254) 	/* Temp receive buffer, gets copied into data. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  255) 	unsigned char recv[I2C_SMBUS_BLOCK_MAX];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  256) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  257) 	struct i2c_client *client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  258) 	ssif_i2c_done done_handler;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  259) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  260) 	/* Thread interface handling */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  261) 	struct task_struct *thread;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  262) 	struct completion wake_thread;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  263) 	bool stopping;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  264) 	int i2c_read_write;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  265) 	int i2c_command;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  266) 	unsigned char *i2c_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  267) 	unsigned int i2c_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  268) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  269) 	struct timer_list retry_timer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  270) 	int retries_left;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  271) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  272) 	long watch_timeout;		/* Timeout for flags check, 0 if off. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  273) 	struct timer_list watch_timer;	/* Flag fetch timer. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  274) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  275) 	/* Info from SSIF cmd */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  276) 	unsigned char max_xmit_msg_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  277) 	unsigned char max_recv_msg_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  278) 	bool cmd8_works; /* See test_multipart_messages() for details. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  279) 	unsigned int  multi_support;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  280) 	int           supports_pec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  281) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  282) #define SSIF_NO_MULTI		0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  283) #define SSIF_MULTI_2_PART	1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  284) #define SSIF_MULTI_n_PART	2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  285) 	unsigned char *multi_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  286) 	unsigned int  multi_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  287) 	unsigned int  multi_pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  288) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  289) 	atomic_t stats[SSIF_NUM_STATS];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  290) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  291) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  292) #define ssif_inc_stat(ssif, stat) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  293) 	atomic_inc(&(ssif)->stats[SSIF_STAT_ ## stat])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  294) #define ssif_get_stat(ssif, stat) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  295) 	((unsigned int) atomic_read(&(ssif)->stats[SSIF_STAT_ ## stat]))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  296) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  297) static bool initialized;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  298) static bool platform_registered;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  299) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  300) static void return_hosed_msg(struct ssif_info *ssif_info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  301) 			     struct ipmi_smi_msg *msg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  302) static void start_next_msg(struct ssif_info *ssif_info, unsigned long *flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  303) static int start_send(struct ssif_info *ssif_info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  304) 		      unsigned char   *data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  305) 		      unsigned int    len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  306) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  307) static unsigned long *ipmi_ssif_lock_cond(struct ssif_info *ssif_info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  308) 					  unsigned long *flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  309) 	__acquires(&ssif_info->lock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  310) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  311) 	spin_lock_irqsave(&ssif_info->lock, *flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  312) 	return flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  313) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  314) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  315) static void ipmi_ssif_unlock_cond(struct ssif_info *ssif_info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  316) 				  unsigned long *flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  317) 	__releases(&ssif_info->lock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  318) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  319) 	spin_unlock_irqrestore(&ssif_info->lock, *flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  320) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  321) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  322) static void deliver_recv_msg(struct ssif_info *ssif_info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  323) 			     struct ipmi_smi_msg *msg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  324) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  325) 	if (msg->rsp_size < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  326) 		return_hosed_msg(ssif_info, msg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  327) 		dev_err(&ssif_info->client->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  328) 			"%s: Malformed message: rsp_size = %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  329) 		       __func__, msg->rsp_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  330) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  331) 		ipmi_smi_msg_received(ssif_info->intf, msg);
^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) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  335) static void return_hosed_msg(struct ssif_info *ssif_info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  336) 			     struct ipmi_smi_msg *msg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  337) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  338) 	ssif_inc_stat(ssif_info, hosed);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  339) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  340) 	/* Make it a response */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  341) 	msg->rsp[0] = msg->data[0] | 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  342) 	msg->rsp[1] = msg->data[1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  343) 	msg->rsp[2] = 0xFF; /* Unknown error. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  344) 	msg->rsp_size = 3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  345) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  346) 	deliver_recv_msg(ssif_info, msg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  347) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  348) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  349) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  350)  * Must be called with the message lock held.  This will release the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  351)  * message lock.  Note that the caller will check SSIF_IDLE and start a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  352)  * new operation, so there is no need to check for new messages to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  353)  * start in here.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  354)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  355) static void start_clear_flags(struct ssif_info *ssif_info, unsigned long *flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  356) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  357) 	unsigned char msg[3];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  358) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  359) 	ssif_info->msg_flags &= ~WDT_PRE_TIMEOUT_INT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  360) 	ssif_info->ssif_state = SSIF_CLEARING_FLAGS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  361) 	ipmi_ssif_unlock_cond(ssif_info, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  362) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  363) 	/* Make sure the watchdog pre-timeout flag is not set at startup. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  364) 	msg[0] = (IPMI_NETFN_APP_REQUEST << 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  365) 	msg[1] = IPMI_CLEAR_MSG_FLAGS_CMD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  366) 	msg[2] = WDT_PRE_TIMEOUT_INT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  367) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  368) 	if (start_send(ssif_info, msg, 3) != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  369) 		/* Error, just go to normal state. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  370) 		ssif_info->ssif_state = SSIF_NORMAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  371) 	}
^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) static void start_flag_fetch(struct ssif_info *ssif_info, unsigned long *flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  375) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  376) 	unsigned char mb[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  377) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  378) 	ssif_info->req_flags = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  379) 	ssif_info->ssif_state = SSIF_GETTING_FLAGS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  380) 	ipmi_ssif_unlock_cond(ssif_info, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  381) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  382) 	mb[0] = (IPMI_NETFN_APP_REQUEST << 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  383) 	mb[1] = IPMI_GET_MSG_FLAGS_CMD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  384) 	if (start_send(ssif_info, mb, 2) != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  385) 		ssif_info->ssif_state = SSIF_NORMAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  386) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  387) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  388) static void check_start_send(struct ssif_info *ssif_info, unsigned long *flags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  389) 			     struct ipmi_smi_msg *msg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  390) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  391) 	if (start_send(ssif_info, msg->data, msg->data_size) != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  392) 		unsigned long oflags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  393) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  394) 		flags = ipmi_ssif_lock_cond(ssif_info, &oflags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  395) 		ssif_info->curr_msg = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  396) 		ssif_info->ssif_state = SSIF_NORMAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  397) 		ipmi_ssif_unlock_cond(ssif_info, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  398) 		ipmi_free_smi_msg(msg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  399) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  400) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  401) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  402) static void start_event_fetch(struct ssif_info *ssif_info, unsigned long *flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  403) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  404) 	struct ipmi_smi_msg *msg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  405) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  406) 	ssif_info->req_events = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  407) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  408) 	msg = ipmi_alloc_smi_msg();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  409) 	if (!msg) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  410) 		ssif_info->ssif_state = SSIF_NORMAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  411) 		ipmi_ssif_unlock_cond(ssif_info, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  412) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  413) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  414) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  415) 	ssif_info->curr_msg = msg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  416) 	ssif_info->ssif_state = SSIF_GETTING_EVENTS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  417) 	ipmi_ssif_unlock_cond(ssif_info, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  418) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  419) 	msg->data[0] = (IPMI_NETFN_APP_REQUEST << 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  420) 	msg->data[1] = IPMI_READ_EVENT_MSG_BUFFER_CMD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  421) 	msg->data_size = 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  422) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  423) 	check_start_send(ssif_info, flags, msg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  424) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  425) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  426) static void start_recv_msg_fetch(struct ssif_info *ssif_info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  427) 				 unsigned long *flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  428) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  429) 	struct ipmi_smi_msg *msg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  430) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  431) 	msg = ipmi_alloc_smi_msg();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  432) 	if (!msg) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  433) 		ssif_info->ssif_state = SSIF_NORMAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  434) 		ipmi_ssif_unlock_cond(ssif_info, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  435) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  436) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  437) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  438) 	ssif_info->curr_msg = msg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  439) 	ssif_info->ssif_state = SSIF_GETTING_MESSAGES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  440) 	ipmi_ssif_unlock_cond(ssif_info, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  441) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  442) 	msg->data[0] = (IPMI_NETFN_APP_REQUEST << 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  443) 	msg->data[1] = IPMI_GET_MSG_CMD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  444) 	msg->data_size = 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  445) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  446) 	check_start_send(ssif_info, flags, msg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  447) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  448) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  449) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  450)  * Must be called with the message lock held.  This will release the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  451)  * message lock.  Note that the caller will check SSIF_IDLE and start a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  452)  * new operation, so there is no need to check for new messages to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  453)  * start in here.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  454)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  455) static void handle_flags(struct ssif_info *ssif_info, unsigned long *flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  456) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  457) 	if (ssif_info->msg_flags & WDT_PRE_TIMEOUT_INT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  458) 		/* Watchdog pre-timeout */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  459) 		ssif_inc_stat(ssif_info, watchdog_pretimeouts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  460) 		start_clear_flags(ssif_info, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  461) 		ipmi_smi_watchdog_pretimeout(ssif_info->intf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  462) 	} else if (ssif_info->msg_flags & RECEIVE_MSG_AVAIL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  463) 		/* Messages available. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  464) 		start_recv_msg_fetch(ssif_info, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  465) 	else if (ssif_info->msg_flags & EVENT_MSG_BUFFER_FULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  466) 		/* Events available. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  467) 		start_event_fetch(ssif_info, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  468) 	else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  469) 		ssif_info->ssif_state = SSIF_NORMAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  470) 		ipmi_ssif_unlock_cond(ssif_info, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  471) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  472) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  473) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  474) static int ipmi_ssif_thread(void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  475) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  476) 	struct ssif_info *ssif_info = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  477) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  478) 	while (!kthread_should_stop()) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  479) 		int result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  480) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  481) 		/* Wait for something to do */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  482) 		result = wait_for_completion_interruptible(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  483) 						&ssif_info->wake_thread);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  484) 		if (ssif_info->stopping)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  485) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  486) 		if (result == -ERESTARTSYS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  487) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  488) 		init_completion(&ssif_info->wake_thread);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  489) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  490) 		if (ssif_info->i2c_read_write == I2C_SMBUS_WRITE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  491) 			result = i2c_smbus_write_block_data(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  492) 				ssif_info->client, ssif_info->i2c_command,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  493) 				ssif_info->i2c_data[0],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  494) 				ssif_info->i2c_data + 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  495) 			ssif_info->done_handler(ssif_info, result, NULL, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  496) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  497) 			result = i2c_smbus_read_block_data(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  498) 				ssif_info->client, ssif_info->i2c_command,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  499) 				ssif_info->i2c_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  500) 			if (result < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  501) 				ssif_info->done_handler(ssif_info, result,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  502) 							NULL, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  503) 			else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  504) 				ssif_info->done_handler(ssif_info, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  505) 							ssif_info->i2c_data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  506) 							result);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  507) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  508) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  509) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  510) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  511) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  512) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  513) static int ssif_i2c_send(struct ssif_info *ssif_info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  514) 			ssif_i2c_done handler,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  515) 			int read_write, int command,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  516) 			unsigned char *data, unsigned int size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  517) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  518) 	ssif_info->done_handler = handler;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  519) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  520) 	ssif_info->i2c_read_write = read_write;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  521) 	ssif_info->i2c_command = command;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  522) 	ssif_info->i2c_data = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  523) 	ssif_info->i2c_size = size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  524) 	complete(&ssif_info->wake_thread);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  525) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  526) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  527) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  528) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  529) static void msg_done_handler(struct ssif_info *ssif_info, int result,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  530) 			     unsigned char *data, unsigned int len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  531) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  532) static void start_get(struct ssif_info *ssif_info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  533) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  534) 	int rv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  535) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  536) 	ssif_info->rtc_us_timer = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  537) 	ssif_info->multi_pos = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  538) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  539) 	rv = ssif_i2c_send(ssif_info, msg_done_handler, I2C_SMBUS_READ,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  540) 			  SSIF_IPMI_RESPONSE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  541) 			  ssif_info->recv, I2C_SMBUS_BLOCK_DATA);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  542) 	if (rv < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  543) 		/* request failed, just return the error. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  544) 		if (ssif_info->ssif_debug & SSIF_DEBUG_MSG)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  545) 			dev_dbg(&ssif_info->client->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  546) 				"Error from i2c_non_blocking_op(5)\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  547) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  548) 		msg_done_handler(ssif_info, -EIO, NULL, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  549) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  550) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  551) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  552) static void retry_timeout(struct timer_list *t)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  553) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  554) 	struct ssif_info *ssif_info = from_timer(ssif_info, t, retry_timer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  555) 	unsigned long oflags, *flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  556) 	bool waiting;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  557) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  558) 	if (ssif_info->stopping)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  559) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  560) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  561) 	flags = ipmi_ssif_lock_cond(ssif_info, &oflags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  562) 	waiting = ssif_info->waiting_alert;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  563) 	ssif_info->waiting_alert = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  564) 	ipmi_ssif_unlock_cond(ssif_info, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  565) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  566) 	if (waiting)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  567) 		start_get(ssif_info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  568) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  569) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  570) static void watch_timeout(struct timer_list *t)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  571) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  572) 	struct ssif_info *ssif_info = from_timer(ssif_info, t, watch_timer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  573) 	unsigned long oflags, *flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  574) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  575) 	if (ssif_info->stopping)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  576) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  577) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  578) 	flags = ipmi_ssif_lock_cond(ssif_info, &oflags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  579) 	if (ssif_info->watch_timeout) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  580) 		mod_timer(&ssif_info->watch_timer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  581) 			  jiffies + ssif_info->watch_timeout);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  582) 		if (SSIF_IDLE(ssif_info)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  583) 			start_flag_fetch(ssif_info, flags); /* Releases lock */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  584) 			return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  585) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  586) 		ssif_info->req_flags = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  587) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  588) 	ipmi_ssif_unlock_cond(ssif_info, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  589) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  590) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  591) static void ssif_alert(struct i2c_client *client, enum i2c_alert_protocol type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  592) 		       unsigned int data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  593) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  594) 	struct ssif_info *ssif_info = i2c_get_clientdata(client);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  595) 	unsigned long oflags, *flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  596) 	bool do_get = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  597) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  598) 	if (type != I2C_PROTOCOL_SMBUS_ALERT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  599) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  600) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  601) 	ssif_inc_stat(ssif_info, alerts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  602) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  603) 	flags = ipmi_ssif_lock_cond(ssif_info, &oflags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  604) 	if (ssif_info->waiting_alert) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  605) 		ssif_info->waiting_alert = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  606) 		del_timer(&ssif_info->retry_timer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  607) 		do_get = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  608) 	} else if (ssif_info->curr_msg) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  609) 		ssif_info->got_alert = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  610) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  611) 	ipmi_ssif_unlock_cond(ssif_info, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  612) 	if (do_get)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  613) 		start_get(ssif_info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  614) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  615) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  616) static int start_resend(struct ssif_info *ssif_info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  617) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  618) static void msg_done_handler(struct ssif_info *ssif_info, int result,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  619) 			     unsigned char *data, unsigned int len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  620) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  621) 	struct ipmi_smi_msg *msg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  622) 	unsigned long oflags, *flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  623) 	int rv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  624) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  625) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  626) 	 * We are single-threaded here, so no need for a lock until we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  627) 	 * start messing with driver states or the queues.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  628) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  629) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  630) 	if (result < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  631) 		ssif_info->retries_left--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  632) 		if (ssif_info->retries_left > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  633) 			ssif_inc_stat(ssif_info, receive_retries);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  634) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  635) 			flags = ipmi_ssif_lock_cond(ssif_info, &oflags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  636) 			ssif_info->waiting_alert = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  637) 			ssif_info->rtc_us_timer = SSIF_MSG_USEC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  638) 			if (!ssif_info->stopping)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  639) 				mod_timer(&ssif_info->retry_timer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  640) 					  jiffies + SSIF_MSG_JIFFIES);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  641) 			ipmi_ssif_unlock_cond(ssif_info, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  642) 			return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  643) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  644) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  645) 		ssif_inc_stat(ssif_info, receive_errors);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  646) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  647) 		if  (ssif_info->ssif_debug & SSIF_DEBUG_MSG)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  648) 			dev_dbg(&ssif_info->client->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  649) 				"%s: Error %d\n", __func__, result);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  650) 		len = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  651) 		goto continue_op;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  652) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  653) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  654) 	if ((len > 1) && (ssif_info->multi_pos == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  655) 				&& (data[0] == 0x00) && (data[1] == 0x01)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  656) 		/* Start of multi-part read.  Start the next transaction. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  657) 		int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  658) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  659) 		ssif_inc_stat(ssif_info, received_message_parts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  660) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  661) 		/* Remove the multi-part read marker. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  662) 		len -= 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  663) 		data += 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  664) 		for (i = 0; i < len; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  665) 			ssif_info->data[i] = data[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  666) 		ssif_info->multi_len = len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  667) 		ssif_info->multi_pos = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  668) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  669) 		rv = ssif_i2c_send(ssif_info, msg_done_handler, I2C_SMBUS_READ,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  670) 				  SSIF_IPMI_MULTI_PART_RESPONSE_MIDDLE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  671) 				  ssif_info->recv, I2C_SMBUS_BLOCK_DATA);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  672) 		if (rv < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  673) 			if (ssif_info->ssif_debug & SSIF_DEBUG_MSG)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  674) 				dev_dbg(&ssif_info->client->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  675) 					"Error from i2c_non_blocking_op(1)\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  676) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  677) 			result = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  678) 		} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  679) 			return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  680) 	} else if (ssif_info->multi_pos) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  681) 		/* Middle of multi-part read.  Start the next transaction. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  682) 		int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  683) 		unsigned char blocknum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  684) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  685) 		if (len == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  686) 			result = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  687) 			if (ssif_info->ssif_debug & SSIF_DEBUG_MSG)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  688) 				dev_dbg(&ssif_info->client->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  689) 					"Middle message with no data\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  690) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  691) 			goto continue_op;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  692) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  693) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  694) 		blocknum = data[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  695) 		len--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  696) 		data++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  697) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  698) 		if (blocknum != 0xff && len != 31) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  699) 		    /* All blocks but the last must have 31 data bytes. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  700) 			result = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  701) 			if (ssif_info->ssif_debug & SSIF_DEBUG_MSG)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  702) 				dev_dbg(&ssif_info->client->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  703) 					"Received middle message <31\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  704) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  705) 			goto continue_op;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  706) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  707) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  708) 		if (ssif_info->multi_len + len > IPMI_MAX_MSG_LENGTH) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  709) 			/* Received message too big, abort the operation. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  710) 			result = -E2BIG;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  711) 			if (ssif_info->ssif_debug & SSIF_DEBUG_MSG)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  712) 				dev_dbg(&ssif_info->client->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  713) 					"Received message too big\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  714) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  715) 			goto continue_op;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  716) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  717) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  718) 		for (i = 0; i < len; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  719) 			ssif_info->data[i + ssif_info->multi_len] = data[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  720) 		ssif_info->multi_len += len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  721) 		if (blocknum == 0xff) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  722) 			/* End of read */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  723) 			len = ssif_info->multi_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  724) 			data = ssif_info->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  725) 		} else if (blocknum + 1 != ssif_info->multi_pos) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  726) 			/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  727) 			 * Out of sequence block, just abort.  Block
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  728) 			 * numbers start at zero for the second block,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  729) 			 * but multi_pos starts at one, so the +1.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  730) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  731) 			if (ssif_info->ssif_debug & SSIF_DEBUG_MSG)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  732) 				dev_dbg(&ssif_info->client->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  733) 					"Received message out of sequence, expected %u, got %u\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  734) 					ssif_info->multi_pos - 1, blocknum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  735) 			result = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  736) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  737) 			ssif_inc_stat(ssif_info, received_message_parts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  738) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  739) 			ssif_info->multi_pos++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  740) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  741) 			rv = ssif_i2c_send(ssif_info, msg_done_handler,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  742) 					   I2C_SMBUS_READ,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  743) 					   SSIF_IPMI_MULTI_PART_RESPONSE_MIDDLE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  744) 					   ssif_info->recv,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  745) 					   I2C_SMBUS_BLOCK_DATA);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  746) 			if (rv < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  747) 				if (ssif_info->ssif_debug & SSIF_DEBUG_MSG)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  748) 					dev_dbg(&ssif_info->client->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  749) 						"Error from ssif_i2c_send\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  750) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  751) 				result = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  752) 			} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  753) 				return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  754) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  755) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  756) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  757)  continue_op:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  758) 	if (result < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  759) 		ssif_inc_stat(ssif_info, receive_errors);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  760) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  761) 		ssif_inc_stat(ssif_info, received_messages);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  762) 		ssif_inc_stat(ssif_info, received_message_parts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  763) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  764) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  765) 	if (ssif_info->ssif_debug & SSIF_DEBUG_STATE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  766) 		dev_dbg(&ssif_info->client->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  767) 			"DONE 1: state = %d, result=%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  768) 			ssif_info->ssif_state, result);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  769) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  770) 	flags = ipmi_ssif_lock_cond(ssif_info, &oflags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  771) 	msg = ssif_info->curr_msg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  772) 	if (msg) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  773) 		if (data) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  774) 			if (len > IPMI_MAX_MSG_LENGTH)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  775) 				len = IPMI_MAX_MSG_LENGTH;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  776) 			memcpy(msg->rsp, data, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  777) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  778) 			len = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  779) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  780) 		msg->rsp_size = len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  781) 		ssif_info->curr_msg = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  782) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  783) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  784) 	switch (ssif_info->ssif_state) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  785) 	case SSIF_NORMAL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  786) 		ipmi_ssif_unlock_cond(ssif_info, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  787) 		if (!msg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  788) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  789) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  790) 		if (result < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  791) 			return_hosed_msg(ssif_info, msg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  792) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  793) 			deliver_recv_msg(ssif_info, msg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  794) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  795) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  796) 	case SSIF_GETTING_FLAGS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  797) 		/* We got the flags from the SSIF, now handle them. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  798) 		if ((result < 0) || (len < 4) || (data[2] != 0)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  799) 			/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  800) 			 * Error fetching flags, or invalid length,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  801) 			 * just give up for now.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  802) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  803) 			ssif_info->ssif_state = SSIF_NORMAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  804) 			ipmi_ssif_unlock_cond(ssif_info, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  805) 			dev_warn(&ssif_info->client->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  806) 				 "Error getting flags: %d %d, %x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  807) 				 result, len, (len >= 3) ? data[2] : 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  808) 		} else if (data[0] != (IPMI_NETFN_APP_REQUEST | 1) << 2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  809) 			   || data[1] != IPMI_GET_MSG_FLAGS_CMD) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  810) 			/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  811) 			 * Don't abort here, maybe it was a queued
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  812) 			 * response to a previous command.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  813) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  814) 			ipmi_ssif_unlock_cond(ssif_info, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  815) 			dev_warn(&ssif_info->client->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  816) 				 "Invalid response getting flags: %x %x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  817) 				 data[0], data[1]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  818) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  819) 			ssif_inc_stat(ssif_info, flag_fetches);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  820) 			ssif_info->msg_flags = data[3];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  821) 			handle_flags(ssif_info, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  822) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  823) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  824) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  825) 	case SSIF_CLEARING_FLAGS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  826) 		/* We cleared the flags. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  827) 		if ((result < 0) || (len < 3) || (data[2] != 0)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  828) 			/* Error clearing flags */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  829) 			dev_warn(&ssif_info->client->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  830) 				 "Error clearing flags: %d %d, %x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  831) 				 result, len, (len >= 3) ? data[2] : 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  832) 		} else if (data[0] != (IPMI_NETFN_APP_REQUEST | 1) << 2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  833) 			   || data[1] != IPMI_CLEAR_MSG_FLAGS_CMD) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  834) 			dev_warn(&ssif_info->client->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  835) 				 "Invalid response clearing flags: %x %x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  836) 				 data[0], data[1]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  837) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  838) 		ssif_info->ssif_state = SSIF_NORMAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  839) 		ipmi_ssif_unlock_cond(ssif_info, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  840) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  841) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  842) 	case SSIF_GETTING_EVENTS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  843) 		if ((result < 0) || (len < 3) || (msg->rsp[2] != 0)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  844) 			/* Error getting event, probably done. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  845) 			msg->done(msg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  846) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  847) 			/* Take off the event flag. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  848) 			ssif_info->msg_flags &= ~EVENT_MSG_BUFFER_FULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  849) 			handle_flags(ssif_info, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  850) 		} else if (msg->rsp[0] != (IPMI_NETFN_APP_REQUEST | 1) << 2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  851) 			   || msg->rsp[1] != IPMI_READ_EVENT_MSG_BUFFER_CMD) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  852) 			dev_warn(&ssif_info->client->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  853) 				 "Invalid response getting events: %x %x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  854) 				 msg->rsp[0], msg->rsp[1]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  855) 			msg->done(msg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  856) 			/* Take off the event flag. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  857) 			ssif_info->msg_flags &= ~EVENT_MSG_BUFFER_FULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  858) 			handle_flags(ssif_info, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  859) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  860) 			handle_flags(ssif_info, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  861) 			ssif_inc_stat(ssif_info, events);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  862) 			deliver_recv_msg(ssif_info, msg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  863) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  864) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  865) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  866) 	case SSIF_GETTING_MESSAGES:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  867) 		if ((result < 0) || (len < 3) || (msg->rsp[2] != 0)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  868) 			/* Error getting event, probably done. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  869) 			msg->done(msg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  870) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  871) 			/* Take off the msg flag. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  872) 			ssif_info->msg_flags &= ~RECEIVE_MSG_AVAIL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  873) 			handle_flags(ssif_info, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  874) 		} else if (msg->rsp[0] != (IPMI_NETFN_APP_REQUEST | 1) << 2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  875) 			   || msg->rsp[1] != IPMI_GET_MSG_CMD) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  876) 			dev_warn(&ssif_info->client->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  877) 				 "Invalid response clearing flags: %x %x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  878) 				 msg->rsp[0], msg->rsp[1]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  879) 			msg->done(msg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  880) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  881) 			/* Take off the msg flag. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  882) 			ssif_info->msg_flags &= ~RECEIVE_MSG_AVAIL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  883) 			handle_flags(ssif_info, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  884) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  885) 			ssif_inc_stat(ssif_info, incoming_messages);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  886) 			handle_flags(ssif_info, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  887) 			deliver_recv_msg(ssif_info, msg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  888) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  889) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  890) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  891) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  892) 	flags = ipmi_ssif_lock_cond(ssif_info, &oflags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  893) 	if (SSIF_IDLE(ssif_info) && !ssif_info->stopping) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  894) 		if (ssif_info->req_events)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  895) 			start_event_fetch(ssif_info, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  896) 		else if (ssif_info->req_flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  897) 			start_flag_fetch(ssif_info, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  898) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  899) 			start_next_msg(ssif_info, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  900) 	} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  901) 		ipmi_ssif_unlock_cond(ssif_info, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  902) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  903) 	if (ssif_info->ssif_debug & SSIF_DEBUG_STATE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  904) 		dev_dbg(&ssif_info->client->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  905) 			"DONE 2: state = %d.\n", ssif_info->ssif_state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  906) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  907) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  908) static void msg_written_handler(struct ssif_info *ssif_info, int result,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  909) 				unsigned char *data, unsigned int len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  910) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  911) 	int rv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  912) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  913) 	/* We are single-threaded here, so no need for a lock. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  914) 	if (result < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  915) 		ssif_info->retries_left--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  916) 		if (ssif_info->retries_left > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  917) 			if (!start_resend(ssif_info)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  918) 				ssif_inc_stat(ssif_info, send_retries);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  919) 				return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  920) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  921) 			/* request failed, just return the error. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  922) 			ssif_inc_stat(ssif_info, send_errors);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  923) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  924) 			if (ssif_info->ssif_debug & SSIF_DEBUG_MSG)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  925) 				dev_dbg(&ssif_info->client->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  926) 					"%s: Out of retries\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  927) 			msg_done_handler(ssif_info, -EIO, NULL, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  928) 			return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  929) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  930) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  931) 		ssif_inc_stat(ssif_info, send_errors);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  932) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  933) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  934) 		 * Got an error on transmit, let the done routine
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  935) 		 * handle it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  936) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  937) 		if (ssif_info->ssif_debug & SSIF_DEBUG_MSG)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  938) 			dev_dbg(&ssif_info->client->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  939) 				"%s: Error  %d\n", __func__, result);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  940) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  941) 		msg_done_handler(ssif_info, result, NULL, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  942) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  943) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  944) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  945) 	if (ssif_info->multi_data) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  946) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  947) 		 * In the middle of a multi-data write.  See the comment
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  948) 		 * in the SSIF_MULTI_n_PART case in the probe function
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  949) 		 * for details on the intricacies of this.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  950) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  951) 		int left, to_write;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  952) 		unsigned char *data_to_send;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  953) 		unsigned char cmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  954) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  955) 		ssif_inc_stat(ssif_info, sent_messages_parts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  956) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  957) 		left = ssif_info->multi_len - ssif_info->multi_pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  958) 		to_write = left;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  959) 		if (to_write > 32)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  960) 			to_write = 32;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  961) 		/* Length byte. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  962) 		ssif_info->multi_data[ssif_info->multi_pos] = to_write;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  963) 		data_to_send = ssif_info->multi_data + ssif_info->multi_pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  964) 		ssif_info->multi_pos += to_write;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  965) 		cmd = SSIF_IPMI_MULTI_PART_REQUEST_MIDDLE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  966) 		if (ssif_info->cmd8_works) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  967) 			if (left == to_write) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  968) 				cmd = SSIF_IPMI_MULTI_PART_REQUEST_END;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  969) 				ssif_info->multi_data = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  970) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  971) 		} else if (to_write < 32) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  972) 			ssif_info->multi_data = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  973) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  974) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  975) 		rv = ssif_i2c_send(ssif_info, msg_written_handler,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  976) 				   I2C_SMBUS_WRITE, cmd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  977) 				   data_to_send, I2C_SMBUS_BLOCK_DATA);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  978) 		if (rv < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  979) 			/* request failed, just return the error. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  980) 			ssif_inc_stat(ssif_info, send_errors);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  981) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  982) 			if (ssif_info->ssif_debug & SSIF_DEBUG_MSG)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  983) 				dev_dbg(&ssif_info->client->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  984) 					"Error from i2c_non_blocking_op(3)\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  985) 			msg_done_handler(ssif_info, -EIO, NULL, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  986) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  987) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  988) 		/* Ready to request the result. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  989) 		unsigned long oflags, *flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  990) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  991) 		ssif_inc_stat(ssif_info, sent_messages);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  992) 		ssif_inc_stat(ssif_info, sent_messages_parts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  993) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  994) 		flags = ipmi_ssif_lock_cond(ssif_info, &oflags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  995) 		if (ssif_info->got_alert) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  996) 			/* The result is already ready, just start it. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  997) 			ssif_info->got_alert = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  998) 			ipmi_ssif_unlock_cond(ssif_info, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  999) 			start_get(ssif_info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1000) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1001) 			/* Wait a jiffie then request the next message */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1002) 			ssif_info->waiting_alert = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1003) 			ssif_info->retries_left = SSIF_RECV_RETRIES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1004) 			ssif_info->rtc_us_timer = SSIF_MSG_PART_USEC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1005) 			if (!ssif_info->stopping)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1006) 				mod_timer(&ssif_info->retry_timer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1007) 					  jiffies + SSIF_MSG_PART_JIFFIES);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1008) 			ipmi_ssif_unlock_cond(ssif_info, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1009) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1010) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1011) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1012) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1013) static int start_resend(struct ssif_info *ssif_info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1014) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1015) 	int rv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1016) 	int command;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1017) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1018) 	ssif_info->got_alert = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1019) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1020) 	if (ssif_info->data_len > 32) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1021) 		command = SSIF_IPMI_MULTI_PART_REQUEST_START;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1022) 		ssif_info->multi_data = ssif_info->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1023) 		ssif_info->multi_len = ssif_info->data_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1024) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1025) 		 * Subtle thing, this is 32, not 33, because we will
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1026) 		 * overwrite the thing at position 32 (which was just
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1027) 		 * transmitted) with the new length.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1028) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1029) 		ssif_info->multi_pos = 32;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1030) 		ssif_info->data[0] = 32;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1031) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1032) 		ssif_info->multi_data = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1033) 		command = SSIF_IPMI_REQUEST;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1034) 		ssif_info->data[0] = ssif_info->data_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1035) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1036) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1037) 	rv = ssif_i2c_send(ssif_info, msg_written_handler, I2C_SMBUS_WRITE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1038) 			  command, ssif_info->data, I2C_SMBUS_BLOCK_DATA);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1039) 	if (rv && (ssif_info->ssif_debug & SSIF_DEBUG_MSG))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1040) 		dev_dbg(&ssif_info->client->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1041) 			"Error from i2c_non_blocking_op(4)\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1042) 	return rv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1043) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1044) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1045) static int start_send(struct ssif_info *ssif_info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1046) 		      unsigned char   *data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1047) 		      unsigned int    len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1048) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1049) 	if (len > IPMI_MAX_MSG_LENGTH)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1050) 		return -E2BIG;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1051) 	if (len > ssif_info->max_xmit_msg_size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1052) 		return -E2BIG;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1053) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1054) 	ssif_info->retries_left = SSIF_SEND_RETRIES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1055) 	memcpy(ssif_info->data + 1, data, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1056) 	ssif_info->data_len = len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1057) 	return start_resend(ssif_info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1058) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1059) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1060) /* Must be called with the message lock held. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1061) static void start_next_msg(struct ssif_info *ssif_info, unsigned long *flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1062) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1063) 	struct ipmi_smi_msg *msg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1064) 	unsigned long oflags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1065) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1066)  restart:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1067) 	if (!SSIF_IDLE(ssif_info)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1068) 		ipmi_ssif_unlock_cond(ssif_info, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1069) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1070) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1071) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1072) 	if (!ssif_info->waiting_msg) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1073) 		ssif_info->curr_msg = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1074) 		ipmi_ssif_unlock_cond(ssif_info, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1075) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1076) 		int rv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1077) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1078) 		ssif_info->curr_msg = ssif_info->waiting_msg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1079) 		ssif_info->waiting_msg = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1080) 		ipmi_ssif_unlock_cond(ssif_info, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1081) 		rv = start_send(ssif_info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1082) 				ssif_info->curr_msg->data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1083) 				ssif_info->curr_msg->data_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1084) 		if (rv) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1085) 			msg = ssif_info->curr_msg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1086) 			ssif_info->curr_msg = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1087) 			return_hosed_msg(ssif_info, msg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1088) 			flags = ipmi_ssif_lock_cond(ssif_info, &oflags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1089) 			goto restart;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1090) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1091) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1092) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1093) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1094) static void sender(void                *send_info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1095) 		   struct ipmi_smi_msg *msg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1096) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1097) 	struct ssif_info *ssif_info = (struct ssif_info *) send_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1098) 	unsigned long oflags, *flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1099) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1100) 	BUG_ON(ssif_info->waiting_msg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1101) 	ssif_info->waiting_msg = msg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1102) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1103) 	flags = ipmi_ssif_lock_cond(ssif_info, &oflags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1104) 	start_next_msg(ssif_info, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1105) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1106) 	if (ssif_info->ssif_debug & SSIF_DEBUG_TIMING) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1107) 		struct timespec64 t;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1108) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1109) 		ktime_get_real_ts64(&t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1110) 		dev_dbg(&ssif_info->client->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1111) 			"**Enqueue %02x %02x: %lld.%6.6ld\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1112) 			msg->data[0], msg->data[1],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1113) 			(long long)t.tv_sec, (long)t.tv_nsec / NSEC_PER_USEC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1114) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1115) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1116) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1117) static int get_smi_info(void *send_info, struct ipmi_smi_info *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1118) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1119) 	struct ssif_info *ssif_info = send_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1120) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1121) 	data->addr_src = ssif_info->addr_source;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1122) 	data->dev = &ssif_info->client->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1123) 	data->addr_info = ssif_info->addr_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1124) 	get_device(data->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1125) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1126) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1127) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1128) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1129) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1130)  * Upper layer wants us to request events.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1131)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1132) static void request_events(void *send_info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1133) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1134) 	struct ssif_info *ssif_info = (struct ssif_info *) send_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1135) 	unsigned long oflags, *flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1136) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1137) 	if (!ssif_info->has_event_buffer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1138) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1139) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1140) 	flags = ipmi_ssif_lock_cond(ssif_info, &oflags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1141) 	ssif_info->req_events = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1142) 	ipmi_ssif_unlock_cond(ssif_info, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1143) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1144) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1145) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1146)  * Upper layer is changing the flag saying whether we need to request
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1147)  * flags periodically or not.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1148)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1149) static void ssif_set_need_watch(void *send_info, unsigned int watch_mask)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1150) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1151) 	struct ssif_info *ssif_info = (struct ssif_info *) send_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1152) 	unsigned long oflags, *flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1153) 	long timeout = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1154) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1155) 	if (watch_mask & IPMI_WATCH_MASK_CHECK_MESSAGES)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1156) 		timeout = SSIF_WATCH_MSG_TIMEOUT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1157) 	else if (watch_mask)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1158) 		timeout = SSIF_WATCH_WATCHDOG_TIMEOUT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1159) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1160) 	flags = ipmi_ssif_lock_cond(ssif_info, &oflags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1161) 	if (timeout != ssif_info->watch_timeout) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1162) 		ssif_info->watch_timeout = timeout;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1163) 		if (ssif_info->watch_timeout)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1164) 			mod_timer(&ssif_info->watch_timer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1165) 				  jiffies + ssif_info->watch_timeout);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1166) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1167) 	ipmi_ssif_unlock_cond(ssif_info, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1168) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1169) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1170) static int ssif_start_processing(void            *send_info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1171) 				 struct ipmi_smi *intf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1172) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1173) 	struct ssif_info *ssif_info = send_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1174) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1175) 	ssif_info->intf = intf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1176) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1177) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1178) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1179) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1180) #define MAX_SSIF_BMCS 4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1181) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1182) static unsigned short addr[MAX_SSIF_BMCS];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1183) static int num_addrs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1184) module_param_array(addr, ushort, &num_addrs, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1185) MODULE_PARM_DESC(addr, "The addresses to scan for IPMI BMCs on the SSIFs.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1186) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1187) static char *adapter_name[MAX_SSIF_BMCS];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1188) static int num_adapter_names;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1189) module_param_array(adapter_name, charp, &num_adapter_names, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1190) MODULE_PARM_DESC(adapter_name, "The string name of the I2C device that has the BMC.  By default all devices are scanned.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1191) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1192) static int slave_addrs[MAX_SSIF_BMCS];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1193) static int num_slave_addrs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1194) module_param_array(slave_addrs, int, &num_slave_addrs, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1195) MODULE_PARM_DESC(slave_addrs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1196) 		 "The default IPMB slave address for the controller.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1197) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1198) static bool alerts_broken;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1199) module_param(alerts_broken, bool, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1200) MODULE_PARM_DESC(alerts_broken, "Don't enable alerts for the controller.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1201) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1202) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1203)  * Bit 0 enables message debugging, bit 1 enables state debugging, and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1204)  * bit 2 enables timing debugging.  This is an array indexed by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1205)  * interface number"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1206)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1207) static int dbg[MAX_SSIF_BMCS];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1208) static int num_dbg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1209) module_param_array(dbg, int, &num_dbg, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1210) MODULE_PARM_DESC(dbg, "Turn on debugging.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1211) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1212) static bool ssif_dbg_probe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1213) module_param_named(dbg_probe, ssif_dbg_probe, bool, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1214) MODULE_PARM_DESC(dbg_probe, "Enable debugging of probing of adapters.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1215) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1216) static bool ssif_tryacpi = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1217) module_param_named(tryacpi, ssif_tryacpi, bool, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1218) MODULE_PARM_DESC(tryacpi, "Setting this to zero will disable the default scan of the interfaces identified via ACPI");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1219) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1220) static bool ssif_trydmi = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1221) module_param_named(trydmi, ssif_trydmi, bool, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1222) MODULE_PARM_DESC(trydmi, "Setting this to zero will disable the default scan of the interfaces identified via DMI (SMBIOS)");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1223) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1224) static DEFINE_MUTEX(ssif_infos_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1225) static LIST_HEAD(ssif_infos);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1226) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1227) #define IPMI_SSIF_ATTR(name) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1228) static ssize_t ipmi_##name##_show(struct device *dev,			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1229) 				  struct device_attribute *attr,	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1230) 				  char *buf)				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1231) {									\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1232) 	struct ssif_info *ssif_info = dev_get_drvdata(dev);		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1233) 									\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1234) 	return snprintf(buf, 10, "%u\n", ssif_get_stat(ssif_info, name));\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1235) }									\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1236) static DEVICE_ATTR(name, S_IRUGO, ipmi_##name##_show, NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1237) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1238) static ssize_t ipmi_type_show(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1239) 			      struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1240) 			      char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1241) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1242) 	return snprintf(buf, 10, "ssif\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1243) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1244) static DEVICE_ATTR(type, S_IRUGO, ipmi_type_show, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1245) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1246) IPMI_SSIF_ATTR(sent_messages);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1247) IPMI_SSIF_ATTR(sent_messages_parts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1248) IPMI_SSIF_ATTR(send_retries);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1249) IPMI_SSIF_ATTR(send_errors);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1250) IPMI_SSIF_ATTR(received_messages);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1251) IPMI_SSIF_ATTR(received_message_parts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1252) IPMI_SSIF_ATTR(receive_retries);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1253) IPMI_SSIF_ATTR(receive_errors);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1254) IPMI_SSIF_ATTR(flag_fetches);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1255) IPMI_SSIF_ATTR(hosed);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1256) IPMI_SSIF_ATTR(events);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1257) IPMI_SSIF_ATTR(watchdog_pretimeouts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1258) IPMI_SSIF_ATTR(alerts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1259) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1260) static struct attribute *ipmi_ssif_dev_attrs[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1261) 	&dev_attr_type.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1262) 	&dev_attr_sent_messages.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1263) 	&dev_attr_sent_messages_parts.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1264) 	&dev_attr_send_retries.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1265) 	&dev_attr_send_errors.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1266) 	&dev_attr_received_messages.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1267) 	&dev_attr_received_message_parts.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1268) 	&dev_attr_receive_retries.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1269) 	&dev_attr_receive_errors.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1270) 	&dev_attr_flag_fetches.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1271) 	&dev_attr_hosed.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1272) 	&dev_attr_events.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1273) 	&dev_attr_watchdog_pretimeouts.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1274) 	&dev_attr_alerts.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1275) 	NULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1276) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1277) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1278) static const struct attribute_group ipmi_ssif_dev_attr_group = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1279) 	.attrs		= ipmi_ssif_dev_attrs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1280) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1281) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1282) static void shutdown_ssif(void *send_info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1283) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1284) 	struct ssif_info *ssif_info = send_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1285) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1286) 	device_remove_group(&ssif_info->client->dev, &ipmi_ssif_dev_attr_group);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1287) 	dev_set_drvdata(&ssif_info->client->dev, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1288) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1289) 	/* make sure the driver is not looking for flags any more. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1290) 	while (ssif_info->ssif_state != SSIF_NORMAL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1291) 		schedule_timeout(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1292) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1293) 	ssif_info->stopping = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1294) 	del_timer_sync(&ssif_info->watch_timer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1295) 	del_timer_sync(&ssif_info->retry_timer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1296) 	if (ssif_info->thread) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1297) 		complete(&ssif_info->wake_thread);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1298) 		kthread_stop(ssif_info->thread);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1299) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1300) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1301) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1302) static int ssif_remove(struct i2c_client *client)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1303) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1304) 	struct ssif_info *ssif_info = i2c_get_clientdata(client);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1305) 	struct ssif_addr_info *addr_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1306) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1307) 	if (!ssif_info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1308) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1309) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1310) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1311) 	 * After this point, we won't deliver anything asychronously
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1312) 	 * to the message handler.  We can unregister ourself.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1313) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1314) 	ipmi_unregister_smi(ssif_info->intf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1315) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1316) 	list_for_each_entry(addr_info, &ssif_infos, link) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1317) 		if (addr_info->client == client) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1318) 			addr_info->client = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1319) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1320) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1321) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1322) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1323) 	kfree(ssif_info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1324) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1325) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1326) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1327) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1328) static int read_response(struct i2c_client *client, unsigned char *resp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1329) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1330) 	int ret = -ENODEV, retry_cnt = SSIF_RECV_RETRIES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1331) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1332) 	while (retry_cnt > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1333) 		ret = i2c_smbus_read_block_data(client, SSIF_IPMI_RESPONSE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1334) 						resp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1335) 		if (ret > 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1336) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1337) 		msleep(SSIF_MSG_MSEC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1338) 		retry_cnt--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1339) 		if (retry_cnt <= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1340) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1341) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1342) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1343) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1344) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1345) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1346) static int do_cmd(struct i2c_client *client, int len, unsigned char *msg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1347) 		  int *resp_len, unsigned char *resp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1348) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1349) 	int retry_cnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1350) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1351) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1352) 	retry_cnt = SSIF_SEND_RETRIES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1353)  retry1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1354) 	ret = i2c_smbus_write_block_data(client, SSIF_IPMI_REQUEST, len, msg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1355) 	if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1356) 		retry_cnt--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1357) 		if (retry_cnt > 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1358) 			goto retry1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1359) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1360) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1361) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1362) 	ret = read_response(client, resp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1363) 	if (ret > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1364) 		/* Validate that the response is correct. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1365) 		if (ret < 3 ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1366) 		    (resp[0] != (msg[0] | (1 << 2))) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1367) 		    (resp[1] != msg[1]))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1368) 			ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1369) 		else if (ret > IPMI_MAX_MSG_LENGTH) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1370) 			ret = -E2BIG;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1371) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1372) 			*resp_len = ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1373) 			ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1374) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1375) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1376) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1377) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1378) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1379) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1380) static int ssif_detect(struct i2c_client *client, struct i2c_board_info *info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1381) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1382) 	unsigned char *resp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1383) 	unsigned char msg[3];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1384) 	int           rv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1385) 	int           len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1386) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1387) 	resp = kmalloc(IPMI_MAX_MSG_LENGTH, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1388) 	if (!resp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1389) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1390) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1391) 	/* Do a Get Device ID command, since it is required. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1392) 	msg[0] = IPMI_NETFN_APP_REQUEST << 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1393) 	msg[1] = IPMI_GET_DEVICE_ID_CMD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1394) 	rv = do_cmd(client, 2, msg, &len, resp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1395) 	if (rv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1396) 		rv = -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1397) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1398) 		strlcpy(info->type, DEVICE_NAME, I2C_NAME_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1399) 	kfree(resp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1400) 	return rv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1401) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1402) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1403) static int strcmp_nospace(char *s1, char *s2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1404) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1405) 	while (*s1 && *s2) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1406) 		while (isspace(*s1))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1407) 			s1++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1408) 		while (isspace(*s2))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1409) 			s2++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1410) 		if (*s1 > *s2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1411) 			return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1412) 		if (*s1 < *s2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1413) 			return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1414) 		s1++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1415) 		s2++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1416) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1417) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1418) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1419) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1420) static struct ssif_addr_info *ssif_info_find(unsigned short addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1421) 					     char *adapter_name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1422) 					     bool match_null_name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1423) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1424) 	struct ssif_addr_info *info, *found = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1425) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1426) restart:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1427) 	list_for_each_entry(info, &ssif_infos, link) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1428) 		if (info->binfo.addr == addr) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1429) 			if (info->addr_src == SI_SMBIOS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1430) 				info->adapter_name = kstrdup(adapter_name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1431) 							     GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1432) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1433) 			if (info->adapter_name || adapter_name) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1434) 				if (!info->adapter_name != !adapter_name) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1435) 					/* One is NULL and one is not */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1436) 					continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1437) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1438) 				if (adapter_name &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1439) 				    strcmp_nospace(info->adapter_name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1440) 						   adapter_name))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1441) 					/* Names do not match */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1442) 					continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1443) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1444) 			found = info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1445) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1446) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1447) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1448) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1449) 	if (!found && match_null_name) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1450) 		/* Try to get an exact match first, then try with a NULL name */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1451) 		adapter_name = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1452) 		match_null_name = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1453) 		goto restart;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1454) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1455) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1456) 	return found;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1457) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1458) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1459) static bool check_acpi(struct ssif_info *ssif_info, struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1460) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1461) #ifdef CONFIG_ACPI
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1462) 	acpi_handle acpi_handle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1463) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1464) 	acpi_handle = ACPI_HANDLE(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1465) 	if (acpi_handle) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1466) 		ssif_info->addr_source = SI_ACPI;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1467) 		ssif_info->addr_info.acpi_info.acpi_handle = acpi_handle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1468) 		request_module("acpi_ipmi");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1469) 		return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1470) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1471) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1472) 	return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1473) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1474) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1475) static int find_slave_address(struct i2c_client *client, int slave_addr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1476) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1477) #ifdef CONFIG_IPMI_DMI_DECODE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1478) 	if (!slave_addr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1479) 		slave_addr = ipmi_dmi_get_slave_addr(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1480) 			SI_TYPE_INVALID,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1481) 			i2c_adapter_id(client->adapter),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1482) 			client->addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1483) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1484) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1485) 	return slave_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1486) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1487) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1488) static int start_multipart_test(struct i2c_client *client,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1489) 				unsigned char *msg, bool do_middle)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1490) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1491) 	int retry_cnt = SSIF_SEND_RETRIES, ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1492) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1493) retry_write:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1494) 	ret = i2c_smbus_write_block_data(client,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1495) 					 SSIF_IPMI_MULTI_PART_REQUEST_START,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1496) 					 32, msg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1497) 	if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1498) 		retry_cnt--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1499) 		if (retry_cnt > 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1500) 			goto retry_write;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1501) 		dev_err(&client->dev, "Could not write multi-part start, though the BMC said it could handle it.  Just limit sends to one part.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1502) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1503) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1504) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1505) 	if (!do_middle)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1506) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1507) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1508) 	ret = i2c_smbus_write_block_data(client,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1509) 					 SSIF_IPMI_MULTI_PART_REQUEST_MIDDLE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1510) 					 32, msg + 32);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1511) 	if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1512) 		dev_err(&client->dev, "Could not write multi-part middle, though the BMC said it could handle it.  Just limit sends to one part.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1513) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1514) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1515) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1516) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1517) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1518) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1519) static void test_multipart_messages(struct i2c_client *client,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1520) 				    struct ssif_info *ssif_info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1521) 				    unsigned char *resp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1522) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1523) 	unsigned char msg[65];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1524) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1525) 	bool do_middle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1526) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1527) 	if (ssif_info->max_xmit_msg_size <= 32)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1528) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1529) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1530) 	do_middle = ssif_info->max_xmit_msg_size > 63;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1531) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1532) 	memset(msg, 0, sizeof(msg));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1533) 	msg[0] = IPMI_NETFN_APP_REQUEST << 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1534) 	msg[1] = IPMI_GET_DEVICE_ID_CMD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1535) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1536) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1537) 	 * The specification is all messed up dealing with sending
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1538) 	 * multi-part messages.  Per what the specification says, it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1539) 	 * is impossible to send a message that is a multiple of 32
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1540) 	 * bytes, except for 32 itself.  It talks about a "start"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1541) 	 * transaction (cmd=6) that must be 32 bytes, "middle"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1542) 	 * transaction (cmd=7) that must be 32 bytes, and an "end"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1543) 	 * transaction.  The "end" transaction is shown as cmd=7 in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1544) 	 * the text, but if that's the case there is no way to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1545) 	 * differentiate between a middle and end part except the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1546) 	 * length being less than 32.  But there is a table at the far
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1547) 	 * end of the section (that I had never noticed until someone
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1548) 	 * pointed it out to me) that mentions it as cmd=8.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1549) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1550) 	 * After some thought, I think the example is wrong and the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1551) 	 * end transaction should be cmd=8.  But some systems don't
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1552) 	 * implement cmd=8, they use a zero-length end transaction,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1553) 	 * even though that violates the SMBus specification.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1554) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1555) 	 * So, to work around this, this code tests if cmd=8 works.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1556) 	 * If it does, then we use that.  If not, it tests zero-
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1557) 	 * byte end transactions.  If that works, good.  If not,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1558) 	 * we only allow 63-byte transactions max.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1559) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1560) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1561) 	ret = start_multipart_test(client, msg, do_middle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1562) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1563) 		goto out_no_multi_part;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1564) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1565) 	ret = i2c_smbus_write_block_data(client,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1566) 					 SSIF_IPMI_MULTI_PART_REQUEST_END,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1567) 					 1, msg + 64);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1568) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1569) 	if (!ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1570) 		ret = read_response(client, resp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1571) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1572) 	if (ret > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1573) 		/* End transactions work, we are good. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1574) 		ssif_info->cmd8_works = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1575) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1576) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1577) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1578) 	ret = start_multipart_test(client, msg, do_middle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1579) 	if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1580) 		dev_err(&client->dev, "Second multipart test failed.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1581) 		goto out_no_multi_part;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1582) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1583) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1584) 	ret = i2c_smbus_write_block_data(client,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1585) 					 SSIF_IPMI_MULTI_PART_REQUEST_MIDDLE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1586) 					 0, msg + 64);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1587) 	if (!ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1588) 		ret = read_response(client, resp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1589) 	if (ret > 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1590) 		/* Zero-size end parts work, use those. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1591) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1592) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1593) 	/* Limit to 63 bytes and use a short middle command to mark the end. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1594) 	if (ssif_info->max_xmit_msg_size > 63)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1595) 		ssif_info->max_xmit_msg_size = 63;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1596) 	return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1597) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1598) out_no_multi_part:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1599) 	ssif_info->max_xmit_msg_size = 32;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1600) 	return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1601) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1602) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1603) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1604)  * Global enables we care about.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1605)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1606) #define GLOBAL_ENABLES_MASK (IPMI_BMC_EVT_MSG_BUFF | IPMI_BMC_RCV_MSG_INTR | \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1607) 			     IPMI_BMC_EVT_MSG_INTR)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1608) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1609) static void ssif_remove_dup(struct i2c_client *client)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1610) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1611) 	struct ssif_info *ssif_info = i2c_get_clientdata(client);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1612) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1613) 	ipmi_unregister_smi(ssif_info->intf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1614) 	kfree(ssif_info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1615) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1616) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1617) static int ssif_add_infos(struct i2c_client *client)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1618) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1619) 	struct ssif_addr_info *info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1620) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1621) 	info = kzalloc(sizeof(*info), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1622) 	if (!info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1623) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1624) 	info->addr_src = SI_ACPI;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1625) 	info->client = client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1626) 	info->adapter_name = kstrdup(client->adapter->name, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1627) 	info->binfo.addr = client->addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1628) 	list_add_tail(&info->link, &ssif_infos);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1629) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1630) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1631) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1632) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1633)  * Prefer ACPI over SMBIOS, if both are available.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1634)  * So if we get an ACPI interface and have already registered a SMBIOS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1635)  * interface at the same address, remove the SMBIOS and add the ACPI one.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1636)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1637) static int ssif_check_and_remove(struct i2c_client *client,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1638) 			      struct ssif_info *ssif_info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1639) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1640) 	struct ssif_addr_info *info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1641) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1642) 	list_for_each_entry(info, &ssif_infos, link) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1643) 		if (!info->client)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1644) 			return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1645) 		if (!strcmp(info->adapter_name, client->adapter->name) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1646) 		    info->binfo.addr == client->addr) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1647) 			if (info->addr_src == SI_ACPI)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1648) 				return -EEXIST;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1649) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1650) 			if (ssif_info->addr_source == SI_ACPI &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1651) 			    info->addr_src == SI_SMBIOS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1652) 				dev_info(&client->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1653) 					 "Removing %s-specified SSIF interface in favor of ACPI\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1654) 					 ipmi_addr_src_to_str(info->addr_src));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1655) 				ssif_remove_dup(info->client);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1656) 				return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1657) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1658) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1659) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1660) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1661) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1662) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1663) static int ssif_probe(struct i2c_client *client, const struct i2c_device_id *id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1664) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1665) 	unsigned char     msg[3];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1666) 	unsigned char     *resp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1667) 	struct ssif_info   *ssif_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1668) 	int               rv = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1669) 	int               len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1670) 	int               i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1671) 	u8		  slave_addr = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1672) 	struct ssif_addr_info *addr_info = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1673) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1674) 	mutex_lock(&ssif_infos_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1675) 	resp = kmalloc(IPMI_MAX_MSG_LENGTH, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1676) 	if (!resp) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1677) 		mutex_unlock(&ssif_infos_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1678) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1679) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1680) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1681) 	ssif_info = kzalloc(sizeof(*ssif_info), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1682) 	if (!ssif_info) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1683) 		kfree(resp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1684) 		mutex_unlock(&ssif_infos_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1685) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1686) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1687) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1688) 	if (!check_acpi(ssif_info, &client->dev)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1689) 		addr_info = ssif_info_find(client->addr, client->adapter->name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1690) 					   true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1691) 		if (!addr_info) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1692) 			/* Must have come in through sysfs. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1693) 			ssif_info->addr_source = SI_HOTMOD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1694) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1695) 			ssif_info->addr_source = addr_info->addr_src;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1696) 			ssif_info->ssif_debug = addr_info->debug;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1697) 			ssif_info->addr_info = addr_info->addr_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1698) 			addr_info->client = client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1699) 			slave_addr = addr_info->slave_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1700) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1701) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1702) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1703) 	ssif_info->client = client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1704) 	i2c_set_clientdata(client, ssif_info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1705) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1706) 	rv = ssif_check_and_remove(client, ssif_info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1707) 	/* If rv is 0 and addr source is not SI_ACPI, continue probing */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1708) 	if (!rv && ssif_info->addr_source == SI_ACPI) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1709) 		rv = ssif_add_infos(client);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1710) 		if (rv) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1711) 			dev_err(&client->dev, "Out of memory!, exiting ..\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1712) 			goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1713) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1714) 	} else if (rv) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1715) 		dev_err(&client->dev, "Not probing, Interface already present\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1716) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1717) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1718) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1719) 	slave_addr = find_slave_address(client, slave_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1720) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1721) 	dev_info(&client->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1722) 		 "Trying %s-specified SSIF interface at i2c address 0x%x, adapter %s, slave address 0x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1723) 		ipmi_addr_src_to_str(ssif_info->addr_source),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1724) 		client->addr, client->adapter->name, slave_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1725) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1726) 	/* Now check for system interface capabilities */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1727) 	msg[0] = IPMI_NETFN_APP_REQUEST << 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1728) 	msg[1] = IPMI_GET_SYSTEM_INTERFACE_CAPABILITIES_CMD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1729) 	msg[2] = 0; /* SSIF */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1730) 	rv = do_cmd(client, 3, msg, &len, resp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1731) 	if (!rv && (len >= 3) && (resp[2] == 0)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1732) 		if (len < 7) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1733) 			if (ssif_dbg_probe)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1734) 				dev_dbg(&ssif_info->client->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1735) 					"SSIF info too short: %d\n", len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1736) 			goto no_support;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1737) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1738) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1739) 		/* Got a good SSIF response, handle it. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1740) 		ssif_info->max_xmit_msg_size = resp[5];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1741) 		ssif_info->max_recv_msg_size = resp[6];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1742) 		ssif_info->multi_support = (resp[4] >> 6) & 0x3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1743) 		ssif_info->supports_pec = (resp[4] >> 3) & 0x1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1744) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1745) 		/* Sanitize the data */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1746) 		switch (ssif_info->multi_support) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1747) 		case SSIF_NO_MULTI:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1748) 			if (ssif_info->max_xmit_msg_size > 32)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1749) 				ssif_info->max_xmit_msg_size = 32;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1750) 			if (ssif_info->max_recv_msg_size > 32)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1751) 				ssif_info->max_recv_msg_size = 32;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1752) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1753) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1754) 		case SSIF_MULTI_2_PART:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1755) 			if (ssif_info->max_xmit_msg_size > 63)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1756) 				ssif_info->max_xmit_msg_size = 63;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1757) 			if (ssif_info->max_recv_msg_size > 62)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1758) 				ssif_info->max_recv_msg_size = 62;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1759) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1760) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1761) 		case SSIF_MULTI_n_PART:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1762) 			/* We take whatever size given, but do some testing. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1763) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1764) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1765) 		default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1766) 			/* Data is not sane, just give up. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1767) 			goto no_support;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1768) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1769) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1770)  no_support:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1771) 		/* Assume no multi-part or PEC support */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1772) 		dev_info(&ssif_info->client->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1773) 			 "Error fetching SSIF: %d %d %2.2x, your system probably doesn't support this command so using defaults\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1774) 			rv, len, resp[2]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1775) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1776) 		ssif_info->max_xmit_msg_size = 32;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1777) 		ssif_info->max_recv_msg_size = 32;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1778) 		ssif_info->multi_support = SSIF_NO_MULTI;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1779) 		ssif_info->supports_pec = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1780) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1781) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1782) 	test_multipart_messages(client, ssif_info, resp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1783) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1784) 	/* Make sure the NMI timeout is cleared. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1785) 	msg[0] = IPMI_NETFN_APP_REQUEST << 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1786) 	msg[1] = IPMI_CLEAR_MSG_FLAGS_CMD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1787) 	msg[2] = WDT_PRE_TIMEOUT_INT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1788) 	rv = do_cmd(client, 3, msg, &len, resp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1789) 	if (rv || (len < 3) || (resp[2] != 0))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1790) 		dev_warn(&ssif_info->client->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1791) 			 "Unable to clear message flags: %d %d %2.2x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1792) 			 rv, len, resp[2]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1793) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1794) 	/* Attempt to enable the event buffer. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1795) 	msg[0] = IPMI_NETFN_APP_REQUEST << 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1796) 	msg[1] = IPMI_GET_BMC_GLOBAL_ENABLES_CMD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1797) 	rv = do_cmd(client, 2, msg, &len, resp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1798) 	if (rv || (len < 4) || (resp[2] != 0)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1799) 		dev_warn(&ssif_info->client->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1800) 			 "Error getting global enables: %d %d %2.2x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1801) 			 rv, len, resp[2]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1802) 		rv = 0; /* Not fatal */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1803) 		goto found;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1804) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1805) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1806) 	ssif_info->global_enables = resp[3];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1807) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1808) 	if (resp[3] & IPMI_BMC_EVT_MSG_BUFF) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1809) 		ssif_info->has_event_buffer = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1810) 		/* buffer is already enabled, nothing to do. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1811) 		goto found;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1812) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1813) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1814) 	msg[0] = IPMI_NETFN_APP_REQUEST << 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1815) 	msg[1] = IPMI_SET_BMC_GLOBAL_ENABLES_CMD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1816) 	msg[2] = ssif_info->global_enables | IPMI_BMC_EVT_MSG_BUFF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1817) 	rv = do_cmd(client, 3, msg, &len, resp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1818) 	if (rv || (len < 2)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1819) 		dev_warn(&ssif_info->client->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1820) 			 "Error setting global enables: %d %d %2.2x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1821) 			 rv, len, resp[2]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1822) 		rv = 0; /* Not fatal */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1823) 		goto found;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1824) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1825) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1826) 	if (resp[2] == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1827) 		/* A successful return means the event buffer is supported. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1828) 		ssif_info->has_event_buffer = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1829) 		ssif_info->global_enables |= IPMI_BMC_EVT_MSG_BUFF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1830) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1831) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1832) 	/* Some systems don't behave well if you enable alerts. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1833) 	if (alerts_broken)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1834) 		goto found;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1835) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1836) 	msg[0] = IPMI_NETFN_APP_REQUEST << 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1837) 	msg[1] = IPMI_SET_BMC_GLOBAL_ENABLES_CMD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1838) 	msg[2] = ssif_info->global_enables | IPMI_BMC_RCV_MSG_INTR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1839) 	rv = do_cmd(client, 3, msg, &len, resp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1840) 	if (rv || (len < 2)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1841) 		dev_warn(&ssif_info->client->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1842) 			 "Error setting global enables: %d %d %2.2x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1843) 			 rv, len, resp[2]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1844) 		rv = 0; /* Not fatal */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1845) 		goto found;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1846) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1847) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1848) 	if (resp[2] == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1849) 		/* A successful return means the alert is supported. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1850) 		ssif_info->supports_alert = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1851) 		ssif_info->global_enables |= IPMI_BMC_RCV_MSG_INTR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1852) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1853) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1854)  found:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1855) 	if (ssif_dbg_probe) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1856) 		dev_dbg(&ssif_info->client->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1857) 		       "%s: i2c_probe found device at i2c address %x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1858) 		       __func__, client->addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1859) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1860) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1861) 	spin_lock_init(&ssif_info->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1862) 	ssif_info->ssif_state = SSIF_NORMAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1863) 	timer_setup(&ssif_info->retry_timer, retry_timeout, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1864) 	timer_setup(&ssif_info->watch_timer, watch_timeout, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1865) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1866) 	for (i = 0; i < SSIF_NUM_STATS; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1867) 		atomic_set(&ssif_info->stats[i], 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1868) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1869) 	if (ssif_info->supports_pec)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1870) 		ssif_info->client->flags |= I2C_CLIENT_PEC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1871) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1872) 	ssif_info->handlers.owner = THIS_MODULE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1873) 	ssif_info->handlers.start_processing = ssif_start_processing;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1874) 	ssif_info->handlers.shutdown = shutdown_ssif;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1875) 	ssif_info->handlers.get_smi_info = get_smi_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1876) 	ssif_info->handlers.sender = sender;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1877) 	ssif_info->handlers.request_events = request_events;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1878) 	ssif_info->handlers.set_need_watch = ssif_set_need_watch;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1879) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1880) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1881) 		unsigned int thread_num;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1882) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1883) 		thread_num = ((i2c_adapter_id(ssif_info->client->adapter)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1884) 			       << 8) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1885) 			      ssif_info->client->addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1886) 		init_completion(&ssif_info->wake_thread);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1887) 		ssif_info->thread = kthread_run(ipmi_ssif_thread, ssif_info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1888) 					       "kssif%4.4x", thread_num);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1889) 		if (IS_ERR(ssif_info->thread)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1890) 			rv = PTR_ERR(ssif_info->thread);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1891) 			dev_notice(&ssif_info->client->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1892) 				   "Could not start kernel thread: error %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1893) 				   rv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1894) 			goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1895) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1896) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1897) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1898) 	dev_set_drvdata(&ssif_info->client->dev, ssif_info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1899) 	rv = device_add_group(&ssif_info->client->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1900) 			      &ipmi_ssif_dev_attr_group);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1901) 	if (rv) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1902) 		dev_err(&ssif_info->client->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1903) 			"Unable to add device attributes: error %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1904) 			rv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1905) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1906) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1907) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1908) 	rv = ipmi_register_smi(&ssif_info->handlers,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1909) 			       ssif_info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1910) 			       &ssif_info->client->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1911) 			       slave_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1912) 	if (rv) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1913) 		dev_err(&ssif_info->client->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1914) 			"Unable to register device: error %d\n", rv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1915) 		goto out_remove_attr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1916) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1917) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1918)  out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1919) 	if (rv) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1920) 		if (addr_info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1921) 			addr_info->client = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1922) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1923) 		dev_err(&ssif_info->client->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1924) 			"Unable to start IPMI SSIF: %d\n", rv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1925) 		i2c_set_clientdata(client, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1926) 		kfree(ssif_info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1927) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1928) 	kfree(resp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1929) 	mutex_unlock(&ssif_infos_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1930) 	return rv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1931) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1932) out_remove_attr:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1933) 	device_remove_group(&ssif_info->client->dev, &ipmi_ssif_dev_attr_group);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1934) 	dev_set_drvdata(&ssif_info->client->dev, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1935) 	goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1936) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1937) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1938) static int new_ssif_client(int addr, char *adapter_name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1939) 			   int debug, int slave_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1940) 			   enum ipmi_addr_src addr_src,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1941) 			   struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1942) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1943) 	struct ssif_addr_info *addr_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1944) 	int rv = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1945) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1946) 	mutex_lock(&ssif_infos_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1947) 	if (ssif_info_find(addr, adapter_name, false)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1948) 		rv = -EEXIST;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1949) 		goto out_unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1950) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1951) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1952) 	addr_info = kzalloc(sizeof(*addr_info), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1953) 	if (!addr_info) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1954) 		rv = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1955) 		goto out_unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1956) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1957) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1958) 	if (adapter_name) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1959) 		addr_info->adapter_name = kstrdup(adapter_name, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1960) 		if (!addr_info->adapter_name) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1961) 			kfree(addr_info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1962) 			rv = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1963) 			goto out_unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1964) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1965) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1966) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1967) 	strncpy(addr_info->binfo.type, DEVICE_NAME,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1968) 		sizeof(addr_info->binfo.type));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1969) 	addr_info->binfo.addr = addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1970) 	addr_info->binfo.platform_data = addr_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1971) 	addr_info->debug = debug;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1972) 	addr_info->slave_addr = slave_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1973) 	addr_info->addr_src = addr_src;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1974) 	addr_info->dev = dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1975) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1976) 	if (dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1977) 		dev_set_drvdata(dev, addr_info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1978) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1979) 	list_add_tail(&addr_info->link, &ssif_infos);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1980) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1981) 	/* Address list will get it */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1982) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1983) out_unlock:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1984) 	mutex_unlock(&ssif_infos_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1985) 	return rv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1986) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1987) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1988) static void free_ssif_clients(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1989) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1990) 	struct ssif_addr_info *info, *tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1991) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1992) 	mutex_lock(&ssif_infos_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1993) 	list_for_each_entry_safe(info, tmp, &ssif_infos, link) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1994) 		list_del(&info->link);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1995) 		kfree(info->adapter_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1996) 		kfree(info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1997) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1998) 	mutex_unlock(&ssif_infos_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1999) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2000) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2001) static unsigned short *ssif_address_list(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2002) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2003) 	struct ssif_addr_info *info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2004) 	unsigned int count = 0, i = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2005) 	unsigned short *address_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2006) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2007) 	list_for_each_entry(info, &ssif_infos, link)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2008) 		count++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2009) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2010) 	address_list = kcalloc(count + 1, sizeof(*address_list),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2011) 			       GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2012) 	if (!address_list)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2013) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2014) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2015) 	list_for_each_entry(info, &ssif_infos, link) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2016) 		unsigned short addr = info->binfo.addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2017) 		int j;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2018) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2019) 		for (j = 0; j < i; j++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2020) 			if (address_list[j] == addr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2021) 				/* Found a dup. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2022) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2023) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2024) 		if (j == i) /* Didn't find it in the list. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2025) 			address_list[i++] = addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2026) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2027) 	address_list[i] = I2C_CLIENT_END;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2028) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2029) 	return address_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2030) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2031) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2032) #ifdef CONFIG_ACPI
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2033) static const struct acpi_device_id ssif_acpi_match[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2034) 	{ "IPI0001", 0 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2035) 	{ },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2036) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2037) MODULE_DEVICE_TABLE(acpi, ssif_acpi_match);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2038) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2039) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2040) #ifdef CONFIG_DMI
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2041) static int dmi_ipmi_probe(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2042) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2043) 	u8 slave_addr = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2044) 	u16 i2c_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2045) 	int rv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2046) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2047) 	if (!ssif_trydmi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2048) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2049) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2050) 	rv = device_property_read_u16(&pdev->dev, "i2c-addr", &i2c_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2051) 	if (rv) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2052) 		dev_warn(&pdev->dev, "No i2c-addr property\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2053) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2054) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2055) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2056) 	rv = device_property_read_u8(&pdev->dev, "slave-addr", &slave_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2057) 	if (rv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2058) 		slave_addr = 0x20;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2059) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2060) 	return new_ssif_client(i2c_addr, NULL, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2061) 			       slave_addr, SI_SMBIOS, &pdev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2062) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2063) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2064) static int dmi_ipmi_probe(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2065) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2066) 	return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2067) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2068) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2069) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2070) static const struct i2c_device_id ssif_id[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2071) 	{ DEVICE_NAME, 0 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2072) 	{ }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2073) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2074) MODULE_DEVICE_TABLE(i2c, ssif_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2075) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2076) static struct i2c_driver ssif_i2c_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2077) 	.class		= I2C_CLASS_HWMON,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2078) 	.driver		= {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2079) 		.name			= DEVICE_NAME
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2080) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2081) 	.probe		= ssif_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2082) 	.remove		= ssif_remove,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2083) 	.alert		= ssif_alert,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2084) 	.id_table	= ssif_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2085) 	.detect		= ssif_detect
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2086) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2087) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2088) static int ssif_platform_probe(struct platform_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2089) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2090) 	return dmi_ipmi_probe(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2091) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2092) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2093) static int ssif_platform_remove(struct platform_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2094) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2095) 	struct ssif_addr_info *addr_info = dev_get_drvdata(&dev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2096) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2097) 	if (!addr_info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2098) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2099) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2100) 	mutex_lock(&ssif_infos_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2101) 	list_del(&addr_info->link);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2102) 	kfree(addr_info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2103) 	mutex_unlock(&ssif_infos_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2104) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2105) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2106) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2107) static const struct platform_device_id ssif_plat_ids[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2108)     { "dmi-ipmi-ssif", 0 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2109)     { }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2110) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2111) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2112) static struct platform_driver ipmi_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2113) 	.driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2114) 		.name = DEVICE_NAME,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2115) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2116) 	.probe		= ssif_platform_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2117) 	.remove		= ssif_platform_remove,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2118) 	.id_table       = ssif_plat_ids
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2119) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2120) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2121) static int init_ipmi_ssif(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2122) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2123) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2124) 	int rv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2125) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2126) 	if (initialized)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2127) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2128) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2129) 	pr_info("IPMI SSIF Interface driver\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2130) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2131) 	/* build list for i2c from addr list */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2132) 	for (i = 0; i < num_addrs; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2133) 		rv = new_ssif_client(addr[i], adapter_name[i],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2134) 				     dbg[i], slave_addrs[i],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2135) 				     SI_HARDCODED, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2136) 		if (rv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2137) 			pr_err("Couldn't add hardcoded device at addr 0x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2138) 			       addr[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2139) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2140) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2141) 	if (ssif_tryacpi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2142) 		ssif_i2c_driver.driver.acpi_match_table	=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2143) 			ACPI_PTR(ssif_acpi_match);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2144) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2145) 	if (ssif_trydmi) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2146) 		rv = platform_driver_register(&ipmi_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2147) 		if (rv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2148) 			pr_err("Unable to register driver: %d\n", rv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2149) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2150) 			platform_registered = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2151) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2152) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2153) 	ssif_i2c_driver.address_list = ssif_address_list();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2154) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2155) 	rv = i2c_add_driver(&ssif_i2c_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2156) 	if (!rv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2157) 		initialized = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2158) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2159) 	return rv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2160) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2161) module_init(init_ipmi_ssif);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2162) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2163) static void cleanup_ipmi_ssif(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2164) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2165) 	if (!initialized)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2166) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2167) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2168) 	initialized = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2169) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2170) 	i2c_del_driver(&ssif_i2c_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2171) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2172) 	kfree(ssif_i2c_driver.address_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2173) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2174) 	if (ssif_trydmi && platform_registered)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2175) 		platform_driver_unregister(&ipmi_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2176) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2177) 	free_ssif_clients();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2178) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2179) module_exit(cleanup_ipmi_ssif);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2180) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2181) MODULE_ALIAS("platform:dmi-ipmi-ssif");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2182) MODULE_AUTHOR("Todd C Davis <todd.c.davis@intel.com>, Corey Minyard <minyard@acm.org>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2183) MODULE_DESCRIPTION("IPMI driver for management controllers on a SMBus");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2184) MODULE_LICENSE("GPL");