5
* Copyright (C) 2013-2015 Mellanox Technologies Ltd.
7
* This program is free software; you can redistribute it and/or
8
* modify it under the terms of the GNU General Public License as
9
* published by the Free Software Foundation; either version 2 of the
10
* License, or any later version.
12
* This program is distributed in the hope that it will be useful, but
13
* WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
* General Public License for more details.
17
* You should have received a copy of the GNU General Public License
18
* along with this program; if not, write to the Free Software
19
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
23
FILE_LICENCE ( GPL2_OR_LATER );
31
#include <ipxe/pcibackup.h>
34
#define GOLAN_PCI_CONFIG_BAR_SIZE 0x100000//HERMON_PCI_CONFIG_BAR_SIZE //TODO: What is the BAR size?
36
#define GOLAN_PAS_SIZE sizeof(uint64_t)
38
#define GOLAN_INVALID_LKEY 0x00000100UL
40
#define GOLAN_MAX_PORTS 2
41
#define GOLAN_PORT_BASE 1
43
#define MELLANOX_VID 0x15b3
44
#define GOLAN_HCA_BAR PCI_BASE_ADDRESS_0 //BAR 0
46
#define GOLAN_HCR_MAX_WAIT_MS 10000
48
#define min(a,b) ((a)<(b)?(a):(b))
50
#define GOLAN_PAGE_SHIFT 12
51
#define GOLAN_PAGE_SIZE (1 << GOLAN_PAGE_SHIFT)
52
#define GOLAN_PAGE_MASK (GOLAN_PAGE_SIZE - 1)
54
#define MAX_MBOX ( GOLAN_PAGE_SIZE / MAILBOX_STRIDE )
57
#define NO_MBOX 0xffff
58
#define MEM_MBOX MEM_CMD_IDX
59
#define GEN_MBOX DEF_CMD_IDX
63
#define MAX_PASE_MBOX ((GOLAN_CMD_PAS_CNT) - 2)
65
#define CMD_STATUS( golan , idx ) ((struct golan_outbox_hdr *)(get_cmd( (golan) , (idx) )->out))->status
66
#define CMD_SYND( golan , idx ) ((struct golan_outbox_hdr *)(get_cmd( (golan) , (idx) )->out))->syndrome
67
#define QRY_PAGES_OUT( golan, idx ) ((struct golan_query_pages_outbox *)(get_cmd( (golan) , (idx) )->out))
69
#define VIRT_2_BE64_BUS( addr ) cpu_to_be64(((unsigned long long )virt_to_bus(addr)))
70
#define BE64_BUS_2_VIRT( addr ) bus_to_virt(be64_to_cpu(addr))
71
#define USR_2_BE64_BUS( addr ) cpu_to_be64(((unsigned long long )user_to_phys(addr, 0)))
72
#define BE64_BUS_2_USR( addr ) be64_to_cpu(phys_to_user(addr))
74
#define GET_INBOX(golan, idx) (&(((struct mbox *)(golan->mboxes.inbox))[idx]))
75
#define GET_OUTBOX(golan, idx) (&(((struct mbox *)(golan->mboxes.outbox))[idx]))
77
#define GOLAN_MBOX_IN( cmd_ptr, in_ptr ) ( { \
80
typeof ( *(in_ptr) ) cooked; \
81
} *u = container_of ( &(cmd_ptr)->in[0], typeof ( *u ), raw[0] ); \
84
#define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d))
86
/* Fw status fields */
89
SIGNATURE_ERROR = 0x1,
91
BAD_BLOCK_NUMBER = 0x3,
92
BAD_OUTPUT_POINTER = 0x4, // pointer not align to mailbox size
93
BAD_INPUT_POINTER = 0x5, // pointer not align to mailbox size
95
INPUT_LEN_ERROR = 0x7, // input length less than 0x8.
96
OUTPUT_LEN_ERROR = 0x8, // output length less than 0x8.
97
RESERVE_NOT_ZERO = 0x9,
101
struct golan_cmdq_md {
114
#define GOLAN_SEND_WQE_BB_SIZE 64
115
#define GOLAN_SEND_UD_WQE_SIZE sizeof(struct golan_send_wqe_ud)
116
#define GOLAN_RECV_WQE_SIZE sizeof(struct golan_recv_wqe_ud)
117
#define GOLAN_WQEBBS_PER_SEND_UD_WQE DIV_ROUND_UP(GOLAN_SEND_UD_WQE_SIZE, GOLAN_SEND_WQE_BB_SIZE)
118
#define GOLAN_SEND_OPCODE 0x0a
119
#define GOLAN_WQE_CTRL_WQE_IDX_BIT 8
121
enum golan_ib_qp_state {
131
struct golan_send_wqe_ud {
132
struct golan_wqe_ctrl_seg ctrl;
133
struct golan_av datagram;
134
struct golan_wqe_data_seg data;
137
union golan_send_wqe {
138
struct golan_send_wqe_ud ud;
139
uint8_t pad[GOLAN_WQEBBS_PER_SEND_UD_WQE * GOLAN_SEND_WQE_BB_SIZE];
142
struct golan_recv_wqe_ud {
143
struct golan_wqe_data_seg data[2];
146
struct golan_recv_wq {
147
struct golan_recv_wqe_ud *wqes;
148
/* WQ size in bytes */
150
/* In SQ, it will be increased in wqe_size (number of WQEBBs per WQE) */
152
/** GRH buffers (if applicable) */
153
struct ib_global_route_header *grh;
154
/** Size of GRH buffers */
158
struct golan_send_wq {
159
union golan_send_wqe *wqes;
160
/* WQ size in bytes */
162
/* In SQ, it will be increased in wqe_size (number of WQEBBs per WQE) */
166
struct golan_queue_pair {
169
struct golan_recv_wq rq;
170
struct golan_send_wq sq;
171
struct golan_qp_db *doorbell_record;
173
enum golan_ib_qp_state state;
176
/* Completion Queue */
177
#define GOLAN_CQE_OPCODE_NOT_VALID 0x0f
178
#define GOLAN_CQE_OPCODE_BIT 4
179
#define GOLAN_CQ_DB_RECORD_SIZE sizeof(uint64_t)
180
#define GOLAN_CQE_OWNER_MASK 1
182
#define MANAGE_PAGES_PSA_OFFSET 0
183
#define PXE_CMDIF_REF 5
186
GOLAN_CQE_SW_OWNERSHIP = 0x0,
187
GOLAN_CQE_HW_OWNERSHIP = 0x1
191
GOLAN_CQE_SIZE_64 = 0,
192
GOLAN_CQE_SIZE_128 = 1
195
struct golan_completion_queue {
196
struct golan_cqe64 *cqes;
198
__be64 *doorbell_record;
203
#define GOLAN_EQE_SIZE sizeof(struct golan_eqe)
204
#define GOLAN_NUM_EQES 8
205
#define GOLAN_EQ_DOORBELL_OFFSET 0x40
207
#define GOLAN_EQ_MAP_ALL_EVENTS \
208
((1 << GOLAN_EVENT_TYPE_PATH_MIG )| \
209
(1 << GOLAN_EVENT_TYPE_COMM_EST )| \
210
(1 << GOLAN_EVENT_TYPE_SQ_DRAINED )| \
211
(1 << GOLAN_EVENT_TYPE_SRQ_LAST_WQE )| \
212
(1 << GOLAN_EVENT_TYPE_SRQ_RQ_LIMIT )| \
213
(1 << GOLAN_EVENT_TYPE_CQ_ERROR )| \
214
(1 << GOLAN_EVENT_TYPE_WQ_CATAS_ERROR )| \
215
(1 << GOLAN_EVENT_TYPE_PATH_MIG_FAILED )| \
216
(1 << GOLAN_EVENT_TYPE_WQ_INVAL_REQ_ERROR )| \
217
(1 << GOLAN_EVENT_TYPE_WQ_ACCESS_ERROR )| \
218
(1 << GOLAN_EVENT_TYPE_SRQ_CATAS_ERROR )| \
219
(1 << GOLAN_EVENT_TYPE_INTERNAL_ERROR )| \
220
(1 << GOLAN_EVENT_TYPE_PORT_CHANGE )| \
221
(1 << GOLAN_EVENT_TYPE_GPIO_EVENT )| \
222
(1 << GOLAN_EVENT_TYPE_CLIENT_RE_REGISTER )| \
223
(1 << GOLAN_EVENT_TYPE_REMOTE_CONFIG )| \
224
(1 << GOLAN_EVENT_TYPE_DB_BF_CONGESTION )| \
225
(1 << GOLAN_EVENT_TYPE_STALL_EVENT )| \
226
(1 << GOLAN_EVENT_TYPE_PACKET_DROPPED )| \
227
(1 << GOLAN_EVENT_TYPE_CMD )| \
228
(1 << GOLAN_EVENT_TYPE_PAGE_REQUEST ))
231
GOLAN_EVENT_TYPE_COMP = 0x0,
233
GOLAN_EVENT_TYPE_PATH_MIG = 0x01,
234
GOLAN_EVENT_TYPE_COMM_EST = 0x02,
235
GOLAN_EVENT_TYPE_SQ_DRAINED = 0x03,
236
GOLAN_EVENT_TYPE_SRQ_LAST_WQE = 0x13,
237
GOLAN_EVENT_TYPE_SRQ_RQ_LIMIT = 0x14,
239
GOLAN_EVENT_TYPE_CQ_ERROR = 0x04,
240
GOLAN_EVENT_TYPE_WQ_CATAS_ERROR = 0x05,
241
GOLAN_EVENT_TYPE_PATH_MIG_FAILED = 0x07,
242
GOLAN_EVENT_TYPE_WQ_INVAL_REQ_ERROR = 0x10,
243
GOLAN_EVENT_TYPE_WQ_ACCESS_ERROR = 0x11,
244
GOLAN_EVENT_TYPE_SRQ_CATAS_ERROR = 0x12,
246
GOLAN_EVENT_TYPE_INTERNAL_ERROR = 0x08,
247
GOLAN_EVENT_TYPE_PORT_CHANGE = 0x09,
248
GOLAN_EVENT_TYPE_GPIO_EVENT = 0x15,
249
// GOLAN_EVENT_TYPE_CLIENT_RE_REGISTER = 0x16,
250
GOLAN_EVENT_TYPE_REMOTE_CONFIG = 0x19,
252
GOLAN_EVENT_TYPE_DB_BF_CONGESTION = 0x1a,
253
GOLAN_EVENT_TYPE_STALL_EVENT = 0x1b,
255
GOLAN_EVENT_TYPE_PACKET_DROPPED = 0x1f,
257
GOLAN_EVENT_TYPE_CMD = 0x0a,
258
GOLAN_EVENT_TYPE_PAGE_REQUEST = 0x0b,
259
GOLAN_EVENT_TYPE_PAGE_FAULT = 0x0C,
262
enum golan_port_sub_event {
263
GOLAN_PORT_CHANGE_SUBTYPE_DOWN = 1,
264
GOLAN_PORT_CHANGE_SUBTYPE_ACTIVE = 4,
265
GOLAN_PORT_CHANGE_SUBTYPE_INITIALIZED = 5,
266
GOLAN_PORT_CHANGE_SUBTYPE_LID = 6,
267
GOLAN_PORT_CHANGE_SUBTYPE_PKEY = 7,
268
GOLAN_PORT_CHANGE_SUBTYPE_GUID = 8,
269
GOLAN_PORT_CHANGE_SUBTYPE_CLIENT_REREG = 9
274
GOLAN_EQE_SW_OWNERSHIP = 0x0,
275
GOLAN_EQE_HW_OWNERSHIP = 0x1
279
GOLAN_EQ_UNARMED = 0,
283
struct golan_event_queue {
286
struct golan_eqe *eqes;
293
/** Infiniband device */
294
struct ib_device *ibdev;
295
/** Network device */
296
struct net_device *netdev;
301
struct golan_mboxes {
306
#define GOLAN_OPEN 0x1
309
struct pci_device *pci;
310
struct golan_hca_init_seg *iseg;
311
struct golan_cmdq_md cmd;
312
struct golan_hca_cap caps; /* stored as big indian*/
313
struct golan_mboxes mboxes;
314
struct list_head pages;
316
uint32_t total_dma_pages;
317
struct golan_uar uar;
318
struct golan_event_queue eq;
323
struct golan_port ports[GOLAN_MAX_PORTS];
326
#endif /* _GOLAN_H_*/