]> CyberLeo.Net >> Repos - FreeBSD/stable/10.git/blob - sys/dev/ntb/ntb_hw/ntb_hw.h
MFC r295618,r300100,r300531:
[FreeBSD/stable/10.git] / sys / dev / ntb / ntb_hw / ntb_hw.h
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$
28  */
29
30 #ifndef _NTB_HW_H_
31 #define _NTB_HW_H_
32
33 struct ntb_softc;
34
35 #define NTB_MAX_NUM_MW  3
36
37 enum 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
45 enum 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
57 SYSCTL_DECL(_hw_ntb);
58
59 typedef void (*ntb_db_callback)(void *data, uint32_t vector);
60 typedef void (*ntb_event_callback)(void *data);
61
62 struct ntb_ctx_ops {
63         ntb_event_callback      link_event;
64         ntb_db_callback         db_event;
65 };
66
67 device_t ntb_get_device(struct ntb_softc *);
68
69 bool ntb_link_is_up(struct ntb_softc *, enum ntb_speed *, enum ntb_width *);
70 void ntb_link_event(struct ntb_softc *);
71 int ntb_link_enable(struct ntb_softc *, enum ntb_speed, enum ntb_width);
72 int ntb_link_disable(struct ntb_softc *);
73 bool ntb_link_enabled(struct ntb_softc *);
74
75 int ntb_set_ctx(struct ntb_softc *, void *, const struct ntb_ctx_ops *);
76 void *ntb_get_ctx(struct ntb_softc *, const struct ntb_ctx_ops **);
77 void ntb_clear_ctx(struct ntb_softc *);
78
79 uint8_t ntb_mw_count(struct ntb_softc *);
80 int ntb_mw_get_range(struct ntb_softc *, unsigned mw_idx, vm_paddr_t *base,
81     caddr_t *vbase, size_t *size, size_t *align, size_t *align_size,
82     bus_addr_t *plimit);
83 int ntb_mw_set_trans(struct ntb_softc *, unsigned mw_idx, bus_addr_t, size_t);
84 int ntb_mw_clear_trans(struct ntb_softc *, unsigned mw_idx);
85
86 int ntb_mw_get_wc(struct ntb_softc *, unsigned mw_idx, vm_memattr_t *mode);
87 int ntb_mw_set_wc(struct ntb_softc *, unsigned mw_idx, vm_memattr_t mode);
88
89 uint8_t ntb_get_max_spads(struct ntb_softc *ntb);
90 void ntb_spad_clear(struct ntb_softc *ntb);
91 int ntb_spad_write(struct ntb_softc *ntb, unsigned int idx, uint32_t val);
92 int ntb_spad_read(struct ntb_softc *ntb, unsigned int idx, uint32_t *val);
93 int ntb_peer_spad_write(struct ntb_softc *ntb, unsigned int idx,
94     uint32_t val);
95 int ntb_peer_spad_read(struct ntb_softc *ntb, unsigned int idx,
96     uint32_t *val);
97
98 uint64_t ntb_db_valid_mask(struct ntb_softc *);
99 uint64_t ntb_db_vector_mask(struct ntb_softc *, uint32_t vector);
100 bus_addr_t ntb_get_peer_db_addr(struct ntb_softc *, vm_size_t *sz_out);
101
102 void ntb_db_clear(struct ntb_softc *, uint64_t bits);
103 void ntb_db_clear_mask(struct ntb_softc *, uint64_t bits);
104 uint64_t ntb_db_read(struct ntb_softc *);
105 void ntb_db_set_mask(struct ntb_softc *, uint64_t bits);
106 void ntb_peer_db_set(struct ntb_softc *, uint64_t bits);
107
108 #define XEON_SPAD_COUNT         16
109 #define ATOM_SPAD_COUNT         16
110
111 /* Hardware owns the low 16 bits of features. */
112 #define NTB_BAR_SIZE_4K         (1 << 0)
113 #define NTB_SDOORBELL_LOCKUP    (1 << 1)
114 #define NTB_SB01BASE_LOCKUP     (1 << 2)
115 #define NTB_B2BDOORBELL_BIT14   (1 << 3)
116 /* Software/configuration owns the top 16 bits. */
117 #define NTB_SPLIT_BAR           (1ull << 16)
118
119 #define NTB_FEATURES_STR \
120     "\20\21SPLIT_BAR4\04B2B_DOORBELL_BIT14\03SB01BASE_LOCKUP" \
121     "\02SDOORBELL_LOCKUP\01BAR_SIZE_4K"
122
123 bool ntb_has_feature(struct ntb_softc *, uint32_t);
124
125 #endif /* _NTB_HW_H_ */