1/************************************************************************* 2Copyright (c) 2003-2007 Cavium Networks (support@cavium.com). All rights 3reserved. 4 5 6Redistribution and use in source and binary forms, with or without 7modification, are permitted provided that the following conditions are 8met: 9 10 * Redistributions of source code must retain the above copyright 11 notice, this list of conditions and the following disclaimer. 12 13 * Redistributions in binary form must reproduce the above 14 copyright notice, this list of conditions and the following 15 disclaimer in the documentation and/or other materials provided 16 with the distribution. 17 18 * Neither the name of Cavium Networks nor the names of 19 its contributors may be used to endorse or promote products 20 derived from this software without specific prior written 21 permission. 22 23This 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. 24 25TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED "AS IS" 26AND 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. 27 28*************************************************************************/ 29 30#include <sys/cdefs.h>
| 1/************************************************************************* 2Copyright (c) 2003-2007 Cavium Networks (support@cavium.com). All rights 3reserved. 4 5 6Redistribution and use in source and binary forms, with or without 7modification, are permitted provided that the following conditions are 8met: 9 10 * Redistributions of source code must retain the above copyright 11 notice, this list of conditions and the following disclaimer. 12 13 * Redistributions in binary form must reproduce the above 14 copyright notice, this list of conditions and the following 15 disclaimer in the documentation and/or other materials provided 16 with the distribution. 17 18 * Neither the name of Cavium Networks nor the names of 19 its contributors may be used to endorse or promote products 20 derived from this software without specific prior written 21 permission. 22 23This 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. 24 25TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED "AS IS" 26AND 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. 27 28*************************************************************************/ 29 30#include <sys/cdefs.h>
|
32 33#include <sys/param.h> 34#include <sys/systm.h> 35#include <sys/bus.h> 36#include <sys/endian.h> 37#include <sys/kernel.h> 38#include <sys/mbuf.h> 39#include <sys/socket.h> 40#include <sys/lock.h> 41#include <sys/mutex.h> 42 43#include <net/ethernet.h> 44#include <net/if.h> 45 46#include "wrapper-cvmx-includes.h" 47#include "ethernet-headers.h" 48 49struct mtx cvm_oct_mdio_mtx; 50MTX_SYSINIT(cvm_oct_mdio, &cvm_oct_mdio_mtx, "MDIO", MTX_DEF); 51 52/** 53 * Perform an MII read. Called by the generic MII routines 54 * 55 * @param dev Device to perform read for 56 * @param phy_id The MII phy id 57 * @param location Register location to read 58 * @return Result from the read or zero on failure 59 */ 60int cvm_oct_mdio_read(struct ifnet *ifp, int phy_id, int location) 61{ 62 cvmx_smi_cmd_t smi_cmd; 63 cvmx_smi_rd_dat_t smi_rd; 64 65 MDIO_LOCK(); 66 smi_cmd.u64 = 0; 67 smi_cmd.s.phy_op = 1; 68 smi_cmd.s.phy_adr = phy_id; 69 smi_cmd.s.reg_adr = location; 70 cvmx_write_csr(CVMX_SMI_CMD, smi_cmd.u64); 71 72 do { 73#if 0 74 if (!in_interrupt()) 75 yield(); 76#endif 77 smi_rd.u64 = cvmx_read_csr(CVMX_SMI_RD_DAT); 78 } while (smi_rd.s.pending); 79 80 MDIO_UNLOCK(); 81 82 if (smi_rd.s.val) 83 return smi_rd.s.dat; 84 else 85 return 0; 86} 87 88 89/** 90 * Perform an MII write. Called by the generic MII routines 91 * 92 * @param dev Device to perform write for 93 * @param phy_id The MII phy id 94 * @param location Register location to write 95 * @param val Value to write 96 */ 97void cvm_oct_mdio_write(struct ifnet *ifp, int phy_id, int location, int val) 98{ 99 cvmx_smi_cmd_t smi_cmd; 100 cvmx_smi_wr_dat_t smi_wr; 101 102 MDIO_LOCK(); 103 smi_wr.u64 = 0; 104 smi_wr.s.dat = val; 105 cvmx_write_csr(CVMX_SMI_WR_DAT, smi_wr.u64); 106 107 smi_cmd.u64 = 0; 108 smi_cmd.s.phy_op = 0; 109 smi_cmd.s.phy_adr = phy_id; 110 smi_cmd.s.reg_adr = location; 111 cvmx_write_csr(CVMX_SMI_CMD, smi_cmd.u64); 112 113 do { 114#if 0 115 if (!in_interrupt()) 116 yield(); 117#endif 118 smi_wr.u64 = cvmx_read_csr(CVMX_SMI_WR_DAT); 119 } while (smi_wr.s.pending); 120 MDIO_UNLOCK(); 121} 122 123/** 124 * Setup the MDIO device structures 125 * 126 * @param dev Device to setup 127 * 128 * @return Zero on success, negative on failure 129 */ 130int cvm_oct_mdio_setup_device(struct ifnet *ifp) 131{ 132 cvm_oct_private_t *priv = (cvm_oct_private_t *)ifp->if_softc; 133 134 priv->phy_id = cvmx_helper_board_get_mii_address(priv->port);
| 32 33#include <sys/param.h> 34#include <sys/systm.h> 35#include <sys/bus.h> 36#include <sys/endian.h> 37#include <sys/kernel.h> 38#include <sys/mbuf.h> 39#include <sys/socket.h> 40#include <sys/lock.h> 41#include <sys/mutex.h> 42 43#include <net/ethernet.h> 44#include <net/if.h> 45 46#include "wrapper-cvmx-includes.h" 47#include "ethernet-headers.h" 48 49struct mtx cvm_oct_mdio_mtx; 50MTX_SYSINIT(cvm_oct_mdio, &cvm_oct_mdio_mtx, "MDIO", MTX_DEF); 51 52/** 53 * Perform an MII read. Called by the generic MII routines 54 * 55 * @param dev Device to perform read for 56 * @param phy_id The MII phy id 57 * @param location Register location to read 58 * @return Result from the read or zero on failure 59 */ 60int cvm_oct_mdio_read(struct ifnet *ifp, int phy_id, int location) 61{ 62 cvmx_smi_cmd_t smi_cmd; 63 cvmx_smi_rd_dat_t smi_rd; 64 65 MDIO_LOCK(); 66 smi_cmd.u64 = 0; 67 smi_cmd.s.phy_op = 1; 68 smi_cmd.s.phy_adr = phy_id; 69 smi_cmd.s.reg_adr = location; 70 cvmx_write_csr(CVMX_SMI_CMD, smi_cmd.u64); 71 72 do { 73#if 0 74 if (!in_interrupt()) 75 yield(); 76#endif 77 smi_rd.u64 = cvmx_read_csr(CVMX_SMI_RD_DAT); 78 } while (smi_rd.s.pending); 79 80 MDIO_UNLOCK(); 81 82 if (smi_rd.s.val) 83 return smi_rd.s.dat; 84 else 85 return 0; 86} 87 88 89/** 90 * Perform an MII write. Called by the generic MII routines 91 * 92 * @param dev Device to perform write for 93 * @param phy_id The MII phy id 94 * @param location Register location to write 95 * @param val Value to write 96 */ 97void cvm_oct_mdio_write(struct ifnet *ifp, int phy_id, int location, int val) 98{ 99 cvmx_smi_cmd_t smi_cmd; 100 cvmx_smi_wr_dat_t smi_wr; 101 102 MDIO_LOCK(); 103 smi_wr.u64 = 0; 104 smi_wr.s.dat = val; 105 cvmx_write_csr(CVMX_SMI_WR_DAT, smi_wr.u64); 106 107 smi_cmd.u64 = 0; 108 smi_cmd.s.phy_op = 0; 109 smi_cmd.s.phy_adr = phy_id; 110 smi_cmd.s.reg_adr = location; 111 cvmx_write_csr(CVMX_SMI_CMD, smi_cmd.u64); 112 113 do { 114#if 0 115 if (!in_interrupt()) 116 yield(); 117#endif 118 smi_wr.u64 = cvmx_read_csr(CVMX_SMI_WR_DAT); 119 } while (smi_wr.s.pending); 120 MDIO_UNLOCK(); 121} 122 123/** 124 * Setup the MDIO device structures 125 * 126 * @param dev Device to setup 127 * 128 * @return Zero on success, negative on failure 129 */ 130int cvm_oct_mdio_setup_device(struct ifnet *ifp) 131{ 132 cvm_oct_private_t *priv = (cvm_oct_private_t *)ifp->if_softc; 133 134 priv->phy_id = cvmx_helper_board_get_mii_address(priv->port);
|