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

Commit d2e0655e authored by Michael S. Tsirkin's avatar Michael S. Tsirkin Committed by Roland Dreier
Browse files

IPoIB: Consolidate private neighbour data handling



Consolidate IPoIB's private neighbour data handling into
ipoib_neigh_alloc() and ipoib_neigh_free().  This will make it easier
to keep track of the neighbour structures that IPoIB is handling, and
is a nice cleanup of the code:

add/remove: 2/1 grow/shrink: 1/8 up/down: 100/-178 (-78)
function                                     old     new   delta
ipoib_neigh_alloc                              -      61     +61
ipoib_neigh_free                               -      36     +36
ipoib_mcast_join_finish                     1288    1291      +3
path_rec_completion                          575     573      -2
ipoib_mcast_join_task                        664     660      -4
ipoib_neigh_destructor                       101      92      -9
ipoib_neigh_setup_dev                         14       3     -11
ipoib_neigh_setup                             17       -     -17
path_free                                    238     215     -23
ipoib_mcast_free                             329     306     -23
ipoib_mcast_send                             718     684     -34
neigh_add_path                               705     650     -55

Signed-off-by: default avatarMichael S. Tsirkin <mst@mellanox.co.il>
Signed-off-by: default avatarRoland Dreier <rolandd@cisco.com>
parent ce1823f0
Loading
Loading
Loading
Loading
+3 −0
Original line number Original line Diff line number Diff line
@@ -230,6 +230,9 @@ static inline struct ipoib_neigh **to_ipoib_neigh(struct neighbour *neigh)
				     INFINIBAND_ALEN, sizeof(void *));
				     INFINIBAND_ALEN, sizeof(void *));
}
}


struct ipoib_neigh *ipoib_neigh_alloc(struct neighbour *neigh);
void ipoib_neigh_free(struct ipoib_neigh *neigh);

extern struct workqueue_struct *ipoib_workqueue;
extern struct workqueue_struct *ipoib_workqueue;


/* functions */
/* functions */
+29 −12
Original line number Original line Diff line number Diff line
@@ -252,8 +252,8 @@ static void path_free(struct net_device *dev, struct ipoib_path *path)
		 */
		 */
		if (neigh->ah)
		if (neigh->ah)
			ipoib_put_ah(neigh->ah);
			ipoib_put_ah(neigh->ah);
		*to_ipoib_neigh(neigh->neighbour) = NULL;

		kfree(neigh);
		ipoib_neigh_free(neigh);
	}
	}


	spin_unlock_irqrestore(&priv->lock, flags);
	spin_unlock_irqrestore(&priv->lock, flags);
@@ -481,7 +481,7 @@ static void neigh_add_path(struct sk_buff *skb, struct net_device *dev)
	struct ipoib_path *path;
	struct ipoib_path *path;
	struct ipoib_neigh *neigh;
	struct ipoib_neigh *neigh;


	neigh = kmalloc(sizeof *neigh, GFP_ATOMIC);
	neigh = ipoib_neigh_alloc(skb->dst->neighbour);
	if (!neigh) {
	if (!neigh) {
		++priv->stats.tx_dropped;
		++priv->stats.tx_dropped;
		dev_kfree_skb_any(skb);
		dev_kfree_skb_any(skb);
@@ -489,8 +489,6 @@ static void neigh_add_path(struct sk_buff *skb, struct net_device *dev)
	}
	}


	skb_queue_head_init(&neigh->queue);
	skb_queue_head_init(&neigh->queue);
	neigh->neighbour = skb->dst->neighbour;
	*to_ipoib_neigh(skb->dst->neighbour) = neigh;


	/*
	/*
	 * We can only be called from ipoib_start_xmit, so we're
	 * We can only be called from ipoib_start_xmit, so we're
@@ -503,7 +501,7 @@ static void neigh_add_path(struct sk_buff *skb, struct net_device *dev)
		path = path_rec_create(dev,
		path = path_rec_create(dev,
				       (union ib_gid *) (skb->dst->neighbour->ha + 4));
				       (union ib_gid *) (skb->dst->neighbour->ha + 4));
		if (!path)
		if (!path)
			goto err;
			goto err_path;


		__path_add(dev, path);
		__path_add(dev, path);
	}
	}
@@ -521,17 +519,17 @@ static void neigh_add_path(struct sk_buff *skb, struct net_device *dev)
		__skb_queue_tail(&neigh->queue, skb);
		__skb_queue_tail(&neigh->queue, skb);


		if (!path->query && path_rec_start(dev, path))
		if (!path->query && path_rec_start(dev, path))
			goto err;
			goto err_list;
	}
	}


	spin_unlock(&priv->lock);
	spin_unlock(&priv->lock);
	return;
	return;


err:
err_list:
	*to_ipoib_neigh(skb->dst->neighbour) = NULL;
	list_del(&neigh->list);
	list_del(&neigh->list);
	kfree(neigh);


err_path:
	ipoib_neigh_free(neigh);
	++priv->stats.tx_dropped;
	++priv->stats.tx_dropped;
	dev_kfree_skb_any(skb);
	dev_kfree_skb_any(skb);


@@ -763,8 +761,7 @@ static void ipoib_neigh_destructor(struct neighbour *n)
		if (neigh->ah)
		if (neigh->ah)
			ah = neigh->ah;
			ah = neigh->ah;
		list_del(&neigh->list);
		list_del(&neigh->list);
		*to_ipoib_neigh(n) = NULL;
		ipoib_neigh_free(neigh);
		kfree(neigh);
	}
	}


	spin_unlock_irqrestore(&priv->lock, flags);
	spin_unlock_irqrestore(&priv->lock, flags);
@@ -773,6 +770,26 @@ static void ipoib_neigh_destructor(struct neighbour *n)
		ipoib_put_ah(ah);
		ipoib_put_ah(ah);
}
}


struct ipoib_neigh *ipoib_neigh_alloc(struct neighbour *neighbour)
{
	struct ipoib_neigh *neigh;

	neigh = kmalloc(sizeof *neigh, GFP_ATOMIC);
	if (!neigh)
		return NULL;

	neigh->neighbour = neighbour;
	*to_ipoib_neigh(neighbour) = neigh;

	return neigh;
}

void ipoib_neigh_free(struct ipoib_neigh *neigh)
{
	*to_ipoib_neigh(neigh->neighbour) = NULL;
	kfree(neigh);
}

static int ipoib_neigh_setup_dev(struct net_device *dev, struct neigh_parms *parms)
static int ipoib_neigh_setup_dev(struct net_device *dev, struct neigh_parms *parms)
{
{
	parms->neigh_destructor = ipoib_neigh_destructor;
	parms->neigh_destructor = ipoib_neigh_destructor;
+2 −5
Original line number Original line Diff line number Diff line
@@ -114,8 +114,7 @@ static void ipoib_mcast_free(struct ipoib_mcast *mcast)
		 */
		 */
		if (neigh->ah)
		if (neigh->ah)
			ipoib_put_ah(neigh->ah);
			ipoib_put_ah(neigh->ah);
		*to_ipoib_neigh(neigh->neighbour) = NULL;
		ipoib_neigh_free(neigh);
		kfree(neigh);
	}
	}


	spin_unlock_irqrestore(&priv->lock, flags);
	spin_unlock_irqrestore(&priv->lock, flags);
@@ -772,13 +771,11 @@ out:
		if (skb->dst            &&
		if (skb->dst            &&
		    skb->dst->neighbour &&
		    skb->dst->neighbour &&
		    !*to_ipoib_neigh(skb->dst->neighbour)) {
		    !*to_ipoib_neigh(skb->dst->neighbour)) {
			struct ipoib_neigh *neigh = kmalloc(sizeof *neigh, GFP_ATOMIC);
			struct ipoib_neigh *neigh = ipoib_neigh_alloc(skb->dst->neighbour);


			if (neigh) {
			if (neigh) {
				kref_get(&mcast->ah->ref);
				kref_get(&mcast->ah->ref);
				neigh->ah  	= mcast->ah;
				neigh->ah  	= mcast->ah;
				neigh->neighbour = skb->dst->neighbour;
				*to_ipoib_neigh(skb->dst->neighbour) = neigh;
				list_add_tail(&neigh->list, &mcast->neigh_list);
				list_add_tail(&neigh->list, &mcast->neigh_list);
			}
			}
		}
		}