Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2016 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_fifo_segment_h__ |
| 16 | #define __included_ssvm_fifo_segment_h__ |
| 17 | |
Florin Coras | 6792ec0 | 2017-03-13 03:49:51 -0700 | [diff] [blame] | 18 | #include <svm/svm_fifo.h> |
| 19 | #include <svm/ssvm.h> |
Florin Coras | a546481 | 2017-04-19 13:00:05 -0700 | [diff] [blame] | 20 | #include <vppinfra/lock.h> |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 21 | |
Dave Barach | 10d8cc6 | 2017-05-30 09:30:07 -0400 | [diff] [blame] | 22 | typedef enum |
| 23 | { |
| 24 | FIFO_SEGMENT_FREELIST_NONE = -1, |
| 25 | FIFO_SEGMENT_RX_FREELIST = 0, |
| 26 | FIFO_SEGMENT_TX_FREELIST, |
| 27 | FIFO_SEGMENT_N_FREELISTS |
| 28 | } svm_fifo_segment_freelist_t; |
| 29 | |
Dave Barach | 818eb54 | 2017-08-02 13:56:13 -0400 | [diff] [blame^] | 30 | #define FIFO_SEGMENT_MIN_FIFO_SIZE 2048 |
| 31 | #define FIFO_SEGMENT_MAX_FIFO_SIZE (8<<20) /* 8mb max fifo size */ |
| 32 | #define FIFO_SEGMENT_ALLOC_CHUNK_SIZE 32 /* allocation quantum */ |
| 33 | |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 34 | typedef struct |
| 35 | { |
Dave Barach | 10d8cc6 | 2017-05-30 09:30:07 -0400 | [diff] [blame] | 36 | svm_fifo_t *fifos; /**< Linked list of active RX fifos */ |
| 37 | u8 *segment_name; /**< Segment name */ |
Dave Barach | 818eb54 | 2017-08-02 13:56:13 -0400 | [diff] [blame^] | 38 | svm_fifo_t **free_fifos; /**< Freelists, by fifo size */ |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 39 | } svm_fifo_segment_header_t; |
| 40 | |
| 41 | typedef struct |
| 42 | { |
| 43 | ssvm_private_t ssvm; |
| 44 | svm_fifo_segment_header_t *h; |
| 45 | } svm_fifo_segment_private_t; |
| 46 | |
| 47 | typedef struct |
| 48 | { |
Florin Coras | a546481 | 2017-04-19 13:00:05 -0700 | [diff] [blame] | 49 | volatile u32 lock; |
| 50 | |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 51 | /** pool of segments */ |
| 52 | svm_fifo_segment_private_t *segments; |
| 53 | /* Where to put the next one */ |
| 54 | u64 next_baseva; |
| 55 | u32 timeout_in_seconds; |
| 56 | } svm_fifo_segment_main_t; |
| 57 | |
| 58 | extern svm_fifo_segment_main_t svm_fifo_segment_main; |
| 59 | |
| 60 | typedef struct |
| 61 | { |
| 62 | char *segment_name; |
| 63 | u32 segment_size; |
Dave Barach | 2c25a62 | 2017-06-26 11:35:07 -0400 | [diff] [blame] | 64 | u32 *new_segment_indices; |
Dave Barach | 10d8cc6 | 2017-05-30 09:30:07 -0400 | [diff] [blame] | 65 | u32 rx_fifo_size; |
| 66 | u32 tx_fifo_size; |
| 67 | u32 preallocated_fifo_pairs; |
Dave Barach | 2c25a62 | 2017-06-26 11:35:07 -0400 | [diff] [blame] | 68 | u32 private_segment_count; |
| 69 | u32 private_segment_size; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 70 | } svm_fifo_segment_create_args_t; |
| 71 | |
| 72 | static inline svm_fifo_segment_private_t * |
| 73 | svm_fifo_get_segment (u32 segment_index) |
| 74 | { |
| 75 | svm_fifo_segment_main_t *ssm = &svm_fifo_segment_main; |
| 76 | return vec_elt_at_index (ssm->segments, segment_index); |
| 77 | } |
| 78 | |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 79 | static inline u8 |
| 80 | svm_fifo_segment_has_fifos (svm_fifo_segment_private_t * fifo_segment) |
| 81 | { |
Dave Barach | 10d8cc6 | 2017-05-30 09:30:07 -0400 | [diff] [blame] | 82 | return fifo_segment->h->fifos != 0; |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 83 | } |
| 84 | |
Dave Barach | 10d8cc6 | 2017-05-30 09:30:07 -0400 | [diff] [blame] | 85 | static inline svm_fifo_t * |
| 86 | svm_fifo_segment_get_fifo_list (svm_fifo_segment_private_t * fifo_segment) |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 87 | { |
Dave Barach | 10d8cc6 | 2017-05-30 09:30:07 -0400 | [diff] [blame] | 88 | return fifo_segment->h->fifos; |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 89 | } |
| 90 | |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 91 | #define foreach_ssvm_fifo_segment_api_error \ |
| 92 | _(OUT_OF_SPACE, "Out of space in segment", -200) |
| 93 | |
| 94 | typedef enum |
| 95 | { |
| 96 | #define _(n,s,c) SSVM_FIFO_SEGMENT_API_ERROR_##n = c, |
| 97 | foreach_ssvm_fifo_segment_api_error |
| 98 | #undef _ |
| 99 | } ssvm_fifo_segment_api_error_enum_t; |
| 100 | |
| 101 | int svm_fifo_segment_create (svm_fifo_segment_create_args_t * a); |
Florin Coras | a546481 | 2017-04-19 13:00:05 -0700 | [diff] [blame] | 102 | int svm_fifo_segment_create_process_private (svm_fifo_segment_create_args_t |
| 103 | * a); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 104 | int svm_fifo_segment_attach (svm_fifo_segment_create_args_t * a); |
| 105 | void svm_fifo_segment_delete (svm_fifo_segment_private_t * s); |
| 106 | |
| 107 | svm_fifo_t *svm_fifo_segment_alloc_fifo (svm_fifo_segment_private_t * s, |
Dave Barach | 10d8cc6 | 2017-05-30 09:30:07 -0400 | [diff] [blame] | 108 | u32 data_size_in_bytes, |
| 109 | svm_fifo_segment_freelist_t index); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 110 | void svm_fifo_segment_free_fifo (svm_fifo_segment_private_t * s, |
Dave Barach | 10d8cc6 | 2017-05-30 09:30:07 -0400 | [diff] [blame] | 111 | svm_fifo_t * f, |
| 112 | svm_fifo_segment_freelist_t index); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 113 | void svm_fifo_segment_init (u64 baseva, u32 timeout_in_seconds); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 114 | u32 svm_fifo_segment_index (svm_fifo_segment_private_t * s); |
| 115 | |
| 116 | #endif /* __included_ssvm_fifo_segment_h__ */ |
| 117 | |
| 118 | /* |
| 119 | * fd.io coding-style-patch-verification: ON |
| 120 | * |
| 121 | * Local Variables: |
| 122 | * eval: (c-set-style "gnu") |
| 123 | * End: |
| 124 | */ |