1 /*
2  * SPDX-FileCopyrightText: Copyright (c) 2016-2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
3  * SPDX-License-Identifier: MIT
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining a
6  * copy of this software and associated documentation files (the "Software"),
7  * to deal in the Software without restriction, including without limitation
8  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9  * and/or sell copies of the Software, and to permit persons to whom the
10  * Software is furnished to do so, subject to the following conditions:
11  *
12  * The above copyright notice and this permission notice shall be included in
13  * all copies or substantial portions of the Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21  * DEALINGS IN THE SOFTWARE.
22  */
23 
24 #ifndef _NVLINK_LIB_CTRL_H_
25 #define _NVLINK_LIB_CTRL_H_
26 
27 
28 #include "nvtypes.h"
29 #include "nvlink_errors.h"
30 
31 /* List of supported capability type */
32 #define NVLINK_CAP_FABRIC_MANAGEMENT 0
33 
34 /*
35  * Max supported capabilities count
36  *
37  */
38 #define NVLINK_CAP_COUNT 1
39 
40 #define NVLINK_UUID_LEN 16
41 
42 /*
43  * Total number of nvlinks connections a device could have.
44  */
45 #define NVLINK_MAX_DEVICE_CONN 64
46 
47 /*
48  * Total number of links to train in parallel
49  */
50 #define NVLINK_MAX_PARALLEL_CONNS_TRAIN_COUNT 288
51 
52 /*
53  * Best effort to copy the driver supplied device name. Name more than
54  * this size (if any) will be truncated.
55  */
56 #define NVLINK_DEVICE_NAME_LEN_MAX 30
57 
58 /*
59  * Total number of nvlink devices supported. Derived based on current supported
60  * limits. OBJ_MAX_GPUS = 32 and NVSWITCH_DEVICE_INSTANCE_MAX = 64
61  */
62 #define NVLINK_DEVICE_INSTANCE_MAX 96
63 
64 /*
65  * Total number of nvlink endpoints core library can have
66  *  This is mapped to NVLINK_MAX_SYSTEM_LINK_NUM in drivers/nvlink/interface/nvlink.h
67  */
68 #define NVLINK_MAX_NVLINK_ENDPOINTS 624
69 
70 #define NVLINK_VERSION_STRING_LENGTH    64
71 
72 #define NVLINK_CCI_TRAINING_TIMEOUT_SEC 30
73 
74 /*
75  * NVLink version consists of,
76  *   major - no compatibility.
77  *   minor - only backwards compatible.
78  */
79 typedef struct
80 {
81     char version[NVLINK_VERSION_STRING_LENGTH];
82 } nvlink_version;
83 
84 typedef struct
85 {
86     NvU16 domain;
87     NvU8  bus;
88     NvU8  device;
89     NvU8  function;
90 } nvlink_pci_dev_info;
91 
92 /* uniquely identify an nvlink endpoint */
93 typedef struct
94 {
95     NvU16               nodeId;
96     NvU16               linkIndex;
97     nvlink_pci_dev_info pciInfo;
98 } nvlink_endpoint;
99 
100 /* uniquely identify an nvlink device */
101 typedef struct
102 {
103     NvU16               nodeId;
104     nvlink_pci_dev_info pciInfo;
105 } nvlink_device_info;
106 
107 /* detailed information about an nvlink device */
108 typedef struct
109 {
110     nvlink_pci_dev_info pciInfo;
111     char                deviceName[NVLINK_DEVICE_NAME_LEN_MAX];
112     NvU8                devUuid[NVLINK_UUID_LEN];
113     NvU16               numLinks;
114     NvU32               devType;
115     NV_DECLARE_ALIGNED(NvU64 enabledLinkMask, 8);
116     NvBool              bEnableAli;
117     /* See struct definition modification guidelines at the top of this file */
118 } nvlink_detailed_dev_info;
119 
120 /* detailed information about a remote nvlink connection endpoint */
121 typedef struct
122 {
123     NvU16               nodeId;
124     NvU16               linkIndex;
125     nvlink_pci_dev_info pciInfo;
126     NvU8                devUuid[NVLINK_UUID_LEN];
127     NvU32               devType;
128 } nvlink_remote_endpoint_info;
129 
130 /* uniquely identify an nvlink connection */
131 typedef struct
132 {
133     nvlink_endpoint srcEndPoint;
134     nvlink_endpoint dstEndPoint;
135 } nvlink_connection_info;
136 
137 /* link device types */
138 typedef enum
139 {
140     nvlink_device_type_unknown = 0,
141     nvlink_device_type_gpu,
142     nvlink_device_type_ibmnpu,
143     nvlink_device_type_nvswitch
144 } nvlink_device_type;
145 
146 /* link modes */
147 typedef enum
148 {
149     nvlink_link_mode_unknown = 0,
150     nvlink_link_mode_off,
151     nvlink_link_mode_active,
152     nvlink_link_mode_swcfg,
153     nvlink_link_mode_fault,
154     nvlink_link_mode_recovery,
155     nvlink_link_mode_fail,
156     nvlink_link_mode_detect,
157     nvlink_link_mode_reset,
158     nvlink_link_mode_enable_pm,
159     nvlink_link_mode_disable_pm,
160     nvlink_link_mode_traffic_setup,
161     nvlink_link_mode_contain,
162     nvlink_link_mode_training_cci
163 } nvlink_link_mode;
164 
165 /* sublink tx modes */
166 typedef enum
167 {
168     nvlink_tx_sublink_mode_unknown = 0,
169     nvlink_tx_sublink_mode_hs,
170     nvlink_tx_sublink_mode_single_lane,
171     nvlink_tx_sublink_mode_train,
172     nvlink_tx_sublink_mode_safe,
173     nvlink_tx_sublink_mode_off,
174     nvlink_tx_sublink_mode_common_mode,
175     nvlink_tx_sublink_mode_common_mode_disable,
176     nvlink_tx_sublink_mode_data_ready,
177     nvlink_tx_sublink_mode_tx_eq,
178     nvlink_tx_sublink_mode_pbrs_en,
179     nvlink_tx_sublink_mode_post_hs
180 } nvlink_tx_sublink_mode;
181 
182 /* sublink rx modes */
183 typedef enum
184 {
185     nvlink_rx_sublink_mode_unknown = 0,
186     nvlink_rx_sublink_mode_hs,
187     nvlink_rx_sublink_mode_single_lane,
188     nvlink_rx_sublink_mode_train,
189     nvlink_rx_sublink_mode_safe,
190     nvlink_rx_sublink_mode_off,
191     nvlink_rx_sublink_mode_rxcal
192 } nvlink_rx_sublink_mode;
193 
194 /* link and sublink state of an nvlink endpoint */
195 typedef struct
196 {
197     NvU8 linkMode;
198     NvU8 txSubLinkMode;
199     NvU8 rxSubLinkMode;
200 } nvlink_link_state;
201 
202 /*
203  * CTRL_NVLINK_CHECK_VERSION
204  *
205  * The interface will check if the client's version is supported by the driver.
206  *
207  * Parameters:
208  *   user [IN]
209  *      version of the interface that the client is compiled with.
210  *
211  *   kernel [OUT]
212  *      version of the interface that the kernel driver is compiled with. This
213  *      information will be filled even if the CTRL call returns
214  *      NVL_ERR_NOT_SUPPORTED due to version mismatch.
215  *
216  *   status [OUT]
217  *      NVL_SUCCESS if the client is using compatible interface.
218  *      NVL_ERR_NOT_SUPPORTED if the client is using incompatible interface.
219  *      Or, Other NVL_XXX status value.
220  */
221 typedef struct
222 {
223     /* input parameters */
224     nvlink_version user;
225 
226     /* output parameters */
227     nvlink_version kernel;
228     NvlStatus      status;
229 } nvlink_check_version;
230 
231 /*
232  * CTRL_NVLINK_SET_NODE_ID
233  *
234  * Assign the nvlink devices with a fabric node id.
235  * This interface will enumerate all the existing registered devices (if any)
236  * and update its node id. Any subsequent nvlink device registration will use
237  * this node id.
238  *
239  * Parameters:
240  *   nodeId [IN]
241  *      fabric node id of the node.
242  *
243  *   status [OUT]
244  *      One of the NVL_XXX status value.
245  */
246 typedef struct
247 {
248     /* input parameters */
249     NvU16     nodeId;
250 
251     /* output parameters */
252     NvlStatus status;
253 } nvlink_set_node_id;
254 
255 /*
256  * CTRL_NVLINK_SET_TX_COMMON_MODE
257  *
258  * Set common mode for all device links.
259  * A user mode module, which has no validated and stored nvlink connection should
260  * do a device discovery. This interface allows all the links to enable or disable
261  * common mode to facilitate such device discovery.
262  *
263  * Parameters:
264  *   commMode [IN]
265  *      Specify the desired common mode, True to enable and False to disable.
266  *
267  *   status [OUT]
268  *      One of the NVL_XXX status value.
269  */
270 typedef struct
271 {
272     /* input parameters */
273     NvBool    commMode;
274 
275     /* output parameters */
276     NvlStatus status;
277 } nvlink_set_tx_common_mode;
278 
279 /*
280  * CTRL_NVLINK_CALIBRATE
281  *
282  * Do Rx Calibration for all the links.
283  * A user mode module, which has no validated and stored nvlink connection
284  * should do a device discovery. This interface allows all the links to
285  * initiate Rx calibration as part of this discovery process.
286  *
287  * Parameters:
288  *   status [OUT]
289  *      One of the NVL_XXX status value.
290  */
291 typedef struct
292 {
293     /* input parameters */
294 
295     /* output parameters */
296     NvlStatus status;
297 } nvlink_calibrate;
298 
299 /*
300  * CTRL_NVLINK_ENABLE_DATA
301  *
302  * Enable TX data for all the registered links in the node.
303  * A user mode module, which has no validated and stored nvlink connection should
304  * do a device discovery. This interface enable data mode for all the links as part
305  * of this discovery process.
306  *
307  * Parameters:
308  *   status [OUT]
309  *      One of the NVL_XXX status value.
310  */
311 typedef struct
312 {
313     /* input parameters */
314 
315     /* output parameters */
316     NvlStatus status;
317 } nvlink_enable_data;
318 
319 /*
320  * CTRL_NVLINK_LINK_INIT_ASYNC
321  *
322  * Initialize all the registered links in the node.
323  * Initializes all the registered links in the node and start SWCFG state
324  * transition for the links. However, this interface will not wait/poll
325  * for the links to finish the initialization. The caller must use
326  * CTRL_NVLINK_DEVICE_LINK_INIT_STATUS to query the link status which will
327  * wait for the initialization to complete and report how many links are
328  * transitioned to SWCFG state.
329  *
330  * Parameters:
331  *   status [OUT]
332  *      One of the NVL_XXX status value.
333  */
334 typedef struct
335 {
336     /* input parameters */
337 
338     /* output parameters */
339     NvlStatus status;
340 } nvlink_link_init_async;
341 
342 /*
343  * CTRL_NVLINK_DEVICE_LINK_INIT_STATUS
344  *
345  * Query link initialization status of the specified device.
346  * This interface poll/wait for the link initialization to complete and report
347  * per link initialization status. The caller can initiate a link initialization
348  * request using the CTRL_NVLINK_LINK_INIT_ASYNC interface.
349  *
350  * Parameters:
351  *   devInfo [OUT]
352  *      nvlink device identification information.
353  *
354  *   status [OUT]
355  *      One of the NVL_XXX status value.
356  *
357  *   initStatus [OUT]
358  *      Per link init state information. Link will be in SWCFG mode on True.
359  */
360 typedef struct
361 {
362     NvU16  linkIndex;
363     NvBool initStatus;
364 } nvlink_link_init_status;
365 
366 typedef struct
367 {
368     /* input parameters */
369     nvlink_device_info       devInfo;
370 
371     /* output parameters */
372     NvlStatus                status;
373     nvlink_link_init_status  linkStatus[NVLINK_MAX_DEVICE_CONN];
374 } nvlink_device_link_init_status;
375 
376 /*
377  * CTRL_NVLINK_DISCOVER_INTRANODE_CONNS
378  *
379  * Initiate an nvlink connection discovery.
380  * This interface allows the node to initiate an nvlink connection discovery
381  * process by writing and reading specific discovery tokens. The discovered
382  * connections are then registered in the nvlink driver context as intranode
383  * connections.
384  *
385  * Note:
386  *   1) Link has to be in SWCFG/HS mode to participate in the discovery process.
387  *   2) This interface will discover only intranode connections.
388  *
389  * Parameters:
390  *   status [OUT]
391  *      One of the NVL_XXX status value.
392  */
393 typedef struct
394 {
395     /* input parameters */
396 
397     /* output parameters */
398     NvlStatus status;
399 } nvlink_discover_intranode_conns;
400 
401 /*
402  * CTRL_NVLINK_DEVICE_GET_INTRANODE_CONNS
403  *
404  * Returns all the nvlink intranode connections for a device.
405  * This interface allows a user mode module to retrive endpoint details
406  * of all the intranode connections for the specified device.
407  *
408  * Note:
409  *   1) Issue CTRL_NVLINK_DISCOVER_INTRANODE_CONNS to discover connections first.
410  *
411  * Parameters:
412  *   devInfo [OUT]
413  *      nvlink device identification information.
414  *
415  *   status [OUT]
416  *      One of the NVL_XXX status value.
417  *
418  *   numConnections [OUT]
419  *      The number of nvlink connections discovered for this device.
420  *
421  *   conn [OUT]
422  *      Detailed device information of each connection to this device.
423  */
424 typedef struct
425 {
426     /* input parameters */
427     nvlink_device_info     devInfo;
428 
429     /* output parameters */
430     NvlStatus              status;
431     NvU32                  numConnections;
432     nvlink_connection_info conn[NVLINK_MAX_DEVICE_CONN];
433 } nvlink_device_get_intranode_conns;
434 
435 /*
436  * CTRL_NVLINK_ADD_INTERNODE_CONN
437  *
438  * Register an internode nvlink connection with driver.
439  * This interface allows a user mode module to populate internode nvlink
440  * connections which are discovered through an nvlink device discovery
441  * process. This is applicable only for multi-node systems where only one
442  * endpoint of the connection is visible/accessible from a given node.
443  *
444  * Parameters:
445  *   localEndPoint [IN]
446  *      Local endpoint information of the internode connection.
447  *
448  *   remoteEndPoint [IN]
449  *      Remote endpoint and device information of the internode connection.
450  *
451  *   status [OUT]
452  *      One of the NVL_XXX status value.
453  */
454 typedef struct
455 {
456     /* input parameters */
457     nvlink_endpoint             localEndPoint;
458     nvlink_remote_endpoint_info remoteEndPoint;
459 
460     /* output parameters */
461     NvlStatus                   status;
462 } nvlink_add_internode_conn;
463 
464 /*
465  * CTRL_NVLINK_REMOVE_INTERNODE_CONN
466  *
467  * Remove a previously added internode nvlink connection from the driver.
468  * This interface allows a user mode module to remove an internode nvlink
469  * connection. This is applicable only for multi-node systems where only one
470  * endpoint of the connection is visible/accessible from a given node.
471  *
472  * Parameters:
473  *   localEndPoint [IN]
474  *      Local endpoint information of the internode connection.
475  *
476  *   status [OUT]
477  *      One of the NVL_XXX status value.
478  */
479 typedef struct
480 {
481     /* input parameters */
482     nvlink_endpoint localEndPoint;
483 
484     /* output parameters */
485     NvlStatus       status;
486 } nvlink_remove_internode_conn;
487 
488 /*
489  * CTRL_NVLINK_DEVICE_WRITE_DISCOVERY_TOKENS
490  *
491  * Write discovery token on links which are not part of any connection.
492  * This interface allows a user mode module, which should discover all the
493  * internode connections to write a unique discovery token on all the links
494  * of the specified device.
495  *
496  * Parameters:
497  *   devInfo [OUT]
498  *      nvlink device identification information.
499  *
500  *   status [OUT]
501  *      One of the NVL_XXX status value.
502  *
503  *   numTokens [OUT]
504  *      Number of nvlink tokens written.
505  *
506  *   tokenInfo [OUT]
507  *      link index, and value of each token written.
508  */
509 typedef struct
510 {
511     NvU16 linkIndex;
512     NV_DECLARE_ALIGNED(NvU64 tokenValue, 8);
513 } nvlink_token_info;
514 
515 typedef struct
516 {
517     /* input parameters */
518     nvlink_device_info  devInfo;
519 
520     /* output parameters */
521     NvlStatus           status;
522     NvU32               numTokens;
523     nvlink_token_info   tokenInfo[NVLINK_MAX_DEVICE_CONN];
524 } nvlink_device_write_discovery_tokens;
525 
526 /*
527  * CTRL_NVLINK_DEVICE_READ_DISCOVERY_TOKENS
528  *
529  * Read discovery token on links which are not part of any connection.
530  * This interface allows a user mode module to read discovery token from all the
531  * links of the specified device. To discover internode connections, a module
532  * will first initiate a write discovery token operation, then read back tokens
533  * from all other nodes and check for matching tokens.
534  *
535  * Parameters:
536  *   devInfo [OUT]
537  *      nvlink device identification information.
538  *
539  *   status [OUT]
540  *      One of the NVL_XXX status value.
541  *
542  *   numTokens [OUT]
543  *      Number of nvlink tokens read.
544  *
545  *   tokenInfo [OUT]
546  *      link index, and value of each token read.
547  */
548 typedef struct
549 {
550     /* input parameters */
551     nvlink_device_info  devInfo;
552 
553     /* output parameters */
554     NvlStatus           status;
555     NvU32               numTokens;
556     nvlink_token_info   tokenInfo[NVLINK_MAX_DEVICE_CONN];
557 } nvlink_device_read_discovery_tokens;
558 
559 /*
560  * CTRL_NVLINK_TRAIN_INTRANODE_CONN
561  *
562  * Train an intranode connection.
563  * This interface allows a user mode module to train an nvlink connection
564  * to the desired state.
565  *
566  * Note:
567  *   1) Source endpoint is treated as active endpoint.
568  *
569  * Parameters:
570  *   trainTo [IN]
571  *      Desired connection state as defined in nvlink_conn_train_type.
572  *
573  *   srcEndPoint [IN]
574  *      Specify source endpoint details of the nvlink connection.
575  *
576  *   dstEndPoint [IN]
577  *      Specify other endpoint details of the nvlink connection.
578  *
579  *   status [OUT]
580  *      One of the NVL_XXX status value.
581  *
582  *   srcEndState [OUT]
583  *      Link and sublink state of the source endpoint.
584  *
585  *   dstEndState [OUT]
586  *      Link and sublink state of the other endpoint.
587  */
588 typedef enum
589 {
590     nvlink_train_conn_off_to_swcfg = 0,
591     nvlink_train_conn_swcfg_to_active,
592     nvlink_train_conn_to_off,
593     nvlink_train_conn_active_to_swcfg,
594     nvlink_train_conn_swcfg_to_off,
595     nvlink_train_conn_off_to_active_ali_non_blocking,
596     nvlink_train_conn_off_to_active_ali_blocking,
597     /* See enum modification guidelines at the top of this file */
598 } nvlink_conn_train_type;
599 
600 typedef struct
601 {
602     /* input parameters */
603     NvU32                  trainTo;
604     nvlink_endpoint        srcEndPoint;
605     nvlink_endpoint        dstEndPoint;
606 
607     /* output parameters */
608     NvlStatus              status;
609     nvlink_link_state      srcEndState;
610     nvlink_link_state      dstEndState;
611 } nvlink_train_intranode_conn;
612 
613 /*
614  * CTRL_NVLINK_TRAIN_INTERNODE_CONN_LINK
615  *
616  * Train link of an internode connection.
617  * This interface allows a user mode module to train the local endpoint
618  * link of an nvlink internode connection to the desired state. This is
619  * applicable only for multi-node systems where only one endpoint of the
620  * connection is visible/accessible from a given node.
621  *
622  * Parameters:
623  *   trainTo [IN]
624  *      Desired link state as defined in nvlink_link_train_type.
625  *
626  *   isMasterEnd [IN]
627  *      True if the endpoint is the master endpoint of the connection.
628  *
629  *   endPoint [IN]
630  *      Specify endpoint details of the nvlink connection.
631  *
632  *   status [OUT]
633  *      One of the NVL_XXX status value.
634  *
635  *   endState [OUT]
636  *      Link and sublink state of the endpoint.
637  */
638 typedef enum
639 {
640     nvlink_train_link_off_to_swcfg = 0,
641     nvlink_train_link_swcfg_to_active,
642     nvlink_train_link_to_off,
643     nvlink_train_link_active_to_swcfg,
644     nvlink_train_link_swcfg_to_off,
645 } nvlink_link_train_type;
646 
647 typedef struct
648 {
649     /* input parameters */
650     NvU32                  trainTo;
651     NvU32                  isMasterEnd;
652     nvlink_endpoint        localEndPoint;
653 
654     /* output parameters */
655     NvlStatus              status;
656     nvlink_link_state      localEndState;
657 } nvlink_train_internode_conn_link;
658 
659 /*
660  * CTRL_NVLINK_TRAIN_INTERNODE_CONN_SUBLINK
661  *
662  * Train sublink of an internode connection.
663  * This interface allows a user mode module to train the local endpoint
664  * sublink of an nvlink internode connection to the desired state. This is
665  * applicable only for multi-node systems where only one endpoint of the
666  * connection is visible/accessible from a given node.
667  *
668  * Parameters:
669  *   trainTo [IN]
670  *       Desired sublink state as defined in nvlink_sublink_train_type.
671  *
672  *   isMasterEnd [IN]
673  *      True if the endpoint is master endpoint of the connection.
674  *
675  *   endPoint [IN]
676  *      Specify endpoint details of the nvlink connection.
677  *
678  *   status [OUT]
679  *      One of the NVL_XXX status value.
680  *
681  *   endState [OUT]
682  *      Link and sublink state of the endpoint.
683  */
684 typedef enum
685 {
686     nvlink_train_sublink_off_to_safe = 0,
687     nvlink_train_sublink_safe_to_hs,
688     nvlink_train_sublink_to_off,
689     nvlink_train_sublink_hs_to_safe,
690     nvlink_train_sublink_safe_to_off,
691 } nvlink_sublink_train_type;
692 
693 typedef struct
694 {
695     /* input parameters */
696     nvlink_sublink_train_type trainTo;
697     NvU32                     isMasterEnd;
698     nvlink_endpoint           localEndPoint;
699 
700     /* output parameters */
701     NvlStatus                 status;
702     nvlink_link_state         localEndState;
703 } nvlink_train_internode_conn_sublink;
704 
705 /*
706  * CTRL_NVLINK_GET_DEVICES_INFO
707  *
708  * Return registered device information.
709  * This interface allows a user mode module to query and retrieve detailed
710  * information about all the registered devices in the nvlink core. This
711  * device information can be later used to uniquely identify each device
712  * present in the node.
713  *
714  * Parameters:
715  *
716  *   status [OUT]
717  *      One of the NVL_XXX status value.
718  *
719  *   numDevice [OUT]
720  *      Total number of devices registered.
721  *
722  *   devInfo [OUT]
723  *      Detailed information of each device.
724  */
725 typedef struct
726 {
727     /* input parameters */
728 
729     /* output parameters */
730     NvlStatus                status;
731     NvU32                    numDevice;
732     nvlink_detailed_dev_info devInfo[NVLINK_DEVICE_INSTANCE_MAX];
733 } nvlink_get_devices_info;
734 
735 /*
736  * CTRL_NVLINK_INITPHASE1
737  *
738  * This interface allows a user mode module to send INITPHASE request to minion.
739  * NOTE: This IOCTRL is supported from GA100+
740  *
741  * Parameters:
742  *   status [OUT]
743  *      One of the NVL_XXX status value.
744  */
745 typedef struct
746 {
747     /* input parameters */
748 
749     /* output parameters */
750     NvlStatus status;
751 } nvlink_initphase1;
752 
753 /*
754  * CTRL_NVLINK_INITNEGOTIATE
755  *
756  * This interface allows a user mode module to send INITNEGOTIATE request to minion.
757  * NOTE: This IOCTRL is supported from GA100+
758  *
759  * Parameters:
760  *   status [OUT]
761  *      One of the NVL_XXX status value.
762  */
763 typedef struct
764 {
765     /* input parameters */
766 
767     /* output parameters */
768     NvlStatus status;
769 } nvlink_initnegotiate;
770 
771 /*
772  * CTRL_NVLINK_RX_INIT_TERM
773  *
774  * This interface allows a user mode module to send RECEIVER TERMINATION on the endpoint.
775  * NOTE: This IOCTRL is supported from GA100+
776  *
777  * Parameters:
778  *   status [OUT]
779  *      One of the NVL_XXX status value.
780  */
781 typedef struct
782 {
783     /* input parameters */
784 
785     /* output parameters */
786     NvlStatus status;
787 } nvlink_rx_init_term;
788 
789 /*
790  * CTRL_NVLINK_DEVICE_READ_SIDS
791  *
792  * NVLink 3.0 onwards, connection detection is handled by Minion. After INITNEGOTIATE
793  * completed, this interface needs to be queried to retrieve the local/remote SIDs
794  * and the local/remote link number of all links associated with a device.
795  *
796  * On NVLink 4.0 this needs to be queried after all links in the system have been
797  * trained.
798  *
799  * Parameters:
800  *   devInfo [IN]
801  *      nvlink device identification information.
802  *
803  *   status [OUT]
804  *      One of the NVL_XXX status value.
805  *
806  *   numEntries [OUT]
807  *      Number of links for which SIDs were read
808  *
809  *   sidInfo [OUT]
810  *      local/remote link number and local/remote sid
811  */
812 typedef struct
813 {
814     NvU32 localLinkNum;
815     NvU32 remoteLinkNum;
816 
817     /* Added as part of NvLink 3.0 */
818     NV_DECLARE_ALIGNED(NvU64 localLinkSid,  8);
819     NV_DECLARE_ALIGNED(NvU64 remoteLinkSid, 8);
820 } nvlink_sid_info;
821 
822 typedef struct
823 {
824     /* input parameters */
825     nvlink_device_info  devInfo;
826 
827     /* output parameters */
828     NvlStatus           status;
829     NvU32               numEntries;
830     nvlink_sid_info     sidInfo[NVLINK_MAX_DEVICE_CONN];
831 } nvlink_device_read_sids;
832 
833 /*
834  * CTRL_NVLINK_SET_RX_DETECT
835  *
836  * This interface allows a user mode module to send RECEIVER DETECT on the endpoint.
837  * NOTE: This IOCTRL is supported from GA100+
838  *
839  * Parameters:
840  *   status [OUT]
841  *      One of the NVL_XXX status value.
842  */
843 typedef struct
844 {
845     /* input parameters */
846 
847     /* output parameters */
848     NvlStatus status;
849 } nvlink_set_rx_detect;
850 
851 /*
852  * CTRL_NVLINK_GET_RX_DETECT
853  *
854  * This interface allows a user mode module to Poll for output of receiver
855  * detect on all the endpoints.
856  * NOTE: This IOCTRL is supported from GA100+
857  *
858  * Parameters:
859  *   status [OUT]
860  *      One of the NVL_XXX status value.
861  */
862 typedef struct
863 {
864     /* input parameters */
865 
866     /* output parameters */
867     NvlStatus status;
868 } nvlink_get_rx_detect;
869 
870 /*
871  * CTRL_NVLINK_ACQUIRE_CAPABILITY
872  *
873  * Upon success, user mode would acquire the requested capability
874  * to perform privilege operations. This IOCTL will acquire one
875  * capability at a time.
876  *
877  * Parameters:
878  *   capDescriptor [IN]
879  *      The OS file descriptor or handle representing the capability.
880  *   cap [IN]
881  *      The requested capability. One of the NVLINK_CAP_*.
882  *
883  *   status [OUT]
884  *      One of the NVL_XXX status value.
885  */
886 typedef struct
887 {
888     /* input parameters */
889     NV_DECLARE_ALIGNED(NvU64 capDescriptor, 8);
890     NvU32 cap;
891 
892     /* output parameters */
893     NvlStatus status;
894 } nvlink_acquire_capability;
895 
896 /*
897  * CTRL_NVLINK_GET_LINK_STATE
898  *
899  * Returns link state. This is needed for trunk links
900  * which has post HS steps to get links to active.
901  *
902  * Parameters:
903  *   endPointPairs [IN]
904  *      Specify the endpoints on which the command is to be sent
905  *
906  *   endPointPairsCount [IN]
907  *      Specify count of endpoints passed in
908  *
909  *   status [OUT]
910  *      One of the NVL_XXX status value.
911  *
912  *   endpointPairsStates [OUT]
913  *      Link and sublink state of the endpoint
914  */
915 typedef struct
916 {
917     /* input parameters */
918     nvlink_endpoint        endPoints[NVLINK_MAX_NVLINK_ENDPOINTS];
919     NvU32                  endPointCount;
920 
921     /* output parameters */
922     NvlStatus              status;
923     nvlink_link_state      endState[NVLINK_MAX_NVLINK_ENDPOINTS];
924 } nvlink_get_link_state;
925 
926 /*
927  * CTRL_NVLINK_TRAIN_INTRANODE_CONNS_PARALLEL
928  *
929  * Train a set of intranode connections in parallel.
930  * This interface allows a user mode module to train a set of nvlink
931  * connections to the desired state.
932  *
933  * Note:
934  *   1) Source endpoint of every pair is treated as active endpoint.
935  *
936  * Parameters:
937  *   trainTo [IN]
938  *      Desired connection state as defined in nvlink_conn_train_type.
939  *
940  *   endPointPairs [IN]
941  *      Specify endpoint pair (source and other endpoint) details of the
942  *      nvlink connections
943  *
944  *   endPointPairsCount [IN]
945  *      Specify count of intranode connnection passed in
946  *
947  *   status [OUT]
948  *      One of the NVL_XXX status value.
949  *
950  *   endpointPairsStates [OUT]
951  *      Link and sublink state of the endpoint pairs
952  */
953 
954 typedef struct
955 {
956     nvlink_endpoint        src;
957     nvlink_endpoint        dst;
958 } nvlink_endpoint_pair;
959 
960 typedef struct
961 {
962     nvlink_link_state      srcEnd;
963     nvlink_link_state      dstEnd;
964 } nvlink_link_state_pair;
965 
966 typedef struct
967 {
968     /* input parameters */
969     NvU32                  trainTo;
970     nvlink_endpoint_pair   endPointPairs[NVLINK_MAX_PARALLEL_CONNS_TRAIN_COUNT];
971     NvU32                  endPointPairsCount;
972 
973     /* output parameters */
974     NvlStatus              status;
975     nvlink_link_state_pair endpointPairsStates[NVLINK_MAX_PARALLEL_CONNS_TRAIN_COUNT];
976 } nvlink_train_intranode_conns_parallel;
977 
978 /*
979  * CTRL_NVLINK_TRAIN_INTERNODE_LINKS_INITOPTIMIZE
980  *
981  * This interface allows a user mode module to send INITOPTIMIZE request to minion
982  *   and poll on the training good status which implies sublinks are trained
983  * NOTE: This IOCTRL is supported from GA100+
984  *
985  * Parameters:
986  *   endPoints [IN]
987  *      Specify the endpoints on which INITOPTIMIZE is to be sent
988  *
989  *   endPointCount [IN]
990  *      Specify count of endpoints passed in
991  *
992  *   status [OUT]
993  *      One of the NVL_XXX status value.
994  */
995 typedef struct
996 {
997     /* input parameters */
998     nvlink_endpoint        endPoints[NVLINK_MAX_NVLINK_ENDPOINTS];
999     NvU32                  endPointCount;
1000 
1001     /* output parameters */
1002     NvlStatus              status;
1003 } nvlink_train_internode_links_initoptimize;
1004 
1005 /*
1006  * CTRL_NVLINK_TRAIN_INTERNODE_LINKS_POST_INITOPTIMIZE
1007  *
1008  * This interface allows a user mode module to send POST_INITOPTIMIZE request to minion
1009  *
1010  * NOTE: This IOCTRL is supported from GA100+
1011  *
1012  * Parameters:
1013  *   endPoints [IN]
1014  *      Specify the endpoints on which POST_INITOPTIMIZE is to be sent
1015  *
1016  *   endPointCount [IN]
1017  *      Specify count of endpoints passed in
1018  *
1019  *   status [OUT]
1020  *      One of the NVL_XXX status value.
1021  */
1022 typedef struct
1023 {
1024     /* input parameters */
1025     nvlink_endpoint        endPoints[NVLINK_MAX_NVLINK_ENDPOINTS];
1026     NvU32                  endPointCount;
1027 
1028     /* output parameters */
1029     NvlStatus              status;
1030 } nvlink_train_internode_links_post_initoptimize;
1031 
1032 /*
1033  * CTRL_NVLINK_TRAIN_INTERNODE_CONNS_PARALLEL
1034  *
1035  * Train link of an internode connection.
1036  * This interface allows a user mode module to train the local endpoint
1037  * link of an nvlink internode connection to the desired state. This is
1038  * applicable only for multi-node systems where only one endpoint of the
1039  * connection is visible/accessible from a given node.
1040  *
1041  * Parameters:
1042  *   trainTo [IN]
1043  *      Desired link state as defined in nvlink_link_train_type.
1044  *
1045  *   isMasterEnd [IN]
1046  *      True if the endpoint is the master endpoint of the connection.
1047  *
1048  *   endPoints [IN]
1049  *      Specify endpoint details of the nvlink connections.
1050  *
1051  *   status [OUT]
1052  *      One of the NVL_XXX status value.
1053  *
1054  *   endStates [OUT]
1055  *      Link and sublink state of the endpoints.
1056  */
1057 
1058 typedef struct
1059 {
1060     /* input parameters */
1061     NvU32                  trainTo;
1062     NvU32                  isMasterEnd[NVLINK_MAX_PARALLEL_CONNS_TRAIN_COUNT];
1063     nvlink_endpoint        localEndPoints[NVLINK_MAX_PARALLEL_CONNS_TRAIN_COUNT];
1064     NvU32                  localEndPointCount;
1065 
1066     /* output parameters */
1067     NvlStatus              status;
1068     nvlink_link_state      localEndStates[NVLINK_MAX_PARALLEL_CONNS_TRAIN_COUNT];
1069 } nvlink_train_internode_conns_parallel;
1070 
1071 /*
1072  * CTRL_NVLINK_INITPHASE5
1073  *
1074  * This interface allows a user mode module to send INITPHASE request to minion.
1075  * NOTE: This IOCTRL is supported from GA100+
1076  *
1077  * Parameters:
1078  *   status [OUT]
1079  *      One of the NVL_XXX status value.
1080  */
1081 typedef struct
1082 {
1083     /* input parameters */
1084 
1085     /* output parameters */
1086     NvlStatus status;
1087 } nvlink_initphase5;
1088 
1089 /*
1090  * CTRL_NVLINK_GET_DEVICE_LINK_STATES
1091  *
1092  * Returns the link state of all links on a given device.
1093  *
1094  * Parameters:
1095  *   devInfo [IN]
1096  *      nvlink device identification information.
1097  *
1098  *   status [OUT]
1099  *      One of the NVL_XXX status value.
1100  *
1101  *   endStates [OUT]
1102  *      Link and sublink state of links. The array
1103  *      is continuous (i.e. it will have all links of the device
1104  *      even if the link is disabled)
1105  *      For links that are not enabled, the index in the array
1106  *      will show the states as INVALID.
1107  *
1108  *   endStatesCount [OUT]
1109  *      count of total entries in the endStates array
1110  *
1111  */
1112 typedef struct
1113 {
1114     /* input parameters */
1115     nvlink_device_info       devInfo;
1116 
1117 
1118     /* output parameters */
1119     NvlStatus              status;
1120     nvlink_link_state      endStates[NVLINK_MAX_DEVICE_CONN];
1121     NvU32                  endStatesCount;
1122     NvU64                  time;
1123 } nvlink_get_device_link_states;
1124 
1125 /*
1126  * Note: Verify that new parameter structs for IOCTLs satisfy
1127  *       sizing restrictions for all OSs they could be used in.
1128  */
1129 
1130 #define CTRL_NVLINK_CHECK_VERSION                            0x01
1131 #define CTRL_NVLINK_SET_NODE_ID                              0x02
1132 #define CTRL_NVLINK_SET_TX_COMMON_MODE                       0x03
1133 #define CTRL_NVLINK_CALIBRATE                                0x04
1134 #define CTRL_NVLINK_ENABLE_DATA                              0x05
1135 #define CTRL_NVLINK_LINK_INIT_ASYNC                          0x06
1136 #define CTRL_NVLINK_DEVICE_LINK_INIT_STATUS                  0x07
1137 #define CTRL_NVLINK_DISCOVER_INTRANODE_CONNS                 0x08
1138 #define CTRL_NVLINK_DEVICE_GET_INTRANODE_CONNS               0x09
1139 #define CTRL_NVLINK_ADD_INTERNODE_CONN                       0x0A
1140 #define CTRL_NVLINK_REMOVE_INTERNODE_CONN                    0x0B
1141 #define CTRL_NVLINK_DEVICE_WRITE_DISCOVERY_TOKENS            0x0C
1142 #define CTRL_NVLINK_DEVICE_READ_DISCOVERY_TOKENS             0x0D
1143 #define CTRL_NVLINK_TRAIN_INTRANODE_CONN                     0x0E
1144 #define CTRL_NVLINK_TRAIN_INTERNODE_CONN_LINK                0x0F
1145 #define CTRL_NVLINK_TRAIN_INTERNODE_CONN_SUBLINK             0x10
1146 #define CTRL_NVLINK_GET_DEVICES_INFO                         0x11
1147 #define CTRL_NVLINK_INITPHASE1                               0x12
1148 #define CTRL_NVLINK_INITNEGOTIATE                            0x13
1149 #define CTRL_NVLINK_RX_INIT_TERM                             0x14
1150 #define CTRL_NVLINK_SET_RX_DETECT                            0x15
1151 #define CTRL_NVLINK_GET_RX_DETECT                            0x16
1152 #define CTRL_NVLINK_ACQUIRE_CAPABILITY                       0x17
1153 #define CTRL_NVLINK_TRAIN_INTRANODE_CONNS_PARALLEL           0x18
1154 #define CTRL_NVLINK_DEVICE_READ_SIDS                         0x19
1155 #define CTRL_NVLINK_TRAIN_INTERNODE_LINKS_INITOPTIMIZE       0x1A
1156 #define CTRL_NVLINK_TRAIN_INTERNODE_LINKS_POST_INITOPTIMIZE  0x1B
1157 #define CTRL_NVLINK_TRAIN_INTERNODE_CONNS_PARALLEL           0x1C
1158 #define CTRL_NVLINK_INITPHASE5                               0x1D
1159 #define CTRL_NVLINK_GET_DEVICE_LINK_STATES                   0x1E
1160 #define CTRL_NVLINK_GET_LINK_STATE                           0x1F
1161 #define CTRL_NVLINK_RESERVED_0                               0x20
1162 #define CTRL_NVLINK_RESERVED_1                               0x21
1163 #define CTRL_NVLINK_RESERVED_2                               0x22
1164 #define CTRL_NVLINK_RESERVED_3                               0x23
1165 #define CTRL_NVLINK_RESERVED_4                               0x24
1166 #define CTRL_NVLINK_RESERVED_5                               0x25
1167 #define CTRL_NVLINK_RESERVED_6                               0x26
1168 #define CTRL_NVLINK_RESERVED_7                               0x27
1169 #define CTRL_NVLINK_RESERVED_8                               0x28
1170 #define CTRL_NVLINK_RESERVED_9                               0x29
1171 #define CTRL_NVLINK_RESERVED_10                              0x2A
1172 #define CTRL_NVLINK_RESERVED_11                              0x2B
1173 /* Do not add code after this line */
1174 
1175 #endif // _NVLINK_LIB_CTRL_H_
1176