Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge tag 'ntb-3.13' of git://github.com/jonmason/ntb

Pull non-transparent bridge updates from Jon Mason:
"NTB driver bug fixes to address a missed call to pci_enable_msix,
NTB-RP Link Up issue, Xeon Doorbell errata workaround, ntb_transport
link down race, and correct dmaengine_get/put usage.

Also, clean-ups to remove duplicate defines and document a hardware
errata. Finally, some changes to improve performance"

* tag 'ntb-3.13' of git://github.com/jonmason/ntb:
NTB: Disable interrupts and poll under high load
NTB: Enable Snoop on Primary Side
NTB: Document HW errata
NTB: remove duplicate defines
NTB: correct dmaengine_get/put usage
NTB: Fix ntb_transport link down race
ntb: Fix missed call to pci_enable_msix()
NTB: Fix NTB-RP Link Up
NTB: Xeon Doorbell errata workaround

+156 -65
+103 -18
drivers/ntb/ntb_hw.c
··· 141 141 ndev->event_cb = NULL; 142 142 } 143 143 144 + static void ntb_irq_work(unsigned long data) 145 + { 146 + struct ntb_db_cb *db_cb = (struct ntb_db_cb *)data; 147 + int rc; 148 + 149 + rc = db_cb->callback(db_cb->data, db_cb->db_num); 150 + if (rc) 151 + tasklet_schedule(&db_cb->irq_work); 152 + else { 153 + struct ntb_device *ndev = db_cb->ndev; 154 + unsigned long mask; 155 + 156 + mask = readw(ndev->reg_ofs.ldb_mask); 157 + clear_bit(db_cb->db_num * ndev->bits_per_vector, &mask); 158 + writew(mask, ndev->reg_ofs.ldb_mask); 159 + } 160 + } 161 + 144 162 /** 145 163 * ntb_register_db_callback() - register a callback for doorbell interrupt 146 164 * @ndev: pointer to ntb_device instance ··· 173 155 * RETURNS: An appropriate -ERRNO error value on error, or zero for success. 174 156 */ 175 157 int ntb_register_db_callback(struct ntb_device *ndev, unsigned int idx, 176 - void *data, void (*func)(void *data, int db_num)) 158 + void *data, int (*func)(void *data, int db_num)) 177 159 { 178 160 unsigned long mask; 179 161 ··· 184 166 185 167 ndev->db_cb[idx].callback = func; 186 168 ndev->db_cb[idx].data = data; 169 + ndev->db_cb[idx].ndev = ndev; 170 + 171 + tasklet_init(&ndev->db_cb[idx].irq_work, ntb_irq_work, 172 + (unsigned long) &ndev->db_cb[idx]); 187 173 188 174 /* unmask interrupt */ 189 175 mask = readw(ndev->reg_ofs.ldb_mask); ··· 215 193 mask = readw(ndev->reg_ofs.ldb_mask); 216 194 set_bit(idx * ndev->bits_per_vector, &mask); 217 195 writew(mask, ndev->reg_ofs.ldb_mask); 196 + 197 + tasklet_disable(&ndev->db_cb[idx].irq_work); 218 198 219 199 ndev->db_cb[idx].callback = NULL; 220 200 } ··· 702 678 return -EINVAL; 703 679 704 680 ndev->limits.max_mw = SNB_ERRATA_MAX_MW; 681 + ndev->limits.max_db_bits = SNB_MAX_DB_BITS; 705 682 ndev->reg_ofs.spad_write = ndev->mw[1].vbase + 706 683 SNB_SPAD_OFFSET; 707 684 ndev->reg_ofs.rdb = ndev->mw[1].vbase + ··· 713 688 */ 714 689 writeq(ndev->mw[1].bar_sz + 0x1000, ndev->reg_base + 715 690 SNB_PBAR4LMT_OFFSET); 691 + /* HW errata on the Limit registers. They can only be 692 + * written when the base register is 4GB aligned and 693 + * < 32bit. This should already be the case based on the 694 + * driver defaults, but write the Limit registers first 695 + * just in case. 696 + */ 716 697 } else { 717 698 ndev->limits.max_mw = SNB_MAX_MW; 699 + 700 + /* HW Errata on bit 14 of b2bdoorbell register. Writes 701 + * will not be mirrored to the remote system. Shrink 702 + * the number of bits by one, since bit 14 is the last 703 + * bit. 704 + */ 705 + ndev->limits.max_db_bits = SNB_MAX_DB_BITS - 1; 718 706 ndev->reg_ofs.spad_write = ndev->reg_base + 719 707 SNB_B2B_SPAD_OFFSET; 720 708 ndev->reg_ofs.rdb = ndev->reg_base + ··· 737 699 * something silly 738 700 */ 739 701 writeq(0, ndev->reg_base + SNB_PBAR4LMT_OFFSET); 702 + /* HW errata on the Limit registers. They can only be 703 + * written when the base register is 4GB aligned and 704 + * < 32bit. This should already be the case based on the 705 + * driver defaults, but write the Limit registers first 706 + * just in case. 707 + */ 740 708 } 741 709 742 710 /* The Xeon errata workaround requires setting SBAR Base ··· 813 769 * have an equal amount. 814 770 */ 815 771 ndev->limits.max_spads = SNB_MAX_COMPAT_SPADS / 2; 772 + ndev->limits.max_db_bits = SNB_MAX_DB_BITS; 816 773 /* Note: The SDOORBELL is the cause of the errata. You REALLY 817 774 * don't want to touch it. 818 775 */ ··· 838 793 * have an equal amount. 839 794 */ 840 795 ndev->limits.max_spads = SNB_MAX_COMPAT_SPADS / 2; 796 + ndev->limits.max_db_bits = SNB_MAX_DB_BITS; 841 797 ndev->reg_ofs.rdb = ndev->reg_base + SNB_PDOORBELL_OFFSET; 842 798 ndev->reg_ofs.ldb = ndev->reg_base + SNB_SDOORBELL_OFFSET; 843 799 ndev->reg_ofs.ldb_mask = ndev->reg_base + SNB_SDBMSK_OFFSET; ··· 865 819 ndev->reg_ofs.lnk_stat = ndev->reg_base + SNB_SLINK_STATUS_OFFSET; 866 820 ndev->reg_ofs.spci_cmd = ndev->reg_base + SNB_PCICMD_OFFSET; 867 821 868 - ndev->limits.max_db_bits = SNB_MAX_DB_BITS; 869 822 ndev->limits.msix_cnt = SNB_MSIX_CNT; 870 823 ndev->bits_per_vector = SNB_DB_BITS_PER_VEC; 871 824 ··· 979 934 { 980 935 struct ntb_db_cb *db_cb = data; 981 936 struct ntb_device *ndev = db_cb->ndev; 937 + unsigned long mask; 982 938 983 939 dev_dbg(&ndev->pdev->dev, "MSI-X irq %d received for DB %d\n", irq, 984 940 db_cb->db_num); 985 941 986 - if (db_cb->callback) 987 - db_cb->callback(db_cb->data, db_cb->db_num); 942 + mask = readw(ndev->reg_ofs.ldb_mask); 943 + set_bit(db_cb->db_num * ndev->bits_per_vector, &mask); 944 + writew(mask, ndev->reg_ofs.ldb_mask); 945 + 946 + tasklet_schedule(&db_cb->irq_work); 988 947 989 948 /* No need to check for the specific HB irq, any interrupt means 990 949 * we're connected. ··· 1004 955 { 1005 956 struct ntb_db_cb *db_cb = data; 1006 957 struct ntb_device *ndev = db_cb->ndev; 958 + unsigned long mask; 1007 959 1008 960 dev_dbg(&ndev->pdev->dev, "MSI-X irq %d received for DB %d\n", irq, 1009 961 db_cb->db_num); 1010 962 1011 - if (db_cb->callback) 1012 - db_cb->callback(db_cb->data, db_cb->db_num); 963 + mask = readw(ndev->reg_ofs.ldb_mask); 964 + set_bit(db_cb->db_num * ndev->bits_per_vector, &mask); 965 + writew(mask, ndev->reg_ofs.ldb_mask); 966 + 967 + tasklet_schedule(&db_cb->irq_work); 1013 968 1014 969 /* On Sandybridge, there are 16 bits in the interrupt register 1015 970 * but only 4 vectors. So, 5 bits are assigned to the first 3 ··· 1039 986 dev_err(&ndev->pdev->dev, "Error determining link status\n"); 1040 987 1041 988 /* bit 15 is always the link bit */ 1042 - writew(1 << ndev->limits.max_db_bits, ndev->reg_ofs.ldb); 989 + writew(1 << SNB_LINK_DB, ndev->reg_ofs.ldb); 1043 990 1044 991 return IRQ_HANDLED; 1045 992 } ··· 1128 1075 "Only %d MSI-X vectors. Limiting the number of queues to that number.\n", 1129 1076 rc); 1130 1077 msix_entries = rc; 1078 + 1079 + rc = pci_enable_msix(pdev, ndev->msix_entries, msix_entries); 1080 + if (rc) 1081 + goto err1; 1131 1082 } 1132 1083 1133 1084 for (i = 0; i < msix_entries; i++) { ··· 1233 1176 */ 1234 1177 if (ndev->hw_type == BWD_HW) 1235 1178 writeq(~0, ndev->reg_ofs.ldb_mask); 1236 - else 1237 - writew(~(1 << ndev->limits.max_db_bits), 1238 - ndev->reg_ofs.ldb_mask); 1179 + else { 1180 + u16 var = 1 << SNB_LINK_DB; 1181 + writew(~var, ndev->reg_ofs.ldb_mask); 1182 + } 1239 1183 1240 1184 rc = ntb_setup_msix(ndev); 1241 1185 if (!rc) ··· 1344 1286 } 1345 1287 } 1346 1288 1289 + static void ntb_hw_link_up(struct ntb_device *ndev) 1290 + { 1291 + if (ndev->conn_type == NTB_CONN_TRANSPARENT) 1292 + ntb_link_event(ndev, NTB_LINK_UP); 1293 + else { 1294 + u32 ntb_cntl; 1295 + 1296 + /* Let's bring the NTB link up */ 1297 + ntb_cntl = readl(ndev->reg_ofs.lnk_cntl); 1298 + ntb_cntl &= ~(NTB_CNTL_LINK_DISABLE | NTB_CNTL_CFG_LOCK); 1299 + ntb_cntl |= NTB_CNTL_P2S_BAR23_SNOOP | NTB_CNTL_S2P_BAR23_SNOOP; 1300 + ntb_cntl |= NTB_CNTL_P2S_BAR45_SNOOP | NTB_CNTL_S2P_BAR45_SNOOP; 1301 + writel(ntb_cntl, ndev->reg_ofs.lnk_cntl); 1302 + } 1303 + } 1304 + 1305 + static void ntb_hw_link_down(struct ntb_device *ndev) 1306 + { 1307 + u32 ntb_cntl; 1308 + 1309 + if (ndev->conn_type == NTB_CONN_TRANSPARENT) { 1310 + ntb_link_event(ndev, NTB_LINK_DOWN); 1311 + return; 1312 + } 1313 + 1314 + /* Bring NTB link down */ 1315 + ntb_cntl = readl(ndev->reg_ofs.lnk_cntl); 1316 + ntb_cntl &= ~(NTB_CNTL_P2S_BAR23_SNOOP | NTB_CNTL_S2P_BAR23_SNOOP); 1317 + ntb_cntl &= ~(NTB_CNTL_P2S_BAR45_SNOOP | NTB_CNTL_S2P_BAR45_SNOOP); 1318 + ntb_cntl |= NTB_CNTL_LINK_DISABLE | NTB_CNTL_CFG_LOCK; 1319 + writel(ntb_cntl, ndev->reg_ofs.lnk_cntl); 1320 + } 1321 + 1347 1322 static int ntb_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id) 1348 1323 { 1349 1324 struct ntb_device *ndev; ··· 1465 1374 if (rc) 1466 1375 goto err6; 1467 1376 1468 - /* Let's bring the NTB link up */ 1469 - writel(NTB_CNTL_BAR23_SNOOP | NTB_CNTL_BAR45_SNOOP, 1470 - ndev->reg_ofs.lnk_cntl); 1377 + ntb_hw_link_up(ndev); 1471 1378 1472 1379 return 0; 1473 1380 ··· 1495 1406 { 1496 1407 struct ntb_device *ndev = pci_get_drvdata(pdev); 1497 1408 int i; 1498 - u32 ntb_cntl; 1499 1409 1500 - /* Bring NTB link down */ 1501 - ntb_cntl = readl(ndev->reg_ofs.lnk_cntl); 1502 - ntb_cntl |= NTB_CNTL_LINK_DISABLE; 1503 - writel(ntb_cntl, ndev->reg_ofs.lnk_cntl); 1410 + ntb_hw_link_down(ndev); 1504 1411 1505 1412 ntb_transport_free(ndev->ntb_transport); 1506 1413
+4 -3
drivers/ntb/ntb_hw.h
··· 106 106 }; 107 107 108 108 struct ntb_db_cb { 109 - void (*callback) (void *data, int db_num); 109 + int (*callback)(void *data, int db_num); 110 110 unsigned int db_num; 111 111 void *data; 112 112 struct ntb_device *ndev; 113 + struct tasklet_struct irq_work; 113 114 }; 114 115 115 116 struct ntb_device { ··· 229 228 void ntb_unregister_transport(struct ntb_device *ndev); 230 229 void ntb_set_mw_addr(struct ntb_device *ndev, unsigned int mw, u64 addr); 231 230 int ntb_register_db_callback(struct ntb_device *ndev, unsigned int idx, 232 - void *data, void (*db_cb_func) (void *data, 233 - int db_num)); 231 + void *data, int (*db_cb_func)(void *data, 232 + int db_num)); 234 233 void ntb_unregister_db_callback(struct ntb_device *ndev, unsigned int idx); 235 234 int ntb_register_event_callback(struct ntb_device *ndev, 236 235 void (*event_cb_func) (void *handle,
+8 -8
drivers/ntb/ntb_regs.h
··· 55 55 #define SNB_MAX_COMPAT_SPADS 16 56 56 /* Reserve the uppermost bit for link interrupt */ 57 57 #define SNB_MAX_DB_BITS 15 58 + #define SNB_LINK_DB 15 58 59 #define SNB_DB_BITS_PER_VEC 5 59 60 #define SNB_MAX_MW 2 60 61 #define SNB_ERRATA_MAX_MW 1 ··· 76 75 #define SNB_SBAR2XLAT_OFFSET 0x0030 77 76 #define SNB_SBAR4XLAT_OFFSET 0x0038 78 77 #define SNB_SBAR0BASE_OFFSET 0x0040 79 - #define SNB_SBAR0BASE_OFFSET 0x0040 80 - #define SNB_SBAR2BASE_OFFSET 0x0048 81 - #define SNB_SBAR4BASE_OFFSET 0x0050 82 78 #define SNB_SBAR2BASE_OFFSET 0x0048 83 79 #define SNB_SBAR4BASE_OFFSET 0x0050 84 80 #define SNB_NTBCNTL_OFFSET 0x0058 ··· 143 145 #define BWD_LTSSMSTATEJMP_FORCEDETECT (1 << 2) 144 146 #define BWD_IBIST_ERR_OFLOW 0x7FFF7FFF 145 147 146 - #define NTB_CNTL_CFG_LOCK (1 << 0) 147 - #define NTB_CNTL_LINK_DISABLE (1 << 1) 148 - #define NTB_CNTL_BAR23_SNOOP (1 << 2) 149 - #define NTB_CNTL_BAR45_SNOOP (1 << 6) 150 - #define BWD_CNTL_LINK_DOWN (1 << 16) 148 + #define NTB_CNTL_CFG_LOCK (1 << 0) 149 + #define NTB_CNTL_LINK_DISABLE (1 << 1) 150 + #define NTB_CNTL_S2P_BAR23_SNOOP (1 << 2) 151 + #define NTB_CNTL_P2S_BAR23_SNOOP (1 << 4) 152 + #define NTB_CNTL_S2P_BAR45_SNOOP (1 << 6) 153 + #define NTB_CNTL_P2S_BAR45_SNOOP (1 << 8) 154 + #define BWD_CNTL_LINK_DOWN (1 << 16) 151 155 152 156 #define NTB_PPD_OFFSET 0x00D4 153 157 #define SNB_PPD_CONN_TYPE 0x0003
+41 -36
drivers/ntb/ntb_transport.c
··· 119 119 120 120 void (*rx_handler) (struct ntb_transport_qp *qp, void *qp_data, 121 121 void *data, int len); 122 - struct tasklet_struct rx_work; 123 122 struct list_head rx_pend_q; 124 123 struct list_head rx_free_q; 125 124 spinlock_t ntb_rx_pend_q_lock; ··· 583 584 return 0; 584 585 } 585 586 586 - static void ntb_qp_link_cleanup(struct work_struct *work) 587 + static void ntb_qp_link_cleanup(struct ntb_transport_qp *qp) 587 588 { 588 - struct ntb_transport_qp *qp = container_of(work, 589 - struct ntb_transport_qp, 590 - link_cleanup); 591 589 struct ntb_transport *nt = qp->transport; 592 590 struct pci_dev *pdev = ntb_query_pdev(nt->ndev); 593 591 ··· 598 602 599 603 dev_info(&pdev->dev, "qp %d: Link Down\n", qp->qp_num); 600 604 qp->qp_link = NTB_LINK_DOWN; 605 + } 606 + 607 + static void ntb_qp_link_cleanup_work(struct work_struct *work) 608 + { 609 + struct ntb_transport_qp *qp = container_of(work, 610 + struct ntb_transport_qp, 611 + link_cleanup); 612 + struct ntb_transport *nt = qp->transport; 613 + 614 + ntb_qp_link_cleanup(qp); 601 615 602 616 if (nt->transport_link == NTB_LINK_UP) 603 617 schedule_delayed_work(&qp->link_work, ··· 619 613 schedule_work(&qp->link_cleanup); 620 614 } 621 615 622 - static void ntb_transport_link_cleanup(struct work_struct *work) 616 + static void ntb_transport_link_cleanup(struct ntb_transport *nt) 623 617 { 624 - struct ntb_transport *nt = container_of(work, struct ntb_transport, 625 - link_cleanup); 626 618 int i; 619 + 620 + /* Pass along the info to any clients */ 621 + for (i = 0; i < nt->max_qps; i++) 622 + if (!test_bit(i, &nt->qp_bitmap)) 623 + ntb_qp_link_cleanup(&nt->qps[i]); 627 624 628 625 if (nt->transport_link == NTB_LINK_DOWN) 629 626 cancel_delayed_work_sync(&nt->link_work); 630 627 else 631 628 nt->transport_link = NTB_LINK_DOWN; 632 - 633 - /* Pass along the info to any clients */ 634 - for (i = 0; i < nt->max_qps; i++) 635 - if (!test_bit(i, &nt->qp_bitmap)) 636 - ntb_qp_link_down(&nt->qps[i]); 637 629 638 630 /* The scratchpad registers keep the values if the remote side 639 631 * goes down, blast them now to give them a sane value the next ··· 639 635 */ 640 636 for (i = 0; i < MAX_SPAD; i++) 641 637 ntb_write_local_spad(nt->ndev, i, 0); 638 + } 639 + 640 + static void ntb_transport_link_cleanup_work(struct work_struct *work) 641 + { 642 + struct ntb_transport *nt = container_of(work, struct ntb_transport, 643 + link_cleanup); 644 + 645 + ntb_transport_link_cleanup(nt); 642 646 } 643 647 644 648 static void ntb_transport_event_callback(void *data, enum ntb_hw_event event) ··· 892 880 } 893 881 894 882 INIT_DELAYED_WORK(&qp->link_work, ntb_qp_link_work); 895 - INIT_WORK(&qp->link_cleanup, ntb_qp_link_cleanup); 883 + INIT_WORK(&qp->link_cleanup, ntb_qp_link_cleanup_work); 896 884 897 885 spin_lock_init(&qp->ntb_rx_pend_q_lock); 898 886 spin_lock_init(&qp->ntb_rx_free_q_lock); ··· 948 936 } 949 937 950 938 INIT_DELAYED_WORK(&nt->link_work, ntb_transport_link_work); 951 - INIT_WORK(&nt->link_cleanup, ntb_transport_link_cleanup); 939 + INIT_WORK(&nt->link_cleanup, ntb_transport_link_cleanup_work); 952 940 953 941 rc = ntb_register_event_callback(nt->ndev, 954 942 ntb_transport_event_callback); ··· 984 972 struct ntb_device *ndev = nt->ndev; 985 973 int i; 986 974 987 - nt->transport_link = NTB_LINK_DOWN; 975 + ntb_transport_link_cleanup(nt); 988 976 989 977 /* verify that all the qp's are freed */ 990 978 for (i = 0; i < nt->max_qps; i++) { ··· 1200 1188 goto out; 1201 1189 } 1202 1190 1203 - static void ntb_transport_rx(unsigned long data) 1191 + static int ntb_transport_rxc_db(void *data, int db_num) 1204 1192 { 1205 - struct ntb_transport_qp *qp = (struct ntb_transport_qp *)data; 1193 + struct ntb_transport_qp *qp = data; 1206 1194 int rc, i; 1195 + 1196 + dev_dbg(&ntb_query_pdev(qp->ndev)->dev, "%s: doorbell %d received\n", 1197 + __func__, db_num); 1207 1198 1208 1199 /* Limit the number of packets processed in a single interrupt to 1209 1200 * provide fairness to others ··· 1219 1204 1220 1205 if (qp->dma_chan) 1221 1206 dma_async_issue_pending(qp->dma_chan); 1222 - } 1223 1207 1224 - static void ntb_transport_rxc_db(void *data, int db_num) 1225 - { 1226 - struct ntb_transport_qp *qp = data; 1227 - 1228 - dev_dbg(&ntb_query_pdev(qp->ndev)->dev, "%s: doorbell %d received\n", 1229 - __func__, db_num); 1230 - 1231 - tasklet_schedule(&qp->rx_work); 1208 + return i; 1232 1209 } 1233 1210 1234 1211 static void ntb_tx_copy_callback(void *data) ··· 1439 1432 qp->tx_handler = handlers->tx_handler; 1440 1433 qp->event_handler = handlers->event_handler; 1441 1434 1435 + dmaengine_get(); 1442 1436 qp->dma_chan = dma_find_channel(DMA_MEMCPY); 1443 - if (!qp->dma_chan) 1437 + if (!qp->dma_chan) { 1438 + dmaengine_put(); 1444 1439 dev_info(&pdev->dev, "Unable to allocate DMA channel, using CPU instead\n"); 1445 - else 1446 - dmaengine_get(); 1440 + } 1447 1441 1448 1442 for (i = 0; i < NTB_QP_DEF_NUM_ENTRIES; i++) { 1449 1443 entry = kzalloc(sizeof(struct ntb_queue_entry), GFP_ATOMIC); ··· 1466 1458 &qp->tx_free_q); 1467 1459 } 1468 1460 1469 - tasklet_init(&qp->rx_work, ntb_transport_rx, (unsigned long) qp); 1470 - 1471 1461 rc = ntb_register_db_callback(qp->ndev, free_queue, qp, 1472 1462 ntb_transport_rxc_db); 1473 1463 if (rc) 1474 - goto err3; 1464 + goto err2; 1475 1465 1476 1466 dev_info(&pdev->dev, "NTB Transport QP %d created\n", qp->qp_num); 1477 1467 1478 1468 return qp; 1479 1469 1480 - err3: 1481 - tasklet_disable(&qp->rx_work); 1482 1470 err2: 1483 1471 while ((entry = ntb_list_rm(&qp->ntb_tx_free_q_lock, &qp->tx_free_q))) 1484 1472 kfree(entry); 1485 1473 err1: 1486 1474 while ((entry = ntb_list_rm(&qp->ntb_rx_free_q_lock, &qp->rx_free_q))) 1487 1475 kfree(entry); 1476 + if (qp->dma_chan) 1477 + dmaengine_put(); 1488 1478 set_bit(free_queue, &nt->qp_bitmap); 1489 1479 err: 1490 1480 return NULL; ··· 1521 1515 } 1522 1516 1523 1517 ntb_unregister_db_callback(qp->ndev, qp->qp_num); 1524 - tasklet_disable(&qp->rx_work); 1525 1518 1526 1519 cancel_delayed_work_sync(&qp->link_work); 1527 1520