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

bgmac: drop ring->num_slots

The ring size is always known at compile time, so make the code a bit
more efficient

Signed-off-by: Felix Fietkau <nbd@openwrt.org>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Felix Fietkau and committed by
David S. Miller
29ba877e 4668ae1f

+15 -15
+14 -13
drivers/net/ethernet/broadcom/bgmac.c
··· 123 123 struct bgmac_dma_desc *dma_desc; 124 124 u32 ctl1; 125 125 126 - if (i == ring->num_slots - 1) 126 + if (i == BGMAC_TX_RING_SLOTS - 1) 127 127 ctl0 |= BGMAC_DESC_CTL0_EOT; 128 128 129 129 ctl1 = len & BGMAC_DESC_CTL1_LEN; ··· 382 382 struct bgmac_dma_desc *dma_desc = ring->cpu_base + desc_idx; 383 383 u32 ctl0 = 0, ctl1 = 0; 384 384 385 - if (desc_idx == ring->num_slots - 1) 385 + if (desc_idx == BGMAC_RX_RING_SLOTS - 1) 386 386 ctl0 |= BGMAC_DESC_CTL0_EOT; 387 387 ctl1 |= BGMAC_RX_BUF_SIZE & BGMAC_DESC_CTL1_LEN; 388 388 /* Is there any BGMAC device that requires extension? */ ··· 521 521 struct bgmac_slot_info *slot; 522 522 int i; 523 523 524 - for (i = 0; i < ring->num_slots; i++) { 524 + for (i = 0; i < BGMAC_TX_RING_SLOTS; i++) { 525 525 int len = dma_desc[i].ctl1 & BGMAC_DESC_CTL1_LEN; 526 526 527 527 slot = &ring->slots[i]; ··· 546 546 struct bgmac_slot_info *slot; 547 547 int i; 548 548 549 - for (i = 0; i < ring->num_slots; i++) { 549 + for (i = 0; i < BGMAC_RX_RING_SLOTS; i++) { 550 550 slot = &ring->slots[i]; 551 551 if (!slot->dma_addr) 552 552 continue; ··· 560 560 } 561 561 562 562 static void bgmac_dma_ring_desc_free(struct bgmac *bgmac, 563 - struct bgmac_dma_ring *ring) 563 + struct bgmac_dma_ring *ring, 564 + int num_slots) 564 565 { 565 566 struct device *dma_dev = bgmac->core->dma_dev; 566 567 int size; ··· 570 569 return; 571 570 572 571 /* Free ring of descriptors */ 573 - size = ring->num_slots * sizeof(struct bgmac_dma_desc); 572 + size = num_slots * sizeof(struct bgmac_dma_desc); 574 573 dma_free_coherent(dma_dev, size, ring->cpu_base, 575 574 ring->dma_base); 576 575 } ··· 591 590 int i; 592 591 593 592 for (i = 0; i < BGMAC_MAX_TX_RINGS; i++) 594 - bgmac_dma_ring_desc_free(bgmac, &bgmac->tx_ring[i]); 593 + bgmac_dma_ring_desc_free(bgmac, &bgmac->tx_ring[i], 594 + BGMAC_TX_RING_SLOTS); 595 595 596 596 for (i = 0; i < BGMAC_MAX_RX_RINGS; i++) 597 - bgmac_dma_ring_desc_free(bgmac, &bgmac->rx_ring[i]); 597 + bgmac_dma_ring_desc_free(bgmac, &bgmac->rx_ring[i], 598 + BGMAC_RX_RING_SLOTS); 598 599 } 599 600 600 601 static int bgmac_dma_alloc(struct bgmac *bgmac) ··· 619 616 620 617 for (i = 0; i < BGMAC_MAX_TX_RINGS; i++) { 621 618 ring = &bgmac->tx_ring[i]; 622 - ring->num_slots = BGMAC_TX_RING_SLOTS; 623 619 ring->mmio_base = ring_base[i]; 624 620 625 621 /* Alloc ring of descriptors */ 626 - size = ring->num_slots * sizeof(struct bgmac_dma_desc); 622 + size = BGMAC_TX_RING_SLOTS * sizeof(struct bgmac_dma_desc); 627 623 ring->cpu_base = dma_zalloc_coherent(dma_dev, size, 628 624 &ring->dma_base, 629 625 GFP_KERNEL); ··· 644 642 645 643 for (i = 0; i < BGMAC_MAX_RX_RINGS; i++) { 646 644 ring = &bgmac->rx_ring[i]; 647 - ring->num_slots = BGMAC_RX_RING_SLOTS; 648 645 ring->mmio_base = ring_base[i]; 649 646 650 647 /* Alloc ring of descriptors */ 651 - size = ring->num_slots * sizeof(struct bgmac_dma_desc); 648 + size = BGMAC_RX_RING_SLOTS * sizeof(struct bgmac_dma_desc); 652 649 ring->cpu_base = dma_zalloc_coherent(dma_dev, size, 653 650 &ring->dma_base, 654 651 GFP_KERNEL); ··· 710 709 711 710 ring->start = 0; 712 711 ring->end = 0; 713 - for (j = 0; j < ring->num_slots; j++) { 712 + for (j = 0; j < BGMAC_RX_RING_SLOTS; j++) { 714 713 err = bgmac_dma_rx_skb_for_slot(bgmac, &ring->slots[j]); 715 714 if (err) 716 715 goto error;
+1 -2
drivers/net/ethernet/broadcom/bgmac.h
··· 419 419 u32 start; 420 420 u32 end; 421 421 422 - u16 num_slots; 423 - u16 mmio_base; 424 422 struct bgmac_dma_desc *cpu_base; 425 423 dma_addr_t dma_base; 426 424 u32 index_base; /* Used for unaligned rings only, otherwise 0 */ 425 + u16 mmio_base; 427 426 bool unaligned; 428 427 429 428 struct bgmac_slot_info slots[BGMAC_RX_RING_SLOTS];