ipath_ht400.c 51 KB

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