brintos

brintos / linux-shallow public Read only

0
0
Text · 10.9 KiB · 56d1abf Raw
295 lines · c
1/* SPDX-License-Identifier: GPL-2.0 */2/* Copyright(c) 2013 - 2018 Intel Corporation. */3 4#ifndef _FM10K_MBX_H_5#define _FM10K_MBX_H_6 7/* forward declaration */8struct fm10k_mbx_info;9 10#include "fm10k_type.h"11#include "fm10k_tlv.h"12 13/* PF Mailbox Registers */14#define FM10K_MBMEM(_n)		((_n) + 0x18000)15#define FM10K_MBMEM_VF(_n, _m)	(((_n) * 0x10) + (_m) + 0x18000)16#define FM10K_MBMEM_SM(_n)	((_n) + 0x18400)17#define FM10K_MBMEM_PF(_n)	((_n) + 0x18600)18/* XOR provides means of switching from Tx to Rx FIFO */19#define FM10K_MBMEM_PF_XOR	(FM10K_MBMEM_SM(0) ^ FM10K_MBMEM_PF(0))20#define FM10K_MBX(_n)		((_n) + 0x18800)21#define FM10K_MBX_REQ				0x0000000222#define FM10K_MBX_ACK				0x0000000423#define FM10K_MBX_REQ_INTERRUPT			0x0000000824#define FM10K_MBX_ACK_INTERRUPT			0x0000001025#define FM10K_MBX_INTERRUPT_ENABLE		0x0000002026#define FM10K_MBX_INTERRUPT_DISABLE		0x0000004027#define FM10K_MBX_GLOBAL_REQ_INTERRUPT		0x0000020028#define FM10K_MBX_GLOBAL_ACK_INTERRUPT		0x0000040029#define FM10K_MBICR(_n)		((_n) + 0x18840)30#define FM10K_GMBX		0x1884231 32/* VF Mailbox Registers */33#define FM10K_VFMBX		0x0001034#define FM10K_VFMBMEM(_n)	((_n) + 0x00020)35#define FM10K_VFMBMEM_LEN	1636#define FM10K_VFMBMEM_VF_XOR	(FM10K_VFMBMEM_LEN / 2)37 38/* Delays/timeouts */39#define FM10K_MBX_DISCONNECT_TIMEOUT		50040#define FM10K_MBX_POLL_DELAY			1941#define FM10K_MBX_INT_DELAY			2042 43/* PF/VF Mailbox state machine44 *45 * +----------+	    connect()	+----------+46 * |  CLOSED  | --------------> |  CONNECT |47 * +----------+			+----------+48 *   ^				  ^	 |49 *   | rcv:	      rcv:	  |	 | rcv:50 *   |  Connect	       Disconnect |	 |  Connect51 *   |  Disconnect     Error	  |	 |  Data52 *   |				  |	 |53 *   |				  |	 V54 * +----------+   disconnect()	+----------+55 * |DISCONNECT| <-------------- |   OPEN   |56 * +----------+			+----------+57 *58 * The diagram above describes the PF/VF mailbox state machine.  There59 * are four main states to this machine.60 * Closed: This state represents a mailbox that is in a standby state61 *	   with interrupts disabled.  In this state the mailbox should not62 *	   read the mailbox or write any data.  The only means of exiting63 *	   this state is for the system to make the connect() call for the64 *	   mailbox, it will then transition to the connect state.65 * Connect: In this state the mailbox is seeking a connection.  It will66 *	    post a connect message with no specified destination and will67 *	    wait for a reply from the other side of the mailbox.  This state68 *	    is exited when either a connect with the local mailbox as the69 *	    destination is received or when a data message is received with70 *	    a valid sequence number.71 * Open: In this state the mailbox is able to transfer data between the local72 *       entity and the remote.  It will fall back to connect in the event of73 *       receiving either an error message, or a disconnect message.  It will74 *       transition to disconnect on a call to disconnect();75 * Disconnect: In this state the mailbox is attempting to gracefully terminate76 *	       the connection.  It will do so at the first point where it knows77 *	       that the remote endpoint is either done sending, or when the78 *	       remote endpoint has fallen back into connect.79 */80enum fm10k_mbx_state {81	FM10K_STATE_CLOSED,82	FM10K_STATE_CONNECT,83	FM10K_STATE_OPEN,84	FM10K_STATE_DISCONNECT,85};86 87/* PF/VF Mailbox header format88 *    3			  2		      1			  089 *  1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 090 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+91 * |        Size/Err_no/CRC        | Rsvd0 | Head  | Tail  | Type  |92 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+93 *94 * The layout above describes the format for the header used in the PF/VF95 * mailbox.  The header is broken out into the following fields:96 * Type: There are 4 supported message types97 *		0x8: Data header - used to transport message data98 *		0xC: Connect header - used to establish connection99 *		0xD: Disconnect header - used to tear down a connection100 *		0xE: Error header - used to address message exceptions101 * Tail: Tail index for local FIFO102 *		Tail index actually consists of two parts.  The MSB of103 *		the head is a loop tracker, it is 0 on an even numbered104 *		loop through the FIFO, and 1 on the odd numbered loops.105 *		To get the actual mailbox offset based on the tail it106 *		is necessary to add bit 3 to bit 0 and clear bit 3.  This107 *		gives us a valid range of 0x1 - 0xE.108 * Head: Head index for remote FIFO109 *		Head index follows the same format as the tail index.110 * Rsvd0: Reserved 0 portion of the mailbox header111 * CRC: Running CRC for all data since connect plus current message header112 * Size: Maximum message size - Applies only to connect headers113 *		The maximum message size is provided during connect to avoid114 *		jamming the mailbox with messages that do not fit.115 * Err_no: Error number - Applies only to error headers116 *		The error number provides an indication of the type of error117 *		experienced.118 */119 120/* macros for retrieving and setting header values */121#define FM10K_MSG_HDR_MASK(name) \122	((0x1u << FM10K_MSG_##name##_SIZE) - 1)123#define FM10K_MSG_HDR_FIELD_SET(value, name) \124	(((u32)(value) & FM10K_MSG_HDR_MASK(name)) << FM10K_MSG_##name##_SHIFT)125#define FM10K_MSG_HDR_FIELD_GET(value, name) \126	((u16)((value) >> FM10K_MSG_##name##_SHIFT) & FM10K_MSG_HDR_MASK(name))127 128/* offsets shared between all headers */129#define FM10K_MSG_TYPE_SHIFT			0130#define FM10K_MSG_TYPE_SIZE			4131#define FM10K_MSG_TAIL_SHIFT			4132#define FM10K_MSG_TAIL_SIZE			4133#define FM10K_MSG_HEAD_SHIFT			8134#define FM10K_MSG_HEAD_SIZE			4135#define FM10K_MSG_RSVD0_SHIFT			12136#define FM10K_MSG_RSVD0_SIZE			4137 138/* offsets for data/disconnect headers */139#define FM10K_MSG_CRC_SHIFT			16140#define FM10K_MSG_CRC_SIZE			16141 142/* offsets for connect headers */143#define FM10K_MSG_CONNECT_SIZE_SHIFT		16144#define FM10K_MSG_CONNECT_SIZE_SIZE		16145 146/* offsets for error headers */147#define FM10K_MSG_ERR_NO_SHIFT			16148#define FM10K_MSG_ERR_NO_SIZE			16149 150enum fm10k_msg_type {151	FM10K_MSG_DATA			= 0x8,152	FM10K_MSG_CONNECT		= 0xC,153	FM10K_MSG_DISCONNECT		= 0xD,154	FM10K_MSG_ERROR			= 0xE,155};156 157/* HNI/SM Mailbox FIFO format158 *    3                   2                   1                   0159 *  1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0160 * +-------+-----------------------+-------+-----------------------+161 * | Error |      Remote Head      |Version|      Local Tail       |162 * +-------+-----------------------+-------+-----------------------+163 * |                                                               |164 * .                        Local FIFO Data                        .165 * .                                                               .166 * +-------+-----------------------+-------+-----------------------+167 *168 * The layout above describes the format for the FIFOs used by the host169 * network interface and the switch manager to communicate messages back170 * and forth.  Both the HNI and the switch maintain one such FIFO.  The171 * layout in memory has the switch manager FIFO followed immediately by172 * the HNI FIFO.  For this reason I am using just the pointer to the173 * HNI FIFO in the mailbox ops as the offset between the two is fixed.174 *175 * The header for the FIFO is broken out into the following fields:176 * Local Tail:  Offset into FIFO region for next DWORD to write.177 * Version:  Version info for mailbox, only values of 0/1 are supported.178 * Remote Head:  Offset into remote FIFO to indicate how much we have read.179 * Error: Error indication, values TBD.180 */181 182/* version number for switch manager mailboxes */183#define FM10K_SM_MBX_VERSION		1184#define FM10K_SM_MBX_FIFO_LEN		(FM10K_MBMEM_PF_XOR - 1)185 186/* offsets shared between all SM FIFO headers */187#define FM10K_MSG_SM_TAIL_SHIFT			0188#define FM10K_MSG_SM_TAIL_SIZE			12189#define FM10K_MSG_SM_VER_SHIFT			12190#define FM10K_MSG_SM_VER_SIZE			4191#define FM10K_MSG_SM_HEAD_SHIFT			16192#define FM10K_MSG_SM_HEAD_SIZE			12193#define FM10K_MSG_SM_ERR_SHIFT			28194#define FM10K_MSG_SM_ERR_SIZE			4195 196/* All error messages returned by mailbox functions197 * The value -511 is 0xFE01 in hex.  The idea is to order the errors198 * from 0xFE01 - 0xFEFF so error codes are easily visible in the mailbox199 * messages.  This also helps to avoid error number collisions as Linux200 * doesn't appear to use error numbers 256 - 511.201 */202#define FM10K_MBX_ERR(_n) ((_n) - 512)203#define FM10K_MBX_ERR_NO_MBX		FM10K_MBX_ERR(0x01)204#define FM10K_MBX_ERR_NO_SPACE		FM10K_MBX_ERR(0x03)205#define FM10K_MBX_ERR_TAIL		FM10K_MBX_ERR(0x05)206#define FM10K_MBX_ERR_HEAD		FM10K_MBX_ERR(0x06)207#define FM10K_MBX_ERR_SRC		FM10K_MBX_ERR(0x08)208#define FM10K_MBX_ERR_TYPE		FM10K_MBX_ERR(0x09)209#define FM10K_MBX_ERR_SIZE		FM10K_MBX_ERR(0x0B)210#define FM10K_MBX_ERR_BUSY		FM10K_MBX_ERR(0x0C)211#define FM10K_MBX_ERR_RSVD0		FM10K_MBX_ERR(0x0E)212#define FM10K_MBX_ERR_CRC		FM10K_MBX_ERR(0x0F)213 214#define FM10K_MBX_CRC_SEED		0xFFFF215 216struct fm10k_mbx_ops {217	s32 (*connect)(struct fm10k_hw *, struct fm10k_mbx_info *);218	void (*disconnect)(struct fm10k_hw *, struct fm10k_mbx_info *);219	bool (*rx_ready)(struct fm10k_mbx_info *);220	bool (*tx_ready)(struct fm10k_mbx_info *, u16);221	bool (*tx_complete)(struct fm10k_mbx_info *);222	s32 (*enqueue_tx)(struct fm10k_hw *, struct fm10k_mbx_info *,223			  const u32 *);224	s32 (*process)(struct fm10k_hw *, struct fm10k_mbx_info *);225	s32 (*register_handlers)(struct fm10k_mbx_info *,226				 const struct fm10k_msg_data *);227};228 229struct fm10k_mbx_fifo {230	u32 *buffer;231	u16 head;232	u16 tail;233	u16 size;234};235 236/* size of buffer to be stored in mailbox for FIFOs */237#define FM10K_MBX_TX_BUFFER_SIZE	512238#define FM10K_MBX_RX_BUFFER_SIZE	128239#define FM10K_MBX_BUFFER_SIZE \240	(FM10K_MBX_TX_BUFFER_SIZE + FM10K_MBX_RX_BUFFER_SIZE)241 242/* minimum and maximum message size in dwords */243#define FM10K_MBX_MSG_MAX_SIZE \244	((FM10K_MBX_TX_BUFFER_SIZE - 1) & (FM10K_MBX_RX_BUFFER_SIZE - 1))245#define FM10K_VFMBX_MSG_MTU	((FM10K_VFMBMEM_LEN / 2) - 1)246 247#define FM10K_MBX_INIT_TIMEOUT	2000 /* number of retries on mailbox */248#define FM10K_MBX_INIT_DELAY	500  /* microseconds between retries */249 250struct fm10k_mbx_info {251	/* function pointers for mailbox operations */252	struct fm10k_mbx_ops ops;253	const struct fm10k_msg_data *msg_data;254 255	/* message FIFOs */256	struct fm10k_mbx_fifo rx;257	struct fm10k_mbx_fifo tx;258 259	/* delay for handling timeouts */260	u32 timeout;261	u32 udelay;262 263	/* mailbox state info */264	u32 mbx_reg, mbmem_reg, mbx_lock, mbx_hdr;265	u16 max_size, mbmem_len;266	u16 tail, tail_len, pulled;267	u16 head, head_len, pushed;268	u16 local, remote;269	enum fm10k_mbx_state state;270 271	/* result of last mailbox test */272	s32 test_result;273 274	/* statistics */275	u64 tx_busy;276	u64 tx_dropped;277	u64 tx_messages;278	u64 tx_dwords;279	u64 tx_mbmem_pulled;280	u64 rx_messages;281	u64 rx_dwords;282	u64 rx_mbmem_pushed;283	u64 rx_parse_err;284 285	/* Buffer to store messages */286	u32 buffer[FM10K_MBX_BUFFER_SIZE];287};288 289s32 fm10k_pfvf_mbx_init(struct fm10k_hw *, struct fm10k_mbx_info *,290			const struct fm10k_msg_data *, u8);291s32 fm10k_sm_mbx_init(struct fm10k_hw *, struct fm10k_mbx_info *,292		      const struct fm10k_msg_data *);293 294#endif /* _FM10K_MBX_H_ */295