linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Francois Romieu <romieu@fr.zoreil.com>
To: Jason McMullan <jason.mcmullan@timesys.com>
Cc: linux-kernel@vger.kernel.org, jgarzik@pobox.com
Subject: Re: [PATCH] MII bus API for PHY devices
Date: Fri, 12 Nov 2004 00:54:39 +0100	[thread overview]
Message-ID: <20041111235439.GB13327@electric-eye.fr.zoreil.com> (raw)
In-Reply-To: <20041111224845.GA12646@jmcmullan.timesys>

Jason McMullan <jason.mcmullan@timesys.com> :
[...]
> --- /dev/null
> +++ linux/drivers/net/mii_bus.c
[...]
> +struct phy_cmd {
> +    u32 mii_reg;
> +    u32 mii_data;
> +    u16 (*funct) (u16 mii_reg, int bus, int id);
   ^^^^

-> spaces

[...]
> +    /* Local state information */
> +    struct {
> +	int irq;
> +	unsigned long msecs;
> +	void (*func)(void *data);
> +	void *data;
> +    	struct work_struct tq;
> +	struct timer_list timer;
   ^^^^^

-> tab...

> +    } delta;
   ^^^^

-> ...spaces

[...]
> +/* Write value to the PHY for this device to the register at regnum, */
> +/* waiting until the write is done before it returns.  All PHY */
> +/* configuration has to be done through the TSEC1 MIIM regs */
> +EXPORT_SYMBOL(mii_bus_write);
> +int mii_bus_write(int bus, int id, int regnum, uint16_t value)
                                                  ^^^^^^^^
-> the code of this file has already used some u16/u32 before this point.

> +{
> +	if (!VALID_BUS(bus))
> +		return -EINVAL;
> +
> +       	mii_bus[bus]->write(mii_bus[bus]->priv,id,regnum,value);
   ^^^^^^^^^^^^^

-> spaces instead of tab
-> please add a space after a colon

-> AFAIKS, the code guarantees that VALID_BUS will not fail.

> +	return 0;
> +}
> +
> +/* Reads from register regnum in the PHY for device dev, */
> +/* returning the value.  Clears miimcom first.  All PHY */
> +/* configuration has to be done through the TSEC1 MIIM regs */
> +EXPORT_SYMBOL(mii_bus_read);
> +int mii_bus_read(int bus, int id, int regnum)
> +{
> +	if (!VALID_BUS(bus))
> +		return -EINVAL;
> +
> +       	return mii_bus[bus]->read(mii_bus[bus]->priv,id,regnum);

-> see above.

[...]
> +#define BRIEF_MII_ERRORS
> +/* Wait for auto-negotiation to complete */
> +u16 mii_parse_sr(u16 mii_reg, int bus, int id)
> +{
> +	unsigned int timeout = MII_TIMEOUT;
> +	struct phy_state *pstate;
> +
> +	if (!VALID(bus, id)) return 0xffff;

-> the return on a separate line only costs an extra character
   and makes the style more consistent (see the code above).

[...]
> +u16 mii_parse_cis8201(u16 mii_reg, int bus, int id)
> +{
> +	unsigned int speed;
> +	struct phy_state *pstate;
> +
> +	if (!VALID(bus, id)) return 0xffff;
> +	pstate = &mii_bus[bus]->phy[id]->state;
> +
> +	if (pstate->link) {
> +		if (mii_reg & MIIM_CIS8201_AUXCONSTAT_DUPLEX)
> +			pstate->duplex = 1;
> +		else
> +			pstate->duplex = 0;

-> If you are really concerned about the size of the source code:
		pstate->duplex =
			(mii_reg & MIIM_CIS8201_AUXCONSTAT_DUPLEX) ? 1 : 0;
> +	NULL
> +};
> +
> +/* Use the PHY ID registers to determine what type of PHY is attached
> + * to device dev.  return a struct phy_info structure describing that PHY
> + */
> +struct phy_info *mii_phy_get_info(int bus, int id)
> +{
> +	u16 phy_reg;
> +	u32 phy_ID;
> +	int i;
> +	struct phy_info *theInfo = NULL;

-> s/theInfo/info/ ?


> +	if (mii_bus[bus] == NULL)
> +		return NULL;

-> This function is not exported and the caller has already
   issued a VALID_BUS.

[...]
> +	/* loop through all the known PHY types, and find one that */
> +	/* matches the ID we read from the PHY. */
> +	for (i = 0; phy_info[i]; i++)
> +		if (phy_info[i]->id == (phy_ID >> phy_info[i]->shift))
> +			theInfo = phy_info[i];

-> add braces around the for block + break ?

> +
> +	if (theInfo == NULL) {
> +		printk("phy %d.%d: PHY id 0x%x is not supported!\n", bus, id, phy_ID);
> +		return NULL;

-> no need to return here.

> +	} else {
> +		printk("phy %d.%d: PHY is %s (%x)\n", bus, id, theInfo->name,
> +		       phy_ID);
> +	}
> +
> +	return theInfo;
> +}
[...]
> +int mii_phy_attach(struct mii_if_info *mii, struct net_device *dev, int bus, int id)
> +{
> +	struct phy_info *phy,*info;
> +
> +	if (mii_bus[bus] == NULL) {
> +		printk(KERN_ERR "mii_phy_attach: Can't attach %s, no MII bus %d present\n",dev->name,bus);
> +		return -ENODEV;
> +	}
> +
> +	if (VALID(bus,id)) {
> +		printk(KERN_ERR "mii_phy_attach: PHY %d.%d is already attached to %s\n",bus,id,dev->name);
> +		return -EBUSY;
> +	}
> +
> +	info = mii_phy_get_info(bus, id);
> +	if (info == NULL)
> +		return -ENODEV;
> +
> +	phy = kmalloc(sizeof(*phy), GFP_KERNEL);
> +	memcpy(phy,info,sizeof(*phy));

-> kmalloc can fail.

[...]
> +int mii_bus_register(struct mii_bus *bus)
> +{
> +	int bus_id;
> +
> +	if (bus == NULL || bus->name == NULL || bus->read == NULL ||
> +	    bus->write == NULL)
> +		return -EINVAL;
[...]
> +	mii_bus[bus_id] = bus;
> +
> +	if (mii_bus[bus_id] == NULL) {

-> bus is not NULL, neither is mii_bus[bus_id] (see above).

> +		up(&mii_bus_lock);
> +		return -EINVAL;
> +	}
> +
> +	if (mii_bus[bus_id]->reset)
> +		mii_bus[bus_id]->reset(mii_bus[bus_id]->priv);

	if (bus->reset)
		bus->reset(bus->priv);

Please, pretty please, more polish (I did not say that it could
be done instantly :o) ).

--
Ueimor

  reply	other threads:[~2004-11-12  0:01 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-11-11 22:48 [PATCH] MII bus API for PHY devices Jason McMullan
2004-11-11 23:54 ` Francois Romieu [this message]
2004-11-12  0:07   ` Francois Romieu
2004-11-12  6:15 ` Benjamin Herrenschmidt
2004-11-12 16:47   ` Jason McMullan
2004-11-13  1:36     ` Benjamin Herrenschmidt
  -- strict thread matches above, loose matches on Subject: below --
2004-11-19 20:18 Manfred Spraul
2004-11-19 21:01 ` Andy Fleming
     [not found] <069B6F33-341C-11D9-9652-000393DBC2E8@freescale.com>
2004-11-18 17:52 ` Andy Fleming
2004-11-18 19:34   ` Jason McMullan
2004-11-18 19:50     ` Andy Fleming
2004-11-18 21:00       ` Jason McMullan
2004-11-18 23:26   ` Benjamin Herrenschmidt
2004-11-19 16:41     ` Jason McMullan
2004-11-19 21:18     ` Andy Fleming
2004-11-19 22:43       ` Benjamin Herrenschmidt
2004-11-20  0:04         ` Andy Fleming
2004-11-11 19:45 Jason McMullan
2004-11-11 21:31 ` Francois Romieu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20041111235439.GB13327@electric-eye.fr.zoreil.com \
    --to=romieu@fr.zoreil.com \
    --cc=jason.mcmullan@timesys.com \
    --cc=jgarzik@pobox.com \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).