ipath_iba6110.c 51 KB

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