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 | |
Anjali Singhai Jain | b9eacec | 2015-11-19 11:34:22 -0800 | [diff] [blame] | 160 | I40E_VIRTCHNL_VF_OFFLOAD_WB_ON_ITR | |
| 161 | I40E_VIRTCHNL_VF_OFFLOAD_RSS_PCTYPE_V2; |
| 162 | |
Mitch Williams | e6d038d | 2015-06-04 16:23:58 -0400 | [diff] [blame] | 163 | adapter->current_op = I40E_VIRTCHNL_OP_GET_VF_RESOURCES; |
| 164 | adapter->aq_required &= ~I40EVF_FLAG_AQ_GET_CONFIG; |
| 165 | if (PF_IS_V11(adapter)) |
| 166 | return i40evf_send_pf_msg(adapter, |
| 167 | I40E_VIRTCHNL_OP_GET_VF_RESOURCES, |
| 168 | (u8 *)&caps, sizeof(caps)); |
| 169 | else |
| 170 | return i40evf_send_pf_msg(adapter, |
| 171 | I40E_VIRTCHNL_OP_GET_VF_RESOURCES, |
| 172 | NULL, 0); |
Greg Rose | 62683ab | 2013-12-21 06:13:01 +0000 | [diff] [blame] | 173 | } |
| 174 | |
| 175 | /** |
| 176 | * i40evf_get_vf_config |
| 177 | * @hw: pointer to the hardware structure |
| 178 | * @len: length of buffer |
| 179 | * |
| 180 | * Get VF configuration from PF and populate hw structure. Must be called after |
| 181 | * admin queue is initialized. Busy waits until response is received from PF, |
| 182 | * with maximum timeout. Response from PF is returned in the buffer for further |
| 183 | * processing by the caller. |
| 184 | **/ |
| 185 | int i40evf_get_vf_config(struct i40evf_adapter *adapter) |
| 186 | { |
| 187 | struct i40e_hw *hw = &adapter->hw; |
| 188 | struct i40e_arq_event_info event; |
Mitch Williams | f8d4db3 | 2014-10-25 03:24:33 +0000 | [diff] [blame] | 189 | enum i40e_virtchnl_ops op; |
Greg Rose | 62683ab | 2013-12-21 06:13:01 +0000 | [diff] [blame] | 190 | i40e_status err; |
Mitch Williams | f8d4db3 | 2014-10-25 03:24:33 +0000 | [diff] [blame] | 191 | u16 len; |
Greg Rose | 62683ab | 2013-12-21 06:13:01 +0000 | [diff] [blame] | 192 | |
| 193 | len = sizeof(struct i40e_virtchnl_vf_resource) + |
| 194 | I40E_MAX_VF_VSI * sizeof(struct i40e_virtchnl_vsi_resource); |
Mitch Williams | 1001dc3 | 2014-11-11 20:02:19 +0000 | [diff] [blame] | 195 | event.buf_len = len; |
| 196 | event.msg_buf = kzalloc(event.buf_len, GFP_KERNEL); |
Greg Rose | 62683ab | 2013-12-21 06:13:01 +0000 | [diff] [blame] | 197 | if (!event.msg_buf) { |
| 198 | err = -ENOMEM; |
| 199 | goto out; |
| 200 | } |
| 201 | |
Mitch Williams | f8d4db3 | 2014-10-25 03:24:33 +0000 | [diff] [blame] | 202 | while (1) { |
Mitch Williams | f8d4db3 | 2014-10-25 03:24:33 +0000 | [diff] [blame] | 203 | /* When the AQ is empty, i40evf_clean_arq_element will return |
| 204 | * nonzero and this loop will terminate. |
| 205 | */ |
| 206 | err = i40evf_clean_arq_element(hw, &event, NULL); |
| 207 | if (err) |
| 208 | goto out_alloc; |
| 209 | op = |
| 210 | (enum i40e_virtchnl_ops)le32_to_cpu(event.desc.cookie_high); |
| 211 | if (op == I40E_VIRTCHNL_OP_GET_VF_RESOURCES) |
| 212 | break; |
| 213 | } |
Greg Rose | 62683ab | 2013-12-21 06:13:01 +0000 | [diff] [blame] | 214 | |
| 215 | err = (i40e_status)le32_to_cpu(event.desc.cookie_low); |
Mitch Williams | 1001dc3 | 2014-11-11 20:02:19 +0000 | [diff] [blame] | 216 | memcpy(adapter->vf_res, event.msg_buf, min(event.msg_len, len)); |
Greg Rose | 62683ab | 2013-12-21 06:13:01 +0000 | [diff] [blame] | 217 | |
| 218 | i40e_vf_parse_hw_config(hw, adapter->vf_res); |
| 219 | out_alloc: |
| 220 | kfree(event.msg_buf); |
| 221 | out: |
| 222 | return err; |
| 223 | } |
| 224 | |
| 225 | /** |
| 226 | * i40evf_configure_queues |
| 227 | * @adapter: adapter structure |
| 228 | * |
| 229 | * Request that the PF set up our (previously allocated) queues. |
| 230 | **/ |
| 231 | void i40evf_configure_queues(struct i40evf_adapter *adapter) |
| 232 | { |
| 233 | struct i40e_virtchnl_vsi_queue_config_info *vqci; |
| 234 | struct i40e_virtchnl_queue_pair_info *vqpi; |
Mitch Williams | cc05292 | 2014-10-25 03:24:34 +0000 | [diff] [blame] | 235 | int pairs = adapter->num_active_queues; |
Greg Rose | 62683ab | 2013-12-21 06:13:01 +0000 | [diff] [blame] | 236 | int i, len; |
| 237 | |
| 238 | if (adapter->current_op != I40E_VIRTCHNL_OP_UNKNOWN) { |
| 239 | /* bail because we already have a command pending */ |
Shannon Nelson | fb43201f | 2015-08-26 15:14:17 -0400 | [diff] [blame] | 240 | dev_err(&adapter->pdev->dev, "Cannot configure queues, command %d pending\n", |
| 241 | adapter->current_op); |
Greg Rose | 62683ab | 2013-12-21 06:13:01 +0000 | [diff] [blame] | 242 | return; |
| 243 | } |
| 244 | adapter->current_op = I40E_VIRTCHNL_OP_CONFIG_VSI_QUEUES; |
| 245 | len = sizeof(struct i40e_virtchnl_vsi_queue_config_info) + |
| 246 | (sizeof(struct i40e_virtchnl_queue_pair_info) * pairs); |
Mitch Williams | a85088d | 2015-11-06 15:26:04 -0800 | [diff] [blame] | 247 | vqci = kzalloc(len, GFP_KERNEL); |
Mitch Williams | 249c8b8 | 2014-05-10 04:49:04 +0000 | [diff] [blame] | 248 | if (!vqci) |
Greg Rose | 62683ab | 2013-12-21 06:13:01 +0000 | [diff] [blame] | 249 | return; |
Mitch Williams | 249c8b8 | 2014-05-10 04:49:04 +0000 | [diff] [blame] | 250 | |
Greg Rose | 62683ab | 2013-12-21 06:13:01 +0000 | [diff] [blame] | 251 | vqci->vsi_id = adapter->vsi_res->vsi_id; |
| 252 | vqci->num_queue_pairs = pairs; |
| 253 | vqpi = vqci->qpair; |
| 254 | /* Size check is not needed here - HW max is 16 queue pairs, and we |
| 255 | * can fit info for 31 of them into the AQ buffer before it overflows. |
| 256 | */ |
| 257 | for (i = 0; i < pairs; i++) { |
| 258 | vqpi->txq.vsi_id = vqci->vsi_id; |
| 259 | vqpi->txq.queue_id = i; |
Mitch Williams | 0dd438d | 2015-10-26 19:44:40 -0400 | [diff] [blame] | 260 | vqpi->txq.ring_len = adapter->tx_rings[i].count; |
| 261 | vqpi->txq.dma_ring_addr = adapter->tx_rings[i].dma; |
Ashish Shah | 5d29896 | 2014-05-22 06:31:25 +0000 | [diff] [blame] | 262 | vqpi->txq.headwb_enabled = 1; |
| 263 | vqpi->txq.dma_headwb_addr = vqpi->txq.dma_ring_addr + |
| 264 | (vqpi->txq.ring_len * sizeof(struct i40e_tx_desc)); |
Greg Rose | 62683ab | 2013-12-21 06:13:01 +0000 | [diff] [blame] | 265 | |
| 266 | vqpi->rxq.vsi_id = vqci->vsi_id; |
| 267 | vqpi->rxq.queue_id = i; |
Mitch Williams | 0dd438d | 2015-10-26 19:44:40 -0400 | [diff] [blame] | 268 | vqpi->rxq.ring_len = adapter->rx_rings[i].count; |
| 269 | vqpi->rxq.dma_ring_addr = adapter->rx_rings[i].dma; |
Greg Rose | 62683ab | 2013-12-21 06:13:01 +0000 | [diff] [blame] | 270 | vqpi->rxq.max_pkt_size = adapter->netdev->mtu |
| 271 | + ETH_HLEN + VLAN_HLEN + ETH_FCS_LEN; |
Mitch Williams | 0dd438d | 2015-10-26 19:44:40 -0400 | [diff] [blame] | 272 | vqpi->rxq.databuffer_size = adapter->rx_rings[i].rx_buf_len; |
Greg Rose | 62683ab | 2013-12-21 06:13:01 +0000 | [diff] [blame] | 273 | vqpi++; |
| 274 | } |
| 275 | |
Mitch Williams | fc86a97 | 2014-06-04 20:41:38 +0000 | [diff] [blame] | 276 | adapter->aq_required &= ~I40EVF_FLAG_AQ_CONFIGURE_QUEUES; |
Greg Rose | 62683ab | 2013-12-21 06:13:01 +0000 | [diff] [blame] | 277 | i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_CONFIG_VSI_QUEUES, |
| 278 | (u8 *)vqci, len); |
| 279 | kfree(vqci); |
Greg Rose | 62683ab | 2013-12-21 06:13:01 +0000 | [diff] [blame] | 280 | } |
| 281 | |
| 282 | /** |
| 283 | * i40evf_enable_queues |
| 284 | * @adapter: adapter structure |
| 285 | * |
| 286 | * Request that the PF enable all of our queues. |
| 287 | **/ |
| 288 | void i40evf_enable_queues(struct i40evf_adapter *adapter) |
| 289 | { |
| 290 | struct i40e_virtchnl_queue_select vqs; |
| 291 | |
| 292 | if (adapter->current_op != I40E_VIRTCHNL_OP_UNKNOWN) { |
| 293 | /* bail because we already have a command pending */ |
Shannon Nelson | fb43201f | 2015-08-26 15:14:17 -0400 | [diff] [blame] | 294 | dev_err(&adapter->pdev->dev, "Cannot enable queues, command %d pending\n", |
| 295 | adapter->current_op); |
Greg Rose | 62683ab | 2013-12-21 06:13:01 +0000 | [diff] [blame] | 296 | return; |
| 297 | } |
| 298 | adapter->current_op = I40E_VIRTCHNL_OP_ENABLE_QUEUES; |
| 299 | vqs.vsi_id = adapter->vsi_res->vsi_id; |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 300 | vqs.tx_queues = BIT(adapter->num_active_queues) - 1; |
Greg Rose | 62683ab | 2013-12-21 06:13:01 +0000 | [diff] [blame] | 301 | vqs.rx_queues = vqs.tx_queues; |
Greg Rose | 62683ab | 2013-12-21 06:13:01 +0000 | [diff] [blame] | 302 | adapter->aq_required &= ~I40EVF_FLAG_AQ_ENABLE_QUEUES; |
Mitch Williams | fc86a97 | 2014-06-04 20:41:38 +0000 | [diff] [blame] | 303 | i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_ENABLE_QUEUES, |
| 304 | (u8 *)&vqs, sizeof(vqs)); |
Greg Rose | 62683ab | 2013-12-21 06:13:01 +0000 | [diff] [blame] | 305 | } |
| 306 | |
| 307 | /** |
| 308 | * i40evf_disable_queues |
| 309 | * @adapter: adapter structure |
| 310 | * |
| 311 | * Request that the PF disable all of our queues. |
| 312 | **/ |
| 313 | void i40evf_disable_queues(struct i40evf_adapter *adapter) |
| 314 | { |
| 315 | struct i40e_virtchnl_queue_select vqs; |
| 316 | |
| 317 | if (adapter->current_op != I40E_VIRTCHNL_OP_UNKNOWN) { |
| 318 | /* bail because we already have a command pending */ |
Shannon Nelson | fb43201f | 2015-08-26 15:14:17 -0400 | [diff] [blame] | 319 | dev_err(&adapter->pdev->dev, "Cannot disable queues, command %d pending\n", |
| 320 | adapter->current_op); |
Greg Rose | 62683ab | 2013-12-21 06:13:01 +0000 | [diff] [blame] | 321 | return; |
| 322 | } |
| 323 | adapter->current_op = I40E_VIRTCHNL_OP_DISABLE_QUEUES; |
| 324 | vqs.vsi_id = adapter->vsi_res->vsi_id; |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 325 | vqs.tx_queues = BIT(adapter->num_active_queues) - 1; |
Greg Rose | 62683ab | 2013-12-21 06:13:01 +0000 | [diff] [blame] | 326 | vqs.rx_queues = vqs.tx_queues; |
Greg Rose | 62683ab | 2013-12-21 06:13:01 +0000 | [diff] [blame] | 327 | adapter->aq_required &= ~I40EVF_FLAG_AQ_DISABLE_QUEUES; |
Mitch Williams | fc86a97 | 2014-06-04 20:41:38 +0000 | [diff] [blame] | 328 | i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_DISABLE_QUEUES, |
| 329 | (u8 *)&vqs, sizeof(vqs)); |
Greg Rose | 62683ab | 2013-12-21 06:13:01 +0000 | [diff] [blame] | 330 | } |
| 331 | |
| 332 | /** |
| 333 | * i40evf_map_queues |
| 334 | * @adapter: adapter structure |
| 335 | * |
| 336 | * Request that the PF map queues to interrupt vectors. Misc causes, including |
| 337 | * admin queue, are always mapped to vector 0. |
| 338 | **/ |
| 339 | void i40evf_map_queues(struct i40evf_adapter *adapter) |
| 340 | { |
| 341 | struct i40e_virtchnl_irq_map_info *vimi; |
| 342 | int v_idx, q_vectors, len; |
| 343 | struct i40e_q_vector *q_vector; |
| 344 | |
| 345 | if (adapter->current_op != I40E_VIRTCHNL_OP_UNKNOWN) { |
| 346 | /* bail because we already have a command pending */ |
Shannon Nelson | fb43201f | 2015-08-26 15:14:17 -0400 | [diff] [blame] | 347 | dev_err(&adapter->pdev->dev, "Cannot map queues to vectors, command %d pending\n", |
| 348 | adapter->current_op); |
Greg Rose | 62683ab | 2013-12-21 06:13:01 +0000 | [diff] [blame] | 349 | return; |
| 350 | } |
| 351 | adapter->current_op = I40E_VIRTCHNL_OP_CONFIG_IRQ_MAP; |
| 352 | |
| 353 | q_vectors = adapter->num_msix_vectors - NONQ_VECS; |
| 354 | |
| 355 | len = sizeof(struct i40e_virtchnl_irq_map_info) + |
| 356 | (adapter->num_msix_vectors * |
| 357 | sizeof(struct i40e_virtchnl_vector_map)); |
Mitch Williams | a85088d | 2015-11-06 15:26:04 -0800 | [diff] [blame] | 358 | vimi = kzalloc(len, GFP_KERNEL); |
Mitch Williams | 249c8b8 | 2014-05-10 04:49:04 +0000 | [diff] [blame] | 359 | if (!vimi) |
Greg Rose | 62683ab | 2013-12-21 06:13:01 +0000 | [diff] [blame] | 360 | return; |
Greg Rose | 62683ab | 2013-12-21 06:13:01 +0000 | [diff] [blame] | 361 | |
| 362 | vimi->num_vectors = adapter->num_msix_vectors; |
| 363 | /* Queue vectors first */ |
| 364 | for (v_idx = 0; v_idx < q_vectors; v_idx++) { |
Mitch Williams | 7d96ba1 | 2015-10-26 19:44:39 -0400 | [diff] [blame] | 365 | q_vector = adapter->q_vectors + v_idx; |
Greg Rose | 62683ab | 2013-12-21 06:13:01 +0000 | [diff] [blame] | 366 | vimi->vecmap[v_idx].vsi_id = adapter->vsi_res->vsi_id; |
| 367 | vimi->vecmap[v_idx].vector_id = v_idx + NONQ_VECS; |
| 368 | vimi->vecmap[v_idx].txq_map = q_vector->ring_mask; |
| 369 | vimi->vecmap[v_idx].rxq_map = q_vector->ring_mask; |
| 370 | } |
| 371 | /* Misc vector last - this is only for AdminQ messages */ |
| 372 | vimi->vecmap[v_idx].vsi_id = adapter->vsi_res->vsi_id; |
| 373 | vimi->vecmap[v_idx].vector_id = 0; |
| 374 | vimi->vecmap[v_idx].txq_map = 0; |
| 375 | vimi->vecmap[v_idx].rxq_map = 0; |
| 376 | |
Mitch Williams | fc86a97 | 2014-06-04 20:41:38 +0000 | [diff] [blame] | 377 | adapter->aq_required &= ~I40EVF_FLAG_AQ_MAP_VECTORS; |
Greg Rose | 62683ab | 2013-12-21 06:13:01 +0000 | [diff] [blame] | 378 | i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_CONFIG_IRQ_MAP, |
| 379 | (u8 *)vimi, len); |
| 380 | kfree(vimi); |
Greg Rose | 62683ab | 2013-12-21 06:13:01 +0000 | [diff] [blame] | 381 | } |
| 382 | |
| 383 | /** |
| 384 | * i40evf_add_ether_addrs |
| 385 | * @adapter: adapter structure |
| 386 | * @addrs: the MAC address filters to add (contiguous) |
| 387 | * @count: number of filters |
| 388 | * |
| 389 | * Request that the PF add one or more addresses to our filters. |
| 390 | **/ |
| 391 | void i40evf_add_ether_addrs(struct i40evf_adapter *adapter) |
| 392 | { |
| 393 | struct i40e_virtchnl_ether_addr_list *veal; |
| 394 | int len, i = 0, count = 0; |
| 395 | struct i40evf_mac_filter *f; |
Mitch Williams | 1418c34 | 2015-10-21 19:47:12 -0400 | [diff] [blame] | 396 | bool more = false; |
Greg Rose | 62683ab | 2013-12-21 06:13:01 +0000 | [diff] [blame] | 397 | |
| 398 | if (adapter->current_op != I40E_VIRTCHNL_OP_UNKNOWN) { |
| 399 | /* bail because we already have a command pending */ |
Shannon Nelson | fb43201f | 2015-08-26 15:14:17 -0400 | [diff] [blame] | 400 | dev_err(&adapter->pdev->dev, "Cannot add filters, command %d pending\n", |
| 401 | adapter->current_op); |
Greg Rose | 62683ab | 2013-12-21 06:13:01 +0000 | [diff] [blame] | 402 | return; |
| 403 | } |
| 404 | list_for_each_entry(f, &adapter->mac_filter_list, list) { |
| 405 | if (f->add) |
| 406 | count++; |
| 407 | } |
| 408 | if (!count) { |
| 409 | adapter->aq_required &= ~I40EVF_FLAG_AQ_ADD_MAC_FILTER; |
| 410 | return; |
| 411 | } |
| 412 | adapter->current_op = I40E_VIRTCHNL_OP_ADD_ETHER_ADDRESS; |
| 413 | |
| 414 | len = sizeof(struct i40e_virtchnl_ether_addr_list) + |
| 415 | (count * sizeof(struct i40e_virtchnl_ether_addr)); |
| 416 | if (len > I40EVF_MAX_AQ_BUF_SIZE) { |
Shannon Nelson | fb43201f | 2015-08-26 15:14:17 -0400 | [diff] [blame] | 417 | 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] | 418 | count = (I40EVF_MAX_AQ_BUF_SIZE - |
| 419 | sizeof(struct i40e_virtchnl_ether_addr_list)) / |
| 420 | sizeof(struct i40e_virtchnl_ether_addr); |
Mitch Williams | 1418c34 | 2015-10-21 19:47:12 -0400 | [diff] [blame] | 421 | len = sizeof(struct i40e_virtchnl_ether_addr_list) + |
| 422 | (count * sizeof(struct i40e_virtchnl_ether_addr)); |
| 423 | more = true; |
Greg Rose | 62683ab | 2013-12-21 06:13:01 +0000 | [diff] [blame] | 424 | } |
| 425 | |
Mitch Williams | a85088d | 2015-11-06 15:26:04 -0800 | [diff] [blame] | 426 | veal = kzalloc(len, GFP_KERNEL); |
Mitch Williams | 249c8b8 | 2014-05-10 04:49:04 +0000 | [diff] [blame] | 427 | if (!veal) |
Greg Rose | 62683ab | 2013-12-21 06:13:01 +0000 | [diff] [blame] | 428 | return; |
Mitch Williams | 249c8b8 | 2014-05-10 04:49:04 +0000 | [diff] [blame] | 429 | |
Greg Rose | 62683ab | 2013-12-21 06:13:01 +0000 | [diff] [blame] | 430 | veal->vsi_id = adapter->vsi_res->vsi_id; |
| 431 | veal->num_elements = count; |
| 432 | list_for_each_entry(f, &adapter->mac_filter_list, list) { |
| 433 | if (f->add) { |
Greg Rose | 9a17390 | 2014-05-22 06:32:02 +0000 | [diff] [blame] | 434 | ether_addr_copy(veal->list[i].addr, f->macaddr); |
Greg Rose | 62683ab | 2013-12-21 06:13:01 +0000 | [diff] [blame] | 435 | i++; |
| 436 | f->add = false; |
Mitch Williams | 0e8d95f89 | 2016-05-16 10:26:36 -0700 | [diff] [blame] | 437 | if (i == count) |
| 438 | break; |
Greg Rose | 62683ab | 2013-12-21 06:13:01 +0000 | [diff] [blame] | 439 | } |
| 440 | } |
Mitch Williams | 1418c34 | 2015-10-21 19:47:12 -0400 | [diff] [blame] | 441 | if (!more) |
| 442 | adapter->aq_required &= ~I40EVF_FLAG_AQ_ADD_MAC_FILTER; |
Greg Rose | 62683ab | 2013-12-21 06:13:01 +0000 | [diff] [blame] | 443 | i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_ADD_ETHER_ADDRESS, |
| 444 | (u8 *)veal, len); |
| 445 | kfree(veal); |
Greg Rose | 62683ab | 2013-12-21 06:13:01 +0000 | [diff] [blame] | 446 | } |
| 447 | |
| 448 | /** |
| 449 | * i40evf_del_ether_addrs |
| 450 | * @adapter: adapter structure |
| 451 | * @addrs: the MAC address filters to remove (contiguous) |
| 452 | * @count: number of filtes |
| 453 | * |
| 454 | * Request that the PF remove one or more addresses from our filters. |
| 455 | **/ |
| 456 | void i40evf_del_ether_addrs(struct i40evf_adapter *adapter) |
| 457 | { |
| 458 | struct i40e_virtchnl_ether_addr_list *veal; |
| 459 | struct i40evf_mac_filter *f, *ftmp; |
| 460 | int len, i = 0, count = 0; |
Mitch Williams | 1418c34 | 2015-10-21 19:47:12 -0400 | [diff] [blame] | 461 | bool more = false; |
Greg Rose | 62683ab | 2013-12-21 06:13:01 +0000 | [diff] [blame] | 462 | |
| 463 | if (adapter->current_op != I40E_VIRTCHNL_OP_UNKNOWN) { |
| 464 | /* bail because we already have a command pending */ |
Shannon Nelson | fb43201f | 2015-08-26 15:14:17 -0400 | [diff] [blame] | 465 | dev_err(&adapter->pdev->dev, "Cannot remove filters, command %d pending\n", |
| 466 | adapter->current_op); |
Greg Rose | 62683ab | 2013-12-21 06:13:01 +0000 | [diff] [blame] | 467 | return; |
| 468 | } |
| 469 | list_for_each_entry(f, &adapter->mac_filter_list, list) { |
| 470 | if (f->remove) |
| 471 | count++; |
| 472 | } |
| 473 | if (!count) { |
| 474 | adapter->aq_required &= ~I40EVF_FLAG_AQ_DEL_MAC_FILTER; |
| 475 | return; |
| 476 | } |
| 477 | adapter->current_op = I40E_VIRTCHNL_OP_DEL_ETHER_ADDRESS; |
| 478 | |
| 479 | len = sizeof(struct i40e_virtchnl_ether_addr_list) + |
| 480 | (count * sizeof(struct i40e_virtchnl_ether_addr)); |
| 481 | if (len > I40EVF_MAX_AQ_BUF_SIZE) { |
Shannon Nelson | fb43201f | 2015-08-26 15:14:17 -0400 | [diff] [blame] | 482 | 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] | 483 | count = (I40EVF_MAX_AQ_BUF_SIZE - |
| 484 | sizeof(struct i40e_virtchnl_ether_addr_list)) / |
| 485 | sizeof(struct i40e_virtchnl_ether_addr); |
Mitch Williams | 1418c34 | 2015-10-21 19:47:12 -0400 | [diff] [blame] | 486 | len = sizeof(struct i40e_virtchnl_ether_addr_list) + |
| 487 | (count * sizeof(struct i40e_virtchnl_ether_addr)); |
| 488 | more = true; |
Greg Rose | 62683ab | 2013-12-21 06:13:01 +0000 | [diff] [blame] | 489 | } |
Mitch Williams | a85088d | 2015-11-06 15:26:04 -0800 | [diff] [blame] | 490 | veal = kzalloc(len, GFP_KERNEL); |
Mitch Williams | 249c8b8 | 2014-05-10 04:49:04 +0000 | [diff] [blame] | 491 | if (!veal) |
Greg Rose | 62683ab | 2013-12-21 06:13:01 +0000 | [diff] [blame] | 492 | return; |
Mitch Williams | 249c8b8 | 2014-05-10 04:49:04 +0000 | [diff] [blame] | 493 | |
Greg Rose | 62683ab | 2013-12-21 06:13:01 +0000 | [diff] [blame] | 494 | veal->vsi_id = adapter->vsi_res->vsi_id; |
| 495 | veal->num_elements = count; |
| 496 | list_for_each_entry_safe(f, ftmp, &adapter->mac_filter_list, list) { |
| 497 | if (f->remove) { |
Greg Rose | 9a17390 | 2014-05-22 06:32:02 +0000 | [diff] [blame] | 498 | ether_addr_copy(veal->list[i].addr, f->macaddr); |
Greg Rose | 62683ab | 2013-12-21 06:13:01 +0000 | [diff] [blame] | 499 | i++; |
| 500 | list_del(&f->list); |
| 501 | kfree(f); |
Mitch Williams | 0e8d95f89 | 2016-05-16 10:26:36 -0700 | [diff] [blame] | 502 | if (i == count) |
| 503 | break; |
Greg Rose | 62683ab | 2013-12-21 06:13:01 +0000 | [diff] [blame] | 504 | } |
| 505 | } |
Mitch Williams | 1418c34 | 2015-10-21 19:47:12 -0400 | [diff] [blame] | 506 | if (!more) |
| 507 | adapter->aq_required &= ~I40EVF_FLAG_AQ_DEL_MAC_FILTER; |
Greg Rose | 62683ab | 2013-12-21 06:13:01 +0000 | [diff] [blame] | 508 | i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_DEL_ETHER_ADDRESS, |
| 509 | (u8 *)veal, len); |
| 510 | kfree(veal); |
Greg Rose | 62683ab | 2013-12-21 06:13:01 +0000 | [diff] [blame] | 511 | } |
| 512 | |
| 513 | /** |
| 514 | * i40evf_add_vlans |
| 515 | * @adapter: adapter structure |
| 516 | * @vlans: the VLANs to add |
| 517 | * @count: number of VLANs |
| 518 | * |
| 519 | * Request that the PF add one or more VLAN filters to our VSI. |
| 520 | **/ |
| 521 | void i40evf_add_vlans(struct i40evf_adapter *adapter) |
| 522 | { |
| 523 | struct i40e_virtchnl_vlan_filter_list *vvfl; |
| 524 | int len, i = 0, count = 0; |
| 525 | struct i40evf_vlan_filter *f; |
Mitch Williams | 1418c34 | 2015-10-21 19:47:12 -0400 | [diff] [blame] | 526 | bool more = false; |
Greg Rose | 62683ab | 2013-12-21 06:13:01 +0000 | [diff] [blame] | 527 | |
| 528 | if (adapter->current_op != I40E_VIRTCHNL_OP_UNKNOWN) { |
| 529 | /* bail because we already have a command pending */ |
Shannon Nelson | fb43201f | 2015-08-26 15:14:17 -0400 | [diff] [blame] | 530 | dev_err(&adapter->pdev->dev, "Cannot add VLANs, command %d pending\n", |
| 531 | adapter->current_op); |
Greg Rose | 62683ab | 2013-12-21 06:13:01 +0000 | [diff] [blame] | 532 | return; |
| 533 | } |
| 534 | |
| 535 | list_for_each_entry(f, &adapter->vlan_filter_list, list) { |
| 536 | if (f->add) |
| 537 | count++; |
| 538 | } |
| 539 | if (!count) { |
| 540 | adapter->aq_required &= ~I40EVF_FLAG_AQ_ADD_VLAN_FILTER; |
| 541 | return; |
| 542 | } |
| 543 | adapter->current_op = I40E_VIRTCHNL_OP_ADD_VLAN; |
| 544 | |
| 545 | len = sizeof(struct i40e_virtchnl_vlan_filter_list) + |
| 546 | (count * sizeof(u16)); |
| 547 | if (len > I40EVF_MAX_AQ_BUF_SIZE) { |
Shannon Nelson | fb43201f | 2015-08-26 15:14:17 -0400 | [diff] [blame] | 548 | 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] | 549 | count = (I40EVF_MAX_AQ_BUF_SIZE - |
| 550 | sizeof(struct i40e_virtchnl_vlan_filter_list)) / |
| 551 | sizeof(u16); |
Mitch Williams | 1418c34 | 2015-10-21 19:47:12 -0400 | [diff] [blame] | 552 | len = sizeof(struct i40e_virtchnl_vlan_filter_list) + |
| 553 | (count * sizeof(u16)); |
| 554 | more = true; |
Greg Rose | 62683ab | 2013-12-21 06:13:01 +0000 | [diff] [blame] | 555 | } |
Mitch Williams | a85088d | 2015-11-06 15:26:04 -0800 | [diff] [blame] | 556 | vvfl = kzalloc(len, GFP_KERNEL); |
Mitch Williams | 249c8b8 | 2014-05-10 04:49:04 +0000 | [diff] [blame] | 557 | if (!vvfl) |
Greg Rose | 62683ab | 2013-12-21 06:13:01 +0000 | [diff] [blame] | 558 | return; |
Mitch Williams | 249c8b8 | 2014-05-10 04:49:04 +0000 | [diff] [blame] | 559 | |
Greg Rose | 62683ab | 2013-12-21 06:13:01 +0000 | [diff] [blame] | 560 | vvfl->vsi_id = adapter->vsi_res->vsi_id; |
| 561 | vvfl->num_elements = count; |
| 562 | list_for_each_entry(f, &adapter->vlan_filter_list, list) { |
| 563 | if (f->add) { |
| 564 | vvfl->vlan_id[i] = f->vlan; |
| 565 | i++; |
| 566 | f->add = false; |
Mitch Williams | 0e8d95f89 | 2016-05-16 10:26:36 -0700 | [diff] [blame] | 567 | if (i == count) |
| 568 | break; |
Greg Rose | 62683ab | 2013-12-21 06:13:01 +0000 | [diff] [blame] | 569 | } |
| 570 | } |
Mitch Williams | 1418c34 | 2015-10-21 19:47:12 -0400 | [diff] [blame] | 571 | if (!more) |
| 572 | adapter->aq_required &= ~I40EVF_FLAG_AQ_ADD_VLAN_FILTER; |
Mitch Williams | fc86a97 | 2014-06-04 20:41:38 +0000 | [diff] [blame] | 573 | i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_ADD_VLAN, (u8 *)vvfl, len); |
| 574 | kfree(vvfl); |
Greg Rose | 62683ab | 2013-12-21 06:13:01 +0000 | [diff] [blame] | 575 | } |
| 576 | |
| 577 | /** |
| 578 | * i40evf_del_vlans |
| 579 | * @adapter: adapter structure |
| 580 | * @vlans: the VLANs to remove |
| 581 | * @count: number of VLANs |
| 582 | * |
| 583 | * Request that the PF remove one or more VLAN filters from our VSI. |
| 584 | **/ |
| 585 | void i40evf_del_vlans(struct i40evf_adapter *adapter) |
| 586 | { |
| 587 | struct i40e_virtchnl_vlan_filter_list *vvfl; |
| 588 | struct i40evf_vlan_filter *f, *ftmp; |
| 589 | int len, i = 0, count = 0; |
Mitch Williams | 1418c34 | 2015-10-21 19:47:12 -0400 | [diff] [blame] | 590 | bool more = false; |
Greg Rose | 62683ab | 2013-12-21 06:13:01 +0000 | [diff] [blame] | 591 | |
| 592 | if (adapter->current_op != I40E_VIRTCHNL_OP_UNKNOWN) { |
| 593 | /* bail because we already have a command pending */ |
Shannon Nelson | fb43201f | 2015-08-26 15:14:17 -0400 | [diff] [blame] | 594 | dev_err(&adapter->pdev->dev, "Cannot remove VLANs, command %d pending\n", |
| 595 | adapter->current_op); |
Greg Rose | 62683ab | 2013-12-21 06:13:01 +0000 | [diff] [blame] | 596 | return; |
| 597 | } |
| 598 | |
| 599 | list_for_each_entry(f, &adapter->vlan_filter_list, list) { |
| 600 | if (f->remove) |
| 601 | count++; |
| 602 | } |
| 603 | if (!count) { |
| 604 | adapter->aq_required &= ~I40EVF_FLAG_AQ_DEL_VLAN_FILTER; |
| 605 | return; |
| 606 | } |
| 607 | adapter->current_op = I40E_VIRTCHNL_OP_DEL_VLAN; |
| 608 | |
| 609 | len = sizeof(struct i40e_virtchnl_vlan_filter_list) + |
| 610 | (count * sizeof(u16)); |
| 611 | if (len > I40EVF_MAX_AQ_BUF_SIZE) { |
Shannon Nelson | fb43201f | 2015-08-26 15:14:17 -0400 | [diff] [blame] | 612 | 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] | 613 | count = (I40EVF_MAX_AQ_BUF_SIZE - |
| 614 | sizeof(struct i40e_virtchnl_vlan_filter_list)) / |
| 615 | sizeof(u16); |
Mitch Williams | 1418c34 | 2015-10-21 19:47:12 -0400 | [diff] [blame] | 616 | len = sizeof(struct i40e_virtchnl_vlan_filter_list) + |
| 617 | (count * sizeof(u16)); |
| 618 | more = true; |
Greg Rose | 62683ab | 2013-12-21 06:13:01 +0000 | [diff] [blame] | 619 | } |
Mitch Williams | a85088d | 2015-11-06 15:26:04 -0800 | [diff] [blame] | 620 | vvfl = kzalloc(len, GFP_KERNEL); |
Mitch Williams | 249c8b8 | 2014-05-10 04:49:04 +0000 | [diff] [blame] | 621 | if (!vvfl) |
Greg Rose | 62683ab | 2013-12-21 06:13:01 +0000 | [diff] [blame] | 622 | return; |
Mitch Williams | 249c8b8 | 2014-05-10 04:49:04 +0000 | [diff] [blame] | 623 | |
Greg Rose | 62683ab | 2013-12-21 06:13:01 +0000 | [diff] [blame] | 624 | vvfl->vsi_id = adapter->vsi_res->vsi_id; |
| 625 | vvfl->num_elements = count; |
| 626 | list_for_each_entry_safe(f, ftmp, &adapter->vlan_filter_list, list) { |
| 627 | if (f->remove) { |
| 628 | vvfl->vlan_id[i] = f->vlan; |
| 629 | i++; |
| 630 | list_del(&f->list); |
| 631 | kfree(f); |
Mitch Williams | 0e8d95f89 | 2016-05-16 10:26:36 -0700 | [diff] [blame] | 632 | if (i == count) |
| 633 | break; |
Greg Rose | 62683ab | 2013-12-21 06:13:01 +0000 | [diff] [blame] | 634 | } |
| 635 | } |
Mitch Williams | 1418c34 | 2015-10-21 19:47:12 -0400 | [diff] [blame] | 636 | if (!more) |
| 637 | adapter->aq_required &= ~I40EVF_FLAG_AQ_DEL_VLAN_FILTER; |
Mitch Williams | fc86a97 | 2014-06-04 20:41:38 +0000 | [diff] [blame] | 638 | i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_DEL_VLAN, (u8 *)vvfl, len); |
| 639 | kfree(vvfl); |
Greg Rose | 62683ab | 2013-12-21 06:13:01 +0000 | [diff] [blame] | 640 | } |
| 641 | |
| 642 | /** |
| 643 | * i40evf_set_promiscuous |
| 644 | * @adapter: adapter structure |
| 645 | * @flags: bitmask to control unicast/multicast promiscuous. |
| 646 | * |
| 647 | * Request that the PF enable promiscuous mode for our VSI. |
| 648 | **/ |
| 649 | void i40evf_set_promiscuous(struct i40evf_adapter *adapter, int flags) |
| 650 | { |
| 651 | struct i40e_virtchnl_promisc_info vpi; |
Anjali Singhai Jain | f42a5c7 | 2016-05-03 15:13:10 -0700 | [diff] [blame] | 652 | int promisc_all; |
Greg Rose | 62683ab | 2013-12-21 06:13:01 +0000 | [diff] [blame] | 653 | |
| 654 | if (adapter->current_op != I40E_VIRTCHNL_OP_UNKNOWN) { |
| 655 | /* bail because we already have a command pending */ |
Shannon Nelson | fb43201f | 2015-08-26 15:14:17 -0400 | [diff] [blame] | 656 | dev_err(&adapter->pdev->dev, "Cannot set promiscuous mode, command %d pending\n", |
| 657 | adapter->current_op); |
Greg Rose | 62683ab | 2013-12-21 06:13:01 +0000 | [diff] [blame] | 658 | return; |
| 659 | } |
Anjali Singhai Jain | 47d3483 | 2016-04-12 08:30:52 -0700 | [diff] [blame] | 660 | |
Anjali Singhai Jain | f42a5c7 | 2016-05-03 15:13:10 -0700 | [diff] [blame] | 661 | promisc_all = I40E_FLAG_VF_UNICAST_PROMISC | |
| 662 | I40E_FLAG_VF_MULTICAST_PROMISC; |
| 663 | if ((flags & promisc_all) == promisc_all) { |
Anjali Singhai Jain | 47d3483 | 2016-04-12 08:30:52 -0700 | [diff] [blame] | 664 | adapter->flags |= I40EVF_FLAG_PROMISC_ON; |
| 665 | adapter->aq_required &= ~I40EVF_FLAG_AQ_REQUEST_PROMISC; |
| 666 | dev_info(&adapter->pdev->dev, "Entering promiscuous mode\n"); |
Anjali Singhai Jain | f42a5c7 | 2016-05-03 15:13:10 -0700 | [diff] [blame] | 667 | } |
| 668 | |
| 669 | if (flags & I40E_FLAG_VF_MULTICAST_PROMISC) { |
| 670 | adapter->flags |= I40EVF_FLAG_ALLMULTI_ON; |
| 671 | adapter->aq_required &= ~I40EVF_FLAG_AQ_REQUEST_ALLMULTI; |
| 672 | dev_info(&adapter->pdev->dev, "Entering multicast promiscuous mode\n"); |
| 673 | } |
| 674 | |
| 675 | if (!flags) { |
Anjali Singhai Jain | 47d3483 | 2016-04-12 08:30:52 -0700 | [diff] [blame] | 676 | adapter->flags &= ~I40EVF_FLAG_PROMISC_ON; |
| 677 | adapter->aq_required &= ~I40EVF_FLAG_AQ_RELEASE_PROMISC; |
| 678 | dev_info(&adapter->pdev->dev, "Leaving promiscuous mode\n"); |
| 679 | } |
| 680 | |
Greg Rose | 62683ab | 2013-12-21 06:13:01 +0000 | [diff] [blame] | 681 | adapter->current_op = I40E_VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE; |
| 682 | vpi.vsi_id = adapter->vsi_res->vsi_id; |
| 683 | vpi.flags = flags; |
| 684 | i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE, |
| 685 | (u8 *)&vpi, sizeof(vpi)); |
| 686 | } |
| 687 | |
| 688 | /** |
| 689 | * i40evf_request_stats |
| 690 | * @adapter: adapter structure |
| 691 | * |
| 692 | * Request VSI statistics from PF. |
| 693 | **/ |
| 694 | void i40evf_request_stats(struct i40evf_adapter *adapter) |
| 695 | { |
| 696 | struct i40e_virtchnl_queue_select vqs; |
Mitch Williams | 75a6443 | 2014-11-11 20:02:42 +0000 | [diff] [blame] | 697 | |
Greg Rose | 62683ab | 2013-12-21 06:13:01 +0000 | [diff] [blame] | 698 | if (adapter->current_op != I40E_VIRTCHNL_OP_UNKNOWN) { |
| 699 | /* no error message, this isn't crucial */ |
| 700 | return; |
| 701 | } |
| 702 | adapter->current_op = I40E_VIRTCHNL_OP_GET_STATS; |
| 703 | vqs.vsi_id = adapter->vsi_res->vsi_id; |
| 704 | /* queue maps are ignored for this message - only the vsi is used */ |
| 705 | if (i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_GET_STATS, |
| 706 | (u8 *)&vqs, sizeof(vqs))) |
| 707 | /* if the request failed, don't lock out others */ |
| 708 | adapter->current_op = I40E_VIRTCHNL_OP_UNKNOWN; |
| 709 | } |
Mitch Williams | 43a3d9b | 2016-04-12 08:30:44 -0700 | [diff] [blame] | 710 | |
| 711 | /** |
| 712 | * i40evf_get_hena |
| 713 | * @adapter: adapter structure |
| 714 | * |
| 715 | * Request hash enable capabilities from PF |
| 716 | **/ |
| 717 | void i40evf_get_hena(struct i40evf_adapter *adapter) |
| 718 | { |
| 719 | if (adapter->current_op != I40E_VIRTCHNL_OP_UNKNOWN) { |
| 720 | /* bail because we already have a command pending */ |
| 721 | dev_err(&adapter->pdev->dev, "Cannot get RSS hash capabilities, command %d pending\n", |
| 722 | adapter->current_op); |
| 723 | return; |
| 724 | } |
| 725 | adapter->current_op = I40E_VIRTCHNL_OP_GET_RSS_HENA_CAPS; |
| 726 | adapter->aq_required &= ~I40EVF_FLAG_AQ_GET_HENA; |
| 727 | i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_GET_RSS_HENA_CAPS, |
| 728 | NULL, 0); |
| 729 | } |
| 730 | |
| 731 | /** |
| 732 | * i40evf_set_hena |
| 733 | * @adapter: adapter structure |
| 734 | * |
| 735 | * Request the PF to set our RSS hash capabilities |
| 736 | **/ |
| 737 | void i40evf_set_hena(struct i40evf_adapter *adapter) |
| 738 | { |
| 739 | struct i40e_virtchnl_rss_hena vrh; |
| 740 | |
| 741 | if (adapter->current_op != I40E_VIRTCHNL_OP_UNKNOWN) { |
| 742 | /* bail because we already have a command pending */ |
| 743 | dev_err(&adapter->pdev->dev, "Cannot set RSS hash enable, command %d pending\n", |
| 744 | adapter->current_op); |
| 745 | return; |
| 746 | } |
| 747 | vrh.hena = adapter->hena; |
| 748 | adapter->current_op = I40E_VIRTCHNL_OP_SET_RSS_HENA; |
| 749 | adapter->aq_required &= ~I40EVF_FLAG_AQ_SET_HENA; |
| 750 | i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_SET_RSS_HENA, |
| 751 | (u8 *)&vrh, sizeof(vrh)); |
| 752 | } |
| 753 | |
| 754 | /** |
| 755 | * i40evf_set_rss_key |
| 756 | * @adapter: adapter structure |
| 757 | * |
| 758 | * Request the PF to set our RSS hash key |
| 759 | **/ |
| 760 | void i40evf_set_rss_key(struct i40evf_adapter *adapter) |
| 761 | { |
| 762 | struct i40e_virtchnl_rss_key *vrk; |
| 763 | int len; |
| 764 | |
| 765 | if (adapter->current_op != I40E_VIRTCHNL_OP_UNKNOWN) { |
| 766 | /* bail because we already have a command pending */ |
| 767 | dev_err(&adapter->pdev->dev, "Cannot set RSS key, command %d pending\n", |
| 768 | adapter->current_op); |
| 769 | return; |
| 770 | } |
| 771 | len = sizeof(struct i40e_virtchnl_rss_key) + |
| 772 | (adapter->rss_key_size * sizeof(u8)) - 1; |
| 773 | vrk = kzalloc(len, GFP_KERNEL); |
| 774 | if (!vrk) |
| 775 | return; |
| 776 | vrk->vsi_id = adapter->vsi.id; |
| 777 | vrk->key_len = adapter->rss_key_size; |
| 778 | memcpy(vrk->key, adapter->rss_key, adapter->rss_key_size); |
| 779 | |
| 780 | adapter->current_op = I40E_VIRTCHNL_OP_CONFIG_RSS_KEY; |
| 781 | adapter->aq_required &= ~I40EVF_FLAG_AQ_SET_RSS_KEY; |
| 782 | i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_CONFIG_RSS_KEY, |
| 783 | (u8 *)vrk, len); |
| 784 | kfree(vrk); |
| 785 | } |
| 786 | |
| 787 | /** |
| 788 | * i40evf_set_rss_lut |
| 789 | * @adapter: adapter structure |
| 790 | * |
| 791 | * Request the PF to set our RSS lookup table |
| 792 | **/ |
| 793 | void i40evf_set_rss_lut(struct i40evf_adapter *adapter) |
| 794 | { |
| 795 | struct i40e_virtchnl_rss_lut *vrl; |
| 796 | int len; |
| 797 | |
| 798 | if (adapter->current_op != I40E_VIRTCHNL_OP_UNKNOWN) { |
| 799 | /* bail because we already have a command pending */ |
| 800 | dev_err(&adapter->pdev->dev, "Cannot set RSS LUT, command %d pending\n", |
| 801 | adapter->current_op); |
| 802 | return; |
| 803 | } |
| 804 | len = sizeof(struct i40e_virtchnl_rss_lut) + |
| 805 | (adapter->rss_lut_size * sizeof(u8)) - 1; |
| 806 | vrl = kzalloc(len, GFP_KERNEL); |
| 807 | if (!vrl) |
| 808 | return; |
| 809 | vrl->vsi_id = adapter->vsi.id; |
| 810 | vrl->lut_entries = adapter->rss_lut_size; |
| 811 | memcpy(vrl->lut, adapter->rss_lut, adapter->rss_lut_size); |
| 812 | adapter->current_op = I40E_VIRTCHNL_OP_CONFIG_RSS_LUT; |
| 813 | adapter->aq_required &= ~I40EVF_FLAG_AQ_SET_RSS_LUT; |
| 814 | i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_CONFIG_RSS_LUT, |
| 815 | (u8 *)vrl, len); |
| 816 | kfree(vrl); |
| 817 | } |
| 818 | |
Mitch Williams | 625777e | 2014-02-20 19:29:05 -0800 | [diff] [blame] | 819 | /** |
Mitch Williams | fe458e5 | 2016-08-04 11:37:02 -0700 | [diff] [blame] | 820 | * i40evf_print_link_message - print link up or down |
| 821 | * @adapter: adapter structure |
| 822 | * |
| 823 | * Log a message telling the world of our wonderous link status |
| 824 | */ |
| 825 | static void i40evf_print_link_message(struct i40evf_adapter *adapter) |
| 826 | { |
| 827 | struct net_device *netdev = adapter->netdev; |
| 828 | char *speed = "Unknown "; |
| 829 | |
| 830 | if (!adapter->link_up) { |
| 831 | netdev_info(netdev, "NIC Link is Down\n"); |
| 832 | return; |
| 833 | } |
| 834 | |
| 835 | switch (adapter->link_speed) { |
| 836 | case I40E_LINK_SPEED_40GB: |
| 837 | speed = "40 G"; |
| 838 | break; |
| 839 | case I40E_LINK_SPEED_20GB: |
| 840 | speed = "20 G"; |
| 841 | break; |
| 842 | case I40E_LINK_SPEED_10GB: |
| 843 | speed = "10 G"; |
| 844 | break; |
| 845 | case I40E_LINK_SPEED_1GB: |
| 846 | speed = "1000 M"; |
| 847 | break; |
| 848 | case I40E_LINK_SPEED_100MB: |
| 849 | speed = "100 M"; |
| 850 | break; |
| 851 | default: |
| 852 | break; |
| 853 | } |
| 854 | |
| 855 | netdev_info(netdev, "NIC Link is Up %sbps Full Duplex\n", speed); |
| 856 | } |
| 857 | |
| 858 | /** |
Mitch Williams | 625777e | 2014-02-20 19:29:05 -0800 | [diff] [blame] | 859 | * i40evf_request_reset |
| 860 | * @adapter: adapter structure |
| 861 | * |
| 862 | * Request that the PF reset this VF. No response is expected. |
| 863 | **/ |
| 864 | void i40evf_request_reset(struct i40evf_adapter *adapter) |
| 865 | { |
| 866 | /* Don't check CURRENT_OP - this is always higher priority */ |
| 867 | i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_RESET_VF, NULL, 0); |
| 868 | adapter->current_op = I40E_VIRTCHNL_OP_UNKNOWN; |
| 869 | } |
Greg Rose | 62683ab | 2013-12-21 06:13:01 +0000 | [diff] [blame] | 870 | |
| 871 | /** |
| 872 | * i40evf_virtchnl_completion |
| 873 | * @adapter: adapter structure |
| 874 | * @v_opcode: opcode sent by PF |
| 875 | * @v_retval: retval sent by PF |
| 876 | * @msg: message sent by PF |
| 877 | * @msglen: message length |
| 878 | * |
| 879 | * Asynchronous completion function for admin queue messages. Rather than busy |
| 880 | * wait, we fire off our requests and assume that no errors will be returned. |
| 881 | * This function handles the reply messages. |
| 882 | **/ |
| 883 | void i40evf_virtchnl_completion(struct i40evf_adapter *adapter, |
| 884 | enum i40e_virtchnl_ops v_opcode, |
| 885 | i40e_status v_retval, |
| 886 | u8 *msg, u16 msglen) |
| 887 | { |
| 888 | struct net_device *netdev = adapter->netdev; |
| 889 | |
| 890 | if (v_opcode == I40E_VIRTCHNL_OP_EVENT) { |
| 891 | struct i40e_virtchnl_pf_event *vpe = |
| 892 | (struct i40e_virtchnl_pf_event *)msg; |
| 893 | switch (vpe->event) { |
| 894 | case I40E_VIRTCHNL_EVENT_LINK_CHANGE: |
Mitch Williams | fe458e5 | 2016-08-04 11:37:02 -0700 | [diff] [blame] | 895 | adapter->link_speed = |
| 896 | vpe->event_data.link_event.link_speed; |
| 897 | if (adapter->link_up != |
| 898 | vpe->event_data.link_event.link_status) { |
| 899 | adapter->link_up = |
| 900 | vpe->event_data.link_event.link_status; |
| 901 | i40evf_print_link_message(adapter); |
Greg Rose | 62683ab | 2013-12-21 06:13:01 +0000 | [diff] [blame] | 902 | netif_tx_stop_all_queues(netdev); |
| 903 | } |
| 904 | break; |
| 905 | case I40E_VIRTCHNL_EVENT_RESET_IMPENDING: |
Mitch Williams | ef8693e | 2014-02-13 03:48:53 -0800 | [diff] [blame] | 906 | dev_info(&adapter->pdev->dev, "PF reset warning received\n"); |
| 907 | if (!(adapter->flags & I40EVF_FLAG_RESET_PENDING)) { |
| 908 | adapter->flags |= I40EVF_FLAG_RESET_PENDING; |
| 909 | dev_info(&adapter->pdev->dev, "Scheduling reset task\n"); |
| 910 | schedule_work(&adapter->reset_task); |
| 911 | } |
Greg Rose | 62683ab | 2013-12-21 06:13:01 +0000 | [diff] [blame] | 912 | break; |
| 913 | default: |
Shannon Nelson | fb43201f | 2015-08-26 15:14:17 -0400 | [diff] [blame] | 914 | dev_err(&adapter->pdev->dev, "Unknown event %d from PF\n", |
| 915 | vpe->event); |
Greg Rose | 62683ab | 2013-12-21 06:13:01 +0000 | [diff] [blame] | 916 | break; |
Greg Rose | 62683ab | 2013-12-21 06:13:01 +0000 | [diff] [blame] | 917 | } |
| 918 | return; |
| 919 | } |
Greg Rose | 62683ab | 2013-12-21 06:13:01 +0000 | [diff] [blame] | 920 | if (v_retval) { |
Mitch Williams | 8d8f229 | 2015-10-21 19:47:11 -0400 | [diff] [blame] | 921 | switch (v_opcode) { |
| 922 | case I40E_VIRTCHNL_OP_ADD_VLAN: |
| 923 | dev_err(&adapter->pdev->dev, "Failed to add VLAN filter, error %s\n", |
| 924 | i40evf_stat_str(&adapter->hw, v_retval)); |
| 925 | break; |
| 926 | case I40E_VIRTCHNL_OP_ADD_ETHER_ADDRESS: |
| 927 | dev_err(&adapter->pdev->dev, "Failed to add MAC filter, error %s\n", |
| 928 | i40evf_stat_str(&adapter->hw, v_retval)); |
| 929 | break; |
| 930 | case I40E_VIRTCHNL_OP_DEL_VLAN: |
| 931 | dev_err(&adapter->pdev->dev, "Failed to delete VLAN filter, error %s\n", |
| 932 | i40evf_stat_str(&adapter->hw, v_retval)); |
| 933 | break; |
| 934 | case I40E_VIRTCHNL_OP_DEL_ETHER_ADDRESS: |
| 935 | dev_err(&adapter->pdev->dev, "Failed to delete MAC filter, error %s\n", |
| 936 | i40evf_stat_str(&adapter->hw, v_retval)); |
| 937 | break; |
| 938 | default: |
| 939 | dev_err(&adapter->pdev->dev, "PF returned error %d (%s) to our request %d\n", |
| 940 | v_retval, |
| 941 | i40evf_stat_str(&adapter->hw, v_retval), |
| 942 | v_opcode); |
| 943 | } |
Greg Rose | 62683ab | 2013-12-21 06:13:01 +0000 | [diff] [blame] | 944 | } |
| 945 | switch (v_opcode) { |
| 946 | case I40E_VIRTCHNL_OP_GET_STATS: { |
| 947 | struct i40e_eth_stats *stats = |
| 948 | (struct i40e_eth_stats *)msg; |
| 949 | adapter->net_stats.rx_packets = stats->rx_unicast + |
| 950 | stats->rx_multicast + |
| 951 | stats->rx_broadcast; |
| 952 | adapter->net_stats.tx_packets = stats->tx_unicast + |
| 953 | stats->tx_multicast + |
| 954 | stats->tx_broadcast; |
| 955 | adapter->net_stats.rx_bytes = stats->rx_bytes; |
| 956 | adapter->net_stats.tx_bytes = stats->tx_bytes; |
Greg Rose | 62683ab | 2013-12-21 06:13:01 +0000 | [diff] [blame] | 957 | adapter->net_stats.tx_errors = stats->tx_errors; |
Shannon Nelson | 03da6f6 | 2014-04-23 04:50:19 +0000 | [diff] [blame] | 958 | adapter->net_stats.rx_dropped = stats->rx_discards; |
Greg Rose | 62683ab | 2013-12-21 06:13:01 +0000 | [diff] [blame] | 959 | adapter->net_stats.tx_dropped = stats->tx_discards; |
| 960 | adapter->current_stats = *stats; |
| 961 | } |
| 962 | break; |
Mitch Williams | e6d038d | 2015-06-04 16:23:58 -0400 | [diff] [blame] | 963 | case I40E_VIRTCHNL_OP_GET_VF_RESOURCES: { |
| 964 | u16 len = sizeof(struct i40e_virtchnl_vf_resource) + |
| 965 | I40E_MAX_VF_VSI * |
| 966 | sizeof(struct i40e_virtchnl_vsi_resource); |
| 967 | memcpy(adapter->vf_res, msg, min(msglen, len)); |
| 968 | i40e_vf_parse_hw_config(&adapter->hw, adapter->vf_res); |
Mitch Williams | 8552d85 | 2015-08-31 19:54:51 -0400 | [diff] [blame] | 969 | /* restore current mac address */ |
| 970 | ether_addr_copy(adapter->hw.mac.addr, netdev->dev_addr); |
Mitch Williams | e6d038d | 2015-06-04 16:23:58 -0400 | [diff] [blame] | 971 | i40evf_process_config(adapter); |
| 972 | } |
| 973 | break; |
Greg Rose | 62683ab | 2013-12-21 06:13:01 +0000 | [diff] [blame] | 974 | case I40E_VIRTCHNL_OP_ENABLE_QUEUES: |
Greg Rose | 62683ab | 2013-12-21 06:13:01 +0000 | [diff] [blame] | 975 | /* enable transmits */ |
| 976 | i40evf_irq_enable(adapter, true); |
| 977 | netif_tx_start_all_queues(adapter->netdev); |
| 978 | netif_carrier_on(adapter->netdev); |
| 979 | break; |
| 980 | case I40E_VIRTCHNL_OP_DISABLE_QUEUES: |
Mitch Williams | e284fc8 | 2015-03-27 00:12:09 -0700 | [diff] [blame] | 981 | i40evf_free_all_tx_resources(adapter); |
| 982 | i40evf_free_all_rx_resources(adapter); |
Mitch Williams | 209dc4d | 2015-12-09 15:50:27 -0800 | [diff] [blame] | 983 | if (adapter->state == __I40EVF_DOWN_PENDING) |
| 984 | adapter->state = __I40EVF_DOWN; |
Greg Rose | 62683ab | 2013-12-21 06:13:01 +0000 | [diff] [blame] | 985 | break; |
Mitch Williams | ed63696 | 2015-04-07 19:45:32 -0400 | [diff] [blame] | 986 | case I40E_VIRTCHNL_OP_VERSION: |
Greg Rose | 62683ab | 2013-12-21 06:13:01 +0000 | [diff] [blame] | 987 | case I40E_VIRTCHNL_OP_CONFIG_IRQ_MAP: |
Mitch Williams | ed63696 | 2015-04-07 19:45:32 -0400 | [diff] [blame] | 988 | /* Don't display an error if we get these out of sequence. |
| 989 | * If the firmware needed to get kicked, we'll get these and |
| 990 | * it's no problem. |
| 991 | */ |
| 992 | if (v_opcode != adapter->current_op) |
| 993 | return; |
Greg Rose | 62683ab | 2013-12-21 06:13:01 +0000 | [diff] [blame] | 994 | break; |
Mitch Williams | 43a3d9b | 2016-04-12 08:30:44 -0700 | [diff] [blame] | 995 | case I40E_VIRTCHNL_OP_GET_RSS_HENA_CAPS: { |
| 996 | struct i40e_virtchnl_rss_hena *vrh = |
| 997 | (struct i40e_virtchnl_rss_hena *)msg; |
| 998 | if (msglen == sizeof(*vrh)) |
| 999 | adapter->hena = vrh->hena; |
| 1000 | else |
| 1001 | dev_warn(&adapter->pdev->dev, |
| 1002 | "Invalid message %d from PF\n", v_opcode); |
| 1003 | } |
| 1004 | break; |
Greg Rose | 62683ab | 2013-12-21 06:13:01 +0000 | [diff] [blame] | 1005 | default: |
Mitch Williams | ed63696 | 2015-04-07 19:45:32 -0400 | [diff] [blame] | 1006 | if (v_opcode != adapter->current_op) |
| 1007 | dev_warn(&adapter->pdev->dev, "Expected response %d from PF, received %d\n", |
| 1008 | adapter->current_op, v_opcode); |
Greg Rose | 62683ab | 2013-12-21 06:13:01 +0000 | [diff] [blame] | 1009 | break; |
| 1010 | } /* switch v_opcode */ |
| 1011 | adapter->current_op = I40E_VIRTCHNL_OP_UNKNOWN; |
| 1012 | } |