ipath_iba6120.c 59 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754
  1. /*
  2. * Copyright (c) 2006, 2007 QLogic Corporation. All rights reserved.
  3. * Copyright (c) 2003, 2004, 2005, 2006 PathScale, Inc. All rights reserved.
  4. *
  5. * This software is available to you under a choice of one of two
  6. * licenses. You may choose to be licensed under the terms of the GNU
  7. * General Public License (GPL) Version 2, available from the file
  8. * COPYING in the main directory of this source tree, or the
  9. * OpenIB.org BSD license below:
  10. *
  11. * Redistribution and use in source and binary forms, with or
  12. * without modification, are permitted provided that the following
  13. * conditions are met:
  14. *
  15. * - Redistributions of source code must retain the above
  16. * copyright notice, this list of conditions and the following
  17. * disclaimer.
  18. *
  19. * - Redistributions in binary form must reproduce the above
  20. * copyright notice, this list of conditions and the following
  21. * disclaimer in the documentation and/or other materials
  22. * provided with the distribution.
  23. *
  24. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  25. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  26. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  27. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  28. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  29. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  30. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  31. * SOFTWARE.
  32. */
  33. /*
  34. * This file contains all of the code that is specific to the
  35. * InfiniPath PCIe chip.
  36. */
  37. #include <linux/interrupt.h>
  38. #include <linux/pci.h>
  39. #include <linux/delay.h>
  40. #include <rdma/ib_verbs.h>
  41. #include "ipath_kernel.h"
  42. #include "ipath_registers.h"
  43. static void ipath_setup_pe_setextled(struct ipath_devdata *, u64, u64);
  44. /*
  45. * This file contains all the chip-specific register information and
  46. * access functions for the QLogic InfiniPath PCI-Express chip.
  47. *
  48. * This lists the InfiniPath registers, in the actual chip layout.
  49. * This structure should never be directly accessed.
  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 Reserved0;
  58. unsigned long long SendRegBase;
  59. unsigned long long UserRegBase;
  60. unsigned long long CounterRegBase;
  61. unsigned long long Scratch;
  62. unsigned long long Reserved1;
  63. unsigned long long Reserved2;
  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 Reserved3;
  99. unsigned long long RcvPktLEDCnt;
  100. unsigned long long Reserved4[8];
  101. unsigned long long SendCtrl;
  102. unsigned long long SendPIOBufBase;
  103. unsigned long long SendPIOSize;
  104. unsigned long long SendPIOBufCnt;
  105. unsigned long long SendPIOAvailAddr;
  106. unsigned long long TxIntMemBase;
  107. unsigned long long TxIntMemSize;
  108. unsigned long long Reserved5;
  109. unsigned long long PCIeRBufTestReg0;
  110. unsigned long long PCIeRBufTestReg1;
  111. unsigned long long Reserved51[6];
  112. unsigned long long SendBufferError;
  113. unsigned long long SendBufferErrorCONT1;
  114. unsigned long long Reserved6SBE[6];
  115. unsigned long long RcvHdrAddr0;
  116. unsigned long long RcvHdrAddr1;
  117. unsigned long long RcvHdrAddr2;
  118. unsigned long long RcvHdrAddr3;
  119. unsigned long long RcvHdrAddr4;
  120. unsigned long long Reserved7RHA[11];
  121. unsigned long long RcvHdrTailAddr0;
  122. unsigned long long RcvHdrTailAddr1;
  123. unsigned long long RcvHdrTailAddr2;
  124. unsigned long long RcvHdrTailAddr3;
  125. unsigned long long RcvHdrTailAddr4;
  126. unsigned long long Reserved8RHTA[11];
  127. unsigned long long Reserved9SW[8];
  128. unsigned long long SerdesConfig0;
  129. unsigned long long SerdesConfig1;
  130. unsigned long long SerdesStatus;
  131. unsigned long long XGXSConfig;
  132. unsigned long long IBPLLCfg;
  133. unsigned long long Reserved10SW2[3];
  134. unsigned long long PCIEQ0SerdesConfig0;
  135. unsigned long long PCIEQ0SerdesConfig1;
  136. unsigned long long PCIEQ0SerdesStatus;
  137. unsigned long long Reserved11;
  138. unsigned long long PCIEQ1SerdesConfig0;
  139. unsigned long long PCIEQ1SerdesConfig1;
  140. unsigned long long PCIEQ1SerdesStatus;
  141. unsigned long long Reserved12;
  142. };
  143. struct _infinipath_do_not_use_counters {
  144. __u64 LBIntCnt;
  145. __u64 LBFlowStallCnt;
  146. __u64 Reserved1;
  147. __u64 TxUnsupVLErrCnt;
  148. __u64 TxDataPktCnt;
  149. __u64 TxFlowPktCnt;
  150. __u64 TxDwordCnt;
  151. __u64 TxLenErrCnt;
  152. __u64 TxMaxMinLenErrCnt;
  153. __u64 TxUnderrunCnt;
  154. __u64 TxFlowStallCnt;
  155. __u64 TxDroppedPktCnt;
  156. __u64 RxDroppedPktCnt;
  157. __u64 RxDataPktCnt;
  158. __u64 RxFlowPktCnt;
  159. __u64 RxDwordCnt;
  160. __u64 RxLenErrCnt;
  161. __u64 RxMaxMinLenErrCnt;
  162. __u64 RxICRCErrCnt;
  163. __u64 RxVCRCErrCnt;
  164. __u64 RxFlowCtrlErrCnt;
  165. __u64 RxBadFormatCnt;
  166. __u64 RxLinkProblemCnt;
  167. __u64 RxEBPCnt;
  168. __u64 RxLPCRCErrCnt;
  169. __u64 RxBufOvflCnt;
  170. __u64 RxTIDFullErrCnt;
  171. __u64 RxTIDValidErrCnt;
  172. __u64 RxPKeyMismatchCnt;
  173. __u64 RxP0HdrEgrOvflCnt;
  174. __u64 RxP1HdrEgrOvflCnt;
  175. __u64 RxP2HdrEgrOvflCnt;
  176. __u64 RxP3HdrEgrOvflCnt;
  177. __u64 RxP4HdrEgrOvflCnt;
  178. __u64 RxP5HdrEgrOvflCnt;
  179. __u64 RxP6HdrEgrOvflCnt;
  180. __u64 RxP7HdrEgrOvflCnt;
  181. __u64 RxP8HdrEgrOvflCnt;
  182. __u64 Reserved6;
  183. __u64 Reserved7;
  184. __u64 IBStatusChangeCnt;
  185. __u64 IBLinkErrRecoveryCnt;
  186. __u64 IBLinkDownedCnt;
  187. __u64 IBSymbolErrCnt;
  188. };
  189. #define IPATH_KREG_OFFSET(field) (offsetof( \
  190. struct _infinipath_do_not_use_kernel_regs, field) / sizeof(u64))
  191. #define IPATH_CREG_OFFSET(field) (offsetof( \
  192. struct _infinipath_do_not_use_counters, field) / sizeof(u64))
  193. static const struct ipath_kregs ipath_pe_kregs = {
  194. .kr_control = IPATH_KREG_OFFSET(Control),
  195. .kr_counterregbase = IPATH_KREG_OFFSET(CounterRegBase),
  196. .kr_debugportselect = IPATH_KREG_OFFSET(DebugPortSelect),
  197. .kr_errorclear = IPATH_KREG_OFFSET(ErrorClear),
  198. .kr_errormask = IPATH_KREG_OFFSET(ErrorMask),
  199. .kr_errorstatus = IPATH_KREG_OFFSET(ErrorStatus),
  200. .kr_extctrl = IPATH_KREG_OFFSET(ExtCtrl),
  201. .kr_extstatus = IPATH_KREG_OFFSET(ExtStatus),
  202. .kr_gpio_clear = IPATH_KREG_OFFSET(GPIOClear),
  203. .kr_gpio_mask = IPATH_KREG_OFFSET(GPIOMask),
  204. .kr_gpio_out = IPATH_KREG_OFFSET(GPIOOut),
  205. .kr_gpio_status = IPATH_KREG_OFFSET(GPIOStatus),
  206. .kr_hwdiagctrl = IPATH_KREG_OFFSET(HwDiagCtrl),
  207. .kr_hwerrclear = IPATH_KREG_OFFSET(HwErrClear),
  208. .kr_hwerrmask = IPATH_KREG_OFFSET(HwErrMask),
  209. .kr_hwerrstatus = IPATH_KREG_OFFSET(HwErrStatus),
  210. .kr_ibcctrl = IPATH_KREG_OFFSET(IBCCtrl),
  211. .kr_ibcstatus = IPATH_KREG_OFFSET(IBCStatus),
  212. .kr_intblocked = IPATH_KREG_OFFSET(IntBlocked),
  213. .kr_intclear = IPATH_KREG_OFFSET(IntClear),
  214. .kr_intmask = IPATH_KREG_OFFSET(IntMask),
  215. .kr_intstatus = IPATH_KREG_OFFSET(IntStatus),
  216. .kr_mdio = IPATH_KREG_OFFSET(MDIO),
  217. .kr_pagealign = IPATH_KREG_OFFSET(PageAlign),
  218. .kr_partitionkey = IPATH_KREG_OFFSET(RcvPartitionKey),
  219. .kr_portcnt = IPATH_KREG_OFFSET(PortCnt),
  220. .kr_rcvbthqp = IPATH_KREG_OFFSET(RcvBTHQP),
  221. .kr_rcvbufbase = IPATH_KREG_OFFSET(RcvBufBase),
  222. .kr_rcvbufsize = IPATH_KREG_OFFSET(RcvBufSize),
  223. .kr_rcvctrl = IPATH_KREG_OFFSET(RcvCtrl),
  224. .kr_rcvegrbase = IPATH_KREG_OFFSET(RcvEgrBase),
  225. .kr_rcvegrcnt = IPATH_KREG_OFFSET(RcvEgrCnt),
  226. .kr_rcvhdrcnt = IPATH_KREG_OFFSET(RcvHdrCnt),
  227. .kr_rcvhdrentsize = IPATH_KREG_OFFSET(RcvHdrEntSize),
  228. .kr_rcvhdrsize = IPATH_KREG_OFFSET(RcvHdrSize),
  229. .kr_rcvintmembase = IPATH_KREG_OFFSET(RxIntMemBase),
  230. .kr_rcvintmemsize = IPATH_KREG_OFFSET(RxIntMemSize),
  231. .kr_rcvtidbase = IPATH_KREG_OFFSET(RcvTIDBase),
  232. .kr_rcvtidcnt = IPATH_KREG_OFFSET(RcvTIDCnt),
  233. .kr_revision = IPATH_KREG_OFFSET(Revision),
  234. .kr_scratch = IPATH_KREG_OFFSET(Scratch),
  235. .kr_sendbuffererror = IPATH_KREG_OFFSET(SendBufferError),
  236. .kr_sendctrl = IPATH_KREG_OFFSET(SendCtrl),
  237. .kr_sendpioavailaddr = IPATH_KREG_OFFSET(SendPIOAvailAddr),
  238. .kr_sendpiobufbase = IPATH_KREG_OFFSET(SendPIOBufBase),
  239. .kr_sendpiobufcnt = IPATH_KREG_OFFSET(SendPIOBufCnt),
  240. .kr_sendpiosize = IPATH_KREG_OFFSET(SendPIOSize),
  241. .kr_sendregbase = IPATH_KREG_OFFSET(SendRegBase),
  242. .kr_txintmembase = IPATH_KREG_OFFSET(TxIntMemBase),
  243. .kr_txintmemsize = IPATH_KREG_OFFSET(TxIntMemSize),
  244. .kr_userregbase = IPATH_KREG_OFFSET(UserRegBase),
  245. .kr_serdesconfig0 = IPATH_KREG_OFFSET(SerdesConfig0),
  246. .kr_serdesconfig1 = IPATH_KREG_OFFSET(SerdesConfig1),
  247. .kr_serdesstatus = IPATH_KREG_OFFSET(SerdesStatus),
  248. .kr_xgxsconfig = IPATH_KREG_OFFSET(XGXSConfig),
  249. .kr_ibpllcfg = IPATH_KREG_OFFSET(IBPLLCfg),
  250. /*
  251. * These should not be used directly via ipath_write_kreg64(),
  252. * use them with ipath_write_kreg64_port(),
  253. */
  254. .kr_rcvhdraddr = IPATH_KREG_OFFSET(RcvHdrAddr0),
  255. .kr_rcvhdrtailaddr = IPATH_KREG_OFFSET(RcvHdrTailAddr0),
  256. /* The rcvpktled register controls one of the debug port signals, so
  257. * a packet activity LED can be connected to it. */
  258. .kr_rcvpktledcnt = IPATH_KREG_OFFSET(RcvPktLEDCnt),
  259. .kr_pcierbuftestreg0 = IPATH_KREG_OFFSET(PCIeRBufTestReg0),
  260. .kr_pcierbuftestreg1 = IPATH_KREG_OFFSET(PCIeRBufTestReg1),
  261. .kr_pcieq0serdesconfig0 = IPATH_KREG_OFFSET(PCIEQ0SerdesConfig0),
  262. .kr_pcieq0serdesconfig1 = IPATH_KREG_OFFSET(PCIEQ0SerdesConfig1),
  263. .kr_pcieq0serdesstatus = IPATH_KREG_OFFSET(PCIEQ0SerdesStatus),
  264. .kr_pcieq1serdesconfig0 = IPATH_KREG_OFFSET(PCIEQ1SerdesConfig0),
  265. .kr_pcieq1serdesconfig1 = IPATH_KREG_OFFSET(PCIEQ1SerdesConfig1),
  266. .kr_pcieq1serdesstatus = IPATH_KREG_OFFSET(PCIEQ1SerdesStatus)
  267. };
  268. static const struct ipath_cregs ipath_pe_cregs = {
  269. .cr_badformatcnt = IPATH_CREG_OFFSET(RxBadFormatCnt),
  270. .cr_erricrccnt = IPATH_CREG_OFFSET(RxICRCErrCnt),
  271. .cr_errlinkcnt = IPATH_CREG_OFFSET(RxLinkProblemCnt),
  272. .cr_errlpcrccnt = IPATH_CREG_OFFSET(RxLPCRCErrCnt),
  273. .cr_errpkey = IPATH_CREG_OFFSET(RxPKeyMismatchCnt),
  274. .cr_errrcvflowctrlcnt = IPATH_CREG_OFFSET(RxFlowCtrlErrCnt),
  275. .cr_err_rlencnt = IPATH_CREG_OFFSET(RxLenErrCnt),
  276. .cr_errslencnt = IPATH_CREG_OFFSET(TxLenErrCnt),
  277. .cr_errtidfull = IPATH_CREG_OFFSET(RxTIDFullErrCnt),
  278. .cr_errtidvalid = IPATH_CREG_OFFSET(RxTIDValidErrCnt),
  279. .cr_errvcrccnt = IPATH_CREG_OFFSET(RxVCRCErrCnt),
  280. .cr_ibstatuschange = IPATH_CREG_OFFSET(IBStatusChangeCnt),
  281. .cr_intcnt = IPATH_CREG_OFFSET(LBIntCnt),
  282. .cr_invalidrlencnt = IPATH_CREG_OFFSET(RxMaxMinLenErrCnt),
  283. .cr_invalidslencnt = IPATH_CREG_OFFSET(TxMaxMinLenErrCnt),
  284. .cr_lbflowstallcnt = IPATH_CREG_OFFSET(LBFlowStallCnt),
  285. .cr_pktrcvcnt = IPATH_CREG_OFFSET(RxDataPktCnt),
  286. .cr_pktrcvflowctrlcnt = IPATH_CREG_OFFSET(RxFlowPktCnt),
  287. .cr_pktsendcnt = IPATH_CREG_OFFSET(TxDataPktCnt),
  288. .cr_pktsendflowcnt = IPATH_CREG_OFFSET(TxFlowPktCnt),
  289. .cr_portovflcnt = IPATH_CREG_OFFSET(RxP0HdrEgrOvflCnt),
  290. .cr_rcvebpcnt = IPATH_CREG_OFFSET(RxEBPCnt),
  291. .cr_rcvovflcnt = IPATH_CREG_OFFSET(RxBufOvflCnt),
  292. .cr_senddropped = IPATH_CREG_OFFSET(TxDroppedPktCnt),
  293. .cr_sendstallcnt = IPATH_CREG_OFFSET(TxFlowStallCnt),
  294. .cr_sendunderruncnt = IPATH_CREG_OFFSET(TxUnderrunCnt),
  295. .cr_wordrcvcnt = IPATH_CREG_OFFSET(RxDwordCnt),
  296. .cr_wordsendcnt = IPATH_CREG_OFFSET(TxDwordCnt),
  297. .cr_unsupvlcnt = IPATH_CREG_OFFSET(TxUnsupVLErrCnt),
  298. .cr_rxdroppktcnt = IPATH_CREG_OFFSET(RxDroppedPktCnt),
  299. .cr_iblinkerrrecovcnt = IPATH_CREG_OFFSET(IBLinkErrRecoveryCnt),
  300. .cr_iblinkdowncnt = IPATH_CREG_OFFSET(IBLinkDownedCnt),
  301. .cr_ibsymbolerrcnt = IPATH_CREG_OFFSET(IBSymbolErrCnt)
  302. };
  303. /* kr_control bits */
  304. #define INFINIPATH_C_RESET 1U
  305. /* kr_intstatus, kr_intclear, kr_intmask bits */
  306. #define INFINIPATH_I_RCVURG_MASK ((1U<<5)-1)
  307. #define INFINIPATH_I_RCVAVAIL_MASK ((1U<<5)-1)
  308. /* kr_hwerrclear, kr_hwerrmask, kr_hwerrstatus, bits */
  309. #define INFINIPATH_HWE_PCIEMEMPARITYERR_MASK 0x000000000000003fULL
  310. #define INFINIPATH_HWE_PCIEMEMPARITYERR_SHIFT 0
  311. #define INFINIPATH_HWE_PCIEPOISONEDTLP 0x0000000010000000ULL
  312. #define INFINIPATH_HWE_PCIECPLTIMEOUT 0x0000000020000000ULL
  313. #define INFINIPATH_HWE_PCIEBUSPARITYXTLH 0x0000000040000000ULL
  314. #define INFINIPATH_HWE_PCIEBUSPARITYXADM 0x0000000080000000ULL
  315. #define INFINIPATH_HWE_PCIEBUSPARITYRADM 0x0000000100000000ULL
  316. #define INFINIPATH_HWE_COREPLL_FBSLIP 0x0080000000000000ULL
  317. #define INFINIPATH_HWE_COREPLL_RFSLIP 0x0100000000000000ULL
  318. #define INFINIPATH_HWE_PCIE1PLLFAILED 0x0400000000000000ULL
  319. #define INFINIPATH_HWE_PCIE0PLLFAILED 0x0800000000000000ULL
  320. #define INFINIPATH_HWE_SERDESPLLFAILED 0x1000000000000000ULL
  321. #define IBA6120_IBCS_LINKTRAININGSTATE_MASK 0xf
  322. #define IBA6120_IBCS_LINKSTATE_SHIFT 4
  323. /* kr_extstatus bits */
  324. #define INFINIPATH_EXTS_FREQSEL 0x2
  325. #define INFINIPATH_EXTS_SERDESSEL 0x4
  326. #define INFINIPATH_EXTS_MEMBIST_ENDTEST 0x0000000000004000
  327. #define INFINIPATH_EXTS_MEMBIST_FOUND 0x0000000000008000
  328. /* kr_xgxsconfig bits */
  329. #define INFINIPATH_XGXS_RESET 0x5ULL
  330. #define _IPATH_GPIO_SDA_NUM 1
  331. #define _IPATH_GPIO_SCL_NUM 0
  332. #define IPATH_GPIO_SDA (1ULL << \
  333. (_IPATH_GPIO_SDA_NUM+INFINIPATH_EXTC_GPIOOE_SHIFT))
  334. #define IPATH_GPIO_SCL (1ULL << \
  335. (_IPATH_GPIO_SCL_NUM+INFINIPATH_EXTC_GPIOOE_SHIFT))
  336. #define INFINIPATH_RT_BUFSIZE_MASK 0xe0000000ULL
  337. #define INFINIPATH_RT_BUFSIZE_SHIFTVAL(tid) \
  338. ((((tid) & INFINIPATH_RT_BUFSIZE_MASK) >> 29) + 11 - 1)
  339. #define INFINIPATH_RT_BUFSIZE(tid) (1 << INFINIPATH_RT_BUFSIZE_SHIFTVAL(tid))
  340. #define INFINIPATH_RT_IS_VALID(tid) \
  341. (((tid) & INFINIPATH_RT_BUFSIZE_MASK) && \
  342. ((((tid) & INFINIPATH_RT_BUFSIZE_MASK) != INFINIPATH_RT_BUFSIZE_MASK)))
  343. #define INFINIPATH_RT_ADDR_MASK 0x1FFFFFFFULL /* 29 bits valid */
  344. #define INFINIPATH_RT_ADDR_SHIFT 10
  345. #define INFINIPATH_R_INTRAVAIL_SHIFT 16
  346. #define INFINIPATH_R_TAILUPD_SHIFT 31
  347. /* 6120 specific hardware errors... */
  348. static const struct ipath_hwerror_msgs ipath_6120_hwerror_msgs[] = {
  349. INFINIPATH_HWE_MSG(PCIEPOISONEDTLP, "PCIe Poisoned TLP"),
  350. INFINIPATH_HWE_MSG(PCIECPLTIMEOUT, "PCIe completion timeout"),
  351. /*
  352. * In practice, it's unlikely wthat we'll see PCIe PLL, or bus
  353. * parity or memory parity error failures, because most likely we
  354. * won't be able to talk to the core of the chip. Nonetheless, we
  355. * might see them, if they are in parts of the PCIe core that aren't
  356. * essential.
  357. */
  358. INFINIPATH_HWE_MSG(PCIE1PLLFAILED, "PCIePLL1"),
  359. INFINIPATH_HWE_MSG(PCIE0PLLFAILED, "PCIePLL0"),
  360. INFINIPATH_HWE_MSG(PCIEBUSPARITYXTLH, "PCIe XTLH core parity"),
  361. INFINIPATH_HWE_MSG(PCIEBUSPARITYXADM, "PCIe ADM TX core parity"),
  362. INFINIPATH_HWE_MSG(PCIEBUSPARITYRADM, "PCIe ADM RX core parity"),
  363. INFINIPATH_HWE_MSG(RXDSYNCMEMPARITYERR, "Rx Dsync"),
  364. INFINIPATH_HWE_MSG(SERDESPLLFAILED, "SerDes PLL"),
  365. };
  366. #define TXE_PIO_PARITY ((INFINIPATH_HWE_TXEMEMPARITYERR_PIOBUF | \
  367. INFINIPATH_HWE_TXEMEMPARITYERR_PIOPBC) \
  368. << INFINIPATH_HWE_TXEMEMPARITYERR_SHIFT)
  369. #define RXE_EAGER_PARITY (INFINIPATH_HWE_RXEMEMPARITYERR_EAGERTID \
  370. << INFINIPATH_HWE_RXEMEMPARITYERR_SHIFT)
  371. static void ipath_pe_put_tid_2(struct ipath_devdata *, u64 __iomem *,
  372. u32, unsigned long);
  373. /*
  374. * On platforms using this chip, and not having ordered WC stores, we
  375. * can get TXE parity errors due to speculative reads to the PIO buffers,
  376. * and this, due to a chip bug can result in (many) false parity error
  377. * reports. So it's a debug print on those, and an info print on systems
  378. * where the speculative reads don't occur.
  379. */
  380. static void ipath_pe_txe_recover(struct ipath_devdata *dd)
  381. {
  382. if (ipath_unordered_wc())
  383. ipath_dbg("Recovering from TXE PIO parity error\n");
  384. else {
  385. ++ipath_stats.sps_txeparity;
  386. dev_info(&dd->pcidev->dev,
  387. "Recovering from TXE PIO parity error\n");
  388. }
  389. }
  390. /**
  391. * ipath_pe_handle_hwerrors - display hardware errors.
  392. * @dd: the infinipath device
  393. * @msg: the output buffer
  394. * @msgl: the size of the output buffer
  395. *
  396. * Use same msg buffer as regular errors to avoid excessive stack
  397. * use. Most hardware errors are catastrophic, but for right now,
  398. * we'll print them and continue. We reuse the same message buffer as
  399. * ipath_handle_errors() to avoid excessive stack usage.
  400. */
  401. static void ipath_pe_handle_hwerrors(struct ipath_devdata *dd, char *msg,
  402. size_t msgl)
  403. {
  404. ipath_err_t hwerrs;
  405. u32 bits, ctrl;
  406. int isfatal = 0;
  407. char bitsmsg[64];
  408. int log_idx;
  409. hwerrs = ipath_read_kreg64(dd, dd->ipath_kregs->kr_hwerrstatus);
  410. if (!hwerrs) {
  411. /*
  412. * better than printing cofusing messages
  413. * This seems to be related to clearing the crc error, or
  414. * the pll error during init.
  415. */
  416. ipath_cdbg(VERBOSE, "Called but no hardware errors set\n");
  417. return;
  418. } else if (hwerrs == ~0ULL) {
  419. ipath_dev_err(dd, "Read of hardware error status failed "
  420. "(all bits set); ignoring\n");
  421. return;
  422. }
  423. ipath_stats.sps_hwerrs++;
  424. /* Always clear the error status register, except MEMBISTFAIL,
  425. * regardless of whether we continue or stop using the chip.
  426. * We want that set so we know it failed, even across driver reload.
  427. * We'll still ignore it in the hwerrmask. We do this partly for
  428. * diagnostics, but also for support */
  429. ipath_write_kreg(dd, dd->ipath_kregs->kr_hwerrclear,
  430. hwerrs&~INFINIPATH_HWE_MEMBISTFAILED);
  431. hwerrs &= dd->ipath_hwerrmask;
  432. /* We log some errors to EEPROM, check if we have any of those. */
  433. for (log_idx = 0; log_idx < IPATH_EEP_LOG_CNT; ++log_idx)
  434. if (hwerrs & dd->ipath_eep_st_masks[log_idx].hwerrs_to_log)
  435. ipath_inc_eeprom_err(dd, log_idx, 1);
  436. /*
  437. * make sure we get this much out, unless told to be quiet,
  438. * or it's occurred within the last 5 seconds
  439. */
  440. if ((hwerrs & ~(dd->ipath_lasthwerror | TXE_PIO_PARITY |
  441. RXE_EAGER_PARITY)) ||
  442. (ipath_debug & __IPATH_VERBDBG))
  443. dev_info(&dd->pcidev->dev, "Hardware error: hwerr=0x%llx "
  444. "(cleared)\n", (unsigned long long) hwerrs);
  445. dd->ipath_lasthwerror |= hwerrs;
  446. if (hwerrs & ~dd->ipath_hwe_bitsextant)
  447. ipath_dev_err(dd, "hwerror interrupt with unknown errors "
  448. "%llx set\n", (unsigned long long)
  449. (hwerrs & ~dd->ipath_hwe_bitsextant));
  450. ctrl = ipath_read_kreg32(dd, dd->ipath_kregs->kr_control);
  451. if (ctrl & INFINIPATH_C_FREEZEMODE) {
  452. /*
  453. * parity errors in send memory are recoverable,
  454. * just cancel the send (if indicated in * sendbuffererror),
  455. * count the occurrence, unfreeze (if no other handled
  456. * hardware error bits are set), and continue. They can
  457. * occur if a processor speculative read is done to the PIO
  458. * buffer while we are sending a packet, for example.
  459. */
  460. if (hwerrs & TXE_PIO_PARITY) {
  461. ipath_pe_txe_recover(dd);
  462. hwerrs &= ~TXE_PIO_PARITY;
  463. }
  464. if (!hwerrs) {
  465. static u32 freeze_cnt;
  466. freeze_cnt++;
  467. ipath_dbg("Clearing freezemode on ignored or recovered "
  468. "hardware error (%u)\n", freeze_cnt);
  469. ipath_clear_freeze(dd);
  470. }
  471. }
  472. *msg = '\0';
  473. if (hwerrs & INFINIPATH_HWE_MEMBISTFAILED) {
  474. strlcat(msg, "[Memory BIST test failed, InfiniPath hardware unusable]",
  475. msgl);
  476. /* ignore from now on, so disable until driver reloaded */
  477. *dd->ipath_statusp |= IPATH_STATUS_HWERROR;
  478. dd->ipath_hwerrmask &= ~INFINIPATH_HWE_MEMBISTFAILED;
  479. ipath_write_kreg(dd, dd->ipath_kregs->kr_hwerrmask,
  480. dd->ipath_hwerrmask);
  481. }
  482. ipath_format_hwerrors(hwerrs,
  483. ipath_6120_hwerror_msgs,
  484. sizeof(ipath_6120_hwerror_msgs)/
  485. sizeof(ipath_6120_hwerror_msgs[0]),
  486. msg, msgl);
  487. if (hwerrs & (INFINIPATH_HWE_PCIEMEMPARITYERR_MASK
  488. << INFINIPATH_HWE_PCIEMEMPARITYERR_SHIFT)) {
  489. bits = (u32) ((hwerrs >>
  490. INFINIPATH_HWE_PCIEMEMPARITYERR_SHIFT) &
  491. INFINIPATH_HWE_PCIEMEMPARITYERR_MASK);
  492. snprintf(bitsmsg, sizeof bitsmsg,
  493. "[PCIe Mem Parity Errs %x] ", bits);
  494. strlcat(msg, bitsmsg, msgl);
  495. }
  496. #define _IPATH_PLL_FAIL (INFINIPATH_HWE_COREPLL_FBSLIP | \
  497. INFINIPATH_HWE_COREPLL_RFSLIP )
  498. if (hwerrs & _IPATH_PLL_FAIL) {
  499. snprintf(bitsmsg, sizeof bitsmsg,
  500. "[PLL failed (%llx), InfiniPath hardware unusable]",
  501. (unsigned long long) hwerrs & _IPATH_PLL_FAIL);
  502. strlcat(msg, bitsmsg, msgl);
  503. /* ignore from now on, so disable until driver reloaded */
  504. dd->ipath_hwerrmask &= ~(hwerrs & _IPATH_PLL_FAIL);
  505. ipath_write_kreg(dd, dd->ipath_kregs->kr_hwerrmask,
  506. dd->ipath_hwerrmask);
  507. }
  508. if (hwerrs & INFINIPATH_HWE_SERDESPLLFAILED) {
  509. /*
  510. * If it occurs, it is left masked since the external
  511. * interface is unused
  512. */
  513. dd->ipath_hwerrmask &= ~INFINIPATH_HWE_SERDESPLLFAILED;
  514. ipath_write_kreg(dd, dd->ipath_kregs->kr_hwerrmask,
  515. dd->ipath_hwerrmask);
  516. }
  517. if (*msg)
  518. ipath_dev_err(dd, "%s hardware error\n", msg);
  519. if (isfatal && !ipath_diag_inuse && dd->ipath_freezemsg) {
  520. /*
  521. * for /sys status file ; if no trailing } is copied, we'll
  522. * know it was truncated.
  523. */
  524. snprintf(dd->ipath_freezemsg, dd->ipath_freezelen,
  525. "{%s}", msg);
  526. }
  527. }
  528. /**
  529. * ipath_pe_boardname - fill in the board name
  530. * @dd: the infinipath device
  531. * @name: the output buffer
  532. * @namelen: the size of the output buffer
  533. *
  534. * info is based on the board revision register
  535. */
  536. static int ipath_pe_boardname(struct ipath_devdata *dd, char *name,
  537. size_t namelen)
  538. {
  539. char *n = NULL;
  540. u8 boardrev = dd->ipath_boardrev;
  541. int ret;
  542. switch (boardrev) {
  543. case 0:
  544. n = "InfiniPath_Emulation";
  545. break;
  546. case 1:
  547. n = "InfiniPath_QLE7140-Bringup";
  548. break;
  549. case 2:
  550. n = "InfiniPath_QLE7140";
  551. break;
  552. case 3:
  553. n = "InfiniPath_QMI7140";
  554. break;
  555. case 4:
  556. n = "InfiniPath_QEM7140";
  557. break;
  558. case 5:
  559. n = "InfiniPath_QMH7140";
  560. break;
  561. case 6:
  562. n = "InfiniPath_QLE7142";
  563. break;
  564. default:
  565. ipath_dev_err(dd,
  566. "Don't yet know about board with ID %u\n",
  567. boardrev);
  568. snprintf(name, namelen, "Unknown_InfiniPath_PCIe_%u",
  569. boardrev);
  570. break;
  571. }
  572. if (n)
  573. snprintf(name, namelen, "%s", n);
  574. if (dd->ipath_majrev != 4 || !dd->ipath_minrev || dd->ipath_minrev>2) {
  575. ipath_dev_err(dd, "Unsupported InfiniPath hardware revision %u.%u!\n",
  576. dd->ipath_majrev, dd->ipath_minrev);
  577. ret = 1;
  578. } else {
  579. ret = 0;
  580. if (dd->ipath_minrev >= 2)
  581. dd->ipath_f_put_tid = ipath_pe_put_tid_2;
  582. }
  583. /*
  584. * set here, not in ipath_init_*_funcs because we have to do
  585. * it after we can read chip registers.
  586. */
  587. dd->ipath_ureg_align =
  588. ipath_read_kreg32(dd, dd->ipath_kregs->kr_pagealign);
  589. return ret;
  590. }
  591. /**
  592. * ipath_pe_init_hwerrors - enable hardware errors
  593. * @dd: the infinipath device
  594. *
  595. * now that we have finished initializing everything that might reasonably
  596. * cause a hardware error, and cleared those errors bits as they occur,
  597. * we can enable hardware errors in the mask (potentially enabling
  598. * freeze mode), and enable hardware errors as errors (along with
  599. * everything else) in errormask
  600. */
  601. static void ipath_pe_init_hwerrors(struct ipath_devdata *dd)
  602. {
  603. ipath_err_t val;
  604. u64 extsval;
  605. extsval = ipath_read_kreg64(dd, dd->ipath_kregs->kr_extstatus);
  606. if (!(extsval & INFINIPATH_EXTS_MEMBIST_ENDTEST))
  607. ipath_dev_err(dd, "MemBIST did not complete!\n");
  608. if (extsval & INFINIPATH_EXTS_MEMBIST_FOUND)
  609. ipath_dbg("MemBIST corrected\n");
  610. val = ~0ULL; /* barring bugs, all hwerrors become interrupts, */
  611. if (!dd->ipath_boardrev) // no PLL for Emulator
  612. val &= ~INFINIPATH_HWE_SERDESPLLFAILED;
  613. if (dd->ipath_minrev < 2) {
  614. /* workaround bug 9460 in internal interface bus parity
  615. * checking. Fixed (HW bug 9490) in Rev2.
  616. */
  617. val &= ~INFINIPATH_HWE_PCIEBUSPARITYRADM;
  618. }
  619. dd->ipath_hwerrmask = val;
  620. }
  621. /**
  622. * ipath_pe_bringup_serdes - bring up the serdes
  623. * @dd: the infinipath device
  624. */
  625. static int ipath_pe_bringup_serdes(struct ipath_devdata *dd)
  626. {
  627. u64 val, config1, prev_val;
  628. int ret = 0;
  629. ipath_dbg("Trying to bringup serdes\n");
  630. if (ipath_read_kreg64(dd, dd->ipath_kregs->kr_hwerrstatus) &
  631. INFINIPATH_HWE_SERDESPLLFAILED) {
  632. ipath_dbg("At start, serdes PLL failed bit set "
  633. "in hwerrstatus, clearing and continuing\n");
  634. ipath_write_kreg(dd, dd->ipath_kregs->kr_hwerrclear,
  635. INFINIPATH_HWE_SERDESPLLFAILED);
  636. }
  637. val = ipath_read_kreg64(dd, dd->ipath_kregs->kr_serdesconfig0);
  638. config1 = ipath_read_kreg64(dd, dd->ipath_kregs->kr_serdesconfig1);
  639. ipath_cdbg(VERBOSE, "SerDes status config0=%llx config1=%llx, "
  640. "xgxsconfig %llx\n", (unsigned long long) val,
  641. (unsigned long long) config1, (unsigned long long)
  642. ipath_read_kreg64(dd, dd->ipath_kregs->kr_xgxsconfig));
  643. /*
  644. * Force reset on, also set rxdetect enable. Must do before reading
  645. * serdesstatus at least for simulation, or some of the bits in
  646. * serdes status will come back as undefined and cause simulation
  647. * failures
  648. */
  649. val |= INFINIPATH_SERDC0_RESET_PLL | INFINIPATH_SERDC0_RXDETECT_EN
  650. | INFINIPATH_SERDC0_L1PWR_DN;
  651. ipath_write_kreg(dd, dd->ipath_kregs->kr_serdesconfig0, val);
  652. /* be sure chip saw it */
  653. ipath_read_kreg64(dd, dd->ipath_kregs->kr_scratch);
  654. udelay(5); /* need pll reset set at least for a bit */
  655. /*
  656. * after PLL is reset, set the per-lane Resets and TxIdle and
  657. * clear the PLL reset and rxdetect (to get falling edge).
  658. * Leave L1PWR bits set (permanently)
  659. */
  660. val &= ~(INFINIPATH_SERDC0_RXDETECT_EN | INFINIPATH_SERDC0_RESET_PLL
  661. | INFINIPATH_SERDC0_L1PWR_DN);
  662. val |= INFINIPATH_SERDC0_RESET_MASK | INFINIPATH_SERDC0_TXIDLE;
  663. ipath_cdbg(VERBOSE, "Clearing pll reset and setting lane resets "
  664. "and txidle (%llx)\n", (unsigned long long) val);
  665. ipath_write_kreg(dd, dd->ipath_kregs->kr_serdesconfig0, val);
  666. /* be sure chip saw it */
  667. ipath_read_kreg64(dd, dd->ipath_kregs->kr_scratch);
  668. /* need PLL reset clear for at least 11 usec before lane
  669. * resets cleared; give it a few more to be sure */
  670. udelay(15);
  671. val &= ~(INFINIPATH_SERDC0_RESET_MASK | INFINIPATH_SERDC0_TXIDLE);
  672. ipath_cdbg(VERBOSE, "Clearing lane resets and txidle "
  673. "(writing %llx)\n", (unsigned long long) val);
  674. ipath_write_kreg(dd, dd->ipath_kregs->kr_serdesconfig0, val);
  675. /* be sure chip saw it */
  676. val = ipath_read_kreg64(dd, dd->ipath_kregs->kr_scratch);
  677. val = ipath_read_kreg64(dd, dd->ipath_kregs->kr_xgxsconfig);
  678. prev_val = val;
  679. if (val & INFINIPATH_XGXS_RESET)
  680. val &= ~INFINIPATH_XGXS_RESET;
  681. if (((val >> INFINIPATH_XGXS_RX_POL_SHIFT) &
  682. INFINIPATH_XGXS_RX_POL_MASK) != dd->ipath_rx_pol_inv ) {
  683. /* need to compensate for Tx inversion in partner */
  684. val &= ~(INFINIPATH_XGXS_RX_POL_MASK <<
  685. INFINIPATH_XGXS_RX_POL_SHIFT);
  686. val |= dd->ipath_rx_pol_inv <<
  687. INFINIPATH_XGXS_RX_POL_SHIFT;
  688. }
  689. if (val != prev_val)
  690. ipath_write_kreg(dd, dd->ipath_kregs->kr_xgxsconfig, val);
  691. val = ipath_read_kreg64(dd, dd->ipath_kregs->kr_serdesconfig0);
  692. /* clear current and de-emphasis bits */
  693. config1 &= ~0x0ffffffff00ULL;
  694. /* set current to 20ma */
  695. config1 |= 0x00000000000ULL;
  696. /* set de-emphasis to -5.68dB */
  697. config1 |= 0x0cccc000000ULL;
  698. ipath_write_kreg(dd, dd->ipath_kregs->kr_serdesconfig1, config1);
  699. ipath_cdbg(VERBOSE, "done: SerDes status config0=%llx "
  700. "config1=%llx, sstatus=%llx xgxs=%llx\n",
  701. (unsigned long long) val, (unsigned long long) config1,
  702. (unsigned long long)
  703. ipath_read_kreg64(dd, dd->ipath_kregs->kr_serdesstatus),
  704. (unsigned long long)
  705. ipath_read_kreg64(dd, dd->ipath_kregs->kr_xgxsconfig));
  706. return ret;
  707. }
  708. /**
  709. * ipath_pe_quiet_serdes - set serdes to txidle
  710. * @dd: the infinipath device
  711. * Called when driver is being unloaded
  712. */
  713. static void ipath_pe_quiet_serdes(struct ipath_devdata *dd)
  714. {
  715. u64 val = ipath_read_kreg64(dd, dd->ipath_kregs->kr_serdesconfig0);
  716. val |= INFINIPATH_SERDC0_TXIDLE;
  717. ipath_dbg("Setting TxIdleEn on serdes (config0 = %llx)\n",
  718. (unsigned long long) val);
  719. ipath_write_kreg(dd, dd->ipath_kregs->kr_serdesconfig0, val);
  720. }
  721. static int ipath_pe_intconfig(struct ipath_devdata *dd)
  722. {
  723. u32 chiprev;
  724. /*
  725. * If the chip supports added error indication via GPIO pins,
  726. * enable interrupts on those bits so the interrupt routine
  727. * can count the events. Also set flag so interrupt routine
  728. * can know they are expected.
  729. */
  730. chiprev = dd->ipath_revision >> INFINIPATH_R_CHIPREVMINOR_SHIFT;
  731. if ((chiprev & INFINIPATH_R_CHIPREVMINOR_MASK) > 1) {
  732. /* Rev2+ reports extra errors via internal GPIO pins */
  733. dd->ipath_flags |= IPATH_GPIO_ERRINTRS;
  734. dd->ipath_gpio_mask |= IPATH_GPIO_ERRINTR_MASK;
  735. ipath_write_kreg(dd, dd->ipath_kregs->kr_gpio_mask,
  736. dd->ipath_gpio_mask);
  737. }
  738. return 0;
  739. }
  740. /**
  741. * ipath_setup_pe_setextled - set the state of the two external LEDs
  742. * @dd: the infinipath device
  743. * @lst: the L state
  744. * @ltst: the LT state
  745. * These LEDs indicate the physical and logical state of IB link.
  746. * For this chip (at least with recommended board pinouts), LED1
  747. * is Yellow (logical state) and LED2 is Green (physical state),
  748. *
  749. * Note: We try to match the Mellanox HCA LED behavior as best
  750. * we can. Green indicates physical link state is OK (something is
  751. * plugged in, and we can train).
  752. * Amber indicates the link is logically up (ACTIVE).
  753. * Mellanox further blinks the amber LED to indicate data packet
  754. * activity, but we have no hardware support for that, so it would
  755. * require waking up every 10-20 msecs and checking the counters
  756. * on the chip, and then turning the LED off if appropriate. That's
  757. * visible overhead, so not something we will do.
  758. *
  759. */
  760. static void ipath_setup_pe_setextled(struct ipath_devdata *dd, u64 lst,
  761. u64 ltst)
  762. {
  763. u64 extctl;
  764. unsigned long flags = 0;
  765. /* the diags use the LED to indicate diag info, so we leave
  766. * the external LED alone when the diags are running */
  767. if (ipath_diag_inuse)
  768. return;
  769. /* Allow override of LED display for, e.g. Locating system in rack */
  770. if (dd->ipath_led_override) {
  771. ltst = (dd->ipath_led_override & IPATH_LED_PHYS)
  772. ? INFINIPATH_IBCS_LT_STATE_LINKUP
  773. : INFINIPATH_IBCS_LT_STATE_DISABLED;
  774. lst = (dd->ipath_led_override & IPATH_LED_LOG)
  775. ? INFINIPATH_IBCS_L_STATE_ACTIVE
  776. : INFINIPATH_IBCS_L_STATE_DOWN;
  777. }
  778. spin_lock_irqsave(&dd->ipath_gpio_lock, flags);
  779. extctl = dd->ipath_extctrl & ~(INFINIPATH_EXTC_LED1PRIPORT_ON |
  780. INFINIPATH_EXTC_LED2PRIPORT_ON);
  781. if (ltst & INFINIPATH_IBCS_LT_STATE_LINKUP)
  782. extctl |= INFINIPATH_EXTC_LED2PRIPORT_ON;
  783. if (lst == INFINIPATH_IBCS_L_STATE_ACTIVE)
  784. extctl |= INFINIPATH_EXTC_LED1PRIPORT_ON;
  785. dd->ipath_extctrl = extctl;
  786. ipath_write_kreg(dd, dd->ipath_kregs->kr_extctrl, extctl);
  787. spin_unlock_irqrestore(&dd->ipath_gpio_lock, flags);
  788. }
  789. /**
  790. * ipath_setup_pe_cleanup - clean up any per-chip chip-specific stuff
  791. * @dd: the infinipath device
  792. *
  793. * This is called during driver unload.
  794. * We do the pci_disable_msi here, not in generic code, because it
  795. * isn't used for the HT chips. If we do end up needing pci_enable_msi
  796. * at some point in the future for HT, we'll move the call back
  797. * into the main init_one code.
  798. */
  799. static void ipath_setup_pe_cleanup(struct ipath_devdata *dd)
  800. {
  801. dd->ipath_msi_lo = 0; /* just in case unload fails */
  802. pci_disable_msi(dd->pcidev);
  803. }
  804. static void ipath_6120_pcie_params(struct ipath_devdata *dd)
  805. {
  806. u16 linkstat, speed;
  807. int pos;
  808. pos = pci_find_capability(dd->pcidev, PCI_CAP_ID_EXP);
  809. if (!pos) {
  810. ipath_dev_err(dd, "Can't find PCI Express capability!\n");
  811. goto bail;
  812. }
  813. pci_read_config_word(dd->pcidev, pos + PCI_EXP_LNKSTA,
  814. &linkstat);
  815. /*
  816. * speed is bits 0-4, linkwidth is bits 4-8
  817. * no defines for them in headers
  818. */
  819. speed = linkstat & 0xf;
  820. linkstat >>= 4;
  821. linkstat &= 0x1f;
  822. dd->ipath_lbus_width = linkstat;
  823. switch (speed) {
  824. case 1:
  825. dd->ipath_lbus_speed = 2500; /* Gen1, 2.5GHz */
  826. break;
  827. case 2:
  828. dd->ipath_lbus_speed = 5000; /* Gen1, 5GHz */
  829. break;
  830. default: /* not defined, assume gen1 */
  831. dd->ipath_lbus_speed = 2500;
  832. break;
  833. }
  834. if (linkstat < 8)
  835. ipath_dev_err(dd,
  836. "PCIe width %u (x8 HCA), performance reduced\n",
  837. linkstat);
  838. else
  839. ipath_cdbg(VERBOSE, "PCIe speed %u width %u (x8 HCA)\n",
  840. dd->ipath_lbus_speed, linkstat);
  841. if (speed != 1)
  842. ipath_dev_err(dd,
  843. "PCIe linkspeed %u is incorrect; "
  844. "should be 1 (2500)!\n", speed);
  845. bail:
  846. /* fill in string, even on errors */
  847. snprintf(dd->ipath_lbus_info, sizeof(dd->ipath_lbus_info),
  848. "PCIe,%uMHz,x%u\n",
  849. dd->ipath_lbus_speed,
  850. dd->ipath_lbus_width);
  851. return;
  852. }
  853. /**
  854. * ipath_setup_pe_config - setup PCIe config related stuff
  855. * @dd: the infinipath device
  856. * @pdev: the PCI device
  857. *
  858. * The pci_enable_msi() call will fail on systems with MSI quirks
  859. * such as those with AMD8131, even if the device of interest is not
  860. * attached to that device, (in the 2.6.13 - 2.6.15 kernels, at least, fixed
  861. * late in 2.6.16).
  862. * All that can be done is to edit the kernel source to remove the quirk
  863. * check until that is fixed.
  864. * We do not need to call enable_msi() for our HyperTransport chip,
  865. * even though it uses MSI, and we want to avoid the quirk warning, so
  866. * So we call enable_msi only for PCIe. If we do end up needing
  867. * pci_enable_msi at some point in the future for HT, we'll move the
  868. * call back into the main init_one code.
  869. * We save the msi lo and hi values, so we can restore them after
  870. * chip reset (the kernel PCI infrastructure doesn't yet handle that
  871. * correctly).
  872. */
  873. static int ipath_setup_pe_config(struct ipath_devdata *dd,
  874. struct pci_dev *pdev)
  875. {
  876. int pos, ret;
  877. dd->ipath_msi_lo = 0; /* used as a flag during reset processing */
  878. ret = pci_enable_msi(dd->pcidev);
  879. if (ret)
  880. ipath_dev_err(dd, "pci_enable_msi failed: %d, "
  881. "interrupts may not work\n", ret);
  882. /* continue even if it fails, we may still be OK... */
  883. dd->ipath_irq = pdev->irq;
  884. if ((pos = pci_find_capability(dd->pcidev, PCI_CAP_ID_MSI))) {
  885. u16 control;
  886. pci_read_config_dword(dd->pcidev, pos + PCI_MSI_ADDRESS_LO,
  887. &dd->ipath_msi_lo);
  888. pci_read_config_dword(dd->pcidev, pos + PCI_MSI_ADDRESS_HI,
  889. &dd->ipath_msi_hi);
  890. pci_read_config_word(dd->pcidev, pos + PCI_MSI_FLAGS,
  891. &control);
  892. /* now save the data (vector) info */
  893. pci_read_config_word(dd->pcidev,
  894. pos + ((control & PCI_MSI_FLAGS_64BIT)
  895. ? 12 : 8),
  896. &dd->ipath_msi_data);
  897. ipath_cdbg(VERBOSE, "Read msi data 0x%x from config offset "
  898. "0x%x, control=0x%x\n", dd->ipath_msi_data,
  899. pos + ((control & PCI_MSI_FLAGS_64BIT) ? 12 : 8),
  900. control);
  901. /* we save the cachelinesize also, although it doesn't
  902. * really matter */
  903. pci_read_config_byte(dd->pcidev, PCI_CACHE_LINE_SIZE,
  904. &dd->ipath_pci_cacheline);
  905. } else
  906. ipath_dev_err(dd, "Can't find MSI capability, "
  907. "can't save MSI settings for reset\n");
  908. ipath_6120_pcie_params(dd);
  909. dd->ipath_link_width_supported = IB_WIDTH_1X | IB_WIDTH_4X;
  910. dd->ipath_link_speed_supported = IPATH_IB_SDR;
  911. dd->ipath_link_width_enabled = IB_WIDTH_4X;
  912. dd->ipath_link_speed_enabled = dd->ipath_link_speed_supported;
  913. /* these can't change for this chip, so set once */
  914. dd->ipath_link_width_active = dd->ipath_link_width_enabled;
  915. dd->ipath_link_speed_active = dd->ipath_link_speed_enabled;
  916. return 0;
  917. }
  918. static void ipath_init_pe_variables(struct ipath_devdata *dd)
  919. {
  920. /*
  921. * setup the register offsets, since they are different for each
  922. * chip
  923. */
  924. dd->ipath_kregs = &ipath_pe_kregs;
  925. dd->ipath_cregs = &ipath_pe_cregs;
  926. /*
  927. * bits for selecting i2c direction and values,
  928. * used for I2C serial flash
  929. */
  930. dd->ipath_gpio_sda_num = _IPATH_GPIO_SDA_NUM;
  931. dd->ipath_gpio_scl_num = _IPATH_GPIO_SCL_NUM;
  932. dd->ipath_gpio_sda = IPATH_GPIO_SDA;
  933. dd->ipath_gpio_scl = IPATH_GPIO_SCL;
  934. /*
  935. * Fill in data for field-values that change in newer chips.
  936. * We dynamically specify only the mask for LINKTRAININGSTATE
  937. * and only the shift for LINKSTATE, as they are the only ones
  938. * that change. Also precalculate the 3 link states of interest
  939. * and the combined mask.
  940. */
  941. dd->ibcs_ls_shift = IBA6120_IBCS_LINKSTATE_SHIFT;
  942. dd->ibcs_lts_mask = IBA6120_IBCS_LINKTRAININGSTATE_MASK;
  943. dd->ibcs_mask = (INFINIPATH_IBCS_LINKSTATE_MASK <<
  944. dd->ibcs_ls_shift) | dd->ibcs_lts_mask;
  945. dd->ib_init = (INFINIPATH_IBCS_LT_STATE_LINKUP <<
  946. INFINIPATH_IBCS_LINKTRAININGSTATE_SHIFT) |
  947. (INFINIPATH_IBCS_L_STATE_INIT << dd->ibcs_ls_shift);
  948. dd->ib_arm = (INFINIPATH_IBCS_LT_STATE_LINKUP <<
  949. INFINIPATH_IBCS_LINKTRAININGSTATE_SHIFT) |
  950. (INFINIPATH_IBCS_L_STATE_ARM << dd->ibcs_ls_shift);
  951. dd->ib_active = (INFINIPATH_IBCS_LT_STATE_LINKUP <<
  952. INFINIPATH_IBCS_LINKTRAININGSTATE_SHIFT) |
  953. (INFINIPATH_IBCS_L_STATE_ACTIVE << dd->ibcs_ls_shift);
  954. /*
  955. * Fill in data for ibcc field-values that change in newer chips.
  956. * We dynamically specify only the mask for LINKINITCMD
  957. * and only the shift for LINKCMD and MAXPKTLEN, as they are
  958. * the only ones that change.
  959. */
  960. dd->ibcc_lic_mask = INFINIPATH_IBCC_LINKINITCMD_MASK;
  961. dd->ibcc_lc_shift = INFINIPATH_IBCC_LINKCMD_SHIFT;
  962. dd->ibcc_mpl_shift = INFINIPATH_IBCC_MAXPKTLEN_SHIFT;
  963. /* Fill in shifts for RcvCtrl. */
  964. dd->ipath_r_portenable_shift = INFINIPATH_R_PORTENABLE_SHIFT;
  965. dd->ipath_r_intravail_shift = INFINIPATH_R_INTRAVAIL_SHIFT;
  966. dd->ipath_r_tailupd_shift = INFINIPATH_R_TAILUPD_SHIFT;
  967. dd->ipath_r_portcfg_shift = 0; /* Not on IBA6120 */
  968. /* variables for sanity checking interrupt and errors */
  969. dd->ipath_hwe_bitsextant =
  970. (INFINIPATH_HWE_RXEMEMPARITYERR_MASK <<
  971. INFINIPATH_HWE_RXEMEMPARITYERR_SHIFT) |
  972. (INFINIPATH_HWE_TXEMEMPARITYERR_MASK <<
  973. INFINIPATH_HWE_TXEMEMPARITYERR_SHIFT) |
  974. (INFINIPATH_HWE_PCIEMEMPARITYERR_MASK <<
  975. INFINIPATH_HWE_PCIEMEMPARITYERR_SHIFT) |
  976. INFINIPATH_HWE_PCIE1PLLFAILED |
  977. INFINIPATH_HWE_PCIE0PLLFAILED |
  978. INFINIPATH_HWE_PCIEPOISONEDTLP |
  979. INFINIPATH_HWE_PCIECPLTIMEOUT |
  980. INFINIPATH_HWE_PCIEBUSPARITYXTLH |
  981. INFINIPATH_HWE_PCIEBUSPARITYXADM |
  982. INFINIPATH_HWE_PCIEBUSPARITYRADM |
  983. INFINIPATH_HWE_MEMBISTFAILED |
  984. INFINIPATH_HWE_COREPLL_FBSLIP |
  985. INFINIPATH_HWE_COREPLL_RFSLIP |
  986. INFINIPATH_HWE_SERDESPLLFAILED |
  987. INFINIPATH_HWE_IBCBUSTOSPCPARITYERR |
  988. INFINIPATH_HWE_IBCBUSFRSPCPARITYERR;
  989. dd->ipath_i_bitsextant =
  990. (INFINIPATH_I_RCVURG_MASK << INFINIPATH_I_RCVURG_SHIFT) |
  991. (INFINIPATH_I_RCVAVAIL_MASK <<
  992. INFINIPATH_I_RCVAVAIL_SHIFT) |
  993. INFINIPATH_I_ERROR | INFINIPATH_I_SPIOSENT |
  994. INFINIPATH_I_SPIOBUFAVAIL | INFINIPATH_I_GPIO;
  995. dd->ipath_e_bitsextant =
  996. INFINIPATH_E_RFORMATERR | INFINIPATH_E_RVCRC |
  997. INFINIPATH_E_RICRC | INFINIPATH_E_RMINPKTLEN |
  998. INFINIPATH_E_RMAXPKTLEN | INFINIPATH_E_RLONGPKTLEN |
  999. INFINIPATH_E_RSHORTPKTLEN | INFINIPATH_E_RUNEXPCHAR |
  1000. INFINIPATH_E_RUNSUPVL | INFINIPATH_E_REBP |
  1001. INFINIPATH_E_RIBFLOW | INFINIPATH_E_RBADVERSION |
  1002. INFINIPATH_E_RRCVEGRFULL | INFINIPATH_E_RRCVHDRFULL |
  1003. INFINIPATH_E_RBADTID | INFINIPATH_E_RHDRLEN |
  1004. INFINIPATH_E_RHDR | INFINIPATH_E_RIBLOSTLINK |
  1005. INFINIPATH_E_SMINPKTLEN | INFINIPATH_E_SMAXPKTLEN |
  1006. INFINIPATH_E_SUNDERRUN | INFINIPATH_E_SPKTLEN |
  1007. INFINIPATH_E_SDROPPEDSMPPKT | INFINIPATH_E_SDROPPEDDATAPKT |
  1008. INFINIPATH_E_SPIOARMLAUNCH | INFINIPATH_E_SUNEXPERRPKTNUM |
  1009. INFINIPATH_E_SUNSUPVL | INFINIPATH_E_IBSTATUSCHANGED |
  1010. INFINIPATH_E_INVALIDADDR | INFINIPATH_E_RESET |
  1011. INFINIPATH_E_HARDWARE;
  1012. dd->ipath_i_rcvavail_mask = INFINIPATH_I_RCVAVAIL_MASK;
  1013. dd->ipath_i_rcvurg_mask = INFINIPATH_I_RCVURG_MASK;
  1014. dd->ipath_i_rcvavail_shift = INFINIPATH_I_RCVAVAIL_SHIFT;
  1015. dd->ipath_i_rcvurg_shift = INFINIPATH_I_RCVURG_SHIFT;
  1016. /*
  1017. * EEPROM error log 0 is TXE Parity errors. 1 is RXE Parity.
  1018. * 2 is Some Misc, 3 is reserved for future.
  1019. */
  1020. dd->ipath_eep_st_masks[0].hwerrs_to_log =
  1021. INFINIPATH_HWE_TXEMEMPARITYERR_MASK <<
  1022. INFINIPATH_HWE_TXEMEMPARITYERR_SHIFT;
  1023. /* Ignore errors in PIO/PBC on systems with unordered write-combining */
  1024. if (ipath_unordered_wc())
  1025. dd->ipath_eep_st_masks[0].hwerrs_to_log &= ~TXE_PIO_PARITY;
  1026. dd->ipath_eep_st_masks[1].hwerrs_to_log =
  1027. INFINIPATH_HWE_RXEMEMPARITYERR_MASK <<
  1028. INFINIPATH_HWE_RXEMEMPARITYERR_SHIFT;
  1029. dd->ipath_eep_st_masks[2].errs_to_log =
  1030. INFINIPATH_E_INVALIDADDR | INFINIPATH_E_RESET;
  1031. dd->delay_mult = 2; /* SDR, 4X, can't change */
  1032. }
  1033. /* setup the MSI stuff again after a reset. I'd like to just call
  1034. * pci_enable_msi() and request_irq() again, but when I do that,
  1035. * the MSI enable bit doesn't get set in the command word, and
  1036. * we switch to to a different interrupt vector, which is confusing,
  1037. * so I instead just do it all inline. Perhaps somehow can tie this
  1038. * into the PCIe hotplug support at some point
  1039. * Note, because I'm doing it all here, I don't call pci_disable_msi()
  1040. * or free_irq() at the start of ipath_setup_pe_reset().
  1041. */
  1042. static int ipath_reinit_msi(struct ipath_devdata *dd)
  1043. {
  1044. int pos;
  1045. u16 control;
  1046. int ret;
  1047. if (!dd->ipath_msi_lo) {
  1048. dev_info(&dd->pcidev->dev, "Can't restore MSI config, "
  1049. "initial setup failed?\n");
  1050. ret = 0;
  1051. goto bail;
  1052. }
  1053. if (!(pos = pci_find_capability(dd->pcidev, PCI_CAP_ID_MSI))) {
  1054. ipath_dev_err(dd, "Can't find MSI capability, "
  1055. "can't restore MSI settings\n");
  1056. ret = 0;
  1057. goto bail;
  1058. }
  1059. ipath_cdbg(VERBOSE, "Writing msi_lo 0x%x to config offset 0x%x\n",
  1060. dd->ipath_msi_lo, pos + PCI_MSI_ADDRESS_LO);
  1061. pci_write_config_dword(dd->pcidev, pos + PCI_MSI_ADDRESS_LO,
  1062. dd->ipath_msi_lo);
  1063. ipath_cdbg(VERBOSE, "Writing msi_lo 0x%x to config offset 0x%x\n",
  1064. dd->ipath_msi_hi, pos + PCI_MSI_ADDRESS_HI);
  1065. pci_write_config_dword(dd->pcidev, pos + PCI_MSI_ADDRESS_HI,
  1066. dd->ipath_msi_hi);
  1067. pci_read_config_word(dd->pcidev, pos + PCI_MSI_FLAGS, &control);
  1068. if (!(control & PCI_MSI_FLAGS_ENABLE)) {
  1069. ipath_cdbg(VERBOSE, "MSI control at off %x was %x, "
  1070. "setting MSI enable (%x)\n", pos + PCI_MSI_FLAGS,
  1071. control, control | PCI_MSI_FLAGS_ENABLE);
  1072. control |= PCI_MSI_FLAGS_ENABLE;
  1073. pci_write_config_word(dd->pcidev, pos + PCI_MSI_FLAGS,
  1074. control);
  1075. }
  1076. /* now rewrite the data (vector) info */
  1077. pci_write_config_word(dd->pcidev, pos +
  1078. ((control & PCI_MSI_FLAGS_64BIT) ? 12 : 8),
  1079. dd->ipath_msi_data);
  1080. /* we restore the cachelinesize also, although it doesn't really
  1081. * matter */
  1082. pci_write_config_byte(dd->pcidev, PCI_CACHE_LINE_SIZE,
  1083. dd->ipath_pci_cacheline);
  1084. /* and now set the pci master bit again */
  1085. pci_set_master(dd->pcidev);
  1086. ret = 1;
  1087. bail:
  1088. return ret;
  1089. }
  1090. /* This routine sleeps, so it can only be called from user context, not
  1091. * from interrupt context. If we need interrupt context, we can split
  1092. * it into two routines.
  1093. */
  1094. static int ipath_setup_pe_reset(struct ipath_devdata *dd)
  1095. {
  1096. u64 val;
  1097. int i;
  1098. int ret;
  1099. /* Use ERROR so it shows up in logs, etc. */
  1100. ipath_dev_err(dd, "Resetting InfiniPath unit %u\n", dd->ipath_unit);
  1101. /* keep chip from being accessed in a few places */
  1102. dd->ipath_flags &= ~(IPATH_INITTED|IPATH_PRESENT);
  1103. val = dd->ipath_control | INFINIPATH_C_RESET;
  1104. ipath_write_kreg(dd, dd->ipath_kregs->kr_control, val);
  1105. mb();
  1106. for (i = 1; i <= 5; i++) {
  1107. int r;
  1108. /* allow MBIST, etc. to complete; longer on each retry.
  1109. * We sometimes get machine checks from bus timeout if no
  1110. * response, so for now, make it *really* long.
  1111. */
  1112. msleep(1000 + (1 + i) * 2000);
  1113. if ((r =
  1114. pci_write_config_dword(dd->pcidev, PCI_BASE_ADDRESS_0,
  1115. dd->ipath_pcibar0)))
  1116. ipath_dev_err(dd, "rewrite of BAR0 failed: %d\n",
  1117. r);
  1118. if ((r =
  1119. pci_write_config_dword(dd->pcidev, PCI_BASE_ADDRESS_1,
  1120. dd->ipath_pcibar1)))
  1121. ipath_dev_err(dd, "rewrite of BAR1 failed: %d\n",
  1122. r);
  1123. /* now re-enable memory access */
  1124. if ((r = pci_enable_device(dd->pcidev)))
  1125. ipath_dev_err(dd, "pci_enable_device failed after "
  1126. "reset: %d\n", r);
  1127. /* whether it worked or not, mark as present, again */
  1128. dd->ipath_flags |= IPATH_PRESENT;
  1129. val = ipath_read_kreg64(dd, dd->ipath_kregs->kr_revision);
  1130. if (val == dd->ipath_revision) {
  1131. ipath_cdbg(VERBOSE, "Got matching revision "
  1132. "register %llx on try %d\n",
  1133. (unsigned long long) val, i);
  1134. ret = ipath_reinit_msi(dd);
  1135. goto bail;
  1136. }
  1137. /* Probably getting -1 back */
  1138. ipath_dbg("Didn't get expected revision register, "
  1139. "got %llx, try %d\n", (unsigned long long) val,
  1140. i + 1);
  1141. }
  1142. ret = 0; /* failed */
  1143. bail:
  1144. if (ret)
  1145. ipath_6120_pcie_params(dd);
  1146. return ret;
  1147. }
  1148. /**
  1149. * ipath_pe_put_tid - write a TID in chip
  1150. * @dd: the infinipath device
  1151. * @tidptr: pointer to the expected TID (in chip) to udpate
  1152. * @tidtype: RCVHQ_RCV_TYPE_EAGER (1) for eager, RCVHQ_RCV_TYPE_EXPECTED (0) for expected
  1153. * @pa: physical address of in memory buffer; ipath_tidinvalid if freeing
  1154. *
  1155. * This exists as a separate routine to allow for special locking etc.
  1156. * It's used for both the full cleanup on exit, as well as the normal
  1157. * setup and teardown.
  1158. */
  1159. static void ipath_pe_put_tid(struct ipath_devdata *dd, u64 __iomem *tidptr,
  1160. u32 type, unsigned long pa)
  1161. {
  1162. u32 __iomem *tidp32 = (u32 __iomem *)tidptr;
  1163. unsigned long flags = 0; /* keep gcc quiet */
  1164. if (pa != dd->ipath_tidinvalid) {
  1165. if (pa & ((1U << 11) - 1)) {
  1166. dev_info(&dd->pcidev->dev, "BUG: physaddr %lx "
  1167. "not 4KB aligned!\n", pa);
  1168. return;
  1169. }
  1170. pa >>= 11;
  1171. /* paranoia check */
  1172. if (pa & ~INFINIPATH_RT_ADDR_MASK)
  1173. ipath_dev_err(dd,
  1174. "BUG: Physical page address 0x%lx "
  1175. "has bits set in 31-29\n", pa);
  1176. if (type == RCVHQ_RCV_TYPE_EAGER)
  1177. pa |= dd->ipath_tidtemplate;
  1178. else /* for now, always full 4KB page */
  1179. pa |= 2 << 29;
  1180. }
  1181. /*
  1182. * Workaround chip bug 9437 by writing the scratch register
  1183. * before and after the TID, and with an io write barrier.
  1184. * We use a spinlock around the writes, so they can't intermix
  1185. * with other TID (eager or expected) writes (the chip bug
  1186. * is triggered by back to back TID writes). Unfortunately, this
  1187. * call can be done from interrupt level for the port 0 eager TIDs,
  1188. * so we have to use irqsave locks.
  1189. */
  1190. spin_lock_irqsave(&dd->ipath_tid_lock, flags);
  1191. ipath_write_kreg(dd, dd->ipath_kregs->kr_scratch, 0xfeeddeaf);
  1192. if (dd->ipath_kregbase)
  1193. writel(pa, tidp32);
  1194. ipath_write_kreg(dd, dd->ipath_kregs->kr_scratch, 0xdeadbeef);
  1195. mmiowb();
  1196. spin_unlock_irqrestore(&dd->ipath_tid_lock, flags);
  1197. }
  1198. /**
  1199. * ipath_pe_put_tid_2 - write a TID in chip, Revision 2 or higher
  1200. * @dd: the infinipath device
  1201. * @tidptr: pointer to the expected TID (in chip) to udpate
  1202. * @tidtype: RCVHQ_RCV_TYPE_EAGER (1) for eager, RCVHQ_RCV_TYPE_EXPECTED (0) for expected
  1203. * @pa: physical address of in memory buffer; ipath_tidinvalid if freeing
  1204. *
  1205. * This exists as a separate routine to allow for selection of the
  1206. * appropriate "flavor". The static calls in cleanup just use the
  1207. * revision-agnostic form, as they are not performance critical.
  1208. */
  1209. static void ipath_pe_put_tid_2(struct ipath_devdata *dd, u64 __iomem *tidptr,
  1210. u32 type, unsigned long pa)
  1211. {
  1212. u32 __iomem *tidp32 = (u32 __iomem *)tidptr;
  1213. if (pa != dd->ipath_tidinvalid) {
  1214. if (pa & ((1U << 11) - 1)) {
  1215. dev_info(&dd->pcidev->dev, "BUG: physaddr %lx "
  1216. "not 2KB aligned!\n", pa);
  1217. return;
  1218. }
  1219. pa >>= 11;
  1220. /* paranoia check */
  1221. if (pa & ~INFINIPATH_RT_ADDR_MASK)
  1222. ipath_dev_err(dd,
  1223. "BUG: Physical page address 0x%lx "
  1224. "has bits set in 31-29\n", pa);
  1225. if (type == RCVHQ_RCV_TYPE_EAGER)
  1226. pa |= dd->ipath_tidtemplate;
  1227. else /* for now, always full 4KB page */
  1228. pa |= 2 << 29;
  1229. }
  1230. if (dd->ipath_kregbase)
  1231. writel(pa, tidp32);
  1232. mmiowb();
  1233. }
  1234. /**
  1235. * ipath_pe_clear_tid - clear all TID entries for a port, expected and eager
  1236. * @dd: the infinipath device
  1237. * @port: the port
  1238. *
  1239. * clear all TID entries for a port, expected and eager.
  1240. * Used from ipath_close(). On this chip, TIDs are only 32 bits,
  1241. * not 64, but they are still on 64 bit boundaries, so tidbase
  1242. * is declared as u64 * for the pointer math, even though we write 32 bits
  1243. */
  1244. static void ipath_pe_clear_tids(struct ipath_devdata *dd, unsigned port)
  1245. {
  1246. u64 __iomem *tidbase;
  1247. unsigned long tidinv;
  1248. int i;
  1249. if (!dd->ipath_kregbase)
  1250. return;
  1251. ipath_cdbg(VERBOSE, "Invalidate TIDs for port %u\n", port);
  1252. tidinv = dd->ipath_tidinvalid;
  1253. tidbase = (u64 __iomem *)
  1254. ((char __iomem *)(dd->ipath_kregbase) +
  1255. dd->ipath_rcvtidbase +
  1256. port * dd->ipath_rcvtidcnt * sizeof(*tidbase));
  1257. for (i = 0; i < dd->ipath_rcvtidcnt; i++)
  1258. dd->ipath_f_put_tid(dd, &tidbase[i], RCVHQ_RCV_TYPE_EXPECTED,
  1259. tidinv);
  1260. tidbase = (u64 __iomem *)
  1261. ((char __iomem *)(dd->ipath_kregbase) +
  1262. dd->ipath_rcvegrbase +
  1263. port * dd->ipath_rcvegrcnt * sizeof(*tidbase));
  1264. for (i = 0; i < dd->ipath_rcvegrcnt; i++)
  1265. dd->ipath_f_put_tid(dd, &tidbase[i], RCVHQ_RCV_TYPE_EAGER,
  1266. tidinv);
  1267. }
  1268. /**
  1269. * ipath_pe_tidtemplate - setup constants for TID updates
  1270. * @dd: the infinipath device
  1271. *
  1272. * We setup stuff that we use a lot, to avoid calculating each time
  1273. */
  1274. static void ipath_pe_tidtemplate(struct ipath_devdata *dd)
  1275. {
  1276. u32 egrsize = dd->ipath_rcvegrbufsize;
  1277. /* For now, we always allocate 4KB buffers (at init) so we can
  1278. * receive max size packets. We may want a module parameter to
  1279. * specify 2KB or 4KB and/or make be per port instead of per device
  1280. * for those who want to reduce memory footprint. Note that the
  1281. * ipath_rcvhdrentsize size must be large enough to hold the largest
  1282. * IB header (currently 96 bytes) that we expect to handle (plus of
  1283. * course the 2 dwords of RHF).
  1284. */
  1285. if (egrsize == 2048)
  1286. dd->ipath_tidtemplate = 1U << 29;
  1287. else if (egrsize == 4096)
  1288. dd->ipath_tidtemplate = 2U << 29;
  1289. else {
  1290. egrsize = 4096;
  1291. dev_info(&dd->pcidev->dev, "BUG: unsupported egrbufsize "
  1292. "%u, using %u\n", dd->ipath_rcvegrbufsize,
  1293. egrsize);
  1294. dd->ipath_tidtemplate = 2U << 29;
  1295. }
  1296. dd->ipath_tidinvalid = 0;
  1297. }
  1298. static int ipath_pe_early_init(struct ipath_devdata *dd)
  1299. {
  1300. dd->ipath_flags |= IPATH_4BYTE_TID;
  1301. if (ipath_unordered_wc())
  1302. dd->ipath_flags |= IPATH_PIO_FLUSH_WC;
  1303. /*
  1304. * For openfabrics, we need to be able to handle an IB header of
  1305. * 24 dwords. HT chip has arbitrary sized receive buffers, so we
  1306. * made them the same size as the PIO buffers. This chip does not
  1307. * handle arbitrary size buffers, so we need the header large enough
  1308. * to handle largest IB header, but still have room for a 2KB MTU
  1309. * standard IB packet.
  1310. */
  1311. dd->ipath_rcvhdrentsize = 24;
  1312. dd->ipath_rcvhdrsize = IPATH_DFLT_RCVHDRSIZE;
  1313. dd->ipath_rhf_offset = 0;
  1314. dd->ipath_egrtidbase = (u64 __iomem *)
  1315. ((char __iomem *) dd->ipath_kregbase + dd->ipath_rcvegrbase);
  1316. /*
  1317. * To truly support a 4KB MTU (for usermode), we need to
  1318. * bump this to a larger value. For now, we use them for
  1319. * the kernel only.
  1320. */
  1321. dd->ipath_rcvegrbufsize = 2048;
  1322. /*
  1323. * the min() check here is currently a nop, but it may not always
  1324. * be, depending on just how we do ipath_rcvegrbufsize
  1325. */
  1326. dd->ipath_ibmaxlen = min(dd->ipath_piosize2k,
  1327. dd->ipath_rcvegrbufsize +
  1328. (dd->ipath_rcvhdrentsize << 2));
  1329. dd->ipath_init_ibmaxlen = dd->ipath_ibmaxlen;
  1330. /*
  1331. * We can request a receive interrupt for 1 or
  1332. * more packets from current offset. For now, we set this
  1333. * up for a single packet.
  1334. */
  1335. dd->ipath_rhdrhead_intr_off = 1ULL<<32;
  1336. ipath_get_eeprom_info(dd);
  1337. return 0;
  1338. }
  1339. int __attribute__((weak)) ipath_unordered_wc(void)
  1340. {
  1341. return 0;
  1342. }
  1343. /**
  1344. * ipath_init_pe_get_base_info - set chip-specific flags for user code
  1345. * @pd: the infinipath port
  1346. * @kbase: ipath_base_info pointer
  1347. *
  1348. * We set the PCIE flag because the lower bandwidth on PCIe vs
  1349. * HyperTransport can affect some user packet algorithms.
  1350. */
  1351. static int ipath_pe_get_base_info(struct ipath_portdata *pd, void *kbase)
  1352. {
  1353. struct ipath_base_info *kinfo = kbase;
  1354. struct ipath_devdata *dd;
  1355. if (ipath_unordered_wc()) {
  1356. kinfo->spi_runtime_flags |= IPATH_RUNTIME_FORCE_WC_ORDER;
  1357. ipath_cdbg(PROC, "Intel processor, forcing WC order\n");
  1358. }
  1359. else
  1360. ipath_cdbg(PROC, "Not Intel processor, WC ordered\n");
  1361. if (pd == NULL)
  1362. goto done;
  1363. dd = pd->port_dd;
  1364. done:
  1365. kinfo->spi_runtime_flags |= IPATH_RUNTIME_PCIE |
  1366. IPATH_RUNTIME_FORCE_PIOAVAIL | IPATH_RUNTIME_PIO_REGSWAPPED;
  1367. return 0;
  1368. }
  1369. static void ipath_pe_free_irq(struct ipath_devdata *dd)
  1370. {
  1371. free_irq(dd->ipath_irq, dd);
  1372. dd->ipath_irq = 0;
  1373. }
  1374. static struct ipath_message_header *
  1375. ipath_pe_get_msgheader(struct ipath_devdata *dd, __le32 *rhf_addr)
  1376. {
  1377. return (struct ipath_message_header *)
  1378. &rhf_addr[sizeof(u64) / sizeof(u32)];
  1379. }
  1380. static void ipath_pe_config_ports(struct ipath_devdata *dd, ushort cfgports)
  1381. {
  1382. dd->ipath_portcnt =
  1383. ipath_read_kreg32(dd, dd->ipath_kregs->kr_portcnt);
  1384. dd->ipath_p0_rcvegrcnt =
  1385. ipath_read_kreg32(dd, dd->ipath_kregs->kr_rcvegrcnt);
  1386. }
  1387. static void ipath_pe_read_counters(struct ipath_devdata *dd,
  1388. struct infinipath_counters *cntrs)
  1389. {
  1390. cntrs->LBIntCnt =
  1391. ipath_snap_cntr(dd, IPATH_CREG_OFFSET(LBIntCnt));
  1392. cntrs->LBFlowStallCnt =
  1393. ipath_snap_cntr(dd, IPATH_CREG_OFFSET(LBFlowStallCnt));
  1394. cntrs->TxSDmaDescCnt = 0;
  1395. cntrs->TxUnsupVLErrCnt =
  1396. ipath_snap_cntr(dd, IPATH_CREG_OFFSET(TxUnsupVLErrCnt));
  1397. cntrs->TxDataPktCnt =
  1398. ipath_snap_cntr(dd, IPATH_CREG_OFFSET(TxDataPktCnt));
  1399. cntrs->TxFlowPktCnt =
  1400. ipath_snap_cntr(dd, IPATH_CREG_OFFSET(TxFlowPktCnt));
  1401. cntrs->TxDwordCnt =
  1402. ipath_snap_cntr(dd, IPATH_CREG_OFFSET(TxDwordCnt));
  1403. cntrs->TxLenErrCnt =
  1404. ipath_snap_cntr(dd, IPATH_CREG_OFFSET(TxLenErrCnt));
  1405. cntrs->TxMaxMinLenErrCnt =
  1406. ipath_snap_cntr(dd, IPATH_CREG_OFFSET(TxMaxMinLenErrCnt));
  1407. cntrs->TxUnderrunCnt =
  1408. ipath_snap_cntr(dd, IPATH_CREG_OFFSET(TxUnderrunCnt));
  1409. cntrs->TxFlowStallCnt =
  1410. ipath_snap_cntr(dd, IPATH_CREG_OFFSET(TxFlowStallCnt));
  1411. cntrs->TxDroppedPktCnt =
  1412. ipath_snap_cntr(dd, IPATH_CREG_OFFSET(TxDroppedPktCnt));
  1413. cntrs->RxDroppedPktCnt =
  1414. ipath_snap_cntr(dd, IPATH_CREG_OFFSET(RxDroppedPktCnt));
  1415. cntrs->RxDataPktCnt =
  1416. ipath_snap_cntr(dd, IPATH_CREG_OFFSET(RxDataPktCnt));
  1417. cntrs->RxFlowPktCnt =
  1418. ipath_snap_cntr(dd, IPATH_CREG_OFFSET(RxFlowPktCnt));
  1419. cntrs->RxDwordCnt =
  1420. ipath_snap_cntr(dd, IPATH_CREG_OFFSET(RxDwordCnt));
  1421. cntrs->RxLenErrCnt =
  1422. ipath_snap_cntr(dd, IPATH_CREG_OFFSET(RxLenErrCnt));
  1423. cntrs->RxMaxMinLenErrCnt =
  1424. ipath_snap_cntr(dd, IPATH_CREG_OFFSET(RxMaxMinLenErrCnt));
  1425. cntrs->RxICRCErrCnt =
  1426. ipath_snap_cntr(dd, IPATH_CREG_OFFSET(RxICRCErrCnt));
  1427. cntrs->RxVCRCErrCnt =
  1428. ipath_snap_cntr(dd, IPATH_CREG_OFFSET(RxVCRCErrCnt));
  1429. cntrs->RxFlowCtrlErrCnt =
  1430. ipath_snap_cntr(dd, IPATH_CREG_OFFSET(RxFlowCtrlErrCnt));
  1431. cntrs->RxBadFormatCnt =
  1432. ipath_snap_cntr(dd, IPATH_CREG_OFFSET(RxBadFormatCnt));
  1433. cntrs->RxLinkProblemCnt =
  1434. ipath_snap_cntr(dd, IPATH_CREG_OFFSET(RxLinkProblemCnt));
  1435. cntrs->RxEBPCnt =
  1436. ipath_snap_cntr(dd, IPATH_CREG_OFFSET(RxEBPCnt));
  1437. cntrs->RxLPCRCErrCnt =
  1438. ipath_snap_cntr(dd, IPATH_CREG_OFFSET(RxLPCRCErrCnt));
  1439. cntrs->RxBufOvflCnt =
  1440. ipath_snap_cntr(dd, IPATH_CREG_OFFSET(RxBufOvflCnt));
  1441. cntrs->RxTIDFullErrCnt =
  1442. ipath_snap_cntr(dd, IPATH_CREG_OFFSET(RxTIDFullErrCnt));
  1443. cntrs->RxTIDValidErrCnt =
  1444. ipath_snap_cntr(dd, IPATH_CREG_OFFSET(RxTIDValidErrCnt));
  1445. cntrs->RxPKeyMismatchCnt =
  1446. ipath_snap_cntr(dd, IPATH_CREG_OFFSET(RxPKeyMismatchCnt));
  1447. cntrs->RxP0HdrEgrOvflCnt =
  1448. ipath_snap_cntr(dd, IPATH_CREG_OFFSET(RxP0HdrEgrOvflCnt));
  1449. cntrs->RxP1HdrEgrOvflCnt =
  1450. ipath_snap_cntr(dd, IPATH_CREG_OFFSET(RxP1HdrEgrOvflCnt));
  1451. cntrs->RxP2HdrEgrOvflCnt =
  1452. ipath_snap_cntr(dd, IPATH_CREG_OFFSET(RxP2HdrEgrOvflCnt));
  1453. cntrs->RxP3HdrEgrOvflCnt =
  1454. ipath_snap_cntr(dd, IPATH_CREG_OFFSET(RxP3HdrEgrOvflCnt));
  1455. cntrs->RxP4HdrEgrOvflCnt =
  1456. ipath_snap_cntr(dd, IPATH_CREG_OFFSET(RxP4HdrEgrOvflCnt));
  1457. cntrs->RxP5HdrEgrOvflCnt = 0;
  1458. cntrs->RxP6HdrEgrOvflCnt = 0;
  1459. cntrs->RxP7HdrEgrOvflCnt = 0;
  1460. cntrs->RxP8HdrEgrOvflCnt = 0;
  1461. cntrs->RxP9HdrEgrOvflCnt = 0;
  1462. cntrs->RxP10HdrEgrOvflCnt = 0;
  1463. cntrs->RxP11HdrEgrOvflCnt = 0;
  1464. cntrs->RxP12HdrEgrOvflCnt = 0;
  1465. cntrs->RxP13HdrEgrOvflCnt = 0;
  1466. cntrs->RxP14HdrEgrOvflCnt = 0;
  1467. cntrs->RxP15HdrEgrOvflCnt = 0;
  1468. cntrs->RxP16HdrEgrOvflCnt = 0;
  1469. cntrs->IBStatusChangeCnt =
  1470. ipath_snap_cntr(dd, IPATH_CREG_OFFSET(IBStatusChangeCnt));
  1471. cntrs->IBLinkErrRecoveryCnt =
  1472. ipath_snap_cntr(dd, IPATH_CREG_OFFSET(IBLinkErrRecoveryCnt));
  1473. cntrs->IBLinkDownedCnt =
  1474. ipath_snap_cntr(dd, IPATH_CREG_OFFSET(IBLinkDownedCnt));
  1475. cntrs->IBSymbolErrCnt =
  1476. ipath_snap_cntr(dd, IPATH_CREG_OFFSET(IBSymbolErrCnt));
  1477. cntrs->RxVL15DroppedPktCnt = 0;
  1478. cntrs->RxOtherLocalPhyErrCnt = 0;
  1479. cntrs->PcieRetryBufDiagQwordCnt = 0;
  1480. cntrs->ExcessBufferOvflCnt = dd->ipath_overrun_thresh_errs;
  1481. cntrs->LocalLinkIntegrityErrCnt = dd->ipath_lli_errs;
  1482. cntrs->RxVlErrCnt = 0;
  1483. cntrs->RxDlidFltrCnt = 0;
  1484. }
  1485. /* no interrupt fallback for these chips */
  1486. static int ipath_pe_nointr_fallback(struct ipath_devdata *dd)
  1487. {
  1488. return 0;
  1489. }
  1490. /*
  1491. * reset the XGXS (between serdes and IBC). Slightly less intrusive
  1492. * than resetting the IBC or external link state, and useful in some
  1493. * cases to cause some retraining. To do this right, we reset IBC
  1494. * as well.
  1495. */
  1496. static void ipath_pe_xgxs_reset(struct ipath_devdata *dd)
  1497. {
  1498. u64 val, prev_val;
  1499. prev_val = ipath_read_kreg64(dd, dd->ipath_kregs->kr_xgxsconfig);
  1500. val = prev_val | INFINIPATH_XGXS_RESET;
  1501. prev_val &= ~INFINIPATH_XGXS_RESET; /* be sure */
  1502. ipath_write_kreg(dd, dd->ipath_kregs->kr_control,
  1503. dd->ipath_control & ~INFINIPATH_C_LINKENABLE);
  1504. ipath_write_kreg(dd, dd->ipath_kregs->kr_xgxsconfig, val);
  1505. ipath_read_kreg32(dd, dd->ipath_kregs->kr_scratch);
  1506. ipath_write_kreg(dd, dd->ipath_kregs->kr_xgxsconfig, prev_val);
  1507. ipath_write_kreg(dd, dd->ipath_kregs->kr_control,
  1508. dd->ipath_control);
  1509. }
  1510. static int ipath_pe_get_ib_cfg(struct ipath_devdata *dd, int which)
  1511. {
  1512. int ret;
  1513. switch (which) {
  1514. case IPATH_IB_CFG_LWID:
  1515. ret = dd->ipath_link_width_active;
  1516. break;
  1517. case IPATH_IB_CFG_SPD:
  1518. ret = dd->ipath_link_speed_active;
  1519. break;
  1520. case IPATH_IB_CFG_LWID_ENB:
  1521. ret = dd->ipath_link_width_enabled;
  1522. break;
  1523. case IPATH_IB_CFG_SPD_ENB:
  1524. ret = dd->ipath_link_speed_enabled;
  1525. break;
  1526. default:
  1527. ret = -ENOTSUPP;
  1528. break;
  1529. }
  1530. return ret;
  1531. }
  1532. /* we assume range checking is already done, if needed */
  1533. static int ipath_pe_set_ib_cfg(struct ipath_devdata *dd, int which, u32 val)
  1534. {
  1535. int ret = 0;
  1536. if (which == IPATH_IB_CFG_LWID_ENB)
  1537. dd->ipath_link_width_enabled = val;
  1538. else if (which == IPATH_IB_CFG_SPD_ENB)
  1539. dd->ipath_link_speed_enabled = val;
  1540. else
  1541. ret = -ENOTSUPP;
  1542. return ret;
  1543. }
  1544. static void ipath_pe_config_jint(struct ipath_devdata *dd, u16 a, u16 b)
  1545. {
  1546. }
  1547. static int ipath_pe_ib_updown(struct ipath_devdata *dd, int ibup, u64 ibcs)
  1548. {
  1549. ipath_setup_pe_setextled(dd, ipath_ib_linkstate(dd, ibcs),
  1550. ipath_ib_linktrstate(dd, ibcs));
  1551. return 0;
  1552. }
  1553. /**
  1554. * ipath_init_iba6120_funcs - set up the chip-specific function pointers
  1555. * @dd: the infinipath device
  1556. *
  1557. * This is global, and is called directly at init to set up the
  1558. * chip-specific function pointers for later use.
  1559. */
  1560. void ipath_init_iba6120_funcs(struct ipath_devdata *dd)
  1561. {
  1562. dd->ipath_f_intrsetup = ipath_pe_intconfig;
  1563. dd->ipath_f_bus = ipath_setup_pe_config;
  1564. dd->ipath_f_reset = ipath_setup_pe_reset;
  1565. dd->ipath_f_get_boardname = ipath_pe_boardname;
  1566. dd->ipath_f_init_hwerrors = ipath_pe_init_hwerrors;
  1567. dd->ipath_f_early_init = ipath_pe_early_init;
  1568. dd->ipath_f_handle_hwerrors = ipath_pe_handle_hwerrors;
  1569. dd->ipath_f_quiet_serdes = ipath_pe_quiet_serdes;
  1570. dd->ipath_f_bringup_serdes = ipath_pe_bringup_serdes;
  1571. dd->ipath_f_clear_tids = ipath_pe_clear_tids;
  1572. /*
  1573. * _f_put_tid may get changed after we read the chip revision,
  1574. * but we start with the safe version for all revs
  1575. */
  1576. dd->ipath_f_put_tid = ipath_pe_put_tid;
  1577. dd->ipath_f_cleanup = ipath_setup_pe_cleanup;
  1578. dd->ipath_f_setextled = ipath_setup_pe_setextled;
  1579. dd->ipath_f_get_base_info = ipath_pe_get_base_info;
  1580. dd->ipath_f_free_irq = ipath_pe_free_irq;
  1581. dd->ipath_f_tidtemplate = ipath_pe_tidtemplate;
  1582. dd->ipath_f_intr_fallback = ipath_pe_nointr_fallback;
  1583. dd->ipath_f_xgxs_reset = ipath_pe_xgxs_reset;
  1584. dd->ipath_f_get_msgheader = ipath_pe_get_msgheader;
  1585. dd->ipath_f_config_ports = ipath_pe_config_ports;
  1586. dd->ipath_f_read_counters = ipath_pe_read_counters;
  1587. dd->ipath_f_get_ib_cfg = ipath_pe_get_ib_cfg;
  1588. dd->ipath_f_set_ib_cfg = ipath_pe_set_ib_cfg;
  1589. dd->ipath_f_config_jint = ipath_pe_config_jint;
  1590. dd->ipath_f_ib_updown = ipath_pe_ib_updown;
  1591. /* initialize chip-specific variables */
  1592. ipath_init_pe_variables(dd);
  1593. }