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# $FreeBSD$ 279a5325c2SAlexander Motin# 289a5325c2SAlexander Motin 299a5325c2SAlexander Motin#include <sys/bus.h> 309a5325c2SAlexander Motin#include <machine/bus.h> 319a5325c2SAlexander Motin 329a5325c2SAlexander MotinINTERFACE ntb; 339a5325c2SAlexander Motin 349a5325c2SAlexander MotinHEADER { 359a5325c2SAlexander Motin enum ntb_speed { 369a5325c2SAlexander Motin NTB_SPEED_AUTO = -1, 379a5325c2SAlexander Motin NTB_SPEED_NONE = 0, 389a5325c2SAlexander Motin NTB_SPEED_GEN1 = 1, 399a5325c2SAlexander Motin NTB_SPEED_GEN2 = 2, 409a5325c2SAlexander Motin NTB_SPEED_GEN3 = 3, 4148c47677SAlexander Motin NTB_SPEED_GEN4 = 4, 429a5325c2SAlexander Motin }; 439a5325c2SAlexander Motin 449a5325c2SAlexander Motin enum ntb_width { 459a5325c2SAlexander Motin NTB_WIDTH_AUTO = -1, 469a5325c2SAlexander Motin NTB_WIDTH_NONE = 0, 479a5325c2SAlexander Motin NTB_WIDTH_1 = 1, 489a5325c2SAlexander Motin NTB_WIDTH_2 = 2, 499a5325c2SAlexander Motin NTB_WIDTH_4 = 4, 509a5325c2SAlexander Motin NTB_WIDTH_8 = 8, 519a5325c2SAlexander Motin NTB_WIDTH_12 = 12, 529a5325c2SAlexander Motin NTB_WIDTH_16 = 16, 539a5325c2SAlexander Motin NTB_WIDTH_32 = 32, 549a5325c2SAlexander Motin }; 559a5325c2SAlexander Motin 569a5325c2SAlexander Motin typedef void (*ntb_db_callback)(void *data, uint32_t vector); 579a5325c2SAlexander Motin typedef void (*ntb_event_callback)(void *data); 589a5325c2SAlexander Motin struct ntb_ctx_ops { 599a5325c2SAlexander Motin ntb_event_callback link_event; 609a5325c2SAlexander Motin ntb_db_callback db_event; 619a5325c2SAlexander Motin }; 629a5325c2SAlexander Motin}; 639a5325c2SAlexander Motin 64*6683132dSAlexander MotinMETHOD int port_number { 65*6683132dSAlexander Motin device_t ntb; 66*6683132dSAlexander Motin}; 67*6683132dSAlexander Motin 68*6683132dSAlexander MotinMETHOD int peer_port_count { 69*6683132dSAlexander Motin device_t ntb; 70*6683132dSAlexander Motin}; 71*6683132dSAlexander Motin 72*6683132dSAlexander MotinMETHOD int peer_port_number { 73*6683132dSAlexander Motin device_t ntb; 74*6683132dSAlexander Motin int pidx; 75*6683132dSAlexander Motin}; 76*6683132dSAlexander Motin 77*6683132dSAlexander MotinMETHOD int peer_port_idx { 78*6683132dSAlexander Motin device_t ntb; 79*6683132dSAlexander Motin int port; 80*6683132dSAlexander Motin}; 81*6683132dSAlexander Motin 829a5325c2SAlexander MotinMETHOD bool link_is_up { 839a5325c2SAlexander Motin device_t ntb; 849a5325c2SAlexander Motin enum ntb_speed *speed; 859a5325c2SAlexander Motin enum ntb_width *width; 869a5325c2SAlexander Motin}; 879a5325c2SAlexander Motin 889a5325c2SAlexander MotinMETHOD int link_enable { 899a5325c2SAlexander Motin device_t ntb; 909a5325c2SAlexander Motin enum ntb_speed speed; 919a5325c2SAlexander Motin enum ntb_width width; 929a5325c2SAlexander Motin}; 939a5325c2SAlexander Motin 949a5325c2SAlexander MotinMETHOD int link_disable { 959a5325c2SAlexander Motin device_t ntb; 969a5325c2SAlexander Motin}; 979a5325c2SAlexander Motin 989a5325c2SAlexander MotinMETHOD bool link_enabled { 999a5325c2SAlexander Motin device_t ntb; 1009a5325c2SAlexander Motin}; 1019a5325c2SAlexander Motin 1029a5325c2SAlexander MotinMETHOD int set_ctx { 1039a5325c2SAlexander Motin device_t ntb; 1049a5325c2SAlexander Motin void *ctx; 1059a5325c2SAlexander Motin const struct ntb_ctx_ops *ctx_ops; 1069a5325c2SAlexander Motin}; 1079a5325c2SAlexander Motin 1089a5325c2SAlexander MotinMETHOD void * get_ctx { 1099a5325c2SAlexander Motin device_t ntb; 1109a5325c2SAlexander Motin const struct ntb_ctx_ops **ctx_ops; 1119a5325c2SAlexander Motin}; 1129a5325c2SAlexander Motin 1139a5325c2SAlexander MotinMETHOD void clear_ctx { 1149a5325c2SAlexander Motin device_t ntb; 1159a5325c2SAlexander Motin}; 1169a5325c2SAlexander Motin 1179a5325c2SAlexander MotinMETHOD uint8_t mw_count { 1189a5325c2SAlexander Motin device_t ntb; 1199a5325c2SAlexander Motin}; 1209a5325c2SAlexander Motin 1219a5325c2SAlexander MotinMETHOD int mw_get_range { 1229a5325c2SAlexander Motin device_t ntb; 1239a5325c2SAlexander Motin unsigned mw_idx; 1249a5325c2SAlexander Motin vm_paddr_t *base; 1259a5325c2SAlexander Motin caddr_t *vbase; 1269a5325c2SAlexander Motin size_t *size; 1279a5325c2SAlexander Motin size_t *align; 1289a5325c2SAlexander Motin size_t *align_size; 1299a5325c2SAlexander Motin bus_addr_t *plimit; 1309a5325c2SAlexander Motin}; 1319a5325c2SAlexander Motin 1329a5325c2SAlexander MotinMETHOD int mw_set_trans { 1339a5325c2SAlexander Motin device_t ntb; 1349a5325c2SAlexander Motin unsigned mw_idx; 1359a5325c2SAlexander Motin bus_addr_t addr; 1369a5325c2SAlexander Motin size_t size; 1379a5325c2SAlexander Motin}; 1389a5325c2SAlexander Motin 1399a5325c2SAlexander MotinMETHOD int mw_clear_trans { 1409a5325c2SAlexander Motin device_t ntb; 1419a5325c2SAlexander Motin unsigned mw_idx; 1429a5325c2SAlexander Motin}; 1439a5325c2SAlexander Motin 1449a5325c2SAlexander MotinMETHOD int mw_get_wc { 1459a5325c2SAlexander Motin device_t ntb; 1469a5325c2SAlexander Motin unsigned mw_idx; 1479a5325c2SAlexander Motin vm_memattr_t *mode; 1489a5325c2SAlexander Motin}; 1499a5325c2SAlexander Motin 1509a5325c2SAlexander MotinMETHOD int mw_set_wc { 1519a5325c2SAlexander Motin device_t ntb; 1529a5325c2SAlexander Motin unsigned mw_idx; 1539a5325c2SAlexander Motin vm_memattr_t mode; 1549a5325c2SAlexander Motin}; 1559a5325c2SAlexander Motin 1569a5325c2SAlexander MotinMETHOD uint8_t spad_count { 1579a5325c2SAlexander Motin device_t ntb; 1589a5325c2SAlexander Motin}; 1599a5325c2SAlexander Motin 1609a5325c2SAlexander MotinMETHOD void spad_clear { 1619a5325c2SAlexander Motin device_t ntb; 1629a5325c2SAlexander Motin}; 1639a5325c2SAlexander Motin 1649a5325c2SAlexander MotinMETHOD int spad_write { 1659a5325c2SAlexander Motin device_t ntb; 1669a5325c2SAlexander Motin unsigned int idx; 1679a5325c2SAlexander Motin uint32_t val; 1689a5325c2SAlexander Motin}; 1699a5325c2SAlexander Motin 1709a5325c2SAlexander MotinMETHOD int spad_read { 1719a5325c2SAlexander Motin device_t ntb; 1729a5325c2SAlexander Motin unsigned int idx; 1739a5325c2SAlexander Motin uint32_t *val; 1749a5325c2SAlexander Motin}; 1759a5325c2SAlexander Motin 1769a5325c2SAlexander MotinMETHOD int peer_spad_write { 1779a5325c2SAlexander Motin device_t ntb; 1789a5325c2SAlexander Motin unsigned int idx; 1799a5325c2SAlexander Motin uint32_t val; 1809a5325c2SAlexander Motin}; 1819a5325c2SAlexander Motin 1829a5325c2SAlexander MotinMETHOD int peer_spad_read { 1839a5325c2SAlexander Motin device_t ntb; 1849a5325c2SAlexander Motin unsigned int idx; 1859a5325c2SAlexander Motin uint32_t *val; 1869a5325c2SAlexander Motin}; 1879a5325c2SAlexander Motin 1889a5325c2SAlexander MotinMETHOD uint64_t db_valid_mask { 1899a5325c2SAlexander Motin device_t ntb; 1909a5325c2SAlexander Motin}; 1919a5325c2SAlexander Motin 1929a5325c2SAlexander MotinMETHOD int db_vector_count { 1939a5325c2SAlexander Motin device_t ntb; 1949a5325c2SAlexander Motin}; 1959a5325c2SAlexander Motin 1969a5325c2SAlexander MotinMETHOD uint64_t db_vector_mask { 1979a5325c2SAlexander Motin device_t ntb; 1989a5325c2SAlexander Motin uint32_t vector; 1999a5325c2SAlexander Motin}; 2009a5325c2SAlexander Motin 2019a5325c2SAlexander MotinMETHOD int peer_db_addr { 2029a5325c2SAlexander Motin device_t ntb; 2039a5325c2SAlexander Motin bus_addr_t *db_addr; 2049a5325c2SAlexander Motin vm_size_t *db_size; 2059a5325c2SAlexander Motin}; 2069a5325c2SAlexander Motin 2079a5325c2SAlexander MotinMETHOD void db_clear { 2089a5325c2SAlexander Motin device_t ntb; 2099a5325c2SAlexander Motin uint64_t bits; 2109a5325c2SAlexander Motin}; 2119a5325c2SAlexander Motin 2129a5325c2SAlexander MotinMETHOD void db_clear_mask { 2139a5325c2SAlexander Motin device_t ntb; 2149a5325c2SAlexander Motin uint64_t bits; 2159a5325c2SAlexander Motin}; 2169a5325c2SAlexander Motin 2179a5325c2SAlexander MotinMETHOD uint64_t db_read { 2189a5325c2SAlexander Motin device_t ntb; 2199a5325c2SAlexander Motin}; 2209a5325c2SAlexander Motin 2219a5325c2SAlexander MotinMETHOD void db_set_mask { 2229a5325c2SAlexander Motin device_t ntb; 2239a5325c2SAlexander Motin uint64_t bits; 2249a5325c2SAlexander Motin}; 2259a5325c2SAlexander Motin 2269a5325c2SAlexander MotinMETHOD void peer_db_set { 2279a5325c2SAlexander Motin device_t ntb; 2289a5325c2SAlexander Motin uint64_t bits; 2299a5325c2SAlexander Motin}; 230