go.ligato.io/vpp-agent/v3@v3.5.0/plugins/vpp/ifplugin/vppcalls/vpp2106/rdma_vppcalls.go (about)

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