ipath_iba6120.c 62 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862
  1. /*
  2. * Copyright (c) 2006, 2007, 2008 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_RCVURG_SHIFT 0
  308. #define INFINIPATH_I_RCVAVAIL_MASK ((1U<<5)-1)
  309. #define INFINIPATH_I_RCVAVAIL_SHIFT 12
  310. /* kr_hwerrclear, kr_hwerrmask, kr_hwerrstatus, bits */
  311. #define INFINIPATH_HWE_PCIEMEMPARITYERR_MASK 0x000000000000003fULL
  312. #define INFINIPATH_HWE_PCIEMEMPARITYERR_SHIFT 0
  313. #define INFINIPATH_HWE_PCIEPOISONEDTLP 0x0000000010000000ULL
  314. #define INFINIPATH_HWE_PCIECPLTIMEOUT 0x0000000020000000ULL
  315. #define INFINIPATH_HWE_PCIEBUSPARITYXTLH 0x0000000040000000ULL
  316. #define INFINIPATH_HWE_PCIEBUSPARITYXADM 0x0000000080000000ULL
  317. #define INFINIPATH_HWE_PCIEBUSPARITYRADM 0x0000000100000000ULL
  318. #define INFINIPATH_HWE_COREPLL_FBSLIP 0x0080000000000000ULL
  319. #define INFINIPATH_HWE_COREPLL_RFSLIP 0x0100000000000000ULL
  320. #define INFINIPATH_HWE_PCIE1PLLFAILED 0x0400000000000000ULL
  321. #define INFINIPATH_HWE_PCIE0PLLFAILED 0x0800000000000000ULL
  322. #define INFINIPATH_HWE_SERDESPLLFAILED 0x1000000000000000ULL
  323. #define IBA6120_IBCS_LINKTRAININGSTATE_MASK 0xf
  324. #define IBA6120_IBCS_LINKSTATE_SHIFT 4
  325. /* kr_extstatus bits */
  326. #define INFINIPATH_EXTS_FREQSEL 0x2
  327. #define INFINIPATH_EXTS_SERDESSEL 0x4
  328. #define INFINIPATH_EXTS_MEMBIST_ENDTEST 0x0000000000004000
  329. #define INFINIPATH_EXTS_MEMBIST_FOUND 0x0000000000008000
  330. /* kr_xgxsconfig bits */
  331. #define INFINIPATH_XGXS_RESET 0x5ULL
  332. #define _IPATH_GPIO_SDA_NUM 1
  333. #define _IPATH_GPIO_SCL_NUM 0
  334. #define IPATH_GPIO_SDA (1ULL << \
  335. (_IPATH_GPIO_SDA_NUM+INFINIPATH_EXTC_GPIOOE_SHIFT))
  336. #define IPATH_GPIO_SCL (1ULL << \
  337. (_IPATH_GPIO_SCL_NUM+INFINIPATH_EXTC_GPIOOE_SHIFT))
  338. #define INFINIPATH_RT_BUFSIZE_MASK 0xe0000000ULL
  339. #define INFINIPATH_RT_BUFSIZE_SHIFTVAL(tid) \
  340. ((((tid) & INFINIPATH_RT_BUFSIZE_MASK) >> 29) + 11 - 1)
  341. #define INFINIPATH_RT_BUFSIZE(tid) (1 << INFINIPATH_RT_BUFSIZE_SHIFTVAL(tid))
  342. #define INFINIPATH_RT_IS_VALID(tid) \
  343. (((tid) & INFINIPATH_RT_BUFSIZE_MASK) && \
  344. ((((tid) & INFINIPATH_RT_BUFSIZE_MASK) != INFINIPATH_RT_BUFSIZE_MASK)))
  345. #define INFINIPATH_RT_ADDR_MASK 0x1FFFFFFFULL /* 29 bits valid */
  346. #define INFINIPATH_RT_ADDR_SHIFT 10
  347. #define INFINIPATH_R_INTRAVAIL_SHIFT 16
  348. #define INFINIPATH_R_TAILUPD_SHIFT 31
  349. /* 6120 specific hardware errors... */
  350. static const struct ipath_hwerror_msgs ipath_6120_hwerror_msgs[] = {
  351. INFINIPATH_HWE_MSG(PCIEPOISONEDTLP, "PCIe Poisoned TLP"),
  352. INFINIPATH_HWE_MSG(PCIECPLTIMEOUT, "PCIe completion timeout"),
  353. /*
  354. * In practice, it's unlikely wthat we'll see PCIe PLL, or bus
  355. * parity or memory parity error failures, because most likely we
  356. * won't be able to talk to the core of the chip. Nonetheless, we
  357. * might see them, if they are in parts of the PCIe core that aren't
  358. * essential.
  359. */
  360. INFINIPATH_HWE_MSG(PCIE1PLLFAILED, "PCIePLL1"),
  361. INFINIPATH_HWE_MSG(PCIE0PLLFAILED, "PCIePLL0"),
  362. INFINIPATH_HWE_MSG(PCIEBUSPARITYXTLH, "PCIe XTLH core parity"),
  363. INFINIPATH_HWE_MSG(PCIEBUSPARITYXADM, "PCIe ADM TX core parity"),
  364. INFINIPATH_HWE_MSG(PCIEBUSPARITYRADM, "PCIe ADM RX core parity"),
  365. INFINIPATH_HWE_MSG(RXDSYNCMEMPARITYERR, "Rx Dsync"),
  366. INFINIPATH_HWE_MSG(SERDESPLLFAILED, "SerDes PLL"),
  367. };
  368. #define TXE_PIO_PARITY ((INFINIPATH_HWE_TXEMEMPARITYERR_PIOBUF | \
  369. INFINIPATH_HWE_TXEMEMPARITYERR_PIOPBC) \
  370. << INFINIPATH_HWE_TXEMEMPARITYERR_SHIFT)
  371. #define RXE_EAGER_PARITY (INFINIPATH_HWE_RXEMEMPARITYERR_EAGERTID \
  372. << INFINIPATH_HWE_RXEMEMPARITYERR_SHIFT)
  373. static void ipath_pe_put_tid_2(struct ipath_devdata *, u64 __iomem *,
  374. u32, unsigned long);
  375. /*
  376. * On platforms using this chip, and not having ordered WC stores, we
  377. * can get TXE parity errors due to speculative reads to the PIO buffers,
  378. * and this, due to a chip bug can result in (many) false parity error
  379. * reports. So it's a debug print on those, and an info print on systems
  380. * where the speculative reads don't occur.
  381. */
  382. static void ipath_pe_txe_recover(struct ipath_devdata *dd)
  383. {
  384. if (ipath_unordered_wc())
  385. ipath_dbg("Recovering from TXE PIO parity error\n");
  386. else {
  387. ++ipath_stats.sps_txeparity;
  388. dev_info(&dd->pcidev->dev,
  389. "Recovering from TXE PIO parity error\n");
  390. }
  391. }
  392. /**
  393. * ipath_pe_handle_hwerrors - display hardware errors.
  394. * @dd: the infinipath device
  395. * @msg: the output buffer
  396. * @msgl: the size of the output buffer
  397. *
  398. * Use same msg buffer as regular errors to avoid excessive stack
  399. * use. Most hardware errors are catastrophic, but for right now,
  400. * we'll print them and continue. We reuse the same message buffer as
  401. * ipath_handle_errors() to avoid excessive stack usage.
  402. */
  403. static void ipath_pe_handle_hwerrors(struct ipath_devdata *dd, char *msg,
  404. size_t msgl)
  405. {
  406. ipath_err_t hwerrs;
  407. u32 bits, ctrl;
  408. int isfatal = 0;
  409. char bitsmsg[64];
  410. int log_idx;
  411. hwerrs = ipath_read_kreg64(dd, dd->ipath_kregs->kr_hwerrstatus);
  412. if (!hwerrs) {
  413. /*
  414. * better than printing cofusing messages
  415. * This seems to be related to clearing the crc error, or
  416. * the pll error during init.
  417. */
  418. ipath_cdbg(VERBOSE, "Called but no hardware errors set\n");
  419. return;
  420. } else if (hwerrs == ~0ULL) {
  421. ipath_dev_err(dd, "Read of hardware error status failed "
  422. "(all bits set); ignoring\n");
  423. return;
  424. }
  425. ipath_stats.sps_hwerrs++;
  426. /* Always clear the error status register, except MEMBISTFAIL,
  427. * regardless of whether we continue or stop using the chip.
  428. * We want that set so we know it failed, even across driver reload.
  429. * We'll still ignore it in the hwerrmask. We do this partly for
  430. * diagnostics, but also for support */
  431. ipath_write_kreg(dd, dd->ipath_kregs->kr_hwerrclear,
  432. hwerrs&~INFINIPATH_HWE_MEMBISTFAILED);
  433. hwerrs &= dd->ipath_hwerrmask;
  434. /* We log some errors to EEPROM, check if we have any of those. */
  435. for (log_idx = 0; log_idx < IPATH_EEP_LOG_CNT; ++log_idx)
  436. if (hwerrs & dd->ipath_eep_st_masks[log_idx].hwerrs_to_log)
  437. ipath_inc_eeprom_err(dd, log_idx, 1);
  438. /*
  439. * make sure we get this much out, unless told to be quiet,
  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) {
  463. ipath_pe_txe_recover(dd);
  464. hwerrs &= ~TXE_PIO_PARITY;
  465. }
  466. if (!hwerrs) {
  467. static u32 freeze_cnt;
  468. freeze_cnt++;
  469. ipath_dbg("Clearing freezemode on ignored or recovered "
  470. "hardware error (%u)\n", freeze_cnt);
  471. ipath_clear_freeze(dd);
  472. }
  473. }
  474. *msg = '\0';
  475. if (hwerrs & INFINIPATH_HWE_MEMBISTFAILED) {
  476. strlcat(msg, "[Memory BIST test failed, InfiniPath hardware unusable]",
  477. msgl);
  478. /* ignore from now on, so disable until driver reloaded */
  479. *dd->ipath_statusp |= IPATH_STATUS_HWERROR;
  480. dd->ipath_hwerrmask &= ~INFINIPATH_HWE_MEMBISTFAILED;
  481. ipath_write_kreg(dd, dd->ipath_kregs->kr_hwerrmask,
  482. dd->ipath_hwerrmask);
  483. }
  484. ipath_format_hwerrors(hwerrs,
  485. ipath_6120_hwerror_msgs,
  486. sizeof(ipath_6120_hwerror_msgs)/
  487. sizeof(ipath_6120_hwerror_msgs[0]),
  488. msg, msgl);
  489. if (hwerrs & (INFINIPATH_HWE_PCIEMEMPARITYERR_MASK
  490. << INFINIPATH_HWE_PCIEMEMPARITYERR_SHIFT)) {
  491. bits = (u32) ((hwerrs >>
  492. INFINIPATH_HWE_PCIEMEMPARITYERR_SHIFT) &
  493. INFINIPATH_HWE_PCIEMEMPARITYERR_MASK);
  494. snprintf(bitsmsg, sizeof bitsmsg,
  495. "[PCIe Mem Parity Errs %x] ", bits);
  496. strlcat(msg, bitsmsg, msgl);
  497. }
  498. #define _IPATH_PLL_FAIL (INFINIPATH_HWE_COREPLL_FBSLIP | \
  499. INFINIPATH_HWE_COREPLL_RFSLIP )
  500. if (hwerrs & _IPATH_PLL_FAIL) {
  501. snprintf(bitsmsg, sizeof bitsmsg,
  502. "[PLL failed (%llx), InfiniPath hardware unusable]",
  503. (unsigned long long) hwerrs & _IPATH_PLL_FAIL);
  504. strlcat(msg, bitsmsg, msgl);
  505. /* ignore from now on, so disable until driver reloaded */
  506. dd->ipath_hwerrmask &= ~(hwerrs & _IPATH_PLL_FAIL);
  507. ipath_write_kreg(dd, dd->ipath_kregs->kr_hwerrmask,
  508. dd->ipath_hwerrmask);
  509. }
  510. if (hwerrs & INFINIPATH_HWE_SERDESPLLFAILED) {
  511. /*
  512. * If it occurs, it is left masked since the external
  513. * interface is unused
  514. */
  515. dd->ipath_hwerrmask &= ~INFINIPATH_HWE_SERDESPLLFAILED;
  516. ipath_write_kreg(dd, dd->ipath_kregs->kr_hwerrmask,
  517. dd->ipath_hwerrmask);
  518. }
  519. if (hwerrs) {
  520. /*
  521. * if any set that we aren't ignoring; only
  522. * make the complaint once, in case it's stuck
  523. * or recurring, and we get here multiple
  524. * times.
  525. */
  526. ipath_dev_err(dd, "%s hardware error\n", msg);
  527. if (dd->ipath_flags & IPATH_INITTED) {
  528. ipath_set_linkstate(dd, IPATH_IB_LINKDOWN);
  529. ipath_setup_pe_setextled(dd,
  530. INFINIPATH_IBCS_L_STATE_DOWN,
  531. INFINIPATH_IBCS_LT_STATE_DISABLED);
  532. ipath_dev_err(dd, "Fatal Hardware Error (freeze "
  533. "mode), no longer usable, SN %.16s\n",
  534. dd->ipath_serial);
  535. isfatal = 1;
  536. }
  537. *dd->ipath_statusp &= ~IPATH_STATUS_IB_READY;
  538. /* mark as having had error */
  539. *dd->ipath_statusp |= IPATH_STATUS_HWERROR;
  540. /*
  541. * mark as not usable, at a minimum until driver
  542. * is reloaded, probably until reboot, since no
  543. * other reset is possible.
  544. */
  545. dd->ipath_flags &= ~IPATH_INITTED;
  546. } else
  547. *msg = 0; /* recovered from all of them */
  548. if (isfatal && !ipath_diag_inuse && dd->ipath_freezemsg && msg) {
  549. /*
  550. * for /sys status file ; if no trailing brace is copied,
  551. * we'll know it was truncated.
  552. */
  553. snprintf(dd->ipath_freezemsg, dd->ipath_freezelen,
  554. "{%s}", msg);
  555. }
  556. }
  557. /**
  558. * ipath_pe_boardname - fill in the board name
  559. * @dd: the infinipath device
  560. * @name: the output buffer
  561. * @namelen: the size of the output buffer
  562. *
  563. * info is based on the board revision register
  564. */
  565. static int ipath_pe_boardname(struct ipath_devdata *dd, char *name,
  566. size_t namelen)
  567. {
  568. char *n = NULL;
  569. u8 boardrev = dd->ipath_boardrev;
  570. int ret;
  571. switch (boardrev) {
  572. case 0:
  573. n = "InfiniPath_Emulation";
  574. break;
  575. case 1:
  576. n = "InfiniPath_QLE7140-Bringup";
  577. break;
  578. case 2:
  579. n = "InfiniPath_QLE7140";
  580. break;
  581. case 3:
  582. n = "InfiniPath_QMI7140";
  583. break;
  584. case 4:
  585. n = "InfiniPath_QEM7140";
  586. break;
  587. case 5:
  588. n = "InfiniPath_QMH7140";
  589. break;
  590. case 6:
  591. n = "InfiniPath_QLE7142";
  592. break;
  593. default:
  594. ipath_dev_err(dd,
  595. "Don't yet know about board with ID %u\n",
  596. boardrev);
  597. snprintf(name, namelen, "Unknown_InfiniPath_PCIe_%u",
  598. boardrev);
  599. break;
  600. }
  601. if (n)
  602. snprintf(name, namelen, "%s", n);
  603. if (dd->ipath_majrev != 4 || !dd->ipath_minrev || dd->ipath_minrev>2) {
  604. ipath_dev_err(dd, "Unsupported InfiniPath hardware revision %u.%u!\n",
  605. dd->ipath_majrev, dd->ipath_minrev);
  606. ret = 1;
  607. } else {
  608. ret = 0;
  609. if (dd->ipath_minrev >= 2)
  610. dd->ipath_f_put_tid = ipath_pe_put_tid_2;
  611. }
  612. /*
  613. * set here, not in ipath_init_*_funcs because we have to do
  614. * it after we can read chip registers.
  615. */
  616. dd->ipath_ureg_align =
  617. ipath_read_kreg32(dd, dd->ipath_kregs->kr_pagealign);
  618. return ret;
  619. }
  620. /**
  621. * ipath_pe_init_hwerrors - enable hardware errors
  622. * @dd: the infinipath device
  623. *
  624. * now that we have finished initializing everything that might reasonably
  625. * cause a hardware error, and cleared those errors bits as they occur,
  626. * we can enable hardware errors in the mask (potentially enabling
  627. * freeze mode), and enable hardware errors as errors (along with
  628. * everything else) in errormask
  629. */
  630. static void ipath_pe_init_hwerrors(struct ipath_devdata *dd)
  631. {
  632. ipath_err_t val;
  633. u64 extsval;
  634. extsval = ipath_read_kreg64(dd, dd->ipath_kregs->kr_extstatus);
  635. if (!(extsval & INFINIPATH_EXTS_MEMBIST_ENDTEST))
  636. ipath_dev_err(dd, "MemBIST did not complete!\n");
  637. if (extsval & INFINIPATH_EXTS_MEMBIST_FOUND)
  638. ipath_dbg("MemBIST corrected\n");
  639. val = ~0ULL; /* barring bugs, all hwerrors become interrupts, */
  640. if (!dd->ipath_boardrev) // no PLL for Emulator
  641. val &= ~INFINIPATH_HWE_SERDESPLLFAILED;
  642. if (dd->ipath_minrev < 2) {
  643. /* workaround bug 9460 in internal interface bus parity
  644. * checking. Fixed (HW bug 9490) in Rev2.
  645. */
  646. val &= ~INFINIPATH_HWE_PCIEBUSPARITYRADM;
  647. }
  648. dd->ipath_hwerrmask = val;
  649. }
  650. /**
  651. * ipath_pe_bringup_serdes - bring up the serdes
  652. * @dd: the infinipath device
  653. */
  654. static int ipath_pe_bringup_serdes(struct ipath_devdata *dd)
  655. {
  656. u64 val, config1, prev_val;
  657. int ret = 0;
  658. ipath_dbg("Trying to bringup serdes\n");
  659. if (ipath_read_kreg64(dd, dd->ipath_kregs->kr_hwerrstatus) &
  660. INFINIPATH_HWE_SERDESPLLFAILED) {
  661. ipath_dbg("At start, serdes PLL failed bit set "
  662. "in hwerrstatus, clearing and continuing\n");
  663. ipath_write_kreg(dd, dd->ipath_kregs->kr_hwerrclear,
  664. INFINIPATH_HWE_SERDESPLLFAILED);
  665. }
  666. dd->ibdeltainprog = 1;
  667. dd->ibsymsnap =
  668. ipath_read_creg32(dd, dd->ipath_cregs->cr_ibsymbolerrcnt);
  669. dd->iblnkerrsnap =
  670. ipath_read_creg32(dd, dd->ipath_cregs->cr_iblinkerrrecovcnt);
  671. val = ipath_read_kreg64(dd, dd->ipath_kregs->kr_serdesconfig0);
  672. config1 = ipath_read_kreg64(dd, dd->ipath_kregs->kr_serdesconfig1);
  673. ipath_cdbg(VERBOSE, "SerDes status config0=%llx config1=%llx, "
  674. "xgxsconfig %llx\n", (unsigned long long) val,
  675. (unsigned long long) config1, (unsigned long long)
  676. ipath_read_kreg64(dd, dd->ipath_kregs->kr_xgxsconfig));
  677. /*
  678. * Force reset on, also set rxdetect enable. Must do before reading
  679. * serdesstatus at least for simulation, or some of the bits in
  680. * serdes status will come back as undefined and cause simulation
  681. * failures
  682. */
  683. val |= INFINIPATH_SERDC0_RESET_PLL | INFINIPATH_SERDC0_RXDETECT_EN
  684. | INFINIPATH_SERDC0_L1PWR_DN;
  685. ipath_write_kreg(dd, dd->ipath_kregs->kr_serdesconfig0, val);
  686. /* be sure chip saw it */
  687. ipath_read_kreg64(dd, dd->ipath_kregs->kr_scratch);
  688. udelay(5); /* need pll reset set at least for a bit */
  689. /*
  690. * after PLL is reset, set the per-lane Resets and TxIdle and
  691. * clear the PLL reset and rxdetect (to get falling edge).
  692. * Leave L1PWR bits set (permanently)
  693. */
  694. val &= ~(INFINIPATH_SERDC0_RXDETECT_EN | INFINIPATH_SERDC0_RESET_PLL
  695. | INFINIPATH_SERDC0_L1PWR_DN);
  696. val |= INFINIPATH_SERDC0_RESET_MASK | INFINIPATH_SERDC0_TXIDLE;
  697. ipath_cdbg(VERBOSE, "Clearing pll reset and setting lane resets "
  698. "and txidle (%llx)\n", (unsigned long long) val);
  699. ipath_write_kreg(dd, dd->ipath_kregs->kr_serdesconfig0, val);
  700. /* be sure chip saw it */
  701. ipath_read_kreg64(dd, dd->ipath_kregs->kr_scratch);
  702. /* need PLL reset clear for at least 11 usec before lane
  703. * resets cleared; give it a few more to be sure */
  704. udelay(15);
  705. val &= ~(INFINIPATH_SERDC0_RESET_MASK | INFINIPATH_SERDC0_TXIDLE);
  706. ipath_cdbg(VERBOSE, "Clearing lane resets and txidle "
  707. "(writing %llx)\n", (unsigned long long) val);
  708. ipath_write_kreg(dd, dd->ipath_kregs->kr_serdesconfig0, val);
  709. /* be sure chip saw it */
  710. val = ipath_read_kreg64(dd, dd->ipath_kregs->kr_scratch);
  711. val = ipath_read_kreg64(dd, dd->ipath_kregs->kr_xgxsconfig);
  712. prev_val = val;
  713. if (val & INFINIPATH_XGXS_RESET)
  714. val &= ~INFINIPATH_XGXS_RESET;
  715. if (((val >> INFINIPATH_XGXS_RX_POL_SHIFT) &
  716. INFINIPATH_XGXS_RX_POL_MASK) != dd->ipath_rx_pol_inv ) {
  717. /* need to compensate for Tx inversion in partner */
  718. val &= ~(INFINIPATH_XGXS_RX_POL_MASK <<
  719. INFINIPATH_XGXS_RX_POL_SHIFT);
  720. val |= dd->ipath_rx_pol_inv <<
  721. INFINIPATH_XGXS_RX_POL_SHIFT;
  722. }
  723. if (val != prev_val)
  724. ipath_write_kreg(dd, dd->ipath_kregs->kr_xgxsconfig, val);
  725. val = ipath_read_kreg64(dd, dd->ipath_kregs->kr_serdesconfig0);
  726. /* clear current and de-emphasis bits */
  727. config1 &= ~0x0ffffffff00ULL;
  728. /* set current to 20ma */
  729. config1 |= 0x00000000000ULL;
  730. /* set de-emphasis to -5.68dB */
  731. config1 |= 0x0cccc000000ULL;
  732. ipath_write_kreg(dd, dd->ipath_kregs->kr_serdesconfig1, config1);
  733. ipath_cdbg(VERBOSE, "done: SerDes status config0=%llx "
  734. "config1=%llx, sstatus=%llx xgxs=%llx\n",
  735. (unsigned long long) val, (unsigned long long) config1,
  736. (unsigned long long)
  737. ipath_read_kreg64(dd, dd->ipath_kregs->kr_serdesstatus),
  738. (unsigned long long)
  739. ipath_read_kreg64(dd, dd->ipath_kregs->kr_xgxsconfig));
  740. return ret;
  741. }
  742. /**
  743. * ipath_pe_quiet_serdes - set serdes to txidle
  744. * @dd: the infinipath device
  745. * Called when driver is being unloaded
  746. */
  747. static void ipath_pe_quiet_serdes(struct ipath_devdata *dd)
  748. {
  749. u64 val = ipath_read_kreg64(dd, dd->ipath_kregs->kr_serdesconfig0);
  750. if (dd->ibsymdelta || dd->iblnkerrdelta ||
  751. dd->ibdeltainprog) {
  752. u64 diagc;
  753. /* enable counter writes */
  754. diagc = ipath_read_kreg64(dd, dd->ipath_kregs->kr_hwdiagctrl);
  755. ipath_write_kreg(dd, dd->ipath_kregs->kr_hwdiagctrl,
  756. diagc | INFINIPATH_DC_COUNTERWREN);
  757. if (dd->ibsymdelta || dd->ibdeltainprog) {
  758. val = ipath_read_creg32(dd,
  759. dd->ipath_cregs->cr_ibsymbolerrcnt);
  760. if (dd->ibdeltainprog)
  761. val -= val - dd->ibsymsnap;
  762. val -= dd->ibsymdelta;
  763. ipath_write_creg(dd,
  764. dd->ipath_cregs->cr_ibsymbolerrcnt, val);
  765. }
  766. if (dd->iblnkerrdelta || dd->ibdeltainprog) {
  767. val = ipath_read_creg32(dd,
  768. dd->ipath_cregs->cr_iblinkerrrecovcnt);
  769. if (dd->ibdeltainprog)
  770. val -= val - dd->iblnkerrsnap;
  771. val -= dd->iblnkerrdelta;
  772. ipath_write_creg(dd,
  773. dd->ipath_cregs->cr_iblinkerrrecovcnt, val);
  774. }
  775. /* and disable counter writes */
  776. ipath_write_kreg(dd, dd->ipath_kregs->kr_hwdiagctrl, diagc);
  777. }
  778. val |= INFINIPATH_SERDC0_TXIDLE;
  779. ipath_dbg("Setting TxIdleEn on serdes (config0 = %llx)\n",
  780. (unsigned long long) val);
  781. ipath_write_kreg(dd, dd->ipath_kregs->kr_serdesconfig0, val);
  782. }
  783. static int ipath_pe_intconfig(struct ipath_devdata *dd)
  784. {
  785. u32 chiprev;
  786. /*
  787. * If the chip supports added error indication via GPIO pins,
  788. * enable interrupts on those bits so the interrupt routine
  789. * can count the events. Also set flag so interrupt routine
  790. * can know they are expected.
  791. */
  792. chiprev = dd->ipath_revision >> INFINIPATH_R_CHIPREVMINOR_SHIFT;
  793. if ((chiprev & INFINIPATH_R_CHIPREVMINOR_MASK) > 1) {
  794. /* Rev2+ reports extra errors via internal GPIO pins */
  795. dd->ipath_flags |= IPATH_GPIO_ERRINTRS;
  796. dd->ipath_gpio_mask |= IPATH_GPIO_ERRINTR_MASK;
  797. ipath_write_kreg(dd, dd->ipath_kregs->kr_gpio_mask,
  798. dd->ipath_gpio_mask);
  799. }
  800. return 0;
  801. }
  802. /**
  803. * ipath_setup_pe_setextled - set the state of the two external LEDs
  804. * @dd: the infinipath device
  805. * @lst: the L state
  806. * @ltst: the LT state
  807. * These LEDs indicate the physical and logical state of IB link.
  808. * For this chip (at least with recommended board pinouts), LED1
  809. * is Yellow (logical state) and LED2 is Green (physical state),
  810. *
  811. * Note: We try to match the Mellanox HCA LED behavior as best
  812. * we can. Green indicates physical link state is OK (something is
  813. * plugged in, and we can train).
  814. * Amber indicates the link is logically up (ACTIVE).
  815. * Mellanox further blinks the amber LED to indicate data packet
  816. * activity, but we have no hardware support for that, so it would
  817. * require waking up every 10-20 msecs and checking the counters
  818. * on the chip, and then turning the LED off if appropriate. That's
  819. * visible overhead, so not something we will do.
  820. *
  821. */
  822. static void ipath_setup_pe_setextled(struct ipath_devdata *dd, u64 lst,
  823. u64 ltst)
  824. {
  825. u64 extctl;
  826. unsigned long flags = 0;
  827. /* the diags use the LED to indicate diag info, so we leave
  828. * the external LED alone when the diags are running */
  829. if (ipath_diag_inuse)
  830. return;
  831. /* Allow override of LED display for, e.g. Locating system in rack */
  832. if (dd->ipath_led_override) {
  833. ltst = (dd->ipath_led_override & IPATH_LED_PHYS)
  834. ? INFINIPATH_IBCS_LT_STATE_LINKUP
  835. : INFINIPATH_IBCS_LT_STATE_DISABLED;
  836. lst = (dd->ipath_led_override & IPATH_LED_LOG)
  837. ? INFINIPATH_IBCS_L_STATE_ACTIVE
  838. : INFINIPATH_IBCS_L_STATE_DOWN;
  839. }
  840. spin_lock_irqsave(&dd->ipath_gpio_lock, flags);
  841. extctl = dd->ipath_extctrl & ~(INFINIPATH_EXTC_LED1PRIPORT_ON |
  842. INFINIPATH_EXTC_LED2PRIPORT_ON);
  843. if (ltst == INFINIPATH_IBCS_LT_STATE_LINKUP)
  844. extctl |= INFINIPATH_EXTC_LED2PRIPORT_ON;
  845. if (lst == INFINIPATH_IBCS_L_STATE_ACTIVE)
  846. extctl |= INFINIPATH_EXTC_LED1PRIPORT_ON;
  847. dd->ipath_extctrl = extctl;
  848. ipath_write_kreg(dd, dd->ipath_kregs->kr_extctrl, extctl);
  849. spin_unlock_irqrestore(&dd->ipath_gpio_lock, flags);
  850. }
  851. /**
  852. * ipath_setup_pe_cleanup - clean up any per-chip chip-specific stuff
  853. * @dd: the infinipath device
  854. *
  855. * This is called during driver unload.
  856. * We do the pci_disable_msi here, not in generic code, because it
  857. * isn't used for the HT chips. If we do end up needing pci_enable_msi
  858. * at some point in the future for HT, we'll move the call back
  859. * into the main init_one code.
  860. */
  861. static void ipath_setup_pe_cleanup(struct ipath_devdata *dd)
  862. {
  863. dd->ipath_msi_lo = 0; /* just in case unload fails */
  864. pci_disable_msi(dd->pcidev);
  865. }
  866. static void ipath_6120_pcie_params(struct ipath_devdata *dd)
  867. {
  868. u16 linkstat, speed;
  869. int pos;
  870. pos = pci_find_capability(dd->pcidev, PCI_CAP_ID_EXP);
  871. if (!pos) {
  872. ipath_dev_err(dd, "Can't find PCI Express capability!\n");
  873. goto bail;
  874. }
  875. pci_read_config_word(dd->pcidev, pos + PCI_EXP_LNKSTA,
  876. &linkstat);
  877. /*
  878. * speed is bits 0-4, linkwidth is bits 4-8
  879. * no defines for them in headers
  880. */
  881. speed = linkstat & 0xf;
  882. linkstat >>= 4;
  883. linkstat &= 0x1f;
  884. dd->ipath_lbus_width = linkstat;
  885. switch (speed) {
  886. case 1:
  887. dd->ipath_lbus_speed = 2500; /* Gen1, 2.5GHz */
  888. break;
  889. case 2:
  890. dd->ipath_lbus_speed = 5000; /* Gen1, 5GHz */
  891. break;
  892. default: /* not defined, assume gen1 */
  893. dd->ipath_lbus_speed = 2500;
  894. break;
  895. }
  896. if (linkstat < 8)
  897. ipath_dev_err(dd,
  898. "PCIe width %u (x8 HCA), performance reduced\n",
  899. linkstat);
  900. else
  901. ipath_cdbg(VERBOSE, "PCIe speed %u width %u (x8 HCA)\n",
  902. dd->ipath_lbus_speed, linkstat);
  903. if (speed != 1)
  904. ipath_dev_err(dd,
  905. "PCIe linkspeed %u is incorrect; "
  906. "should be 1 (2500)!\n", speed);
  907. bail:
  908. /* fill in string, even on errors */
  909. snprintf(dd->ipath_lbus_info, sizeof(dd->ipath_lbus_info),
  910. "PCIe,%uMHz,x%u\n",
  911. dd->ipath_lbus_speed,
  912. dd->ipath_lbus_width);
  913. return;
  914. }
  915. /**
  916. * ipath_setup_pe_config - setup PCIe config related stuff
  917. * @dd: the infinipath device
  918. * @pdev: the PCI device
  919. *
  920. * The pci_enable_msi() call will fail on systems with MSI quirks
  921. * such as those with AMD8131, even if the device of interest is not
  922. * attached to that device, (in the 2.6.13 - 2.6.15 kernels, at least, fixed
  923. * late in 2.6.16).
  924. * All that can be done is to edit the kernel source to remove the quirk
  925. * check until that is fixed.
  926. * We do not need to call enable_msi() for our HyperTransport chip,
  927. * even though it uses MSI, and we want to avoid the quirk warning, so
  928. * So we call enable_msi only for PCIe. If we do end up needing
  929. * pci_enable_msi at some point in the future for HT, we'll move the
  930. * call back into the main init_one code.
  931. * We save the msi lo and hi values, so we can restore them after
  932. * chip reset (the kernel PCI infrastructure doesn't yet handle that
  933. * correctly).
  934. */
  935. static int ipath_setup_pe_config(struct ipath_devdata *dd,
  936. struct pci_dev *pdev)
  937. {
  938. int pos, ret;
  939. dd->ipath_msi_lo = 0; /* used as a flag during reset processing */
  940. ret = pci_enable_msi(dd->pcidev);
  941. if (ret)
  942. ipath_dev_err(dd, "pci_enable_msi failed: %d, "
  943. "interrupts may not work\n", ret);
  944. /* continue even if it fails, we may still be OK... */
  945. dd->ipath_irq = pdev->irq;
  946. if ((pos = pci_find_capability(dd->pcidev, PCI_CAP_ID_MSI))) {
  947. u16 control;
  948. pci_read_config_dword(dd->pcidev, pos + PCI_MSI_ADDRESS_LO,
  949. &dd->ipath_msi_lo);
  950. pci_read_config_dword(dd->pcidev, pos + PCI_MSI_ADDRESS_HI,
  951. &dd->ipath_msi_hi);
  952. pci_read_config_word(dd->pcidev, pos + PCI_MSI_FLAGS,
  953. &control);
  954. /* now save the data (vector) info */
  955. pci_read_config_word(dd->pcidev,
  956. pos + ((control & PCI_MSI_FLAGS_64BIT)
  957. ? 12 : 8),
  958. &dd->ipath_msi_data);
  959. ipath_cdbg(VERBOSE, "Read msi data 0x%x from config offset "
  960. "0x%x, control=0x%x\n", dd->ipath_msi_data,
  961. pos + ((control & PCI_MSI_FLAGS_64BIT) ? 12 : 8),
  962. control);
  963. /* we save the cachelinesize also, although it doesn't
  964. * really matter */
  965. pci_read_config_byte(dd->pcidev, PCI_CACHE_LINE_SIZE,
  966. &dd->ipath_pci_cacheline);
  967. } else
  968. ipath_dev_err(dd, "Can't find MSI capability, "
  969. "can't save MSI settings for reset\n");
  970. ipath_6120_pcie_params(dd);
  971. dd->ipath_link_width_supported = IB_WIDTH_1X | IB_WIDTH_4X;
  972. dd->ipath_link_speed_supported = IPATH_IB_SDR;
  973. dd->ipath_link_width_enabled = IB_WIDTH_4X;
  974. dd->ipath_link_speed_enabled = dd->ipath_link_speed_supported;
  975. /* these can't change for this chip, so set once */
  976. dd->ipath_link_width_active = dd->ipath_link_width_enabled;
  977. dd->ipath_link_speed_active = dd->ipath_link_speed_enabled;
  978. return 0;
  979. }
  980. static void ipath_init_pe_variables(struct ipath_devdata *dd)
  981. {
  982. /*
  983. * setup the register offsets, since they are different for each
  984. * chip
  985. */
  986. dd->ipath_kregs = &ipath_pe_kregs;
  987. dd->ipath_cregs = &ipath_pe_cregs;
  988. /*
  989. * bits for selecting i2c direction and values,
  990. * used for I2C serial flash
  991. */
  992. dd->ipath_gpio_sda_num = _IPATH_GPIO_SDA_NUM;
  993. dd->ipath_gpio_scl_num = _IPATH_GPIO_SCL_NUM;
  994. dd->ipath_gpio_sda = IPATH_GPIO_SDA;
  995. dd->ipath_gpio_scl = IPATH_GPIO_SCL;
  996. /*
  997. * Fill in data for field-values that change in newer chips.
  998. * We dynamically specify only the mask for LINKTRAININGSTATE
  999. * and only the shift for LINKSTATE, as they are the only ones
  1000. * that change. Also precalculate the 3 link states of interest
  1001. * and the combined mask.
  1002. */
  1003. dd->ibcs_ls_shift = IBA6120_IBCS_LINKSTATE_SHIFT;
  1004. dd->ibcs_lts_mask = IBA6120_IBCS_LINKTRAININGSTATE_MASK;
  1005. dd->ibcs_mask = (INFINIPATH_IBCS_LINKSTATE_MASK <<
  1006. dd->ibcs_ls_shift) | dd->ibcs_lts_mask;
  1007. dd->ib_init = (INFINIPATH_IBCS_LT_STATE_LINKUP <<
  1008. INFINIPATH_IBCS_LINKTRAININGSTATE_SHIFT) |
  1009. (INFINIPATH_IBCS_L_STATE_INIT << dd->ibcs_ls_shift);
  1010. dd->ib_arm = (INFINIPATH_IBCS_LT_STATE_LINKUP <<
  1011. INFINIPATH_IBCS_LINKTRAININGSTATE_SHIFT) |
  1012. (INFINIPATH_IBCS_L_STATE_ARM << dd->ibcs_ls_shift);
  1013. dd->ib_active = (INFINIPATH_IBCS_LT_STATE_LINKUP <<
  1014. INFINIPATH_IBCS_LINKTRAININGSTATE_SHIFT) |
  1015. (INFINIPATH_IBCS_L_STATE_ACTIVE << dd->ibcs_ls_shift);
  1016. /*
  1017. * Fill in data for ibcc field-values that change in newer chips.
  1018. * We dynamically specify only the mask for LINKINITCMD
  1019. * and only the shift for LINKCMD and MAXPKTLEN, as they are
  1020. * the only ones that change.
  1021. */
  1022. dd->ibcc_lic_mask = INFINIPATH_IBCC_LINKINITCMD_MASK;
  1023. dd->ibcc_lc_shift = INFINIPATH_IBCC_LINKCMD_SHIFT;
  1024. dd->ibcc_mpl_shift = INFINIPATH_IBCC_MAXPKTLEN_SHIFT;
  1025. /* Fill in shifts for RcvCtrl. */
  1026. dd->ipath_r_portenable_shift = INFINIPATH_R_PORTENABLE_SHIFT;
  1027. dd->ipath_r_intravail_shift = INFINIPATH_R_INTRAVAIL_SHIFT;
  1028. dd->ipath_r_tailupd_shift = INFINIPATH_R_TAILUPD_SHIFT;
  1029. dd->ipath_r_portcfg_shift = 0; /* Not on IBA6120 */
  1030. /* variables for sanity checking interrupt and errors */
  1031. dd->ipath_hwe_bitsextant =
  1032. (INFINIPATH_HWE_RXEMEMPARITYERR_MASK <<
  1033. INFINIPATH_HWE_RXEMEMPARITYERR_SHIFT) |
  1034. (INFINIPATH_HWE_TXEMEMPARITYERR_MASK <<
  1035. INFINIPATH_HWE_TXEMEMPARITYERR_SHIFT) |
  1036. (INFINIPATH_HWE_PCIEMEMPARITYERR_MASK <<
  1037. INFINIPATH_HWE_PCIEMEMPARITYERR_SHIFT) |
  1038. INFINIPATH_HWE_PCIE1PLLFAILED |
  1039. INFINIPATH_HWE_PCIE0PLLFAILED |
  1040. INFINIPATH_HWE_PCIEPOISONEDTLP |
  1041. INFINIPATH_HWE_PCIECPLTIMEOUT |
  1042. INFINIPATH_HWE_PCIEBUSPARITYXTLH |
  1043. INFINIPATH_HWE_PCIEBUSPARITYXADM |
  1044. INFINIPATH_HWE_PCIEBUSPARITYRADM |
  1045. INFINIPATH_HWE_MEMBISTFAILED |
  1046. INFINIPATH_HWE_COREPLL_FBSLIP |
  1047. INFINIPATH_HWE_COREPLL_RFSLIP |
  1048. INFINIPATH_HWE_SERDESPLLFAILED |
  1049. INFINIPATH_HWE_IBCBUSTOSPCPARITYERR |
  1050. INFINIPATH_HWE_IBCBUSFRSPCPARITYERR;
  1051. dd->ipath_i_bitsextant =
  1052. (INFINIPATH_I_RCVURG_MASK << INFINIPATH_I_RCVURG_SHIFT) |
  1053. (INFINIPATH_I_RCVAVAIL_MASK <<
  1054. INFINIPATH_I_RCVAVAIL_SHIFT) |
  1055. INFINIPATH_I_ERROR | INFINIPATH_I_SPIOSENT |
  1056. INFINIPATH_I_SPIOBUFAVAIL | INFINIPATH_I_GPIO;
  1057. dd->ipath_e_bitsextant =
  1058. INFINIPATH_E_RFORMATERR | INFINIPATH_E_RVCRC |
  1059. INFINIPATH_E_RICRC | INFINIPATH_E_RMINPKTLEN |
  1060. INFINIPATH_E_RMAXPKTLEN | INFINIPATH_E_RLONGPKTLEN |
  1061. INFINIPATH_E_RSHORTPKTLEN | INFINIPATH_E_RUNEXPCHAR |
  1062. INFINIPATH_E_RUNSUPVL | INFINIPATH_E_REBP |
  1063. INFINIPATH_E_RIBFLOW | INFINIPATH_E_RBADVERSION |
  1064. INFINIPATH_E_RRCVEGRFULL | INFINIPATH_E_RRCVHDRFULL |
  1065. INFINIPATH_E_RBADTID | INFINIPATH_E_RHDRLEN |
  1066. INFINIPATH_E_RHDR | INFINIPATH_E_RIBLOSTLINK |
  1067. INFINIPATH_E_SMINPKTLEN | INFINIPATH_E_SMAXPKTLEN |
  1068. INFINIPATH_E_SUNDERRUN | INFINIPATH_E_SPKTLEN |
  1069. INFINIPATH_E_SDROPPEDSMPPKT | INFINIPATH_E_SDROPPEDDATAPKT |
  1070. INFINIPATH_E_SPIOARMLAUNCH | INFINIPATH_E_SUNEXPERRPKTNUM |
  1071. INFINIPATH_E_SUNSUPVL | INFINIPATH_E_IBSTATUSCHANGED |
  1072. INFINIPATH_E_INVALIDADDR | INFINIPATH_E_RESET |
  1073. INFINIPATH_E_HARDWARE;
  1074. dd->ipath_i_rcvavail_mask = INFINIPATH_I_RCVAVAIL_MASK;
  1075. dd->ipath_i_rcvurg_mask = INFINIPATH_I_RCVURG_MASK;
  1076. dd->ipath_i_rcvavail_shift = INFINIPATH_I_RCVAVAIL_SHIFT;
  1077. dd->ipath_i_rcvurg_shift = INFINIPATH_I_RCVURG_SHIFT;
  1078. /*
  1079. * EEPROM error log 0 is TXE Parity errors. 1 is RXE Parity.
  1080. * 2 is Some Misc, 3 is reserved for future.
  1081. */
  1082. dd->ipath_eep_st_masks[0].hwerrs_to_log =
  1083. INFINIPATH_HWE_TXEMEMPARITYERR_MASK <<
  1084. INFINIPATH_HWE_TXEMEMPARITYERR_SHIFT;
  1085. /* Ignore errors in PIO/PBC on systems with unordered write-combining */
  1086. if (ipath_unordered_wc())
  1087. dd->ipath_eep_st_masks[0].hwerrs_to_log &= ~TXE_PIO_PARITY;
  1088. dd->ipath_eep_st_masks[1].hwerrs_to_log =
  1089. INFINIPATH_HWE_RXEMEMPARITYERR_MASK <<
  1090. INFINIPATH_HWE_RXEMEMPARITYERR_SHIFT;
  1091. dd->ipath_eep_st_masks[2].errs_to_log = INFINIPATH_E_RESET;
  1092. dd->delay_mult = 2; /* SDR, 4X, can't change */
  1093. }
  1094. /* setup the MSI stuff again after a reset. I'd like to just call
  1095. * pci_enable_msi() and request_irq() again, but when I do that,
  1096. * the MSI enable bit doesn't get set in the command word, and
  1097. * we switch to to a different interrupt vector, which is confusing,
  1098. * so I instead just do it all inline. Perhaps somehow can tie this
  1099. * into the PCIe hotplug support at some point
  1100. * Note, because I'm doing it all here, I don't call pci_disable_msi()
  1101. * or free_irq() at the start of ipath_setup_pe_reset().
  1102. */
  1103. static int ipath_reinit_msi(struct ipath_devdata *dd)
  1104. {
  1105. int pos;
  1106. u16 control;
  1107. int ret;
  1108. if (!dd->ipath_msi_lo) {
  1109. dev_info(&dd->pcidev->dev, "Can't restore MSI config, "
  1110. "initial setup failed?\n");
  1111. ret = 0;
  1112. goto bail;
  1113. }
  1114. if (!(pos = pci_find_capability(dd->pcidev, PCI_CAP_ID_MSI))) {
  1115. ipath_dev_err(dd, "Can't find MSI capability, "
  1116. "can't restore MSI settings\n");
  1117. ret = 0;
  1118. goto bail;
  1119. }
  1120. ipath_cdbg(VERBOSE, "Writing msi_lo 0x%x to config offset 0x%x\n",
  1121. dd->ipath_msi_lo, pos + PCI_MSI_ADDRESS_LO);
  1122. pci_write_config_dword(dd->pcidev, pos + PCI_MSI_ADDRESS_LO,
  1123. dd->ipath_msi_lo);
  1124. ipath_cdbg(VERBOSE, "Writing msi_lo 0x%x to config offset 0x%x\n",
  1125. dd->ipath_msi_hi, pos + PCI_MSI_ADDRESS_HI);
  1126. pci_write_config_dword(dd->pcidev, pos + PCI_MSI_ADDRESS_HI,
  1127. dd->ipath_msi_hi);
  1128. pci_read_config_word(dd->pcidev, pos + PCI_MSI_FLAGS, &control);
  1129. if (!(control & PCI_MSI_FLAGS_ENABLE)) {
  1130. ipath_cdbg(VERBOSE, "MSI control at off %x was %x, "
  1131. "setting MSI enable (%x)\n", pos + PCI_MSI_FLAGS,
  1132. control, control | PCI_MSI_FLAGS_ENABLE);
  1133. control |= PCI_MSI_FLAGS_ENABLE;
  1134. pci_write_config_word(dd->pcidev, pos + PCI_MSI_FLAGS,
  1135. control);
  1136. }
  1137. /* now rewrite the data (vector) info */
  1138. pci_write_config_word(dd->pcidev, pos +
  1139. ((control & PCI_MSI_FLAGS_64BIT) ? 12 : 8),
  1140. dd->ipath_msi_data);
  1141. /* we restore the cachelinesize also, although it doesn't really
  1142. * matter */
  1143. pci_write_config_byte(dd->pcidev, PCI_CACHE_LINE_SIZE,
  1144. dd->ipath_pci_cacheline);
  1145. /* and now set the pci master bit again */
  1146. pci_set_master(dd->pcidev);
  1147. ret = 1;
  1148. bail:
  1149. return ret;
  1150. }
  1151. /* This routine sleeps, so it can only be called from user context, not
  1152. * from interrupt context. If we need interrupt context, we can split
  1153. * it into two routines.
  1154. */
  1155. static int ipath_setup_pe_reset(struct ipath_devdata *dd)
  1156. {
  1157. u64 val;
  1158. int i;
  1159. int ret;
  1160. u16 cmdval;
  1161. pci_read_config_word(dd->pcidev, PCI_COMMAND, &cmdval);
  1162. /* Use ERROR so it shows up in logs, etc. */
  1163. ipath_dev_err(dd, "Resetting InfiniPath unit %u\n", dd->ipath_unit);
  1164. /* keep chip from being accessed in a few places */
  1165. dd->ipath_flags &= ~(IPATH_INITTED|IPATH_PRESENT);
  1166. val = dd->ipath_control | INFINIPATH_C_RESET;
  1167. ipath_write_kreg(dd, dd->ipath_kregs->kr_control, val);
  1168. mb();
  1169. for (i = 1; i <= 5; i++) {
  1170. int r;
  1171. /* allow MBIST, etc. to complete; longer on each retry.
  1172. * We sometimes get machine checks from bus timeout if no
  1173. * response, so for now, make it *really* long.
  1174. */
  1175. msleep(1000 + (1 + i) * 2000);
  1176. if ((r =
  1177. pci_write_config_dword(dd->pcidev, PCI_BASE_ADDRESS_0,
  1178. dd->ipath_pcibar0)))
  1179. ipath_dev_err(dd, "rewrite of BAR0 failed: %d\n",
  1180. r);
  1181. if ((r =
  1182. pci_write_config_dword(dd->pcidev, PCI_BASE_ADDRESS_1,
  1183. dd->ipath_pcibar1)))
  1184. ipath_dev_err(dd, "rewrite of BAR1 failed: %d\n",
  1185. r);
  1186. /* now re-enable memory access */
  1187. pci_write_config_word(dd->pcidev, PCI_COMMAND, cmdval);
  1188. if ((r = pci_enable_device(dd->pcidev)))
  1189. ipath_dev_err(dd, "pci_enable_device failed after "
  1190. "reset: %d\n", r);
  1191. /*
  1192. * whether it fully enabled or not, mark as present,
  1193. * again (but not INITTED)
  1194. */
  1195. dd->ipath_flags |= IPATH_PRESENT;
  1196. val = ipath_read_kreg64(dd, dd->ipath_kregs->kr_revision);
  1197. if (val == dd->ipath_revision) {
  1198. ipath_cdbg(VERBOSE, "Got matching revision "
  1199. "register %llx on try %d\n",
  1200. (unsigned long long) val, i);
  1201. ret = ipath_reinit_msi(dd);
  1202. goto bail;
  1203. }
  1204. /* Probably getting -1 back */
  1205. ipath_dbg("Didn't get expected revision register, "
  1206. "got %llx, try %d\n", (unsigned long long) val,
  1207. i + 1);
  1208. }
  1209. ret = 0; /* failed */
  1210. bail:
  1211. if (ret)
  1212. ipath_6120_pcie_params(dd);
  1213. return ret;
  1214. }
  1215. /**
  1216. * ipath_pe_put_tid - write a TID in chip
  1217. * @dd: the infinipath device
  1218. * @tidptr: pointer to the expected TID (in chip) to udpate
  1219. * @tidtype: RCVHQ_RCV_TYPE_EAGER (1) for eager, RCVHQ_RCV_TYPE_EXPECTED (0) for expected
  1220. * @pa: physical address of in memory buffer; ipath_tidinvalid if freeing
  1221. *
  1222. * This exists as a separate routine to allow for special locking etc.
  1223. * It's used for both the full cleanup on exit, as well as the normal
  1224. * setup and teardown.
  1225. */
  1226. static void ipath_pe_put_tid(struct ipath_devdata *dd, u64 __iomem *tidptr,
  1227. u32 type, unsigned long pa)
  1228. {
  1229. u32 __iomem *tidp32 = (u32 __iomem *)tidptr;
  1230. unsigned long flags = 0; /* keep gcc quiet */
  1231. int tidx;
  1232. spinlock_t *tidlockp;
  1233. if (!dd->ipath_kregbase)
  1234. return;
  1235. if (pa != dd->ipath_tidinvalid) {
  1236. if (pa & ((1U << 11) - 1)) {
  1237. dev_info(&dd->pcidev->dev, "BUG: physaddr %lx "
  1238. "not 2KB aligned!\n", pa);
  1239. return;
  1240. }
  1241. pa >>= 11;
  1242. /* paranoia check */
  1243. if (pa & ~INFINIPATH_RT_ADDR_MASK)
  1244. ipath_dev_err(dd,
  1245. "BUG: Physical page address 0x%lx "
  1246. "has bits set in 31-29\n", pa);
  1247. if (type == RCVHQ_RCV_TYPE_EAGER)
  1248. pa |= dd->ipath_tidtemplate;
  1249. else /* for now, always full 4KB page */
  1250. pa |= 2 << 29;
  1251. }
  1252. /*
  1253. * Workaround chip bug 9437 by writing the scratch register
  1254. * before and after the TID, and with an io write barrier.
  1255. * We use a spinlock around the writes, so they can't intermix
  1256. * with other TID (eager or expected) writes (the chip bug
  1257. * is triggered by back to back TID writes). Unfortunately, this
  1258. * call can be done from interrupt level for the port 0 eager TIDs,
  1259. * so we have to use irqsave locks.
  1260. */
  1261. /*
  1262. * Assumes tidptr always > ipath_egrtidbase
  1263. * if type == RCVHQ_RCV_TYPE_EAGER.
  1264. */
  1265. tidx = tidptr - dd->ipath_egrtidbase;
  1266. tidlockp = (type == RCVHQ_RCV_TYPE_EAGER && tidx < dd->ipath_rcvegrcnt)
  1267. ? &dd->ipath_kernel_tid_lock : &dd->ipath_user_tid_lock;
  1268. spin_lock_irqsave(tidlockp, flags);
  1269. ipath_write_kreg(dd, dd->ipath_kregs->kr_scratch, 0xfeeddeaf);
  1270. writel(pa, tidp32);
  1271. ipath_write_kreg(dd, dd->ipath_kregs->kr_scratch, 0xdeadbeef);
  1272. mmiowb();
  1273. spin_unlock_irqrestore(tidlockp, flags);
  1274. }
  1275. /**
  1276. * ipath_pe_put_tid_2 - write a TID in chip, Revision 2 or higher
  1277. * @dd: the infinipath device
  1278. * @tidptr: pointer to the expected TID (in chip) to udpate
  1279. * @tidtype: RCVHQ_RCV_TYPE_EAGER (1) for eager, RCVHQ_RCV_TYPE_EXPECTED (0) for expected
  1280. * @pa: physical address of in memory buffer; ipath_tidinvalid if freeing
  1281. *
  1282. * This exists as a separate routine to allow for selection of the
  1283. * appropriate "flavor". The static calls in cleanup just use the
  1284. * revision-agnostic form, as they are not performance critical.
  1285. */
  1286. static void ipath_pe_put_tid_2(struct ipath_devdata *dd, u64 __iomem *tidptr,
  1287. u32 type, unsigned long pa)
  1288. {
  1289. u32 __iomem *tidp32 = (u32 __iomem *)tidptr;
  1290. u32 tidx;
  1291. if (!dd->ipath_kregbase)
  1292. return;
  1293. if (pa != dd->ipath_tidinvalid) {
  1294. if (pa & ((1U << 11) - 1)) {
  1295. dev_info(&dd->pcidev->dev, "BUG: physaddr %lx "
  1296. "not 2KB aligned!\n", pa);
  1297. return;
  1298. }
  1299. pa >>= 11;
  1300. /* paranoia check */
  1301. if (pa & ~INFINIPATH_RT_ADDR_MASK)
  1302. ipath_dev_err(dd,
  1303. "BUG: Physical page address 0x%lx "
  1304. "has bits set in 31-29\n", pa);
  1305. if (type == RCVHQ_RCV_TYPE_EAGER)
  1306. pa |= dd->ipath_tidtemplate;
  1307. else /* for now, always full 4KB page */
  1308. pa |= 2 << 29;
  1309. }
  1310. tidx = tidptr - dd->ipath_egrtidbase;
  1311. writel(pa, tidp32);
  1312. mmiowb();
  1313. }
  1314. /**
  1315. * ipath_pe_clear_tid - clear all TID entries for a port, expected and eager
  1316. * @dd: the infinipath device
  1317. * @port: the port
  1318. *
  1319. * clear all TID entries for a port, expected and eager.
  1320. * Used from ipath_close(). On this chip, TIDs are only 32 bits,
  1321. * not 64, but they are still on 64 bit boundaries, so tidbase
  1322. * is declared as u64 * for the pointer math, even though we write 32 bits
  1323. */
  1324. static void ipath_pe_clear_tids(struct ipath_devdata *dd, unsigned port)
  1325. {
  1326. u64 __iomem *tidbase;
  1327. unsigned long tidinv;
  1328. int i;
  1329. if (!dd->ipath_kregbase)
  1330. return;
  1331. ipath_cdbg(VERBOSE, "Invalidate TIDs for port %u\n", port);
  1332. tidinv = dd->ipath_tidinvalid;
  1333. tidbase = (u64 __iomem *)
  1334. ((char __iomem *)(dd->ipath_kregbase) +
  1335. dd->ipath_rcvtidbase +
  1336. port * dd->ipath_rcvtidcnt * sizeof(*tidbase));
  1337. for (i = 0; i < dd->ipath_rcvtidcnt; i++)
  1338. dd->ipath_f_put_tid(dd, &tidbase[i], RCVHQ_RCV_TYPE_EXPECTED,
  1339. tidinv);
  1340. tidbase = (u64 __iomem *)
  1341. ((char __iomem *)(dd->ipath_kregbase) +
  1342. dd->ipath_rcvegrbase +
  1343. port * dd->ipath_rcvegrcnt * sizeof(*tidbase));
  1344. for (i = 0; i < dd->ipath_rcvegrcnt; i++)
  1345. dd->ipath_f_put_tid(dd, &tidbase[i], RCVHQ_RCV_TYPE_EAGER,
  1346. tidinv);
  1347. }
  1348. /**
  1349. * ipath_pe_tidtemplate - setup constants for TID updates
  1350. * @dd: the infinipath device
  1351. *
  1352. * We setup stuff that we use a lot, to avoid calculating each time
  1353. */
  1354. static void ipath_pe_tidtemplate(struct ipath_devdata *dd)
  1355. {
  1356. u32 egrsize = dd->ipath_rcvegrbufsize;
  1357. /* For now, we always allocate 4KB buffers (at init) so we can
  1358. * receive max size packets. We may want a module parameter to
  1359. * specify 2KB or 4KB and/or make be per port instead of per device
  1360. * for those who want to reduce memory footprint. Note that the
  1361. * ipath_rcvhdrentsize size must be large enough to hold the largest
  1362. * IB header (currently 96 bytes) that we expect to handle (plus of
  1363. * course the 2 dwords of RHF).
  1364. */
  1365. if (egrsize == 2048)
  1366. dd->ipath_tidtemplate = 1U << 29;
  1367. else if (egrsize == 4096)
  1368. dd->ipath_tidtemplate = 2U << 29;
  1369. else {
  1370. egrsize = 4096;
  1371. dev_info(&dd->pcidev->dev, "BUG: unsupported egrbufsize "
  1372. "%u, using %u\n", dd->ipath_rcvegrbufsize,
  1373. egrsize);
  1374. dd->ipath_tidtemplate = 2U << 29;
  1375. }
  1376. dd->ipath_tidinvalid = 0;
  1377. }
  1378. static int ipath_pe_early_init(struct ipath_devdata *dd)
  1379. {
  1380. dd->ipath_flags |= IPATH_4BYTE_TID;
  1381. if (ipath_unordered_wc())
  1382. dd->ipath_flags |= IPATH_PIO_FLUSH_WC;
  1383. /*
  1384. * For openfabrics, we need to be able to handle an IB header of
  1385. * 24 dwords. HT chip has arbitrary sized receive buffers, so we
  1386. * made them the same size as the PIO buffers. This chip does not
  1387. * handle arbitrary size buffers, so we need the header large enough
  1388. * to handle largest IB header, but still have room for a 2KB MTU
  1389. * standard IB packet.
  1390. */
  1391. dd->ipath_rcvhdrentsize = 24;
  1392. dd->ipath_rcvhdrsize = IPATH_DFLT_RCVHDRSIZE;
  1393. dd->ipath_rhf_offset = 0;
  1394. dd->ipath_egrtidbase = (u64 __iomem *)
  1395. ((char __iomem *) dd->ipath_kregbase + dd->ipath_rcvegrbase);
  1396. dd->ipath_rcvegrbufsize = ipath_mtu4096 ? 4096 : 2048;
  1397. /*
  1398. * the min() check here is currently a nop, but it may not always
  1399. * be, depending on just how we do ipath_rcvegrbufsize
  1400. */
  1401. dd->ipath_ibmaxlen = min(ipath_mtu4096 ? dd->ipath_piosize4k :
  1402. dd->ipath_piosize2k,
  1403. dd->ipath_rcvegrbufsize +
  1404. (dd->ipath_rcvhdrentsize << 2));
  1405. dd->ipath_init_ibmaxlen = dd->ipath_ibmaxlen;
  1406. /*
  1407. * We can request a receive interrupt for 1 or
  1408. * more packets from current offset. For now, we set this
  1409. * up for a single packet.
  1410. */
  1411. dd->ipath_rhdrhead_intr_off = 1ULL<<32;
  1412. ipath_get_eeprom_info(dd);
  1413. return 0;
  1414. }
  1415. int __attribute__((weak)) ipath_unordered_wc(void)
  1416. {
  1417. return 0;
  1418. }
  1419. /**
  1420. * ipath_init_pe_get_base_info - set chip-specific flags for user code
  1421. * @pd: the infinipath port
  1422. * @kbase: ipath_base_info pointer
  1423. *
  1424. * We set the PCIE flag because the lower bandwidth on PCIe vs
  1425. * HyperTransport can affect some user packet algorithms.
  1426. */
  1427. static int ipath_pe_get_base_info(struct ipath_portdata *pd, void *kbase)
  1428. {
  1429. struct ipath_base_info *kinfo = kbase;
  1430. struct ipath_devdata *dd;
  1431. if (ipath_unordered_wc()) {
  1432. kinfo->spi_runtime_flags |= IPATH_RUNTIME_FORCE_WC_ORDER;
  1433. ipath_cdbg(PROC, "Intel processor, forcing WC order\n");
  1434. }
  1435. else
  1436. ipath_cdbg(PROC, "Not Intel processor, WC ordered\n");
  1437. if (pd == NULL)
  1438. goto done;
  1439. dd = pd->port_dd;
  1440. done:
  1441. kinfo->spi_runtime_flags |= IPATH_RUNTIME_PCIE |
  1442. IPATH_RUNTIME_FORCE_PIOAVAIL | IPATH_RUNTIME_PIO_REGSWAPPED;
  1443. return 0;
  1444. }
  1445. static void ipath_pe_free_irq(struct ipath_devdata *dd)
  1446. {
  1447. free_irq(dd->ipath_irq, dd);
  1448. dd->ipath_irq = 0;
  1449. }
  1450. static struct ipath_message_header *
  1451. ipath_pe_get_msgheader(struct ipath_devdata *dd, __le32 *rhf_addr)
  1452. {
  1453. return (struct ipath_message_header *)
  1454. &rhf_addr[sizeof(u64) / sizeof(u32)];
  1455. }
  1456. static void ipath_pe_config_ports(struct ipath_devdata *dd, ushort cfgports)
  1457. {
  1458. dd->ipath_portcnt =
  1459. ipath_read_kreg32(dd, dd->ipath_kregs->kr_portcnt);
  1460. dd->ipath_p0_rcvegrcnt =
  1461. ipath_read_kreg32(dd, dd->ipath_kregs->kr_rcvegrcnt);
  1462. }
  1463. static void ipath_pe_read_counters(struct ipath_devdata *dd,
  1464. struct infinipath_counters *cntrs)
  1465. {
  1466. cntrs->LBIntCnt =
  1467. ipath_snap_cntr(dd, IPATH_CREG_OFFSET(LBIntCnt));
  1468. cntrs->LBFlowStallCnt =
  1469. ipath_snap_cntr(dd, IPATH_CREG_OFFSET(LBFlowStallCnt));
  1470. cntrs->TxSDmaDescCnt = 0;
  1471. cntrs->TxUnsupVLErrCnt =
  1472. ipath_snap_cntr(dd, IPATH_CREG_OFFSET(TxUnsupVLErrCnt));
  1473. cntrs->TxDataPktCnt =
  1474. ipath_snap_cntr(dd, IPATH_CREG_OFFSET(TxDataPktCnt));
  1475. cntrs->TxFlowPktCnt =
  1476. ipath_snap_cntr(dd, IPATH_CREG_OFFSET(TxFlowPktCnt));
  1477. cntrs->TxDwordCnt =
  1478. ipath_snap_cntr(dd, IPATH_CREG_OFFSET(TxDwordCnt));
  1479. cntrs->TxLenErrCnt =
  1480. ipath_snap_cntr(dd, IPATH_CREG_OFFSET(TxLenErrCnt));
  1481. cntrs->TxMaxMinLenErrCnt =
  1482. ipath_snap_cntr(dd, IPATH_CREG_OFFSET(TxMaxMinLenErrCnt));
  1483. cntrs->TxUnderrunCnt =
  1484. ipath_snap_cntr(dd, IPATH_CREG_OFFSET(TxUnderrunCnt));
  1485. cntrs->TxFlowStallCnt =
  1486. ipath_snap_cntr(dd, IPATH_CREG_OFFSET(TxFlowStallCnt));
  1487. cntrs->TxDroppedPktCnt =
  1488. ipath_snap_cntr(dd, IPATH_CREG_OFFSET(TxDroppedPktCnt));
  1489. cntrs->RxDroppedPktCnt =
  1490. ipath_snap_cntr(dd, IPATH_CREG_OFFSET(RxDroppedPktCnt));
  1491. cntrs->RxDataPktCnt =
  1492. ipath_snap_cntr(dd, IPATH_CREG_OFFSET(RxDataPktCnt));
  1493. cntrs->RxFlowPktCnt =
  1494. ipath_snap_cntr(dd, IPATH_CREG_OFFSET(RxFlowPktCnt));
  1495. cntrs->RxDwordCnt =
  1496. ipath_snap_cntr(dd, IPATH_CREG_OFFSET(RxDwordCnt));
  1497. cntrs->RxLenErrCnt =
  1498. ipath_snap_cntr(dd, IPATH_CREG_OFFSET(RxLenErrCnt));
  1499. cntrs->RxMaxMinLenErrCnt =
  1500. ipath_snap_cntr(dd, IPATH_CREG_OFFSET(RxMaxMinLenErrCnt));
  1501. cntrs->RxICRCErrCnt =
  1502. ipath_snap_cntr(dd, IPATH_CREG_OFFSET(RxICRCErrCnt));
  1503. cntrs->RxVCRCErrCnt =
  1504. ipath_snap_cntr(dd, IPATH_CREG_OFFSET(RxVCRCErrCnt));
  1505. cntrs->RxFlowCtrlErrCnt =
  1506. ipath_snap_cntr(dd, IPATH_CREG_OFFSET(RxFlowCtrlErrCnt));
  1507. cntrs->RxBadFormatCnt =
  1508. ipath_snap_cntr(dd, IPATH_CREG_OFFSET(RxBadFormatCnt));
  1509. cntrs->RxLinkProblemCnt =
  1510. ipath_snap_cntr(dd, IPATH_CREG_OFFSET(RxLinkProblemCnt));
  1511. cntrs->RxEBPCnt =
  1512. ipath_snap_cntr(dd, IPATH_CREG_OFFSET(RxEBPCnt));
  1513. cntrs->RxLPCRCErrCnt =
  1514. ipath_snap_cntr(dd, IPATH_CREG_OFFSET(RxLPCRCErrCnt));
  1515. cntrs->RxBufOvflCnt =
  1516. ipath_snap_cntr(dd, IPATH_CREG_OFFSET(RxBufOvflCnt));
  1517. cntrs->RxTIDFullErrCnt =
  1518. ipath_snap_cntr(dd, IPATH_CREG_OFFSET(RxTIDFullErrCnt));
  1519. cntrs->RxTIDValidErrCnt =
  1520. ipath_snap_cntr(dd, IPATH_CREG_OFFSET(RxTIDValidErrCnt));
  1521. cntrs->RxPKeyMismatchCnt =
  1522. ipath_snap_cntr(dd, IPATH_CREG_OFFSET(RxPKeyMismatchCnt));
  1523. cntrs->RxP0HdrEgrOvflCnt =
  1524. ipath_snap_cntr(dd, IPATH_CREG_OFFSET(RxP0HdrEgrOvflCnt));
  1525. cntrs->RxP1HdrEgrOvflCnt =
  1526. ipath_snap_cntr(dd, IPATH_CREG_OFFSET(RxP1HdrEgrOvflCnt));
  1527. cntrs->RxP2HdrEgrOvflCnt =
  1528. ipath_snap_cntr(dd, IPATH_CREG_OFFSET(RxP2HdrEgrOvflCnt));
  1529. cntrs->RxP3HdrEgrOvflCnt =
  1530. ipath_snap_cntr(dd, IPATH_CREG_OFFSET(RxP3HdrEgrOvflCnt));
  1531. cntrs->RxP4HdrEgrOvflCnt =
  1532. ipath_snap_cntr(dd, IPATH_CREG_OFFSET(RxP4HdrEgrOvflCnt));
  1533. cntrs->RxP5HdrEgrOvflCnt = 0;
  1534. cntrs->RxP6HdrEgrOvflCnt = 0;
  1535. cntrs->RxP7HdrEgrOvflCnt = 0;
  1536. cntrs->RxP8HdrEgrOvflCnt = 0;
  1537. cntrs->RxP9HdrEgrOvflCnt = 0;
  1538. cntrs->RxP10HdrEgrOvflCnt = 0;
  1539. cntrs->RxP11HdrEgrOvflCnt = 0;
  1540. cntrs->RxP12HdrEgrOvflCnt = 0;
  1541. cntrs->RxP13HdrEgrOvflCnt = 0;
  1542. cntrs->RxP14HdrEgrOvflCnt = 0;
  1543. cntrs->RxP15HdrEgrOvflCnt = 0;
  1544. cntrs->RxP16HdrEgrOvflCnt = 0;
  1545. cntrs->IBStatusChangeCnt =
  1546. ipath_snap_cntr(dd, IPATH_CREG_OFFSET(IBStatusChangeCnt));
  1547. cntrs->IBLinkErrRecoveryCnt =
  1548. ipath_snap_cntr(dd, IPATH_CREG_OFFSET(IBLinkErrRecoveryCnt));
  1549. cntrs->IBLinkDownedCnt =
  1550. ipath_snap_cntr(dd, IPATH_CREG_OFFSET(IBLinkDownedCnt));
  1551. cntrs->IBSymbolErrCnt =
  1552. ipath_snap_cntr(dd, IPATH_CREG_OFFSET(IBSymbolErrCnt));
  1553. cntrs->RxVL15DroppedPktCnt = 0;
  1554. cntrs->RxOtherLocalPhyErrCnt = 0;
  1555. cntrs->PcieRetryBufDiagQwordCnt = 0;
  1556. cntrs->ExcessBufferOvflCnt = dd->ipath_overrun_thresh_errs;
  1557. cntrs->LocalLinkIntegrityErrCnt = dd->ipath_lli_errs;
  1558. cntrs->RxVlErrCnt = 0;
  1559. cntrs->RxDlidFltrCnt = 0;
  1560. }
  1561. /* no interrupt fallback for these chips */
  1562. static int ipath_pe_nointr_fallback(struct ipath_devdata *dd)
  1563. {
  1564. return 0;
  1565. }
  1566. /*
  1567. * reset the XGXS (between serdes and IBC). Slightly less intrusive
  1568. * than resetting the IBC or external link state, and useful in some
  1569. * cases to cause some retraining. To do this right, we reset IBC
  1570. * as well.
  1571. */
  1572. static void ipath_pe_xgxs_reset(struct ipath_devdata *dd)
  1573. {
  1574. u64 val, prev_val;
  1575. prev_val = ipath_read_kreg64(dd, dd->ipath_kregs->kr_xgxsconfig);
  1576. val = prev_val | INFINIPATH_XGXS_RESET;
  1577. prev_val &= ~INFINIPATH_XGXS_RESET; /* be sure */
  1578. ipath_write_kreg(dd, dd->ipath_kregs->kr_control,
  1579. dd->ipath_control & ~INFINIPATH_C_LINKENABLE);
  1580. ipath_write_kreg(dd, dd->ipath_kregs->kr_xgxsconfig, val);
  1581. ipath_read_kreg32(dd, dd->ipath_kregs->kr_scratch);
  1582. ipath_write_kreg(dd, dd->ipath_kregs->kr_xgxsconfig, prev_val);
  1583. ipath_write_kreg(dd, dd->ipath_kregs->kr_control,
  1584. dd->ipath_control);
  1585. }
  1586. static int ipath_pe_get_ib_cfg(struct ipath_devdata *dd, int which)
  1587. {
  1588. int ret;
  1589. switch (which) {
  1590. case IPATH_IB_CFG_LWID:
  1591. ret = dd->ipath_link_width_active;
  1592. break;
  1593. case IPATH_IB_CFG_SPD:
  1594. ret = dd->ipath_link_speed_active;
  1595. break;
  1596. case IPATH_IB_CFG_LWID_ENB:
  1597. ret = dd->ipath_link_width_enabled;
  1598. break;
  1599. case IPATH_IB_CFG_SPD_ENB:
  1600. ret = dd->ipath_link_speed_enabled;
  1601. break;
  1602. default:
  1603. ret = -ENOTSUPP;
  1604. break;
  1605. }
  1606. return ret;
  1607. }
  1608. /* we assume range checking is already done, if needed */
  1609. static int ipath_pe_set_ib_cfg(struct ipath_devdata *dd, int which, u32 val)
  1610. {
  1611. int ret = 0;
  1612. if (which == IPATH_IB_CFG_LWID_ENB)
  1613. dd->ipath_link_width_enabled = val;
  1614. else if (which == IPATH_IB_CFG_SPD_ENB)
  1615. dd->ipath_link_speed_enabled = val;
  1616. else
  1617. ret = -ENOTSUPP;
  1618. return ret;
  1619. }
  1620. static void ipath_pe_config_jint(struct ipath_devdata *dd, u16 a, u16 b)
  1621. {
  1622. }
  1623. static int ipath_pe_ib_updown(struct ipath_devdata *dd, int ibup, u64 ibcs)
  1624. {
  1625. if (ibup) {
  1626. if (dd->ibdeltainprog) {
  1627. dd->ibdeltainprog = 0;
  1628. dd->ibsymdelta +=
  1629. ipath_read_creg32(dd,
  1630. dd->ipath_cregs->cr_ibsymbolerrcnt) -
  1631. dd->ibsymsnap;
  1632. dd->iblnkerrdelta +=
  1633. ipath_read_creg32(dd,
  1634. dd->ipath_cregs->cr_iblinkerrrecovcnt) -
  1635. dd->iblnkerrsnap;
  1636. }
  1637. } else {
  1638. dd->ipath_lli_counter = 0;
  1639. if (!dd->ibdeltainprog) {
  1640. dd->ibdeltainprog = 1;
  1641. dd->ibsymsnap =
  1642. ipath_read_creg32(dd,
  1643. dd->ipath_cregs->cr_ibsymbolerrcnt);
  1644. dd->iblnkerrsnap =
  1645. ipath_read_creg32(dd,
  1646. dd->ipath_cregs->cr_iblinkerrrecovcnt);
  1647. }
  1648. }
  1649. ipath_setup_pe_setextled(dd, ipath_ib_linkstate(dd, ibcs),
  1650. ipath_ib_linktrstate(dd, ibcs));
  1651. return 0;
  1652. }
  1653. /**
  1654. * ipath_init_iba6120_funcs - set up the chip-specific function pointers
  1655. * @dd: the infinipath device
  1656. *
  1657. * This is global, and is called directly at init to set up the
  1658. * chip-specific function pointers for later use.
  1659. */
  1660. void ipath_init_iba6120_funcs(struct ipath_devdata *dd)
  1661. {
  1662. dd->ipath_f_intrsetup = ipath_pe_intconfig;
  1663. dd->ipath_f_bus = ipath_setup_pe_config;
  1664. dd->ipath_f_reset = ipath_setup_pe_reset;
  1665. dd->ipath_f_get_boardname = ipath_pe_boardname;
  1666. dd->ipath_f_init_hwerrors = ipath_pe_init_hwerrors;
  1667. dd->ipath_f_early_init = ipath_pe_early_init;
  1668. dd->ipath_f_handle_hwerrors = ipath_pe_handle_hwerrors;
  1669. dd->ipath_f_quiet_serdes = ipath_pe_quiet_serdes;
  1670. dd->ipath_f_bringup_serdes = ipath_pe_bringup_serdes;
  1671. dd->ipath_f_clear_tids = ipath_pe_clear_tids;
  1672. /*
  1673. * _f_put_tid may get changed after we read the chip revision,
  1674. * but we start with the safe version for all revs
  1675. */
  1676. dd->ipath_f_put_tid = ipath_pe_put_tid;
  1677. dd->ipath_f_cleanup = ipath_setup_pe_cleanup;
  1678. dd->ipath_f_setextled = ipath_setup_pe_setextled;
  1679. dd->ipath_f_get_base_info = ipath_pe_get_base_info;
  1680. dd->ipath_f_free_irq = ipath_pe_free_irq;
  1681. dd->ipath_f_tidtemplate = ipath_pe_tidtemplate;
  1682. dd->ipath_f_intr_fallback = ipath_pe_nointr_fallback;
  1683. dd->ipath_f_xgxs_reset = ipath_pe_xgxs_reset;
  1684. dd->ipath_f_get_msgheader = ipath_pe_get_msgheader;
  1685. dd->ipath_f_config_ports = ipath_pe_config_ports;
  1686. dd->ipath_f_read_counters = ipath_pe_read_counters;
  1687. dd->ipath_f_get_ib_cfg = ipath_pe_get_ib_cfg;
  1688. dd->ipath_f_set_ib_cfg = ipath_pe_set_ib_cfg;
  1689. dd->ipath_f_config_jint = ipath_pe_config_jint;
  1690. dd->ipath_f_ib_updown = ipath_pe_ib_updown;
  1691. /* initialize chip-specific variables */
  1692. ipath_init_pe_variables(dd);
  1693. }