Damjan Marion | 8bdc63b | 2016-11-02 14:48:21 +0100 | [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 | |
| 16 | #ifndef included_vnet_vnet_device_h |
| 17 | #define included_vnet_vnet_device_h |
| 18 | |
| 19 | #include <vnet/unix/pcap.h> |
| 20 | #include <vnet/l3_types.h> |
| 21 | |
| 22 | typedef enum |
| 23 | { |
John Lo | a60d4cb | 2016-12-17 03:09:58 -0500 | [diff] [blame] | 24 | VNET_DEVICE_INPUT_NEXT_IP4_NCS_INPUT, |
Damjan Marion | 8bdc63b | 2016-11-02 14:48:21 +0100 | [diff] [blame] | 25 | VNET_DEVICE_INPUT_NEXT_IP4_INPUT, |
| 26 | VNET_DEVICE_INPUT_NEXT_IP6_INPUT, |
| 27 | VNET_DEVICE_INPUT_NEXT_MPLS_INPUT, |
| 28 | VNET_DEVICE_INPUT_NEXT_ETHERNET_INPUT, |
| 29 | VNET_DEVICE_INPUT_NEXT_DROP, |
| 30 | VNET_DEVICE_INPUT_N_NEXT_NODES, |
| 31 | } vnet_device_input_next_t; |
| 32 | |
| 33 | #define VNET_DEVICE_INPUT_NEXT_NODES { \ |
| 34 | [VNET_DEVICE_INPUT_NEXT_DROP] = "error-drop", \ |
| 35 | [VNET_DEVICE_INPUT_NEXT_ETHERNET_INPUT] = "ethernet-input", \ |
John Lo | a60d4cb | 2016-12-17 03:09:58 -0500 | [diff] [blame] | 36 | [VNET_DEVICE_INPUT_NEXT_IP4_NCS_INPUT] = "ip4-input-no-checksum", \ |
| 37 | [VNET_DEVICE_INPUT_NEXT_IP4_INPUT] = "ip4-input", \ |
Damjan Marion | 8bdc63b | 2016-11-02 14:48:21 +0100 | [diff] [blame] | 38 | [VNET_DEVICE_INPUT_NEXT_IP6_INPUT] = "ip6-input", \ |
| 39 | [VNET_DEVICE_INPUT_NEXT_MPLS_INPUT] = "mpls-input", \ |
| 40 | } |
| 41 | |
Damjan Marion | b3bb101 | 2017-02-28 21:55:28 +0100 | [diff] [blame] | 42 | typedef struct |
| 43 | { |
| 44 | CLIB_CACHE_LINE_ALIGN_MARK (cacheline0); |
| 45 | |
| 46 | /* total input packet counter */ |
| 47 | u64 aggregate_rx_packets; |
| 48 | } vnet_device_per_worker_data_t; |
| 49 | |
| 50 | typedef struct |
| 51 | { |
| 52 | vnet_device_per_worker_data_t *workers; |
Damjan Marion | 586afd7 | 2017-04-05 19:18:20 +0200 | [diff] [blame] | 53 | uword first_worker_thread_index; |
| 54 | uword last_worker_thread_index; |
| 55 | uword next_worker_thread_index; |
Damjan Marion | b3bb101 | 2017-02-28 21:55:28 +0100 | [diff] [blame] | 56 | } vnet_device_main_t; |
| 57 | |
Damjan Marion | eb743fa | 2017-03-20 16:34:15 +0100 | [diff] [blame] | 58 | typedef struct |
| 59 | { |
| 60 | u32 hw_if_index; |
| 61 | u32 dev_instance; |
| 62 | u16 queue_id; |
Damjan Marion | 4403690 | 2017-04-28 12:29:15 +0200 | [diff] [blame] | 63 | vnet_hw_interface_rx_mode mode; |
Christophe Fontaine | 26054ea | 2017-06-20 13:57:47 +0200 | [diff] [blame] | 64 | u32 interrupt_pending; |
Damjan Marion | eb743fa | 2017-03-20 16:34:15 +0100 | [diff] [blame] | 65 | } vnet_device_and_queue_t; |
| 66 | |
| 67 | typedef struct |
| 68 | { |
| 69 | vnet_device_and_queue_t *devices_and_queues; |
Damjan Marion | 153646e | 2017-04-05 18:15:45 +0200 | [diff] [blame] | 70 | vlib_node_state_t enabled_node_state; |
Damjan Marion | eb743fa | 2017-03-20 16:34:15 +0100 | [diff] [blame] | 71 | } vnet_device_input_runtime_t; |
| 72 | |
Damjan Marion | b3bb101 | 2017-02-28 21:55:28 +0100 | [diff] [blame] | 73 | extern vnet_device_main_t vnet_device_main; |
Damjan Marion | 51327ac | 2016-11-09 11:59:42 +0100 | [diff] [blame] | 74 | extern vlib_node_registration_t device_input_node; |
Damjan Marion | 7dc4146 | 2016-11-15 19:47:58 +0100 | [diff] [blame] | 75 | extern const u32 device_input_next_node_advance[]; |
Damjan Marion | bd846cd | 2017-11-21 13:12:41 +0100 | [diff] [blame] | 76 | extern const u32 device_input_next_node_flags[]; |
Damjan Marion | 51327ac | 2016-11-09 11:59:42 +0100 | [diff] [blame] | 77 | |
Damjan Marion | eb743fa | 2017-03-20 16:34:15 +0100 | [diff] [blame] | 78 | static inline void |
Damjan Marion | 4403690 | 2017-04-28 12:29:15 +0200 | [diff] [blame] | 79 | vnet_hw_interface_set_input_node (vnet_main_t * vnm, u32 hw_if_index, |
| 80 | u32 node_index) |
Damjan Marion | eb743fa | 2017-03-20 16:34:15 +0100 | [diff] [blame] | 81 | { |
Damjan Marion | eb743fa | 2017-03-20 16:34:15 +0100 | [diff] [blame] | 82 | vnet_hw_interface_t *hw = vnet_get_hw_interface (vnm, hw_if_index); |
| 83 | hw->input_node_index = node_index; |
| 84 | } |
| 85 | |
Damjan Marion | 4403690 | 2017-04-28 12:29:15 +0200 | [diff] [blame] | 86 | void vnet_hw_interface_assign_rx_thread (vnet_main_t * vnm, u32 hw_if_index, |
| 87 | u16 queue_id, uword thread_index); |
| 88 | int vnet_hw_interface_unassign_rx_thread (vnet_main_t * vnm, u32 hw_if_index, |
| 89 | u16 queue_id); |
| 90 | int vnet_hw_interface_set_rx_mode (vnet_main_t * vnm, u32 hw_if_index, |
| 91 | u16 queue_id, |
| 92 | vnet_hw_interface_rx_mode mode); |
| 93 | int vnet_hw_interface_get_rx_mode (vnet_main_t * vnm, u32 hw_if_index, |
| 94 | u16 queue_id, |
| 95 | vnet_hw_interface_rx_mode * mode); |
Damjan Marion | eb743fa | 2017-03-20 16:34:15 +0100 | [diff] [blame] | 96 | |
Damjan Marion | b3bb101 | 2017-02-28 21:55:28 +0100 | [diff] [blame] | 97 | static inline u64 |
| 98 | vnet_get_aggregate_rx_packets (void) |
| 99 | { |
| 100 | vnet_device_main_t *vdm = &vnet_device_main; |
| 101 | u64 sum = 0; |
| 102 | vnet_device_per_worker_data_t *pwd; |
| 103 | |
| 104 | vec_foreach (pwd, vdm->workers) sum += pwd->aggregate_rx_packets; |
| 105 | |
| 106 | return sum; |
| 107 | } |
| 108 | |
| 109 | static inline void |
Damjan Marion | 586afd7 | 2017-04-05 19:18:20 +0200 | [diff] [blame] | 110 | vnet_device_increment_rx_packets (u32 thread_index, u64 count) |
Damjan Marion | b3bb101 | 2017-02-28 21:55:28 +0100 | [diff] [blame] | 111 | { |
| 112 | vnet_device_main_t *vdm = &vnet_device_main; |
| 113 | vnet_device_per_worker_data_t *pwd; |
| 114 | |
Damjan Marion | 586afd7 | 2017-04-05 19:18:20 +0200 | [diff] [blame] | 115 | pwd = vec_elt_at_index (vdm->workers, thread_index); |
Damjan Marion | b3bb101 | 2017-02-28 21:55:28 +0100 | [diff] [blame] | 116 | pwd->aggregate_rx_packets += count; |
| 117 | } |
| 118 | |
Damjan Marion | eb743fa | 2017-03-20 16:34:15 +0100 | [diff] [blame] | 119 | static_always_inline vnet_device_and_queue_t * |
| 120 | vnet_get_device_and_queue (vlib_main_t * vm, vlib_node_runtime_t * node) |
| 121 | { |
| 122 | vnet_device_input_runtime_t *rt = (void *) node->runtime_data; |
| 123 | return rt->devices_and_queues; |
| 124 | } |
| 125 | |
Damjan Marion | 153646e | 2017-04-05 18:15:45 +0200 | [diff] [blame] | 126 | static_always_inline uword |
| 127 | vnet_get_device_input_thread_index (vnet_main_t * vnm, u32 hw_if_index, |
| 128 | u16 queue_id) |
| 129 | { |
| 130 | vnet_hw_interface_t *hw = vnet_get_hw_interface (vnm, hw_if_index); |
| 131 | ASSERT (queue_id < vec_len (hw->input_node_thread_index_by_queue)); |
| 132 | return hw->input_node_thread_index_by_queue[queue_id]; |
| 133 | } |
| 134 | |
Damjan Marion | eb743fa | 2017-03-20 16:34:15 +0100 | [diff] [blame] | 135 | static_always_inline void |
| 136 | vnet_device_input_set_interrupt_pending (vnet_main_t * vnm, u32 hw_if_index, |
| 137 | u16 queue_id) |
| 138 | { |
Damjan Marion | 153646e | 2017-04-05 18:15:45 +0200 | [diff] [blame] | 139 | vlib_main_t *vm; |
| 140 | vnet_hw_interface_t *hw; |
| 141 | vnet_device_input_runtime_t *rt; |
| 142 | vnet_device_and_queue_t *dq; |
| 143 | uword idx; |
Damjan Marion | eb743fa | 2017-03-20 16:34:15 +0100 | [diff] [blame] | 144 | |
Damjan Marion | 153646e | 2017-04-05 18:15:45 +0200 | [diff] [blame] | 145 | hw = vnet_get_hw_interface (vnm, hw_if_index); |
| 146 | idx = vnet_get_device_input_thread_index (vnm, hw_if_index, queue_id); |
| 147 | vm = vlib_mains[idx]; |
| 148 | rt = vlib_node_get_runtime_data (vm, hw->input_node_index); |
| 149 | idx = hw->dq_runtime_index_by_queue[queue_id]; |
| 150 | dq = vec_elt_at_index (rt->devices_and_queues, idx); |
| 151 | dq->interrupt_pending = 1; |
| 152 | |
| 153 | vlib_node_set_interrupt_pending (vm, hw->input_node_index); |
Damjan Marion | eb743fa | 2017-03-20 16:34:15 +0100 | [diff] [blame] | 154 | } |
| 155 | |
Dave Barach | 32f4e18 | 2018-03-20 08:49:02 -0400 | [diff] [blame] | 156 | #define foreach_device_and_queue(var,vec) \ |
| 157 | for (var = (vec); var < vec_end (vec); var++) \ |
| 158 | if ((var->mode == VNET_HW_INTERFACE_RX_MODE_POLLING) \ |
| 159 | || clib_smp_swap (&((var)->interrupt_pending), 0)) |
| 160 | |
Damjan Marion | 153646e | 2017-04-05 18:15:45 +0200 | [diff] [blame] | 161 | |
Damjan Marion | 8bdc63b | 2016-11-02 14:48:21 +0100 | [diff] [blame] | 162 | #endif /* included_vnet_vnet_device_h */ |
| 163 | |
| 164 | /* |
| 165 | * fd.io coding-style-patch-verification: ON |
| 166 | * |
| 167 | * Local Variables: |
| 168 | * eval: (c-set-style "gnu") |
| 169 | * End: |
| 170 | */ |