ipath_iba6110.c 52 KB

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