Damjan Marion | 7cd468a | 2016-12-19 23:05:39 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2015 Cisco and/or its affiliates. |
| 3 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | * you may not use this file except in compliance with the License. |
| 5 | * You may obtain a copy of the License at: |
| 6 | * |
| 7 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | * |
| 9 | * Unless required by applicable law or agreed to in writing, software |
| 10 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | * See the License for the specific language governing permissions and |
| 13 | * limitations under the License. |
| 14 | */ |
| 15 | #ifndef __included_ssvm_eth_h__ |
| 16 | #define __included_ssvm_eth_h__ |
| 17 | |
| 18 | #include <vnet/vnet.h> |
| 19 | |
| 20 | #include <vppinfra/elog.h> |
| 21 | #include <vppinfra/error.h> |
| 22 | #include <vppinfra/format.h> |
| 23 | #include <vppinfra/hash.h> |
| 24 | #include <vppinfra/vec.h> |
| 25 | #include <vppinfra/elog.h> |
| 26 | #include <vlib/vlib.h> |
| 27 | #include <vnet/ethernet/ethernet.h> |
| 28 | #include <vnet/devices/devices.h> |
| 29 | #include <vnet/ip/ip.h> |
| 30 | #include <vnet/pg/pg.h> |
| 31 | #include <vlibmemory/unix_shared_memory_queue.h> |
| 32 | |
| 33 | #include <svm/ssvm.h> |
| 34 | |
| 35 | extern vnet_device_class_t ssvm_eth_device_class; |
| 36 | extern vlib_node_registration_t ssvm_eth_input_node; |
| 37 | |
| 38 | #define SSVM_BUFFER_SIZE \ |
| 39 | (VLIB_BUFFER_DATA_SIZE + VLIB_BUFFER_PRE_DATA_SIZE) |
| 40 | #define SSVM_PACKET_TYPE 1 |
| 41 | |
| 42 | typedef struct |
| 43 | { |
| 44 | /* Type of queue element */ |
| 45 | u8 type; |
| 46 | u8 flags; |
| 47 | #define SSVM_BUFFER_NEXT_PRESENT (1<<0) |
| 48 | u8 owner; |
| 49 | u8 tag; |
| 50 | i16 current_data_hint; |
| 51 | u16 length_this_buffer; |
| 52 | u16 total_length_not_including_first_buffer; |
| 53 | u16 pad; |
| 54 | u32 next_index; |
| 55 | /* offset 16 */ |
| 56 | u8 data[SSVM_BUFFER_SIZE]; |
| 57 | /* pad to an even multiple of 64 octets */ |
| 58 | u8 pad2[CLIB_CACHE_LINE_BYTES - 16]; |
| 59 | } ssvm_eth_queue_elt_t; |
| 60 | |
| 61 | typedef struct |
| 62 | { |
| 63 | /* vector of point-to-point connections */ |
| 64 | ssvm_private_t *intfcs; |
| 65 | |
| 66 | u32 *buffer_cache; |
| 67 | u32 *chunk_cache; |
| 68 | |
| 69 | /* Configurable parameters */ |
| 70 | /* base address for next placement */ |
| 71 | u64 next_base_va; |
| 72 | u64 segment_size; |
| 73 | u64 nbuffers; |
| 74 | u64 queue_elts; |
| 75 | |
| 76 | /* Segment names */ |
| 77 | u8 **names; |
| 78 | |
| 79 | /* convenience */ |
| 80 | vlib_main_t *vlib_main; |
| 81 | vnet_main_t *vnet_main; |
| 82 | elog_main_t *elog_main; |
| 83 | } ssvm_eth_main_t; |
| 84 | |
| 85 | ssvm_eth_main_t ssvm_eth_main; |
| 86 | |
| 87 | typedef enum |
| 88 | { |
| 89 | CHUNK_POOL_FREELIST_INDEX = 0, |
| 90 | CHUNK_POOL_INDEX, |
| 91 | CHUNK_POOL_NFREE, |
| 92 | TO_MASTER_Q_INDEX, |
| 93 | TO_SLAVE_Q_INDEX, |
| 94 | MASTER_ADMIN_STATE_INDEX, |
| 95 | SLAVE_ADMIN_STATE_INDEX, |
| 96 | } ssvm_eth_opaque_index_t; |
| 97 | |
| 98 | /* |
| 99 | * debug scaffolding. |
| 100 | */ |
| 101 | static inline void |
| 102 | ssvm_eth_validate_freelists (int need_lock) |
| 103 | { |
| 104 | #if CLIB_DEBUG > 0 |
| 105 | ssvm_eth_main_t *em = &ssvm_eth_main; |
| 106 | ssvm_private_t *intfc; |
| 107 | ssvm_shared_header_t *sh; |
| 108 | u32 *elt_indices; |
| 109 | u32 n_available; |
| 110 | int i; |
| 111 | |
| 112 | for (i = 0; i < vec_len (em->intfcs); i++) |
| 113 | { |
| 114 | intfc = em->intfcs + i; |
| 115 | sh = intfc->sh; |
| 116 | u32 my_pid = intfc->my_pid; |
| 117 | |
| 118 | if (need_lock) |
| 119 | ssvm_lock (sh, my_pid, 15); |
| 120 | |
| 121 | elt_indices = (u32 *) (sh->opaque[CHUNK_POOL_FREELIST_INDEX]); |
| 122 | n_available = (u32) (uword) (sh->opaque[CHUNK_POOL_NFREE]); |
| 123 | |
| 124 | for (i = 0; i < n_available; i++) |
| 125 | ASSERT (elt_indices[i] < 2048); |
| 126 | |
| 127 | if (need_lock) |
| 128 | ssvm_unlock (sh); |
| 129 | } |
| 130 | #endif |
| 131 | } |
| 132 | |
| 133 | #endif /* __included_ssvm_eth_h__ */ |
| 134 | |
| 135 | /* |
| 136 | * fd.io coding-style-patch-verification: ON |
| 137 | * |
| 138 | * Local Variables: |
| 139 | * eval: (c-set-style "gnu") |
| 140 | * End: |
| 141 | */ |