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

Commit 6e03718c authored by kirjanov@gmail.com's avatar kirjanov@gmail.com Committed by David S. Miller
Browse files

greth: some driver cleanups



On Fri, Feb 19, 2010 at 13:51 +0100, Jiri Pirko wrote:
>
> <snip>
> >>@@ -1031,7 +1029,7 @@ static void greth_set_multicast_list(struct net_device *dev)
> >> 			return;
> >> 		}
> >>
> >>-		if (dev->mc_count == 0) {
> >>+		if (!netdev_mc_count(dev)) {
> also please use netdev_mc_empty() here.
Some driver cleanups:
* convert to use phy_find_first/phy_direct_connect
* convert to use netdev_mc_* helpers
* fixed missing validate_addr hook
* removed netdev_priv castings

Signed-off-by: default avatarDenis Kirjanov <kirjanov@gmail.com>
Reviewed-by: default avatarJiri Pirko <jpirko@redhat.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 91fea585
Loading
Loading
Loading
Loading
+18 −31
Original line number Original line Diff line number Diff line
@@ -965,7 +965,7 @@ static int greth_set_mac_add(struct net_device *dev, void *p)
	struct greth_private *greth;
	struct greth_private *greth;
	struct greth_regs *regs;
	struct greth_regs *regs;


	greth = (struct greth_private *) netdev_priv(dev);
	greth = netdev_priv(dev);
	regs = (struct greth_regs *) greth->regs;
	regs = (struct greth_regs *) greth->regs;


	if (!is_valid_ether_addr(addr->sa_data))
	if (!is_valid_ether_addr(addr->sa_data))
@@ -988,20 +988,14 @@ static u32 greth_hash_get_index(__u8 *addr)
static void greth_set_hash_filter(struct net_device *dev)
static void greth_set_hash_filter(struct net_device *dev)
{
{
	struct dev_mc_list *curr;
	struct dev_mc_list *curr;
	struct greth_private *greth = (struct greth_private *) netdev_priv(dev);
	struct greth_private *greth = netdev_priv(dev);
	struct greth_regs *regs = (struct greth_regs *) greth->regs;
	struct greth_regs *regs = (struct greth_regs *) greth->regs;
	u32 mc_filter[2];
	u32 mc_filter[2];
	unsigned int i, bitnr;
	unsigned int bitnr;


	mc_filter[0] = mc_filter[1] = 0;
	mc_filter[0] = mc_filter[1] = 0;


	curr = dev->mc_list;
	netdev_for_each_mc_addr(curr, dev) {

	for (i = 0; i < dev->mc_count; i++, curr = curr->next) {

		if (!curr)
			break;	/* unexpected end of list */

		bitnr = greth_hash_get_index(curr->dmi_addr);
		bitnr = greth_hash_get_index(curr->dmi_addr);
		mc_filter[bitnr >> 5] |= 1 << (bitnr & 31);
		mc_filter[bitnr >> 5] |= 1 << (bitnr & 31);
	}
	}
@@ -1031,7 +1025,7 @@ static void greth_set_multicast_list(struct net_device *dev)
			return;
			return;
		}
		}


		if (dev->mc_count == 0) {
		if (netdev_mc_empty(dev)) {
			cfg &= ~GRETH_CTRL_MCEN;
			cfg &= ~GRETH_CTRL_MCEN;
			GRETH_REGSAVE(regs->control, cfg);
			GRETH_REGSAVE(regs->control, cfg);
			return;
			return;
@@ -1160,6 +1154,7 @@ static struct net_device_ops greth_netdev_ops = {
	.ndo_stop = greth_close,
	.ndo_stop = greth_close,
	.ndo_start_xmit = greth_start_xmit,
	.ndo_start_xmit = greth_start_xmit,
	.ndo_set_mac_address = greth_set_mac_add,
	.ndo_set_mac_address = greth_set_mac_add,
	.ndo_validate_addr 	= eth_validate_addr,
};
};


static inline int wait_for_mdio(struct greth_private *greth)
static inline int wait_for_mdio(struct greth_private *greth)
@@ -1275,28 +1270,26 @@ static int greth_mdio_probe(struct net_device *dev)
{
{
	struct greth_private *greth = netdev_priv(dev);
	struct greth_private *greth = netdev_priv(dev);
	struct phy_device *phy = NULL;
	struct phy_device *phy = NULL;
	u32 interface;
	int ret;
	int i;


	/* Find the first PHY */
	/* Find the first PHY */
	for (i = 0; i < PHY_MAX_ADDR; i++) {
	phy = phy_find_first(greth->mdio);
		if (greth->mdio->phy_map[i]) {

			phy = greth->mdio->phy_map[i];
			break;
		}
	}
	if (!phy) {
	if (!phy) {
		if (netif_msg_probe(greth))
		if (netif_msg_probe(greth))
			dev_err(&dev->dev, "no PHY found\n");
			dev_err(&dev->dev, "no PHY found\n");
		return -ENXIO;
		return -ENXIO;
	}
	}


	if (greth->gbit_mac)
	ret = phy_connect_direct(dev, phy, &greth_link_change,
		interface = PHY_INTERFACE_MODE_GMII;
			0, greth->gbit_mac ?
	else
			PHY_INTERFACE_MODE_GMII :
		interface = PHY_INTERFACE_MODE_MII;
			PHY_INTERFACE_MODE_MII);

	if (ret) {
	phy = phy_connect(dev, dev_name(&phy->dev), &greth_link_change, 0, interface);
		if (netif_msg_ifup(greth))
			dev_err(&dev->dev, "could not attach to PHY\n");
		return ret;
	}


	if (greth->gbit_mac)
	if (greth->gbit_mac)
		phy->supported &= PHY_GBIT_FEATURES;
		phy->supported &= PHY_GBIT_FEATURES;
@@ -1305,12 +1298,6 @@ static int greth_mdio_probe(struct net_device *dev)


	phy->advertising = phy->supported;
	phy->advertising = phy->supported;


	if (IS_ERR(phy)) {
		if (netif_msg_ifup(greth))
			dev_err(&dev->dev, "could not attach to PHY\n");
		return PTR_ERR(phy);
	}

	greth->link = 0;
	greth->link = 0;
	greth->speed = 0;
	greth->speed = 0;
	greth->duplex = -1;
	greth->duplex = -1;