Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 /* Copyright(c) 2013 - 2018 Intel Corporation. */
0003 
0004 #ifndef _FM10K_MBX_H_
0005 #define _FM10K_MBX_H_
0006 
0007 /* forward declaration */
0008 struct fm10k_mbx_info;
0009 
0010 #include "fm10k_type.h"
0011 #include "fm10k_tlv.h"
0012 
0013 /* PF Mailbox Registers */
0014 #define FM10K_MBMEM(_n)     ((_n) + 0x18000)
0015 #define FM10K_MBMEM_VF(_n, _m)  (((_n) * 0x10) + (_m) + 0x18000)
0016 #define FM10K_MBMEM_SM(_n)  ((_n) + 0x18400)
0017 #define FM10K_MBMEM_PF(_n)  ((_n) + 0x18600)
0018 /* XOR provides means of switching from Tx to Rx FIFO */
0019 #define FM10K_MBMEM_PF_XOR  (FM10K_MBMEM_SM(0) ^ FM10K_MBMEM_PF(0))
0020 #define FM10K_MBX(_n)       ((_n) + 0x18800)
0021 #define FM10K_MBX_REQ               0x00000002
0022 #define FM10K_MBX_ACK               0x00000004
0023 #define FM10K_MBX_REQ_INTERRUPT         0x00000008
0024 #define FM10K_MBX_ACK_INTERRUPT         0x00000010
0025 #define FM10K_MBX_INTERRUPT_ENABLE      0x00000020
0026 #define FM10K_MBX_INTERRUPT_DISABLE     0x00000040
0027 #define FM10K_MBX_GLOBAL_REQ_INTERRUPT      0x00000200
0028 #define FM10K_MBX_GLOBAL_ACK_INTERRUPT      0x00000400
0029 #define FM10K_MBICR(_n)     ((_n) + 0x18840)
0030 #define FM10K_GMBX      0x18842
0031 
0032 /* VF Mailbox Registers */
0033 #define FM10K_VFMBX     0x00010
0034 #define FM10K_VFMBMEM(_n)   ((_n) + 0x00020)
0035 #define FM10K_VFMBMEM_LEN   16
0036 #define FM10K_VFMBMEM_VF_XOR    (FM10K_VFMBMEM_LEN / 2)
0037 
0038 /* Delays/timeouts */
0039 #define FM10K_MBX_DISCONNECT_TIMEOUT        500
0040 #define FM10K_MBX_POLL_DELAY            19
0041 #define FM10K_MBX_INT_DELAY         20
0042 
0043 /* PF/VF Mailbox state machine
0044  *
0045  * +----------+     connect()   +----------+
0046  * |  CLOSED  | --------------> |  CONNECT |
0047  * +----------+         +----------+
0048  *   ^                ^  |
0049  *   | rcv:       rcv:    |  | rcv:
0050  *   |  Connect        Disconnect |  |  Connect
0051  *   |  Disconnect     Error      |  |  Data
0052  *   |                |  |
0053  *   |                |  V
0054  * +----------+   disconnect()  +----------+
0055  * |DISCONNECT| <-------------- |   OPEN   |
0056  * +----------+         +----------+
0057  *
0058  * The diagram above describes the PF/VF mailbox state machine.  There
0059  * are four main states to this machine.
0060  * Closed: This state represents a mailbox that is in a standby state
0061  *     with interrupts disabled.  In this state the mailbox should not
0062  *     read the mailbox or write any data.  The only means of exiting
0063  *     this state is for the system to make the connect() call for the
0064  *     mailbox, it will then transition to the connect state.
0065  * Connect: In this state the mailbox is seeking a connection.  It will
0066  *      post a connect message with no specified destination and will
0067  *      wait for a reply from the other side of the mailbox.  This state
0068  *      is exited when either a connect with the local mailbox as the
0069  *      destination is received or when a data message is received with
0070  *      a valid sequence number.
0071  * Open: In this state the mailbox is able to transfer data between the local
0072  *       entity and the remote.  It will fall back to connect in the event of
0073  *       receiving either an error message, or a disconnect message.  It will
0074  *       transition to disconnect on a call to disconnect();
0075  * Disconnect: In this state the mailbox is attempting to gracefully terminate
0076  *         the connection.  It will do so at the first point where it knows
0077  *         that the remote endpoint is either done sending, or when the
0078  *         remote endpoint has fallen back into connect.
0079  */
0080 enum fm10k_mbx_state {
0081     FM10K_STATE_CLOSED,
0082     FM10K_STATE_CONNECT,
0083     FM10K_STATE_OPEN,
0084     FM10K_STATE_DISCONNECT,
0085 };
0086 
0087 /* PF/VF Mailbox header format
0088  *    3           2           1           0
0089  *  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
0090  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
0091  * |        Size/Err_no/CRC        | Rsvd0 | Head  | Tail  | Type  |
0092  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
0093  *
0094  * The layout above describes the format for the header used in the PF/VF
0095  * mailbox.  The header is broken out into the following fields:
0096  * Type: There are 4 supported message types
0097  *      0x8: Data header - used to transport message data
0098  *      0xC: Connect header - used to establish connection
0099  *      0xD: Disconnect header - used to tear down a connection
0100  *      0xE: Error header - used to address message exceptions
0101  * Tail: Tail index for local FIFO
0102  *      Tail index actually consists of two parts.  The MSB of
0103  *      the head is a loop tracker, it is 0 on an even numbered
0104  *      loop through the FIFO, and 1 on the odd numbered loops.
0105  *      To get the actual mailbox offset based on the tail it
0106  *      is necessary to add bit 3 to bit 0 and clear bit 3.  This
0107  *      gives us a valid range of 0x1 - 0xE.
0108  * Head: Head index for remote FIFO
0109  *      Head index follows the same format as the tail index.
0110  * Rsvd0: Reserved 0 portion of the mailbox header
0111  * CRC: Running CRC for all data since connect plus current message header
0112  * Size: Maximum message size - Applies only to connect headers
0113  *      The maximum message size is provided during connect to avoid
0114  *      jamming the mailbox with messages that do not fit.
0115  * Err_no: Error number - Applies only to error headers
0116  *      The error number provides an indication of the type of error
0117  *      experienced.
0118  */
0119 
0120 /* macros for retrieving and setting header values */
0121 #define FM10K_MSG_HDR_MASK(name) \
0122     ((0x1u << FM10K_MSG_##name##_SIZE) - 1)
0123 #define FM10K_MSG_HDR_FIELD_SET(value, name) \
0124     (((u32)(value) & FM10K_MSG_HDR_MASK(name)) << FM10K_MSG_##name##_SHIFT)
0125 #define FM10K_MSG_HDR_FIELD_GET(value, name) \
0126     ((u16)((value) >> FM10K_MSG_##name##_SHIFT) & FM10K_MSG_HDR_MASK(name))
0127 
0128 /* offsets shared between all headers */
0129 #define FM10K_MSG_TYPE_SHIFT            0
0130 #define FM10K_MSG_TYPE_SIZE         4
0131 #define FM10K_MSG_TAIL_SHIFT            4
0132 #define FM10K_MSG_TAIL_SIZE         4
0133 #define FM10K_MSG_HEAD_SHIFT            8
0134 #define FM10K_MSG_HEAD_SIZE         4
0135 #define FM10K_MSG_RSVD0_SHIFT           12
0136 #define FM10K_MSG_RSVD0_SIZE            4
0137 
0138 /* offsets for data/disconnect headers */
0139 #define FM10K_MSG_CRC_SHIFT         16
0140 #define FM10K_MSG_CRC_SIZE          16
0141 
0142 /* offsets for connect headers */
0143 #define FM10K_MSG_CONNECT_SIZE_SHIFT        16
0144 #define FM10K_MSG_CONNECT_SIZE_SIZE     16
0145 
0146 /* offsets for error headers */
0147 #define FM10K_MSG_ERR_NO_SHIFT          16
0148 #define FM10K_MSG_ERR_NO_SIZE           16
0149 
0150 enum fm10k_msg_type {
0151     FM10K_MSG_DATA          = 0x8,
0152     FM10K_MSG_CONNECT       = 0xC,
0153     FM10K_MSG_DISCONNECT        = 0xD,
0154     FM10K_MSG_ERROR         = 0xE,
0155 };
0156 
0157 /* HNI/SM Mailbox FIFO format
0158  *    3                   2                   1                   0
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 0
0160  * +-------+-----------------------+-------+-----------------------+
0161  * | Error |      Remote Head      |Version|      Local Tail       |
0162  * +-------+-----------------------+-------+-----------------------+
0163  * |                                                               |
0164  * .                        Local FIFO Data                        .
0165  * .                                                               .
0166  * +-------+-----------------------+-------+-----------------------+
0167  *
0168  * The layout above describes the format for the FIFOs used by the host
0169  * network interface and the switch manager to communicate messages back
0170  * and forth.  Both the HNI and the switch maintain one such FIFO.  The
0171  * layout in memory has the switch manager FIFO followed immediately by
0172  * the HNI FIFO.  For this reason I am using just the pointer to the
0173  * HNI FIFO in the mailbox ops as the offset between the two is fixed.
0174  *
0175  * The header for the FIFO is broken out into the following fields:
0176  * Local Tail:  Offset into FIFO region for next DWORD to write.
0177  * Version:  Version info for mailbox, only values of 0/1 are supported.
0178  * Remote Head:  Offset into remote FIFO to indicate how much we have read.
0179  * Error: Error indication, values TBD.
0180  */
0181 
0182 /* version number for switch manager mailboxes */
0183 #define FM10K_SM_MBX_VERSION        1
0184 #define FM10K_SM_MBX_FIFO_LEN       (FM10K_MBMEM_PF_XOR - 1)
0185 
0186 /* offsets shared between all SM FIFO headers */
0187 #define FM10K_MSG_SM_TAIL_SHIFT         0
0188 #define FM10K_MSG_SM_TAIL_SIZE          12
0189 #define FM10K_MSG_SM_VER_SHIFT          12
0190 #define FM10K_MSG_SM_VER_SIZE           4
0191 #define FM10K_MSG_SM_HEAD_SHIFT         16
0192 #define FM10K_MSG_SM_HEAD_SIZE          12
0193 #define FM10K_MSG_SM_ERR_SHIFT          28
0194 #define FM10K_MSG_SM_ERR_SIZE           4
0195 
0196 /* All error messages returned by mailbox functions
0197  * The value -511 is 0xFE01 in hex.  The idea is to order the errors
0198  * from 0xFE01 - 0xFEFF so error codes are easily visible in the mailbox
0199  * messages.  This also helps to avoid error number collisions as Linux
0200  * doesn't appear to use error numbers 256 - 511.
0201  */
0202 #define FM10K_MBX_ERR(_n) ((_n) - 512)
0203 #define FM10K_MBX_ERR_NO_MBX        FM10K_MBX_ERR(0x01)
0204 #define FM10K_MBX_ERR_NO_SPACE      FM10K_MBX_ERR(0x03)
0205 #define FM10K_MBX_ERR_TAIL      FM10K_MBX_ERR(0x05)
0206 #define FM10K_MBX_ERR_HEAD      FM10K_MBX_ERR(0x06)
0207 #define FM10K_MBX_ERR_SRC       FM10K_MBX_ERR(0x08)
0208 #define FM10K_MBX_ERR_TYPE      FM10K_MBX_ERR(0x09)
0209 #define FM10K_MBX_ERR_SIZE      FM10K_MBX_ERR(0x0B)
0210 #define FM10K_MBX_ERR_BUSY      FM10K_MBX_ERR(0x0C)
0211 #define FM10K_MBX_ERR_RSVD0     FM10K_MBX_ERR(0x0E)
0212 #define FM10K_MBX_ERR_CRC       FM10K_MBX_ERR(0x0F)
0213 
0214 #define FM10K_MBX_CRC_SEED      0xFFFF
0215 
0216 struct fm10k_mbx_ops {
0217     s32 (*connect)(struct fm10k_hw *, struct fm10k_mbx_info *);
0218     void (*disconnect)(struct fm10k_hw *, struct fm10k_mbx_info *);
0219     bool (*rx_ready)(struct fm10k_mbx_info *);
0220     bool (*tx_ready)(struct fm10k_mbx_info *, u16);
0221     bool (*tx_complete)(struct fm10k_mbx_info *);
0222     s32 (*enqueue_tx)(struct fm10k_hw *, struct fm10k_mbx_info *,
0223               const u32 *);
0224     s32 (*process)(struct fm10k_hw *, struct fm10k_mbx_info *);
0225     s32 (*register_handlers)(struct fm10k_mbx_info *,
0226                  const struct fm10k_msg_data *);
0227 };
0228 
0229 struct fm10k_mbx_fifo {
0230     u32 *buffer;
0231     u16 head;
0232     u16 tail;
0233     u16 size;
0234 };
0235 
0236 /* size of buffer to be stored in mailbox for FIFOs */
0237 #define FM10K_MBX_TX_BUFFER_SIZE    512
0238 #define FM10K_MBX_RX_BUFFER_SIZE    128
0239 #define FM10K_MBX_BUFFER_SIZE \
0240     (FM10K_MBX_TX_BUFFER_SIZE + FM10K_MBX_RX_BUFFER_SIZE)
0241 
0242 /* minimum and maximum message size in dwords */
0243 #define FM10K_MBX_MSG_MAX_SIZE \
0244     ((FM10K_MBX_TX_BUFFER_SIZE - 1) & (FM10K_MBX_RX_BUFFER_SIZE - 1))
0245 #define FM10K_VFMBX_MSG_MTU ((FM10K_VFMBMEM_LEN / 2) - 1)
0246 
0247 #define FM10K_MBX_INIT_TIMEOUT  2000 /* number of retries on mailbox */
0248 #define FM10K_MBX_INIT_DELAY    500  /* microseconds between retries */
0249 
0250 struct fm10k_mbx_info {
0251     /* function pointers for mailbox operations */
0252     struct fm10k_mbx_ops ops;
0253     const struct fm10k_msg_data *msg_data;
0254 
0255     /* message FIFOs */
0256     struct fm10k_mbx_fifo rx;
0257     struct fm10k_mbx_fifo tx;
0258 
0259     /* delay for handling timeouts */
0260     u32 timeout;
0261     u32 udelay;
0262 
0263     /* mailbox state info */
0264     u32 mbx_reg, mbmem_reg, mbx_lock, mbx_hdr;
0265     u16 max_size, mbmem_len;
0266     u16 tail, tail_len, pulled;
0267     u16 head, head_len, pushed;
0268     u16 local, remote;
0269     enum fm10k_mbx_state state;
0270 
0271     /* result of last mailbox test */
0272     s32 test_result;
0273 
0274     /* statistics */
0275     u64 tx_busy;
0276     u64 tx_dropped;
0277     u64 tx_messages;
0278     u64 tx_dwords;
0279     u64 tx_mbmem_pulled;
0280     u64 rx_messages;
0281     u64 rx_dwords;
0282     u64 rx_mbmem_pushed;
0283     u64 rx_parse_err;
0284 
0285     /* Buffer to store messages */
0286     u32 buffer[FM10K_MBX_BUFFER_SIZE];
0287 };
0288 
0289 s32 fm10k_pfvf_mbx_init(struct fm10k_hw *, struct fm10k_mbx_info *,
0290             const struct fm10k_msg_data *, u8);
0291 s32 fm10k_sm_mbx_init(struct fm10k_hw *, struct fm10k_mbx_info *,
0292               const struct fm10k_msg_data *);
0293 
0294 #endif /* _FM10K_MBX_H_ */