fm10k: Add support for mailbox
[deliverable/linux.git] / drivers / net / ethernet / intel / fm10k / fm10k_mbx.h
CommitLineData
6b1f201f
AD
1/* Intel Ethernet Switch Host Interface Driver
2 * Copyright(c) 2013 - 2014 Intel Corporation.
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms and conditions of the GNU General Public License,
6 * version 2, as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
11 * more details.
12 *
13 * The full GNU General Public License is included in this distribution in
14 * the file called "COPYING".
15 *
16 * Contact Information:
17 * e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
18 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
19 */
20
21#ifndef _FM10K_MBX_H_
22#define _FM10K_MBX_H_
23
24/* forward declaration */
25struct fm10k_mbx_info;
26
27#include "fm10k_type.h"
28#include "fm10k_tlv.h"
29
30/* PF Mailbox Registers */
31#define FM10K_MBMEM(_n) ((_n) + 0x18000)
32#define FM10K_MBMEM_VF(_n, _m) (((_n) * 0x10) + (_m) + 0x18000)
33#define FM10K_MBMEM_SM(_n) ((_n) + 0x18400)
34#define FM10K_MBMEM_PF(_n) ((_n) + 0x18600)
35/* XOR provides means of switching from Tx to Rx FIFO */
36#define FM10K_MBMEM_PF_XOR (FM10K_MBMEM_SM(0) ^ FM10K_MBMEM_PF(0))
37#define FM10K_MBX(_n) ((_n) + 0x18800)
38#define FM10K_MBX_REQ 0x00000002
39#define FM10K_MBX_ACK 0x00000004
40#define FM10K_MBX_REQ_INTERRUPT 0x00000008
41#define FM10K_MBX_ACK_INTERRUPT 0x00000010
42#define FM10K_MBX_INTERRUPT_ENABLE 0x00000020
43#define FM10K_MBX_INTERRUPT_DISABLE 0x00000040
44#define FM10K_MBICR(_n) ((_n) + 0x18840)
45#define FM10K_GMBX 0x18842
46
47/* VF Mailbox Registers */
48#define FM10K_VFMBX 0x00010
49#define FM10K_VFMBMEM(_n) ((_n) + 0x00020)
50#define FM10K_VFMBMEM_LEN 16
51#define FM10K_VFMBMEM_VF_XOR (FM10K_VFMBMEM_LEN / 2)
52
53/* Delays/timeouts */
54#define FM10K_MBX_DISCONNECT_TIMEOUT 500
55#define FM10K_MBX_POLL_DELAY 19
56#define FM10K_MBX_INT_DELAY 20
57
58/* PF/VF Mailbox state machine
59 *
60 * +----------+ connect() +----------+
61 * | CLOSED | --------------> | CONNECT |
62 * +----------+ +----------+
63 * ^ ^ |
64 * | rcv: rcv: | | rcv:
65 * | Connect Disconnect | | Connect
66 * | Disconnect Error | | Data
67 * | | |
68 * | | V
69 * +----------+ disconnect() +----------+
70 * |DISCONNECT| <-------------- | OPEN |
71 * +----------+ +----------+
72 *
73 * The diagram above describes the PF/VF mailbox state machine. There
74 * are four main states to this machine.
75 * Closed: This state represents a mailbox that is in a standby state
76 * with interrupts disabled. In this state the mailbox should not
77 * read the mailbox or write any data. The only means of exiting
78 * this state is for the system to make the connect() call for the
79 * mailbox, it will then transition to the connect state.
80 * Connect: In this state the mailbox is seeking a connection. It will
81 * post a connect message with no specified destination and will
82 * wait for a reply from the other side of the mailbox. This state
83 * is exited when either a connect with the local mailbox as the
84 * destination is received or when a data message is received with
85 * a valid sequence number.
86 * Open: In this state the mailbox is able to transfer data between the local
87 * entity and the remote. It will fall back to connect in the event of
88 * receiving either an error message, or a disconnect message. It will
89 * transition to disconnect on a call to disconnect();
90 * Disconnect: In this state the mailbox is attempting to gracefully terminate
91 * the connection. It will do so at the first point where it knows
92 * that the remote endpoint is either done sending, or when the
93 * remote endpoint has fallen back into connect.
94 */
95enum fm10k_mbx_state {
96 FM10K_STATE_CLOSED,
97 FM10K_STATE_CONNECT,
98 FM10K_STATE_OPEN,
99 FM10K_STATE_DISCONNECT,
100};
101
102/* macros for retriving and setting header values */
103#define FM10K_MSG_HDR_MASK(name) \
104 ((0x1u << FM10K_MSG_##name##_SIZE) - 1)
105#define FM10K_MSG_HDR_FIELD_SET(value, name) \
106 (((u32)(value) & FM10K_MSG_HDR_MASK(name)) << FM10K_MSG_##name##_SHIFT)
107#define FM10K_MSG_HDR_FIELD_GET(value, name) \
108 ((u16)((value) >> FM10K_MSG_##name##_SHIFT) & FM10K_MSG_HDR_MASK(name))
109
110/* HNI/SM Mailbox FIFO format
111 * 3 2 1 0
112 * 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
113 * +-------+-----------------------+-------+-----------------------+
114 * | Error | Remote Head |Version| Local Tail |
115 * +-------+-----------------------+-------+-----------------------+
116 * | |
117 * . Local FIFO Data .
118 * . .
119 * +-------+-----------------------+-------+-----------------------+
120 *
121 * The layout above describes the format for the FIFOs used by the host
122 * network interface and the switch manager to communicate messages back
123 * and forth. Both the HNI and the switch maintain one such FIFO. The
124 * layout in memory has the switch manager FIFO followed immediately by
125 * the HNI FIFO. For this reason I am using just the pointer to the
126 * HNI FIFO in the mailbox ops as the offset between the two is fixed.
127 *
128 * The header for the FIFO is broken out into the following fields:
129 * Local Tail: Offset into FIFO region for next DWORD to write.
130 * Version: Version info for mailbox, only values of 0/1 are supported.
131 * Remote Head: Offset into remote FIFO to indicate how much we have read.
132 * Error: Error indication, values TBD.
133 */
134
135/* version number for switch manager mailboxes */
136#define FM10K_SM_MBX_VERSION 1
137#define FM10K_SM_MBX_FIFO_LEN (FM10K_MBMEM_PF_XOR - 1)
138
139/* offsets shared between all SM FIFO headers */
140#define FM10K_MSG_SM_TAIL_SHIFT 0
141#define FM10K_MSG_SM_TAIL_SIZE 12
142#define FM10K_MSG_SM_VER_SHIFT 12
143#define FM10K_MSG_SM_VER_SIZE 4
144#define FM10K_MSG_SM_HEAD_SHIFT 16
145#define FM10K_MSG_SM_HEAD_SIZE 12
146#define FM10K_MSG_SM_ERR_SHIFT 28
147#define FM10K_MSG_SM_ERR_SIZE 4
148
149/* All error messages returned by mailbox functions
150 * The value -511 is 0xFE01 in hex. The idea is to order the errors
151 * from 0xFE01 - 0xFEFF so error codes are easily visible in the mailbox
152 * messages. This also helps to avoid error number collisions as Linux
153 * doesn't appear to use error numbers 256 - 511.
154 */
155#define FM10K_MBX_ERR(_n) ((_n) - 512)
156#define FM10K_MBX_ERR_NO_MBX FM10K_MBX_ERR(0x01)
157#define FM10K_MBX_ERR_NO_SPACE FM10K_MBX_ERR(0x03)
158#define FM10K_MBX_ERR_TAIL FM10K_MBX_ERR(0x05)
159#define FM10K_MBX_ERR_HEAD FM10K_MBX_ERR(0x06)
160#define FM10K_MBX_ERR_SRC FM10K_MBX_ERR(0x08)
161#define FM10K_MBX_ERR_TYPE FM10K_MBX_ERR(0x09)
162#define FM10K_MBX_ERR_SIZE FM10K_MBX_ERR(0x0B)
163#define FM10K_MBX_ERR_BUSY FM10K_MBX_ERR(0x0C)
164#define FM10K_MBX_ERR_RSVD0 FM10K_MBX_ERR(0x0E)
165#define FM10K_MBX_ERR_CRC FM10K_MBX_ERR(0x0F)
166
167#define FM10K_MBX_CRC_SEED 0xFFFF
168
169struct fm10k_mbx_ops {
170 s32 (*connect)(struct fm10k_hw *, struct fm10k_mbx_info *);
171 void (*disconnect)(struct fm10k_hw *, struct fm10k_mbx_info *);
172 bool (*rx_ready)(struct fm10k_mbx_info *);
173 bool (*tx_ready)(struct fm10k_mbx_info *, u16);
174 bool (*tx_complete)(struct fm10k_mbx_info *);
175 s32 (*enqueue_tx)(struct fm10k_hw *, struct fm10k_mbx_info *,
176 const u32 *);
177 s32 (*process)(struct fm10k_hw *, struct fm10k_mbx_info *);
178 s32 (*register_handlers)(struct fm10k_mbx_info *,
179 const struct fm10k_msg_data *);
180};
181
182struct fm10k_mbx_fifo {
183 u32 *buffer;
184 u16 head;
185 u16 tail;
186 u16 size;
187};
188
189/* size of buffer to be stored in mailbox for FIFOs */
190#define FM10K_MBX_TX_BUFFER_SIZE 512
191#define FM10K_MBX_RX_BUFFER_SIZE 128
192#define FM10K_MBX_BUFFER_SIZE \
193 (FM10K_MBX_TX_BUFFER_SIZE + FM10K_MBX_RX_BUFFER_SIZE)
194
195/* minimum and maximum message size in dwords */
196#define FM10K_MBX_MSG_MAX_SIZE \
197 ((FM10K_MBX_TX_BUFFER_SIZE - 1) & (FM10K_MBX_RX_BUFFER_SIZE - 1))
198#define FM10K_VFMBX_MSG_MTU ((FM10K_VFMBMEM_LEN / 2) - 1)
199
200#define FM10K_MBX_INIT_TIMEOUT 2000 /* number of retries on mailbox */
201#define FM10K_MBX_INIT_DELAY 500 /* microseconds between retries */
202
203struct fm10k_mbx_info {
204 /* function pointers for mailbox operations */
205 struct fm10k_mbx_ops ops;
206 const struct fm10k_msg_data *msg_data;
207
208 /* message FIFOs */
209 struct fm10k_mbx_fifo rx;
210 struct fm10k_mbx_fifo tx;
211
212 /* delay for handling timeouts */
213 u32 timeout;
214 u32 udelay;
215
216 /* mailbox state info */
217 u32 mbx_reg, mbmem_reg, mbx_lock, mbx_hdr;
218 u16 max_size, mbmem_len;
219 u16 tail, tail_len, pulled;
220 u16 head, head_len, pushed;
221 u16 local, remote;
222 enum fm10k_mbx_state state;
223
224 /* result of last mailbox test */
225 s32 test_result;
226
227 /* statistics */
228 u64 tx_busy;
229 u64 tx_dropped;
230 u64 tx_messages;
231 u64 tx_dwords;
232 u64 rx_messages;
233 u64 rx_dwords;
234 u64 rx_parse_err;
235
236 /* Buffer to store messages */
237 u32 buffer[FM10K_MBX_BUFFER_SIZE];
238};
239
240#endif /* _FM10K_MBX_H_ */
This page took 0.034312 seconds and 5 git commands to generate.