oa-tc6-framework.rst 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497
  1. .. SPDX-License-Identifier: GPL-2.0+
  2. =========================================================================
  3. OPEN Alliance 10BASE-T1x MAC-PHY Serial Interface (TC6) Framework Support
  4. =========================================================================
  5. Introduction
  6. ------------
  7. The IEEE 802.3cg project defines two 10 Mbit/s PHYs operating over a
  8. single pair of conductors. The 10BASE-T1L (Clause 146) is a long reach
  9. PHY supporting full duplex point-to-point operation over 1 km of single
  10. balanced pair of conductors. The 10BASE-T1S (Clause 147) is a short reach
  11. PHY supporting full / half duplex point-to-point operation over 15 m of
  12. single balanced pair of conductors, or half duplex multidrop bus
  13. operation over 25 m of single balanced pair of conductors.
  14. Furthermore, the IEEE 802.3cg project defines the new Physical Layer
  15. Collision Avoidance (PLCA) Reconciliation Sublayer (Clause 148) meant to
  16. provide improved determinism to the CSMA/CD media access method. PLCA
  17. works in conjunction with the 10BASE-T1S PHY operating in multidrop mode.
  18. The aforementioned PHYs are intended to cover the low-speed / low-cost
  19. applications in industrial and automotive environment. The large number
  20. of pins (16) required by the MII interface, which is specified by the
  21. IEEE 802.3 in Clause 22, is one of the major cost factors that need to be
  22. addressed to fulfil this objective.
  23. The MAC-PHY solution integrates an IEEE Clause 4 MAC and a 10BASE-T1x PHY
  24. exposing a low pin count Serial Peripheral Interface (SPI) to the host
  25. microcontroller. This also enables the addition of Ethernet functionality
  26. to existing low-end microcontrollers which do not integrate a MAC
  27. controller.
  28. Overview
  29. --------
  30. The MAC-PHY is specified to carry both data (Ethernet frames) and control
  31. (register access) transactions over a single full-duplex serial peripheral
  32. interface.
  33. Protocol Overview
  34. -----------------
  35. Two types of transactions are defined in the protocol: data transactions
  36. for Ethernet frame transfers and control transactions for register
  37. read/write transfers. A chunk is the basic element of data transactions
  38. and is composed of 4 bytes of overhead plus 64 bytes of payload size for
  39. each chunk. Ethernet frames are transferred over one or more data chunks.
  40. Control transactions consist of one or more register read/write control
  41. commands.
  42. SPI transactions are initiated by the SPI host with the assertion of CSn
  43. low to the MAC-PHY and ends with the deassertion of CSn high. In between
  44. each SPI transaction, the SPI host may need time for additional
  45. processing and to setup the next SPI data or control transaction.
  46. SPI data transactions consist of an equal number of transmit (TX) and
  47. receive (RX) chunks. Chunks in both transmit and receive directions may
  48. or may not contain valid frame data independent from each other, allowing
  49. for the simultaneous transmission and reception of different length
  50. frames.
  51. Each transmit data chunk begins with a 32-bit data header followed by a
  52. data chunk payload on MOSI. The data header indicates whether transmit
  53. frame data is present and provides the information to determine which
  54. bytes of the payload contain valid frame data.
  55. In parallel, receive data chunks are received on MISO. Each receive data
  56. chunk consists of a data chunk payload ending with a 32-bit data footer.
  57. The data footer indicates if there is receive frame data present within
  58. the payload or not and provides the information to determine which bytes
  59. of the payload contain valid frame data.
  60. Reference
  61. ---------
  62. 10BASE-T1x MAC-PHY Serial Interface Specification,
  63. Link: https://opensig.org/download/document/OPEN_Alliance_10BASET1x_MAC-PHY_Serial_Interface_V1.1.pdf
  64. Hardware Architecture
  65. ---------------------
  66. .. code-block:: none
  67. +----------+ +-------------------------------------+
  68. | | | MAC-PHY |
  69. | |<---->| +-----------+ +-------+ +-------+ |
  70. | SPI Host | | | SPI Slave | | MAC | | PHY | |
  71. | | | +-----------+ +-------+ +-------+ |
  72. +----------+ +-------------------------------------+
  73. Software Architecture
  74. ---------------------
  75. .. code-block:: none
  76. +----------------------------------------------------------+
  77. | Networking Subsystem |
  78. +----------------------------------------------------------+
  79. / \ / \
  80. | |
  81. | |
  82. \ / |
  83. +----------------------+ +-----------------------------+
  84. | MAC Driver |<--->| OPEN Alliance TC6 Framework |
  85. +----------------------+ +-----------------------------+
  86. / \ / \
  87. | |
  88. | |
  89. | \ /
  90. +----------------------------------------------------------+
  91. | SPI Subsystem |
  92. +----------------------------------------------------------+
  93. / \
  94. |
  95. |
  96. \ /
  97. +----------------------------------------------------------+
  98. | 10BASE-T1x MAC-PHY Device |
  99. +----------------------------------------------------------+
  100. Implementation
  101. --------------
  102. MAC Driver
  103. ~~~~~~~~~~
  104. - Probed by SPI subsystem.
  105. - Initializes OA TC6 framework for the MAC-PHY.
  106. - Registers and configures the network device.
  107. - Sends the tx ethernet frames from n/w subsystem to OA TC6 framework.
  108. OPEN Alliance TC6 Framework
  109. ~~~~~~~~~~~~~~~~~~~~~~~~~~~
  110. - Initializes PHYLIB interface.
  111. - Registers mac-phy interrupt.
  112. - Performs mac-phy register read/write operation using the control
  113. transaction protocol specified in the OPEN Alliance 10BASE-T1x MAC-PHY
  114. Serial Interface specification.
  115. - Performs Ethernet frames transaction using the data transaction protocol
  116. for Ethernet frames specified in the OPEN Alliance 10BASE-T1x MAC-PHY
  117. Serial Interface specification.
  118. - Forwards the received Ethernet frame from 10Base-T1x MAC-PHY to n/w
  119. subsystem.
  120. Data Transaction
  121. ~~~~~~~~~~~~~~~~
  122. The Ethernet frames that are typically transferred from the SPI host to
  123. the MAC-PHY will be converted into multiple transmit data chunks. Each
  124. transmit data chunk will have a 4 bytes header which contains the
  125. information needed to determine the validity and the location of the
  126. transmit frame data within the 64 bytes data chunk payload.
  127. .. code-block:: none
  128. +---------------------------------------------------+
  129. | Tx Chunk |
  130. | +---------------------------+ +----------------+ | MOSI
  131. | | 64 bytes chunk payload | | 4 bytes header | |------------>
  132. | +---------------------------+ +----------------+ |
  133. +---------------------------------------------------+
  134. 4 bytes header contains the below fields,
  135. DNC (Bit 31) - Data-Not-Control flag. This flag specifies the type of SPI
  136. transaction. For TX data chunks, this bit shall be ’1’.
  137. 0 - Control command
  138. 1 - Data chunk
  139. SEQ (Bit 30) - Data Chunk Sequence. This bit is used to indicate an
  140. even/odd transmit data chunk sequence to the MAC-PHY.
  141. NORX (Bit 29) - No Receive flag. The SPI host may set this bit to prevent
  142. the MAC-PHY from conveying RX data on the MISO for the
  143. current chunk (DV = 0 in the footer), indicating that the
  144. host would not process it. Typically, the SPI host should
  145. set NORX = 0 indicating that it will accept and process
  146. any receive frame data within the current chunk.
  147. RSVD (Bit 28..24) - Reserved: All reserved bits shall be ‘0’.
  148. VS (Bit 23..22) - Vendor Specific. These bits are implementation specific.
  149. If the MAC-PHY does not implement these bits, the host
  150. shall set them to ‘0’.
  151. DV (Bit 21) - Data Valid flag. The SPI host uses this bit to indicate
  152. whether the current chunk contains valid transmit frame data
  153. (DV = 1) or not (DV = 0). When ‘0’, the MAC-PHY ignores the
  154. chunk payload. Note that the receive path is unaffected by
  155. the setting of the DV bit in the data header.
  156. SV (Bit 20) - Start Valid flag. The SPI host shall set this bit when the
  157. beginning of an Ethernet frame is present in the current
  158. transmit data chunk payload. Otherwise, this bit shall be
  159. zero. This bit is not to be confused with the Start-of-Frame
  160. Delimiter (SFD) byte described in IEEE 802.3 [2].
  161. SWO (Bit 19..16) - Start Word Offset. When SV = 1, this field shall
  162. contain the 32-bit word offset into the transmit data
  163. chunk payload that points to the start of a new
  164. Ethernet frame to be transmitted. The host shall write
  165. this field as zero when SV = 0.
  166. RSVD (Bit 15) - Reserved: All reserved bits shall be ‘0’.
  167. EV (Bit 14) - End Valid flag. The SPI host shall set this bit when the end
  168. of an Ethernet frame is present in the current transmit data
  169. chunk payload. Otherwise, this bit shall be zero.
  170. EBO (Bit 13..8) - End Byte Offset. When EV = 1, this field shall contain
  171. the byte offset into the transmit data chunk payload
  172. that points to the last byte of the Ethernet frame to
  173. transmit. This field shall be zero when EV = 0.
  174. TSC (Bit 7..6) - Timestamp Capture. Request a timestamp capture when the
  175. frame is transmitted onto the network.
  176. 00 - Do not capture a timestamp
  177. 01 - Capture timestamp into timestamp capture register A
  178. 10 - Capture timestamp into timestamp capture register B
  179. 11 - Capture timestamp into timestamp capture register C
  180. RSVD (Bit 5..1) - Reserved: All reserved bits shall be ‘0’.
  181. P (Bit 0) - Parity. Parity bit calculated over the transmit data header.
  182. Method used is odd parity.
  183. The number of buffers available in the MAC-PHY to store the incoming
  184. transmit data chunk payloads is represented as transmit credits. The
  185. available transmit credits in the MAC-PHY can be read either from the
  186. Buffer Status Register or footer (Refer below for the footer info)
  187. received from the MAC-PHY. The SPI host should not write more data chunks
  188. than the available transmit credits as this will lead to transmit buffer
  189. overflow error.
  190. In case the previous data footer had no transmit credits available and
  191. once the transmit credits become available for transmitting transmit data
  192. chunks, the MAC-PHY interrupt is asserted to SPI host. On reception of the
  193. first data header this interrupt will be deasserted and the received
  194. footer for the first data chunk will have the transmit credits available
  195. information.
  196. The Ethernet frames that are typically transferred from MAC-PHY to SPI
  197. host will be sent as multiple receive data chunks. Each receive data
  198. chunk will have 64 bytes of data chunk payload followed by 4 bytes footer
  199. which contains the information needed to determine the validity and the
  200. location of the receive frame data within the 64 bytes data chunk payload.
  201. .. code-block:: none
  202. +---------------------------------------------------+
  203. | Rx Chunk |
  204. | +----------------+ +---------------------------+ | MISO
  205. | | 4 bytes footer | | 64 bytes chunk payload | |------------>
  206. | +----------------+ +---------------------------+ |
  207. +---------------------------------------------------+
  208. 4 bytes footer contains the below fields,
  209. EXST (Bit 31) - Extended Status. This bit is set when any bit in the
  210. STATUS0 or STATUS1 registers are set and not masked.
  211. HDRB (Bit 30) - Received Header Bad. When set, indicates that the MAC-PHY
  212. received a control or data header with a parity error.
  213. SYNC (Bit 29) - Configuration Synchronized flag. This bit reflects the
  214. state of the SYNC bit in the CONFIG0 configuration
  215. register (see Table 12). A zero indicates that the MAC-PHY
  216. configuration may not be as expected by the SPI host.
  217. Following configuration, the SPI host sets the
  218. corresponding bitin the configuration register which is
  219. reflected in this field.
  220. RCA (Bit 28..24) - Receive Chunks Available. The RCA field indicates to
  221. the SPI host the minimum number of additional receive
  222. data chunks of frame data that are available for
  223. reading beyond the current receive data chunk. This
  224. field is zero when there is no receive frame data
  225. pending in the MAC-PHY’s buffer for reading.
  226. VS (Bit 23..22) - Vendor Specific. These bits are implementation specific.
  227. If not implemented, the MAC-PHY shall set these bits to
  228. ‘0’.
  229. DV (Bit 21) - Data Valid flag. The MAC-PHY uses this bit to indicate
  230. whether the current receive data chunk contains valid
  231. receive frame data (DV = 1) or not (DV = 0). When ‘0’, the
  232. SPI host shall ignore the chunk payload.
  233. SV (Bit 20) - Start Valid flag. The MAC-PHY sets this bit when the current
  234. chunk payload contains the start of an Ethernet frame.
  235. Otherwise, this bit is zero. The SV bit is not to be
  236. confused with the Start-of-Frame Delimiter (SFD) byte
  237. described in IEEE 802.3 [2].
  238. SWO (Bit 19..16) - Start Word Offset. When SV = 1, this field contains the
  239. 32-bit word offset into the receive data chunk payload
  240. containing the first byte of a new received Ethernet
  241. frame. When a receive timestamp has been added to the
  242. beginning of the received Ethernet frame (RTSA = 1)
  243. then SWO points to the most significant byte of the
  244. timestamp. This field will be zero when SV = 0.
  245. FD (Bit 15) - Frame Drop. When set, this bit indicates that the MAC has
  246. detected a condition for which the SPI host should drop the
  247. received Ethernet frame. This bit is only valid at the end
  248. of a received Ethernet frame (EV = 1) and shall be zero at
  249. all other times.
  250. EV (Bit 14) - End Valid flag. The MAC-PHY sets this bit when the end of a
  251. received Ethernet frame is present in this receive data
  252. chunk payload.
  253. EBO (Bit 13..8) - End Byte Offset: When EV = 1, this field contains the
  254. byte offset into the receive data chunk payload that
  255. locates the last byte of the received Ethernet frame.
  256. This field is zero when EV = 0.
  257. RTSA (Bit 7) - Receive Timestamp Added. This bit is set when a 32-bit or
  258. 64-bit timestamp has been added to the beginning of the
  259. received Ethernet frame. The MAC-PHY shall set this bit to
  260. zero when SV = 0.
  261. RTSP (Bit 6) - Receive Timestamp Parity. Parity bit calculated over the
  262. 32-bit/64-bit timestamp added to the beginning of the
  263. received Ethernet frame. Method used is odd parity. The
  264. MAC-PHY shall set this bit to zero when RTSA = 0.
  265. TXC (Bit 5..1) - Transmit Credits. This field contains the minimum number
  266. of transmit data chunks of frame data that the SPI host
  267. can write in a single transaction without incurring a
  268. transmit buffer overflow error.
  269. P (Bit 0) - Parity. Parity bit calculated over the receive data footer.
  270. Method used is odd parity.
  271. SPI host will initiate the data receive transaction based on the receive
  272. chunks available in the MAC-PHY which is provided in the receive chunk
  273. footer (RCA - Receive Chunks Available). SPI host will create data invalid
  274. transmit data chunks (empty chunks) or data valid transmit data chunks in
  275. case there are valid Ethernet frames to transmit to the MAC-PHY. The
  276. receive chunks available in MAC-PHY can be read either from the Buffer
  277. Status Register or footer.
  278. In case the previous data footer had no receive data chunks available and
  279. once the receive data chunks become available again for reading, the
  280. MAC-PHY interrupt is asserted to SPI host. On reception of the first data
  281. header this interrupt will be deasserted and the received footer for the
  282. first data chunk will have the receive chunks available information.
  283. MAC-PHY Interrupt
  284. ~~~~~~~~~~~~~~~~~
  285. The MAC-PHY interrupt is asserted when the following conditions are met.
  286. Receive chunks available - This interrupt is asserted when the previous
  287. data footer had no receive data chunks available and once the receive
  288. data chunks become available for reading. On reception of the first data
  289. header this interrupt will be deasserted.
  290. Transmit chunk credits available - This interrupt is asserted when the
  291. previous data footer indicated no transmit credits available and once the
  292. transmit credits become available for transmitting transmit data chunks.
  293. On reception of the first data header this interrupt will be deasserted.
  294. Extended status event - This interrupt is asserted when the previous data
  295. footer indicated no extended status and once the extended event become
  296. available. In this case the host should read status #0 register to know
  297. the corresponding error/event. On reception of the first data header this
  298. interrupt will be deasserted.
  299. Control Transaction
  300. ~~~~~~~~~~~~~~~~~~~
  301. 4 bytes control header contains the below fields,
  302. DNC (Bit 31) - Data-Not-Control flag. This flag specifies the type of SPI
  303. transaction. For control commands, this bit shall be ‘0’.
  304. 0 - Control command
  305. 1 - Data chunk
  306. HDRB (Bit 30) - Received Header Bad. When set by the MAC-PHY, indicates
  307. that a header was received with a parity error. The SPI
  308. host should always clear this bit. The MAC-PHY ignores the
  309. HDRB value sent by the SPI host on MOSI.
  310. WNR (Bit 29) - Write-Not-Read. This bit indicates if data is to be written
  311. to registers (when set) or read from registers
  312. (when clear).
  313. AID (Bit 28) - Address Increment Disable. When clear, the address will be
  314. automatically post-incremented by one following each
  315. register read or write. When set, address auto increment is
  316. disabled allowing successive reads and writes to occur at
  317. the same register address.
  318. MMS (Bit 27..24) - Memory Map Selector. This field selects the specific
  319. register memory map to access.
  320. ADDR (Bit 23..8) - Address. Address of the first register within the
  321. selected memory map to access.
  322. LEN (Bit 7..1) - Length. Specifies the number of registers to read/write.
  323. This field is interpreted as the number of registers
  324. minus 1 allowing for up to 128 consecutive registers read
  325. or written starting at the address specified in ADDR. A
  326. length of zero shall read or write a single register.
  327. P (Bit 0) - Parity. Parity bit calculated over the control command header.
  328. Method used is odd parity.
  329. Control transactions consist of one or more control commands. Control
  330. commands are used by the SPI host to read and write registers within the
  331. MAC-PHY. Each control commands are composed of a 4 bytes control command
  332. header followed by register write data in case of control write command.
  333. The MAC-PHY ignores the final 4 bytes of data from the SPI host at the end
  334. of the control write command. The control write command is also echoed
  335. from the MAC-PHY back to the SPI host to identify which register write
  336. failed in case of any bus errors. The echoed Control write command will
  337. have the first 4 bytes unused value to be ignored by the SPI host
  338. followed by 4 bytes echoed control header followed by echoed register
  339. write data. Control write commands can write either a single register or
  340. multiple consecutive registers. When multiple consecutive registers are
  341. written, the address is automatically post-incremented by the MAC-PHY.
  342. Writing to any unimplemented or undefined registers shall be ignored and
  343. yield no effect.
  344. The MAC-PHY ignores all data from the SPI host following the control
  345. header for the remainder of the control read command. The control read
  346. command is also echoed from the MAC-PHY back to the SPI host to identify
  347. which register read is failed in case of any bus errors. The echoed
  348. Control read command will have the first 4 bytes of unused value to be
  349. ignored by the SPI host followed by 4 bytes echoed control header followed
  350. by register read data. Control read commands can read either a single
  351. register or multiple consecutive registers. When multiple consecutive
  352. registers are read, the address is automatically post-incremented by the
  353. MAC-PHY. Reading any unimplemented or undefined registers shall return
  354. zero.
  355. Device drivers API
  356. ==================
  357. The include/linux/oa_tc6.h defines the following functions:
  358. .. c:function:: struct oa_tc6 *oa_tc6_init(struct spi_device *spi, \
  359. struct net_device *netdev)
  360. Initialize OA TC6 lib.
  361. .. c:function:: void oa_tc6_exit(struct oa_tc6 *tc6)
  362. Free allocated OA TC6 lib.
  363. .. c:function:: int oa_tc6_write_register(struct oa_tc6 *tc6, u32 address, \
  364. u32 value)
  365. Write a single register in the MAC-PHY.
  366. .. c:function:: int oa_tc6_write_registers(struct oa_tc6 *tc6, u32 address, \
  367. u32 value[], u8 length)
  368. Writing multiple consecutive registers starting from @address in the MAC-PHY.
  369. Maximum of 128 consecutive registers can be written starting at @address.
  370. .. c:function:: int oa_tc6_read_register(struct oa_tc6 *tc6, u32 address, \
  371. u32 *value)
  372. Read a single register in the MAC-PHY.
  373. .. c:function:: int oa_tc6_read_registers(struct oa_tc6 *tc6, u32 address, \
  374. u32 value[], u8 length)
  375. Reading multiple consecutive registers starting from @address in the MAC-PHY.
  376. Maximum of 128 consecutive registers can be read starting at @address.
  377. .. c:function:: netdev_tx_t oa_tc6_start_xmit(struct oa_tc6 *tc6, \
  378. struct sk_buff *skb);
  379. The transmit Ethernet frame in the skb is or going to be transmitted through
  380. the MAC-PHY.
  381. .. c:function:: int oa_tc6_zero_align_receive_frame_enable(struct oa_tc6 *tc6);
  382. Zero align receive frame feature can be enabled to align all receive ethernet
  383. frames data to start at the beginning of any receive data chunk payload with a
  384. start word offset (SWO) of zero.