ipath_iba6110.c 52 KB

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