1210284Sjmallett/***********************license start***************
2232812Sjmallett * Copyright (c) 2003-2010  Cavium Inc. (support@cavium.com). All rights
3215990Sjmallett * reserved.
4210284Sjmallett *
5210284Sjmallett *
6215990Sjmallett * Redistribution and use in source and binary forms, with or without
7215990Sjmallett * modification, are permitted provided that the following conditions are
8215990Sjmallett * met:
9210284Sjmallett *
10215990Sjmallett *   * Redistributions of source code must retain the above copyright
11215990Sjmallett *     notice, this list of conditions and the following disclaimer.
12210284Sjmallett *
13215990Sjmallett *   * Redistributions in binary form must reproduce the above
14215990Sjmallett *     copyright notice, this list of conditions and the following
15215990Sjmallett *     disclaimer in the documentation and/or other materials provided
16215990Sjmallett *     with the distribution.
17215990Sjmallett
18232812Sjmallett *   * Neither the name of Cavium Inc. nor the names of
19215990Sjmallett *     its contributors may be used to endorse or promote products
20215990Sjmallett *     derived from this software without specific prior written
21215990Sjmallett *     permission.
22215990Sjmallett
23215990Sjmallett * This Software, including technical data, may be subject to U.S. export  control
24215990Sjmallett * laws, including the U.S. Export Administration Act and its  associated
25215990Sjmallett * regulations, and may be subject to export or import  regulations in other
26215990Sjmallett * countries.
27215990Sjmallett
28215990Sjmallett * TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED "AS IS"
29232812Sjmallett * AND WITH ALL FAULTS AND CAVIUM INC. MAKES NO PROMISES, REPRESENTATIONS OR
30215990Sjmallett * WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY, OR OTHERWISE, WITH RESPECT TO
31215990Sjmallett * THE SOFTWARE, INCLUDING ITS CONDITION, ITS CONFORMITY TO ANY REPRESENTATION OR
32215990Sjmallett * DESCRIPTION, OR THE EXISTENCE OF ANY LATENT OR PATENT DEFECTS, AND CAVIUM
33215990Sjmallett * SPECIFICALLY DISCLAIMS ALL IMPLIED (IF ANY) WARRANTIES OF TITLE,
34215990Sjmallett * MERCHANTABILITY, NONINFRINGEMENT, FITNESS FOR A PARTICULAR PURPOSE, LACK OF
35215990Sjmallett * VIRUSES, ACCURACY OR COMPLETENESS, QUIET ENJOYMENT, QUIET POSSESSION OR
36215990Sjmallett * CORRESPONDENCE TO DESCRIPTION. THE ENTIRE  RISK ARISING OUT OF USE OR
37215990Sjmallett * PERFORMANCE OF THE SOFTWARE LIES WITH YOU.
38210284Sjmallett ***********************license end**************************************/
39210284Sjmallett
40210284Sjmallett
41210284Sjmallett
42210284Sjmallett
43210284Sjmallett
44210284Sjmallett
45215990Sjmallett
46210284Sjmallett/**
47210284Sjmallett * @file
48210284Sjmallett *
49210284Sjmallett * Functions for LOOP initialization, configuration,
50210284Sjmallett * and monitoring.
51210284Sjmallett *
52232812Sjmallett * <hr>$Revision: 70030 $<hr>
53210284Sjmallett */
54215990Sjmallett#ifdef CVMX_BUILD_FOR_LINUX_KERNEL
55215990Sjmallett#include <asm/octeon/cvmx.h>
56215990Sjmallett#include <asm/octeon/cvmx-config.h>
57215990Sjmallett#ifdef CVMX_ENABLE_PKO_FUNCTIONS
58215990Sjmallett#include <asm/octeon/cvmx-helper.h>
59215990Sjmallett#endif
60215990Sjmallett#include <asm/octeon/cvmx-pip-defs.h>
61215990Sjmallett#else
62215990Sjmallett#if !defined(__FreeBSD__) || !defined(_KERNEL)
63215990Sjmallett#include "executive-config.h"
64215990Sjmallett#include "cvmx-config.h"
65215990Sjmallett#ifdef CVMX_ENABLE_PKO_FUNCTIONS
66215990Sjmallett
67210284Sjmallett#include "cvmx.h"
68210284Sjmallett#include "cvmx-helper.h"
69215990Sjmallett#endif
70215990Sjmallett#else
71215990Sjmallett#include "cvmx.h"
72215990Sjmallett#include "cvmx-helper.h"
73215990Sjmallett#endif
74215990Sjmallett#endif
75215990Sjmallett#ifdef CVMX_ENABLE_PKO_FUNCTIONS
76210284Sjmallett
77232812Sjmallett
78232812Sjmallettint __cvmx_helper_loop_enumerate(int interface)
79232812Sjmallett{
80232812Sjmallett	return (OCTEON_IS_MODEL(OCTEON_CN68XX) ? 8 : 4);
81232812Sjmallett}
82232812Sjmallett
83210284Sjmallett/**
84210284Sjmallett * @INTERNAL
85210284Sjmallett * Probe a LOOP interface and determine the number of ports
86210284Sjmallett * connected to it. The LOOP interface should still be down
87210284Sjmallett * after this call.
88210284Sjmallett *
89210284Sjmallett * @param interface Interface to probe
90210284Sjmallett *
91210284Sjmallett * @return Number of ports on the interface. Zero to disable.
92210284Sjmallett */
93210284Sjmallettint __cvmx_helper_loop_probe(int interface)
94210284Sjmallett{
95232812Sjmallett	return __cvmx_helper_loop_enumerate(interface);
96210284Sjmallett}
97210284Sjmallett
98210284Sjmallett
99210284Sjmallett/**
100210284Sjmallett * @INTERNAL
101210284Sjmallett * Bringup and enable a LOOP interface. After this call packet
102210284Sjmallett * I/O should be fully functional. This is called with IPD
103210284Sjmallett * enabled but PKO disabled.
104210284Sjmallett *
105210284Sjmallett * @param interface Interface to bring up
106210284Sjmallett *
107210284Sjmallett * @return Zero on success, negative on failure
108210284Sjmallett */
109210284Sjmallettint __cvmx_helper_loop_enable(int interface)
110210284Sjmallett{
111232812Sjmallett    cvmx_pip_prt_cfgx_t port_cfg;
112232812Sjmallett    int num_ports, index;
113232812Sjmallett    unsigned long offset;
114232812Sjmallett
115232812Sjmallett    num_ports = __cvmx_helper_get_num_ipd_ports(interface);
116232812Sjmallett
117232812Sjmallett    /*
118232812Sjmallett     * We need to disable length checking so packet < 64 bytes and jumbo
119232812Sjmallett     * frames don't get errors
120232812Sjmallett     */
121232812Sjmallett    for (index = 0; index < num_ports; index++) {
122232812Sjmallett        offset = ((octeon_has_feature(OCTEON_FEATURE_PKND)) ?
123232812Sjmallett	    cvmx_helper_get_pknd(interface, index) :
124232812Sjmallett            cvmx_helper_get_ipd_port(interface, index));
125232812Sjmallett
126232812Sjmallett        port_cfg.u64 = cvmx_read_csr(CVMX_PIP_PRT_CFGX(offset));
127232812Sjmallett        port_cfg.s.maxerr_en = 0;
128232812Sjmallett        port_cfg.s.minerr_en = 0;
129232812Sjmallett        cvmx_write_csr(CVMX_PIP_PRT_CFGX(offset), port_cfg.u64);
130232812Sjmallett    }
131232812Sjmallett
132232812Sjmallett    /*
133232812Sjmallett     * Disable FCS stripping for loopback ports
134232812Sjmallett     */
135232812Sjmallett    if (!octeon_has_feature(OCTEON_FEATURE_PKND)) {
136232812Sjmallett        cvmx_ipd_sub_port_fcs_t ipd_sub_port_fcs;
137232812Sjmallett        ipd_sub_port_fcs.u64 = cvmx_read_csr(CVMX_IPD_SUB_PORT_FCS);
138232812Sjmallett        ipd_sub_port_fcs.s.port_bit2 = 0;
139232812Sjmallett        cvmx_write_csr(CVMX_IPD_SUB_PORT_FCS, ipd_sub_port_fcs.u64);
140232812Sjmallett    }
141232812Sjmallett
142210284Sjmallett    return 0;
143210284Sjmallett}
144210284Sjmallett
145210284Sjmallett#endif /* CVMX_ENABLE_PKO_FUNCTIONS */
146210284Sjmallett
147