diff options
Diffstat (limited to 'cvmx-mdio.h')
| -rw-r--r-- | cvmx-mdio.h | 190 |
1 files changed, 115 insertions, 75 deletions
diff --git a/cvmx-mdio.h b/cvmx-mdio.h index e203ffe81c7d..859f03e83704 100644 --- a/cvmx-mdio.h +++ b/cvmx-mdio.h @@ -1,39 +1,40 @@ /***********************license start*************** - * Copyright (c) 2003-2008 Cavium Networks (support@cavium.com). All rights - * reserved. + * Copyright (c) 2003-2010 Cavium Networks (support@cavium.com). All rights + * reserved. * * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials provided - * with the distribution. - * - * * Neither the name of Cavium Networks nor the names of - * its contributors may be used to endorse or promote products - * derived from this software without specific prior written - * permission. - * - * TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED "AS IS" - * AND WITH ALL FAULTS AND CAVIUM NETWORKS MAKES NO PROMISES, REPRESENTATIONS - * OR WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY, OR OTHERWISE, WITH - * RESPECT TO THE SOFTWARE, INCLUDING ITS CONDITION, ITS CONFORMITY TO ANY - * REPRESENTATION OR DESCRIPTION, OR THE EXISTENCE OF ANY LATENT OR PATENT - * DEFECTS, AND CAVIUM SPECIFICALLY DISCLAIMS ALL IMPLIED (IF ANY) WARRANTIES - * OF TITLE, MERCHANTABILITY, NONINFRINGEMENT, FITNESS FOR A PARTICULAR - * PURPOSE, LACK OF VIRUSES, ACCURACY OR COMPLETENESS, QUIET ENJOYMENT, QUIET - * POSSESSION OR CORRESPONDENCE TO DESCRIPTION. THE ENTIRE RISK ARISING OUT - * OF USE OR PERFORMANCE OF THE SOFTWARE LIES WITH YOU. - * - * - * For any questions regarding licensing please contact marketing@caviumnetworks.com + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. * + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + + * * Neither the name of Cavium Networks nor the names of + * its contributors may be used to endorse or promote products + * derived from this software without specific prior written + * permission. + + * This Software, including technical data, may be subject to U.S. export control + * laws, including the U.S. Export Administration Act and its associated + * regulations, and may be subject to export or import regulations in other + * countries. + + * TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED "AS IS" + * AND WITH ALL FAULTS AND CAVIUM NETWORKS MAKES NO PROMISES, REPRESENTATIONS OR + * WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY, OR OTHERWISE, WITH RESPECT TO + * THE SOFTWARE, INCLUDING ITS CONDITION, ITS CONFORMITY TO ANY REPRESENTATION OR + * DESCRIPTION, OR THE EXISTENCE OF ANY LATENT OR PATENT DEFECTS, AND CAVIUM + * SPECIFICALLY DISCLAIMS ALL IMPLIED (IF ANY) WARRANTIES OF TITLE, + * MERCHANTABILITY, NONINFRINGEMENT, FITNESS FOR A PARTICULAR PURPOSE, LACK OF + * VIRUSES, ACCURACY OR COMPLETENESS, QUIET ENJOYMENT, QUIET POSSESSION OR + * CORRESPONDENCE TO DESCRIPTION. THE ENTIRE RISK ARISING OUT OF USE OR + * PERFORMANCE OF THE SOFTWARE LIES WITH YOU. ***********************license end**************************************/ @@ -41,18 +42,26 @@ + /** * @file * * Interface to the SMI/MDIO hardware, including support for both IEEE 802.3 * clause 22 and clause 45 operations. * - * <hr>$Revision: 41586 $<hr> + * <hr>$Revision: 52004 $<hr> */ #ifndef __CVMX_MIO_H__ #define __CVMX_MIO_H__ +#ifdef CVMX_BUILD_FOR_LINUX_KERNEL +#include <asm/octeon/octeon.h> +#include <asm/octeon/cvmx-clock.h> +#else +#include "cvmx-clock.h" +#endif + #ifdef __cplusplus extern "C" { #endif @@ -310,6 +319,8 @@ typedef union #define CVMX_MMD_DEVICE_VENDOR_1 30 #define CVMX_MMD_DEVICE_VENDOR_2 31 +#define CVMX_MDIO_TIMEOUT 100000 /* 100 millisec */ + /* Helper function to put MDIO interface into clause 45 mode */ static inline void __cvmx_mdio_set_clause45_mode(int bus_id) { @@ -331,6 +342,30 @@ static inline void __cvmx_mdio_set_clause22_mode(int bus_id) } /** + * @INTERNAL + * Function to read SMIX_RD_DAT and check for timeouts. This + * code sequence is done fairly often, so put in in one spot. + * + * @param bus_id SMI/MDIO bus to read + * + * @return Value of SMIX_RD_DAT. pending will be set on + * a timeout. + */ +static inline cvmx_smix_rd_dat_t __cvmx_mdio_read_rd_dat(int bus_id) +{ + cvmx_smix_rd_dat_t smi_rd; + uint64_t done = cvmx_get_cycle() + (uint64_t)CVMX_MDIO_TIMEOUT * + cvmx_clock_get_rate(CVMX_CLOCK_CORE) / 1000000; + do + { + cvmx_wait(1000); + smi_rd.u64 = cvmx_read_csr(CVMX_SMIX_RD_DAT(bus_id)); + } while (smi_rd.s.pending && (cvmx_get_cycle() < done)); + return smi_rd; +} + + +/** * Perform an MII read. This function is used to read PHY * registers controlling auto negotiation. * @@ -343,9 +378,24 @@ static inline void __cvmx_mdio_set_clause22_mode(int bus_id) */ static inline int cvmx_mdio_read(int bus_id, int phy_id, int location) { +#if defined(CVMX_BUILD_FOR_LINUX_KERNEL) && defined(CONFIG_PHYLIB) + struct mii_bus *bus; + int rv; + + BUG_ON(bus_id > 1 || bus_id < 0); + + bus = octeon_mdiobuses[bus_id]; + if (bus == NULL) + return -1; + + rv = mdiobus_read(bus, phy_id, location); + + if (rv < 0) + return -1; + return rv; +#else cvmx_smix_cmd_t smi_cmd; cvmx_smix_rd_dat_t smi_rd; - int timeout = 1000; if (octeon_has_feature(OCTEON_FEATURE_MDIO_CLAUSE_45)) __cvmx_mdio_set_clause22_mode(bus_id); @@ -356,16 +406,12 @@ static inline int cvmx_mdio_read(int bus_id, int phy_id, int location) smi_cmd.s.reg_adr = location; cvmx_write_csr(CVMX_SMIX_CMD(bus_id), smi_cmd.u64); - do - { - cvmx_wait(1000); - smi_rd.u64 = cvmx_read_csr(CVMX_SMIX_RD_DAT(bus_id)); - } while (smi_rd.s.pending && timeout--); - + smi_rd = __cvmx_mdio_read_rd_dat(bus_id); if (smi_rd.s.val) return smi_rd.s.dat; else return -1; +#endif } @@ -384,9 +430,24 @@ static inline int cvmx_mdio_read(int bus_id, int phy_id, int location) */ static inline int cvmx_mdio_write(int bus_id, int phy_id, int location, int val) { - cvmx_smix_cmd_t smi_cmd; +#if defined(CVMX_BUILD_FOR_LINUX_KERNEL) && defined(CONFIG_PHYLIB) + struct mii_bus *bus; + int rv; + + BUG_ON(bus_id > 1 || bus_id < 0); + + bus = octeon_mdiobuses[bus_id]; + if (bus == NULL) + return -1; + + rv = mdiobus_write(bus, phy_id, location, (u16)val); + + if (rv < 0) + return -1; + return 0; +#else + cvmx_smix_cmd_t smi_cmd; cvmx_smix_wr_dat_t smi_wr; - int timeout = 1000; if (octeon_has_feature(OCTEON_FEATURE_MDIO_CLAUSE_45)) __cvmx_mdio_set_clause22_mode(bus_id); @@ -401,17 +462,15 @@ static inline int cvmx_mdio_write(int bus_id, int phy_id, int location, int val) smi_cmd.s.reg_adr = location; cvmx_write_csr(CVMX_SMIX_CMD(bus_id), smi_cmd.u64); - do - { - cvmx_wait(1000); - smi_wr.u64 = cvmx_read_csr(CVMX_SMIX_WR_DAT(bus_id)); - } while (smi_wr.s.pending && --timeout); - if (timeout <= 0) + if (CVMX_WAIT_FOR_FIELD64(CVMX_SMIX_WR_DAT(bus_id), + cvmx_smix_wr_dat_t, pending, ==, 0, CVMX_MDIO_TIMEOUT)) return -1; return 0; +#endif } +#ifndef CVMX_BUILD_FOR_LINUX_KERNEL /** * Perform an IEEE 802.3 clause 45 MII read. This function is used to read PHY * registers controlling auto negotiation. @@ -430,7 +489,6 @@ static inline int cvmx_mdio_45_read(int bus_id, int phy_id, int device, int loca cvmx_smix_cmd_t smi_cmd; cvmx_smix_rd_dat_t smi_rd; cvmx_smix_wr_dat_t smi_wr; - int timeout = 1000; if (!octeon_has_feature(OCTEON_FEATURE_MDIO_CLAUSE_45)) return -1; @@ -447,12 +505,8 @@ static inline int cvmx_mdio_45_read(int bus_id, int phy_id, int device, int loca smi_cmd.s.reg_adr = device; cvmx_write_csr(CVMX_SMIX_CMD(bus_id), smi_cmd.u64); - do - { - cvmx_wait(1000); - smi_wr.u64 = cvmx_read_csr(CVMX_SMIX_WR_DAT(bus_id)); - } while (smi_wr.s.pending && --timeout); - if (timeout <= 0) + if (CVMX_WAIT_FOR_FIELD64(CVMX_SMIX_WR_DAT(bus_id), + cvmx_smix_wr_dat_t, pending, ==, 0, CVMX_MDIO_TIMEOUT)) { cvmx_dprintf ("cvmx_mdio_45_read: bus_id %d phy_id %2d device %2d register %2d TIME OUT(address)\n", bus_id, phy_id, device, location); return -1; @@ -464,13 +518,8 @@ static inline int cvmx_mdio_45_read(int bus_id, int phy_id, int device, int loca smi_cmd.s.reg_adr = device; cvmx_write_csr(CVMX_SMIX_CMD(bus_id), smi_cmd.u64); - do - { - cvmx_wait(1000); - smi_rd.u64 = cvmx_read_csr(CVMX_SMIX_RD_DAT(bus_id)); - } while (smi_rd.s.pending && timeout--); - - if(timeout <= 0) + smi_rd = __cvmx_mdio_read_rd_dat(bus_id); + if (smi_rd.s.pending) { cvmx_dprintf ("cvmx_mdio_45_read: bus_id %d phy_id %2d device %2d register %2d TIME OUT(data)\n", bus_id, phy_id, device, location); return -1; @@ -504,7 +553,6 @@ static inline int cvmx_mdio_45_write(int bus_id, int phy_id, int device, int loc { cvmx_smix_cmd_t smi_cmd; cvmx_smix_wr_dat_t smi_wr; - int timeout = 1000; if (!octeon_has_feature(OCTEON_FEATURE_MDIO_CLAUSE_45)) return -1; @@ -521,12 +569,8 @@ static inline int cvmx_mdio_45_write(int bus_id, int phy_id, int device, int loc smi_cmd.s.reg_adr = device; cvmx_write_csr(CVMX_SMIX_CMD(bus_id), smi_cmd.u64); - do - { - cvmx_wait(1000); - smi_wr.u64 = cvmx_read_csr(CVMX_SMIX_WR_DAT(bus_id)); - } while (smi_wr.s.pending && --timeout); - if (timeout <= 0) + if (CVMX_WAIT_FOR_FIELD64(CVMX_SMIX_WR_DAT(bus_id), + cvmx_smix_wr_dat_t, pending, ==, 0, CVMX_MDIO_TIMEOUT)) return -1; smi_wr.u64 = 0; @@ -539,17 +583,13 @@ static inline int cvmx_mdio_45_write(int bus_id, int phy_id, int device, int loc smi_cmd.s.reg_adr = device; cvmx_write_csr(CVMX_SMIX_CMD(bus_id), smi_cmd.u64); - do - { - cvmx_wait(1000); - smi_wr.u64 = cvmx_read_csr(CVMX_SMIX_WR_DAT(bus_id)); - } while (smi_wr.s.pending && --timeout); - if (timeout <= 0) + if (CVMX_WAIT_FOR_FIELD64(CVMX_SMIX_WR_DAT(bus_id), + cvmx_smix_wr_dat_t, pending, ==, 0, CVMX_MDIO_TIMEOUT)) return -1; return 0; } - +#endif #ifdef __cplusplus } |
