blob: f1433a39a986ad464ae31ca3365afb7b454c62df [file] [log] [blame]
Shad Ansari2f7f9be2017-06-07 13:34:53 -07001/******************************************************************************
2 *
3 * <:copyright-BRCM:2016:DUAL/GPL:standard
4 *
5 * Copyright (c) 2016 Broadcom
6 * All Rights Reserved
7 *
8 * Unless you and Broadcom execute a separate written software license
9 * agreement governing use of this software, this software is licensed
10 * to you under the terms of the GNU General Public License version 2
11 * (the "GPL"), available at http://www.broadcom.com/licenses/GPLv2.php,
12 * with the following added to such license:
13 *
14 * As a special exception, the copyright holders of this software give
15 * you permission to link this software with independent modules, and
16 * to copy and distribute the resulting executable under terms of your
17 * choice, provided that you also meet, for each linked independent
18 * module, the terms and conditions of the license of that module.
19 * An independent module is a module which is not derived from this
20 * software. The special exception does not apply to any modifications
21 * of the software.
22 *
23 * Not withstanding the above, under no circumstances may you combine
24 * this software in any way with any other Broadcom software provided
25 * under a license other than the GPL, without Broadcom's express prior
26 * written consent.
27 *
28 * :>
29 *
30 *****************************************************************************/
31
32#ifndef TEST_SW_UTIL_LOOPBACK
33
34#include <bal_common.h>
35#include <bal_core.h>
36#include <bcm_dev_log.h>
37#include <bal_msg.h>
38#include "bal_switch_acc_term.h"
39#include "bal_switch_util.h"
40#include "bal_dpp_interface.h"
41
42#include <bcm/types.h>
43#include <bcm/port.h>
44
45/**
46 * @file bal_dpp_interface.c
47 * @brief BAL Switch util functions that handle interface requests on DUNE PACKET PROCESSOR
48 * @addtogroup sw_util
49 *
50 */
51
52/*@{*/
53
54
55/**
56 * @brief Set up pon interface with DPP
57 *
58 * This routine is called by sw_util_interface_set in the BAL core
59 * to execute DPP specific API for pon interface request
60 *
61 * @param p_interface_inst Pointer to interface instance
62 * @param opt_type UP/DOWN/RESTART the interface
63 * @return bcmos_errno
64 */
65bcmos_errno bal_sw_util_dpp_interface_set(acc_term_interface *p_interface_inst, bal_util_oper_if opt_type )
66{
67 bcmos_errno ret = BCM_ERR_OK;
68 int rc = 0;
69 bcmbal_interface_key intf_key = p_interface_inst->api_req_int_obj_info.key;
70 int unit, port;
71
72 BCM_LOG(INFO, log_id_sw_util, " DPP - Got a interface SET: intf_type: %s, intf_id: %d, opt_type: %s\n",
73 (intf_key.intf_type == BCMBAL_INTF_TYPE_PON ? "PON":"NNI"),
74 intf_key.intf_id,
75 (opt_type == BAL_UTIL_OPER_IF_DOWN ? "DOWN":"UP"));
76
77 /* based on interface type get the device number and physical port number from associated table */
78 switch(intf_key.intf_type)
79 {
80 case BCMBAL_INTF_TYPE_PON:
81 unit = bal_bcm_pon_inf_dev_get(intf_key.intf_id);
82 port = bal_bcm_pon_inf_pbm_get(intf_key.intf_id);
83 break;
84 case BCMBAL_INTF_TYPE_NNI:
85 unit = bal_bcm_net_inf_dev_get(intf_key.intf_id);
86 port = bal_bcm_net_inf_pbm_get(intf_key.intf_id);
87 break;
88 default:
89 BCM_LOG(ERROR, log_id_sw_util, "Error, Unrecognized interface type %d\n", intf_key.intf_type);
90 return BCM_ERR_INTERNAL;
91 break;
92 }
93
94 switch (opt_type)
95 {
96 case BAL_UTIL_OPER_IF_DOWN:
97 rc = bcm_port_enable_set(unit, port, 0);
98 break;
99 case BAL_UTIL_OPER_IF_UP:
100 default:
101 /* disable */
102 rc = bcm_port_enable_set(unit, port, 0);
103 /* sleep 300 ms */
104 usleep(300000);
105 /* enable */
106 rc = bcm_port_enable_set(unit, port, 1);
107 /* Enable auto-negotiation if necessary */
108 if (intf_key.intf_type == BCMBAL_INTF_TYPE_NNI &&
109 bcmbal_is_nni_autoneg_on(intf_key.intf_id))
110 {
111 /* sleep 400 ms */
112 usleep(400000);
113 rc = rc ? rc : bcm_port_autoneg_set(unit, port, 1);
114 BCM_LOG(INFO, log_id_sw_util, "Enabled autoneg on NNI unit:port %d:%d. rc=%d\n", unit, port, rc);
115 }
116 break;
117 }
118 if (rc)
119 {
120 BCM_LOG(ERROR, log_id_sw_util, "Error, bcm_port_enable_set for pon failed %d\n", rc);
121 ret = BCM_ERR_INTERNAL;
122 }
123 return ret;
124}
125
126/*@}*/
127#endif /* #ifndef TEST_SW_UTIL_LOOPBACK */