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