net/mlx4_core: Add timestamping device capability
[linux-drm-fsl-dcu.git] / include / linux / mlx4 / device.h
1 /*
2  * Copyright (c) 2006, 2007 Cisco Systems, Inc.  All rights reserved.
3  *
4  * This software is available to you under a choice of one of two
5  * licenses.  You may choose to be licensed under the terms of the GNU
6  * General Public License (GPL) Version 2, available from the file
7  * COPYING in the main directory of this source tree, or the
8  * OpenIB.org BSD license below:
9  *
10  *     Redistribution and use in source and binary forms, with or
11  *     without modification, are permitted provided that the following
12  *     conditions are met:
13  *
14  *      - Redistributions of source code must retain the above
15  *        copyright notice, this list of conditions and the following
16  *        disclaimer.
17  *
18  *      - Redistributions in binary form must reproduce the above
19  *        copyright notice, this list of conditions and the following
20  *        disclaimer in the documentation and/or other materials
21  *        provided with the distribution.
22  *
23  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
27  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30  * SOFTWARE.
31  */
32
33 #ifndef MLX4_DEVICE_H
34 #define MLX4_DEVICE_H
35
36 #include <linux/pci.h>
37 #include <linux/completion.h>
38 #include <linux/radix-tree.h>
39 #include <linux/cpu_rmap.h>
40
41 #include <linux/atomic.h>
42
43 #define MAX_MSIX_P_PORT         17
44 #define MAX_MSIX                64
45 #define MSIX_LEGACY_SZ          4
46 #define MIN_MSIX_P_PORT         5
47
48 enum {
49         MLX4_FLAG_MSI_X         = 1 << 0,
50         MLX4_FLAG_OLD_PORT_CMDS = 1 << 1,
51         MLX4_FLAG_MASTER        = 1 << 2,
52         MLX4_FLAG_SLAVE         = 1 << 3,
53         MLX4_FLAG_SRIOV         = 1 << 4,
54 };
55
56 enum {
57         MLX4_PORT_CAP_IS_SM     = 1 << 1,
58         MLX4_PORT_CAP_DEV_MGMT_SUP = 1 << 19,
59 };
60
61 enum {
62         MLX4_MAX_PORTS          = 2,
63         MLX4_MAX_PORT_PKEYS     = 128
64 };
65
66 /* base qkey for use in sriov tunnel-qp/proxy-qp communication.
67  * These qkeys must not be allowed for general use. This is a 64k range,
68  * and to test for violation, we use the mask (protect against future chg).
69  */
70 #define MLX4_RESERVED_QKEY_BASE  (0xFFFF0000)
71 #define MLX4_RESERVED_QKEY_MASK  (0xFFFF0000)
72
73 enum {
74         MLX4_BOARD_ID_LEN = 64
75 };
76
77 enum {
78         MLX4_MAX_NUM_PF         = 16,
79         MLX4_MAX_NUM_VF         = 64,
80         MLX4_MFUNC_MAX          = 80,
81         MLX4_MAX_EQ_NUM         = 1024,
82         MLX4_MFUNC_EQ_NUM       = 4,
83         MLX4_MFUNC_MAX_EQES     = 8,
84         MLX4_MFUNC_EQE_MASK     = (MLX4_MFUNC_MAX_EQES - 1)
85 };
86
87 /* Driver supports 3 diffrent device methods to manage traffic steering:
88  *      -device managed - High level API for ib and eth flow steering. FW is
89  *                        managing flow steering tables.
90  *      - B0 steering mode - Common low level API for ib and (if supported) eth.
91  *      - A0 steering mode - Limited low level API for eth. In case of IB,
92  *                           B0 mode is in use.
93  */
94 enum {
95         MLX4_STEERING_MODE_A0,
96         MLX4_STEERING_MODE_B0,
97         MLX4_STEERING_MODE_DEVICE_MANAGED
98 };
99
100 static inline const char *mlx4_steering_mode_str(int steering_mode)
101 {
102         switch (steering_mode) {
103         case MLX4_STEERING_MODE_A0:
104                 return "A0 steering";
105
106         case MLX4_STEERING_MODE_B0:
107                 return "B0 steering";
108
109         case MLX4_STEERING_MODE_DEVICE_MANAGED:
110                 return "Device managed flow steering";
111
112         default:
113                 return "Unrecognize steering mode";
114         }
115 }
116
117 enum {
118         MLX4_DEV_CAP_FLAG_RC            = 1LL <<  0,
119         MLX4_DEV_CAP_FLAG_UC            = 1LL <<  1,
120         MLX4_DEV_CAP_FLAG_UD            = 1LL <<  2,
121         MLX4_DEV_CAP_FLAG_XRC           = 1LL <<  3,
122         MLX4_DEV_CAP_FLAG_SRQ           = 1LL <<  6,
123         MLX4_DEV_CAP_FLAG_IPOIB_CSUM    = 1LL <<  7,
124         MLX4_DEV_CAP_FLAG_BAD_PKEY_CNTR = 1LL <<  8,
125         MLX4_DEV_CAP_FLAG_BAD_QKEY_CNTR = 1LL <<  9,
126         MLX4_DEV_CAP_FLAG_DPDP          = 1LL << 12,
127         MLX4_DEV_CAP_FLAG_BLH           = 1LL << 15,
128         MLX4_DEV_CAP_FLAG_MEM_WINDOW    = 1LL << 16,
129         MLX4_DEV_CAP_FLAG_APM           = 1LL << 17,
130         MLX4_DEV_CAP_FLAG_ATOMIC        = 1LL << 18,
131         MLX4_DEV_CAP_FLAG_RAW_MCAST     = 1LL << 19,
132         MLX4_DEV_CAP_FLAG_UD_AV_PORT    = 1LL << 20,
133         MLX4_DEV_CAP_FLAG_UD_MCAST      = 1LL << 21,
134         MLX4_DEV_CAP_FLAG_IBOE          = 1LL << 30,
135         MLX4_DEV_CAP_FLAG_UC_LOOPBACK   = 1LL << 32,
136         MLX4_DEV_CAP_FLAG_FCS_KEEP      = 1LL << 34,
137         MLX4_DEV_CAP_FLAG_WOL_PORT1     = 1LL << 37,
138         MLX4_DEV_CAP_FLAG_WOL_PORT2     = 1LL << 38,
139         MLX4_DEV_CAP_FLAG_UDP_RSS       = 1LL << 40,
140         MLX4_DEV_CAP_FLAG_VEP_UC_STEER  = 1LL << 41,
141         MLX4_DEV_CAP_FLAG_VEP_MC_STEER  = 1LL << 42,
142         MLX4_DEV_CAP_FLAG_COUNTERS      = 1LL << 48,
143         MLX4_DEV_CAP_FLAG_SET_ETH_SCHED = 1LL << 53,
144         MLX4_DEV_CAP_FLAG_SENSE_SUPPORT = 1LL << 55,
145         MLX4_DEV_CAP_FLAG_PORT_MNG_CHG_EV = 1LL << 59,
146         MLX4_DEV_CAP_FLAG_64B_EQE       = 1LL << 61,
147         MLX4_DEV_CAP_FLAG_64B_CQE       = 1LL << 62
148 };
149
150 enum {
151         MLX4_DEV_CAP_FLAG2_RSS                  = 1LL <<  0,
152         MLX4_DEV_CAP_FLAG2_RSS_TOP              = 1LL <<  1,
153         MLX4_DEV_CAP_FLAG2_RSS_XOR              = 1LL <<  2,
154         MLX4_DEV_CAP_FLAG2_FS_EN                = 1LL <<  3,
155         MLX4_DEV_CAP_FLAGS2_REASSIGN_MAC_EN     = 1LL <<  4,
156         MLX4_DEV_CAP_FLAG2_TS                   = 1LL <<  5
157 };
158
159 enum {
160         MLX4_DEV_CAP_64B_EQE_ENABLED    = 1LL << 0,
161         MLX4_DEV_CAP_64B_CQE_ENABLED    = 1LL << 1
162 };
163
164 enum {
165         MLX4_USER_DEV_CAP_64B_CQE       = 1L << 0
166 };
167
168 enum {
169         MLX4_FUNC_CAP_64B_EQE_CQE       = 1L << 0
170 };
171
172
173 #define MLX4_ATTR_EXTENDED_PORT_INFO    cpu_to_be16(0xff90)
174
175 enum {
176         MLX4_BMME_FLAG_WIN_TYPE_2B      = 1 <<  1,
177         MLX4_BMME_FLAG_LOCAL_INV        = 1 <<  6,
178         MLX4_BMME_FLAG_REMOTE_INV       = 1 <<  7,
179         MLX4_BMME_FLAG_TYPE_2_WIN       = 1 <<  9,
180         MLX4_BMME_FLAG_RESERVED_LKEY    = 1 << 10,
181         MLX4_BMME_FLAG_FAST_REG_WR      = 1 << 11,
182 };
183
184 enum mlx4_event {
185         MLX4_EVENT_TYPE_COMP               = 0x00,
186         MLX4_EVENT_TYPE_PATH_MIG           = 0x01,
187         MLX4_EVENT_TYPE_COMM_EST           = 0x02,
188         MLX4_EVENT_TYPE_SQ_DRAINED         = 0x03,
189         MLX4_EVENT_TYPE_SRQ_QP_LAST_WQE    = 0x13,
190         MLX4_EVENT_TYPE_SRQ_LIMIT          = 0x14,
191         MLX4_EVENT_TYPE_CQ_ERROR           = 0x04,
192         MLX4_EVENT_TYPE_WQ_CATAS_ERROR     = 0x05,
193         MLX4_EVENT_TYPE_EEC_CATAS_ERROR    = 0x06,
194         MLX4_EVENT_TYPE_PATH_MIG_FAILED    = 0x07,
195         MLX4_EVENT_TYPE_WQ_INVAL_REQ_ERROR = 0x10,
196         MLX4_EVENT_TYPE_WQ_ACCESS_ERROR    = 0x11,
197         MLX4_EVENT_TYPE_SRQ_CATAS_ERROR    = 0x12,
198         MLX4_EVENT_TYPE_LOCAL_CATAS_ERROR  = 0x08,
199         MLX4_EVENT_TYPE_PORT_CHANGE        = 0x09,
200         MLX4_EVENT_TYPE_EQ_OVERFLOW        = 0x0f,
201         MLX4_EVENT_TYPE_ECC_DETECT         = 0x0e,
202         MLX4_EVENT_TYPE_CMD                = 0x0a,
203         MLX4_EVENT_TYPE_VEP_UPDATE         = 0x19,
204         MLX4_EVENT_TYPE_COMM_CHANNEL       = 0x18,
205         MLX4_EVENT_TYPE_FATAL_WARNING      = 0x1b,
206         MLX4_EVENT_TYPE_FLR_EVENT          = 0x1c,
207         MLX4_EVENT_TYPE_PORT_MNG_CHG_EVENT = 0x1d,
208         MLX4_EVENT_TYPE_NONE               = 0xff,
209 };
210
211 enum {
212         MLX4_PORT_CHANGE_SUBTYPE_DOWN   = 1,
213         MLX4_PORT_CHANGE_SUBTYPE_ACTIVE = 4
214 };
215
216 enum {
217         MLX4_FATAL_WARNING_SUBTYPE_WARMING = 0,
218 };
219
220 enum slave_port_state {
221         SLAVE_PORT_DOWN = 0,
222         SLAVE_PENDING_UP,
223         SLAVE_PORT_UP,
224 };
225
226 enum slave_port_gen_event {
227         SLAVE_PORT_GEN_EVENT_DOWN = 0,
228         SLAVE_PORT_GEN_EVENT_UP,
229         SLAVE_PORT_GEN_EVENT_NONE,
230 };
231
232 enum slave_port_state_event {
233         MLX4_PORT_STATE_DEV_EVENT_PORT_DOWN,
234         MLX4_PORT_STATE_DEV_EVENT_PORT_UP,
235         MLX4_PORT_STATE_IB_PORT_STATE_EVENT_GID_VALID,
236         MLX4_PORT_STATE_IB_EVENT_GID_INVALID,
237 };
238
239 enum {
240         MLX4_PERM_LOCAL_READ    = 1 << 10,
241         MLX4_PERM_LOCAL_WRITE   = 1 << 11,
242         MLX4_PERM_REMOTE_READ   = 1 << 12,
243         MLX4_PERM_REMOTE_WRITE  = 1 << 13,
244         MLX4_PERM_ATOMIC        = 1 << 14,
245         MLX4_PERM_BIND_MW       = 1 << 15,
246 };
247
248 enum {
249         MLX4_OPCODE_NOP                 = 0x00,
250         MLX4_OPCODE_SEND_INVAL          = 0x01,
251         MLX4_OPCODE_RDMA_WRITE          = 0x08,
252         MLX4_OPCODE_RDMA_WRITE_IMM      = 0x09,
253         MLX4_OPCODE_SEND                = 0x0a,
254         MLX4_OPCODE_SEND_IMM            = 0x0b,
255         MLX4_OPCODE_LSO                 = 0x0e,
256         MLX4_OPCODE_RDMA_READ           = 0x10,
257         MLX4_OPCODE_ATOMIC_CS           = 0x11,
258         MLX4_OPCODE_ATOMIC_FA           = 0x12,
259         MLX4_OPCODE_MASKED_ATOMIC_CS    = 0x14,
260         MLX4_OPCODE_MASKED_ATOMIC_FA    = 0x15,
261         MLX4_OPCODE_BIND_MW             = 0x18,
262         MLX4_OPCODE_FMR                 = 0x19,
263         MLX4_OPCODE_LOCAL_INVAL         = 0x1b,
264         MLX4_OPCODE_CONFIG_CMD          = 0x1f,
265
266         MLX4_RECV_OPCODE_RDMA_WRITE_IMM = 0x00,
267         MLX4_RECV_OPCODE_SEND           = 0x01,
268         MLX4_RECV_OPCODE_SEND_IMM       = 0x02,
269         MLX4_RECV_OPCODE_SEND_INVAL     = 0x03,
270
271         MLX4_CQE_OPCODE_ERROR           = 0x1e,
272         MLX4_CQE_OPCODE_RESIZE          = 0x16,
273 };
274
275 enum {
276         MLX4_STAT_RATE_OFFSET   = 5
277 };
278
279 enum mlx4_protocol {
280         MLX4_PROT_IB_IPV6 = 0,
281         MLX4_PROT_ETH,
282         MLX4_PROT_IB_IPV4,
283         MLX4_PROT_FCOE
284 };
285
286 enum {
287         MLX4_MTT_FLAG_PRESENT           = 1
288 };
289
290 enum mlx4_qp_region {
291         MLX4_QP_REGION_FW = 0,
292         MLX4_QP_REGION_ETH_ADDR,
293         MLX4_QP_REGION_FC_ADDR,
294         MLX4_QP_REGION_FC_EXCH,
295         MLX4_NUM_QP_REGION
296 };
297
298 enum mlx4_port_type {
299         MLX4_PORT_TYPE_NONE     = 0,
300         MLX4_PORT_TYPE_IB       = 1,
301         MLX4_PORT_TYPE_ETH      = 2,
302         MLX4_PORT_TYPE_AUTO     = 3
303 };
304
305 enum mlx4_special_vlan_idx {
306         MLX4_NO_VLAN_IDX        = 0,
307         MLX4_VLAN_MISS_IDX,
308         MLX4_VLAN_REGULAR
309 };
310
311 enum mlx4_steer_type {
312         MLX4_MC_STEER = 0,
313         MLX4_UC_STEER,
314         MLX4_NUM_STEERS
315 };
316
317 enum {
318         MLX4_NUM_FEXCH          = 64 * 1024,
319 };
320
321 enum {
322         MLX4_MAX_FAST_REG_PAGES = 511,
323 };
324
325 enum {
326         MLX4_DEV_PMC_SUBTYPE_GUID_INFO   = 0x14,
327         MLX4_DEV_PMC_SUBTYPE_PORT_INFO   = 0x15,
328         MLX4_DEV_PMC_SUBTYPE_PKEY_TABLE  = 0x16,
329 };
330
331 /* Port mgmt change event handling */
332 enum {
333         MLX4_EQ_PORT_INFO_MSTR_SM_LID_CHANGE_MASK       = 1 << 0,
334         MLX4_EQ_PORT_INFO_GID_PFX_CHANGE_MASK           = 1 << 1,
335         MLX4_EQ_PORT_INFO_LID_CHANGE_MASK               = 1 << 2,
336         MLX4_EQ_PORT_INFO_CLIENT_REREG_MASK             = 1 << 3,
337         MLX4_EQ_PORT_INFO_MSTR_SM_SL_CHANGE_MASK        = 1 << 4,
338 };
339
340 #define MSTR_SM_CHANGE_MASK (MLX4_EQ_PORT_INFO_MSTR_SM_SL_CHANGE_MASK | \
341                              MLX4_EQ_PORT_INFO_MSTR_SM_LID_CHANGE_MASK)
342
343 static inline u64 mlx4_fw_ver(u64 major, u64 minor, u64 subminor)
344 {
345         return (major << 32) | (minor << 16) | subminor;
346 }
347
348 struct mlx4_phys_caps {
349         u32                     gid_phys_table_len[MLX4_MAX_PORTS + 1];
350         u32                     pkey_phys_table_len[MLX4_MAX_PORTS + 1];
351         u32                     num_phys_eqs;
352         u32                     base_sqpn;
353         u32                     base_proxy_sqpn;
354         u32                     base_tunnel_sqpn;
355 };
356
357 struct mlx4_caps {
358         u64                     fw_ver;
359         u32                     function;
360         int                     num_ports;
361         int                     vl_cap[MLX4_MAX_PORTS + 1];
362         int                     ib_mtu_cap[MLX4_MAX_PORTS + 1];
363         __be32                  ib_port_def_cap[MLX4_MAX_PORTS + 1];
364         u64                     def_mac[MLX4_MAX_PORTS + 1];
365         int                     eth_mtu_cap[MLX4_MAX_PORTS + 1];
366         int                     gid_table_len[MLX4_MAX_PORTS + 1];
367         int                     pkey_table_len[MLX4_MAX_PORTS + 1];
368         int                     trans_type[MLX4_MAX_PORTS + 1];
369         int                     vendor_oui[MLX4_MAX_PORTS + 1];
370         int                     wavelength[MLX4_MAX_PORTS + 1];
371         u64                     trans_code[MLX4_MAX_PORTS + 1];
372         int                     local_ca_ack_delay;
373         int                     num_uars;
374         u32                     uar_page_size;
375         int                     bf_reg_size;
376         int                     bf_regs_per_page;
377         int                     max_sq_sg;
378         int                     max_rq_sg;
379         int                     num_qps;
380         int                     max_wqes;
381         int                     max_sq_desc_sz;
382         int                     max_rq_desc_sz;
383         int                     max_qp_init_rdma;
384         int                     max_qp_dest_rdma;
385         u32                     *qp0_proxy;
386         u32                     *qp1_proxy;
387         u32                     *qp0_tunnel;
388         u32                     *qp1_tunnel;
389         int                     num_srqs;
390         int                     max_srq_wqes;
391         int                     max_srq_sge;
392         int                     reserved_srqs;
393         int                     num_cqs;
394         int                     max_cqes;
395         int                     reserved_cqs;
396         int                     num_eqs;
397         int                     reserved_eqs;
398         int                     num_comp_vectors;
399         int                     comp_pool;
400         int                     num_mpts;
401         int                     max_fmr_maps;
402         int                     num_mtts;
403         int                     fmr_reserved_mtts;
404         int                     reserved_mtts;
405         int                     reserved_mrws;
406         int                     reserved_uars;
407         int                     num_mgms;
408         int                     num_amgms;
409         int                     reserved_mcgs;
410         int                     num_qp_per_mgm;
411         int                     steering_mode;
412         int                     fs_log_max_ucast_qp_range_size;
413         int                     num_pds;
414         int                     reserved_pds;
415         int                     max_xrcds;
416         int                     reserved_xrcds;
417         int                     mtt_entry_sz;
418         u32                     max_msg_sz;
419         u32                     page_size_cap;
420         u64                     flags;
421         u64                     flags2;
422         u32                     bmme_flags;
423         u32                     reserved_lkey;
424         u16                     stat_rate_support;
425         u8                      port_width_cap[MLX4_MAX_PORTS + 1];
426         int                     max_gso_sz;
427         int                     max_rss_tbl_sz;
428         int                     reserved_qps_cnt[MLX4_NUM_QP_REGION];
429         int                     reserved_qps;
430         int                     reserved_qps_base[MLX4_NUM_QP_REGION];
431         int                     log_num_macs;
432         int                     log_num_vlans;
433         int                     log_num_prios;
434         enum mlx4_port_type     port_type[MLX4_MAX_PORTS + 1];
435         u8                      supported_type[MLX4_MAX_PORTS + 1];
436         u8                      suggested_type[MLX4_MAX_PORTS + 1];
437         u8                      default_sense[MLX4_MAX_PORTS + 1];
438         u32                     port_mask[MLX4_MAX_PORTS + 1];
439         enum mlx4_port_type     possible_type[MLX4_MAX_PORTS + 1];
440         u32                     max_counters;
441         u8                      port_ib_mtu[MLX4_MAX_PORTS + 1];
442         u16                     sqp_demux;
443         u32                     eqe_size;
444         u32                     cqe_size;
445         u8                      eqe_factor;
446         u32                     userspace_caps; /* userspace must be aware of these */
447         u32                     function_caps;  /* VFs must be aware of these */
448 };
449
450 struct mlx4_buf_list {
451         void                   *buf;
452         dma_addr_t              map;
453 };
454
455 struct mlx4_buf {
456         struct mlx4_buf_list    direct;
457         struct mlx4_buf_list   *page_list;
458         int                     nbufs;
459         int                     npages;
460         int                     page_shift;
461 };
462
463 struct mlx4_mtt {
464         u32                     offset;
465         int                     order;
466         int                     page_shift;
467 };
468
469 enum {
470         MLX4_DB_PER_PAGE = PAGE_SIZE / 4
471 };
472
473 struct mlx4_db_pgdir {
474         struct list_head        list;
475         DECLARE_BITMAP(order0, MLX4_DB_PER_PAGE);
476         DECLARE_BITMAP(order1, MLX4_DB_PER_PAGE / 2);
477         unsigned long          *bits[2];
478         __be32                 *db_page;
479         dma_addr_t              db_dma;
480 };
481
482 struct mlx4_ib_user_db_page;
483
484 struct mlx4_db {
485         __be32                  *db;
486         union {
487                 struct mlx4_db_pgdir            *pgdir;
488                 struct mlx4_ib_user_db_page     *user_page;
489         }                       u;
490         dma_addr_t              dma;
491         int                     index;
492         int                     order;
493 };
494
495 struct mlx4_hwq_resources {
496         struct mlx4_db          db;
497         struct mlx4_mtt         mtt;
498         struct mlx4_buf         buf;
499 };
500
501 struct mlx4_mr {
502         struct mlx4_mtt         mtt;
503         u64                     iova;
504         u64                     size;
505         u32                     key;
506         u32                     pd;
507         u32                     access;
508         int                     enabled;
509 };
510
511 enum mlx4_mw_type {
512         MLX4_MW_TYPE_1 = 1,
513         MLX4_MW_TYPE_2 = 2,
514 };
515
516 struct mlx4_mw {
517         u32                     key;
518         u32                     pd;
519         enum mlx4_mw_type       type;
520         int                     enabled;
521 };
522
523 struct mlx4_fmr {
524         struct mlx4_mr          mr;
525         struct mlx4_mpt_entry  *mpt;
526         __be64                 *mtts;
527         dma_addr_t              dma_handle;
528         int                     max_pages;
529         int                     max_maps;
530         int                     maps;
531         u8                      page_shift;
532 };
533
534 struct mlx4_uar {
535         unsigned long           pfn;
536         int                     index;
537         struct list_head        bf_list;
538         unsigned                free_bf_bmap;
539         void __iomem           *map;
540         void __iomem           *bf_map;
541 };
542
543 struct mlx4_bf {
544         unsigned long           offset;
545         int                     buf_size;
546         struct mlx4_uar        *uar;
547         void __iomem           *reg;
548 };
549
550 struct mlx4_cq {
551         void (*comp)            (struct mlx4_cq *);
552         void (*event)           (struct mlx4_cq *, enum mlx4_event);
553
554         struct mlx4_uar        *uar;
555
556         u32                     cons_index;
557
558         __be32                 *set_ci_db;
559         __be32                 *arm_db;
560         int                     arm_sn;
561
562         int                     cqn;
563         unsigned                vector;
564
565         atomic_t                refcount;
566         struct completion       free;
567 };
568
569 struct mlx4_qp {
570         void (*event)           (struct mlx4_qp *, enum mlx4_event);
571
572         int                     qpn;
573
574         atomic_t                refcount;
575         struct completion       free;
576 };
577
578 struct mlx4_srq {
579         void (*event)           (struct mlx4_srq *, enum mlx4_event);
580
581         int                     srqn;
582         int                     max;
583         int                     max_gs;
584         int                     wqe_shift;
585
586         atomic_t                refcount;
587         struct completion       free;
588 };
589
590 struct mlx4_av {
591         __be32                  port_pd;
592         u8                      reserved1;
593         u8                      g_slid;
594         __be16                  dlid;
595         u8                      reserved2;
596         u8                      gid_index;
597         u8                      stat_rate;
598         u8                      hop_limit;
599         __be32                  sl_tclass_flowlabel;
600         u8                      dgid[16];
601 };
602
603 struct mlx4_eth_av {
604         __be32          port_pd;
605         u8              reserved1;
606         u8              smac_idx;
607         u16             reserved2;
608         u8              reserved3;
609         u8              gid_index;
610         u8              stat_rate;
611         u8              hop_limit;
612         __be32          sl_tclass_flowlabel;
613         u8              dgid[16];
614         u32             reserved4[2];
615         __be16          vlan;
616         u8              mac[6];
617 };
618
619 union mlx4_ext_av {
620         struct mlx4_av          ib;
621         struct mlx4_eth_av      eth;
622 };
623
624 struct mlx4_counter {
625         u8      reserved1[3];
626         u8      counter_mode;
627         __be32  num_ifc;
628         u32     reserved2[2];
629         __be64  rx_frames;
630         __be64  rx_bytes;
631         __be64  tx_frames;
632         __be64  tx_bytes;
633 };
634
635 struct mlx4_dev {
636         struct pci_dev         *pdev;
637         unsigned long           flags;
638         unsigned long           num_slaves;
639         struct mlx4_caps        caps;
640         struct mlx4_phys_caps   phys_caps;
641         struct radix_tree_root  qp_table_tree;
642         u8                      rev_id;
643         char                    board_id[MLX4_BOARD_ID_LEN];
644         int                     num_vfs;
645         int                     oper_log_mgm_entry_size;
646         u64                     regid_promisc_array[MLX4_MAX_PORTS + 1];
647         u64                     regid_allmulti_array[MLX4_MAX_PORTS + 1];
648 };
649
650 struct mlx4_eqe {
651         u8                      reserved1;
652         u8                      type;
653         u8                      reserved2;
654         u8                      subtype;
655         union {
656                 u32             raw[6];
657                 struct {
658                         __be32  cqn;
659                 } __packed comp;
660                 struct {
661                         u16     reserved1;
662                         __be16  token;
663                         u32     reserved2;
664                         u8      reserved3[3];
665                         u8      status;
666                         __be64  out_param;
667                 } __packed cmd;
668                 struct {
669                         __be32  qpn;
670                 } __packed qp;
671                 struct {
672                         __be32  srqn;
673                 } __packed srq;
674                 struct {
675                         __be32  cqn;
676                         u32     reserved1;
677                         u8      reserved2[3];
678                         u8      syndrome;
679                 } __packed cq_err;
680                 struct {
681                         u32     reserved1[2];
682                         __be32  port;
683                 } __packed port_change;
684                 struct {
685                         #define COMM_CHANNEL_BIT_ARRAY_SIZE     4
686                         u32 reserved;
687                         u32 bit_vec[COMM_CHANNEL_BIT_ARRAY_SIZE];
688                 } __packed comm_channel_arm;
689                 struct {
690                         u8      port;
691                         u8      reserved[3];
692                         __be64  mac;
693                 } __packed mac_update;
694                 struct {
695                         __be32  slave_id;
696                 } __packed flr_event;
697                 struct {
698                         __be16  current_temperature;
699                         __be16  warning_threshold;
700                 } __packed warming;
701                 struct {
702                         u8 reserved[3];
703                         u8 port;
704                         union {
705                                 struct {
706                                         __be16 mstr_sm_lid;
707                                         __be16 port_lid;
708                                         __be32 changed_attr;
709                                         u8 reserved[3];
710                                         u8 mstr_sm_sl;
711                                         __be64 gid_prefix;
712                                 } __packed port_info;
713                                 struct {
714                                         __be32 block_ptr;
715                                         __be32 tbl_entries_mask;
716                                 } __packed tbl_change_info;
717                         } params;
718                 } __packed port_mgmt_change;
719         }                       event;
720         u8                      slave_id;
721         u8                      reserved3[2];
722         u8                      owner;
723 } __packed;
724
725 struct mlx4_init_port_param {
726         int                     set_guid0;
727         int                     set_node_guid;
728         int                     set_si_guid;
729         u16                     mtu;
730         int                     port_width_cap;
731         u16                     vl_cap;
732         u16                     max_gid;
733         u16                     max_pkey;
734         u64                     guid0;
735         u64                     node_guid;
736         u64                     si_guid;
737 };
738
739 #define mlx4_foreach_port(port, dev, type)                              \
740         for ((port) = 1; (port) <= (dev)->caps.num_ports; (port)++)     \
741                 if ((type) == (dev)->caps.port_mask[(port)])
742
743 #define mlx4_foreach_non_ib_transport_port(port, dev)                     \
744         for ((port) = 1; (port) <= (dev)->caps.num_ports; (port)++)       \
745                 if (((dev)->caps.port_mask[port] != MLX4_PORT_TYPE_IB))
746
747 #define mlx4_foreach_ib_transport_port(port, dev)                         \
748         for ((port) = 1; (port) <= (dev)->caps.num_ports; (port)++)       \
749                 if (((dev)->caps.port_mask[port] == MLX4_PORT_TYPE_IB) || \
750                         ((dev)->caps.flags & MLX4_DEV_CAP_FLAG_IBOE))
751
752 #define MLX4_INVALID_SLAVE_ID   0xFF
753
754 void handle_port_mgmt_change_event(struct work_struct *work);
755
756 static inline int mlx4_master_func_num(struct mlx4_dev *dev)
757 {
758         return dev->caps.function;
759 }
760
761 static inline int mlx4_is_master(struct mlx4_dev *dev)
762 {
763         return dev->flags & MLX4_FLAG_MASTER;
764 }
765
766 static inline int mlx4_is_qp_reserved(struct mlx4_dev *dev, u32 qpn)
767 {
768         return (qpn < dev->phys_caps.base_sqpn + 8 +
769                 16 * MLX4_MFUNC_MAX * !!mlx4_is_master(dev));
770 }
771
772 static inline int mlx4_is_guest_proxy(struct mlx4_dev *dev, int slave, u32 qpn)
773 {
774         int guest_proxy_base = dev->phys_caps.base_proxy_sqpn + slave * 8;
775
776         if (qpn >= guest_proxy_base && qpn < guest_proxy_base + 8)
777                 return 1;
778
779         return 0;
780 }
781
782 static inline int mlx4_is_mfunc(struct mlx4_dev *dev)
783 {
784         return dev->flags & (MLX4_FLAG_SLAVE | MLX4_FLAG_MASTER);
785 }
786
787 static inline int mlx4_is_slave(struct mlx4_dev *dev)
788 {
789         return dev->flags & MLX4_FLAG_SLAVE;
790 }
791
792 int mlx4_buf_alloc(struct mlx4_dev *dev, int size, int max_direct,
793                    struct mlx4_buf *buf);
794 void mlx4_buf_free(struct mlx4_dev *dev, int size, struct mlx4_buf *buf);
795 static inline void *mlx4_buf_offset(struct mlx4_buf *buf, int offset)
796 {
797         if (BITS_PER_LONG == 64 || buf->nbufs == 1)
798                 return buf->direct.buf + offset;
799         else
800                 return buf->page_list[offset >> PAGE_SHIFT].buf +
801                         (offset & (PAGE_SIZE - 1));
802 }
803
804 int mlx4_pd_alloc(struct mlx4_dev *dev, u32 *pdn);
805 void mlx4_pd_free(struct mlx4_dev *dev, u32 pdn);
806 int mlx4_xrcd_alloc(struct mlx4_dev *dev, u32 *xrcdn);
807 void mlx4_xrcd_free(struct mlx4_dev *dev, u32 xrcdn);
808
809 int mlx4_uar_alloc(struct mlx4_dev *dev, struct mlx4_uar *uar);
810 void mlx4_uar_free(struct mlx4_dev *dev, struct mlx4_uar *uar);
811 int mlx4_bf_alloc(struct mlx4_dev *dev, struct mlx4_bf *bf);
812 void mlx4_bf_free(struct mlx4_dev *dev, struct mlx4_bf *bf);
813
814 int mlx4_mtt_init(struct mlx4_dev *dev, int npages, int page_shift,
815                   struct mlx4_mtt *mtt);
816 void mlx4_mtt_cleanup(struct mlx4_dev *dev, struct mlx4_mtt *mtt);
817 u64 mlx4_mtt_addr(struct mlx4_dev *dev, struct mlx4_mtt *mtt);
818
819 int mlx4_mr_alloc(struct mlx4_dev *dev, u32 pd, u64 iova, u64 size, u32 access,
820                   int npages, int page_shift, struct mlx4_mr *mr);
821 int mlx4_mr_free(struct mlx4_dev *dev, struct mlx4_mr *mr);
822 int mlx4_mr_enable(struct mlx4_dev *dev, struct mlx4_mr *mr);
823 int mlx4_mw_alloc(struct mlx4_dev *dev, u32 pd, enum mlx4_mw_type type,
824                   struct mlx4_mw *mw);
825 void mlx4_mw_free(struct mlx4_dev *dev, struct mlx4_mw *mw);
826 int mlx4_mw_enable(struct mlx4_dev *dev, struct mlx4_mw *mw);
827 int mlx4_write_mtt(struct mlx4_dev *dev, struct mlx4_mtt *mtt,
828                    int start_index, int npages, u64 *page_list);
829 int mlx4_buf_write_mtt(struct mlx4_dev *dev, struct mlx4_mtt *mtt,
830                        struct mlx4_buf *buf);
831
832 int mlx4_db_alloc(struct mlx4_dev *dev, struct mlx4_db *db, int order);
833 void mlx4_db_free(struct mlx4_dev *dev, struct mlx4_db *db);
834
835 int mlx4_alloc_hwq_res(struct mlx4_dev *dev, struct mlx4_hwq_resources *wqres,
836                        int size, int max_direct);
837 void mlx4_free_hwq_res(struct mlx4_dev *mdev, struct mlx4_hwq_resources *wqres,
838                        int size);
839
840 int mlx4_cq_alloc(struct mlx4_dev *dev, int nent, struct mlx4_mtt *mtt,
841                   struct mlx4_uar *uar, u64 db_rec, struct mlx4_cq *cq,
842                   unsigned vector, int collapsed);
843 void mlx4_cq_free(struct mlx4_dev *dev, struct mlx4_cq *cq);
844
845 int mlx4_qp_reserve_range(struct mlx4_dev *dev, int cnt, int align, int *base);
846 void mlx4_qp_release_range(struct mlx4_dev *dev, int base_qpn, int cnt);
847
848 int mlx4_qp_alloc(struct mlx4_dev *dev, int qpn, struct mlx4_qp *qp);
849 void mlx4_qp_free(struct mlx4_dev *dev, struct mlx4_qp *qp);
850
851 int mlx4_srq_alloc(struct mlx4_dev *dev, u32 pdn, u32 cqn, u16 xrcdn,
852                    struct mlx4_mtt *mtt, u64 db_rec, struct mlx4_srq *srq);
853 void mlx4_srq_free(struct mlx4_dev *dev, struct mlx4_srq *srq);
854 int mlx4_srq_arm(struct mlx4_dev *dev, struct mlx4_srq *srq, int limit_watermark);
855 int mlx4_srq_query(struct mlx4_dev *dev, struct mlx4_srq *srq, int *limit_watermark);
856
857 int mlx4_INIT_PORT(struct mlx4_dev *dev, int port);
858 int mlx4_CLOSE_PORT(struct mlx4_dev *dev, int port);
859
860 int mlx4_unicast_attach(struct mlx4_dev *dev, struct mlx4_qp *qp, u8 gid[16],
861                         int block_mcast_loopback, enum mlx4_protocol prot);
862 int mlx4_unicast_detach(struct mlx4_dev *dev, struct mlx4_qp *qp, u8 gid[16],
863                         enum mlx4_protocol prot);
864 int mlx4_multicast_attach(struct mlx4_dev *dev, struct mlx4_qp *qp, u8 gid[16],
865                           u8 port, int block_mcast_loopback,
866                           enum mlx4_protocol protocol, u64 *reg_id);
867 int mlx4_multicast_detach(struct mlx4_dev *dev, struct mlx4_qp *qp, u8 gid[16],
868                           enum mlx4_protocol protocol, u64 reg_id);
869
870 enum {
871         MLX4_DOMAIN_UVERBS      = 0x1000,
872         MLX4_DOMAIN_ETHTOOL     = 0x2000,
873         MLX4_DOMAIN_RFS         = 0x3000,
874         MLX4_DOMAIN_NIC    = 0x5000,
875 };
876
877 enum mlx4_net_trans_rule_id {
878         MLX4_NET_TRANS_RULE_ID_ETH = 0,
879         MLX4_NET_TRANS_RULE_ID_IB,
880         MLX4_NET_TRANS_RULE_ID_IPV6,
881         MLX4_NET_TRANS_RULE_ID_IPV4,
882         MLX4_NET_TRANS_RULE_ID_TCP,
883         MLX4_NET_TRANS_RULE_ID_UDP,
884         MLX4_NET_TRANS_RULE_NUM, /* should be last */
885 };
886
887 extern const u16 __sw_id_hw[];
888
889 static inline int map_hw_to_sw_id(u16 header_id)
890 {
891
892         int i;
893         for (i = 0; i < MLX4_NET_TRANS_RULE_NUM; i++) {
894                 if (header_id == __sw_id_hw[i])
895                         return i;
896         }
897         return -EINVAL;
898 }
899
900 enum mlx4_net_trans_promisc_mode {
901         MLX4_FS_PROMISC_NONE = 0,
902         MLX4_FS_PROMISC_UPLINK,
903         /* For future use. Not implemented yet */
904         MLX4_FS_PROMISC_FUNCTION_PORT,
905         MLX4_FS_PROMISC_ALL_MULTI,
906 };
907
908 struct mlx4_spec_eth {
909         u8      dst_mac[6];
910         u8      dst_mac_msk[6];
911         u8      src_mac[6];
912         u8      src_mac_msk[6];
913         u8      ether_type_enable;
914         __be16  ether_type;
915         __be16  vlan_id_msk;
916         __be16  vlan_id;
917 };
918
919 struct mlx4_spec_tcp_udp {
920         __be16 dst_port;
921         __be16 dst_port_msk;
922         __be16 src_port;
923         __be16 src_port_msk;
924 };
925
926 struct mlx4_spec_ipv4 {
927         __be32 dst_ip;
928         __be32 dst_ip_msk;
929         __be32 src_ip;
930         __be32 src_ip_msk;
931 };
932
933 struct mlx4_spec_ib {
934         __be32  r_qpn;
935         __be32  qpn_msk;
936         u8      dst_gid[16];
937         u8      dst_gid_msk[16];
938 };
939
940 struct mlx4_spec_list {
941         struct  list_head list;
942         enum    mlx4_net_trans_rule_id id;
943         union {
944                 struct mlx4_spec_eth eth;
945                 struct mlx4_spec_ib ib;
946                 struct mlx4_spec_ipv4 ipv4;
947                 struct mlx4_spec_tcp_udp tcp_udp;
948         };
949 };
950
951 enum mlx4_net_trans_hw_rule_queue {
952         MLX4_NET_TRANS_Q_FIFO,
953         MLX4_NET_TRANS_Q_LIFO,
954 };
955
956 struct mlx4_net_trans_rule {
957         struct  list_head list;
958         enum    mlx4_net_trans_hw_rule_queue queue_mode;
959         bool    exclusive;
960         bool    allow_loopback;
961         enum    mlx4_net_trans_promisc_mode promisc_mode;
962         u8      port;
963         u16     priority;
964         u32     qpn;
965 };
966
967 int mlx4_flow_steer_promisc_add(struct mlx4_dev *dev, u8 port, u32 qpn,
968                                 enum mlx4_net_trans_promisc_mode mode);
969 int mlx4_flow_steer_promisc_remove(struct mlx4_dev *dev, u8 port,
970                                    enum mlx4_net_trans_promisc_mode mode);
971 int mlx4_multicast_promisc_add(struct mlx4_dev *dev, u32 qpn, u8 port);
972 int mlx4_multicast_promisc_remove(struct mlx4_dev *dev, u32 qpn, u8 port);
973 int mlx4_unicast_promisc_add(struct mlx4_dev *dev, u32 qpn, u8 port);
974 int mlx4_unicast_promisc_remove(struct mlx4_dev *dev, u32 qpn, u8 port);
975 int mlx4_SET_MCAST_FLTR(struct mlx4_dev *dev, u8 port, u64 mac, u64 clear, u8 mode);
976
977 int mlx4_register_mac(struct mlx4_dev *dev, u8 port, u64 mac);
978 void mlx4_unregister_mac(struct mlx4_dev *dev, u8 port, u64 mac);
979 int mlx4_get_base_qpn(struct mlx4_dev *dev, u8 port);
980 int __mlx4_replace_mac(struct mlx4_dev *dev, u8 port, int qpn, u64 new_mac);
981 void mlx4_set_stats_bitmap(struct mlx4_dev *dev, u64 *stats_bitmap);
982 int mlx4_SET_PORT_general(struct mlx4_dev *dev, u8 port, int mtu,
983                           u8 pptx, u8 pfctx, u8 pprx, u8 pfcrx);
984 int mlx4_SET_PORT_qpn_calc(struct mlx4_dev *dev, u8 port, u32 base_qpn,
985                            u8 promisc);
986 int mlx4_SET_PORT_PRIO2TC(struct mlx4_dev *dev, u8 port, u8 *prio2tc);
987 int mlx4_SET_PORT_SCHEDULER(struct mlx4_dev *dev, u8 port, u8 *tc_tx_bw,
988                 u8 *pg, u16 *ratelimit);
989 int mlx4_find_cached_vlan(struct mlx4_dev *dev, u8 port, u16 vid, int *idx);
990 int mlx4_register_vlan(struct mlx4_dev *dev, u8 port, u16 vlan, int *index);
991 void mlx4_unregister_vlan(struct mlx4_dev *dev, u8 port, int index);
992
993 int mlx4_map_phys_fmr(struct mlx4_dev *dev, struct mlx4_fmr *fmr, u64 *page_list,
994                       int npages, u64 iova, u32 *lkey, u32 *rkey);
995 int mlx4_fmr_alloc(struct mlx4_dev *dev, u32 pd, u32 access, int max_pages,
996                    int max_maps, u8 page_shift, struct mlx4_fmr *fmr);
997 int mlx4_fmr_enable(struct mlx4_dev *dev, struct mlx4_fmr *fmr);
998 void mlx4_fmr_unmap(struct mlx4_dev *dev, struct mlx4_fmr *fmr,
999                     u32 *lkey, u32 *rkey);
1000 int mlx4_fmr_free(struct mlx4_dev *dev, struct mlx4_fmr *fmr);
1001 int mlx4_SYNC_TPT(struct mlx4_dev *dev);
1002 int mlx4_test_interrupts(struct mlx4_dev *dev);
1003 int mlx4_assign_eq(struct mlx4_dev *dev, char *name, struct cpu_rmap *rmap,
1004                    int *vector);
1005 void mlx4_release_eq(struct mlx4_dev *dev, int vec);
1006
1007 int mlx4_wol_read(struct mlx4_dev *dev, u64 *config, int port);
1008 int mlx4_wol_write(struct mlx4_dev *dev, u64 config, int port);
1009
1010 int mlx4_counter_alloc(struct mlx4_dev *dev, u32 *idx);
1011 void mlx4_counter_free(struct mlx4_dev *dev, u32 idx);
1012
1013 int mlx4_flow_attach(struct mlx4_dev *dev,
1014                      struct mlx4_net_trans_rule *rule, u64 *reg_id);
1015 int mlx4_flow_detach(struct mlx4_dev *dev, u64 reg_id);
1016
1017 void mlx4_sync_pkey_table(struct mlx4_dev *dev, int slave, int port,
1018                           int i, int val);
1019
1020 int mlx4_get_parav_qkey(struct mlx4_dev *dev, u32 qpn, u32 *qkey);
1021
1022 int mlx4_is_slave_active(struct mlx4_dev *dev, int slave);
1023 int mlx4_gen_pkey_eqe(struct mlx4_dev *dev, int slave, u8 port);
1024 int mlx4_gen_guid_change_eqe(struct mlx4_dev *dev, int slave, u8 port);
1025 int mlx4_gen_slaves_port_mgt_ev(struct mlx4_dev *dev, u8 port, int attr);
1026 int mlx4_gen_port_state_change_eqe(struct mlx4_dev *dev, int slave, u8 port, u8 port_subtype_change);
1027 enum slave_port_state mlx4_get_slave_port_state(struct mlx4_dev *dev, int slave, u8 port);
1028 int set_and_calc_slave_port_state(struct mlx4_dev *dev, int slave, u8 port, int event, enum slave_port_gen_event *gen_event);
1029
1030 void mlx4_put_slave_node_guid(struct mlx4_dev *dev, int slave, __be64 guid);
1031 __be64 mlx4_get_slave_node_guid(struct mlx4_dev *dev, int slave);
1032
1033 #endif /* MLX4_DEVICE_H */