• Russell King's avatar
    PCI: mvebu: Use exact config access size; don't read/modify/write · 79e3f6ce
    Russell King authored
    The idea that you can arbitarily read 32-bits from PCI configuration space,
    modify a sub-field (like the command register) and write it back without
    consequence is deeply flawed.
    
    Status registers (such as the status register, PCIe device status register,
    etc) contain status bits which are read, write-one-to-clear.
    
    What this means is that reading 32-bits from the command register,
    modifying the command register, and then writing it back has the effect of
    clearing any status bits that were indicating at that time.  Same for the
    PCIe device control register clearing bits in the PCIe device status
    register.
    
    Since the Armada chips support byte, 16-bit and 32-bit accesses to the
    registers (unless otherwise stated) and the PCI configuration data register
    does not specify otherwise, it seems logical that the chip can indeed
    generate the proper configuration access cycles down to byte level.
    
    Testing with an ASM1062 PCIe to SATA mini-PCIe card on Armada 388.  PCIe
    capability at 0x80, DevCtl at 0x88, DevSta at 0x8a.
    
    Before:
      /# setpci -s 1:0.0 0x88.l		- DevSta: CorrErr+
      00012810
      /# setpci -s 1:0.0 0x88.w=0x2810	- Write DevCtl only
      /# setpci -s 1:0.0 0x88.l		- CorrErr cleared - FAIL
      00002810
    
    After:
      /# setpci -s 1:0.0 0x88.l		- DevSta: CorrErr+
      00012810
      /# setpci -s 1:0.0 0x88.w=0x2810	- check DevCtl only write
      /# setpci -s 1:0.0 0x88.l		- CorErr remains set
      00012810
      /# setpci -s 1:0.0 0x88.w=0x281f	- check DevCtl write works
      /# setpci -s 1:0.0 0x88.l		- devctl field updated
      0001281f
      /# setpci -s 1:0.0 0x8a.w=0xffff	- clear DevSta
      /# setpci -s 1:0.0 0x88.l		- CorrErr now cleared
      0000281f
      /# setpci -s 1:0.0 0x88.w=0x2810	- restore DevCtl
      /# setpci -s 1:0.0 0x88.l		- check
      00002810
    
    [bhelgaas: changelog]
    Tested-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com> (Armada XP GP)
    Tested-by: Andrew Lunn <andrew@lunn.ch> (Kirkwood DIR665)
    Signed-off-by: default avatarRussell King <rmk+kernel@arm.linux.org.uk>
    Signed-off-by: default avatarBjorn Helgaas <bhelgaas@google.com>
    Reviewed-by: default avatarThomas Petazzoni <thomas.petazzoni@free-electrons.com>
    79e3f6ce
pci-mvebu.c 28 KB