2 * Copyright(c) 2015 - 2017 Intel Corporation.
4 * This file is provided under a dual BSD/GPLv2 license. When using or
5 * redistributing this file, you may do so under either license.
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of version 2 of the GNU General Public License as
11 * published by the Free Software Foundation.
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
20 * Redistribution and use in source and binary forms, with or without
21 * modification, are permitted provided that the following conditions
24 * - Redistributions of source code must retain the above copyright
25 * notice, this list of conditions and the following disclaimer.
26 * - Redistributions in binary form must reproduce the above copyright
27 * notice, this list of conditions and the following disclaimer in
28 * the documentation and/or other materials provided with the
30 * - Neither the name of Intel Corporation nor the names of its
31 * contributors may be used to endorse or promote products derived
32 * from this software without specific prior written permission.
34 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
35 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
36 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
37 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
38 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
39 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
40 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
41 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
42 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
43 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
44 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
48 #include <linux/pci.h>
50 #include <linux/delay.h>
51 #include <linux/vmalloc.h>
52 #include <linux/aer.h>
53 #include <linux/module.h>
56 #include "chip_registers.h"
60 * This file contains PCIe utility routines.
64 * Code to adjust PCIe capabilities.
66 static void tune_pcie_caps(struct hfi1_devdata *);
69 * Do all the common PCIe setup and initialization.
70 * devdata is not yet allocated, and is not allocated until after this
71 * routine returns success. Therefore dd_dev_err() can't be used for error
74 int hfi1_pcie_init(struct pci_dev *pdev, const struct pci_device_id *ent)
78 ret = pci_enable_device(pdev);
81 * This can happen (in theory) iff:
82 * We did a chip reset, and then failed to reprogram the
83 * BAR, or the chip reset due to an internal error. We then
84 * unloaded the driver and reloaded it.
86 * Both reset cases set the BAR back to initial state. For
87 * the latter case, the AER sticky error bit at offset 0x718
88 * should be set, but the Linux kernel doesn't yet know
89 * about that, it appears. If the original BAR was retained
90 * in the kernel data structures, this may be OK.
92 hfi1_early_err(&pdev->dev, "pci enable failed: error %d\n",
97 ret = pci_request_regions(pdev, DRIVER_NAME);
99 hfi1_early_err(&pdev->dev,
100 "pci_request_regions fails: err %d\n", -ret);
104 ret = pci_set_dma_mask(pdev, DMA_BIT_MASK(64));
107 * If the 64 bit setup fails, try 32 bit. Some systems
108 * do not setup 64 bit maps on systems with 2GB or less
111 ret = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
113 hfi1_early_err(&pdev->dev,
114 "Unable to set DMA mask: %d\n", ret);
117 ret = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32));
119 ret = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64));
122 hfi1_early_err(&pdev->dev,
123 "Unable to set DMA consistent mask: %d\n", ret);
127 pci_set_master(pdev);
128 (void)pci_enable_pcie_error_reporting(pdev);
132 hfi1_pcie_cleanup(pdev);
138 * Clean what was done in hfi1_pcie_init()
140 void hfi1_pcie_cleanup(struct pci_dev *pdev)
142 pci_disable_device(pdev);
144 * Release regions should be called after the disable. OK to
145 * call if request regions has not been called or failed.
147 pci_release_regions(pdev);
151 * Do remaining PCIe setup, once dd is allocated, and save away
152 * fields required to re-initialize after a chip reset, or for
153 * various other purposes
155 int hfi1_pcie_ddinit(struct hfi1_devdata *dd, struct pci_dev *pdev)
158 resource_size_t addr;
162 addr = pci_resource_start(pdev, 0);
163 len = pci_resource_len(pdev, 0);
166 * The TXE PIO buffers are at the tail end of the chip space.
167 * Cut them off and map them separately.
170 /* sanity check vs expectations */
171 if (len != TXE_PIO_SEND + TXE_PIO_SIZE) {
172 dd_dev_err(dd, "chip PIO range does not match\n");
176 dd->kregbase1 = ioremap_nocache(addr, RCV_ARRAY);
177 if (!dd->kregbase1) {
178 dd_dev_err(dd, "UC mapping of kregbase1 failed\n");
181 dd_dev_info(dd, "UC base1: %p for %x\n", dd->kregbase1, RCV_ARRAY);
183 /* verify that reads actually work, save revision for reset check */
184 dd->revision = readq(dd->kregbase1 + CCE_REVISION);
185 if (dd->revision == ~(u64)0) {
186 dd_dev_err(dd, "Cannot read chip CSRs\n");
190 rcv_array_count = readq(dd->kregbase1 + RCV_ARRAY_CNT);
191 dd_dev_info(dd, "RcvArray count: %u\n", rcv_array_count);
192 dd->base2_start = RCV_ARRAY + rcv_array_count * 8;
194 dd->kregbase2 = ioremap_nocache(
195 addr + dd->base2_start,
196 TXE_PIO_SEND - dd->base2_start);
197 if (!dd->kregbase2) {
198 dd_dev_err(dd, "UC mapping of kregbase2 failed\n");
201 dd_dev_info(dd, "UC base2: %p for %x\n", dd->kregbase2,
202 TXE_PIO_SEND - dd->base2_start);
204 dd->piobase = ioremap_wc(addr + TXE_PIO_SEND, TXE_PIO_SIZE);
206 dd_dev_err(dd, "WC mapping of send buffers failed\n");
209 dd_dev_info(dd, "WC piobase: %p\n for %x", dd->piobase, TXE_PIO_SIZE);
211 dd->physaddr = addr; /* used for io_remap, etc. */
214 * Map the chip's RcvArray as write-combining to allow us
215 * to write an entire cacheline worth of entries in one shot.
217 dd->rcvarray_wc = ioremap_wc(addr + RCV_ARRAY,
218 rcv_array_count * 8);
219 if (!dd->rcvarray_wc) {
220 dd_dev_err(dd, "WC mapping of receive array failed\n");
223 dd_dev_info(dd, "WC RcvArray: %p for %x\n",
224 dd->rcvarray_wc, rcv_array_count * 8);
226 dd->flags |= HFI1_PRESENT; /* chip.c CSR routines now work */
230 hfi1_pcie_ddcleanup(dd);
235 * Do PCIe cleanup related to dd, after chip-specific cleanup, etc. Just prior
236 * to releasing the dd memory.
237 * Void because all of the core pcie cleanup functions are void.
239 void hfi1_pcie_ddcleanup(struct hfi1_devdata *dd)
241 dd->flags &= ~HFI1_PRESENT;
243 iounmap(dd->kregbase1);
244 dd->kregbase1 = NULL;
246 iounmap(dd->kregbase2);
247 dd->kregbase2 = NULL;
249 iounmap(dd->rcvarray_wc);
250 dd->rcvarray_wc = NULL;
252 iounmap(dd->piobase);
256 /* return the PCIe link speed from the given link status */
257 static u32 extract_speed(u16 linkstat)
261 switch (linkstat & PCI_EXP_LNKSTA_CLS) {
262 default: /* not defined, assume Gen1 */
263 case PCI_EXP_LNKSTA_CLS_2_5GB:
264 speed = 2500; /* Gen 1, 2.5GHz */
266 case PCI_EXP_LNKSTA_CLS_5_0GB:
267 speed = 5000; /* Gen 2, 5GHz */
269 case PCI_EXP_LNKSTA_CLS_8_0GB:
270 speed = 8000; /* Gen 3, 8GHz */
276 /* return the PCIe link speed from the given link status */
277 static u32 extract_width(u16 linkstat)
279 return (linkstat & PCI_EXP_LNKSTA_NLW) >> PCI_EXP_LNKSTA_NLW_SHIFT;
282 /* read the link status and set dd->{lbus_width,lbus_speed,lbus_info} */
283 static void update_lbus_info(struct hfi1_devdata *dd)
288 ret = pcie_capability_read_word(dd->pcidev, PCI_EXP_LNKSTA, &linkstat);
290 dd_dev_err(dd, "Unable to read from PCI config\n");
294 dd->lbus_width = extract_width(linkstat);
295 dd->lbus_speed = extract_speed(linkstat);
296 snprintf(dd->lbus_info, sizeof(dd->lbus_info),
297 "PCIe,%uMHz,x%u", dd->lbus_speed, dd->lbus_width);
301 * Read in the current PCIe link width and speed. Find if the link is
304 int pcie_speeds(struct hfi1_devdata *dd)
307 struct pci_dev *parent = dd->pcidev->bus->self;
310 if (!pci_is_pcie(dd->pcidev)) {
311 dd_dev_err(dd, "Can't find PCI Express capability!\n");
315 /* find if our max speed is Gen3 and parent supports Gen3 speeds */
316 dd->link_gen3_capable = 1;
318 ret = pcie_capability_read_dword(dd->pcidev, PCI_EXP_LNKCAP, &linkcap);
320 dd_dev_err(dd, "Unable to read from PCI config\n");
324 if ((linkcap & PCI_EXP_LNKCAP_SLS) != PCI_EXP_LNKCAP_SLS_8_0GB) {
326 "This HFI is not Gen3 capable, max speed 0x%x, need 0x3\n",
327 linkcap & PCI_EXP_LNKCAP_SLS);
328 dd->link_gen3_capable = 0;
332 * bus->max_bus_speed is set from the bridge's linkcap Max Link Speed
334 if (parent && dd->pcidev->bus->max_bus_speed != PCIE_SPEED_8_0GT) {
335 dd_dev_info(dd, "Parent PCIe bridge does not support Gen3\n");
336 dd->link_gen3_capable = 0;
339 /* obtain the link width and current speed */
340 update_lbus_info(dd);
342 dd_dev_info(dd, "%s\n", dd->lbus_info);
349 * - actual number of interrupts allocated or
350 * - 0 if fell back to INTx.
353 int request_msix(struct hfi1_devdata *dd, u32 msireq)
357 nvec = pci_alloc_irq_vectors(dd->pcidev, 1, msireq,
358 PCI_IRQ_MSIX | PCI_IRQ_LEGACY);
360 dd_dev_err(dd, "pci_alloc_irq_vectors() failed: %d\n", nvec);
366 /* check for legacy IRQ */
367 if (nvec == 1 && !dd->pcidev->msix_enabled)
373 /* restore command and BARs after a reset has wiped them out */
374 int restore_pci_variables(struct hfi1_devdata *dd)
378 ret = pci_write_config_word(dd->pcidev, PCI_COMMAND, dd->pci_command);
382 ret = pci_write_config_dword(dd->pcidev, PCI_BASE_ADDRESS_0,
387 ret = pci_write_config_dword(dd->pcidev, PCI_BASE_ADDRESS_1,
392 ret = pci_write_config_dword(dd->pcidev, PCI_ROM_ADDRESS, dd->pci_rom);
396 ret = pcie_capability_write_word(dd->pcidev, PCI_EXP_DEVCTL,
401 ret = pcie_capability_write_word(dd->pcidev, PCI_EXP_LNKCTL,
406 ret = pcie_capability_write_word(dd->pcidev, PCI_EXP_DEVCTL2,
411 ret = pci_write_config_dword(dd->pcidev, PCI_CFG_MSIX0, dd->pci_msix0);
415 if (pci_find_ext_capability(dd->pcidev, PCI_EXT_CAP_ID_TPH)) {
416 ret = pci_write_config_dword(dd->pcidev, PCIE_CFG_TPH2,
424 dd_dev_err(dd, "Unable to write to PCI config\n");
428 /* Save BARs and command to rewrite after device reset */
429 int save_pci_variables(struct hfi1_devdata *dd)
433 ret = pci_read_config_dword(dd->pcidev, PCI_BASE_ADDRESS_0,
438 ret = pci_read_config_dword(dd->pcidev, PCI_BASE_ADDRESS_1,
443 ret = pci_read_config_dword(dd->pcidev, PCI_ROM_ADDRESS, &dd->pci_rom);
447 ret = pci_read_config_word(dd->pcidev, PCI_COMMAND, &dd->pci_command);
451 ret = pcie_capability_read_word(dd->pcidev, PCI_EXP_DEVCTL,
456 ret = pcie_capability_read_word(dd->pcidev, PCI_EXP_LNKCTL,
461 ret = pcie_capability_read_word(dd->pcidev, PCI_EXP_DEVCTL2,
466 ret = pci_read_config_dword(dd->pcidev, PCI_CFG_MSIX0, &dd->pci_msix0);
470 if (pci_find_ext_capability(dd->pcidev, PCI_EXT_CAP_ID_TPH)) {
471 ret = pci_read_config_dword(dd->pcidev, PCIE_CFG_TPH2,
479 dd_dev_err(dd, "Unable to read from PCI config\n");
484 * BIOS may not set PCIe bus-utilization parameters for best performance.
485 * Check and optionally adjust them to maximize our throughput.
487 static int hfi1_pcie_caps;
488 module_param_named(pcie_caps, hfi1_pcie_caps, int, S_IRUGO);
489 MODULE_PARM_DESC(pcie_caps, "Max PCIe tuning: Payload (0..3), ReadReq (4..7)");
491 uint aspm_mode = ASPM_MODE_DISABLED;
492 module_param_named(aspm, aspm_mode, uint, S_IRUGO);
493 MODULE_PARM_DESC(aspm, "PCIe ASPM: 0: disable, 1: enable, 2: dynamic");
495 static void tune_pcie_caps(struct hfi1_devdata *dd)
497 struct pci_dev *parent;
498 u16 rc_mpss, rc_mps, ep_mpss, ep_mps;
499 u16 rc_mrrs, ep_mrrs, max_mrrs, ectl;
503 * Turn on extended tags in DevCtl in case the BIOS has turned it off
504 * to improve WFR SDMA bandwidth
506 ret = pcie_capability_read_word(dd->pcidev, PCI_EXP_DEVCTL, &ectl);
507 if ((!ret) && !(ectl & PCI_EXP_DEVCTL_EXT_TAG)) {
508 dd_dev_info(dd, "Enabling PCIe extended tags\n");
509 ectl |= PCI_EXP_DEVCTL_EXT_TAG;
510 ret = pcie_capability_write_word(dd->pcidev,
511 PCI_EXP_DEVCTL, ectl);
513 dd_dev_info(dd, "Unable to write to PCI config\n");
515 /* Find out supported and configured values for parent (root) */
516 parent = dd->pcidev->bus->self;
518 * The driver cannot perform the tuning if it does not have
519 * access to the upstream component.
522 dd_dev_info(dd, "Parent not found\n");
525 if (!pci_is_root_bus(parent->bus)) {
526 dd_dev_info(dd, "Parent not root\n");
529 if (!pci_is_pcie(parent)) {
530 dd_dev_info(dd, "Parent is not PCI Express capable\n");
533 if (!pci_is_pcie(dd->pcidev)) {
534 dd_dev_info(dd, "PCI device is not PCI Express capable\n");
537 rc_mpss = parent->pcie_mpss;
538 rc_mps = ffs(pcie_get_mps(parent)) - 8;
539 /* Find out supported and configured values for endpoint (us) */
540 ep_mpss = dd->pcidev->pcie_mpss;
541 ep_mps = ffs(pcie_get_mps(dd->pcidev)) - 8;
543 /* Find max payload supported by root, endpoint */
544 if (rc_mpss > ep_mpss)
547 /* If Supported greater than limit in module param, limit it */
548 if (rc_mpss > (hfi1_pcie_caps & 7))
549 rc_mpss = hfi1_pcie_caps & 7;
550 /* If less than (allowed, supported), bump root payload */
551 if (rc_mpss > rc_mps) {
553 pcie_set_mps(parent, 128 << rc_mps);
555 /* If less than (allowed, supported), bump endpoint payload */
556 if (rc_mpss > ep_mps) {
558 pcie_set_mps(dd->pcidev, 128 << ep_mps);
562 * Now the Read Request size.
563 * No field for max supported, but PCIe spec limits it to 4096,
564 * which is code '5' (log2(4096) - 7)
567 if (max_mrrs > ((hfi1_pcie_caps >> 4) & 7))
568 max_mrrs = (hfi1_pcie_caps >> 4) & 7;
570 max_mrrs = 128 << max_mrrs;
571 rc_mrrs = pcie_get_readrq(parent);
572 ep_mrrs = pcie_get_readrq(dd->pcidev);
574 if (max_mrrs > rc_mrrs) {
576 pcie_set_readrq(parent, rc_mrrs);
578 if (max_mrrs > ep_mrrs) {
580 pcie_set_readrq(dd->pcidev, ep_mrrs);
584 /* End of PCIe capability tuning */
587 * From here through hfi1_pci_err_handler definition is invoked via
588 * PCI error infrastructure, registered via pci
590 static pci_ers_result_t
591 pci_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
593 struct hfi1_devdata *dd = pci_get_drvdata(pdev);
594 pci_ers_result_t ret = PCI_ERS_RESULT_RECOVERED;
597 case pci_channel_io_normal:
598 dd_dev_info(dd, "State Normal, ignoring\n");
601 case pci_channel_io_frozen:
602 dd_dev_info(dd, "State Frozen, requesting reset\n");
603 pci_disable_device(pdev);
604 ret = PCI_ERS_RESULT_NEED_RESET;
607 case pci_channel_io_perm_failure:
609 dd_dev_info(dd, "State Permanent Failure, disabling\n");
610 /* no more register accesses! */
611 dd->flags &= ~HFI1_PRESENT;
612 hfi1_disable_after_error(dd);
614 /* else early, or other problem */
615 ret = PCI_ERS_RESULT_DISCONNECT;
618 default: /* shouldn't happen */
619 dd_dev_info(dd, "HFI1 PCI errors detected (state %d)\n",
626 static pci_ers_result_t
627 pci_mmio_enabled(struct pci_dev *pdev)
630 struct hfi1_devdata *dd = pci_get_drvdata(pdev);
631 pci_ers_result_t ret = PCI_ERS_RESULT_RECOVERED;
633 if (dd && dd->pport) {
634 words = read_port_cntr(dd->pport, C_RX_WORDS, CNTR_INVALID_VL);
636 ret = PCI_ERS_RESULT_NEED_RESET;
638 "HFI1 mmio_enabled function called, read wordscntr %llx, returning %d\n",
644 static pci_ers_result_t
645 pci_slot_reset(struct pci_dev *pdev)
647 struct hfi1_devdata *dd = pci_get_drvdata(pdev);
649 dd_dev_info(dd, "HFI1 slot_reset function called, ignored\n");
650 return PCI_ERS_RESULT_CAN_RECOVER;
654 pci_resume(struct pci_dev *pdev)
656 struct hfi1_devdata *dd = pci_get_drvdata(pdev);
658 dd_dev_info(dd, "HFI1 resume function called\n");
659 pci_cleanup_aer_uncorrect_error_status(pdev);
661 * Running jobs will fail, since it's asynchronous
662 * unlike sysfs-requested reset. Better than
665 hfi1_init(dd, 1); /* same as re-init after reset */
668 const struct pci_error_handlers hfi1_pci_err_handler = {
669 .error_detected = pci_error_detected,
670 .mmio_enabled = pci_mmio_enabled,
671 .slot_reset = pci_slot_reset,
672 .resume = pci_resume,
675 /*============================================================================*/
676 /* PCIe Gen3 support */
679 * This code is separated out because it is expected to be removed in the
680 * final shipping product. If not, then it will be revisited and items
681 * will be moved to more standard locations.
684 /* ASIC_PCI_SD_HOST_STATUS.FW_DNLD_STS field values */
685 #define DL_STATUS_HFI0 0x1 /* hfi0 firmware download complete */
686 #define DL_STATUS_HFI1 0x2 /* hfi1 firmware download complete */
687 #define DL_STATUS_BOTH 0x3 /* hfi0 and hfi1 firmware download complete */
689 /* ASIC_PCI_SD_HOST_STATUS.FW_DNLD_ERR field values */
690 #define DL_ERR_NONE 0x0 /* no error */
691 #define DL_ERR_SWAP_PARITY 0x1 /* parity error in SerDes interrupt */
692 /* or response data */
693 #define DL_ERR_DISABLED 0x2 /* hfi disabled */
694 #define DL_ERR_SECURITY 0x3 /* security check failed */
695 #define DL_ERR_SBUS 0x4 /* SBus status error */
696 #define DL_ERR_XFR_PARITY 0x5 /* parity error during ROM transfer*/
698 /* gasket block secondary bus reset delay */
699 #define SBR_DELAY_US 200000 /* 200ms */
701 static uint pcie_target = 3;
702 module_param(pcie_target, uint, S_IRUGO);
703 MODULE_PARM_DESC(pcie_target, "PCIe target speed (0 skip, 1-3 Gen1-3)");
705 static uint pcie_force;
706 module_param(pcie_force, uint, S_IRUGO);
707 MODULE_PARM_DESC(pcie_force, "Force driver to do a PCIe firmware download even if already at target speed");
709 static uint pcie_retry = 5;
710 module_param(pcie_retry, uint, S_IRUGO);
711 MODULE_PARM_DESC(pcie_retry, "Driver will try this many times to reach requested speed");
713 #define UNSET_PSET 255
714 #define DEFAULT_DISCRETE_PSET 2 /* discrete HFI */
715 #define DEFAULT_MCP_PSET 6 /* MCP HFI */
716 static uint pcie_pset = UNSET_PSET;
717 module_param(pcie_pset, uint, S_IRUGO);
718 MODULE_PARM_DESC(pcie_pset, "PCIe Eq Pset value to use, range is 0-10");
720 static uint pcie_ctle = 3; /* discrete on, integrated on */
721 module_param(pcie_ctle, uint, S_IRUGO);
722 MODULE_PARM_DESC(pcie_ctle, "PCIe static CTLE mode, bit 0 - discrete on/off, bit 1 - integrated on/off");
724 /* equalization columns */
729 /* discrete silicon preliminary equalization values */
730 static const u8 discrete_preliminary_eq[11][3] = {
732 { 0x00, 0x00, 0x12 }, /* p0 */
733 { 0x00, 0x00, 0x0c }, /* p1 */
734 { 0x00, 0x00, 0x0f }, /* p2 */
735 { 0x00, 0x00, 0x09 }, /* p3 */
736 { 0x00, 0x00, 0x00 }, /* p4 */
737 { 0x06, 0x00, 0x00 }, /* p5 */
738 { 0x09, 0x00, 0x00 }, /* p6 */
739 { 0x06, 0x00, 0x0f }, /* p7 */
740 { 0x09, 0x00, 0x09 }, /* p8 */
741 { 0x0c, 0x00, 0x00 }, /* p9 */
742 { 0x00, 0x00, 0x18 }, /* p10 */
745 /* integrated silicon preliminary equalization values */
746 static const u8 integrated_preliminary_eq[11][3] = {
748 { 0x00, 0x1e, 0x07 }, /* p0 */
749 { 0x00, 0x1e, 0x05 }, /* p1 */
750 { 0x00, 0x1e, 0x06 }, /* p2 */
751 { 0x00, 0x1e, 0x04 }, /* p3 */
752 { 0x00, 0x1e, 0x00 }, /* p4 */
753 { 0x03, 0x1e, 0x00 }, /* p5 */
754 { 0x04, 0x1e, 0x00 }, /* p6 */
755 { 0x03, 0x1e, 0x06 }, /* p7 */
756 { 0x03, 0x1e, 0x04 }, /* p8 */
757 { 0x05, 0x1e, 0x00 }, /* p9 */
758 { 0x00, 0x1e, 0x0a }, /* p10 */
761 static const u8 discrete_ctle_tunings[11][4] = {
763 { 0x48, 0x0b, 0x04, 0x04 }, /* p0 */
764 { 0x60, 0x05, 0x0f, 0x0a }, /* p1 */
765 { 0x50, 0x09, 0x06, 0x06 }, /* p2 */
766 { 0x68, 0x05, 0x0f, 0x0a }, /* p3 */
767 { 0x80, 0x05, 0x0f, 0x0a }, /* p4 */
768 { 0x70, 0x05, 0x0f, 0x0a }, /* p5 */
769 { 0x68, 0x05, 0x0f, 0x0a }, /* p6 */
770 { 0x38, 0x0f, 0x00, 0x00 }, /* p7 */
771 { 0x48, 0x09, 0x06, 0x06 }, /* p8 */
772 { 0x60, 0x05, 0x0f, 0x0a }, /* p9 */
773 { 0x38, 0x0f, 0x00, 0x00 }, /* p10 */
776 static const u8 integrated_ctle_tunings[11][4] = {
778 { 0x38, 0x0f, 0x00, 0x00 }, /* p0 */
779 { 0x38, 0x0f, 0x00, 0x00 }, /* p1 */
780 { 0x38, 0x0f, 0x00, 0x00 }, /* p2 */
781 { 0x38, 0x0f, 0x00, 0x00 }, /* p3 */
782 { 0x58, 0x0a, 0x05, 0x05 }, /* p4 */
783 { 0x48, 0x0a, 0x05, 0x05 }, /* p5 */
784 { 0x40, 0x0a, 0x05, 0x05 }, /* p6 */
785 { 0x38, 0x0f, 0x00, 0x00 }, /* p7 */
786 { 0x38, 0x0f, 0x00, 0x00 }, /* p8 */
787 { 0x38, 0x09, 0x06, 0x06 }, /* p9 */
788 { 0x38, 0x0e, 0x01, 0x01 }, /* p10 */
791 /* helper to format the value to write to hardware */
792 #define eq_value(pre, curr, post) \
794 PCIE_CFG_REG_PL102_GEN3_EQ_PRE_CURSOR_PSET_SHIFT) \
795 | (((u32)(curr)) << PCIE_CFG_REG_PL102_GEN3_EQ_CURSOR_PSET_SHIFT) \
796 | (((u32)(post)) << \
797 PCIE_CFG_REG_PL102_GEN3_EQ_POST_CURSOR_PSET_SHIFT))
800 * Load the given EQ preset table into the PCIe hardware.
802 static int load_eq_table(struct hfi1_devdata *dd, const u8 eq[11][3], u8 fs,
805 struct pci_dev *pdev = dd->pcidev;
809 u8 c_minus1, c0, c_plus1;
812 for (i = 0; i < 11; i++) {
814 pci_write_config_dword(pdev, PCIE_CFG_REG_PL103, i);
815 /* write the value */
816 c_minus1 = eq[i][PREC] / div;
817 c0 = fs - (eq[i][PREC] / div) - (eq[i][POST] / div);
818 c_plus1 = eq[i][POST] / div;
819 pci_write_config_dword(pdev, PCIE_CFG_REG_PL102,
820 eq_value(c_minus1, c0, c_plus1));
821 /* check if these coefficients violate EQ rules */
822 ret = pci_read_config_dword(dd->pcidev,
823 PCIE_CFG_REG_PL105, &violation);
825 dd_dev_err(dd, "Unable to read from PCI config\n");
831 & PCIE_CFG_REG_PL105_GEN3_EQ_VIOLATE_COEF_RULES_SMASK){
832 if (hit_error == 0) {
834 "Gen3 EQ Table Coefficient rule violations\n");
835 dd_dev_err(dd, " prec attn post\n");
837 dd_dev_err(dd, " p%02d: %02x %02x %02x\n",
838 i, (u32)eq[i][0], (u32)eq[i][1],
840 dd_dev_err(dd, " %02x %02x %02x\n",
841 (u32)c_minus1, (u32)c0, (u32)c_plus1);
851 * Steps to be done after the PCIe firmware is downloaded and
852 * before the SBR for the Pcie Gen3.
853 * The SBus resource is already being held.
855 static void pcie_post_steps(struct hfi1_devdata *dd)
859 set_sbus_fast_mode(dd);
861 * Write to the PCIe PCSes to set the G3_LOCKED_NEXT bits to 1.
862 * This avoids a spurious framing error that can otherwise be
863 * generated by the MAC layer.
865 * Use individual addresses since no broadcast is set up.
867 for (i = 0; i < NUM_PCIE_SERDES; i++) {
868 sbus_request(dd, pcie_pcs_addrs[dd->hfi1_id][i],
869 0x03, WRITE_SBUS_RECEIVER, 0x00022132);
872 clear_sbus_fast_mode(dd);
876 * Trigger a secondary bus reset (SBR) on ourselves using our parent.
878 * Based on pci_parent_bus_reset() which is not exported by the
881 static int trigger_sbr(struct hfi1_devdata *dd)
883 struct pci_dev *dev = dd->pcidev;
884 struct pci_dev *pdev;
887 if (!dev->bus->self) {
888 dd_dev_err(dd, "%s: no parent device\n", __func__);
892 /* should not be anyone else on the bus */
893 list_for_each_entry(pdev, &dev->bus->devices, bus_list)
896 "%s: another device is on the same bus\n",
902 * A secondary bus reset (SBR) issues a hot reset to our device.
903 * The following routine does a 1s wait after the reset is dropped
904 * per PCI Trhfa (recovery time). PCIe 3.0 section 6.6.1 -
905 * Conventional Reset, paragraph 3, line 35 also says that a 1s
906 * delay after a reset is required. Per spec requirements,
907 * the link is either working or not after that point.
909 pci_reset_bridge_secondary_bus(dev->bus->self);
915 * Write the given gasket interrupt register.
917 static void write_gasket_interrupt(struct hfi1_devdata *dd, int index,
920 write_csr(dd, ASIC_PCIE_SD_INTRPT_LIST + (index * 8),
921 (((u64)code << ASIC_PCIE_SD_INTRPT_LIST_INTRPT_CODE_SHIFT) |
922 ((u64)data << ASIC_PCIE_SD_INTRPT_LIST_INTRPT_DATA_SHIFT)));
926 * Tell the gasket logic how to react to the reset.
928 static void arm_gasket_logic(struct hfi1_devdata *dd)
932 reg = (((u64)1 << dd->hfi1_id) <<
933 ASIC_PCIE_SD_HOST_CMD_INTRPT_CMD_SHIFT) |
934 ((u64)pcie_serdes_broadcast[dd->hfi1_id] <<
935 ASIC_PCIE_SD_HOST_CMD_SBUS_RCVR_ADDR_SHIFT |
936 ASIC_PCIE_SD_HOST_CMD_SBR_MODE_SMASK |
937 ((u64)SBR_DELAY_US & ASIC_PCIE_SD_HOST_CMD_TIMER_MASK) <<
938 ASIC_PCIE_SD_HOST_CMD_TIMER_SHIFT);
939 write_csr(dd, ASIC_PCIE_SD_HOST_CMD, reg);
940 /* read back to push the write */
941 read_csr(dd, ASIC_PCIE_SD_HOST_CMD);
945 * CCE_PCIE_CTRL long name helpers
946 * We redefine these shorter macros to use in the code while leaving
947 * chip_registers.h to be autogenerated from the hardware spec.
949 #define LANE_BUNDLE_MASK CCE_PCIE_CTRL_PCIE_LANE_BUNDLE_MASK
950 #define LANE_BUNDLE_SHIFT CCE_PCIE_CTRL_PCIE_LANE_BUNDLE_SHIFT
951 #define LANE_DELAY_MASK CCE_PCIE_CTRL_PCIE_LANE_DELAY_MASK
952 #define LANE_DELAY_SHIFT CCE_PCIE_CTRL_PCIE_LANE_DELAY_SHIFT
953 #define MARGIN_OVERWRITE_ENABLE_SHIFT CCE_PCIE_CTRL_XMT_MARGIN_OVERWRITE_ENABLE_SHIFT
954 #define MARGIN_SHIFT CCE_PCIE_CTRL_XMT_MARGIN_SHIFT
955 #define MARGIN_G1_G2_OVERWRITE_MASK CCE_PCIE_CTRL_XMT_MARGIN_GEN1_GEN2_OVERWRITE_ENABLE_MASK
956 #define MARGIN_G1_G2_OVERWRITE_SHIFT CCE_PCIE_CTRL_XMT_MARGIN_GEN1_GEN2_OVERWRITE_ENABLE_SHIFT
957 #define MARGIN_GEN1_GEN2_MASK CCE_PCIE_CTRL_XMT_MARGIN_GEN1_GEN2_MASK
958 #define MARGIN_GEN1_GEN2_SHIFT CCE_PCIE_CTRL_XMT_MARGIN_GEN1_GEN2_SHIFT
961 * Write xmt_margin for full-swing (WFR-B) or half-swing (WFR-C).
963 static void write_xmt_margin(struct hfi1_devdata *dd, const char *fname)
971 pcie_ctrl = read_csr(dd, CCE_PCIE_CTRL);
974 * For Discrete, use full-swing.
975 * - PCIe TX defaults to full-swing.
976 * Leave this register as default.
977 * For Integrated, use half-swing
978 * - Copy xmt_margin and xmt_margin_oe
979 * from Gen1/Gen2 to Gen3.
981 if (dd->pcidev->device == PCI_DEVICE_ID_INTEL1) { /* integrated */
982 /* extract initial fields */
983 xmt_margin = (pcie_ctrl >> MARGIN_GEN1_GEN2_SHIFT)
984 & MARGIN_GEN1_GEN2_MASK;
985 xmt_margin_oe = (pcie_ctrl >> MARGIN_G1_G2_OVERWRITE_SHIFT)
986 & MARGIN_G1_G2_OVERWRITE_MASK;
987 lane_delay = (pcie_ctrl >> LANE_DELAY_SHIFT) & LANE_DELAY_MASK;
988 lane_bundle = (pcie_ctrl >> LANE_BUNDLE_SHIFT)
992 * For A0, EFUSE values are not set. Override with the
997 * xmt_margin and OverwiteEnabel should be the
998 * same for Gen1/Gen2 and Gen3
1001 xmt_margin_oe = 0x1;
1002 lane_delay = 0xF; /* Delay 240ns. */
1003 lane_bundle = 0x0; /* Set to 1 lane. */
1006 /* overwrite existing values */
1007 pcie_ctrl = (xmt_margin << MARGIN_GEN1_GEN2_SHIFT)
1008 | (xmt_margin_oe << MARGIN_G1_G2_OVERWRITE_SHIFT)
1009 | (xmt_margin << MARGIN_SHIFT)
1010 | (xmt_margin_oe << MARGIN_OVERWRITE_ENABLE_SHIFT)
1011 | (lane_delay << LANE_DELAY_SHIFT)
1012 | (lane_bundle << LANE_BUNDLE_SHIFT);
1014 write_csr(dd, CCE_PCIE_CTRL, pcie_ctrl);
1017 dd_dev_dbg(dd, "%s: program XMT margin, CcePcieCtrl 0x%llx\n",
1022 * Do all the steps needed to transition the PCIe link to Gen3 speed.
1024 int do_pcie_gen3_transition(struct hfi1_devdata *dd)
1026 struct pci_dev *parent = dd->pcidev->bus->self;
1032 int do_retry, retry_count = 0;
1035 uint pset = pcie_pset;
1036 u16 target_vector, target_speed;
1037 u16 lnkctl2, vendor;
1040 const u8 (*ctle_tunings)[4];
1041 uint static_ctle_mode;
1042 int return_error = 0;
1044 /* PCIe Gen3 is for the ASIC only */
1045 if (dd->icode != ICODE_RTL_SILICON)
1048 if (pcie_target == 1) { /* target Gen1 */
1049 target_vector = PCI_EXP_LNKCTL2_TLS_2_5GT;
1050 target_speed = 2500;
1051 } else if (pcie_target == 2) { /* target Gen2 */
1052 target_vector = PCI_EXP_LNKCTL2_TLS_5_0GT;
1053 target_speed = 5000;
1054 } else if (pcie_target == 3) { /* target Gen3 */
1055 target_vector = PCI_EXP_LNKCTL2_TLS_8_0GT;
1056 target_speed = 8000;
1058 /* off or invalid target - skip */
1059 dd_dev_info(dd, "%s: Skipping PCIe transition\n", __func__);
1063 /* if already at target speed, done (unless forced) */
1064 if (dd->lbus_speed == target_speed) {
1065 dd_dev_info(dd, "%s: PCIe already at gen%d, %s\n", __func__,
1067 pcie_force ? "re-doing anyway" : "skipping");
1073 * The driver cannot do the transition if it has no access to the
1074 * upstream component
1077 dd_dev_info(dd, "%s: No upstream, Can't do gen3 transition\n",
1083 * Do the Gen3 transition. Steps are those of the PCIe Gen3
1087 /* step 1: pcie link working in gen1/gen2 */
1089 /* step 2: if either side is not capable of Gen3, done */
1090 if (pcie_target == 3 && !dd->link_gen3_capable) {
1091 dd_dev_err(dd, "The PCIe link is not Gen3 capable\n");
1096 /* hold the SBus resource across the firmware download and SBR */
1097 ret = acquire_chip_resource(dd, CR_SBUS, SBUS_TIMEOUT);
1099 dd_dev_err(dd, "%s: unable to acquire SBus resource\n",
1104 /* make sure thermal polling is not causing interrupts */
1105 therm = read_csr(dd, ASIC_CFG_THERM_POLL_EN);
1107 write_csr(dd, ASIC_CFG_THERM_POLL_EN, 0x0);
1109 dd_dev_info(dd, "%s: Disabled therm polling\n",
1114 /* the SBus download will reset the spico for thermal */
1116 /* step 3: download SBus Master firmware */
1117 /* step 4: download PCIe Gen3 SerDes firmware */
1118 dd_dev_info(dd, "%s: downloading firmware\n", __func__);
1119 ret = load_pcie_firmware(dd);
1121 /* do not proceed if the firmware cannot be downloaded */
1126 /* step 5: set up device parameter settings */
1127 dd_dev_info(dd, "%s: setting PCIe registers\n", __func__);
1130 * PcieCfgSpcie1 - Link Control 3
1131 * Leave at reset value. No need to set PerfEq - link equalization
1132 * will be performed automatically after the SBR when the target
1136 /* clear all 16 per-lane error bits (PCIe: Lane Error Status) */
1137 pci_write_config_dword(dd->pcidev, PCIE_CFG_SPCIE2, 0xffff);
1139 /* step 5a: Set Synopsys Port Logic registers */
1142 * PcieCfgRegPl2 - Port Force Link
1144 * Set the low power field to 0x10 to avoid unnecessary power
1145 * management messages. All other fields are zero.
1147 reg32 = 0x10ul << PCIE_CFG_REG_PL2_LOW_PWR_ENT_CNT_SHIFT;
1148 pci_write_config_dword(dd->pcidev, PCIE_CFG_REG_PL2, reg32);
1151 * PcieCfgRegPl100 - Gen3 Control
1153 * turn off PcieCfgRegPl100.Gen3ZRxDcNonCompl
1154 * turn on PcieCfgRegPl100.EqEieosCnt
1155 * Everything else zero.
1157 reg32 = PCIE_CFG_REG_PL100_EQ_EIEOS_CNT_SMASK;
1158 pci_write_config_dword(dd->pcidev, PCIE_CFG_REG_PL100, reg32);
1161 * PcieCfgRegPl101 - Gen3 EQ FS and LF
1162 * PcieCfgRegPl102 - Gen3 EQ Presets to Coefficients Mapping
1163 * PcieCfgRegPl103 - Gen3 EQ Preset Index
1164 * PcieCfgRegPl105 - Gen3 EQ Status
1166 * Give initial EQ settings.
1168 if (dd->pcidev->device == PCI_DEVICE_ID_INTEL0) { /* discrete */
1169 /* 1000mV, FS=24, LF = 8 */
1173 eq = discrete_preliminary_eq;
1174 default_pset = DEFAULT_DISCRETE_PSET;
1175 ctle_tunings = discrete_ctle_tunings;
1176 /* bit 0 - discrete on/off */
1177 static_ctle_mode = pcie_ctle & 0x1;
1179 /* 400mV, FS=29, LF = 9 */
1183 eq = integrated_preliminary_eq;
1184 default_pset = DEFAULT_MCP_PSET;
1185 ctle_tunings = integrated_ctle_tunings;
1186 /* bit 1 - integrated on/off */
1187 static_ctle_mode = (pcie_ctle >> 1) & 0x1;
1189 pci_write_config_dword(dd->pcidev, PCIE_CFG_REG_PL101,
1191 PCIE_CFG_REG_PL101_GEN3_EQ_LOCAL_FS_SHIFT) |
1193 PCIE_CFG_REG_PL101_GEN3_EQ_LOCAL_LF_SHIFT));
1194 ret = load_eq_table(dd, eq, fs, div);
1199 * PcieCfgRegPl106 - Gen3 EQ Control
1201 * Set Gen3EqPsetReqVec, leave other fields 0.
1203 if (pset == UNSET_PSET)
1204 pset = default_pset;
1205 if (pset > 10) { /* valid range is 0-10, inclusive */
1206 dd_dev_err(dd, "%s: Invalid Eq Pset %u, setting to %d\n",
1207 __func__, pset, default_pset);
1208 pset = default_pset;
1210 dd_dev_info(dd, "%s: using EQ Pset %u\n", __func__, pset);
1211 pci_write_config_dword(dd->pcidev, PCIE_CFG_REG_PL106,
1213 PCIE_CFG_REG_PL106_GEN3_EQ_PSET_REQ_VEC_SHIFT) |
1214 PCIE_CFG_REG_PL106_GEN3_EQ_EVAL2MS_DISABLE_SMASK |
1215 PCIE_CFG_REG_PL106_GEN3_EQ_PHASE23_EXIT_MODE_SMASK);
1218 * step 5b: Do post firmware download steps via SBus
1220 dd_dev_info(dd, "%s: doing pcie post steps\n", __func__);
1221 pcie_post_steps(dd);
1224 * step 5c: Program gasket interrupts
1226 /* set the Rx Bit Rate to REFCLK ratio */
1227 write_gasket_interrupt(dd, intnum++, 0x0006, 0x0050);
1228 /* disable pCal for PCIe Gen3 RX equalization */
1229 /* select adaptive or static CTLE */
1230 write_gasket_interrupt(dd, intnum++, 0x0026,
1231 0x5b01 | (static_ctle_mode << 3));
1233 * Enable iCal for PCIe Gen3 RX equalization, and set which
1234 * evaluation of RX_EQ_EVAL will launch the iCal procedure.
1236 write_gasket_interrupt(dd, intnum++, 0x0026, 0x5202);
1238 if (static_ctle_mode) {
1239 /* apply static CTLE tunings */
1240 u8 pcie_dc, pcie_lf, pcie_hf, pcie_bw;
1242 pcie_dc = ctle_tunings[pset][0];
1243 pcie_lf = ctle_tunings[pset][1];
1244 pcie_hf = ctle_tunings[pset][2];
1245 pcie_bw = ctle_tunings[pset][3];
1246 write_gasket_interrupt(dd, intnum++, 0x0026, 0x0200 | pcie_dc);
1247 write_gasket_interrupt(dd, intnum++, 0x0026, 0x0100 | pcie_lf);
1248 write_gasket_interrupt(dd, intnum++, 0x0026, 0x0000 | pcie_hf);
1249 write_gasket_interrupt(dd, intnum++, 0x0026, 0x5500 | pcie_bw);
1252 /* terminate list */
1253 write_gasket_interrupt(dd, intnum++, 0x0000, 0x0000);
1256 * step 5d: program XMT margin
1258 write_xmt_margin(dd, __func__);
1261 * step 5e: disable active state power management (ASPM). It
1262 * will be enabled if required later
1264 dd_dev_info(dd, "%s: clearing ASPM\n", __func__);
1265 aspm_hw_disable_l1(dd);
1268 * step 5f: clear DirectSpeedChange
1269 * PcieCfgRegPl67.DirectSpeedChange must be zero to prevent the
1270 * change in the speed target from starting before we are ready.
1271 * This field defaults to 0 and we are not changing it, so nothing
1275 /* step 5g: Set target link speed */
1277 * Set target link speed to be target on both device and parent.
1278 * On setting the parent: Some system BIOSs "helpfully" set the
1279 * parent target speed to Gen2 to match the ASIC's initial speed.
1280 * We can set the target Gen3 because we have already checked
1281 * that it is Gen3 capable earlier.
1283 dd_dev_info(dd, "%s: setting parent target link speed\n", __func__);
1284 ret = pcie_capability_read_word(parent, PCI_EXP_LNKCTL2, &lnkctl2);
1286 dd_dev_err(dd, "Unable to read from PCI config\n");
1291 dd_dev_info(dd, "%s: ..old link control2: 0x%x\n", __func__,
1293 /* only write to parent if target is not as high as ours */
1294 if ((lnkctl2 & PCI_EXP_LNKCTL2_TLS) < target_vector) {
1295 lnkctl2 &= ~PCI_EXP_LNKCTL2_TLS;
1296 lnkctl2 |= target_vector;
1297 dd_dev_info(dd, "%s: ..new link control2: 0x%x\n", __func__,
1299 ret = pcie_capability_write_word(parent,
1300 PCI_EXP_LNKCTL2, lnkctl2);
1302 dd_dev_err(dd, "Unable to write to PCI config\n");
1307 dd_dev_info(dd, "%s: ..target speed is OK\n", __func__);
1310 dd_dev_info(dd, "%s: setting target link speed\n", __func__);
1311 ret = pcie_capability_read_word(dd->pcidev, PCI_EXP_LNKCTL2, &lnkctl2);
1313 dd_dev_err(dd, "Unable to read from PCI config\n");
1318 dd_dev_info(dd, "%s: ..old link control2: 0x%x\n", __func__,
1320 lnkctl2 &= ~PCI_EXP_LNKCTL2_TLS;
1321 lnkctl2 |= target_vector;
1322 dd_dev_info(dd, "%s: ..new link control2: 0x%x\n", __func__,
1324 ret = pcie_capability_write_word(dd->pcidev, PCI_EXP_LNKCTL2, lnkctl2);
1326 dd_dev_err(dd, "Unable to write to PCI config\n");
1331 /* step 5h: arm gasket logic */
1332 /* hold DC in reset across the SBR */
1333 write_csr(dd, CCE_DC_CTRL, CCE_DC_CTRL_DC_RESET_SMASK);
1334 (void)read_csr(dd, CCE_DC_CTRL); /* DC reset hold */
1335 /* save firmware control across the SBR */
1336 fw_ctrl = read_csr(dd, MISC_CFG_FW_CTRL);
1338 dd_dev_info(dd, "%s: arming gasket logic\n", __func__);
1339 arm_gasket_logic(dd);
1342 * step 6: quiesce PCIe link
1343 * The chip has already been reset, so there will be no traffic
1344 * from the chip. Linux has no easy way to enforce that it will
1345 * not try to access the device, so we just need to hope it doesn't
1346 * do it while we are doing the reset.
1350 * step 7: initiate the secondary bus reset (SBR)
1351 * step 8: hardware brings the links back up
1352 * step 9: wait for link speed transition to be complete
1354 dd_dev_info(dd, "%s: calling trigger_sbr\n", __func__);
1355 ret = trigger_sbr(dd);
1359 /* step 10: decide what to do next */
1361 /* check if we can read PCI space */
1362 ret = pci_read_config_word(dd->pcidev, PCI_VENDOR_ID, &vendor);
1365 "%s: read of VendorID failed after SBR, err %d\n",
1370 if (vendor == 0xffff) {
1371 dd_dev_info(dd, "%s: VendorID is all 1s after SBR\n", __func__);
1377 /* restore PCI space registers we know were reset */
1378 dd_dev_info(dd, "%s: calling restore_pci_variables\n", __func__);
1379 ret = restore_pci_variables(dd);
1381 dd_dev_err(dd, "%s: Could not restore PCI variables\n",
1387 /* restore firmware control */
1388 write_csr(dd, MISC_CFG_FW_CTRL, fw_ctrl);
1391 * Check the gasket block status.
1393 * This is the first CSR read after the SBR. If the read returns
1394 * all 1s (fails), the link did not make it back.
1396 * Once we're sure we can read and write, clear the DC reset after
1397 * the SBR. Then check for any per-lane errors. Then look over
1400 reg = read_csr(dd, ASIC_PCIE_SD_HOST_STATUS);
1401 dd_dev_info(dd, "%s: gasket block status: 0x%llx\n", __func__, reg);
1402 if (reg == ~0ull) { /* PCIe read failed/timeout */
1403 dd_dev_err(dd, "SBR failed - unable to read from device\n");
1409 /* clear the DC reset */
1410 write_csr(dd, CCE_DC_CTRL, 0);
1412 /* Set the LED off */
1415 /* check for any per-lane errors */
1416 ret = pci_read_config_dword(dd->pcidev, PCIE_CFG_SPCIE2, ®32);
1418 dd_dev_err(dd, "Unable to read from PCI config\n");
1423 dd_dev_info(dd, "%s: per-lane errors: 0x%x\n", __func__, reg32);
1425 /* extract status, look for our HFI */
1426 status = (reg >> ASIC_PCIE_SD_HOST_STATUS_FW_DNLD_STS_SHIFT)
1427 & ASIC_PCIE_SD_HOST_STATUS_FW_DNLD_STS_MASK;
1428 if ((status & (1 << dd->hfi1_id)) == 0) {
1430 "%s: gasket status 0x%x, expecting 0x%x\n",
1431 __func__, status, 1 << dd->hfi1_id);
1437 err = (reg >> ASIC_PCIE_SD_HOST_STATUS_FW_DNLD_ERR_SHIFT)
1438 & ASIC_PCIE_SD_HOST_STATUS_FW_DNLD_ERR_MASK;
1440 dd_dev_err(dd, "%s: gasket error %d\n", __func__, err);
1445 /* update our link information cache */
1446 update_lbus_info(dd);
1447 dd_dev_info(dd, "%s: new speed and width: %s\n", __func__,
1450 if (dd->lbus_speed != target_speed) { /* not target */
1452 do_retry = retry_count < pcie_retry;
1453 dd_dev_err(dd, "PCIe link speed did not switch to Gen%d%s\n",
1454 pcie_target, do_retry ? ", retrying" : "");
1457 msleep(100); /* allow time to settle */
1465 write_csr(dd, ASIC_CFG_THERM_POLL_EN, 0x1);
1467 dd_dev_info(dd, "%s: Re-enable therm polling\n",
1470 release_chip_resource(dd, CR_SBUS);
1472 /* return no error if it is OK to be at current speed */
1473 if (ret && !return_error) {
1474 dd_dev_err(dd, "Proceeding at current speed PCIe speed\n");
1478 dd_dev_info(dd, "%s: done\n", __func__);