ipath_iba6120.c 54 KB

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