forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-01-31 f70575805708cabdedea7498aaa3f710fde4d920
kernel/drivers/net/wan/wanxl.c
....@@ -1,12 +1,9 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * wanXL serial card driver for Linux
34 * host part
45 *
56 * Copyright (C) 2003 Krzysztof Halasa <khc@pm.waw.pl>
6
- *
7
- * This program is free software; you can redistribute it and/or modify it
8
- * under the terms of version 2 of the GNU General Public License
9
- * as published by the Free Software Foundation.
107 *
118 * Status:
129 * - Only DTE (external clock) support with NRZ and NRZI encodings
....@@ -81,7 +78,7 @@
8178 struct sk_buff *rx_skbs[RX_QUEUE_LENGTH];
8279 struct card_status *status; /* shared between host and card */
8380 dma_addr_t status_address;
84
- struct port ports[0]; /* 1 - 4 port structures follow */
81
+ struct port ports[]; /* 1 - 4 port structures follow */
8582 };
8683
8784
....@@ -102,7 +99,7 @@
10299 static inline dma_addr_t pci_map_single_debug(struct pci_dev *pdev, void *ptr,
103100 size_t size, int direction)
104101 {
105
- dma_addr_t addr = pci_map_single(pdev, ptr, size, direction);
102
+ dma_addr_t addr = dma_map_single(&pdev->dev, ptr, size, direction);
106103 if (addr + size > 0x100000000LL)
107104 pr_crit("%s: pci_map_single() returned memory at 0x%llx!\n",
108105 pci_name(pdev), (unsigned long long)addr);
....@@ -183,9 +180,9 @@
183180 dev->stats.tx_bytes += skb->len;
184181 }
185182 desc->stat = PACKET_EMPTY; /* Free descriptor */
186
- pci_unmap_single(port->card->pdev, desc->address, skb->len,
187
- PCI_DMA_TODEVICE);
188
- dev_kfree_skb_irq(skb);
183
+ dma_unmap_single(&port->card->pdev->dev, desc->address,
184
+ skb->len, DMA_TO_DEVICE);
185
+ dev_consume_skb_irq(skb);
189186 port->tx_in = (port->tx_in + 1) % TX_BUFFERS;
190187 }
191188 }
....@@ -210,9 +207,9 @@
210207 if (!skb)
211208 dev->stats.rx_dropped++;
212209 else {
213
- pci_unmap_single(card->pdev, desc->address,
214
- BUFFER_LENGTH,
215
- PCI_DMA_FROMDEVICE);
210
+ dma_unmap_single(&card->pdev->dev,
211
+ desc->address, BUFFER_LENGTH,
212
+ DMA_FROM_DEVICE);
216213 skb_put(skb, desc->length);
217214
218215 #ifdef DEBUG_PKT
....@@ -230,9 +227,10 @@
230227 if (!skb) {
231228 skb = dev_alloc_skb(BUFFER_LENGTH);
232229 desc->address = skb ?
233
- pci_map_single(card->pdev, skb->data,
230
+ dma_map_single(&card->pdev->dev,
231
+ skb->data,
234232 BUFFER_LENGTH,
235
- PCI_DMA_FROMDEVICE) : 0;
233
+ DMA_FROM_DEVICE) : 0;
236234 card->rx_skbs[card->rx_in] = skb;
237235 }
238236 }
....@@ -294,8 +292,8 @@
294292 #endif
295293
296294 port->tx_skbs[port->tx_out] = skb;
297
- desc->address = pci_map_single(port->card->pdev, skb->data, skb->len,
298
- PCI_DMA_TODEVICE);
295
+ desc->address = dma_map_single(&port->card->pdev->dev, skb->data,
296
+ skb->len, DMA_TO_DEVICE);
299297 desc->length = skb->len;
300298 desc->stat = PACKET_FULL;
301299 writel(1 << (DOORBELL_TO_CARD_TX_0 + port->node),
....@@ -454,9 +452,9 @@
454452
455453 if (desc->stat != PACKET_EMPTY) {
456454 desc->stat = PACKET_EMPTY;
457
- pci_unmap_single(port->card->pdev, desc->address,
458
- port->tx_skbs[i]->len,
459
- PCI_DMA_TODEVICE);
455
+ dma_unmap_single(&port->card->pdev->dev,
456
+ desc->address, port->tx_skbs[i]->len,
457
+ DMA_TO_DEVICE);
460458 dev_kfree_skb(port->tx_skbs[i]);
461459 }
462460 }
....@@ -527,9 +525,9 @@
527525
528526 for (i = 0; i < RX_QUEUE_LENGTH; i++)
529527 if (card->rx_skbs[i]) {
530
- pci_unmap_single(card->pdev,
528
+ dma_unmap_single(&card->pdev->dev,
531529 card->status->rx_descs[i].address,
532
- BUFFER_LENGTH, PCI_DMA_FROMDEVICE);
530
+ BUFFER_LENGTH, DMA_FROM_DEVICE);
533531 dev_kfree_skb(card->rx_skbs[i]);
534532 }
535533
....@@ -537,8 +535,8 @@
537535 iounmap(card->plx);
538536
539537 if (card->status)
540
- pci_free_consistent(pdev, sizeof(struct card_status),
541
- card->status, card->status_address);
538
+ dma_free_coherent(&pdev->dev, sizeof(struct card_status),
539
+ card->status, card->status_address);
542540
543541 pci_release_regions(pdev);
544542 pci_disable_device(pdev);
....@@ -565,7 +563,7 @@
565563 u32 plx_phy; /* PLX PCI base address */
566564 u32 mem_phy; /* memory PCI base addr */
567565 u8 __iomem *mem; /* memory virtual base addr */
568
- int i, ports, alloc_size;
566
+ int i, ports;
569567
570568 #ifndef MODULE
571569 pr_info_once("%s\n", version);
....@@ -582,8 +580,8 @@
582580 We set both dma_mask and consistent_dma_mask to 28 bits
583581 and pray pci_alloc_consistent() will use this info. It should
584582 work on most platforms */
585
- if (pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(28)) ||
586
- pci_set_dma_mask(pdev, DMA_BIT_MASK(28))) {
583
+ if (dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(28)) ||
584
+ dma_set_mask(&pdev->dev, DMA_BIT_MASK(28))) {
587585 pr_err("No usable DMA configuration\n");
588586 pci_disable_device(pdev);
589587 return -EIO;
....@@ -601,8 +599,7 @@
601599 default: ports = 4;
602600 }
603601
604
- alloc_size = sizeof(struct card) + ports * sizeof(struct port);
605
- card = kzalloc(alloc_size, GFP_KERNEL);
602
+ card = kzalloc(struct_size(card, ports, ports), GFP_KERNEL);
606603 if (card == NULL) {
607604 pci_release_regions(pdev);
608605 pci_disable_device(pdev);
....@@ -612,9 +609,9 @@
612609 pci_set_drvdata(pdev, card);
613610 card->pdev = pdev;
614611
615
- card->status = pci_alloc_consistent(pdev,
616
- sizeof(struct card_status),
617
- &card->status_address);
612
+ card->status = dma_alloc_coherent(&pdev->dev,
613
+ sizeof(struct card_status),
614
+ &card->status_address, GFP_KERNEL);
618615 if (card->status == NULL) {
619616 wanxl_pci_remove_one(pdev);
620617 return -ENOBUFS;
....@@ -629,8 +626,8 @@
629626 /* FIXME when PCI/DMA subsystems are fixed.
630627 We set both dma_mask and consistent_dma_mask back to 32 bits
631628 to indicate the card can do 32-bit DMA addressing */
632
- if (pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32)) ||
633
- pci_set_dma_mask(pdev, DMA_BIT_MASK(32))) {
629
+ if (dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(32)) ||
630
+ dma_set_mask(&pdev->dev, DMA_BIT_MASK(32))) {
634631 pr_err("No usable DMA configuration\n");
635632 wanxl_pci_remove_one(pdev);
636633 return -EIO;
....@@ -639,7 +636,7 @@
639636 /* set up PLX mapping */
640637 plx_phy = pci_resource_start(pdev, 0);
641638
642
- card->plx = ioremap_nocache(plx_phy, 0x70);
639
+ card->plx = ioremap(plx_phy, 0x70);
643640 if (!card->plx) {
644641 pr_err("ioremap() failed\n");
645642 wanxl_pci_remove_one(pdev);
....@@ -703,12 +700,11 @@
703700 card->rx_skbs[i] = skb;
704701 if (skb)
705702 card->status->rx_descs[i].address =
706
- pci_map_single(card->pdev, skb->data,
707
- BUFFER_LENGTH,
708
- PCI_DMA_FROMDEVICE);
703
+ dma_map_single(&card->pdev->dev, skb->data,
704
+ BUFFER_LENGTH, DMA_FROM_DEVICE);
709705 }
710706
711
- mem = ioremap_nocache(mem_phy, PDM_OFFSET + sizeof(firmware));
707
+ mem = ioremap(mem_phy, PDM_OFFSET + sizeof(firmware));
712708 if (!mem) {
713709 pr_err("ioremap() failed\n");
714710 wanxl_pci_remove_one(pdev);