aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--drivers/ntb/ntb_hw.c567
-rw-r--r--drivers/ntb/ntb_hw.h19
-rw-r--r--drivers/ntb/ntb_regs.h38
3 files changed, 501 insertions, 123 deletions
diff --git a/drivers/ntb/ntb_hw.c b/drivers/ntb/ntb_hw.c
index 372e08c4ffef..cd29b1038c5e 100644
--- a/drivers/ntb/ntb_hw.c
+++ b/drivers/ntb/ntb_hw.c
@@ -64,10 +64,6 @@ MODULE_VERSION(NTB_VER);
64MODULE_LICENSE("Dual BSD/GPL"); 64MODULE_LICENSE("Dual BSD/GPL");
65MODULE_AUTHOR("Intel Corporation"); 65MODULE_AUTHOR("Intel Corporation");
66 66
67static bool xeon_errata_workaround = true;
68module_param(xeon_errata_workaround, bool, 0644);
69MODULE_PARM_DESC(xeon_errata_workaround, "Workaround for the Xeon Errata");
70
71enum { 67enum {
72 NTB_CONN_TRANSPARENT = 0, 68 NTB_CONN_TRANSPARENT = 0,
73 NTB_CONN_B2B, 69 NTB_CONN_B2B,
@@ -88,8 +84,8 @@ static struct dentry *debugfs_dir;
88 84
89#define BWD_LINK_RECOVERY_TIME 500 85#define BWD_LINK_RECOVERY_TIME 500
90 86
91/* Translate memory window 0,1 to BAR 2,4 */ 87/* Translate memory window 0,1,2 to BAR 2,4,5 */
92#define MW_TO_BAR(mw) (mw * NTB_MAX_NUM_MW + 2) 88#define MW_TO_BAR(mw) (mw == 0 ? 2 : (mw == 1 ? 4 : 5))
93 89
94static const struct pci_device_id ntb_pci_tbl[] = { 90static const struct pci_device_id ntb_pci_tbl[] = {
95 {PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_NTB_B2B_BWD)}, 91 {PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_NTB_B2B_BWD)},
@@ -109,6 +105,65 @@ static const struct pci_device_id ntb_pci_tbl[] = {
109}; 105};
110MODULE_DEVICE_TABLE(pci, ntb_pci_tbl); 106MODULE_DEVICE_TABLE(pci, ntb_pci_tbl);
111 107
108static int is_ntb_xeon(struct ntb_device *ndev)
109{
110 switch (ndev->pdev->device) {
111 case PCI_DEVICE_ID_INTEL_NTB_SS_JSF:
112 case PCI_DEVICE_ID_INTEL_NTB_SS_SNB:
113 case PCI_DEVICE_ID_INTEL_NTB_SS_IVT:
114 case PCI_DEVICE_ID_INTEL_NTB_SS_HSX:
115 case PCI_DEVICE_ID_INTEL_NTB_PS_JSF:
116 case PCI_DEVICE_ID_INTEL_NTB_PS_SNB:
117 case PCI_DEVICE_ID_INTEL_NTB_PS_IVT:
118 case PCI_DEVICE_ID_INTEL_NTB_PS_HSX:
119 case PCI_DEVICE_ID_INTEL_NTB_B2B_JSF:
120 case PCI_DEVICE_ID_INTEL_NTB_B2B_SNB:
121 case PCI_DEVICE_ID_INTEL_NTB_B2B_IVT:
122 case PCI_DEVICE_ID_INTEL_NTB_B2B_HSX:
123 return 1;
124 default:
125 return 0;
126 }
127
128 return 0;
129}
130
131static int is_ntb_atom(struct ntb_device *ndev)
132{
133 switch (ndev->pdev->device) {
134 case PCI_DEVICE_ID_INTEL_NTB_B2B_BWD:
135 return 1;
136 default:
137 return 0;
138 }
139
140 return 0;
141}
142
143static void ntb_set_errata_flags(struct ntb_device *ndev)
144{
145 switch (ndev->pdev->device) {
146 /*
147 * this workaround applies to all platform up to IvyBridge
148 * Haswell has splitbar support and use a different workaround
149 */
150 case PCI_DEVICE_ID_INTEL_NTB_SS_JSF:
151 case PCI_DEVICE_ID_INTEL_NTB_SS_SNB:
152 case PCI_DEVICE_ID_INTEL_NTB_SS_IVT:
153 case PCI_DEVICE_ID_INTEL_NTB_SS_HSX:
154 case PCI_DEVICE_ID_INTEL_NTB_PS_JSF:
155 case PCI_DEVICE_ID_INTEL_NTB_PS_SNB:
156 case PCI_DEVICE_ID_INTEL_NTB_PS_IVT:
157 case PCI_DEVICE_ID_INTEL_NTB_PS_HSX:
158 case PCI_DEVICE_ID_INTEL_NTB_B2B_JSF:
159 case PCI_DEVICE_ID_INTEL_NTB_B2B_SNB:
160 case PCI_DEVICE_ID_INTEL_NTB_B2B_IVT:
161 case PCI_DEVICE_ID_INTEL_NTB_B2B_HSX:
162 ndev->wa_flags |= WA_SNB_ERR;
163 break;
164 }
165}
166
112/** 167/**
113 * ntb_register_event_callback() - register event callback 168 * ntb_register_event_callback() - register event callback
114 * @ndev: pointer to ntb_device instance 169 * @ndev: pointer to ntb_device instance
@@ -451,8 +506,14 @@ void ntb_set_mw_addr(struct ntb_device *ndev, unsigned int mw, u64 addr)
451 case NTB_BAR_23: 506 case NTB_BAR_23:
452 writeq(addr, ndev->reg_ofs.bar2_xlat); 507 writeq(addr, ndev->reg_ofs.bar2_xlat);
453 break; 508 break;
454 case NTB_BAR_45: 509 case NTB_BAR_4:
455 writeq(addr, ndev->reg_ofs.bar4_xlat); 510 if (ndev->split_bar)
511 writel(addr, ndev->reg_ofs.bar4_xlat);
512 else
513 writeq(addr, ndev->reg_ofs.bar4_xlat);
514 break;
515 case NTB_BAR_5:
516 writel(addr, ndev->reg_ofs.bar5_xlat);
456 break; 517 break;
457 } 518 }
458} 519}
@@ -535,7 +596,7 @@ static void ntb_link_event(struct ntb_device *ndev, int link_state)
535 ndev->link_status = NTB_LINK_UP; 596 ndev->link_status = NTB_LINK_UP;
536 event = NTB_EVENT_HW_LINK_UP; 597 event = NTB_EVENT_HW_LINK_UP;
537 598
538 if (ndev->hw_type == BWD_HW || 599 if (is_ntb_atom(ndev) ||
539 ndev->conn_type == NTB_CONN_TRANSPARENT) 600 ndev->conn_type == NTB_CONN_TRANSPARENT)
540 status = readw(ndev->reg_ofs.lnk_stat); 601 status = readw(ndev->reg_ofs.lnk_stat);
541 else { 602 else {
@@ -566,7 +627,7 @@ static int ntb_link_status(struct ntb_device *ndev)
566{ 627{
567 int link_state; 628 int link_state;
568 629
569 if (ndev->hw_type == BWD_HW) { 630 if (is_ntb_atom(ndev)) {
570 u32 ntb_cntl; 631 u32 ntb_cntl;
571 632
572 ntb_cntl = readl(ndev->reg_ofs.lnk_cntl); 633 ntb_cntl = readl(ndev->reg_ofs.lnk_cntl);
@@ -667,29 +728,16 @@ static void bwd_link_poll(struct work_struct *work)
667 728
668static int ntb_xeon_setup(struct ntb_device *ndev) 729static int ntb_xeon_setup(struct ntb_device *ndev)
669{ 730{
670 int rc; 731 switch (ndev->conn_type) {
671 u8 val;
672
673 ndev->hw_type = SNB_HW;
674
675 rc = pci_read_config_byte(ndev->pdev, NTB_PPD_OFFSET, &val);
676 if (rc)
677 return rc;
678
679 if (val & SNB_PPD_DEV_TYPE)
680 ndev->dev_type = NTB_DEV_USD;
681 else
682 ndev->dev_type = NTB_DEV_DSD;
683
684 switch (val & SNB_PPD_CONN_TYPE) {
685 case NTB_CONN_B2B: 732 case NTB_CONN_B2B:
686 dev_info(&ndev->pdev->dev, "Conn Type = B2B\n");
687 ndev->conn_type = NTB_CONN_B2B;
688 ndev->reg_ofs.ldb = ndev->reg_base + SNB_PDOORBELL_OFFSET; 733 ndev->reg_ofs.ldb = ndev->reg_base + SNB_PDOORBELL_OFFSET;
689 ndev->reg_ofs.ldb_mask = ndev->reg_base + SNB_PDBMSK_OFFSET; 734 ndev->reg_ofs.ldb_mask = ndev->reg_base + SNB_PDBMSK_OFFSET;
690 ndev->reg_ofs.spad_read = ndev->reg_base + SNB_SPAD_OFFSET; 735 ndev->reg_ofs.spad_read = ndev->reg_base + SNB_SPAD_OFFSET;
691 ndev->reg_ofs.bar2_xlat = ndev->reg_base + SNB_SBAR2XLAT_OFFSET; 736 ndev->reg_ofs.bar2_xlat = ndev->reg_base + SNB_SBAR2XLAT_OFFSET;
692 ndev->reg_ofs.bar4_xlat = ndev->reg_base + SNB_SBAR4XLAT_OFFSET; 737 ndev->reg_ofs.bar4_xlat = ndev->reg_base + SNB_SBAR4XLAT_OFFSET;
738 if (ndev->split_bar)
739 ndev->reg_ofs.bar5_xlat =
740 ndev->reg_base + SNB_SBAR5XLAT_OFFSET;
693 ndev->limits.max_spads = SNB_MAX_B2B_SPADS; 741 ndev->limits.max_spads = SNB_MAX_B2B_SPADS;
694 742
695 /* There is a Xeon hardware errata related to writes to 743 /* There is a Xeon hardware errata related to writes to
@@ -698,16 +746,17 @@ static int ntb_xeon_setup(struct ntb_device *ndev)
698 * this use the second memory window to access the interrupt and 746 * this use the second memory window to access the interrupt and
699 * scratch pad registers on the remote system. 747 * scratch pad registers on the remote system.
700 */ 748 */
701 if (xeon_errata_workaround) { 749 if (ndev->wa_flags & WA_SNB_ERR) {
702 if (!ndev->mw[1].bar_sz) 750 if (!ndev->mw[ndev->limits.max_mw - 1].bar_sz)
703 return -EINVAL; 751 return -EINVAL;
704 752
705 ndev->limits.max_mw = SNB_ERRATA_MAX_MW;
706 ndev->limits.max_db_bits = SNB_MAX_DB_BITS; 753 ndev->limits.max_db_bits = SNB_MAX_DB_BITS;
707 ndev->reg_ofs.spad_write = ndev->mw[1].vbase + 754 ndev->reg_ofs.spad_write =
708 SNB_SPAD_OFFSET; 755 ndev->mw[ndev->limits.max_mw - 1].vbase +
709 ndev->reg_ofs.rdb = ndev->mw[1].vbase + 756 SNB_SPAD_OFFSET;
710 SNB_PDOORBELL_OFFSET; 757 ndev->reg_ofs.rdb =
758 ndev->mw[ndev->limits.max_mw - 1].vbase +
759 SNB_PDOORBELL_OFFSET;
711 760
712 /* Set the Limit register to 4k, the minimum size, to 761 /* Set the Limit register to 4k, the minimum size, to
713 * prevent an illegal access 762 * prevent an illegal access
@@ -720,9 +769,9 @@ static int ntb_xeon_setup(struct ntb_device *ndev)
720 * the driver defaults, but write the Limit registers 769 * the driver defaults, but write the Limit registers
721 * first just in case. 770 * first just in case.
722 */ 771 */
723 } else {
724 ndev->limits.max_mw = SNB_MAX_MW;
725 772
773 ndev->limits.max_mw = SNB_ERRATA_MAX_MW;
774 } else {
726 /* HW Errata on bit 14 of b2bdoorbell register. Writes 775 /* HW Errata on bit 14 of b2bdoorbell register. Writes
727 * will not be mirrored to the remote system. Shrink 776 * will not be mirrored to the remote system. Shrink
728 * the number of bits by one, since bit 14 is the last 777 * the number of bits by one, since bit 14 is the last
@@ -735,7 +784,8 @@ static int ntb_xeon_setup(struct ntb_device *ndev)
735 SNB_B2B_DOORBELL_OFFSET; 784 SNB_B2B_DOORBELL_OFFSET;
736 785
737 /* Disable the Limit register, just incase it is set to 786 /* Disable the Limit register, just incase it is set to
738 * something silly 787 * something silly. A 64bit write should handle it
788 * regardless of whether it has a split BAR or not.
739 */ 789 */
740 writeq(0, ndev->reg_base + SNB_PBAR4LMT_OFFSET); 790 writeq(0, ndev->reg_base + SNB_PBAR4LMT_OFFSET);
741 /* HW errata on the Limit registers. They can only be 791 /* HW errata on the Limit registers. They can only be
@@ -744,6 +794,10 @@ static int ntb_xeon_setup(struct ntb_device *ndev)
744 * the driver defaults, but write the Limit registers 794 * the driver defaults, but write the Limit registers
745 * first just in case. 795 * first just in case.
746 */ 796 */
797 if (ndev->split_bar)
798 ndev->limits.max_mw = HSX_SPLITBAR_MAX_MW;
799 else
800 ndev->limits.max_mw = SNB_MAX_MW;
747 } 801 }
748 802
749 /* The Xeon errata workaround requires setting SBAR Base 803 /* The Xeon errata workaround requires setting SBAR Base
@@ -753,12 +807,22 @@ static int ntb_xeon_setup(struct ntb_device *ndev)
753 if (ndev->dev_type == NTB_DEV_USD) { 807 if (ndev->dev_type == NTB_DEV_USD) {
754 writeq(SNB_MBAR23_DSD_ADDR, ndev->reg_base + 808 writeq(SNB_MBAR23_DSD_ADDR, ndev->reg_base +
755 SNB_PBAR2XLAT_OFFSET); 809 SNB_PBAR2XLAT_OFFSET);
756 if (xeon_errata_workaround) 810 if (ndev->wa_flags & WA_SNB_ERR)
757 writeq(SNB_MBAR01_DSD_ADDR, ndev->reg_base + 811 writeq(SNB_MBAR01_DSD_ADDR, ndev->reg_base +
758 SNB_PBAR4XLAT_OFFSET); 812 SNB_PBAR4XLAT_OFFSET);
759 else { 813 else {
760 writeq(SNB_MBAR45_DSD_ADDR, ndev->reg_base + 814 if (ndev->split_bar) {
761 SNB_PBAR4XLAT_OFFSET); 815 writel(SNB_MBAR4_DSD_ADDR,
816 ndev->reg_base +
817 SNB_PBAR4XLAT_OFFSET);
818 writel(SNB_MBAR5_DSD_ADDR,
819 ndev->reg_base +
820 SNB_PBAR5XLAT_OFFSET);
821 } else
822 writeq(SNB_MBAR4_DSD_ADDR,
823 ndev->reg_base +
824 SNB_PBAR4XLAT_OFFSET);
825
762 /* B2B_XLAT_OFFSET is a 64bit register, but can 826 /* B2B_XLAT_OFFSET is a 64bit register, but can
763 * only take 32bit writes 827 * only take 32bit writes
764 */ 828 */
@@ -772,18 +836,35 @@ static int ntb_xeon_setup(struct ntb_device *ndev)
772 SNB_SBAR0BASE_OFFSET); 836 SNB_SBAR0BASE_OFFSET);
773 writeq(SNB_MBAR23_USD_ADDR, ndev->reg_base + 837 writeq(SNB_MBAR23_USD_ADDR, ndev->reg_base +
774 SNB_SBAR2BASE_OFFSET); 838 SNB_SBAR2BASE_OFFSET);
775 writeq(SNB_MBAR45_USD_ADDR, ndev->reg_base + 839 if (ndev->split_bar) {
776 SNB_SBAR4BASE_OFFSET); 840 writel(SNB_MBAR4_USD_ADDR, ndev->reg_base +
841 SNB_SBAR4BASE_OFFSET);
842 writel(SNB_MBAR5_USD_ADDR, ndev->reg_base +
843 SNB_SBAR5BASE_OFFSET);
844 } else
845 writeq(SNB_MBAR4_USD_ADDR, ndev->reg_base +
846 SNB_SBAR4BASE_OFFSET);
777 } else { 847 } else {
778 writeq(SNB_MBAR23_USD_ADDR, ndev->reg_base + 848 writeq(SNB_MBAR23_USD_ADDR, ndev->reg_base +
779 SNB_PBAR2XLAT_OFFSET); 849 SNB_PBAR2XLAT_OFFSET);
780 if (xeon_errata_workaround) 850 if (ndev->wa_flags & WA_SNB_ERR)
781 writeq(SNB_MBAR01_USD_ADDR, ndev->reg_base + 851 writeq(SNB_MBAR01_USD_ADDR, ndev->reg_base +
782 SNB_PBAR4XLAT_OFFSET); 852 SNB_PBAR4XLAT_OFFSET);
783 else { 853 else {
784 writeq(SNB_MBAR45_USD_ADDR, ndev->reg_base + 854 if (ndev->split_bar) {
785 SNB_PBAR4XLAT_OFFSET); 855 writel(SNB_MBAR4_USD_ADDR,
786 /* B2B_XLAT_OFFSET is a 64bit register, but can 856 ndev->reg_base +
857 SNB_PBAR4XLAT_OFFSET);
858 writel(SNB_MBAR5_USD_ADDR,
859 ndev->reg_base +
860 SNB_PBAR5XLAT_OFFSET);
861 } else
862 writeq(SNB_MBAR4_USD_ADDR,
863 ndev->reg_base +
864 SNB_PBAR4XLAT_OFFSET);
865
866 /*
867 * B2B_XLAT_OFFSET is a 64bit register, but can
787 * only take 32bit writes 868 * only take 32bit writes
788 */ 869 */
789 writel(SNB_MBAR01_USD_ADDR & 0xffffffff, 870 writel(SNB_MBAR01_USD_ADDR & 0xffffffff,
@@ -795,17 +876,21 @@ static int ntb_xeon_setup(struct ntb_device *ndev)
795 SNB_SBAR0BASE_OFFSET); 876 SNB_SBAR0BASE_OFFSET);
796 writeq(SNB_MBAR23_DSD_ADDR, ndev->reg_base + 877 writeq(SNB_MBAR23_DSD_ADDR, ndev->reg_base +
797 SNB_SBAR2BASE_OFFSET); 878 SNB_SBAR2BASE_OFFSET);
798 writeq(SNB_MBAR45_DSD_ADDR, ndev->reg_base + 879 if (ndev->split_bar) {
799 SNB_SBAR4BASE_OFFSET); 880 writel(SNB_MBAR4_DSD_ADDR, ndev->reg_base +
881 SNB_SBAR4BASE_OFFSET);
882 writel(SNB_MBAR5_DSD_ADDR, ndev->reg_base +
883 SNB_SBAR5BASE_OFFSET);
884 } else
885 writeq(SNB_MBAR4_DSD_ADDR, ndev->reg_base +
886 SNB_SBAR4BASE_OFFSET);
887
800 } 888 }
801 break; 889 break;
802 case NTB_CONN_RP: 890 case NTB_CONN_RP:
803 dev_info(&ndev->pdev->dev, "Conn Type = RP\n"); 891 if (ndev->wa_flags & WA_SNB_ERR) {
804 ndev->conn_type = NTB_CONN_RP;
805
806 if (xeon_errata_workaround) {
807 dev_err(&ndev->pdev->dev, 892 dev_err(&ndev->pdev->dev,
808 "NTB-RP disabled due to hardware errata. To disregard this warning and potentially lock-up the system, add the parameter 'xeon_errata_workaround=0'.\n"); 893 "NTB-RP disabled due to hardware errata.\n");
809 return -EINVAL; 894 return -EINVAL;
810 } 895 }
811 896
@@ -829,11 +914,20 @@ static int ntb_xeon_setup(struct ntb_device *ndev)
829 ndev->reg_ofs.spad_read = ndev->reg_base + SNB_SPAD_OFFSET; 914 ndev->reg_ofs.spad_read = ndev->reg_base + SNB_SPAD_OFFSET;
830 ndev->reg_ofs.bar2_xlat = ndev->reg_base + SNB_SBAR2XLAT_OFFSET; 915 ndev->reg_ofs.bar2_xlat = ndev->reg_base + SNB_SBAR2XLAT_OFFSET;
831 ndev->reg_ofs.bar4_xlat = ndev->reg_base + SNB_SBAR4XLAT_OFFSET; 916 ndev->reg_ofs.bar4_xlat = ndev->reg_base + SNB_SBAR4XLAT_OFFSET;
832 ndev->limits.max_mw = SNB_MAX_MW; 917 if (ndev->split_bar) {
918 ndev->reg_ofs.bar5_xlat =
919 ndev->reg_base + SNB_SBAR5XLAT_OFFSET;
920 ndev->limits.max_mw = HSX_SPLITBAR_MAX_MW;
921 } else
922 ndev->limits.max_mw = SNB_MAX_MW;
833 break; 923 break;
834 case NTB_CONN_TRANSPARENT: 924 case NTB_CONN_TRANSPARENT:
835 dev_info(&ndev->pdev->dev, "Conn Type = TRANSPARENT\n"); 925 if (ndev->wa_flags & WA_SNB_ERR) {
836 ndev->conn_type = NTB_CONN_TRANSPARENT; 926 dev_err(&ndev->pdev->dev,
927 "NTB-TRANSPARENT disabled due to hardware errata.\n");
928 return -EINVAL;
929 }
930
837 /* Scratch pads need to have exclusive access from the primary 931 /* Scratch pads need to have exclusive access from the primary
838 * or secondary side. Halve the num spads so that each side can 932 * or secondary side. Halve the num spads so that each side can
839 * have an equal amount. 933 * have an equal amount.
@@ -852,13 +946,18 @@ static int ntb_xeon_setup(struct ntb_device *ndev)
852 ndev->reg_ofs.bar2_xlat = ndev->reg_base + SNB_PBAR2XLAT_OFFSET; 946 ndev->reg_ofs.bar2_xlat = ndev->reg_base + SNB_PBAR2XLAT_OFFSET;
853 ndev->reg_ofs.bar4_xlat = ndev->reg_base + SNB_PBAR4XLAT_OFFSET; 947 ndev->reg_ofs.bar4_xlat = ndev->reg_base + SNB_PBAR4XLAT_OFFSET;
854 948
855 ndev->limits.max_mw = SNB_MAX_MW; 949 if (ndev->split_bar) {
950 ndev->reg_ofs.bar5_xlat =
951 ndev->reg_base + SNB_PBAR5XLAT_OFFSET;
952 ndev->limits.max_mw = HSX_SPLITBAR_MAX_MW;
953 } else
954 ndev->limits.max_mw = SNB_MAX_MW;
856 break; 955 break;
857 default: 956 default:
858 /* Most likely caused by the remote NTB-RP device not being 957 /*
859 * configured 958 * we should never hit this. the detect function should've
959 * take cared of everything.
860 */ 960 */
861 dev_err(&ndev->pdev->dev, "Unknown PPD %x\n", val);
862 return -EINVAL; 961 return -EINVAL;
863 } 962 }
864 963
@@ -932,34 +1031,16 @@ static int ntb_device_setup(struct ntb_device *ndev)
932{ 1031{
933 int rc; 1032 int rc;
934 1033
935 switch (ndev->pdev->device) { 1034 if (is_ntb_xeon(ndev))
936 case PCI_DEVICE_ID_INTEL_NTB_SS_JSF:
937 case PCI_DEVICE_ID_INTEL_NTB_SS_SNB:
938 case PCI_DEVICE_ID_INTEL_NTB_SS_IVT:
939 case PCI_DEVICE_ID_INTEL_NTB_SS_HSX:
940 case PCI_DEVICE_ID_INTEL_NTB_PS_JSF:
941 case PCI_DEVICE_ID_INTEL_NTB_PS_SNB:
942 case PCI_DEVICE_ID_INTEL_NTB_PS_IVT:
943 case PCI_DEVICE_ID_INTEL_NTB_PS_HSX:
944 case PCI_DEVICE_ID_INTEL_NTB_B2B_JSF:
945 case PCI_DEVICE_ID_INTEL_NTB_B2B_SNB:
946 case PCI_DEVICE_ID_INTEL_NTB_B2B_IVT:
947 case PCI_DEVICE_ID_INTEL_NTB_B2B_HSX:
948 rc = ntb_xeon_setup(ndev); 1035 rc = ntb_xeon_setup(ndev);
949 break; 1036 else if (is_ntb_atom(ndev))
950 case PCI_DEVICE_ID_INTEL_NTB_B2B_BWD:
951 rc = ntb_bwd_setup(ndev); 1037 rc = ntb_bwd_setup(ndev);
952 break; 1038 else
953 default:
954 rc = -ENODEV; 1039 rc = -ENODEV;
955 }
956 1040
957 if (rc) 1041 if (rc)
958 return rc; 1042 return rc;
959 1043
960 dev_info(&ndev->pdev->dev, "Device Type = %s\n",
961 ndev->dev_type == NTB_DEV_USD ? "USD/DSP" : "DSD/USP");
962
963 if (ndev->conn_type == NTB_CONN_B2B) 1044 if (ndev->conn_type == NTB_CONN_B2B)
964 /* Enable Bus Master and Memory Space on the secondary side */ 1045 /* Enable Bus Master and Memory Space on the secondary side */
965 writew(PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER, 1046 writew(PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER,
@@ -970,7 +1051,7 @@ static int ntb_device_setup(struct ntb_device *ndev)
970 1051
971static void ntb_device_free(struct ntb_device *ndev) 1052static void ntb_device_free(struct ntb_device *ndev)
972{ 1053{
973 if (ndev->hw_type == BWD_HW) { 1054 if (is_ntb_atom(ndev)) {
974 cancel_delayed_work_sync(&ndev->hb_timer); 1055 cancel_delayed_work_sync(&ndev->hb_timer);
975 cancel_delayed_work_sync(&ndev->lr_timer); 1056 cancel_delayed_work_sync(&ndev->lr_timer);
976 } 1057 }
@@ -1050,7 +1131,7 @@ static irqreturn_t ntb_interrupt(int irq, void *dev)
1050 struct ntb_device *ndev = dev; 1131 struct ntb_device *ndev = dev;
1051 unsigned int i = 0; 1132 unsigned int i = 0;
1052 1133
1053 if (ndev->hw_type == BWD_HW) { 1134 if (is_ntb_atom(ndev)) {
1054 u64 ldb = readq(ndev->reg_ofs.ldb); 1135 u64 ldb = readq(ndev->reg_ofs.ldb);
1055 1136
1056 dev_dbg(&ndev->pdev->dev, "irq %d - ldb = %Lx\n", irq, ldb); 1137 dev_dbg(&ndev->pdev->dev, "irq %d - ldb = %Lx\n", irq, ldb);
@@ -1192,7 +1273,7 @@ static int ntb_setup_msix(struct ntb_device *ndev)
1192 for (i = 0; i < msix_entries; i++) 1273 for (i = 0; i < msix_entries; i++)
1193 ndev->msix_entries[i].entry = i; 1274 ndev->msix_entries[i].entry = i;
1194 1275
1195 if (ndev->hw_type == BWD_HW) 1276 if (is_ntb_atom(ndev))
1196 rc = ntb_setup_bwd_msix(ndev, msix_entries); 1277 rc = ntb_setup_bwd_msix(ndev, msix_entries);
1197 else 1278 else
1198 rc = ntb_setup_snb_msix(ndev, msix_entries); 1279 rc = ntb_setup_snb_msix(ndev, msix_entries);
@@ -1252,7 +1333,7 @@ static int ntb_setup_interrupts(struct ntb_device *ndev)
1252 /* On BWD, disable all interrupts. On SNB, disable all but Link 1333 /* On BWD, disable all interrupts. On SNB, disable all but Link
1253 * Interrupt. The rest will be unmasked as callbacks are registered. 1334 * Interrupt. The rest will be unmasked as callbacks are registered.
1254 */ 1335 */
1255 if (ndev->hw_type == BWD_HW) 1336 if (is_ntb_atom(ndev))
1256 writeq(~0, ndev->reg_ofs.ldb_mask); 1337 writeq(~0, ndev->reg_ofs.ldb_mask);
1257 else { 1338 else {
1258 u16 var = 1 << SNB_LINK_DB; 1339 u16 var = 1 << SNB_LINK_DB;
@@ -1285,7 +1366,7 @@ static void ntb_free_interrupts(struct ntb_device *ndev)
1285 struct pci_dev *pdev = ndev->pdev; 1366 struct pci_dev *pdev = ndev->pdev;
1286 1367
1287 /* mask interrupts */ 1368 /* mask interrupts */
1288 if (ndev->hw_type == BWD_HW) 1369 if (is_ntb_atom(ndev))
1289 writeq(~0, ndev->reg_ofs.ldb_mask); 1370 writeq(~0, ndev->reg_ofs.ldb_mask);
1290 else 1371 else
1291 writew(~0, ndev->reg_ofs.ldb_mask); 1372 writew(~0, ndev->reg_ofs.ldb_mask);
@@ -1296,7 +1377,7 @@ static void ntb_free_interrupts(struct ntb_device *ndev)
1296 1377
1297 for (i = 0; i < ndev->num_msix; i++) { 1378 for (i = 0; i < ndev->num_msix; i++) {
1298 msix = &ndev->msix_entries[i]; 1379 msix = &ndev->msix_entries[i];
1299 if (ndev->hw_type != BWD_HW && i == ndev->num_msix - 1) 1380 if (is_ntb_xeon(ndev) && i == ndev->num_msix - 1)
1300 free_irq(msix->vector, ndev); 1381 free_irq(msix->vector, ndev);
1301 else 1382 else
1302 free_irq(msix->vector, &ndev->db_cb[i]); 1383 free_irq(msix->vector, &ndev->db_cb[i]);
@@ -1344,6 +1425,101 @@ static void ntb_free_callbacks(struct ntb_device *ndev)
1344 kfree(ndev->db_cb); 1425 kfree(ndev->db_cb);
1345} 1426}
1346 1427
1428static ssize_t ntb_debugfs_read(struct file *filp, char __user *ubuf,
1429 size_t count, loff_t *offp)
1430{
1431 struct ntb_device *ndev;
1432 char *buf;
1433 ssize_t ret, offset, out_count;
1434
1435 out_count = 500;
1436
1437 buf = kmalloc(out_count, GFP_KERNEL);
1438 if (!buf)
1439 return -ENOMEM;
1440
1441 ndev = filp->private_data;
1442 offset = 0;
1443 offset += snprintf(buf + offset, out_count - offset,
1444 "NTB Device Information:\n");
1445 offset += snprintf(buf + offset, out_count - offset,
1446 "Connection Type - \t\t%s\n",
1447 ndev->conn_type == NTB_CONN_TRANSPARENT ?
1448 "Transparent" : (ndev->conn_type == NTB_CONN_B2B) ?
1449 "Back to back" : "Root Port");
1450 offset += snprintf(buf + offset, out_count - offset,
1451 "Device Type - \t\t\t%s\n",
1452 ndev->dev_type == NTB_DEV_USD ?
1453 "DSD/USP" : "USD/DSP");
1454 offset += snprintf(buf + offset, out_count - offset,
1455 "Max Number of Callbacks - \t%u\n",
1456 ntb_max_cbs(ndev));
1457 offset += snprintf(buf + offset, out_count - offset,
1458 "Link Status - \t\t\t%s\n",
1459 ntb_hw_link_status(ndev) ? "Up" : "Down");
1460 if (ntb_hw_link_status(ndev)) {
1461 offset += snprintf(buf + offset, out_count - offset,
1462 "Link Speed - \t\t\tPCI-E Gen %u\n",
1463 ndev->link_speed);
1464 offset += snprintf(buf + offset, out_count - offset,
1465 "Link Width - \t\t\tx%u\n",
1466 ndev->link_width);
1467 }
1468
1469 if (is_ntb_xeon(ndev)) {
1470 u32 status32;
1471 u16 status16;
1472 int rc;
1473
1474 offset += snprintf(buf + offset, out_count - offset,
1475 "\nNTB Device Statistics:\n");
1476 offset += snprintf(buf + offset, out_count - offset,
1477 "Upstream Memory Miss - \t%u\n",
1478 readw(ndev->reg_base +
1479 SNB_USMEMMISS_OFFSET));
1480
1481 offset += snprintf(buf + offset, out_count - offset,
1482 "\nNTB Hardware Errors:\n");
1483
1484 rc = pci_read_config_word(ndev->pdev, SNB_DEVSTS_OFFSET,
1485 &status16);
1486 if (!rc)
1487 offset += snprintf(buf + offset, out_count - offset,
1488 "DEVSTS - \t%#06x\n", status16);
1489
1490 rc = pci_read_config_word(ndev->pdev, SNB_LINK_STATUS_OFFSET,
1491 &status16);
1492 if (!rc)
1493 offset += snprintf(buf + offset, out_count - offset,
1494 "LNKSTS - \t%#06x\n", status16);
1495
1496 rc = pci_read_config_dword(ndev->pdev, SNB_UNCERRSTS_OFFSET,
1497 &status32);
1498 if (!rc)
1499 offset += snprintf(buf + offset, out_count - offset,
1500 "UNCERRSTS - \t%#010x\n", status32);
1501
1502 rc = pci_read_config_dword(ndev->pdev, SNB_CORERRSTS_OFFSET,
1503 &status32);
1504 if (!rc)
1505 offset += snprintf(buf + offset, out_count - offset,
1506 "CORERRSTS - \t%#010x\n", status32);
1507 }
1508
1509 if (offset > out_count)
1510 offset = out_count;
1511
1512 ret = simple_read_from_buffer(ubuf, count, offp, buf, offset);
1513 kfree(buf);
1514 return ret;
1515}
1516
1517static const struct file_operations ntb_debugfs_info = {
1518 .owner = THIS_MODULE,
1519 .open = simple_open,
1520 .read = ntb_debugfs_read,
1521};
1522
1347static void ntb_setup_debugfs(struct ntb_device *ndev) 1523static void ntb_setup_debugfs(struct ntb_device *ndev)
1348{ 1524{
1349 if (!debugfs_initialized()) 1525 if (!debugfs_initialized())
@@ -1354,6 +1530,11 @@ static void ntb_setup_debugfs(struct ntb_device *ndev)
1354 1530
1355 ndev->debugfs_dir = debugfs_create_dir(pci_name(ndev->pdev), 1531 ndev->debugfs_dir = debugfs_create_dir(pci_name(ndev->pdev),
1356 debugfs_dir); 1532 debugfs_dir);
1533 if (ndev->debugfs_dir)
1534 ndev->debugfs_info = debugfs_create_file("info", S_IRUSR,
1535 ndev->debugfs_dir,
1536 ndev,
1537 &ntb_debugfs_info);
1357} 1538}
1358 1539
1359static void ntb_free_debugfs(struct ntb_device *ndev) 1540static void ntb_free_debugfs(struct ntb_device *ndev)
@@ -1377,7 +1558,11 @@ static void ntb_hw_link_up(struct ntb_device *ndev)
1377 ntb_cntl = readl(ndev->reg_ofs.lnk_cntl); 1558 ntb_cntl = readl(ndev->reg_ofs.lnk_cntl);
1378 ntb_cntl &= ~(NTB_CNTL_LINK_DISABLE | NTB_CNTL_CFG_LOCK); 1559 ntb_cntl &= ~(NTB_CNTL_LINK_DISABLE | NTB_CNTL_CFG_LOCK);
1379 ntb_cntl |= NTB_CNTL_P2S_BAR23_SNOOP | NTB_CNTL_S2P_BAR23_SNOOP; 1560 ntb_cntl |= NTB_CNTL_P2S_BAR23_SNOOP | NTB_CNTL_S2P_BAR23_SNOOP;
1380 ntb_cntl |= NTB_CNTL_P2S_BAR45_SNOOP | NTB_CNTL_S2P_BAR45_SNOOP; 1561 ntb_cntl |= NTB_CNTL_P2S_BAR4_SNOOP | NTB_CNTL_S2P_BAR4_SNOOP;
1562 if (ndev->split_bar)
1563 ntb_cntl |= NTB_CNTL_P2S_BAR5_SNOOP |
1564 NTB_CNTL_S2P_BAR5_SNOOP;
1565
1381 writel(ntb_cntl, ndev->reg_ofs.lnk_cntl); 1566 writel(ntb_cntl, ndev->reg_ofs.lnk_cntl);
1382 } 1567 }
1383} 1568}
@@ -1394,11 +1579,128 @@ static void ntb_hw_link_down(struct ntb_device *ndev)
1394 /* Bring NTB link down */ 1579 /* Bring NTB link down */
1395 ntb_cntl = readl(ndev->reg_ofs.lnk_cntl); 1580 ntb_cntl = readl(ndev->reg_ofs.lnk_cntl);
1396 ntb_cntl &= ~(NTB_CNTL_P2S_BAR23_SNOOP | NTB_CNTL_S2P_BAR23_SNOOP); 1581 ntb_cntl &= ~(NTB_CNTL_P2S_BAR23_SNOOP | NTB_CNTL_S2P_BAR23_SNOOP);
1397 ntb_cntl &= ~(NTB_CNTL_P2S_BAR45_SNOOP | NTB_CNTL_S2P_BAR45_SNOOP); 1582 ntb_cntl &= ~(NTB_CNTL_P2S_BAR4_SNOOP | NTB_CNTL_S2P_BAR4_SNOOP);
1583 if (ndev->split_bar)
1584 ntb_cntl &= ~(NTB_CNTL_P2S_BAR5_SNOOP |
1585 NTB_CNTL_S2P_BAR5_SNOOP);
1398 ntb_cntl |= NTB_CNTL_LINK_DISABLE | NTB_CNTL_CFG_LOCK; 1586 ntb_cntl |= NTB_CNTL_LINK_DISABLE | NTB_CNTL_CFG_LOCK;
1399 writel(ntb_cntl, ndev->reg_ofs.lnk_cntl); 1587 writel(ntb_cntl, ndev->reg_ofs.lnk_cntl);
1400} 1588}
1401 1589
1590static void ntb_max_mw_detect(struct ntb_device *ndev)
1591{
1592 if (ndev->split_bar)
1593 ndev->limits.max_mw = HSX_SPLITBAR_MAX_MW;
1594 else
1595 ndev->limits.max_mw = SNB_MAX_MW;
1596}
1597
1598static int ntb_xeon_detect(struct ntb_device *ndev)
1599{
1600 int rc, bars_mask;
1601 u32 bars;
1602 u8 ppd;
1603
1604 ndev->hw_type = SNB_HW;
1605
1606 rc = pci_read_config_byte(ndev->pdev, NTB_PPD_OFFSET, &ppd);
1607 if (rc)
1608 return -EIO;
1609
1610 if (ppd & SNB_PPD_DEV_TYPE)
1611 ndev->dev_type = NTB_DEV_USD;
1612 else
1613 ndev->dev_type = NTB_DEV_DSD;
1614
1615 ndev->split_bar = (ppd & SNB_PPD_SPLIT_BAR) ? 1 : 0;
1616
1617 switch (ppd & SNB_PPD_CONN_TYPE) {
1618 case NTB_CONN_B2B:
1619 dev_info(&ndev->pdev->dev, "Conn Type = B2B\n");
1620 ndev->conn_type = NTB_CONN_B2B;
1621 break;
1622 case NTB_CONN_RP:
1623 dev_info(&ndev->pdev->dev, "Conn Type = RP\n");
1624 ndev->conn_type = NTB_CONN_RP;
1625 break;
1626 case NTB_CONN_TRANSPARENT:
1627 dev_info(&ndev->pdev->dev, "Conn Type = TRANSPARENT\n");
1628 ndev->conn_type = NTB_CONN_TRANSPARENT;
1629 /*
1630 * This mode is default to USD/DSP. HW does not report
1631 * properly in transparent mode as it has no knowledge of
1632 * NTB. We will just force correct here.
1633 */
1634 ndev->dev_type = NTB_DEV_USD;
1635
1636 /*
1637 * This is a way for transparent BAR to figure out if we
1638 * are doing split BAR or not. There is no way for the hw
1639 * on the transparent side to know and set the PPD.
1640 */
1641 bars_mask = pci_select_bars(ndev->pdev, IORESOURCE_MEM);
1642 bars = hweight32(bars_mask);
1643 if (bars == (HSX_SPLITBAR_MAX_MW + 1))
1644 ndev->split_bar = 1;
1645
1646 break;
1647 default:
1648 dev_err(&ndev->pdev->dev, "Unknown PPD %x\n", ppd);
1649 return -ENODEV;
1650 }
1651
1652 ntb_max_mw_detect(ndev);
1653
1654 return 0;
1655}
1656
1657static int ntb_atom_detect(struct ntb_device *ndev)
1658{
1659 int rc;
1660 u32 ppd;
1661
1662 ndev->hw_type = BWD_HW;
1663
1664 rc = pci_read_config_dword(ndev->pdev, NTB_PPD_OFFSET, &ppd);
1665 if (rc)
1666 return rc;
1667
1668 switch ((ppd & BWD_PPD_CONN_TYPE) >> 8) {
1669 case NTB_CONN_B2B:
1670 dev_info(&ndev->pdev->dev, "Conn Type = B2B\n");
1671 ndev->conn_type = NTB_CONN_B2B;
1672 break;
1673 case NTB_CONN_RP:
1674 default:
1675 dev_err(&ndev->pdev->dev, "Unsupported NTB configuration\n");
1676 return -EINVAL;
1677 }
1678
1679 if (ppd & BWD_PPD_DEV_TYPE)
1680 ndev->dev_type = NTB_DEV_DSD;
1681 else
1682 ndev->dev_type = NTB_DEV_USD;
1683
1684 return 0;
1685}
1686
1687static int ntb_device_detect(struct ntb_device *ndev)
1688{
1689 int rc;
1690
1691 if (is_ntb_xeon(ndev))
1692 rc = ntb_xeon_detect(ndev);
1693 else if (is_ntb_atom(ndev))
1694 rc = ntb_atom_detect(ndev);
1695 else
1696 rc = -ENODEV;
1697
1698 dev_info(&ndev->pdev->dev, "Device Type = %s\n",
1699 ndev->dev_type == NTB_DEV_USD ? "USD/DSP" : "DSD/USP");
1700
1701 return 0;
1702}
1703
1402static int ntb_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id) 1704static int ntb_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
1403{ 1705{
1404 struct ntb_device *ndev; 1706 struct ntb_device *ndev;
@@ -1409,6 +1711,9 @@ static int ntb_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
1409 return -ENOMEM; 1711 return -ENOMEM;
1410 1712
1411 ndev->pdev = pdev; 1713 ndev->pdev = pdev;
1714
1715 ntb_set_errata_flags(ndev);
1716
1412 ndev->link_status = NTB_LINK_DOWN; 1717 ndev->link_status = NTB_LINK_DOWN;
1413 pci_set_drvdata(pdev, ndev); 1718 pci_set_drvdata(pdev, ndev);
1414 ntb_setup_debugfs(ndev); 1719 ntb_setup_debugfs(ndev);
@@ -1419,22 +1724,54 @@ static int ntb_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
1419 1724
1420 pci_set_master(ndev->pdev); 1725 pci_set_master(ndev->pdev);
1421 1726
1422 rc = pci_request_selected_regions(pdev, NTB_BAR_MASK, KBUILD_MODNAME); 1727 rc = ntb_device_detect(ndev);
1423 if (rc) 1728 if (rc)
1729 goto err;
1730
1731 ndev->mw = kcalloc(ndev->limits.max_mw, sizeof(struct ntb_mw),
1732 GFP_KERNEL);
1733 if (!ndev->mw) {
1734 rc = -ENOMEM;
1424 goto err1; 1735 goto err1;
1736 }
1737
1738 if (ndev->split_bar)
1739 rc = pci_request_selected_regions(pdev, NTB_SPLITBAR_MASK,
1740 KBUILD_MODNAME);
1741 else
1742 rc = pci_request_selected_regions(pdev, NTB_BAR_MASK,
1743 KBUILD_MODNAME);
1744
1745 if (rc)
1746 goto err2;
1425 1747
1426 ndev->reg_base = pci_ioremap_bar(pdev, NTB_BAR_MMIO); 1748 ndev->reg_base = pci_ioremap_bar(pdev, NTB_BAR_MMIO);
1427 if (!ndev->reg_base) { 1749 if (!ndev->reg_base) {
1428 dev_warn(&pdev->dev, "Cannot remap BAR 0\n"); 1750 dev_warn(&pdev->dev, "Cannot remap BAR 0\n");
1429 rc = -EIO; 1751 rc = -EIO;
1430 goto err2; 1752 goto err3;
1431 } 1753 }
1432 1754
1433 for (i = 0; i < NTB_MAX_NUM_MW; i++) { 1755 for (i = 0; i < ndev->limits.max_mw; i++) {
1434 ndev->mw[i].bar_sz = pci_resource_len(pdev, MW_TO_BAR(i)); 1756 ndev->mw[i].bar_sz = pci_resource_len(pdev, MW_TO_BAR(i));
1435 ndev->mw[i].vbase = 1757
1436 ioremap_wc(pci_resource_start(pdev, MW_TO_BAR(i)), 1758 /*
1437 ndev->mw[i].bar_sz); 1759 * with the errata we need to steal last of the memory
1760 * windows for workarounds and they point to MMIO registers.
1761 */
1762 if ((ndev->wa_flags & WA_SNB_ERR) &&
1763 (i == (ndev->limits.max_mw - 1))) {
1764 ndev->mw[i].vbase =
1765 ioremap_nocache(pci_resource_start(pdev,
1766 MW_TO_BAR(i)),
1767 ndev->mw[i].bar_sz);
1768 } else {
1769 ndev->mw[i].vbase =
1770 ioremap_wc(pci_resource_start(pdev,
1771 MW_TO_BAR(i)),
1772 ndev->mw[i].bar_sz);
1773 }
1774
1438 dev_info(&pdev->dev, "MW %d size %llu\n", i, 1775 dev_info(&pdev->dev, "MW %d size %llu\n", i,
1439 (unsigned long long) ndev->mw[i].bar_sz); 1776 (unsigned long long) ndev->mw[i].bar_sz);
1440 if (!ndev->mw[i].vbase) { 1777 if (!ndev->mw[i].vbase) {
@@ -1449,7 +1786,7 @@ static int ntb_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
1449 if (rc) { 1786 if (rc) {
1450 rc = pci_set_dma_mask(pdev, DMA_BIT_MASK(32)); 1787 rc = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
1451 if (rc) 1788 if (rc)
1452 goto err3; 1789 goto err4;
1453 1790
1454 dev_warn(&pdev->dev, "Cannot DMA highmem\n"); 1791 dev_warn(&pdev->dev, "Cannot DMA highmem\n");
1455 } 1792 }
@@ -1458,22 +1795,22 @@ static int ntb_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
1458 if (rc) { 1795 if (rc) {
1459 rc = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32)); 1796 rc = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32));
1460 if (rc) 1797 if (rc)
1461 goto err3; 1798 goto err4;
1462 1799
1463 dev_warn(&pdev->dev, "Cannot DMA consistent highmem\n"); 1800 dev_warn(&pdev->dev, "Cannot DMA consistent highmem\n");
1464 } 1801 }
1465 1802
1466 rc = ntb_device_setup(ndev); 1803 rc = ntb_device_setup(ndev);
1467 if (rc) 1804 if (rc)
1468 goto err3; 1805 goto err4;
1469 1806
1470 rc = ntb_create_callbacks(ndev); 1807 rc = ntb_create_callbacks(ndev);
1471 if (rc) 1808 if (rc)
1472 goto err4; 1809 goto err5;
1473 1810
1474 rc = ntb_setup_interrupts(ndev); 1811 rc = ntb_setup_interrupts(ndev);
1475 if (rc) 1812 if (rc)
1476 goto err5; 1813 goto err6;
1477 1814
1478 /* The scratchpad registers keep the values between rmmod/insmod, 1815 /* The scratchpad registers keep the values between rmmod/insmod,
1479 * blast them now 1816 * blast them now
@@ -1485,24 +1822,29 @@ static int ntb_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
1485 1822
1486 rc = ntb_transport_init(pdev); 1823 rc = ntb_transport_init(pdev);
1487 if (rc) 1824 if (rc)
1488 goto err6; 1825 goto err7;
1489 1826
1490 ntb_hw_link_up(ndev); 1827 ntb_hw_link_up(ndev);
1491 1828
1492 return 0; 1829 return 0;
1493 1830
1494err6: 1831err7:
1495 ntb_free_interrupts(ndev); 1832 ntb_free_interrupts(ndev);
1496err5: 1833err6:
1497 ntb_free_callbacks(ndev); 1834 ntb_free_callbacks(ndev);
1498err4: 1835err5:
1499 ntb_device_free(ndev); 1836 ntb_device_free(ndev);
1500err3: 1837err4:
1501 for (i--; i >= 0; i--) 1838 for (i--; i >= 0; i--)
1502 iounmap(ndev->mw[i].vbase); 1839 iounmap(ndev->mw[i].vbase);
1503 iounmap(ndev->reg_base); 1840 iounmap(ndev->reg_base);
1841err3:
1842 if (ndev->split_bar)
1843 pci_release_selected_regions(pdev, NTB_SPLITBAR_MASK);
1844 else
1845 pci_release_selected_regions(pdev, NTB_BAR_MASK);
1504err2: 1846err2:
1505 pci_release_selected_regions(pdev, NTB_BAR_MASK); 1847 kfree(ndev->mw);
1506err1: 1848err1:
1507 pci_disable_device(pdev); 1849 pci_disable_device(pdev);
1508err: 1850err:
@@ -1526,11 +1868,19 @@ static void ntb_pci_remove(struct pci_dev *pdev)
1526 ntb_free_callbacks(ndev); 1868 ntb_free_callbacks(ndev);
1527 ntb_device_free(ndev); 1869 ntb_device_free(ndev);
1528 1870
1529 for (i = 0; i < NTB_MAX_NUM_MW; i++) 1871 /* need to reset max_mw limits so we can unmap properly */
1872 if (ndev->hw_type == SNB_HW)
1873 ntb_max_mw_detect(ndev);
1874
1875 for (i = 0; i < ndev->limits.max_mw; i++)
1530 iounmap(ndev->mw[i].vbase); 1876 iounmap(ndev->mw[i].vbase);
1531 1877
1878 kfree(ndev->mw);
1532 iounmap(ndev->reg_base); 1879 iounmap(ndev->reg_base);
1533 pci_release_selected_regions(pdev, NTB_BAR_MASK); 1880 if (ndev->split_bar)
1881 pci_release_selected_regions(pdev, NTB_SPLITBAR_MASK);
1882 else
1883 pci_release_selected_regions(pdev, NTB_BAR_MASK);
1534 pci_disable_device(pdev); 1884 pci_disable_device(pdev);
1535 ntb_free_debugfs(ndev); 1885 ntb_free_debugfs(ndev);
1536 kfree(ndev); 1886 kfree(ndev);
@@ -1542,4 +1892,5 @@ static struct pci_driver ntb_pci_driver = {
1542 .probe = ntb_pci_probe, 1892 .probe = ntb_pci_probe,
1543 .remove = ntb_pci_remove, 1893 .remove = ntb_pci_remove,
1544}; 1894};
1895
1545module_pci_driver(ntb_pci_driver); 1896module_pci_driver(ntb_pci_driver);
diff --git a/drivers/ntb/ntb_hw.h b/drivers/ntb/ntb_hw.h
index 465517b7393e..96de5fc95f90 100644
--- a/drivers/ntb/ntb_hw.h
+++ b/drivers/ntb/ntb_hw.h
@@ -78,14 +78,16 @@ static inline void writeq(u64 val, void __iomem *addr)
78 78
79#define NTB_BAR_MMIO 0 79#define NTB_BAR_MMIO 0
80#define NTB_BAR_23 2 80#define NTB_BAR_23 2
81#define NTB_BAR_45 4 81#define NTB_BAR_4 4
82#define NTB_BAR_5 5
83
82#define NTB_BAR_MASK ((1 << NTB_BAR_MMIO) | (1 << NTB_BAR_23) |\ 84#define NTB_BAR_MASK ((1 << NTB_BAR_MMIO) | (1 << NTB_BAR_23) |\
83 (1 << NTB_BAR_45)) 85 (1 << NTB_BAR_4))
86#define NTB_SPLITBAR_MASK ((1 << NTB_BAR_MMIO) | (1 << NTB_BAR_23) |\
87 (1 << NTB_BAR_4) | (1 << NTB_BAR_5))
84 88
85#define NTB_HB_TIMEOUT msecs_to_jiffies(1000) 89#define NTB_HB_TIMEOUT msecs_to_jiffies(1000)
86 90
87#define NTB_MAX_NUM_MW 2
88
89enum ntb_hw_event { 91enum ntb_hw_event {
90 NTB_EVENT_SW_EVENT0 = 0, 92 NTB_EVENT_SW_EVENT0 = 0,
91 NTB_EVENT_SW_EVENT1, 93 NTB_EVENT_SW_EVENT1,
@@ -109,11 +111,13 @@ struct ntb_db_cb {
109 struct tasklet_struct irq_work; 111 struct tasklet_struct irq_work;
110}; 112};
111 113
114#define WA_SNB_ERR 0x00000001
115
112struct ntb_device { 116struct ntb_device {
113 struct pci_dev *pdev; 117 struct pci_dev *pdev;
114 struct msix_entry *msix_entries; 118 struct msix_entry *msix_entries;
115 void __iomem *reg_base; 119 void __iomem *reg_base;
116 struct ntb_mw mw[NTB_MAX_NUM_MW]; 120 struct ntb_mw *mw;
117 struct { 121 struct {
118 unsigned char max_mw; 122 unsigned char max_mw;
119 unsigned char max_spads; 123 unsigned char max_spads;
@@ -126,6 +130,7 @@ struct ntb_device {
126 void __iomem *rdb; 130 void __iomem *rdb;
127 void __iomem *bar2_xlat; 131 void __iomem *bar2_xlat;
128 void __iomem *bar4_xlat; 132 void __iomem *bar4_xlat;
133 void __iomem *bar5_xlat;
129 void __iomem *spad_write; 134 void __iomem *spad_write;
130 void __iomem *spad_read; 135 void __iomem *spad_read;
131 void __iomem *lnk_cntl; 136 void __iomem *lnk_cntl;
@@ -145,6 +150,7 @@ struct ntb_device {
145 unsigned char link_width; 150 unsigned char link_width;
146 unsigned char link_speed; 151 unsigned char link_speed;
147 unsigned char link_status; 152 unsigned char link_status;
153 unsigned char split_bar;
148 154
149 struct delayed_work hb_timer; 155 struct delayed_work hb_timer;
150 unsigned long last_ts; 156 unsigned long last_ts;
@@ -152,6 +158,9 @@ struct ntb_device {
152 struct delayed_work lr_timer; 158 struct delayed_work lr_timer;
153 159
154 struct dentry *debugfs_dir; 160 struct dentry *debugfs_dir;
161 struct dentry *debugfs_info;
162
163 unsigned int wa_flags;
155}; 164};
156 165
157/** 166/**
diff --git a/drivers/ntb/ntb_regs.h b/drivers/ntb/ntb_regs.h
index 9774506419d7..f028ff81fd77 100644
--- a/drivers/ntb/ntb_regs.h
+++ b/drivers/ntb/ntb_regs.h
@@ -57,34 +57,43 @@
57#define SNB_MAX_DB_BITS 15 57#define SNB_MAX_DB_BITS 15
58#define SNB_LINK_DB 15 58#define SNB_LINK_DB 15
59#define SNB_DB_BITS_PER_VEC 5 59#define SNB_DB_BITS_PER_VEC 5
60#define HSX_SPLITBAR_MAX_MW 3
60#define SNB_MAX_MW 2 61#define SNB_MAX_MW 2
61#define SNB_ERRATA_MAX_MW 1 62#define SNB_ERRATA_MAX_MW 1
62 63
63#define SNB_DB_HW_LINK 0x8000 64#define SNB_DB_HW_LINK 0x8000
64 65
66#define SNB_UNCERRSTS_OFFSET 0x014C
67#define SNB_CORERRSTS_OFFSET 0x0158
68#define SNB_LINK_STATUS_OFFSET 0x01A2
65#define SNB_PCICMD_OFFSET 0x0504 69#define SNB_PCICMD_OFFSET 0x0504
66#define SNB_DEVCTRL_OFFSET 0x0598 70#define SNB_DEVCTRL_OFFSET 0x0598
71#define SNB_DEVSTS_OFFSET 0x059A
67#define SNB_SLINK_STATUS_OFFSET 0x05A2 72#define SNB_SLINK_STATUS_OFFSET 0x05A2
68#define SNB_LINK_STATUS_OFFSET 0x01A2
69 73
70#define SNB_PBAR2LMT_OFFSET 0x0000 74#define SNB_PBAR2LMT_OFFSET 0x0000
71#define SNB_PBAR4LMT_OFFSET 0x0008 75#define SNB_PBAR4LMT_OFFSET 0x0008
76#define SNB_PBAR5LMT_OFFSET 0x000C
72#define SNB_PBAR2XLAT_OFFSET 0x0010 77#define SNB_PBAR2XLAT_OFFSET 0x0010
73#define SNB_PBAR4XLAT_OFFSET 0x0018 78#define SNB_PBAR4XLAT_OFFSET 0x0018
79#define SNB_PBAR5XLAT_OFFSET 0x001C
74#define SNB_SBAR2LMT_OFFSET 0x0020 80#define SNB_SBAR2LMT_OFFSET 0x0020
75#define SNB_SBAR4LMT_OFFSET 0x0028 81#define SNB_SBAR4LMT_OFFSET 0x0028
82#define SNB_SBAR5LMT_OFFSET 0x002C
76#define SNB_SBAR2XLAT_OFFSET 0x0030 83#define SNB_SBAR2XLAT_OFFSET 0x0030
77#define SNB_SBAR4XLAT_OFFSET 0x0038 84#define SNB_SBAR4XLAT_OFFSET 0x0038
85#define SNB_SBAR5XLAT_OFFSET 0x003C
78#define SNB_SBAR0BASE_OFFSET 0x0040 86#define SNB_SBAR0BASE_OFFSET 0x0040
79#define SNB_SBAR2BASE_OFFSET 0x0048 87#define SNB_SBAR2BASE_OFFSET 0x0048
80#define SNB_SBAR4BASE_OFFSET 0x0050 88#define SNB_SBAR4BASE_OFFSET 0x0050
89#define SNB_SBAR5BASE_OFFSET 0x0054
81#define SNB_NTBCNTL_OFFSET 0x0058 90#define SNB_NTBCNTL_OFFSET 0x0058
82#define SNB_SBDF_OFFSET 0x005C 91#define SNB_SBDF_OFFSET 0x005C
83#define SNB_PDOORBELL_OFFSET 0x0060 92#define SNB_PDOORBELL_OFFSET 0x0060
84#define SNB_PDBMSK_OFFSET 0x0062 93#define SNB_PDBMSK_OFFSET 0x0062
85#define SNB_SDOORBELL_OFFSET 0x0064 94#define SNB_SDOORBELL_OFFSET 0x0064
86#define SNB_SDBMSK_OFFSET 0x0066 95#define SNB_SDBMSK_OFFSET 0x0066
87#define SNB_USMEMMISS 0x0070 96#define SNB_USMEMMISS_OFFSET 0x0070
88#define SNB_SPAD_OFFSET 0x0080 97#define SNB_SPAD_OFFSET 0x0080
89#define SNB_SPADSEMA4_OFFSET 0x00c0 98#define SNB_SPADSEMA4_OFFSET 0x00c0
90#define SNB_WCCNTRL_OFFSET 0x00e0 99#define SNB_WCCNTRL_OFFSET 0x00e0
@@ -93,12 +102,18 @@
93#define SNB_B2B_XLAT_OFFSETL 0x0144 102#define SNB_B2B_XLAT_OFFSETL 0x0144
94#define SNB_B2B_XLAT_OFFSETU 0x0148 103#define SNB_B2B_XLAT_OFFSETU 0x0148
95 104
96#define SNB_MBAR01_USD_ADDR 0x000000210000000CULL 105/*
97#define SNB_MBAR23_USD_ADDR 0x000000410000000CULL 106 * The addresses are setup so the 32bit BARs can function. Thus
98#define SNB_MBAR45_USD_ADDR 0x000000810000000CULL 107 * the addresses are all in 32bit space
99#define SNB_MBAR01_DSD_ADDR 0x000000200000000CULL 108 */
100#define SNB_MBAR23_DSD_ADDR 0x000000400000000CULL 109#define SNB_MBAR01_USD_ADDR 0x000000002100000CULL
101#define SNB_MBAR45_DSD_ADDR 0x000000800000000CULL 110#define SNB_MBAR23_USD_ADDR 0x000000004100000CULL
111#define SNB_MBAR4_USD_ADDR 0x000000008100000CULL
112#define SNB_MBAR5_USD_ADDR 0x00000000A100000CULL
113#define SNB_MBAR01_DSD_ADDR 0x000000002000000CULL
114#define SNB_MBAR23_DSD_ADDR 0x000000004000000CULL
115#define SNB_MBAR4_DSD_ADDR 0x000000008000000CULL
116#define SNB_MBAR5_DSD_ADDR 0x00000000A000000CULL
102 117
103#define BWD_MSIX_CNT 34 118#define BWD_MSIX_CNT 34
104#define BWD_MAX_SPADS 16 119#define BWD_MAX_SPADS 16
@@ -147,13 +162,16 @@
147#define NTB_CNTL_LINK_DISABLE (1 << 1) 162#define NTB_CNTL_LINK_DISABLE (1 << 1)
148#define NTB_CNTL_S2P_BAR23_SNOOP (1 << 2) 163#define NTB_CNTL_S2P_BAR23_SNOOP (1 << 2)
149#define NTB_CNTL_P2S_BAR23_SNOOP (1 << 4) 164#define NTB_CNTL_P2S_BAR23_SNOOP (1 << 4)
150#define NTB_CNTL_S2P_BAR45_SNOOP (1 << 6) 165#define NTB_CNTL_S2P_BAR4_SNOOP (1 << 6)
151#define NTB_CNTL_P2S_BAR45_SNOOP (1 << 8) 166#define NTB_CNTL_P2S_BAR4_SNOOP (1 << 8)
167#define NTB_CNTL_S2P_BAR5_SNOOP (1 << 12)
168#define NTB_CNTL_P2S_BAR5_SNOOP (1 << 14)
152#define BWD_CNTL_LINK_DOWN (1 << 16) 169#define BWD_CNTL_LINK_DOWN (1 << 16)
153 170
154#define NTB_PPD_OFFSET 0x00D4 171#define NTB_PPD_OFFSET 0x00D4
155#define SNB_PPD_CONN_TYPE 0x0003 172#define SNB_PPD_CONN_TYPE 0x0003
156#define SNB_PPD_DEV_TYPE 0x0010 173#define SNB_PPD_DEV_TYPE 0x0010
174#define SNB_PPD_SPLIT_BAR (1 << 6)
157#define BWD_PPD_INIT_LINK 0x0008 175#define BWD_PPD_INIT_LINK 0x0008
158#define BWD_PPD_CONN_TYPE 0x0300 176#define BWD_PPD_CONN_TYPE 0x0300
159#define BWD_PPD_DEV_TYPE 0x1000 177#define BWD_PPD_DEV_TYPE 0x1000