ipath_iba6110.c 62 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944
  1. /*
  2. * Copyright (c) 2006, 2007 QLogic Corporation. All rights reserved.
  3. * Copyright (c) 2003, 2004, 2005, 2006 PathScale, Inc. All rights reserved.
  4. *
  5. * This software is available to you under a choice of one of two
  6. * licenses. You may choose to be licensed under the terms of the GNU
  7. * General Public License (GPL) Version 2, available from the file
  8. * COPYING in the main directory of this source tree, or the
  9. * OpenIB.org BSD license below:
  10. *
  11. * Redistribution and use in source and binary forms, with or
  12. * without modification, are permitted provided that the following
  13. * conditions are met:
  14. *
  15. * - Redistributions of source code must retain the above
  16. * copyright notice, this list of conditions and the following
  17. * disclaimer.
  18. *
  19. * - Redistributions in binary form must reproduce the above
  20. * copyright notice, this list of conditions and the following
  21. * disclaimer in the documentation and/or other materials
  22. * provided with the distribution.
  23. *
  24. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  25. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  26. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  27. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  28. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  29. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  30. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  31. * SOFTWARE.
  32. */
  33. /*
  34. * This file contains all of the code that is specific to the InfiniPath
  35. * HT chip.
  36. */
  37. #include <linux/vmalloc.h>
  38. #include <linux/pci.h>
  39. #include <linux/delay.h>
  40. #include <linux/htirq.h>
  41. #include "ipath_kernel.h"
  42. #include "ipath_registers.h"
  43. static void ipath_setup_ht_setextled(struct ipath_devdata *, u64, u64);
  44. /*
  45. * This lists the InfiniPath registers, in the actual chip layout.
  46. * This structure should never be directly accessed.
  47. *
  48. * The names are in InterCap form because they're taken straight from
  49. * the chip specification. Since they're only used in this file, they
  50. * don't pollute the rest of the source.
  51. */
  52. struct _infinipath_do_not_use_kernel_regs {
  53. unsigned long long Revision;
  54. unsigned long long Control;
  55. unsigned long long PageAlign;
  56. unsigned long long PortCnt;
  57. unsigned long long DebugPortSelect;
  58. unsigned long long DebugPort;
  59. unsigned long long SendRegBase;
  60. unsigned long long UserRegBase;
  61. unsigned long long CounterRegBase;
  62. unsigned long long Scratch;
  63. unsigned long long ReservedMisc1;
  64. unsigned long long InterruptConfig;
  65. unsigned long long IntBlocked;
  66. unsigned long long IntMask;
  67. unsigned long long IntStatus;
  68. unsigned long long IntClear;
  69. unsigned long long ErrorMask;
  70. unsigned long long ErrorStatus;
  71. unsigned long long ErrorClear;
  72. unsigned long long HwErrMask;
  73. unsigned long long HwErrStatus;
  74. unsigned long long HwErrClear;
  75. unsigned long long HwDiagCtrl;
  76. unsigned long long MDIO;
  77. unsigned long long IBCStatus;
  78. unsigned long long IBCCtrl;
  79. unsigned long long ExtStatus;
  80. unsigned long long ExtCtrl;
  81. unsigned long long GPIOOut;
  82. unsigned long long GPIOMask;
  83. unsigned long long GPIOStatus;
  84. unsigned long long GPIOClear;
  85. unsigned long long RcvCtrl;
  86. unsigned long long RcvBTHQP;
  87. unsigned long long RcvHdrSize;
  88. unsigned long long RcvHdrCnt;
  89. unsigned long long RcvHdrEntSize;
  90. unsigned long long RcvTIDBase;
  91. unsigned long long RcvTIDCnt;
  92. unsigned long long RcvEgrBase;
  93. unsigned long long RcvEgrCnt;
  94. unsigned long long RcvBufBase;
  95. unsigned long long RcvBufSize;
  96. unsigned long long RxIntMemBase;
  97. unsigned long long RxIntMemSize;
  98. unsigned long long RcvPartitionKey;
  99. unsigned long long ReservedRcv[10];
  100. unsigned long long SendCtrl;
  101. unsigned long long SendPIOBufBase;
  102. unsigned long long SendPIOSize;
  103. unsigned long long SendPIOBufCnt;
  104. unsigned long long SendPIOAvailAddr;
  105. unsigned long long TxIntMemBase;
  106. unsigned long long TxIntMemSize;
  107. unsigned long long ReservedSend[9];
  108. unsigned long long SendBufferError;
  109. unsigned long long SendBufferErrorCONT1;
  110. unsigned long long SendBufferErrorCONT2;
  111. unsigned long long SendBufferErrorCONT3;
  112. unsigned long long ReservedSBE[4];
  113. unsigned long long RcvHdrAddr0;
  114. unsigned long long RcvHdrAddr1;
  115. unsigned long long RcvHdrAddr2;
  116. unsigned long long RcvHdrAddr3;
  117. unsigned long long RcvHdrAddr4;
  118. unsigned long long RcvHdrAddr5;
  119. unsigned long long RcvHdrAddr6;
  120. unsigned long long RcvHdrAddr7;
  121. unsigned long long RcvHdrAddr8;
  122. unsigned long long ReservedRHA[7];
  123. unsigned long long RcvHdrTailAddr0;
  124. unsigned long long RcvHdrTailAddr1;
  125. unsigned long long RcvHdrTailAddr2;
  126. unsigned long long RcvHdrTailAddr3;
  127. unsigned long long RcvHdrTailAddr4;
  128. unsigned long long RcvHdrTailAddr5;
  129. unsigned long long RcvHdrTailAddr6;
  130. unsigned long long RcvHdrTailAddr7;
  131. unsigned long long RcvHdrTailAddr8;
  132. unsigned long long ReservedRHTA[7];
  133. unsigned long long Sync; /* Software only */
  134. unsigned long long Dump; /* Software only */
  135. unsigned long long SimVer; /* Software only */
  136. unsigned long long ReservedSW[5];
  137. unsigned long long SerdesConfig0;
  138. unsigned long long SerdesConfig1;
  139. unsigned long long SerdesStatus;
  140. unsigned long long XGXSConfig;
  141. unsigned long long ReservedSW2[4];
  142. };
  143. struct _infinipath_do_not_use_counters {
  144. __u64 LBIntCnt;
  145. __u64 LBFlowStallCnt;
  146. __u64 Reserved1;
  147. __u64 TxUnsupVLErrCnt;
  148. __u64 TxDataPktCnt;
  149. __u64 TxFlowPktCnt;
  150. __u64 TxDwordCnt;
  151. __u64 TxLenErrCnt;
  152. __u64 TxMaxMinLenErrCnt;
  153. __u64 TxUnderrunCnt;
  154. __u64 TxFlowStallCnt;
  155. __u64 TxDroppedPktCnt;
  156. __u64 RxDroppedPktCnt;
  157. __u64 RxDataPktCnt;
  158. __u64 RxFlowPktCnt;
  159. __u64 RxDwordCnt;
  160. __u64 RxLenErrCnt;
  161. __u64 RxMaxMinLenErrCnt;
  162. __u64 RxICRCErrCnt;
  163. __u64 RxVCRCErrCnt;
  164. __u64 RxFlowCtrlErrCnt;
  165. __u64 RxBadFormatCnt;
  166. __u64 RxLinkProblemCnt;
  167. __u64 RxEBPCnt;
  168. __u64 RxLPCRCErrCnt;
  169. __u64 RxBufOvflCnt;
  170. __u64 RxTIDFullErrCnt;
  171. __u64 RxTIDValidErrCnt;
  172. __u64 RxPKeyMismatchCnt;
  173. __u64 RxP0HdrEgrOvflCnt;
  174. __u64 RxP1HdrEgrOvflCnt;
  175. __u64 RxP2HdrEgrOvflCnt;
  176. __u64 RxP3HdrEgrOvflCnt;
  177. __u64 RxP4HdrEgrOvflCnt;
  178. __u64 RxP5HdrEgrOvflCnt;
  179. __u64 RxP6HdrEgrOvflCnt;
  180. __u64 RxP7HdrEgrOvflCnt;
  181. __u64 RxP8HdrEgrOvflCnt;
  182. __u64 Reserved6;
  183. __u64 Reserved7;
  184. __u64 IBStatusChangeCnt;
  185. __u64 IBLinkErrRecoveryCnt;
  186. __u64 IBLinkDownedCnt;
  187. __u64 IBSymbolErrCnt;
  188. };
  189. #define IPATH_KREG_OFFSET(field) (offsetof( \
  190. struct _infinipath_do_not_use_kernel_regs, field) / sizeof(u64))
  191. #define IPATH_CREG_OFFSET(field) (offsetof( \
  192. struct _infinipath_do_not_use_counters, field) / sizeof(u64))
  193. static const struct ipath_kregs ipath_ht_kregs = {
  194. .kr_control = IPATH_KREG_OFFSET(Control),
  195. .kr_counterregbase = IPATH_KREG_OFFSET(CounterRegBase),
  196. .kr_debugport = IPATH_KREG_OFFSET(DebugPort),
  197. .kr_debugportselect = IPATH_KREG_OFFSET(DebugPortSelect),
  198. .kr_errorclear = IPATH_KREG_OFFSET(ErrorClear),
  199. .kr_errormask = IPATH_KREG_OFFSET(ErrorMask),
  200. .kr_errorstatus = IPATH_KREG_OFFSET(ErrorStatus),
  201. .kr_extctrl = IPATH_KREG_OFFSET(ExtCtrl),
  202. .kr_extstatus = IPATH_KREG_OFFSET(ExtStatus),
  203. .kr_gpio_clear = IPATH_KREG_OFFSET(GPIOClear),
  204. .kr_gpio_mask = IPATH_KREG_OFFSET(GPIOMask),
  205. .kr_gpio_out = IPATH_KREG_OFFSET(GPIOOut),
  206. .kr_gpio_status = IPATH_KREG_OFFSET(GPIOStatus),
  207. .kr_hwdiagctrl = IPATH_KREG_OFFSET(HwDiagCtrl),
  208. .kr_hwerrclear = IPATH_KREG_OFFSET(HwErrClear),
  209. .kr_hwerrmask = IPATH_KREG_OFFSET(HwErrMask),
  210. .kr_hwerrstatus = IPATH_KREG_OFFSET(HwErrStatus),
  211. .kr_ibcctrl = IPATH_KREG_OFFSET(IBCCtrl),
  212. .kr_ibcstatus = IPATH_KREG_OFFSET(IBCStatus),
  213. .kr_intblocked = IPATH_KREG_OFFSET(IntBlocked),
  214. .kr_intclear = IPATH_KREG_OFFSET(IntClear),
  215. .kr_interruptconfig = IPATH_KREG_OFFSET(InterruptConfig),
  216. .kr_intmask = IPATH_KREG_OFFSET(IntMask),
  217. .kr_intstatus = IPATH_KREG_OFFSET(IntStatus),
  218. .kr_mdio = IPATH_KREG_OFFSET(MDIO),
  219. .kr_pagealign = IPATH_KREG_OFFSET(PageAlign),
  220. .kr_partitionkey = IPATH_KREG_OFFSET(RcvPartitionKey),
  221. .kr_portcnt = IPATH_KREG_OFFSET(PortCnt),
  222. .kr_rcvbthqp = IPATH_KREG_OFFSET(RcvBTHQP),
  223. .kr_rcvbufbase = IPATH_KREG_OFFSET(RcvBufBase),
  224. .kr_rcvbufsize = IPATH_KREG_OFFSET(RcvBufSize),
  225. .kr_rcvctrl = IPATH_KREG_OFFSET(RcvCtrl),
  226. .kr_rcvegrbase = IPATH_KREG_OFFSET(RcvEgrBase),
  227. .kr_rcvegrcnt = IPATH_KREG_OFFSET(RcvEgrCnt),
  228. .kr_rcvhdrcnt = IPATH_KREG_OFFSET(RcvHdrCnt),
  229. .kr_rcvhdrentsize = IPATH_KREG_OFFSET(RcvHdrEntSize),
  230. .kr_rcvhdrsize = IPATH_KREG_OFFSET(RcvHdrSize),
  231. .kr_rcvintmembase = IPATH_KREG_OFFSET(RxIntMemBase),
  232. .kr_rcvintmemsize = IPATH_KREG_OFFSET(RxIntMemSize),
  233. .kr_rcvtidbase = IPATH_KREG_OFFSET(RcvTIDBase),
  234. .kr_rcvtidcnt = IPATH_KREG_OFFSET(RcvTIDCnt),
  235. .kr_revision = IPATH_KREG_OFFSET(Revision),
  236. .kr_scratch = IPATH_KREG_OFFSET(Scratch),
  237. .kr_sendbuffererror = IPATH_KREG_OFFSET(SendBufferError),
  238. .kr_sendctrl = IPATH_KREG_OFFSET(SendCtrl),
  239. .kr_sendpioavailaddr = IPATH_KREG_OFFSET(SendPIOAvailAddr),
  240. .kr_sendpiobufbase = IPATH_KREG_OFFSET(SendPIOBufBase),
  241. .kr_sendpiobufcnt = IPATH_KREG_OFFSET(SendPIOBufCnt),
  242. .kr_sendpiosize = IPATH_KREG_OFFSET(SendPIOSize),
  243. .kr_sendregbase = IPATH_KREG_OFFSET(SendRegBase),
  244. .kr_txintmembase = IPATH_KREG_OFFSET(TxIntMemBase),
  245. .kr_txintmemsize = IPATH_KREG_OFFSET(TxIntMemSize),
  246. .kr_userregbase = IPATH_KREG_OFFSET(UserRegBase),
  247. .kr_serdesconfig0 = IPATH_KREG_OFFSET(SerdesConfig0),
  248. .kr_serdesconfig1 = IPATH_KREG_OFFSET(SerdesConfig1),
  249. .kr_serdesstatus = IPATH_KREG_OFFSET(SerdesStatus),
  250. .kr_xgxsconfig = IPATH_KREG_OFFSET(XGXSConfig),
  251. /*
  252. * These should not be used directly via ipath_write_kreg64(),
  253. * use them with ipath_write_kreg64_port(),
  254. */
  255. .kr_rcvhdraddr = IPATH_KREG_OFFSET(RcvHdrAddr0),
  256. .kr_rcvhdrtailaddr = IPATH_KREG_OFFSET(RcvHdrTailAddr0)
  257. };
  258. static const struct ipath_cregs ipath_ht_cregs = {
  259. .cr_badformatcnt = IPATH_CREG_OFFSET(RxBadFormatCnt),
  260. .cr_erricrccnt = IPATH_CREG_OFFSET(RxICRCErrCnt),
  261. .cr_errlinkcnt = IPATH_CREG_OFFSET(RxLinkProblemCnt),
  262. .cr_errlpcrccnt = IPATH_CREG_OFFSET(RxLPCRCErrCnt),
  263. .cr_errpkey = IPATH_CREG_OFFSET(RxPKeyMismatchCnt),
  264. .cr_errrcvflowctrlcnt = IPATH_CREG_OFFSET(RxFlowCtrlErrCnt),
  265. .cr_err_rlencnt = IPATH_CREG_OFFSET(RxLenErrCnt),
  266. .cr_errslencnt = IPATH_CREG_OFFSET(TxLenErrCnt),
  267. .cr_errtidfull = IPATH_CREG_OFFSET(RxTIDFullErrCnt),
  268. .cr_errtidvalid = IPATH_CREG_OFFSET(RxTIDValidErrCnt),
  269. .cr_errvcrccnt = IPATH_CREG_OFFSET(RxVCRCErrCnt),
  270. .cr_ibstatuschange = IPATH_CREG_OFFSET(IBStatusChangeCnt),
  271. /* calc from Reg_CounterRegBase + offset */
  272. .cr_intcnt = IPATH_CREG_OFFSET(LBIntCnt),
  273. .cr_invalidrlencnt = IPATH_CREG_OFFSET(RxMaxMinLenErrCnt),
  274. .cr_invalidslencnt = IPATH_CREG_OFFSET(TxMaxMinLenErrCnt),
  275. .cr_lbflowstallcnt = IPATH_CREG_OFFSET(LBFlowStallCnt),
  276. .cr_pktrcvcnt = IPATH_CREG_OFFSET(RxDataPktCnt),
  277. .cr_pktrcvflowctrlcnt = IPATH_CREG_OFFSET(RxFlowPktCnt),
  278. .cr_pktsendcnt = IPATH_CREG_OFFSET(TxDataPktCnt),
  279. .cr_pktsendflowcnt = IPATH_CREG_OFFSET(TxFlowPktCnt),
  280. .cr_portovflcnt = IPATH_CREG_OFFSET(RxP0HdrEgrOvflCnt),
  281. .cr_rcvebpcnt = IPATH_CREG_OFFSET(RxEBPCnt),
  282. .cr_rcvovflcnt = IPATH_CREG_OFFSET(RxBufOvflCnt),
  283. .cr_senddropped = IPATH_CREG_OFFSET(TxDroppedPktCnt),
  284. .cr_sendstallcnt = IPATH_CREG_OFFSET(TxFlowStallCnt),
  285. .cr_sendunderruncnt = IPATH_CREG_OFFSET(TxUnderrunCnt),
  286. .cr_wordrcvcnt = IPATH_CREG_OFFSET(RxDwordCnt),
  287. .cr_wordsendcnt = IPATH_CREG_OFFSET(TxDwordCnt),
  288. .cr_unsupvlcnt = IPATH_CREG_OFFSET(TxUnsupVLErrCnt),
  289. .cr_rxdroppktcnt = IPATH_CREG_OFFSET(RxDroppedPktCnt),
  290. .cr_iblinkerrrecovcnt = IPATH_CREG_OFFSET(IBLinkErrRecoveryCnt),
  291. .cr_iblinkdowncnt = IPATH_CREG_OFFSET(IBLinkDownedCnt),
  292. .cr_ibsymbolerrcnt = IPATH_CREG_OFFSET(IBSymbolErrCnt)
  293. };
  294. /* kr_intstatus, kr_intclear, kr_intmask bits */
  295. #define INFINIPATH_I_RCVURG_MASK ((1U<<9)-1)
  296. #define INFINIPATH_I_RCVAVAIL_MASK ((1U<<9)-1)
  297. /* kr_hwerrclear, kr_hwerrmask, kr_hwerrstatus, bits */
  298. #define INFINIPATH_HWE_HTCMEMPARITYERR_SHIFT 0
  299. #define INFINIPATH_HWE_HTCMEMPARITYERR_MASK 0x3FFFFFULL
  300. #define INFINIPATH_HWE_HTCLNKABYTE0CRCERR 0x0000000000800000ULL
  301. #define INFINIPATH_HWE_HTCLNKABYTE1CRCERR 0x0000000001000000ULL
  302. #define INFINIPATH_HWE_HTCLNKBBYTE0CRCERR 0x0000000002000000ULL
  303. #define INFINIPATH_HWE_HTCLNKBBYTE1CRCERR 0x0000000004000000ULL
  304. #define INFINIPATH_HWE_HTCMISCERR4 0x0000000008000000ULL
  305. #define INFINIPATH_HWE_HTCMISCERR5 0x0000000010000000ULL
  306. #define INFINIPATH_HWE_HTCMISCERR6 0x0000000020000000ULL
  307. #define INFINIPATH_HWE_HTCMISCERR7 0x0000000040000000ULL
  308. #define INFINIPATH_HWE_HTCBUSTREQPARITYERR 0x0000000080000000ULL
  309. #define INFINIPATH_HWE_HTCBUSTRESPPARITYERR 0x0000000100000000ULL
  310. #define INFINIPATH_HWE_HTCBUSIREQPARITYERR 0x0000000200000000ULL
  311. #define INFINIPATH_HWE_COREPLL_FBSLIP 0x0080000000000000ULL
  312. #define INFINIPATH_HWE_COREPLL_RFSLIP 0x0100000000000000ULL
  313. #define INFINIPATH_HWE_HTBPLL_FBSLIP 0x0200000000000000ULL
  314. #define INFINIPATH_HWE_HTBPLL_RFSLIP 0x0400000000000000ULL
  315. #define INFINIPATH_HWE_HTAPLL_FBSLIP 0x0800000000000000ULL
  316. #define INFINIPATH_HWE_HTAPLL_RFSLIP 0x1000000000000000ULL
  317. #define INFINIPATH_HWE_SERDESPLLFAILED 0x2000000000000000ULL
  318. #define IBA6110_IBCS_LINKTRAININGSTATE_MASK 0xf
  319. #define IBA6110_IBCS_LINKSTATE_SHIFT 4
  320. /* kr_extstatus bits */
  321. #define INFINIPATH_EXTS_FREQSEL 0x2
  322. #define INFINIPATH_EXTS_SERDESSEL 0x4
  323. #define INFINIPATH_EXTS_MEMBIST_ENDTEST 0x0000000000004000
  324. #define INFINIPATH_EXTS_MEMBIST_CORRECT 0x0000000000008000
  325. /* TID entries (memory), HT-only */
  326. #define INFINIPATH_RT_ADDR_MASK 0xFFFFFFFFFFULL /* 40 bits valid */
  327. #define INFINIPATH_RT_VALID 0x8000000000000000ULL
  328. #define INFINIPATH_RT_ADDR_SHIFT 0
  329. #define INFINIPATH_RT_BUFSIZE_MASK 0x3FFFULL
  330. #define INFINIPATH_RT_BUFSIZE_SHIFT 48
  331. #define INFINIPATH_R_INTRAVAIL_SHIFT 16
  332. #define INFINIPATH_R_TAILUPD_SHIFT 31
  333. /* kr_xgxsconfig bits */
  334. #define INFINIPATH_XGXS_RESET 0x7ULL
  335. /*
  336. * masks and bits that are different in different chips, or present only
  337. * in one
  338. */
  339. static const ipath_err_t infinipath_hwe_htcmemparityerr_mask =
  340. INFINIPATH_HWE_HTCMEMPARITYERR_MASK;
  341. static const ipath_err_t infinipath_hwe_htcmemparityerr_shift =
  342. INFINIPATH_HWE_HTCMEMPARITYERR_SHIFT;
  343. static const ipath_err_t infinipath_hwe_htclnkabyte0crcerr =
  344. INFINIPATH_HWE_HTCLNKABYTE0CRCERR;
  345. static const ipath_err_t infinipath_hwe_htclnkabyte1crcerr =
  346. INFINIPATH_HWE_HTCLNKABYTE1CRCERR;
  347. static const ipath_err_t infinipath_hwe_htclnkbbyte0crcerr =
  348. INFINIPATH_HWE_HTCLNKBBYTE0CRCERR;
  349. static const ipath_err_t infinipath_hwe_htclnkbbyte1crcerr =
  350. INFINIPATH_HWE_HTCLNKBBYTE1CRCERR;
  351. #define _IPATH_GPIO_SDA_NUM 1
  352. #define _IPATH_GPIO_SCL_NUM 0
  353. #define IPATH_GPIO_SDA \
  354. (1ULL << (_IPATH_GPIO_SDA_NUM+INFINIPATH_EXTC_GPIOOE_SHIFT))
  355. #define IPATH_GPIO_SCL \
  356. (1ULL << (_IPATH_GPIO_SCL_NUM+INFINIPATH_EXTC_GPIOOE_SHIFT))
  357. /* keep the code below somewhat more readonable; not used elsewhere */
  358. #define _IPATH_HTLINK0_CRCBITS (infinipath_hwe_htclnkabyte0crcerr | \
  359. infinipath_hwe_htclnkabyte1crcerr)
  360. #define _IPATH_HTLINK1_CRCBITS (infinipath_hwe_htclnkbbyte0crcerr | \
  361. infinipath_hwe_htclnkbbyte1crcerr)
  362. #define _IPATH_HTLANE0_CRCBITS (infinipath_hwe_htclnkabyte0crcerr | \
  363. infinipath_hwe_htclnkbbyte0crcerr)
  364. #define _IPATH_HTLANE1_CRCBITS (infinipath_hwe_htclnkabyte1crcerr | \
  365. infinipath_hwe_htclnkbbyte1crcerr)
  366. static void hwerr_crcbits(struct ipath_devdata *dd, ipath_err_t hwerrs,
  367. char *msg, size_t msgl)
  368. {
  369. char bitsmsg[64];
  370. ipath_err_t crcbits = hwerrs &
  371. (_IPATH_HTLINK0_CRCBITS | _IPATH_HTLINK1_CRCBITS);
  372. /* don't check if 8bit HT */
  373. if (dd->ipath_flags & IPATH_8BIT_IN_HT0)
  374. crcbits &= ~infinipath_hwe_htclnkabyte1crcerr;
  375. /* don't check if 8bit HT */
  376. if (dd->ipath_flags & IPATH_8BIT_IN_HT1)
  377. crcbits &= ~infinipath_hwe_htclnkbbyte1crcerr;
  378. /*
  379. * we'll want to ignore link errors on link that is
  380. * not in use, if any. For now, complain about both
  381. */
  382. if (crcbits) {
  383. u16 ctrl0, ctrl1;
  384. snprintf(bitsmsg, sizeof bitsmsg,
  385. "[HT%s lane %s CRC (%llx); powercycle to completely clear]",
  386. !(crcbits & _IPATH_HTLINK1_CRCBITS) ?
  387. "0 (A)" : (!(crcbits & _IPATH_HTLINK0_CRCBITS)
  388. ? "1 (B)" : "0+1 (A+B)"),
  389. !(crcbits & _IPATH_HTLANE1_CRCBITS) ? "0"
  390. : (!(crcbits & _IPATH_HTLANE0_CRCBITS) ? "1" :
  391. "0+1"), (unsigned long long) crcbits);
  392. strlcat(msg, bitsmsg, msgl);
  393. /*
  394. * print extra info for debugging. slave/primary
  395. * config word 4, 8 (link control 0, 1)
  396. */
  397. if (pci_read_config_word(dd->pcidev,
  398. dd->ipath_ht_slave_off + 0x4,
  399. &ctrl0))
  400. dev_info(&dd->pcidev->dev, "Couldn't read "
  401. "linkctrl0 of slave/primary "
  402. "config block\n");
  403. else if (!(ctrl0 & 1 << 6))
  404. /* not if EOC bit set */
  405. ipath_dbg("HT linkctrl0 0x%x%s%s\n", ctrl0,
  406. ((ctrl0 >> 8) & 7) ? " CRC" : "",
  407. ((ctrl0 >> 4) & 1) ? "linkfail" :
  408. "");
  409. if (pci_read_config_word(dd->pcidev,
  410. dd->ipath_ht_slave_off + 0x8,
  411. &ctrl1))
  412. dev_info(&dd->pcidev->dev, "Couldn't read "
  413. "linkctrl1 of slave/primary "
  414. "config block\n");
  415. else if (!(ctrl1 & 1 << 6))
  416. /* not if EOC bit set */
  417. ipath_dbg("HT linkctrl1 0x%x%s%s\n", ctrl1,
  418. ((ctrl1 >> 8) & 7) ? " CRC" : "",
  419. ((ctrl1 >> 4) & 1) ? "linkfail" :
  420. "");
  421. /* disable until driver reloaded */
  422. dd->ipath_hwerrmask &= ~crcbits;
  423. ipath_write_kreg(dd, dd->ipath_kregs->kr_hwerrmask,
  424. dd->ipath_hwerrmask);
  425. ipath_dbg("HT crc errs: %s\n", msg);
  426. } else
  427. ipath_dbg("ignoring HT crc errors 0x%llx, "
  428. "not in use\n", (unsigned long long)
  429. (hwerrs & (_IPATH_HTLINK0_CRCBITS |
  430. _IPATH_HTLINK1_CRCBITS)));
  431. }
  432. /* 6110 specific hardware errors... */
  433. static const struct ipath_hwerror_msgs ipath_6110_hwerror_msgs[] = {
  434. INFINIPATH_HWE_MSG(HTCBUSIREQPARITYERR, "HTC Ireq Parity"),
  435. INFINIPATH_HWE_MSG(HTCBUSTREQPARITYERR, "HTC Treq Parity"),
  436. INFINIPATH_HWE_MSG(HTCBUSTRESPPARITYERR, "HTC Tresp Parity"),
  437. INFINIPATH_HWE_MSG(HTCMISCERR5, "HT core Misc5"),
  438. INFINIPATH_HWE_MSG(HTCMISCERR6, "HT core Misc6"),
  439. INFINIPATH_HWE_MSG(HTCMISCERR7, "HT core Misc7"),
  440. INFINIPATH_HWE_MSG(RXDSYNCMEMPARITYERR, "Rx Dsync"),
  441. INFINIPATH_HWE_MSG(SERDESPLLFAILED, "SerDes PLL"),
  442. };
  443. #define TXE_PIO_PARITY ((INFINIPATH_HWE_TXEMEMPARITYERR_PIOBUF | \
  444. INFINIPATH_HWE_TXEMEMPARITYERR_PIOPBC) \
  445. << INFINIPATH_HWE_TXEMEMPARITYERR_SHIFT)
  446. #define RXE_EAGER_PARITY (INFINIPATH_HWE_RXEMEMPARITYERR_EAGERTID \
  447. << INFINIPATH_HWE_RXEMEMPARITYERR_SHIFT)
  448. static int ipath_ht_txe_recover(struct ipath_devdata *);
  449. /**
  450. * ipath_ht_handle_hwerrors - display hardware errors.
  451. * @dd: the infinipath device
  452. * @msg: the output buffer
  453. * @msgl: the size of the output buffer
  454. *
  455. * Use same msg buffer as regular errors to avoid excessive stack
  456. * use. Most hardware errors are catastrophic, but for right now,
  457. * we'll print them and continue. We reuse the same message buffer as
  458. * ipath_handle_errors() to avoid excessive stack usage.
  459. */
  460. static void ipath_ht_handle_hwerrors(struct ipath_devdata *dd, char *msg,
  461. size_t msgl)
  462. {
  463. ipath_err_t hwerrs;
  464. u32 bits, ctrl;
  465. int isfatal = 0;
  466. char bitsmsg[64];
  467. int log_idx;
  468. hwerrs = ipath_read_kreg64(dd, dd->ipath_kregs->kr_hwerrstatus);
  469. if (!hwerrs) {
  470. ipath_cdbg(VERBOSE, "Called but no hardware errors set\n");
  471. /*
  472. * better than printing cofusing messages
  473. * This seems to be related to clearing the crc error, or
  474. * the pll error during init.
  475. */
  476. goto bail;
  477. } else if (hwerrs == -1LL) {
  478. ipath_dev_err(dd, "Read of hardware error status failed "
  479. "(all bits set); ignoring\n");
  480. goto bail;
  481. }
  482. ipath_stats.sps_hwerrs++;
  483. /* Always clear the error status register, except MEMBISTFAIL,
  484. * regardless of whether we continue or stop using the chip.
  485. * We want that set so we know it failed, even across driver reload.
  486. * We'll still ignore it in the hwerrmask. We do this partly for
  487. * diagnostics, but also for support */
  488. ipath_write_kreg(dd, dd->ipath_kregs->kr_hwerrclear,
  489. hwerrs&~INFINIPATH_HWE_MEMBISTFAILED);
  490. hwerrs &= dd->ipath_hwerrmask;
  491. /* We log some errors to EEPROM, check if we have any of those. */
  492. for (log_idx = 0; log_idx < IPATH_EEP_LOG_CNT; ++log_idx)
  493. if (hwerrs & dd->ipath_eep_st_masks[log_idx].hwerrs_to_log)
  494. ipath_inc_eeprom_err(dd, log_idx, 1);
  495. /*
  496. * make sure we get this much out, unless told to be quiet,
  497. * it's a parity error we may recover from,
  498. * or it's occurred within the last 5 seconds
  499. */
  500. if ((hwerrs & ~(dd->ipath_lasthwerror | TXE_PIO_PARITY |
  501. RXE_EAGER_PARITY)) ||
  502. (ipath_debug & __IPATH_VERBDBG))
  503. dev_info(&dd->pcidev->dev, "Hardware error: hwerr=0x%llx "
  504. "(cleared)\n", (unsigned long long) hwerrs);
  505. dd->ipath_lasthwerror |= hwerrs;
  506. if (hwerrs & ~dd->ipath_hwe_bitsextant)
  507. ipath_dev_err(dd, "hwerror interrupt with unknown errors "
  508. "%llx set\n", (unsigned long long)
  509. (hwerrs & ~dd->ipath_hwe_bitsextant));
  510. ctrl = ipath_read_kreg32(dd, dd->ipath_kregs->kr_control);
  511. if ((ctrl & INFINIPATH_C_FREEZEMODE) && !ipath_diag_inuse) {
  512. /*
  513. * parity errors in send memory are recoverable,
  514. * just cancel the send (if indicated in * sendbuffererror),
  515. * count the occurrence, unfreeze (if no other handled
  516. * hardware error bits are set), and continue. They can
  517. * occur if a processor speculative read is done to the PIO
  518. * buffer while we are sending a packet, for example.
  519. */
  520. if ((hwerrs & TXE_PIO_PARITY) && ipath_ht_txe_recover(dd))
  521. hwerrs &= ~TXE_PIO_PARITY;
  522. if (hwerrs & RXE_EAGER_PARITY)
  523. ipath_dev_err(dd, "RXE parity, Eager TID error is not "
  524. "recoverable\n");
  525. if (!hwerrs) {
  526. ipath_dbg("Clearing freezemode on ignored or "
  527. "recovered hardware error\n");
  528. ipath_clear_freeze(dd);
  529. }
  530. }
  531. *msg = '\0';
  532. /*
  533. * may someday want to decode into which bits are which
  534. * functional area for parity errors, etc.
  535. */
  536. if (hwerrs & (infinipath_hwe_htcmemparityerr_mask
  537. << INFINIPATH_HWE_HTCMEMPARITYERR_SHIFT)) {
  538. bits = (u32) ((hwerrs >>
  539. INFINIPATH_HWE_HTCMEMPARITYERR_SHIFT) &
  540. INFINIPATH_HWE_HTCMEMPARITYERR_MASK);
  541. snprintf(bitsmsg, sizeof bitsmsg, "[HTC Parity Errs %x] ",
  542. bits);
  543. strlcat(msg, bitsmsg, msgl);
  544. }
  545. ipath_format_hwerrors(hwerrs,
  546. ipath_6110_hwerror_msgs,
  547. sizeof(ipath_6110_hwerror_msgs) /
  548. sizeof(ipath_6110_hwerror_msgs[0]),
  549. msg, msgl);
  550. if (hwerrs & (_IPATH_HTLINK0_CRCBITS | _IPATH_HTLINK1_CRCBITS))
  551. hwerr_crcbits(dd, hwerrs, msg, msgl);
  552. if (hwerrs & INFINIPATH_HWE_MEMBISTFAILED) {
  553. strlcat(msg, "[Memory BIST test failed, InfiniPath hardware unusable]",
  554. msgl);
  555. /* ignore from now on, so disable until driver reloaded */
  556. dd->ipath_hwerrmask &= ~INFINIPATH_HWE_MEMBISTFAILED;
  557. ipath_write_kreg(dd, dd->ipath_kregs->kr_hwerrmask,
  558. dd->ipath_hwerrmask);
  559. }
  560. #define _IPATH_PLL_FAIL (INFINIPATH_HWE_COREPLL_FBSLIP | \
  561. INFINIPATH_HWE_COREPLL_RFSLIP | \
  562. INFINIPATH_HWE_HTBPLL_FBSLIP | \
  563. INFINIPATH_HWE_HTBPLL_RFSLIP | \
  564. INFINIPATH_HWE_HTAPLL_FBSLIP | \
  565. INFINIPATH_HWE_HTAPLL_RFSLIP)
  566. if (hwerrs & _IPATH_PLL_FAIL) {
  567. snprintf(bitsmsg, sizeof bitsmsg,
  568. "[PLL failed (%llx), InfiniPath hardware unusable]",
  569. (unsigned long long) (hwerrs & _IPATH_PLL_FAIL));
  570. strlcat(msg, bitsmsg, msgl);
  571. /* ignore from now on, so disable until driver reloaded */
  572. dd->ipath_hwerrmask &= ~(hwerrs & _IPATH_PLL_FAIL);
  573. ipath_write_kreg(dd, dd->ipath_kregs->kr_hwerrmask,
  574. dd->ipath_hwerrmask);
  575. }
  576. if (hwerrs & INFINIPATH_HWE_SERDESPLLFAILED) {
  577. /*
  578. * If it occurs, it is left masked since the eternal
  579. * interface is unused
  580. */
  581. dd->ipath_hwerrmask &= ~INFINIPATH_HWE_SERDESPLLFAILED;
  582. ipath_write_kreg(dd, dd->ipath_kregs->kr_hwerrmask,
  583. dd->ipath_hwerrmask);
  584. }
  585. if (hwerrs) {
  586. /*
  587. * if any set that we aren't ignoring; only
  588. * make the complaint once, in case it's stuck
  589. * or recurring, and we get here multiple
  590. * times.
  591. * force link down, so switch knows, and
  592. * LEDs are turned off
  593. */
  594. if (dd->ipath_flags & IPATH_INITTED) {
  595. ipath_set_linkstate(dd, IPATH_IB_LINKDOWN);
  596. ipath_setup_ht_setextled(dd,
  597. INFINIPATH_IBCS_L_STATE_DOWN,
  598. INFINIPATH_IBCS_LT_STATE_DISABLED);
  599. ipath_dev_err(dd, "Fatal Hardware Error (freeze "
  600. "mode), no longer usable, SN %.16s\n",
  601. dd->ipath_serial);
  602. isfatal = 1;
  603. }
  604. *dd->ipath_statusp &= ~IPATH_STATUS_IB_READY;
  605. /* mark as having had error */
  606. *dd->ipath_statusp |= IPATH_STATUS_HWERROR;
  607. /*
  608. * mark as not usable, at a minimum until driver
  609. * is reloaded, probably until reboot, since no
  610. * other reset is possible.
  611. */
  612. dd->ipath_flags &= ~IPATH_INITTED;
  613. }
  614. else
  615. *msg = 0; /* recovered from all of them */
  616. if (*msg)
  617. ipath_dev_err(dd, "%s hardware error\n", msg);
  618. if (isfatal && !ipath_diag_inuse && dd->ipath_freezemsg)
  619. /*
  620. * for status file; if no trailing brace is copied,
  621. * we'll know it was truncated.
  622. */
  623. snprintf(dd->ipath_freezemsg,
  624. dd->ipath_freezelen, "{%s}", msg);
  625. bail:;
  626. }
  627. /**
  628. * ipath_ht_boardname - fill in the board name
  629. * @dd: the infinipath device
  630. * @name: the output buffer
  631. * @namelen: the size of the output buffer
  632. *
  633. * fill in the board name, based on the board revision register
  634. */
  635. static int ipath_ht_boardname(struct ipath_devdata *dd, char *name,
  636. size_t namelen)
  637. {
  638. char *n = NULL;
  639. u8 boardrev = dd->ipath_boardrev;
  640. int ret = 0;
  641. switch (boardrev) {
  642. case 5:
  643. /*
  644. * original production board; two production levels, with
  645. * different serial number ranges. See ipath_ht_early_init() for
  646. * case where we enable IPATH_GPIO_INTR for later serial # range.
  647. * Original 112* serial number is no longer supported.
  648. */
  649. n = "InfiniPath_QHT7040";
  650. break;
  651. case 7:
  652. /* small form factor production board */
  653. n = "InfiniPath_QHT7140";
  654. break;
  655. default: /* don't know, just print the number */
  656. ipath_dev_err(dd, "Don't yet know about board "
  657. "with ID %u\n", boardrev);
  658. snprintf(name, namelen, "Unknown_InfiniPath_QHT7xxx_%u",
  659. boardrev);
  660. break;
  661. }
  662. if (n)
  663. snprintf(name, namelen, "%s", n);
  664. if (ret) {
  665. ipath_dev_err(dd, "Unsupported InfiniPath board %s!\n", name);
  666. goto bail;
  667. }
  668. if (dd->ipath_majrev != 3 || (dd->ipath_minrev < 2 ||
  669. dd->ipath_minrev > 4)) {
  670. /*
  671. * This version of the driver only supports Rev 3.2 - 3.4
  672. */
  673. ipath_dev_err(dd,
  674. "Unsupported InfiniPath hardware revision %u.%u!\n",
  675. dd->ipath_majrev, dd->ipath_minrev);
  676. ret = 1;
  677. goto bail;
  678. }
  679. /*
  680. * pkt/word counters are 32 bit, and therefore wrap fast enough
  681. * that we snapshot them from a timer, and maintain 64 bit shadow
  682. * copies
  683. */
  684. dd->ipath_flags |= IPATH_32BITCOUNTERS;
  685. dd->ipath_flags |= IPATH_GPIO_INTR;
  686. if (dd->ipath_htspeed != 800)
  687. ipath_dev_err(dd,
  688. "Incorrectly configured for HT @ %uMHz\n",
  689. dd->ipath_htspeed);
  690. ret = 0;
  691. /*
  692. * set here, not in ipath_init_*_funcs because we have to do
  693. * it after we can read chip registers.
  694. */
  695. dd->ipath_ureg_align =
  696. ipath_read_kreg32(dd, dd->ipath_kregs->kr_pagealign);
  697. bail:
  698. return ret;
  699. }
  700. static void ipath_check_htlink(struct ipath_devdata *dd)
  701. {
  702. u8 linkerr, link_off, i;
  703. for (i = 0; i < 2; i++) {
  704. link_off = dd->ipath_ht_slave_off + i * 4 + 0xd;
  705. if (pci_read_config_byte(dd->pcidev, link_off, &linkerr))
  706. dev_info(&dd->pcidev->dev, "Couldn't read "
  707. "linkerror%d of HT slave/primary block\n",
  708. i);
  709. else if (linkerr & 0xf0) {
  710. ipath_cdbg(VERBOSE, "HT linkerr%d bits 0x%x set, "
  711. "clearing\n", linkerr >> 4, i);
  712. /*
  713. * writing the linkerr bits that are set should
  714. * clear them
  715. */
  716. if (pci_write_config_byte(dd->pcidev, link_off,
  717. linkerr))
  718. ipath_dbg("Failed write to clear HT "
  719. "linkerror%d\n", i);
  720. if (pci_read_config_byte(dd->pcidev, link_off,
  721. &linkerr))
  722. dev_info(&dd->pcidev->dev,
  723. "Couldn't reread linkerror%d of "
  724. "HT slave/primary block\n", i);
  725. else if (linkerr & 0xf0)
  726. dev_info(&dd->pcidev->dev,
  727. "HT linkerror%d bits 0x%x "
  728. "couldn't be cleared\n",
  729. i, linkerr >> 4);
  730. }
  731. }
  732. }
  733. static int ipath_setup_ht_reset(struct ipath_devdata *dd)
  734. {
  735. ipath_dbg("No reset possible for this InfiniPath hardware\n");
  736. return 0;
  737. }
  738. #define HT_INTR_DISC_CONFIG 0x80 /* HT interrupt and discovery cap */
  739. #define HT_INTR_REG_INDEX 2 /* intconfig requires indirect accesses */
  740. /*
  741. * Bits 13-15 of command==0 is slave/primary block. Clear any HT CRC
  742. * errors. We only bother to do this at load time, because it's OK if
  743. * it happened before we were loaded (first time after boot/reset),
  744. * but any time after that, it's fatal anyway. Also need to not check
  745. * for for upper byte errors if we are in 8 bit mode, so figure out
  746. * our width. For now, at least, also complain if it's 8 bit.
  747. */
  748. static void slave_or_pri_blk(struct ipath_devdata *dd, struct pci_dev *pdev,
  749. int pos, u8 cap_type)
  750. {
  751. u8 linkwidth = 0, linkerr, link_a_b_off, link_off;
  752. u16 linkctrl = 0;
  753. int i;
  754. dd->ipath_ht_slave_off = pos;
  755. /* command word, master_host bit */
  756. /* master host || slave */
  757. if ((cap_type >> 2) & 1)
  758. link_a_b_off = 4;
  759. else
  760. link_a_b_off = 0;
  761. ipath_cdbg(VERBOSE, "HT%u (Link %c) connected to processor\n",
  762. link_a_b_off ? 1 : 0,
  763. link_a_b_off ? 'B' : 'A');
  764. link_a_b_off += pos;
  765. /*
  766. * check both link control registers; clear both HT CRC sets if
  767. * necessary.
  768. */
  769. for (i = 0; i < 2; i++) {
  770. link_off = pos + i * 4 + 0x4;
  771. if (pci_read_config_word(pdev, link_off, &linkctrl))
  772. ipath_dev_err(dd, "Couldn't read HT link control%d "
  773. "register\n", i);
  774. else if (linkctrl & (0xf << 8)) {
  775. ipath_cdbg(VERBOSE, "Clear linkctrl%d CRC Error "
  776. "bits %x\n", i, linkctrl & (0xf << 8));
  777. /*
  778. * now write them back to clear the error.
  779. */
  780. pci_write_config_byte(pdev, link_off,
  781. linkctrl & (0xf << 8));
  782. }
  783. }
  784. /*
  785. * As with HT CRC bits, same for protocol errors that might occur
  786. * during boot.
  787. */
  788. for (i = 0; i < 2; i++) {
  789. link_off = pos + i * 4 + 0xd;
  790. if (pci_read_config_byte(pdev, link_off, &linkerr))
  791. dev_info(&pdev->dev, "Couldn't read linkerror%d "
  792. "of HT slave/primary block\n", i);
  793. else if (linkerr & 0xf0) {
  794. ipath_cdbg(VERBOSE, "HT linkerr%d bits 0x%x set, "
  795. "clearing\n", linkerr >> 4, i);
  796. /*
  797. * writing the linkerr bits that are set will clear
  798. * them
  799. */
  800. if (pci_write_config_byte
  801. (pdev, link_off, linkerr))
  802. ipath_dbg("Failed write to clear HT "
  803. "linkerror%d\n", i);
  804. if (pci_read_config_byte(pdev, link_off, &linkerr))
  805. dev_info(&pdev->dev, "Couldn't reread "
  806. "linkerror%d of HT slave/primary "
  807. "block\n", i);
  808. else if (linkerr & 0xf0)
  809. dev_info(&pdev->dev, "HT linkerror%d bits "
  810. "0x%x couldn't be cleared\n",
  811. i, linkerr >> 4);
  812. }
  813. }
  814. /*
  815. * this is just for our link to the host, not devices connected
  816. * through tunnel.
  817. */
  818. if (pci_read_config_byte(pdev, link_a_b_off + 7, &linkwidth))
  819. ipath_dev_err(dd, "Couldn't read HT link width "
  820. "config register\n");
  821. else {
  822. u32 width;
  823. switch (linkwidth & 7) {
  824. case 5:
  825. width = 4;
  826. break;
  827. case 4:
  828. width = 2;
  829. break;
  830. case 3:
  831. width = 32;
  832. break;
  833. case 1:
  834. width = 16;
  835. break;
  836. case 0:
  837. default: /* if wrong, assume 8 bit */
  838. width = 8;
  839. break;
  840. }
  841. dd->ipath_htwidth = width;
  842. if (linkwidth != 0x11) {
  843. ipath_dev_err(dd, "Not configured for 16 bit HT "
  844. "(%x)\n", linkwidth);
  845. if (!(linkwidth & 0xf)) {
  846. ipath_dbg("Will ignore HT lane1 errors\n");
  847. dd->ipath_flags |= IPATH_8BIT_IN_HT0;
  848. }
  849. }
  850. }
  851. /*
  852. * this is just for our link to the host, not devices connected
  853. * through tunnel.
  854. */
  855. if (pci_read_config_byte(pdev, link_a_b_off + 0xd, &linkwidth))
  856. ipath_dev_err(dd, "Couldn't read HT link frequency "
  857. "config register\n");
  858. else {
  859. u32 speed;
  860. switch (linkwidth & 0xf) {
  861. case 6:
  862. speed = 1000;
  863. break;
  864. case 5:
  865. speed = 800;
  866. break;
  867. case 4:
  868. speed = 600;
  869. break;
  870. case 3:
  871. speed = 500;
  872. break;
  873. case 2:
  874. speed = 400;
  875. break;
  876. case 1:
  877. speed = 300;
  878. break;
  879. default:
  880. /*
  881. * assume reserved and vendor-specific are 200...
  882. */
  883. case 0:
  884. speed = 200;
  885. break;
  886. }
  887. dd->ipath_htspeed = speed;
  888. }
  889. }
  890. static int ipath_ht_intconfig(struct ipath_devdata *dd)
  891. {
  892. int ret;
  893. if (dd->ipath_intconfig) {
  894. ipath_write_kreg(dd, dd->ipath_kregs->kr_interruptconfig,
  895. dd->ipath_intconfig); /* interrupt address */
  896. ret = 0;
  897. } else {
  898. ipath_dev_err(dd, "No interrupts enabled, couldn't setup "
  899. "interrupt address\n");
  900. ret = -EINVAL;
  901. }
  902. return ret;
  903. }
  904. static void ipath_ht_irq_update(struct pci_dev *dev, int irq,
  905. struct ht_irq_msg *msg)
  906. {
  907. struct ipath_devdata *dd = pci_get_drvdata(dev);
  908. u64 prev_intconfig = dd->ipath_intconfig;
  909. dd->ipath_intconfig = msg->address_lo;
  910. dd->ipath_intconfig |= ((u64) msg->address_hi) << 32;
  911. /*
  912. * If the previous value of dd->ipath_intconfig is zero, we're
  913. * getting configured for the first time, and must not program the
  914. * intconfig register here (it will be programmed later, when the
  915. * hardware is ready). Otherwise, we should.
  916. */
  917. if (prev_intconfig)
  918. ipath_ht_intconfig(dd);
  919. }
  920. /**
  921. * ipath_setup_ht_config - setup the interruptconfig register
  922. * @dd: the infinipath device
  923. * @pdev: the PCI device
  924. *
  925. * setup the interruptconfig register from the HT config info.
  926. * Also clear CRC errors in HT linkcontrol, if necessary.
  927. * This is done only for the real hardware. It is done before
  928. * chip address space is initted, so can't touch infinipath registers
  929. */
  930. static int ipath_setup_ht_config(struct ipath_devdata *dd,
  931. struct pci_dev *pdev)
  932. {
  933. int pos, ret;
  934. ret = __ht_create_irq(pdev, 0, ipath_ht_irq_update);
  935. if (ret < 0) {
  936. ipath_dev_err(dd, "Couldn't create interrupt handler: "
  937. "err %d\n", ret);
  938. goto bail;
  939. }
  940. dd->ipath_irq = ret;
  941. ret = 0;
  942. /*
  943. * Handle clearing CRC errors in linkctrl register if necessary. We
  944. * do this early, before we ever enable errors or hardware errors,
  945. * mostly to avoid causing the chip to enter freeze mode.
  946. */
  947. pos = pci_find_capability(pdev, PCI_CAP_ID_HT);
  948. if (!pos) {
  949. ipath_dev_err(dd, "Couldn't find HyperTransport "
  950. "capability; no interrupts\n");
  951. ret = -ENODEV;
  952. goto bail;
  953. }
  954. do {
  955. u8 cap_type;
  956. /*
  957. * The HT capability type byte is 3 bytes after the
  958. * capability byte.
  959. */
  960. if (pci_read_config_byte(pdev, pos + 3, &cap_type)) {
  961. dev_info(&pdev->dev, "Couldn't read config "
  962. "command @ %d\n", pos);
  963. continue;
  964. }
  965. if (!(cap_type & 0xE0))
  966. slave_or_pri_blk(dd, pdev, pos, cap_type);
  967. } while ((pos = pci_find_next_capability(pdev, pos,
  968. PCI_CAP_ID_HT)));
  969. dd->ipath_flags |= IPATH_SWAP_PIOBUFS;
  970. bail:
  971. return ret;
  972. }
  973. /**
  974. * ipath_setup_ht_cleanup - clean up any per-chip chip-specific stuff
  975. * @dd: the infinipath device
  976. *
  977. * Called during driver unload.
  978. * This is currently a nop for the HT chip, not for all chips
  979. */
  980. static void ipath_setup_ht_cleanup(struct ipath_devdata *dd)
  981. {
  982. }
  983. /**
  984. * ipath_setup_ht_setextled - set the state of the two external LEDs
  985. * @dd: the infinipath device
  986. * @lst: the L state
  987. * @ltst: the LT state
  988. *
  989. * Set the state of the two external LEDs, to indicate physical and
  990. * logical state of IB link. For this chip (at least with recommended
  991. * board pinouts), LED1 is Green (physical state), and LED2 is Yellow
  992. * (logical state)
  993. *
  994. * Note: We try to match the Mellanox HCA LED behavior as best
  995. * we can. Green indicates physical link state is OK (something is
  996. * plugged in, and we can train).
  997. * Amber indicates the link is logically up (ACTIVE).
  998. * Mellanox further blinks the amber LED to indicate data packet
  999. * activity, but we have no hardware support for that, so it would
  1000. * require waking up every 10-20 msecs and checking the counters
  1001. * on the chip, and then turning the LED off if appropriate. That's
  1002. * visible overhead, so not something we will do.
  1003. *
  1004. */
  1005. static void ipath_setup_ht_setextled(struct ipath_devdata *dd,
  1006. u64 lst, u64 ltst)
  1007. {
  1008. u64 extctl;
  1009. unsigned long flags = 0;
  1010. /* the diags use the LED to indicate diag info, so we leave
  1011. * the external LED alone when the diags are running */
  1012. if (ipath_diag_inuse)
  1013. return;
  1014. /* Allow override of LED display for, e.g. Locating system in rack */
  1015. if (dd->ipath_led_override) {
  1016. ltst = (dd->ipath_led_override & IPATH_LED_PHYS)
  1017. ? INFINIPATH_IBCS_LT_STATE_LINKUP
  1018. : INFINIPATH_IBCS_LT_STATE_DISABLED;
  1019. lst = (dd->ipath_led_override & IPATH_LED_LOG)
  1020. ? INFINIPATH_IBCS_L_STATE_ACTIVE
  1021. : INFINIPATH_IBCS_L_STATE_DOWN;
  1022. }
  1023. spin_lock_irqsave(&dd->ipath_gpio_lock, flags);
  1024. /*
  1025. * start by setting both LED control bits to off, then turn
  1026. * on the appropriate bit(s).
  1027. */
  1028. if (dd->ipath_boardrev == 8) { /* LS/X-1 uses different pins */
  1029. /*
  1030. * major difference is that INFINIPATH_EXTC_LEDGBLERR_OFF
  1031. * is inverted, because it is normally used to indicate
  1032. * a hardware fault at reset, if there were errors
  1033. */
  1034. extctl = (dd->ipath_extctrl & ~INFINIPATH_EXTC_LEDGBLOK_ON)
  1035. | INFINIPATH_EXTC_LEDGBLERR_OFF;
  1036. if (ltst == INFINIPATH_IBCS_LT_STATE_LINKUP)
  1037. extctl &= ~INFINIPATH_EXTC_LEDGBLERR_OFF;
  1038. if (lst == INFINIPATH_IBCS_L_STATE_ACTIVE)
  1039. extctl |= INFINIPATH_EXTC_LEDGBLOK_ON;
  1040. }
  1041. else {
  1042. extctl = dd->ipath_extctrl &
  1043. ~(INFINIPATH_EXTC_LED1PRIPORT_ON |
  1044. INFINIPATH_EXTC_LED2PRIPORT_ON);
  1045. if (ltst == INFINIPATH_IBCS_LT_STATE_LINKUP)
  1046. extctl |= INFINIPATH_EXTC_LED1PRIPORT_ON;
  1047. if (lst == INFINIPATH_IBCS_L_STATE_ACTIVE)
  1048. extctl |= INFINIPATH_EXTC_LED2PRIPORT_ON;
  1049. }
  1050. dd->ipath_extctrl = extctl;
  1051. ipath_write_kreg(dd, dd->ipath_kregs->kr_extctrl, extctl);
  1052. spin_unlock_irqrestore(&dd->ipath_gpio_lock, flags);
  1053. }
  1054. static void ipath_init_ht_variables(struct ipath_devdata *dd)
  1055. {
  1056. /*
  1057. * setup the register offsets, since they are different for each
  1058. * chip
  1059. */
  1060. dd->ipath_kregs = &ipath_ht_kregs;
  1061. dd->ipath_cregs = &ipath_ht_cregs;
  1062. dd->ipath_gpio_sda_num = _IPATH_GPIO_SDA_NUM;
  1063. dd->ipath_gpio_scl_num = _IPATH_GPIO_SCL_NUM;
  1064. dd->ipath_gpio_sda = IPATH_GPIO_SDA;
  1065. dd->ipath_gpio_scl = IPATH_GPIO_SCL;
  1066. /*
  1067. * Fill in data for field-values that change in newer chips.
  1068. * We dynamically specify only the mask for LINKTRAININGSTATE
  1069. * and only the shift for LINKSTATE, as they are the only ones
  1070. * that change. Also precalculate the 3 link states of interest
  1071. * and the combined mask.
  1072. */
  1073. dd->ibcs_ls_shift = IBA6110_IBCS_LINKSTATE_SHIFT;
  1074. dd->ibcs_lts_mask = IBA6110_IBCS_LINKTRAININGSTATE_MASK;
  1075. dd->ibcs_mask = (INFINIPATH_IBCS_LINKSTATE_MASK <<
  1076. dd->ibcs_ls_shift) | dd->ibcs_lts_mask;
  1077. dd->ib_init = (INFINIPATH_IBCS_LT_STATE_LINKUP <<
  1078. INFINIPATH_IBCS_LINKTRAININGSTATE_SHIFT) |
  1079. (INFINIPATH_IBCS_L_STATE_INIT << dd->ibcs_ls_shift);
  1080. dd->ib_arm = (INFINIPATH_IBCS_LT_STATE_LINKUP <<
  1081. INFINIPATH_IBCS_LINKTRAININGSTATE_SHIFT) |
  1082. (INFINIPATH_IBCS_L_STATE_ARM << dd->ibcs_ls_shift);
  1083. dd->ib_active = (INFINIPATH_IBCS_LT_STATE_LINKUP <<
  1084. INFINIPATH_IBCS_LINKTRAININGSTATE_SHIFT) |
  1085. (INFINIPATH_IBCS_L_STATE_ACTIVE << dd->ibcs_ls_shift);
  1086. /*
  1087. * Fill in data for ibcc field-values that change in newer chips.
  1088. * We dynamically specify only the mask for LINKINITCMD
  1089. * and only the shift for LINKCMD and MAXPKTLEN, as they are
  1090. * the only ones that change.
  1091. */
  1092. dd->ibcc_lic_mask = INFINIPATH_IBCC_LINKINITCMD_MASK;
  1093. dd->ibcc_lc_shift = INFINIPATH_IBCC_LINKCMD_SHIFT;
  1094. dd->ibcc_mpl_shift = INFINIPATH_IBCC_MAXPKTLEN_SHIFT;
  1095. /* Fill in shifts for RcvCtrl. */
  1096. dd->ipath_r_portenable_shift = INFINIPATH_R_PORTENABLE_SHIFT;
  1097. dd->ipath_r_intravail_shift = INFINIPATH_R_INTRAVAIL_SHIFT;
  1098. dd->ipath_r_tailupd_shift = INFINIPATH_R_TAILUPD_SHIFT;
  1099. dd->ipath_r_portcfg_shift = 0; /* Not on IBA6110 */
  1100. dd->ipath_i_bitsextant =
  1101. (INFINIPATH_I_RCVURG_MASK << INFINIPATH_I_RCVURG_SHIFT) |
  1102. (INFINIPATH_I_RCVAVAIL_MASK <<
  1103. INFINIPATH_I_RCVAVAIL_SHIFT) |
  1104. INFINIPATH_I_ERROR | INFINIPATH_I_SPIOSENT |
  1105. INFINIPATH_I_SPIOBUFAVAIL | INFINIPATH_I_GPIO;
  1106. dd->ipath_e_bitsextant =
  1107. INFINIPATH_E_RFORMATERR | INFINIPATH_E_RVCRC |
  1108. INFINIPATH_E_RICRC | INFINIPATH_E_RMINPKTLEN |
  1109. INFINIPATH_E_RMAXPKTLEN | INFINIPATH_E_RLONGPKTLEN |
  1110. INFINIPATH_E_RSHORTPKTLEN | INFINIPATH_E_RUNEXPCHAR |
  1111. INFINIPATH_E_RUNSUPVL | INFINIPATH_E_REBP |
  1112. INFINIPATH_E_RIBFLOW | INFINIPATH_E_RBADVERSION |
  1113. INFINIPATH_E_RRCVEGRFULL | INFINIPATH_E_RRCVHDRFULL |
  1114. INFINIPATH_E_RBADTID | INFINIPATH_E_RHDRLEN |
  1115. INFINIPATH_E_RHDR | INFINIPATH_E_RIBLOSTLINK |
  1116. INFINIPATH_E_SMINPKTLEN | INFINIPATH_E_SMAXPKTLEN |
  1117. INFINIPATH_E_SUNDERRUN | INFINIPATH_E_SPKTLEN |
  1118. INFINIPATH_E_SDROPPEDSMPPKT | INFINIPATH_E_SDROPPEDDATAPKT |
  1119. INFINIPATH_E_SPIOARMLAUNCH | INFINIPATH_E_SUNEXPERRPKTNUM |
  1120. INFINIPATH_E_SUNSUPVL | INFINIPATH_E_IBSTATUSCHANGED |
  1121. INFINIPATH_E_INVALIDADDR | INFINIPATH_E_RESET |
  1122. INFINIPATH_E_HARDWARE;
  1123. dd->ipath_hwe_bitsextant =
  1124. (INFINIPATH_HWE_HTCMEMPARITYERR_MASK <<
  1125. INFINIPATH_HWE_HTCMEMPARITYERR_SHIFT) |
  1126. (INFINIPATH_HWE_TXEMEMPARITYERR_MASK <<
  1127. INFINIPATH_HWE_TXEMEMPARITYERR_SHIFT) |
  1128. (INFINIPATH_HWE_RXEMEMPARITYERR_MASK <<
  1129. INFINIPATH_HWE_RXEMEMPARITYERR_SHIFT) |
  1130. INFINIPATH_HWE_HTCLNKABYTE0CRCERR |
  1131. INFINIPATH_HWE_HTCLNKABYTE1CRCERR |
  1132. INFINIPATH_HWE_HTCLNKBBYTE0CRCERR |
  1133. INFINIPATH_HWE_HTCLNKBBYTE1CRCERR |
  1134. INFINIPATH_HWE_HTCMISCERR4 |
  1135. INFINIPATH_HWE_HTCMISCERR5 | INFINIPATH_HWE_HTCMISCERR6 |
  1136. INFINIPATH_HWE_HTCMISCERR7 |
  1137. INFINIPATH_HWE_HTCBUSTREQPARITYERR |
  1138. INFINIPATH_HWE_HTCBUSTRESPPARITYERR |
  1139. INFINIPATH_HWE_HTCBUSIREQPARITYERR |
  1140. INFINIPATH_HWE_RXDSYNCMEMPARITYERR |
  1141. INFINIPATH_HWE_MEMBISTFAILED |
  1142. INFINIPATH_HWE_COREPLL_FBSLIP |
  1143. INFINIPATH_HWE_COREPLL_RFSLIP |
  1144. INFINIPATH_HWE_HTBPLL_FBSLIP |
  1145. INFINIPATH_HWE_HTBPLL_RFSLIP |
  1146. INFINIPATH_HWE_HTAPLL_FBSLIP |
  1147. INFINIPATH_HWE_HTAPLL_RFSLIP |
  1148. INFINIPATH_HWE_SERDESPLLFAILED |
  1149. INFINIPATH_HWE_IBCBUSTOSPCPARITYERR |
  1150. INFINIPATH_HWE_IBCBUSFRSPCPARITYERR;
  1151. dd->ipath_i_rcvavail_mask = INFINIPATH_I_RCVAVAIL_MASK;
  1152. dd->ipath_i_rcvurg_mask = INFINIPATH_I_RCVURG_MASK;
  1153. dd->ipath_i_rcvavail_shift = INFINIPATH_I_RCVAVAIL_SHIFT;
  1154. dd->ipath_i_rcvurg_shift = INFINIPATH_I_RCVURG_SHIFT;
  1155. /*
  1156. * EEPROM error log 0 is TXE Parity errors. 1 is RXE Parity.
  1157. * 2 is Some Misc, 3 is reserved for future.
  1158. */
  1159. dd->ipath_eep_st_masks[0].hwerrs_to_log =
  1160. INFINIPATH_HWE_TXEMEMPARITYERR_MASK <<
  1161. INFINIPATH_HWE_TXEMEMPARITYERR_SHIFT;
  1162. dd->ipath_eep_st_masks[1].hwerrs_to_log =
  1163. INFINIPATH_HWE_RXEMEMPARITYERR_MASK <<
  1164. INFINIPATH_HWE_RXEMEMPARITYERR_SHIFT;
  1165. dd->ipath_eep_st_masks[2].errs_to_log = INFINIPATH_E_RESET;
  1166. dd->delay_mult = 2; /* SDR, 4X, can't change */
  1167. dd->ipath_link_width_supported = IB_WIDTH_1X | IB_WIDTH_4X;
  1168. dd->ipath_link_speed_supported = IPATH_IB_SDR;
  1169. dd->ipath_link_width_enabled = IB_WIDTH_4X;
  1170. dd->ipath_link_speed_enabled = dd->ipath_link_speed_supported;
  1171. /* these can't change for this chip, so set once */
  1172. dd->ipath_link_width_active = dd->ipath_link_width_enabled;
  1173. dd->ipath_link_speed_active = dd->ipath_link_speed_enabled;
  1174. }
  1175. /**
  1176. * ipath_ht_init_hwerrors - enable hardware errors
  1177. * @dd: the infinipath device
  1178. *
  1179. * now that we have finished initializing everything that might reasonably
  1180. * cause a hardware error, and cleared those errors bits as they occur,
  1181. * we can enable hardware errors in the mask (potentially enabling
  1182. * freeze mode), and enable hardware errors as errors (along with
  1183. * everything else) in errormask
  1184. */
  1185. static void ipath_ht_init_hwerrors(struct ipath_devdata *dd)
  1186. {
  1187. ipath_err_t val;
  1188. u64 extsval;
  1189. extsval = ipath_read_kreg64(dd, dd->ipath_kregs->kr_extstatus);
  1190. if (!(extsval & INFINIPATH_EXTS_MEMBIST_ENDTEST))
  1191. ipath_dev_err(dd, "MemBIST did not complete!\n");
  1192. if (extsval & INFINIPATH_EXTS_MEMBIST_CORRECT)
  1193. ipath_dbg("MemBIST corrected\n");
  1194. ipath_check_htlink(dd);
  1195. /* barring bugs, all hwerrors become interrupts, which can */
  1196. val = -1LL;
  1197. /* don't look at crc lane1 if 8 bit */
  1198. if (dd->ipath_flags & IPATH_8BIT_IN_HT0)
  1199. val &= ~infinipath_hwe_htclnkabyte1crcerr;
  1200. /* don't look at crc lane1 if 8 bit */
  1201. if (dd->ipath_flags & IPATH_8BIT_IN_HT1)
  1202. val &= ~infinipath_hwe_htclnkbbyte1crcerr;
  1203. /*
  1204. * disable RXDSYNCMEMPARITY because external serdes is unused,
  1205. * and therefore the logic will never be used or initialized,
  1206. * and uninitialized state will normally result in this error
  1207. * being asserted. Similarly for the external serdess pll
  1208. * lock signal.
  1209. */
  1210. val &= ~(INFINIPATH_HWE_SERDESPLLFAILED |
  1211. INFINIPATH_HWE_RXDSYNCMEMPARITYERR);
  1212. /*
  1213. * Disable MISCERR4 because of an inversion in the HT core
  1214. * logic checking for errors that cause this bit to be set.
  1215. * The errata can also cause the protocol error bit to be set
  1216. * in the HT config space linkerror register(s).
  1217. */
  1218. val &= ~INFINIPATH_HWE_HTCMISCERR4;
  1219. /*
  1220. * PLL ignored because unused MDIO interface has a logic problem
  1221. */
  1222. if (dd->ipath_boardrev == 4 || dd->ipath_boardrev == 9)
  1223. val &= ~INFINIPATH_HWE_SERDESPLLFAILED;
  1224. dd->ipath_hwerrmask = val;
  1225. }
  1226. /**
  1227. * ipath_ht_bringup_serdes - bring up the serdes
  1228. * @dd: the infinipath device
  1229. */
  1230. static int ipath_ht_bringup_serdes(struct ipath_devdata *dd)
  1231. {
  1232. u64 val, config1;
  1233. int ret = 0, change = 0;
  1234. ipath_dbg("Trying to bringup serdes\n");
  1235. if (ipath_read_kreg64(dd, dd->ipath_kregs->kr_hwerrstatus) &
  1236. INFINIPATH_HWE_SERDESPLLFAILED)
  1237. {
  1238. ipath_dbg("At start, serdes PLL failed bit set in "
  1239. "hwerrstatus, clearing and continuing\n");
  1240. ipath_write_kreg(dd, dd->ipath_kregs->kr_hwerrclear,
  1241. INFINIPATH_HWE_SERDESPLLFAILED);
  1242. }
  1243. val = ipath_read_kreg64(dd, dd->ipath_kregs->kr_serdesconfig0);
  1244. config1 = ipath_read_kreg64(dd, dd->ipath_kregs->kr_serdesconfig1);
  1245. ipath_cdbg(VERBOSE, "Initial serdes status is config0=%llx "
  1246. "config1=%llx, sstatus=%llx xgxs %llx\n",
  1247. (unsigned long long) val, (unsigned long long) config1,
  1248. (unsigned long long)
  1249. ipath_read_kreg64(dd, dd->ipath_kregs->kr_serdesstatus),
  1250. (unsigned long long)
  1251. ipath_read_kreg64(dd, dd->ipath_kregs->kr_xgxsconfig));
  1252. /* force reset on */
  1253. val |= INFINIPATH_SERDC0_RESET_PLL
  1254. /* | INFINIPATH_SERDC0_RESET_MASK */
  1255. ;
  1256. ipath_write_kreg(dd, dd->ipath_kregs->kr_serdesconfig0, val);
  1257. udelay(15); /* need pll reset set at least for a bit */
  1258. if (val & INFINIPATH_SERDC0_RESET_PLL) {
  1259. u64 val2 = val &= ~INFINIPATH_SERDC0_RESET_PLL;
  1260. /* set lane resets, and tx idle, during pll reset */
  1261. val2 |= INFINIPATH_SERDC0_RESET_MASK |
  1262. INFINIPATH_SERDC0_TXIDLE;
  1263. ipath_cdbg(VERBOSE, "Clearing serdes PLL reset (writing "
  1264. "%llx)\n", (unsigned long long) val2);
  1265. ipath_write_kreg(dd, dd->ipath_kregs->kr_serdesconfig0,
  1266. val2);
  1267. /*
  1268. * be sure chip saw it
  1269. */
  1270. val = ipath_read_kreg64(dd, dd->ipath_kregs->kr_scratch);
  1271. /*
  1272. * need pll reset clear at least 11 usec before lane
  1273. * resets cleared; give it a few more
  1274. */
  1275. udelay(15);
  1276. val = val2; /* for check below */
  1277. }
  1278. if (val & (INFINIPATH_SERDC0_RESET_PLL |
  1279. INFINIPATH_SERDC0_RESET_MASK |
  1280. INFINIPATH_SERDC0_TXIDLE)) {
  1281. val &= ~(INFINIPATH_SERDC0_RESET_PLL |
  1282. INFINIPATH_SERDC0_RESET_MASK |
  1283. INFINIPATH_SERDC0_TXIDLE);
  1284. /* clear them */
  1285. ipath_write_kreg(dd, dd->ipath_kregs->kr_serdesconfig0,
  1286. val);
  1287. }
  1288. val = ipath_read_kreg64(dd, dd->ipath_kregs->kr_xgxsconfig);
  1289. if (val & INFINIPATH_XGXS_RESET) {
  1290. /* normally true after boot */
  1291. val &= ~INFINIPATH_XGXS_RESET;
  1292. change = 1;
  1293. }
  1294. if (((val >> INFINIPATH_XGXS_RX_POL_SHIFT) &
  1295. INFINIPATH_XGXS_RX_POL_MASK) != dd->ipath_rx_pol_inv ) {
  1296. /* need to compensate for Tx inversion in partner */
  1297. val &= ~(INFINIPATH_XGXS_RX_POL_MASK <<
  1298. INFINIPATH_XGXS_RX_POL_SHIFT);
  1299. val |= dd->ipath_rx_pol_inv <<
  1300. INFINIPATH_XGXS_RX_POL_SHIFT;
  1301. change = 1;
  1302. }
  1303. if (change)
  1304. ipath_write_kreg(dd, dd->ipath_kregs->kr_xgxsconfig, val);
  1305. val = ipath_read_kreg64(dd, dd->ipath_kregs->kr_serdesconfig0);
  1306. /* clear current and de-emphasis bits */
  1307. config1 &= ~0x0ffffffff00ULL;
  1308. /* set current to 20ma */
  1309. config1 |= 0x00000000000ULL;
  1310. /* set de-emphasis to -5.68dB */
  1311. config1 |= 0x0cccc000000ULL;
  1312. ipath_write_kreg(dd, dd->ipath_kregs->kr_serdesconfig1, config1);
  1313. ipath_cdbg(VERBOSE, "After setup: serdes status is config0=%llx "
  1314. "config1=%llx, sstatus=%llx xgxs %llx\n",
  1315. (unsigned long long) val, (unsigned long long) config1,
  1316. (unsigned long long)
  1317. ipath_read_kreg64(dd, dd->ipath_kregs->kr_serdesstatus),
  1318. (unsigned long long)
  1319. ipath_read_kreg64(dd, dd->ipath_kregs->kr_xgxsconfig));
  1320. return ret; /* for now, say we always succeeded */
  1321. }
  1322. /**
  1323. * ipath_ht_quiet_serdes - set serdes to txidle
  1324. * @dd: the infinipath device
  1325. * driver is being unloaded
  1326. */
  1327. static void ipath_ht_quiet_serdes(struct ipath_devdata *dd)
  1328. {
  1329. u64 val = ipath_read_kreg64(dd, dd->ipath_kregs->kr_serdesconfig0);
  1330. val |= INFINIPATH_SERDC0_TXIDLE;
  1331. ipath_dbg("Setting TxIdleEn on serdes (config0 = %llx)\n",
  1332. (unsigned long long) val);
  1333. ipath_write_kreg(dd, dd->ipath_kregs->kr_serdesconfig0, val);
  1334. }
  1335. /**
  1336. * ipath_pe_put_tid - write a TID in chip
  1337. * @dd: the infinipath device
  1338. * @tidptr: pointer to the expected TID (in chip) to udpate
  1339. * @tidtype: RCVHQ_RCV_TYPE_EAGER (1) for eager, RCVHQ_RCV_TYPE_EXPECTED (0) for expected
  1340. * @pa: physical address of in memory buffer; ipath_tidinvalid if freeing
  1341. *
  1342. * This exists as a separate routine to allow for special locking etc.
  1343. * It's used for both the full cleanup on exit, as well as the normal
  1344. * setup and teardown.
  1345. */
  1346. static void ipath_ht_put_tid(struct ipath_devdata *dd,
  1347. u64 __iomem *tidptr, u32 type,
  1348. unsigned long pa)
  1349. {
  1350. if (!dd->ipath_kregbase)
  1351. return;
  1352. if (pa != dd->ipath_tidinvalid) {
  1353. if (unlikely((pa & ~INFINIPATH_RT_ADDR_MASK))) {
  1354. dev_info(&dd->pcidev->dev,
  1355. "physaddr %lx has more than "
  1356. "40 bits, using only 40!!!\n", pa);
  1357. pa &= INFINIPATH_RT_ADDR_MASK;
  1358. }
  1359. if (type == RCVHQ_RCV_TYPE_EAGER)
  1360. pa |= dd->ipath_tidtemplate;
  1361. else {
  1362. /* in words (fixed, full page). */
  1363. u64 lenvalid = PAGE_SIZE >> 2;
  1364. lenvalid <<= INFINIPATH_RT_BUFSIZE_SHIFT;
  1365. pa |= lenvalid | INFINIPATH_RT_VALID;
  1366. }
  1367. }
  1368. writeq(pa, tidptr);
  1369. }
  1370. /**
  1371. * ipath_ht_clear_tid - clear all TID entries for a port, expected and eager
  1372. * @dd: the infinipath device
  1373. * @port: the port
  1374. *
  1375. * Used from ipath_close(), and at chip initialization.
  1376. */
  1377. static void ipath_ht_clear_tids(struct ipath_devdata *dd, unsigned port)
  1378. {
  1379. u64 __iomem *tidbase;
  1380. int i;
  1381. if (!dd->ipath_kregbase)
  1382. return;
  1383. ipath_cdbg(VERBOSE, "Invalidate TIDs for port %u\n", port);
  1384. /*
  1385. * need to invalidate all of the expected TID entries for this
  1386. * port, so we don't have valid entries that might somehow get
  1387. * used (early in next use of this port, or through some bug)
  1388. */
  1389. tidbase = (u64 __iomem *) ((char __iomem *)(dd->ipath_kregbase) +
  1390. dd->ipath_rcvtidbase +
  1391. port * dd->ipath_rcvtidcnt *
  1392. sizeof(*tidbase));
  1393. for (i = 0; i < dd->ipath_rcvtidcnt; i++)
  1394. ipath_ht_put_tid(dd, &tidbase[i], RCVHQ_RCV_TYPE_EXPECTED,
  1395. dd->ipath_tidinvalid);
  1396. tidbase = (u64 __iomem *) ((char __iomem *)(dd->ipath_kregbase) +
  1397. dd->ipath_rcvegrbase +
  1398. port * dd->ipath_rcvegrcnt *
  1399. sizeof(*tidbase));
  1400. for (i = 0; i < dd->ipath_rcvegrcnt; i++)
  1401. ipath_ht_put_tid(dd, &tidbase[i], RCVHQ_RCV_TYPE_EAGER,
  1402. dd->ipath_tidinvalid);
  1403. }
  1404. /**
  1405. * ipath_ht_tidtemplate - setup constants for TID updates
  1406. * @dd: the infinipath device
  1407. *
  1408. * We setup stuff that we use a lot, to avoid calculating each time
  1409. */
  1410. static void ipath_ht_tidtemplate(struct ipath_devdata *dd)
  1411. {
  1412. dd->ipath_tidtemplate = dd->ipath_ibmaxlen >> 2;
  1413. dd->ipath_tidtemplate <<= INFINIPATH_RT_BUFSIZE_SHIFT;
  1414. dd->ipath_tidtemplate |= INFINIPATH_RT_VALID;
  1415. /*
  1416. * work around chip errata bug 7358, by marking invalid tids
  1417. * as having max length
  1418. */
  1419. dd->ipath_tidinvalid = (-1LL & INFINIPATH_RT_BUFSIZE_MASK) <<
  1420. INFINIPATH_RT_BUFSIZE_SHIFT;
  1421. }
  1422. static int ipath_ht_early_init(struct ipath_devdata *dd)
  1423. {
  1424. u32 __iomem *piobuf;
  1425. u32 pioincr, val32;
  1426. int i;
  1427. /*
  1428. * one cache line; long IB headers will spill over into received
  1429. * buffer
  1430. */
  1431. dd->ipath_rcvhdrentsize = 16;
  1432. dd->ipath_rcvhdrsize = IPATH_DFLT_RCVHDRSIZE;
  1433. /*
  1434. * For HT, we allocate a somewhat overly large eager buffer,
  1435. * such that we can guarantee that we can receive the largest
  1436. * packet that we can send out. To truly support a 4KB MTU,
  1437. * we need to bump this to a large value. To date, other than
  1438. * testing, we have never encountered an HCA that can really
  1439. * send 4KB MTU packets, so we do not handle that (we'll get
  1440. * errors interrupts if we ever see one).
  1441. */
  1442. dd->ipath_rcvegrbufsize = dd->ipath_piosize2k;
  1443. /*
  1444. * the min() check here is currently a nop, but it may not
  1445. * always be, depending on just how we do ipath_rcvegrbufsize
  1446. */
  1447. dd->ipath_ibmaxlen = min(dd->ipath_piosize2k,
  1448. dd->ipath_rcvegrbufsize);
  1449. dd->ipath_init_ibmaxlen = dd->ipath_ibmaxlen;
  1450. ipath_ht_tidtemplate(dd);
  1451. /*
  1452. * zero all the TID entries at startup. We do this for sanity,
  1453. * in case of a previous driver crash of some kind, and also
  1454. * because the chip powers up with these memories in an unknown
  1455. * state. Use portcnt, not cfgports, since this is for the
  1456. * full chip, not for current (possibly different) configuration
  1457. * value.
  1458. * Chip Errata bug 6447
  1459. */
  1460. for (val32 = 0; val32 < dd->ipath_portcnt; val32++)
  1461. ipath_ht_clear_tids(dd, val32);
  1462. /*
  1463. * write the pbc of each buffer, to be sure it's initialized, then
  1464. * cancel all the buffers, and also abort any packets that might
  1465. * have been in flight for some reason (the latter is for driver
  1466. * unload/reload, but isn't a bad idea at first init). PIO send
  1467. * isn't enabled at this point, so there is no danger of sending
  1468. * these out on the wire.
  1469. * Chip Errata bug 6610
  1470. */
  1471. piobuf = (u32 __iomem *) (((char __iomem *)(dd->ipath_kregbase)) +
  1472. dd->ipath_piobufbase);
  1473. pioincr = dd->ipath_palign / sizeof(*piobuf);
  1474. for (i = 0; i < dd->ipath_piobcnt2k; i++) {
  1475. /*
  1476. * reasonable word count, just to init pbc
  1477. */
  1478. writel(16, piobuf);
  1479. piobuf += pioincr;
  1480. }
  1481. ipath_get_eeprom_info(dd);
  1482. if (dd->ipath_boardrev == 5) {
  1483. /*
  1484. * Later production QHT7040 has same changes as QHT7140, so
  1485. * can use GPIO interrupts. They have serial #'s starting
  1486. * with 128, rather than 112.
  1487. */
  1488. if (dd->ipath_serial[0] == '1' &&
  1489. dd->ipath_serial[1] == '2' &&
  1490. dd->ipath_serial[2] == '8')
  1491. dd->ipath_flags |= IPATH_GPIO_INTR;
  1492. else {
  1493. ipath_dev_err(dd, "Unsupported InfiniPath board "
  1494. "(serial number %.16s)!\n",
  1495. dd->ipath_serial);
  1496. return 1;
  1497. }
  1498. }
  1499. if (dd->ipath_minrev >= 4) {
  1500. /* Rev4+ reports extra errors via internal GPIO pins */
  1501. dd->ipath_flags |= IPATH_GPIO_ERRINTRS;
  1502. dd->ipath_gpio_mask |= IPATH_GPIO_ERRINTR_MASK;
  1503. ipath_write_kreg(dd, dd->ipath_kregs->kr_gpio_mask,
  1504. dd->ipath_gpio_mask);
  1505. }
  1506. return 0;
  1507. }
  1508. static int ipath_ht_txe_recover(struct ipath_devdata *dd)
  1509. {
  1510. int cnt = ++ipath_stats.sps_txeparity;
  1511. if (cnt >= IPATH_MAX_PARITY_ATTEMPTS) {
  1512. if (cnt == IPATH_MAX_PARITY_ATTEMPTS)
  1513. ipath_dev_err(dd,
  1514. "Too many attempts to recover from "
  1515. "TXE parity, giving up\n");
  1516. return 0;
  1517. }
  1518. dev_info(&dd->pcidev->dev,
  1519. "Recovering from TXE PIO parity error\n");
  1520. return 1;
  1521. }
  1522. /**
  1523. * ipath_init_ht_get_base_info - set chip-specific flags for user code
  1524. * @dd: the infinipath device
  1525. * @kbase: ipath_base_info pointer
  1526. *
  1527. * We set the PCIE flag because the lower bandwidth on PCIe vs
  1528. * HyperTransport can affect some user packet algorithms.
  1529. */
  1530. static int ipath_ht_get_base_info(struct ipath_portdata *pd, void *kbase)
  1531. {
  1532. struct ipath_base_info *kinfo = kbase;
  1533. kinfo->spi_runtime_flags |= IPATH_RUNTIME_HT |
  1534. IPATH_RUNTIME_PIO_REGSWAPPED;
  1535. if (pd->port_dd->ipath_minrev < 4)
  1536. kinfo->spi_runtime_flags |= IPATH_RUNTIME_RCVHDR_COPY;
  1537. return 0;
  1538. }
  1539. static void ipath_ht_free_irq(struct ipath_devdata *dd)
  1540. {
  1541. free_irq(dd->ipath_irq, dd);
  1542. ht_destroy_irq(dd->ipath_irq);
  1543. dd->ipath_irq = 0;
  1544. dd->ipath_intconfig = 0;
  1545. }
  1546. static struct ipath_message_header *
  1547. ipath_ht_get_msgheader(struct ipath_devdata *dd, __le32 *rhf_addr)
  1548. {
  1549. return (struct ipath_message_header *)
  1550. &rhf_addr[sizeof(u64) / sizeof(u32)];
  1551. }
  1552. static void ipath_ht_config_ports(struct ipath_devdata *dd, ushort cfgports)
  1553. {
  1554. dd->ipath_portcnt =
  1555. ipath_read_kreg32(dd, dd->ipath_kregs->kr_portcnt);
  1556. dd->ipath_p0_rcvegrcnt =
  1557. ipath_read_kreg32(dd, dd->ipath_kregs->kr_rcvegrcnt);
  1558. }
  1559. static void ipath_ht_read_counters(struct ipath_devdata *dd,
  1560. struct infinipath_counters *cntrs)
  1561. {
  1562. cntrs->LBIntCnt =
  1563. ipath_snap_cntr(dd, IPATH_CREG_OFFSET(LBIntCnt));
  1564. cntrs->LBFlowStallCnt =
  1565. ipath_snap_cntr(dd, IPATH_CREG_OFFSET(LBFlowStallCnt));
  1566. cntrs->TxSDmaDescCnt = 0;
  1567. cntrs->TxUnsupVLErrCnt =
  1568. ipath_snap_cntr(dd, IPATH_CREG_OFFSET(TxUnsupVLErrCnt));
  1569. cntrs->TxDataPktCnt =
  1570. ipath_snap_cntr(dd, IPATH_CREG_OFFSET(TxDataPktCnt));
  1571. cntrs->TxFlowPktCnt =
  1572. ipath_snap_cntr(dd, IPATH_CREG_OFFSET(TxFlowPktCnt));
  1573. cntrs->TxDwordCnt =
  1574. ipath_snap_cntr(dd, IPATH_CREG_OFFSET(TxDwordCnt));
  1575. cntrs->TxLenErrCnt =
  1576. ipath_snap_cntr(dd, IPATH_CREG_OFFSET(TxLenErrCnt));
  1577. cntrs->TxMaxMinLenErrCnt =
  1578. ipath_snap_cntr(dd, IPATH_CREG_OFFSET(TxMaxMinLenErrCnt));
  1579. cntrs->TxUnderrunCnt =
  1580. ipath_snap_cntr(dd, IPATH_CREG_OFFSET(TxUnderrunCnt));
  1581. cntrs->TxFlowStallCnt =
  1582. ipath_snap_cntr(dd, IPATH_CREG_OFFSET(TxFlowStallCnt));
  1583. cntrs->TxDroppedPktCnt =
  1584. ipath_snap_cntr(dd, IPATH_CREG_OFFSET(TxDroppedPktCnt));
  1585. cntrs->RxDroppedPktCnt =
  1586. ipath_snap_cntr(dd, IPATH_CREG_OFFSET(RxDroppedPktCnt));
  1587. cntrs->RxDataPktCnt =
  1588. ipath_snap_cntr(dd, IPATH_CREG_OFFSET(RxDataPktCnt));
  1589. cntrs->RxFlowPktCnt =
  1590. ipath_snap_cntr(dd, IPATH_CREG_OFFSET(RxFlowPktCnt));
  1591. cntrs->RxDwordCnt =
  1592. ipath_snap_cntr(dd, IPATH_CREG_OFFSET(RxDwordCnt));
  1593. cntrs->RxLenErrCnt =
  1594. ipath_snap_cntr(dd, IPATH_CREG_OFFSET(RxLenErrCnt));
  1595. cntrs->RxMaxMinLenErrCnt =
  1596. ipath_snap_cntr(dd, IPATH_CREG_OFFSET(RxMaxMinLenErrCnt));
  1597. cntrs->RxICRCErrCnt =
  1598. ipath_snap_cntr(dd, IPATH_CREG_OFFSET(RxICRCErrCnt));
  1599. cntrs->RxVCRCErrCnt =
  1600. ipath_snap_cntr(dd, IPATH_CREG_OFFSET(RxVCRCErrCnt));
  1601. cntrs->RxFlowCtrlErrCnt =
  1602. ipath_snap_cntr(dd, IPATH_CREG_OFFSET(RxFlowCtrlErrCnt));
  1603. cntrs->RxBadFormatCnt =
  1604. ipath_snap_cntr(dd, IPATH_CREG_OFFSET(RxBadFormatCnt));
  1605. cntrs->RxLinkProblemCnt =
  1606. ipath_snap_cntr(dd, IPATH_CREG_OFFSET(RxLinkProblemCnt));
  1607. cntrs->RxEBPCnt =
  1608. ipath_snap_cntr(dd, IPATH_CREG_OFFSET(RxEBPCnt));
  1609. cntrs->RxLPCRCErrCnt =
  1610. ipath_snap_cntr(dd, IPATH_CREG_OFFSET(RxLPCRCErrCnt));
  1611. cntrs->RxBufOvflCnt =
  1612. ipath_snap_cntr(dd, IPATH_CREG_OFFSET(RxBufOvflCnt));
  1613. cntrs->RxTIDFullErrCnt =
  1614. ipath_snap_cntr(dd, IPATH_CREG_OFFSET(RxTIDFullErrCnt));
  1615. cntrs->RxTIDValidErrCnt =
  1616. ipath_snap_cntr(dd, IPATH_CREG_OFFSET(RxTIDValidErrCnt));
  1617. cntrs->RxPKeyMismatchCnt =
  1618. ipath_snap_cntr(dd, IPATH_CREG_OFFSET(RxPKeyMismatchCnt));
  1619. cntrs->RxP0HdrEgrOvflCnt =
  1620. ipath_snap_cntr(dd, IPATH_CREG_OFFSET(RxP0HdrEgrOvflCnt));
  1621. cntrs->RxP1HdrEgrOvflCnt =
  1622. ipath_snap_cntr(dd, IPATH_CREG_OFFSET(RxP1HdrEgrOvflCnt));
  1623. cntrs->RxP2HdrEgrOvflCnt =
  1624. ipath_snap_cntr(dd, IPATH_CREG_OFFSET(RxP2HdrEgrOvflCnt));
  1625. cntrs->RxP3HdrEgrOvflCnt =
  1626. ipath_snap_cntr(dd, IPATH_CREG_OFFSET(RxP3HdrEgrOvflCnt));
  1627. cntrs->RxP4HdrEgrOvflCnt =
  1628. ipath_snap_cntr(dd, IPATH_CREG_OFFSET(RxP4HdrEgrOvflCnt));
  1629. cntrs->RxP5HdrEgrOvflCnt =
  1630. ipath_snap_cntr(dd, IPATH_CREG_OFFSET(RxP5HdrEgrOvflCnt));
  1631. cntrs->RxP6HdrEgrOvflCnt =
  1632. ipath_snap_cntr(dd, IPATH_CREG_OFFSET(RxP6HdrEgrOvflCnt));
  1633. cntrs->RxP7HdrEgrOvflCnt =
  1634. ipath_snap_cntr(dd, IPATH_CREG_OFFSET(RxP7HdrEgrOvflCnt));
  1635. cntrs->RxP8HdrEgrOvflCnt =
  1636. ipath_snap_cntr(dd, IPATH_CREG_OFFSET(RxP8HdrEgrOvflCnt));
  1637. cntrs->RxP9HdrEgrOvflCnt = 0;
  1638. cntrs->RxP10HdrEgrOvflCnt = 0;
  1639. cntrs->RxP11HdrEgrOvflCnt = 0;
  1640. cntrs->RxP12HdrEgrOvflCnt = 0;
  1641. cntrs->RxP13HdrEgrOvflCnt = 0;
  1642. cntrs->RxP14HdrEgrOvflCnt = 0;
  1643. cntrs->RxP15HdrEgrOvflCnt = 0;
  1644. cntrs->RxP16HdrEgrOvflCnt = 0;
  1645. cntrs->IBStatusChangeCnt =
  1646. ipath_snap_cntr(dd, IPATH_CREG_OFFSET(IBStatusChangeCnt));
  1647. cntrs->IBLinkErrRecoveryCnt =
  1648. ipath_snap_cntr(dd, IPATH_CREG_OFFSET(IBLinkErrRecoveryCnt));
  1649. cntrs->IBLinkDownedCnt =
  1650. ipath_snap_cntr(dd, IPATH_CREG_OFFSET(IBLinkDownedCnt));
  1651. cntrs->IBSymbolErrCnt =
  1652. ipath_snap_cntr(dd, IPATH_CREG_OFFSET(IBSymbolErrCnt));
  1653. cntrs->RxVL15DroppedPktCnt = 0;
  1654. cntrs->RxOtherLocalPhyErrCnt = 0;
  1655. cntrs->PcieRetryBufDiagQwordCnt = 0;
  1656. cntrs->ExcessBufferOvflCnt = dd->ipath_overrun_thresh_errs;
  1657. cntrs->LocalLinkIntegrityErrCnt =
  1658. (dd->ipath_flags & IPATH_GPIO_ERRINTRS) ?
  1659. dd->ipath_lli_errs : dd->ipath_lli_errors;
  1660. cntrs->RxVlErrCnt = 0;
  1661. cntrs->RxDlidFltrCnt = 0;
  1662. }
  1663. /* no interrupt fallback for these chips */
  1664. static int ipath_ht_nointr_fallback(struct ipath_devdata *dd)
  1665. {
  1666. return 0;
  1667. }
  1668. /*
  1669. * reset the XGXS (between serdes and IBC). Slightly less intrusive
  1670. * than resetting the IBC or external link state, and useful in some
  1671. * cases to cause some retraining. To do this right, we reset IBC
  1672. * as well.
  1673. */
  1674. static void ipath_ht_xgxs_reset(struct ipath_devdata *dd)
  1675. {
  1676. u64 val, prev_val;
  1677. prev_val = ipath_read_kreg64(dd, dd->ipath_kregs->kr_xgxsconfig);
  1678. val = prev_val | INFINIPATH_XGXS_RESET;
  1679. prev_val &= ~INFINIPATH_XGXS_RESET; /* be sure */
  1680. ipath_write_kreg(dd, dd->ipath_kregs->kr_control,
  1681. dd->ipath_control & ~INFINIPATH_C_LINKENABLE);
  1682. ipath_write_kreg(dd, dd->ipath_kregs->kr_xgxsconfig, val);
  1683. ipath_read_kreg32(dd, dd->ipath_kregs->kr_scratch);
  1684. ipath_write_kreg(dd, dd->ipath_kregs->kr_xgxsconfig, prev_val);
  1685. ipath_write_kreg(dd, dd->ipath_kregs->kr_control,
  1686. dd->ipath_control);
  1687. }
  1688. static int ipath_ht_get_ib_cfg(struct ipath_devdata *dd, int which)
  1689. {
  1690. int ret;
  1691. switch (which) {
  1692. case IPATH_IB_CFG_LWID:
  1693. ret = dd->ipath_link_width_active;
  1694. break;
  1695. case IPATH_IB_CFG_SPD:
  1696. ret = dd->ipath_link_speed_active;
  1697. break;
  1698. case IPATH_IB_CFG_LWID_ENB:
  1699. ret = dd->ipath_link_width_enabled;
  1700. break;
  1701. case IPATH_IB_CFG_SPD_ENB:
  1702. ret = dd->ipath_link_speed_enabled;
  1703. break;
  1704. default:
  1705. ret = -ENOTSUPP;
  1706. break;
  1707. }
  1708. return ret;
  1709. }
  1710. /* we assume range checking is already done, if needed */
  1711. static int ipath_ht_set_ib_cfg(struct ipath_devdata *dd, int which, u32 val)
  1712. {
  1713. int ret = 0;
  1714. if (which == IPATH_IB_CFG_LWID_ENB)
  1715. dd->ipath_link_width_enabled = val;
  1716. else if (which == IPATH_IB_CFG_SPD_ENB)
  1717. dd->ipath_link_speed_enabled = val;
  1718. else
  1719. ret = -ENOTSUPP;
  1720. return ret;
  1721. }
  1722. static void ipath_ht_config_jint(struct ipath_devdata *dd, u16 a, u16 b)
  1723. {
  1724. }
  1725. static int ipath_ht_ib_updown(struct ipath_devdata *dd, int ibup, u64 ibcs)
  1726. {
  1727. ipath_setup_ht_setextled(dd, ipath_ib_linkstate(dd, ibcs),
  1728. ipath_ib_linktrstate(dd, ibcs));
  1729. return 0;
  1730. }
  1731. /**
  1732. * ipath_init_iba6110_funcs - set up the chip-specific function pointers
  1733. * @dd: the infinipath device
  1734. *
  1735. * This is global, and is called directly at init to set up the
  1736. * chip-specific function pointers for later use.
  1737. */
  1738. void ipath_init_iba6110_funcs(struct ipath_devdata *dd)
  1739. {
  1740. dd->ipath_f_intrsetup = ipath_ht_intconfig;
  1741. dd->ipath_f_bus = ipath_setup_ht_config;
  1742. dd->ipath_f_reset = ipath_setup_ht_reset;
  1743. dd->ipath_f_get_boardname = ipath_ht_boardname;
  1744. dd->ipath_f_init_hwerrors = ipath_ht_init_hwerrors;
  1745. dd->ipath_f_early_init = ipath_ht_early_init;
  1746. dd->ipath_f_handle_hwerrors = ipath_ht_handle_hwerrors;
  1747. dd->ipath_f_quiet_serdes = ipath_ht_quiet_serdes;
  1748. dd->ipath_f_bringup_serdes = ipath_ht_bringup_serdes;
  1749. dd->ipath_f_clear_tids = ipath_ht_clear_tids;
  1750. dd->ipath_f_put_tid = ipath_ht_put_tid;
  1751. dd->ipath_f_cleanup = ipath_setup_ht_cleanup;
  1752. dd->ipath_f_setextled = ipath_setup_ht_setextled;
  1753. dd->ipath_f_get_base_info = ipath_ht_get_base_info;
  1754. dd->ipath_f_free_irq = ipath_ht_free_irq;
  1755. dd->ipath_f_tidtemplate = ipath_ht_tidtemplate;
  1756. dd->ipath_f_intr_fallback = ipath_ht_nointr_fallback;
  1757. dd->ipath_f_get_msgheader = ipath_ht_get_msgheader;
  1758. dd->ipath_f_config_ports = ipath_ht_config_ports;
  1759. dd->ipath_f_read_counters = ipath_ht_read_counters;
  1760. dd->ipath_f_xgxs_reset = ipath_ht_xgxs_reset;
  1761. dd->ipath_f_get_ib_cfg = ipath_ht_get_ib_cfg;
  1762. dd->ipath_f_set_ib_cfg = ipath_ht_set_ib_cfg;
  1763. dd->ipath_f_config_jint = ipath_ht_config_jint;
  1764. dd->ipath_f_ib_updown = ipath_ht_ib_updown;
  1765. /*
  1766. * initialize chip-specific variables
  1767. */
  1768. ipath_init_ht_variables(dd);
  1769. }