xref: /freebsd/sys/dev/ntb/ntb_if.m (revision 031beb4e239bfce798af17f5fe8dba8bcaf13d99)
19a5325c2SAlexander Motin#-
29a5325c2SAlexander Motin# Copyright (c) 2016 Alexander Motin <mav@FreeBSD.org>
39a5325c2SAlexander Motin# All rights reserved.
49a5325c2SAlexander Motin#
59a5325c2SAlexander Motin# Redistribution and use in source and binary forms, with or without
69a5325c2SAlexander Motin# modification, are permitted provided that the following conditions
79a5325c2SAlexander Motin# are met:
89a5325c2SAlexander Motin# 1. Redistributions of source code must retain the above copyright
99a5325c2SAlexander Motin#    notice, this list of conditions and the following disclaimer.
109a5325c2SAlexander Motin# 2. Redistributions in binary form must reproduce the above copyright
119a5325c2SAlexander Motin#    notice, this list of conditions and the following disclaimer in the
129a5325c2SAlexander Motin#    documentation and/or other materials provided with the distribution.
139a5325c2SAlexander Motin#
149a5325c2SAlexander Motin# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
159a5325c2SAlexander Motin# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
169a5325c2SAlexander Motin# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
179a5325c2SAlexander Motin# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
189a5325c2SAlexander Motin# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
199a5325c2SAlexander Motin# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
209a5325c2SAlexander Motin# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
219a5325c2SAlexander Motin# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
229a5325c2SAlexander Motin# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
239a5325c2SAlexander Motin# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
249a5325c2SAlexander Motin# SUCH DAMAGE.
259a5325c2SAlexander Motin#
269a5325c2SAlexander Motin#
279a5325c2SAlexander Motin
289a5325c2SAlexander Motin#include <sys/bus.h>
299a5325c2SAlexander Motin#include <machine/bus.h>
309a5325c2SAlexander Motin
319a5325c2SAlexander MotinINTERFACE ntb;
329a5325c2SAlexander Motin
339a5325c2SAlexander MotinHEADER {
349a5325c2SAlexander Motin	enum ntb_speed {
359a5325c2SAlexander Motin		NTB_SPEED_AUTO = -1,
369a5325c2SAlexander Motin		NTB_SPEED_NONE = 0,
379a5325c2SAlexander Motin		NTB_SPEED_GEN1 = 1,
389a5325c2SAlexander Motin		NTB_SPEED_GEN2 = 2,
399a5325c2SAlexander Motin		NTB_SPEED_GEN3 = 3,
4048c47677SAlexander Motin		NTB_SPEED_GEN4 = 4,
419a5325c2SAlexander Motin	};
429a5325c2SAlexander Motin
439a5325c2SAlexander Motin	enum ntb_width {
449a5325c2SAlexander Motin		NTB_WIDTH_AUTO = -1,
459a5325c2SAlexander Motin		NTB_WIDTH_NONE = 0,
469a5325c2SAlexander Motin		NTB_WIDTH_1 = 1,
479a5325c2SAlexander Motin		NTB_WIDTH_2 = 2,
489a5325c2SAlexander Motin		NTB_WIDTH_4 = 4,
499a5325c2SAlexander Motin		NTB_WIDTH_8 = 8,
509a5325c2SAlexander Motin		NTB_WIDTH_12 = 12,
519a5325c2SAlexander Motin		NTB_WIDTH_16 = 16,
529a5325c2SAlexander Motin		NTB_WIDTH_32 = 32,
539a5325c2SAlexander Motin	};
549a5325c2SAlexander Motin
559a5325c2SAlexander Motin	typedef void (*ntb_db_callback)(void *data, uint32_t vector);
569a5325c2SAlexander Motin	typedef void (*ntb_event_callback)(void *data);
579a5325c2SAlexander Motin	struct ntb_ctx_ops {
589a5325c2SAlexander Motin		ntb_event_callback	link_event;
599a5325c2SAlexander Motin		ntb_db_callback		db_event;
609a5325c2SAlexander Motin	};
619a5325c2SAlexander Motin};
629a5325c2SAlexander Motin
63*6683132dSAlexander MotinMETHOD int port_number {
64*6683132dSAlexander Motin	device_t	ntb;
65*6683132dSAlexander Motin};
66*6683132dSAlexander Motin
67*6683132dSAlexander MotinMETHOD int peer_port_count {
68*6683132dSAlexander Motin	device_t	ntb;
69*6683132dSAlexander Motin};
70*6683132dSAlexander Motin
71*6683132dSAlexander MotinMETHOD int peer_port_number {
72*6683132dSAlexander Motin	device_t	ntb;
73*6683132dSAlexander Motin	int		pidx;
74*6683132dSAlexander Motin};
75*6683132dSAlexander Motin
76*6683132dSAlexander MotinMETHOD int peer_port_idx {
77*6683132dSAlexander Motin	device_t	ntb;
78*6683132dSAlexander Motin	int		port;
79*6683132dSAlexander Motin};
80*6683132dSAlexander Motin
819a5325c2SAlexander MotinMETHOD bool link_is_up {
829a5325c2SAlexander Motin	device_t	 ntb;
839a5325c2SAlexander Motin	enum ntb_speed	*speed;
849a5325c2SAlexander Motin	enum ntb_width	*width;
859a5325c2SAlexander Motin};
869a5325c2SAlexander Motin
879a5325c2SAlexander MotinMETHOD int link_enable {
889a5325c2SAlexander Motin	device_t	 ntb;
899a5325c2SAlexander Motin	enum ntb_speed	 speed;
909a5325c2SAlexander Motin	enum ntb_width	 width;
919a5325c2SAlexander Motin};
929a5325c2SAlexander Motin
939a5325c2SAlexander MotinMETHOD int link_disable {
949a5325c2SAlexander Motin	device_t	 ntb;
959a5325c2SAlexander Motin};
969a5325c2SAlexander Motin
979a5325c2SAlexander MotinMETHOD bool link_enabled {
989a5325c2SAlexander Motin	device_t	 ntb;
999a5325c2SAlexander Motin};
1009a5325c2SAlexander Motin
1019a5325c2SAlexander MotinMETHOD int set_ctx {
1029a5325c2SAlexander Motin	device_t	 ntb;
1039a5325c2SAlexander Motin	void		*ctx;
1049a5325c2SAlexander Motin	const struct ntb_ctx_ops *ctx_ops;
1059a5325c2SAlexander Motin};
1069a5325c2SAlexander Motin
1079a5325c2SAlexander MotinMETHOD void * get_ctx {
1089a5325c2SAlexander Motin	device_t	 ntb;
1099a5325c2SAlexander Motin	const struct ntb_ctx_ops **ctx_ops;
1109a5325c2SAlexander Motin};
1119a5325c2SAlexander Motin
1129a5325c2SAlexander MotinMETHOD void clear_ctx {
1139a5325c2SAlexander Motin	device_t	 ntb;
1149a5325c2SAlexander Motin};
1159a5325c2SAlexander Motin
1169a5325c2SAlexander MotinMETHOD uint8_t mw_count {
1179a5325c2SAlexander Motin	device_t	 ntb;
1189a5325c2SAlexander Motin};
1199a5325c2SAlexander Motin
1209a5325c2SAlexander MotinMETHOD int mw_get_range {
1219a5325c2SAlexander Motin	device_t	 ntb;
1229a5325c2SAlexander Motin	unsigned	 mw_idx;
1239a5325c2SAlexander Motin	vm_paddr_t	*base;
1249a5325c2SAlexander Motin	caddr_t		*vbase;
1259a5325c2SAlexander Motin	size_t		*size;
1269a5325c2SAlexander Motin	size_t		*align;
1279a5325c2SAlexander Motin	size_t		*align_size;
1289a5325c2SAlexander Motin	bus_addr_t	*plimit;
1299a5325c2SAlexander Motin};
1309a5325c2SAlexander Motin
1319a5325c2SAlexander MotinMETHOD int mw_set_trans {
1329a5325c2SAlexander Motin	device_t	 ntb;
1339a5325c2SAlexander Motin	unsigned	 mw_idx;
1349a5325c2SAlexander Motin	bus_addr_t	 addr;
1359a5325c2SAlexander Motin	size_t		 size;
1369a5325c2SAlexander Motin};
1379a5325c2SAlexander Motin
1389a5325c2SAlexander MotinMETHOD int mw_clear_trans {
1399a5325c2SAlexander Motin	device_t	 ntb;
1409a5325c2SAlexander Motin	unsigned	 mw_idx;
1419a5325c2SAlexander Motin};
1429a5325c2SAlexander Motin
1439a5325c2SAlexander MotinMETHOD int mw_get_wc {
1449a5325c2SAlexander Motin	device_t	 ntb;
1459a5325c2SAlexander Motin	unsigned	 mw_idx;
1469a5325c2SAlexander Motin	vm_memattr_t	*mode;
1479a5325c2SAlexander Motin};
1489a5325c2SAlexander Motin
1499a5325c2SAlexander MotinMETHOD int mw_set_wc {
1509a5325c2SAlexander Motin	device_t	 ntb;
1519a5325c2SAlexander Motin	unsigned	 mw_idx;
1529a5325c2SAlexander Motin	vm_memattr_t	 mode;
1539a5325c2SAlexander Motin};
1549a5325c2SAlexander Motin
1559a5325c2SAlexander MotinMETHOD uint8_t spad_count {
1569a5325c2SAlexander Motin	device_t	 ntb;
1579a5325c2SAlexander Motin};
1589a5325c2SAlexander Motin
1599a5325c2SAlexander MotinMETHOD void spad_clear {
1609a5325c2SAlexander Motin	device_t	 ntb;
1619a5325c2SAlexander Motin};
1629a5325c2SAlexander Motin
1639a5325c2SAlexander MotinMETHOD int spad_write {
1649a5325c2SAlexander Motin	device_t	 ntb;
1659a5325c2SAlexander Motin	unsigned int	 idx;
1669a5325c2SAlexander Motin	uint32_t	 val;
1679a5325c2SAlexander Motin};
1689a5325c2SAlexander Motin
1699a5325c2SAlexander MotinMETHOD int spad_read {
1709a5325c2SAlexander Motin	device_t	 ntb;
1719a5325c2SAlexander Motin	unsigned int	 idx;
1729a5325c2SAlexander Motin	uint32_t	 *val;
1739a5325c2SAlexander Motin};
1749a5325c2SAlexander Motin
1759a5325c2SAlexander MotinMETHOD int peer_spad_write {
1769a5325c2SAlexander Motin	device_t	 ntb;
1779a5325c2SAlexander Motin	unsigned int	 idx;
1789a5325c2SAlexander Motin	uint32_t	 val;
1799a5325c2SAlexander Motin};
1809a5325c2SAlexander Motin
1819a5325c2SAlexander MotinMETHOD int peer_spad_read {
1829a5325c2SAlexander Motin	device_t	 ntb;
1839a5325c2SAlexander Motin	unsigned int	 idx;
1849a5325c2SAlexander Motin	uint32_t	*val;
1859a5325c2SAlexander Motin};
1869a5325c2SAlexander Motin
1879a5325c2SAlexander MotinMETHOD uint64_t db_valid_mask {
1889a5325c2SAlexander Motin	device_t	 ntb;
1899a5325c2SAlexander Motin};
1909a5325c2SAlexander Motin
1919a5325c2SAlexander MotinMETHOD int db_vector_count {
1929a5325c2SAlexander Motin	device_t	 ntb;
1939a5325c2SAlexander Motin};
1949a5325c2SAlexander Motin
1959a5325c2SAlexander MotinMETHOD uint64_t db_vector_mask {
1969a5325c2SAlexander Motin	device_t	 ntb;
1979a5325c2SAlexander Motin	uint32_t	 vector;
1989a5325c2SAlexander Motin};
1999a5325c2SAlexander Motin
2009a5325c2SAlexander MotinMETHOD int peer_db_addr {
2019a5325c2SAlexander Motin	device_t	 ntb;
2029a5325c2SAlexander Motin	bus_addr_t	*db_addr;
2039a5325c2SAlexander Motin	vm_size_t	*db_size;
2049a5325c2SAlexander Motin};
2059a5325c2SAlexander Motin
2069a5325c2SAlexander MotinMETHOD void db_clear {
2079a5325c2SAlexander Motin	device_t	 ntb;
2089a5325c2SAlexander Motin	uint64_t	 bits;
2099a5325c2SAlexander Motin};
2109a5325c2SAlexander Motin
2119a5325c2SAlexander MotinMETHOD void db_clear_mask {
2129a5325c2SAlexander Motin	device_t	 ntb;
2139a5325c2SAlexander Motin	uint64_t	 bits;
2149a5325c2SAlexander Motin};
2159a5325c2SAlexander Motin
2169a5325c2SAlexander MotinMETHOD uint64_t db_read {
2179a5325c2SAlexander Motin	device_t	 ntb;
2189a5325c2SAlexander Motin};
2199a5325c2SAlexander Motin
2209a5325c2SAlexander MotinMETHOD void db_set_mask {
2219a5325c2SAlexander Motin	device_t	 ntb;
2229a5325c2SAlexander Motin	uint64_t	 bits;
2239a5325c2SAlexander Motin};
2249a5325c2SAlexander Motin
2259a5325c2SAlexander MotinMETHOD void peer_db_set {
2269a5325c2SAlexander Motin	device_t	 ntb;
2279a5325c2SAlexander Motin	uint64_t	 bits;
2289a5325c2SAlexander Motin};
229