1/*
2 * Copyright 2014-2017 Cavium, Inc.
3 * The contents of this file are subject to the terms of the Common Development
4 * and Distribution License, v.1,  (the "License").
5 *
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the License at available
9 * at http://opensource.org/licenses/CDDL-1.0
10 *
11 * See the License for the specific language governing permissions and
12 * limitations under the License.
13 */
14
15#ifndef _netlink_h_
16#define _netlink_h_
17
18#include "bcmtype.h"
19
20/* The values are defined to adapt the previous IMD firmware definitions */
21#define NETLINK_STATUS_SUCCESS                     0
22#define NETLINK_STATUS_DENY_PHY_ACCESS_FAILURE     0x10005
23#define NETLINK_STATUS_PHY_FAILURE                 0x1000a
24#define NETLINK_STATUS_WRONG_MEDIA_FAILURE         0x20006
25#define NETLINK_STATUS_BAD_LINK_SETTING_FAILURE    0x20007
26#define NETLINK_STATUS_PWR_MGMT_CONFLICT_FAILURE   0x20008
27#define NETLINK_STATUS_INVALID_INPUT_FAILURE       0x20002
28#define NETLINK_STATUS_NOT_SUPPORTED_FAILURE       0x2000b
29#define NETLINK_STATUS_BAD_SPEED_FAILURE           0x80000001
30#define NETLINK_STATUS_LINK_ALREADY_UP_FAILURE     0x80000002
31
32
33
34
35/* Link status codes: definition based on what's in shmem.h */
36#define NETLINK_GET_LINK_STATUS_INIT_VALUE                 0xffffffff
37#define NETLINK_GET_LINK_STATUS_LINK_UP                    0x1
38#define NETLINK_GET_LINK_STATUS_LINK_DOWN                  0x0
39#define NETLINK_GET_LINK_STATUS_SPEED_MASK                 0x1e
40#define NETLINK_GET_LINK_STATUS_AN_INCOMPLETE              (0<<1)
41
42#define NETLINK_GET_LINK_STATUS_10HALF                     (1<<1)
43#define NETLINK_GET_LINK_STATUS_10FULL                     (2<<1)
44#define NETLINK_GET_LINK_STATUS_100HALF                    (3<<1)
45#define NETLINK_GET_LINK_STATUS_100BASE_T4                 (4<<1)
46#define NETLINK_GET_LINK_STATUS_100FULL                    (5<<1)
47#define NETLINK_GET_LINK_STATUS_1000HALF                   (6<<1)
48#define NETLINK_GET_LINK_STATUS_1000FULL                   (7<<1)
49#define NETLINK_GET_LINK_STATUS_2500HALF                   (8<<1)
50
51#define NETLINK_GET_LINK_STATUS_2500FULL                   (9<<1)
52
53#define NETLINK_GET_LINK_STATUS_AN_ENABLED                 0x000020L
54#define NETLINK_GET_LINK_STATUS_AN_COMPLETE                0x000040L
55#define NETLINK_GET_LINK_STATUS_PARALLEL_DET               0x000080L
56#define NETLINK_GET_LINK_STATUS_RESERVED                   0x000100L
57#define NETLINK_GET_LINK_STATUS_PARTNER_AD_1000FULL        0x000200L
58#define NETLINK_GET_LINK_STATUS_PARTNER_AD_1000HALF        0x000400L
59#define NETLINK_GET_LINK_STATUS_PARTNER_AD_100BT4          0x000800L
60#define NETLINK_GET_LINK_STATUS_PARTNER_AD_100FULL         0x001000L
61#define NETLINK_GET_LINK_STATUS_PARTNER_AD_100HALF         0x002000L
62#define NETLINK_GET_LINK_STATUS_PARTNER_AD_10FULL          0x004000L
63#define NETLINK_GET_LINK_STATUS_PARTNER_AD_10HALF          0x008000L
64#define NETLINK_GET_LINK_STATUS_TX_FC_ENABLED              0x010000L
65#define NETLINK_GET_LINK_STATUS_RX_FC_ENABLED              0x020000L
66#define NETLINK_GET_LINK_STATUS_PARTNER_SYM_PAUSE_CAP      0x040000L
67#define NETLINK_GET_LINK_STATUS_PARTNER_ASYM_PAUSE_CAP     0x080000L
68#define NETLINK_GET_LINK_STATUS_SERDES_LINK                0x100000L
69#define NETLINK_GET_LINK_STATUS_PARTNER_AD_2500FULL        0x200000L
70#define NETLINK_GET_LINK_STATUS_PARTNER_AD_2500HALF        0x400000L
71
72#define NETLINK_GET_LINK_STATUS_NO_MEDIA_DETECTED          0x20000000L
73#define NETLINK_GET_LINK_STATUS_CABLESENSE                 0x40000000L
74#define NETLINK_GET_LINK_STATUS_SW_TIMER_EVENT             0x80000000L
75
76
77/* netlink_get_link_status():
78 * Input: A pointer to a u32_t type storage
79 * Output: bit-wise OR'd of any NETLINK_GET_LINK_STATUS_* constants
80 * Return: 0 for success, non-zero for failure (see NETLINK_CODE_* constants).
81 */
82typedef u32_t (* netlink_get_link_status_t)(u32_t *get_link_attrib);
83
84u32_t netlink_get_link_status ( u32_t *get_link_attrib );
85
86
87
88/* netlink_drv_set_link()
89 * Input: A u32_t value indicating the desired link
90 * Output: None, in fact, the link may not be effective right away
91 *         (subject to the time needed to establish the link).
92 * Return: 0 for success, non-zero for failure (see NETLINK_CODE_* constants).
93 */
94u32_t netlink_drv_set_link( u32_t drv_link_attrib );
95
96#define NETLINK_DRV_SET_LINK_SPEED_10HALF        (1<<0)
97#define NETLINK_DRV_SET_LINK_SPEED_10FULL        (1<<1)
98#define NETLINK_DRV_SET_LINK_SPEED_100HALF       (1<<2)
99#define NETLINK_DRV_SET_LINK_SPEED_100FULL       (1<<3)
100
101#define NETLINK_DRV_SET_LINK_SPEED_1GHALF        (1<<4)
102#define NETLINK_DRV_SET_LINK_SPEED_1GFULL        (1<<5)
103
104#define NETLINK_DRV_SET_LINK_SPEED_2G5HALF       (1<<6)
105#define NETLINK_DRV_SET_LINK_SPEED_2G5FULL       (1<<7)
106
107#define NETLINK_DRV_SET_LINK_SPEED_10GHALF       (1<<8) // place holder for now.
108#define NETLINK_DRV_SET_LINK_SPEED_10GFULL       (1<<9) // place holder for now.
109#define NETLINK_DRV_SET_LINK_ENABLE_AUTONEG      (1<<10)
110                        /* (vs Forced): If autoeng enabled, the speed
111                         * bits above dictate what capability advertisement.
112                         * Otherwise, only one of the applicable speed/duplex
113                         * bits above can be set, and it will be used to
114                         * establish the forced link.
115                         */
116#define NETLINK_DRV_SET_LINK_PHY_APP_MASK        (1<<11)
117#define NETLINK_DRV_SET_LINK_PHY_APP_REMOTE      (1<<11)
118#define NETLINK_DRV_SET_LINK_PHY_APP_LOCAL       (0<<11)
119
120                        /* (Local vs Remote): The setting will be stored as
121                         * driver preference. If the media type matches the
122                         * current setup, the setting will also be applied
123                         * immediately.
124                         */
125
126#define NETLINK_DRV_SET_LINK_FC_SYM_PAUSE        (1<<12)
127#define NETLINK_DRV_SET_LINK_FC_ASYM_PAUSE       (1<<13)
128
129#define NETLINK_DRV_SET_LINK_ETH_AT_WIRESPEED_ENABLE (1<<14)
130#define NETLINK_DRV_SET_LINK_PHY_RESET           (1<<15)
131                        /* Local serdes will be reset. If remote Cu PHY
132                         * is present, MDIO write will be issued to the
133                         * remote PHY to reset it. Then, whatever other
134                         * settings will be applied.
135                         */
136
137
138/* This override bit tells the set_link() routine to set the link
139 * again even if the link is already up at a desired speed */
140#define NETLINK_SET_LINK_OVERRIDE              0x80000000
141
142/* Setting this will advertise all capability that the power budget (e.g.
143 * overdraw Vaux current in absence of main power) and design capability
144 * (e.g. 2.5G) allow.
145 * In case of the 5708 Serdes, fall back is assumed. */
146#define NETLINK_SET_LINK_SPEED_AUTONEG         0x00
147
148/* These speed values are used for forced speed unless selective autoneg
149 * is selected. Do NOT try to bit-wise OR them. In the case of selective
150 * autoneg, that speed will be advertised. */
151#define NETLINK_SET_LINK_SPEED_UNKNOWN         0x00
152#define NETLINK_SET_LINK_SPEED_10MBPS          0x01
153#define NETLINK_SET_LINK_SPEED_100MBPS         0x02
154#define NETLINK_SET_LINK_SPEED_1000MBPS        0x04
155#define NETLINK_SET_LINK_SPEED_2500MBPS        0x08
156#define NETLINK_SET_LINK_SPEED_MASK            0xff
157
158#define NETLINK_SET_LINK_DUPLEX_HALF           0x0100
159#define NETLINK_SET_LINK_DUPLEX_FULL           0x0000
160
161#define NETLINK_SET_LINK_PAUSE_CAP             0x0200
162#define NETLINK_SET_LINK_ASYM_PAUSE            0x0400
163
164/* When selective autoneg is enabled, only one speed will be used for
165 * capability advertisement. */
166#define NETLINK_SET_LINK_SELECTIVE_AUTONEG     0x10000
167
168/* netlink_set_link():
169 * Input: bit-wise OR'd of any NETLINK_SET_LINK_* constants (except the speed)
170 * Output: None.
171 * Return: 0 for success, non-zero for failure (see NETLINK_CODE_* constants).
172 *
173 * Example 1: To set 100Full forced speed, the parameter would look like
174 *                NETLINK_SET_LINK_SPEED_100MBPS |
175 *                NETLINK_SET_LINK_DUPLEX_FULL.
176 * Example 2: To set selective autoneg at 100Full with pause capability,
177 *            the parameter would look like
178 *                NETLINK_SET_LINK_SPEED_100MBPS |
179 *                NETLINK_SET_LINK_PAUSE_CAP |
180 *                NETLINK_SET_LINK_SELECTIVE_AUTONEG |
181 *                NETLINK_SET_LINK_DUPLEX_FULL.
182 *
183 * Note 1: If caller passes any speed settings, and if the system is
184 *         in OSPresent mode, no action will be taken, the actual speed
185 *         advertisement will be done by OS Driver.
186 * Note 2: If caller passes "NETLINK_SET_LINK_SPEED_AUTONEG" parameter,
187 *         if the system is in OSAbsent mode and if the system has
188 *         Vmain power the link speed 2500/1000/100/10 will be advertised.
189 * Note 3: If caller passes "NETLINK_SET_LINK_SPEED_AUTONEG" parameter,
190 *         if the system is in OSAbsent mode and if the system does
191 *         not have Vmain power (Vaux power mode) and the "
192 *         PowerOverDrawn" bit is set (OK to consume more power in
193 *         order to acquire highest link speed), the link speed
194 *         2500/1000/100/10 will be advertised.
195 * Note 4: If caller passes "NETLINK_SET_LINK_SPEED_AUTONEG" parameter,
196 *         if the system is in OSAbsent mode, and if the system does
197 *         not have Vmain power (Vaux power mode) and the
198 *         "PowerOverDrawn" bit is cleared (don't consume more power
199 *         than necessary), the link speed 100/10 will be advertised.
200 *
201 */
202typedef u32_t (* netlink_set_link_t)(u32_t set_link_attrib);
203
204u32_t netlink_set_link ( u32_t set_link_attrib );
205
206
207void netlink_serdes_fallback ( void );
208
209#endif /* _netlink_h_ */
210