New upstream version 18.02
[deb_dpdk.git] / drivers / net / ixgbe / base / ixgbe_hv_vf.c
1 /*******************************************************************************
2
3 Copyright (c) 2001-2015, Intel Corporation
4 All rights reserved.
5
6 Redistribution and use in source and binary forms, with or without
7 modification, are permitted provided that the following conditions are met:
8
9  1. Redistributions of source code must retain the above copyright notice,
10     this list of conditions and the following disclaimer.
11
12  2. Redistributions in binary form must reproduce the above copyright
13     notice, this list of conditions and the following disclaimer in the
14     documentation and/or other materials provided with the distribution.
15
16  3. Neither the name of the Intel Corporation nor the names of its
17     contributors may be used to endorse or promote products derived from
18     this software without specific prior written permission.
19
20 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
24 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 POSSIBILITY OF SUCH DAMAGE.
31
32 ***************************************************************************/
33
34 #include "ixgbe_vf.h"
35 #include "ixgbe_hv_vf.h"
36
37 /**
38  * Hyper-V variant - just a stub.
39  * @hw: unused
40  * @mc_addr_list: unused
41  * @mc_addr_count: unused
42  * @next: unused
43  * @clear: unused
44  */
45 static s32 ixgbevf_hv_update_mc_addr_list_vf(struct ixgbe_hw *hw, u8 *mc_addr_list,
46                                  u32 mc_addr_count, ixgbe_mc_addr_itr next,
47                                  bool clear)
48 {
49         UNREFERENCED_5PARAMETER(hw, mc_addr_list, mc_addr_count, next, clear);
50
51         return IXGBE_ERR_FEATURE_NOT_SUPPORTED;
52 }
53
54 /**
55  * Hyper-V variant - just a stub.
56  * @hw: unused
57  * @xcast_mode: unused
58  */
59 static s32 ixgbevf_hv_update_xcast_mode(struct ixgbe_hw *hw, int xcast_mode)
60 {
61         UNREFERENCED_2PARAMETER(hw, xcast_mode);
62
63         return IXGBE_ERR_FEATURE_NOT_SUPPORTED;
64 }
65
66 /**
67  * Hyper-V variant - just a stub.
68  * @hw: unused
69  * @vlan: unused
70  * @vind: unused
71  * @vlan_on: unused
72  * @vlvf_bypass: unused
73  */
74 static s32 ixgbevf_hv_set_vfta_vf(struct ixgbe_hw *hw, u32 vlan, u32 vind,
75                                   bool vlan_on, bool vlvf_bypass)
76 {
77         UNREFERENCED_5PARAMETER(hw, vlan, vind, vlan_on, vlvf_bypass);
78
79         return IXGBE_ERR_FEATURE_NOT_SUPPORTED;
80 }
81
82 static s32 ixgbevf_hv_set_uc_addr_vf(struct ixgbe_hw *hw, u32 index, u8 *addr)
83 {
84         UNREFERENCED_3PARAMETER(hw, index, addr);
85
86         return IXGBE_ERR_FEATURE_NOT_SUPPORTED;
87 }
88
89 /**
90  * Hyper-V variant - just a stub.
91  */
92 static s32 ixgbevf_hv_reset_hw_vf(struct ixgbe_hw *hw)
93 {
94         UNREFERENCED_PARAMETER(hw);
95
96         return IXGBE_ERR_FEATURE_NOT_SUPPORTED;
97 }
98
99 /**
100  * Hyper-V variant - just a stub.
101  */
102 static s32 ixgbevf_hv_set_rar_vf(struct ixgbe_hw *hw, u32 index, u8 *addr, u32 vlan, u32 vind)
103 {
104         UNREFERENCED_5PARAMETER(hw, index, addr, vlan, vind);
105
106         return IXGBE_ERR_FEATURE_NOT_SUPPORTED;
107 }
108
109 /**
110  * Hyper-V variant; there is no mailbox communication.
111  * @hw: pointer to hardware structure
112  * @speed: pointer to link speed
113  * @link_up: true is link is up, false otherwise
114  * @autoneg_wait_to_complete: unused
115  *
116  */
117 static s32 ixgbevf_hv_check_mac_link_vf(struct ixgbe_hw *hw,
118                                         ixgbe_link_speed *speed,
119                                         bool *link_up,
120                                         bool autoneg_wait_to_complete)
121 {
122         struct ixgbe_mbx_info *mbx = &hw->mbx;
123         struct ixgbe_mac_info *mac = &hw->mac;
124         u32 links_reg;
125         UNREFERENCED_1PARAMETER(autoneg_wait_to_complete);
126
127         /* If we were hit with a reset drop the link */
128         if (!mbx->ops.check_for_rst(hw, 0) || !mbx->timeout)
129                 mac->get_link_status = true;
130
131         if (!mac->get_link_status)
132                 goto out;
133
134         /* if link status is down no point in checking to see if pf is up */
135         links_reg = IXGBE_READ_REG(hw, IXGBE_VFLINKS);
136         if (!(links_reg & IXGBE_LINKS_UP))
137                 goto out;
138
139         /* for SFP+ modules and DA cables on 82599 it can take up to 500usecs
140          * before the link status is correct
141          */
142         if (mac->type == ixgbe_mac_82599_vf) {
143                 int i;
144
145                 for (i = 0; i < 5; i++) {
146                         DELAY(100);
147                         links_reg = IXGBE_READ_REG(hw, IXGBE_VFLINKS);
148
149                         if (!(links_reg & IXGBE_LINKS_UP))
150                                 goto out;
151                 }
152         }
153
154         switch (links_reg & IXGBE_LINKS_SPEED_82599) {
155         case IXGBE_LINKS_SPEED_10G_82599:
156                 *speed = IXGBE_LINK_SPEED_10GB_FULL;
157                 if (hw->mac.type >= ixgbe_mac_X550) {
158                         if (links_reg & IXGBE_LINKS_SPEED_NON_STD)
159                                 *speed = IXGBE_LINK_SPEED_2_5GB_FULL;
160                 }
161                 break;
162         case IXGBE_LINKS_SPEED_1G_82599:
163                 *speed = IXGBE_LINK_SPEED_1GB_FULL;
164                 break;
165         case IXGBE_LINKS_SPEED_100_82599:
166                 *speed = IXGBE_LINK_SPEED_100_FULL;
167                 if (hw->mac.type == ixgbe_mac_X550) {
168                         if (links_reg & IXGBE_LINKS_SPEED_NON_STD)
169                                 *speed = IXGBE_LINK_SPEED_5GB_FULL;
170                 }
171                 break;
172         case IXGBE_LINKS_SPEED_10_X550EM_A:
173                 *speed = IXGBE_LINK_SPEED_UNKNOWN;
174                 /* Reserved for pre-x550 devices */
175                 if (hw->mac.type >= ixgbe_mac_X550)
176                         *speed = IXGBE_LINK_SPEED_10_FULL;
177                 break;
178         default:
179                 *speed = IXGBE_LINK_SPEED_UNKNOWN;
180         }
181
182         /* if we passed all the tests above then the link is up and we no
183          * longer need to check for link
184          */
185         mac->get_link_status = false;
186
187 out:
188         *link_up = !mac->get_link_status;
189         return IXGBE_SUCCESS;
190 }
191
192 /**
193  * ixgbevf_hv_set_rlpml_vf - Set the maximum receive packet length
194  * @hw: pointer to the HW structure
195  * @max_size: value to assign to max frame size
196  * Hyper-V variant.
197  **/
198 static s32 ixgbevf_hv_set_rlpml_vf(struct ixgbe_hw *hw, u16 max_size)
199 {
200         u32 reg;
201
202         /* If we are on Hyper-V, we implement this functionality
203          * differently.
204          */
205         reg =  IXGBE_READ_REG(hw, IXGBE_VFRXDCTL(0));
206         /* CRC == 4 */
207         reg |= ((max_size + 4) | IXGBE_RXDCTL_RLPML_EN);
208         IXGBE_WRITE_REG(hw, IXGBE_VFRXDCTL(0), reg);
209
210         return IXGBE_SUCCESS;
211 }
212
213 /**
214  *  ixgbevf_hv_negotiate_api_version_vf - Negotiate supported API version
215  *  @hw: pointer to the HW structure
216  *  @api: integer containing requested API version
217  *  Hyper-V version - only ixgbe_mbox_api_10 supported.
218  **/
219 static int ixgbevf_hv_negotiate_api_version_vf(struct ixgbe_hw *hw, int api)
220 {
221         UNREFERENCED_1PARAMETER(hw);
222
223         /* Hyper-V only supports api version ixgbe_mbox_api_10 */
224         if (api != ixgbe_mbox_api_10)
225                 return IXGBE_ERR_INVALID_ARGUMENT;
226
227         return IXGBE_SUCCESS;
228 }
229
230 /**
231  *  ixgbevf_hv_init_ops_vf - Initialize the pointers for vf
232  *  @hw: pointer to hardware structure
233  *
234  *  This will assign function pointers, adapter-specific functions can
235  *  override the assignment of generic function pointers by assigning
236  *  their own adapter-specific function pointers.
237  *  Does not touch the hardware.
238  **/
239 s32 ixgbevf_hv_init_ops_vf(struct ixgbe_hw *hw)
240 {
241         /* Set defaults for VF then override applicable Hyper-V
242          * specific functions
243          */
244         ixgbe_init_ops_vf(hw);
245
246         hw->mac.ops.reset_hw = ixgbevf_hv_reset_hw_vf;
247         hw->mac.ops.check_link = ixgbevf_hv_check_mac_link_vf;
248         hw->mac.ops.negotiate_api_version = ixgbevf_hv_negotiate_api_version_vf;
249         hw->mac.ops.set_rar = ixgbevf_hv_set_rar_vf;
250         hw->mac.ops.update_mc_addr_list = ixgbevf_hv_update_mc_addr_list_vf;
251         hw->mac.ops.update_xcast_mode = ixgbevf_hv_update_xcast_mode;
252         hw->mac.ops.set_uc_addr = ixgbevf_hv_set_uc_addr_vf;
253         hw->mac.ops.set_vfta = ixgbevf_hv_set_vfta_vf;
254         hw->mac.ops.set_rlpml = ixgbevf_hv_set_rlpml_vf;
255
256         return IXGBE_SUCCESS;
257 }