linux/drivers/net/hyperv/hyperv_net.h

/* SPDX-License-Identifier: GPL-2.0-only */
/*
 *
 * Copyright (c) 2011, Microsoft Corporation.
 *
 * Authors:
 *   Haiyang Zhang <[email protected]>
 *   Hank Janssen  <[email protected]>
 *   K. Y. Srinivasan <[email protected]>
 */

#ifndef _HYPERV_NET_H
#define _HYPERV_NET_H

#include <linux/list.h>
#include <linux/hyperv.h>
#include <linux/rndis.h>
#include <linux/jhash.h>
#include <net/xdp.h>

/* RSS related */
#define OID_GEN_RECEIVE_SCALE_CAPABILITIES
#define OID_GEN_RECEIVE_SCALE_PARAMETERS

#define NDIS_OBJECT_TYPE_RSS_CAPABILITIES
#define NDIS_OBJECT_TYPE_RSS_PARAMETERS
#define NDIS_OBJECT_TYPE_OFFLOAD

#define NDIS_RECEIVE_SCALE_CAPABILITIES_REVISION_2
#define NDIS_RECEIVE_SCALE_PARAMETERS_REVISION_2

struct ndis_obj_header {} __packed;

/* ndis_recv_scale_cap/cap_flag */
#define NDIS_RSS_CAPS_MESSAGE_SIGNALED_INTERRUPTS
#define NDIS_RSS_CAPS_CLASSIFICATION_AT_ISR
#define NDIS_RSS_CAPS_CLASSIFICATION_AT_DPC
#define NDIS_RSS_CAPS_USING_MSI_X
#define NDIS_RSS_CAPS_RSS_AVAILABLE_ON_PORTS
#define NDIS_RSS_CAPS_SUPPORTS_MSI_X
#define NDIS_RSS_CAPS_HASH_TYPE_TCP_IPV4
#define NDIS_RSS_CAPS_HASH_TYPE_TCP_IPV6
#define NDIS_RSS_CAPS_HASH_TYPE_TCP_IPV6_EX

struct ndis_recv_scale_cap {} __packed;


/* ndis_recv_scale_param flags */
#define NDIS_RSS_PARAM_FLAG_BASE_CPU_UNCHANGED
#define NDIS_RSS_PARAM_FLAG_HASH_INFO_UNCHANGED
#define NDIS_RSS_PARAM_FLAG_ITABLE_UNCHANGED
#define NDIS_RSS_PARAM_FLAG_HASH_KEY_UNCHANGED
#define NDIS_RSS_PARAM_FLAG_DISABLE_RSS

/* Hash info bits */
#define NDIS_HASH_FUNC_TOEPLITZ
#define NDIS_HASH_IPV4
#define NDIS_HASH_TCP_IPV4
#define NDIS_HASH_IPV6
#define NDIS_HASH_IPV6_EX
#define NDIS_HASH_TCP_IPV6
#define NDIS_HASH_TCP_IPV6_EX

#define NDIS_RSS_INDIRECTION_TABLE_MAX_SIZE_REVISION_2
#define NDIS_RSS_HASH_SECRET_KEY_MAX_SIZE_REVISION_2

#define ITAB_NUM
#define ITAB_NUM_MAX

struct ndis_recv_scale_param {};

struct ndis_tcp_ip_checksum_info {};

struct ndis_pkt_8021q_info {};

/*
 * Represent netvsc packet which contains 1 RNDIS and 1 ethernet frame
 * within the RNDIS
 *
 * The size of this structure is less than 48 bytes and we can now
 * place this structure in the skb->cb field.
 */
struct hv_netvsc_packet {};

#define NETVSC_HASH_KEYLEN

struct netvsc_device_info {};

enum rndis_device_state {};

struct rndis_device {};


/* Interface */
struct rndis_message;
struct ndis_offload_params;
struct netvsc_device;
struct netvsc_channel;
struct net_device_context;

extern u32 netvsc_ring_bytes;

struct netvsc_device *netvsc_device_add(struct hv_device *device,
					const struct netvsc_device_info *info);
int netvsc_alloc_recv_comp_ring(struct netvsc_device *net_device, u32 q_idx);
void netvsc_device_remove(struct hv_device *device);
int netvsc_send(struct net_device *net,
		struct hv_netvsc_packet *packet,
		struct rndis_message *rndis_msg,
		struct hv_page_buffer *page_buffer,
		struct sk_buff *skb,
		bool xdp_tx);
void netvsc_linkstatus_callback(struct net_device *net,
				struct rndis_message *resp,
				void *data, u32 data_buflen);
int netvsc_recv_callback(struct net_device *net,
			 struct netvsc_device *nvdev,
			 struct netvsc_channel *nvchan);
void netvsc_channel_cb(void *context);
int netvsc_poll(struct napi_struct *napi, int budget);

void netvsc_xdp_xmit(struct sk_buff *skb, struct net_device *ndev);
u32 netvsc_run_xdp(struct net_device *ndev, struct netvsc_channel *nvchan,
		   struct xdp_buff *xdp);
unsigned int netvsc_xdp_fraglen(unsigned int len);
struct bpf_prog *netvsc_xdp_get(struct netvsc_device *nvdev);
int netvsc_xdp_set(struct net_device *dev, struct bpf_prog *prog,
		   struct netlink_ext_ack *extack,
		   struct netvsc_device *nvdev);
int netvsc_vf_setxdp(struct net_device *vf_netdev, struct bpf_prog *prog);
int netvsc_bpf(struct net_device *dev, struct netdev_bpf *bpf);
int netvsc_ndoxdp_xmit(struct net_device *ndev, int n,
		       struct xdp_frame **frames, u32 flags);

int rndis_set_subchannel(struct net_device *ndev,
			 struct netvsc_device *nvdev,
			 struct netvsc_device_info *dev_info);
int rndis_filter_open(struct netvsc_device *nvdev);
int rndis_filter_close(struct netvsc_device *nvdev);
struct netvsc_device *rndis_filter_device_add(struct hv_device *dev,
					      struct netvsc_device_info *info);
void rndis_filter_update(struct netvsc_device *nvdev);
void rndis_filter_device_remove(struct hv_device *dev,
				struct netvsc_device *nvdev);
int rndis_filter_set_rss_param(struct rndis_device *rdev,
			       const u8 *key);
int rndis_filter_set_offload_params(struct net_device *ndev,
				    struct netvsc_device *nvdev,
				    struct ndis_offload_params *req_offloads);
int rndis_filter_receive(struct net_device *ndev,
			 struct netvsc_device *net_dev,
			 struct netvsc_channel *nvchan,
			 void *data, u32 buflen);

int rndis_filter_set_device_mac(struct netvsc_device *ndev,
				const char *mac);

int netvsc_switch_datapath(struct net_device *nv_dev, bool vf);

#define NVSP_INVALID_PROTOCOL_VERSION

#define NVSP_PROTOCOL_VERSION_1
#define NVSP_PROTOCOL_VERSION_2
#define NVSP_PROTOCOL_VERSION_4
#define NVSP_PROTOCOL_VERSION_5
#define NVSP_PROTOCOL_VERSION_6
#define NVSP_PROTOCOL_VERSION_61

enum {};

enum {};

struct nvsp_message_header {};

/* Init Messages */

/*
 * This message is used by the VSC to initialize the channel after the channels
 * has been opened. This message should never include anything other then
 * versioning (i.e. this message will be the same for ever).
 */
struct nvsp_message_init {} __packed;

/*
 * This message is used by the VSP to complete the initialization of the
 * channel. This message should never include anything other then versioning
 * (i.e. this message will be the same for ever).
 */
struct nvsp_message_init_complete {} __packed;

nvsp_message_init_uber __packed;

/* Version 1 Messages */

/*
 * This message is used by the VSC to send the NDIS version to the VSP. The VSP
 * can use this information when handling OIDs sent by the VSC.
 */
struct nvsp_1_message_send_ndis_version {} __packed;

/*
 * This message is used by the VSC to send a receive buffer to the VSP. The VSP
 * can then use the receive buffer to send data to the VSC.
 */
struct nvsp_1_message_send_receive_buffer {} __packed;

struct nvsp_1_receive_buffer_section {} __packed;

/*
 * This message is used by the VSP to acknowledge a receive buffer send by the
 * VSC. This message must be sent by the VSP before the VSP uses the receive
 * buffer.
 */
struct nvsp_1_message_send_receive_buffer_complete {} __packed;

/*
 * This message is sent by the VSC to revoke the receive buffer.  After the VSP
 * completes this transaction, the vsp should never use the receive buffer
 * again.
 */
struct nvsp_1_message_revoke_receive_buffer {};

/*
 * This message is used by the VSC to send a send buffer to the VSP. The VSC
 * can then use the send buffer to send data to the VSP.
 */
struct nvsp_1_message_send_send_buffer {} __packed;

/*
 * This message is used by the VSP to acknowledge a send buffer sent by the
 * VSC. This message must be sent by the VSP before the VSP uses the sent
 * buffer.
 */
struct nvsp_1_message_send_send_buffer_complete {} __packed;

/*
 * This message is sent by the VSC to revoke the send buffer.  After the VSP
 * completes this transaction, the vsp should never use the send buffer again.
 */
struct nvsp_1_message_revoke_send_buffer {};

/*
 * This message is used by both the VSP and the VSC to send a RNDIS message to
 * the opposite channel endpoint.
 */
struct nvsp_1_message_send_rndis_packet {} __packed;

/*
 * This message is used by both the VSP and the VSC to complete a RNDIS message
 * to the opposite channel endpoint. At this point, the initiator of this
 * message cannot use any resources associated with the original RNDIS packet.
 */
struct nvsp_1_message_send_rndis_packet_complete {};

nvsp_1_message_uber __packed;


/*
 * Network VSP protocol version 2 messages:
 */
struct nvsp_2_vsc_capability {} __packed;

struct nvsp_2_send_ndis_config {} __packed;

/* Allocate receive buffer */
struct nvsp_2_alloc_rxbuf {} __packed;

/* Allocate receive buffer complete */
struct nvsp_2_alloc_rxbuf_comp {} __packed;

struct nvsp_2_free_rxbuf {} __packed;

nvsp_2_message_uber __packed;

struct nvsp_4_send_vf_association {} __packed;

enum nvsp_vm_datapath {};

struct nvsp_4_sw_datapath {} __packed;

nvsp_4_message_uber __packed;

enum nvsp_subchannel_operation {};

struct nvsp_5_subchannel_request {} __packed;

struct nvsp_5_subchannel_complete {} __packed;

struct nvsp_5_send_indirect_table {} __packed;

nvsp_5_message_uber __packed;

enum nvsp_6_pd_api_op {};

struct grp_affinity {} __packed;

struct nvsp_6_pd_api_req {} __packed;

struct nvsp_6_pd_api_comp {} __packed;

struct nvsp_6_pd_buf {} __packed;

struct nvsp_6_pd_batch_msg {} __packed;

nvsp_6_message_uber __packed;

nvsp_all_messages __packed;

/* ALL Messages */
struct nvsp_message {} __packed;


#define NETVSC_MTU
#define NETVSC_MTU_MIN

/* Max buffer sizes allowed by a host */
#define NETVSC_RECEIVE_BUFFER_SIZE
#define NETVSC_RECEIVE_BUFFER_SIZE_LEGACY
#define NETVSC_RECEIVE_BUFFER_DEFAULT

#define NETVSC_SEND_BUFFER_SIZE
#define NETVSC_SEND_BUFFER_DEFAULT

#define NETVSC_INVALID_INDEX

#define NETVSC_SEND_SECTION_SIZE
#define NETVSC_RECV_SECTION_SIZE

/* Default size of TX buf: 1MB, RX buf: 16MB */
#define NETVSC_MIN_TX_SECTIONS
#define NETVSC_DEFAULT_TX
#define NETVSC_MIN_RX_SECTIONS
#define NETVSC_DEFAULT_RX

#define NETVSC_RECEIVE_BUFFER_ID
#define NETVSC_SEND_BUFFER_ID

#define NETVSC_SUPPORTED_HW_FEATURES

#define VRSS_SEND_TAB_SIZE
#define VRSS_CHANNEL_MAX
#define VRSS_CHANNEL_DEFAULT

#define RNDIS_MAX_PKT_DEFAULT
#define RNDIS_PKT_ALIGN_DEFAULT

#define NETVSC_XDP_HDRM

#define NETVSC_MIN_OUT_MSG_SIZE
#define NETVSC_MIN_IN_MSG_SIZE

/* Estimated requestor size:
 * out_ring_size/min_out_msg_size + in_ring_size/min_in_msg_size
 */
static inline u32 netvsc_rqstor_size(unsigned long ringbytes)
{}

/* XFER PAGE packets can specify a maximum of 375 ranges for NDIS >= 6.0
 * and a maximum of 64 ranges for NDIS < 6.0 with no RSC; with RSC, this
 * limit is raised to 562 (= NVSP_RSC_MAX).
 */
#define NETVSC_MAX_XFER_PAGE_RANGES
#define NETVSC_XFER_HEADER_SIZE(rng_cnt)
#define NETVSC_MAX_PKT_SIZE

struct multi_send_data {};

struct recv_comp_data {};

struct multi_recv_comp {};

#define NVSP_RSC_MAX

struct nvsc_rsc {};

#define NVSC_RSC_VLAN
#define NVSC_RSC_CSUM_INFO
#define NVSC_RSC_HASH_INFO

struct netvsc_stats_tx {};

struct netvsc_stats_rx {};

struct netvsc_ethtool_stats {};

struct netvsc_ethtool_pcpu_stats {};

struct netvsc_vf_pcpu_stats {};

struct netvsc_reconfig {};

/* L4 hash bits for different protocols */
#define HV_TCP4_L4HASH
#define HV_TCP6_L4HASH
#define HV_UDP4_L4HASH
#define HV_UDP6_L4HASH
#define HV_DEFAULT_L4HASH

/* The context of the netvsc device  */
struct net_device_context {};

/* Azure hosts don't support non-TCP port numbers in hashing for fragmented
 * packets. We can use ethtool to change UDP hash level when necessary.
 */
static inline u32 netvsc_get_hash(struct sk_buff *skb,
				  const struct net_device_context *ndc)
{}

/* Per channel data */
struct netvsc_channel {};

/* Per netvsc device */
struct netvsc_device {};

/* NdisInitialize message */
struct rndis_initialize_request {};

/* Response to NdisInitialize */
struct rndis_initialize_complete {};

/* Call manager devices only: Information about an address family */
/* supported by the device is appended to the response to NdisInitialize. */
struct rndis_co_address_family {};

/* NdisHalt message */
struct rndis_halt_request {};

/* NdisQueryRequest message */
struct rndis_query_request {};

/* Response to NdisQueryRequest */
struct rndis_query_complete {};

/* NdisSetRequest message */
struct rndis_set_request {};

/* Response to NdisSetRequest */
struct rndis_set_complete {};

/* NdisReset message */
struct rndis_reset_request {};

/* Response to NdisReset */
struct rndis_reset_complete {};

/* NdisMIndicateStatus message */
struct rndis_indicate_status {};

/* Diagnostic information passed as the status buffer in */
/* struct rndis_indicate_status messages signifying error conditions. */
struct rndis_diagnostic_info {};

/* NdisKeepAlive message */
struct rndis_keepalive_request {};

/* Response to NdisKeepAlive */
struct rndis_keepalive_complete {};

/*
 * Data message. All Offset fields contain byte offsets from the beginning of
 * struct rndis_packet. All Length fields are in bytes.  VcHandle is set
 * to 0 for connectionless data, otherwise it contains the VC handle.
 */
struct rndis_packet {};

/* Optional Out of Band data associated with a Data message. */
struct rndis_oobd {};

/* Packet extension field contents associated with a Data message. */
struct rndis_per_packet_info {};

enum ndis_per_pkt_info_type {};

enum rndis_per_pkt_info_interal_type {};

#define RNDIS_PKTINFO_SUBALLOC
#define RNDIS_PKTINFO_1ST_FRAG
#define RNDIS_PKTINFO_LAST_FRAG

#define RNDIS_PKTINFO_ID_V1

struct rndis_pktinfo_id {};

struct ndis_object_header {};

#define NDIS_OBJECT_TYPE_DEFAULT
#define NDIS_OFFLOAD_PARAMETERS_REVISION_3
#define NDIS_OFFLOAD_PARAMETERS_REVISION_2
#define NDIS_OFFLOAD_PARAMETERS_REVISION_1

#define NDIS_OFFLOAD_PARAMETERS_NO_CHANGE
#define NDIS_OFFLOAD_PARAMETERS_LSOV2_DISABLED
#define NDIS_OFFLOAD_PARAMETERS_LSOV2_ENABLED
#define NDIS_OFFLOAD_PARAMETERS_LSOV1_ENABLED
#define NDIS_OFFLOAD_PARAMETERS_RSC_DISABLED
#define NDIS_OFFLOAD_PARAMETERS_RSC_ENABLED
#define NDIS_OFFLOAD_PARAMETERS_TX_RX_DISABLED
#define NDIS_OFFLOAD_PARAMETERS_TX_ENABLED_RX_DISABLED
#define NDIS_OFFLOAD_PARAMETERS_RX_ENABLED_TX_DISABLED
#define NDIS_OFFLOAD_PARAMETERS_TX_RX_ENABLED

#define NDIS_TCP_LARGE_SEND_OFFLOAD_V2_TYPE
#define NDIS_TCP_LARGE_SEND_OFFLOAD_IPV4
#define NDIS_TCP_LARGE_SEND_OFFLOAD_IPV6

#define VERSION_4_OFFLOAD_SIZE
/*
 * New offload OIDs for NDIS 6
 */
#define OID_TCP_OFFLOAD_CURRENT_CONFIG
#define OID_TCP_OFFLOAD_PARAMETERS
#define OID_TCP_OFFLOAD_HARDWARE_CAPABILITIES
#define OID_TCP_CONNECTION_OFFLOAD_CURRENT_CONFIG
#define OID_TCP_CONNECTION_OFFLOAD_HARDWARE_CAPABILITIES
#define OID_OFFLOAD_ENCAPSULATION

/*
 * OID_TCP_OFFLOAD_HARDWARE_CAPABILITIES
 * ndis_type: NDIS_OBJTYPE_OFFLOAD
 */

#define NDIS_OFFLOAD_ENCAP_NONE
#define NDIS_OFFLOAD_ENCAP_NULL
#define NDIS_OFFLOAD_ENCAP_8023
#define NDIS_OFFLOAD_ENCAP_8023PQ
#define NDIS_OFFLOAD_ENCAP_8023PQ_OOB
#define NDIS_OFFLOAD_ENCAP_RFC1483

struct ndis_csum_offload {};

struct ndis_lsov1_offload {};

struct ndis_ipsecv1_offload {};

struct ndis_lsov2_offload {};

struct ndis_ipsecv2_offload {};

struct ndis_rsc_offload {};

struct ndis_encap_offload {};

struct ndis_offload {};

#define NDIS_OFFLOAD_SIZE
#define NDIS_OFFLOAD_SIZE_6_0
#define NDIS_OFFLOAD_SIZE_6_1

struct ndis_offload_params {};

struct ndis_tcp_lso_info {};

#define NDIS_VLAN_PPI_SIZE

#define NDIS_CSUM_PPI_SIZE

#define NDIS_LSO_PPI_SIZE

#define NDIS_HASH_PPI_SIZE

/* Total size of all PPI data */
#define NDIS_ALL_PPI_SIZE

/* Format of Information buffer passed in a SetRequest for the OID */
/* OID_GEN_RNDIS_CONFIG_PARAMETER. */
struct rndis_config_parameter_info {};

/* Values for ParameterType in struct rndis_config_parameter_info */
#define RNDIS_CONFIG_PARAM_TYPE_INTEGER
#define RNDIS_CONFIG_PARAM_TYPE_STRING

/* CONDIS Miniport messages for connection oriented devices */
/* that do not implement a call manager. */

/* CoNdisMiniportCreateVc message */
struct rcondis_mp_create_vc {};

/* Response to CoNdisMiniportCreateVc */
struct rcondis_mp_create_vc_complete {};

/* CoNdisMiniportDeleteVc message */
struct rcondis_mp_delete_vc {};

/* Response to CoNdisMiniportDeleteVc */
struct rcondis_mp_delete_vc_complete {};

/* CoNdisMiniportQueryRequest message */
struct rcondis_mp_query_request {};

/* CoNdisMiniportSetRequest message */
struct rcondis_mp_set_request {};

/* CoNdisIndicateStatus message */
struct rcondis_indicate_status {};

/* CONDIS Call/VC parameters */
struct rcondis_specific_parameters {};

struct rcondis_media_parameters {};

struct rndis_flowspec {};

struct rcondis_call_manager_parameters {};

/* CoNdisMiniportActivateVc message */
struct rcondis_mp_activate_vc_request {};

/* Response to CoNdisMiniportActivateVc */
struct rcondis_mp_activate_vc_complete {};

/* CoNdisMiniportDeactivateVc message */
struct rcondis_mp_deactivate_vc_request {};

/* Response to CoNdisMiniportDeactivateVc */
struct rcondis_mp_deactivate_vc_complete {};


/* union with all of the RNDIS messages */
rndis_message_container;

/* Remote NDIS message format */
struct rndis_message {};


/* Handy macros */

/* get the size of an RNDIS message. Pass in the message type, */
/* struct rndis_set_request, struct rndis_packet for example */
#define RNDIS_MESSAGE_SIZE(msg)

#define RNDIS_HEADER_SIZE

#define RNDIS_AND_PPI_SIZE

#define NDIS_PACKET_TYPE_DIRECTED
#define NDIS_PACKET_TYPE_MULTICAST
#define NDIS_PACKET_TYPE_ALL_MULTICAST
#define NDIS_PACKET_TYPE_BROADCAST
#define NDIS_PACKET_TYPE_SOURCE_ROUTING
#define NDIS_PACKET_TYPE_PROMISCUOUS
#define NDIS_PACKET_TYPE_SMT
#define NDIS_PACKET_TYPE_ALL_LOCAL
#define NDIS_PACKET_TYPE_GROUP
#define NDIS_PACKET_TYPE_ALL_FUNCTIONAL
#define NDIS_PACKET_TYPE_FUNCTIONAL
#define NDIS_PACKET_TYPE_MAC_FRAME

#define TRANSPORT_INFO_NOT_IP
#define TRANSPORT_INFO_IPV4_TCP
#define TRANSPORT_INFO_IPV4_UDP
#define TRANSPORT_INFO_IPV6_TCP
#define TRANSPORT_INFO_IPV6_UDP

#define RETRY_US_LO
#define RETRY_US_HI
#define RETRY_MAX

void netvsc_dma_unmap(struct hv_device *hv_dev,
		      struct hv_netvsc_packet *packet);
#endif /* _HYPERV_NET_H */