linux/drivers/net/ethernet/intel/fm10k/fm10k_mbx.h

/* SPDX-License-Identifier: GPL-2.0 */
/* Copyright(c) 2013 - 2018 Intel Corporation. */

#ifndef _FM10K_MBX_H_
#define _FM10K_MBX_H_

/* forward declaration */
struct fm10k_mbx_info;

#include "fm10k_type.h"
#include "fm10k_tlv.h"

/* PF Mailbox Registers */
#define FM10K_MBMEM(_n)
#define FM10K_MBMEM_VF(_n, _m)
#define FM10K_MBMEM_SM(_n)
#define FM10K_MBMEM_PF(_n)
/* XOR provides means of switching from Tx to Rx FIFO */
#define FM10K_MBMEM_PF_XOR
#define FM10K_MBX(_n)
#define FM10K_MBX_REQ
#define FM10K_MBX_ACK
#define FM10K_MBX_REQ_INTERRUPT
#define FM10K_MBX_ACK_INTERRUPT
#define FM10K_MBX_INTERRUPT_ENABLE
#define FM10K_MBX_INTERRUPT_DISABLE
#define FM10K_MBX_GLOBAL_REQ_INTERRUPT
#define FM10K_MBX_GLOBAL_ACK_INTERRUPT
#define FM10K_MBICR(_n)
#define FM10K_GMBX

/* VF Mailbox Registers */
#define FM10K_VFMBX
#define FM10K_VFMBMEM(_n)
#define FM10K_VFMBMEM_LEN
#define FM10K_VFMBMEM_VF_XOR

/* Delays/timeouts */
#define FM10K_MBX_DISCONNECT_TIMEOUT
#define FM10K_MBX_POLL_DELAY
#define FM10K_MBX_INT_DELAY

/* PF/VF Mailbox state machine
 *
 * +----------+	    connect()	+----------+
 * |  CLOSED  | --------------> |  CONNECT |
 * +----------+			+----------+
 *   ^				  ^	 |
 *   | rcv:	      rcv:	  |	 | rcv:
 *   |  Connect	       Disconnect |	 |  Connect
 *   |  Disconnect     Error	  |	 |  Data
 *   |				  |	 |
 *   |				  |	 V
 * +----------+   disconnect()	+----------+
 * |DISCONNECT| <-------------- |   OPEN   |
 * +----------+			+----------+
 *
 * The diagram above describes the PF/VF mailbox state machine.  There
 * are four main states to this machine.
 * Closed: This state represents a mailbox that is in a standby state
 *	   with interrupts disabled.  In this state the mailbox should not
 *	   read the mailbox or write any data.  The only means of exiting
 *	   this state is for the system to make the connect() call for the
 *	   mailbox, it will then transition to the connect state.
 * Connect: In this state the mailbox is seeking a connection.  It will
 *	    post a connect message with no specified destination and will
 *	    wait for a reply from the other side of the mailbox.  This state
 *	    is exited when either a connect with the local mailbox as the
 *	    destination is received or when a data message is received with
 *	    a valid sequence number.
 * Open: In this state the mailbox is able to transfer data between the local
 *       entity and the remote.  It will fall back to connect in the event of
 *       receiving either an error message, or a disconnect message.  It will
 *       transition to disconnect on a call to disconnect();
 * Disconnect: In this state the mailbox is attempting to gracefully terminate
 *	       the connection.  It will do so at the first point where it knows
 *	       that the remote endpoint is either done sending, or when the
 *	       remote endpoint has fallen back into connect.
 */
enum fm10k_mbx_state {};

/* PF/VF Mailbox header format
 *    3			  2		      1			  0
 *  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 0
 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
 * |        Size/Err_no/CRC        | Rsvd0 | Head  | Tail  | Type  |
 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
 *
 * The layout above describes the format for the header used in the PF/VF
 * mailbox.  The header is broken out into the following fields:
 * Type: There are 4 supported message types
 *		0x8: Data header - used to transport message data
 *		0xC: Connect header - used to establish connection
 *		0xD: Disconnect header - used to tear down a connection
 *		0xE: Error header - used to address message exceptions
 * Tail: Tail index for local FIFO
 *		Tail index actually consists of two parts.  The MSB of
 *		the head is a loop tracker, it is 0 on an even numbered
 *		loop through the FIFO, and 1 on the odd numbered loops.
 *		To get the actual mailbox offset based on the tail it
 *		is necessary to add bit 3 to bit 0 and clear bit 3.  This
 *		gives us a valid range of 0x1 - 0xE.
 * Head: Head index for remote FIFO
 *		Head index follows the same format as the tail index.
 * Rsvd0: Reserved 0 portion of the mailbox header
 * CRC: Running CRC for all data since connect plus current message header
 * Size: Maximum message size - Applies only to connect headers
 *		The maximum message size is provided during connect to avoid
 *		jamming the mailbox with messages that do not fit.
 * Err_no: Error number - Applies only to error headers
 *		The error number provides an indication of the type of error
 *		experienced.
 */

/* macros for retrieving and setting header values */
#define FM10K_MSG_HDR_MASK(name)
#define FM10K_MSG_HDR_FIELD_SET(value, name)
#define FM10K_MSG_HDR_FIELD_GET(value, name)

/* offsets shared between all headers */
#define FM10K_MSG_TYPE_SHIFT
#define FM10K_MSG_TYPE_SIZE
#define FM10K_MSG_TAIL_SHIFT
#define FM10K_MSG_TAIL_SIZE
#define FM10K_MSG_HEAD_SHIFT
#define FM10K_MSG_HEAD_SIZE
#define FM10K_MSG_RSVD0_SHIFT
#define FM10K_MSG_RSVD0_SIZE

/* offsets for data/disconnect headers */
#define FM10K_MSG_CRC_SHIFT
#define FM10K_MSG_CRC_SIZE

/* offsets for connect headers */
#define FM10K_MSG_CONNECT_SIZE_SHIFT
#define FM10K_MSG_CONNECT_SIZE_SIZE

/* offsets for error headers */
#define FM10K_MSG_ERR_NO_SHIFT
#define FM10K_MSG_ERR_NO_SIZE

enum fm10k_msg_type {};

/* HNI/SM Mailbox FIFO format
 *    3                   2                   1                   0
 *  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 0
 * +-------+-----------------------+-------+-----------------------+
 * | Error |      Remote Head      |Version|      Local Tail       |
 * +-------+-----------------------+-------+-----------------------+
 * |                                                               |
 * .                        Local FIFO Data                        .
 * .                                                               .
 * +-------+-----------------------+-------+-----------------------+
 *
 * The layout above describes the format for the FIFOs used by the host
 * network interface and the switch manager to communicate messages back
 * and forth.  Both the HNI and the switch maintain one such FIFO.  The
 * layout in memory has the switch manager FIFO followed immediately by
 * the HNI FIFO.  For this reason I am using just the pointer to the
 * HNI FIFO in the mailbox ops as the offset between the two is fixed.
 *
 * The header for the FIFO is broken out into the following fields:
 * Local Tail:  Offset into FIFO region for next DWORD to write.
 * Version:  Version info for mailbox, only values of 0/1 are supported.
 * Remote Head:  Offset into remote FIFO to indicate how much we have read.
 * Error: Error indication, values TBD.
 */

/* version number for switch manager mailboxes */
#define FM10K_SM_MBX_VERSION
#define FM10K_SM_MBX_FIFO_LEN

/* offsets shared between all SM FIFO headers */
#define FM10K_MSG_SM_TAIL_SHIFT
#define FM10K_MSG_SM_TAIL_SIZE
#define FM10K_MSG_SM_VER_SHIFT
#define FM10K_MSG_SM_VER_SIZE
#define FM10K_MSG_SM_HEAD_SHIFT
#define FM10K_MSG_SM_HEAD_SIZE
#define FM10K_MSG_SM_ERR_SHIFT
#define FM10K_MSG_SM_ERR_SIZE

/* All error messages returned by mailbox functions
 * The value -511 is 0xFE01 in hex.  The idea is to order the errors
 * from 0xFE01 - 0xFEFF so error codes are easily visible in the mailbox
 * messages.  This also helps to avoid error number collisions as Linux
 * doesn't appear to use error numbers 256 - 511.
 */
#define FM10K_MBX_ERR(_n)
#define FM10K_MBX_ERR_NO_MBX
#define FM10K_MBX_ERR_NO_SPACE
#define FM10K_MBX_ERR_TAIL
#define FM10K_MBX_ERR_HEAD
#define FM10K_MBX_ERR_SRC
#define FM10K_MBX_ERR_TYPE
#define FM10K_MBX_ERR_SIZE
#define FM10K_MBX_ERR_BUSY
#define FM10K_MBX_ERR_RSVD0
#define FM10K_MBX_ERR_CRC

#define FM10K_MBX_CRC_SEED

struct fm10k_mbx_ops {};

struct fm10k_mbx_fifo {};

/* size of buffer to be stored in mailbox for FIFOs */
#define FM10K_MBX_TX_BUFFER_SIZE
#define FM10K_MBX_RX_BUFFER_SIZE
#define FM10K_MBX_BUFFER_SIZE

/* minimum and maximum message size in dwords */
#define FM10K_MBX_MSG_MAX_SIZE
#define FM10K_VFMBX_MSG_MTU

#define FM10K_MBX_INIT_TIMEOUT
#define FM10K_MBX_INIT_DELAY

struct fm10k_mbx_info {};

s32 fm10k_pfvf_mbx_init(struct fm10k_hw *, struct fm10k_mbx_info *,
			const struct fm10k_msg_data *, u8);
s32 fm10k_sm_mbx_init(struct fm10k_hw *, struct fm10k_mbx_info *,
		      const struct fm10k_msg_data *);

#endif /* _FM10K_MBX_H_ */