Merge branch 'bpf-Allow-selecting-numa-node-during-map-creation'
[linux-2.6/btrfs-unstable.git] / include / linux / ntb.h
blob609e232c00da824739f461dceb1abc4481404f7c
1 /*
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.
5 * GPL LICENSE SUMMARY
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.
19 * BSD LICENSE
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
26 * are met:
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
33 * distribution.
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>
56 #ifndef _NTB_H_
57 #define _NTB_H_
59 #include <linux/completion.h>
60 #include <linux/device.h>
62 struct ntb_client;
63 struct ntb_dev;
64 struct pci_dev;
66 /**
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.
74 enum ntb_topo {
75 NTB_TOPO_NONE = -1,
76 NTB_TOPO_PRI,
77 NTB_TOPO_SEC,
78 NTB_TOPO_B2B_USD,
79 NTB_TOPO_B2B_DSD,
82 static inline int ntb_topo_is_b2b(enum ntb_topo topo)
84 switch ((int)topo) {
85 case NTB_TOPO_B2B_USD:
86 case NTB_TOPO_B2B_DSD:
87 return 1;
89 return 0;
92 static inline char *ntb_topo_string(enum ntb_topo topo)
94 switch (topo) {
95 case NTB_TOPO_NONE: return "NTB_TOPO_NONE";
96 case NTB_TOPO_PRI: return "NTB_TOPO_PRI";
97 case NTB_TOPO_SEC: return "NTB_TOPO_SEC";
98 case NTB_TOPO_B2B_USD: return "NTB_TOPO_B2B_USD";
99 case NTB_TOPO_B2B_DSD: return "NTB_TOPO_B2B_DSD";
101 return "NTB_TOPO_INVALID";
105 * enum ntb_speed - NTB link training speed
106 * @NTB_SPEED_AUTO: Request the max supported speed.
107 * @NTB_SPEED_NONE: Link is not trained to any speed.
108 * @NTB_SPEED_GEN1: Link is trained to gen1 speed.
109 * @NTB_SPEED_GEN2: Link is trained to gen2 speed.
110 * @NTB_SPEED_GEN3: Link is trained to gen3 speed.
111 * @NTB_SPEED_GEN4: Link is trained to gen4 speed.
113 enum ntb_speed {
114 NTB_SPEED_AUTO = -1,
115 NTB_SPEED_NONE = 0,
116 NTB_SPEED_GEN1 = 1,
117 NTB_SPEED_GEN2 = 2,
118 NTB_SPEED_GEN3 = 3,
119 NTB_SPEED_GEN4 = 4
123 * enum ntb_width - NTB link training width
124 * @NTB_WIDTH_AUTO: Request the max supported width.
125 * @NTB_WIDTH_NONE: Link is not trained to any width.
126 * @NTB_WIDTH_1: Link is trained to 1 lane width.
127 * @NTB_WIDTH_2: Link is trained to 2 lane width.
128 * @NTB_WIDTH_4: Link is trained to 4 lane width.
129 * @NTB_WIDTH_8: Link is trained to 8 lane width.
130 * @NTB_WIDTH_12: Link is trained to 12 lane width.
131 * @NTB_WIDTH_16: Link is trained to 16 lane width.
132 * @NTB_WIDTH_32: Link is trained to 32 lane width.
134 enum ntb_width {
135 NTB_WIDTH_AUTO = -1,
136 NTB_WIDTH_NONE = 0,
137 NTB_WIDTH_1 = 1,
138 NTB_WIDTH_2 = 2,
139 NTB_WIDTH_4 = 4,
140 NTB_WIDTH_8 = 8,
141 NTB_WIDTH_12 = 12,
142 NTB_WIDTH_16 = 16,
143 NTB_WIDTH_32 = 32,
147 * enum ntb_default_port - NTB default port number
148 * @NTB_PORT_PRI_USD: Default port of the NTB_TOPO_PRI/NTB_TOPO_B2B_USD
149 * topologies
150 * @NTB_PORT_SEC_DSD: Default port of the NTB_TOPO_SEC/NTB_TOPO_B2B_DSD
151 * topologies
153 enum ntb_default_port {
154 NTB_PORT_PRI_USD,
155 NTB_PORT_SEC_DSD
157 #define NTB_DEF_PEER_CNT (1)
158 #define NTB_DEF_PEER_IDX (0)
161 * struct ntb_client_ops - ntb client operations
162 * @probe: Notify client of a new device.
163 * @remove: Notify client to remove a device.
165 struct ntb_client_ops {
166 int (*probe)(struct ntb_client *client, struct ntb_dev *ntb);
167 void (*remove)(struct ntb_client *client, struct ntb_dev *ntb);
170 static inline int ntb_client_ops_is_valid(const struct ntb_client_ops *ops)
172 /* commented callbacks are not required: */
173 return
174 ops->probe &&
175 ops->remove &&
180 * struct ntb_ctx_ops - ntb driver context operations
181 * @link_event: See ntb_link_event().
182 * @db_event: See ntb_db_event().
183 * @msg_event: See ntb_msg_event().
185 struct ntb_ctx_ops {
186 void (*link_event)(void *ctx);
187 void (*db_event)(void *ctx, int db_vector);
188 void (*msg_event)(void *ctx);
191 static inline int ntb_ctx_ops_is_valid(const struct ntb_ctx_ops *ops)
193 /* commented callbacks are not required: */
194 return
195 /* ops->link_event && */
196 /* ops->db_event && */
197 /* ops->msg_event && */
202 * struct ntb_ctx_ops - ntb device operations
203 * @port_number: See ntb_port_number().
204 * @peer_port_count: See ntb_peer_port_count().
205 * @peer_port_number: See ntb_peer_port_number().
206 * @peer_port_idx: See ntb_peer_port_idx().
207 * @link_is_up: See ntb_link_is_up().
208 * @link_enable: See ntb_link_enable().
209 * @link_disable: See ntb_link_disable().
210 * @mw_count: See ntb_mw_count().
211 * @mw_get_align: See ntb_mw_get_align().
212 * @mw_set_trans: See ntb_mw_set_trans().
213 * @mw_clear_trans: See ntb_mw_clear_trans().
214 * @peer_mw_count: See ntb_peer_mw_count().
215 * @peer_mw_get_addr: See ntb_peer_mw_get_addr().
216 * @peer_mw_set_trans: See ntb_peer_mw_set_trans().
217 * @peer_mw_clear_trans:See ntb_peer_mw_clear_trans().
218 * @db_is_unsafe: See ntb_db_is_unsafe().
219 * @db_valid_mask: See ntb_db_valid_mask().
220 * @db_vector_count: See ntb_db_vector_count().
221 * @db_vector_mask: See ntb_db_vector_mask().
222 * @db_read: See ntb_db_read().
223 * @db_set: See ntb_db_set().
224 * @db_clear: See ntb_db_clear().
225 * @db_read_mask: See ntb_db_read_mask().
226 * @db_set_mask: See ntb_db_set_mask().
227 * @db_clear_mask: See ntb_db_clear_mask().
228 * @peer_db_addr: See ntb_peer_db_addr().
229 * @peer_db_read: See ntb_peer_db_read().
230 * @peer_db_set: See ntb_peer_db_set().
231 * @peer_db_clear: See ntb_peer_db_clear().
232 * @peer_db_read_mask: See ntb_peer_db_read_mask().
233 * @peer_db_set_mask: See ntb_peer_db_set_mask().
234 * @peer_db_clear_mask: See ntb_peer_db_clear_mask().
235 * @spad_is_unsafe: See ntb_spad_is_unsafe().
236 * @spad_count: See ntb_spad_count().
237 * @spad_read: See ntb_spad_read().
238 * @spad_write: See ntb_spad_write().
239 * @peer_spad_addr: See ntb_peer_spad_addr().
240 * @peer_spad_read: See ntb_peer_spad_read().
241 * @peer_spad_write: See ntb_peer_spad_write().
242 * @msg_count: See ntb_msg_count().
243 * @msg_inbits: See ntb_msg_inbits().
244 * @msg_outbits: See ntb_msg_outbits().
245 * @msg_read_sts: See ntb_msg_read_sts().
246 * @msg_clear_sts: See ntb_msg_clear_sts().
247 * @msg_set_mask: See ntb_msg_set_mask().
248 * @msg_clear_mask: See ntb_msg_clear_mask().
249 * @msg_read: See ntb_msg_read().
250 * @msg_write: See ntb_msg_write().
252 struct ntb_dev_ops {
253 int (*port_number)(struct ntb_dev *ntb);
254 int (*peer_port_count)(struct ntb_dev *ntb);
255 int (*peer_port_number)(struct ntb_dev *ntb, int pidx);
256 int (*peer_port_idx)(struct ntb_dev *ntb, int port);
258 u64 (*link_is_up)(struct ntb_dev *ntb,
259 enum ntb_speed *speed, enum ntb_width *width);
260 int (*link_enable)(struct ntb_dev *ntb,
261 enum ntb_speed max_speed, enum ntb_width max_width);
262 int (*link_disable)(struct ntb_dev *ntb);
264 int (*mw_count)(struct ntb_dev *ntb, int pidx);
265 int (*mw_get_align)(struct ntb_dev *ntb, int pidx, int widx,
266 resource_size_t *addr_align,
267 resource_size_t *size_align,
268 resource_size_t *size_max);
269 int (*mw_set_trans)(struct ntb_dev *ntb, int pidx, int widx,
270 dma_addr_t addr, resource_size_t size);
271 int (*mw_clear_trans)(struct ntb_dev *ntb, int pidx, int widx);
272 int (*peer_mw_count)(struct ntb_dev *ntb);
273 int (*peer_mw_get_addr)(struct ntb_dev *ntb, int widx,
274 phys_addr_t *base, resource_size_t *size);
275 int (*peer_mw_set_trans)(struct ntb_dev *ntb, int pidx, int widx,
276 u64 addr, resource_size_t size);
277 int (*peer_mw_clear_trans)(struct ntb_dev *ntb, int pidx, int widx);
279 int (*db_is_unsafe)(struct ntb_dev *ntb);
280 u64 (*db_valid_mask)(struct ntb_dev *ntb);
281 int (*db_vector_count)(struct ntb_dev *ntb);
282 u64 (*db_vector_mask)(struct ntb_dev *ntb, int db_vector);
284 u64 (*db_read)(struct ntb_dev *ntb);
285 int (*db_set)(struct ntb_dev *ntb, u64 db_bits);
286 int (*db_clear)(struct ntb_dev *ntb, u64 db_bits);
288 u64 (*db_read_mask)(struct ntb_dev *ntb);
289 int (*db_set_mask)(struct ntb_dev *ntb, u64 db_bits);
290 int (*db_clear_mask)(struct ntb_dev *ntb, u64 db_bits);
292 int (*peer_db_addr)(struct ntb_dev *ntb,
293 phys_addr_t *db_addr, resource_size_t *db_size);
294 u64 (*peer_db_read)(struct ntb_dev *ntb);
295 int (*peer_db_set)(struct ntb_dev *ntb, u64 db_bits);
296 int (*peer_db_clear)(struct ntb_dev *ntb, u64 db_bits);
298 u64 (*peer_db_read_mask)(struct ntb_dev *ntb);
299 int (*peer_db_set_mask)(struct ntb_dev *ntb, u64 db_bits);
300 int (*peer_db_clear_mask)(struct ntb_dev *ntb, u64 db_bits);
302 int (*spad_is_unsafe)(struct ntb_dev *ntb);
303 int (*spad_count)(struct ntb_dev *ntb);
305 u32 (*spad_read)(struct ntb_dev *ntb, int sidx);
306 int (*spad_write)(struct ntb_dev *ntb, int sidx, u32 val);
308 int (*peer_spad_addr)(struct ntb_dev *ntb, int pidx, int sidx,
309 phys_addr_t *spad_addr);
310 u32 (*peer_spad_read)(struct ntb_dev *ntb, int pidx, int sidx);
311 int (*peer_spad_write)(struct ntb_dev *ntb, int pidx, int sidx,
312 u32 val);
314 int (*msg_count)(struct ntb_dev *ntb);
315 u64 (*msg_inbits)(struct ntb_dev *ntb);
316 u64 (*msg_outbits)(struct ntb_dev *ntb);
317 u64 (*msg_read_sts)(struct ntb_dev *ntb);
318 int (*msg_clear_sts)(struct ntb_dev *ntb, u64 sts_bits);
319 int (*msg_set_mask)(struct ntb_dev *ntb, u64 mask_bits);
320 int (*msg_clear_mask)(struct ntb_dev *ntb, u64 mask_bits);
321 int (*msg_read)(struct ntb_dev *ntb, int midx, int *pidx, u32 *msg);
322 int (*msg_write)(struct ntb_dev *ntb, int midx, int pidx, u32 msg);
325 static inline int ntb_dev_ops_is_valid(const struct ntb_dev_ops *ops)
327 /* commented callbacks are not required: */
328 return
329 /* Port operations are required for multiport devices */
330 !ops->peer_port_count == !ops->port_number &&
331 !ops->peer_port_number == !ops->port_number &&
332 !ops->peer_port_idx == !ops->port_number &&
334 /* Link operations are required */
335 ops->link_is_up &&
336 ops->link_enable &&
337 ops->link_disable &&
339 /* One or both MW interfaces should be developed */
340 ops->mw_count &&
341 ops->mw_get_align &&
342 (ops->mw_set_trans ||
343 ops->peer_mw_set_trans) &&
344 /* ops->mw_clear_trans && */
345 ops->peer_mw_count &&
346 ops->peer_mw_get_addr &&
347 /* ops->peer_mw_clear_trans && */
349 /* Doorbell operations are mostly required */
350 /* ops->db_is_unsafe && */
351 ops->db_valid_mask &&
352 /* both set, or both unset */
353 (!ops->db_vector_count == !ops->db_vector_mask) &&
354 ops->db_read &&
355 /* ops->db_set && */
356 ops->db_clear &&
357 /* ops->db_read_mask && */
358 ops->db_set_mask &&
359 ops->db_clear_mask &&
360 /* ops->peer_db_addr && */
361 /* ops->peer_db_read && */
362 ops->peer_db_set &&
363 /* ops->peer_db_clear && */
364 /* ops->peer_db_read_mask && */
365 /* ops->peer_db_set_mask && */
366 /* ops->peer_db_clear_mask && */
368 /* Scrachpads interface is optional */
369 /* !ops->spad_is_unsafe == !ops->spad_count && */
370 !ops->spad_read == !ops->spad_count &&
371 !ops->spad_write == !ops->spad_count &&
372 /* !ops->peer_spad_addr == !ops->spad_count && */
373 /* !ops->peer_spad_read == !ops->spad_count && */
374 !ops->peer_spad_write == !ops->spad_count &&
376 /* Messaging interface is optional */
377 !ops->msg_inbits == !ops->msg_count &&
378 !ops->msg_outbits == !ops->msg_count &&
379 !ops->msg_read_sts == !ops->msg_count &&
380 !ops->msg_clear_sts == !ops->msg_count &&
381 /* !ops->msg_set_mask == !ops->msg_count && */
382 /* !ops->msg_clear_mask == !ops->msg_count && */
383 !ops->msg_read == !ops->msg_count &&
384 !ops->msg_write == !ops->msg_count &&
389 * struct ntb_client - client interested in ntb devices
390 * @drv: Linux driver object.
391 * @ops: See &ntb_client_ops.
393 struct ntb_client {
394 struct device_driver drv;
395 const struct ntb_client_ops ops;
397 #define drv_ntb_client(__drv) container_of((__drv), struct ntb_client, drv)
400 * struct ntb_device - ntb device
401 * @dev: Linux device object.
402 * @pdev: PCI device entry of the ntb.
403 * @topo: Detected topology of the ntb.
404 * @ops: See &ntb_dev_ops.
405 * @ctx: See &ntb_ctx_ops.
406 * @ctx_ops: See &ntb_ctx_ops.
408 struct ntb_dev {
409 struct device dev;
410 struct pci_dev *pdev;
411 enum ntb_topo topo;
412 const struct ntb_dev_ops *ops;
413 void *ctx;
414 const struct ntb_ctx_ops *ctx_ops;
416 /* private: */
418 /* synchronize setting, clearing, and calling ctx_ops */
419 spinlock_t ctx_lock;
420 /* block unregister until device is fully released */
421 struct completion released;
423 #define dev_ntb(__dev) container_of((__dev), struct ntb_dev, dev)
426 * ntb_register_client() - register a client for interest in ntb devices
427 * @client: Client context.
429 * The client will be added to the list of clients interested in ntb devices.
430 * The client will be notified of any ntb devices that are not already
431 * associated with a client, or if ntb devices are registered later.
433 * Return: Zero if the client is registered, otherwise an error number.
435 #define ntb_register_client(client) \
436 __ntb_register_client((client), THIS_MODULE, KBUILD_MODNAME)
438 int __ntb_register_client(struct ntb_client *client, struct module *mod,
439 const char *mod_name);
442 * ntb_unregister_client() - unregister a client for interest in ntb devices
443 * @client: Client context.
445 * The client will be removed from the list of clients interested in ntb
446 * devices. If any ntb devices are associated with the client, the client will
447 * be notified to remove those devices.
449 void ntb_unregister_client(struct ntb_client *client);
451 #define module_ntb_client(__ntb_client) \
452 module_driver(__ntb_client, ntb_register_client, \
453 ntb_unregister_client)
456 * ntb_register_device() - register a ntb device
457 * @ntb: NTB device context.
459 * The device will be added to the list of ntb devices. If any clients are
460 * interested in ntb devices, each client will be notified of the ntb device,
461 * until at most one client accepts the device.
463 * Return: Zero if the device is registered, otherwise an error number.
465 int ntb_register_device(struct ntb_dev *ntb);
468 * ntb_register_device() - unregister a ntb device
469 * @ntb: NTB device context.
471 * The device will be removed from the list of ntb devices. If the ntb device
472 * is associated with a client, the client will be notified to remove the
473 * device.
475 void ntb_unregister_device(struct ntb_dev *ntb);
478 * ntb_set_ctx() - associate a driver context with an ntb device
479 * @ntb: NTB device context.
480 * @ctx: Driver context.
481 * @ctx_ops: Driver context operations.
483 * Associate a driver context and operations with a ntb device. The context is
484 * provided by the client driver, and the driver may associate a different
485 * context with each ntb device.
487 * Return: Zero if the context is associated, otherwise an error number.
489 int ntb_set_ctx(struct ntb_dev *ntb, void *ctx,
490 const struct ntb_ctx_ops *ctx_ops);
493 * ntb_clear_ctx() - disassociate any driver context from an ntb device
494 * @ntb: NTB device context.
496 * Clear any association that may exist between a driver context and the ntb
497 * device.
499 void ntb_clear_ctx(struct ntb_dev *ntb);
502 * ntb_link_event() - notify driver context of a change in link status
503 * @ntb: NTB device context.
505 * Notify the driver context that the link status may have changed. The driver
506 * should call ntb_link_is_up() to get the current status.
508 void ntb_link_event(struct ntb_dev *ntb);
511 * ntb_db_event() - notify driver context of a doorbell event
512 * @ntb: NTB device context.
513 * @vector: Interrupt vector number.
515 * Notify the driver context of a doorbell event. If hardware supports
516 * multiple interrupt vectors for doorbells, the vector number indicates which
517 * vector received the interrupt. The vector number is relative to the first
518 * vector used for doorbells, starting at zero, and must be less than
519 * ntb_db_vector_count(). The driver may call ntb_db_read() to check which
520 * doorbell bits need service, and ntb_db_vector_mask() to determine which of
521 * those bits are associated with the vector number.
523 void ntb_db_event(struct ntb_dev *ntb, int vector);
526 * ntb_msg_event() - notify driver context of a message event
527 * @ntb: NTB device context.
529 * Notify the driver context of a message event. If hardware supports
530 * message registers, this event indicates, that a new message arrived in
531 * some incoming message register or last sent message couldn't be delivered.
532 * The events can be masked/unmasked by the methods ntb_msg_set_mask() and
533 * ntb_msg_clear_mask().
535 void ntb_msg_event(struct ntb_dev *ntb);
538 * ntb_default_port_number() - get the default local port number
539 * @ntb: NTB device context.
541 * If hardware driver doesn't specify port_number() callback method, the NTB
542 * is considered with just two ports. So this method returns default local
543 * port number in compliance with topology.
545 * NOTE Don't call this method directly. The ntb_port_number() function should
546 * be used instead.
548 * Return: the default local port number
550 int ntb_default_port_number(struct ntb_dev *ntb);
553 * ntb_default_port_count() - get the default number of peer device ports
554 * @ntb: NTB device context.
556 * By default hardware driver supports just one peer device.
558 * NOTE Don't call this method directly. The ntb_peer_port_count() function
559 * should be used instead.
561 * Return: the default number of peer ports
563 int ntb_default_peer_port_count(struct ntb_dev *ntb);
566 * ntb_default_peer_port_number() - get the default peer port by given index
567 * @ntb: NTB device context.
568 * @idx: Peer port index (should not differ from zero).
570 * By default hardware driver supports just one peer device, so this method
571 * shall return the corresponding value from enum ntb_default_port.
573 * NOTE Don't call this method directly. The ntb_peer_port_number() function
574 * should be used instead.
576 * Return: the peer device port or negative value indicating an error
578 int ntb_default_peer_port_number(struct ntb_dev *ntb, int pidx);
581 * ntb_default_peer_port_idx() - get the default peer device port index by
582 * given port number
583 * @ntb: NTB device context.
584 * @port: Peer port number (should be one of enum ntb_default_port).
586 * By default hardware driver supports just one peer device, so while
587 * specified port-argument indicates peer port from enum ntb_default_port,
588 * the return value shall be zero.
590 * NOTE Don't call this method directly. The ntb_peer_port_idx() function
591 * should be used instead.
593 * Return: the peer port index or negative value indicating an error
595 int ntb_default_peer_port_idx(struct ntb_dev *ntb, int port);
598 * ntb_port_number() - get the local port number
599 * @ntb: NTB device context.
601 * Hardware must support at least simple two-ports ntb connection
603 * Return: the local port number
605 static inline int ntb_port_number(struct ntb_dev *ntb)
607 if (!ntb->ops->port_number)
608 return ntb_default_port_number(ntb);
610 return ntb->ops->port_number(ntb);
614 * ntb_peer_port_count() - get the number of peer device ports
615 * @ntb: NTB device context.
617 * Hardware may support an access to memory of several remote domains
618 * over multi-port NTB devices. This method returns the number of peers,
619 * local device can have shared memory with.
621 * Return: the number of peer ports
623 static inline int ntb_peer_port_count(struct ntb_dev *ntb)
625 if (!ntb->ops->peer_port_count)
626 return ntb_default_peer_port_count(ntb);
628 return ntb->ops->peer_port_count(ntb);
632 * ntb_peer_port_number() - get the peer port by given index
633 * @ntb: NTB device context.
634 * @pidx: Peer port index.
636 * Peer ports are continuously enumerated by NTB API logic, so this method
637 * lets to retrieve port real number by its index.
639 * Return: the peer device port or negative value indicating an error
641 static inline int ntb_peer_port_number(struct ntb_dev *ntb, int pidx)
643 if (!ntb->ops->peer_port_number)
644 return ntb_default_peer_port_number(ntb, pidx);
646 return ntb->ops->peer_port_number(ntb, pidx);
650 * ntb_peer_port_idx() - get the peer device port index by given port number
651 * @ntb: NTB device context.
652 * @port: Peer port number.
654 * Inverse operation of ntb_peer_port_number(), so one can get port index
655 * by specified port number.
657 * Return: the peer port index or negative value indicating an error
659 static inline int ntb_peer_port_idx(struct ntb_dev *ntb, int port)
661 if (!ntb->ops->peer_port_idx)
662 return ntb_default_peer_port_idx(ntb, port);
664 return ntb->ops->peer_port_idx(ntb, port);
668 * ntb_link_is_up() - get the current ntb link state
669 * @ntb: NTB device context.
670 * @speed: OUT - The link speed expressed as PCIe generation number.
671 * @width: OUT - The link width expressed as the number of PCIe lanes.
673 * Get the current state of the ntb link. It is recommended to query the link
674 * state once after every link event. It is safe to query the link state in
675 * the context of the link event callback.
677 * Return: bitfield of indexed ports link state: bit is set/cleared if the
678 * link is up/down respectively.
680 static inline u64 ntb_link_is_up(struct ntb_dev *ntb,
681 enum ntb_speed *speed, enum ntb_width *width)
683 return ntb->ops->link_is_up(ntb, speed, width);
687 * ntb_link_enable() - enable the local port ntb connection
688 * @ntb: NTB device context.
689 * @max_speed: The maximum link speed expressed as PCIe generation number.
690 * @max_width: The maximum link width expressed as the number of PCIe lanes.
692 * Enable the NTB/PCIe link on the local or remote (for bridge-to-bridge
693 * topology) side of the bridge. If it's supported the ntb device should train
694 * the link to its maximum speed and width, or the requested speed and width,
695 * whichever is smaller. Some hardware doesn't support PCIe link training, so
696 * the last two arguments will be ignored then.
698 * Return: Zero on success, otherwise an error number.
700 static inline int ntb_link_enable(struct ntb_dev *ntb,
701 enum ntb_speed max_speed,
702 enum ntb_width max_width)
704 return ntb->ops->link_enable(ntb, max_speed, max_width);
708 * ntb_link_disable() - disable the local port ntb connection
709 * @ntb: NTB device context.
711 * Disable the link on the local or remote (for b2b topology) of the ntb.
712 * The ntb device should disable the link. Returning from this call must
713 * indicate that a barrier has passed, though with no more writes may pass in
714 * either direction across the link, except if this call returns an error
715 * number.
717 * Return: Zero on success, otherwise an error number.
719 static inline int ntb_link_disable(struct ntb_dev *ntb)
721 return ntb->ops->link_disable(ntb);
725 * ntb_mw_count() - get the number of inbound memory windows, which could
726 * be created for a specified peer device
727 * @ntb: NTB device context.
728 * @pidx: Port index of peer device.
730 * Hardware and topology may support a different number of memory windows.
731 * Moreover different peer devices can support different number of memory
732 * windows. Simply speaking this method returns the number of possible inbound
733 * memory windows to share with specified peer device.
735 * Return: the number of memory windows.
737 static inline int ntb_mw_count(struct ntb_dev *ntb, int pidx)
739 return ntb->ops->mw_count(ntb, pidx);
743 * ntb_mw_get_align() - get the restriction parameters of inbound memory window
744 * @ntb: NTB device context.
745 * @pidx: Port index of peer device.
746 * @widx: Memory window index.
747 * @addr_align: OUT - the base alignment for translating the memory window
748 * @size_align: OUT - the size alignment for translating the memory window
749 * @size_max: OUT - the maximum size of the memory window
751 * Get the alignments of an inbound memory window with specified index.
752 * NULL may be given for any output parameter if the value is not needed.
753 * The alignment and size parameters may be used for allocation of proper
754 * shared memory.
756 * Return: Zero on success, otherwise a negative error number.
758 static inline int ntb_mw_get_align(struct ntb_dev *ntb, int pidx, int widx,
759 resource_size_t *addr_align,
760 resource_size_t *size_align,
761 resource_size_t *size_max)
763 return ntb->ops->mw_get_align(ntb, pidx, widx, addr_align, size_align,
764 size_max);
768 * ntb_mw_set_trans() - set the translation of an inbound memory window
769 * @ntb: NTB device context.
770 * @pidx: Port index of peer device.
771 * @widx: Memory window index.
772 * @addr: The dma address of local memory to expose to the peer.
773 * @size: The size of the local memory to expose to the peer.
775 * Set the translation of a memory window. The peer may access local memory
776 * through the window starting at the address, up to the size. The address
777 * and size must be aligned in compliance with restrictions of
778 * ntb_mw_get_align(). The region size should not exceed the size_max parameter
779 * of that method.
781 * This method may not be implemented due to the hardware specific memory
782 * windows interface.
784 * Return: Zero on success, otherwise an error number.
786 static inline int ntb_mw_set_trans(struct ntb_dev *ntb, int pidx, int widx,
787 dma_addr_t addr, resource_size_t size)
789 if (!ntb->ops->mw_set_trans)
790 return 0;
792 return ntb->ops->mw_set_trans(ntb, pidx, widx, addr, size);
796 * ntb_mw_clear_trans() - clear the translation address of an inbound memory
797 * window
798 * @ntb: NTB device context.
799 * @pidx: Port index of peer device.
800 * @widx: Memory window index.
802 * Clear the translation of an inbound memory window. The peer may no longer
803 * access local memory through the window.
805 * Return: Zero on success, otherwise an error number.
807 static inline int ntb_mw_clear_trans(struct ntb_dev *ntb, int pidx, int widx)
809 if (!ntb->ops->mw_clear_trans)
810 return ntb_mw_set_trans(ntb, pidx, widx, 0, 0);
812 return ntb->ops->mw_clear_trans(ntb, pidx, widx);
816 * ntb_peer_mw_count() - get the number of outbound memory windows, which could
817 * be mapped to access a shared memory
818 * @ntb: NTB device context.
820 * Hardware and topology may support a different number of memory windows.
821 * This method returns the number of outbound memory windows supported by
822 * local device.
824 * Return: the number of memory windows.
826 static inline int ntb_peer_mw_count(struct ntb_dev *ntb)
828 return ntb->ops->peer_mw_count(ntb);
832 * ntb_peer_mw_get_addr() - get map address of an outbound memory window
833 * @ntb: NTB device context.
834 * @widx: Memory window index (within ntb_peer_mw_count() return value).
835 * @base: OUT - the base address of mapping region.
836 * @size: OUT - the size of mapping region.
838 * Get base and size of memory region to map. NULL may be given for any output
839 * parameter if the value is not needed. The base and size may be used for
840 * mapping the memory window, to access the peer memory.
842 * Return: Zero on success, otherwise a negative error number.
844 static inline int ntb_peer_mw_get_addr(struct ntb_dev *ntb, int widx,
845 phys_addr_t *base, resource_size_t *size)
847 return ntb->ops->peer_mw_get_addr(ntb, widx, base, size);
851 * ntb_peer_mw_set_trans() - set a translation address of a memory window
852 * retrieved from a peer device
853 * @ntb: NTB device context.
854 * @pidx: Port index of peer device the translation address received from.
855 * @widx: Memory window index.
856 * @addr: The dma address of the shared memory to access.
857 * @size: The size of the shared memory to access.
859 * Set the translation of an outbound memory window. The local device may
860 * access shared memory allocated by a peer device sent the address.
862 * This method may not be implemented due to the hardware specific memory
863 * windows interface, so a translation address can be only set on the side,
864 * where shared memory (inbound memory windows) is allocated.
866 * Return: Zero on success, otherwise an error number.
868 static inline int ntb_peer_mw_set_trans(struct ntb_dev *ntb, int pidx, int widx,
869 u64 addr, resource_size_t size)
871 if (!ntb->ops->peer_mw_set_trans)
872 return 0;
874 return ntb->ops->peer_mw_set_trans(ntb, pidx, widx, addr, size);
878 * ntb_peer_mw_clear_trans() - clear the translation address of an outbound
879 * memory window
880 * @ntb: NTB device context.
881 * @pidx: Port index of peer device.
882 * @widx: Memory window index.
884 * Clear the translation of a outbound memory window. The local device may no
885 * longer access a shared memory through the window.
887 * This method may not be implemented due to the hardware specific memory
888 * windows interface.
890 * Return: Zero on success, otherwise an error number.
892 static inline int ntb_peer_mw_clear_trans(struct ntb_dev *ntb, int pidx,
893 int widx)
895 if (!ntb->ops->peer_mw_clear_trans)
896 return ntb_peer_mw_set_trans(ntb, pidx, widx, 0, 0);
898 return ntb->ops->peer_mw_clear_trans(ntb, pidx, widx);
902 * ntb_db_is_unsafe() - check if it is safe to use hardware doorbell
903 * @ntb: NTB device context.
905 * It is possible for some ntb hardware to be affected by errata. Hardware
906 * drivers can advise clients to avoid using doorbells. Clients may ignore
907 * this advice, though caution is recommended.
909 * Return: Zero if it is safe to use doorbells, or One if it is not safe.
911 static inline int ntb_db_is_unsafe(struct ntb_dev *ntb)
913 if (!ntb->ops->db_is_unsafe)
914 return 0;
916 return ntb->ops->db_is_unsafe(ntb);
920 * ntb_db_valid_mask() - get a mask of doorbell bits supported by the ntb
921 * @ntb: NTB device context.
923 * Hardware may support different number or arrangement of doorbell bits.
925 * Return: A mask of doorbell bits supported by the ntb.
927 static inline u64 ntb_db_valid_mask(struct ntb_dev *ntb)
929 return ntb->ops->db_valid_mask(ntb);
933 * ntb_db_vector_count() - get the number of doorbell interrupt vectors
934 * @ntb: NTB device context.
936 * Hardware may support different number of interrupt vectors.
938 * Return: The number of doorbell interrupt vectors.
940 static inline int ntb_db_vector_count(struct ntb_dev *ntb)
942 if (!ntb->ops->db_vector_count)
943 return 1;
945 return ntb->ops->db_vector_count(ntb);
949 * ntb_db_vector_mask() - get a mask of doorbell bits serviced by a vector
950 * @ntb: NTB device context.
951 * @vector: Doorbell vector number.
953 * Each interrupt vector may have a different number or arrangement of bits.
955 * Return: A mask of doorbell bits serviced by a vector.
957 static inline u64 ntb_db_vector_mask(struct ntb_dev *ntb, int vector)
959 if (!ntb->ops->db_vector_mask)
960 return ntb_db_valid_mask(ntb);
962 return ntb->ops->db_vector_mask(ntb, vector);
966 * ntb_db_read() - read the local doorbell register
967 * @ntb: NTB device context.
969 * Read the local doorbell register, and return the bits that are set.
971 * Return: The bits currently set in the local doorbell register.
973 static inline u64 ntb_db_read(struct ntb_dev *ntb)
975 return ntb->ops->db_read(ntb);
979 * ntb_db_set() - set bits in the local doorbell register
980 * @ntb: NTB device context.
981 * @db_bits: Doorbell bits to set.
983 * Set bits in the local doorbell register, which may generate a local doorbell
984 * interrupt. Bits that were already set must remain set.
986 * This is unusual, and hardware may not support it.
988 * Return: Zero on success, otherwise an error number.
990 static inline int ntb_db_set(struct ntb_dev *ntb, u64 db_bits)
992 if (!ntb->ops->db_set)
993 return -EINVAL;
995 return ntb->ops->db_set(ntb, db_bits);
999 * ntb_db_clear() - clear bits in the local doorbell register
1000 * @ntb: NTB device context.
1001 * @db_bits: Doorbell bits to clear.
1003 * Clear bits in the local doorbell register, arming the bits for the next
1004 * doorbell.
1006 * Return: Zero on success, otherwise an error number.
1008 static inline int ntb_db_clear(struct ntb_dev *ntb, u64 db_bits)
1010 return ntb->ops->db_clear(ntb, db_bits);
1014 * ntb_db_read_mask() - read the local doorbell mask
1015 * @ntb: NTB device context.
1017 * Read the local doorbell mask register, and return the bits that are set.
1019 * This is unusual, though hardware is likely to support it.
1021 * Return: The bits currently set in the local doorbell mask register.
1023 static inline u64 ntb_db_read_mask(struct ntb_dev *ntb)
1025 if (!ntb->ops->db_read_mask)
1026 return 0;
1028 return ntb->ops->db_read_mask(ntb);
1032 * ntb_db_set_mask() - set bits in the local doorbell mask
1033 * @ntb: NTB device context.
1034 * @db_bits: Doorbell mask bits to set.
1036 * Set bits in the local doorbell mask register, preventing doorbell interrupts
1037 * from being generated for those doorbell bits. Bits that were already set
1038 * must remain set.
1040 * Return: Zero on success, otherwise an error number.
1042 static inline int ntb_db_set_mask(struct ntb_dev *ntb, u64 db_bits)
1044 return ntb->ops->db_set_mask(ntb, db_bits);
1048 * ntb_db_clear_mask() - clear bits in the local doorbell mask
1049 * @ntb: NTB device context.
1050 * @db_bits: Doorbell bits to clear.
1052 * Clear bits in the local doorbell mask register, allowing doorbell interrupts
1053 * from being generated for those doorbell bits. If a doorbell bit is already
1054 * set at the time the mask is cleared, and the corresponding mask bit is
1055 * changed from set to clear, then the ntb driver must ensure that
1056 * ntb_db_event() is called. If the hardware does not generate the interrupt
1057 * on clearing the mask bit, then the driver must call ntb_db_event() anyway.
1059 * Return: Zero on success, otherwise an error number.
1061 static inline int ntb_db_clear_mask(struct ntb_dev *ntb, u64 db_bits)
1063 return ntb->ops->db_clear_mask(ntb, db_bits);
1067 * ntb_peer_db_addr() - address and size of the peer doorbell register
1068 * @ntb: NTB device context.
1069 * @db_addr: OUT - The address of the peer doorbell register.
1070 * @db_size: OUT - The number of bytes to write the peer doorbell register.
1072 * Return the address of the peer doorbell register. This may be used, for
1073 * example, by drivers that offload memory copy operations to a dma engine.
1074 * The drivers may wish to ring the peer doorbell at the completion of memory
1075 * copy operations. For efficiency, and to simplify ordering of operations
1076 * between the dma memory copies and the ringing doorbell, the driver may
1077 * append one additional dma memory copy with the doorbell register as the
1078 * destination, after the memory copy operations.
1080 * Return: Zero on success, otherwise an error number.
1082 static inline int ntb_peer_db_addr(struct ntb_dev *ntb,
1083 phys_addr_t *db_addr,
1084 resource_size_t *db_size)
1086 if (!ntb->ops->peer_db_addr)
1087 return -EINVAL;
1089 return ntb->ops->peer_db_addr(ntb, db_addr, db_size);
1093 * ntb_peer_db_read() - read the peer doorbell register
1094 * @ntb: NTB device context.
1096 * Read the peer doorbell register, and return the bits that are set.
1098 * This is unusual, and hardware may not support it.
1100 * Return: The bits currently set in the peer doorbell register.
1102 static inline u64 ntb_peer_db_read(struct ntb_dev *ntb)
1104 if (!ntb->ops->peer_db_read)
1105 return 0;
1107 return ntb->ops->peer_db_read(ntb);
1111 * ntb_peer_db_set() - set bits in the peer doorbell register
1112 * @ntb: NTB device context.
1113 * @db_bits: Doorbell bits to set.
1115 * Set bits in the peer doorbell register, which may generate a peer doorbell
1116 * interrupt. Bits that were already set must remain set.
1118 * Return: Zero on success, otherwise an error number.
1120 static inline int ntb_peer_db_set(struct ntb_dev *ntb, u64 db_bits)
1122 return ntb->ops->peer_db_set(ntb, db_bits);
1126 * ntb_peer_db_clear() - clear bits in the peer doorbell register
1127 * @ntb: NTB device context.
1128 * @db_bits: Doorbell bits to clear.
1130 * Clear bits in the peer doorbell register, arming the bits for the next
1131 * doorbell.
1133 * This is unusual, and hardware may not support it.
1135 * Return: Zero on success, otherwise an error number.
1137 static inline int ntb_peer_db_clear(struct ntb_dev *ntb, u64 db_bits)
1139 if (!ntb->ops->db_clear)
1140 return -EINVAL;
1142 return ntb->ops->peer_db_clear(ntb, db_bits);
1146 * ntb_peer_db_read_mask() - read the peer doorbell mask
1147 * @ntb: NTB device context.
1149 * Read the peer doorbell mask register, and return the bits that are set.
1151 * This is unusual, and hardware may not support it.
1153 * Return: The bits currently set in the peer doorbell mask register.
1155 static inline u64 ntb_peer_db_read_mask(struct ntb_dev *ntb)
1157 if (!ntb->ops->db_read_mask)
1158 return 0;
1160 return ntb->ops->peer_db_read_mask(ntb);
1164 * ntb_peer_db_set_mask() - set bits in the peer doorbell mask
1165 * @ntb: NTB device context.
1166 * @db_bits: Doorbell mask bits to set.
1168 * Set bits in the peer doorbell mask register, preventing doorbell interrupts
1169 * from being generated for those doorbell bits. Bits that were already set
1170 * must remain set.
1172 * This is unusual, and hardware may not support it.
1174 * Return: Zero on success, otherwise an error number.
1176 static inline int ntb_peer_db_set_mask(struct ntb_dev *ntb, u64 db_bits)
1178 if (!ntb->ops->db_set_mask)
1179 return -EINVAL;
1181 return ntb->ops->peer_db_set_mask(ntb, db_bits);
1185 * ntb_peer_db_clear_mask() - clear bits in the peer doorbell mask
1186 * @ntb: NTB device context.
1187 * @db_bits: Doorbell bits to clear.
1189 * Clear bits in the peer doorbell mask register, allowing doorbell interrupts
1190 * from being generated for those doorbell bits. If the hardware does not
1191 * generate the interrupt on clearing the mask bit, then the driver should not
1192 * implement this function!
1194 * This is unusual, and hardware may not support it.
1196 * Return: Zero on success, otherwise an error number.
1198 static inline int ntb_peer_db_clear_mask(struct ntb_dev *ntb, u64 db_bits)
1200 if (!ntb->ops->db_clear_mask)
1201 return -EINVAL;
1203 return ntb->ops->peer_db_clear_mask(ntb, db_bits);
1207 * ntb_spad_is_unsafe() - check if it is safe to use the hardware scratchpads
1208 * @ntb: NTB device context.
1210 * It is possible for some ntb hardware to be affected by errata. Hardware
1211 * drivers can advise clients to avoid using scratchpads. Clients may ignore
1212 * this advice, though caution is recommended.
1214 * Return: Zero if it is safe to use scratchpads, or One if it is not safe.
1216 static inline int ntb_spad_is_unsafe(struct ntb_dev *ntb)
1218 if (!ntb->ops->spad_is_unsafe)
1219 return 0;
1221 return ntb->ops->spad_is_unsafe(ntb);
1225 * ntb_spad_count() - get the number of scratchpads
1226 * @ntb: NTB device context.
1228 * Hardware and topology may support a different number of scratchpads.
1229 * Although it must be the same for all ports per NTB device.
1231 * Return: the number of scratchpads.
1233 static inline int ntb_spad_count(struct ntb_dev *ntb)
1235 if (!ntb->ops->spad_count)
1236 return 0;
1238 return ntb->ops->spad_count(ntb);
1242 * ntb_spad_read() - read the local scratchpad register
1243 * @ntb: NTB device context.
1244 * @sidx: Scratchpad index.
1246 * Read the local scratchpad register, and return the value.
1248 * Return: The value of the local scratchpad register.
1250 static inline u32 ntb_spad_read(struct ntb_dev *ntb, int sidx)
1252 if (!ntb->ops->spad_read)
1253 return ~(u32)0;
1255 return ntb->ops->spad_read(ntb, sidx);
1259 * ntb_spad_write() - write the local scratchpad register
1260 * @ntb: NTB device context.
1261 * @sidx: Scratchpad index.
1262 * @val: Scratchpad value.
1264 * Write the value to the local scratchpad register.
1266 * Return: Zero on success, otherwise an error number.
1268 static inline int ntb_spad_write(struct ntb_dev *ntb, int sidx, u32 val)
1270 if (!ntb->ops->spad_write)
1271 return -EINVAL;
1273 return ntb->ops->spad_write(ntb, sidx, val);
1277 * ntb_peer_spad_addr() - address of the peer scratchpad register
1278 * @ntb: NTB device context.
1279 * @pidx: Port index of peer device.
1280 * @sidx: Scratchpad index.
1281 * @spad_addr: OUT - The address of the peer scratchpad register.
1283 * Return the address of the peer doorbell register. This may be used, for
1284 * example, by drivers that offload memory copy operations to a dma engine.
1286 * Return: Zero on success, otherwise an error number.
1288 static inline int ntb_peer_spad_addr(struct ntb_dev *ntb, int pidx, int sidx,
1289 phys_addr_t *spad_addr)
1291 if (!ntb->ops->peer_spad_addr)
1292 return -EINVAL;
1294 return ntb->ops->peer_spad_addr(ntb, pidx, sidx, spad_addr);
1298 * ntb_peer_spad_read() - read the peer scratchpad register
1299 * @ntb: NTB device context.
1300 * @pidx: Port index of peer device.
1301 * @sidx: Scratchpad index.
1303 * Read the peer scratchpad register, and return the value.
1305 * Return: The value of the local scratchpad register.
1307 static inline u32 ntb_peer_spad_read(struct ntb_dev *ntb, int pidx, int sidx)
1309 if (!ntb->ops->peer_spad_read)
1310 return ~(u32)0;
1312 return ntb->ops->peer_spad_read(ntb, pidx, sidx);
1316 * ntb_peer_spad_write() - write the peer scratchpad register
1317 * @ntb: NTB device context.
1318 * @pidx: Port index of peer device.
1319 * @sidx: Scratchpad index.
1320 * @val: Scratchpad value.
1322 * Write the value to the peer scratchpad register.
1324 * Return: Zero on success, otherwise an error number.
1326 static inline int ntb_peer_spad_write(struct ntb_dev *ntb, int pidx, int sidx,
1327 u32 val)
1329 if (!ntb->ops->peer_spad_write)
1330 return -EINVAL;
1332 return ntb->ops->peer_spad_write(ntb, pidx, sidx, val);
1336 * ntb_msg_count() - get the number of message registers
1337 * @ntb: NTB device context.
1339 * Hardware may support a different number of message registers.
1341 * Return: the number of message registers.
1343 static inline int ntb_msg_count(struct ntb_dev *ntb)
1345 if (!ntb->ops->msg_count)
1346 return 0;
1348 return ntb->ops->msg_count(ntb);
1352 * ntb_msg_inbits() - get a bitfield of inbound message registers status
1353 * @ntb: NTB device context.
1355 * The method returns the bitfield of status and mask registers, which related
1356 * to inbound message registers.
1358 * Return: bitfield of inbound message registers.
1360 static inline u64 ntb_msg_inbits(struct ntb_dev *ntb)
1362 if (!ntb->ops->msg_inbits)
1363 return 0;
1365 return ntb->ops->msg_inbits(ntb);
1369 * ntb_msg_outbits() - get a bitfield of outbound message registers status
1370 * @ntb: NTB device context.
1372 * The method returns the bitfield of status and mask registers, which related
1373 * to outbound message registers.
1375 * Return: bitfield of outbound message registers.
1377 static inline u64 ntb_msg_outbits(struct ntb_dev *ntb)
1379 if (!ntb->ops->msg_outbits)
1380 return 0;
1382 return ntb->ops->msg_outbits(ntb);
1386 * ntb_msg_read_sts() - read the message registers status
1387 * @ntb: NTB device context.
1389 * Read the status of message register. Inbound and outbound message registers
1390 * related bits can be filtered by masks retrieved from ntb_msg_inbits() and
1391 * ntb_msg_outbits().
1393 * Return: status bits of message registers
1395 static inline u64 ntb_msg_read_sts(struct ntb_dev *ntb)
1397 if (!ntb->ops->msg_read_sts)
1398 return 0;
1400 return ntb->ops->msg_read_sts(ntb);
1404 * ntb_msg_clear_sts() - clear status bits of message registers
1405 * @ntb: NTB device context.
1406 * @sts_bits: Status bits to clear.
1408 * Clear bits in the status register.
1410 * Return: Zero on success, otherwise a negative error number.
1412 static inline int ntb_msg_clear_sts(struct ntb_dev *ntb, u64 sts_bits)
1414 if (!ntb->ops->msg_clear_sts)
1415 return -EINVAL;
1417 return ntb->ops->msg_clear_sts(ntb, sts_bits);
1421 * ntb_msg_set_mask() - set mask of message register status bits
1422 * @ntb: NTB device context.
1423 * @mask_bits: Mask bits.
1425 * Mask the message registers status bits from raising the message event.
1427 * Return: Zero on success, otherwise a negative error number.
1429 static inline int ntb_msg_set_mask(struct ntb_dev *ntb, u64 mask_bits)
1431 if (!ntb->ops->msg_set_mask)
1432 return -EINVAL;
1434 return ntb->ops->msg_set_mask(ntb, mask_bits);
1438 * ntb_msg_clear_mask() - clear message registers mask
1439 * @ntb: NTB device context.
1440 * @mask_bits: Mask bits to clear.
1442 * Clear bits in the message events mask register.
1444 * Return: Zero on success, otherwise a negative error number.
1446 static inline int ntb_msg_clear_mask(struct ntb_dev *ntb, u64 mask_bits)
1448 if (!ntb->ops->msg_clear_mask)
1449 return -EINVAL;
1451 return ntb->ops->msg_clear_mask(ntb, mask_bits);
1455 * ntb_msg_read() - read message register with specified index
1456 * @ntb: NTB device context.
1457 * @midx: Message register index
1458 * @pidx: OUT - Port index of peer device a message retrieved from
1459 * @msg: OUT - Data
1461 * Read data from the specified message register. Source port index of a
1462 * message is retrieved as well.
1464 * Return: Zero on success, otherwise a negative error number.
1466 static inline int ntb_msg_read(struct ntb_dev *ntb, int midx, int *pidx,
1467 u32 *msg)
1469 if (!ntb->ops->msg_read)
1470 return -EINVAL;
1472 return ntb->ops->msg_read(ntb, midx, pidx, msg);
1476 * ntb_msg_write() - write data to the specified message register
1477 * @ntb: NTB device context.
1478 * @midx: Message register index
1479 * @pidx: Port index of peer device a message being sent to
1480 * @msg: Data to send
1482 * Send data to a specified peer device using the defined message register.
1483 * Message event can be raised if the midx registers isn't empty while
1484 * calling this method and the corresponding interrupt isn't masked.
1486 * Return: Zero on success, otherwise a negative error number.
1488 static inline int ntb_msg_write(struct ntb_dev *ntb, int midx, int pidx,
1489 u32 msg)
1491 if (!ntb->ops->msg_write)
1492 return -EINVAL;
1494 return ntb->ops->msg_write(ntb, midx, pidx, msg);
1497 #endif