Linux Audio

Check our new training course

Loading...
v6.13.7
   1// SPDX-License-Identifier: GPL-2.0
   2/* Copyright(c) 2013 - 2018 Intel Corporation. */
   3
   4#include <linux/net/intel/libie/rx.h>
   5
   6#include "iavf.h"
   7#include "iavf_prototype.h"
 
 
 
 
 
   8
   9/**
  10 * iavf_send_pf_msg
  11 * @adapter: adapter structure
  12 * @op: virtual channel opcode
  13 * @msg: pointer to message buffer
  14 * @len: message length
  15 *
  16 * Send message to PF and print status if failure.
  17 **/
  18static int iavf_send_pf_msg(struct iavf_adapter *adapter,
  19			    enum virtchnl_ops op, u8 *msg, u16 len)
  20{
  21	struct iavf_hw *hw = &adapter->hw;
  22	enum iavf_status status;
  23
  24	if (adapter->flags & IAVF_FLAG_PF_COMMS_FAILED)
  25		return 0; /* nothing to see here, move along */
  26
  27	status = iavf_aq_send_msg_to_pf(hw, op, 0, msg, len, NULL);
  28	if (status)
  29		dev_dbg(&adapter->pdev->dev, "Unable to send opcode %d to PF, status %s, aq_err %s\n",
  30			op, iavf_stat_str(hw, status),
  31			iavf_aq_str(hw, hw->aq.asq_last_status));
  32	return iavf_status_to_errno(status);
  33}
  34
  35/**
  36 * iavf_send_api_ver
  37 * @adapter: adapter structure
  38 *
  39 * Send API version admin queue message to the PF. The reply is not checked
  40 * in this function. Returns 0 if the message was successfully
  41 * sent, or one of the IAVF_ADMIN_QUEUE_ERROR_ statuses if not.
  42 **/
  43int iavf_send_api_ver(struct iavf_adapter *adapter)
  44{
  45	struct virtchnl_version_info vvi;
  46
  47	vvi.major = VIRTCHNL_VERSION_MAJOR;
  48	vvi.minor = VIRTCHNL_VERSION_MINOR;
  49
  50	return iavf_send_pf_msg(adapter, VIRTCHNL_OP_VERSION, (u8 *)&vvi,
  51				sizeof(vvi));
  52}
  53
  54/**
  55 * iavf_poll_virtchnl_msg
  56 * @hw: HW configuration structure
  57 * @event: event to populate on success
  58 * @op_to_poll: requested virtchnl op to poll for
  59 *
  60 * Initialize poll for virtchnl msg matching the requested_op. Returns 0
  61 * if a message of the correct opcode is in the queue or an error code
  62 * if no message matching the op code is waiting and other failures.
  63 */
  64static int
  65iavf_poll_virtchnl_msg(struct iavf_hw *hw, struct iavf_arq_event_info *event,
  66		       enum virtchnl_ops op_to_poll)
  67{
  68	enum virtchnl_ops received_op;
  69	enum iavf_status status;
  70	u32 v_retval;
  71
  72	while (1) {
  73		/* When the AQ is empty, iavf_clean_arq_element will return
  74		 * nonzero and this loop will terminate.
  75		 */
  76		status = iavf_clean_arq_element(hw, event, NULL);
  77		if (status != IAVF_SUCCESS)
  78			return iavf_status_to_errno(status);
  79		received_op =
  80		    (enum virtchnl_ops)le32_to_cpu(event->desc.cookie_high);
  81		if (op_to_poll == received_op)
  82			break;
  83	}
  84
  85	v_retval = le32_to_cpu(event->desc.cookie_low);
  86	return virtchnl_status_to_errno((enum virtchnl_status_code)v_retval);
  87}
  88
  89/**
  90 * iavf_verify_api_ver
  91 * @adapter: adapter structure
  92 *
  93 * Compare API versions with the PF. Must be called after admin queue is
  94 * initialized. Returns 0 if API versions match, -EIO if they do not,
  95 * IAVF_ERR_ADMIN_QUEUE_NO_WORK if the admin queue is empty, and any errors
  96 * from the firmware are propagated.
  97 **/
  98int iavf_verify_api_ver(struct iavf_adapter *adapter)
  99{
 
 
 100	struct iavf_arq_event_info event;
 101	int err;
 
 102
 103	event.buf_len = IAVF_MAX_AQ_BUF_SIZE;
 104	event.msg_buf = kzalloc(IAVF_MAX_AQ_BUF_SIZE, GFP_KERNEL);
 105	if (!event.msg_buf)
 106		return -ENOMEM;
 107
 108	err = iavf_poll_virtchnl_msg(&adapter->hw, &event, VIRTCHNL_OP_VERSION);
 109	if (!err) {
 110		struct virtchnl_version_info *pf_vvi =
 111			(struct virtchnl_version_info *)event.msg_buf;
 112		adapter->pf_version = *pf_vvi;
 113
 114		if (pf_vvi->major > VIRTCHNL_VERSION_MAJOR ||
 115		    (pf_vvi->major == VIRTCHNL_VERSION_MAJOR &&
 116		     pf_vvi->minor > VIRTCHNL_VERSION_MINOR))
 117			err = -EIO;
 118	}
 119
 120	kfree(event.msg_buf);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 121
 
 
 
 
 
 
 
 
 
 
 
 122	return err;
 123}
 124
 125/**
 126 * iavf_send_vf_config_msg
 127 * @adapter: adapter structure
 128 *
 129 * Send VF configuration request admin queue message to the PF. The reply
 130 * is not checked in this function. Returns 0 if the message was
 131 * successfully sent, or one of the IAVF_ADMIN_QUEUE_ERROR_ statuses if not.
 132 **/
 133int iavf_send_vf_config_msg(struct iavf_adapter *adapter)
 134{
 135	u32 caps;
 136
 137	caps = VIRTCHNL_VF_OFFLOAD_L2 |
 138	       VIRTCHNL_VF_OFFLOAD_RSS_PF |
 139	       VIRTCHNL_VF_OFFLOAD_RSS_AQ |
 140	       VIRTCHNL_VF_OFFLOAD_RSS_REG |
 141	       VIRTCHNL_VF_OFFLOAD_VLAN |
 142	       VIRTCHNL_VF_OFFLOAD_WB_ON_ITR |
 143	       VIRTCHNL_VF_OFFLOAD_RSS_PCTYPE_V2 |
 144	       VIRTCHNL_VF_OFFLOAD_ENCAP |
 145	       VIRTCHNL_VF_OFFLOAD_TC_U32 |
 146	       VIRTCHNL_VF_OFFLOAD_VLAN_V2 |
 147	       VIRTCHNL_VF_OFFLOAD_CRC |
 148	       VIRTCHNL_VF_OFFLOAD_ENCAP_CSUM |
 149	       VIRTCHNL_VF_OFFLOAD_REQ_QUEUES |
 150	       VIRTCHNL_VF_OFFLOAD_ADQ |
 151	       VIRTCHNL_VF_OFFLOAD_USO |
 152	       VIRTCHNL_VF_OFFLOAD_FDIR_PF |
 153	       VIRTCHNL_VF_OFFLOAD_ADV_RSS_PF |
 154	       VIRTCHNL_VF_CAP_ADV_LINK_SPEED |
 155	       VIRTCHNL_VF_OFFLOAD_QOS;
 156
 157	adapter->current_op = VIRTCHNL_OP_GET_VF_RESOURCES;
 158	adapter->aq_required &= ~IAVF_FLAG_AQ_GET_CONFIG;
 159	if (PF_IS_V11(adapter))
 160		return iavf_send_pf_msg(adapter, VIRTCHNL_OP_GET_VF_RESOURCES,
 161					(u8 *)&caps, sizeof(caps));
 162	else
 163		return iavf_send_pf_msg(adapter, VIRTCHNL_OP_GET_VF_RESOURCES,
 164					NULL, 0);
 165}
 166
 167int iavf_send_vf_offload_vlan_v2_msg(struct iavf_adapter *adapter)
 168{
 169	adapter->aq_required &= ~IAVF_FLAG_AQ_GET_OFFLOAD_VLAN_V2_CAPS;
 170
 171	if (!VLAN_V2_ALLOWED(adapter))
 172		return -EOPNOTSUPP;
 173
 174	adapter->current_op = VIRTCHNL_OP_GET_OFFLOAD_VLAN_V2_CAPS;
 175
 176	return iavf_send_pf_msg(adapter, VIRTCHNL_OP_GET_OFFLOAD_VLAN_V2_CAPS,
 177				NULL, 0);
 178}
 179
 180/**
 181 * iavf_validate_num_queues
 182 * @adapter: adapter structure
 183 *
 184 * Validate that the number of queues the PF has sent in
 185 * VIRTCHNL_OP_GET_VF_RESOURCES is not larger than the VF can handle.
 186 **/
 187static void iavf_validate_num_queues(struct iavf_adapter *adapter)
 188{
 189	if (adapter->vf_res->num_queue_pairs > IAVF_MAX_REQ_QUEUES) {
 190		struct virtchnl_vsi_resource *vsi_res;
 191		int i;
 192
 193		dev_info(&adapter->pdev->dev, "Received %d queues, but can only have a max of %d\n",
 194			 adapter->vf_res->num_queue_pairs,
 195			 IAVF_MAX_REQ_QUEUES);
 196		dev_info(&adapter->pdev->dev, "Fixing by reducing queues to %d\n",
 197			 IAVF_MAX_REQ_QUEUES);
 198		adapter->vf_res->num_queue_pairs = IAVF_MAX_REQ_QUEUES;
 199		for (i = 0; i < adapter->vf_res->num_vsis; i++) {
 200			vsi_res = &adapter->vf_res->vsi_res[i];
 201			vsi_res->num_queue_pairs = IAVF_MAX_REQ_QUEUES;
 202		}
 203	}
 204}
 205
 206/**
 207 * iavf_get_vf_config
 208 * @adapter: private adapter structure
 209 *
 210 * Get VF configuration from PF and populate hw structure. Must be called after
 211 * admin queue is initialized. Busy waits until response is received from PF,
 212 * with maximum timeout. Response from PF is returned in the buffer for further
 213 * processing by the caller.
 214 **/
 215int iavf_get_vf_config(struct iavf_adapter *adapter)
 216{
 217	struct iavf_hw *hw = &adapter->hw;
 218	struct iavf_arq_event_info event;
 
 
 219	u16 len;
 220	int err;
 221
 222	len = IAVF_VIRTCHNL_VF_RESOURCE_SIZE;
 
 223	event.buf_len = len;
 224	event.msg_buf = kzalloc(len, GFP_KERNEL);
 225	if (!event.msg_buf)
 226		return -ENOMEM;
 
 
 227
 228	err = iavf_poll_virtchnl_msg(hw, &event, VIRTCHNL_OP_GET_VF_RESOURCES);
 
 
 
 
 
 
 
 
 
 
 
 
 
 229	memcpy(adapter->vf_res, event.msg_buf, min(event.msg_len, len));
 230
 231	/* some PFs send more queues than we should have so validate that
 232	 * we aren't getting too many queues
 233	 */
 234	if (!err)
 235		iavf_validate_num_queues(adapter);
 236	iavf_vf_parse_hw_config(hw, adapter->vf_res);
 237
 238	kfree(event.msg_buf);
 239
 240	return err;
 241}
 242
 243int iavf_get_vf_vlan_v2_caps(struct iavf_adapter *adapter)
 244{
 245	struct iavf_arq_event_info event;
 246	int err;
 247	u16 len;
 248
 249	len = sizeof(struct virtchnl_vlan_caps);
 250	event.buf_len = len;
 251	event.msg_buf = kzalloc(len, GFP_KERNEL);
 252	if (!event.msg_buf)
 253		return -ENOMEM;
 254
 255	err = iavf_poll_virtchnl_msg(&adapter->hw, &event,
 256				     VIRTCHNL_OP_GET_OFFLOAD_VLAN_V2_CAPS);
 257	if (!err)
 258		memcpy(&adapter->vlan_v2_caps, event.msg_buf,
 259		       min(event.msg_len, len));
 260
 261	kfree(event.msg_buf);
 262
 263	return err;
 264}
 265
 266/**
 267 * iavf_configure_queues
 268 * @adapter: adapter structure
 269 *
 270 * Request that the PF set up our (previously allocated) queues.
 271 **/
 272void iavf_configure_queues(struct iavf_adapter *adapter)
 273{
 274	struct virtchnl_vsi_queue_config_info *vqci;
 275	int pairs = adapter->num_active_queues;
 276	struct virtchnl_queue_pair_info *vqpi;
 277	u32 i, max_frame;
 
 278	size_t len;
 279
 280	max_frame = LIBIE_MAX_RX_FRM_LEN(adapter->rx_rings->pp->p.offset);
 281	max_frame = min_not_zero(adapter->vf_res->max_mtu, max_frame);
 282
 283	if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
 284		/* bail because we already have a command pending */
 285		dev_err(&adapter->pdev->dev, "Cannot configure queues, command %d pending\n",
 286			adapter->current_op);
 287		return;
 288	}
 289	adapter->current_op = VIRTCHNL_OP_CONFIG_VSI_QUEUES;
 290	len = virtchnl_struct_size(vqci, qpair, pairs);
 291	vqci = kzalloc(len, GFP_KERNEL);
 292	if (!vqci)
 293		return;
 294
 
 
 
 
 
 295	vqci->vsi_id = adapter->vsi_res->vsi_id;
 296	vqci->num_queue_pairs = pairs;
 297	vqpi = vqci->qpair;
 298	/* Size check is not needed here - HW max is 16 queue pairs, and we
 299	 * can fit info for 31 of them into the AQ buffer before it overflows.
 300	 */
 301	for (i = 0; i < pairs; i++) {
 302		vqpi->txq.vsi_id = vqci->vsi_id;
 303		vqpi->txq.queue_id = i;
 304		vqpi->txq.ring_len = adapter->tx_rings[i].count;
 305		vqpi->txq.dma_ring_addr = adapter->tx_rings[i].dma;
 306		vqpi->rxq.vsi_id = vqci->vsi_id;
 307		vqpi->rxq.queue_id = i;
 308		vqpi->rxq.ring_len = adapter->rx_rings[i].count;
 309		vqpi->rxq.dma_ring_addr = adapter->rx_rings[i].dma;
 310		vqpi->rxq.max_pkt_size = max_frame;
 311		vqpi->rxq.databuffer_size = adapter->rx_rings[i].rx_buf_len;
 312		if (CRC_OFFLOAD_ALLOWED(adapter))
 313			vqpi->rxq.crc_disable = !!(adapter->netdev->features &
 314						   NETIF_F_RXFCS);
 315		vqpi++;
 316	}
 317
 318	adapter->aq_required &= ~IAVF_FLAG_AQ_CONFIGURE_QUEUES;
 319	iavf_send_pf_msg(adapter, VIRTCHNL_OP_CONFIG_VSI_QUEUES,
 320			 (u8 *)vqci, len);
 321	kfree(vqci);
 322}
 323
 324/**
 325 * iavf_enable_queues
 326 * @adapter: adapter structure
 327 *
 328 * Request that the PF enable all of our queues.
 329 **/
 330void iavf_enable_queues(struct iavf_adapter *adapter)
 331{
 332	struct virtchnl_queue_select vqs;
 333
 334	if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
 335		/* bail because we already have a command pending */
 336		dev_err(&adapter->pdev->dev, "Cannot enable queues, command %d pending\n",
 337			adapter->current_op);
 338		return;
 339	}
 340	adapter->current_op = VIRTCHNL_OP_ENABLE_QUEUES;
 341	vqs.vsi_id = adapter->vsi_res->vsi_id;
 342	vqs.tx_queues = BIT(adapter->num_active_queues) - 1;
 343	vqs.rx_queues = vqs.tx_queues;
 344	adapter->aq_required &= ~IAVF_FLAG_AQ_ENABLE_QUEUES;
 345	iavf_send_pf_msg(adapter, VIRTCHNL_OP_ENABLE_QUEUES,
 346			 (u8 *)&vqs, sizeof(vqs));
 347}
 348
 349/**
 350 * iavf_disable_queues
 351 * @adapter: adapter structure
 352 *
 353 * Request that the PF disable all of our queues.
 354 **/
 355void iavf_disable_queues(struct iavf_adapter *adapter)
 356{
 357	struct virtchnl_queue_select vqs;
 358
 359	if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
 360		/* bail because we already have a command pending */
 361		dev_err(&adapter->pdev->dev, "Cannot disable queues, command %d pending\n",
 362			adapter->current_op);
 363		return;
 364	}
 365	adapter->current_op = VIRTCHNL_OP_DISABLE_QUEUES;
 366	vqs.vsi_id = adapter->vsi_res->vsi_id;
 367	vqs.tx_queues = BIT(adapter->num_active_queues) - 1;
 368	vqs.rx_queues = vqs.tx_queues;
 369	adapter->aq_required &= ~IAVF_FLAG_AQ_DISABLE_QUEUES;
 370	iavf_send_pf_msg(adapter, VIRTCHNL_OP_DISABLE_QUEUES,
 371			 (u8 *)&vqs, sizeof(vqs));
 372}
 373
 374/**
 375 * iavf_map_queues
 376 * @adapter: adapter structure
 377 *
 378 * Request that the PF map queues to interrupt vectors. Misc causes, including
 379 * admin queue, are always mapped to vector 0.
 380 **/
 381void iavf_map_queues(struct iavf_adapter *adapter)
 382{
 383	struct virtchnl_irq_map_info *vimi;
 384	struct virtchnl_vector_map *vecmap;
 385	struct iavf_q_vector *q_vector;
 386	int v_idx, q_vectors;
 387	size_t len;
 388
 389	if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
 390		/* bail because we already have a command pending */
 391		dev_err(&adapter->pdev->dev, "Cannot map queues to vectors, command %d pending\n",
 392			adapter->current_op);
 393		return;
 394	}
 395	adapter->current_op = VIRTCHNL_OP_CONFIG_IRQ_MAP;
 396
 397	q_vectors = adapter->num_msix_vectors - NONQ_VECS;
 398
 399	len = virtchnl_struct_size(vimi, vecmap, adapter->num_msix_vectors);
 400	vimi = kzalloc(len, GFP_KERNEL);
 401	if (!vimi)
 402		return;
 403
 404	vimi->num_vectors = adapter->num_msix_vectors;
 405	/* Queue vectors first */
 406	for (v_idx = 0; v_idx < q_vectors; v_idx++) {
 407		q_vector = &adapter->q_vectors[v_idx];
 408		vecmap = &vimi->vecmap[v_idx];
 409
 410		vecmap->vsi_id = adapter->vsi_res->vsi_id;
 411		vecmap->vector_id = v_idx + NONQ_VECS;
 412		vecmap->txq_map = q_vector->ring_mask;
 413		vecmap->rxq_map = q_vector->ring_mask;
 414		vecmap->rxitr_idx = IAVF_RX_ITR;
 415		vecmap->txitr_idx = IAVF_TX_ITR;
 416	}
 417	/* Misc vector last - this is only for AdminQ messages */
 418	vecmap = &vimi->vecmap[v_idx];
 419	vecmap->vsi_id = adapter->vsi_res->vsi_id;
 420	vecmap->vector_id = 0;
 421	vecmap->txq_map = 0;
 422	vecmap->rxq_map = 0;
 423
 424	adapter->aq_required &= ~IAVF_FLAG_AQ_MAP_VECTORS;
 425	iavf_send_pf_msg(adapter, VIRTCHNL_OP_CONFIG_IRQ_MAP,
 426			 (u8 *)vimi, len);
 427	kfree(vimi);
 428}
 429
 430/**
 431 * iavf_set_mac_addr_type - Set the correct request type from the filter type
 432 * @virtchnl_ether_addr: pointer to requested list element
 433 * @filter: pointer to requested filter
 434 **/
 435static void
 436iavf_set_mac_addr_type(struct virtchnl_ether_addr *virtchnl_ether_addr,
 437		       const struct iavf_mac_filter *filter)
 438{
 439	virtchnl_ether_addr->type = filter->is_primary ?
 440		VIRTCHNL_ETHER_ADDR_PRIMARY :
 441		VIRTCHNL_ETHER_ADDR_EXTRA;
 442}
 443
 444/**
 445 * iavf_add_ether_addrs
 446 * @adapter: adapter structure
 447 *
 448 * Request that the PF add one or more addresses to our filters.
 449 **/
 450void iavf_add_ether_addrs(struct iavf_adapter *adapter)
 451{
 452	struct virtchnl_ether_addr_list *veal;
 453	struct iavf_mac_filter *f;
 454	int i = 0, count = 0;
 455	bool more = false;
 456	size_t len;
 457
 458	if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
 459		/* bail because we already have a command pending */
 460		dev_err(&adapter->pdev->dev, "Cannot add filters, command %d pending\n",
 461			adapter->current_op);
 462		return;
 463	}
 464
 465	spin_lock_bh(&adapter->mac_vlan_list_lock);
 466
 467	list_for_each_entry(f, &adapter->mac_filter_list, list) {
 468		if (f->add)
 469			count++;
 470	}
 471	if (!count) {
 472		adapter->aq_required &= ~IAVF_FLAG_AQ_ADD_MAC_FILTER;
 473		spin_unlock_bh(&adapter->mac_vlan_list_lock);
 474		return;
 475	}
 476	adapter->current_op = VIRTCHNL_OP_ADD_ETH_ADDR;
 477
 478	len = virtchnl_struct_size(veal, list, count);
 479	if (len > IAVF_MAX_AQ_BUF_SIZE) {
 480		dev_warn(&adapter->pdev->dev, "Too many add MAC changes in one request\n");
 481		while (len > IAVF_MAX_AQ_BUF_SIZE)
 482			len = virtchnl_struct_size(veal, list, --count);
 
 
 483		more = true;
 484	}
 485
 486	veal = kzalloc(len, GFP_ATOMIC);
 487	if (!veal) {
 488		spin_unlock_bh(&adapter->mac_vlan_list_lock);
 489		return;
 490	}
 491
 492	veal->vsi_id = adapter->vsi_res->vsi_id;
 493	veal->num_elements = count;
 494	list_for_each_entry(f, &adapter->mac_filter_list, list) {
 495		if (f->add) {
 496			ether_addr_copy(veal->list[i].addr, f->macaddr);
 497			iavf_set_mac_addr_type(&veal->list[i], f);
 498			i++;
 499			f->add = false;
 500			if (i == count)
 501				break;
 502		}
 503	}
 504	if (!more)
 505		adapter->aq_required &= ~IAVF_FLAG_AQ_ADD_MAC_FILTER;
 506
 507	spin_unlock_bh(&adapter->mac_vlan_list_lock);
 508
 509	iavf_send_pf_msg(adapter, VIRTCHNL_OP_ADD_ETH_ADDR, (u8 *)veal, len);
 510	kfree(veal);
 511}
 512
 513/**
 514 * iavf_del_ether_addrs
 515 * @adapter: adapter structure
 516 *
 517 * Request that the PF remove one or more addresses from our filters.
 518 **/
 519void iavf_del_ether_addrs(struct iavf_adapter *adapter)
 520{
 521	struct virtchnl_ether_addr_list *veal;
 522	struct iavf_mac_filter *f, *ftmp;
 523	int i = 0, count = 0;
 524	bool more = false;
 525	size_t len;
 526
 527	if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
 528		/* bail because we already have a command pending */
 529		dev_err(&adapter->pdev->dev, "Cannot remove filters, command %d pending\n",
 530			adapter->current_op);
 531		return;
 532	}
 533
 534	spin_lock_bh(&adapter->mac_vlan_list_lock);
 535
 536	list_for_each_entry(f, &adapter->mac_filter_list, list) {
 537		if (f->remove)
 538			count++;
 539	}
 540	if (!count) {
 541		adapter->aq_required &= ~IAVF_FLAG_AQ_DEL_MAC_FILTER;
 542		spin_unlock_bh(&adapter->mac_vlan_list_lock);
 543		return;
 544	}
 545	adapter->current_op = VIRTCHNL_OP_DEL_ETH_ADDR;
 546
 547	len = virtchnl_struct_size(veal, list, count);
 548	if (len > IAVF_MAX_AQ_BUF_SIZE) {
 549		dev_warn(&adapter->pdev->dev, "Too many delete MAC changes in one request\n");
 550		while (len > IAVF_MAX_AQ_BUF_SIZE)
 551			len = virtchnl_struct_size(veal, list, --count);
 
 
 552		more = true;
 553	}
 554	veal = kzalloc(len, GFP_ATOMIC);
 555	if (!veal) {
 556		spin_unlock_bh(&adapter->mac_vlan_list_lock);
 557		return;
 558	}
 559
 560	veal->vsi_id = adapter->vsi_res->vsi_id;
 561	veal->num_elements = count;
 562	list_for_each_entry_safe(f, ftmp, &adapter->mac_filter_list, list) {
 563		if (f->remove) {
 564			ether_addr_copy(veal->list[i].addr, f->macaddr);
 565			iavf_set_mac_addr_type(&veal->list[i], f);
 566			i++;
 567			list_del(&f->list);
 568			kfree(f);
 569			if (i == count)
 570				break;
 571		}
 572	}
 573	if (!more)
 574		adapter->aq_required &= ~IAVF_FLAG_AQ_DEL_MAC_FILTER;
 575
 576	spin_unlock_bh(&adapter->mac_vlan_list_lock);
 577
 578	iavf_send_pf_msg(adapter, VIRTCHNL_OP_DEL_ETH_ADDR, (u8 *)veal, len);
 579	kfree(veal);
 580}
 581
 582/**
 583 * iavf_mac_add_ok
 584 * @adapter: adapter structure
 585 *
 586 * Submit list of filters based on PF response.
 587 **/
 588static void iavf_mac_add_ok(struct iavf_adapter *adapter)
 589{
 590	struct iavf_mac_filter *f, *ftmp;
 591
 592	spin_lock_bh(&adapter->mac_vlan_list_lock);
 593	list_for_each_entry_safe(f, ftmp, &adapter->mac_filter_list, list) {
 594		f->is_new_mac = false;
 595		if (!f->add && !f->add_handled)
 596			f->add_handled = true;
 597	}
 598	spin_unlock_bh(&adapter->mac_vlan_list_lock);
 599}
 600
 601/**
 602 * iavf_mac_add_reject
 603 * @adapter: adapter structure
 604 *
 605 * Remove filters from list based on PF response.
 606 **/
 607static void iavf_mac_add_reject(struct iavf_adapter *adapter)
 608{
 609	struct net_device *netdev = adapter->netdev;
 610	struct iavf_mac_filter *f, *ftmp;
 611
 612	spin_lock_bh(&adapter->mac_vlan_list_lock);
 613	list_for_each_entry_safe(f, ftmp, &adapter->mac_filter_list, list) {
 614		if (f->remove && ether_addr_equal(f->macaddr, netdev->dev_addr))
 615			f->remove = false;
 616
 617		if (!f->add && !f->add_handled)
 618			f->add_handled = true;
 619
 620		if (f->is_new_mac) {
 621			list_del(&f->list);
 622			kfree(f);
 623		}
 624	}
 625	spin_unlock_bh(&adapter->mac_vlan_list_lock);
 626}
 627
 628/**
 629 * iavf_vlan_add_reject
 630 * @adapter: adapter structure
 631 *
 632 * Remove VLAN filters from list based on PF response.
 633 **/
 634static void iavf_vlan_add_reject(struct iavf_adapter *adapter)
 635{
 636	struct iavf_vlan_filter *f, *ftmp;
 637
 638	spin_lock_bh(&adapter->mac_vlan_list_lock);
 639	list_for_each_entry_safe(f, ftmp, &adapter->vlan_filter_list, list) {
 640		if (f->state == IAVF_VLAN_IS_NEW) {
 641			list_del(&f->list);
 642			kfree(f);
 643			adapter->num_vlan_filters--;
 644		}
 645	}
 646	spin_unlock_bh(&adapter->mac_vlan_list_lock);
 647}
 648
 649/**
 650 * iavf_add_vlans
 651 * @adapter: adapter structure
 652 *
 653 * Request that the PF add one or more VLAN filters to our VSI.
 654 **/
 655void iavf_add_vlans(struct iavf_adapter *adapter)
 656{
 
 657	int len, i = 0, count = 0;
 658	struct iavf_vlan_filter *f;
 659	bool more = false;
 660
 661	if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
 662		/* bail because we already have a command pending */
 663		dev_err(&adapter->pdev->dev, "Cannot add VLANs, command %d pending\n",
 664			adapter->current_op);
 665		return;
 666	}
 667
 668	spin_lock_bh(&adapter->mac_vlan_list_lock);
 669
 670	list_for_each_entry(f, &adapter->vlan_filter_list, list) {
 671		if (f->state == IAVF_VLAN_ADD)
 672			count++;
 673	}
 674	if (!count || !VLAN_FILTERING_ALLOWED(adapter)) {
 675		adapter->aq_required &= ~IAVF_FLAG_AQ_ADD_VLAN_FILTER;
 676		spin_unlock_bh(&adapter->mac_vlan_list_lock);
 677		return;
 678	}
 
 679
 680	if (VLAN_ALLOWED(adapter)) {
 681		struct virtchnl_vlan_filter_list *vvfl;
 682
 683		adapter->current_op = VIRTCHNL_OP_ADD_VLAN;
 684
 685		len = virtchnl_struct_size(vvfl, vlan_id, count);
 686		if (len > IAVF_MAX_AQ_BUF_SIZE) {
 687			dev_warn(&adapter->pdev->dev, "Too many add VLAN changes in one request\n");
 688			while (len > IAVF_MAX_AQ_BUF_SIZE)
 689				len = virtchnl_struct_size(vvfl, vlan_id,
 690							   --count);
 691			more = true;
 692		}
 693		vvfl = kzalloc(len, GFP_ATOMIC);
 694		if (!vvfl) {
 695			spin_unlock_bh(&adapter->mac_vlan_list_lock);
 696			return;
 697		}
 698
 699		vvfl->vsi_id = adapter->vsi_res->vsi_id;
 700		vvfl->num_elements = count;
 701		list_for_each_entry(f, &adapter->vlan_filter_list, list) {
 702			if (f->state == IAVF_VLAN_ADD) {
 703				vvfl->vlan_id[i] = f->vlan.vid;
 704				i++;
 705				f->state = IAVF_VLAN_IS_NEW;
 706				if (i == count)
 707					break;
 708			}
 709		}
 710		if (!more)
 711			adapter->aq_required &= ~IAVF_FLAG_AQ_ADD_VLAN_FILTER;
 712
 713		spin_unlock_bh(&adapter->mac_vlan_list_lock);
 
 
 714
 715		iavf_send_pf_msg(adapter, VIRTCHNL_OP_ADD_VLAN, (u8 *)vvfl, len);
 716		kfree(vvfl);
 717	} else {
 718		u16 max_vlans = adapter->vlan_v2_caps.filtering.max_filters;
 719		u16 current_vlans = iavf_get_num_vlans_added(adapter);
 720		struct virtchnl_vlan_filter_list_v2 *vvfl_v2;
 721
 722		adapter->current_op = VIRTCHNL_OP_ADD_VLAN_V2;
 723
 724		if ((count + current_vlans) > max_vlans &&
 725		    current_vlans < max_vlans) {
 726			count = max_vlans - iavf_get_num_vlans_added(adapter);
 727			more = true;
 728		}
 729
 730		len = virtchnl_struct_size(vvfl_v2, filters, count);
 731		if (len > IAVF_MAX_AQ_BUF_SIZE) {
 732			dev_warn(&adapter->pdev->dev, "Too many add VLAN changes in one request\n");
 733			while (len > IAVF_MAX_AQ_BUF_SIZE)
 734				len = virtchnl_struct_size(vvfl_v2, filters,
 735							   --count);
 736			more = true;
 737		}
 738
 739		vvfl_v2 = kzalloc(len, GFP_ATOMIC);
 740		if (!vvfl_v2) {
 741			spin_unlock_bh(&adapter->mac_vlan_list_lock);
 742			return;
 743		}
 744
 745		vvfl_v2->vport_id = adapter->vsi_res->vsi_id;
 746		vvfl_v2->num_elements = count;
 747		list_for_each_entry(f, &adapter->vlan_filter_list, list) {
 748			if (f->state == IAVF_VLAN_ADD) {
 749				struct virtchnl_vlan_supported_caps *filtering_support =
 750					&adapter->vlan_v2_caps.filtering.filtering_support;
 751				struct virtchnl_vlan *vlan;
 752
 753				if (i == count)
 754					break;
 755
 756				/* give priority over outer if it's enabled */
 757				if (filtering_support->outer)
 758					vlan = &vvfl_v2->filters[i].outer;
 759				else
 760					vlan = &vvfl_v2->filters[i].inner;
 761
 762				vlan->tci = f->vlan.vid;
 763				vlan->tpid = f->vlan.tpid;
 764
 765				i++;
 766				f->state = IAVF_VLAN_IS_NEW;
 767			}
 768		}
 
 
 
 769
 770		if (!more)
 771			adapter->aq_required &= ~IAVF_FLAG_AQ_ADD_VLAN_FILTER;
 772
 773		spin_unlock_bh(&adapter->mac_vlan_list_lock);
 774
 775		iavf_send_pf_msg(adapter, VIRTCHNL_OP_ADD_VLAN_V2,
 776				 (u8 *)vvfl_v2, len);
 777		kfree(vvfl_v2);
 778	}
 779}
 780
 781/**
 782 * iavf_del_vlans
 783 * @adapter: adapter structure
 784 *
 785 * Request that the PF remove one or more VLAN filters from our VSI.
 786 **/
 787void iavf_del_vlans(struct iavf_adapter *adapter)
 788{
 
 789	struct iavf_vlan_filter *f, *ftmp;
 790	int len, i = 0, count = 0;
 791	bool more = false;
 792
 793	if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
 794		/* bail because we already have a command pending */
 795		dev_err(&adapter->pdev->dev, "Cannot remove VLANs, command %d pending\n",
 796			adapter->current_op);
 797		return;
 798	}
 799
 800	spin_lock_bh(&adapter->mac_vlan_list_lock);
 801
 802	list_for_each_entry_safe(f, ftmp, &adapter->vlan_filter_list, list) {
 803		/* since VLAN capabilities are not allowed, we dont want to send
 804		 * a VLAN delete request because it will most likely fail and
 805		 * create unnecessary errors/noise, so just free the VLAN
 806		 * filters marked for removal to enable bailing out before
 807		 * sending a virtchnl message
 808		 */
 809		if (f->state == IAVF_VLAN_REMOVE &&
 810		    !VLAN_FILTERING_ALLOWED(adapter)) {
 811			list_del(&f->list);
 812			kfree(f);
 813			adapter->num_vlan_filters--;
 814		} else if (f->state == IAVF_VLAN_DISABLE &&
 815		    !VLAN_FILTERING_ALLOWED(adapter)) {
 816			f->state = IAVF_VLAN_INACTIVE;
 817		} else if (f->state == IAVF_VLAN_REMOVE ||
 818			   f->state == IAVF_VLAN_DISABLE) {
 819			count++;
 820		}
 821	}
 822	if (!count || !VLAN_FILTERING_ALLOWED(adapter)) {
 823		adapter->aq_required &= ~IAVF_FLAG_AQ_DEL_VLAN_FILTER;
 824		spin_unlock_bh(&adapter->mac_vlan_list_lock);
 825		return;
 826	}
 
 827
 828	if (VLAN_ALLOWED(adapter)) {
 829		struct virtchnl_vlan_filter_list *vvfl;
 830
 831		adapter->current_op = VIRTCHNL_OP_DEL_VLAN;
 832
 833		len = virtchnl_struct_size(vvfl, vlan_id, count);
 834		if (len > IAVF_MAX_AQ_BUF_SIZE) {
 835			dev_warn(&adapter->pdev->dev, "Too many delete VLAN changes in one request\n");
 836			while (len > IAVF_MAX_AQ_BUF_SIZE)
 837				len = virtchnl_struct_size(vvfl, vlan_id,
 838							   --count);
 839			more = true;
 840		}
 841		vvfl = kzalloc(len, GFP_ATOMIC);
 842		if (!vvfl) {
 843			spin_unlock_bh(&adapter->mac_vlan_list_lock);
 844			return;
 845		}
 846
 847		vvfl->vsi_id = adapter->vsi_res->vsi_id;
 848		vvfl->num_elements = count;
 849		list_for_each_entry_safe(f, ftmp, &adapter->vlan_filter_list, list) {
 850			if (f->state == IAVF_VLAN_DISABLE) {
 851				vvfl->vlan_id[i] = f->vlan.vid;
 852				f->state = IAVF_VLAN_INACTIVE;
 853				i++;
 854				if (i == count)
 855					break;
 856			} else if (f->state == IAVF_VLAN_REMOVE) {
 857				vvfl->vlan_id[i] = f->vlan.vid;
 858				list_del(&f->list);
 859				kfree(f);
 860				adapter->num_vlan_filters--;
 861				i++;
 862				if (i == count)
 863					break;
 864			}
 865		}
 866
 867		if (!more)
 868			adapter->aq_required &= ~IAVF_FLAG_AQ_DEL_VLAN_FILTER;
 869
 870		spin_unlock_bh(&adapter->mac_vlan_list_lock);
 
 
 871
 872		iavf_send_pf_msg(adapter, VIRTCHNL_OP_DEL_VLAN, (u8 *)vvfl, len);
 873		kfree(vvfl);
 874	} else {
 875		struct virtchnl_vlan_filter_list_v2 *vvfl_v2;
 876
 877		adapter->current_op = VIRTCHNL_OP_DEL_VLAN_V2;
 878
 879		len = virtchnl_struct_size(vvfl_v2, filters, count);
 880		if (len > IAVF_MAX_AQ_BUF_SIZE) {
 881			dev_warn(&adapter->pdev->dev, "Too many add VLAN changes in one request\n");
 882			while (len > IAVF_MAX_AQ_BUF_SIZE)
 883				len = virtchnl_struct_size(vvfl_v2, filters,
 884							   --count);
 885			more = true;
 886		}
 887
 888		vvfl_v2 = kzalloc(len, GFP_ATOMIC);
 889		if (!vvfl_v2) {
 890			spin_unlock_bh(&adapter->mac_vlan_list_lock);
 891			return;
 892		}
 893
 894		vvfl_v2->vport_id = adapter->vsi_res->vsi_id;
 895		vvfl_v2->num_elements = count;
 896		list_for_each_entry_safe(f, ftmp, &adapter->vlan_filter_list, list) {
 897			if (f->state == IAVF_VLAN_DISABLE ||
 898			    f->state == IAVF_VLAN_REMOVE) {
 899				struct virtchnl_vlan_supported_caps *filtering_support =
 900					&adapter->vlan_v2_caps.filtering.filtering_support;
 901				struct virtchnl_vlan *vlan;
 902
 903				/* give priority over outer if it's enabled */
 904				if (filtering_support->outer)
 905					vlan = &vvfl_v2->filters[i].outer;
 906				else
 907					vlan = &vvfl_v2->filters[i].inner;
 908
 909				vlan->tci = f->vlan.vid;
 910				vlan->tpid = f->vlan.tpid;
 911
 912				if (f->state == IAVF_VLAN_DISABLE) {
 913					f->state = IAVF_VLAN_INACTIVE;
 914				} else {
 915					list_del(&f->list);
 916					kfree(f);
 917					adapter->num_vlan_filters--;
 918				}
 919				i++;
 920				if (i == count)
 921					break;
 922			}
 923		}
 
 
 
 924
 925		if (!more)
 926			adapter->aq_required &= ~IAVF_FLAG_AQ_DEL_VLAN_FILTER;
 927
 928		spin_unlock_bh(&adapter->mac_vlan_list_lock);
 929
 930		iavf_send_pf_msg(adapter, VIRTCHNL_OP_DEL_VLAN_V2,
 931				 (u8 *)vvfl_v2, len);
 932		kfree(vvfl_v2);
 933	}
 934}
 935
 936/**
 937 * iavf_set_promiscuous
 938 * @adapter: adapter structure
 
 939 *
 940 * Request that the PF enable promiscuous mode for our VSI.
 941 **/
 942void iavf_set_promiscuous(struct iavf_adapter *adapter)
 943{
 944	struct net_device *netdev = adapter->netdev;
 945	struct virtchnl_promisc_info vpi;
 946	unsigned int flags;
 947
 948	if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
 949		/* bail because we already have a command pending */
 950		dev_err(&adapter->pdev->dev, "Cannot set promiscuous mode, command %d pending\n",
 951			adapter->current_op);
 952		return;
 953	}
 954
 955	/* prevent changes to promiscuous flags */
 956	spin_lock_bh(&adapter->current_netdev_promisc_flags_lock);
 957
 958	/* sanity check to prevent duplicate AQ calls */
 959	if (!iavf_promiscuous_mode_changed(adapter)) {
 960		adapter->aq_required &= ~IAVF_FLAG_AQ_CONFIGURE_PROMISC_MODE;
 961		dev_dbg(&adapter->pdev->dev, "No change in promiscuous mode\n");
 962		/* allow changes to promiscuous flags */
 963		spin_unlock_bh(&adapter->current_netdev_promisc_flags_lock);
 964		return;
 965	}
 966
 967	/* there are 2 bits, but only 3 states */
 968	if (!(netdev->flags & IFF_PROMISC) &&
 969	    netdev->flags & IFF_ALLMULTI) {
 970		/* State 1  - only multicast promiscuous mode enabled
 971		 * - !IFF_PROMISC && IFF_ALLMULTI
 972		 */
 973		flags = FLAG_VF_MULTICAST_PROMISC;
 974		adapter->current_netdev_promisc_flags |= IFF_ALLMULTI;
 975		adapter->current_netdev_promisc_flags &= ~IFF_PROMISC;
 976		dev_info(&adapter->pdev->dev, "Entering multicast promiscuous mode\n");
 977	} else if (!(netdev->flags & IFF_PROMISC) &&
 978		   !(netdev->flags & IFF_ALLMULTI)) {
 979		/* State 2 - unicast/multicast promiscuous mode disabled
 980		 * - !IFF_PROMISC && !IFF_ALLMULTI
 981		 */
 982		flags = 0;
 983		adapter->current_netdev_promisc_flags &=
 984			~(IFF_PROMISC | IFF_ALLMULTI);
 985		dev_info(&adapter->pdev->dev, "Leaving promiscuous mode\n");
 986	} else {
 987		/* State 3 - unicast/multicast promiscuous mode enabled
 988		 * - IFF_PROMISC && IFF_ALLMULTI
 989		 * - IFF_PROMISC && !IFF_ALLMULTI
 990		 */
 991		flags = FLAG_VF_UNICAST_PROMISC | FLAG_VF_MULTICAST_PROMISC;
 992		adapter->current_netdev_promisc_flags |= IFF_PROMISC;
 993		if (netdev->flags & IFF_ALLMULTI)
 994			adapter->current_netdev_promisc_flags |= IFF_ALLMULTI;
 995		else
 996			adapter->current_netdev_promisc_flags &= ~IFF_ALLMULTI;
 997
 998		dev_info(&adapter->pdev->dev, "Entering promiscuous mode\n");
 999	}
1000
1001	adapter->aq_required &= ~IAVF_FLAG_AQ_CONFIGURE_PROMISC_MODE;
1002
1003	/* allow changes to promiscuous flags */
1004	spin_unlock_bh(&adapter->current_netdev_promisc_flags_lock);
 
 
 
1005
1006	adapter->current_op = VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE;
1007	vpi.vsi_id = adapter->vsi_res->vsi_id;
1008	vpi.flags = flags;
1009	iavf_send_pf_msg(adapter, VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE,
1010			 (u8 *)&vpi, sizeof(vpi));
1011}
1012
1013/**
1014 * iavf_request_stats
1015 * @adapter: adapter structure
1016 *
1017 * Request VSI statistics from PF.
1018 **/
1019void iavf_request_stats(struct iavf_adapter *adapter)
1020{
1021	struct virtchnl_queue_select vqs;
1022
1023	if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
1024		/* no error message, this isn't crucial */
1025		return;
1026	}
1027
1028	adapter->aq_required &= ~IAVF_FLAG_AQ_REQUEST_STATS;
1029	adapter->current_op = VIRTCHNL_OP_GET_STATS;
1030	vqs.vsi_id = adapter->vsi_res->vsi_id;
1031	/* queue maps are ignored for this message - only the vsi is used */
1032	if (iavf_send_pf_msg(adapter, VIRTCHNL_OP_GET_STATS, (u8 *)&vqs,
1033			     sizeof(vqs)))
1034		/* if the request failed, don't lock out others */
1035		adapter->current_op = VIRTCHNL_OP_UNKNOWN;
1036}
1037
1038/**
1039 * iavf_get_hena
1040 * @adapter: adapter structure
1041 *
1042 * Request hash enable capabilities from PF
1043 **/
1044void iavf_get_hena(struct iavf_adapter *adapter)
1045{
1046	if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
1047		/* bail because we already have a command pending */
1048		dev_err(&adapter->pdev->dev, "Cannot get RSS hash capabilities, command %d pending\n",
1049			adapter->current_op);
1050		return;
1051	}
1052	adapter->current_op = VIRTCHNL_OP_GET_RSS_HENA_CAPS;
1053	adapter->aq_required &= ~IAVF_FLAG_AQ_GET_HENA;
1054	iavf_send_pf_msg(adapter, VIRTCHNL_OP_GET_RSS_HENA_CAPS, NULL, 0);
1055}
1056
1057/**
1058 * iavf_set_hena
1059 * @adapter: adapter structure
1060 *
1061 * Request the PF to set our RSS hash capabilities
1062 **/
1063void iavf_set_hena(struct iavf_adapter *adapter)
1064{
1065	struct virtchnl_rss_hena vrh;
1066
1067	if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
1068		/* bail because we already have a command pending */
1069		dev_err(&adapter->pdev->dev, "Cannot set RSS hash enable, command %d pending\n",
1070			adapter->current_op);
1071		return;
1072	}
1073	vrh.hena = adapter->hena;
1074	adapter->current_op = VIRTCHNL_OP_SET_RSS_HENA;
1075	adapter->aq_required &= ~IAVF_FLAG_AQ_SET_HENA;
1076	iavf_send_pf_msg(adapter, VIRTCHNL_OP_SET_RSS_HENA, (u8 *)&vrh,
1077			 sizeof(vrh));
1078}
1079
1080/**
1081 * iavf_set_rss_key
1082 * @adapter: adapter structure
1083 *
1084 * Request the PF to set our RSS hash key
1085 **/
1086void iavf_set_rss_key(struct iavf_adapter *adapter)
1087{
1088	struct virtchnl_rss_key *vrk;
1089	int len;
1090
1091	if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
1092		/* bail because we already have a command pending */
1093		dev_err(&adapter->pdev->dev, "Cannot set RSS key, command %d pending\n",
1094			adapter->current_op);
1095		return;
1096	}
1097	len = virtchnl_struct_size(vrk, key, adapter->rss_key_size);
 
1098	vrk = kzalloc(len, GFP_KERNEL);
1099	if (!vrk)
1100		return;
1101	vrk->vsi_id = adapter->vsi.id;
1102	vrk->key_len = adapter->rss_key_size;
1103	memcpy(vrk->key, adapter->rss_key, adapter->rss_key_size);
1104
1105	adapter->current_op = VIRTCHNL_OP_CONFIG_RSS_KEY;
1106	adapter->aq_required &= ~IAVF_FLAG_AQ_SET_RSS_KEY;
1107	iavf_send_pf_msg(adapter, VIRTCHNL_OP_CONFIG_RSS_KEY, (u8 *)vrk, len);
1108	kfree(vrk);
1109}
1110
1111/**
1112 * iavf_set_rss_lut
1113 * @adapter: adapter structure
1114 *
1115 * Request the PF to set our RSS lookup table
1116 **/
1117void iavf_set_rss_lut(struct iavf_adapter *adapter)
1118{
1119	struct virtchnl_rss_lut *vrl;
1120	int len;
1121
1122	if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
1123		/* bail because we already have a command pending */
1124		dev_err(&adapter->pdev->dev, "Cannot set RSS LUT, command %d pending\n",
1125			adapter->current_op);
1126		return;
1127	}
1128	len = virtchnl_struct_size(vrl, lut, adapter->rss_lut_size);
 
1129	vrl = kzalloc(len, GFP_KERNEL);
1130	if (!vrl)
1131		return;
1132	vrl->vsi_id = adapter->vsi.id;
1133	vrl->lut_entries = adapter->rss_lut_size;
1134	memcpy(vrl->lut, adapter->rss_lut, adapter->rss_lut_size);
1135	adapter->current_op = VIRTCHNL_OP_CONFIG_RSS_LUT;
1136	adapter->aq_required &= ~IAVF_FLAG_AQ_SET_RSS_LUT;
1137	iavf_send_pf_msg(adapter, VIRTCHNL_OP_CONFIG_RSS_LUT, (u8 *)vrl, len);
1138	kfree(vrl);
1139}
1140
1141/**
1142 * iavf_set_rss_hfunc
1143 * @adapter: adapter structure
1144 *
1145 * Request the PF to set our RSS Hash function
1146 **/
1147void iavf_set_rss_hfunc(struct iavf_adapter *adapter)
1148{
1149	struct virtchnl_rss_hfunc *vrh;
1150	int len = sizeof(*vrh);
1151
1152	if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
1153		/* bail because we already have a command pending */
1154		dev_err(&adapter->pdev->dev, "Cannot set RSS Hash function, command %d pending\n",
1155			adapter->current_op);
1156		return;
1157	}
1158	vrh = kzalloc(len, GFP_KERNEL);
1159	if (!vrh)
1160		return;
1161	vrh->vsi_id = adapter->vsi.id;
1162	vrh->rss_algorithm = adapter->hfunc;
1163	adapter->current_op = VIRTCHNL_OP_CONFIG_RSS_HFUNC;
1164	adapter->aq_required &= ~IAVF_FLAG_AQ_SET_RSS_HFUNC;
1165	iavf_send_pf_msg(adapter, VIRTCHNL_OP_CONFIG_RSS_HFUNC, (u8 *)vrh, len);
1166	kfree(vrh);
1167}
1168
1169/**
1170 * iavf_enable_vlan_stripping
1171 * @adapter: adapter structure
1172 *
1173 * Request VLAN header stripping to be enabled
1174 **/
1175void iavf_enable_vlan_stripping(struct iavf_adapter *adapter)
1176{
1177	if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
1178		/* bail because we already have a command pending */
1179		dev_err(&adapter->pdev->dev, "Cannot enable stripping, command %d pending\n",
1180			adapter->current_op);
1181		return;
1182	}
1183	adapter->current_op = VIRTCHNL_OP_ENABLE_VLAN_STRIPPING;
1184	adapter->aq_required &= ~IAVF_FLAG_AQ_ENABLE_VLAN_STRIPPING;
1185	iavf_send_pf_msg(adapter, VIRTCHNL_OP_ENABLE_VLAN_STRIPPING, NULL, 0);
1186}
1187
1188/**
1189 * iavf_disable_vlan_stripping
1190 * @adapter: adapter structure
1191 *
1192 * Request VLAN header stripping to be disabled
1193 **/
1194void iavf_disable_vlan_stripping(struct iavf_adapter *adapter)
1195{
1196	if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
1197		/* bail because we already have a command pending */
1198		dev_err(&adapter->pdev->dev, "Cannot disable stripping, command %d pending\n",
1199			adapter->current_op);
1200		return;
1201	}
1202	adapter->current_op = VIRTCHNL_OP_DISABLE_VLAN_STRIPPING;
1203	adapter->aq_required &= ~IAVF_FLAG_AQ_DISABLE_VLAN_STRIPPING;
1204	iavf_send_pf_msg(adapter, VIRTCHNL_OP_DISABLE_VLAN_STRIPPING, NULL, 0);
1205}
1206
1207/**
1208 * iavf_tpid_to_vc_ethertype - transform from VLAN TPID to virtchnl ethertype
1209 * @tpid: VLAN TPID (i.e. 0x8100, 0x88a8, etc.)
1210 */
1211static u32 iavf_tpid_to_vc_ethertype(u16 tpid)
1212{
1213	switch (tpid) {
1214	case ETH_P_8021Q:
1215		return VIRTCHNL_VLAN_ETHERTYPE_8100;
1216	case ETH_P_8021AD:
1217		return VIRTCHNL_VLAN_ETHERTYPE_88A8;
1218	}
1219
1220	return 0;
1221}
1222
1223/**
1224 * iavf_set_vc_offload_ethertype - set virtchnl ethertype for offload message
1225 * @adapter: adapter structure
1226 * @msg: message structure used for updating offloads over virtchnl to update
1227 * @tpid: VLAN TPID (i.e. 0x8100, 0x88a8, etc.)
1228 * @offload_op: opcode used to determine which support structure to check
1229 */
1230static int
1231iavf_set_vc_offload_ethertype(struct iavf_adapter *adapter,
1232			      struct virtchnl_vlan_setting *msg, u16 tpid,
1233			      enum virtchnl_ops offload_op)
1234{
1235	struct virtchnl_vlan_supported_caps *offload_support;
1236	u16 vc_ethertype = iavf_tpid_to_vc_ethertype(tpid);
1237
1238	/* reference the correct offload support structure */
1239	switch (offload_op) {
1240	case VIRTCHNL_OP_ENABLE_VLAN_STRIPPING_V2:
1241	case VIRTCHNL_OP_DISABLE_VLAN_STRIPPING_V2:
1242		offload_support =
1243			&adapter->vlan_v2_caps.offloads.stripping_support;
1244		break;
1245	case VIRTCHNL_OP_ENABLE_VLAN_INSERTION_V2:
1246	case VIRTCHNL_OP_DISABLE_VLAN_INSERTION_V2:
1247		offload_support =
1248			&adapter->vlan_v2_caps.offloads.insertion_support;
1249		break;
1250	default:
1251		dev_err(&adapter->pdev->dev, "Invalid opcode %d for setting virtchnl ethertype to enable/disable VLAN offloads\n",
1252			offload_op);
1253		return -EINVAL;
1254	}
1255
1256	/* make sure ethertype is supported */
1257	if (offload_support->outer & vc_ethertype &&
1258	    offload_support->outer & VIRTCHNL_VLAN_TOGGLE) {
1259		msg->outer_ethertype_setting = vc_ethertype;
1260	} else if (offload_support->inner & vc_ethertype &&
1261		   offload_support->inner & VIRTCHNL_VLAN_TOGGLE) {
1262		msg->inner_ethertype_setting = vc_ethertype;
1263	} else {
1264		dev_dbg(&adapter->pdev->dev, "opcode %d unsupported for VLAN TPID 0x%04x\n",
1265			offload_op, tpid);
1266		return -EINVAL;
1267	}
1268
1269	return 0;
1270}
1271
1272/**
1273 * iavf_clear_offload_v2_aq_required - clear AQ required bit for offload request
1274 * @adapter: adapter structure
1275 * @tpid: VLAN TPID
1276 * @offload_op: opcode used to determine which AQ required bit to clear
1277 */
1278static void
1279iavf_clear_offload_v2_aq_required(struct iavf_adapter *adapter, u16 tpid,
1280				  enum virtchnl_ops offload_op)
1281{
1282	switch (offload_op) {
1283	case VIRTCHNL_OP_ENABLE_VLAN_STRIPPING_V2:
1284		if (tpid == ETH_P_8021Q)
1285			adapter->aq_required &=
1286				~IAVF_FLAG_AQ_ENABLE_CTAG_VLAN_STRIPPING;
1287		else if (tpid == ETH_P_8021AD)
1288			adapter->aq_required &=
1289				~IAVF_FLAG_AQ_ENABLE_STAG_VLAN_STRIPPING;
1290		break;
1291	case VIRTCHNL_OP_DISABLE_VLAN_STRIPPING_V2:
1292		if (tpid == ETH_P_8021Q)
1293			adapter->aq_required &=
1294				~IAVF_FLAG_AQ_DISABLE_CTAG_VLAN_STRIPPING;
1295		else if (tpid == ETH_P_8021AD)
1296			adapter->aq_required &=
1297				~IAVF_FLAG_AQ_DISABLE_STAG_VLAN_STRIPPING;
1298		break;
1299	case VIRTCHNL_OP_ENABLE_VLAN_INSERTION_V2:
1300		if (tpid == ETH_P_8021Q)
1301			adapter->aq_required &=
1302				~IAVF_FLAG_AQ_ENABLE_CTAG_VLAN_INSERTION;
1303		else if (tpid == ETH_P_8021AD)
1304			adapter->aq_required &=
1305				~IAVF_FLAG_AQ_ENABLE_STAG_VLAN_INSERTION;
1306		break;
1307	case VIRTCHNL_OP_DISABLE_VLAN_INSERTION_V2:
1308		if (tpid == ETH_P_8021Q)
1309			adapter->aq_required &=
1310				~IAVF_FLAG_AQ_DISABLE_CTAG_VLAN_INSERTION;
1311		else if (tpid == ETH_P_8021AD)
1312			adapter->aq_required &=
1313				~IAVF_FLAG_AQ_DISABLE_STAG_VLAN_INSERTION;
1314		break;
1315	default:
1316		dev_err(&adapter->pdev->dev, "Unsupported opcode %d specified for clearing aq_required bits for VIRTCHNL_VF_OFFLOAD_VLAN_V2 offload request\n",
1317			offload_op);
1318	}
1319}
1320
1321/**
1322 * iavf_send_vlan_offload_v2 - send offload enable/disable over virtchnl
1323 * @adapter: adapter structure
1324 * @tpid: VLAN TPID used for the command (i.e. 0x8100 or 0x88a8)
1325 * @offload_op: offload_op used to make the request over virtchnl
1326 */
1327static void
1328iavf_send_vlan_offload_v2(struct iavf_adapter *adapter, u16 tpid,
1329			  enum virtchnl_ops offload_op)
1330{
1331	struct virtchnl_vlan_setting *msg;
1332	int len = sizeof(*msg);
1333
1334	if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
1335		/* bail because we already have a command pending */
1336		dev_err(&adapter->pdev->dev, "Cannot send %d, command %d pending\n",
1337			offload_op, adapter->current_op);
1338		return;
1339	}
1340
1341	adapter->current_op = offload_op;
1342
1343	msg = kzalloc(len, GFP_KERNEL);
1344	if (!msg)
1345		return;
1346
1347	msg->vport_id = adapter->vsi_res->vsi_id;
1348
1349	/* always clear to prevent unsupported and endless requests */
1350	iavf_clear_offload_v2_aq_required(adapter, tpid, offload_op);
1351
1352	/* only send valid offload requests */
1353	if (!iavf_set_vc_offload_ethertype(adapter, msg, tpid, offload_op))
1354		iavf_send_pf_msg(adapter, offload_op, (u8 *)msg, len);
1355	else
1356		adapter->current_op = VIRTCHNL_OP_UNKNOWN;
1357
1358	kfree(msg);
1359}
1360
1361/**
1362 * iavf_enable_vlan_stripping_v2 - enable VLAN stripping
1363 * @adapter: adapter structure
1364 * @tpid: VLAN TPID used to enable VLAN stripping
1365 */
1366void iavf_enable_vlan_stripping_v2(struct iavf_adapter *adapter, u16 tpid)
1367{
1368	iavf_send_vlan_offload_v2(adapter, tpid,
1369				  VIRTCHNL_OP_ENABLE_VLAN_STRIPPING_V2);
1370}
1371
1372/**
1373 * iavf_disable_vlan_stripping_v2 - disable VLAN stripping
1374 * @adapter: adapter structure
1375 * @tpid: VLAN TPID used to disable VLAN stripping
1376 */
1377void iavf_disable_vlan_stripping_v2(struct iavf_adapter *adapter, u16 tpid)
1378{
1379	iavf_send_vlan_offload_v2(adapter, tpid,
1380				  VIRTCHNL_OP_DISABLE_VLAN_STRIPPING_V2);
1381}
1382
1383/**
1384 * iavf_enable_vlan_insertion_v2 - enable VLAN insertion
1385 * @adapter: adapter structure
1386 * @tpid: VLAN TPID used to enable VLAN insertion
1387 */
1388void iavf_enable_vlan_insertion_v2(struct iavf_adapter *adapter, u16 tpid)
1389{
1390	iavf_send_vlan_offload_v2(adapter, tpid,
1391				  VIRTCHNL_OP_ENABLE_VLAN_INSERTION_V2);
1392}
1393
1394/**
1395 * iavf_disable_vlan_insertion_v2 - disable VLAN insertion
1396 * @adapter: adapter structure
1397 * @tpid: VLAN TPID used to disable VLAN insertion
1398 */
1399void iavf_disable_vlan_insertion_v2(struct iavf_adapter *adapter, u16 tpid)
1400{
1401	iavf_send_vlan_offload_v2(adapter, tpid,
1402				  VIRTCHNL_OP_DISABLE_VLAN_INSERTION_V2);
1403}
1404
1405/**
1406 * iavf_print_link_message - print link up or down
1407 * @adapter: adapter structure
1408 *
1409 * Log a message telling the world of our wonderous link status
1410 */
1411static void iavf_print_link_message(struct iavf_adapter *adapter)
1412{
1413	struct net_device *netdev = adapter->netdev;
1414	int link_speed_mbps;
1415	char *speed;
1416
1417	if (!adapter->link_up) {
1418		netdev_info(netdev, "NIC Link is Down\n");
1419		return;
1420	}
1421
 
 
 
 
1422	if (ADV_LINK_SUPPORT(adapter)) {
1423		link_speed_mbps = adapter->link_speed_mbps;
1424		goto print_link_msg;
1425	}
1426
1427	switch (adapter->link_speed) {
1428	case VIRTCHNL_LINK_SPEED_40GB:
1429		link_speed_mbps = SPEED_40000;
1430		break;
1431	case VIRTCHNL_LINK_SPEED_25GB:
1432		link_speed_mbps = SPEED_25000;
1433		break;
1434	case VIRTCHNL_LINK_SPEED_20GB:
1435		link_speed_mbps = SPEED_20000;
1436		break;
1437	case VIRTCHNL_LINK_SPEED_10GB:
1438		link_speed_mbps = SPEED_10000;
1439		break;
1440	case VIRTCHNL_LINK_SPEED_5GB:
1441		link_speed_mbps = SPEED_5000;
1442		break;
1443	case VIRTCHNL_LINK_SPEED_2_5GB:
1444		link_speed_mbps = SPEED_2500;
1445		break;
1446	case VIRTCHNL_LINK_SPEED_1GB:
1447		link_speed_mbps = SPEED_1000;
1448		break;
1449	case VIRTCHNL_LINK_SPEED_100MB:
1450		link_speed_mbps = SPEED_100;
1451		break;
1452	default:
1453		link_speed_mbps = SPEED_UNKNOWN;
1454		break;
1455	}
1456
1457print_link_msg:
1458	if (link_speed_mbps > SPEED_1000) {
1459		if (link_speed_mbps == SPEED_2500) {
1460			speed = kasprintf(GFP_KERNEL, "%s", "2.5 Gbps");
1461		} else {
1462			/* convert to Gbps inline */
1463			speed = kasprintf(GFP_KERNEL, "%d Gbps",
1464					  link_speed_mbps / 1000);
1465		}
1466	} else if (link_speed_mbps == SPEED_UNKNOWN) {
1467		speed = kasprintf(GFP_KERNEL, "%s", "Unknown Mbps");
1468	} else {
1469		speed = kasprintf(GFP_KERNEL, "%d Mbps", link_speed_mbps);
 
1470	}
1471
1472	netdev_info(netdev, "NIC Link is Up Speed is %s Full Duplex\n", speed);
1473	kfree(speed);
1474}
1475
1476/**
1477 * iavf_get_vpe_link_status
1478 * @adapter: adapter structure
1479 * @vpe: virtchnl_pf_event structure
1480 *
1481 * Helper function for determining the link status
1482 **/
1483static bool
1484iavf_get_vpe_link_status(struct iavf_adapter *adapter,
1485			 struct virtchnl_pf_event *vpe)
1486{
1487	if (ADV_LINK_SUPPORT(adapter))
1488		return vpe->event_data.link_event_adv.link_status;
1489	else
1490		return vpe->event_data.link_event.link_status;
1491}
1492
1493/**
1494 * iavf_set_adapter_link_speed_from_vpe
1495 * @adapter: adapter structure for which we are setting the link speed
1496 * @vpe: virtchnl_pf_event structure that contains the link speed we are setting
1497 *
1498 * Helper function for setting iavf_adapter link speed
1499 **/
1500static void
1501iavf_set_adapter_link_speed_from_vpe(struct iavf_adapter *adapter,
1502				     struct virtchnl_pf_event *vpe)
1503{
1504	if (ADV_LINK_SUPPORT(adapter))
1505		adapter->link_speed_mbps =
1506			vpe->event_data.link_event_adv.link_speed;
1507	else
1508		adapter->link_speed = vpe->event_data.link_event.link_speed;
1509}
1510
1511/**
1512 * iavf_get_qos_caps - get qos caps support
1513 * @adapter: iavf adapter struct instance
1514 *
1515 * This function requests PF for Supported QoS Caps.
1516 */
1517void iavf_get_qos_caps(struct iavf_adapter *adapter)
1518{
1519	if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
1520		/* bail because we already have a command pending */
1521		dev_err(&adapter->pdev->dev,
1522			"Cannot get qos caps, command %d pending\n",
1523			adapter->current_op);
1524		return;
1525	}
1526
1527	adapter->current_op = VIRTCHNL_OP_GET_QOS_CAPS;
1528	adapter->aq_required &= ~IAVF_FLAG_AQ_GET_QOS_CAPS;
1529	iavf_send_pf_msg(adapter, VIRTCHNL_OP_GET_QOS_CAPS, NULL, 0);
1530}
1531
1532/**
1533 * iavf_set_quanta_size - set quanta size of queue chunk
1534 * @adapter: iavf adapter struct instance
1535 * @quanta_size: quanta size in bytes
1536 * @queue_index: starting index of queue chunk
1537 * @num_queues: number of queues in the queue chunk
1538 *
1539 * This function requests PF to set quanta size of queue chunk
1540 * starting at queue_index.
1541 */
1542static void
1543iavf_set_quanta_size(struct iavf_adapter *adapter, u16 quanta_size,
1544		     u16 queue_index, u16 num_queues)
1545{
1546	struct virtchnl_quanta_cfg quanta_cfg;
1547
1548	if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
1549		/* bail because we already have a command pending */
1550		dev_err(&adapter->pdev->dev,
1551			"Cannot set queue quanta size, command %d pending\n",
1552			adapter->current_op);
1553		return;
1554	}
1555
1556	adapter->current_op = VIRTCHNL_OP_CONFIG_QUANTA;
1557	quanta_cfg.quanta_size = quanta_size;
1558	quanta_cfg.queue_select.type = VIRTCHNL_QUEUE_TYPE_TX;
1559	quanta_cfg.queue_select.start_queue_id = queue_index;
1560	quanta_cfg.queue_select.num_queues = num_queues;
1561	adapter->aq_required &= ~IAVF_FLAG_AQ_CFG_QUEUES_QUANTA_SIZE;
1562	iavf_send_pf_msg(adapter, VIRTCHNL_OP_CONFIG_QUANTA,
1563			 (u8 *)&quanta_cfg, sizeof(quanta_cfg));
1564}
1565
1566/**
1567 * iavf_cfg_queues_quanta_size - configure quanta size of queues
1568 * @adapter: adapter structure
1569 *
1570 * Request that the PF configure quanta size of allocated queues.
1571 **/
1572void iavf_cfg_queues_quanta_size(struct iavf_adapter *adapter)
1573{
1574	int quanta_size = IAVF_DEFAULT_QUANTA_SIZE;
1575
1576	/* Set Queue Quanta Size to default */
1577	iavf_set_quanta_size(adapter, quanta_size, 0,
1578			     adapter->num_active_queues);
1579}
1580
1581/**
1582 * iavf_cfg_queues_bw - configure bandwidth of allocated queues
1583 * @adapter: iavf adapter structure instance
1584 *
1585 * This function requests PF to configure queue bandwidth of allocated queues
1586 */
1587void iavf_cfg_queues_bw(struct iavf_adapter *adapter)
1588{
1589	struct virtchnl_queues_bw_cfg *qs_bw_cfg;
1590	struct net_shaper *q_shaper;
1591	int qs_to_update = 0;
1592	int i, inx = 0;
1593	size_t len;
1594
1595	if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
1596		/* bail because we already have a command pending */
1597		dev_err(&adapter->pdev->dev,
1598			"Cannot set tc queue bw, command %d pending\n",
1599			adapter->current_op);
1600		return;
1601	}
1602
1603	for (i = 0; i < adapter->num_active_queues; i++) {
1604		if (adapter->tx_rings[i].q_shaper_update)
1605			qs_to_update++;
1606	}
1607	len = struct_size(qs_bw_cfg, cfg, qs_to_update);
1608	qs_bw_cfg = kzalloc(len, GFP_KERNEL);
1609	if (!qs_bw_cfg)
1610		return;
1611
1612	qs_bw_cfg->vsi_id = adapter->vsi.id;
1613	qs_bw_cfg->num_queues = qs_to_update;
1614
1615	for (i = 0; i < adapter->num_active_queues; i++) {
1616		struct iavf_ring *tx_ring = &adapter->tx_rings[i];
1617
1618		q_shaper = &tx_ring->q_shaper;
1619		if (tx_ring->q_shaper_update) {
1620			qs_bw_cfg->cfg[inx].queue_id = i;
1621			qs_bw_cfg->cfg[inx].shaper.peak = q_shaper->bw_max;
1622			qs_bw_cfg->cfg[inx].shaper.committed = q_shaper->bw_min;
1623			qs_bw_cfg->cfg[inx].tc = 0;
1624			inx++;
1625		}
1626	}
1627
1628	adapter->current_op = VIRTCHNL_OP_CONFIG_QUEUE_BW;
1629	adapter->aq_required &= ~IAVF_FLAG_AQ_CONFIGURE_QUEUES_BW;
1630	iavf_send_pf_msg(adapter, VIRTCHNL_OP_CONFIG_QUEUE_BW,
1631			 (u8 *)qs_bw_cfg, len);
1632	kfree(qs_bw_cfg);
1633}
1634
1635/**
1636 * iavf_enable_channels
1637 * @adapter: adapter structure
1638 *
1639 * Request that the PF enable channels as specified by
1640 * the user via tc tool.
1641 **/
1642void iavf_enable_channels(struct iavf_adapter *adapter)
1643{
1644	struct virtchnl_tc_info *vti = NULL;
1645	size_t len;
1646	int i;
1647
1648	if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
1649		/* bail because we already have a command pending */
1650		dev_err(&adapter->pdev->dev, "Cannot configure mqprio, command %d pending\n",
1651			adapter->current_op);
1652		return;
1653	}
1654
1655	len = virtchnl_struct_size(vti, list, adapter->num_tc);
1656	vti = kzalloc(len, GFP_KERNEL);
1657	if (!vti)
1658		return;
1659	vti->num_tc = adapter->num_tc;
1660	for (i = 0; i < vti->num_tc; i++) {
1661		vti->list[i].count = adapter->ch_config.ch_info[i].count;
1662		vti->list[i].offset = adapter->ch_config.ch_info[i].offset;
1663		vti->list[i].pad = 0;
1664		vti->list[i].max_tx_rate =
1665				adapter->ch_config.ch_info[i].max_tx_rate;
1666	}
1667
1668	adapter->ch_config.state = __IAVF_TC_RUNNING;
1669	adapter->flags |= IAVF_FLAG_REINIT_ITR_NEEDED;
1670	adapter->current_op = VIRTCHNL_OP_ENABLE_CHANNELS;
1671	adapter->aq_required &= ~IAVF_FLAG_AQ_ENABLE_CHANNELS;
1672	iavf_send_pf_msg(adapter, VIRTCHNL_OP_ENABLE_CHANNELS, (u8 *)vti, len);
1673	kfree(vti);
1674}
1675
1676/**
1677 * iavf_disable_channels
1678 * @adapter: adapter structure
1679 *
1680 * Request that the PF disable channels that are configured
1681 **/
1682void iavf_disable_channels(struct iavf_adapter *adapter)
1683{
1684	if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
1685		/* bail because we already have a command pending */
1686		dev_err(&adapter->pdev->dev, "Cannot configure mqprio, command %d pending\n",
1687			adapter->current_op);
1688		return;
1689	}
1690
1691	adapter->ch_config.state = __IAVF_TC_INVALID;
1692	adapter->flags |= IAVF_FLAG_REINIT_ITR_NEEDED;
1693	adapter->current_op = VIRTCHNL_OP_DISABLE_CHANNELS;
1694	adapter->aq_required &= ~IAVF_FLAG_AQ_DISABLE_CHANNELS;
1695	iavf_send_pf_msg(adapter, VIRTCHNL_OP_DISABLE_CHANNELS, NULL, 0);
1696}
1697
1698/**
1699 * iavf_print_cloud_filter
1700 * @adapter: adapter structure
1701 * @f: cloud filter to print
1702 *
1703 * Print the cloud filter
1704 **/
1705static void iavf_print_cloud_filter(struct iavf_adapter *adapter,
1706				    struct virtchnl_filter *f)
1707{
1708	switch (f->flow_type) {
1709	case VIRTCHNL_TCP_V4_FLOW:
1710		dev_info(&adapter->pdev->dev, "dst_mac: %pM src_mac: %pM vlan_id: %hu dst_ip: %pI4 src_ip %pI4 dst_port %hu src_port %hu\n",
1711			 &f->data.tcp_spec.dst_mac,
1712			 &f->data.tcp_spec.src_mac,
1713			 ntohs(f->data.tcp_spec.vlan_id),
1714			 &f->data.tcp_spec.dst_ip[0],
1715			 &f->data.tcp_spec.src_ip[0],
1716			 ntohs(f->data.tcp_spec.dst_port),
1717			 ntohs(f->data.tcp_spec.src_port));
1718		break;
1719	case VIRTCHNL_TCP_V6_FLOW:
1720		dev_info(&adapter->pdev->dev, "dst_mac: %pM src_mac: %pM vlan_id: %hu dst_ip: %pI6 src_ip %pI6 dst_port %hu src_port %hu\n",
1721			 &f->data.tcp_spec.dst_mac,
1722			 &f->data.tcp_spec.src_mac,
1723			 ntohs(f->data.tcp_spec.vlan_id),
1724			 &f->data.tcp_spec.dst_ip,
1725			 &f->data.tcp_spec.src_ip,
1726			 ntohs(f->data.tcp_spec.dst_port),
1727			 ntohs(f->data.tcp_spec.src_port));
1728		break;
1729	}
1730}
1731
1732/**
1733 * iavf_add_cloud_filter
1734 * @adapter: adapter structure
1735 *
1736 * Request that the PF add cloud filters as specified
1737 * by the user via tc tool.
1738 **/
1739void iavf_add_cloud_filter(struct iavf_adapter *adapter)
1740{
1741	struct iavf_cloud_filter *cf;
1742	struct virtchnl_filter *f;
1743	int len = 0, count = 0;
1744
1745	if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
1746		/* bail because we already have a command pending */
1747		dev_err(&adapter->pdev->dev, "Cannot add cloud filter, command %d pending\n",
1748			adapter->current_op);
1749		return;
1750	}
1751	list_for_each_entry(cf, &adapter->cloud_filter_list, list) {
1752		if (cf->add) {
1753			count++;
1754			break;
1755		}
1756	}
1757	if (!count) {
1758		adapter->aq_required &= ~IAVF_FLAG_AQ_ADD_CLOUD_FILTER;
1759		return;
1760	}
1761	adapter->current_op = VIRTCHNL_OP_ADD_CLOUD_FILTER;
1762
1763	len = sizeof(struct virtchnl_filter);
1764	f = kzalloc(len, GFP_KERNEL);
1765	if (!f)
1766		return;
1767
1768	list_for_each_entry(cf, &adapter->cloud_filter_list, list) {
1769		if (cf->add) {
1770			memcpy(f, &cf->f, sizeof(struct virtchnl_filter));
1771			cf->add = false;
1772			cf->state = __IAVF_CF_ADD_PENDING;
1773			iavf_send_pf_msg(adapter, VIRTCHNL_OP_ADD_CLOUD_FILTER,
1774					 (u8 *)f, len);
1775		}
1776	}
1777	kfree(f);
1778}
1779
1780/**
1781 * iavf_del_cloud_filter
1782 * @adapter: adapter structure
1783 *
1784 * Request that the PF delete cloud filters as specified
1785 * by the user via tc tool.
1786 **/
1787void iavf_del_cloud_filter(struct iavf_adapter *adapter)
1788{
1789	struct iavf_cloud_filter *cf, *cftmp;
1790	struct virtchnl_filter *f;
1791	int len = 0, count = 0;
1792
1793	if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
1794		/* bail because we already have a command pending */
1795		dev_err(&adapter->pdev->dev, "Cannot remove cloud filter, command %d pending\n",
1796			adapter->current_op);
1797		return;
1798	}
1799	list_for_each_entry(cf, &adapter->cloud_filter_list, list) {
1800		if (cf->del) {
1801			count++;
1802			break;
1803		}
1804	}
1805	if (!count) {
1806		adapter->aq_required &= ~IAVF_FLAG_AQ_DEL_CLOUD_FILTER;
1807		return;
1808	}
1809	adapter->current_op = VIRTCHNL_OP_DEL_CLOUD_FILTER;
1810
1811	len = sizeof(struct virtchnl_filter);
1812	f = kzalloc(len, GFP_KERNEL);
1813	if (!f)
1814		return;
1815
1816	list_for_each_entry_safe(cf, cftmp, &adapter->cloud_filter_list, list) {
1817		if (cf->del) {
1818			memcpy(f, &cf->f, sizeof(struct virtchnl_filter));
1819			cf->del = false;
1820			cf->state = __IAVF_CF_DEL_PENDING;
1821			iavf_send_pf_msg(adapter, VIRTCHNL_OP_DEL_CLOUD_FILTER,
1822					 (u8 *)f, len);
1823		}
1824	}
1825	kfree(f);
1826}
1827
1828/**
1829 * iavf_add_fdir_filter
1830 * @adapter: the VF adapter structure
1831 *
1832 * Request that the PF add Flow Director filters as specified
1833 * by the user via ethtool.
1834 **/
1835void iavf_add_fdir_filter(struct iavf_adapter *adapter)
1836{
1837	struct iavf_fdir_fltr *fdir;
1838	struct virtchnl_fdir_add *f;
1839	bool process_fltr = false;
1840	int len;
1841
1842	if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
1843		/* bail because we already have a command pending */
1844		dev_err(&adapter->pdev->dev, "Cannot add Flow Director filter, command %d pending\n",
1845			adapter->current_op);
1846		return;
1847	}
1848
1849	len = sizeof(struct virtchnl_fdir_add);
1850	f = kzalloc(len, GFP_KERNEL);
1851	if (!f)
1852		return;
1853
1854	spin_lock_bh(&adapter->fdir_fltr_lock);
1855	list_for_each_entry(fdir, &adapter->fdir_list_head, list) {
1856		if (fdir->state == IAVF_FDIR_FLTR_ADD_REQUEST) {
1857			process_fltr = true;
1858			fdir->state = IAVF_FDIR_FLTR_ADD_PENDING;
1859			memcpy(f, &fdir->vc_add_msg, len);
1860			break;
1861		}
1862	}
1863	spin_unlock_bh(&adapter->fdir_fltr_lock);
1864
1865	if (!process_fltr) {
1866		/* prevent iavf_add_fdir_filter() from being called when there
1867		 * are no filters to add
1868		 */
1869		adapter->aq_required &= ~IAVF_FLAG_AQ_ADD_FDIR_FILTER;
1870		kfree(f);
1871		return;
1872	}
1873	adapter->current_op = VIRTCHNL_OP_ADD_FDIR_FILTER;
1874	iavf_send_pf_msg(adapter, VIRTCHNL_OP_ADD_FDIR_FILTER, (u8 *)f, len);
1875	kfree(f);
1876}
1877
1878/**
1879 * iavf_del_fdir_filter
1880 * @adapter: the VF adapter structure
1881 *
1882 * Request that the PF delete Flow Director filters as specified
1883 * by the user via ethtool.
1884 **/
1885void iavf_del_fdir_filter(struct iavf_adapter *adapter)
1886{
1887	struct virtchnl_fdir_del f = {};
1888	struct iavf_fdir_fltr *fdir;
 
1889	bool process_fltr = false;
1890	int len;
1891
1892	if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
1893		/* bail because we already have a command pending */
1894		dev_err(&adapter->pdev->dev, "Cannot remove Flow Director filter, command %d pending\n",
1895			adapter->current_op);
1896		return;
1897	}
1898
1899	len = sizeof(struct virtchnl_fdir_del);
1900
1901	spin_lock_bh(&adapter->fdir_fltr_lock);
1902	list_for_each_entry(fdir, &adapter->fdir_list_head, list) {
1903		if (fdir->state == IAVF_FDIR_FLTR_DEL_REQUEST) {
1904			process_fltr = true;
 
1905			f.vsi_id = fdir->vc_add_msg.vsi_id;
1906			f.flow_id = fdir->flow_id;
1907			fdir->state = IAVF_FDIR_FLTR_DEL_PENDING;
1908			break;
1909		} else if (fdir->state == IAVF_FDIR_FLTR_DIS_REQUEST) {
1910			process_fltr = true;
1911			f.vsi_id = fdir->vc_add_msg.vsi_id;
1912			f.flow_id = fdir->flow_id;
1913			fdir->state = IAVF_FDIR_FLTR_DIS_PENDING;
1914			break;
1915		}
1916	}
1917	spin_unlock_bh(&adapter->fdir_fltr_lock);
1918
1919	if (!process_fltr) {
1920		adapter->aq_required &= ~IAVF_FLAG_AQ_DEL_FDIR_FILTER;
1921		return;
1922	}
1923
1924	adapter->current_op = VIRTCHNL_OP_DEL_FDIR_FILTER;
1925	iavf_send_pf_msg(adapter, VIRTCHNL_OP_DEL_FDIR_FILTER, (u8 *)&f, len);
1926}
1927
1928/**
1929 * iavf_add_adv_rss_cfg
1930 * @adapter: the VF adapter structure
1931 *
1932 * Request that the PF add RSS configuration as specified
1933 * by the user via ethtool.
1934 **/
1935void iavf_add_adv_rss_cfg(struct iavf_adapter *adapter)
1936{
1937	struct virtchnl_rss_cfg *rss_cfg;
1938	struct iavf_adv_rss *rss;
1939	bool process_rss = false;
1940	int len;
1941
1942	if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
1943		/* bail because we already have a command pending */
1944		dev_err(&adapter->pdev->dev, "Cannot add RSS configuration, command %d pending\n",
1945			adapter->current_op);
1946		return;
1947	}
1948
1949	len = sizeof(struct virtchnl_rss_cfg);
1950	rss_cfg = kzalloc(len, GFP_KERNEL);
1951	if (!rss_cfg)
1952		return;
1953
1954	spin_lock_bh(&adapter->adv_rss_lock);
1955	list_for_each_entry(rss, &adapter->adv_rss_list_head, list) {
1956		if (rss->state == IAVF_ADV_RSS_ADD_REQUEST) {
1957			process_rss = true;
1958			rss->state = IAVF_ADV_RSS_ADD_PENDING;
1959			memcpy(rss_cfg, &rss->cfg_msg, len);
1960			iavf_print_adv_rss_cfg(adapter, rss,
1961					       "Input set change for",
1962					       "is pending");
1963			break;
1964		}
1965	}
1966	spin_unlock_bh(&adapter->adv_rss_lock);
1967
1968	if (process_rss) {
1969		adapter->current_op = VIRTCHNL_OP_ADD_RSS_CFG;
1970		iavf_send_pf_msg(adapter, VIRTCHNL_OP_ADD_RSS_CFG,
1971				 (u8 *)rss_cfg, len);
1972	} else {
1973		adapter->aq_required &= ~IAVF_FLAG_AQ_ADD_ADV_RSS_CFG;
1974	}
1975
1976	kfree(rss_cfg);
1977}
1978
1979/**
1980 * iavf_del_adv_rss_cfg
1981 * @adapter: the VF adapter structure
1982 *
1983 * Request that the PF delete RSS configuration as specified
1984 * by the user via ethtool.
1985 **/
1986void iavf_del_adv_rss_cfg(struct iavf_adapter *adapter)
1987{
1988	struct virtchnl_rss_cfg *rss_cfg;
1989	struct iavf_adv_rss *rss;
1990	bool process_rss = false;
1991	int len;
1992
1993	if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
1994		/* bail because we already have a command pending */
1995		dev_err(&adapter->pdev->dev, "Cannot remove RSS configuration, command %d pending\n",
1996			adapter->current_op);
1997		return;
1998	}
1999
2000	len = sizeof(struct virtchnl_rss_cfg);
2001	rss_cfg = kzalloc(len, GFP_KERNEL);
2002	if (!rss_cfg)
2003		return;
2004
2005	spin_lock_bh(&adapter->adv_rss_lock);
2006	list_for_each_entry(rss, &adapter->adv_rss_list_head, list) {
2007		if (rss->state == IAVF_ADV_RSS_DEL_REQUEST) {
2008			process_rss = true;
2009			rss->state = IAVF_ADV_RSS_DEL_PENDING;
2010			memcpy(rss_cfg, &rss->cfg_msg, len);
2011			break;
2012		}
2013	}
2014	spin_unlock_bh(&adapter->adv_rss_lock);
2015
2016	if (process_rss) {
2017		adapter->current_op = VIRTCHNL_OP_DEL_RSS_CFG;
2018		iavf_send_pf_msg(adapter, VIRTCHNL_OP_DEL_RSS_CFG,
2019				 (u8 *)rss_cfg, len);
2020	} else {
2021		adapter->aq_required &= ~IAVF_FLAG_AQ_DEL_ADV_RSS_CFG;
2022	}
2023
2024	kfree(rss_cfg);
2025}
2026
2027/**
2028 * iavf_request_reset
2029 * @adapter: adapter structure
2030 *
2031 * Request that the PF reset this VF. No response is expected.
2032 **/
2033int iavf_request_reset(struct iavf_adapter *adapter)
2034{
2035	int err;
2036	/* Don't check CURRENT_OP - this is always higher priority */
2037	err = iavf_send_pf_msg(adapter, VIRTCHNL_OP_RESET_VF, NULL, 0);
2038	adapter->current_op = VIRTCHNL_OP_UNKNOWN;
2039	return err;
2040}
2041
2042/**
2043 * iavf_netdev_features_vlan_strip_set - update vlan strip status
2044 * @netdev: ptr to netdev being adjusted
2045 * @enable: enable or disable vlan strip
2046 *
2047 * Helper function to change vlan strip status in netdev->features.
2048 */
2049static void iavf_netdev_features_vlan_strip_set(struct net_device *netdev,
2050						const bool enable)
2051{
2052	if (enable)
2053		netdev->features |= NETIF_F_HW_VLAN_CTAG_RX;
2054	else
2055		netdev->features &= ~NETIF_F_HW_VLAN_CTAG_RX;
2056}
2057
2058/**
2059 * iavf_activate_fdir_filters - Reactivate all FDIR filters after a reset
2060 * @adapter: private adapter structure
2061 *
2062 * Called after a reset to re-add all FDIR filters and delete some of them
2063 * if they were pending to be deleted.
2064 */
2065static void iavf_activate_fdir_filters(struct iavf_adapter *adapter)
2066{
2067	struct iavf_fdir_fltr *f, *ftmp;
2068	bool add_filters = false;
2069
2070	spin_lock_bh(&adapter->fdir_fltr_lock);
2071	list_for_each_entry_safe(f, ftmp, &adapter->fdir_list_head, list) {
2072		if (f->state == IAVF_FDIR_FLTR_ADD_REQUEST ||
2073		    f->state == IAVF_FDIR_FLTR_ADD_PENDING ||
2074		    f->state == IAVF_FDIR_FLTR_ACTIVE) {
2075			/* All filters and requests have been removed in PF,
2076			 * restore them
2077			 */
2078			f->state = IAVF_FDIR_FLTR_ADD_REQUEST;
2079			add_filters = true;
2080		} else if (f->state == IAVF_FDIR_FLTR_DIS_REQUEST ||
2081			   f->state == IAVF_FDIR_FLTR_DIS_PENDING) {
2082			/* Link down state, leave filters as inactive */
2083			f->state = IAVF_FDIR_FLTR_INACTIVE;
2084		} else if (f->state == IAVF_FDIR_FLTR_DEL_REQUEST ||
2085			   f->state == IAVF_FDIR_FLTR_DEL_PENDING) {
2086			/* Delete filters that were pending to be deleted, the
2087			 * list on PF is already cleared after a reset
2088			 */
2089			list_del(&f->list);
2090			iavf_dec_fdir_active_fltr(adapter, f);
2091			kfree(f);
2092		}
2093	}
2094	spin_unlock_bh(&adapter->fdir_fltr_lock);
2095
2096	if (add_filters)
2097		adapter->aq_required |= IAVF_FLAG_AQ_ADD_FDIR_FILTER;
2098}
2099
2100/**
2101 * iavf_virtchnl_completion
2102 * @adapter: adapter structure
2103 * @v_opcode: opcode sent by PF
2104 * @v_retval: retval sent by PF
2105 * @msg: message sent by PF
2106 * @msglen: message length
2107 *
2108 * Asynchronous completion function for admin queue messages. Rather than busy
2109 * wait, we fire off our requests and assume that no errors will be returned.
2110 * This function handles the reply messages.
2111 **/
2112void iavf_virtchnl_completion(struct iavf_adapter *adapter,
2113			      enum virtchnl_ops v_opcode,
2114			      enum iavf_status v_retval, u8 *msg, u16 msglen)
2115{
2116	struct net_device *netdev = adapter->netdev;
2117
2118	if (v_opcode == VIRTCHNL_OP_EVENT) {
2119		struct virtchnl_pf_event *vpe =
2120			(struct virtchnl_pf_event *)msg;
2121		bool link_up = iavf_get_vpe_link_status(adapter, vpe);
2122
2123		switch (vpe->event) {
2124		case VIRTCHNL_EVENT_LINK_CHANGE:
2125			iavf_set_adapter_link_speed_from_vpe(adapter, vpe);
2126
2127			/* we've already got the right link status, bail */
2128			if (adapter->link_up == link_up)
2129				break;
2130
2131			if (link_up) {
2132				/* If we get link up message and start queues
2133				 * before our queues are configured it will
2134				 * trigger a TX hang. In that case, just ignore
2135				 * the link status message,we'll get another one
2136				 * after we enable queues and actually prepared
2137				 * to send traffic.
2138				 */
2139				if (adapter->state != __IAVF_RUNNING)
2140					break;
2141
2142				/* For ADq enabled VF, we reconfigure VSIs and
2143				 * re-allocate queues. Hence wait till all
2144				 * queues are enabled.
2145				 */
2146				if (adapter->flags &
2147				    IAVF_FLAG_QUEUES_DISABLED)
2148					break;
2149			}
2150
2151			adapter->link_up = link_up;
2152			if (link_up) {
2153				netif_tx_start_all_queues(netdev);
2154				netif_carrier_on(netdev);
2155			} else {
2156				netif_tx_stop_all_queues(netdev);
2157				netif_carrier_off(netdev);
2158			}
2159			iavf_print_link_message(adapter);
2160			break;
2161		case VIRTCHNL_EVENT_RESET_IMPENDING:
2162			dev_info(&adapter->pdev->dev, "Reset indication received from the PF\n");
2163			if (!(adapter->flags & IAVF_FLAG_RESET_PENDING)) {
 
2164				dev_info(&adapter->pdev->dev, "Scheduling reset task\n");
2165				iavf_schedule_reset(adapter, IAVF_FLAG_RESET_PENDING);
2166			}
2167			break;
2168		default:
2169			dev_err(&adapter->pdev->dev, "Unknown event %d from PF\n",
2170				vpe->event);
2171			break;
2172		}
2173		return;
2174	}
2175	if (v_retval) {
2176		switch (v_opcode) {
2177		case VIRTCHNL_OP_ADD_VLAN:
2178			dev_err(&adapter->pdev->dev, "Failed to add VLAN filter, error %s\n",
2179				iavf_stat_str(&adapter->hw, v_retval));
2180			break;
2181		case VIRTCHNL_OP_ADD_ETH_ADDR:
2182			dev_err(&adapter->pdev->dev, "Failed to add MAC filter, error %s\n",
2183				iavf_stat_str(&adapter->hw, v_retval));
2184			iavf_mac_add_reject(adapter);
2185			/* restore administratively set MAC address */
2186			ether_addr_copy(adapter->hw.mac.addr, netdev->dev_addr);
2187			wake_up(&adapter->vc_waitqueue);
2188			break;
2189		case VIRTCHNL_OP_DEL_VLAN:
2190			dev_err(&adapter->pdev->dev, "Failed to delete VLAN filter, error %s\n",
2191				iavf_stat_str(&adapter->hw, v_retval));
2192			break;
2193		case VIRTCHNL_OP_DEL_ETH_ADDR:
2194			dev_err(&adapter->pdev->dev, "Failed to delete MAC filter, error %s\n",
2195				iavf_stat_str(&adapter->hw, v_retval));
2196			break;
2197		case VIRTCHNL_OP_ENABLE_CHANNELS:
2198			dev_err(&adapter->pdev->dev, "Failed to configure queue channels, error %s\n",
2199				iavf_stat_str(&adapter->hw, v_retval));
2200			adapter->flags &= ~IAVF_FLAG_REINIT_ITR_NEEDED;
2201			adapter->ch_config.state = __IAVF_TC_INVALID;
2202			netdev_reset_tc(netdev);
2203			netif_tx_start_all_queues(netdev);
2204			break;
2205		case VIRTCHNL_OP_DISABLE_CHANNELS:
2206			dev_err(&adapter->pdev->dev, "Failed to disable queue channels, error %s\n",
2207				iavf_stat_str(&adapter->hw, v_retval));
2208			adapter->flags &= ~IAVF_FLAG_REINIT_ITR_NEEDED;
2209			adapter->ch_config.state = __IAVF_TC_RUNNING;
2210			netif_tx_start_all_queues(netdev);
2211			break;
2212		case VIRTCHNL_OP_ADD_CLOUD_FILTER: {
2213			struct iavf_cloud_filter *cf, *cftmp;
2214
2215			list_for_each_entry_safe(cf, cftmp,
2216						 &adapter->cloud_filter_list,
2217						 list) {
2218				if (cf->state == __IAVF_CF_ADD_PENDING) {
2219					cf->state = __IAVF_CF_INVALID;
2220					dev_info(&adapter->pdev->dev, "Failed to add cloud filter, error %s\n",
2221						 iavf_stat_str(&adapter->hw,
2222							       v_retval));
2223					iavf_print_cloud_filter(adapter,
2224								&cf->f);
2225					list_del(&cf->list);
2226					kfree(cf);
2227					adapter->num_cloud_filters--;
2228				}
2229			}
2230			}
2231			break;
2232		case VIRTCHNL_OP_DEL_CLOUD_FILTER: {
2233			struct iavf_cloud_filter *cf;
2234
2235			list_for_each_entry(cf, &adapter->cloud_filter_list,
2236					    list) {
2237				if (cf->state == __IAVF_CF_DEL_PENDING) {
2238					cf->state = __IAVF_CF_ACTIVE;
2239					dev_info(&adapter->pdev->dev, "Failed to del cloud filter, error %s\n",
2240						 iavf_stat_str(&adapter->hw,
2241							       v_retval));
2242					iavf_print_cloud_filter(adapter,
2243								&cf->f);
2244				}
2245			}
2246			}
2247			break;
2248		case VIRTCHNL_OP_ADD_FDIR_FILTER: {
2249			struct iavf_fdir_fltr *fdir, *fdir_tmp;
2250
2251			spin_lock_bh(&adapter->fdir_fltr_lock);
2252			list_for_each_entry_safe(fdir, fdir_tmp,
2253						 &adapter->fdir_list_head,
2254						 list) {
2255				if (fdir->state == IAVF_FDIR_FLTR_ADD_PENDING) {
2256					dev_info(&adapter->pdev->dev, "Failed to add Flow Director filter, error %s\n",
2257						 iavf_stat_str(&adapter->hw,
2258							       v_retval));
2259					iavf_print_fdir_fltr(adapter, fdir);
2260					if (msglen)
2261						dev_err(&adapter->pdev->dev,
2262							"%s\n", msg);
2263					list_del(&fdir->list);
2264					iavf_dec_fdir_active_fltr(adapter, fdir);
2265					kfree(fdir);
 
2266				}
2267			}
2268			spin_unlock_bh(&adapter->fdir_fltr_lock);
2269			}
2270			break;
2271		case VIRTCHNL_OP_DEL_FDIR_FILTER: {
2272			struct iavf_fdir_fltr *fdir;
2273
2274			spin_lock_bh(&adapter->fdir_fltr_lock);
2275			list_for_each_entry(fdir, &adapter->fdir_list_head,
2276					    list) {
2277				if (fdir->state == IAVF_FDIR_FLTR_DEL_PENDING ||
2278				    fdir->state == IAVF_FDIR_FLTR_DIS_PENDING) {
2279					fdir->state = IAVF_FDIR_FLTR_ACTIVE;
2280					dev_info(&adapter->pdev->dev, "Failed to del Flow Director filter, error %s\n",
2281						 iavf_stat_str(&adapter->hw,
2282							       v_retval));
2283					iavf_print_fdir_fltr(adapter, fdir);
2284				}
2285			}
2286			spin_unlock_bh(&adapter->fdir_fltr_lock);
2287			}
2288			break;
2289		case VIRTCHNL_OP_ADD_RSS_CFG: {
2290			struct iavf_adv_rss *rss, *rss_tmp;
2291
2292			spin_lock_bh(&adapter->adv_rss_lock);
2293			list_for_each_entry_safe(rss, rss_tmp,
2294						 &adapter->adv_rss_list_head,
2295						 list) {
2296				if (rss->state == IAVF_ADV_RSS_ADD_PENDING) {
2297					iavf_print_adv_rss_cfg(adapter, rss,
2298							       "Failed to change the input set for",
2299							       NULL);
2300					list_del(&rss->list);
2301					kfree(rss);
2302				}
2303			}
2304			spin_unlock_bh(&adapter->adv_rss_lock);
2305			}
2306			break;
2307		case VIRTCHNL_OP_DEL_RSS_CFG: {
2308			struct iavf_adv_rss *rss;
2309
2310			spin_lock_bh(&adapter->adv_rss_lock);
2311			list_for_each_entry(rss, &adapter->adv_rss_list_head,
2312					    list) {
2313				if (rss->state == IAVF_ADV_RSS_DEL_PENDING) {
2314					rss->state = IAVF_ADV_RSS_ACTIVE;
2315					dev_err(&adapter->pdev->dev, "Failed to delete RSS configuration, error %s\n",
2316						iavf_stat_str(&adapter->hw,
2317							      v_retval));
2318				}
2319			}
2320			spin_unlock_bh(&adapter->adv_rss_lock);
2321			}
2322			break;
2323		case VIRTCHNL_OP_ENABLE_VLAN_STRIPPING:
2324			dev_warn(&adapter->pdev->dev, "Changing VLAN Stripping is not allowed when Port VLAN is configured\n");
2325			/* Vlan stripping could not be enabled by ethtool.
2326			 * Disable it in netdev->features.
2327			 */
2328			iavf_netdev_features_vlan_strip_set(netdev, false);
2329			break;
2330		case VIRTCHNL_OP_DISABLE_VLAN_STRIPPING:
2331			dev_warn(&adapter->pdev->dev, "Changing VLAN Stripping is not allowed when Port VLAN is configured\n");
2332			/* Vlan stripping could not be disabled by ethtool.
2333			 * Enable it in netdev->features.
2334			 */
2335			iavf_netdev_features_vlan_strip_set(netdev, true);
2336			break;
2337		case VIRTCHNL_OP_ADD_VLAN_V2:
2338			iavf_vlan_add_reject(adapter);
2339			dev_warn(&adapter->pdev->dev, "Failed to add VLAN filter, error %s\n",
2340				 iavf_stat_str(&adapter->hw, v_retval));
2341			break;
2342		case VIRTCHNL_OP_CONFIG_RSS_HFUNC:
2343			dev_warn(&adapter->pdev->dev, "Failed to configure hash function, error %s\n",
2344				 iavf_stat_str(&adapter->hw, v_retval));
2345
2346			if (adapter->hfunc ==
2347					VIRTCHNL_RSS_ALG_TOEPLITZ_SYMMETRIC)
2348				adapter->hfunc =
2349					VIRTCHNL_RSS_ALG_TOEPLITZ_ASYMMETRIC;
2350			else
2351				adapter->hfunc =
2352					VIRTCHNL_RSS_ALG_TOEPLITZ_SYMMETRIC;
2353
2354			break;
2355		case VIRTCHNL_OP_GET_QOS_CAPS:
2356			dev_warn(&adapter->pdev->dev, "Failed to Get Qos CAPs, error %s\n",
2357				 iavf_stat_str(&adapter->hw, v_retval));
2358			break;
2359		case VIRTCHNL_OP_CONFIG_QUANTA:
2360			dev_warn(&adapter->pdev->dev, "Failed to Config Quanta, error %s\n",
2361				 iavf_stat_str(&adapter->hw, v_retval));
2362			break;
2363		case VIRTCHNL_OP_CONFIG_QUEUE_BW:
2364			dev_warn(&adapter->pdev->dev, "Failed to Config Queue BW, error %s\n",
2365				 iavf_stat_str(&adapter->hw, v_retval));
2366			break;
2367		default:
2368			dev_err(&adapter->pdev->dev, "PF returned error %d (%s) to our request %d\n",
2369				v_retval, iavf_stat_str(&adapter->hw, v_retval),
2370				v_opcode);
2371		}
2372	}
2373	switch (v_opcode) {
2374	case VIRTCHNL_OP_ADD_ETH_ADDR:
2375		if (!v_retval)
2376			iavf_mac_add_ok(adapter);
2377		if (!ether_addr_equal(netdev->dev_addr, adapter->hw.mac.addr))
2378			if (!ether_addr_equal(netdev->dev_addr,
2379					      adapter->hw.mac.addr)) {
2380				netif_addr_lock_bh(netdev);
2381				eth_hw_addr_set(netdev, adapter->hw.mac.addr);
2382				netif_addr_unlock_bh(netdev);
2383			}
2384		wake_up(&adapter->vc_waitqueue);
2385		break;
2386	case VIRTCHNL_OP_GET_STATS: {
2387		struct iavf_eth_stats *stats =
2388			(struct iavf_eth_stats *)msg;
2389		netdev->stats.rx_packets = stats->rx_unicast +
2390					   stats->rx_multicast +
2391					   stats->rx_broadcast;
2392		netdev->stats.tx_packets = stats->tx_unicast +
2393					   stats->tx_multicast +
2394					   stats->tx_broadcast;
2395		netdev->stats.rx_bytes = stats->rx_bytes;
2396		netdev->stats.tx_bytes = stats->tx_bytes;
2397		netdev->stats.tx_errors = stats->tx_errors;
2398		netdev->stats.rx_dropped = stats->rx_discards;
2399		netdev->stats.tx_dropped = stats->tx_discards;
2400		adapter->current_stats = *stats;
2401		}
2402		break;
2403	case VIRTCHNL_OP_GET_VF_RESOURCES: {
2404		u16 len = IAVF_VIRTCHNL_VF_RESOURCE_SIZE;
2405
 
2406		memcpy(adapter->vf_res, msg, min(msglen, len));
2407		iavf_validate_num_queues(adapter);
2408		iavf_vf_parse_hw_config(&adapter->hw, adapter->vf_res);
2409		if (is_zero_ether_addr(adapter->hw.mac.addr)) {
2410			/* restore current mac address */
2411			ether_addr_copy(adapter->hw.mac.addr, netdev->dev_addr);
2412		} else {
2413			netif_addr_lock_bh(netdev);
2414			/* refresh current mac address if changed */
 
2415			ether_addr_copy(netdev->perm_addr,
2416					adapter->hw.mac.addr);
2417			netif_addr_unlock_bh(netdev);
2418		}
2419		spin_lock_bh(&adapter->mac_vlan_list_lock);
2420		iavf_add_filter(adapter, adapter->hw.mac.addr);
2421
2422		if (VLAN_ALLOWED(adapter)) {
2423			if (!list_empty(&adapter->vlan_filter_list)) {
2424				struct iavf_vlan_filter *vlf;
2425
2426				/* re-add all VLAN filters over virtchnl */
2427				list_for_each_entry(vlf,
2428						    &adapter->vlan_filter_list,
2429						    list)
2430					vlf->state = IAVF_VLAN_ADD;
2431
2432				adapter->aq_required |=
2433					IAVF_FLAG_AQ_ADD_VLAN_FILTER;
2434			}
2435		}
2436
2437		spin_unlock_bh(&adapter->mac_vlan_list_lock);
2438
2439		iavf_activate_fdir_filters(adapter);
2440
2441		iavf_parse_vf_resource_msg(adapter);
2442
2443		/* negotiated VIRTCHNL_VF_OFFLOAD_VLAN_V2, so wait for the
2444		 * response to VIRTCHNL_OP_GET_OFFLOAD_VLAN_V2_CAPS to finish
2445		 * configuration
2446		 */
2447		if (VLAN_V2_ALLOWED(adapter))
2448			break;
2449		/* fallthrough and finish config if VIRTCHNL_VF_OFFLOAD_VLAN_V2
2450		 * wasn't successfully negotiated with the PF
2451		 */
2452		}
2453		fallthrough;
2454	case VIRTCHNL_OP_GET_OFFLOAD_VLAN_V2_CAPS: {
2455		struct iavf_mac_filter *f;
2456		bool was_mac_changed;
2457		u64 aq_required = 0;
2458
2459		if (v_opcode == VIRTCHNL_OP_GET_OFFLOAD_VLAN_V2_CAPS)
2460			memcpy(&adapter->vlan_v2_caps, msg,
2461			       min_t(u16, msglen,
2462				     sizeof(adapter->vlan_v2_caps)));
2463
2464		iavf_process_config(adapter);
2465		adapter->flags |= IAVF_FLAG_SETUP_NETDEV_FEATURES;
2466		iavf_schedule_finish_config(adapter);
2467
2468		iavf_set_queue_vlan_tag_loc(adapter);
2469
2470		was_mac_changed = !ether_addr_equal(netdev->dev_addr,
2471						    adapter->hw.mac.addr);
2472
2473		spin_lock_bh(&adapter->mac_vlan_list_lock);
2474
2475		/* re-add all MAC filters */
2476		list_for_each_entry(f, &adapter->mac_filter_list, list) {
2477			if (was_mac_changed &&
2478			    ether_addr_equal(netdev->dev_addr, f->macaddr))
2479				ether_addr_copy(f->macaddr,
2480						adapter->hw.mac.addr);
2481
2482			f->is_new_mac = true;
2483			f->add = true;
2484			f->add_handled = false;
2485			f->remove = false;
2486		}
2487
2488		/* re-add all VLAN filters */
2489		if (VLAN_FILTERING_ALLOWED(adapter)) {
2490			struct iavf_vlan_filter *vlf;
2491
2492			if (!list_empty(&adapter->vlan_filter_list)) {
2493				list_for_each_entry(vlf,
2494						    &adapter->vlan_filter_list,
2495						    list)
2496					vlf->state = IAVF_VLAN_ADD;
2497
2498				aq_required |= IAVF_FLAG_AQ_ADD_VLAN_FILTER;
2499			}
2500		}
2501
2502		spin_unlock_bh(&adapter->mac_vlan_list_lock);
2503
2504		netif_addr_lock_bh(netdev);
2505		eth_hw_addr_set(netdev, adapter->hw.mac.addr);
2506		netif_addr_unlock_bh(netdev);
2507
2508		adapter->aq_required |= IAVF_FLAG_AQ_ADD_MAC_FILTER |
2509			aq_required;
2510		}
2511		break;
2512	case VIRTCHNL_OP_ENABLE_QUEUES:
2513		/* enable transmits */
2514		iavf_irq_enable(adapter, true);
2515		wake_up(&adapter->reset_waitqueue);
2516		adapter->flags &= ~IAVF_FLAG_QUEUES_DISABLED;
2517		break;
2518	case VIRTCHNL_OP_DISABLE_QUEUES:
2519		iavf_free_all_tx_resources(adapter);
2520		iavf_free_all_rx_resources(adapter);
2521		if (adapter->state == __IAVF_DOWN_PENDING) {
2522			iavf_change_state(adapter, __IAVF_DOWN);
2523			wake_up(&adapter->down_waitqueue);
2524		}
2525		break;
2526	case VIRTCHNL_OP_VERSION:
2527	case VIRTCHNL_OP_CONFIG_IRQ_MAP:
2528		/* Don't display an error if we get these out of sequence.
2529		 * If the firmware needed to get kicked, we'll get these and
2530		 * it's no problem.
2531		 */
2532		if (v_opcode != adapter->current_op)
2533			return;
2534		break;
 
 
 
 
 
 
 
 
 
 
 
 
 
2535	case VIRTCHNL_OP_GET_RSS_HENA_CAPS: {
2536		struct virtchnl_rss_hena *vrh = (struct virtchnl_rss_hena *)msg;
2537
2538		if (msglen == sizeof(*vrh))
2539			adapter->hena = vrh->hena;
2540		else
2541			dev_warn(&adapter->pdev->dev,
2542				 "Invalid message %d from PF\n", v_opcode);
2543		}
2544		break;
2545	case VIRTCHNL_OP_REQUEST_QUEUES: {
2546		struct virtchnl_vf_res_request *vfres =
2547			(struct virtchnl_vf_res_request *)msg;
2548
2549		if (vfres->num_queue_pairs != adapter->num_req_queues) {
2550			dev_info(&adapter->pdev->dev,
2551				 "Requested %d queues, PF can support %d\n",
2552				 adapter->num_req_queues,
2553				 vfres->num_queue_pairs);
2554			adapter->num_req_queues = 0;
2555			adapter->flags &= ~IAVF_FLAG_REINIT_ITR_NEEDED;
2556		}
2557		}
2558		break;
2559	case VIRTCHNL_OP_ADD_CLOUD_FILTER: {
2560		struct iavf_cloud_filter *cf;
2561
2562		list_for_each_entry(cf, &adapter->cloud_filter_list, list) {
2563			if (cf->state == __IAVF_CF_ADD_PENDING)
2564				cf->state = __IAVF_CF_ACTIVE;
2565		}
2566		}
2567		break;
2568	case VIRTCHNL_OP_DEL_CLOUD_FILTER: {
2569		struct iavf_cloud_filter *cf, *cftmp;
2570
2571		list_for_each_entry_safe(cf, cftmp, &adapter->cloud_filter_list,
2572					 list) {
2573			if (cf->state == __IAVF_CF_DEL_PENDING) {
2574				cf->state = __IAVF_CF_INVALID;
2575				list_del(&cf->list);
2576				kfree(cf);
2577				adapter->num_cloud_filters--;
2578			}
2579		}
2580		}
2581		break;
2582	case VIRTCHNL_OP_ADD_FDIR_FILTER: {
2583		struct virtchnl_fdir_add *add_fltr = (struct virtchnl_fdir_add *)msg;
2584		struct iavf_fdir_fltr *fdir, *fdir_tmp;
2585
2586		spin_lock_bh(&adapter->fdir_fltr_lock);
2587		list_for_each_entry_safe(fdir, fdir_tmp,
2588					 &adapter->fdir_list_head,
2589					 list) {
2590			if (fdir->state == IAVF_FDIR_FLTR_ADD_PENDING) {
2591				if (add_fltr->status == VIRTCHNL_FDIR_SUCCESS) {
2592					if (!iavf_is_raw_fdir(fdir))
2593						dev_info(&adapter->pdev->dev, "Flow Director filter with location %u is added\n",
2594							 fdir->loc);
2595					else
2596						dev_info(&adapter->pdev->dev, "Flow Director filter (raw) for TC handle %x is added\n",
2597							 TC_U32_USERHTID(fdir->cls_u32_handle));
2598					fdir->state = IAVF_FDIR_FLTR_ACTIVE;
2599					fdir->flow_id = add_fltr->flow_id;
2600				} else {
2601					dev_info(&adapter->pdev->dev, "Failed to add Flow Director filter with status: %d\n",
2602						 add_fltr->status);
2603					iavf_print_fdir_fltr(adapter, fdir);
2604					list_del(&fdir->list);
2605					iavf_dec_fdir_active_fltr(adapter, fdir);
2606					kfree(fdir);
 
2607				}
2608			}
2609		}
2610		spin_unlock_bh(&adapter->fdir_fltr_lock);
2611		}
2612		break;
2613	case VIRTCHNL_OP_DEL_FDIR_FILTER: {
2614		struct virtchnl_fdir_del *del_fltr = (struct virtchnl_fdir_del *)msg;
2615		struct iavf_fdir_fltr *fdir, *fdir_tmp;
2616
2617		spin_lock_bh(&adapter->fdir_fltr_lock);
2618		list_for_each_entry_safe(fdir, fdir_tmp, &adapter->fdir_list_head,
2619					 list) {
2620			if (fdir->state == IAVF_FDIR_FLTR_DEL_PENDING) {
2621				if (del_fltr->status == VIRTCHNL_FDIR_SUCCESS ||
2622				    del_fltr->status ==
2623				    VIRTCHNL_FDIR_FAILURE_RULE_NONEXIST) {
2624					if (!iavf_is_raw_fdir(fdir))
2625						dev_info(&adapter->pdev->dev, "Flow Director filter with location %u is deleted\n",
2626							 fdir->loc);
2627					else
2628						dev_info(&adapter->pdev->dev, "Flow Director filter (raw) for TC handle %x is deleted\n",
2629							 TC_U32_USERHTID(fdir->cls_u32_handle));
2630					list_del(&fdir->list);
2631					iavf_dec_fdir_active_fltr(adapter, fdir);
2632					kfree(fdir);
 
2633				} else {
2634					fdir->state = IAVF_FDIR_FLTR_ACTIVE;
2635					dev_info(&adapter->pdev->dev, "Failed to delete Flow Director filter with status: %d\n",
2636						 del_fltr->status);
2637					iavf_print_fdir_fltr(adapter, fdir);
2638				}
2639			} else if (fdir->state == IAVF_FDIR_FLTR_DIS_PENDING) {
2640				if (del_fltr->status == VIRTCHNL_FDIR_SUCCESS ||
2641				    del_fltr->status ==
2642				    VIRTCHNL_FDIR_FAILURE_RULE_NONEXIST) {
2643					fdir->state = IAVF_FDIR_FLTR_INACTIVE;
2644				} else {
2645					fdir->state = IAVF_FDIR_FLTR_ACTIVE;
2646					dev_info(&adapter->pdev->dev, "Failed to disable Flow Director filter with status: %d\n",
2647						 del_fltr->status);
2648					iavf_print_fdir_fltr(adapter, fdir);
2649				}
2650			}
2651		}
2652		spin_unlock_bh(&adapter->fdir_fltr_lock);
2653		}
2654		break;
2655	case VIRTCHNL_OP_ADD_RSS_CFG: {
2656		struct iavf_adv_rss *rss;
2657
2658		spin_lock_bh(&adapter->adv_rss_lock);
2659		list_for_each_entry(rss, &adapter->adv_rss_list_head, list) {
2660			if (rss->state == IAVF_ADV_RSS_ADD_PENDING) {
2661				iavf_print_adv_rss_cfg(adapter, rss,
2662						       "Input set change for",
2663						       "successful");
2664				rss->state = IAVF_ADV_RSS_ACTIVE;
2665			}
2666		}
2667		spin_unlock_bh(&adapter->adv_rss_lock);
2668		}
2669		break;
2670	case VIRTCHNL_OP_DEL_RSS_CFG: {
2671		struct iavf_adv_rss *rss, *rss_tmp;
2672
2673		spin_lock_bh(&adapter->adv_rss_lock);
2674		list_for_each_entry_safe(rss, rss_tmp,
2675					 &adapter->adv_rss_list_head, list) {
2676			if (rss->state == IAVF_ADV_RSS_DEL_PENDING) {
2677				list_del(&rss->list);
2678				kfree(rss);
2679			}
2680		}
2681		spin_unlock_bh(&adapter->adv_rss_lock);
2682		}
2683		break;
2684	case VIRTCHNL_OP_ADD_VLAN_V2: {
2685		struct iavf_vlan_filter *f;
2686
2687		spin_lock_bh(&adapter->mac_vlan_list_lock);
2688		list_for_each_entry(f, &adapter->vlan_filter_list, list) {
2689			if (f->state == IAVF_VLAN_IS_NEW)
2690				f->state = IAVF_VLAN_ACTIVE;
2691		}
2692		spin_unlock_bh(&adapter->mac_vlan_list_lock);
2693		}
2694		break;
2695	case VIRTCHNL_OP_ENABLE_VLAN_STRIPPING:
2696		/* PF enabled vlan strip on this VF.
2697		 * Update netdev->features if needed to be in sync with ethtool.
2698		 */
2699		if (!v_retval)
2700			iavf_netdev_features_vlan_strip_set(netdev, true);
2701		break;
2702	case VIRTCHNL_OP_DISABLE_VLAN_STRIPPING:
2703		/* PF disabled vlan strip on this VF.
2704		 * Update netdev->features if needed to be in sync with ethtool.
2705		 */
2706		if (!v_retval)
2707			iavf_netdev_features_vlan_strip_set(netdev, false);
2708		break;
2709	case VIRTCHNL_OP_GET_QOS_CAPS: {
2710		u16 len = struct_size(adapter->qos_caps, cap,
2711				      IAVF_MAX_QOS_TC_NUM);
2712
2713		memcpy(adapter->qos_caps, msg, min(msglen, len));
2714
2715		adapter->aq_required |= IAVF_FLAG_AQ_CFG_QUEUES_QUANTA_SIZE;
2716		}
2717		break;
2718	case VIRTCHNL_OP_CONFIG_QUANTA:
2719		break;
2720	case VIRTCHNL_OP_CONFIG_QUEUE_BW: {
2721		int i;
2722		/* shaper configuration is successful for all queues */
2723		for (i = 0; i < adapter->num_active_queues; i++)
2724			adapter->tx_rings[i].q_shaper_update = false;
2725	}
2726		break;
2727	default:
2728		if (adapter->current_op && (v_opcode != adapter->current_op))
2729			dev_warn(&adapter->pdev->dev, "Expected response %d from PF, received %d\n",
2730				 adapter->current_op, v_opcode);
2731		break;
2732	} /* switch v_opcode */
2733	adapter->current_op = VIRTCHNL_OP_UNKNOWN;
2734}
v5.14.15
   1// SPDX-License-Identifier: GPL-2.0
   2/* Copyright(c) 2013 - 2018 Intel Corporation. */
   3
 
 
   4#include "iavf.h"
   5#include "iavf_prototype.h"
   6#include "iavf_client.h"
   7
   8/* busy wait delay in msec */
   9#define IAVF_BUSY_WAIT_DELAY 10
  10#define IAVF_BUSY_WAIT_COUNT 50
  11
  12/**
  13 * iavf_send_pf_msg
  14 * @adapter: adapter structure
  15 * @op: virtual channel opcode
  16 * @msg: pointer to message buffer
  17 * @len: message length
  18 *
  19 * Send message to PF and print status if failure.
  20 **/
  21static int iavf_send_pf_msg(struct iavf_adapter *adapter,
  22			    enum virtchnl_ops op, u8 *msg, u16 len)
  23{
  24	struct iavf_hw *hw = &adapter->hw;
  25	enum iavf_status err;
  26
  27	if (adapter->flags & IAVF_FLAG_PF_COMMS_FAILED)
  28		return 0; /* nothing to see here, move along */
  29
  30	err = iavf_aq_send_msg_to_pf(hw, op, 0, msg, len, NULL);
  31	if (err)
  32		dev_dbg(&adapter->pdev->dev, "Unable to send opcode %d to PF, err %s, aq_err %s\n",
  33			op, iavf_stat_str(hw, err),
  34			iavf_aq_str(hw, hw->aq.asq_last_status));
  35	return err;
  36}
  37
  38/**
  39 * iavf_send_api_ver
  40 * @adapter: adapter structure
  41 *
  42 * Send API version admin queue message to the PF. The reply is not checked
  43 * in this function. Returns 0 if the message was successfully
  44 * sent, or one of the IAVF_ADMIN_QUEUE_ERROR_ statuses if not.
  45 **/
  46int iavf_send_api_ver(struct iavf_adapter *adapter)
  47{
  48	struct virtchnl_version_info vvi;
  49
  50	vvi.major = VIRTCHNL_VERSION_MAJOR;
  51	vvi.minor = VIRTCHNL_VERSION_MINOR;
  52
  53	return iavf_send_pf_msg(adapter, VIRTCHNL_OP_VERSION, (u8 *)&vvi,
  54				sizeof(vvi));
  55}
  56
  57/**
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
  58 * iavf_verify_api_ver
  59 * @adapter: adapter structure
  60 *
  61 * Compare API versions with the PF. Must be called after admin queue is
  62 * initialized. Returns 0 if API versions match, -EIO if they do not,
  63 * IAVF_ERR_ADMIN_QUEUE_NO_WORK if the admin queue is empty, and any errors
  64 * from the firmware are propagated.
  65 **/
  66int iavf_verify_api_ver(struct iavf_adapter *adapter)
  67{
  68	struct virtchnl_version_info *pf_vvi;
  69	struct iavf_hw *hw = &adapter->hw;
  70	struct iavf_arq_event_info event;
  71	enum virtchnl_ops op;
  72	enum iavf_status err;
  73
  74	event.buf_len = IAVF_MAX_AQ_BUF_SIZE;
  75	event.msg_buf = kzalloc(event.buf_len, GFP_KERNEL);
  76	if (!event.msg_buf) {
  77		err = -ENOMEM;
  78		goto out;
 
 
 
 
 
 
 
 
 
 
  79	}
  80
  81	while (1) {
  82		err = iavf_clean_arq_element(hw, &event, NULL);
  83		/* When the AQ is empty, iavf_clean_arq_element will return
  84		 * nonzero and this loop will terminate.
  85		 */
  86		if (err)
  87			goto out_alloc;
  88		op =
  89		    (enum virtchnl_ops)le32_to_cpu(event.desc.cookie_high);
  90		if (op == VIRTCHNL_OP_VERSION)
  91			break;
  92	}
  93
  94
  95	err = (enum iavf_status)le32_to_cpu(event.desc.cookie_low);
  96	if (err)
  97		goto out_alloc;
  98
  99	if (op != VIRTCHNL_OP_VERSION) {
 100		dev_info(&adapter->pdev->dev, "Invalid reply type %d from PF\n",
 101			op);
 102		err = -EIO;
 103		goto out_alloc;
 104	}
 105
 106	pf_vvi = (struct virtchnl_version_info *)event.msg_buf;
 107	adapter->pf_version = *pf_vvi;
 108
 109	if ((pf_vvi->major > VIRTCHNL_VERSION_MAJOR) ||
 110	    ((pf_vvi->major == VIRTCHNL_VERSION_MAJOR) &&
 111	     (pf_vvi->minor > VIRTCHNL_VERSION_MINOR)))
 112		err = -EIO;
 113
 114out_alloc:
 115	kfree(event.msg_buf);
 116out:
 117	return err;
 118}
 119
 120/**
 121 * iavf_send_vf_config_msg
 122 * @adapter: adapter structure
 123 *
 124 * Send VF configuration request admin queue message to the PF. The reply
 125 * is not checked in this function. Returns 0 if the message was
 126 * successfully sent, or one of the IAVF_ADMIN_QUEUE_ERROR_ statuses if not.
 127 **/
 128int iavf_send_vf_config_msg(struct iavf_adapter *adapter)
 129{
 130	u32 caps;
 131
 132	caps = VIRTCHNL_VF_OFFLOAD_L2 |
 133	       VIRTCHNL_VF_OFFLOAD_RSS_PF |
 134	       VIRTCHNL_VF_OFFLOAD_RSS_AQ |
 135	       VIRTCHNL_VF_OFFLOAD_RSS_REG |
 136	       VIRTCHNL_VF_OFFLOAD_VLAN |
 137	       VIRTCHNL_VF_OFFLOAD_WB_ON_ITR |
 138	       VIRTCHNL_VF_OFFLOAD_RSS_PCTYPE_V2 |
 139	       VIRTCHNL_VF_OFFLOAD_ENCAP |
 
 
 
 140	       VIRTCHNL_VF_OFFLOAD_ENCAP_CSUM |
 141	       VIRTCHNL_VF_OFFLOAD_REQ_QUEUES |
 142	       VIRTCHNL_VF_OFFLOAD_ADQ |
 143	       VIRTCHNL_VF_OFFLOAD_USO |
 144	       VIRTCHNL_VF_OFFLOAD_FDIR_PF |
 145	       VIRTCHNL_VF_OFFLOAD_ADV_RSS_PF |
 146	       VIRTCHNL_VF_CAP_ADV_LINK_SPEED;
 
 147
 148	adapter->current_op = VIRTCHNL_OP_GET_VF_RESOURCES;
 149	adapter->aq_required &= ~IAVF_FLAG_AQ_GET_CONFIG;
 150	if (PF_IS_V11(adapter))
 151		return iavf_send_pf_msg(adapter, VIRTCHNL_OP_GET_VF_RESOURCES,
 152					(u8 *)&caps, sizeof(caps));
 153	else
 154		return iavf_send_pf_msg(adapter, VIRTCHNL_OP_GET_VF_RESOURCES,
 155					NULL, 0);
 156}
 157
 
 
 
 
 
 
 
 
 
 
 
 
 
 158/**
 159 * iavf_validate_num_queues
 160 * @adapter: adapter structure
 161 *
 162 * Validate that the number of queues the PF has sent in
 163 * VIRTCHNL_OP_GET_VF_RESOURCES is not larger than the VF can handle.
 164 **/
 165static void iavf_validate_num_queues(struct iavf_adapter *adapter)
 166{
 167	if (adapter->vf_res->num_queue_pairs > IAVF_MAX_REQ_QUEUES) {
 168		struct virtchnl_vsi_resource *vsi_res;
 169		int i;
 170
 171		dev_info(&adapter->pdev->dev, "Received %d queues, but can only have a max of %d\n",
 172			 adapter->vf_res->num_queue_pairs,
 173			 IAVF_MAX_REQ_QUEUES);
 174		dev_info(&adapter->pdev->dev, "Fixing by reducing queues to %d\n",
 175			 IAVF_MAX_REQ_QUEUES);
 176		adapter->vf_res->num_queue_pairs = IAVF_MAX_REQ_QUEUES;
 177		for (i = 0; i < adapter->vf_res->num_vsis; i++) {
 178			vsi_res = &adapter->vf_res->vsi_res[i];
 179			vsi_res->num_queue_pairs = IAVF_MAX_REQ_QUEUES;
 180		}
 181	}
 182}
 183
 184/**
 185 * iavf_get_vf_config
 186 * @adapter: private adapter structure
 187 *
 188 * Get VF configuration from PF and populate hw structure. Must be called after
 189 * admin queue is initialized. Busy waits until response is received from PF,
 190 * with maximum timeout. Response from PF is returned in the buffer for further
 191 * processing by the caller.
 192 **/
 193int iavf_get_vf_config(struct iavf_adapter *adapter)
 194{
 195	struct iavf_hw *hw = &adapter->hw;
 196	struct iavf_arq_event_info event;
 197	enum virtchnl_ops op;
 198	enum iavf_status err;
 199	u16 len;
 
 200
 201	len =  sizeof(struct virtchnl_vf_resource) +
 202		IAVF_MAX_VF_VSI * sizeof(struct virtchnl_vsi_resource);
 203	event.buf_len = len;
 204	event.msg_buf = kzalloc(event.buf_len, GFP_KERNEL);
 205	if (!event.msg_buf) {
 206		err = -ENOMEM;
 207		goto out;
 208	}
 209
 210	while (1) {
 211		/* When the AQ is empty, iavf_clean_arq_element will return
 212		 * nonzero and this loop will terminate.
 213		 */
 214		err = iavf_clean_arq_element(hw, &event, NULL);
 215		if (err)
 216			goto out_alloc;
 217		op =
 218		    (enum virtchnl_ops)le32_to_cpu(event.desc.cookie_high);
 219		if (op == VIRTCHNL_OP_GET_VF_RESOURCES)
 220			break;
 221	}
 222
 223	err = (enum iavf_status)le32_to_cpu(event.desc.cookie_low);
 224	memcpy(adapter->vf_res, event.msg_buf, min(event.msg_len, len));
 225
 226	/* some PFs send more queues than we should have so validate that
 227	 * we aren't getting too many queues
 228	 */
 229	if (!err)
 230		iavf_validate_num_queues(adapter);
 231	iavf_vf_parse_hw_config(hw, adapter->vf_res);
 232out_alloc:
 233	kfree(event.msg_buf);
 234out:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 235	return err;
 236}
 237
 238/**
 239 * iavf_configure_queues
 240 * @adapter: adapter structure
 241 *
 242 * Request that the PF set up our (previously allocated) queues.
 243 **/
 244void iavf_configure_queues(struct iavf_adapter *adapter)
 245{
 246	struct virtchnl_vsi_queue_config_info *vqci;
 
 247	struct virtchnl_queue_pair_info *vqpi;
 248	int pairs = adapter->num_active_queues;
 249	int i, max_frame = IAVF_MAX_RXBUFFER;
 250	size_t len;
 251
 
 
 
 252	if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
 253		/* bail because we already have a command pending */
 254		dev_err(&adapter->pdev->dev, "Cannot configure queues, command %d pending\n",
 255			adapter->current_op);
 256		return;
 257	}
 258	adapter->current_op = VIRTCHNL_OP_CONFIG_VSI_QUEUES;
 259	len = struct_size(vqci, qpair, pairs);
 260	vqci = kzalloc(len, GFP_KERNEL);
 261	if (!vqci)
 262		return;
 263
 264	/* Limit maximum frame size when jumbo frames is not enabled */
 265	if (!(adapter->flags & IAVF_FLAG_LEGACY_RX) &&
 266	    (adapter->netdev->mtu <= ETH_DATA_LEN))
 267		max_frame = IAVF_RXBUFFER_1536 - NET_IP_ALIGN;
 268
 269	vqci->vsi_id = adapter->vsi_res->vsi_id;
 270	vqci->num_queue_pairs = pairs;
 271	vqpi = vqci->qpair;
 272	/* Size check is not needed here - HW max is 16 queue pairs, and we
 273	 * can fit info for 31 of them into the AQ buffer before it overflows.
 274	 */
 275	for (i = 0; i < pairs; i++) {
 276		vqpi->txq.vsi_id = vqci->vsi_id;
 277		vqpi->txq.queue_id = i;
 278		vqpi->txq.ring_len = adapter->tx_rings[i].count;
 279		vqpi->txq.dma_ring_addr = adapter->tx_rings[i].dma;
 280		vqpi->rxq.vsi_id = vqci->vsi_id;
 281		vqpi->rxq.queue_id = i;
 282		vqpi->rxq.ring_len = adapter->rx_rings[i].count;
 283		vqpi->rxq.dma_ring_addr = adapter->rx_rings[i].dma;
 284		vqpi->rxq.max_pkt_size = max_frame;
 285		vqpi->rxq.databuffer_size =
 286			ALIGN(adapter->rx_rings[i].rx_buf_len,
 287			      BIT_ULL(IAVF_RXQ_CTX_DBUFF_SHIFT));
 
 288		vqpi++;
 289	}
 290
 291	adapter->aq_required &= ~IAVF_FLAG_AQ_CONFIGURE_QUEUES;
 292	iavf_send_pf_msg(adapter, VIRTCHNL_OP_CONFIG_VSI_QUEUES,
 293			 (u8 *)vqci, len);
 294	kfree(vqci);
 295}
 296
 297/**
 298 * iavf_enable_queues
 299 * @adapter: adapter structure
 300 *
 301 * Request that the PF enable all of our queues.
 302 **/
 303void iavf_enable_queues(struct iavf_adapter *adapter)
 304{
 305	struct virtchnl_queue_select vqs;
 306
 307	if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
 308		/* bail because we already have a command pending */
 309		dev_err(&adapter->pdev->dev, "Cannot enable queues, command %d pending\n",
 310			adapter->current_op);
 311		return;
 312	}
 313	adapter->current_op = VIRTCHNL_OP_ENABLE_QUEUES;
 314	vqs.vsi_id = adapter->vsi_res->vsi_id;
 315	vqs.tx_queues = BIT(adapter->num_active_queues) - 1;
 316	vqs.rx_queues = vqs.tx_queues;
 317	adapter->aq_required &= ~IAVF_FLAG_AQ_ENABLE_QUEUES;
 318	iavf_send_pf_msg(adapter, VIRTCHNL_OP_ENABLE_QUEUES,
 319			 (u8 *)&vqs, sizeof(vqs));
 320}
 321
 322/**
 323 * iavf_disable_queues
 324 * @adapter: adapter structure
 325 *
 326 * Request that the PF disable all of our queues.
 327 **/
 328void iavf_disable_queues(struct iavf_adapter *adapter)
 329{
 330	struct virtchnl_queue_select vqs;
 331
 332	if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
 333		/* bail because we already have a command pending */
 334		dev_err(&adapter->pdev->dev, "Cannot disable queues, command %d pending\n",
 335			adapter->current_op);
 336		return;
 337	}
 338	adapter->current_op = VIRTCHNL_OP_DISABLE_QUEUES;
 339	vqs.vsi_id = adapter->vsi_res->vsi_id;
 340	vqs.tx_queues = BIT(adapter->num_active_queues) - 1;
 341	vqs.rx_queues = vqs.tx_queues;
 342	adapter->aq_required &= ~IAVF_FLAG_AQ_DISABLE_QUEUES;
 343	iavf_send_pf_msg(adapter, VIRTCHNL_OP_DISABLE_QUEUES,
 344			 (u8 *)&vqs, sizeof(vqs));
 345}
 346
 347/**
 348 * iavf_map_queues
 349 * @adapter: adapter structure
 350 *
 351 * Request that the PF map queues to interrupt vectors. Misc causes, including
 352 * admin queue, are always mapped to vector 0.
 353 **/
 354void iavf_map_queues(struct iavf_adapter *adapter)
 355{
 356	struct virtchnl_irq_map_info *vimi;
 357	struct virtchnl_vector_map *vecmap;
 358	struct iavf_q_vector *q_vector;
 359	int v_idx, q_vectors;
 360	size_t len;
 361
 362	if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
 363		/* bail because we already have a command pending */
 364		dev_err(&adapter->pdev->dev, "Cannot map queues to vectors, command %d pending\n",
 365			adapter->current_op);
 366		return;
 367	}
 368	adapter->current_op = VIRTCHNL_OP_CONFIG_IRQ_MAP;
 369
 370	q_vectors = adapter->num_msix_vectors - NONQ_VECS;
 371
 372	len = struct_size(vimi, vecmap, adapter->num_msix_vectors);
 373	vimi = kzalloc(len, GFP_KERNEL);
 374	if (!vimi)
 375		return;
 376
 377	vimi->num_vectors = adapter->num_msix_vectors;
 378	/* Queue vectors first */
 379	for (v_idx = 0; v_idx < q_vectors; v_idx++) {
 380		q_vector = &adapter->q_vectors[v_idx];
 381		vecmap = &vimi->vecmap[v_idx];
 382
 383		vecmap->vsi_id = adapter->vsi_res->vsi_id;
 384		vecmap->vector_id = v_idx + NONQ_VECS;
 385		vecmap->txq_map = q_vector->ring_mask;
 386		vecmap->rxq_map = q_vector->ring_mask;
 387		vecmap->rxitr_idx = IAVF_RX_ITR;
 388		vecmap->txitr_idx = IAVF_TX_ITR;
 389	}
 390	/* Misc vector last - this is only for AdminQ messages */
 391	vecmap = &vimi->vecmap[v_idx];
 392	vecmap->vsi_id = adapter->vsi_res->vsi_id;
 393	vecmap->vector_id = 0;
 394	vecmap->txq_map = 0;
 395	vecmap->rxq_map = 0;
 396
 397	adapter->aq_required &= ~IAVF_FLAG_AQ_MAP_VECTORS;
 398	iavf_send_pf_msg(adapter, VIRTCHNL_OP_CONFIG_IRQ_MAP,
 399			 (u8 *)vimi, len);
 400	kfree(vimi);
 401}
 402
 403/**
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 404 * iavf_add_ether_addrs
 405 * @adapter: adapter structure
 406 *
 407 * Request that the PF add one or more addresses to our filters.
 408 **/
 409void iavf_add_ether_addrs(struct iavf_adapter *adapter)
 410{
 411	struct virtchnl_ether_addr_list *veal;
 412	struct iavf_mac_filter *f;
 413	int i = 0, count = 0;
 414	bool more = false;
 415	size_t len;
 416
 417	if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
 418		/* bail because we already have a command pending */
 419		dev_err(&adapter->pdev->dev, "Cannot add filters, command %d pending\n",
 420			adapter->current_op);
 421		return;
 422	}
 423
 424	spin_lock_bh(&adapter->mac_vlan_list_lock);
 425
 426	list_for_each_entry(f, &adapter->mac_filter_list, list) {
 427		if (f->add)
 428			count++;
 429	}
 430	if (!count) {
 431		adapter->aq_required &= ~IAVF_FLAG_AQ_ADD_MAC_FILTER;
 432		spin_unlock_bh(&adapter->mac_vlan_list_lock);
 433		return;
 434	}
 435	adapter->current_op = VIRTCHNL_OP_ADD_ETH_ADDR;
 436
 437	len = struct_size(veal, list, count);
 438	if (len > IAVF_MAX_AQ_BUF_SIZE) {
 439		dev_warn(&adapter->pdev->dev, "Too many add MAC changes in one request\n");
 440		count = (IAVF_MAX_AQ_BUF_SIZE -
 441			 sizeof(struct virtchnl_ether_addr_list)) /
 442			sizeof(struct virtchnl_ether_addr);
 443		len = struct_size(veal, list, count);
 444		more = true;
 445	}
 446
 447	veal = kzalloc(len, GFP_ATOMIC);
 448	if (!veal) {
 449		spin_unlock_bh(&adapter->mac_vlan_list_lock);
 450		return;
 451	}
 452
 453	veal->vsi_id = adapter->vsi_res->vsi_id;
 454	veal->num_elements = count;
 455	list_for_each_entry(f, &adapter->mac_filter_list, list) {
 456		if (f->add) {
 457			ether_addr_copy(veal->list[i].addr, f->macaddr);
 
 458			i++;
 459			f->add = false;
 460			if (i == count)
 461				break;
 462		}
 463	}
 464	if (!more)
 465		adapter->aq_required &= ~IAVF_FLAG_AQ_ADD_MAC_FILTER;
 466
 467	spin_unlock_bh(&adapter->mac_vlan_list_lock);
 468
 469	iavf_send_pf_msg(adapter, VIRTCHNL_OP_ADD_ETH_ADDR, (u8 *)veal, len);
 470	kfree(veal);
 471}
 472
 473/**
 474 * iavf_del_ether_addrs
 475 * @adapter: adapter structure
 476 *
 477 * Request that the PF remove one or more addresses from our filters.
 478 **/
 479void iavf_del_ether_addrs(struct iavf_adapter *adapter)
 480{
 481	struct virtchnl_ether_addr_list *veal;
 482	struct iavf_mac_filter *f, *ftmp;
 483	int i = 0, count = 0;
 484	bool more = false;
 485	size_t len;
 486
 487	if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
 488		/* bail because we already have a command pending */
 489		dev_err(&adapter->pdev->dev, "Cannot remove filters, command %d pending\n",
 490			adapter->current_op);
 491		return;
 492	}
 493
 494	spin_lock_bh(&adapter->mac_vlan_list_lock);
 495
 496	list_for_each_entry(f, &adapter->mac_filter_list, list) {
 497		if (f->remove)
 498			count++;
 499	}
 500	if (!count) {
 501		adapter->aq_required &= ~IAVF_FLAG_AQ_DEL_MAC_FILTER;
 502		spin_unlock_bh(&adapter->mac_vlan_list_lock);
 503		return;
 504	}
 505	adapter->current_op = VIRTCHNL_OP_DEL_ETH_ADDR;
 506
 507	len = struct_size(veal, list, count);
 508	if (len > IAVF_MAX_AQ_BUF_SIZE) {
 509		dev_warn(&adapter->pdev->dev, "Too many delete MAC changes in one request\n");
 510		count = (IAVF_MAX_AQ_BUF_SIZE -
 511			 sizeof(struct virtchnl_ether_addr_list)) /
 512			sizeof(struct virtchnl_ether_addr);
 513		len = struct_size(veal, list, count);
 514		more = true;
 515	}
 516	veal = kzalloc(len, GFP_ATOMIC);
 517	if (!veal) {
 518		spin_unlock_bh(&adapter->mac_vlan_list_lock);
 519		return;
 520	}
 521
 522	veal->vsi_id = adapter->vsi_res->vsi_id;
 523	veal->num_elements = count;
 524	list_for_each_entry_safe(f, ftmp, &adapter->mac_filter_list, list) {
 525		if (f->remove) {
 526			ether_addr_copy(veal->list[i].addr, f->macaddr);
 
 527			i++;
 528			list_del(&f->list);
 529			kfree(f);
 530			if (i == count)
 531				break;
 532		}
 533	}
 534	if (!more)
 535		adapter->aq_required &= ~IAVF_FLAG_AQ_DEL_MAC_FILTER;
 536
 537	spin_unlock_bh(&adapter->mac_vlan_list_lock);
 538
 539	iavf_send_pf_msg(adapter, VIRTCHNL_OP_DEL_ETH_ADDR, (u8 *)veal, len);
 540	kfree(veal);
 541}
 542
 543/**
 544 * iavf_mac_add_ok
 545 * @adapter: adapter structure
 546 *
 547 * Submit list of filters based on PF response.
 548 **/
 549static void iavf_mac_add_ok(struct iavf_adapter *adapter)
 550{
 551	struct iavf_mac_filter *f, *ftmp;
 552
 553	spin_lock_bh(&adapter->mac_vlan_list_lock);
 554	list_for_each_entry_safe(f, ftmp, &adapter->mac_filter_list, list) {
 555		f->is_new_mac = false;
 
 
 556	}
 557	spin_unlock_bh(&adapter->mac_vlan_list_lock);
 558}
 559
 560/**
 561 * iavf_mac_add_reject
 562 * @adapter: adapter structure
 563 *
 564 * Remove filters from list based on PF response.
 565 **/
 566static void iavf_mac_add_reject(struct iavf_adapter *adapter)
 567{
 568	struct net_device *netdev = adapter->netdev;
 569	struct iavf_mac_filter *f, *ftmp;
 570
 571	spin_lock_bh(&adapter->mac_vlan_list_lock);
 572	list_for_each_entry_safe(f, ftmp, &adapter->mac_filter_list, list) {
 573		if (f->remove && ether_addr_equal(f->macaddr, netdev->dev_addr))
 574			f->remove = false;
 575
 
 
 
 576		if (f->is_new_mac) {
 577			list_del(&f->list);
 578			kfree(f);
 579		}
 580	}
 581	spin_unlock_bh(&adapter->mac_vlan_list_lock);
 582}
 583
 584/**
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 585 * iavf_add_vlans
 586 * @adapter: adapter structure
 587 *
 588 * Request that the PF add one or more VLAN filters to our VSI.
 589 **/
 590void iavf_add_vlans(struct iavf_adapter *adapter)
 591{
 592	struct virtchnl_vlan_filter_list *vvfl;
 593	int len, i = 0, count = 0;
 594	struct iavf_vlan_filter *f;
 595	bool more = false;
 596
 597	if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
 598		/* bail because we already have a command pending */
 599		dev_err(&adapter->pdev->dev, "Cannot add VLANs, command %d pending\n",
 600			adapter->current_op);
 601		return;
 602	}
 603
 604	spin_lock_bh(&adapter->mac_vlan_list_lock);
 605
 606	list_for_each_entry(f, &adapter->vlan_filter_list, list) {
 607		if (f->add)
 608			count++;
 609	}
 610	if (!count) {
 611		adapter->aq_required &= ~IAVF_FLAG_AQ_ADD_VLAN_FILTER;
 612		spin_unlock_bh(&adapter->mac_vlan_list_lock);
 613		return;
 614	}
 615	adapter->current_op = VIRTCHNL_OP_ADD_VLAN;
 616
 617	len = sizeof(struct virtchnl_vlan_filter_list) +
 618	      (count * sizeof(u16));
 619	if (len > IAVF_MAX_AQ_BUF_SIZE) {
 620		dev_warn(&adapter->pdev->dev, "Too many add VLAN changes in one request\n");
 621		count = (IAVF_MAX_AQ_BUF_SIZE -
 622			 sizeof(struct virtchnl_vlan_filter_list)) /
 623			sizeof(u16);
 624		len = sizeof(struct virtchnl_vlan_filter_list) +
 625		      (count * sizeof(u16));
 626		more = true;
 627	}
 628	vvfl = kzalloc(len, GFP_ATOMIC);
 629	if (!vvfl) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 630		spin_unlock_bh(&adapter->mac_vlan_list_lock);
 631		return;
 632	}
 633
 634	vvfl->vsi_id = adapter->vsi_res->vsi_id;
 635	vvfl->num_elements = count;
 636	list_for_each_entry(f, &adapter->vlan_filter_list, list) {
 637		if (f->add) {
 638			vvfl->vlan_id[i] = f->vlan;
 639			i++;
 640			f->add = false;
 641			if (i == count)
 642				break;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 643		}
 644	}
 645	if (!more)
 646		adapter->aq_required &= ~IAVF_FLAG_AQ_ADD_VLAN_FILTER;
 647
 648	spin_unlock_bh(&adapter->mac_vlan_list_lock);
 
 
 
 649
 650	iavf_send_pf_msg(adapter, VIRTCHNL_OP_ADD_VLAN, (u8 *)vvfl, len);
 651	kfree(vvfl);
 
 
 652}
 653
 654/**
 655 * iavf_del_vlans
 656 * @adapter: adapter structure
 657 *
 658 * Request that the PF remove one or more VLAN filters from our VSI.
 659 **/
 660void iavf_del_vlans(struct iavf_adapter *adapter)
 661{
 662	struct virtchnl_vlan_filter_list *vvfl;
 663	struct iavf_vlan_filter *f, *ftmp;
 664	int len, i = 0, count = 0;
 665	bool more = false;
 666
 667	if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
 668		/* bail because we already have a command pending */
 669		dev_err(&adapter->pdev->dev, "Cannot remove VLANs, command %d pending\n",
 670			adapter->current_op);
 671		return;
 672	}
 673
 674	spin_lock_bh(&adapter->mac_vlan_list_lock);
 675
 676	list_for_each_entry(f, &adapter->vlan_filter_list, list) {
 677		if (f->remove)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 678			count++;
 
 679	}
 680	if (!count) {
 681		adapter->aq_required &= ~IAVF_FLAG_AQ_DEL_VLAN_FILTER;
 682		spin_unlock_bh(&adapter->mac_vlan_list_lock);
 683		return;
 684	}
 685	adapter->current_op = VIRTCHNL_OP_DEL_VLAN;
 686
 687	len = sizeof(struct virtchnl_vlan_filter_list) +
 688	      (count * sizeof(u16));
 689	if (len > IAVF_MAX_AQ_BUF_SIZE) {
 690		dev_warn(&adapter->pdev->dev, "Too many delete VLAN changes in one request\n");
 691		count = (IAVF_MAX_AQ_BUF_SIZE -
 692			 sizeof(struct virtchnl_vlan_filter_list)) /
 693			sizeof(u16);
 694		len = sizeof(struct virtchnl_vlan_filter_list) +
 695		      (count * sizeof(u16));
 696		more = true;
 697	}
 698	vvfl = kzalloc(len, GFP_ATOMIC);
 699	if (!vvfl) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 700		spin_unlock_bh(&adapter->mac_vlan_list_lock);
 701		return;
 702	}
 703
 704	vvfl->vsi_id = adapter->vsi_res->vsi_id;
 705	vvfl->num_elements = count;
 706	list_for_each_entry_safe(f, ftmp, &adapter->vlan_filter_list, list) {
 707		if (f->remove) {
 708			vvfl->vlan_id[i] = f->vlan;
 709			i++;
 710			list_del(&f->list);
 711			kfree(f);
 712			if (i == count)
 713				break;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 714		}
 715	}
 716	if (!more)
 717		adapter->aq_required &= ~IAVF_FLAG_AQ_DEL_VLAN_FILTER;
 718
 719	spin_unlock_bh(&adapter->mac_vlan_list_lock);
 
 
 
 720
 721	iavf_send_pf_msg(adapter, VIRTCHNL_OP_DEL_VLAN, (u8 *)vvfl, len);
 722	kfree(vvfl);
 
 
 723}
 724
 725/**
 726 * iavf_set_promiscuous
 727 * @adapter: adapter structure
 728 * @flags: bitmask to control unicast/multicast promiscuous.
 729 *
 730 * Request that the PF enable promiscuous mode for our VSI.
 731 **/
 732void iavf_set_promiscuous(struct iavf_adapter *adapter, int flags)
 733{
 
 734	struct virtchnl_promisc_info vpi;
 735	int promisc_all;
 736
 737	if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
 738		/* bail because we already have a command pending */
 739		dev_err(&adapter->pdev->dev, "Cannot set promiscuous mode, command %d pending\n",
 740			adapter->current_op);
 741		return;
 742	}
 743
 744	promisc_all = FLAG_VF_UNICAST_PROMISC |
 745		      FLAG_VF_MULTICAST_PROMISC;
 746	if ((flags & promisc_all) == promisc_all) {
 747		adapter->flags |= IAVF_FLAG_PROMISC_ON;
 748		adapter->aq_required &= ~IAVF_FLAG_AQ_REQUEST_PROMISC;
 749		dev_info(&adapter->pdev->dev, "Entering promiscuous mode\n");
 
 
 
 
 750	}
 751
 752	if (flags & FLAG_VF_MULTICAST_PROMISC) {
 753		adapter->flags |= IAVF_FLAG_ALLMULTI_ON;
 754		adapter->aq_required &= ~IAVF_FLAG_AQ_REQUEST_ALLMULTI;
 
 
 
 
 
 
 755		dev_info(&adapter->pdev->dev, "Entering multicast promiscuous mode\n");
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 756	}
 757
 758	if (!flags) {
 759		adapter->flags &= ~(IAVF_FLAG_PROMISC_ON |
 760				    IAVF_FLAG_ALLMULTI_ON);
 761		adapter->aq_required &= ~(IAVF_FLAG_AQ_RELEASE_PROMISC |
 762					  IAVF_FLAG_AQ_RELEASE_ALLMULTI);
 763		dev_info(&adapter->pdev->dev, "Leaving promiscuous mode\n");
 764	}
 765
 766	adapter->current_op = VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE;
 767	vpi.vsi_id = adapter->vsi_res->vsi_id;
 768	vpi.flags = flags;
 769	iavf_send_pf_msg(adapter, VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE,
 770			 (u8 *)&vpi, sizeof(vpi));
 771}
 772
 773/**
 774 * iavf_request_stats
 775 * @adapter: adapter structure
 776 *
 777 * Request VSI statistics from PF.
 778 **/
 779void iavf_request_stats(struct iavf_adapter *adapter)
 780{
 781	struct virtchnl_queue_select vqs;
 782
 783	if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
 784		/* no error message, this isn't crucial */
 785		return;
 786	}
 
 
 787	adapter->current_op = VIRTCHNL_OP_GET_STATS;
 788	vqs.vsi_id = adapter->vsi_res->vsi_id;
 789	/* queue maps are ignored for this message - only the vsi is used */
 790	if (iavf_send_pf_msg(adapter, VIRTCHNL_OP_GET_STATS, (u8 *)&vqs,
 791			     sizeof(vqs)))
 792		/* if the request failed, don't lock out others */
 793		adapter->current_op = VIRTCHNL_OP_UNKNOWN;
 794}
 795
 796/**
 797 * iavf_get_hena
 798 * @adapter: adapter structure
 799 *
 800 * Request hash enable capabilities from PF
 801 **/
 802void iavf_get_hena(struct iavf_adapter *adapter)
 803{
 804	if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
 805		/* bail because we already have a command pending */
 806		dev_err(&adapter->pdev->dev, "Cannot get RSS hash capabilities, command %d pending\n",
 807			adapter->current_op);
 808		return;
 809	}
 810	adapter->current_op = VIRTCHNL_OP_GET_RSS_HENA_CAPS;
 811	adapter->aq_required &= ~IAVF_FLAG_AQ_GET_HENA;
 812	iavf_send_pf_msg(adapter, VIRTCHNL_OP_GET_RSS_HENA_CAPS, NULL, 0);
 813}
 814
 815/**
 816 * iavf_set_hena
 817 * @adapter: adapter structure
 818 *
 819 * Request the PF to set our RSS hash capabilities
 820 **/
 821void iavf_set_hena(struct iavf_adapter *adapter)
 822{
 823	struct virtchnl_rss_hena vrh;
 824
 825	if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
 826		/* bail because we already have a command pending */
 827		dev_err(&adapter->pdev->dev, "Cannot set RSS hash enable, command %d pending\n",
 828			adapter->current_op);
 829		return;
 830	}
 831	vrh.hena = adapter->hena;
 832	adapter->current_op = VIRTCHNL_OP_SET_RSS_HENA;
 833	adapter->aq_required &= ~IAVF_FLAG_AQ_SET_HENA;
 834	iavf_send_pf_msg(adapter, VIRTCHNL_OP_SET_RSS_HENA, (u8 *)&vrh,
 835			 sizeof(vrh));
 836}
 837
 838/**
 839 * iavf_set_rss_key
 840 * @adapter: adapter structure
 841 *
 842 * Request the PF to set our RSS hash key
 843 **/
 844void iavf_set_rss_key(struct iavf_adapter *adapter)
 845{
 846	struct virtchnl_rss_key *vrk;
 847	int len;
 848
 849	if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
 850		/* bail because we already have a command pending */
 851		dev_err(&adapter->pdev->dev, "Cannot set RSS key, command %d pending\n",
 852			adapter->current_op);
 853		return;
 854	}
 855	len = sizeof(struct virtchnl_rss_key) +
 856	      (adapter->rss_key_size * sizeof(u8)) - 1;
 857	vrk = kzalloc(len, GFP_KERNEL);
 858	if (!vrk)
 859		return;
 860	vrk->vsi_id = adapter->vsi.id;
 861	vrk->key_len = adapter->rss_key_size;
 862	memcpy(vrk->key, adapter->rss_key, adapter->rss_key_size);
 863
 864	adapter->current_op = VIRTCHNL_OP_CONFIG_RSS_KEY;
 865	adapter->aq_required &= ~IAVF_FLAG_AQ_SET_RSS_KEY;
 866	iavf_send_pf_msg(adapter, VIRTCHNL_OP_CONFIG_RSS_KEY, (u8 *)vrk, len);
 867	kfree(vrk);
 868}
 869
 870/**
 871 * iavf_set_rss_lut
 872 * @adapter: adapter structure
 873 *
 874 * Request the PF to set our RSS lookup table
 875 **/
 876void iavf_set_rss_lut(struct iavf_adapter *adapter)
 877{
 878	struct virtchnl_rss_lut *vrl;
 879	int len;
 880
 881	if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
 882		/* bail because we already have a command pending */
 883		dev_err(&adapter->pdev->dev, "Cannot set RSS LUT, command %d pending\n",
 884			adapter->current_op);
 885		return;
 886	}
 887	len = sizeof(struct virtchnl_rss_lut) +
 888	      (adapter->rss_lut_size * sizeof(u8)) - 1;
 889	vrl = kzalloc(len, GFP_KERNEL);
 890	if (!vrl)
 891		return;
 892	vrl->vsi_id = adapter->vsi.id;
 893	vrl->lut_entries = adapter->rss_lut_size;
 894	memcpy(vrl->lut, adapter->rss_lut, adapter->rss_lut_size);
 895	adapter->current_op = VIRTCHNL_OP_CONFIG_RSS_LUT;
 896	adapter->aq_required &= ~IAVF_FLAG_AQ_SET_RSS_LUT;
 897	iavf_send_pf_msg(adapter, VIRTCHNL_OP_CONFIG_RSS_LUT, (u8 *)vrl, len);
 898	kfree(vrl);
 899}
 900
 901/**
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 902 * iavf_enable_vlan_stripping
 903 * @adapter: adapter structure
 904 *
 905 * Request VLAN header stripping to be enabled
 906 **/
 907void iavf_enable_vlan_stripping(struct iavf_adapter *adapter)
 908{
 909	if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
 910		/* bail because we already have a command pending */
 911		dev_err(&adapter->pdev->dev, "Cannot enable stripping, command %d pending\n",
 912			adapter->current_op);
 913		return;
 914	}
 915	adapter->current_op = VIRTCHNL_OP_ENABLE_VLAN_STRIPPING;
 916	adapter->aq_required &= ~IAVF_FLAG_AQ_ENABLE_VLAN_STRIPPING;
 917	iavf_send_pf_msg(adapter, VIRTCHNL_OP_ENABLE_VLAN_STRIPPING, NULL, 0);
 918}
 919
 920/**
 921 * iavf_disable_vlan_stripping
 922 * @adapter: adapter structure
 923 *
 924 * Request VLAN header stripping to be disabled
 925 **/
 926void iavf_disable_vlan_stripping(struct iavf_adapter *adapter)
 927{
 928	if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
 929		/* bail because we already have a command pending */
 930		dev_err(&adapter->pdev->dev, "Cannot disable stripping, command %d pending\n",
 931			adapter->current_op);
 932		return;
 933	}
 934	adapter->current_op = VIRTCHNL_OP_DISABLE_VLAN_STRIPPING;
 935	adapter->aq_required &= ~IAVF_FLAG_AQ_DISABLE_VLAN_STRIPPING;
 936	iavf_send_pf_msg(adapter, VIRTCHNL_OP_DISABLE_VLAN_STRIPPING, NULL, 0);
 937}
 938
 939#define IAVF_MAX_SPEED_STRLEN	13
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 940
 941/**
 942 * iavf_print_link_message - print link up or down
 943 * @adapter: adapter structure
 944 *
 945 * Log a message telling the world of our wonderous link status
 946 */
 947static void iavf_print_link_message(struct iavf_adapter *adapter)
 948{
 949	struct net_device *netdev = adapter->netdev;
 950	int link_speed_mbps;
 951	char *speed;
 952
 953	if (!adapter->link_up) {
 954		netdev_info(netdev, "NIC Link is Down\n");
 955		return;
 956	}
 957
 958	speed = kzalloc(IAVF_MAX_SPEED_STRLEN, GFP_KERNEL);
 959	if (!speed)
 960		return;
 961
 962	if (ADV_LINK_SUPPORT(adapter)) {
 963		link_speed_mbps = adapter->link_speed_mbps;
 964		goto print_link_msg;
 965	}
 966
 967	switch (adapter->link_speed) {
 968	case VIRTCHNL_LINK_SPEED_40GB:
 969		link_speed_mbps = SPEED_40000;
 970		break;
 971	case VIRTCHNL_LINK_SPEED_25GB:
 972		link_speed_mbps = SPEED_25000;
 973		break;
 974	case VIRTCHNL_LINK_SPEED_20GB:
 975		link_speed_mbps = SPEED_20000;
 976		break;
 977	case VIRTCHNL_LINK_SPEED_10GB:
 978		link_speed_mbps = SPEED_10000;
 979		break;
 980	case VIRTCHNL_LINK_SPEED_5GB:
 981		link_speed_mbps = SPEED_5000;
 982		break;
 983	case VIRTCHNL_LINK_SPEED_2_5GB:
 984		link_speed_mbps = SPEED_2500;
 985		break;
 986	case VIRTCHNL_LINK_SPEED_1GB:
 987		link_speed_mbps = SPEED_1000;
 988		break;
 989	case VIRTCHNL_LINK_SPEED_100MB:
 990		link_speed_mbps = SPEED_100;
 991		break;
 992	default:
 993		link_speed_mbps = SPEED_UNKNOWN;
 994		break;
 995	}
 996
 997print_link_msg:
 998	if (link_speed_mbps > SPEED_1000) {
 999		if (link_speed_mbps == SPEED_2500)
1000			snprintf(speed, IAVF_MAX_SPEED_STRLEN, "2.5 Gbps");
1001		else
1002			/* convert to Gbps inline */
1003			snprintf(speed, IAVF_MAX_SPEED_STRLEN, "%d %s",
1004				 link_speed_mbps / 1000, "Gbps");
 
1005	} else if (link_speed_mbps == SPEED_UNKNOWN) {
1006		snprintf(speed, IAVF_MAX_SPEED_STRLEN, "%s", "Unknown Mbps");
1007	} else {
1008		snprintf(speed, IAVF_MAX_SPEED_STRLEN, "%u %s",
1009			 link_speed_mbps, "Mbps");
1010	}
1011
1012	netdev_info(netdev, "NIC Link is Up Speed is %s Full Duplex\n", speed);
1013	kfree(speed);
1014}
1015
1016/**
1017 * iavf_get_vpe_link_status
1018 * @adapter: adapter structure
1019 * @vpe: virtchnl_pf_event structure
1020 *
1021 * Helper function for determining the link status
1022 **/
1023static bool
1024iavf_get_vpe_link_status(struct iavf_adapter *adapter,
1025			 struct virtchnl_pf_event *vpe)
1026{
1027	if (ADV_LINK_SUPPORT(adapter))
1028		return vpe->event_data.link_event_adv.link_status;
1029	else
1030		return vpe->event_data.link_event.link_status;
1031}
1032
1033/**
1034 * iavf_set_adapter_link_speed_from_vpe
1035 * @adapter: adapter structure for which we are setting the link speed
1036 * @vpe: virtchnl_pf_event structure that contains the link speed we are setting
1037 *
1038 * Helper function for setting iavf_adapter link speed
1039 **/
1040static void
1041iavf_set_adapter_link_speed_from_vpe(struct iavf_adapter *adapter,
1042				     struct virtchnl_pf_event *vpe)
1043{
1044	if (ADV_LINK_SUPPORT(adapter))
1045		adapter->link_speed_mbps =
1046			vpe->event_data.link_event_adv.link_speed;
1047	else
1048		adapter->link_speed = vpe->event_data.link_event.link_speed;
1049}
1050
1051/**
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1052 * iavf_enable_channels
1053 * @adapter: adapter structure
1054 *
1055 * Request that the PF enable channels as specified by
1056 * the user via tc tool.
1057 **/
1058void iavf_enable_channels(struct iavf_adapter *adapter)
1059{
1060	struct virtchnl_tc_info *vti = NULL;
1061	size_t len;
1062	int i;
1063
1064	if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
1065		/* bail because we already have a command pending */
1066		dev_err(&adapter->pdev->dev, "Cannot configure mqprio, command %d pending\n",
1067			adapter->current_op);
1068		return;
1069	}
1070
1071	len = struct_size(vti, list, adapter->num_tc - 1);
1072	vti = kzalloc(len, GFP_KERNEL);
1073	if (!vti)
1074		return;
1075	vti->num_tc = adapter->num_tc;
1076	for (i = 0; i < vti->num_tc; i++) {
1077		vti->list[i].count = adapter->ch_config.ch_info[i].count;
1078		vti->list[i].offset = adapter->ch_config.ch_info[i].offset;
1079		vti->list[i].pad = 0;
1080		vti->list[i].max_tx_rate =
1081				adapter->ch_config.ch_info[i].max_tx_rate;
1082	}
1083
1084	adapter->ch_config.state = __IAVF_TC_RUNNING;
1085	adapter->flags |= IAVF_FLAG_REINIT_ITR_NEEDED;
1086	adapter->current_op = VIRTCHNL_OP_ENABLE_CHANNELS;
1087	adapter->aq_required &= ~IAVF_FLAG_AQ_ENABLE_CHANNELS;
1088	iavf_send_pf_msg(adapter, VIRTCHNL_OP_ENABLE_CHANNELS, (u8 *)vti, len);
1089	kfree(vti);
1090}
1091
1092/**
1093 * iavf_disable_channels
1094 * @adapter: adapter structure
1095 *
1096 * Request that the PF disable channels that are configured
1097 **/
1098void iavf_disable_channels(struct iavf_adapter *adapter)
1099{
1100	if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
1101		/* bail because we already have a command pending */
1102		dev_err(&adapter->pdev->dev, "Cannot configure mqprio, command %d pending\n",
1103			adapter->current_op);
1104		return;
1105	}
1106
1107	adapter->ch_config.state = __IAVF_TC_INVALID;
1108	adapter->flags |= IAVF_FLAG_REINIT_ITR_NEEDED;
1109	adapter->current_op = VIRTCHNL_OP_DISABLE_CHANNELS;
1110	adapter->aq_required &= ~IAVF_FLAG_AQ_DISABLE_CHANNELS;
1111	iavf_send_pf_msg(adapter, VIRTCHNL_OP_DISABLE_CHANNELS, NULL, 0);
1112}
1113
1114/**
1115 * iavf_print_cloud_filter
1116 * @adapter: adapter structure
1117 * @f: cloud filter to print
1118 *
1119 * Print the cloud filter
1120 **/
1121static void iavf_print_cloud_filter(struct iavf_adapter *adapter,
1122				    struct virtchnl_filter *f)
1123{
1124	switch (f->flow_type) {
1125	case VIRTCHNL_TCP_V4_FLOW:
1126		dev_info(&adapter->pdev->dev, "dst_mac: %pM src_mac: %pM vlan_id: %hu dst_ip: %pI4 src_ip %pI4 dst_port %hu src_port %hu\n",
1127			 &f->data.tcp_spec.dst_mac,
1128			 &f->data.tcp_spec.src_mac,
1129			 ntohs(f->data.tcp_spec.vlan_id),
1130			 &f->data.tcp_spec.dst_ip[0],
1131			 &f->data.tcp_spec.src_ip[0],
1132			 ntohs(f->data.tcp_spec.dst_port),
1133			 ntohs(f->data.tcp_spec.src_port));
1134		break;
1135	case VIRTCHNL_TCP_V6_FLOW:
1136		dev_info(&adapter->pdev->dev, "dst_mac: %pM src_mac: %pM vlan_id: %hu dst_ip: %pI6 src_ip %pI6 dst_port %hu src_port %hu\n",
1137			 &f->data.tcp_spec.dst_mac,
1138			 &f->data.tcp_spec.src_mac,
1139			 ntohs(f->data.tcp_spec.vlan_id),
1140			 &f->data.tcp_spec.dst_ip,
1141			 &f->data.tcp_spec.src_ip,
1142			 ntohs(f->data.tcp_spec.dst_port),
1143			 ntohs(f->data.tcp_spec.src_port));
1144		break;
1145	}
1146}
1147
1148/**
1149 * iavf_add_cloud_filter
1150 * @adapter: adapter structure
1151 *
1152 * Request that the PF add cloud filters as specified
1153 * by the user via tc tool.
1154 **/
1155void iavf_add_cloud_filter(struct iavf_adapter *adapter)
1156{
1157	struct iavf_cloud_filter *cf;
1158	struct virtchnl_filter *f;
1159	int len = 0, count = 0;
1160
1161	if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
1162		/* bail because we already have a command pending */
1163		dev_err(&adapter->pdev->dev, "Cannot add cloud filter, command %d pending\n",
1164			adapter->current_op);
1165		return;
1166	}
1167	list_for_each_entry(cf, &adapter->cloud_filter_list, list) {
1168		if (cf->add) {
1169			count++;
1170			break;
1171		}
1172	}
1173	if (!count) {
1174		adapter->aq_required &= ~IAVF_FLAG_AQ_ADD_CLOUD_FILTER;
1175		return;
1176	}
1177	adapter->current_op = VIRTCHNL_OP_ADD_CLOUD_FILTER;
1178
1179	len = sizeof(struct virtchnl_filter);
1180	f = kzalloc(len, GFP_KERNEL);
1181	if (!f)
1182		return;
1183
1184	list_for_each_entry(cf, &adapter->cloud_filter_list, list) {
1185		if (cf->add) {
1186			memcpy(f, &cf->f, sizeof(struct virtchnl_filter));
1187			cf->add = false;
1188			cf->state = __IAVF_CF_ADD_PENDING;
1189			iavf_send_pf_msg(adapter, VIRTCHNL_OP_ADD_CLOUD_FILTER,
1190					 (u8 *)f, len);
1191		}
1192	}
1193	kfree(f);
1194}
1195
1196/**
1197 * iavf_del_cloud_filter
1198 * @adapter: adapter structure
1199 *
1200 * Request that the PF delete cloud filters as specified
1201 * by the user via tc tool.
1202 **/
1203void iavf_del_cloud_filter(struct iavf_adapter *adapter)
1204{
1205	struct iavf_cloud_filter *cf, *cftmp;
1206	struct virtchnl_filter *f;
1207	int len = 0, count = 0;
1208
1209	if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
1210		/* bail because we already have a command pending */
1211		dev_err(&adapter->pdev->dev, "Cannot remove cloud filter, command %d pending\n",
1212			adapter->current_op);
1213		return;
1214	}
1215	list_for_each_entry(cf, &adapter->cloud_filter_list, list) {
1216		if (cf->del) {
1217			count++;
1218			break;
1219		}
1220	}
1221	if (!count) {
1222		adapter->aq_required &= ~IAVF_FLAG_AQ_DEL_CLOUD_FILTER;
1223		return;
1224	}
1225	adapter->current_op = VIRTCHNL_OP_DEL_CLOUD_FILTER;
1226
1227	len = sizeof(struct virtchnl_filter);
1228	f = kzalloc(len, GFP_KERNEL);
1229	if (!f)
1230		return;
1231
1232	list_for_each_entry_safe(cf, cftmp, &adapter->cloud_filter_list, list) {
1233		if (cf->del) {
1234			memcpy(f, &cf->f, sizeof(struct virtchnl_filter));
1235			cf->del = false;
1236			cf->state = __IAVF_CF_DEL_PENDING;
1237			iavf_send_pf_msg(adapter, VIRTCHNL_OP_DEL_CLOUD_FILTER,
1238					 (u8 *)f, len);
1239		}
1240	}
1241	kfree(f);
1242}
1243
1244/**
1245 * iavf_add_fdir_filter
1246 * @adapter: the VF adapter structure
1247 *
1248 * Request that the PF add Flow Director filters as specified
1249 * by the user via ethtool.
1250 **/
1251void iavf_add_fdir_filter(struct iavf_adapter *adapter)
1252{
1253	struct iavf_fdir_fltr *fdir;
1254	struct virtchnl_fdir_add *f;
1255	bool process_fltr = false;
1256	int len;
1257
1258	if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
1259		/* bail because we already have a command pending */
1260		dev_err(&adapter->pdev->dev, "Cannot add Flow Director filter, command %d pending\n",
1261			adapter->current_op);
1262		return;
1263	}
1264
1265	len = sizeof(struct virtchnl_fdir_add);
1266	f = kzalloc(len, GFP_KERNEL);
1267	if (!f)
1268		return;
1269
1270	spin_lock_bh(&adapter->fdir_fltr_lock);
1271	list_for_each_entry(fdir, &adapter->fdir_list_head, list) {
1272		if (fdir->state == IAVF_FDIR_FLTR_ADD_REQUEST) {
1273			process_fltr = true;
1274			fdir->state = IAVF_FDIR_FLTR_ADD_PENDING;
1275			memcpy(f, &fdir->vc_add_msg, len);
1276			break;
1277		}
1278	}
1279	spin_unlock_bh(&adapter->fdir_fltr_lock);
1280
1281	if (!process_fltr) {
1282		/* prevent iavf_add_fdir_filter() from being called when there
1283		 * are no filters to add
1284		 */
1285		adapter->aq_required &= ~IAVF_FLAG_AQ_ADD_FDIR_FILTER;
1286		kfree(f);
1287		return;
1288	}
1289	adapter->current_op = VIRTCHNL_OP_ADD_FDIR_FILTER;
1290	iavf_send_pf_msg(adapter, VIRTCHNL_OP_ADD_FDIR_FILTER, (u8 *)f, len);
1291	kfree(f);
1292}
1293
1294/**
1295 * iavf_del_fdir_filter
1296 * @adapter: the VF adapter structure
1297 *
1298 * Request that the PF delete Flow Director filters as specified
1299 * by the user via ethtool.
1300 **/
1301void iavf_del_fdir_filter(struct iavf_adapter *adapter)
1302{
 
1303	struct iavf_fdir_fltr *fdir;
1304	struct virtchnl_fdir_del f;
1305	bool process_fltr = false;
1306	int len;
1307
1308	if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
1309		/* bail because we already have a command pending */
1310		dev_err(&adapter->pdev->dev, "Cannot remove Flow Director filter, command %d pending\n",
1311			adapter->current_op);
1312		return;
1313	}
1314
1315	len = sizeof(struct virtchnl_fdir_del);
1316
1317	spin_lock_bh(&adapter->fdir_fltr_lock);
1318	list_for_each_entry(fdir, &adapter->fdir_list_head, list) {
1319		if (fdir->state == IAVF_FDIR_FLTR_DEL_REQUEST) {
1320			process_fltr = true;
1321			memset(&f, 0, len);
1322			f.vsi_id = fdir->vc_add_msg.vsi_id;
1323			f.flow_id = fdir->flow_id;
1324			fdir->state = IAVF_FDIR_FLTR_DEL_PENDING;
1325			break;
 
 
 
 
 
 
1326		}
1327	}
1328	spin_unlock_bh(&adapter->fdir_fltr_lock);
1329
1330	if (!process_fltr) {
1331		adapter->aq_required &= ~IAVF_FLAG_AQ_DEL_FDIR_FILTER;
1332		return;
1333	}
1334
1335	adapter->current_op = VIRTCHNL_OP_DEL_FDIR_FILTER;
1336	iavf_send_pf_msg(adapter, VIRTCHNL_OP_DEL_FDIR_FILTER, (u8 *)&f, len);
1337}
1338
1339/**
1340 * iavf_add_adv_rss_cfg
1341 * @adapter: the VF adapter structure
1342 *
1343 * Request that the PF add RSS configuration as specified
1344 * by the user via ethtool.
1345 **/
1346void iavf_add_adv_rss_cfg(struct iavf_adapter *adapter)
1347{
1348	struct virtchnl_rss_cfg *rss_cfg;
1349	struct iavf_adv_rss *rss;
1350	bool process_rss = false;
1351	int len;
1352
1353	if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
1354		/* bail because we already have a command pending */
1355		dev_err(&adapter->pdev->dev, "Cannot add RSS configuration, command %d pending\n",
1356			adapter->current_op);
1357		return;
1358	}
1359
1360	len = sizeof(struct virtchnl_rss_cfg);
1361	rss_cfg = kzalloc(len, GFP_KERNEL);
1362	if (!rss_cfg)
1363		return;
1364
1365	spin_lock_bh(&adapter->adv_rss_lock);
1366	list_for_each_entry(rss, &adapter->adv_rss_list_head, list) {
1367		if (rss->state == IAVF_ADV_RSS_ADD_REQUEST) {
1368			process_rss = true;
1369			rss->state = IAVF_ADV_RSS_ADD_PENDING;
1370			memcpy(rss_cfg, &rss->cfg_msg, len);
1371			iavf_print_adv_rss_cfg(adapter, rss,
1372					       "Input set change for",
1373					       "is pending");
1374			break;
1375		}
1376	}
1377	spin_unlock_bh(&adapter->adv_rss_lock);
1378
1379	if (process_rss) {
1380		adapter->current_op = VIRTCHNL_OP_ADD_RSS_CFG;
1381		iavf_send_pf_msg(adapter, VIRTCHNL_OP_ADD_RSS_CFG,
1382				 (u8 *)rss_cfg, len);
1383	} else {
1384		adapter->aq_required &= ~IAVF_FLAG_AQ_ADD_ADV_RSS_CFG;
1385	}
1386
1387	kfree(rss_cfg);
1388}
1389
1390/**
1391 * iavf_del_adv_rss_cfg
1392 * @adapter: the VF adapter structure
1393 *
1394 * Request that the PF delete RSS configuration as specified
1395 * by the user via ethtool.
1396 **/
1397void iavf_del_adv_rss_cfg(struct iavf_adapter *adapter)
1398{
1399	struct virtchnl_rss_cfg *rss_cfg;
1400	struct iavf_adv_rss *rss;
1401	bool process_rss = false;
1402	int len;
1403
1404	if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
1405		/* bail because we already have a command pending */
1406		dev_err(&adapter->pdev->dev, "Cannot remove RSS configuration, command %d pending\n",
1407			adapter->current_op);
1408		return;
1409	}
1410
1411	len = sizeof(struct virtchnl_rss_cfg);
1412	rss_cfg = kzalloc(len, GFP_KERNEL);
1413	if (!rss_cfg)
1414		return;
1415
1416	spin_lock_bh(&adapter->adv_rss_lock);
1417	list_for_each_entry(rss, &adapter->adv_rss_list_head, list) {
1418		if (rss->state == IAVF_ADV_RSS_DEL_REQUEST) {
1419			process_rss = true;
1420			rss->state = IAVF_ADV_RSS_DEL_PENDING;
1421			memcpy(rss_cfg, &rss->cfg_msg, len);
1422			break;
1423		}
1424	}
1425	spin_unlock_bh(&adapter->adv_rss_lock);
1426
1427	if (process_rss) {
1428		adapter->current_op = VIRTCHNL_OP_DEL_RSS_CFG;
1429		iavf_send_pf_msg(adapter, VIRTCHNL_OP_DEL_RSS_CFG,
1430				 (u8 *)rss_cfg, len);
1431	} else {
1432		adapter->aq_required &= ~IAVF_FLAG_AQ_DEL_ADV_RSS_CFG;
1433	}
1434
1435	kfree(rss_cfg);
1436}
1437
1438/**
1439 * iavf_request_reset
1440 * @adapter: adapter structure
1441 *
1442 * Request that the PF reset this VF. No response is expected.
1443 **/
1444void iavf_request_reset(struct iavf_adapter *adapter)
1445{
 
1446	/* Don't check CURRENT_OP - this is always higher priority */
1447	iavf_send_pf_msg(adapter, VIRTCHNL_OP_RESET_VF, NULL, 0);
1448	adapter->current_op = VIRTCHNL_OP_UNKNOWN;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1449}
1450
1451/**
1452 * iavf_virtchnl_completion
1453 * @adapter: adapter structure
1454 * @v_opcode: opcode sent by PF
1455 * @v_retval: retval sent by PF
1456 * @msg: message sent by PF
1457 * @msglen: message length
1458 *
1459 * Asynchronous completion function for admin queue messages. Rather than busy
1460 * wait, we fire off our requests and assume that no errors will be returned.
1461 * This function handles the reply messages.
1462 **/
1463void iavf_virtchnl_completion(struct iavf_adapter *adapter,
1464			      enum virtchnl_ops v_opcode,
1465			      enum iavf_status v_retval, u8 *msg, u16 msglen)
1466{
1467	struct net_device *netdev = adapter->netdev;
1468
1469	if (v_opcode == VIRTCHNL_OP_EVENT) {
1470		struct virtchnl_pf_event *vpe =
1471			(struct virtchnl_pf_event *)msg;
1472		bool link_up = iavf_get_vpe_link_status(adapter, vpe);
1473
1474		switch (vpe->event) {
1475		case VIRTCHNL_EVENT_LINK_CHANGE:
1476			iavf_set_adapter_link_speed_from_vpe(adapter, vpe);
1477
1478			/* we've already got the right link status, bail */
1479			if (adapter->link_up == link_up)
1480				break;
1481
1482			if (link_up) {
1483				/* If we get link up message and start queues
1484				 * before our queues are configured it will
1485				 * trigger a TX hang. In that case, just ignore
1486				 * the link status message,we'll get another one
1487				 * after we enable queues and actually prepared
1488				 * to send traffic.
1489				 */
1490				if (adapter->state != __IAVF_RUNNING)
1491					break;
1492
1493				/* For ADq enabled VF, we reconfigure VSIs and
1494				 * re-allocate queues. Hence wait till all
1495				 * queues are enabled.
1496				 */
1497				if (adapter->flags &
1498				    IAVF_FLAG_QUEUES_DISABLED)
1499					break;
1500			}
1501
1502			adapter->link_up = link_up;
1503			if (link_up) {
1504				netif_tx_start_all_queues(netdev);
1505				netif_carrier_on(netdev);
1506			} else {
1507				netif_tx_stop_all_queues(netdev);
1508				netif_carrier_off(netdev);
1509			}
1510			iavf_print_link_message(adapter);
1511			break;
1512		case VIRTCHNL_EVENT_RESET_IMPENDING:
1513			dev_info(&adapter->pdev->dev, "Reset warning received from the PF\n");
1514			if (!(adapter->flags & IAVF_FLAG_RESET_PENDING)) {
1515				adapter->flags |= IAVF_FLAG_RESET_PENDING;
1516				dev_info(&adapter->pdev->dev, "Scheduling reset task\n");
1517				queue_work(iavf_wq, &adapter->reset_task);
1518			}
1519			break;
1520		default:
1521			dev_err(&adapter->pdev->dev, "Unknown event %d from PF\n",
1522				vpe->event);
1523			break;
1524		}
1525		return;
1526	}
1527	if (v_retval) {
1528		switch (v_opcode) {
1529		case VIRTCHNL_OP_ADD_VLAN:
1530			dev_err(&adapter->pdev->dev, "Failed to add VLAN filter, error %s\n",
1531				iavf_stat_str(&adapter->hw, v_retval));
1532			break;
1533		case VIRTCHNL_OP_ADD_ETH_ADDR:
1534			dev_err(&adapter->pdev->dev, "Failed to add MAC filter, error %s\n",
1535				iavf_stat_str(&adapter->hw, v_retval));
1536			iavf_mac_add_reject(adapter);
1537			/* restore administratively set MAC address */
1538			ether_addr_copy(adapter->hw.mac.addr, netdev->dev_addr);
 
1539			break;
1540		case VIRTCHNL_OP_DEL_VLAN:
1541			dev_err(&adapter->pdev->dev, "Failed to delete VLAN filter, error %s\n",
1542				iavf_stat_str(&adapter->hw, v_retval));
1543			break;
1544		case VIRTCHNL_OP_DEL_ETH_ADDR:
1545			dev_err(&adapter->pdev->dev, "Failed to delete MAC filter, error %s\n",
1546				iavf_stat_str(&adapter->hw, v_retval));
1547			break;
1548		case VIRTCHNL_OP_ENABLE_CHANNELS:
1549			dev_err(&adapter->pdev->dev, "Failed to configure queue channels, error %s\n",
1550				iavf_stat_str(&adapter->hw, v_retval));
1551			adapter->flags &= ~IAVF_FLAG_REINIT_ITR_NEEDED;
1552			adapter->ch_config.state = __IAVF_TC_INVALID;
1553			netdev_reset_tc(netdev);
1554			netif_tx_start_all_queues(netdev);
1555			break;
1556		case VIRTCHNL_OP_DISABLE_CHANNELS:
1557			dev_err(&adapter->pdev->dev, "Failed to disable queue channels, error %s\n",
1558				iavf_stat_str(&adapter->hw, v_retval));
1559			adapter->flags &= ~IAVF_FLAG_REINIT_ITR_NEEDED;
1560			adapter->ch_config.state = __IAVF_TC_RUNNING;
1561			netif_tx_start_all_queues(netdev);
1562			break;
1563		case VIRTCHNL_OP_ADD_CLOUD_FILTER: {
1564			struct iavf_cloud_filter *cf, *cftmp;
1565
1566			list_for_each_entry_safe(cf, cftmp,
1567						 &adapter->cloud_filter_list,
1568						 list) {
1569				if (cf->state == __IAVF_CF_ADD_PENDING) {
1570					cf->state = __IAVF_CF_INVALID;
1571					dev_info(&adapter->pdev->dev, "Failed to add cloud filter, error %s\n",
1572						 iavf_stat_str(&adapter->hw,
1573							       v_retval));
1574					iavf_print_cloud_filter(adapter,
1575								&cf->f);
1576					list_del(&cf->list);
1577					kfree(cf);
1578					adapter->num_cloud_filters--;
1579				}
1580			}
1581			}
1582			break;
1583		case VIRTCHNL_OP_DEL_CLOUD_FILTER: {
1584			struct iavf_cloud_filter *cf;
1585
1586			list_for_each_entry(cf, &adapter->cloud_filter_list,
1587					    list) {
1588				if (cf->state == __IAVF_CF_DEL_PENDING) {
1589					cf->state = __IAVF_CF_ACTIVE;
1590					dev_info(&adapter->pdev->dev, "Failed to del cloud filter, error %s\n",
1591						 iavf_stat_str(&adapter->hw,
1592							       v_retval));
1593					iavf_print_cloud_filter(adapter,
1594								&cf->f);
1595				}
1596			}
1597			}
1598			break;
1599		case VIRTCHNL_OP_ADD_FDIR_FILTER: {
1600			struct iavf_fdir_fltr *fdir, *fdir_tmp;
1601
1602			spin_lock_bh(&adapter->fdir_fltr_lock);
1603			list_for_each_entry_safe(fdir, fdir_tmp,
1604						 &adapter->fdir_list_head,
1605						 list) {
1606				if (fdir->state == IAVF_FDIR_FLTR_ADD_PENDING) {
1607					dev_info(&adapter->pdev->dev, "Failed to add Flow Director filter, error %s\n",
1608						 iavf_stat_str(&adapter->hw,
1609							       v_retval));
1610					iavf_print_fdir_fltr(adapter, fdir);
1611					if (msglen)
1612						dev_err(&adapter->pdev->dev,
1613							"%s\n", msg);
1614					list_del(&fdir->list);
 
1615					kfree(fdir);
1616					adapter->fdir_active_fltr--;
1617				}
1618			}
1619			spin_unlock_bh(&adapter->fdir_fltr_lock);
1620			}
1621			break;
1622		case VIRTCHNL_OP_DEL_FDIR_FILTER: {
1623			struct iavf_fdir_fltr *fdir;
1624
1625			spin_lock_bh(&adapter->fdir_fltr_lock);
1626			list_for_each_entry(fdir, &adapter->fdir_list_head,
1627					    list) {
1628				if (fdir->state == IAVF_FDIR_FLTR_DEL_PENDING) {
 
1629					fdir->state = IAVF_FDIR_FLTR_ACTIVE;
1630					dev_info(&adapter->pdev->dev, "Failed to del Flow Director filter, error %s\n",
1631						 iavf_stat_str(&adapter->hw,
1632							       v_retval));
1633					iavf_print_fdir_fltr(adapter, fdir);
1634				}
1635			}
1636			spin_unlock_bh(&adapter->fdir_fltr_lock);
1637			}
1638			break;
1639		case VIRTCHNL_OP_ADD_RSS_CFG: {
1640			struct iavf_adv_rss *rss, *rss_tmp;
1641
1642			spin_lock_bh(&adapter->adv_rss_lock);
1643			list_for_each_entry_safe(rss, rss_tmp,
1644						 &adapter->adv_rss_list_head,
1645						 list) {
1646				if (rss->state == IAVF_ADV_RSS_ADD_PENDING) {
1647					iavf_print_adv_rss_cfg(adapter, rss,
1648							       "Failed to change the input set for",
1649							       NULL);
1650					list_del(&rss->list);
1651					kfree(rss);
1652				}
1653			}
1654			spin_unlock_bh(&adapter->adv_rss_lock);
1655			}
1656			break;
1657		case VIRTCHNL_OP_DEL_RSS_CFG: {
1658			struct iavf_adv_rss *rss;
1659
1660			spin_lock_bh(&adapter->adv_rss_lock);
1661			list_for_each_entry(rss, &adapter->adv_rss_list_head,
1662					    list) {
1663				if (rss->state == IAVF_ADV_RSS_DEL_PENDING) {
1664					rss->state = IAVF_ADV_RSS_ACTIVE;
1665					dev_err(&adapter->pdev->dev, "Failed to delete RSS configuration, error %s\n",
1666						iavf_stat_str(&adapter->hw,
1667							      v_retval));
1668				}
1669			}
1670			spin_unlock_bh(&adapter->adv_rss_lock);
1671			}
1672			break;
1673		case VIRTCHNL_OP_ENABLE_VLAN_STRIPPING:
 
 
 
 
 
 
1674		case VIRTCHNL_OP_DISABLE_VLAN_STRIPPING:
1675			dev_warn(&adapter->pdev->dev, "Changing VLAN Stripping is not allowed when Port VLAN is configured\n");
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1676			break;
1677		default:
1678			dev_err(&adapter->pdev->dev, "PF returned error %d (%s) to our request %d\n",
1679				v_retval, iavf_stat_str(&adapter->hw, v_retval),
1680				v_opcode);
1681		}
1682	}
1683	switch (v_opcode) {
1684	case VIRTCHNL_OP_ADD_ETH_ADDR:
1685		if (!v_retval)
1686			iavf_mac_add_ok(adapter);
1687		if (!ether_addr_equal(netdev->dev_addr, adapter->hw.mac.addr))
1688			ether_addr_copy(netdev->dev_addr, adapter->hw.mac.addr);
 
 
 
 
 
 
1689		break;
1690	case VIRTCHNL_OP_GET_STATS: {
1691		struct iavf_eth_stats *stats =
1692			(struct iavf_eth_stats *)msg;
1693		netdev->stats.rx_packets = stats->rx_unicast +
1694					   stats->rx_multicast +
1695					   stats->rx_broadcast;
1696		netdev->stats.tx_packets = stats->tx_unicast +
1697					   stats->tx_multicast +
1698					   stats->tx_broadcast;
1699		netdev->stats.rx_bytes = stats->rx_bytes;
1700		netdev->stats.tx_bytes = stats->tx_bytes;
1701		netdev->stats.tx_errors = stats->tx_errors;
1702		netdev->stats.rx_dropped = stats->rx_discards;
1703		netdev->stats.tx_dropped = stats->tx_discards;
1704		adapter->current_stats = *stats;
1705		}
1706		break;
1707	case VIRTCHNL_OP_GET_VF_RESOURCES: {
1708		u16 len = sizeof(struct virtchnl_vf_resource) +
1709			  IAVF_MAX_VF_VSI *
1710			  sizeof(struct virtchnl_vsi_resource);
1711		memcpy(adapter->vf_res, msg, min(msglen, len));
1712		iavf_validate_num_queues(adapter);
1713		iavf_vf_parse_hw_config(&adapter->hw, adapter->vf_res);
1714		if (is_zero_ether_addr(adapter->hw.mac.addr)) {
1715			/* restore current mac address */
1716			ether_addr_copy(adapter->hw.mac.addr, netdev->dev_addr);
1717		} else {
 
1718			/* refresh current mac address if changed */
1719			ether_addr_copy(netdev->dev_addr, adapter->hw.mac.addr);
1720			ether_addr_copy(netdev->perm_addr,
1721					adapter->hw.mac.addr);
 
1722		}
1723		spin_lock_bh(&adapter->mac_vlan_list_lock);
1724		iavf_add_filter(adapter, adapter->hw.mac.addr);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1725		spin_unlock_bh(&adapter->mac_vlan_list_lock);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1726		iavf_process_config(adapter);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1727		}
1728		break;
1729	case VIRTCHNL_OP_ENABLE_QUEUES:
1730		/* enable transmits */
1731		iavf_irq_enable(adapter, true);
 
1732		adapter->flags &= ~IAVF_FLAG_QUEUES_DISABLED;
1733		break;
1734	case VIRTCHNL_OP_DISABLE_QUEUES:
1735		iavf_free_all_tx_resources(adapter);
1736		iavf_free_all_rx_resources(adapter);
1737		if (adapter->state == __IAVF_DOWN_PENDING) {
1738			adapter->state = __IAVF_DOWN;
1739			wake_up(&adapter->down_waitqueue);
1740		}
1741		break;
1742	case VIRTCHNL_OP_VERSION:
1743	case VIRTCHNL_OP_CONFIG_IRQ_MAP:
1744		/* Don't display an error if we get these out of sequence.
1745		 * If the firmware needed to get kicked, we'll get these and
1746		 * it's no problem.
1747		 */
1748		if (v_opcode != adapter->current_op)
1749			return;
1750		break;
1751	case VIRTCHNL_OP_IWARP:
1752		/* Gobble zero-length replies from the PF. They indicate that
1753		 * a previous message was received OK, and the client doesn't
1754		 * care about that.
1755		 */
1756		if (msglen && CLIENT_ENABLED(adapter))
1757			iavf_notify_client_message(&adapter->vsi, msg, msglen);
1758		break;
1759
1760	case VIRTCHNL_OP_CONFIG_IWARP_IRQ_MAP:
1761		adapter->client_pending &=
1762				~(BIT(VIRTCHNL_OP_CONFIG_IWARP_IRQ_MAP));
1763		break;
1764	case VIRTCHNL_OP_GET_RSS_HENA_CAPS: {
1765		struct virtchnl_rss_hena *vrh = (struct virtchnl_rss_hena *)msg;
1766
1767		if (msglen == sizeof(*vrh))
1768			adapter->hena = vrh->hena;
1769		else
1770			dev_warn(&adapter->pdev->dev,
1771				 "Invalid message %d from PF\n", v_opcode);
1772		}
1773		break;
1774	case VIRTCHNL_OP_REQUEST_QUEUES: {
1775		struct virtchnl_vf_res_request *vfres =
1776			(struct virtchnl_vf_res_request *)msg;
1777
1778		if (vfres->num_queue_pairs != adapter->num_req_queues) {
1779			dev_info(&adapter->pdev->dev,
1780				 "Requested %d queues, PF can support %d\n",
1781				 adapter->num_req_queues,
1782				 vfres->num_queue_pairs);
1783			adapter->num_req_queues = 0;
1784			adapter->flags &= ~IAVF_FLAG_REINIT_ITR_NEEDED;
1785		}
1786		}
1787		break;
1788	case VIRTCHNL_OP_ADD_CLOUD_FILTER: {
1789		struct iavf_cloud_filter *cf;
1790
1791		list_for_each_entry(cf, &adapter->cloud_filter_list, list) {
1792			if (cf->state == __IAVF_CF_ADD_PENDING)
1793				cf->state = __IAVF_CF_ACTIVE;
1794		}
1795		}
1796		break;
1797	case VIRTCHNL_OP_DEL_CLOUD_FILTER: {
1798		struct iavf_cloud_filter *cf, *cftmp;
1799
1800		list_for_each_entry_safe(cf, cftmp, &adapter->cloud_filter_list,
1801					 list) {
1802			if (cf->state == __IAVF_CF_DEL_PENDING) {
1803				cf->state = __IAVF_CF_INVALID;
1804				list_del(&cf->list);
1805				kfree(cf);
1806				adapter->num_cloud_filters--;
1807			}
1808		}
1809		}
1810		break;
1811	case VIRTCHNL_OP_ADD_FDIR_FILTER: {
1812		struct virtchnl_fdir_add *add_fltr = (struct virtchnl_fdir_add *)msg;
1813		struct iavf_fdir_fltr *fdir, *fdir_tmp;
1814
1815		spin_lock_bh(&adapter->fdir_fltr_lock);
1816		list_for_each_entry_safe(fdir, fdir_tmp,
1817					 &adapter->fdir_list_head,
1818					 list) {
1819			if (fdir->state == IAVF_FDIR_FLTR_ADD_PENDING) {
1820				if (add_fltr->status == VIRTCHNL_FDIR_SUCCESS) {
1821					dev_info(&adapter->pdev->dev, "Flow Director filter with location %u is added\n",
1822						 fdir->loc);
 
 
 
 
1823					fdir->state = IAVF_FDIR_FLTR_ACTIVE;
1824					fdir->flow_id = add_fltr->flow_id;
1825				} else {
1826					dev_info(&adapter->pdev->dev, "Failed to add Flow Director filter with status: %d\n",
1827						 add_fltr->status);
1828					iavf_print_fdir_fltr(adapter, fdir);
1829					list_del(&fdir->list);
 
1830					kfree(fdir);
1831					adapter->fdir_active_fltr--;
1832				}
1833			}
1834		}
1835		spin_unlock_bh(&adapter->fdir_fltr_lock);
1836		}
1837		break;
1838	case VIRTCHNL_OP_DEL_FDIR_FILTER: {
1839		struct virtchnl_fdir_del *del_fltr = (struct virtchnl_fdir_del *)msg;
1840		struct iavf_fdir_fltr *fdir, *fdir_tmp;
1841
1842		spin_lock_bh(&adapter->fdir_fltr_lock);
1843		list_for_each_entry_safe(fdir, fdir_tmp, &adapter->fdir_list_head,
1844					 list) {
1845			if (fdir->state == IAVF_FDIR_FLTR_DEL_PENDING) {
1846				if (del_fltr->status == VIRTCHNL_FDIR_SUCCESS) {
1847					dev_info(&adapter->pdev->dev, "Flow Director filter with location %u is deleted\n",
1848						 fdir->loc);
 
 
 
 
 
 
1849					list_del(&fdir->list);
 
1850					kfree(fdir);
1851					adapter->fdir_active_fltr--;
1852				} else {
1853					fdir->state = IAVF_FDIR_FLTR_ACTIVE;
1854					dev_info(&adapter->pdev->dev, "Failed to delete Flow Director filter with status: %d\n",
1855						 del_fltr->status);
1856					iavf_print_fdir_fltr(adapter, fdir);
1857				}
 
 
 
 
 
 
 
 
 
 
 
1858			}
1859		}
1860		spin_unlock_bh(&adapter->fdir_fltr_lock);
1861		}
1862		break;
1863	case VIRTCHNL_OP_ADD_RSS_CFG: {
1864		struct iavf_adv_rss *rss;
1865
1866		spin_lock_bh(&adapter->adv_rss_lock);
1867		list_for_each_entry(rss, &adapter->adv_rss_list_head, list) {
1868			if (rss->state == IAVF_ADV_RSS_ADD_PENDING) {
1869				iavf_print_adv_rss_cfg(adapter, rss,
1870						       "Input set change for",
1871						       "successful");
1872				rss->state = IAVF_ADV_RSS_ACTIVE;
1873			}
1874		}
1875		spin_unlock_bh(&adapter->adv_rss_lock);
1876		}
1877		break;
1878	case VIRTCHNL_OP_DEL_RSS_CFG: {
1879		struct iavf_adv_rss *rss, *rss_tmp;
1880
1881		spin_lock_bh(&adapter->adv_rss_lock);
1882		list_for_each_entry_safe(rss, rss_tmp,
1883					 &adapter->adv_rss_list_head, list) {
1884			if (rss->state == IAVF_ADV_RSS_DEL_PENDING) {
1885				list_del(&rss->list);
1886				kfree(rss);
1887			}
1888		}
1889		spin_unlock_bh(&adapter->adv_rss_lock);
1890		}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1891		break;
1892	default:
1893		if (adapter->current_op && (v_opcode != adapter->current_op))
1894			dev_warn(&adapter->pdev->dev, "Expected response %d from PF, received %d\n",
1895				 adapter->current_op, v_opcode);
1896		break;
1897	} /* switch v_opcode */
1898	adapter->current_op = VIRTCHNL_OP_UNKNOWN;
1899}