socdiag-nsa.c (4570B)
1 /* 2 * 3 * This license is set out in https://raw.githubusercontent.com/Broadcom-Network-Switching-Software/OpenBCM/master/Legal/LICENSE file. 4 * 5 * Copyright 2007-2019 Broadcom Inc. All rights reserved. 6 */ 7 #ifdef NO_SAL_APPL 8 9 /****************************************************************************** 10 * 11 * About NO_SAL_APPL mode 12 * 13 * This configuration is built with NO_SAL_APPL defined. 14 * 15 * In this build configuration, the Application SAL is not required to be compiled 16 * or ported to the target operating system/environment. 17 * 18 * There are 4 functions you must provide to hook the diag shell up to your 19 * environment. These 4 functions are documented below. 20 * They are also implemented for the simulation target. 21 * 22 * You should provide your own implementation of these functions 23 * to import the diag shell into your environment. 24 */ 25 26 /* 27 * Function: 28 * sal_portable_vprintf 29 * Purpose: 30 * Printf function used by the diag shell. 31 * Parameters: 32 * fmt -- format string 33 * vargs -- va_list 34 * 35 * Notes: 36 * Required for output from the shell 37 * 38 * A version compatible with unix is provided here for 39 * the simulator build. Provide your own in your environment. 40 */ 41 #include <shared/bsl.h> 42 43 #include <stdarg.h> /* for va_list */ 44 #include <stdio.h> /* for vprintf */ 45 #include <sal/appl/io.h> /* for prototype for these functions */ 46 47 int 48 sal_portable_vprintf(const char* fmt, va_list vargs) 49 { 50 return vprintf(fmt, vargs); 51 } 52 53 54 55 /* 56 * Function: 57 * sal_portable_readline 58 * Purpose: 59 * Retrieve an input line for the diag shell. 60 * Parameters: 61 * prompt -- prompt to be printed to the user at the input line 62 * buf -- receive buffer for the line 63 * bufsize -- maximum size of the receive buffer 64 * Returns: 65 * buf 66 * 67 * Notes: 68 * Required for input to the diag shell. 69 * If you are only calling sh_process_command() and not 70 * the diag shell input loop, this function will never get called 71 * and you can just return NULL. 72 */ 73 74 extern char* 75 sal_portable_readline(char *prompt, char *buf, int bufsize) 76 { 77 if(prompt) { 78 printf("%s", prompt); 79 } 80 if(buf && bufsize > 0) { 81 buf[0] = 0; 82 fgets(buf, bufsize, stdin); 83 if(buf[strlen(buf)-1] == '\n') { 84 buf[strlen(buf)-1] = 0; 85 } 86 } 87 return buf; 88 } 89 90 91 /****************************************************************************** 92 * 93 * END OF PORTABILITY FUNCTIONS FOR BCM_PORTABLE_DIAG_MODE 94 */ 95 96 97 98 99 /****************************************************************************** 100 * 101 * The rest of this file is concerned with providing an actual system main 102 * application using the diag shell in portability mode. 103 * 104 * These are specific to the simulator platform and are not part of the 105 * portability functions required and described above. 106 */ 107 108 #include <unistd.h> 109 #include <appl/diag/system.h> /* diag_shell */ 110 #include <sal/appl/pci.h> /* pci_device_iter */ 111 #include <bde/pli/plibde.h> /* bde_create */ 112 113 ibde_t *bde; 114 115 int 116 bde_create(void) 117 { 118 return plibde_create(&bde); 119 } 120 121 /* 122 * Main loop. 123 */ 124 int main(int argc, char *argv[]) 125 { 126 if (sal_core_init()) { 127 LOG_CLI((BSL_META("SAL Core Initialization failed\n"))); 128 exit(1); 129 } 130 131 LOG_CLI((BSL_META("Broadcom Command Monitor: (NO_SAL_APPL build)\n" 132 "Copyright (c) 1998-2010 Broadcom Corp.\n"))); 133 LOG_CLI((BSL_META("Version %s built %s\n"), _build_release, _build_date)); 134 135 diag_shell(); 136 137 return 0; 138 } 139 140 141 /* 142 * This function needed by the plibde implementation only 143 */ 144 145 #ifndef PCI_MAX_DEV 146 #define PCI_MAX_DEV 32 147 #endif 148 149 #ifndef PCI_MAX_BUS 150 #define PCI_MAX_BUS 1 151 #endif 152 153 int 154 pci_device_iter(int (*rtn)(pci_dev_t *dev, 155 uint16 pciVenID, 156 uint16 pciDevID, 157 uint8 pciRevID)) 158 { 159 uint32 venID, devID, revID; 160 int rv = 0; 161 pci_dev_t dev; 162 163 dev.funcNo = 0; 164 165 for (dev.busNo = 0; 166 dev.busNo < PCI_MAX_BUS && rv == 0; 167 dev.busNo++) { 168 169 for (dev.devNo = 0; 170 dev.devNo < PCI_MAX_DEV && rv == 0; 171 dev.devNo++) { 172 173 if (dev.devNo == 12) { 174 continue; 175 } 176 177 /* NOTE -- pci_config_getw exported by plibde (not appl sal) in this case */ 178 venID = pci_config_getw(&dev, PCI_CONF_VENDOR_ID) & 0xffff; 179 180 if (venID == 0xffff) { 181 continue; 182 } 183 184 devID = pci_config_getw(&dev, PCI_CONF_VENDOR_ID) >> 16; 185 revID = pci_config_getw(&dev, PCI_CONF_REVISION_ID) & 0xff; 186 187 rv = (*rtn)(&dev, venID, devID, revID); 188 } 189 } 190 191 return rv; 192 } 193 194 195 #endif /* NO_SAL_APPL */