1 /*******************************************************************************
2     Copyright (c) 2014-2023 NVidia Corporation
3 
4     Permission is hereby granted, free of charge, to any person obtaining a copy
5     of this software and associated documentation files (the "Software"), to
6     deal in the Software without restriction, including without limitation the
7     rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
8     sell copies of the Software, and to permit persons to whom the Software is
9     furnished to do so, subject to the following conditions:
10 
11         The above copyright notice and this permission notice shall be
12         included in all copies or substantial portions of the Software.
13 
14     THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15     IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16     FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17     THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18     LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19     FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20     DEALINGS IN THE SOFTWARE.
21 *******************************************************************************/
22 
23 //
24 //     nvlink.h
25 //
26 
27 #ifndef _NVLINK_H_
28 #define _NVLINK_H_
29 
30 #ifdef __cplusplus
31 extern "C" {
32 #endif
33 
34 #include <nv-kernel-interface-api.h>
35 #include "nvlink_common.h"
36 #include "nvlink_lib_ctrl.h"
37 #include "nv_list.h"
38 #include "nvlink_errors.h"
39 #include "nvCpuUuid.h"
40 
41 // Debug Prints
42 #if defined(DEVELOP) || defined(DEBUG) || defined(NV_MODS)
43         #define NVLINK_PRINT_ENABLED    1
44         #define NVLINK_PRINT(format_and_stuff) nvlink_print format_and_stuff
45 
46         #define DBG_MODULE_NVLINK_CORE  __FILE__, __LINE__, __FUNCTION__
47         #define DBG_MODULE_IBMNPU       DBG_MODULE_NVLINK_CORE
48         #define DBG_MODULE_TEGRASHIM    DBG_MODULE_NVLINK_CORE
49         #define DBG_MODULE_EBRIDGE      DBG_MODULE_NVLINK_CORE
50         #define DBG_MODULE_NVSWITCH     DBG_MODULE_NVLINK_CORE
51 #else
52     #define NVLINK_PRINT(format_and_stuff)  ((void)(0))
53 #endif
54 
55 // Devices that support NVLINK
56 #define NVLINK_DEVICE_TYPE_EBRIDGE         0x0
57 #define NVLINK_DEVICE_TYPE_IBMNPU          0x1
58 #define NVLINK_DEVICE_TYPE_GPU             0x2
59 #define NVLINK_DEVICE_TYPE_NVSWITCH        0x3
60 #define NVLINK_DEVICE_TYPE_TEGRASHIM       0x4
61 
62 // NVLink versions
63 #define NVLINK_DEVICE_VERSION_10           0x00000001
64 #define NVLINK_DEVICE_VERSION_20           0x00000002
65 #define NVLINK_DEVICE_VERSION_22           0x00000004
66 #define NVLINK_DEVICE_VERSION_30           0x00000005
67 #define NVLINK_DEVICE_VERSION_31           0x00000006
68 #define NVLINK_DEVICE_VERSION_40           0x00000007
69 
70 // Link Transition Timeouts in miliseconds
71 #define NVLINK_TRANSITION_OFF_TIMEOUT        1
72 #define NVLINK_TRANSITION_SAFE_TIMEOUT       300
73 #define NVLINK_TRANSITION_HS_TIMEOUT         8000
74 #define NVLINK_TRANSITION_ACTIVE_PENDING     2000
75 #define NVLINK_TRANSITION_POST_HS_TIMEOUT    70
76 
77 // Link training seed values
78 #define NVLINK_MAX_SEED_NUM                6
79 #define NVLINK_MAX_SEED_BUFFER_SIZE        NVLINK_MAX_SEED_NUM + 1
80 
81 #define NVLINK_MAX_SYSTEM_LINK_NUM         624
82 
83 // Forwards
84 struct nvlink_device;
85 struct nvlink_device_handle;
86 struct nvlink_link;
87 struct nvlink_link_handlers;
88 
89 // nvlink device state
90 struct nvlink_device
91 {
92     NVListRec node;
93 
94     // List of links associated with this device
95     NVListRec link_list;
96 
97     // Uniquely identifies a device in the core
98     NvU64 deviceId;
99 
100     // Client supplied names and ids
101     char *driverName;
102     char *deviceName;
103     NvU8 *uuid;
104 
105     // PCI Information
106     struct nvlink_pci_info pciInfo;
107 
108     // Device type and status
109     NvU64  type;
110     NvBool initialized;
111 
112     // Training type: ALI or Non-ALI
113     NvBool enableALI;
114 
115     // fabric node id
116     NvU16  nodeId;
117 
118     // per Ioctrl data
119     NvU32 numIoctrls;
120     NvU32 numLinksPerIoctrl;
121     NvU32 numActiveLinksPerIoctrl;
122 
123     //
124     // boolean indicating if a given device
125     // is a reduced nvlink config
126     //
127     NvBool bReducedNvlinkConfig;
128 
129     // Client private information
130     void *pDevInfo;
131 };
132 
133 // nvlink link change type
134 enum nvlink_link_change_type
135 {
136     nvlink_retrain_from_off,
137     nvlink_retrain_from_safe,
138 
139 };
140 
141 // nvlink link_change parameters
142 struct nvlink_link_change
143 {
144     struct nvlink_link *master;
145     struct nvlink_link *slave;
146 
147     enum nvlink_link_change_type change_type;
148 };
149 
150 //
151 // Structure representing Nvlink Error Threshold
152 //
153 struct nvlink_link_error_threshold
154 {
155     NvU8 thresholdMan;
156     NvU8 thresholdExp;
157     NvU8 timescaleMan;
158     NvU8 timescaleExp;
159     NvBool bInterruptEn;
160     NvBool bUserConfig;
161     NvBool bInterruptTrigerred; // Error threshold interrupt generated
162 };
163 
164 // nvlink link state
165 struct nvlink_link
166 {
167     NVListRec node;
168 
169     // Device the link is associated with
170     struct nvlink_device *dev;
171 
172     // Lock for per link structure
173     void *linkLock;
174 
175     // Uniquely identifies a link in the core
176     NvU64 linkId;
177 
178     // If this link is the master of its connection
179     NvBool master;
180 
181     // Client supplied link name and number
182     char  *linkName;
183     NvU32 linkNumber;
184 
185     NvU64 token;
186 
187     // Link state
188     NvU32 state;
189     NvBool inSWCFG;
190 
191     // Sublink states
192     NvU32 tx_sublink_state;
193     NvU32 rx_sublink_state;
194 
195     // Has rceiver detect passed
196     NvBool bRxDetected;
197 
198     // Link failed when sending InitPll to minion
199     NvBool bTxCommonModeFail;
200 
201     // Link failed when transitioning to SWCFG
202     NvBool bSafeTransitionFail;
203 
204     // Link failed when sending INITPHASE5 to minion
205     NvBool bInitphase5Fails;
206 
207     // IP version
208     NvU32 version;
209 
210     // Has state been saved
211     NvBool bStateSaved;
212 
213     // Number of retries to put link to safe
214     NvU32 safe_retries;
215 
216     // Set if LINK is ac coupled
217     NvBool ac_coupled;
218 
219     // Number of retries to discover the other end of the link
220     NvU32 packet_injection_retries;
221 
222     // Local Sid of the link.
223     NvU64 localSid;
224 
225     // Remote Sid of the link.
226     NvU64 remoteSid;
227 
228     // Remote LinkId to which the current link is connected.
229     NvU32 remoteLinkId;
230 
231     NvU32 remoteDeviceType;
232 
233     // Has INITNEGOTIATE received CONFIG_GOOD (NVL3.0+)
234     NvBool bInitnegotiateConfigGood;
235 
236     // Power state transition status
237     enum
238     {
239         nvlink_power_state_in_L0,
240         nvlink_power_state_entering_L2,
241         nvlink_power_state_in_L2,
242         nvlink_power_state_exiting_L2
243     } powerStateTransitionStatus;
244 
245     // Link handlers
246     const struct nvlink_link_handlers *link_handlers;
247 
248     // Client private information
249     void *link_info;
250 
251     // Outstanding link change request information
252     struct nvlink_link_change link_change;
253 
254     //seed data for given nvlink
255     NvU32 seedData[NVLINK_MAX_SEED_BUFFER_SIZE];
256 
257     struct nvlink_link_error_threshold errorThreshold;
258 };
259 
260 // nvlink link handler ops
261 struct nvlink_link_handlers
262 {
263     NV_API_CALL NvlStatus (*add)                        (struct nvlink_link *link);
264     NV_API_CALL NvlStatus (*remove)                     (struct nvlink_link *link);
265     NV_API_CALL NvlStatus (*lock)                       (struct nvlink_link *link);
266     NV_API_CALL void      (*unlock)                     (struct nvlink_link *link);
267     NV_API_CALL NvlStatus (*queue_link_change)          (struct nvlink_link_change *link_change);
268     NV_API_CALL NvlStatus (*set_dl_link_mode)           (struct nvlink_link *link, NvU64  mode, NvU32 flags);
269     NV_API_CALL NvlStatus (*get_dl_link_mode)           (struct nvlink_link *link, NvU64 *mode);
270     NV_API_CALL NvlStatus (*set_tl_link_mode)           (struct nvlink_link *link, NvU64  mode, NvU32 flags);
271     NV_API_CALL NvlStatus (*get_tl_link_mode)           (struct nvlink_link *link, NvU64 *mode);
272     NV_API_CALL NvlStatus (*set_tx_mode)                (struct nvlink_link *link, NvU64  mode, NvU32 flags);
273     NV_API_CALL NvlStatus (*get_tx_mode)                (struct nvlink_link *link, NvU64 *mode, NvU32 *subMode);
274     NV_API_CALL NvlStatus (*set_rx_mode)                (struct nvlink_link *link, NvU64  mode, NvU32 flags);
275     NV_API_CALL NvlStatus (*get_rx_mode)                (struct nvlink_link *link, NvU64 *mode, NvU32 *subMode);
276     NV_API_CALL NvlStatus (*set_rx_detect)              (struct nvlink_link *link, NvU32 flags);
277     NV_API_CALL NvlStatus (*get_rx_detect)              (struct nvlink_link *link);
278     NV_API_CALL NvlStatus (*write_discovery_token)      (struct nvlink_link *link, NvU64  token);
279     NV_API_CALL NvlStatus (*read_discovery_token)       (struct nvlink_link *link, NvU64 *token);
280     NV_API_CALL void      (*training_complete)          (struct nvlink_link *link);
281     NV_API_CALL void      (*get_uphy_load)              (struct nvlink_link *link, NvBool* bUnlocked);
282     NV_API_CALL NvlStatus (*ali_training)               (struct nvlink_link *link);
283 };
284 
285 //
286 // Represents an intranode connections in single/multi-node system.
287 // Both endpoints of the connection is visible from same node.
288 //
289 struct nvlink_intranode_conn
290 {
291     NVListRec node;
292     struct nvlink_link *end0;
293     struct nvlink_link *end1;
294 };
295 
296 //
297 // Represents internode connections in a multi-node system.
298 // One of the endpoint of the connection must be a local link.
299 //
300 struct nvlink_internode_conn
301 {
302     NVListRec                    node;
303     struct nvlink_link          *local_end;
304     nvlink_remote_endpoint_info  remote_end;
305 };
306 
307 
308 // Typedefs
309 typedef struct nvlink_device           nvlink_device;
310 typedef struct nvlink_device_handle    nvlink_device_handle;
311 typedef struct nvlink_link             nvlink_link;
312 typedef struct nvlink_link_change      nvlink_link_change;
313 typedef struct nvlink_device_handlers  nvlink_device_handlers;
314 typedef struct nvlink_link_handlers    nvlink_link_handlers;
315 typedef struct nvlink_intranode_conn   nvlink_intranode_conn;
316 typedef struct nvlink_internode_conn   nvlink_internode_conn;
317 typedef enum   nvlink_link_change_type nvlink_link_change_type;
318 typedef struct nvlink_inband_data      nvlink_inband_data;
319 
320 
321 #define NVLINK_MAX_NUM_SAFE_RETRIES                 7
322 #define NVLINK_MAX_NUM_PACKET_INJECTION_RETRIES     4
323 
324 
325 // NVLINK LINK states
326 #define NVLINK_LINKSTATE_OFF                            0x00   // OFF
327 #define NVLINK_LINKSTATE_HS                             0x01   // High Speed
328 #define NVLINK_LINKSTATE_SAFE                           0x02   // Safe/Discovery State
329 #define NVLINK_LINKSTATE_FAULT                          0x03   // Faulty
330 #define NVLINK_LINKSTATE_RECOVERY                       0x04   // Recovery
331 #define NVLINK_LINKSTATE_FAIL                           0x05   // Unconnected/Fail
332 #define NVLINK_LINKSTATE_DETECT                         0x06   // Detect mode
333 #define NVLINK_LINKSTATE_RESET                          0x07   // Reset
334 #define NVLINK_LINKSTATE_ENABLE_PM                      0x08   // Enable Link Power Management
335 #define NVLINK_LINKSTATE_DISABLE_PM                     0x09   // Disable Link Power Management
336 #define NVLINK_LINKSTATE_SLEEP                          0x0A   // Sleep (L2)
337 #define NVLINK_LINKSTATE_SAVE_STATE                     0x0B   // Save state while entering L2
338 #define NVLINK_LINKSTATE_RESTORE_STATE                  0x0C   // Restore state while exiting L2
339 #define NVLINK_LINKSTATE_PRE_HS                         0x0E   // Settings before moving to High Speed
340 #define NVLINK_LINKSTATE_DISABLE_ERR_DETECT             0x0F   // Disable Error detection (interrupt)
341 #define NVLINK_LINKSTATE_LANE_DISABLE                   0x10   // Disable Lanes
342 #define NVLINK_LINKSTATE_LANE_SHUTDOWN                  0x11   // Shutdown Lanes in PHY
343 #define NVLINK_LINKSTATE_TRAFFIC_SETUP                  0x12   // Setup traffic flow after ACTIVE
344 #define NVLINK_LINKSTATE_INITPHASE1                     0x13   // INITPHASE1
345 #define NVLINK_LINKSTATE_INITNEGOTIATE                  0x14   // Initialize the negotiation (Ampere And Later)
346 #define NVLINK_LINKSTATE_POST_INITNEGOTIATE             0x15   // Sends DL stat
347 #define NVLINK_LINKSTATE_INITOPTIMIZE                   0x16   // INITOPTIMIZE
348 #define NVLINK_LINKSTATE_POST_INITOPTIMIZE              0x17   // POST INITOPTIMIZE DL stat check
349 #define NVLINK_LINKSTATE_DISABLE_HEARTBEAT              0x18   // Disables the heartbeat errors
350 #define NVLINK_LINKSTATE_CONTAIN                        0x19   // TL is in contain mode
351 #define NVLINK_LINKSTATE_INITTL                         0x1A   // INITTL
352 #define NVLINK_LINKSTATE_INITPHASE5                     0x1B   // INITPHASE5
353 #define NVLINK_LINKSTATE_ALI                            0x1C   // ALI
354 #define NVLINK_LINKSTATE_ACTIVE_PENDING                 0x1D   // Intermediate state for a link going to active
355 #define NVLINK_LINKSTATE_INVALID                        0xFF   // Invalid state
356 
357 // NVLINK TX SUBLINK states
358 #define NVLINK_SUBLINK_STATE_TX_HS                      0x0   // TX High Speed
359 #define NVLINK_SUBLINK_STATE_TX_SINGLE_LANE             0x4   // TX Single Lane (1/8th or 1/4th) Mode (Deprecated)
360 #define NVLINK_SUBLINK_STATE_TX_LOW_POWER               0x4   // TX Single Lane Mode / L1
361 #define NVLINK_SUBLINK_STATE_TX_TRAIN                   0x5   // TX training
362 #define NVLINK_SUBLINK_STATE_TX_SAFE                    0x6   // TX Safe Mode
363 #define NVLINK_SUBLINK_STATE_TX_OFF                     0x7   // TX OFF
364 #define NVLINK_SUBLINK_STATE_TX_COMMON_MODE             0x8   // TX common mode enable
365 #define NVLINK_SUBLINK_STATE_TX_COMMON_MODE_DISABLE     0x9   // TX common mode disable
366 #define NVLINK_SUBLINK_STATE_TX_DATA_READY              0xA   // Do Data Ready and Data Enable
367 #define NVLINK_SUBLINK_STATE_TX_EQ                      0xB   // TX equalization
368 #define NVLINK_SUBLINK_STATE_TX_PRBS_EN                 0xC   // TX IOBIST PRBS generator enable
369 #define NVLINK_SUBLINK_STATE_TX_POST_HS                 0xD   // TX Post High Speed settings
370 
371 // NVLINK RX SUBLINK states
372 #define NVLINK_SUBLINK_STATE_RX_HS                      0x0   // RX High Speed
373 #define NVLINK_SUBLINK_STATE_RX_SINGLE_LANE             0x4   // RX Single Lane (1/8th or 1/4th) Mode (Deprecated)
374 #define NVLINK_SUBLINK_STATE_RX_LOW_POWER               0x4   // RX Single Lane Mode / L1
375 #define NVLINK_SUBLINK_STATE_RX_TRAIN                   0x5   // RX training
376 #define NVLINK_SUBLINK_STATE_RX_SAFE                    0x6   // RX Safe Mode
377 #define NVLINK_SUBLINK_STATE_RX_OFF                     0x7   // RX OFF
378 #define NVLINK_SUBLINK_STATE_RX_RXCAL                   0x8   // RX in calibration
379 #define NVLINK_SUBLINK_STATE_RX_INIT_TERM               0x9   // Enable RX termination
380 
381 // NVLINK TX SUBLINK sub-states
382 #define NVLINK_SUBLINK_SUBSTATE_TX_STABLE               0x0   // TX Stable
383 
384 // NVLINK RX SUBLINK sub-states
385 #define NVLINK_SUBLINK_SUBSTATE_RX_STABLE               0x0   // RX Stable
386 
387 // State change flags
388 #define NVLINK_STATE_CHANGE_ASYNC                       0x0   // Don't wait for the state change to complete
389 #define NVLINK_STATE_CHANGE_SYNC                        0x1   // Wait for the state change to complete
390 
391 
392 /************************************************************************************************/
393 /***************************** NVLink library management functions ******************************/
394 /************************************************************************************************/
395 
396 /*
397  * Check if the nvlink core library is initialized
398  */
399 NvBool nvlink_lib_is_initialized(void);
400 
401 /*
402  * Check if there are no devices registered
403  */
404 NvBool nvlink_lib_is_device_list_empty(void);
405 
406 /*
407  * Get if a device registerd to the nvlink corelib has a reduced nvlink config
408  */
409 NvBool nvlink_lib_is_registerd_device_with_reduced_config(void);
410 
411 /************************************************************************************************/
412 /************************** NVLink library driver-side interface ********************************/
413 /***************** Manages device and link registration and un-registration *********************/
414 /************************************************************************************************/
415 
416 /*
417  * Associates device in the NVLink Core
418  * During the call, the calling driver must support callbacks into the driver from Core
419  */
420 NvlStatus nvlink_lib_register_device(nvlink_device *dev);
421 
422 /*
423  * Unassociates device in the NVLink Core
424  * Includes removing any links related to the device if still registered
425  * During the call, the calling driver must support callbacks into the driver from Core
426  */
427 NvlStatus nvlink_lib_unregister_device(nvlink_device *dev);
428 
429 
430 /*
431  * Associates link with a device in the NVLink Core
432  * During the call, the calling driver must support callbacks into the driver from Core
433  */
434 NvlStatus nvlink_lib_register_link(nvlink_device *dev, nvlink_link *link);
435 
436 /*
437  * Unassociates link from a device in the NVLink Core
438  * During the call, the calling driver must support callbacks into the driver from Core
439  */
440 NvlStatus nvlink_lib_unregister_link(nvlink_link *link);
441 
442 /*
443 * Gets number of devices with type deviceType
444 */
445 NvlStatus nvlink_lib_return_device_count_by_type(NvU32 deviceType, NvU32 *numDevices);
446 
447 
448 /************************************************************************************************/
449 /******************************* NVLink link management functions *******************************/
450 /************************************************************************************************/
451 
452 /*
453  * Check if the device has no links registered
454  */
455 NvBool nvlink_lib_is_link_list_empty(nvlink_device *dev);
456 
457 /*
458  * Get the link associated with the given device's link number
459  */
460 NvlStatus nvlink_lib_get_link(nvlink_device  *device,
461                               NvU32           link_id,
462                               nvlink_link   **link);
463 
464 /*
465  * Set the link endpoint as the link master
466  */
467 NvlStatus nvlink_lib_set_link_master(nvlink_link *link);
468 
469 /*
470  * Get the link master associated with this endpoint
471  */
472 NvlStatus nvlink_lib_get_link_master(nvlink_link *link, nvlink_link **master);
473 
474 /*
475  * Set the training state for the given link as non-ALI or ALI
476  */
477 NvlStatus nvlink_lib_link_set_training_mode(nvlink_link *link, NvBool enableALI);
478 
479 /************************************************************************************************/
480 /*************************** NVLink topology discovery functions ********************************/
481 /************************************************************************************************/
482 
483 /*
484  * Get the connected remote endpoint information
485  *   For a given link, return the other endpoint details it is connected
486  *   to. If there is no connection associated with the given link, then
487  *   conn_info.connected member will be NV_FALSE.
488  *
489  *   Note: This routine will not initiate any link initialization or topology
490  *   discovery.
491  */
492 NvlStatus nvlink_lib_get_remote_conn_info(nvlink_link *link, nvlink_conn_info *conn_info);
493 
494 /*
495  * Get the connected remote endpoint information
496  *   For a given end of a link, returns the device and link information
497  *   for the remote end along with a boolean variable that specifies if
498  *   the topology detection was complete
499  */
500 NvlStatus nvlink_lib_discover_and_get_remote_conn_info(nvlink_link      *end,
501                                                        nvlink_conn_info *conn_info,
502                                                        NvU32             flags);
503 
504 
505 /************************************************************************************************/
506 /****************************** NVLink initialization functions *********************************/
507 /************************************************************************************************/
508 
509 /*
510  * Re-init a given link from OFF to SWCFG
511  */
512 NvlStatus nvlink_lib_reinit_link_from_off_to_swcfg(nvlink_link *link,
513                                                    NvU32        flags);
514 
515 /************************************************************************************************/
516 /********************************** NVLink training functions ***********************************/
517 /************************************************************************************************/
518 
519 /*
520  * Train a given set of links from SWCFG to ACTIVE state
521  *    a. For low training latency - caller passes all links as an array
522  *    b. For high training latency - caller passes link one by one
523  */
524 NvlStatus nvlink_lib_train_links_from_swcfg_to_active(nvlink_link **links,
525                                                       NvU32         linkCount,
526                                                       NvU32         flags);
527 
528 /*
529  * Train a given set of links of a device from L2 to ACTIVE state
530  */
531 NvlStatus nvlink_lib_train_links_from_L2_to_active(nvlink_device *dev,
532                                                    NvU32          linkMask,
533                                                    NvU32          flags);
534 
535 /*
536  * Retrain a given link from SWCFG to ACTIVE
537  */
538 NvlStatus nvlink_lib_retrain_link_from_swcfg_to_active(nvlink_link *link,
539                                                        NvU32        flags);
540 
541 /*
542  * Save the seed Data passed in from an endpoint driver
543 */
544 NvlStatus nvlink_lib_save_training_seeds(nvlink_link * link,
545                                          NvU32 *       seedData);
546 NvlStatus nvlink_lib_copy_training_seeds(nvlink_link * link,
547                                          NvU32 * seedDataCopy);
548 
549 /*
550  * Send the endpoint driver back the seeds we have stored
551 */
552 void nvlink_lib_restore_training_seeds(nvlink_link * link,
553                                        NvU32 *       seedData);
554 
555 /*
556  * Check that the requested links have trained to active
557 */
558 NvlStatus nvlink_lib_check_training_complete(nvlink_link **links,
559                                              NvU32 linkCount);
560 
561 
562 /************************************************************************************************/
563 /********************************** NVLink shutdown functions ***********************************/
564 /************************************************************************************************/
565 
566 /*
567  * [CLEAN SHUTDOWN]
568  * Shutdown given links of a device from active to L2 state
569  */
570 NvlStatus nvlink_lib_powerdown_links_from_active_to_L2(nvlink_device *dev,
571                                                        NvU32          linkMask,
572                                                        NvU32          flags);
573 
574 /*
575  * [PSEUDO-CLEAN SHUTDOWN]
576  * Shutdown the given array of links from ACTIVE to OFF state
577  */
578 NvlStatus nvlink_lib_powerdown_links_from_active_to_off(nvlink_link **links,
579                                                         NvU32         numLinks,
580                                                         NvU32         flags);
581 
582 /*
583  * Power down the given array of links from ACTIVE to SWCFG state
584  */
585 NvlStatus nvlink_lib_powerdown_links_from_active_to_swcfg(nvlink_link **links,
586                                                           NvU32         numLinks,
587                                                           NvU32         flags);
588 
589 /*
590  * Reset the given array of links
591  */
592 NvlStatus nvlink_lib_reset_links(nvlink_link **links,
593                                  NvU32         numLinks,
594                                  NvU32         flags);
595 
596 /*
597  * Floorsweep the necessary links and set buffer ready on the active links
598  */
599 NvlStatus nvlink_lib_powerdown_floorswept_links_to_off(nvlink_device *pDevice);
600 
601 
602 /*
603  * Nvlink core library structure iterators
604  */
605 
606 #define FOR_EACH_DEVICE_REGISTERED(dev, head, node)  \
607         nvListForEachEntry(dev, &head.node, node)
608 
609 #define FOR_EACH_LINK_REGISTERED(link, dev, node)    \
610         nvListForEachEntry(link, &dev->link_list, node)
611 
612 #define FOR_EACH_LINK_REGISTERED_SAFE(link, next, dev, node)       \
613         nvListForEachEntry_safe(link, next, &dev->link_list, node)
614 
615 #define FOR_EACH_CONNECTION(conn, head, node)        \
616         nvListForEachEntry(conn, &head.node, node)
617 
618 #ifdef __cplusplus
619 }
620 #endif
621 
622 #endif // _NVLINK_H_
623