usb3 link traning

USB3.0 has a state machine called LTSSM (Link training and status state machine) which is responsible for

  1. Initialization and link training
  2. Power management transitions
  3. Link error recovery and other connectivity issues.

LTSSM has 12 high level states as shown below. In this blog, we will examine the states that are involved in link training, and see how link partners moves to state U0 where actual transfers begin.

12个状态分为三组:u0是正常工作状态

First, there are four operational link states, U0, U1, U2, and U3. U0 is a state where a SuperSpeed link is enabled. Packet transfers are in progress or the link is idle. U1 is low power link state where no packet transfer is carried out and the SuperSpeed link connectivity can be disabled to allow opportunities for saving the link power. U2 is also a low power link state. Compared with U1, U2 allows for further power saving opportunities with a penalty of increased exit latency. U3 is a link suspend state where aggressive power saving opportunities are possible.

​​​​​​​Second, there are four link states, Rx.Detect, Polling, Recovery, and Hot Reset, that are introduced for link initialization and training. Rx.Detect represents the initial power-on link state where a port is attempting to determine if its SuperSpeed link partner is present. Upon detecting the presence of a SuperSpeed link partner, the link training process will be started. Polling is a link state that is defined for the two link partners to have their SuperSpeed transmitters and receivers trained, synchronized, and ready for packet transfer. Recovery is a link state defined for retraining the link when the two link partners exit from a low power link state, or when a link partner has detected that the link is not operating in U0 properly and the link needs to be retrained, or when a link partner decides to change the mode of link operation. Hot Reset is a state defined to allow a downstream port to reset its upstream port.

Third, two other link states, Loopback and Compliance Mode, are introduced for bit error test and 
transmitter compliance test. Finally, two more link states are defined. SS.Inactive is a link error 
state where a link is in a non-operable state and software intervention is needed. SS.Disabled is a 
link state where SuperSpeed connectivity is disabled and the link may operate under USB 2.0 
mode

链路训练是在上电复位后或指示热复位时链路初始化期间发生的一系列事件。这基本上是在开始对链路进行任何类型的传输之前检测链路伙伴并训练链路。

如上图所示,链路训练序列从 Rx.Detect 开始(上行端口和下行端口的电源开启状态),并以退出到 U0 结束,这是发送和接收数据包的正常操作状态。在链路训练之前,上游和下游端口都将处于 SS.Disabled 状态(移除端口的 SuperSpeed 连接的状态)。在轮询状态下,通过 LFPS(低频周期信号)握手启用链路训练,该握手用于在没有 SS 信令的情况下传递信息 

下图显示了链路训练状态及其子状态。

polling和u0 之间链路是如何训练的,TSEQ,TS1,TS2

How data is displayed here

For simplicity, data is shown in 8-bit hex dump format. As 8b/10b encoding involves K symbols, these are shown in their 8-bit hex representation in bold font. The 8b/10b symbol encodings are listed in Appendix A of the USB spec (and in several other documents available).

In particular, note that K28.5 (Comma) appears as 0xbc in bold.

Also for simplicity, the different patterns are shown in hex dumps starting with offset 0. This alignment is artificial -- there is no guarantee for any 16-bit nor 32-bit alignment, or at all, on a real data link. The USB 3.0's stream granularity is a link symbol.

Also omitted are SKP ordered sets, which consist of two consecutive K28.1 symbols (decoded as 0x3c). These can be inserted by the transmitting side in certain places (see section 6.4.3.1 in the spec) or virtually anywhere by the receiver's PHY to maintain its elasticity buffer. The examples shown below are clean from SKP symbols.

Stage I: Polling LFPS pulses

This is the first thing seen after the physical connection of a USB 3.0 plug. On the wires, they are preceded by receiver detection pulses, which are visible on an oscilloscope, but they produce no output from the PHY's receiver interface.

It's worth to note that no reset signal is issued, in particular no LFPS reset. Those familiar with USB 1.1 / 2.0 might expect one or several resets, but this is not the case with USB 3.0.

The Polling LFPS bursts are detected by the PHY's Electrical Idle being deasserted for 1 us each time, with 9 us between these (it can be seen as a pulse rate of 10 us with a duty cycle of 10%).

Once both sides have seen the other side's Polling LFPS pulses, they stop generating those, and turn on their MGT transmitters. There should be at least 16 such pulses according to the spec, but sometimes fewer are detected. Fewer pulses than the 16 required for transmission is a slight breach of the spec, since as few as two pulses are enough for reception on the other side.

Stage II: TSEQ ordered sets

The first thing transmitted on the MGT link are TSEQ ordered sets. Following the USB spec's section 6.4.1.1.3, the TSEQ ordered set is transmitted 65536 times (three sets are shown below).

00000000  bc ff 17 c0 14 b2 e7 02  82 72 6e 28 a6 be 6d bf  |.........rn(..m.|
00000010  4a 4a 4a 4a 4a 4a 4a 4a  4a 4a 4a 4a 4a 4a 4a 4a  |JJJJJJJJJJJJJJJJ|
00000020  bc ff 17 c0 14 b2 e7 02  82 72 6e 28 a6 be 6d bf  |.........rn(..m.|
00000030  4a 4a 4a 4a 4a 4a 4a 4a  4a 4a 4a 4a 4a 4a 4a 4a  |JJJJJJJJJJJJJJJJ|
00000040  bc ff 17 c0 14 b2 e7 02  82 72 6e 28 a6 be 6d bf  |.........rn(..m.|
00000050  4a 4a 4a 4a 4a 4a 4a 4a  4a 4a 4a 4a 4a 4a 4a 4a  |JJJJJJJJJJJJJJJJ|
[ ... ]

As each set is 32 symbols long, this sequence is 2097152 (2^21) symbols long, and lasts about 4.2 ms. The number of symbols received is usually slightly smaller, as some symbols are lost until the receiver's MGT's is locked.

Note that symbols 1-15 in the TSEQ ordered set are the scrambler's first symbols after its reset. Compare with the last table in Appendix B in the USB 3.x spec.

Stage III: TS1 ordered sets

After the TSEQ sequence, TS1 ordered sets are transmitted. There is no condition for switching from TSEQ to TS1 -- it's just that the required number of TSEQ ordered sets have been sent.

The TS1 ordered sets are 16 symbols each (four sets shown below). All symbols are fixed except the sixth, which is the Link Functionality field, marked red below. The meaning of this field is given in Table 6-6 of the spec. A Hot Reset is signaled by setting bit 0 of this symbol as '1'. The other bits are used to request loopback, turning the scrambler off etc., and are rarely used outside the testing lab.

The 0x4a symbols identify this ordered set as an TS1 (and not an TS2).

00000000  bc bc bc bc 00 00 4a 4a  4a 4a 4a 4a 4a 4a 4a 4a  |......JJJJJJJJJJ|
00000010  bc bc bc bc 00 00 4a 4a  4a 4a 4a 4a 4a 4a 4a 4a  |......JJJJJJJJJJ|
00000020  bc bc bc bc 00 00 4a 4a  4a 4a 4a 4a 4a 4a 4a 4a  |......JJJJJJJJJJ|
00000030  bc bc bc bc 00 00 4a 4a  4a 4a 4a 4a 4a 4a 4a 4a  |......JJJJJJJJJJ|
[ ... ]

Stage IV: TS2 ordered sets

The TS2 ordered set is sent to acknowledge the reception of eight consecutive and identical TS1 or TS2  ordered sets from the link partner. The repeated 0x45 symbol indicates it's an TS2.

00000000  bc bc bc bc 00 00 45 45  45 45 45 45 45 45 45 45  |......EEEEEEEEEE|
00000010  bc bc bc bc 00 00 45 45  45 45 45 45 45 45 45 45  |......EEEEEEEEEE|
00000020  bc bc bc bc 00 00 45 45  45 45 45 45 45 45 45 45  |......EEEEEEEEEE|
00000030  bc bc bc bc 00 00 45 45  45 45 45 45 45 45 45 45  |......EEEEEEEEEE|
[ ... ]

Stage V: Idle handshake

This is the final stage of the physical link bringup: No more ordered sets, but the data channel itself, with (scrambled) idle symbols (0x00) to begin with.

The condition for jumping to this stage is the reception of eight consecutive and identical TS2 ordered sets, and having transmitted TS2 while those were received, and eight other TS2's after that. In other words, the first TS1 handshake stage is surely behind us, and the TS2 has been up and running enough time for both sides to move on.

The idle stage is shown below starting at offset 0x10, after a single TS2 ordered set. The data bytes immediately after the TS2 ordered set is always as shown: Since the idle (0x00) symbol is transmitted at this stage, the data consists of the scrambler's output, beginning from its 13th octet after a reset. For reference, the scrambler's first outputs after reset are given in the last table of the spec's Appendix B (along with a C program implementing it). It's the same scrambler used for PCIe,  Displayport and several other standards.

The reason the scrambler's 13th octet is the first visible, is that section 6.3.1.3 of the spec requires that the scrambler should advance on each symbol (except for SKP) and reset on each COMMA symbol. Consequently, the scrambler is reset by each of the four COMMA symbols at the beginning of the TS2 ordered set, and then advances on the 12 remaining symbols of it. When switching the ordered set off after the last symbol of TS2, we have the scrambler at the 13th position after reset.

00000000  bc bc bc bc 00 00 45 45  45 45 45 45 45 45 45 45  |......EEEEEEEEEE|
00000010  be 6d bf 8d be 40 a7 e6  2c d3 e2 b2 07 02 77 2a  |.m...@..,.....w*|
00000020  cd 34 be e0 a7 5d 24 b1  9b a1 bd 22 d4 45 1d d3  |.4...]$....".E..|
00000030  d7 ea 76 ee 2c da 1a fa  28 2d 36 3b 3a 0e 6f 67  |..v.,...(-6;:.og|
[ ... ]

An interesting point is that the scrambler is never reset again: There are no COMMA symbols in the following states, unless the link is retrained (e.g. brought into a lower power state and back into Recovery, or just into Recovery because the link didn't function properly). So the last COMMA in the last TS2 is the one that determines the scrambler's state as long as the link remains established.

In the example above, all bytes shown are idle symbols. The spec requires each side to transmit idle symbols (i.e. the scrambler's output) until it has received eight consecutive idle symbols, and then continue to send another eight idle symbols. In effect, this ensures that the receiving and transmitting scramblers are in sync. It will usually take more than 16 symbols, as there are usually some buffers on an MGT link transmission path. The time to complete this stage is 2ms, which is 1 Msymbols. But it usually ends by far quicker.

Link is up (the U0 state)

After typically less than a microsecond, link layer packets will begin to appear. This page discusses the different packets that appear on wire.

Packets start (and sometimes end) with K symbol sequences, consisting of symbols listed in table 6-2 in the spec:

  • SHP = K27.7, coded as 0xfb with K flag set
  • SDP = K28.2, coded as 0x5c with K flag set
  • END = K29.7, coded as 0xfd with K flag set
  • EPF = K23.7, coded as 0xf7 with K flag set
  • SLC = K30.7, coded as 0xfe with K flag set

Spotting these packets is easy. For example, the header packet begins with four K-symbols: SHP, SHP, SHP and EPF (that is, hex codes  fb fb fb f7), and is followed by 16 non-K symbols. When data follows that packet, it follows the header packet immediately, and begins with SDP, SDP, SDP and EPF (5c 5c 5c f7) and ends with END, END, END and EPF (fd fd fd f7).

There are also Link Commands, which appear as SLC, SLC, SLC, EPF (fe fe fe f7) followed by four non-K symbols.

K-symbols are not scrambled, but the non-K (data) symbols are, so while it's easy to find the packets' boundaries, decoding their content requires descrambling. Which is essentially XORing with the scrambler's output.

For example, a header packet:

00000000  fb fb fb f7 14 60 fb 63  a0 8a 0c ff e6 78 b3 bb  |.....`.c.....x..|
00000010  0e 62 08 2e

The content of this packet is can't be obtained in the absence of the scrambler's state.

And this an example of four link commands, followed by several idle symbols (one can tell they're idle because there's no packet header):

00000000  fe fe fe f7 f6 0f 94 75  fe fe fe f7 f8 8e e3 ef  |.......u........|
00000010  fe fe fe f7 c2 34 ec 62  fe fe fe f7 e9 77 c9 d8  |.....4.b.....w..|
00000020  05 e5 dd 68 0d 78 4c 53  8b d6 86 57 b2 aa 1a 80  |...h.xLS...W....|

Once again, the content of these link commands can't be obtained without descrambling.

From TS2 to decoding a packet

Taking a bit broader look, let's go back to the last TS2 ordered set, through the idle handshake, and the first packets transmitted:

00000000  bc bc bc bc 00 00 45 45  45 45 45 45 45 45 45 45  |......EEEEEEEEEE|
00000010  be 6d bf 8d be 40 a7 e6  2c d3 e2 b2 07 02 77 2a  |.m...@..,.....w*|
00000020  cd 34 be e0 a7 5d 24 b1  9b a1 bd 22 d4 45 1d d3  |.4...]$....".E..|
00000030  d7 ea 76 ee 2c da 1a fa  28 2d 36 3b 3a 0e 6f 67  |..v.,...(-6;:.og|
00000040  cf 06 4c 26 d3 e9 3a cd  27 76 30 fc 94 8b 03 de  |..L&..:.'v0.....|
00000050  d3 06 52 f6 4f 88 80 95  c4 6a 66 f2 9f 0c a1 35  |..R.O....jf....5|
00000060  e2 41 cf 27 74 40 7e 9e  a5 58 fe 84 09 60 08 a9  |.A.'t@~..X...`..|
00000070  f1 0b 6f 62 17 43 5c ed  48 39 3f d4 5a f5 0e b3  |..ob.C\.H9?.Z...|
00000080  c7 03 9d 9b 8b 0d 8e 5c  fe fe fe f7 2a c4 0c 56  |.......\....*..V|
00000090  da 0b 42 7a 7c d1 cf a8  1c 12 ee 41 c2 3f 38 7a  |..Bz|......A.?8z|
000000a0  0d 69 f4 01 da 31 72 c5  a0 d7 93 0e dc af a4 55  |.i...1r........U|
000000b0  e7 f0 72 16 68 d5 38 84  dd 00 cd 18 9e ca 30 59  |..r.h.8.......0Y|
000000c0  4c 75 1b 77 31 c5 ed cf  91 64 6e 3d fe e8 29 04  |Lu.w1....dn=..).|
000000d0  cf 6c fc c4 0b 5e da 62  ba 5b ab df 59 b7 7d 37  |.l...^.b.[..Y.}7|
000000e0  5e e3 1a c6 88 14 f5 4f  8b c8 56 cb d3 10 42 63  |^......O..V...Bc|
000000f0  04 8a b4 f7 84 01 a0 01  83 49 67 ee fe fe fe f7  |.........Ig.....|
00000100  f6 0f 94 75 fe fe fe f7  f8 8e e3 ef fe fe fe f7  |...u............|
00000110  c2 34 ec 62 fe fe fe f7  e9 77 c9 d8 05 e5 dd 68  |.4.b.....w.....h|

Packet transmissions are marked in red above. In this example, the first packet appears 120 symbols after the end of the last TS2 ordered set. Note that even though all packets start on a 32-bit work aligned position, this should be considered a coincidence (albeit a frequent one).

Now let's decode the first packet, which is a link command. Its four data bytes, 2a c4 0c 56, begin at position 0x8c of the hex dump above. Recall that the scrambler was reset by the COMMA words of the last TS2 ordered set, so its first word appears at offset 0x4. The relevant scrambler offset is hence 0x8c - 0x04 = 0x88. Looking at the initial scrambler outputs at the USB spec's Appendix B, the scrambler produces 2d ac 0b 3e at this offset.

The packet's content is the XOR of the data bytes above and the scrambler. i.e. { 2a c4 0c 56 } XOR { 2d ac 0b 3e } = { 07 68 07 68 }. Link commands consist of one 16-bit word repeated twice, so it's no surprise that we got this repeated sequence. The 16-bit word, 0x6807, consists of a payload in bits 10:0, and a CRC5 in 15:11. The payload is hence 0x6807 AND 0x7ff = 0x0007. According to Table 7-4 in the USB 3.0 spec, this is an LGOOD_7. This is hence a Header Sequence Number Advertisement (see section 7.2.4.1.1 in the spec).

Lane polarity reversal

The USB 3.x spec requires the receiver to be tolertant to lane polarity reversal, i.e. that the P and N differential wires are swapped. If this happens, all K codes in use are received without change (the 8b/10b code makes them appear to be the same), but D10.2 (0x4a) arrives as D21.5 (0xb5), and D5.2 (0x45) arrives as D26.5 (0xba).

As the TSEQ, TS1 and TS2 ordered sets contain repeated 0x4a / 0x45 symbols, it's easy to spot their polarity reversed counterparts, in particular as the comma (K28.5) arrives intact.

  • 0
    点赞
  • 18
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
DisplayPort Link Training(显示端口链路训练)是为了确保有效的数据传输而发生的一系列通信过程。当连接一个显示器(或其他显示设备)到计算机时,DisplayPort会自动进行链路训练过程来最优化信号传输。下面是DisplayPort Link Training的主要步骤: 1. 插入:将DisplayPort连接器插入计算机的显示输出端口,并将另一端插入显示器的接口。 2. 握手:计算机和显示器之间进行一次初始化的握手,以建立通信。 3. 发现:计算机会读取显示器的EDID(扩展显示标识数据)以了解显示器的类型、分辨率和刷新率等信息。 4. 链路配置:根据显示器的EDID信息,计算机会选择符合最佳配置参数的链路设置。这些参数包括带宽、色彩深度和分辨率等。 5. 频道等化:在链路配置之后,计算机会发送一系列数字模式来调整和优化信号传输。这个过程称为频道等化,目的是减少信号传输中的失真和干扰。 6. 再握手:在频道等化之后,计算机和显示器再次进行握手以确认链路的稳定性,并确保两者的信号传输能力匹配。 7. 数据传输:一旦完成链路配置和频道等化,计算机就可以通过DisplayPort发送图像和音频数据到显示器,从而实现高质量的图像显示。 总的来说,DisplayPort Link Training是一系列用于优化和稳定显示器信号传输的过程,确保计算机和显示器之间的连接能够实现最佳的图像显示效果。这个过程中会根据显示器的特性和要求进行链路配置和频道等化,从而最大程度上提供高质量的图像显示体验。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值