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