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