Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

net: axienet: Autodetect 64-bit DMA capability

When newer revisions of the Axienet IP are configured for a 64-bit bus,
we *need* to write to the MSB part of the an address registers,
otherwise the IP won't recognise this as a DMA start condition.
This is even true when the actual DMA address comes from the lower 4 GB.

To autodetect this configuration, at probe time we write all 1's to such
an MSB register, and see if any bits stick. If this is configured for a
32-bit bus, those MSB registers are RES0, so reading back 0 indicates
that no MSB writes are necessary.
On the other hands reading anything other than 0 indicated the need to
write the MSB registers, so we set the respective flag.

The actual DMA mask stays at 32-bit for now. To help bisecting, a
separate patch will enable allocations from higher addresses.

Signed-off-by: Andre Przywara <andre.przywara@arm.com>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Andre Przywara and committed by
David S. Miller
f735c40e 4e958f33

+27
+1
drivers/net/ethernet/xilinx/xilinx_axienet.h
··· 161 161 #define XAE_FCC_OFFSET 0x0000040C /* Flow Control Configuration */ 162 162 #define XAE_EMMC_OFFSET 0x00000410 /* EMAC mode configuration */ 163 163 #define XAE_PHYC_OFFSET 0x00000414 /* RGMII/SGMII configuration */ 164 + #define XAE_ID_OFFSET 0x000004F8 /* Identification register */ 164 165 #define XAE_MDIO_MC_OFFSET 0x00000500 /* MII Management Config */ 165 166 #define XAE_MDIO_MCR_OFFSET 0x00000504 /* MII Management Control */ 166 167 #define XAE_MDIO_MWD_OFFSET 0x00000508 /* MII Management Write Data */
+26
drivers/net/ethernet/xilinx/xilinx_axienet_main.c
··· 151 151 dma_addr_t addr) 152 152 { 153 153 axienet_dma_out32(lp, reg, lower_32_bits(addr)); 154 + 155 + if (lp->features & XAE_FEATURE_DMA_64BIT) 156 + axienet_dma_out32(lp, reg + 4, upper_32_bits(addr)); 154 157 } 155 158 156 159 static void desc_set_phys_addr(struct axienet_local *lp, dma_addr_t addr, ··· 1929 1926 dev_err(&pdev->dev, "could not determine irqs\n"); 1930 1927 ret = -ENOMEM; 1931 1928 goto free_netdev; 1929 + } 1930 + 1931 + /* Autodetect the need for 64-bit DMA pointers. 1932 + * When the IP is configured for a bus width bigger than 32 bits, 1933 + * writing the MSB registers is mandatory, even if they are all 0. 1934 + * We can detect this case by writing all 1's to one such register 1935 + * and see if that sticks: when the IP is configured for 32 bits 1936 + * only, those registers are RES0. 1937 + * Those MSB registers were introduced in IP v7.1, which we check first. 1938 + */ 1939 + if ((axienet_ior(lp, XAE_ID_OFFSET) >> 24) >= 0x9) { 1940 + void __iomem *desc = lp->dma_regs + XAXIDMA_TX_CDESC_OFFSET + 4; 1941 + 1942 + iowrite32(0x0, desc); 1943 + if (ioread32(desc) == 0) { /* sanity check */ 1944 + iowrite32(0xffffffff, desc); 1945 + if (ioread32(desc) > 0) { 1946 + lp->features |= XAE_FEATURE_DMA_64BIT; 1947 + dev_info(&pdev->dev, 1948 + "autodetected 64-bit DMA range\n"); 1949 + } 1950 + iowrite32(0x0, desc); 1951 + } 1932 1952 } 1933 1953 1934 1954 /* Check for Ethernet core IRQ (optional) */