hc
2024-05-10 23fa18eaa71266feff7ba8d83022d9e1cc83c65a
kernel/drivers/dma/ioat/init.c
....@@ -1,19 +1,7 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * Intel I/OAT DMA Linux driver
34 * Copyright(c) 2004 - 2015 Intel Corporation.
4
- *
5
- * This program is free software; you can redistribute it and/or modify it
6
- * under the terms and conditions of the GNU General Public License,
7
- * version 2, as published by the Free Software Foundation.
8
- *
9
- * This program is distributed in the hope that it will be useful, but WITHOUT
10
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12
- * more details.
13
- *
14
- * The full GNU General Public License is included in this distribution in
15
- * the file called "COPYING".
16
- *
175 */
186
197 #include <linux/init.h>
....@@ -119,6 +107,9 @@
119107 { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_IOAT_BDXDE2) },
120108 { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_IOAT_BDXDE3) },
121109
110
+ /* I/OAT v3.4 platforms */
111
+ { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_IOAT_ICX) },
112
+
122113 { 0, }
123114 };
124115 MODULE_DEVICE_TABLE(pci, ioat_pci_tbl);
....@@ -135,10 +126,10 @@
135126 static int ioat_dca_enabled = 1;
136127 module_param(ioat_dca_enabled, int, 0644);
137128 MODULE_PARM_DESC(ioat_dca_enabled, "control support of dca service (default: 1)");
138
-int ioat_pending_level = 4;
129
+int ioat_pending_level = 7;
139130 module_param(ioat_pending_level, int, 0644);
140131 MODULE_PARM_DESC(ioat_pending_level,
141
- "high-water mark for pushing ioat descriptors (default: 4)");
132
+ "high-water mark for pushing ioat descriptors (default: 7)");
142133 static char ioat_interrupt_style[32] = "msix";
143134 module_param_string(ioat_interrupt_style, ioat_interrupt_style,
144135 sizeof(ioat_interrupt_style), 0644);
....@@ -565,10 +556,6 @@
565556 ioat_kobject_del(ioat_dma);
566557
567558 dma_async_device_unregister(dma);
568
-
569
- dma_pool_destroy(ioat_dma->completion_pool);
570
-
571
- INIT_LIST_HEAD(&dma->channels);
572559 }
573560
574561 /**
....@@ -598,7 +585,7 @@
598585 dev_dbg(dev, "%s: xfercap = %d\n", __func__, 1 << xfercap_log);
599586
600587 for (i = 0; i < dma->chancnt; i++) {
601
- ioat_chan = devm_kzalloc(dev, sizeof(*ioat_chan), GFP_KERNEL);
588
+ ioat_chan = kzalloc(sizeof(*ioat_chan), GFP_KERNEL);
602589 if (!ioat_chan)
603590 break;
604591
....@@ -615,7 +602,7 @@
615602
616603 /**
617604 * ioat_free_chan_resources - release all the descriptors
618
- * @chan: the channel to be cleaned
605
+ * @c: the channel to be cleaned
619606 */
620607 static void ioat_free_chan_resources(struct dma_chan *c)
621608 {
....@@ -633,7 +620,16 @@
633620 return;
634621
635622 ioat_stop(ioat_chan);
636
- ioat_reset_hw(ioat_chan);
623
+
624
+ if (!test_bit(IOAT_CHAN_DOWN, &ioat_chan->state)) {
625
+ ioat_reset_hw(ioat_chan);
626
+
627
+ /* Put LTR to idle */
628
+ if (ioat_dma->version >= IOAT_VER_3_4)
629
+ writeb(IOAT_CHAN_LTR_SWSEL_IDLE,
630
+ ioat_chan->reg_base +
631
+ IOAT_CHAN_LTR_SWSEL_OFFSET);
632
+ }
637633
638634 spin_lock_bh(&ioat_chan->cleanup_lock);
639635 spin_lock_bh(&ioat_chan->prep_lock);
....@@ -655,7 +651,7 @@
655651 }
656652
657653 for (i = 0; i < ioat_chan->desc_chunks; i++) {
658
- dma_free_coherent(to_dev(ioat_chan), SZ_2M,
654
+ dma_free_coherent(to_dev(ioat_chan), IOAT_CHUNK_SIZE,
659655 ioat_chan->descs[i].virt,
660656 ioat_chan->descs[i].hw);
661657 ioat_chan->descs[i].virt = NULL;
....@@ -724,6 +720,28 @@
724720 spin_unlock_bh(&ioat_chan->prep_lock);
725721 spin_unlock_bh(&ioat_chan->cleanup_lock);
726722
723
+ /* Setting up LTR values for 3.4 or later */
724
+ if (ioat_chan->ioat_dma->version >= IOAT_VER_3_4) {
725
+ u32 lat_val;
726
+
727
+ lat_val = IOAT_CHAN_LTR_ACTIVE_SNVAL |
728
+ IOAT_CHAN_LTR_ACTIVE_SNLATSCALE |
729
+ IOAT_CHAN_LTR_ACTIVE_SNREQMNT;
730
+ writel(lat_val, ioat_chan->reg_base +
731
+ IOAT_CHAN_LTR_ACTIVE_OFFSET);
732
+
733
+ lat_val = IOAT_CHAN_LTR_IDLE_SNVAL |
734
+ IOAT_CHAN_LTR_IDLE_SNLATSCALE |
735
+ IOAT_CHAN_LTR_IDLE_SNREQMNT;
736
+ writel(lat_val, ioat_chan->reg_base +
737
+ IOAT_CHAN_LTR_IDLE_OFFSET);
738
+
739
+ /* Select to active */
740
+ writeb(IOAT_CHAN_LTR_SWSEL_ACTIVE,
741
+ ioat_chan->reg_base +
742
+ IOAT_CHAN_LTR_SWSEL_OFFSET);
743
+ }
744
+
727745 ioat_start_null_desc(ioat_chan);
728746
729747 /* check that we got off the ground */
....@@ -749,8 +767,6 @@
749767 struct ioatdma_chan *ioat_chan, int idx)
750768 {
751769 struct dma_device *dma = &ioat_dma->dma_dev;
752
- struct dma_chan *c = &ioat_chan->dma_chan;
753
- unsigned long data = (unsigned long) c;
754770
755771 ioat_chan->ioat_dma = ioat_dma;
756772 ioat_chan->reg_base = ioat_dma->reg_base + (0x80 * (idx + 1));
....@@ -760,7 +776,7 @@
760776 list_add_tail(&ioat_chan->dma_chan.device_node, &dma->channels);
761777 ioat_dma->idx[idx] = ioat_chan;
762778 timer_setup(&ioat_chan->timer, ioat_timer_event, 0);
763
- tasklet_init(&ioat_chan->cleanup_task, ioat_cleanup_event, data);
779
+ tasklet_setup(&ioat_chan->cleanup_task, ioat_cleanup_event);
764780 }
765781
766782 #define IOAT_NUM_SRC_TEST 6 /* must be <= 8 */
....@@ -1177,13 +1193,17 @@
11771193 /* disable relaxed ordering */
11781194 err = pcie_capability_read_word(pdev, IOAT_DEVCTRL_OFFSET, &val16);
11791195 if (err)
1180
- return err;
1196
+ return pcibios_err_to_errno(err);
11811197
11821198 /* clear relaxed ordering enable */
11831199 val16 &= ~IOAT_DEVCTRL_ROE;
11841200 err = pcie_capability_write_word(pdev, IOAT_DEVCTRL_OFFSET, val16);
11851201 if (err)
1186
- return err;
1202
+ return pcibios_err_to_errno(err);
1203
+
1204
+ if (ioat_dma->cap & IOAT_CAP_DPS)
1205
+ writeb(ioat_pending_level + 1,
1206
+ ioat_dma->reg_base + IOAT_PREFETCH_LIMIT_OFFSET);
11871207
11881208 return 0;
11891209 }
....@@ -1245,7 +1265,7 @@
12451265 #define DRV_NAME "ioatdma"
12461266
12471267 static pci_ers_result_t ioat_pcie_error_detected(struct pci_dev *pdev,
1248
- enum pci_channel_state error)
1268
+ pci_channel_state_t error)
12491269 {
12501270 dev_dbg(&pdev->dev, "%s: PCIe AER error %d\n", DRV_NAME, error);
12511271
....@@ -1258,7 +1278,6 @@
12581278 static pci_ers_result_t ioat_pcie_error_slot_reset(struct pci_dev *pdev)
12591279 {
12601280 pci_ers_result_t result = PCI_ERS_RESULT_RECOVERED;
1261
- int err;
12621281
12631282 dev_dbg(&pdev->dev, "%s post reset handling\n", DRV_NAME);
12641283
....@@ -1271,12 +1290,6 @@
12711290 pci_restore_state(pdev);
12721291 pci_save_state(pdev);
12731292 pci_wake_from_d3(pdev, false);
1274
- }
1275
-
1276
- err = pci_cleanup_aer_uncorrect_error_status(pdev);
1277
- if (err) {
1278
- dev_err(&pdev->dev,
1279
- "AER uncorrect error status clear failed: %#x\n", err);
12801293 }
12811294
12821295 return result;
....@@ -1307,16 +1320,28 @@
13071320 .err_handler = &ioat_err_handler,
13081321 };
13091322
1323
+static void release_ioatdma(struct dma_device *device)
1324
+{
1325
+ struct ioatdma_device *d = to_ioatdma_device(device);
1326
+ int i;
1327
+
1328
+ for (i = 0; i < IOAT_MAX_CHANS; i++)
1329
+ kfree(d->idx[i]);
1330
+
1331
+ dma_pool_destroy(d->completion_pool);
1332
+ kfree(d);
1333
+}
1334
+
13101335 static struct ioatdma_device *
13111336 alloc_ioatdma(struct pci_dev *pdev, void __iomem *iobase)
13121337 {
1313
- struct device *dev = &pdev->dev;
1314
- struct ioatdma_device *d = devm_kzalloc(dev, sizeof(*d), GFP_KERNEL);
1338
+ struct ioatdma_device *d = kzalloc(sizeof(*d), GFP_KERNEL);
13151339
13161340 if (!d)
13171341 return NULL;
13181342 d->pdev = pdev;
13191343 d->reg_base = iobase;
1344
+ d->dma_dev.device_release = release_ioatdma;
13201345 return d;
13211346 }
13221347
....@@ -1357,6 +1382,8 @@
13571382 pci_set_drvdata(pdev, device);
13581383
13591384 device->version = readb(device->reg_base + IOAT_VER_OFFSET);
1385
+ if (device->version >= IOAT_VER_3_4)
1386
+ ioat_dca_enabled = 0;
13601387 if (device->version >= IOAT_VER_3_0) {
13611388 if (is_skx_ioat(pdev))
13621389 device->version = IOAT_VER_3_2;
....@@ -1383,6 +1410,8 @@
13831410 if (!device)
13841411 return;
13851412
1413
+ ioat_shutdown(pdev);
1414
+
13861415 dev_err(&pdev->dev, "Removing dma and dca services\n");
13871416 if (device->dca) {
13881417 unregister_dca_provider(device->dca, &pdev->dev);