Carl van Schaik | 6d7b2ff | 2018-07-06 22:00:55 +1000 | [diff] [blame] | 1 | /* |
| 2 | * include/vservices/transport.h |
| 3 | * |
| 4 | * Copyright (c) 2012-2018 General Dynamics |
| 5 | * Copyright (c) 2014 Open Kernel Labs, Inc. |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License version 2 as |
| 9 | * published by the Free Software Foundation. |
| 10 | * |
| 11 | * This file contains the transport vtable structure. This is made public so |
| 12 | * that the application drivers can call the vtable functions directly (via |
| 13 | * the inlined wrappers in service.h) rather than indirectly via a function |
| 14 | * call. |
| 15 | * |
| 16 | */ |
| 17 | |
| 18 | #ifndef _VSERVICES_TRANSPORT_H_ |
| 19 | #define _VSERVICES_TRANSPORT_H_ |
| 20 | |
| 21 | #include <linux/types.h> |
| 22 | |
| 23 | #include <vservices/types.h> |
| 24 | |
| 25 | struct vs_transport; |
| 26 | struct vs_mbuf; |
| 27 | struct vs_service_device; |
| 28 | |
| 29 | /** |
| 30 | * struct vs_transport_vtable - Transport driver operations. Transport drivers |
| 31 | * must provide implementations for all operations in this table. |
| 32 | * --- Message buffer allocation --- |
| 33 | * @alloc_mbuf: Allocate an mbuf of the given size for the given service |
| 34 | * @free_mbuf: Deallocate an mbuf |
| 35 | * @mbuf_size: Return the size in bytes of a message buffer. The size returned |
| 36 | * should be the total number of bytes including any headers. |
| 37 | * @max_mbuf_size: Return the maximum allowable message buffer allocation size. |
| 38 | * --- Message sending --- |
| 39 | * @send: Queue an mbuf for sending |
| 40 | * @flush: Start the transfer for the current message batch, if any |
| 41 | * @notify: Send a notification |
| 42 | * --- Transport-level reset handling --- |
| 43 | * @reset: Reset the transport layer |
| 44 | * @ready: Ready the transport layer |
| 45 | * --- Service management --- |
| 46 | * @service_add: A new service has been added to this transport's session |
| 47 | * @service_remove: A service has been removed from this transport's session |
| 48 | * @service_start: A service on this transport's session has had its resource |
| 49 | * allocations set and is about to start. This is always interleaved with |
| 50 | * service_reset, with one specific exception: the core service client, |
| 51 | * which has its quotas initially hard-coded to 0 send / 1 recv and |
| 52 | * adjusted when the initial startup message arrives. |
| 53 | * @service_reset: A service on this transport's session has just been reset, |
| 54 | * and any resources allocated to it should be cleaned up to prepare |
| 55 | * for later reallocation. |
| 56 | * @service_send_avail: The number of message buffers that this service is |
| 57 | * able to send before going over quota. |
| 58 | * --- Query transport capabilities --- |
| 59 | * @get_notify_bits: Fetch the number of sent and received notification bits |
| 60 | * supported by this transport. Note that this can be any positive value |
| 61 | * up to UINT_MAX. |
| 62 | * @get_quota_limits: Fetch the total send and receive message buffer quotas |
| 63 | * supported by this transport. Note that this can be any positive value |
| 64 | * up to UINT_MAX. |
| 65 | */ |
| 66 | struct vs_transport_vtable { |
| 67 | /* Message buffer allocation */ |
| 68 | struct vs_mbuf *(*alloc_mbuf)(struct vs_transport *transport, |
| 69 | struct vs_service_device *service, size_t size, |
| 70 | gfp_t gfp_flags); |
| 71 | void (*free_mbuf)(struct vs_transport *transport, |
| 72 | struct vs_service_device *service, |
| 73 | struct vs_mbuf *mbuf); |
| 74 | size_t (*mbuf_size)(struct vs_mbuf *mbuf); |
| 75 | size_t (*max_mbuf_size)(struct vs_transport *transport); |
| 76 | |
| 77 | /* Sending messages */ |
| 78 | int (*send)(struct vs_transport *transport, |
| 79 | struct vs_service_device *service, |
| 80 | struct vs_mbuf *mbuf, unsigned long flags); |
| 81 | int (*flush)(struct vs_transport *transport, |
| 82 | struct vs_service_device *service); |
| 83 | int (*notify)(struct vs_transport *transport, |
| 84 | struct vs_service_device *service, |
| 85 | unsigned long bits); |
| 86 | |
| 87 | /* Raising and clearing transport-level reset */ |
| 88 | void (*reset)(struct vs_transport *transport); |
| 89 | void (*ready)(struct vs_transport *transport); |
| 90 | |
| 91 | /* Service management */ |
| 92 | int (*service_add)(struct vs_transport *transport, |
| 93 | struct vs_service_device *service); |
| 94 | void (*service_remove)(struct vs_transport *transport, |
| 95 | struct vs_service_device *service); |
| 96 | |
| 97 | int (*service_start)(struct vs_transport *transport, |
| 98 | struct vs_service_device *service); |
| 99 | int (*service_reset)(struct vs_transport *transport, |
| 100 | struct vs_service_device *service); |
| 101 | |
| 102 | ssize_t (*service_send_avail)(struct vs_transport *transport, |
| 103 | struct vs_service_device *service); |
| 104 | |
| 105 | /* Query transport capabilities */ |
| 106 | void (*get_notify_bits)(struct vs_transport *transport, |
| 107 | unsigned *send_notify_bits, unsigned *recv_notify_bits); |
| 108 | void (*get_quota_limits)(struct vs_transport *transport, |
| 109 | unsigned *send_quota, unsigned *recv_quota); |
| 110 | }; |
| 111 | |
| 112 | /* Flags for .send */ |
| 113 | #define VS_TRANSPORT_SEND_FLAGS_MORE 0x1 |
| 114 | |
| 115 | /** |
| 116 | * struct vs_transport - A structure representing a transport |
| 117 | * @type: type of transport i.e. microvisror/loopback etc |
| 118 | * @vt: Transport operations table |
| 119 | * @notify_info: Array of incoming notification settings |
| 120 | * @notify_info_size: Size of the incoming notification array |
| 121 | */ |
| 122 | struct vs_transport { |
| 123 | const char *type; |
| 124 | const struct vs_transport_vtable *vt; |
| 125 | struct vs_notify_info *notify_info; |
| 126 | int notify_info_size; |
| 127 | }; |
| 128 | |
| 129 | /** |
| 130 | * struct vs_mbuf - Message buffer. This is always allocated and released by the |
| 131 | * transport callbacks defined above, so it may be embedded in a |
| 132 | * transport-specific structure containing additional state. |
| 133 | * @data: Message data buffer |
| 134 | * @size: Size of the data buffer in bytes |
| 135 | * @is_recv: True if this mbuf was received from the other end of the |
| 136 | * transport. False if it was allocated by this end for sending. |
| 137 | * @priv: Private value that will not be touched by the framework |
| 138 | * @queue: list_head for entry in lists. The session layer uses this queue |
| 139 | * for receiving messages. The transport driver may use this queue for its |
| 140 | * own purposes when sending messages. |
| 141 | */ |
| 142 | struct vs_mbuf { |
| 143 | void *data; |
| 144 | size_t size; |
| 145 | bool is_recv; |
| 146 | void *priv; |
| 147 | struct list_head queue; |
| 148 | }; |
| 149 | |
| 150 | #endif /* _VSERVICES_TRANSPORT_H_ */ |