openbcm

Git mirror of https://github.com/Broadcom-Network-Switching-Software/OpenBCM
git clone git://git.finwo.net/mirror/broadcom/openbcm
Log | Files | Refs | README

pcitest.c (8650B)


      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  * PCI Tests
      8  */
      9 
     10 #include <shared/bsl.h>
     11 
     12 #include <sal/types.h>
     13 #include <shared/bsl.h>
     14 #include <appl/diag/system.h>
     15 #include <appl/diag/parse.h>
     16 #include <soc/debug.h>
     17 #include <sal/appl/pci.h>
     18 #include <ibde.h>
     19 #include "testlist.h"
     20 
     21 #if defined (BCM_ESW_SUPPORT) || defined (BCM_DFE_SUPPORT) || defined (BCM_PETRA_SUPPORT) || defined (BCM_DNX_SUPPORT) || defined (BCM_DNXF_SUPPORT)
     22 
     23 /*
     24  * These numbers need to be chosen not to conflict with other read data
     25  * in pca table.  Chip specific values are substituted for them in
     26  * setup_pca_table.
     27  */
     28 #define	DEVID	0x12
     29 #define	VENID	0x13
     30 #define	REVID	0x14
     31 #define	ID	0x15	/* 0xff00ffff to accommodate bondouts */
     32 
     33 #define	ILINE	0
     34 #define	IPIN	(PCI_INTERRUPT_A << 8)
     35 
     36 typedef struct pci_config_addr_s {
     37     uint32	pca_flags;		/* Flags - see below */
     38 #   define	RD	0x01		/* Do read */
     39 #   define	WR	0x02		/* Do write */
     40     uint32	pca_addr;		/* Address to muck with */
     41     uint32	pca_write;		/* Write Value */
     42     uint32	pca_read;		/* Expected read value */
     43     uint32	pca_read_mask;		/* Mask actual read with this */
     44 } pca_t;
     45 
     46 typedef struct pt_s {
     47 #   define	PT_REGS ((int)((PCI_CONF_MAX_LATENCY + 3) / sizeof(uint32)))
     48     uint32	pt_config[PT_REGS];
     49 } pt_t;
     50 
     51 pt_t	pt_config[SOC_MAX_NUM_DEVICES];
     52 
     53 static const pca_t	pca_table_fixed[] = {
     54 /* read/write	Config Address      w-data     r-data 	 	Mask	   */
     55 /* -----------+------------------+------------+--------------+------------ */
     56 
     57     /* Test Device/Vendor ID for Read/Write */
     58 
     59     {RD, 	PCI_CONF_VENDOR_ID,	0,		VENID,		0x0000ffff},
     60     /* High byte of DEVID only, to accommodate different bond-outs */
     61     {RD, 	PCI_CONF_VENDOR_ID,	0,		DEVID,		0xff000000},
     62     {RD+WR,	PCI_CONF_VENDOR_ID,	0xaaaaaaaa,	ID,		0xff00ffff},
     63     {RD+WR,	PCI_CONF_VENDOR_ID,	0x55555555,	ID,		0xff00ffff},
     64     {RD+WR,	PCI_CONF_VENDOR_ID,	0xffffffff,	ID,		0xff00ffff},
     65     {RD+WR,	PCI_CONF_VENDOR_ID,	0x00000000,	ID,		0xff00ffff},
     66 
     67     /* Test MBAR0 - should be 64K + anywhere in 64-bit space */
     68 
     69     /* {RD+WR,	PCI_CONF_BASE0,	   0xffffffff,	0xffff0004,	0xffffffff},*/
     70 
     71     /* Class Code and revision for Read Only */
     72     /* Excludes metal-spin portion of Rev ID (lower 4 bits) */
     73 
     74     {RD, 	PCI_CONF_REVISION_ID,	   0,		REVID,		0xff7fffff},
     75     {RD+WR, 	PCI_CONF_REVISION_ID,	   0,		REVID,		0xff7fffff},
     76     {RD+WR, 	PCI_CONF_REVISION_ID,	   0x55555555,	REVID,		0xff7fffff},
     77     {RD+WR, 	PCI_CONF_REVISION_ID,	   0xaaaaaaaa,	REVID,		0xff7fffff},
     78     {RD+WR, 	PCI_CONF_REVISION_ID,	   0xffffffff,	REVID,		0xff7fffff},
     79 
     80     /* Int pin indication */
     81 
     82     {RD, 	PCI_CONF_INTERRUPT_LINE,	   0,		IPIN,		0xff00},
     83     {RD+WR, 	PCI_CONF_INTERRUPT_LINE,	   0,		IPIN,		0xff00},
     84     {RD+WR, 	PCI_CONF_INTERRUPT_LINE,	   0x55555555,	IPIN,		0xff00},
     85     {RD+WR, 	PCI_CONF_INTERRUPT_LINE,	   0xaaaaaaaa,	IPIN,		0xff00},
     86     {RD+WR, 	PCI_CONF_INTERRUPT_LINE,	   0xffffffff,	IPIN,		0xff00},
     87 
     88     /* Interrupt line assignment */
     89 
     90     {RD+WR, 	PCI_CONF_INTERRUPT_LINE,	   0,		0,		0xff},
     91     {RD+WR, 	PCI_CONF_INTERRUPT_LINE,	   0,		0,		0xff},
     92     {RD+WR, 	PCI_CONF_INTERRUPT_LINE,	   0x55555555,	0x55,		0xff},
     93     {RD+WR, 	PCI_CONF_INTERRUPT_LINE,	   0xaaaaaaaa,	0xaa,		0xff},
     94     {RD+WR, 	PCI_CONF_INTERRUPT_LINE,	   0xffffffff,	0xff,		0xff}
     95 };
     96 
     97 static int pca_cnt = COUNTOF(pca_table_fixed);
     98 static pca_t pca_table[COUNTOF(pca_table_fixed)];
     99 
    100 /*
    101  * Function to set up a chips expected PCI table for testing
    102  */
    103 
    104 /*Override pci test parameters if required*/
    105 static void
    106 pci_test_params_override(int unit, uint16 *vendor_id, uint16 *dev_id, uint8 *rev_id)
    107 {
    108 
    109 #ifdef BCM_88754_A0
    110     if (SOC_IS_BCM88754_A0(unit)) {
    111         *vendor_id = BCM88754_ORIGINAL_VENDOR_ID;
    112         *dev_id = BCM88754_ORIGINAL_DEVICE_ID;
    113         *rev_id = BCM88754_A0_ORIGINAL_REV_ID;
    114     }
    115 #endif /*BCM_88754_A0*/
    116 
    117 }
    118 
    119 static void
    120 setup_pca_table(int unit)
    121 {
    122     int i;
    123     uint16 dev_id;
    124     uint8 rev_id;
    125     uint16 vendor_id;
    126 
    127     /* Get the real chip ID, as opposed to driver chip ID */
    128     soc_cm_get_id(unit, &dev_id, &rev_id);
    129     vendor_id = SOC_PCI_VENDOR(unit);
    130 
    131 
    132     /*Override pci test parameters if required*/
    133     pci_test_params_override(unit, &vendor_id, &dev_id, &rev_id);
    134 
    135     memcpy(pca_table, pca_table_fixed, sizeof(pca_table_fixed));
    136     for (i=0; i<pca_cnt; i++) {
    137         switch (pca_table_fixed[i].pca_read) {
    138         case VENID:
    139             pca_table[i].pca_read = vendor_id;
    140             break;
    141         case DEVID:
    142 	    /* High byte only (see comment above) */
    143             pca_table[i].pca_read = (dev_id << 16) & 0xff000000;
    144             if (soc_property_get_str(unit, spn_PCI_OVERRIDE_DEV) != NULL) {
    145                 /* Ignore if PCI DEV ID override configured */
    146                 pca_table[i].pca_read &= ~0xFFFF0000;
    147                 pca_table[i].pca_read_mask &= ~0xFFFF0000;
    148             }
    149             break;
    150         case REVID:
    151             pca_table[i].pca_read = (rev_id | PCI_NETWORK_CLASS_ID << 8);
    152             if (soc_property_get_str(unit, spn_PCI_OVERRIDE_REV) != NULL) {
    153                 /* Ignore if PCI REV ID override configured */
    154                 pca_table[i].pca_read &= ~0x000000FF;
    155                 pca_table[i].pca_read_mask &= ~0x000000FF;
    156             }
    157             pca_table[i].pca_read &= pca_table[i].pca_read_mask;
    158             break;
    159         case ID:
    160             pca_table[i].pca_read =
    161 		((dev_id << 16) |
    162 		 (vendor_id)) & 0xff00ffff;
    163             if (soc_property_get_str(unit, spn_PCI_OVERRIDE_DEV) != NULL) {
    164                 /* Ignore if PCI DEV ID override configured */
    165                 pca_table[i].pca_read &= ~0xFFFF0000;
    166                 pca_table[i].pca_read_mask &= ~0xFFFF0000;
    167             }
    168             break;
    169         }
    170     }
    171 }
    172 
    173 
    174 int
    175 pci_test(int u, args_t *a, void *pa)
    176 /*
    177  * Function: 	pci_test
    178  * Purpose:	Test basic PCI stuff on StrataSwitch.
    179  * Parameters:	u - unit #.
    180  *		a - pointer to arguments.
    181  *		pa - ignored cookie.
    182  * Returns:	0
    183  */
    184 {
    185     int		i;
    186 
    187     COMPILER_REFERENCE(a);
    188     COMPILER_REFERENCE(pa);
    189 
    190     setup_pca_table(u);
    191 
    192 
    193     for (i = 0; i < pca_cnt; i++) {
    194 	pca_t *p = &pca_table[i];
    195 	uint32	read_val;
    196 
    197 	/* If write - do write first */
    198 
    199 	if (p->pca_flags & WR) {
    200 	    LOG_VERBOSE(BSL_LS_APPL_TESTS,
    201                         (BSL_META_U(u,
    202                                     "Writing PCI Config 0x%x <--- 0x%x\n"),
    203                          p->pca_addr, p->pca_write));
    204 	    if (bde->pci_conf_write(u, p->pca_addr, p->pca_write)){
    205 		test_error(u, "PCI config write failed to address: 0x%x\n",
    206 			   p->pca_addr);
    207 		continue;		/* If test error returns */
    208 	    }
    209 	}
    210 	read_val = bde->pci_conf_read(u, p->pca_addr);
    211 	read_val &= p->pca_read_mask;
    212 	LOG_VERBOSE(BSL_LS_APPL_TESTS,
    213                     (BSL_META_U(u,
    214                                 "Reading PCI Config (Masked) 0x%x --> 0x%x\n"), 
    215                      p->pca_addr, read_val));
    216 	if (read_val != p->pca_read) {
    217 	    test_error(u, "PCI Config @0x%x Read 0x%x expected 0x%x\n",
    218 		       p->pca_addr, read_val, p->pca_read);
    219 	}
    220     }
    221 
    222     return(0);
    223 }
    224 
    225 /*ARGSUSED*/
    226 int
    227 pci_test_done(int u, void *pa)
    228 /*
    229  * Function: 	pci_test_done
    230  * Purpose:	Restore all values to CMIC from soc structure.
    231  * Parameters:	u - unit #
    232  *		pa - cookie (Ignored)
    233  * Returns:	0 - OK
    234  *		-1 - failed
    235  */
    236 {
    237     pt_t	*pt;
    238     int		i;
    239     int		rv = 0;
    240 
    241     if (!pa) {		/* Never got far enough --- just return success */
    242 	return(0);
    243     }
    244     pt = (pt_t *)pa;
    245 
    246     for (i = 0; i < PT_REGS; i++) {      
    247       rv |= bde->pci_conf_write(u, i * 4, pt->pt_config[i]);
    248     }
    249     return(rv);
    250 }
    251 
    252 int
    253 pci_test_init(int u, args_t *a, void **pa)
    254 /*
    255  * Function: 	pci_test_init
    256  * Purpose:	Save all the current PCI Config registers to write
    257  *		on completion.
    258  * Parameters:	u - unit #
    259  *		a - pointer to args
    260  *		pa - Pointer to cookie
    261  * Returns:	0 - success, -1 - failed.
    262  */
    263 {
    264     pt_t	*pt = &pt_config[u];
    265     int		i;
    266 
    267     if (ARG_CNT(a)) {
    268 	test_error(u, "Arguments not supported\n");
    269 	return -1;
    270     }
    271 
    272     for (i = 0; i < PT_REGS; i++) {
    273 	pt->pt_config[i] = bde->pci_conf_read(u, i * 4);
    274     }
    275     *pa = pt;
    276     return(0);
    277 }
    278 
    279 int
    280 pci_sch_test(int u, args_t *a, void *pa)
    281 /*
    282  * Function: 	pci_sch_test
    283  * Purpose:	Run test patterns through CMIC_SCHAN_MESSAGE buffer
    284  * Parameters:	u - unit #.
    285  *		a - pointer to arguments.
    286  *		pa - ignored cookie.
    287  * Returns:	0
    288  */
    289 {
    290     COMPILER_REFERENCE(a);
    291     COMPILER_REFERENCE(pa);
    292 
    293     if (soc_pci_test(u) < 0) {
    294 	test_error(u, "CMIC PCI S-Channel Buffer test failed\n");
    295     }
    296 
    297     return 0;	/* If test_error() returns */
    298 }
    299 
    300 #endif /* BCM_ESW_SUPPORT */