ntb_hw.h revision 291280
1231990Smp/*-
283098Smp * Copyright (C) 2013 Intel Corporation
383098Smp * Copyright (C) 2015 EMC Corporation
483098Smp * All rights reserved.
583098Smp *
683098Smp * Redistribution and use in source and binary forms, with or without
783098Smp * modification, are permitted provided that the following conditions
883098Smp * are met:
983098Smp * 1. Redistributions of source code must retain the above copyright
1083098Smp *    notice, this list of conditions and the following disclaimer.
1183098Smp * 2. Redistributions in binary form must reproduce the above copyright
1283098Smp *    notice, this list of conditions and the following disclaimer in the
13231990Smp *    documentation and/or other materials provided with the distribution.
14231990Smp *
1583098Smp * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16231990Smp * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17231990Smp * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18231990Smp * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19231990Smp * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2083098Smp * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21231990Smp * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2283098Smp * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23231990Smp * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2483098Smp * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2583098Smp * SUCH DAMAGE.
26231990Smp *
2783098Smp * $FreeBSD: head/sys/dev/ntb/ntb_hw/ntb_hw.h 291280 2015-11-25 01:59:08Z cem $
2883098Smp */
2983098Smp
3083098Smp#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);
89int ntb_spad_write(struct ntb_softc *ntb, unsigned int idx, uint32_t val);
90int ntb_spad_read(struct ntb_softc *ntb, unsigned int idx, uint32_t *val);
91int ntb_peer_spad_write(struct ntb_softc *ntb, unsigned int idx,
92    uint32_t val);
93int ntb_peer_spad_read(struct ntb_softc *ntb, unsigned int idx,
94    uint32_t *val);
95
96uint64_t ntb_db_valid_mask(struct ntb_softc *);
97uint64_t ntb_db_vector_mask(struct ntb_softc *, uint32_t vector);
98bus_addr_t ntb_get_peer_db_addr(struct ntb_softc *, vm_size_t *sz_out);
99
100void ntb_db_clear(struct ntb_softc *, uint64_t bits);
101void ntb_db_clear_mask(struct ntb_softc *, uint64_t bits);
102uint64_t ntb_db_read(struct ntb_softc *);
103void ntb_db_set_mask(struct ntb_softc *, uint64_t bits);
104void ntb_peer_db_set(struct ntb_softc *, uint64_t bits);
105
106#define XEON_SPAD_COUNT		16
107#define ATOM_SPAD_COUNT		16
108
109/* Hardware owns the low 16 bits of features. */
110#define NTB_BAR_SIZE_4K		(1 << 0)
111#define NTB_SDOORBELL_LOCKUP	(1 << 1)
112#define NTB_SB01BASE_LOCKUP	(1 << 2)
113#define NTB_B2BDOORBELL_BIT14	(1 << 3)
114/* Software/configuration owns the top 16 bits. */
115#define NTB_SPLIT_BAR		(1ull << 16)
116
117#define NTB_FEATURES_STR \
118    "\20\21SPLIT_BAR4\04B2B_DOORBELL_BIT14\03SB01BASE_LOCKUP" \
119    "\02SDOORBELL_LOCKUP\01BAR_SIZE_4K"
120
121bool ntb_has_feature(struct ntb_softc *, uint32_t);
122
123#endif /* _NTB_HW_H_ */
124