ipath_iba6120.c 49 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440
  1. /*
  2. * Copyright (c) 2006, 2007 QLogic Corporation. 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 PCIe 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. static void ipath_setup_pe_setextled(struct ipath_devdata *, u64, u64);
  43. /*
  44. * This file contains all the chip-specific register information and
  45. * access functions for the QLogic InfiniPath PCI-Express chip.
  46. *
  47. * This lists the InfiniPath registers, in the actual chip layout.
  48. * This structure should never be directly accessed.
  49. */
  50. struct _infinipath_do_not_use_kernel_regs {
  51. unsigned long long Revision;
  52. unsigned long long Control;
  53. unsigned long long PageAlign;
  54. unsigned long long PortCnt;
  55. unsigned long long DebugPortSelect;
  56. unsigned long long Reserved0;
  57. unsigned long long SendRegBase;
  58. unsigned long long UserRegBase;
  59. unsigned long long CounterRegBase;
  60. unsigned long long Scratch;
  61. unsigned long long Reserved1;
  62. unsigned long long Reserved2;
  63. unsigned long long IntBlocked;
  64. unsigned long long IntMask;
  65. unsigned long long IntStatus;
  66. unsigned long long IntClear;
  67. unsigned long long ErrorMask;
  68. unsigned long long ErrorStatus;
  69. unsigned long long ErrorClear;
  70. unsigned long long HwErrMask;
  71. unsigned long long HwErrStatus;
  72. unsigned long long HwErrClear;
  73. unsigned long long HwDiagCtrl;
  74. unsigned long long MDIO;
  75. unsigned long long IBCStatus;
  76. unsigned long long IBCCtrl;
  77. unsigned long long ExtStatus;
  78. unsigned long long ExtCtrl;
  79. unsigned long long GPIOOut;
  80. unsigned long long GPIOMask;
  81. unsigned long long GPIOStatus;
  82. unsigned long long GPIOClear;
  83. unsigned long long RcvCtrl;
  84. unsigned long long RcvBTHQP;
  85. unsigned long long RcvHdrSize;
  86. unsigned long long RcvHdrCnt;
  87. unsigned long long RcvHdrEntSize;
  88. unsigned long long RcvTIDBase;
  89. unsigned long long RcvTIDCnt;
  90. unsigned long long RcvEgrBase;
  91. unsigned long long RcvEgrCnt;
  92. unsigned long long RcvBufBase;
  93. unsigned long long RcvBufSize;
  94. unsigned long long RxIntMemBase;
  95. unsigned long long RxIntMemSize;
  96. unsigned long long RcvPartitionKey;
  97. unsigned long long Reserved3;
  98. unsigned long long RcvPktLEDCnt;
  99. unsigned long long Reserved4[8];
  100. unsigned long long SendCtrl;
  101. unsigned long long SendPIOBufBase;
  102. unsigned long long SendPIOSize;
  103. unsigned long long SendPIOBufCnt;
  104. unsigned long long SendPIOAvailAddr;
  105. unsigned long long TxIntMemBase;
  106. unsigned long long TxIntMemSize;
  107. unsigned long long Reserved5;
  108. unsigned long long PCIeRBufTestReg0;
  109. unsigned long long PCIeRBufTestReg1;
  110. unsigned long long Reserved51[6];
  111. unsigned long long SendBufferError;
  112. unsigned long long SendBufferErrorCONT1;
  113. unsigned long long Reserved6SBE[6];
  114. unsigned long long RcvHdrAddr0;
  115. unsigned long long RcvHdrAddr1;
  116. unsigned long long RcvHdrAddr2;
  117. unsigned long long RcvHdrAddr3;
  118. unsigned long long RcvHdrAddr4;
  119. unsigned long long Reserved7RHA[11];
  120. unsigned long long RcvHdrTailAddr0;
  121. unsigned long long RcvHdrTailAddr1;
  122. unsigned long long RcvHdrTailAddr2;
  123. unsigned long long RcvHdrTailAddr3;
  124. unsigned long long RcvHdrTailAddr4;
  125. unsigned long long Reserved8RHTA[11];
  126. unsigned long long Reserved9SW[8];
  127. unsigned long long SerdesConfig0;
  128. unsigned long long SerdesConfig1;
  129. unsigned long long SerdesStatus;
  130. unsigned long long XGXSConfig;
  131. unsigned long long IBPLLCfg;
  132. unsigned long long Reserved10SW2[3];
  133. unsigned long long PCIEQ0SerdesConfig0;
  134. unsigned long long PCIEQ0SerdesConfig1;
  135. unsigned long long PCIEQ0SerdesStatus;
  136. unsigned long long Reserved11;
  137. unsigned long long PCIEQ1SerdesConfig0;
  138. unsigned long long PCIEQ1SerdesConfig1;
  139. unsigned long long PCIEQ1SerdesStatus;
  140. unsigned long long Reserved12;
  141. };
  142. #define IPATH_KREG_OFFSET(field) (offsetof(struct \
  143. _infinipath_do_not_use_kernel_regs, field) / sizeof(u64))
  144. #define IPATH_CREG_OFFSET(field) (offsetof( \
  145. struct infinipath_counters, field) / sizeof(u64))
  146. static const struct ipath_kregs ipath_pe_kregs = {
  147. .kr_control = IPATH_KREG_OFFSET(Control),
  148. .kr_counterregbase = IPATH_KREG_OFFSET(CounterRegBase),
  149. .kr_debugportselect = IPATH_KREG_OFFSET(DebugPortSelect),
  150. .kr_errorclear = IPATH_KREG_OFFSET(ErrorClear),
  151. .kr_errormask = IPATH_KREG_OFFSET(ErrorMask),
  152. .kr_errorstatus = IPATH_KREG_OFFSET(ErrorStatus),
  153. .kr_extctrl = IPATH_KREG_OFFSET(ExtCtrl),
  154. .kr_extstatus = IPATH_KREG_OFFSET(ExtStatus),
  155. .kr_gpio_clear = IPATH_KREG_OFFSET(GPIOClear),
  156. .kr_gpio_mask = IPATH_KREG_OFFSET(GPIOMask),
  157. .kr_gpio_out = IPATH_KREG_OFFSET(GPIOOut),
  158. .kr_gpio_status = IPATH_KREG_OFFSET(GPIOStatus),
  159. .kr_hwdiagctrl = IPATH_KREG_OFFSET(HwDiagCtrl),
  160. .kr_hwerrclear = IPATH_KREG_OFFSET(HwErrClear),
  161. .kr_hwerrmask = IPATH_KREG_OFFSET(HwErrMask),
  162. .kr_hwerrstatus = IPATH_KREG_OFFSET(HwErrStatus),
  163. .kr_ibcctrl = IPATH_KREG_OFFSET(IBCCtrl),
  164. .kr_ibcstatus = IPATH_KREG_OFFSET(IBCStatus),
  165. .kr_intblocked = IPATH_KREG_OFFSET(IntBlocked),
  166. .kr_intclear = IPATH_KREG_OFFSET(IntClear),
  167. .kr_intmask = IPATH_KREG_OFFSET(IntMask),
  168. .kr_intstatus = IPATH_KREG_OFFSET(IntStatus),
  169. .kr_mdio = IPATH_KREG_OFFSET(MDIO),
  170. .kr_pagealign = IPATH_KREG_OFFSET(PageAlign),
  171. .kr_partitionkey = IPATH_KREG_OFFSET(RcvPartitionKey),
  172. .kr_portcnt = IPATH_KREG_OFFSET(PortCnt),
  173. .kr_rcvbthqp = IPATH_KREG_OFFSET(RcvBTHQP),
  174. .kr_rcvbufbase = IPATH_KREG_OFFSET(RcvBufBase),
  175. .kr_rcvbufsize = IPATH_KREG_OFFSET(RcvBufSize),
  176. .kr_rcvctrl = IPATH_KREG_OFFSET(RcvCtrl),
  177. .kr_rcvegrbase = IPATH_KREG_OFFSET(RcvEgrBase),
  178. .kr_rcvegrcnt = IPATH_KREG_OFFSET(RcvEgrCnt),
  179. .kr_rcvhdrcnt = IPATH_KREG_OFFSET(RcvHdrCnt),
  180. .kr_rcvhdrentsize = IPATH_KREG_OFFSET(RcvHdrEntSize),
  181. .kr_rcvhdrsize = IPATH_KREG_OFFSET(RcvHdrSize),
  182. .kr_rcvintmembase = IPATH_KREG_OFFSET(RxIntMemBase),
  183. .kr_rcvintmemsize = IPATH_KREG_OFFSET(RxIntMemSize),
  184. .kr_rcvtidbase = IPATH_KREG_OFFSET(RcvTIDBase),
  185. .kr_rcvtidcnt = IPATH_KREG_OFFSET(RcvTIDCnt),
  186. .kr_revision = IPATH_KREG_OFFSET(Revision),
  187. .kr_scratch = IPATH_KREG_OFFSET(Scratch),
  188. .kr_sendbuffererror = IPATH_KREG_OFFSET(SendBufferError),
  189. .kr_sendctrl = IPATH_KREG_OFFSET(SendCtrl),
  190. .kr_sendpioavailaddr = IPATH_KREG_OFFSET(SendPIOAvailAddr),
  191. .kr_sendpiobufbase = IPATH_KREG_OFFSET(SendPIOBufBase),
  192. .kr_sendpiobufcnt = IPATH_KREG_OFFSET(SendPIOBufCnt),
  193. .kr_sendpiosize = IPATH_KREG_OFFSET(SendPIOSize),
  194. .kr_sendregbase = IPATH_KREG_OFFSET(SendRegBase),
  195. .kr_txintmembase = IPATH_KREG_OFFSET(TxIntMemBase),
  196. .kr_txintmemsize = IPATH_KREG_OFFSET(TxIntMemSize),
  197. .kr_userregbase = IPATH_KREG_OFFSET(UserRegBase),
  198. .kr_serdesconfig0 = IPATH_KREG_OFFSET(SerdesConfig0),
  199. .kr_serdesconfig1 = IPATH_KREG_OFFSET(SerdesConfig1),
  200. .kr_serdesstatus = IPATH_KREG_OFFSET(SerdesStatus),
  201. .kr_xgxsconfig = IPATH_KREG_OFFSET(XGXSConfig),
  202. .kr_ibpllcfg = IPATH_KREG_OFFSET(IBPLLCfg),
  203. /*
  204. * These should not be used directly via ipath_write_kreg64(),
  205. * use them with ipath_write_kreg64_port(),
  206. */
  207. .kr_rcvhdraddr = IPATH_KREG_OFFSET(RcvHdrAddr0),
  208. .kr_rcvhdrtailaddr = IPATH_KREG_OFFSET(RcvHdrTailAddr0),
  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 ((1U<<5)-1)
  258. #define INFINIPATH_I_RCVAVAIL_MASK ((1U<<5)-1)
  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. #define INFINIPATH_R_INTRAVAIL_SHIFT 16
  284. #define INFINIPATH_R_TAILUPD_SHIFT 31
  285. /* 6120 specific hardware errors... */
  286. static const struct ipath_hwerror_msgs ipath_6120_hwerror_msgs[] = {
  287. INFINIPATH_HWE_MSG(PCIEPOISONEDTLP, "PCIe Poisoned TLP"),
  288. INFINIPATH_HWE_MSG(PCIECPLTIMEOUT, "PCIe completion timeout"),
  289. /*
  290. * In practice, it's unlikely wthat we'll see PCIe PLL, or bus
  291. * parity or memory parity error failures, because most likely we
  292. * won't be able to talk to the core of the chip. Nonetheless, we
  293. * might see them, if they are in parts of the PCIe core that aren't
  294. * essential.
  295. */
  296. INFINIPATH_HWE_MSG(PCIE1PLLFAILED, "PCIePLL1"),
  297. INFINIPATH_HWE_MSG(PCIE0PLLFAILED, "PCIePLL0"),
  298. INFINIPATH_HWE_MSG(PCIEBUSPARITYXTLH, "PCIe XTLH core parity"),
  299. INFINIPATH_HWE_MSG(PCIEBUSPARITYXADM, "PCIe ADM TX core parity"),
  300. INFINIPATH_HWE_MSG(PCIEBUSPARITYRADM, "PCIe ADM RX core parity"),
  301. INFINIPATH_HWE_MSG(RXDSYNCMEMPARITYERR, "Rx Dsync"),
  302. INFINIPATH_HWE_MSG(SERDESPLLFAILED, "SerDes PLL"),
  303. };
  304. #define TXE_PIO_PARITY ((INFINIPATH_HWE_TXEMEMPARITYERR_PIOBUF | \
  305. INFINIPATH_HWE_TXEMEMPARITYERR_PIOPBC) \
  306. << INFINIPATH_HWE_TXEMEMPARITYERR_SHIFT)
  307. static int ipath_pe_txe_recover(struct ipath_devdata *);
  308. static void ipath_pe_put_tid_2(struct ipath_devdata *, u64 __iomem *,
  309. u32, unsigned long);
  310. /**
  311. * ipath_pe_handle_hwerrors - display hardware errors.
  312. * @dd: the infinipath device
  313. * @msg: the output buffer
  314. * @msgl: the size of the output buffer
  315. *
  316. * Use same msg buffer as regular errors to avoid excessive stack
  317. * use. Most hardware errors are catastrophic, but for right now,
  318. * we'll print them and continue. We reuse the same message buffer as
  319. * ipath_handle_errors() to avoid excessive stack usage.
  320. */
  321. static void ipath_pe_handle_hwerrors(struct ipath_devdata *dd, char *msg,
  322. size_t msgl)
  323. {
  324. ipath_err_t hwerrs;
  325. u32 bits, ctrl;
  326. int isfatal = 0;
  327. char bitsmsg[64];
  328. int log_idx;
  329. hwerrs = ipath_read_kreg64(dd, dd->ipath_kregs->kr_hwerrstatus);
  330. if (!hwerrs) {
  331. /*
  332. * better than printing cofusing messages
  333. * This seems to be related to clearing the crc error, or
  334. * the pll error during init.
  335. */
  336. ipath_cdbg(VERBOSE, "Called but no hardware errors set\n");
  337. return;
  338. } else if (hwerrs == ~0ULL) {
  339. ipath_dev_err(dd, "Read of hardware error status failed "
  340. "(all bits set); ignoring\n");
  341. return;
  342. }
  343. ipath_stats.sps_hwerrs++;
  344. /* Always clear the error status register, except MEMBISTFAIL,
  345. * regardless of whether we continue or stop using the chip.
  346. * We want that set so we know it failed, even across driver reload.
  347. * We'll still ignore it in the hwerrmask. We do this partly for
  348. * diagnostics, but also for support */
  349. ipath_write_kreg(dd, dd->ipath_kregs->kr_hwerrclear,
  350. hwerrs&~INFINIPATH_HWE_MEMBISTFAILED);
  351. hwerrs &= dd->ipath_hwerrmask;
  352. /* We log some errors to EEPROM, check if we have any of those. */
  353. for (log_idx = 0; log_idx < IPATH_EEP_LOG_CNT; ++log_idx)
  354. if (hwerrs & dd->ipath_eep_st_masks[log_idx].hwerrs_to_log)
  355. ipath_inc_eeprom_err(dd, log_idx, 1);
  356. /*
  357. * make sure we get this much out, unless told to be quiet,
  358. * or it's occurred within the last 5 seconds
  359. */
  360. if ((hwerrs & ~(dd->ipath_lasthwerror |
  361. ((INFINIPATH_HWE_TXEMEMPARITYERR_PIOBUF |
  362. INFINIPATH_HWE_TXEMEMPARITYERR_PIOPBC)
  363. << INFINIPATH_HWE_TXEMEMPARITYERR_SHIFT))) ||
  364. (ipath_debug & __IPATH_VERBDBG))
  365. dev_info(&dd->pcidev->dev, "Hardware error: hwerr=0x%llx "
  366. "(cleared)\n", (unsigned long long) hwerrs);
  367. dd->ipath_lasthwerror |= hwerrs;
  368. if (hwerrs & ~dd->ipath_hwe_bitsextant)
  369. ipath_dev_err(dd, "hwerror interrupt with unknown errors "
  370. "%llx set\n", (unsigned long long)
  371. (hwerrs & ~dd->ipath_hwe_bitsextant));
  372. ctrl = ipath_read_kreg32(dd, dd->ipath_kregs->kr_control);
  373. if (ctrl & INFINIPATH_C_FREEZEMODE) {
  374. /*
  375. * parity errors in send memory are recoverable,
  376. * just cancel the send (if indicated in * sendbuffererror),
  377. * count the occurrence, unfreeze (if no other handled
  378. * hardware error bits are set), and continue. They can
  379. * occur if a processor speculative read is done to the PIO
  380. * buffer while we are sending a packet, for example.
  381. */
  382. if ((hwerrs & TXE_PIO_PARITY) && ipath_pe_txe_recover(dd))
  383. hwerrs &= ~TXE_PIO_PARITY;
  384. if (hwerrs) {
  385. /*
  386. * if any set that we aren't ignoring only make the
  387. * complaint once, in case it's stuck or recurring,
  388. * and we get here multiple times
  389. * Force link down, so switch knows, and
  390. * LEDs are turned off
  391. */
  392. if (dd->ipath_flags & IPATH_INITTED) {
  393. ipath_set_linkstate(dd, IPATH_IB_LINKDOWN);
  394. ipath_setup_pe_setextled(dd,
  395. INFINIPATH_IBCS_L_STATE_DOWN,
  396. INFINIPATH_IBCS_LT_STATE_DISABLED);
  397. ipath_dev_err(dd, "Fatal Hardware Error (freeze "
  398. "mode), no longer usable, SN %.16s\n",
  399. dd->ipath_serial);
  400. isfatal = 1;
  401. }
  402. /*
  403. * Mark as having had an error for driver, and also
  404. * for /sys and status word mapped to user programs.
  405. * This marks unit as not usable, until reset
  406. */
  407. *dd->ipath_statusp &= ~IPATH_STATUS_IB_READY;
  408. *dd->ipath_statusp |= IPATH_STATUS_HWERROR;
  409. dd->ipath_flags &= ~IPATH_INITTED;
  410. } else {
  411. static u32 freeze_cnt;
  412. freeze_cnt++;
  413. ipath_dbg("Clearing freezemode on ignored or recovered "
  414. "hardware error (%u)\n", freeze_cnt);
  415. ipath_clear_freeze(dd);
  416. }
  417. }
  418. *msg = '\0';
  419. if (hwerrs & INFINIPATH_HWE_MEMBISTFAILED) {
  420. strlcat(msg, "[Memory BIST test failed, InfiniPath hardware unusable]",
  421. msgl);
  422. /* ignore from now on, so disable until driver reloaded */
  423. *dd->ipath_statusp |= IPATH_STATUS_HWERROR;
  424. dd->ipath_hwerrmask &= ~INFINIPATH_HWE_MEMBISTFAILED;
  425. ipath_write_kreg(dd, dd->ipath_kregs->kr_hwerrmask,
  426. dd->ipath_hwerrmask);
  427. }
  428. ipath_format_hwerrors(hwerrs,
  429. ipath_6120_hwerror_msgs,
  430. sizeof(ipath_6120_hwerror_msgs)/
  431. sizeof(ipath_6120_hwerror_msgs[0]),
  432. msg, msgl);
  433. if (hwerrs & (INFINIPATH_HWE_PCIEMEMPARITYERR_MASK
  434. << INFINIPATH_HWE_PCIEMEMPARITYERR_SHIFT)) {
  435. bits = (u32) ((hwerrs >>
  436. INFINIPATH_HWE_PCIEMEMPARITYERR_SHIFT) &
  437. INFINIPATH_HWE_PCIEMEMPARITYERR_MASK);
  438. snprintf(bitsmsg, sizeof bitsmsg,
  439. "[PCIe Mem Parity Errs %x] ", bits);
  440. strlcat(msg, bitsmsg, msgl);
  441. }
  442. #define _IPATH_PLL_FAIL (INFINIPATH_HWE_COREPLL_FBSLIP | \
  443. INFINIPATH_HWE_COREPLL_RFSLIP )
  444. if (hwerrs & _IPATH_PLL_FAIL) {
  445. snprintf(bitsmsg, sizeof bitsmsg,
  446. "[PLL failed (%llx), InfiniPath hardware unusable]",
  447. (unsigned long long) hwerrs & _IPATH_PLL_FAIL);
  448. strlcat(msg, bitsmsg, msgl);
  449. /* ignore from now on, so disable until driver reloaded */
  450. dd->ipath_hwerrmask &= ~(hwerrs & _IPATH_PLL_FAIL);
  451. ipath_write_kreg(dd, dd->ipath_kregs->kr_hwerrmask,
  452. dd->ipath_hwerrmask);
  453. }
  454. if (hwerrs & INFINIPATH_HWE_SERDESPLLFAILED) {
  455. /*
  456. * If it occurs, it is left masked since the eternal
  457. * interface is unused
  458. */
  459. dd->ipath_hwerrmask &= ~INFINIPATH_HWE_SERDESPLLFAILED;
  460. ipath_write_kreg(dd, dd->ipath_kregs->kr_hwerrmask,
  461. dd->ipath_hwerrmask);
  462. }
  463. if (*msg)
  464. ipath_dev_err(dd, "%s hardware error\n", msg);
  465. if (isfatal && !ipath_diag_inuse && dd->ipath_freezemsg) {
  466. /*
  467. * for /sys status file ; if no trailing } is copied, we'll
  468. * know it was truncated.
  469. */
  470. snprintf(dd->ipath_freezemsg, dd->ipath_freezelen,
  471. "{%s}", msg);
  472. }
  473. }
  474. /**
  475. * ipath_pe_boardname - fill in the board name
  476. * @dd: the infinipath device
  477. * @name: the output buffer
  478. * @namelen: the size of the output buffer
  479. *
  480. * info is based on the board revision register
  481. */
  482. static int ipath_pe_boardname(struct ipath_devdata *dd, char *name,
  483. size_t namelen)
  484. {
  485. char *n = NULL;
  486. u8 boardrev = dd->ipath_boardrev;
  487. int ret;
  488. switch (boardrev) {
  489. case 0:
  490. n = "InfiniPath_Emulation";
  491. break;
  492. case 1:
  493. n = "InfiniPath_QLE7140-Bringup";
  494. break;
  495. case 2:
  496. n = "InfiniPath_QLE7140";
  497. break;
  498. case 3:
  499. n = "InfiniPath_QMI7140";
  500. break;
  501. case 4:
  502. n = "InfiniPath_QEM7140";
  503. break;
  504. case 5:
  505. n = "InfiniPath_QMH7140";
  506. break;
  507. case 6:
  508. n = "InfiniPath_QLE7142";
  509. break;
  510. default:
  511. ipath_dev_err(dd,
  512. "Don't yet know about board with ID %u\n",
  513. boardrev);
  514. snprintf(name, namelen, "Unknown_InfiniPath_PCIe_%u",
  515. boardrev);
  516. break;
  517. }
  518. if (n)
  519. snprintf(name, namelen, "%s", n);
  520. if (dd->ipath_majrev != 4 || !dd->ipath_minrev || dd->ipath_minrev>2) {
  521. ipath_dev_err(dd, "Unsupported InfiniPath hardware revision %u.%u!\n",
  522. dd->ipath_majrev, dd->ipath_minrev);
  523. ret = 1;
  524. } else {
  525. ret = 0;
  526. if (dd->ipath_minrev >= 2)
  527. dd->ipath_f_put_tid = ipath_pe_put_tid_2;
  528. }
  529. return ret;
  530. }
  531. /**
  532. * ipath_pe_init_hwerrors - enable hardware errors
  533. * @dd: the infinipath device
  534. *
  535. * now that we have finished initializing everything that might reasonably
  536. * cause a hardware error, and cleared those errors bits as they occur,
  537. * we can enable hardware errors in the mask (potentially enabling
  538. * freeze mode), and enable hardware errors as errors (along with
  539. * everything else) in errormask
  540. */
  541. static void ipath_pe_init_hwerrors(struct ipath_devdata *dd)
  542. {
  543. ipath_err_t val;
  544. u64 extsval;
  545. extsval = ipath_read_kreg64(dd, dd->ipath_kregs->kr_extstatus);
  546. if (!(extsval & INFINIPATH_EXTS_MEMBIST_ENDTEST))
  547. ipath_dev_err(dd, "MemBIST did not complete!\n");
  548. if (extsval & INFINIPATH_EXTS_MEMBIST_FOUND)
  549. ipath_dbg("MemBIST corrected\n");
  550. val = ~0ULL; /* barring bugs, all hwerrors become interrupts, */
  551. if (!dd->ipath_boardrev) // no PLL for Emulator
  552. val &= ~INFINIPATH_HWE_SERDESPLLFAILED;
  553. if (dd->ipath_minrev < 2) {
  554. /* workaround bug 9460 in internal interface bus parity
  555. * checking. Fixed (HW bug 9490) in Rev2.
  556. */
  557. val &= ~INFINIPATH_HWE_PCIEBUSPARITYRADM;
  558. }
  559. dd->ipath_hwerrmask = val;
  560. }
  561. /**
  562. * ipath_pe_bringup_serdes - bring up the serdes
  563. * @dd: the infinipath device
  564. */
  565. static int ipath_pe_bringup_serdes(struct ipath_devdata *dd)
  566. {
  567. u64 val, config1, prev_val;
  568. int ret = 0;
  569. ipath_dbg("Trying to bringup serdes\n");
  570. if (ipath_read_kreg64(dd, dd->ipath_kregs->kr_hwerrstatus) &
  571. INFINIPATH_HWE_SERDESPLLFAILED) {
  572. ipath_dbg("At start, serdes PLL failed bit set "
  573. "in hwerrstatus, clearing and continuing\n");
  574. ipath_write_kreg(dd, dd->ipath_kregs->kr_hwerrclear,
  575. INFINIPATH_HWE_SERDESPLLFAILED);
  576. }
  577. val = ipath_read_kreg64(dd, dd->ipath_kregs->kr_serdesconfig0);
  578. config1 = ipath_read_kreg64(dd, dd->ipath_kregs->kr_serdesconfig1);
  579. ipath_cdbg(VERBOSE, "SerDes status config0=%llx config1=%llx, "
  580. "xgxsconfig %llx\n", (unsigned long long) val,
  581. (unsigned long long) config1, (unsigned long long)
  582. ipath_read_kreg64(dd, dd->ipath_kregs->kr_xgxsconfig));
  583. /*
  584. * Force reset on, also set rxdetect enable. Must do before reading
  585. * serdesstatus at least for simulation, or some of the bits in
  586. * serdes status will come back as undefined and cause simulation
  587. * failures
  588. */
  589. val |= INFINIPATH_SERDC0_RESET_PLL | INFINIPATH_SERDC0_RXDETECT_EN
  590. | INFINIPATH_SERDC0_L1PWR_DN;
  591. ipath_write_kreg(dd, dd->ipath_kregs->kr_serdesconfig0, val);
  592. /* be sure chip saw it */
  593. ipath_read_kreg64(dd, dd->ipath_kregs->kr_scratch);
  594. udelay(5); /* need pll reset set at least for a bit */
  595. /*
  596. * after PLL is reset, set the per-lane Resets and TxIdle and
  597. * clear the PLL reset and rxdetect (to get falling edge).
  598. * Leave L1PWR bits set (permanently)
  599. */
  600. val &= ~(INFINIPATH_SERDC0_RXDETECT_EN | INFINIPATH_SERDC0_RESET_PLL
  601. | INFINIPATH_SERDC0_L1PWR_DN);
  602. val |= INFINIPATH_SERDC0_RESET_MASK | INFINIPATH_SERDC0_TXIDLE;
  603. ipath_cdbg(VERBOSE, "Clearing pll reset and setting lane resets "
  604. "and txidle (%llx)\n", (unsigned long long) val);
  605. ipath_write_kreg(dd, dd->ipath_kregs->kr_serdesconfig0, val);
  606. /* be sure chip saw it */
  607. ipath_read_kreg64(dd, dd->ipath_kregs->kr_scratch);
  608. /* need PLL reset clear for at least 11 usec before lane
  609. * resets cleared; give it a few more to be sure */
  610. udelay(15);
  611. val &= ~(INFINIPATH_SERDC0_RESET_MASK | INFINIPATH_SERDC0_TXIDLE);
  612. ipath_cdbg(VERBOSE, "Clearing lane resets and txidle "
  613. "(writing %llx)\n", (unsigned long long) val);
  614. ipath_write_kreg(dd, dd->ipath_kregs->kr_serdesconfig0, val);
  615. /* be sure chip saw it */
  616. val = ipath_read_kreg64(dd, dd->ipath_kregs->kr_scratch);
  617. val = ipath_read_kreg64(dd, dd->ipath_kregs->kr_xgxsconfig);
  618. prev_val = val;
  619. if (((val >> INFINIPATH_XGXS_MDIOADDR_SHIFT) &
  620. INFINIPATH_XGXS_MDIOADDR_MASK) != 3) {
  621. val &=
  622. ~(INFINIPATH_XGXS_MDIOADDR_MASK <<
  623. INFINIPATH_XGXS_MDIOADDR_SHIFT);
  624. /* MDIO address 3 */
  625. val |= 3ULL << INFINIPATH_XGXS_MDIOADDR_SHIFT;
  626. }
  627. if (val & INFINIPATH_XGXS_RESET) {
  628. val &= ~INFINIPATH_XGXS_RESET;
  629. }
  630. if (((val >> INFINIPATH_XGXS_RX_POL_SHIFT) &
  631. INFINIPATH_XGXS_RX_POL_MASK) != dd->ipath_rx_pol_inv ) {
  632. /* need to compensate for Tx inversion in partner */
  633. val &= ~(INFINIPATH_XGXS_RX_POL_MASK <<
  634. INFINIPATH_XGXS_RX_POL_SHIFT);
  635. val |= dd->ipath_rx_pol_inv <<
  636. INFINIPATH_XGXS_RX_POL_SHIFT;
  637. }
  638. if (val != prev_val)
  639. ipath_write_kreg(dd, dd->ipath_kregs->kr_xgxsconfig, val);
  640. val = ipath_read_kreg64(dd, dd->ipath_kregs->kr_serdesconfig0);
  641. /* clear current and de-emphasis bits */
  642. config1 &= ~0x0ffffffff00ULL;
  643. /* set current to 20ma */
  644. config1 |= 0x00000000000ULL;
  645. /* set de-emphasis to -5.68dB */
  646. config1 |= 0x0cccc000000ULL;
  647. ipath_write_kreg(dd, dd->ipath_kregs->kr_serdesconfig1, config1);
  648. ipath_cdbg(VERBOSE, "done: SerDes status config0=%llx "
  649. "config1=%llx, sstatus=%llx xgxs=%llx\n",
  650. (unsigned long long) val, (unsigned long long) config1,
  651. (unsigned long long)
  652. ipath_read_kreg64(dd, dd->ipath_kregs->kr_serdesstatus),
  653. (unsigned long long)
  654. ipath_read_kreg64(dd, dd->ipath_kregs->kr_xgxsconfig));
  655. if (!ipath_waitfor_mdio_cmdready(dd)) {
  656. ipath_write_kreg(
  657. dd, dd->ipath_kregs->kr_mdio,
  658. ipath_mdio_req(IPATH_MDIO_CMD_READ, 31,
  659. IPATH_MDIO_CTRL_XGXS_REG_8, 0));
  660. if (ipath_waitfor_complete(dd, dd->ipath_kregs->kr_mdio,
  661. IPATH_MDIO_DATAVALID, &val))
  662. ipath_dbg("Never got MDIO data for XGXS "
  663. "status read\n");
  664. else
  665. ipath_cdbg(VERBOSE, "MDIO Read reg8, "
  666. "'bank' 31 %x\n", (u32) val);
  667. } else
  668. ipath_dbg("Never got MDIO cmdready for XGXS status read\n");
  669. return ret;
  670. }
  671. /**
  672. * ipath_pe_quiet_serdes - set serdes to txidle
  673. * @dd: the infinipath device
  674. * Called when driver is being unloaded
  675. */
  676. static void ipath_pe_quiet_serdes(struct ipath_devdata *dd)
  677. {
  678. u64 val = ipath_read_kreg64(dd, dd->ipath_kregs->kr_serdesconfig0);
  679. val |= INFINIPATH_SERDC0_TXIDLE;
  680. ipath_dbg("Setting TxIdleEn on serdes (config0 = %llx)\n",
  681. (unsigned long long) val);
  682. ipath_write_kreg(dd, dd->ipath_kregs->kr_serdesconfig0, val);
  683. }
  684. static int ipath_pe_intconfig(struct ipath_devdata *dd)
  685. {
  686. u32 chiprev;
  687. /*
  688. * If the chip supports added error indication via GPIO pins,
  689. * enable interrupts on those bits so the interrupt routine
  690. * can count the events. Also set flag so interrupt routine
  691. * can know they are expected.
  692. */
  693. chiprev = dd->ipath_revision >> INFINIPATH_R_CHIPREVMINOR_SHIFT;
  694. if ((chiprev & INFINIPATH_R_CHIPREVMINOR_MASK) > 1) {
  695. /* Rev2+ reports extra errors via internal GPIO pins */
  696. dd->ipath_flags |= IPATH_GPIO_ERRINTRS;
  697. dd->ipath_gpio_mask |= IPATH_GPIO_ERRINTR_MASK;
  698. ipath_write_kreg(dd, dd->ipath_kregs->kr_gpio_mask,
  699. dd->ipath_gpio_mask);
  700. }
  701. return 0;
  702. }
  703. /**
  704. * ipath_setup_pe_setextled - set the state of the two external LEDs
  705. * @dd: the infinipath device
  706. * @lst: the L state
  707. * @ltst: the LT state
  708. * These LEDs indicate the physical and logical state of IB link.
  709. * For this chip (at least with recommended board pinouts), LED1
  710. * is Yellow (logical state) and LED2 is Green (physical state),
  711. *
  712. * Note: We try to match the Mellanox HCA LED behavior as best
  713. * we can. Green indicates physical link state is OK (something is
  714. * plugged in, and we can train).
  715. * Amber indicates the link is logically up (ACTIVE).
  716. * Mellanox further blinks the amber LED to indicate data packet
  717. * activity, but we have no hardware support for that, so it would
  718. * require waking up every 10-20 msecs and checking the counters
  719. * on the chip, and then turning the LED off if appropriate. That's
  720. * visible overhead, so not something we will do.
  721. *
  722. */
  723. static void ipath_setup_pe_setextled(struct ipath_devdata *dd, u64 lst,
  724. u64 ltst)
  725. {
  726. u64 extctl;
  727. unsigned long flags = 0;
  728. /* the diags use the LED to indicate diag info, so we leave
  729. * the external LED alone when the diags are running */
  730. if (ipath_diag_inuse)
  731. return;
  732. /* Allow override of LED display for, e.g. Locating system in rack */
  733. if (dd->ipath_led_override) {
  734. ltst = (dd->ipath_led_override & IPATH_LED_PHYS)
  735. ? INFINIPATH_IBCS_LT_STATE_LINKUP
  736. : INFINIPATH_IBCS_LT_STATE_DISABLED;
  737. lst = (dd->ipath_led_override & IPATH_LED_LOG)
  738. ? INFINIPATH_IBCS_L_STATE_ACTIVE
  739. : INFINIPATH_IBCS_L_STATE_DOWN;
  740. }
  741. spin_lock_irqsave(&dd->ipath_gpio_lock, flags);
  742. extctl = dd->ipath_extctrl & ~(INFINIPATH_EXTC_LED1PRIPORT_ON |
  743. INFINIPATH_EXTC_LED2PRIPORT_ON);
  744. if (ltst & INFINIPATH_IBCS_LT_STATE_LINKUP)
  745. extctl |= INFINIPATH_EXTC_LED2PRIPORT_ON;
  746. if (lst == INFINIPATH_IBCS_L_STATE_ACTIVE)
  747. extctl |= INFINIPATH_EXTC_LED1PRIPORT_ON;
  748. dd->ipath_extctrl = extctl;
  749. ipath_write_kreg(dd, dd->ipath_kregs->kr_extctrl, extctl);
  750. spin_unlock_irqrestore(&dd->ipath_gpio_lock, flags);
  751. }
  752. /**
  753. * ipath_setup_pe_cleanup - clean up any per-chip chip-specific stuff
  754. * @dd: the infinipath device
  755. *
  756. * This is called during driver unload.
  757. * We do the pci_disable_msi here, not in generic code, because it
  758. * isn't used for the HT chips. If we do end up needing pci_enable_msi
  759. * at some point in the future for HT, we'll move the call back
  760. * into the main init_one code.
  761. */
  762. static void ipath_setup_pe_cleanup(struct ipath_devdata *dd)
  763. {
  764. dd->ipath_msi_lo = 0; /* just in case unload fails */
  765. pci_disable_msi(dd->pcidev);
  766. }
  767. /**
  768. * ipath_setup_pe_config - setup PCIe config related stuff
  769. * @dd: the infinipath device
  770. * @pdev: the PCI device
  771. *
  772. * The pci_enable_msi() call will fail on systems with MSI quirks
  773. * such as those with AMD8131, even if the device of interest is not
  774. * attached to that device, (in the 2.6.13 - 2.6.15 kernels, at least, fixed
  775. * late in 2.6.16).
  776. * All that can be done is to edit the kernel source to remove the quirk
  777. * check until that is fixed.
  778. * We do not need to call enable_msi() for our HyperTransport chip,
  779. * even though it uses MSI, and we want to avoid the quirk warning, so
  780. * So we call enable_msi only for PCIe. If we do end up needing
  781. * pci_enable_msi at some point in the future for HT, we'll move the
  782. * call back into the main init_one code.
  783. * We save the msi lo and hi values, so we can restore them after
  784. * chip reset (the kernel PCI infrastructure doesn't yet handle that
  785. * correctly).
  786. */
  787. static int ipath_setup_pe_config(struct ipath_devdata *dd,
  788. struct pci_dev *pdev)
  789. {
  790. int pos, ret;
  791. dd->ipath_msi_lo = 0; /* used as a flag during reset processing */
  792. ret = pci_enable_msi(dd->pcidev);
  793. if (ret)
  794. ipath_dev_err(dd, "pci_enable_msi failed: %d, "
  795. "interrupts may not work\n", ret);
  796. /* continue even if it fails, we may still be OK... */
  797. dd->ipath_irq = pdev->irq;
  798. if ((pos = pci_find_capability(dd->pcidev, PCI_CAP_ID_MSI))) {
  799. u16 control;
  800. pci_read_config_dword(dd->pcidev, pos + PCI_MSI_ADDRESS_LO,
  801. &dd->ipath_msi_lo);
  802. pci_read_config_dword(dd->pcidev, pos + PCI_MSI_ADDRESS_HI,
  803. &dd->ipath_msi_hi);
  804. pci_read_config_word(dd->pcidev, pos + PCI_MSI_FLAGS,
  805. &control);
  806. /* now save the data (vector) info */
  807. pci_read_config_word(dd->pcidev,
  808. pos + ((control & PCI_MSI_FLAGS_64BIT)
  809. ? 12 : 8),
  810. &dd->ipath_msi_data);
  811. ipath_cdbg(VERBOSE, "Read msi data 0x%x from config offset "
  812. "0x%x, control=0x%x\n", dd->ipath_msi_data,
  813. pos + ((control & PCI_MSI_FLAGS_64BIT) ? 12 : 8),
  814. control);
  815. /* we save the cachelinesize also, although it doesn't
  816. * really matter */
  817. pci_read_config_byte(dd->pcidev, PCI_CACHE_LINE_SIZE,
  818. &dd->ipath_pci_cacheline);
  819. } else
  820. ipath_dev_err(dd, "Can't find MSI capability, "
  821. "can't save MSI settings for reset\n");
  822. if ((pos = pci_find_capability(dd->pcidev, PCI_CAP_ID_EXP))) {
  823. u16 linkstat;
  824. pci_read_config_word(dd->pcidev, pos + PCI_EXP_LNKSTA,
  825. &linkstat);
  826. linkstat >>= 4;
  827. linkstat &= 0x1f;
  828. if (linkstat != 8)
  829. ipath_dev_err(dd, "PCIe width %u, "
  830. "performance reduced\n", linkstat);
  831. }
  832. else
  833. ipath_dev_err(dd, "Can't find PCI Express "
  834. "capability!\n");
  835. return 0;
  836. }
  837. static void ipath_init_pe_variables(struct ipath_devdata *dd)
  838. {
  839. /*
  840. * bits for selecting i2c direction and values,
  841. * used for I2C serial flash
  842. */
  843. dd->ipath_gpio_sda_num = _IPATH_GPIO_SDA_NUM;
  844. dd->ipath_gpio_scl_num = _IPATH_GPIO_SCL_NUM;
  845. dd->ipath_gpio_sda = IPATH_GPIO_SDA;
  846. dd->ipath_gpio_scl = IPATH_GPIO_SCL;
  847. /* Fill in shifts for RcvCtrl. */
  848. dd->ipath_r_portenable_shift = INFINIPATH_R_PORTENABLE_SHIFT;
  849. dd->ipath_r_intravail_shift = INFINIPATH_R_INTRAVAIL_SHIFT;
  850. dd->ipath_r_tailupd_shift = INFINIPATH_R_TAILUPD_SHIFT;
  851. dd->ipath_r_portcfg_shift = 0; /* Not on IBA6120 */
  852. /* variables for sanity checking interrupt and errors */
  853. dd->ipath_hwe_bitsextant =
  854. (INFINIPATH_HWE_RXEMEMPARITYERR_MASK <<
  855. INFINIPATH_HWE_RXEMEMPARITYERR_SHIFT) |
  856. (INFINIPATH_HWE_TXEMEMPARITYERR_MASK <<
  857. INFINIPATH_HWE_TXEMEMPARITYERR_SHIFT) |
  858. (INFINIPATH_HWE_PCIEMEMPARITYERR_MASK <<
  859. INFINIPATH_HWE_PCIEMEMPARITYERR_SHIFT) |
  860. INFINIPATH_HWE_PCIE1PLLFAILED |
  861. INFINIPATH_HWE_PCIE0PLLFAILED |
  862. INFINIPATH_HWE_PCIEPOISONEDTLP |
  863. INFINIPATH_HWE_PCIECPLTIMEOUT |
  864. INFINIPATH_HWE_PCIEBUSPARITYXTLH |
  865. INFINIPATH_HWE_PCIEBUSPARITYXADM |
  866. INFINIPATH_HWE_PCIEBUSPARITYRADM |
  867. INFINIPATH_HWE_MEMBISTFAILED |
  868. INFINIPATH_HWE_COREPLL_FBSLIP |
  869. INFINIPATH_HWE_COREPLL_RFSLIP |
  870. INFINIPATH_HWE_SERDESPLLFAILED |
  871. INFINIPATH_HWE_IBCBUSTOSPCPARITYERR |
  872. INFINIPATH_HWE_IBCBUSFRSPCPARITYERR;
  873. dd->ipath_i_bitsextant =
  874. (INFINIPATH_I_RCVURG_MASK << INFINIPATH_I_RCVURG_SHIFT) |
  875. (INFINIPATH_I_RCVAVAIL_MASK <<
  876. INFINIPATH_I_RCVAVAIL_SHIFT) |
  877. INFINIPATH_I_ERROR | INFINIPATH_I_SPIOSENT |
  878. INFINIPATH_I_SPIOBUFAVAIL | INFINIPATH_I_GPIO;
  879. dd->ipath_e_bitsextant =
  880. INFINIPATH_E_RFORMATERR | INFINIPATH_E_RVCRC |
  881. INFINIPATH_E_RICRC | INFINIPATH_E_RMINPKTLEN |
  882. INFINIPATH_E_RMAXPKTLEN | INFINIPATH_E_RLONGPKTLEN |
  883. INFINIPATH_E_RSHORTPKTLEN | INFINIPATH_E_RUNEXPCHAR |
  884. INFINIPATH_E_RUNSUPVL | INFINIPATH_E_REBP |
  885. INFINIPATH_E_RIBFLOW | INFINIPATH_E_RBADVERSION |
  886. INFINIPATH_E_RRCVEGRFULL | INFINIPATH_E_RRCVHDRFULL |
  887. INFINIPATH_E_RBADTID | INFINIPATH_E_RHDRLEN |
  888. INFINIPATH_E_RHDR | INFINIPATH_E_RIBLOSTLINK |
  889. INFINIPATH_E_SMINPKTLEN | INFINIPATH_E_SMAXPKTLEN |
  890. INFINIPATH_E_SUNDERRUN | INFINIPATH_E_SPKTLEN |
  891. INFINIPATH_E_SDROPPEDSMPPKT | INFINIPATH_E_SDROPPEDDATAPKT |
  892. INFINIPATH_E_SPIOARMLAUNCH | INFINIPATH_E_SUNEXPERRPKTNUM |
  893. INFINIPATH_E_SUNSUPVL | INFINIPATH_E_IBSTATUSCHANGED |
  894. INFINIPATH_E_INVALIDADDR | INFINIPATH_E_RESET |
  895. INFINIPATH_E_HARDWARE;
  896. dd->ipath_i_rcvavail_mask = INFINIPATH_I_RCVAVAIL_MASK;
  897. dd->ipath_i_rcvurg_mask = INFINIPATH_I_RCVURG_MASK;
  898. /*
  899. * EEPROM error log 0 is TXE Parity errors. 1 is RXE Parity.
  900. * 2 is Some Misc, 3 is reserved for future.
  901. */
  902. dd->ipath_eep_st_masks[0].hwerrs_to_log =
  903. INFINIPATH_HWE_TXEMEMPARITYERR_MASK <<
  904. INFINIPATH_HWE_TXEMEMPARITYERR_SHIFT;
  905. /* Ignore errors in PIO/PBC on systems with unordered write-combining */
  906. if (ipath_unordered_wc())
  907. dd->ipath_eep_st_masks[0].hwerrs_to_log &= ~TXE_PIO_PARITY;
  908. dd->ipath_eep_st_masks[1].hwerrs_to_log =
  909. INFINIPATH_HWE_RXEMEMPARITYERR_MASK <<
  910. INFINIPATH_HWE_RXEMEMPARITYERR_SHIFT;
  911. dd->ipath_eep_st_masks[2].errs_to_log =
  912. INFINIPATH_E_INVALIDADDR | INFINIPATH_E_RESET;
  913. }
  914. /* setup the MSI stuff again after a reset. I'd like to just call
  915. * pci_enable_msi() and request_irq() again, but when I do that,
  916. * the MSI enable bit doesn't get set in the command word, and
  917. * we switch to to a different interrupt vector, which is confusing,
  918. * so I instead just do it all inline. Perhaps somehow can tie this
  919. * into the PCIe hotplug support at some point
  920. * Note, because I'm doing it all here, I don't call pci_disable_msi()
  921. * or free_irq() at the start of ipath_setup_pe_reset().
  922. */
  923. static int ipath_reinit_msi(struct ipath_devdata *dd)
  924. {
  925. int pos;
  926. u16 control;
  927. int ret;
  928. if (!dd->ipath_msi_lo) {
  929. dev_info(&dd->pcidev->dev, "Can't restore MSI config, "
  930. "initial setup failed?\n");
  931. ret = 0;
  932. goto bail;
  933. }
  934. if (!(pos = pci_find_capability(dd->pcidev, PCI_CAP_ID_MSI))) {
  935. ipath_dev_err(dd, "Can't find MSI capability, "
  936. "can't restore MSI settings\n");
  937. ret = 0;
  938. goto bail;
  939. }
  940. ipath_cdbg(VERBOSE, "Writing msi_lo 0x%x to config offset 0x%x\n",
  941. dd->ipath_msi_lo, pos + PCI_MSI_ADDRESS_LO);
  942. pci_write_config_dword(dd->pcidev, pos + PCI_MSI_ADDRESS_LO,
  943. dd->ipath_msi_lo);
  944. ipath_cdbg(VERBOSE, "Writing msi_lo 0x%x to config offset 0x%x\n",
  945. dd->ipath_msi_hi, pos + PCI_MSI_ADDRESS_HI);
  946. pci_write_config_dword(dd->pcidev, pos + PCI_MSI_ADDRESS_HI,
  947. dd->ipath_msi_hi);
  948. pci_read_config_word(dd->pcidev, pos + PCI_MSI_FLAGS, &control);
  949. if (!(control & PCI_MSI_FLAGS_ENABLE)) {
  950. ipath_cdbg(VERBOSE, "MSI control at off %x was %x, "
  951. "setting MSI enable (%x)\n", pos + PCI_MSI_FLAGS,
  952. control, control | PCI_MSI_FLAGS_ENABLE);
  953. control |= PCI_MSI_FLAGS_ENABLE;
  954. pci_write_config_word(dd->pcidev, pos + PCI_MSI_FLAGS,
  955. control);
  956. }
  957. /* now rewrite the data (vector) info */
  958. pci_write_config_word(dd->pcidev, pos +
  959. ((control & PCI_MSI_FLAGS_64BIT) ? 12 : 8),
  960. dd->ipath_msi_data);
  961. /* we restore the cachelinesize also, although it doesn't really
  962. * matter */
  963. pci_write_config_byte(dd->pcidev, PCI_CACHE_LINE_SIZE,
  964. dd->ipath_pci_cacheline);
  965. /* and now set the pci master bit again */
  966. pci_set_master(dd->pcidev);
  967. ret = 1;
  968. bail:
  969. return ret;
  970. }
  971. /* This routine sleeps, so it can only be called from user context, not
  972. * from interrupt context. If we need interrupt context, we can split
  973. * it into two routines.
  974. */
  975. static int ipath_setup_pe_reset(struct ipath_devdata *dd)
  976. {
  977. u64 val;
  978. int i;
  979. int ret;
  980. /* Use ERROR so it shows up in logs, etc. */
  981. ipath_dev_err(dd, "Resetting InfiniPath unit %u\n", dd->ipath_unit);
  982. /* keep chip from being accessed in a few places */
  983. dd->ipath_flags &= ~(IPATH_INITTED|IPATH_PRESENT);
  984. val = dd->ipath_control | INFINIPATH_C_RESET;
  985. ipath_write_kreg(dd, dd->ipath_kregs->kr_control, val);
  986. mb();
  987. for (i = 1; i <= 5; i++) {
  988. int r;
  989. /* allow MBIST, etc. to complete; longer on each retry.
  990. * We sometimes get machine checks from bus timeout if no
  991. * response, so for now, make it *really* long.
  992. */
  993. msleep(1000 + (1 + i) * 2000);
  994. if ((r =
  995. pci_write_config_dword(dd->pcidev, PCI_BASE_ADDRESS_0,
  996. dd->ipath_pcibar0)))
  997. ipath_dev_err(dd, "rewrite of BAR0 failed: %d\n",
  998. r);
  999. if ((r =
  1000. pci_write_config_dword(dd->pcidev, PCI_BASE_ADDRESS_1,
  1001. dd->ipath_pcibar1)))
  1002. ipath_dev_err(dd, "rewrite of BAR1 failed: %d\n",
  1003. r);
  1004. /* now re-enable memory access */
  1005. if ((r = pci_enable_device(dd->pcidev)))
  1006. ipath_dev_err(dd, "pci_enable_device failed after "
  1007. "reset: %d\n", r);
  1008. /* whether it worked or not, mark as present, again */
  1009. dd->ipath_flags |= IPATH_PRESENT;
  1010. val = ipath_read_kreg64(dd, dd->ipath_kregs->kr_revision);
  1011. if (val == dd->ipath_revision) {
  1012. ipath_cdbg(VERBOSE, "Got matching revision "
  1013. "register %llx on try %d\n",
  1014. (unsigned long long) val, i);
  1015. ret = ipath_reinit_msi(dd);
  1016. goto bail;
  1017. }
  1018. /* Probably getting -1 back */
  1019. ipath_dbg("Didn't get expected revision register, "
  1020. "got %llx, try %d\n", (unsigned long long) val,
  1021. i + 1);
  1022. }
  1023. ret = 0; /* failed */
  1024. bail:
  1025. return ret;
  1026. }
  1027. /**
  1028. * ipath_pe_put_tid - write a TID in chip
  1029. * @dd: the infinipath device
  1030. * @tidptr: pointer to the expected TID (in chip) to udpate
  1031. * @tidtype: RCVHQ_RCV_TYPE_EAGER (1) for eager, RCVHQ_RCV_TYPE_EXPECTED (0) for expected
  1032. * @pa: physical address of in memory buffer; ipath_tidinvalid if freeing
  1033. *
  1034. * This exists as a separate routine to allow for special locking etc.
  1035. * It's used for both the full cleanup on exit, as well as the normal
  1036. * setup and teardown.
  1037. */
  1038. static void ipath_pe_put_tid(struct ipath_devdata *dd, u64 __iomem *tidptr,
  1039. u32 type, unsigned long pa)
  1040. {
  1041. u32 __iomem *tidp32 = (u32 __iomem *)tidptr;
  1042. unsigned long flags = 0; /* keep gcc quiet */
  1043. if (pa != dd->ipath_tidinvalid) {
  1044. if (pa & ((1U << 11) - 1)) {
  1045. dev_info(&dd->pcidev->dev, "BUG: physaddr %lx "
  1046. "not 4KB aligned!\n", pa);
  1047. return;
  1048. }
  1049. pa >>= 11;
  1050. /* paranoia check */
  1051. if (pa & (7<<29))
  1052. ipath_dev_err(dd,
  1053. "BUG: Physical page address 0x%lx "
  1054. "has bits set in 31-29\n", pa);
  1055. if (type == RCVHQ_RCV_TYPE_EAGER)
  1056. pa |= dd->ipath_tidtemplate;
  1057. else /* for now, always full 4KB page */
  1058. pa |= 2 << 29;
  1059. }
  1060. /*
  1061. * Workaround chip bug 9437 by writing the scratch register
  1062. * before and after the TID, and with an io write barrier.
  1063. * We use a spinlock around the writes, so they can't intermix
  1064. * with other TID (eager or expected) writes (the chip bug
  1065. * is triggered by back to back TID writes). Unfortunately, this
  1066. * call can be done from interrupt level for the port 0 eager TIDs,
  1067. * so we have to use irqsave locks.
  1068. */
  1069. spin_lock_irqsave(&dd->ipath_tid_lock, flags);
  1070. ipath_write_kreg(dd, dd->ipath_kregs->kr_scratch, 0xfeeddeaf);
  1071. if (dd->ipath_kregbase)
  1072. writel(pa, tidp32);
  1073. ipath_write_kreg(dd, dd->ipath_kregs->kr_scratch, 0xdeadbeef);
  1074. mmiowb();
  1075. spin_unlock_irqrestore(&dd->ipath_tid_lock, flags);
  1076. }
  1077. /**
  1078. * ipath_pe_put_tid_2 - write a TID in chip, Revision 2 or higher
  1079. * @dd: the infinipath device
  1080. * @tidptr: pointer to the expected TID (in chip) to udpate
  1081. * @tidtype: RCVHQ_RCV_TYPE_EAGER (1) for eager, RCVHQ_RCV_TYPE_EXPECTED (0) for expected
  1082. * @pa: physical address of in memory buffer; ipath_tidinvalid if freeing
  1083. *
  1084. * This exists as a separate routine to allow for selection of the
  1085. * appropriate "flavor". The static calls in cleanup just use the
  1086. * revision-agnostic form, as they are not performance critical.
  1087. */
  1088. static void ipath_pe_put_tid_2(struct ipath_devdata *dd, u64 __iomem *tidptr,
  1089. u32 type, unsigned long pa)
  1090. {
  1091. u32 __iomem *tidp32 = (u32 __iomem *)tidptr;
  1092. if (pa != dd->ipath_tidinvalid) {
  1093. if (pa & ((1U << 11) - 1)) {
  1094. dev_info(&dd->pcidev->dev, "BUG: physaddr %lx "
  1095. "not 2KB aligned!\n", pa);
  1096. return;
  1097. }
  1098. pa >>= 11;
  1099. /* paranoia check */
  1100. if (pa & (7<<29))
  1101. ipath_dev_err(dd,
  1102. "BUG: Physical page address 0x%lx "
  1103. "has bits set in 31-29\n", pa);
  1104. if (type == RCVHQ_RCV_TYPE_EAGER)
  1105. pa |= dd->ipath_tidtemplate;
  1106. else /* for now, always full 4KB page */
  1107. pa |= 2 << 29;
  1108. }
  1109. if (dd->ipath_kregbase)
  1110. writel(pa, tidp32);
  1111. mmiowb();
  1112. }
  1113. /**
  1114. * ipath_pe_clear_tid - clear all TID entries for a port, expected and eager
  1115. * @dd: the infinipath device
  1116. * @port: the port
  1117. *
  1118. * clear all TID entries for a port, expected and eager.
  1119. * Used from ipath_close(). On this chip, TIDs are only 32 bits,
  1120. * not 64, but they are still on 64 bit boundaries, so tidbase
  1121. * is declared as u64 * for the pointer math, even though we write 32 bits
  1122. */
  1123. static void ipath_pe_clear_tids(struct ipath_devdata *dd, unsigned port)
  1124. {
  1125. u64 __iomem *tidbase;
  1126. unsigned long tidinv;
  1127. int i;
  1128. if (!dd->ipath_kregbase)
  1129. return;
  1130. ipath_cdbg(VERBOSE, "Invalidate TIDs for port %u\n", port);
  1131. tidinv = dd->ipath_tidinvalid;
  1132. tidbase = (u64 __iomem *)
  1133. ((char __iomem *)(dd->ipath_kregbase) +
  1134. dd->ipath_rcvtidbase +
  1135. port * dd->ipath_rcvtidcnt * sizeof(*tidbase));
  1136. for (i = 0; i < dd->ipath_rcvtidcnt; i++)
  1137. dd->ipath_f_put_tid(dd, &tidbase[i], RCVHQ_RCV_TYPE_EXPECTED,
  1138. tidinv);
  1139. tidbase = (u64 __iomem *)
  1140. ((char __iomem *)(dd->ipath_kregbase) +
  1141. dd->ipath_rcvegrbase +
  1142. port * dd->ipath_rcvegrcnt * sizeof(*tidbase));
  1143. for (i = 0; i < dd->ipath_rcvegrcnt; i++)
  1144. dd->ipath_f_put_tid(dd, &tidbase[i], RCVHQ_RCV_TYPE_EAGER,
  1145. tidinv);
  1146. }
  1147. /**
  1148. * ipath_pe_tidtemplate - setup constants for TID updates
  1149. * @dd: the infinipath device
  1150. *
  1151. * We setup stuff that we use a lot, to avoid calculating each time
  1152. */
  1153. static void ipath_pe_tidtemplate(struct ipath_devdata *dd)
  1154. {
  1155. u32 egrsize = dd->ipath_rcvegrbufsize;
  1156. /* For now, we always allocate 4KB buffers (at init) so we can
  1157. * receive max size packets. We may want a module parameter to
  1158. * specify 2KB or 4KB and/or make be per port instead of per device
  1159. * for those who want to reduce memory footprint. Note that the
  1160. * ipath_rcvhdrentsize size must be large enough to hold the largest
  1161. * IB header (currently 96 bytes) that we expect to handle (plus of
  1162. * course the 2 dwords of RHF).
  1163. */
  1164. if (egrsize == 2048)
  1165. dd->ipath_tidtemplate = 1U << 29;
  1166. else if (egrsize == 4096)
  1167. dd->ipath_tidtemplate = 2U << 29;
  1168. else {
  1169. egrsize = 4096;
  1170. dev_info(&dd->pcidev->dev, "BUG: unsupported egrbufsize "
  1171. "%u, using %u\n", dd->ipath_rcvegrbufsize,
  1172. egrsize);
  1173. dd->ipath_tidtemplate = 2U << 29;
  1174. }
  1175. dd->ipath_tidinvalid = 0;
  1176. }
  1177. static int ipath_pe_early_init(struct ipath_devdata *dd)
  1178. {
  1179. dd->ipath_flags |= IPATH_4BYTE_TID;
  1180. if (ipath_unordered_wc())
  1181. dd->ipath_flags |= IPATH_PIO_FLUSH_WC;
  1182. /*
  1183. * For openfabrics, we need to be able to handle an IB header of
  1184. * 24 dwords. HT chip has arbitrary sized receive buffers, so we
  1185. * made them the same size as the PIO buffers. This chip does not
  1186. * handle arbitrary size buffers, so we need the header large enough
  1187. * to handle largest IB header, but still have room for a 2KB MTU
  1188. * standard IB packet.
  1189. */
  1190. dd->ipath_rcvhdrentsize = 24;
  1191. dd->ipath_rcvhdrsize = IPATH_DFLT_RCVHDRSIZE;
  1192. /*
  1193. * To truly support a 4KB MTU (for usermode), we need to
  1194. * bump this to a larger value. For now, we use them for
  1195. * the kernel only.
  1196. */
  1197. dd->ipath_rcvegrbufsize = 2048;
  1198. /*
  1199. * the min() check here is currently a nop, but it may not always
  1200. * be, depending on just how we do ipath_rcvegrbufsize
  1201. */
  1202. dd->ipath_ibmaxlen = min(dd->ipath_piosize2k,
  1203. dd->ipath_rcvegrbufsize +
  1204. (dd->ipath_rcvhdrentsize << 2));
  1205. dd->ipath_init_ibmaxlen = dd->ipath_ibmaxlen;
  1206. /*
  1207. * We can request a receive interrupt for 1 or
  1208. * more packets from current offset. For now, we set this
  1209. * up for a single packet.
  1210. */
  1211. dd->ipath_rhdrhead_intr_off = 1ULL<<32;
  1212. ipath_get_eeprom_info(dd);
  1213. return 0;
  1214. }
  1215. int __attribute__((weak)) ipath_unordered_wc(void)
  1216. {
  1217. return 0;
  1218. }
  1219. /**
  1220. * ipath_init_pe_get_base_info - set chip-specific flags for user code
  1221. * @pd: the infinipath port
  1222. * @kbase: ipath_base_info pointer
  1223. *
  1224. * We set the PCIE flag because the lower bandwidth on PCIe vs
  1225. * HyperTransport can affect some user packet algorithms.
  1226. */
  1227. static int ipath_pe_get_base_info(struct ipath_portdata *pd, void *kbase)
  1228. {
  1229. struct ipath_base_info *kinfo = kbase;
  1230. struct ipath_devdata *dd;
  1231. if (ipath_unordered_wc()) {
  1232. kinfo->spi_runtime_flags |= IPATH_RUNTIME_FORCE_WC_ORDER;
  1233. ipath_cdbg(PROC, "Intel processor, forcing WC order\n");
  1234. }
  1235. else
  1236. ipath_cdbg(PROC, "Not Intel processor, WC ordered\n");
  1237. if (pd == NULL)
  1238. goto done;
  1239. dd = pd->port_dd;
  1240. done:
  1241. kinfo->spi_runtime_flags |= IPATH_RUNTIME_PCIE |
  1242. IPATH_RUNTIME_FORCE_PIOAVAIL | IPATH_RUNTIME_PIO_REGSWAPPED;
  1243. return 0;
  1244. }
  1245. static void ipath_pe_free_irq(struct ipath_devdata *dd)
  1246. {
  1247. free_irq(dd->ipath_irq, dd);
  1248. dd->ipath_irq = 0;
  1249. }
  1250. /*
  1251. * On platforms using this chip, and not having ordered WC stores, we
  1252. * can get TXE parity errors due to speculative reads to the PIO buffers,
  1253. * and this, due to a chip bug can result in (many) false parity error
  1254. * reports. So it's a debug print on those, and an info print on systems
  1255. * where the speculative reads don't occur.
  1256. * Because we can get lots of false errors, we have no upper limit
  1257. * on recovery attempts on those platforms.
  1258. */
  1259. static int ipath_pe_txe_recover(struct ipath_devdata *dd)
  1260. {
  1261. if (ipath_unordered_wc())
  1262. ipath_dbg("Recovering from TXE PIO parity error\n");
  1263. else {
  1264. int cnt = ++ipath_stats.sps_txeparity;
  1265. if (cnt >= IPATH_MAX_PARITY_ATTEMPTS) {
  1266. if (cnt == IPATH_MAX_PARITY_ATTEMPTS)
  1267. ipath_dev_err(dd,
  1268. "Too many attempts to recover from "
  1269. "TXE parity, giving up\n");
  1270. return 0;
  1271. }
  1272. dev_info(&dd->pcidev->dev,
  1273. "Recovering from TXE PIO parity error\n");
  1274. }
  1275. return 1;
  1276. }
  1277. /**
  1278. * ipath_init_iba6120_funcs - set up the chip-specific function pointers
  1279. * @dd: the infinipath device
  1280. *
  1281. * This is global, and is called directly at init to set up the
  1282. * chip-specific function pointers for later use.
  1283. */
  1284. void ipath_init_iba6120_funcs(struct ipath_devdata *dd)
  1285. {
  1286. dd->ipath_f_intrsetup = ipath_pe_intconfig;
  1287. dd->ipath_f_bus = ipath_setup_pe_config;
  1288. dd->ipath_f_reset = ipath_setup_pe_reset;
  1289. dd->ipath_f_get_boardname = ipath_pe_boardname;
  1290. dd->ipath_f_init_hwerrors = ipath_pe_init_hwerrors;
  1291. dd->ipath_f_early_init = ipath_pe_early_init;
  1292. dd->ipath_f_handle_hwerrors = ipath_pe_handle_hwerrors;
  1293. dd->ipath_f_quiet_serdes = ipath_pe_quiet_serdes;
  1294. dd->ipath_f_bringup_serdes = ipath_pe_bringup_serdes;
  1295. dd->ipath_f_clear_tids = ipath_pe_clear_tids;
  1296. /*
  1297. * this may get changed after we read the chip revision,
  1298. * but we start with the safe version for all revs
  1299. */
  1300. dd->ipath_f_put_tid = ipath_pe_put_tid;
  1301. dd->ipath_f_cleanup = ipath_setup_pe_cleanup;
  1302. dd->ipath_f_setextled = ipath_setup_pe_setextled;
  1303. dd->ipath_f_get_base_info = ipath_pe_get_base_info;
  1304. dd->ipath_f_free_irq = ipath_pe_free_irq;
  1305. /* initialize chip-specific variables */
  1306. dd->ipath_f_tidtemplate = ipath_pe_tidtemplate;
  1307. /*
  1308. * setup the register offsets, since they are different for each
  1309. * chip
  1310. */
  1311. dd->ipath_kregs = &ipath_pe_kregs;
  1312. dd->ipath_cregs = &ipath_pe_cregs;
  1313. ipath_init_pe_variables(dd);
  1314. }