hc
2024-05-11 297b60346df8beafee954a0fd7c2d64f33f3b9bc
kernel/drivers/net/ethernet/micrel/ksz884x.c
....@@ -1,17 +1,9 @@
1
-/**
1
+// SPDX-License-Identifier: GPL-2.0-only
2
+/*
23 * drivers/net/ethernet/micrel/ksx884x.c - Micrel KSZ8841/2 PCI Ethernet driver
34 *
45 * Copyright (c) 2009-2010 Micrel, Inc.
56 * Tristram Ha <Tristram.Ha@micrel.com>
6
- *
7
- * This program is free software; you can redistribute it and/or modify
8
- * it under the terms of the GNU General Public License version 2 as
9
- * published by the Free Software Foundation.
10
- *
11
- * This program is distributed in the hope that it will be useful,
12
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
- * GNU General Public License for more details.
157 */
168
179 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
....@@ -967,7 +959,7 @@
967959 * struct ksz_dma_buf - OS dependent DMA buffer data structure
968960 * @skb: Associated socket buffer.
969961 * @dma: Associated physical DMA address.
970
- * len: Actual len used.
962
+ * @len: Actual len used.
971963 */
972964 struct ksz_dma_buf {
973965 struct sk_buff *skb;
....@@ -1262,6 +1254,7 @@
12621254 * @multi_list_size: Multicast address list size.
12631255 * @enabled: Indication of hardware enabled.
12641256 * @rx_stop: Indication of receive process stop.
1257
+ * @reserved2: none
12651258 * @features: Hardware features to enable.
12661259 * @overrides: Hardware features to override.
12671260 * @parent: Pointer to parent, network device private structure.
....@@ -1455,7 +1448,7 @@
14551448 * struct dev_priv - Network device private data structure
14561449 * @adapter: Adapter device information.
14571450 * @port: Port information.
1458
- * @monitor_time_info: Timer to monitor ports.
1451
+ * @monitor_timer_info: Timer to monitor ports.
14591452 * @proc_sem: Semaphore for proc accessing.
14601453 * @id: Device ID.
14611454 * @mii_if: MII interface information.
....@@ -1574,6 +1567,7 @@
15741567
15751568 /**
15761569 * hw_block_intr - block hardware interrupts
1570
+ * @hw: The hardware instance.
15771571 *
15781572 * This function blocks all interrupts of the hardware and returns the current
15791573 * interrupt enable mask so that interrupts can be restored later.
....@@ -1826,6 +1820,7 @@
18261820 * port_r_mib_pkt - read dropped packet counts
18271821 * @hw: The hardware instance.
18281822 * @port: The port index.
1823
+ * @last: last one
18291824 * @cnt: Buffer to store the receive and transmit dropped packet counts.
18301825 *
18311826 * This routine reads the dropped packet counts of the port.
....@@ -1979,7 +1974,7 @@
19791974 * port_chk_shift - check port bit
19801975 * @hw: The hardware instance.
19811976 * @port: The port index.
1982
- * @offset: The offset of the register.
1977
+ * @addr: The offset of the register.
19831978 * @shift: Number of bits to shift.
19841979 *
19851980 * This function checks whether the specified port is set in the register or
....@@ -2001,7 +1996,7 @@
20011996 * port_cfg_shift - set port bit
20021997 * @hw: The hardware instance.
20031998 * @port: The port index.
2004
- * @offset: The offset of the register.
1999
+ * @addr: The offset of the register.
20052000 * @shift: Number of bits to shift.
20062001 * @set: The flag indicating whether the port is to be set or not.
20072002 *
....@@ -2173,7 +2168,7 @@
21732168 num = (data & BROADCAST_STORM_RATE_HI);
21742169 num <<= 8;
21752170 num |= (data & BROADCAST_STORM_RATE_LO) >> 8;
2176
- num = (num * 100 + BROADCAST_STORM_VALUE / 2) / BROADCAST_STORM_VALUE;
2171
+ num = DIV_ROUND_CLOSEST(num * 100, BROADCAST_STORM_VALUE);
21772172 *percent = (u8) num;
21782173 }
21792174
....@@ -4397,9 +4392,9 @@
43974392 DESC_ALIGNMENT;
43984393
43994394 adapter->desc_pool.alloc_virt =
4400
- pci_zalloc_consistent(adapter->pdev,
4401
- adapter->desc_pool.alloc_size,
4402
- &adapter->desc_pool.dma_addr);
4395
+ dma_alloc_coherent(&adapter->pdev->dev,
4396
+ adapter->desc_pool.alloc_size,
4397
+ &adapter->desc_pool.dma_addr, GFP_KERNEL);
44034398 if (adapter->desc_pool.alloc_virt == NULL) {
44044399 adapter->desc_pool.alloc_size = 0;
44054400 return 1;
....@@ -4432,13 +4427,16 @@
44324427 /**
44334428 * free_dma_buf - release DMA buffer resources
44344429 * @adapter: Adapter information structure.
4430
+ * @dma_buf: pointer to buf
4431
+ * @direction: to or from device
44354432 *
44364433 * This routine is just a helper function to release the DMA buffer resources.
44374434 */
44384435 static void free_dma_buf(struct dev_info *adapter, struct ksz_dma_buf *dma_buf,
44394436 int direction)
44404437 {
4441
- pci_unmap_single(adapter->pdev, dma_buf->dma, dma_buf->len, direction);
4438
+ dma_unmap_single(&adapter->pdev->dev, dma_buf->dma, dma_buf->len,
4439
+ direction);
44424440 dev_kfree_skb(dma_buf->skb);
44434441 dma_buf->skb = NULL;
44444442 dma_buf->dma = 0;
....@@ -4463,16 +4461,15 @@
44634461
44644462 dma_buf = DMA_BUFFER(desc);
44654463 if (dma_buf->skb && dma_buf->len != adapter->mtu)
4466
- free_dma_buf(adapter, dma_buf, PCI_DMA_FROMDEVICE);
4464
+ free_dma_buf(adapter, dma_buf, DMA_FROM_DEVICE);
44674465 dma_buf->len = adapter->mtu;
44684466 if (!dma_buf->skb)
44694467 dma_buf->skb = alloc_skb(dma_buf->len, GFP_ATOMIC);
44704468 if (dma_buf->skb && !dma_buf->dma)
4471
- dma_buf->dma = pci_map_single(
4472
- adapter->pdev,
4473
- skb_tail_pointer(dma_buf->skb),
4474
- dma_buf->len,
4475
- PCI_DMA_FROMDEVICE);
4469
+ dma_buf->dma = dma_map_single(&adapter->pdev->dev,
4470
+ skb_tail_pointer(dma_buf->skb),
4471
+ dma_buf->len,
4472
+ DMA_FROM_DEVICE);
44764473
44774474 /* Set descriptor. */
44784475 set_rx_buf(desc, dma_buf->dma);
....@@ -4550,11 +4547,10 @@
45504547
45514548 /* Free memory. */
45524549 if (adapter->desc_pool.alloc_virt)
4553
- pci_free_consistent(
4554
- adapter->pdev,
4555
- adapter->desc_pool.alloc_size,
4556
- adapter->desc_pool.alloc_virt,
4557
- adapter->desc_pool.dma_addr);
4550
+ dma_free_coherent(&adapter->pdev->dev,
4551
+ adapter->desc_pool.alloc_size,
4552
+ adapter->desc_pool.alloc_virt,
4553
+ adapter->desc_pool.dma_addr);
45584554
45594555 /* Reset resource pool. */
45604556 adapter->desc_pool.alloc_size = 0;
....@@ -4570,6 +4566,7 @@
45704566 * ksz_free_buffers - free buffers used in the descriptors
45714567 * @adapter: Adapter information structure.
45724568 * @desc_info: Descriptor information structure.
4569
+ * @direction: to or from device
45734570 *
45744571 * This local routine frees buffers used in the DMA buffers.
45754572 */
....@@ -4597,12 +4594,10 @@
45974594 static void ksz_free_mem(struct dev_info *adapter)
45984595 {
45994596 /* Free transmit buffers. */
4600
- ksz_free_buffers(adapter, &adapter->hw.tx_desc_info,
4601
- PCI_DMA_TODEVICE);
4597
+ ksz_free_buffers(adapter, &adapter->hw.tx_desc_info, DMA_TO_DEVICE);
46024598
46034599 /* Free receive buffers. */
4604
- ksz_free_buffers(adapter, &adapter->hw.rx_desc_info,
4605
- PCI_DMA_FROMDEVICE);
4600
+ ksz_free_buffers(adapter, &adapter->hw.rx_desc_info, DMA_FROM_DEVICE);
46064601
46074602 /* Free descriptors. */
46084603 ksz_free_desc(adapter);
....@@ -4664,9 +4659,8 @@
46644659
46654660 dma_buf->len = skb_headlen(skb);
46664661
4667
- dma_buf->dma = pci_map_single(
4668
- hw_priv->pdev, skb->data, dma_buf->len,
4669
- PCI_DMA_TODEVICE);
4662
+ dma_buf->dma = dma_map_single(&hw_priv->pdev->dev, skb->data,
4663
+ dma_buf->len, DMA_TO_DEVICE);
46704664 set_tx_buf(desc, dma_buf->dma);
46714665 set_tx_len(desc, dma_buf->len);
46724666
....@@ -4683,11 +4677,10 @@
46834677 dma_buf = DMA_BUFFER(desc);
46844678 dma_buf->len = skb_frag_size(this_frag);
46854679
4686
- dma_buf->dma = pci_map_single(
4687
- hw_priv->pdev,
4688
- skb_frag_address(this_frag),
4689
- dma_buf->len,
4690
- PCI_DMA_TODEVICE);
4680
+ dma_buf->dma = dma_map_single(&hw_priv->pdev->dev,
4681
+ skb_frag_address(this_frag),
4682
+ dma_buf->len,
4683
+ DMA_TO_DEVICE);
46914684 set_tx_buf(desc, dma_buf->dma);
46924685 set_tx_len(desc, dma_buf->len);
46934686
....@@ -4707,9 +4700,8 @@
47074700 } else {
47084701 dma_buf->len = len;
47094702
4710
- dma_buf->dma = pci_map_single(
4711
- hw_priv->pdev, skb->data, dma_buf->len,
4712
- PCI_DMA_TODEVICE);
4703
+ dma_buf->dma = dma_map_single(&hw_priv->pdev->dev, skb->data,
4704
+ dma_buf->len, DMA_TO_DEVICE);
47134705 set_tx_buf(desc, dma_buf->dma);
47144706 set_tx_len(desc, dma_buf->len);
47154707 }
....@@ -4734,7 +4726,8 @@
47344726
47354727 /**
47364728 * transmit_cleanup - clean up transmit descriptors
4737
- * @dev: Network device.
4729
+ * @hw_priv: Network device.
4730
+ * @normal: break if owned
47384731 *
47394732 * This routine is called to clean up the transmitted buffers.
47404733 */
....@@ -4763,9 +4756,8 @@
47634756 }
47644757
47654758 dma_buf = DMA_BUFFER(desc);
4766
- pci_unmap_single(
4767
- hw_priv->pdev, dma_buf->dma, dma_buf->len,
4768
- PCI_DMA_TODEVICE);
4759
+ dma_unmap_single(&hw_priv->pdev->dev, dma_buf->dma,
4760
+ dma_buf->len, DMA_TO_DEVICE);
47694761
47704762 /* This descriptor contains the last buffer in the packet. */
47714763 if (dma_buf->skb) {
....@@ -4791,7 +4783,7 @@
47914783
47924784 /**
47934785 * transmit_done - transmit done processing
4794
- * @dev: Network device.
4786
+ * @hw_priv: Network device.
47954787 *
47964788 * This routine is called when the transmit interrupt is triggered, indicating
47974789 * either a packet is sent successfully or there are transmit errors.
....@@ -4897,13 +4889,14 @@
48974889 /**
48984890 * netdev_tx_timeout - transmit timeout processing
48994891 * @dev: Network device.
4892
+ * @txqueue: index of hanging queue
49004893 *
49014894 * This routine is called when the transmit timer expires. That indicates the
49024895 * hardware is not running correctly because transmit interrupts are not
49034896 * triggered to free up resources so that the transmit routine can continue
49044897 * sending out packets. The hardware is reset to correct the problem.
49054898 */
4906
-static void netdev_tx_timeout(struct net_device *dev)
4899
+static void netdev_tx_timeout(struct net_device *dev, unsigned int txqueue)
49074900 {
49084901 static unsigned long last_reset;
49094902
....@@ -4992,15 +4985,13 @@
49924985 struct dev_info *hw_priv = priv->adapter;
49934986 struct ksz_dma_buf *dma_buf;
49944987 struct sk_buff *skb;
4995
- int rx_status;
49964988
49974989 /* Received length includes 4-byte CRC. */
49984990 packet_len = status.rx.frame_len - 4;
49994991
50004992 dma_buf = DMA_BUFFER(desc);
5001
- pci_dma_sync_single_for_cpu(
5002
- hw_priv->pdev, dma_buf->dma, packet_len + 4,
5003
- PCI_DMA_FROMDEVICE);
4993
+ dma_sync_single_for_cpu(&hw_priv->pdev->dev, dma_buf->dma,
4994
+ packet_len + 4, DMA_FROM_DEVICE);
50044995
50054996 do {
50064997 /* skb->data != skb->head */
....@@ -5029,7 +5020,7 @@
50295020 dev->stats.rx_bytes += packet_len;
50305021
50315022 /* Notify upper layer for received packet. */
5032
- rx_status = netif_rx(skb);
5023
+ netif_rx(skb);
50335024
50345025 return 0;
50355026 }
....@@ -5174,9 +5165,9 @@
51745165 return received;
51755166 }
51765167
5177
-static void rx_proc_task(unsigned long data)
5168
+static void rx_proc_task(struct tasklet_struct *t)
51785169 {
5179
- struct dev_info *hw_priv = (struct dev_info *) data;
5170
+ struct dev_info *hw_priv = from_tasklet(hw_priv, t, rx_tasklet);
51805171 struct ksz_hw *hw = &hw_priv->hw;
51815172
51825173 if (!hw->enabled)
....@@ -5196,9 +5187,9 @@
51965187 }
51975188 }
51985189
5199
-static void tx_proc_task(unsigned long data)
5190
+static void tx_proc_task(struct tasklet_struct *t)
52005191 {
5201
- struct dev_info *hw_priv = (struct dev_info *) data;
5192
+ struct dev_info *hw_priv = from_tasklet(hw_priv, t, tx_tasklet);
52025193 struct ksz_hw *hw = &hw_priv->hw;
52035194
52045195 hw_ack_intr(hw, KS884X_INT_TX_MASK);
....@@ -5451,10 +5442,8 @@
54515442 rc = request_irq(dev->irq, netdev_intr, IRQF_SHARED, dev->name, dev);
54525443 if (rc)
54535444 return rc;
5454
- tasklet_init(&hw_priv->rx_tasklet, rx_proc_task,
5455
- (unsigned long) hw_priv);
5456
- tasklet_init(&hw_priv->tx_tasklet, tx_proc_task,
5457
- (unsigned long) hw_priv);
5445
+ tasklet_setup(&hw_priv->rx_tasklet, rx_proc_task);
5446
+ tasklet_setup(&hw_priv->tx_tasklet, tx_proc_task);
54585447
54595448 hw->promiscuous = 0;
54605449 hw->all_multi = 0;
....@@ -5701,7 +5690,7 @@
57015690 * from the bridge.
57025691 */
57035692 if ((hw->features & STP_SUPPORT) && !promiscuous &&
5704
- (dev->priv_flags & IFF_BRIDGE_PORT)) {
5693
+ netif_is_bridge_port(dev)) {
57055694 struct ksz_switch *sw = hw->ksz_switch;
57065695 int port = priv->port.first_port;
57075696
....@@ -5844,8 +5833,7 @@
58445833 /* Get address of MII PHY in use. */
58455834 case SIOCGMIIPHY:
58465835 data->phy_id = priv->id;
5847
-
5848
- /* Fallthrough... */
5836
+ fallthrough;
58495837
58505838 /* Read MII PHY register. */
58515839 case SIOCGMIIREG:
....@@ -6093,14 +6081,6 @@
60936081 sizeof(info->bus_info));
60946082 }
60956083
6096
-/**
6097
- * netdev_get_regs_len - get length of register dump
6098
- * @dev: Network device.
6099
- *
6100
- * This function returns the length of the register dump.
6101
- *
6102
- * Return length of the register dump.
6103
- */
61046084 static struct hw_regs {
61056085 int start;
61066086 int end;
....@@ -6114,6 +6094,14 @@
61146094 { 0, 0 }
61156095 };
61166096
6097
+/**
6098
+ * netdev_get_regs_len - get length of register dump
6099
+ * @dev: Network device.
6100
+ *
6101
+ * This function returns the length of the register dump.
6102
+ *
6103
+ * Return length of the register dump.
6104
+ */
61176105 static int netdev_get_regs_len(struct net_device *dev)
61186106 {
61196107 struct hw_regs *range = hw_regs_range;
....@@ -6255,6 +6243,8 @@
62556243 return EEPROM_SIZE * 2;
62566244 }
62576245
6246
+#define EEPROM_MAGIC 0x10A18842
6247
+
62586248 /**
62596249 * netdev_get_eeprom - get EEPROM data
62606250 * @dev: Network device.
....@@ -6265,8 +6255,6 @@
62656255 *
62666256 * Return 0 if successful; otherwise an error code.
62676257 */
6268
-#define EEPROM_MAGIC 0x10A18842
6269
-
62706258 static int netdev_get_eeprom(struct net_device *dev,
62716259 struct ethtool_eeprom *eeprom, u8 *data)
62726260 {
....@@ -6403,7 +6391,7 @@
64036391 /**
64046392 * netdev_get_ringparam - get tx/rx ring parameters
64056393 * @dev: Network device.
6406
- * @pause: Ethtool RING settings data structure.
6394
+ * @ring: Ethtool RING settings data structure.
64076395 *
64086396 * This procedure returns the TX/RX ring settings.
64096397 */
....@@ -6524,7 +6512,6 @@
65246512 int i;
65256513 int n;
65266514 int p;
6527
- int rc;
65286515 u64 counter[TOTAL_PORT_COUNTER_NUM];
65296516
65306517 mutex_lock(&hw_priv->lock);
....@@ -6545,19 +6532,19 @@
65456532
65466533 if (1 == port->mib_port_cnt && n < SWITCH_PORT_NUM) {
65476534 p = n;
6548
- rc = wait_event_interruptible_timeout(
6535
+ wait_event_interruptible_timeout(
65496536 hw_priv->counter[p].counter,
65506537 2 == hw_priv->counter[p].read,
65516538 HZ * 1);
65526539 } else
65536540 for (i = 0, p = n; i < port->mib_port_cnt - n; i++, p++) {
65546541 if (0 == i) {
6555
- rc = wait_event_interruptible_timeout(
6542
+ wait_event_interruptible_timeout(
65566543 hw_priv->counter[p].counter,
65576544 2 == hw_priv->counter[p].read,
65586545 HZ * 2);
65596546 } else if (hw->port_mib[p].cnt_ptr) {
6560
- rc = wait_event_interruptible_timeout(
6547
+ wait_event_interruptible_timeout(
65616548 hw_priv->counter[p].counter,
65626549 2 == hw_priv->counter[p].read,
65636550 HZ * 1);
....@@ -6708,7 +6695,7 @@
67086695
67096696 /**
67106697 * dev_monitor - periodic monitoring
6711
- * @ptr: Network device pointer.
6698
+ * @t: timer list containing a network device pointer.
67126699 *
67136700 * This routine is run in a kernel timer to monitor the network device.
67146701 */
....@@ -6936,14 +6923,14 @@
69366923 char banner[sizeof(version)];
69376924 struct ksz_switch *sw = NULL;
69386925
6939
- result = pci_enable_device(pdev);
6926
+ result = pcim_enable_device(pdev);
69406927 if (result)
69416928 return result;
69426929
69436930 result = -ENODEV;
69446931
6945
- if (pci_set_dma_mask(pdev, DMA_BIT_MASK(32)) ||
6946
- pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32)))
6932
+ if (dma_set_mask(&pdev->dev, DMA_BIT_MASK(32)) ||
6933
+ dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(32)))
69476934 return result;
69486935
69496936 reg_base = pci_resource_start(pdev, 0);
....@@ -7162,17 +7149,14 @@
71627149 kfree(info);
71637150 }
71647151
7165
-#ifdef CONFIG_PM
7166
-static int pcidev_resume(struct pci_dev *pdev)
7152
+static int __maybe_unused pcidev_resume(struct device *dev_d)
71677153 {
71687154 int i;
7169
- struct platform_info *info = pci_get_drvdata(pdev);
7155
+ struct platform_info *info = dev_get_drvdata(dev_d);
71707156 struct dev_info *hw_priv = &info->dev_info;
71717157 struct ksz_hw *hw = &hw_priv->hw;
71727158
7173
- pci_set_power_state(pdev, PCI_D0);
7174
- pci_restore_state(pdev);
7175
- pci_enable_wake(pdev, PCI_D0, 0);
7159
+ device_wakeup_disable(dev_d);
71767160
71777161 if (hw_priv->wol_enable)
71787162 hw_cfg_wol_pme(hw, 0);
....@@ -7189,10 +7173,10 @@
71897173 return 0;
71907174 }
71917175
7192
-static int pcidev_suspend(struct pci_dev *pdev, pm_message_t state)
7176
+static int __maybe_unused pcidev_suspend(struct device *dev_d)
71937177 {
71947178 int i;
7195
- struct platform_info *info = pci_get_drvdata(pdev);
7179
+ struct platform_info *info = dev_get_drvdata(dev_d);
71967180 struct dev_info *hw_priv = &info->dev_info;
71977181 struct ksz_hw *hw = &hw_priv->hw;
71987182
....@@ -7214,12 +7198,9 @@
72147198 hw_cfg_wol_pme(hw, 1);
72157199 }
72167200
7217
- pci_save_state(pdev);
7218
- pci_enable_wake(pdev, pci_choose_state(pdev, state), 1);
7219
- pci_set_power_state(pdev, pci_choose_state(pdev, state));
7201
+ device_wakeup_enable(dev_d);
72207202 return 0;
72217203 }
7222
-#endif
72237204
72247205 static char pcidev_name[] = "ksz884xp";
72257206
....@@ -7233,11 +7214,10 @@
72337214
72347215 MODULE_DEVICE_TABLE(pci, pcidev_table);
72357216
7217
+static SIMPLE_DEV_PM_OPS(pcidev_pm_ops, pcidev_suspend, pcidev_resume);
7218
+
72367219 static struct pci_driver pci_device_driver = {
7237
-#ifdef CONFIG_PM
7238
- .suspend = pcidev_suspend,
7239
- .resume = pcidev_resume,
7240
-#endif
7220
+ .driver.pm = &pcidev_pm_ops,
72417221 .name = pcidev_name,
72427222 .id_table = pcidev_table,
72437223 .probe = pcidev_init,