ipath_iba7220.c 86 KB

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