Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 43c7bd1f authored by stephen hemminger's avatar stephen hemminger Committed by David S. Miller
Browse files

netvsc: use refcount_t for keeping track of sub channels



Rather than a lock and variable, use a refcount_t to keep track
of the number of sub channels.  Don't need to wait for subchannels
on device removal since wait was already done in device_add.

Also fix the error handling; don't wait forever in case of
an error on request to create sub channels.

Signed-off-by: default avatarStephen Hemminger <sthemmin@microsoft.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent a0be450e
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -761,8 +761,8 @@ struct netvsc_device {

	u32 max_chn;
	u32 num_chn;
	spinlock_t sc_lock; /* Protects num_sc_offered variable */
	u32 num_sc_offered;

	refcount_t sc_offered;

	/* Holds rndis device info */
	void *extension;
+10 −31
Original line number Diff line number Diff line
@@ -997,7 +997,6 @@ static void netvsc_sc_open(struct vmbus_channel *new_sc)
	struct netvsc_device *nvscdev = net_device_to_netvsc_device(ndev);
	u16 chn_index = new_sc->offermsg.offer.sub_channel_index;
	struct netvsc_channel *nvchan;
	unsigned long flags;
	int ret;

	if (chn_index >= nvscdev->num_chn)
@@ -1019,10 +1018,7 @@ static void netvsc_sc_open(struct vmbus_channel *new_sc)

	napi_enable(&nvchan->napi);

	spin_lock_irqsave(&nvscdev->sc_lock, flags);
	nvscdev->num_sc_offered--;
	spin_unlock_irqrestore(&nvscdev->sc_lock, flags);
	if (nvscdev->num_sc_offered == 0)
	if (refcount_dec_and_test(&nvscdev->sc_offered))
		complete(&nvscdev->channel_init_wait);
}

@@ -1039,12 +1035,9 @@ int rndis_filter_device_add(struct hv_device *dev,
	struct ndis_recv_scale_cap rsscap;
	u32 rsscap_size = sizeof(struct ndis_recv_scale_cap);
	unsigned int gso_max_size = GSO_MAX_SIZE;
	u32 mtu, size;
	u32 num_rss_qs;
	u32 sc_delta;
	u32 mtu, size, num_rss_qs;
	const struct cpumask *node_cpu_mask;
	u32 num_possible_rss_qs;
	unsigned long flags;
	int i, ret;

	rndis_device = get_rndis_device();
@@ -1067,7 +1060,7 @@ int rndis_filter_device_add(struct hv_device *dev,
	net_device->max_chn = 1;
	net_device->num_chn = 1;

	spin_lock_init(&net_device->sc_lock);
	refcount_set(&net_device->sc_offered, 0);

	net_device->extension = rndis_device;
	rndis_device->ndev = net;
@@ -1204,6 +1197,7 @@ int rndis_filter_device_add(struct hv_device *dev,
	if (num_rss_qs == 0)
		return 0;

	refcount_set(&net_device->sc_offered, num_rss_qs);
	vmbus_set_sc_create_callback(dev->channel, netvsc_sc_open);

	init_packet = &net_device->channel_init_pkt;
@@ -1219,32 +1213,23 @@ int rndis_filter_device_add(struct hv_device *dev,
			       VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED);
	if (ret)
		goto out;
	wait_for_completion(&net_device->channel_init_wait);

	if (init_packet->msg.v5_msg.subchn_comp.status !=
	    NVSP_STAT_SUCCESS) {
	if (init_packet->msg.v5_msg.subchn_comp.status != NVSP_STAT_SUCCESS) {
		ret = -ENODEV;
		goto out;
	}
	wait_for_completion(&net_device->channel_init_wait);

	net_device->num_chn = 1 +
		init_packet->msg.v5_msg.subchn_comp.num_subchannels;

	ret = rndis_filter_set_rss_param(rndis_device, netvsc_hash_key,
	/* ignore failues from setting rss parameters, still have channels */
	rndis_filter_set_rss_param(rndis_device, netvsc_hash_key,
				   net_device->num_chn);

	/*
	 * Set the number of sub-channels to be received.
	 */
	spin_lock_irqsave(&net_device->sc_lock, flags);
	sc_delta = num_rss_qs - (net_device->num_chn - 1);
	net_device->num_sc_offered -= sc_delta;
	spin_unlock_irqrestore(&net_device->sc_lock, flags);

out:
	if (ret) {
		net_device->max_chn = 1;
		net_device->num_chn = 1;
		net_device->num_sc_offered = 0;
	}

	return 0; /* return 0 because primary channel can be used alone */
@@ -1259,12 +1244,6 @@ void rndis_filter_device_remove(struct hv_device *dev,
{
	struct rndis_device *rndis_dev = net_dev->extension;

	/* If not all subchannel offers are complete, wait for them until
	 * completion to avoid race.
	 */
	if (net_dev->num_sc_offered > 0)
		wait_for_completion(&net_dev->channel_init_wait);

	/* Halt and release the rndis device */
	rndis_filter_halt_device(rndis_dev);