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