The Design and Implementation of the FreeBSD Operating System, Second Edition
Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition)


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/mips/cavium/octe/ethernet-mdio.c

Version: -  FREEBSD  -  FREEBSD-13-STABLE  -  FREEBSD-13-0  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  l41  -  OPENBSD  -  linux-2.6  -  MK84  -  PLAN9  -  xnu-8792 
SearchContext: -  none  -  3  -  10 

    1 /*************************************************************************
    2 SPDX-License-Identifier: BSD-3-Clause
    3 
    4 Copyright (c) 2003-2007  Cavium Networks (support@cavium.com). All rights
    5 reserved.
    6 
    7 
    8 Redistribution and use in source and binary forms, with or without
    9 modification, are permitted provided that the following conditions are
   10 met:
   11 
   12     * Redistributions of source code must retain the above copyright
   13       notice, this list of conditions and the following disclaimer.
   14 
   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.
   19 
   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
   23       permission.
   24 
   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.
   26 
   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.
   29 
   30 *************************************************************************/
   31 
   32 #include <sys/cdefs.h>
   33 __FBSDID("$FreeBSD$");
   34 
   35 #include <sys/param.h>
   36 #include <sys/systm.h>
   37 #include <sys/bus.h>
   38 #include <sys/endian.h>
   39 #include <sys/kernel.h>
   40 #include <sys/mbuf.h>
   41 #include <sys/socket.h>
   42 #include <sys/lock.h>
   43 #include <sys/mutex.h>
   44 
   45 #include <net/ethernet.h>
   46 #include <net/if.h>
   47 #include <net/if_var.h>
   48 
   49 #include "wrapper-cvmx-includes.h"
   50 #include "ethernet-headers.h"
   51 
   52 struct mtx cvm_oct_mdio_mtx;
   53 MTX_SYSINIT(cvm_oct_mdio, &cvm_oct_mdio_mtx, "MDIO", MTX_DEF);
   54 
   55 /**
   56  * Perform an MII read. Called by the generic MII routines
   57  *
   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
   62  */
   63 int cvm_oct_mdio_read(struct ifnet *ifp, int phy_id, int location)
   64 {
   65         cvmx_smi_cmd_t          smi_cmd;
   66         cvmx_smi_rd_dat_t       smi_rd;
   67 
   68         MDIO_LOCK();
   69         smi_cmd.u64 = 0;
   70         smi_cmd.s.phy_op = 1;
   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);
   74 
   75         do {
   76                 cvmx_wait(1000);
   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  */
   97 void 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                 cvmx_wait(1000);
  115                 smi_wr.u64 = cvmx_read_csr(CVMX_SMI_WR_DAT);
  116         } while (smi_wr.s.pending);
  117         MDIO_UNLOCK();
  118 }
  119 
  120 /**
  121  * Setup the MDIO device structures
  122  *
  123  * @param dev    Device to setup
  124  *
  125  * @return Zero on success, negative on failure
  126  */
  127 int cvm_oct_mdio_setup_device(struct ifnet *ifp)
  128 {
  129         cvm_oct_private_t *priv = (cvm_oct_private_t *)ifp->if_softc;
  130 
  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;
  135 
  136         return 0;
  137 }
  138 

Cache object: 5033f4fa4f10859b7269b03f2a4c796b


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.