Greg Rose | 62683ab | 2013-12-21 06:13:01 +0000 | [diff] [blame] | 1 | /******************************************************************************* |
| 2 | * |
| 3 | * Intel Ethernet Controller XL710 Family Linux Virtual Function Driver |
Mitch Williams | ef8693e | 2014-02-13 03:48:53 -0800 | [diff] [blame] | 4 | * Copyright(c) 2013 - 2014 Intel Corporation. |
Greg Rose | 62683ab | 2013-12-21 06:13:01 +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 | * |
Jesse Brandeburg | b831607 | 2014-04-05 07:46:11 +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/>. |
| 17 | * |
Greg Rose | 62683ab | 2013-12-21 06:13:01 +0000 | [diff] [blame] | 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 "i40evf.h" |
| 28 | #include "i40e_prototype.h" |
| 29 | |
| 30 | /* busy wait delay in msec */ |
| 31 | #define I40EVF_BUSY_WAIT_DELAY 10 |
| 32 | #define I40EVF_BUSY_WAIT_COUNT 50 |
| 33 | |
| 34 | /** |
| 35 | * i40evf_send_pf_msg |
| 36 | * @adapter: adapter structure |
| 37 | * @op: virtual channel opcode |
| 38 | * @msg: pointer to message buffer |
| 39 | * @len: message length |
| 40 | * |
| 41 | * Send message to PF and print status if failure. |
| 42 | **/ |
| 43 | static int i40evf_send_pf_msg(struct i40evf_adapter *adapter, |
| 44 | enum i40e_virtchnl_ops op, u8 *msg, u16 len) |
| 45 | { |
| 46 | struct i40e_hw *hw = &adapter->hw; |
| 47 | i40e_status err; |
| 48 | |
Mitch Williams | ef8693e | 2014-02-13 03:48:53 -0800 | [diff] [blame] | 49 | if (adapter->flags & I40EVF_FLAG_PF_COMMS_FAILED) |
| 50 | return 0; /* nothing to see here, move along */ |
| 51 | |
Greg Rose | 62683ab | 2013-12-21 06:13:01 +0000 | [diff] [blame] | 52 | err = i40e_aq_send_msg_to_pf(hw, op, 0, msg, len, NULL); |
| 53 | if (err) |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 54 | dev_err(&adapter->pdev->dev, "Unable to send opcode %d to PF, err %s, aq_err %s\n", |
| 55 | op, i40evf_stat_str(hw, err), |
| 56 | i40evf_aq_str(hw, hw->aq.asq_last_status)); |
Greg Rose | 62683ab | 2013-12-21 06:13:01 +0000 | [diff] [blame] | 57 | return err; |
| 58 | } |
| 59 | |
| 60 | /** |
| 61 | * i40evf_send_api_ver |
| 62 | * @adapter: adapter structure |
| 63 | * |
| 64 | * Send API version admin queue message to the PF. The reply is not checked |
| 65 | * in this function. Returns 0 if the message was successfully |
| 66 | * sent, or one of the I40E_ADMIN_QUEUE_ERROR_ statuses if not. |
| 67 | **/ |
| 68 | int i40evf_send_api_ver(struct i40evf_adapter *adapter) |
| 69 | { |
| 70 | struct i40e_virtchnl_version_info vvi; |
| 71 | |
| 72 | vvi.major = I40E_VIRTCHNL_VERSION_MAJOR; |
| 73 | vvi.minor = I40E_VIRTCHNL_VERSION_MINOR; |
| 74 | |
| 75 | return i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_VERSION, (u8 *)&vvi, |
| 76 | sizeof(vvi)); |
| 77 | } |
| 78 | |
| 79 | /** |
| 80 | * i40evf_verify_api_ver |
| 81 | * @adapter: adapter structure |
| 82 | * |
| 83 | * Compare API versions with the PF. Must be called after admin queue is |
Mitch Williams | 6a8e93d | 2014-06-05 00:09:17 +0000 | [diff] [blame] | 84 | * initialized. Returns 0 if API versions match, -EIO if they do not, |
| 85 | * I40E_ERR_ADMIN_QUEUE_NO_WORK if the admin queue is empty, and any errors |
| 86 | * from the firmware are propagated. |
Greg Rose | 62683ab | 2013-12-21 06:13:01 +0000 | [diff] [blame] | 87 | **/ |
| 88 | int i40evf_verify_api_ver(struct i40evf_adapter *adapter) |
| 89 | { |
| 90 | struct i40e_virtchnl_version_info *pf_vvi; |
| 91 | struct i40e_hw *hw = &adapter->hw; |
| 92 | struct i40e_arq_event_info event; |
Mitch Williams | f8d4db3 | 2014-10-25 03:24:33 +0000 | [diff] [blame] | 93 | enum i40e_virtchnl_ops op; |
Greg Rose | 62683ab | 2013-12-21 06:13:01 +0000 | [diff] [blame] | 94 | i40e_status err; |
| 95 | |
Mitch Williams | 1001dc3 | 2014-11-11 20:02:19 +0000 | [diff] [blame] | 96 | event.buf_len = I40EVF_MAX_AQ_BUF_SIZE; |
| 97 | event.msg_buf = kzalloc(event.buf_len, GFP_KERNEL); |
Greg Rose | 62683ab | 2013-12-21 06:13:01 +0000 | [diff] [blame] | 98 | if (!event.msg_buf) { |
| 99 | err = -ENOMEM; |
| 100 | goto out; |
| 101 | } |
| 102 | |
Mitch Williams | f8d4db3 | 2014-10-25 03:24:33 +0000 | [diff] [blame] | 103 | while (1) { |
| 104 | err = i40evf_clean_arq_element(hw, &event, NULL); |
| 105 | /* When the AQ is empty, i40evf_clean_arq_element will return |
| 106 | * nonzero and this loop will terminate. |
| 107 | */ |
| 108 | if (err) |
| 109 | goto out_alloc; |
| 110 | op = |
| 111 | (enum i40e_virtchnl_ops)le32_to_cpu(event.desc.cookie_high); |
| 112 | if (op == I40E_VIRTCHNL_OP_VERSION) |
| 113 | break; |
| 114 | } |
| 115 | |
Greg Rose | 62683ab | 2013-12-21 06:13:01 +0000 | [diff] [blame] | 116 | |
| 117 | err = (i40e_status)le32_to_cpu(event.desc.cookie_low); |
Mitch Williams | 6a8e93d | 2014-06-05 00:09:17 +0000 | [diff] [blame] | 118 | if (err) |
Greg Rose | 62683ab | 2013-12-21 06:13:01 +0000 | [diff] [blame] | 119 | goto out_alloc; |
Greg Rose | 62683ab | 2013-12-21 06:13:01 +0000 | [diff] [blame] | 120 | |
Mitch Williams | f8d4db3 | 2014-10-25 03:24:33 +0000 | [diff] [blame] | 121 | if (op != I40E_VIRTCHNL_OP_VERSION) { |
Mitch Williams | 6a8e93d | 2014-06-05 00:09:17 +0000 | [diff] [blame] | 122 | dev_info(&adapter->pdev->dev, "Invalid reply type %d from PF\n", |
Mitch Williams | f8d4db3 | 2014-10-25 03:24:33 +0000 | [diff] [blame] | 123 | op); |
Greg Rose | 62683ab | 2013-12-21 06:13:01 +0000 | [diff] [blame] | 124 | err = -EIO; |
| 125 | goto out_alloc; |
| 126 | } |
| 127 | |
| 128 | pf_vvi = (struct i40e_virtchnl_version_info *)event.msg_buf; |
Mitch Williams | ee1693e | 2015-06-04 16:23:59 -0400 | [diff] [blame] | 129 | adapter->pf_version = *pf_vvi; |
| 130 | |
| 131 | if ((pf_vvi->major > I40E_VIRTCHNL_VERSION_MAJOR) || |
| 132 | ((pf_vvi->major == I40E_VIRTCHNL_VERSION_MAJOR) && |
| 133 | (pf_vvi->minor > I40E_VIRTCHNL_VERSION_MINOR))) |
Greg Rose | 62683ab | 2013-12-21 06:13:01 +0000 | [diff] [blame] | 134 | err = -EIO; |
| 135 | |
| 136 | out_alloc: |
| 137 | kfree(event.msg_buf); |
| 138 | out: |
| 139 | return err; |
| 140 | } |
| 141 | |
| 142 | /** |
| 143 | * i40evf_send_vf_config_msg |
| 144 | * @adapter: adapter structure |
| 145 | * |
| 146 | * Send VF configuration request admin queue message to the PF. The reply |
| 147 | * is not checked in this function. Returns 0 if the message was |
| 148 | * successfully sent, or one of the I40E_ADMIN_QUEUE_ERROR_ statuses if not. |
| 149 | **/ |
| 150 | int i40evf_send_vf_config_msg(struct i40evf_adapter *adapter) |
| 151 | { |
Mitch Williams | e6d038d | 2015-06-04 16:23:58 -0400 | [diff] [blame] | 152 | u32 caps; |
| 153 | |
| 154 | adapter->current_op = I40E_VIRTCHNL_OP_GET_VF_RESOURCES; |
| 155 | adapter->aq_required &= ~I40EVF_FLAG_AQ_GET_CONFIG; |
| 156 | caps = I40E_VIRTCHNL_VF_OFFLOAD_L2 | |
| 157 | I40E_VIRTCHNL_VF_OFFLOAD_RSS_AQ | |
| 158 | I40E_VIRTCHNL_VF_OFFLOAD_RSS_REG | |
Anjali Singhai Jain | 1f01227 | 2015-09-03 17:18:53 -0400 | [diff] [blame] | 159 | I40E_VIRTCHNL_VF_OFFLOAD_VLAN | |
| 160 | I40E_VIRTCHNL_VF_OFFLOAD_WB_ON_ITR; |
Mitch Williams | e6d038d | 2015-06-04 16:23:58 -0400 | [diff] [blame] | 161 | adapter->current_op = I40E_VIRTCHNL_OP_GET_VF_RESOURCES; |
| 162 | adapter->aq_required &= ~I40EVF_FLAG_AQ_GET_CONFIG; |
| 163 | if (PF_IS_V11(adapter)) |
| 164 | return i40evf_send_pf_msg(adapter, |
| 165 | I40E_VIRTCHNL_OP_GET_VF_RESOURCES, |
| 166 | (u8 *)&caps, sizeof(caps)); |
| 167 | else |
| 168 | return i40evf_send_pf_msg(adapter, |
| 169 | I40E_VIRTCHNL_OP_GET_VF_RESOURCES, |
| 170 | NULL, 0); |
Greg Rose | 62683ab | 2013-12-21 06:13:01 +0000 | [diff] [blame] | 171 | } |
| 172 | |
| 173 | /** |
| 174 | * i40evf_get_vf_config |
| 175 | * @hw: pointer to the hardware structure |
| 176 | * @len: length of buffer |
| 177 | * |
| 178 | * Get VF configuration from PF and populate hw structure. Must be called after |
| 179 | * admin queue is initialized. Busy waits until response is received from PF, |
| 180 | * with maximum timeout. Response from PF is returned in the buffer for further |
| 181 | * processing by the caller. |
| 182 | **/ |
| 183 | int i40evf_get_vf_config(struct i40evf_adapter *adapter) |
| 184 | { |
| 185 | struct i40e_hw *hw = &adapter->hw; |
| 186 | struct i40e_arq_event_info event; |
Mitch Williams | f8d4db3 | 2014-10-25 03:24:33 +0000 | [diff] [blame] | 187 | enum i40e_virtchnl_ops op; |
Greg Rose | 62683ab | 2013-12-21 06:13:01 +0000 | [diff] [blame] | 188 | i40e_status err; |
Mitch Williams | f8d4db3 | 2014-10-25 03:24:33 +0000 | [diff] [blame] | 189 | u16 len; |
Greg Rose | 62683ab | 2013-12-21 06:13:01 +0000 | [diff] [blame] | 190 | |
| 191 | len = sizeof(struct i40e_virtchnl_vf_resource) + |
| 192 | I40E_MAX_VF_VSI * sizeof(struct i40e_virtchnl_vsi_resource); |
Mitch Williams | 1001dc3 | 2014-11-11 20:02:19 +0000 | [diff] [blame] | 193 | event.buf_len = len; |
| 194 | event.msg_buf = kzalloc(event.buf_len, GFP_KERNEL); |
Greg Rose | 62683ab | 2013-12-21 06:13:01 +0000 | [diff] [blame] | 195 | if (!event.msg_buf) { |
| 196 | err = -ENOMEM; |
| 197 | goto out; |
| 198 | } |
| 199 | |
Mitch Williams | f8d4db3 | 2014-10-25 03:24:33 +0000 | [diff] [blame] | 200 | while (1) { |
Mitch Williams | f8d4db3 | 2014-10-25 03:24:33 +0000 | [diff] [blame] | 201 | /* When the AQ is empty, i40evf_clean_arq_element will return |
| 202 | * nonzero and this loop will terminate. |
| 203 | */ |
| 204 | err = i40evf_clean_arq_element(hw, &event, NULL); |
| 205 | if (err) |
| 206 | goto out_alloc; |
| 207 | op = |
| 208 | (enum i40e_virtchnl_ops)le32_to_cpu(event.desc.cookie_high); |
| 209 | if (op == I40E_VIRTCHNL_OP_GET_VF_RESOURCES) |
| 210 | break; |
| 211 | } |
Greg Rose | 62683ab | 2013-12-21 06:13:01 +0000 | [diff] [blame] | 212 | |
| 213 | err = (i40e_status)le32_to_cpu(event.desc.cookie_low); |
Mitch Williams | 1001dc3 | 2014-11-11 20:02:19 +0000 | [diff] [blame] | 214 | memcpy(adapter->vf_res, event.msg_buf, min(event.msg_len, len)); |
Greg Rose | 62683ab | 2013-12-21 06:13:01 +0000 | [diff] [blame] | 215 | |
| 216 | i40e_vf_parse_hw_config(hw, adapter->vf_res); |
| 217 | out_alloc: |
| 218 | kfree(event.msg_buf); |
| 219 | out: |
| 220 | return err; |
| 221 | } |
| 222 | |
| 223 | /** |
| 224 | * i40evf_configure_queues |
| 225 | * @adapter: adapter structure |
| 226 | * |
| 227 | * Request that the PF set up our (previously allocated) queues. |
| 228 | **/ |
| 229 | void i40evf_configure_queues(struct i40evf_adapter *adapter) |
| 230 | { |
| 231 | struct i40e_virtchnl_vsi_queue_config_info *vqci; |
| 232 | struct i40e_virtchnl_queue_pair_info *vqpi; |
Mitch Williams | cc05292 | 2014-10-25 03:24:34 +0000 | [diff] [blame] | 233 | int pairs = adapter->num_active_queues; |
Greg Rose | 62683ab | 2013-12-21 06:13:01 +0000 | [diff] [blame] | 234 | int i, len; |
| 235 | |
| 236 | if (adapter->current_op != I40E_VIRTCHNL_OP_UNKNOWN) { |
| 237 | /* bail because we already have a command pending */ |
Shannon Nelson | fb43201f | 2015-08-26 15:14:17 -0400 | [diff] [blame] | 238 | dev_err(&adapter->pdev->dev, "Cannot configure queues, command %d pending\n", |
| 239 | adapter->current_op); |
Greg Rose | 62683ab | 2013-12-21 06:13:01 +0000 | [diff] [blame] | 240 | return; |
| 241 | } |
| 242 | adapter->current_op = I40E_VIRTCHNL_OP_CONFIG_VSI_QUEUES; |
| 243 | len = sizeof(struct i40e_virtchnl_vsi_queue_config_info) + |
| 244 | (sizeof(struct i40e_virtchnl_queue_pair_info) * pairs); |
| 245 | vqci = kzalloc(len, GFP_ATOMIC); |
Mitch Williams | 249c8b8 | 2014-05-10 04:49:04 +0000 | [diff] [blame] | 246 | if (!vqci) |
Greg Rose | 62683ab | 2013-12-21 06:13:01 +0000 | [diff] [blame] | 247 | return; |
Mitch Williams | 249c8b8 | 2014-05-10 04:49:04 +0000 | [diff] [blame] | 248 | |
Greg Rose | 62683ab | 2013-12-21 06:13:01 +0000 | [diff] [blame] | 249 | vqci->vsi_id = adapter->vsi_res->vsi_id; |
| 250 | vqci->num_queue_pairs = pairs; |
| 251 | vqpi = vqci->qpair; |
| 252 | /* Size check is not needed here - HW max is 16 queue pairs, and we |
| 253 | * can fit info for 31 of them into the AQ buffer before it overflows. |
| 254 | */ |
| 255 | for (i = 0; i < pairs; i++) { |
| 256 | vqpi->txq.vsi_id = vqci->vsi_id; |
| 257 | vqpi->txq.queue_id = i; |
| 258 | vqpi->txq.ring_len = adapter->tx_rings[i]->count; |
| 259 | vqpi->txq.dma_ring_addr = adapter->tx_rings[i]->dma; |
Ashish Shah | 5d29896 | 2014-05-22 06:31:25 +0000 | [diff] [blame] | 260 | vqpi->txq.headwb_enabled = 1; |
| 261 | vqpi->txq.dma_headwb_addr = vqpi->txq.dma_ring_addr + |
| 262 | (vqpi->txq.ring_len * sizeof(struct i40e_tx_desc)); |
Greg Rose | 62683ab | 2013-12-21 06:13:01 +0000 | [diff] [blame] | 263 | |
| 264 | vqpi->rxq.vsi_id = vqci->vsi_id; |
| 265 | vqpi->rxq.queue_id = i; |
| 266 | vqpi->rxq.ring_len = adapter->rx_rings[i]->count; |
| 267 | vqpi->rxq.dma_ring_addr = adapter->rx_rings[i]->dma; |
| 268 | vqpi->rxq.max_pkt_size = adapter->netdev->mtu |
| 269 | + ETH_HLEN + VLAN_HLEN + ETH_FCS_LEN; |
| 270 | vqpi->rxq.databuffer_size = adapter->rx_rings[i]->rx_buf_len; |
| 271 | vqpi++; |
| 272 | } |
| 273 | |
Mitch Williams | fc86a97 | 2014-06-04 20:41:38 +0000 | [diff] [blame] | 274 | adapter->aq_required &= ~I40EVF_FLAG_AQ_CONFIGURE_QUEUES; |
Greg Rose | 62683ab | 2013-12-21 06:13:01 +0000 | [diff] [blame] | 275 | i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_CONFIG_VSI_QUEUES, |
| 276 | (u8 *)vqci, len); |
| 277 | kfree(vqci); |
Greg Rose | 62683ab | 2013-12-21 06:13:01 +0000 | [diff] [blame] | 278 | } |
| 279 | |
| 280 | /** |
| 281 | * i40evf_enable_queues |
| 282 | * @adapter: adapter structure |
| 283 | * |
| 284 | * Request that the PF enable all of our queues. |
| 285 | **/ |
| 286 | void i40evf_enable_queues(struct i40evf_adapter *adapter) |
| 287 | { |
| 288 | struct i40e_virtchnl_queue_select vqs; |
| 289 | |
| 290 | if (adapter->current_op != I40E_VIRTCHNL_OP_UNKNOWN) { |
| 291 | /* bail because we already have a command pending */ |
Shannon Nelson | fb43201f | 2015-08-26 15:14:17 -0400 | [diff] [blame] | 292 | dev_err(&adapter->pdev->dev, "Cannot enable queues, command %d pending\n", |
| 293 | adapter->current_op); |
Greg Rose | 62683ab | 2013-12-21 06:13:01 +0000 | [diff] [blame] | 294 | return; |
| 295 | } |
| 296 | adapter->current_op = I40E_VIRTCHNL_OP_ENABLE_QUEUES; |
| 297 | vqs.vsi_id = adapter->vsi_res->vsi_id; |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 298 | vqs.tx_queues = BIT(adapter->num_active_queues) - 1; |
Greg Rose | 62683ab | 2013-12-21 06:13:01 +0000 | [diff] [blame] | 299 | vqs.rx_queues = vqs.tx_queues; |
Greg Rose | 62683ab | 2013-12-21 06:13:01 +0000 | [diff] [blame] | 300 | adapter->aq_required &= ~I40EVF_FLAG_AQ_ENABLE_QUEUES; |
Mitch Williams | fc86a97 | 2014-06-04 20:41:38 +0000 | [diff] [blame] | 301 | i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_ENABLE_QUEUES, |
| 302 | (u8 *)&vqs, sizeof(vqs)); |
Greg Rose | 62683ab | 2013-12-21 06:13:01 +0000 | [diff] [blame] | 303 | } |
| 304 | |
| 305 | /** |
| 306 | * i40evf_disable_queues |
| 307 | * @adapter: adapter structure |
| 308 | * |
| 309 | * Request that the PF disable all of our queues. |
| 310 | **/ |
| 311 | void i40evf_disable_queues(struct i40evf_adapter *adapter) |
| 312 | { |
| 313 | struct i40e_virtchnl_queue_select vqs; |
| 314 | |
| 315 | if (adapter->current_op != I40E_VIRTCHNL_OP_UNKNOWN) { |
| 316 | /* bail because we already have a command pending */ |
Shannon Nelson | fb43201f | 2015-08-26 15:14:17 -0400 | [diff] [blame] | 317 | dev_err(&adapter->pdev->dev, "Cannot disable queues, command %d pending\n", |
| 318 | adapter->current_op); |
Greg Rose | 62683ab | 2013-12-21 06:13:01 +0000 | [diff] [blame] | 319 | return; |
| 320 | } |
| 321 | adapter->current_op = I40E_VIRTCHNL_OP_DISABLE_QUEUES; |
| 322 | vqs.vsi_id = adapter->vsi_res->vsi_id; |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 323 | vqs.tx_queues = BIT(adapter->num_active_queues) - 1; |
Greg Rose | 62683ab | 2013-12-21 06:13:01 +0000 | [diff] [blame] | 324 | vqs.rx_queues = vqs.tx_queues; |
Greg Rose | 62683ab | 2013-12-21 06:13:01 +0000 | [diff] [blame] | 325 | adapter->aq_required &= ~I40EVF_FLAG_AQ_DISABLE_QUEUES; |
Mitch Williams | fc86a97 | 2014-06-04 20:41:38 +0000 | [diff] [blame] | 326 | i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_DISABLE_QUEUES, |
| 327 | (u8 *)&vqs, sizeof(vqs)); |
Greg Rose | 62683ab | 2013-12-21 06:13:01 +0000 | [diff] [blame] | 328 | } |
| 329 | |
| 330 | /** |
| 331 | * i40evf_map_queues |
| 332 | * @adapter: adapter structure |
| 333 | * |
| 334 | * Request that the PF map queues to interrupt vectors. Misc causes, including |
| 335 | * admin queue, are always mapped to vector 0. |
| 336 | **/ |
| 337 | void i40evf_map_queues(struct i40evf_adapter *adapter) |
| 338 | { |
| 339 | struct i40e_virtchnl_irq_map_info *vimi; |
| 340 | int v_idx, q_vectors, len; |
| 341 | struct i40e_q_vector *q_vector; |
| 342 | |
| 343 | if (adapter->current_op != I40E_VIRTCHNL_OP_UNKNOWN) { |
| 344 | /* bail because we already have a command pending */ |
Shannon Nelson | fb43201f | 2015-08-26 15:14:17 -0400 | [diff] [blame] | 345 | dev_err(&adapter->pdev->dev, "Cannot map queues to vectors, command %d pending\n", |
| 346 | adapter->current_op); |
Greg Rose | 62683ab | 2013-12-21 06:13:01 +0000 | [diff] [blame] | 347 | return; |
| 348 | } |
| 349 | adapter->current_op = I40E_VIRTCHNL_OP_CONFIG_IRQ_MAP; |
| 350 | |
| 351 | q_vectors = adapter->num_msix_vectors - NONQ_VECS; |
| 352 | |
| 353 | len = sizeof(struct i40e_virtchnl_irq_map_info) + |
| 354 | (adapter->num_msix_vectors * |
| 355 | sizeof(struct i40e_virtchnl_vector_map)); |
| 356 | vimi = kzalloc(len, GFP_ATOMIC); |
Mitch Williams | 249c8b8 | 2014-05-10 04:49:04 +0000 | [diff] [blame] | 357 | if (!vimi) |
Greg Rose | 62683ab | 2013-12-21 06:13:01 +0000 | [diff] [blame] | 358 | return; |
Greg Rose | 62683ab | 2013-12-21 06:13:01 +0000 | [diff] [blame] | 359 | |
| 360 | vimi->num_vectors = adapter->num_msix_vectors; |
| 361 | /* Queue vectors first */ |
| 362 | for (v_idx = 0; v_idx < q_vectors; v_idx++) { |
| 363 | q_vector = adapter->q_vector[v_idx]; |
| 364 | vimi->vecmap[v_idx].vsi_id = adapter->vsi_res->vsi_id; |
| 365 | vimi->vecmap[v_idx].vector_id = v_idx + NONQ_VECS; |
| 366 | vimi->vecmap[v_idx].txq_map = q_vector->ring_mask; |
| 367 | vimi->vecmap[v_idx].rxq_map = q_vector->ring_mask; |
| 368 | } |
| 369 | /* Misc vector last - this is only for AdminQ messages */ |
| 370 | vimi->vecmap[v_idx].vsi_id = adapter->vsi_res->vsi_id; |
| 371 | vimi->vecmap[v_idx].vector_id = 0; |
| 372 | vimi->vecmap[v_idx].txq_map = 0; |
| 373 | vimi->vecmap[v_idx].rxq_map = 0; |
| 374 | |
Mitch Williams | fc86a97 | 2014-06-04 20:41:38 +0000 | [diff] [blame] | 375 | adapter->aq_required &= ~I40EVF_FLAG_AQ_MAP_VECTORS; |
Greg Rose | 62683ab | 2013-12-21 06:13:01 +0000 | [diff] [blame] | 376 | i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_CONFIG_IRQ_MAP, |
| 377 | (u8 *)vimi, len); |
| 378 | kfree(vimi); |
Greg Rose | 62683ab | 2013-12-21 06:13:01 +0000 | [diff] [blame] | 379 | } |
| 380 | |
| 381 | /** |
| 382 | * i40evf_add_ether_addrs |
| 383 | * @adapter: adapter structure |
| 384 | * @addrs: the MAC address filters to add (contiguous) |
| 385 | * @count: number of filters |
| 386 | * |
| 387 | * Request that the PF add one or more addresses to our filters. |
| 388 | **/ |
| 389 | void i40evf_add_ether_addrs(struct i40evf_adapter *adapter) |
| 390 | { |
| 391 | struct i40e_virtchnl_ether_addr_list *veal; |
| 392 | int len, i = 0, count = 0; |
| 393 | struct i40evf_mac_filter *f; |
Mitch Williams | 1418c34 | 2015-10-21 19:47:12 -0400 | [diff] [blame^] | 394 | bool more = false; |
Greg Rose | 62683ab | 2013-12-21 06:13:01 +0000 | [diff] [blame] | 395 | |
| 396 | if (adapter->current_op != I40E_VIRTCHNL_OP_UNKNOWN) { |
| 397 | /* bail because we already have a command pending */ |
Shannon Nelson | fb43201f | 2015-08-26 15:14:17 -0400 | [diff] [blame] | 398 | dev_err(&adapter->pdev->dev, "Cannot add filters, command %d pending\n", |
| 399 | adapter->current_op); |
Greg Rose | 62683ab | 2013-12-21 06:13:01 +0000 | [diff] [blame] | 400 | return; |
| 401 | } |
| 402 | list_for_each_entry(f, &adapter->mac_filter_list, list) { |
| 403 | if (f->add) |
| 404 | count++; |
| 405 | } |
| 406 | if (!count) { |
| 407 | adapter->aq_required &= ~I40EVF_FLAG_AQ_ADD_MAC_FILTER; |
| 408 | return; |
| 409 | } |
| 410 | adapter->current_op = I40E_VIRTCHNL_OP_ADD_ETHER_ADDRESS; |
| 411 | |
| 412 | len = sizeof(struct i40e_virtchnl_ether_addr_list) + |
| 413 | (count * sizeof(struct i40e_virtchnl_ether_addr)); |
| 414 | if (len > I40EVF_MAX_AQ_BUF_SIZE) { |
Shannon Nelson | fb43201f | 2015-08-26 15:14:17 -0400 | [diff] [blame] | 415 | dev_warn(&adapter->pdev->dev, "Too many add MAC changes in one request\n"); |
Greg Rose | 62683ab | 2013-12-21 06:13:01 +0000 | [diff] [blame] | 416 | count = (I40EVF_MAX_AQ_BUF_SIZE - |
| 417 | sizeof(struct i40e_virtchnl_ether_addr_list)) / |
| 418 | sizeof(struct i40e_virtchnl_ether_addr); |
Mitch Williams | 1418c34 | 2015-10-21 19:47:12 -0400 | [diff] [blame^] | 419 | len = sizeof(struct i40e_virtchnl_ether_addr_list) + |
| 420 | (count * sizeof(struct i40e_virtchnl_ether_addr)); |
| 421 | more = true; |
Greg Rose | 62683ab | 2013-12-21 06:13:01 +0000 | [diff] [blame] | 422 | } |
| 423 | |
| 424 | veal = kzalloc(len, GFP_ATOMIC); |
Mitch Williams | 249c8b8 | 2014-05-10 04:49:04 +0000 | [diff] [blame] | 425 | if (!veal) |
Greg Rose | 62683ab | 2013-12-21 06:13:01 +0000 | [diff] [blame] | 426 | return; |
Mitch Williams | 249c8b8 | 2014-05-10 04:49:04 +0000 | [diff] [blame] | 427 | |
Greg Rose | 62683ab | 2013-12-21 06:13:01 +0000 | [diff] [blame] | 428 | veal->vsi_id = adapter->vsi_res->vsi_id; |
| 429 | veal->num_elements = count; |
| 430 | list_for_each_entry(f, &adapter->mac_filter_list, list) { |
| 431 | if (f->add) { |
Greg Rose | 9a17390 | 2014-05-22 06:32:02 +0000 | [diff] [blame] | 432 | ether_addr_copy(veal->list[i].addr, f->macaddr); |
Greg Rose | 62683ab | 2013-12-21 06:13:01 +0000 | [diff] [blame] | 433 | i++; |
| 434 | f->add = false; |
| 435 | } |
| 436 | } |
Mitch Williams | 1418c34 | 2015-10-21 19:47:12 -0400 | [diff] [blame^] | 437 | if (!more) |
| 438 | adapter->aq_required &= ~I40EVF_FLAG_AQ_ADD_MAC_FILTER; |
Greg Rose | 62683ab | 2013-12-21 06:13:01 +0000 | [diff] [blame] | 439 | i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_ADD_ETHER_ADDRESS, |
| 440 | (u8 *)veal, len); |
| 441 | kfree(veal); |
Greg Rose | 62683ab | 2013-12-21 06:13:01 +0000 | [diff] [blame] | 442 | } |
| 443 | |
| 444 | /** |
| 445 | * i40evf_del_ether_addrs |
| 446 | * @adapter: adapter structure |
| 447 | * @addrs: the MAC address filters to remove (contiguous) |
| 448 | * @count: number of filtes |
| 449 | * |
| 450 | * Request that the PF remove one or more addresses from our filters. |
| 451 | **/ |
| 452 | void i40evf_del_ether_addrs(struct i40evf_adapter *adapter) |
| 453 | { |
| 454 | struct i40e_virtchnl_ether_addr_list *veal; |
| 455 | struct i40evf_mac_filter *f, *ftmp; |
| 456 | int len, i = 0, count = 0; |
Mitch Williams | 1418c34 | 2015-10-21 19:47:12 -0400 | [diff] [blame^] | 457 | bool more = false; |
Greg Rose | 62683ab | 2013-12-21 06:13:01 +0000 | [diff] [blame] | 458 | |
| 459 | if (adapter->current_op != I40E_VIRTCHNL_OP_UNKNOWN) { |
| 460 | /* bail because we already have a command pending */ |
Shannon Nelson | fb43201f | 2015-08-26 15:14:17 -0400 | [diff] [blame] | 461 | dev_err(&adapter->pdev->dev, "Cannot remove filters, command %d pending\n", |
| 462 | adapter->current_op); |
Greg Rose | 62683ab | 2013-12-21 06:13:01 +0000 | [diff] [blame] | 463 | return; |
| 464 | } |
| 465 | list_for_each_entry(f, &adapter->mac_filter_list, list) { |
| 466 | if (f->remove) |
| 467 | count++; |
| 468 | } |
| 469 | if (!count) { |
| 470 | adapter->aq_required &= ~I40EVF_FLAG_AQ_DEL_MAC_FILTER; |
| 471 | return; |
| 472 | } |
| 473 | adapter->current_op = I40E_VIRTCHNL_OP_DEL_ETHER_ADDRESS; |
| 474 | |
| 475 | len = sizeof(struct i40e_virtchnl_ether_addr_list) + |
| 476 | (count * sizeof(struct i40e_virtchnl_ether_addr)); |
| 477 | if (len > I40EVF_MAX_AQ_BUF_SIZE) { |
Shannon Nelson | fb43201f | 2015-08-26 15:14:17 -0400 | [diff] [blame] | 478 | dev_warn(&adapter->pdev->dev, "Too many delete MAC changes in one request\n"); |
Greg Rose | 62683ab | 2013-12-21 06:13:01 +0000 | [diff] [blame] | 479 | count = (I40EVF_MAX_AQ_BUF_SIZE - |
| 480 | sizeof(struct i40e_virtchnl_ether_addr_list)) / |
| 481 | sizeof(struct i40e_virtchnl_ether_addr); |
Mitch Williams | 1418c34 | 2015-10-21 19:47:12 -0400 | [diff] [blame^] | 482 | len = sizeof(struct i40e_virtchnl_ether_addr_list) + |
| 483 | (count * sizeof(struct i40e_virtchnl_ether_addr)); |
| 484 | more = true; |
Greg Rose | 62683ab | 2013-12-21 06:13:01 +0000 | [diff] [blame] | 485 | } |
| 486 | veal = kzalloc(len, GFP_ATOMIC); |
Mitch Williams | 249c8b8 | 2014-05-10 04:49:04 +0000 | [diff] [blame] | 487 | if (!veal) |
Greg Rose | 62683ab | 2013-12-21 06:13:01 +0000 | [diff] [blame] | 488 | return; |
Mitch Williams | 249c8b8 | 2014-05-10 04:49:04 +0000 | [diff] [blame] | 489 | |
Greg Rose | 62683ab | 2013-12-21 06:13:01 +0000 | [diff] [blame] | 490 | veal->vsi_id = adapter->vsi_res->vsi_id; |
| 491 | veal->num_elements = count; |
| 492 | list_for_each_entry_safe(f, ftmp, &adapter->mac_filter_list, list) { |
| 493 | if (f->remove) { |
Greg Rose | 9a17390 | 2014-05-22 06:32:02 +0000 | [diff] [blame] | 494 | ether_addr_copy(veal->list[i].addr, f->macaddr); |
Greg Rose | 62683ab | 2013-12-21 06:13:01 +0000 | [diff] [blame] | 495 | i++; |
| 496 | list_del(&f->list); |
| 497 | kfree(f); |
| 498 | } |
| 499 | } |
Mitch Williams | 1418c34 | 2015-10-21 19:47:12 -0400 | [diff] [blame^] | 500 | if (!more) |
| 501 | adapter->aq_required &= ~I40EVF_FLAG_AQ_DEL_MAC_FILTER; |
Greg Rose | 62683ab | 2013-12-21 06:13:01 +0000 | [diff] [blame] | 502 | i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_DEL_ETHER_ADDRESS, |
| 503 | (u8 *)veal, len); |
| 504 | kfree(veal); |
Greg Rose | 62683ab | 2013-12-21 06:13:01 +0000 | [diff] [blame] | 505 | } |
| 506 | |
| 507 | /** |
| 508 | * i40evf_add_vlans |
| 509 | * @adapter: adapter structure |
| 510 | * @vlans: the VLANs to add |
| 511 | * @count: number of VLANs |
| 512 | * |
| 513 | * Request that the PF add one or more VLAN filters to our VSI. |
| 514 | **/ |
| 515 | void i40evf_add_vlans(struct i40evf_adapter *adapter) |
| 516 | { |
| 517 | struct i40e_virtchnl_vlan_filter_list *vvfl; |
| 518 | int len, i = 0, count = 0; |
| 519 | struct i40evf_vlan_filter *f; |
Mitch Williams | 1418c34 | 2015-10-21 19:47:12 -0400 | [diff] [blame^] | 520 | bool more = false; |
Greg Rose | 62683ab | 2013-12-21 06:13:01 +0000 | [diff] [blame] | 521 | |
| 522 | if (adapter->current_op != I40E_VIRTCHNL_OP_UNKNOWN) { |
| 523 | /* bail because we already have a command pending */ |
Shannon Nelson | fb43201f | 2015-08-26 15:14:17 -0400 | [diff] [blame] | 524 | dev_err(&adapter->pdev->dev, "Cannot add VLANs, command %d pending\n", |
| 525 | adapter->current_op); |
Greg Rose | 62683ab | 2013-12-21 06:13:01 +0000 | [diff] [blame] | 526 | return; |
| 527 | } |
| 528 | |
| 529 | list_for_each_entry(f, &adapter->vlan_filter_list, list) { |
| 530 | if (f->add) |
| 531 | count++; |
| 532 | } |
| 533 | if (!count) { |
| 534 | adapter->aq_required &= ~I40EVF_FLAG_AQ_ADD_VLAN_FILTER; |
| 535 | return; |
| 536 | } |
| 537 | adapter->current_op = I40E_VIRTCHNL_OP_ADD_VLAN; |
| 538 | |
| 539 | len = sizeof(struct i40e_virtchnl_vlan_filter_list) + |
| 540 | (count * sizeof(u16)); |
| 541 | if (len > I40EVF_MAX_AQ_BUF_SIZE) { |
Shannon Nelson | fb43201f | 2015-08-26 15:14:17 -0400 | [diff] [blame] | 542 | dev_warn(&adapter->pdev->dev, "Too many add VLAN changes in one request\n"); |
Greg Rose | 62683ab | 2013-12-21 06:13:01 +0000 | [diff] [blame] | 543 | count = (I40EVF_MAX_AQ_BUF_SIZE - |
| 544 | sizeof(struct i40e_virtchnl_vlan_filter_list)) / |
| 545 | sizeof(u16); |
Mitch Williams | 1418c34 | 2015-10-21 19:47:12 -0400 | [diff] [blame^] | 546 | len = sizeof(struct i40e_virtchnl_vlan_filter_list) + |
| 547 | (count * sizeof(u16)); |
| 548 | more = true; |
Greg Rose | 62683ab | 2013-12-21 06:13:01 +0000 | [diff] [blame] | 549 | } |
| 550 | vvfl = kzalloc(len, GFP_ATOMIC); |
Mitch Williams | 249c8b8 | 2014-05-10 04:49:04 +0000 | [diff] [blame] | 551 | if (!vvfl) |
Greg Rose | 62683ab | 2013-12-21 06:13:01 +0000 | [diff] [blame] | 552 | return; |
Mitch Williams | 249c8b8 | 2014-05-10 04:49:04 +0000 | [diff] [blame] | 553 | |
Greg Rose | 62683ab | 2013-12-21 06:13:01 +0000 | [diff] [blame] | 554 | vvfl->vsi_id = adapter->vsi_res->vsi_id; |
| 555 | vvfl->num_elements = count; |
| 556 | list_for_each_entry(f, &adapter->vlan_filter_list, list) { |
| 557 | if (f->add) { |
| 558 | vvfl->vlan_id[i] = f->vlan; |
| 559 | i++; |
| 560 | f->add = false; |
| 561 | } |
| 562 | } |
Mitch Williams | 1418c34 | 2015-10-21 19:47:12 -0400 | [diff] [blame^] | 563 | if (!more) |
| 564 | adapter->aq_required &= ~I40EVF_FLAG_AQ_ADD_VLAN_FILTER; |
Mitch Williams | fc86a97 | 2014-06-04 20:41:38 +0000 | [diff] [blame] | 565 | i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_ADD_VLAN, (u8 *)vvfl, len); |
| 566 | kfree(vvfl); |
Greg Rose | 62683ab | 2013-12-21 06:13:01 +0000 | [diff] [blame] | 567 | } |
| 568 | |
| 569 | /** |
| 570 | * i40evf_del_vlans |
| 571 | * @adapter: adapter structure |
| 572 | * @vlans: the VLANs to remove |
| 573 | * @count: number of VLANs |
| 574 | * |
| 575 | * Request that the PF remove one or more VLAN filters from our VSI. |
| 576 | **/ |
| 577 | void i40evf_del_vlans(struct i40evf_adapter *adapter) |
| 578 | { |
| 579 | struct i40e_virtchnl_vlan_filter_list *vvfl; |
| 580 | struct i40evf_vlan_filter *f, *ftmp; |
| 581 | int len, i = 0, count = 0; |
Mitch Williams | 1418c34 | 2015-10-21 19:47:12 -0400 | [diff] [blame^] | 582 | bool more = false; |
Greg Rose | 62683ab | 2013-12-21 06:13:01 +0000 | [diff] [blame] | 583 | |
| 584 | if (adapter->current_op != I40E_VIRTCHNL_OP_UNKNOWN) { |
| 585 | /* bail because we already have a command pending */ |
Shannon Nelson | fb43201f | 2015-08-26 15:14:17 -0400 | [diff] [blame] | 586 | dev_err(&adapter->pdev->dev, "Cannot remove VLANs, command %d pending\n", |
| 587 | adapter->current_op); |
Greg Rose | 62683ab | 2013-12-21 06:13:01 +0000 | [diff] [blame] | 588 | return; |
| 589 | } |
| 590 | |
| 591 | list_for_each_entry(f, &adapter->vlan_filter_list, list) { |
| 592 | if (f->remove) |
| 593 | count++; |
| 594 | } |
| 595 | if (!count) { |
| 596 | adapter->aq_required &= ~I40EVF_FLAG_AQ_DEL_VLAN_FILTER; |
| 597 | return; |
| 598 | } |
| 599 | adapter->current_op = I40E_VIRTCHNL_OP_DEL_VLAN; |
| 600 | |
| 601 | len = sizeof(struct i40e_virtchnl_vlan_filter_list) + |
| 602 | (count * sizeof(u16)); |
| 603 | if (len > I40EVF_MAX_AQ_BUF_SIZE) { |
Shannon Nelson | fb43201f | 2015-08-26 15:14:17 -0400 | [diff] [blame] | 604 | dev_warn(&adapter->pdev->dev, "Too many delete VLAN changes in one request\n"); |
Greg Rose | 62683ab | 2013-12-21 06:13:01 +0000 | [diff] [blame] | 605 | count = (I40EVF_MAX_AQ_BUF_SIZE - |
| 606 | sizeof(struct i40e_virtchnl_vlan_filter_list)) / |
| 607 | sizeof(u16); |
Mitch Williams | 1418c34 | 2015-10-21 19:47:12 -0400 | [diff] [blame^] | 608 | len = sizeof(struct i40e_virtchnl_vlan_filter_list) + |
| 609 | (count * sizeof(u16)); |
| 610 | more = true; |
Greg Rose | 62683ab | 2013-12-21 06:13:01 +0000 | [diff] [blame] | 611 | } |
| 612 | vvfl = kzalloc(len, GFP_ATOMIC); |
Mitch Williams | 249c8b8 | 2014-05-10 04:49:04 +0000 | [diff] [blame] | 613 | if (!vvfl) |
Greg Rose | 62683ab | 2013-12-21 06:13:01 +0000 | [diff] [blame] | 614 | return; |
Mitch Williams | 249c8b8 | 2014-05-10 04:49:04 +0000 | [diff] [blame] | 615 | |
Greg Rose | 62683ab | 2013-12-21 06:13:01 +0000 | [diff] [blame] | 616 | vvfl->vsi_id = adapter->vsi_res->vsi_id; |
| 617 | vvfl->num_elements = count; |
| 618 | list_for_each_entry_safe(f, ftmp, &adapter->vlan_filter_list, list) { |
| 619 | if (f->remove) { |
| 620 | vvfl->vlan_id[i] = f->vlan; |
| 621 | i++; |
| 622 | list_del(&f->list); |
| 623 | kfree(f); |
| 624 | } |
| 625 | } |
Mitch Williams | 1418c34 | 2015-10-21 19:47:12 -0400 | [diff] [blame^] | 626 | if (!more) |
| 627 | adapter->aq_required &= ~I40EVF_FLAG_AQ_DEL_VLAN_FILTER; |
Mitch Williams | fc86a97 | 2014-06-04 20:41:38 +0000 | [diff] [blame] | 628 | i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_DEL_VLAN, (u8 *)vvfl, len); |
| 629 | kfree(vvfl); |
Greg Rose | 62683ab | 2013-12-21 06:13:01 +0000 | [diff] [blame] | 630 | } |
| 631 | |
| 632 | /** |
| 633 | * i40evf_set_promiscuous |
| 634 | * @adapter: adapter structure |
| 635 | * @flags: bitmask to control unicast/multicast promiscuous. |
| 636 | * |
| 637 | * Request that the PF enable promiscuous mode for our VSI. |
| 638 | **/ |
| 639 | void i40evf_set_promiscuous(struct i40evf_adapter *adapter, int flags) |
| 640 | { |
| 641 | struct i40e_virtchnl_promisc_info vpi; |
| 642 | |
| 643 | if (adapter->current_op != I40E_VIRTCHNL_OP_UNKNOWN) { |
| 644 | /* bail because we already have a command pending */ |
Shannon Nelson | fb43201f | 2015-08-26 15:14:17 -0400 | [diff] [blame] | 645 | dev_err(&adapter->pdev->dev, "Cannot set promiscuous mode, command %d pending\n", |
| 646 | adapter->current_op); |
Greg Rose | 62683ab | 2013-12-21 06:13:01 +0000 | [diff] [blame] | 647 | return; |
| 648 | } |
| 649 | adapter->current_op = I40E_VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE; |
| 650 | vpi.vsi_id = adapter->vsi_res->vsi_id; |
| 651 | vpi.flags = flags; |
| 652 | i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE, |
| 653 | (u8 *)&vpi, sizeof(vpi)); |
| 654 | } |
| 655 | |
| 656 | /** |
| 657 | * i40evf_request_stats |
| 658 | * @adapter: adapter structure |
| 659 | * |
| 660 | * Request VSI statistics from PF. |
| 661 | **/ |
| 662 | void i40evf_request_stats(struct i40evf_adapter *adapter) |
| 663 | { |
| 664 | struct i40e_virtchnl_queue_select vqs; |
Mitch Williams | 75a6443 | 2014-11-11 20:02:42 +0000 | [diff] [blame] | 665 | |
Greg Rose | 62683ab | 2013-12-21 06:13:01 +0000 | [diff] [blame] | 666 | if (adapter->current_op != I40E_VIRTCHNL_OP_UNKNOWN) { |
| 667 | /* no error message, this isn't crucial */ |
| 668 | return; |
| 669 | } |
| 670 | adapter->current_op = I40E_VIRTCHNL_OP_GET_STATS; |
| 671 | vqs.vsi_id = adapter->vsi_res->vsi_id; |
| 672 | /* queue maps are ignored for this message - only the vsi is used */ |
| 673 | if (i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_GET_STATS, |
| 674 | (u8 *)&vqs, sizeof(vqs))) |
| 675 | /* if the request failed, don't lock out others */ |
| 676 | adapter->current_op = I40E_VIRTCHNL_OP_UNKNOWN; |
| 677 | } |
Mitch Williams | 625777e | 2014-02-20 19:29:05 -0800 | [diff] [blame] | 678 | /** |
| 679 | * i40evf_request_reset |
| 680 | * @adapter: adapter structure |
| 681 | * |
| 682 | * Request that the PF reset this VF. No response is expected. |
| 683 | **/ |
| 684 | void i40evf_request_reset(struct i40evf_adapter *adapter) |
| 685 | { |
| 686 | /* Don't check CURRENT_OP - this is always higher priority */ |
| 687 | i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_RESET_VF, NULL, 0); |
| 688 | adapter->current_op = I40E_VIRTCHNL_OP_UNKNOWN; |
| 689 | } |
Greg Rose | 62683ab | 2013-12-21 06:13:01 +0000 | [diff] [blame] | 690 | |
| 691 | /** |
| 692 | * i40evf_virtchnl_completion |
| 693 | * @adapter: adapter structure |
| 694 | * @v_opcode: opcode sent by PF |
| 695 | * @v_retval: retval sent by PF |
| 696 | * @msg: message sent by PF |
| 697 | * @msglen: message length |
| 698 | * |
| 699 | * Asynchronous completion function for admin queue messages. Rather than busy |
| 700 | * wait, we fire off our requests and assume that no errors will be returned. |
| 701 | * This function handles the reply messages. |
| 702 | **/ |
| 703 | void i40evf_virtchnl_completion(struct i40evf_adapter *adapter, |
| 704 | enum i40e_virtchnl_ops v_opcode, |
| 705 | i40e_status v_retval, |
| 706 | u8 *msg, u16 msglen) |
| 707 | { |
| 708 | struct net_device *netdev = adapter->netdev; |
| 709 | |
| 710 | if (v_opcode == I40E_VIRTCHNL_OP_EVENT) { |
| 711 | struct i40e_virtchnl_pf_event *vpe = |
| 712 | (struct i40e_virtchnl_pf_event *)msg; |
| 713 | switch (vpe->event) { |
| 714 | case I40E_VIRTCHNL_EVENT_LINK_CHANGE: |
| 715 | adapter->link_up = |
| 716 | vpe->event_data.link_event.link_status; |
| 717 | if (adapter->link_up && !netif_carrier_ok(netdev)) { |
| 718 | dev_info(&adapter->pdev->dev, "NIC Link is Up\n"); |
| 719 | netif_carrier_on(netdev); |
| 720 | netif_tx_wake_all_queues(netdev); |
| 721 | } else if (!adapter->link_up) { |
| 722 | dev_info(&adapter->pdev->dev, "NIC Link is Down\n"); |
| 723 | netif_carrier_off(netdev); |
| 724 | netif_tx_stop_all_queues(netdev); |
| 725 | } |
| 726 | break; |
| 727 | case I40E_VIRTCHNL_EVENT_RESET_IMPENDING: |
Mitch Williams | ef8693e | 2014-02-13 03:48:53 -0800 | [diff] [blame] | 728 | dev_info(&adapter->pdev->dev, "PF reset warning received\n"); |
| 729 | if (!(adapter->flags & I40EVF_FLAG_RESET_PENDING)) { |
| 730 | adapter->flags |= I40EVF_FLAG_RESET_PENDING; |
| 731 | dev_info(&adapter->pdev->dev, "Scheduling reset task\n"); |
| 732 | schedule_work(&adapter->reset_task); |
| 733 | } |
Greg Rose | 62683ab | 2013-12-21 06:13:01 +0000 | [diff] [blame] | 734 | break; |
| 735 | default: |
Shannon Nelson | fb43201f | 2015-08-26 15:14:17 -0400 | [diff] [blame] | 736 | dev_err(&adapter->pdev->dev, "Unknown event %d from PF\n", |
| 737 | vpe->event); |
Greg Rose | 62683ab | 2013-12-21 06:13:01 +0000 | [diff] [blame] | 738 | break; |
Greg Rose | 62683ab | 2013-12-21 06:13:01 +0000 | [diff] [blame] | 739 | } |
| 740 | return; |
| 741 | } |
Greg Rose | 62683ab | 2013-12-21 06:13:01 +0000 | [diff] [blame] | 742 | if (v_retval) { |
Mitch Williams | 8d8f229 | 2015-10-21 19:47:11 -0400 | [diff] [blame] | 743 | switch (v_opcode) { |
| 744 | case I40E_VIRTCHNL_OP_ADD_VLAN: |
| 745 | dev_err(&adapter->pdev->dev, "Failed to add VLAN filter, error %s\n", |
| 746 | i40evf_stat_str(&adapter->hw, v_retval)); |
| 747 | break; |
| 748 | case I40E_VIRTCHNL_OP_ADD_ETHER_ADDRESS: |
| 749 | dev_err(&adapter->pdev->dev, "Failed to add MAC filter, error %s\n", |
| 750 | i40evf_stat_str(&adapter->hw, v_retval)); |
| 751 | break; |
| 752 | case I40E_VIRTCHNL_OP_DEL_VLAN: |
| 753 | dev_err(&adapter->pdev->dev, "Failed to delete VLAN filter, error %s\n", |
| 754 | i40evf_stat_str(&adapter->hw, v_retval)); |
| 755 | break; |
| 756 | case I40E_VIRTCHNL_OP_DEL_ETHER_ADDRESS: |
| 757 | dev_err(&adapter->pdev->dev, "Failed to delete MAC filter, error %s\n", |
| 758 | i40evf_stat_str(&adapter->hw, v_retval)); |
| 759 | break; |
| 760 | default: |
| 761 | dev_err(&adapter->pdev->dev, "PF returned error %d (%s) to our request %d\n", |
| 762 | v_retval, |
| 763 | i40evf_stat_str(&adapter->hw, v_retval), |
| 764 | v_opcode); |
| 765 | } |
Greg Rose | 62683ab | 2013-12-21 06:13:01 +0000 | [diff] [blame] | 766 | } |
| 767 | switch (v_opcode) { |
| 768 | case I40E_VIRTCHNL_OP_GET_STATS: { |
| 769 | struct i40e_eth_stats *stats = |
| 770 | (struct i40e_eth_stats *)msg; |
| 771 | adapter->net_stats.rx_packets = stats->rx_unicast + |
| 772 | stats->rx_multicast + |
| 773 | stats->rx_broadcast; |
| 774 | adapter->net_stats.tx_packets = stats->tx_unicast + |
| 775 | stats->tx_multicast + |
| 776 | stats->tx_broadcast; |
| 777 | adapter->net_stats.rx_bytes = stats->rx_bytes; |
| 778 | adapter->net_stats.tx_bytes = stats->tx_bytes; |
Greg Rose | 62683ab | 2013-12-21 06:13:01 +0000 | [diff] [blame] | 779 | adapter->net_stats.tx_errors = stats->tx_errors; |
Shannon Nelson | 03da6f6 | 2014-04-23 04:50:19 +0000 | [diff] [blame] | 780 | adapter->net_stats.rx_dropped = stats->rx_discards; |
Greg Rose | 62683ab | 2013-12-21 06:13:01 +0000 | [diff] [blame] | 781 | adapter->net_stats.tx_dropped = stats->tx_discards; |
| 782 | adapter->current_stats = *stats; |
| 783 | } |
| 784 | break; |
Mitch Williams | e6d038d | 2015-06-04 16:23:58 -0400 | [diff] [blame] | 785 | case I40E_VIRTCHNL_OP_GET_VF_RESOURCES: { |
| 786 | u16 len = sizeof(struct i40e_virtchnl_vf_resource) + |
| 787 | I40E_MAX_VF_VSI * |
| 788 | sizeof(struct i40e_virtchnl_vsi_resource); |
| 789 | memcpy(adapter->vf_res, msg, min(msglen, len)); |
| 790 | i40e_vf_parse_hw_config(&adapter->hw, adapter->vf_res); |
Mitch Williams | 8552d85 | 2015-08-31 19:54:51 -0400 | [diff] [blame] | 791 | /* restore current mac address */ |
| 792 | ether_addr_copy(adapter->hw.mac.addr, netdev->dev_addr); |
Mitch Williams | e6d038d | 2015-06-04 16:23:58 -0400 | [diff] [blame] | 793 | i40evf_process_config(adapter); |
| 794 | } |
| 795 | break; |
Greg Rose | 62683ab | 2013-12-21 06:13:01 +0000 | [diff] [blame] | 796 | case I40E_VIRTCHNL_OP_ENABLE_QUEUES: |
Greg Rose | 62683ab | 2013-12-21 06:13:01 +0000 | [diff] [blame] | 797 | /* enable transmits */ |
| 798 | i40evf_irq_enable(adapter, true); |
| 799 | netif_tx_start_all_queues(adapter->netdev); |
| 800 | netif_carrier_on(adapter->netdev); |
| 801 | break; |
| 802 | case I40E_VIRTCHNL_OP_DISABLE_QUEUES: |
Mitch Williams | e284fc8 | 2015-03-27 00:12:09 -0700 | [diff] [blame] | 803 | i40evf_free_all_tx_resources(adapter); |
| 804 | i40evf_free_all_rx_resources(adapter); |
Greg Rose | 62683ab | 2013-12-21 06:13:01 +0000 | [diff] [blame] | 805 | break; |
Mitch Williams | ed63696 | 2015-04-07 19:45:32 -0400 | [diff] [blame] | 806 | case I40E_VIRTCHNL_OP_VERSION: |
Greg Rose | 62683ab | 2013-12-21 06:13:01 +0000 | [diff] [blame] | 807 | case I40E_VIRTCHNL_OP_CONFIG_IRQ_MAP: |
Mitch Williams | ed63696 | 2015-04-07 19:45:32 -0400 | [diff] [blame] | 808 | /* Don't display an error if we get these out of sequence. |
| 809 | * If the firmware needed to get kicked, we'll get these and |
| 810 | * it's no problem. |
| 811 | */ |
| 812 | if (v_opcode != adapter->current_op) |
| 813 | return; |
Greg Rose | 62683ab | 2013-12-21 06:13:01 +0000 | [diff] [blame] | 814 | break; |
| 815 | default: |
Mitch Williams | ed63696 | 2015-04-07 19:45:32 -0400 | [diff] [blame] | 816 | if (v_opcode != adapter->current_op) |
| 817 | dev_warn(&adapter->pdev->dev, "Expected response %d from PF, received %d\n", |
| 818 | adapter->current_op, v_opcode); |
Greg Rose | 62683ab | 2013-12-21 06:13:01 +0000 | [diff] [blame] | 819 | break; |
| 820 | } /* switch v_opcode */ |
| 821 | adapter->current_op = I40E_VIRTCHNL_OP_UNKNOWN; |
| 822 | } |