aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/tg3.c
diff options
context:
space:
mode:
authorDavid S. Miller <davem@davemloft.net>2005-05-19 01:50:10 -0400
committerDavid S. Miller <davem@davemloft.net>2005-05-19 01:50:10 -0400
commit59e6b4343299373bc10dd131ab5142f53ddd838a (patch)
tree1381e9d661f4ff83e89cb17678ce4813a90c4afb /drivers/net/tg3.c
parent15f9850d3c2d46f5851a424d2990a18b5bb5ebfd (diff)
[TG3]: Refine DMA boundary setting.
Extract DMA boundary bit selection into a seperate function, tg3_calc_dma_bndry(). Call this from tg3_test_dma(). Make DMA test more reliable by using no DMA boundry setting during the test. If the test passes, then use the setting we selected before the test. Signed-off-by: David S. Miller <davem@davemloft.net> Signed-off-by: Michael Chan <mchan@broadcom.com>
Diffstat (limited to 'drivers/net/tg3.c')
-rw-r--r--drivers/net/tg3.c207
1 files changed, 163 insertions, 44 deletions
diff --git a/drivers/net/tg3.c b/drivers/net/tg3.c
index 3df5b78d2693..4ab9680ffbd2 100644
--- a/drivers/net/tg3.c
+++ b/drivers/net/tg3.c
@@ -8775,6 +8775,146 @@ static int __devinit tg3_get_device_address(struct tg3 *tp)
8775 return 0; 8775 return 0;
8776} 8776}
8777 8777
8778#define BOUNDARY_SINGLE_CACHELINE 1
8779#define BOUNDARY_MULTI_CACHELINE 2
8780
8781static u32 __devinit tg3_calc_dma_bndry(struct tg3 *tp, u32 val)
8782{
8783 int cacheline_size;
8784 u8 byte;
8785 int goal;
8786
8787 pci_read_config_byte(tp->pdev, PCI_CACHE_LINE_SIZE, &byte);
8788 if (byte == 0)
8789 cacheline_size = 1024;
8790 else
8791 cacheline_size = (int) byte * 4;
8792
8793 /* On 5703 and later chips, the boundary bits have no
8794 * effect.
8795 */
8796 if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5700 &&
8797 GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5701 &&
8798 !(tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS))
8799 goto out;
8800
8801#if defined(CONFIG_PPC64) || defined(CONFIG_IA64) || defined(CONFIG_PARISC)
8802 goal = BOUNDARY_MULTI_CACHELINE;
8803#else
8804#if defined(CONFIG_SPARC64) || defined(CONFIG_ALPHA)
8805 goal = BOUNDARY_SINGLE_CACHELINE;
8806#else
8807 goal = 0;
8808#endif
8809#endif
8810
8811 if (!goal)
8812 goto out;
8813
8814 /* PCI controllers on most RISC systems tend to disconnect
8815 * when a device tries to burst across a cache-line boundary.
8816 * Therefore, letting tg3 do so just wastes PCI bandwidth.
8817 *
8818 * Unfortunately, for PCI-E there are only limited
8819 * write-side controls for this, and thus for reads
8820 * we will still get the disconnects. We'll also waste
8821 * these PCI cycles for both read and write for chips
8822 * other than 5700 and 5701 which do not implement the
8823 * boundary bits.
8824 */
8825 if ((tp->tg3_flags & TG3_FLAG_PCIX_MODE) &&
8826 !(tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS)) {
8827 switch (cacheline_size) {
8828 case 16:
8829 case 32:
8830 case 64:
8831 case 128:
8832 if (goal == BOUNDARY_SINGLE_CACHELINE) {
8833 val |= (DMA_RWCTRL_READ_BNDRY_128_PCIX |
8834 DMA_RWCTRL_WRITE_BNDRY_128_PCIX);
8835 } else {
8836 val |= (DMA_RWCTRL_READ_BNDRY_384_PCIX |
8837 DMA_RWCTRL_WRITE_BNDRY_384_PCIX);
8838 }
8839 break;
8840
8841 case 256:
8842 val |= (DMA_RWCTRL_READ_BNDRY_256_PCIX |
8843 DMA_RWCTRL_WRITE_BNDRY_256_PCIX);
8844 break;
8845
8846 default:
8847 val |= (DMA_RWCTRL_READ_BNDRY_384_PCIX |
8848 DMA_RWCTRL_WRITE_BNDRY_384_PCIX);
8849 break;
8850 };
8851 } else if (tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS) {
8852 switch (cacheline_size) {
8853 case 16:
8854 case 32:
8855 case 64:
8856 if (goal == BOUNDARY_SINGLE_CACHELINE) {
8857 val &= ~DMA_RWCTRL_WRITE_BNDRY_DISAB_PCIE;
8858 val |= DMA_RWCTRL_WRITE_BNDRY_64_PCIE;
8859 break;
8860 }
8861 /* fallthrough */
8862 case 128:
8863 default:
8864 val &= ~DMA_RWCTRL_WRITE_BNDRY_DISAB_PCIE;
8865 val |= DMA_RWCTRL_WRITE_BNDRY_128_PCIE;
8866 break;
8867 };
8868 } else {
8869 switch (cacheline_size) {
8870 case 16:
8871 if (goal == BOUNDARY_SINGLE_CACHELINE) {
8872 val |= (DMA_RWCTRL_READ_BNDRY_16 |
8873 DMA_RWCTRL_WRITE_BNDRY_16);
8874 break;
8875 }
8876 /* fallthrough */
8877 case 32:
8878 if (goal == BOUNDARY_SINGLE_CACHELINE) {
8879 val |= (DMA_RWCTRL_READ_BNDRY_32 |
8880 DMA_RWCTRL_WRITE_BNDRY_32);
8881 break;
8882 }
8883 /* fallthrough */
8884 case 64:
8885 if (goal == BOUNDARY_SINGLE_CACHELINE) {
8886 val |= (DMA_RWCTRL_READ_BNDRY_64 |
8887 DMA_RWCTRL_WRITE_BNDRY_64);
8888 break;
8889 }
8890 /* fallthrough */
8891 case 128:
8892 if (goal == BOUNDARY_SINGLE_CACHELINE) {
8893 val |= (DMA_RWCTRL_READ_BNDRY_128 |
8894 DMA_RWCTRL_WRITE_BNDRY_128);
8895 break;
8896 }
8897 /* fallthrough */
8898 case 256:
8899 val |= (DMA_RWCTRL_READ_BNDRY_256 |
8900 DMA_RWCTRL_WRITE_BNDRY_256);
8901 break;
8902 case 512:
8903 val |= (DMA_RWCTRL_READ_BNDRY_512 |
8904 DMA_RWCTRL_WRITE_BNDRY_512);
8905 break;
8906 case 1024:
8907 default:
8908 val |= (DMA_RWCTRL_READ_BNDRY_1024 |
8909 DMA_RWCTRL_WRITE_BNDRY_1024);
8910 break;
8911 };
8912 }
8913
8914out:
8915 return val;
8916}
8917
8778static int __devinit tg3_do_test_dma(struct tg3 *tp, u32 *buf, dma_addr_t buf_dma, int size, int to_device) 8918static int __devinit tg3_do_test_dma(struct tg3 *tp, u32 *buf, dma_addr_t buf_dma, int size, int to_device)
8779{ 8919{
8780 struct tg3_internal_buffer_desc test_desc; 8920 struct tg3_internal_buffer_desc test_desc;
@@ -8861,7 +9001,7 @@ static int __devinit tg3_do_test_dma(struct tg3 *tp, u32 *buf, dma_addr_t buf_dm
8861static int __devinit tg3_test_dma(struct tg3 *tp) 9001static int __devinit tg3_test_dma(struct tg3 *tp)
8862{ 9002{
8863 dma_addr_t buf_dma; 9003 dma_addr_t buf_dma;
8864 u32 *buf; 9004 u32 *buf, saved_dma_rwctrl;
8865 int ret; 9005 int ret;
8866 9006
8867 buf = pci_alloc_consistent(tp->pdev, TEST_BUFFER_SIZE, &buf_dma); 9007 buf = pci_alloc_consistent(tp->pdev, TEST_BUFFER_SIZE, &buf_dma);
@@ -8873,46 +9013,7 @@ static int __devinit tg3_test_dma(struct tg3 *tp)
8873 tp->dma_rwctrl = ((0x7 << DMA_RWCTRL_PCI_WRITE_CMD_SHIFT) | 9013 tp->dma_rwctrl = ((0x7 << DMA_RWCTRL_PCI_WRITE_CMD_SHIFT) |
8874 (0x6 << DMA_RWCTRL_PCI_READ_CMD_SHIFT)); 9014 (0x6 << DMA_RWCTRL_PCI_READ_CMD_SHIFT));
8875 9015
8876#ifndef CONFIG_X86 9016 tp->dma_rwctrl = tg3_calc_dma_bndry(tp, tp->dma_rwctrl);
8877 {
8878 u8 byte;
8879 int cacheline_size;
8880 pci_read_config_byte(tp->pdev, PCI_CACHE_LINE_SIZE, &byte);
8881
8882 if (byte == 0)
8883 cacheline_size = 1024;
8884 else
8885 cacheline_size = (int) byte * 4;
8886
8887 switch (cacheline_size) {
8888 case 16:
8889 case 32:
8890 case 64:
8891 case 128:
8892 if ((tp->tg3_flags & TG3_FLAG_PCIX_MODE) &&
8893 !(tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS)) {
8894 tp->dma_rwctrl |=
8895 DMA_RWCTRL_WRITE_BNDRY_384_PCIX;
8896 break;
8897 } else if (tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS) {
8898 tp->dma_rwctrl &=
8899 ~(DMA_RWCTRL_PCI_WRITE_CMD);
8900 tp->dma_rwctrl |=
8901 DMA_RWCTRL_WRITE_BNDRY_128_PCIE;
8902 break;
8903 }
8904 /* fallthrough */
8905 case 256:
8906 if (!(tp->tg3_flags & TG3_FLAG_PCIX_MODE) &&
8907 !(tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS))
8908 tp->dma_rwctrl |=
8909 DMA_RWCTRL_WRITE_BNDRY_256;
8910 else if (!(tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS))
8911 tp->dma_rwctrl |=
8912 DMA_RWCTRL_WRITE_BNDRY_256_PCIX;
8913 };
8914 }
8915#endif
8916 9017
8917 if (tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS) { 9018 if (tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS) {
8918 /* DMA read watermark not used on PCIE */ 9019 /* DMA read watermark not used on PCIE */
@@ -8931,7 +9032,7 @@ static int __devinit tg3_test_dma(struct tg3 *tp)
8931 if (ccval == 0x6 || ccval == 0x7) 9032 if (ccval == 0x6 || ccval == 0x7)
8932 tp->dma_rwctrl |= DMA_RWCTRL_ONE_DMA; 9033 tp->dma_rwctrl |= DMA_RWCTRL_ONE_DMA;
8933 9034
8934 /* Set bit 23 to renable PCIX hw bug fix */ 9035 /* Set bit 23 to enable PCIX hw bug fix */
8935 tp->dma_rwctrl |= 0x009f0000; 9036 tp->dma_rwctrl |= 0x009f0000;
8936 } else { 9037 } else {
8937 tp->dma_rwctrl |= 0x001b000f; 9038 tp->dma_rwctrl |= 0x001b000f;
@@ -8972,6 +9073,13 @@ static int __devinit tg3_test_dma(struct tg3 *tp)
8972 GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5701) 9073 GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5701)
8973 goto out; 9074 goto out;
8974 9075
9076 /* It is best to perform DMA test with maximum write burst size
9077 * to expose the 5700/5701 write DMA bug.
9078 */
9079 saved_dma_rwctrl = tp->dma_rwctrl;
9080 tp->dma_rwctrl &= ~DMA_RWCTRL_WRITE_BNDRY_MASK;
9081 tw32(TG3PCI_DMA_RW_CTRL, tp->dma_rwctrl);
9082
8975 while (1) { 9083 while (1) {
8976 u32 *p = buf, i; 9084 u32 *p = buf, i;
8977 9085
@@ -9010,8 +9118,9 @@ static int __devinit tg3_test_dma(struct tg3 *tp)
9010 if (p[i] == i) 9118 if (p[i] == i)
9011 continue; 9119 continue;
9012 9120
9013 if ((tp->dma_rwctrl & DMA_RWCTRL_WRITE_BNDRY_MASK) == 9121 if ((tp->dma_rwctrl & DMA_RWCTRL_WRITE_BNDRY_MASK) !=
9014 DMA_RWCTRL_WRITE_BNDRY_DISAB) { 9122 DMA_RWCTRL_WRITE_BNDRY_16) {
9123 tp->dma_rwctrl &= ~DMA_RWCTRL_WRITE_BNDRY_MASK;
9015 tp->dma_rwctrl |= DMA_RWCTRL_WRITE_BNDRY_16; 9124 tp->dma_rwctrl |= DMA_RWCTRL_WRITE_BNDRY_16;
9016 tw32(TG3PCI_DMA_RW_CTRL, tp->dma_rwctrl); 9125 tw32(TG3PCI_DMA_RW_CTRL, tp->dma_rwctrl);
9017 break; 9126 break;
@@ -9028,6 +9137,14 @@ static int __devinit tg3_test_dma(struct tg3 *tp)
9028 break; 9137 break;
9029 } 9138 }
9030 } 9139 }
9140 if ((tp->dma_rwctrl & DMA_RWCTRL_WRITE_BNDRY_MASK) !=
9141 DMA_RWCTRL_WRITE_BNDRY_16) {
9142 /* DMA test passed without adjusting DMA boundary,
9143 * just restore the calculated DMA boundary
9144 */
9145 tp->dma_rwctrl = saved_dma_rwctrl;
9146 tw32(TG3PCI_DMA_RW_CTRL, tp->dma_rwctrl);
9147 }
9031 9148
9032out: 9149out:
9033 pci_free_consistent(tp->pdev, TEST_BUFFER_SIZE, buf, buf_dma); 9150 pci_free_consistent(tp->pdev, TEST_BUFFER_SIZE, buf, buf_dma);
@@ -9429,6 +9546,8 @@ static int __devinit tg3_init_one(struct pci_dev *pdev,
9429 (tp->tg3_flags & TG3_FLAG_SPLIT_MODE) != 0, 9546 (tp->tg3_flags & TG3_FLAG_SPLIT_MODE) != 0,
9430 (tp->tg3_flags2 & TG3_FLG2_NO_ETH_WIRE_SPEED) == 0, 9547 (tp->tg3_flags2 & TG3_FLG2_NO_ETH_WIRE_SPEED) == 0,
9431 (tp->tg3_flags2 & TG3_FLG2_TSO_CAPABLE) != 0); 9548 (tp->tg3_flags2 & TG3_FLG2_TSO_CAPABLE) != 0);
9549 printk(KERN_INFO "%s: dma_rwctrl[%08x]\n",
9550 dev->name, tp->dma_rwctrl);
9432 9551
9433 return 0; 9552 return 0;
9434 9553