New upstream version 18.11-rc1
[deb_dpdk.git] / drivers / net / ixgbe / base / ixgbe_hv_vf.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2001-2018
3  */
4
5 #include "ixgbe_vf.h"
6 #include "ixgbe_hv_vf.h"
7
8 /**
9  * Hyper-V variant - just a stub.
10  * @hw: unused
11  * @mc_addr_list: unused
12  * @mc_addr_count: unused
13  * @next: unused
14  * @clear: unused
15  */
16 static s32 ixgbevf_hv_update_mc_addr_list_vf(struct ixgbe_hw *hw, u8 *mc_addr_list,
17                                  u32 mc_addr_count, ixgbe_mc_addr_itr next,
18                                  bool clear)
19 {
20         UNREFERENCED_5PARAMETER(hw, mc_addr_list, mc_addr_count, next, clear);
21
22         return IXGBE_ERR_FEATURE_NOT_SUPPORTED;
23 }
24
25 /**
26  * Hyper-V variant - just a stub.
27  * @hw: unused
28  * @xcast_mode: unused
29  */
30 static s32 ixgbevf_hv_update_xcast_mode(struct ixgbe_hw *hw, int xcast_mode)
31 {
32         UNREFERENCED_2PARAMETER(hw, xcast_mode);
33
34         return IXGBE_ERR_FEATURE_NOT_SUPPORTED;
35 }
36
37 /**
38  * Hyper-V variant - just a stub.
39  * @hw: unused
40  * @vlan: unused
41  * @vind: unused
42  * @vlan_on: unused
43  * @vlvf_bypass: unused
44  */
45 static s32 ixgbevf_hv_set_vfta_vf(struct ixgbe_hw *hw, u32 vlan, u32 vind,
46                                   bool vlan_on, bool vlvf_bypass)
47 {
48         UNREFERENCED_5PARAMETER(hw, vlan, vind, vlan_on, vlvf_bypass);
49
50         return IXGBE_ERR_FEATURE_NOT_SUPPORTED;
51 }
52
53 static s32 ixgbevf_hv_set_uc_addr_vf(struct ixgbe_hw *hw, u32 index, u8 *addr)
54 {
55         UNREFERENCED_3PARAMETER(hw, index, addr);
56
57         return IXGBE_ERR_FEATURE_NOT_SUPPORTED;
58 }
59
60 /**
61  * Hyper-V variant - just a stub.
62  */
63 static s32 ixgbevf_hv_reset_hw_vf(struct ixgbe_hw *hw)
64 {
65         UNREFERENCED_PARAMETER(hw);
66
67         return IXGBE_ERR_FEATURE_NOT_SUPPORTED;
68 }
69
70 /**
71  * Hyper-V variant - just a stub.
72  */
73 static s32 ixgbevf_hv_set_rar_vf(struct ixgbe_hw *hw, u32 index, u8 *addr, u32 vlan, u32 vind)
74 {
75         UNREFERENCED_5PARAMETER(hw, index, addr, vlan, vind);
76
77         return IXGBE_ERR_FEATURE_NOT_SUPPORTED;
78 }
79
80 /**
81  * Hyper-V variant; there is no mailbox communication.
82  * @hw: pointer to hardware structure
83  * @speed: pointer to link speed
84  * @link_up: true is link is up, false otherwise
85  * @autoneg_wait_to_complete: unused
86  *
87  */
88 static s32 ixgbevf_hv_check_mac_link_vf(struct ixgbe_hw *hw,
89                                         ixgbe_link_speed *speed,
90                                         bool *link_up,
91                                         bool autoneg_wait_to_complete)
92 {
93         struct ixgbe_mbx_info *mbx = &hw->mbx;
94         struct ixgbe_mac_info *mac = &hw->mac;
95         u32 links_reg;
96         UNREFERENCED_1PARAMETER(autoneg_wait_to_complete);
97
98         /* If we were hit with a reset drop the link */
99         if (!mbx->ops.check_for_rst(hw, 0) || !mbx->timeout)
100                 mac->get_link_status = true;
101
102         if (!mac->get_link_status)
103                 goto out;
104
105         /* if link status is down no point in checking to see if pf is up */
106         links_reg = IXGBE_READ_REG(hw, IXGBE_VFLINKS);
107         if (!(links_reg & IXGBE_LINKS_UP))
108                 goto out;
109
110         /* for SFP+ modules and DA cables on 82599 it can take up to 500usecs
111          * before the link status is correct
112          */
113         if (mac->type == ixgbe_mac_82599_vf) {
114                 int i;
115
116                 for (i = 0; i < 5; i++) {
117                         DELAY(100);
118                         links_reg = IXGBE_READ_REG(hw, IXGBE_VFLINKS);
119
120                         if (!(links_reg & IXGBE_LINKS_UP))
121                                 goto out;
122                 }
123         }
124
125         switch (links_reg & IXGBE_LINKS_SPEED_82599) {
126         case IXGBE_LINKS_SPEED_10G_82599:
127                 *speed = IXGBE_LINK_SPEED_10GB_FULL;
128                 if (hw->mac.type >= ixgbe_mac_X550) {
129                         if (links_reg & IXGBE_LINKS_SPEED_NON_STD)
130                                 *speed = IXGBE_LINK_SPEED_2_5GB_FULL;
131                 }
132                 break;
133         case IXGBE_LINKS_SPEED_1G_82599:
134                 *speed = IXGBE_LINK_SPEED_1GB_FULL;
135                 break;
136         case IXGBE_LINKS_SPEED_100_82599:
137                 *speed = IXGBE_LINK_SPEED_100_FULL;
138                 if (hw->mac.type == ixgbe_mac_X550) {
139                         if (links_reg & IXGBE_LINKS_SPEED_NON_STD)
140                                 *speed = IXGBE_LINK_SPEED_5GB_FULL;
141                 }
142                 break;
143         case IXGBE_LINKS_SPEED_10_X550EM_A:
144                 *speed = IXGBE_LINK_SPEED_UNKNOWN;
145                 /* Reserved for pre-x550 devices */
146                 if (hw->mac.type >= ixgbe_mac_X550)
147                         *speed = IXGBE_LINK_SPEED_10_FULL;
148                 break;
149         default:
150                 *speed = IXGBE_LINK_SPEED_UNKNOWN;
151         }
152
153         /* if we passed all the tests above then the link is up and we no
154          * longer need to check for link
155          */
156         mac->get_link_status = false;
157
158 out:
159         *link_up = !mac->get_link_status;
160         return IXGBE_SUCCESS;
161 }
162
163 /**
164  * ixgbevf_hv_set_rlpml_vf - Set the maximum receive packet length
165  * @hw: pointer to the HW structure
166  * @max_size: value to assign to max frame size
167  * Hyper-V variant.
168  **/
169 static s32 ixgbevf_hv_set_rlpml_vf(struct ixgbe_hw *hw, u16 max_size)
170 {
171         u32 reg;
172
173         /* If we are on Hyper-V, we implement this functionality
174          * differently.
175          */
176         reg =  IXGBE_READ_REG(hw, IXGBE_VFRXDCTL(0));
177         /* CRC == 4 */
178         reg |= ((max_size + 4) | IXGBE_RXDCTL_RLPML_EN);
179         IXGBE_WRITE_REG(hw, IXGBE_VFRXDCTL(0), reg);
180
181         return IXGBE_SUCCESS;
182 }
183
184 /**
185  *  ixgbevf_hv_negotiate_api_version_vf - Negotiate supported API version
186  *  @hw: pointer to the HW structure
187  *  @api: integer containing requested API version
188  *  Hyper-V version - only ixgbe_mbox_api_10 supported.
189  **/
190 static int ixgbevf_hv_negotiate_api_version_vf(struct ixgbe_hw *hw, int api)
191 {
192         UNREFERENCED_1PARAMETER(hw);
193
194         /* Hyper-V only supports api version ixgbe_mbox_api_10 */
195         if (api != ixgbe_mbox_api_10)
196                 return IXGBE_ERR_INVALID_ARGUMENT;
197
198         return IXGBE_SUCCESS;
199 }
200
201 /**
202  *  ixgbevf_hv_init_ops_vf - Initialize the pointers for vf
203  *  @hw: pointer to hardware structure
204  *
205  *  This will assign function pointers, adapter-specific functions can
206  *  override the assignment of generic function pointers by assigning
207  *  their own adapter-specific function pointers.
208  *  Does not touch the hardware.
209  **/
210 s32 ixgbevf_hv_init_ops_vf(struct ixgbe_hw *hw)
211 {
212         /* Set defaults for VF then override applicable Hyper-V
213          * specific functions
214          */
215         ixgbe_init_ops_vf(hw);
216
217         hw->mac.ops.reset_hw = ixgbevf_hv_reset_hw_vf;
218         hw->mac.ops.check_link = ixgbevf_hv_check_mac_link_vf;
219         hw->mac.ops.negotiate_api_version = ixgbevf_hv_negotiate_api_version_vf;
220         hw->mac.ops.set_rar = ixgbevf_hv_set_rar_vf;
221         hw->mac.ops.update_mc_addr_list = ixgbevf_hv_update_mc_addr_list_vf;
222         hw->mac.ops.update_xcast_mode = ixgbevf_hv_update_xcast_mode;
223         hw->mac.ops.set_uc_addr = ixgbevf_hv_set_uc_addr_vf;
224         hw->mac.ops.set_vfta = ixgbevf_hv_set_vfta_vf;
225         hw->mac.ops.set_rlpml = ixgbevf_hv_set_rlpml_vf;
226
227         return IXGBE_SUCCESS;
228 }