]>
git.proxmox.com Git - mirror_ubuntu-eoan-kernel.git/blob - include/linux/ntb.h
2 * This file is provided under a dual BSD/GPLv2 license. When using or
3 * redistributing this file, you may do so under either license.
7 * Copyright (C) 2015 EMC Corporation. All Rights Reserved.
8 * Copyright (C) 2016 T-Platforms. All Rights Reserved.
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of version 2 of the GNU General Public License as
12 * published by the Free Software Foundation.
14 * This program is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
21 * Copyright (C) 2015 EMC Corporation. All Rights Reserved.
22 * Copyright (C) 2016 T-Platforms. All Rights Reserved.
24 * Redistribution and use in source and binary forms, with or without
25 * modification, are permitted provided that the following conditions
28 * * Redistributions of source code must retain the above copyright
29 * notice, this list of conditions and the following disclaimer.
30 * * Redistributions in binary form must reproduce the above copy
31 * notice, this list of conditions and the following disclaimer in
32 * the documentation and/or other materials provided with the
34 * * Neither the name of Intel Corporation nor the names of its
35 * contributors may be used to endorse or promote products derived
36 * from this software without specific prior written permission.
38 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
39 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
40 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
41 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
42 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
43 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
44 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
45 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
46 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
47 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
48 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
50 * PCIe NTB Linux driver
52 * Contact Information:
53 * Allen Hubbe <Allen.Hubbe@emc.com>
59 #include <linux/completion.h>
60 #include <linux/device.h>
67 * enum ntb_topo - NTB connection topology
68 * @NTB_TOPO_NONE: Topology is unknown or invalid.
69 * @NTB_TOPO_PRI: On primary side of local ntb.
70 * @NTB_TOPO_SEC: On secondary side of remote ntb.
71 * @NTB_TOPO_B2B_USD: On primary side of local ntb upstream of remote ntb.
72 * @NTB_TOPO_B2B_DSD: On primary side of local ntb downstream of remote ntb.
73 * @NTB_TOPO_SWITCH: Connected via a switch which supports ntb.
74 * @NTB_TOPO_CROSSLINK: Connected via two symmetric switchecs
86 static inline int ntb_topo_is_b2b(enum ntb_topo topo
)
89 case NTB_TOPO_B2B_USD
:
90 case NTB_TOPO_B2B_DSD
:
96 static inline char *ntb_topo_string(enum ntb_topo topo
)
99 case NTB_TOPO_NONE
: return "NTB_TOPO_NONE";
100 case NTB_TOPO_PRI
: return "NTB_TOPO_PRI";
101 case NTB_TOPO_SEC
: return "NTB_TOPO_SEC";
102 case NTB_TOPO_B2B_USD
: return "NTB_TOPO_B2B_USD";
103 case NTB_TOPO_B2B_DSD
: return "NTB_TOPO_B2B_DSD";
104 case NTB_TOPO_SWITCH
: return "NTB_TOPO_SWITCH";
105 case NTB_TOPO_CROSSLINK
: return "NTB_TOPO_CROSSLINK";
107 return "NTB_TOPO_INVALID";
111 * enum ntb_speed - NTB link training speed
112 * @NTB_SPEED_AUTO: Request the max supported speed.
113 * @NTB_SPEED_NONE: Link is not trained to any speed.
114 * @NTB_SPEED_GEN1: Link is trained to gen1 speed.
115 * @NTB_SPEED_GEN2: Link is trained to gen2 speed.
116 * @NTB_SPEED_GEN3: Link is trained to gen3 speed.
117 * @NTB_SPEED_GEN4: Link is trained to gen4 speed.
129 * enum ntb_width - NTB link training width
130 * @NTB_WIDTH_AUTO: Request the max supported width.
131 * @NTB_WIDTH_NONE: Link is not trained to any width.
132 * @NTB_WIDTH_1: Link is trained to 1 lane width.
133 * @NTB_WIDTH_2: Link is trained to 2 lane width.
134 * @NTB_WIDTH_4: Link is trained to 4 lane width.
135 * @NTB_WIDTH_8: Link is trained to 8 lane width.
136 * @NTB_WIDTH_12: Link is trained to 12 lane width.
137 * @NTB_WIDTH_16: Link is trained to 16 lane width.
138 * @NTB_WIDTH_32: Link is trained to 32 lane width.
153 * enum ntb_default_port - NTB default port number
154 * @NTB_PORT_PRI_USD: Default port of the NTB_TOPO_PRI/NTB_TOPO_B2B_USD
156 * @NTB_PORT_SEC_DSD: Default port of the NTB_TOPO_SEC/NTB_TOPO_B2B_DSD
159 enum ntb_default_port
{
163 #define NTB_DEF_PEER_CNT (1)
164 #define NTB_DEF_PEER_IDX (0)
167 * struct ntb_client_ops - ntb client operations
168 * @probe: Notify client of a new device.
169 * @remove: Notify client to remove a device.
171 struct ntb_client_ops
{
172 int (*probe
)(struct ntb_client
*client
, struct ntb_dev
*ntb
);
173 void (*remove
)(struct ntb_client
*client
, struct ntb_dev
*ntb
);
176 static inline int ntb_client_ops_is_valid(const struct ntb_client_ops
*ops
)
178 /* commented callbacks are not required: */
186 * struct ntb_ctx_ops - ntb driver context operations
187 * @link_event: See ntb_link_event().
188 * @db_event: See ntb_db_event().
189 * @msg_event: See ntb_msg_event().
192 void (*link_event
)(void *ctx
);
193 void (*db_event
)(void *ctx
, int db_vector
);
194 void (*msg_event
)(void *ctx
);
197 static inline int ntb_ctx_ops_is_valid(const struct ntb_ctx_ops
*ops
)
199 /* commented callbacks are not required: */
201 /* ops->link_event && */
202 /* ops->db_event && */
203 /* ops->msg_event && */
208 * struct ntb_ctx_ops - ntb device operations
209 * @port_number: See ntb_port_number().
210 * @peer_port_count: See ntb_peer_port_count().
211 * @peer_port_number: See ntb_peer_port_number().
212 * @peer_port_idx: See ntb_peer_port_idx().
213 * @link_is_up: See ntb_link_is_up().
214 * @link_enable: See ntb_link_enable().
215 * @link_disable: See ntb_link_disable().
216 * @mw_count: See ntb_mw_count().
217 * @mw_get_align: See ntb_mw_get_align().
218 * @mw_set_trans: See ntb_mw_set_trans().
219 * @mw_clear_trans: See ntb_mw_clear_trans().
220 * @peer_mw_count: See ntb_peer_mw_count().
221 * @peer_mw_get_addr: See ntb_peer_mw_get_addr().
222 * @peer_mw_set_trans: See ntb_peer_mw_set_trans().
223 * @peer_mw_clear_trans:See ntb_peer_mw_clear_trans().
224 * @db_is_unsafe: See ntb_db_is_unsafe().
225 * @db_valid_mask: See ntb_db_valid_mask().
226 * @db_vector_count: See ntb_db_vector_count().
227 * @db_vector_mask: See ntb_db_vector_mask().
228 * @db_read: See ntb_db_read().
229 * @db_set: See ntb_db_set().
230 * @db_clear: See ntb_db_clear().
231 * @db_read_mask: See ntb_db_read_mask().
232 * @db_set_mask: See ntb_db_set_mask().
233 * @db_clear_mask: See ntb_db_clear_mask().
234 * @peer_db_addr: See ntb_peer_db_addr().
235 * @peer_db_read: See ntb_peer_db_read().
236 * @peer_db_set: See ntb_peer_db_set().
237 * @peer_db_clear: See ntb_peer_db_clear().
238 * @peer_db_read_mask: See ntb_peer_db_read_mask().
239 * @peer_db_set_mask: See ntb_peer_db_set_mask().
240 * @peer_db_clear_mask: See ntb_peer_db_clear_mask().
241 * @spad_is_unsafe: See ntb_spad_is_unsafe().
242 * @spad_count: See ntb_spad_count().
243 * @spad_read: See ntb_spad_read().
244 * @spad_write: See ntb_spad_write().
245 * @peer_spad_addr: See ntb_peer_spad_addr().
246 * @peer_spad_read: See ntb_peer_spad_read().
247 * @peer_spad_write: See ntb_peer_spad_write().
248 * @msg_count: See ntb_msg_count().
249 * @msg_inbits: See ntb_msg_inbits().
250 * @msg_outbits: See ntb_msg_outbits().
251 * @msg_read_sts: See ntb_msg_read_sts().
252 * @msg_clear_sts: See ntb_msg_clear_sts().
253 * @msg_set_mask: See ntb_msg_set_mask().
254 * @msg_clear_mask: See ntb_msg_clear_mask().
255 * @msg_read: See ntb_msg_read().
256 * @peer_msg_write: See ntb_peer_msg_write().
259 int (*port_number
)(struct ntb_dev
*ntb
);
260 int (*peer_port_count
)(struct ntb_dev
*ntb
);
261 int (*peer_port_number
)(struct ntb_dev
*ntb
, int pidx
);
262 int (*peer_port_idx
)(struct ntb_dev
*ntb
, int port
);
264 u64 (*link_is_up
)(struct ntb_dev
*ntb
,
265 enum ntb_speed
*speed
, enum ntb_width
*width
);
266 int (*link_enable
)(struct ntb_dev
*ntb
,
267 enum ntb_speed max_speed
, enum ntb_width max_width
);
268 int (*link_disable
)(struct ntb_dev
*ntb
);
270 int (*mw_count
)(struct ntb_dev
*ntb
, int pidx
);
271 int (*mw_get_align
)(struct ntb_dev
*ntb
, int pidx
, int widx
,
272 resource_size_t
*addr_align
,
273 resource_size_t
*size_align
,
274 resource_size_t
*size_max
);
275 int (*mw_set_trans
)(struct ntb_dev
*ntb
, int pidx
, int widx
,
276 dma_addr_t addr
, resource_size_t size
);
277 int (*mw_clear_trans
)(struct ntb_dev
*ntb
, int pidx
, int widx
);
278 int (*peer_mw_count
)(struct ntb_dev
*ntb
);
279 int (*peer_mw_get_addr
)(struct ntb_dev
*ntb
, int widx
,
280 phys_addr_t
*base
, resource_size_t
*size
);
281 int (*peer_mw_set_trans
)(struct ntb_dev
*ntb
, int pidx
, int widx
,
282 u64 addr
, resource_size_t size
);
283 int (*peer_mw_clear_trans
)(struct ntb_dev
*ntb
, int pidx
, int widx
);
285 int (*db_is_unsafe
)(struct ntb_dev
*ntb
);
286 u64 (*db_valid_mask
)(struct ntb_dev
*ntb
);
287 int (*db_vector_count
)(struct ntb_dev
*ntb
);
288 u64 (*db_vector_mask
)(struct ntb_dev
*ntb
, int db_vector
);
290 u64 (*db_read
)(struct ntb_dev
*ntb
);
291 int (*db_set
)(struct ntb_dev
*ntb
, u64 db_bits
);
292 int (*db_clear
)(struct ntb_dev
*ntb
, u64 db_bits
);
294 u64 (*db_read_mask
)(struct ntb_dev
*ntb
);
295 int (*db_set_mask
)(struct ntb_dev
*ntb
, u64 db_bits
);
296 int (*db_clear_mask
)(struct ntb_dev
*ntb
, u64 db_bits
);
298 int (*peer_db_addr
)(struct ntb_dev
*ntb
,
299 phys_addr_t
*db_addr
, resource_size_t
*db_size
,
300 u64
*db_data
, int db_bit
);
301 u64 (*peer_db_read
)(struct ntb_dev
*ntb
);
302 int (*peer_db_set
)(struct ntb_dev
*ntb
, u64 db_bits
);
303 int (*peer_db_clear
)(struct ntb_dev
*ntb
, u64 db_bits
);
305 u64 (*peer_db_read_mask
)(struct ntb_dev
*ntb
);
306 int (*peer_db_set_mask
)(struct ntb_dev
*ntb
, u64 db_bits
);
307 int (*peer_db_clear_mask
)(struct ntb_dev
*ntb
, u64 db_bits
);
309 int (*spad_is_unsafe
)(struct ntb_dev
*ntb
);
310 int (*spad_count
)(struct ntb_dev
*ntb
);
312 u32 (*spad_read
)(struct ntb_dev
*ntb
, int sidx
);
313 int (*spad_write
)(struct ntb_dev
*ntb
, int sidx
, u32 val
);
315 int (*peer_spad_addr
)(struct ntb_dev
*ntb
, int pidx
, int sidx
,
316 phys_addr_t
*spad_addr
);
317 u32 (*peer_spad_read
)(struct ntb_dev
*ntb
, int pidx
, int sidx
);
318 int (*peer_spad_write
)(struct ntb_dev
*ntb
, int pidx
, int sidx
,
321 int (*msg_count
)(struct ntb_dev
*ntb
);
322 u64 (*msg_inbits
)(struct ntb_dev
*ntb
);
323 u64 (*msg_outbits
)(struct ntb_dev
*ntb
);
324 u64 (*msg_read_sts
)(struct ntb_dev
*ntb
);
325 int (*msg_clear_sts
)(struct ntb_dev
*ntb
, u64 sts_bits
);
326 int (*msg_set_mask
)(struct ntb_dev
*ntb
, u64 mask_bits
);
327 int (*msg_clear_mask
)(struct ntb_dev
*ntb
, u64 mask_bits
);
328 u32 (*msg_read
)(struct ntb_dev
*ntb
, int *pidx
, int midx
);
329 int (*peer_msg_write
)(struct ntb_dev
*ntb
, int pidx
, int midx
, u32 msg
);
332 static inline int ntb_dev_ops_is_valid(const struct ntb_dev_ops
*ops
)
334 /* commented callbacks are not required: */
336 /* Port operations are required for multiport devices */
337 !ops
->peer_port_count
== !ops
->port_number
&&
338 !ops
->peer_port_number
== !ops
->port_number
&&
339 !ops
->peer_port_idx
== !ops
->port_number
&&
341 /* Link operations are required */
346 /* One or both MW interfaces should be developed */
349 (ops
->mw_set_trans
||
350 ops
->peer_mw_set_trans
) &&
351 /* ops->mw_clear_trans && */
352 ops
->peer_mw_count
&&
353 ops
->peer_mw_get_addr
&&
354 /* ops->peer_mw_clear_trans && */
356 /* Doorbell operations are mostly required */
357 /* ops->db_is_unsafe && */
358 ops
->db_valid_mask
&&
359 /* both set, or both unset */
360 (!ops
->db_vector_count
== !ops
->db_vector_mask
) &&
364 /* ops->db_read_mask && */
366 ops
->db_clear_mask
&&
367 /* ops->peer_db_addr && */
368 /* ops->peer_db_read && */
370 /* ops->peer_db_clear && */
371 /* ops->peer_db_read_mask && */
372 /* ops->peer_db_set_mask && */
373 /* ops->peer_db_clear_mask && */
375 /* Scrachpads interface is optional */
376 /* !ops->spad_is_unsafe == !ops->spad_count && */
377 !ops
->spad_read
== !ops
->spad_count
&&
378 !ops
->spad_write
== !ops
->spad_count
&&
379 /* !ops->peer_spad_addr == !ops->spad_count && */
380 /* !ops->peer_spad_read == !ops->spad_count && */
381 !ops
->peer_spad_write
== !ops
->spad_count
&&
383 /* Messaging interface is optional */
384 !ops
->msg_inbits
== !ops
->msg_count
&&
385 !ops
->msg_outbits
== !ops
->msg_count
&&
386 !ops
->msg_read_sts
== !ops
->msg_count
&&
387 !ops
->msg_clear_sts
== !ops
->msg_count
&&
388 /* !ops->msg_set_mask == !ops->msg_count && */
389 /* !ops->msg_clear_mask == !ops->msg_count && */
390 !ops
->msg_read
== !ops
->msg_count
&&
391 !ops
->peer_msg_write
== !ops
->msg_count
&&
396 * struct ntb_client - client interested in ntb devices
397 * @drv: Linux driver object.
398 * @ops: See &ntb_client_ops.
401 struct device_driver drv
;
402 const struct ntb_client_ops ops
;
404 #define drv_ntb_client(__drv) container_of((__drv), struct ntb_client, drv)
407 * struct ntb_device - ntb device
408 * @dev: Linux device object.
409 * @pdev: PCI device entry of the ntb.
410 * @topo: Detected topology of the ntb.
411 * @ops: See &ntb_dev_ops.
412 * @ctx: See &ntb_ctx_ops.
413 * @ctx_ops: See &ntb_ctx_ops.
417 struct pci_dev
*pdev
;
419 const struct ntb_dev_ops
*ops
;
421 const struct ntb_ctx_ops
*ctx_ops
;
425 /* synchronize setting, clearing, and calling ctx_ops */
427 /* block unregister until device is fully released */
428 struct completion released
;
430 #define dev_ntb(__dev) container_of((__dev), struct ntb_dev, dev)
433 * ntb_register_client() - register a client for interest in ntb devices
434 * @client: Client context.
436 * The client will be added to the list of clients interested in ntb devices.
437 * The client will be notified of any ntb devices that are not already
438 * associated with a client, or if ntb devices are registered later.
440 * Return: Zero if the client is registered, otherwise an error number.
442 #define ntb_register_client(client) \
443 __ntb_register_client((client), THIS_MODULE, KBUILD_MODNAME)
445 int __ntb_register_client(struct ntb_client
*client
, struct module
*mod
,
446 const char *mod_name
);
449 * ntb_unregister_client() - unregister a client for interest in ntb devices
450 * @client: Client context.
452 * The client will be removed from the list of clients interested in ntb
453 * devices. If any ntb devices are associated with the client, the client will
454 * be notified to remove those devices.
456 void ntb_unregister_client(struct ntb_client
*client
);
458 #define module_ntb_client(__ntb_client) \
459 module_driver(__ntb_client, ntb_register_client, \
460 ntb_unregister_client)
463 * ntb_register_device() - register a ntb device
464 * @ntb: NTB device context.
466 * The device will be added to the list of ntb devices. If any clients are
467 * interested in ntb devices, each client will be notified of the ntb device,
468 * until at most one client accepts the device.
470 * Return: Zero if the device is registered, otherwise an error number.
472 int ntb_register_device(struct ntb_dev
*ntb
);
475 * ntb_register_device() - unregister a ntb device
476 * @ntb: NTB device context.
478 * The device will be removed from the list of ntb devices. If the ntb device
479 * is associated with a client, the client will be notified to remove the
482 void ntb_unregister_device(struct ntb_dev
*ntb
);
485 * ntb_set_ctx() - associate a driver context with an ntb device
486 * @ntb: NTB device context.
487 * @ctx: Driver context.
488 * @ctx_ops: Driver context operations.
490 * Associate a driver context and operations with a ntb device. The context is
491 * provided by the client driver, and the driver may associate a different
492 * context with each ntb device.
494 * Return: Zero if the context is associated, otherwise an error number.
496 int ntb_set_ctx(struct ntb_dev
*ntb
, void *ctx
,
497 const struct ntb_ctx_ops
*ctx_ops
);
500 * ntb_clear_ctx() - disassociate any driver context from an ntb device
501 * @ntb: NTB device context.
503 * Clear any association that may exist between a driver context and the ntb
506 void ntb_clear_ctx(struct ntb_dev
*ntb
);
509 * ntb_link_event() - notify driver context of a change in link status
510 * @ntb: NTB device context.
512 * Notify the driver context that the link status may have changed. The driver
513 * should call ntb_link_is_up() to get the current status.
515 void ntb_link_event(struct ntb_dev
*ntb
);
518 * ntb_db_event() - notify driver context of a doorbell event
519 * @ntb: NTB device context.
520 * @vector: Interrupt vector number.
522 * Notify the driver context of a doorbell event. If hardware supports
523 * multiple interrupt vectors for doorbells, the vector number indicates which
524 * vector received the interrupt. The vector number is relative to the first
525 * vector used for doorbells, starting at zero, and must be less than
526 * ntb_db_vector_count(). The driver may call ntb_db_read() to check which
527 * doorbell bits need service, and ntb_db_vector_mask() to determine which of
528 * those bits are associated with the vector number.
530 void ntb_db_event(struct ntb_dev
*ntb
, int vector
);
533 * ntb_msg_event() - notify driver context of a message event
534 * @ntb: NTB device context.
536 * Notify the driver context of a message event. If hardware supports
537 * message registers, this event indicates, that a new message arrived in
538 * some incoming message register or last sent message couldn't be delivered.
539 * The events can be masked/unmasked by the methods ntb_msg_set_mask() and
540 * ntb_msg_clear_mask().
542 void ntb_msg_event(struct ntb_dev
*ntb
);
545 * ntb_default_port_number() - get the default local port number
546 * @ntb: NTB device context.
548 * If hardware driver doesn't specify port_number() callback method, the NTB
549 * is considered with just two ports. So this method returns default local
550 * port number in compliance with topology.
552 * NOTE Don't call this method directly. The ntb_port_number() function should
555 * Return: the default local port number
557 int ntb_default_port_number(struct ntb_dev
*ntb
);
560 * ntb_default_port_count() - get the default number of peer device ports
561 * @ntb: NTB device context.
563 * By default hardware driver supports just one peer device.
565 * NOTE Don't call this method directly. The ntb_peer_port_count() function
566 * should be used instead.
568 * Return: the default number of peer ports
570 int ntb_default_peer_port_count(struct ntb_dev
*ntb
);
573 * ntb_default_peer_port_number() - get the default peer port by given index
574 * @ntb: NTB device context.
575 * @idx: Peer port index (should not differ from zero).
577 * By default hardware driver supports just one peer device, so this method
578 * shall return the corresponding value from enum ntb_default_port.
580 * NOTE Don't call this method directly. The ntb_peer_port_number() function
581 * should be used instead.
583 * Return: the peer device port or negative value indicating an error
585 int ntb_default_peer_port_number(struct ntb_dev
*ntb
, int pidx
);
588 * ntb_default_peer_port_idx() - get the default peer device port index by
590 * @ntb: NTB device context.
591 * @port: Peer port number (should be one of enum ntb_default_port).
593 * By default hardware driver supports just one peer device, so while
594 * specified port-argument indicates peer port from enum ntb_default_port,
595 * the return value shall be zero.
597 * NOTE Don't call this method directly. The ntb_peer_port_idx() function
598 * should be used instead.
600 * Return: the peer port index or negative value indicating an error
602 int ntb_default_peer_port_idx(struct ntb_dev
*ntb
, int port
);
605 * ntb_port_number() - get the local port number
606 * @ntb: NTB device context.
608 * Hardware must support at least simple two-ports ntb connection
610 * Return: the local port number
612 static inline int ntb_port_number(struct ntb_dev
*ntb
)
614 if (!ntb
->ops
->port_number
)
615 return ntb_default_port_number(ntb
);
617 return ntb
->ops
->port_number(ntb
);
621 * ntb_peer_port_count() - get the number of peer device ports
622 * @ntb: NTB device context.
624 * Hardware may support an access to memory of several remote domains
625 * over multi-port NTB devices. This method returns the number of peers,
626 * local device can have shared memory with.
628 * Return: the number of peer ports
630 static inline int ntb_peer_port_count(struct ntb_dev
*ntb
)
632 if (!ntb
->ops
->peer_port_count
)
633 return ntb_default_peer_port_count(ntb
);
635 return ntb
->ops
->peer_port_count(ntb
);
639 * ntb_peer_port_number() - get the peer port by given index
640 * @ntb: NTB device context.
641 * @pidx: Peer port index.
643 * Peer ports are continuously enumerated by NTB API logic, so this method
644 * lets to retrieve port real number by its index.
646 * Return: the peer device port or negative value indicating an error
648 static inline int ntb_peer_port_number(struct ntb_dev
*ntb
, int pidx
)
650 if (!ntb
->ops
->peer_port_number
)
651 return ntb_default_peer_port_number(ntb
, pidx
);
653 return ntb
->ops
->peer_port_number(ntb
, pidx
);
657 * ntb_peer_port_idx() - get the peer device port index by given port number
658 * @ntb: NTB device context.
659 * @port: Peer port number.
661 * Inverse operation of ntb_peer_port_number(), so one can get port index
662 * by specified port number.
664 * Return: the peer port index or negative value indicating an error
666 static inline int ntb_peer_port_idx(struct ntb_dev
*ntb
, int port
)
668 if (!ntb
->ops
->peer_port_idx
)
669 return ntb_default_peer_port_idx(ntb
, port
);
671 return ntb
->ops
->peer_port_idx(ntb
, port
);
675 * ntb_link_is_up() - get the current ntb link state
676 * @ntb: NTB device context.
677 * @speed: OUT - The link speed expressed as PCIe generation number.
678 * @width: OUT - The link width expressed as the number of PCIe lanes.
680 * Get the current state of the ntb link. It is recommended to query the link
681 * state once after every link event. It is safe to query the link state in
682 * the context of the link event callback.
684 * Return: bitfield of indexed ports link state: bit is set/cleared if the
685 * link is up/down respectively.
687 static inline u64
ntb_link_is_up(struct ntb_dev
*ntb
,
688 enum ntb_speed
*speed
, enum ntb_width
*width
)
690 return ntb
->ops
->link_is_up(ntb
, speed
, width
);
694 * ntb_link_enable() - enable the local port ntb connection
695 * @ntb: NTB device context.
696 * @max_speed: The maximum link speed expressed as PCIe generation number.
697 * @max_width: The maximum link width expressed as the number of PCIe lanes.
699 * Enable the NTB/PCIe link on the local or remote (for bridge-to-bridge
700 * topology) side of the bridge. If it's supported the ntb device should train
701 * the link to its maximum speed and width, or the requested speed and width,
702 * whichever is smaller. Some hardware doesn't support PCIe link training, so
703 * the last two arguments will be ignored then.
705 * Return: Zero on success, otherwise an error number.
707 static inline int ntb_link_enable(struct ntb_dev
*ntb
,
708 enum ntb_speed max_speed
,
709 enum ntb_width max_width
)
711 return ntb
->ops
->link_enable(ntb
, max_speed
, max_width
);
715 * ntb_link_disable() - disable the local port ntb connection
716 * @ntb: NTB device context.
718 * Disable the link on the local or remote (for b2b topology) of the ntb.
719 * The ntb device should disable the link. Returning from this call must
720 * indicate that a barrier has passed, though with no more writes may pass in
721 * either direction across the link, except if this call returns an error
724 * Return: Zero on success, otherwise an error number.
726 static inline int ntb_link_disable(struct ntb_dev
*ntb
)
728 return ntb
->ops
->link_disable(ntb
);
732 * ntb_mw_count() - get the number of inbound memory windows, which could
733 * be created for a specified peer device
734 * @ntb: NTB device context.
735 * @pidx: Port index of peer device.
737 * Hardware and topology may support a different number of memory windows.
738 * Moreover different peer devices can support different number of memory
739 * windows. Simply speaking this method returns the number of possible inbound
740 * memory windows to share with specified peer device. Note: this may return
741 * zero if the link is not up yet.
743 * Return: the number of memory windows.
745 static inline int ntb_mw_count(struct ntb_dev
*ntb
, int pidx
)
747 return ntb
->ops
->mw_count(ntb
, pidx
);
751 * ntb_mw_get_align() - get the restriction parameters of inbound memory window
752 * @ntb: NTB device context.
753 * @pidx: Port index of peer device.
754 * @widx: Memory window index.
755 * @addr_align: OUT - the base alignment for translating the memory window
756 * @size_align: OUT - the size alignment for translating the memory window
757 * @size_max: OUT - the maximum size of the memory window
759 * Get the alignments of an inbound memory window with specified index.
760 * NULL may be given for any output parameter if the value is not needed.
761 * The alignment and size parameters may be used for allocation of proper
762 * shared memory. Note: this must only be called when the link is up.
764 * Return: Zero on success, otherwise a negative error number.
766 static inline int ntb_mw_get_align(struct ntb_dev
*ntb
, int pidx
, int widx
,
767 resource_size_t
*addr_align
,
768 resource_size_t
*size_align
,
769 resource_size_t
*size_max
)
771 if (!(ntb_link_is_up(ntb
, NULL
, NULL
) & BIT_ULL(pidx
)))
774 return ntb
->ops
->mw_get_align(ntb
, pidx
, widx
, addr_align
, size_align
,
779 * ntb_mw_set_trans() - set the translation of an inbound memory window
780 * @ntb: NTB device context.
781 * @pidx: Port index of peer device.
782 * @widx: Memory window index.
783 * @addr: The dma address of local memory to expose to the peer.
784 * @size: The size of the local memory to expose to the peer.
786 * Set the translation of a memory window. The peer may access local memory
787 * through the window starting at the address, up to the size. The address
788 * and size must be aligned in compliance with restrictions of
789 * ntb_mw_get_align(). The region size should not exceed the size_max parameter
792 * This method may not be implemented due to the hardware specific memory
795 * Return: Zero on success, otherwise an error number.
797 static inline int ntb_mw_set_trans(struct ntb_dev
*ntb
, int pidx
, int widx
,
798 dma_addr_t addr
, resource_size_t size
)
800 if (!ntb
->ops
->mw_set_trans
)
803 return ntb
->ops
->mw_set_trans(ntb
, pidx
, widx
, addr
, size
);
807 * ntb_mw_clear_trans() - clear the translation address of an inbound memory
809 * @ntb: NTB device context.
810 * @pidx: Port index of peer device.
811 * @widx: Memory window index.
813 * Clear the translation of an inbound memory window. The peer may no longer
814 * access local memory through the window.
816 * Return: Zero on success, otherwise an error number.
818 static inline int ntb_mw_clear_trans(struct ntb_dev
*ntb
, int pidx
, int widx
)
820 if (!ntb
->ops
->mw_clear_trans
)
821 return ntb_mw_set_trans(ntb
, pidx
, widx
, 0, 0);
823 return ntb
->ops
->mw_clear_trans(ntb
, pidx
, widx
);
827 * ntb_peer_mw_count() - get the number of outbound memory windows, which could
828 * be mapped to access a shared memory
829 * @ntb: NTB device context.
831 * Hardware and topology may support a different number of memory windows.
832 * This method returns the number of outbound memory windows supported by
835 * Return: the number of memory windows.
837 static inline int ntb_peer_mw_count(struct ntb_dev
*ntb
)
839 return ntb
->ops
->peer_mw_count(ntb
);
843 * ntb_peer_mw_get_addr() - get map address of an outbound memory window
844 * @ntb: NTB device context.
845 * @widx: Memory window index (within ntb_peer_mw_count() return value).
846 * @base: OUT - the base address of mapping region.
847 * @size: OUT - the size of mapping region.
849 * Get base and size of memory region to map. NULL may be given for any output
850 * parameter if the value is not needed. The base and size may be used for
851 * mapping the memory window, to access the peer memory.
853 * Return: Zero on success, otherwise a negative error number.
855 static inline int ntb_peer_mw_get_addr(struct ntb_dev
*ntb
, int widx
,
856 phys_addr_t
*base
, resource_size_t
*size
)
858 return ntb
->ops
->peer_mw_get_addr(ntb
, widx
, base
, size
);
862 * ntb_peer_mw_set_trans() - set a translation address of a memory window
863 * retrieved from a peer device
864 * @ntb: NTB device context.
865 * @pidx: Port index of peer device the translation address received from.
866 * @widx: Memory window index.
867 * @addr: The dma address of the shared memory to access.
868 * @size: The size of the shared memory to access.
870 * Set the translation of an outbound memory window. The local device may
871 * access shared memory allocated by a peer device sent the address.
873 * This method may not be implemented due to the hardware specific memory
874 * windows interface, so a translation address can be only set on the side,
875 * where shared memory (inbound memory windows) is allocated.
877 * Return: Zero on success, otherwise an error number.
879 static inline int ntb_peer_mw_set_trans(struct ntb_dev
*ntb
, int pidx
, int widx
,
880 u64 addr
, resource_size_t size
)
882 if (!ntb
->ops
->peer_mw_set_trans
)
885 return ntb
->ops
->peer_mw_set_trans(ntb
, pidx
, widx
, addr
, size
);
889 * ntb_peer_mw_clear_trans() - clear the translation address of an outbound
891 * @ntb: NTB device context.
892 * @pidx: Port index of peer device.
893 * @widx: Memory window index.
895 * Clear the translation of a outbound memory window. The local device may no
896 * longer access a shared memory through the window.
898 * This method may not be implemented due to the hardware specific memory
901 * Return: Zero on success, otherwise an error number.
903 static inline int ntb_peer_mw_clear_trans(struct ntb_dev
*ntb
, int pidx
,
906 if (!ntb
->ops
->peer_mw_clear_trans
)
907 return ntb_peer_mw_set_trans(ntb
, pidx
, widx
, 0, 0);
909 return ntb
->ops
->peer_mw_clear_trans(ntb
, pidx
, widx
);
913 * ntb_db_is_unsafe() - check if it is safe to use hardware doorbell
914 * @ntb: NTB device context.
916 * It is possible for some ntb hardware to be affected by errata. Hardware
917 * drivers can advise clients to avoid using doorbells. Clients may ignore
918 * this advice, though caution is recommended.
920 * Return: Zero if it is safe to use doorbells, or One if it is not safe.
922 static inline int ntb_db_is_unsafe(struct ntb_dev
*ntb
)
924 if (!ntb
->ops
->db_is_unsafe
)
927 return ntb
->ops
->db_is_unsafe(ntb
);
931 * ntb_db_valid_mask() - get a mask of doorbell bits supported by the ntb
932 * @ntb: NTB device context.
934 * Hardware may support different number or arrangement of doorbell bits.
936 * Return: A mask of doorbell bits supported by the ntb.
938 static inline u64
ntb_db_valid_mask(struct ntb_dev
*ntb
)
940 return ntb
->ops
->db_valid_mask(ntb
);
944 * ntb_db_vector_count() - get the number of doorbell interrupt vectors
945 * @ntb: NTB device context.
947 * Hardware may support different number of interrupt vectors.
949 * Return: The number of doorbell interrupt vectors.
951 static inline int ntb_db_vector_count(struct ntb_dev
*ntb
)
953 if (!ntb
->ops
->db_vector_count
)
956 return ntb
->ops
->db_vector_count(ntb
);
960 * ntb_db_vector_mask() - get a mask of doorbell bits serviced by a vector
961 * @ntb: NTB device context.
962 * @vector: Doorbell vector number.
964 * Each interrupt vector may have a different number or arrangement of bits.
966 * Return: A mask of doorbell bits serviced by a vector.
968 static inline u64
ntb_db_vector_mask(struct ntb_dev
*ntb
, int vector
)
970 if (!ntb
->ops
->db_vector_mask
)
971 return ntb_db_valid_mask(ntb
);
973 return ntb
->ops
->db_vector_mask(ntb
, vector
);
977 * ntb_db_read() - read the local doorbell register
978 * @ntb: NTB device context.
980 * Read the local doorbell register, and return the bits that are set.
982 * Return: The bits currently set in the local doorbell register.
984 static inline u64
ntb_db_read(struct ntb_dev
*ntb
)
986 return ntb
->ops
->db_read(ntb
);
990 * ntb_db_set() - set bits in the local doorbell register
991 * @ntb: NTB device context.
992 * @db_bits: Doorbell bits to set.
994 * Set bits in the local doorbell register, which may generate a local doorbell
995 * interrupt. Bits that were already set must remain set.
997 * This is unusual, and hardware may not support it.
999 * Return: Zero on success, otherwise an error number.
1001 static inline int ntb_db_set(struct ntb_dev
*ntb
, u64 db_bits
)
1003 if (!ntb
->ops
->db_set
)
1006 return ntb
->ops
->db_set(ntb
, db_bits
);
1010 * ntb_db_clear() - clear bits in the local doorbell register
1011 * @ntb: NTB device context.
1012 * @db_bits: Doorbell bits to clear.
1014 * Clear bits in the local doorbell register, arming the bits for the next
1017 * Return: Zero on success, otherwise an error number.
1019 static inline int ntb_db_clear(struct ntb_dev
*ntb
, u64 db_bits
)
1021 return ntb
->ops
->db_clear(ntb
, db_bits
);
1025 * ntb_db_read_mask() - read the local doorbell mask
1026 * @ntb: NTB device context.
1028 * Read the local doorbell mask register, and return the bits that are set.
1030 * This is unusual, though hardware is likely to support it.
1032 * Return: The bits currently set in the local doorbell mask register.
1034 static inline u64
ntb_db_read_mask(struct ntb_dev
*ntb
)
1036 if (!ntb
->ops
->db_read_mask
)
1039 return ntb
->ops
->db_read_mask(ntb
);
1043 * ntb_db_set_mask() - set bits in the local doorbell mask
1044 * @ntb: NTB device context.
1045 * @db_bits: Doorbell mask bits to set.
1047 * Set bits in the local doorbell mask register, preventing doorbell interrupts
1048 * from being generated for those doorbell bits. Bits that were already set
1051 * Return: Zero on success, otherwise an error number.
1053 static inline int ntb_db_set_mask(struct ntb_dev
*ntb
, u64 db_bits
)
1055 return ntb
->ops
->db_set_mask(ntb
, db_bits
);
1059 * ntb_db_clear_mask() - clear bits in the local doorbell mask
1060 * @ntb: NTB device context.
1061 * @db_bits: Doorbell bits to clear.
1063 * Clear bits in the local doorbell mask register, allowing doorbell interrupts
1064 * from being generated for those doorbell bits. If a doorbell bit is already
1065 * set at the time the mask is cleared, and the corresponding mask bit is
1066 * changed from set to clear, then the ntb driver must ensure that
1067 * ntb_db_event() is called. If the hardware does not generate the interrupt
1068 * on clearing the mask bit, then the driver must call ntb_db_event() anyway.
1070 * Return: Zero on success, otherwise an error number.
1072 static inline int ntb_db_clear_mask(struct ntb_dev
*ntb
, u64 db_bits
)
1074 return ntb
->ops
->db_clear_mask(ntb
, db_bits
);
1078 * ntb_peer_db_addr() - address and size of the peer doorbell register
1079 * @ntb: NTB device context.
1080 * @db_addr: OUT - The address of the peer doorbell register.
1081 * @db_size: OUT - The number of bytes to write the peer doorbell register.
1082 * @db_data: OUT - The data of peer doorbell register
1083 * @db_bit: door bell bit number
1085 * Return the address of the peer doorbell register. This may be used, for
1086 * example, by drivers that offload memory copy operations to a dma engine.
1087 * The drivers may wish to ring the peer doorbell at the completion of memory
1088 * copy operations. For efficiency, and to simplify ordering of operations
1089 * between the dma memory copies and the ringing doorbell, the driver may
1090 * append one additional dma memory copy with the doorbell register as the
1091 * destination, after the memory copy operations.
1093 * Return: Zero on success, otherwise an error number.
1095 static inline int ntb_peer_db_addr(struct ntb_dev
*ntb
,
1096 phys_addr_t
*db_addr
,
1097 resource_size_t
*db_size
,
1098 u64
*db_data
, int db_bit
)
1100 if (!ntb
->ops
->peer_db_addr
)
1103 return ntb
->ops
->peer_db_addr(ntb
, db_addr
, db_size
, db_data
, db_bit
);
1107 * ntb_peer_db_read() - read the peer doorbell register
1108 * @ntb: NTB device context.
1110 * Read the peer doorbell register, and return the bits that are set.
1112 * This is unusual, and hardware may not support it.
1114 * Return: The bits currently set in the peer doorbell register.
1116 static inline u64
ntb_peer_db_read(struct ntb_dev
*ntb
)
1118 if (!ntb
->ops
->peer_db_read
)
1121 return ntb
->ops
->peer_db_read(ntb
);
1125 * ntb_peer_db_set() - set bits in the peer doorbell register
1126 * @ntb: NTB device context.
1127 * @db_bits: Doorbell bits to set.
1129 * Set bits in the peer doorbell register, which may generate a peer doorbell
1130 * interrupt. Bits that were already set must remain set.
1132 * Return: Zero on success, otherwise an error number.
1134 static inline int ntb_peer_db_set(struct ntb_dev
*ntb
, u64 db_bits
)
1136 return ntb
->ops
->peer_db_set(ntb
, db_bits
);
1140 * ntb_peer_db_clear() - clear bits in the peer doorbell register
1141 * @ntb: NTB device context.
1142 * @db_bits: Doorbell bits to clear.
1144 * Clear bits in the peer doorbell register, arming the bits for the next
1147 * This is unusual, and hardware may not support it.
1149 * Return: Zero on success, otherwise an error number.
1151 static inline int ntb_peer_db_clear(struct ntb_dev
*ntb
, u64 db_bits
)
1153 if (!ntb
->ops
->db_clear
)
1156 return ntb
->ops
->peer_db_clear(ntb
, db_bits
);
1160 * ntb_peer_db_read_mask() - read the peer doorbell mask
1161 * @ntb: NTB device context.
1163 * Read the peer doorbell mask register, and return the bits that are set.
1165 * This is unusual, and hardware may not support it.
1167 * Return: The bits currently set in the peer doorbell mask register.
1169 static inline u64
ntb_peer_db_read_mask(struct ntb_dev
*ntb
)
1171 if (!ntb
->ops
->db_read_mask
)
1174 return ntb
->ops
->peer_db_read_mask(ntb
);
1178 * ntb_peer_db_set_mask() - set bits in the peer doorbell mask
1179 * @ntb: NTB device context.
1180 * @db_bits: Doorbell mask bits to set.
1182 * Set bits in the peer doorbell mask register, preventing doorbell interrupts
1183 * from being generated for those doorbell bits. Bits that were already set
1186 * This is unusual, and hardware may not support it.
1188 * Return: Zero on success, otherwise an error number.
1190 static inline int ntb_peer_db_set_mask(struct ntb_dev
*ntb
, u64 db_bits
)
1192 if (!ntb
->ops
->db_set_mask
)
1195 return ntb
->ops
->peer_db_set_mask(ntb
, db_bits
);
1199 * ntb_peer_db_clear_mask() - clear bits in the peer doorbell mask
1200 * @ntb: NTB device context.
1201 * @db_bits: Doorbell bits to clear.
1203 * Clear bits in the peer doorbell mask register, allowing doorbell interrupts
1204 * from being generated for those doorbell bits. If the hardware does not
1205 * generate the interrupt on clearing the mask bit, then the driver should not
1206 * implement this function!
1208 * This is unusual, and hardware may not support it.
1210 * Return: Zero on success, otherwise an error number.
1212 static inline int ntb_peer_db_clear_mask(struct ntb_dev
*ntb
, u64 db_bits
)
1214 if (!ntb
->ops
->db_clear_mask
)
1217 return ntb
->ops
->peer_db_clear_mask(ntb
, db_bits
);
1221 * ntb_spad_is_unsafe() - check if it is safe to use the hardware scratchpads
1222 * @ntb: NTB device context.
1224 * It is possible for some ntb hardware to be affected by errata. Hardware
1225 * drivers can advise clients to avoid using scratchpads. Clients may ignore
1226 * this advice, though caution is recommended.
1228 * Return: Zero if it is safe to use scratchpads, or One if it is not safe.
1230 static inline int ntb_spad_is_unsafe(struct ntb_dev
*ntb
)
1232 if (!ntb
->ops
->spad_is_unsafe
)
1235 return ntb
->ops
->spad_is_unsafe(ntb
);
1239 * ntb_spad_count() - get the number of scratchpads
1240 * @ntb: NTB device context.
1242 * Hardware and topology may support a different number of scratchpads.
1243 * Although it must be the same for all ports per NTB device.
1245 * Return: the number of scratchpads.
1247 static inline int ntb_spad_count(struct ntb_dev
*ntb
)
1249 if (!ntb
->ops
->spad_count
)
1252 return ntb
->ops
->spad_count(ntb
);
1256 * ntb_spad_read() - read the local scratchpad register
1257 * @ntb: NTB device context.
1258 * @sidx: Scratchpad index.
1260 * Read the local scratchpad register, and return the value.
1262 * Return: The value of the local scratchpad register.
1264 static inline u32
ntb_spad_read(struct ntb_dev
*ntb
, int sidx
)
1266 if (!ntb
->ops
->spad_read
)
1269 return ntb
->ops
->spad_read(ntb
, sidx
);
1273 * ntb_spad_write() - write the local scratchpad register
1274 * @ntb: NTB device context.
1275 * @sidx: Scratchpad index.
1276 * @val: Scratchpad value.
1278 * Write the value to the local scratchpad register.
1280 * Return: Zero on success, otherwise an error number.
1282 static inline int ntb_spad_write(struct ntb_dev
*ntb
, int sidx
, u32 val
)
1284 if (!ntb
->ops
->spad_write
)
1287 return ntb
->ops
->spad_write(ntb
, sidx
, val
);
1291 * ntb_peer_spad_addr() - address of the peer scratchpad register
1292 * @ntb: NTB device context.
1293 * @pidx: Port index of peer device.
1294 * @sidx: Scratchpad index.
1295 * @spad_addr: OUT - The address of the peer scratchpad register.
1297 * Return the address of the peer doorbell register. This may be used, for
1298 * example, by drivers that offload memory copy operations to a dma engine.
1300 * Return: Zero on success, otherwise an error number.
1302 static inline int ntb_peer_spad_addr(struct ntb_dev
*ntb
, int pidx
, int sidx
,
1303 phys_addr_t
*spad_addr
)
1305 if (!ntb
->ops
->peer_spad_addr
)
1308 return ntb
->ops
->peer_spad_addr(ntb
, pidx
, sidx
, spad_addr
);
1312 * ntb_peer_spad_read() - read the peer scratchpad register
1313 * @ntb: NTB device context.
1314 * @pidx: Port index of peer device.
1315 * @sidx: Scratchpad index.
1317 * Read the peer scratchpad register, and return the value.
1319 * Return: The value of the local scratchpad register.
1321 static inline u32
ntb_peer_spad_read(struct ntb_dev
*ntb
, int pidx
, int sidx
)
1323 if (!ntb
->ops
->peer_spad_read
)
1326 return ntb
->ops
->peer_spad_read(ntb
, pidx
, sidx
);
1330 * ntb_peer_spad_write() - write the peer scratchpad register
1331 * @ntb: NTB device context.
1332 * @pidx: Port index of peer device.
1333 * @sidx: Scratchpad index.
1334 * @val: Scratchpad value.
1336 * Write the value to the peer scratchpad register.
1338 * Return: Zero on success, otherwise an error number.
1340 static inline int ntb_peer_spad_write(struct ntb_dev
*ntb
, int pidx
, int sidx
,
1343 if (!ntb
->ops
->peer_spad_write
)
1346 return ntb
->ops
->peer_spad_write(ntb
, pidx
, sidx
, val
);
1350 * ntb_msg_count() - get the number of message registers
1351 * @ntb: NTB device context.
1353 * Hardware may support a different number of message registers.
1355 * Return: the number of message registers.
1357 static inline int ntb_msg_count(struct ntb_dev
*ntb
)
1359 if (!ntb
->ops
->msg_count
)
1362 return ntb
->ops
->msg_count(ntb
);
1366 * ntb_msg_inbits() - get a bitfield of inbound message registers status
1367 * @ntb: NTB device context.
1369 * The method returns the bitfield of status and mask registers, which related
1370 * to inbound message registers.
1372 * Return: bitfield of inbound message registers.
1374 static inline u64
ntb_msg_inbits(struct ntb_dev
*ntb
)
1376 if (!ntb
->ops
->msg_inbits
)
1379 return ntb
->ops
->msg_inbits(ntb
);
1383 * ntb_msg_outbits() - get a bitfield of outbound message registers status
1384 * @ntb: NTB device context.
1386 * The method returns the bitfield of status and mask registers, which related
1387 * to outbound message registers.
1389 * Return: bitfield of outbound message registers.
1391 static inline u64
ntb_msg_outbits(struct ntb_dev
*ntb
)
1393 if (!ntb
->ops
->msg_outbits
)
1396 return ntb
->ops
->msg_outbits(ntb
);
1400 * ntb_msg_read_sts() - read the message registers status
1401 * @ntb: NTB device context.
1403 * Read the status of message register. Inbound and outbound message registers
1404 * related bits can be filtered by masks retrieved from ntb_msg_inbits() and
1405 * ntb_msg_outbits().
1407 * Return: status bits of message registers
1409 static inline u64
ntb_msg_read_sts(struct ntb_dev
*ntb
)
1411 if (!ntb
->ops
->msg_read_sts
)
1414 return ntb
->ops
->msg_read_sts(ntb
);
1418 * ntb_msg_clear_sts() - clear status bits of message registers
1419 * @ntb: NTB device context.
1420 * @sts_bits: Status bits to clear.
1422 * Clear bits in the status register.
1424 * Return: Zero on success, otherwise a negative error number.
1426 static inline int ntb_msg_clear_sts(struct ntb_dev
*ntb
, u64 sts_bits
)
1428 if (!ntb
->ops
->msg_clear_sts
)
1431 return ntb
->ops
->msg_clear_sts(ntb
, sts_bits
);
1435 * ntb_msg_set_mask() - set mask of message register status bits
1436 * @ntb: NTB device context.
1437 * @mask_bits: Mask bits.
1439 * Mask the message registers status bits from raising the message event.
1441 * Return: Zero on success, otherwise a negative error number.
1443 static inline int ntb_msg_set_mask(struct ntb_dev
*ntb
, u64 mask_bits
)
1445 if (!ntb
->ops
->msg_set_mask
)
1448 return ntb
->ops
->msg_set_mask(ntb
, mask_bits
);
1452 * ntb_msg_clear_mask() - clear message registers mask
1453 * @ntb: NTB device context.
1454 * @mask_bits: Mask bits to clear.
1456 * Clear bits in the message events mask register.
1458 * Return: Zero on success, otherwise a negative error number.
1460 static inline int ntb_msg_clear_mask(struct ntb_dev
*ntb
, u64 mask_bits
)
1462 if (!ntb
->ops
->msg_clear_mask
)
1465 return ntb
->ops
->msg_clear_mask(ntb
, mask_bits
);
1469 * ntb_msg_read() - read inbound message register with specified index
1470 * @ntb: NTB device context.
1471 * @pidx: OUT - Port index of peer device a message retrieved from
1472 * @midx: Message register index
1474 * Read data from the specified message register. Source port index of a
1475 * message is retrieved as well.
1477 * Return: The value of the inbound message register.
1479 static inline u32
ntb_msg_read(struct ntb_dev
*ntb
, int *pidx
, int midx
)
1481 if (!ntb
->ops
->msg_read
)
1484 return ntb
->ops
->msg_read(ntb
, pidx
, midx
);
1488 * ntb_peer_msg_write() - write data to the specified peer message register
1489 * @ntb: NTB device context.
1490 * @pidx: Port index of peer device a message being sent to
1491 * @midx: Message register index
1492 * @msg: Data to send
1494 * Send data to a specified peer device using the defined message register.
1495 * Message event can be raised if the midx registers isn't empty while
1496 * calling this method and the corresponding interrupt isn't masked.
1498 * Return: Zero on success, otherwise a negative error number.
1500 static inline int ntb_peer_msg_write(struct ntb_dev
*ntb
, int pidx
, int midx
,
1503 if (!ntb
->ops
->peer_msg_write
)
1506 return ntb
->ops
->peer_msg_write(ntb
, pidx
, midx
, msg
);