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); |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 552 | f = i40e_add_filter(vsi, vf->default_lan_addr.addr, |
Mitch Williams | e995163 | 2015-04-27 14:57:13 -0400 | [diff] [blame] | 553 | vf->port_vlan_id ? vf->port_vlan_id : -1, |
| 554 | true, false); |
Greg Rose | 1a10370 | 2013-11-28 06:42:39 +0000 | [diff] [blame] | 555 | if (!f) |
| 556 | dev_info(&pf->pdev->dev, |
| 557 | "Could not allocate VF MAC addr\n"); |
Mitch Williams | e995163 | 2015-04-27 14:57:13 -0400 | [diff] [blame] | 558 | f = i40e_add_filter(vsi, brdcast, |
| 559 | vf->port_vlan_id ? vf->port_vlan_id : -1, |
Greg Rose | 1a10370 | 2013-11-28 06:42:39 +0000 | [diff] [blame] | 560 | true, false); |
| 561 | if (!f) |
| 562 | dev_info(&pf->pdev->dev, |
| 563 | "Could not allocate VF broadcast filter\n"); |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 564 | spin_unlock_bh(&vsi->mac_filter_list_lock); |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 565 | } |
Neerav Parikh | 6dbbbfb | 2013-11-26 10:49:24 +0000 | [diff] [blame] | 566 | |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 567 | /* program mac filter */ |
Jesse Brandeburg | 17652c6 | 2015-11-05 17:01:02 -0800 | [diff] [blame] | 568 | ret = i40e_sync_vsi_filters(vsi); |
Mitch Williams | fd1646e | 2014-02-13 03:48:44 -0800 | [diff] [blame] | 569 | if (ret) |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 570 | dev_err(&pf->pdev->dev, "Unable to program ucast filters\n"); |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 571 | |
Mitch Williams | 6b19289 | 2014-03-06 09:02:29 +0000 | [diff] [blame] | 572 | /* Set VF bandwidth if specified */ |
| 573 | if (vf->tx_rate) { |
| 574 | ret = i40e_aq_config_vsi_bw_limit(&pf->hw, vsi->seid, |
| 575 | vf->tx_rate / 50, 0, NULL); |
| 576 | if (ret) |
| 577 | dev_err(&pf->pdev->dev, "Unable to set tx rate, VF %d, error code %d.\n", |
| 578 | vf->vf_id, ret); |
| 579 | } |
| 580 | |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 581 | error_alloc_vsi_res: |
| 582 | return ret; |
| 583 | } |
| 584 | |
| 585 | /** |
Mitch Williams | 805bd5b | 2013-11-28 06:39:26 +0000 | [diff] [blame] | 586 | * i40e_enable_vf_mappings |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 587 | * @vf: pointer to the VF info |
Mitch Williams | 805bd5b | 2013-11-28 06:39:26 +0000 | [diff] [blame] | 588 | * |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 589 | * enable VF mappings |
Mitch Williams | 805bd5b | 2013-11-28 06:39:26 +0000 | [diff] [blame] | 590 | **/ |
| 591 | static void i40e_enable_vf_mappings(struct i40e_vf *vf) |
| 592 | { |
| 593 | struct i40e_pf *pf = vf->pf; |
| 594 | struct i40e_hw *hw = &pf->hw; |
| 595 | u32 reg, total_queue_pairs = 0; |
| 596 | int j; |
| 597 | |
| 598 | /* Tell the hardware we're using noncontiguous mapping. HW requires |
| 599 | * that VF queues be mapped using this method, even when they are |
| 600 | * contiguous in real life |
| 601 | */ |
| 602 | wr32(hw, I40E_VSILAN_QBASE(vf->lan_vsi_id), |
| 603 | I40E_VSILAN_QBASE_VSIQTABLE_ENA_MASK); |
| 604 | |
| 605 | /* enable VF vplan_qtable mappings */ |
| 606 | reg = I40E_VPLAN_MAPENA_TXRX_ENA_MASK; |
| 607 | wr32(hw, I40E_VPLAN_MAPENA(vf->vf_id), reg); |
| 608 | |
| 609 | /* map PF queues to VF queues */ |
Anjali Singhai Jain | fdf0e0b | 2015-03-31 00:45:05 -0700 | [diff] [blame] | 610 | for (j = 0; j < pf->vsi[vf->lan_vsi_idx]->alloc_queue_pairs; j++) { |
| 611 | 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] | 612 | |
Mitch Williams | 805bd5b | 2013-11-28 06:39:26 +0000 | [diff] [blame] | 613 | reg = (qid & I40E_VPLAN_QTABLE_QINDEX_MASK); |
| 614 | wr32(hw, I40E_VPLAN_QTABLE(total_queue_pairs, vf->vf_id), reg); |
| 615 | total_queue_pairs++; |
| 616 | } |
| 617 | |
| 618 | /* map PF queues to VSI */ |
| 619 | for (j = 0; j < 7; j++) { |
Anjali Singhai Jain | fdf0e0b | 2015-03-31 00:45:05 -0700 | [diff] [blame] | 620 | if (j * 2 >= pf->vsi[vf->lan_vsi_idx]->alloc_queue_pairs) { |
Mitch Williams | 805bd5b | 2013-11-28 06:39:26 +0000 | [diff] [blame] | 621 | reg = 0x07FF07FF; /* unused */ |
| 622 | } else { |
Anjali Singhai Jain | fdf0e0b | 2015-03-31 00:45:05 -0700 | [diff] [blame] | 623 | 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] | 624 | j * 2); |
| 625 | reg = qid; |
Anjali Singhai Jain | fdf0e0b | 2015-03-31 00:45:05 -0700 | [diff] [blame] | 626 | 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) + 1); |
| 628 | reg |= qid << 16; |
| 629 | } |
| 630 | wr32(hw, I40E_VSILAN_QTABLE(j, vf->lan_vsi_id), reg); |
| 631 | } |
| 632 | |
| 633 | i40e_flush(hw); |
| 634 | } |
| 635 | |
| 636 | /** |
| 637 | * i40e_disable_vf_mappings |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 638 | * @vf: pointer to the VF info |
Mitch Williams | 805bd5b | 2013-11-28 06:39:26 +0000 | [diff] [blame] | 639 | * |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 640 | * disable VF mappings |
Mitch Williams | 805bd5b | 2013-11-28 06:39:26 +0000 | [diff] [blame] | 641 | **/ |
| 642 | static void i40e_disable_vf_mappings(struct i40e_vf *vf) |
| 643 | { |
| 644 | struct i40e_pf *pf = vf->pf; |
| 645 | struct i40e_hw *hw = &pf->hw; |
| 646 | int i; |
| 647 | |
| 648 | /* disable qp mappings */ |
| 649 | wr32(hw, I40E_VPLAN_MAPENA(vf->vf_id), 0); |
| 650 | for (i = 0; i < I40E_MAX_VSI_QP; i++) |
| 651 | wr32(hw, I40E_VPLAN_QTABLE(i, vf->vf_id), |
| 652 | I40E_QUEUE_END_OF_LIST); |
| 653 | i40e_flush(hw); |
| 654 | } |
| 655 | |
| 656 | /** |
| 657 | * i40e_free_vf_res |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 658 | * @vf: pointer to the VF info |
Mitch Williams | 805bd5b | 2013-11-28 06:39:26 +0000 | [diff] [blame] | 659 | * |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 660 | * free VF resources |
Mitch Williams | 805bd5b | 2013-11-28 06:39:26 +0000 | [diff] [blame] | 661 | **/ |
| 662 | static void i40e_free_vf_res(struct i40e_vf *vf) |
| 663 | { |
| 664 | struct i40e_pf *pf = vf->pf; |
Mitch Williams | fc18eaa | 2013-11-28 06:39:27 +0000 | [diff] [blame] | 665 | struct i40e_hw *hw = &pf->hw; |
| 666 | u32 reg_idx, reg; |
| 667 | int i, msix_vf; |
Mitch Williams | 805bd5b | 2013-11-28 06:39:26 +0000 | [diff] [blame] | 668 | |
| 669 | /* free vsi & disconnect it from the parent uplink */ |
Anjali Singhai Jain | fdf0e0b | 2015-03-31 00:45:05 -0700 | [diff] [blame] | 670 | if (vf->lan_vsi_idx) { |
| 671 | i40e_vsi_release(pf->vsi[vf->lan_vsi_idx]); |
| 672 | vf->lan_vsi_idx = 0; |
Mitch Williams | 805bd5b | 2013-11-28 06:39:26 +0000 | [diff] [blame] | 673 | vf->lan_vsi_id = 0; |
| 674 | } |
Mitch Williams | 9347eb7 | 2014-02-11 08:26:32 +0000 | [diff] [blame] | 675 | msix_vf = pf->hw.func_caps.num_msix_vectors_vf; |
| 676 | |
Mitch Williams | fc18eaa | 2013-11-28 06:39:27 +0000 | [diff] [blame] | 677 | /* disable interrupts so the VF starts in a known state */ |
| 678 | for (i = 0; i < msix_vf; i++) { |
| 679 | /* format is same for both registers */ |
| 680 | if (0 == i) |
| 681 | reg_idx = I40E_VFINT_DYN_CTL0(vf->vf_id); |
| 682 | else |
| 683 | reg_idx = I40E_VFINT_DYN_CTLN(((msix_vf - 1) * |
| 684 | (vf->vf_id)) |
| 685 | + (i - 1)); |
| 686 | wr32(hw, reg_idx, I40E_VFINT_DYN_CTLN_CLEARPBA_MASK); |
| 687 | i40e_flush(hw); |
| 688 | } |
Mitch Williams | 805bd5b | 2013-11-28 06:39:26 +0000 | [diff] [blame] | 689 | |
Mitch Williams | fc18eaa | 2013-11-28 06:39:27 +0000 | [diff] [blame] | 690 | /* clear the irq settings */ |
| 691 | for (i = 0; i < msix_vf; i++) { |
| 692 | /* format is same for both registers */ |
| 693 | if (0 == i) |
| 694 | reg_idx = I40E_VPINT_LNKLST0(vf->vf_id); |
| 695 | else |
| 696 | reg_idx = I40E_VPINT_LNKLSTN(((msix_vf - 1) * |
| 697 | (vf->vf_id)) |
| 698 | + (i - 1)); |
| 699 | reg = (I40E_VPINT_LNKLSTN_FIRSTQ_TYPE_MASK | |
| 700 | I40E_VPINT_LNKLSTN_FIRSTQ_INDX_MASK); |
| 701 | wr32(hw, reg_idx, reg); |
| 702 | i40e_flush(hw); |
| 703 | } |
Mitch Williams | 805bd5b | 2013-11-28 06:39:26 +0000 | [diff] [blame] | 704 | /* reset some of the state varibles keeping |
| 705 | * track of the resources |
| 706 | */ |
| 707 | vf->num_queue_pairs = 0; |
| 708 | vf->vf_states = 0; |
Mitch Williams | 21be99e | 2015-08-31 19:54:48 -0400 | [diff] [blame] | 709 | clear_bit(I40E_VF_STAT_INIT, &vf->vf_states); |
Mitch Williams | 805bd5b | 2013-11-28 06:39:26 +0000 | [diff] [blame] | 710 | } |
| 711 | |
| 712 | /** |
| 713 | * i40e_alloc_vf_res |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 714 | * @vf: pointer to the VF info |
Mitch Williams | 805bd5b | 2013-11-28 06:39:26 +0000 | [diff] [blame] | 715 | * |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 716 | * allocate VF resources |
Mitch Williams | 805bd5b | 2013-11-28 06:39:26 +0000 | [diff] [blame] | 717 | **/ |
| 718 | static int i40e_alloc_vf_res(struct i40e_vf *vf) |
| 719 | { |
| 720 | struct i40e_pf *pf = vf->pf; |
| 721 | int total_queue_pairs = 0; |
| 722 | int ret; |
| 723 | |
| 724 | /* allocate hw vsi context & associated resources */ |
| 725 | ret = i40e_alloc_vsi_res(vf, I40E_VSI_SRIOV); |
| 726 | if (ret) |
| 727 | goto error_alloc; |
Anjali Singhai Jain | fdf0e0b | 2015-03-31 00:45:05 -0700 | [diff] [blame] | 728 | total_queue_pairs += pf->vsi[vf->lan_vsi_idx]->alloc_queue_pairs; |
Mitch Williams | 805bd5b | 2013-11-28 06:39:26 +0000 | [diff] [blame] | 729 | set_bit(I40E_VIRTCHNL_VF_CAP_PRIVILEGE, &vf->vf_caps); |
| 730 | |
| 731 | /* store the total qps number for the runtime |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 732 | * VF req validation |
Mitch Williams | 805bd5b | 2013-11-28 06:39:26 +0000 | [diff] [blame] | 733 | */ |
| 734 | vf->num_queue_pairs = total_queue_pairs; |
| 735 | |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 736 | /* VF is now completely initialized */ |
Mitch Williams | 805bd5b | 2013-11-28 06:39:26 +0000 | [diff] [blame] | 737 | set_bit(I40E_VF_STAT_INIT, &vf->vf_states); |
| 738 | |
| 739 | error_alloc: |
| 740 | if (ret) |
| 741 | i40e_free_vf_res(vf); |
| 742 | |
| 743 | return ret; |
| 744 | } |
| 745 | |
Mitch Williams | fc18eaa | 2013-11-28 06:39:27 +0000 | [diff] [blame] | 746 | #define VF_DEVICE_STATUS 0xAA |
| 747 | #define VF_TRANS_PENDING_MASK 0x20 |
| 748 | /** |
| 749 | * i40e_quiesce_vf_pci |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 750 | * @vf: pointer to the VF structure |
Mitch Williams | fc18eaa | 2013-11-28 06:39:27 +0000 | [diff] [blame] | 751 | * |
| 752 | * Wait for VF PCI transactions to be cleared after reset. Returns -EIO |
| 753 | * if the transactions never clear. |
| 754 | **/ |
| 755 | static int i40e_quiesce_vf_pci(struct i40e_vf *vf) |
| 756 | { |
| 757 | struct i40e_pf *pf = vf->pf; |
| 758 | struct i40e_hw *hw = &pf->hw; |
| 759 | int vf_abs_id, i; |
| 760 | u32 reg; |
| 761 | |
Mitch Williams | b141d61 | 2013-11-28 06:39:36 +0000 | [diff] [blame] | 762 | vf_abs_id = vf->vf_id + hw->func_caps.vf_base_id; |
Mitch Williams | fc18eaa | 2013-11-28 06:39:27 +0000 | [diff] [blame] | 763 | |
| 764 | wr32(hw, I40E_PF_PCI_CIAA, |
| 765 | VF_DEVICE_STATUS | (vf_abs_id << I40E_PF_PCI_CIAA_VF_NUM_SHIFT)); |
| 766 | for (i = 0; i < 100; i++) { |
| 767 | reg = rd32(hw, I40E_PF_PCI_CIAD); |
| 768 | if ((reg & VF_TRANS_PENDING_MASK) == 0) |
| 769 | return 0; |
| 770 | udelay(1); |
| 771 | } |
| 772 | return -EIO; |
| 773 | } |
| 774 | |
Mitch Williams | 805bd5b | 2013-11-28 06:39:26 +0000 | [diff] [blame] | 775 | /** |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 776 | * i40e_reset_vf |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 777 | * @vf: pointer to the VF structure |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 778 | * @flr: VFLR was issued or not |
| 779 | * |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 780 | * reset the VF |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 781 | **/ |
Mitch Williams | fc18eaa | 2013-11-28 06:39:27 +0000 | [diff] [blame] | 782 | void i40e_reset_vf(struct i40e_vf *vf, bool flr) |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 783 | { |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 784 | struct i40e_pf *pf = vf->pf; |
| 785 | struct i40e_hw *hw = &pf->hw; |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 786 | bool rsd = false; |
Mitch Williams | fc18eaa | 2013-11-28 06:39:27 +0000 | [diff] [blame] | 787 | int i; |
| 788 | u32 reg; |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 789 | |
Mitch Williams | 3ba9bcb | 2015-01-09 11:18:15 +0000 | [diff] [blame] | 790 | if (test_and_set_bit(__I40E_VF_DISABLE, &pf->state)) |
| 791 | return; |
| 792 | |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 793 | /* warn the VF */ |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 794 | clear_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states); |
| 795 | |
Mitch Williams | fc18eaa | 2013-11-28 06:39:27 +0000 | [diff] [blame] | 796 | /* In the case of a VFLR, the HW has already reset the VF and we |
| 797 | * just need to clean up, so don't hit the VFRTRIG register. |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 798 | */ |
| 799 | if (!flr) { |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 800 | /* reset VF using VPGEN_VFRTRIG reg */ |
Mitch Williams | fc18eaa | 2013-11-28 06:39:27 +0000 | [diff] [blame] | 801 | reg = rd32(hw, I40E_VPGEN_VFRTRIG(vf->vf_id)); |
| 802 | reg |= I40E_VPGEN_VFRTRIG_VFSWR_MASK; |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 803 | wr32(hw, I40E_VPGEN_VFRTRIG(vf->vf_id), reg); |
| 804 | i40e_flush(hw); |
| 805 | } |
| 806 | |
Mitch Williams | fc18eaa | 2013-11-28 06:39:27 +0000 | [diff] [blame] | 807 | if (i40e_quiesce_vf_pci(vf)) |
| 808 | dev_err(&pf->pdev->dev, "VF %d PCI transactions stuck\n", |
| 809 | vf->vf_id); |
| 810 | |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 811 | /* poll VPGEN_VFRSTAT reg to make sure |
| 812 | * that reset is complete |
| 813 | */ |
Mitch Williams | 1750a22 | 2015-01-09 11:18:13 +0000 | [diff] [blame] | 814 | for (i = 0; i < 10; i++) { |
| 815 | /* VF reset requires driver to first reset the VF and then |
| 816 | * poll the status register to make sure that the reset |
| 817 | * completed successfully. Due to internal HW FIFO flushes, |
| 818 | * we must wait 10ms before the register will be valid. |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 819 | */ |
Mitch Williams | 1750a22 | 2015-01-09 11:18:13 +0000 | [diff] [blame] | 820 | usleep_range(10000, 20000); |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 821 | reg = rd32(hw, I40E_VPGEN_VFRSTAT(vf->vf_id)); |
| 822 | if (reg & I40E_VPGEN_VFRSTAT_VFRD_MASK) { |
| 823 | rsd = true; |
| 824 | break; |
| 825 | } |
| 826 | } |
| 827 | |
Anjali Singhai Jain | 57175ac | 2015-04-07 19:45:35 -0400 | [diff] [blame] | 828 | if (flr) |
| 829 | usleep_range(10000, 20000); |
| 830 | |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 831 | if (!rsd) |
Mitch Williams | fc18eaa | 2013-11-28 06:39:27 +0000 | [diff] [blame] | 832 | 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] | 833 | vf->vf_id); |
Mitch Williams | fc18eaa | 2013-11-28 06:39:27 +0000 | [diff] [blame] | 834 | wr32(hw, I40E_VFGEN_RSTAT1(vf->vf_id), I40E_VFR_COMPLETED); |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 835 | /* clear the reset bit in the VPGEN_VFRTRIG reg */ |
| 836 | reg = rd32(hw, I40E_VPGEN_VFRTRIG(vf->vf_id)); |
| 837 | reg &= ~I40E_VPGEN_VFRTRIG_VFSWR_MASK; |
| 838 | wr32(hw, I40E_VPGEN_VFRTRIG(vf->vf_id), reg); |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 839 | |
Mitch Williams | fc18eaa | 2013-11-28 06:39:27 +0000 | [diff] [blame] | 840 | /* On initial reset, we won't have any queues */ |
Anjali Singhai Jain | fdf0e0b | 2015-03-31 00:45:05 -0700 | [diff] [blame] | 841 | if (vf->lan_vsi_idx == 0) |
Mitch Williams | fc18eaa | 2013-11-28 06:39:27 +0000 | [diff] [blame] | 842 | goto complete_reset; |
| 843 | |
Anjali Singhai Jain | fdf0e0b | 2015-03-31 00:45:05 -0700 | [diff] [blame] | 844 | i40e_vsi_control_rings(pf->vsi[vf->lan_vsi_idx], false); |
Mitch Williams | fc18eaa | 2013-11-28 06:39:27 +0000 | [diff] [blame] | 845 | complete_reset: |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 846 | /* reallocate VF resources to reset the VSI state */ |
Mitch Williams | fc18eaa | 2013-11-28 06:39:27 +0000 | [diff] [blame] | 847 | i40e_free_vf_res(vf); |
Mitch Williams | 21be99e | 2015-08-31 19:54:48 -0400 | [diff] [blame] | 848 | if (!i40e_alloc_vf_res(vf)) { |
| 849 | i40e_enable_vf_mappings(vf); |
| 850 | set_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states); |
| 851 | clear_bit(I40E_VF_STAT_DISABLED, &vf->vf_states); |
| 852 | } |
Mitch Williams | fc18eaa | 2013-11-28 06:39:27 +0000 | [diff] [blame] | 853 | /* tell the VF the reset is done */ |
| 854 | wr32(hw, I40E_VFGEN_RSTAT1(vf->vf_id), I40E_VFR_VFACTIVE); |
| 855 | i40e_flush(hw); |
Mitch Williams | 3ba9bcb | 2015-01-09 11:18:15 +0000 | [diff] [blame] | 856 | clear_bit(__I40E_VF_DISABLE, &pf->state); |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 857 | } |
Greg Rose | c354229 | 2013-12-13 08:38:38 +0000 | [diff] [blame] | 858 | |
| 859 | /** |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 860 | * i40e_free_vfs |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 861 | * @pf: pointer to the PF structure |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 862 | * |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 863 | * free VF resources |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 864 | **/ |
| 865 | void i40e_free_vfs(struct i40e_pf *pf) |
| 866 | { |
Mitch Williams | f741453 | 2013-11-28 06:39:40 +0000 | [diff] [blame] | 867 | struct i40e_hw *hw = &pf->hw; |
| 868 | u32 reg_idx, bit_idx; |
| 869 | int i, tmp, vf_id; |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 870 | |
| 871 | if (!pf->vf) |
| 872 | return; |
Mitch Williams | 3ba9bcb | 2015-01-09 11:18:15 +0000 | [diff] [blame] | 873 | while (test_and_set_bit(__I40E_VF_DISABLE, &pf->state)) |
| 874 | usleep_range(1000, 2000); |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 875 | |
Mitch Williams | 4443463 | 2015-04-07 11:32:55 -0700 | [diff] [blame] | 876 | for (i = 0; i < pf->num_alloc_vfs; i++) |
| 877 | if (test_bit(I40E_VF_STAT_INIT, &pf->vf[i].vf_states)) |
| 878 | i40e_vsi_control_rings(pf->vsi[pf->vf[i].lan_vsi_idx], |
| 879 | false); |
| 880 | |
Mitch Williams | 0325fca | 2015-08-26 15:14:09 -0400 | [diff] [blame] | 881 | for (i = 0; i < pf->num_alloc_vfs; i++) |
| 882 | if (test_bit(I40E_VF_STAT_INIT, &pf->vf[i].vf_states)) |
| 883 | i40e_vsi_control_rings(pf->vsi[pf->vf[i].lan_vsi_idx], |
| 884 | false); |
| 885 | |
Mitch A Williams | 6a9ddb3 | 2014-12-09 08:53:01 +0000 | [diff] [blame] | 886 | /* Disable IOV before freeing resources. This lets any VF drivers |
| 887 | * running in the host get themselves cleaned up before we yank |
| 888 | * the carpet out from underneath their feet. |
| 889 | */ |
| 890 | if (!pci_vfs_assigned(pf->pdev)) |
| 891 | pci_disable_sriov(pf->pdev); |
Mitch Williams | 6d7b967 | 2015-03-31 00:45:02 -0700 | [diff] [blame] | 892 | else |
| 893 | 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] | 894 | |
| 895 | msleep(20); /* let any messages in transit get finished up */ |
| 896 | |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 897 | /* free up VF resources */ |
Mitch Williams | 6c1b5bf | 2013-11-28 06:39:30 +0000 | [diff] [blame] | 898 | tmp = pf->num_alloc_vfs; |
| 899 | pf->num_alloc_vfs = 0; |
| 900 | for (i = 0; i < tmp; i++) { |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 901 | if (test_bit(I40E_VF_STAT_INIT, &pf->vf[i].vf_states)) |
| 902 | i40e_free_vf_res(&pf->vf[i]); |
| 903 | /* disable qp mappings */ |
| 904 | i40e_disable_vf_mappings(&pf->vf[i]); |
| 905 | } |
| 906 | |
| 907 | kfree(pf->vf); |
| 908 | pf->vf = NULL; |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 909 | |
Mitch Williams | 9e5634d | 2014-04-04 04:43:14 +0000 | [diff] [blame] | 910 | /* This check is for when the driver is unloaded while VFs are |
| 911 | * assigned. Setting the number of VFs to 0 through sysfs is caught |
| 912 | * before this function ever gets called. |
| 913 | */ |
Ethan Zhao | c24817b | 2014-07-22 18:36:43 +0000 | [diff] [blame] | 914 | if (!pci_vfs_assigned(pf->pdev)) { |
Mitch Williams | f741453 | 2013-11-28 06:39:40 +0000 | [diff] [blame] | 915 | /* Acknowledge VFLR for all VFS. Without this, VFs will fail to |
| 916 | * work correctly when SR-IOV gets re-enabled. |
| 917 | */ |
| 918 | for (vf_id = 0; vf_id < tmp; vf_id++) { |
| 919 | reg_idx = (hw->func_caps.vf_base_id + vf_id) / 32; |
| 920 | bit_idx = (hw->func_caps.vf_base_id + vf_id) % 32; |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 921 | wr32(hw, I40E_GLGEN_VFLRSTAT(reg_idx), BIT(bit_idx)); |
Mitch Williams | f741453 | 2013-11-28 06:39:40 +0000 | [diff] [blame] | 922 | } |
Greg Rose | c354229 | 2013-12-13 08:38:38 +0000 | [diff] [blame] | 923 | } |
Mitch Williams | 3ba9bcb | 2015-01-09 11:18:15 +0000 | [diff] [blame] | 924 | clear_bit(__I40E_VF_DISABLE, &pf->state); |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 925 | } |
| 926 | |
| 927 | #ifdef CONFIG_PCI_IOV |
| 928 | /** |
| 929 | * i40e_alloc_vfs |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 930 | * @pf: pointer to the PF structure |
| 931 | * @num_alloc_vfs: number of VFs to allocate |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 932 | * |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 933 | * allocate VF resources |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 934 | **/ |
Mitch Williams | 4aeec01 | 2014-02-13 03:48:47 -0800 | [diff] [blame] | 935 | int i40e_alloc_vfs(struct i40e_pf *pf, u16 num_alloc_vfs) |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 936 | { |
| 937 | struct i40e_vf *vfs; |
| 938 | int i, ret = 0; |
| 939 | |
Mitch Williams | 6c1b5bf | 2013-11-28 06:39:30 +0000 | [diff] [blame] | 940 | /* Disable interrupt 0 so we don't try to handle the VFLR. */ |
Mitch Williams | 2ef28cf | 2013-11-28 06:39:32 +0000 | [diff] [blame] | 941 | i40e_irq_dynamic_disable_icr0(pf); |
| 942 | |
Mitch Williams | 4aeec01 | 2014-02-13 03:48:47 -0800 | [diff] [blame] | 943 | /* Check to see if we're just allocating resources for extant VFs */ |
| 944 | if (pci_num_vf(pf->pdev) != num_alloc_vfs) { |
| 945 | ret = pci_enable_sriov(pf->pdev, num_alloc_vfs); |
| 946 | if (ret) { |
Akeem G Abodunrin | de445b3 | 2015-10-01 14:37:40 -0400 | [diff] [blame] | 947 | pf->flags &= ~I40E_FLAG_VEB_MODE_ENABLED; |
Mitch Williams | 4aeec01 | 2014-02-13 03:48:47 -0800 | [diff] [blame] | 948 | pf->num_alloc_vfs = 0; |
| 949 | goto err_iov; |
| 950 | } |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 951 | } |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 952 | /* allocate memory */ |
Akeem G Abodunrin | cc6456a | 2014-02-06 05:51:02 +0000 | [diff] [blame] | 953 | vfs = kcalloc(num_alloc_vfs, sizeof(struct i40e_vf), GFP_KERNEL); |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 954 | if (!vfs) { |
| 955 | ret = -ENOMEM; |
| 956 | goto err_alloc; |
| 957 | } |
Mitch Williams | c674d12 | 2014-05-20 08:01:40 +0000 | [diff] [blame] | 958 | pf->vf = vfs; |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 959 | |
| 960 | /* apply default profile */ |
| 961 | for (i = 0; i < num_alloc_vfs; i++) { |
| 962 | vfs[i].pf = pf; |
| 963 | vfs[i].parent_type = I40E_SWITCH_ELEMENT_TYPE_VEB; |
| 964 | vfs[i].vf_id = i; |
| 965 | |
| 966 | /* assign default capabilities */ |
| 967 | set_bit(I40E_VIRTCHNL_VF_CAP_L2, &vfs[i].vf_caps); |
Mitch Williams | c674d12 | 2014-05-20 08:01:40 +0000 | [diff] [blame] | 968 | vfs[i].spoofchk = true; |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 969 | /* VF resources get allocated during reset */ |
Mitch Williams | fc18eaa | 2013-11-28 06:39:27 +0000 | [diff] [blame] | 970 | i40e_reset_vf(&vfs[i], false); |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 971 | |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 972 | } |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 973 | pf->num_alloc_vfs = num_alloc_vfs; |
| 974 | |
| 975 | err_alloc: |
| 976 | if (ret) |
| 977 | i40e_free_vfs(pf); |
| 978 | err_iov: |
Mitch Williams | 6c1b5bf | 2013-11-28 06:39:30 +0000 | [diff] [blame] | 979 | /* Re-enable interrupt 0. */ |
Mitch Williams | 2ef28cf | 2013-11-28 06:39:32 +0000 | [diff] [blame] | 980 | i40e_irq_dynamic_enable_icr0(pf); |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 981 | return ret; |
| 982 | } |
| 983 | |
| 984 | #endif |
| 985 | /** |
| 986 | * i40e_pci_sriov_enable |
| 987 | * @pdev: pointer to a pci_dev structure |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 988 | * @num_vfs: number of VFs to allocate |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 989 | * |
| 990 | * Enable or change the number of VFs |
| 991 | **/ |
| 992 | static int i40e_pci_sriov_enable(struct pci_dev *pdev, int num_vfs) |
| 993 | { |
| 994 | #ifdef CONFIG_PCI_IOV |
| 995 | struct i40e_pf *pf = pci_get_drvdata(pdev); |
| 996 | int pre_existing_vfs = pci_num_vf(pdev); |
| 997 | int err = 0; |
| 998 | |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 999 | if (test_bit(__I40E_TESTING, &pf->state)) { |
Greg Rose | e17bc41 | 2015-04-16 20:05:59 -0400 | [diff] [blame] | 1000 | dev_warn(&pdev->dev, |
| 1001 | "Cannot enable SR-IOV virtual functions while the device is undergoing diagnostic testing\n"); |
| 1002 | err = -EPERM; |
| 1003 | goto err_out; |
| 1004 | } |
| 1005 | |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1006 | if (pre_existing_vfs && pre_existing_vfs != num_vfs) |
| 1007 | i40e_free_vfs(pf); |
| 1008 | else if (pre_existing_vfs && pre_existing_vfs == num_vfs) |
| 1009 | goto out; |
| 1010 | |
| 1011 | if (num_vfs > pf->num_req_vfs) { |
Mitch Williams | 96c8d07 | 2015-08-27 11:42:35 -0400 | [diff] [blame] | 1012 | dev_warn(&pdev->dev, "Unable to enable %d VFs. Limited to %d VFs due to device resource constraints.\n", |
| 1013 | num_vfs, pf->num_req_vfs); |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1014 | err = -EPERM; |
| 1015 | goto err_out; |
| 1016 | } |
| 1017 | |
Mitch Williams | 96c8d07 | 2015-08-27 11:42:35 -0400 | [diff] [blame] | 1018 | dev_info(&pdev->dev, "Allocating %d VFs.\n", num_vfs); |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1019 | err = i40e_alloc_vfs(pf, num_vfs); |
| 1020 | if (err) { |
| 1021 | dev_warn(&pdev->dev, "Failed to enable SR-IOV: %d\n", err); |
| 1022 | goto err_out; |
| 1023 | } |
| 1024 | |
| 1025 | out: |
| 1026 | return num_vfs; |
| 1027 | |
| 1028 | err_out: |
| 1029 | return err; |
| 1030 | #endif |
| 1031 | return 0; |
| 1032 | } |
| 1033 | |
| 1034 | /** |
| 1035 | * i40e_pci_sriov_configure |
| 1036 | * @pdev: pointer to a pci_dev structure |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 1037 | * @num_vfs: number of VFs to allocate |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1038 | * |
| 1039 | * Enable or change the number of VFs. Called when the user updates the number |
| 1040 | * of VFs in sysfs. |
| 1041 | **/ |
| 1042 | int i40e_pci_sriov_configure(struct pci_dev *pdev, int num_vfs) |
| 1043 | { |
| 1044 | struct i40e_pf *pf = pci_get_drvdata(pdev); |
| 1045 | |
Anjali Singhai Jain | fc60861 | 2015-05-08 15:35:57 -0700 | [diff] [blame] | 1046 | if (num_vfs) { |
| 1047 | if (!(pf->flags & I40E_FLAG_VEB_MODE_ENABLED)) { |
| 1048 | pf->flags |= I40E_FLAG_VEB_MODE_ENABLED; |
| 1049 | i40e_do_reset_safe(pf, |
| 1050 | BIT_ULL(__I40E_PF_RESET_REQUESTED)); |
| 1051 | } |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1052 | return i40e_pci_sriov_enable(pdev, num_vfs); |
Anjali Singhai Jain | fc60861 | 2015-05-08 15:35:57 -0700 | [diff] [blame] | 1053 | } |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1054 | |
Ethan Zhao | c24817b | 2014-07-22 18:36:43 +0000 | [diff] [blame] | 1055 | if (!pci_vfs_assigned(pf->pdev)) { |
Mitch Williams | 9e5634d | 2014-04-04 04:43:14 +0000 | [diff] [blame] | 1056 | i40e_free_vfs(pf); |
Anjali Singhai Jain | fc60861 | 2015-05-08 15:35:57 -0700 | [diff] [blame] | 1057 | pf->flags &= ~I40E_FLAG_VEB_MODE_ENABLED; |
| 1058 | i40e_do_reset_safe(pf, BIT_ULL(__I40E_PF_RESET_REQUESTED)); |
Mitch Williams | 9e5634d | 2014-04-04 04:43:14 +0000 | [diff] [blame] | 1059 | } else { |
| 1060 | dev_warn(&pdev->dev, "Unable to free VFs because some are assigned to VMs.\n"); |
| 1061 | return -EINVAL; |
| 1062 | } |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1063 | return 0; |
| 1064 | } |
| 1065 | |
| 1066 | /***********************virtual channel routines******************/ |
| 1067 | |
| 1068 | /** |
| 1069 | * i40e_vc_send_msg_to_vf |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 1070 | * @vf: pointer to the VF info |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1071 | * @v_opcode: virtual channel opcode |
| 1072 | * @v_retval: virtual channel return value |
| 1073 | * @msg: pointer to the msg buffer |
| 1074 | * @msglen: msg length |
| 1075 | * |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 1076 | * send msg to VF |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1077 | **/ |
| 1078 | static int i40e_vc_send_msg_to_vf(struct i40e_vf *vf, u32 v_opcode, |
| 1079 | u32 v_retval, u8 *msg, u16 msglen) |
| 1080 | { |
Anjali Singhai Jain | 6e7b5bd | 2014-07-10 07:58:21 +0000 | [diff] [blame] | 1081 | struct i40e_pf *pf; |
| 1082 | struct i40e_hw *hw; |
| 1083 | int abs_vf_id; |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1084 | i40e_status aq_ret; |
| 1085 | |
Anjali Singhai Jain | 6e7b5bd | 2014-07-10 07:58:21 +0000 | [diff] [blame] | 1086 | /* validate the request */ |
| 1087 | if (!vf || vf->vf_id >= vf->pf->num_alloc_vfs) |
| 1088 | return -EINVAL; |
| 1089 | |
| 1090 | pf = vf->pf; |
| 1091 | hw = &pf->hw; |
| 1092 | abs_vf_id = vf->vf_id + hw->func_caps.vf_base_id; |
| 1093 | |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1094 | /* single place to detect unsuccessful return values */ |
| 1095 | if (v_retval) { |
| 1096 | vf->num_invalid_msgs++; |
Mitch Williams | e7ffb72 | 2015-10-26 19:44:37 -0400 | [diff] [blame] | 1097 | dev_err(&pf->pdev->dev, "VF %d failed opcode %d, error: %d\n", |
| 1098 | vf->vf_id, v_opcode, v_retval); |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1099 | if (vf->num_invalid_msgs > |
| 1100 | I40E_DEFAULT_NUM_INVALID_MSGS_ALLOWED) { |
| 1101 | dev_err(&pf->pdev->dev, |
| 1102 | "Number of invalid messages exceeded for VF %d\n", |
| 1103 | vf->vf_id); |
| 1104 | dev_err(&pf->pdev->dev, "Use PF Control I/F to enable the VF\n"); |
| 1105 | set_bit(I40E_VF_STAT_DISABLED, &vf->vf_states); |
| 1106 | } |
| 1107 | } else { |
| 1108 | vf->num_valid_msgs++; |
Jingjing Wu | 5d38c93 | 2015-09-28 14:12:39 -0400 | [diff] [blame] | 1109 | /* reset the invalid counter, if a valid message is received. */ |
| 1110 | vf->num_invalid_msgs = 0; |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1111 | } |
| 1112 | |
Ashish Shah | f19efbb | 2014-08-01 13:27:06 -0700 | [diff] [blame] | 1113 | 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] | 1114 | msg, msglen, NULL); |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1115 | if (aq_ret) { |
| 1116 | dev_err(&pf->pdev->dev, |
| 1117 | "Unable to send the message to VF %d aq_err %d\n", |
| 1118 | vf->vf_id, pf->hw.aq.asq_last_status); |
| 1119 | return -EIO; |
| 1120 | } |
| 1121 | |
| 1122 | return 0; |
| 1123 | } |
| 1124 | |
| 1125 | /** |
| 1126 | * i40e_vc_send_resp_to_vf |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 1127 | * @vf: pointer to the VF info |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1128 | * @opcode: operation code |
| 1129 | * @retval: return value |
| 1130 | * |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 1131 | * send resp msg to VF |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1132 | **/ |
| 1133 | static int i40e_vc_send_resp_to_vf(struct i40e_vf *vf, |
| 1134 | enum i40e_virtchnl_ops opcode, |
| 1135 | i40e_status retval) |
| 1136 | { |
| 1137 | return i40e_vc_send_msg_to_vf(vf, opcode, retval, NULL, 0); |
| 1138 | } |
| 1139 | |
| 1140 | /** |
| 1141 | * i40e_vc_get_version_msg |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 1142 | * @vf: pointer to the VF info |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1143 | * |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 1144 | * 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] | 1145 | **/ |
Mitch Williams | f4ca1a2 | 2015-06-04 16:23:57 -0400 | [diff] [blame] | 1146 | 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] | 1147 | { |
| 1148 | struct i40e_virtchnl_version_info info = { |
| 1149 | I40E_VIRTCHNL_VERSION_MAJOR, I40E_VIRTCHNL_VERSION_MINOR |
| 1150 | }; |
| 1151 | |
Mitch Williams | f4ca1a2 | 2015-06-04 16:23:57 -0400 | [diff] [blame] | 1152 | vf->vf_ver = *(struct i40e_virtchnl_version_info *)msg; |
Mitch Williams | 606a548 | 2015-06-04 16:24:00 -0400 | [diff] [blame] | 1153 | /* VFs running the 1.0 API expect to get 1.0 back or they will cry. */ |
| 1154 | if (VF_IS_V10(vf)) |
| 1155 | info.minor = I40E_VIRTCHNL_VERSION_MINOR_NO_VF_CAPS; |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1156 | return i40e_vc_send_msg_to_vf(vf, I40E_VIRTCHNL_OP_VERSION, |
| 1157 | I40E_SUCCESS, (u8 *)&info, |
| 1158 | sizeof(struct |
| 1159 | i40e_virtchnl_version_info)); |
| 1160 | } |
| 1161 | |
| 1162 | /** |
| 1163 | * i40e_vc_get_vf_resources_msg |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 1164 | * @vf: pointer to the VF info |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1165 | * @msg: pointer to the msg buffer |
| 1166 | * @msglen: msg length |
| 1167 | * |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 1168 | * called from the VF to request its resources |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1169 | **/ |
Mitch Williams | f4ca1a2 | 2015-06-04 16:23:57 -0400 | [diff] [blame] | 1170 | 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] | 1171 | { |
| 1172 | struct i40e_virtchnl_vf_resource *vfres = NULL; |
| 1173 | struct i40e_pf *pf = vf->pf; |
| 1174 | i40e_status aq_ret = 0; |
| 1175 | struct i40e_vsi *vsi; |
| 1176 | int i = 0, len = 0; |
| 1177 | int num_vsis = 1; |
| 1178 | int ret; |
| 1179 | |
| 1180 | if (!test_bit(I40E_VF_STAT_INIT, &vf->vf_states)) { |
| 1181 | aq_ret = I40E_ERR_PARAM; |
| 1182 | goto err; |
| 1183 | } |
| 1184 | |
| 1185 | len = (sizeof(struct i40e_virtchnl_vf_resource) + |
| 1186 | sizeof(struct i40e_virtchnl_vsi_resource) * num_vsis); |
| 1187 | |
| 1188 | vfres = kzalloc(len, GFP_KERNEL); |
| 1189 | if (!vfres) { |
| 1190 | aq_ret = I40E_ERR_NO_MEMORY; |
| 1191 | len = 0; |
| 1192 | goto err; |
| 1193 | } |
Mitch Williams | f4ca1a2 | 2015-06-04 16:23:57 -0400 | [diff] [blame] | 1194 | if (VF_IS_V11(vf)) |
| 1195 | vf->driver_caps = *(u32 *)msg; |
| 1196 | else |
| 1197 | vf->driver_caps = I40E_VIRTCHNL_VF_OFFLOAD_L2 | |
| 1198 | I40E_VIRTCHNL_VF_OFFLOAD_RSS_REG | |
| 1199 | I40E_VIRTCHNL_VF_OFFLOAD_VLAN; |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1200 | |
| 1201 | vfres->vf_offload_flags = I40E_VIRTCHNL_VF_OFFLOAD_L2; |
Anjali Singhai Jain | fdf0e0b | 2015-03-31 00:45:05 -0700 | [diff] [blame] | 1202 | vsi = pf->vsi[vf->lan_vsi_idx]; |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1203 | if (!vsi->info.pvid) |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 1204 | vfres->vf_offload_flags |= I40E_VIRTCHNL_VF_OFFLOAD_VLAN; |
| 1205 | if (pf->flags & I40E_FLAG_RSS_AQ_CAPABLE) { |
| 1206 | if (vf->driver_caps & I40E_VIRTCHNL_VF_OFFLOAD_RSS_AQ) |
| 1207 | vfres->vf_offload_flags |= |
| 1208 | I40E_VIRTCHNL_VF_OFFLOAD_RSS_AQ; |
| 1209 | } else { |
| 1210 | vfres->vf_offload_flags |= I40E_VIRTCHNL_VF_OFFLOAD_RSS_REG; |
| 1211 | } |
Anjali Singhai Jain | 1f01227 | 2015-09-03 17:18:53 -0400 | [diff] [blame] | 1212 | |
| 1213 | if (vf->driver_caps & I40E_VIRTCHNL_VF_OFFLOAD_RX_POLLING) |
| 1214 | vfres->vf_offload_flags |= I40E_VIRTCHNL_VF_OFFLOAD_RX_POLLING; |
| 1215 | |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1216 | vfres->num_vsis = num_vsis; |
| 1217 | vfres->num_queue_pairs = vf->num_queue_pairs; |
| 1218 | vfres->max_vectors = pf->hw.func_caps.num_msix_vectors_vf; |
Anjali Singhai Jain | fdf0e0b | 2015-03-31 00:45:05 -0700 | [diff] [blame] | 1219 | if (vf->lan_vsi_idx) { |
| 1220 | vfres->vsi_res[i].vsi_id = vf->lan_vsi_id; |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1221 | vfres->vsi_res[i].vsi_type = I40E_VSI_SRIOV; |
Mitch Williams | f578f5f | 2015-08-28 17:55:58 -0400 | [diff] [blame] | 1222 | vfres->vsi_res[i].num_queue_pairs = vsi->alloc_queue_pairs; |
| 1223 | /* VFs only use TC 0 */ |
| 1224 | vfres->vsi_res[i].qset_handle |
| 1225 | = le16_to_cpu(vsi->info.qs_handle[0]); |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 1226 | ether_addr_copy(vfres->vsi_res[i].default_mac_addr, |
| 1227 | vf->default_lan_addr.addr); |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1228 | i++; |
| 1229 | } |
| 1230 | set_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states); |
| 1231 | |
| 1232 | err: |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 1233 | /* send the response back to the VF */ |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1234 | ret = i40e_vc_send_msg_to_vf(vf, I40E_VIRTCHNL_OP_GET_VF_RESOURCES, |
| 1235 | aq_ret, (u8 *)vfres, len); |
| 1236 | |
| 1237 | kfree(vfres); |
| 1238 | return ret; |
| 1239 | } |
| 1240 | |
| 1241 | /** |
| 1242 | * i40e_vc_reset_vf_msg |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 1243 | * @vf: pointer to the VF info |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1244 | * @msg: pointer to the msg buffer |
| 1245 | * @msglen: msg length |
| 1246 | * |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 1247 | * called from the VF to reset itself, |
| 1248 | * unlike other virtchnl messages, PF driver |
| 1249 | * doesn't send the response back to the VF |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1250 | **/ |
Mitch Williams | fc18eaa | 2013-11-28 06:39:27 +0000 | [diff] [blame] | 1251 | static void i40e_vc_reset_vf_msg(struct i40e_vf *vf) |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1252 | { |
Mitch Williams | fc18eaa | 2013-11-28 06:39:27 +0000 | [diff] [blame] | 1253 | if (test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states)) |
| 1254 | i40e_reset_vf(vf, false); |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1255 | } |
| 1256 | |
| 1257 | /** |
| 1258 | * i40e_vc_config_promiscuous_mode_msg |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 1259 | * @vf: pointer to the VF info |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1260 | * @msg: pointer to the msg buffer |
| 1261 | * @msglen: msg length |
| 1262 | * |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 1263 | * called from the VF to configure the promiscuous mode of |
| 1264 | * VF vsis |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1265 | **/ |
| 1266 | static int i40e_vc_config_promiscuous_mode_msg(struct i40e_vf *vf, |
| 1267 | u8 *msg, u16 msglen) |
| 1268 | { |
| 1269 | struct i40e_virtchnl_promisc_info *info = |
| 1270 | (struct i40e_virtchnl_promisc_info *)msg; |
| 1271 | struct i40e_pf *pf = vf->pf; |
| 1272 | struct i40e_hw *hw = &pf->hw; |
Ashish Shah | 89cb86c | 2014-08-01 13:27:10 -0700 | [diff] [blame] | 1273 | struct i40e_vsi *vsi; |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1274 | bool allmulti = false; |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1275 | i40e_status aq_ret; |
| 1276 | |
Anjali Singhai Jain | fdf0e0b | 2015-03-31 00:45:05 -0700 | [diff] [blame] | 1277 | vsi = i40e_find_vsi_from_id(pf, info->vsi_id); |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1278 | if (!test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states) || |
| 1279 | !test_bit(I40E_VIRTCHNL_VF_CAP_PRIVILEGE, &vf->vf_caps) || |
| 1280 | !i40e_vc_isvalid_vsi_id(vf, info->vsi_id) || |
Anjali Singhai Jain | fdf0e0b | 2015-03-31 00:45:05 -0700 | [diff] [blame] | 1281 | (vsi->type != I40E_VSI_FCOE)) { |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1282 | aq_ret = I40E_ERR_PARAM; |
| 1283 | goto error_param; |
| 1284 | } |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1285 | if (info->flags & I40E_FLAG_VF_MULTICAST_PROMISC) |
| 1286 | allmulti = true; |
Ashish Shah | 89cb86c | 2014-08-01 13:27:10 -0700 | [diff] [blame] | 1287 | aq_ret = i40e_aq_set_vsi_multicast_promiscuous(hw, vsi->seid, |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1288 | allmulti, NULL); |
| 1289 | |
| 1290 | error_param: |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 1291 | /* send the response to the VF */ |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1292 | return i40e_vc_send_resp_to_vf(vf, |
| 1293 | I40E_VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE, |
| 1294 | aq_ret); |
| 1295 | } |
| 1296 | |
| 1297 | /** |
| 1298 | * i40e_vc_config_queues_msg |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 1299 | * @vf: pointer to the VF info |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1300 | * @msg: pointer to the msg buffer |
| 1301 | * @msglen: msg length |
| 1302 | * |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 1303 | * called from the VF to configure the rx/tx |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1304 | * queues |
| 1305 | **/ |
| 1306 | static int i40e_vc_config_queues_msg(struct i40e_vf *vf, u8 *msg, u16 msglen) |
| 1307 | { |
| 1308 | struct i40e_virtchnl_vsi_queue_config_info *qci = |
| 1309 | (struct i40e_virtchnl_vsi_queue_config_info *)msg; |
| 1310 | struct i40e_virtchnl_queue_pair_info *qpi; |
Ashish Shah | 5f5e33b | 2014-07-10 07:58:15 +0000 | [diff] [blame] | 1311 | struct i40e_pf *pf = vf->pf; |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1312 | u16 vsi_id, vsi_queue_id; |
| 1313 | i40e_status aq_ret = 0; |
| 1314 | int i; |
| 1315 | |
| 1316 | if (!test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states)) { |
| 1317 | aq_ret = I40E_ERR_PARAM; |
| 1318 | goto error_param; |
| 1319 | } |
| 1320 | |
| 1321 | vsi_id = qci->vsi_id; |
| 1322 | if (!i40e_vc_isvalid_vsi_id(vf, vsi_id)) { |
| 1323 | aq_ret = I40E_ERR_PARAM; |
| 1324 | goto error_param; |
| 1325 | } |
| 1326 | for (i = 0; i < qci->num_queue_pairs; i++) { |
| 1327 | qpi = &qci->qpair[i]; |
| 1328 | vsi_queue_id = qpi->txq.queue_id; |
| 1329 | if ((qpi->txq.vsi_id != vsi_id) || |
| 1330 | (qpi->rxq.vsi_id != vsi_id) || |
| 1331 | (qpi->rxq.queue_id != vsi_queue_id) || |
| 1332 | !i40e_vc_isvalid_queue_id(vf, vsi_id, vsi_queue_id)) { |
| 1333 | aq_ret = I40E_ERR_PARAM; |
| 1334 | goto error_param; |
| 1335 | } |
| 1336 | |
| 1337 | if (i40e_config_vsi_rx_queue(vf, vsi_id, vsi_queue_id, |
| 1338 | &qpi->rxq) || |
| 1339 | i40e_config_vsi_tx_queue(vf, vsi_id, vsi_queue_id, |
| 1340 | &qpi->txq)) { |
| 1341 | aq_ret = I40E_ERR_PARAM; |
| 1342 | goto error_param; |
| 1343 | } |
| 1344 | } |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 1345 | /* 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] | 1346 | 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] | 1347 | |
| 1348 | error_param: |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 1349 | /* send the response to the VF */ |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1350 | return i40e_vc_send_resp_to_vf(vf, I40E_VIRTCHNL_OP_CONFIG_VSI_QUEUES, |
| 1351 | aq_ret); |
| 1352 | } |
| 1353 | |
| 1354 | /** |
| 1355 | * i40e_vc_config_irq_map_msg |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 1356 | * @vf: pointer to the VF info |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1357 | * @msg: pointer to the msg buffer |
| 1358 | * @msglen: msg length |
| 1359 | * |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 1360 | * called from the VF to configure the irq to |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1361 | * queue map |
| 1362 | **/ |
| 1363 | static int i40e_vc_config_irq_map_msg(struct i40e_vf *vf, u8 *msg, u16 msglen) |
| 1364 | { |
| 1365 | struct i40e_virtchnl_irq_map_info *irqmap_info = |
| 1366 | (struct i40e_virtchnl_irq_map_info *)msg; |
| 1367 | struct i40e_virtchnl_vector_map *map; |
| 1368 | u16 vsi_id, vsi_queue_id, vector_id; |
| 1369 | i40e_status aq_ret = 0; |
| 1370 | unsigned long tempmap; |
| 1371 | int i; |
| 1372 | |
| 1373 | if (!test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states)) { |
| 1374 | aq_ret = I40E_ERR_PARAM; |
| 1375 | goto error_param; |
| 1376 | } |
| 1377 | |
| 1378 | for (i = 0; i < irqmap_info->num_vectors; i++) { |
| 1379 | map = &irqmap_info->vecmap[i]; |
| 1380 | |
| 1381 | vector_id = map->vector_id; |
| 1382 | vsi_id = map->vsi_id; |
| 1383 | /* validate msg params */ |
| 1384 | if (!i40e_vc_isvalid_vector_id(vf, vector_id) || |
| 1385 | !i40e_vc_isvalid_vsi_id(vf, vsi_id)) { |
| 1386 | aq_ret = I40E_ERR_PARAM; |
| 1387 | goto error_param; |
| 1388 | } |
| 1389 | |
| 1390 | /* lookout for the invalid queue index */ |
| 1391 | tempmap = map->rxq_map; |
Wei Yongjun | 4836650 | 2013-09-24 05:17:36 +0000 | [diff] [blame] | 1392 | for_each_set_bit(vsi_queue_id, &tempmap, I40E_MAX_VSI_QP) { |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1393 | if (!i40e_vc_isvalid_queue_id(vf, vsi_id, |
| 1394 | vsi_queue_id)) { |
| 1395 | aq_ret = I40E_ERR_PARAM; |
| 1396 | goto error_param; |
| 1397 | } |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1398 | } |
| 1399 | |
| 1400 | tempmap = map->txq_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 | i40e_config_irq_link_list(vf, vsi_id, map); |
| 1410 | } |
| 1411 | error_param: |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 1412 | /* send the response to the VF */ |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1413 | return i40e_vc_send_resp_to_vf(vf, I40E_VIRTCHNL_OP_CONFIG_IRQ_MAP, |
| 1414 | aq_ret); |
| 1415 | } |
| 1416 | |
| 1417 | /** |
| 1418 | * i40e_vc_enable_queues_msg |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 1419 | * @vf: pointer to the VF info |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1420 | * @msg: pointer to the msg buffer |
| 1421 | * @msglen: msg length |
| 1422 | * |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 1423 | * called from the VF to enable all or specific queue(s) |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1424 | **/ |
| 1425 | static int i40e_vc_enable_queues_msg(struct i40e_vf *vf, u8 *msg, u16 msglen) |
| 1426 | { |
| 1427 | struct i40e_virtchnl_queue_select *vqs = |
| 1428 | (struct i40e_virtchnl_queue_select *)msg; |
| 1429 | struct i40e_pf *pf = vf->pf; |
| 1430 | u16 vsi_id = vqs->vsi_id; |
| 1431 | i40e_status aq_ret = 0; |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1432 | |
| 1433 | if (!test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states)) { |
| 1434 | aq_ret = I40E_ERR_PARAM; |
| 1435 | goto error_param; |
| 1436 | } |
| 1437 | |
| 1438 | if (!i40e_vc_isvalid_vsi_id(vf, vsi_id)) { |
| 1439 | aq_ret = I40E_ERR_PARAM; |
| 1440 | goto error_param; |
| 1441 | } |
| 1442 | |
| 1443 | if ((0 == vqs->rx_queues) && (0 == vqs->tx_queues)) { |
| 1444 | aq_ret = I40E_ERR_PARAM; |
| 1445 | goto error_param; |
| 1446 | } |
Anjali Singhai Jain | fdf0e0b | 2015-03-31 00:45:05 -0700 | [diff] [blame] | 1447 | |
| 1448 | if (i40e_vsi_control_rings(pf->vsi[vf->lan_vsi_idx], true)) |
Mitch Williams | 88f6563 | 2013-11-28 06:39:28 +0000 | [diff] [blame] | 1449 | aq_ret = I40E_ERR_TIMEOUT; |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1450 | error_param: |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 1451 | /* send the response to the VF */ |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1452 | return i40e_vc_send_resp_to_vf(vf, I40E_VIRTCHNL_OP_ENABLE_QUEUES, |
| 1453 | aq_ret); |
| 1454 | } |
| 1455 | |
| 1456 | /** |
| 1457 | * i40e_vc_disable_queues_msg |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 1458 | * @vf: pointer to the VF info |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1459 | * @msg: pointer to the msg buffer |
| 1460 | * @msglen: msg length |
| 1461 | * |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 1462 | * called from the VF to disable all or specific |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1463 | * queue(s) |
| 1464 | **/ |
| 1465 | static int i40e_vc_disable_queues_msg(struct i40e_vf *vf, u8 *msg, u16 msglen) |
| 1466 | { |
| 1467 | struct i40e_virtchnl_queue_select *vqs = |
| 1468 | (struct i40e_virtchnl_queue_select *)msg; |
| 1469 | struct i40e_pf *pf = vf->pf; |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1470 | i40e_status aq_ret = 0; |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1471 | |
| 1472 | if (!test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states)) { |
| 1473 | aq_ret = I40E_ERR_PARAM; |
| 1474 | goto error_param; |
| 1475 | } |
| 1476 | |
| 1477 | if (!i40e_vc_isvalid_vsi_id(vf, vqs->vsi_id)) { |
| 1478 | aq_ret = I40E_ERR_PARAM; |
| 1479 | goto error_param; |
| 1480 | } |
| 1481 | |
| 1482 | if ((0 == vqs->rx_queues) && (0 == vqs->tx_queues)) { |
| 1483 | aq_ret = I40E_ERR_PARAM; |
| 1484 | goto error_param; |
| 1485 | } |
Anjali Singhai Jain | fdf0e0b | 2015-03-31 00:45:05 -0700 | [diff] [blame] | 1486 | |
| 1487 | if (i40e_vsi_control_rings(pf->vsi[vf->lan_vsi_idx], false)) |
Mitch Williams | 88f6563 | 2013-11-28 06:39:28 +0000 | [diff] [blame] | 1488 | aq_ret = I40E_ERR_TIMEOUT; |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1489 | |
| 1490 | error_param: |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 1491 | /* send the response to the VF */ |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1492 | return i40e_vc_send_resp_to_vf(vf, I40E_VIRTCHNL_OP_DISABLE_QUEUES, |
| 1493 | aq_ret); |
| 1494 | } |
| 1495 | |
| 1496 | /** |
| 1497 | * i40e_vc_get_stats_msg |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 1498 | * @vf: pointer to the VF info |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1499 | * @msg: pointer to the msg buffer |
| 1500 | * @msglen: msg length |
| 1501 | * |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 1502 | * called from the VF to get vsi stats |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1503 | **/ |
| 1504 | static int i40e_vc_get_stats_msg(struct i40e_vf *vf, u8 *msg, u16 msglen) |
| 1505 | { |
| 1506 | struct i40e_virtchnl_queue_select *vqs = |
| 1507 | (struct i40e_virtchnl_queue_select *)msg; |
| 1508 | struct i40e_pf *pf = vf->pf; |
| 1509 | struct i40e_eth_stats stats; |
| 1510 | i40e_status aq_ret = 0; |
| 1511 | struct i40e_vsi *vsi; |
| 1512 | |
| 1513 | memset(&stats, 0, sizeof(struct i40e_eth_stats)); |
| 1514 | |
| 1515 | if (!test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states)) { |
| 1516 | aq_ret = I40E_ERR_PARAM; |
| 1517 | goto error_param; |
| 1518 | } |
| 1519 | |
| 1520 | if (!i40e_vc_isvalid_vsi_id(vf, vqs->vsi_id)) { |
| 1521 | aq_ret = I40E_ERR_PARAM; |
| 1522 | goto error_param; |
| 1523 | } |
| 1524 | |
Anjali Singhai Jain | fdf0e0b | 2015-03-31 00:45:05 -0700 | [diff] [blame] | 1525 | vsi = pf->vsi[vf->lan_vsi_idx]; |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1526 | if (!vsi) { |
| 1527 | aq_ret = I40E_ERR_PARAM; |
| 1528 | goto error_param; |
| 1529 | } |
| 1530 | i40e_update_eth_stats(vsi); |
Mitch Williams | 5a9769c | 2013-11-28 06:39:38 +0000 | [diff] [blame] | 1531 | stats = vsi->eth_stats; |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1532 | |
| 1533 | error_param: |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 1534 | /* send the response back to the VF */ |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1535 | return i40e_vc_send_msg_to_vf(vf, I40E_VIRTCHNL_OP_GET_STATS, aq_ret, |
| 1536 | (u8 *)&stats, sizeof(stats)); |
| 1537 | } |
| 1538 | |
| 1539 | /** |
Greg Rose | f657a6e | 2013-11-28 06:39:42 +0000 | [diff] [blame] | 1540 | * i40e_check_vf_permission |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 1541 | * @vf: pointer to the VF info |
Greg Rose | f657a6e | 2013-11-28 06:39:42 +0000 | [diff] [blame] | 1542 | * @macaddr: pointer to the MAC Address being checked |
| 1543 | * |
| 1544 | * Check if the VF has permission to add or delete unicast MAC address |
| 1545 | * filters and return error code -EPERM if not. Then check if the |
| 1546 | * address filter requested is broadcast or zero and if so return |
| 1547 | * an invalid MAC address error code. |
| 1548 | **/ |
| 1549 | static inline int i40e_check_vf_permission(struct i40e_vf *vf, u8 *macaddr) |
| 1550 | { |
| 1551 | struct i40e_pf *pf = vf->pf; |
| 1552 | int ret = 0; |
| 1553 | |
| 1554 | if (is_broadcast_ether_addr(macaddr) || |
| 1555 | is_zero_ether_addr(macaddr)) { |
| 1556 | dev_err(&pf->pdev->dev, "invalid VF MAC addr %pM\n", macaddr); |
| 1557 | ret = I40E_ERR_INVALID_MAC_ADDR; |
Greg Rose | 5017c2a | 2013-12-07 10:36:54 +0000 | [diff] [blame] | 1558 | } else if (vf->pf_set_mac && !is_multicast_ether_addr(macaddr) && |
| 1559 | !ether_addr_equal(macaddr, vf->default_lan_addr.addr)) { |
Greg Rose | f657a6e | 2013-11-28 06:39:42 +0000 | [diff] [blame] | 1560 | /* If the host VMM administrator has set the VF MAC address |
| 1561 | * administratively via the ndo_set_vf_mac command then deny |
| 1562 | * permission to the VF to add or delete unicast MAC addresses. |
Greg Rose | 5017c2a | 2013-12-07 10:36:54 +0000 | [diff] [blame] | 1563 | * The VF may request to set the MAC address filter already |
| 1564 | * assigned to it so do not return an error in that case. |
Greg Rose | f657a6e | 2013-11-28 06:39:42 +0000 | [diff] [blame] | 1565 | */ |
| 1566 | dev_err(&pf->pdev->dev, |
| 1567 | "VF attempting to override administratively set MAC address\nPlease reload the VF driver to resume normal operation\n"); |
| 1568 | ret = -EPERM; |
| 1569 | } |
| 1570 | return ret; |
| 1571 | } |
| 1572 | |
| 1573 | /** |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1574 | * i40e_vc_add_mac_addr_msg |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 1575 | * @vf: pointer to the VF info |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1576 | * @msg: pointer to the msg buffer |
| 1577 | * @msglen: msg length |
| 1578 | * |
| 1579 | * add guest mac address filter |
| 1580 | **/ |
| 1581 | static int i40e_vc_add_mac_addr_msg(struct i40e_vf *vf, u8 *msg, u16 msglen) |
| 1582 | { |
| 1583 | struct i40e_virtchnl_ether_addr_list *al = |
| 1584 | (struct i40e_virtchnl_ether_addr_list *)msg; |
| 1585 | struct i40e_pf *pf = vf->pf; |
| 1586 | struct i40e_vsi *vsi = NULL; |
| 1587 | u16 vsi_id = al->vsi_id; |
Greg Rose | f657a6e | 2013-11-28 06:39:42 +0000 | [diff] [blame] | 1588 | i40e_status ret = 0; |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1589 | int i; |
| 1590 | |
| 1591 | if (!test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states) || |
| 1592 | !test_bit(I40E_VIRTCHNL_VF_CAP_PRIVILEGE, &vf->vf_caps) || |
| 1593 | !i40e_vc_isvalid_vsi_id(vf, vsi_id)) { |
Greg Rose | f657a6e | 2013-11-28 06:39:42 +0000 | [diff] [blame] | 1594 | ret = I40E_ERR_PARAM; |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1595 | goto error_param; |
| 1596 | } |
| 1597 | |
| 1598 | for (i = 0; i < al->num_elements; i++) { |
Greg Rose | f657a6e | 2013-11-28 06:39:42 +0000 | [diff] [blame] | 1599 | ret = i40e_check_vf_permission(vf, al->list[i].addr); |
| 1600 | if (ret) |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1601 | goto error_param; |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1602 | } |
Anjali Singhai Jain | fdf0e0b | 2015-03-31 00:45:05 -0700 | [diff] [blame] | 1603 | vsi = pf->vsi[vf->lan_vsi_idx]; |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1604 | |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1605 | /* Lock once, because all function inside for loop accesses VSI's |
| 1606 | * MAC filter list which needs to be protected using same lock. |
| 1607 | */ |
| 1608 | spin_lock_bh(&vsi->mac_filter_list_lock); |
| 1609 | |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1610 | /* add new addresses to the list */ |
| 1611 | for (i = 0; i < al->num_elements; i++) { |
| 1612 | struct i40e_mac_filter *f; |
| 1613 | |
| 1614 | f = i40e_find_mac(vsi, al->list[i].addr, true, false); |
Mitch Williams | 7e68edf9 | 2013-11-16 10:00:41 +0000 | [diff] [blame] | 1615 | if (!f) { |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1616 | if (i40e_is_vsi_in_vlan(vsi)) |
| 1617 | f = i40e_put_mac_in_vlan(vsi, al->list[i].addr, |
| 1618 | true, false); |
| 1619 | else |
| 1620 | f = i40e_add_filter(vsi, al->list[i].addr, -1, |
| 1621 | true, false); |
| 1622 | } |
| 1623 | |
| 1624 | if (!f) { |
| 1625 | dev_err(&pf->pdev->dev, |
Mitch Williams | 8d8f229 | 2015-10-21 19:47:11 -0400 | [diff] [blame] | 1626 | "Unable to add MAC filter %pM for VF %d\n", |
| 1627 | al->list[i].addr, vf->vf_id); |
Greg Rose | f657a6e | 2013-11-28 06:39:42 +0000 | [diff] [blame] | 1628 | ret = I40E_ERR_PARAM; |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1629 | spin_unlock_bh(&vsi->mac_filter_list_lock); |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1630 | goto error_param; |
| 1631 | } |
| 1632 | } |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1633 | spin_unlock_bh(&vsi->mac_filter_list_lock); |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1634 | |
| 1635 | /* program the updated filter list */ |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 1636 | ret = i40e_sync_vsi_filters(vsi); |
| 1637 | if (ret) |
| 1638 | dev_err(&pf->pdev->dev, "Unable to program VF %d MAC filters, error %d\n", |
| 1639 | vf->vf_id, ret); |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1640 | |
| 1641 | error_param: |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 1642 | /* send the response to the VF */ |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1643 | 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] | 1644 | ret); |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1645 | } |
| 1646 | |
| 1647 | /** |
| 1648 | * i40e_vc_del_mac_addr_msg |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 1649 | * @vf: pointer to the VF info |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1650 | * @msg: pointer to the msg buffer |
| 1651 | * @msglen: msg length |
| 1652 | * |
| 1653 | * remove guest mac address filter |
| 1654 | **/ |
| 1655 | static int i40e_vc_del_mac_addr_msg(struct i40e_vf *vf, u8 *msg, u16 msglen) |
| 1656 | { |
| 1657 | struct i40e_virtchnl_ether_addr_list *al = |
| 1658 | (struct i40e_virtchnl_ether_addr_list *)msg; |
| 1659 | struct i40e_pf *pf = vf->pf; |
| 1660 | struct i40e_vsi *vsi = NULL; |
| 1661 | u16 vsi_id = al->vsi_id; |
Greg Rose | f657a6e | 2013-11-28 06:39:42 +0000 | [diff] [blame] | 1662 | i40e_status ret = 0; |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1663 | int i; |
| 1664 | |
| 1665 | if (!test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states) || |
| 1666 | !test_bit(I40E_VIRTCHNL_VF_CAP_PRIVILEGE, &vf->vf_caps) || |
| 1667 | !i40e_vc_isvalid_vsi_id(vf, vsi_id)) { |
Greg Rose | f657a6e | 2013-11-28 06:39:42 +0000 | [diff] [blame] | 1668 | ret = I40E_ERR_PARAM; |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1669 | goto error_param; |
| 1670 | } |
Greg Rose | f657a6e | 2013-11-28 06:39:42 +0000 | [diff] [blame] | 1671 | |
| 1672 | for (i = 0; i < al->num_elements; i++) { |
Mitch Williams | 700bbf6 | 2013-12-21 05:44:45 +0000 | [diff] [blame] | 1673 | if (is_broadcast_ether_addr(al->list[i].addr) || |
| 1674 | is_zero_ether_addr(al->list[i].addr)) { |
Mitch Williams | 8d8f229 | 2015-10-21 19:47:11 -0400 | [diff] [blame] | 1675 | dev_err(&pf->pdev->dev, "Invalid MAC addr %pM for VF %d\n", |
| 1676 | al->list[i].addr, vf->vf_id); |
Mitch Williams | 700bbf6 | 2013-12-21 05:44:45 +0000 | [diff] [blame] | 1677 | ret = I40E_ERR_INVALID_MAC_ADDR; |
Greg Rose | f657a6e | 2013-11-28 06:39:42 +0000 | [diff] [blame] | 1678 | goto error_param; |
Mitch Williams | 700bbf6 | 2013-12-21 05:44:45 +0000 | [diff] [blame] | 1679 | } |
Greg Rose | f657a6e | 2013-11-28 06:39:42 +0000 | [diff] [blame] | 1680 | } |
Anjali Singhai Jain | fdf0e0b | 2015-03-31 00:45:05 -0700 | [diff] [blame] | 1681 | vsi = pf->vsi[vf->lan_vsi_idx]; |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1682 | |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1683 | spin_lock_bh(&vsi->mac_filter_list_lock); |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1684 | /* delete addresses from the list */ |
| 1685 | for (i = 0; i < al->num_elements; i++) |
| 1686 | i40e_del_filter(vsi, al->list[i].addr, |
| 1687 | I40E_VLAN_ANY, true, false); |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1688 | spin_unlock_bh(&vsi->mac_filter_list_lock); |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1689 | |
| 1690 | /* program the updated filter list */ |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 1691 | ret = i40e_sync_vsi_filters(vsi); |
| 1692 | if (ret) |
| 1693 | dev_err(&pf->pdev->dev, "Unable to program VF %d MAC filters, error %d\n", |
| 1694 | vf->vf_id, ret); |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1695 | |
| 1696 | error_param: |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 1697 | /* send the response to the VF */ |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1698 | 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] | 1699 | ret); |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1700 | } |
| 1701 | |
| 1702 | /** |
| 1703 | * i40e_vc_add_vlan_msg |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 1704 | * @vf: pointer to the VF info |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1705 | * @msg: pointer to the msg buffer |
| 1706 | * @msglen: msg length |
| 1707 | * |
| 1708 | * program guest vlan id |
| 1709 | **/ |
| 1710 | static int i40e_vc_add_vlan_msg(struct i40e_vf *vf, u8 *msg, u16 msglen) |
| 1711 | { |
| 1712 | struct i40e_virtchnl_vlan_filter_list *vfl = |
| 1713 | (struct i40e_virtchnl_vlan_filter_list *)msg; |
| 1714 | struct i40e_pf *pf = vf->pf; |
| 1715 | struct i40e_vsi *vsi = NULL; |
| 1716 | u16 vsi_id = vfl->vsi_id; |
| 1717 | i40e_status aq_ret = 0; |
| 1718 | int i; |
| 1719 | |
| 1720 | if (!test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states) || |
| 1721 | !test_bit(I40E_VIRTCHNL_VF_CAP_PRIVILEGE, &vf->vf_caps) || |
| 1722 | !i40e_vc_isvalid_vsi_id(vf, vsi_id)) { |
| 1723 | aq_ret = I40E_ERR_PARAM; |
| 1724 | goto error_param; |
| 1725 | } |
| 1726 | |
| 1727 | for (i = 0; i < vfl->num_elements; i++) { |
| 1728 | if (vfl->vlan_id[i] > I40E_MAX_VLANID) { |
| 1729 | aq_ret = I40E_ERR_PARAM; |
| 1730 | dev_err(&pf->pdev->dev, |
| 1731 | "invalid VF VLAN id %d\n", vfl->vlan_id[i]); |
| 1732 | goto error_param; |
| 1733 | } |
| 1734 | } |
Anjali Singhai Jain | fdf0e0b | 2015-03-31 00:45:05 -0700 | [diff] [blame] | 1735 | vsi = pf->vsi[vf->lan_vsi_idx]; |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1736 | if (vsi->info.pvid) { |
| 1737 | aq_ret = I40E_ERR_PARAM; |
| 1738 | goto error_param; |
| 1739 | } |
| 1740 | |
| 1741 | i40e_vlan_stripping_enable(vsi); |
| 1742 | for (i = 0; i < vfl->num_elements; i++) { |
| 1743 | /* add new VLAN filter */ |
| 1744 | int ret = i40e_vsi_add_vlan(vsi, vfl->vlan_id[i]); |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 1745 | |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1746 | if (ret) |
| 1747 | dev_err(&pf->pdev->dev, |
Mitch Williams | 8d8f229 | 2015-10-21 19:47:11 -0400 | [diff] [blame] | 1748 | "Unable to add VLAN filter %d for VF %d, error %d\n", |
| 1749 | vfl->vlan_id[i], vf->vf_id, ret); |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1750 | } |
| 1751 | |
| 1752 | error_param: |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 1753 | /* send the response to the VF */ |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1754 | return i40e_vc_send_resp_to_vf(vf, I40E_VIRTCHNL_OP_ADD_VLAN, aq_ret); |
| 1755 | } |
| 1756 | |
| 1757 | /** |
| 1758 | * i40e_vc_remove_vlan_msg |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 1759 | * @vf: pointer to the VF info |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1760 | * @msg: pointer to the msg buffer |
| 1761 | * @msglen: msg length |
| 1762 | * |
| 1763 | * remove programmed guest vlan id |
| 1764 | **/ |
| 1765 | static int i40e_vc_remove_vlan_msg(struct i40e_vf *vf, u8 *msg, u16 msglen) |
| 1766 | { |
| 1767 | struct i40e_virtchnl_vlan_filter_list *vfl = |
| 1768 | (struct i40e_virtchnl_vlan_filter_list *)msg; |
| 1769 | struct i40e_pf *pf = vf->pf; |
| 1770 | struct i40e_vsi *vsi = NULL; |
| 1771 | u16 vsi_id = vfl->vsi_id; |
| 1772 | i40e_status aq_ret = 0; |
| 1773 | int i; |
| 1774 | |
| 1775 | if (!test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states) || |
| 1776 | !test_bit(I40E_VIRTCHNL_VF_CAP_PRIVILEGE, &vf->vf_caps) || |
| 1777 | !i40e_vc_isvalid_vsi_id(vf, vsi_id)) { |
| 1778 | aq_ret = I40E_ERR_PARAM; |
| 1779 | goto error_param; |
| 1780 | } |
| 1781 | |
| 1782 | for (i = 0; i < vfl->num_elements; i++) { |
| 1783 | if (vfl->vlan_id[i] > I40E_MAX_VLANID) { |
| 1784 | aq_ret = I40E_ERR_PARAM; |
| 1785 | goto error_param; |
| 1786 | } |
| 1787 | } |
| 1788 | |
Anjali Singhai Jain | fdf0e0b | 2015-03-31 00:45:05 -0700 | [diff] [blame] | 1789 | vsi = pf->vsi[vf->lan_vsi_idx]; |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1790 | if (vsi->info.pvid) { |
| 1791 | aq_ret = I40E_ERR_PARAM; |
| 1792 | goto error_param; |
| 1793 | } |
| 1794 | |
| 1795 | for (i = 0; i < vfl->num_elements; i++) { |
| 1796 | int ret = i40e_vsi_kill_vlan(vsi, vfl->vlan_id[i]); |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 1797 | |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1798 | if (ret) |
| 1799 | dev_err(&pf->pdev->dev, |
Mitch Williams | 8d8f229 | 2015-10-21 19:47:11 -0400 | [diff] [blame] | 1800 | "Unable to delete VLAN filter %d for VF %d, error %d\n", |
| 1801 | vfl->vlan_id[i], vf->vf_id, ret); |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1802 | } |
| 1803 | |
| 1804 | error_param: |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 1805 | /* send the response to the VF */ |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1806 | return i40e_vc_send_resp_to_vf(vf, I40E_VIRTCHNL_OP_DEL_VLAN, aq_ret); |
| 1807 | } |
| 1808 | |
| 1809 | /** |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1810 | * i40e_vc_validate_vf_msg |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 1811 | * @vf: pointer to the VF info |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1812 | * @msg: pointer to the msg buffer |
| 1813 | * @msglen: msg length |
| 1814 | * @msghndl: msg handle |
| 1815 | * |
| 1816 | * validate msg |
| 1817 | **/ |
| 1818 | static int i40e_vc_validate_vf_msg(struct i40e_vf *vf, u32 v_opcode, |
| 1819 | u32 v_retval, u8 *msg, u16 msglen) |
| 1820 | { |
| 1821 | bool err_msg_format = false; |
| 1822 | int valid_len; |
| 1823 | |
| 1824 | /* Check if VF is disabled. */ |
| 1825 | if (test_bit(I40E_VF_STAT_DISABLED, &vf->vf_states)) |
| 1826 | return I40E_ERR_PARAM; |
| 1827 | |
| 1828 | /* Validate message length. */ |
| 1829 | switch (v_opcode) { |
| 1830 | case I40E_VIRTCHNL_OP_VERSION: |
| 1831 | valid_len = sizeof(struct i40e_virtchnl_version_info); |
| 1832 | break; |
| 1833 | case I40E_VIRTCHNL_OP_RESET_VF: |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1834 | valid_len = 0; |
| 1835 | break; |
Mitch Williams | f4ca1a2 | 2015-06-04 16:23:57 -0400 | [diff] [blame] | 1836 | case I40E_VIRTCHNL_OP_GET_VF_RESOURCES: |
| 1837 | if (VF_IS_V11(vf)) |
| 1838 | valid_len = sizeof(u32); |
| 1839 | else |
| 1840 | valid_len = 0; |
| 1841 | break; |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1842 | case I40E_VIRTCHNL_OP_CONFIG_TX_QUEUE: |
| 1843 | valid_len = sizeof(struct i40e_virtchnl_txq_info); |
| 1844 | break; |
| 1845 | case I40E_VIRTCHNL_OP_CONFIG_RX_QUEUE: |
| 1846 | valid_len = sizeof(struct i40e_virtchnl_rxq_info); |
| 1847 | break; |
| 1848 | case I40E_VIRTCHNL_OP_CONFIG_VSI_QUEUES: |
| 1849 | valid_len = sizeof(struct i40e_virtchnl_vsi_queue_config_info); |
| 1850 | if (msglen >= valid_len) { |
| 1851 | struct i40e_virtchnl_vsi_queue_config_info *vqc = |
| 1852 | (struct i40e_virtchnl_vsi_queue_config_info *)msg; |
| 1853 | valid_len += (vqc->num_queue_pairs * |
| 1854 | sizeof(struct |
| 1855 | i40e_virtchnl_queue_pair_info)); |
| 1856 | if (vqc->num_queue_pairs == 0) |
| 1857 | err_msg_format = true; |
| 1858 | } |
| 1859 | break; |
| 1860 | case I40E_VIRTCHNL_OP_CONFIG_IRQ_MAP: |
| 1861 | valid_len = sizeof(struct i40e_virtchnl_irq_map_info); |
| 1862 | if (msglen >= valid_len) { |
| 1863 | struct i40e_virtchnl_irq_map_info *vimi = |
| 1864 | (struct i40e_virtchnl_irq_map_info *)msg; |
| 1865 | valid_len += (vimi->num_vectors * |
| 1866 | sizeof(struct i40e_virtchnl_vector_map)); |
| 1867 | if (vimi->num_vectors == 0) |
| 1868 | err_msg_format = true; |
| 1869 | } |
| 1870 | break; |
| 1871 | case I40E_VIRTCHNL_OP_ENABLE_QUEUES: |
| 1872 | case I40E_VIRTCHNL_OP_DISABLE_QUEUES: |
| 1873 | valid_len = sizeof(struct i40e_virtchnl_queue_select); |
| 1874 | break; |
| 1875 | case I40E_VIRTCHNL_OP_ADD_ETHER_ADDRESS: |
| 1876 | case I40E_VIRTCHNL_OP_DEL_ETHER_ADDRESS: |
| 1877 | valid_len = sizeof(struct i40e_virtchnl_ether_addr_list); |
| 1878 | if (msglen >= valid_len) { |
| 1879 | struct i40e_virtchnl_ether_addr_list *veal = |
| 1880 | (struct i40e_virtchnl_ether_addr_list *)msg; |
| 1881 | valid_len += veal->num_elements * |
| 1882 | sizeof(struct i40e_virtchnl_ether_addr); |
| 1883 | if (veal->num_elements == 0) |
| 1884 | err_msg_format = true; |
| 1885 | } |
| 1886 | break; |
| 1887 | case I40E_VIRTCHNL_OP_ADD_VLAN: |
| 1888 | case I40E_VIRTCHNL_OP_DEL_VLAN: |
| 1889 | valid_len = sizeof(struct i40e_virtchnl_vlan_filter_list); |
| 1890 | if (msglen >= valid_len) { |
| 1891 | struct i40e_virtchnl_vlan_filter_list *vfl = |
| 1892 | (struct i40e_virtchnl_vlan_filter_list *)msg; |
| 1893 | valid_len += vfl->num_elements * sizeof(u16); |
| 1894 | if (vfl->num_elements == 0) |
| 1895 | err_msg_format = true; |
| 1896 | } |
| 1897 | break; |
| 1898 | case I40E_VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE: |
| 1899 | valid_len = sizeof(struct i40e_virtchnl_promisc_info); |
| 1900 | break; |
| 1901 | case I40E_VIRTCHNL_OP_GET_STATS: |
| 1902 | valid_len = sizeof(struct i40e_virtchnl_queue_select); |
| 1903 | break; |
| 1904 | /* These are always errors coming from the VF. */ |
| 1905 | case I40E_VIRTCHNL_OP_EVENT: |
| 1906 | case I40E_VIRTCHNL_OP_UNKNOWN: |
| 1907 | default: |
| 1908 | return -EPERM; |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1909 | } |
| 1910 | /* few more checks */ |
| 1911 | if ((valid_len != msglen) || (err_msg_format)) { |
| 1912 | i40e_vc_send_resp_to_vf(vf, v_opcode, I40E_ERR_PARAM); |
| 1913 | return -EINVAL; |
| 1914 | } else { |
| 1915 | return 0; |
| 1916 | } |
| 1917 | } |
| 1918 | |
| 1919 | /** |
| 1920 | * i40e_vc_process_vf_msg |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 1921 | * @pf: pointer to the PF structure |
| 1922 | * @vf_id: source VF id |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1923 | * @msg: pointer to the msg buffer |
| 1924 | * @msglen: msg length |
| 1925 | * @msghndl: msg handle |
| 1926 | * |
| 1927 | * called from the common aeq/arq handler to |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 1928 | * process request from VF |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1929 | **/ |
| 1930 | int i40e_vc_process_vf_msg(struct i40e_pf *pf, u16 vf_id, u32 v_opcode, |
| 1931 | u32 v_retval, u8 *msg, u16 msglen) |
| 1932 | { |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1933 | struct i40e_hw *hw = &pf->hw; |
Dan Carpenter | c243e96 | 2014-01-15 06:43:39 +0000 | [diff] [blame] | 1934 | 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] | 1935 | struct i40e_vf *vf; |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1936 | int ret; |
| 1937 | |
| 1938 | pf->vf_aq_requests++; |
Mitch Williams | 7efa84b | 2013-11-28 06:39:41 +0000 | [diff] [blame] | 1939 | if (local_vf_id >= pf->num_alloc_vfs) |
Mitch Williams | 6c1b5bf | 2013-11-28 06:39:30 +0000 | [diff] [blame] | 1940 | return -EINVAL; |
Mitch Williams | 7efa84b | 2013-11-28 06:39:41 +0000 | [diff] [blame] | 1941 | vf = &(pf->vf[local_vf_id]); |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1942 | /* perform basic checks on the msg */ |
| 1943 | ret = i40e_vc_validate_vf_msg(vf, v_opcode, v_retval, msg, msglen); |
| 1944 | |
| 1945 | if (ret) { |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 1946 | 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] | 1947 | local_vf_id, v_opcode, msglen); |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1948 | return ret; |
| 1949 | } |
Mitch Williams | bae3cae | 2014-01-14 00:49:49 -0800 | [diff] [blame] | 1950 | |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1951 | switch (v_opcode) { |
| 1952 | case I40E_VIRTCHNL_OP_VERSION: |
Mitch Williams | f4ca1a2 | 2015-06-04 16:23:57 -0400 | [diff] [blame] | 1953 | ret = i40e_vc_get_version_msg(vf, msg); |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1954 | break; |
| 1955 | case I40E_VIRTCHNL_OP_GET_VF_RESOURCES: |
Mitch Williams | f4ca1a2 | 2015-06-04 16:23:57 -0400 | [diff] [blame] | 1956 | ret = i40e_vc_get_vf_resources_msg(vf, msg); |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1957 | break; |
| 1958 | case I40E_VIRTCHNL_OP_RESET_VF: |
Mitch Williams | fc18eaa | 2013-11-28 06:39:27 +0000 | [diff] [blame] | 1959 | i40e_vc_reset_vf_msg(vf); |
| 1960 | ret = 0; |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1961 | break; |
| 1962 | case I40E_VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE: |
| 1963 | ret = i40e_vc_config_promiscuous_mode_msg(vf, msg, msglen); |
| 1964 | break; |
| 1965 | case I40E_VIRTCHNL_OP_CONFIG_VSI_QUEUES: |
| 1966 | ret = i40e_vc_config_queues_msg(vf, msg, msglen); |
| 1967 | break; |
| 1968 | case I40E_VIRTCHNL_OP_CONFIG_IRQ_MAP: |
| 1969 | ret = i40e_vc_config_irq_map_msg(vf, msg, msglen); |
| 1970 | break; |
| 1971 | case I40E_VIRTCHNL_OP_ENABLE_QUEUES: |
| 1972 | ret = i40e_vc_enable_queues_msg(vf, msg, msglen); |
Mitch Williams | 055b295 | 2015-04-07 19:45:33 -0400 | [diff] [blame] | 1973 | i40e_vc_notify_vf_link_state(vf); |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1974 | break; |
| 1975 | case I40E_VIRTCHNL_OP_DISABLE_QUEUES: |
| 1976 | ret = i40e_vc_disable_queues_msg(vf, msg, msglen); |
| 1977 | break; |
| 1978 | case I40E_VIRTCHNL_OP_ADD_ETHER_ADDRESS: |
| 1979 | ret = i40e_vc_add_mac_addr_msg(vf, msg, msglen); |
| 1980 | break; |
| 1981 | case I40E_VIRTCHNL_OP_DEL_ETHER_ADDRESS: |
| 1982 | ret = i40e_vc_del_mac_addr_msg(vf, msg, msglen); |
| 1983 | break; |
| 1984 | case I40E_VIRTCHNL_OP_ADD_VLAN: |
| 1985 | ret = i40e_vc_add_vlan_msg(vf, msg, msglen); |
| 1986 | break; |
| 1987 | case I40E_VIRTCHNL_OP_DEL_VLAN: |
| 1988 | ret = i40e_vc_remove_vlan_msg(vf, msg, msglen); |
| 1989 | break; |
| 1990 | case I40E_VIRTCHNL_OP_GET_STATS: |
| 1991 | ret = i40e_vc_get_stats_msg(vf, msg, msglen); |
| 1992 | break; |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1993 | case I40E_VIRTCHNL_OP_UNKNOWN: |
| 1994 | default: |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 1995 | dev_err(&pf->pdev->dev, "Unsupported opcode %d from VF %d\n", |
Mitch Williams | 7efa84b | 2013-11-28 06:39:41 +0000 | [diff] [blame] | 1996 | v_opcode, local_vf_id); |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 1997 | ret = i40e_vc_send_resp_to_vf(vf, v_opcode, |
| 1998 | I40E_ERR_NOT_IMPLEMENTED); |
| 1999 | break; |
| 2000 | } |
| 2001 | |
| 2002 | return ret; |
| 2003 | } |
| 2004 | |
| 2005 | /** |
| 2006 | * i40e_vc_process_vflr_event |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 2007 | * @pf: pointer to the PF structure |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 2008 | * |
| 2009 | * called from the vlfr irq handler to |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 2010 | * free up VF resources and state variables |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 2011 | **/ |
| 2012 | int i40e_vc_process_vflr_event(struct i40e_pf *pf) |
| 2013 | { |
| 2014 | u32 reg, reg_idx, bit_idx, vf_id; |
| 2015 | struct i40e_hw *hw = &pf->hw; |
| 2016 | struct i40e_vf *vf; |
| 2017 | |
| 2018 | if (!test_bit(__I40E_VFLR_EVENT_PENDING, &pf->state)) |
| 2019 | return 0; |
| 2020 | |
Mitch Williams | c5c2f7c | 2014-11-11 03:15:04 +0000 | [diff] [blame] | 2021 | /* re-enable vflr interrupt cause */ |
| 2022 | reg = rd32(hw, I40E_PFINT_ICR0_ENA); |
| 2023 | reg |= I40E_PFINT_ICR0_ENA_VFLR_MASK; |
| 2024 | wr32(hw, I40E_PFINT_ICR0_ENA, reg); |
| 2025 | i40e_flush(hw); |
| 2026 | |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 2027 | clear_bit(__I40E_VFLR_EVENT_PENDING, &pf->state); |
| 2028 | for (vf_id = 0; vf_id < pf->num_alloc_vfs; vf_id++) { |
| 2029 | reg_idx = (hw->func_caps.vf_base_id + vf_id) / 32; |
| 2030 | bit_idx = (hw->func_caps.vf_base_id + vf_id) % 32; |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 2031 | /* read GLGEN_VFLRSTAT register to find out the flr VFs */ |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 2032 | vf = &pf->vf[vf_id]; |
| 2033 | reg = rd32(hw, I40E_GLGEN_VFLRSTAT(reg_idx)); |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 2034 | if (reg & BIT(bit_idx)) { |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 2035 | /* clear the bit in GLGEN_VFLRSTAT */ |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 2036 | wr32(hw, I40E_GLGEN_VFLRSTAT(reg_idx), BIT(bit_idx)); |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 2037 | |
Mitch Williams | eb2d80b | 2014-02-13 03:48:48 -0800 | [diff] [blame] | 2038 | if (!test_bit(__I40E_DOWN, &pf->state)) |
| 2039 | i40e_reset_vf(vf, true); |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 2040 | } |
| 2041 | } |
| 2042 | |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 2043 | return 0; |
| 2044 | } |
| 2045 | |
| 2046 | /** |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 2047 | * i40e_ndo_set_vf_mac |
| 2048 | * @netdev: network interface device structure |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 2049 | * @vf_id: VF identifier |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 2050 | * @mac: mac address |
| 2051 | * |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 2052 | * program VF mac address |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 2053 | **/ |
| 2054 | int i40e_ndo_set_vf_mac(struct net_device *netdev, int vf_id, u8 *mac) |
| 2055 | { |
| 2056 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 2057 | struct i40e_vsi *vsi = np->vsi; |
| 2058 | struct i40e_pf *pf = vsi->back; |
| 2059 | struct i40e_mac_filter *f; |
| 2060 | struct i40e_vf *vf; |
| 2061 | int ret = 0; |
| 2062 | |
| 2063 | /* validate the request */ |
| 2064 | if (vf_id >= pf->num_alloc_vfs) { |
| 2065 | dev_err(&pf->pdev->dev, |
| 2066 | "Invalid VF Identifier %d\n", vf_id); |
| 2067 | ret = -EINVAL; |
| 2068 | goto error_param; |
| 2069 | } |
| 2070 | |
| 2071 | vf = &(pf->vf[vf_id]); |
Anjali Singhai Jain | fdf0e0b | 2015-03-31 00:45:05 -0700 | [diff] [blame] | 2072 | vsi = pf->vsi[vf->lan_vsi_idx]; |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 2073 | if (!test_bit(I40E_VF_STAT_INIT, &vf->vf_states)) { |
| 2074 | dev_err(&pf->pdev->dev, |
| 2075 | "Uninitialized VF %d\n", vf_id); |
| 2076 | ret = -EINVAL; |
| 2077 | goto error_param; |
| 2078 | } |
| 2079 | |
| 2080 | if (!is_valid_ether_addr(mac)) { |
| 2081 | dev_err(&pf->pdev->dev, |
| 2082 | "Invalid VF ethernet address\n"); |
| 2083 | ret = -EINVAL; |
| 2084 | goto error_param; |
| 2085 | } |
| 2086 | |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2087 | /* Lock once because below invoked function add/del_filter requires |
| 2088 | * mac_filter_list_lock to be held |
| 2089 | */ |
| 2090 | spin_lock_bh(&vsi->mac_filter_list_lock); |
| 2091 | |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 2092 | /* delete the temporary mac address */ |
Mitch Williams | e995163 | 2015-04-27 14:57:13 -0400 | [diff] [blame] | 2093 | i40e_del_filter(vsi, vf->default_lan_addr.addr, |
| 2094 | vf->port_vlan_id ? vf->port_vlan_id : -1, |
Greg Rose | 37cc0d2 | 2014-04-01 07:11:44 +0000 | [diff] [blame] | 2095 | true, false); |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 2096 | |
Greg Rose | 29f71bb | 2014-05-20 08:01:45 +0000 | [diff] [blame] | 2097 | /* Delete all the filters for this VSI - we're going to kill it |
| 2098 | * anyway. |
| 2099 | */ |
| 2100 | list_for_each_entry(f, &vsi->mac_filter_list, list) |
| 2101 | i40e_del_filter(vsi, f->macaddr, f->vlan, true, false); |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 2102 | |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2103 | spin_unlock_bh(&vsi->mac_filter_list_lock); |
| 2104 | |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 2105 | dev_info(&pf->pdev->dev, "Setting MAC %pM on VF %d\n", mac, vf_id); |
| 2106 | /* program mac filter */ |
Jesse Brandeburg | 17652c6 | 2015-11-05 17:01:02 -0800 | [diff] [blame] | 2107 | if (i40e_sync_vsi_filters(vsi)) { |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 2108 | dev_err(&pf->pdev->dev, "Unable to program ucast filters\n"); |
| 2109 | ret = -EIO; |
| 2110 | goto error_param; |
| 2111 | } |
Greg Rose | 9a17390 | 2014-05-22 06:32:02 +0000 | [diff] [blame] | 2112 | ether_addr_copy(vf->default_lan_addr.addr, mac); |
Greg Rose | f657a6e | 2013-11-28 06:39:42 +0000 | [diff] [blame] | 2113 | vf->pf_set_mac = true; |
Greg Rose | 17413a8 | 2014-06-04 01:23:13 +0000 | [diff] [blame] | 2114 | /* Force the VF driver stop so it has to reload with new MAC address */ |
| 2115 | i40e_vc_disable_vf(pf, vf); |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 2116 | 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] | 2117 | |
| 2118 | error_param: |
| 2119 | return ret; |
| 2120 | } |
| 2121 | |
| 2122 | /** |
| 2123 | * i40e_ndo_set_vf_port_vlan |
| 2124 | * @netdev: network interface device structure |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 2125 | * @vf_id: VF identifier |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 2126 | * @vlan_id: mac address |
| 2127 | * @qos: priority setting |
| 2128 | * |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 2129 | * program VF vlan id and/or qos |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 2130 | **/ |
| 2131 | int i40e_ndo_set_vf_port_vlan(struct net_device *netdev, |
| 2132 | int vf_id, u16 vlan_id, u8 qos) |
| 2133 | { |
Mitch Williams | f7fc2f2 | 2015-07-23 16:54:36 -0400 | [diff] [blame] | 2134 | u16 vlanprio = vlan_id | (qos << I40E_VLAN_PRIORITY_SHIFT); |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 2135 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 2136 | struct i40e_pf *pf = np->vsi->back; |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2137 | bool is_vsi_in_vlan = false; |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 2138 | struct i40e_vsi *vsi; |
| 2139 | struct i40e_vf *vf; |
| 2140 | int ret = 0; |
| 2141 | |
| 2142 | /* validate the request */ |
| 2143 | if (vf_id >= pf->num_alloc_vfs) { |
| 2144 | dev_err(&pf->pdev->dev, "Invalid VF Identifier %d\n", vf_id); |
| 2145 | ret = -EINVAL; |
| 2146 | goto error_pvid; |
| 2147 | } |
| 2148 | |
| 2149 | if ((vlan_id > I40E_MAX_VLANID) || (qos > 7)) { |
| 2150 | dev_err(&pf->pdev->dev, "Invalid VF Parameters\n"); |
| 2151 | ret = -EINVAL; |
| 2152 | goto error_pvid; |
| 2153 | } |
| 2154 | |
| 2155 | vf = &(pf->vf[vf_id]); |
Anjali Singhai Jain | fdf0e0b | 2015-03-31 00:45:05 -0700 | [diff] [blame] | 2156 | vsi = pf->vsi[vf->lan_vsi_idx]; |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 2157 | if (!test_bit(I40E_VF_STAT_INIT, &vf->vf_states)) { |
| 2158 | dev_err(&pf->pdev->dev, "Uninitialized VF %d\n", vf_id); |
| 2159 | ret = -EINVAL; |
| 2160 | goto error_pvid; |
| 2161 | } |
| 2162 | |
Mitch Williams | f7fc2f2 | 2015-07-23 16:54:36 -0400 | [diff] [blame] | 2163 | if (le16_to_cpu(vsi->info.pvid) == vlanprio) |
Mitch Williams | 85927ec | 2015-04-27 14:57:10 -0400 | [diff] [blame] | 2164 | /* duplicate request, so just return success */ |
| 2165 | goto error_pvid; |
| 2166 | |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2167 | spin_lock_bh(&vsi->mac_filter_list_lock); |
| 2168 | is_vsi_in_vlan = i40e_is_vsi_in_vlan(vsi); |
| 2169 | spin_unlock_bh(&vsi->mac_filter_list_lock); |
| 2170 | |
| 2171 | if (le16_to_cpu(vsi->info.pvid) == 0 && is_vsi_in_vlan) { |
Greg Rose | 99a4973 | 2014-01-13 16:13:03 -0800 | [diff] [blame] | 2172 | dev_err(&pf->pdev->dev, |
| 2173 | "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", |
| 2174 | vf_id); |
Greg Rose | f9b4b62 | 2014-03-06 09:02:28 +0000 | [diff] [blame] | 2175 | /* Administrator Error - knock the VF offline until he does |
| 2176 | * the right thing by reconfiguring his network correctly |
| 2177 | * and then reloading the VF driver. |
| 2178 | */ |
| 2179 | i40e_vc_disable_vf(pf, vf); |
| 2180 | } |
Greg Rose | 99a4973 | 2014-01-13 16:13:03 -0800 | [diff] [blame] | 2181 | |
Greg Rose | 8d82a7c | 2014-01-13 16:13:04 -0800 | [diff] [blame] | 2182 | /* Check for condition where there was already a port VLAN ID |
| 2183 | * 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] | 2184 | * Additionally check for the condition where there was a port |
| 2185 | * 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] | 2186 | * Before deleting all the old VLAN filters we must add new ones |
| 2187 | * with -1 (I40E_VLAN_ANY) or otherwise we're left with all our |
| 2188 | * MAC addresses deleted. |
| 2189 | */ |
Greg Rose | 1315f7c | 2014-03-14 07:32:20 +0000 | [diff] [blame] | 2190 | if ((!(vlan_id || qos) || |
Mitch Williams | f7fc2f2 | 2015-07-23 16:54:36 -0400 | [diff] [blame] | 2191 | vlanprio != le16_to_cpu(vsi->info.pvid)) && |
Greg Rose | 1315f7c | 2014-03-14 07:32:20 +0000 | [diff] [blame] | 2192 | vsi->info.pvid) |
Greg Rose | 8d82a7c | 2014-01-13 16:13:04 -0800 | [diff] [blame] | 2193 | ret = i40e_vsi_add_vlan(vsi, I40E_VLAN_ANY); |
| 2194 | |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 2195 | if (vsi->info.pvid) { |
| 2196 | /* kill old VLAN */ |
| 2197 | ret = i40e_vsi_kill_vlan(vsi, (le16_to_cpu(vsi->info.pvid) & |
| 2198 | VLAN_VID_MASK)); |
| 2199 | if (ret) { |
| 2200 | dev_info(&vsi->back->pdev->dev, |
| 2201 | "remove VLAN failed, ret=%d, aq_err=%d\n", |
| 2202 | ret, pf->hw.aq.asq_last_status); |
| 2203 | } |
| 2204 | } |
| 2205 | if (vlan_id || qos) |
Mitch Williams | f7fc2f2 | 2015-07-23 16:54:36 -0400 | [diff] [blame] | 2206 | ret = i40e_vsi_add_pvid(vsi, vlanprio); |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 2207 | else |
Greg Rose | 6c12fcb | 2013-11-28 06:39:34 +0000 | [diff] [blame] | 2208 | i40e_vsi_remove_pvid(vsi); |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 2209 | |
| 2210 | if (vlan_id) { |
| 2211 | dev_info(&pf->pdev->dev, "Setting VLAN %d, QOS 0x%x on VF %d\n", |
| 2212 | vlan_id, qos, vf_id); |
| 2213 | |
| 2214 | /* add new VLAN filter */ |
| 2215 | ret = i40e_vsi_add_vlan(vsi, vlan_id); |
| 2216 | if (ret) { |
| 2217 | dev_info(&vsi->back->pdev->dev, |
| 2218 | "add VF VLAN failed, ret=%d aq_err=%d\n", ret, |
| 2219 | vsi->back->hw.aq.asq_last_status); |
| 2220 | goto error_pvid; |
| 2221 | } |
Greg Rose | 8d82a7c | 2014-01-13 16:13:04 -0800 | [diff] [blame] | 2222 | /* Kill non-vlan MAC filters - ignore error return since |
| 2223 | * there might not be any non-vlan MAC filters. |
| 2224 | */ |
| 2225 | i40e_vsi_kill_vlan(vsi, I40E_VLAN_ANY); |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 2226 | } |
| 2227 | |
| 2228 | if (ret) { |
| 2229 | dev_err(&pf->pdev->dev, "Unable to update VF vsi context\n"); |
| 2230 | goto error_pvid; |
| 2231 | } |
Greg Rose | 6c12fcb | 2013-11-28 06:39:34 +0000 | [diff] [blame] | 2232 | /* The Port VLAN needs to be saved across resets the same as the |
| 2233 | * default LAN MAC address. |
| 2234 | */ |
| 2235 | vf->port_vlan_id = le16_to_cpu(vsi->info.pvid); |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 2236 | ret = 0; |
| 2237 | |
| 2238 | error_pvid: |
| 2239 | return ret; |
| 2240 | } |
| 2241 | |
Mitch Williams | 84590fd | 2014-04-09 05:58:57 +0000 | [diff] [blame] | 2242 | #define I40E_BW_CREDIT_DIVISOR 50 /* 50Mbps per BW credit */ |
| 2243 | #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] | 2244 | /** |
| 2245 | * i40e_ndo_set_vf_bw |
| 2246 | * @netdev: network interface device structure |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 2247 | * @vf_id: VF identifier |
| 2248 | * @tx_rate: Tx rate |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 2249 | * |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 2250 | * configure VF Tx rate |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 2251 | **/ |
Sucheta Chakraborty | ed61668 | 2014-05-22 09:59:05 -0400 | [diff] [blame] | 2252 | int i40e_ndo_set_vf_bw(struct net_device *netdev, int vf_id, int min_tx_rate, |
| 2253 | int max_tx_rate) |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 2254 | { |
Mitch Williams | 6b19289 | 2014-03-06 09:02:29 +0000 | [diff] [blame] | 2255 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 2256 | struct i40e_pf *pf = np->vsi->back; |
| 2257 | struct i40e_vsi *vsi; |
| 2258 | struct i40e_vf *vf; |
| 2259 | int speed = 0; |
| 2260 | int ret = 0; |
| 2261 | |
| 2262 | /* validate the request */ |
| 2263 | if (vf_id >= pf->num_alloc_vfs) { |
| 2264 | dev_err(&pf->pdev->dev, "Invalid VF Identifier %d.\n", vf_id); |
| 2265 | ret = -EINVAL; |
| 2266 | goto error; |
| 2267 | } |
| 2268 | |
Sucheta Chakraborty | ed61668 | 2014-05-22 09:59:05 -0400 | [diff] [blame] | 2269 | if (min_tx_rate) { |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 2270 | 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] | 2271 | min_tx_rate, vf_id); |
| 2272 | return -EINVAL; |
| 2273 | } |
| 2274 | |
Mitch Williams | 6b19289 | 2014-03-06 09:02:29 +0000 | [diff] [blame] | 2275 | vf = &(pf->vf[vf_id]); |
Anjali Singhai Jain | fdf0e0b | 2015-03-31 00:45:05 -0700 | [diff] [blame] | 2276 | vsi = pf->vsi[vf->lan_vsi_idx]; |
Mitch Williams | 6b19289 | 2014-03-06 09:02:29 +0000 | [diff] [blame] | 2277 | if (!test_bit(I40E_VF_STAT_INIT, &vf->vf_states)) { |
| 2278 | dev_err(&pf->pdev->dev, "Uninitialized VF %d.\n", vf_id); |
| 2279 | ret = -EINVAL; |
| 2280 | goto error; |
| 2281 | } |
| 2282 | |
| 2283 | switch (pf->hw.phy.link_info.link_speed) { |
| 2284 | case I40E_LINK_SPEED_40GB: |
| 2285 | speed = 40000; |
| 2286 | break; |
| 2287 | case I40E_LINK_SPEED_10GB: |
| 2288 | speed = 10000; |
| 2289 | break; |
| 2290 | case I40E_LINK_SPEED_1GB: |
| 2291 | speed = 1000; |
| 2292 | break; |
| 2293 | default: |
| 2294 | break; |
| 2295 | } |
| 2296 | |
Sucheta Chakraborty | ed61668 | 2014-05-22 09:59:05 -0400 | [diff] [blame] | 2297 | if (max_tx_rate > speed) { |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 2298 | 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] | 2299 | max_tx_rate, vf->vf_id); |
Mitch Williams | 6b19289 | 2014-03-06 09:02:29 +0000 | [diff] [blame] | 2300 | ret = -EINVAL; |
| 2301 | goto error; |
| 2302 | } |
| 2303 | |
Mitch Williams | dac9b31 | 2014-04-09 05:58:56 +0000 | [diff] [blame] | 2304 | if ((max_tx_rate < 50) && (max_tx_rate > 0)) { |
| 2305 | dev_warn(&pf->pdev->dev, "Setting max Tx rate to minimum usable value of 50Mbps.\n"); |
| 2306 | max_tx_rate = 50; |
| 2307 | } |
| 2308 | |
Mitch Williams | 6b19289 | 2014-03-06 09:02:29 +0000 | [diff] [blame] | 2309 | /* Tx rate credits are in values of 50Mbps, 0 is disabled*/ |
Mitch Williams | 84590fd | 2014-04-09 05:58:57 +0000 | [diff] [blame] | 2310 | ret = i40e_aq_config_vsi_bw_limit(&pf->hw, vsi->seid, |
| 2311 | max_tx_rate / I40E_BW_CREDIT_DIVISOR, |
| 2312 | I40E_MAX_BW_INACTIVE_ACCUM, NULL); |
Mitch Williams | 6b19289 | 2014-03-06 09:02:29 +0000 | [diff] [blame] | 2313 | if (ret) { |
Sucheta Chakraborty | ed61668 | 2014-05-22 09:59:05 -0400 | [diff] [blame] | 2314 | 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] | 2315 | ret); |
| 2316 | ret = -EIO; |
| 2317 | goto error; |
| 2318 | } |
Sucheta Chakraborty | ed61668 | 2014-05-22 09:59:05 -0400 | [diff] [blame] | 2319 | vf->tx_rate = max_tx_rate; |
Mitch Williams | 6b19289 | 2014-03-06 09:02:29 +0000 | [diff] [blame] | 2320 | error: |
| 2321 | return ret; |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 2322 | } |
| 2323 | |
| 2324 | /** |
| 2325 | * i40e_ndo_get_vf_config |
| 2326 | * @netdev: network interface device structure |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 2327 | * @vf_id: VF identifier |
| 2328 | * @ivi: VF configuration structure |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 2329 | * |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 2330 | * return VF configuration |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 2331 | **/ |
| 2332 | int i40e_ndo_get_vf_config(struct net_device *netdev, |
| 2333 | int vf_id, struct ifla_vf_info *ivi) |
| 2334 | { |
| 2335 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 2336 | struct i40e_vsi *vsi = np->vsi; |
| 2337 | struct i40e_pf *pf = vsi->back; |
| 2338 | struct i40e_vf *vf; |
| 2339 | int ret = 0; |
| 2340 | |
| 2341 | /* validate the request */ |
| 2342 | if (vf_id >= pf->num_alloc_vfs) { |
| 2343 | dev_err(&pf->pdev->dev, "Invalid VF Identifier %d\n", vf_id); |
| 2344 | ret = -EINVAL; |
| 2345 | goto error_param; |
| 2346 | } |
| 2347 | |
| 2348 | vf = &(pf->vf[vf_id]); |
| 2349 | /* first vsi is always the LAN vsi */ |
Anjali Singhai Jain | fdf0e0b | 2015-03-31 00:45:05 -0700 | [diff] [blame] | 2350 | vsi = pf->vsi[vf->lan_vsi_idx]; |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 2351 | if (!test_bit(I40E_VF_STAT_INIT, &vf->vf_states)) { |
| 2352 | dev_err(&pf->pdev->dev, "Uninitialized VF %d\n", vf_id); |
| 2353 | ret = -EINVAL; |
| 2354 | goto error_param; |
| 2355 | } |
| 2356 | |
| 2357 | ivi->vf = vf_id; |
| 2358 | |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 2359 | ether_addr_copy(ivi->mac, vf->default_lan_addr.addr); |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 2360 | |
Sucheta Chakraborty | ed61668 | 2014-05-22 09:59:05 -0400 | [diff] [blame] | 2361 | ivi->max_tx_rate = vf->tx_rate; |
| 2362 | ivi->min_tx_rate = 0; |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 2363 | ivi->vlan = le16_to_cpu(vsi->info.pvid) & I40E_VLAN_MASK; |
| 2364 | ivi->qos = (le16_to_cpu(vsi->info.pvid) & I40E_PRIORITY_MASK) >> |
| 2365 | I40E_VLAN_PRIORITY_SHIFT; |
Mitch Williams | 84ca55a | 2014-03-14 07:32:24 +0000 | [diff] [blame] | 2366 | if (vf->link_forced == false) |
| 2367 | ivi->linkstate = IFLA_VF_LINK_STATE_AUTO; |
| 2368 | else if (vf->link_up == true) |
| 2369 | ivi->linkstate = IFLA_VF_LINK_STATE_ENABLE; |
| 2370 | else |
| 2371 | ivi->linkstate = IFLA_VF_LINK_STATE_DISABLE; |
Mitch Williams | c674d12 | 2014-05-20 08:01:40 +0000 | [diff] [blame] | 2372 | ivi->spoofchk = vf->spoofchk; |
Jesse Brandeburg | 5c3c48a | 2013-09-11 08:40:07 +0000 | [diff] [blame] | 2373 | ret = 0; |
| 2374 | |
| 2375 | error_param: |
| 2376 | return ret; |
| 2377 | } |
Mitch Williams | 588aefa | 2014-02-11 08:27:49 +0000 | [diff] [blame] | 2378 | |
| 2379 | /** |
| 2380 | * i40e_ndo_set_vf_link_state |
| 2381 | * @netdev: network interface device structure |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 2382 | * @vf_id: VF identifier |
Mitch Williams | 588aefa | 2014-02-11 08:27:49 +0000 | [diff] [blame] | 2383 | * @link: required link state |
| 2384 | * |
| 2385 | * Set the link state of a specified VF, regardless of physical link state |
| 2386 | **/ |
| 2387 | int i40e_ndo_set_vf_link_state(struct net_device *netdev, int vf_id, int link) |
| 2388 | { |
| 2389 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 2390 | struct i40e_pf *pf = np->vsi->back; |
| 2391 | struct i40e_virtchnl_pf_event pfe; |
| 2392 | struct i40e_hw *hw = &pf->hw; |
| 2393 | struct i40e_vf *vf; |
Ashish Shah | f19efbb | 2014-08-01 13:27:06 -0700 | [diff] [blame] | 2394 | int abs_vf_id; |
Mitch Williams | 588aefa | 2014-02-11 08:27:49 +0000 | [diff] [blame] | 2395 | int ret = 0; |
| 2396 | |
| 2397 | /* validate the request */ |
| 2398 | if (vf_id >= pf->num_alloc_vfs) { |
| 2399 | dev_err(&pf->pdev->dev, "Invalid VF Identifier %d\n", vf_id); |
| 2400 | ret = -EINVAL; |
| 2401 | goto error_out; |
| 2402 | } |
| 2403 | |
| 2404 | vf = &pf->vf[vf_id]; |
Ashish Shah | f19efbb | 2014-08-01 13:27:06 -0700 | [diff] [blame] | 2405 | abs_vf_id = vf->vf_id + hw->func_caps.vf_base_id; |
Mitch Williams | 588aefa | 2014-02-11 08:27:49 +0000 | [diff] [blame] | 2406 | |
| 2407 | pfe.event = I40E_VIRTCHNL_EVENT_LINK_CHANGE; |
| 2408 | pfe.severity = I40E_PF_EVENT_SEVERITY_INFO; |
| 2409 | |
| 2410 | switch (link) { |
| 2411 | case IFLA_VF_LINK_STATE_AUTO: |
| 2412 | vf->link_forced = false; |
| 2413 | pfe.event_data.link_event.link_status = |
| 2414 | pf->hw.phy.link_info.link_info & I40E_AQ_LINK_UP; |
| 2415 | pfe.event_data.link_event.link_speed = |
| 2416 | pf->hw.phy.link_info.link_speed; |
| 2417 | break; |
| 2418 | case IFLA_VF_LINK_STATE_ENABLE: |
| 2419 | vf->link_forced = true; |
| 2420 | vf->link_up = true; |
| 2421 | pfe.event_data.link_event.link_status = true; |
| 2422 | pfe.event_data.link_event.link_speed = I40E_LINK_SPEED_40GB; |
| 2423 | break; |
| 2424 | case IFLA_VF_LINK_STATE_DISABLE: |
| 2425 | vf->link_forced = true; |
| 2426 | vf->link_up = false; |
| 2427 | pfe.event_data.link_event.link_status = false; |
| 2428 | pfe.event_data.link_event.link_speed = 0; |
| 2429 | break; |
| 2430 | default: |
| 2431 | ret = -EINVAL; |
| 2432 | goto error_out; |
| 2433 | } |
| 2434 | /* Notify the VF of its new link state */ |
Ashish Shah | f19efbb | 2014-08-01 13:27:06 -0700 | [diff] [blame] | 2435 | 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] | 2436 | 0, (u8 *)&pfe, sizeof(pfe), NULL); |
| 2437 | |
| 2438 | error_out: |
| 2439 | return ret; |
| 2440 | } |
Mitch Williams | c674d12 | 2014-05-20 08:01:40 +0000 | [diff] [blame] | 2441 | |
| 2442 | /** |
| 2443 | * i40e_ndo_set_vf_spoofchk |
| 2444 | * @netdev: network interface device structure |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 2445 | * @vf_id: VF identifier |
Mitch Williams | c674d12 | 2014-05-20 08:01:40 +0000 | [diff] [blame] | 2446 | * @enable: flag to enable or disable feature |
| 2447 | * |
| 2448 | * Enable or disable VF spoof checking |
| 2449 | **/ |
Serey Kong | e6d9004 | 2014-07-12 07:28:14 +0000 | [diff] [blame] | 2450 | 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] | 2451 | { |
| 2452 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 2453 | struct i40e_vsi *vsi = np->vsi; |
| 2454 | struct i40e_pf *pf = vsi->back; |
| 2455 | struct i40e_vsi_context ctxt; |
| 2456 | struct i40e_hw *hw = &pf->hw; |
| 2457 | struct i40e_vf *vf; |
| 2458 | int ret = 0; |
| 2459 | |
| 2460 | /* validate the request */ |
| 2461 | if (vf_id >= pf->num_alloc_vfs) { |
| 2462 | dev_err(&pf->pdev->dev, "Invalid VF Identifier %d\n", vf_id); |
| 2463 | ret = -EINVAL; |
| 2464 | goto out; |
| 2465 | } |
| 2466 | |
| 2467 | vf = &(pf->vf[vf_id]); |
| 2468 | |
| 2469 | if (enable == vf->spoofchk) |
| 2470 | goto out; |
| 2471 | |
| 2472 | vf->spoofchk = enable; |
| 2473 | memset(&ctxt, 0, sizeof(ctxt)); |
Anjali Singhai Jain | fdf0e0b | 2015-03-31 00:45:05 -0700 | [diff] [blame] | 2474 | ctxt.seid = pf->vsi[vf->lan_vsi_idx]->seid; |
Mitch Williams | c674d12 | 2014-05-20 08:01:40 +0000 | [diff] [blame] | 2475 | ctxt.pf_num = pf->hw.pf_id; |
| 2476 | ctxt.info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_SECURITY_VALID); |
| 2477 | if (enable) |
Greg Rose | 30d71af | 2015-01-29 07:17:17 +0000 | [diff] [blame] | 2478 | ctxt.info.sec_flags |= (I40E_AQ_VSI_SEC_FLAG_ENABLE_VLAN_CHK | |
| 2479 | I40E_AQ_VSI_SEC_FLAG_ENABLE_MAC_CHK); |
Mitch Williams | c674d12 | 2014-05-20 08:01:40 +0000 | [diff] [blame] | 2480 | ret = i40e_aq_update_vsi_params(hw, &ctxt, NULL); |
| 2481 | if (ret) { |
| 2482 | dev_err(&pf->pdev->dev, "Error %d updating VSI parameters\n", |
| 2483 | ret); |
| 2484 | ret = -EIO; |
| 2485 | } |
| 2486 | out: |
| 2487 | return ret; |
| 2488 | } |