1 /*************************************************************************
2 SPDX-License-Identifier: BSD-3-Clause
4 Copyright (c) 2003-2007 Cavium Networks (support@cavium.com). All rights
8 Redistribution and use in source and binary forms, with or without
9 modification, are permitted provided that the following conditions are
12 * Redistributions of source code must retain the above copyright
13 notice, this list of conditions and the following disclaimer.
15 * Redistributions in binary form must reproduce the above
16 copyright notice, this list of conditions and the following
17 disclaimer in the documentation and/or other materials provided
18 with the distribution.
20 * Neither the name of Cavium Networks nor the names of
21 its contributors may be used to endorse or promote products
22 derived from this software without specific prior written
25 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.
27 TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED "AS IS"
28 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.
30 *************************************************************************/
32 #include <sys/cdefs.h>
33 __FBSDID("$FreeBSD$");
35 #include <sys/param.h>
36 #include <sys/systm.h>
38 #include <sys/endian.h>
39 #include <sys/kernel.h>
41 #include <sys/socket.h>
43 #include <sys/mutex.h>
45 #include <net/ethernet.h>
47 #include <net/if_var.h>
49 #include "wrapper-cvmx-includes.h"
50 #include "ethernet-headers.h"
52 struct mtx cvm_oct_mdio_mtx;
53 MTX_SYSINIT(cvm_oct_mdio, &cvm_oct_mdio_mtx, "MDIO", MTX_DEF);
56 * Perform an MII read. Called by the generic MII routines
58 * @param dev Device to perform read for
59 * @param phy_id The MII phy id
60 * @param location Register location to read
61 * @return Result from the read or zero on failure
63 int cvm_oct_mdio_read(struct ifnet *ifp, int phy_id, int location)
65 cvmx_smi_cmd_t smi_cmd;
66 cvmx_smi_rd_dat_t smi_rd;
71 smi_cmd.s.phy_adr = phy_id;
72 smi_cmd.s.reg_adr = location;
73 cvmx_write_csr(CVMX_SMI_CMD, smi_cmd.u64);
77 smi_rd.u64 = cvmx_read_csr(CVMX_SMI_RD_DAT);
78 } while (smi_rd.s.pending);
90 * Perform an MII write. Called by the generic MII routines
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
97 void cvm_oct_mdio_write(struct ifnet *ifp, int phy_id, int location, int val)
99 cvmx_smi_cmd_t smi_cmd;
100 cvmx_smi_wr_dat_t smi_wr;
105 cvmx_write_csr(CVMX_SMI_WR_DAT, smi_wr.u64);
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);
115 smi_wr.u64 = cvmx_read_csr(CVMX_SMI_WR_DAT);
116 } while (smi_wr.s.pending);
121 * Setup the MDIO device structures
123 * @param dev Device to setup
125 * @return Zero on success, negative on failure
127 int cvm_oct_mdio_setup_device(struct ifnet *ifp)
129 cvm_oct_private_t *priv = (cvm_oct_private_t *)ifp->if_softc;
131 priv->phy_id = cvmx_helper_board_get_mii_address(priv->port);
132 priv->phy_device = NULL;
133 priv->mdio_read = NULL;
134 priv->mdio_write = NULL;