ipath_iba6110.c 53 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659
  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. #define IPATH_KREG_OFFSET(field) (offsetof(struct \
  144. _infinipath_do_not_use_kernel_regs, field) / sizeof(u64))
  145. #define IPATH_CREG_OFFSET(field) (offsetof( \
  146. struct infinipath_counters, field) / sizeof(u64))
  147. static const struct ipath_kregs ipath_ht_kregs = {
  148. .kr_control = IPATH_KREG_OFFSET(Control),
  149. .kr_counterregbase = IPATH_KREG_OFFSET(CounterRegBase),
  150. .kr_debugport = IPATH_KREG_OFFSET(DebugPort),
  151. .kr_debugportselect = IPATH_KREG_OFFSET(DebugPortSelect),
  152. .kr_errorclear = IPATH_KREG_OFFSET(ErrorClear),
  153. .kr_errormask = IPATH_KREG_OFFSET(ErrorMask),
  154. .kr_errorstatus = IPATH_KREG_OFFSET(ErrorStatus),
  155. .kr_extctrl = IPATH_KREG_OFFSET(ExtCtrl),
  156. .kr_extstatus = IPATH_KREG_OFFSET(ExtStatus),
  157. .kr_gpio_clear = IPATH_KREG_OFFSET(GPIOClear),
  158. .kr_gpio_mask = IPATH_KREG_OFFSET(GPIOMask),
  159. .kr_gpio_out = IPATH_KREG_OFFSET(GPIOOut),
  160. .kr_gpio_status = IPATH_KREG_OFFSET(GPIOStatus),
  161. .kr_hwdiagctrl = IPATH_KREG_OFFSET(HwDiagCtrl),
  162. .kr_hwerrclear = IPATH_KREG_OFFSET(HwErrClear),
  163. .kr_hwerrmask = IPATH_KREG_OFFSET(HwErrMask),
  164. .kr_hwerrstatus = IPATH_KREG_OFFSET(HwErrStatus),
  165. .kr_ibcctrl = IPATH_KREG_OFFSET(IBCCtrl),
  166. .kr_ibcstatus = IPATH_KREG_OFFSET(IBCStatus),
  167. .kr_intblocked = IPATH_KREG_OFFSET(IntBlocked),
  168. .kr_intclear = IPATH_KREG_OFFSET(IntClear),
  169. .kr_interruptconfig = IPATH_KREG_OFFSET(InterruptConfig),
  170. .kr_intmask = IPATH_KREG_OFFSET(IntMask),
  171. .kr_intstatus = IPATH_KREG_OFFSET(IntStatus),
  172. .kr_mdio = IPATH_KREG_OFFSET(MDIO),
  173. .kr_pagealign = IPATH_KREG_OFFSET(PageAlign),
  174. .kr_partitionkey = IPATH_KREG_OFFSET(RcvPartitionKey),
  175. .kr_portcnt = IPATH_KREG_OFFSET(PortCnt),
  176. .kr_rcvbthqp = IPATH_KREG_OFFSET(RcvBTHQP),
  177. .kr_rcvbufbase = IPATH_KREG_OFFSET(RcvBufBase),
  178. .kr_rcvbufsize = IPATH_KREG_OFFSET(RcvBufSize),
  179. .kr_rcvctrl = IPATH_KREG_OFFSET(RcvCtrl),
  180. .kr_rcvegrbase = IPATH_KREG_OFFSET(RcvEgrBase),
  181. .kr_rcvegrcnt = IPATH_KREG_OFFSET(RcvEgrCnt),
  182. .kr_rcvhdrcnt = IPATH_KREG_OFFSET(RcvHdrCnt),
  183. .kr_rcvhdrentsize = IPATH_KREG_OFFSET(RcvHdrEntSize),
  184. .kr_rcvhdrsize = IPATH_KREG_OFFSET(RcvHdrSize),
  185. .kr_rcvintmembase = IPATH_KREG_OFFSET(RxIntMemBase),
  186. .kr_rcvintmemsize = IPATH_KREG_OFFSET(RxIntMemSize),
  187. .kr_rcvtidbase = IPATH_KREG_OFFSET(RcvTIDBase),
  188. .kr_rcvtidcnt = IPATH_KREG_OFFSET(RcvTIDCnt),
  189. .kr_revision = IPATH_KREG_OFFSET(Revision),
  190. .kr_scratch = IPATH_KREG_OFFSET(Scratch),
  191. .kr_sendbuffererror = IPATH_KREG_OFFSET(SendBufferError),
  192. .kr_sendctrl = IPATH_KREG_OFFSET(SendCtrl),
  193. .kr_sendpioavailaddr = IPATH_KREG_OFFSET(SendPIOAvailAddr),
  194. .kr_sendpiobufbase = IPATH_KREG_OFFSET(SendPIOBufBase),
  195. .kr_sendpiobufcnt = IPATH_KREG_OFFSET(SendPIOBufCnt),
  196. .kr_sendpiosize = IPATH_KREG_OFFSET(SendPIOSize),
  197. .kr_sendregbase = IPATH_KREG_OFFSET(SendRegBase),
  198. .kr_txintmembase = IPATH_KREG_OFFSET(TxIntMemBase),
  199. .kr_txintmemsize = IPATH_KREG_OFFSET(TxIntMemSize),
  200. .kr_userregbase = IPATH_KREG_OFFSET(UserRegBase),
  201. .kr_serdesconfig0 = IPATH_KREG_OFFSET(SerdesConfig0),
  202. .kr_serdesconfig1 = IPATH_KREG_OFFSET(SerdesConfig1),
  203. .kr_serdesstatus = IPATH_KREG_OFFSET(SerdesStatus),
  204. .kr_xgxsconfig = IPATH_KREG_OFFSET(XGXSConfig),
  205. /*
  206. * These should not be used directly via ipath_write_kreg64(),
  207. * use them with ipath_write_kreg64_port(),
  208. */
  209. .kr_rcvhdraddr = IPATH_KREG_OFFSET(RcvHdrAddr0),
  210. .kr_rcvhdrtailaddr = IPATH_KREG_OFFSET(RcvHdrTailAddr0)
  211. };
  212. static const struct ipath_cregs ipath_ht_cregs = {
  213. .cr_badformatcnt = IPATH_CREG_OFFSET(RxBadFormatCnt),
  214. .cr_erricrccnt = IPATH_CREG_OFFSET(RxICRCErrCnt),
  215. .cr_errlinkcnt = IPATH_CREG_OFFSET(RxLinkProblemCnt),
  216. .cr_errlpcrccnt = IPATH_CREG_OFFSET(RxLPCRCErrCnt),
  217. .cr_errpkey = IPATH_CREG_OFFSET(RxPKeyMismatchCnt),
  218. .cr_errrcvflowctrlcnt = IPATH_CREG_OFFSET(RxFlowCtrlErrCnt),
  219. .cr_err_rlencnt = IPATH_CREG_OFFSET(RxLenErrCnt),
  220. .cr_errslencnt = IPATH_CREG_OFFSET(TxLenErrCnt),
  221. .cr_errtidfull = IPATH_CREG_OFFSET(RxTIDFullErrCnt),
  222. .cr_errtidvalid = IPATH_CREG_OFFSET(RxTIDValidErrCnt),
  223. .cr_errvcrccnt = IPATH_CREG_OFFSET(RxVCRCErrCnt),
  224. .cr_ibstatuschange = IPATH_CREG_OFFSET(IBStatusChangeCnt),
  225. /* calc from Reg_CounterRegBase + offset */
  226. .cr_intcnt = IPATH_CREG_OFFSET(LBIntCnt),
  227. .cr_invalidrlencnt = IPATH_CREG_OFFSET(RxMaxMinLenErrCnt),
  228. .cr_invalidslencnt = IPATH_CREG_OFFSET(TxMaxMinLenErrCnt),
  229. .cr_lbflowstallcnt = IPATH_CREG_OFFSET(LBFlowStallCnt),
  230. .cr_pktrcvcnt = IPATH_CREG_OFFSET(RxDataPktCnt),
  231. .cr_pktrcvflowctrlcnt = IPATH_CREG_OFFSET(RxFlowPktCnt),
  232. .cr_pktsendcnt = IPATH_CREG_OFFSET(TxDataPktCnt),
  233. .cr_pktsendflowcnt = IPATH_CREG_OFFSET(TxFlowPktCnt),
  234. .cr_portovflcnt = IPATH_CREG_OFFSET(RxP0HdrEgrOvflCnt),
  235. .cr_rcvebpcnt = IPATH_CREG_OFFSET(RxEBPCnt),
  236. .cr_rcvovflcnt = IPATH_CREG_OFFSET(RxBufOvflCnt),
  237. .cr_senddropped = IPATH_CREG_OFFSET(TxDroppedPktCnt),
  238. .cr_sendstallcnt = IPATH_CREG_OFFSET(TxFlowStallCnt),
  239. .cr_sendunderruncnt = IPATH_CREG_OFFSET(TxUnderrunCnt),
  240. .cr_wordrcvcnt = IPATH_CREG_OFFSET(RxDwordCnt),
  241. .cr_wordsendcnt = IPATH_CREG_OFFSET(TxDwordCnt),
  242. .cr_unsupvlcnt = IPATH_CREG_OFFSET(TxUnsupVLErrCnt),
  243. .cr_rxdroppktcnt = IPATH_CREG_OFFSET(RxDroppedPktCnt),
  244. .cr_iblinkerrrecovcnt = IPATH_CREG_OFFSET(IBLinkErrRecoveryCnt),
  245. .cr_iblinkdowncnt = IPATH_CREG_OFFSET(IBLinkDownedCnt),
  246. .cr_ibsymbolerrcnt = IPATH_CREG_OFFSET(IBSymbolErrCnt)
  247. };
  248. /* kr_intstatus, kr_intclear, kr_intmask bits */
  249. #define INFINIPATH_I_RCVURG_MASK ((1U<<9)-1)
  250. #define INFINIPATH_I_RCVAVAIL_MASK ((1U<<9)-1)
  251. /* kr_hwerrclear, kr_hwerrmask, kr_hwerrstatus, bits */
  252. #define INFINIPATH_HWE_HTCMEMPARITYERR_SHIFT 0
  253. #define INFINIPATH_HWE_HTCMEMPARITYERR_MASK 0x3FFFFFULL
  254. #define INFINIPATH_HWE_HTCLNKABYTE0CRCERR 0x0000000000800000ULL
  255. #define INFINIPATH_HWE_HTCLNKABYTE1CRCERR 0x0000000001000000ULL
  256. #define INFINIPATH_HWE_HTCLNKBBYTE0CRCERR 0x0000000002000000ULL
  257. #define INFINIPATH_HWE_HTCLNKBBYTE1CRCERR 0x0000000004000000ULL
  258. #define INFINIPATH_HWE_HTCMISCERR4 0x0000000008000000ULL
  259. #define INFINIPATH_HWE_HTCMISCERR5 0x0000000010000000ULL
  260. #define INFINIPATH_HWE_HTCMISCERR6 0x0000000020000000ULL
  261. #define INFINIPATH_HWE_HTCMISCERR7 0x0000000040000000ULL
  262. #define INFINIPATH_HWE_HTCBUSTREQPARITYERR 0x0000000080000000ULL
  263. #define INFINIPATH_HWE_HTCBUSTRESPPARITYERR 0x0000000100000000ULL
  264. #define INFINIPATH_HWE_HTCBUSIREQPARITYERR 0x0000000200000000ULL
  265. #define INFINIPATH_HWE_COREPLL_FBSLIP 0x0080000000000000ULL
  266. #define INFINIPATH_HWE_COREPLL_RFSLIP 0x0100000000000000ULL
  267. #define INFINIPATH_HWE_HTBPLL_FBSLIP 0x0200000000000000ULL
  268. #define INFINIPATH_HWE_HTBPLL_RFSLIP 0x0400000000000000ULL
  269. #define INFINIPATH_HWE_HTAPLL_FBSLIP 0x0800000000000000ULL
  270. #define INFINIPATH_HWE_HTAPLL_RFSLIP 0x1000000000000000ULL
  271. #define INFINIPATH_HWE_SERDESPLLFAILED 0x2000000000000000ULL
  272. /* kr_extstatus bits */
  273. #define INFINIPATH_EXTS_FREQSEL 0x2
  274. #define INFINIPATH_EXTS_SERDESSEL 0x4
  275. #define INFINIPATH_EXTS_MEMBIST_ENDTEST 0x0000000000004000
  276. #define INFINIPATH_EXTS_MEMBIST_CORRECT 0x0000000000008000
  277. /* TID entries (memory), HT-only */
  278. #define INFINIPATH_RT_ADDR_MASK 0xFFFFFFFFFFULL /* 40 bits valid */
  279. #define INFINIPATH_RT_VALID 0x8000000000000000ULL
  280. #define INFINIPATH_RT_ADDR_SHIFT 0
  281. #define INFINIPATH_RT_BUFSIZE_MASK 0x3FFFULL
  282. #define INFINIPATH_RT_BUFSIZE_SHIFT 48
  283. #define INFINIPATH_R_INTRAVAIL_SHIFT 16
  284. #define INFINIPATH_R_TAILUPD_SHIFT 31
  285. /* kr_xgxsconfig bits */
  286. #define INFINIPATH_XGXS_RESET 0x7ULL
  287. /*
  288. * masks and bits that are different in different chips, or present only
  289. * in one
  290. */
  291. static const ipath_err_t infinipath_hwe_htcmemparityerr_mask =
  292. INFINIPATH_HWE_HTCMEMPARITYERR_MASK;
  293. static const ipath_err_t infinipath_hwe_htcmemparityerr_shift =
  294. INFINIPATH_HWE_HTCMEMPARITYERR_SHIFT;
  295. static const ipath_err_t infinipath_hwe_htclnkabyte0crcerr =
  296. INFINIPATH_HWE_HTCLNKABYTE0CRCERR;
  297. static const ipath_err_t infinipath_hwe_htclnkabyte1crcerr =
  298. INFINIPATH_HWE_HTCLNKABYTE1CRCERR;
  299. static const ipath_err_t infinipath_hwe_htclnkbbyte0crcerr =
  300. INFINIPATH_HWE_HTCLNKBBYTE0CRCERR;
  301. static const ipath_err_t infinipath_hwe_htclnkbbyte1crcerr =
  302. INFINIPATH_HWE_HTCLNKBBYTE1CRCERR;
  303. #define _IPATH_GPIO_SDA_NUM 1
  304. #define _IPATH_GPIO_SCL_NUM 0
  305. #define IPATH_GPIO_SDA \
  306. (1ULL << (_IPATH_GPIO_SDA_NUM+INFINIPATH_EXTC_GPIOOE_SHIFT))
  307. #define IPATH_GPIO_SCL \
  308. (1ULL << (_IPATH_GPIO_SCL_NUM+INFINIPATH_EXTC_GPIOOE_SHIFT))
  309. /* keep the code below somewhat more readonable; not used elsewhere */
  310. #define _IPATH_HTLINK0_CRCBITS (infinipath_hwe_htclnkabyte0crcerr | \
  311. infinipath_hwe_htclnkabyte1crcerr)
  312. #define _IPATH_HTLINK1_CRCBITS (infinipath_hwe_htclnkbbyte0crcerr | \
  313. infinipath_hwe_htclnkbbyte1crcerr)
  314. #define _IPATH_HTLANE0_CRCBITS (infinipath_hwe_htclnkabyte0crcerr | \
  315. infinipath_hwe_htclnkbbyte0crcerr)
  316. #define _IPATH_HTLANE1_CRCBITS (infinipath_hwe_htclnkabyte1crcerr | \
  317. infinipath_hwe_htclnkbbyte1crcerr)
  318. static void hwerr_crcbits(struct ipath_devdata *dd, ipath_err_t hwerrs,
  319. char *msg, size_t msgl)
  320. {
  321. char bitsmsg[64];
  322. ipath_err_t crcbits = hwerrs &
  323. (_IPATH_HTLINK0_CRCBITS | _IPATH_HTLINK1_CRCBITS);
  324. /* don't check if 8bit HT */
  325. if (dd->ipath_flags & IPATH_8BIT_IN_HT0)
  326. crcbits &= ~infinipath_hwe_htclnkabyte1crcerr;
  327. /* don't check if 8bit HT */
  328. if (dd->ipath_flags & IPATH_8BIT_IN_HT1)
  329. crcbits &= ~infinipath_hwe_htclnkbbyte1crcerr;
  330. /*
  331. * we'll want to ignore link errors on link that is
  332. * not in use, if any. For now, complain about both
  333. */
  334. if (crcbits) {
  335. u16 ctrl0, ctrl1;
  336. snprintf(bitsmsg, sizeof bitsmsg,
  337. "[HT%s lane %s CRC (%llx); powercycle to completely clear]",
  338. !(crcbits & _IPATH_HTLINK1_CRCBITS) ?
  339. "0 (A)" : (!(crcbits & _IPATH_HTLINK0_CRCBITS)
  340. ? "1 (B)" : "0+1 (A+B)"),
  341. !(crcbits & _IPATH_HTLANE1_CRCBITS) ? "0"
  342. : (!(crcbits & _IPATH_HTLANE0_CRCBITS) ? "1" :
  343. "0+1"), (unsigned long long) crcbits);
  344. strlcat(msg, bitsmsg, msgl);
  345. /*
  346. * print extra info for debugging. slave/primary
  347. * config word 4, 8 (link control 0, 1)
  348. */
  349. if (pci_read_config_word(dd->pcidev,
  350. dd->ipath_ht_slave_off + 0x4,
  351. &ctrl0))
  352. dev_info(&dd->pcidev->dev, "Couldn't read "
  353. "linkctrl0 of slave/primary "
  354. "config block\n");
  355. else if (!(ctrl0 & 1 << 6))
  356. /* not if EOC bit set */
  357. ipath_dbg("HT linkctrl0 0x%x%s%s\n", ctrl0,
  358. ((ctrl0 >> 8) & 7) ? " CRC" : "",
  359. ((ctrl0 >> 4) & 1) ? "linkfail" :
  360. "");
  361. if (pci_read_config_word(dd->pcidev,
  362. dd->ipath_ht_slave_off + 0x8,
  363. &ctrl1))
  364. dev_info(&dd->pcidev->dev, "Couldn't read "
  365. "linkctrl1 of slave/primary "
  366. "config block\n");
  367. else if (!(ctrl1 & 1 << 6))
  368. /* not if EOC bit set */
  369. ipath_dbg("HT linkctrl1 0x%x%s%s\n", ctrl1,
  370. ((ctrl1 >> 8) & 7) ? " CRC" : "",
  371. ((ctrl1 >> 4) & 1) ? "linkfail" :
  372. "");
  373. /* disable until driver reloaded */
  374. dd->ipath_hwerrmask &= ~crcbits;
  375. ipath_write_kreg(dd, dd->ipath_kregs->kr_hwerrmask,
  376. dd->ipath_hwerrmask);
  377. ipath_dbg("HT crc errs: %s\n", msg);
  378. } else
  379. ipath_dbg("ignoring HT crc errors 0x%llx, "
  380. "not in use\n", (unsigned long long)
  381. (hwerrs & (_IPATH_HTLINK0_CRCBITS |
  382. _IPATH_HTLINK1_CRCBITS)));
  383. }
  384. /* 6110 specific hardware errors... */
  385. static const struct ipath_hwerror_msgs ipath_6110_hwerror_msgs[] = {
  386. INFINIPATH_HWE_MSG(HTCBUSIREQPARITYERR, "HTC Ireq Parity"),
  387. INFINIPATH_HWE_MSG(HTCBUSTREQPARITYERR, "HTC Treq Parity"),
  388. INFINIPATH_HWE_MSG(HTCBUSTRESPPARITYERR, "HTC Tresp Parity"),
  389. INFINIPATH_HWE_MSG(HTCMISCERR5, "HT core Misc5"),
  390. INFINIPATH_HWE_MSG(HTCMISCERR6, "HT core Misc6"),
  391. INFINIPATH_HWE_MSG(HTCMISCERR7, "HT core Misc7"),
  392. INFINIPATH_HWE_MSG(RXDSYNCMEMPARITYERR, "Rx Dsync"),
  393. INFINIPATH_HWE_MSG(SERDESPLLFAILED, "SerDes PLL"),
  394. };
  395. #define TXE_PIO_PARITY ((INFINIPATH_HWE_TXEMEMPARITYERR_PIOBUF | \
  396. INFINIPATH_HWE_TXEMEMPARITYERR_PIOPBC) \
  397. << INFINIPATH_HWE_TXEMEMPARITYERR_SHIFT)
  398. #define RXE_EAGER_PARITY (INFINIPATH_HWE_RXEMEMPARITYERR_EAGERTID \
  399. << INFINIPATH_HWE_RXEMEMPARITYERR_SHIFT)
  400. static int ipath_ht_txe_recover(struct ipath_devdata *);
  401. /**
  402. * ipath_ht_handle_hwerrors - display hardware errors.
  403. * @dd: the infinipath device
  404. * @msg: the output buffer
  405. * @msgl: the size of the output buffer
  406. *
  407. * Use same msg buffer as regular errors to avoid excessive stack
  408. * use. Most hardware errors are catastrophic, but for right now,
  409. * we'll print them and continue. We reuse the same message buffer as
  410. * ipath_handle_errors() to avoid excessive stack usage.
  411. */
  412. static void ipath_ht_handle_hwerrors(struct ipath_devdata *dd, char *msg,
  413. size_t msgl)
  414. {
  415. ipath_err_t hwerrs;
  416. u32 bits, ctrl;
  417. int isfatal = 0;
  418. char bitsmsg[64];
  419. int log_idx;
  420. hwerrs = ipath_read_kreg64(dd, dd->ipath_kregs->kr_hwerrstatus);
  421. if (!hwerrs) {
  422. ipath_cdbg(VERBOSE, "Called but no hardware errors set\n");
  423. /*
  424. * better than printing cofusing messages
  425. * This seems to be related to clearing the crc error, or
  426. * the pll error during init.
  427. */
  428. goto bail;
  429. } else if (hwerrs == -1LL) {
  430. ipath_dev_err(dd, "Read of hardware error status failed "
  431. "(all bits set); ignoring\n");
  432. goto bail;
  433. }
  434. ipath_stats.sps_hwerrs++;
  435. /* Always clear the error status register, except MEMBISTFAIL,
  436. * regardless of whether we continue or stop using the chip.
  437. * We want that set so we know it failed, even across driver reload.
  438. * We'll still ignore it in the hwerrmask. We do this partly for
  439. * diagnostics, but also for support */
  440. ipath_write_kreg(dd, dd->ipath_kregs->kr_hwerrclear,
  441. hwerrs&~INFINIPATH_HWE_MEMBISTFAILED);
  442. hwerrs &= dd->ipath_hwerrmask;
  443. /* We log some errors to EEPROM, check if we have any of those. */
  444. for (log_idx = 0; log_idx < IPATH_EEP_LOG_CNT; ++log_idx)
  445. if (hwerrs & dd->ipath_eep_st_masks[log_idx].hwerrs_to_log)
  446. ipath_inc_eeprom_err(dd, log_idx, 1);
  447. /*
  448. * make sure we get this much out, unless told to be quiet,
  449. * it's a parity error we may recover from,
  450. * or it's occurred within the last 5 seconds
  451. */
  452. if ((hwerrs & ~(dd->ipath_lasthwerror | TXE_PIO_PARITY |
  453. RXE_EAGER_PARITY)) ||
  454. (ipath_debug & __IPATH_VERBDBG))
  455. dev_info(&dd->pcidev->dev, "Hardware error: hwerr=0x%llx "
  456. "(cleared)\n", (unsigned long long) hwerrs);
  457. dd->ipath_lasthwerror |= hwerrs;
  458. if (hwerrs & ~dd->ipath_hwe_bitsextant)
  459. ipath_dev_err(dd, "hwerror interrupt with unknown errors "
  460. "%llx set\n", (unsigned long long)
  461. (hwerrs & ~dd->ipath_hwe_bitsextant));
  462. ctrl = ipath_read_kreg32(dd, dd->ipath_kregs->kr_control);
  463. if ((ctrl & INFINIPATH_C_FREEZEMODE) && !ipath_diag_inuse) {
  464. /*
  465. * parity errors in send memory are recoverable,
  466. * just cancel the send (if indicated in * sendbuffererror),
  467. * count the occurrence, unfreeze (if no other handled
  468. * hardware error bits are set), and continue. They can
  469. * occur if a processor speculative read is done to the PIO
  470. * buffer while we are sending a packet, for example.
  471. */
  472. if ((hwerrs & TXE_PIO_PARITY) && ipath_ht_txe_recover(dd))
  473. hwerrs &= ~TXE_PIO_PARITY;
  474. if (hwerrs & RXE_EAGER_PARITY)
  475. ipath_dev_err(dd, "RXE parity, Eager TID error is not "
  476. "recoverable\n");
  477. if (!hwerrs) {
  478. ipath_dbg("Clearing freezemode on ignored or "
  479. "recovered hardware error\n");
  480. ipath_clear_freeze(dd);
  481. }
  482. }
  483. *msg = '\0';
  484. /*
  485. * may someday want to decode into which bits are which
  486. * functional area for parity errors, etc.
  487. */
  488. if (hwerrs & (infinipath_hwe_htcmemparityerr_mask
  489. << INFINIPATH_HWE_HTCMEMPARITYERR_SHIFT)) {
  490. bits = (u32) ((hwerrs >>
  491. INFINIPATH_HWE_HTCMEMPARITYERR_SHIFT) &
  492. INFINIPATH_HWE_HTCMEMPARITYERR_MASK);
  493. snprintf(bitsmsg, sizeof bitsmsg, "[HTC Parity Errs %x] ",
  494. bits);
  495. strlcat(msg, bitsmsg, msgl);
  496. }
  497. ipath_format_hwerrors(hwerrs,
  498. ipath_6110_hwerror_msgs,
  499. sizeof(ipath_6110_hwerror_msgs) /
  500. sizeof(ipath_6110_hwerror_msgs[0]),
  501. msg, msgl);
  502. if (hwerrs & (_IPATH_HTLINK0_CRCBITS | _IPATH_HTLINK1_CRCBITS))
  503. hwerr_crcbits(dd, hwerrs, msg, msgl);
  504. if (hwerrs & INFINIPATH_HWE_MEMBISTFAILED) {
  505. strlcat(msg, "[Memory BIST test failed, InfiniPath hardware unusable]",
  506. msgl);
  507. /* ignore from now on, so disable until driver reloaded */
  508. dd->ipath_hwerrmask &= ~INFINIPATH_HWE_MEMBISTFAILED;
  509. ipath_write_kreg(dd, dd->ipath_kregs->kr_hwerrmask,
  510. dd->ipath_hwerrmask);
  511. }
  512. #define _IPATH_PLL_FAIL (INFINIPATH_HWE_COREPLL_FBSLIP | \
  513. INFINIPATH_HWE_COREPLL_RFSLIP | \
  514. INFINIPATH_HWE_HTBPLL_FBSLIP | \
  515. INFINIPATH_HWE_HTBPLL_RFSLIP | \
  516. INFINIPATH_HWE_HTAPLL_FBSLIP | \
  517. INFINIPATH_HWE_HTAPLL_RFSLIP)
  518. if (hwerrs & _IPATH_PLL_FAIL) {
  519. snprintf(bitsmsg, sizeof bitsmsg,
  520. "[PLL failed (%llx), InfiniPath hardware unusable]",
  521. (unsigned long long) (hwerrs & _IPATH_PLL_FAIL));
  522. strlcat(msg, bitsmsg, msgl);
  523. /* ignore from now on, so disable until driver reloaded */
  524. dd->ipath_hwerrmask &= ~(hwerrs & _IPATH_PLL_FAIL);
  525. ipath_write_kreg(dd, dd->ipath_kregs->kr_hwerrmask,
  526. dd->ipath_hwerrmask);
  527. }
  528. if (hwerrs & INFINIPATH_HWE_SERDESPLLFAILED) {
  529. /*
  530. * If it occurs, it is left masked since the eternal
  531. * interface is unused
  532. */
  533. dd->ipath_hwerrmask &= ~INFINIPATH_HWE_SERDESPLLFAILED;
  534. ipath_write_kreg(dd, dd->ipath_kregs->kr_hwerrmask,
  535. dd->ipath_hwerrmask);
  536. }
  537. if (hwerrs) {
  538. /*
  539. * if any set that we aren't ignoring; only
  540. * make the complaint once, in case it's stuck
  541. * or recurring, and we get here multiple
  542. * times.
  543. * force link down, so switch knows, and
  544. * LEDs are turned off
  545. */
  546. if (dd->ipath_flags & IPATH_INITTED) {
  547. ipath_set_linkstate(dd, IPATH_IB_LINKDOWN);
  548. ipath_setup_ht_setextled(dd,
  549. INFINIPATH_IBCS_L_STATE_DOWN,
  550. INFINIPATH_IBCS_LT_STATE_DISABLED);
  551. ipath_dev_err(dd, "Fatal Hardware Error (freeze "
  552. "mode), no longer usable, SN %.16s\n",
  553. dd->ipath_serial);
  554. isfatal = 1;
  555. }
  556. *dd->ipath_statusp &= ~IPATH_STATUS_IB_READY;
  557. /* mark as having had error */
  558. *dd->ipath_statusp |= IPATH_STATUS_HWERROR;
  559. /*
  560. * mark as not usable, at a minimum until driver
  561. * is reloaded, probably until reboot, since no
  562. * other reset is possible.
  563. */
  564. dd->ipath_flags &= ~IPATH_INITTED;
  565. }
  566. else
  567. *msg = 0; /* recovered from all of them */
  568. if (*msg)
  569. ipath_dev_err(dd, "%s hardware error\n", msg);
  570. if (isfatal && !ipath_diag_inuse && dd->ipath_freezemsg)
  571. /*
  572. * for status file; if no trailing brace is copied,
  573. * we'll know it was truncated.
  574. */
  575. snprintf(dd->ipath_freezemsg,
  576. dd->ipath_freezelen, "{%s}", msg);
  577. bail:;
  578. }
  579. /**
  580. * ipath_ht_boardname - fill in the board name
  581. * @dd: the infinipath device
  582. * @name: the output buffer
  583. * @namelen: the size of the output buffer
  584. *
  585. * fill in the board name, based on the board revision register
  586. */
  587. static int ipath_ht_boardname(struct ipath_devdata *dd, char *name,
  588. size_t namelen)
  589. {
  590. char *n = NULL;
  591. u8 boardrev = dd->ipath_boardrev;
  592. int ret = 0;
  593. switch (boardrev) {
  594. case 5:
  595. /*
  596. * original production board; two production levels, with
  597. * different serial number ranges. See ipath_ht_early_init() for
  598. * case where we enable IPATH_GPIO_INTR for later serial # range.
  599. * Original 112* serial number is no longer supported.
  600. */
  601. n = "InfiniPath_QHT7040";
  602. break;
  603. case 7:
  604. /* small form factor production board */
  605. n = "InfiniPath_QHT7140";
  606. break;
  607. default: /* don't know, just print the number */
  608. ipath_dev_err(dd, "Don't yet know about board "
  609. "with ID %u\n", boardrev);
  610. snprintf(name, namelen, "Unknown_InfiniPath_QHT7xxx_%u",
  611. boardrev);
  612. ret = 1;
  613. break;
  614. }
  615. if (n)
  616. snprintf(name, namelen, "%s", n);
  617. if (ret) {
  618. ipath_dev_err(dd, "Unsupported InfiniPath board %s!\n", name);
  619. goto bail;
  620. }
  621. if (dd->ipath_majrev != 3 || (dd->ipath_minrev < 2 ||
  622. dd->ipath_minrev > 4)) {
  623. /*
  624. * This version of the driver only supports Rev 3.2 - 3.4
  625. */
  626. ipath_dev_err(dd,
  627. "Unsupported InfiniPath hardware revision %u.%u!\n",
  628. dd->ipath_majrev, dd->ipath_minrev);
  629. ret = 1;
  630. goto bail;
  631. }
  632. /*
  633. * pkt/word counters are 32 bit, and therefore wrap fast enough
  634. * that we snapshot them from a timer, and maintain 64 bit shadow
  635. * copies
  636. */
  637. dd->ipath_flags |= IPATH_32BITCOUNTERS;
  638. dd->ipath_flags |= IPATH_GPIO_INTR;
  639. if (dd->ipath_htspeed != 800)
  640. ipath_dev_err(dd,
  641. "Incorrectly configured for HT @ %uMHz\n",
  642. dd->ipath_htspeed);
  643. ret = 0;
  644. bail:
  645. return ret;
  646. }
  647. static void ipath_check_htlink(struct ipath_devdata *dd)
  648. {
  649. u8 linkerr, link_off, i;
  650. for (i = 0; i < 2; i++) {
  651. link_off = dd->ipath_ht_slave_off + i * 4 + 0xd;
  652. if (pci_read_config_byte(dd->pcidev, link_off, &linkerr))
  653. dev_info(&dd->pcidev->dev, "Couldn't read "
  654. "linkerror%d of HT slave/primary block\n",
  655. i);
  656. else if (linkerr & 0xf0) {
  657. ipath_cdbg(VERBOSE, "HT linkerr%d bits 0x%x set, "
  658. "clearing\n", linkerr >> 4, i);
  659. /*
  660. * writing the linkerr bits that are set should
  661. * clear them
  662. */
  663. if (pci_write_config_byte(dd->pcidev, link_off,
  664. linkerr))
  665. ipath_dbg("Failed write to clear HT "
  666. "linkerror%d\n", i);
  667. if (pci_read_config_byte(dd->pcidev, link_off,
  668. &linkerr))
  669. dev_info(&dd->pcidev->dev,
  670. "Couldn't reread linkerror%d of "
  671. "HT slave/primary block\n", i);
  672. else if (linkerr & 0xf0)
  673. dev_info(&dd->pcidev->dev,
  674. "HT linkerror%d bits 0x%x "
  675. "couldn't be cleared\n",
  676. i, linkerr >> 4);
  677. }
  678. }
  679. }
  680. static int ipath_setup_ht_reset(struct ipath_devdata *dd)
  681. {
  682. ipath_dbg("No reset possible for this InfiniPath hardware\n");
  683. return 0;
  684. }
  685. #define HT_INTR_DISC_CONFIG 0x80 /* HT interrupt and discovery cap */
  686. #define HT_INTR_REG_INDEX 2 /* intconfig requires indirect accesses */
  687. /*
  688. * Bits 13-15 of command==0 is slave/primary block. Clear any HT CRC
  689. * errors. We only bother to do this at load time, because it's OK if
  690. * it happened before we were loaded (first time after boot/reset),
  691. * but any time after that, it's fatal anyway. Also need to not check
  692. * for for upper byte errors if we are in 8 bit mode, so figure out
  693. * our width. For now, at least, also complain if it's 8 bit.
  694. */
  695. static void slave_or_pri_blk(struct ipath_devdata *dd, struct pci_dev *pdev,
  696. int pos, u8 cap_type)
  697. {
  698. u8 linkwidth = 0, linkerr, link_a_b_off, link_off;
  699. u16 linkctrl = 0;
  700. int i;
  701. dd->ipath_ht_slave_off = pos;
  702. /* command word, master_host bit */
  703. /* master host || slave */
  704. if ((cap_type >> 2) & 1)
  705. link_a_b_off = 4;
  706. else
  707. link_a_b_off = 0;
  708. ipath_cdbg(VERBOSE, "HT%u (Link %c) connected to processor\n",
  709. link_a_b_off ? 1 : 0,
  710. link_a_b_off ? 'B' : 'A');
  711. link_a_b_off += pos;
  712. /*
  713. * check both link control registers; clear both HT CRC sets if
  714. * necessary.
  715. */
  716. for (i = 0; i < 2; i++) {
  717. link_off = pos + i * 4 + 0x4;
  718. if (pci_read_config_word(pdev, link_off, &linkctrl))
  719. ipath_dev_err(dd, "Couldn't read HT link control%d "
  720. "register\n", i);
  721. else if (linkctrl & (0xf << 8)) {
  722. ipath_cdbg(VERBOSE, "Clear linkctrl%d CRC Error "
  723. "bits %x\n", i, linkctrl & (0xf << 8));
  724. /*
  725. * now write them back to clear the error.
  726. */
  727. pci_write_config_byte(pdev, link_off,
  728. linkctrl & (0xf << 8));
  729. }
  730. }
  731. /*
  732. * As with HT CRC bits, same for protocol errors that might occur
  733. * during boot.
  734. */
  735. for (i = 0; i < 2; i++) {
  736. link_off = pos + i * 4 + 0xd;
  737. if (pci_read_config_byte(pdev, link_off, &linkerr))
  738. dev_info(&pdev->dev, "Couldn't read linkerror%d "
  739. "of HT slave/primary block\n", i);
  740. else if (linkerr & 0xf0) {
  741. ipath_cdbg(VERBOSE, "HT linkerr%d bits 0x%x set, "
  742. "clearing\n", linkerr >> 4, i);
  743. /*
  744. * writing the linkerr bits that are set will clear
  745. * them
  746. */
  747. if (pci_write_config_byte
  748. (pdev, link_off, linkerr))
  749. ipath_dbg("Failed write to clear HT "
  750. "linkerror%d\n", i);
  751. if (pci_read_config_byte(pdev, link_off, &linkerr))
  752. dev_info(&pdev->dev, "Couldn't reread "
  753. "linkerror%d of HT slave/primary "
  754. "block\n", i);
  755. else if (linkerr & 0xf0)
  756. dev_info(&pdev->dev, "HT linkerror%d bits "
  757. "0x%x couldn't be cleared\n",
  758. i, linkerr >> 4);
  759. }
  760. }
  761. /*
  762. * this is just for our link to the host, not devices connected
  763. * through tunnel.
  764. */
  765. if (pci_read_config_byte(pdev, link_a_b_off + 7, &linkwidth))
  766. ipath_dev_err(dd, "Couldn't read HT link width "
  767. "config register\n");
  768. else {
  769. u32 width;
  770. switch (linkwidth & 7) {
  771. case 5:
  772. width = 4;
  773. break;
  774. case 4:
  775. width = 2;
  776. break;
  777. case 3:
  778. width = 32;
  779. break;
  780. case 1:
  781. width = 16;
  782. break;
  783. case 0:
  784. default: /* if wrong, assume 8 bit */
  785. width = 8;
  786. break;
  787. }
  788. dd->ipath_htwidth = width;
  789. if (linkwidth != 0x11) {
  790. ipath_dev_err(dd, "Not configured for 16 bit HT "
  791. "(%x)\n", linkwidth);
  792. if (!(linkwidth & 0xf)) {
  793. ipath_dbg("Will ignore HT lane1 errors\n");
  794. dd->ipath_flags |= IPATH_8BIT_IN_HT0;
  795. }
  796. }
  797. }
  798. /*
  799. * this is just for our link to the host, not devices connected
  800. * through tunnel.
  801. */
  802. if (pci_read_config_byte(pdev, link_a_b_off + 0xd, &linkwidth))
  803. ipath_dev_err(dd, "Couldn't read HT link frequency "
  804. "config register\n");
  805. else {
  806. u32 speed;
  807. switch (linkwidth & 0xf) {
  808. case 6:
  809. speed = 1000;
  810. break;
  811. case 5:
  812. speed = 800;
  813. break;
  814. case 4:
  815. speed = 600;
  816. break;
  817. case 3:
  818. speed = 500;
  819. break;
  820. case 2:
  821. speed = 400;
  822. break;
  823. case 1:
  824. speed = 300;
  825. break;
  826. default:
  827. /*
  828. * assume reserved and vendor-specific are 200...
  829. */
  830. case 0:
  831. speed = 200;
  832. break;
  833. }
  834. dd->ipath_htspeed = speed;
  835. }
  836. }
  837. static int ipath_ht_intconfig(struct ipath_devdata *dd)
  838. {
  839. int ret;
  840. if (dd->ipath_intconfig) {
  841. ipath_write_kreg(dd, dd->ipath_kregs->kr_interruptconfig,
  842. dd->ipath_intconfig); /* interrupt address */
  843. ret = 0;
  844. } else {
  845. ipath_dev_err(dd, "No interrupts enabled, couldn't setup "
  846. "interrupt address\n");
  847. ret = -EINVAL;
  848. }
  849. return ret;
  850. }
  851. static void ipath_ht_irq_update(struct pci_dev *dev, int irq,
  852. struct ht_irq_msg *msg)
  853. {
  854. struct ipath_devdata *dd = pci_get_drvdata(dev);
  855. u64 prev_intconfig = dd->ipath_intconfig;
  856. dd->ipath_intconfig = msg->address_lo;
  857. dd->ipath_intconfig |= ((u64) msg->address_hi) << 32;
  858. /*
  859. * If the previous value of dd->ipath_intconfig is zero, we're
  860. * getting configured for the first time, and must not program the
  861. * intconfig register here (it will be programmed later, when the
  862. * hardware is ready). Otherwise, we should.
  863. */
  864. if (prev_intconfig)
  865. ipath_ht_intconfig(dd);
  866. }
  867. /**
  868. * ipath_setup_ht_config - setup the interruptconfig register
  869. * @dd: the infinipath device
  870. * @pdev: the PCI device
  871. *
  872. * setup the interruptconfig register from the HT config info.
  873. * Also clear CRC errors in HT linkcontrol, if necessary.
  874. * This is done only for the real hardware. It is done before
  875. * chip address space is initted, so can't touch infinipath registers
  876. */
  877. static int ipath_setup_ht_config(struct ipath_devdata *dd,
  878. struct pci_dev *pdev)
  879. {
  880. int pos, ret;
  881. ret = __ht_create_irq(pdev, 0, ipath_ht_irq_update);
  882. if (ret < 0) {
  883. ipath_dev_err(dd, "Couldn't create interrupt handler: "
  884. "err %d\n", ret);
  885. goto bail;
  886. }
  887. dd->ipath_irq = ret;
  888. ret = 0;
  889. /*
  890. * Handle clearing CRC errors in linkctrl register if necessary. We
  891. * do this early, before we ever enable errors or hardware errors,
  892. * mostly to avoid causing the chip to enter freeze mode.
  893. */
  894. pos = pci_find_capability(pdev, PCI_CAP_ID_HT);
  895. if (!pos) {
  896. ipath_dev_err(dd, "Couldn't find HyperTransport "
  897. "capability; no interrupts\n");
  898. ret = -ENODEV;
  899. goto bail;
  900. }
  901. do {
  902. u8 cap_type;
  903. /* the HT capability type byte is 3 bytes after the
  904. * capability byte.
  905. */
  906. if (pci_read_config_byte(pdev, pos + 3, &cap_type)) {
  907. dev_info(&pdev->dev, "Couldn't read config "
  908. "command @ %d\n", pos);
  909. continue;
  910. }
  911. if (!(cap_type & 0xE0))
  912. slave_or_pri_blk(dd, pdev, pos, cap_type);
  913. } while ((pos = pci_find_next_capability(pdev, pos,
  914. PCI_CAP_ID_HT)));
  915. bail:
  916. return ret;
  917. }
  918. /**
  919. * ipath_setup_ht_cleanup - clean up any per-chip chip-specific stuff
  920. * @dd: the infinipath device
  921. *
  922. * Called during driver unload.
  923. * This is currently a nop for the HT chip, not for all chips
  924. */
  925. static void ipath_setup_ht_cleanup(struct ipath_devdata *dd)
  926. {
  927. }
  928. /**
  929. * ipath_setup_ht_setextled - set the state of the two external LEDs
  930. * @dd: the infinipath device
  931. * @lst: the L state
  932. * @ltst: the LT state
  933. *
  934. * Set the state of the two external LEDs, to indicate physical and
  935. * logical state of IB link. For this chip (at least with recommended
  936. * board pinouts), LED1 is Green (physical state), and LED2 is Yellow
  937. * (logical state)
  938. *
  939. * Note: We try to match the Mellanox HCA LED behavior as best
  940. * we can. Green indicates physical link state is OK (something is
  941. * plugged in, and we can train).
  942. * Amber indicates the link is logically up (ACTIVE).
  943. * Mellanox further blinks the amber LED to indicate data packet
  944. * activity, but we have no hardware support for that, so it would
  945. * require waking up every 10-20 msecs and checking the counters
  946. * on the chip, and then turning the LED off if appropriate. That's
  947. * visible overhead, so not something we will do.
  948. *
  949. */
  950. static void ipath_setup_ht_setextled(struct ipath_devdata *dd,
  951. u64 lst, u64 ltst)
  952. {
  953. u64 extctl;
  954. unsigned long flags = 0;
  955. /* the diags use the LED to indicate diag info, so we leave
  956. * the external LED alone when the diags are running */
  957. if (ipath_diag_inuse)
  958. return;
  959. /* Allow override of LED display for, e.g. Locating system in rack */
  960. if (dd->ipath_led_override) {
  961. ltst = (dd->ipath_led_override & IPATH_LED_PHYS)
  962. ? INFINIPATH_IBCS_LT_STATE_LINKUP
  963. : INFINIPATH_IBCS_LT_STATE_DISABLED;
  964. lst = (dd->ipath_led_override & IPATH_LED_LOG)
  965. ? INFINIPATH_IBCS_L_STATE_ACTIVE
  966. : INFINIPATH_IBCS_L_STATE_DOWN;
  967. }
  968. spin_lock_irqsave(&dd->ipath_gpio_lock, flags);
  969. /*
  970. * start by setting both LED control bits to off, then turn
  971. * on the appropriate bit(s).
  972. */
  973. if (dd->ipath_boardrev == 8) { /* LS/X-1 uses different pins */
  974. /*
  975. * major difference is that INFINIPATH_EXTC_LEDGBLERR_OFF
  976. * is inverted, because it is normally used to indicate
  977. * a hardware fault at reset, if there were errors
  978. */
  979. extctl = (dd->ipath_extctrl & ~INFINIPATH_EXTC_LEDGBLOK_ON)
  980. | INFINIPATH_EXTC_LEDGBLERR_OFF;
  981. if (ltst == INFINIPATH_IBCS_LT_STATE_LINKUP)
  982. extctl &= ~INFINIPATH_EXTC_LEDGBLERR_OFF;
  983. if (lst == INFINIPATH_IBCS_L_STATE_ACTIVE)
  984. extctl |= INFINIPATH_EXTC_LEDGBLOK_ON;
  985. }
  986. else {
  987. extctl = dd->ipath_extctrl &
  988. ~(INFINIPATH_EXTC_LED1PRIPORT_ON |
  989. INFINIPATH_EXTC_LED2PRIPORT_ON);
  990. if (ltst == INFINIPATH_IBCS_LT_STATE_LINKUP)
  991. extctl |= INFINIPATH_EXTC_LED1PRIPORT_ON;
  992. if (lst == INFINIPATH_IBCS_L_STATE_ACTIVE)
  993. extctl |= INFINIPATH_EXTC_LED2PRIPORT_ON;
  994. }
  995. dd->ipath_extctrl = extctl;
  996. ipath_write_kreg(dd, dd->ipath_kregs->kr_extctrl, extctl);
  997. spin_unlock_irqrestore(&dd->ipath_gpio_lock, flags);
  998. }
  999. static void ipath_init_ht_variables(struct ipath_devdata *dd)
  1000. {
  1001. dd->ipath_gpio_sda_num = _IPATH_GPIO_SDA_NUM;
  1002. dd->ipath_gpio_scl_num = _IPATH_GPIO_SCL_NUM;
  1003. dd->ipath_gpio_sda = IPATH_GPIO_SDA;
  1004. dd->ipath_gpio_scl = IPATH_GPIO_SCL;
  1005. /* Fill in shifts for RcvCtrl. */
  1006. dd->ipath_r_portenable_shift = INFINIPATH_R_PORTENABLE_SHIFT;
  1007. dd->ipath_r_intravail_shift = INFINIPATH_R_INTRAVAIL_SHIFT;
  1008. dd->ipath_r_tailupd_shift = INFINIPATH_R_TAILUPD_SHIFT;
  1009. dd->ipath_r_portcfg_shift = 0; /* Not on IBA6110 */
  1010. dd->ipath_i_bitsextant =
  1011. (INFINIPATH_I_RCVURG_MASK << INFINIPATH_I_RCVURG_SHIFT) |
  1012. (INFINIPATH_I_RCVAVAIL_MASK <<
  1013. INFINIPATH_I_RCVAVAIL_SHIFT) |
  1014. INFINIPATH_I_ERROR | INFINIPATH_I_SPIOSENT |
  1015. INFINIPATH_I_SPIOBUFAVAIL | INFINIPATH_I_GPIO;
  1016. dd->ipath_e_bitsextant =
  1017. INFINIPATH_E_RFORMATERR | INFINIPATH_E_RVCRC |
  1018. INFINIPATH_E_RICRC | INFINIPATH_E_RMINPKTLEN |
  1019. INFINIPATH_E_RMAXPKTLEN | INFINIPATH_E_RLONGPKTLEN |
  1020. INFINIPATH_E_RSHORTPKTLEN | INFINIPATH_E_RUNEXPCHAR |
  1021. INFINIPATH_E_RUNSUPVL | INFINIPATH_E_REBP |
  1022. INFINIPATH_E_RIBFLOW | INFINIPATH_E_RBADVERSION |
  1023. INFINIPATH_E_RRCVEGRFULL | INFINIPATH_E_RRCVHDRFULL |
  1024. INFINIPATH_E_RBADTID | INFINIPATH_E_RHDRLEN |
  1025. INFINIPATH_E_RHDR | INFINIPATH_E_RIBLOSTLINK |
  1026. INFINIPATH_E_SMINPKTLEN | INFINIPATH_E_SMAXPKTLEN |
  1027. INFINIPATH_E_SUNDERRUN | INFINIPATH_E_SPKTLEN |
  1028. INFINIPATH_E_SDROPPEDSMPPKT | INFINIPATH_E_SDROPPEDDATAPKT |
  1029. INFINIPATH_E_SPIOARMLAUNCH | INFINIPATH_E_SUNEXPERRPKTNUM |
  1030. INFINIPATH_E_SUNSUPVL | INFINIPATH_E_IBSTATUSCHANGED |
  1031. INFINIPATH_E_INVALIDADDR | INFINIPATH_E_RESET |
  1032. INFINIPATH_E_HARDWARE;
  1033. dd->ipath_hwe_bitsextant =
  1034. (INFINIPATH_HWE_HTCMEMPARITYERR_MASK <<
  1035. INFINIPATH_HWE_HTCMEMPARITYERR_SHIFT) |
  1036. (INFINIPATH_HWE_TXEMEMPARITYERR_MASK <<
  1037. INFINIPATH_HWE_TXEMEMPARITYERR_SHIFT) |
  1038. (INFINIPATH_HWE_RXEMEMPARITYERR_MASK <<
  1039. INFINIPATH_HWE_RXEMEMPARITYERR_SHIFT) |
  1040. INFINIPATH_HWE_HTCLNKABYTE0CRCERR |
  1041. INFINIPATH_HWE_HTCLNKABYTE1CRCERR |
  1042. INFINIPATH_HWE_HTCLNKBBYTE0CRCERR |
  1043. INFINIPATH_HWE_HTCLNKBBYTE1CRCERR |
  1044. INFINIPATH_HWE_HTCMISCERR4 |
  1045. INFINIPATH_HWE_HTCMISCERR5 | INFINIPATH_HWE_HTCMISCERR6 |
  1046. INFINIPATH_HWE_HTCMISCERR7 |
  1047. INFINIPATH_HWE_HTCBUSTREQPARITYERR |
  1048. INFINIPATH_HWE_HTCBUSTRESPPARITYERR |
  1049. INFINIPATH_HWE_HTCBUSIREQPARITYERR |
  1050. INFINIPATH_HWE_RXDSYNCMEMPARITYERR |
  1051. INFINIPATH_HWE_MEMBISTFAILED |
  1052. INFINIPATH_HWE_COREPLL_FBSLIP |
  1053. INFINIPATH_HWE_COREPLL_RFSLIP |
  1054. INFINIPATH_HWE_HTBPLL_FBSLIP |
  1055. INFINIPATH_HWE_HTBPLL_RFSLIP |
  1056. INFINIPATH_HWE_HTAPLL_FBSLIP |
  1057. INFINIPATH_HWE_HTAPLL_RFSLIP |
  1058. INFINIPATH_HWE_SERDESPLLFAILED |
  1059. INFINIPATH_HWE_IBCBUSTOSPCPARITYERR |
  1060. INFINIPATH_HWE_IBCBUSFRSPCPARITYERR;
  1061. dd->ipath_i_rcvavail_mask = INFINIPATH_I_RCVAVAIL_MASK;
  1062. dd->ipath_i_rcvurg_mask = INFINIPATH_I_RCVURG_MASK;
  1063. /*
  1064. * EEPROM error log 0 is TXE Parity errors. 1 is RXE Parity.
  1065. * 2 is Some Misc, 3 is reserved for future.
  1066. */
  1067. dd->ipath_eep_st_masks[0].hwerrs_to_log =
  1068. INFINIPATH_HWE_TXEMEMPARITYERR_MASK <<
  1069. INFINIPATH_HWE_TXEMEMPARITYERR_SHIFT;
  1070. dd->ipath_eep_st_masks[1].hwerrs_to_log =
  1071. INFINIPATH_HWE_RXEMEMPARITYERR_MASK <<
  1072. INFINIPATH_HWE_RXEMEMPARITYERR_SHIFT;
  1073. dd->ipath_eep_st_masks[2].errs_to_log =
  1074. INFINIPATH_E_INVALIDADDR | INFINIPATH_E_RESET;
  1075. }
  1076. /**
  1077. * ipath_ht_init_hwerrors - enable hardware errors
  1078. * @dd: the infinipath device
  1079. *
  1080. * now that we have finished initializing everything that might reasonably
  1081. * cause a hardware error, and cleared those errors bits as they occur,
  1082. * we can enable hardware errors in the mask (potentially enabling
  1083. * freeze mode), and enable hardware errors as errors (along with
  1084. * everything else) in errormask
  1085. */
  1086. static void ipath_ht_init_hwerrors(struct ipath_devdata *dd)
  1087. {
  1088. ipath_err_t val;
  1089. u64 extsval;
  1090. extsval = ipath_read_kreg64(dd, dd->ipath_kregs->kr_extstatus);
  1091. if (!(extsval & INFINIPATH_EXTS_MEMBIST_ENDTEST))
  1092. ipath_dev_err(dd, "MemBIST did not complete!\n");
  1093. if (extsval & INFINIPATH_EXTS_MEMBIST_CORRECT)
  1094. ipath_dbg("MemBIST corrected\n");
  1095. ipath_check_htlink(dd);
  1096. /* barring bugs, all hwerrors become interrupts, which can */
  1097. val = -1LL;
  1098. /* don't look at crc lane1 if 8 bit */
  1099. if (dd->ipath_flags & IPATH_8BIT_IN_HT0)
  1100. val &= ~infinipath_hwe_htclnkabyte1crcerr;
  1101. /* don't look at crc lane1 if 8 bit */
  1102. if (dd->ipath_flags & IPATH_8BIT_IN_HT1)
  1103. val &= ~infinipath_hwe_htclnkbbyte1crcerr;
  1104. /*
  1105. * disable RXDSYNCMEMPARITY because external serdes is unused,
  1106. * and therefore the logic will never be used or initialized,
  1107. * and uninitialized state will normally result in this error
  1108. * being asserted. Similarly for the external serdess pll
  1109. * lock signal.
  1110. */
  1111. val &= ~(INFINIPATH_HWE_SERDESPLLFAILED |
  1112. INFINIPATH_HWE_RXDSYNCMEMPARITYERR);
  1113. /*
  1114. * Disable MISCERR4 because of an inversion in the HT core
  1115. * logic checking for errors that cause this bit to be set.
  1116. * The errata can also cause the protocol error bit to be set
  1117. * in the HT config space linkerror register(s).
  1118. */
  1119. val &= ~INFINIPATH_HWE_HTCMISCERR4;
  1120. /*
  1121. * PLL ignored because MDIO interface has a logic problem
  1122. * for reads, on Comstock and Ponderosa. BRINGUP
  1123. */
  1124. if (dd->ipath_boardrev == 4 || dd->ipath_boardrev == 9)
  1125. val &= ~INFINIPATH_HWE_SERDESPLLFAILED;
  1126. dd->ipath_hwerrmask = val;
  1127. }
  1128. /**
  1129. * ipath_ht_bringup_serdes - bring up the serdes
  1130. * @dd: the infinipath device
  1131. */
  1132. static int ipath_ht_bringup_serdes(struct ipath_devdata *dd)
  1133. {
  1134. u64 val, config1;
  1135. int ret = 0, change = 0;
  1136. ipath_dbg("Trying to bringup serdes\n");
  1137. if (ipath_read_kreg64(dd, dd->ipath_kregs->kr_hwerrstatus) &
  1138. INFINIPATH_HWE_SERDESPLLFAILED)
  1139. {
  1140. ipath_dbg("At start, serdes PLL failed bit set in "
  1141. "hwerrstatus, clearing and continuing\n");
  1142. ipath_write_kreg(dd, dd->ipath_kregs->kr_hwerrclear,
  1143. INFINIPATH_HWE_SERDESPLLFAILED);
  1144. }
  1145. val = ipath_read_kreg64(dd, dd->ipath_kregs->kr_serdesconfig0);
  1146. config1 = ipath_read_kreg64(dd, dd->ipath_kregs->kr_serdesconfig1);
  1147. ipath_cdbg(VERBOSE, "Initial serdes status is config0=%llx "
  1148. "config1=%llx, sstatus=%llx xgxs %llx\n",
  1149. (unsigned long long) val, (unsigned long long) config1,
  1150. (unsigned long long)
  1151. ipath_read_kreg64(dd, dd->ipath_kregs->kr_serdesstatus),
  1152. (unsigned long long)
  1153. ipath_read_kreg64(dd, dd->ipath_kregs->kr_xgxsconfig));
  1154. /* force reset on */
  1155. val |= INFINIPATH_SERDC0_RESET_PLL
  1156. /* | INFINIPATH_SERDC0_RESET_MASK */
  1157. ;
  1158. ipath_write_kreg(dd, dd->ipath_kregs->kr_serdesconfig0, val);
  1159. udelay(15); /* need pll reset set at least for a bit */
  1160. if (val & INFINIPATH_SERDC0_RESET_PLL) {
  1161. u64 val2 = val &= ~INFINIPATH_SERDC0_RESET_PLL;
  1162. /* set lane resets, and tx idle, during pll reset */
  1163. val2 |= INFINIPATH_SERDC0_RESET_MASK |
  1164. INFINIPATH_SERDC0_TXIDLE;
  1165. ipath_cdbg(VERBOSE, "Clearing serdes PLL reset (writing "
  1166. "%llx)\n", (unsigned long long) val2);
  1167. ipath_write_kreg(dd, dd->ipath_kregs->kr_serdesconfig0,
  1168. val2);
  1169. /*
  1170. * be sure chip saw it
  1171. */
  1172. val = ipath_read_kreg64(dd, dd->ipath_kregs->kr_scratch);
  1173. /*
  1174. * need pll reset clear at least 11 usec before lane
  1175. * resets cleared; give it a few more
  1176. */
  1177. udelay(15);
  1178. val = val2; /* for check below */
  1179. }
  1180. if (val & (INFINIPATH_SERDC0_RESET_PLL |
  1181. INFINIPATH_SERDC0_RESET_MASK |
  1182. INFINIPATH_SERDC0_TXIDLE)) {
  1183. val &= ~(INFINIPATH_SERDC0_RESET_PLL |
  1184. INFINIPATH_SERDC0_RESET_MASK |
  1185. INFINIPATH_SERDC0_TXIDLE);
  1186. /* clear them */
  1187. ipath_write_kreg(dd, dd->ipath_kregs->kr_serdesconfig0,
  1188. val);
  1189. }
  1190. val = ipath_read_kreg64(dd, dd->ipath_kregs->kr_xgxsconfig);
  1191. if (((val >> INFINIPATH_XGXS_MDIOADDR_SHIFT) &
  1192. INFINIPATH_XGXS_MDIOADDR_MASK) != 3) {
  1193. val &= ~(INFINIPATH_XGXS_MDIOADDR_MASK <<
  1194. INFINIPATH_XGXS_MDIOADDR_SHIFT);
  1195. /*
  1196. * we use address 3
  1197. */
  1198. val |= 3ULL << INFINIPATH_XGXS_MDIOADDR_SHIFT;
  1199. change = 1;
  1200. }
  1201. if (val & INFINIPATH_XGXS_RESET) {
  1202. /* normally true after boot */
  1203. val &= ~INFINIPATH_XGXS_RESET;
  1204. change = 1;
  1205. }
  1206. if (((val >> INFINIPATH_XGXS_RX_POL_SHIFT) &
  1207. INFINIPATH_XGXS_RX_POL_MASK) != dd->ipath_rx_pol_inv ) {
  1208. /* need to compensate for Tx inversion in partner */
  1209. val &= ~(INFINIPATH_XGXS_RX_POL_MASK <<
  1210. INFINIPATH_XGXS_RX_POL_SHIFT);
  1211. val |= dd->ipath_rx_pol_inv <<
  1212. INFINIPATH_XGXS_RX_POL_SHIFT;
  1213. change = 1;
  1214. }
  1215. if (change)
  1216. ipath_write_kreg(dd, dd->ipath_kregs->kr_xgxsconfig, val);
  1217. val = ipath_read_kreg64(dd, dd->ipath_kregs->kr_serdesconfig0);
  1218. /* clear current and de-emphasis bits */
  1219. config1 &= ~0x0ffffffff00ULL;
  1220. /* set current to 20ma */
  1221. config1 |= 0x00000000000ULL;
  1222. /* set de-emphasis to -5.68dB */
  1223. config1 |= 0x0cccc000000ULL;
  1224. ipath_write_kreg(dd, dd->ipath_kregs->kr_serdesconfig1, config1);
  1225. ipath_cdbg(VERBOSE, "After setup: serdes status is config0=%llx "
  1226. "config1=%llx, sstatus=%llx xgxs %llx\n",
  1227. (unsigned long long) val, (unsigned long long) config1,
  1228. (unsigned long long)
  1229. ipath_read_kreg64(dd, dd->ipath_kregs->kr_serdesstatus),
  1230. (unsigned long long)
  1231. ipath_read_kreg64(dd, dd->ipath_kregs->kr_xgxsconfig));
  1232. if (!ipath_waitfor_mdio_cmdready(dd)) {
  1233. ipath_write_kreg(dd, dd->ipath_kregs->kr_mdio,
  1234. ipath_mdio_req(IPATH_MDIO_CMD_READ, 31,
  1235. IPATH_MDIO_CTRL_XGXS_REG_8,
  1236. 0));
  1237. if (ipath_waitfor_complete(dd, dd->ipath_kregs->kr_mdio,
  1238. IPATH_MDIO_DATAVALID, &val))
  1239. ipath_dbg("Never got MDIO data for XGXS status "
  1240. "read\n");
  1241. else
  1242. ipath_cdbg(VERBOSE, "MDIO Read reg8, "
  1243. "'bank' 31 %x\n", (u32) val);
  1244. } else
  1245. ipath_dbg("Never got MDIO cmdready for XGXS status read\n");
  1246. return ret; /* for now, say we always succeeded */
  1247. }
  1248. /**
  1249. * ipath_ht_quiet_serdes - set serdes to txidle
  1250. * @dd: the infinipath device
  1251. * driver is being unloaded
  1252. */
  1253. static void ipath_ht_quiet_serdes(struct ipath_devdata *dd)
  1254. {
  1255. u64 val = ipath_read_kreg64(dd, dd->ipath_kregs->kr_serdesconfig0);
  1256. val |= INFINIPATH_SERDC0_TXIDLE;
  1257. ipath_dbg("Setting TxIdleEn on serdes (config0 = %llx)\n",
  1258. (unsigned long long) val);
  1259. ipath_write_kreg(dd, dd->ipath_kregs->kr_serdesconfig0, val);
  1260. }
  1261. /**
  1262. * ipath_pe_put_tid - write a TID in chip
  1263. * @dd: the infinipath device
  1264. * @tidptr: pointer to the expected TID (in chip) to udpate
  1265. * @tidtype: RCVHQ_RCV_TYPE_EAGER (1) for eager, RCVHQ_RCV_TYPE_EXPECTED (0) for expected
  1266. * @pa: physical address of in memory buffer; ipath_tidinvalid if freeing
  1267. *
  1268. * This exists as a separate routine to allow for special locking etc.
  1269. * It's used for both the full cleanup on exit, as well as the normal
  1270. * setup and teardown.
  1271. */
  1272. static void ipath_ht_put_tid(struct ipath_devdata *dd,
  1273. u64 __iomem *tidptr, u32 type,
  1274. unsigned long pa)
  1275. {
  1276. if (!dd->ipath_kregbase)
  1277. return;
  1278. if (pa != dd->ipath_tidinvalid) {
  1279. if (unlikely((pa & ~INFINIPATH_RT_ADDR_MASK))) {
  1280. dev_info(&dd->pcidev->dev,
  1281. "physaddr %lx has more than "
  1282. "40 bits, using only 40!!!\n", pa);
  1283. pa &= INFINIPATH_RT_ADDR_MASK;
  1284. }
  1285. if (type == RCVHQ_RCV_TYPE_EAGER)
  1286. pa |= dd->ipath_tidtemplate;
  1287. else {
  1288. /* in words (fixed, full page). */
  1289. u64 lenvalid = PAGE_SIZE >> 2;
  1290. lenvalid <<= INFINIPATH_RT_BUFSIZE_SHIFT;
  1291. pa |= lenvalid | INFINIPATH_RT_VALID;
  1292. }
  1293. }
  1294. writeq(pa, tidptr);
  1295. }
  1296. /**
  1297. * ipath_ht_clear_tid - clear all TID entries for a port, expected and eager
  1298. * @dd: the infinipath device
  1299. * @port: the port
  1300. *
  1301. * Used from ipath_close(), and at chip initialization.
  1302. */
  1303. static void ipath_ht_clear_tids(struct ipath_devdata *dd, unsigned port)
  1304. {
  1305. u64 __iomem *tidbase;
  1306. int i;
  1307. if (!dd->ipath_kregbase)
  1308. return;
  1309. ipath_cdbg(VERBOSE, "Invalidate TIDs for port %u\n", port);
  1310. /*
  1311. * need to invalidate all of the expected TID entries for this
  1312. * port, so we don't have valid entries that might somehow get
  1313. * used (early in next use of this port, or through some bug)
  1314. */
  1315. tidbase = (u64 __iomem *) ((char __iomem *)(dd->ipath_kregbase) +
  1316. dd->ipath_rcvtidbase +
  1317. port * dd->ipath_rcvtidcnt *
  1318. sizeof(*tidbase));
  1319. for (i = 0; i < dd->ipath_rcvtidcnt; i++)
  1320. ipath_ht_put_tid(dd, &tidbase[i], RCVHQ_RCV_TYPE_EXPECTED,
  1321. dd->ipath_tidinvalid);
  1322. tidbase = (u64 __iomem *) ((char __iomem *)(dd->ipath_kregbase) +
  1323. dd->ipath_rcvegrbase +
  1324. port * dd->ipath_rcvegrcnt *
  1325. sizeof(*tidbase));
  1326. for (i = 0; i < dd->ipath_rcvegrcnt; i++)
  1327. ipath_ht_put_tid(dd, &tidbase[i], RCVHQ_RCV_TYPE_EAGER,
  1328. dd->ipath_tidinvalid);
  1329. }
  1330. /**
  1331. * ipath_ht_tidtemplate - setup constants for TID updates
  1332. * @dd: the infinipath device
  1333. *
  1334. * We setup stuff that we use a lot, to avoid calculating each time
  1335. */
  1336. static void ipath_ht_tidtemplate(struct ipath_devdata *dd)
  1337. {
  1338. dd->ipath_tidtemplate = dd->ipath_ibmaxlen >> 2;
  1339. dd->ipath_tidtemplate <<= INFINIPATH_RT_BUFSIZE_SHIFT;
  1340. dd->ipath_tidtemplate |= INFINIPATH_RT_VALID;
  1341. /*
  1342. * work around chip errata bug 7358, by marking invalid tids
  1343. * as having max length
  1344. */
  1345. dd->ipath_tidinvalid = (-1LL & INFINIPATH_RT_BUFSIZE_MASK) <<
  1346. INFINIPATH_RT_BUFSIZE_SHIFT;
  1347. }
  1348. static int ipath_ht_early_init(struct ipath_devdata *dd)
  1349. {
  1350. u32 __iomem *piobuf;
  1351. u32 pioincr, val32;
  1352. int i;
  1353. /*
  1354. * one cache line; long IB headers will spill over into received
  1355. * buffer
  1356. */
  1357. dd->ipath_rcvhdrentsize = 16;
  1358. dd->ipath_rcvhdrsize = IPATH_DFLT_RCVHDRSIZE;
  1359. /*
  1360. * For HT, we allocate a somewhat overly large eager buffer,
  1361. * such that we can guarantee that we can receive the largest
  1362. * packet that we can send out. To truly support a 4KB MTU,
  1363. * we need to bump this to a large value. To date, other than
  1364. * testing, we have never encountered an HCA that can really
  1365. * send 4KB MTU packets, so we do not handle that (we'll get
  1366. * errors interrupts if we ever see one).
  1367. */
  1368. dd->ipath_rcvegrbufsize = dd->ipath_piosize2k;
  1369. /*
  1370. * the min() check here is currently a nop, but it may not
  1371. * always be, depending on just how we do ipath_rcvegrbufsize
  1372. */
  1373. dd->ipath_ibmaxlen = min(dd->ipath_piosize2k,
  1374. dd->ipath_rcvegrbufsize);
  1375. dd->ipath_init_ibmaxlen = dd->ipath_ibmaxlen;
  1376. ipath_ht_tidtemplate(dd);
  1377. /*
  1378. * zero all the TID entries at startup. We do this for sanity,
  1379. * in case of a previous driver crash of some kind, and also
  1380. * because the chip powers up with these memories in an unknown
  1381. * state. Use portcnt, not cfgports, since this is for the
  1382. * full chip, not for current (possibly different) configuration
  1383. * value.
  1384. * Chip Errata bug 6447
  1385. */
  1386. for (val32 = 0; val32 < dd->ipath_portcnt; val32++)
  1387. ipath_ht_clear_tids(dd, val32);
  1388. /*
  1389. * write the pbc of each buffer, to be sure it's initialized, then
  1390. * cancel all the buffers, and also abort any packets that might
  1391. * have been in flight for some reason (the latter is for driver
  1392. * unload/reload, but isn't a bad idea at first init). PIO send
  1393. * isn't enabled at this point, so there is no danger of sending
  1394. * these out on the wire.
  1395. * Chip Errata bug 6610
  1396. */
  1397. piobuf = (u32 __iomem *) (((char __iomem *)(dd->ipath_kregbase)) +
  1398. dd->ipath_piobufbase);
  1399. pioincr = dd->ipath_palign / sizeof(*piobuf);
  1400. for (i = 0; i < dd->ipath_piobcnt2k; i++) {
  1401. /*
  1402. * reasonable word count, just to init pbc
  1403. */
  1404. writel(16, piobuf);
  1405. piobuf += pioincr;
  1406. }
  1407. ipath_get_eeprom_info(dd);
  1408. if (dd->ipath_boardrev == 5 && dd->ipath_serial[0] == '1' &&
  1409. dd->ipath_serial[1] == '2' && dd->ipath_serial[2] == '8') {
  1410. /*
  1411. * Later production QHT7040 has same changes as QHT7140, so
  1412. * can use GPIO interrupts. They have serial #'s starting
  1413. * with 128, rather than 112.
  1414. */
  1415. if (dd->ipath_serial[0] == '1' &&
  1416. dd->ipath_serial[1] == '2' &&
  1417. dd->ipath_serial[2] == '8')
  1418. dd->ipath_flags |= IPATH_GPIO_INTR;
  1419. else {
  1420. ipath_dev_err(dd, "Unsupported InfiniPath board "
  1421. "(serial number %.16s)!\n",
  1422. dd->ipath_serial);
  1423. return 1;
  1424. }
  1425. }
  1426. if (dd->ipath_minrev >= 4) {
  1427. /* Rev4+ reports extra errors via internal GPIO pins */
  1428. dd->ipath_flags |= IPATH_GPIO_ERRINTRS;
  1429. dd->ipath_gpio_mask |= IPATH_GPIO_ERRINTR_MASK;
  1430. ipath_write_kreg(dd, dd->ipath_kregs->kr_gpio_mask,
  1431. dd->ipath_gpio_mask);
  1432. }
  1433. return 0;
  1434. }
  1435. static int ipath_ht_txe_recover(struct ipath_devdata *dd)
  1436. {
  1437. int cnt = ++ipath_stats.sps_txeparity;
  1438. if (cnt >= IPATH_MAX_PARITY_ATTEMPTS) {
  1439. if (cnt == IPATH_MAX_PARITY_ATTEMPTS)
  1440. ipath_dev_err(dd,
  1441. "Too many attempts to recover from "
  1442. "TXE parity, giving up\n");
  1443. return 0;
  1444. }
  1445. dev_info(&dd->pcidev->dev,
  1446. "Recovering from TXE PIO parity error\n");
  1447. return 1;
  1448. }
  1449. /**
  1450. * ipath_init_ht_get_base_info - set chip-specific flags for user code
  1451. * @dd: the infinipath device
  1452. * @kbase: ipath_base_info pointer
  1453. *
  1454. * We set the PCIE flag because the lower bandwidth on PCIe vs
  1455. * HyperTransport can affect some user packet algorithms.
  1456. */
  1457. static int ipath_ht_get_base_info(struct ipath_portdata *pd, void *kbase)
  1458. {
  1459. struct ipath_base_info *kinfo = kbase;
  1460. kinfo->spi_runtime_flags |= IPATH_RUNTIME_HT |
  1461. IPATH_RUNTIME_PIO_REGSWAPPED;
  1462. if (pd->port_dd->ipath_minrev < 4)
  1463. kinfo->spi_runtime_flags |= IPATH_RUNTIME_RCVHDR_COPY;
  1464. return 0;
  1465. }
  1466. static void ipath_ht_free_irq(struct ipath_devdata *dd)
  1467. {
  1468. free_irq(dd->ipath_irq, dd);
  1469. ht_destroy_irq(dd->ipath_irq);
  1470. dd->ipath_irq = 0;
  1471. dd->ipath_intconfig = 0;
  1472. }
  1473. /**
  1474. * ipath_init_iba6110_funcs - set up the chip-specific function pointers
  1475. * @dd: the infinipath device
  1476. *
  1477. * This is global, and is called directly at init to set up the
  1478. * chip-specific function pointers for later use.
  1479. */
  1480. void ipath_init_iba6110_funcs(struct ipath_devdata *dd)
  1481. {
  1482. dd->ipath_f_intrsetup = ipath_ht_intconfig;
  1483. dd->ipath_f_bus = ipath_setup_ht_config;
  1484. dd->ipath_f_reset = ipath_setup_ht_reset;
  1485. dd->ipath_f_get_boardname = ipath_ht_boardname;
  1486. dd->ipath_f_init_hwerrors = ipath_ht_init_hwerrors;
  1487. dd->ipath_f_early_init = ipath_ht_early_init;
  1488. dd->ipath_f_handle_hwerrors = ipath_ht_handle_hwerrors;
  1489. dd->ipath_f_quiet_serdes = ipath_ht_quiet_serdes;
  1490. dd->ipath_f_bringup_serdes = ipath_ht_bringup_serdes;
  1491. dd->ipath_f_clear_tids = ipath_ht_clear_tids;
  1492. dd->ipath_f_put_tid = ipath_ht_put_tid;
  1493. dd->ipath_f_cleanup = ipath_setup_ht_cleanup;
  1494. dd->ipath_f_setextled = ipath_setup_ht_setextled;
  1495. dd->ipath_f_get_base_info = ipath_ht_get_base_info;
  1496. dd->ipath_f_free_irq = ipath_ht_free_irq;
  1497. /*
  1498. * initialize chip-specific variables
  1499. */
  1500. dd->ipath_f_tidtemplate = ipath_ht_tidtemplate;
  1501. /*
  1502. * setup the register offsets, since they are different for each
  1503. * chip
  1504. */
  1505. dd->ipath_kregs = &ipath_ht_kregs;
  1506. dd->ipath_cregs = &ipath_ht_cregs;
  1507. /*
  1508. * do very early init that is needed before ipath_f_bus is
  1509. * called
  1510. */
  1511. ipath_init_ht_variables(dd);
  1512. }