ipath_iba6110.c 53 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667
  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 InfiniPath
  35. * HT chip.
  36. */
  37. #include <linux/vmalloc.h>
  38. #include <linux/pci.h>
  39. #include <linux/delay.h>
  40. #include <linux/htirq.h>
  41. #include "ipath_kernel.h"
  42. #include "ipath_registers.h"
  43. static void ipath_setup_ht_setextled(struct ipath_devdata *, u64, u64);
  44. /*
  45. * This lists the InfiniPath registers, in the actual chip layout.
  46. * This structure should never be directly accessed.
  47. *
  48. * The names are in InterCap form because they're taken straight from
  49. * the chip specification. Since they're only used in this file, they
  50. * don't pollute the rest of the source.
  51. */
  52. struct _infinipath_do_not_use_kernel_regs {
  53. unsigned long long Revision;
  54. unsigned long long Control;
  55. unsigned long long PageAlign;
  56. unsigned long long PortCnt;
  57. unsigned long long DebugPortSelect;
  58. unsigned long long DebugPort;
  59. unsigned long long SendRegBase;
  60. unsigned long long UserRegBase;
  61. unsigned long long CounterRegBase;
  62. unsigned long long Scratch;
  63. unsigned long long ReservedMisc1;
  64. unsigned long long InterruptConfig;
  65. unsigned long long IntBlocked;
  66. unsigned long long IntMask;
  67. unsigned long long IntStatus;
  68. unsigned long long IntClear;
  69. unsigned long long ErrorMask;
  70. unsigned long long ErrorStatus;
  71. unsigned long long ErrorClear;
  72. unsigned long long HwErrMask;
  73. unsigned long long HwErrStatus;
  74. unsigned long long HwErrClear;
  75. unsigned long long HwDiagCtrl;
  76. unsigned long long MDIO;
  77. unsigned long long IBCStatus;
  78. unsigned long long IBCCtrl;
  79. unsigned long long ExtStatus;
  80. unsigned long long ExtCtrl;
  81. unsigned long long GPIOOut;
  82. unsigned long long GPIOMask;
  83. unsigned long long GPIOStatus;
  84. unsigned long long GPIOClear;
  85. unsigned long long RcvCtrl;
  86. unsigned long long RcvBTHQP;
  87. unsigned long long RcvHdrSize;
  88. unsigned long long RcvHdrCnt;
  89. unsigned long long RcvHdrEntSize;
  90. unsigned long long RcvTIDBase;
  91. unsigned long long RcvTIDCnt;
  92. unsigned long long RcvEgrBase;
  93. unsigned long long RcvEgrCnt;
  94. unsigned long long RcvBufBase;
  95. unsigned long long RcvBufSize;
  96. unsigned long long RxIntMemBase;
  97. unsigned long long RxIntMemSize;
  98. unsigned long long RcvPartitionKey;
  99. unsigned long long ReservedRcv[10];
  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 ReservedSend[9];
  108. unsigned long long SendBufferError;
  109. unsigned long long SendBufferErrorCONT1;
  110. unsigned long long SendBufferErrorCONT2;
  111. unsigned long long SendBufferErrorCONT3;
  112. unsigned long long ReservedSBE[4];
  113. unsigned long long RcvHdrAddr0;
  114. unsigned long long RcvHdrAddr1;
  115. unsigned long long RcvHdrAddr2;
  116. unsigned long long RcvHdrAddr3;
  117. unsigned long long RcvHdrAddr4;
  118. unsigned long long RcvHdrAddr5;
  119. unsigned long long RcvHdrAddr6;
  120. unsigned long long RcvHdrAddr7;
  121. unsigned long long RcvHdrAddr8;
  122. unsigned long long ReservedRHA[7];
  123. unsigned long long RcvHdrTailAddr0;
  124. unsigned long long RcvHdrTailAddr1;
  125. unsigned long long RcvHdrTailAddr2;
  126. unsigned long long RcvHdrTailAddr3;
  127. unsigned long long RcvHdrTailAddr4;
  128. unsigned long long RcvHdrTailAddr5;
  129. unsigned long long RcvHdrTailAddr6;
  130. unsigned long long RcvHdrTailAddr7;
  131. unsigned long long RcvHdrTailAddr8;
  132. unsigned long long ReservedRHTA[7];
  133. unsigned long long Sync; /* Software only */
  134. unsigned long long Dump; /* Software only */
  135. unsigned long long SimVer; /* Software only */
  136. unsigned long long ReservedSW[5];
  137. unsigned long long SerdesConfig0;
  138. unsigned long long SerdesConfig1;
  139. unsigned long long SerdesStatus;
  140. unsigned long long XGXSConfig;
  141. unsigned long long ReservedSW2[4];
  142. };
  143. #define IPATH_KREG_OFFSET(field) (offsetof(struct \
  144. _infinipath_do_not_use_kernel_regs, field) / sizeof(u64))
  145. #define IPATH_CREG_OFFSET(field) (offsetof( \
  146. struct infinipath_counters, field) / sizeof(u64))
  147. static const struct ipath_kregs ipath_ht_kregs = {
  148. .kr_control = IPATH_KREG_OFFSET(Control),
  149. .kr_counterregbase = IPATH_KREG_OFFSET(CounterRegBase),
  150. .kr_debugport = IPATH_KREG_OFFSET(DebugPort),
  151. .kr_debugportselect = IPATH_KREG_OFFSET(DebugPortSelect),
  152. .kr_errorclear = IPATH_KREG_OFFSET(ErrorClear),
  153. .kr_errormask = IPATH_KREG_OFFSET(ErrorMask),
  154. .kr_errorstatus = IPATH_KREG_OFFSET(ErrorStatus),
  155. .kr_extctrl = IPATH_KREG_OFFSET(ExtCtrl),
  156. .kr_extstatus = IPATH_KREG_OFFSET(ExtStatus),
  157. .kr_gpio_clear = IPATH_KREG_OFFSET(GPIOClear),
  158. .kr_gpio_mask = IPATH_KREG_OFFSET(GPIOMask),
  159. .kr_gpio_out = IPATH_KREG_OFFSET(GPIOOut),
  160. .kr_gpio_status = IPATH_KREG_OFFSET(GPIOStatus),
  161. .kr_hwdiagctrl = IPATH_KREG_OFFSET(HwDiagCtrl),
  162. .kr_hwerrclear = IPATH_KREG_OFFSET(HwErrClear),
  163. .kr_hwerrmask = IPATH_KREG_OFFSET(HwErrMask),
  164. .kr_hwerrstatus = IPATH_KREG_OFFSET(HwErrStatus),
  165. .kr_ibcctrl = IPATH_KREG_OFFSET(IBCCtrl),
  166. .kr_ibcstatus = IPATH_KREG_OFFSET(IBCStatus),
  167. .kr_intblocked = IPATH_KREG_OFFSET(IntBlocked),
  168. .kr_intclear = IPATH_KREG_OFFSET(IntClear),
  169. .kr_interruptconfig = IPATH_KREG_OFFSET(InterruptConfig),
  170. .kr_intmask = IPATH_KREG_OFFSET(IntMask),
  171. .kr_intstatus = IPATH_KREG_OFFSET(IntStatus),
  172. .kr_mdio = IPATH_KREG_OFFSET(MDIO),
  173. .kr_pagealign = IPATH_KREG_OFFSET(PageAlign),
  174. .kr_partitionkey = IPATH_KREG_OFFSET(RcvPartitionKey),
  175. .kr_portcnt = IPATH_KREG_OFFSET(PortCnt),
  176. .kr_rcvbthqp = IPATH_KREG_OFFSET(RcvBTHQP),
  177. .kr_rcvbufbase = IPATH_KREG_OFFSET(RcvBufBase),
  178. .kr_rcvbufsize = IPATH_KREG_OFFSET(RcvBufSize),
  179. .kr_rcvctrl = IPATH_KREG_OFFSET(RcvCtrl),
  180. .kr_rcvegrbase = IPATH_KREG_OFFSET(RcvEgrBase),
  181. .kr_rcvegrcnt = IPATH_KREG_OFFSET(RcvEgrCnt),
  182. .kr_rcvhdrcnt = IPATH_KREG_OFFSET(RcvHdrCnt),
  183. .kr_rcvhdrentsize = IPATH_KREG_OFFSET(RcvHdrEntSize),
  184. .kr_rcvhdrsize = IPATH_KREG_OFFSET(RcvHdrSize),
  185. .kr_rcvintmembase = IPATH_KREG_OFFSET(RxIntMemBase),
  186. .kr_rcvintmemsize = IPATH_KREG_OFFSET(RxIntMemSize),
  187. .kr_rcvtidbase = IPATH_KREG_OFFSET(RcvTIDBase),
  188. .kr_rcvtidcnt = IPATH_KREG_OFFSET(RcvTIDCnt),
  189. .kr_revision = IPATH_KREG_OFFSET(Revision),
  190. .kr_scratch = IPATH_KREG_OFFSET(Scratch),
  191. .kr_sendbuffererror = IPATH_KREG_OFFSET(SendBufferError),
  192. .kr_sendctrl = IPATH_KREG_OFFSET(SendCtrl),
  193. .kr_sendpioavailaddr = IPATH_KREG_OFFSET(SendPIOAvailAddr),
  194. .kr_sendpiobufbase = IPATH_KREG_OFFSET(SendPIOBufBase),
  195. .kr_sendpiobufcnt = IPATH_KREG_OFFSET(SendPIOBufCnt),
  196. .kr_sendpiosize = IPATH_KREG_OFFSET(SendPIOSize),
  197. .kr_sendregbase = IPATH_KREG_OFFSET(SendRegBase),
  198. .kr_txintmembase = IPATH_KREG_OFFSET(TxIntMemBase),
  199. .kr_txintmemsize = IPATH_KREG_OFFSET(TxIntMemSize),
  200. .kr_userregbase = IPATH_KREG_OFFSET(UserRegBase),
  201. .kr_serdesconfig0 = IPATH_KREG_OFFSET(SerdesConfig0),
  202. .kr_serdesconfig1 = IPATH_KREG_OFFSET(SerdesConfig1),
  203. .kr_serdesstatus = IPATH_KREG_OFFSET(SerdesStatus),
  204. .kr_xgxsconfig = IPATH_KREG_OFFSET(XGXSConfig),
  205. /*
  206. * These should not be used directly via ipath_write_kreg64(),
  207. * use them with ipath_write_kreg64_port(),
  208. */
  209. .kr_rcvhdraddr = IPATH_KREG_OFFSET(RcvHdrAddr0),
  210. .kr_rcvhdrtailaddr = IPATH_KREG_OFFSET(RcvHdrTailAddr0)
  211. };
  212. static const struct ipath_cregs ipath_ht_cregs = {
  213. .cr_badformatcnt = IPATH_CREG_OFFSET(RxBadFormatCnt),
  214. .cr_erricrccnt = IPATH_CREG_OFFSET(RxICRCErrCnt),
  215. .cr_errlinkcnt = IPATH_CREG_OFFSET(RxLinkProblemCnt),
  216. .cr_errlpcrccnt = IPATH_CREG_OFFSET(RxLPCRCErrCnt),
  217. .cr_errpkey = IPATH_CREG_OFFSET(RxPKeyMismatchCnt),
  218. .cr_errrcvflowctrlcnt = IPATH_CREG_OFFSET(RxFlowCtrlErrCnt),
  219. .cr_err_rlencnt = IPATH_CREG_OFFSET(RxLenErrCnt),
  220. .cr_errslencnt = IPATH_CREG_OFFSET(TxLenErrCnt),
  221. .cr_errtidfull = IPATH_CREG_OFFSET(RxTIDFullErrCnt),
  222. .cr_errtidvalid = IPATH_CREG_OFFSET(RxTIDValidErrCnt),
  223. .cr_errvcrccnt = IPATH_CREG_OFFSET(RxVCRCErrCnt),
  224. .cr_ibstatuschange = IPATH_CREG_OFFSET(IBStatusChangeCnt),
  225. /* calc from Reg_CounterRegBase + offset */
  226. .cr_intcnt = IPATH_CREG_OFFSET(LBIntCnt),
  227. .cr_invalidrlencnt = IPATH_CREG_OFFSET(RxMaxMinLenErrCnt),
  228. .cr_invalidslencnt = IPATH_CREG_OFFSET(TxMaxMinLenErrCnt),
  229. .cr_lbflowstallcnt = IPATH_CREG_OFFSET(LBFlowStallCnt),
  230. .cr_pktrcvcnt = IPATH_CREG_OFFSET(RxDataPktCnt),
  231. .cr_pktrcvflowctrlcnt = IPATH_CREG_OFFSET(RxFlowPktCnt),
  232. .cr_pktsendcnt = IPATH_CREG_OFFSET(TxDataPktCnt),
  233. .cr_pktsendflowcnt = IPATH_CREG_OFFSET(TxFlowPktCnt),
  234. .cr_portovflcnt = IPATH_CREG_OFFSET(RxP0HdrEgrOvflCnt),
  235. .cr_rcvebpcnt = IPATH_CREG_OFFSET(RxEBPCnt),
  236. .cr_rcvovflcnt = IPATH_CREG_OFFSET(RxBufOvflCnt),
  237. .cr_senddropped = IPATH_CREG_OFFSET(TxDroppedPktCnt),
  238. .cr_sendstallcnt = IPATH_CREG_OFFSET(TxFlowStallCnt),
  239. .cr_sendunderruncnt = IPATH_CREG_OFFSET(TxUnderrunCnt),
  240. .cr_wordrcvcnt = IPATH_CREG_OFFSET(RxDwordCnt),
  241. .cr_wordsendcnt = IPATH_CREG_OFFSET(TxDwordCnt),
  242. .cr_unsupvlcnt = IPATH_CREG_OFFSET(TxUnsupVLErrCnt),
  243. .cr_rxdroppktcnt = IPATH_CREG_OFFSET(RxDroppedPktCnt),
  244. .cr_iblinkerrrecovcnt = IPATH_CREG_OFFSET(IBLinkErrRecoveryCnt),
  245. .cr_iblinkdowncnt = IPATH_CREG_OFFSET(IBLinkDownedCnt),
  246. .cr_ibsymbolerrcnt = IPATH_CREG_OFFSET(IBSymbolErrCnt)
  247. };
  248. /* kr_intstatus, kr_intclear, kr_intmask bits */
  249. #define INFINIPATH_I_RCVURG_MASK ((1U<<9)-1)
  250. #define INFINIPATH_I_RCVAVAIL_MASK ((1U<<9)-1)
  251. /* kr_hwerrclear, kr_hwerrmask, kr_hwerrstatus, bits */
  252. #define INFINIPATH_HWE_HTCMEMPARITYERR_SHIFT 0
  253. #define INFINIPATH_HWE_HTCMEMPARITYERR_MASK 0x3FFFFFULL
  254. #define INFINIPATH_HWE_HTCLNKABYTE0CRCERR 0x0000000000800000ULL
  255. #define INFINIPATH_HWE_HTCLNKABYTE1CRCERR 0x0000000001000000ULL
  256. #define INFINIPATH_HWE_HTCLNKBBYTE0CRCERR 0x0000000002000000ULL
  257. #define INFINIPATH_HWE_HTCLNKBBYTE1CRCERR 0x0000000004000000ULL
  258. #define INFINIPATH_HWE_HTCMISCERR4 0x0000000008000000ULL
  259. #define INFINIPATH_HWE_HTCMISCERR5 0x0000000010000000ULL
  260. #define INFINIPATH_HWE_HTCMISCERR6 0x0000000020000000ULL
  261. #define INFINIPATH_HWE_HTCMISCERR7 0x0000000040000000ULL
  262. #define INFINIPATH_HWE_HTCBUSTREQPARITYERR 0x0000000080000000ULL
  263. #define INFINIPATH_HWE_HTCBUSTRESPPARITYERR 0x0000000100000000ULL
  264. #define INFINIPATH_HWE_HTCBUSIREQPARITYERR 0x0000000200000000ULL
  265. #define INFINIPATH_HWE_COREPLL_FBSLIP 0x0080000000000000ULL
  266. #define INFINIPATH_HWE_COREPLL_RFSLIP 0x0100000000000000ULL
  267. #define INFINIPATH_HWE_HTBPLL_FBSLIP 0x0200000000000000ULL
  268. #define INFINIPATH_HWE_HTBPLL_RFSLIP 0x0400000000000000ULL
  269. #define INFINIPATH_HWE_HTAPLL_FBSLIP 0x0800000000000000ULL
  270. #define INFINIPATH_HWE_HTAPLL_RFSLIP 0x1000000000000000ULL
  271. #define INFINIPATH_HWE_SERDESPLLFAILED 0x2000000000000000ULL
  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_CORRECT 0x0000000000008000
  277. /* TID entries (memory), HT-only */
  278. #define INFINIPATH_RT_ADDR_MASK 0xFFFFFFFFFFULL /* 40 bits valid */
  279. #define INFINIPATH_RT_VALID 0x8000000000000000ULL
  280. #define INFINIPATH_RT_ADDR_SHIFT 0
  281. #define INFINIPATH_RT_BUFSIZE_MASK 0x3FFFULL
  282. #define INFINIPATH_RT_BUFSIZE_SHIFT 48
  283. /*
  284. * masks and bits that are different in different chips, or present only
  285. * in one
  286. */
  287. static const ipath_err_t infinipath_hwe_htcmemparityerr_mask =
  288. INFINIPATH_HWE_HTCMEMPARITYERR_MASK;
  289. static const ipath_err_t infinipath_hwe_htcmemparityerr_shift =
  290. INFINIPATH_HWE_HTCMEMPARITYERR_SHIFT;
  291. static const ipath_err_t infinipath_hwe_htclnkabyte0crcerr =
  292. INFINIPATH_HWE_HTCLNKABYTE0CRCERR;
  293. static const ipath_err_t infinipath_hwe_htclnkabyte1crcerr =
  294. INFINIPATH_HWE_HTCLNKABYTE1CRCERR;
  295. static const ipath_err_t infinipath_hwe_htclnkbbyte0crcerr =
  296. INFINIPATH_HWE_HTCLNKBBYTE0CRCERR;
  297. static const ipath_err_t infinipath_hwe_htclnkbbyte1crcerr =
  298. INFINIPATH_HWE_HTCLNKBBYTE1CRCERR;
  299. #define _IPATH_GPIO_SDA_NUM 1
  300. #define _IPATH_GPIO_SCL_NUM 0
  301. #define IPATH_GPIO_SDA \
  302. (1ULL << (_IPATH_GPIO_SDA_NUM+INFINIPATH_EXTC_GPIOOE_SHIFT))
  303. #define IPATH_GPIO_SCL \
  304. (1ULL << (_IPATH_GPIO_SCL_NUM+INFINIPATH_EXTC_GPIOOE_SHIFT))
  305. /* keep the code below somewhat more readonable; not used elsewhere */
  306. #define _IPATH_HTLINK0_CRCBITS (infinipath_hwe_htclnkabyte0crcerr | \
  307. infinipath_hwe_htclnkabyte1crcerr)
  308. #define _IPATH_HTLINK1_CRCBITS (infinipath_hwe_htclnkbbyte0crcerr | \
  309. infinipath_hwe_htclnkbbyte1crcerr)
  310. #define _IPATH_HTLANE0_CRCBITS (infinipath_hwe_htclnkabyte0crcerr | \
  311. infinipath_hwe_htclnkbbyte0crcerr)
  312. #define _IPATH_HTLANE1_CRCBITS (infinipath_hwe_htclnkabyte1crcerr | \
  313. infinipath_hwe_htclnkbbyte1crcerr)
  314. static void hwerr_crcbits(struct ipath_devdata *dd, ipath_err_t hwerrs,
  315. char *msg, size_t msgl)
  316. {
  317. char bitsmsg[64];
  318. ipath_err_t crcbits = hwerrs &
  319. (_IPATH_HTLINK0_CRCBITS | _IPATH_HTLINK1_CRCBITS);
  320. /* don't check if 8bit HT */
  321. if (dd->ipath_flags & IPATH_8BIT_IN_HT0)
  322. crcbits &= ~infinipath_hwe_htclnkabyte1crcerr;
  323. /* don't check if 8bit HT */
  324. if (dd->ipath_flags & IPATH_8BIT_IN_HT1)
  325. crcbits &= ~infinipath_hwe_htclnkbbyte1crcerr;
  326. /*
  327. * we'll want to ignore link errors on link that is
  328. * not in use, if any. For now, complain about both
  329. */
  330. if (crcbits) {
  331. u16 ctrl0, ctrl1;
  332. snprintf(bitsmsg, sizeof bitsmsg,
  333. "[HT%s lane %s CRC (%llx); powercycle to completely clear]",
  334. !(crcbits & _IPATH_HTLINK1_CRCBITS) ?
  335. "0 (A)" : (!(crcbits & _IPATH_HTLINK0_CRCBITS)
  336. ? "1 (B)" : "0+1 (A+B)"),
  337. !(crcbits & _IPATH_HTLANE1_CRCBITS) ? "0"
  338. : (!(crcbits & _IPATH_HTLANE0_CRCBITS) ? "1" :
  339. "0+1"), (unsigned long long) crcbits);
  340. strlcat(msg, bitsmsg, msgl);
  341. /*
  342. * print extra info for debugging. slave/primary
  343. * config word 4, 8 (link control 0, 1)
  344. */
  345. if (pci_read_config_word(dd->pcidev,
  346. dd->ipath_ht_slave_off + 0x4,
  347. &ctrl0))
  348. dev_info(&dd->pcidev->dev, "Couldn't read "
  349. "linkctrl0 of slave/primary "
  350. "config block\n");
  351. else if (!(ctrl0 & 1 << 6))
  352. /* not if EOC bit set */
  353. ipath_dbg("HT linkctrl0 0x%x%s%s\n", ctrl0,
  354. ((ctrl0 >> 8) & 7) ? " CRC" : "",
  355. ((ctrl0 >> 4) & 1) ? "linkfail" :
  356. "");
  357. if (pci_read_config_word(dd->pcidev,
  358. dd->ipath_ht_slave_off + 0x8,
  359. &ctrl1))
  360. dev_info(&dd->pcidev->dev, "Couldn't read "
  361. "linkctrl1 of slave/primary "
  362. "config block\n");
  363. else if (!(ctrl1 & 1 << 6))
  364. /* not if EOC bit set */
  365. ipath_dbg("HT linkctrl1 0x%x%s%s\n", ctrl1,
  366. ((ctrl1 >> 8) & 7) ? " CRC" : "",
  367. ((ctrl1 >> 4) & 1) ? "linkfail" :
  368. "");
  369. /* disable until driver reloaded */
  370. dd->ipath_hwerrmask &= ~crcbits;
  371. ipath_write_kreg(dd, dd->ipath_kregs->kr_hwerrmask,
  372. dd->ipath_hwerrmask);
  373. ipath_dbg("HT crc errs: %s\n", msg);
  374. } else
  375. ipath_dbg("ignoring HT crc errors 0x%llx, "
  376. "not in use\n", (unsigned long long)
  377. (hwerrs & (_IPATH_HTLINK0_CRCBITS |
  378. _IPATH_HTLINK1_CRCBITS)));
  379. }
  380. /* 6110 specific hardware errors... */
  381. static const struct ipath_hwerror_msgs ipath_6110_hwerror_msgs[] = {
  382. INFINIPATH_HWE_MSG(HTCBUSIREQPARITYERR, "HTC Ireq Parity"),
  383. INFINIPATH_HWE_MSG(HTCBUSTREQPARITYERR, "HTC Treq Parity"),
  384. INFINIPATH_HWE_MSG(HTCBUSTRESPPARITYERR, "HTC Tresp Parity"),
  385. INFINIPATH_HWE_MSG(HTCMISCERR5, "HT core Misc5"),
  386. INFINIPATH_HWE_MSG(HTCMISCERR6, "HT core Misc6"),
  387. INFINIPATH_HWE_MSG(HTCMISCERR7, "HT core Misc7"),
  388. INFINIPATH_HWE_MSG(RXDSYNCMEMPARITYERR, "Rx Dsync"),
  389. INFINIPATH_HWE_MSG(SERDESPLLFAILED, "SerDes PLL"),
  390. };
  391. #define TXE_PIO_PARITY ((INFINIPATH_HWE_TXEMEMPARITYERR_PIOBUF | \
  392. INFINIPATH_HWE_TXEMEMPARITYERR_PIOPBC) \
  393. << INFINIPATH_HWE_TXEMEMPARITYERR_SHIFT)
  394. #define RXE_EAGER_PARITY (INFINIPATH_HWE_RXEMEMPARITYERR_EAGERTID \
  395. << INFINIPATH_HWE_RXEMEMPARITYERR_SHIFT)
  396. static int ipath_ht_txe_recover(struct ipath_devdata *);
  397. /**
  398. * ipath_ht_handle_hwerrors - display hardware errors.
  399. * @dd: the infinipath device
  400. * @msg: the output buffer
  401. * @msgl: the size of the output buffer
  402. *
  403. * Use same msg buffer as regular errors to avoid excessive stack
  404. * use. Most hardware errors are catastrophic, but for right now,
  405. * we'll print them and continue. We reuse the same message buffer as
  406. * ipath_handle_errors() to avoid excessive stack usage.
  407. */
  408. static void ipath_ht_handle_hwerrors(struct ipath_devdata *dd, char *msg,
  409. size_t msgl)
  410. {
  411. ipath_err_t hwerrs;
  412. u32 bits, ctrl;
  413. int isfatal = 0;
  414. char bitsmsg[64];
  415. int log_idx;
  416. hwerrs = ipath_read_kreg64(dd, dd->ipath_kregs->kr_hwerrstatus);
  417. if (!hwerrs) {
  418. ipath_cdbg(VERBOSE, "Called but no hardware errors set\n");
  419. /*
  420. * better than printing cofusing messages
  421. * This seems to be related to clearing the crc error, or
  422. * the pll error during init.
  423. */
  424. goto bail;
  425. } else if (hwerrs == -1LL) {
  426. ipath_dev_err(dd, "Read of hardware error status failed "
  427. "(all bits set); ignoring\n");
  428. goto bail;
  429. }
  430. ipath_stats.sps_hwerrs++;
  431. /* Always clear the error status register, except MEMBISTFAIL,
  432. * regardless of whether we continue or stop using the chip.
  433. * We want that set so we know it failed, even across driver reload.
  434. * We'll still ignore it in the hwerrmask. We do this partly for
  435. * diagnostics, but also for support */
  436. ipath_write_kreg(dd, dd->ipath_kregs->kr_hwerrclear,
  437. hwerrs&~INFINIPATH_HWE_MEMBISTFAILED);
  438. hwerrs &= dd->ipath_hwerrmask;
  439. /* We log some errors to EEPROM, check if we have any of those. */
  440. for (log_idx = 0; log_idx < IPATH_EEP_LOG_CNT; ++log_idx)
  441. if (hwerrs & dd->ipath_eep_st_masks[log_idx].hwerrs_to_log)
  442. ipath_inc_eeprom_err(dd, log_idx, 1);
  443. /*
  444. * make sure we get this much out, unless told to be quiet,
  445. * it's a parity error we may recover from,
  446. * or it's occurred within the last 5 seconds
  447. */
  448. if ((hwerrs & ~(dd->ipath_lasthwerror | TXE_PIO_PARITY |
  449. RXE_EAGER_PARITY)) ||
  450. (ipath_debug & __IPATH_VERBDBG))
  451. dev_info(&dd->pcidev->dev, "Hardware error: hwerr=0x%llx "
  452. "(cleared)\n", (unsigned long long) hwerrs);
  453. dd->ipath_lasthwerror |= hwerrs;
  454. if (hwerrs & ~dd->ipath_hwe_bitsextant)
  455. ipath_dev_err(dd, "hwerror interrupt with unknown errors "
  456. "%llx set\n", (unsigned long long)
  457. (hwerrs & ~dd->ipath_hwe_bitsextant));
  458. ctrl = ipath_read_kreg32(dd, dd->ipath_kregs->kr_control);
  459. if ((ctrl & INFINIPATH_C_FREEZEMODE) && !ipath_diag_inuse) {
  460. /*
  461. * parity errors in send memory are recoverable,
  462. * just cancel the send (if indicated in * sendbuffererror),
  463. * count the occurrence, unfreeze (if no other handled
  464. * hardware error bits are set), and continue. They can
  465. * occur if a processor speculative read is done to the PIO
  466. * buffer while we are sending a packet, for example.
  467. */
  468. if ((hwerrs & TXE_PIO_PARITY) && ipath_ht_txe_recover(dd))
  469. hwerrs &= ~TXE_PIO_PARITY;
  470. if (hwerrs & RXE_EAGER_PARITY)
  471. ipath_dev_err(dd, "RXE parity, Eager TID error is not "
  472. "recoverable\n");
  473. if (!hwerrs) {
  474. ipath_dbg("Clearing freezemode on ignored or "
  475. "recovered hardware error\n");
  476. ipath_clear_freeze(dd);
  477. }
  478. }
  479. *msg = '\0';
  480. /*
  481. * may someday want to decode into which bits are which
  482. * functional area for parity errors, etc.
  483. */
  484. if (hwerrs & (infinipath_hwe_htcmemparityerr_mask
  485. << INFINIPATH_HWE_HTCMEMPARITYERR_SHIFT)) {
  486. bits = (u32) ((hwerrs >>
  487. INFINIPATH_HWE_HTCMEMPARITYERR_SHIFT) &
  488. INFINIPATH_HWE_HTCMEMPARITYERR_MASK);
  489. snprintf(bitsmsg, sizeof bitsmsg, "[HTC Parity Errs %x] ",
  490. bits);
  491. strlcat(msg, bitsmsg, msgl);
  492. }
  493. ipath_format_hwerrors(hwerrs,
  494. ipath_6110_hwerror_msgs,
  495. sizeof(ipath_6110_hwerror_msgs) /
  496. sizeof(ipath_6110_hwerror_msgs[0]),
  497. msg, msgl);
  498. if (hwerrs & (_IPATH_HTLINK0_CRCBITS | _IPATH_HTLINK1_CRCBITS))
  499. hwerr_crcbits(dd, hwerrs, msg, msgl);
  500. if (hwerrs & INFINIPATH_HWE_MEMBISTFAILED) {
  501. strlcat(msg, "[Memory BIST test failed, InfiniPath hardware unusable]",
  502. msgl);
  503. /* ignore from now on, so disable until driver reloaded */
  504. dd->ipath_hwerrmask &= ~INFINIPATH_HWE_MEMBISTFAILED;
  505. ipath_write_kreg(dd, dd->ipath_kregs->kr_hwerrmask,
  506. dd->ipath_hwerrmask);
  507. }
  508. #define _IPATH_PLL_FAIL (INFINIPATH_HWE_COREPLL_FBSLIP | \
  509. INFINIPATH_HWE_COREPLL_RFSLIP | \
  510. INFINIPATH_HWE_HTBPLL_FBSLIP | \
  511. INFINIPATH_HWE_HTBPLL_RFSLIP | \
  512. INFINIPATH_HWE_HTAPLL_FBSLIP | \
  513. INFINIPATH_HWE_HTAPLL_RFSLIP)
  514. if (hwerrs & _IPATH_PLL_FAIL) {
  515. snprintf(bitsmsg, sizeof bitsmsg,
  516. "[PLL failed (%llx), InfiniPath hardware unusable]",
  517. (unsigned long long) (hwerrs & _IPATH_PLL_FAIL));
  518. strlcat(msg, bitsmsg, msgl);
  519. /* ignore from now on, so disable until driver reloaded */
  520. dd->ipath_hwerrmask &= ~(hwerrs & _IPATH_PLL_FAIL);
  521. ipath_write_kreg(dd, dd->ipath_kregs->kr_hwerrmask,
  522. dd->ipath_hwerrmask);
  523. }
  524. if (hwerrs & INFINIPATH_HWE_SERDESPLLFAILED) {
  525. /*
  526. * If it occurs, it is left masked since the eternal
  527. * interface is unused
  528. */
  529. dd->ipath_hwerrmask &= ~INFINIPATH_HWE_SERDESPLLFAILED;
  530. ipath_write_kreg(dd, dd->ipath_kregs->kr_hwerrmask,
  531. dd->ipath_hwerrmask);
  532. }
  533. if (hwerrs) {
  534. /*
  535. * if any set that we aren't ignoring; only
  536. * make the complaint once, in case it's stuck
  537. * or recurring, and we get here multiple
  538. * times.
  539. * force link down, so switch knows, and
  540. * LEDs are turned off
  541. */
  542. if (dd->ipath_flags & IPATH_INITTED) {
  543. ipath_set_linkstate(dd, IPATH_IB_LINKDOWN);
  544. ipath_setup_ht_setextled(dd,
  545. INFINIPATH_IBCS_L_STATE_DOWN,
  546. INFINIPATH_IBCS_LT_STATE_DISABLED);
  547. ipath_dev_err(dd, "Fatal Hardware Error (freeze "
  548. "mode), no longer usable, SN %.16s\n",
  549. dd->ipath_serial);
  550. isfatal = 1;
  551. }
  552. *dd->ipath_statusp &= ~IPATH_STATUS_IB_READY;
  553. /* mark as having had error */
  554. *dd->ipath_statusp |= IPATH_STATUS_HWERROR;
  555. /*
  556. * mark as not usable, at a minimum until driver
  557. * is reloaded, probably until reboot, since no
  558. * other reset is possible.
  559. */
  560. dd->ipath_flags &= ~IPATH_INITTED;
  561. }
  562. else
  563. *msg = 0; /* recovered from all of them */
  564. if (*msg)
  565. ipath_dev_err(dd, "%s hardware error\n", msg);
  566. if (isfatal && !ipath_diag_inuse && dd->ipath_freezemsg)
  567. /*
  568. * for status file; if no trailing brace is copied,
  569. * we'll know it was truncated.
  570. */
  571. snprintf(dd->ipath_freezemsg,
  572. dd->ipath_freezelen, "{%s}", msg);
  573. bail:;
  574. }
  575. /**
  576. * ipath_ht_boardname - fill in the board name
  577. * @dd: the infinipath device
  578. * @name: the output buffer
  579. * @namelen: the size of the output buffer
  580. *
  581. * fill in the board name, based on the board revision register
  582. */
  583. static int ipath_ht_boardname(struct ipath_devdata *dd, char *name,
  584. size_t namelen)
  585. {
  586. char *n = NULL;
  587. u8 boardrev = dd->ipath_boardrev;
  588. int ret;
  589. switch (boardrev) {
  590. case 4: /* Ponderosa is one of the bringup boards */
  591. n = "Ponderosa";
  592. break;
  593. case 5:
  594. /*
  595. * original production board; two production levels, with
  596. * different serial number ranges. See ipath_ht_early_init() for
  597. * case where we enable IPATH_GPIO_INTR for later serial # range.
  598. */
  599. n = "InfiniPath_QHT7040";
  600. break;
  601. case 6:
  602. n = "OEM_Board_3";
  603. break;
  604. case 7:
  605. /* small form factor production board */
  606. n = "InfiniPath_QHT7140";
  607. break;
  608. case 8:
  609. n = "LS/X-1";
  610. break;
  611. case 9: /* Comstock bringup test board */
  612. n = "Comstock";
  613. break;
  614. case 10:
  615. n = "OEM_Board_2";
  616. break;
  617. case 11:
  618. n = "InfiniPath_HT-470"; /* obsoleted */
  619. break;
  620. case 12:
  621. n = "OEM_Board_4";
  622. break;
  623. default: /* don't know, just print the number */
  624. ipath_dev_err(dd, "Don't yet know about board "
  625. "with ID %u\n", boardrev);
  626. snprintf(name, namelen, "Unknown_InfiniPath_QHT7xxx_%u",
  627. boardrev);
  628. break;
  629. }
  630. if (n)
  631. snprintf(name, namelen, "%s", n);
  632. if (dd->ipath_majrev != 3 || (dd->ipath_minrev < 2 ||
  633. dd->ipath_minrev > 4)) {
  634. /*
  635. * This version of the driver only supports Rev 3.2 - 3.4
  636. */
  637. ipath_dev_err(dd,
  638. "Unsupported InfiniPath hardware revision %u.%u!\n",
  639. dd->ipath_majrev, dd->ipath_minrev);
  640. ret = 1;
  641. goto bail;
  642. }
  643. /*
  644. * pkt/word counters are 32 bit, and therefore wrap fast enough
  645. * that we snapshot them from a timer, and maintain 64 bit shadow
  646. * copies
  647. */
  648. dd->ipath_flags |= IPATH_32BITCOUNTERS;
  649. if (dd->ipath_htspeed != 800)
  650. ipath_dev_err(dd,
  651. "Incorrectly configured for HT @ %uMHz\n",
  652. dd->ipath_htspeed);
  653. if (dd->ipath_boardrev == 7 || dd->ipath_boardrev == 11 ||
  654. dd->ipath_boardrev == 6)
  655. dd->ipath_flags |= IPATH_GPIO_INTR;
  656. else
  657. dd->ipath_flags |= IPATH_POLL_RX_INTR;
  658. if (dd->ipath_boardrev == 8) { /* LS/X-1 */
  659. u64 val;
  660. val = ipath_read_kreg64(dd, dd->ipath_kregs->kr_extstatus);
  661. if (val & INFINIPATH_EXTS_SERDESSEL) {
  662. /*
  663. * hardware disabled
  664. *
  665. * This means that the chip is hardware disabled,
  666. * and will not be able to bring up the link,
  667. * in any case. We special case this and abort
  668. * early, to avoid later messages. We also set
  669. * the DISABLED status bit
  670. */
  671. ipath_dbg("Unit %u is hardware-disabled\n",
  672. dd->ipath_unit);
  673. *dd->ipath_statusp |= IPATH_STATUS_DISABLED;
  674. /* this value is handled differently */
  675. ret = 2;
  676. goto bail;
  677. }
  678. }
  679. ret = 0;
  680. bail:
  681. return ret;
  682. }
  683. static void ipath_check_htlink(struct ipath_devdata *dd)
  684. {
  685. u8 linkerr, link_off, i;
  686. for (i = 0; i < 2; i++) {
  687. link_off = dd->ipath_ht_slave_off + i * 4 + 0xd;
  688. if (pci_read_config_byte(dd->pcidev, link_off, &linkerr))
  689. dev_info(&dd->pcidev->dev, "Couldn't read "
  690. "linkerror%d of HT slave/primary block\n",
  691. i);
  692. else if (linkerr & 0xf0) {
  693. ipath_cdbg(VERBOSE, "HT linkerr%d bits 0x%x set, "
  694. "clearing\n", linkerr >> 4, i);
  695. /*
  696. * writing the linkerr bits that are set should
  697. * clear them
  698. */
  699. if (pci_write_config_byte(dd->pcidev, link_off,
  700. linkerr))
  701. ipath_dbg("Failed write to clear HT "
  702. "linkerror%d\n", i);
  703. if (pci_read_config_byte(dd->pcidev, link_off,
  704. &linkerr))
  705. dev_info(&dd->pcidev->dev,
  706. "Couldn't reread linkerror%d of "
  707. "HT slave/primary block\n", i);
  708. else if (linkerr & 0xf0)
  709. dev_info(&dd->pcidev->dev,
  710. "HT linkerror%d bits 0x%x "
  711. "couldn't be cleared\n",
  712. i, linkerr >> 4);
  713. }
  714. }
  715. }
  716. static int ipath_setup_ht_reset(struct ipath_devdata *dd)
  717. {
  718. ipath_dbg("No reset possible for this InfiniPath hardware\n");
  719. return 0;
  720. }
  721. #define HT_INTR_DISC_CONFIG 0x80 /* HT interrupt and discovery cap */
  722. #define HT_INTR_REG_INDEX 2 /* intconfig requires indirect accesses */
  723. /*
  724. * Bits 13-15 of command==0 is slave/primary block. Clear any HT CRC
  725. * errors. We only bother to do this at load time, because it's OK if
  726. * it happened before we were loaded (first time after boot/reset),
  727. * but any time after that, it's fatal anyway. Also need to not check
  728. * for for upper byte errors if we are in 8 bit mode, so figure out
  729. * our width. For now, at least, also complain if it's 8 bit.
  730. */
  731. static void slave_or_pri_blk(struct ipath_devdata *dd, struct pci_dev *pdev,
  732. int pos, u8 cap_type)
  733. {
  734. u8 linkwidth = 0, linkerr, link_a_b_off, link_off;
  735. u16 linkctrl = 0;
  736. int i;
  737. dd->ipath_ht_slave_off = pos;
  738. /* command word, master_host bit */
  739. /* master host || slave */
  740. if ((cap_type >> 2) & 1)
  741. link_a_b_off = 4;
  742. else
  743. link_a_b_off = 0;
  744. ipath_cdbg(VERBOSE, "HT%u (Link %c) connected to processor\n",
  745. link_a_b_off ? 1 : 0,
  746. link_a_b_off ? 'B' : 'A');
  747. link_a_b_off += pos;
  748. /*
  749. * check both link control registers; clear both HT CRC sets if
  750. * necessary.
  751. */
  752. for (i = 0; i < 2; i++) {
  753. link_off = pos + i * 4 + 0x4;
  754. if (pci_read_config_word(pdev, link_off, &linkctrl))
  755. ipath_dev_err(dd, "Couldn't read HT link control%d "
  756. "register\n", i);
  757. else if (linkctrl & (0xf << 8)) {
  758. ipath_cdbg(VERBOSE, "Clear linkctrl%d CRC Error "
  759. "bits %x\n", i, linkctrl & (0xf << 8));
  760. /*
  761. * now write them back to clear the error.
  762. */
  763. pci_write_config_byte(pdev, link_off,
  764. linkctrl & (0xf << 8));
  765. }
  766. }
  767. /*
  768. * As with HT CRC bits, same for protocol errors that might occur
  769. * during boot.
  770. */
  771. for (i = 0; i < 2; i++) {
  772. link_off = pos + i * 4 + 0xd;
  773. if (pci_read_config_byte(pdev, link_off, &linkerr))
  774. dev_info(&pdev->dev, "Couldn't read linkerror%d "
  775. "of HT slave/primary block\n", i);
  776. else if (linkerr & 0xf0) {
  777. ipath_cdbg(VERBOSE, "HT linkerr%d bits 0x%x set, "
  778. "clearing\n", linkerr >> 4, i);
  779. /*
  780. * writing the linkerr bits that are set will clear
  781. * them
  782. */
  783. if (pci_write_config_byte
  784. (pdev, link_off, linkerr))
  785. ipath_dbg("Failed write to clear HT "
  786. "linkerror%d\n", i);
  787. if (pci_read_config_byte(pdev, link_off, &linkerr))
  788. dev_info(&pdev->dev, "Couldn't reread "
  789. "linkerror%d of HT slave/primary "
  790. "block\n", i);
  791. else if (linkerr & 0xf0)
  792. dev_info(&pdev->dev, "HT linkerror%d bits "
  793. "0x%x couldn't be cleared\n",
  794. i, linkerr >> 4);
  795. }
  796. }
  797. /*
  798. * this is just for our link to the host, not devices connected
  799. * through tunnel.
  800. */
  801. if (pci_read_config_byte(pdev, link_a_b_off + 7, &linkwidth))
  802. ipath_dev_err(dd, "Couldn't read HT link width "
  803. "config register\n");
  804. else {
  805. u32 width;
  806. switch (linkwidth & 7) {
  807. case 5:
  808. width = 4;
  809. break;
  810. case 4:
  811. width = 2;
  812. break;
  813. case 3:
  814. width = 32;
  815. break;
  816. case 1:
  817. width = 16;
  818. break;
  819. case 0:
  820. default: /* if wrong, assume 8 bit */
  821. width = 8;
  822. break;
  823. }
  824. dd->ipath_htwidth = width;
  825. if (linkwidth != 0x11) {
  826. ipath_dev_err(dd, "Not configured for 16 bit HT "
  827. "(%x)\n", linkwidth);
  828. if (!(linkwidth & 0xf)) {
  829. ipath_dbg("Will ignore HT lane1 errors\n");
  830. dd->ipath_flags |= IPATH_8BIT_IN_HT0;
  831. }
  832. }
  833. }
  834. /*
  835. * this is just for our link to the host, not devices connected
  836. * through tunnel.
  837. */
  838. if (pci_read_config_byte(pdev, link_a_b_off + 0xd, &linkwidth))
  839. ipath_dev_err(dd, "Couldn't read HT link frequency "
  840. "config register\n");
  841. else {
  842. u32 speed;
  843. switch (linkwidth & 0xf) {
  844. case 6:
  845. speed = 1000;
  846. break;
  847. case 5:
  848. speed = 800;
  849. break;
  850. case 4:
  851. speed = 600;
  852. break;
  853. case 3:
  854. speed = 500;
  855. break;
  856. case 2:
  857. speed = 400;
  858. break;
  859. case 1:
  860. speed = 300;
  861. break;
  862. default:
  863. /*
  864. * assume reserved and vendor-specific are 200...
  865. */
  866. case 0:
  867. speed = 200;
  868. break;
  869. }
  870. dd->ipath_htspeed = speed;
  871. }
  872. }
  873. static int ipath_ht_intconfig(struct ipath_devdata *dd)
  874. {
  875. int ret;
  876. if (dd->ipath_intconfig) {
  877. ipath_write_kreg(dd, dd->ipath_kregs->kr_interruptconfig,
  878. dd->ipath_intconfig); /* interrupt address */
  879. ret = 0;
  880. } else {
  881. ipath_dev_err(dd, "No interrupts enabled, couldn't setup "
  882. "interrupt address\n");
  883. ret = -EINVAL;
  884. }
  885. return ret;
  886. }
  887. static void ipath_ht_irq_update(struct pci_dev *dev, int irq,
  888. struct ht_irq_msg *msg)
  889. {
  890. struct ipath_devdata *dd = pci_get_drvdata(dev);
  891. u64 prev_intconfig = dd->ipath_intconfig;
  892. dd->ipath_intconfig = msg->address_lo;
  893. dd->ipath_intconfig |= ((u64) msg->address_hi) << 32;
  894. /*
  895. * If the previous value of dd->ipath_intconfig is zero, we're
  896. * getting configured for the first time, and must not program the
  897. * intconfig register here (it will be programmed later, when the
  898. * hardware is ready). Otherwise, we should.
  899. */
  900. if (prev_intconfig)
  901. ipath_ht_intconfig(dd);
  902. }
  903. /**
  904. * ipath_setup_ht_config - setup the interruptconfig register
  905. * @dd: the infinipath device
  906. * @pdev: the PCI device
  907. *
  908. * setup the interruptconfig register from the HT config info.
  909. * Also clear CRC errors in HT linkcontrol, if necessary.
  910. * This is done only for the real hardware. It is done before
  911. * chip address space is initted, so can't touch infinipath registers
  912. */
  913. static int ipath_setup_ht_config(struct ipath_devdata *dd,
  914. struct pci_dev *pdev)
  915. {
  916. int pos, ret;
  917. ret = __ht_create_irq(pdev, 0, ipath_ht_irq_update);
  918. if (ret < 0) {
  919. ipath_dev_err(dd, "Couldn't create interrupt handler: "
  920. "err %d\n", ret);
  921. goto bail;
  922. }
  923. dd->ipath_irq = ret;
  924. ret = 0;
  925. /*
  926. * Handle clearing CRC errors in linkctrl register if necessary. We
  927. * do this early, before we ever enable errors or hardware errors,
  928. * mostly to avoid causing the chip to enter freeze mode.
  929. */
  930. pos = pci_find_capability(pdev, PCI_CAP_ID_HT);
  931. if (!pos) {
  932. ipath_dev_err(dd, "Couldn't find HyperTransport "
  933. "capability; no interrupts\n");
  934. ret = -ENODEV;
  935. goto bail;
  936. }
  937. do {
  938. u8 cap_type;
  939. /* the HT capability type byte is 3 bytes after the
  940. * capability byte.
  941. */
  942. if (pci_read_config_byte(pdev, pos + 3, &cap_type)) {
  943. dev_info(&pdev->dev, "Couldn't read config "
  944. "command @ %d\n", pos);
  945. continue;
  946. }
  947. if (!(cap_type & 0xE0))
  948. slave_or_pri_blk(dd, pdev, pos, cap_type);
  949. } while ((pos = pci_find_next_capability(pdev, pos,
  950. PCI_CAP_ID_HT)));
  951. bail:
  952. return ret;
  953. }
  954. /**
  955. * ipath_setup_ht_cleanup - clean up any per-chip chip-specific stuff
  956. * @dd: the infinipath device
  957. *
  958. * Called during driver unload.
  959. * This is currently a nop for the HT chip, not for all chips
  960. */
  961. static void ipath_setup_ht_cleanup(struct ipath_devdata *dd)
  962. {
  963. }
  964. /**
  965. * ipath_setup_ht_setextled - set the state of the two external LEDs
  966. * @dd: the infinipath device
  967. * @lst: the L state
  968. * @ltst: the LT state
  969. *
  970. * Set the state of the two external LEDs, to indicate physical and
  971. * logical state of IB link. For this chip (at least with recommended
  972. * board pinouts), LED1 is Green (physical state), and LED2 is Yellow
  973. * (logical state)
  974. *
  975. * Note: We try to match the Mellanox HCA LED behavior as best
  976. * we can. Green indicates physical link state is OK (something is
  977. * plugged in, and we can train).
  978. * Amber indicates the link is logically up (ACTIVE).
  979. * Mellanox further blinks the amber LED to indicate data packet
  980. * activity, but we have no hardware support for that, so it would
  981. * require waking up every 10-20 msecs and checking the counters
  982. * on the chip, and then turning the LED off if appropriate. That's
  983. * visible overhead, so not something we will do.
  984. *
  985. */
  986. static void ipath_setup_ht_setextled(struct ipath_devdata *dd,
  987. u64 lst, u64 ltst)
  988. {
  989. u64 extctl;
  990. unsigned long flags = 0;
  991. /* the diags use the LED to indicate diag info, so we leave
  992. * the external LED alone when the diags are running */
  993. if (ipath_diag_inuse)
  994. return;
  995. /* Allow override of LED display for, e.g. Locating system in rack */
  996. if (dd->ipath_led_override) {
  997. ltst = (dd->ipath_led_override & IPATH_LED_PHYS)
  998. ? INFINIPATH_IBCS_LT_STATE_LINKUP
  999. : INFINIPATH_IBCS_LT_STATE_DISABLED;
  1000. lst = (dd->ipath_led_override & IPATH_LED_LOG)
  1001. ? INFINIPATH_IBCS_L_STATE_ACTIVE
  1002. : INFINIPATH_IBCS_L_STATE_DOWN;
  1003. }
  1004. spin_lock_irqsave(&dd->ipath_gpio_lock, flags);
  1005. /*
  1006. * start by setting both LED control bits to off, then turn
  1007. * on the appropriate bit(s).
  1008. */
  1009. if (dd->ipath_boardrev == 8) { /* LS/X-1 uses different pins */
  1010. /*
  1011. * major difference is that INFINIPATH_EXTC_LEDGBLERR_OFF
  1012. * is inverted, because it is normally used to indicate
  1013. * a hardware fault at reset, if there were errors
  1014. */
  1015. extctl = (dd->ipath_extctrl & ~INFINIPATH_EXTC_LEDGBLOK_ON)
  1016. | INFINIPATH_EXTC_LEDGBLERR_OFF;
  1017. if (ltst == INFINIPATH_IBCS_LT_STATE_LINKUP)
  1018. extctl &= ~INFINIPATH_EXTC_LEDGBLERR_OFF;
  1019. if (lst == INFINIPATH_IBCS_L_STATE_ACTIVE)
  1020. extctl |= INFINIPATH_EXTC_LEDGBLOK_ON;
  1021. }
  1022. else {
  1023. extctl = dd->ipath_extctrl &
  1024. ~(INFINIPATH_EXTC_LED1PRIPORT_ON |
  1025. INFINIPATH_EXTC_LED2PRIPORT_ON);
  1026. if (ltst == INFINIPATH_IBCS_LT_STATE_LINKUP)
  1027. extctl |= INFINIPATH_EXTC_LED1PRIPORT_ON;
  1028. if (lst == INFINIPATH_IBCS_L_STATE_ACTIVE)
  1029. extctl |= INFINIPATH_EXTC_LED2PRIPORT_ON;
  1030. }
  1031. dd->ipath_extctrl = extctl;
  1032. ipath_write_kreg(dd, dd->ipath_kregs->kr_extctrl, extctl);
  1033. spin_unlock_irqrestore(&dd->ipath_gpio_lock, flags);
  1034. }
  1035. static void ipath_init_ht_variables(struct ipath_devdata *dd)
  1036. {
  1037. dd->ipath_gpio_sda_num = _IPATH_GPIO_SDA_NUM;
  1038. dd->ipath_gpio_scl_num = _IPATH_GPIO_SCL_NUM;
  1039. dd->ipath_gpio_sda = IPATH_GPIO_SDA;
  1040. dd->ipath_gpio_scl = IPATH_GPIO_SCL;
  1041. dd->ipath_i_bitsextant =
  1042. (INFINIPATH_I_RCVURG_MASK << INFINIPATH_I_RCVURG_SHIFT) |
  1043. (INFINIPATH_I_RCVAVAIL_MASK <<
  1044. INFINIPATH_I_RCVAVAIL_SHIFT) |
  1045. INFINIPATH_I_ERROR | INFINIPATH_I_SPIOSENT |
  1046. INFINIPATH_I_SPIOBUFAVAIL | INFINIPATH_I_GPIO;
  1047. dd->ipath_e_bitsextant =
  1048. INFINIPATH_E_RFORMATERR | INFINIPATH_E_RVCRC |
  1049. INFINIPATH_E_RICRC | INFINIPATH_E_RMINPKTLEN |
  1050. INFINIPATH_E_RMAXPKTLEN | INFINIPATH_E_RLONGPKTLEN |
  1051. INFINIPATH_E_RSHORTPKTLEN | INFINIPATH_E_RUNEXPCHAR |
  1052. INFINIPATH_E_RUNSUPVL | INFINIPATH_E_REBP |
  1053. INFINIPATH_E_RIBFLOW | INFINIPATH_E_RBADVERSION |
  1054. INFINIPATH_E_RRCVEGRFULL | INFINIPATH_E_RRCVHDRFULL |
  1055. INFINIPATH_E_RBADTID | INFINIPATH_E_RHDRLEN |
  1056. INFINIPATH_E_RHDR | INFINIPATH_E_RIBLOSTLINK |
  1057. INFINIPATH_E_SMINPKTLEN | INFINIPATH_E_SMAXPKTLEN |
  1058. INFINIPATH_E_SUNDERRUN | INFINIPATH_E_SPKTLEN |
  1059. INFINIPATH_E_SDROPPEDSMPPKT | INFINIPATH_E_SDROPPEDDATAPKT |
  1060. INFINIPATH_E_SPIOARMLAUNCH | INFINIPATH_E_SUNEXPERRPKTNUM |
  1061. INFINIPATH_E_SUNSUPVL | INFINIPATH_E_IBSTATUSCHANGED |
  1062. INFINIPATH_E_INVALIDADDR | INFINIPATH_E_RESET |
  1063. INFINIPATH_E_HARDWARE;
  1064. dd->ipath_hwe_bitsextant =
  1065. (INFINIPATH_HWE_HTCMEMPARITYERR_MASK <<
  1066. INFINIPATH_HWE_HTCMEMPARITYERR_SHIFT) |
  1067. (INFINIPATH_HWE_TXEMEMPARITYERR_MASK <<
  1068. INFINIPATH_HWE_TXEMEMPARITYERR_SHIFT) |
  1069. (INFINIPATH_HWE_RXEMEMPARITYERR_MASK <<
  1070. INFINIPATH_HWE_RXEMEMPARITYERR_SHIFT) |
  1071. INFINIPATH_HWE_HTCLNKABYTE0CRCERR |
  1072. INFINIPATH_HWE_HTCLNKABYTE1CRCERR |
  1073. INFINIPATH_HWE_HTCLNKBBYTE0CRCERR |
  1074. INFINIPATH_HWE_HTCLNKBBYTE1CRCERR |
  1075. INFINIPATH_HWE_HTCMISCERR4 |
  1076. INFINIPATH_HWE_HTCMISCERR5 | INFINIPATH_HWE_HTCMISCERR6 |
  1077. INFINIPATH_HWE_HTCMISCERR7 |
  1078. INFINIPATH_HWE_HTCBUSTREQPARITYERR |
  1079. INFINIPATH_HWE_HTCBUSTRESPPARITYERR |
  1080. INFINIPATH_HWE_HTCBUSIREQPARITYERR |
  1081. INFINIPATH_HWE_RXDSYNCMEMPARITYERR |
  1082. INFINIPATH_HWE_MEMBISTFAILED |
  1083. INFINIPATH_HWE_COREPLL_FBSLIP |
  1084. INFINIPATH_HWE_COREPLL_RFSLIP |
  1085. INFINIPATH_HWE_HTBPLL_FBSLIP |
  1086. INFINIPATH_HWE_HTBPLL_RFSLIP |
  1087. INFINIPATH_HWE_HTAPLL_FBSLIP |
  1088. INFINIPATH_HWE_HTAPLL_RFSLIP |
  1089. INFINIPATH_HWE_SERDESPLLFAILED |
  1090. INFINIPATH_HWE_IBCBUSTOSPCPARITYERR |
  1091. INFINIPATH_HWE_IBCBUSFRSPCPARITYERR;
  1092. dd->ipath_i_rcvavail_mask = INFINIPATH_I_RCVAVAIL_MASK;
  1093. dd->ipath_i_rcvurg_mask = INFINIPATH_I_RCVURG_MASK;
  1094. /*
  1095. * EEPROM error log 0 is TXE Parity errors. 1 is RXE Parity.
  1096. * 2 is Some Misc, 3 is reserved for future.
  1097. */
  1098. dd->ipath_eep_st_masks[0].hwerrs_to_log =
  1099. INFINIPATH_HWE_TXEMEMPARITYERR_MASK <<
  1100. INFINIPATH_HWE_TXEMEMPARITYERR_SHIFT;
  1101. dd->ipath_eep_st_masks[1].hwerrs_to_log =
  1102. INFINIPATH_HWE_RXEMEMPARITYERR_MASK <<
  1103. INFINIPATH_HWE_RXEMEMPARITYERR_SHIFT;
  1104. dd->ipath_eep_st_masks[2].errs_to_log =
  1105. INFINIPATH_E_INVALIDADDR | INFINIPATH_E_RESET;
  1106. }
  1107. /**
  1108. * ipath_ht_init_hwerrors - enable hardware errors
  1109. * @dd: the infinipath device
  1110. *
  1111. * now that we have finished initializing everything that might reasonably
  1112. * cause a hardware error, and cleared those errors bits as they occur,
  1113. * we can enable hardware errors in the mask (potentially enabling
  1114. * freeze mode), and enable hardware errors as errors (along with
  1115. * everything else) in errormask
  1116. */
  1117. static void ipath_ht_init_hwerrors(struct ipath_devdata *dd)
  1118. {
  1119. ipath_err_t val;
  1120. u64 extsval;
  1121. extsval = ipath_read_kreg64(dd, dd->ipath_kregs->kr_extstatus);
  1122. if (!(extsval & INFINIPATH_EXTS_MEMBIST_ENDTEST))
  1123. ipath_dev_err(dd, "MemBIST did not complete!\n");
  1124. if (extsval & INFINIPATH_EXTS_MEMBIST_CORRECT)
  1125. ipath_dbg("MemBIST corrected\n");
  1126. ipath_check_htlink(dd);
  1127. /* barring bugs, all hwerrors become interrupts, which can */
  1128. val = -1LL;
  1129. /* don't look at crc lane1 if 8 bit */
  1130. if (dd->ipath_flags & IPATH_8BIT_IN_HT0)
  1131. val &= ~infinipath_hwe_htclnkabyte1crcerr;
  1132. /* don't look at crc lane1 if 8 bit */
  1133. if (dd->ipath_flags & IPATH_8BIT_IN_HT1)
  1134. val &= ~infinipath_hwe_htclnkbbyte1crcerr;
  1135. /*
  1136. * disable RXDSYNCMEMPARITY because external serdes is unused,
  1137. * and therefore the logic will never be used or initialized,
  1138. * and uninitialized state will normally result in this error
  1139. * being asserted. Similarly for the external serdess pll
  1140. * lock signal.
  1141. */
  1142. val &= ~(INFINIPATH_HWE_SERDESPLLFAILED |
  1143. INFINIPATH_HWE_RXDSYNCMEMPARITYERR);
  1144. /*
  1145. * Disable MISCERR4 because of an inversion in the HT core
  1146. * logic checking for errors that cause this bit to be set.
  1147. * The errata can also cause the protocol error bit to be set
  1148. * in the HT config space linkerror register(s).
  1149. */
  1150. val &= ~INFINIPATH_HWE_HTCMISCERR4;
  1151. /*
  1152. * PLL ignored because MDIO interface has a logic problem
  1153. * for reads, on Comstock and Ponderosa. BRINGUP
  1154. */
  1155. if (dd->ipath_boardrev == 4 || dd->ipath_boardrev == 9)
  1156. val &= ~INFINIPATH_HWE_SERDESPLLFAILED;
  1157. dd->ipath_hwerrmask = val;
  1158. }
  1159. /**
  1160. * ipath_ht_bringup_serdes - bring up the serdes
  1161. * @dd: the infinipath device
  1162. */
  1163. static int ipath_ht_bringup_serdes(struct ipath_devdata *dd)
  1164. {
  1165. u64 val, config1;
  1166. int ret = 0, change = 0;
  1167. ipath_dbg("Trying to bringup serdes\n");
  1168. if (ipath_read_kreg64(dd, dd->ipath_kregs->kr_hwerrstatus) &
  1169. INFINIPATH_HWE_SERDESPLLFAILED)
  1170. {
  1171. ipath_dbg("At start, serdes PLL failed bit set in "
  1172. "hwerrstatus, clearing and continuing\n");
  1173. ipath_write_kreg(dd, dd->ipath_kregs->kr_hwerrclear,
  1174. INFINIPATH_HWE_SERDESPLLFAILED);
  1175. }
  1176. val = ipath_read_kreg64(dd, dd->ipath_kregs->kr_serdesconfig0);
  1177. config1 = ipath_read_kreg64(dd, dd->ipath_kregs->kr_serdesconfig1);
  1178. ipath_cdbg(VERBOSE, "Initial serdes status is config0=%llx "
  1179. "config1=%llx, sstatus=%llx xgxs %llx\n",
  1180. (unsigned long long) val, (unsigned long long) config1,
  1181. (unsigned long long)
  1182. ipath_read_kreg64(dd, dd->ipath_kregs->kr_serdesstatus),
  1183. (unsigned long long)
  1184. ipath_read_kreg64(dd, dd->ipath_kregs->kr_xgxsconfig));
  1185. /* force reset on */
  1186. val |= INFINIPATH_SERDC0_RESET_PLL
  1187. /* | INFINIPATH_SERDC0_RESET_MASK */
  1188. ;
  1189. ipath_write_kreg(dd, dd->ipath_kregs->kr_serdesconfig0, val);
  1190. udelay(15); /* need pll reset set at least for a bit */
  1191. if (val & INFINIPATH_SERDC0_RESET_PLL) {
  1192. u64 val2 = val &= ~INFINIPATH_SERDC0_RESET_PLL;
  1193. /* set lane resets, and tx idle, during pll reset */
  1194. val2 |= INFINIPATH_SERDC0_RESET_MASK |
  1195. INFINIPATH_SERDC0_TXIDLE;
  1196. ipath_cdbg(VERBOSE, "Clearing serdes PLL reset (writing "
  1197. "%llx)\n", (unsigned long long) val2);
  1198. ipath_write_kreg(dd, dd->ipath_kregs->kr_serdesconfig0,
  1199. val2);
  1200. /*
  1201. * be sure chip saw it
  1202. */
  1203. val = ipath_read_kreg64(dd, dd->ipath_kregs->kr_scratch);
  1204. /*
  1205. * need pll reset clear at least 11 usec before lane
  1206. * resets cleared; give it a few more
  1207. */
  1208. udelay(15);
  1209. val = val2; /* for check below */
  1210. }
  1211. if (val & (INFINIPATH_SERDC0_RESET_PLL |
  1212. INFINIPATH_SERDC0_RESET_MASK |
  1213. INFINIPATH_SERDC0_TXIDLE)) {
  1214. val &= ~(INFINIPATH_SERDC0_RESET_PLL |
  1215. INFINIPATH_SERDC0_RESET_MASK |
  1216. INFINIPATH_SERDC0_TXIDLE);
  1217. /* clear them */
  1218. ipath_write_kreg(dd, dd->ipath_kregs->kr_serdesconfig0,
  1219. val);
  1220. }
  1221. val = ipath_read_kreg64(dd, dd->ipath_kregs->kr_xgxsconfig);
  1222. if (((val >> INFINIPATH_XGXS_MDIOADDR_SHIFT) &
  1223. INFINIPATH_XGXS_MDIOADDR_MASK) != 3) {
  1224. val &= ~(INFINIPATH_XGXS_MDIOADDR_MASK <<
  1225. INFINIPATH_XGXS_MDIOADDR_SHIFT);
  1226. /*
  1227. * we use address 3
  1228. */
  1229. val |= 3ULL << INFINIPATH_XGXS_MDIOADDR_SHIFT;
  1230. change = 1;
  1231. }
  1232. if (val & INFINIPATH_XGXS_RESET) {
  1233. /* normally true after boot */
  1234. val &= ~INFINIPATH_XGXS_RESET;
  1235. change = 1;
  1236. }
  1237. if (((val >> INFINIPATH_XGXS_RX_POL_SHIFT) &
  1238. INFINIPATH_XGXS_RX_POL_MASK) != dd->ipath_rx_pol_inv ) {
  1239. /* need to compensate for Tx inversion in partner */
  1240. val &= ~(INFINIPATH_XGXS_RX_POL_MASK <<
  1241. INFINIPATH_XGXS_RX_POL_SHIFT);
  1242. val |= dd->ipath_rx_pol_inv <<
  1243. INFINIPATH_XGXS_RX_POL_SHIFT;
  1244. change = 1;
  1245. }
  1246. if (change)
  1247. ipath_write_kreg(dd, dd->ipath_kregs->kr_xgxsconfig, val);
  1248. val = ipath_read_kreg64(dd, dd->ipath_kregs->kr_serdesconfig0);
  1249. /* clear current and de-emphasis bits */
  1250. config1 &= ~0x0ffffffff00ULL;
  1251. /* set current to 20ma */
  1252. config1 |= 0x00000000000ULL;
  1253. /* set de-emphasis to -5.68dB */
  1254. config1 |= 0x0cccc000000ULL;
  1255. ipath_write_kreg(dd, dd->ipath_kregs->kr_serdesconfig1, config1);
  1256. ipath_cdbg(VERBOSE, "After setup: serdes status is config0=%llx "
  1257. "config1=%llx, sstatus=%llx xgxs %llx\n",
  1258. (unsigned long long) val, (unsigned long long) config1,
  1259. (unsigned long long)
  1260. ipath_read_kreg64(dd, dd->ipath_kregs->kr_serdesstatus),
  1261. (unsigned long long)
  1262. ipath_read_kreg64(dd, dd->ipath_kregs->kr_xgxsconfig));
  1263. if (!ipath_waitfor_mdio_cmdready(dd)) {
  1264. ipath_write_kreg(dd, dd->ipath_kregs->kr_mdio,
  1265. ipath_mdio_req(IPATH_MDIO_CMD_READ, 31,
  1266. IPATH_MDIO_CTRL_XGXS_REG_8,
  1267. 0));
  1268. if (ipath_waitfor_complete(dd, dd->ipath_kregs->kr_mdio,
  1269. IPATH_MDIO_DATAVALID, &val))
  1270. ipath_dbg("Never got MDIO data for XGXS status "
  1271. "read\n");
  1272. else
  1273. ipath_cdbg(VERBOSE, "MDIO Read reg8, "
  1274. "'bank' 31 %x\n", (u32) val);
  1275. } else
  1276. ipath_dbg("Never got MDIO cmdready for XGXS status read\n");
  1277. return ret; /* for now, say we always succeeded */
  1278. }
  1279. /**
  1280. * ipath_ht_quiet_serdes - set serdes to txidle
  1281. * @dd: the infinipath device
  1282. * driver is being unloaded
  1283. */
  1284. static void ipath_ht_quiet_serdes(struct ipath_devdata *dd)
  1285. {
  1286. u64 val = ipath_read_kreg64(dd, dd->ipath_kregs->kr_serdesconfig0);
  1287. val |= INFINIPATH_SERDC0_TXIDLE;
  1288. ipath_dbg("Setting TxIdleEn on serdes (config0 = %llx)\n",
  1289. (unsigned long long) val);
  1290. ipath_write_kreg(dd, dd->ipath_kregs->kr_serdesconfig0, val);
  1291. }
  1292. /**
  1293. * ipath_pe_put_tid - write a TID in chip
  1294. * @dd: the infinipath device
  1295. * @tidptr: pointer to the expected TID (in chip) to udpate
  1296. * @tidtype: RCVHQ_RCV_TYPE_EAGER (1) for eager, RCVHQ_RCV_TYPE_EXPECTED (0) for expected
  1297. * @pa: physical address of in memory buffer; ipath_tidinvalid if freeing
  1298. *
  1299. * This exists as a separate routine to allow for special locking etc.
  1300. * It's used for both the full cleanup on exit, as well as the normal
  1301. * setup and teardown.
  1302. */
  1303. static void ipath_ht_put_tid(struct ipath_devdata *dd,
  1304. u64 __iomem *tidptr, u32 type,
  1305. unsigned long pa)
  1306. {
  1307. if (!dd->ipath_kregbase)
  1308. return;
  1309. if (pa != dd->ipath_tidinvalid) {
  1310. if (unlikely((pa & ~INFINIPATH_RT_ADDR_MASK))) {
  1311. dev_info(&dd->pcidev->dev,
  1312. "physaddr %lx has more than "
  1313. "40 bits, using only 40!!!\n", pa);
  1314. pa &= INFINIPATH_RT_ADDR_MASK;
  1315. }
  1316. if (type == RCVHQ_RCV_TYPE_EAGER)
  1317. pa |= dd->ipath_tidtemplate;
  1318. else {
  1319. /* in words (fixed, full page). */
  1320. u64 lenvalid = PAGE_SIZE >> 2;
  1321. lenvalid <<= INFINIPATH_RT_BUFSIZE_SHIFT;
  1322. pa |= lenvalid | INFINIPATH_RT_VALID;
  1323. }
  1324. }
  1325. writeq(pa, tidptr);
  1326. }
  1327. /**
  1328. * ipath_ht_clear_tid - clear all TID entries for a port, expected and eager
  1329. * @dd: the infinipath device
  1330. * @port: the port
  1331. *
  1332. * Used from ipath_close(), and at chip initialization.
  1333. */
  1334. static void ipath_ht_clear_tids(struct ipath_devdata *dd, unsigned port)
  1335. {
  1336. u64 __iomem *tidbase;
  1337. int i;
  1338. if (!dd->ipath_kregbase)
  1339. return;
  1340. ipath_cdbg(VERBOSE, "Invalidate TIDs for port %u\n", port);
  1341. /*
  1342. * need to invalidate all of the expected TID entries for this
  1343. * port, so we don't have valid entries that might somehow get
  1344. * used (early in next use of this port, or through some bug)
  1345. */
  1346. tidbase = (u64 __iomem *) ((char __iomem *)(dd->ipath_kregbase) +
  1347. dd->ipath_rcvtidbase +
  1348. port * dd->ipath_rcvtidcnt *
  1349. sizeof(*tidbase));
  1350. for (i = 0; i < dd->ipath_rcvtidcnt; i++)
  1351. ipath_ht_put_tid(dd, &tidbase[i], RCVHQ_RCV_TYPE_EXPECTED,
  1352. dd->ipath_tidinvalid);
  1353. tidbase = (u64 __iomem *) ((char __iomem *)(dd->ipath_kregbase) +
  1354. dd->ipath_rcvegrbase +
  1355. port * dd->ipath_rcvegrcnt *
  1356. sizeof(*tidbase));
  1357. for (i = 0; i < dd->ipath_rcvegrcnt; i++)
  1358. ipath_ht_put_tid(dd, &tidbase[i], RCVHQ_RCV_TYPE_EAGER,
  1359. dd->ipath_tidinvalid);
  1360. }
  1361. /**
  1362. * ipath_ht_tidtemplate - setup constants for TID updates
  1363. * @dd: the infinipath device
  1364. *
  1365. * We setup stuff that we use a lot, to avoid calculating each time
  1366. */
  1367. static void ipath_ht_tidtemplate(struct ipath_devdata *dd)
  1368. {
  1369. dd->ipath_tidtemplate = dd->ipath_ibmaxlen >> 2;
  1370. dd->ipath_tidtemplate <<= INFINIPATH_RT_BUFSIZE_SHIFT;
  1371. dd->ipath_tidtemplate |= INFINIPATH_RT_VALID;
  1372. /*
  1373. * work around chip errata bug 7358, by marking invalid tids
  1374. * as having max length
  1375. */
  1376. dd->ipath_tidinvalid = (-1LL & INFINIPATH_RT_BUFSIZE_MASK) <<
  1377. INFINIPATH_RT_BUFSIZE_SHIFT;
  1378. }
  1379. static int ipath_ht_early_init(struct ipath_devdata *dd)
  1380. {
  1381. u32 __iomem *piobuf;
  1382. u32 pioincr, val32;
  1383. int i;
  1384. /*
  1385. * one cache line; long IB headers will spill over into received
  1386. * buffer
  1387. */
  1388. dd->ipath_rcvhdrentsize = 16;
  1389. dd->ipath_rcvhdrsize = IPATH_DFLT_RCVHDRSIZE;
  1390. /*
  1391. * For HT, we allocate a somewhat overly large eager buffer,
  1392. * such that we can guarantee that we can receive the largest
  1393. * packet that we can send out. To truly support a 4KB MTU,
  1394. * we need to bump this to a large value. To date, other than
  1395. * testing, we have never encountered an HCA that can really
  1396. * send 4KB MTU packets, so we do not handle that (we'll get
  1397. * errors interrupts if we ever see one).
  1398. */
  1399. dd->ipath_rcvegrbufsize = dd->ipath_piosize2k;
  1400. /*
  1401. * the min() check here is currently a nop, but it may not
  1402. * always be, depending on just how we do ipath_rcvegrbufsize
  1403. */
  1404. dd->ipath_ibmaxlen = min(dd->ipath_piosize2k,
  1405. dd->ipath_rcvegrbufsize);
  1406. dd->ipath_init_ibmaxlen = dd->ipath_ibmaxlen;
  1407. ipath_ht_tidtemplate(dd);
  1408. /*
  1409. * zero all the TID entries at startup. We do this for sanity,
  1410. * in case of a previous driver crash of some kind, and also
  1411. * because the chip powers up with these memories in an unknown
  1412. * state. Use portcnt, not cfgports, since this is for the
  1413. * full chip, not for current (possibly different) configuration
  1414. * value.
  1415. * Chip Errata bug 6447
  1416. */
  1417. for (val32 = 0; val32 < dd->ipath_portcnt; val32++)
  1418. ipath_ht_clear_tids(dd, val32);
  1419. /*
  1420. * write the pbc of each buffer, to be sure it's initialized, then
  1421. * cancel all the buffers, and also abort any packets that might
  1422. * have been in flight for some reason (the latter is for driver
  1423. * unload/reload, but isn't a bad idea at first init). PIO send
  1424. * isn't enabled at this point, so there is no danger of sending
  1425. * these out on the wire.
  1426. * Chip Errata bug 6610
  1427. */
  1428. piobuf = (u32 __iomem *) (((char __iomem *)(dd->ipath_kregbase)) +
  1429. dd->ipath_piobufbase);
  1430. pioincr = dd->ipath_palign / sizeof(*piobuf);
  1431. for (i = 0; i < dd->ipath_piobcnt2k; i++) {
  1432. /*
  1433. * reasonable word count, just to init pbc
  1434. */
  1435. writel(16, piobuf);
  1436. piobuf += pioincr;
  1437. }
  1438. ipath_get_eeprom_info(dd);
  1439. if (dd->ipath_boardrev == 5 && dd->ipath_serial[0] == '1' &&
  1440. dd->ipath_serial[1] == '2' && dd->ipath_serial[2] == '8') {
  1441. /*
  1442. * Later production QHT7040 has same changes as QHT7140, so
  1443. * can use GPIO interrupts. They have serial #'s starting
  1444. * with 128, rather than 112.
  1445. */
  1446. dd->ipath_flags |= IPATH_GPIO_INTR;
  1447. dd->ipath_flags &= ~IPATH_POLL_RX_INTR;
  1448. }
  1449. return 0;
  1450. }
  1451. static int ipath_ht_txe_recover(struct ipath_devdata *dd)
  1452. {
  1453. int cnt = ++ipath_stats.sps_txeparity;
  1454. if (cnt >= IPATH_MAX_PARITY_ATTEMPTS) {
  1455. if (cnt == IPATH_MAX_PARITY_ATTEMPTS)
  1456. ipath_dev_err(dd,
  1457. "Too many attempts to recover from "
  1458. "TXE parity, giving up\n");
  1459. return 0;
  1460. }
  1461. dev_info(&dd->pcidev->dev,
  1462. "Recovering from TXE PIO parity error\n");
  1463. return 1;
  1464. }
  1465. /**
  1466. * ipath_init_ht_get_base_info - set chip-specific flags for user code
  1467. * @dd: the infinipath device
  1468. * @kbase: ipath_base_info pointer
  1469. *
  1470. * We set the PCIE flag because the lower bandwidth on PCIe vs
  1471. * HyperTransport can affect some user packet algorithms.
  1472. */
  1473. static int ipath_ht_get_base_info(struct ipath_portdata *pd, void *kbase)
  1474. {
  1475. struct ipath_base_info *kinfo = kbase;
  1476. kinfo->spi_runtime_flags |= IPATH_RUNTIME_HT |
  1477. IPATH_RUNTIME_RCVHDR_COPY;
  1478. return 0;
  1479. }
  1480. static void ipath_ht_free_irq(struct ipath_devdata *dd)
  1481. {
  1482. free_irq(dd->ipath_irq, dd);
  1483. ht_destroy_irq(dd->ipath_irq);
  1484. dd->ipath_irq = 0;
  1485. dd->ipath_intconfig = 0;
  1486. }
  1487. /**
  1488. * ipath_init_iba6110_funcs - set up the chip-specific function pointers
  1489. * @dd: the infinipath device
  1490. *
  1491. * This is global, and is called directly at init to set up the
  1492. * chip-specific function pointers for later use.
  1493. */
  1494. void ipath_init_iba6110_funcs(struct ipath_devdata *dd)
  1495. {
  1496. dd->ipath_f_intrsetup = ipath_ht_intconfig;
  1497. dd->ipath_f_bus = ipath_setup_ht_config;
  1498. dd->ipath_f_reset = ipath_setup_ht_reset;
  1499. dd->ipath_f_get_boardname = ipath_ht_boardname;
  1500. dd->ipath_f_init_hwerrors = ipath_ht_init_hwerrors;
  1501. dd->ipath_f_early_init = ipath_ht_early_init;
  1502. dd->ipath_f_handle_hwerrors = ipath_ht_handle_hwerrors;
  1503. dd->ipath_f_quiet_serdes = ipath_ht_quiet_serdes;
  1504. dd->ipath_f_bringup_serdes = ipath_ht_bringup_serdes;
  1505. dd->ipath_f_clear_tids = ipath_ht_clear_tids;
  1506. dd->ipath_f_put_tid = ipath_ht_put_tid;
  1507. dd->ipath_f_cleanup = ipath_setup_ht_cleanup;
  1508. dd->ipath_f_setextled = ipath_setup_ht_setextled;
  1509. dd->ipath_f_get_base_info = ipath_ht_get_base_info;
  1510. dd->ipath_f_free_irq = ipath_ht_free_irq;
  1511. /*
  1512. * initialize chip-specific variables
  1513. */
  1514. dd->ipath_f_tidtemplate = ipath_ht_tidtemplate;
  1515. /*
  1516. * setup the register offsets, since they are different for each
  1517. * chip
  1518. */
  1519. dd->ipath_kregs = &ipath_ht_kregs;
  1520. dd->ipath_cregs = &ipath_ht_cregs;
  1521. /*
  1522. * do very early init that is needed before ipath_f_bus is
  1523. * called
  1524. */
  1525. ipath_init_ht_variables(dd);
  1526. }