34 #include <linux/sched.h>
37 #include <linux/pci.h>
40 #include <linux/netdevice.h>
42 #include <linux/bitmap.h>
43 #include <linux/slab.h>
44 #include <linux/module.h>
53 static char iname[16];
54 snprintf(iname,
sizeof iname,
"infinipath%u", unit);
58 #define DRIVER_LOAD_MSG "QLogic " IPATH_DRV_NAME " loaded: "
59 #define PFX IPATH_DRV_NAME ": "
67 static struct idr unit_table;
83 static unsigned ipath_hol_timeout_ms = 13000;
86 "duration of user app suspension after link failure");
121 "CfgWaitCfgEnhanced",
126 "LTState18",
"LTState19",
"LTState1A",
"LTState1B",
127 "LTState1C",
"LTState1D",
"LTState1E",
"LTState1F"
135 #define PCI_VENDOR_ID_PATHSCALE 0x1fc1
136 #define PCI_DEVICE_ID_INFINIPATH_HT 0xd
139 #define STATUS_TIMEOUT 60
150 .probe = ipath_init_one,
152 .id_table = ipath_pci_tbl,
173 ipath_dbg(
"Read bar0 %x bar1 %x\n", *bar0, *bar1);
176 static void ipath_free_devdata(
struct pci_dev *pdev,
181 pci_set_drvdata(pdev,
NULL);
187 spin_unlock_irqrestore(&ipath_devs_lock, flags);
215 ": Could not allocate unit ID: error %d\n", -ret);
216 ipath_free_devdata(pdev, dd);
222 pci_set_drvdata(pdev, dd);
227 spin_unlock_irqrestore(&ipath_devs_lock, flags);
244 dd = __ipath_lookup(unit);
252 int nunits, npresent, nup;
257 nunits = npresent = nup = maxports = 0;
276 *npresentp = npresent;
280 *maxportsp = maxports;
323 "No PIObufs for checking perf, skipping\n");
336 "Couldn't get memory for checking PIO perf,"
343 for (lcnt = 0; lcnt < 10000
U; lcnt++) {
368 for (emsecs = lcnt = 0; emsecs <= 5
UL; lcnt++) {
374 if (lcnt < (emsecs * 1024U))
376 "Performance problem: bandwidth to PIO buffers is "
378 lcnt / (
u32) emsecs);
380 ipath_dbg(
"PIO buffer bandwidth %u MiB/sec is OK\n",
381 lcnt / (
u32) emsecs);
400 unsigned long long addr;
401 u32 bar0 = 0, bar1 = 0;
403 dd = ipath_alloc_devdata(pdev);
407 ": Could not allocate devdata: error %d\n", -ret);
434 "driver_data %lx\n", addr, len, pdev->
irq, ent->
vendor,
437 read_bars(dd, pdev, &bar0, &bar1);
439 if (!bar1 && !(bar0 & ~0xf)) {
442 "rewriting as %llx\n", addr);
443 ret = pci_write_config_dword(
447 "failed: err %d\n", -ret);
450 ret = pci_write_config_dword(
454 "failed: err %d\n", -ret);
459 "not usable until reboot\n");
467 dev_info(&pdev->
dev,
"pci_request_regions unit %u fails: "
482 "Unable to set DMA mask for unit %u: %d\n",
487 ipath_dbg(
"No 64bit DMA mask, used 32 bit mask\n");
488 ret = pci_set_consistent_dma_mask(pdev,
DMA_BIT_MASK(32));
491 "Unable to set DMA consistent mask "
498 ret = pci_set_consistent_dma_mask(pdev,
DMA_BIT_MASK(64));
501 "Unable to set DMA consistent mask "
525 "failing\n", ent->
device);
529 for (j = 0; j < 6; j++) {
545 #if defined(__powerpc__)
554 ipath_dbg(
"Unable to map io addr %llx to kvirt, failing\n",
568 "continuing anyway\n");
597 "(err %d): performance may be poor\n",
602 ipath_verify_pioperf(dd);
631 ipath_free_devdata(pdev, dd);
688 for (i = port_tidbase; i <
maxtid; i++) {
691 pci_unmap_page(dd->
pcidev, tmpd[i],
701 "entries locked\n", cnt);
706 "unlocked via ipath_m{un}lock\n",
778 ipath_dbg(
"irq is 0, not doing free_irq "
796 ipath_free_devdata(pdev, dd);
821 ipath_cdbg(PKT,
"disarm %u PIObufs first=%u\n", cnt, first);
822 for (i = first; i < last; i++) {
833 ipath_read_kreg64(dd, dd->
ipath_kregs->kr_scratch);
869 val = ipath_read_kreg64(dd, dd->
ipath_kregs->kr_ibcstatus);
871 (
unsigned long long) ipath_read_kreg64(
873 (
unsigned long long) val,
880 char *
buf,
size_t blen)
882 static const struct {
906 if ((err & errs[i].err) && !expected)
907 bidx +=
snprintf(buf + bidx, blen - bidx,
924 if (!(err & ~INFINIPATH_E_PKTERRS))
937 strlcat(buf,
"rshortpktlen ", blen);
939 strlcat(buf,
"sdroppeddatapkt ", blen);
941 strlcat(buf,
"spktlen ", blen);
950 strlcat(buf,
"rhdrlen ", blen);
952 strlcat(buf,
"rbadtid ", blen);
954 strlcat(buf,
"rbadversion ", blen);
958 strlcat(buf,
"sendspecialtrigger ", blen);
960 strlcat(buf,
"rlongpktlen ", blen);
962 strlcat(buf,
"rmaxpktlen ", blen);
964 strlcat(buf,
"rminpktlen ", blen);
966 strlcat(buf,
"sminpktlen ", blen);
968 strlcat(buf,
"rformaterr ", blen);
970 strlcat(buf,
"runsupvl ", blen);
972 strlcat(buf,
"runexpchar ", blen);
974 strlcat(buf,
"ribflow ", blen);
976 strlcat(buf,
"sunderrun ", blen);
978 strlcat(buf,
"spioarmlaunch ", blen);
980 strlcat(buf,
"sunexperrpktnum ", blen);
982 strlcat(buf,
"sdroppedsmppkt ", blen);
984 strlcat(buf,
"smaxpktlen ", blen);
986 strlcat(buf,
"sunsupVL ", blen);
988 strlcat(buf,
"invalidaddr ", blen);
990 strlcat(buf,
"rcvegrfull ", blen);
992 strlcat(buf,
"rcvhdrfull ", blen);
994 strlcat(buf,
"ibcstatuschg ", blen);
996 strlcat(buf,
"riblostlink ", blen);
998 strlcat(buf,
"hardware ", blen);
1002 decode_sdma_errs(dd, err, buf, blen);
1004 strlcat(buf,
"invalideepromcmd ", blen);
1017 static void get_rhf_errstring(
u32 err,
char *
msg,
size_t len)
1023 strlcat(msg,
"icrcerr ", len);
1025 strlcat(msg,
"vcrcerr ", len);
1027 strlcat(msg,
"parityerr ", len);
1034 strlcat(msg,
"ipathhdrerr ", len);
1039 strlcat(msg,
"invalid ipathhdr ", len);
1094 skb = __dev_alloc_skb(len, gfp_mask);
1101 skb_reserve(skb, 4);
1106 skb_reserve(skb, 2048 - una);
1122 get_rhf_errstring(eflags, emsg,
sizeof emsg);
1123 ipath_cdbg(PKT,
"RHFerrs %x hdrqtail=%x typ=%u "
1124 "tlen=%x opcode=%x egridx=%x: %s\n",
1126 ipath_hdrget_rcv_type(rhf_addr),
1127 ipath_hdrget_length_in_bytes(rhf_addr),
1132 if (eflags & (INFINIPATH_RHF_H_ICRCERR | INFINIPATH_RHF_H_VCRCERR)) {
1157 u32 etail = -1,
l, hdrqtail;
1159 u32 eflags,
i, etype, tlen, pkttot = 0, updegr = 0, reloop = 0;
1160 static u64 totcalls;
1166 u32 seq = ipath_hdrget_seq(rhf_addr);
1172 hdrqtail = ipath_get_rcvhdrtail(pd);
1179 for (last = 0, i = 1; !last; i += !last) {
1181 eflags = ipath_hdrget_err_flags(rhf_addr);
1182 etype = ipath_hdrget_rcv_type(rhf_addr);
1184 tlen = ipath_hdrget_length_in_bytes(rhf_addr);
1187 ipath_hdrget_use_egr_buf(rhf_addr) :
1196 etail = ipath_hdrget_index(rhf_addr);
1198 if (tlen >
sizeof(*hdr) ||
1200 ebuf = ipath_get_egrbuf(dd, etail);
1210 ipath_hdrget_ipath_ver(hdr->
iph.ver_port_tid_offset) !=
1212 ipath_cdbg(PKT,
"Bad InfiniPath protocol version "
1216 ipath_rcv_hdrerr(dd, eflags, l, etail, rhf_addr, hdr);
1225 "qp=%x), len %x; ignored\n",
1226 etype, opcode, qp, tlen);
1229 ipath_dbg(
"Bug: Expected TID, opcode %x; ignored\n",
1239 ipath_cdbg(ERRPKT,
"Error Pkt, but no eflags! egrbuf"
1240 " %x, len %x hdrq+%x rhf: %Lx\n",
1241 etail, tlen, l, (
unsigned long long)
1244 u32 j, *
d, dw = rsize-2;
1245 if (rsize > (tlen>>2))
1250 for (j = 0; j < dw; j++)
1252 (j%8) == 7 ?
"\n" :
" ");
1262 u32 seq = ipath_hdrget_seq(rhf_addr);
1268 }
else if (l == hdrqtail)
1275 if (last || !(i & 0xf)) {
1301 u32 hqtail = ipath_get_rcvhdrtail(pd);
1302 if (hqtail != hdrqtail) {
1333 unsigned long flags;
1355 ipath_dbg(
"Update shadow pioavail, but regs_dma NULL!\n");
1363 ipath_cdbg(PKT,
"Refill avail, dma0=%llx shad0=%lx, "
1364 "d1=%llx s1=%lx, d2=%llx s2=%lx, d3=%llx "
1376 PKT,
"2nd group, dma4=%llx shad4=%lx, "
1377 "d5=%llx s5=%lx, d6=%llx s6=%lx, "
1389 for (i = 0; i < piobregs; i++) {
1390 u64 pchbusy, pchg, piov, pnew;
1403 pnew |= piov & pchbusy;
1407 spin_unlock_irqrestore(&ipath_pioavail_lock, flags);
1416 static void ipath_reset_availshadow(
struct ipath_devdata *dd)
1419 unsigned long flags;
1436 0xaaaaaaaaaaaaaaaaULL);
1438 ipath_dbg(
"shadow[%d] was %Lx, now %lx\n",
1439 i, (
unsigned long long) oldval,
1442 spin_unlock_irqrestore(&ipath_pioavail_lock, flags);
1459 "Error: can't set protocol header "
1460 "size %u, already %u\n",
1467 (
sizeof(
u64) /
sizeof(
u32)))) {
1468 ipath_dbg(
"Error: can't set protocol header size %u "
1469 "(> max %u)\n", rhdrsize,
1476 ipath_write_kreg(dd, dd->
ipath_kregs->kr_rcvhdrsize,
1500 ipath_dbg(
"%u tries no piobufavail ts%lx; dmacopy: "
1501 "%llx %llx %llx %llx\n"
1502 "ipath shadow: %lx %lx %lx %lx\n",
1509 shadow[0], shadow[1], shadow[2], shadow[3]);
1515 (
sizeof(shadow[0]) * 4 * 4))
1517 "%llx %llx %llx %llx\n"
1518 "ipath shadow: %lx %lx %lx %lx\n",
1523 shadow[4], shadow[5], shadow[6], shadow[7]);
1526 ipath_reset_availshadow(dd);
1540 int i,
j, updated = 0;
1542 unsigned long flags;
1546 piobcnt = last -
first;
1553 ipath_update_pio_bufs(dd);
1565 for (j = 0; j < piobcnt; j++, i++) {
1574 spin_unlock_irqrestore(&ipath_pioavail_lock, flags);
1582 ipath_update_pio_bufs(dd);
1586 }
else if (updated == 1 && piobcnt <=
1597 ipath_update_pio_bufs(dd);
1606 if (i < dd->ipath_piobcnt2k)
1640 buf = ipath_getpiobuf_range(dd, &pnum, first, nbufs, lasti);
1656 pnum, (pnum < dd->ipath_piobcnt2k) ? 2 : 4, buf);
1672 unsigned len,
int avail)
1674 unsigned long flags;
1675 unsigned end, cnt = 0;
1679 end = start + len * 2;
1683 while (start < end) {
1717 __set_bit(start + INFINIPATH_SENDPIOAVAIL_BUSY_SHIFT,
1728 spin_unlock_irqrestore(&ipath_pioavail_lock, flags);
1741 if (!avail && len < cnt)
1743 if (cnt < dd->ipath_pioupd_thresh) {
1745 ipath_dbg(
"Decreased pio update threshold to %u\n",
1752 ipath_write_kreg(dd, dd->
ipath_kregs->kr_sendctrl,
1784 "for port %u rcvhdrq failed\n",
1796 "for port %u rcvhdrqtailaddr "
1808 (
unsigned long long) phys_hdrqtail);
1814 "for port %u rcvhdr Q\n",
1822 "hdrtailaddr@%p %llx physical\n",
1858 unsigned long flags;
1883 ipath_dbg(
"Cancelling all in-progress send buffers\n");
1899 ipath_write_kreg(dd, dd->
ipath_kregs->kr_sendctrl,
1901 ipath_read_kreg64(dd, dd->
ipath_kregs->kr_scratch);
1911 if (restore_sendctrl) {
1916 ipath_write_kreg(dd, dd->
ipath_kregs->kr_sendctrl,
1919 ipath_read_kreg64(dd, dd->
ipath_kregs->kr_scratch);
1947 unsigned long flags;
1951 ipath_write_kreg(dd, dd->
ipath_kregs->kr_sendctrl,
1953 ipath_read_kreg64(dd, dd->
ipath_kregs->kr_scratch);
1954 ipath_write_kreg(dd, dd->
ipath_kregs->kr_sendctrl,
1956 ipath_read_kreg64(dd, dd->
ipath_kregs->kr_scratch);
1961 static void ipath_set_ib_lstate(
struct ipath_devdata *dd,
int linkcmd,
1965 static const char *
what[4] = {
1980 }
else if (linitcmd) {
1994 "Moving unit %u to %s (initcmd=0x%x), current ltstate is %s\n",
1997 ipath_read_kreg64(dd, dd->
ipath_kregs->kr_ibcstatus))]);
2085 "Disabling IB local loopback (normal)\n");
2112 ipath_dbg(
"Invalid linkstate 0x%x requested\n", newstate);
2146 if (arg != 256 && arg != 512 && arg != 1024 && arg != 2048 &&
2148 ipath_dbg(
"Trying to set invalid mtu %u, failing\n", arg);
2163 if (arg > piosize && arg <= dd->ipath_init_ibmaxlen)
2207 (~((1U << lmc) - 1)) << 16);
2233 where = regno +
port;
2237 ipath_write_kreg(dd, where, value);
2247 #define LED_OVER_FREQ_SHIFT 8
2248 #define LED_OVER_FREQ_MASK (0xFF<<LED_OVER_FREQ_SHIFT)
2250 #define LED_OVER_BOTH_OFF (8)
2252 static void ipath_run_led_override(
unsigned long opaque)
2257 u64 lstate, ltstate,
val;
2271 val = ipath_read_kreg64(dd, dd->
ipath_kregs->kr_ibcstatus);
2272 ltstate = ipath_ib_linktrstate(dd, val);
2273 lstate = ipath_ib_linkstate(dd, val);
2294 timeoff = (
HZ << 4)/freq;
2310 ipath_run_led_override;
2329 unsigned long flags;
2331 ipath_dbg(
"Shutting down the device\n");
2343 ipath_write_kreg(dd, dd->
ipath_kregs->kr_intmask, 0ULL);
2360 ipath_read_kreg64(dd, dd->
ipath_kregs->kr_scratch);
2413 ipath_write_kreg(dd, dd->
ipath_kregs->kr_hwerrclear,
2461 "chunk %u/%u\n", base,
2462 (
unsigned long) size,
2478 "ipath_port0_skbinfo @ %p\n", pd->
port_port,
2481 if (skbinfo[e].
skb) {
2482 pci_unmap_single(dd->
pcidev, skbinfo[e].
phys,
2485 dev_kfree_skb(skbinfo[e].skb);
2496 static int __init infinipath_init(
void)
2514 ret = pci_register_driver(&ipath_driver);
2517 ": Unable to register driver: error %d\n", -ret);
2524 "ipathfs: error %d\n", -ret);
2540 static void __exit infinipath_cleanup(
void)
2563 unsigned long flags;
2580 dev_info(&dd->
pcidev->dev,
"Reset on unit %u requested\n", unit);
2584 "not initialized or not present\n", unit);
2596 "(PID %u cmd %s), can't reset\n",
2609 ipath_write_kreg(dd, dd->
ipath_kregs->kr_intmask, 0ULL);
2612 ipath_dbg(
"Reinitializing unit %u after reset attempt\n",
2619 "reset failed with %d\n", unit, ret);
2622 "resetting\n", unit);
2635 int i, sub, any = 0;
2637 unsigned long flags;
2651 "(PID %u), sending signal %d\n",
2652 i, pid_nr(pid), sig);
2656 pid = dd->
ipath_pd[
i]->port_subpid[sub];
2660 "%d:%d in use (PID %u), sending "
2661 "signal %d\n", i, sub, pid_nr(pid), sig);
2672 if (ipath_signal_procs(dd,
SIGSTOP))
2680 if (ipath_signal_procs(dd,
SIGCONT))
2681 ipath_dbg(
"Continued some processes\n");
2694 ipath_hol_signal_down(dd);
2708 ipath_hol_signal_up(dd);
2726 ipath_hol_signal_down(dd);
2730 ipath_hol_signal_up(dd);
2733 ipath_dbg(
"link's up, don't resched timer\n");
2750 val = ipath_read_kreg64(dd, dd->
ipath_kregs->kr_xgxsconfig);
2755 ipath_write_kreg(dd, dd->
ipath_kregs->kr_xgxsconfig, val);
2772 ipath_write_kreg(dd, dd->
ipath_kregs->kr_errorclear,
2775 ipath_write_kreg(dd, dd->
ipath_kregs->kr_errormask,
2784 ipath_write_kreg(dd, dd->
ipath_kregs->kr_errormask,