Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

sfc: move channel alloc/removal code

Reallocation and copying code is included, as well as some housekeeping
code.
Other files have been patched up a bit to accommodate the changes.

Small code styling fixes included.

Signed-off-by: Alexandru-Mihai Maftei <amaftei@solarflare.com>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Alex Maftei (amaftei) and committed by
David S. Miller
83975485 e20ba5b1

+441 -435
-420
drivers/net/ethernet/sfc/efx.c
··· 96 96 */ 97 97 static unsigned int tx_irq_mod_usec = 150; 98 98 99 - /* This is the first interrupt mode to try out of: 100 - * 0 => MSI-X 101 - * 1 => MSI 102 - * 2 => legacy 103 - */ 104 - static unsigned int interrupt_mode; 105 - 106 99 /* This is the requested number of CPUs to use for Receive-Side Scaling (RSS), 107 100 * i.e. the number of CPUs among which we may distribute simultaneous 108 101 * interrupt handling. ··· 237 244 * 238 245 *************************************************************************/ 239 246 240 - /* Allocate and initialise a channel structure. */ 241 - struct efx_channel * 242 - efx_alloc_channel(struct efx_nic *efx, int i, struct efx_channel *old_channel) 243 - { 244 - struct efx_channel *channel; 245 - struct efx_rx_queue *rx_queue; 246 - struct efx_tx_queue *tx_queue; 247 - int j; 248 - 249 - channel = kzalloc(sizeof(*channel), GFP_KERNEL); 250 - if (!channel) 251 - return NULL; 252 - 253 - channel->efx = efx; 254 - channel->channel = i; 255 - channel->type = &efx_default_channel_type; 256 - 257 - for (j = 0; j < EFX_TXQ_TYPES; j++) { 258 - tx_queue = &channel->tx_queue[j]; 259 - tx_queue->efx = efx; 260 - tx_queue->queue = i * EFX_TXQ_TYPES + j; 261 - tx_queue->channel = channel; 262 - } 263 - 264 - #ifdef CONFIG_RFS_ACCEL 265 - INIT_DELAYED_WORK(&channel->filter_work, efx_filter_rfs_expire); 266 - #endif 267 - 268 - rx_queue = &channel->rx_queue; 269 - rx_queue->efx = efx; 270 - timer_setup(&rx_queue->slow_fill, efx_rx_slow_fill, 0); 271 - 272 - return channel; 273 - } 274 - 275 - /* Allocate and initialise a channel structure, copying parameters 276 - * (but not resources) from an old channel structure. 277 - */ 278 - struct efx_channel *efx_copy_channel(const struct efx_channel *old_channel) 279 - { 280 - struct efx_channel *channel; 281 - struct efx_rx_queue *rx_queue; 282 - struct efx_tx_queue *tx_queue; 283 - int j; 284 - 285 - channel = kmalloc(sizeof(*channel), GFP_KERNEL); 286 - if (!channel) 287 - return NULL; 288 - 289 - *channel = *old_channel; 290 - 291 - channel->napi_dev = NULL; 292 - INIT_HLIST_NODE(&channel->napi_str.napi_hash_node); 293 - channel->napi_str.napi_id = 0; 294 - channel->napi_str.state = 0; 295 - memset(&channel->eventq, 0, sizeof(channel->eventq)); 296 - 297 - for (j = 0; j < EFX_TXQ_TYPES; j++) { 298 - tx_queue = &channel->tx_queue[j]; 299 - if (tx_queue->channel) 300 - tx_queue->channel = channel; 301 - tx_queue->buffer = NULL; 302 - memset(&tx_queue->txd, 0, sizeof(tx_queue->txd)); 303 - } 304 - 305 - rx_queue = &channel->rx_queue; 306 - rx_queue->buffer = NULL; 307 - memset(&rx_queue->rxd, 0, sizeof(rx_queue->rxd)); 308 - timer_setup(&rx_queue->slow_fill, efx_rx_slow_fill, 0); 309 - #ifdef CONFIG_RFS_ACCEL 310 - INIT_DELAYED_WORK(&channel->filter_work, efx_filter_rfs_expire); 311 - #endif 312 - 313 - return channel; 314 - } 315 - 316 - static int efx_probe_channel(struct efx_channel *channel) 317 - { 318 - struct efx_tx_queue *tx_queue; 319 - struct efx_rx_queue *rx_queue; 320 - int rc; 321 - 322 - netif_dbg(channel->efx, probe, channel->efx->net_dev, 323 - "creating channel %d\n", channel->channel); 324 - 325 - rc = channel->type->pre_probe(channel); 326 - if (rc) 327 - goto fail; 328 - 329 - rc = efx_probe_eventq(channel); 330 - if (rc) 331 - goto fail; 332 - 333 - efx_for_each_channel_tx_queue(tx_queue, channel) { 334 - rc = efx_probe_tx_queue(tx_queue); 335 - if (rc) 336 - goto fail; 337 - } 338 - 339 - efx_for_each_channel_rx_queue(rx_queue, channel) { 340 - rc = efx_probe_rx_queue(rx_queue); 341 - if (rc) 342 - goto fail; 343 - } 344 - 345 - channel->rx_list = NULL; 346 - 347 - return 0; 348 - 349 - fail: 350 - efx_remove_channel(channel); 351 - return rc; 352 - } 353 - 354 - void efx_get_channel_name(struct efx_channel *channel, char *buf, size_t len) 355 - { 356 - struct efx_nic *efx = channel->efx; 357 - const char *type; 358 - int number; 359 - 360 - number = channel->channel; 361 - 362 - if (number >= efx->xdp_channel_offset && 363 - !WARN_ON_ONCE(!efx->n_xdp_channels)) { 364 - type = "-xdp"; 365 - number -= efx->xdp_channel_offset; 366 - } else if (efx->tx_channel_offset == 0) { 367 - type = ""; 368 - } else if (number < efx->tx_channel_offset) { 369 - type = "-rx"; 370 - } else { 371 - type = "-tx"; 372 - number -= efx->tx_channel_offset; 373 - } 374 - snprintf(buf, len, "%s%s-%d", efx->name, type, number); 375 - } 376 - 377 - void efx_set_channel_names(struct efx_nic *efx) 378 - { 379 - struct efx_channel *channel; 380 - 381 - efx_for_each_channel(channel, efx) 382 - channel->type->get_name(channel, 383 - efx->msi_context[channel->channel].name, 384 - sizeof(efx->msi_context[0].name)); 385 - } 386 - 387 - int efx_probe_channels(struct efx_nic *efx) 388 - { 389 - struct efx_channel *channel; 390 - int rc; 391 - 392 - /* Restart special buffer allocation */ 393 - efx->next_buffer_table = 0; 394 - 395 - /* Probe channels in reverse, so that any 'extra' channels 396 - * use the start of the buffer table. This allows the traffic 397 - * channels to be resized without moving them or wasting the 398 - * entries before them. 399 - */ 400 - efx_for_each_channel_rev(channel, efx) { 401 - rc = efx_probe_channel(channel); 402 - if (rc) { 403 - netif_err(efx, probe, efx->net_dev, 404 - "failed to create channel %d\n", 405 - channel->channel); 406 - goto fail; 407 - } 408 - } 409 - efx_set_channel_names(efx); 410 - 411 - return 0; 412 - 413 - fail: 414 - efx_remove_channels(efx); 415 - return rc; 416 - } 417 - 418 - void efx_remove_channel(struct efx_channel *channel) 419 - { 420 - struct efx_tx_queue *tx_queue; 421 - struct efx_rx_queue *rx_queue; 422 - 423 - netif_dbg(channel->efx, drv, channel->efx->net_dev, 424 - "destroy chan %d\n", channel->channel); 425 - 426 - efx_for_each_channel_rx_queue(rx_queue, channel) 427 - efx_remove_rx_queue(rx_queue); 428 - efx_for_each_possible_channel_tx_queue(tx_queue, channel) 429 - efx_remove_tx_queue(tx_queue); 430 - efx_remove_eventq(channel); 431 - channel->type->post_remove(channel); 432 - } 433 - 434 - void efx_remove_channels(struct efx_nic *efx) 435 - { 436 - struct efx_channel *channel; 437 - 438 - efx_for_each_channel(channel, efx) 439 - efx_remove_channel(channel); 440 - 441 - kfree(efx->xdp_tx_queues); 442 - } 443 - 444 - int efx_realloc_channels(struct efx_nic *efx, u32 rxq_entries, u32 txq_entries) 445 - { 446 - struct efx_channel *other_channel[EFX_MAX_CHANNELS], *channel; 447 - u32 old_rxq_entries, old_txq_entries; 448 - unsigned i, next_buffer_table = 0; 449 - int rc, rc2; 450 - 451 - rc = efx_check_disabled(efx); 452 - if (rc) 453 - return rc; 454 - 455 - /* Not all channels should be reallocated. We must avoid 456 - * reallocating their buffer table entries. 457 - */ 458 - efx_for_each_channel(channel, efx) { 459 - struct efx_rx_queue *rx_queue; 460 - struct efx_tx_queue *tx_queue; 461 - 462 - if (channel->type->copy) 463 - continue; 464 - next_buffer_table = max(next_buffer_table, 465 - channel->eventq.index + 466 - channel->eventq.entries); 467 - efx_for_each_channel_rx_queue(rx_queue, channel) 468 - next_buffer_table = max(next_buffer_table, 469 - rx_queue->rxd.index + 470 - rx_queue->rxd.entries); 471 - efx_for_each_channel_tx_queue(tx_queue, channel) 472 - next_buffer_table = max(next_buffer_table, 473 - tx_queue->txd.index + 474 - tx_queue->txd.entries); 475 - } 476 - 477 - efx_device_detach_sync(efx); 478 - efx_stop_all(efx); 479 - efx_soft_disable_interrupts(efx); 480 - 481 - /* Clone channels (where possible) */ 482 - memset(other_channel, 0, sizeof(other_channel)); 483 - for (i = 0; i < efx->n_channels; i++) { 484 - channel = efx->channel[i]; 485 - if (channel->type->copy) 486 - channel = channel->type->copy(channel); 487 - if (!channel) { 488 - rc = -ENOMEM; 489 - goto out; 490 - } 491 - other_channel[i] = channel; 492 - } 493 - 494 - /* Swap entry counts and channel pointers */ 495 - old_rxq_entries = efx->rxq_entries; 496 - old_txq_entries = efx->txq_entries; 497 - efx->rxq_entries = rxq_entries; 498 - efx->txq_entries = txq_entries; 499 - for (i = 0; i < efx->n_channels; i++) { 500 - channel = efx->channel[i]; 501 - efx->channel[i] = other_channel[i]; 502 - other_channel[i] = channel; 503 - } 504 - 505 - /* Restart buffer table allocation */ 506 - efx->next_buffer_table = next_buffer_table; 507 - 508 - for (i = 0; i < efx->n_channels; i++) { 509 - channel = efx->channel[i]; 510 - if (!channel->type->copy) 511 - continue; 512 - rc = efx_probe_channel(channel); 513 - if (rc) 514 - goto rollback; 515 - efx_init_napi_channel(efx->channel[i]); 516 - } 517 - 518 - out: 519 - /* Destroy unused channel structures */ 520 - for (i = 0; i < efx->n_channels; i++) { 521 - channel = other_channel[i]; 522 - if (channel && channel->type->copy) { 523 - efx_fini_napi_channel(channel); 524 - efx_remove_channel(channel); 525 - kfree(channel); 526 - } 527 - } 528 - 529 - rc2 = efx_soft_enable_interrupts(efx); 530 - if (rc2) { 531 - rc = rc ? rc : rc2; 532 - netif_err(efx, drv, efx->net_dev, 533 - "unable to restart interrupts on channel reallocation\n"); 534 - efx_schedule_reset(efx, RESET_TYPE_DISABLE); 535 - } else { 536 - efx_start_all(efx); 537 - efx_device_attach_if_not_resetting(efx); 538 - } 539 - return rc; 540 - 541 - rollback: 542 - /* Swap back */ 543 - efx->rxq_entries = old_rxq_entries; 544 - efx->txq_entries = old_txq_entries; 545 - for (i = 0; i < efx->n_channels; i++) { 546 - channel = efx->channel[i]; 547 - efx->channel[i] = other_channel[i]; 548 - other_channel[i] = channel; 549 - } 550 - goto out; 551 - } 552 - 553 247 void efx_schedule_slow_fill(struct efx_rx_queue *rx_queue) 554 248 { 555 249 mod_timer(&rx_queue->slow_fill, jiffies + msecs_to_jiffies(10)); 556 - } 557 - 558 - bool efx_default_channel_want_txqs(struct efx_channel *channel) 559 - { 560 - return channel->channel - channel->efx->tx_channel_offset < 561 - channel->efx->n_tx_channels; 562 - } 563 - 564 - static const struct efx_channel_type efx_default_channel_type = { 565 - .pre_probe = efx_channel_dummy_op_int, 566 - .post_remove = efx_channel_dummy_op_void, 567 - .get_name = efx_get_channel_name, 568 - .copy = efx_copy_channel, 569 - .want_txqs = efx_default_channel_want_txqs, 570 - .keep_eventq = false, 571 - .want_pio = true, 572 - }; 573 - 574 - int efx_channel_dummy_op_int(struct efx_channel *channel) 575 - { 576 - return 0; 577 - } 578 - 579 - void efx_channel_dummy_op_void(struct efx_channel *channel) 580 - { 581 250 } 582 251 583 252 /************************************************************************** ··· 753 1098 754 1099 /* Remove legacy interrupt */ 755 1100 efx->legacy_irq = 0; 756 - } 757 - 758 - int efx_set_channels(struct efx_nic *efx) 759 - { 760 - struct efx_channel *channel; 761 - struct efx_tx_queue *tx_queue; 762 - int xdp_queue_number; 763 - 764 - efx->tx_channel_offset = 765 - efx_separate_tx_channels ? 766 - efx->n_channels - efx->n_tx_channels : 0; 767 - 768 - if (efx->xdp_tx_queue_count) { 769 - EFX_WARN_ON_PARANOID(efx->xdp_tx_queues); 770 - 771 - /* Allocate array for XDP TX queue lookup. */ 772 - efx->xdp_tx_queues = kcalloc(efx->xdp_tx_queue_count, 773 - sizeof(*efx->xdp_tx_queues), 774 - GFP_KERNEL); 775 - if (!efx->xdp_tx_queues) 776 - return -ENOMEM; 777 - } 778 - 779 - /* We need to mark which channels really have RX and TX 780 - * queues, and adjust the TX queue numbers if we have separate 781 - * RX-only and TX-only channels. 782 - */ 783 - xdp_queue_number = 0; 784 - efx_for_each_channel(channel, efx) { 785 - if (channel->channel < efx->n_rx_channels) 786 - channel->rx_queue.core_index = channel->channel; 787 - else 788 - channel->rx_queue.core_index = -1; 789 - 790 - efx_for_each_channel_tx_queue(tx_queue, channel) { 791 - tx_queue->queue -= (efx->tx_channel_offset * 792 - EFX_TXQ_TYPES); 793 - 794 - if (efx_channel_is_xdp_tx(channel) && 795 - xdp_queue_number < efx->xdp_tx_queue_count) { 796 - efx->xdp_tx_queues[xdp_queue_number] = tx_queue; 797 - xdp_queue_number++; 798 - } 799 - } 800 - } 801 - return 0; 802 1101 } 803 1102 804 1103 static int efx_probe_nic(struct efx_nic *efx) ··· 1631 2022 * 1632 2023 **************************************************************************/ 1633 2024 1634 - int efx_init_channels(struct efx_nic *efx) 1635 - { 1636 - unsigned int i; 1637 - 1638 - for (i = 0; i < EFX_MAX_CHANNELS; i++) { 1639 - efx->channel[i] = efx_alloc_channel(efx, i, NULL); 1640 - if (!efx->channel[i]) 1641 - return -ENOMEM; 1642 - efx->msi_context[i].efx = efx; 1643 - efx->msi_context[i].index = i; 1644 - } 1645 - 1646 - /* Higher numbered interrupt modes are less capable! */ 1647 - if (WARN_ON_ONCE(efx->type->max_interrupt_mode > 1648 - efx->type->min_interrupt_mode)) { 1649 - return -EIO; 1650 - } 1651 - efx->interrupt_mode = max(efx->type->max_interrupt_mode, 1652 - interrupt_mode); 1653 - efx->interrupt_mode = min(efx->type->min_interrupt_mode, 1654 - interrupt_mode); 1655 - 1656 - return 0; 1657 - } 1658 - 1659 2025 void efx_update_sw_stats(struct efx_nic *efx, u64 *stats) 1660 2026 { 1661 2027 u64 n_rx_nodesc_trunc = 0; ··· 2412 2828 * Kernel module interface 2413 2829 * 2414 2830 *************************************************************************/ 2415 - 2416 - module_param(interrupt_mode, uint, 0444); 2417 - MODULE_PARM_DESC(interrupt_mode, 2418 - "Interrupt mode (0=>MSIX 1=>MSI 2=>legacy)"); 2419 2831 2420 2832 static int __init efx_init_module(void) 2421 2833 {
-4
drivers/net/ethernet/sfc/efx.h
··· 203 203 return ctx->context_id != EFX_EF10_RSS_CONTEXT_INVALID; 204 204 } 205 205 206 - /* Channels */ 207 - int efx_channel_dummy_op_int(struct efx_channel *channel); 208 - void efx_channel_dummy_op_void(struct efx_channel *channel); 209 - 210 206 /* Ethtool support */ 211 207 extern const struct ethtool_ops efx_ethtool_ops; 212 208
+440
drivers/net/ethernet/sfc/efx_channels.c
··· 18 18 #include "nic.h" 19 19 #include "sriov.h" 20 20 21 + /* This is the first interrupt mode to try out of: 22 + * 0 => MSI-X 23 + * 1 => MSI 24 + * 2 => legacy 25 + */ 26 + static unsigned int interrupt_mode; 27 + module_param(interrupt_mode, uint, 0444); 28 + MODULE_PARM_DESC(interrupt_mode, 29 + "Interrupt mode (0=>MSIX 1=>MSI 2=>legacy)"); 30 + 21 31 static unsigned int irq_adapt_low_thresh = 8000; 22 32 module_param(irq_adapt_low_thresh, uint, 0644); 23 33 MODULE_PARM_DESC(irq_adapt_low_thresh, ··· 42 32 * NAPI devices. 43 33 */ 44 34 static int napi_weight = 64; 35 + 36 + /*************** 37 + * Housekeeping 38 + ***************/ 39 + 40 + int efx_channel_dummy_op_int(struct efx_channel *channel) 41 + { 42 + return 0; 43 + } 44 + 45 + void efx_channel_dummy_op_void(struct efx_channel *channel) 46 + { 47 + } 48 + 49 + static const struct efx_channel_type efx_default_channel_type = { 50 + .pre_probe = efx_channel_dummy_op_int, 51 + .post_remove = efx_channel_dummy_op_void, 52 + .get_name = efx_get_channel_name, 53 + .copy = efx_copy_channel, 54 + .want_txqs = efx_default_channel_want_txqs, 55 + .keep_eventq = false, 56 + .want_pio = true, 57 + }; 58 + 59 + /************************************************************************** 60 + * 61 + * Channel handling 62 + * 63 + *************************************************************************/ 64 + 65 + /* Allocate and initialise a channel structure. */ 66 + struct efx_channel * 67 + efx_alloc_channel(struct efx_nic *efx, int i, struct efx_channel *old_channel) 68 + { 69 + struct efx_rx_queue *rx_queue; 70 + struct efx_tx_queue *tx_queue; 71 + struct efx_channel *channel; 72 + int j; 73 + 74 + channel = kzalloc(sizeof(*channel), GFP_KERNEL); 75 + if (!channel) 76 + return NULL; 77 + 78 + channel->efx = efx; 79 + channel->channel = i; 80 + channel->type = &efx_default_channel_type; 81 + 82 + for (j = 0; j < EFX_TXQ_TYPES; j++) { 83 + tx_queue = &channel->tx_queue[j]; 84 + tx_queue->efx = efx; 85 + tx_queue->queue = i * EFX_TXQ_TYPES + j; 86 + tx_queue->channel = channel; 87 + } 88 + 89 + #ifdef CONFIG_RFS_ACCEL 90 + INIT_DELAYED_WORK(&channel->filter_work, efx_filter_rfs_expire); 91 + #endif 92 + 93 + rx_queue = &channel->rx_queue; 94 + rx_queue->efx = efx; 95 + timer_setup(&rx_queue->slow_fill, efx_rx_slow_fill, 0); 96 + 97 + return channel; 98 + } 99 + 100 + int efx_init_channels(struct efx_nic *efx) 101 + { 102 + unsigned int i; 103 + 104 + for (i = 0; i < EFX_MAX_CHANNELS; i++) { 105 + efx->channel[i] = efx_alloc_channel(efx, i, NULL); 106 + if (!efx->channel[i]) 107 + return -ENOMEM; 108 + efx->msi_context[i].efx = efx; 109 + efx->msi_context[i].index = i; 110 + } 111 + 112 + /* Higher numbered interrupt modes are less capable! */ 113 + if (WARN_ON_ONCE(efx->type->max_interrupt_mode > 114 + efx->type->min_interrupt_mode)) { 115 + return -EIO; 116 + } 117 + efx->interrupt_mode = max(efx->type->max_interrupt_mode, 118 + interrupt_mode); 119 + efx->interrupt_mode = min(efx->type->min_interrupt_mode, 120 + interrupt_mode); 121 + 122 + return 0; 123 + } 124 + 125 + void efx_fini_channels(struct efx_nic *efx) 126 + { 127 + unsigned int i; 128 + 129 + for (i = 0; i < EFX_MAX_CHANNELS; i++) 130 + if (efx->channel[i]) { 131 + kfree(efx->channel[i]); 132 + efx->channel[i] = NULL; 133 + } 134 + } 135 + 136 + /* Allocate and initialise a channel structure, copying parameters 137 + * (but not resources) from an old channel structure. 138 + */ 139 + struct efx_channel *efx_copy_channel(const struct efx_channel *old_channel) 140 + { 141 + struct efx_rx_queue *rx_queue; 142 + struct efx_tx_queue *tx_queue; 143 + struct efx_channel *channel; 144 + int j; 145 + 146 + channel = kmalloc(sizeof(*channel), GFP_KERNEL); 147 + if (!channel) 148 + return NULL; 149 + 150 + *channel = *old_channel; 151 + 152 + channel->napi_dev = NULL; 153 + INIT_HLIST_NODE(&channel->napi_str.napi_hash_node); 154 + channel->napi_str.napi_id = 0; 155 + channel->napi_str.state = 0; 156 + memset(&channel->eventq, 0, sizeof(channel->eventq)); 157 + 158 + for (j = 0; j < EFX_TXQ_TYPES; j++) { 159 + tx_queue = &channel->tx_queue[j]; 160 + if (tx_queue->channel) 161 + tx_queue->channel = channel; 162 + tx_queue->buffer = NULL; 163 + memset(&tx_queue->txd, 0, sizeof(tx_queue->txd)); 164 + } 165 + 166 + rx_queue = &channel->rx_queue; 167 + rx_queue->buffer = NULL; 168 + memset(&rx_queue->rxd, 0, sizeof(rx_queue->rxd)); 169 + timer_setup(&rx_queue->slow_fill, efx_rx_slow_fill, 0); 170 + #ifdef CONFIG_RFS_ACCEL 171 + INIT_DELAYED_WORK(&channel->filter_work, efx_filter_rfs_expire); 172 + #endif 173 + 174 + return channel; 175 + } 176 + 177 + static int efx_probe_channel(struct efx_channel *channel) 178 + { 179 + struct efx_tx_queue *tx_queue; 180 + struct efx_rx_queue *rx_queue; 181 + int rc; 182 + 183 + netif_dbg(channel->efx, probe, channel->efx->net_dev, 184 + "creating channel %d\n", channel->channel); 185 + 186 + rc = channel->type->pre_probe(channel); 187 + if (rc) 188 + goto fail; 189 + 190 + rc = efx_probe_eventq(channel); 191 + if (rc) 192 + goto fail; 193 + 194 + efx_for_each_channel_tx_queue(tx_queue, channel) { 195 + rc = efx_probe_tx_queue(tx_queue); 196 + if (rc) 197 + goto fail; 198 + } 199 + 200 + efx_for_each_channel_rx_queue(rx_queue, channel) { 201 + rc = efx_probe_rx_queue(rx_queue); 202 + if (rc) 203 + goto fail; 204 + } 205 + 206 + channel->rx_list = NULL; 207 + 208 + return 0; 209 + 210 + fail: 211 + efx_remove_channel(channel); 212 + return rc; 213 + } 214 + 215 + void efx_get_channel_name(struct efx_channel *channel, char *buf, size_t len) 216 + { 217 + struct efx_nic *efx = channel->efx; 218 + const char *type; 219 + int number; 220 + 221 + number = channel->channel; 222 + 223 + if (number >= efx->xdp_channel_offset && 224 + !WARN_ON_ONCE(!efx->n_xdp_channels)) { 225 + type = "-xdp"; 226 + number -= efx->xdp_channel_offset; 227 + } else if (efx->tx_channel_offset == 0) { 228 + type = ""; 229 + } else if (number < efx->tx_channel_offset) { 230 + type = "-rx"; 231 + } else { 232 + type = "-tx"; 233 + number -= efx->tx_channel_offset; 234 + } 235 + snprintf(buf, len, "%s%s-%d", efx->name, type, number); 236 + } 237 + 238 + void efx_set_channel_names(struct efx_nic *efx) 239 + { 240 + struct efx_channel *channel; 241 + 242 + efx_for_each_channel(channel, efx) 243 + channel->type->get_name(channel, 244 + efx->msi_context[channel->channel].name, 245 + sizeof(efx->msi_context[0].name)); 246 + } 247 + 248 + int efx_probe_channels(struct efx_nic *efx) 249 + { 250 + struct efx_channel *channel; 251 + int rc; 252 + 253 + /* Restart special buffer allocation */ 254 + efx->next_buffer_table = 0; 255 + 256 + /* Probe channels in reverse, so that any 'extra' channels 257 + * use the start of the buffer table. This allows the traffic 258 + * channels to be resized without moving them or wasting the 259 + * entries before them. 260 + */ 261 + efx_for_each_channel_rev(channel, efx) { 262 + rc = efx_probe_channel(channel); 263 + if (rc) { 264 + netif_err(efx, probe, efx->net_dev, 265 + "failed to create channel %d\n", 266 + channel->channel); 267 + goto fail; 268 + } 269 + } 270 + efx_set_channel_names(efx); 271 + 272 + return 0; 273 + 274 + fail: 275 + efx_remove_channels(efx); 276 + return rc; 277 + } 278 + 279 + void efx_remove_channel(struct efx_channel *channel) 280 + { 281 + struct efx_tx_queue *tx_queue; 282 + struct efx_rx_queue *rx_queue; 283 + 284 + netif_dbg(channel->efx, drv, channel->efx->net_dev, 285 + "destroy chan %d\n", channel->channel); 286 + 287 + efx_for_each_channel_rx_queue(rx_queue, channel) 288 + efx_remove_rx_queue(rx_queue); 289 + efx_for_each_possible_channel_tx_queue(tx_queue, channel) 290 + efx_remove_tx_queue(tx_queue); 291 + efx_remove_eventq(channel); 292 + channel->type->post_remove(channel); 293 + } 294 + 295 + void efx_remove_channels(struct efx_nic *efx) 296 + { 297 + struct efx_channel *channel; 298 + 299 + efx_for_each_channel(channel, efx) 300 + efx_remove_channel(channel); 301 + 302 + kfree(efx->xdp_tx_queues); 303 + } 304 + 305 + int efx_realloc_channels(struct efx_nic *efx, u32 rxq_entries, u32 txq_entries) 306 + { 307 + struct efx_channel *other_channel[EFX_MAX_CHANNELS], *channel; 308 + unsigned int i, next_buffer_table = 0; 309 + u32 old_rxq_entries, old_txq_entries; 310 + int rc, rc2; 311 + 312 + rc = efx_check_disabled(efx); 313 + if (rc) 314 + return rc; 315 + 316 + /* Not all channels should be reallocated. We must avoid 317 + * reallocating their buffer table entries. 318 + */ 319 + efx_for_each_channel(channel, efx) { 320 + struct efx_rx_queue *rx_queue; 321 + struct efx_tx_queue *tx_queue; 322 + 323 + if (channel->type->copy) 324 + continue; 325 + next_buffer_table = max(next_buffer_table, 326 + channel->eventq.index + 327 + channel->eventq.entries); 328 + efx_for_each_channel_rx_queue(rx_queue, channel) 329 + next_buffer_table = max(next_buffer_table, 330 + rx_queue->rxd.index + 331 + rx_queue->rxd.entries); 332 + efx_for_each_channel_tx_queue(tx_queue, channel) 333 + next_buffer_table = max(next_buffer_table, 334 + tx_queue->txd.index + 335 + tx_queue->txd.entries); 336 + } 337 + 338 + efx_device_detach_sync(efx); 339 + efx_stop_all(efx); 340 + efx_soft_disable_interrupts(efx); 341 + 342 + /* Clone channels (where possible) */ 343 + memset(other_channel, 0, sizeof(other_channel)); 344 + for (i = 0; i < efx->n_channels; i++) { 345 + channel = efx->channel[i]; 346 + if (channel->type->copy) 347 + channel = channel->type->copy(channel); 348 + if (!channel) { 349 + rc = -ENOMEM; 350 + goto out; 351 + } 352 + other_channel[i] = channel; 353 + } 354 + 355 + /* Swap entry counts and channel pointers */ 356 + old_rxq_entries = efx->rxq_entries; 357 + old_txq_entries = efx->txq_entries; 358 + efx->rxq_entries = rxq_entries; 359 + efx->txq_entries = txq_entries; 360 + for (i = 0; i < efx->n_channels; i++) { 361 + channel = efx->channel[i]; 362 + efx->channel[i] = other_channel[i]; 363 + other_channel[i] = channel; 364 + } 365 + 366 + /* Restart buffer table allocation */ 367 + efx->next_buffer_table = next_buffer_table; 368 + 369 + for (i = 0; i < efx->n_channels; i++) { 370 + channel = efx->channel[i]; 371 + if (!channel->type->copy) 372 + continue; 373 + rc = efx_probe_channel(channel); 374 + if (rc) 375 + goto rollback; 376 + efx_init_napi_channel(efx->channel[i]); 377 + } 378 + 379 + out: 380 + /* Destroy unused channel structures */ 381 + for (i = 0; i < efx->n_channels; i++) { 382 + channel = other_channel[i]; 383 + if (channel && channel->type->copy) { 384 + efx_fini_napi_channel(channel); 385 + efx_remove_channel(channel); 386 + kfree(channel); 387 + } 388 + } 389 + 390 + rc2 = efx_soft_enable_interrupts(efx); 391 + if (rc2) { 392 + rc = rc ? rc : rc2; 393 + netif_err(efx, drv, efx->net_dev, 394 + "unable to restart interrupts on channel reallocation\n"); 395 + efx_schedule_reset(efx, RESET_TYPE_DISABLE); 396 + } else { 397 + efx_start_all(efx); 398 + efx_device_attach_if_not_resetting(efx); 399 + } 400 + return rc; 401 + 402 + rollback: 403 + /* Swap back */ 404 + efx->rxq_entries = old_rxq_entries; 405 + efx->txq_entries = old_txq_entries; 406 + for (i = 0; i < efx->n_channels; i++) { 407 + channel = efx->channel[i]; 408 + efx->channel[i] = other_channel[i]; 409 + other_channel[i] = channel; 410 + } 411 + goto out; 412 + } 413 + 414 + int efx_set_channels(struct efx_nic *efx) 415 + { 416 + struct efx_channel *channel; 417 + struct efx_tx_queue *tx_queue; 418 + int xdp_queue_number; 419 + 420 + efx->tx_channel_offset = 421 + efx_separate_tx_channels ? 422 + efx->n_channels - efx->n_tx_channels : 0; 423 + 424 + if (efx->xdp_tx_queue_count) { 425 + EFX_WARN_ON_PARANOID(efx->xdp_tx_queues); 426 + 427 + /* Allocate array for XDP TX queue lookup. */ 428 + efx->xdp_tx_queues = kcalloc(efx->xdp_tx_queue_count, 429 + sizeof(*efx->xdp_tx_queues), 430 + GFP_KERNEL); 431 + if (!efx->xdp_tx_queues) 432 + return -ENOMEM; 433 + } 434 + 435 + /* We need to mark which channels really have RX and TX 436 + * queues, and adjust the TX queue numbers if we have separate 437 + * RX-only and TX-only channels. 438 + */ 439 + xdp_queue_number = 0; 440 + efx_for_each_channel(channel, efx) { 441 + if (channel->channel < efx->n_rx_channels) 442 + channel->rx_queue.core_index = channel->channel; 443 + else 444 + channel->rx_queue.core_index = -1; 445 + 446 + efx_for_each_channel_tx_queue(tx_queue, channel) { 447 + tx_queue->queue -= (efx->tx_channel_offset * 448 + EFX_TXQ_TYPES); 449 + 450 + if (efx_channel_is_xdp_tx(channel) && 451 + xdp_queue_number < efx->xdp_tx_queue_count) { 452 + efx->xdp_tx_queues[xdp_queue_number] = tx_queue; 453 + xdp_queue_number++; 454 + } 455 + } 456 + } 457 + return 0; 458 + } 459 + 460 + bool efx_default_channel_want_txqs(struct efx_channel *channel) 461 + { 462 + return channel->channel - channel->efx->tx_channel_offset < 463 + channel->efx->n_tx_channels; 464 + } 45 465 46 466 /************* 47 467 * START/STOP
-11
drivers/net/ethernet/sfc/efx_common.c
··· 884 884 return rc; 885 885 } 886 886 887 - void efx_fini_channels(struct efx_nic *efx) 888 - { 889 - unsigned int i; 890 - 891 - for (i = 0; i < EFX_MAX_CHANNELS; i++) 892 - if (efx->channel[i]) { 893 - kfree(efx->channel[i]); 894 - efx->channel[i] = NULL; 895 - } 896 - } 897 - 898 887 void efx_fini_struct(struct efx_nic *efx) 899 888 { 900 889 #ifdef CONFIG_RFS_ACCEL
+1
drivers/net/ethernet/sfc/siena_sriov.c
··· 7 7 #include <linux/module.h> 8 8 #include "net_driver.h" 9 9 #include "efx.h" 10 + #include "efx_channels.h" 10 11 #include "nic.h" 11 12 #include "io.h" 12 13 #include "mcdi.h"