go.ligato.io/vpp-agent/v3@v3.5.0/plugins/vpp/ifplugin/vppcalls/vpp2210/rdma_vppcalls.go (about) 1 // Copyright (c) 2022 Cisco and/or its affiliates. 2 // 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 package vpp2210 16 17 import ( 18 "context" 19 20 "github.com/pkg/errors" 21 22 "go.ligato.io/vpp-agent/v3/plugins/vpp" 23 interfaces "go.ligato.io/vpp-agent/v3/proto/ligato/vpp/interfaces" 24 25 "go.ligato.io/vpp-agent/v3/plugins/vpp/binapi/vpp2210/interface_types" 26 vpp_rdma "go.ligato.io/vpp-agent/v3/plugins/vpp/binapi/vpp2210/rdma" 27 ) 28 29 // AddRdmaInterface adds new interface with RDMA driver. 30 func (h *InterfaceVppHandler) AddRdmaInterface(ctx context.Context, ifName string, rdmaLink *interfaces.RDMALink) (swIdx uint32, err error) { 31 if h.rdma == nil { 32 return 0, errors.WithMessage(vpp.ErrPluginDisabled, "rdma") 33 } 34 35 req := &vpp_rdma.RdmaCreateV3{ 36 HostIf: rdmaLink.GetHostIfName(), 37 Name: ifName, 38 RxqNum: uint16(rdmaLink.GetRxqNum()), 39 RxqSize: uint16(rdmaLink.GetRxqSize()), 40 TxqSize: uint16(rdmaLink.GetTxqSize()), 41 Mode: rdmaMode(rdmaLink.GetMode()), 42 } 43 44 reply := &vpp_rdma.RdmaCreateV3Reply{} 45 if err := h.callsChannel.SendRequest(req).ReceiveReply(reply); err != nil { 46 return 0, err 47 } 48 swIdx = uint32(reply.SwIfIndex) 49 50 return swIdx, h.SetInterfaceTag(ifName, swIdx) 51 } 52 53 // DeleteRdmaInterface removes interface with RDMA driver. 54 func (h *InterfaceVppHandler) DeleteRdmaInterface(ctx context.Context, ifName string, ifIdx uint32) error { 55 if h.rdma == nil { 56 return errors.WithMessage(vpp.ErrPluginDisabled, "rdma") 57 } 58 59 req := &vpp_rdma.RdmaDelete{ 60 SwIfIndex: interface_types.InterfaceIndex(ifIdx), 61 } 62 63 reply := &vpp_rdma.RdmaDeleteReply{} 64 if err := h.callsChannel.SendRequest(req).ReceiveReply(reply); err != nil { 65 return err 66 } 67 68 return h.RemoveInterfaceTag(ifName, ifIdx) 69 } 70 71 func rdmaMode(mode interfaces.RDMALink_Mode) vpp_rdma.RdmaMode { 72 switch mode { 73 case interfaces.RDMALink_DV: 74 return vpp_rdma.RDMA_API_MODE_DV 75 case interfaces.RDMALink_IBV: 76 return vpp_rdma.RDMA_API_MODE_IBV 77 default: 78 return vpp_rdma.RDMA_API_MODE_AUTO 79 } 80 }