/*
*
* Copyright (c) 2011, Microsoft Corporation.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*
* This program is distributed in the hope it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along with
* this program; if not, write to the Free Software Foundation, Inc., 59 Temple
* Place - Suite 330, Boston, MA 02111-1307 USA.
*
* Authors:
* Haiyang Zhang <haiyangz@microsoft.com>
* Hank Janssen <hjanssen@microsoft.com>
* K. Y. Srinivasan <kys@microsoft.com>
*
*/
#ifndef _HYPERV_NET_H
#define _HYPERV_NET_H
#include <linux/list.h>
#include <linux/hyperv.h>
/* Fwd declaration */
struct hv_netvsc_packet;
/* Represent the xfer page packet which contains 1 or more netvsc packet */
struct xferpage_packet {
struct list_head list_ent;
/* # of netvsc packets this xfer packet contains */
u32 count;
};
/*
* Represent netvsc packet which contains 1 RNDIS and 1 ethernet frame
* within the RNDIS
*/
struct hv_netvsc_packet {
/* Bookkeeping stuff */
struct list_head list_ent;
struct hv_device *device;
bool is_data_pkt;
/*
* Valid only for receives when we break a xfer page packet
* into multiple netvsc packets
*/
struct xferpage_packet *xfer_page_pkt;
union {
struct {
u64 recv_completion_tid;
void *recv_completion_ctx;
void (*recv_completion)(void *context);
} recv;
struct {
u64 send_completion_tid;
void *send_completion_ctx;
void (*send_completion)(void *context);
} send;
} completion;
/* This points to the memory after page_buf */
void *extension;
u32 total_data_buflen;
/* Points to the send/receive buffer where the ethernet frame is */
void *data;
u32 page_buf_cnt;
struct hv_page_buffer page_buf[0];
};
struct netvsc_device_info {
unsigned char mac_adr[6];
bool link_state; /* 0 - link up, 1 - link down */
int ring_size;
};
enum rndis_device_state {
RNDIS_DEV_UNINITIALIZED = 0,
RNDIS_DEV_INITIALIZING,
RNDIS_DEV_INITIALIZED,
RNDIS_DEV_DATAINITIALIZED,
};
struct rndis_device {
struct netvsc_device *net_dev;
enum rndis_device_state state;
bool link_state;
atomic_t new_req_id;
spinlock_t request_lock;
struct list_head req_list;
unsigned char hw_mac_adr[ETH_ALEN];
};
/* Interface */
int netvsc_device_add(struct hv_device *device, void *additional_info);
int netvsc_device_remove(struct hv_device *device);
int netvsc_send(struct hv_device *device,
struct hv_netvsc_packet *packet);
void netvsc_linkstatus_callback(struct hv_device *device_obj,
unsigned int status);
int netvsc_recv_callback(struct hv_device *device_obj,
struct hv_netvsc_packet *packet);
int rndis_filter_open(struct hv_device *dev);
int rndis_filter_close(struct hv_device *dev);
int rndis_filter_device_add(struct hv_device *dev,
void *additional_info);
void rndis_filter_device_remove(struct hv_device *dev);
int rndis_filter_receive(struct hv_device *dev,
struct hv_netvsc_packet *pkt);
int rndis_filter_send(struct hv_device *dev,
struct hv_netvsc_packet *pkt);
int rndis_filter_set_packet_filter(struct rndis_device *dev, u32 new_filter);
#define NVSP_INVALID_PROTOCOL_VERSION ((u32)0xFFFFFFFF)
#define NVSP_PROTOCOL_VERSION_1 2
#define NVSP_PROTOCOL_VERSION_2 0x30002
enum {
NVSP_MSG_TYPE_NONE = 0,
/* Init Messages */
NVSP_MSG_TYPE_INIT = 1,
NVSP_MSG_TYPE_INIT_COMPLETE = 2,
NVSP_VERSION_MSG_START = 100,
/* Version 1 Messages */
NVSP_MSG1_TYPE_SEND_NDIS_VER = NVSP_VERSION_MSG_START,
NVSP_MSG1_TYPE_SEND_RECV_BUF,
NVSP_MSG1_TYPE_SEND_RECV_BUF_COMPLETE,
NVSP_MSG1_TYPE_REVOKE_RECV_BUF,
NVSP_MSG1_TYPE_SEND_SEND_BUF,