0001
0002
0003
0004
0005
0006
0007
0008 #include <linux/kernel.h>
0009 #include <linux/init.h>
0010 #include <linux/pci.h>
0011 #include <linux/interrupt.h>
0012 #include <linux/time.h>
0013 #include <linux/delay.h>
0014 #include <linux/moduleparam.h>
0015
0016 #include <asm/octeon/octeon.h>
0017 #include <asm/octeon/cvmx-npei-defs.h>
0018 #include <asm/octeon/cvmx-pciercx-defs.h>
0019 #include <asm/octeon/cvmx-pescx-defs.h>
0020 #include <asm/octeon/cvmx-pexp-defs.h>
0021 #include <asm/octeon/cvmx-pemx-defs.h>
0022 #include <asm/octeon/cvmx-dpi-defs.h>
0023 #include <asm/octeon/cvmx-sli-defs.h>
0024 #include <asm/octeon/cvmx-sriox-defs.h>
0025 #include <asm/octeon/cvmx-helper-errata.h>
0026 #include <asm/octeon/pci-octeon.h>
0027
0028 #define MRRS_CN5XXX 0
0029 #define MPS_CN5XXX 0
0030 #define MRRS_CN6XXX 3
0031 #define MPS_CN6XXX 0
0032
0033
0034 static int pcie_disable;
0035 module_param(pcie_disable, int, S_IRUGO);
0036
0037 static int enable_pcie_14459_war;
0038 static int enable_pcie_bus_num_war[2];
0039
0040 union cvmx_pcie_address {
0041 uint64_t u64;
0042 struct {
0043 uint64_t upper:2;
0044 uint64_t reserved_49_61:13;
0045 uint64_t io:1;
0046 uint64_t did:5;
0047 uint64_t subdid:3;
0048 uint64_t reserved_36_39:4;
0049 uint64_t es:2;
0050 uint64_t port:2;
0051 uint64_t reserved_29_31:3;
0052
0053
0054
0055
0056 uint64_t ty:1;
0057
0058 uint64_t bus:8;
0059
0060
0061
0062
0063
0064 uint64_t dev:5;
0065
0066 uint64_t func:3;
0067
0068
0069
0070
0071 uint64_t reg:12;
0072 } config;
0073 struct {
0074 uint64_t upper:2;
0075 uint64_t reserved_49_61:13;
0076 uint64_t io:1;
0077 uint64_t did:5;
0078 uint64_t subdid:3;
0079 uint64_t reserved_36_39:4;
0080 uint64_t es:2;
0081 uint64_t port:2;
0082 uint64_t address:32;
0083 } io;
0084 struct {
0085 uint64_t upper:2;
0086 uint64_t reserved_49_61:13;
0087 uint64_t io:1;
0088 uint64_t did:5;
0089 uint64_t subdid:3;
0090 uint64_t reserved_36_39:4;
0091 uint64_t address:36;
0092 } mem;
0093 };
0094
0095 static int cvmx_pcie_rc_initialize(int pcie_port);
0096
0097
0098
0099
0100
0101
0102
0103
0104
0105 static inline uint64_t cvmx_pcie_get_io_base_address(int pcie_port)
0106 {
0107 union cvmx_pcie_address pcie_addr;
0108 pcie_addr.u64 = 0;
0109 pcie_addr.io.upper = 0;
0110 pcie_addr.io.io = 1;
0111 pcie_addr.io.did = 3;
0112 pcie_addr.io.subdid = 2;
0113 pcie_addr.io.es = 1;
0114 pcie_addr.io.port = pcie_port;
0115 return pcie_addr.u64;
0116 }
0117
0118
0119
0120
0121
0122
0123
0124
0125
0126 static inline uint64_t cvmx_pcie_get_io_size(int pcie_port)
0127 {
0128 return 1ull << 32;
0129 }
0130
0131
0132
0133
0134
0135
0136
0137
0138
0139 static inline uint64_t cvmx_pcie_get_mem_base_address(int pcie_port)
0140 {
0141 union cvmx_pcie_address pcie_addr;
0142 pcie_addr.u64 = 0;
0143 pcie_addr.mem.upper = 0;
0144 pcie_addr.mem.io = 1;
0145 pcie_addr.mem.did = 3;
0146 pcie_addr.mem.subdid = 3 + pcie_port;
0147 return pcie_addr.u64;
0148 }
0149
0150
0151
0152
0153
0154
0155
0156
0157
0158 static inline uint64_t cvmx_pcie_get_mem_size(int pcie_port)
0159 {
0160 return 1ull << 36;
0161 }
0162
0163
0164
0165
0166
0167
0168
0169
0170
0171
0172 static uint32_t cvmx_pcie_cfgx_read(int pcie_port, uint32_t cfg_offset)
0173 {
0174 if (octeon_has_feature(OCTEON_FEATURE_NPEI)) {
0175 union cvmx_pescx_cfg_rd pescx_cfg_rd;
0176 pescx_cfg_rd.u64 = 0;
0177 pescx_cfg_rd.s.addr = cfg_offset;
0178 cvmx_write_csr(CVMX_PESCX_CFG_RD(pcie_port), pescx_cfg_rd.u64);
0179 pescx_cfg_rd.u64 = cvmx_read_csr(CVMX_PESCX_CFG_RD(pcie_port));
0180 return pescx_cfg_rd.s.data;
0181 } else {
0182 union cvmx_pemx_cfg_rd pemx_cfg_rd;
0183 pemx_cfg_rd.u64 = 0;
0184 pemx_cfg_rd.s.addr = cfg_offset;
0185 cvmx_write_csr(CVMX_PEMX_CFG_RD(pcie_port), pemx_cfg_rd.u64);
0186 pemx_cfg_rd.u64 = cvmx_read_csr(CVMX_PEMX_CFG_RD(pcie_port));
0187 return pemx_cfg_rd.s.data;
0188 }
0189 }
0190
0191
0192
0193
0194
0195
0196
0197
0198
0199 static void cvmx_pcie_cfgx_write(int pcie_port, uint32_t cfg_offset,
0200 uint32_t val)
0201 {
0202 if (octeon_has_feature(OCTEON_FEATURE_NPEI)) {
0203 union cvmx_pescx_cfg_wr pescx_cfg_wr;
0204 pescx_cfg_wr.u64 = 0;
0205 pescx_cfg_wr.s.addr = cfg_offset;
0206 pescx_cfg_wr.s.data = val;
0207 cvmx_write_csr(CVMX_PESCX_CFG_WR(pcie_port), pescx_cfg_wr.u64);
0208 } else {
0209 union cvmx_pemx_cfg_wr pemx_cfg_wr;
0210 pemx_cfg_wr.u64 = 0;
0211 pemx_cfg_wr.s.addr = cfg_offset;
0212 pemx_cfg_wr.s.data = val;
0213 cvmx_write_csr(CVMX_PEMX_CFG_WR(pcie_port), pemx_cfg_wr.u64);
0214 }
0215 }
0216
0217
0218
0219
0220
0221
0222
0223
0224
0225
0226
0227
0228 static inline uint64_t __cvmx_pcie_build_config_addr(int pcie_port, int bus,
0229 int dev, int fn, int reg)
0230 {
0231 union cvmx_pcie_address pcie_addr;
0232 union cvmx_pciercx_cfg006 pciercx_cfg006;
0233
0234 pciercx_cfg006.u32 =
0235 cvmx_pcie_cfgx_read(pcie_port, CVMX_PCIERCX_CFG006(pcie_port));
0236 if ((bus <= pciercx_cfg006.s.pbnum) && (dev != 0))
0237 return 0;
0238
0239 pcie_addr.u64 = 0;
0240 pcie_addr.config.upper = 2;
0241 pcie_addr.config.io = 1;
0242 pcie_addr.config.did = 3;
0243 pcie_addr.config.subdid = 1;
0244 pcie_addr.config.es = 1;
0245 pcie_addr.config.port = pcie_port;
0246 pcie_addr.config.ty = (bus > pciercx_cfg006.s.pbnum);
0247 pcie_addr.config.bus = bus;
0248 pcie_addr.config.dev = dev;
0249 pcie_addr.config.func = fn;
0250 pcie_addr.config.reg = reg;
0251 return pcie_addr.u64;
0252 }
0253
0254
0255
0256
0257
0258
0259
0260
0261
0262
0263
0264
0265 static uint8_t cvmx_pcie_config_read8(int pcie_port, int bus, int dev,
0266 int fn, int reg)
0267 {
0268 uint64_t address =
0269 __cvmx_pcie_build_config_addr(pcie_port, bus, dev, fn, reg);
0270 if (address)
0271 return cvmx_read64_uint8(address);
0272 else
0273 return 0xff;
0274 }
0275
0276
0277
0278
0279
0280
0281
0282
0283
0284
0285
0286
0287 static uint16_t cvmx_pcie_config_read16(int pcie_port, int bus, int dev,
0288 int fn, int reg)
0289 {
0290 uint64_t address =
0291 __cvmx_pcie_build_config_addr(pcie_port, bus, dev, fn, reg);
0292 if (address)
0293 return le16_to_cpu(cvmx_read64_uint16(address));
0294 else
0295 return 0xffff;
0296 }
0297
0298
0299
0300
0301
0302
0303
0304
0305
0306
0307
0308
0309 static uint32_t cvmx_pcie_config_read32(int pcie_port, int bus, int dev,
0310 int fn, int reg)
0311 {
0312 uint64_t address =
0313 __cvmx_pcie_build_config_addr(pcie_port, bus, dev, fn, reg);
0314 if (address)
0315 return le32_to_cpu(cvmx_read64_uint32(address));
0316 else
0317 return 0xffffffff;
0318 }
0319
0320
0321
0322
0323
0324
0325
0326
0327
0328
0329
0330 static void cvmx_pcie_config_write8(int pcie_port, int bus, int dev, int fn,
0331 int reg, uint8_t val)
0332 {
0333 uint64_t address =
0334 __cvmx_pcie_build_config_addr(pcie_port, bus, dev, fn, reg);
0335 if (address)
0336 cvmx_write64_uint8(address, val);
0337 }
0338
0339
0340
0341
0342
0343
0344
0345
0346
0347
0348
0349 static void cvmx_pcie_config_write16(int pcie_port, int bus, int dev, int fn,
0350 int reg, uint16_t val)
0351 {
0352 uint64_t address =
0353 __cvmx_pcie_build_config_addr(pcie_port, bus, dev, fn, reg);
0354 if (address)
0355 cvmx_write64_uint16(address, cpu_to_le16(val));
0356 }
0357
0358
0359
0360
0361
0362
0363
0364
0365
0366
0367
0368 static void cvmx_pcie_config_write32(int pcie_port, int bus, int dev, int fn,
0369 int reg, uint32_t val)
0370 {
0371 uint64_t address =
0372 __cvmx_pcie_build_config_addr(pcie_port, bus, dev, fn, reg);
0373 if (address)
0374 cvmx_write64_uint32(address, cpu_to_le32(val));
0375 }
0376
0377
0378
0379
0380
0381
0382 static void __cvmx_pcie_rc_initialize_config_space(int pcie_port)
0383 {
0384 union cvmx_pciercx_cfg030 pciercx_cfg030;
0385 union cvmx_pciercx_cfg070 pciercx_cfg070;
0386 union cvmx_pciercx_cfg001 pciercx_cfg001;
0387 union cvmx_pciercx_cfg032 pciercx_cfg032;
0388 union cvmx_pciercx_cfg006 pciercx_cfg006;
0389 union cvmx_pciercx_cfg008 pciercx_cfg008;
0390 union cvmx_pciercx_cfg009 pciercx_cfg009;
0391 union cvmx_pciercx_cfg010 pciercx_cfg010;
0392 union cvmx_pciercx_cfg011 pciercx_cfg011;
0393 union cvmx_pciercx_cfg035 pciercx_cfg035;
0394 union cvmx_pciercx_cfg075 pciercx_cfg075;
0395 union cvmx_pciercx_cfg034 pciercx_cfg034;
0396
0397
0398
0399
0400
0401
0402 pciercx_cfg030.u32 = cvmx_pcie_cfgx_read(pcie_port, CVMX_PCIERCX_CFG030(pcie_port));
0403 if (OCTEON_IS_MODEL(OCTEON_CN5XXX)) {
0404 pciercx_cfg030.s.mps = MPS_CN5XXX;
0405 pciercx_cfg030.s.mrrs = MRRS_CN5XXX;
0406 } else {
0407 pciercx_cfg030.s.mps = MPS_CN6XXX;
0408 pciercx_cfg030.s.mrrs = MRRS_CN6XXX;
0409 }
0410
0411
0412
0413
0414 pciercx_cfg030.s.ro_en = 1;
0415
0416 pciercx_cfg030.s.ns_en = 1;
0417
0418 pciercx_cfg030.s.ce_en = 1;
0419
0420 pciercx_cfg030.s.nfe_en = 1;
0421
0422 pciercx_cfg030.s.fe_en = 1;
0423
0424 pciercx_cfg030.s.ur_en = 1;
0425 cvmx_pcie_cfgx_write(pcie_port, CVMX_PCIERCX_CFG030(pcie_port), pciercx_cfg030.u32);
0426
0427
0428 if (octeon_has_feature(OCTEON_FEATURE_NPEI)) {
0429 union cvmx_npei_ctl_status2 npei_ctl_status2;
0430
0431
0432
0433
0434
0435
0436 npei_ctl_status2.u64 = cvmx_read_csr(CVMX_PEXP_NPEI_CTL_STATUS2);
0437
0438 npei_ctl_status2.s.mps = MPS_CN5XXX;
0439
0440 npei_ctl_status2.s.mrrs = MRRS_CN5XXX;
0441 if (pcie_port)
0442 npei_ctl_status2.s.c1_b1_s = 3;
0443 else
0444 npei_ctl_status2.s.c0_b1_s = 3;
0445
0446 cvmx_write_csr(CVMX_PEXP_NPEI_CTL_STATUS2, npei_ctl_status2.u64);
0447 } else {
0448
0449
0450
0451
0452
0453
0454 union cvmx_dpi_sli_prtx_cfg prt_cfg;
0455 union cvmx_sli_s2m_portx_ctl sli_s2m_portx_ctl;
0456 prt_cfg.u64 = cvmx_read_csr(CVMX_DPI_SLI_PRTX_CFG(pcie_port));
0457 prt_cfg.s.mps = MPS_CN6XXX;
0458 prt_cfg.s.mrrs = MRRS_CN6XXX;
0459
0460 prt_cfg.s.molr = 32;
0461 cvmx_write_csr(CVMX_DPI_SLI_PRTX_CFG(pcie_port), prt_cfg.u64);
0462
0463 sli_s2m_portx_ctl.u64 = cvmx_read_csr(CVMX_PEXP_SLI_S2M_PORTX_CTL(pcie_port));
0464 sli_s2m_portx_ctl.s.mrrs = MRRS_CN6XXX;
0465 cvmx_write_csr(CVMX_PEXP_SLI_S2M_PORTX_CTL(pcie_port), sli_s2m_portx_ctl.u64);
0466 }
0467
0468
0469 pciercx_cfg070.u32 = cvmx_pcie_cfgx_read(pcie_port, CVMX_PCIERCX_CFG070(pcie_port));
0470 pciercx_cfg070.s.ge = 1;
0471 pciercx_cfg070.s.ce = 1;
0472 cvmx_pcie_cfgx_write(pcie_port, CVMX_PCIERCX_CFG070(pcie_port), pciercx_cfg070.u32);
0473
0474
0475
0476
0477
0478
0479
0480 pciercx_cfg001.u32 = cvmx_pcie_cfgx_read(pcie_port, CVMX_PCIERCX_CFG001(pcie_port));
0481 pciercx_cfg001.s.msae = 1;
0482 pciercx_cfg001.s.me = 1;
0483 pciercx_cfg001.s.i_dis = 1;
0484 pciercx_cfg001.s.see = 1;
0485 cvmx_pcie_cfgx_write(pcie_port, CVMX_PCIERCX_CFG001(pcie_port), pciercx_cfg001.u32);
0486
0487
0488
0489 cvmx_pcie_cfgx_write(pcie_port, CVMX_PCIERCX_CFG066(pcie_port), 0);
0490
0491 cvmx_pcie_cfgx_write(pcie_port, CVMX_PCIERCX_CFG069(pcie_port), 0);
0492
0493
0494
0495 pciercx_cfg032.u32 = cvmx_pcie_cfgx_read(pcie_port, CVMX_PCIERCX_CFG032(pcie_port));
0496 pciercx_cfg032.s.aslpc = 0;
0497 cvmx_pcie_cfgx_write(pcie_port, CVMX_PCIERCX_CFG032(pcie_port), pciercx_cfg032.u32);
0498
0499
0500
0501
0502
0503
0504
0505
0506
0507
0508 pciercx_cfg006.u32 = 0;
0509 pciercx_cfg006.s.pbnum = 1;
0510 pciercx_cfg006.s.sbnum = 1;
0511 pciercx_cfg006.s.subbnum = 1;
0512 cvmx_pcie_cfgx_write(pcie_port, CVMX_PCIERCX_CFG006(pcie_port), pciercx_cfg006.u32);
0513
0514
0515
0516
0517
0518
0519
0520 pciercx_cfg008.u32 = 0;
0521 pciercx_cfg008.s.mb_addr = 0x100;
0522 pciercx_cfg008.s.ml_addr = 0;
0523 cvmx_pcie_cfgx_write(pcie_port, CVMX_PCIERCX_CFG008(pcie_port), pciercx_cfg008.u32);
0524
0525
0526
0527
0528
0529
0530
0531
0532 pciercx_cfg009.u32 = cvmx_pcie_cfgx_read(pcie_port, CVMX_PCIERCX_CFG009(pcie_port));
0533 pciercx_cfg010.u32 = cvmx_pcie_cfgx_read(pcie_port, CVMX_PCIERCX_CFG010(pcie_port));
0534 pciercx_cfg011.u32 = cvmx_pcie_cfgx_read(pcie_port, CVMX_PCIERCX_CFG011(pcie_port));
0535 pciercx_cfg009.s.lmem_base = 0x100;
0536 pciercx_cfg009.s.lmem_limit = 0;
0537 pciercx_cfg010.s.umem_base = 0x100;
0538 pciercx_cfg011.s.umem_limit = 0;
0539 cvmx_pcie_cfgx_write(pcie_port, CVMX_PCIERCX_CFG009(pcie_port), pciercx_cfg009.u32);
0540 cvmx_pcie_cfgx_write(pcie_port, CVMX_PCIERCX_CFG010(pcie_port), pciercx_cfg010.u32);
0541 cvmx_pcie_cfgx_write(pcie_port, CVMX_PCIERCX_CFG011(pcie_port), pciercx_cfg011.u32);
0542
0543
0544
0545
0546
0547 pciercx_cfg035.u32 = cvmx_pcie_cfgx_read(pcie_port, CVMX_PCIERCX_CFG035(pcie_port));
0548 pciercx_cfg035.s.secee = 1;
0549 pciercx_cfg035.s.sefee = 1;
0550 pciercx_cfg035.s.senfee = 1;
0551 pciercx_cfg035.s.pmeie = 1;
0552 cvmx_pcie_cfgx_write(pcie_port, CVMX_PCIERCX_CFG035(pcie_port), pciercx_cfg035.u32);
0553
0554
0555
0556
0557
0558 pciercx_cfg075.u32 = cvmx_pcie_cfgx_read(pcie_port, CVMX_PCIERCX_CFG075(pcie_port));
0559 pciercx_cfg075.s.cere = 1;
0560 pciercx_cfg075.s.nfere = 1;
0561 pciercx_cfg075.s.fere = 1;
0562 cvmx_pcie_cfgx_write(pcie_port, CVMX_PCIERCX_CFG075(pcie_port), pciercx_cfg075.u32);
0563
0564
0565
0566
0567
0568 pciercx_cfg034.u32 = cvmx_pcie_cfgx_read(pcie_port, CVMX_PCIERCX_CFG034(pcie_port));
0569 pciercx_cfg034.s.hpint_en = 1;
0570 pciercx_cfg034.s.dlls_en = 1;
0571 pciercx_cfg034.s.ccint_en = 1;
0572 cvmx_pcie_cfgx_write(pcie_port, CVMX_PCIERCX_CFG034(pcie_port), pciercx_cfg034.u32);
0573 }
0574
0575
0576
0577
0578
0579
0580
0581
0582
0583
0584 static int __cvmx_pcie_rc_initialize_link_gen1(int pcie_port)
0585 {
0586 uint64_t start_cycle;
0587 union cvmx_pescx_ctl_status pescx_ctl_status;
0588 union cvmx_pciercx_cfg452 pciercx_cfg452;
0589 union cvmx_pciercx_cfg032 pciercx_cfg032;
0590 union cvmx_pciercx_cfg448 pciercx_cfg448;
0591
0592
0593 pciercx_cfg452.u32 = cvmx_pcie_cfgx_read(pcie_port, CVMX_PCIERCX_CFG452(pcie_port));
0594 pescx_ctl_status.u64 = cvmx_read_csr(CVMX_PESCX_CTL_STATUS(pcie_port));
0595 if (pescx_ctl_status.s.qlm_cfg == 0)
0596
0597 pciercx_cfg452.s.lme = 0xf;
0598 else
0599
0600 pciercx_cfg452.s.lme = 0x7;
0601 cvmx_pcie_cfgx_write(pcie_port, CVMX_PCIERCX_CFG452(pcie_port), pciercx_cfg452.u32);
0602
0603
0604
0605
0606
0607
0608 if (OCTEON_IS_MODEL(OCTEON_CN52XX_PASS1_X)) {
0609 union cvmx_pciercx_cfg455 pciercx_cfg455;
0610 pciercx_cfg455.u32 = cvmx_pcie_cfgx_read(pcie_port, CVMX_PCIERCX_CFG455(pcie_port));
0611 pciercx_cfg455.s.m_cpl_len_err = 1;
0612 cvmx_pcie_cfgx_write(pcie_port, CVMX_PCIERCX_CFG455(pcie_port), pciercx_cfg455.u32);
0613 }
0614
0615
0616 if (OCTEON_IS_MODEL(OCTEON_CN52XX) && (pcie_port == 1)) {
0617 pescx_ctl_status.s.lane_swp = 1;
0618 cvmx_write_csr(CVMX_PESCX_CTL_STATUS(pcie_port), pescx_ctl_status.u64);
0619 }
0620
0621
0622 pescx_ctl_status.u64 = cvmx_read_csr(CVMX_PESCX_CTL_STATUS(pcie_port));
0623 pescx_ctl_status.s.lnk_enb = 1;
0624 cvmx_write_csr(CVMX_PESCX_CTL_STATUS(pcie_port), pescx_ctl_status.u64);
0625
0626
0627
0628
0629
0630 if (OCTEON_IS_MODEL(OCTEON_CN52XX_PASS1_0))
0631 __cvmx_helper_errata_qlm_disable_2nd_order_cdr(0);
0632
0633
0634 start_cycle = cvmx_get_cycle();
0635 do {
0636 if (cvmx_get_cycle() - start_cycle > 2 * octeon_get_clock_rate()) {
0637 cvmx_dprintf("PCIe: Port %d link timeout\n", pcie_port);
0638 return -1;
0639 }
0640 __delay(10000);
0641 pciercx_cfg032.u32 = cvmx_pcie_cfgx_read(pcie_port, CVMX_PCIERCX_CFG032(pcie_port));
0642 } while (pciercx_cfg032.s.dlla == 0);
0643
0644
0645 cvmx_write_csr(CVMX_PEXP_NPEI_INT_SUM, cvmx_read_csr(CVMX_PEXP_NPEI_INT_SUM));
0646
0647
0648
0649
0650
0651
0652
0653
0654
0655 pciercx_cfg448.u32 = cvmx_pcie_cfgx_read(pcie_port, CVMX_PCIERCX_CFG448(pcie_port));
0656 switch (pciercx_cfg032.s.nlw) {
0657 case 1:
0658 pciercx_cfg448.s.rtl = 1677;
0659 break;
0660 case 2:
0661 pciercx_cfg448.s.rtl = 867;
0662 break;
0663 case 4:
0664 pciercx_cfg448.s.rtl = 462;
0665 break;
0666 case 8:
0667 pciercx_cfg448.s.rtl = 258;
0668 break;
0669 }
0670 cvmx_pcie_cfgx_write(pcie_port, CVMX_PCIERCX_CFG448(pcie_port), pciercx_cfg448.u32);
0671
0672 return 0;
0673 }
0674
0675 static void __cvmx_increment_ba(union cvmx_sli_mem_access_subidx *pmas)
0676 {
0677 if (OCTEON_IS_MODEL(OCTEON_CN68XX))
0678 pmas->cn68xx.ba++;
0679 else
0680 pmas->s.ba++;
0681 }
0682
0683
0684
0685
0686
0687
0688
0689
0690
0691 static int __cvmx_pcie_rc_initialize_gen1(int pcie_port)
0692 {
0693 int i;
0694 int base;
0695 u64 addr_swizzle;
0696 union cvmx_ciu_soft_prst ciu_soft_prst;
0697 union cvmx_pescx_bist_status pescx_bist_status;
0698 union cvmx_pescx_bist_status2 pescx_bist_status2;
0699 union cvmx_npei_ctl_status npei_ctl_status;
0700 union cvmx_npei_mem_access_ctl npei_mem_access_ctl;
0701 union cvmx_npei_mem_access_subidx mem_access_subid;
0702 union cvmx_npei_dbg_data npei_dbg_data;
0703 union cvmx_pescx_ctl_status2 pescx_ctl_status2;
0704 union cvmx_pciercx_cfg032 pciercx_cfg032;
0705 union cvmx_npei_bar1_indexx bar1_index;
0706
0707 retry:
0708
0709
0710
0711
0712 npei_ctl_status.u64 = cvmx_read_csr(CVMX_PEXP_NPEI_CTL_STATUS);
0713 if ((pcie_port == 0) && !npei_ctl_status.s.host_mode) {
0714 cvmx_dprintf("PCIe: Port %d in endpoint mode\n", pcie_port);
0715 return -1;
0716 }
0717
0718
0719
0720
0721
0722 if (OCTEON_IS_MODEL(OCTEON_CN52XX)) {
0723 npei_dbg_data.u64 = cvmx_read_csr(CVMX_PEXP_NPEI_DBG_DATA);
0724 if ((pcie_port == 1) && npei_dbg_data.cn52xx.qlm0_link_width) {
0725 cvmx_dprintf("PCIe: ERROR: cvmx_pcie_rc_initialize() called on port1, but port1 is disabled\n");
0726 return -1;
0727 }
0728 }
0729
0730
0731
0732
0733
0734 npei_ctl_status.s.arb = 1;
0735
0736 npei_ctl_status.s.cfg_rtry = 0x20;
0737
0738
0739
0740
0741 if (OCTEON_IS_MODEL(OCTEON_CN52XX_PASS1_X)) {
0742 npei_ctl_status.s.p0_ntags = 0x20;
0743 npei_ctl_status.s.p1_ntags = 0x20;
0744 }
0745 cvmx_write_csr(CVMX_PEXP_NPEI_CTL_STATUS, npei_ctl_status.u64);
0746
0747
0748 if (cvmx_sysinfo_get()->board_type == CVMX_BOARD_TYPE_EBH5200) {
0749
0750
0751
0752
0753
0754
0755
0756 if (pcie_port == 0) {
0757 ciu_soft_prst.u64 = cvmx_read_csr(CVMX_CIU_SOFT_PRST);
0758
0759
0760
0761
0762
0763
0764 if (ciu_soft_prst.s.soft_prst == 0) {
0765
0766 ciu_soft_prst.s.soft_prst = 1;
0767 cvmx_write_csr(CVMX_CIU_SOFT_PRST, ciu_soft_prst.u64);
0768 ciu_soft_prst.u64 = cvmx_read_csr(CVMX_CIU_SOFT_PRST1);
0769 ciu_soft_prst.s.soft_prst = 1;
0770 cvmx_write_csr(CVMX_CIU_SOFT_PRST1, ciu_soft_prst.u64);
0771
0772 udelay(2000);
0773 }
0774 ciu_soft_prst.u64 = cvmx_read_csr(CVMX_CIU_SOFT_PRST1);
0775 ciu_soft_prst.s.soft_prst = 0;
0776 cvmx_write_csr(CVMX_CIU_SOFT_PRST1, ciu_soft_prst.u64);
0777 ciu_soft_prst.u64 = cvmx_read_csr(CVMX_CIU_SOFT_PRST);
0778 ciu_soft_prst.s.soft_prst = 0;
0779 cvmx_write_csr(CVMX_CIU_SOFT_PRST, ciu_soft_prst.u64);
0780 }
0781 } else {
0782
0783
0784
0785
0786
0787 if (pcie_port)
0788 ciu_soft_prst.u64 = cvmx_read_csr(CVMX_CIU_SOFT_PRST1);
0789 else
0790 ciu_soft_prst.u64 = cvmx_read_csr(CVMX_CIU_SOFT_PRST);
0791
0792
0793
0794
0795
0796 if (ciu_soft_prst.s.soft_prst == 0) {
0797
0798 ciu_soft_prst.s.soft_prst = 1;
0799 if (pcie_port)
0800 cvmx_write_csr(CVMX_CIU_SOFT_PRST1, ciu_soft_prst.u64);
0801 else
0802 cvmx_write_csr(CVMX_CIU_SOFT_PRST, ciu_soft_prst.u64);
0803
0804 udelay(2000);
0805 }
0806 if (pcie_port) {
0807 ciu_soft_prst.u64 = cvmx_read_csr(CVMX_CIU_SOFT_PRST1);
0808 ciu_soft_prst.s.soft_prst = 0;
0809 cvmx_write_csr(CVMX_CIU_SOFT_PRST1, ciu_soft_prst.u64);
0810 } else {
0811 ciu_soft_prst.u64 = cvmx_read_csr(CVMX_CIU_SOFT_PRST);
0812 ciu_soft_prst.s.soft_prst = 0;
0813 cvmx_write_csr(CVMX_CIU_SOFT_PRST, ciu_soft_prst.u64);
0814 }
0815 }
0816
0817
0818
0819
0820
0821
0822 __delay(400000);
0823
0824
0825
0826
0827
0828 if (!OCTEON_IS_MODEL(OCTEON_CN56XX_PASS1_X) && !OCTEON_IS_MODEL(OCTEON_CN52XX_PASS1_X)) {
0829
0830 pescx_ctl_status2.u64 = cvmx_read_csr(CVMX_PESCX_CTL_STATUS2(pcie_port));
0831 pescx_ctl_status2.s.pclk_run = 1;
0832 cvmx_write_csr(CVMX_PESCX_CTL_STATUS2(pcie_port), pescx_ctl_status2.u64);
0833
0834
0835
0836 if (CVMX_WAIT_FOR_FIELD64(CVMX_PESCX_CTL_STATUS2(pcie_port),
0837 union cvmx_pescx_ctl_status2, pclk_run, ==, 1, 10000)) {
0838 cvmx_dprintf("PCIe: Port %d isn't clocked, skipping.\n", pcie_port);
0839 return -1;
0840 }
0841 }
0842
0843
0844
0845
0846
0847
0848 pescx_ctl_status2.u64 = cvmx_read_csr(CVMX_PESCX_CTL_STATUS2(pcie_port));
0849 if (pescx_ctl_status2.s.pcierst) {
0850 cvmx_dprintf("PCIe: Port %d stuck in reset, skipping.\n", pcie_port);
0851 return -1;
0852 }
0853
0854
0855
0856
0857
0858
0859 pescx_bist_status2.u64 = cvmx_read_csr(CVMX_PESCX_BIST_STATUS2(pcie_port));
0860 if (pescx_bist_status2.u64) {
0861 cvmx_dprintf("PCIe: Port %d BIST2 failed. Most likely this port isn't hooked up, skipping.\n",
0862 pcie_port);
0863 return -1;
0864 }
0865
0866
0867 pescx_bist_status.u64 = cvmx_read_csr(CVMX_PESCX_BIST_STATUS(pcie_port));
0868 if (pescx_bist_status.u64)
0869 cvmx_dprintf("PCIe: BIST FAILED for port %d (0x%016llx)\n",
0870 pcie_port, CAST64(pescx_bist_status.u64));
0871
0872
0873 __cvmx_pcie_rc_initialize_config_space(pcie_port);
0874
0875
0876 if (__cvmx_pcie_rc_initialize_link_gen1(pcie_port)) {
0877 cvmx_dprintf("PCIe: Failed to initialize port %d, probably the slot is empty\n",
0878 pcie_port);
0879 return -1;
0880 }
0881
0882
0883 npei_mem_access_ctl.u64 = cvmx_read_csr(CVMX_PEXP_NPEI_MEM_ACCESS_CTL);
0884 npei_mem_access_ctl.s.max_word = 0;
0885 npei_mem_access_ctl.s.timer = 127;
0886 cvmx_write_csr(CVMX_PEXP_NPEI_MEM_ACCESS_CTL, npei_mem_access_ctl.u64);
0887
0888
0889 mem_access_subid.u64 = 0;
0890 mem_access_subid.s.port = pcie_port;
0891 mem_access_subid.s.nmerge = 1;
0892 mem_access_subid.s.esr = 1;
0893 mem_access_subid.s.esw = 1;
0894 mem_access_subid.s.nsr = 0;
0895 mem_access_subid.s.nsw = 0;
0896 mem_access_subid.s.ror = 0;
0897 mem_access_subid.s.row = 0;
0898 mem_access_subid.s.ba = 0;
0899
0900
0901
0902
0903
0904 for (i = 12 + pcie_port * 4; i < 16 + pcie_port * 4; i++) {
0905 cvmx_write_csr(CVMX_PEXP_NPEI_MEM_ACCESS_SUBIDX(i), mem_access_subid.u64);
0906 mem_access_subid.s.ba += 1;
0907 }
0908
0909
0910
0911
0912
0913
0914 for (i = 0; i < 4; i++) {
0915 cvmx_write_csr(CVMX_PESCX_P2P_BARX_START(i, pcie_port), -1);
0916 cvmx_write_csr(CVMX_PESCX_P2P_BARX_END(i, pcie_port), -1);
0917 }
0918
0919
0920 cvmx_write_csr(CVMX_PESCX_P2N_BAR0_START(pcie_port), 0);
0921
0922
0923 cvmx_write_csr(CVMX_PESCX_P2N_BAR1_START(pcie_port), CVMX_PCIE_BAR1_RC_BASE);
0924
0925 bar1_index.u32 = 0;
0926 bar1_index.s.addr_idx = (CVMX_PCIE_BAR1_PHYS_BASE >> 22);
0927 bar1_index.s.ca = 1;
0928 bar1_index.s.end_swp = 1;
0929 bar1_index.s.addr_v = 1;
0930
0931 base = pcie_port ? 16 : 0;
0932
0933
0934 #ifdef __MIPSEB__
0935 addr_swizzle = 4;
0936 #else
0937 addr_swizzle = 0;
0938 #endif
0939 for (i = 0; i < 16; i++) {
0940 cvmx_write64_uint32((CVMX_PEXP_NPEI_BAR1_INDEXX(base) ^ addr_swizzle),
0941 bar1_index.u32);
0942 base++;
0943
0944 bar1_index.s.addr_idx += (((1ull << 28) / 16ull) >> 22);
0945 }
0946
0947
0948
0949
0950
0951
0952
0953 cvmx_write_csr(CVMX_PESCX_P2N_BAR2_START(pcie_port), 0);
0954
0955
0956
0957
0958
0959
0960
0961
0962
0963
0964 if (pcie_port) {
0965 union cvmx_npei_ctl_port1 npei_ctl_port;
0966 npei_ctl_port.u64 = cvmx_read_csr(CVMX_PEXP_NPEI_CTL_PORT1);
0967 npei_ctl_port.s.bar2_enb = 1;
0968 npei_ctl_port.s.bar2_esx = 1;
0969 npei_ctl_port.s.bar2_cax = 0;
0970 npei_ctl_port.s.ptlp_ro = 1;
0971 npei_ctl_port.s.ctlp_ro = 1;
0972 npei_ctl_port.s.wait_com = 0;
0973 npei_ctl_port.s.waitl_com = 0;
0974 cvmx_write_csr(CVMX_PEXP_NPEI_CTL_PORT1, npei_ctl_port.u64);
0975 } else {
0976 union cvmx_npei_ctl_port0 npei_ctl_port;
0977 npei_ctl_port.u64 = cvmx_read_csr(CVMX_PEXP_NPEI_CTL_PORT0);
0978 npei_ctl_port.s.bar2_enb = 1;
0979 npei_ctl_port.s.bar2_esx = 1;
0980 npei_ctl_port.s.bar2_cax = 0;
0981 npei_ctl_port.s.ptlp_ro = 1;
0982 npei_ctl_port.s.ctlp_ro = 1;
0983 npei_ctl_port.s.wait_com = 0;
0984 npei_ctl_port.s.waitl_com = 0;
0985 cvmx_write_csr(CVMX_PEXP_NPEI_CTL_PORT0, npei_ctl_port.u64);
0986 }
0987
0988
0989
0990
0991
0992
0993
0994
0995 if (OCTEON_IS_MODEL(OCTEON_CN56XX_PASS2_X) ||
0996 OCTEON_IS_MODEL(OCTEON_CN52XX_PASS2_X) ||
0997 OCTEON_IS_MODEL(OCTEON_CN56XX_PASS1_X) ||
0998 OCTEON_IS_MODEL(OCTEON_CN52XX_PASS1_X)) {
0999 union cvmx_npei_dbg_data dbg_data;
1000 int old_in_fif_p_count;
1001 int in_fif_p_count;
1002 int out_p_count;
1003 int in_p_offset = (OCTEON_IS_MODEL(OCTEON_CN52XX_PASS1_X) || OCTEON_IS_MODEL(OCTEON_CN56XX_PASS1_X)) ? 4 : 1;
1004 int i;
1005
1006
1007
1008
1009
1010 uint64_t write_address = (cvmx_pcie_get_mem_base_address(pcie_port) + 0x100000) | (1ull<<63);
1011
1012
1013
1014
1015
1016 i = in_p_offset;
1017 while (i--) {
1018 cvmx_write64_uint32(write_address, 0);
1019 __delay(10000);
1020 }
1021
1022
1023
1024
1025
1026
1027
1028
1029 cvmx_write_csr(CVMX_PEXP_NPEI_DBG_SELECT, (pcie_port) ? 0xd7fc : 0xcffc);
1030 cvmx_read_csr(CVMX_PEXP_NPEI_DBG_SELECT);
1031 do {
1032 dbg_data.u64 = cvmx_read_csr(CVMX_PEXP_NPEI_DBG_DATA);
1033 old_in_fif_p_count = dbg_data.s.data & 0xff;
1034 cvmx_write64_uint32(write_address, 0);
1035 __delay(10000);
1036 dbg_data.u64 = cvmx_read_csr(CVMX_PEXP_NPEI_DBG_DATA);
1037 in_fif_p_count = dbg_data.s.data & 0xff;
1038 } while (in_fif_p_count != ((old_in_fif_p_count+1) & 0xff));
1039
1040
1041 in_fif_p_count = (in_fif_p_count + in_p_offset) & 0xff;
1042
1043
1044 cvmx_write_csr(CVMX_PEXP_NPEI_DBG_SELECT, (pcie_port) ? 0xd00f : 0xc80f);
1045 cvmx_read_csr(CVMX_PEXP_NPEI_DBG_SELECT);
1046 dbg_data.u64 = cvmx_read_csr(CVMX_PEXP_NPEI_DBG_DATA);
1047 out_p_count = (dbg_data.s.data>>1) & 0xff;
1048
1049
1050 if (out_p_count != in_fif_p_count) {
1051 cvmx_dprintf("PCIe: Port %d aligning TLP counters as workaround to maintain ordering\n", pcie_port);
1052 while (in_fif_p_count != 0) {
1053 cvmx_write64_uint32(write_address, 0);
1054 __delay(10000);
1055 in_fif_p_count = (in_fif_p_count + 1) & 0xff;
1056 }
1057
1058
1059
1060
1061
1062
1063
1064
1065 if ((cvmx_sysinfo_get()->board_type == CVMX_BOARD_TYPE_EBH5200) &&
1066 (pcie_port == 1))
1067 cvmx_pcie_rc_initialize(0);
1068
1069 goto retry;
1070 }
1071 }
1072
1073
1074 pciercx_cfg032.u32 = cvmx_pcie_cfgx_read(pcie_port, CVMX_PCIERCX_CFG032(pcie_port));
1075 cvmx_dprintf("PCIe: Port %d link active, %d lanes\n", pcie_port, pciercx_cfg032.s.nlw);
1076
1077 return 0;
1078 }
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089 static int __cvmx_pcie_rc_initialize_link_gen2(int pcie_port)
1090 {
1091 uint64_t start_cycle;
1092 union cvmx_pemx_ctl_status pem_ctl_status;
1093 union cvmx_pciercx_cfg032 pciercx_cfg032;
1094 union cvmx_pciercx_cfg448 pciercx_cfg448;
1095
1096
1097 pem_ctl_status.u64 = cvmx_read_csr(CVMX_PEMX_CTL_STATUS(pcie_port));
1098 pem_ctl_status.s.lnk_enb = 1;
1099 cvmx_write_csr(CVMX_PEMX_CTL_STATUS(pcie_port), pem_ctl_status.u64);
1100
1101
1102 start_cycle = cvmx_get_cycle();
1103 do {
1104 if (cvmx_get_cycle() - start_cycle > octeon_get_clock_rate())
1105 return -1;
1106 __delay(10000);
1107 pciercx_cfg032.u32 = cvmx_pcie_cfgx_read(pcie_port, CVMX_PCIERCX_CFG032(pcie_port));
1108 } while ((pciercx_cfg032.s.dlla == 0) || (pciercx_cfg032.s.lt == 1));
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118 pciercx_cfg448.u32 = cvmx_pcie_cfgx_read(pcie_port, CVMX_PCIERCX_CFG448(pcie_port));
1119 switch (pciercx_cfg032.s.nlw) {
1120 case 1:
1121 pciercx_cfg448.s.rtl = 1677;
1122 break;
1123 case 2:
1124 pciercx_cfg448.s.rtl = 867;
1125 break;
1126 case 4:
1127 pciercx_cfg448.s.rtl = 462;
1128 break;
1129 case 8:
1130 pciercx_cfg448.s.rtl = 258;
1131 break;
1132 }
1133 cvmx_pcie_cfgx_write(pcie_port, CVMX_PCIERCX_CFG448(pcie_port), pciercx_cfg448.u32);
1134
1135 return 0;
1136 }
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147 static int __cvmx_pcie_rc_initialize_gen2(int pcie_port)
1148 {
1149 int i;
1150 union cvmx_ciu_soft_prst ciu_soft_prst;
1151 union cvmx_mio_rst_ctlx mio_rst_ctl;
1152 union cvmx_pemx_bar_ctl pemx_bar_ctl;
1153 union cvmx_pemx_ctl_status pemx_ctl_status;
1154 union cvmx_pemx_bist_status pemx_bist_status;
1155 union cvmx_pemx_bist_status2 pemx_bist_status2;
1156 union cvmx_pciercx_cfg032 pciercx_cfg032;
1157 union cvmx_pciercx_cfg515 pciercx_cfg515;
1158 union cvmx_sli_ctl_portx sli_ctl_portx;
1159 union cvmx_sli_mem_access_ctl sli_mem_access_ctl;
1160 union cvmx_sli_mem_access_subidx mem_access_subid;
1161 union cvmx_sriox_status_reg sriox_status_reg;
1162 union cvmx_pemx_bar1_indexx bar1_index;
1163
1164 if (octeon_has_feature(OCTEON_FEATURE_SRIO)) {
1165
1166 if (OCTEON_IS_MODEL(OCTEON_CN66XX)) {
1167
1168
1169
1170
1171
1172 union cvmx_mio_qlmx_cfg qlmx_cfg;
1173 qlmx_cfg.u64 = cvmx_read_csr(CVMX_MIO_QLMX_CFG(pcie_port));
1174
1175 if (qlmx_cfg.s.qlm_spd == 15) {
1176 pr_notice("PCIe: Port %d is disabled, skipping.\n", pcie_port);
1177 return -1;
1178 }
1179
1180 switch (qlmx_cfg.s.qlm_spd) {
1181 case 0x1:
1182 case 0x3:
1183 case 0x4:
1184 case 0x6:
1185 pr_notice("PCIe: Port %d is SRIO, skipping.\n", pcie_port);
1186 return -1;
1187 case 0x9:
1188 pr_notice("PCIe: Port %d is SGMII, skipping.\n", pcie_port);
1189 return -1;
1190 case 0xb:
1191 pr_notice("PCIe: Port %d is XAUI, skipping.\n", pcie_port);
1192 return -1;
1193 case 0x0:
1194 case 0x8:
1195 case 0x2:
1196 case 0xa:
1197 break;
1198 default:
1199 pr_notice("PCIe: Port %d is unknown, skipping.\n", pcie_port);
1200 return -1;
1201 }
1202 } else {
1203 sriox_status_reg.u64 = cvmx_read_csr(CVMX_SRIOX_STATUS_REG(pcie_port));
1204 if (sriox_status_reg.s.srio) {
1205 pr_notice("PCIe: Port %d is SRIO, skipping.\n", pcie_port);
1206 return -1;
1207 }
1208 }
1209 }
1210
1211 #if 0
1212
1213 pr_notice("PCIE : init for pcie analyzer.\n");
1214 cvmx_helper_qlm_jtag_init();
1215 cvmx_helper_qlm_jtag_shift_zeros(pcie_port, 85);
1216 cvmx_helper_qlm_jtag_shift(pcie_port, 1, 1);
1217 cvmx_helper_qlm_jtag_shift_zeros(pcie_port, 300-86);
1218 cvmx_helper_qlm_jtag_shift_zeros(pcie_port, 85);
1219 cvmx_helper_qlm_jtag_shift(pcie_port, 1, 1);
1220 cvmx_helper_qlm_jtag_shift_zeros(pcie_port, 300-86);
1221 cvmx_helper_qlm_jtag_shift_zeros(pcie_port, 85);
1222 cvmx_helper_qlm_jtag_shift(pcie_port, 1, 1);
1223 cvmx_helper_qlm_jtag_shift_zeros(pcie_port, 300-86);
1224 cvmx_helper_qlm_jtag_shift_zeros(pcie_port, 85);
1225 cvmx_helper_qlm_jtag_shift(pcie_port, 1, 1);
1226 cvmx_helper_qlm_jtag_shift_zeros(pcie_port, 300-86);
1227 cvmx_helper_qlm_jtag_update(pcie_port);
1228 #endif
1229
1230
1231 mio_rst_ctl.u64 = cvmx_read_csr(CVMX_MIO_RST_CTLX(pcie_port));
1232 if (!mio_rst_ctl.s.host_mode) {
1233 pr_notice("PCIe: Port %d in endpoint mode.\n", pcie_port);
1234 return -1;
1235 }
1236
1237
1238 if (OCTEON_IS_MODEL(OCTEON_CN63XX_PASS1_0)) {
1239 if (pcie_port) {
1240 union cvmx_ciu_qlm ciu_qlm;
1241 ciu_qlm.u64 = cvmx_read_csr(CVMX_CIU_QLM1);
1242 ciu_qlm.s.txbypass = 1;
1243 ciu_qlm.s.txdeemph = 5;
1244 ciu_qlm.s.txmargin = 0x17;
1245 cvmx_write_csr(CVMX_CIU_QLM1, ciu_qlm.u64);
1246 } else {
1247 union cvmx_ciu_qlm ciu_qlm;
1248 ciu_qlm.u64 = cvmx_read_csr(CVMX_CIU_QLM0);
1249 ciu_qlm.s.txbypass = 1;
1250 ciu_qlm.s.txdeemph = 5;
1251 ciu_qlm.s.txmargin = 0x17;
1252 cvmx_write_csr(CVMX_CIU_QLM0, ciu_qlm.u64);
1253 }
1254 }
1255
1256 if (pcie_port)
1257 ciu_soft_prst.u64 = cvmx_read_csr(CVMX_CIU_SOFT_PRST1);
1258 else
1259 ciu_soft_prst.u64 = cvmx_read_csr(CVMX_CIU_SOFT_PRST);
1260
1261
1262
1263
1264
1265 if (ciu_soft_prst.s.soft_prst == 0) {
1266
1267 ciu_soft_prst.s.soft_prst = 1;
1268 if (pcie_port)
1269 cvmx_write_csr(CVMX_CIU_SOFT_PRST1, ciu_soft_prst.u64);
1270 else
1271 cvmx_write_csr(CVMX_CIU_SOFT_PRST, ciu_soft_prst.u64);
1272
1273 udelay(2000);
1274 }
1275 if (pcie_port) {
1276 ciu_soft_prst.u64 = cvmx_read_csr(CVMX_CIU_SOFT_PRST1);
1277 ciu_soft_prst.s.soft_prst = 0;
1278 cvmx_write_csr(CVMX_CIU_SOFT_PRST1, ciu_soft_prst.u64);
1279 } else {
1280 ciu_soft_prst.u64 = cvmx_read_csr(CVMX_CIU_SOFT_PRST);
1281 ciu_soft_prst.s.soft_prst = 0;
1282 cvmx_write_csr(CVMX_CIU_SOFT_PRST, ciu_soft_prst.u64);
1283 }
1284
1285
1286 udelay(1000);
1287
1288
1289
1290
1291
1292
1293 if (CVMX_WAIT_FOR_FIELD64(CVMX_MIO_RST_CTLX(pcie_port), union cvmx_mio_rst_ctlx, rst_done, ==, 1, 10000)) {
1294 pr_notice("PCIe: Port %d stuck in reset, skipping.\n", pcie_port);
1295 return -1;
1296 }
1297
1298
1299 pemx_bist_status.u64 = cvmx_read_csr(CVMX_PEMX_BIST_STATUS(pcie_port));
1300 if (pemx_bist_status.u64)
1301 pr_notice("PCIe: BIST FAILED for port %d (0x%016llx)\n", pcie_port, CAST64(pemx_bist_status.u64));
1302 pemx_bist_status2.u64 = cvmx_read_csr(CVMX_PEMX_BIST_STATUS2(pcie_port));
1303
1304 if (OCTEON_IS_MODEL(OCTEON_CN63XX_PASS1_X))
1305 pemx_bist_status2.u64 &= ~0x3full;
1306 if (pemx_bist_status2.u64)
1307 pr_notice("PCIe: BIST2 FAILED for port %d (0x%016llx)\n", pcie_port, CAST64(pemx_bist_status2.u64));
1308
1309
1310 __cvmx_pcie_rc_initialize_config_space(pcie_port);
1311
1312
1313 pciercx_cfg515.u32 = cvmx_pcie_cfgx_read(pcie_port, CVMX_PCIERCX_CFG515(pcie_port));
1314 pciercx_cfg515.s.dsc = 1;
1315 cvmx_pcie_cfgx_write(pcie_port, CVMX_PCIERCX_CFG515(pcie_port), pciercx_cfg515.u32);
1316
1317
1318 if (__cvmx_pcie_rc_initialize_link_gen2(pcie_port)) {
1319
1320
1321
1322
1323
1324 union cvmx_pciercx_cfg031 pciercx_cfg031;
1325 pciercx_cfg031.u32 = cvmx_pcie_cfgx_read(pcie_port, CVMX_PCIERCX_CFG031(pcie_port));
1326 pciercx_cfg031.s.mls = 1;
1327 cvmx_pcie_cfgx_write(pcie_port, CVMX_PCIERCX_CFG031(pcie_port), pciercx_cfg031.u32);
1328 if (__cvmx_pcie_rc_initialize_link_gen2(pcie_port)) {
1329 pr_notice("PCIe: Link timeout on port %d, probably the slot is empty\n", pcie_port);
1330 return -1;
1331 }
1332 }
1333
1334
1335 sli_mem_access_ctl.u64 = cvmx_read_csr(CVMX_PEXP_SLI_MEM_ACCESS_CTL);
1336 sli_mem_access_ctl.s.max_word = 0;
1337 sli_mem_access_ctl.s.timer = 127;
1338 cvmx_write_csr(CVMX_PEXP_SLI_MEM_ACCESS_CTL, sli_mem_access_ctl.u64);
1339
1340
1341 mem_access_subid.u64 = 0;
1342 mem_access_subid.s.port = pcie_port;
1343 mem_access_subid.s.nmerge = 0;
1344 mem_access_subid.s.esr = 1;
1345 mem_access_subid.s.esw = 1;
1346 mem_access_subid.s.wtype = 0;
1347 mem_access_subid.s.rtype = 0;
1348
1349 if (OCTEON_IS_MODEL(OCTEON_CN68XX))
1350 mem_access_subid.cn68xx.ba = 0;
1351 else
1352 mem_access_subid.s.ba = 0;
1353
1354
1355
1356
1357
1358 for (i = 12 + pcie_port * 4; i < 16 + pcie_port * 4; i++) {
1359 cvmx_write_csr(CVMX_PEXP_SLI_MEM_ACCESS_SUBIDX(i), mem_access_subid.u64);
1360
1361 __cvmx_increment_ba(&mem_access_subid);
1362 }
1363
1364
1365
1366
1367
1368
1369 for (i = 0; i < 4; i++) {
1370 cvmx_write_csr(CVMX_PEMX_P2P_BARX_START(i, pcie_port), -1);
1371 cvmx_write_csr(CVMX_PEMX_P2P_BARX_END(i, pcie_port), -1);
1372 }
1373
1374
1375 cvmx_write_csr(CVMX_PEMX_P2N_BAR0_START(pcie_port), 0);
1376
1377
1378
1379
1380
1381
1382
1383 cvmx_write_csr(CVMX_PEMX_P2N_BAR2_START(pcie_port), 0);
1384
1385
1386
1387
1388
1389
1390
1391
1392 pemx_bar_ctl.u64 = cvmx_read_csr(CVMX_PEMX_BAR_CTL(pcie_port));
1393 pemx_bar_ctl.s.bar1_siz = 3;
1394 pemx_bar_ctl.s.bar2_enb = 1;
1395 pemx_bar_ctl.s.bar2_esx = 1;
1396 pemx_bar_ctl.s.bar2_cax = 0;
1397 cvmx_write_csr(CVMX_PEMX_BAR_CTL(pcie_port), pemx_bar_ctl.u64);
1398 sli_ctl_portx.u64 = cvmx_read_csr(CVMX_PEXP_SLI_CTL_PORTX(pcie_port));
1399 sli_ctl_portx.s.ptlp_ro = 1;
1400 sli_ctl_portx.s.ctlp_ro = 1;
1401 sli_ctl_portx.s.wait_com = 0;
1402 sli_ctl_portx.s.waitl_com = 0;
1403 cvmx_write_csr(CVMX_PEXP_SLI_CTL_PORTX(pcie_port), sli_ctl_portx.u64);
1404
1405
1406 cvmx_write_csr(CVMX_PEMX_P2N_BAR1_START(pcie_port), CVMX_PCIE_BAR1_RC_BASE);
1407
1408 bar1_index.u64 = 0;
1409 bar1_index.s.addr_idx = (CVMX_PCIE_BAR1_PHYS_BASE >> 22);
1410 bar1_index.s.ca = 1;
1411 bar1_index.s.end_swp = 1;
1412 bar1_index.s.addr_v = 1;
1413
1414 for (i = 0; i < 16; i++) {
1415 cvmx_write_csr(CVMX_PEMX_BAR1_INDEXX(i, pcie_port), bar1_index.u64);
1416
1417 bar1_index.s.addr_idx += (((1ull << 28) / 16ull) >> 22);
1418 }
1419
1420
1421
1422
1423
1424 pemx_ctl_status.u64 = cvmx_read_csr(CVMX_PEMX_CTL_STATUS(pcie_port));
1425 pemx_ctl_status.s.cfg_rtry = 250 * 5000000 / 0x10000;
1426 cvmx_write_csr(CVMX_PEMX_CTL_STATUS(pcie_port), pemx_ctl_status.u64);
1427
1428
1429 pciercx_cfg032.u32 = cvmx_pcie_cfgx_read(pcie_port, CVMX_PCIERCX_CFG032(pcie_port));
1430 pr_notice("PCIe: Port %d link active, %d lanes, speed gen%d\n", pcie_port, pciercx_cfg032.s.nlw, pciercx_cfg032.s.ls);
1431
1432 return 0;
1433 }
1434
1435
1436
1437
1438
1439
1440
1441
1442 static int cvmx_pcie_rc_initialize(int pcie_port)
1443 {
1444 int result;
1445 if (octeon_has_feature(OCTEON_FEATURE_NPEI))
1446 result = __cvmx_pcie_rc_initialize_gen1(pcie_port);
1447 else
1448 result = __cvmx_pcie_rc_initialize_gen2(pcie_port);
1449 return result;
1450 }
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465 int octeon_pcie_pcibios_map_irq(const struct pci_dev *dev, u8 slot, u8 pin)
1466 {
1467
1468
1469
1470
1471
1472
1473 if (strstr(octeon_board_type_string(), "EBH5600") &&
1474 dev->bus && dev->bus->parent) {
1475
1476
1477
1478
1479 while (dev->bus && dev->bus->parent)
1480 dev = to_pci_dev(dev->bus->bridge);
1481
1482
1483
1484
1485
1486 if ((dev->bus->number == 1) &&
1487 (dev->vendor == 0x10b5) && (dev->device == 0x8114)) {
1488
1489
1490
1491
1492 pin = ((pin - 3) & 3) + 1;
1493 }
1494 }
1495
1496
1497
1498
1499
1500 return pin - 1 + OCTEON_IRQ_PCI_INT0;
1501 }
1502
1503 static void set_cfg_read_retry(u32 retry_cnt)
1504 {
1505 union cvmx_pemx_ctl_status pemx_ctl;
1506 pemx_ctl.u64 = cvmx_read_csr(CVMX_PEMX_CTL_STATUS(1));
1507 pemx_ctl.s.cfg_rtry = retry_cnt;
1508 cvmx_write_csr(CVMX_PEMX_CTL_STATUS(1), pemx_ctl.u64);
1509 }
1510
1511
1512 static u32 disable_cfg_read_retry(void)
1513 {
1514 u32 retry_cnt;
1515
1516 union cvmx_pemx_ctl_status pemx_ctl;
1517 pemx_ctl.u64 = cvmx_read_csr(CVMX_PEMX_CTL_STATUS(1));
1518 retry_cnt = pemx_ctl.s.cfg_rtry;
1519 pemx_ctl.s.cfg_rtry = 0;
1520 cvmx_write_csr(CVMX_PEMX_CTL_STATUS(1), pemx_ctl.u64);
1521 return retry_cnt;
1522 }
1523
1524 static int is_cfg_retry(void)
1525 {
1526 union cvmx_pemx_int_sum pemx_int_sum;
1527 pemx_int_sum.u64 = cvmx_read_csr(CVMX_PEMX_INT_SUM(1));
1528 if (pemx_int_sum.s.crs_dr)
1529 return 1;
1530 return 0;
1531 }
1532
1533
1534
1535
1536
1537 static int octeon_pcie_read_config(unsigned int pcie_port, struct pci_bus *bus,
1538 unsigned int devfn, int reg, int size,
1539 u32 *val)
1540 {
1541 union octeon_cvmemctl cvmmemctl;
1542 union octeon_cvmemctl cvmmemctl_save;
1543 int bus_number = bus->number;
1544 int cfg_retry = 0;
1545 int retry_cnt = 0;
1546 int max_retry_cnt = 10;
1547 u32 cfg_retry_cnt = 0;
1548
1549 cvmmemctl_save.u64 = 0;
1550 BUG_ON(pcie_port >= ARRAY_SIZE(enable_pcie_bus_num_war));
1551
1552
1553
1554
1555 if (bus->parent == NULL) {
1556 if (enable_pcie_bus_num_war[pcie_port])
1557 bus_number = 0;
1558 else {
1559 union cvmx_pciercx_cfg006 pciercx_cfg006;
1560 pciercx_cfg006.u32 = cvmx_pcie_cfgx_read(pcie_port,
1561 CVMX_PCIERCX_CFG006(pcie_port));
1562 if (pciercx_cfg006.s.pbnum != bus_number) {
1563 pciercx_cfg006.s.pbnum = bus_number;
1564 pciercx_cfg006.s.sbnum = bus_number;
1565 pciercx_cfg006.s.subbnum = bus_number;
1566 cvmx_pcie_cfgx_write(pcie_port,
1567 CVMX_PCIERCX_CFG006(pcie_port),
1568 pciercx_cfg006.u32);
1569 }
1570 }
1571 }
1572
1573
1574
1575
1576
1577
1578 if ((bus->parent == NULL) && (devfn >> 3 != 0))
1579 return PCIBIOS_FUNC_NOT_SUPPORTED;
1580
1581
1582
1583
1584
1585
1586
1587 if (OCTEON_IS_MODEL(OCTEON_CN56XX_PASS1) ||
1588 OCTEON_IS_MODEL(OCTEON_CN56XX_PASS1_1)) {
1589
1590
1591
1592
1593
1594
1595
1596 if ((bus->parent == NULL) && (devfn >= 2))
1597 return PCIBIOS_FUNC_NOT_SUPPORTED;
1598
1599
1600
1601
1602
1603 #if 1
1604
1605 if (bus_number == 2)
1606 return PCIBIOS_FUNC_NOT_SUPPORTED;
1607 #elif 0
1608
1609
1610
1611
1612 if ((bus_number == 2) && (devfn >> 3 != 2))
1613 return PCIBIOS_FUNC_NOT_SUPPORTED;
1614 #elif 0
1615
1616
1617
1618
1619 if ((bus_number == 2) && (devfn >> 3 != 3))
1620 return PCIBIOS_FUNC_NOT_SUPPORTED;
1621 #elif 0
1622
1623 if ((bus_number == 2) &&
1624 !((devfn == (2 << 3)) || (devfn == (3 << 3))))
1625 return PCIBIOS_FUNC_NOT_SUPPORTED;
1626 #endif
1627
1628
1629
1630
1631
1632 #if 0
1633
1634 if ((bus_number == 4) &&
1635 !((devfn >> 3 >= 1) && (devfn >> 3 <= 4)))
1636 return PCIBIOS_FUNC_NOT_SUPPORTED;
1637
1638 if ((bus_number == 5) && (devfn >> 3 != 0))
1639 return PCIBIOS_FUNC_NOT_SUPPORTED;
1640
1641 if ((bus_number == 6) && (devfn >> 3 != 0))
1642 return PCIBIOS_FUNC_NOT_SUPPORTED;
1643
1644 if ((bus_number == 7) && (devfn >> 3 != 0))
1645 return PCIBIOS_FUNC_NOT_SUPPORTED;
1646
1647 if ((bus_number == 8) && (devfn >> 3 != 0))
1648 return PCIBIOS_FUNC_NOT_SUPPORTED;
1649 #endif
1650
1651
1652
1653
1654
1655
1656
1657
1658 cvmmemctl_save.u64 = __read_64bit_c0_register($11, 7);
1659 cvmmemctl.u64 = cvmmemctl_save.u64;
1660 cvmmemctl.s.didtto = 2;
1661 __write_64bit_c0_register($11, 7, cvmmemctl.u64);
1662 }
1663
1664 if ((OCTEON_IS_MODEL(OCTEON_CN63XX)) && (enable_pcie_14459_war))
1665 cfg_retry_cnt = disable_cfg_read_retry();
1666
1667 pr_debug("pcie_cfg_rd port=%d b=%d devfn=0x%03x reg=0x%03x"
1668 " size=%d ", pcie_port, bus_number, devfn, reg, size);
1669 do {
1670 switch (size) {
1671 case 4:
1672 *val = cvmx_pcie_config_read32(pcie_port, bus_number,
1673 devfn >> 3, devfn & 0x7, reg);
1674 break;
1675 case 2:
1676 *val = cvmx_pcie_config_read16(pcie_port, bus_number,
1677 devfn >> 3, devfn & 0x7, reg);
1678 break;
1679 case 1:
1680 *val = cvmx_pcie_config_read8(pcie_port, bus_number,
1681 devfn >> 3, devfn & 0x7, reg);
1682 break;
1683 default:
1684 if (OCTEON_IS_MODEL(OCTEON_CN63XX))
1685 set_cfg_read_retry(cfg_retry_cnt);
1686 return PCIBIOS_FUNC_NOT_SUPPORTED;
1687 }
1688 if ((OCTEON_IS_MODEL(OCTEON_CN63XX)) &&
1689 (enable_pcie_14459_war)) {
1690 cfg_retry = is_cfg_retry();
1691 retry_cnt++;
1692 if (retry_cnt > max_retry_cnt) {
1693 pr_err(" pcie cfg_read retries failed. retry_cnt=%d\n",
1694 retry_cnt);
1695 cfg_retry = 0;
1696 }
1697 }
1698 } while (cfg_retry);
1699
1700 if ((OCTEON_IS_MODEL(OCTEON_CN63XX)) && (enable_pcie_14459_war))
1701 set_cfg_read_retry(cfg_retry_cnt);
1702 pr_debug("val=%08x : tries=%02d\n", *val, retry_cnt);
1703 if (OCTEON_IS_MODEL(OCTEON_CN56XX_PASS1) ||
1704 OCTEON_IS_MODEL(OCTEON_CN56XX_PASS1_1))
1705 write_c0_cvmmemctl(cvmmemctl_save.u64);
1706 return PCIBIOS_SUCCESSFUL;
1707 }
1708
1709 static int octeon_pcie0_read_config(struct pci_bus *bus, unsigned int devfn,
1710 int reg, int size, u32 *val)
1711 {
1712 return octeon_pcie_read_config(0, bus, devfn, reg, size, val);
1713 }
1714
1715 static int octeon_pcie1_read_config(struct pci_bus *bus, unsigned int devfn,
1716 int reg, int size, u32 *val)
1717 {
1718 return octeon_pcie_read_config(1, bus, devfn, reg, size, val);
1719 }
1720
1721 static int octeon_dummy_read_config(struct pci_bus *bus, unsigned int devfn,
1722 int reg, int size, u32 *val)
1723 {
1724 return PCIBIOS_FUNC_NOT_SUPPORTED;
1725 }
1726
1727
1728
1729
1730 static int octeon_pcie_write_config(unsigned int pcie_port, struct pci_bus *bus,
1731 unsigned int devfn, int reg,
1732 int size, u32 val)
1733 {
1734 int bus_number = bus->number;
1735
1736 BUG_ON(pcie_port >= ARRAY_SIZE(enable_pcie_bus_num_war));
1737
1738 if ((bus->parent == NULL) && (enable_pcie_bus_num_war[pcie_port]))
1739 bus_number = 0;
1740
1741 pr_debug("pcie_cfg_wr port=%d b=%d devfn=0x%03x"
1742 " reg=0x%03x size=%d val=%08x\n", pcie_port, bus_number, devfn,
1743 reg, size, val);
1744
1745
1746 switch (size) {
1747 case 4:
1748 cvmx_pcie_config_write32(pcie_port, bus_number, devfn >> 3,
1749 devfn & 0x7, reg, val);
1750 break;
1751 case 2:
1752 cvmx_pcie_config_write16(pcie_port, bus_number, devfn >> 3,
1753 devfn & 0x7, reg, val);
1754 break;
1755 case 1:
1756 cvmx_pcie_config_write8(pcie_port, bus_number, devfn >> 3,
1757 devfn & 0x7, reg, val);
1758 break;
1759 default:
1760 return PCIBIOS_FUNC_NOT_SUPPORTED;
1761 }
1762 return PCIBIOS_SUCCESSFUL;
1763 }
1764
1765 static int octeon_pcie0_write_config(struct pci_bus *bus, unsigned int devfn,
1766 int reg, int size, u32 val)
1767 {
1768 return octeon_pcie_write_config(0, bus, devfn, reg, size, val);
1769 }
1770
1771 static int octeon_pcie1_write_config(struct pci_bus *bus, unsigned int devfn,
1772 int reg, int size, u32 val)
1773 {
1774 return octeon_pcie_write_config(1, bus, devfn, reg, size, val);
1775 }
1776
1777 static int octeon_dummy_write_config(struct pci_bus *bus, unsigned int devfn,
1778 int reg, int size, u32 val)
1779 {
1780 return PCIBIOS_FUNC_NOT_SUPPORTED;
1781 }
1782
1783 static struct pci_ops octeon_pcie0_ops = {
1784 .read = octeon_pcie0_read_config,
1785 .write = octeon_pcie0_write_config,
1786 };
1787
1788 static struct resource octeon_pcie0_mem_resource = {
1789 .name = "Octeon PCIe0 MEM",
1790 .flags = IORESOURCE_MEM,
1791 };
1792
1793 static struct resource octeon_pcie0_io_resource = {
1794 .name = "Octeon PCIe0 IO",
1795 .flags = IORESOURCE_IO,
1796 };
1797
1798 static struct pci_controller octeon_pcie0_controller = {
1799 .pci_ops = &octeon_pcie0_ops,
1800 .mem_resource = &octeon_pcie0_mem_resource,
1801 .io_resource = &octeon_pcie0_io_resource,
1802 };
1803
1804 static struct pci_ops octeon_pcie1_ops = {
1805 .read = octeon_pcie1_read_config,
1806 .write = octeon_pcie1_write_config,
1807 };
1808
1809 static struct resource octeon_pcie1_mem_resource = {
1810 .name = "Octeon PCIe1 MEM",
1811 .flags = IORESOURCE_MEM,
1812 };
1813
1814 static struct resource octeon_pcie1_io_resource = {
1815 .name = "Octeon PCIe1 IO",
1816 .flags = IORESOURCE_IO,
1817 };
1818
1819 static struct pci_controller octeon_pcie1_controller = {
1820 .pci_ops = &octeon_pcie1_ops,
1821 .mem_resource = &octeon_pcie1_mem_resource,
1822 .io_resource = &octeon_pcie1_io_resource,
1823 };
1824
1825 static struct pci_ops octeon_dummy_ops = {
1826 .read = octeon_dummy_read_config,
1827 .write = octeon_dummy_write_config,
1828 };
1829
1830 static struct resource octeon_dummy_mem_resource = {
1831 .name = "Virtual PCIe MEM",
1832 .flags = IORESOURCE_MEM,
1833 };
1834
1835 static struct resource octeon_dummy_io_resource = {
1836 .name = "Virtual PCIe IO",
1837 .flags = IORESOURCE_IO,
1838 };
1839
1840 static struct pci_controller octeon_dummy_controller = {
1841 .pci_ops = &octeon_dummy_ops,
1842 .mem_resource = &octeon_dummy_mem_resource,
1843 .io_resource = &octeon_dummy_io_resource,
1844 };
1845
1846 static int device_needs_bus_num_war(uint32_t deviceid)
1847 {
1848 #define IDT_VENDOR_ID 0x111d
1849
1850 if ((deviceid & 0xffff) == IDT_VENDOR_ID)
1851 return 1;
1852 return 0;
1853 }
1854
1855
1856
1857
1858
1859
1860 static int __init octeon_pcie_setup(void)
1861 {
1862 int result;
1863 int host_mode;
1864 int srio_war15205 = 0, port;
1865 union cvmx_sli_ctl_portx sli_ctl_portx;
1866 union cvmx_sriox_status_reg sriox_status_reg;
1867
1868
1869 if (!octeon_has_feature(OCTEON_FEATURE_PCIE))
1870 return 0;
1871
1872
1873 if (octeon_is_simulation())
1874 return 0;
1875
1876
1877 if (pcie_disable)
1878 return 0;
1879
1880
1881 octeon_pcibios_map_irq = octeon_pcie_pcibios_map_irq;
1882
1883
1884
1885
1886
1887 set_io_port_base(CVMX_ADD_IO_SEG(cvmx_pcie_get_io_base_address(0)));
1888 ioport_resource.start = 0;
1889 ioport_resource.end =
1890 cvmx_pcie_get_io_base_address(1) -
1891 cvmx_pcie_get_io_base_address(0) + cvmx_pcie_get_io_size(1) - 1;
1892
1893
1894
1895
1896
1897
1898
1899 octeon_dummy_controller.io_map_base = -1;
1900 octeon_dummy_controller.mem_resource->start = (1ull<<48);
1901 octeon_dummy_controller.mem_resource->end = (1ull<<48);
1902 register_pci_controller(&octeon_dummy_controller);
1903
1904 if (octeon_has_feature(OCTEON_FEATURE_NPEI)) {
1905 union cvmx_npei_ctl_status npei_ctl_status;
1906 npei_ctl_status.u64 = cvmx_read_csr(CVMX_PEXP_NPEI_CTL_STATUS);
1907 host_mode = npei_ctl_status.s.host_mode;
1908 octeon_dma_bar_type = OCTEON_DMA_BAR_TYPE_PCIE;
1909 } else {
1910 union cvmx_mio_rst_ctlx mio_rst_ctl;
1911 mio_rst_ctl.u64 = cvmx_read_csr(CVMX_MIO_RST_CTLX(0));
1912 host_mode = mio_rst_ctl.s.host_mode;
1913 octeon_dma_bar_type = OCTEON_DMA_BAR_TYPE_PCIE2;
1914 }
1915
1916 if (host_mode) {
1917 pr_notice("PCIe: Initializing port 0\n");
1918
1919 if (OCTEON_IS_MODEL(OCTEON_CN63XX_PASS1_X) ||
1920 OCTEON_IS_MODEL(OCTEON_CN63XX_PASS2_0)) {
1921 sriox_status_reg.u64 = cvmx_read_csr(CVMX_SRIOX_STATUS_REG(0));
1922 if (sriox_status_reg.s.srio) {
1923 srio_war15205 += 1;
1924 port = 0;
1925 }
1926 }
1927 result = cvmx_pcie_rc_initialize(0);
1928 if (result == 0) {
1929 uint32_t device0;
1930
1931 octeon_pcie0_controller.mem_offset =
1932 cvmx_pcie_get_mem_base_address(0);
1933
1934 octeon_pcie0_controller.io_map_base =
1935 CVMX_ADD_IO_SEG(cvmx_pcie_get_io_base_address
1936 (0));
1937 octeon_pcie0_controller.io_offset = 0;
1938
1939
1940
1941
1942
1943
1944
1945 octeon_pcie0_controller.mem_resource->start =
1946 cvmx_pcie_get_mem_base_address(0) +
1947 (4ul << 30) - (OCTEON_PCI_BAR1_HOLE_SIZE << 20);
1948 octeon_pcie0_controller.mem_resource->end =
1949 cvmx_pcie_get_mem_base_address(0) +
1950 cvmx_pcie_get_mem_size(0) - 1;
1951
1952
1953
1954
1955 octeon_pcie0_controller.io_resource->start = 4 << 10;
1956 octeon_pcie0_controller.io_resource->end =
1957 cvmx_pcie_get_io_size(0) - 1;
1958 msleep(100);
1959 register_pci_controller(&octeon_pcie0_controller);
1960 device0 = cvmx_pcie_config_read32(0, 0, 0, 0, 0);
1961 enable_pcie_bus_num_war[0] =
1962 device_needs_bus_num_war(device0);
1963 }
1964 } else {
1965 pr_notice("PCIe: Port 0 in endpoint mode, skipping.\n");
1966
1967 if (OCTEON_IS_MODEL(OCTEON_CN63XX_PASS1_X) ||
1968 OCTEON_IS_MODEL(OCTEON_CN63XX_PASS2_0)) {
1969 srio_war15205 += 1;
1970 port = 0;
1971 }
1972 }
1973
1974 if (octeon_has_feature(OCTEON_FEATURE_NPEI)) {
1975 host_mode = 1;
1976
1977 if (OCTEON_IS_MODEL(OCTEON_CN52XX)) {
1978 union cvmx_npei_dbg_data dbg_data;
1979 dbg_data.u64 = cvmx_read_csr(CVMX_PEXP_NPEI_DBG_DATA);
1980 if (dbg_data.cn52xx.qlm0_link_width)
1981 host_mode = 0;
1982 }
1983 } else {
1984 union cvmx_mio_rst_ctlx mio_rst_ctl;
1985 mio_rst_ctl.u64 = cvmx_read_csr(CVMX_MIO_RST_CTLX(1));
1986 host_mode = mio_rst_ctl.s.host_mode;
1987 }
1988
1989 if (host_mode) {
1990 pr_notice("PCIe: Initializing port 1\n");
1991
1992 if (OCTEON_IS_MODEL(OCTEON_CN63XX_PASS1_X) ||
1993 OCTEON_IS_MODEL(OCTEON_CN63XX_PASS2_0)) {
1994 sriox_status_reg.u64 = cvmx_read_csr(CVMX_SRIOX_STATUS_REG(1));
1995 if (sriox_status_reg.s.srio) {
1996 srio_war15205 += 1;
1997 port = 1;
1998 }
1999 }
2000 result = cvmx_pcie_rc_initialize(1);
2001 if (result == 0) {
2002 uint32_t device0;
2003
2004 octeon_pcie1_controller.mem_offset =
2005 cvmx_pcie_get_mem_base_address(1);
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015 octeon_pcie1_controller.io_map_base =
2016 CVMX_ADD_IO_SEG(cvmx_pcie_get_io_base_address(0));
2017
2018 octeon_pcie1_controller.io_offset =
2019 cvmx_pcie_get_io_base_address(1) -
2020 cvmx_pcie_get_io_base_address(0);
2021
2022
2023
2024
2025
2026
2027 octeon_pcie1_controller.mem_resource->start =
2028 cvmx_pcie_get_mem_base_address(1) + (4ul << 30) -
2029 (OCTEON_PCI_BAR1_HOLE_SIZE << 20);
2030 octeon_pcie1_controller.mem_resource->end =
2031 cvmx_pcie_get_mem_base_address(1) +
2032 cvmx_pcie_get_mem_size(1) - 1;
2033
2034
2035
2036
2037 octeon_pcie1_controller.io_resource->start =
2038 cvmx_pcie_get_io_base_address(1) -
2039 cvmx_pcie_get_io_base_address(0);
2040 octeon_pcie1_controller.io_resource->end =
2041 octeon_pcie1_controller.io_resource->start +
2042 cvmx_pcie_get_io_size(1) - 1;
2043 msleep(100);
2044 register_pci_controller(&octeon_pcie1_controller);
2045 device0 = cvmx_pcie_config_read32(1, 0, 0, 0, 0);
2046 enable_pcie_bus_num_war[1] =
2047 device_needs_bus_num_war(device0);
2048 }
2049 } else {
2050 pr_notice("PCIe: Port 1 not in root complex mode, skipping.\n");
2051
2052 if (OCTEON_IS_MODEL(OCTEON_CN63XX_PASS1_X) ||
2053 OCTEON_IS_MODEL(OCTEON_CN63XX_PASS2_0)) {
2054 srio_war15205 += 1;
2055 port = 1;
2056 }
2057 }
2058
2059
2060
2061
2062
2063
2064
2065 if (OCTEON_IS_MODEL(OCTEON_CN63XX_PASS1_X) ||
2066 OCTEON_IS_MODEL(OCTEON_CN63XX_PASS2_0)) {
2067 if (srio_war15205 == 1) {
2068 sli_ctl_portx.u64 = cvmx_read_csr(CVMX_PEXP_SLI_CTL_PORTX(port));
2069 sli_ctl_portx.s.inta_map = 1;
2070 sli_ctl_portx.s.intb_map = 1;
2071 sli_ctl_portx.s.intc_map = 1;
2072 sli_ctl_portx.s.intd_map = 1;
2073 cvmx_write_csr(CVMX_PEXP_SLI_CTL_PORTX(port), sli_ctl_portx.u64);
2074
2075 sli_ctl_portx.u64 = cvmx_read_csr(CVMX_PEXP_SLI_CTL_PORTX(!port));
2076 sli_ctl_portx.s.inta_map = 0;
2077 sli_ctl_portx.s.intb_map = 0;
2078 sli_ctl_portx.s.intc_map = 0;
2079 sli_ctl_portx.s.intd_map = 0;
2080 cvmx_write_csr(CVMX_PEXP_SLI_CTL_PORTX(!port), sli_ctl_portx.u64);
2081 }
2082 }
2083
2084 octeon_pci_dma_init();
2085
2086 return 0;
2087 }
2088 arch_initcall(octeon_pcie_setup);