ipath_iba6120.c 57 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692
  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
  35. * InfiniPath PCIe chip.
  36. */
  37. #include <linux/interrupt.h>
  38. #include <linux/pci.h>
  39. #include <linux/delay.h>
  40. #include "ipath_kernel.h"
  41. #include "ipath_registers.h"
  42. static void ipath_setup_pe_setextled(struct ipath_devdata *, u64, u64);
  43. /*
  44. * This file contains all the chip-specific register information and
  45. * access functions for the QLogic InfiniPath PCI-Express chip.
  46. *
  47. * This lists the InfiniPath registers, in the actual chip layout.
  48. * This structure should never be directly accessed.
  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 Reserved0;
  57. unsigned long long SendRegBase;
  58. unsigned long long UserRegBase;
  59. unsigned long long CounterRegBase;
  60. unsigned long long Scratch;
  61. unsigned long long Reserved1;
  62. unsigned long long Reserved2;
  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 Reserved3;
  98. unsigned long long RcvPktLEDCnt;
  99. unsigned long long Reserved4[8];
  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 Reserved5;
  108. unsigned long long PCIeRBufTestReg0;
  109. unsigned long long PCIeRBufTestReg1;
  110. unsigned long long Reserved51[6];
  111. unsigned long long SendBufferError;
  112. unsigned long long SendBufferErrorCONT1;
  113. unsigned long long Reserved6SBE[6];
  114. unsigned long long RcvHdrAddr0;
  115. unsigned long long RcvHdrAddr1;
  116. unsigned long long RcvHdrAddr2;
  117. unsigned long long RcvHdrAddr3;
  118. unsigned long long RcvHdrAddr4;
  119. unsigned long long Reserved7RHA[11];
  120. unsigned long long RcvHdrTailAddr0;
  121. unsigned long long RcvHdrTailAddr1;
  122. unsigned long long RcvHdrTailAddr2;
  123. unsigned long long RcvHdrTailAddr3;
  124. unsigned long long RcvHdrTailAddr4;
  125. unsigned long long Reserved8RHTA[11];
  126. unsigned long long Reserved9SW[8];
  127. unsigned long long SerdesConfig0;
  128. unsigned long long SerdesConfig1;
  129. unsigned long long SerdesStatus;
  130. unsigned long long XGXSConfig;
  131. unsigned long long IBPLLCfg;
  132. unsigned long long Reserved10SW2[3];
  133. unsigned long long PCIEQ0SerdesConfig0;
  134. unsigned long long PCIEQ0SerdesConfig1;
  135. unsigned long long PCIEQ0SerdesStatus;
  136. unsigned long long Reserved11;
  137. unsigned long long PCIEQ1SerdesConfig0;
  138. unsigned long long PCIEQ1SerdesConfig1;
  139. unsigned long long PCIEQ1SerdesStatus;
  140. unsigned long long Reserved12;
  141. };
  142. struct _infinipath_do_not_use_counters {
  143. __u64 LBIntCnt;
  144. __u64 LBFlowStallCnt;
  145. __u64 Reserved1;
  146. __u64 TxUnsupVLErrCnt;
  147. __u64 TxDataPktCnt;
  148. __u64 TxFlowPktCnt;
  149. __u64 TxDwordCnt;
  150. __u64 TxLenErrCnt;
  151. __u64 TxMaxMinLenErrCnt;
  152. __u64 TxUnderrunCnt;
  153. __u64 TxFlowStallCnt;
  154. __u64 TxDroppedPktCnt;
  155. __u64 RxDroppedPktCnt;
  156. __u64 RxDataPktCnt;
  157. __u64 RxFlowPktCnt;
  158. __u64 RxDwordCnt;
  159. __u64 RxLenErrCnt;
  160. __u64 RxMaxMinLenErrCnt;
  161. __u64 RxICRCErrCnt;
  162. __u64 RxVCRCErrCnt;
  163. __u64 RxFlowCtrlErrCnt;
  164. __u64 RxBadFormatCnt;
  165. __u64 RxLinkProblemCnt;
  166. __u64 RxEBPCnt;
  167. __u64 RxLPCRCErrCnt;
  168. __u64 RxBufOvflCnt;
  169. __u64 RxTIDFullErrCnt;
  170. __u64 RxTIDValidErrCnt;
  171. __u64 RxPKeyMismatchCnt;
  172. __u64 RxP0HdrEgrOvflCnt;
  173. __u64 RxP1HdrEgrOvflCnt;
  174. __u64 RxP2HdrEgrOvflCnt;
  175. __u64 RxP3HdrEgrOvflCnt;
  176. __u64 RxP4HdrEgrOvflCnt;
  177. __u64 RxP5HdrEgrOvflCnt;
  178. __u64 RxP6HdrEgrOvflCnt;
  179. __u64 RxP7HdrEgrOvflCnt;
  180. __u64 RxP8HdrEgrOvflCnt;
  181. __u64 Reserved6;
  182. __u64 Reserved7;
  183. __u64 IBStatusChangeCnt;
  184. __u64 IBLinkErrRecoveryCnt;
  185. __u64 IBLinkDownedCnt;
  186. __u64 IBSymbolErrCnt;
  187. };
  188. #define IPATH_KREG_OFFSET(field) (offsetof( \
  189. struct _infinipath_do_not_use_kernel_regs, field) / sizeof(u64))
  190. #define IPATH_CREG_OFFSET(field) (offsetof( \
  191. struct _infinipath_do_not_use_counters, field) / sizeof(u64))
  192. static const struct ipath_kregs ipath_pe_kregs = {
  193. .kr_control = IPATH_KREG_OFFSET(Control),
  194. .kr_counterregbase = IPATH_KREG_OFFSET(CounterRegBase),
  195. .kr_debugportselect = IPATH_KREG_OFFSET(DebugPortSelect),
  196. .kr_errorclear = IPATH_KREG_OFFSET(ErrorClear),
  197. .kr_errormask = IPATH_KREG_OFFSET(ErrorMask),
  198. .kr_errorstatus = IPATH_KREG_OFFSET(ErrorStatus),
  199. .kr_extctrl = IPATH_KREG_OFFSET(ExtCtrl),
  200. .kr_extstatus = IPATH_KREG_OFFSET(ExtStatus),
  201. .kr_gpio_clear = IPATH_KREG_OFFSET(GPIOClear),
  202. .kr_gpio_mask = IPATH_KREG_OFFSET(GPIOMask),
  203. .kr_gpio_out = IPATH_KREG_OFFSET(GPIOOut),
  204. .kr_gpio_status = IPATH_KREG_OFFSET(GPIOStatus),
  205. .kr_hwdiagctrl = IPATH_KREG_OFFSET(HwDiagCtrl),
  206. .kr_hwerrclear = IPATH_KREG_OFFSET(HwErrClear),
  207. .kr_hwerrmask = IPATH_KREG_OFFSET(HwErrMask),
  208. .kr_hwerrstatus = IPATH_KREG_OFFSET(HwErrStatus),
  209. .kr_ibcctrl = IPATH_KREG_OFFSET(IBCCtrl),
  210. .kr_ibcstatus = IPATH_KREG_OFFSET(IBCStatus),
  211. .kr_intblocked = IPATH_KREG_OFFSET(IntBlocked),
  212. .kr_intclear = IPATH_KREG_OFFSET(IntClear),
  213. .kr_intmask = IPATH_KREG_OFFSET(IntMask),
  214. .kr_intstatus = IPATH_KREG_OFFSET(IntStatus),
  215. .kr_mdio = IPATH_KREG_OFFSET(MDIO),
  216. .kr_pagealign = IPATH_KREG_OFFSET(PageAlign),
  217. .kr_partitionkey = IPATH_KREG_OFFSET(RcvPartitionKey),
  218. .kr_portcnt = IPATH_KREG_OFFSET(PortCnt),
  219. .kr_rcvbthqp = IPATH_KREG_OFFSET(RcvBTHQP),
  220. .kr_rcvbufbase = IPATH_KREG_OFFSET(RcvBufBase),
  221. .kr_rcvbufsize = IPATH_KREG_OFFSET(RcvBufSize),
  222. .kr_rcvctrl = IPATH_KREG_OFFSET(RcvCtrl),
  223. .kr_rcvegrbase = IPATH_KREG_OFFSET(RcvEgrBase),
  224. .kr_rcvegrcnt = IPATH_KREG_OFFSET(RcvEgrCnt),
  225. .kr_rcvhdrcnt = IPATH_KREG_OFFSET(RcvHdrCnt),
  226. .kr_rcvhdrentsize = IPATH_KREG_OFFSET(RcvHdrEntSize),
  227. .kr_rcvhdrsize = IPATH_KREG_OFFSET(RcvHdrSize),
  228. .kr_rcvintmembase = IPATH_KREG_OFFSET(RxIntMemBase),
  229. .kr_rcvintmemsize = IPATH_KREG_OFFSET(RxIntMemSize),
  230. .kr_rcvtidbase = IPATH_KREG_OFFSET(RcvTIDBase),
  231. .kr_rcvtidcnt = IPATH_KREG_OFFSET(RcvTIDCnt),
  232. .kr_revision = IPATH_KREG_OFFSET(Revision),
  233. .kr_scratch = IPATH_KREG_OFFSET(Scratch),
  234. .kr_sendbuffererror = IPATH_KREG_OFFSET(SendBufferError),
  235. .kr_sendctrl = IPATH_KREG_OFFSET(SendCtrl),
  236. .kr_sendpioavailaddr = IPATH_KREG_OFFSET(SendPIOAvailAddr),
  237. .kr_sendpiobufbase = IPATH_KREG_OFFSET(SendPIOBufBase),
  238. .kr_sendpiobufcnt = IPATH_KREG_OFFSET(SendPIOBufCnt),
  239. .kr_sendpiosize = IPATH_KREG_OFFSET(SendPIOSize),
  240. .kr_sendregbase = IPATH_KREG_OFFSET(SendRegBase),
  241. .kr_txintmembase = IPATH_KREG_OFFSET(TxIntMemBase),
  242. .kr_txintmemsize = IPATH_KREG_OFFSET(TxIntMemSize),
  243. .kr_userregbase = IPATH_KREG_OFFSET(UserRegBase),
  244. .kr_serdesconfig0 = IPATH_KREG_OFFSET(SerdesConfig0),
  245. .kr_serdesconfig1 = IPATH_KREG_OFFSET(SerdesConfig1),
  246. .kr_serdesstatus = IPATH_KREG_OFFSET(SerdesStatus),
  247. .kr_xgxsconfig = IPATH_KREG_OFFSET(XGXSConfig),
  248. .kr_ibpllcfg = IPATH_KREG_OFFSET(IBPLLCfg),
  249. /*
  250. * These should not be used directly via ipath_write_kreg64(),
  251. * use them with ipath_write_kreg64_port(),
  252. */
  253. .kr_rcvhdraddr = IPATH_KREG_OFFSET(RcvHdrAddr0),
  254. .kr_rcvhdrtailaddr = IPATH_KREG_OFFSET(RcvHdrTailAddr0),
  255. /* The rcvpktled register controls one of the debug port signals, so
  256. * a packet activity LED can be connected to it. */
  257. .kr_rcvpktledcnt = IPATH_KREG_OFFSET(RcvPktLEDCnt),
  258. .kr_pcierbuftestreg0 = IPATH_KREG_OFFSET(PCIeRBufTestReg0),
  259. .kr_pcierbuftestreg1 = IPATH_KREG_OFFSET(PCIeRBufTestReg1),
  260. .kr_pcieq0serdesconfig0 = IPATH_KREG_OFFSET(PCIEQ0SerdesConfig0),
  261. .kr_pcieq0serdesconfig1 = IPATH_KREG_OFFSET(PCIEQ0SerdesConfig1),
  262. .kr_pcieq0serdesstatus = IPATH_KREG_OFFSET(PCIEQ0SerdesStatus),
  263. .kr_pcieq1serdesconfig0 = IPATH_KREG_OFFSET(PCIEQ1SerdesConfig0),
  264. .kr_pcieq1serdesconfig1 = IPATH_KREG_OFFSET(PCIEQ1SerdesConfig1),
  265. .kr_pcieq1serdesstatus = IPATH_KREG_OFFSET(PCIEQ1SerdesStatus)
  266. };
  267. static const struct ipath_cregs ipath_pe_cregs = {
  268. .cr_badformatcnt = IPATH_CREG_OFFSET(RxBadFormatCnt),
  269. .cr_erricrccnt = IPATH_CREG_OFFSET(RxICRCErrCnt),
  270. .cr_errlinkcnt = IPATH_CREG_OFFSET(RxLinkProblemCnt),
  271. .cr_errlpcrccnt = IPATH_CREG_OFFSET(RxLPCRCErrCnt),
  272. .cr_errpkey = IPATH_CREG_OFFSET(RxPKeyMismatchCnt),
  273. .cr_errrcvflowctrlcnt = IPATH_CREG_OFFSET(RxFlowCtrlErrCnt),
  274. .cr_err_rlencnt = IPATH_CREG_OFFSET(RxLenErrCnt),
  275. .cr_errslencnt = IPATH_CREG_OFFSET(TxLenErrCnt),
  276. .cr_errtidfull = IPATH_CREG_OFFSET(RxTIDFullErrCnt),
  277. .cr_errtidvalid = IPATH_CREG_OFFSET(RxTIDValidErrCnt),
  278. .cr_errvcrccnt = IPATH_CREG_OFFSET(RxVCRCErrCnt),
  279. .cr_ibstatuschange = IPATH_CREG_OFFSET(IBStatusChangeCnt),
  280. .cr_intcnt = IPATH_CREG_OFFSET(LBIntCnt),
  281. .cr_invalidrlencnt = IPATH_CREG_OFFSET(RxMaxMinLenErrCnt),
  282. .cr_invalidslencnt = IPATH_CREG_OFFSET(TxMaxMinLenErrCnt),
  283. .cr_lbflowstallcnt = IPATH_CREG_OFFSET(LBFlowStallCnt),
  284. .cr_pktrcvcnt = IPATH_CREG_OFFSET(RxDataPktCnt),
  285. .cr_pktrcvflowctrlcnt = IPATH_CREG_OFFSET(RxFlowPktCnt),
  286. .cr_pktsendcnt = IPATH_CREG_OFFSET(TxDataPktCnt),
  287. .cr_pktsendflowcnt = IPATH_CREG_OFFSET(TxFlowPktCnt),
  288. .cr_portovflcnt = IPATH_CREG_OFFSET(RxP0HdrEgrOvflCnt),
  289. .cr_rcvebpcnt = IPATH_CREG_OFFSET(RxEBPCnt),
  290. .cr_rcvovflcnt = IPATH_CREG_OFFSET(RxBufOvflCnt),
  291. .cr_senddropped = IPATH_CREG_OFFSET(TxDroppedPktCnt),
  292. .cr_sendstallcnt = IPATH_CREG_OFFSET(TxFlowStallCnt),
  293. .cr_sendunderruncnt = IPATH_CREG_OFFSET(TxUnderrunCnt),
  294. .cr_wordrcvcnt = IPATH_CREG_OFFSET(RxDwordCnt),
  295. .cr_wordsendcnt = IPATH_CREG_OFFSET(TxDwordCnt),
  296. .cr_unsupvlcnt = IPATH_CREG_OFFSET(TxUnsupVLErrCnt),
  297. .cr_rxdroppktcnt = IPATH_CREG_OFFSET(RxDroppedPktCnt),
  298. .cr_iblinkerrrecovcnt = IPATH_CREG_OFFSET(IBLinkErrRecoveryCnt),
  299. .cr_iblinkdowncnt = IPATH_CREG_OFFSET(IBLinkDownedCnt),
  300. .cr_ibsymbolerrcnt = IPATH_CREG_OFFSET(IBSymbolErrCnt)
  301. };
  302. /* kr_intstatus, kr_intclear, kr_intmask bits */
  303. #define INFINIPATH_I_RCVURG_MASK ((1U<<5)-1)
  304. #define INFINIPATH_I_RCVAVAIL_MASK ((1U<<5)-1)
  305. /* kr_hwerrclear, kr_hwerrmask, kr_hwerrstatus, bits */
  306. #define INFINIPATH_HWE_PCIEMEMPARITYERR_MASK 0x000000000000003fULL
  307. #define INFINIPATH_HWE_PCIEMEMPARITYERR_SHIFT 0
  308. #define INFINIPATH_HWE_PCIEPOISONEDTLP 0x0000000010000000ULL
  309. #define INFINIPATH_HWE_PCIECPLTIMEOUT 0x0000000020000000ULL
  310. #define INFINIPATH_HWE_PCIEBUSPARITYXTLH 0x0000000040000000ULL
  311. #define INFINIPATH_HWE_PCIEBUSPARITYXADM 0x0000000080000000ULL
  312. #define INFINIPATH_HWE_PCIEBUSPARITYRADM 0x0000000100000000ULL
  313. #define INFINIPATH_HWE_COREPLL_FBSLIP 0x0080000000000000ULL
  314. #define INFINIPATH_HWE_COREPLL_RFSLIP 0x0100000000000000ULL
  315. #define INFINIPATH_HWE_PCIE1PLLFAILED 0x0400000000000000ULL
  316. #define INFINIPATH_HWE_PCIE0PLLFAILED 0x0800000000000000ULL
  317. #define INFINIPATH_HWE_SERDESPLLFAILED 0x1000000000000000ULL
  318. #define IBA6120_IBCS_LINKTRAININGSTATE_MASK 0xf
  319. #define IBA6120_IBCS_LINKSTATE_SHIFT 4
  320. /* kr_extstatus bits */
  321. #define INFINIPATH_EXTS_FREQSEL 0x2
  322. #define INFINIPATH_EXTS_SERDESSEL 0x4
  323. #define INFINIPATH_EXTS_MEMBIST_ENDTEST 0x0000000000004000
  324. #define INFINIPATH_EXTS_MEMBIST_FOUND 0x0000000000008000
  325. #define _IPATH_GPIO_SDA_NUM 1
  326. #define _IPATH_GPIO_SCL_NUM 0
  327. #define IPATH_GPIO_SDA (1ULL << \
  328. (_IPATH_GPIO_SDA_NUM+INFINIPATH_EXTC_GPIOOE_SHIFT))
  329. #define IPATH_GPIO_SCL (1ULL << \
  330. (_IPATH_GPIO_SCL_NUM+INFINIPATH_EXTC_GPIOOE_SHIFT))
  331. #define INFINIPATH_R_INTRAVAIL_SHIFT 16
  332. #define INFINIPATH_R_TAILUPD_SHIFT 31
  333. /* 6120 specific hardware errors... */
  334. static const struct ipath_hwerror_msgs ipath_6120_hwerror_msgs[] = {
  335. INFINIPATH_HWE_MSG(PCIEPOISONEDTLP, "PCIe Poisoned TLP"),
  336. INFINIPATH_HWE_MSG(PCIECPLTIMEOUT, "PCIe completion timeout"),
  337. /*
  338. * In practice, it's unlikely wthat we'll see PCIe PLL, or bus
  339. * parity or memory parity error failures, because most likely we
  340. * won't be able to talk to the core of the chip. Nonetheless, we
  341. * might see them, if they are in parts of the PCIe core that aren't
  342. * essential.
  343. */
  344. INFINIPATH_HWE_MSG(PCIE1PLLFAILED, "PCIePLL1"),
  345. INFINIPATH_HWE_MSG(PCIE0PLLFAILED, "PCIePLL0"),
  346. INFINIPATH_HWE_MSG(PCIEBUSPARITYXTLH, "PCIe XTLH core parity"),
  347. INFINIPATH_HWE_MSG(PCIEBUSPARITYXADM, "PCIe ADM TX core parity"),
  348. INFINIPATH_HWE_MSG(PCIEBUSPARITYRADM, "PCIe ADM RX core parity"),
  349. INFINIPATH_HWE_MSG(RXDSYNCMEMPARITYERR, "Rx Dsync"),
  350. INFINIPATH_HWE_MSG(SERDESPLLFAILED, "SerDes PLL"),
  351. };
  352. #define TXE_PIO_PARITY ((INFINIPATH_HWE_TXEMEMPARITYERR_PIOBUF | \
  353. INFINIPATH_HWE_TXEMEMPARITYERR_PIOPBC) \
  354. << INFINIPATH_HWE_TXEMEMPARITYERR_SHIFT)
  355. static void ipath_pe_put_tid_2(struct ipath_devdata *, u64 __iomem *,
  356. u32, unsigned long);
  357. /*
  358. * On platforms using this chip, and not having ordered WC stores, we
  359. * can get TXE parity errors due to speculative reads to the PIO buffers,
  360. * and this, due to a chip bug can result in (many) false parity error
  361. * reports. So it's a debug print on those, and an info print on systems
  362. * where the speculative reads don't occur.
  363. */
  364. static void ipath_pe_txe_recover(struct ipath_devdata *dd)
  365. {
  366. if (ipath_unordered_wc())
  367. ipath_dbg("Recovering from TXE PIO parity error\n");
  368. else {
  369. ++ipath_stats.sps_txeparity;
  370. dev_info(&dd->pcidev->dev,
  371. "Recovering from TXE PIO parity error\n");
  372. }
  373. }
  374. /**
  375. * ipath_pe_handle_hwerrors - display hardware errors.
  376. * @dd: the infinipath device
  377. * @msg: the output buffer
  378. * @msgl: the size of the output buffer
  379. *
  380. * Use same msg buffer as regular errors to avoid excessive stack
  381. * use. Most hardware errors are catastrophic, but for right now,
  382. * we'll print them and continue. We reuse the same message buffer as
  383. * ipath_handle_errors() to avoid excessive stack usage.
  384. */
  385. static void ipath_pe_handle_hwerrors(struct ipath_devdata *dd, char *msg,
  386. size_t msgl)
  387. {
  388. ipath_err_t hwerrs;
  389. u32 bits, ctrl;
  390. int isfatal = 0;
  391. char bitsmsg[64];
  392. int log_idx;
  393. hwerrs = ipath_read_kreg64(dd, dd->ipath_kregs->kr_hwerrstatus);
  394. if (!hwerrs) {
  395. /*
  396. * better than printing cofusing messages
  397. * This seems to be related to clearing the crc error, or
  398. * the pll error during init.
  399. */
  400. ipath_cdbg(VERBOSE, "Called but no hardware errors set\n");
  401. return;
  402. } else if (hwerrs == ~0ULL) {
  403. ipath_dev_err(dd, "Read of hardware error status failed "
  404. "(all bits set); ignoring\n");
  405. return;
  406. }
  407. ipath_stats.sps_hwerrs++;
  408. /* Always clear the error status register, except MEMBISTFAIL,
  409. * regardless of whether we continue or stop using the chip.
  410. * We want that set so we know it failed, even across driver reload.
  411. * We'll still ignore it in the hwerrmask. We do this partly for
  412. * diagnostics, but also for support */
  413. ipath_write_kreg(dd, dd->ipath_kregs->kr_hwerrclear,
  414. hwerrs&~INFINIPATH_HWE_MEMBISTFAILED);
  415. hwerrs &= dd->ipath_hwerrmask;
  416. /* We log some errors to EEPROM, check if we have any of those. */
  417. for (log_idx = 0; log_idx < IPATH_EEP_LOG_CNT; ++log_idx)
  418. if (hwerrs & dd->ipath_eep_st_masks[log_idx].hwerrs_to_log)
  419. ipath_inc_eeprom_err(dd, log_idx, 1);
  420. /*
  421. * make sure we get this much out, unless told to be quiet,
  422. * or it's occurred within the last 5 seconds
  423. */
  424. if ((hwerrs & ~(dd->ipath_lasthwerror |
  425. ((INFINIPATH_HWE_TXEMEMPARITYERR_PIOBUF |
  426. INFINIPATH_HWE_TXEMEMPARITYERR_PIOPBC)
  427. << INFINIPATH_HWE_TXEMEMPARITYERR_SHIFT))) ||
  428. (ipath_debug & __IPATH_VERBDBG))
  429. dev_info(&dd->pcidev->dev, "Hardware error: hwerr=0x%llx "
  430. "(cleared)\n", (unsigned long long) hwerrs);
  431. dd->ipath_lasthwerror |= hwerrs;
  432. if (hwerrs & ~dd->ipath_hwe_bitsextant)
  433. ipath_dev_err(dd, "hwerror interrupt with unknown errors "
  434. "%llx set\n", (unsigned long long)
  435. (hwerrs & ~dd->ipath_hwe_bitsextant));
  436. ctrl = ipath_read_kreg32(dd, dd->ipath_kregs->kr_control);
  437. if (ctrl & INFINIPATH_C_FREEZEMODE) {
  438. /*
  439. * parity errors in send memory are recoverable,
  440. * just cancel the send (if indicated in * sendbuffererror),
  441. * count the occurrence, unfreeze (if no other handled
  442. * hardware error bits are set), and continue. They can
  443. * occur if a processor speculative read is done to the PIO
  444. * buffer while we are sending a packet, for example.
  445. */
  446. if (hwerrs & TXE_PIO_PARITY) {
  447. ipath_pe_txe_recover(dd);
  448. hwerrs &= ~TXE_PIO_PARITY;
  449. }
  450. if (!hwerrs) {
  451. static u32 freeze_cnt;
  452. freeze_cnt++;
  453. ipath_dbg("Clearing freezemode on ignored or recovered "
  454. "hardware error (%u)\n", freeze_cnt);
  455. ipath_clear_freeze(dd);
  456. }
  457. }
  458. *msg = '\0';
  459. if (hwerrs & INFINIPATH_HWE_MEMBISTFAILED) {
  460. strlcat(msg, "[Memory BIST test failed, InfiniPath hardware unusable]",
  461. msgl);
  462. /* ignore from now on, so disable until driver reloaded */
  463. *dd->ipath_statusp |= IPATH_STATUS_HWERROR;
  464. dd->ipath_hwerrmask &= ~INFINIPATH_HWE_MEMBISTFAILED;
  465. ipath_write_kreg(dd, dd->ipath_kregs->kr_hwerrmask,
  466. dd->ipath_hwerrmask);
  467. }
  468. ipath_format_hwerrors(hwerrs,
  469. ipath_6120_hwerror_msgs,
  470. sizeof(ipath_6120_hwerror_msgs)/
  471. sizeof(ipath_6120_hwerror_msgs[0]),
  472. msg, msgl);
  473. if (hwerrs & (INFINIPATH_HWE_PCIEMEMPARITYERR_MASK
  474. << INFINIPATH_HWE_PCIEMEMPARITYERR_SHIFT)) {
  475. bits = (u32) ((hwerrs >>
  476. INFINIPATH_HWE_PCIEMEMPARITYERR_SHIFT) &
  477. INFINIPATH_HWE_PCIEMEMPARITYERR_MASK);
  478. snprintf(bitsmsg, sizeof bitsmsg,
  479. "[PCIe Mem Parity Errs %x] ", bits);
  480. strlcat(msg, bitsmsg, msgl);
  481. }
  482. #define _IPATH_PLL_FAIL (INFINIPATH_HWE_COREPLL_FBSLIP | \
  483. INFINIPATH_HWE_COREPLL_RFSLIP )
  484. if (hwerrs & _IPATH_PLL_FAIL) {
  485. snprintf(bitsmsg, sizeof bitsmsg,
  486. "[PLL failed (%llx), InfiniPath hardware unusable]",
  487. (unsigned long long) hwerrs & _IPATH_PLL_FAIL);
  488. strlcat(msg, bitsmsg, msgl);
  489. /* ignore from now on, so disable until driver reloaded */
  490. dd->ipath_hwerrmask &= ~(hwerrs & _IPATH_PLL_FAIL);
  491. ipath_write_kreg(dd, dd->ipath_kregs->kr_hwerrmask,
  492. dd->ipath_hwerrmask);
  493. }
  494. if (hwerrs & INFINIPATH_HWE_SERDESPLLFAILED) {
  495. /*
  496. * If it occurs, it is left masked since the external
  497. * interface is unused
  498. */
  499. dd->ipath_hwerrmask &= ~INFINIPATH_HWE_SERDESPLLFAILED;
  500. ipath_write_kreg(dd, dd->ipath_kregs->kr_hwerrmask,
  501. dd->ipath_hwerrmask);
  502. }
  503. if (*msg)
  504. ipath_dev_err(dd, "%s hardware error\n", msg);
  505. if (isfatal && !ipath_diag_inuse && dd->ipath_freezemsg) {
  506. /*
  507. * for /sys status file ; if no trailing } is copied, we'll
  508. * know it was truncated.
  509. */
  510. snprintf(dd->ipath_freezemsg, dd->ipath_freezelen,
  511. "{%s}", msg);
  512. }
  513. }
  514. /**
  515. * ipath_pe_boardname - fill in the board name
  516. * @dd: the infinipath device
  517. * @name: the output buffer
  518. * @namelen: the size of the output buffer
  519. *
  520. * info is based on the board revision register
  521. */
  522. static int ipath_pe_boardname(struct ipath_devdata *dd, char *name,
  523. size_t namelen)
  524. {
  525. char *n = NULL;
  526. u8 boardrev = dd->ipath_boardrev;
  527. int ret;
  528. switch (boardrev) {
  529. case 0:
  530. n = "InfiniPath_Emulation";
  531. break;
  532. case 1:
  533. n = "InfiniPath_QLE7140-Bringup";
  534. break;
  535. case 2:
  536. n = "InfiniPath_QLE7140";
  537. break;
  538. case 3:
  539. n = "InfiniPath_QMI7140";
  540. break;
  541. case 4:
  542. n = "InfiniPath_QEM7140";
  543. break;
  544. case 5:
  545. n = "InfiniPath_QMH7140";
  546. break;
  547. case 6:
  548. n = "InfiniPath_QLE7142";
  549. break;
  550. default:
  551. ipath_dev_err(dd,
  552. "Don't yet know about board with ID %u\n",
  553. boardrev);
  554. snprintf(name, namelen, "Unknown_InfiniPath_PCIe_%u",
  555. boardrev);
  556. break;
  557. }
  558. if (n)
  559. snprintf(name, namelen, "%s", n);
  560. if (dd->ipath_majrev != 4 || !dd->ipath_minrev || dd->ipath_minrev>2) {
  561. ipath_dev_err(dd, "Unsupported InfiniPath hardware revision %u.%u!\n",
  562. dd->ipath_majrev, dd->ipath_minrev);
  563. ret = 1;
  564. } else {
  565. ret = 0;
  566. if (dd->ipath_minrev >= 2)
  567. dd->ipath_f_put_tid = ipath_pe_put_tid_2;
  568. }
  569. /*
  570. * set here, not in ipath_init_*_funcs because we have to do
  571. * it after we can read chip registers.
  572. */
  573. dd->ipath_ureg_align =
  574. ipath_read_kreg32(dd, dd->ipath_kregs->kr_pagealign);
  575. return ret;
  576. }
  577. /**
  578. * ipath_pe_init_hwerrors - enable hardware errors
  579. * @dd: the infinipath device
  580. *
  581. * now that we have finished initializing everything that might reasonably
  582. * cause a hardware error, and cleared those errors bits as they occur,
  583. * we can enable hardware errors in the mask (potentially enabling
  584. * freeze mode), and enable hardware errors as errors (along with
  585. * everything else) in errormask
  586. */
  587. static void ipath_pe_init_hwerrors(struct ipath_devdata *dd)
  588. {
  589. ipath_err_t val;
  590. u64 extsval;
  591. extsval = ipath_read_kreg64(dd, dd->ipath_kregs->kr_extstatus);
  592. if (!(extsval & INFINIPATH_EXTS_MEMBIST_ENDTEST))
  593. ipath_dev_err(dd, "MemBIST did not complete!\n");
  594. if (extsval & INFINIPATH_EXTS_MEMBIST_FOUND)
  595. ipath_dbg("MemBIST corrected\n");
  596. val = ~0ULL; /* barring bugs, all hwerrors become interrupts, */
  597. if (!dd->ipath_boardrev) // no PLL for Emulator
  598. val &= ~INFINIPATH_HWE_SERDESPLLFAILED;
  599. if (dd->ipath_minrev < 2) {
  600. /* workaround bug 9460 in internal interface bus parity
  601. * checking. Fixed (HW bug 9490) in Rev2.
  602. */
  603. val &= ~INFINIPATH_HWE_PCIEBUSPARITYRADM;
  604. }
  605. dd->ipath_hwerrmask = val;
  606. }
  607. /**
  608. * ipath_pe_bringup_serdes - bring up the serdes
  609. * @dd: the infinipath device
  610. */
  611. static int ipath_pe_bringup_serdes(struct ipath_devdata *dd)
  612. {
  613. u64 val, config1, prev_val;
  614. int ret = 0;
  615. ipath_dbg("Trying to bringup serdes\n");
  616. if (ipath_read_kreg64(dd, dd->ipath_kregs->kr_hwerrstatus) &
  617. INFINIPATH_HWE_SERDESPLLFAILED) {
  618. ipath_dbg("At start, serdes PLL failed bit set "
  619. "in hwerrstatus, clearing and continuing\n");
  620. ipath_write_kreg(dd, dd->ipath_kregs->kr_hwerrclear,
  621. INFINIPATH_HWE_SERDESPLLFAILED);
  622. }
  623. val = ipath_read_kreg64(dd, dd->ipath_kregs->kr_serdesconfig0);
  624. config1 = ipath_read_kreg64(dd, dd->ipath_kregs->kr_serdesconfig1);
  625. ipath_cdbg(VERBOSE, "SerDes status config0=%llx config1=%llx, "
  626. "xgxsconfig %llx\n", (unsigned long long) val,
  627. (unsigned long long) config1, (unsigned long long)
  628. ipath_read_kreg64(dd, dd->ipath_kregs->kr_xgxsconfig));
  629. /*
  630. * Force reset on, also set rxdetect enable. Must do before reading
  631. * serdesstatus at least for simulation, or some of the bits in
  632. * serdes status will come back as undefined and cause simulation
  633. * failures
  634. */
  635. val |= INFINIPATH_SERDC0_RESET_PLL | INFINIPATH_SERDC0_RXDETECT_EN
  636. | INFINIPATH_SERDC0_L1PWR_DN;
  637. ipath_write_kreg(dd, dd->ipath_kregs->kr_serdesconfig0, val);
  638. /* be sure chip saw it */
  639. ipath_read_kreg64(dd, dd->ipath_kregs->kr_scratch);
  640. udelay(5); /* need pll reset set at least for a bit */
  641. /*
  642. * after PLL is reset, set the per-lane Resets and TxIdle and
  643. * clear the PLL reset and rxdetect (to get falling edge).
  644. * Leave L1PWR bits set (permanently)
  645. */
  646. val &= ~(INFINIPATH_SERDC0_RXDETECT_EN | INFINIPATH_SERDC0_RESET_PLL
  647. | INFINIPATH_SERDC0_L1PWR_DN);
  648. val |= INFINIPATH_SERDC0_RESET_MASK | INFINIPATH_SERDC0_TXIDLE;
  649. ipath_cdbg(VERBOSE, "Clearing pll reset and setting lane resets "
  650. "and txidle (%llx)\n", (unsigned long long) val);
  651. ipath_write_kreg(dd, dd->ipath_kregs->kr_serdesconfig0, val);
  652. /* be sure chip saw it */
  653. ipath_read_kreg64(dd, dd->ipath_kregs->kr_scratch);
  654. /* need PLL reset clear for at least 11 usec before lane
  655. * resets cleared; give it a few more to be sure */
  656. udelay(15);
  657. val &= ~(INFINIPATH_SERDC0_RESET_MASK | INFINIPATH_SERDC0_TXIDLE);
  658. ipath_cdbg(VERBOSE, "Clearing lane resets and txidle "
  659. "(writing %llx)\n", (unsigned long long) val);
  660. ipath_write_kreg(dd, dd->ipath_kregs->kr_serdesconfig0, val);
  661. /* be sure chip saw it */
  662. val = ipath_read_kreg64(dd, dd->ipath_kregs->kr_scratch);
  663. val = ipath_read_kreg64(dd, dd->ipath_kregs->kr_xgxsconfig);
  664. prev_val = val;
  665. if (val & INFINIPATH_XGXS_RESET)
  666. val &= ~INFINIPATH_XGXS_RESET;
  667. if (((val >> INFINIPATH_XGXS_RX_POL_SHIFT) &
  668. INFINIPATH_XGXS_RX_POL_MASK) != dd->ipath_rx_pol_inv ) {
  669. /* need to compensate for Tx inversion in partner */
  670. val &= ~(INFINIPATH_XGXS_RX_POL_MASK <<
  671. INFINIPATH_XGXS_RX_POL_SHIFT);
  672. val |= dd->ipath_rx_pol_inv <<
  673. INFINIPATH_XGXS_RX_POL_SHIFT;
  674. }
  675. if (val != prev_val)
  676. ipath_write_kreg(dd, dd->ipath_kregs->kr_xgxsconfig, val);
  677. val = ipath_read_kreg64(dd, dd->ipath_kregs->kr_serdesconfig0);
  678. /* clear current and de-emphasis bits */
  679. config1 &= ~0x0ffffffff00ULL;
  680. /* set current to 20ma */
  681. config1 |= 0x00000000000ULL;
  682. /* set de-emphasis to -5.68dB */
  683. config1 |= 0x0cccc000000ULL;
  684. ipath_write_kreg(dd, dd->ipath_kregs->kr_serdesconfig1, config1);
  685. ipath_cdbg(VERBOSE, "done: SerDes status config0=%llx "
  686. "config1=%llx, sstatus=%llx xgxs=%llx\n",
  687. (unsigned long long) val, (unsigned long long) config1,
  688. (unsigned long long)
  689. ipath_read_kreg64(dd, dd->ipath_kregs->kr_serdesstatus),
  690. (unsigned long long)
  691. ipath_read_kreg64(dd, dd->ipath_kregs->kr_xgxsconfig));
  692. return ret;
  693. }
  694. /**
  695. * ipath_pe_quiet_serdes - set serdes to txidle
  696. * @dd: the infinipath device
  697. * Called when driver is being unloaded
  698. */
  699. static void ipath_pe_quiet_serdes(struct ipath_devdata *dd)
  700. {
  701. u64 val = ipath_read_kreg64(dd, dd->ipath_kregs->kr_serdesconfig0);
  702. val |= INFINIPATH_SERDC0_TXIDLE;
  703. ipath_dbg("Setting TxIdleEn on serdes (config0 = %llx)\n",
  704. (unsigned long long) val);
  705. ipath_write_kreg(dd, dd->ipath_kregs->kr_serdesconfig0, val);
  706. }
  707. static int ipath_pe_intconfig(struct ipath_devdata *dd)
  708. {
  709. u32 chiprev;
  710. /*
  711. * If the chip supports added error indication via GPIO pins,
  712. * enable interrupts on those bits so the interrupt routine
  713. * can count the events. Also set flag so interrupt routine
  714. * can know they are expected.
  715. */
  716. chiprev = dd->ipath_revision >> INFINIPATH_R_CHIPREVMINOR_SHIFT;
  717. if ((chiprev & INFINIPATH_R_CHIPREVMINOR_MASK) > 1) {
  718. /* Rev2+ reports extra errors via internal GPIO pins */
  719. dd->ipath_flags |= IPATH_GPIO_ERRINTRS;
  720. dd->ipath_gpio_mask |= IPATH_GPIO_ERRINTR_MASK;
  721. ipath_write_kreg(dd, dd->ipath_kregs->kr_gpio_mask,
  722. dd->ipath_gpio_mask);
  723. }
  724. return 0;
  725. }
  726. /**
  727. * ipath_setup_pe_setextled - set the state of the two external LEDs
  728. * @dd: the infinipath device
  729. * @lst: the L state
  730. * @ltst: the LT state
  731. * These LEDs indicate the physical and logical state of IB link.
  732. * For this chip (at least with recommended board pinouts), LED1
  733. * is Yellow (logical state) and LED2 is Green (physical state),
  734. *
  735. * Note: We try to match the Mellanox HCA LED behavior as best
  736. * we can. Green indicates physical link state is OK (something is
  737. * plugged in, and we can train).
  738. * Amber indicates the link is logically up (ACTIVE).
  739. * Mellanox further blinks the amber LED to indicate data packet
  740. * activity, but we have no hardware support for that, so it would
  741. * require waking up every 10-20 msecs and checking the counters
  742. * on the chip, and then turning the LED off if appropriate. That's
  743. * visible overhead, so not something we will do.
  744. *
  745. */
  746. static void ipath_setup_pe_setextled(struct ipath_devdata *dd, u64 lst,
  747. u64 ltst)
  748. {
  749. u64 extctl;
  750. unsigned long flags = 0;
  751. /* the diags use the LED to indicate diag info, so we leave
  752. * the external LED alone when the diags are running */
  753. if (ipath_diag_inuse)
  754. return;
  755. /* Allow override of LED display for, e.g. Locating system in rack */
  756. if (dd->ipath_led_override) {
  757. ltst = (dd->ipath_led_override & IPATH_LED_PHYS)
  758. ? INFINIPATH_IBCS_LT_STATE_LINKUP
  759. : INFINIPATH_IBCS_LT_STATE_DISABLED;
  760. lst = (dd->ipath_led_override & IPATH_LED_LOG)
  761. ? INFINIPATH_IBCS_L_STATE_ACTIVE
  762. : INFINIPATH_IBCS_L_STATE_DOWN;
  763. }
  764. spin_lock_irqsave(&dd->ipath_gpio_lock, flags);
  765. extctl = dd->ipath_extctrl & ~(INFINIPATH_EXTC_LED1PRIPORT_ON |
  766. INFINIPATH_EXTC_LED2PRIPORT_ON);
  767. if (ltst & INFINIPATH_IBCS_LT_STATE_LINKUP)
  768. extctl |= INFINIPATH_EXTC_LED2PRIPORT_ON;
  769. if (lst == INFINIPATH_IBCS_L_STATE_ACTIVE)
  770. extctl |= INFINIPATH_EXTC_LED1PRIPORT_ON;
  771. dd->ipath_extctrl = extctl;
  772. ipath_write_kreg(dd, dd->ipath_kregs->kr_extctrl, extctl);
  773. spin_unlock_irqrestore(&dd->ipath_gpio_lock, flags);
  774. }
  775. /**
  776. * ipath_setup_pe_cleanup - clean up any per-chip chip-specific stuff
  777. * @dd: the infinipath device
  778. *
  779. * This is called during driver unload.
  780. * We do the pci_disable_msi here, not in generic code, because it
  781. * isn't used for the HT chips. If we do end up needing pci_enable_msi
  782. * at some point in the future for HT, we'll move the call back
  783. * into the main init_one code.
  784. */
  785. static void ipath_setup_pe_cleanup(struct ipath_devdata *dd)
  786. {
  787. dd->ipath_msi_lo = 0; /* just in case unload fails */
  788. pci_disable_msi(dd->pcidev);
  789. }
  790. /**
  791. * ipath_setup_pe_config - setup PCIe config related stuff
  792. * @dd: the infinipath device
  793. * @pdev: the PCI device
  794. *
  795. * The pci_enable_msi() call will fail on systems with MSI quirks
  796. * such as those with AMD8131, even if the device of interest is not
  797. * attached to that device, (in the 2.6.13 - 2.6.15 kernels, at least, fixed
  798. * late in 2.6.16).
  799. * All that can be done is to edit the kernel source to remove the quirk
  800. * check until that is fixed.
  801. * We do not need to call enable_msi() for our HyperTransport chip,
  802. * even though it uses MSI, and we want to avoid the quirk warning, so
  803. * So we call enable_msi only for PCIe. If we do end up needing
  804. * pci_enable_msi at some point in the future for HT, we'll move the
  805. * call back into the main init_one code.
  806. * We save the msi lo and hi values, so we can restore them after
  807. * chip reset (the kernel PCI infrastructure doesn't yet handle that
  808. * correctly).
  809. */
  810. static int ipath_setup_pe_config(struct ipath_devdata *dd,
  811. struct pci_dev *pdev)
  812. {
  813. int pos, ret;
  814. dd->ipath_msi_lo = 0; /* used as a flag during reset processing */
  815. ret = pci_enable_msi(dd->pcidev);
  816. if (ret)
  817. ipath_dev_err(dd, "pci_enable_msi failed: %d, "
  818. "interrupts may not work\n", ret);
  819. /* continue even if it fails, we may still be OK... */
  820. dd->ipath_irq = pdev->irq;
  821. if ((pos = pci_find_capability(dd->pcidev, PCI_CAP_ID_MSI))) {
  822. u16 control;
  823. pci_read_config_dword(dd->pcidev, pos + PCI_MSI_ADDRESS_LO,
  824. &dd->ipath_msi_lo);
  825. pci_read_config_dword(dd->pcidev, pos + PCI_MSI_ADDRESS_HI,
  826. &dd->ipath_msi_hi);
  827. pci_read_config_word(dd->pcidev, pos + PCI_MSI_FLAGS,
  828. &control);
  829. /* now save the data (vector) info */
  830. pci_read_config_word(dd->pcidev,
  831. pos + ((control & PCI_MSI_FLAGS_64BIT)
  832. ? 12 : 8),
  833. &dd->ipath_msi_data);
  834. ipath_cdbg(VERBOSE, "Read msi data 0x%x from config offset "
  835. "0x%x, control=0x%x\n", dd->ipath_msi_data,
  836. pos + ((control & PCI_MSI_FLAGS_64BIT) ? 12 : 8),
  837. control);
  838. /* we save the cachelinesize also, although it doesn't
  839. * really matter */
  840. pci_read_config_byte(dd->pcidev, PCI_CACHE_LINE_SIZE,
  841. &dd->ipath_pci_cacheline);
  842. } else
  843. ipath_dev_err(dd, "Can't find MSI capability, "
  844. "can't save MSI settings for reset\n");
  845. if ((pos = pci_find_capability(dd->pcidev, PCI_CAP_ID_EXP))) {
  846. u16 linkstat;
  847. pci_read_config_word(dd->pcidev, pos + PCI_EXP_LNKSTA,
  848. &linkstat);
  849. linkstat >>= 4;
  850. linkstat &= 0x1f;
  851. if (linkstat != 8)
  852. ipath_dev_err(dd, "PCIe width %u, "
  853. "performance reduced\n", linkstat);
  854. }
  855. else
  856. ipath_dev_err(dd, "Can't find PCI Express "
  857. "capability!\n");
  858. dd->ipath_link_width_supported = IB_WIDTH_1X | IB_WIDTH_4X;
  859. dd->ipath_link_speed_supported = IPATH_IB_SDR;
  860. dd->ipath_link_width_enabled = IB_WIDTH_4X;
  861. dd->ipath_link_speed_enabled = dd->ipath_link_speed_supported;
  862. /* these can't change for this chip, so set once */
  863. dd->ipath_link_width_active = dd->ipath_link_width_enabled;
  864. dd->ipath_link_speed_active = dd->ipath_link_speed_enabled;
  865. return 0;
  866. }
  867. static void ipath_init_pe_variables(struct ipath_devdata *dd)
  868. {
  869. /*
  870. * setup the register offsets, since they are different for each
  871. * chip
  872. */
  873. dd->ipath_kregs = &ipath_pe_kregs;
  874. dd->ipath_cregs = &ipath_pe_cregs;
  875. /*
  876. * bits for selecting i2c direction and values,
  877. * used for I2C serial flash
  878. */
  879. dd->ipath_gpio_sda_num = _IPATH_GPIO_SDA_NUM;
  880. dd->ipath_gpio_scl_num = _IPATH_GPIO_SCL_NUM;
  881. dd->ipath_gpio_sda = IPATH_GPIO_SDA;
  882. dd->ipath_gpio_scl = IPATH_GPIO_SCL;
  883. /*
  884. * Fill in data for field-values that change in newer chips.
  885. * We dynamically specify only the mask for LINKTRAININGSTATE
  886. * and only the shift for LINKSTATE, as they are the only ones
  887. * that change. Also precalculate the 3 link states of interest
  888. * and the combined mask.
  889. */
  890. dd->ibcs_ls_shift = IBA6120_IBCS_LINKSTATE_SHIFT;
  891. dd->ibcs_lts_mask = IBA6120_IBCS_LINKTRAININGSTATE_MASK;
  892. dd->ibcs_mask = (INFINIPATH_IBCS_LINKSTATE_MASK <<
  893. dd->ibcs_ls_shift) | dd->ibcs_lts_mask;
  894. dd->ib_init = (INFINIPATH_IBCS_LT_STATE_LINKUP <<
  895. INFINIPATH_IBCS_LINKTRAININGSTATE_SHIFT) |
  896. (INFINIPATH_IBCS_L_STATE_INIT << dd->ibcs_ls_shift);
  897. dd->ib_arm = (INFINIPATH_IBCS_LT_STATE_LINKUP <<
  898. INFINIPATH_IBCS_LINKTRAININGSTATE_SHIFT) |
  899. (INFINIPATH_IBCS_L_STATE_ARM << dd->ibcs_ls_shift);
  900. dd->ib_active = (INFINIPATH_IBCS_LT_STATE_LINKUP <<
  901. INFINIPATH_IBCS_LINKTRAININGSTATE_SHIFT) |
  902. (INFINIPATH_IBCS_L_STATE_ACTIVE << dd->ibcs_ls_shift);
  903. /*
  904. * Fill in data for ibcc field-values that change in newer chips.
  905. * We dynamically specify only the mask for LINKINITCMD
  906. * and only the shift for LINKCMD and MAXPKTLEN, as they are
  907. * the only ones that change.
  908. */
  909. dd->ibcc_lic_mask = INFINIPATH_IBCC_LINKINITCMD_MASK;
  910. dd->ibcc_lc_shift = INFINIPATH_IBCC_LINKCMD_SHIFT;
  911. dd->ibcc_mpl_shift = INFINIPATH_IBCC_MAXPKTLEN_SHIFT;
  912. /* Fill in shifts for RcvCtrl. */
  913. dd->ipath_r_portenable_shift = INFINIPATH_R_PORTENABLE_SHIFT;
  914. dd->ipath_r_intravail_shift = INFINIPATH_R_INTRAVAIL_SHIFT;
  915. dd->ipath_r_tailupd_shift = INFINIPATH_R_TAILUPD_SHIFT;
  916. dd->ipath_r_portcfg_shift = 0; /* Not on IBA6120 */
  917. /* variables for sanity checking interrupt and errors */
  918. dd->ipath_hwe_bitsextant =
  919. (INFINIPATH_HWE_RXEMEMPARITYERR_MASK <<
  920. INFINIPATH_HWE_RXEMEMPARITYERR_SHIFT) |
  921. (INFINIPATH_HWE_TXEMEMPARITYERR_MASK <<
  922. INFINIPATH_HWE_TXEMEMPARITYERR_SHIFT) |
  923. (INFINIPATH_HWE_PCIEMEMPARITYERR_MASK <<
  924. INFINIPATH_HWE_PCIEMEMPARITYERR_SHIFT) |
  925. INFINIPATH_HWE_PCIE1PLLFAILED |
  926. INFINIPATH_HWE_PCIE0PLLFAILED |
  927. INFINIPATH_HWE_PCIEPOISONEDTLP |
  928. INFINIPATH_HWE_PCIECPLTIMEOUT |
  929. INFINIPATH_HWE_PCIEBUSPARITYXTLH |
  930. INFINIPATH_HWE_PCIEBUSPARITYXADM |
  931. INFINIPATH_HWE_PCIEBUSPARITYRADM |
  932. INFINIPATH_HWE_MEMBISTFAILED |
  933. INFINIPATH_HWE_COREPLL_FBSLIP |
  934. INFINIPATH_HWE_COREPLL_RFSLIP |
  935. INFINIPATH_HWE_SERDESPLLFAILED |
  936. INFINIPATH_HWE_IBCBUSTOSPCPARITYERR |
  937. INFINIPATH_HWE_IBCBUSFRSPCPARITYERR;
  938. dd->ipath_i_bitsextant =
  939. (INFINIPATH_I_RCVURG_MASK << INFINIPATH_I_RCVURG_SHIFT) |
  940. (INFINIPATH_I_RCVAVAIL_MASK <<
  941. INFINIPATH_I_RCVAVAIL_SHIFT) |
  942. INFINIPATH_I_ERROR | INFINIPATH_I_SPIOSENT |
  943. INFINIPATH_I_SPIOBUFAVAIL | INFINIPATH_I_GPIO;
  944. dd->ipath_e_bitsextant =
  945. INFINIPATH_E_RFORMATERR | INFINIPATH_E_RVCRC |
  946. INFINIPATH_E_RICRC | INFINIPATH_E_RMINPKTLEN |
  947. INFINIPATH_E_RMAXPKTLEN | INFINIPATH_E_RLONGPKTLEN |
  948. INFINIPATH_E_RSHORTPKTLEN | INFINIPATH_E_RUNEXPCHAR |
  949. INFINIPATH_E_RUNSUPVL | INFINIPATH_E_REBP |
  950. INFINIPATH_E_RIBFLOW | INFINIPATH_E_RBADVERSION |
  951. INFINIPATH_E_RRCVEGRFULL | INFINIPATH_E_RRCVHDRFULL |
  952. INFINIPATH_E_RBADTID | INFINIPATH_E_RHDRLEN |
  953. INFINIPATH_E_RHDR | INFINIPATH_E_RIBLOSTLINK |
  954. INFINIPATH_E_SMINPKTLEN | INFINIPATH_E_SMAXPKTLEN |
  955. INFINIPATH_E_SUNDERRUN | INFINIPATH_E_SPKTLEN |
  956. INFINIPATH_E_SDROPPEDSMPPKT | INFINIPATH_E_SDROPPEDDATAPKT |
  957. INFINIPATH_E_SPIOARMLAUNCH | INFINIPATH_E_SUNEXPERRPKTNUM |
  958. INFINIPATH_E_SUNSUPVL | INFINIPATH_E_IBSTATUSCHANGED |
  959. INFINIPATH_E_INVALIDADDR | INFINIPATH_E_RESET |
  960. INFINIPATH_E_HARDWARE;
  961. dd->ipath_i_rcvavail_mask = INFINIPATH_I_RCVAVAIL_MASK;
  962. dd->ipath_i_rcvurg_mask = INFINIPATH_I_RCVURG_MASK;
  963. dd->ipath_i_rcvavail_shift = INFINIPATH_I_RCVAVAIL_SHIFT;
  964. dd->ipath_i_rcvurg_shift = INFINIPATH_I_RCVURG_SHIFT;
  965. /*
  966. * EEPROM error log 0 is TXE Parity errors. 1 is RXE Parity.
  967. * 2 is Some Misc, 3 is reserved for future.
  968. */
  969. dd->ipath_eep_st_masks[0].hwerrs_to_log =
  970. INFINIPATH_HWE_TXEMEMPARITYERR_MASK <<
  971. INFINIPATH_HWE_TXEMEMPARITYERR_SHIFT;
  972. /* Ignore errors in PIO/PBC on systems with unordered write-combining */
  973. if (ipath_unordered_wc())
  974. dd->ipath_eep_st_masks[0].hwerrs_to_log &= ~TXE_PIO_PARITY;
  975. dd->ipath_eep_st_masks[1].hwerrs_to_log =
  976. INFINIPATH_HWE_RXEMEMPARITYERR_MASK <<
  977. INFINIPATH_HWE_RXEMEMPARITYERR_SHIFT;
  978. dd->ipath_eep_st_masks[2].errs_to_log =
  979. INFINIPATH_E_INVALIDADDR | INFINIPATH_E_RESET;
  980. dd->delay_mult = 2; /* SDR, 4X, can't change */
  981. }
  982. /* setup the MSI stuff again after a reset. I'd like to just call
  983. * pci_enable_msi() and request_irq() again, but when I do that,
  984. * the MSI enable bit doesn't get set in the command word, and
  985. * we switch to to a different interrupt vector, which is confusing,
  986. * so I instead just do it all inline. Perhaps somehow can tie this
  987. * into the PCIe hotplug support at some point
  988. * Note, because I'm doing it all here, I don't call pci_disable_msi()
  989. * or free_irq() at the start of ipath_setup_pe_reset().
  990. */
  991. static int ipath_reinit_msi(struct ipath_devdata *dd)
  992. {
  993. int pos;
  994. u16 control;
  995. int ret;
  996. if (!dd->ipath_msi_lo) {
  997. dev_info(&dd->pcidev->dev, "Can't restore MSI config, "
  998. "initial setup failed?\n");
  999. ret = 0;
  1000. goto bail;
  1001. }
  1002. if (!(pos = pci_find_capability(dd->pcidev, PCI_CAP_ID_MSI))) {
  1003. ipath_dev_err(dd, "Can't find MSI capability, "
  1004. "can't restore MSI settings\n");
  1005. ret = 0;
  1006. goto bail;
  1007. }
  1008. ipath_cdbg(VERBOSE, "Writing msi_lo 0x%x to config offset 0x%x\n",
  1009. dd->ipath_msi_lo, pos + PCI_MSI_ADDRESS_LO);
  1010. pci_write_config_dword(dd->pcidev, pos + PCI_MSI_ADDRESS_LO,
  1011. dd->ipath_msi_lo);
  1012. ipath_cdbg(VERBOSE, "Writing msi_lo 0x%x to config offset 0x%x\n",
  1013. dd->ipath_msi_hi, pos + PCI_MSI_ADDRESS_HI);
  1014. pci_write_config_dword(dd->pcidev, pos + PCI_MSI_ADDRESS_HI,
  1015. dd->ipath_msi_hi);
  1016. pci_read_config_word(dd->pcidev, pos + PCI_MSI_FLAGS, &control);
  1017. if (!(control & PCI_MSI_FLAGS_ENABLE)) {
  1018. ipath_cdbg(VERBOSE, "MSI control at off %x was %x, "
  1019. "setting MSI enable (%x)\n", pos + PCI_MSI_FLAGS,
  1020. control, control | PCI_MSI_FLAGS_ENABLE);
  1021. control |= PCI_MSI_FLAGS_ENABLE;
  1022. pci_write_config_word(dd->pcidev, pos + PCI_MSI_FLAGS,
  1023. control);
  1024. }
  1025. /* now rewrite the data (vector) info */
  1026. pci_write_config_word(dd->pcidev, pos +
  1027. ((control & PCI_MSI_FLAGS_64BIT) ? 12 : 8),
  1028. dd->ipath_msi_data);
  1029. /* we restore the cachelinesize also, although it doesn't really
  1030. * matter */
  1031. pci_write_config_byte(dd->pcidev, PCI_CACHE_LINE_SIZE,
  1032. dd->ipath_pci_cacheline);
  1033. /* and now set the pci master bit again */
  1034. pci_set_master(dd->pcidev);
  1035. ret = 1;
  1036. bail:
  1037. return ret;
  1038. }
  1039. /* This routine sleeps, so it can only be called from user context, not
  1040. * from interrupt context. If we need interrupt context, we can split
  1041. * it into two routines.
  1042. */
  1043. static int ipath_setup_pe_reset(struct ipath_devdata *dd)
  1044. {
  1045. u64 val;
  1046. int i;
  1047. int ret;
  1048. /* Use ERROR so it shows up in logs, etc. */
  1049. ipath_dev_err(dd, "Resetting InfiniPath unit %u\n", dd->ipath_unit);
  1050. /* keep chip from being accessed in a few places */
  1051. dd->ipath_flags &= ~(IPATH_INITTED|IPATH_PRESENT);
  1052. val = dd->ipath_control | INFINIPATH_C_RESET;
  1053. ipath_write_kreg(dd, dd->ipath_kregs->kr_control, val);
  1054. mb();
  1055. for (i = 1; i <= 5; i++) {
  1056. int r;
  1057. /* allow MBIST, etc. to complete; longer on each retry.
  1058. * We sometimes get machine checks from bus timeout if no
  1059. * response, so for now, make it *really* long.
  1060. */
  1061. msleep(1000 + (1 + i) * 2000);
  1062. if ((r =
  1063. pci_write_config_dword(dd->pcidev, PCI_BASE_ADDRESS_0,
  1064. dd->ipath_pcibar0)))
  1065. ipath_dev_err(dd, "rewrite of BAR0 failed: %d\n",
  1066. r);
  1067. if ((r =
  1068. pci_write_config_dword(dd->pcidev, PCI_BASE_ADDRESS_1,
  1069. dd->ipath_pcibar1)))
  1070. ipath_dev_err(dd, "rewrite of BAR1 failed: %d\n",
  1071. r);
  1072. /* now re-enable memory access */
  1073. if ((r = pci_enable_device(dd->pcidev)))
  1074. ipath_dev_err(dd, "pci_enable_device failed after "
  1075. "reset: %d\n", r);
  1076. /* whether it worked or not, mark as present, again */
  1077. dd->ipath_flags |= IPATH_PRESENT;
  1078. val = ipath_read_kreg64(dd, dd->ipath_kregs->kr_revision);
  1079. if (val == dd->ipath_revision) {
  1080. ipath_cdbg(VERBOSE, "Got matching revision "
  1081. "register %llx on try %d\n",
  1082. (unsigned long long) val, i);
  1083. ret = ipath_reinit_msi(dd);
  1084. goto bail;
  1085. }
  1086. /* Probably getting -1 back */
  1087. ipath_dbg("Didn't get expected revision register, "
  1088. "got %llx, try %d\n", (unsigned long long) val,
  1089. i + 1);
  1090. }
  1091. ret = 0; /* failed */
  1092. bail:
  1093. return ret;
  1094. }
  1095. /**
  1096. * ipath_pe_put_tid - write a TID in chip
  1097. * @dd: the infinipath device
  1098. * @tidptr: pointer to the expected TID (in chip) to udpate
  1099. * @tidtype: RCVHQ_RCV_TYPE_EAGER (1) for eager, RCVHQ_RCV_TYPE_EXPECTED (0) for expected
  1100. * @pa: physical address of in memory buffer; ipath_tidinvalid if freeing
  1101. *
  1102. * This exists as a separate routine to allow for special locking etc.
  1103. * It's used for both the full cleanup on exit, as well as the normal
  1104. * setup and teardown.
  1105. */
  1106. static void ipath_pe_put_tid(struct ipath_devdata *dd, u64 __iomem *tidptr,
  1107. u32 type, unsigned long pa)
  1108. {
  1109. u32 __iomem *tidp32 = (u32 __iomem *)tidptr;
  1110. unsigned long flags = 0; /* keep gcc quiet */
  1111. if (pa != dd->ipath_tidinvalid) {
  1112. if (pa & ((1U << 11) - 1)) {
  1113. dev_info(&dd->pcidev->dev, "BUG: physaddr %lx "
  1114. "not 4KB aligned!\n", pa);
  1115. return;
  1116. }
  1117. pa >>= 11;
  1118. /* paranoia check */
  1119. if (pa & (7<<29))
  1120. ipath_dev_err(dd,
  1121. "BUG: Physical page address 0x%lx "
  1122. "has bits set in 31-29\n", pa);
  1123. if (type == RCVHQ_RCV_TYPE_EAGER)
  1124. pa |= dd->ipath_tidtemplate;
  1125. else /* for now, always full 4KB page */
  1126. pa |= 2 << 29;
  1127. }
  1128. /*
  1129. * Workaround chip bug 9437 by writing the scratch register
  1130. * before and after the TID, and with an io write barrier.
  1131. * We use a spinlock around the writes, so they can't intermix
  1132. * with other TID (eager or expected) writes (the chip bug
  1133. * is triggered by back to back TID writes). Unfortunately, this
  1134. * call can be done from interrupt level for the port 0 eager TIDs,
  1135. * so we have to use irqsave locks.
  1136. */
  1137. spin_lock_irqsave(&dd->ipath_tid_lock, flags);
  1138. ipath_write_kreg(dd, dd->ipath_kregs->kr_scratch, 0xfeeddeaf);
  1139. if (dd->ipath_kregbase)
  1140. writel(pa, tidp32);
  1141. ipath_write_kreg(dd, dd->ipath_kregs->kr_scratch, 0xdeadbeef);
  1142. mmiowb();
  1143. spin_unlock_irqrestore(&dd->ipath_tid_lock, flags);
  1144. }
  1145. /**
  1146. * ipath_pe_put_tid_2 - write a TID in chip, Revision 2 or higher
  1147. * @dd: the infinipath device
  1148. * @tidptr: pointer to the expected TID (in chip) to udpate
  1149. * @tidtype: RCVHQ_RCV_TYPE_EAGER (1) for eager, RCVHQ_RCV_TYPE_EXPECTED (0) for expected
  1150. * @pa: physical address of in memory buffer; ipath_tidinvalid if freeing
  1151. *
  1152. * This exists as a separate routine to allow for selection of the
  1153. * appropriate "flavor". The static calls in cleanup just use the
  1154. * revision-agnostic form, as they are not performance critical.
  1155. */
  1156. static void ipath_pe_put_tid_2(struct ipath_devdata *dd, u64 __iomem *tidptr,
  1157. u32 type, unsigned long pa)
  1158. {
  1159. u32 __iomem *tidp32 = (u32 __iomem *)tidptr;
  1160. if (pa != dd->ipath_tidinvalid) {
  1161. if (pa & ((1U << 11) - 1)) {
  1162. dev_info(&dd->pcidev->dev, "BUG: physaddr %lx "
  1163. "not 2KB aligned!\n", pa);
  1164. return;
  1165. }
  1166. pa >>= 11;
  1167. /* paranoia check */
  1168. if (pa & (7<<29))
  1169. ipath_dev_err(dd,
  1170. "BUG: Physical page address 0x%lx "
  1171. "has bits set in 31-29\n", pa);
  1172. if (type == RCVHQ_RCV_TYPE_EAGER)
  1173. pa |= dd->ipath_tidtemplate;
  1174. else /* for now, always full 4KB page */
  1175. pa |= 2 << 29;
  1176. }
  1177. if (dd->ipath_kregbase)
  1178. writel(pa, tidp32);
  1179. mmiowb();
  1180. }
  1181. /**
  1182. * ipath_pe_clear_tid - clear all TID entries for a port, expected and eager
  1183. * @dd: the infinipath device
  1184. * @port: the port
  1185. *
  1186. * clear all TID entries for a port, expected and eager.
  1187. * Used from ipath_close(). On this chip, TIDs are only 32 bits,
  1188. * not 64, but they are still on 64 bit boundaries, so tidbase
  1189. * is declared as u64 * for the pointer math, even though we write 32 bits
  1190. */
  1191. static void ipath_pe_clear_tids(struct ipath_devdata *dd, unsigned port)
  1192. {
  1193. u64 __iomem *tidbase;
  1194. unsigned long tidinv;
  1195. int i;
  1196. if (!dd->ipath_kregbase)
  1197. return;
  1198. ipath_cdbg(VERBOSE, "Invalidate TIDs for port %u\n", port);
  1199. tidinv = dd->ipath_tidinvalid;
  1200. tidbase = (u64 __iomem *)
  1201. ((char __iomem *)(dd->ipath_kregbase) +
  1202. dd->ipath_rcvtidbase +
  1203. port * dd->ipath_rcvtidcnt * sizeof(*tidbase));
  1204. for (i = 0; i < dd->ipath_rcvtidcnt; i++)
  1205. dd->ipath_f_put_tid(dd, &tidbase[i], RCVHQ_RCV_TYPE_EXPECTED,
  1206. tidinv);
  1207. tidbase = (u64 __iomem *)
  1208. ((char __iomem *)(dd->ipath_kregbase) +
  1209. dd->ipath_rcvegrbase +
  1210. port * dd->ipath_rcvegrcnt * sizeof(*tidbase));
  1211. for (i = 0; i < dd->ipath_rcvegrcnt; i++)
  1212. dd->ipath_f_put_tid(dd, &tidbase[i], RCVHQ_RCV_TYPE_EAGER,
  1213. tidinv);
  1214. }
  1215. /**
  1216. * ipath_pe_tidtemplate - setup constants for TID updates
  1217. * @dd: the infinipath device
  1218. *
  1219. * We setup stuff that we use a lot, to avoid calculating each time
  1220. */
  1221. static void ipath_pe_tidtemplate(struct ipath_devdata *dd)
  1222. {
  1223. u32 egrsize = dd->ipath_rcvegrbufsize;
  1224. /* For now, we always allocate 4KB buffers (at init) so we can
  1225. * receive max size packets. We may want a module parameter to
  1226. * specify 2KB or 4KB and/or make be per port instead of per device
  1227. * for those who want to reduce memory footprint. Note that the
  1228. * ipath_rcvhdrentsize size must be large enough to hold the largest
  1229. * IB header (currently 96 bytes) that we expect to handle (plus of
  1230. * course the 2 dwords of RHF).
  1231. */
  1232. if (egrsize == 2048)
  1233. dd->ipath_tidtemplate = 1U << 29;
  1234. else if (egrsize == 4096)
  1235. dd->ipath_tidtemplate = 2U << 29;
  1236. else {
  1237. egrsize = 4096;
  1238. dev_info(&dd->pcidev->dev, "BUG: unsupported egrbufsize "
  1239. "%u, using %u\n", dd->ipath_rcvegrbufsize,
  1240. egrsize);
  1241. dd->ipath_tidtemplate = 2U << 29;
  1242. }
  1243. dd->ipath_tidinvalid = 0;
  1244. }
  1245. static int ipath_pe_early_init(struct ipath_devdata *dd)
  1246. {
  1247. dd->ipath_flags |= IPATH_4BYTE_TID;
  1248. if (ipath_unordered_wc())
  1249. dd->ipath_flags |= IPATH_PIO_FLUSH_WC;
  1250. /*
  1251. * For openfabrics, we need to be able to handle an IB header of
  1252. * 24 dwords. HT chip has arbitrary sized receive buffers, so we
  1253. * made them the same size as the PIO buffers. This chip does not
  1254. * handle arbitrary size buffers, so we need the header large enough
  1255. * to handle largest IB header, but still have room for a 2KB MTU
  1256. * standard IB packet.
  1257. */
  1258. dd->ipath_rcvhdrentsize = 24;
  1259. dd->ipath_rcvhdrsize = IPATH_DFLT_RCVHDRSIZE;
  1260. dd->ipath_rhf_offset = 0;
  1261. dd->ipath_egrtidbase = (u64 __iomem *)
  1262. ((char __iomem *) dd->ipath_kregbase + dd->ipath_rcvegrbase);
  1263. /*
  1264. * To truly support a 4KB MTU (for usermode), we need to
  1265. * bump this to a larger value. For now, we use them for
  1266. * the kernel only.
  1267. */
  1268. dd->ipath_rcvegrbufsize = 2048;
  1269. /*
  1270. * the min() check here is currently a nop, but it may not always
  1271. * be, depending on just how we do ipath_rcvegrbufsize
  1272. */
  1273. dd->ipath_ibmaxlen = min(dd->ipath_piosize2k,
  1274. dd->ipath_rcvegrbufsize +
  1275. (dd->ipath_rcvhdrentsize << 2));
  1276. dd->ipath_init_ibmaxlen = dd->ipath_ibmaxlen;
  1277. /*
  1278. * We can request a receive interrupt for 1 or
  1279. * more packets from current offset. For now, we set this
  1280. * up for a single packet.
  1281. */
  1282. dd->ipath_rhdrhead_intr_off = 1ULL<<32;
  1283. ipath_get_eeprom_info(dd);
  1284. return 0;
  1285. }
  1286. int __attribute__((weak)) ipath_unordered_wc(void)
  1287. {
  1288. return 0;
  1289. }
  1290. /**
  1291. * ipath_init_pe_get_base_info - set chip-specific flags for user code
  1292. * @pd: the infinipath port
  1293. * @kbase: ipath_base_info pointer
  1294. *
  1295. * We set the PCIE flag because the lower bandwidth on PCIe vs
  1296. * HyperTransport can affect some user packet algorithms.
  1297. */
  1298. static int ipath_pe_get_base_info(struct ipath_portdata *pd, void *kbase)
  1299. {
  1300. struct ipath_base_info *kinfo = kbase;
  1301. struct ipath_devdata *dd;
  1302. if (ipath_unordered_wc()) {
  1303. kinfo->spi_runtime_flags |= IPATH_RUNTIME_FORCE_WC_ORDER;
  1304. ipath_cdbg(PROC, "Intel processor, forcing WC order\n");
  1305. }
  1306. else
  1307. ipath_cdbg(PROC, "Not Intel processor, WC ordered\n");
  1308. if (pd == NULL)
  1309. goto done;
  1310. dd = pd->port_dd;
  1311. done:
  1312. kinfo->spi_runtime_flags |= IPATH_RUNTIME_PCIE |
  1313. IPATH_RUNTIME_FORCE_PIOAVAIL | IPATH_RUNTIME_PIO_REGSWAPPED;
  1314. return 0;
  1315. }
  1316. static void ipath_pe_free_irq(struct ipath_devdata *dd)
  1317. {
  1318. free_irq(dd->ipath_irq, dd);
  1319. dd->ipath_irq = 0;
  1320. }
  1321. static struct ipath_message_header *
  1322. ipath_pe_get_msgheader(struct ipath_devdata *dd, __le32 *rhf_addr)
  1323. {
  1324. return (struct ipath_message_header *)
  1325. &rhf_addr[sizeof(u64) / sizeof(u32)];
  1326. }
  1327. static void ipath_pe_config_ports(struct ipath_devdata *dd, ushort cfgports)
  1328. {
  1329. dd->ipath_portcnt =
  1330. ipath_read_kreg32(dd, dd->ipath_kregs->kr_portcnt);
  1331. dd->ipath_p0_rcvegrcnt =
  1332. ipath_read_kreg32(dd, dd->ipath_kregs->kr_rcvegrcnt);
  1333. }
  1334. static void ipath_pe_read_counters(struct ipath_devdata *dd,
  1335. struct infinipath_counters *cntrs)
  1336. {
  1337. cntrs->LBIntCnt =
  1338. ipath_snap_cntr(dd, IPATH_CREG_OFFSET(LBIntCnt));
  1339. cntrs->LBFlowStallCnt =
  1340. ipath_snap_cntr(dd, IPATH_CREG_OFFSET(LBFlowStallCnt));
  1341. cntrs->TxSDmaDescCnt = 0;
  1342. cntrs->TxUnsupVLErrCnt =
  1343. ipath_snap_cntr(dd, IPATH_CREG_OFFSET(TxUnsupVLErrCnt));
  1344. cntrs->TxDataPktCnt =
  1345. ipath_snap_cntr(dd, IPATH_CREG_OFFSET(TxDataPktCnt));
  1346. cntrs->TxFlowPktCnt =
  1347. ipath_snap_cntr(dd, IPATH_CREG_OFFSET(TxFlowPktCnt));
  1348. cntrs->TxDwordCnt =
  1349. ipath_snap_cntr(dd, IPATH_CREG_OFFSET(TxDwordCnt));
  1350. cntrs->TxLenErrCnt =
  1351. ipath_snap_cntr(dd, IPATH_CREG_OFFSET(TxLenErrCnt));
  1352. cntrs->TxMaxMinLenErrCnt =
  1353. ipath_snap_cntr(dd, IPATH_CREG_OFFSET(TxMaxMinLenErrCnt));
  1354. cntrs->TxUnderrunCnt =
  1355. ipath_snap_cntr(dd, IPATH_CREG_OFFSET(TxUnderrunCnt));
  1356. cntrs->TxFlowStallCnt =
  1357. ipath_snap_cntr(dd, IPATH_CREG_OFFSET(TxFlowStallCnt));
  1358. cntrs->TxDroppedPktCnt =
  1359. ipath_snap_cntr(dd, IPATH_CREG_OFFSET(TxDroppedPktCnt));
  1360. cntrs->RxDroppedPktCnt =
  1361. ipath_snap_cntr(dd, IPATH_CREG_OFFSET(RxDroppedPktCnt));
  1362. cntrs->RxDataPktCnt =
  1363. ipath_snap_cntr(dd, IPATH_CREG_OFFSET(RxDataPktCnt));
  1364. cntrs->RxFlowPktCnt =
  1365. ipath_snap_cntr(dd, IPATH_CREG_OFFSET(RxFlowPktCnt));
  1366. cntrs->RxDwordCnt =
  1367. ipath_snap_cntr(dd, IPATH_CREG_OFFSET(RxDwordCnt));
  1368. cntrs->RxLenErrCnt =
  1369. ipath_snap_cntr(dd, IPATH_CREG_OFFSET(RxLenErrCnt));
  1370. cntrs->RxMaxMinLenErrCnt =
  1371. ipath_snap_cntr(dd, IPATH_CREG_OFFSET(RxMaxMinLenErrCnt));
  1372. cntrs->RxICRCErrCnt =
  1373. ipath_snap_cntr(dd, IPATH_CREG_OFFSET(RxICRCErrCnt));
  1374. cntrs->RxVCRCErrCnt =
  1375. ipath_snap_cntr(dd, IPATH_CREG_OFFSET(RxVCRCErrCnt));
  1376. cntrs->RxFlowCtrlErrCnt =
  1377. ipath_snap_cntr(dd, IPATH_CREG_OFFSET(RxFlowCtrlErrCnt));
  1378. cntrs->RxBadFormatCnt =
  1379. ipath_snap_cntr(dd, IPATH_CREG_OFFSET(RxBadFormatCnt));
  1380. cntrs->RxLinkProblemCnt =
  1381. ipath_snap_cntr(dd, IPATH_CREG_OFFSET(RxLinkProblemCnt));
  1382. cntrs->RxEBPCnt =
  1383. ipath_snap_cntr(dd, IPATH_CREG_OFFSET(RxEBPCnt));
  1384. cntrs->RxLPCRCErrCnt =
  1385. ipath_snap_cntr(dd, IPATH_CREG_OFFSET(RxLPCRCErrCnt));
  1386. cntrs->RxBufOvflCnt =
  1387. ipath_snap_cntr(dd, IPATH_CREG_OFFSET(RxBufOvflCnt));
  1388. cntrs->RxTIDFullErrCnt =
  1389. ipath_snap_cntr(dd, IPATH_CREG_OFFSET(RxTIDFullErrCnt));
  1390. cntrs->RxTIDValidErrCnt =
  1391. ipath_snap_cntr(dd, IPATH_CREG_OFFSET(RxTIDValidErrCnt));
  1392. cntrs->RxPKeyMismatchCnt =
  1393. ipath_snap_cntr(dd, IPATH_CREG_OFFSET(RxPKeyMismatchCnt));
  1394. cntrs->RxP0HdrEgrOvflCnt =
  1395. ipath_snap_cntr(dd, IPATH_CREG_OFFSET(RxP0HdrEgrOvflCnt));
  1396. cntrs->RxP1HdrEgrOvflCnt =
  1397. ipath_snap_cntr(dd, IPATH_CREG_OFFSET(RxP1HdrEgrOvflCnt));
  1398. cntrs->RxP2HdrEgrOvflCnt =
  1399. ipath_snap_cntr(dd, IPATH_CREG_OFFSET(RxP2HdrEgrOvflCnt));
  1400. cntrs->RxP3HdrEgrOvflCnt =
  1401. ipath_snap_cntr(dd, IPATH_CREG_OFFSET(RxP3HdrEgrOvflCnt));
  1402. cntrs->RxP4HdrEgrOvflCnt =
  1403. ipath_snap_cntr(dd, IPATH_CREG_OFFSET(RxP4HdrEgrOvflCnt));
  1404. cntrs->RxP5HdrEgrOvflCnt = 0;
  1405. cntrs->RxP6HdrEgrOvflCnt = 0;
  1406. cntrs->RxP7HdrEgrOvflCnt = 0;
  1407. cntrs->RxP8HdrEgrOvflCnt = 0;
  1408. cntrs->RxP9HdrEgrOvflCnt = 0;
  1409. cntrs->RxP10HdrEgrOvflCnt = 0;
  1410. cntrs->RxP11HdrEgrOvflCnt = 0;
  1411. cntrs->RxP12HdrEgrOvflCnt = 0;
  1412. cntrs->RxP13HdrEgrOvflCnt = 0;
  1413. cntrs->RxP14HdrEgrOvflCnt = 0;
  1414. cntrs->RxP15HdrEgrOvflCnt = 0;
  1415. cntrs->RxP16HdrEgrOvflCnt = 0;
  1416. cntrs->IBStatusChangeCnt =
  1417. ipath_snap_cntr(dd, IPATH_CREG_OFFSET(IBStatusChangeCnt));
  1418. cntrs->IBLinkErrRecoveryCnt =
  1419. ipath_snap_cntr(dd, IPATH_CREG_OFFSET(IBLinkErrRecoveryCnt));
  1420. cntrs->IBLinkDownedCnt =
  1421. ipath_snap_cntr(dd, IPATH_CREG_OFFSET(IBLinkDownedCnt));
  1422. cntrs->IBSymbolErrCnt =
  1423. ipath_snap_cntr(dd, IPATH_CREG_OFFSET(IBSymbolErrCnt));
  1424. cntrs->RxVL15DroppedPktCnt = 0;
  1425. cntrs->RxOtherLocalPhyErrCnt = 0;
  1426. cntrs->PcieRetryBufDiagQwordCnt = 0;
  1427. cntrs->ExcessBufferOvflCnt = dd->ipath_overrun_thresh_errs;
  1428. cntrs->LocalLinkIntegrityErrCnt = dd->ipath_lli_errs;
  1429. cntrs->RxVlErrCnt = 0;
  1430. cntrs->RxDlidFltrCnt = 0;
  1431. }
  1432. /* no interrupt fallback for these chips */
  1433. static int ipath_pe_nointr_fallback(struct ipath_devdata *dd)
  1434. {
  1435. return 0;
  1436. }
  1437. /*
  1438. * reset the XGXS (between serdes and IBC). Slightly less intrusive
  1439. * than resetting the IBC or external link state, and useful in some
  1440. * cases to cause some retraining. To do this right, we reset IBC
  1441. * as well.
  1442. */
  1443. static void ipath_pe_xgxs_reset(struct ipath_devdata *dd)
  1444. {
  1445. u64 val, prev_val;
  1446. prev_val = ipath_read_kreg64(dd, dd->ipath_kregs->kr_xgxsconfig);
  1447. val = prev_val | INFINIPATH_XGXS_RESET;
  1448. prev_val &= ~INFINIPATH_XGXS_RESET; /* be sure */
  1449. ipath_write_kreg(dd, dd->ipath_kregs->kr_control,
  1450. dd->ipath_control & ~INFINIPATH_C_LINKENABLE);
  1451. ipath_write_kreg(dd, dd->ipath_kregs->kr_xgxsconfig, val);
  1452. ipath_read_kreg32(dd, dd->ipath_kregs->kr_scratch);
  1453. ipath_write_kreg(dd, dd->ipath_kregs->kr_xgxsconfig, prev_val);
  1454. ipath_write_kreg(dd, dd->ipath_kregs->kr_control,
  1455. dd->ipath_control);
  1456. }
  1457. static int ipath_pe_get_ib_cfg(struct ipath_devdata *dd, int which)
  1458. {
  1459. int ret;
  1460. switch (which) {
  1461. case IPATH_IB_CFG_LWID:
  1462. ret = dd->ipath_link_width_active;
  1463. break;
  1464. case IPATH_IB_CFG_SPD:
  1465. ret = dd->ipath_link_speed_active;
  1466. break;
  1467. case IPATH_IB_CFG_LWID_ENB:
  1468. ret = dd->ipath_link_width_enabled;
  1469. break;
  1470. case IPATH_IB_CFG_SPD_ENB:
  1471. ret = dd->ipath_link_speed_enabled;
  1472. break;
  1473. default:
  1474. ret = -ENOTSUPP;
  1475. break;
  1476. }
  1477. return ret;
  1478. }
  1479. /* we assume range checking is already done, if needed */
  1480. static int ipath_pe_set_ib_cfg(struct ipath_devdata *dd, int which, u32 val)
  1481. {
  1482. int ret = 0;
  1483. if (which == IPATH_IB_CFG_LWID_ENB)
  1484. dd->ipath_link_width_enabled = val;
  1485. else if (which == IPATH_IB_CFG_SPD_ENB)
  1486. dd->ipath_link_speed_enabled = val;
  1487. else
  1488. ret = -ENOTSUPP;
  1489. return ret;
  1490. }
  1491. static void ipath_pe_config_jint(struct ipath_devdata *dd, u16 a, u16 b)
  1492. {
  1493. }
  1494. static int ipath_pe_ib_updown(struct ipath_devdata *dd, int ibup, u64 ibcs)
  1495. {
  1496. ipath_setup_pe_setextled(dd, ipath_ib_linkstate(dd, ibcs),
  1497. ipath_ib_linktrstate(dd, ibcs));
  1498. return 0;
  1499. }
  1500. /**
  1501. * ipath_init_iba6120_funcs - set up the chip-specific function pointers
  1502. * @dd: the infinipath device
  1503. *
  1504. * This is global, and is called directly at init to set up the
  1505. * chip-specific function pointers for later use.
  1506. */
  1507. void ipath_init_iba6120_funcs(struct ipath_devdata *dd)
  1508. {
  1509. dd->ipath_f_intrsetup = ipath_pe_intconfig;
  1510. dd->ipath_f_bus = ipath_setup_pe_config;
  1511. dd->ipath_f_reset = ipath_setup_pe_reset;
  1512. dd->ipath_f_get_boardname = ipath_pe_boardname;
  1513. dd->ipath_f_init_hwerrors = ipath_pe_init_hwerrors;
  1514. dd->ipath_f_early_init = ipath_pe_early_init;
  1515. dd->ipath_f_handle_hwerrors = ipath_pe_handle_hwerrors;
  1516. dd->ipath_f_quiet_serdes = ipath_pe_quiet_serdes;
  1517. dd->ipath_f_bringup_serdes = ipath_pe_bringup_serdes;
  1518. dd->ipath_f_clear_tids = ipath_pe_clear_tids;
  1519. /*
  1520. * _f_put_tid may get changed after we read the chip revision,
  1521. * but we start with the safe version for all revs
  1522. */
  1523. dd->ipath_f_put_tid = ipath_pe_put_tid;
  1524. dd->ipath_f_cleanup = ipath_setup_pe_cleanup;
  1525. dd->ipath_f_setextled = ipath_setup_pe_setextled;
  1526. dd->ipath_f_get_base_info = ipath_pe_get_base_info;
  1527. dd->ipath_f_free_irq = ipath_pe_free_irq;
  1528. dd->ipath_f_tidtemplate = ipath_pe_tidtemplate;
  1529. dd->ipath_f_intr_fallback = ipath_pe_nointr_fallback;
  1530. dd->ipath_f_xgxs_reset = ipath_pe_xgxs_reset;
  1531. dd->ipath_f_get_msgheader = ipath_pe_get_msgheader;
  1532. dd->ipath_f_config_ports = ipath_pe_config_ports;
  1533. dd->ipath_f_read_counters = ipath_pe_read_counters;
  1534. dd->ipath_f_get_ib_cfg = ipath_pe_get_ib_cfg;
  1535. dd->ipath_f_set_ib_cfg = ipath_pe_set_ib_cfg;
  1536. dd->ipath_f_config_jint = ipath_pe_config_jint;
  1537. dd->ipath_f_ib_updown = ipath_pe_ib_updown;
  1538. /* initialize chip-specific variables */
  1539. ipath_init_pe_variables(dd);
  1540. }