1d30ea906Sjfb8856606..  SPDX-License-Identifier: BSD-3-Clause
2d30ea906Sjfb8856606    Copyright 2018 The DPDK contributors
3d30ea906Sjfb8856606
4a9643ea8Slogwang.. _doc_guidelines:
5a9643ea8Slogwang
6a9643ea8SlogwangDPDK Documentation Guidelines
7a9643ea8Slogwang=============================
8a9643ea8Slogwang
9a9643ea8SlogwangThis document outlines the guidelines for writing the DPDK Guides and API documentation in RST and Doxygen format.
10a9643ea8Slogwang
11a9643ea8SlogwangIt also explains the structure of the DPDK documentation and shows how to build the Html and PDF versions of the documents.
12a9643ea8Slogwang
13a9643ea8Slogwang
14a9643ea8SlogwangStructure of the Documentation
15a9643ea8Slogwang------------------------------
16a9643ea8Slogwang
17a9643ea8SlogwangThe DPDK source code repository contains input files to build the API documentation and User Guides.
18a9643ea8Slogwang
19a9643ea8SlogwangThe main directories that contain files related to documentation are shown below::
20a9643ea8Slogwang
21a9643ea8Slogwang   lib
22a9643ea8Slogwang   |-- librte_acl
23a9643ea8Slogwang   |-- librte_cfgfile
24a9643ea8Slogwang   |-- librte_cmdline
25a9643ea8Slogwang   |-- librte_eal
26a9643ea8Slogwang   |   |-- ...
27a9643ea8Slogwang   ...
28a9643ea8Slogwang   doc
29a9643ea8Slogwang   |-- api
30a9643ea8Slogwang   +-- guides
31a9643ea8Slogwang       |-- freebsd_gsg
32a9643ea8Slogwang       |-- linux_gsg
33a9643ea8Slogwang       |-- prog_guide
34a9643ea8Slogwang       |-- sample_app_ug
35a9643ea8Slogwang       |-- guidelines
36a9643ea8Slogwang       |-- testpmd_app_ug
37a9643ea8Slogwang       |-- rel_notes
38a9643ea8Slogwang       |-- nics
39a9643ea8Slogwang       |-- ...
40a9643ea8Slogwang
41a9643ea8Slogwang
421646932aSjfb8856606The API documentation is built from `Doxygen <http://www.doxygen.nl>`_ comments in the header files.
43a9643ea8SlogwangThese files are mainly in the ``lib/librte_*`` directories although some of the Poll Mode Drivers in ``drivers/net``
44a9643ea8Slogwangare also documented with Doxygen.
45a9643ea8Slogwang
46a9643ea8SlogwangThe configuration files that are used to control the Doxygen output are in the ``doc/api`` directory.
47a9643ea8Slogwang
48a9643ea8SlogwangThe user guides such as *The Programmers Guide* and the *FreeBSD* and *Linux Getting Started* Guides are generated
491646932aSjfb8856606from RST markup text files using the `Sphinx <http://sphinx-doc.org>`_ Documentation Generator.
50a9643ea8Slogwang
51a9643ea8SlogwangThese files are included in the ``doc/guides/`` directory.
52a9643ea8SlogwangThe output is controlled by the ``doc/guides/conf.py`` file.
53a9643ea8Slogwang
54a9643ea8Slogwang
55a9643ea8SlogwangRole of the Documentation
56a9643ea8Slogwang-------------------------
57a9643ea8Slogwang
58a9643ea8SlogwangThe following items outline the roles of the different parts of the documentation and when they need to be updated or
59a9643ea8Slogwangadded to by the developer.
60a9643ea8Slogwang
61a9643ea8Slogwang* **Release Notes**
62a9643ea8Slogwang
63a9643ea8Slogwang  The Release Notes document which features have been added in the current and previous releases of DPDK and highlight
64a9643ea8Slogwang  any known issues.
65*2d9fd380Sjfb8856606  The Releases Notes also contain notifications of features that will change ABI compatibility in the next release.
66a9643ea8Slogwang
67a9643ea8Slogwang  Developers should include updates to the Release Notes with patch sets that relate to any of the following sections:
68a9643ea8Slogwang
69a9643ea8Slogwang  * New Features
70a9643ea8Slogwang  * Resolved Issues (see below)
71a9643ea8Slogwang  * Known Issues
72a9643ea8Slogwang  * API Changes
73a9643ea8Slogwang  * ABI Changes
74a9643ea8Slogwang  * Shared Library Versions
75a9643ea8Slogwang
76a9643ea8Slogwang  Resolved Issues should only include issues from previous releases that have been resolved in the current release.
77a9643ea8Slogwang  Issues that are introduced and then fixed within a release cycle do not have to be included here.
78a9643ea8Slogwang
79a9643ea8Slogwang  Refer to the Release Notes from the previous DPDK release for the correct format of each section.
80a9643ea8Slogwang
81a9643ea8Slogwang
82a9643ea8Slogwang* **API documentation**
83a9643ea8Slogwang
84a9643ea8Slogwang  The API documentation explains how to use the public DPDK functions.
850c6bd470Sfengbojiang  The `API index page <https://doc.dpdk.org/api/>`_ shows the generated API documentation with related groups of functions.
86a9643ea8Slogwang
87a9643ea8Slogwang  The API documentation should be updated via Doxygen comments when new functions are added.
88a9643ea8Slogwang
89a9643ea8Slogwang* **Getting Started Guides**
90a9643ea8Slogwang
91a9643ea8Slogwang  The Getting Started Guides show how to install and configure DPDK and how to run DPDK based applications on different OSes.
92a9643ea8Slogwang
93a9643ea8Slogwang  A Getting Started Guide should be added when DPDK is ported to a new OS.
94a9643ea8Slogwang
95a9643ea8Slogwang* **The Programmers Guide**
96a9643ea8Slogwang
97a9643ea8Slogwang  The Programmers Guide explains how the API components of DPDK such as the EAL, Memzone, Rings and the Hash Library work.
98a9643ea8Slogwang  It also explains how some higher level functionality such as Packet Distributor, Packet Framework and KNI work.
99a9643ea8Slogwang  It also shows the build system and explains how to add applications.
100a9643ea8Slogwang
101a9643ea8Slogwang  The Programmers Guide should be expanded when new functionality is added to DPDK.
102a9643ea8Slogwang
103a9643ea8Slogwang* **App Guides**
104a9643ea8Slogwang
105a9643ea8Slogwang  The app guides document the DPDK applications in the ``app`` directory such as ``testpmd``.
106a9643ea8Slogwang
107a9643ea8Slogwang  The app guides should be updated if functionality is changed or added.
108a9643ea8Slogwang
109a9643ea8Slogwang* **Sample App Guides**
110a9643ea8Slogwang
111a9643ea8Slogwang  The sample app guides document the DPDK example applications in the examples directory.
112a9643ea8Slogwang  Generally they demonstrate a major feature such as L2 or L3 Forwarding, Multi Process or Power Management.
113a9643ea8Slogwang  They explain the purpose of the sample application, how to run it and step through some of the code to explain the
114a9643ea8Slogwang  major functionality.
115a9643ea8Slogwang
116a9643ea8Slogwang  A new sample application should be accompanied by a new sample app guide.
117a9643ea8Slogwang  The guide for the Skeleton Forwarding app is a good starting reference.
118a9643ea8Slogwang
119a9643ea8Slogwang* **Network Interface Controller Drivers**
120a9643ea8Slogwang
121a9643ea8Slogwang  The NIC Drivers document explains the features of the individual Poll Mode Drivers, such as software requirements,
122a9643ea8Slogwang  configuration and initialization.
123a9643ea8Slogwang
124a9643ea8Slogwang  New documentation should be added for new Poll Mode Drivers.
125a9643ea8Slogwang
126a9643ea8Slogwang* **Guidelines**
127a9643ea8Slogwang
128a9643ea8Slogwang  The guideline documents record community process, expectations and design directions.
129a9643ea8Slogwang
130a9643ea8Slogwang  They can be extended, amended or discussed by submitting a patch and getting community approval.
131a9643ea8Slogwang
132a9643ea8Slogwang
133a9643ea8SlogwangBuilding the Documentation
134a9643ea8Slogwang--------------------------
135a9643ea8Slogwang
136a9643ea8SlogwangDependencies
137a9643ea8Slogwang~~~~~~~~~~~~
138a9643ea8Slogwang
139a9643ea8Slogwang
140a9643ea8SlogwangThe following dependencies must be installed to build the documentation:
141a9643ea8Slogwang
142a9643ea8Slogwang* Doxygen.
143a9643ea8Slogwang
144a9643ea8Slogwang* Sphinx (also called python-sphinx).
145a9643ea8Slogwang
146a9643ea8Slogwang* TexLive (at least TexLive-core and the extra Latex support).
147a9643ea8Slogwang
148a9643ea8Slogwang* Inkscape.
149a9643ea8Slogwang
150a9643ea8Slogwang`Doxygen`_ generates documentation from commented source code.
151a9643ea8SlogwangIt can be installed as follows:
152a9643ea8Slogwang
153a9643ea8Slogwang.. code-block:: console
154a9643ea8Slogwang
155a9643ea8Slogwang   # Ubuntu/Debian.
156a9643ea8Slogwang   sudo apt-get -y install doxygen
157a9643ea8Slogwang
158a9643ea8Slogwang   # Red Hat/Fedora.
159a9643ea8Slogwang   sudo dnf     -y install doxygen
160a9643ea8Slogwang
161a9643ea8Slogwang`Sphinx`_ is a Python documentation tool for converting RST files to Html or to PDF (via LaTeX).
162a9643ea8SlogwangFor full support with figure and table captioning the latest version of Sphinx can be installed as follows:
163a9643ea8Slogwang
164a9643ea8Slogwang.. code-block:: console
165a9643ea8Slogwang
166a9643ea8Slogwang   # Ubuntu/Debian.
167*2d9fd380Sjfb8856606   sudo apt-get -y install python3-sphinx python3-sphinx-rtd-theme
168a9643ea8Slogwang
169a9643ea8Slogwang   # Red Hat/Fedora.
170*2d9fd380Sjfb8856606   sudo dnf     -y install python3-sphinx python3-sphinx_rtd_theme
171a9643ea8Slogwang
1721646932aSjfb8856606For further information on getting started with Sphinx see the
1731646932aSjfb8856606`Sphinx Getting Started <http://www.sphinx-doc.org/en/master/usage/quickstart.html>`_.
174a9643ea8Slogwang
175a9643ea8Slogwang.. Note::
176a9643ea8Slogwang
177a9643ea8Slogwang   To get full support for Figure and Table numbering it is best to install Sphinx 1.3.1 or later.
178a9643ea8Slogwang
179a9643ea8Slogwang
180a9643ea8Slogwang`Inkscape`_ is a vector based graphics program which is used to create SVG images and also to convert SVG images to PDF images.
181a9643ea8SlogwangIt can be installed as follows:
182a9643ea8Slogwang
183a9643ea8Slogwang.. code-block:: console
184a9643ea8Slogwang
185a9643ea8Slogwang   # Ubuntu/Debian.
186a9643ea8Slogwang   sudo apt-get -y install inkscape
187a9643ea8Slogwang
188a9643ea8Slogwang   # Red Hat/Fedora.
189a9643ea8Slogwang   sudo dnf     -y install inkscape
190a9643ea8Slogwang
191a9643ea8Slogwang`TexLive <http://www.tug.org/texlive/>`_ is an installation package for Tex/LaTeX.
192a9643ea8SlogwangIt is used to generate the PDF versions of the documentation.
193a9643ea8SlogwangThe main required packages can be installed as follows:
194a9643ea8Slogwang
195a9643ea8Slogwang.. code-block:: console
196a9643ea8Slogwang
197a9643ea8Slogwang   # Ubuntu/Debian.
1984b05018fSfengbojiang   sudo apt-get -y install texlive-latex-extra texlive-lang-greek
199a9643ea8Slogwang
200a9643ea8Slogwang   # Red Hat/Fedora, selective install.
2014b05018fSfengbojiang   sudo dnf     -y install texlive-collection-latexextra texlive-greek-fontenc
202a9643ea8Slogwang
2031646932aSjfb8856606`Latexmk <http://personal.psu.edu/jcc8/software/latexmk-jcc/>`_ is a perl script
2041646932aSjfb8856606for running LaTeX for resolving cross references,
2051646932aSjfb8856606and it also runs auxiliary programs like bibtex, makeindex if necessary, and dvips.
2061646932aSjfb8856606It has also a number of other useful capabilities (see man 1 latexmk).
2071646932aSjfb8856606
2081646932aSjfb8856606.. code-block:: console
2091646932aSjfb8856606
2101646932aSjfb8856606   # Ubuntu/Debian.
2111646932aSjfb8856606   sudo apt-get -y install latexmk
2121646932aSjfb8856606
2131646932aSjfb8856606   # Red Hat/Fedora.
2141646932aSjfb8856606   sudo dnf     -y install latexmk
2151646932aSjfb8856606
216a9643ea8Slogwang
217a9643ea8SlogwangBuild commands
218a9643ea8Slogwang~~~~~~~~~~~~~~
219a9643ea8Slogwang
220a9643ea8SlogwangThe documentation is built using the standard DPDK build system.
221a9643ea8Slogwang
222*2d9fd380Sjfb8856606To build the documentation::
223a9643ea8Slogwang
224*2d9fd380Sjfb8856606   ninja -C build doc
225a9643ea8Slogwang
226*2d9fd380Sjfb8856606See :doc:`../linux_gsg/build_dpdk` for more detail on compiling DPDK with meson.
227a9643ea8Slogwang
228*2d9fd380Sjfb8856606The output is generated in the ``build`` directory::
229a9643ea8Slogwang
230a9643ea8Slogwang   build/doc
231a9643ea8Slogwang         |-- html
232a9643ea8Slogwang         |   |-- api
233a9643ea8Slogwang         |   +-- guides
234a9643ea8Slogwang         |
235a9643ea8Slogwang         +-- pdf
236a9643ea8Slogwang             +-- guides
237a9643ea8Slogwang
238a9643ea8Slogwang
239a9643ea8Slogwang.. Note::
240a9643ea8Slogwang
241a9643ea8Slogwang   Make sure to fix any Sphinx or Doxygen warnings when adding or updating documentation.
242a9643ea8Slogwang
243a9643ea8Slogwang
244a9643ea8SlogwangDocument Guidelines
245a9643ea8Slogwang-------------------
246a9643ea8Slogwang
247a9643ea8SlogwangHere are some guidelines in relation to the style of the documentation:
248a9643ea8Slogwang
249a9643ea8Slogwang* Document the obvious as well as the obscure since it won't always be obvious to the reader.
250a9643ea8Slogwang  For example an instruction like "Set up 64 2MB Hugepages" is better when followed by a sample commandline or a link to
251a9643ea8Slogwang  the appropriate section of the documentation.
252a9643ea8Slogwang
253a9643ea8Slogwang* Use American English spellings throughout.
254a9643ea8Slogwang  This can be checked using the ``aspell`` utility::
255a9643ea8Slogwang
256a9643ea8Slogwang       aspell --lang=en_US --check doc/guides/sample_app_ug/mydoc.rst
257a9643ea8Slogwang
258a9643ea8Slogwang
259a9643ea8SlogwangRST Guidelines
260a9643ea8Slogwang--------------
261a9643ea8Slogwang
262a9643ea8SlogwangThe RST (reStructuredText) format is a plain text markup format that can be converted to Html, PDF or other formats.
263a9643ea8SlogwangIt is most closely associated with Python but it can be used to document any language.
264a9643ea8SlogwangIt is used in DPDK to document everything apart from the API.
265a9643ea8Slogwang
266a9643ea8SlogwangThe Sphinx documentation contains a very useful `RST Primer <http://sphinx-doc.org/rest.html#rst-primer>`_ which is a
267a9643ea8Slogwanggood place to learn the minimal set of syntax required to format a document.
268a9643ea8Slogwang
269a9643ea8SlogwangThe official `reStructuredText <http://docutils.sourceforge.net/rst.html>`_ website contains the specification for the
270a9643ea8SlogwangRST format and also examples of how to use it.
271a9643ea8SlogwangHowever, for most developers the RST Primer is a better resource.
272a9643ea8Slogwang
273a9643ea8SlogwangThe most common guidelines for writing RST text are detailed in the
274a9643ea8Slogwang`Documenting Python <https://docs.python.org/devguide/documenting.html>`_ guidelines.
275a9643ea8SlogwangThe additional guidelines below reiterate or expand upon those guidelines.
276a9643ea8Slogwang
277a9643ea8Slogwang
278a9643ea8SlogwangLine Length
279a9643ea8Slogwang~~~~~~~~~~~
280a9643ea8Slogwang
2812bfe3f2eSlogwang* Lines in sentences should be less than 80 characters and wrapped at
2822bfe3f2eSlogwang  words. Multiple sentences which are not separated by a blank line are joined
2832bfe3f2eSlogwang  automatically into paragraphs.
284a9643ea8Slogwang
2852bfe3f2eSlogwang* Lines in literal blocks **must** be less than 80 characters since
2862bfe3f2eSlogwang  they are not wrapped by the document formatters and can exceed the page width
2872bfe3f2eSlogwang  in PDF documents.
288a9643ea8Slogwang
2892bfe3f2eSlogwang  Long literal command lines can be shown wrapped with backslashes. For
2902bfe3f2eSlogwang  example::
291a9643ea8Slogwang
292*2d9fd380Sjfb8856606     dpdk-testpmd -l 2-3 -n 4 \
2932bfe3f2eSlogwang             --vdev=virtio_user0,path=/dev/vhost-net,queues=2,queue_size=1024 \
294d30ea906Sjfb8856606             -- -i --tx-offloads=0x0000002c --enable-lro --txq=2 --rxq=2 \
295d30ea906Sjfb8856606             --txd=1024 --rxd=1024
296a9643ea8Slogwang
297a9643ea8Slogwang
298a9643ea8SlogwangWhitespace
299a9643ea8Slogwang~~~~~~~~~~
300a9643ea8Slogwang
301a9643ea8Slogwang* Standard RST indentation is 3 spaces.
302a9643ea8Slogwang  Code can be indented 4 spaces, especially if it is copied from source files.
303a9643ea8Slogwang
304a9643ea8Slogwang* No tabs.
305a9643ea8Slogwang  Convert tabs in embedded code to 4 or 8 spaces.
306a9643ea8Slogwang
307a9643ea8Slogwang* No trailing whitespace.
308a9643ea8Slogwang
309a9643ea8Slogwang* Add 2 blank lines before each section header.
310a9643ea8Slogwang
311a9643ea8Slogwang* Add 1 blank line after each section header.
312a9643ea8Slogwang
313a9643ea8Slogwang* Add 1 blank line between each line of a list.
314a9643ea8Slogwang
315a9643ea8Slogwang
316a9643ea8SlogwangSection Headers
317a9643ea8Slogwang~~~~~~~~~~~~~~~
318a9643ea8Slogwang
3192bfe3f2eSlogwang* Section headers should use the following underline formats::
320a9643ea8Slogwang
321a9643ea8Slogwang   Level 1 Heading
322a9643ea8Slogwang   ===============
323a9643ea8Slogwang
324a9643ea8Slogwang
325a9643ea8Slogwang   Level 2 Heading
326a9643ea8Slogwang   ---------------
327a9643ea8Slogwang
328a9643ea8Slogwang
329a9643ea8Slogwang   Level 3 Heading
330a9643ea8Slogwang   ~~~~~~~~~~~~~~~
331a9643ea8Slogwang
332a9643ea8Slogwang
333a9643ea8Slogwang   Level 4 Heading
334a9643ea8Slogwang   ^^^^^^^^^^^^^^^
335a9643ea8Slogwang
336a9643ea8Slogwang
337a9643ea8Slogwang* Level 4 headings should be used sparingly.
338a9643ea8Slogwang
339a9643ea8Slogwang* The underlines should match the length of the text.
340a9643ea8Slogwang
341a9643ea8Slogwang* In general, the heading should be less than 80 characters, for conciseness.
342a9643ea8Slogwang
343a9643ea8Slogwang* As noted above:
344a9643ea8Slogwang
345a9643ea8Slogwang   * Add 2 blank lines before each section header.
346a9643ea8Slogwang
347a9643ea8Slogwang   * Add 1 blank line after each section header.
348a9643ea8Slogwang
349a9643ea8Slogwang
350a9643ea8SlogwangLists
351a9643ea8Slogwang~~~~~
352a9643ea8Slogwang
353a9643ea8Slogwang* Bullet lists should be formatted with a leading ``*`` as follows::
354a9643ea8Slogwang
355a9643ea8Slogwang     * Item one.
356a9643ea8Slogwang
357a9643ea8Slogwang     * Item two is a long line that is wrapped and then indented to match
358a9643ea8Slogwang       the start of the previous line.
359a9643ea8Slogwang
360a9643ea8Slogwang     * One space character between the bullet and the text is preferred.
361a9643ea8Slogwang
362a9643ea8Slogwang* Numbered lists can be formatted with a leading number but the preference is to use ``#.`` which will give automatic numbering.
363a9643ea8Slogwang  This is more convenient when adding or removing items::
364a9643ea8Slogwang
365a9643ea8Slogwang     #. Item one.
366a9643ea8Slogwang
367a9643ea8Slogwang     #. Item two is a long line that is wrapped and then indented to match
368a9643ea8Slogwang        the start of the previous line.
369a9643ea8Slogwang
3702bfe3f2eSlogwang     #. Item three.
3712bfe3f2eSlogwang
372a9643ea8Slogwang* Definition lists can be written with or without a bullet::
373a9643ea8Slogwang
374a9643ea8Slogwang     * Item one.
375a9643ea8Slogwang
376a9643ea8Slogwang       Some text about item one.
377a9643ea8Slogwang
378a9643ea8Slogwang     * Item two.
379a9643ea8Slogwang
380a9643ea8Slogwang       Some text about item two.
381a9643ea8Slogwang
382a9643ea8Slogwang* All lists, and sub-lists, must be separated from the preceding text by a blank line.
383a9643ea8Slogwang  This is a syntax requirement.
384a9643ea8Slogwang
385a9643ea8Slogwang* All list items should be separated by a blank line for readability.
386a9643ea8Slogwang
387a9643ea8Slogwang
388a9643ea8SlogwangCode and Literal block sections
389a9643ea8Slogwang~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
390a9643ea8Slogwang
391a9643ea8Slogwang* Inline text that is required to be rendered with a fixed width font should be enclosed in backquotes like this:
392a9643ea8Slogwang  \`\`text\`\`, so that it appears like this: ``text``.
393a9643ea8Slogwang
394a9643ea8Slogwang* Fixed width, literal blocks of texts should be indented at least 3 spaces and prefixed with ``::`` like this::
395a9643ea8Slogwang
396a9643ea8Slogwang     Here is some fixed width text::
397a9643ea8Slogwang
398a9643ea8Slogwang        0x0001 0x0001 0x00FF 0x00FF
399a9643ea8Slogwang
400a9643ea8Slogwang* It is also possible to specify an encoding for a literal block using the ``.. code-block::`` directive so that syntax
401a9643ea8Slogwang  highlighting can be applied.
402a9643ea8Slogwang  Examples of supported highlighting are::
403a9643ea8Slogwang
404a9643ea8Slogwang     .. code-block:: console
405a9643ea8Slogwang     .. code-block:: c
406a9643ea8Slogwang     .. code-block:: python
407a9643ea8Slogwang     .. code-block:: diff
408a9643ea8Slogwang     .. code-block:: none
409a9643ea8Slogwang
410a9643ea8Slogwang  That can be applied as follows::
411a9643ea8Slogwang
412a9643ea8Slogwang      .. code-block:: c
413a9643ea8Slogwang
414a9643ea8Slogwang         #include<stdio.h>
415a9643ea8Slogwang
416a9643ea8Slogwang         int main() {
417a9643ea8Slogwang
418a9643ea8Slogwang            printf("Hello World\n");
419a9643ea8Slogwang
420a9643ea8Slogwang            return 0;
421a9643ea8Slogwang         }
422a9643ea8Slogwang
423a9643ea8Slogwang  Which would be rendered as:
424a9643ea8Slogwang
425a9643ea8Slogwang  .. code-block:: c
426a9643ea8Slogwang
427a9643ea8Slogwang      #include<stdio.h>
428a9643ea8Slogwang
429a9643ea8Slogwang      int main() {
430a9643ea8Slogwang
431a9643ea8Slogwang         printf("Hello World\n");
432a9643ea8Slogwang
433a9643ea8Slogwang         return 0;
434a9643ea8Slogwang      }
435a9643ea8Slogwang
436a9643ea8Slogwang
437a9643ea8Slogwang* The default encoding for a literal block using the simplified ``::``
438a9643ea8Slogwang  directive is ``none``.
439a9643ea8Slogwang
440a9643ea8Slogwang* Lines in literal blocks must be less than 80 characters since they can exceed the page width when converted to PDF documentation.
441a9643ea8Slogwang  For long literal lines that exceed that limit try to wrap the text at sensible locations.
442a9643ea8Slogwang  For example a long command line could be documented like this and still work if copied directly from the docs::
443a9643ea8Slogwang
444*2d9fd380Sjfb8856606     ./<build_dir>/app/dpdk-testpmd -l 0-2 -n3 --vdev=net_pcap0,iface=eth0    \
4452bfe3f2eSlogwang                               --vdev=net_pcap1,iface=eth1     \
446a9643ea8Slogwang                               -- -i --nb-cores=2 --nb-ports=2 \
447a9643ea8Slogwang                                  --total-num-mbufs=2048
448a9643ea8Slogwang
449a9643ea8Slogwang* Long lines that cannot be wrapped, such as application output, should be truncated to be less than 80 characters.
450a9643ea8Slogwang
451a9643ea8Slogwang
452a9643ea8SlogwangImages
453a9643ea8Slogwang~~~~~~
454a9643ea8Slogwang
455a9643ea8Slogwang* All images should be in SVG scalar graphics format.
456a9643ea8Slogwang  They should be true SVG XML files and should not include binary formats embedded in a SVG wrapper.
457a9643ea8Slogwang
458a9643ea8Slogwang* The DPDK documentation contains some legacy images in PNG format.
459a9643ea8Slogwang  These will be converted to SVG in time.
460a9643ea8Slogwang
461a9643ea8Slogwang* `Inkscape <http://inkscape.org>`_ is the recommended graphics editor for creating the images.
462a9643ea8Slogwang  Use some of the older images in ``doc/guides/prog_guide/img/`` as a template, for example ``mbuf1.svg``
4632bfe3f2eSlogwang  or ``ring-enqueue1.svg``.
464a9643ea8Slogwang
465a9643ea8Slogwang* The SVG images should include a copyright notice, as an XML comment.
466a9643ea8Slogwang
467a9643ea8Slogwang* Images in the documentation should be formatted as follows:
468a9643ea8Slogwang
469a9643ea8Slogwang   * The image should be preceded by a label in the format ``.. _figure_XXXX:`` with a leading underscore and
470a9643ea8Slogwang     where ``XXXX`` is a unique descriptive name.
471a9643ea8Slogwang
472a9643ea8Slogwang   * Images should be included using the ``.. figure::`` directive and the file type should be set to ``*`` (not ``.svg``).
473a9643ea8Slogwang     This allows the format of the image to be changed if required, without updating the documentation.
474a9643ea8Slogwang
475a9643ea8Slogwang   * Images must have a caption as part of the ``.. figure::`` directive.
476a9643ea8Slogwang
477a9643ea8Slogwang* Here is an example of the previous three guidelines::
478a9643ea8Slogwang
479a9643ea8Slogwang     .. _figure_mempool:
480a9643ea8Slogwang
481a9643ea8Slogwang     .. figure:: img/mempool.*
482a9643ea8Slogwang
483a9643ea8Slogwang        A mempool in memory with its associated ring.
484a9643ea8Slogwang
485a9643ea8Slogwang.. _mock_label:
486a9643ea8Slogwang
487a9643ea8Slogwang* Images can then be linked to using the ``:numref:`` directive::
488a9643ea8Slogwang
489a9643ea8Slogwang     The mempool layout is shown in :numref:`figure_mempool`.
490a9643ea8Slogwang
491a9643ea8Slogwang  This would be rendered as: *The mempool layout is shown in* :ref:`Fig 6.3 <mock_label>`.
492a9643ea8Slogwang
493a9643ea8Slogwang  **Note**: The ``:numref:`` directive requires Sphinx 1.3.1 or later.
494a9643ea8Slogwang  With earlier versions it will still be rendered as a link but won't have an automatically generated number.
495a9643ea8Slogwang
496a9643ea8Slogwang* The caption of the image can be generated, with a link, using the ``:ref:`` directive::
497a9643ea8Slogwang
498a9643ea8Slogwang     :ref:`figure_mempool`
499a9643ea8Slogwang
500a9643ea8Slogwang  This would be rendered as: *A mempool in memory with its associated ring.*
501a9643ea8Slogwang
502a9643ea8SlogwangTables
503a9643ea8Slogwang~~~~~~
504a9643ea8Slogwang
505a9643ea8Slogwang* RST tables should be used sparingly.
506a9643ea8Slogwang  They are hard to format and to edit, they are often rendered incorrectly in PDF format, and the same information
507a9643ea8Slogwang  can usually be shown just as clearly with a definition or bullet list.
508a9643ea8Slogwang
509a9643ea8Slogwang* Tables in the documentation should be formatted as follows:
510a9643ea8Slogwang
511a9643ea8Slogwang   * The table should be preceded by a label in the format ``.. _table_XXXX:`` with a leading underscore and where
512a9643ea8Slogwang     ``XXXX`` is a unique descriptive name.
513a9643ea8Slogwang
514a9643ea8Slogwang   * Tables should be included using the ``.. table::`` directive and must have a caption.
515a9643ea8Slogwang
516a9643ea8Slogwang* Here is an example of the previous two guidelines::
517a9643ea8Slogwang
518a9643ea8Slogwang     .. _table_qos_pipes:
519a9643ea8Slogwang
520a9643ea8Slogwang     .. table:: Sample configuration for QOS pipes.
521a9643ea8Slogwang
522a9643ea8Slogwang        +----------+----------+----------+
523a9643ea8Slogwang        | Header 1 | Header 2 | Header 3 |
524a9643ea8Slogwang        |          |          |          |
525a9643ea8Slogwang        +==========+==========+==========+
526a9643ea8Slogwang        | Text     | Text     | Text     |
527a9643ea8Slogwang        +----------+----------+----------+
528a9643ea8Slogwang        | ...      | ...      | ...      |
529a9643ea8Slogwang        +----------+----------+----------+
530a9643ea8Slogwang
531a9643ea8Slogwang* Tables can be linked to using the ``:numref:`` and ``:ref:`` directives, as shown in the previous section for images.
532a9643ea8Slogwang  For example::
533a9643ea8Slogwang
534a9643ea8Slogwang     The QOS configuration is shown in :numref:`table_qos_pipes`.
535a9643ea8Slogwang
536a9643ea8Slogwang* Tables should not include merged cells since they are not supported by the PDF renderer.
537a9643ea8Slogwang
538a9643ea8Slogwang
539a9643ea8Slogwang.. _links:
540a9643ea8Slogwang
541a9643ea8SlogwangHyperlinks
542a9643ea8Slogwang~~~~~~~~~~
543a9643ea8Slogwang
544a9643ea8Slogwang* Links to external websites can be plain URLs.
5450c6bd470Sfengbojiang  The following is rendered as https://dpdk.org::
546a9643ea8Slogwang
5470c6bd470Sfengbojiang     https://dpdk.org
548a9643ea8Slogwang
549a9643ea8Slogwang* They can contain alternative text.
5500c6bd470Sfengbojiang  The following is rendered as `Check out DPDK <https://dpdk.org>`_::
551a9643ea8Slogwang
5520c6bd470Sfengbojiang     `Check out DPDK <https://dpdk.org>`_
553a9643ea8Slogwang
554a9643ea8Slogwang* An internal link can be generated by placing labels in the document with the format ``.. _label_name``.
555a9643ea8Slogwang
556a9643ea8Slogwang* The following links to the top of this section: :ref:`links`::
557a9643ea8Slogwang
558a9643ea8Slogwang     .. _links:
559a9643ea8Slogwang
560a9643ea8Slogwang     Hyperlinks
561a9643ea8Slogwang     ~~~~~~~~~~
562a9643ea8Slogwang
563a9643ea8Slogwang     * The following links to the top of this section: :ref:`links`:
564a9643ea8Slogwang
565a9643ea8Slogwang.. Note::
566a9643ea8Slogwang
567a9643ea8Slogwang   The label must have a leading underscore but the reference to it must omit it.
568a9643ea8Slogwang   This is a frequent cause of errors and warnings.
569a9643ea8Slogwang
570a9643ea8Slogwang* The use of a label is preferred since it works across files and will still work if the header text changes.
571a9643ea8Slogwang
572a9643ea8Slogwang
573a9643ea8Slogwang.. _doxygen_guidelines:
574a9643ea8Slogwang
575a9643ea8SlogwangDoxygen Guidelines
576a9643ea8Slogwang------------------
577a9643ea8Slogwang
578a9643ea8SlogwangThe DPDK API is documented using Doxygen comment annotations in the header files.
579a9643ea8SlogwangDoxygen is a very powerful tool, it is extremely configurable and with a little effort can be used to create expressive documents.
5801646932aSjfb8856606See the `Doxygen website <http://www.doxygen.nl>`_ for full details on how to use it.
581a9643ea8Slogwang
582a9643ea8SlogwangThe following are some guidelines for use of Doxygen in the DPDK API documentation:
583a9643ea8Slogwang
584a9643ea8Slogwang* New libraries that are documented with Doxygen should be added to the Doxygen configuration file: ``doc/api/doxy-api.conf``.
585a9643ea8Slogwang  It is only required to add the directory that contains the files.
586a9643ea8Slogwang  It isn't necessary to explicitly name each file since the configuration matches all ``rte_*.h`` files in the directory.
587a9643ea8Slogwang
588a9643ea8Slogwang* Use proper capitalization and punctuation in the Doxygen comments since they will become sentences in the documentation.
589a9643ea8Slogwang  This in particular applies to single line comments, which is the case the is most often forgotten.
590a9643ea8Slogwang
591a9643ea8Slogwang* Use ``@`` style Doxygen commands instead of ``\`` style commands.
592a9643ea8Slogwang
593a9643ea8Slogwang* Add a general description of each library at the head of the main header files:
594a9643ea8Slogwang
595a9643ea8Slogwang  .. code-block:: c
596a9643ea8Slogwang
597a9643ea8Slogwang      /**
598a9643ea8Slogwang       * @file
599a9643ea8Slogwang       * RTE Mempool.
600a9643ea8Slogwang       *
601a9643ea8Slogwang       * A memory pool is an allocator of fixed-size object. It is
602a9643ea8Slogwang       * identified by its name, and uses a ring to store free objects.
603a9643ea8Slogwang       * ...
604a9643ea8Slogwang       */
605a9643ea8Slogwang
606a9643ea8Slogwang* Document the purpose of a function, the parameters used and the return
607a9643ea8Slogwang  value:
608a9643ea8Slogwang
609a9643ea8Slogwang  .. code-block:: c
610a9643ea8Slogwang
611a9643ea8Slogwang     /**
612d30ea906Sjfb8856606      * Try to take the lock.
613a9643ea8Slogwang      *
614d30ea906Sjfb8856606      * @param sl
615d30ea906Sjfb8856606      *   A pointer to the spinlock.
616a9643ea8Slogwang      * @return
617d30ea906Sjfb8856606      *   1 if the lock is successfully taken; 0 otherwise.
618a9643ea8Slogwang      */
619d30ea906Sjfb8856606     int rte_spinlock_trylock(rte_spinlock_t *sl);
620a9643ea8Slogwang
621a9643ea8Slogwang* Doxygen supports Markdown style syntax such as bold, italics, fixed width text and lists.
622a9643ea8Slogwang  For example the second line in the ``devargs`` parameter in the previous example will be rendered as:
623a9643ea8Slogwang
6242bfe3f2eSlogwang     The strings should be a pci address like ``0000:01:00.0`` or **virtual** device name like ``net_pcap0``.
625a9643ea8Slogwang
626a9643ea8Slogwang* Use ``-`` instead of ``*`` for lists within the Doxygen comment since the latter can get confused with the comment delimiter.
627a9643ea8Slogwang
628a9643ea8Slogwang* Add an empty line between the function description, the ``@params`` and ``@return`` for readability.
629a9643ea8Slogwang
630a9643ea8Slogwang* Place the ``@params`` description on separate line and indent it by 2 spaces.
631a9643ea8Slogwang  (It would be better to use no indentation since this is more common and also because checkpatch complains about leading
632a9643ea8Slogwang  whitespace in comments.
633a9643ea8Slogwang  However this is the convention used in the existing DPDK code.)
634a9643ea8Slogwang
635a9643ea8Slogwang* Documented functions can be linked to simply by adding ``()`` to the function name:
636a9643ea8Slogwang
637a9643ea8Slogwang  .. code-block:: c
638a9643ea8Slogwang
639a9643ea8Slogwang      /**
640a9643ea8Slogwang       * The functions exported by the application Ethernet API to setup
641a9643ea8Slogwang       * a device designated by its port identifier must be invoked in
642a9643ea8Slogwang       * the following order:
643a9643ea8Slogwang       *     - rte_eth_dev_configure()
644a9643ea8Slogwang       *     - rte_eth_tx_queue_setup()
645a9643ea8Slogwang       *     - rte_eth_rx_queue_setup()
646a9643ea8Slogwang       *     - rte_eth_dev_start()
647a9643ea8Slogwang       */
648a9643ea8Slogwang
649a9643ea8Slogwang  In the API documentation the functions will be rendered as links, see the
6500c6bd470Sfengbojiang  `online section of the rte_ethdev.h docs <https://doc.dpdk.org/api/rte__ethdev_8h.html>`_ that contains the above text.
651a9643ea8Slogwang
652a9643ea8Slogwang* The ``@see`` keyword can be used to create a *see also* link to another file or library.
653a9643ea8Slogwang  This directive should be placed on one line at the bottom of the documentation section.
654a9643ea8Slogwang
655a9643ea8Slogwang  .. code-block:: c
656a9643ea8Slogwang
657a9643ea8Slogwang     /**
658a9643ea8Slogwang      * ...
659a9643ea8Slogwang      *
660a9643ea8Slogwang      * Some text that references mempools.
661a9643ea8Slogwang      *
662a9643ea8Slogwang      * @see eal_memzone.c
663a9643ea8Slogwang      */
664a9643ea8Slogwang
665a9643ea8Slogwang* Doxygen supports two types of comments for documenting variables, constants and members: prefix and postfix:
666a9643ea8Slogwang
667a9643ea8Slogwang  .. code-block:: c
668a9643ea8Slogwang
669a9643ea8Slogwang     /** This is a prefix comment. */
670a9643ea8Slogwang     #define RTE_FOO_ERROR  0x023.
671a9643ea8Slogwang
672a9643ea8Slogwang     #define RTE_BAR_ERROR  0x024. /**< This is a postfix comment. */
673a9643ea8Slogwang
674a9643ea8Slogwang* Postfix comments are preferred for struct members and constants if they can be documented in the same way:
675a9643ea8Slogwang
676a9643ea8Slogwang  .. code-block:: c
677a9643ea8Slogwang
678a9643ea8Slogwang     struct rte_eth_stats {
679a9643ea8Slogwang         uint64_t ipackets; /**< Total number of received packets. */
680a9643ea8Slogwang         uint64_t opackets; /**< Total number of transmitted packets.*/
681a9643ea8Slogwang         uint64_t ibytes;   /**< Total number of received bytes. */
682a9643ea8Slogwang         uint64_t obytes;   /**< Total number of transmitted bytes. */
683a9643ea8Slogwang         uint64_t imissed;  /**< Total of RX missed packets. */
684a9643ea8Slogwang         uint64_t ibadcrc;  /**< Total of RX packets with CRC error. */
685a9643ea8Slogwang         uint64_t ibadlen;  /**< Total of RX packets with bad length. */
686a9643ea8Slogwang     }
687a9643ea8Slogwang
688a9643ea8Slogwang  Note: postfix comments should be aligned with spaces not tabs in accordance
689a9643ea8Slogwang  with the :ref:`coding_style`.
690a9643ea8Slogwang
691a9643ea8Slogwang* If a single comment type can't be used, due to line length limitations then
692a9643ea8Slogwang  prefix comments should be preferred.
693a9643ea8Slogwang  For example this section of the code contains prefix comments, postfix comments on the same line and postfix
694a9643ea8Slogwang  comments on a separate line:
695a9643ea8Slogwang
696a9643ea8Slogwang  .. code-block:: c
697a9643ea8Slogwang
698a9643ea8Slogwang     /** Number of elements in the elt_pa array. */
699a9643ea8Slogwang     uint32_t    pg_num __rte_cache_aligned;
700a9643ea8Slogwang     uint32_t    pg_shift;     /**< LOG2 of the physical pages. */
701a9643ea8Slogwang     uintptr_t   pg_mask;      /**< Physical page mask value. */
702a9643ea8Slogwang     uintptr_t   elt_va_start;
703a9643ea8Slogwang     /**< Virtual address of the first mempool object. */
704a9643ea8Slogwang     uintptr_t   elt_va_end;
705a9643ea8Slogwang     /**< Virtual address of the <size + 1> mempool object. */
706a9643ea8Slogwang     phys_addr_t elt_pa[MEMPOOL_PG_NUM_DEFAULT];
707a9643ea8Slogwang     /**< Array of physical page addresses for the mempool buffer. */
708a9643ea8Slogwang
709a9643ea8Slogwang  This doesn't have an effect on the rendered documentation but it is confusing for the developer reading the code.
710a9643ea8Slogwang  It this case it would be clearer to use prefix comments throughout:
711a9643ea8Slogwang
712a9643ea8Slogwang  .. code-block:: c
713a9643ea8Slogwang
714a9643ea8Slogwang     /** Number of elements in the elt_pa array. */
715a9643ea8Slogwang     uint32_t    pg_num __rte_cache_aligned;
716a9643ea8Slogwang     /** LOG2 of the physical pages. */
717a9643ea8Slogwang     uint32_t    pg_shift;
718a9643ea8Slogwang     /** Physical page mask value. */
719a9643ea8Slogwang     uintptr_t   pg_mask;
720a9643ea8Slogwang     /** Virtual address of the first mempool object. */
721a9643ea8Slogwang     uintptr_t   elt_va_start;
722a9643ea8Slogwang     /** Virtual address of the <size + 1> mempool object. */
723a9643ea8Slogwang     uintptr_t   elt_va_end;
724a9643ea8Slogwang     /** Array of physical page addresses for the mempool buffer. */
725a9643ea8Slogwang     phys_addr_t elt_pa[MEMPOOL_PG_NUM_DEFAULT];
726a9643ea8Slogwang
727a9643ea8Slogwang* Read the rendered section of the documentation that you have added for correctness, clarity and consistency
728a9643ea8Slogwang  with the surrounding text.
729