ipath_ht400.c 51 KB

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