Re: [PATCH] [02/10] pasemi_mac: Stop using the pci config space accessors for register read/writes

2007-08-23 Thread Olof Johansson
On Thu, Aug 23, 2007 at 10:31:03AM +1000, Stephen Rothwell wrote:
> On Wed, 22 Aug 2007 09:12:48 -0500 Olof Johansson <[EMAIL PROTECTED]> wrote:
> >
> > -static unsigned int read_iob_reg(struct pasemi_mac *mac, unsigned int reg)
> > +static inline unsigned int read_iob_reg(struct pasemi_mac *mac, unsigned 
> > int reg)
>   ^^
> For static functions in C files, we tend not to bother marking them
> inline any more as the compiler does a pretty good job theses days.

Yeah, sloppy coding on my behalf. It was still there from when I
explicitly added noinline during debugging, forgot to take it out
alltogether.

> > -   pci_read_config_dword(mac->iob_pdev, reg, &val);
> > +   val = in_le32(mac->iob_regs+reg);
> > +
> > return val;
> 
> Why not just "return in_le32(mac->iob_regs+reg);" ?
> And similarly below?

Residual from debugging as well, I had debug hooks showing what was
read/written that I took out, but didn't fix up the surrounding stuff.


Refreshed patch posted separately. Thanks for the feedback.

-Olof
-
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] [02/10] pasemi_mac: Stop using the pci config space accessors for register read/writes

2007-08-22 Thread Stephen Rothwell
Hi Olof,

On Wed, 22 Aug 2007 09:12:48 -0500 Olof Johansson <[EMAIL PROTECTED]> wrote:
>
> -static unsigned int read_iob_reg(struct pasemi_mac *mac, unsigned int reg)
> +static inline unsigned int read_iob_reg(struct pasemi_mac *mac, unsigned int 
> reg)
  ^^
For static functions in C files, we tend not to bother marking them
inline any more as the compiler does a pretty good job theses days.

>  {
>   unsigned int val;
>  
> - pci_read_config_dword(mac->iob_pdev, reg, &val);
> + val = in_le32(mac->iob_regs+reg);
> +
>   return val;

Why not just "return in_le32(mac->iob_regs+reg);" ?
And similarly below?

> +static inline void __iomem * __devinit map_onedev(struct pci_dev *p, int 
> index)
  ^^^
Mixing inline and __*init is just plain silly :-)

> +fallback:
> + /* This is hardcoded and ugly, but we have some firmware versions
> +  * who don't provide the register space in the device tree. Luckily
   ^^^
"that"

-- 
Cheers,
Stephen Rothwell[EMAIL PROTECTED]
http://www.canb.auug.org.au/~sfr/


pgp00KliTG9BH.pgp
Description: PGP signature


[PATCH] [02/10] pasemi_mac: Stop using the pci config space accessors for register read/writes

2007-08-22 Thread Olof Johansson
Move away from using the pci config access functions for simple register
access.  Our device has all of the registers in the config space (hey,
from the hardware point of view it looks reasonable :-), so we need to
somehow get to it. Newer firmwares have it in the device tree such that
we can just get it and ioremap it there (in case it ever moves in future
products). For now, provide a hardcoded fallback for older firmwares.


Signed-off-by: Olof Johansson <[EMAIL PROTECTED]>


Index: mainline/drivers/net/pasemi_mac.c
===
--- mainline.orig/drivers/net/pasemi_mac.c
+++ mainline/drivers/net/pasemi_mac.c
@@ -81,46 +81,47 @@ MODULE_PARM_DESC(debug, "PA Semi MAC bit
 
 static struct pasdma_status *dma_status;
 
-static unsigned int read_iob_reg(struct pasemi_mac *mac, unsigned int reg)
+static inline unsigned int read_iob_reg(struct pasemi_mac *mac, unsigned int 
reg)
 {
unsigned int val;
 
-   pci_read_config_dword(mac->iob_pdev, reg, &val);
+   val = in_le32(mac->iob_regs+reg);
+
return val;
 }
 
-static void write_iob_reg(struct pasemi_mac *mac, unsigned int reg,
+static inline void write_iob_reg(struct pasemi_mac *mac, unsigned int reg,
  unsigned int val)
 {
-   pci_write_config_dword(mac->iob_pdev, reg, val);
+   out_le32(mac->iob_regs+reg, val);
 }
 
-static unsigned int read_mac_reg(struct pasemi_mac *mac, unsigned int reg)
+static inline unsigned int read_mac_reg(struct pasemi_mac *mac, unsigned int 
reg)
 {
unsigned int val;
 
-   pci_read_config_dword(mac->pdev, reg, &val);
+   val = in_le32(mac->regs+reg);
return val;
 }
 
-static void write_mac_reg(struct pasemi_mac *mac, unsigned int reg,
+static inline void write_mac_reg(struct pasemi_mac *mac, unsigned int reg,
  unsigned int val)
 {
-   pci_write_config_dword(mac->pdev, reg, val);
+   out_le32(mac->regs+reg, val);
 }
 
-static unsigned int read_dma_reg(struct pasemi_mac *mac, unsigned int reg)
+static inline unsigned int read_dma_reg(struct pasemi_mac *mac, unsigned int 
reg)
 {
unsigned int val;
 
-   pci_read_config_dword(mac->dma_pdev, reg, &val);
+   val = in_le32(mac->dma_regs+reg);
return val;
 }
 
-static void write_dma_reg(struct pasemi_mac *mac, unsigned int reg,
+static inline void write_dma_reg(struct pasemi_mac *mac, unsigned int reg,
  unsigned int val)
 {
-   pci_write_config_dword(mac->dma_pdev, reg, val);
+   out_le32(mac->dma_regs+reg, val);
 }
 
 static int pasemi_get_mac_addr(struct pasemi_mac *mac)
@@ -585,7 +586,6 @@ static int pasemi_mac_clean_tx(struct pa
}
mac->tx->next_to_clean += count;
spin_unlock_irqrestore(&mac->tx->lock, flags);
-
netif_wake_queue(mac->netdev);
 
return count;
@@ -1076,6 +1076,73 @@ static int pasemi_mac_poll(struct net_de
}
 }
 
+static inline void __iomem * __devinit map_onedev(struct pci_dev *p, int index)
+{
+   struct device_node *dn;
+   void __iomem *ret;
+
+   dn = pci_device_to_OF_node(p);
+   if (!dn)
+   goto fallback;
+
+   ret = of_iomap(dn, index);
+   if (!ret)
+   goto fallback;
+
+   return ret;
+fallback:
+   /* This is hardcoded and ugly, but we have some firmware versions
+* who don't provide the register space in the device tree. Luckily
+* they are at well-known locations so we can just do the math here.
+*/
+   return ioremap(0xe000 + (p->devfn << 12), 0x2000);
+}
+
+static int __devinit pasemi_mac_map_regs(struct pasemi_mac *mac)
+{
+   struct resource res;
+   struct device_node *dn;
+   int err;
+
+   mac->dma_pdev = pci_get_device(PCI_VENDOR_ID_PASEMI, 0xa007, NULL);
+   if (!mac->dma_pdev) {
+   dev_err(&mac->pdev->dev, "Can't find DMA Controller\n");
+   return -ENODEV;
+   }
+
+   mac->iob_pdev = pci_get_device(PCI_VENDOR_ID_PASEMI, 0xa001, NULL);
+   if (!mac->iob_pdev) {
+   dev_err(&mac->pdev->dev, "Can't find I/O Bridge\n");
+   return -ENODEV;
+   }
+
+   mac->regs = map_onedev(mac->pdev, 0);
+   mac->dma_regs = map_onedev(mac->dma_pdev, 0);
+   mac->iob_regs = map_onedev(mac->iob_pdev, 0);
+
+   if (!mac->regs || !mac->dma_regs || !mac->iob_regs) {
+   dev_err(&mac->pdev->dev, "Can't map registers\n");
+   return -ENODEV;
+   }
+
+   /* The dma status structure is located in the I/O bridge, and
+* is cache coherent.
+*/
+   if (!dma_status) {
+   dn = pci_device_to_OF_node(mac->iob_pdev);
+   if (dn)
+   err = of_address_to_resource(dn, 1, &res);
+   if (!dn || err) {
+   /* Fallback for old firmware */
+   res.start = 0xfd80;
+   res