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