Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1 | /******************************************************************************* |
| 2 | * |
| 3 | * Intel Ethernet Controller XL710 Family Linux Driver |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 4 | * Copyright(c) 2013 - 2015 Intel Corporation. |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify it |
| 7 | * under the terms and conditions of the GNU General Public License, |
| 8 | * version 2, as published by the Free Software Foundation. |
| 9 | * |
| 10 | * This program is distributed in the hope it will be useful, but WITHOUT |
| 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 13 | * more details. |
| 14 | * |
Greg Rose | dc641b7 | 2013-12-18 13:45:51 +0000 | [diff] [blame] | 15 | * You should have received a copy of the GNU General Public License along |
| 16 | * with this program. If not, see <http://www.gnu.org/licenses/>. |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 17 | * |
| 18 | * The full GNU General Public License is included in this distribution in |
| 19 | * the file called "COPYING". |
| 20 | * |
| 21 | * Contact Information: |
| 22 | * e1000-devel Mailing List <e1000-devel@lists.sourceforge.net> |
| 23 | * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 |
| 24 | * |
| 25 | ******************************************************************************/ |
| 26 | |
| 27 | #include "i40e.h" |
| 28 | |
Mitch Williams | 532b045 | 2015-04-07 19:45:34 -0400 | [diff] [blame] | 29 | /*********************notification routines***********************/ |
| 30 | |
| 31 | /** |
| 32 | * i40e_vc_vf_broadcast |
| 33 | * @pf: pointer to the PF structure |
| 34 | * @opcode: operation code |
| 35 | * @retval: return value |
| 36 | * @msg: pointer to the msg buffer |
| 37 | * @msglen: msg length |
| 38 | * |
| 39 | * send a message to all VFs on a given PF |
| 40 | **/ |
| 41 | static void i40e_vc_vf_broadcast(struct i40e_pf *pf, |
| 42 | enum i40e_virtchnl_ops v_opcode, |
| 43 | i40e_status v_retval, u8 *msg, |
| 44 | u16 msglen) |
| 45 | { |
| 46 | struct i40e_hw *hw = &pf->hw; |
| 47 | struct i40e_vf *vf = pf->vf; |
| 48 | int i; |
| 49 | |
| 50 | for (i = 0; i < pf->num_alloc_vfs; i++, vf++) { |
| 51 | int abs_vf_id = vf->vf_id + hw->func_caps.vf_base_id; |
| 52 | /* Not all vfs are enabled so skip the ones that are not */ |
| 53 | if (!test_bit(I40E_VF_STAT_INIT, &vf->vf_states) && |
| 54 | !test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states)) |
| 55 | continue; |
| 56 | |
| 57 | /* Ignore return value on purpose - a given VF may fail, but |
| 58 | * we need to keep going and send to all of them |
| 59 | */ |
| 60 | i40e_aq_send_msg_to_vf(hw, abs_vf_id, v_opcode, v_retval, |
| 61 | msg, msglen, NULL); |
| 62 | } |
| 63 | } |
| 64 | |
| 65 | /** |
| 66 | * i40e_vc_notify_link_state |
| 67 | * @vf: pointer to the VF structure |
| 68 | * |
| 69 | * send a link status message to a single VF |
| 70 | **/ |
| 71 | static void i40e_vc_notify_vf_link_state(struct i40e_vf *vf) |
| 72 | { |
| 73 | struct i40e_virtchnl_pf_event pfe; |
| 74 | struct i40e_pf *pf = vf->pf; |
| 75 | struct i40e_hw *hw = &pf->hw; |
| 76 | struct i40e_link_status *ls = &pf->hw.phy.link_info; |
| 77 | int abs_vf_id = vf->vf_id + hw->func_caps.vf_base_id; |
| 78 | |
| 79 | pfe.event = I40E_VIRTCHNL_EVENT_LINK_CHANGE; |
| 80 | pfe.severity = I40E_PF_EVENT_SEVERITY_INFO; |
| 81 | if (vf->link_forced) { |
| 82 | pfe.event_data.link_event.link_status = vf->link_up; |
| 83 | pfe.event_data.link_event.link_speed = |
| 84 | (vf->link_up ? I40E_LINK_SPEED_40GB : 0); |
| 85 | } else { |
| 86 | pfe.event_data.link_event.link_status = |
| 87 | ls->link_info & I40E_AQ_LINK_UP; |
| 88 | pfe.event_data.link_event.link_speed = ls->link_speed; |
| 89 | } |
| 90 | i40e_aq_send_msg_to_vf(hw, abs_vf_id, I40E_VIRTCHNL_OP_EVENT, |
| 91 | 0, (u8 *)&pfe, sizeof(pfe), NULL); |
| 92 | } |
| 93 | |
| 94 | /** |
| 95 | * i40e_vc_notify_link_state |
| 96 | * @pf: pointer to the PF structure |
| 97 | * |
| 98 | * send a link status message to all VFs on a given PF |
| 99 | **/ |
| 100 | void i40e_vc_notify_link_state(struct i40e_pf *pf) |
| 101 | { |
| 102 | int i; |
| 103 | |
| 104 | for (i = 0; i < pf->num_alloc_vfs; i++) |
| 105 | i40e_vc_notify_vf_link_state(&pf->vf[i]); |
| 106 | } |
| 107 | |
| 108 | /** |
| 109 | * i40e_vc_notify_reset |
| 110 | * @pf: pointer to the PF structure |
| 111 | * |
| 112 | * indicate a pending reset to all VFs on a given PF |
| 113 | **/ |
| 114 | void i40e_vc_notify_reset(struct i40e_pf *pf) |
| 115 | { |
| 116 | struct i40e_virtchnl_pf_event pfe; |
| 117 | |
| 118 | pfe.event = I40E_VIRTCHNL_EVENT_RESET_IMPENDING; |
| 119 | pfe.severity = I40E_PF_EVENT_SEVERITY_CERTAIN_DOOM; |
| 120 | i40e_vc_vf_broadcast(pf, I40E_VIRTCHNL_OP_EVENT, 0, |
| 121 | (u8 *)&pfe, sizeof(struct i40e_virtchnl_pf_event)); |
| 122 | } |
| 123 | |
| 124 | /** |
| 125 | * i40e_vc_notify_vf_reset |
| 126 | * @vf: pointer to the VF structure |
| 127 | * |
| 128 | * indicate a pending reset to the given VF |
| 129 | **/ |
| 130 | void i40e_vc_notify_vf_reset(struct i40e_vf *vf) |
| 131 | { |
| 132 | struct i40e_virtchnl_pf_event pfe; |
| 133 | int abs_vf_id; |
| 134 | |
| 135 | /* validate the request */ |
| 136 | if (!vf || vf->vf_id >= vf->pf->num_alloc_vfs) |
| 137 | return; |
| 138 | |
| 139 | /* verify if the VF is in either init or active before proceeding */ |
| 140 | if (!test_bit(I40E_VF_STAT_INIT, &vf->vf_states) && |
| 141 | !test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states)) |
| 142 | return; |
| 143 | |
| 144 | abs_vf_id = vf->vf_id + vf->pf->hw.func_caps.vf_base_id; |
| 145 | |
| 146 | pfe.event = I40E_VIRTCHNL_EVENT_RESET_IMPENDING; |
| 147 | pfe.severity = I40E_PF_EVENT_SEVERITY_CERTAIN_DOOM; |
| 148 | i40e_aq_send_msg_to_vf(&vf->pf->hw, abs_vf_id, I40E_VIRTCHNL_OP_EVENT, |
| 149 | 0, (u8 *)&pfe, |
| 150 | sizeof(struct i40e_virtchnl_pf_event), NULL); |
| 151 | } |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 152 | /***********************misc routines*****************************/ |
| 153 | |
| 154 | /** |
Greg Rose | f9b4b62 | 2014-03-06 09:02:28 +0000 | [diff] [blame] | 155 | * i40e_vc_disable_vf |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 156 | * @pf: pointer to the PF info |
| 157 | * @vf: pointer to the VF info |
Greg Rose | f9b4b62 | 2014-03-06 09:02:28 +0000 | [diff] [blame] | 158 | * |
| 159 | * Disable the VF through a SW reset |
| 160 | **/ |
| 161 | static inline void i40e_vc_disable_vf(struct i40e_pf *pf, struct i40e_vf *vf) |
| 162 | { |
Mitch Williams | 54f455e | 2015-04-27 14:57:14 -0400 | [diff] [blame] | 163 | i40e_vc_notify_vf_reset(vf); |
| 164 | i40e_reset_vf(vf, false); |
Greg Rose | f9b4b62 | 2014-03-06 09:02:28 +0000 | [diff] [blame] | 165 | } |
| 166 | |
| 167 | /** |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 168 | * i40e_vc_isvalid_vsi_id |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 169 | * @vf: pointer to the VF info |
| 170 | * @vsi_id: VF relative VSI id |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 171 | * |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 172 | * check for the valid VSI id |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 173 | **/ |
Anjali Singhai Jain | fdf0e0b | 2015-03-31 00:45:05 -0700 | [diff] [blame] | 174 | static inline bool i40e_vc_isvalid_vsi_id(struct i40e_vf *vf, u16 vsi_id) |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 175 | { |
| 176 | struct i40e_pf *pf = vf->pf; |
Anjali Singhai Jain | fdf0e0b | 2015-03-31 00:45:05 -0700 | [diff] [blame] | 177 | struct i40e_vsi *vsi = i40e_find_vsi_from_id(pf, vsi_id); |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 178 | |
Anjali Singhai Jain | fdf0e0b | 2015-03-31 00:45:05 -0700 | [diff] [blame] | 179 | return (vsi && (vsi->vf_id == vf->vf_id)); |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 180 | } |
| 181 | |
| 182 | /** |
| 183 | * i40e_vc_isvalid_queue_id |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 184 | * @vf: pointer to the VF info |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 185 | * @vsi_id: vsi id |
| 186 | * @qid: vsi relative queue id |
| 187 | * |
| 188 | * check for the valid queue id |
| 189 | **/ |
Anjali Singhai Jain | fdf0e0b | 2015-03-31 00:45:05 -0700 | [diff] [blame] | 190 | static inline bool i40e_vc_isvalid_queue_id(struct i40e_vf *vf, u16 vsi_id, |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 191 | u8 qid) |
| 192 | { |
| 193 | struct i40e_pf *pf = vf->pf; |
Anjali Singhai Jain | fdf0e0b | 2015-03-31 00:45:05 -0700 | [diff] [blame] | 194 | struct i40e_vsi *vsi = i40e_find_vsi_from_id(pf, vsi_id); |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 195 | |
Anjali Singhai Jain | fdf0e0b | 2015-03-31 00:45:05 -0700 | [diff] [blame] | 196 | return (vsi && (qid < vsi->alloc_queue_pairs)); |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 197 | } |
| 198 | |
| 199 | /** |
| 200 | * i40e_vc_isvalid_vector_id |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 201 | * @vf: pointer to the VF info |
| 202 | * @vector_id: VF relative vector id |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 203 | * |
| 204 | * check for the valid vector id |
| 205 | **/ |
| 206 | static inline bool i40e_vc_isvalid_vector_id(struct i40e_vf *vf, u8 vector_id) |
| 207 | { |
| 208 | struct i40e_pf *pf = vf->pf; |
| 209 | |
Mitch Williams | 9347eb7 | 2014-02-11 08:26:32 +0000 | [diff] [blame] | 210 | return vector_id < pf->hw.func_caps.num_msix_vectors_vf; |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 211 | } |
| 212 | |
| 213 | /***********************vf resource mgmt routines*****************/ |
| 214 | |
| 215 | /** |
| 216 | * i40e_vc_get_pf_queue_id |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 217 | * @vf: pointer to the VF info |
Anjali Singhai Jain | fdf0e0b | 2015-03-31 00:45:05 -0700 | [diff] [blame] | 218 | * @vsi_id: id of VSI as provided by the FW |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 219 | * @vsi_queue_id: vsi relative queue id |
| 220 | * |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 221 | * return PF relative queue id |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 222 | **/ |
Anjali Singhai Jain | fdf0e0b | 2015-03-31 00:45:05 -0700 | [diff] [blame] | 223 | static u16 i40e_vc_get_pf_queue_id(struct i40e_vf *vf, u16 vsi_id, |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 224 | u8 vsi_queue_id) |
| 225 | { |
| 226 | struct i40e_pf *pf = vf->pf; |
Anjali Singhai Jain | fdf0e0b | 2015-03-31 00:45:05 -0700 | [diff] [blame] | 227 | struct i40e_vsi *vsi = i40e_find_vsi_from_id(pf, vsi_id); |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 228 | u16 pf_queue_id = I40E_QUEUE_END_OF_LIST; |
| 229 | |
Anjali Singhai Jain | fdf0e0b | 2015-03-31 00:45:05 -0700 | [diff] [blame] | 230 | if (!vsi) |
| 231 | return pf_queue_id; |
| 232 | |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 233 | if (le16_to_cpu(vsi->info.mapping_flags) & |
| 234 | I40E_AQ_VSI_QUE_MAP_NONCONTIG) |
| 235 | pf_queue_id = |
| 236 | le16_to_cpu(vsi->info.queue_mapping[vsi_queue_id]); |
| 237 | else |
| 238 | pf_queue_id = le16_to_cpu(vsi->info.queue_mapping[0]) + |
| 239 | vsi_queue_id; |
| 240 | |
| 241 | return pf_queue_id; |
| 242 | } |
| 243 | |
| 244 | /** |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 245 | * i40e_config_irq_link_list |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 246 | * @vf: pointer to the VF info |
Anjali Singhai Jain | fdf0e0b | 2015-03-31 00:45:05 -0700 | [diff] [blame] | 247 | * @vsi_id: id of VSI as given by the FW |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 248 | * @vecmap: irq map info |
| 249 | * |
| 250 | * configure irq link list from the map |
| 251 | **/ |
Anjali Singhai Jain | fdf0e0b | 2015-03-31 00:45:05 -0700 | [diff] [blame] | 252 | static void i40e_config_irq_link_list(struct i40e_vf *vf, u16 vsi_id, |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 253 | struct i40e_virtchnl_vector_map *vecmap) |
| 254 | { |
| 255 | unsigned long linklistmap = 0, tempmap; |
| 256 | struct i40e_pf *pf = vf->pf; |
| 257 | struct i40e_hw *hw = &pf->hw; |
| 258 | u16 vsi_queue_id, pf_queue_id; |
| 259 | enum i40e_queue_type qtype; |
| 260 | u16 next_q, vector_id; |
| 261 | u32 reg, reg_idx; |
| 262 | u16 itr_idx = 0; |
| 263 | |
| 264 | vector_id = vecmap->vector_id; |
| 265 | /* setup the head */ |
| 266 | if (0 == vector_id) |
| 267 | reg_idx = I40E_VPINT_LNKLST0(vf->vf_id); |
| 268 | else |
| 269 | reg_idx = I40E_VPINT_LNKLSTN( |
Mitch Williams | 9347eb7 | 2014-02-11 08:26:32 +0000 | [diff] [blame] | 270 | ((pf->hw.func_caps.num_msix_vectors_vf - 1) * vf->vf_id) + |
| 271 | (vector_id - 1)); |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 272 | |
| 273 | if (vecmap->rxq_map == 0 && vecmap->txq_map == 0) { |
| 274 | /* Special case - No queues mapped on this vector */ |
| 275 | wr32(hw, reg_idx, I40E_VPINT_LNKLST0_FIRSTQ_INDX_MASK); |
| 276 | goto irq_list_done; |
| 277 | } |
| 278 | tempmap = vecmap->rxq_map; |
Wei Yongjun | 4836650 | 2013-09-24 05:17:36 +0000 | [diff] [blame] | 279 | for_each_set_bit(vsi_queue_id, &tempmap, I40E_MAX_VSI_QP) { |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 280 | linklistmap |= (BIT(I40E_VIRTCHNL_SUPPORTED_QTYPES * |
| 281 | vsi_queue_id)); |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 282 | } |
| 283 | |
| 284 | tempmap = vecmap->txq_map; |
Wei Yongjun | 4836650 | 2013-09-24 05:17:36 +0000 | [diff] [blame] | 285 | for_each_set_bit(vsi_queue_id, &tempmap, I40E_MAX_VSI_QP) { |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 286 | linklistmap |= (BIT(I40E_VIRTCHNL_SUPPORTED_QTYPES * |
| 287 | vsi_queue_id + 1)); |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 288 | } |
| 289 | |
| 290 | next_q = find_first_bit(&linklistmap, |
| 291 | (I40E_MAX_VSI_QP * |
| 292 | I40E_VIRTCHNL_SUPPORTED_QTYPES)); |
Mitch Williams | b82bc49e | 2015-11-06 15:26:10 -0800 | [diff] [blame] | 293 | vsi_queue_id = next_q / I40E_VIRTCHNL_SUPPORTED_QTYPES; |
| 294 | qtype = next_q % I40E_VIRTCHNL_SUPPORTED_QTYPES; |
Anjali Singhai Jain | fdf0e0b | 2015-03-31 00:45:05 -0700 | [diff] [blame] | 295 | pf_queue_id = i40e_vc_get_pf_queue_id(vf, vsi_id, vsi_queue_id); |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 296 | reg = ((qtype << I40E_VPINT_LNKLSTN_FIRSTQ_TYPE_SHIFT) | pf_queue_id); |
| 297 | |
| 298 | wr32(hw, reg_idx, reg); |
| 299 | |
| 300 | while (next_q < (I40E_MAX_VSI_QP * I40E_VIRTCHNL_SUPPORTED_QTYPES)) { |
| 301 | switch (qtype) { |
| 302 | case I40E_QUEUE_TYPE_RX: |
| 303 | reg_idx = I40E_QINT_RQCTL(pf_queue_id); |
| 304 | itr_idx = vecmap->rxitr_idx; |
| 305 | break; |
| 306 | case I40E_QUEUE_TYPE_TX: |
| 307 | reg_idx = I40E_QINT_TQCTL(pf_queue_id); |
| 308 | itr_idx = vecmap->txitr_idx; |
| 309 | break; |
| 310 | default: |
| 311 | break; |
| 312 | } |
| 313 | |
| 314 | next_q = find_next_bit(&linklistmap, |
| 315 | (I40E_MAX_VSI_QP * |
| 316 | I40E_VIRTCHNL_SUPPORTED_QTYPES), |
| 317 | next_q + 1); |
Mitch Williams | 829af3a | 2013-12-18 13:46:00 +0000 | [diff] [blame] | 318 | if (next_q < |
| 319 | (I40E_MAX_VSI_QP * I40E_VIRTCHNL_SUPPORTED_QTYPES)) { |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 320 | vsi_queue_id = next_q / I40E_VIRTCHNL_SUPPORTED_QTYPES; |
| 321 | qtype = next_q % I40E_VIRTCHNL_SUPPORTED_QTYPES; |
Anjali Singhai Jain | fdf0e0b | 2015-03-31 00:45:05 -0700 | [diff] [blame] | 322 | pf_queue_id = i40e_vc_get_pf_queue_id(vf, vsi_id, |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 323 | vsi_queue_id); |
| 324 | } else { |
| 325 | pf_queue_id = I40E_QUEUE_END_OF_LIST; |
| 326 | qtype = 0; |
| 327 | } |
| 328 | |
| 329 | /* format for the RQCTL & TQCTL regs is same */ |
| 330 | reg = (vector_id) | |
| 331 | (qtype << I40E_QINT_RQCTL_NEXTQ_TYPE_SHIFT) | |
| 332 | (pf_queue_id << I40E_QINT_RQCTL_NEXTQ_INDX_SHIFT) | |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 333 | BIT(I40E_QINT_RQCTL_CAUSE_ENA_SHIFT) | |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 334 | (itr_idx << I40E_QINT_RQCTL_ITR_INDX_SHIFT); |
| 335 | wr32(hw, reg_idx, reg); |
| 336 | } |
| 337 | |
Anjali Singhai Jain | b8262a6 | 2015-07-10 19:36:08 -0400 | [diff] [blame] | 338 | /* if the vf is running in polling mode and using interrupt zero, |
| 339 | * need to disable auto-mask on enabling zero interrupt for VFs. |
| 340 | */ |
| 341 | if ((vf->driver_caps & I40E_VIRTCHNL_VF_OFFLOAD_RX_POLLING) && |
| 342 | (vector_id == 0)) { |
| 343 | reg = rd32(hw, I40E_GLINT_CTL); |
| 344 | if (!(reg & I40E_GLINT_CTL_DIS_AUTOMASK_VF0_MASK)) { |
| 345 | reg |= I40E_GLINT_CTL_DIS_AUTOMASK_VF0_MASK; |
| 346 | wr32(hw, I40E_GLINT_CTL, reg); |
| 347 | } |
| 348 | } |
| 349 | |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 350 | irq_list_done: |
| 351 | i40e_flush(hw); |
| 352 | } |
| 353 | |
| 354 | /** |
| 355 | * i40e_config_vsi_tx_queue |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 356 | * @vf: pointer to the VF info |
Anjali Singhai Jain | fdf0e0b | 2015-03-31 00:45:05 -0700 | [diff] [blame] | 357 | * @vsi_id: id of VSI as provided by the FW |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 358 | * @vsi_queue_id: vsi relative queue index |
| 359 | * @info: config. info |
| 360 | * |
| 361 | * configure tx queue |
| 362 | **/ |
Anjali Singhai Jain | fdf0e0b | 2015-03-31 00:45:05 -0700 | [diff] [blame] | 363 | static int i40e_config_vsi_tx_queue(struct i40e_vf *vf, u16 vsi_id, |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 364 | u16 vsi_queue_id, |
| 365 | struct i40e_virtchnl_txq_info *info) |
| 366 | { |
| 367 | struct i40e_pf *pf = vf->pf; |
| 368 | struct i40e_hw *hw = &pf->hw; |
| 369 | struct i40e_hmc_obj_txq tx_ctx; |
Anjali Singhai Jain | fdf0e0b | 2015-03-31 00:45:05 -0700 | [diff] [blame] | 370 | struct i40e_vsi *vsi; |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 371 | u16 pf_queue_id; |
| 372 | u32 qtx_ctl; |
| 373 | int ret = 0; |
| 374 | |
Anjali Singhai Jain | fdf0e0b | 2015-03-31 00:45:05 -0700 | [diff] [blame] | 375 | pf_queue_id = i40e_vc_get_pf_queue_id(vf, vsi_id, vsi_queue_id); |
| 376 | vsi = i40e_find_vsi_from_id(pf, vsi_id); |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 377 | |
| 378 | /* clear the context structure first */ |
| 379 | memset(&tx_ctx, 0, sizeof(struct i40e_hmc_obj_txq)); |
| 380 | |
| 381 | /* only set the required fields */ |
| 382 | tx_ctx.base = info->dma_ring_addr / 128; |
| 383 | tx_ctx.qlen = info->ring_len; |
Anjali Singhai Jain | fdf0e0b | 2015-03-31 00:45:05 -0700 | [diff] [blame] | 384 | tx_ctx.rdylist = le16_to_cpu(vsi->info.qs_handle[0]); |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 385 | tx_ctx.rdylist_act = 0; |
Ashish Shah | 5d29896 | 2014-05-22 06:31:25 +0000 | [diff] [blame] | 386 | tx_ctx.head_wb_ena = info->headwb_enabled; |
| 387 | tx_ctx.head_wb_addr = info->dma_headwb_addr; |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 388 | |
| 389 | /* clear the context in the HMC */ |
| 390 | ret = i40e_clear_lan_tx_queue_context(hw, pf_queue_id); |
| 391 | if (ret) { |
| 392 | dev_err(&pf->pdev->dev, |
| 393 | "Failed to clear VF LAN Tx queue context %d, error: %d\n", |
| 394 | pf_queue_id, ret); |
| 395 | ret = -ENOENT; |
| 396 | goto error_context; |
| 397 | } |
| 398 | |
| 399 | /* set the context in the HMC */ |
| 400 | ret = i40e_set_lan_tx_queue_context(hw, pf_queue_id, &tx_ctx); |
| 401 | if (ret) { |
| 402 | dev_err(&pf->pdev->dev, |
| 403 | "Failed to set VF LAN Tx queue context %d error: %d\n", |
| 404 | pf_queue_id, ret); |
| 405 | ret = -ENOENT; |
| 406 | goto error_context; |
| 407 | } |
| 408 | |
| 409 | /* associate this queue with the PCI VF function */ |
| 410 | qtx_ctl = I40E_QTX_CTL_VF_QUEUE; |
Shannon Nelson | 13fd977 | 2013-09-28 07:14:19 +0000 | [diff] [blame] | 411 | qtx_ctl |= ((hw->pf_id << I40E_QTX_CTL_PF_INDX_SHIFT) |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 412 | & I40E_QTX_CTL_PF_INDX_MASK); |
| 413 | qtx_ctl |= (((vf->vf_id + hw->func_caps.vf_base_id) |
| 414 | << I40E_QTX_CTL_VFVM_INDX_SHIFT) |
| 415 | & I40E_QTX_CTL_VFVM_INDX_MASK); |
| 416 | wr32(hw, I40E_QTX_CTL(pf_queue_id), qtx_ctl); |
| 417 | i40e_flush(hw); |
| 418 | |
| 419 | error_context: |
| 420 | return ret; |
| 421 | } |
| 422 | |
| 423 | /** |
| 424 | * i40e_config_vsi_rx_queue |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 425 | * @vf: pointer to the VF info |
Anjali Singhai Jain | fdf0e0b | 2015-03-31 00:45:05 -0700 | [diff] [blame] | 426 | * @vsi_id: id of VSI as provided by the FW |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 427 | * @vsi_queue_id: vsi relative queue index |
| 428 | * @info: config. info |
| 429 | * |
| 430 | * configure rx queue |
| 431 | **/ |
Anjali Singhai Jain | fdf0e0b | 2015-03-31 00:45:05 -0700 | [diff] [blame] | 432 | static int i40e_config_vsi_rx_queue(struct i40e_vf *vf, u16 vsi_id, |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 433 | u16 vsi_queue_id, |
| 434 | struct i40e_virtchnl_rxq_info *info) |
| 435 | { |
| 436 | struct i40e_pf *pf = vf->pf; |
| 437 | struct i40e_hw *hw = &pf->hw; |
| 438 | struct i40e_hmc_obj_rxq rx_ctx; |
| 439 | u16 pf_queue_id; |
| 440 | int ret = 0; |
| 441 | |
Anjali Singhai Jain | fdf0e0b | 2015-03-31 00:45:05 -0700 | [diff] [blame] | 442 | pf_queue_id = i40e_vc_get_pf_queue_id(vf, vsi_id, vsi_queue_id); |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 443 | |
| 444 | /* clear the context structure first */ |
| 445 | memset(&rx_ctx, 0, sizeof(struct i40e_hmc_obj_rxq)); |
| 446 | |
| 447 | /* only set the required fields */ |
| 448 | rx_ctx.base = info->dma_ring_addr / 128; |
| 449 | rx_ctx.qlen = info->ring_len; |
| 450 | |
| 451 | if (info->splithdr_enabled) { |
| 452 | rx_ctx.hsplit_0 = I40E_RX_SPLIT_L2 | |
| 453 | I40E_RX_SPLIT_IP | |
| 454 | I40E_RX_SPLIT_TCP_UDP | |
| 455 | I40E_RX_SPLIT_SCTP; |
| 456 | /* header length validation */ |
| 457 | if (info->hdr_size > ((2 * 1024) - 64)) { |
| 458 | ret = -EINVAL; |
| 459 | goto error_param; |
| 460 | } |
| 461 | rx_ctx.hbuff = info->hdr_size >> I40E_RXQ_CTX_HBUFF_SHIFT; |
| 462 | |
| 463 | /* set splitalways mode 10b */ |
| 464 | rx_ctx.dtype = 0x2; |
| 465 | } |
| 466 | |
| 467 | /* databuffer length validation */ |
| 468 | if (info->databuffer_size > ((16 * 1024) - 128)) { |
| 469 | ret = -EINVAL; |
| 470 | goto error_param; |
| 471 | } |
| 472 | rx_ctx.dbuff = info->databuffer_size >> I40E_RXQ_CTX_DBUFF_SHIFT; |
| 473 | |
| 474 | /* max pkt. length validation */ |
| 475 | if (info->max_pkt_size >= (16 * 1024) || info->max_pkt_size < 64) { |
| 476 | ret = -EINVAL; |
| 477 | goto error_param; |
| 478 | } |
| 479 | rx_ctx.rxmax = info->max_pkt_size; |
| 480 | |
| 481 | /* enable 32bytes desc always */ |
| 482 | rx_ctx.dsize = 1; |
| 483 | |
| 484 | /* default values */ |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 485 | rx_ctx.lrxqthresh = 2; |
| 486 | rx_ctx.crcstrip = 1; |
Mitch Williams | 50d4165 | 2014-04-09 05:58:55 +0000 | [diff] [blame] | 487 | rx_ctx.prefena = 1; |
Shannon Nelson | c1d11ce | 2014-07-29 04:01:03 +0000 | [diff] [blame] | 488 | rx_ctx.l2tsel = 1; |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 489 | |
| 490 | /* clear the context in the HMC */ |
| 491 | ret = i40e_clear_lan_rx_queue_context(hw, pf_queue_id); |
| 492 | if (ret) { |
| 493 | dev_err(&pf->pdev->dev, |
| 494 | "Failed to clear VF LAN Rx queue context %d, error: %d\n", |
| 495 | pf_queue_id, ret); |
| 496 | ret = -ENOENT; |
| 497 | goto error_param; |
| 498 | } |
| 499 | |
| 500 | /* set the context in the HMC */ |
| 501 | ret = i40e_set_lan_rx_queue_context(hw, pf_queue_id, &rx_ctx); |
| 502 | if (ret) { |
| 503 | dev_err(&pf->pdev->dev, |
| 504 | "Failed to set VF LAN Rx queue context %d error: %d\n", |
| 505 | pf_queue_id, ret); |
| 506 | ret = -ENOENT; |
| 507 | goto error_param; |
| 508 | } |
| 509 | |
| 510 | error_param: |
| 511 | return ret; |
| 512 | } |
| 513 | |
| 514 | /** |
| 515 | * i40e_alloc_vsi_res |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 516 | * @vf: pointer to the VF info |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 517 | * @type: type of VSI to allocate |
| 518 | * |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 519 | * alloc VF vsi context & resources |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 520 | **/ |
| 521 | static int i40e_alloc_vsi_res(struct i40e_vf *vf, enum i40e_vsi_type type) |
| 522 | { |
| 523 | struct i40e_mac_filter *f = NULL; |
| 524 | struct i40e_pf *pf = vf->pf; |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 525 | struct i40e_vsi *vsi; |
| 526 | int ret = 0; |
| 527 | |
| 528 | vsi = i40e_vsi_setup(pf, type, pf->vsi[pf->lan_vsi]->seid, vf->vf_id); |
| 529 | |
| 530 | if (!vsi) { |
| 531 | dev_err(&pf->pdev->dev, |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 532 | "add vsi failed for VF %d, aq_err %d\n", |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 533 | vf->vf_id, pf->hw.aq.asq_last_status); |
| 534 | ret = -ENOENT; |
| 535 | goto error_alloc_vsi_res; |
| 536 | } |
| 537 | if (type == I40E_VSI_SRIOV) { |
Greg Rose | 1a10370 | 2013-11-28 06:42:39 +0000 | [diff] [blame] | 538 | u8 brdcast[ETH_ALEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff}; |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 539 | |
Anjali Singhai Jain | fdf0e0b | 2015-03-31 00:45:05 -0700 | [diff] [blame] | 540 | vf->lan_vsi_idx = vsi->idx; |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 541 | vf->lan_vsi_id = vsi->id; |
Greg Rose | 6c12fcb | 2013-11-28 06:39:34 +0000 | [diff] [blame] | 542 | /* If the port VLAN has been configured and then the |
| 543 | * VF driver was removed then the VSI port VLAN |
| 544 | * configuration was destroyed. Check if there is |
| 545 | * a port VLAN and restore the VSI configuration if |
| 546 | * needed. |
| 547 | */ |
| 548 | if (vf->port_vlan_id) |
| 549 | i40e_vsi_add_pvid(vsi, vf->port_vlan_id); |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 550 | |
| 551 | spin_lock_bh(&vsi->mac_filter_list_lock); |
Mitch Williams | b7b713a | 2015-11-19 11:34:17 -0800 | [diff] [blame] | 552 | if (is_valid_ether_addr(vf->default_lan_addr.addr)) { |
| 553 | f = i40e_add_filter(vsi, vf->default_lan_addr.addr, |
| 554 | vf->port_vlan_id ? vf->port_vlan_id : -1, |
| 555 | true, false); |
| 556 | if (!f) |
| 557 | dev_info(&pf->pdev->dev, |
| 558 | "Could not add MAC filter %pM for VF %d\n", |
| 559 | vf->default_lan_addr.addr, vf->vf_id); |
| 560 | } |
Mitch Williams | e995163 | 2015-04-27 14:57:13 -0400 | [diff] [blame] | 561 | f = i40e_add_filter(vsi, brdcast, |
| 562 | vf->port_vlan_id ? vf->port_vlan_id : -1, |
Greg Rose | 1a10370 | 2013-11-28 06:42:39 +0000 | [diff] [blame] | 563 | true, false); |
| 564 | if (!f) |
| 565 | dev_info(&pf->pdev->dev, |
| 566 | "Could not allocate VF broadcast filter\n"); |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 567 | spin_unlock_bh(&vsi->mac_filter_list_lock); |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 568 | } |
Neerav Parikh | 6dbbbfb | 2013-11-26 10:49:24 +0000 | [diff] [blame] | 569 | |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 570 | /* program mac filter */ |
Jesse Brandeburg | 17652c6 | 2015-11-05 17:01:02 -0800 | [diff] [blame] | 571 | ret = i40e_sync_vsi_filters(vsi); |
Mitch Williams | fd1646e | 2014-02-13 03:48:44 -0800 | [diff] [blame] | 572 | if (ret) |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 573 | dev_err(&pf->pdev->dev, "Unable to program ucast filters\n"); |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 574 | |
Mitch Williams | 6b19289 | 2014-03-06 09:02:29 +0000 | [diff] [blame] | 575 | /* Set VF bandwidth if specified */ |
| 576 | if (vf->tx_rate) { |
| 577 | ret = i40e_aq_config_vsi_bw_limit(&pf->hw, vsi->seid, |
| 578 | vf->tx_rate / 50, 0, NULL); |
| 579 | if (ret) |
| 580 | dev_err(&pf->pdev->dev, "Unable to set tx rate, VF %d, error code %d.\n", |
| 581 | vf->vf_id, ret); |
| 582 | } |
| 583 | |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 584 | error_alloc_vsi_res: |
| 585 | return ret; |
| 586 | } |
| 587 | |
| 588 | /** |
Mitch Williams | 805bd5b | 2013-11-28 06:39:26 +0000 | [diff] [blame] | 589 | * i40e_enable_vf_mappings |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 590 | * @vf: pointer to the VF info |
Mitch Williams | 805bd5b | 2013-11-28 06:39:26 +0000 | [diff] [blame] | 591 | * |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 592 | * enable VF mappings |
Mitch Williams | 805bd5b | 2013-11-28 06:39:26 +0000 | [diff] [blame] | 593 | **/ |
| 594 | static void i40e_enable_vf_mappings(struct i40e_vf *vf) |
| 595 | { |
| 596 | struct i40e_pf *pf = vf->pf; |
| 597 | struct i40e_hw *hw = &pf->hw; |
| 598 | u32 reg, total_queue_pairs = 0; |
| 599 | int j; |
| 600 | |
| 601 | /* Tell the hardware we're using noncontiguous mapping. HW requires |
| 602 | * that VF queues be mapped using this method, even when they are |
| 603 | * contiguous in real life |
| 604 | */ |
| 605 | wr32(hw, I40E_VSILAN_QBASE(vf->lan_vsi_id), |
| 606 | I40E_VSILAN_QBASE_VSIQTABLE_ENA_MASK); |
| 607 | |
| 608 | /* enable VF vplan_qtable mappings */ |
| 609 | reg = I40E_VPLAN_MAPENA_TXRX_ENA_MASK; |
| 610 | wr32(hw, I40E_VPLAN_MAPENA(vf->vf_id), reg); |
| 611 | |
| 612 | /* map PF queues to VF queues */ |
Anjali Singhai Jain | fdf0e0b | 2015-03-31 00:45:05 -0700 | [diff] [blame] | 613 | for (j = 0; j < pf->vsi[vf->lan_vsi_idx]->alloc_queue_pairs; j++) { |
| 614 | u16 qid = i40e_vc_get_pf_queue_id(vf, vf->lan_vsi_id, j); |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 615 | |
Mitch Williams | 805bd5b | 2013-11-28 06:39:26 +0000 | [diff] [blame] | 616 | reg = (qid & I40E_VPLAN_QTABLE_QINDEX_MASK); |
| 617 | wr32(hw, I40E_VPLAN_QTABLE(total_queue_pairs, vf->vf_id), reg); |
| 618 | total_queue_pairs++; |
| 619 | } |
| 620 | |
| 621 | /* map PF queues to VSI */ |
| 622 | for (j = 0; j < 7; j++) { |
Anjali Singhai Jain | fdf0e0b | 2015-03-31 00:45:05 -0700 | [diff] [blame] | 623 | if (j * 2 >= pf->vsi[vf->lan_vsi_idx]->alloc_queue_pairs) { |
Mitch Williams | 805bd5b | 2013-11-28 06:39:26 +0000 | [diff] [blame] | 624 | reg = 0x07FF07FF; /* unused */ |
| 625 | } else { |
Anjali Singhai Jain | fdf0e0b | 2015-03-31 00:45:05 -0700 | [diff] [blame] | 626 | u16 qid = i40e_vc_get_pf_queue_id(vf, vf->lan_vsi_id, |
Mitch Williams | 805bd5b | 2013-11-28 06:39:26 +0000 | [diff] [blame] | 627 | j * 2); |
| 628 | reg = qid; |
Anjali Singhai Jain | fdf0e0b | 2015-03-31 00:45:05 -0700 | [diff] [blame] | 629 | qid = i40e_vc_get_pf_queue_id(vf, vf->lan_vsi_id, |
Mitch Williams | 805bd5b | 2013-11-28 06:39:26 +0000 | [diff] [blame] | 630 | (j * 2) + 1); |
| 631 | reg |= qid << 16; |
| 632 | } |
| 633 | wr32(hw, I40E_VSILAN_QTABLE(j, vf->lan_vsi_id), reg); |
| 634 | } |
| 635 | |
| 636 | i40e_flush(hw); |
| 637 | } |
| 638 | |
| 639 | /** |
| 640 | * i40e_disable_vf_mappings |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 641 | * @vf: pointer to the VF info |
Mitch Williams | 805bd5b | 2013-11-28 06:39:26 +0000 | [diff] [blame] | 642 | * |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 643 | * disable VF mappings |
Mitch Williams | 805bd5b | 2013-11-28 06:39:26 +0000 | [diff] [blame] | 644 | **/ |
| 645 | static void i40e_disable_vf_mappings(struct i40e_vf *vf) |
| 646 | { |
| 647 | struct i40e_pf *pf = vf->pf; |
| 648 | struct i40e_hw *hw = &pf->hw; |
| 649 | int i; |
| 650 | |
| 651 | /* disable qp mappings */ |
| 652 | wr32(hw, I40E_VPLAN_MAPENA(vf->vf_id), 0); |
| 653 | for (i = 0; i < I40E_MAX_VSI_QP; i++) |
| 654 | wr32(hw, I40E_VPLAN_QTABLE(i, vf->vf_id), |
| 655 | I40E_QUEUE_END_OF_LIST); |
| 656 | i40e_flush(hw); |
| 657 | } |
| 658 | |
| 659 | /** |
| 660 | * i40e_free_vf_res |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 661 | * @vf: pointer to the VF info |
Mitch Williams | 805bd5b | 2013-11-28 06:39:26 +0000 | [diff] [blame] | 662 | * |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 663 | * free VF resources |
Mitch Williams | 805bd5b | 2013-11-28 06:39:26 +0000 | [diff] [blame] | 664 | **/ |
| 665 | static void i40e_free_vf_res(struct i40e_vf *vf) |
| 666 | { |
| 667 | struct i40e_pf *pf = vf->pf; |
Mitch Williams | fc18eaa | 2013-11-28 06:39:27 +0000 | [diff] [blame] | 668 | struct i40e_hw *hw = &pf->hw; |
| 669 | u32 reg_idx, reg; |
| 670 | int i, msix_vf; |
Mitch Williams | 805bd5b | 2013-11-28 06:39:26 +0000 | [diff] [blame] | 671 | |
| 672 | /* free vsi & disconnect it from the parent uplink */ |
Anjali Singhai Jain | fdf0e0b | 2015-03-31 00:45:05 -0700 | [diff] [blame] | 673 | if (vf->lan_vsi_idx) { |
| 674 | i40e_vsi_release(pf->vsi[vf->lan_vsi_idx]); |
| 675 | vf->lan_vsi_idx = 0; |
Mitch Williams | 805bd5b | 2013-11-28 06:39:26 +0000 | [diff] [blame] | 676 | vf->lan_vsi_id = 0; |
| 677 | } |
Mitch Williams | 9347eb7 | 2014-02-11 08:26:32 +0000 | [diff] [blame] | 678 | msix_vf = pf->hw.func_caps.num_msix_vectors_vf; |
| 679 | |
Mitch Williams | fc18eaa | 2013-11-28 06:39:27 +0000 | [diff] [blame] | 680 | /* disable interrupts so the VF starts in a known state */ |
| 681 | for (i = 0; i < msix_vf; i++) { |
| 682 | /* format is same for both registers */ |
| 683 | if (0 == i) |
| 684 | reg_idx = I40E_VFINT_DYN_CTL0(vf->vf_id); |
| 685 | else |
| 686 | reg_idx = I40E_VFINT_DYN_CTLN(((msix_vf - 1) * |
| 687 | (vf->vf_id)) |
| 688 | + (i - 1)); |
| 689 | wr32(hw, reg_idx, I40E_VFINT_DYN_CTLN_CLEARPBA_MASK); |
| 690 | i40e_flush(hw); |
| 691 | } |
Mitch Williams | 805bd5b | 2013-11-28 06:39:26 +0000 | [diff] [blame] | 692 | |
Mitch Williams | fc18eaa | 2013-11-28 06:39:27 +0000 | [diff] [blame] | 693 | /* clear the irq settings */ |
| 694 | for (i = 0; i < msix_vf; i++) { |
| 695 | /* format is same for both registers */ |
| 696 | if (0 == i) |
| 697 | reg_idx = I40E_VPINT_LNKLST0(vf->vf_id); |
| 698 | else |
| 699 | reg_idx = I40E_VPINT_LNKLSTN(((msix_vf - 1) * |
| 700 | (vf->vf_id)) |
| 701 | + (i - 1)); |
| 702 | reg = (I40E_VPINT_LNKLSTN_FIRSTQ_TYPE_MASK | |
| 703 | I40E_VPINT_LNKLSTN_FIRSTQ_INDX_MASK); |
| 704 | wr32(hw, reg_idx, reg); |
| 705 | i40e_flush(hw); |
| 706 | } |
Mitch Williams | 805bd5b | 2013-11-28 06:39:26 +0000 | [diff] [blame] | 707 | /* reset some of the state varibles keeping |
| 708 | * track of the resources |
| 709 | */ |
| 710 | vf->num_queue_pairs = 0; |
| 711 | vf->vf_states = 0; |
Mitch Williams | 21be99e | 2015-08-31 19:54:48 -0400 | [diff] [blame] | 712 | clear_bit(I40E_VF_STAT_INIT, &vf->vf_states); |
Mitch Williams | 805bd5b | 2013-11-28 06:39:26 +0000 | [diff] [blame] | 713 | } |
| 714 | |
| 715 | /** |
| 716 | * i40e_alloc_vf_res |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 717 | * @vf: pointer to the VF info |
Mitch Williams | 805bd5b | 2013-11-28 06:39:26 +0000 | [diff] [blame] | 718 | * |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 719 | * allocate VF resources |
Mitch Williams | 805bd5b | 2013-11-28 06:39:26 +0000 | [diff] [blame] | 720 | **/ |
| 721 | static int i40e_alloc_vf_res(struct i40e_vf *vf) |
| 722 | { |
| 723 | struct i40e_pf *pf = vf->pf; |
| 724 | int total_queue_pairs = 0; |
| 725 | int ret; |
| 726 | |
| 727 | /* allocate hw vsi context & associated resources */ |
| 728 | ret = i40e_alloc_vsi_res(vf, I40E_VSI_SRIOV); |
| 729 | if (ret) |
| 730 | goto error_alloc; |
Anjali Singhai Jain | fdf0e0b | 2015-03-31 00:45:05 -0700 | [diff] [blame] | 731 | total_queue_pairs += pf->vsi[vf->lan_vsi_idx]->alloc_queue_pairs; |
Mitch Williams | 805bd5b | 2013-11-28 06:39:26 +0000 | [diff] [blame] | 732 | set_bit(I40E_VIRTCHNL_VF_CAP_PRIVILEGE, &vf->vf_caps); |
| 733 | |
| 734 | /* store the total qps number for the runtime |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 735 | * VF req validation |
Mitch Williams | 805bd5b | 2013-11-28 06:39:26 +0000 | [diff] [blame] | 736 | */ |
| 737 | vf->num_queue_pairs = total_queue_pairs; |
| 738 | |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 739 | /* VF is now completely initialized */ |
Mitch Williams | 805bd5b | 2013-11-28 06:39:26 +0000 | [diff] [blame] | 740 | set_bit(I40E_VF_STAT_INIT, &vf->vf_states); |
| 741 | |
| 742 | error_alloc: |
| 743 | if (ret) |
| 744 | i40e_free_vf_res(vf); |
| 745 | |
| 746 | return ret; |
| 747 | } |
| 748 | |
Mitch Williams | fc18eaa | 2013-11-28 06:39:27 +0000 | [diff] [blame] | 749 | #define VF_DEVICE_STATUS 0xAA |
| 750 | #define VF_TRANS_PENDING_MASK 0x20 |
| 751 | /** |
| 752 | * i40e_quiesce_vf_pci |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 753 | * @vf: pointer to the VF structure |
Mitch Williams | fc18eaa | 2013-11-28 06:39:27 +0000 | [diff] [blame] | 754 | * |
| 755 | * Wait for VF PCI transactions to be cleared after reset. Returns -EIO |
| 756 | * if the transactions never clear. |
| 757 | **/ |
| 758 | static int i40e_quiesce_vf_pci(struct i40e_vf *vf) |
| 759 | { |
| 760 | struct i40e_pf *pf = vf->pf; |
| 761 | struct i40e_hw *hw = &pf->hw; |
| 762 | int vf_abs_id, i; |
| 763 | u32 reg; |
| 764 | |
Mitch Williams | b141d61 | 2013-11-28 06:39:36 +0000 | [diff] [blame] | 765 | vf_abs_id = vf->vf_id + hw->func_caps.vf_base_id; |
Mitch Williams | fc18eaa | 2013-11-28 06:39:27 +0000 | [diff] [blame] | 766 | |
| 767 | wr32(hw, I40E_PF_PCI_CIAA, |
| 768 | VF_DEVICE_STATUS | (vf_abs_id << I40E_PF_PCI_CIAA_VF_NUM_SHIFT)); |
| 769 | for (i = 0; i < 100; i++) { |
| 770 | reg = rd32(hw, I40E_PF_PCI_CIAD); |
| 771 | if ((reg & VF_TRANS_PENDING_MASK) == 0) |
| 772 | return 0; |
| 773 | udelay(1); |
| 774 | } |
| 775 | return -EIO; |
| 776 | } |
| 777 | |
Mitch Williams | 805bd5b | 2013-11-28 06:39:26 +0000 | [diff] [blame] | 778 | /** |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 779 | * i40e_reset_vf |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 780 | * @vf: pointer to the VF structure |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 781 | * @flr: VFLR was issued or not |
| 782 | * |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 783 | * reset the VF |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 784 | **/ |
Mitch Williams | fc18eaa | 2013-11-28 06:39:27 +0000 | [diff] [blame] | 785 | void i40e_reset_vf(struct i40e_vf *vf, bool flr) |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 786 | { |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 787 | struct i40e_pf *pf = vf->pf; |
| 788 | struct i40e_hw *hw = &pf->hw; |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 789 | bool rsd = false; |
Mitch Williams | fc18eaa | 2013-11-28 06:39:27 +0000 | [diff] [blame] | 790 | int i; |
| 791 | u32 reg; |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 792 | |
Mitch Williams | 3ba9bcb | 2015-01-09 11:18:15 +0000 | [diff] [blame] | 793 | if (test_and_set_bit(__I40E_VF_DISABLE, &pf->state)) |
| 794 | return; |
| 795 | |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 796 | /* warn the VF */ |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 797 | clear_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states); |
| 798 | |
Mitch Williams | fc18eaa | 2013-11-28 06:39:27 +0000 | [diff] [blame] | 799 | /* In the case of a VFLR, the HW has already reset the VF and we |
| 800 | * just need to clean up, so don't hit the VFRTRIG register. |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 801 | */ |
| 802 | if (!flr) { |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 803 | /* reset VF using VPGEN_VFRTRIG reg */ |
Mitch Williams | fc18eaa | 2013-11-28 06:39:27 +0000 | [diff] [blame] | 804 | reg = rd32(hw, I40E_VPGEN_VFRTRIG(vf->vf_id)); |
| 805 | reg |= I40E_VPGEN_VFRTRIG_VFSWR_MASK; |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 806 | wr32(hw, I40E_VPGEN_VFRTRIG(vf->vf_id), reg); |
| 807 | i40e_flush(hw); |
| 808 | } |
| 809 | |
Mitch Williams | fc18eaa | 2013-11-28 06:39:27 +0000 | [diff] [blame] | 810 | if (i40e_quiesce_vf_pci(vf)) |
| 811 | dev_err(&pf->pdev->dev, "VF %d PCI transactions stuck\n", |
| 812 | vf->vf_id); |
| 813 | |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 814 | /* poll VPGEN_VFRSTAT reg to make sure |
| 815 | * that reset is complete |
| 816 | */ |
Mitch Williams | 1750a22 | 2015-01-09 11:18:13 +0000 | [diff] [blame] | 817 | for (i = 0; i < 10; i++) { |
| 818 | /* VF reset requires driver to first reset the VF and then |
| 819 | * poll the status register to make sure that the reset |
| 820 | * completed successfully. Due to internal HW FIFO flushes, |
| 821 | * we must wait 10ms before the register will be valid. |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 822 | */ |
Mitch Williams | 1750a22 | 2015-01-09 11:18:13 +0000 | [diff] [blame] | 823 | usleep_range(10000, 20000); |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 824 | reg = rd32(hw, I40E_VPGEN_VFRSTAT(vf->vf_id)); |
| 825 | if (reg & I40E_VPGEN_VFRSTAT_VFRD_MASK) { |
| 826 | rsd = true; |
| 827 | break; |
| 828 | } |
| 829 | } |
| 830 | |
Anjali Singhai Jain | 57175ac | 2015-04-07 19:45:35 -0400 | [diff] [blame] | 831 | if (flr) |
| 832 | usleep_range(10000, 20000); |
| 833 | |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 834 | if (!rsd) |
Mitch Williams | fc18eaa | 2013-11-28 06:39:27 +0000 | [diff] [blame] | 835 | dev_err(&pf->pdev->dev, "VF reset check timeout on VF %d\n", |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 836 | vf->vf_id); |
Mitch Williams | fc18eaa | 2013-11-28 06:39:27 +0000 | [diff] [blame] | 837 | wr32(hw, I40E_VFGEN_RSTAT1(vf->vf_id), I40E_VFR_COMPLETED); |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 838 | /* clear the reset bit in the VPGEN_VFRTRIG reg */ |
| 839 | reg = rd32(hw, I40E_VPGEN_VFRTRIG(vf->vf_id)); |
| 840 | reg &= ~I40E_VPGEN_VFRTRIG_VFSWR_MASK; |
| 841 | wr32(hw, I40E_VPGEN_VFRTRIG(vf->vf_id), reg); |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 842 | |
Mitch Williams | fc18eaa | 2013-11-28 06:39:27 +0000 | [diff] [blame] | 843 | /* On initial reset, we won't have any queues */ |
Anjali Singhai Jain | fdf0e0b | 2015-03-31 00:45:05 -0700 | [diff] [blame] | 844 | if (vf->lan_vsi_idx == 0) |
Mitch Williams | fc18eaa | 2013-11-28 06:39:27 +0000 | [diff] [blame] | 845 | goto complete_reset; |
| 846 | |
Anjali Singhai Jain | fdf0e0b | 2015-03-31 00:45:05 -0700 | [diff] [blame] | 847 | i40e_vsi_control_rings(pf->vsi[vf->lan_vsi_idx], false); |
Mitch Williams | fc18eaa | 2013-11-28 06:39:27 +0000 | [diff] [blame] | 848 | complete_reset: |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 849 | /* reallocate VF resources to reset the VSI state */ |
Mitch Williams | fc18eaa | 2013-11-28 06:39:27 +0000 | [diff] [blame] | 850 | i40e_free_vf_res(vf); |
Mitch Williams | 21be99e | 2015-08-31 19:54:48 -0400 | [diff] [blame] | 851 | if (!i40e_alloc_vf_res(vf)) { |
| 852 | i40e_enable_vf_mappings(vf); |
| 853 | set_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states); |
| 854 | clear_bit(I40E_VF_STAT_DISABLED, &vf->vf_states); |
| 855 | } |
Mitch Williams | fc18eaa | 2013-11-28 06:39:27 +0000 | [diff] [blame] | 856 | /* tell the VF the reset is done */ |
| 857 | wr32(hw, I40E_VFGEN_RSTAT1(vf->vf_id), I40E_VFR_VFACTIVE); |
| 858 | i40e_flush(hw); |
Mitch Williams | 3ba9bcb | 2015-01-09 11:18:15 +0000 | [diff] [blame] | 859 | clear_bit(__I40E_VF_DISABLE, &pf->state); |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 860 | } |
Greg Rose | c354229 | 2013-12-13 08:38:38 +0000 | [diff] [blame] | 861 | |
| 862 | /** |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 863 | * i40e_free_vfs |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 864 | * @pf: pointer to the PF structure |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 865 | * |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 866 | * free VF resources |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 867 | **/ |
| 868 | void i40e_free_vfs(struct i40e_pf *pf) |
| 869 | { |
Mitch Williams | f741453 | 2013-11-28 06:39:40 +0000 | [diff] [blame] | 870 | struct i40e_hw *hw = &pf->hw; |
| 871 | u32 reg_idx, bit_idx; |
| 872 | int i, tmp, vf_id; |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 873 | |
| 874 | if (!pf->vf) |
| 875 | return; |
Mitch Williams | 3ba9bcb | 2015-01-09 11:18:15 +0000 | [diff] [blame] | 876 | while (test_and_set_bit(__I40E_VF_DISABLE, &pf->state)) |
| 877 | usleep_range(1000, 2000); |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 878 | |
Mitch Williams | 4443463 | 2015-04-07 11:32:55 -0700 | [diff] [blame] | 879 | for (i = 0; i < pf->num_alloc_vfs; i++) |
| 880 | if (test_bit(I40E_VF_STAT_INIT, &pf->vf[i].vf_states)) |
| 881 | i40e_vsi_control_rings(pf->vsi[pf->vf[i].lan_vsi_idx], |
| 882 | false); |
| 883 | |
Mitch Williams | 0325fca | 2015-08-26 15:14:09 -0400 | [diff] [blame] | 884 | for (i = 0; i < pf->num_alloc_vfs; i++) |
| 885 | if (test_bit(I40E_VF_STAT_INIT, &pf->vf[i].vf_states)) |
| 886 | i40e_vsi_control_rings(pf->vsi[pf->vf[i].lan_vsi_idx], |
| 887 | false); |
| 888 | |
Mitch A Williams | 6a9ddb3 | 2014-12-09 08:53:01 +0000 | [diff] [blame] | 889 | /* Disable IOV before freeing resources. This lets any VF drivers |
| 890 | * running in the host get themselves cleaned up before we yank |
| 891 | * the carpet out from underneath their feet. |
| 892 | */ |
| 893 | if (!pci_vfs_assigned(pf->pdev)) |
| 894 | pci_disable_sriov(pf->pdev); |
Mitch Williams | 6d7b967 | 2015-03-31 00:45:02 -0700 | [diff] [blame] | 895 | else |
| 896 | dev_warn(&pf->pdev->dev, "VFs are assigned - not disabling SR-IOV\n"); |
Mitch A Williams | 6a9ddb3 | 2014-12-09 08:53:01 +0000 | [diff] [blame] | 897 | |
| 898 | msleep(20); /* let any messages in transit get finished up */ |
| 899 | |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 900 | /* free up VF resources */ |
Mitch Williams | 6c1b5bf | 2013-11-28 06:39:30 +0000 | [diff] [blame] | 901 | tmp = pf->num_alloc_vfs; |
| 902 | pf->num_alloc_vfs = 0; |
| 903 | for (i = 0; i < tmp; i++) { |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 904 | if (test_bit(I40E_VF_STAT_INIT, &pf->vf[i].vf_states)) |
| 905 | i40e_free_vf_res(&pf->vf[i]); |
| 906 | /* disable qp mappings */ |
| 907 | i40e_disable_vf_mappings(&pf->vf[i]); |
| 908 | } |
| 909 | |
| 910 | kfree(pf->vf); |
| 911 | pf->vf = NULL; |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 912 | |
Mitch Williams | 9e5634d | 2014-04-04 04:43:14 +0000 | [diff] [blame] | 913 | /* This check is for when the driver is unloaded while VFs are |
| 914 | * assigned. Setting the number of VFs to 0 through sysfs is caught |
| 915 | * before this function ever gets called. |
| 916 | */ |
Ethan Zhao | c24817b | 2014-07-22 18:36:43 +0000 | [diff] [blame] | 917 | if (!pci_vfs_assigned(pf->pdev)) { |
Mitch Williams | f741453 | 2013-11-28 06:39:40 +0000 | [diff] [blame] | 918 | /* Acknowledge VFLR for all VFS. Without this, VFs will fail to |
| 919 | * work correctly when SR-IOV gets re-enabled. |
| 920 | */ |
| 921 | for (vf_id = 0; vf_id < tmp; vf_id++) { |
| 922 | reg_idx = (hw->func_caps.vf_base_id + vf_id) / 32; |
| 923 | bit_idx = (hw->func_caps.vf_base_id + vf_id) % 32; |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 924 | wr32(hw, I40E_GLGEN_VFLRSTAT(reg_idx), BIT(bit_idx)); |
Mitch Williams | f741453 | 2013-11-28 06:39:40 +0000 | [diff] [blame] | 925 | } |
Greg Rose | c354229 | 2013-12-13 08:38:38 +0000 | [diff] [blame] | 926 | } |
Mitch Williams | 3ba9bcb | 2015-01-09 11:18:15 +0000 | [diff] [blame] | 927 | clear_bit(__I40E_VF_DISABLE, &pf->state); |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 928 | } |
| 929 | |
| 930 | #ifdef CONFIG_PCI_IOV |
| 931 | /** |
| 932 | * i40e_alloc_vfs |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 933 | * @pf: pointer to the PF structure |
| 934 | * @num_alloc_vfs: number of VFs to allocate |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 935 | * |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 936 | * allocate VF resources |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 937 | **/ |
Mitch Williams | 4aeec01 | 2014-02-13 03:48:47 -0800 | [diff] [blame] | 938 | int i40e_alloc_vfs(struct i40e_pf *pf, u16 num_alloc_vfs) |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 939 | { |
| 940 | struct i40e_vf *vfs; |
| 941 | int i, ret = 0; |
| 942 | |
Mitch Williams | 6c1b5bf | 2013-11-28 06:39:30 +0000 | [diff] [blame] | 943 | /* Disable interrupt 0 so we don't try to handle the VFLR. */ |
Mitch Williams | 2ef28cf | 2013-11-28 06:39:32 +0000 | [diff] [blame] | 944 | i40e_irq_dynamic_disable_icr0(pf); |
| 945 | |
Mitch Williams | 4aeec01 | 2014-02-13 03:48:47 -0800 | [diff] [blame] | 946 | /* Check to see if we're just allocating resources for extant VFs */ |
| 947 | if (pci_num_vf(pf->pdev) != num_alloc_vfs) { |
| 948 | ret = pci_enable_sriov(pf->pdev, num_alloc_vfs); |
| 949 | if (ret) { |
Akeem G Abodunrin | de445b3 | 2015-10-01 14:37:40 -0400 | [diff] [blame] | 950 | pf->flags &= ~I40E_FLAG_VEB_MODE_ENABLED; |
Mitch Williams | 4aeec01 | 2014-02-13 03:48:47 -0800 | [diff] [blame] | 951 | pf->num_alloc_vfs = 0; |
| 952 | goto err_iov; |
| 953 | } |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 954 | } |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 955 | /* allocate memory */ |
Akeem G Abodunrin | cc6456a | 2014-02-06 05:51:02 +0000 | [diff] [blame] | 956 | vfs = kcalloc(num_alloc_vfs, sizeof(struct i40e_vf), GFP_KERNEL); |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 957 | if (!vfs) { |
| 958 | ret = -ENOMEM; |
| 959 | goto err_alloc; |
| 960 | } |
Mitch Williams | c674d12 | 2014-05-20 08:01:40 +0000 | [diff] [blame] | 961 | pf->vf = vfs; |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 962 | |
| 963 | /* apply default profile */ |
| 964 | for (i = 0; i < num_alloc_vfs; i++) { |
| 965 | vfs[i].pf = pf; |
| 966 | vfs[i].parent_type = I40E_SWITCH_ELEMENT_TYPE_VEB; |
| 967 | vfs[i].vf_id = i; |
| 968 | |
| 969 | /* assign default capabilities */ |
| 970 | set_bit(I40E_VIRTCHNL_VF_CAP_L2, &vfs[i].vf_caps); |
Mitch Williams | c674d12 | 2014-05-20 08:01:40 +0000 | [diff] [blame] | 971 | vfs[i].spoofchk = true; |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 972 | /* VF resources get allocated during reset */ |
Mitch Williams | fc18eaa | 2013-11-28 06:39:27 +0000 | [diff] [blame] | 973 | i40e_reset_vf(&vfs[i], false); |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 974 | |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 975 | } |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 976 | pf->num_alloc_vfs = num_alloc_vfs; |
| 977 | |
| 978 | err_alloc: |
| 979 | if (ret) |
| 980 | i40e_free_vfs(pf); |
| 981 | err_iov: |
Mitch Williams | 6c1b5bf | 2013-11-28 06:39:30 +0000 | [diff] [blame] | 982 | /* Re-enable interrupt 0. */ |
Mitch Williams | 2ef28cf | 2013-11-28 06:39:32 +0000 | [diff] [blame] | 983 | i40e_irq_dynamic_enable_icr0(pf); |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 984 | return ret; |
| 985 | } |
| 986 | |
| 987 | #endif |
| 988 | /** |
| 989 | * i40e_pci_sriov_enable |
| 990 | * @pdev: pointer to a pci_dev structure |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 991 | * @num_vfs: number of VFs to allocate |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 992 | * |
| 993 | * Enable or change the number of VFs |
| 994 | **/ |
| 995 | static int i40e_pci_sriov_enable(struct pci_dev *pdev, int num_vfs) |
| 996 | { |
| 997 | #ifdef CONFIG_PCI_IOV |
| 998 | struct i40e_pf *pf = pci_get_drvdata(pdev); |
| 999 | int pre_existing_vfs = pci_num_vf(pdev); |
| 1000 | int err = 0; |
| 1001 | |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 1002 | if (test_bit(__I40E_TESTING, &pf->state)) { |
Greg Rose | e17bc41 | 2015-04-16 20:05:59 -0400 | [diff] [blame] | 1003 | dev_warn(&pdev->dev, |
| 1004 | "Cannot enable SR-IOV virtual functions while the device is undergoing diagnostic testing\n"); |
| 1005 | err = -EPERM; |
| 1006 | goto err_out; |
| 1007 | } |
| 1008 | |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1009 | if (pre_existing_vfs && pre_existing_vfs != num_vfs) |
| 1010 | i40e_free_vfs(pf); |
| 1011 | else if (pre_existing_vfs && pre_existing_vfs == num_vfs) |
| 1012 | goto out; |
| 1013 | |
| 1014 | if (num_vfs > pf->num_req_vfs) { |
Mitch Williams | 96c8d07 | 2015-08-27 11:42:35 -0400 | [diff] [blame] | 1015 | dev_warn(&pdev->dev, "Unable to enable %d VFs. Limited to %d VFs due to device resource constraints.\n", |
| 1016 | num_vfs, pf->num_req_vfs); |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1017 | err = -EPERM; |
| 1018 | goto err_out; |
| 1019 | } |
| 1020 | |
Mitch Williams | 96c8d07 | 2015-08-27 11:42:35 -0400 | [diff] [blame] | 1021 | dev_info(&pdev->dev, "Allocating %d VFs.\n", num_vfs); |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1022 | err = i40e_alloc_vfs(pf, num_vfs); |
| 1023 | if (err) { |
| 1024 | dev_warn(&pdev->dev, "Failed to enable SR-IOV: %d\n", err); |
| 1025 | goto err_out; |
| 1026 | } |
| 1027 | |
| 1028 | out: |
| 1029 | return num_vfs; |
| 1030 | |
| 1031 | err_out: |
| 1032 | return err; |
| 1033 | #endif |
| 1034 | return 0; |
| 1035 | } |
| 1036 | |
| 1037 | /** |
| 1038 | * i40e_pci_sriov_configure |
| 1039 | * @pdev: pointer to a pci_dev structure |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 1040 | * @num_vfs: number of VFs to allocate |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1041 | * |
| 1042 | * Enable or change the number of VFs. Called when the user updates the number |
| 1043 | * of VFs in sysfs. |
| 1044 | **/ |
| 1045 | int i40e_pci_sriov_configure(struct pci_dev *pdev, int num_vfs) |
| 1046 | { |
| 1047 | struct i40e_pf *pf = pci_get_drvdata(pdev); |
| 1048 | |
Anjali Singhai Jain | fc60861 | 2015-05-08 15:35:57 -0700 | [diff] [blame] | 1049 | if (num_vfs) { |
| 1050 | if (!(pf->flags & I40E_FLAG_VEB_MODE_ENABLED)) { |
| 1051 | pf->flags |= I40E_FLAG_VEB_MODE_ENABLED; |
| 1052 | i40e_do_reset_safe(pf, |
| 1053 | BIT_ULL(__I40E_PF_RESET_REQUESTED)); |
| 1054 | } |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1055 | return i40e_pci_sriov_enable(pdev, num_vfs); |
Anjali Singhai Jain | fc60861 | 2015-05-08 15:35:57 -0700 | [diff] [blame] | 1056 | } |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1057 | |
Ethan Zhao | c24817b | 2014-07-22 18:36:43 +0000 | [diff] [blame] | 1058 | if (!pci_vfs_assigned(pf->pdev)) { |
Mitch Williams | 9e5634d | 2014-04-04 04:43:14 +0000 | [diff] [blame] | 1059 | i40e_free_vfs(pf); |
Anjali Singhai Jain | fc60861 | 2015-05-08 15:35:57 -0700 | [diff] [blame] | 1060 | pf->flags &= ~I40E_FLAG_VEB_MODE_ENABLED; |
| 1061 | i40e_do_reset_safe(pf, BIT_ULL(__I40E_PF_RESET_REQUESTED)); |
Mitch Williams | 9e5634d | 2014-04-04 04:43:14 +0000 | [diff] [blame] | 1062 | } else { |
| 1063 | dev_warn(&pdev->dev, "Unable to free VFs because some are assigned to VMs.\n"); |
| 1064 | return -EINVAL; |
| 1065 | } |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1066 | return 0; |
| 1067 | } |
| 1068 | |
| 1069 | /***********************virtual channel routines******************/ |
| 1070 | |
| 1071 | /** |
| 1072 | * i40e_vc_send_msg_to_vf |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 1073 | * @vf: pointer to the VF info |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1074 | * @v_opcode: virtual channel opcode |
| 1075 | * @v_retval: virtual channel return value |
| 1076 | * @msg: pointer to the msg buffer |
| 1077 | * @msglen: msg length |
| 1078 | * |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 1079 | * send msg to VF |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1080 | **/ |
| 1081 | static int i40e_vc_send_msg_to_vf(struct i40e_vf *vf, u32 v_opcode, |
| 1082 | u32 v_retval, u8 *msg, u16 msglen) |
| 1083 | { |
Anjali Singhai Jain | 6e7b5bd | 2014-07-10 07:58:21 +0000 | [diff] [blame] | 1084 | struct i40e_pf *pf; |
| 1085 | struct i40e_hw *hw; |
| 1086 | int abs_vf_id; |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1087 | i40e_status aq_ret; |
| 1088 | |
Anjali Singhai Jain | 6e7b5bd | 2014-07-10 07:58:21 +0000 | [diff] [blame] | 1089 | /* validate the request */ |
| 1090 | if (!vf || vf->vf_id >= vf->pf->num_alloc_vfs) |
| 1091 | return -EINVAL; |
| 1092 | |
| 1093 | pf = vf->pf; |
| 1094 | hw = &pf->hw; |
| 1095 | abs_vf_id = vf->vf_id + hw->func_caps.vf_base_id; |
| 1096 | |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1097 | /* single place to detect unsuccessful return values */ |
| 1098 | if (v_retval) { |
| 1099 | vf->num_invalid_msgs++; |
Mitch Williams | e7ffb72 | 2015-10-26 19:44:37 -0400 | [diff] [blame] | 1100 | dev_err(&pf->pdev->dev, "VF %d failed opcode %d, error: %d\n", |
| 1101 | vf->vf_id, v_opcode, v_retval); |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1102 | if (vf->num_invalid_msgs > |
| 1103 | I40E_DEFAULT_NUM_INVALID_MSGS_ALLOWED) { |
| 1104 | dev_err(&pf->pdev->dev, |
| 1105 | "Number of invalid messages exceeded for VF %d\n", |
| 1106 | vf->vf_id); |
| 1107 | dev_err(&pf->pdev->dev, "Use PF Control I/F to enable the VF\n"); |
| 1108 | set_bit(I40E_VF_STAT_DISABLED, &vf->vf_states); |
| 1109 | } |
| 1110 | } else { |
| 1111 | vf->num_valid_msgs++; |
Jingjing Wu | 5d38c93 | 2015-09-28 14:12:39 -0400 | [diff] [blame] | 1112 | /* reset the invalid counter, if a valid message is received. */ |
| 1113 | vf->num_invalid_msgs = 0; |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1114 | } |
| 1115 | |
Ashish Shah | f19efbb | 2014-08-01 13:27:06 -0700 | [diff] [blame] | 1116 | aq_ret = i40e_aq_send_msg_to_vf(hw, abs_vf_id, v_opcode, v_retval, |
Mitch Williams | 7efa84b | 2013-11-28 06:39:41 +0000 | [diff] [blame] | 1117 | msg, msglen, NULL); |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1118 | if (aq_ret) { |
| 1119 | dev_err(&pf->pdev->dev, |
| 1120 | "Unable to send the message to VF %d aq_err %d\n", |
| 1121 | vf->vf_id, pf->hw.aq.asq_last_status); |
| 1122 | return -EIO; |
| 1123 | } |
| 1124 | |
| 1125 | return 0; |
| 1126 | } |
| 1127 | |
| 1128 | /** |
| 1129 | * i40e_vc_send_resp_to_vf |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 1130 | * @vf: pointer to the VF info |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1131 | * @opcode: operation code |
| 1132 | * @retval: return value |
| 1133 | * |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 1134 | * send resp msg to VF |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1135 | **/ |
| 1136 | static int i40e_vc_send_resp_to_vf(struct i40e_vf *vf, |
| 1137 | enum i40e_virtchnl_ops opcode, |
| 1138 | i40e_status retval) |
| 1139 | { |
| 1140 | return i40e_vc_send_msg_to_vf(vf, opcode, retval, NULL, 0); |
| 1141 | } |
| 1142 | |
| 1143 | /** |
| 1144 | * i40e_vc_get_version_msg |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 1145 | * @vf: pointer to the VF info |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1146 | * |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 1147 | * called from the VF to request the API version used by the PF |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1148 | **/ |
Mitch Williams | f4ca1a2 | 2015-06-04 16:23:57 -0400 | [diff] [blame] | 1149 | static int i40e_vc_get_version_msg(struct i40e_vf *vf, u8 *msg) |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1150 | { |
| 1151 | struct i40e_virtchnl_version_info info = { |
| 1152 | I40E_VIRTCHNL_VERSION_MAJOR, I40E_VIRTCHNL_VERSION_MINOR |
| 1153 | }; |
| 1154 | |
Mitch Williams | f4ca1a2 | 2015-06-04 16:23:57 -0400 | [diff] [blame] | 1155 | vf->vf_ver = *(struct i40e_virtchnl_version_info *)msg; |
Mitch Williams | 606a548 | 2015-06-04 16:24:00 -0400 | [diff] [blame] | 1156 | /* VFs running the 1.0 API expect to get 1.0 back or they will cry. */ |
| 1157 | if (VF_IS_V10(vf)) |
| 1158 | info.minor = I40E_VIRTCHNL_VERSION_MINOR_NO_VF_CAPS; |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1159 | return i40e_vc_send_msg_to_vf(vf, I40E_VIRTCHNL_OP_VERSION, |
| 1160 | I40E_SUCCESS, (u8 *)&info, |
| 1161 | sizeof(struct |
| 1162 | i40e_virtchnl_version_info)); |
| 1163 | } |
| 1164 | |
| 1165 | /** |
| 1166 | * i40e_vc_get_vf_resources_msg |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 1167 | * @vf: pointer to the VF info |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1168 | * @msg: pointer to the msg buffer |
| 1169 | * @msglen: msg length |
| 1170 | * |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 1171 | * called from the VF to request its resources |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1172 | **/ |
Mitch Williams | f4ca1a2 | 2015-06-04 16:23:57 -0400 | [diff] [blame] | 1173 | static int i40e_vc_get_vf_resources_msg(struct i40e_vf *vf, u8 *msg) |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1174 | { |
| 1175 | struct i40e_virtchnl_vf_resource *vfres = NULL; |
| 1176 | struct i40e_pf *pf = vf->pf; |
| 1177 | i40e_status aq_ret = 0; |
| 1178 | struct i40e_vsi *vsi; |
| 1179 | int i = 0, len = 0; |
| 1180 | int num_vsis = 1; |
| 1181 | int ret; |
| 1182 | |
| 1183 | if (!test_bit(I40E_VF_STAT_INIT, &vf->vf_states)) { |
| 1184 | aq_ret = I40E_ERR_PARAM; |
| 1185 | goto err; |
| 1186 | } |
| 1187 | |
| 1188 | len = (sizeof(struct i40e_virtchnl_vf_resource) + |
| 1189 | sizeof(struct i40e_virtchnl_vsi_resource) * num_vsis); |
| 1190 | |
| 1191 | vfres = kzalloc(len, GFP_KERNEL); |
| 1192 | if (!vfres) { |
| 1193 | aq_ret = I40E_ERR_NO_MEMORY; |
| 1194 | len = 0; |
| 1195 | goto err; |
| 1196 | } |
Mitch Williams | f4ca1a2 | 2015-06-04 16:23:57 -0400 | [diff] [blame] | 1197 | if (VF_IS_V11(vf)) |
| 1198 | vf->driver_caps = *(u32 *)msg; |
| 1199 | else |
| 1200 | vf->driver_caps = I40E_VIRTCHNL_VF_OFFLOAD_L2 | |
| 1201 | I40E_VIRTCHNL_VF_OFFLOAD_RSS_REG | |
| 1202 | I40E_VIRTCHNL_VF_OFFLOAD_VLAN; |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1203 | |
| 1204 | vfres->vf_offload_flags = I40E_VIRTCHNL_VF_OFFLOAD_L2; |
Anjali Singhai Jain | fdf0e0b | 2015-03-31 00:45:05 -0700 | [diff] [blame] | 1205 | vsi = pf->vsi[vf->lan_vsi_idx]; |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1206 | if (!vsi->info.pvid) |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 1207 | vfres->vf_offload_flags |= I40E_VIRTCHNL_VF_OFFLOAD_VLAN; |
| 1208 | if (pf->flags & I40E_FLAG_RSS_AQ_CAPABLE) { |
| 1209 | if (vf->driver_caps & I40E_VIRTCHNL_VF_OFFLOAD_RSS_AQ) |
| 1210 | vfres->vf_offload_flags |= |
| 1211 | I40E_VIRTCHNL_VF_OFFLOAD_RSS_AQ; |
| 1212 | } else { |
| 1213 | vfres->vf_offload_flags |= I40E_VIRTCHNL_VF_OFFLOAD_RSS_REG; |
| 1214 | } |
Anjali Singhai Jain | 1f01227 | 2015-09-03 17:18:53 -0400 | [diff] [blame] | 1215 | |
Anjali Singhai Jain | 3d0da5b | 2015-12-22 14:25:05 -0800 | [diff] [blame^] | 1216 | if (pf->flags & I40E_FLAG_MULTIPLE_TCP_UDP_RSS_PCTYPE) { |
| 1217 | if (vf->driver_caps & I40E_VIRTCHNL_VF_OFFLOAD_RSS_PCTYPE_V2) |
| 1218 | vfres->vf_offload_flags |= |
| 1219 | I40E_VIRTCHNL_VF_OFFLOAD_RSS_PCTYPE_V2; |
| 1220 | } |
| 1221 | |
Anjali Singhai Jain | 1f01227 | 2015-09-03 17:18:53 -0400 | [diff] [blame] | 1222 | if (vf->driver_caps & I40E_VIRTCHNL_VF_OFFLOAD_RX_POLLING) |
| 1223 | vfres->vf_offload_flags |= I40E_VIRTCHNL_VF_OFFLOAD_RX_POLLING; |
| 1224 | |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1225 | vfres->num_vsis = num_vsis; |
| 1226 | vfres->num_queue_pairs = vf->num_queue_pairs; |
| 1227 | vfres->max_vectors = pf->hw.func_caps.num_msix_vectors_vf; |
Anjali Singhai Jain | fdf0e0b | 2015-03-31 00:45:05 -0700 | [diff] [blame] | 1228 | if (vf->lan_vsi_idx) { |
| 1229 | vfres->vsi_res[i].vsi_id = vf->lan_vsi_id; |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1230 | vfres->vsi_res[i].vsi_type = I40E_VSI_SRIOV; |
Mitch Williams | f578f5f | 2015-08-28 17:55:58 -0400 | [diff] [blame] | 1231 | vfres->vsi_res[i].num_queue_pairs = vsi->alloc_queue_pairs; |
| 1232 | /* VFs only use TC 0 */ |
| 1233 | vfres->vsi_res[i].qset_handle |
| 1234 | = le16_to_cpu(vsi->info.qs_handle[0]); |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 1235 | ether_addr_copy(vfres->vsi_res[i].default_mac_addr, |
| 1236 | vf->default_lan_addr.addr); |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1237 | i++; |
| 1238 | } |
| 1239 | set_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states); |
| 1240 | |
| 1241 | err: |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 1242 | /* send the response back to the VF */ |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1243 | ret = i40e_vc_send_msg_to_vf(vf, I40E_VIRTCHNL_OP_GET_VF_RESOURCES, |
| 1244 | aq_ret, (u8 *)vfres, len); |
| 1245 | |
| 1246 | kfree(vfres); |
| 1247 | return ret; |
| 1248 | } |
| 1249 | |
| 1250 | /** |
| 1251 | * i40e_vc_reset_vf_msg |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 1252 | * @vf: pointer to the VF info |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1253 | * @msg: pointer to the msg buffer |
| 1254 | * @msglen: msg length |
| 1255 | * |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 1256 | * called from the VF to reset itself, |
| 1257 | * unlike other virtchnl messages, PF driver |
| 1258 | * doesn't send the response back to the VF |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1259 | **/ |
Mitch Williams | fc18eaa | 2013-11-28 06:39:27 +0000 | [diff] [blame] | 1260 | static void i40e_vc_reset_vf_msg(struct i40e_vf *vf) |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1261 | { |
Mitch Williams | fc18eaa | 2013-11-28 06:39:27 +0000 | [diff] [blame] | 1262 | if (test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states)) |
| 1263 | i40e_reset_vf(vf, false); |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1264 | } |
| 1265 | |
| 1266 | /** |
| 1267 | * i40e_vc_config_promiscuous_mode_msg |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 1268 | * @vf: pointer to the VF info |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1269 | * @msg: pointer to the msg buffer |
| 1270 | * @msglen: msg length |
| 1271 | * |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 1272 | * called from the VF to configure the promiscuous mode of |
| 1273 | * VF vsis |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1274 | **/ |
| 1275 | static int i40e_vc_config_promiscuous_mode_msg(struct i40e_vf *vf, |
| 1276 | u8 *msg, u16 msglen) |
| 1277 | { |
| 1278 | struct i40e_virtchnl_promisc_info *info = |
| 1279 | (struct i40e_virtchnl_promisc_info *)msg; |
| 1280 | struct i40e_pf *pf = vf->pf; |
| 1281 | struct i40e_hw *hw = &pf->hw; |
Ashish Shah | 89cb86c | 2014-08-01 13:27:10 -0700 | [diff] [blame] | 1282 | struct i40e_vsi *vsi; |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1283 | bool allmulti = false; |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1284 | i40e_status aq_ret; |
| 1285 | |
Anjali Singhai Jain | fdf0e0b | 2015-03-31 00:45:05 -0700 | [diff] [blame] | 1286 | vsi = i40e_find_vsi_from_id(pf, info->vsi_id); |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1287 | if (!test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states) || |
| 1288 | !test_bit(I40E_VIRTCHNL_VF_CAP_PRIVILEGE, &vf->vf_caps) || |
| 1289 | !i40e_vc_isvalid_vsi_id(vf, info->vsi_id) || |
Anjali Singhai Jain | fdf0e0b | 2015-03-31 00:45:05 -0700 | [diff] [blame] | 1290 | (vsi->type != I40E_VSI_FCOE)) { |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1291 | aq_ret = I40E_ERR_PARAM; |
| 1292 | goto error_param; |
| 1293 | } |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1294 | if (info->flags & I40E_FLAG_VF_MULTICAST_PROMISC) |
| 1295 | allmulti = true; |
Ashish Shah | 89cb86c | 2014-08-01 13:27:10 -0700 | [diff] [blame] | 1296 | aq_ret = i40e_aq_set_vsi_multicast_promiscuous(hw, vsi->seid, |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1297 | allmulti, NULL); |
| 1298 | |
| 1299 | error_param: |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 1300 | /* send the response to the VF */ |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1301 | return i40e_vc_send_resp_to_vf(vf, |
| 1302 | I40E_VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE, |
| 1303 | aq_ret); |
| 1304 | } |
| 1305 | |
| 1306 | /** |
| 1307 | * i40e_vc_config_queues_msg |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 1308 | * @vf: pointer to the VF info |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1309 | * @msg: pointer to the msg buffer |
| 1310 | * @msglen: msg length |
| 1311 | * |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 1312 | * called from the VF to configure the rx/tx |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1313 | * queues |
| 1314 | **/ |
| 1315 | static int i40e_vc_config_queues_msg(struct i40e_vf *vf, u8 *msg, u16 msglen) |
| 1316 | { |
| 1317 | struct i40e_virtchnl_vsi_queue_config_info *qci = |
| 1318 | (struct i40e_virtchnl_vsi_queue_config_info *)msg; |
| 1319 | struct i40e_virtchnl_queue_pair_info *qpi; |
Ashish Shah | 5f5e33b | 2014-07-10 07:58:15 +0000 | [diff] [blame] | 1320 | struct i40e_pf *pf = vf->pf; |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1321 | u16 vsi_id, vsi_queue_id; |
| 1322 | i40e_status aq_ret = 0; |
| 1323 | int i; |
| 1324 | |
| 1325 | if (!test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states)) { |
| 1326 | aq_ret = I40E_ERR_PARAM; |
| 1327 | goto error_param; |
| 1328 | } |
| 1329 | |
| 1330 | vsi_id = qci->vsi_id; |
| 1331 | if (!i40e_vc_isvalid_vsi_id(vf, vsi_id)) { |
| 1332 | aq_ret = I40E_ERR_PARAM; |
| 1333 | goto error_param; |
| 1334 | } |
| 1335 | for (i = 0; i < qci->num_queue_pairs; i++) { |
| 1336 | qpi = &qci->qpair[i]; |
| 1337 | vsi_queue_id = qpi->txq.queue_id; |
| 1338 | if ((qpi->txq.vsi_id != vsi_id) || |
| 1339 | (qpi->rxq.vsi_id != vsi_id) || |
| 1340 | (qpi->rxq.queue_id != vsi_queue_id) || |
| 1341 | !i40e_vc_isvalid_queue_id(vf, vsi_id, vsi_queue_id)) { |
| 1342 | aq_ret = I40E_ERR_PARAM; |
| 1343 | goto error_param; |
| 1344 | } |
| 1345 | |
| 1346 | if (i40e_config_vsi_rx_queue(vf, vsi_id, vsi_queue_id, |
| 1347 | &qpi->rxq) || |
| 1348 | i40e_config_vsi_tx_queue(vf, vsi_id, vsi_queue_id, |
| 1349 | &qpi->txq)) { |
| 1350 | aq_ret = I40E_ERR_PARAM; |
| 1351 | goto error_param; |
| 1352 | } |
| 1353 | } |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 1354 | /* set vsi num_queue_pairs in use to num configured by VF */ |
Anjali Singhai Jain | fdf0e0b | 2015-03-31 00:45:05 -0700 | [diff] [blame] | 1355 | pf->vsi[vf->lan_vsi_idx]->num_queue_pairs = qci->num_queue_pairs; |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1356 | |
| 1357 | error_param: |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 1358 | /* send the response to the VF */ |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1359 | return i40e_vc_send_resp_to_vf(vf, I40E_VIRTCHNL_OP_CONFIG_VSI_QUEUES, |
| 1360 | aq_ret); |
| 1361 | } |
| 1362 | |
| 1363 | /** |
| 1364 | * i40e_vc_config_irq_map_msg |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 1365 | * @vf: pointer to the VF info |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1366 | * @msg: pointer to the msg buffer |
| 1367 | * @msglen: msg length |
| 1368 | * |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 1369 | * called from the VF to configure the irq to |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1370 | * queue map |
| 1371 | **/ |
| 1372 | static int i40e_vc_config_irq_map_msg(struct i40e_vf *vf, u8 *msg, u16 msglen) |
| 1373 | { |
| 1374 | struct i40e_virtchnl_irq_map_info *irqmap_info = |
| 1375 | (struct i40e_virtchnl_irq_map_info *)msg; |
| 1376 | struct i40e_virtchnl_vector_map *map; |
| 1377 | u16 vsi_id, vsi_queue_id, vector_id; |
| 1378 | i40e_status aq_ret = 0; |
| 1379 | unsigned long tempmap; |
| 1380 | int i; |
| 1381 | |
| 1382 | if (!test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states)) { |
| 1383 | aq_ret = I40E_ERR_PARAM; |
| 1384 | goto error_param; |
| 1385 | } |
| 1386 | |
| 1387 | for (i = 0; i < irqmap_info->num_vectors; i++) { |
| 1388 | map = &irqmap_info->vecmap[i]; |
| 1389 | |
| 1390 | vector_id = map->vector_id; |
| 1391 | vsi_id = map->vsi_id; |
| 1392 | /* validate msg params */ |
| 1393 | if (!i40e_vc_isvalid_vector_id(vf, vector_id) || |
| 1394 | !i40e_vc_isvalid_vsi_id(vf, vsi_id)) { |
| 1395 | aq_ret = I40E_ERR_PARAM; |
| 1396 | goto error_param; |
| 1397 | } |
| 1398 | |
| 1399 | /* lookout for the invalid queue index */ |
| 1400 | tempmap = map->rxq_map; |
Wei Yongjun | 4836650 | 2013-09-24 05:17:36 +0000 | [diff] [blame] | 1401 | for_each_set_bit(vsi_queue_id, &tempmap, I40E_MAX_VSI_QP) { |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1402 | if (!i40e_vc_isvalid_queue_id(vf, vsi_id, |
| 1403 | vsi_queue_id)) { |
| 1404 | aq_ret = I40E_ERR_PARAM; |
| 1405 | goto error_param; |
| 1406 | } |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1407 | } |
| 1408 | |
| 1409 | tempmap = map->txq_map; |
Wei Yongjun | 4836650 | 2013-09-24 05:17:36 +0000 | [diff] [blame] | 1410 | for_each_set_bit(vsi_queue_id, &tempmap, I40E_MAX_VSI_QP) { |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1411 | if (!i40e_vc_isvalid_queue_id(vf, vsi_id, |
| 1412 | vsi_queue_id)) { |
| 1413 | aq_ret = I40E_ERR_PARAM; |
| 1414 | goto error_param; |
| 1415 | } |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1416 | } |
| 1417 | |
| 1418 | i40e_config_irq_link_list(vf, vsi_id, map); |
| 1419 | } |
| 1420 | error_param: |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 1421 | /* send the response to the VF */ |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1422 | return i40e_vc_send_resp_to_vf(vf, I40E_VIRTCHNL_OP_CONFIG_IRQ_MAP, |
| 1423 | aq_ret); |
| 1424 | } |
| 1425 | |
| 1426 | /** |
| 1427 | * i40e_vc_enable_queues_msg |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 1428 | * @vf: pointer to the VF info |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1429 | * @msg: pointer to the msg buffer |
| 1430 | * @msglen: msg length |
| 1431 | * |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 1432 | * called from the VF to enable all or specific queue(s) |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1433 | **/ |
| 1434 | static int i40e_vc_enable_queues_msg(struct i40e_vf *vf, u8 *msg, u16 msglen) |
| 1435 | { |
| 1436 | struct i40e_virtchnl_queue_select *vqs = |
| 1437 | (struct i40e_virtchnl_queue_select *)msg; |
| 1438 | struct i40e_pf *pf = vf->pf; |
| 1439 | u16 vsi_id = vqs->vsi_id; |
| 1440 | i40e_status aq_ret = 0; |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1441 | |
| 1442 | if (!test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states)) { |
| 1443 | aq_ret = I40E_ERR_PARAM; |
| 1444 | goto error_param; |
| 1445 | } |
| 1446 | |
| 1447 | if (!i40e_vc_isvalid_vsi_id(vf, vsi_id)) { |
| 1448 | aq_ret = I40E_ERR_PARAM; |
| 1449 | goto error_param; |
| 1450 | } |
| 1451 | |
| 1452 | if ((0 == vqs->rx_queues) && (0 == vqs->tx_queues)) { |
| 1453 | aq_ret = I40E_ERR_PARAM; |
| 1454 | goto error_param; |
| 1455 | } |
Anjali Singhai Jain | fdf0e0b | 2015-03-31 00:45:05 -0700 | [diff] [blame] | 1456 | |
| 1457 | if (i40e_vsi_control_rings(pf->vsi[vf->lan_vsi_idx], true)) |
Mitch Williams | 88f6563 | 2013-11-28 06:39:28 +0000 | [diff] [blame] | 1458 | aq_ret = I40E_ERR_TIMEOUT; |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1459 | error_param: |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 1460 | /* send the response to the VF */ |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1461 | return i40e_vc_send_resp_to_vf(vf, I40E_VIRTCHNL_OP_ENABLE_QUEUES, |
| 1462 | aq_ret); |
| 1463 | } |
| 1464 | |
| 1465 | /** |
| 1466 | * i40e_vc_disable_queues_msg |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 1467 | * @vf: pointer to the VF info |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1468 | * @msg: pointer to the msg buffer |
| 1469 | * @msglen: msg length |
| 1470 | * |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 1471 | * called from the VF to disable all or specific |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1472 | * queue(s) |
| 1473 | **/ |
| 1474 | static int i40e_vc_disable_queues_msg(struct i40e_vf *vf, u8 *msg, u16 msglen) |
| 1475 | { |
| 1476 | struct i40e_virtchnl_queue_select *vqs = |
| 1477 | (struct i40e_virtchnl_queue_select *)msg; |
| 1478 | struct i40e_pf *pf = vf->pf; |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1479 | i40e_status aq_ret = 0; |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1480 | |
| 1481 | if (!test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states)) { |
| 1482 | aq_ret = I40E_ERR_PARAM; |
| 1483 | goto error_param; |
| 1484 | } |
| 1485 | |
| 1486 | if (!i40e_vc_isvalid_vsi_id(vf, vqs->vsi_id)) { |
| 1487 | aq_ret = I40E_ERR_PARAM; |
| 1488 | goto error_param; |
| 1489 | } |
| 1490 | |
| 1491 | if ((0 == vqs->rx_queues) && (0 == vqs->tx_queues)) { |
| 1492 | aq_ret = I40E_ERR_PARAM; |
| 1493 | goto error_param; |
| 1494 | } |
Anjali Singhai Jain | fdf0e0b | 2015-03-31 00:45:05 -0700 | [diff] [blame] | 1495 | |
| 1496 | if (i40e_vsi_control_rings(pf->vsi[vf->lan_vsi_idx], false)) |
Mitch Williams | 88f6563 | 2013-11-28 06:39:28 +0000 | [diff] [blame] | 1497 | aq_ret = I40E_ERR_TIMEOUT; |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1498 | |
| 1499 | error_param: |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 1500 | /* send the response to the VF */ |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1501 | return i40e_vc_send_resp_to_vf(vf, I40E_VIRTCHNL_OP_DISABLE_QUEUES, |
| 1502 | aq_ret); |
| 1503 | } |
| 1504 | |
| 1505 | /** |
| 1506 | * i40e_vc_get_stats_msg |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 1507 | * @vf: pointer to the VF info |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1508 | * @msg: pointer to the msg buffer |
| 1509 | * @msglen: msg length |
| 1510 | * |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 1511 | * called from the VF to get vsi stats |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1512 | **/ |
| 1513 | static int i40e_vc_get_stats_msg(struct i40e_vf *vf, u8 *msg, u16 msglen) |
| 1514 | { |
| 1515 | struct i40e_virtchnl_queue_select *vqs = |
| 1516 | (struct i40e_virtchnl_queue_select *)msg; |
| 1517 | struct i40e_pf *pf = vf->pf; |
| 1518 | struct i40e_eth_stats stats; |
| 1519 | i40e_status aq_ret = 0; |
| 1520 | struct i40e_vsi *vsi; |
| 1521 | |
| 1522 | memset(&stats, 0, sizeof(struct i40e_eth_stats)); |
| 1523 | |
| 1524 | if (!test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states)) { |
| 1525 | aq_ret = I40E_ERR_PARAM; |
| 1526 | goto error_param; |
| 1527 | } |
| 1528 | |
| 1529 | if (!i40e_vc_isvalid_vsi_id(vf, vqs->vsi_id)) { |
| 1530 | aq_ret = I40E_ERR_PARAM; |
| 1531 | goto error_param; |
| 1532 | } |
| 1533 | |
Anjali Singhai Jain | fdf0e0b | 2015-03-31 00:45:05 -0700 | [diff] [blame] | 1534 | vsi = pf->vsi[vf->lan_vsi_idx]; |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1535 | if (!vsi) { |
| 1536 | aq_ret = I40E_ERR_PARAM; |
| 1537 | goto error_param; |
| 1538 | } |
| 1539 | i40e_update_eth_stats(vsi); |
Mitch Williams | 5a9769c | 2013-11-28 06:39:38 +0000 | [diff] [blame] | 1540 | stats = vsi->eth_stats; |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1541 | |
| 1542 | error_param: |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 1543 | /* send the response back to the VF */ |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1544 | return i40e_vc_send_msg_to_vf(vf, I40E_VIRTCHNL_OP_GET_STATS, aq_ret, |
| 1545 | (u8 *)&stats, sizeof(stats)); |
| 1546 | } |
| 1547 | |
| 1548 | /** |
Greg Rose | f657a6e | 2013-11-28 06:39:42 +0000 | [diff] [blame] | 1549 | * i40e_check_vf_permission |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 1550 | * @vf: pointer to the VF info |
Greg Rose | f657a6e | 2013-11-28 06:39:42 +0000 | [diff] [blame] | 1551 | * @macaddr: pointer to the MAC Address being checked |
| 1552 | * |
| 1553 | * Check if the VF has permission to add or delete unicast MAC address |
| 1554 | * filters and return error code -EPERM if not. Then check if the |
| 1555 | * address filter requested is broadcast or zero and if so return |
| 1556 | * an invalid MAC address error code. |
| 1557 | **/ |
| 1558 | static inline int i40e_check_vf_permission(struct i40e_vf *vf, u8 *macaddr) |
| 1559 | { |
| 1560 | struct i40e_pf *pf = vf->pf; |
| 1561 | int ret = 0; |
| 1562 | |
| 1563 | if (is_broadcast_ether_addr(macaddr) || |
| 1564 | is_zero_ether_addr(macaddr)) { |
| 1565 | dev_err(&pf->pdev->dev, "invalid VF MAC addr %pM\n", macaddr); |
| 1566 | ret = I40E_ERR_INVALID_MAC_ADDR; |
Greg Rose | 5017c2a | 2013-12-07 10:36:54 +0000 | [diff] [blame] | 1567 | } else if (vf->pf_set_mac && !is_multicast_ether_addr(macaddr) && |
| 1568 | !ether_addr_equal(macaddr, vf->default_lan_addr.addr)) { |
Greg Rose | f657a6e | 2013-11-28 06:39:42 +0000 | [diff] [blame] | 1569 | /* If the host VMM administrator has set the VF MAC address |
| 1570 | * administratively via the ndo_set_vf_mac command then deny |
| 1571 | * permission to the VF to add or delete unicast MAC addresses. |
Greg Rose | 5017c2a | 2013-12-07 10:36:54 +0000 | [diff] [blame] | 1572 | * The VF may request to set the MAC address filter already |
| 1573 | * assigned to it so do not return an error in that case. |
Greg Rose | f657a6e | 2013-11-28 06:39:42 +0000 | [diff] [blame] | 1574 | */ |
| 1575 | dev_err(&pf->pdev->dev, |
| 1576 | "VF attempting to override administratively set MAC address\nPlease reload the VF driver to resume normal operation\n"); |
| 1577 | ret = -EPERM; |
| 1578 | } |
| 1579 | return ret; |
| 1580 | } |
| 1581 | |
| 1582 | /** |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1583 | * i40e_vc_add_mac_addr_msg |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 1584 | * @vf: pointer to the VF info |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1585 | * @msg: pointer to the msg buffer |
| 1586 | * @msglen: msg length |
| 1587 | * |
| 1588 | * add guest mac address filter |
| 1589 | **/ |
| 1590 | static int i40e_vc_add_mac_addr_msg(struct i40e_vf *vf, u8 *msg, u16 msglen) |
| 1591 | { |
| 1592 | struct i40e_virtchnl_ether_addr_list *al = |
| 1593 | (struct i40e_virtchnl_ether_addr_list *)msg; |
| 1594 | struct i40e_pf *pf = vf->pf; |
| 1595 | struct i40e_vsi *vsi = NULL; |
| 1596 | u16 vsi_id = al->vsi_id; |
Greg Rose | f657a6e | 2013-11-28 06:39:42 +0000 | [diff] [blame] | 1597 | i40e_status ret = 0; |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1598 | int i; |
| 1599 | |
| 1600 | if (!test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states) || |
| 1601 | !test_bit(I40E_VIRTCHNL_VF_CAP_PRIVILEGE, &vf->vf_caps) || |
| 1602 | !i40e_vc_isvalid_vsi_id(vf, vsi_id)) { |
Greg Rose | f657a6e | 2013-11-28 06:39:42 +0000 | [diff] [blame] | 1603 | ret = I40E_ERR_PARAM; |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1604 | goto error_param; |
| 1605 | } |
| 1606 | |
| 1607 | for (i = 0; i < al->num_elements; i++) { |
Greg Rose | f657a6e | 2013-11-28 06:39:42 +0000 | [diff] [blame] | 1608 | ret = i40e_check_vf_permission(vf, al->list[i].addr); |
| 1609 | if (ret) |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1610 | goto error_param; |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1611 | } |
Anjali Singhai Jain | fdf0e0b | 2015-03-31 00:45:05 -0700 | [diff] [blame] | 1612 | vsi = pf->vsi[vf->lan_vsi_idx]; |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1613 | |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1614 | /* Lock once, because all function inside for loop accesses VSI's |
| 1615 | * MAC filter list which needs to be protected using same lock. |
| 1616 | */ |
| 1617 | spin_lock_bh(&vsi->mac_filter_list_lock); |
| 1618 | |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1619 | /* add new addresses to the list */ |
| 1620 | for (i = 0; i < al->num_elements; i++) { |
| 1621 | struct i40e_mac_filter *f; |
| 1622 | |
| 1623 | f = i40e_find_mac(vsi, al->list[i].addr, true, false); |
Mitch Williams | 7e68edf9 | 2013-11-16 10:00:41 +0000 | [diff] [blame] | 1624 | if (!f) { |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1625 | if (i40e_is_vsi_in_vlan(vsi)) |
| 1626 | f = i40e_put_mac_in_vlan(vsi, al->list[i].addr, |
| 1627 | true, false); |
| 1628 | else |
| 1629 | f = i40e_add_filter(vsi, al->list[i].addr, -1, |
| 1630 | true, false); |
| 1631 | } |
| 1632 | |
| 1633 | if (!f) { |
| 1634 | dev_err(&pf->pdev->dev, |
Mitch Williams | 8d8f229 | 2015-10-21 19:47:11 -0400 | [diff] [blame] | 1635 | "Unable to add MAC filter %pM for VF %d\n", |
| 1636 | al->list[i].addr, vf->vf_id); |
Greg Rose | f657a6e | 2013-11-28 06:39:42 +0000 | [diff] [blame] | 1637 | ret = I40E_ERR_PARAM; |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1638 | spin_unlock_bh(&vsi->mac_filter_list_lock); |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1639 | goto error_param; |
| 1640 | } |
| 1641 | } |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1642 | spin_unlock_bh(&vsi->mac_filter_list_lock); |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1643 | |
| 1644 | /* program the updated filter list */ |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 1645 | ret = i40e_sync_vsi_filters(vsi); |
| 1646 | if (ret) |
| 1647 | dev_err(&pf->pdev->dev, "Unable to program VF %d MAC filters, error %d\n", |
| 1648 | vf->vf_id, ret); |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1649 | |
| 1650 | error_param: |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 1651 | /* send the response to the VF */ |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1652 | return i40e_vc_send_resp_to_vf(vf, I40E_VIRTCHNL_OP_ADD_ETHER_ADDRESS, |
Greg Rose | f657a6e | 2013-11-28 06:39:42 +0000 | [diff] [blame] | 1653 | ret); |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1654 | } |
| 1655 | |
| 1656 | /** |
| 1657 | * i40e_vc_del_mac_addr_msg |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 1658 | * @vf: pointer to the VF info |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1659 | * @msg: pointer to the msg buffer |
| 1660 | * @msglen: msg length |
| 1661 | * |
| 1662 | * remove guest mac address filter |
| 1663 | **/ |
| 1664 | static int i40e_vc_del_mac_addr_msg(struct i40e_vf *vf, u8 *msg, u16 msglen) |
| 1665 | { |
| 1666 | struct i40e_virtchnl_ether_addr_list *al = |
| 1667 | (struct i40e_virtchnl_ether_addr_list *)msg; |
| 1668 | struct i40e_pf *pf = vf->pf; |
| 1669 | struct i40e_vsi *vsi = NULL; |
| 1670 | u16 vsi_id = al->vsi_id; |
Greg Rose | f657a6e | 2013-11-28 06:39:42 +0000 | [diff] [blame] | 1671 | i40e_status ret = 0; |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1672 | int i; |
| 1673 | |
| 1674 | if (!test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states) || |
| 1675 | !test_bit(I40E_VIRTCHNL_VF_CAP_PRIVILEGE, &vf->vf_caps) || |
| 1676 | !i40e_vc_isvalid_vsi_id(vf, vsi_id)) { |
Greg Rose | f657a6e | 2013-11-28 06:39:42 +0000 | [diff] [blame] | 1677 | ret = I40E_ERR_PARAM; |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1678 | goto error_param; |
| 1679 | } |
Greg Rose | f657a6e | 2013-11-28 06:39:42 +0000 | [diff] [blame] | 1680 | |
| 1681 | for (i = 0; i < al->num_elements; i++) { |
Mitch Williams | 700bbf6 | 2013-12-21 05:44:45 +0000 | [diff] [blame] | 1682 | if (is_broadcast_ether_addr(al->list[i].addr) || |
| 1683 | is_zero_ether_addr(al->list[i].addr)) { |
Mitch Williams | 8d8f229 | 2015-10-21 19:47:11 -0400 | [diff] [blame] | 1684 | dev_err(&pf->pdev->dev, "Invalid MAC addr %pM for VF %d\n", |
| 1685 | al->list[i].addr, vf->vf_id); |
Mitch Williams | 700bbf6 | 2013-12-21 05:44:45 +0000 | [diff] [blame] | 1686 | ret = I40E_ERR_INVALID_MAC_ADDR; |
Greg Rose | f657a6e | 2013-11-28 06:39:42 +0000 | [diff] [blame] | 1687 | goto error_param; |
Mitch Williams | 700bbf6 | 2013-12-21 05:44:45 +0000 | [diff] [blame] | 1688 | } |
Greg Rose | f657a6e | 2013-11-28 06:39:42 +0000 | [diff] [blame] | 1689 | } |
Anjali Singhai Jain | fdf0e0b | 2015-03-31 00:45:05 -0700 | [diff] [blame] | 1690 | vsi = pf->vsi[vf->lan_vsi_idx]; |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1691 | |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1692 | spin_lock_bh(&vsi->mac_filter_list_lock); |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1693 | /* delete addresses from the list */ |
| 1694 | for (i = 0; i < al->num_elements; i++) |
Mitch Williams | b36e9ab | 2015-11-19 11:34:16 -0800 | [diff] [blame] | 1695 | if (i40e_del_mac_all_vlan(vsi, al->list[i].addr, true, false)) { |
| 1696 | ret = I40E_ERR_INVALID_MAC_ADDR; |
| 1697 | spin_unlock_bh(&vsi->mac_filter_list_lock); |
| 1698 | goto error_param; |
| 1699 | } |
| 1700 | |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1701 | spin_unlock_bh(&vsi->mac_filter_list_lock); |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1702 | |
| 1703 | /* program the updated filter list */ |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 1704 | ret = i40e_sync_vsi_filters(vsi); |
| 1705 | if (ret) |
| 1706 | dev_err(&pf->pdev->dev, "Unable to program VF %d MAC filters, error %d\n", |
| 1707 | vf->vf_id, ret); |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1708 | |
| 1709 | error_param: |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 1710 | /* send the response to the VF */ |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1711 | return i40e_vc_send_resp_to_vf(vf, I40E_VIRTCHNL_OP_DEL_ETHER_ADDRESS, |
Greg Rose | f657a6e | 2013-11-28 06:39:42 +0000 | [diff] [blame] | 1712 | ret); |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1713 | } |
| 1714 | |
| 1715 | /** |
| 1716 | * i40e_vc_add_vlan_msg |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 1717 | * @vf: pointer to the VF info |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1718 | * @msg: pointer to the msg buffer |
| 1719 | * @msglen: msg length |
| 1720 | * |
| 1721 | * program guest vlan id |
| 1722 | **/ |
| 1723 | static int i40e_vc_add_vlan_msg(struct i40e_vf *vf, u8 *msg, u16 msglen) |
| 1724 | { |
| 1725 | struct i40e_virtchnl_vlan_filter_list *vfl = |
| 1726 | (struct i40e_virtchnl_vlan_filter_list *)msg; |
| 1727 | struct i40e_pf *pf = vf->pf; |
| 1728 | struct i40e_vsi *vsi = NULL; |
| 1729 | u16 vsi_id = vfl->vsi_id; |
| 1730 | i40e_status aq_ret = 0; |
| 1731 | int i; |
| 1732 | |
| 1733 | if (!test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states) || |
| 1734 | !test_bit(I40E_VIRTCHNL_VF_CAP_PRIVILEGE, &vf->vf_caps) || |
| 1735 | !i40e_vc_isvalid_vsi_id(vf, vsi_id)) { |
| 1736 | aq_ret = I40E_ERR_PARAM; |
| 1737 | goto error_param; |
| 1738 | } |
| 1739 | |
| 1740 | for (i = 0; i < vfl->num_elements; i++) { |
| 1741 | if (vfl->vlan_id[i] > I40E_MAX_VLANID) { |
| 1742 | aq_ret = I40E_ERR_PARAM; |
| 1743 | dev_err(&pf->pdev->dev, |
| 1744 | "invalid VF VLAN id %d\n", vfl->vlan_id[i]); |
| 1745 | goto error_param; |
| 1746 | } |
| 1747 | } |
Anjali Singhai Jain | fdf0e0b | 2015-03-31 00:45:05 -0700 | [diff] [blame] | 1748 | vsi = pf->vsi[vf->lan_vsi_idx]; |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1749 | if (vsi->info.pvid) { |
| 1750 | aq_ret = I40E_ERR_PARAM; |
| 1751 | goto error_param; |
| 1752 | } |
| 1753 | |
| 1754 | i40e_vlan_stripping_enable(vsi); |
| 1755 | for (i = 0; i < vfl->num_elements; i++) { |
| 1756 | /* add new VLAN filter */ |
| 1757 | int ret = i40e_vsi_add_vlan(vsi, vfl->vlan_id[i]); |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 1758 | |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1759 | if (ret) |
| 1760 | dev_err(&pf->pdev->dev, |
Mitch Williams | 8d8f229 | 2015-10-21 19:47:11 -0400 | [diff] [blame] | 1761 | "Unable to add VLAN filter %d for VF %d, error %d\n", |
| 1762 | vfl->vlan_id[i], vf->vf_id, ret); |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1763 | } |
| 1764 | |
| 1765 | error_param: |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 1766 | /* send the response to the VF */ |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1767 | return i40e_vc_send_resp_to_vf(vf, I40E_VIRTCHNL_OP_ADD_VLAN, aq_ret); |
| 1768 | } |
| 1769 | |
| 1770 | /** |
| 1771 | * i40e_vc_remove_vlan_msg |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 1772 | * @vf: pointer to the VF info |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1773 | * @msg: pointer to the msg buffer |
| 1774 | * @msglen: msg length |
| 1775 | * |
| 1776 | * remove programmed guest vlan id |
| 1777 | **/ |
| 1778 | static int i40e_vc_remove_vlan_msg(struct i40e_vf *vf, u8 *msg, u16 msglen) |
| 1779 | { |
| 1780 | struct i40e_virtchnl_vlan_filter_list *vfl = |
| 1781 | (struct i40e_virtchnl_vlan_filter_list *)msg; |
| 1782 | struct i40e_pf *pf = vf->pf; |
| 1783 | struct i40e_vsi *vsi = NULL; |
| 1784 | u16 vsi_id = vfl->vsi_id; |
| 1785 | i40e_status aq_ret = 0; |
| 1786 | int i; |
| 1787 | |
| 1788 | if (!test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states) || |
| 1789 | !test_bit(I40E_VIRTCHNL_VF_CAP_PRIVILEGE, &vf->vf_caps) || |
| 1790 | !i40e_vc_isvalid_vsi_id(vf, vsi_id)) { |
| 1791 | aq_ret = I40E_ERR_PARAM; |
| 1792 | goto error_param; |
| 1793 | } |
| 1794 | |
| 1795 | for (i = 0; i < vfl->num_elements; i++) { |
| 1796 | if (vfl->vlan_id[i] > I40E_MAX_VLANID) { |
| 1797 | aq_ret = I40E_ERR_PARAM; |
| 1798 | goto error_param; |
| 1799 | } |
| 1800 | } |
| 1801 | |
Anjali Singhai Jain | fdf0e0b | 2015-03-31 00:45:05 -0700 | [diff] [blame] | 1802 | vsi = pf->vsi[vf->lan_vsi_idx]; |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1803 | if (vsi->info.pvid) { |
| 1804 | aq_ret = I40E_ERR_PARAM; |
| 1805 | goto error_param; |
| 1806 | } |
| 1807 | |
| 1808 | for (i = 0; i < vfl->num_elements; i++) { |
| 1809 | int ret = i40e_vsi_kill_vlan(vsi, vfl->vlan_id[i]); |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 1810 | |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1811 | if (ret) |
| 1812 | dev_err(&pf->pdev->dev, |
Mitch Williams | 8d8f229 | 2015-10-21 19:47:11 -0400 | [diff] [blame] | 1813 | "Unable to delete VLAN filter %d for VF %d, error %d\n", |
| 1814 | vfl->vlan_id[i], vf->vf_id, ret); |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1815 | } |
| 1816 | |
| 1817 | error_param: |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 1818 | /* send the response to the VF */ |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1819 | return i40e_vc_send_resp_to_vf(vf, I40E_VIRTCHNL_OP_DEL_VLAN, aq_ret); |
| 1820 | } |
| 1821 | |
| 1822 | /** |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1823 | * i40e_vc_validate_vf_msg |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 1824 | * @vf: pointer to the VF info |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1825 | * @msg: pointer to the msg buffer |
| 1826 | * @msglen: msg length |
| 1827 | * @msghndl: msg handle |
| 1828 | * |
| 1829 | * validate msg |
| 1830 | **/ |
| 1831 | static int i40e_vc_validate_vf_msg(struct i40e_vf *vf, u32 v_opcode, |
| 1832 | u32 v_retval, u8 *msg, u16 msglen) |
| 1833 | { |
| 1834 | bool err_msg_format = false; |
| 1835 | int valid_len; |
| 1836 | |
| 1837 | /* Check if VF is disabled. */ |
| 1838 | if (test_bit(I40E_VF_STAT_DISABLED, &vf->vf_states)) |
| 1839 | return I40E_ERR_PARAM; |
| 1840 | |
| 1841 | /* Validate message length. */ |
| 1842 | switch (v_opcode) { |
| 1843 | case I40E_VIRTCHNL_OP_VERSION: |
| 1844 | valid_len = sizeof(struct i40e_virtchnl_version_info); |
| 1845 | break; |
| 1846 | case I40E_VIRTCHNL_OP_RESET_VF: |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1847 | valid_len = 0; |
| 1848 | break; |
Mitch Williams | f4ca1a2 | 2015-06-04 16:23:57 -0400 | [diff] [blame] | 1849 | case I40E_VIRTCHNL_OP_GET_VF_RESOURCES: |
| 1850 | if (VF_IS_V11(vf)) |
| 1851 | valid_len = sizeof(u32); |
| 1852 | else |
| 1853 | valid_len = 0; |
| 1854 | break; |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1855 | case I40E_VIRTCHNL_OP_CONFIG_TX_QUEUE: |
| 1856 | valid_len = sizeof(struct i40e_virtchnl_txq_info); |
| 1857 | break; |
| 1858 | case I40E_VIRTCHNL_OP_CONFIG_RX_QUEUE: |
| 1859 | valid_len = sizeof(struct i40e_virtchnl_rxq_info); |
| 1860 | break; |
| 1861 | case I40E_VIRTCHNL_OP_CONFIG_VSI_QUEUES: |
| 1862 | valid_len = sizeof(struct i40e_virtchnl_vsi_queue_config_info); |
| 1863 | if (msglen >= valid_len) { |
| 1864 | struct i40e_virtchnl_vsi_queue_config_info *vqc = |
| 1865 | (struct i40e_virtchnl_vsi_queue_config_info *)msg; |
| 1866 | valid_len += (vqc->num_queue_pairs * |
| 1867 | sizeof(struct |
| 1868 | i40e_virtchnl_queue_pair_info)); |
| 1869 | if (vqc->num_queue_pairs == 0) |
| 1870 | err_msg_format = true; |
| 1871 | } |
| 1872 | break; |
| 1873 | case I40E_VIRTCHNL_OP_CONFIG_IRQ_MAP: |
| 1874 | valid_len = sizeof(struct i40e_virtchnl_irq_map_info); |
| 1875 | if (msglen >= valid_len) { |
| 1876 | struct i40e_virtchnl_irq_map_info *vimi = |
| 1877 | (struct i40e_virtchnl_irq_map_info *)msg; |
| 1878 | valid_len += (vimi->num_vectors * |
| 1879 | sizeof(struct i40e_virtchnl_vector_map)); |
| 1880 | if (vimi->num_vectors == 0) |
| 1881 | err_msg_format = true; |
| 1882 | } |
| 1883 | break; |
| 1884 | case I40E_VIRTCHNL_OP_ENABLE_QUEUES: |
| 1885 | case I40E_VIRTCHNL_OP_DISABLE_QUEUES: |
| 1886 | valid_len = sizeof(struct i40e_virtchnl_queue_select); |
| 1887 | break; |
| 1888 | case I40E_VIRTCHNL_OP_ADD_ETHER_ADDRESS: |
| 1889 | case I40E_VIRTCHNL_OP_DEL_ETHER_ADDRESS: |
| 1890 | valid_len = sizeof(struct i40e_virtchnl_ether_addr_list); |
| 1891 | if (msglen >= valid_len) { |
| 1892 | struct i40e_virtchnl_ether_addr_list *veal = |
| 1893 | (struct i40e_virtchnl_ether_addr_list *)msg; |
| 1894 | valid_len += veal->num_elements * |
| 1895 | sizeof(struct i40e_virtchnl_ether_addr); |
| 1896 | if (veal->num_elements == 0) |
| 1897 | err_msg_format = true; |
| 1898 | } |
| 1899 | break; |
| 1900 | case I40E_VIRTCHNL_OP_ADD_VLAN: |
| 1901 | case I40E_VIRTCHNL_OP_DEL_VLAN: |
| 1902 | valid_len = sizeof(struct i40e_virtchnl_vlan_filter_list); |
| 1903 | if (msglen >= valid_len) { |
| 1904 | struct i40e_virtchnl_vlan_filter_list *vfl = |
| 1905 | (struct i40e_virtchnl_vlan_filter_list *)msg; |
| 1906 | valid_len += vfl->num_elements * sizeof(u16); |
| 1907 | if (vfl->num_elements == 0) |
| 1908 | err_msg_format = true; |
| 1909 | } |
| 1910 | break; |
| 1911 | case I40E_VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE: |
| 1912 | valid_len = sizeof(struct i40e_virtchnl_promisc_info); |
| 1913 | break; |
| 1914 | case I40E_VIRTCHNL_OP_GET_STATS: |
| 1915 | valid_len = sizeof(struct i40e_virtchnl_queue_select); |
| 1916 | break; |
| 1917 | /* These are always errors coming from the VF. */ |
| 1918 | case I40E_VIRTCHNL_OP_EVENT: |
| 1919 | case I40E_VIRTCHNL_OP_UNKNOWN: |
| 1920 | default: |
| 1921 | return -EPERM; |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1922 | } |
| 1923 | /* few more checks */ |
| 1924 | if ((valid_len != msglen) || (err_msg_format)) { |
| 1925 | i40e_vc_send_resp_to_vf(vf, v_opcode, I40E_ERR_PARAM); |
| 1926 | return -EINVAL; |
| 1927 | } else { |
| 1928 | return 0; |
| 1929 | } |
| 1930 | } |
| 1931 | |
| 1932 | /** |
| 1933 | * i40e_vc_process_vf_msg |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 1934 | * @pf: pointer to the PF structure |
| 1935 | * @vf_id: source VF id |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1936 | * @msg: pointer to the msg buffer |
| 1937 | * @msglen: msg length |
| 1938 | * @msghndl: msg handle |
| 1939 | * |
| 1940 | * called from the common aeq/arq handler to |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 1941 | * process request from VF |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1942 | **/ |
| 1943 | int i40e_vc_process_vf_msg(struct i40e_pf *pf, u16 vf_id, u32 v_opcode, |
| 1944 | u32 v_retval, u8 *msg, u16 msglen) |
| 1945 | { |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1946 | struct i40e_hw *hw = &pf->hw; |
Dan Carpenter | c243e96 | 2014-01-15 06:43:39 +0000 | [diff] [blame] | 1947 | unsigned int local_vf_id = vf_id - hw->func_caps.vf_base_id; |
Mitch Williams | 6c1b5bf | 2013-11-28 06:39:30 +0000 | [diff] [blame] | 1948 | struct i40e_vf *vf; |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1949 | int ret; |
| 1950 | |
| 1951 | pf->vf_aq_requests++; |
Mitch Williams | 7efa84b | 2013-11-28 06:39:41 +0000 | [diff] [blame] | 1952 | if (local_vf_id >= pf->num_alloc_vfs) |
Mitch Williams | 6c1b5bf | 2013-11-28 06:39:30 +0000 | [diff] [blame] | 1953 | return -EINVAL; |
Mitch Williams | 7efa84b | 2013-11-28 06:39:41 +0000 | [diff] [blame] | 1954 | vf = &(pf->vf[local_vf_id]); |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1955 | /* perform basic checks on the msg */ |
| 1956 | ret = i40e_vc_validate_vf_msg(vf, v_opcode, v_retval, msg, msglen); |
| 1957 | |
| 1958 | if (ret) { |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 1959 | dev_err(&pf->pdev->dev, "Invalid message from VF %d, opcode %d, len %d\n", |
Mitch Williams | 7efa84b | 2013-11-28 06:39:41 +0000 | [diff] [blame] | 1960 | local_vf_id, v_opcode, msglen); |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1961 | return ret; |
| 1962 | } |
Mitch Williams | bae3cae | 2014-01-14 00:49:49 -0800 | [diff] [blame] | 1963 | |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1964 | switch (v_opcode) { |
| 1965 | case I40E_VIRTCHNL_OP_VERSION: |
Mitch Williams | f4ca1a2 | 2015-06-04 16:23:57 -0400 | [diff] [blame] | 1966 | ret = i40e_vc_get_version_msg(vf, msg); |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1967 | break; |
| 1968 | case I40E_VIRTCHNL_OP_GET_VF_RESOURCES: |
Mitch Williams | f4ca1a2 | 2015-06-04 16:23:57 -0400 | [diff] [blame] | 1969 | ret = i40e_vc_get_vf_resources_msg(vf, msg); |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1970 | break; |
| 1971 | case I40E_VIRTCHNL_OP_RESET_VF: |
Mitch Williams | fc18eaa | 2013-11-28 06:39:27 +0000 | [diff] [blame] | 1972 | i40e_vc_reset_vf_msg(vf); |
| 1973 | ret = 0; |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1974 | break; |
| 1975 | case I40E_VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE: |
| 1976 | ret = i40e_vc_config_promiscuous_mode_msg(vf, msg, msglen); |
| 1977 | break; |
| 1978 | case I40E_VIRTCHNL_OP_CONFIG_VSI_QUEUES: |
| 1979 | ret = i40e_vc_config_queues_msg(vf, msg, msglen); |
| 1980 | break; |
| 1981 | case I40E_VIRTCHNL_OP_CONFIG_IRQ_MAP: |
| 1982 | ret = i40e_vc_config_irq_map_msg(vf, msg, msglen); |
| 1983 | break; |
| 1984 | case I40E_VIRTCHNL_OP_ENABLE_QUEUES: |
| 1985 | ret = i40e_vc_enable_queues_msg(vf, msg, msglen); |
Mitch Williams | 055b295 | 2015-04-07 19:45:33 -0400 | [diff] [blame] | 1986 | i40e_vc_notify_vf_link_state(vf); |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1987 | break; |
| 1988 | case I40E_VIRTCHNL_OP_DISABLE_QUEUES: |
| 1989 | ret = i40e_vc_disable_queues_msg(vf, msg, msglen); |
| 1990 | break; |
| 1991 | case I40E_VIRTCHNL_OP_ADD_ETHER_ADDRESS: |
| 1992 | ret = i40e_vc_add_mac_addr_msg(vf, msg, msglen); |
| 1993 | break; |
| 1994 | case I40E_VIRTCHNL_OP_DEL_ETHER_ADDRESS: |
| 1995 | ret = i40e_vc_del_mac_addr_msg(vf, msg, msglen); |
| 1996 | break; |
| 1997 | case I40E_VIRTCHNL_OP_ADD_VLAN: |
| 1998 | ret = i40e_vc_add_vlan_msg(vf, msg, msglen); |
| 1999 | break; |
| 2000 | case I40E_VIRTCHNL_OP_DEL_VLAN: |
| 2001 | ret = i40e_vc_remove_vlan_msg(vf, msg, msglen); |
| 2002 | break; |
| 2003 | case I40E_VIRTCHNL_OP_GET_STATS: |
| 2004 | ret = i40e_vc_get_stats_msg(vf, msg, msglen); |
| 2005 | break; |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 2006 | case I40E_VIRTCHNL_OP_UNKNOWN: |
| 2007 | default: |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 2008 | dev_err(&pf->pdev->dev, "Unsupported opcode %d from VF %d\n", |
Mitch Williams | 7efa84b | 2013-11-28 06:39:41 +0000 | [diff] [blame] | 2009 | v_opcode, local_vf_id); |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 2010 | ret = i40e_vc_send_resp_to_vf(vf, v_opcode, |
| 2011 | I40E_ERR_NOT_IMPLEMENTED); |
| 2012 | break; |
| 2013 | } |
| 2014 | |
| 2015 | return ret; |
| 2016 | } |
| 2017 | |
| 2018 | /** |
| 2019 | * i40e_vc_process_vflr_event |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 2020 | * @pf: pointer to the PF structure |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 2021 | * |
| 2022 | * called from the vlfr irq handler to |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 2023 | * free up VF resources and state variables |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 2024 | **/ |
| 2025 | int i40e_vc_process_vflr_event(struct i40e_pf *pf) |
| 2026 | { |
| 2027 | u32 reg, reg_idx, bit_idx, vf_id; |
| 2028 | struct i40e_hw *hw = &pf->hw; |
| 2029 | struct i40e_vf *vf; |
| 2030 | |
| 2031 | if (!test_bit(__I40E_VFLR_EVENT_PENDING, &pf->state)) |
| 2032 | return 0; |
| 2033 | |
Mitch Williams | c5c2f7c | 2014-11-11 03:15:04 +0000 | [diff] [blame] | 2034 | /* re-enable vflr interrupt cause */ |
| 2035 | reg = rd32(hw, I40E_PFINT_ICR0_ENA); |
| 2036 | reg |= I40E_PFINT_ICR0_ENA_VFLR_MASK; |
| 2037 | wr32(hw, I40E_PFINT_ICR0_ENA, reg); |
| 2038 | i40e_flush(hw); |
| 2039 | |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 2040 | clear_bit(__I40E_VFLR_EVENT_PENDING, &pf->state); |
| 2041 | for (vf_id = 0; vf_id < pf->num_alloc_vfs; vf_id++) { |
| 2042 | reg_idx = (hw->func_caps.vf_base_id + vf_id) / 32; |
| 2043 | bit_idx = (hw->func_caps.vf_base_id + vf_id) % 32; |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 2044 | /* read GLGEN_VFLRSTAT register to find out the flr VFs */ |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 2045 | vf = &pf->vf[vf_id]; |
| 2046 | reg = rd32(hw, I40E_GLGEN_VFLRSTAT(reg_idx)); |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 2047 | if (reg & BIT(bit_idx)) { |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 2048 | /* clear the bit in GLGEN_VFLRSTAT */ |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 2049 | wr32(hw, I40E_GLGEN_VFLRSTAT(reg_idx), BIT(bit_idx)); |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 2050 | |
Mitch Williams | eb2d80b | 2014-02-13 03:48:48 -0800 | [diff] [blame] | 2051 | if (!test_bit(__I40E_DOWN, &pf->state)) |
| 2052 | i40e_reset_vf(vf, true); |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 2053 | } |
| 2054 | } |
| 2055 | |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 2056 | return 0; |
| 2057 | } |
| 2058 | |
| 2059 | /** |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 2060 | * i40e_ndo_set_vf_mac |
| 2061 | * @netdev: network interface device structure |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 2062 | * @vf_id: VF identifier |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 2063 | * @mac: mac address |
| 2064 | * |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 2065 | * program VF mac address |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 2066 | **/ |
| 2067 | int i40e_ndo_set_vf_mac(struct net_device *netdev, int vf_id, u8 *mac) |
| 2068 | { |
| 2069 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 2070 | struct i40e_vsi *vsi = np->vsi; |
| 2071 | struct i40e_pf *pf = vsi->back; |
| 2072 | struct i40e_mac_filter *f; |
| 2073 | struct i40e_vf *vf; |
| 2074 | int ret = 0; |
| 2075 | |
| 2076 | /* validate the request */ |
| 2077 | if (vf_id >= pf->num_alloc_vfs) { |
| 2078 | dev_err(&pf->pdev->dev, |
| 2079 | "Invalid VF Identifier %d\n", vf_id); |
| 2080 | ret = -EINVAL; |
| 2081 | goto error_param; |
| 2082 | } |
| 2083 | |
| 2084 | vf = &(pf->vf[vf_id]); |
Anjali Singhai Jain | fdf0e0b | 2015-03-31 00:45:05 -0700 | [diff] [blame] | 2085 | vsi = pf->vsi[vf->lan_vsi_idx]; |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 2086 | if (!test_bit(I40E_VF_STAT_INIT, &vf->vf_states)) { |
Mitch Williams | 2d166c3 | 2015-12-22 15:34:42 -0800 | [diff] [blame] | 2087 | dev_err(&pf->pdev->dev, "VF %d still in reset. Try again.\n", |
| 2088 | vf_id); |
| 2089 | ret = -EAGAIN; |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 2090 | goto error_param; |
| 2091 | } |
| 2092 | |
Mitch Williams | efd8e39 | 2015-12-22 15:34:43 -0800 | [diff] [blame] | 2093 | if (is_multicast_ether_addr(mac)) { |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 2094 | dev_err(&pf->pdev->dev, |
Mitch Williams | efd8e39 | 2015-12-22 15:34:43 -0800 | [diff] [blame] | 2095 | "Invalid Ethernet address %pM for VF %d\n", mac, vf_id); |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 2096 | ret = -EINVAL; |
| 2097 | goto error_param; |
| 2098 | } |
| 2099 | |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2100 | /* Lock once because below invoked function add/del_filter requires |
| 2101 | * mac_filter_list_lock to be held |
| 2102 | */ |
| 2103 | spin_lock_bh(&vsi->mac_filter_list_lock); |
| 2104 | |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 2105 | /* delete the temporary mac address */ |
Mitch Williams | efd8e39 | 2015-12-22 15:34:43 -0800 | [diff] [blame] | 2106 | if (!is_zero_ether_addr(vf->default_lan_addr.addr)) |
| 2107 | i40e_del_filter(vsi, vf->default_lan_addr.addr, |
| 2108 | vf->port_vlan_id ? vf->port_vlan_id : -1, |
| 2109 | true, false); |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 2110 | |
Greg Rose | 29f71bb | 2014-05-20 08:01:45 +0000 | [diff] [blame] | 2111 | /* Delete all the filters for this VSI - we're going to kill it |
| 2112 | * anyway. |
| 2113 | */ |
| 2114 | list_for_each_entry(f, &vsi->mac_filter_list, list) |
| 2115 | i40e_del_filter(vsi, f->macaddr, f->vlan, true, false); |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 2116 | |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2117 | spin_unlock_bh(&vsi->mac_filter_list_lock); |
| 2118 | |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 2119 | dev_info(&pf->pdev->dev, "Setting MAC %pM on VF %d\n", mac, vf_id); |
| 2120 | /* program mac filter */ |
Jesse Brandeburg | 17652c6 | 2015-11-05 17:01:02 -0800 | [diff] [blame] | 2121 | if (i40e_sync_vsi_filters(vsi)) { |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 2122 | dev_err(&pf->pdev->dev, "Unable to program ucast filters\n"); |
| 2123 | ret = -EIO; |
| 2124 | goto error_param; |
| 2125 | } |
Greg Rose | 9a17390 | 2014-05-22 06:32:02 +0000 | [diff] [blame] | 2126 | ether_addr_copy(vf->default_lan_addr.addr, mac); |
Greg Rose | f657a6e | 2013-11-28 06:39:42 +0000 | [diff] [blame] | 2127 | vf->pf_set_mac = true; |
Greg Rose | 17413a8 | 2014-06-04 01:23:13 +0000 | [diff] [blame] | 2128 | /* Force the VF driver stop so it has to reload with new MAC address */ |
| 2129 | i40e_vc_disable_vf(pf, vf); |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 2130 | dev_info(&pf->pdev->dev, "Reload the VF driver to make this change effective.\n"); |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 2131 | |
| 2132 | error_param: |
| 2133 | return ret; |
| 2134 | } |
| 2135 | |
| 2136 | /** |
| 2137 | * i40e_ndo_set_vf_port_vlan |
| 2138 | * @netdev: network interface device structure |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 2139 | * @vf_id: VF identifier |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 2140 | * @vlan_id: mac address |
| 2141 | * @qos: priority setting |
| 2142 | * |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 2143 | * program VF vlan id and/or qos |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 2144 | **/ |
| 2145 | int i40e_ndo_set_vf_port_vlan(struct net_device *netdev, |
| 2146 | int vf_id, u16 vlan_id, u8 qos) |
| 2147 | { |
Mitch Williams | f7fc2f2 | 2015-07-23 16:54:36 -0400 | [diff] [blame] | 2148 | u16 vlanprio = vlan_id | (qos << I40E_VLAN_PRIORITY_SHIFT); |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 2149 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 2150 | struct i40e_pf *pf = np->vsi->back; |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2151 | bool is_vsi_in_vlan = false; |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 2152 | struct i40e_vsi *vsi; |
| 2153 | struct i40e_vf *vf; |
| 2154 | int ret = 0; |
| 2155 | |
| 2156 | /* validate the request */ |
| 2157 | if (vf_id >= pf->num_alloc_vfs) { |
| 2158 | dev_err(&pf->pdev->dev, "Invalid VF Identifier %d\n", vf_id); |
| 2159 | ret = -EINVAL; |
| 2160 | goto error_pvid; |
| 2161 | } |
| 2162 | |
| 2163 | if ((vlan_id > I40E_MAX_VLANID) || (qos > 7)) { |
| 2164 | dev_err(&pf->pdev->dev, "Invalid VF Parameters\n"); |
| 2165 | ret = -EINVAL; |
| 2166 | goto error_pvid; |
| 2167 | } |
| 2168 | |
| 2169 | vf = &(pf->vf[vf_id]); |
Anjali Singhai Jain | fdf0e0b | 2015-03-31 00:45:05 -0700 | [diff] [blame] | 2170 | vsi = pf->vsi[vf->lan_vsi_idx]; |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 2171 | if (!test_bit(I40E_VF_STAT_INIT, &vf->vf_states)) { |
Mitch Williams | 2d166c3 | 2015-12-22 15:34:42 -0800 | [diff] [blame] | 2172 | dev_err(&pf->pdev->dev, "VF %d still in reset. Try again.\n", |
| 2173 | vf_id); |
| 2174 | ret = -EAGAIN; |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 2175 | goto error_pvid; |
| 2176 | } |
| 2177 | |
Mitch Williams | f7fc2f2 | 2015-07-23 16:54:36 -0400 | [diff] [blame] | 2178 | if (le16_to_cpu(vsi->info.pvid) == vlanprio) |
Mitch Williams | 85927ec | 2015-04-27 14:57:10 -0400 | [diff] [blame] | 2179 | /* duplicate request, so just return success */ |
| 2180 | goto error_pvid; |
| 2181 | |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2182 | spin_lock_bh(&vsi->mac_filter_list_lock); |
| 2183 | is_vsi_in_vlan = i40e_is_vsi_in_vlan(vsi); |
| 2184 | spin_unlock_bh(&vsi->mac_filter_list_lock); |
| 2185 | |
| 2186 | if (le16_to_cpu(vsi->info.pvid) == 0 && is_vsi_in_vlan) { |
Greg Rose | 99a4973 | 2014-01-13 16:13:03 -0800 | [diff] [blame] | 2187 | dev_err(&pf->pdev->dev, |
| 2188 | "VF %d has already configured VLAN filters and the administrator is requesting a port VLAN override.\nPlease unload and reload the VF driver for this change to take effect.\n", |
| 2189 | vf_id); |
Greg Rose | f9b4b62 | 2014-03-06 09:02:28 +0000 | [diff] [blame] | 2190 | /* Administrator Error - knock the VF offline until he does |
| 2191 | * the right thing by reconfiguring his network correctly |
| 2192 | * and then reloading the VF driver. |
| 2193 | */ |
| 2194 | i40e_vc_disable_vf(pf, vf); |
| 2195 | } |
Greg Rose | 99a4973 | 2014-01-13 16:13:03 -0800 | [diff] [blame] | 2196 | |
Greg Rose | 8d82a7c | 2014-01-13 16:13:04 -0800 | [diff] [blame] | 2197 | /* Check for condition where there was already a port VLAN ID |
| 2198 | * filter set and now it is being deleted by setting it to zero. |
Greg Rose | 1315f7c | 2014-03-14 07:32:20 +0000 | [diff] [blame] | 2199 | * Additionally check for the condition where there was a port |
| 2200 | * VLAN but now there is a new and different port VLAN being set. |
Greg Rose | 8d82a7c | 2014-01-13 16:13:04 -0800 | [diff] [blame] | 2201 | * Before deleting all the old VLAN filters we must add new ones |
| 2202 | * with -1 (I40E_VLAN_ANY) or otherwise we're left with all our |
| 2203 | * MAC addresses deleted. |
| 2204 | */ |
Greg Rose | 1315f7c | 2014-03-14 07:32:20 +0000 | [diff] [blame] | 2205 | if ((!(vlan_id || qos) || |
Mitch Williams | f7fc2f2 | 2015-07-23 16:54:36 -0400 | [diff] [blame] | 2206 | vlanprio != le16_to_cpu(vsi->info.pvid)) && |
Greg Rose | 1315f7c | 2014-03-14 07:32:20 +0000 | [diff] [blame] | 2207 | vsi->info.pvid) |
Greg Rose | 8d82a7c | 2014-01-13 16:13:04 -0800 | [diff] [blame] | 2208 | ret = i40e_vsi_add_vlan(vsi, I40E_VLAN_ANY); |
| 2209 | |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 2210 | if (vsi->info.pvid) { |
| 2211 | /* kill old VLAN */ |
| 2212 | ret = i40e_vsi_kill_vlan(vsi, (le16_to_cpu(vsi->info.pvid) & |
| 2213 | VLAN_VID_MASK)); |
| 2214 | if (ret) { |
| 2215 | dev_info(&vsi->back->pdev->dev, |
| 2216 | "remove VLAN failed, ret=%d, aq_err=%d\n", |
| 2217 | ret, pf->hw.aq.asq_last_status); |
| 2218 | } |
| 2219 | } |
| 2220 | if (vlan_id || qos) |
Mitch Williams | f7fc2f2 | 2015-07-23 16:54:36 -0400 | [diff] [blame] | 2221 | ret = i40e_vsi_add_pvid(vsi, vlanprio); |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 2222 | else |
Greg Rose | 6c12fcb | 2013-11-28 06:39:34 +0000 | [diff] [blame] | 2223 | i40e_vsi_remove_pvid(vsi); |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 2224 | |
| 2225 | if (vlan_id) { |
| 2226 | dev_info(&pf->pdev->dev, "Setting VLAN %d, QOS 0x%x on VF %d\n", |
| 2227 | vlan_id, qos, vf_id); |
| 2228 | |
| 2229 | /* add new VLAN filter */ |
| 2230 | ret = i40e_vsi_add_vlan(vsi, vlan_id); |
| 2231 | if (ret) { |
| 2232 | dev_info(&vsi->back->pdev->dev, |
| 2233 | "add VF VLAN failed, ret=%d aq_err=%d\n", ret, |
| 2234 | vsi->back->hw.aq.asq_last_status); |
| 2235 | goto error_pvid; |
| 2236 | } |
Greg Rose | 8d82a7c | 2014-01-13 16:13:04 -0800 | [diff] [blame] | 2237 | /* Kill non-vlan MAC filters - ignore error return since |
| 2238 | * there might not be any non-vlan MAC filters. |
| 2239 | */ |
| 2240 | i40e_vsi_kill_vlan(vsi, I40E_VLAN_ANY); |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 2241 | } |
| 2242 | |
| 2243 | if (ret) { |
| 2244 | dev_err(&pf->pdev->dev, "Unable to update VF vsi context\n"); |
| 2245 | goto error_pvid; |
| 2246 | } |
Greg Rose | 6c12fcb | 2013-11-28 06:39:34 +0000 | [diff] [blame] | 2247 | /* The Port VLAN needs to be saved across resets the same as the |
| 2248 | * default LAN MAC address. |
| 2249 | */ |
| 2250 | vf->port_vlan_id = le16_to_cpu(vsi->info.pvid); |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 2251 | ret = 0; |
| 2252 | |
| 2253 | error_pvid: |
| 2254 | return ret; |
| 2255 | } |
| 2256 | |
Mitch Williams | 84590fd | 2014-04-09 05:58:57 +0000 | [diff] [blame] | 2257 | #define I40E_BW_CREDIT_DIVISOR 50 /* 50Mbps per BW credit */ |
| 2258 | #define I40E_MAX_BW_INACTIVE_ACCUM 4 /* device can accumulate 4 credits max */ |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 2259 | /** |
| 2260 | * i40e_ndo_set_vf_bw |
| 2261 | * @netdev: network interface device structure |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 2262 | * @vf_id: VF identifier |
| 2263 | * @tx_rate: Tx rate |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 2264 | * |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 2265 | * configure VF Tx rate |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 2266 | **/ |
Sucheta Chakraborty | ed61668 | 2014-05-22 09:59:05 -0400 | [diff] [blame] | 2267 | int i40e_ndo_set_vf_bw(struct net_device *netdev, int vf_id, int min_tx_rate, |
| 2268 | int max_tx_rate) |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 2269 | { |
Mitch Williams | 6b19289 | 2014-03-06 09:02:29 +0000 | [diff] [blame] | 2270 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 2271 | struct i40e_pf *pf = np->vsi->back; |
| 2272 | struct i40e_vsi *vsi; |
| 2273 | struct i40e_vf *vf; |
| 2274 | int speed = 0; |
| 2275 | int ret = 0; |
| 2276 | |
| 2277 | /* validate the request */ |
| 2278 | if (vf_id >= pf->num_alloc_vfs) { |
| 2279 | dev_err(&pf->pdev->dev, "Invalid VF Identifier %d.\n", vf_id); |
| 2280 | ret = -EINVAL; |
| 2281 | goto error; |
| 2282 | } |
| 2283 | |
Sucheta Chakraborty | ed61668 | 2014-05-22 09:59:05 -0400 | [diff] [blame] | 2284 | if (min_tx_rate) { |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 2285 | dev_err(&pf->pdev->dev, "Invalid min tx rate (%d) (greater than 0) specified for VF %d.\n", |
Sucheta Chakraborty | ed61668 | 2014-05-22 09:59:05 -0400 | [diff] [blame] | 2286 | min_tx_rate, vf_id); |
| 2287 | return -EINVAL; |
| 2288 | } |
| 2289 | |
Mitch Williams | 6b19289 | 2014-03-06 09:02:29 +0000 | [diff] [blame] | 2290 | vf = &(pf->vf[vf_id]); |
Anjali Singhai Jain | fdf0e0b | 2015-03-31 00:45:05 -0700 | [diff] [blame] | 2291 | vsi = pf->vsi[vf->lan_vsi_idx]; |
Mitch Williams | 6b19289 | 2014-03-06 09:02:29 +0000 | [diff] [blame] | 2292 | if (!test_bit(I40E_VF_STAT_INIT, &vf->vf_states)) { |
Mitch Williams | 2d166c3 | 2015-12-22 15:34:42 -0800 | [diff] [blame] | 2293 | dev_err(&pf->pdev->dev, "VF %d still in reset. Try again.\n", |
| 2294 | vf_id); |
| 2295 | ret = -EAGAIN; |
Mitch Williams | 6b19289 | 2014-03-06 09:02:29 +0000 | [diff] [blame] | 2296 | goto error; |
| 2297 | } |
| 2298 | |
| 2299 | switch (pf->hw.phy.link_info.link_speed) { |
| 2300 | case I40E_LINK_SPEED_40GB: |
| 2301 | speed = 40000; |
| 2302 | break; |
| 2303 | case I40E_LINK_SPEED_10GB: |
| 2304 | speed = 10000; |
| 2305 | break; |
| 2306 | case I40E_LINK_SPEED_1GB: |
| 2307 | speed = 1000; |
| 2308 | break; |
| 2309 | default: |
| 2310 | break; |
| 2311 | } |
| 2312 | |
Sucheta Chakraborty | ed61668 | 2014-05-22 09:59:05 -0400 | [diff] [blame] | 2313 | if (max_tx_rate > speed) { |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 2314 | dev_err(&pf->pdev->dev, "Invalid max tx rate %d specified for VF %d.", |
Sucheta Chakraborty | ed61668 | 2014-05-22 09:59:05 -0400 | [diff] [blame] | 2315 | max_tx_rate, vf->vf_id); |
Mitch Williams | 6b19289 | 2014-03-06 09:02:29 +0000 | [diff] [blame] | 2316 | ret = -EINVAL; |
| 2317 | goto error; |
| 2318 | } |
| 2319 | |
Mitch Williams | dac9b31 | 2014-04-09 05:58:56 +0000 | [diff] [blame] | 2320 | if ((max_tx_rate < 50) && (max_tx_rate > 0)) { |
| 2321 | dev_warn(&pf->pdev->dev, "Setting max Tx rate to minimum usable value of 50Mbps.\n"); |
| 2322 | max_tx_rate = 50; |
| 2323 | } |
| 2324 | |
Mitch Williams | 6b19289 | 2014-03-06 09:02:29 +0000 | [diff] [blame] | 2325 | /* Tx rate credits are in values of 50Mbps, 0 is disabled*/ |
Mitch Williams | 84590fd | 2014-04-09 05:58:57 +0000 | [diff] [blame] | 2326 | ret = i40e_aq_config_vsi_bw_limit(&pf->hw, vsi->seid, |
| 2327 | max_tx_rate / I40E_BW_CREDIT_DIVISOR, |
| 2328 | I40E_MAX_BW_INACTIVE_ACCUM, NULL); |
Mitch Williams | 6b19289 | 2014-03-06 09:02:29 +0000 | [diff] [blame] | 2329 | if (ret) { |
Sucheta Chakraborty | ed61668 | 2014-05-22 09:59:05 -0400 | [diff] [blame] | 2330 | dev_err(&pf->pdev->dev, "Unable to set max tx rate, error code %d.\n", |
Mitch Williams | 6b19289 | 2014-03-06 09:02:29 +0000 | [diff] [blame] | 2331 | ret); |
| 2332 | ret = -EIO; |
| 2333 | goto error; |
| 2334 | } |
Sucheta Chakraborty | ed61668 | 2014-05-22 09:59:05 -0400 | [diff] [blame] | 2335 | vf->tx_rate = max_tx_rate; |
Mitch Williams | 6b19289 | 2014-03-06 09:02:29 +0000 | [diff] [blame] | 2336 | error: |
| 2337 | return ret; |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 2338 | } |
| 2339 | |
| 2340 | /** |
| 2341 | * i40e_ndo_get_vf_config |
| 2342 | * @netdev: network interface device structure |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 2343 | * @vf_id: VF identifier |
| 2344 | * @ivi: VF configuration structure |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 2345 | * |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 2346 | * return VF configuration |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 2347 | **/ |
| 2348 | int i40e_ndo_get_vf_config(struct net_device *netdev, |
| 2349 | int vf_id, struct ifla_vf_info *ivi) |
| 2350 | { |
| 2351 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 2352 | struct i40e_vsi *vsi = np->vsi; |
| 2353 | struct i40e_pf *pf = vsi->back; |
| 2354 | struct i40e_vf *vf; |
| 2355 | int ret = 0; |
| 2356 | |
| 2357 | /* validate the request */ |
| 2358 | if (vf_id >= pf->num_alloc_vfs) { |
| 2359 | dev_err(&pf->pdev->dev, "Invalid VF Identifier %d\n", vf_id); |
| 2360 | ret = -EINVAL; |
| 2361 | goto error_param; |
| 2362 | } |
| 2363 | |
| 2364 | vf = &(pf->vf[vf_id]); |
| 2365 | /* first vsi is always the LAN vsi */ |
Anjali Singhai Jain | fdf0e0b | 2015-03-31 00:45:05 -0700 | [diff] [blame] | 2366 | vsi = pf->vsi[vf->lan_vsi_idx]; |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 2367 | if (!test_bit(I40E_VF_STAT_INIT, &vf->vf_states)) { |
Mitch Williams | 2d166c3 | 2015-12-22 15:34:42 -0800 | [diff] [blame] | 2368 | dev_err(&pf->pdev->dev, "VF %d still in reset. Try again.\n", |
| 2369 | vf_id); |
| 2370 | ret = -EAGAIN; |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 2371 | goto error_param; |
| 2372 | } |
| 2373 | |
| 2374 | ivi->vf = vf_id; |
| 2375 | |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 2376 | ether_addr_copy(ivi->mac, vf->default_lan_addr.addr); |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 2377 | |
Sucheta Chakraborty | ed61668 | 2014-05-22 09:59:05 -0400 | [diff] [blame] | 2378 | ivi->max_tx_rate = vf->tx_rate; |
| 2379 | ivi->min_tx_rate = 0; |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 2380 | ivi->vlan = le16_to_cpu(vsi->info.pvid) & I40E_VLAN_MASK; |
| 2381 | ivi->qos = (le16_to_cpu(vsi->info.pvid) & I40E_PRIORITY_MASK) >> |
| 2382 | I40E_VLAN_PRIORITY_SHIFT; |
Mitch Williams | 84ca55a | 2014-03-14 07:32:24 +0000 | [diff] [blame] | 2383 | if (vf->link_forced == false) |
| 2384 | ivi->linkstate = IFLA_VF_LINK_STATE_AUTO; |
| 2385 | else if (vf->link_up == true) |
| 2386 | ivi->linkstate = IFLA_VF_LINK_STATE_ENABLE; |
| 2387 | else |
| 2388 | ivi->linkstate = IFLA_VF_LINK_STATE_DISABLE; |
Mitch Williams | c674d12 | 2014-05-20 08:01:40 +0000 | [diff] [blame] | 2389 | ivi->spoofchk = vf->spoofchk; |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 2390 | ret = 0; |
| 2391 | |
| 2392 | error_param: |
| 2393 | return ret; |
| 2394 | } |
Mitch Williams | 588aefa | 2014-02-11 08:27:49 +0000 | [diff] [blame] | 2395 | |
| 2396 | /** |
| 2397 | * i40e_ndo_set_vf_link_state |
| 2398 | * @netdev: network interface device structure |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 2399 | * @vf_id: VF identifier |
Mitch Williams | 588aefa | 2014-02-11 08:27:49 +0000 | [diff] [blame] | 2400 | * @link: required link state |
| 2401 | * |
| 2402 | * Set the link state of a specified VF, regardless of physical link state |
| 2403 | **/ |
| 2404 | int i40e_ndo_set_vf_link_state(struct net_device *netdev, int vf_id, int link) |
| 2405 | { |
| 2406 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 2407 | struct i40e_pf *pf = np->vsi->back; |
| 2408 | struct i40e_virtchnl_pf_event pfe; |
| 2409 | struct i40e_hw *hw = &pf->hw; |
| 2410 | struct i40e_vf *vf; |
Ashish Shah | f19efbb | 2014-08-01 13:27:06 -0700 | [diff] [blame] | 2411 | int abs_vf_id; |
Mitch Williams | 588aefa | 2014-02-11 08:27:49 +0000 | [diff] [blame] | 2412 | int ret = 0; |
| 2413 | |
| 2414 | /* validate the request */ |
| 2415 | if (vf_id >= pf->num_alloc_vfs) { |
| 2416 | dev_err(&pf->pdev->dev, "Invalid VF Identifier %d\n", vf_id); |
| 2417 | ret = -EINVAL; |
| 2418 | goto error_out; |
| 2419 | } |
| 2420 | |
| 2421 | vf = &pf->vf[vf_id]; |
Ashish Shah | f19efbb | 2014-08-01 13:27:06 -0700 | [diff] [blame] | 2422 | abs_vf_id = vf->vf_id + hw->func_caps.vf_base_id; |
Mitch Williams | 588aefa | 2014-02-11 08:27:49 +0000 | [diff] [blame] | 2423 | |
| 2424 | pfe.event = I40E_VIRTCHNL_EVENT_LINK_CHANGE; |
| 2425 | pfe.severity = I40E_PF_EVENT_SEVERITY_INFO; |
| 2426 | |
| 2427 | switch (link) { |
| 2428 | case IFLA_VF_LINK_STATE_AUTO: |
| 2429 | vf->link_forced = false; |
| 2430 | pfe.event_data.link_event.link_status = |
| 2431 | pf->hw.phy.link_info.link_info & I40E_AQ_LINK_UP; |
| 2432 | pfe.event_data.link_event.link_speed = |
| 2433 | pf->hw.phy.link_info.link_speed; |
| 2434 | break; |
| 2435 | case IFLA_VF_LINK_STATE_ENABLE: |
| 2436 | vf->link_forced = true; |
| 2437 | vf->link_up = true; |
| 2438 | pfe.event_data.link_event.link_status = true; |
| 2439 | pfe.event_data.link_event.link_speed = I40E_LINK_SPEED_40GB; |
| 2440 | break; |
| 2441 | case IFLA_VF_LINK_STATE_DISABLE: |
| 2442 | vf->link_forced = true; |
| 2443 | vf->link_up = false; |
| 2444 | pfe.event_data.link_event.link_status = false; |
| 2445 | pfe.event_data.link_event.link_speed = 0; |
| 2446 | break; |
| 2447 | default: |
| 2448 | ret = -EINVAL; |
| 2449 | goto error_out; |
| 2450 | } |
| 2451 | /* Notify the VF of its new link state */ |
Ashish Shah | f19efbb | 2014-08-01 13:27:06 -0700 | [diff] [blame] | 2452 | i40e_aq_send_msg_to_vf(hw, abs_vf_id, I40E_VIRTCHNL_OP_EVENT, |
Mitch Williams | 588aefa | 2014-02-11 08:27:49 +0000 | [diff] [blame] | 2453 | 0, (u8 *)&pfe, sizeof(pfe), NULL); |
| 2454 | |
| 2455 | error_out: |
| 2456 | return ret; |
| 2457 | } |
Mitch Williams | c674d12 | 2014-05-20 08:01:40 +0000 | [diff] [blame] | 2458 | |
| 2459 | /** |
| 2460 | * i40e_ndo_set_vf_spoofchk |
| 2461 | * @netdev: network interface device structure |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 2462 | * @vf_id: VF identifier |
Mitch Williams | c674d12 | 2014-05-20 08:01:40 +0000 | [diff] [blame] | 2463 | * @enable: flag to enable or disable feature |
| 2464 | * |
| 2465 | * Enable or disable VF spoof checking |
| 2466 | **/ |
Serey Kong | e6d9004 | 2014-07-12 07:28:14 +0000 | [diff] [blame] | 2467 | int i40e_ndo_set_vf_spoofchk(struct net_device *netdev, int vf_id, bool enable) |
Mitch Williams | c674d12 | 2014-05-20 08:01:40 +0000 | [diff] [blame] | 2468 | { |
| 2469 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 2470 | struct i40e_vsi *vsi = np->vsi; |
| 2471 | struct i40e_pf *pf = vsi->back; |
| 2472 | struct i40e_vsi_context ctxt; |
| 2473 | struct i40e_hw *hw = &pf->hw; |
| 2474 | struct i40e_vf *vf; |
| 2475 | int ret = 0; |
| 2476 | |
| 2477 | /* validate the request */ |
| 2478 | if (vf_id >= pf->num_alloc_vfs) { |
| 2479 | dev_err(&pf->pdev->dev, "Invalid VF Identifier %d\n", vf_id); |
| 2480 | ret = -EINVAL; |
| 2481 | goto out; |
| 2482 | } |
| 2483 | |
| 2484 | vf = &(pf->vf[vf_id]); |
Mitch Williams | 2d166c3 | 2015-12-22 15:34:42 -0800 | [diff] [blame] | 2485 | if (!test_bit(I40E_VF_STAT_INIT, &vf->vf_states)) { |
| 2486 | dev_err(&pf->pdev->dev, "VF %d still in reset. Try again.\n", |
| 2487 | vf_id); |
| 2488 | ret = -EAGAIN; |
| 2489 | goto out; |
| 2490 | } |
Mitch Williams | c674d12 | 2014-05-20 08:01:40 +0000 | [diff] [blame] | 2491 | |
| 2492 | if (enable == vf->spoofchk) |
| 2493 | goto out; |
| 2494 | |
| 2495 | vf->spoofchk = enable; |
| 2496 | memset(&ctxt, 0, sizeof(ctxt)); |
Anjali Singhai Jain | fdf0e0b | 2015-03-31 00:45:05 -0700 | [diff] [blame] | 2497 | ctxt.seid = pf->vsi[vf->lan_vsi_idx]->seid; |
Mitch Williams | c674d12 | 2014-05-20 08:01:40 +0000 | [diff] [blame] | 2498 | ctxt.pf_num = pf->hw.pf_id; |
| 2499 | ctxt.info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_SECURITY_VALID); |
| 2500 | if (enable) |
Greg Rose | 30d71af | 2015-01-29 07:17:17 +0000 | [diff] [blame] | 2501 | ctxt.info.sec_flags |= (I40E_AQ_VSI_SEC_FLAG_ENABLE_VLAN_CHK | |
| 2502 | I40E_AQ_VSI_SEC_FLAG_ENABLE_MAC_CHK); |
Mitch Williams | c674d12 | 2014-05-20 08:01:40 +0000 | [diff] [blame] | 2503 | ret = i40e_aq_update_vsi_params(hw, &ctxt, NULL); |
| 2504 | if (ret) { |
| 2505 | dev_err(&pf->pdev->dev, "Error %d updating VSI parameters\n", |
| 2506 | ret); |
| 2507 | ret = -EIO; |
| 2508 | } |
| 2509 | out: |
| 2510 | return ret; |
| 2511 | } |