NewBus'ify NTB subsystem.
This follows NTB subsystem modularization in Linux, tuning it to FreeBSD native NewBus interfaces. This change allows to support different types of hardware with different drivers, support multiple NTB instances in a system, ntb_transport module use for needs other then if_ntb, etc. Sponsored by: iXsystems, Inc.
This commit is contained in:
parent
12738808e7
commit
9a5325c205
@ -282,7 +282,10 @@ dev/hyperv/vmbus/amd64/hyperv_machdep.c optional hyperv
|
||||
dev/hyperv/vmbus/amd64/vmbus_vector.S optional hyperv
|
||||
dev/nfe/if_nfe.c optional nfe pci
|
||||
dev/ntb/if_ntb/if_ntb.c optional if_ntb
|
||||
dev/ntb/ntb_hw/ntb_hw.c optional if_ntb | ntb_hw
|
||||
dev/ntb/ntb_transport.c optional if_ntb
|
||||
dev/ntb/ntb.c optional if_ntb | ntb_hw
|
||||
dev/ntb/ntb_if.m optional if_ntb | ntb_hw
|
||||
dev/ntb/ntb_hw/ntb_hw.c optional ntb_hw
|
||||
dev/nvd/nvd.c optional nvd nvme
|
||||
dev/nvme/nvme.c optional nvme
|
||||
dev/nvme/nvme_ctrlr.c optional nvme
|
||||
|
@ -276,7 +276,10 @@ dev/mse/mse.c optional mse
|
||||
dev/mse/mse_isa.c optional mse isa
|
||||
dev/nfe/if_nfe.c optional nfe pci
|
||||
dev/ntb/if_ntb/if_ntb.c optional if_ntb
|
||||
dev/ntb/ntb_hw/ntb_hw.c optional if_ntb | ntb_hw
|
||||
dev/ntb/ntb_transport.c optional if_ntb
|
||||
dev/ntb/ntb.c optional if_ntb | ntb_hw
|
||||
dev/ntb/ntb_if.m optional if_ntb | ntb_hw
|
||||
dev/ntb/ntb_hw/ntb_hw.c optional ntb_hw
|
||||
dev/nvd/nvd.c optional nvd nvme
|
||||
dev/nvme/nvme.c optional nvme
|
||||
dev/nvme/nvme_ctrlr.c optional nvme
|
||||
|
File diff suppressed because it is too large
Load Diff
42
sys/dev/ntb/ntb.c
Normal file
42
sys/dev/ntb/ntb.c
Normal file
@ -0,0 +1,42 @@
|
||||
/*-
|
||||
* Copyright (c) 2016 Alexander Motin <mav@FreeBSD.org>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/kernel.h>
|
||||
#include <sys/systm.h>
|
||||
#include <sys/bus.h>
|
||||
#include <sys/module.h>
|
||||
#include <sys/sysctl.h>
|
||||
|
||||
#include "ntb.h"
|
||||
|
||||
devclass_t ntb_hw_devclass;
|
||||
SYSCTL_NODE(_hw, OID_AUTO, ntb, CTLFLAG_RW, 0, "NTB sysctls");
|
||||
|
||||
MODULE_VERSION(ntb, 1);
|
37
sys/dev/ntb/ntb.h
Normal file
37
sys/dev/ntb/ntb.h
Normal file
@ -0,0 +1,37 @@
|
||||
/*-
|
||||
* Copyright (c) 2016 Alexander Motin <mav@FreeBSD.org>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* $FreeBSD$
|
||||
*/
|
||||
|
||||
#ifndef _NTB_H_
|
||||
#define _NTB_H_
|
||||
|
||||
#include "ntb_if.h"
|
||||
|
||||
extern devclass_t ntb_hw_devclass;
|
||||
SYSCTL_DECL(_hw_ntb);
|
||||
|
||||
#endif /* _NTB_H_ */
|
File diff suppressed because it is too large
Load Diff
@ -1,125 +0,0 @@
|
||||
/*-
|
||||
* Copyright (C) 2013 Intel Corporation
|
||||
* Copyright (C) 2015 EMC Corporation
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* $FreeBSD$
|
||||
*/
|
||||
|
||||
#ifndef _NTB_HW_H_
|
||||
#define _NTB_HW_H_
|
||||
|
||||
struct ntb_softc;
|
||||
|
||||
#define NTB_MAX_NUM_MW 3
|
||||
|
||||
enum ntb_speed {
|
||||
NTB_SPEED_AUTO = -1,
|
||||
NTB_SPEED_NONE = 0,
|
||||
NTB_SPEED_GEN1 = 1,
|
||||
NTB_SPEED_GEN2 = 2,
|
||||
NTB_SPEED_GEN3 = 3,
|
||||
};
|
||||
|
||||
enum ntb_width {
|
||||
NTB_WIDTH_AUTO = -1,
|
||||
NTB_WIDTH_NONE = 0,
|
||||
NTB_WIDTH_1 = 1,
|
||||
NTB_WIDTH_2 = 2,
|
||||
NTB_WIDTH_4 = 4,
|
||||
NTB_WIDTH_8 = 8,
|
||||
NTB_WIDTH_12 = 12,
|
||||
NTB_WIDTH_16 = 16,
|
||||
NTB_WIDTH_32 = 32,
|
||||
};
|
||||
|
||||
SYSCTL_DECL(_hw_ntb);
|
||||
|
||||
typedef void (*ntb_db_callback)(void *data, uint32_t vector);
|
||||
typedef void (*ntb_event_callback)(void *data);
|
||||
|
||||
struct ntb_ctx_ops {
|
||||
ntb_event_callback link_event;
|
||||
ntb_db_callback db_event;
|
||||
};
|
||||
|
||||
device_t ntb_get_device(struct ntb_softc *);
|
||||
|
||||
bool ntb_link_is_up(struct ntb_softc *, enum ntb_speed *, enum ntb_width *);
|
||||
void ntb_link_event(struct ntb_softc *);
|
||||
int ntb_link_enable(struct ntb_softc *, enum ntb_speed, enum ntb_width);
|
||||
int ntb_link_disable(struct ntb_softc *);
|
||||
bool ntb_link_enabled(struct ntb_softc *);
|
||||
|
||||
int ntb_set_ctx(struct ntb_softc *, void *, const struct ntb_ctx_ops *);
|
||||
void *ntb_get_ctx(struct ntb_softc *, const struct ntb_ctx_ops **);
|
||||
void ntb_clear_ctx(struct ntb_softc *);
|
||||
|
||||
uint8_t ntb_mw_count(struct ntb_softc *);
|
||||
int ntb_mw_get_range(struct ntb_softc *, unsigned mw_idx, vm_paddr_t *base,
|
||||
caddr_t *vbase, size_t *size, size_t *align, size_t *align_size,
|
||||
bus_addr_t *plimit);
|
||||
int ntb_mw_set_trans(struct ntb_softc *, unsigned mw_idx, bus_addr_t, size_t);
|
||||
int ntb_mw_clear_trans(struct ntb_softc *, unsigned mw_idx);
|
||||
|
||||
int ntb_mw_get_wc(struct ntb_softc *, unsigned mw_idx, vm_memattr_t *mode);
|
||||
int ntb_mw_set_wc(struct ntb_softc *, unsigned mw_idx, vm_memattr_t mode);
|
||||
|
||||
uint8_t ntb_get_max_spads(struct ntb_softc *ntb);
|
||||
void ntb_spad_clear(struct ntb_softc *ntb);
|
||||
int ntb_spad_write(struct ntb_softc *ntb, unsigned int idx, uint32_t val);
|
||||
int ntb_spad_read(struct ntb_softc *ntb, unsigned int idx, uint32_t *val);
|
||||
int ntb_peer_spad_write(struct ntb_softc *ntb, unsigned int idx,
|
||||
uint32_t val);
|
||||
int ntb_peer_spad_read(struct ntb_softc *ntb, unsigned int idx,
|
||||
uint32_t *val);
|
||||
|
||||
uint64_t ntb_db_valid_mask(struct ntb_softc *);
|
||||
uint64_t ntb_db_vector_mask(struct ntb_softc *, uint32_t vector);
|
||||
bus_addr_t ntb_get_peer_db_addr(struct ntb_softc *, vm_size_t *sz_out);
|
||||
|
||||
void ntb_db_clear(struct ntb_softc *, uint64_t bits);
|
||||
void ntb_db_clear_mask(struct ntb_softc *, uint64_t bits);
|
||||
uint64_t ntb_db_read(struct ntb_softc *);
|
||||
void ntb_db_set_mask(struct ntb_softc *, uint64_t bits);
|
||||
void ntb_peer_db_set(struct ntb_softc *, uint64_t bits);
|
||||
|
||||
#define XEON_SPAD_COUNT 16
|
||||
#define ATOM_SPAD_COUNT 16
|
||||
|
||||
/* Hardware owns the low 16 bits of features. */
|
||||
#define NTB_BAR_SIZE_4K (1 << 0)
|
||||
#define NTB_SDOORBELL_LOCKUP (1 << 1)
|
||||
#define NTB_SB01BASE_LOCKUP (1 << 2)
|
||||
#define NTB_B2BDOORBELL_BIT14 (1 << 3)
|
||||
/* Software/configuration owns the top 16 bits. */
|
||||
#define NTB_SPLIT_BAR (1ull << 16)
|
||||
|
||||
#define NTB_FEATURES_STR \
|
||||
"\20\21SPLIT_BAR4\04B2B_DOORBELL_BIT14\03SB01BASE_LOCKUP" \
|
||||
"\02SDOORBELL_LOCKUP\01BAR_SIZE_4K"
|
||||
|
||||
bool ntb_has_feature(struct ntb_softc *, uint32_t);
|
||||
|
||||
#endif /* _NTB_HW_H_ */
|
@ -1,4 +1,5 @@
|
||||
/*-
|
||||
* Copyright (c) 2016 Alexander Motin <mav@FreeBSD.org>
|
||||
* Copyright (C) 2013 Intel Corporation
|
||||
* Copyright (C) 2015 EMC Corporation
|
||||
* All rights reserved.
|
||||
@ -76,6 +77,7 @@
|
||||
#define XEON_SDBMSK_OFFSET 0x0066
|
||||
#define XEON_USMEMMISS_OFFSET 0x0070
|
||||
#define XEON_SPAD_OFFSET 0x0080
|
||||
#define XEON_SPAD_COUNT 16
|
||||
#define XEON_SPADSEMA4_OFFSET 0x00c0
|
||||
#define XEON_WCCNTRL_OFFSET 0x00e0
|
||||
#define XEON_UNCERRSTS_OFFSET 0x014c
|
||||
@ -104,6 +106,7 @@
|
||||
#define ATOM_NTBCNTL_OFFSET 0x0060
|
||||
#define ATOM_EBDF_OFFSET 0x0064
|
||||
#define ATOM_SPAD_OFFSET 0x0080
|
||||
#define ATOM_SPAD_COUNT 16
|
||||
#define ATOM_SPADSEMA_OFFSET 0x00c0
|
||||
#define ATOM_STKYSPAD_OFFSET 0x00c4
|
||||
#define ATOM_PBAR2XLAT_OFFSET 0x8008
|
||||
|
497
sys/dev/ntb/ntb_if.m
Normal file
497
sys/dev/ntb/ntb_if.m
Normal file
@ -0,0 +1,497 @@
|
||||
#-
|
||||
# Copyright (c) 2016 Alexander Motin <mav@FreeBSD.org>
|
||||
# All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions
|
||||
# are met:
|
||||
# 1. Redistributions of source code must retain the above copyright
|
||||
# notice, this list of conditions and the following disclaimer.
|
||||
# 2. Redistributions in binary form must reproduce the above copyright
|
||||
# notice, this list of conditions and the following disclaimer in the
|
||||
# documentation and/or other materials provided with the distribution.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
# SUCH DAMAGE.
|
||||
#
|
||||
# $FreeBSD$
|
||||
#
|
||||
|
||||
#include <sys/bus.h>
|
||||
#include <machine/bus.h>
|
||||
|
||||
INTERFACE ntb;
|
||||
|
||||
HEADER {
|
||||
enum ntb_speed {
|
||||
NTB_SPEED_AUTO = -1,
|
||||
NTB_SPEED_NONE = 0,
|
||||
NTB_SPEED_GEN1 = 1,
|
||||
NTB_SPEED_GEN2 = 2,
|
||||
NTB_SPEED_GEN3 = 3,
|
||||
};
|
||||
|
||||
enum ntb_width {
|
||||
NTB_WIDTH_AUTO = -1,
|
||||
NTB_WIDTH_NONE = 0,
|
||||
NTB_WIDTH_1 = 1,
|
||||
NTB_WIDTH_2 = 2,
|
||||
NTB_WIDTH_4 = 4,
|
||||
NTB_WIDTH_8 = 8,
|
||||
NTB_WIDTH_12 = 12,
|
||||
NTB_WIDTH_16 = 16,
|
||||
NTB_WIDTH_32 = 32,
|
||||
};
|
||||
|
||||
typedef void (*ntb_db_callback)(void *data, uint32_t vector);
|
||||
typedef void (*ntb_event_callback)(void *data);
|
||||
struct ntb_ctx_ops {
|
||||
ntb_event_callback link_event;
|
||||
ntb_db_callback db_event;
|
||||
};
|
||||
};
|
||||
|
||||
#
|
||||
# ntb_link_is_up() - get the current ntb link state
|
||||
# @ntb: NTB device context
|
||||
# @speed: OUT - The link speed expressed as PCIe generation number
|
||||
# @width: OUT - The link width expressed as the number of PCIe lanes
|
||||
#
|
||||
# RETURNS: true or false based on the hardware link state
|
||||
#
|
||||
METHOD bool link_is_up {
|
||||
device_t ntb;
|
||||
enum ntb_speed *speed;
|
||||
enum ntb_width *width;
|
||||
};
|
||||
|
||||
#
|
||||
# ntb_link_enable() - enable the link on the secondary side of the ntb
|
||||
# @ntb: NTB device context
|
||||
# @max_speed: The maximum link speed expressed as PCIe generation number[0]
|
||||
# @max_width: The maximum link width expressed as the number of PCIe lanes[0]
|
||||
#
|
||||
# Enable the link on the secondary side of the ntb. This can only be done
|
||||
# from the primary side of the ntb in primary or b2b topology. The ntb device
|
||||
# should train the link to its maximum speed and width, or the requested speed
|
||||
# and width, whichever is smaller, if supported.
|
||||
#
|
||||
# Return: Zero on success, otherwise an error number.
|
||||
#
|
||||
# [0]: Only NTB_SPEED_AUTO and NTB_WIDTH_AUTO are valid inputs; other speed
|
||||
# and width input will be ignored.
|
||||
#/
|
||||
METHOD int link_enable {
|
||||
device_t ntb;
|
||||
enum ntb_speed speed;
|
||||
enum ntb_width width;
|
||||
};
|
||||
|
||||
#
|
||||
# ntb_link_disable() - disable the link on the secondary side of the ntb
|
||||
# @ntb: NTB device context
|
||||
#
|
||||
# Disable the link on the secondary side of the ntb. This can only be done
|
||||
# from the primary side of the ntb in primary or b2b topology. The ntb device
|
||||
# should disable the link. Returning from this call must indicate that a
|
||||
# barrier has passed, though with no more writes may pass in either direction
|
||||
# across the link, except if this call returns an error number.
|
||||
#
|
||||
# Return: Zero on success, otherwise an error number.
|
||||
#
|
||||
METHOD int link_disable {
|
||||
device_t ntb;
|
||||
};
|
||||
|
||||
#
|
||||
# get enable status of the link on the secondary side of the ntb
|
||||
#
|
||||
METHOD bool link_enabled {
|
||||
device_t ntb;
|
||||
};
|
||||
|
||||
#
|
||||
# ntb_set_ctx() - associate a driver context with an ntb device
|
||||
# @ntb: NTB device context
|
||||
# @ctx: Driver context
|
||||
# @ctx_ops: Driver context operations
|
||||
#
|
||||
# Associate a driver context and operations with a ntb device. The context is
|
||||
# provided by the client driver, and the driver may associate a different
|
||||
# context with each ntb device.
|
||||
#
|
||||
# Return: Zero if the context is associated, otherwise an error number.
|
||||
#
|
||||
METHOD int set_ctx {
|
||||
device_t ntb;
|
||||
void *ctx;
|
||||
const struct ntb_ctx_ops *ctx_ops;
|
||||
};
|
||||
|
||||
#
|
||||
# ntb_set_ctx() - get a driver context associated with an ntb device
|
||||
# @ntb: NTB device context
|
||||
# @ctx_ops: Driver context operations
|
||||
#
|
||||
# Get a driver context and operations associated with a ntb device.
|
||||
#
|
||||
METHOD void * get_ctx {
|
||||
device_t ntb;
|
||||
const struct ntb_ctx_ops **ctx_ops;
|
||||
};
|
||||
|
||||
#
|
||||
# ntb_clear_ctx() - disassociate any driver context from an ntb device
|
||||
# @ntb: NTB device context
|
||||
#
|
||||
# Clear any association that may exist between a driver context and the ntb
|
||||
# device.
|
||||
#
|
||||
METHOD void clear_ctx {
|
||||
device_t ntb;
|
||||
};
|
||||
|
||||
#
|
||||
# ntb_mw_count() - Get the number of memory windows available for KPI
|
||||
# consumers.
|
||||
#
|
||||
# (Excludes any MW wholly reserved for register access.)
|
||||
#
|
||||
METHOD uint8_t mw_count {
|
||||
device_t ntb;
|
||||
};
|
||||
|
||||
#
|
||||
# ntb_mw_get_range() - get the range of a memory window
|
||||
# @ntb: NTB device context
|
||||
# @idx: Memory window number
|
||||
# @base: OUT - the base address for mapping the memory window
|
||||
# @size: OUT - the size for mapping the memory window
|
||||
# @align: OUT - the base alignment for translating the memory window
|
||||
# @align_size: OUT - the size alignment for translating the memory window
|
||||
#
|
||||
# Get the range of a memory window. NULL may be given for any output
|
||||
# parameter if the value is not needed. The base and size may be used for
|
||||
# mapping the memory window, to access the peer memory. The alignment and
|
||||
# size may be used for translating the memory window, for the peer to access
|
||||
# memory on the local system.
|
||||
#
|
||||
# Return: Zero on success, otherwise an error number.
|
||||
#
|
||||
METHOD int mw_get_range {
|
||||
device_t ntb;
|
||||
unsigned mw_idx;
|
||||
vm_paddr_t *base;
|
||||
caddr_t *vbase;
|
||||
size_t *size;
|
||||
size_t *align;
|
||||
size_t *align_size;
|
||||
bus_addr_t *plimit;
|
||||
};
|
||||
|
||||
#
|
||||
# ntb_mw_set_trans() - set the translation of a memory window
|
||||
# @ntb: NTB device context
|
||||
# @idx: Memory window number
|
||||
# @addr: The dma address local memory to expose to the peer
|
||||
# @size: The size of the local memory to expose to the peer
|
||||
#
|
||||
# Set the translation of a memory window. The peer may access local memory
|
||||
# through the window starting at the address, up to the size. The address
|
||||
# must be aligned to the alignment specified by ntb_mw_get_range(). The size
|
||||
# must be aligned to the size alignment specified by ntb_mw_get_range(). The
|
||||
# address must be below the plimit specified by ntb_mw_get_range() (i.e. for
|
||||
# 32-bit BARs).
|
||||
#
|
||||
# Return: Zero on success, otherwise an error number.
|
||||
#
|
||||
METHOD int mw_set_trans {
|
||||
device_t ntb;
|
||||
unsigned mw_idx;
|
||||
bus_addr_t addr;
|
||||
size_t size;
|
||||
};
|
||||
|
||||
#
|
||||
# ntb_mw_clear_trans() - clear the translation of a memory window
|
||||
# @ntb: NTB device context
|
||||
# @idx: Memory window number
|
||||
#
|
||||
# Clear the translation of a memory window. The peer may no longer access
|
||||
# local memory through the window.
|
||||
#
|
||||
# Return: Zero on success, otherwise an error number.
|
||||
#
|
||||
METHOD int mw_clear_trans {
|
||||
device_t ntb;
|
||||
unsigned mw_idx;
|
||||
};
|
||||
|
||||
#
|
||||
# ntb_mw_get_wc - Get the write-combine status of a memory window
|
||||
#
|
||||
# Returns: Zero on success, setting *wc; otherwise an error number (e.g. if
|
||||
# idx is an invalid memory window).
|
||||
#
|
||||
# Mode is a VM_MEMATTR_* type.
|
||||
#
|
||||
METHOD int mw_get_wc {
|
||||
device_t ntb;
|
||||
unsigned mw_idx;
|
||||
vm_memattr_t *mode;
|
||||
};
|
||||
|
||||
#
|
||||
# ntb_mw_set_wc - Set the write-combine status of a memory window
|
||||
#
|
||||
# If 'mode' matches the current status, this does nothing and succeeds. Mode
|
||||
# is a VM_MEMATTR_* type.
|
||||
#
|
||||
# Returns: Zero on success, setting the caching attribute on the virtual
|
||||
# mapping of the BAR; otherwise an error number (e.g. if idx is an invalid
|
||||
# memory window, or if changing the caching attribute fails).
|
||||
#
|
||||
METHOD int mw_set_wc {
|
||||
device_t ntb;
|
||||
unsigned mw_idx;
|
||||
vm_memattr_t mode;
|
||||
};
|
||||
|
||||
#
|
||||
# ntb_spad_count() - get the total scratch regs usable
|
||||
# @ntb: pointer to ntb_softc instance
|
||||
#
|
||||
# This function returns the max 32bit scratchpad registers usable by the
|
||||
# upper layer.
|
||||
#
|
||||
# RETURNS: total number of scratch pad registers available
|
||||
#
|
||||
METHOD uint8_t spad_count {
|
||||
device_t ntb;
|
||||
};
|
||||
|
||||
#
|
||||
# ntb_get_max_spads() - zero local scratch registers
|
||||
# @ntb: pointer to ntb_softc instance
|
||||
#
|
||||
# This functions overwrites all local scratchpad registers with zeroes.
|
||||
#
|
||||
METHOD void spad_clear {
|
||||
device_t ntb;
|
||||
};
|
||||
|
||||
#
|
||||
# ntb_spad_write() - write to the secondary scratchpad register
|
||||
# @ntb: pointer to ntb_softc instance
|
||||
# @idx: index to the scratchpad register, 0 based
|
||||
# @val: the data value to put into the register
|
||||
#
|
||||
# This function allows writing of a 32bit value to the indexed scratchpad
|
||||
# register. The register resides on the secondary (external) side.
|
||||
#
|
||||
# RETURNS: An appropriate ERRNO error value on error, or zero for success.
|
||||
#
|
||||
METHOD int spad_write {
|
||||
device_t ntb;
|
||||
unsigned int idx;
|
||||
uint32_t val;
|
||||
};
|
||||
|
||||
#
|
||||
# ntb_spad_read() - read from the primary scratchpad register
|
||||
# @ntb: pointer to ntb_softc instance
|
||||
# @idx: index to scratchpad register, 0 based
|
||||
# @val: pointer to 32bit integer for storing the register value
|
||||
#
|
||||
# This function allows reading of the 32bit scratchpad register on
|
||||
# the primary (internal) side.
|
||||
#
|
||||
# RETURNS: An appropriate ERRNO error value on error, or zero for success.
|
||||
#
|
||||
METHOD int spad_read {
|
||||
device_t ntb;
|
||||
unsigned int idx;
|
||||
uint32_t *val;
|
||||
};
|
||||
|
||||
#
|
||||
# ntb_peer_spad_write() - write to the secondary scratchpad register
|
||||
# @ntb: pointer to ntb_softc instance
|
||||
# @idx: index to the scratchpad register, 0 based
|
||||
# @val: the data value to put into the register
|
||||
#
|
||||
# This function allows writing of a 32bit value to the indexed scratchpad
|
||||
# register. The register resides on the secondary (external) side.
|
||||
#
|
||||
# RETURNS: An appropriate ERRNO error value on error, or zero for success.
|
||||
#
|
||||
METHOD int peer_spad_write {
|
||||
device_t ntb;
|
||||
unsigned int idx;
|
||||
uint32_t val;
|
||||
};
|
||||
|
||||
#
|
||||
# ntb_peer_spad_read() - read from the primary scratchpad register
|
||||
# @ntb: pointer to ntb_softc instance
|
||||
# @idx: index to scratchpad register, 0 based
|
||||
# @val: pointer to 32bit integer for storing the register value
|
||||
#
|
||||
# This function allows reading of the 32bit scratchpad register on
|
||||
# the primary (internal) side.
|
||||
#
|
||||
# RETURNS: An appropriate ERRNO error value on error, or zero for success.
|
||||
#
|
||||
METHOD int peer_spad_read {
|
||||
device_t ntb;
|
||||
unsigned int idx;
|
||||
uint32_t *val;
|
||||
};
|
||||
|
||||
#
|
||||
# ntb_db_valid_mask() - get a mask of doorbell bits supported by the ntb
|
||||
# @ntb: NTB device context
|
||||
#
|
||||
# Hardware may support different number or arrangement of doorbell bits.
|
||||
#
|
||||
# Return: A mask of doorbell bits supported by the ntb.
|
||||
#
|
||||
METHOD uint64_t db_valid_mask {
|
||||
device_t ntb;
|
||||
};
|
||||
|
||||
#
|
||||
# ntb_db_vector_count() - get the number of doorbell interrupt vectors
|
||||
# @ntb: NTB device context.
|
||||
#
|
||||
# Hardware may support different number of interrupt vectors.
|
||||
#
|
||||
# Return: The number of doorbell interrupt vectors.
|
||||
#
|
||||
METHOD int db_vector_count {
|
||||
device_t ntb;
|
||||
};
|
||||
|
||||
#
|
||||
# ntb_db_vector_mask() - get a mask of doorbell bits serviced by a vector
|
||||
# @ntb: NTB device context
|
||||
# @vector: Doorbell vector number
|
||||
#
|
||||
# Each interrupt vector may have a different number or arrangement of bits.
|
||||
#
|
||||
# Return: A mask of doorbell bits serviced by a vector.
|
||||
#
|
||||
METHOD uint64_t db_vector_mask {
|
||||
device_t ntb;
|
||||
uint32_t vector;
|
||||
};
|
||||
|
||||
#
|
||||
# ntb_peer_db_addr() - address and size of the peer doorbell register
|
||||
# @ntb: NTB device context.
|
||||
# @db_addr: OUT - The address of the peer doorbell register.
|
||||
# @db_size: OUT - The number of bytes to write the peer doorbell register.
|
||||
#
|
||||
# Return the address of the peer doorbell register. This may be used, for
|
||||
# example, by drivers that offload memory copy operations to a dma engine.
|
||||
# The drivers may wish to ring the peer doorbell at the completion of memory
|
||||
# copy operations. For efficiency, and to simplify ordering of operations
|
||||
# between the dma memory copies and the ringing doorbell, the driver may
|
||||
# append one additional dma memory copy with the doorbell register as the
|
||||
# destination, after the memory copy operations.
|
||||
#
|
||||
# Return: Zero on success, otherwise an error number.
|
||||
#
|
||||
# Note that writing the peer doorbell via a memory window will *not* generate
|
||||
# an interrupt on the remote host; that must be done separately.
|
||||
#
|
||||
METHOD int peer_db_addr {
|
||||
device_t ntb;
|
||||
bus_addr_t *db_addr;
|
||||
vm_size_t *db_size;
|
||||
};
|
||||
|
||||
#
|
||||
# ntb_db_clear() - clear bits in the local doorbell register
|
||||
# @ntb: NTB device context.
|
||||
# @db_bits: Doorbell bits to clear.
|
||||
#
|
||||
# Clear bits in the local doorbell register, arming the bits for the next
|
||||
# doorbell.
|
||||
#
|
||||
# Return: Zero on success, otherwise an error number.
|
||||
#
|
||||
METHOD void db_clear {
|
||||
device_t ntb;
|
||||
uint64_t bits;
|
||||
};
|
||||
|
||||
#
|
||||
# ntb_db_clear_mask() - clear bits in the local doorbell mask
|
||||
# @ntb: NTB device context.
|
||||
# @db_bits: Doorbell bits to clear.
|
||||
#
|
||||
# Clear bits in the local doorbell mask register, allowing doorbell interrupts
|
||||
# from being generated for those doorbell bits. If a doorbell bit is already
|
||||
# set at the time the mask is cleared, and the corresponding mask bit is
|
||||
# changed from set to clear, then the ntb driver must ensure that
|
||||
# ntb_db_event() is called. If the hardware does not generate the interrupt
|
||||
# on clearing the mask bit, then the driver must call ntb_db_event() anyway.
|
||||
#
|
||||
# Return: Zero on success, otherwise an error number.
|
||||
#
|
||||
METHOD void db_clear_mask {
|
||||
device_t ntb;
|
||||
uint64_t bits;
|
||||
};
|
||||
|
||||
#
|
||||
# ntb_db_read() - read the local doorbell register
|
||||
# @ntb: NTB device context.
|
||||
#
|
||||
# Read the local doorbell register, and return the bits that are set.
|
||||
#
|
||||
# Return: The bits currently set in the local doorbell register.
|
||||
#
|
||||
METHOD uint64_t db_read {
|
||||
device_t ntb;
|
||||
};
|
||||
|
||||
#
|
||||
# ntb_db_set_mask() - set bits in the local doorbell mask
|
||||
# @ntb: NTB device context.
|
||||
# @db_bits: Doorbell mask bits to set.
|
||||
#
|
||||
# Set bits in the local doorbell mask register, preventing doorbell interrupts
|
||||
# from being generated for those doorbell bits. Bits that were already set
|
||||
# must remain set.
|
||||
#
|
||||
# Return: Zero on success, otherwise an error number.
|
||||
#
|
||||
METHOD void db_set_mask {
|
||||
device_t ntb;
|
||||
uint64_t bits;
|
||||
};
|
||||
|
||||
#
|
||||
# ntb_peer_db_set() - Set the doorbell on the secondary/external side
|
||||
# @ntb: pointer to ntb_softc instance
|
||||
# @bit: doorbell bits to ring
|
||||
#
|
||||
# This function allows triggering of a doorbell on the secondary/external
|
||||
# side that will initiate an interrupt on the remote host
|
||||
#
|
||||
METHOD void peer_db_set {
|
||||
device_t ntb;
|
||||
uint64_t bits;
|
||||
};
|
||||
|
1492
sys/dev/ntb/ntb_transport.c
Normal file
1492
sys/dev/ntb/ntb_transport.c
Normal file
File diff suppressed because it is too large
Load Diff
60
sys/dev/ntb/ntb_transport.h
Normal file
60
sys/dev/ntb/ntb_transport.h
Normal file
@ -0,0 +1,60 @@
|
||||
/*-
|
||||
* Copyright (c) 2016 Alexander Motin <mav@FreeBSD.org>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* $FreeBSD$
|
||||
*/
|
||||
|
||||
struct ntb_transport_qp;
|
||||
|
||||
extern devclass_t ntb_transport_devclass;
|
||||
|
||||
enum ntb_link_event {
|
||||
NTB_LINK_DOWN = 0,
|
||||
NTB_LINK_UP,
|
||||
};
|
||||
|
||||
struct ntb_queue_handlers {
|
||||
void (*rx_handler)(struct ntb_transport_qp *qp, void *qp_data,
|
||||
void *data, int len);
|
||||
void (*tx_handler)(struct ntb_transport_qp *qp, void *qp_data,
|
||||
void *data, int len);
|
||||
void (*event_handler)(void *data, enum ntb_link_event status);
|
||||
};
|
||||
|
||||
unsigned char ntb_transport_qp_num(struct ntb_transport_qp *qp);
|
||||
unsigned int ntb_transport_max_size(struct ntb_transport_qp *qp);
|
||||
struct ntb_transport_qp *
|
||||
ntb_transport_create_queue(void *data, device_t dev,
|
||||
const struct ntb_queue_handlers *handlers);
|
||||
void ntb_transport_free_queue(struct ntb_transport_qp *qp);
|
||||
int ntb_transport_rx_enqueue(struct ntb_transport_qp *qp, void *cb, void *data,
|
||||
unsigned int len);
|
||||
int ntb_transport_tx_enqueue(struct ntb_transport_qp *qp, void *cb, void *data,
|
||||
unsigned int len);
|
||||
void *ntb_transport_rx_remove(struct ntb_transport_qp *qp, unsigned int *len);
|
||||
void ntb_transport_link_up(struct ntb_transport_qp *qp);
|
||||
void ntb_transport_link_down(struct ntb_transport_qp *qp);
|
||||
bool ntb_transport_link_query(struct ntb_transport_qp *qp);
|
||||
unsigned int ntb_transport_tx_free_entry(struct ntb_transport_qp *qp);
|
@ -1,5 +1,5 @@
|
||||
# $FreeBSD$
|
||||
|
||||
SUBDIR= ntb_hw if_ntb
|
||||
SUBDIR= ntb ntb_hw ntb_transport if_ntb
|
||||
|
||||
.include <bsd.subdir.mk>
|
||||
|
9
sys/modules/ntb/ntb/Makefile
Normal file
9
sys/modules/ntb/ntb/Makefile
Normal file
@ -0,0 +1,9 @@
|
||||
# $FreeBSD$
|
||||
|
||||
.PATH: ${.CURDIR}/../../../dev/ntb
|
||||
|
||||
KMOD = ntb
|
||||
SRCS = ntb.c ntb_if.c
|
||||
SRCS += device_if.h bus_if.h ntb_if.h
|
||||
|
||||
.include <bsd.kmod.mk>
|
@ -4,6 +4,6 @@
|
||||
|
||||
KMOD = ntb_hw
|
||||
SRCS = ntb_hw.c
|
||||
SRCS += device_if.h bus_if.h pci_if.h
|
||||
SRCS += device_if.h bus_if.h pci_if.h ntb_if.h
|
||||
|
||||
.include <bsd.kmod.mk>
|
||||
|
9
sys/modules/ntb/ntb_transport/Makefile
Normal file
9
sys/modules/ntb/ntb_transport/Makefile
Normal file
@ -0,0 +1,9 @@
|
||||
# $FreeBSD$
|
||||
|
||||
.PATH: ${.CURDIR}/../../../dev/ntb
|
||||
|
||||
KMOD = ntb_transport
|
||||
SRCS = ntb_transport.c
|
||||
SRCS += device_if.h bus_if.h ntb_if.h
|
||||
|
||||
.include <bsd.kmod.mk>
|
Loading…
Reference in New Issue
Block a user