ipath_iba6110.c 52 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619
  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); powercycle to completely clear]",
  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. ((INFINIPATH_HWE_TXEMEMPARITYERR_PIOBUF |
  429. INFINIPATH_HWE_TXEMEMPARITYERR_PIOPBC)
  430. << INFINIPATH_HWE_TXEMEMPARITYERR_SHIFT))) ||
  431. (ipath_debug & __IPATH_VERBDBG))
  432. dev_info(&dd->pcidev->dev, "Hardware error: hwerr=0x%llx "
  433. "(cleared)\n", (unsigned long long) hwerrs);
  434. dd->ipath_lasthwerror |= hwerrs;
  435. if (hwerrs & ~dd->ipath_hwe_bitsextant)
  436. ipath_dev_err(dd, "hwerror interrupt with unknown errors "
  437. "%llx set\n", (unsigned long long)
  438. (hwerrs & ~dd->ipath_hwe_bitsextant));
  439. ctrl = ipath_read_kreg32(dd, dd->ipath_kregs->kr_control);
  440. if (ctrl & INFINIPATH_C_FREEZEMODE) {
  441. /*
  442. * parity errors in send memory are recoverable,
  443. * just cancel the send (if indicated in * sendbuffererror),
  444. * count the occurrence, unfreeze (if no other handled
  445. * hardware error bits are set), and continue. They can
  446. * occur if a processor speculative read is done to the PIO
  447. * buffer while we are sending a packet, for example.
  448. */
  449. if (hwerrs & ((INFINIPATH_HWE_TXEMEMPARITYERR_PIOBUF |
  450. INFINIPATH_HWE_TXEMEMPARITYERR_PIOPBC)
  451. << INFINIPATH_HWE_TXEMEMPARITYERR_SHIFT)) {
  452. ipath_stats.sps_txeparity++;
  453. ipath_dbg("Recovering from TXE parity error (%llu), "
  454. "hwerrstatus=%llx\n",
  455. (unsigned long long) ipath_stats.sps_txeparity,
  456. (unsigned long long) hwerrs);
  457. ipath_disarm_senderrbufs(dd);
  458. hwerrs &= ~((INFINIPATH_HWE_TXEMEMPARITYERR_PIOBUF |
  459. INFINIPATH_HWE_TXEMEMPARITYERR_PIOPBC)
  460. << INFINIPATH_HWE_TXEMEMPARITYERR_SHIFT);
  461. if (!hwerrs) { /* else leave in freeze mode */
  462. ipath_write_kreg(dd,
  463. dd->ipath_kregs->kr_control,
  464. dd->ipath_control);
  465. return;
  466. }
  467. }
  468. if (hwerrs) {
  469. /*
  470. * if any set that we aren't ignoring; only
  471. * make the complaint once, in case it's stuck
  472. * or recurring, and we get here multiple
  473. * times.
  474. */
  475. if (dd->ipath_flags & IPATH_INITTED) {
  476. ipath_dev_err(dd, "Fatal Hardware Error (freeze "
  477. "mode), no longer usable, SN %.16s\n",
  478. dd->ipath_serial);
  479. isfatal = 1;
  480. }
  481. *dd->ipath_statusp &= ~IPATH_STATUS_IB_READY;
  482. /* mark as having had error */
  483. *dd->ipath_statusp |= IPATH_STATUS_HWERROR;
  484. /*
  485. * mark as not usable, at a minimum until driver
  486. * is reloaded, probably until reboot, since no
  487. * other reset is possible.
  488. */
  489. dd->ipath_flags &= ~IPATH_INITTED;
  490. } else {
  491. ipath_dbg("Clearing freezemode on ignored hardware "
  492. "error\n");
  493. ctrl &= ~INFINIPATH_C_FREEZEMODE;
  494. ipath_write_kreg(dd, dd->ipath_kregs->kr_control,
  495. ctrl);
  496. }
  497. }
  498. *msg = '\0';
  499. /*
  500. * may someday want to decode into which bits are which
  501. * functional area for parity errors, etc.
  502. */
  503. if (hwerrs & (infinipath_hwe_htcmemparityerr_mask
  504. << INFINIPATH_HWE_HTCMEMPARITYERR_SHIFT)) {
  505. bits = (u32) ((hwerrs >>
  506. INFINIPATH_HWE_HTCMEMPARITYERR_SHIFT) &
  507. INFINIPATH_HWE_HTCMEMPARITYERR_MASK);
  508. snprintf(bitsmsg, sizeof bitsmsg, "[HTC Parity Errs %x] ",
  509. bits);
  510. strlcat(msg, bitsmsg, msgl);
  511. }
  512. ipath_format_hwerrors(hwerrs,
  513. ipath_6110_hwerror_msgs,
  514. sizeof(ipath_6110_hwerror_msgs) /
  515. sizeof(ipath_6110_hwerror_msgs[0]),
  516. msg, msgl);
  517. if (hwerrs & (_IPATH_HTLINK0_CRCBITS | _IPATH_HTLINK1_CRCBITS))
  518. hwerr_crcbits(dd, hwerrs, msg, msgl);
  519. if (hwerrs & INFINIPATH_HWE_MEMBISTFAILED) {
  520. strlcat(msg, "[Memory BIST test failed, InfiniPath hardware unusable]",
  521. msgl);
  522. /* ignore from now on, so disable until driver reloaded */
  523. dd->ipath_hwerrmask &= ~INFINIPATH_HWE_MEMBISTFAILED;
  524. ipath_write_kreg(dd, dd->ipath_kregs->kr_hwerrmask,
  525. dd->ipath_hwerrmask);
  526. }
  527. #define _IPATH_PLL_FAIL (INFINIPATH_HWE_COREPLL_FBSLIP | \
  528. INFINIPATH_HWE_COREPLL_RFSLIP | \
  529. INFINIPATH_HWE_HTBPLL_FBSLIP | \
  530. INFINIPATH_HWE_HTBPLL_RFSLIP | \
  531. INFINIPATH_HWE_HTAPLL_FBSLIP | \
  532. INFINIPATH_HWE_HTAPLL_RFSLIP)
  533. if (hwerrs & _IPATH_PLL_FAIL) {
  534. snprintf(bitsmsg, sizeof bitsmsg,
  535. "[PLL failed (%llx), InfiniPath hardware unusable]",
  536. (unsigned long long) (hwerrs & _IPATH_PLL_FAIL));
  537. strlcat(msg, bitsmsg, msgl);
  538. /* ignore from now on, so disable until driver reloaded */
  539. dd->ipath_hwerrmask &= ~(hwerrs & _IPATH_PLL_FAIL);
  540. ipath_write_kreg(dd, dd->ipath_kregs->kr_hwerrmask,
  541. dd->ipath_hwerrmask);
  542. }
  543. if (hwerrs & INFINIPATH_HWE_SERDESPLLFAILED) {
  544. /*
  545. * If it occurs, it is left masked since the eternal
  546. * interface is unused
  547. */
  548. dd->ipath_hwerrmask &= ~INFINIPATH_HWE_SERDESPLLFAILED;
  549. ipath_write_kreg(dd, dd->ipath_kregs->kr_hwerrmask,
  550. dd->ipath_hwerrmask);
  551. }
  552. ipath_dev_err(dd, "%s hardware error\n", msg);
  553. if (isfatal && !ipath_diag_inuse && dd->ipath_freezemsg)
  554. /*
  555. * for status file; if no trailing brace is copied,
  556. * we'll know it was truncated.
  557. */
  558. snprintf(dd->ipath_freezemsg,
  559. dd->ipath_freezelen, "{%s}", msg);
  560. bail:;
  561. }
  562. /**
  563. * ipath_ht_boardname - fill in the board name
  564. * @dd: the infinipath device
  565. * @name: the output buffer
  566. * @namelen: the size of the output buffer
  567. *
  568. * fill in the board name, based on the board revision register
  569. */
  570. static int ipath_ht_boardname(struct ipath_devdata *dd, char *name,
  571. size_t namelen)
  572. {
  573. char *n = NULL;
  574. u8 boardrev = dd->ipath_boardrev;
  575. int ret;
  576. switch (boardrev) {
  577. case 4: /* Ponderosa is one of the bringup boards */
  578. n = "Ponderosa";
  579. break;
  580. case 5:
  581. /*
  582. * original production board; two production levels, with
  583. * different serial number ranges. See ipath_ht_early_init() for
  584. * case where we enable IPATH_GPIO_INTR for later serial # range.
  585. */
  586. n = "InfiniPath_QHT7040";
  587. break;
  588. case 6:
  589. n = "OEM_Board_3";
  590. break;
  591. case 7:
  592. /* small form factor production board */
  593. n = "InfiniPath_QHT7140";
  594. break;
  595. case 8:
  596. n = "LS/X-1";
  597. break;
  598. case 9: /* Comstock bringup test board */
  599. n = "Comstock";
  600. break;
  601. case 10:
  602. n = "OEM_Board_2";
  603. break;
  604. case 11:
  605. n = "InfiniPath_HT-470"; /* obsoleted */
  606. break;
  607. case 12:
  608. n = "OEM_Board_4";
  609. break;
  610. default: /* don't know, just print the number */
  611. ipath_dev_err(dd, "Don't yet know about board "
  612. "with ID %u\n", boardrev);
  613. snprintf(name, namelen, "Unknown_InfiniPath_QHT7xxx_%u",
  614. boardrev);
  615. break;
  616. }
  617. if (n)
  618. snprintf(name, namelen, "%s", n);
  619. if (dd->ipath_majrev != 3 || (dd->ipath_minrev < 2 || dd->ipath_minrev > 3)) {
  620. /*
  621. * This version of the driver only supports Rev 3.2 and 3.3
  622. */
  623. ipath_dev_err(dd,
  624. "Unsupported InfiniPath hardware revision %u.%u!\n",
  625. dd->ipath_majrev, dd->ipath_minrev);
  626. ret = 1;
  627. goto bail;
  628. }
  629. /*
  630. * pkt/word counters are 32 bit, and therefore wrap fast enough
  631. * that we snapshot them from a timer, and maintain 64 bit shadow
  632. * copies
  633. */
  634. dd->ipath_flags |= IPATH_32BITCOUNTERS;
  635. if (dd->ipath_htspeed != 800)
  636. ipath_dev_err(dd,
  637. "Incorrectly configured for HT @ %uMHz\n",
  638. dd->ipath_htspeed);
  639. if (dd->ipath_boardrev == 7 || dd->ipath_boardrev == 11 ||
  640. dd->ipath_boardrev == 6)
  641. dd->ipath_flags |= IPATH_GPIO_INTR;
  642. else
  643. dd->ipath_flags |= IPATH_POLL_RX_INTR;
  644. if (dd->ipath_boardrev == 8) { /* LS/X-1 */
  645. u64 val;
  646. val = ipath_read_kreg64(dd, dd->ipath_kregs->kr_extstatus);
  647. if (val & INFINIPATH_EXTS_SERDESSEL) {
  648. /*
  649. * hardware disabled
  650. *
  651. * This means that the chip is hardware disabled,
  652. * and will not be able to bring up the link,
  653. * in any case. We special case this and abort
  654. * early, to avoid later messages. We also set
  655. * the DISABLED status bit
  656. */
  657. ipath_dbg("Unit %u is hardware-disabled\n",
  658. dd->ipath_unit);
  659. *dd->ipath_statusp |= IPATH_STATUS_DISABLED;
  660. /* this value is handled differently */
  661. ret = 2;
  662. goto bail;
  663. }
  664. }
  665. ret = 0;
  666. bail:
  667. return ret;
  668. }
  669. static void ipath_check_htlink(struct ipath_devdata *dd)
  670. {
  671. u8 linkerr, link_off, i;
  672. for (i = 0; i < 2; i++) {
  673. link_off = dd->ipath_ht_slave_off + i * 4 + 0xd;
  674. if (pci_read_config_byte(dd->pcidev, link_off, &linkerr))
  675. dev_info(&dd->pcidev->dev, "Couldn't read "
  676. "linkerror%d of HT slave/primary block\n",
  677. i);
  678. else if (linkerr & 0xf0) {
  679. ipath_cdbg(VERBOSE, "HT linkerr%d bits 0x%x set, "
  680. "clearing\n", linkerr >> 4, i);
  681. /*
  682. * writing the linkerr bits that are set should
  683. * clear them
  684. */
  685. if (pci_write_config_byte(dd->pcidev, link_off,
  686. linkerr))
  687. ipath_dbg("Failed write to clear HT "
  688. "linkerror%d\n", i);
  689. if (pci_read_config_byte(dd->pcidev, link_off,
  690. &linkerr))
  691. dev_info(&dd->pcidev->dev,
  692. "Couldn't reread linkerror%d of "
  693. "HT slave/primary block\n", i);
  694. else if (linkerr & 0xf0)
  695. dev_info(&dd->pcidev->dev,
  696. "HT linkerror%d bits 0x%x "
  697. "couldn't be cleared\n",
  698. i, linkerr >> 4);
  699. }
  700. }
  701. }
  702. static int ipath_setup_ht_reset(struct ipath_devdata *dd)
  703. {
  704. ipath_dbg("No reset possible for this InfiniPath hardware\n");
  705. return 0;
  706. }
  707. #define HT_INTR_DISC_CONFIG 0x80 /* HT interrupt and discovery cap */
  708. #define HT_INTR_REG_INDEX 2 /* intconfig requires indirect accesses */
  709. /*
  710. * Bits 13-15 of command==0 is slave/primary block. Clear any HT CRC
  711. * errors. We only bother to do this at load time, because it's OK if
  712. * it happened before we were loaded (first time after boot/reset),
  713. * but any time after that, it's fatal anyway. Also need to not check
  714. * for for upper byte errors if we are in 8 bit mode, so figure out
  715. * our width. For now, at least, also complain if it's 8 bit.
  716. */
  717. static void slave_or_pri_blk(struct ipath_devdata *dd, struct pci_dev *pdev,
  718. int pos, u8 cap_type)
  719. {
  720. u8 linkwidth = 0, linkerr, link_a_b_off, link_off;
  721. u16 linkctrl = 0;
  722. int i;
  723. dd->ipath_ht_slave_off = pos;
  724. /* command word, master_host bit */
  725. /* master host || slave */
  726. if ((cap_type >> 2) & 1)
  727. link_a_b_off = 4;
  728. else
  729. link_a_b_off = 0;
  730. ipath_cdbg(VERBOSE, "HT%u (Link %c) connected to processor\n",
  731. link_a_b_off ? 1 : 0,
  732. link_a_b_off ? 'B' : 'A');
  733. link_a_b_off += pos;
  734. /*
  735. * check both link control registers; clear both HT CRC sets if
  736. * necessary.
  737. */
  738. for (i = 0; i < 2; i++) {
  739. link_off = pos + i * 4 + 0x4;
  740. if (pci_read_config_word(pdev, link_off, &linkctrl))
  741. ipath_dev_err(dd, "Couldn't read HT link control%d "
  742. "register\n", i);
  743. else if (linkctrl & (0xf << 8)) {
  744. ipath_cdbg(VERBOSE, "Clear linkctrl%d CRC Error "
  745. "bits %x\n", i, linkctrl & (0xf << 8));
  746. /*
  747. * now write them back to clear the error.
  748. */
  749. pci_write_config_byte(pdev, link_off,
  750. linkctrl & (0xf << 8));
  751. }
  752. }
  753. /*
  754. * As with HT CRC bits, same for protocol errors that might occur
  755. * during boot.
  756. */
  757. for (i = 0; i < 2; i++) {
  758. link_off = pos + i * 4 + 0xd;
  759. if (pci_read_config_byte(pdev, link_off, &linkerr))
  760. dev_info(&pdev->dev, "Couldn't read linkerror%d "
  761. "of HT slave/primary block\n", i);
  762. else if (linkerr & 0xf0) {
  763. ipath_cdbg(VERBOSE, "HT linkerr%d bits 0x%x set, "
  764. "clearing\n", linkerr >> 4, i);
  765. /*
  766. * writing the linkerr bits that are set will clear
  767. * them
  768. */
  769. if (pci_write_config_byte
  770. (pdev, link_off, linkerr))
  771. ipath_dbg("Failed write to clear HT "
  772. "linkerror%d\n", i);
  773. if (pci_read_config_byte(pdev, link_off, &linkerr))
  774. dev_info(&pdev->dev, "Couldn't reread "
  775. "linkerror%d of HT slave/primary "
  776. "block\n", i);
  777. else if (linkerr & 0xf0)
  778. dev_info(&pdev->dev, "HT linkerror%d bits "
  779. "0x%x couldn't be cleared\n",
  780. i, linkerr >> 4);
  781. }
  782. }
  783. /*
  784. * this is just for our link to the host, not devices connected
  785. * through tunnel.
  786. */
  787. if (pci_read_config_byte(pdev, link_a_b_off + 7, &linkwidth))
  788. ipath_dev_err(dd, "Couldn't read HT link width "
  789. "config register\n");
  790. else {
  791. u32 width;
  792. switch (linkwidth & 7) {
  793. case 5:
  794. width = 4;
  795. break;
  796. case 4:
  797. width = 2;
  798. break;
  799. case 3:
  800. width = 32;
  801. break;
  802. case 1:
  803. width = 16;
  804. break;
  805. case 0:
  806. default: /* if wrong, assume 8 bit */
  807. width = 8;
  808. break;
  809. }
  810. dd->ipath_htwidth = width;
  811. if (linkwidth != 0x11) {
  812. ipath_dev_err(dd, "Not configured for 16 bit HT "
  813. "(%x)\n", linkwidth);
  814. if (!(linkwidth & 0xf)) {
  815. ipath_dbg("Will ignore HT lane1 errors\n");
  816. dd->ipath_flags |= IPATH_8BIT_IN_HT0;
  817. }
  818. }
  819. }
  820. /*
  821. * this is just for our link to the host, not devices connected
  822. * through tunnel.
  823. */
  824. if (pci_read_config_byte(pdev, link_a_b_off + 0xd, &linkwidth))
  825. ipath_dev_err(dd, "Couldn't read HT link frequency "
  826. "config register\n");
  827. else {
  828. u32 speed;
  829. switch (linkwidth & 0xf) {
  830. case 6:
  831. speed = 1000;
  832. break;
  833. case 5:
  834. speed = 800;
  835. break;
  836. case 4:
  837. speed = 600;
  838. break;
  839. case 3:
  840. speed = 500;
  841. break;
  842. case 2:
  843. speed = 400;
  844. break;
  845. case 1:
  846. speed = 300;
  847. break;
  848. default:
  849. /*
  850. * assume reserved and vendor-specific are 200...
  851. */
  852. case 0:
  853. speed = 200;
  854. break;
  855. }
  856. dd->ipath_htspeed = speed;
  857. }
  858. }
  859. static int set_int_handler(struct ipath_devdata *dd, struct pci_dev *pdev,
  860. int pos)
  861. {
  862. u32 int_handler_addr_lower;
  863. u32 int_handler_addr_upper;
  864. u64 ihandler;
  865. u32 intvec;
  866. /* use indirection register to get the intr handler */
  867. pci_write_config_byte(pdev, pos + HT_INTR_REG_INDEX, 0x10);
  868. pci_read_config_dword(pdev, pos + 4, &int_handler_addr_lower);
  869. pci_write_config_byte(pdev, pos + HT_INTR_REG_INDEX, 0x11);
  870. pci_read_config_dword(pdev, pos + 4, &int_handler_addr_upper);
  871. ihandler = (u64) int_handler_addr_lower |
  872. ((u64) int_handler_addr_upper << 32);
  873. /*
  874. * kernels with CONFIG_PCI_MSI set the vector in the irq field of
  875. * struct pci_device, so we use that to program the internal
  876. * interrupt register (not config space) with that value. The BIOS
  877. * must still have done the basic MSI setup.
  878. */
  879. intvec = pdev->irq;
  880. /*
  881. * clear any vector bits there; normally not set but we'll overload
  882. * this for some debug purposes (setting the HTC debug register
  883. * value from software, rather than GPIOs), so it might be set on a
  884. * driver reload.
  885. */
  886. ihandler &= ~0xff0000;
  887. /* x86 vector goes in intrinfo[23:16] */
  888. ihandler |= intvec << 16;
  889. ipath_cdbg(VERBOSE, "ihandler lower %x, upper %x, intvec %x, "
  890. "interruptconfig %llx\n", int_handler_addr_lower,
  891. int_handler_addr_upper, intvec,
  892. (unsigned long long) ihandler);
  893. /* can't program yet, so save for interrupt setup */
  894. dd->ipath_intconfig = ihandler;
  895. /* keep going, so we find link control stuff also */
  896. return ihandler != 0;
  897. }
  898. /**
  899. * ipath_setup_ht_config - setup the interruptconfig register
  900. * @dd: the infinipath device
  901. * @pdev: the PCI device
  902. *
  903. * setup the interruptconfig register from the HT config info.
  904. * Also clear CRC errors in HT linkcontrol, if necessary.
  905. * This is done only for the real hardware. It is done before
  906. * chip address space is initted, so can't touch infinipath registers
  907. */
  908. static int ipath_setup_ht_config(struct ipath_devdata *dd,
  909. struct pci_dev *pdev)
  910. {
  911. int pos, ret = 0;
  912. int ihandler = 0;
  913. /*
  914. * Read the capability info to find the interrupt info, and also
  915. * handle clearing CRC errors in linkctrl register if necessary. We
  916. * do this early, before we ever enable errors or hardware errors,
  917. * mostly to avoid causing the chip to enter freeze mode.
  918. */
  919. pos = pci_find_capability(pdev, PCI_CAP_ID_HT);
  920. if (!pos) {
  921. ipath_dev_err(dd, "Couldn't find HyperTransport "
  922. "capability; no interrupts\n");
  923. ret = -ENODEV;
  924. goto bail;
  925. }
  926. do {
  927. u8 cap_type;
  928. /* the HT capability type byte is 3 bytes after the
  929. * capability byte.
  930. */
  931. if (pci_read_config_byte(pdev, pos + 3, &cap_type)) {
  932. dev_info(&pdev->dev, "Couldn't read config "
  933. "command @ %d\n", pos);
  934. continue;
  935. }
  936. if (!(cap_type & 0xE0))
  937. slave_or_pri_blk(dd, pdev, pos, cap_type);
  938. else if (cap_type == HT_INTR_DISC_CONFIG)
  939. ihandler = set_int_handler(dd, pdev, pos);
  940. } while ((pos = pci_find_next_capability(pdev, pos,
  941. PCI_CAP_ID_HT)));
  942. if (!ihandler) {
  943. ipath_dev_err(dd, "Couldn't find interrupt handler in "
  944. "config space\n");
  945. ret = -ENODEV;
  946. }
  947. bail:
  948. return ret;
  949. }
  950. /**
  951. * ipath_setup_ht_cleanup - clean up any per-chip chip-specific stuff
  952. * @dd: the infinipath device
  953. *
  954. * Called during driver unload.
  955. * This is currently a nop for the HT chip, not for all chips
  956. */
  957. static void ipath_setup_ht_cleanup(struct ipath_devdata *dd)
  958. {
  959. }
  960. /**
  961. * ipath_setup_ht_setextled - set the state of the two external LEDs
  962. * @dd: the infinipath device
  963. * @lst: the L state
  964. * @ltst: the LT state
  965. *
  966. * Set the state of the two external LEDs, to indicate physical and
  967. * logical state of IB link. For this chip (at least with recommended
  968. * board pinouts), LED1 is Green (physical state), and LED2 is Yellow
  969. * (logical state)
  970. *
  971. * Note: We try to match the Mellanox HCA LED behavior as best
  972. * we can. Green indicates physical link state is OK (something is
  973. * plugged in, and we can train).
  974. * Amber indicates the link is logically up (ACTIVE).
  975. * Mellanox further blinks the amber LED to indicate data packet
  976. * activity, but we have no hardware support for that, so it would
  977. * require waking up every 10-20 msecs and checking the counters
  978. * on the chip, and then turning the LED off if appropriate. That's
  979. * visible overhead, so not something we will do.
  980. *
  981. */
  982. static void ipath_setup_ht_setextled(struct ipath_devdata *dd,
  983. u64 lst, u64 ltst)
  984. {
  985. u64 extctl;
  986. /* the diags use the LED to indicate diag info, so we leave
  987. * the external LED alone when the diags are running */
  988. if (ipath_diag_inuse)
  989. return;
  990. /*
  991. * start by setting both LED control bits to off, then turn
  992. * on the appropriate bit(s).
  993. */
  994. if (dd->ipath_boardrev == 8) { /* LS/X-1 uses different pins */
  995. /*
  996. * major difference is that INFINIPATH_EXTC_LEDGBLERR_OFF
  997. * is inverted, because it is normally used to indicate
  998. * a hardware fault at reset, if there were errors
  999. */
  1000. extctl = (dd->ipath_extctrl & ~INFINIPATH_EXTC_LEDGBLOK_ON)
  1001. | INFINIPATH_EXTC_LEDGBLERR_OFF;
  1002. if (ltst == INFINIPATH_IBCS_LT_STATE_LINKUP)
  1003. extctl &= ~INFINIPATH_EXTC_LEDGBLERR_OFF;
  1004. if (lst == INFINIPATH_IBCS_L_STATE_ACTIVE)
  1005. extctl |= INFINIPATH_EXTC_LEDGBLOK_ON;
  1006. }
  1007. else {
  1008. extctl = dd->ipath_extctrl &
  1009. ~(INFINIPATH_EXTC_LED1PRIPORT_ON |
  1010. INFINIPATH_EXTC_LED2PRIPORT_ON);
  1011. if (ltst == INFINIPATH_IBCS_LT_STATE_LINKUP)
  1012. extctl |= INFINIPATH_EXTC_LED1PRIPORT_ON;
  1013. if (lst == INFINIPATH_IBCS_L_STATE_ACTIVE)
  1014. extctl |= INFINIPATH_EXTC_LED2PRIPORT_ON;
  1015. }
  1016. dd->ipath_extctrl = extctl;
  1017. ipath_write_kreg(dd, dd->ipath_kregs->kr_extctrl, extctl);
  1018. }
  1019. static void ipath_init_ht_variables(struct ipath_devdata *dd)
  1020. {
  1021. dd->ipath_gpio_sda_num = _IPATH_GPIO_SDA_NUM;
  1022. dd->ipath_gpio_scl_num = _IPATH_GPIO_SCL_NUM;
  1023. dd->ipath_gpio_sda = IPATH_GPIO_SDA;
  1024. dd->ipath_gpio_scl = IPATH_GPIO_SCL;
  1025. dd->ipath_i_bitsextant =
  1026. (INFINIPATH_I_RCVURG_MASK << INFINIPATH_I_RCVURG_SHIFT) |
  1027. (INFINIPATH_I_RCVAVAIL_MASK <<
  1028. INFINIPATH_I_RCVAVAIL_SHIFT) |
  1029. INFINIPATH_I_ERROR | INFINIPATH_I_SPIOSENT |
  1030. INFINIPATH_I_SPIOBUFAVAIL | INFINIPATH_I_GPIO;
  1031. dd->ipath_e_bitsextant =
  1032. INFINIPATH_E_RFORMATERR | INFINIPATH_E_RVCRC |
  1033. INFINIPATH_E_RICRC | INFINIPATH_E_RMINPKTLEN |
  1034. INFINIPATH_E_RMAXPKTLEN | INFINIPATH_E_RLONGPKTLEN |
  1035. INFINIPATH_E_RSHORTPKTLEN | INFINIPATH_E_RUNEXPCHAR |
  1036. INFINIPATH_E_RUNSUPVL | INFINIPATH_E_REBP |
  1037. INFINIPATH_E_RIBFLOW | INFINIPATH_E_RBADVERSION |
  1038. INFINIPATH_E_RRCVEGRFULL | INFINIPATH_E_RRCVHDRFULL |
  1039. INFINIPATH_E_RBADTID | INFINIPATH_E_RHDRLEN |
  1040. INFINIPATH_E_RHDR | INFINIPATH_E_RIBLOSTLINK |
  1041. INFINIPATH_E_SMINPKTLEN | INFINIPATH_E_SMAXPKTLEN |
  1042. INFINIPATH_E_SUNDERRUN | INFINIPATH_E_SPKTLEN |
  1043. INFINIPATH_E_SDROPPEDSMPPKT | INFINIPATH_E_SDROPPEDDATAPKT |
  1044. INFINIPATH_E_SPIOARMLAUNCH | INFINIPATH_E_SUNEXPERRPKTNUM |
  1045. INFINIPATH_E_SUNSUPVL | INFINIPATH_E_IBSTATUSCHANGED |
  1046. INFINIPATH_E_INVALIDADDR | INFINIPATH_E_RESET |
  1047. INFINIPATH_E_HARDWARE;
  1048. dd->ipath_hwe_bitsextant =
  1049. (INFINIPATH_HWE_HTCMEMPARITYERR_MASK <<
  1050. INFINIPATH_HWE_HTCMEMPARITYERR_SHIFT) |
  1051. (INFINIPATH_HWE_TXEMEMPARITYERR_MASK <<
  1052. INFINIPATH_HWE_TXEMEMPARITYERR_SHIFT) |
  1053. (INFINIPATH_HWE_RXEMEMPARITYERR_MASK <<
  1054. INFINIPATH_HWE_RXEMEMPARITYERR_SHIFT) |
  1055. INFINIPATH_HWE_HTCLNKABYTE0CRCERR |
  1056. INFINIPATH_HWE_HTCLNKABYTE1CRCERR |
  1057. INFINIPATH_HWE_HTCLNKBBYTE0CRCERR |
  1058. INFINIPATH_HWE_HTCLNKBBYTE1CRCERR |
  1059. INFINIPATH_HWE_HTCMISCERR4 |
  1060. INFINIPATH_HWE_HTCMISCERR5 | INFINIPATH_HWE_HTCMISCERR6 |
  1061. INFINIPATH_HWE_HTCMISCERR7 |
  1062. INFINIPATH_HWE_HTCBUSTREQPARITYERR |
  1063. INFINIPATH_HWE_HTCBUSTRESPPARITYERR |
  1064. INFINIPATH_HWE_HTCBUSIREQPARITYERR |
  1065. INFINIPATH_HWE_RXDSYNCMEMPARITYERR |
  1066. INFINIPATH_HWE_MEMBISTFAILED |
  1067. INFINIPATH_HWE_COREPLL_FBSLIP |
  1068. INFINIPATH_HWE_COREPLL_RFSLIP |
  1069. INFINIPATH_HWE_HTBPLL_FBSLIP |
  1070. INFINIPATH_HWE_HTBPLL_RFSLIP |
  1071. INFINIPATH_HWE_HTAPLL_FBSLIP |
  1072. INFINIPATH_HWE_HTAPLL_RFSLIP |
  1073. INFINIPATH_HWE_SERDESPLLFAILED |
  1074. INFINIPATH_HWE_IBCBUSTOSPCPARITYERR |
  1075. INFINIPATH_HWE_IBCBUSFRSPCPARITYERR;
  1076. dd->ipath_i_rcvavail_mask = INFINIPATH_I_RCVAVAIL_MASK;
  1077. dd->ipath_i_rcvurg_mask = INFINIPATH_I_RCVURG_MASK;
  1078. }
  1079. /**
  1080. * ipath_ht_init_hwerrors - enable hardware errors
  1081. * @dd: the infinipath device
  1082. *
  1083. * now that we have finished initializing everything that might reasonably
  1084. * cause a hardware error, and cleared those errors bits as they occur,
  1085. * we can enable hardware errors in the mask (potentially enabling
  1086. * freeze mode), and enable hardware errors as errors (along with
  1087. * everything else) in errormask
  1088. */
  1089. static void ipath_ht_init_hwerrors(struct ipath_devdata *dd)
  1090. {
  1091. ipath_err_t val;
  1092. u64 extsval;
  1093. extsval = ipath_read_kreg64(dd, dd->ipath_kregs->kr_extstatus);
  1094. if (!(extsval & INFINIPATH_EXTS_MEMBIST_ENDTEST))
  1095. ipath_dev_err(dd, "MemBIST did not complete!\n");
  1096. ipath_check_htlink(dd);
  1097. /* barring bugs, all hwerrors become interrupts, which can */
  1098. val = -1LL;
  1099. /* don't look at crc lane1 if 8 bit */
  1100. if (dd->ipath_flags & IPATH_8BIT_IN_HT0)
  1101. val &= ~infinipath_hwe_htclnkabyte1crcerr;
  1102. /* don't look at crc lane1 if 8 bit */
  1103. if (dd->ipath_flags & IPATH_8BIT_IN_HT1)
  1104. val &= ~infinipath_hwe_htclnkbbyte1crcerr;
  1105. /*
  1106. * disable RXDSYNCMEMPARITY because external serdes is unused,
  1107. * and therefore the logic will never be used or initialized,
  1108. * and uninitialized state will normally result in this error
  1109. * being asserted. Similarly for the external serdess pll
  1110. * lock signal.
  1111. */
  1112. val &= ~(INFINIPATH_HWE_SERDESPLLFAILED |
  1113. INFINIPATH_HWE_RXDSYNCMEMPARITYERR);
  1114. /*
  1115. * Disable MISCERR4 because of an inversion in the HT core
  1116. * logic checking for errors that cause this bit to be set.
  1117. * The errata can also cause the protocol error bit to be set
  1118. * in the HT config space linkerror register(s).
  1119. */
  1120. val &= ~INFINIPATH_HWE_HTCMISCERR4;
  1121. /*
  1122. * PLL ignored because MDIO interface has a logic problem
  1123. * for reads, on Comstock and Ponderosa. BRINGUP
  1124. */
  1125. if (dd->ipath_boardrev == 4 || dd->ipath_boardrev == 9)
  1126. val &= ~INFINIPATH_HWE_SERDESPLLFAILED;
  1127. dd->ipath_hwerrmask = val;
  1128. }
  1129. /**
  1130. * ipath_ht_bringup_serdes - bring up the serdes
  1131. * @dd: the infinipath device
  1132. */
  1133. static int ipath_ht_bringup_serdes(struct ipath_devdata *dd)
  1134. {
  1135. u64 val, config1;
  1136. int ret = 0, change = 0;
  1137. ipath_dbg("Trying to bringup serdes\n");
  1138. if (ipath_read_kreg64(dd, dd->ipath_kregs->kr_hwerrstatus) &
  1139. INFINIPATH_HWE_SERDESPLLFAILED)
  1140. {
  1141. ipath_dbg("At start, serdes PLL failed bit set in "
  1142. "hwerrstatus, clearing and continuing\n");
  1143. ipath_write_kreg(dd, dd->ipath_kregs->kr_hwerrclear,
  1144. INFINIPATH_HWE_SERDESPLLFAILED);
  1145. }
  1146. val = ipath_read_kreg64(dd, dd->ipath_kregs->kr_serdesconfig0);
  1147. config1 = ipath_read_kreg64(dd, dd->ipath_kregs->kr_serdesconfig1);
  1148. ipath_cdbg(VERBOSE, "Initial serdes status is config0=%llx "
  1149. "config1=%llx, sstatus=%llx xgxs %llx\n",
  1150. (unsigned long long) val, (unsigned long long) config1,
  1151. (unsigned long long)
  1152. ipath_read_kreg64(dd, dd->ipath_kregs->kr_serdesstatus),
  1153. (unsigned long long)
  1154. ipath_read_kreg64(dd, dd->ipath_kregs->kr_xgxsconfig));
  1155. /* force reset on */
  1156. val |= INFINIPATH_SERDC0_RESET_PLL
  1157. /* | INFINIPATH_SERDC0_RESET_MASK */
  1158. ;
  1159. ipath_write_kreg(dd, dd->ipath_kregs->kr_serdesconfig0, val);
  1160. udelay(15); /* need pll reset set at least for a bit */
  1161. if (val & INFINIPATH_SERDC0_RESET_PLL) {
  1162. u64 val2 = val &= ~INFINIPATH_SERDC0_RESET_PLL;
  1163. /* set lane resets, and tx idle, during pll reset */
  1164. val2 |= INFINIPATH_SERDC0_RESET_MASK |
  1165. INFINIPATH_SERDC0_TXIDLE;
  1166. ipath_cdbg(VERBOSE, "Clearing serdes PLL reset (writing "
  1167. "%llx)\n", (unsigned long long) val2);
  1168. ipath_write_kreg(dd, dd->ipath_kregs->kr_serdesconfig0,
  1169. val2);
  1170. /*
  1171. * be sure chip saw it
  1172. */
  1173. val = ipath_read_kreg64(dd, dd->ipath_kregs->kr_scratch);
  1174. /*
  1175. * need pll reset clear at least 11 usec before lane
  1176. * resets cleared; give it a few more
  1177. */
  1178. udelay(15);
  1179. val = val2; /* for check below */
  1180. }
  1181. if (val & (INFINIPATH_SERDC0_RESET_PLL |
  1182. INFINIPATH_SERDC0_RESET_MASK |
  1183. INFINIPATH_SERDC0_TXIDLE)) {
  1184. val &= ~(INFINIPATH_SERDC0_RESET_PLL |
  1185. INFINIPATH_SERDC0_RESET_MASK |
  1186. INFINIPATH_SERDC0_TXIDLE);
  1187. /* clear them */
  1188. ipath_write_kreg(dd, dd->ipath_kregs->kr_serdesconfig0,
  1189. val);
  1190. }
  1191. val = ipath_read_kreg64(dd, dd->ipath_kregs->kr_xgxsconfig);
  1192. if (((val >> INFINIPATH_XGXS_MDIOADDR_SHIFT) &
  1193. INFINIPATH_XGXS_MDIOADDR_MASK) != 3) {
  1194. val &= ~(INFINIPATH_XGXS_MDIOADDR_MASK <<
  1195. INFINIPATH_XGXS_MDIOADDR_SHIFT);
  1196. /*
  1197. * we use address 3
  1198. */
  1199. val |= 3ULL << INFINIPATH_XGXS_MDIOADDR_SHIFT;
  1200. change = 1;
  1201. }
  1202. if (val & INFINIPATH_XGXS_RESET) {
  1203. /* normally true after boot */
  1204. val &= ~INFINIPATH_XGXS_RESET;
  1205. change = 1;
  1206. }
  1207. if (((val >> INFINIPATH_XGXS_RX_POL_SHIFT) &
  1208. INFINIPATH_XGXS_RX_POL_MASK) != dd->ipath_rx_pol_inv ) {
  1209. /* need to compensate for Tx inversion in partner */
  1210. val &= ~(INFINIPATH_XGXS_RX_POL_MASK <<
  1211. INFINIPATH_XGXS_RX_POL_SHIFT);
  1212. val |= dd->ipath_rx_pol_inv <<
  1213. INFINIPATH_XGXS_RX_POL_SHIFT;
  1214. change = 1;
  1215. }
  1216. if (change)
  1217. ipath_write_kreg(dd, dd->ipath_kregs->kr_xgxsconfig, val);
  1218. val = ipath_read_kreg64(dd, dd->ipath_kregs->kr_serdesconfig0);
  1219. /* clear current and de-emphasis bits */
  1220. config1 &= ~0x0ffffffff00ULL;
  1221. /* set current to 20ma */
  1222. config1 |= 0x00000000000ULL;
  1223. /* set de-emphasis to -5.68dB */
  1224. config1 |= 0x0cccc000000ULL;
  1225. ipath_write_kreg(dd, dd->ipath_kregs->kr_serdesconfig1, config1);
  1226. ipath_cdbg(VERBOSE, "After setup: serdes status is config0=%llx "
  1227. "config1=%llx, sstatus=%llx xgxs %llx\n",
  1228. (unsigned long long) val, (unsigned long long) config1,
  1229. (unsigned long long)
  1230. ipath_read_kreg64(dd, dd->ipath_kregs->kr_serdesstatus),
  1231. (unsigned long long)
  1232. ipath_read_kreg64(dd, dd->ipath_kregs->kr_xgxsconfig));
  1233. if (!ipath_waitfor_mdio_cmdready(dd)) {
  1234. ipath_write_kreg(dd, dd->ipath_kregs->kr_mdio,
  1235. ipath_mdio_req(IPATH_MDIO_CMD_READ, 31,
  1236. IPATH_MDIO_CTRL_XGXS_REG_8,
  1237. 0));
  1238. if (ipath_waitfor_complete(dd, dd->ipath_kregs->kr_mdio,
  1239. IPATH_MDIO_DATAVALID, &val))
  1240. ipath_dbg("Never got MDIO data for XGXS status "
  1241. "read\n");
  1242. else
  1243. ipath_cdbg(VERBOSE, "MDIO Read reg8, "
  1244. "'bank' 31 %x\n", (u32) val);
  1245. } else
  1246. ipath_dbg("Never got MDIO cmdready for XGXS status read\n");
  1247. return ret; /* for now, say we always succeeded */
  1248. }
  1249. /**
  1250. * ipath_ht_quiet_serdes - set serdes to txidle
  1251. * @dd: the infinipath device
  1252. * driver is being unloaded
  1253. */
  1254. static void ipath_ht_quiet_serdes(struct ipath_devdata *dd)
  1255. {
  1256. u64 val = ipath_read_kreg64(dd, dd->ipath_kregs->kr_serdesconfig0);
  1257. val |= INFINIPATH_SERDC0_TXIDLE;
  1258. ipath_dbg("Setting TxIdleEn on serdes (config0 = %llx)\n",
  1259. (unsigned long long) val);
  1260. ipath_write_kreg(dd, dd->ipath_kregs->kr_serdesconfig0, val);
  1261. }
  1262. static int ipath_ht_intconfig(struct ipath_devdata *dd)
  1263. {
  1264. int ret;
  1265. if (!dd->ipath_intconfig) {
  1266. ipath_dev_err(dd, "No interrupts enabled, couldn't setup "
  1267. "interrupt address\n");
  1268. ret = 1;
  1269. goto bail;
  1270. }
  1271. ipath_write_kreg(dd, dd->ipath_kregs->kr_interruptconfig,
  1272. dd->ipath_intconfig); /* interrupt address */
  1273. ret = 0;
  1274. bail:
  1275. return ret;
  1276. }
  1277. /**
  1278. * ipath_pe_put_tid - write a TID in chip
  1279. * @dd: the infinipath device
  1280. * @tidptr: pointer to the expected TID (in chip) to udpate
  1281. * @tidtype: 0 for eager, 1 for expected
  1282. * @pa: physical address of in memory buffer; ipath_tidinvalid if freeing
  1283. *
  1284. * This exists as a separate routine to allow for special locking etc.
  1285. * It's used for both the full cleanup on exit, as well as the normal
  1286. * setup and teardown.
  1287. */
  1288. static void ipath_ht_put_tid(struct ipath_devdata *dd,
  1289. u64 __iomem *tidptr, u32 type,
  1290. unsigned long pa)
  1291. {
  1292. if (pa != dd->ipath_tidinvalid) {
  1293. if (unlikely((pa & ~INFINIPATH_RT_ADDR_MASK))) {
  1294. dev_info(&dd->pcidev->dev,
  1295. "physaddr %lx has more than "
  1296. "40 bits, using only 40!!!\n", pa);
  1297. pa &= INFINIPATH_RT_ADDR_MASK;
  1298. }
  1299. if (type == 0)
  1300. pa |= dd->ipath_tidtemplate;
  1301. else {
  1302. /* in words (fixed, full page). */
  1303. u64 lenvalid = PAGE_SIZE >> 2;
  1304. lenvalid <<= INFINIPATH_RT_BUFSIZE_SHIFT;
  1305. pa |= lenvalid | INFINIPATH_RT_VALID;
  1306. }
  1307. }
  1308. if (dd->ipath_kregbase)
  1309. writeq(pa, tidptr);
  1310. }
  1311. /**
  1312. * ipath_ht_clear_tid - clear all TID entries for a port, expected and eager
  1313. * @dd: the infinipath device
  1314. * @port: the port
  1315. *
  1316. * Used from ipath_close(), and at chip initialization.
  1317. */
  1318. static void ipath_ht_clear_tids(struct ipath_devdata *dd, unsigned port)
  1319. {
  1320. u64 __iomem *tidbase;
  1321. int i;
  1322. if (!dd->ipath_kregbase)
  1323. return;
  1324. ipath_cdbg(VERBOSE, "Invalidate TIDs for port %u\n", port);
  1325. /*
  1326. * need to invalidate all of the expected TID entries for this
  1327. * port, so we don't have valid entries that might somehow get
  1328. * used (early in next use of this port, or through some bug)
  1329. */
  1330. tidbase = (u64 __iomem *) ((char __iomem *)(dd->ipath_kregbase) +
  1331. dd->ipath_rcvtidbase +
  1332. port * dd->ipath_rcvtidcnt *
  1333. sizeof(*tidbase));
  1334. for (i = 0; i < dd->ipath_rcvtidcnt; i++)
  1335. ipath_ht_put_tid(dd, &tidbase[i], 1, dd->ipath_tidinvalid);
  1336. tidbase = (u64 __iomem *) ((char __iomem *)(dd->ipath_kregbase) +
  1337. dd->ipath_rcvegrbase +
  1338. port * dd->ipath_rcvegrcnt *
  1339. sizeof(*tidbase));
  1340. for (i = 0; i < dd->ipath_rcvegrcnt; i++)
  1341. ipath_ht_put_tid(dd, &tidbase[i], 0, dd->ipath_tidinvalid);
  1342. }
  1343. /**
  1344. * ipath_ht_tidtemplate - setup constants for TID updates
  1345. * @dd: the infinipath device
  1346. *
  1347. * We setup stuff that we use a lot, to avoid calculating each time
  1348. */
  1349. static void ipath_ht_tidtemplate(struct ipath_devdata *dd)
  1350. {
  1351. dd->ipath_tidtemplate = dd->ipath_ibmaxlen >> 2;
  1352. dd->ipath_tidtemplate <<= INFINIPATH_RT_BUFSIZE_SHIFT;
  1353. dd->ipath_tidtemplate |= INFINIPATH_RT_VALID;
  1354. /*
  1355. * work around chip errata bug 7358, by marking invalid tids
  1356. * as having max length
  1357. */
  1358. dd->ipath_tidinvalid = (-1LL & INFINIPATH_RT_BUFSIZE_MASK) <<
  1359. INFINIPATH_RT_BUFSIZE_SHIFT;
  1360. }
  1361. static int ipath_ht_early_init(struct ipath_devdata *dd)
  1362. {
  1363. u32 __iomem *piobuf;
  1364. u32 pioincr, val32, egrsize;
  1365. int i;
  1366. /*
  1367. * one cache line; long IB headers will spill over into received
  1368. * buffer
  1369. */
  1370. dd->ipath_rcvhdrentsize = 16;
  1371. dd->ipath_rcvhdrsize = IPATH_DFLT_RCVHDRSIZE;
  1372. /*
  1373. * For HT, we allocate a somewhat overly large eager buffer,
  1374. * such that we can guarantee that we can receive the largest
  1375. * packet that we can send out. To truly support a 4KB MTU,
  1376. * we need to bump this to a large value. To date, other than
  1377. * testing, we have never encountered an HCA that can really
  1378. * send 4KB MTU packets, so we do not handle that (we'll get
  1379. * errors interrupts if we ever see one).
  1380. */
  1381. dd->ipath_rcvegrbufsize = dd->ipath_piosize2k;
  1382. egrsize = dd->ipath_rcvegrbufsize;
  1383. /*
  1384. * the min() check here is currently a nop, but it may not
  1385. * always be, depending on just how we do ipath_rcvegrbufsize
  1386. */
  1387. dd->ipath_ibmaxlen = min(dd->ipath_piosize2k,
  1388. dd->ipath_rcvegrbufsize);
  1389. dd->ipath_init_ibmaxlen = dd->ipath_ibmaxlen;
  1390. ipath_ht_tidtemplate(dd);
  1391. /*
  1392. * zero all the TID entries at startup. We do this for sanity,
  1393. * in case of a previous driver crash of some kind, and also
  1394. * because the chip powers up with these memories in an unknown
  1395. * state. Use portcnt, not cfgports, since this is for the
  1396. * full chip, not for current (possibly different) configuration
  1397. * value.
  1398. * Chip Errata bug 6447
  1399. */
  1400. for (val32 = 0; val32 < dd->ipath_portcnt; val32++)
  1401. ipath_ht_clear_tids(dd, val32);
  1402. /*
  1403. * write the pbc of each buffer, to be sure it's initialized, then
  1404. * cancel all the buffers, and also abort any packets that might
  1405. * have been in flight for some reason (the latter is for driver
  1406. * unload/reload, but isn't a bad idea at first init). PIO send
  1407. * isn't enabled at this point, so there is no danger of sending
  1408. * these out on the wire.
  1409. * Chip Errata bug 6610
  1410. */
  1411. piobuf = (u32 __iomem *) (((char __iomem *)(dd->ipath_kregbase)) +
  1412. dd->ipath_piobufbase);
  1413. pioincr = dd->ipath_palign / sizeof(*piobuf);
  1414. for (i = 0; i < dd->ipath_piobcnt2k; i++) {
  1415. /*
  1416. * reasonable word count, just to init pbc
  1417. */
  1418. writel(16, piobuf);
  1419. piobuf += pioincr;
  1420. }
  1421. /*
  1422. * self-clearing
  1423. */
  1424. ipath_write_kreg(dd, dd->ipath_kregs->kr_sendctrl,
  1425. INFINIPATH_S_ABORT);
  1426. ipath_get_eeprom_info(dd);
  1427. if(dd->ipath_boardrev == 5 && dd->ipath_serial[0] == '1' &&
  1428. dd->ipath_serial[1] == '2' && dd->ipath_serial[2] == '8') {
  1429. /*
  1430. * Later production QHT7040 has same changes as QHT7140, so
  1431. * can use GPIO interrupts. They have serial #'s starting
  1432. * with 128, rather than 112.
  1433. */
  1434. dd->ipath_flags |= IPATH_GPIO_INTR;
  1435. dd->ipath_flags &= ~IPATH_POLL_RX_INTR;
  1436. }
  1437. return 0;
  1438. }
  1439. /**
  1440. * ipath_init_ht_get_base_info - set chip-specific flags for user code
  1441. * @dd: the infinipath device
  1442. * @kbase: ipath_base_info pointer
  1443. *
  1444. * We set the PCIE flag because the lower bandwidth on PCIe vs
  1445. * HyperTransport can affect some user packet algorithims.
  1446. */
  1447. static int ipath_ht_get_base_info(struct ipath_portdata *pd, void *kbase)
  1448. {
  1449. struct ipath_base_info *kinfo = kbase;
  1450. kinfo->spi_runtime_flags |= IPATH_RUNTIME_HT |
  1451. IPATH_RUNTIME_RCVHDR_COPY;
  1452. return 0;
  1453. }
  1454. /**
  1455. * ipath_init_iba6110_funcs - set up the chip-specific function pointers
  1456. * @dd: the infinipath device
  1457. *
  1458. * This is global, and is called directly at init to set up the
  1459. * chip-specific function pointers for later use.
  1460. */
  1461. void ipath_init_iba6110_funcs(struct ipath_devdata *dd)
  1462. {
  1463. dd->ipath_f_intrsetup = ipath_ht_intconfig;
  1464. dd->ipath_f_bus = ipath_setup_ht_config;
  1465. dd->ipath_f_reset = ipath_setup_ht_reset;
  1466. dd->ipath_f_get_boardname = ipath_ht_boardname;
  1467. dd->ipath_f_init_hwerrors = ipath_ht_init_hwerrors;
  1468. dd->ipath_f_early_init = ipath_ht_early_init;
  1469. dd->ipath_f_handle_hwerrors = ipath_ht_handle_hwerrors;
  1470. dd->ipath_f_quiet_serdes = ipath_ht_quiet_serdes;
  1471. dd->ipath_f_bringup_serdes = ipath_ht_bringup_serdes;
  1472. dd->ipath_f_clear_tids = ipath_ht_clear_tids;
  1473. dd->ipath_f_put_tid = ipath_ht_put_tid;
  1474. dd->ipath_f_cleanup = ipath_setup_ht_cleanup;
  1475. dd->ipath_f_setextled = ipath_setup_ht_setextled;
  1476. dd->ipath_f_get_base_info = ipath_ht_get_base_info;
  1477. /*
  1478. * initialize chip-specific variables
  1479. */
  1480. dd->ipath_f_tidtemplate = ipath_ht_tidtemplate;
  1481. /*
  1482. * setup the register offsets, since they are different for each
  1483. * chip
  1484. */
  1485. dd->ipath_kregs = &ipath_ht_kregs;
  1486. dd->ipath_cregs = &ipath_ht_cregs;
  1487. /*
  1488. * do very early init that is needed before ipath_f_bus is
  1489. * called
  1490. */
  1491. ipath_init_ht_variables(dd);
  1492. }