35 #include <linux/pci.h>
36 #include <linux/netdevice.h>
40 #include <linux/module.h>
48 #define pr_fmt(fmt) QIB_DRV_NAME ": " fmt
53 #define QIB_MIN_USER_CTXT_BUFCNT 7
55 #define QLOGIC_IB_R_SOFTWARE_MASK 0xFF
56 #define QLOGIC_IB_R_SOFTWARE_SHIFT 24
57 #define QLOGIC_IB_R_EMULATOR_MASK (1ULL<<62)
81 MODULE_PARM_DESC(cc_table_size,
"Congestion control table entries 0 (CCA disabled - default), min = 128, max = 1984");
94 static void verify_interrupt(
unsigned long);
96 static struct idr qib_unit_table;
107 }
else if (qib_cfgctxts < dd->num_pports)
109 else if (qib_cfgctxts <= dd->ctxtcnt)
132 "Unable to allocate ctxtdata array, failing\n");
149 "Unable to allocate ctxtdata for Kernel ctxt, failing\n");
241 "failed to allocate congestion control table for port %d!\n",
250 "failed to allocate congestion setting list for port %d!\n",
259 "failed to allocate shadow ccti list for port %d!\n",
268 "failed to allocate shadow congestion setting list for port %d!\n",
292 "Congestion Control table size %d less than minimum %d for port %d\n",
296 qib_dev_err(dd,
"Congestion Control Agent disabled for port %d\n",
311 "failed to allocate PIOavail reg area in memory\n");
320 status_page = (
u64 *)
327 for (pidx = 0; pidx < dd->
num_pports; ++pidx) {
328 dd->
pport[pidx].statusp = status_page;
359 static void init_shadow_tids(
struct qib_devdata *dd)
367 "failed to allocate shadow page * array, no expected sends!\n");
374 "failed to allocate shadow dma handle array, no expected sends!\n");
399 "Driver only handles version %d, chip swversion is %d (%llx), failng\n",
403 QLOGIC_IB_R_SOFTWARE_MASK,
422 ret = init_pioavailregs(dd);
423 init_shadow_tids(dd);
444 static int init_after_reset(
struct qib_devdata *dd)
495 static void verify_interrupt(
unsigned long opaque)
509 "No interrupts detected, not usable.\n");
515 static void init_piobuf_state(
struct qib_devdata *dd)
575 static int qib_create_workqueues(
struct qib_devdata *dd)
580 for (pidx = 0; pidx < dd->
num_pports; ++pidx) {
581 ppd = dd->
pport + pidx;
584 snprintf(wq_name,
sizeof(wq_name),
"qib%d_%d",
594 pr_err(
"create_singlethread_workqueue failed for port %d\n",
596 for (pidx = 0; pidx < dd->
num_pports; ++pidx) {
597 ppd = dd->
pport + pidx;
623 int ret = 0, pidx, lastfail = 0;
631 for (pidx = 0; pidx < dd->
num_pports; ++pidx) {
632 ppd = dd->
pport + pidx;
641 ret = init_after_reset(dd);
643 ret = loadtime_init(dd);
672 "failed to allocate kernel ctxt's rcvhdrq and/or egr bufs\n");
677 for (pidx = 0; pidx < dd->
num_pports; ++pidx) {
681 ppd = dd->
pport + pidx;
706 "Failed to bringup IB port %u\n", ppd->
port);
716 if (!ret && lastfail)
725 init_piobuf_state(dd);
730 for (pidx = 0; pidx < dd->
num_pports; ++pidx) {
731 ppd = dd->
pport + pidx;
781 return idr_find(&qib_unit_table, unit);
790 dd = __qib_lookup(unit);
800 static void qib_stop_timers(
struct qib_devdata *dd)
813 for (pidx = 0; pidx < dd->
num_pports; ++pidx) {
814 ppd = dd->
pport + pidx;
835 static void qib_shutdown_device(
struct qib_devdata *dd)
840 for (pidx = 0; pidx < dd->
num_pports; ++pidx) {
841 ppd = dd->
pport + pidx;
855 for (pidx = 0; pidx < dd->
num_pports; ++pidx) {
856 ppd = dd->
pport + pidx;
874 for (pidx = 0; pidx < dd->
num_pports; ++pidx) {
875 ppd = dd->
pport + pidx;
963 static void qib_verify_pioperf(
struct qib_devdata *dd)
973 "No PIObufs for checking perf, skipping\n");
986 "Couldn't get memory for checking PIO perf,"
993 for (lcnt = 0; lcnt < 10000
U; lcnt++) {
1014 for (emsecs = lcnt = 0; emsecs <= 5
UL; lcnt++) {
1020 if (lcnt < (emsecs * 1024U))
1022 "Performance problem: bandwidth to PIO buffers is only %u MiB/sec\n",
1023 lcnt / (
u32) emsecs);
1039 unsigned long flags;
1059 unsigned long flags;
1082 "Could not allocate unit ID: error %d\n", -ret);
1096 "Could not alloc cpulist info, cpu affinity might be wrong\n");
1115 for (pidx = 0; pidx < dd->
num_pports; ++pidx) {
1118 ppd = dd->
pport + pidx;
1141 #define DRIVER_LOAD_MSG "QLogic " QIB_DRV_NAME " loaded: "
1142 #define PFX QIB_DRV_NAME ": "
1155 .probe = qib_init_one,
1157 .id_table = qib_pci_tbl,
1165 static int __init qlogic_ib_init(
void)
1185 pr_err(
"idr_pre_get() failed\n");
1190 ret = pci_register_driver(&qib_driver);
1192 pr_err(
"Unable to register driver: error %d\n", -ret);
1198 pr_err(
"Unable to register ipathfs\n");
1216 static void __exit qlogic_ib_cleanup(
void)
1223 "Unable to cleanup counter filesystem: error %d\n",
1240 static void cleanup_device_data(
struct qib_devdata *dd)
1245 unsigned long flags;
1248 for (pidx = 0; pidx < dd->
num_pports; ++pidx) {
1249 if (dd->
pport[pidx].statusp)
1252 spin_lock(&dd->
pport[pidx].cc_shadow_lock);
1255 dd->
pport[pidx].congestion_entries =
NULL;
1259 dd->
pport[pidx].ccti_entries_shadow =
NULL;
1260 kfree(dd->
pport[pidx].congestion_entries_shadow);
1261 dd->
pport[pidx].congestion_entries_shadow =
NULL;
1263 spin_unlock(&dd->
pport[pidx].cc_shadow_lock);
1281 for (ctxt = 0; ctxt < dd->
cfgctxts; ctxt++) {
1282 int ctxt_tidbase = ctxt * dd->
rcvtidcnt;
1285 for (i = ctxt_tidbase; i <
maxtid; i++) {
1288 pci_unmap_page(dd->
pcidev, tmpd[i],
1311 spin_unlock_irqrestore(&dd->
uctxt_lock, flags);
1312 for (ctxt = 0; tmp && ctxt < dd->
ctxtcnt; ctxt++) {
1326 static void qib_postinit_cleanup(
struct qib_devdata *dd)
1340 cleanup_device_data(dd);
1348 int ret,
j, pidx, initfail;
1361 #ifdef CONFIG_PCI_MSI
1365 "QLogic PCIE device 0x%x cannot work if CONFIG_PCI_MSI is not enabled\n",
1381 "Failing on unknown QLogic deviceid 0x%x\n",
1391 ret = qib_create_workqueues(dd);
1411 qib_dev_err(dd,
"Failed to create /dev devices: %d\n", -j);
1414 qib_dev_err(dd,
"Failed filesystem setup for counters: %d\n",
1418 qib_stop_timers(dd);
1420 for (pidx = 0; pidx < dd->
num_pports; ++pidx)
1430 qib_postinit_cleanup(dd);
1440 "Write combining not enabled (err %d): performance may be poor\n",
1446 qib_verify_pioperf(dd);
1464 qib_shutdown_device(dd);
1466 qib_stop_timers(dd);
1473 qib_dev_err(dd,
"Failed counters filesystem cleanup: %d\n",
1478 qib_postinit_cleanup(dd);
1508 "attempt to allocate %d bytes for ctxt %u rcvhdrq failed\n",
1516 goto bail_free_hdrq;
1539 "attempt to allocate 1 page for ctxt %u rcvhdrqtailaddr failed\n",
1563 unsigned e, egrcnt, egrperchunk,
chunk, egrsize, egroff;
1584 kzalloc(chunk *
sizeof(rcd->
rcvegrbuf[0]),
1594 goto bail_rcvegrbuf;
1604 goto bail_rcvegrbuf_phys;
1616 for (i = 0; e < egrcnt && i < egrperchunk; e++, i++) {
1630 bail_rcvegrbuf_phys:
1661 u64 qib_userlen = 0;
1681 qib_kreglen = qib_pio2koffset;
1682 qib_piolen = qib_pio2klen;
1683 }
else if (qib_pio2koffset < qib_pio4koffset) {
1684 qib_kreglen = qib_pio2koffset;
1685 qib_piolen = qib_pio4koffset + qib_pio4klen - qib_kreglen;
1687 qib_kreglen = qib_pio4koffset;
1688 qib_piolen = qib_pio2koffset + qib_pio2klen - qib_kreglen;
1690 qib_piolen += vl15buflen;
1700 qib_piobase =
ioremap_wc(qib_physaddr + qib_kreglen, qib_piolen);
1713 ((
char __iomem *) qib_kregbase + qib_kreglen);
1717 qib_pio2koffset - qib_kreglen);
1721 qib_pio4koffset - qib_kreglen);