ipath_iba6120.c 58 KB

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