A flaw exists in the Linux kernel related to PCI link speed calculation during retrain failures. Specifically, when `pcie failed link retrain()` fails to retrain a link, it attempts to revert to the previous link speed. However, the calculation of this speed from the Link Control 2 register does not properly mask out non-speed bits, leading to an incorrect speed value being determined as PCI SPEED UNKNOWN (0xff). This results in a warning message and potential issues with downstream link functionality. The issue occurs due to an incorrect conversion of values in `PCIE LNKCTL2 TLS2SPEED()` and `PCIE LNKCAP SLS2SPEED()`.