2 * Copyright (C) 2013 Intel Corporation
3 * Copyright (C) 2015 EMC Corporation
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
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.
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
35 #define NTB_MAX_NUM_MW 3
59 typedef void (*ntb_db_callback)(void *data, uint32_t vector);
60 typedef void (*ntb_event_callback)(void *data);
63 ntb_event_callback link_event;
64 ntb_db_callback db_event;
67 device_t ntb_get_device(struct ntb_softc *);
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 *);
74 int ntb_set_ctx(struct ntb_softc *, void *, const struct ntb_ctx_ops *);
75 void *ntb_get_ctx(struct ntb_softc *, const struct ntb_ctx_ops **);
76 void ntb_clear_ctx(struct ntb_softc *);
78 uint8_t ntb_mw_count(struct ntb_softc *);
79 int 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 int ntb_mw_set_trans(struct ntb_softc *, unsigned mw_idx, bus_addr_t, size_t);
82 int ntb_mw_clear_trans(struct ntb_softc *, unsigned mw_idx);
84 uint8_t ntb_get_max_spads(struct ntb_softc *ntb);
85 int ntb_spad_write(struct ntb_softc *ntb, unsigned int idx, uint32_t val);
86 int ntb_spad_read(struct ntb_softc *ntb, unsigned int idx, uint32_t *val);
87 int ntb_peer_spad_write(struct ntb_softc *ntb, unsigned int idx,
89 int ntb_peer_spad_read(struct ntb_softc *ntb, unsigned int idx,
92 uint64_t ntb_db_valid_mask(struct ntb_softc *);
93 uint64_t ntb_db_vector_mask(struct ntb_softc *, uint32_t vector);
94 bus_addr_t ntb_get_peer_db_addr(struct ntb_softc *, vm_size_t *sz_out);
96 void ntb_db_clear(struct ntb_softc *, uint64_t bits);
97 void ntb_db_clear_mask(struct ntb_softc *, uint64_t bits);
98 uint64_t ntb_db_read(struct ntb_softc *);
99 void ntb_db_set_mask(struct ntb_softc *, uint64_t bits);
100 void ntb_peer_db_set(struct ntb_softc *, uint64_t bits);
102 /* Hardware owns the low 16 bits of features. */
103 #define NTB_BAR_SIZE_4K (1 << 0)
104 #define NTB_SDOORBELL_LOCKUP (1 << 1)
105 #define NTB_SB01BASE_LOCKUP (1 << 2)
106 #define NTB_B2BDOORBELL_BIT14 (1 << 3)
107 /* Software/configuration owns the top 16 bits. */
108 #define NTB_SPLIT_BAR (1ull << 16)
110 #define NTB_FEATURES_STR \
111 "\20\21SPLIT_BAR4\04B2B_DOORBELL_BIT14\03SB01BASE_LOCKUP" \
112 "\02SDOORBELL_LOCKUP\01BAR_SIZE_4K"
114 bool ntb_has_feature(struct ntb_softc *, uint32_t);
116 #endif /* _NTB_HW_H_ */