Subject: Re: [PATCH] [v3] PA Semi PWRficient Ethernet driver

From: Ingo Oeser <[email-masked]>
Date: Wed, 31 Jan 2007 13:44:31 +0100

Hi,

Olof Johansson schrieb:
[...]
> +static int pasemi_mac_close(struct net_device *dev)
> +{
[..]
> +	do {
> +		pci_read_config_dword(mac->dma_pdev,
> +				      PAS_DMA_TXCHAN_TCMDSTA(mac->dma_txch),
> +				      &stat);
> +	} while (stat & PAS_DMA_TXCHAN_TCMDSTA_ACT);
> +
> +	do {
> +		pci_read_config_dword(mac->dma_pdev,
> +				      PAS_DMA_RXCHAN_CCMDSTA(mac->dma_rxch),
> +				      &stat);
> +	} while (stat & PAS_DMA_RXCHAN_CCMDSTA_ACT);
> +
> +	do {
> +		pci_read_config_dword(mac->dma_pdev,
> +				      PAS_DMA_RXINT_RCMDSTA(mac->dma_if),
> +				      &stat);
> +	} while (stat & PAS_DMA_RXINT_RCMDSTA_ACT);

You might want to write these loops like that:

#define MAX_READ_TRIES 10000
unsigned int tries;
unsigned int state;
for(tries=0; tries < MAX_READ_TRIES; tries++)
{
	read_stat(&stat);
	if ((stat & STATE_FLAG) == 0);
		break;
	cond_resched();
}
if (stat & STATE_FLAG) {
	dev_err(&mac->pdev->dev, "Failed to stop device, possible hardware error?\n");
        /* Panic, disable device, mark unusable, whatever is better than hanging here */
}

That way you:
- Let you give other processes a chance to run, 
  while you wait for your hardware state to change 
  (if your hardware can tolerate these latencies).
- can somehow handle hardware failure and at least give the user a clue
  what is happening.

Regards

Ingo Oeser