Skip to content

Commit 71790a2

Browse files
haiyangzdavem330
authored andcommitted
hv_netvsc: Add structs and handlers for VF messages
This patch adds data structures and handlers for messages related to SRIOV Virtual Function. Signed-off-by: Haiyang Zhang <haiyangz@microsoft.com> Reviewed-by: K. Y. Srinivasan <kys@microsoft.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 70d2db7 commit 71790a2

File tree

2 files changed

+62
-10
lines changed

2 files changed

+62
-10
lines changed

drivers/net/hyperv/hyperv_net.h

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -541,6 +541,29 @@ union nvsp_2_message_uber {
541541
struct nvsp_2_free_rxbuf free_rxbuf;
542542
} __packed;
543543

544+
struct nvsp_4_send_vf_association {
545+
/* 1: allocated, serial number is valid. 0: not allocated */
546+
u32 allocated;
547+
548+
/* Serial number of the VF to team with */
549+
u32 serial;
550+
} __packed;
551+
552+
enum nvsp_vm_datapath {
553+
NVSP_DATAPATH_SYNTHETIC = 0,
554+
NVSP_DATAPATH_VF,
555+
NVSP_DATAPATH_MAX
556+
};
557+
558+
struct nvsp_4_sw_datapath {
559+
u32 active_datapath; /* active data path in VM */
560+
} __packed;
561+
562+
union nvsp_4_message_uber {
563+
struct nvsp_4_send_vf_association vf_assoc;
564+
struct nvsp_4_sw_datapath active_dp;
565+
} __packed;
566+
544567
enum nvsp_subchannel_operation {
545568
NVSP_SUBCHANNEL_NONE = 0,
546569
NVSP_SUBCHANNEL_ALLOCATE,
@@ -578,6 +601,7 @@ union nvsp_all_messages {
578601
union nvsp_message_init_uber init_msg;
579602
union nvsp_1_message_uber v1_msg;
580603
union nvsp_2_message_uber v2_msg;
604+
union nvsp_4_message_uber v4_msg;
581605
union nvsp_5_message_uber v5_msg;
582606
} __packed;
583607

@@ -691,6 +715,11 @@ struct netvsc_device {
691715

692716
/* The net device context */
693717
struct net_device_context *nd_ctx;
718+
719+
/* 1: allocated, serial number is valid. 0: not allocated */
720+
u32 vf_alloc;
721+
/* Serial number of the VF to team with */
722+
u32 vf_serial;
694723
};
695724

696725
/* NdisInitialize message */

drivers/net/hyperv/netvsc.c

Lines changed: 33 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -453,13 +453,16 @@ static int negotiate_nvsp_ver(struct hv_device *device,
453453
if (nvsp_ver == NVSP_PROTOCOL_VERSION_1)
454454
return 0;
455455

456-
/* NVSPv2 only: Send NDIS config */
456+
/* NVSPv2 or later: Send NDIS config */
457457
memset(init_packet, 0, sizeof(struct nvsp_message));
458458
init_packet->hdr.msg_type = NVSP_MSG2_TYPE_SEND_NDIS_CONFIG;
459459
init_packet->msg.v2_msg.send_ndis_config.mtu = net_device->ndev->mtu +
460460
ETH_HLEN;
461461
init_packet->msg.v2_msg.send_ndis_config.capability.ieee8021q = 1;
462462

463+
if (nvsp_ver >= NVSP_PROTOCOL_VERSION_5)
464+
init_packet->msg.v2_msg.send_ndis_config.capability.sriov = 1;
465+
463466
ret = vmbus_sendpacket(device->channel, init_packet,
464467
sizeof(struct nvsp_message),
465468
(unsigned long)init_packet,
@@ -1064,11 +1067,10 @@ static void netvsc_receive(struct netvsc_device *net_device,
10641067

10651068

10661069
static void netvsc_send_table(struct hv_device *hdev,
1067-
struct vmpacket_descriptor *vmpkt)
1070+
struct nvsp_message *nvmsg)
10681071
{
10691072
struct netvsc_device *nvscdev;
10701073
struct net_device *ndev;
1071-
struct nvsp_message *nvmsg;
10721074
int i;
10731075
u32 count, *tab;
10741076

@@ -1077,12 +1079,6 @@ static void netvsc_send_table(struct hv_device *hdev,
10771079
return;
10781080
ndev = nvscdev->ndev;
10791081

1080-
nvmsg = (struct nvsp_message *)((unsigned long)vmpkt +
1081-
(vmpkt->offset8 << 3));
1082-
1083-
if (nvmsg->hdr.msg_type != NVSP_MSG5_TYPE_SEND_INDIRECTION_TABLE)
1084-
return;
1085-
10861082
count = nvmsg->msg.v5_msg.send_table.count;
10871083
if (count != VRSS_SEND_TAB_SIZE) {
10881084
netdev_err(ndev, "Received wrong send-table size:%u\n", count);
@@ -1096,6 +1092,28 @@ static void netvsc_send_table(struct hv_device *hdev,
10961092
nvscdev->send_table[i] = tab[i];
10971093
}
10981094

1095+
static void netvsc_send_vf(struct netvsc_device *nvdev,
1096+
struct nvsp_message *nvmsg)
1097+
{
1098+
nvdev->vf_alloc = nvmsg->msg.v4_msg.vf_assoc.allocated;
1099+
nvdev->vf_serial = nvmsg->msg.v4_msg.vf_assoc.serial;
1100+
}
1101+
1102+
static inline void netvsc_receive_inband(struct hv_device *hdev,
1103+
struct netvsc_device *nvdev,
1104+
struct nvsp_message *nvmsg)
1105+
{
1106+
switch (nvmsg->hdr.msg_type) {
1107+
case NVSP_MSG5_TYPE_SEND_INDIRECTION_TABLE:
1108+
netvsc_send_table(hdev, nvmsg);
1109+
break;
1110+
1111+
case NVSP_MSG4_TYPE_SEND_VF_ASSOCIATION:
1112+
netvsc_send_vf(nvdev, nvmsg);
1113+
break;
1114+
}
1115+
}
1116+
10991117
void netvsc_channel_cb(void *context)
11001118
{
11011119
int ret;
@@ -1108,6 +1126,7 @@ void netvsc_channel_cb(void *context)
11081126
unsigned char *buffer;
11091127
int bufferlen = NETVSC_PACKET_SIZE;
11101128
struct net_device *ndev;
1129+
struct nvsp_message *nvmsg;
11111130

11121131
if (channel->primary_channel != NULL)
11131132
device = channel->primary_channel->device_obj;
@@ -1126,6 +1145,8 @@ void netvsc_channel_cb(void *context)
11261145
if (ret == 0) {
11271146
if (bytes_recvd > 0) {
11281147
desc = (struct vmpacket_descriptor *)buffer;
1148+
nvmsg = (struct nvsp_message *)((unsigned long)
1149+
desc + (desc->offset8 << 3));
11291150
switch (desc->type) {
11301151
case VM_PKT_COMP:
11311152
netvsc_send_completion(net_device,
@@ -1138,7 +1159,9 @@ void netvsc_channel_cb(void *context)
11381159
break;
11391160

11401161
case VM_PKT_DATA_INBAND:
1141-
netvsc_send_table(device, desc);
1162+
netvsc_receive_inband(device,
1163+
net_device,
1164+
nvmsg);
11421165
break;
11431166

11441167
default:

0 commit comments

Comments
 (0)