hc
2024-12-19 9370bb92b2d16684ee45cf24e879c93c509162da
kernel/drivers/net/can/grcan.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
23 * Socket CAN driver for Aeroflex Gaisler GRCAN and GRHCAN.
34 *
....@@ -17,11 +18,6 @@
1718 *
1819 * See "Documentation/admin-guide/kernel-parameters.rst" for information on the module
1920 * parameters.
20
- *
21
- * This program is free software; you can redistribute it and/or modify it
22
- * under the terms of the GNU General Public License as published by the
23
- * Free Software Foundation; either version 2 of the License, or (at your
24
- * option) any later version.
2521 *
2622 * Contributors: Andreas Larsson <andreas@gaisler.com>
2723 */
....@@ -245,13 +241,14 @@
245241 .rxsize = GRCAN_DEFAULT_BUFFER_SIZE, \
246242 }
247243
248
-#define GRCAN_TXBUG_SAFE_GRLIB_VERSION 0x4100
244
+#define GRCAN_TXBUG_SAFE_GRLIB_VERSION 4100
249245 #define GRLIB_VERSION_MASK 0xffff
250246
251247 /* GRCAN private data structure */
252248 struct grcan_priv {
253249 struct can_priv can; /* must be the first member */
254250 struct net_device *dev;
251
+ struct device *ofdev_dev;
255252 struct napi_struct napi;
256253
257254 struct grcan_registers __iomem *regs; /* ioremap'ed registers */
....@@ -730,7 +727,7 @@
730727 txrx = "on rx ";
731728 stats->rx_errors++;
732729 }
733
- netdev_err(dev, "Fatal AHB buss error %s- halting device\n",
730
+ netdev_err(dev, "Fatal AHB bus error %s- halting device\n",
734731 txrx);
735732
736733 spin_lock_irqsave(&priv->lock, flags);
....@@ -928,7 +925,7 @@
928925 struct grcan_priv *priv = netdev_priv(dev);
929926 struct grcan_dma *dma = &priv->dma;
930927
931
- dma_free_coherent(&dev->dev, dma->base_size, dma->base_buf,
928
+ dma_free_coherent(priv->ofdev_dev, dma->base_size, dma->base_buf,
932929 dma->base_handle);
933930 memset(dma, 0, sizeof(*dma));
934931 }
....@@ -953,7 +950,7 @@
953950
954951 /* Extra GRCAN_BUFFER_ALIGNMENT to allow for alignment */
955952 dma->base_size = lsize + ssize + GRCAN_BUFFER_ALIGNMENT;
956
- dma->base_buf = dma_alloc_coherent(&dev->dev,
953
+ dma->base_buf = dma_alloc_coherent(priv->ofdev_dev,
957954 dma->base_size,
958955 &dma->base_handle,
959956 GFP_KERNEL);
....@@ -1117,8 +1114,10 @@
11171114
11181115 priv->closing = true;
11191116 if (priv->need_txbug_workaround) {
1117
+ spin_unlock_irqrestore(&priv->lock, flags);
11201118 del_timer_sync(&priv->hang_timer);
11211119 del_timer_sync(&priv->rr_timer);
1120
+ spin_lock_irqsave(&priv->lock, flags);
11221121 }
11231122 netif_stop_queue(dev);
11241123 grcan_stop_hardware(dev);
....@@ -1138,7 +1137,7 @@
11381137 return 0;
11391138 }
11401139
1141
-static int grcan_transmit_catch_up(struct net_device *dev, int budget)
1140
+static void grcan_transmit_catch_up(struct net_device *dev)
11421141 {
11431142 struct grcan_priv *priv = netdev_priv(dev);
11441143 unsigned long flags;
....@@ -1146,7 +1145,7 @@
11461145
11471146 spin_lock_irqsave(&priv->lock, flags);
11481147
1149
- work_done = catch_up_echo_skb(dev, budget, true);
1148
+ work_done = catch_up_echo_skb(dev, -1, true);
11501149 if (work_done) {
11511150 if (!priv->resetting && !priv->closing &&
11521151 !(priv->can.ctrlmode & CAN_CTRLMODE_LISTENONLY))
....@@ -1160,8 +1159,6 @@
11601159 }
11611160
11621161 spin_unlock_irqrestore(&priv->lock, flags);
1163
-
1164
- return work_done;
11651162 }
11661163
11671164 static int grcan_receive(struct net_device *dev, int budget)
....@@ -1243,19 +1240,13 @@
12431240 struct net_device *dev = priv->dev;
12441241 struct grcan_registers __iomem *regs = priv->regs;
12451242 unsigned long flags;
1246
- int tx_work_done, rx_work_done;
1247
- int rx_budget = budget / 2;
1248
- int tx_budget = budget - rx_budget;
1243
+ int work_done;
12491244
1250
- /* Half of the budget for receiveing messages */
1251
- rx_work_done = grcan_receive(dev, rx_budget);
1245
+ work_done = grcan_receive(dev, budget);
12521246
1253
- /* Half of the budget for transmitting messages as that can trigger echo
1254
- * frames being received
1255
- */
1256
- tx_work_done = grcan_transmit_catch_up(dev, tx_budget);
1247
+ grcan_transmit_catch_up(dev);
12571248
1258
- if (rx_work_done < rx_budget && tx_work_done < tx_budget) {
1249
+ if (work_done < budget) {
12591250 napi_complete(napi);
12601251
12611252 /* Guarantee no interference with a running reset that otherwise
....@@ -1272,7 +1263,7 @@
12721263 spin_unlock_irqrestore(&priv->lock, flags);
12731264 }
12741265
1275
- return rx_work_done + tx_work_done;
1266
+ return work_done;
12761267 }
12771268
12781269 /* Work tx bug by waiting while for the risky situation to clear. If that fails,
....@@ -1604,6 +1595,7 @@
16041595 memcpy(&priv->config, &grcan_module_config,
16051596 sizeof(struct grcan_device_config));
16061597 priv->dev = dev;
1598
+ priv->ofdev_dev = &ofdev->dev;
16071599 priv->regs = base;
16081600 priv->can.bittiming_const = &grcan_bittiming_const;
16091601 priv->can.do_set_bittiming = grcan_set_bittiming;
....@@ -1656,7 +1648,7 @@
16561648 static int grcan_probe(struct platform_device *ofdev)
16571649 {
16581650 struct device_node *np = ofdev->dev.of_node;
1659
- struct resource *res;
1651
+ struct device_node *sysid_parent;
16601652 u32 sysid, ambafreq;
16611653 int irq, err;
16621654 void __iomem *base;
....@@ -1665,10 +1657,14 @@
16651657 /* Compare GRLIB version number with the first that does not
16661658 * have the tx bug (see start_xmit)
16671659 */
1668
- err = of_property_read_u32(np, "systemid", &sysid);
1669
- if (!err && ((sysid & GRLIB_VERSION_MASK)
1670
- >= GRCAN_TXBUG_SAFE_GRLIB_VERSION))
1671
- txbug = false;
1660
+ sysid_parent = of_find_node_by_path("/ambapp0");
1661
+ if (sysid_parent) {
1662
+ err = of_property_read_u32(sysid_parent, "systemid", &sysid);
1663
+ if (!err && ((sysid & GRLIB_VERSION_MASK) >=
1664
+ GRCAN_TXBUG_SAFE_GRLIB_VERSION))
1665
+ txbug = false;
1666
+ of_node_put(sysid_parent);
1667
+ }
16721668
16731669 err = of_property_read_u32(np, "freq", &ambafreq);
16741670 if (err) {
....@@ -1676,8 +1672,7 @@
16761672 goto exit_error;
16771673 }
16781674
1679
- res = platform_get_resource(ofdev, IORESOURCE_MEM, 0);
1680
- base = devm_ioremap_resource(&ofdev->dev, res);
1675
+ base = devm_platform_ioremap_resource(ofdev, 0);
16811676 if (IS_ERR(base)) {
16821677 err = PTR_ERR(base);
16831678 goto exit_error;