ipath_pe800.c 43 KB

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