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