]> git.proxmox.com Git - ceph.git/blob - ceph/src/msg/async/dpdk/net.h
import quincy beta 17.1.0
[ceph.git] / ceph / src / msg / async / dpdk / net.h
1 /*
2 * This file is open source software, licensed to you under the terms
3 * of the Apache License, Version 2.0 (the "License"). See the NOTICE file
4 * distributed with this work for additional information regarding copyright
5 * ownership. You may not use this file except in compliance with the License.
6 *
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing,
12 * software distributed under the License is distributed on an
13 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 * KIND, either express or implied. See the License for the
15 * specific language governing permissions and limitations
16 * under the License.
17 */
18 /*
19 * Copyright (C) 2014 Cloudius Systems, Ltd.
20 */
21
22 #ifndef CEPH_MSG_DPDK_NET_H
23 #define CEPH_MSG_DPDK_NET_H
24
25 #include "const.h"
26 #include "ethernet.h"
27 #include "Packet.h"
28 #include "stream.h"
29 #include "toeplitz.h"
30
31 struct hw_features {
32 // Enable tx ip header checksum offload
33 bool tx_csum_ip_offload = false;
34 // Enable tx l4 (TCP or UDP) checksum offload
35 bool tx_csum_l4_offload = false;
36 // Enable rx checksum offload
37 bool rx_csum_offload = false;
38 // LRO is enabled
39 bool rx_lro = false;
40 // Enable tx TCP segment offload
41 bool tx_tso = false;
42 // Enable tx UDP fragmentation offload
43 bool tx_ufo = false;
44 // Maximum Transmission Unit
45 uint16_t mtu = 1500;
46 // Maximun packet len when TCP/UDP offload is enabled
47 uint16_t max_packet_len = ip_packet_len_max - eth_hdr_len;
48 };
49
50 class forward_hash {
51 uint8_t data[64];
52 size_t end_idx = 0;
53 public:
54 size_t size() const {
55 return end_idx;
56 }
57 void push_back(uint8_t b) {
58 ceph_assert(end_idx < sizeof(data));
59 data[end_idx++] = b;
60 }
61 void push_back(uint16_t b) {
62 push_back(uint8_t(b));
63 push_back(uint8_t(b >> 8));
64 }
65 void push_back(uint32_t b) {
66 push_back(uint16_t(b));
67 push_back(uint16_t(b >> 16));
68 }
69 const uint8_t& operator[](size_t idx) const {
70 return data[idx];
71 }
72 };
73
74 class interface;
75
76 class l3_protocol {
77 public:
78 struct l3packet {
79 eth_protocol_num proto_num;
80 ethernet_address to;
81 Packet p;
82 };
83 using packet_provider_type = std::function<std::optional<l3packet> ()>;
84
85 private:
86 interface* _netif;
87 eth_protocol_num _proto_num;
88
89 public:
90 explicit l3_protocol(interface* netif, eth_protocol_num proto_num, packet_provider_type func);
91 subscription<Packet, ethernet_address> receive(
92 std::function<int (Packet, ethernet_address)> rx_fn,
93 std::function<bool (forward_hash &h, Packet &p, size_t s)> forward);
94
95 private:
96 friend class interface;
97 };
98
99 class DPDKDevice;
100 struct ipv4_address;
101
102 class interface {
103 CephContext *cct;
104 struct l3_rx_stream {
105 stream<Packet, ethernet_address> packet_stream;
106 std::function<bool (forward_hash&, Packet&, size_t)> forward;
107 bool ready() { return packet_stream.started(); }
108 explicit l3_rx_stream(std::function<bool (forward_hash&, Packet&, size_t)>&& fw) : forward(fw) {}
109 };
110 std::unordered_map<uint16_t, l3_rx_stream> _proto_map;
111 std::shared_ptr<DPDKDevice> _dev;
112 subscription<Packet> _rx;
113 ethernet_address _hw_address;
114 struct hw_features _hw_features;
115 std::vector<l3_protocol::packet_provider_type> _pkt_providers;
116
117 private:
118 int dispatch_packet(EventCenter *c, Packet p);
119 public:
120 explicit interface(CephContext *cct, std::shared_ptr<DPDKDevice> dev, EventCenter *center);
121 ethernet_address hw_address() { return _hw_address; }
122 const struct hw_features& get_hw_features() const { return _hw_features; }
123 subscription<Packet, ethernet_address> register_l3(
124 eth_protocol_num proto_num,
125 std::function<int (Packet, ethernet_address)> next,
126 std::function<bool (forward_hash&, Packet&, size_t)> forward);
127 void forward(EventCenter *source, unsigned target, Packet p);
128 unsigned hash2cpu(uint32_t hash);
129 void register_packet_provider(l3_protocol::packet_provider_type func) {
130 _pkt_providers.push_back(std::move(func));
131 }
132 const rss_key_type& rss_key() const;
133 uint16_t hw_queues_count() const;
134 void arp_learn(ethernet_address l2, ipv4_address l3);
135 friend class l3_protocol;
136 };
137
138 #endif //CEPH_MSG_DPDK_NET_H