ipath_iba6110.c 62 KB

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