1 // SPDX-License-Identifier: GPL-2.0 2 /* Copyright(c) 2013 - 2018 Intel Corporation. */ 3 4 #include <linux/list.h> 5 #include <linux/errno.h> 6 #include <linux/net/intel/i40e_client.h> 7 8 #include "i40e.h" 9 #include "i40e_prototype.h" 10 11 static const char i40e_client_interface_version_str[] = I40E_CLIENT_VERSION_STR; 12 static struct i40e_client *registered_client; 13 static LIST_HEAD(i40e_devices); 14 static DEFINE_MUTEX(i40e_device_mutex); 15 DEFINE_IDA(i40e_client_ida); 16 17 static int i40e_client_virtchnl_send(struct i40e_info *ldev, 18 struct i40e_client *client, 19 u32 vf_id, u8 *msg, u16 len); 20 21 static int i40e_client_setup_qvlist(struct i40e_info *ldev, 22 struct i40e_client *client, 23 struct i40e_qvlist_info *qvlist_info); 24 25 static void i40e_client_request_reset(struct i40e_info *ldev, 26 struct i40e_client *client, 27 u32 reset_level); 28 29 static int i40e_client_update_vsi_ctxt(struct i40e_info *ldev, 30 struct i40e_client *client, 31 bool is_vf, u32 vf_id, 32 u32 flag, u32 valid_flag); 33 34 static struct i40e_ops i40e_lan_ops = { 35 .virtchnl_send = i40e_client_virtchnl_send, 36 .setup_qvlist = i40e_client_setup_qvlist, 37 .request_reset = i40e_client_request_reset, 38 .update_vsi_ctxt = i40e_client_update_vsi_ctxt, 39 }; 40 41 /** 42 * i40e_client_get_params - Get the params that can change at runtime 43 * @vsi: the VSI with the message 44 * @params: client param struct 45 * 46 **/ 47 static 48 int i40e_client_get_params(struct i40e_vsi *vsi, struct i40e_params *params) 49 { 50 struct i40e_dcbx_config *dcb_cfg = &vsi->back->hw.local_dcbx_config; 51 int i = 0; 52 53 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) { 54 u8 tc = dcb_cfg->etscfg.prioritytable[i]; 55 u16 qs_handle; 56 57 /* If TC is not enabled for VSI use TC0 for UP */ 58 if (!(vsi->tc_config.enabled_tc & BIT(tc))) 59 tc = 0; 60 61 qs_handle = le16_to_cpu(vsi->info.qs_handle[tc]); 62 params->qos.prio_qos[i].tc = tc; 63 params->qos.prio_qos[i].qs_handle = qs_handle; 64 if (qs_handle == I40E_AQ_VSI_QS_HANDLE_INVALID) { 65 dev_err(&vsi->back->pdev->dev, "Invalid queue set handle for TC = %d, vsi id = %d\n", 66 tc, vsi->id); 67 return -EINVAL; 68 } 69 } 70 71 params->mtu = vsi->netdev->mtu; 72 return 0; 73 } 74 75 /** 76 * i40e_notify_client_of_vf_msg - call the client vf message callback 77 * @vsi: the VSI with the message 78 * @vf_id: the absolute VF id that sent the message 79 * @msg: message buffer 80 * @len: length of the message 81 * 82 * If there is a client to this VSI, call the client 83 **/ 84 void 85 i40e_notify_client_of_vf_msg(struct i40e_vsi *vsi, u32 vf_id, u8 *msg, u16 len) 86 { 87 struct i40e_pf *pf = vsi->back; 88 struct i40e_client_instance *cdev = pf->cinst; 89 90 if (!cdev || !cdev->client) 91 return; 92 if (!cdev->client->ops || !cdev->client->ops->virtchnl_receive) { 93 dev_dbg(&pf->pdev->dev, 94 "Cannot locate client instance virtual channel receive routine\n"); 95 return; 96 } 97 if (!test_bit(__I40E_CLIENT_INSTANCE_OPENED, &cdev->state)) { 98 dev_dbg(&pf->pdev->dev, "Client is not open, abort virtchnl_receive\n"); 99 return; 100 } 101 cdev->client->ops->virtchnl_receive(&cdev->lan_info, cdev->client, 102 vf_id, msg, len); 103 } 104 105 /** 106 * i40e_notify_client_of_l2_param_changes - call the client notify callback 107 * @vsi: the VSI with l2 param changes 108 * 109 * If there is a client to this VSI, call the client 110 **/ 111 void i40e_notify_client_of_l2_param_changes(struct i40e_vsi *vsi) 112 { 113 struct i40e_pf *pf = vsi->back; 114 struct i40e_client_instance *cdev = pf->cinst; 115 struct i40e_params params; 116 117 if (!cdev || !cdev->client) 118 return; 119 if (!cdev->client->ops || !cdev->client->ops->l2_param_change) { 120 dev_dbg(&vsi->back->pdev->dev, 121 "Cannot locate client instance l2_param_change routine\n"); 122 return; 123 } 124 if (!test_bit(__I40E_CLIENT_INSTANCE_OPENED, &cdev->state)) { 125 dev_dbg(&vsi->back->pdev->dev, "Client is not open, abort l2 param change\n"); 126 return; 127 } 128 memset(¶ms, 0, sizeof(params)); 129 i40e_client_get_params(vsi, ¶ms); 130 memcpy(&cdev->lan_info.params, ¶ms, sizeof(struct i40e_params)); 131 cdev->client->ops->l2_param_change(&cdev->lan_info, cdev->client, 132 ¶ms); 133 } 134 135 /** 136 * i40e_client_release_qvlist - release MSI-X vector mapping for client 137 * @ldev: pointer to L2 context. 138 * 139 **/ 140 static void i40e_client_release_qvlist(struct i40e_info *ldev) 141 { 142 struct i40e_qvlist_info *qvlist_info = ldev->qvlist_info; 143 u32 i; 144 145 if (!ldev->qvlist_info) 146 return; 147 148 for (i = 0; i < qvlist_info->num_vectors; i++) { 149 struct i40e_pf *pf = ldev->pf; 150 struct i40e_qv_info *qv_info; 151 u32 reg_idx; 152 153 qv_info = &qvlist_info->qv_info[i]; 154 if (!qv_info) 155 continue; 156 reg_idx = I40E_PFINT_LNKLSTN(qv_info->v_idx - 1); 157 wr32(&pf->hw, reg_idx, I40E_PFINT_LNKLSTN_FIRSTQ_INDX_MASK); 158 } 159 kfree(ldev->qvlist_info); 160 ldev->qvlist_info = NULL; 161 } 162 163 /** 164 * i40e_notify_client_of_netdev_close - call the client close callback 165 * @vsi: the VSI with netdev closed 166 * @reset: true when close called due to a reset pending 167 * 168 * If there is a client to this netdev, call the client with close 169 **/ 170 void i40e_notify_client_of_netdev_close(struct i40e_vsi *vsi, bool reset) 171 { 172 struct i40e_pf *pf = vsi->back; 173 struct i40e_client_instance *cdev = pf->cinst; 174 175 if (!cdev || !cdev->client) 176 return; 177 if (!cdev->client->ops || !cdev->client->ops->close) { 178 dev_dbg(&vsi->back->pdev->dev, 179 "Cannot locate client instance close routine\n"); 180 return; 181 } 182 cdev->client->ops->close(&cdev->lan_info, cdev->client, reset); 183 clear_bit(__I40E_CLIENT_INSTANCE_OPENED, &cdev->state); 184 i40e_client_release_qvlist(&cdev->lan_info); 185 } 186 187 /** 188 * i40e_notify_client_of_vf_reset - call the client vf reset callback 189 * @pf: PF device pointer 190 * @vf_id: asolute id of VF being reset 191 * 192 * If there is a client attached to this PF, notify when a VF is reset 193 **/ 194 void i40e_notify_client_of_vf_reset(struct i40e_pf *pf, u32 vf_id) 195 { 196 struct i40e_client_instance *cdev = pf->cinst; 197 198 if (!cdev || !cdev->client) 199 return; 200 if (!cdev->client->ops || !cdev->client->ops->vf_reset) { 201 dev_dbg(&pf->pdev->dev, 202 "Cannot locate client instance VF reset routine\n"); 203 return; 204 } 205 if (!test_bit(__I40E_CLIENT_INSTANCE_OPENED, &cdev->state)) { 206 dev_dbg(&pf->pdev->dev, "Client is not open, abort vf-reset\n"); 207 return; 208 } 209 cdev->client->ops->vf_reset(&cdev->lan_info, cdev->client, vf_id); 210 } 211 212 /** 213 * i40e_notify_client_of_vf_enable - call the client vf notification callback 214 * @pf: PF device pointer 215 * @num_vfs: the number of VFs currently enabled, 0 for disable 216 * 217 * If there is a client attached to this PF, call its VF notification routine 218 **/ 219 void i40e_notify_client_of_vf_enable(struct i40e_pf *pf, u32 num_vfs) 220 { 221 struct i40e_client_instance *cdev = pf->cinst; 222 223 if (!cdev || !cdev->client) 224 return; 225 if (!cdev->client->ops || !cdev->client->ops->vf_enable) { 226 dev_dbg(&pf->pdev->dev, 227 "Cannot locate client instance VF enable routine\n"); 228 return; 229 } 230 if (!test_bit(__I40E_CLIENT_INSTANCE_OPENED, 231 &cdev->state)) { 232 dev_dbg(&pf->pdev->dev, "Client is not open, abort vf-enable\n"); 233 return; 234 } 235 cdev->client->ops->vf_enable(&cdev->lan_info, cdev->client, num_vfs); 236 } 237 238 /** 239 * i40e_vf_client_capable - ask the client if it likes the specified VF 240 * @pf: PF device pointer 241 * @vf_id: the VF in question 242 * 243 * If there is a client of the specified type attached to this PF, call 244 * its vf_capable routine 245 **/ 246 int i40e_vf_client_capable(struct i40e_pf *pf, u32 vf_id) 247 { 248 struct i40e_client_instance *cdev = pf->cinst; 249 int capable = false; 250 251 if (!cdev || !cdev->client) 252 goto out; 253 if (!cdev->client->ops || !cdev->client->ops->vf_capable) { 254 dev_dbg(&pf->pdev->dev, 255 "Cannot locate client instance VF capability routine\n"); 256 goto out; 257 } 258 if (!test_bit(__I40E_CLIENT_INSTANCE_OPENED, &cdev->state)) 259 goto out; 260 261 capable = cdev->client->ops->vf_capable(&cdev->lan_info, 262 cdev->client, 263 vf_id); 264 out: 265 return capable; 266 } 267 268 void i40e_client_update_msix_info(struct i40e_pf *pf) 269 { 270 struct i40e_client_instance *cdev = pf->cinst; 271 272 if (!cdev || !cdev->client) 273 return; 274 275 cdev->lan_info.msix_count = pf->num_iwarp_msix; 276 cdev->lan_info.msix_entries = &pf->msix_entries[pf->iwarp_base_vector]; 277 } 278 279 static void i40e_auxiliary_dev_release(struct device *dev) 280 { 281 struct i40e_auxiliary_device *i40e_aux_dev = 282 container_of(dev, struct i40e_auxiliary_device, aux_dev.dev); 283 284 ida_free(&i40e_client_ida, i40e_aux_dev->aux_dev.id); 285 kfree(i40e_aux_dev); 286 } 287 288 static int i40e_register_auxiliary_dev(struct i40e_info *ldev, const char *name) 289 { 290 struct i40e_auxiliary_device *i40e_aux_dev; 291 struct pci_dev *pdev = ldev->pcidev; 292 struct auxiliary_device *aux_dev; 293 int ret; 294 295 i40e_aux_dev = kzalloc(sizeof(*i40e_aux_dev), GFP_KERNEL); 296 if (!i40e_aux_dev) 297 return -ENOMEM; 298 299 i40e_aux_dev->ldev = ldev; 300 301 aux_dev = &i40e_aux_dev->aux_dev; 302 aux_dev->name = name; 303 aux_dev->dev.parent = &pdev->dev; 304 aux_dev->dev.release = i40e_auxiliary_dev_release; 305 ldev->aux_dev = aux_dev; 306 307 ret = ida_alloc(&i40e_client_ida, GFP_KERNEL); 308 if (ret < 0) { 309 kfree(i40e_aux_dev); 310 return ret; 311 } 312 aux_dev->id = ret; 313 314 ret = auxiliary_device_init(aux_dev); 315 if (ret < 0) { 316 ida_free(&i40e_client_ida, aux_dev->id); 317 kfree(i40e_aux_dev); 318 return ret; 319 } 320 321 ret = auxiliary_device_add(aux_dev); 322 if (ret) { 323 auxiliary_device_uninit(aux_dev); 324 return ret; 325 } 326 327 return ret; 328 } 329 330 /** 331 * i40e_client_add_instance - add a client instance struct to the instance list 332 * @pf: pointer to the board struct 333 * 334 **/ 335 static void i40e_client_add_instance(struct i40e_pf *pf) 336 { 337 struct i40e_client_instance *cdev = NULL; 338 struct netdev_hw_addr *mac = NULL; 339 struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi]; 340 341 cdev = kzalloc(sizeof(*cdev), GFP_KERNEL); 342 if (!cdev) 343 return; 344 345 cdev->lan_info.pf = (void *)pf; 346 cdev->lan_info.netdev = vsi->netdev; 347 cdev->lan_info.pcidev = pf->pdev; 348 cdev->lan_info.fid = pf->hw.pf_id; 349 cdev->lan_info.ftype = I40E_CLIENT_FTYPE_PF; 350 cdev->lan_info.hw_addr = pf->hw.hw_addr; 351 cdev->lan_info.ops = &i40e_lan_ops; 352 cdev->lan_info.version.major = I40E_CLIENT_VERSION_MAJOR; 353 cdev->lan_info.version.minor = I40E_CLIENT_VERSION_MINOR; 354 cdev->lan_info.version.build = I40E_CLIENT_VERSION_BUILD; 355 cdev->lan_info.fw_maj_ver = pf->hw.aq.fw_maj_ver; 356 cdev->lan_info.fw_min_ver = pf->hw.aq.fw_min_ver; 357 cdev->lan_info.fw_build = pf->hw.aq.fw_build; 358 set_bit(__I40E_CLIENT_INSTANCE_NONE, &cdev->state); 359 360 if (i40e_client_get_params(vsi, &cdev->lan_info.params)) 361 goto free_cdev; 362 363 mac = list_first_entry(&cdev->lan_info.netdev->dev_addrs.list, 364 struct netdev_hw_addr, list); 365 if (mac) 366 ether_addr_copy(cdev->lan_info.lanmac, mac->addr); 367 else 368 dev_err(&pf->pdev->dev, "MAC address list is empty!\n"); 369 370 cdev->client = registered_client; 371 pf->cinst = cdev; 372 373 cdev->lan_info.msix_count = pf->num_iwarp_msix; 374 cdev->lan_info.msix_entries = &pf->msix_entries[pf->iwarp_base_vector]; 375 376 if (i40e_register_auxiliary_dev(&cdev->lan_info, "iwarp")) 377 goto free_cdev; 378 379 return; 380 381 free_cdev: 382 kfree(cdev); 383 pf->cinst = NULL; 384 } 385 386 /** 387 * i40e_client_del_instance - removes a client instance from the list 388 * @pf: pointer to the board struct 389 * 390 **/ 391 static 392 void i40e_client_del_instance(struct i40e_pf *pf) 393 { 394 kfree(pf->cinst); 395 pf->cinst = NULL; 396 } 397 398 /** 399 * i40e_client_subtask - client maintenance work 400 * @pf: board private structure 401 **/ 402 void i40e_client_subtask(struct i40e_pf *pf) 403 { 404 struct i40e_client *client; 405 struct i40e_client_instance *cdev; 406 struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi]; 407 int ret = 0; 408 409 if (!test_and_clear_bit(__I40E_CLIENT_SERVICE_REQUESTED, pf->state)) 410 return; 411 cdev = pf->cinst; 412 413 /* If we're down or resetting, just bail */ 414 if (test_bit(__I40E_DOWN, pf->state) || 415 test_bit(__I40E_CONFIG_BUSY, pf->state)) 416 return; 417 418 if (!cdev || !cdev->client) 419 return; 420 421 client = cdev->client; 422 423 /* Here we handle client opens. If the client is down, and 424 * the netdev is registered, then open the client. 425 */ 426 if (!test_bit(__I40E_CLIENT_INSTANCE_OPENED, &cdev->state)) { 427 if (vsi->netdev_registered && 428 client->ops && client->ops->open) { 429 set_bit(__I40E_CLIENT_INSTANCE_OPENED, &cdev->state); 430 ret = client->ops->open(&cdev->lan_info, client); 431 if (ret) { 432 /* Remove failed client instance */ 433 clear_bit(__I40E_CLIENT_INSTANCE_OPENED, 434 &cdev->state); 435 i40e_client_del_instance(pf); 436 return; 437 } 438 } 439 } 440 441 /* enable/disable PE TCP_ENA flag based on netdev down/up 442 */ 443 if (test_bit(__I40E_VSI_DOWN, vsi->state)) 444 i40e_client_update_vsi_ctxt(&cdev->lan_info, client, 445 0, 0, 0, 446 I40E_CLIENT_VSI_FLAG_TCP_ENABLE); 447 else 448 i40e_client_update_vsi_ctxt(&cdev->lan_info, client, 449 0, 0, 450 I40E_CLIENT_VSI_FLAG_TCP_ENABLE, 451 I40E_CLIENT_VSI_FLAG_TCP_ENABLE); 452 } 453 454 /** 455 * i40e_lan_add_device - add a lan device struct to the list of lan devices 456 * @pf: pointer to the board struct 457 * 458 * Returns 0 on success or none 0 on error 459 **/ 460 int i40e_lan_add_device(struct i40e_pf *pf) 461 { 462 struct i40e_device *ldev; 463 int ret = 0; 464 465 mutex_lock(&i40e_device_mutex); 466 list_for_each_entry(ldev, &i40e_devices, list) { 467 if (ldev->pf == pf) { 468 ret = -EEXIST; 469 goto out; 470 } 471 } 472 ldev = kzalloc(sizeof(*ldev), GFP_KERNEL); 473 if (!ldev) { 474 ret = -ENOMEM; 475 goto out; 476 } 477 ldev->pf = pf; 478 INIT_LIST_HEAD(&ldev->list); 479 list_add(&ldev->list, &i40e_devices); 480 dev_info(&pf->pdev->dev, "Added LAN device PF%d bus=0x%02x dev=0x%02x func=0x%02x\n", 481 pf->hw.pf_id, pf->hw.bus.bus_id, 482 pf->hw.bus.device, pf->hw.bus.func); 483 484 i40e_client_add_instance(pf); 485 486 set_bit(__I40E_CLIENT_SERVICE_REQUESTED, pf->state); 487 i40e_service_event_schedule(pf); 488 489 out: 490 mutex_unlock(&i40e_device_mutex); 491 return ret; 492 } 493 494 /** 495 * i40e_lan_del_device - removes a lan device from the device list 496 * @pf: pointer to the board struct 497 * 498 * Returns 0 on success or non-0 on error 499 **/ 500 int i40e_lan_del_device(struct i40e_pf *pf) 501 { 502 struct auxiliary_device *aux_dev = pf->cinst->lan_info.aux_dev; 503 struct i40e_device *ldev, *tmp; 504 int ret = -ENODEV; 505 506 auxiliary_device_delete(aux_dev); 507 auxiliary_device_uninit(aux_dev); 508 509 /* First, remove any client instance. */ 510 i40e_client_del_instance(pf); 511 512 mutex_lock(&i40e_device_mutex); 513 list_for_each_entry_safe(ldev, tmp, &i40e_devices, list) { 514 if (ldev->pf == pf) { 515 dev_info(&pf->pdev->dev, "Deleted LAN device PF%d bus=0x%02x dev=0x%02x func=0x%02x\n", 516 pf->hw.pf_id, pf->hw.bus.bus_id, 517 pf->hw.bus.device, pf->hw.bus.func); 518 list_del(&ldev->list); 519 kfree(ldev); 520 ret = 0; 521 break; 522 } 523 } 524 mutex_unlock(&i40e_device_mutex); 525 return ret; 526 } 527 528 /** 529 * i40e_client_release - release client specific resources 530 * @client: pointer to the registered client 531 * 532 **/ 533 static void i40e_client_release(struct i40e_client *client) 534 { 535 struct i40e_client_instance *cdev; 536 struct i40e_device *ldev; 537 struct i40e_pf *pf; 538 539 mutex_lock(&i40e_device_mutex); 540 list_for_each_entry(ldev, &i40e_devices, list) { 541 pf = ldev->pf; 542 cdev = pf->cinst; 543 if (!cdev) 544 continue; 545 546 while (test_and_set_bit(__I40E_SERVICE_SCHED, 547 pf->state)) 548 usleep_range(500, 1000); 549 550 if (test_bit(__I40E_CLIENT_INSTANCE_OPENED, &cdev->state)) { 551 if (client->ops && client->ops->close) 552 client->ops->close(&cdev->lan_info, client, 553 false); 554 i40e_client_release_qvlist(&cdev->lan_info); 555 clear_bit(__I40E_CLIENT_INSTANCE_OPENED, &cdev->state); 556 557 dev_warn(&pf->pdev->dev, 558 "Client %s instance for PF id %d closed\n", 559 client->name, pf->hw.pf_id); 560 } 561 /* delete the client instance */ 562 i40e_client_del_instance(pf); 563 dev_info(&pf->pdev->dev, "Deleted client instance of Client %s\n", 564 client->name); 565 clear_bit(__I40E_SERVICE_SCHED, pf->state); 566 } 567 mutex_unlock(&i40e_device_mutex); 568 } 569 570 /** 571 * i40e_client_prepare - prepare client specific resources 572 * @client: pointer to the registered client 573 * 574 **/ 575 static void i40e_client_prepare(struct i40e_client *client) 576 { 577 struct i40e_device *ldev; 578 struct i40e_pf *pf; 579 580 mutex_lock(&i40e_device_mutex); 581 list_for_each_entry(ldev, &i40e_devices, list) { 582 pf = ldev->pf; 583 i40e_client_add_instance(pf); 584 /* Start the client subtask */ 585 set_bit(__I40E_CLIENT_SERVICE_REQUESTED, pf->state); 586 i40e_service_event_schedule(pf); 587 } 588 mutex_unlock(&i40e_device_mutex); 589 } 590 591 /** 592 * i40e_client_virtchnl_send - TBD 593 * @ldev: pointer to L2 context 594 * @client: Client pointer 595 * @vf_id: absolute VF identifier 596 * @msg: message buffer 597 * @len: length of message buffer 598 * 599 * Return 0 on success or < 0 on error 600 **/ 601 static int i40e_client_virtchnl_send(struct i40e_info *ldev, 602 struct i40e_client *client, 603 u32 vf_id, u8 *msg, u16 len) 604 { 605 struct i40e_pf *pf = ldev->pf; 606 struct i40e_hw *hw = &pf->hw; 607 i40e_status err; 608 609 err = i40e_aq_send_msg_to_vf(hw, vf_id, VIRTCHNL_OP_IWARP, 610 0, msg, len, NULL); 611 if (err) 612 dev_err(&pf->pdev->dev, "Unable to send iWarp message to VF, error %d, aq status %d\n", 613 err, hw->aq.asq_last_status); 614 615 return err; 616 } 617 618 /** 619 * i40e_client_setup_qvlist 620 * @ldev: pointer to L2 context. 621 * @client: Client pointer. 622 * @qvlist_info: queue and vector list 623 * 624 * Return 0 on success or < 0 on error 625 **/ 626 static int i40e_client_setup_qvlist(struct i40e_info *ldev, 627 struct i40e_client *client, 628 struct i40e_qvlist_info *qvlist_info) 629 { 630 struct i40e_pf *pf = ldev->pf; 631 struct i40e_hw *hw = &pf->hw; 632 struct i40e_qv_info *qv_info; 633 u32 v_idx, i, reg_idx, reg; 634 635 ldev->qvlist_info = kzalloc(struct_size(ldev->qvlist_info, qv_info, 636 qvlist_info->num_vectors), GFP_KERNEL); 637 if (!ldev->qvlist_info) 638 return -ENOMEM; 639 ldev->qvlist_info->num_vectors = qvlist_info->num_vectors; 640 641 for (i = 0; i < qvlist_info->num_vectors; i++) { 642 qv_info = &qvlist_info->qv_info[i]; 643 if (!qv_info) 644 continue; 645 v_idx = qv_info->v_idx; 646 647 /* Validate vector id belongs to this client */ 648 if ((v_idx >= (pf->iwarp_base_vector + pf->num_iwarp_msix)) || 649 (v_idx < pf->iwarp_base_vector)) 650 goto err; 651 652 ldev->qvlist_info->qv_info[i] = *qv_info; 653 reg_idx = I40E_PFINT_LNKLSTN(v_idx - 1); 654 655 if (qv_info->ceq_idx == I40E_QUEUE_INVALID_IDX) { 656 /* Special case - No CEQ mapped on this vector */ 657 wr32(hw, reg_idx, I40E_PFINT_LNKLSTN_FIRSTQ_INDX_MASK); 658 } else { 659 reg = (qv_info->ceq_idx & 660 I40E_PFINT_LNKLSTN_FIRSTQ_INDX_MASK) | 661 (I40E_QUEUE_TYPE_PE_CEQ << 662 I40E_PFINT_LNKLSTN_FIRSTQ_TYPE_SHIFT); 663 wr32(hw, reg_idx, reg); 664 665 reg = (I40E_PFINT_CEQCTL_CAUSE_ENA_MASK | 666 (v_idx << I40E_PFINT_CEQCTL_MSIX_INDX_SHIFT) | 667 (qv_info->itr_idx << 668 I40E_PFINT_CEQCTL_ITR_INDX_SHIFT) | 669 (I40E_QUEUE_END_OF_LIST << 670 I40E_PFINT_CEQCTL_NEXTQ_INDX_SHIFT)); 671 wr32(hw, I40E_PFINT_CEQCTL(qv_info->ceq_idx), reg); 672 } 673 if (qv_info->aeq_idx != I40E_QUEUE_INVALID_IDX) { 674 reg = (I40E_PFINT_AEQCTL_CAUSE_ENA_MASK | 675 (v_idx << I40E_PFINT_AEQCTL_MSIX_INDX_SHIFT) | 676 (qv_info->itr_idx << 677 I40E_PFINT_AEQCTL_ITR_INDX_SHIFT)); 678 679 wr32(hw, I40E_PFINT_AEQCTL, reg); 680 } 681 } 682 /* Mitigate sync problems with iwarp VF driver */ 683 i40e_flush(hw); 684 return 0; 685 err: 686 kfree(ldev->qvlist_info); 687 ldev->qvlist_info = NULL; 688 return -EINVAL; 689 } 690 691 /** 692 * i40e_client_request_reset 693 * @ldev: pointer to L2 context. 694 * @client: Client pointer. 695 * @reset_level: reset level 696 **/ 697 static void i40e_client_request_reset(struct i40e_info *ldev, 698 struct i40e_client *client, 699 u32 reset_level) 700 { 701 struct i40e_pf *pf = ldev->pf; 702 703 switch (reset_level) { 704 case I40E_CLIENT_RESET_LEVEL_PF: 705 set_bit(__I40E_PF_RESET_REQUESTED, pf->state); 706 break; 707 case I40E_CLIENT_RESET_LEVEL_CORE: 708 set_bit(__I40E_PF_RESET_REQUESTED, pf->state); 709 break; 710 default: 711 dev_warn(&pf->pdev->dev, 712 "Client for PF id %d requested an unsupported reset: %d.\n", 713 pf->hw.pf_id, reset_level); 714 break; 715 } 716 717 i40e_service_event_schedule(pf); 718 } 719 720 /** 721 * i40e_client_update_vsi_ctxt 722 * @ldev: pointer to L2 context. 723 * @client: Client pointer. 724 * @is_vf: if this for the VF 725 * @vf_id: if is_vf true this carries the vf_id 726 * @flag: Any device level setting that needs to be done for PE 727 * @valid_flag: Bits in this match up and enable changing of flag bits 728 * 729 * Return 0 on success or < 0 on error 730 **/ 731 static int i40e_client_update_vsi_ctxt(struct i40e_info *ldev, 732 struct i40e_client *client, 733 bool is_vf, u32 vf_id, 734 u32 flag, u32 valid_flag) 735 { 736 struct i40e_pf *pf = ldev->pf; 737 struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi]; 738 struct i40e_vsi_context ctxt; 739 bool update = true; 740 i40e_status err; 741 742 /* TODO: for now do not allow setting VF's VSI setting */ 743 if (is_vf) 744 return -EINVAL; 745 746 ctxt.seid = pf->main_vsi_seid; 747 ctxt.pf_num = pf->hw.pf_id; 748 err = i40e_aq_get_vsi_params(&pf->hw, &ctxt, NULL); 749 ctxt.flags = I40E_AQ_VSI_TYPE_PF; 750 if (err) { 751 dev_info(&pf->pdev->dev, 752 "couldn't get PF vsi config, err %s aq_err %s\n", 753 i40e_stat_str(&pf->hw, err), 754 i40e_aq_str(&pf->hw, 755 pf->hw.aq.asq_last_status)); 756 return -ENOENT; 757 } 758 759 if ((valid_flag & I40E_CLIENT_VSI_FLAG_TCP_ENABLE) && 760 (flag & I40E_CLIENT_VSI_FLAG_TCP_ENABLE)) { 761 ctxt.info.valid_sections = 762 cpu_to_le16(I40E_AQ_VSI_PROP_QUEUE_OPT_VALID); 763 ctxt.info.queueing_opt_flags |= I40E_AQ_VSI_QUE_OPT_TCP_ENA; 764 } else if ((valid_flag & I40E_CLIENT_VSI_FLAG_TCP_ENABLE) && 765 !(flag & I40E_CLIENT_VSI_FLAG_TCP_ENABLE)) { 766 ctxt.info.valid_sections = 767 cpu_to_le16(I40E_AQ_VSI_PROP_QUEUE_OPT_VALID); 768 ctxt.info.queueing_opt_flags &= ~I40E_AQ_VSI_QUE_OPT_TCP_ENA; 769 } else { 770 update = false; 771 dev_warn(&pf->pdev->dev, 772 "Client for PF id %d request an unsupported Config: %x.\n", 773 pf->hw.pf_id, flag); 774 } 775 776 if (update) { 777 err = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL); 778 if (err) { 779 dev_info(&pf->pdev->dev, 780 "update VSI ctxt for PE failed, err %s aq_err %s\n", 781 i40e_stat_str(&pf->hw, err), 782 i40e_aq_str(&pf->hw, 783 pf->hw.aq.asq_last_status)); 784 } 785 } 786 return err; 787 } 788 789 void i40e_client_device_register(struct i40e_info *ldev, struct i40e_client *client) 790 { 791 struct i40e_pf *pf = ldev->pf; 792 793 pf->cinst->client = client; 794 set_bit(__I40E_CLIENT_SERVICE_REQUESTED, pf->state); 795 i40e_service_event_schedule(pf); 796 } 797 EXPORT_SYMBOL_GPL(i40e_client_device_register); 798 799 void i40e_client_device_unregister(struct i40e_info *ldev) 800 { 801 struct i40e_pf *pf = ldev->pf; 802 struct i40e_client_instance *cdev = pf->cinst; 803 804 if (!cdev) 805 return; 806 807 while (test_and_set_bit(__I40E_SERVICE_SCHED, pf->state)) 808 usleep_range(500, 1000); 809 810 if (test_bit(__I40E_CLIENT_INSTANCE_OPENED, &cdev->state)) { 811 cdev->client->ops->close(&cdev->lan_info, cdev->client, false); 812 clear_bit(__I40E_CLIENT_INSTANCE_OPENED, &cdev->state); 813 i40e_client_release_qvlist(&cdev->lan_info); 814 } 815 816 pf->cinst->client = NULL; 817 clear_bit(__I40E_SERVICE_SCHED, pf->state); 818 } 819 EXPORT_SYMBOL_GPL(i40e_client_device_unregister); 820 821 /* Retain these legacy global registration/unregistration calls till i40iw is 822 * removed from the kernel. The irdma unified driver does not use these 823 * exported symbols. 824 */ 825 /** 826 * i40e_register_client - Register a i40e client driver with the L2 driver 827 * @client: pointer to the i40e_client struct 828 * 829 * Returns 0 on success or non-0 on error 830 **/ 831 int i40e_register_client(struct i40e_client *client) 832 { 833 int ret = 0; 834 835 if (!client) { 836 ret = -EIO; 837 goto out; 838 } 839 840 if (strlen(client->name) == 0) { 841 pr_info("i40e: Failed to register client with no name\n"); 842 ret = -EIO; 843 goto out; 844 } 845 846 if (registered_client) { 847 pr_info("i40e: Client %s has already been registered!\n", 848 client->name); 849 ret = -EEXIST; 850 goto out; 851 } 852 853 if ((client->version.major != I40E_CLIENT_VERSION_MAJOR) || 854 (client->version.minor != I40E_CLIENT_VERSION_MINOR)) { 855 pr_info("i40e: Failed to register client %s due to mismatched client interface version\n", 856 client->name); 857 pr_info("Client is using version: %02d.%02d.%02d while LAN driver supports %s\n", 858 client->version.major, client->version.minor, 859 client->version.build, 860 i40e_client_interface_version_str); 861 ret = -EIO; 862 goto out; 863 } 864 865 registered_client = client; 866 867 i40e_client_prepare(client); 868 869 pr_info("i40e: Registered client %s\n", client->name); 870 out: 871 return ret; 872 } 873 EXPORT_SYMBOL(i40e_register_client); 874 875 /** 876 * i40e_unregister_client - Unregister a i40e client driver with the L2 driver 877 * @client: pointer to the i40e_client struct 878 * 879 * Returns 0 on success or non-0 on error 880 **/ 881 int i40e_unregister_client(struct i40e_client *client) 882 { 883 int ret = 0; 884 885 if (registered_client != client) { 886 pr_info("i40e: Client %s has not been registered\n", 887 client->name); 888 ret = -ENODEV; 889 goto out; 890 } 891 registered_client = NULL; 892 /* When a unregister request comes through we would have to send 893 * a close for each of the client instances that were opened. 894 * client_release function is called to handle this. 895 */ 896 i40e_client_release(client); 897 898 pr_info("i40e: Unregistered client %s\n", client->name); 899 out: 900 return ret; 901 } 902 EXPORT_SYMBOL(i40e_unregister_client); 903