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.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
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
19 * Copyright (C) 2014 Cloudius Systems, Ltd.
22 #ifndef CEPH_MSG_DPDK_NET_H
23 #define CEPH_MSG_DPDK_NET_H
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;
40 // Enable tx TCP segment offload
42 // Enable tx UDP fragmentation offload
44 // Maximum Transmission Unit
46 // Maximun packet len when TCP/UDP offload is enabled
47 uint16_t max_packet_len
= ip_packet_len_max
- eth_hdr_len
;
57 void push_back(uint8_t b
) {
58 ceph_assert(end_idx
< sizeof(data
));
61 void push_back(uint16_t b
) {
62 push_back(uint8_t(b
));
63 push_back(uint8_t(b
>> 8));
65 void push_back(uint32_t b
) {
66 push_back(uint16_t(b
));
67 push_back(uint16_t(b
>> 16));
69 const uint8_t& operator[](size_t idx
) const {
79 eth_protocol_num proto_num
;
83 using packet_provider_type
= std::function
<std::optional
<l3packet
> ()>;
87 eth_protocol_num _proto_num
;
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
);
96 friend class interface
;
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
) {}
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
;
118 int dispatch_packet(EventCenter
*c
, Packet p
);
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
));
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
;
138 #endif //CEPH_MSG_DPDK_NET_H