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