iPXE
golan.h
Go to the documentation of this file.
1#ifndef _GOLAN_H_
2#define _GOLAN_H_
3
4/*
5 * Copyright (C) 2013-2015 Mellanox Technologies Ltd.
6 *
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.
11 *
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.
16 *
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
20 * 02110-1301, USA.
21 */
22
23FILE_LICENCE ( GPL2_OR_LATER );
24
25#include <ipxe/pci.h>
26#include <ipxe/pcibackup.h>
27#include <byteswap.h>
28#include <errno.h>
29#include <ipxe/io.h>
30#include <stdio.h>
31#include <unistd.h>
32#include "CIB_PRM.h"
34
35#define GOLAN_PCI_CONFIG_BAR_SIZE 0x100000//HERMON_PCI_CONFIG_BAR_SIZE //TODO: What is the BAR size?
36
37#define GOLAN_PAS_SIZE sizeof(uint64_t)
38
39#define GOLAN_INVALID_LKEY 0x00000100UL
40
41#define GOLAN_MAX_PORTS 2
42#define GOLAN_PORT_BASE 1
43
44#define MELLANOX_VID 0x15b3
45#define GOLAN_HCA_BAR PCI_BASE_ADDRESS_0 //BAR 0
46
47#define GOLAN_HCR_MAX_WAIT_MS 10000
48
49#define min(a,b) ((a)<(b)?(a):(b))
50
51#define GOLAN_PAGE_SHIFT 12
52#define GOLAN_PAGE_SIZE (1 << GOLAN_PAGE_SHIFT)
53#define GOLAN_PAGE_MASK (GOLAN_PAGE_SIZE - 1)
54
55#define MAX_MBOX ( GOLAN_PAGE_SIZE / MAILBOX_STRIDE )
56#define DEF_CMD_IDX 1
57#define MEM_CMD_IDX 0
58#define NO_MBOX 0xffff
59#define MEM_MBOX MEM_CMD_IDX
60#define GEN_MBOX DEF_CMD_IDX
61
62#define CMD_IF_REV 4
63
64#define MAX_PASE_MBOX ((GOLAN_CMD_PAS_CNT) - 2)
65
66#define CMD_STATUS( golan , idx ) ((struct golan_outbox_hdr *)(get_cmd( (golan) , (idx) )->out))->status
67#define CMD_SYND( golan , idx ) ((struct golan_outbox_hdr *)(get_cmd( (golan) , (idx) )->out))->syndrome
68#define QRY_PAGES_OUT( golan, idx ) ((struct golan_query_pages_outbox *)(get_cmd( (golan) , (idx) )->out))
69
70#define VIRT_2_BE64_BUS( addr ) cpu_to_be64(((unsigned long long )virt_to_bus(addr)))
71#define BE64_BUS_2_VIRT( addr ) bus_to_virt(be64_to_cpu(addr))
72#define USR_2_BE64_BUS( addr ) cpu_to_be64(((unsigned long long )virt_to_phys(addr)))
73#define BE64_BUS_2_USR( addr ) be64_to_cpu(phys_to_virt(addr))
74
75#define GET_INBOX(golan, idx) (&(((struct mbox *)(golan->mboxes.inbox))[idx]))
76#define GET_OUTBOX(golan, idx) (&(((struct mbox *)(golan->mboxes.outbox))[idx]))
77
78#define GOLAN_MBOX_IN( cmd_ptr, in_ptr ) ( { \
79 union { \
80 __be32 raw[4]; \
81 typeof ( *(in_ptr) ) cooked; \
82 } *u = container_of ( &(cmd_ptr)->in[0], typeof ( *u ), raw[0] ); \
83 &u->cooked; } )
84
85#define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d))
86
87/* Fw status fields */
88typedef enum {
89 NO_ERRORS = 0x0,
93 BAD_OUTPUT_POINTER = 0x4, // pointer not align to mailbox size
94 BAD_INPUT_POINTER = 0x5, // pointer not align to mailbox size
96 INPUT_LEN_ERROR = 0x7, // input length less than 0x8.
97 OUTPUT_LEN_ERROR = 0x8, // output length less than 0x8.
101
107
108struct golan_uar {
110 void *virt;
111 unsigned long phys;
112};
113
114
116 /* length of area in pages */
118 /** Firmware area in external memory
119 *
120 * This is allocated when first needed, and freed only on
121 * final teardown, in order to avoid memory map changes at
122 * runtime.
123 */
124 void *area;
125};
126/* Queue Pair */
127#define GOLAN_SEND_WQE_BB_SIZE 64
128#define GOLAN_SEND_UD_WQE_SIZE sizeof(struct golan_send_wqe_ud)
129#define GOLAN_RECV_WQE_SIZE sizeof(struct golan_recv_wqe_ud)
130#define GOLAN_WQEBBS_PER_SEND_UD_WQE DIV_ROUND_UP(GOLAN_SEND_UD_WQE_SIZE, GOLAN_SEND_WQE_BB_SIZE)
131#define GOLAN_SEND_OPCODE 0x0a
132#define GOLAN_WQE_CTRL_WQE_IDX_BIT 8
133
143
149
154
158
161 /* WQ size in bytes */
162 int size;
163 /* In SQ, it will be increased in wqe_size (number of WQEBBs per WQE) */
165 /** GRH buffers (if applicable) */
167 /** Size of GRH buffers */
168 size_t grh_size;
169};
170
173 /* WQ size in bytes */
174 int size;
175 /* In SQ, it will be increased in wqe_size (number of WQEBBs per WQE) */
177};
178
188
189/* Completion Queue */
190#define GOLAN_CQE_OPCODE_NOT_VALID 0x0f
191#define GOLAN_CQE_OPCODE_BIT 4
192#define GOLAN_CQ_DB_RECORD_SIZE sizeof(uint64_t)
193#define GOLAN_CQE_OWNER_MASK 1
194
195#define MANAGE_PAGES_PSA_OFFSET 0
196#define PXE_CMDIF_REF 5
197
198enum {
201};
202
203enum {
206};
207
213
214
215/* Event Queue */
216#define GOLAN_EQE_SIZE sizeof(struct golan_eqe)
217#define GOLAN_NUM_EQES 8
218#define GOLAN_EQ_DOORBELL_OFFSET 0x40
219#define DB_BUFFER0_EVEN_OFFSET 0x800
220#define DB_BUFFER0_ODD_OFFSET 0x900
221
222#define GOLAN_EQ_MAP_ALL_EVENTS \
223 ((1 << GOLAN_EVENT_TYPE_PATH_MIG )| \
224 (1 << GOLAN_EVENT_TYPE_COMM_EST )| \
225 (1 << GOLAN_EVENT_TYPE_SQ_DRAINED )| \
226 (1 << GOLAN_EVENT_TYPE_SRQ_LAST_WQE )| \
227 (1 << GOLAN_EVENT_TYPE_SRQ_RQ_LIMIT )| \
228 (1 << GOLAN_EVENT_TYPE_CQ_ERROR )| \
229 (1 << GOLAN_EVENT_TYPE_WQ_CATAS_ERROR )| \
230 (1 << GOLAN_EVENT_TYPE_PATH_MIG_FAILED )| \
231 (1 << GOLAN_EVENT_TYPE_WQ_INVAL_REQ_ERROR )| \
232 (1 << GOLAN_EVENT_TYPE_WQ_ACCESS_ERROR )| \
233 (1 << GOLAN_EVENT_TYPE_SRQ_CATAS_ERROR )| \
234 (1 << GOLAN_EVENT_TYPE_INTERNAL_ERROR )| \
235 (1 << GOLAN_EVENT_TYPE_PORT_CHANGE )| \
236 (1 << GOLAN_EVENT_TYPE_GPIO_EVENT )| \
237 (1 << GOLAN_EVENT_TYPE_CLIENT_RE_REGISTER )| \
238 (1 << GOLAN_EVENT_TYPE_REMOTE_CONFIG )| \
239 (1 << GOLAN_EVENT_TYPE_DB_BF_CONGESTION )| \
240 (1 << GOLAN_EVENT_TYPE_STALL_EVENT )| \
241 (1 << GOLAN_EVENT_TYPE_PACKET_DROPPED )| \
242 (1 << GOLAN_EVENT_TYPE_CMD )| \
243 (1 << GOLAN_EVENT_TYPE_PAGE_REQUEST ))
244
276
286
287
288enum {
291};
292
293enum {
296};
297
306
308 /** Infiniband device */
310 /** Network device */
312 /** VEP number */
314};
315
317 void *inbox;
318 void *outbox;
319};
320
321#define GOLAN_OPEN 0x1
322
343
344#endif /* _GOLAN_H_*/
unsigned int uint32_t
Definition stdint.h:12
unsigned long long uint64_t
Definition stdint.h:13
unsigned char uint8_t
Definition stdint.h:10
#define __be32
Definition bnxt.h:25
#define __be64
Definition bnxt.h:26
Error codes.
#define GOLAN_FW_AREAS_NUM
Definition golan.h:340
#define GOLAN_SEND_WQE_BB_SIZE
Definition golan.h:127
@ GOLAN_EQE_SW_OWNERSHIP
Definition golan.h:289
@ GOLAN_EQE_HW_OWNERSHIP
Definition golan.h:290
@ GOLAN_CQE_SIZE_64
Definition golan.h:204
@ GOLAN_CQE_SIZE_128
Definition golan.h:205
golan_port_sub_event
Definition golan.h:277
@ GOLAN_PORT_CHANGE_SUBTYPE_LID
Definition golan.h:281
@ GOLAN_PORT_CHANGE_SUBTYPE_ACTIVE
Definition golan.h:279
@ GOLAN_PORT_CHANGE_SUBTYPE_GUID
Definition golan.h:283
@ GOLAN_PORT_CHANGE_SUBTYPE_DOWN
Definition golan.h:278
@ GOLAN_PORT_CHANGE_SUBTYPE_INITIALIZED
Definition golan.h:280
@ GOLAN_PORT_CHANGE_SUBTYPE_PKEY
Definition golan.h:282
@ GOLAN_PORT_CHANGE_SUBTYPE_CLIENT_REREG
Definition golan.h:284
golan_ib_qp_state
Definition golan.h:134
@ GOLAN_IB_QPS_ERR
Definition golan.h:141
@ GOLAN_IB_QPS_RTR
Definition golan.h:137
@ GOLAN_IB_QPS_RESET
Definition golan.h:135
@ GOLAN_IB_QPS_SQD
Definition golan.h:139
@ GOLAN_IB_QPS_SQE
Definition golan.h:140
@ GOLAN_IB_QPS_INIT
Definition golan.h:136
@ GOLAN_IB_QPS_RTS
Definition golan.h:138
@ GOLAN_EQ_UNARMED
Definition golan.h:294
@ GOLAN_EQ_ARMED
Definition golan.h:295
golan_event
Definition golan.h:245
@ GOLAN_EVENT_TYPE_SRQ_CATAS_ERROR
Definition golan.h:259
@ GOLAN_EVENT_TYPE_PATH_MIG_FAILED
Definition golan.h:256
@ GOLAN_EVENT_TYPE_CMD
Definition golan.h:272
@ GOLAN_EVENT_TYPE_STALL_EVENT
Definition golan.h:268
@ GOLAN_EVENT_TYPE_PATH_MIG
Definition golan.h:248
@ GOLAN_EVENT_TYPE_SRQ_LAST_WQE
Definition golan.h:251
@ GOLAN_EVENT_TYPE_PORT_CHANGE
Definition golan.h:262
@ GOLAN_EVENT_TYPE_WQ_CATAS_ERROR
Definition golan.h:255
@ GOLAN_EVENT_TYPE_INTERNAL_ERROR
Definition golan.h:261
@ GOLAN_EVENT_TYPE_WQ_ACCESS_ERROR
Definition golan.h:258
@ GOLAN_EVENT_TYPE_PAGE_REQUEST
Definition golan.h:273
@ GOLAN_EVENT_TYPE_COMP
Definition golan.h:246
@ GOLAN_EVENT_TYPE_WQ_INVAL_REQ_ERROR
Definition golan.h:257
@ GOLAN_EVENT_TYPE_SRQ_RQ_LIMIT
Definition golan.h:252
@ GOLAN_EVENT_TYPE_SQ_DRAINED
Definition golan.h:250
@ GOLAN_EVENT_TYPE_PAGE_FAULT
Definition golan.h:274
@ GOLAN_EVENT_TYPE_PACKET_DROPPED
Definition golan.h:270
@ GOLAN_EVENT_TYPE_CQ_ERROR
Definition golan.h:254
@ GOLAN_EVENT_TYPE_COMM_EST
Definition golan.h:249
@ GOLAN_EVENT_TYPE_REMOTE_CONFIG
Definition golan.h:265
@ GOLAN_EVENT_TYPE_DB_BF_CONGESTION
Definition golan.h:267
@ GOLAN_EVENT_TYPE_GPIO_EVENT
Definition golan.h:263
#define GOLAN_MAX_PORTS
Definition golan.h:41
return_hdr_t
Definition golan.h:88
@ NO_ERRORS
Definition golan.h:89
@ BAD_OUTPUT_POINTER
Definition golan.h:93
@ BAD_CMD_TYPE
Definition golan.h:99
@ BAD_INPUT_POINTER
Definition golan.h:94
@ BAD_BLOCK_NUMBER
Definition golan.h:92
@ OUTPUT_LEN_ERROR
Definition golan.h:97
@ RESERVE_NOT_ZERO
Definition golan.h:98
@ INTERNAL_ERROR
Definition golan.h:95
@ INPUT_LEN_ERROR
Definition golan.h:96
@ TOKEN_ERROR
Definition golan.h:91
@ SIGNATURE_ERROR
Definition golan.h:90
@ GOLAN_CQE_SW_OWNERSHIP
Definition golan.h:199
@ GOLAN_CQE_HW_OWNERSHIP
Definition golan.h:200
#define GOLAN_WQEBBS_PER_SEND_UD_WQE
Definition golan.h:130
#define FILE_LICENCE(_licence)
Declare a particular licence as applying to a file.
Definition compiler.h:896
#define u8
Definition igbvf_osdep.h:40
iPXE I/O API
PCI bus.
PCI configuration space backup and restoration.
void * addr
Definition golan.h:103
u16 log_stride
Definition golan.h:104
__be64 * doorbell_record
Definition golan.h:211
struct golan_cqe64 * cqes
Definition golan.h:209
struct golan_eqe * eqes
Definition golan.h:301
__be32 * doorbell
Definition golan.h:303
uint32_t cons_index
Definition golan.h:304
uint8_t eqn
Definition golan.h:299
uint64_t mask
Definition golan.h:300
void * area
Firmware area in external memory.
Definition golan.h:124
uint32_t npages
Definition golan.h:117
void * inbox
Definition golan.h:317
void * outbox
Definition golan.h:318
struct net_device * netdev
Network device.
Definition golan.h:311
u8 vep_number
VEP number.
Definition golan.h:313
struct ib_device * ibdev
Infiniband device.
Definition golan.h:309
struct golan_recv_wq rq
Definition golan.h:182
enum golan_ib_qp_state state
Definition golan.h:186
struct golan_send_wq sq
Definition golan.h:183
struct golan_qp_db * doorbell_record
Definition golan.h:184
void * wqes
Definition golan.h:180
struct golan_recv_wqe_ud * wqes
Definition golan.h:160
u16 next_idx
Definition golan.h:164
size_t grh_size
Size of GRH buffers.
Definition golan.h:168
struct ib_global_route_header * grh
GRH buffers (if applicable)
Definition golan.h:166
struct golan_wqe_data_seg data[2]
Definition golan.h:156
u16 next_idx
Definition golan.h:176
union golan_send_wqe * wqes
Definition golan.h:172
struct golan_av datagram
Definition golan.h:146
struct golan_wqe_ctrl_seg ctrl
Definition golan.h:145
struct golan_wqe_data_seg data
Definition golan.h:147
void * virt
Definition golan.h:110
uint32_t index
Definition golan.h:109
unsigned long phys
Definition golan.h:111
Definition golan.h:323
struct golan_uar uar
Definition golan.h:332
u32 flags
Definition golan.h:336
struct golan_hca_cap caps
Definition golan.h:327
mlx_utils * utils
Definition golan.h:337
struct golan_hca_init_seg * iseg
Definition golan.h:325
struct golan_port ports[GOLAN_MAX_PORTS]
Definition golan.h:339
struct golan_event_queue eq
Definition golan.h:333
struct golan_cmdq_md cmd
Definition golan.h:326
struct list_head pages
Definition golan.h:329
struct pci_device * pci
Definition golan.h:324
u32 mkey
Definition golan.h:335
uint32_t pdn
Definition golan.h:334
struct golan_mboxes mboxes
Definition golan.h:328
uint32_t cmd_bm
Definition golan.h:330
uint32_t total_dma_pages
Definition golan.h:331
struct golan_firmware_area fw_areas[GOLAN_FW_AREAS_NUM]
Definition golan.h:341
An Infiniband device.
Definition infiniband.h:399
An Infiniband Global Route Header.
Definition ib_packet.h:90
A doubly-linked list entry (or list head)
Definition list.h:19
A network device.
Definition netdevice.h:353
A PCI device.
Definition pci.h:211
uint8_t pad[GOLAN_WQEBBS_PER_SEND_UD_WQE *GOLAN_SEND_WQE_BB_SIZE]
Definition golan.h:152
struct golan_send_wqe_ud ud
Definition golan.h:151
#define u16
Definition vga.h:20
#define u32
Definition vga.h:21