ipath_iba6110.c 53 KB

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