ipath_iba6110.c 62 KB

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