forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-01-31 f70575805708cabdedea7498aaa3f710fde4d920
kernel/drivers/isdn/hardware/mISDN/hfcpci.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
23 *
34 * hfcpci.c low level driver for CCD's hfc-pci based cards
....@@ -8,20 +9,6 @@
89 *
910 * Copyright 1999 by Werner Cornelius (werner@isdn-development.de)
1011 * Copyright 2008 by Karsten Keil <kkeil@novell.com>
11
- *
12
- * This program is free software; you can redistribute it and/or modify
13
- * it under the terms of the GNU General Public License as published by
14
- * the Free Software Foundation; either version 2, or (at your option)
15
- * any later version.
16
- *
17
- * This program is distributed in the hope that it will be useful,
18
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20
- * GNU General Public License for more details.
21
- *
22
- * You should have received a copy of the GNU General Public License
23
- * along with this program; if not, write to the Free Software
24
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
2512 *
2613 * Module options:
2714 *
....@@ -41,7 +28,6 @@
4128 * If kernel uses a frequency of 1000 Hz, steps of 8 samples are possible.
4229 * If the kernel uses 100 Hz, steps of 80 samples are possible.
4330 * If the kernel uses 300 Hz, steps of about 26 samples are possible.
44
- *
4531 */
4632
4733 #include <linux/interrupt.h>
....@@ -172,7 +158,8 @@
172158 /* disable memory mapped ports + busmaster */
173159 pci_write_config_word(hc->pdev, PCI_COMMAND, 0);
174160 del_timer(&hc->hw.timer);
175
- pci_free_consistent(hc->pdev, 0x8000, hc->hw.fifos, hc->hw.dmahandle);
161
+ dma_free_coherent(&hc->pdev->dev, 0x8000, hc->hw.fifos,
162
+ hc->hw.dmahandle);
176163 iounmap(hc->hw.pci_io);
177164 }
178165
....@@ -580,8 +567,7 @@
580567 }
581568 maxlen = bchannel_get_rxbuf(bch, fcnt_rx);
582569 if (maxlen < 0) {
583
- pr_warning("B%d: No bufferspace for %d bytes\n",
584
- bch->nr, fcnt_rx);
570
+ pr_warn("B%d: No bufferspace for %d bytes\n", bch->nr, fcnt_rx);
585571 } else {
586572 ptr = skb_put(bch->rx_skb, fcnt_rx);
587573 if (le16_to_cpu(*z2r) + fcnt_rx <= B_FIFO_SIZE + B_SUB_VAL)
....@@ -853,7 +839,7 @@
853839 *z1t = cpu_to_le16(new_z1); /* now send data */
854840 if (bch->tx_idx < bch->tx_skb->len)
855841 return;
856
- dev_kfree_skb(bch->tx_skb);
842
+ dev_kfree_skb_any(bch->tx_skb);
857843 if (get_next_bframe(bch))
858844 goto next_t_frame;
859845 return;
....@@ -909,7 +895,7 @@
909895 }
910896 bz->za[new_f1].z1 = cpu_to_le16(new_z1); /* for next buffer */
911897 bz->f1 = new_f1; /* next frame */
912
- dev_kfree_skb(bch->tx_skb);
898
+ dev_kfree_skb_any(bch->tx_skb);
913899 get_next_bframe(bch);
914900 }
915901
....@@ -1133,8 +1119,7 @@
11331119 if (bch->tx_skb && bch->tx_idx < bch->tx_skb->len)
11341120 hfcpci_fill_fifo(bch);
11351121 else {
1136
- if (bch->tx_skb)
1137
- dev_kfree_skb(bch->tx_skb);
1122
+ dev_kfree_skb_any(bch->tx_skb);
11381123 if (get_next_bframe(bch))
11391124 hfcpci_fill_fifo(bch);
11401125 }
....@@ -1146,8 +1131,7 @@
11461131 if (dch->tx_skb && dch->tx_idx < dch->tx_skb->len)
11471132 hfcpci_fill_dfifo(dch->hw);
11481133 else {
1149
- if (dch->tx_skb)
1150
- dev_kfree_skb(dch->tx_skb);
1134
+ dev_kfree_skb(dch->tx_skb);
11511135 if (get_next_dframe(dch))
11521136 hfcpci_fill_dfifo(dch->hw);
11531137 }
....@@ -1296,7 +1280,7 @@
12961280 case (-1): /* used for init */
12971281 bch->state = -1;
12981282 bch->nr = bc;
1299
- /* fall through */
1283
+ fallthrough;
13001284 case (ISDN_P_NONE):
13011285 if (bch->state == ISDN_P_NONE)
13021286 return 0;
....@@ -1633,16 +1617,19 @@
16331617 test_and_clear_bit(FLG_L2_ACTIVATED, &dch->Flags);
16341618 spin_lock_irqsave(&hc->lock, flags);
16351619 if (hc->hw.protocol == ISDN_P_NT_S0) {
1620
+ struct sk_buff_head free_queue;
1621
+
1622
+ __skb_queue_head_init(&free_queue);
16361623 /* prepare deactivation */
16371624 Write_hfc(hc, HFCPCI_STATES, 0x40);
1638
- skb_queue_purge(&dch->squeue);
1625
+ skb_queue_splice_init(&dch->squeue, &free_queue);
16391626 if (dch->tx_skb) {
1640
- dev_kfree_skb(dch->tx_skb);
1627
+ __skb_queue_tail(&free_queue, dch->tx_skb);
16411628 dch->tx_skb = NULL;
16421629 }
16431630 dch->tx_idx = 0;
16441631 if (dch->rx_skb) {
1645
- dev_kfree_skb(dch->rx_skb);
1632
+ __skb_queue_tail(&free_queue, dch->rx_skb);
16461633 dch->rx_skb = NULL;
16471634 }
16481635 test_and_clear_bit(FLG_TX_BUSY, &dch->Flags);
....@@ -1655,10 +1642,12 @@
16551642 hc->hw.mst_m &= ~HFCPCI_MASTER;
16561643 Write_hfc(hc, HFCPCI_MST_MODE, hc->hw.mst_m);
16571644 ret = 0;
1645
+ spin_unlock_irqrestore(&hc->lock, flags);
1646
+ __skb_queue_purge(&free_queue);
16581647 } else {
16591648 ret = l1_event(dch->l1, hh->prim);
1649
+ spin_unlock_irqrestore(&hc->lock, flags);
16601650 }
1661
- spin_unlock_irqrestore(&hc->lock, flags);
16621651 break;
16631652 }
16641653 if (!ret)
....@@ -2010,32 +1999,46 @@
20101999 pci_set_master(hc->pdev);
20112000 if (!hc->irq) {
20122001 printk(KERN_WARNING "HFC-PCI: No IRQ for PCI card found\n");
2013
- return 1;
2002
+ return -EINVAL;
20142003 }
20152004 hc->hw.pci_io =
20162005 (char __iomem *)(unsigned long)hc->pdev->resource[1].start;
20172006
20182007 if (!hc->hw.pci_io) {
20192008 printk(KERN_WARNING "HFC-PCI: No IO-Mem for PCI card found\n");
2020
- return 1;
2009
+ return -ENOMEM;
20212010 }
20222011 /* Allocate memory for FIFOS */
20232012 /* the memory needs to be on a 32k boundary within the first 4G */
2024
- pci_set_dma_mask(hc->pdev, 0xFFFF8000);
2025
- buffer = pci_alloc_consistent(hc->pdev, 0x8000, &hc->hw.dmahandle);
2013
+ if (dma_set_mask(&hc->pdev->dev, 0xFFFF8000)) {
2014
+ printk(KERN_WARNING
2015
+ "HFC-PCI: No usable DMA configuration!\n");
2016
+ return -EIO;
2017
+ }
2018
+ buffer = dma_alloc_coherent(&hc->pdev->dev, 0x8000, &hc->hw.dmahandle,
2019
+ GFP_KERNEL);
20262020 /* We silently assume the address is okay if nonzero */
20272021 if (!buffer) {
20282022 printk(KERN_WARNING
20292023 "HFC-PCI: Error allocating memory for FIFO!\n");
2030
- return 1;
2024
+ return -ENOMEM;
20312025 }
20322026 hc->hw.fifos = buffer;
20332027 pci_write_config_dword(hc->pdev, 0x80, hc->hw.dmahandle);
20342028 hc->hw.pci_io = ioremap((ulong) hc->hw.pci_io, 256);
2029
+ if (unlikely(!hc->hw.pci_io)) {
2030
+ printk(KERN_WARNING
2031
+ "HFC-PCI: Error in ioremap for PCI!\n");
2032
+ dma_free_coherent(&hc->pdev->dev, 0x8000, hc->hw.fifos,
2033
+ hc->hw.dmahandle);
2034
+ return -ENOMEM;
2035
+ }
2036
+
20352037 printk(KERN_INFO
2036
- "HFC-PCI: defined at mem %#lx fifo %#lx(%#lx) IRQ %d HZ %d\n",
2037
- (u_long) hc->hw.pci_io, (u_long) hc->hw.fifos,
2038
- (u_long) hc->hw.dmahandle, hc->irq, HZ);
2038
+ "HFC-PCI: defined at mem %#lx fifo %p(%pad) IRQ %d HZ %d\n",
2039
+ (u_long) hc->hw.pci_io, hc->hw.fifos,
2040
+ &hc->hw.dmahandle, hc->irq, HZ);
2041
+
20392042 /* enable memory mapped ports, disable busmaster */
20402043 pci_write_config_word(hc->pdev, PCI_COMMAND, PCI_ENA_MEMIO);
20412044 hc->hw.int_m2 = 0;
....@@ -2274,7 +2277,7 @@
22742277 return 0;
22752278
22762279 if (hc->hw.int_m2 & HFCPCI_IRQ_ENABLE) {
2277
- spin_lock(&hc->lock);
2280
+ spin_lock_irq(&hc->lock);
22782281 bch = Sel_BCS(hc, hc->hw.bswapped ? 2 : 1);
22792282 if (bch && bch->state == ISDN_P_B_RAW) { /* B1 rx&tx */
22802283 main_rec_hfcpci(bch);
....@@ -2285,7 +2288,7 @@
22852288 main_rec_hfcpci(bch);
22862289 tx_birq(bch);
22872290 }
2288
- spin_unlock(&hc->lock);
2291
+ spin_unlock_irq(&hc->lock);
22892292 }
22902293 return 0;
22912294 }