ntb_hw.h revision 295618
1/*-
2 * Copyright (C) 2013 Intel Corporation
3 * Copyright (C) 2015 EMC Corporation
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 *    notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 *    notice, this list of conditions and the following disclaimer in the
13 *    documentation and/or other materials provided with the distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25 * SUCH DAMAGE.
26 *
27 * $FreeBSD: head/sys/dev/ntb/ntb_hw/ntb_hw.h 295618 2016-02-14 22:37:28Z cem $
28 */
29
30#ifndef _NTB_HW_H_
31#define _NTB_HW_H_
32
33struct ntb_softc;
34
35#define NTB_MAX_NUM_MW	3
36
37enum ntb_speed {
38	NTB_SPEED_AUTO = -1,
39	NTB_SPEED_NONE = 0,
40	NTB_SPEED_GEN1 = 1,
41	NTB_SPEED_GEN2 = 2,
42	NTB_SPEED_GEN3 = 3,
43};
44
45enum ntb_width {
46	NTB_WIDTH_AUTO = -1,
47	NTB_WIDTH_NONE = 0,
48	NTB_WIDTH_1 = 1,
49	NTB_WIDTH_2 = 2,
50	NTB_WIDTH_4 = 4,
51	NTB_WIDTH_8 = 8,
52	NTB_WIDTH_12 = 12,
53	NTB_WIDTH_16 = 16,
54	NTB_WIDTH_32 = 32,
55};
56
57SYSCTL_DECL(_hw_ntb);
58
59typedef void (*ntb_db_callback)(void *data, uint32_t vector);
60typedef void (*ntb_event_callback)(void *data);
61
62struct ntb_ctx_ops {
63	ntb_event_callback	link_event;
64	ntb_db_callback		db_event;
65};
66
67device_t ntb_get_device(struct ntb_softc *);
68
69bool ntb_link_is_up(struct ntb_softc *, enum ntb_speed *, enum ntb_width *);
70void ntb_link_event(struct ntb_softc *);
71int ntb_link_enable(struct ntb_softc *, enum ntb_speed, enum ntb_width);
72int ntb_link_disable(struct ntb_softc *);
73
74int ntb_set_ctx(struct ntb_softc *, void *, const struct ntb_ctx_ops *);
75void *ntb_get_ctx(struct ntb_softc *, const struct ntb_ctx_ops **);
76void ntb_clear_ctx(struct ntb_softc *);
77
78uint8_t ntb_mw_count(struct ntb_softc *);
79int ntb_mw_get_range(struct ntb_softc *, unsigned mw_idx, vm_paddr_t *base,
80    caddr_t *vbase, size_t *size, size_t *align, size_t *align_size,
81    bus_addr_t *plimit);
82int ntb_mw_set_trans(struct ntb_softc *, unsigned mw_idx, bus_addr_t, size_t);
83int ntb_mw_clear_trans(struct ntb_softc *, unsigned mw_idx);
84
85int ntb_mw_get_wc(struct ntb_softc *, unsigned mw_idx, vm_memattr_t *mode);
86int ntb_mw_set_wc(struct ntb_softc *, unsigned mw_idx, vm_memattr_t mode);
87
88uint8_t ntb_get_max_spads(struct ntb_softc *ntb);
89void ntb_spad_clear(struct ntb_softc *ntb);
90int ntb_spad_write(struct ntb_softc *ntb, unsigned int idx, uint32_t val);
91int ntb_spad_read(struct ntb_softc *ntb, unsigned int idx, uint32_t *val);
92int ntb_peer_spad_write(struct ntb_softc *ntb, unsigned int idx,
93    uint32_t val);
94int ntb_peer_spad_read(struct ntb_softc *ntb, unsigned int idx,
95    uint32_t *val);
96
97uint64_t ntb_db_valid_mask(struct ntb_softc *);
98uint64_t ntb_db_vector_mask(struct ntb_softc *, uint32_t vector);
99bus_addr_t ntb_get_peer_db_addr(struct ntb_softc *, vm_size_t *sz_out);
100
101void ntb_db_clear(struct ntb_softc *, uint64_t bits);
102void ntb_db_clear_mask(struct ntb_softc *, uint64_t bits);
103uint64_t ntb_db_read(struct ntb_softc *);
104void ntb_db_set_mask(struct ntb_softc *, uint64_t bits);
105void ntb_peer_db_set(struct ntb_softc *, uint64_t bits);
106
107#define XEON_SPAD_COUNT		16
108#define ATOM_SPAD_COUNT		16
109
110/* Hardware owns the low 16 bits of features. */
111#define NTB_BAR_SIZE_4K		(1 << 0)
112#define NTB_SDOORBELL_LOCKUP	(1 << 1)
113#define NTB_SB01BASE_LOCKUP	(1 << 2)
114#define NTB_B2BDOORBELL_BIT14	(1 << 3)
115/* Software/configuration owns the top 16 bits. */
116#define NTB_SPLIT_BAR		(1ull << 16)
117
118#define NTB_FEATURES_STR \
119    "\20\21SPLIT_BAR4\04B2B_DOORBELL_BIT14\03SB01BASE_LOCKUP" \
120    "\02SDOORBELL_LOCKUP\01BAR_SIZE_4K"
121
122bool ntb_has_feature(struct ntb_softc *, uint32_t);
123
124#endif /* _NTB_HW_H_ */
125