xref: /freebsd/sys/dev/ntb/ntb.h (revision 3883c6fb)
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 #ifndef _NTB_H_
289a5325c2SAlexander Motin #define _NTB_H_
299a5325c2SAlexander Motin 
309a5325c2SAlexander Motin #include "ntb_if.h"
319a5325c2SAlexander Motin 
329a5325c2SAlexander Motin SYSCTL_DECL(_hw_ntb);
339a5325c2SAlexander Motin 
344490696bSAlexander Motin int ntb_register_device(device_t ntb);
354490696bSAlexander Motin int ntb_unregister_device(device_t ntb);
36ddfc9c4cSWarner Losh int ntb_child_location(device_t dev, device_t child, struct sbuf *sb);
37b7dd3fbeSAlexander Motin int ntb_print_child(device_t dev, device_t child);
387f215e07SAlexander Motin bus_dma_tag_t ntb_get_dma_tag(device_t bus, device_t child);
394490696bSAlexander Motin 
404490696bSAlexander Motin /*
414490696bSAlexander Motin  * ntb_link_event() - notify driver context of a change in link status
424490696bSAlexander Motin  * @ntb:        NTB device context
434490696bSAlexander Motin  *
444490696bSAlexander Motin  * Notify the driver context that the link status may have changed.  The driver
454490696bSAlexander Motin  * should call intb_link_is_up() to get the current status.
464490696bSAlexander Motin  */
474490696bSAlexander Motin void ntb_link_event(device_t ntb);
484490696bSAlexander Motin 
494490696bSAlexander Motin /*
504490696bSAlexander Motin  * ntb_db_event() - notify driver context of a doorbell event
514490696bSAlexander Motin  * @ntb:        NTB device context
524490696bSAlexander Motin  * @vector:     Interrupt vector number
534490696bSAlexander Motin  *
544490696bSAlexander Motin  * Notify the driver context of a doorbell event.  If hardware supports
554490696bSAlexander Motin  * multiple interrupt vectors for doorbells, the vector number indicates which
564490696bSAlexander Motin  * vector received the interrupt.  The vector number is relative to the first
574490696bSAlexander Motin  * vector used for doorbells, starting at zero, and must be less than
584490696bSAlexander Motin  * ntb_db_vector_count().  The driver may call ntb_db_read() to check which
594490696bSAlexander Motin  * doorbell bits need service, and ntb_db_vector_mask() to determine which of
604490696bSAlexander Motin  * those bits are associated with the vector number.
614490696bSAlexander Motin  */
624490696bSAlexander Motin void ntb_db_event(device_t ntb, uint32_t vec);
634490696bSAlexander Motin 
646683132dSAlexander Motin /**
656683132dSAlexander Motin  * ntb_port_number() - get the local port number
666683132dSAlexander Motin  * @ntb:        NTB device context.
676683132dSAlexander Motin  *
686683132dSAlexander Motin  * Hardware driver returns local port number in compliance with topology.
696683132dSAlexander Motin  *
706683132dSAlexander Motin  * Return: the local port number
716683132dSAlexander Motin  */
726683132dSAlexander Motin int ntb_port_number(device_t ntb);
736683132dSAlexander Motin 
746683132dSAlexander Motin /**
756683132dSAlexander Motin  * ntb_port_count() - get the number of peer device ports
766683132dSAlexander Motin  * @ntb:        NTB device context.
776683132dSAlexander Motin  *
786683132dSAlexander Motin  * By default hardware driver supports just one peer device.
796683132dSAlexander Motin  *
806683132dSAlexander Motin  * Return: the number of peer ports
816683132dSAlexander Motin  */
826683132dSAlexander Motin int ntb_peer_port_count(device_t ntb);
836683132dSAlexander Motin 
846683132dSAlexander Motin /**
856683132dSAlexander Motin  * ntb_peer_port_number() - get the peer port by given index
866683132dSAlexander Motin  * @ntb:        NTB device context.
876683132dSAlexander Motin  * @idx:        Peer port index (should be zero for now).
886683132dSAlexander Motin  *
896683132dSAlexander Motin  * By default hardware driver supports just one peer device, so this method
906683132dSAlexander Motin  * shall return the corresponding value.
916683132dSAlexander Motin  *
926683132dSAlexander Motin  * Return: the peer device port or an error number
936683132dSAlexander Motin  */
946683132dSAlexander Motin int ntb_peer_port_number(device_t ntb, int pidx);
956683132dSAlexander Motin 
966683132dSAlexander Motin /*
976683132dSAlexander Motin  * ntb_peer_port_idx() - get the peer device port index by given port
986683132dSAlexander Motin  *                       number
996683132dSAlexander Motin  * @ntb:        NTB device context.
1006683132dSAlexander Motin  * @port:       Peer port number
1016683132dSAlexander Motin  *
1026683132dSAlexander Motin  * By default hardware driver supports just one peer device, so given a
1036683132dSAlexander Motin  * valid peer port number, the return value shall be zero.
1046683132dSAlexander Motin  *
1056683132dSAlexander Motin  * Return: the peer port index or an error number
1066683132dSAlexander Motin  */
1076683132dSAlexander Motin int ntb_peer_port_idx(device_t ntb, int port);
1086683132dSAlexander Motin 
1094490696bSAlexander Motin /*
1104490696bSAlexander Motin  * ntb_link_is_up() - get the current ntb link state
1114490696bSAlexander Motin  * @ntb:        NTB device context
1124490696bSAlexander Motin  * @speed:      OUT - The link speed expressed as PCIe generation number
1134490696bSAlexander Motin  * @width:      OUT - The link width expressed as the number of PCIe lanes
1144490696bSAlexander Motin  *
1154490696bSAlexander Motin  * RETURNS: true or false based on the hardware link state
1164490696bSAlexander Motin  */
1174490696bSAlexander Motin bool ntb_link_is_up(device_t ntb, enum ntb_speed *speed, enum ntb_width *width);
1184490696bSAlexander Motin 
1194490696bSAlexander Motin /*
1204490696bSAlexander Motin  * ntb_link_enable() - enable the link on the secondary side of the ntb
1214490696bSAlexander Motin  * @ntb:        NTB device context
1224490696bSAlexander Motin  * @max_speed:  The maximum link speed expressed as PCIe generation number[0]
1234490696bSAlexander Motin  * @max_width:  The maximum link width expressed as the number of PCIe lanes[0]
1244490696bSAlexander Motin  *
1254490696bSAlexander Motin  * Enable the link on the secondary side of the ntb.  This can only be done
1264490696bSAlexander Motin  * from the primary side of the ntb in primary or b2b topology.  The ntb device
1274490696bSAlexander Motin  * should train the link to its maximum speed and width, or the requested speed
1284490696bSAlexander Motin  * and width, whichever is smaller, if supported.
1294490696bSAlexander Motin  *
1304490696bSAlexander Motin  * Return: Zero on success, otherwise an error number.
1314490696bSAlexander Motin  *
1324490696bSAlexander Motin  * [0]: Only NTB_SPEED_AUTO and NTB_WIDTH_AUTO are valid inputs; other speed
1334490696bSAlexander Motin  *      and width input will be ignored.
1344490696bSAlexander Motin  */
1354490696bSAlexander Motin int ntb_link_enable(device_t ntb, enum ntb_speed speed, enum ntb_width width);
1364490696bSAlexander Motin 
1374490696bSAlexander Motin /*
1384490696bSAlexander Motin  * ntb_link_disable() - disable the link on the secondary side of the ntb
1394490696bSAlexander Motin  * @ntb:        NTB device context
1404490696bSAlexander Motin  *
1414490696bSAlexander Motin  * Disable the link on the secondary side of the ntb.  This can only be done
1424490696bSAlexander Motin  * from the primary side of the ntb in primary or b2b topology.  The ntb device
1434490696bSAlexander Motin  * should disable the link.  Returning from this call must indicate that a
1444490696bSAlexander Motin  * barrier has passed, though with no more writes may pass in either direction
1454490696bSAlexander Motin  * across the link, except if this call returns an error number.
1464490696bSAlexander Motin  *
1474490696bSAlexander Motin  * Return: Zero on success, otherwise an error number.
1484490696bSAlexander Motin  */
1494490696bSAlexander Motin int ntb_link_disable(device_t ntb);
1504490696bSAlexander Motin 
1514490696bSAlexander Motin /*
1524490696bSAlexander Motin  * get enable status of the link on the secondary side of the ntb
1534490696bSAlexander Motin  */
1544490696bSAlexander Motin bool ntb_link_enabled(device_t ntb);
1554490696bSAlexander Motin 
1564490696bSAlexander Motin /*
1574490696bSAlexander Motin  * ntb_set_ctx() - associate a driver context with an ntb device
1584490696bSAlexander Motin  * @ntb:        NTB device context
1594490696bSAlexander Motin  * @ctx:        Driver context
1604490696bSAlexander Motin  * @ctx_ops:    Driver context operations
1614490696bSAlexander Motin  *
1624490696bSAlexander Motin  * Associate a driver context and operations with a ntb device.  The context is
1634490696bSAlexander Motin  * provided by the client driver, and the driver may associate a different
1644490696bSAlexander Motin  * context with each ntb device.
1654490696bSAlexander Motin  *
1664490696bSAlexander Motin  * Return: Zero if the context is associated, otherwise an error number.
1674490696bSAlexander Motin  */
1684490696bSAlexander Motin int ntb_set_ctx(device_t ntb, void *ctx, const struct ntb_ctx_ops *ctx_ops);
1694490696bSAlexander Motin 
1704490696bSAlexander Motin /*
1714490696bSAlexander Motin  * ntb_set_ctx() - get a driver context associated with an ntb device
1724490696bSAlexander Motin  * @ntb:        NTB device context
1734490696bSAlexander Motin  * @ctx_ops:    Driver context operations
1744490696bSAlexander Motin  *
1754490696bSAlexander Motin  * Get a driver context and operations associated with a ntb device.
1764490696bSAlexander Motin  */
1774490696bSAlexander Motin void * ntb_get_ctx(device_t ntb, const struct ntb_ctx_ops **ctx_ops);
1784490696bSAlexander Motin 
1794490696bSAlexander Motin /*
1804490696bSAlexander Motin  * ntb_clear_ctx() - disassociate any driver context from an ntb device
1814490696bSAlexander Motin  * @ntb:        NTB device context
1824490696bSAlexander Motin  *
1834490696bSAlexander Motin  * Clear any association that may exist between a driver context and the ntb
1844490696bSAlexander Motin  * device.
1854490696bSAlexander Motin  */
1864490696bSAlexander Motin void ntb_clear_ctx(device_t ntb);
1874490696bSAlexander Motin 
1884490696bSAlexander Motin /*
1894490696bSAlexander Motin  * ntb_mw_count() - Get the number of memory windows available for KPI
1904490696bSAlexander Motin  * consumers.
1914490696bSAlexander Motin  *
1924490696bSAlexander Motin  * (Excludes any MW wholly reserved for register access.)
1934490696bSAlexander Motin  */
1944490696bSAlexander Motin uint8_t ntb_mw_count(device_t ntb);
1954490696bSAlexander Motin 
1964490696bSAlexander Motin /*
1974490696bSAlexander Motin  * ntb_mw_get_range() - get the range of a memory window
1984490696bSAlexander Motin  * @ntb:        NTB device context
1994490696bSAlexander Motin  * @idx:        Memory window number
2004490696bSAlexander Motin  * @base:       OUT - the base address for mapping the memory window
2014490696bSAlexander Motin  * @size:       OUT - the size for mapping the memory window
2024490696bSAlexander Motin  * @align:      OUT - the base alignment for translating the memory window
2034490696bSAlexander Motin  * @align_size: OUT - the size alignment for translating the memory window
2044490696bSAlexander Motin  *
2054490696bSAlexander Motin  * Get the range of a memory window.  NULL may be given for any output
2064490696bSAlexander Motin  * parameter if the value is not needed.  The base and size may be used for
2074490696bSAlexander Motin  * mapping the memory window, to access the peer memory.  The alignment and
2084490696bSAlexander Motin  * size may be used for translating the memory window, for the peer to access
2094490696bSAlexander Motin  * memory on the local system.
2104490696bSAlexander Motin  *
2114490696bSAlexander Motin  * Return: Zero on success, otherwise an error number.
2124490696bSAlexander Motin  */
2134490696bSAlexander Motin int ntb_mw_get_range(device_t ntb, unsigned mw_idx, vm_paddr_t *base,
2144490696bSAlexander Motin     caddr_t *vbase, size_t *size, size_t *align, size_t *align_size,
2154490696bSAlexander Motin     bus_addr_t *plimit);
2164490696bSAlexander Motin 
2174490696bSAlexander Motin /*
2184490696bSAlexander Motin  * ntb_mw_set_trans() - set the translation of a memory window
2194490696bSAlexander Motin  * @ntb:        NTB device context
2204490696bSAlexander Motin  * @idx:        Memory window number
2214490696bSAlexander Motin  * @addr:       The dma address local memory to expose to the peer
2224490696bSAlexander Motin  * @size:       The size of the local memory to expose to the peer
2234490696bSAlexander Motin  *
2244490696bSAlexander Motin  * Set the translation of a memory window.  The peer may access local memory
2254490696bSAlexander Motin  * through the window starting at the address, up to the size.  The address
2264490696bSAlexander Motin  * must be aligned to the alignment specified by ntb_mw_get_range().  The size
2274490696bSAlexander Motin  * must be aligned to the size alignment specified by ntb_mw_get_range().  The
2284490696bSAlexander Motin  * address must be below the plimit specified by ntb_mw_get_range() (i.e. for
2294490696bSAlexander Motin  * 32-bit BARs).
2304490696bSAlexander Motin  *
2314490696bSAlexander Motin  * Return: Zero on success, otherwise an error number.
2324490696bSAlexander Motin  */
2334490696bSAlexander Motin int ntb_mw_set_trans(device_t ntb, unsigned mw_idx, bus_addr_t addr,
2344490696bSAlexander Motin     size_t size);
2354490696bSAlexander Motin 
2364490696bSAlexander Motin /*
2374490696bSAlexander Motin  * ntb_mw_clear_trans() - clear the translation of a memory window
2384490696bSAlexander Motin  * @ntb:	NTB device context
2394490696bSAlexander Motin  * @idx:	Memory window number
2404490696bSAlexander Motin  *
2414490696bSAlexander Motin  * Clear the translation of a memory window.  The peer may no longer access
2424490696bSAlexander Motin  * local memory through the window.
2434490696bSAlexander Motin  *
2444490696bSAlexander Motin  * Return: Zero on success, otherwise an error number.
2454490696bSAlexander Motin  */
2464490696bSAlexander Motin int ntb_mw_clear_trans(device_t ntb, unsigned mw_idx);
2474490696bSAlexander Motin 
2484490696bSAlexander Motin /*
2494490696bSAlexander Motin  * ntb_mw_get_wc - Get the write-combine status of a memory window
2504490696bSAlexander Motin  *
2514490696bSAlexander Motin  * Returns:  Zero on success, setting *wc; otherwise an error number (e.g. if
2524490696bSAlexander Motin  * idx is an invalid memory window).
2534490696bSAlexander Motin  *
2544490696bSAlexander Motin  * Mode is a VM_MEMATTR_* type.
2554490696bSAlexander Motin  */
2564490696bSAlexander Motin int ntb_mw_get_wc(device_t ntb, unsigned mw_idx, vm_memattr_t *mode);
2574490696bSAlexander Motin 
2584490696bSAlexander Motin /*
2594490696bSAlexander Motin  * ntb_mw_set_wc - Set the write-combine status of a memory window
2604490696bSAlexander Motin  *
2614490696bSAlexander Motin  * If 'mode' matches the current status, this does nothing and succeeds.  Mode
2624490696bSAlexander Motin  * is a VM_MEMATTR_* type.
2634490696bSAlexander Motin  *
2644490696bSAlexander Motin  * Returns:  Zero on success, setting the caching attribute on the virtual
2654490696bSAlexander Motin  * mapping of the BAR; otherwise an error number (e.g. if idx is an invalid
2664490696bSAlexander Motin  * memory window, or if changing the caching attribute fails).
2674490696bSAlexander Motin  */
2684490696bSAlexander Motin int ntb_mw_set_wc(device_t ntb, unsigned mw_idx, vm_memattr_t mode);
2694490696bSAlexander Motin 
2704490696bSAlexander Motin /*
2714490696bSAlexander Motin  * ntb_spad_count() - get the total scratch regs usable
2724490696bSAlexander Motin  * @ntb: pointer to ntb_softc instance
2734490696bSAlexander Motin  *
2744490696bSAlexander Motin  * This function returns the max 32bit scratchpad registers usable by the
2754490696bSAlexander Motin  * upper layer.
2764490696bSAlexander Motin  *
2774490696bSAlexander Motin  * RETURNS: total number of scratch pad registers available
2784490696bSAlexander Motin  */
2794490696bSAlexander Motin uint8_t ntb_spad_count(device_t ntb);
2804490696bSAlexander Motin 
2814490696bSAlexander Motin /*
2823883c6fbSAlexander Motin  * ntb_spad_clear() - zero local scratch registers
2834490696bSAlexander Motin  * @ntb: pointer to ntb_softc instance
2844490696bSAlexander Motin  *
2854490696bSAlexander Motin  * This functions overwrites all local scratchpad registers with zeroes.
2864490696bSAlexander Motin  */
2874490696bSAlexander Motin void ntb_spad_clear(device_t ntb);
2884490696bSAlexander Motin 
2894490696bSAlexander Motin /*
2904490696bSAlexander Motin  * ntb_spad_write() - write to the secondary scratchpad register
2914490696bSAlexander Motin  * @ntb: pointer to ntb_softc instance
2924490696bSAlexander Motin  * @idx: index to the scratchpad register, 0 based
2934490696bSAlexander Motin  * @val: the data value to put into the register
2944490696bSAlexander Motin  *
2954490696bSAlexander Motin  * This function allows writing of a 32bit value to the indexed scratchpad
2964490696bSAlexander Motin  * register. The register resides on the secondary (external) side.
2974490696bSAlexander Motin  *
2984490696bSAlexander Motin  * RETURNS: An appropriate ERRNO error value on error, or zero for success.
2994490696bSAlexander Motin  */
3004490696bSAlexander Motin int ntb_spad_write(device_t ntb, unsigned int idx, uint32_t val);
3014490696bSAlexander Motin 
3024490696bSAlexander Motin /*
3034490696bSAlexander Motin  * ntb_spad_read() - read from the primary scratchpad register
3044490696bSAlexander Motin  * @ntb: pointer to ntb_softc instance
3054490696bSAlexander Motin  * @idx: index to scratchpad register, 0 based
3064490696bSAlexander Motin  * @val: pointer to 32bit integer for storing the register value
3074490696bSAlexander Motin  *
3084490696bSAlexander Motin  * This function allows reading of the 32bit scratchpad register on
3094490696bSAlexander Motin  * the primary (internal) side.
3104490696bSAlexander Motin  *
3114490696bSAlexander Motin  * RETURNS: An appropriate ERRNO error value on error, or zero for success.
3124490696bSAlexander Motin  */
3134490696bSAlexander Motin int ntb_spad_read(device_t ntb, unsigned int idx, uint32_t *val);
3144490696bSAlexander Motin 
3154490696bSAlexander Motin /*
3164490696bSAlexander Motin  * ntb_peer_spad_write() - write to the secondary scratchpad register
3174490696bSAlexander Motin  * @ntb: pointer to ntb_softc instance
3184490696bSAlexander Motin  * @idx: index to the scratchpad register, 0 based
3194490696bSAlexander Motin  * @val: the data value to put into the register
3204490696bSAlexander Motin  *
3214490696bSAlexander Motin  * This function allows writing of a 32bit value to the indexed scratchpad
3224490696bSAlexander Motin  * register. The register resides on the secondary (external) side.
3234490696bSAlexander Motin  *
3244490696bSAlexander Motin  * RETURNS: An appropriate ERRNO error value on error, or zero for success.
3254490696bSAlexander Motin  */
3264490696bSAlexander Motin int ntb_peer_spad_write(device_t ntb, unsigned int idx, uint32_t val);
3274490696bSAlexander Motin 
3284490696bSAlexander Motin /*
3294490696bSAlexander Motin  * ntb_peer_spad_read() - read from the primary scratchpad register
3304490696bSAlexander Motin  * @ntb: pointer to ntb_softc instance
3314490696bSAlexander Motin  * @idx: index to scratchpad register, 0 based
3324490696bSAlexander Motin  * @val: pointer to 32bit integer for storing the register value
3334490696bSAlexander Motin  *
3344490696bSAlexander Motin  * This function allows reading of the 32bit scratchpad register on
3354490696bSAlexander Motin  * the primary (internal) side.
3364490696bSAlexander Motin  *
3374490696bSAlexander Motin  * RETURNS: An appropriate ERRNO error value on error, or zero for success.
3384490696bSAlexander Motin  */
3394490696bSAlexander Motin int ntb_peer_spad_read(device_t ntb, unsigned int idx, uint32_t *val);
3404490696bSAlexander Motin 
3414490696bSAlexander Motin /*
3424490696bSAlexander Motin  * ntb_db_valid_mask() - get a mask of doorbell bits supported by the ntb
3434490696bSAlexander Motin  * @ntb:	NTB device context
3444490696bSAlexander Motin  *
3454490696bSAlexander Motin  * Hardware may support different number or arrangement of doorbell bits.
3464490696bSAlexander Motin  *
3474490696bSAlexander Motin  * Return: A mask of doorbell bits supported by the ntb.
3484490696bSAlexander Motin  */
3494490696bSAlexander Motin uint64_t ntb_db_valid_mask(device_t ntb);
3504490696bSAlexander Motin 
3514490696bSAlexander Motin /*
3524490696bSAlexander Motin  * ntb_db_vector_count() - get the number of doorbell interrupt vectors
3534490696bSAlexander Motin  * @ntb:	NTB device context.
3544490696bSAlexander Motin  *
3554490696bSAlexander Motin  * Hardware may support different number of interrupt vectors.
3564490696bSAlexander Motin  *
3574490696bSAlexander Motin  * Return: The number of doorbell interrupt vectors.
3584490696bSAlexander Motin  */
3594490696bSAlexander Motin int ntb_db_vector_count(device_t ntb);
3604490696bSAlexander Motin 
3614490696bSAlexander Motin /*
3624490696bSAlexander Motin  * ntb_db_vector_mask() - get a mask of doorbell bits serviced by a vector
3634490696bSAlexander Motin  * @ntb:	NTB device context
3644490696bSAlexander Motin  * @vector:	Doorbell vector number
3654490696bSAlexander Motin  *
3664490696bSAlexander Motin  * Each interrupt vector may have a different number or arrangement of bits.
3674490696bSAlexander Motin  *
3684490696bSAlexander Motin  * Return: A mask of doorbell bits serviced by a vector.
3694490696bSAlexander Motin  */
3704490696bSAlexander Motin uint64_t ntb_db_vector_mask(device_t ntb, uint32_t vector);
3714490696bSAlexander Motin 
3724490696bSAlexander Motin /*
3734490696bSAlexander Motin  * ntb_peer_db_addr() - address and size of the peer doorbell register
3744490696bSAlexander Motin  * @ntb:	NTB device context.
3754490696bSAlexander Motin  * @db_addr:	OUT - The address of the peer doorbell register.
3764490696bSAlexander Motin  * @db_size:	OUT - The number of bytes to write the peer doorbell register.
3774490696bSAlexander Motin  *
3784490696bSAlexander Motin  * Return the address of the peer doorbell register.  This may be used, for
3794490696bSAlexander Motin  * example, by drivers that offload memory copy operations to a dma engine.
3804490696bSAlexander Motin  * The drivers may wish to ring the peer doorbell at the completion of memory
3814490696bSAlexander Motin  * copy operations.  For efficiency, and to simplify ordering of operations
3824490696bSAlexander Motin  * between the dma memory copies and the ringing doorbell, the driver may
3834490696bSAlexander Motin  * append one additional dma memory copy with the doorbell register as the
3844490696bSAlexander Motin  * destination, after the memory copy operations.
3854490696bSAlexander Motin  *
3864490696bSAlexander Motin  * Return: Zero on success, otherwise an error number.
3874490696bSAlexander Motin  *
3884490696bSAlexander Motin  * Note that writing the peer doorbell via a memory window will *not* generate
3894490696bSAlexander Motin  * an interrupt on the remote host; that must be done separately.
3904490696bSAlexander Motin  */
3914490696bSAlexander Motin int ntb_peer_db_addr(device_t ntb, bus_addr_t *db_addr, vm_size_t *db_size);
3924490696bSAlexander Motin 
3934490696bSAlexander Motin /*
3944490696bSAlexander Motin  * ntb_db_clear() - clear bits in the local doorbell register
3954490696bSAlexander Motin  * @ntb:	NTB device context.
3964490696bSAlexander Motin  * @db_bits:	Doorbell bits to clear.
3974490696bSAlexander Motin  *
3984490696bSAlexander Motin  * Clear bits in the local doorbell register, arming the bits for the next
3994490696bSAlexander Motin  * doorbell.
4004490696bSAlexander Motin  *
4014490696bSAlexander Motin  * Return: Zero on success, otherwise an error number.
4024490696bSAlexander Motin  */
4034490696bSAlexander Motin void ntb_db_clear(device_t ntb, uint64_t bits);
4044490696bSAlexander Motin 
4054490696bSAlexander Motin /*
4064490696bSAlexander Motin  * ntb_db_clear_mask() - clear bits in the local doorbell mask
4074490696bSAlexander Motin  * @ntb:	NTB device context.
4084490696bSAlexander Motin  * @db_bits:	Doorbell bits to clear.
4094490696bSAlexander Motin  *
4104490696bSAlexander Motin  * Clear bits in the local doorbell mask register, allowing doorbell interrupts
4114490696bSAlexander Motin  * from being generated for those doorbell bits.  If a doorbell bit is already
4124490696bSAlexander Motin  * set at the time the mask is cleared, and the corresponding mask bit is
4134490696bSAlexander Motin  * changed from set to clear, then the ntb driver must ensure that
4144490696bSAlexander Motin  * ntb_db_event() is called.  If the hardware does not generate the interrupt
4154490696bSAlexander Motin  * on clearing the mask bit, then the driver must call ntb_db_event() anyway.
4164490696bSAlexander Motin  *
4174490696bSAlexander Motin  * Return: Zero on success, otherwise an error number.
4184490696bSAlexander Motin  */
4194490696bSAlexander Motin void ntb_db_clear_mask(device_t ntb, uint64_t bits);
4204490696bSAlexander Motin 
4214490696bSAlexander Motin /*
4224490696bSAlexander Motin  * ntb_db_read() - read the local doorbell register
4234490696bSAlexander Motin  * @ntb:	NTB device context.
4244490696bSAlexander Motin  *
4254490696bSAlexander Motin  * Read the local doorbell register, and return the bits that are set.
4264490696bSAlexander Motin  *
4274490696bSAlexander Motin  * Return: The bits currently set in the local doorbell register.
4284490696bSAlexander Motin  */
4294490696bSAlexander Motin uint64_t ntb_db_read(device_t ntb);
4304490696bSAlexander Motin 
4314490696bSAlexander Motin /*
4324490696bSAlexander Motin  * ntb_db_set_mask() - set bits in the local doorbell mask
4334490696bSAlexander Motin  * @ntb:	NTB device context.
4344490696bSAlexander Motin  * @db_bits:	Doorbell mask bits to set.
4354490696bSAlexander Motin  *
4364490696bSAlexander Motin  * Set bits in the local doorbell mask register, preventing doorbell interrupts
4374490696bSAlexander Motin  * from being generated for those doorbell bits.  Bits that were already set
4384490696bSAlexander Motin  * must remain set.
4394490696bSAlexander Motin  *
4404490696bSAlexander Motin  * Return: Zero on success, otherwise an error number.
4414490696bSAlexander Motin  */
4424490696bSAlexander Motin void ntb_db_set_mask(device_t ntb, uint64_t bits);
4434490696bSAlexander Motin 
4444490696bSAlexander Motin /*
4454490696bSAlexander Motin  * ntb_peer_db_set() - Set the doorbell on the secondary/external side
4464490696bSAlexander Motin  * @ntb: pointer to ntb_softc instance
4474490696bSAlexander Motin  * @bit: doorbell bits to ring
4484490696bSAlexander Motin  *
4494490696bSAlexander Motin  * This function allows triggering of a doorbell on the secondary/external
4504490696bSAlexander Motin  * side that will initiate an interrupt on the remote host
4514490696bSAlexander Motin  */
4524490696bSAlexander Motin void ntb_peer_db_set(device_t ntb, uint64_t bits);
4534490696bSAlexander Motin 
4549a5325c2SAlexander Motin #endif /* _NTB_H_ */
455