]> mj.ucw.cz Git - pciutils.git/blob - lmr/lmr.h
pcilmr: Add functions for device checking and preparations before main margining...
[pciutils.git] / lmr / lmr.h
1 /*
2  *      The PCI Utilities -- Margining utility main header
3  *
4  *      Copyright (c) 2023 KNS Group LLC (YADRO)
5  *
6  *      Can be freely distributed and used under the terms of the GNU GPL v2+.
7  *
8  *      SPDX-License-Identifier: GPL-2.0-or-later
9  */
10
11 #ifndef _LMR_H
12 #define _LMR_H
13
14 #include <stdbool.h>
15
16 #include "pciutils.h"
17
18 /* PCI Device wrapper for margining functions */
19 struct margin_dev {
20   struct pci_dev *dev;
21   int lmr_cap_addr;
22   u8 width;
23   u8 retimers_n;
24   u8 link_speed;
25
26   /* Saved Device settings to restore after margining */
27   u8 aspm;
28   bool hasd; // Hardware Autonomous Speed Disable
29   bool hawd; // Hardware Autonomous Width Disable
30 };
31
32 struct margin_link {
33   struct margin_dev down_port;
34   struct margin_dev up_port;
35 };
36
37 /* margin_hw */
38
39 /* Verify that devices form the link with 16 GT/s or 32 GT/s data rate */
40 bool margin_verify_link(struct pci_dev *down_port, struct pci_dev *up_port);
41
42 /* Check Margining Ready bit from Margining Port Status Register */
43 bool margin_check_ready_bit(struct pci_dev *dev);
44
45 /* Verify link and fill wrappers */
46 bool margin_fill_link(struct pci_dev *down_port, struct pci_dev *up_port,
47                       struct margin_link *wrappers);
48
49 /* Disable ASPM, set Hardware Autonomous Speed/Width Disable bits */
50 bool margin_prep_link(struct margin_link *link);
51
52 /* Restore ASPM, Hardware Autonomous Speed/Width settings */
53 void margin_restore_link(struct margin_link *link);
54
55 #endif