| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-or-later |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | |
|---|
| 3 | 4 | Broadcom B43legacy wireless driver |
|---|
| .. | .. |
|---|
| 10 | 11 | Copyright (C) 2002 David S. Miller |
|---|
| 11 | 12 | Copyright (C) Pekka Pietikainen |
|---|
| 12 | 13 | |
|---|
| 13 | | - This program is free software; you can redistribute it and/or modify |
|---|
| 14 | | - it under the terms of the GNU General Public License as published by |
|---|
| 15 | | - the Free Software Foundation; either version 2 of the License, or |
|---|
| 16 | | - (at your option) any later version. |
|---|
| 17 | | - |
|---|
| 18 | | - This program is distributed in the hope that it will be useful, |
|---|
| 19 | | - but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 20 | | - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 21 | | - GNU General Public License for more details. |
|---|
| 22 | | - |
|---|
| 23 | | - You should have received a copy of the GNU General Public License |
|---|
| 24 | | - along with this program; see the file COPYING. If not, write to |
|---|
| 25 | | - the Free Software Foundation, Inc., 51 Franklin Steet, Fifth Floor, |
|---|
| 26 | | - Boston, MA 02110-1301, USA. |
|---|
| 27 | 14 | |
|---|
| 28 | 15 | */ |
|---|
| 29 | 16 | |
|---|
| .. | .. |
|---|
| 202 | 189 | switch (queue_priority) { |
|---|
| 203 | 190 | default: |
|---|
| 204 | 191 | B43legacy_WARN_ON(1); |
|---|
| 205 | | - /* fallthrough */ |
|---|
| 192 | + fallthrough; |
|---|
| 206 | 193 | case 0: |
|---|
| 207 | 194 | ring = dev->dma.tx_ring3; |
|---|
| 208 | 195 | break; |
|---|
| .. | .. |
|---|
| 331 | 318 | static int alloc_ringmemory(struct b43legacy_dmaring *ring) |
|---|
| 332 | 319 | { |
|---|
| 333 | 320 | /* GFP flags must match the flags in free_ringmemory()! */ |
|---|
| 334 | | - ring->descbase = dma_zalloc_coherent(ring->dev->dev->dma_dev, |
|---|
| 335 | | - B43legacy_DMA_RINGMEMSIZE, |
|---|
| 336 | | - &(ring->dmabase), GFP_KERNEL); |
|---|
| 321 | + ring->descbase = dma_alloc_coherent(ring->dev->dev->dma_dev, |
|---|
| 322 | + B43legacy_DMA_RINGMEMSIZE, |
|---|
| 323 | + &(ring->dmabase), GFP_KERNEL); |
|---|
| 337 | 324 | if (!ring->descbase) |
|---|
| 338 | 325 | return -ENOMEM; |
|---|
| 339 | 326 | |
|---|
| .. | .. |
|---|
| 616 | 603 | } |
|---|
| 617 | 604 | } |
|---|
| 618 | 605 | |
|---|
| 619 | | -static u64 supported_dma_mask(struct b43legacy_wldev *dev) |
|---|
| 606 | +static enum b43legacy_dmatype b43legacy_engine_type(struct b43legacy_wldev *dev) |
|---|
| 620 | 607 | { |
|---|
| 621 | 608 | u32 tmp; |
|---|
| 622 | 609 | u16 mmio_base; |
|---|
| .. | .. |
|---|
| 628 | 615 | tmp = b43legacy_read32(dev, mmio_base + |
|---|
| 629 | 616 | B43legacy_DMA32_TXCTL); |
|---|
| 630 | 617 | if (tmp & B43legacy_DMA32_TXADDREXT_MASK) |
|---|
| 631 | | - return DMA_BIT_MASK(32); |
|---|
| 632 | | - |
|---|
| 633 | | - return DMA_BIT_MASK(30); |
|---|
| 634 | | -} |
|---|
| 635 | | - |
|---|
| 636 | | -static enum b43legacy_dmatype dma_mask_to_engine_type(u64 dmamask) |
|---|
| 637 | | -{ |
|---|
| 638 | | - if (dmamask == DMA_BIT_MASK(30)) |
|---|
| 639 | | - return B43legacy_DMA_30BIT; |
|---|
| 640 | | - if (dmamask == DMA_BIT_MASK(32)) |
|---|
| 641 | 618 | return B43legacy_DMA_32BIT; |
|---|
| 642 | | - B43legacy_WARN_ON(1); |
|---|
| 643 | 619 | return B43legacy_DMA_30BIT; |
|---|
| 644 | 620 | } |
|---|
| 645 | 621 | |
|---|
| .. | .. |
|---|
| 797 | 773 | dma->tx_ring0 = NULL; |
|---|
| 798 | 774 | } |
|---|
| 799 | 775 | |
|---|
| 800 | | -static int b43legacy_dma_set_mask(struct b43legacy_wldev *dev, u64 mask) |
|---|
| 801 | | -{ |
|---|
| 802 | | - u64 orig_mask = mask; |
|---|
| 803 | | - bool fallback = false; |
|---|
| 804 | | - int err; |
|---|
| 805 | | - |
|---|
| 806 | | - /* Try to set the DMA mask. If it fails, try falling back to a |
|---|
| 807 | | - * lower mask, as we can always also support a lower one. */ |
|---|
| 808 | | - while (1) { |
|---|
| 809 | | - err = dma_set_mask_and_coherent(dev->dev->dma_dev, mask); |
|---|
| 810 | | - if (!err) |
|---|
| 811 | | - break; |
|---|
| 812 | | - if (mask == DMA_BIT_MASK(64)) { |
|---|
| 813 | | - mask = DMA_BIT_MASK(32); |
|---|
| 814 | | - fallback = true; |
|---|
| 815 | | - continue; |
|---|
| 816 | | - } |
|---|
| 817 | | - if (mask == DMA_BIT_MASK(32)) { |
|---|
| 818 | | - mask = DMA_BIT_MASK(30); |
|---|
| 819 | | - fallback = true; |
|---|
| 820 | | - continue; |
|---|
| 821 | | - } |
|---|
| 822 | | - b43legacyerr(dev->wl, "The machine/kernel does not support " |
|---|
| 823 | | - "the required %u-bit DMA mask\n", |
|---|
| 824 | | - (unsigned int)dma_mask_to_engine_type(orig_mask)); |
|---|
| 825 | | - return -EOPNOTSUPP; |
|---|
| 826 | | - } |
|---|
| 827 | | - if (fallback) { |
|---|
| 828 | | - b43legacyinfo(dev->wl, "DMA mask fallback from %u-bit to %u-" |
|---|
| 829 | | - "bit\n", |
|---|
| 830 | | - (unsigned int)dma_mask_to_engine_type(orig_mask), |
|---|
| 831 | | - (unsigned int)dma_mask_to_engine_type(mask)); |
|---|
| 832 | | - } |
|---|
| 833 | | - |
|---|
| 834 | | - return 0; |
|---|
| 835 | | -} |
|---|
| 836 | | - |
|---|
| 837 | 776 | int b43legacy_dma_init(struct b43legacy_wldev *dev) |
|---|
| 838 | 777 | { |
|---|
| 839 | 778 | struct b43legacy_dma *dma = &dev->dma; |
|---|
| 840 | 779 | struct b43legacy_dmaring *ring; |
|---|
| 780 | + enum b43legacy_dmatype type = b43legacy_engine_type(dev); |
|---|
| 841 | 781 | int err; |
|---|
| 842 | | - u64 dmamask; |
|---|
| 843 | | - enum b43legacy_dmatype type; |
|---|
| 844 | 782 | |
|---|
| 845 | | - dmamask = supported_dma_mask(dev); |
|---|
| 846 | | - type = dma_mask_to_engine_type(dmamask); |
|---|
| 847 | | - err = b43legacy_dma_set_mask(dev, dmamask); |
|---|
| 783 | + err = dma_set_mask_and_coherent(dev->dev->dma_dev, DMA_BIT_MASK(type)); |
|---|
| 848 | 784 | if (err) { |
|---|
| 849 | 785 | #ifdef CONFIG_B43LEGACY_PIO |
|---|
| 850 | 786 | b43legacywarn(dev->wl, "DMA for this device not supported. " |
|---|
| .. | .. |
|---|
| 1149 | 1085 | return -ENOSPC; |
|---|
| 1150 | 1086 | } |
|---|
| 1151 | 1087 | |
|---|
| 1152 | | - if (unlikely(WARN_ON(free_slots(ring) < SLOTS_PER_PACKET))) { |
|---|
| 1088 | + if (WARN_ON(free_slots(ring) < SLOTS_PER_PACKET)) { |
|---|
| 1153 | 1089 | /* If we get here, we have a real error with the queue |
|---|
| 1154 | 1090 | * full, but queues not stopped. */ |
|---|
| 1155 | 1091 | b43legacyerr(dev->wl, "DMA queue overflow\n"); |
|---|