drm/exynos: fix types for compilation on 64bit architectures
[linux-2.6/btrfs-unstable.git] / include / linux / ntb.h
blobf798e2afba88db5cd50b356108d2250048e17593
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.
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of version 2 of the GNU General Public License as
11 * published by the Free Software Foundation.
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
18 * BSD LICENSE
20 * Copyright (C) 2015 EMC Corporation. All Rights Reserved.
22 * Redistribution and use in source and binary forms, with or without
23 * modification, are permitted provided that the following conditions
24 * are met:
26 * * Redistributions of source code must retain the above copyright
27 * notice, this list of conditions and the following disclaimer.
28 * * Redistributions in binary form must reproduce the above copy
29 * notice, this list of conditions and the following disclaimer in
30 * the documentation and/or other materials provided with the
31 * distribution.
32 * * Neither the name of Intel Corporation nor the names of its
33 * contributors may be used to endorse or promote products derived
34 * from this software without specific prior written permission.
36 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
37 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
38 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
39 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
40 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
42 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
43 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
44 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
45 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
46 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
48 * PCIe NTB Linux driver
50 * Contact Information:
51 * Allen Hubbe <Allen.Hubbe@emc.com>
54 #ifndef _NTB_H_
55 #define _NTB_H_
57 #include <linux/completion.h>
58 #include <linux/device.h>
60 struct ntb_client;
61 struct ntb_dev;
62 struct pci_dev;
64 /**
65 * enum ntb_topo - NTB connection topology
66 * @NTB_TOPO_NONE: Topology is unknown or invalid.
67 * @NTB_TOPO_PRI: On primary side of local ntb.
68 * @NTB_TOPO_SEC: On secondary side of remote ntb.
69 * @NTB_TOPO_B2B_USD: On primary side of local ntb upstream of remote ntb.
70 * @NTB_TOPO_B2B_DSD: On primary side of local ntb downstream of remote ntb.
72 enum ntb_topo {
73 NTB_TOPO_NONE = -1,
74 NTB_TOPO_PRI,
75 NTB_TOPO_SEC,
76 NTB_TOPO_B2B_USD,
77 NTB_TOPO_B2B_DSD,
80 static inline int ntb_topo_is_b2b(enum ntb_topo topo)
82 switch ((int)topo) {
83 case NTB_TOPO_B2B_USD:
84 case NTB_TOPO_B2B_DSD:
85 return 1;
87 return 0;
90 static inline char *ntb_topo_string(enum ntb_topo topo)
92 switch (topo) {
93 case NTB_TOPO_NONE: return "NTB_TOPO_NONE";
94 case NTB_TOPO_PRI: return "NTB_TOPO_PRI";
95 case NTB_TOPO_SEC: return "NTB_TOPO_SEC";
96 case NTB_TOPO_B2B_USD: return "NTB_TOPO_B2B_USD";
97 case NTB_TOPO_B2B_DSD: return "NTB_TOPO_B2B_DSD";
99 return "NTB_TOPO_INVALID";
103 * enum ntb_speed - NTB link training speed
104 * @NTB_SPEED_AUTO: Request the max supported speed.
105 * @NTB_SPEED_NONE: Link is not trained to any speed.
106 * @NTB_SPEED_GEN1: Link is trained to gen1 speed.
107 * @NTB_SPEED_GEN2: Link is trained to gen2 speed.
108 * @NTB_SPEED_GEN3: Link is trained to gen3 speed.
110 enum ntb_speed {
111 NTB_SPEED_AUTO = -1,
112 NTB_SPEED_NONE = 0,
113 NTB_SPEED_GEN1 = 1,
114 NTB_SPEED_GEN2 = 2,
115 NTB_SPEED_GEN3 = 3,
119 * enum ntb_width - NTB link training width
120 * @NTB_WIDTH_AUTO: Request the max supported width.
121 * @NTB_WIDTH_NONE: Link is not trained to any width.
122 * @NTB_WIDTH_1: Link is trained to 1 lane width.
123 * @NTB_WIDTH_2: Link is trained to 2 lane width.
124 * @NTB_WIDTH_4: Link is trained to 4 lane width.
125 * @NTB_WIDTH_8: Link is trained to 8 lane width.
126 * @NTB_WIDTH_12: Link is trained to 12 lane width.
127 * @NTB_WIDTH_16: Link is trained to 16 lane width.
128 * @NTB_WIDTH_32: Link is trained to 32 lane width.
130 enum ntb_width {
131 NTB_WIDTH_AUTO = -1,
132 NTB_WIDTH_NONE = 0,
133 NTB_WIDTH_1 = 1,
134 NTB_WIDTH_2 = 2,
135 NTB_WIDTH_4 = 4,
136 NTB_WIDTH_8 = 8,
137 NTB_WIDTH_12 = 12,
138 NTB_WIDTH_16 = 16,
139 NTB_WIDTH_32 = 32,
143 * struct ntb_client_ops - ntb client operations
144 * @probe: Notify client of a new device.
145 * @remove: Notify client to remove a device.
147 struct ntb_client_ops {
148 int (*probe)(struct ntb_client *client, struct ntb_dev *ntb);
149 void (*remove)(struct ntb_client *client, struct ntb_dev *ntb);
152 static inline int ntb_client_ops_is_valid(const struct ntb_client_ops *ops)
154 /* commented callbacks are not required: */
155 return
156 ops->probe &&
157 ops->remove &&
162 * struct ntb_ctx_ops - ntb driver context operations
163 * @link_event: See ntb_link_event().
164 * @db_event: See ntb_db_event().
166 struct ntb_ctx_ops {
167 void (*link_event)(void *ctx);
168 void (*db_event)(void *ctx, int db_vector);
171 static inline int ntb_ctx_ops_is_valid(const struct ntb_ctx_ops *ops)
173 /* commented callbacks are not required: */
174 return
175 /* ops->link_event && */
176 /* ops->db_event && */
181 * struct ntb_ctx_ops - ntb device operations
182 * @mw_count: See ntb_mw_count().
183 * @mw_get_range: See ntb_mw_get_range().
184 * @mw_set_trans: See ntb_mw_set_trans().
185 * @mw_clear_trans: See ntb_mw_clear_trans().
186 * @link_is_up: See ntb_link_is_up().
187 * @link_enable: See ntb_link_enable().
188 * @link_disable: See ntb_link_disable().
189 * @db_is_unsafe: See ntb_db_is_unsafe().
190 * @db_valid_mask: See ntb_db_valid_mask().
191 * @db_vector_count: See ntb_db_vector_count().
192 * @db_vector_mask: See ntb_db_vector_mask().
193 * @db_read: See ntb_db_read().
194 * @db_set: See ntb_db_set().
195 * @db_clear: See ntb_db_clear().
196 * @db_read_mask: See ntb_db_read_mask().
197 * @db_set_mask: See ntb_db_set_mask().
198 * @db_clear_mask: See ntb_db_clear_mask().
199 * @peer_db_addr: See ntb_peer_db_addr().
200 * @peer_db_read: See ntb_peer_db_read().
201 * @peer_db_set: See ntb_peer_db_set().
202 * @peer_db_clear: See ntb_peer_db_clear().
203 * @peer_db_read_mask: See ntb_peer_db_read_mask().
204 * @peer_db_set_mask: See ntb_peer_db_set_mask().
205 * @peer_db_clear_mask: See ntb_peer_db_clear_mask().
206 * @spad_is_unsafe: See ntb_spad_is_unsafe().
207 * @spad_count: See ntb_spad_count().
208 * @spad_read: See ntb_spad_read().
209 * @spad_write: See ntb_spad_write().
210 * @peer_spad_addr: See ntb_peer_spad_addr().
211 * @peer_spad_read: See ntb_peer_spad_read().
212 * @peer_spad_write: See ntb_peer_spad_write().
214 struct ntb_dev_ops {
215 int (*mw_count)(struct ntb_dev *ntb);
216 int (*mw_get_range)(struct ntb_dev *ntb, int idx,
217 phys_addr_t *base, resource_size_t *size,
218 resource_size_t *align, resource_size_t *align_size);
219 int (*mw_set_trans)(struct ntb_dev *ntb, int idx,
220 dma_addr_t addr, resource_size_t size);
221 int (*mw_clear_trans)(struct ntb_dev *ntb, int idx);
223 int (*link_is_up)(struct ntb_dev *ntb,
224 enum ntb_speed *speed, enum ntb_width *width);
225 int (*link_enable)(struct ntb_dev *ntb,
226 enum ntb_speed max_speed, enum ntb_width max_width);
227 int (*link_disable)(struct ntb_dev *ntb);
229 int (*db_is_unsafe)(struct ntb_dev *ntb);
230 u64 (*db_valid_mask)(struct ntb_dev *ntb);
231 int (*db_vector_count)(struct ntb_dev *ntb);
232 u64 (*db_vector_mask)(struct ntb_dev *ntb, int db_vector);
234 u64 (*db_read)(struct ntb_dev *ntb);
235 int (*db_set)(struct ntb_dev *ntb, u64 db_bits);
236 int (*db_clear)(struct ntb_dev *ntb, u64 db_bits);
238 u64 (*db_read_mask)(struct ntb_dev *ntb);
239 int (*db_set_mask)(struct ntb_dev *ntb, u64 db_bits);
240 int (*db_clear_mask)(struct ntb_dev *ntb, u64 db_bits);
242 int (*peer_db_addr)(struct ntb_dev *ntb,
243 phys_addr_t *db_addr, resource_size_t *db_size);
244 u64 (*peer_db_read)(struct ntb_dev *ntb);
245 int (*peer_db_set)(struct ntb_dev *ntb, u64 db_bits);
246 int (*peer_db_clear)(struct ntb_dev *ntb, u64 db_bits);
248 u64 (*peer_db_read_mask)(struct ntb_dev *ntb);
249 int (*peer_db_set_mask)(struct ntb_dev *ntb, u64 db_bits);
250 int (*peer_db_clear_mask)(struct ntb_dev *ntb, u64 db_bits);
252 int (*spad_is_unsafe)(struct ntb_dev *ntb);
253 int (*spad_count)(struct ntb_dev *ntb);
255 u32 (*spad_read)(struct ntb_dev *ntb, int idx);
256 int (*spad_write)(struct ntb_dev *ntb, int idx, u32 val);
258 int (*peer_spad_addr)(struct ntb_dev *ntb, int idx,
259 phys_addr_t *spad_addr);
260 u32 (*peer_spad_read)(struct ntb_dev *ntb, int idx);
261 int (*peer_spad_write)(struct ntb_dev *ntb, int idx, u32 val);
264 static inline int ntb_dev_ops_is_valid(const struct ntb_dev_ops *ops)
266 /* commented callbacks are not required: */
267 return
268 ops->mw_count &&
269 ops->mw_get_range &&
270 ops->mw_set_trans &&
271 /* ops->mw_clear_trans && */
272 ops->link_is_up &&
273 ops->link_enable &&
274 ops->link_disable &&
275 /* ops->db_is_unsafe && */
276 ops->db_valid_mask &&
278 /* both set, or both unset */
279 (!ops->db_vector_count == !ops->db_vector_mask) &&
281 ops->db_read &&
282 /* ops->db_set && */
283 ops->db_clear &&
284 /* ops->db_read_mask && */
285 ops->db_set_mask &&
286 ops->db_clear_mask &&
287 ops->peer_db_addr &&
288 /* ops->peer_db_read && */
289 ops->peer_db_set &&
290 /* ops->peer_db_clear && */
291 /* ops->peer_db_read_mask && */
292 /* ops->peer_db_set_mask && */
293 /* ops->peer_db_clear_mask && */
294 /* ops->spad_is_unsafe && */
295 ops->spad_count &&
296 ops->spad_read &&
297 ops->spad_write &&
298 ops->peer_spad_addr &&
299 /* ops->peer_spad_read && */
300 ops->peer_spad_write &&
305 * struct ntb_client - client interested in ntb devices
306 * @drv: Linux driver object.
307 * @ops: See &ntb_client_ops.
309 struct ntb_client {
310 struct device_driver drv;
311 const struct ntb_client_ops ops;
314 #define drv_ntb_client(__drv) container_of((__drv), struct ntb_client, drv)
317 * struct ntb_device - ntb device
318 * @dev: Linux device object.
319 * @pdev: Pci device entry of the ntb.
320 * @topo: Detected topology of the ntb.
321 * @ops: See &ntb_dev_ops.
322 * @ctx: See &ntb_ctx_ops.
323 * @ctx_ops: See &ntb_ctx_ops.
325 struct ntb_dev {
326 struct device dev;
327 struct pci_dev *pdev;
328 enum ntb_topo topo;
329 const struct ntb_dev_ops *ops;
330 void *ctx;
331 const struct ntb_ctx_ops *ctx_ops;
333 /* private: */
335 /* synchronize setting, clearing, and calling ctx_ops */
336 spinlock_t ctx_lock;
337 /* block unregister until device is fully released */
338 struct completion released;
341 #define dev_ntb(__dev) container_of((__dev), struct ntb_dev, dev)
344 * ntb_register_client() - register a client for interest in ntb devices
345 * @client: Client context.
347 * The client will be added to the list of clients interested in ntb devices.
348 * The client will be notified of any ntb devices that are not already
349 * associated with a client, or if ntb devices are registered later.
351 * Return: Zero if the client is registered, otherwise an error number.
353 #define ntb_register_client(client) \
354 __ntb_register_client((client), THIS_MODULE, KBUILD_MODNAME)
356 int __ntb_register_client(struct ntb_client *client, struct module *mod,
357 const char *mod_name);
360 * ntb_unregister_client() - unregister a client for interest in ntb devices
361 * @client: Client context.
363 * The client will be removed from the list of clients interested in ntb
364 * devices. If any ntb devices are associated with the client, the client will
365 * be notified to remove those devices.
367 void ntb_unregister_client(struct ntb_client *client);
369 #define module_ntb_client(__ntb_client) \
370 module_driver(__ntb_client, ntb_register_client, \
371 ntb_unregister_client)
374 * ntb_register_device() - register a ntb device
375 * @ntb: NTB device context.
377 * The device will be added to the list of ntb devices. If any clients are
378 * interested in ntb devices, each client will be notified of the ntb device,
379 * until at most one client accepts the device.
381 * Return: Zero if the device is registered, otherwise an error number.
383 int ntb_register_device(struct ntb_dev *ntb);
386 * ntb_register_device() - unregister a ntb device
387 * @ntb: NTB device context.
389 * The device will be removed from the list of ntb devices. If the ntb device
390 * is associated with a client, the client will be notified to remove the
391 * device.
393 void ntb_unregister_device(struct ntb_dev *ntb);
396 * ntb_set_ctx() - associate a driver context with an ntb device
397 * @ntb: NTB device context.
398 * @ctx: Driver context.
399 * @ctx_ops: Driver context operations.
401 * Associate a driver context and operations with a ntb device. The context is
402 * provided by the client driver, and the driver may associate a different
403 * context with each ntb device.
405 * Return: Zero if the context is associated, otherwise an error number.
407 int ntb_set_ctx(struct ntb_dev *ntb, void *ctx,
408 const struct ntb_ctx_ops *ctx_ops);
411 * ntb_clear_ctx() - disassociate any driver context from an ntb device
412 * @ntb: NTB device context.
414 * Clear any association that may exist between a driver context and the ntb
415 * device.
417 void ntb_clear_ctx(struct ntb_dev *ntb);
420 * ntb_link_event() - notify driver context of a change in link status
421 * @ntb: NTB device context.
423 * Notify the driver context that the link status may have changed. The driver
424 * should call ntb_link_is_up() to get the current status.
426 void ntb_link_event(struct ntb_dev *ntb);
429 * ntb_db_event() - notify driver context of a doorbell event
430 * @ntb: NTB device context.
431 * @vector: Interrupt vector number.
433 * Notify the driver context of a doorbell event. If hardware supports
434 * multiple interrupt vectors for doorbells, the vector number indicates which
435 * vector received the interrupt. The vector number is relative to the first
436 * vector used for doorbells, starting at zero, and must be less than
437 ** ntb_db_vector_count(). The driver may call ntb_db_read() to check which
438 * doorbell bits need service, and ntb_db_vector_mask() to determine which of
439 * those bits are associated with the vector number.
441 void ntb_db_event(struct ntb_dev *ntb, int vector);
444 * ntb_mw_count() - get the number of memory windows
445 * @ntb: NTB device context.
447 * Hardware and topology may support a different number of memory windows.
449 * Return: the number of memory windows.
451 static inline int ntb_mw_count(struct ntb_dev *ntb)
453 return ntb->ops->mw_count(ntb);
457 * ntb_mw_get_range() - get the range of a memory window
458 * @ntb: NTB device context.
459 * @idx: Memory window number.
460 * @base: OUT - the base address for mapping the memory window
461 * @size: OUT - the size for mapping the memory window
462 * @align: OUT - the base alignment for translating the memory window
463 * @align_size: OUT - the size alignment for translating the memory window
465 * Get the range of a memory window. NULL may be given for any output
466 * parameter if the value is not needed. The base and size may be used for
467 * mapping the memory window, to access the peer memory. The alignment and
468 * size may be used for translating the memory window, for the peer to access
469 * memory on the local system.
471 * Return: Zero on success, otherwise an error number.
473 static inline int ntb_mw_get_range(struct ntb_dev *ntb, int idx,
474 phys_addr_t *base, resource_size_t *size,
475 resource_size_t *align, resource_size_t *align_size)
477 return ntb->ops->mw_get_range(ntb, idx, base, size,
478 align, align_size);
482 * ntb_mw_set_trans() - set the translation of a memory window
483 * @ntb: NTB device context.
484 * @idx: Memory window number.
485 * @addr: The dma address local memory to expose to the peer.
486 * @size: The size of the local memory to expose to the peer.
488 * Set the translation of a memory window. The peer may access local memory
489 * through the window starting at the address, up to the size. The address
490 * must be aligned to the alignment specified by ntb_mw_get_range(). The size
491 * must be aligned to the size alignment specified by ntb_mw_get_range().
493 * Return: Zero on success, otherwise an error number.
495 static inline int ntb_mw_set_trans(struct ntb_dev *ntb, int idx,
496 dma_addr_t addr, resource_size_t size)
498 return ntb->ops->mw_set_trans(ntb, idx, addr, size);
502 * ntb_mw_clear_trans() - clear the translation of a memory window
503 * @ntb: NTB device context.
504 * @idx: Memory window number.
506 * Clear the translation of a memory window. The peer may no longer access
507 * local memory through the window.
509 * Return: Zero on success, otherwise an error number.
511 static inline int ntb_mw_clear_trans(struct ntb_dev *ntb, int idx)
513 if (!ntb->ops->mw_clear_trans)
514 return ntb->ops->mw_set_trans(ntb, idx, 0, 0);
516 return ntb->ops->mw_clear_trans(ntb, idx);
520 * ntb_link_is_up() - get the current ntb link state
521 * @ntb: NTB device context.
522 * @speed: OUT - The link speed expressed as PCIe generation number.
523 * @width: OUT - The link width expressed as the number of PCIe lanes.
525 * Get the current state of the ntb link. It is recommended to query the link
526 * state once after every link event. It is safe to query the link state in
527 * the context of the link event callback.
529 * Return: One if the link is up, zero if the link is down, otherwise a
530 * negative value indicating the error number.
532 static inline int ntb_link_is_up(struct ntb_dev *ntb,
533 enum ntb_speed *speed, enum ntb_width *width)
535 return ntb->ops->link_is_up(ntb, speed, width);
539 * ntb_link_enable() - enable the link on the secondary side of the ntb
540 * @ntb: NTB device context.
541 * @max_speed: The maximum link speed expressed as PCIe generation number.
542 * @max_width: The maximum link width expressed as the number of PCIe lanes.
544 * Enable the link on the secondary side of the ntb. This can only be done
545 * from the primary side of the ntb in primary or b2b topology. The ntb device
546 * should train the link to its maximum speed and width, or the requested speed
547 * and width, whichever is smaller, if supported.
549 * Return: Zero on success, otherwise an error number.
551 static inline int ntb_link_enable(struct ntb_dev *ntb,
552 enum ntb_speed max_speed,
553 enum ntb_width max_width)
555 return ntb->ops->link_enable(ntb, max_speed, max_width);
559 * ntb_link_disable() - disable the link on the secondary side of the ntb
560 * @ntb: NTB device context.
562 * Disable the link on the secondary side of the ntb. This can only be
563 * done from the primary side of the ntb in primary or b2b topology. The ntb
564 * device should disable the link. Returning from this call must indicate that
565 * a barrier has passed, though with no more writes may pass in either
566 * direction across the link, except if this call returns an error number.
568 * Return: Zero on success, otherwise an error number.
570 static inline int ntb_link_disable(struct ntb_dev *ntb)
572 return ntb->ops->link_disable(ntb);
576 * ntb_db_is_unsafe() - check if it is safe to use hardware doorbell
577 * @ntb: NTB device context.
579 * It is possible for some ntb hardware to be affected by errata. Hardware
580 * drivers can advise clients to avoid using doorbells. Clients may ignore
581 * this advice, though caution is recommended.
583 * Return: Zero if it is safe to use doorbells, or One if it is not safe.
585 static inline int ntb_db_is_unsafe(struct ntb_dev *ntb)
587 if (!ntb->ops->db_is_unsafe)
588 return 0;
590 return ntb->ops->db_is_unsafe(ntb);
594 * ntb_db_valid_mask() - get a mask of doorbell bits supported by the ntb
595 * @ntb: NTB device context.
597 * Hardware may support different number or arrangement of doorbell bits.
599 * Return: A mask of doorbell bits supported by the ntb.
601 static inline u64 ntb_db_valid_mask(struct ntb_dev *ntb)
603 return ntb->ops->db_valid_mask(ntb);
607 * ntb_db_vector_count() - get the number of doorbell interrupt vectors
608 * @ntb: NTB device context.
610 * Hardware may support different number of interrupt vectors.
612 * Return: The number of doorbell interrupt vectors.
614 static inline int ntb_db_vector_count(struct ntb_dev *ntb)
616 if (!ntb->ops->db_vector_count)
617 return 1;
619 return ntb->ops->db_vector_count(ntb);
623 * ntb_db_vector_mask() - get a mask of doorbell bits serviced by a vector
624 * @ntb: NTB device context.
625 * @vector: Doorbell vector number.
627 * Each interrupt vector may have a different number or arrangement of bits.
629 * Return: A mask of doorbell bits serviced by a vector.
631 static inline u64 ntb_db_vector_mask(struct ntb_dev *ntb, int vector)
633 if (!ntb->ops->db_vector_mask)
634 return ntb_db_valid_mask(ntb);
636 return ntb->ops->db_vector_mask(ntb, vector);
640 * ntb_db_read() - read the local doorbell register
641 * @ntb: NTB device context.
643 * Read the local doorbell register, and return the bits that are set.
645 * Return: The bits currently set in the local doorbell register.
647 static inline u64 ntb_db_read(struct ntb_dev *ntb)
649 return ntb->ops->db_read(ntb);
653 * ntb_db_set() - set bits in the local doorbell register
654 * @ntb: NTB device context.
655 * @db_bits: Doorbell bits to set.
657 * Set bits in the local doorbell register, which may generate a local doorbell
658 * interrupt. Bits that were already set must remain set.
660 * This is unusual, and hardware may not support it.
662 * Return: Zero on success, otherwise an error number.
664 static inline int ntb_db_set(struct ntb_dev *ntb, u64 db_bits)
666 if (!ntb->ops->db_set)
667 return -EINVAL;
669 return ntb->ops->db_set(ntb, db_bits);
673 * ntb_db_clear() - clear bits in the local doorbell register
674 * @ntb: NTB device context.
675 * @db_bits: Doorbell bits to clear.
677 * Clear bits in the local doorbell register, arming the bits for the next
678 * doorbell.
680 * Return: Zero on success, otherwise an error number.
682 static inline int ntb_db_clear(struct ntb_dev *ntb, u64 db_bits)
684 return ntb->ops->db_clear(ntb, db_bits);
688 * ntb_db_read_mask() - read the local doorbell mask
689 * @ntb: NTB device context.
691 * Read the local doorbell mask register, and return the bits that are set.
693 * This is unusual, though hardware is likely to support it.
695 * Return: The bits currently set in the local doorbell mask register.
697 static inline u64 ntb_db_read_mask(struct ntb_dev *ntb)
699 if (!ntb->ops->db_read_mask)
700 return 0;
702 return ntb->ops->db_read_mask(ntb);
706 * ntb_db_set_mask() - set bits in the local doorbell mask
707 * @ntb: NTB device context.
708 * @db_bits: Doorbell mask bits to set.
710 * Set bits in the local doorbell mask register, preventing doorbell interrupts
711 * from being generated for those doorbell bits. Bits that were already set
712 * must remain set.
714 * Return: Zero on success, otherwise an error number.
716 static inline int ntb_db_set_mask(struct ntb_dev *ntb, u64 db_bits)
718 return ntb->ops->db_set_mask(ntb, db_bits);
722 * ntb_db_clear_mask() - clear bits in the local doorbell mask
723 * @ntb: NTB device context.
724 * @db_bits: Doorbell bits to clear.
726 * Clear bits in the local doorbell mask register, allowing doorbell interrupts
727 * from being generated for those doorbell bits. If a doorbell bit is already
728 * set at the time the mask is cleared, and the corresponding mask bit is
729 * changed from set to clear, then the ntb driver must ensure that
730 * ntb_db_event() is called. If the hardware does not generate the interrupt
731 * on clearing the mask bit, then the driver must call ntb_db_event() anyway.
733 * Return: Zero on success, otherwise an error number.
735 static inline int ntb_db_clear_mask(struct ntb_dev *ntb, u64 db_bits)
737 return ntb->ops->db_clear_mask(ntb, db_bits);
741 * ntb_peer_db_addr() - address and size of the peer doorbell register
742 * @ntb: NTB device context.
743 * @db_addr: OUT - The address of the peer doorbell register.
744 * @db_size: OUT - The number of bytes to write the peer doorbell register.
746 * Return the address of the peer doorbell register. This may be used, for
747 * example, by drivers that offload memory copy operations to a dma engine.
748 * The drivers may wish to ring the peer doorbell at the completion of memory
749 * copy operations. For efficiency, and to simplify ordering of operations
750 * between the dma memory copies and the ringing doorbell, the driver may
751 * append one additional dma memory copy with the doorbell register as the
752 * destination, after the memory copy operations.
754 * Return: Zero on success, otherwise an error number.
756 static inline int ntb_peer_db_addr(struct ntb_dev *ntb,
757 phys_addr_t *db_addr,
758 resource_size_t *db_size)
760 return ntb->ops->peer_db_addr(ntb, db_addr, db_size);
764 * ntb_peer_db_read() - read the peer doorbell register
765 * @ntb: NTB device context.
767 * Read the peer doorbell register, and return the bits that are set.
769 * This is unusual, and hardware may not support it.
771 * Return: The bits currently set in the peer doorbell register.
773 static inline u64 ntb_peer_db_read(struct ntb_dev *ntb)
775 if (!ntb->ops->peer_db_read)
776 return 0;
778 return ntb->ops->peer_db_read(ntb);
782 * ntb_peer_db_set() - set bits in the peer doorbell register
783 * @ntb: NTB device context.
784 * @db_bits: Doorbell bits to set.
786 * Set bits in the peer doorbell register, which may generate a peer doorbell
787 * interrupt. Bits that were already set must remain set.
789 * Return: Zero on success, otherwise an error number.
791 static inline int ntb_peer_db_set(struct ntb_dev *ntb, u64 db_bits)
793 return ntb->ops->peer_db_set(ntb, db_bits);
797 * ntb_peer_db_clear() - clear bits in the peer doorbell register
798 * @ntb: NTB device context.
799 * @db_bits: Doorbell bits to clear.
801 * Clear bits in the peer doorbell register, arming the bits for the next
802 * doorbell.
804 * This is unusual, and hardware may not support it.
806 * Return: Zero on success, otherwise an error number.
808 static inline int ntb_peer_db_clear(struct ntb_dev *ntb, u64 db_bits)
810 if (!ntb->ops->db_clear)
811 return -EINVAL;
813 return ntb->ops->peer_db_clear(ntb, db_bits);
817 * ntb_peer_db_read_mask() - read the peer doorbell mask
818 * @ntb: NTB device context.
820 * Read the peer doorbell mask register, and return the bits that are set.
822 * This is unusual, and hardware may not support it.
824 * Return: The bits currently set in the peer doorbell mask register.
826 static inline u64 ntb_peer_db_read_mask(struct ntb_dev *ntb)
828 if (!ntb->ops->db_read_mask)
829 return 0;
831 return ntb->ops->peer_db_read_mask(ntb);
835 * ntb_peer_db_set_mask() - set bits in the peer doorbell mask
836 * @ntb: NTB device context.
837 * @db_bits: Doorbell mask bits to set.
839 * Set bits in the peer doorbell mask register, preventing doorbell interrupts
840 * from being generated for those doorbell bits. Bits that were already set
841 * must remain set.
843 * This is unusual, and hardware may not support it.
845 * Return: Zero on success, otherwise an error number.
847 static inline int ntb_peer_db_set_mask(struct ntb_dev *ntb, u64 db_bits)
849 if (!ntb->ops->db_set_mask)
850 return -EINVAL;
852 return ntb->ops->peer_db_set_mask(ntb, db_bits);
856 * ntb_peer_db_clear_mask() - clear bits in the peer doorbell mask
857 * @ntb: NTB device context.
858 * @db_bits: Doorbell bits to clear.
860 * Clear bits in the peer doorbell mask register, allowing doorbell interrupts
861 * from being generated for those doorbell bits. If the hardware does not
862 * generate the interrupt on clearing the mask bit, then the driver should not
863 * implement this function!
865 * This is unusual, and hardware may not support it.
867 * Return: Zero on success, otherwise an error number.
869 static inline int ntb_peer_db_clear_mask(struct ntb_dev *ntb, u64 db_bits)
871 if (!ntb->ops->db_clear_mask)
872 return -EINVAL;
874 return ntb->ops->peer_db_clear_mask(ntb, db_bits);
878 * ntb_spad_is_unsafe() - check if it is safe to use the hardware scratchpads
879 * @ntb: NTB device context.
881 * It is possible for some ntb hardware to be affected by errata. Hardware
882 * drivers can advise clients to avoid using scratchpads. Clients may ignore
883 * this advice, though caution is recommended.
885 * Return: Zero if it is safe to use scratchpads, or One if it is not safe.
887 static inline int ntb_spad_is_unsafe(struct ntb_dev *ntb)
889 if (!ntb->ops->spad_is_unsafe)
890 return 0;
892 return ntb->ops->spad_is_unsafe(ntb);
896 * ntb_mw_count() - get the number of scratchpads
897 * @ntb: NTB device context.
899 * Hardware and topology may support a different number of scratchpads.
901 * Return: the number of scratchpads.
903 static inline int ntb_spad_count(struct ntb_dev *ntb)
905 return ntb->ops->spad_count(ntb);
909 * ntb_spad_read() - read the local scratchpad register
910 * @ntb: NTB device context.
911 * @idx: Scratchpad index.
913 * Read the local scratchpad register, and return the value.
915 * Return: The value of the local scratchpad register.
917 static inline u32 ntb_spad_read(struct ntb_dev *ntb, int idx)
919 return ntb->ops->spad_read(ntb, idx);
923 * ntb_spad_write() - write the local scratchpad register
924 * @ntb: NTB device context.
925 * @idx: Scratchpad index.
926 * @val: Scratchpad value.
928 * Write the value to the local scratchpad register.
930 * Return: Zero on success, otherwise an error number.
932 static inline int ntb_spad_write(struct ntb_dev *ntb, int idx, u32 val)
934 return ntb->ops->spad_write(ntb, idx, val);
938 * ntb_peer_spad_addr() - address of the peer scratchpad register
939 * @ntb: NTB device context.
940 * @idx: Scratchpad index.
941 * @spad_addr: OUT - The address of the peer scratchpad register.
943 * Return the address of the peer doorbell register. This may be used, for
944 * example, by drivers that offload memory copy operations to a dma engine.
946 * Return: Zero on success, otherwise an error number.
948 static inline int ntb_peer_spad_addr(struct ntb_dev *ntb, int idx,
949 phys_addr_t *spad_addr)
951 return ntb->ops->peer_spad_addr(ntb, idx, spad_addr);
955 * ntb_peer_spad_read() - read the peer scratchpad register
956 * @ntb: NTB device context.
957 * @idx: Scratchpad index.
959 * Read the peer scratchpad register, and return the value.
961 * Return: The value of the local scratchpad register.
963 static inline u32 ntb_peer_spad_read(struct ntb_dev *ntb, int idx)
965 return ntb->ops->peer_spad_read(ntb, idx);
969 * ntb_peer_spad_write() - write the peer scratchpad register
970 * @ntb: NTB device context.
971 * @idx: Scratchpad index.
972 * @val: Scratchpad value.
974 * Write the value to the peer scratchpad register.
976 * Return: Zero on success, otherwise an error number.
978 static inline int ntb_peer_spad_write(struct ntb_dev *ntb, int idx, u32 val)
980 return ntb->ops->peer_spad_write(ntb, idx, val);
983 #endif