Skip to content

Commit 0a1275c

Browse files
vittyvkdavem330
authored andcommitted
hv_netvsc: get rid of struct net_device pointer in struct netvsc_device
Simplify netvsvc pointer graph by getting rid of the redundant ndev pointer. We can always get a pointer to struct net_device from somewhere else. Signed-off-by: Vitaly Kuznetsov <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 3d541ac commit 0a1275c

File tree

4 files changed

+72
-64
lines changed

4 files changed

+72
-64
lines changed

drivers/net/hyperv/hyperv_net.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,6 @@ struct rndis_device {
173173

174174
/* Interface */
175175
struct rndis_message;
176-
struct netvsc_device;
177176
int netvsc_device_add(struct hv_device *device, void *additional_info);
178177
int netvsc_device_remove(struct hv_device *device);
179178
int netvsc_send(struct hv_device *device,
@@ -203,7 +202,7 @@ int rndis_filter_receive(struct hv_device *dev,
203202
int rndis_filter_set_packet_filter(struct rndis_device *dev, u32 new_filter);
204203
int rndis_filter_set_device_mac(struct hv_device *hdev, char *mac);
205204

206-
void netvsc_switch_datapath(struct netvsc_device *nv_dev, bool vf);
205+
void netvsc_switch_datapath(struct net_device *nv_dev, bool vf);
207206

208207
#define NVSP_INVALID_PROTOCOL_VERSION ((u32)0xFFFFFFFF)
209208

@@ -711,8 +710,6 @@ struct netvsc_device {
711710
struct nvsp_message revoke_packet;
712711
/* unsigned char HwMacAddr[HW_MACADDR_LEN]; */
713712

714-
struct net_device *ndev;
715-
716713
struct vmbus_channel *chn_table[VRSS_CHANNEL_MAX];
717714
u32 send_table[VRSS_SEND_TAB_SIZE];
718715
u32 max_chn;

drivers/net/hyperv/netvsc.c

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,12 @@
3737
* Switch the data path from the synthetic interface to the VF
3838
* interface.
3939
*/
40-
void netvsc_switch_datapath(struct netvsc_device *nv_dev, bool vf)
40+
void netvsc_switch_datapath(struct net_device *ndev, bool vf)
4141
{
42-
struct nvsp_message *init_pkt = &nv_dev->channel_init_pkt;
43-
struct net_device *ndev = nv_dev->ndev;
4442
struct net_device_context *net_device_ctx = netdev_priv(ndev);
4543
struct hv_device *dev = net_device_ctx->device_ctx;
44+
struct netvsc_device *nv_dev = net_device_ctx->nvdev;
45+
struct nvsp_message *init_pkt = &nv_dev->channel_init_pkt;
4646

4747
memset(init_pkt, 0, sizeof(struct nvsp_message));
4848
init_pkt->hdr.msg_type = NVSP_MSG4_TYPE_SWITCH_DATA_PATH;
@@ -80,7 +80,6 @@ static struct netvsc_device *alloc_net_device(struct hv_device *device)
8080
net_device->destroy = false;
8181
atomic_set(&net_device->open_cnt, 0);
8282
atomic_set(&net_device->vf_use_cnt, 0);
83-
net_device->ndev = ndev;
8483
net_device->max_pkt = RNDIS_MAX_PKT_DEFAULT;
8584
net_device->pkt_align = RNDIS_PKT_ALIGN_DEFAULT;
8685

@@ -263,7 +262,7 @@ static int netvsc_init_buf(struct hv_device *device)
263262
net_device = get_outbound_net_device(device);
264263
if (!net_device)
265264
return -ENODEV;
266-
ndev = net_device->ndev;
265+
ndev = hv_get_drvdata(device);
267266

268267
node = cpu_to_node(device->channel->target_cpu);
269268
net_device->recv_buf = vzalloc_node(net_device->recv_buf_size, node);
@@ -453,6 +452,7 @@ static int negotiate_nvsp_ver(struct hv_device *device,
453452
struct nvsp_message *init_packet,
454453
u32 nvsp_ver)
455454
{
455+
struct net_device *ndev = hv_get_drvdata(device);
456456
int ret;
457457
unsigned long t;
458458

@@ -486,8 +486,7 @@ static int negotiate_nvsp_ver(struct hv_device *device,
486486
/* NVSPv2 or later: Send NDIS config */
487487
memset(init_packet, 0, sizeof(struct nvsp_message));
488488
init_packet->hdr.msg_type = NVSP_MSG2_TYPE_SEND_NDIS_CONFIG;
489-
init_packet->msg.v2_msg.send_ndis_config.mtu = net_device->ndev->mtu +
490-
ETH_HLEN;
489+
init_packet->msg.v2_msg.send_ndis_config.mtu = ndev->mtu + ETH_HLEN;
491490
init_packet->msg.v2_msg.send_ndis_config.capability.ieee8021q = 1;
492491

493492
if (nvsp_ver >= NVSP_PROTOCOL_VERSION_5)
@@ -507,15 +506,13 @@ static int netvsc_connect_vsp(struct hv_device *device)
507506
struct netvsc_device *net_device;
508507
struct nvsp_message *init_packet;
509508
int ndis_version;
510-
struct net_device *ndev;
511509
u32 ver_list[] = { NVSP_PROTOCOL_VERSION_1, NVSP_PROTOCOL_VERSION_2,
512510
NVSP_PROTOCOL_VERSION_4, NVSP_PROTOCOL_VERSION_5 };
513511
int i, num_ver = 4; /* number of different NVSP versions */
514512

515513
net_device = get_outbound_net_device(device);
516514
if (!net_device)
517515
return -ENODEV;
518-
ndev = net_device->ndev;
519516

520517
init_packet = &net_device->channel_init_pkt;
521518

@@ -768,6 +765,7 @@ static u32 netvsc_copy_to_send_buf(struct netvsc_device *net_device,
768765
}
769766

770767
static inline int netvsc_send_pkt(
768+
struct hv_device *device,
771769
struct hv_netvsc_packet *packet,
772770
struct netvsc_device *net_device,
773771
struct hv_page_buffer **pb,
@@ -776,7 +774,7 @@ static inline int netvsc_send_pkt(
776774
struct nvsp_message nvmsg;
777775
u16 q_idx = packet->q_idx;
778776
struct vmbus_channel *out_channel = net_device->chn_table[q_idx];
779-
struct net_device *ndev = net_device->ndev;
777+
struct net_device *ndev = hv_get_drvdata(device);
780778
u64 req_id;
781779
int ret;
782780
struct hv_page_buffer *pgbuf;
@@ -971,7 +969,8 @@ int netvsc_send(struct hv_device *device,
971969
}
972970

973971
if (msd_send) {
974-
m_ret = netvsc_send_pkt(msd_send, net_device, NULL, msd_skb);
972+
m_ret = netvsc_send_pkt(device, msd_send, net_device,
973+
NULL, msd_skb);
975974

976975
if (m_ret != 0) {
977976
netvsc_free_send_slot(net_device,
@@ -982,7 +981,7 @@ int netvsc_send(struct hv_device *device,
982981

983982
send_now:
984983
if (cur_send)
985-
ret = netvsc_send_pkt(cur_send, net_device, pb, skb);
984+
ret = netvsc_send_pkt(device, cur_send, net_device, pb, skb);
986985

987986
if (ret != 0 && section_index != NETVSC_INVALID_INDEX)
988987
netvsc_free_send_slot(net_device, section_index);
@@ -998,9 +997,7 @@ static void netvsc_send_recv_completion(struct hv_device *device,
998997
struct nvsp_message recvcompMessage;
999998
int retries = 0;
1000999
int ret;
1001-
struct net_device *ndev;
1002-
1003-
ndev = net_device->ndev;
1000+
struct net_device *ndev = hv_get_drvdata(device);
10041001

10051002
recvcompMessage.hdr.msg_type =
10061003
NVSP_MSG1_TYPE_SEND_RNDIS_PKT_COMPLETE;
@@ -1047,11 +1044,9 @@ static void netvsc_receive(struct netvsc_device *net_device,
10471044
u32 status = NVSP_STAT_SUCCESS;
10481045
int i;
10491046
int count = 0;
1050-
struct net_device *ndev;
1047+
struct net_device *ndev = hv_get_drvdata(device);
10511048
void *data;
10521049

1053-
ndev = net_device->ndev;
1054-
10551050
/*
10561051
* All inbound packets other than send completion should be xfer page
10571052
* packet
@@ -1107,14 +1102,13 @@ static void netvsc_send_table(struct hv_device *hdev,
11071102
struct nvsp_message *nvmsg)
11081103
{
11091104
struct netvsc_device *nvscdev;
1110-
struct net_device *ndev;
1105+
struct net_device *ndev = hv_get_drvdata(hdev);
11111106
int i;
11121107
u32 count, *tab;
11131108

11141109
nvscdev = get_outbound_net_device(hdev);
11151110
if (!nvscdev)
11161111
return;
1117-
ndev = nvscdev->ndev;
11181112

11191113
count = nvmsg->msg.v5_msg.send_table.count;
11201114
if (count != VRSS_SEND_TAB_SIZE) {
@@ -1173,7 +1167,7 @@ void netvsc_channel_cb(void *context)
11731167
net_device = get_inbound_net_device(device);
11741168
if (!net_device)
11751169
return;
1176-
ndev = net_device->ndev;
1170+
ndev = hv_get_drvdata(device);
11771171
buffer = get_per_channel_state(channel);
11781172

11791173
do {

0 commit comments

Comments
 (0)