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