~pmdj/ubuntu/trusty/qemu/2.9+applesmc+fadtv3

« back to all changes in this revision

Viewing changes to roms/ipxe/src/drivers/infiniband/golan.h

  • Committer: Phil Dennis-Jordan
  • Date: 2017-07-21 08:03:43 UTC
  • mfrom: (1.1.1)
  • Revision ID: phil@philjordan.eu-20170721080343-2yr2vdj7713czahv
New upstream release 2.9.0.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
 
23
FILE_LICENCE ( GPL2_OR_LATER );
 
24
 
 
25
#include <byteswap.h>
 
26
#include <errno.h>
 
27
#include <stdio.h>
 
28
#include <unistd.h>
 
29
#include <ipxe/io.h>
 
30
#include <ipxe/pci.h>
 
31
#include <ipxe/pcibackup.h>
 
32
#include "CIB_PRM.h"
 
33
 
 
34
#define GOLAN_PCI_CONFIG_BAR_SIZE       0x100000//HERMON_PCI_CONFIG_BAR_SIZE //TODO: What is the BAR size?
 
35
 
 
36
#define GOLAN_PAS_SIZE  sizeof(uint64_t)
 
37
 
 
38
#define GOLAN_INVALID_LKEY 0x00000100UL
 
39
 
 
40
#define GOLAN_MAX_PORTS 2
 
41
#define GOLAN_PORT_BASE 1
 
42
 
 
43
#define MELLANOX_VID    0x15b3
 
44
#define GOLAN_HCA_BAR   PCI_BASE_ADDRESS_0      //BAR 0
 
45
 
 
46
#define GOLAN_HCR_MAX_WAIT_MS   10000
 
47
 
 
48
#define min(a,b) ((a)<(b)?(a):(b))
 
49
 
 
50
#define GOLAN_PAGE_SHIFT        12
 
51
#define GOLAN_PAGE_SIZE         (1 << GOLAN_PAGE_SHIFT)
 
52
#define GOLAN_PAGE_MASK         (GOLAN_PAGE_SIZE - 1)
 
53
 
 
54
#define MAX_MBOX        ( GOLAN_PAGE_SIZE / MAILBOX_STRIDE )
 
55
#define DEF_CMD_IDX     1
 
56
#define MEM_CMD_IDX     0
 
57
#define NO_MBOX         0xffff
 
58
#define MEM_MBOX        MEM_CMD_IDX
 
59
#define GEN_MBOX        DEF_CMD_IDX
 
60
 
 
61
#define CMD_IF_REV      4
 
62
 
 
63
#define MAX_PASE_MBOX   ((GOLAN_CMD_PAS_CNT) - 2)
 
64
 
 
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))
 
68
 
 
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))
 
73
 
 
74
#define GET_INBOX(golan, idx)           (&(((struct mbox *)(golan->mboxes.inbox))[idx]))
 
75
#define GET_OUTBOX(golan, idx)          (&(((struct mbox *)(golan->mboxes.outbox))[idx]))
 
76
 
 
77
#define GOLAN_MBOX_IN( cmd_ptr, in_ptr ) ( {                              \
 
78
        union {                                                           \
 
79
                __be32 raw[4];                                            \
 
80
                typeof ( *(in_ptr) ) cooked;                              \
 
81
        } *u = container_of ( &(cmd_ptr)->in[0], typeof ( *u ), raw[0] ); \
 
82
        &u->cooked; } )
 
83
 
 
84
#define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d))
 
85
 
 
86
/* Fw status fields */
 
87
typedef enum {
 
88
        NO_ERRORS          = 0x0,
 
89
        SIGNATURE_ERROR    = 0x1,
 
90
        TOKEN_ERROR        = 0x2,
 
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
 
94
        INTERNAL_ERROR     = 0x6,
 
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,
 
98
        BAD_CMD_TYPE       = 0x10,
 
99
} return_hdr_t;
 
100
 
 
101
struct golan_cmdq_md {
 
102
        void    *addr;
 
103
        u16     log_stride;
 
104
        u16     size;
 
105
};
 
106
 
 
107
struct golan_uar {
 
108
    uint32_t            index;
 
109
    void                *virt;
 
110
    unsigned long       phys;
 
111
};
 
112
 
 
113
/* Queue Pair */
 
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
 
120
 
 
121
enum golan_ib_qp_state {
 
122
        GOLAN_IB_QPS_RESET,
 
123
        GOLAN_IB_QPS_INIT,
 
124
        GOLAN_IB_QPS_RTR,
 
125
        GOLAN_IB_QPS_RTS,
 
126
        GOLAN_IB_QPS_SQD,
 
127
        GOLAN_IB_QPS_SQE,
 
128
        GOLAN_IB_QPS_ERR
 
129
};
 
130
 
 
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;
 
135
};
 
136
 
 
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];
 
140
};
 
141
 
 
142
struct golan_recv_wqe_ud {
 
143
        struct golan_wqe_data_seg data[2];
 
144
};
 
145
 
 
146
struct golan_recv_wq {
 
147
        struct golan_recv_wqe_ud *wqes;
 
148
        /* WQ size in bytes */
 
149
        int     size;
 
150
        /* In SQ, it will be increased in wqe_size (number of WQEBBs per WQE) */
 
151
        u16 next_idx;
 
152
        /** GRH buffers (if applicable) */
 
153
        struct ib_global_route_header *grh;
 
154
        /** Size of GRH buffers */
 
155
        size_t grh_size;
 
156
};
 
157
 
 
158
struct golan_send_wq {
 
159
        union golan_send_wqe *wqes;
 
160
        /* WQ size in bytes */
 
161
        int size;
 
162
        /* In SQ, it will be increased in wqe_size (number of WQEBBs per WQE) */
 
163
        u16 next_idx;
 
164
};
 
165
 
 
166
struct golan_queue_pair {
 
167
        void *wqes;
 
168
        int size;
 
169
        struct golan_recv_wq rq;
 
170
        struct golan_send_wq sq;
 
171
        struct golan_qp_db *doorbell_record;
 
172
        u32 doorbell_qpn;
 
173
        enum golan_ib_qp_state state;
 
174
};
 
175
 
 
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
 
181
 
 
182
#define MANAGE_PAGES_PSA_OFFSET         0
 
183
#define PXE_CMDIF_REF                   5
 
184
 
 
185
enum {
 
186
        GOLAN_CQE_SW_OWNERSHIP = 0x0,
 
187
        GOLAN_CQE_HW_OWNERSHIP = 0x1
 
188
};
 
189
 
 
190
enum {
 
191
        GOLAN_CQE_SIZE_64       = 0,
 
192
        GOLAN_CQE_SIZE_128      = 1
 
193
};
 
194
 
 
195
struct golan_completion_queue {
 
196
        struct golan_cqe64      *cqes;
 
197
        int                                     size;
 
198
        __be64          *doorbell_record;
 
199
};
 
200
 
 
201
 
 
202
/* Event Queue */
 
203
#define GOLAN_EQE_SIZE                          sizeof(struct golan_eqe)
 
204
#define GOLAN_NUM_EQES                          8
 
205
#define GOLAN_EQ_DOORBELL_OFFSET                0x40
 
206
 
 
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             ))
 
229
 
 
230
enum golan_event {
 
231
        GOLAN_EVENT_TYPE_COMP                   = 0x0,
 
232
 
 
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,
 
238
 
 
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,
 
245
 
 
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,
 
251
 
 
252
        GOLAN_EVENT_TYPE_DB_BF_CONGESTION       = 0x1a,
 
253
        GOLAN_EVENT_TYPE_STALL_EVENT            = 0x1b,
 
254
 
 
255
        GOLAN_EVENT_TYPE_PACKET_DROPPED         = 0x1f,
 
256
 
 
257
        GOLAN_EVENT_TYPE_CMD                    = 0x0a,
 
258
        GOLAN_EVENT_TYPE_PAGE_REQUEST           = 0x0b,
 
259
        GOLAN_EVENT_TYPE_PAGE_FAULT             = 0x0C,
 
260
};
 
261
 
 
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
 
270
};
 
271
 
 
272
 
 
273
enum {
 
274
        GOLAN_EQE_SW_OWNERSHIP = 0x0,
 
275
        GOLAN_EQE_HW_OWNERSHIP = 0x1
 
276
};
 
277
 
 
278
enum {
 
279
        GOLAN_EQ_UNARMED        = 0,
 
280
        GOLAN_EQ_ARMED          = 1,
 
281
};
 
282
 
 
283
struct golan_event_queue {
 
284
        uint8_t                 eqn;
 
285
        uint64_t                mask;
 
286
        struct golan_eqe        *eqes;
 
287
        int                     size;
 
288
        __be32                  *doorbell;
 
289
        uint32_t                cons_index;
 
290
};
 
291
 
 
292
struct golan_port {
 
293
        /** Infiniband device */
 
294
        struct ib_device        *ibdev;
 
295
        /** Network device */
 
296
        struct net_device       *netdev;
 
297
        /** VEP number */
 
298
        u8 vep_number;
 
299
};
 
300
 
 
301
struct golan_mboxes {
 
302
        void    *inbox;
 
303
        void    *outbox;
 
304
};
 
305
 
 
306
#define GOLAN_OPEN      0x1
 
307
 
 
308
struct golan {
 
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;
 
315
        uint32_t                        cmd_bm;
 
316
        uint32_t                        total_dma_pages;
 
317
        struct golan_uar                uar;
 
318
        struct golan_event_queue        eq;
 
319
        uint32_t                        pdn;
 
320
        u32                             mkey;
 
321
        u32                             flags;
 
322
 
 
323
        struct golan_port               ports[GOLAN_MAX_PORTS];
 
324
};
 
325
 
 
326
#endif /* _GOLAN_H_*/