hc
2024-02-19 1c055e55a242a33e574e48be530e06770a210dcd
kernel/drivers/net/ethernet/moxa/moxart_ether.c
....@@ -74,18 +74,15 @@
7474 static void moxart_mac_free_memory(struct net_device *ndev)
7575 {
7676 struct moxart_mac_priv_t *priv = netdev_priv(ndev);
77
- int i;
78
-
79
- for (i = 0; i < RX_DESC_NUM; i++)
80
- dma_unmap_single(&ndev->dev, priv->rx_mapping[i],
81
- priv->rx_buf_size, DMA_FROM_DEVICE);
8277
8378 if (priv->tx_desc_base)
84
- dma_free_coherent(NULL, TX_REG_DESC_SIZE * TX_DESC_NUM,
79
+ dma_free_coherent(&priv->pdev->dev,
80
+ TX_REG_DESC_SIZE * TX_DESC_NUM,
8581 priv->tx_desc_base, priv->tx_base);
8682
8783 if (priv->rx_desc_base)
88
- dma_free_coherent(NULL, RX_REG_DESC_SIZE * RX_DESC_NUM,
84
+ dma_free_coherent(&priv->pdev->dev,
85
+ RX_REG_DESC_SIZE * RX_DESC_NUM,
8986 priv->rx_desc_base, priv->rx_base);
9087
9188 kfree(priv->tx_buf_base);
....@@ -145,11 +142,11 @@
145142 desc + RX_REG_OFFSET_DESC1);
146143
147144 priv->rx_buf[i] = priv->rx_buf_base + priv->rx_buf_size * i;
148
- priv->rx_mapping[i] = dma_map_single(&ndev->dev,
145
+ priv->rx_mapping[i] = dma_map_single(&priv->pdev->dev,
149146 priv->rx_buf[i],
150147 priv->rx_buf_size,
151148 DMA_FROM_DEVICE);
152
- if (dma_mapping_error(&ndev->dev, priv->rx_mapping[i]))
149
+ if (dma_mapping_error(&priv->pdev->dev, priv->rx_mapping[i]))
153150 netdev_err(ndev, "DMA mapping error\n");
154151
155152 moxart_desc_write(priv->rx_mapping[i],
....@@ -191,6 +188,7 @@
191188 static int moxart_mac_stop(struct net_device *ndev)
192189 {
193190 struct moxart_mac_priv_t *priv = netdev_priv(ndev);
191
+ int i;
194192
195193 napi_disable(&priv->napi);
196194
....@@ -201,6 +199,11 @@
201199
202200 /* disable all functions */
203201 writel(0, priv->base + REG_MAC_CTRL);
202
+
203
+ /* unmap areas mapped in moxart_mac_setup_desc_ring() */
204
+ for (i = 0; i < RX_DESC_NUM; i++)
205
+ dma_unmap_single(&priv->pdev->dev, priv->rx_mapping[i],
206
+ priv->rx_buf_size, DMA_FROM_DEVICE);
204207
205208 return 0;
206209 }
....@@ -238,7 +241,7 @@
238241 if (len > RX_BUF_SIZE)
239242 len = RX_BUF_SIZE;
240243
241
- dma_sync_single_for_cpu(&ndev->dev,
244
+ dma_sync_single_for_cpu(&priv->pdev->dev,
242245 priv->rx_mapping[rx_head],
243246 priv->rx_buf_size, DMA_FROM_DEVICE);
244247 skb = netdev_alloc_skb_ip_align(ndev, len);
....@@ -292,13 +295,13 @@
292295 unsigned int tx_tail = priv->tx_tail;
293296
294297 while (tx_tail != tx_head) {
295
- dma_unmap_single(&ndev->dev, priv->tx_mapping[tx_tail],
298
+ dma_unmap_single(&priv->pdev->dev, priv->tx_mapping[tx_tail],
296299 priv->tx_len[tx_tail], DMA_TO_DEVICE);
297300
298301 ndev->stats.tx_packets++;
299302 ndev->stats.tx_bytes += priv->tx_skb[tx_tail]->len;
300303
301
- dev_kfree_skb_irq(priv->tx_skb[tx_tail]);
304
+ dev_consume_skb_irq(priv->tx_skb[tx_tail]);
302305 priv->tx_skb[tx_tail] = NULL;
303306
304307 tx_tail = TX_NEXT(tx_tail);
....@@ -329,14 +332,15 @@
329332 return IRQ_HANDLED;
330333 }
331334
332
-static int moxart_mac_start_xmit(struct sk_buff *skb, struct net_device *ndev)
335
+static netdev_tx_t moxart_mac_start_xmit(struct sk_buff *skb,
336
+ struct net_device *ndev)
333337 {
334338 struct moxart_mac_priv_t *priv = netdev_priv(ndev);
335339 void *desc;
336340 unsigned int len;
337341 unsigned int tx_head;
338342 u32 txdes1;
339
- int ret = NETDEV_TX_BUSY;
343
+ netdev_tx_t ret = NETDEV_TX_BUSY;
340344
341345 spin_lock_irq(&priv->txlock);
342346
....@@ -355,9 +359,9 @@
355359
356360 len = skb->len > TX_BUF_SIZE ? TX_BUF_SIZE : skb->len;
357361
358
- priv->tx_mapping[tx_head] = dma_map_single(&ndev->dev, skb->data,
362
+ priv->tx_mapping[tx_head] = dma_map_single(&priv->pdev->dev, skb->data,
359363 len, DMA_TO_DEVICE);
360
- if (dma_mapping_error(&ndev->dev, priv->tx_mapping[tx_head])) {
364
+ if (dma_mapping_error(&priv->pdev->dev, priv->tx_mapping[tx_head])) {
361365 netdev_err(ndev, "DMA mapping error\n");
362366 goto out_unlock;
363367 }
....@@ -376,7 +380,7 @@
376380 len = ETH_ZLEN;
377381 }
378382
379
- dma_sync_single_for_device(&ndev->dev, priv->tx_mapping[tx_head],
383
+ dma_sync_single_for_device(&priv->pdev->dev, priv->tx_mapping[tx_head],
380384 priv->tx_buf_size, DMA_TO_DEVICE);
381385
382386 txdes1 = TX_DESC1_LTS | TX_DESC1_FTS | (len & TX_DESC1_BUF_SIZE_MASK);
....@@ -476,22 +480,22 @@
476480
477481 priv = netdev_priv(ndev);
478482 priv->ndev = ndev;
483
+ priv->pdev = pdev;
479484
480
- res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
481
- ndev->base_addr = res->start;
482
- priv->base = devm_ioremap_resource(p_dev, res);
485
+ priv->base = devm_platform_get_and_ioremap_resource(pdev, 0, &res);
483486 if (IS_ERR(priv->base)) {
484487 dev_err(p_dev, "devm_ioremap_resource failed\n");
485488 ret = PTR_ERR(priv->base);
486489 goto init_fail;
487490 }
491
+ ndev->base_addr = res->start;
488492
489493 spin_lock_init(&priv->txlock);
490494
491495 priv->tx_buf_size = TX_BUF_SIZE;
492496 priv->rx_buf_size = RX_BUF_SIZE;
493497
494
- priv->tx_desc_base = dma_alloc_coherent(NULL, TX_REG_DESC_SIZE *
498
+ priv->tx_desc_base = dma_alloc_coherent(p_dev, TX_REG_DESC_SIZE *
495499 TX_DESC_NUM, &priv->tx_base,
496500 GFP_DMA | GFP_KERNEL);
497501 if (!priv->tx_desc_base) {
....@@ -499,7 +503,7 @@
499503 goto init_fail;
500504 }
501505
502
- priv->rx_desc_base = dma_alloc_coherent(NULL, RX_REG_DESC_SIZE *
506
+ priv->rx_desc_base = dma_alloc_coherent(p_dev, RX_REG_DESC_SIZE *
503507 RX_DESC_NUM, &priv->rx_base,
504508 GFP_DMA | GFP_KERNEL);
505509 if (!priv->rx_desc_base) {