Skip to content

Commit

Permalink
replace pci_* functions and constants with dma_* functions and constants
Browse files Browse the repository at this point in the history
  • Loading branch information
tomaspinho committed May 30, 2022
1 parent 05aae2a commit f7c84ef
Show file tree
Hide file tree
Showing 5 changed files with 131 additions and 4 deletions.
30 changes: 29 additions & 1 deletion hal/rtl8821c/pci/rtl8821ce_halmac.c
Expand Up @@ -44,8 +44,13 @@ static u8 pci_write_port_not_xmitframe(void *d, u32 size, u8 *pBuf, u8 qsel)
rtw_hal_get_def_var(padapter, HAL_DEF_TX_PAGE_SIZE, &page_size);

/* map TX DESC buf_addr (including TX DESC + tx data) */
#if (LINUX_VERSION_CODE < KERNEL_VERSION(5, 18, 0))
mapping = pci_map_single(pdev, pBuf,
size+TX_WIFI_INFO_SIZE, PCI_DMA_TODEVICE);
size+TX_WIFI_INFO_SIZE, PCI_DMA_TODEVICE);
#else
mapping = dma_map_single(&pdev->dev, pBuf,
size+TX_WIFI_INFO_SIZE, DMA_TO_DEVICE);
#endif


/* Calculate page size.
Expand All @@ -57,12 +62,22 @@ static u8 pci_write_port_not_xmitframe(void *d, u32 size, u8 *pBuf, u8 qsel)
if (((size + TX_WIFI_INFO_SIZE) % page_size) > 0)
page_size_length++;

#if (LINUX_VERSION_CODE < KERNEL_VERSION(5, 18, 0))
txbd = pci_alloc_consistent(pdev,
sizeof(struct tx_buf_desc), &txbd_dma);
#else
txbd = dma_alloc_coherent(&pdev->dev,
sizeof(struct tx_buf_desc), &txbd_dma, GFP_KERNEL);
#endif

if (!txbd) {
#if (LINUX_VERSION_CODE < KERNEL_VERSION(5, 18, 0))
pci_unmap_single(pdev, mapping,
size + TX_WIFI_INFO_SIZE, PCI_DMA_FROMDEVICE);
#else
dma_unmap_single(&pdev->dev, mapping,
size + TX_WIFI_INFO_SIZE, DMA_FROM_DEVICE);
#endif

return _FALSE;
}
Expand Down Expand Up @@ -136,10 +151,19 @@ static u8 pci_write_port_not_xmitframe(void *d, u32 size, u8 *pBuf, u8 qsel)

udelay(100);

#if (LINUX_VERSION_CODE < KERNEL_VERSION(5, 18, 0))
pci_free_consistent(pdev, sizeof(struct tx_buf_desc), txbd, txbd_dma);
#else
dma_free_coherent(&pdev->dev, sizeof(struct tx_buf_desc), txbd, txbd_dma);
#endif

#if (LINUX_VERSION_CODE < KERNEL_VERSION(5, 18, 0))
pci_unmap_single(pdev, mapping,
size + TX_WIFI_INFO_SIZE, PCI_DMA_FROMDEVICE);
#else
dma_unmap_single(&pdev->dev, mapping,
size + TX_WIFI_INFO_SIZE, DMA_FROM_DEVICE);
#endif

return ret;

Expand Down Expand Up @@ -271,7 +295,11 @@ static u8 pci_write_data_rsvd_page_xmitframe(void *d, u8 *pBuf, u32 size)

/*To patch*/

#if (LINUX_VERSION_CODE < KERNEL_VERSION(5, 18, 0))
pci_unmap_single(pdev, mapping, pxmitbuf->len, PCI_DMA_TODEVICE);
#else
dma_unmap_single(&pdev->dev, mapping, pxmitbuf->len, DMA_TO_DEVICE);
#endif

return _TRUE;
}
Expand Down
6 changes: 6 additions & 0 deletions hal/rtl8821c/pci/rtl8821ce_ops.c
Expand Up @@ -86,9 +86,15 @@ static void rtl8821ce_reset_bd(_adapter *padapter)
#ifdef CONFIG_64BIT_DMA
mapping |= (dma_addr_t)GET_TX_BD_PHYSICAL_ADDR0_HIGH(tx_bd) << 32;
#endif
#if (LINUX_VERSION_CODE < KERNEL_VERSION(5, 18, 0))
pci_unmap_single(pdvobjpriv->ppcidev,
mapping,
pxmitbuf->len, PCI_DMA_TODEVICE);
#else
dma_unmap_single(&(pdvobjpriv->ppcidev)->dev,
mapping,
pxmitbuf->len, DMA_TO_DEVICE);
#endif
rtw_free_xmitbuf(t_priv, pxmitbuf);
} else {
RTW_INFO("%s(): qlen(%d) is not zero, but have xmitbuf in pending queue\n",
Expand Down
56 changes: 54 additions & 2 deletions hal/rtl8821c/pci/rtl8821ce_recv.c
Expand Up @@ -208,10 +208,18 @@ static void rtl8821ce_rx_mpdu(_adapter *padapter)
_rtw_init_listhead(&precvframe->u.hdr.list);
precvframe->u.hdr.len = 0;

#if (LINUX_VERSION_CODE < KERNEL_VERSION(5, 18, 0))
pci_unmap_single(pdvobjpriv->ppcidev,
*((dma_addr_t *)skb->cb),
r_priv->rxbuffersize,
PCI_DMA_FROMDEVICE);
#else
dma_unmap_single(&(pdvobjpriv->ppcidev)->dev,
*((dma_addr_t *)skb->cb),
r_priv->rxbuffersize,
DMA_FROM_DEVICE);
#endif


rtl8821c_query_rx_desc(precvframe, skb->data);
pattrib = &precvframe->u.hdr.attrib;
Expand Down Expand Up @@ -244,10 +252,17 @@ static void rtl8821ce_rx_mpdu(_adapter *padapter)

RTW_INFO("rtl8821ce_rx_mpdu:can't allocate memory for skb copy\n");
*((dma_addr_t *) skb->cb) =
#if (LINUX_VERSION_CODE < KERNEL_VERSION(5, 18, 0))
pci_map_single(pdvobjpriv->ppcidev,
skb_tail_pointer(skb),
r_priv->rxbuffersize,
PCI_DMA_FROMDEVICE);
#else
dma_map_single(&(pdvobjpriv->ppcidev)->dev,
skb_tail_pointer(skb),
r_priv->rxbuffersize,
DMA_FROM_DEVICE);
#endif
goto done;
}

Expand All @@ -264,10 +279,17 @@ static void rtl8821ce_rx_mpdu(_adapter *padapter)
rtw_free_recvframe(precvframe, pfree_recv_queue);
}
*((dma_addr_t *) skb->cb) =
#if (LINUX_VERSION_CODE < KERNEL_VERSION(5, 18, 0))
pci_map_single(pdvobjpriv->ppcidev,
skb_tail_pointer(skb),
r_priv->rxbuffersize,
PCI_DMA_FROMDEVICE);
#else
dma_map_single(&(pdvobjpriv->ppcidev)->dev,
skb_tail_pointer(skb),
r_priv->rxbuffersize,
DMA_FROM_DEVICE);
#endif
}
done:

Expand Down Expand Up @@ -369,10 +391,18 @@ int rtl8821ce_init_rxbd_ring(_adapter *padapter)
/* rx_queue_idx 1:RX_CMD_QUEUE */
for (rx_queue_idx = 0; rx_queue_idx < 1; rx_queue_idx++) {
r_priv->rx_ring[rx_queue_idx].buf_desc =
#if (LINUX_VERSION_CODE < KERNEL_VERSION(5, 18, 0))
pci_alloc_consistent(pdev,
sizeof(*r_priv->rx_ring[rx_queue_idx].buf_desc) *
r_priv->rxringcount,
&r_priv->rx_ring[rx_queue_idx].dma);
#else
dma_alloc_coherent(&pdev->dev,
sizeof(*r_priv->rx_ring[rx_queue_idx].buf_desc) *
r_priv->rxringcount,
&r_priv->rx_ring[rx_queue_idx].dma,
GFP_KERNEL);
#endif

if (!r_priv->rx_ring[rx_queue_idx].buf_desc ||
(unsigned long)r_priv->rx_ring[rx_queue_idx].buf_desc &
Expand Down Expand Up @@ -401,9 +431,16 @@ int rtl8821ce_init_rxbd_ring(_adapter *padapter)
/* just set skb->cb to mapping addr
* for pci_unmap_single use
*/
#if (LINUX_VERSION_CODE < KERNEL_VERSION(5, 18, 0))
*mapping = pci_map_single(pdev, skb_tail_pointer(skb),
r_priv->rxbuffersize,
PCI_DMA_FROMDEVICE);
r_priv->rxbuffersize,
PCI_DMA_FROMDEVICE);
#else
*mapping = dma_map_single(&pdev->dev, skb_tail_pointer(skb),
r_priv->rxbuffersize,
DMA_FROM_DEVICE);
#endif


/* Reset FS, LS, Total len */
SET_RX_BD_LS(rx_desc, 0);
Expand Down Expand Up @@ -445,18 +482,33 @@ void rtl8821ce_free_rxbd_ring(_adapter *padapter)
if (!skb)
continue;

#if (LINUX_VERSION_CODE < KERNEL_VERSION(5, 18, 0))
pci_unmap_single(pdev,
*((dma_addr_t *) skb->cb),
r_priv->rxbuffersize,
PCI_DMA_FROMDEVICE);
#else
dma_unmap_single(&pdev->dev,
*((dma_addr_t *) skb->cb),
r_priv->rxbuffersize,
DMA_FROM_DEVICE);
#endif
kfree_skb(skb);
}

#if (LINUX_VERSION_CODE < KERNEL_VERSION(5, 18, 0))
pci_free_consistent(pdev,
sizeof(*r_priv->rx_ring[rx_queue_idx].buf_desc) *
r_priv->rxringcount,
r_priv->rx_ring[rx_queue_idx].buf_desc,
r_priv->rx_ring[rx_queue_idx].dma);
#else
dma_free_coherent(&pdev->dev,
sizeof(*r_priv->rx_ring[rx_queue_idx].buf_desc) *
r_priv->rxringcount,
r_priv->rx_ring[rx_queue_idx].buf_desc,
r_priv->rx_ring[rx_queue_idx].dma);
#endif
r_priv->rx_ring[rx_queue_idx].buf_desc = NULL;
}

Expand Down
26 changes: 26 additions & 0 deletions hal/rtl8821c/pci/rtl8821ce_xmit.c
Expand Up @@ -293,8 +293,13 @@ static void rtl8821ce_update_txbd(struct xmit_frame *pxmitframe,
u16 page_size_length = 0;

/* map TX DESC buf_addr (including TX DESC + tx data) */
#if (LINUX_VERSION_CODE < KERNEL_VERSION(5, 18, 0))
mapping = pci_map_single(pdvobjpriv->ppcidev, pxmitframe->buf_addr,
sz + TX_WIFI_INFO_SIZE, PCI_DMA_TODEVICE);
#else
mapping = dma_map_single(&(pdvobjpriv->ppcidev)->dev, pxmitframe->buf_addr,
sz + TX_WIFI_INFO_SIZE, DMA_TO_DEVICE);
#endif

/* Calculate page size.
* Total buffer length including TX_WIFI_INFO and PacketLen
Expand Down Expand Up @@ -1248,7 +1253,11 @@ int rtl8821ce_init_txbd_ring(_adapter *padapter, unsigned int q_idx,

RTW_INFO("%s entries num:%d\n", __func__, entries);

#if (LINUX_VERSION_CODE < KERNEL_VERSION(5, 18, 0))
txbd = pci_alloc_consistent(pdev, sizeof(*txbd) * entries, &dma);
#else
txbd = dma_alloc_coherent(&pdev->dev, sizeof(*txbd) * entries, &dma, GFP_KERNEL);
#endif

if (!txbd || (unsigned long)txbd & 0xFF) {
RTW_INFO("Cannot allocate TXBD (q_idx = %d)\n", q_idx);
Expand Down Expand Up @@ -1294,9 +1303,15 @@ void rtl8821ce_free_txbd_ring(_adapter *padapter, unsigned int prio)
#ifdef CONFIG_64BIT_DMA
mapping |= (dma_addr_t)GET_TX_BD_PHYSICAL_ADDR0_HIGH(txbd) << 32;
#endif
#if (LINUX_VERSION_CODE < KERNEL_VERSION(5, 18, 0))
pci_unmap_single(pdev,
mapping,
pxmitbuf->len, PCI_DMA_TODEVICE);
#else
dma_unmap_single(&pdev->dev,
mapping,
pxmitbuf->len, DMA_TO_DEVICE);
#endif

rtw_free_xmitbuf(t_priv, pxmitbuf);

Expand All @@ -1307,8 +1322,13 @@ void rtl8821ce_free_txbd_ring(_adapter *padapter, unsigned int prio)
}
}

#if (LINUX_VERSION_CODE < KERNEL_VERSION(5, 18, 0))
pci_free_consistent(pdev, sizeof(*ring->buf_desc) * ring->entries,
ring->buf_desc, ring->dma);
#else
dma_free_coherent(&pdev->dev, sizeof(*ring->buf_desc) * ring->entries,
ring->buf_desc, ring->dma);
#endif
ring->buf_desc = NULL;

}
Expand Down Expand Up @@ -1442,9 +1462,15 @@ void rtl8821ce_tx_isr(PADAPTER Adapter, int prio)
#ifdef CONFIG_64BIT_DMA
mapping |= (dma_addr_t)GET_TX_BD_PHYSICAL_ADDR0_HIGH(tx_desc) << 32;
#endif
#if (LINUX_VERSION_CODE < KERNEL_VERSION(5, 18, 0))
pci_unmap_single(pdvobjpriv->ppcidev,
mapping,
pxmitbuf->len, PCI_DMA_TODEVICE);
#else
dma_unmap_single(&(pdvobjpriv->ppcidev)->dev,
mapping,
pxmitbuf->len, DMA_TO_DEVICE);
#endif
rtw_sctx_done(&pxmitbuf->sctx);
rtw_free_xmitbuf(&(pxmitbuf->padapter->xmitpriv),
pxmitbuf);
Expand Down
17 changes: 16 additions & 1 deletion os_dep/linux/pci_intf.c
Expand Up @@ -25,7 +25,6 @@

#endif


#if defined(PLATFORM_LINUX) && defined(PLATFORM_WINDOWS)

#error "Shall be Linux or Windows, but not both!\n"
Expand Down Expand Up @@ -1195,9 +1194,17 @@ static struct dvobj_priv *pci_dvobj_init(struct pci_dev *pdev, const struct pci_
}

#ifdef CONFIG_64BIT_DMA
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 18, 0))
if (!dma_set_mask(&pdev->dev, DMA_BIT_MASK(64))) {
#else
if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(64))) {
#endif
RTW_INFO("RTL819xCE: Using 64bit DMA\n");
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 18, 0))
err = dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(64));
#else
err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64));
#endif
if (err != 0) {
RTW_ERR("Unable to obtain 64bit DMA for consistent allocations\n");
goto disable_picdev;
Expand All @@ -1206,8 +1213,16 @@ static struct dvobj_priv *pci_dvobj_init(struct pci_dev *pdev, const struct pci_
} else
#endif
{
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 18, 0))
if (!dma_set_mask(&pdev->dev, DMA_BIT_MASK(32))) {
#else
if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(32))) {
#endif
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 18, 0))
err = dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(32));
#else
err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32));
#endif
if (err != 0) {
RTW_ERR("Unable to obtain 32bit DMA for consistent allocations\n");
goto disable_picdev;
Expand Down

0 comments on commit f7c84ef

Please sign in to comment.