ipath_iba7220.c 86 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630
  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 7220 chip (except that specific to the SerDes)
  36. */
  37. #include <linux/interrupt.h>
  38. #include <linux/pci.h>
  39. #include <linux/delay.h>
  40. #include <linux/io.h>
  41. #include <rdma/ib_verbs.h>
  42. #include "ipath_kernel.h"
  43. #include "ipath_registers.h"
  44. #include "ipath_7220.h"
  45. static void ipath_setup_7220_setextled(struct ipath_devdata *, u64, u64);
  46. static unsigned ipath_compat_ddr_negotiate = 1;
  47. module_param_named(compat_ddr_negotiate, ipath_compat_ddr_negotiate, uint,
  48. S_IWUSR | S_IRUGO);
  49. MODULE_PARM_DESC(compat_ddr_negotiate,
  50. "Attempt pre-IBTA 1.2 DDR speed negotiation");
  51. static unsigned ipath_sdma_fetch_arb = 1;
  52. module_param_named(fetch_arb, ipath_sdma_fetch_arb, uint, S_IRUGO);
  53. MODULE_PARM_DESC(fetch_arb, "IBA7220: change SDMA descriptor arbitration");
  54. /*
  55. * This file contains almost all the chip-specific register information and
  56. * access functions for the QLogic InfiniPath 7220 PCI-Express chip, with the
  57. * exception of SerDes support, which in in ipath_sd7220.c.
  58. *
  59. * This lists the InfiniPath registers, in the actual chip layout.
  60. * This structure should never be directly accessed.
  61. */
  62. struct _infinipath_do_not_use_kernel_regs {
  63. unsigned long long Revision;
  64. unsigned long long Control;
  65. unsigned long long PageAlign;
  66. unsigned long long PortCnt;
  67. unsigned long long DebugPortSelect;
  68. unsigned long long DebugSigsIntSel; /* was Reserved0;*/
  69. unsigned long long SendRegBase;
  70. unsigned long long UserRegBase;
  71. unsigned long long CounterRegBase;
  72. unsigned long long Scratch;
  73. unsigned long long EEPROMAddrCmd; /* was Reserved1; */
  74. unsigned long long EEPROMData; /* was Reserved2; */
  75. unsigned long long IntBlocked;
  76. unsigned long long IntMask;
  77. unsigned long long IntStatus;
  78. unsigned long long IntClear;
  79. unsigned long long ErrorMask;
  80. unsigned long long ErrorStatus;
  81. unsigned long long ErrorClear;
  82. unsigned long long HwErrMask;
  83. unsigned long long HwErrStatus;
  84. unsigned long long HwErrClear;
  85. unsigned long long HwDiagCtrl;
  86. unsigned long long MDIO;
  87. unsigned long long IBCStatus;
  88. unsigned long long IBCCtrl;
  89. unsigned long long ExtStatus;
  90. unsigned long long ExtCtrl;
  91. unsigned long long GPIOOut;
  92. unsigned long long GPIOMask;
  93. unsigned long long GPIOStatus;
  94. unsigned long long GPIOClear;
  95. unsigned long long RcvCtrl;
  96. unsigned long long RcvBTHQP;
  97. unsigned long long RcvHdrSize;
  98. unsigned long long RcvHdrCnt;
  99. unsigned long long RcvHdrEntSize;
  100. unsigned long long RcvTIDBase;
  101. unsigned long long RcvTIDCnt;
  102. unsigned long long RcvEgrBase;
  103. unsigned long long RcvEgrCnt;
  104. unsigned long long RcvBufBase;
  105. unsigned long long RcvBufSize;
  106. unsigned long long RxIntMemBase;
  107. unsigned long long RxIntMemSize;
  108. unsigned long long RcvPartitionKey;
  109. unsigned long long RcvQPMulticastPort;
  110. unsigned long long RcvPktLEDCnt;
  111. unsigned long long IBCDDRCtrl;
  112. unsigned long long HRTBT_GUID;
  113. unsigned long long IB_SDTEST_IF_TX;
  114. unsigned long long IB_SDTEST_IF_RX;
  115. unsigned long long IBCDDRCtrl2;
  116. unsigned long long IBCDDRStatus;
  117. unsigned long long JIntReload;
  118. unsigned long long IBNCModeCtrl;
  119. unsigned long long SendCtrl;
  120. unsigned long long SendBufBase;
  121. unsigned long long SendBufSize;
  122. unsigned long long SendBufCnt;
  123. unsigned long long SendAvailAddr;
  124. unsigned long long TxIntMemBase;
  125. unsigned long long TxIntMemSize;
  126. unsigned long long SendDmaBase;
  127. unsigned long long SendDmaLenGen;
  128. unsigned long long SendDmaTail;
  129. unsigned long long SendDmaHead;
  130. unsigned long long SendDmaHeadAddr;
  131. unsigned long long SendDmaBufMask0;
  132. unsigned long long SendDmaBufMask1;
  133. unsigned long long SendDmaBufMask2;
  134. unsigned long long SendDmaStatus;
  135. unsigned long long SendBufferError;
  136. unsigned long long SendBufferErrorCONT1;
  137. unsigned long long SendBufErr2; /* was Reserved6SBE[0/6] */
  138. unsigned long long Reserved6L[2];
  139. unsigned long long AvailUpdCount;
  140. unsigned long long RcvHdrAddr0;
  141. unsigned long long RcvHdrAddrs[16]; /* Why enumerate? */
  142. unsigned long long Reserved7hdtl; /* Align next to 300 */
  143. unsigned long long RcvHdrTailAddr0; /* 300, like others */
  144. unsigned long long RcvHdrTailAddrs[16];
  145. unsigned long long Reserved9SW[7]; /* was [8]; we have 17 ports */
  146. unsigned long long IbsdEpbAccCtl; /* IB Serdes EPB access control */
  147. unsigned long long IbsdEpbTransReg; /* IB Serdes EPB Transaction */
  148. unsigned long long Reserved10sds; /* was SerdesStatus on */
  149. unsigned long long XGXSConfig;
  150. unsigned long long IBSerDesCtrl; /* Was IBPLLCfg on Monty */
  151. unsigned long long EEPCtlStat; /* for "boot" EEPROM/FLASH */
  152. unsigned long long EEPAddrCmd;
  153. unsigned long long EEPData;
  154. unsigned long long PcieEpbAccCtl;
  155. unsigned long long PcieEpbTransCtl;
  156. unsigned long long EfuseCtl; /* E-Fuse control */
  157. unsigned long long EfuseData[4];
  158. unsigned long long ProcMon;
  159. /* this chip moves following two from previous 200, 208 */
  160. unsigned long long PCIeRBufTestReg0;
  161. unsigned long long PCIeRBufTestReg1;
  162. /* added for this chip */
  163. unsigned long long PCIeRBufTestReg2;
  164. unsigned long long PCIeRBufTestReg3;
  165. /* added for this chip, debug only */
  166. unsigned long long SPC_JTAG_ACCESS_REG;
  167. unsigned long long LAControlReg;
  168. unsigned long long GPIODebugSelReg;
  169. unsigned long long DebugPortValueReg;
  170. /* added for this chip, DMA */
  171. unsigned long long SendDmaBufUsed[3];
  172. unsigned long long SendDmaReqTagUsed;
  173. /*
  174. * added for this chip, EFUSE: note that these program 64-bit
  175. * words 2 and 3 */
  176. unsigned long long efuse_pgm_data[2];
  177. unsigned long long Reserved11LAalign[10]; /* Skip 4B0..4F8 */
  178. /* we have 30 regs for DDS and RXEQ in IB SERDES */
  179. unsigned long long SerDesDDSRXEQ[30];
  180. unsigned long long Reserved12LAalign[2]; /* Skip 5F0, 5F8 */
  181. /* added for LA debug support */
  182. unsigned long long LAMemory[32];
  183. };
  184. struct _infinipath_do_not_use_counters {
  185. __u64 LBIntCnt;
  186. __u64 LBFlowStallCnt;
  187. __u64 TxSDmaDescCnt; /* was Reserved1 */
  188. __u64 TxUnsupVLErrCnt;
  189. __u64 TxDataPktCnt;
  190. __u64 TxFlowPktCnt;
  191. __u64 TxDwordCnt;
  192. __u64 TxLenErrCnt;
  193. __u64 TxMaxMinLenErrCnt;
  194. __u64 TxUnderrunCnt;
  195. __u64 TxFlowStallCnt;
  196. __u64 TxDroppedPktCnt;
  197. __u64 RxDroppedPktCnt;
  198. __u64 RxDataPktCnt;
  199. __u64 RxFlowPktCnt;
  200. __u64 RxDwordCnt;
  201. __u64 RxLenErrCnt;
  202. __u64 RxMaxMinLenErrCnt;
  203. __u64 RxICRCErrCnt;
  204. __u64 RxVCRCErrCnt;
  205. __u64 RxFlowCtrlErrCnt;
  206. __u64 RxBadFormatCnt;
  207. __u64 RxLinkProblemCnt;
  208. __u64 RxEBPCnt;
  209. __u64 RxLPCRCErrCnt;
  210. __u64 RxBufOvflCnt;
  211. __u64 RxTIDFullErrCnt;
  212. __u64 RxTIDValidErrCnt;
  213. __u64 RxPKeyMismatchCnt;
  214. __u64 RxP0HdrEgrOvflCnt;
  215. __u64 RxP1HdrEgrOvflCnt;
  216. __u64 RxP2HdrEgrOvflCnt;
  217. __u64 RxP3HdrEgrOvflCnt;
  218. __u64 RxP4HdrEgrOvflCnt;
  219. __u64 RxP5HdrEgrOvflCnt;
  220. __u64 RxP6HdrEgrOvflCnt;
  221. __u64 RxP7HdrEgrOvflCnt;
  222. __u64 RxP8HdrEgrOvflCnt;
  223. __u64 RxP9HdrEgrOvflCnt; /* was Reserved6 */
  224. __u64 RxP10HdrEgrOvflCnt; /* was Reserved7 */
  225. __u64 RxP11HdrEgrOvflCnt; /* new for IBA7220 */
  226. __u64 RxP12HdrEgrOvflCnt; /* new for IBA7220 */
  227. __u64 RxP13HdrEgrOvflCnt; /* new for IBA7220 */
  228. __u64 RxP14HdrEgrOvflCnt; /* new for IBA7220 */
  229. __u64 RxP15HdrEgrOvflCnt; /* new for IBA7220 */
  230. __u64 RxP16HdrEgrOvflCnt; /* new for IBA7220 */
  231. __u64 IBStatusChangeCnt;
  232. __u64 IBLinkErrRecoveryCnt;
  233. __u64 IBLinkDownedCnt;
  234. __u64 IBSymbolErrCnt;
  235. /* The following are new for IBA7220 */
  236. __u64 RxVL15DroppedPktCnt;
  237. __u64 RxOtherLocalPhyErrCnt;
  238. __u64 PcieRetryBufDiagQwordCnt;
  239. __u64 ExcessBufferOvflCnt;
  240. __u64 LocalLinkIntegrityErrCnt;
  241. __u64 RxVlErrCnt;
  242. __u64 RxDlidFltrCnt;
  243. __u64 Reserved8[7];
  244. __u64 PSStat;
  245. __u64 PSStart;
  246. __u64 PSInterval;
  247. __u64 PSRcvDataCount;
  248. __u64 PSRcvPktsCount;
  249. __u64 PSXmitDataCount;
  250. __u64 PSXmitPktsCount;
  251. __u64 PSXmitWaitCount;
  252. };
  253. #define IPATH_KREG_OFFSET(field) (offsetof( \
  254. struct _infinipath_do_not_use_kernel_regs, field) / sizeof(u64))
  255. #define IPATH_CREG_OFFSET(field) (offsetof( \
  256. struct _infinipath_do_not_use_counters, field) / sizeof(u64))
  257. static const struct ipath_kregs ipath_7220_kregs = {
  258. .kr_control = IPATH_KREG_OFFSET(Control),
  259. .kr_counterregbase = IPATH_KREG_OFFSET(CounterRegBase),
  260. .kr_debugportselect = IPATH_KREG_OFFSET(DebugPortSelect),
  261. .kr_errorclear = IPATH_KREG_OFFSET(ErrorClear),
  262. .kr_errormask = IPATH_KREG_OFFSET(ErrorMask),
  263. .kr_errorstatus = IPATH_KREG_OFFSET(ErrorStatus),
  264. .kr_extctrl = IPATH_KREG_OFFSET(ExtCtrl),
  265. .kr_extstatus = IPATH_KREG_OFFSET(ExtStatus),
  266. .kr_gpio_clear = IPATH_KREG_OFFSET(GPIOClear),
  267. .kr_gpio_mask = IPATH_KREG_OFFSET(GPIOMask),
  268. .kr_gpio_out = IPATH_KREG_OFFSET(GPIOOut),
  269. .kr_gpio_status = IPATH_KREG_OFFSET(GPIOStatus),
  270. .kr_hwdiagctrl = IPATH_KREG_OFFSET(HwDiagCtrl),
  271. .kr_hwerrclear = IPATH_KREG_OFFSET(HwErrClear),
  272. .kr_hwerrmask = IPATH_KREG_OFFSET(HwErrMask),
  273. .kr_hwerrstatus = IPATH_KREG_OFFSET(HwErrStatus),
  274. .kr_ibcctrl = IPATH_KREG_OFFSET(IBCCtrl),
  275. .kr_ibcstatus = IPATH_KREG_OFFSET(IBCStatus),
  276. .kr_intblocked = IPATH_KREG_OFFSET(IntBlocked),
  277. .kr_intclear = IPATH_KREG_OFFSET(IntClear),
  278. .kr_intmask = IPATH_KREG_OFFSET(IntMask),
  279. .kr_intstatus = IPATH_KREG_OFFSET(IntStatus),
  280. .kr_mdio = IPATH_KREG_OFFSET(MDIO),
  281. .kr_pagealign = IPATH_KREG_OFFSET(PageAlign),
  282. .kr_partitionkey = IPATH_KREG_OFFSET(RcvPartitionKey),
  283. .kr_portcnt = IPATH_KREG_OFFSET(PortCnt),
  284. .kr_rcvbthqp = IPATH_KREG_OFFSET(RcvBTHQP),
  285. .kr_rcvbufbase = IPATH_KREG_OFFSET(RcvBufBase),
  286. .kr_rcvbufsize = IPATH_KREG_OFFSET(RcvBufSize),
  287. .kr_rcvctrl = IPATH_KREG_OFFSET(RcvCtrl),
  288. .kr_rcvegrbase = IPATH_KREG_OFFSET(RcvEgrBase),
  289. .kr_rcvegrcnt = IPATH_KREG_OFFSET(RcvEgrCnt),
  290. .kr_rcvhdrcnt = IPATH_KREG_OFFSET(RcvHdrCnt),
  291. .kr_rcvhdrentsize = IPATH_KREG_OFFSET(RcvHdrEntSize),
  292. .kr_rcvhdrsize = IPATH_KREG_OFFSET(RcvHdrSize),
  293. .kr_rcvintmembase = IPATH_KREG_OFFSET(RxIntMemBase),
  294. .kr_rcvintmemsize = IPATH_KREG_OFFSET(RxIntMemSize),
  295. .kr_rcvtidbase = IPATH_KREG_OFFSET(RcvTIDBase),
  296. .kr_rcvtidcnt = IPATH_KREG_OFFSET(RcvTIDCnt),
  297. .kr_revision = IPATH_KREG_OFFSET(Revision),
  298. .kr_scratch = IPATH_KREG_OFFSET(Scratch),
  299. .kr_sendbuffererror = IPATH_KREG_OFFSET(SendBufferError),
  300. .kr_sendctrl = IPATH_KREG_OFFSET(SendCtrl),
  301. .kr_sendpioavailaddr = IPATH_KREG_OFFSET(SendAvailAddr),
  302. .kr_sendpiobufbase = IPATH_KREG_OFFSET(SendBufBase),
  303. .kr_sendpiobufcnt = IPATH_KREG_OFFSET(SendBufCnt),
  304. .kr_sendpiosize = IPATH_KREG_OFFSET(SendBufSize),
  305. .kr_sendregbase = IPATH_KREG_OFFSET(SendRegBase),
  306. .kr_txintmembase = IPATH_KREG_OFFSET(TxIntMemBase),
  307. .kr_txintmemsize = IPATH_KREG_OFFSET(TxIntMemSize),
  308. .kr_userregbase = IPATH_KREG_OFFSET(UserRegBase),
  309. .kr_xgxsconfig = IPATH_KREG_OFFSET(XGXSConfig),
  310. /* send dma related regs */
  311. .kr_senddmabase = IPATH_KREG_OFFSET(SendDmaBase),
  312. .kr_senddmalengen = IPATH_KREG_OFFSET(SendDmaLenGen),
  313. .kr_senddmatail = IPATH_KREG_OFFSET(SendDmaTail),
  314. .kr_senddmahead = IPATH_KREG_OFFSET(SendDmaHead),
  315. .kr_senddmaheadaddr = IPATH_KREG_OFFSET(SendDmaHeadAddr),
  316. .kr_senddmabufmask0 = IPATH_KREG_OFFSET(SendDmaBufMask0),
  317. .kr_senddmabufmask1 = IPATH_KREG_OFFSET(SendDmaBufMask1),
  318. .kr_senddmabufmask2 = IPATH_KREG_OFFSET(SendDmaBufMask2),
  319. .kr_senddmastatus = IPATH_KREG_OFFSET(SendDmaStatus),
  320. /* SerDes related regs */
  321. .kr_ibserdesctrl = IPATH_KREG_OFFSET(IBSerDesCtrl),
  322. .kr_ib_epbacc = IPATH_KREG_OFFSET(IbsdEpbAccCtl),
  323. .kr_ib_epbtrans = IPATH_KREG_OFFSET(IbsdEpbTransReg),
  324. .kr_pcie_epbacc = IPATH_KREG_OFFSET(PcieEpbAccCtl),
  325. .kr_pcie_epbtrans = IPATH_KREG_OFFSET(PcieEpbTransCtl),
  326. .kr_ib_ddsrxeq = IPATH_KREG_OFFSET(SerDesDDSRXEQ),
  327. /*
  328. * These should not be used directly via ipath_read_kreg64(),
  329. * use them with ipath_read_kreg64_port()
  330. */
  331. .kr_rcvhdraddr = IPATH_KREG_OFFSET(RcvHdrAddr0),
  332. .kr_rcvhdrtailaddr = IPATH_KREG_OFFSET(RcvHdrTailAddr0),
  333. /*
  334. * The rcvpktled register controls one of the debug port signals, so
  335. * a packet activity LED can be connected to it.
  336. */
  337. .kr_rcvpktledcnt = IPATH_KREG_OFFSET(RcvPktLEDCnt),
  338. .kr_pcierbuftestreg0 = IPATH_KREG_OFFSET(PCIeRBufTestReg0),
  339. .kr_pcierbuftestreg1 = IPATH_KREG_OFFSET(PCIeRBufTestReg1),
  340. .kr_hrtbt_guid = IPATH_KREG_OFFSET(HRTBT_GUID),
  341. .kr_ibcddrctrl = IPATH_KREG_OFFSET(IBCDDRCtrl),
  342. .kr_ibcddrstatus = IPATH_KREG_OFFSET(IBCDDRStatus),
  343. .kr_jintreload = IPATH_KREG_OFFSET(JIntReload)
  344. };
  345. static const struct ipath_cregs ipath_7220_cregs = {
  346. .cr_badformatcnt = IPATH_CREG_OFFSET(RxBadFormatCnt),
  347. .cr_erricrccnt = IPATH_CREG_OFFSET(RxICRCErrCnt),
  348. .cr_errlinkcnt = IPATH_CREG_OFFSET(RxLinkProblemCnt),
  349. .cr_errlpcrccnt = IPATH_CREG_OFFSET(RxLPCRCErrCnt),
  350. .cr_errpkey = IPATH_CREG_OFFSET(RxPKeyMismatchCnt),
  351. .cr_errrcvflowctrlcnt = IPATH_CREG_OFFSET(RxFlowCtrlErrCnt),
  352. .cr_err_rlencnt = IPATH_CREG_OFFSET(RxLenErrCnt),
  353. .cr_errslencnt = IPATH_CREG_OFFSET(TxLenErrCnt),
  354. .cr_errtidfull = IPATH_CREG_OFFSET(RxTIDFullErrCnt),
  355. .cr_errtidvalid = IPATH_CREG_OFFSET(RxTIDValidErrCnt),
  356. .cr_errvcrccnt = IPATH_CREG_OFFSET(RxVCRCErrCnt),
  357. .cr_ibstatuschange = IPATH_CREG_OFFSET(IBStatusChangeCnt),
  358. .cr_intcnt = IPATH_CREG_OFFSET(LBIntCnt),
  359. .cr_invalidrlencnt = IPATH_CREG_OFFSET(RxMaxMinLenErrCnt),
  360. .cr_invalidslencnt = IPATH_CREG_OFFSET(TxMaxMinLenErrCnt),
  361. .cr_lbflowstallcnt = IPATH_CREG_OFFSET(LBFlowStallCnt),
  362. .cr_pktrcvcnt = IPATH_CREG_OFFSET(RxDataPktCnt),
  363. .cr_pktrcvflowctrlcnt = IPATH_CREG_OFFSET(RxFlowPktCnt),
  364. .cr_pktsendcnt = IPATH_CREG_OFFSET(TxDataPktCnt),
  365. .cr_pktsendflowcnt = IPATH_CREG_OFFSET(TxFlowPktCnt),
  366. .cr_portovflcnt = IPATH_CREG_OFFSET(RxP0HdrEgrOvflCnt),
  367. .cr_rcvebpcnt = IPATH_CREG_OFFSET(RxEBPCnt),
  368. .cr_rcvovflcnt = IPATH_CREG_OFFSET(RxBufOvflCnt),
  369. .cr_senddropped = IPATH_CREG_OFFSET(TxDroppedPktCnt),
  370. .cr_sendstallcnt = IPATH_CREG_OFFSET(TxFlowStallCnt),
  371. .cr_sendunderruncnt = IPATH_CREG_OFFSET(TxUnderrunCnt),
  372. .cr_wordrcvcnt = IPATH_CREG_OFFSET(RxDwordCnt),
  373. .cr_wordsendcnt = IPATH_CREG_OFFSET(TxDwordCnt),
  374. .cr_unsupvlcnt = IPATH_CREG_OFFSET(TxUnsupVLErrCnt),
  375. .cr_rxdroppktcnt = IPATH_CREG_OFFSET(RxDroppedPktCnt),
  376. .cr_iblinkerrrecovcnt = IPATH_CREG_OFFSET(IBLinkErrRecoveryCnt),
  377. .cr_iblinkdowncnt = IPATH_CREG_OFFSET(IBLinkDownedCnt),
  378. .cr_ibsymbolerrcnt = IPATH_CREG_OFFSET(IBSymbolErrCnt),
  379. .cr_vl15droppedpktcnt = IPATH_CREG_OFFSET(RxVL15DroppedPktCnt),
  380. .cr_rxotherlocalphyerrcnt =
  381. IPATH_CREG_OFFSET(RxOtherLocalPhyErrCnt),
  382. .cr_excessbufferovflcnt = IPATH_CREG_OFFSET(ExcessBufferOvflCnt),
  383. .cr_locallinkintegrityerrcnt =
  384. IPATH_CREG_OFFSET(LocalLinkIntegrityErrCnt),
  385. .cr_rxvlerrcnt = IPATH_CREG_OFFSET(RxVlErrCnt),
  386. .cr_rxdlidfltrcnt = IPATH_CREG_OFFSET(RxDlidFltrCnt),
  387. .cr_psstat = IPATH_CREG_OFFSET(PSStat),
  388. .cr_psstart = IPATH_CREG_OFFSET(PSStart),
  389. .cr_psinterval = IPATH_CREG_OFFSET(PSInterval),
  390. .cr_psrcvdatacount = IPATH_CREG_OFFSET(PSRcvDataCount),
  391. .cr_psrcvpktscount = IPATH_CREG_OFFSET(PSRcvPktsCount),
  392. .cr_psxmitdatacount = IPATH_CREG_OFFSET(PSXmitDataCount),
  393. .cr_psxmitpktscount = IPATH_CREG_OFFSET(PSXmitPktsCount),
  394. .cr_psxmitwaitcount = IPATH_CREG_OFFSET(PSXmitWaitCount),
  395. };
  396. /* kr_control bits */
  397. #define INFINIPATH_C_RESET (1U<<7)
  398. /* kr_intstatus, kr_intclear, kr_intmask bits */
  399. #define INFINIPATH_I_RCVURG_MASK ((1ULL<<17)-1)
  400. #define INFINIPATH_I_RCVURG_SHIFT 32
  401. #define INFINIPATH_I_RCVAVAIL_MASK ((1ULL<<17)-1)
  402. #define INFINIPATH_I_RCVAVAIL_SHIFT 0
  403. #define INFINIPATH_I_SERDESTRIMDONE (1ULL<<27)
  404. /* kr_hwerrclear, kr_hwerrmask, kr_hwerrstatus, bits */
  405. #define INFINIPATH_HWE_PCIEMEMPARITYERR_MASK 0x00000000000000ffULL
  406. #define INFINIPATH_HWE_PCIEMEMPARITYERR_SHIFT 0
  407. #define INFINIPATH_HWE_PCIEPOISONEDTLP 0x0000000010000000ULL
  408. #define INFINIPATH_HWE_PCIECPLTIMEOUT 0x0000000020000000ULL
  409. #define INFINIPATH_HWE_PCIEBUSPARITYXTLH 0x0000000040000000ULL
  410. #define INFINIPATH_HWE_PCIEBUSPARITYXADM 0x0000000080000000ULL
  411. #define INFINIPATH_HWE_PCIEBUSPARITYRADM 0x0000000100000000ULL
  412. #define INFINIPATH_HWE_COREPLL_FBSLIP 0x0080000000000000ULL
  413. #define INFINIPATH_HWE_COREPLL_RFSLIP 0x0100000000000000ULL
  414. #define INFINIPATH_HWE_PCIE1PLLFAILED 0x0400000000000000ULL
  415. #define INFINIPATH_HWE_PCIE0PLLFAILED 0x0800000000000000ULL
  416. #define INFINIPATH_HWE_SERDESPLLFAILED 0x1000000000000000ULL
  417. /* specific to this chip */
  418. #define INFINIPATH_HWE_PCIECPLDATAQUEUEERR 0x0000000000000040ULL
  419. #define INFINIPATH_HWE_PCIECPLHDRQUEUEERR 0x0000000000000080ULL
  420. #define INFINIPATH_HWE_SDMAMEMREADERR 0x0000000010000000ULL
  421. #define INFINIPATH_HWE_CLK_UC_PLLNOTLOCKED 0x2000000000000000ULL
  422. #define INFINIPATH_HWE_PCIESERDESQ0PCLKNOTDETECT 0x0100000000000000ULL
  423. #define INFINIPATH_HWE_PCIESERDESQ1PCLKNOTDETECT 0x0200000000000000ULL
  424. #define INFINIPATH_HWE_PCIESERDESQ2PCLKNOTDETECT 0x0400000000000000ULL
  425. #define INFINIPATH_HWE_PCIESERDESQ3PCLKNOTDETECT 0x0800000000000000ULL
  426. #define INFINIPATH_HWE_DDSRXEQMEMORYPARITYERR 0x0000008000000000ULL
  427. #define INFINIPATH_HWE_IB_UC_MEMORYPARITYERR 0x0000004000000000ULL
  428. #define INFINIPATH_HWE_PCIE_UC_OCT0MEMORYPARITYERR 0x0000001000000000ULL
  429. #define INFINIPATH_HWE_PCIE_UC_OCT1MEMORYPARITYERR 0x0000002000000000ULL
  430. #define IBA7220_IBCS_LINKTRAININGSTATE_MASK 0x1F
  431. #define IBA7220_IBCS_LINKSTATE_SHIFT 5
  432. #define IBA7220_IBCS_LINKSPEED_SHIFT 8
  433. #define IBA7220_IBCS_LINKWIDTH_SHIFT 9
  434. #define IBA7220_IBCC_LINKINITCMD_MASK 0x7ULL
  435. #define IBA7220_IBCC_LINKCMD_SHIFT 19
  436. #define IBA7220_IBCC_MAXPKTLEN_SHIFT 21
  437. /* kr_ibcddrctrl bits */
  438. #define IBA7220_IBC_DLIDLMC_MASK 0xFFFFFFFFUL
  439. #define IBA7220_IBC_DLIDLMC_SHIFT 32
  440. #define IBA7220_IBC_HRTBT_MASK 3
  441. #define IBA7220_IBC_HRTBT_SHIFT 16
  442. #define IBA7220_IBC_HRTBT_ENB 0x10000UL
  443. #define IBA7220_IBC_LANE_REV_SUPPORTED (1<<8)
  444. #define IBA7220_IBC_LREV_MASK 1
  445. #define IBA7220_IBC_LREV_SHIFT 8
  446. #define IBA7220_IBC_RXPOL_MASK 1
  447. #define IBA7220_IBC_RXPOL_SHIFT 7
  448. #define IBA7220_IBC_WIDTH_SHIFT 5
  449. #define IBA7220_IBC_WIDTH_MASK 0x3
  450. #define IBA7220_IBC_WIDTH_1X_ONLY (0<<IBA7220_IBC_WIDTH_SHIFT)
  451. #define IBA7220_IBC_WIDTH_4X_ONLY (1<<IBA7220_IBC_WIDTH_SHIFT)
  452. #define IBA7220_IBC_WIDTH_AUTONEG (2<<IBA7220_IBC_WIDTH_SHIFT)
  453. #define IBA7220_IBC_SPEED_AUTONEG (1<<1)
  454. #define IBA7220_IBC_SPEED_SDR (1<<2)
  455. #define IBA7220_IBC_SPEED_DDR (1<<3)
  456. #define IBA7220_IBC_SPEED_AUTONEG_MASK (0x7<<1)
  457. #define IBA7220_IBC_IBTA_1_2_MASK (1)
  458. /* kr_ibcddrstatus */
  459. /* link latency shift is 0, don't bother defining */
  460. #define IBA7220_DDRSTAT_LINKLAT_MASK 0x3ffffff
  461. /* kr_extstatus bits */
  462. #define INFINIPATH_EXTS_FREQSEL 0x2
  463. #define INFINIPATH_EXTS_SERDESSEL 0x4
  464. #define INFINIPATH_EXTS_MEMBIST_ENDTEST 0x0000000000004000
  465. #define INFINIPATH_EXTS_MEMBIST_DISABLED 0x0000000000008000
  466. /* kr_xgxsconfig bits */
  467. #define INFINIPATH_XGXS_RESET 0x5ULL
  468. #define INFINIPATH_XGXS_FC_SAFE (1ULL<<63)
  469. /* kr_rcvpktledcnt */
  470. #define IBA7220_LEDBLINK_ON_SHIFT 32 /* 4ns period on after packet */
  471. #define IBA7220_LEDBLINK_OFF_SHIFT 0 /* 4ns period off before next on */
  472. #define _IPATH_GPIO_SDA_NUM 1
  473. #define _IPATH_GPIO_SCL_NUM 0
  474. #define IPATH_GPIO_SDA (1ULL << \
  475. (_IPATH_GPIO_SDA_NUM+INFINIPATH_EXTC_GPIOOE_SHIFT))
  476. #define IPATH_GPIO_SCL (1ULL << \
  477. (_IPATH_GPIO_SCL_NUM+INFINIPATH_EXTC_GPIOOE_SHIFT))
  478. #define IBA7220_R_INTRAVAIL_SHIFT 17
  479. #define IBA7220_R_TAILUPD_SHIFT 35
  480. #define IBA7220_R_PORTCFG_SHIFT 36
  481. #define INFINIPATH_JINT_PACKETSHIFT 16
  482. #define INFINIPATH_JINT_DEFAULT_IDLE_TICKS 0
  483. #define INFINIPATH_JINT_DEFAULT_MAX_PACKETS 0
  484. #define IBA7220_HDRHEAD_PKTINT_SHIFT 32 /* interrupt cnt in upper 32 bits */
  485. /*
  486. * the size bits give us 2^N, in KB units. 0 marks as invalid,
  487. * and 7 is reserved. We currently use only 2KB and 4KB
  488. */
  489. #define IBA7220_TID_SZ_SHIFT 37 /* shift to 3bit size selector */
  490. #define IBA7220_TID_SZ_2K (1UL<<IBA7220_TID_SZ_SHIFT) /* 2KB */
  491. #define IBA7220_TID_SZ_4K (2UL<<IBA7220_TID_SZ_SHIFT) /* 4KB */
  492. #define IBA7220_TID_PA_SHIFT 11U /* TID addr in chip stored w/o low bits */
  493. #define IPATH_AUTONEG_TRIES 5 /* sequential retries to negotiate DDR */
  494. static char int_type[16] = "auto";
  495. module_param_string(interrupt_type, int_type, sizeof(int_type), 0444);
  496. MODULE_PARM_DESC(int_type, " interrupt_type=auto|force_msi|force_intx");
  497. /* packet rate matching delay; chip has support */
  498. static u8 rate_to_delay[2][2] = {
  499. /* 1x, 4x */
  500. { 8, 2 }, /* SDR */
  501. { 4, 1 } /* DDR */
  502. };
  503. /* 7220 specific hardware errors... */
  504. static const struct ipath_hwerror_msgs ipath_7220_hwerror_msgs[] = {
  505. INFINIPATH_HWE_MSG(PCIEPOISONEDTLP, "PCIe Poisoned TLP"),
  506. INFINIPATH_HWE_MSG(PCIECPLTIMEOUT, "PCIe completion timeout"),
  507. /*
  508. * In practice, it's unlikely wthat we'll see PCIe PLL, or bus
  509. * parity or memory parity error failures, because most likely we
  510. * won't be able to talk to the core of the chip. Nonetheless, we
  511. * might see them, if they are in parts of the PCIe core that aren't
  512. * essential.
  513. */
  514. INFINIPATH_HWE_MSG(PCIE1PLLFAILED, "PCIePLL1"),
  515. INFINIPATH_HWE_MSG(PCIE0PLLFAILED, "PCIePLL0"),
  516. INFINIPATH_HWE_MSG(PCIEBUSPARITYXTLH, "PCIe XTLH core parity"),
  517. INFINIPATH_HWE_MSG(PCIEBUSPARITYXADM, "PCIe ADM TX core parity"),
  518. INFINIPATH_HWE_MSG(PCIEBUSPARITYRADM, "PCIe ADM RX core parity"),
  519. INFINIPATH_HWE_MSG(RXDSYNCMEMPARITYERR, "Rx Dsync"),
  520. INFINIPATH_HWE_MSG(SERDESPLLFAILED, "SerDes PLL"),
  521. INFINIPATH_HWE_MSG(PCIECPLDATAQUEUEERR, "PCIe cpl header queue"),
  522. INFINIPATH_HWE_MSG(PCIECPLHDRQUEUEERR, "PCIe cpl data queue"),
  523. INFINIPATH_HWE_MSG(SDMAMEMREADERR, "Send DMA memory read"),
  524. INFINIPATH_HWE_MSG(CLK_UC_PLLNOTLOCKED, "uC PLL clock not locked"),
  525. INFINIPATH_HWE_MSG(PCIESERDESQ0PCLKNOTDETECT,
  526. "PCIe serdes Q0 no clock"),
  527. INFINIPATH_HWE_MSG(PCIESERDESQ1PCLKNOTDETECT,
  528. "PCIe serdes Q1 no clock"),
  529. INFINIPATH_HWE_MSG(PCIESERDESQ2PCLKNOTDETECT,
  530. "PCIe serdes Q2 no clock"),
  531. INFINIPATH_HWE_MSG(PCIESERDESQ3PCLKNOTDETECT,
  532. "PCIe serdes Q3 no clock"),
  533. INFINIPATH_HWE_MSG(DDSRXEQMEMORYPARITYERR,
  534. "DDS RXEQ memory parity"),
  535. INFINIPATH_HWE_MSG(IB_UC_MEMORYPARITYERR, "IB uC memory parity"),
  536. INFINIPATH_HWE_MSG(PCIE_UC_OCT0MEMORYPARITYERR,
  537. "PCIe uC oct0 memory parity"),
  538. INFINIPATH_HWE_MSG(PCIE_UC_OCT1MEMORYPARITYERR,
  539. "PCIe uC oct1 memory parity"),
  540. };
  541. static void autoneg_work(struct work_struct *);
  542. /*
  543. * the offset is different for different configured port numbers, since
  544. * port0 is fixed in size, but others can vary. Make it a function to
  545. * make the issue more obvious.
  546. */
  547. static inline u32 port_egrtid_idx(struct ipath_devdata *dd, unsigned port)
  548. {
  549. return port ? dd->ipath_p0_rcvegrcnt +
  550. (port-1) * dd->ipath_rcvegrcnt : 0;
  551. }
  552. static void ipath_7220_txe_recover(struct ipath_devdata *dd)
  553. {
  554. ++ipath_stats.sps_txeparity;
  555. dev_info(&dd->pcidev->dev,
  556. "Recovering from TXE PIO parity error\n");
  557. ipath_disarm_senderrbufs(dd);
  558. }
  559. /**
  560. * ipath_7220_handle_hwerrors - display hardware errors.
  561. * @dd: the infinipath device
  562. * @msg: the output buffer
  563. * @msgl: the size of the output buffer
  564. *
  565. * Use same msg buffer as regular errors to avoid excessive stack
  566. * use. Most hardware errors are catastrophic, but for right now,
  567. * we'll print them and continue. We reuse the same message buffer as
  568. * ipath_handle_errors() to avoid excessive stack usage.
  569. */
  570. static void ipath_7220_handle_hwerrors(struct ipath_devdata *dd, char *msg,
  571. size_t msgl)
  572. {
  573. ipath_err_t hwerrs;
  574. u32 bits, ctrl;
  575. int isfatal = 0;
  576. char bitsmsg[64];
  577. int log_idx;
  578. hwerrs = ipath_read_kreg64(dd, dd->ipath_kregs->kr_hwerrstatus);
  579. if (!hwerrs) {
  580. /*
  581. * better than printing cofusing messages
  582. * This seems to be related to clearing the crc error, or
  583. * the pll error during init.
  584. */
  585. ipath_cdbg(VERBOSE, "Called but no hardware errors set\n");
  586. goto bail;
  587. } else if (hwerrs == ~0ULL) {
  588. ipath_dev_err(dd, "Read of hardware error status failed "
  589. "(all bits set); ignoring\n");
  590. goto bail;
  591. }
  592. ipath_stats.sps_hwerrs++;
  593. /*
  594. * Always clear the error status register, except MEMBISTFAIL,
  595. * regardless of whether we continue or stop using the chip.
  596. * We want that set so we know it failed, even across driver reload.
  597. * We'll still ignore it in the hwerrmask. We do this partly for
  598. * diagnostics, but also for support.
  599. */
  600. ipath_write_kreg(dd, dd->ipath_kregs->kr_hwerrclear,
  601. hwerrs&~INFINIPATH_HWE_MEMBISTFAILED);
  602. hwerrs &= dd->ipath_hwerrmask;
  603. /* We log some errors to EEPROM, check if we have any of those. */
  604. for (log_idx = 0; log_idx < IPATH_EEP_LOG_CNT; ++log_idx)
  605. if (hwerrs & dd->ipath_eep_st_masks[log_idx].hwerrs_to_log)
  606. ipath_inc_eeprom_err(dd, log_idx, 1);
  607. /*
  608. * Make sure we get this much out, unless told to be quiet,
  609. * or it's occurred within the last 5 seconds.
  610. */
  611. if ((hwerrs & ~(dd->ipath_lasthwerror |
  612. ((INFINIPATH_HWE_TXEMEMPARITYERR_PIOBUF |
  613. INFINIPATH_HWE_TXEMEMPARITYERR_PIOPBC)
  614. << INFINIPATH_HWE_TXEMEMPARITYERR_SHIFT))) ||
  615. (ipath_debug & __IPATH_VERBDBG))
  616. dev_info(&dd->pcidev->dev, "Hardware error: hwerr=0x%llx "
  617. "(cleared)\n", (unsigned long long) hwerrs);
  618. dd->ipath_lasthwerror |= hwerrs;
  619. if (hwerrs & ~dd->ipath_hwe_bitsextant)
  620. ipath_dev_err(dd, "hwerror interrupt with unknown errors "
  621. "%llx set\n", (unsigned long long)
  622. (hwerrs & ~dd->ipath_hwe_bitsextant));
  623. if (hwerrs & INFINIPATH_HWE_IB_UC_MEMORYPARITYERR)
  624. ipath_sd7220_clr_ibpar(dd);
  625. ctrl = ipath_read_kreg32(dd, dd->ipath_kregs->kr_control);
  626. if ((ctrl & INFINIPATH_C_FREEZEMODE) && !ipath_diag_inuse) {
  627. /*
  628. * Parity errors in send memory are recoverable by h/w
  629. * just do housekeeping, exit freeze mode and continue.
  630. */
  631. if (hwerrs & ((INFINIPATH_HWE_TXEMEMPARITYERR_PIOBUF |
  632. INFINIPATH_HWE_TXEMEMPARITYERR_PIOPBC)
  633. << INFINIPATH_HWE_TXEMEMPARITYERR_SHIFT)) {
  634. ipath_7220_txe_recover(dd);
  635. hwerrs &= ~((INFINIPATH_HWE_TXEMEMPARITYERR_PIOBUF |
  636. INFINIPATH_HWE_TXEMEMPARITYERR_PIOPBC)
  637. << INFINIPATH_HWE_TXEMEMPARITYERR_SHIFT);
  638. }
  639. if (hwerrs) {
  640. /*
  641. * If any set that we aren't ignoring only make the
  642. * complaint once, in case it's stuck or recurring,
  643. * and we get here multiple times
  644. * Force link down, so switch knows, and
  645. * LEDs are turned off.
  646. */
  647. if (dd->ipath_flags & IPATH_INITTED) {
  648. ipath_set_linkstate(dd, IPATH_IB_LINKDOWN);
  649. ipath_setup_7220_setextled(dd,
  650. INFINIPATH_IBCS_L_STATE_DOWN,
  651. INFINIPATH_IBCS_LT_STATE_DISABLED);
  652. ipath_dev_err(dd, "Fatal Hardware Error "
  653. "(freeze mode), no longer"
  654. " usable, SN %.16s\n",
  655. dd->ipath_serial);
  656. isfatal = 1;
  657. }
  658. /*
  659. * Mark as having had an error for driver, and also
  660. * for /sys and status word mapped to user programs.
  661. * This marks unit as not usable, until reset.
  662. */
  663. *dd->ipath_statusp &= ~IPATH_STATUS_IB_READY;
  664. *dd->ipath_statusp |= IPATH_STATUS_HWERROR;
  665. dd->ipath_flags &= ~IPATH_INITTED;
  666. } else {
  667. ipath_dbg("Clearing freezemode on ignored or "
  668. "recovered hardware error\n");
  669. ipath_clear_freeze(dd);
  670. }
  671. }
  672. *msg = '\0';
  673. if (hwerrs & INFINIPATH_HWE_MEMBISTFAILED) {
  674. strlcat(msg, "[Memory BIST test failed, "
  675. "InfiniPath hardware unusable]", msgl);
  676. /* ignore from now on, so disable until driver reloaded */
  677. *dd->ipath_statusp |= IPATH_STATUS_HWERROR;
  678. dd->ipath_hwerrmask &= ~INFINIPATH_HWE_MEMBISTFAILED;
  679. ipath_write_kreg(dd, dd->ipath_kregs->kr_hwerrmask,
  680. dd->ipath_hwerrmask);
  681. }
  682. ipath_format_hwerrors(hwerrs,
  683. ipath_7220_hwerror_msgs,
  684. ARRAY_SIZE(ipath_7220_hwerror_msgs),
  685. msg, msgl);
  686. if (hwerrs & (INFINIPATH_HWE_PCIEMEMPARITYERR_MASK
  687. << INFINIPATH_HWE_PCIEMEMPARITYERR_SHIFT)) {
  688. bits = (u32) ((hwerrs >>
  689. INFINIPATH_HWE_PCIEMEMPARITYERR_SHIFT) &
  690. INFINIPATH_HWE_PCIEMEMPARITYERR_MASK);
  691. snprintf(bitsmsg, sizeof bitsmsg,
  692. "[PCIe Mem Parity Errs %x] ", bits);
  693. strlcat(msg, bitsmsg, msgl);
  694. }
  695. #define _IPATH_PLL_FAIL (INFINIPATH_HWE_COREPLL_FBSLIP | \
  696. INFINIPATH_HWE_COREPLL_RFSLIP)
  697. if (hwerrs & _IPATH_PLL_FAIL) {
  698. snprintf(bitsmsg, sizeof bitsmsg,
  699. "[PLL failed (%llx), InfiniPath hardware unusable]",
  700. (unsigned long long) hwerrs & _IPATH_PLL_FAIL);
  701. strlcat(msg, bitsmsg, msgl);
  702. /* ignore from now on, so disable until driver reloaded */
  703. dd->ipath_hwerrmask &= ~(hwerrs & _IPATH_PLL_FAIL);
  704. ipath_write_kreg(dd, dd->ipath_kregs->kr_hwerrmask,
  705. dd->ipath_hwerrmask);
  706. }
  707. if (hwerrs & INFINIPATH_HWE_SERDESPLLFAILED) {
  708. /*
  709. * If it occurs, it is left masked since the eternal
  710. * interface is unused.
  711. */
  712. dd->ipath_hwerrmask &= ~INFINIPATH_HWE_SERDESPLLFAILED;
  713. ipath_write_kreg(dd, dd->ipath_kregs->kr_hwerrmask,
  714. dd->ipath_hwerrmask);
  715. }
  716. ipath_dev_err(dd, "%s hardware error\n", msg);
  717. /*
  718. * For /sys status file. if no trailing } is copied, we'll
  719. * know it was truncated.
  720. */
  721. if (isfatal && !ipath_diag_inuse && dd->ipath_freezemsg)
  722. snprintf(dd->ipath_freezemsg, dd->ipath_freezelen,
  723. "{%s}", msg);
  724. bail:;
  725. }
  726. /**
  727. * ipath_7220_boardname - fill in the board name
  728. * @dd: the infinipath device
  729. * @name: the output buffer
  730. * @namelen: the size of the output buffer
  731. *
  732. * info is based on the board revision register
  733. */
  734. static int ipath_7220_boardname(struct ipath_devdata *dd, char *name,
  735. size_t namelen)
  736. {
  737. char *n = NULL;
  738. u8 boardrev = dd->ipath_boardrev;
  739. int ret;
  740. if (boardrev == 15) {
  741. /*
  742. * Emulator sometimes comes up all-ones, rather than zero.
  743. */
  744. boardrev = 0;
  745. dd->ipath_boardrev = boardrev;
  746. }
  747. switch (boardrev) {
  748. case 0:
  749. n = "InfiniPath_7220_Emulation";
  750. break;
  751. case 1:
  752. n = "InfiniPath_QLE7240";
  753. break;
  754. case 2:
  755. n = "InfiniPath_QLE7280";
  756. break;
  757. case 3:
  758. n = "InfiniPath_QLE7242";
  759. break;
  760. case 4:
  761. n = "InfiniPath_QEM7240";
  762. break;
  763. case 5:
  764. n = "InfiniPath_QMI7240";
  765. break;
  766. case 6:
  767. n = "InfiniPath_QMI7264";
  768. break;
  769. case 7:
  770. n = "InfiniPath_QMH7240";
  771. break;
  772. case 8:
  773. n = "InfiniPath_QME7240";
  774. break;
  775. case 9:
  776. n = "InfiniPath_QLE7250";
  777. break;
  778. case 10:
  779. n = "InfiniPath_QLE7290";
  780. break;
  781. case 11:
  782. n = "InfiniPath_QEM7250";
  783. break;
  784. case 12:
  785. n = "InfiniPath_QLE-Bringup";
  786. break;
  787. default:
  788. ipath_dev_err(dd,
  789. "Don't yet know about board with ID %u\n",
  790. boardrev);
  791. snprintf(name, namelen, "Unknown_InfiniPath_PCIe_%u",
  792. boardrev);
  793. break;
  794. }
  795. if (n)
  796. snprintf(name, namelen, "%s", n);
  797. if (dd->ipath_majrev != 5 || !dd->ipath_minrev ||
  798. dd->ipath_minrev > 2) {
  799. ipath_dev_err(dd, "Unsupported InfiniPath hardware "
  800. "revision %u.%u!\n",
  801. dd->ipath_majrev, dd->ipath_minrev);
  802. ret = 1;
  803. } else if (dd->ipath_minrev == 1 &&
  804. !(dd->ipath_flags & IPATH_INITTED)) {
  805. /* Rev1 chips are prototype. Complain at init, but allow use */
  806. ipath_dev_err(dd, "Unsupported hardware "
  807. "revision %u.%u, Contact support@qlogic.com\n",
  808. dd->ipath_majrev, dd->ipath_minrev);
  809. ret = 0;
  810. } else
  811. ret = 0;
  812. /*
  813. * Set here not in ipath_init_*_funcs because we have to do
  814. * it after we can read chip registers.
  815. */
  816. dd->ipath_ureg_align = 0x10000; /* 64KB alignment */
  817. return ret;
  818. }
  819. /**
  820. * ipath_7220_init_hwerrors - enable hardware errors
  821. * @dd: the infinipath device
  822. *
  823. * now that we have finished initializing everything that might reasonably
  824. * cause a hardware error, and cleared those errors bits as they occur,
  825. * we can enable hardware errors in the mask (potentially enabling
  826. * freeze mode), and enable hardware errors as errors (along with
  827. * everything else) in errormask
  828. */
  829. static void ipath_7220_init_hwerrors(struct ipath_devdata *dd)
  830. {
  831. ipath_err_t val;
  832. u64 extsval;
  833. extsval = ipath_read_kreg64(dd, dd->ipath_kregs->kr_extstatus);
  834. if (!(extsval & (INFINIPATH_EXTS_MEMBIST_ENDTEST |
  835. INFINIPATH_EXTS_MEMBIST_DISABLED)))
  836. ipath_dev_err(dd, "MemBIST did not complete!\n");
  837. if (extsval & INFINIPATH_EXTS_MEMBIST_DISABLED)
  838. dev_info(&dd->pcidev->dev, "MemBIST is disabled.\n");
  839. val = ~0ULL; /* barring bugs, all hwerrors become interrupts, */
  840. if (!dd->ipath_boardrev) /* no PLL for Emulator */
  841. val &= ~INFINIPATH_HWE_SERDESPLLFAILED;
  842. if (dd->ipath_minrev == 1)
  843. val &= ~(1ULL << 42); /* TXE LaunchFIFO Parity rev1 issue */
  844. val &= ~INFINIPATH_HWE_IB_UC_MEMORYPARITYERR;
  845. dd->ipath_hwerrmask = val;
  846. /*
  847. * special trigger "error" is for debugging purposes. It
  848. * works around a processor/chipset problem. The error
  849. * interrupt allows us to count occurrences, but we don't
  850. * want to pay the overhead for normal use. Emulation only
  851. */
  852. if (!dd->ipath_boardrev)
  853. dd->ipath_maskederrs = INFINIPATH_E_SENDSPECIALTRIGGER;
  854. }
  855. /*
  856. * All detailed interaction with the SerDes has been moved to ipath_sd7220.c
  857. *
  858. * The portion of IBA7220-specific bringup_serdes() that actually deals with
  859. * registers and memory within the SerDes itself is ipath_sd7220_init().
  860. */
  861. /**
  862. * ipath_7220_bringup_serdes - bring up the serdes
  863. * @dd: the infinipath device
  864. */
  865. static int ipath_7220_bringup_serdes(struct ipath_devdata *dd)
  866. {
  867. int ret = 0;
  868. u64 val, prev_val, guid;
  869. int was_reset; /* Note whether uC was reset */
  870. ipath_dbg("Trying to bringup serdes\n");
  871. if (ipath_read_kreg64(dd, dd->ipath_kregs->kr_hwerrstatus) &
  872. INFINIPATH_HWE_SERDESPLLFAILED) {
  873. ipath_dbg("At start, serdes PLL failed bit set "
  874. "in hwerrstatus, clearing and continuing\n");
  875. ipath_write_kreg(dd, dd->ipath_kregs->kr_hwerrclear,
  876. INFINIPATH_HWE_SERDESPLLFAILED);
  877. }
  878. dd->ibdeltainprog = 1;
  879. dd->ibsymsnap =
  880. ipath_read_creg32(dd, dd->ipath_cregs->cr_ibsymbolerrcnt);
  881. dd->iblnkerrsnap =
  882. ipath_read_creg32(dd, dd->ipath_cregs->cr_iblinkerrrecovcnt);
  883. if (!dd->ipath_ibcddrctrl) {
  884. /* not on re-init after reset */
  885. dd->ipath_ibcddrctrl =
  886. ipath_read_kreg64(dd, dd->ipath_kregs->kr_ibcddrctrl);
  887. if (dd->ipath_link_speed_enabled ==
  888. (IPATH_IB_SDR | IPATH_IB_DDR))
  889. dd->ipath_ibcddrctrl |=
  890. IBA7220_IBC_SPEED_AUTONEG_MASK |
  891. IBA7220_IBC_IBTA_1_2_MASK;
  892. else
  893. dd->ipath_ibcddrctrl |=
  894. dd->ipath_link_speed_enabled == IPATH_IB_DDR
  895. ? IBA7220_IBC_SPEED_DDR :
  896. IBA7220_IBC_SPEED_SDR;
  897. if ((dd->ipath_link_width_enabled & (IB_WIDTH_1X |
  898. IB_WIDTH_4X)) == (IB_WIDTH_1X | IB_WIDTH_4X))
  899. dd->ipath_ibcddrctrl |= IBA7220_IBC_WIDTH_AUTONEG;
  900. else
  901. dd->ipath_ibcddrctrl |=
  902. dd->ipath_link_width_enabled == IB_WIDTH_4X
  903. ? IBA7220_IBC_WIDTH_4X_ONLY :
  904. IBA7220_IBC_WIDTH_1X_ONLY;
  905. /* always enable these on driver reload, not sticky */
  906. dd->ipath_ibcddrctrl |=
  907. IBA7220_IBC_RXPOL_MASK << IBA7220_IBC_RXPOL_SHIFT;
  908. dd->ipath_ibcddrctrl |=
  909. IBA7220_IBC_HRTBT_MASK << IBA7220_IBC_HRTBT_SHIFT;
  910. /*
  911. * automatic lane reversal detection for receive
  912. * doesn't work correctly in rev 1, so disable it
  913. * on that rev, otherwise enable (disabling not
  914. * sticky across reload for >rev1)
  915. */
  916. if (dd->ipath_minrev == 1)
  917. dd->ipath_ibcddrctrl &=
  918. ~IBA7220_IBC_LANE_REV_SUPPORTED;
  919. else
  920. dd->ipath_ibcddrctrl |=
  921. IBA7220_IBC_LANE_REV_SUPPORTED;
  922. }
  923. ipath_write_kreg(dd, dd->ipath_kregs->kr_ibcddrctrl,
  924. dd->ipath_ibcddrctrl);
  925. ipath_write_kreg(dd, IPATH_KREG_OFFSET(IBNCModeCtrl), 0Ull);
  926. /* IBA7220 has SERDES MPU reset in D0 of what _was_ IBPLLCfg */
  927. val = ipath_read_kreg64(dd, dd->ipath_kregs->kr_ibserdesctrl);
  928. /* remember if uC was in Reset or not, for dactrim */
  929. was_reset = (val & 1);
  930. ipath_cdbg(VERBOSE, "IBReset %s xgxsconfig %llx\n",
  931. was_reset ? "Asserted" : "Negated", (unsigned long long)
  932. ipath_read_kreg64(dd, dd->ipath_kregs->kr_xgxsconfig));
  933. if (dd->ipath_boardrev) {
  934. /*
  935. * Hardware is not emulator, and may have been reset. Init it.
  936. * Below will release reset, but needs to know if chip was
  937. * originally in reset, to only trim DACs on first time
  938. * after chip reset or powercycle (not driver reload)
  939. */
  940. ret = ipath_sd7220_init(dd, was_reset);
  941. }
  942. val = ipath_read_kreg64(dd, dd->ipath_kregs->kr_xgxsconfig);
  943. prev_val = val;
  944. val |= INFINIPATH_XGXS_FC_SAFE;
  945. if (val != prev_val) {
  946. ipath_write_kreg(dd, dd->ipath_kregs->kr_xgxsconfig, val);
  947. ipath_read_kreg32(dd, dd->ipath_kregs->kr_scratch);
  948. }
  949. if (val & INFINIPATH_XGXS_RESET)
  950. val &= ~INFINIPATH_XGXS_RESET;
  951. if (val != prev_val)
  952. ipath_write_kreg(dd, dd->ipath_kregs->kr_xgxsconfig, val);
  953. ipath_cdbg(VERBOSE, "done: xgxs=%llx from %llx\n",
  954. (unsigned long long)
  955. ipath_read_kreg64(dd, dd->ipath_kregs->kr_xgxsconfig),
  956. (unsigned long long) prev_val);
  957. guid = be64_to_cpu(dd->ipath_guid);
  958. if (!guid) {
  959. /* have to have something, so use likely unique tsc */
  960. guid = get_cycles();
  961. ipath_dbg("No GUID for heartbeat, faking %llx\n",
  962. (unsigned long long)guid);
  963. } else
  964. ipath_cdbg(VERBOSE, "Wrote %llX to HRTBT_GUID\n",
  965. (unsigned long long) guid);
  966. ipath_write_kreg(dd, dd->ipath_kregs->kr_hrtbt_guid, guid);
  967. return ret;
  968. }
  969. static void ipath_7220_config_jint(struct ipath_devdata *dd,
  970. u16 idle_ticks, u16 max_packets)
  971. {
  972. /*
  973. * We can request a receive interrupt for 1 or more packets
  974. * from current offset.
  975. */
  976. if (idle_ticks == 0 || max_packets == 0)
  977. /* interrupt after one packet if no mitigation */
  978. dd->ipath_rhdrhead_intr_off =
  979. 1ULL << IBA7220_HDRHEAD_PKTINT_SHIFT;
  980. else
  981. /* Turn off RcvHdrHead interrupts if using mitigation */
  982. dd->ipath_rhdrhead_intr_off = 0ULL;
  983. /* refresh kernel RcvHdrHead registers... */
  984. ipath_write_ureg(dd, ur_rcvhdrhead,
  985. dd->ipath_rhdrhead_intr_off |
  986. dd->ipath_pd[0]->port_head, 0);
  987. dd->ipath_jint_max_packets = max_packets;
  988. dd->ipath_jint_idle_ticks = idle_ticks;
  989. ipath_write_kreg(dd, dd->ipath_kregs->kr_jintreload,
  990. ((u64) max_packets << INFINIPATH_JINT_PACKETSHIFT) |
  991. idle_ticks);
  992. }
  993. /**
  994. * ipath_7220_quiet_serdes - set serdes to txidle
  995. * @dd: the infinipath device
  996. * Called when driver is being unloaded
  997. */
  998. static void ipath_7220_quiet_serdes(struct ipath_devdata *dd)
  999. {
  1000. u64 val;
  1001. if (dd->ibsymdelta || dd->iblnkerrdelta ||
  1002. dd->ibdeltainprog) {
  1003. u64 diagc;
  1004. /* enable counter writes */
  1005. diagc = ipath_read_kreg64(dd, dd->ipath_kregs->kr_hwdiagctrl);
  1006. ipath_write_kreg(dd, dd->ipath_kregs->kr_hwdiagctrl,
  1007. diagc | INFINIPATH_DC_COUNTERWREN);
  1008. if (dd->ibsymdelta || dd->ibdeltainprog) {
  1009. val = ipath_read_creg32(dd,
  1010. dd->ipath_cregs->cr_ibsymbolerrcnt);
  1011. if (dd->ibdeltainprog)
  1012. val -= val - dd->ibsymsnap;
  1013. val -= dd->ibsymdelta;
  1014. ipath_write_creg(dd,
  1015. dd->ipath_cregs->cr_ibsymbolerrcnt, val);
  1016. }
  1017. if (dd->iblnkerrdelta || dd->ibdeltainprog) {
  1018. val = ipath_read_creg32(dd,
  1019. dd->ipath_cregs->cr_iblinkerrrecovcnt);
  1020. if (dd->ibdeltainprog)
  1021. val -= val - dd->iblnkerrsnap;
  1022. val -= dd->iblnkerrdelta;
  1023. ipath_write_creg(dd,
  1024. dd->ipath_cregs->cr_iblinkerrrecovcnt, val);
  1025. }
  1026. /* and disable counter writes */
  1027. ipath_write_kreg(dd, dd->ipath_kregs->kr_hwdiagctrl, diagc);
  1028. }
  1029. dd->ipath_flags &= ~IPATH_IB_AUTONEG_INPROG;
  1030. wake_up(&dd->ipath_autoneg_wait);
  1031. cancel_delayed_work(&dd->ipath_autoneg_work);
  1032. flush_scheduled_work();
  1033. ipath_shutdown_relock_poll(dd);
  1034. val = ipath_read_kreg64(dd, dd->ipath_kregs->kr_xgxsconfig);
  1035. val |= INFINIPATH_XGXS_RESET;
  1036. ipath_write_kreg(dd, dd->ipath_kregs->kr_xgxsconfig, val);
  1037. }
  1038. static int ipath_7220_intconfig(struct ipath_devdata *dd)
  1039. {
  1040. ipath_7220_config_jint(dd, dd->ipath_jint_idle_ticks,
  1041. dd->ipath_jint_max_packets);
  1042. return 0;
  1043. }
  1044. /**
  1045. * ipath_setup_7220_setextled - set the state of the two external LEDs
  1046. * @dd: the infinipath device
  1047. * @lst: the L state
  1048. * @ltst: the LT state
  1049. *
  1050. * These LEDs indicate the physical and logical state of IB link.
  1051. * For this chip (at least with recommended board pinouts), LED1
  1052. * is Yellow (logical state) and LED2 is Green (physical state),
  1053. *
  1054. * Note: We try to match the Mellanox HCA LED behavior as best
  1055. * we can. Green indicates physical link state is OK (something is
  1056. * plugged in, and we can train).
  1057. * Amber indicates the link is logically up (ACTIVE).
  1058. * Mellanox further blinks the amber LED to indicate data packet
  1059. * activity, but we have no hardware support for that, so it would
  1060. * require waking up every 10-20 msecs and checking the counters
  1061. * on the chip, and then turning the LED off if appropriate. That's
  1062. * visible overhead, so not something we will do.
  1063. *
  1064. */
  1065. static void ipath_setup_7220_setextled(struct ipath_devdata *dd, u64 lst,
  1066. u64 ltst)
  1067. {
  1068. u64 extctl, ledblink = 0;
  1069. unsigned long flags = 0;
  1070. /* the diags use the LED to indicate diag info, so we leave
  1071. * the external LED alone when the diags are running */
  1072. if (ipath_diag_inuse)
  1073. return;
  1074. /* Allow override of LED display for, e.g. Locating system in rack */
  1075. if (dd->ipath_led_override) {
  1076. ltst = (dd->ipath_led_override & IPATH_LED_PHYS)
  1077. ? INFINIPATH_IBCS_LT_STATE_LINKUP
  1078. : INFINIPATH_IBCS_LT_STATE_DISABLED;
  1079. lst = (dd->ipath_led_override & IPATH_LED_LOG)
  1080. ? INFINIPATH_IBCS_L_STATE_ACTIVE
  1081. : INFINIPATH_IBCS_L_STATE_DOWN;
  1082. }
  1083. spin_lock_irqsave(&dd->ipath_gpio_lock, flags);
  1084. extctl = dd->ipath_extctrl & ~(INFINIPATH_EXTC_LED1PRIPORT_ON |
  1085. INFINIPATH_EXTC_LED2PRIPORT_ON);
  1086. if (ltst == INFINIPATH_IBCS_LT_STATE_LINKUP) {
  1087. extctl |= INFINIPATH_EXTC_LED1PRIPORT_ON;
  1088. /*
  1089. * counts are in chip clock (4ns) periods.
  1090. * This is 1/16 sec (66.6ms) on,
  1091. * 3/16 sec (187.5 ms) off, with packets rcvd
  1092. */
  1093. ledblink = ((66600*1000UL/4) << IBA7220_LEDBLINK_ON_SHIFT)
  1094. | ((187500*1000UL/4) << IBA7220_LEDBLINK_OFF_SHIFT);
  1095. }
  1096. if (lst == INFINIPATH_IBCS_L_STATE_ACTIVE)
  1097. extctl |= INFINIPATH_EXTC_LED2PRIPORT_ON;
  1098. dd->ipath_extctrl = extctl;
  1099. ipath_write_kreg(dd, dd->ipath_kregs->kr_extctrl, extctl);
  1100. spin_unlock_irqrestore(&dd->ipath_gpio_lock, flags);
  1101. if (ledblink) /* blink the LED on packet receive */
  1102. ipath_write_kreg(dd, dd->ipath_kregs->kr_rcvpktledcnt,
  1103. ledblink);
  1104. }
  1105. /*
  1106. * Similar to pci_intx(pdev, 1), except that we make sure
  1107. * msi is off...
  1108. */
  1109. static void ipath_enable_intx(struct pci_dev *pdev)
  1110. {
  1111. u16 cw, new;
  1112. int pos;
  1113. /* first, turn on INTx */
  1114. pci_read_config_word(pdev, PCI_COMMAND, &cw);
  1115. new = cw & ~PCI_COMMAND_INTX_DISABLE;
  1116. if (new != cw)
  1117. pci_write_config_word(pdev, PCI_COMMAND, new);
  1118. /* then turn off MSI */
  1119. pos = pci_find_capability(pdev, PCI_CAP_ID_MSI);
  1120. if (pos) {
  1121. pci_read_config_word(pdev, pos + PCI_MSI_FLAGS, &cw);
  1122. new = cw & ~PCI_MSI_FLAGS_ENABLE;
  1123. if (new != cw)
  1124. pci_write_config_word(pdev, pos + PCI_MSI_FLAGS, new);
  1125. }
  1126. }
  1127. static int ipath_msi_enabled(struct pci_dev *pdev)
  1128. {
  1129. int pos, ret = 0;
  1130. pos = pci_find_capability(pdev, PCI_CAP_ID_MSI);
  1131. if (pos) {
  1132. u16 cw;
  1133. pci_read_config_word(pdev, pos + PCI_MSI_FLAGS, &cw);
  1134. ret = !!(cw & PCI_MSI_FLAGS_ENABLE);
  1135. }
  1136. return ret;
  1137. }
  1138. /*
  1139. * disable msi interrupt if enabled, and clear the flag.
  1140. * flag is used primarily for the fallback to INTx, but
  1141. * is also used in reinit after reset as a flag.
  1142. */
  1143. static void ipath_7220_nomsi(struct ipath_devdata *dd)
  1144. {
  1145. dd->ipath_msi_lo = 0;
  1146. if (ipath_msi_enabled(dd->pcidev)) {
  1147. /*
  1148. * free, but don't zero; later kernels require
  1149. * it be freed before disable_msi, so the intx
  1150. * setup has to request it again.
  1151. */
  1152. if (dd->ipath_irq)
  1153. free_irq(dd->ipath_irq, dd);
  1154. pci_disable_msi(dd->pcidev);
  1155. }
  1156. }
  1157. /*
  1158. * ipath_setup_7220_cleanup - clean up any per-chip chip-specific stuff
  1159. * @dd: the infinipath device
  1160. *
  1161. * Nothing but msi interrupt cleanup for now.
  1162. *
  1163. * This is called during driver unload.
  1164. */
  1165. static void ipath_setup_7220_cleanup(struct ipath_devdata *dd)
  1166. {
  1167. ipath_7220_nomsi(dd);
  1168. }
  1169. static void ipath_7220_pcie_params(struct ipath_devdata *dd, u32 boardrev)
  1170. {
  1171. u16 linkstat, minwidth, speed;
  1172. int pos;
  1173. pos = pci_find_capability(dd->pcidev, PCI_CAP_ID_EXP);
  1174. if (!pos) {
  1175. ipath_dev_err(dd, "Can't find PCI Express capability!\n");
  1176. goto bail;
  1177. }
  1178. pci_read_config_word(dd->pcidev, pos + PCI_EXP_LNKSTA,
  1179. &linkstat);
  1180. /*
  1181. * speed is bits 0-4, linkwidth is bits 4-8
  1182. * no defines for them in headers
  1183. */
  1184. speed = linkstat & 0xf;
  1185. linkstat >>= 4;
  1186. linkstat &= 0x1f;
  1187. dd->ipath_lbus_width = linkstat;
  1188. switch (boardrev) {
  1189. case 0:
  1190. case 2:
  1191. case 10:
  1192. case 12:
  1193. minwidth = 16; /* x16 capable boards */
  1194. break;
  1195. default:
  1196. minwidth = 8; /* x8 capable boards */
  1197. break;
  1198. }
  1199. switch (speed) {
  1200. case 1:
  1201. dd->ipath_lbus_speed = 2500; /* Gen1, 2.5GHz */
  1202. break;
  1203. case 2:
  1204. dd->ipath_lbus_speed = 5000; /* Gen1, 5GHz */
  1205. break;
  1206. default: /* not defined, assume gen1 */
  1207. dd->ipath_lbus_speed = 2500;
  1208. break;
  1209. }
  1210. if (linkstat < minwidth)
  1211. ipath_dev_err(dd,
  1212. "PCIe width %u (x%u HCA), performance "
  1213. "reduced\n", linkstat, minwidth);
  1214. else
  1215. ipath_cdbg(VERBOSE, "PCIe speed %u width %u (x%u HCA)\n",
  1216. dd->ipath_lbus_speed, linkstat, minwidth);
  1217. if (speed != 1)
  1218. ipath_dev_err(dd,
  1219. "PCIe linkspeed %u is incorrect; "
  1220. "should be 1 (2500)!\n", speed);
  1221. bail:
  1222. /* fill in string, even on errors */
  1223. snprintf(dd->ipath_lbus_info, sizeof(dd->ipath_lbus_info),
  1224. "PCIe,%uMHz,x%u\n",
  1225. dd->ipath_lbus_speed,
  1226. dd->ipath_lbus_width);
  1227. return;
  1228. }
  1229. /**
  1230. * ipath_setup_7220_config - setup PCIe config related stuff
  1231. * @dd: the infinipath device
  1232. * @pdev: the PCI device
  1233. *
  1234. * The pci_enable_msi() call will fail on systems with MSI quirks
  1235. * such as those with AMD8131, even if the device of interest is not
  1236. * attached to that device, (in the 2.6.13 - 2.6.15 kernels, at least, fixed
  1237. * late in 2.6.16).
  1238. * All that can be done is to edit the kernel source to remove the quirk
  1239. * check until that is fixed.
  1240. * We do not need to call enable_msi() for our HyperTransport chip,
  1241. * even though it uses MSI, and we want to avoid the quirk warning, so
  1242. * So we call enable_msi only for PCIe. If we do end up needing
  1243. * pci_enable_msi at some point in the future for HT, we'll move the
  1244. * call back into the main init_one code.
  1245. * We save the msi lo and hi values, so we can restore them after
  1246. * chip reset (the kernel PCI infrastructure doesn't yet handle that
  1247. * correctly).
  1248. */
  1249. static int ipath_setup_7220_config(struct ipath_devdata *dd,
  1250. struct pci_dev *pdev)
  1251. {
  1252. int pos, ret = -1;
  1253. u32 boardrev;
  1254. dd->ipath_msi_lo = 0; /* used as a flag during reset processing */
  1255. pos = pci_find_capability(pdev, PCI_CAP_ID_MSI);
  1256. if (!strcmp(int_type, "force_msi") || !strcmp(int_type, "auto"))
  1257. ret = pci_enable_msi(pdev);
  1258. if (ret) {
  1259. if (!strcmp(int_type, "force_msi")) {
  1260. ipath_dev_err(dd, "pci_enable_msi failed: %d, "
  1261. "force_msi is on, so not continuing.\n",
  1262. ret);
  1263. return ret;
  1264. }
  1265. ipath_enable_intx(pdev);
  1266. if (!strcmp(int_type, "auto"))
  1267. ipath_dev_err(dd, "pci_enable_msi failed: %d, "
  1268. "falling back to INTx\n", ret);
  1269. } else if (pos) {
  1270. u16 control;
  1271. pci_read_config_dword(pdev, pos + PCI_MSI_ADDRESS_LO,
  1272. &dd->ipath_msi_lo);
  1273. pci_read_config_dword(pdev, pos + PCI_MSI_ADDRESS_HI,
  1274. &dd->ipath_msi_hi);
  1275. pci_read_config_word(pdev, pos + PCI_MSI_FLAGS,
  1276. &control);
  1277. /* now save the data (vector) info */
  1278. pci_read_config_word(pdev,
  1279. pos + ((control & PCI_MSI_FLAGS_64BIT)
  1280. ? PCI_MSI_DATA_64 :
  1281. PCI_MSI_DATA_32),
  1282. &dd->ipath_msi_data);
  1283. } else
  1284. ipath_dev_err(dd, "Can't find MSI capability, "
  1285. "can't save MSI settings for reset\n");
  1286. dd->ipath_irq = pdev->irq;
  1287. /*
  1288. * We save the cachelinesize also, although it doesn't
  1289. * really matter.
  1290. */
  1291. pci_read_config_byte(pdev, PCI_CACHE_LINE_SIZE,
  1292. &dd->ipath_pci_cacheline);
  1293. /*
  1294. * this function called early, ipath_boardrev not set yet. Can't
  1295. * use ipath_read_kreg64() yet, too early in init, so use readq()
  1296. */
  1297. boardrev = (readq(&dd->ipath_kregbase[dd->ipath_kregs->kr_revision])
  1298. >> INFINIPATH_R_BOARDID_SHIFT) & INFINIPATH_R_BOARDID_MASK;
  1299. ipath_7220_pcie_params(dd, boardrev);
  1300. dd->ipath_flags |= IPATH_NODMA_RTAIL | IPATH_HAS_SEND_DMA |
  1301. IPATH_HAS_PBC_CNT | IPATH_HAS_THRESH_UPDATE;
  1302. dd->ipath_pioupd_thresh = 4U; /* set default update threshold */
  1303. return 0;
  1304. }
  1305. static void ipath_init_7220_variables(struct ipath_devdata *dd)
  1306. {
  1307. /*
  1308. * setup the register offsets, since they are different for each
  1309. * chip
  1310. */
  1311. dd->ipath_kregs = &ipath_7220_kregs;
  1312. dd->ipath_cregs = &ipath_7220_cregs;
  1313. /*
  1314. * bits for selecting i2c direction and values,
  1315. * used for I2C serial flash
  1316. */
  1317. dd->ipath_gpio_sda_num = _IPATH_GPIO_SDA_NUM;
  1318. dd->ipath_gpio_scl_num = _IPATH_GPIO_SCL_NUM;
  1319. dd->ipath_gpio_sda = IPATH_GPIO_SDA;
  1320. dd->ipath_gpio_scl = IPATH_GPIO_SCL;
  1321. /*
  1322. * Fill in data for field-values that change in IBA7220.
  1323. * We dynamically specify only the mask for LINKTRAININGSTATE
  1324. * and only the shift for LINKSTATE, as they are the only ones
  1325. * that change. Also precalculate the 3 link states of interest
  1326. * and the combined mask.
  1327. */
  1328. dd->ibcs_ls_shift = IBA7220_IBCS_LINKSTATE_SHIFT;
  1329. dd->ibcs_lts_mask = IBA7220_IBCS_LINKTRAININGSTATE_MASK;
  1330. dd->ibcs_mask = (INFINIPATH_IBCS_LINKSTATE_MASK <<
  1331. dd->ibcs_ls_shift) | dd->ibcs_lts_mask;
  1332. dd->ib_init = (INFINIPATH_IBCS_LT_STATE_LINKUP <<
  1333. INFINIPATH_IBCS_LINKTRAININGSTATE_SHIFT) |
  1334. (INFINIPATH_IBCS_L_STATE_INIT << dd->ibcs_ls_shift);
  1335. dd->ib_arm = (INFINIPATH_IBCS_LT_STATE_LINKUP <<
  1336. INFINIPATH_IBCS_LINKTRAININGSTATE_SHIFT) |
  1337. (INFINIPATH_IBCS_L_STATE_ARM << dd->ibcs_ls_shift);
  1338. dd->ib_active = (INFINIPATH_IBCS_LT_STATE_LINKUP <<
  1339. INFINIPATH_IBCS_LINKTRAININGSTATE_SHIFT) |
  1340. (INFINIPATH_IBCS_L_STATE_ACTIVE << dd->ibcs_ls_shift);
  1341. /*
  1342. * Fill in data for ibcc field-values that change in IBA7220.
  1343. * We dynamically specify only the mask for LINKINITCMD
  1344. * and only the shift for LINKCMD and MAXPKTLEN, as they are
  1345. * the only ones that change.
  1346. */
  1347. dd->ibcc_lic_mask = IBA7220_IBCC_LINKINITCMD_MASK;
  1348. dd->ibcc_lc_shift = IBA7220_IBCC_LINKCMD_SHIFT;
  1349. dd->ibcc_mpl_shift = IBA7220_IBCC_MAXPKTLEN_SHIFT;
  1350. /* Fill in shifts for RcvCtrl. */
  1351. dd->ipath_r_portenable_shift = INFINIPATH_R_PORTENABLE_SHIFT;
  1352. dd->ipath_r_intravail_shift = IBA7220_R_INTRAVAIL_SHIFT;
  1353. dd->ipath_r_tailupd_shift = IBA7220_R_TAILUPD_SHIFT;
  1354. dd->ipath_r_portcfg_shift = IBA7220_R_PORTCFG_SHIFT;
  1355. /* variables for sanity checking interrupt and errors */
  1356. dd->ipath_hwe_bitsextant =
  1357. (INFINIPATH_HWE_RXEMEMPARITYERR_MASK <<
  1358. INFINIPATH_HWE_RXEMEMPARITYERR_SHIFT) |
  1359. (INFINIPATH_HWE_TXEMEMPARITYERR_MASK <<
  1360. INFINIPATH_HWE_TXEMEMPARITYERR_SHIFT) |
  1361. (INFINIPATH_HWE_PCIEMEMPARITYERR_MASK <<
  1362. INFINIPATH_HWE_PCIEMEMPARITYERR_SHIFT) |
  1363. INFINIPATH_HWE_PCIE1PLLFAILED |
  1364. INFINIPATH_HWE_PCIE0PLLFAILED |
  1365. INFINIPATH_HWE_PCIEPOISONEDTLP |
  1366. INFINIPATH_HWE_PCIECPLTIMEOUT |
  1367. INFINIPATH_HWE_PCIEBUSPARITYXTLH |
  1368. INFINIPATH_HWE_PCIEBUSPARITYXADM |
  1369. INFINIPATH_HWE_PCIEBUSPARITYRADM |
  1370. INFINIPATH_HWE_MEMBISTFAILED |
  1371. INFINIPATH_HWE_COREPLL_FBSLIP |
  1372. INFINIPATH_HWE_COREPLL_RFSLIP |
  1373. INFINIPATH_HWE_SERDESPLLFAILED |
  1374. INFINIPATH_HWE_IBCBUSTOSPCPARITYERR |
  1375. INFINIPATH_HWE_IBCBUSFRSPCPARITYERR |
  1376. INFINIPATH_HWE_PCIECPLDATAQUEUEERR |
  1377. INFINIPATH_HWE_PCIECPLHDRQUEUEERR |
  1378. INFINIPATH_HWE_SDMAMEMREADERR |
  1379. INFINIPATH_HWE_CLK_UC_PLLNOTLOCKED |
  1380. INFINIPATH_HWE_PCIESERDESQ0PCLKNOTDETECT |
  1381. INFINIPATH_HWE_PCIESERDESQ1PCLKNOTDETECT |
  1382. INFINIPATH_HWE_PCIESERDESQ2PCLKNOTDETECT |
  1383. INFINIPATH_HWE_PCIESERDESQ3PCLKNOTDETECT |
  1384. INFINIPATH_HWE_DDSRXEQMEMORYPARITYERR |
  1385. INFINIPATH_HWE_IB_UC_MEMORYPARITYERR |
  1386. INFINIPATH_HWE_PCIE_UC_OCT0MEMORYPARITYERR |
  1387. INFINIPATH_HWE_PCIE_UC_OCT1MEMORYPARITYERR;
  1388. dd->ipath_i_bitsextant =
  1389. INFINIPATH_I_SDMAINT | INFINIPATH_I_SDMADISABLED |
  1390. (INFINIPATH_I_RCVURG_MASK << INFINIPATH_I_RCVURG_SHIFT) |
  1391. (INFINIPATH_I_RCVAVAIL_MASK <<
  1392. INFINIPATH_I_RCVAVAIL_SHIFT) |
  1393. INFINIPATH_I_ERROR | INFINIPATH_I_SPIOSENT |
  1394. INFINIPATH_I_SPIOBUFAVAIL | INFINIPATH_I_GPIO |
  1395. INFINIPATH_I_JINT | INFINIPATH_I_SERDESTRIMDONE;
  1396. dd->ipath_e_bitsextant =
  1397. INFINIPATH_E_RFORMATERR | INFINIPATH_E_RVCRC |
  1398. INFINIPATH_E_RICRC | INFINIPATH_E_RMINPKTLEN |
  1399. INFINIPATH_E_RMAXPKTLEN | INFINIPATH_E_RLONGPKTLEN |
  1400. INFINIPATH_E_RSHORTPKTLEN | INFINIPATH_E_RUNEXPCHAR |
  1401. INFINIPATH_E_RUNSUPVL | INFINIPATH_E_REBP |
  1402. INFINIPATH_E_RIBFLOW | INFINIPATH_E_RBADVERSION |
  1403. INFINIPATH_E_RRCVEGRFULL | INFINIPATH_E_RRCVHDRFULL |
  1404. INFINIPATH_E_RBADTID | INFINIPATH_E_RHDRLEN |
  1405. INFINIPATH_E_RHDR | INFINIPATH_E_RIBLOSTLINK |
  1406. INFINIPATH_E_SENDSPECIALTRIGGER |
  1407. INFINIPATH_E_SDMADISABLED | INFINIPATH_E_SMINPKTLEN |
  1408. INFINIPATH_E_SMAXPKTLEN | INFINIPATH_E_SUNDERRUN |
  1409. INFINIPATH_E_SPKTLEN | INFINIPATH_E_SDROPPEDSMPPKT |
  1410. INFINIPATH_E_SDROPPEDDATAPKT |
  1411. INFINIPATH_E_SPIOARMLAUNCH | INFINIPATH_E_SUNEXPERRPKTNUM |
  1412. INFINIPATH_E_SUNSUPVL | INFINIPATH_E_SENDBUFMISUSE |
  1413. INFINIPATH_E_SDMAGENMISMATCH | INFINIPATH_E_SDMAOUTOFBOUND |
  1414. INFINIPATH_E_SDMATAILOUTOFBOUND | INFINIPATH_E_SDMABASE |
  1415. INFINIPATH_E_SDMA1STDESC | INFINIPATH_E_SDMARPYTAG |
  1416. INFINIPATH_E_SDMADWEN | INFINIPATH_E_SDMAMISSINGDW |
  1417. INFINIPATH_E_SDMAUNEXPDATA |
  1418. INFINIPATH_E_IBSTATUSCHANGED | INFINIPATH_E_INVALIDADDR |
  1419. INFINIPATH_E_RESET | INFINIPATH_E_HARDWARE |
  1420. INFINIPATH_E_SDMADESCADDRMISALIGN |
  1421. INFINIPATH_E_INVALIDEEPCMD;
  1422. dd->ipath_i_rcvavail_mask = INFINIPATH_I_RCVAVAIL_MASK;
  1423. dd->ipath_i_rcvurg_mask = INFINIPATH_I_RCVURG_MASK;
  1424. dd->ipath_i_rcvavail_shift = INFINIPATH_I_RCVAVAIL_SHIFT;
  1425. dd->ipath_i_rcvurg_shift = INFINIPATH_I_RCVURG_SHIFT;
  1426. dd->ipath_flags |= IPATH_INTREG_64 | IPATH_HAS_MULT_IB_SPEED
  1427. | IPATH_HAS_LINK_LATENCY;
  1428. /*
  1429. * EEPROM error log 0 is TXE Parity errors. 1 is RXE Parity.
  1430. * 2 is Some Misc, 3 is reserved for future.
  1431. */
  1432. dd->ipath_eep_st_masks[0].hwerrs_to_log =
  1433. INFINIPATH_HWE_TXEMEMPARITYERR_MASK <<
  1434. INFINIPATH_HWE_TXEMEMPARITYERR_SHIFT;
  1435. dd->ipath_eep_st_masks[1].hwerrs_to_log =
  1436. INFINIPATH_HWE_RXEMEMPARITYERR_MASK <<
  1437. INFINIPATH_HWE_RXEMEMPARITYERR_SHIFT;
  1438. dd->ipath_eep_st_masks[2].errs_to_log = INFINIPATH_E_RESET;
  1439. ipath_linkrecovery = 0;
  1440. init_waitqueue_head(&dd->ipath_autoneg_wait);
  1441. INIT_DELAYED_WORK(&dd->ipath_autoneg_work, autoneg_work);
  1442. dd->ipath_link_width_supported = IB_WIDTH_1X | IB_WIDTH_4X;
  1443. dd->ipath_link_speed_supported = IPATH_IB_SDR | IPATH_IB_DDR;
  1444. dd->ipath_link_width_enabled = dd->ipath_link_width_supported;
  1445. dd->ipath_link_speed_enabled = dd->ipath_link_speed_supported;
  1446. /*
  1447. * set the initial values to reasonable default, will be set
  1448. * for real when link is up.
  1449. */
  1450. dd->ipath_link_width_active = IB_WIDTH_4X;
  1451. dd->ipath_link_speed_active = IPATH_IB_SDR;
  1452. dd->delay_mult = rate_to_delay[0][1];
  1453. }
  1454. /*
  1455. * Setup the MSI stuff again after a reset. I'd like to just call
  1456. * pci_enable_msi() and request_irq() again, but when I do that,
  1457. * the MSI enable bit doesn't get set in the command word, and
  1458. * we switch to to a different interrupt vector, which is confusing,
  1459. * so I instead just do it all inline. Perhaps somehow can tie this
  1460. * into the PCIe hotplug support at some point
  1461. * Note, because I'm doing it all here, I don't call pci_disable_msi()
  1462. * or free_irq() at the start of ipath_setup_7220_reset().
  1463. */
  1464. static int ipath_reinit_msi(struct ipath_devdata *dd)
  1465. {
  1466. int ret = 0;
  1467. int pos;
  1468. u16 control;
  1469. if (!dd->ipath_msi_lo) /* Using intX, or init problem */
  1470. goto bail;
  1471. pos = pci_find_capability(dd->pcidev, PCI_CAP_ID_MSI);
  1472. if (!pos) {
  1473. ipath_dev_err(dd, "Can't find MSI capability, "
  1474. "can't restore MSI settings\n");
  1475. goto bail;
  1476. }
  1477. ipath_cdbg(VERBOSE, "Writing msi_lo 0x%x to config offset 0x%x\n",
  1478. dd->ipath_msi_lo, pos + PCI_MSI_ADDRESS_LO);
  1479. pci_write_config_dword(dd->pcidev, pos + PCI_MSI_ADDRESS_LO,
  1480. dd->ipath_msi_lo);
  1481. ipath_cdbg(VERBOSE, "Writing msi_lo 0x%x to config offset 0x%x\n",
  1482. dd->ipath_msi_hi, pos + PCI_MSI_ADDRESS_HI);
  1483. pci_write_config_dword(dd->pcidev, pos + PCI_MSI_ADDRESS_HI,
  1484. dd->ipath_msi_hi);
  1485. pci_read_config_word(dd->pcidev, pos + PCI_MSI_FLAGS, &control);
  1486. if (!(control & PCI_MSI_FLAGS_ENABLE)) {
  1487. ipath_cdbg(VERBOSE, "MSI control at off %x was %x, "
  1488. "setting MSI enable (%x)\n", pos + PCI_MSI_FLAGS,
  1489. control, control | PCI_MSI_FLAGS_ENABLE);
  1490. control |= PCI_MSI_FLAGS_ENABLE;
  1491. pci_write_config_word(dd->pcidev, pos + PCI_MSI_FLAGS,
  1492. control);
  1493. }
  1494. /* now rewrite the data (vector) info */
  1495. pci_write_config_word(dd->pcidev, pos +
  1496. ((control & PCI_MSI_FLAGS_64BIT) ? 12 : 8),
  1497. dd->ipath_msi_data);
  1498. ret = 1;
  1499. bail:
  1500. if (!ret) {
  1501. ipath_dbg("Using INTx, MSI disabled or not configured\n");
  1502. ipath_enable_intx(dd->pcidev);
  1503. ret = 1;
  1504. }
  1505. /*
  1506. * We restore the cachelinesize also, although it doesn't really
  1507. * matter.
  1508. */
  1509. pci_write_config_byte(dd->pcidev, PCI_CACHE_LINE_SIZE,
  1510. dd->ipath_pci_cacheline);
  1511. /* and now set the pci master bit again */
  1512. pci_set_master(dd->pcidev);
  1513. return ret;
  1514. }
  1515. /*
  1516. * This routine sleeps, so it can only be called from user context, not
  1517. * from interrupt context. If we need interrupt context, we can split
  1518. * it into two routines.
  1519. */
  1520. static int ipath_setup_7220_reset(struct ipath_devdata *dd)
  1521. {
  1522. u64 val;
  1523. int i;
  1524. int ret;
  1525. u16 cmdval;
  1526. pci_read_config_word(dd->pcidev, PCI_COMMAND, &cmdval);
  1527. /* Use dev_err so it shows up in logs, etc. */
  1528. ipath_dev_err(dd, "Resetting InfiniPath unit %u\n", dd->ipath_unit);
  1529. /* keep chip from being accessed in a few places */
  1530. dd->ipath_flags &= ~(IPATH_INITTED | IPATH_PRESENT);
  1531. val = dd->ipath_control | INFINIPATH_C_RESET;
  1532. ipath_write_kreg(dd, dd->ipath_kregs->kr_control, val);
  1533. mb();
  1534. for (i = 1; i <= 5; i++) {
  1535. int r;
  1536. /*
  1537. * Allow MBIST, etc. to complete; longer on each retry.
  1538. * We sometimes get machine checks from bus timeout if no
  1539. * response, so for now, make it *really* long.
  1540. */
  1541. msleep(1000 + (1 + i) * 2000);
  1542. r = pci_write_config_dword(dd->pcidev, PCI_BASE_ADDRESS_0,
  1543. dd->ipath_pcibar0);
  1544. if (r)
  1545. ipath_dev_err(dd, "rewrite of BAR0 failed: %d\n", r);
  1546. r = pci_write_config_dword(dd->pcidev, PCI_BASE_ADDRESS_1,
  1547. dd->ipath_pcibar1);
  1548. if (r)
  1549. ipath_dev_err(dd, "rewrite of BAR1 failed: %d\n", r);
  1550. /* now re-enable memory access */
  1551. pci_write_config_word(dd->pcidev, PCI_COMMAND, cmdval);
  1552. r = pci_enable_device(dd->pcidev);
  1553. if (r)
  1554. ipath_dev_err(dd, "pci_enable_device failed after "
  1555. "reset: %d\n", r);
  1556. /*
  1557. * whether it fully enabled or not, mark as present,
  1558. * again (but not INITTED)
  1559. */
  1560. dd->ipath_flags |= IPATH_PRESENT;
  1561. val = ipath_read_kreg64(dd, dd->ipath_kregs->kr_revision);
  1562. if (val == dd->ipath_revision) {
  1563. ipath_cdbg(VERBOSE, "Got matching revision "
  1564. "register %llx on try %d\n",
  1565. (unsigned long long) val, i);
  1566. ret = ipath_reinit_msi(dd);
  1567. goto bail;
  1568. }
  1569. /* Probably getting -1 back */
  1570. ipath_dbg("Didn't get expected revision register, "
  1571. "got %llx, try %d\n", (unsigned long long) val,
  1572. i + 1);
  1573. }
  1574. ret = 0; /* failed */
  1575. bail:
  1576. if (ret)
  1577. ipath_7220_pcie_params(dd, dd->ipath_boardrev);
  1578. return ret;
  1579. }
  1580. /**
  1581. * ipath_7220_put_tid - write a TID to the chip
  1582. * @dd: the infinipath device
  1583. * @tidptr: pointer to the expected TID (in chip) to udpate
  1584. * @tidtype: 0 for eager, 1 for expected
  1585. * @pa: physical address of in memory buffer; ipath_tidinvalid if freeing
  1586. *
  1587. * This exists as a separate routine to allow for selection of the
  1588. * appropriate "flavor". The static calls in cleanup just use the
  1589. * revision-agnostic form, as they are not performance critical.
  1590. */
  1591. static void ipath_7220_put_tid(struct ipath_devdata *dd, u64 __iomem *tidptr,
  1592. u32 type, unsigned long pa)
  1593. {
  1594. if (pa != dd->ipath_tidinvalid) {
  1595. u64 chippa = pa >> IBA7220_TID_PA_SHIFT;
  1596. /* paranoia checks */
  1597. if (pa != (chippa << IBA7220_TID_PA_SHIFT)) {
  1598. dev_info(&dd->pcidev->dev, "BUG: physaddr %lx "
  1599. "not 2KB aligned!\n", pa);
  1600. return;
  1601. }
  1602. if (chippa >= (1UL << IBA7220_TID_SZ_SHIFT)) {
  1603. ipath_dev_err(dd,
  1604. "BUG: Physical page address 0x%lx "
  1605. "larger than supported\n", pa);
  1606. return;
  1607. }
  1608. if (type == RCVHQ_RCV_TYPE_EAGER)
  1609. chippa |= dd->ipath_tidtemplate;
  1610. else /* for now, always full 4KB page */
  1611. chippa |= IBA7220_TID_SZ_4K;
  1612. writeq(chippa, tidptr);
  1613. } else
  1614. writeq(pa, tidptr);
  1615. mmiowb();
  1616. }
  1617. /**
  1618. * ipath_7220_clear_tid - clear all TID entries for a port, expected and eager
  1619. * @dd: the infinipath device
  1620. * @port: the port
  1621. *
  1622. * clear all TID entries for a port, expected and eager.
  1623. * Used from ipath_close(). On this chip, TIDs are only 32 bits,
  1624. * not 64, but they are still on 64 bit boundaries, so tidbase
  1625. * is declared as u64 * for the pointer math, even though we write 32 bits
  1626. */
  1627. static void ipath_7220_clear_tids(struct ipath_devdata *dd, unsigned port)
  1628. {
  1629. u64 __iomem *tidbase;
  1630. unsigned long tidinv;
  1631. int i;
  1632. if (!dd->ipath_kregbase)
  1633. return;
  1634. ipath_cdbg(VERBOSE, "Invalidate TIDs for port %u\n", port);
  1635. tidinv = dd->ipath_tidinvalid;
  1636. tidbase = (u64 __iomem *)
  1637. ((char __iomem *)(dd->ipath_kregbase) +
  1638. dd->ipath_rcvtidbase +
  1639. port * dd->ipath_rcvtidcnt * sizeof(*tidbase));
  1640. for (i = 0; i < dd->ipath_rcvtidcnt; i++)
  1641. ipath_7220_put_tid(dd, &tidbase[i], RCVHQ_RCV_TYPE_EXPECTED,
  1642. tidinv);
  1643. tidbase = (u64 __iomem *)
  1644. ((char __iomem *)(dd->ipath_kregbase) +
  1645. dd->ipath_rcvegrbase + port_egrtid_idx(dd, port)
  1646. * sizeof(*tidbase));
  1647. for (i = port ? dd->ipath_rcvegrcnt : dd->ipath_p0_rcvegrcnt; i; i--)
  1648. ipath_7220_put_tid(dd, &tidbase[i-1], RCVHQ_RCV_TYPE_EAGER,
  1649. tidinv);
  1650. }
  1651. /**
  1652. * ipath_7220_tidtemplate - setup constants for TID updates
  1653. * @dd: the infinipath device
  1654. *
  1655. * We setup stuff that we use a lot, to avoid calculating each time
  1656. */
  1657. static void ipath_7220_tidtemplate(struct ipath_devdata *dd)
  1658. {
  1659. /* For now, we always allocate 4KB buffers (at init) so we can
  1660. * receive max size packets. We may want a module parameter to
  1661. * specify 2KB or 4KB and/or make be per port instead of per device
  1662. * for those who want to reduce memory footprint. Note that the
  1663. * ipath_rcvhdrentsize size must be large enough to hold the largest
  1664. * IB header (currently 96 bytes) that we expect to handle (plus of
  1665. * course the 2 dwords of RHF).
  1666. */
  1667. if (dd->ipath_rcvegrbufsize == 2048)
  1668. dd->ipath_tidtemplate = IBA7220_TID_SZ_2K;
  1669. else if (dd->ipath_rcvegrbufsize == 4096)
  1670. dd->ipath_tidtemplate = IBA7220_TID_SZ_4K;
  1671. else {
  1672. dev_info(&dd->pcidev->dev, "BUG: unsupported egrbufsize "
  1673. "%u, using %u\n", dd->ipath_rcvegrbufsize,
  1674. 4096);
  1675. dd->ipath_tidtemplate = IBA7220_TID_SZ_4K;
  1676. }
  1677. dd->ipath_tidinvalid = 0;
  1678. }
  1679. static int ipath_7220_early_init(struct ipath_devdata *dd)
  1680. {
  1681. u32 i, s;
  1682. if (strcmp(int_type, "auto") &&
  1683. strcmp(int_type, "force_msi") &&
  1684. strcmp(int_type, "force_intx")) {
  1685. ipath_dev_err(dd, "Invalid interrupt_type: '%s', expecting "
  1686. "auto, force_msi or force_intx\n", int_type);
  1687. return -EINVAL;
  1688. }
  1689. /*
  1690. * Control[4] has been added to change the arbitration within
  1691. * the SDMA engine between favoring data fetches over descriptor
  1692. * fetches. ipath_sdma_fetch_arb==0 gives data fetches priority.
  1693. */
  1694. if (ipath_sdma_fetch_arb && (dd->ipath_minrev > 1))
  1695. dd->ipath_control |= 1<<4;
  1696. dd->ipath_flags |= IPATH_4BYTE_TID;
  1697. /*
  1698. * For openfabrics, we need to be able to handle an IB header of
  1699. * 24 dwords. HT chip has arbitrary sized receive buffers, so we
  1700. * made them the same size as the PIO buffers. This chip does not
  1701. * handle arbitrary size buffers, so we need the header large enough
  1702. * to handle largest IB header, but still have room for a 2KB MTU
  1703. * standard IB packet.
  1704. */
  1705. dd->ipath_rcvhdrentsize = 24;
  1706. dd->ipath_rcvhdrsize = IPATH_DFLT_RCVHDRSIZE;
  1707. dd->ipath_rhf_offset =
  1708. dd->ipath_rcvhdrentsize - sizeof(u64) / sizeof(u32);
  1709. dd->ipath_rcvegrbufsize = ipath_mtu4096 ? 4096 : 2048;
  1710. /*
  1711. * the min() check here is currently a nop, but it may not always
  1712. * be, depending on just how we do ipath_rcvegrbufsize
  1713. */
  1714. dd->ipath_ibmaxlen = min(ipath_mtu4096 ? dd->ipath_piosize4k :
  1715. dd->ipath_piosize2k,
  1716. dd->ipath_rcvegrbufsize +
  1717. (dd->ipath_rcvhdrentsize << 2));
  1718. dd->ipath_init_ibmaxlen = dd->ipath_ibmaxlen;
  1719. ipath_7220_config_jint(dd, INFINIPATH_JINT_DEFAULT_IDLE_TICKS,
  1720. INFINIPATH_JINT_DEFAULT_MAX_PACKETS);
  1721. if (dd->ipath_boardrev) /* no eeprom on emulator */
  1722. ipath_get_eeprom_info(dd);
  1723. /* start of code to check and print procmon */
  1724. s = ipath_read_kreg32(dd, IPATH_KREG_OFFSET(ProcMon));
  1725. s &= ~(1U<<31); /* clear done bit */
  1726. s |= 1U<<14; /* clear counter (write 1 to clear) */
  1727. ipath_write_kreg(dd, IPATH_KREG_OFFSET(ProcMon), s);
  1728. /* make sure clear_counter low long enough before start */
  1729. ipath_read_kreg32(dd, dd->ipath_kregs->kr_scratch);
  1730. ipath_read_kreg32(dd, dd->ipath_kregs->kr_scratch);
  1731. s &= ~(1U<<14); /* allow counter to count (before starting) */
  1732. ipath_write_kreg(dd, IPATH_KREG_OFFSET(ProcMon), s);
  1733. ipath_read_kreg32(dd, dd->ipath_kregs->kr_scratch);
  1734. ipath_read_kreg32(dd, dd->ipath_kregs->kr_scratch);
  1735. s = ipath_read_kreg32(dd, IPATH_KREG_OFFSET(ProcMon));
  1736. s |= 1U<<15; /* start the counter */
  1737. s &= ~(1U<<31); /* clear done bit */
  1738. s &= ~0x7ffU; /* clear frequency bits */
  1739. s |= 0xe29; /* set frequency bits, in case cleared */
  1740. ipath_write_kreg(dd, IPATH_KREG_OFFSET(ProcMon), s);
  1741. s = 0;
  1742. for (i = 500; i > 0 && !(s&(1ULL<<31)); i--) {
  1743. ipath_read_kreg32(dd, dd->ipath_kregs->kr_scratch);
  1744. s = ipath_read_kreg32(dd, IPATH_KREG_OFFSET(ProcMon));
  1745. }
  1746. if (!(s&(1U<<31)))
  1747. ipath_dev_err(dd, "ProcMon register not valid: 0x%x\n", s);
  1748. else
  1749. ipath_dbg("ProcMon=0x%x, count=0x%x\n", s, (s>>16)&0x1ff);
  1750. return 0;
  1751. }
  1752. /**
  1753. * ipath_init_7220_get_base_info - set chip-specific flags for user code
  1754. * @pd: the infinipath port
  1755. * @kbase: ipath_base_info pointer
  1756. *
  1757. * We set the PCIE flag because the lower bandwidth on PCIe vs
  1758. * HyperTransport can affect some user packet algorithims.
  1759. */
  1760. static int ipath_7220_get_base_info(struct ipath_portdata *pd, void *kbase)
  1761. {
  1762. struct ipath_base_info *kinfo = kbase;
  1763. kinfo->spi_runtime_flags |=
  1764. IPATH_RUNTIME_PCIE | IPATH_RUNTIME_NODMA_RTAIL |
  1765. IPATH_RUNTIME_SDMA;
  1766. return 0;
  1767. }
  1768. static void ipath_7220_free_irq(struct ipath_devdata *dd)
  1769. {
  1770. free_irq(dd->ipath_irq, dd);
  1771. dd->ipath_irq = 0;
  1772. }
  1773. static struct ipath_message_header *
  1774. ipath_7220_get_msgheader(struct ipath_devdata *dd, __le32 *rhf_addr)
  1775. {
  1776. u32 offset = ipath_hdrget_offset(rhf_addr);
  1777. return (struct ipath_message_header *)
  1778. (rhf_addr - dd->ipath_rhf_offset + offset);
  1779. }
  1780. static void ipath_7220_config_ports(struct ipath_devdata *dd, ushort cfgports)
  1781. {
  1782. u32 nchipports;
  1783. nchipports = ipath_read_kreg32(dd, dd->ipath_kregs->kr_portcnt);
  1784. if (!cfgports) {
  1785. int ncpus = num_online_cpus();
  1786. if (ncpus <= 4)
  1787. dd->ipath_portcnt = 5;
  1788. else if (ncpus <= 8)
  1789. dd->ipath_portcnt = 9;
  1790. if (dd->ipath_portcnt)
  1791. ipath_dbg("Auto-configured for %u ports, %d cpus "
  1792. "online\n", dd->ipath_portcnt, ncpus);
  1793. } else if (cfgports <= nchipports)
  1794. dd->ipath_portcnt = cfgports;
  1795. if (!dd->ipath_portcnt) /* none of the above, set to max */
  1796. dd->ipath_portcnt = nchipports;
  1797. /*
  1798. * chip can be configured for 5, 9, or 17 ports, and choice
  1799. * affects number of eager TIDs per port (1K, 2K, 4K).
  1800. */
  1801. if (dd->ipath_portcnt > 9)
  1802. dd->ipath_rcvctrl |= 2ULL << IBA7220_R_PORTCFG_SHIFT;
  1803. else if (dd->ipath_portcnt > 5)
  1804. dd->ipath_rcvctrl |= 1ULL << IBA7220_R_PORTCFG_SHIFT;
  1805. /* else configure for default 5 receive ports */
  1806. ipath_write_kreg(dd, dd->ipath_kregs->kr_rcvctrl,
  1807. dd->ipath_rcvctrl);
  1808. dd->ipath_p0_rcvegrcnt = 2048; /* always */
  1809. if (dd->ipath_flags & IPATH_HAS_SEND_DMA)
  1810. dd->ipath_pioreserved = 3; /* kpiobufs used for PIO */
  1811. }
  1812. static int ipath_7220_get_ib_cfg(struct ipath_devdata *dd, int which)
  1813. {
  1814. int lsb, ret = 0;
  1815. u64 maskr; /* right-justified mask */
  1816. switch (which) {
  1817. case IPATH_IB_CFG_HRTBT: /* Get Heartbeat off/enable/auto */
  1818. lsb = IBA7220_IBC_HRTBT_SHIFT;
  1819. maskr = IBA7220_IBC_HRTBT_MASK;
  1820. break;
  1821. case IPATH_IB_CFG_LWID_ENB: /* Get allowed Link-width */
  1822. ret = dd->ipath_link_width_enabled;
  1823. goto done;
  1824. case IPATH_IB_CFG_LWID: /* Get currently active Link-width */
  1825. ret = dd->ipath_link_width_active;
  1826. goto done;
  1827. case IPATH_IB_CFG_SPD_ENB: /* Get allowed Link speeds */
  1828. ret = dd->ipath_link_speed_enabled;
  1829. goto done;
  1830. case IPATH_IB_CFG_SPD: /* Get current Link spd */
  1831. ret = dd->ipath_link_speed_active;
  1832. goto done;
  1833. case IPATH_IB_CFG_RXPOL_ENB: /* Get Auto-RX-polarity enable */
  1834. lsb = IBA7220_IBC_RXPOL_SHIFT;
  1835. maskr = IBA7220_IBC_RXPOL_MASK;
  1836. break;
  1837. case IPATH_IB_CFG_LREV_ENB: /* Get Auto-Lane-reversal enable */
  1838. lsb = IBA7220_IBC_LREV_SHIFT;
  1839. maskr = IBA7220_IBC_LREV_MASK;
  1840. break;
  1841. case IPATH_IB_CFG_LINKLATENCY:
  1842. ret = ipath_read_kreg64(dd, dd->ipath_kregs->kr_ibcddrstatus)
  1843. & IBA7220_DDRSTAT_LINKLAT_MASK;
  1844. goto done;
  1845. default:
  1846. ret = -ENOTSUPP;
  1847. goto done;
  1848. }
  1849. ret = (int)((dd->ipath_ibcddrctrl >> lsb) & maskr);
  1850. done:
  1851. return ret;
  1852. }
  1853. static int ipath_7220_set_ib_cfg(struct ipath_devdata *dd, int which, u32 val)
  1854. {
  1855. int lsb, ret = 0, setforce = 0;
  1856. u64 maskr; /* right-justified mask */
  1857. switch (which) {
  1858. case IPATH_IB_CFG_LIDLMC:
  1859. /*
  1860. * Set LID and LMC. Combined to avoid possible hazard
  1861. * caller puts LMC in 16MSbits, DLID in 16LSbits of val
  1862. */
  1863. lsb = IBA7220_IBC_DLIDLMC_SHIFT;
  1864. maskr = IBA7220_IBC_DLIDLMC_MASK;
  1865. break;
  1866. case IPATH_IB_CFG_HRTBT: /* set Heartbeat off/enable/auto */
  1867. if (val & IPATH_IB_HRTBT_ON &&
  1868. (dd->ipath_flags & IPATH_NO_HRTBT))
  1869. goto bail;
  1870. lsb = IBA7220_IBC_HRTBT_SHIFT;
  1871. maskr = IBA7220_IBC_HRTBT_MASK;
  1872. break;
  1873. case IPATH_IB_CFG_LWID_ENB: /* set allowed Link-width */
  1874. /*
  1875. * As with speed, only write the actual register if
  1876. * the link is currently down, otherwise takes effect
  1877. * on next link change.
  1878. */
  1879. dd->ipath_link_width_enabled = val;
  1880. if ((dd->ipath_flags & (IPATH_LINKDOWN|IPATH_LINKINIT)) !=
  1881. IPATH_LINKDOWN)
  1882. goto bail;
  1883. /*
  1884. * We set the IPATH_IB_FORCE_NOTIFY bit so updown
  1885. * will get called because we want update
  1886. * link_width_active, and the change may not take
  1887. * effect for some time (if we are in POLL), so this
  1888. * flag will force the updown routine to be called
  1889. * on the next ibstatuschange down interrupt, even
  1890. * if it's not an down->up transition.
  1891. */
  1892. val--; /* convert from IB to chip */
  1893. maskr = IBA7220_IBC_WIDTH_MASK;
  1894. lsb = IBA7220_IBC_WIDTH_SHIFT;
  1895. setforce = 1;
  1896. dd->ipath_flags |= IPATH_IB_FORCE_NOTIFY;
  1897. break;
  1898. case IPATH_IB_CFG_SPD_ENB: /* set allowed Link speeds */
  1899. /*
  1900. * If we turn off IB1.2, need to preset SerDes defaults,
  1901. * but not right now. Set a flag for the next time
  1902. * we command the link down. As with width, only write the
  1903. * actual register if the link is currently down, otherwise
  1904. * takes effect on next link change. Since setting is being
  1905. * explictly requested (via MAD or sysfs), clear autoneg
  1906. * failure status if speed autoneg is enabled.
  1907. */
  1908. dd->ipath_link_speed_enabled = val;
  1909. if (dd->ipath_ibcddrctrl & IBA7220_IBC_IBTA_1_2_MASK &&
  1910. !(val & (val - 1)))
  1911. dd->ipath_presets_needed = 1;
  1912. if ((dd->ipath_flags & (IPATH_LINKDOWN|IPATH_LINKINIT)) !=
  1913. IPATH_LINKDOWN)
  1914. goto bail;
  1915. /*
  1916. * We set the IPATH_IB_FORCE_NOTIFY bit so updown
  1917. * will get called because we want update
  1918. * link_speed_active, and the change may not take
  1919. * effect for some time (if we are in POLL), so this
  1920. * flag will force the updown routine to be called
  1921. * on the next ibstatuschange down interrupt, even
  1922. * if it's not an down->up transition. When setting
  1923. * speed autoneg, clear AUTONEG_FAILED.
  1924. */
  1925. if (val == (IPATH_IB_SDR | IPATH_IB_DDR)) {
  1926. val = IBA7220_IBC_SPEED_AUTONEG_MASK |
  1927. IBA7220_IBC_IBTA_1_2_MASK;
  1928. dd->ipath_flags &= ~IPATH_IB_AUTONEG_FAILED;
  1929. } else
  1930. val = val == IPATH_IB_DDR ? IBA7220_IBC_SPEED_DDR
  1931. : IBA7220_IBC_SPEED_SDR;
  1932. maskr = IBA7220_IBC_SPEED_AUTONEG_MASK |
  1933. IBA7220_IBC_IBTA_1_2_MASK;
  1934. lsb = 0; /* speed bits are low bits */
  1935. setforce = 1;
  1936. break;
  1937. case IPATH_IB_CFG_RXPOL_ENB: /* set Auto-RX-polarity enable */
  1938. lsb = IBA7220_IBC_RXPOL_SHIFT;
  1939. maskr = IBA7220_IBC_RXPOL_MASK;
  1940. break;
  1941. case IPATH_IB_CFG_LREV_ENB: /* set Auto-Lane-reversal enable */
  1942. lsb = IBA7220_IBC_LREV_SHIFT;
  1943. maskr = IBA7220_IBC_LREV_MASK;
  1944. break;
  1945. default:
  1946. ret = -ENOTSUPP;
  1947. goto bail;
  1948. }
  1949. dd->ipath_ibcddrctrl &= ~(maskr << lsb);
  1950. dd->ipath_ibcddrctrl |= (((u64) val & maskr) << lsb);
  1951. ipath_write_kreg(dd, dd->ipath_kregs->kr_ibcddrctrl,
  1952. dd->ipath_ibcddrctrl);
  1953. if (setforce)
  1954. dd->ipath_flags |= IPATH_IB_FORCE_NOTIFY;
  1955. bail:
  1956. return ret;
  1957. }
  1958. static void ipath_7220_read_counters(struct ipath_devdata *dd,
  1959. struct infinipath_counters *cntrs)
  1960. {
  1961. u64 *counters = (u64 *) cntrs;
  1962. int i;
  1963. for (i = 0; i < sizeof(*cntrs) / sizeof(u64); i++)
  1964. counters[i] = ipath_snap_cntr(dd, i);
  1965. }
  1966. /* if we are using MSI, try to fallback to INTx */
  1967. static int ipath_7220_intr_fallback(struct ipath_devdata *dd)
  1968. {
  1969. if (dd->ipath_msi_lo) {
  1970. dev_info(&dd->pcidev->dev, "MSI interrupt not detected,"
  1971. " trying INTx interrupts\n");
  1972. ipath_7220_nomsi(dd);
  1973. ipath_enable_intx(dd->pcidev);
  1974. /*
  1975. * some newer kernels require free_irq before disable_msi,
  1976. * and irq can be changed during disable and intx enable
  1977. * and we need to therefore use the pcidev->irq value,
  1978. * not our saved MSI value.
  1979. */
  1980. dd->ipath_irq = dd->pcidev->irq;
  1981. if (request_irq(dd->ipath_irq, ipath_intr, IRQF_SHARED,
  1982. IPATH_DRV_NAME, dd))
  1983. ipath_dev_err(dd,
  1984. "Could not re-request_irq for INTx\n");
  1985. return 1;
  1986. }
  1987. return 0;
  1988. }
  1989. /*
  1990. * reset the XGXS (between serdes and IBC). Slightly less intrusive
  1991. * than resetting the IBC or external link state, and useful in some
  1992. * cases to cause some retraining. To do this right, we reset IBC
  1993. * as well.
  1994. */
  1995. static void ipath_7220_xgxs_reset(struct ipath_devdata *dd)
  1996. {
  1997. u64 val, prev_val;
  1998. prev_val = ipath_read_kreg64(dd, dd->ipath_kregs->kr_xgxsconfig);
  1999. val = prev_val | INFINIPATH_XGXS_RESET;
  2000. prev_val &= ~INFINIPATH_XGXS_RESET; /* be sure */
  2001. ipath_write_kreg(dd, dd->ipath_kregs->kr_control,
  2002. dd->ipath_control & ~INFINIPATH_C_LINKENABLE);
  2003. ipath_write_kreg(dd, dd->ipath_kregs->kr_xgxsconfig, val);
  2004. ipath_read_kreg32(dd, dd->ipath_kregs->kr_scratch);
  2005. ipath_write_kreg(dd, dd->ipath_kregs->kr_xgxsconfig, prev_val);
  2006. ipath_write_kreg(dd, dd->ipath_kregs->kr_control,
  2007. dd->ipath_control);
  2008. }
  2009. /* Still needs cleanup, too much hardwired stuff */
  2010. static void autoneg_send(struct ipath_devdata *dd,
  2011. u32 *hdr, u32 dcnt, u32 *data)
  2012. {
  2013. int i;
  2014. u64 cnt;
  2015. u32 __iomem *piobuf;
  2016. u32 pnum;
  2017. i = 0;
  2018. cnt = 7 + dcnt + 1; /* 7 dword header, dword data, icrc */
  2019. while (!(piobuf = ipath_getpiobuf(dd, cnt, &pnum))) {
  2020. if (i++ > 15) {
  2021. ipath_dbg("Couldn't get pio buffer for send\n");
  2022. return;
  2023. }
  2024. udelay(2);
  2025. }
  2026. if (dd->ipath_flags&IPATH_HAS_PBC_CNT)
  2027. cnt |= 0x80000000UL<<32; /* mark as VL15 */
  2028. writeq(cnt, piobuf);
  2029. ipath_flush_wc();
  2030. __iowrite32_copy(piobuf + 2, hdr, 7);
  2031. __iowrite32_copy(piobuf + 9, data, dcnt);
  2032. ipath_flush_wc();
  2033. }
  2034. /*
  2035. * _start packet gets sent twice at start, _done gets sent twice at end
  2036. */
  2037. static void ipath_autoneg_send(struct ipath_devdata *dd, int which)
  2038. {
  2039. static u32 swapped;
  2040. u32 dw, i, hcnt, dcnt, *data;
  2041. static u32 hdr[7] = { 0xf002ffff, 0x48ffff, 0x6400abba };
  2042. static u32 madpayload_start[0x40] = {
  2043. 0x1810103, 0x1, 0x0, 0x0, 0x2c90000, 0x2c9, 0x0, 0x0,
  2044. 0xffffffff, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
  2045. 0x1, 0x1388, 0x15e, 0x1, /* rest 0's */
  2046. };
  2047. static u32 madpayload_done[0x40] = {
  2048. 0x1810103, 0x1, 0x0, 0x0, 0x2c90000, 0x2c9, 0x0, 0x0,
  2049. 0xffffffff, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
  2050. 0x40000001, 0x1388, 0x15e, /* rest 0's */
  2051. };
  2052. dcnt = ARRAY_SIZE(madpayload_start);
  2053. hcnt = ARRAY_SIZE(hdr);
  2054. if (!swapped) {
  2055. /* for maintainability, do it at runtime */
  2056. for (i = 0; i < hcnt; i++) {
  2057. dw = (__force u32) cpu_to_be32(hdr[i]);
  2058. hdr[i] = dw;
  2059. }
  2060. for (i = 0; i < dcnt; i++) {
  2061. dw = (__force u32) cpu_to_be32(madpayload_start[i]);
  2062. madpayload_start[i] = dw;
  2063. dw = (__force u32) cpu_to_be32(madpayload_done[i]);
  2064. madpayload_done[i] = dw;
  2065. }
  2066. swapped = 1;
  2067. }
  2068. data = which ? madpayload_done : madpayload_start;
  2069. ipath_cdbg(PKT, "Sending %s special MADs\n", which?"done":"start");
  2070. autoneg_send(dd, hdr, dcnt, data);
  2071. ipath_read_kreg64(dd, dd->ipath_kregs->kr_scratch);
  2072. udelay(2);
  2073. autoneg_send(dd, hdr, dcnt, data);
  2074. ipath_read_kreg64(dd, dd->ipath_kregs->kr_scratch);
  2075. udelay(2);
  2076. }
  2077. /*
  2078. * Do the absolute minimum to cause an IB speed change, and make it
  2079. * ready, but don't actually trigger the change. The caller will
  2080. * do that when ready (if link is in Polling training state, it will
  2081. * happen immediately, otherwise when link next goes down)
  2082. *
  2083. * This routine should only be used as part of the DDR autonegotation
  2084. * code for devices that are not compliant with IB 1.2 (or code that
  2085. * fixes things up for same).
  2086. *
  2087. * When link has gone down, and autoneg enabled, or autoneg has
  2088. * failed and we give up until next time we set both speeds, and
  2089. * then we want IBTA enabled as well as "use max enabled speed.
  2090. */
  2091. static void set_speed_fast(struct ipath_devdata *dd, u32 speed)
  2092. {
  2093. dd->ipath_ibcddrctrl &= ~(IBA7220_IBC_SPEED_AUTONEG_MASK |
  2094. IBA7220_IBC_IBTA_1_2_MASK |
  2095. (IBA7220_IBC_WIDTH_MASK << IBA7220_IBC_WIDTH_SHIFT));
  2096. if (speed == (IPATH_IB_SDR | IPATH_IB_DDR))
  2097. dd->ipath_ibcddrctrl |= IBA7220_IBC_SPEED_AUTONEG_MASK |
  2098. IBA7220_IBC_IBTA_1_2_MASK;
  2099. else
  2100. dd->ipath_ibcddrctrl |= speed == IPATH_IB_DDR ?
  2101. IBA7220_IBC_SPEED_DDR : IBA7220_IBC_SPEED_SDR;
  2102. /*
  2103. * Convert from IB-style 1 = 1x, 2 = 4x, 3 = auto
  2104. * to chip-centric 0 = 1x, 1 = 4x, 2 = auto
  2105. */
  2106. dd->ipath_ibcddrctrl |= (u64)(dd->ipath_link_width_enabled - 1) <<
  2107. IBA7220_IBC_WIDTH_SHIFT;
  2108. ipath_write_kreg(dd, dd->ipath_kregs->kr_ibcddrctrl,
  2109. dd->ipath_ibcddrctrl);
  2110. ipath_cdbg(VERBOSE, "setup for IB speed (%x) done\n", speed);
  2111. }
  2112. /*
  2113. * this routine is only used when we are not talking to another
  2114. * IB 1.2-compliant device that we think can do DDR.
  2115. * (This includes all existing switch chips as of Oct 2007.)
  2116. * 1.2-compliant devices go directly to DDR prior to reaching INIT
  2117. */
  2118. static void try_auto_neg(struct ipath_devdata *dd)
  2119. {
  2120. /*
  2121. * required for older non-IB1.2 DDR switches. Newer
  2122. * non-IB-compliant switches don't need it, but so far,
  2123. * aren't bothered by it either. "Magic constant"
  2124. */
  2125. ipath_write_kreg(dd, IPATH_KREG_OFFSET(IBNCModeCtrl),
  2126. 0x3b9dc07);
  2127. dd->ipath_flags |= IPATH_IB_AUTONEG_INPROG;
  2128. ipath_autoneg_send(dd, 0);
  2129. set_speed_fast(dd, IPATH_IB_DDR);
  2130. ipath_toggle_rclkrls(dd);
  2131. /* 2 msec is minimum length of a poll cycle */
  2132. schedule_delayed_work(&dd->ipath_autoneg_work,
  2133. msecs_to_jiffies(2));
  2134. }
  2135. static int ipath_7220_ib_updown(struct ipath_devdata *dd, int ibup, u64 ibcs)
  2136. {
  2137. int ret = 0, symadj = 0;
  2138. u32 ltstate = ipath_ib_linkstate(dd, ibcs);
  2139. dd->ipath_link_width_active =
  2140. ((ibcs >> IBA7220_IBCS_LINKWIDTH_SHIFT) & 1) ?
  2141. IB_WIDTH_4X : IB_WIDTH_1X;
  2142. dd->ipath_link_speed_active =
  2143. ((ibcs >> IBA7220_IBCS_LINKSPEED_SHIFT) & 1) ?
  2144. IPATH_IB_DDR : IPATH_IB_SDR;
  2145. if (!ibup) {
  2146. /*
  2147. * when link goes down we don't want aeq running, so it
  2148. * won't't interfere with IBC training, etc., and we need
  2149. * to go back to the static SerDes preset values
  2150. */
  2151. if (dd->ipath_x1_fix_tries &&
  2152. ltstate <= INFINIPATH_IBCS_LT_STATE_SLEEPQUIET &&
  2153. ltstate != INFINIPATH_IBCS_LT_STATE_LINKUP)
  2154. dd->ipath_x1_fix_tries = 0;
  2155. if (!(dd->ipath_flags & (IPATH_IB_AUTONEG_FAILED |
  2156. IPATH_IB_AUTONEG_INPROG)))
  2157. set_speed_fast(dd, dd->ipath_link_speed_enabled);
  2158. if (!(dd->ipath_flags & IPATH_IB_AUTONEG_INPROG)) {
  2159. ipath_cdbg(VERBOSE, "Setting RXEQ defaults\n");
  2160. ipath_sd7220_presets(dd);
  2161. }
  2162. /* this might better in ipath_sd7220_presets() */
  2163. ipath_set_relock_poll(dd, ibup);
  2164. } else {
  2165. if (ipath_compat_ddr_negotiate &&
  2166. !(dd->ipath_flags & (IPATH_IB_AUTONEG_FAILED |
  2167. IPATH_IB_AUTONEG_INPROG)) &&
  2168. dd->ipath_link_speed_active == IPATH_IB_SDR &&
  2169. (dd->ipath_link_speed_enabled &
  2170. (IPATH_IB_DDR | IPATH_IB_SDR)) ==
  2171. (IPATH_IB_DDR | IPATH_IB_SDR) &&
  2172. dd->ipath_autoneg_tries < IPATH_AUTONEG_TRIES) {
  2173. /* we are SDR, and DDR auto-negotiation enabled */
  2174. ++dd->ipath_autoneg_tries;
  2175. ipath_dbg("DDR negotiation try, %u/%u\n",
  2176. dd->ipath_autoneg_tries,
  2177. IPATH_AUTONEG_TRIES);
  2178. if (!dd->ibdeltainprog) {
  2179. dd->ibdeltainprog = 1;
  2180. dd->ibsymsnap = ipath_read_creg32(dd,
  2181. dd->ipath_cregs->cr_ibsymbolerrcnt);
  2182. dd->iblnkerrsnap = ipath_read_creg32(dd,
  2183. dd->ipath_cregs->cr_iblinkerrrecovcnt);
  2184. }
  2185. try_auto_neg(dd);
  2186. ret = 1; /* no other IB status change processing */
  2187. } else if ((dd->ipath_flags & IPATH_IB_AUTONEG_INPROG)
  2188. && dd->ipath_link_speed_active == IPATH_IB_SDR) {
  2189. ipath_autoneg_send(dd, 1);
  2190. set_speed_fast(dd, IPATH_IB_DDR);
  2191. udelay(2);
  2192. ipath_toggle_rclkrls(dd);
  2193. ret = 1; /* no other IB status change processing */
  2194. } else {
  2195. if ((dd->ipath_flags & IPATH_IB_AUTONEG_INPROG) &&
  2196. (dd->ipath_link_speed_active & IPATH_IB_DDR)) {
  2197. ipath_dbg("Got to INIT with DDR autoneg\n");
  2198. dd->ipath_flags &= ~(IPATH_IB_AUTONEG_INPROG
  2199. | IPATH_IB_AUTONEG_FAILED);
  2200. dd->ipath_autoneg_tries = 0;
  2201. /* re-enable SDR, for next link down */
  2202. set_speed_fast(dd,
  2203. dd->ipath_link_speed_enabled);
  2204. wake_up(&dd->ipath_autoneg_wait);
  2205. symadj = 1;
  2206. } else if (dd->ipath_flags & IPATH_IB_AUTONEG_FAILED) {
  2207. /*
  2208. * clear autoneg failure flag, and do setup
  2209. * so we'll try next time link goes down and
  2210. * back to INIT (possibly connected to different
  2211. * device).
  2212. */
  2213. ipath_dbg("INIT %sDR after autoneg failure\n",
  2214. (dd->ipath_link_speed_active &
  2215. IPATH_IB_DDR) ? "D" : "S");
  2216. dd->ipath_flags &= ~IPATH_IB_AUTONEG_FAILED;
  2217. dd->ipath_ibcddrctrl |=
  2218. IBA7220_IBC_IBTA_1_2_MASK;
  2219. ipath_write_kreg(dd,
  2220. IPATH_KREG_OFFSET(IBNCModeCtrl), 0);
  2221. symadj = 1;
  2222. }
  2223. }
  2224. /*
  2225. * if we are in 1X on rev1 only, and are in autoneg width,
  2226. * it could be due to an xgxs problem, so if we haven't
  2227. * already tried, try twice to get to 4X; if we
  2228. * tried, and couldn't, report it, since it will
  2229. * probably not be what is desired.
  2230. */
  2231. if (dd->ipath_minrev == 1 &&
  2232. (dd->ipath_link_width_enabled & (IB_WIDTH_1X |
  2233. IB_WIDTH_4X)) == (IB_WIDTH_1X | IB_WIDTH_4X)
  2234. && dd->ipath_link_width_active == IB_WIDTH_1X
  2235. && dd->ipath_x1_fix_tries < 3) {
  2236. if (++dd->ipath_x1_fix_tries == 3) {
  2237. dev_info(&dd->pcidev->dev,
  2238. "IB link is in 1X mode\n");
  2239. if (!(dd->ipath_flags &
  2240. IPATH_IB_AUTONEG_INPROG))
  2241. symadj = 1;
  2242. }
  2243. else {
  2244. ipath_cdbg(VERBOSE, "IB 1X in "
  2245. "auto-width, try %u to be "
  2246. "sure it's really 1X; "
  2247. "ltstate %u\n",
  2248. dd->ipath_x1_fix_tries,
  2249. ltstate);
  2250. dd->ipath_f_xgxs_reset(dd);
  2251. ret = 1; /* skip other processing */
  2252. }
  2253. } else if (!(dd->ipath_flags & IPATH_IB_AUTONEG_INPROG))
  2254. symadj = 1;
  2255. if (!ret) {
  2256. dd->delay_mult = rate_to_delay
  2257. [(ibcs >> IBA7220_IBCS_LINKSPEED_SHIFT) & 1]
  2258. [(ibcs >> IBA7220_IBCS_LINKWIDTH_SHIFT) & 1];
  2259. ipath_set_relock_poll(dd, ibup);
  2260. }
  2261. }
  2262. if (symadj) {
  2263. if (dd->ibdeltainprog) {
  2264. dd->ibdeltainprog = 0;
  2265. dd->ibsymdelta += ipath_read_creg32(dd,
  2266. dd->ipath_cregs->cr_ibsymbolerrcnt) -
  2267. dd->ibsymsnap;
  2268. dd->iblnkerrdelta += ipath_read_creg32(dd,
  2269. dd->ipath_cregs->cr_iblinkerrrecovcnt) -
  2270. dd->iblnkerrsnap;
  2271. }
  2272. } else if (!ibup && !dd->ibdeltainprog
  2273. && !(dd->ipath_flags & IPATH_IB_AUTONEG_INPROG)) {
  2274. dd->ibdeltainprog = 1;
  2275. dd->ibsymsnap = ipath_read_creg32(dd,
  2276. dd->ipath_cregs->cr_ibsymbolerrcnt);
  2277. dd->iblnkerrsnap = ipath_read_creg32(dd,
  2278. dd->ipath_cregs->cr_iblinkerrrecovcnt);
  2279. }
  2280. if (!ret)
  2281. ipath_setup_7220_setextled(dd, ipath_ib_linkstate(dd, ibcs),
  2282. ltstate);
  2283. return ret;
  2284. }
  2285. /*
  2286. * Handle the empirically determined mechanism for auto-negotiation
  2287. * of DDR speed with switches.
  2288. */
  2289. static void autoneg_work(struct work_struct *work)
  2290. {
  2291. struct ipath_devdata *dd;
  2292. u64 startms;
  2293. u32 lastlts, i;
  2294. dd = container_of(work, struct ipath_devdata,
  2295. ipath_autoneg_work.work);
  2296. startms = jiffies_to_msecs(jiffies);
  2297. /*
  2298. * busy wait for this first part, it should be at most a
  2299. * few hundred usec, since we scheduled ourselves for 2msec.
  2300. */
  2301. for (i = 0; i < 25; i++) {
  2302. lastlts = ipath_ib_linktrstate(dd, dd->ipath_lastibcstat);
  2303. if (lastlts == INFINIPATH_IBCS_LT_STATE_POLLQUIET) {
  2304. ipath_set_linkstate(dd, IPATH_IB_LINKDOWN_DISABLE);
  2305. break;
  2306. }
  2307. udelay(100);
  2308. }
  2309. if (!(dd->ipath_flags & IPATH_IB_AUTONEG_INPROG))
  2310. goto done; /* we got there early or told to stop */
  2311. /* we expect this to timeout */
  2312. if (wait_event_timeout(dd->ipath_autoneg_wait,
  2313. !(dd->ipath_flags & IPATH_IB_AUTONEG_INPROG),
  2314. msecs_to_jiffies(90)))
  2315. goto done;
  2316. ipath_toggle_rclkrls(dd);
  2317. /* we expect this to timeout */
  2318. if (wait_event_timeout(dd->ipath_autoneg_wait,
  2319. !(dd->ipath_flags & IPATH_IB_AUTONEG_INPROG),
  2320. msecs_to_jiffies(1700)))
  2321. goto done;
  2322. set_speed_fast(dd, IPATH_IB_SDR);
  2323. ipath_toggle_rclkrls(dd);
  2324. /*
  2325. * wait up to 250 msec for link to train and get to INIT at DDR;
  2326. * this should terminate early
  2327. */
  2328. wait_event_timeout(dd->ipath_autoneg_wait,
  2329. !(dd->ipath_flags & IPATH_IB_AUTONEG_INPROG),
  2330. msecs_to_jiffies(250));
  2331. done:
  2332. if (dd->ipath_flags & IPATH_IB_AUTONEG_INPROG) {
  2333. ipath_dbg("Did not get to DDR INIT (%x) after %Lu msecs\n",
  2334. ipath_ib_state(dd, dd->ipath_lastibcstat),
  2335. (unsigned long long) jiffies_to_msecs(jiffies)-startms);
  2336. dd->ipath_flags &= ~IPATH_IB_AUTONEG_INPROG;
  2337. if (dd->ipath_autoneg_tries == IPATH_AUTONEG_TRIES) {
  2338. dd->ipath_flags |= IPATH_IB_AUTONEG_FAILED;
  2339. ipath_dbg("Giving up on DDR until next IB "
  2340. "link Down\n");
  2341. dd->ipath_autoneg_tries = 0;
  2342. }
  2343. set_speed_fast(dd, dd->ipath_link_speed_enabled);
  2344. }
  2345. }
  2346. /**
  2347. * ipath_init_iba7220_funcs - set up the chip-specific function pointers
  2348. * @dd: the infinipath device
  2349. *
  2350. * This is global, and is called directly at init to set up the
  2351. * chip-specific function pointers for later use.
  2352. */
  2353. void ipath_init_iba7220_funcs(struct ipath_devdata *dd)
  2354. {
  2355. dd->ipath_f_intrsetup = ipath_7220_intconfig;
  2356. dd->ipath_f_bus = ipath_setup_7220_config;
  2357. dd->ipath_f_reset = ipath_setup_7220_reset;
  2358. dd->ipath_f_get_boardname = ipath_7220_boardname;
  2359. dd->ipath_f_init_hwerrors = ipath_7220_init_hwerrors;
  2360. dd->ipath_f_early_init = ipath_7220_early_init;
  2361. dd->ipath_f_handle_hwerrors = ipath_7220_handle_hwerrors;
  2362. dd->ipath_f_quiet_serdes = ipath_7220_quiet_serdes;
  2363. dd->ipath_f_bringup_serdes = ipath_7220_bringup_serdes;
  2364. dd->ipath_f_clear_tids = ipath_7220_clear_tids;
  2365. dd->ipath_f_put_tid = ipath_7220_put_tid;
  2366. dd->ipath_f_cleanup = ipath_setup_7220_cleanup;
  2367. dd->ipath_f_setextled = ipath_setup_7220_setextled;
  2368. dd->ipath_f_get_base_info = ipath_7220_get_base_info;
  2369. dd->ipath_f_free_irq = ipath_7220_free_irq;
  2370. dd->ipath_f_tidtemplate = ipath_7220_tidtemplate;
  2371. dd->ipath_f_intr_fallback = ipath_7220_intr_fallback;
  2372. dd->ipath_f_xgxs_reset = ipath_7220_xgxs_reset;
  2373. dd->ipath_f_get_ib_cfg = ipath_7220_get_ib_cfg;
  2374. dd->ipath_f_set_ib_cfg = ipath_7220_set_ib_cfg;
  2375. dd->ipath_f_config_jint = ipath_7220_config_jint;
  2376. dd->ipath_f_config_ports = ipath_7220_config_ports;
  2377. dd->ipath_f_read_counters = ipath_7220_read_counters;
  2378. dd->ipath_f_get_msgheader = ipath_7220_get_msgheader;
  2379. dd->ipath_f_ib_updown = ipath_7220_ib_updown;
  2380. /* initialize chip-specific variables */
  2381. ipath_init_7220_variables(dd);
  2382. }