ipath_pe800.c 43 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247
  1. /*
  2. * Copyright (c) 2003, 2004, 2005, 2006 PathScale, Inc. All rights reserved.
  3. *
  4. * This software is available to you under a choice of one of two
  5. * licenses. You may choose to be licensed under the terms of the GNU
  6. * General Public License (GPL) Version 2, available from the file
  7. * COPYING in the main directory of this source tree, or the
  8. * OpenIB.org BSD license below:
  9. *
  10. * Redistribution and use in source and binary forms, with or
  11. * without modification, are permitted provided that the following
  12. * conditions are met:
  13. *
  14. * - Redistributions of source code must retain the above
  15. * copyright notice, this list of conditions and the following
  16. * disclaimer.
  17. *
  18. * - Redistributions in binary form must reproduce the above
  19. * copyright notice, this list of conditions and the following
  20. * disclaimer in the documentation and/or other materials
  21. * provided with the distribution.
  22. *
  23. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  24. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  25. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  26. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  27. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  28. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  29. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  30. * SOFTWARE.
  31. */
  32. /*
  33. * This file contains all of the code that is specific to the
  34. * InfiniPath PE-800 chip.
  35. */
  36. #include <linux/interrupt.h>
  37. #include <linux/pci.h>
  38. #include <linux/delay.h>
  39. #include "ipath_kernel.h"
  40. #include "ipath_registers.h"
  41. /*
  42. * This file contains all the chip-specific register information and
  43. * access functions for the PathScale PE800, the PCI-Express chip.
  44. *
  45. * This lists the InfiniPath PE800 registers, in the actual chip layout.
  46. * This structure should never be directly accessed.
  47. */
  48. struct _infinipath_do_not_use_kernel_regs {
  49. unsigned long long Revision;
  50. unsigned long long Control;
  51. unsigned long long PageAlign;
  52. unsigned long long PortCnt;
  53. unsigned long long DebugPortSelect;
  54. unsigned long long Reserved0;
  55. unsigned long long SendRegBase;
  56. unsigned long long UserRegBase;
  57. unsigned long long CounterRegBase;
  58. unsigned long long Scratch;
  59. unsigned long long Reserved1;
  60. unsigned long long Reserved2;
  61. unsigned long long IntBlocked;
  62. unsigned long long IntMask;
  63. unsigned long long IntStatus;
  64. unsigned long long IntClear;
  65. unsigned long long ErrorMask;
  66. unsigned long long ErrorStatus;
  67. unsigned long long ErrorClear;
  68. unsigned long long HwErrMask;
  69. unsigned long long HwErrStatus;
  70. unsigned long long HwErrClear;
  71. unsigned long long HwDiagCtrl;
  72. unsigned long long MDIO;
  73. unsigned long long IBCStatus;
  74. unsigned long long IBCCtrl;
  75. unsigned long long ExtStatus;
  76. unsigned long long ExtCtrl;
  77. unsigned long long GPIOOut;
  78. unsigned long long GPIOMask;
  79. unsigned long long GPIOStatus;
  80. unsigned long long GPIOClear;
  81. unsigned long long RcvCtrl;
  82. unsigned long long RcvBTHQP;
  83. unsigned long long RcvHdrSize;
  84. unsigned long long RcvHdrCnt;
  85. unsigned long long RcvHdrEntSize;
  86. unsigned long long RcvTIDBase;
  87. unsigned long long RcvTIDCnt;
  88. unsigned long long RcvEgrBase;
  89. unsigned long long RcvEgrCnt;
  90. unsigned long long RcvBufBase;
  91. unsigned long long RcvBufSize;
  92. unsigned long long RxIntMemBase;
  93. unsigned long long RxIntMemSize;
  94. unsigned long long RcvPartitionKey;
  95. unsigned long long Reserved3;
  96. unsigned long long RcvPktLEDCnt;
  97. unsigned long long Reserved4[8];
  98. unsigned long long SendCtrl;
  99. unsigned long long SendPIOBufBase;
  100. unsigned long long SendPIOSize;
  101. unsigned long long SendPIOBufCnt;
  102. unsigned long long SendPIOAvailAddr;
  103. unsigned long long TxIntMemBase;
  104. unsigned long long TxIntMemSize;
  105. unsigned long long Reserved5;
  106. unsigned long long PCIeRBufTestReg0;
  107. unsigned long long PCIeRBufTestReg1;
  108. unsigned long long Reserved51[6];
  109. unsigned long long SendBufferError;
  110. unsigned long long SendBufferErrorCONT1;
  111. unsigned long long Reserved6SBE[6];
  112. unsigned long long RcvHdrAddr0;
  113. unsigned long long RcvHdrAddr1;
  114. unsigned long long RcvHdrAddr2;
  115. unsigned long long RcvHdrAddr3;
  116. unsigned long long RcvHdrAddr4;
  117. unsigned long long Reserved7RHA[11];
  118. unsigned long long RcvHdrTailAddr0;
  119. unsigned long long RcvHdrTailAddr1;
  120. unsigned long long RcvHdrTailAddr2;
  121. unsigned long long RcvHdrTailAddr3;
  122. unsigned long long RcvHdrTailAddr4;
  123. unsigned long long Reserved8RHTA[11];
  124. unsigned long long Reserved9SW[8];
  125. unsigned long long SerdesConfig0;
  126. unsigned long long SerdesConfig1;
  127. unsigned long long SerdesStatus;
  128. unsigned long long XGXSConfig;
  129. unsigned long long IBPLLCfg;
  130. unsigned long long Reserved10SW2[3];
  131. unsigned long long PCIEQ0SerdesConfig0;
  132. unsigned long long PCIEQ0SerdesConfig1;
  133. unsigned long long PCIEQ0SerdesStatus;
  134. unsigned long long Reserved11;
  135. unsigned long long PCIEQ1SerdesConfig0;
  136. unsigned long long PCIEQ1SerdesConfig1;
  137. unsigned long long PCIEQ1SerdesStatus;
  138. unsigned long long Reserved12;
  139. };
  140. #define IPATH_KREG_OFFSET(field) (offsetof(struct \
  141. _infinipath_do_not_use_kernel_regs, field) / sizeof(u64))
  142. #define IPATH_CREG_OFFSET(field) (offsetof( \
  143. struct infinipath_counters, field) / sizeof(u64))
  144. static const struct ipath_kregs ipath_pe_kregs = {
  145. .kr_control = IPATH_KREG_OFFSET(Control),
  146. .kr_counterregbase = IPATH_KREG_OFFSET(CounterRegBase),
  147. .kr_debugportselect = IPATH_KREG_OFFSET(DebugPortSelect),
  148. .kr_errorclear = IPATH_KREG_OFFSET(ErrorClear),
  149. .kr_errormask = IPATH_KREG_OFFSET(ErrorMask),
  150. .kr_errorstatus = IPATH_KREG_OFFSET(ErrorStatus),
  151. .kr_extctrl = IPATH_KREG_OFFSET(ExtCtrl),
  152. .kr_extstatus = IPATH_KREG_OFFSET(ExtStatus),
  153. .kr_gpio_clear = IPATH_KREG_OFFSET(GPIOClear),
  154. .kr_gpio_mask = IPATH_KREG_OFFSET(GPIOMask),
  155. .kr_gpio_out = IPATH_KREG_OFFSET(GPIOOut),
  156. .kr_gpio_status = IPATH_KREG_OFFSET(GPIOStatus),
  157. .kr_hwdiagctrl = IPATH_KREG_OFFSET(HwDiagCtrl),
  158. .kr_hwerrclear = IPATH_KREG_OFFSET(HwErrClear),
  159. .kr_hwerrmask = IPATH_KREG_OFFSET(HwErrMask),
  160. .kr_hwerrstatus = IPATH_KREG_OFFSET(HwErrStatus),
  161. .kr_ibcctrl = IPATH_KREG_OFFSET(IBCCtrl),
  162. .kr_ibcstatus = IPATH_KREG_OFFSET(IBCStatus),
  163. .kr_intblocked = IPATH_KREG_OFFSET(IntBlocked),
  164. .kr_intclear = IPATH_KREG_OFFSET(IntClear),
  165. .kr_intmask = IPATH_KREG_OFFSET(IntMask),
  166. .kr_intstatus = IPATH_KREG_OFFSET(IntStatus),
  167. .kr_mdio = IPATH_KREG_OFFSET(MDIO),
  168. .kr_pagealign = IPATH_KREG_OFFSET(PageAlign),
  169. .kr_partitionkey = IPATH_KREG_OFFSET(RcvPartitionKey),
  170. .kr_portcnt = IPATH_KREG_OFFSET(PortCnt),
  171. .kr_rcvbthqp = IPATH_KREG_OFFSET(RcvBTHQP),
  172. .kr_rcvbufbase = IPATH_KREG_OFFSET(RcvBufBase),
  173. .kr_rcvbufsize = IPATH_KREG_OFFSET(RcvBufSize),
  174. .kr_rcvctrl = IPATH_KREG_OFFSET(RcvCtrl),
  175. .kr_rcvegrbase = IPATH_KREG_OFFSET(RcvEgrBase),
  176. .kr_rcvegrcnt = IPATH_KREG_OFFSET(RcvEgrCnt),
  177. .kr_rcvhdrcnt = IPATH_KREG_OFFSET(RcvHdrCnt),
  178. .kr_rcvhdrentsize = IPATH_KREG_OFFSET(RcvHdrEntSize),
  179. .kr_rcvhdrsize = IPATH_KREG_OFFSET(RcvHdrSize),
  180. .kr_rcvintmembase = IPATH_KREG_OFFSET(RxIntMemBase),
  181. .kr_rcvintmemsize = IPATH_KREG_OFFSET(RxIntMemSize),
  182. .kr_rcvtidbase = IPATH_KREG_OFFSET(RcvTIDBase),
  183. .kr_rcvtidcnt = IPATH_KREG_OFFSET(RcvTIDCnt),
  184. .kr_revision = IPATH_KREG_OFFSET(Revision),
  185. .kr_scratch = IPATH_KREG_OFFSET(Scratch),
  186. .kr_sendbuffererror = IPATH_KREG_OFFSET(SendBufferError),
  187. .kr_sendctrl = IPATH_KREG_OFFSET(SendCtrl),
  188. .kr_sendpioavailaddr = IPATH_KREG_OFFSET(SendPIOAvailAddr),
  189. .kr_sendpiobufbase = IPATH_KREG_OFFSET(SendPIOBufBase),
  190. .kr_sendpiobufcnt = IPATH_KREG_OFFSET(SendPIOBufCnt),
  191. .kr_sendpiosize = IPATH_KREG_OFFSET(SendPIOSize),
  192. .kr_sendregbase = IPATH_KREG_OFFSET(SendRegBase),
  193. .kr_txintmembase = IPATH_KREG_OFFSET(TxIntMemBase),
  194. .kr_txintmemsize = IPATH_KREG_OFFSET(TxIntMemSize),
  195. .kr_userregbase = IPATH_KREG_OFFSET(UserRegBase),
  196. .kr_serdesconfig0 = IPATH_KREG_OFFSET(SerdesConfig0),
  197. .kr_serdesconfig1 = IPATH_KREG_OFFSET(SerdesConfig1),
  198. .kr_serdesstatus = IPATH_KREG_OFFSET(SerdesStatus),
  199. .kr_xgxsconfig = IPATH_KREG_OFFSET(XGXSConfig),
  200. .kr_ibpllcfg = IPATH_KREG_OFFSET(IBPLLCfg),
  201. /*
  202. * These should not be used directly via ipath_read_kreg64(),
  203. * use them with ipath_read_kreg64_port()
  204. */
  205. .kr_rcvhdraddr = IPATH_KREG_OFFSET(RcvHdrAddr0),
  206. .kr_rcvhdrtailaddr = IPATH_KREG_OFFSET(RcvHdrTailAddr0),
  207. /* This group is pe-800-specific; and used only in this file */
  208. /* The rcvpktled register controls one of the debug port signals, so
  209. * a packet activity LED can be connected to it. */
  210. .kr_rcvpktledcnt = IPATH_KREG_OFFSET(RcvPktLEDCnt),
  211. .kr_pcierbuftestreg0 = IPATH_KREG_OFFSET(PCIeRBufTestReg0),
  212. .kr_pcierbuftestreg1 = IPATH_KREG_OFFSET(PCIeRBufTestReg1),
  213. .kr_pcieq0serdesconfig0 = IPATH_KREG_OFFSET(PCIEQ0SerdesConfig0),
  214. .kr_pcieq0serdesconfig1 = IPATH_KREG_OFFSET(PCIEQ0SerdesConfig1),
  215. .kr_pcieq0serdesstatus = IPATH_KREG_OFFSET(PCIEQ0SerdesStatus),
  216. .kr_pcieq1serdesconfig0 = IPATH_KREG_OFFSET(PCIEQ1SerdesConfig0),
  217. .kr_pcieq1serdesconfig1 = IPATH_KREG_OFFSET(PCIEQ1SerdesConfig1),
  218. .kr_pcieq1serdesstatus = IPATH_KREG_OFFSET(PCIEQ1SerdesStatus)
  219. };
  220. static const struct ipath_cregs ipath_pe_cregs = {
  221. .cr_badformatcnt = IPATH_CREG_OFFSET(RxBadFormatCnt),
  222. .cr_erricrccnt = IPATH_CREG_OFFSET(RxICRCErrCnt),
  223. .cr_errlinkcnt = IPATH_CREG_OFFSET(RxLinkProblemCnt),
  224. .cr_errlpcrccnt = IPATH_CREG_OFFSET(RxLPCRCErrCnt),
  225. .cr_errpkey = IPATH_CREG_OFFSET(RxPKeyMismatchCnt),
  226. .cr_errrcvflowctrlcnt = IPATH_CREG_OFFSET(RxFlowCtrlErrCnt),
  227. .cr_err_rlencnt = IPATH_CREG_OFFSET(RxLenErrCnt),
  228. .cr_errslencnt = IPATH_CREG_OFFSET(TxLenErrCnt),
  229. .cr_errtidfull = IPATH_CREG_OFFSET(RxTIDFullErrCnt),
  230. .cr_errtidvalid = IPATH_CREG_OFFSET(RxTIDValidErrCnt),
  231. .cr_errvcrccnt = IPATH_CREG_OFFSET(RxVCRCErrCnt),
  232. .cr_ibstatuschange = IPATH_CREG_OFFSET(IBStatusChangeCnt),
  233. .cr_intcnt = IPATH_CREG_OFFSET(LBIntCnt),
  234. .cr_invalidrlencnt = IPATH_CREG_OFFSET(RxMaxMinLenErrCnt),
  235. .cr_invalidslencnt = IPATH_CREG_OFFSET(TxMaxMinLenErrCnt),
  236. .cr_lbflowstallcnt = IPATH_CREG_OFFSET(LBFlowStallCnt),
  237. .cr_pktrcvcnt = IPATH_CREG_OFFSET(RxDataPktCnt),
  238. .cr_pktrcvflowctrlcnt = IPATH_CREG_OFFSET(RxFlowPktCnt),
  239. .cr_pktsendcnt = IPATH_CREG_OFFSET(TxDataPktCnt),
  240. .cr_pktsendflowcnt = IPATH_CREG_OFFSET(TxFlowPktCnt),
  241. .cr_portovflcnt = IPATH_CREG_OFFSET(RxP0HdrEgrOvflCnt),
  242. .cr_rcvebpcnt = IPATH_CREG_OFFSET(RxEBPCnt),
  243. .cr_rcvovflcnt = IPATH_CREG_OFFSET(RxBufOvflCnt),
  244. .cr_senddropped = IPATH_CREG_OFFSET(TxDroppedPktCnt),
  245. .cr_sendstallcnt = IPATH_CREG_OFFSET(TxFlowStallCnt),
  246. .cr_sendunderruncnt = IPATH_CREG_OFFSET(TxUnderrunCnt),
  247. .cr_wordrcvcnt = IPATH_CREG_OFFSET(RxDwordCnt),
  248. .cr_wordsendcnt = IPATH_CREG_OFFSET(TxDwordCnt),
  249. .cr_unsupvlcnt = IPATH_CREG_OFFSET(TxUnsupVLErrCnt),
  250. .cr_rxdroppktcnt = IPATH_CREG_OFFSET(RxDroppedPktCnt),
  251. .cr_iblinkerrrecovcnt = IPATH_CREG_OFFSET(IBLinkErrRecoveryCnt),
  252. .cr_iblinkdowncnt = IPATH_CREG_OFFSET(IBLinkDownedCnt),
  253. .cr_ibsymbolerrcnt = IPATH_CREG_OFFSET(IBSymbolErrCnt)
  254. };
  255. /* kr_intstatus, kr_intclear, kr_intmask bits */
  256. #define INFINIPATH_I_RCVURG_MASK 0x1F
  257. #define INFINIPATH_I_RCVAVAIL_MASK 0x1F
  258. /* kr_hwerrclear, kr_hwerrmask, kr_hwerrstatus, bits */
  259. #define INFINIPATH_HWE_PCIEMEMPARITYERR_MASK 0x000000000000003fULL
  260. #define INFINIPATH_HWE_PCIEMEMPARITYERR_SHIFT 0
  261. #define INFINIPATH_HWE_PCIEPOISONEDTLP 0x0000000010000000ULL
  262. #define INFINIPATH_HWE_PCIECPLTIMEOUT 0x0000000020000000ULL
  263. #define INFINIPATH_HWE_PCIEBUSPARITYXTLH 0x0000000040000000ULL
  264. #define INFINIPATH_HWE_PCIEBUSPARITYXADM 0x0000000080000000ULL
  265. #define INFINIPATH_HWE_PCIEBUSPARITYRADM 0x0000000100000000ULL
  266. #define INFINIPATH_HWE_COREPLL_FBSLIP 0x0080000000000000ULL
  267. #define INFINIPATH_HWE_COREPLL_RFSLIP 0x0100000000000000ULL
  268. #define INFINIPATH_HWE_PCIE1PLLFAILED 0x0400000000000000ULL
  269. #define INFINIPATH_HWE_PCIE0PLLFAILED 0x0800000000000000ULL
  270. #define INFINIPATH_HWE_SERDESPLLFAILED 0x1000000000000000ULL
  271. /* kr_extstatus bits */
  272. #define INFINIPATH_EXTS_FREQSEL 0x2
  273. #define INFINIPATH_EXTS_SERDESSEL 0x4
  274. #define INFINIPATH_EXTS_MEMBIST_ENDTEST 0x0000000000004000
  275. #define INFINIPATH_EXTS_MEMBIST_FOUND 0x0000000000008000
  276. #define _IPATH_GPIO_SDA_NUM 1
  277. #define _IPATH_GPIO_SCL_NUM 0
  278. #define IPATH_GPIO_SDA (1ULL << \
  279. (_IPATH_GPIO_SDA_NUM+INFINIPATH_EXTC_GPIOOE_SHIFT))
  280. #define IPATH_GPIO_SCL (1ULL << \
  281. (_IPATH_GPIO_SCL_NUM+INFINIPATH_EXTC_GPIOOE_SHIFT))
  282. /**
  283. * ipath_pe_handle_hwerrors - display hardware errors.
  284. * @dd: the infinipath device
  285. * @msg: the output buffer
  286. * @msgl: the size of the output buffer
  287. *
  288. * Use same msg buffer as regular errors to avoid excessive stack
  289. * use. Most hardware errors are catastrophic, but for right now,
  290. * we'll print them and continue. We reuse the same message buffer as
  291. * ipath_handle_errors() to avoid excessive stack usage.
  292. */
  293. static void ipath_pe_handle_hwerrors(struct ipath_devdata *dd, char *msg,
  294. size_t msgl)
  295. {
  296. ipath_err_t hwerrs;
  297. u32 bits, ctrl;
  298. int isfatal = 0;
  299. char bitsmsg[64];
  300. hwerrs = ipath_read_kreg64(dd, dd->ipath_kregs->kr_hwerrstatus);
  301. if (!hwerrs) {
  302. /*
  303. * better than printing cofusing messages
  304. * This seems to be related to clearing the crc error, or
  305. * the pll error during init.
  306. */
  307. ipath_cdbg(VERBOSE, "Called but no hardware errors set\n");
  308. return;
  309. } else if (hwerrs == ~0ULL) {
  310. ipath_dev_err(dd, "Read of hardware error status failed "
  311. "(all bits set); ignoring\n");
  312. return;
  313. }
  314. ipath_stats.sps_hwerrs++;
  315. /* Always clear the error status register, except MEMBISTFAIL,
  316. * regardless of whether we continue or stop using the chip.
  317. * We want that set so we know it failed, even across driver reload.
  318. * We'll still ignore it in the hwerrmask. We do this partly for
  319. * diagnostics, but also for support */
  320. ipath_write_kreg(dd, dd->ipath_kregs->kr_hwerrclear,
  321. hwerrs&~INFINIPATH_HWE_MEMBISTFAILED);
  322. hwerrs &= dd->ipath_hwerrmask;
  323. /*
  324. * make sure we get this much out, unless told to be quiet,
  325. * or it's occurred within the last 5 seconds
  326. */
  327. if ((hwerrs & ~dd->ipath_lasthwerror) ||
  328. (ipath_debug & __IPATH_VERBDBG))
  329. dev_info(&dd->pcidev->dev, "Hardware error: hwerr=0x%llx "
  330. "(cleared)\n", (unsigned long long) hwerrs);
  331. dd->ipath_lasthwerror |= hwerrs;
  332. if (hwerrs & ~infinipath_hwe_bitsextant)
  333. ipath_dev_err(dd, "hwerror interrupt with unknown errors "
  334. "%llx set\n", (unsigned long long)
  335. (hwerrs & ~infinipath_hwe_bitsextant));
  336. ctrl = ipath_read_kreg32(dd, dd->ipath_kregs->kr_control);
  337. if (ctrl & INFINIPATH_C_FREEZEMODE) {
  338. if (hwerrs) {
  339. /*
  340. * if any set that we aren't ignoring only make the
  341. * complaint once, in case it's stuck or recurring,
  342. * and we get here multiple times
  343. */
  344. if (dd->ipath_flags & IPATH_INITTED) {
  345. ipath_dev_err(dd, "Fatal Error (freeze "
  346. "mode), no longer usable\n");
  347. isfatal = 1;
  348. }
  349. /*
  350. * Mark as having had an error for driver, and also
  351. * for /sys and status word mapped to user programs.
  352. * This marks unit as not usable, until reset
  353. */
  354. *dd->ipath_statusp &= ~IPATH_STATUS_IB_READY;
  355. *dd->ipath_statusp |= IPATH_STATUS_HWERROR;
  356. dd->ipath_flags &= ~IPATH_INITTED;
  357. } else {
  358. ipath_dbg("Clearing freezemode on ignored hardware "
  359. "error\n");
  360. ctrl &= ~INFINIPATH_C_FREEZEMODE;
  361. ipath_write_kreg(dd, dd->ipath_kregs->kr_control,
  362. ctrl);
  363. }
  364. }
  365. *msg = '\0';
  366. if (hwerrs & INFINIPATH_HWE_MEMBISTFAILED) {
  367. strlcat(msg, "[Memory BIST test failed, PE-800 unusable]",
  368. msgl);
  369. /* ignore from now on, so disable until driver reloaded */
  370. *dd->ipath_statusp |= IPATH_STATUS_HWERROR;
  371. dd->ipath_hwerrmask &= ~INFINIPATH_HWE_MEMBISTFAILED;
  372. ipath_write_kreg(dd, dd->ipath_kregs->kr_hwerrmask,
  373. dd->ipath_hwerrmask);
  374. }
  375. if (hwerrs & (INFINIPATH_HWE_RXEMEMPARITYERR_MASK
  376. << INFINIPATH_HWE_RXEMEMPARITYERR_SHIFT)) {
  377. bits = (u32) ((hwerrs >>
  378. INFINIPATH_HWE_RXEMEMPARITYERR_SHIFT) &
  379. INFINIPATH_HWE_RXEMEMPARITYERR_MASK);
  380. snprintf(bitsmsg, sizeof bitsmsg, "[RXE Parity Errs %x] ",
  381. bits);
  382. strlcat(msg, bitsmsg, msgl);
  383. }
  384. if (hwerrs & (INFINIPATH_HWE_TXEMEMPARITYERR_MASK
  385. << INFINIPATH_HWE_TXEMEMPARITYERR_SHIFT)) {
  386. bits = (u32) ((hwerrs >>
  387. INFINIPATH_HWE_TXEMEMPARITYERR_SHIFT) &
  388. INFINIPATH_HWE_TXEMEMPARITYERR_MASK);
  389. snprintf(bitsmsg, sizeof bitsmsg, "[TXE Parity Errs %x] ",
  390. bits);
  391. strlcat(msg, bitsmsg, msgl);
  392. }
  393. if (hwerrs & (INFINIPATH_HWE_PCIEMEMPARITYERR_MASK
  394. << INFINIPATH_HWE_PCIEMEMPARITYERR_SHIFT)) {
  395. bits = (u32) ((hwerrs >>
  396. INFINIPATH_HWE_PCIEMEMPARITYERR_SHIFT) &
  397. INFINIPATH_HWE_PCIEMEMPARITYERR_MASK);
  398. snprintf(bitsmsg, sizeof bitsmsg,
  399. "[PCIe Mem Parity Errs %x] ", bits);
  400. strlcat(msg, bitsmsg, msgl);
  401. }
  402. if (hwerrs & INFINIPATH_HWE_IBCBUSTOSPCPARITYERR)
  403. strlcat(msg, "[IB2IPATH Parity]", msgl);
  404. if (hwerrs & INFINIPATH_HWE_IBCBUSFRSPCPARITYERR)
  405. strlcat(msg, "[IPATH2IB Parity]", msgl);
  406. #define _IPATH_PLL_FAIL (INFINIPATH_HWE_COREPLL_FBSLIP | \
  407. INFINIPATH_HWE_COREPLL_RFSLIP )
  408. if (hwerrs & _IPATH_PLL_FAIL) {
  409. snprintf(bitsmsg, sizeof bitsmsg,
  410. "[PLL failed (%llx), PE-800 unusable]",
  411. (unsigned long long) hwerrs & _IPATH_PLL_FAIL);
  412. strlcat(msg, bitsmsg, msgl);
  413. /* ignore from now on, so disable until driver reloaded */
  414. dd->ipath_hwerrmask &= ~(hwerrs & _IPATH_PLL_FAIL);
  415. ipath_write_kreg(dd, dd->ipath_kregs->kr_hwerrmask,
  416. dd->ipath_hwerrmask);
  417. }
  418. if (hwerrs & INFINIPATH_HWE_SERDESPLLFAILED) {
  419. /*
  420. * If it occurs, it is left masked since the eternal
  421. * interface is unused
  422. */
  423. dd->ipath_hwerrmask &= ~INFINIPATH_HWE_SERDESPLLFAILED;
  424. ipath_write_kreg(dd, dd->ipath_kregs->kr_hwerrmask,
  425. dd->ipath_hwerrmask);
  426. }
  427. if (hwerrs & INFINIPATH_HWE_PCIEPOISONEDTLP)
  428. strlcat(msg, "[PCIe Poisoned TLP]", msgl);
  429. if (hwerrs & INFINIPATH_HWE_PCIECPLTIMEOUT)
  430. strlcat(msg, "[PCIe completion timeout]", msgl);
  431. /*
  432. * In practice, it's unlikely wthat we'll see PCIe PLL, or bus
  433. * parity or memory parity error failures, because most likely we
  434. * won't be able to talk to the core of the chip. Nonetheless, we
  435. * might see them, if they are in parts of the PCIe core that aren't
  436. * essential.
  437. */
  438. if (hwerrs & INFINIPATH_HWE_PCIE1PLLFAILED)
  439. strlcat(msg, "[PCIePLL1]", msgl);
  440. if (hwerrs & INFINIPATH_HWE_PCIE0PLLFAILED)
  441. strlcat(msg, "[PCIePLL0]", msgl);
  442. if (hwerrs & INFINIPATH_HWE_PCIEBUSPARITYXTLH)
  443. strlcat(msg, "[PCIe XTLH core parity]", msgl);
  444. if (hwerrs & INFINIPATH_HWE_PCIEBUSPARITYXADM)
  445. strlcat(msg, "[PCIe ADM TX core parity]", msgl);
  446. if (hwerrs & INFINIPATH_HWE_PCIEBUSPARITYRADM)
  447. strlcat(msg, "[PCIe ADM RX core parity]", msgl);
  448. if (hwerrs & INFINIPATH_HWE_RXDSYNCMEMPARITYERR)
  449. strlcat(msg, "[Rx Dsync]", msgl);
  450. if (hwerrs & INFINIPATH_HWE_SERDESPLLFAILED)
  451. strlcat(msg, "[SerDes PLL]", msgl);
  452. ipath_dev_err(dd, "%s hardware error\n", msg);
  453. if (isfatal && !ipath_diag_inuse && dd->ipath_freezemsg) {
  454. /*
  455. * for /sys status file ; if no trailing } is copied, we'll
  456. * know it was truncated.
  457. */
  458. snprintf(dd->ipath_freezemsg, dd->ipath_freezelen,
  459. "{%s}", msg);
  460. }
  461. }
  462. /**
  463. * ipath_pe_boardname - fill in the board name
  464. * @dd: the infinipath device
  465. * @name: the output buffer
  466. * @namelen: the size of the output buffer
  467. *
  468. * info is based on the board revision register
  469. */
  470. static int ipath_pe_boardname(struct ipath_devdata *dd, char *name,
  471. size_t namelen)
  472. {
  473. char *n = NULL;
  474. u8 boardrev = dd->ipath_boardrev;
  475. int ret;
  476. switch (boardrev) {
  477. case 0:
  478. n = "InfiniPath_Emulation";
  479. break;
  480. case 1:
  481. n = "InfiniPath_PE-800-Bringup";
  482. break;
  483. case 2:
  484. n = "InfiniPath_PE-880";
  485. break;
  486. case 3:
  487. n = "InfiniPath_PE-850";
  488. break;
  489. case 4:
  490. n = "InfiniPath_PE-860";
  491. break;
  492. default:
  493. ipath_dev_err(dd,
  494. "Don't yet know about board with ID %u\n",
  495. boardrev);
  496. snprintf(name, namelen, "Unknown_InfiniPath_PE-8xx_%u",
  497. boardrev);
  498. break;
  499. }
  500. if (n)
  501. snprintf(name, namelen, "%s", n);
  502. if (dd->ipath_majrev != 4 || dd->ipath_minrev != 1) {
  503. ipath_dev_err(dd, "Unsupported PE-800 revision %u.%u!\n",
  504. dd->ipath_majrev, dd->ipath_minrev);
  505. ret = 1;
  506. } else
  507. ret = 0;
  508. return ret;
  509. }
  510. /**
  511. * ipath_pe_init_hwerrors - enable hardware errors
  512. * @dd: the infinipath device
  513. *
  514. * now that we have finished initializing everything that might reasonably
  515. * cause a hardware error, and cleared those errors bits as they occur,
  516. * we can enable hardware errors in the mask (potentially enabling
  517. * freeze mode), and enable hardware errors as errors (along with
  518. * everything else) in errormask
  519. */
  520. static void ipath_pe_init_hwerrors(struct ipath_devdata *dd)
  521. {
  522. ipath_err_t val;
  523. u64 extsval;
  524. extsval = ipath_read_kreg64(dd, dd->ipath_kregs->kr_extstatus);
  525. if (!(extsval & INFINIPATH_EXTS_MEMBIST_ENDTEST))
  526. ipath_dev_err(dd, "MemBIST did not complete!\n");
  527. val = ~0ULL; /* barring bugs, all hwerrors become interrupts, */
  528. if (!dd->ipath_boardrev) // no PLL for Emulator
  529. val &= ~INFINIPATH_HWE_SERDESPLLFAILED;
  530. /* workaround bug 9460 in internal interface bus parity checking */
  531. val &= ~INFINIPATH_HWE_PCIEBUSPARITYRADM;
  532. dd->ipath_hwerrmask = val;
  533. }
  534. /**
  535. * ipath_pe_bringup_serdes - bring up the serdes
  536. * @dd: the infinipath device
  537. */
  538. static int ipath_pe_bringup_serdes(struct ipath_devdata *dd)
  539. {
  540. u64 val, tmp, config1;
  541. int ret = 0, change = 0;
  542. ipath_dbg("Trying to bringup serdes\n");
  543. if (ipath_read_kreg64(dd, dd->ipath_kregs->kr_hwerrstatus) &
  544. INFINIPATH_HWE_SERDESPLLFAILED) {
  545. ipath_dbg("At start, serdes PLL failed bit set "
  546. "in hwerrstatus, clearing and continuing\n");
  547. ipath_write_kreg(dd, dd->ipath_kregs->kr_hwerrclear,
  548. INFINIPATH_HWE_SERDESPLLFAILED);
  549. }
  550. val = ipath_read_kreg64(dd, dd->ipath_kregs->kr_serdesconfig0);
  551. config1 = ipath_read_kreg64(dd, dd->ipath_kregs->kr_serdesconfig1);
  552. ipath_cdbg(VERBOSE, "SerDes status config0=%llx config1=%llx, "
  553. "xgxsconfig %llx\n", (unsigned long long) val,
  554. (unsigned long long) config1, (unsigned long long)
  555. ipath_read_kreg64(dd, dd->ipath_kregs->kr_xgxsconfig));
  556. /*
  557. * Force reset on, also set rxdetect enable. Must do before reading
  558. * serdesstatus at least for simulation, or some of the bits in
  559. * serdes status will come back as undefined and cause simulation
  560. * failures
  561. */
  562. val |= INFINIPATH_SERDC0_RESET_PLL | INFINIPATH_SERDC0_RXDETECT_EN
  563. | INFINIPATH_SERDC0_L1PWR_DN;
  564. ipath_write_kreg(dd, dd->ipath_kregs->kr_serdesconfig0, val);
  565. /* be sure chip saw it */
  566. tmp = ipath_read_kreg64(dd, dd->ipath_kregs->kr_scratch);
  567. udelay(5); /* need pll reset set at least for a bit */
  568. /*
  569. * after PLL is reset, set the per-lane Resets and TxIdle and
  570. * clear the PLL reset and rxdetect (to get falling edge).
  571. * Leave L1PWR bits set (permanently)
  572. */
  573. val &= ~(INFINIPATH_SERDC0_RXDETECT_EN | INFINIPATH_SERDC0_RESET_PLL
  574. | INFINIPATH_SERDC0_L1PWR_DN);
  575. val |= INFINIPATH_SERDC0_RESET_MASK | INFINIPATH_SERDC0_TXIDLE;
  576. ipath_cdbg(VERBOSE, "Clearing pll reset and setting lane resets "
  577. "and txidle (%llx)\n", (unsigned long long) val);
  578. ipath_write_kreg(dd, dd->ipath_kregs->kr_serdesconfig0, val);
  579. /* be sure chip saw it */
  580. tmp = ipath_read_kreg64(dd, dd->ipath_kregs->kr_scratch);
  581. /* need PLL reset clear for at least 11 usec before lane
  582. * resets cleared; give it a few more to be sure */
  583. udelay(15);
  584. val &= ~(INFINIPATH_SERDC0_RESET_MASK | INFINIPATH_SERDC0_TXIDLE);
  585. ipath_cdbg(VERBOSE, "Clearing lane resets and txidle "
  586. "(writing %llx)\n", (unsigned long long) val);
  587. ipath_write_kreg(dd, dd->ipath_kregs->kr_serdesconfig0, val);
  588. /* be sure chip saw it */
  589. val = ipath_read_kreg64(dd, dd->ipath_kregs->kr_scratch);
  590. val = ipath_read_kreg64(dd, dd->ipath_kregs->kr_xgxsconfig);
  591. if (((val >> INFINIPATH_XGXS_MDIOADDR_SHIFT) &
  592. INFINIPATH_XGXS_MDIOADDR_MASK) != 3) {
  593. val &=
  594. ~(INFINIPATH_XGXS_MDIOADDR_MASK <<
  595. INFINIPATH_XGXS_MDIOADDR_SHIFT);
  596. /* MDIO address 3 */
  597. val |= 3ULL << INFINIPATH_XGXS_MDIOADDR_SHIFT;
  598. change = 1;
  599. }
  600. if (val & INFINIPATH_XGXS_RESET) {
  601. val &= ~INFINIPATH_XGXS_RESET;
  602. change = 1;
  603. }
  604. if (change)
  605. ipath_write_kreg(dd, dd->ipath_kregs->kr_xgxsconfig, val);
  606. val = ipath_read_kreg64(dd, dd->ipath_kregs->kr_serdesconfig0);
  607. /* clear current and de-emphasis bits */
  608. config1 &= ~0x0ffffffff00ULL;
  609. /* set current to 20ma */
  610. config1 |= 0x00000000000ULL;
  611. /* set de-emphasis to -5.68dB */
  612. config1 |= 0x0cccc000000ULL;
  613. ipath_write_kreg(dd, dd->ipath_kregs->kr_serdesconfig1, config1);
  614. ipath_cdbg(VERBOSE, "done: SerDes status config0=%llx "
  615. "config1=%llx, sstatus=%llx xgxs=%llx\n",
  616. (unsigned long long) val, (unsigned long long) config1,
  617. (unsigned long long)
  618. ipath_read_kreg64(dd, dd->ipath_kregs->kr_serdesstatus),
  619. (unsigned long long)
  620. ipath_read_kreg64(dd, dd->ipath_kregs->kr_xgxsconfig));
  621. if (!ipath_waitfor_mdio_cmdready(dd)) {
  622. ipath_write_kreg(
  623. dd, dd->ipath_kregs->kr_mdio,
  624. ipath_mdio_req(IPATH_MDIO_CMD_READ, 31,
  625. IPATH_MDIO_CTRL_XGXS_REG_8, 0));
  626. if (ipath_waitfor_complete(dd, dd->ipath_kregs->kr_mdio,
  627. IPATH_MDIO_DATAVALID, &val))
  628. ipath_dbg("Never got MDIO data for XGXS "
  629. "status read\n");
  630. else
  631. ipath_cdbg(VERBOSE, "MDIO Read reg8, "
  632. "'bank' 31 %x\n", (u32) val);
  633. } else
  634. ipath_dbg("Never got MDIO cmdready for XGXS status read\n");
  635. return ret;
  636. }
  637. /**
  638. * ipath_pe_quiet_serdes - set serdes to txidle
  639. * @dd: the infinipath device
  640. * Called when driver is being unloaded
  641. */
  642. static void ipath_pe_quiet_serdes(struct ipath_devdata *dd)
  643. {
  644. u64 val = ipath_read_kreg64(dd, dd->ipath_kregs->kr_serdesconfig0);
  645. val |= INFINIPATH_SERDC0_TXIDLE;
  646. ipath_dbg("Setting TxIdleEn on serdes (config0 = %llx)\n",
  647. (unsigned long long) val);
  648. ipath_write_kreg(dd, dd->ipath_kregs->kr_serdesconfig0, val);
  649. }
  650. /* this is not yet needed on the PE800, so just return 0. */
  651. static int ipath_pe_intconfig(struct ipath_devdata *dd)
  652. {
  653. return 0;
  654. }
  655. /**
  656. * ipath_setup_pe_setextled - set the state of the two external LEDs
  657. * @dd: the infinipath device
  658. * @lst: the L state
  659. * @ltst: the LT state
  660. * These LEDs indicate the physical and logical state of IB link.
  661. * For this chip (at least with recommended board pinouts), LED1
  662. * is Yellow (logical state) and LED2 is Green (physical state),
  663. *
  664. * Note: We try to match the Mellanox HCA LED behavior as best
  665. * we can. Green indicates physical link state is OK (something is
  666. * plugged in, and we can train).
  667. * Amber indicates the link is logically up (ACTIVE).
  668. * Mellanox further blinks the amber LED to indicate data packet
  669. * activity, but we have no hardware support for that, so it would
  670. * require waking up every 10-20 msecs and checking the counters
  671. * on the chip, and then turning the LED off if appropriate. That's
  672. * visible overhead, so not something we will do.
  673. *
  674. */
  675. static void ipath_setup_pe_setextled(struct ipath_devdata *dd, u64 lst,
  676. u64 ltst)
  677. {
  678. u64 extctl;
  679. /* the diags use the LED to indicate diag info, so we leave
  680. * the external LED alone when the diags are running */
  681. if (ipath_diag_inuse)
  682. return;
  683. extctl = dd->ipath_extctrl & ~(INFINIPATH_EXTC_LED1PRIPORT_ON |
  684. INFINIPATH_EXTC_LED2PRIPORT_ON);
  685. if (ltst & INFINIPATH_IBCS_LT_STATE_LINKUP)
  686. extctl |= INFINIPATH_EXTC_LED2PRIPORT_ON;
  687. if (lst == INFINIPATH_IBCS_L_STATE_ACTIVE)
  688. extctl |= INFINIPATH_EXTC_LED1PRIPORT_ON;
  689. dd->ipath_extctrl = extctl;
  690. ipath_write_kreg(dd, dd->ipath_kregs->kr_extctrl, extctl);
  691. }
  692. /**
  693. * ipath_setup_pe_cleanup - clean up any per-chip chip-specific stuff
  694. * @dd: the infinipath device
  695. *
  696. * This is called during driver unload.
  697. * We do the pci_disable_msi here, not in generic code, because it
  698. * isn't used for the HT-400. If we do end up needing pci_enable_msi
  699. * at some point in the future for HT-400, we'll move the call back
  700. * into the main init_one code.
  701. */
  702. static void ipath_setup_pe_cleanup(struct ipath_devdata *dd)
  703. {
  704. dd->ipath_msi_lo = 0; /* just in case unload fails */
  705. pci_disable_msi(dd->pcidev);
  706. }
  707. /**
  708. * ipath_setup_pe_config - setup PCIe config related stuff
  709. * @dd: the infinipath device
  710. * @pdev: the PCI device
  711. *
  712. * The pci_enable_msi() call will fail on systems with MSI quirks
  713. * such as those with AMD8131, even if the device of interest is not
  714. * attached to that device, (in the 2.6.13 - 2.6.15 kernels, at least, fixed
  715. * late in 2.6.16).
  716. * All that can be done is to edit the kernel source to remove the quirk
  717. * check until that is fixed.
  718. * We do not need to call enable_msi() for our HyperTransport chip (HT-400),
  719. * even those it uses MSI, and we want to avoid the quirk warning, so
  720. * So we call enable_msi only for the PE-800. If we do end up needing
  721. * pci_enable_msi at some point in the future for HT-400, we'll move the
  722. * call back into the main init_one code.
  723. * We save the msi lo and hi values, so we can restore them after
  724. * chip reset (the kernel PCI infrastructure doesn't yet handle that
  725. * correctly).
  726. */
  727. static int ipath_setup_pe_config(struct ipath_devdata *dd,
  728. struct pci_dev *pdev)
  729. {
  730. int pos, ret;
  731. dd->ipath_msi_lo = 0; /* used as a flag during reset processing */
  732. ret = pci_enable_msi(dd->pcidev);
  733. if (ret)
  734. ipath_dev_err(dd, "pci_enable_msi failed: %d, "
  735. "interrupts may not work\n", ret);
  736. /* continue even if it fails, we may still be OK... */
  737. if ((pos = pci_find_capability(dd->pcidev, PCI_CAP_ID_MSI))) {
  738. u16 control;
  739. pci_read_config_dword(dd->pcidev, pos + PCI_MSI_ADDRESS_LO,
  740. &dd->ipath_msi_lo);
  741. pci_read_config_dword(dd->pcidev, pos + PCI_MSI_ADDRESS_HI,
  742. &dd->ipath_msi_hi);
  743. pci_read_config_word(dd->pcidev, pos + PCI_MSI_FLAGS,
  744. &control);
  745. /* now save the data (vector) info */
  746. pci_read_config_word(dd->pcidev,
  747. pos + ((control & PCI_MSI_FLAGS_64BIT)
  748. ? 12 : 8),
  749. &dd->ipath_msi_data);
  750. ipath_cdbg(VERBOSE, "Read msi data 0x%x from config offset "
  751. "0x%x, control=0x%x\n", dd->ipath_msi_data,
  752. pos + ((control & PCI_MSI_FLAGS_64BIT) ? 12 : 8),
  753. control);
  754. /* we save the cachelinesize also, although it doesn't
  755. * really matter */
  756. pci_read_config_byte(dd->pcidev, PCI_CACHE_LINE_SIZE,
  757. &dd->ipath_pci_cacheline);
  758. } else
  759. ipath_dev_err(dd, "Can't find MSI capability, "
  760. "can't save MSI settings for reset\n");
  761. if ((pos = pci_find_capability(dd->pcidev, PCI_CAP_ID_EXP))) {
  762. u16 linkstat;
  763. pci_read_config_word(dd->pcidev, pos + PCI_EXP_LNKSTA,
  764. &linkstat);
  765. linkstat >>= 4;
  766. linkstat &= 0x1f;
  767. if (linkstat != 8)
  768. ipath_dev_err(dd, "PCIe width %u, "
  769. "performance reduced\n", linkstat);
  770. }
  771. else
  772. ipath_dev_err(dd, "Can't find PCI Express "
  773. "capability!\n");
  774. return 0;
  775. }
  776. static void ipath_init_pe_variables(void)
  777. {
  778. /*
  779. * bits for selecting i2c direction and values,
  780. * used for I2C serial flash
  781. */
  782. ipath_gpio_sda_num = _IPATH_GPIO_SDA_NUM;
  783. ipath_gpio_scl_num = _IPATH_GPIO_SCL_NUM;
  784. ipath_gpio_sda = IPATH_GPIO_SDA;
  785. ipath_gpio_scl = IPATH_GPIO_SCL;
  786. /* variables for sanity checking interrupt and errors */
  787. infinipath_hwe_bitsextant =
  788. (INFINIPATH_HWE_RXEMEMPARITYERR_MASK <<
  789. INFINIPATH_HWE_RXEMEMPARITYERR_SHIFT) |
  790. (INFINIPATH_HWE_PCIEMEMPARITYERR_MASK <<
  791. INFINIPATH_HWE_PCIEMEMPARITYERR_SHIFT) |
  792. INFINIPATH_HWE_PCIE1PLLFAILED |
  793. INFINIPATH_HWE_PCIE0PLLFAILED |
  794. INFINIPATH_HWE_PCIEPOISONEDTLP |
  795. INFINIPATH_HWE_PCIECPLTIMEOUT |
  796. INFINIPATH_HWE_PCIEBUSPARITYXTLH |
  797. INFINIPATH_HWE_PCIEBUSPARITYXADM |
  798. INFINIPATH_HWE_PCIEBUSPARITYRADM |
  799. INFINIPATH_HWE_MEMBISTFAILED |
  800. INFINIPATH_HWE_COREPLL_FBSLIP |
  801. INFINIPATH_HWE_COREPLL_RFSLIP |
  802. INFINIPATH_HWE_SERDESPLLFAILED |
  803. INFINIPATH_HWE_IBCBUSTOSPCPARITYERR |
  804. INFINIPATH_HWE_IBCBUSFRSPCPARITYERR;
  805. infinipath_i_bitsextant =
  806. (INFINIPATH_I_RCVURG_MASK << INFINIPATH_I_RCVURG_SHIFT) |
  807. (INFINIPATH_I_RCVAVAIL_MASK <<
  808. INFINIPATH_I_RCVAVAIL_SHIFT) |
  809. INFINIPATH_I_ERROR | INFINIPATH_I_SPIOSENT |
  810. INFINIPATH_I_SPIOBUFAVAIL | INFINIPATH_I_GPIO;
  811. infinipath_e_bitsextant =
  812. INFINIPATH_E_RFORMATERR | INFINIPATH_E_RVCRC |
  813. INFINIPATH_E_RICRC | INFINIPATH_E_RMINPKTLEN |
  814. INFINIPATH_E_RMAXPKTLEN | INFINIPATH_E_RLONGPKTLEN |
  815. INFINIPATH_E_RSHORTPKTLEN | INFINIPATH_E_RUNEXPCHAR |
  816. INFINIPATH_E_RUNSUPVL | INFINIPATH_E_REBP |
  817. INFINIPATH_E_RIBFLOW | INFINIPATH_E_RBADVERSION |
  818. INFINIPATH_E_RRCVEGRFULL | INFINIPATH_E_RRCVHDRFULL |
  819. INFINIPATH_E_RBADTID | INFINIPATH_E_RHDRLEN |
  820. INFINIPATH_E_RHDR | INFINIPATH_E_RIBLOSTLINK |
  821. INFINIPATH_E_SMINPKTLEN | INFINIPATH_E_SMAXPKTLEN |
  822. INFINIPATH_E_SUNDERRUN | INFINIPATH_E_SPKTLEN |
  823. INFINIPATH_E_SDROPPEDSMPPKT | INFINIPATH_E_SDROPPEDDATAPKT |
  824. INFINIPATH_E_SPIOARMLAUNCH | INFINIPATH_E_SUNEXPERRPKTNUM |
  825. INFINIPATH_E_SUNSUPVL | INFINIPATH_E_IBSTATUSCHANGED |
  826. INFINIPATH_E_INVALIDADDR | INFINIPATH_E_RESET |
  827. INFINIPATH_E_HARDWARE;
  828. infinipath_i_rcvavail_mask = INFINIPATH_I_RCVAVAIL_MASK;
  829. infinipath_i_rcvurg_mask = INFINIPATH_I_RCVURG_MASK;
  830. }
  831. /* setup the MSI stuff again after a reset. I'd like to just call
  832. * pci_enable_msi() and request_irq() again, but when I do that,
  833. * the MSI enable bit doesn't get set in the command word, and
  834. * we switch to to a different interrupt vector, which is confusing,
  835. * so I instead just do it all inline. Perhaps somehow can tie this
  836. * into the PCIe hotplug support at some point
  837. * Note, because I'm doing it all here, I don't call pci_disable_msi()
  838. * or free_irq() at the start of ipath_setup_pe_reset().
  839. */
  840. static int ipath_reinit_msi(struct ipath_devdata *dd)
  841. {
  842. int pos;
  843. u16 control;
  844. int ret;
  845. if (!dd->ipath_msi_lo) {
  846. dev_info(&dd->pcidev->dev, "Can't restore MSI config, "
  847. "initial setup failed?\n");
  848. ret = 0;
  849. goto bail;
  850. }
  851. if (!(pos = pci_find_capability(dd->pcidev, PCI_CAP_ID_MSI))) {
  852. ipath_dev_err(dd, "Can't find MSI capability, "
  853. "can't restore MSI settings\n");
  854. ret = 0;
  855. goto bail;
  856. }
  857. ipath_cdbg(VERBOSE, "Writing msi_lo 0x%x to config offset 0x%x\n",
  858. dd->ipath_msi_lo, pos + PCI_MSI_ADDRESS_LO);
  859. pci_write_config_dword(dd->pcidev, pos + PCI_MSI_ADDRESS_LO,
  860. dd->ipath_msi_lo);
  861. ipath_cdbg(VERBOSE, "Writing msi_lo 0x%x to config offset 0x%x\n",
  862. dd->ipath_msi_hi, pos + PCI_MSI_ADDRESS_HI);
  863. pci_write_config_dword(dd->pcidev, pos + PCI_MSI_ADDRESS_HI,
  864. dd->ipath_msi_hi);
  865. pci_read_config_word(dd->pcidev, pos + PCI_MSI_FLAGS, &control);
  866. if (!(control & PCI_MSI_FLAGS_ENABLE)) {
  867. ipath_cdbg(VERBOSE, "MSI control at off %x was %x, "
  868. "setting MSI enable (%x)\n", pos + PCI_MSI_FLAGS,
  869. control, control | PCI_MSI_FLAGS_ENABLE);
  870. control |= PCI_MSI_FLAGS_ENABLE;
  871. pci_write_config_word(dd->pcidev, pos + PCI_MSI_FLAGS,
  872. control);
  873. }
  874. /* now rewrite the data (vector) info */
  875. pci_write_config_word(dd->pcidev, pos +
  876. ((control & PCI_MSI_FLAGS_64BIT) ? 12 : 8),
  877. dd->ipath_msi_data);
  878. /* we restore the cachelinesize also, although it doesn't really
  879. * matter */
  880. pci_write_config_byte(dd->pcidev, PCI_CACHE_LINE_SIZE,
  881. dd->ipath_pci_cacheline);
  882. /* and now set the pci master bit again */
  883. pci_set_master(dd->pcidev);
  884. ret = 1;
  885. bail:
  886. return ret;
  887. }
  888. /* This routine sleeps, so it can only be called from user context, not
  889. * from interrupt context. If we need interrupt context, we can split
  890. * it into two routines.
  891. */
  892. static int ipath_setup_pe_reset(struct ipath_devdata *dd)
  893. {
  894. u64 val;
  895. int i;
  896. int ret;
  897. /* Use ERROR so it shows up in logs, etc. */
  898. ipath_dev_err(dd, "Resetting PE-800 unit %u\n",
  899. dd->ipath_unit);
  900. val = dd->ipath_control | INFINIPATH_C_RESET;
  901. ipath_write_kreg(dd, dd->ipath_kregs->kr_control, val);
  902. mb();
  903. for (i = 1; i <= 5; i++) {
  904. int r;
  905. /* allow MBIST, etc. to complete; longer on each retry.
  906. * We sometimes get machine checks from bus timeout if no
  907. * response, so for now, make it *really* long.
  908. */
  909. msleep(1000 + (1 + i) * 2000);
  910. if ((r =
  911. pci_write_config_dword(dd->pcidev, PCI_BASE_ADDRESS_0,
  912. dd->ipath_pcibar0)))
  913. ipath_dev_err(dd, "rewrite of BAR0 failed: %d\n",
  914. r);
  915. if ((r =
  916. pci_write_config_dword(dd->pcidev, PCI_BASE_ADDRESS_1,
  917. dd->ipath_pcibar1)))
  918. ipath_dev_err(dd, "rewrite of BAR1 failed: %d\n",
  919. r);
  920. /* now re-enable memory access */
  921. if ((r = pci_enable_device(dd->pcidev)))
  922. ipath_dev_err(dd, "pci_enable_device failed after "
  923. "reset: %d\n", r);
  924. val = ipath_read_kreg64(dd, dd->ipath_kregs->kr_revision);
  925. if (val == dd->ipath_revision) {
  926. ipath_cdbg(VERBOSE, "Got matching revision "
  927. "register %llx on try %d\n",
  928. (unsigned long long) val, i);
  929. ret = ipath_reinit_msi(dd);
  930. goto bail;
  931. }
  932. /* Probably getting -1 back */
  933. ipath_dbg("Didn't get expected revision register, "
  934. "got %llx, try %d\n", (unsigned long long) val,
  935. i + 1);
  936. }
  937. ret = 0; /* failed */
  938. bail:
  939. return ret;
  940. }
  941. /**
  942. * ipath_pe_put_tid - write a TID in chip
  943. * @dd: the infinipath device
  944. * @tidptr: pointer to the expected TID (in chip) to udpate
  945. * @tidtype: 0 for eager, 1 for expected
  946. * @pa: physical address of in memory buffer; ipath_tidinvalid if freeing
  947. *
  948. * This exists as a separate routine to allow for special locking etc.
  949. * It's used for both the full cleanup on exit, as well as the normal
  950. * setup and teardown.
  951. */
  952. static void ipath_pe_put_tid(struct ipath_devdata *dd, u64 __iomem *tidptr,
  953. u32 type, unsigned long pa)
  954. {
  955. u32 __iomem *tidp32 = (u32 __iomem *)tidptr;
  956. unsigned long flags = 0; /* keep gcc quiet */
  957. if (pa != dd->ipath_tidinvalid) {
  958. if (pa & ((1U << 11) - 1)) {
  959. dev_info(&dd->pcidev->dev, "BUG: physaddr %lx "
  960. "not 4KB aligned!\n", pa);
  961. return;
  962. }
  963. pa >>= 11;
  964. /* paranoia check */
  965. if (pa & (7<<29))
  966. ipath_dev_err(dd,
  967. "BUG: Physical page address 0x%lx "
  968. "has bits set in 31-29\n", pa);
  969. if (type == 0)
  970. pa |= dd->ipath_tidtemplate;
  971. else /* for now, always full 4KB page */
  972. pa |= 2 << 29;
  973. }
  974. /* workaround chip bug 9437 by writing each TID twice
  975. * and holding a spinlock around the writes, so they don't
  976. * intermix with other TID (eager or expected) writes
  977. * Unfortunately, this call can be done from interrupt level
  978. * for the port 0 eager TIDs, so we have to use irqsave
  979. */
  980. spin_lock_irqsave(&dd->ipath_tid_lock, flags);
  981. ipath_write_kreg(dd, dd->ipath_kregs->kr_scratch, 0xfeeddeaf);
  982. if (dd->ipath_kregbase)
  983. writel(pa, tidp32);
  984. ipath_write_kreg(dd, dd->ipath_kregs->kr_scratch, 0xdeadbeef);
  985. mmiowb();
  986. spin_unlock_irqrestore(&dd->ipath_tid_lock, flags);
  987. }
  988. /**
  989. * ipath_pe_clear_tid - clear all TID entries for a port, expected and eager
  990. * @dd: the infinipath device
  991. * @port: the port
  992. *
  993. * clear all TID entries for a port, expected and eager.
  994. * Used from ipath_close(). On PE800, TIDs are only 32 bits,
  995. * not 64, but they are still on 64 bit boundaries, so tidbase
  996. * is declared as u64 * for the pointer math, even though we write 32 bits
  997. */
  998. static void ipath_pe_clear_tids(struct ipath_devdata *dd, unsigned port)
  999. {
  1000. u64 __iomem *tidbase;
  1001. unsigned long tidinv;
  1002. int i;
  1003. if (!dd->ipath_kregbase)
  1004. return;
  1005. ipath_cdbg(VERBOSE, "Invalidate TIDs for port %u\n", port);
  1006. tidinv = dd->ipath_tidinvalid;
  1007. tidbase = (u64 __iomem *)
  1008. ((char __iomem *)(dd->ipath_kregbase) +
  1009. dd->ipath_rcvtidbase +
  1010. port * dd->ipath_rcvtidcnt * sizeof(*tidbase));
  1011. for (i = 0; i < dd->ipath_rcvtidcnt; i++)
  1012. ipath_pe_put_tid(dd, &tidbase[i], 0, tidinv);
  1013. tidbase = (u64 __iomem *)
  1014. ((char __iomem *)(dd->ipath_kregbase) +
  1015. dd->ipath_rcvegrbase +
  1016. port * dd->ipath_rcvegrcnt * sizeof(*tidbase));
  1017. for (i = 0; i < dd->ipath_rcvegrcnt; i++)
  1018. ipath_pe_put_tid(dd, &tidbase[i], 1, tidinv);
  1019. }
  1020. /**
  1021. * ipath_pe_tidtemplate - setup constants for TID updates
  1022. * @dd: the infinipath device
  1023. *
  1024. * We setup stuff that we use a lot, to avoid calculating each time
  1025. */
  1026. static void ipath_pe_tidtemplate(struct ipath_devdata *dd)
  1027. {
  1028. u32 egrsize = dd->ipath_rcvegrbufsize;
  1029. /* For now, we always allocate 4KB buffers (at init) so we can
  1030. * receive max size packets. We may want a module parameter to
  1031. * specify 2KB or 4KB and/or make be per port instead of per device
  1032. * for those who want to reduce memory footprint. Note that the
  1033. * ipath_rcvhdrentsize size must be large enough to hold the largest
  1034. * IB header (currently 96 bytes) that we expect to handle (plus of
  1035. * course the 2 dwords of RHF).
  1036. */
  1037. if (egrsize == 2048)
  1038. dd->ipath_tidtemplate = 1U << 29;
  1039. else if (egrsize == 4096)
  1040. dd->ipath_tidtemplate = 2U << 29;
  1041. else {
  1042. egrsize = 4096;
  1043. dev_info(&dd->pcidev->dev, "BUG: unsupported egrbufsize "
  1044. "%u, using %u\n", dd->ipath_rcvegrbufsize,
  1045. egrsize);
  1046. dd->ipath_tidtemplate = 2U << 29;
  1047. }
  1048. dd->ipath_tidinvalid = 0;
  1049. }
  1050. static int ipath_pe_early_init(struct ipath_devdata *dd)
  1051. {
  1052. dd->ipath_flags |= IPATH_4BYTE_TID;
  1053. /*
  1054. * For openib, we need to be able to handle an IB header of 96 bytes
  1055. * or 24 dwords. HT-400 has arbitrary sized receive buffers, so we
  1056. * made them the same size as the PIO buffers. The PE-800 does not
  1057. * handle arbitrary size buffers, so we need the header large enough
  1058. * to handle largest IB header, but still have room for a 2KB MTU
  1059. * standard IB packet.
  1060. */
  1061. dd->ipath_rcvhdrentsize = 24;
  1062. dd->ipath_rcvhdrsize = IPATH_DFLT_RCVHDRSIZE;
  1063. /* For HT-400, we allocate a somewhat overly large eager buffer,
  1064. * such that we can guarantee that we can receive the largest packet
  1065. * that we can send out. To truly support a 4KB MTU, we need to
  1066. * bump this to a larger value. We'll do this when I get around to
  1067. * testing 4KB sends on the PE-800, which I have not yet done.
  1068. */
  1069. dd->ipath_rcvegrbufsize = 2048;
  1070. /*
  1071. * the min() check here is currently a nop, but it may not always
  1072. * be, depending on just how we do ipath_rcvegrbufsize
  1073. */
  1074. dd->ipath_ibmaxlen = min(dd->ipath_piosize2k,
  1075. dd->ipath_rcvegrbufsize +
  1076. (dd->ipath_rcvhdrentsize << 2));
  1077. dd->ipath_init_ibmaxlen = dd->ipath_ibmaxlen;
  1078. /*
  1079. * For PE-800, we can request a receive interrupt for 1 or
  1080. * more packets from current offset. For now, we set this
  1081. * up for a single packet, to match the HT-400 behavior.
  1082. */
  1083. dd->ipath_rhdrhead_intr_off = 1ULL<<32;
  1084. return 0;
  1085. }
  1086. int __attribute__((weak)) ipath_unordered_wc(void)
  1087. {
  1088. return 0;
  1089. }
  1090. /**
  1091. * ipath_init_pe_get_base_info - set chip-specific flags for user code
  1092. * @dd: the infinipath device
  1093. * @kbase: ipath_base_info pointer
  1094. *
  1095. * We set the PCIE flag because the lower bandwidth on PCIe vs
  1096. * HyperTransport can affect some user packet algorithims.
  1097. */
  1098. static int ipath_pe_get_base_info(struct ipath_portdata *pd, void *kbase)
  1099. {
  1100. struct ipath_base_info *kinfo = kbase;
  1101. if (ipath_unordered_wc()) {
  1102. kinfo->spi_runtime_flags |= IPATH_RUNTIME_FORCE_WC_ORDER;
  1103. ipath_cdbg(PROC, "Intel processor, forcing WC order\n");
  1104. }
  1105. else
  1106. ipath_cdbg(PROC, "Not Intel processor, WC ordered\n");
  1107. kinfo->spi_runtime_flags |= IPATH_RUNTIME_PCIE;
  1108. return 0;
  1109. }
  1110. /**
  1111. * ipath_init_pe800_funcs - set up the chip-specific function pointers
  1112. * @dd: the infinipath device
  1113. *
  1114. * This is global, and is called directly at init to set up the
  1115. * chip-specific function pointers for later use.
  1116. */
  1117. void ipath_init_pe800_funcs(struct ipath_devdata *dd)
  1118. {
  1119. dd->ipath_f_intrsetup = ipath_pe_intconfig;
  1120. dd->ipath_f_bus = ipath_setup_pe_config;
  1121. dd->ipath_f_reset = ipath_setup_pe_reset;
  1122. dd->ipath_f_get_boardname = ipath_pe_boardname;
  1123. dd->ipath_f_init_hwerrors = ipath_pe_init_hwerrors;
  1124. dd->ipath_f_early_init = ipath_pe_early_init;
  1125. dd->ipath_f_handle_hwerrors = ipath_pe_handle_hwerrors;
  1126. dd->ipath_f_quiet_serdes = ipath_pe_quiet_serdes;
  1127. dd->ipath_f_bringup_serdes = ipath_pe_bringup_serdes;
  1128. dd->ipath_f_clear_tids = ipath_pe_clear_tids;
  1129. dd->ipath_f_put_tid = ipath_pe_put_tid;
  1130. dd->ipath_f_cleanup = ipath_setup_pe_cleanup;
  1131. dd->ipath_f_setextled = ipath_setup_pe_setextled;
  1132. dd->ipath_f_get_base_info = ipath_pe_get_base_info;
  1133. /* initialize chip-specific variables */
  1134. dd->ipath_f_tidtemplate = ipath_pe_tidtemplate;
  1135. /*
  1136. * setup the register offsets, since they are different for each
  1137. * chip
  1138. */
  1139. dd->ipath_kregs = &ipath_pe_kregs;
  1140. dd->ipath_cregs = &ipath_pe_cregs;
  1141. ipath_init_pe_variables();
  1142. }