Linux Audio

Check our new training course

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