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