ipath_iba6110.c 51 KB

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