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-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    3)  * ssi_protocol.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    5)  * Implementation of the SSI McSAAB improved protocol.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    6)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    7)  * Copyright (C) 2010 Nokia Corporation. All rights reserved.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    8)  * Copyright (C) 2013 Sebastian Reichel <sre@kernel.org>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    9)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   10)  * Contact: Carlos Chinea <carlos.chinea@nokia.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   11)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   12) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   13) #include <linux/atomic.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   14) #include <linux/clk.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   15) #include <linux/device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   16) #include <linux/err.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   17) #include <linux/gpio.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   18) #include <linux/if_ether.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   19) #include <linux/if_arp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   20) #include <linux/if_phonet.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   21) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   22) #include <linux/irq.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   23) #include <linux/list.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   24) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   25) #include <linux/netdevice.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   26) #include <linux/notifier.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   27) #include <linux/scatterlist.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   28) #include <linux/skbuff.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   29) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   30) #include <linux/spinlock.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   31) #include <linux/timer.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   32) #include <linux/hsi/hsi.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   33) #include <linux/hsi/ssi_protocol.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   34) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   35) void ssi_waketest(struct hsi_client *cl, unsigned int enable);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   36) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   37) #define SSIP_TXQUEUE_LEN	100
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   38) #define SSIP_MAX_MTU		65535
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   39) #define SSIP_DEFAULT_MTU	4000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   40) #define PN_MEDIA_SOS		21
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   41) #define SSIP_MIN_PN_HDR		6	/* FIXME: Revisit */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   42) #define SSIP_WDTOUT		2000	/* FIXME: has to be 500 msecs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   43) #define SSIP_KATOUT		15	/* 15 msecs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   44) #define SSIP_MAX_CMDS		5 /* Number of pre-allocated commands buffers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   45) #define SSIP_BYTES_TO_FRAMES(x) ((((x) - 1) >> 2) + 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   46) #define SSIP_CMT_LOADER_SYNC	0x11223344
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   47) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   48)  * SSI protocol command definitions
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   49)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   50) #define SSIP_COMMAND(data)	((data) >> 28)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   51) #define SSIP_PAYLOAD(data)	((data) & 0xfffffff)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   52) /* Commands */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   53) #define SSIP_SW_BREAK		0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   54) #define SSIP_BOOTINFO_REQ	1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   55) #define SSIP_BOOTINFO_RESP	2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   56) #define SSIP_WAKETEST_RESULT	3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   57) #define SSIP_START_TRANS	4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   58) #define SSIP_READY		5
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   59) /* Payloads */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   60) #define SSIP_DATA_VERSION(data)	((data) & 0xff)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   61) #define SSIP_LOCAL_VERID	1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   62) #define SSIP_WAKETEST_OK	0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   63) #define SSIP_WAKETEST_FAILED	1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   64) #define SSIP_PDU_LENGTH(data)	(((data) >> 8) & 0xffff)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   65) #define SSIP_MSG_ID(data)	((data) & 0xff)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   66) /* Generic Command */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   67) #define SSIP_CMD(cmd, payload)	(((cmd) << 28) | ((payload) & 0xfffffff))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   68) /* Commands for the control channel */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   69) #define SSIP_BOOTINFO_REQ_CMD(ver) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   70) 		SSIP_CMD(SSIP_BOOTINFO_REQ, SSIP_DATA_VERSION(ver))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   71) #define SSIP_BOOTINFO_RESP_CMD(ver) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   72) 		SSIP_CMD(SSIP_BOOTINFO_RESP, SSIP_DATA_VERSION(ver))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   73) #define SSIP_START_TRANS_CMD(pdulen, id) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   74) 		SSIP_CMD(SSIP_START_TRANS, (((pdulen) << 8) | SSIP_MSG_ID(id)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   75) #define SSIP_READY_CMD		SSIP_CMD(SSIP_READY, 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   76) #define SSIP_SWBREAK_CMD	SSIP_CMD(SSIP_SW_BREAK, 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   77) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   78) #define SSIP_WAKETEST_FLAG 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   79) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   80) /* Main state machine states */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   81) enum {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   82) 	INIT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   83) 	HANDSHAKE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   84) 	ACTIVE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   85) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   86) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   87) /* Send state machine states */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   88) enum {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   89) 	SEND_IDLE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   90) 	WAIT4READY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   91) 	SEND_READY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   92) 	SENDING,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   93) 	SENDING_SWBREAK,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   94) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   95) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   96) /* Receive state machine states */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   97) enum {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   98) 	RECV_IDLE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   99) 	RECV_READY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  100) 	RECEIVING,
^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) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  104)  * struct ssi_protocol - SSI protocol (McSAAB) data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  105)  * @main_state: Main state machine
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  106)  * @send_state: TX state machine
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  107)  * @recv_state: RX state machine
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  108)  * @flags: Flags, currently only used to follow wake line test
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  109)  * @rxid: RX data id
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  110)  * @txid: TX data id
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  111)  * @txqueue_len: TX queue length
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  112)  * @tx_wd: TX watchdog
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  113)  * @rx_wd: RX watchdog
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  114)  * @keep_alive: Workaround for SSI HW bug
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  115)  * @lock: To serialize access to this struct
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  116)  * @netdev: Phonet network device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  117)  * @txqueue: TX data queue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  118)  * @cmdqueue: Queue of free commands
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  119)  * @cl: HSI client own reference
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  120)  * @link: Link for ssip_list
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  121)  * @tx_usecount: Refcount to keep track the slaves that use the wake line
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  122)  * @channel_id_cmd: HSI channel id for command stream
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  123)  * @channel_id_data: HSI channel id for data stream
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  124)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  125) struct ssi_protocol {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  126) 	unsigned int		main_state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  127) 	unsigned int		send_state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  128) 	unsigned int		recv_state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  129) 	unsigned long		flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  130) 	u8			rxid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  131) 	u8			txid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  132) 	unsigned int		txqueue_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  133) 	struct timer_list	tx_wd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  134) 	struct timer_list	rx_wd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  135) 	struct timer_list	keep_alive; /* wake-up workaround */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  136) 	spinlock_t		lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  137) 	struct net_device	*netdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  138) 	struct list_head	txqueue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  139) 	struct list_head	cmdqueue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  140) 	struct work_struct	work;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  141) 	struct hsi_client	*cl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  142) 	struct list_head	link;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  143) 	atomic_t		tx_usecnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  144) 	int			channel_id_cmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  145) 	int			channel_id_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  146) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  147) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  148) /* List of ssi protocol instances */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  149) static LIST_HEAD(ssip_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  150) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  151) static void ssip_rxcmd_complete(struct hsi_msg *msg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  152) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  153) static inline void ssip_set_cmd(struct hsi_msg *msg, u32 cmd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  154) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  155) 	u32 *data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  156) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  157) 	data = sg_virt(msg->sgt.sgl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  158) 	*data = cmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  159) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  160) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  161) static inline u32 ssip_get_cmd(struct hsi_msg *msg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  162) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  163) 	u32 *data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  164) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  165) 	data = sg_virt(msg->sgt.sgl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  166) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  167) 	return *data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  168) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  169) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  170) static void ssip_skb_to_msg(struct sk_buff *skb, struct hsi_msg *msg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  171) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  172) 	skb_frag_t *frag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  173) 	struct scatterlist *sg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  174) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  175) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  176) 	BUG_ON(msg->sgt.nents != (unsigned int)(skb_shinfo(skb)->nr_frags + 1));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  177) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  178) 	sg = msg->sgt.sgl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  179) 	sg_set_buf(sg, skb->data, skb_headlen(skb));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  180) 	for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  181) 		sg = sg_next(sg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  182) 		BUG_ON(!sg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  183) 		frag = &skb_shinfo(skb)->frags[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  184) 		sg_set_page(sg, skb_frag_page(frag), skb_frag_size(frag),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  185) 				skb_frag_off(frag));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  186) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  187) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  188) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  189) static void ssip_free_data(struct hsi_msg *msg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  190) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  191) 	struct sk_buff *skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  192) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  193) 	skb = msg->context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  194) 	pr_debug("free data: msg %p context %p skb %p\n", msg, msg->context,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  195) 								skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  196) 	msg->destructor = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  197) 	dev_kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  198) 	hsi_free_msg(msg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  199) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  200) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  201) static struct hsi_msg *ssip_alloc_data(struct ssi_protocol *ssi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  202) 					struct sk_buff *skb, gfp_t flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  203) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  204) 	struct hsi_msg *msg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  205) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  206) 	msg = hsi_alloc_msg(skb_shinfo(skb)->nr_frags + 1, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  207) 	if (!msg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  208) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  209) 	ssip_skb_to_msg(skb, msg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  210) 	msg->destructor = ssip_free_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  211) 	msg->channel = ssi->channel_id_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  212) 	msg->context = skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  213) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  214) 	return msg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  215) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  216) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  217) static inline void ssip_release_cmd(struct hsi_msg *msg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  218) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  219) 	struct ssi_protocol *ssi = hsi_client_drvdata(msg->cl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  220) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  221) 	dev_dbg(&msg->cl->device, "Release cmd 0x%08x\n", ssip_get_cmd(msg));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  222) 	spin_lock_bh(&ssi->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  223) 	list_add_tail(&msg->link, &ssi->cmdqueue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  224) 	spin_unlock_bh(&ssi->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  225) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  226) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  227) static struct hsi_msg *ssip_claim_cmd(struct ssi_protocol *ssi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  228) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  229) 	struct hsi_msg *msg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  230) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  231) 	BUG_ON(list_empty(&ssi->cmdqueue));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  232) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  233) 	spin_lock_bh(&ssi->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  234) 	msg = list_first_entry(&ssi->cmdqueue, struct hsi_msg, link);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  235) 	list_del(&msg->link);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  236) 	spin_unlock_bh(&ssi->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  237) 	msg->destructor = ssip_release_cmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  238) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  239) 	return msg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  240) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  241) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  242) static void ssip_free_cmds(struct ssi_protocol *ssi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  243) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  244) 	struct hsi_msg *msg, *tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  245) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  246) 	list_for_each_entry_safe(msg, tmp, &ssi->cmdqueue, link) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  247) 		list_del(&msg->link);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  248) 		msg->destructor = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  249) 		kfree(sg_virt(msg->sgt.sgl));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  250) 		hsi_free_msg(msg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  251) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  252) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  253) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  254) static int ssip_alloc_cmds(struct ssi_protocol *ssi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  255) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  256) 	struct hsi_msg *msg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  257) 	u32 *buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  258) 	unsigned int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  259) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  260) 	for (i = 0; i < SSIP_MAX_CMDS; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  261) 		msg = hsi_alloc_msg(1, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  262) 		if (!msg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  263) 			goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  264) 		buf = kmalloc(sizeof(*buf), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  265) 		if (!buf) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  266) 			hsi_free_msg(msg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  267) 			goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  268) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  269) 		sg_init_one(msg->sgt.sgl, buf, sizeof(*buf));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  270) 		msg->channel = ssi->channel_id_cmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  271) 		list_add_tail(&msg->link, &ssi->cmdqueue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  272) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  273) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  274) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  275) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  276) 	ssip_free_cmds(ssi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  277) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  278) 	return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  279) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  280) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  281) static void ssip_set_rxstate(struct ssi_protocol *ssi, unsigned int state)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  282) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  283) 	ssi->recv_state = state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  284) 	switch (state) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  285) 	case RECV_IDLE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  286) 		del_timer(&ssi->rx_wd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  287) 		if (ssi->send_state == SEND_IDLE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  288) 			del_timer(&ssi->keep_alive);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  289) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  290) 	case RECV_READY:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  291) 		/* CMT speech workaround */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  292) 		if (atomic_read(&ssi->tx_usecnt))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  293) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  294) 		fallthrough;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  295) 	case RECEIVING:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  296) 		mod_timer(&ssi->keep_alive, jiffies +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  297) 						msecs_to_jiffies(SSIP_KATOUT));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  298) 		mod_timer(&ssi->rx_wd, jiffies + msecs_to_jiffies(SSIP_WDTOUT));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  299) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  300) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  301) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  302) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  303) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  304) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  305) static void ssip_set_txstate(struct ssi_protocol *ssi, unsigned int state)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  306) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  307) 	ssi->send_state = state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  308) 	switch (state) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  309) 	case SEND_IDLE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  310) 	case SEND_READY:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  311) 		del_timer(&ssi->tx_wd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  312) 		if (ssi->recv_state == RECV_IDLE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  313) 			del_timer(&ssi->keep_alive);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  314) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  315) 	case WAIT4READY:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  316) 	case SENDING:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  317) 	case SENDING_SWBREAK:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  318) 		mod_timer(&ssi->keep_alive,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  319) 				jiffies + msecs_to_jiffies(SSIP_KATOUT));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  320) 		mod_timer(&ssi->tx_wd, jiffies + msecs_to_jiffies(SSIP_WDTOUT));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  321) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  322) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  323) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  324) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  325) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  326) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  327) struct hsi_client *ssip_slave_get_master(struct hsi_client *slave)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  328) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  329) 	struct hsi_client *master = ERR_PTR(-ENODEV);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  330) 	struct ssi_protocol *ssi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  331) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  332) 	list_for_each_entry(ssi, &ssip_list, link)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  333) 		if (slave->device.parent == ssi->cl->device.parent) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  334) 			master = ssi->cl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  335) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  336) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  337) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  338) 	return master;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  339) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  340) EXPORT_SYMBOL_GPL(ssip_slave_get_master);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  341) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  342) int ssip_slave_start_tx(struct hsi_client *master)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  343) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  344) 	struct ssi_protocol *ssi = hsi_client_drvdata(master);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  345) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  346) 	dev_dbg(&master->device, "start TX %d\n", atomic_read(&ssi->tx_usecnt));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  347) 	spin_lock_bh(&ssi->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  348) 	if (ssi->send_state == SEND_IDLE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  349) 		ssip_set_txstate(ssi, WAIT4READY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  350) 		hsi_start_tx(master);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  351) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  352) 	spin_unlock_bh(&ssi->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  353) 	atomic_inc(&ssi->tx_usecnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  354) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  355) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  356) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  357) EXPORT_SYMBOL_GPL(ssip_slave_start_tx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  358) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  359) int ssip_slave_stop_tx(struct hsi_client *master)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  360) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  361) 	struct ssi_protocol *ssi = hsi_client_drvdata(master);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  362) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  363) 	WARN_ON_ONCE(atomic_read(&ssi->tx_usecnt) == 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  364) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  365) 	if (atomic_dec_and_test(&ssi->tx_usecnt)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  366) 		spin_lock_bh(&ssi->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  367) 		if ((ssi->send_state == SEND_READY) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  368) 			(ssi->send_state == WAIT4READY)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  369) 			ssip_set_txstate(ssi, SEND_IDLE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  370) 			hsi_stop_tx(master);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  371) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  372) 		spin_unlock_bh(&ssi->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  373) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  374) 	dev_dbg(&master->device, "stop TX %d\n", atomic_read(&ssi->tx_usecnt));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  375) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  376) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  377) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  378) EXPORT_SYMBOL_GPL(ssip_slave_stop_tx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  379) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  380) int ssip_slave_running(struct hsi_client *master)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  381) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  382) 	struct ssi_protocol *ssi = hsi_client_drvdata(master);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  383) 	return netif_running(ssi->netdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  384) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  385) EXPORT_SYMBOL_GPL(ssip_slave_running);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  386) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  387) static void ssip_reset(struct hsi_client *cl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  388) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  389) 	struct ssi_protocol *ssi = hsi_client_drvdata(cl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  390) 	struct list_head *head, *tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  391) 	struct hsi_msg *msg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  392) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  393) 	if (netif_running(ssi->netdev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  394) 		netif_carrier_off(ssi->netdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  395) 	hsi_flush(cl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  396) 	spin_lock_bh(&ssi->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  397) 	if (ssi->send_state != SEND_IDLE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  398) 		hsi_stop_tx(cl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  399) 	spin_unlock_bh(&ssi->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  400) 	if (test_and_clear_bit(SSIP_WAKETEST_FLAG, &ssi->flags))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  401) 		ssi_waketest(cl, 0); /* FIXME: To be removed */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  402) 	spin_lock_bh(&ssi->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  403) 	del_timer(&ssi->rx_wd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  404) 	del_timer(&ssi->tx_wd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  405) 	del_timer(&ssi->keep_alive);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  406) 	ssi->main_state = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  407) 	ssi->send_state = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  408) 	ssi->recv_state = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  409) 	ssi->flags = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  410) 	ssi->rxid = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  411) 	ssi->txid = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  412) 	list_for_each_safe(head, tmp, &ssi->txqueue) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  413) 		msg = list_entry(head, struct hsi_msg, link);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  414) 		dev_dbg(&cl->device, "Pending TX data\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  415) 		list_del(head);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  416) 		ssip_free_data(msg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  417) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  418) 	ssi->txqueue_len = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  419) 	spin_unlock_bh(&ssi->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  420) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  421) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  422) static void ssip_dump_state(struct hsi_client *cl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  423) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  424) 	struct ssi_protocol *ssi = hsi_client_drvdata(cl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  425) 	struct hsi_msg *msg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  426) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  427) 	spin_lock_bh(&ssi->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  428) 	dev_err(&cl->device, "Main state: %d\n", ssi->main_state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  429) 	dev_err(&cl->device, "Recv state: %d\n", ssi->recv_state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  430) 	dev_err(&cl->device, "Send state: %d\n", ssi->send_state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  431) 	dev_err(&cl->device, "CMT %s\n", (ssi->main_state == ACTIVE) ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  432) 							"Online" : "Offline");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  433) 	dev_err(&cl->device, "Wake test %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  434) 				test_bit(SSIP_WAKETEST_FLAG, &ssi->flags));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  435) 	dev_err(&cl->device, "Data RX id: %d\n", ssi->rxid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  436) 	dev_err(&cl->device, "Data TX id: %d\n", ssi->txid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  437) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  438) 	list_for_each_entry(msg, &ssi->txqueue, link)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  439) 		dev_err(&cl->device, "pending TX data (%p)\n", msg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  440) 	spin_unlock_bh(&ssi->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  441) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  442) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  443) static void ssip_error(struct hsi_client *cl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  444) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  445) 	struct ssi_protocol *ssi = hsi_client_drvdata(cl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  446) 	struct hsi_msg *msg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  447) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  448) 	ssip_dump_state(cl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  449) 	ssip_reset(cl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  450) 	msg = ssip_claim_cmd(ssi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  451) 	msg->complete = ssip_rxcmd_complete;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  452) 	hsi_async_read(cl, msg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  453) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  454) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  455) static void ssip_keep_alive(struct timer_list *t)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  456) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  457) 	struct ssi_protocol *ssi = from_timer(ssi, t, keep_alive);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  458) 	struct hsi_client *cl = ssi->cl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  459) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  460) 	dev_dbg(&cl->device, "Keep alive kick in: m(%d) r(%d) s(%d)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  461) 		ssi->main_state, ssi->recv_state, ssi->send_state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  462) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  463) 	spin_lock(&ssi->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  464) 	if (ssi->recv_state == RECV_IDLE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  465) 		switch (ssi->send_state) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  466) 		case SEND_READY:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  467) 			if (atomic_read(&ssi->tx_usecnt) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  468) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  469) 			fallthrough;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  470) 			/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  471) 			 * Workaround for cmt-speech in that case
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  472) 			 * we relay on audio timers.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  473) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  474) 		case SEND_IDLE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  475) 			spin_unlock(&ssi->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  476) 			return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  477) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  478) 	mod_timer(&ssi->keep_alive, jiffies + msecs_to_jiffies(SSIP_KATOUT));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  479) 	spin_unlock(&ssi->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  480) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  481) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  482) static void ssip_rx_wd(struct timer_list *t)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  483) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  484) 	struct ssi_protocol *ssi = from_timer(ssi, t, rx_wd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  485) 	struct hsi_client *cl = ssi->cl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  486) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  487) 	dev_err(&cl->device, "Watchdog triggered\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  488) 	ssip_error(cl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  489) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  490) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  491) static void ssip_tx_wd(struct timer_list *t)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  492) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  493) 	struct ssi_protocol *ssi = from_timer(ssi, t, tx_wd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  494) 	struct hsi_client *cl = ssi->cl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  495) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  496) 	dev_err(&cl->device, "Watchdog triggered\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  497) 	ssip_error(cl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  498) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  499) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  500) static void ssip_send_bootinfo_req_cmd(struct hsi_client *cl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  501) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  502) 	struct ssi_protocol *ssi = hsi_client_drvdata(cl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  503) 	struct hsi_msg *msg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  504) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  505) 	dev_dbg(&cl->device, "Issuing BOOT INFO REQ command\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  506) 	msg = ssip_claim_cmd(ssi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  507) 	ssip_set_cmd(msg, SSIP_BOOTINFO_REQ_CMD(SSIP_LOCAL_VERID));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  508) 	msg->complete = ssip_release_cmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  509) 	hsi_async_write(cl, msg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  510) 	dev_dbg(&cl->device, "Issuing RX command\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  511) 	msg = ssip_claim_cmd(ssi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  512) 	msg->complete = ssip_rxcmd_complete;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  513) 	hsi_async_read(cl, msg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  514) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  515) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  516) static void ssip_start_rx(struct hsi_client *cl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  517) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  518) 	struct ssi_protocol *ssi = hsi_client_drvdata(cl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  519) 	struct hsi_msg *msg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  520) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  521) 	dev_dbg(&cl->device, "RX start M(%d) R(%d)\n", ssi->main_state,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  522) 						ssi->recv_state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  523) 	spin_lock_bh(&ssi->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  524) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  525) 	 * We can have two UP events in a row due to a short low
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  526) 	 * high transition. Therefore we need to ignore the sencond UP event.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  527) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  528) 	if ((ssi->main_state != ACTIVE) || (ssi->recv_state == RECV_READY)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  529) 		spin_unlock_bh(&ssi->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  530) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  531) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  532) 	ssip_set_rxstate(ssi, RECV_READY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  533) 	spin_unlock_bh(&ssi->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  534) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  535) 	msg = ssip_claim_cmd(ssi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  536) 	ssip_set_cmd(msg, SSIP_READY_CMD);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  537) 	msg->complete = ssip_release_cmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  538) 	dev_dbg(&cl->device, "Send READY\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  539) 	hsi_async_write(cl, msg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  540) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  541) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  542) static void ssip_stop_rx(struct hsi_client *cl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  543) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  544) 	struct ssi_protocol *ssi = hsi_client_drvdata(cl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  545) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  546) 	dev_dbg(&cl->device, "RX stop M(%d)\n", ssi->main_state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  547) 	spin_lock_bh(&ssi->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  548) 	if (likely(ssi->main_state == ACTIVE))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  549) 		ssip_set_rxstate(ssi, RECV_IDLE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  550) 	spin_unlock_bh(&ssi->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  551) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  552) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  553) static void ssip_free_strans(struct hsi_msg *msg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  554) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  555) 	ssip_free_data(msg->context);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  556) 	ssip_release_cmd(msg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  557) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  558) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  559) static void ssip_strans_complete(struct hsi_msg *msg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  560) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  561) 	struct hsi_client *cl = msg->cl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  562) 	struct ssi_protocol *ssi = hsi_client_drvdata(cl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  563) 	struct hsi_msg *data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  564) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  565) 	data = msg->context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  566) 	ssip_release_cmd(msg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  567) 	spin_lock_bh(&ssi->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  568) 	ssip_set_txstate(ssi, SENDING);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  569) 	spin_unlock_bh(&ssi->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  570) 	hsi_async_write(cl, data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  571) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  572) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  573) static int ssip_xmit(struct hsi_client *cl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  574) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  575) 	struct ssi_protocol *ssi = hsi_client_drvdata(cl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  576) 	struct hsi_msg *msg, *dmsg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  577) 	struct sk_buff *skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  578) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  579) 	spin_lock_bh(&ssi->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  580) 	if (list_empty(&ssi->txqueue)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  581) 		spin_unlock_bh(&ssi->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  582) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  583) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  584) 	dmsg = list_first_entry(&ssi->txqueue, struct hsi_msg, link);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  585) 	list_del(&dmsg->link);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  586) 	ssi->txqueue_len--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  587) 	spin_unlock_bh(&ssi->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  588) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  589) 	msg = ssip_claim_cmd(ssi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  590) 	skb = dmsg->context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  591) 	msg->context = dmsg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  592) 	msg->complete = ssip_strans_complete;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  593) 	msg->destructor = ssip_free_strans;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  594) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  595) 	spin_lock_bh(&ssi->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  596) 	ssip_set_cmd(msg, SSIP_START_TRANS_CMD(SSIP_BYTES_TO_FRAMES(skb->len),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  597) 								ssi->txid));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  598) 	ssi->txid++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  599) 	ssip_set_txstate(ssi, SENDING);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  600) 	spin_unlock_bh(&ssi->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  601) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  602) 	dev_dbg(&cl->device, "Send STRANS (%d frames)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  603) 						SSIP_BYTES_TO_FRAMES(skb->len));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  604) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  605) 	return hsi_async_write(cl, msg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  606) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  607) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  608) /* In soft IRQ context */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  609) static void ssip_pn_rx(struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  610) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  611) 	struct net_device *dev = skb->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  612) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  613) 	if (unlikely(!netif_running(dev))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  614) 		dev_dbg(&dev->dev, "Drop RX packet\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  615) 		dev->stats.rx_dropped++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  616) 		dev_kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  617) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  618) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  619) 	if (unlikely(!pskb_may_pull(skb, SSIP_MIN_PN_HDR))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  620) 		dev_dbg(&dev->dev, "Error drop RX packet\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  621) 		dev->stats.rx_errors++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  622) 		dev->stats.rx_length_errors++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  623) 		dev_kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  624) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  625) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  626) 	dev->stats.rx_packets++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  627) 	dev->stats.rx_bytes += skb->len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  628) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  629) 	/* length field is exchanged in network byte order */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  630) 	((u16 *)skb->data)[2] = ntohs(((u16 *)skb->data)[2]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  631) 	dev_dbg(&dev->dev, "RX length fixed (%04x -> %u)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  632) 			((u16 *)skb->data)[2], ntohs(((u16 *)skb->data)[2]));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  633) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  634) 	skb->protocol = htons(ETH_P_PHONET);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  635) 	skb_reset_mac_header(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  636) 	__skb_pull(skb, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  637) 	netif_rx(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  638) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  639) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  640) static void ssip_rx_data_complete(struct hsi_msg *msg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  641) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  642) 	struct hsi_client *cl = msg->cl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  643) 	struct ssi_protocol *ssi = hsi_client_drvdata(cl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  644) 	struct sk_buff *skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  645) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  646) 	if (msg->status == HSI_STATUS_ERROR) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  647) 		dev_err(&cl->device, "RX data error\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  648) 		ssip_free_data(msg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  649) 		ssip_error(cl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  650) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  651) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  652) 	del_timer(&ssi->rx_wd); /* FIXME: Revisit */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  653) 	skb = msg->context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  654) 	ssip_pn_rx(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  655) 	hsi_free_msg(msg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  656) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  657) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  658) static void ssip_rx_bootinforeq(struct hsi_client *cl, u32 cmd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  659) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  660) 	struct ssi_protocol *ssi = hsi_client_drvdata(cl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  661) 	struct hsi_msg *msg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  662) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  663) 	/* Workaroud: Ignore CMT Loader message leftover */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  664) 	if (cmd == SSIP_CMT_LOADER_SYNC)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  665) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  666) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  667) 	switch (ssi->main_state) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  668) 	case ACTIVE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  669) 		dev_err(&cl->device, "Boot info req on active state\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  670) 		ssip_error(cl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  671) 		fallthrough;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  672) 	case INIT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  673) 	case HANDSHAKE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  674) 		spin_lock_bh(&ssi->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  675) 		ssi->main_state = HANDSHAKE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  676) 		spin_unlock_bh(&ssi->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  677) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  678) 		if (!test_and_set_bit(SSIP_WAKETEST_FLAG, &ssi->flags))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  679) 			ssi_waketest(cl, 1); /* FIXME: To be removed */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  680) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  681) 		spin_lock_bh(&ssi->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  682) 		/* Start boot handshake watchdog */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  683) 		mod_timer(&ssi->tx_wd, jiffies + msecs_to_jiffies(SSIP_WDTOUT));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  684) 		spin_unlock_bh(&ssi->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  685) 		dev_dbg(&cl->device, "Send BOOTINFO_RESP\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  686) 		if (SSIP_DATA_VERSION(cmd) != SSIP_LOCAL_VERID)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  687) 			dev_warn(&cl->device, "boot info req verid mismatch\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  688) 		msg = ssip_claim_cmd(ssi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  689) 		ssip_set_cmd(msg, SSIP_BOOTINFO_RESP_CMD(SSIP_LOCAL_VERID));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  690) 		msg->complete = ssip_release_cmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  691) 		hsi_async_write(cl, msg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  692) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  693) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  694) 		dev_dbg(&cl->device, "Wrong state M(%d)\n", ssi->main_state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  695) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  696) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  697) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  698) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  699) static void ssip_rx_bootinforesp(struct hsi_client *cl, u32 cmd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  700) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  701) 	struct ssi_protocol *ssi = hsi_client_drvdata(cl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  702) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  703) 	if (SSIP_DATA_VERSION(cmd) != SSIP_LOCAL_VERID)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  704) 		dev_warn(&cl->device, "boot info resp verid mismatch\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  705) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  706) 	spin_lock_bh(&ssi->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  707) 	if (ssi->main_state != ACTIVE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  708) 		/* Use tx_wd as a boot watchdog in non ACTIVE state */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  709) 		mod_timer(&ssi->tx_wd, jiffies + msecs_to_jiffies(SSIP_WDTOUT));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  710) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  711) 		dev_dbg(&cl->device, "boot info resp ignored M(%d)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  712) 							ssi->main_state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  713) 	spin_unlock_bh(&ssi->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  714) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  715) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  716) static void ssip_rx_waketest(struct hsi_client *cl, u32 cmd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  717) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  718) 	struct ssi_protocol *ssi = hsi_client_drvdata(cl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  719) 	unsigned int wkres = SSIP_PAYLOAD(cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  720) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  721) 	spin_lock_bh(&ssi->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  722) 	if (ssi->main_state != HANDSHAKE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  723) 		dev_dbg(&cl->device, "wake lines test ignored M(%d)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  724) 							ssi->main_state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  725) 		spin_unlock_bh(&ssi->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  726) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  727) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  728) 	spin_unlock_bh(&ssi->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  729) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  730) 	if (test_and_clear_bit(SSIP_WAKETEST_FLAG, &ssi->flags))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  731) 		ssi_waketest(cl, 0); /* FIXME: To be removed */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  732) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  733) 	spin_lock_bh(&ssi->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  734) 	ssi->main_state = ACTIVE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  735) 	del_timer(&ssi->tx_wd); /* Stop boot handshake timer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  736) 	spin_unlock_bh(&ssi->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  737) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  738) 	dev_notice(&cl->device, "WAKELINES TEST %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  739) 				wkres & SSIP_WAKETEST_FAILED ? "FAILED" : "OK");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  740) 	if (wkres & SSIP_WAKETEST_FAILED) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  741) 		ssip_error(cl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  742) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  743) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  744) 	dev_dbg(&cl->device, "CMT is ONLINE\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  745) 	netif_wake_queue(ssi->netdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  746) 	netif_carrier_on(ssi->netdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  747) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  748) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  749) static void ssip_rx_ready(struct hsi_client *cl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  750) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  751) 	struct ssi_protocol *ssi = hsi_client_drvdata(cl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  752) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  753) 	spin_lock_bh(&ssi->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  754) 	if (unlikely(ssi->main_state != ACTIVE)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  755) 		dev_dbg(&cl->device, "READY on wrong state: S(%d) M(%d)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  756) 					ssi->send_state, ssi->main_state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  757) 		spin_unlock_bh(&ssi->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  758) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  759) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  760) 	if (ssi->send_state != WAIT4READY) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  761) 		dev_dbg(&cl->device, "Ignore spurious READY command\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  762) 		spin_unlock_bh(&ssi->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  763) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  764) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  765) 	ssip_set_txstate(ssi, SEND_READY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  766) 	spin_unlock_bh(&ssi->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  767) 	ssip_xmit(cl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  768) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  769) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  770) static void ssip_rx_strans(struct hsi_client *cl, u32 cmd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  771) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  772) 	struct ssi_protocol *ssi = hsi_client_drvdata(cl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  773) 	struct sk_buff *skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  774) 	struct hsi_msg *msg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  775) 	int len = SSIP_PDU_LENGTH(cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  776) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  777) 	dev_dbg(&cl->device, "RX strans: %d frames\n", len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  778) 	spin_lock_bh(&ssi->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  779) 	if (unlikely(ssi->main_state != ACTIVE)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  780) 		dev_err(&cl->device, "START TRANS wrong state: S(%d) M(%d)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  781) 					ssi->send_state, ssi->main_state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  782) 		spin_unlock_bh(&ssi->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  783) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  784) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  785) 	ssip_set_rxstate(ssi, RECEIVING);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  786) 	if (unlikely(SSIP_MSG_ID(cmd) != ssi->rxid)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  787) 		dev_err(&cl->device, "START TRANS id %d expected %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  788) 					SSIP_MSG_ID(cmd), ssi->rxid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  789) 		spin_unlock_bh(&ssi->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  790) 		goto out1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  791) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  792) 	ssi->rxid++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  793) 	spin_unlock_bh(&ssi->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  794) 	skb = netdev_alloc_skb(ssi->netdev, len * 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  795) 	if (unlikely(!skb)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  796) 		dev_err(&cl->device, "No memory for rx skb\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  797) 		goto out1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  798) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  799) 	skb->dev = ssi->netdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  800) 	skb_put(skb, len * 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  801) 	msg = ssip_alloc_data(ssi, skb, GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  802) 	if (unlikely(!msg)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  803) 		dev_err(&cl->device, "No memory for RX data msg\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  804) 		goto out2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  805) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  806) 	msg->complete = ssip_rx_data_complete;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  807) 	hsi_async_read(cl, msg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  808) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  809) 	return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  810) out2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  811) 	dev_kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  812) out1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  813) 	ssip_error(cl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  814) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  815) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  816) static void ssip_rxcmd_complete(struct hsi_msg *msg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  817) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  818) 	struct hsi_client *cl = msg->cl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  819) 	u32 cmd = ssip_get_cmd(msg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  820) 	unsigned int cmdid = SSIP_COMMAND(cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  821) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  822) 	if (msg->status == HSI_STATUS_ERROR) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  823) 		dev_err(&cl->device, "RX error detected\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  824) 		ssip_release_cmd(msg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  825) 		ssip_error(cl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  826) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  827) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  828) 	hsi_async_read(cl, msg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  829) 	dev_dbg(&cl->device, "RX cmd: 0x%08x\n", cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  830) 	switch (cmdid) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  831) 	case SSIP_SW_BREAK:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  832) 		/* Ignored */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  833) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  834) 	case SSIP_BOOTINFO_REQ:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  835) 		ssip_rx_bootinforeq(cl, cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  836) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  837) 	case SSIP_BOOTINFO_RESP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  838) 		ssip_rx_bootinforesp(cl, cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  839) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  840) 	case SSIP_WAKETEST_RESULT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  841) 		ssip_rx_waketest(cl, cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  842) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  843) 	case SSIP_START_TRANS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  844) 		ssip_rx_strans(cl, cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  845) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  846) 	case SSIP_READY:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  847) 		ssip_rx_ready(cl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  848) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  849) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  850) 		dev_warn(&cl->device, "command 0x%08x not supported\n", cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  851) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  852) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  853) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  854) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  855) static void ssip_swbreak_complete(struct hsi_msg *msg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  856) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  857) 	struct hsi_client *cl = msg->cl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  858) 	struct ssi_protocol *ssi = hsi_client_drvdata(cl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  859) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  860) 	ssip_release_cmd(msg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  861) 	spin_lock_bh(&ssi->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  862) 	if (list_empty(&ssi->txqueue)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  863) 		if (atomic_read(&ssi->tx_usecnt)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  864) 			ssip_set_txstate(ssi, SEND_READY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  865) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  866) 			ssip_set_txstate(ssi, SEND_IDLE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  867) 			hsi_stop_tx(cl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  868) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  869) 		spin_unlock_bh(&ssi->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  870) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  871) 		spin_unlock_bh(&ssi->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  872) 		ssip_xmit(cl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  873) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  874) 	netif_wake_queue(ssi->netdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  875) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  876) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  877) static void ssip_tx_data_complete(struct hsi_msg *msg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  878) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  879) 	struct hsi_client *cl = msg->cl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  880) 	struct ssi_protocol *ssi = hsi_client_drvdata(cl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  881) 	struct hsi_msg *cmsg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  882) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  883) 	if (msg->status == HSI_STATUS_ERROR) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  884) 		dev_err(&cl->device, "TX data error\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  885) 		ssip_error(cl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  886) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  887) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  888) 	spin_lock_bh(&ssi->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  889) 	if (list_empty(&ssi->txqueue)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  890) 		ssip_set_txstate(ssi, SENDING_SWBREAK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  891) 		spin_unlock_bh(&ssi->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  892) 		cmsg = ssip_claim_cmd(ssi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  893) 		ssip_set_cmd(cmsg, SSIP_SWBREAK_CMD);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  894) 		cmsg->complete = ssip_swbreak_complete;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  895) 		dev_dbg(&cl->device, "Send SWBREAK\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  896) 		hsi_async_write(cl, cmsg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  897) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  898) 		spin_unlock_bh(&ssi->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  899) 		ssip_xmit(cl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  900) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  901) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  902) 	ssip_free_data(msg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  903) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  904) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  905) static void ssip_port_event(struct hsi_client *cl, unsigned long event)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  906) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  907) 	switch (event) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  908) 	case HSI_EVENT_START_RX:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  909) 		ssip_start_rx(cl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  910) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  911) 	case HSI_EVENT_STOP_RX:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  912) 		ssip_stop_rx(cl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  913) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  914) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  915) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  916) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  917) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  918) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  919) static int ssip_pn_open(struct net_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  920) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  921) 	struct hsi_client *cl = to_hsi_client(dev->dev.parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  922) 	struct ssi_protocol *ssi = hsi_client_drvdata(cl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  923) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  924) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  925) 	err = hsi_claim_port(cl, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  926) 	if (err < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  927) 		dev_err(&cl->device, "SSI port already claimed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  928) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  929) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  930) 	err = hsi_register_port_event(cl, ssip_port_event);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  931) 	if (err < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  932) 		dev_err(&cl->device, "Register HSI port event failed (%d)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  933) 			err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  934) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  935) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  936) 	dev_dbg(&cl->device, "Configuring SSI port\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  937) 	hsi_setup(cl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  938) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  939) 	if (!test_and_set_bit(SSIP_WAKETEST_FLAG, &ssi->flags))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  940) 		ssi_waketest(cl, 1); /* FIXME: To be removed */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  941) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  942) 	spin_lock_bh(&ssi->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  943) 	ssi->main_state = HANDSHAKE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  944) 	spin_unlock_bh(&ssi->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  945) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  946) 	ssip_send_bootinfo_req_cmd(cl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  947) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  948) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  949) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  950) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  951) static int ssip_pn_stop(struct net_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  952) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  953) 	struct hsi_client *cl = to_hsi_client(dev->dev.parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  954) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  955) 	ssip_reset(cl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  956) 	hsi_unregister_port_event(cl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  957) 	hsi_release_port(cl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  958) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  959) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  960) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  961) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  962) static void ssip_xmit_work(struct work_struct *work)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  963) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  964) 	struct ssi_protocol *ssi =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  965) 				container_of(work, struct ssi_protocol, work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  966) 	struct hsi_client *cl = ssi->cl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  967) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  968) 	ssip_xmit(cl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  969) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  970) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  971) static int ssip_pn_xmit(struct sk_buff *skb, struct net_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  972) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  973) 	struct hsi_client *cl = to_hsi_client(dev->dev.parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  974) 	struct ssi_protocol *ssi = hsi_client_drvdata(cl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  975) 	struct hsi_msg *msg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  976) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  977) 	if ((skb->protocol != htons(ETH_P_PHONET)) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  978) 					(skb->len < SSIP_MIN_PN_HDR))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  979) 		goto drop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  980) 	/* Pad to 32-bits - FIXME: Revisit*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  981) 	if ((skb->len & 3) && skb_pad(skb, 4 - (skb->len & 3)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  982) 		goto inc_dropped;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  983) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  984) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  985) 	 * Modem sends Phonet messages over SSI with its own endianness.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  986) 	 * Assume that modem has the same endianness as we do.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  987) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  988) 	if (skb_cow_head(skb, 0))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  989) 		goto drop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  990) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  991) 	/* length field is exchanged in network byte order */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  992) 	((u16 *)skb->data)[2] = htons(((u16 *)skb->data)[2]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  993) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  994) 	msg = ssip_alloc_data(ssi, skb, GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  995) 	if (!msg) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  996) 		dev_dbg(&cl->device, "Dropping tx data: No memory\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  997) 		goto drop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  998) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  999) 	msg->complete = ssip_tx_data_complete;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1000) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1001) 	spin_lock_bh(&ssi->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1002) 	if (unlikely(ssi->main_state != ACTIVE)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1003) 		spin_unlock_bh(&ssi->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1004) 		dev_dbg(&cl->device, "Dropping tx data: CMT is OFFLINE\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1005) 		goto drop2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1006) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1007) 	list_add_tail(&msg->link, &ssi->txqueue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1008) 	ssi->txqueue_len++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1009) 	if (dev->tx_queue_len < ssi->txqueue_len) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1010) 		dev_info(&cl->device, "TX queue full %d\n", ssi->txqueue_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1011) 		netif_stop_queue(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1012) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1013) 	if (ssi->send_state == SEND_IDLE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1014) 		ssip_set_txstate(ssi, WAIT4READY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1015) 		spin_unlock_bh(&ssi->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1016) 		dev_dbg(&cl->device, "Start TX qlen %d\n", ssi->txqueue_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1017) 		hsi_start_tx(cl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1018) 	} else if (ssi->send_state == SEND_READY) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1019) 		/* Needed for cmt-speech workaround */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1020) 		dev_dbg(&cl->device, "Start TX on SEND READY qlen %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1021) 							ssi->txqueue_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1022) 		spin_unlock_bh(&ssi->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1023) 		schedule_work(&ssi->work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1024) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1025) 		spin_unlock_bh(&ssi->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1026) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1027) 	dev->stats.tx_packets++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1028) 	dev->stats.tx_bytes += skb->len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1029) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1030) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1031) drop2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1032) 	hsi_free_msg(msg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1033) drop:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1034) 	dev_kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1035) inc_dropped:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1036) 	dev->stats.tx_dropped++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1037) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1038) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1039) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1040) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1041) /* CMT reset event handler */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1042) void ssip_reset_event(struct hsi_client *master)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1043) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1044) 	struct ssi_protocol *ssi = hsi_client_drvdata(master);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1045) 	dev_err(&ssi->cl->device, "CMT reset detected!\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1046) 	ssip_error(ssi->cl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1047) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1048) EXPORT_SYMBOL_GPL(ssip_reset_event);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1049) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1050) static const struct net_device_ops ssip_pn_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1051) 	.ndo_open	= ssip_pn_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1052) 	.ndo_stop	= ssip_pn_stop,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1053) 	.ndo_start_xmit	= ssip_pn_xmit,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1054) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1055) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1056) static void ssip_pn_setup(struct net_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1057) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1058) 	dev->features		= 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1059) 	dev->netdev_ops		= &ssip_pn_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1060) 	dev->type		= ARPHRD_PHONET;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1061) 	dev->flags		= IFF_POINTOPOINT | IFF_NOARP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1062) 	dev->mtu		= SSIP_DEFAULT_MTU;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1063) 	dev->hard_header_len	= 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1064) 	dev->dev_addr[0]	= PN_MEDIA_SOS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1065) 	dev->addr_len		= 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1066) 	dev->tx_queue_len	= SSIP_TXQUEUE_LEN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1067) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1068) 	dev->needs_free_netdev	= true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1069) 	dev->header_ops		= &phonet_header_ops;
^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) static int ssi_protocol_probe(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1073) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1074) 	static const char ifname[] = "phonet%d";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1075) 	struct hsi_client *cl = to_hsi_client(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1076) 	struct ssi_protocol *ssi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1077) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1078) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1079) 	ssi = kzalloc(sizeof(*ssi), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1080) 	if (!ssi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1081) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1082) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1083) 	spin_lock_init(&ssi->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1084) 	timer_setup(&ssi->rx_wd, ssip_rx_wd, TIMER_DEFERRABLE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1085) 	timer_setup(&ssi->tx_wd, ssip_tx_wd, TIMER_DEFERRABLE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1086) 	timer_setup(&ssi->keep_alive, ssip_keep_alive, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1087) 	INIT_LIST_HEAD(&ssi->txqueue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1088) 	INIT_LIST_HEAD(&ssi->cmdqueue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1089) 	atomic_set(&ssi->tx_usecnt, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1090) 	hsi_client_set_drvdata(cl, ssi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1091) 	ssi->cl = cl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1092) 	INIT_WORK(&ssi->work, ssip_xmit_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1093) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1094) 	ssi->channel_id_cmd = hsi_get_channel_id_by_name(cl, "mcsaab-control");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1095) 	if (ssi->channel_id_cmd < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1096) 		err = ssi->channel_id_cmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1097) 		dev_err(dev, "Could not get cmd channel (%d)\n", err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1098) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1099) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1100) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1101) 	ssi->channel_id_data = hsi_get_channel_id_by_name(cl, "mcsaab-data");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1102) 	if (ssi->channel_id_data < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1103) 		err = ssi->channel_id_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1104) 		dev_err(dev, "Could not get data channel (%d)\n", err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1105) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1106) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1107) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1108) 	err = ssip_alloc_cmds(ssi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1109) 	if (err < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1110) 		dev_err(dev, "No memory for commands\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1111) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1112) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1113) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1114) 	ssi->netdev = alloc_netdev(0, ifname, NET_NAME_UNKNOWN, ssip_pn_setup);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1115) 	if (!ssi->netdev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1116) 		dev_err(dev, "No memory for netdev\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1117) 		err = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1118) 		goto out1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1119) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1120) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1121) 	/* MTU range: 6 - 65535 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1122) 	ssi->netdev->min_mtu = PHONET_MIN_MTU;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1123) 	ssi->netdev->max_mtu = SSIP_MAX_MTU;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1124) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1125) 	SET_NETDEV_DEV(ssi->netdev, dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1126) 	netif_carrier_off(ssi->netdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1127) 	err = register_netdev(ssi->netdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1128) 	if (err < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1129) 		dev_err(dev, "Register netdev failed (%d)\n", err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1130) 		goto out2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1131) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1132) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1133) 	list_add(&ssi->link, &ssip_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1134) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1135) 	dev_dbg(dev, "channel configuration: cmd=%d, data=%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1136) 		ssi->channel_id_cmd, ssi->channel_id_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1137) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1138) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1139) out2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1140) 	free_netdev(ssi->netdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1141) out1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1142) 	ssip_free_cmds(ssi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1143) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1144) 	kfree(ssi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1145) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1146) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1147) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1148) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1149) static int ssi_protocol_remove(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1150) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1151) 	struct hsi_client *cl = to_hsi_client(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1152) 	struct ssi_protocol *ssi = hsi_client_drvdata(cl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1153) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1154) 	list_del(&ssi->link);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1155) 	unregister_netdev(ssi->netdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1156) 	ssip_free_cmds(ssi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1157) 	hsi_client_set_drvdata(cl, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1158) 	kfree(ssi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1159) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1160) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1161) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1162) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1163) static struct hsi_client_driver ssip_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1164) 	.driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1165) 		.name	= "ssi-protocol",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1166) 		.owner	= THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1167) 		.probe	= ssi_protocol_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1168) 		.remove	= ssi_protocol_remove,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1169) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1170) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1171) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1172) static int __init ssip_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1173) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1174) 	pr_info("SSI protocol aka McSAAB added\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1175) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1176) 	return hsi_register_client_driver(&ssip_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1177) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1178) module_init(ssip_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1179) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1180) static void __exit ssip_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1181) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1182) 	hsi_unregister_client_driver(&ssip_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1183) 	pr_info("SSI protocol driver removed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1184) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1185) module_exit(ssip_exit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1186) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1187) MODULE_ALIAS("hsi:ssi-protocol");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1188) MODULE_AUTHOR("Carlos Chinea <carlos.chinea@nokia.com>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1189) MODULE_AUTHOR("Remi Denis-Courmont <remi.denis-courmont@nokia.com>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1190) MODULE_DESCRIPTION("SSI protocol improved aka McSAAB");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1191) MODULE_LICENSE("GPL");