ipath_iba7220.c 84 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566
  1. /*
  2. * Copyright (c) 2006, 2007, 2008 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 7220 chip (except that specific to the SerDes)
  36. */
  37. #include <linux/interrupt.h>
  38. #include <linux/pci.h>
  39. #include <linux/delay.h>
  40. #include <linux/io.h>
  41. #include <rdma/ib_verbs.h>
  42. #include "ipath_kernel.h"
  43. #include "ipath_registers.h"
  44. #include "ipath_7220.h"
  45. static void ipath_setup_7220_setextled(struct ipath_devdata *, u64, u64);
  46. static unsigned ipath_compat_ddr_negotiate = 1;
  47. module_param_named(compat_ddr_negotiate, ipath_compat_ddr_negotiate, uint,
  48. S_IWUSR | S_IRUGO);
  49. MODULE_PARM_DESC(compat_ddr_negotiate,
  50. "Attempt pre-IBTA 1.2 DDR speed negotiation");
  51. static unsigned ipath_sdma_fetch_arb = 1;
  52. module_param_named(fetch_arb, ipath_sdma_fetch_arb, uint, S_IRUGO);
  53. MODULE_PARM_DESC(fetch_arb, "IBA7220: change SDMA descriptor arbitration");
  54. /*
  55. * This file contains almost all the chip-specific register information and
  56. * access functions for the QLogic InfiniPath 7220 PCI-Express chip, with the
  57. * exception of SerDes support, which in in ipath_sd7220.c.
  58. *
  59. * This lists the InfiniPath registers, in the actual chip layout.
  60. * This structure should never be directly accessed.
  61. */
  62. struct _infinipath_do_not_use_kernel_regs {
  63. unsigned long long Revision;
  64. unsigned long long Control;
  65. unsigned long long PageAlign;
  66. unsigned long long PortCnt;
  67. unsigned long long DebugPortSelect;
  68. unsigned long long DebugSigsIntSel; /* was Reserved0;*/
  69. unsigned long long SendRegBase;
  70. unsigned long long UserRegBase;
  71. unsigned long long CounterRegBase;
  72. unsigned long long Scratch;
  73. unsigned long long EEPROMAddrCmd; /* was Reserved1; */
  74. unsigned long long EEPROMData; /* was Reserved2; */
  75. unsigned long long IntBlocked;
  76. unsigned long long IntMask;
  77. unsigned long long IntStatus;
  78. unsigned long long IntClear;
  79. unsigned long long ErrorMask;
  80. unsigned long long ErrorStatus;
  81. unsigned long long ErrorClear;
  82. unsigned long long HwErrMask;
  83. unsigned long long HwErrStatus;
  84. unsigned long long HwErrClear;
  85. unsigned long long HwDiagCtrl;
  86. unsigned long long MDIO;
  87. unsigned long long IBCStatus;
  88. unsigned long long IBCCtrl;
  89. unsigned long long ExtStatus;
  90. unsigned long long ExtCtrl;
  91. unsigned long long GPIOOut;
  92. unsigned long long GPIOMask;
  93. unsigned long long GPIOStatus;
  94. unsigned long long GPIOClear;
  95. unsigned long long RcvCtrl;
  96. unsigned long long RcvBTHQP;
  97. unsigned long long RcvHdrSize;
  98. unsigned long long RcvHdrCnt;
  99. unsigned long long RcvHdrEntSize;
  100. unsigned long long RcvTIDBase;
  101. unsigned long long RcvTIDCnt;
  102. unsigned long long RcvEgrBase;
  103. unsigned long long RcvEgrCnt;
  104. unsigned long long RcvBufBase;
  105. unsigned long long RcvBufSize;
  106. unsigned long long RxIntMemBase;
  107. unsigned long long RxIntMemSize;
  108. unsigned long long RcvPartitionKey;
  109. unsigned long long RcvQPMulticastPort;
  110. unsigned long long RcvPktLEDCnt;
  111. unsigned long long IBCDDRCtrl;
  112. unsigned long long HRTBT_GUID;
  113. unsigned long long IB_SDTEST_IF_TX;
  114. unsigned long long IB_SDTEST_IF_RX;
  115. unsigned long long IBCDDRCtrl2;
  116. unsigned long long IBCDDRStatus;
  117. unsigned long long JIntReload;
  118. unsigned long long IBNCModeCtrl;
  119. unsigned long long SendCtrl;
  120. unsigned long long SendBufBase;
  121. unsigned long long SendBufSize;
  122. unsigned long long SendBufCnt;
  123. unsigned long long SendAvailAddr;
  124. unsigned long long TxIntMemBase;
  125. unsigned long long TxIntMemSize;
  126. unsigned long long SendDmaBase;
  127. unsigned long long SendDmaLenGen;
  128. unsigned long long SendDmaTail;
  129. unsigned long long SendDmaHead;
  130. unsigned long long SendDmaHeadAddr;
  131. unsigned long long SendDmaBufMask0;
  132. unsigned long long SendDmaBufMask1;
  133. unsigned long long SendDmaBufMask2;
  134. unsigned long long SendDmaStatus;
  135. unsigned long long SendBufferError;
  136. unsigned long long SendBufferErrorCONT1;
  137. unsigned long long SendBufErr2; /* was Reserved6SBE[0/6] */
  138. unsigned long long Reserved6L[2];
  139. unsigned long long AvailUpdCount;
  140. unsigned long long RcvHdrAddr0;
  141. unsigned long long RcvHdrAddrs[16]; /* Why enumerate? */
  142. unsigned long long Reserved7hdtl; /* Align next to 300 */
  143. unsigned long long RcvHdrTailAddr0; /* 300, like others */
  144. unsigned long long RcvHdrTailAddrs[16];
  145. unsigned long long Reserved9SW[7]; /* was [8]; we have 17 ports */
  146. unsigned long long IbsdEpbAccCtl; /* IB Serdes EPB access control */
  147. unsigned long long IbsdEpbTransReg; /* IB Serdes EPB Transaction */
  148. unsigned long long Reserved10sds; /* was SerdesStatus on */
  149. unsigned long long XGXSConfig;
  150. unsigned long long IBSerDesCtrl; /* Was IBPLLCfg on Monty */
  151. unsigned long long EEPCtlStat; /* for "boot" EEPROM/FLASH */
  152. unsigned long long EEPAddrCmd;
  153. unsigned long long EEPData;
  154. unsigned long long PcieEpbAccCtl;
  155. unsigned long long PcieEpbTransCtl;
  156. unsigned long long EfuseCtl; /* E-Fuse control */
  157. unsigned long long EfuseData[4];
  158. unsigned long long ProcMon;
  159. /* this chip moves following two from previous 200, 208 */
  160. unsigned long long PCIeRBufTestReg0;
  161. unsigned long long PCIeRBufTestReg1;
  162. /* added for this chip */
  163. unsigned long long PCIeRBufTestReg2;
  164. unsigned long long PCIeRBufTestReg3;
  165. /* added for this chip, debug only */
  166. unsigned long long SPC_JTAG_ACCESS_REG;
  167. unsigned long long LAControlReg;
  168. unsigned long long GPIODebugSelReg;
  169. unsigned long long DebugPortValueReg;
  170. /* added for this chip, DMA */
  171. unsigned long long SendDmaBufUsed[3];
  172. unsigned long long SendDmaReqTagUsed;
  173. /*
  174. * added for this chip, EFUSE: note that these program 64-bit
  175. * words 2 and 3 */
  176. unsigned long long efuse_pgm_data[2];
  177. unsigned long long Reserved11LAalign[10]; /* Skip 4B0..4F8 */
  178. /* we have 30 regs for DDS and RXEQ in IB SERDES */
  179. unsigned long long SerDesDDSRXEQ[30];
  180. unsigned long long Reserved12LAalign[2]; /* Skip 5F0, 5F8 */
  181. /* added for LA debug support */
  182. unsigned long long LAMemory[32];
  183. };
  184. struct _infinipath_do_not_use_counters {
  185. __u64 LBIntCnt;
  186. __u64 LBFlowStallCnt;
  187. __u64 TxSDmaDescCnt; /* was Reserved1 */
  188. __u64 TxUnsupVLErrCnt;
  189. __u64 TxDataPktCnt;
  190. __u64 TxFlowPktCnt;
  191. __u64 TxDwordCnt;
  192. __u64 TxLenErrCnt;
  193. __u64 TxMaxMinLenErrCnt;
  194. __u64 TxUnderrunCnt;
  195. __u64 TxFlowStallCnt;
  196. __u64 TxDroppedPktCnt;
  197. __u64 RxDroppedPktCnt;
  198. __u64 RxDataPktCnt;
  199. __u64 RxFlowPktCnt;
  200. __u64 RxDwordCnt;
  201. __u64 RxLenErrCnt;
  202. __u64 RxMaxMinLenErrCnt;
  203. __u64 RxICRCErrCnt;
  204. __u64 RxVCRCErrCnt;
  205. __u64 RxFlowCtrlErrCnt;
  206. __u64 RxBadFormatCnt;
  207. __u64 RxLinkProblemCnt;
  208. __u64 RxEBPCnt;
  209. __u64 RxLPCRCErrCnt;
  210. __u64 RxBufOvflCnt;
  211. __u64 RxTIDFullErrCnt;
  212. __u64 RxTIDValidErrCnt;
  213. __u64 RxPKeyMismatchCnt;
  214. __u64 RxP0HdrEgrOvflCnt;
  215. __u64 RxP1HdrEgrOvflCnt;
  216. __u64 RxP2HdrEgrOvflCnt;
  217. __u64 RxP3HdrEgrOvflCnt;
  218. __u64 RxP4HdrEgrOvflCnt;
  219. __u64 RxP5HdrEgrOvflCnt;
  220. __u64 RxP6HdrEgrOvflCnt;
  221. __u64 RxP7HdrEgrOvflCnt;
  222. __u64 RxP8HdrEgrOvflCnt;
  223. __u64 RxP9HdrEgrOvflCnt; /* was Reserved6 */
  224. __u64 RxP10HdrEgrOvflCnt; /* was Reserved7 */
  225. __u64 RxP11HdrEgrOvflCnt; /* new for IBA7220 */
  226. __u64 RxP12HdrEgrOvflCnt; /* new for IBA7220 */
  227. __u64 RxP13HdrEgrOvflCnt; /* new for IBA7220 */
  228. __u64 RxP14HdrEgrOvflCnt; /* new for IBA7220 */
  229. __u64 RxP15HdrEgrOvflCnt; /* new for IBA7220 */
  230. __u64 RxP16HdrEgrOvflCnt; /* new for IBA7220 */
  231. __u64 IBStatusChangeCnt;
  232. __u64 IBLinkErrRecoveryCnt;
  233. __u64 IBLinkDownedCnt;
  234. __u64 IBSymbolErrCnt;
  235. /* The following are new for IBA7220 */
  236. __u64 RxVL15DroppedPktCnt;
  237. __u64 RxOtherLocalPhyErrCnt;
  238. __u64 PcieRetryBufDiagQwordCnt;
  239. __u64 ExcessBufferOvflCnt;
  240. __u64 LocalLinkIntegrityErrCnt;
  241. __u64 RxVlErrCnt;
  242. __u64 RxDlidFltrCnt;
  243. __u64 Reserved8[7];
  244. __u64 PSStat;
  245. __u64 PSStart;
  246. __u64 PSInterval;
  247. __u64 PSRcvDataCount;
  248. __u64 PSRcvPktsCount;
  249. __u64 PSXmitDataCount;
  250. __u64 PSXmitPktsCount;
  251. __u64 PSXmitWaitCount;
  252. };
  253. #define IPATH_KREG_OFFSET(field) (offsetof( \
  254. struct _infinipath_do_not_use_kernel_regs, field) / sizeof(u64))
  255. #define IPATH_CREG_OFFSET(field) (offsetof( \
  256. struct _infinipath_do_not_use_counters, field) / sizeof(u64))
  257. static const struct ipath_kregs ipath_7220_kregs = {
  258. .kr_control = IPATH_KREG_OFFSET(Control),
  259. .kr_counterregbase = IPATH_KREG_OFFSET(CounterRegBase),
  260. .kr_debugportselect = IPATH_KREG_OFFSET(DebugPortSelect),
  261. .kr_errorclear = IPATH_KREG_OFFSET(ErrorClear),
  262. .kr_errormask = IPATH_KREG_OFFSET(ErrorMask),
  263. .kr_errorstatus = IPATH_KREG_OFFSET(ErrorStatus),
  264. .kr_extctrl = IPATH_KREG_OFFSET(ExtCtrl),
  265. .kr_extstatus = IPATH_KREG_OFFSET(ExtStatus),
  266. .kr_gpio_clear = IPATH_KREG_OFFSET(GPIOClear),
  267. .kr_gpio_mask = IPATH_KREG_OFFSET(GPIOMask),
  268. .kr_gpio_out = IPATH_KREG_OFFSET(GPIOOut),
  269. .kr_gpio_status = IPATH_KREG_OFFSET(GPIOStatus),
  270. .kr_hwdiagctrl = IPATH_KREG_OFFSET(HwDiagCtrl),
  271. .kr_hwerrclear = IPATH_KREG_OFFSET(HwErrClear),
  272. .kr_hwerrmask = IPATH_KREG_OFFSET(HwErrMask),
  273. .kr_hwerrstatus = IPATH_KREG_OFFSET(HwErrStatus),
  274. .kr_ibcctrl = IPATH_KREG_OFFSET(IBCCtrl),
  275. .kr_ibcstatus = IPATH_KREG_OFFSET(IBCStatus),
  276. .kr_intblocked = IPATH_KREG_OFFSET(IntBlocked),
  277. .kr_intclear = IPATH_KREG_OFFSET(IntClear),
  278. .kr_intmask = IPATH_KREG_OFFSET(IntMask),
  279. .kr_intstatus = IPATH_KREG_OFFSET(IntStatus),
  280. .kr_mdio = IPATH_KREG_OFFSET(MDIO),
  281. .kr_pagealign = IPATH_KREG_OFFSET(PageAlign),
  282. .kr_partitionkey = IPATH_KREG_OFFSET(RcvPartitionKey),
  283. .kr_portcnt = IPATH_KREG_OFFSET(PortCnt),
  284. .kr_rcvbthqp = IPATH_KREG_OFFSET(RcvBTHQP),
  285. .kr_rcvbufbase = IPATH_KREG_OFFSET(RcvBufBase),
  286. .kr_rcvbufsize = IPATH_KREG_OFFSET(RcvBufSize),
  287. .kr_rcvctrl = IPATH_KREG_OFFSET(RcvCtrl),
  288. .kr_rcvegrbase = IPATH_KREG_OFFSET(RcvEgrBase),
  289. .kr_rcvegrcnt = IPATH_KREG_OFFSET(RcvEgrCnt),
  290. .kr_rcvhdrcnt = IPATH_KREG_OFFSET(RcvHdrCnt),
  291. .kr_rcvhdrentsize = IPATH_KREG_OFFSET(RcvHdrEntSize),
  292. .kr_rcvhdrsize = IPATH_KREG_OFFSET(RcvHdrSize),
  293. .kr_rcvintmembase = IPATH_KREG_OFFSET(RxIntMemBase),
  294. .kr_rcvintmemsize = IPATH_KREG_OFFSET(RxIntMemSize),
  295. .kr_rcvtidbase = IPATH_KREG_OFFSET(RcvTIDBase),
  296. .kr_rcvtidcnt = IPATH_KREG_OFFSET(RcvTIDCnt),
  297. .kr_revision = IPATH_KREG_OFFSET(Revision),
  298. .kr_scratch = IPATH_KREG_OFFSET(Scratch),
  299. .kr_sendbuffererror = IPATH_KREG_OFFSET(SendBufferError),
  300. .kr_sendctrl = IPATH_KREG_OFFSET(SendCtrl),
  301. .kr_sendpioavailaddr = IPATH_KREG_OFFSET(SendAvailAddr),
  302. .kr_sendpiobufbase = IPATH_KREG_OFFSET(SendBufBase),
  303. .kr_sendpiobufcnt = IPATH_KREG_OFFSET(SendBufCnt),
  304. .kr_sendpiosize = IPATH_KREG_OFFSET(SendBufSize),
  305. .kr_sendregbase = IPATH_KREG_OFFSET(SendRegBase),
  306. .kr_txintmembase = IPATH_KREG_OFFSET(TxIntMemBase),
  307. .kr_txintmemsize = IPATH_KREG_OFFSET(TxIntMemSize),
  308. .kr_userregbase = IPATH_KREG_OFFSET(UserRegBase),
  309. .kr_xgxsconfig = IPATH_KREG_OFFSET(XGXSConfig),
  310. /* send dma related regs */
  311. .kr_senddmabase = IPATH_KREG_OFFSET(SendDmaBase),
  312. .kr_senddmalengen = IPATH_KREG_OFFSET(SendDmaLenGen),
  313. .kr_senddmatail = IPATH_KREG_OFFSET(SendDmaTail),
  314. .kr_senddmahead = IPATH_KREG_OFFSET(SendDmaHead),
  315. .kr_senddmaheadaddr = IPATH_KREG_OFFSET(SendDmaHeadAddr),
  316. .kr_senddmabufmask0 = IPATH_KREG_OFFSET(SendDmaBufMask0),
  317. .kr_senddmabufmask1 = IPATH_KREG_OFFSET(SendDmaBufMask1),
  318. .kr_senddmabufmask2 = IPATH_KREG_OFFSET(SendDmaBufMask2),
  319. .kr_senddmastatus = IPATH_KREG_OFFSET(SendDmaStatus),
  320. /* SerDes related regs */
  321. .kr_ibserdesctrl = IPATH_KREG_OFFSET(IBSerDesCtrl),
  322. .kr_ib_epbacc = IPATH_KREG_OFFSET(IbsdEpbAccCtl),
  323. .kr_ib_epbtrans = IPATH_KREG_OFFSET(IbsdEpbTransReg),
  324. .kr_pcie_epbacc = IPATH_KREG_OFFSET(PcieEpbAccCtl),
  325. .kr_pcie_epbtrans = IPATH_KREG_OFFSET(PcieEpbTransCtl),
  326. .kr_ib_ddsrxeq = IPATH_KREG_OFFSET(SerDesDDSRXEQ),
  327. /*
  328. * These should not be used directly via ipath_read_kreg64(),
  329. * use them with ipath_read_kreg64_port()
  330. */
  331. .kr_rcvhdraddr = IPATH_KREG_OFFSET(RcvHdrAddr0),
  332. .kr_rcvhdrtailaddr = IPATH_KREG_OFFSET(RcvHdrTailAddr0),
  333. /*
  334. * The rcvpktled register controls one of the debug port signals, so
  335. * a packet activity LED can be connected to it.
  336. */
  337. .kr_rcvpktledcnt = IPATH_KREG_OFFSET(RcvPktLEDCnt),
  338. .kr_pcierbuftestreg0 = IPATH_KREG_OFFSET(PCIeRBufTestReg0),
  339. .kr_pcierbuftestreg1 = IPATH_KREG_OFFSET(PCIeRBufTestReg1),
  340. .kr_hrtbt_guid = IPATH_KREG_OFFSET(HRTBT_GUID),
  341. .kr_ibcddrctrl = IPATH_KREG_OFFSET(IBCDDRCtrl),
  342. .kr_ibcddrstatus = IPATH_KREG_OFFSET(IBCDDRStatus),
  343. .kr_jintreload = IPATH_KREG_OFFSET(JIntReload)
  344. };
  345. static const struct ipath_cregs ipath_7220_cregs = {
  346. .cr_badformatcnt = IPATH_CREG_OFFSET(RxBadFormatCnt),
  347. .cr_erricrccnt = IPATH_CREG_OFFSET(RxICRCErrCnt),
  348. .cr_errlinkcnt = IPATH_CREG_OFFSET(RxLinkProblemCnt),
  349. .cr_errlpcrccnt = IPATH_CREG_OFFSET(RxLPCRCErrCnt),
  350. .cr_errpkey = IPATH_CREG_OFFSET(RxPKeyMismatchCnt),
  351. .cr_errrcvflowctrlcnt = IPATH_CREG_OFFSET(RxFlowCtrlErrCnt),
  352. .cr_err_rlencnt = IPATH_CREG_OFFSET(RxLenErrCnt),
  353. .cr_errslencnt = IPATH_CREG_OFFSET(TxLenErrCnt),
  354. .cr_errtidfull = IPATH_CREG_OFFSET(RxTIDFullErrCnt),
  355. .cr_errtidvalid = IPATH_CREG_OFFSET(RxTIDValidErrCnt),
  356. .cr_errvcrccnt = IPATH_CREG_OFFSET(RxVCRCErrCnt),
  357. .cr_ibstatuschange = IPATH_CREG_OFFSET(IBStatusChangeCnt),
  358. .cr_intcnt = IPATH_CREG_OFFSET(LBIntCnt),
  359. .cr_invalidrlencnt = IPATH_CREG_OFFSET(RxMaxMinLenErrCnt),
  360. .cr_invalidslencnt = IPATH_CREG_OFFSET(TxMaxMinLenErrCnt),
  361. .cr_lbflowstallcnt = IPATH_CREG_OFFSET(LBFlowStallCnt),
  362. .cr_pktrcvcnt = IPATH_CREG_OFFSET(RxDataPktCnt),
  363. .cr_pktrcvflowctrlcnt = IPATH_CREG_OFFSET(RxFlowPktCnt),
  364. .cr_pktsendcnt = IPATH_CREG_OFFSET(TxDataPktCnt),
  365. .cr_pktsendflowcnt = IPATH_CREG_OFFSET(TxFlowPktCnt),
  366. .cr_portovflcnt = IPATH_CREG_OFFSET(RxP0HdrEgrOvflCnt),
  367. .cr_rcvebpcnt = IPATH_CREG_OFFSET(RxEBPCnt),
  368. .cr_rcvovflcnt = IPATH_CREG_OFFSET(RxBufOvflCnt),
  369. .cr_senddropped = IPATH_CREG_OFFSET(TxDroppedPktCnt),
  370. .cr_sendstallcnt = IPATH_CREG_OFFSET(TxFlowStallCnt),
  371. .cr_sendunderruncnt = IPATH_CREG_OFFSET(TxUnderrunCnt),
  372. .cr_wordrcvcnt = IPATH_CREG_OFFSET(RxDwordCnt),
  373. .cr_wordsendcnt = IPATH_CREG_OFFSET(TxDwordCnt),
  374. .cr_unsupvlcnt = IPATH_CREG_OFFSET(TxUnsupVLErrCnt),
  375. .cr_rxdroppktcnt = IPATH_CREG_OFFSET(RxDroppedPktCnt),
  376. .cr_iblinkerrrecovcnt = IPATH_CREG_OFFSET(IBLinkErrRecoveryCnt),
  377. .cr_iblinkdowncnt = IPATH_CREG_OFFSET(IBLinkDownedCnt),
  378. .cr_ibsymbolerrcnt = IPATH_CREG_OFFSET(IBSymbolErrCnt),
  379. .cr_vl15droppedpktcnt = IPATH_CREG_OFFSET(RxVL15DroppedPktCnt),
  380. .cr_rxotherlocalphyerrcnt =
  381. IPATH_CREG_OFFSET(RxOtherLocalPhyErrCnt),
  382. .cr_excessbufferovflcnt = IPATH_CREG_OFFSET(ExcessBufferOvflCnt),
  383. .cr_locallinkintegrityerrcnt =
  384. IPATH_CREG_OFFSET(LocalLinkIntegrityErrCnt),
  385. .cr_rxvlerrcnt = IPATH_CREG_OFFSET(RxVlErrCnt),
  386. .cr_rxdlidfltrcnt = IPATH_CREG_OFFSET(RxDlidFltrCnt),
  387. .cr_psstat = IPATH_CREG_OFFSET(PSStat),
  388. .cr_psstart = IPATH_CREG_OFFSET(PSStart),
  389. .cr_psinterval = IPATH_CREG_OFFSET(PSInterval),
  390. .cr_psrcvdatacount = IPATH_CREG_OFFSET(PSRcvDataCount),
  391. .cr_psrcvpktscount = IPATH_CREG_OFFSET(PSRcvPktsCount),
  392. .cr_psxmitdatacount = IPATH_CREG_OFFSET(PSXmitDataCount),
  393. .cr_psxmitpktscount = IPATH_CREG_OFFSET(PSXmitPktsCount),
  394. .cr_psxmitwaitcount = IPATH_CREG_OFFSET(PSXmitWaitCount),
  395. };
  396. /* kr_control bits */
  397. #define INFINIPATH_C_RESET (1U<<7)
  398. /* kr_intstatus, kr_intclear, kr_intmask bits */
  399. #define INFINIPATH_I_RCVURG_MASK ((1ULL<<17)-1)
  400. #define INFINIPATH_I_RCVURG_SHIFT 32
  401. #define INFINIPATH_I_RCVAVAIL_MASK ((1ULL<<17)-1)
  402. #define INFINIPATH_I_RCVAVAIL_SHIFT 0
  403. #define INFINIPATH_I_SERDESTRIMDONE (1ULL<<27)
  404. /* kr_hwerrclear, kr_hwerrmask, kr_hwerrstatus, bits */
  405. #define INFINIPATH_HWE_PCIEMEMPARITYERR_MASK 0x00000000000000ffULL
  406. #define INFINIPATH_HWE_PCIEMEMPARITYERR_SHIFT 0
  407. #define INFINIPATH_HWE_PCIEPOISONEDTLP 0x0000000010000000ULL
  408. #define INFINIPATH_HWE_PCIECPLTIMEOUT 0x0000000020000000ULL
  409. #define INFINIPATH_HWE_PCIEBUSPARITYXTLH 0x0000000040000000ULL
  410. #define INFINIPATH_HWE_PCIEBUSPARITYXADM 0x0000000080000000ULL
  411. #define INFINIPATH_HWE_PCIEBUSPARITYRADM 0x0000000100000000ULL
  412. #define INFINIPATH_HWE_COREPLL_FBSLIP 0x0080000000000000ULL
  413. #define INFINIPATH_HWE_COREPLL_RFSLIP 0x0100000000000000ULL
  414. #define INFINIPATH_HWE_PCIE1PLLFAILED 0x0400000000000000ULL
  415. #define INFINIPATH_HWE_PCIE0PLLFAILED 0x0800000000000000ULL
  416. #define INFINIPATH_HWE_SERDESPLLFAILED 0x1000000000000000ULL
  417. /* specific to this chip */
  418. #define INFINIPATH_HWE_PCIECPLDATAQUEUEERR 0x0000000000000040ULL
  419. #define INFINIPATH_HWE_PCIECPLHDRQUEUEERR 0x0000000000000080ULL
  420. #define INFINIPATH_HWE_SDMAMEMREADERR 0x0000000010000000ULL
  421. #define INFINIPATH_HWE_CLK_UC_PLLNOTLOCKED 0x2000000000000000ULL
  422. #define INFINIPATH_HWE_PCIESERDESQ0PCLKNOTDETECT 0x0100000000000000ULL
  423. #define INFINIPATH_HWE_PCIESERDESQ1PCLKNOTDETECT 0x0200000000000000ULL
  424. #define INFINIPATH_HWE_PCIESERDESQ2PCLKNOTDETECT 0x0400000000000000ULL
  425. #define INFINIPATH_HWE_PCIESERDESQ3PCLKNOTDETECT 0x0800000000000000ULL
  426. #define INFINIPATH_HWE_DDSRXEQMEMORYPARITYERR 0x0000008000000000ULL
  427. #define INFINIPATH_HWE_IB_UC_MEMORYPARITYERR 0x0000004000000000ULL
  428. #define INFINIPATH_HWE_PCIE_UC_OCT0MEMORYPARITYERR 0x0000001000000000ULL
  429. #define INFINIPATH_HWE_PCIE_UC_OCT1MEMORYPARITYERR 0x0000002000000000ULL
  430. #define IBA7220_IBCS_LINKTRAININGSTATE_MASK 0x1F
  431. #define IBA7220_IBCS_LINKSTATE_SHIFT 5
  432. #define IBA7220_IBCS_LINKSPEED_SHIFT 8
  433. #define IBA7220_IBCS_LINKWIDTH_SHIFT 9
  434. #define IBA7220_IBCC_LINKINITCMD_MASK 0x7ULL
  435. #define IBA7220_IBCC_LINKCMD_SHIFT 19
  436. #define IBA7220_IBCC_MAXPKTLEN_SHIFT 21
  437. /* kr_ibcddrctrl bits */
  438. #define IBA7220_IBC_DLIDLMC_MASK 0xFFFFFFFFUL
  439. #define IBA7220_IBC_DLIDLMC_SHIFT 32
  440. #define IBA7220_IBC_HRTBT_MASK 3
  441. #define IBA7220_IBC_HRTBT_SHIFT 16
  442. #define IBA7220_IBC_HRTBT_ENB 0x10000UL
  443. #define IBA7220_IBC_LANE_REV_SUPPORTED (1<<8)
  444. #define IBA7220_IBC_LREV_MASK 1
  445. #define IBA7220_IBC_LREV_SHIFT 8
  446. #define IBA7220_IBC_RXPOL_MASK 1
  447. #define IBA7220_IBC_RXPOL_SHIFT 7
  448. #define IBA7220_IBC_WIDTH_SHIFT 5
  449. #define IBA7220_IBC_WIDTH_MASK 0x3
  450. #define IBA7220_IBC_WIDTH_1X_ONLY (0<<IBA7220_IBC_WIDTH_SHIFT)
  451. #define IBA7220_IBC_WIDTH_4X_ONLY (1<<IBA7220_IBC_WIDTH_SHIFT)
  452. #define IBA7220_IBC_WIDTH_AUTONEG (2<<IBA7220_IBC_WIDTH_SHIFT)
  453. #define IBA7220_IBC_SPEED_AUTONEG (1<<1)
  454. #define IBA7220_IBC_SPEED_SDR (1<<2)
  455. #define IBA7220_IBC_SPEED_DDR (1<<3)
  456. #define IBA7220_IBC_SPEED_AUTONEG_MASK (0x7<<1)
  457. #define IBA7220_IBC_IBTA_1_2_MASK (1)
  458. /* kr_ibcddrstatus */
  459. /* link latency shift is 0, don't bother defining */
  460. #define IBA7220_DDRSTAT_LINKLAT_MASK 0x3ffffff
  461. /* kr_extstatus bits */
  462. #define INFINIPATH_EXTS_FREQSEL 0x2
  463. #define INFINIPATH_EXTS_SERDESSEL 0x4
  464. #define INFINIPATH_EXTS_MEMBIST_ENDTEST 0x0000000000004000
  465. #define INFINIPATH_EXTS_MEMBIST_DISABLED 0x0000000000008000
  466. /* kr_xgxsconfig bits */
  467. #define INFINIPATH_XGXS_RESET 0x5ULL
  468. #define INFINIPATH_XGXS_FC_SAFE (1ULL<<63)
  469. /* kr_rcvpktledcnt */
  470. #define IBA7220_LEDBLINK_ON_SHIFT 32 /* 4ns period on after packet */
  471. #define IBA7220_LEDBLINK_OFF_SHIFT 0 /* 4ns period off before next on */
  472. #define _IPATH_GPIO_SDA_NUM 1
  473. #define _IPATH_GPIO_SCL_NUM 0
  474. #define IPATH_GPIO_SDA (1ULL << \
  475. (_IPATH_GPIO_SDA_NUM+INFINIPATH_EXTC_GPIOOE_SHIFT))
  476. #define IPATH_GPIO_SCL (1ULL << \
  477. (_IPATH_GPIO_SCL_NUM+INFINIPATH_EXTC_GPIOOE_SHIFT))
  478. #define IBA7220_R_INTRAVAIL_SHIFT 17
  479. #define IBA7220_R_TAILUPD_SHIFT 35
  480. #define IBA7220_R_PORTCFG_SHIFT 36
  481. #define INFINIPATH_JINT_PACKETSHIFT 16
  482. #define INFINIPATH_JINT_DEFAULT_IDLE_TICKS 0
  483. #define INFINIPATH_JINT_DEFAULT_MAX_PACKETS 0
  484. #define IBA7220_HDRHEAD_PKTINT_SHIFT 32 /* interrupt cnt in upper 32 bits */
  485. /*
  486. * the size bits give us 2^N, in KB units. 0 marks as invalid,
  487. * and 7 is reserved. We currently use only 2KB and 4KB
  488. */
  489. #define IBA7220_TID_SZ_SHIFT 37 /* shift to 3bit size selector */
  490. #define IBA7220_TID_SZ_2K (1UL<<IBA7220_TID_SZ_SHIFT) /* 2KB */
  491. #define IBA7220_TID_SZ_4K (2UL<<IBA7220_TID_SZ_SHIFT) /* 4KB */
  492. #define IBA7220_TID_PA_SHIFT 11U /* TID addr in chip stored w/o low bits */
  493. #define IPATH_AUTONEG_TRIES 5 /* sequential retries to negotiate DDR */
  494. static char int_type[16] = "auto";
  495. module_param_string(interrupt_type, int_type, sizeof(int_type), 0444);
  496. MODULE_PARM_DESC(int_type, " interrupt_type=auto|force_msi|force_intx\n");
  497. /* packet rate matching delay; chip has support */
  498. static u8 rate_to_delay[2][2] = {
  499. /* 1x, 4x */
  500. { 8, 2 }, /* SDR */
  501. { 4, 1 } /* DDR */
  502. };
  503. /* 7220 specific hardware errors... */
  504. static const struct ipath_hwerror_msgs ipath_7220_hwerror_msgs[] = {
  505. INFINIPATH_HWE_MSG(PCIEPOISONEDTLP, "PCIe Poisoned TLP"),
  506. INFINIPATH_HWE_MSG(PCIECPLTIMEOUT, "PCIe completion timeout"),
  507. /*
  508. * In practice, it's unlikely wthat we'll see PCIe PLL, or bus
  509. * parity or memory parity error failures, because most likely we
  510. * won't be able to talk to the core of the chip. Nonetheless, we
  511. * might see them, if they are in parts of the PCIe core that aren't
  512. * essential.
  513. */
  514. INFINIPATH_HWE_MSG(PCIE1PLLFAILED, "PCIePLL1"),
  515. INFINIPATH_HWE_MSG(PCIE0PLLFAILED, "PCIePLL0"),
  516. INFINIPATH_HWE_MSG(PCIEBUSPARITYXTLH, "PCIe XTLH core parity"),
  517. INFINIPATH_HWE_MSG(PCIEBUSPARITYXADM, "PCIe ADM TX core parity"),
  518. INFINIPATH_HWE_MSG(PCIEBUSPARITYRADM, "PCIe ADM RX core parity"),
  519. INFINIPATH_HWE_MSG(RXDSYNCMEMPARITYERR, "Rx Dsync"),
  520. INFINIPATH_HWE_MSG(SERDESPLLFAILED, "SerDes PLL"),
  521. INFINIPATH_HWE_MSG(PCIECPLDATAQUEUEERR, "PCIe cpl header queue"),
  522. INFINIPATH_HWE_MSG(PCIECPLHDRQUEUEERR, "PCIe cpl data queue"),
  523. INFINIPATH_HWE_MSG(SDMAMEMREADERR, "Send DMA memory read"),
  524. INFINIPATH_HWE_MSG(CLK_UC_PLLNOTLOCKED, "uC PLL clock not locked"),
  525. INFINIPATH_HWE_MSG(PCIESERDESQ0PCLKNOTDETECT,
  526. "PCIe serdes Q0 no clock"),
  527. INFINIPATH_HWE_MSG(PCIESERDESQ1PCLKNOTDETECT,
  528. "PCIe serdes Q1 no clock"),
  529. INFINIPATH_HWE_MSG(PCIESERDESQ2PCLKNOTDETECT,
  530. "PCIe serdes Q2 no clock"),
  531. INFINIPATH_HWE_MSG(PCIESERDESQ3PCLKNOTDETECT,
  532. "PCIe serdes Q3 no clock"),
  533. INFINIPATH_HWE_MSG(DDSRXEQMEMORYPARITYERR,
  534. "DDS RXEQ memory parity"),
  535. INFINIPATH_HWE_MSG(IB_UC_MEMORYPARITYERR, "IB uC memory parity"),
  536. INFINIPATH_HWE_MSG(PCIE_UC_OCT0MEMORYPARITYERR,
  537. "PCIe uC oct0 memory parity"),
  538. INFINIPATH_HWE_MSG(PCIE_UC_OCT1MEMORYPARITYERR,
  539. "PCIe uC oct1 memory parity"),
  540. };
  541. static void autoneg_work(struct work_struct *);
  542. /*
  543. * the offset is different for different configured port numbers, since
  544. * port0 is fixed in size, but others can vary. Make it a function to
  545. * make the issue more obvious.
  546. */
  547. static inline u32 port_egrtid_idx(struct ipath_devdata *dd, unsigned port)
  548. {
  549. return port ? dd->ipath_p0_rcvegrcnt +
  550. (port-1) * dd->ipath_rcvegrcnt : 0;
  551. }
  552. static void ipath_7220_txe_recover(struct ipath_devdata *dd)
  553. {
  554. ++ipath_stats.sps_txeparity;
  555. dev_info(&dd->pcidev->dev,
  556. "Recovering from TXE PIO parity error\n");
  557. ipath_disarm_senderrbufs(dd, 1);
  558. }
  559. /**
  560. * ipath_7220_handle_hwerrors - display hardware errors.
  561. * @dd: the infinipath device
  562. * @msg: the output buffer
  563. * @msgl: the size of the output buffer
  564. *
  565. * Use same msg buffer as regular errors to avoid excessive stack
  566. * use. Most hardware errors are catastrophic, but for right now,
  567. * we'll print them and continue. We reuse the same message buffer as
  568. * ipath_handle_errors() to avoid excessive stack usage.
  569. */
  570. static void ipath_7220_handle_hwerrors(struct ipath_devdata *dd, char *msg,
  571. size_t msgl)
  572. {
  573. ipath_err_t hwerrs;
  574. u32 bits, ctrl;
  575. int isfatal = 0;
  576. char bitsmsg[64];
  577. int log_idx;
  578. hwerrs = ipath_read_kreg64(dd, dd->ipath_kregs->kr_hwerrstatus);
  579. if (!hwerrs) {
  580. /*
  581. * better than printing cofusing messages
  582. * This seems to be related to clearing the crc error, or
  583. * the pll error during init.
  584. */
  585. ipath_cdbg(VERBOSE, "Called but no hardware errors set\n");
  586. goto bail;
  587. } else if (hwerrs == ~0ULL) {
  588. ipath_dev_err(dd, "Read of hardware error status failed "
  589. "(all bits set); ignoring\n");
  590. goto bail;
  591. }
  592. ipath_stats.sps_hwerrs++;
  593. /*
  594. * Always clear the error status register, except MEMBISTFAIL,
  595. * regardless of whether we continue or stop using the chip.
  596. * We want that set so we know it failed, even across driver reload.
  597. * We'll still ignore it in the hwerrmask. We do this partly for
  598. * diagnostics, but also for support.
  599. */
  600. ipath_write_kreg(dd, dd->ipath_kregs->kr_hwerrclear,
  601. hwerrs&~INFINIPATH_HWE_MEMBISTFAILED);
  602. hwerrs &= dd->ipath_hwerrmask;
  603. /* We log some errors to EEPROM, check if we have any of those. */
  604. for (log_idx = 0; log_idx < IPATH_EEP_LOG_CNT; ++log_idx)
  605. if (hwerrs & dd->ipath_eep_st_masks[log_idx].hwerrs_to_log)
  606. ipath_inc_eeprom_err(dd, log_idx, 1);
  607. /*
  608. * Make sure we get this much out, unless told to be quiet,
  609. * or it's occurred within the last 5 seconds.
  610. */
  611. if ((hwerrs & ~(dd->ipath_lasthwerror |
  612. ((INFINIPATH_HWE_TXEMEMPARITYERR_PIOBUF |
  613. INFINIPATH_HWE_TXEMEMPARITYERR_PIOPBC)
  614. << INFINIPATH_HWE_TXEMEMPARITYERR_SHIFT))) ||
  615. (ipath_debug & __IPATH_VERBDBG))
  616. dev_info(&dd->pcidev->dev, "Hardware error: hwerr=0x%llx "
  617. "(cleared)\n", (unsigned long long) hwerrs);
  618. dd->ipath_lasthwerror |= hwerrs;
  619. if (hwerrs & ~dd->ipath_hwe_bitsextant)
  620. ipath_dev_err(dd, "hwerror interrupt with unknown errors "
  621. "%llx set\n", (unsigned long long)
  622. (hwerrs & ~dd->ipath_hwe_bitsextant));
  623. if (hwerrs & INFINIPATH_HWE_IB_UC_MEMORYPARITYERR)
  624. ipath_sd7220_clr_ibpar(dd);
  625. ctrl = ipath_read_kreg32(dd, dd->ipath_kregs->kr_control);
  626. if ((ctrl & INFINIPATH_C_FREEZEMODE) && !ipath_diag_inuse) {
  627. /*
  628. * Parity errors in send memory are recoverable,
  629. * just cancel the send (if indicated in * sendbuffererror),
  630. * count the occurrence, unfreeze (if no other handled
  631. * hardware error bits are set), and continue.
  632. */
  633. if (hwerrs & ((INFINIPATH_HWE_TXEMEMPARITYERR_PIOBUF |
  634. INFINIPATH_HWE_TXEMEMPARITYERR_PIOPBC)
  635. << INFINIPATH_HWE_TXEMEMPARITYERR_SHIFT)) {
  636. ipath_7220_txe_recover(dd);
  637. hwerrs &= ~((INFINIPATH_HWE_TXEMEMPARITYERR_PIOBUF |
  638. INFINIPATH_HWE_TXEMEMPARITYERR_PIOPBC)
  639. << INFINIPATH_HWE_TXEMEMPARITYERR_SHIFT);
  640. if (!hwerrs) {
  641. /* else leave in freeze mode */
  642. ipath_write_kreg(dd,
  643. dd->ipath_kregs->kr_control,
  644. dd->ipath_control);
  645. goto bail;
  646. }
  647. }
  648. if (hwerrs) {
  649. /*
  650. * If any set that we aren't ignoring only make the
  651. * complaint once, in case it's stuck or recurring,
  652. * and we get here multiple times
  653. * Force link down, so switch knows, and
  654. * LEDs are turned off.
  655. */
  656. if (dd->ipath_flags & IPATH_INITTED) {
  657. ipath_set_linkstate(dd, IPATH_IB_LINKDOWN);
  658. ipath_setup_7220_setextled(dd,
  659. INFINIPATH_IBCS_L_STATE_DOWN,
  660. INFINIPATH_IBCS_LT_STATE_DISABLED);
  661. ipath_dev_err(dd, "Fatal Hardware Error "
  662. "(freeze mode), no longer"
  663. " usable, SN %.16s\n",
  664. dd->ipath_serial);
  665. isfatal = 1;
  666. }
  667. /*
  668. * Mark as having had an error for driver, and also
  669. * for /sys and status word mapped to user programs.
  670. * This marks unit as not usable, until reset.
  671. */
  672. *dd->ipath_statusp &= ~IPATH_STATUS_IB_READY;
  673. *dd->ipath_statusp |= IPATH_STATUS_HWERROR;
  674. dd->ipath_flags &= ~IPATH_INITTED;
  675. } else {
  676. ipath_dbg("Clearing freezemode on ignored hardware "
  677. "error\n");
  678. ipath_clear_freeze(dd);
  679. }
  680. }
  681. *msg = '\0';
  682. if (hwerrs & INFINIPATH_HWE_MEMBISTFAILED) {
  683. strlcat(msg, "[Memory BIST test failed, "
  684. "InfiniPath hardware unusable]", msgl);
  685. /* ignore from now on, so disable until driver reloaded */
  686. *dd->ipath_statusp |= IPATH_STATUS_HWERROR;
  687. dd->ipath_hwerrmask &= ~INFINIPATH_HWE_MEMBISTFAILED;
  688. ipath_write_kreg(dd, dd->ipath_kregs->kr_hwerrmask,
  689. dd->ipath_hwerrmask);
  690. }
  691. ipath_format_hwerrors(hwerrs,
  692. ipath_7220_hwerror_msgs,
  693. ARRAY_SIZE(ipath_7220_hwerror_msgs),
  694. msg, msgl);
  695. if (hwerrs & (INFINIPATH_HWE_PCIEMEMPARITYERR_MASK
  696. << INFINIPATH_HWE_PCIEMEMPARITYERR_SHIFT)) {
  697. bits = (u32) ((hwerrs >>
  698. INFINIPATH_HWE_PCIEMEMPARITYERR_SHIFT) &
  699. INFINIPATH_HWE_PCIEMEMPARITYERR_MASK);
  700. snprintf(bitsmsg, sizeof bitsmsg,
  701. "[PCIe Mem Parity Errs %x] ", bits);
  702. strlcat(msg, bitsmsg, msgl);
  703. }
  704. #define _IPATH_PLL_FAIL (INFINIPATH_HWE_COREPLL_FBSLIP | \
  705. INFINIPATH_HWE_COREPLL_RFSLIP)
  706. if (hwerrs & _IPATH_PLL_FAIL) {
  707. snprintf(bitsmsg, sizeof bitsmsg,
  708. "[PLL failed (%llx), InfiniPath hardware unusable]",
  709. (unsigned long long) hwerrs & _IPATH_PLL_FAIL);
  710. strlcat(msg, bitsmsg, msgl);
  711. /* ignore from now on, so disable until driver reloaded */
  712. dd->ipath_hwerrmask &= ~(hwerrs & _IPATH_PLL_FAIL);
  713. ipath_write_kreg(dd, dd->ipath_kregs->kr_hwerrmask,
  714. dd->ipath_hwerrmask);
  715. }
  716. if (hwerrs & INFINIPATH_HWE_SERDESPLLFAILED) {
  717. /*
  718. * If it occurs, it is left masked since the eternal
  719. * interface is unused.
  720. */
  721. dd->ipath_hwerrmask &= ~INFINIPATH_HWE_SERDESPLLFAILED;
  722. ipath_write_kreg(dd, dd->ipath_kregs->kr_hwerrmask,
  723. dd->ipath_hwerrmask);
  724. }
  725. ipath_dev_err(dd, "%s hardware error\n", msg);
  726. /*
  727. * For /sys status file. if no trailing } is copied, we'll
  728. * know it was truncated.
  729. */
  730. if (isfatal && !ipath_diag_inuse && dd->ipath_freezemsg)
  731. snprintf(dd->ipath_freezemsg, dd->ipath_freezelen,
  732. "{%s}", msg);
  733. bail:;
  734. }
  735. /**
  736. * ipath_7220_boardname - fill in the board name
  737. * @dd: the infinipath device
  738. * @name: the output buffer
  739. * @namelen: the size of the output buffer
  740. *
  741. * info is based on the board revision register
  742. */
  743. static int ipath_7220_boardname(struct ipath_devdata *dd, char *name,
  744. size_t namelen)
  745. {
  746. char *n = NULL;
  747. u8 boardrev = dd->ipath_boardrev;
  748. int ret;
  749. if (boardrev == 15) {
  750. /*
  751. * Emulator sometimes comes up all-ones, rather than zero.
  752. */
  753. boardrev = 0;
  754. dd->ipath_boardrev = boardrev;
  755. }
  756. switch (boardrev) {
  757. case 0:
  758. n = "InfiniPath_7220_Emulation";
  759. break;
  760. case 1:
  761. n = "InfiniPath_QLE7240";
  762. break;
  763. case 2:
  764. n = "InfiniPath_QLE7280";
  765. break;
  766. case 3:
  767. n = "InfiniPath_QLE7242";
  768. break;
  769. case 4:
  770. n = "InfiniPath_QEM7240";
  771. break;
  772. case 5:
  773. n = "InfiniPath_QMI7240";
  774. break;
  775. case 6:
  776. n = "InfiniPath_QMI7264";
  777. break;
  778. case 7:
  779. n = "InfiniPath_QMH7240";
  780. break;
  781. case 8:
  782. n = "InfiniPath_QME7240";
  783. break;
  784. case 9:
  785. n = "InfiniPath_QLE7250";
  786. break;
  787. case 10:
  788. n = "InfiniPath_QLE7290";
  789. break;
  790. case 11:
  791. n = "InfiniPath_QEM7250";
  792. break;
  793. case 12:
  794. n = "InfiniPath_QLE-Bringup";
  795. break;
  796. default:
  797. ipath_dev_err(dd,
  798. "Don't yet know about board with ID %u\n",
  799. boardrev);
  800. snprintf(name, namelen, "Unknown_InfiniPath_PCIe_%u",
  801. boardrev);
  802. break;
  803. }
  804. if (n)
  805. snprintf(name, namelen, "%s", n);
  806. if (dd->ipath_majrev != 5 || !dd->ipath_minrev ||
  807. dd->ipath_minrev > 2) {
  808. ipath_dev_err(dd, "Unsupported InfiniPath hardware "
  809. "revision %u.%u!\n",
  810. dd->ipath_majrev, dd->ipath_minrev);
  811. ret = 1;
  812. } else if (dd->ipath_minrev == 1) {
  813. /* Rev1 chips are prototype. Complain, but allow use */
  814. ipath_dev_err(dd, "Unsupported hardware "
  815. "revision %u.%u, Contact support@qlogic.com\n",
  816. dd->ipath_majrev, dd->ipath_minrev);
  817. ret = 0;
  818. } else
  819. ret = 0;
  820. /*
  821. * Set here not in ipath_init_*_funcs because we have to do
  822. * it after we can read chip registers.
  823. */
  824. dd->ipath_ureg_align = 0x10000; /* 64KB alignment */
  825. return ret;
  826. }
  827. /**
  828. * ipath_7220_init_hwerrors - enable hardware errors
  829. * @dd: the infinipath device
  830. *
  831. * now that we have finished initializing everything that might reasonably
  832. * cause a hardware error, and cleared those errors bits as they occur,
  833. * we can enable hardware errors in the mask (potentially enabling
  834. * freeze mode), and enable hardware errors as errors (along with
  835. * everything else) in errormask
  836. */
  837. static void ipath_7220_init_hwerrors(struct ipath_devdata *dd)
  838. {
  839. ipath_err_t val;
  840. u64 extsval;
  841. extsval = ipath_read_kreg64(dd, dd->ipath_kregs->kr_extstatus);
  842. if (!(extsval & (INFINIPATH_EXTS_MEMBIST_ENDTEST |
  843. INFINIPATH_EXTS_MEMBIST_DISABLED)))
  844. ipath_dev_err(dd, "MemBIST did not complete!\n");
  845. if (extsval & INFINIPATH_EXTS_MEMBIST_DISABLED)
  846. dev_info(&dd->pcidev->dev, "MemBIST is disabled.\n");
  847. val = ~0ULL; /* barring bugs, all hwerrors become interrupts, */
  848. if (!dd->ipath_boardrev) /* no PLL for Emulator */
  849. val &= ~INFINIPATH_HWE_SERDESPLLFAILED;
  850. if (dd->ipath_minrev == 1)
  851. val &= ~(1ULL << 42); /* TXE LaunchFIFO Parity rev1 issue */
  852. val &= ~INFINIPATH_HWE_IB_UC_MEMORYPARITYERR;
  853. dd->ipath_hwerrmask = val;
  854. /*
  855. * special trigger "error" is for debugging purposes. It
  856. * works around a processor/chipset problem. The error
  857. * interrupt allows us to count occurrences, but we don't
  858. * want to pay the overhead for normal use. Emulation only
  859. */
  860. if (!dd->ipath_boardrev)
  861. dd->ipath_maskederrs = INFINIPATH_E_SENDSPECIALTRIGGER;
  862. }
  863. /*
  864. * All detailed interaction with the SerDes has been moved to ipath_sd7220.c
  865. *
  866. * The portion of IBA7220-specific bringup_serdes() that actually deals with
  867. * registers and memory within the SerDes itself is ipath_sd7220_init().
  868. */
  869. /**
  870. * ipath_7220_bringup_serdes - bring up the serdes
  871. * @dd: the infinipath device
  872. */
  873. static int ipath_7220_bringup_serdes(struct ipath_devdata *dd)
  874. {
  875. int ret = 0;
  876. u64 val, prev_val, guid;
  877. int was_reset; /* Note whether uC was reset */
  878. ipath_dbg("Trying to bringup serdes\n");
  879. if (ipath_read_kreg64(dd, dd->ipath_kregs->kr_hwerrstatus) &
  880. INFINIPATH_HWE_SERDESPLLFAILED) {
  881. ipath_dbg("At start, serdes PLL failed bit set "
  882. "in hwerrstatus, clearing and continuing\n");
  883. ipath_write_kreg(dd, dd->ipath_kregs->kr_hwerrclear,
  884. INFINIPATH_HWE_SERDESPLLFAILED);
  885. }
  886. if (!dd->ipath_ibcddrctrl) {
  887. /* not on re-init after reset */
  888. dd->ipath_ibcddrctrl =
  889. ipath_read_kreg64(dd, dd->ipath_kregs->kr_ibcddrctrl);
  890. if (dd->ipath_link_speed_enabled ==
  891. (IPATH_IB_SDR | IPATH_IB_DDR))
  892. dd->ipath_ibcddrctrl |=
  893. IBA7220_IBC_SPEED_AUTONEG_MASK |
  894. IBA7220_IBC_IBTA_1_2_MASK;
  895. else
  896. dd->ipath_ibcddrctrl |=
  897. dd->ipath_link_speed_enabled == IPATH_IB_DDR
  898. ? IBA7220_IBC_SPEED_DDR :
  899. IBA7220_IBC_SPEED_SDR;
  900. if ((dd->ipath_link_width_enabled & (IB_WIDTH_1X |
  901. IB_WIDTH_4X)) == (IB_WIDTH_1X | IB_WIDTH_4X))
  902. dd->ipath_ibcddrctrl |= IBA7220_IBC_WIDTH_AUTONEG;
  903. else
  904. dd->ipath_ibcddrctrl |=
  905. dd->ipath_link_width_enabled == IB_WIDTH_4X
  906. ? IBA7220_IBC_WIDTH_4X_ONLY :
  907. IBA7220_IBC_WIDTH_1X_ONLY;
  908. /* always enable these on driver reload, not sticky */
  909. dd->ipath_ibcddrctrl |=
  910. IBA7220_IBC_RXPOL_MASK << IBA7220_IBC_RXPOL_SHIFT;
  911. dd->ipath_ibcddrctrl |=
  912. IBA7220_IBC_HRTBT_MASK << IBA7220_IBC_HRTBT_SHIFT;
  913. /*
  914. * automatic lane reversal detection for receive
  915. * doesn't work correctly in rev 1, so disable it
  916. * on that rev, otherwise enable (disabling not
  917. * sticky across reload for >rev1)
  918. */
  919. if (dd->ipath_minrev == 1)
  920. dd->ipath_ibcddrctrl &=
  921. ~IBA7220_IBC_LANE_REV_SUPPORTED;
  922. else
  923. dd->ipath_ibcddrctrl |=
  924. IBA7220_IBC_LANE_REV_SUPPORTED;
  925. }
  926. ipath_write_kreg(dd, dd->ipath_kregs->kr_ibcddrctrl,
  927. dd->ipath_ibcddrctrl);
  928. ipath_write_kreg(dd, IPATH_KREG_OFFSET(IBNCModeCtrl), 0Ull);
  929. /* IBA7220 has SERDES MPU reset in D0 of what _was_ IBPLLCfg */
  930. val = ipath_read_kreg64(dd, dd->ipath_kregs->kr_ibserdesctrl);
  931. /* remember if uC was in Reset or not, for dactrim */
  932. was_reset = (val & 1);
  933. ipath_cdbg(VERBOSE, "IBReset %s xgxsconfig %llx\n",
  934. was_reset ? "Asserted" : "Negated", (unsigned long long)
  935. ipath_read_kreg64(dd, dd->ipath_kregs->kr_xgxsconfig));
  936. if (dd->ipath_boardrev) {
  937. /*
  938. * Hardware is not emulator, and may have been reset. Init it.
  939. * Below will release reset, but needs to know if chip was
  940. * originally in reset, to only trim DACs on first time
  941. * after chip reset or powercycle (not driver reload)
  942. */
  943. ret = ipath_sd7220_init(dd, was_reset);
  944. }
  945. val = ipath_read_kreg64(dd, dd->ipath_kregs->kr_xgxsconfig);
  946. prev_val = val;
  947. val |= INFINIPATH_XGXS_FC_SAFE;
  948. if (val != prev_val) {
  949. ipath_write_kreg(dd, dd->ipath_kregs->kr_xgxsconfig, val);
  950. ipath_read_kreg32(dd, dd->ipath_kregs->kr_scratch);
  951. }
  952. if (val & INFINIPATH_XGXS_RESET)
  953. val &= ~INFINIPATH_XGXS_RESET;
  954. if (val != prev_val)
  955. ipath_write_kreg(dd, dd->ipath_kregs->kr_xgxsconfig, val);
  956. ipath_cdbg(VERBOSE, "done: xgxs=%llx from %llx\n",
  957. (unsigned long long)
  958. ipath_read_kreg64(dd, dd->ipath_kregs->kr_xgxsconfig),
  959. prev_val);
  960. guid = be64_to_cpu(dd->ipath_guid);
  961. if (!guid) {
  962. /* have to have something, so use likely unique tsc */
  963. guid = get_cycles();
  964. ipath_dbg("No GUID for heartbeat, faking %llx\n",
  965. (unsigned long long)guid);
  966. } else
  967. ipath_cdbg(VERBOSE, "Wrote %llX to HRTBT_GUID\n", guid);
  968. ipath_write_kreg(dd, dd->ipath_kregs->kr_hrtbt_guid, guid);
  969. return ret;
  970. }
  971. static void ipath_7220_config_jint(struct ipath_devdata *dd,
  972. u16 idle_ticks, u16 max_packets)
  973. {
  974. /*
  975. * We can request a receive interrupt for 1 or more packets
  976. * from current offset.
  977. */
  978. if (idle_ticks == 0 || max_packets == 0)
  979. /* interrupt after one packet if no mitigation */
  980. dd->ipath_rhdrhead_intr_off =
  981. 1ULL << IBA7220_HDRHEAD_PKTINT_SHIFT;
  982. else
  983. /* Turn off RcvHdrHead interrupts if using mitigation */
  984. dd->ipath_rhdrhead_intr_off = 0ULL;
  985. /* refresh kernel RcvHdrHead registers... */
  986. ipath_write_ureg(dd, ur_rcvhdrhead,
  987. dd->ipath_rhdrhead_intr_off |
  988. dd->ipath_pd[0]->port_head, 0);
  989. dd->ipath_jint_max_packets = max_packets;
  990. dd->ipath_jint_idle_ticks = idle_ticks;
  991. ipath_write_kreg(dd, dd->ipath_kregs->kr_jintreload,
  992. ((u64) max_packets << INFINIPATH_JINT_PACKETSHIFT) |
  993. idle_ticks);
  994. }
  995. /**
  996. * ipath_7220_quiet_serdes - set serdes to txidle
  997. * @dd: the infinipath device
  998. * Called when driver is being unloaded
  999. */
  1000. static void ipath_7220_quiet_serdes(struct ipath_devdata *dd)
  1001. {
  1002. u64 val;
  1003. dd->ipath_flags &= ~IPATH_IB_AUTONEG_INPROG;
  1004. wake_up(&dd->ipath_autoneg_wait);
  1005. cancel_delayed_work(&dd->ipath_autoneg_work);
  1006. flush_scheduled_work();
  1007. ipath_shutdown_relock_poll(dd);
  1008. val = ipath_read_kreg64(dd, dd->ipath_kregs->kr_xgxsconfig);
  1009. val |= INFINIPATH_XGXS_RESET;
  1010. ipath_write_kreg(dd, dd->ipath_kregs->kr_xgxsconfig, val);
  1011. }
  1012. static int ipath_7220_intconfig(struct ipath_devdata *dd)
  1013. {
  1014. ipath_7220_config_jint(dd, dd->ipath_jint_idle_ticks,
  1015. dd->ipath_jint_max_packets);
  1016. return 0;
  1017. }
  1018. /**
  1019. * ipath_setup_7220_setextled - set the state of the two external LEDs
  1020. * @dd: the infinipath device
  1021. * @lst: the L state
  1022. * @ltst: the LT state
  1023. *
  1024. * These LEDs indicate the physical and logical state of IB link.
  1025. * For this chip (at least with recommended board pinouts), LED1
  1026. * is Yellow (logical state) and LED2 is Green (physical state),
  1027. *
  1028. * Note: We try to match the Mellanox HCA LED behavior as best
  1029. * we can. Green indicates physical link state is OK (something is
  1030. * plugged in, and we can train).
  1031. * Amber indicates the link is logically up (ACTIVE).
  1032. * Mellanox further blinks the amber LED to indicate data packet
  1033. * activity, but we have no hardware support for that, so it would
  1034. * require waking up every 10-20 msecs and checking the counters
  1035. * on the chip, and then turning the LED off if appropriate. That's
  1036. * visible overhead, so not something we will do.
  1037. *
  1038. */
  1039. static void ipath_setup_7220_setextled(struct ipath_devdata *dd, u64 lst,
  1040. u64 ltst)
  1041. {
  1042. u64 extctl, ledblink = 0;
  1043. unsigned long flags = 0;
  1044. /* the diags use the LED to indicate diag info, so we leave
  1045. * the external LED alone when the diags are running */
  1046. if (ipath_diag_inuse)
  1047. return;
  1048. /* Allow override of LED display for, e.g. Locating system in rack */
  1049. if (dd->ipath_led_override) {
  1050. ltst = (dd->ipath_led_override & IPATH_LED_PHYS)
  1051. ? INFINIPATH_IBCS_LT_STATE_LINKUP
  1052. : INFINIPATH_IBCS_LT_STATE_DISABLED;
  1053. lst = (dd->ipath_led_override & IPATH_LED_LOG)
  1054. ? INFINIPATH_IBCS_L_STATE_ACTIVE
  1055. : INFINIPATH_IBCS_L_STATE_DOWN;
  1056. }
  1057. spin_lock_irqsave(&dd->ipath_gpio_lock, flags);
  1058. extctl = dd->ipath_extctrl & ~(INFINIPATH_EXTC_LED1PRIPORT_ON |
  1059. INFINIPATH_EXTC_LED2PRIPORT_ON);
  1060. if (ltst == INFINIPATH_IBCS_LT_STATE_LINKUP) {
  1061. extctl |= INFINIPATH_EXTC_LED1PRIPORT_ON;
  1062. /*
  1063. * counts are in chip clock (4ns) periods.
  1064. * This is 1/16 sec (66.6ms) on,
  1065. * 3/16 sec (187.5 ms) off, with packets rcvd
  1066. */
  1067. ledblink = ((66600*1000UL/4) << IBA7220_LEDBLINK_ON_SHIFT)
  1068. | ((187500*1000UL/4) << IBA7220_LEDBLINK_OFF_SHIFT);
  1069. }
  1070. if (lst == INFINIPATH_IBCS_L_STATE_ACTIVE)
  1071. extctl |= INFINIPATH_EXTC_LED2PRIPORT_ON;
  1072. dd->ipath_extctrl = extctl;
  1073. ipath_write_kreg(dd, dd->ipath_kregs->kr_extctrl, extctl);
  1074. spin_unlock_irqrestore(&dd->ipath_gpio_lock, flags);
  1075. if (ledblink) /* blink the LED on packet receive */
  1076. ipath_write_kreg(dd, dd->ipath_kregs->kr_rcvpktledcnt,
  1077. ledblink);
  1078. }
  1079. /*
  1080. * Similar to pci_intx(pdev, 1), except that we make sure
  1081. * msi is off...
  1082. */
  1083. static void ipath_enable_intx(struct pci_dev *pdev)
  1084. {
  1085. u16 cw, new;
  1086. int pos;
  1087. /* first, turn on INTx */
  1088. pci_read_config_word(pdev, PCI_COMMAND, &cw);
  1089. new = cw & ~PCI_COMMAND_INTX_DISABLE;
  1090. if (new != cw)
  1091. pci_write_config_word(pdev, PCI_COMMAND, new);
  1092. /* then turn off MSI */
  1093. pos = pci_find_capability(pdev, PCI_CAP_ID_MSI);
  1094. if (pos) {
  1095. pci_read_config_word(pdev, pos + PCI_MSI_FLAGS, &cw);
  1096. new = cw & ~PCI_MSI_FLAGS_ENABLE;
  1097. if (new != cw)
  1098. pci_write_config_word(pdev, pos + PCI_MSI_FLAGS, new);
  1099. }
  1100. }
  1101. static int ipath_msi_enabled(struct pci_dev *pdev)
  1102. {
  1103. int pos, ret = 0;
  1104. pos = pci_find_capability(pdev, PCI_CAP_ID_MSI);
  1105. if (pos) {
  1106. u16 cw;
  1107. pci_read_config_word(pdev, pos + PCI_MSI_FLAGS, &cw);
  1108. ret = !!(cw & PCI_MSI_FLAGS_ENABLE);
  1109. }
  1110. return ret;
  1111. }
  1112. /*
  1113. * disable msi interrupt if enabled, and clear the flag.
  1114. * flag is used primarily for the fallback to INTx, but
  1115. * is also used in reinit after reset as a flag.
  1116. */
  1117. static void ipath_7220_nomsi(struct ipath_devdata *dd)
  1118. {
  1119. dd->ipath_msi_lo = 0;
  1120. if (ipath_msi_enabled(dd->pcidev)) {
  1121. /*
  1122. * free, but don't zero; later kernels require
  1123. * it be freed before disable_msi, so the intx
  1124. * setup has to request it again.
  1125. */
  1126. if (dd->ipath_irq)
  1127. free_irq(dd->ipath_irq, dd);
  1128. pci_disable_msi(dd->pcidev);
  1129. }
  1130. }
  1131. /*
  1132. * ipath_setup_7220_cleanup - clean up any per-chip chip-specific stuff
  1133. * @dd: the infinipath device
  1134. *
  1135. * Nothing but msi interrupt cleanup for now.
  1136. *
  1137. * This is called during driver unload.
  1138. */
  1139. static void ipath_setup_7220_cleanup(struct ipath_devdata *dd)
  1140. {
  1141. ipath_7220_nomsi(dd);
  1142. }
  1143. static void ipath_7220_pcie_params(struct ipath_devdata *dd, u32 boardrev)
  1144. {
  1145. u16 linkstat, minwidth, speed;
  1146. int pos;
  1147. pos = pci_find_capability(dd->pcidev, PCI_CAP_ID_EXP);
  1148. if (!pos) {
  1149. ipath_dev_err(dd, "Can't find PCI Express capability!\n");
  1150. goto bail;
  1151. }
  1152. pci_read_config_word(dd->pcidev, pos + PCI_EXP_LNKSTA,
  1153. &linkstat);
  1154. /*
  1155. * speed is bits 0-4, linkwidth is bits 4-8
  1156. * no defines for them in headers
  1157. */
  1158. speed = linkstat & 0xf;
  1159. linkstat >>= 4;
  1160. linkstat &= 0x1f;
  1161. dd->ipath_lbus_width = linkstat;
  1162. switch (boardrev) {
  1163. case 0:
  1164. case 2:
  1165. case 10:
  1166. case 12:
  1167. minwidth = 16; /* x16 capable boards */
  1168. break;
  1169. default:
  1170. minwidth = 8; /* x8 capable boards */
  1171. break;
  1172. }
  1173. switch (speed) {
  1174. case 1:
  1175. dd->ipath_lbus_speed = 2500; /* Gen1, 2.5GHz */
  1176. break;
  1177. case 2:
  1178. dd->ipath_lbus_speed = 5000; /* Gen1, 5GHz */
  1179. break;
  1180. default: /* not defined, assume gen1 */
  1181. dd->ipath_lbus_speed = 2500;
  1182. break;
  1183. }
  1184. if (linkstat < minwidth)
  1185. ipath_dev_err(dd,
  1186. "PCIe width %u (x%u HCA), performance "
  1187. "reduced\n", linkstat, minwidth);
  1188. else
  1189. ipath_cdbg(VERBOSE, "PCIe speed %u width %u (x%u HCA)\n",
  1190. dd->ipath_lbus_speed, linkstat, minwidth);
  1191. if (speed != 1)
  1192. ipath_dev_err(dd,
  1193. "PCIe linkspeed %u is incorrect; "
  1194. "should be 1 (2500)!\n", speed);
  1195. bail:
  1196. /* fill in string, even on errors */
  1197. snprintf(dd->ipath_lbus_info, sizeof(dd->ipath_lbus_info),
  1198. "PCIe,%uMHz,x%u\n",
  1199. dd->ipath_lbus_speed,
  1200. dd->ipath_lbus_width);
  1201. return;
  1202. }
  1203. /**
  1204. * ipath_setup_7220_config - setup PCIe config related stuff
  1205. * @dd: the infinipath device
  1206. * @pdev: the PCI device
  1207. *
  1208. * The pci_enable_msi() call will fail on systems with MSI quirks
  1209. * such as those with AMD8131, even if the device of interest is not
  1210. * attached to that device, (in the 2.6.13 - 2.6.15 kernels, at least, fixed
  1211. * late in 2.6.16).
  1212. * All that can be done is to edit the kernel source to remove the quirk
  1213. * check until that is fixed.
  1214. * We do not need to call enable_msi() for our HyperTransport chip,
  1215. * even though it uses MSI, and we want to avoid the quirk warning, so
  1216. * So we call enable_msi only for PCIe. If we do end up needing
  1217. * pci_enable_msi at some point in the future for HT, we'll move the
  1218. * call back into the main init_one code.
  1219. * We save the msi lo and hi values, so we can restore them after
  1220. * chip reset (the kernel PCI infrastructure doesn't yet handle that
  1221. * correctly).
  1222. */
  1223. static int ipath_setup_7220_config(struct ipath_devdata *dd,
  1224. struct pci_dev *pdev)
  1225. {
  1226. int pos, ret = -1;
  1227. u32 boardrev;
  1228. dd->ipath_msi_lo = 0; /* used as a flag during reset processing */
  1229. pos = pci_find_capability(pdev, PCI_CAP_ID_MSI);
  1230. if (!strcmp(int_type, "force_msi") || !strcmp(int_type, "auto"))
  1231. ret = pci_enable_msi(pdev);
  1232. if (ret) {
  1233. if (!strcmp(int_type, "force_msi")) {
  1234. ipath_dev_err(dd, "pci_enable_msi failed: %d, "
  1235. "force_msi is on, so not continuing.\n",
  1236. ret);
  1237. return ret;
  1238. }
  1239. ipath_enable_intx(pdev);
  1240. if (!strcmp(int_type, "auto"))
  1241. ipath_dev_err(dd, "pci_enable_msi failed: %d, "
  1242. "falling back to INTx\n", ret);
  1243. } else if (pos) {
  1244. u16 control;
  1245. pci_read_config_dword(pdev, pos + PCI_MSI_ADDRESS_LO,
  1246. &dd->ipath_msi_lo);
  1247. pci_read_config_dword(pdev, pos + PCI_MSI_ADDRESS_HI,
  1248. &dd->ipath_msi_hi);
  1249. pci_read_config_word(pdev, pos + PCI_MSI_FLAGS,
  1250. &control);
  1251. /* now save the data (vector) info */
  1252. pci_read_config_word(pdev,
  1253. pos + ((control & PCI_MSI_FLAGS_64BIT)
  1254. ? PCI_MSI_DATA_64 :
  1255. PCI_MSI_DATA_32),
  1256. &dd->ipath_msi_data);
  1257. } else
  1258. ipath_dev_err(dd, "Can't find MSI capability, "
  1259. "can't save MSI settings for reset\n");
  1260. dd->ipath_irq = pdev->irq;
  1261. /*
  1262. * We save the cachelinesize also, although it doesn't
  1263. * really matter.
  1264. */
  1265. pci_read_config_byte(pdev, PCI_CACHE_LINE_SIZE,
  1266. &dd->ipath_pci_cacheline);
  1267. /*
  1268. * this function called early, ipath_boardrev not set yet. Can't
  1269. * use ipath_read_kreg64() yet, too early in init, so use readq()
  1270. */
  1271. boardrev = (readq(&dd->ipath_kregbase[dd->ipath_kregs->kr_revision])
  1272. >> INFINIPATH_R_BOARDID_SHIFT) & INFINIPATH_R_BOARDID_MASK;
  1273. ipath_7220_pcie_params(dd, boardrev);
  1274. dd->ipath_flags |= IPATH_NODMA_RTAIL | IPATH_HAS_SEND_DMA |
  1275. IPATH_HAS_PBC_CNT | IPATH_HAS_THRESH_UPDATE;
  1276. dd->ipath_pioupd_thresh = 4U; /* set default update threshold */
  1277. return 0;
  1278. }
  1279. static void ipath_init_7220_variables(struct ipath_devdata *dd)
  1280. {
  1281. /*
  1282. * setup the register offsets, since they are different for each
  1283. * chip
  1284. */
  1285. dd->ipath_kregs = &ipath_7220_kregs;
  1286. dd->ipath_cregs = &ipath_7220_cregs;
  1287. /*
  1288. * bits for selecting i2c direction and values,
  1289. * used for I2C serial flash
  1290. */
  1291. dd->ipath_gpio_sda_num = _IPATH_GPIO_SDA_NUM;
  1292. dd->ipath_gpio_scl_num = _IPATH_GPIO_SCL_NUM;
  1293. dd->ipath_gpio_sda = IPATH_GPIO_SDA;
  1294. dd->ipath_gpio_scl = IPATH_GPIO_SCL;
  1295. /*
  1296. * Fill in data for field-values that change in IBA7220.
  1297. * We dynamically specify only the mask for LINKTRAININGSTATE
  1298. * and only the shift for LINKSTATE, as they are the only ones
  1299. * that change. Also precalculate the 3 link states of interest
  1300. * and the combined mask.
  1301. */
  1302. dd->ibcs_ls_shift = IBA7220_IBCS_LINKSTATE_SHIFT;
  1303. dd->ibcs_lts_mask = IBA7220_IBCS_LINKTRAININGSTATE_MASK;
  1304. dd->ibcs_mask = (INFINIPATH_IBCS_LINKSTATE_MASK <<
  1305. dd->ibcs_ls_shift) | dd->ibcs_lts_mask;
  1306. dd->ib_init = (INFINIPATH_IBCS_LT_STATE_LINKUP <<
  1307. INFINIPATH_IBCS_LINKTRAININGSTATE_SHIFT) |
  1308. (INFINIPATH_IBCS_L_STATE_INIT << dd->ibcs_ls_shift);
  1309. dd->ib_arm = (INFINIPATH_IBCS_LT_STATE_LINKUP <<
  1310. INFINIPATH_IBCS_LINKTRAININGSTATE_SHIFT) |
  1311. (INFINIPATH_IBCS_L_STATE_ARM << dd->ibcs_ls_shift);
  1312. dd->ib_active = (INFINIPATH_IBCS_LT_STATE_LINKUP <<
  1313. INFINIPATH_IBCS_LINKTRAININGSTATE_SHIFT) |
  1314. (INFINIPATH_IBCS_L_STATE_ACTIVE << dd->ibcs_ls_shift);
  1315. /*
  1316. * Fill in data for ibcc field-values that change in IBA7220.
  1317. * We dynamically specify only the mask for LINKINITCMD
  1318. * and only the shift for LINKCMD and MAXPKTLEN, as they are
  1319. * the only ones that change.
  1320. */
  1321. dd->ibcc_lic_mask = IBA7220_IBCC_LINKINITCMD_MASK;
  1322. dd->ibcc_lc_shift = IBA7220_IBCC_LINKCMD_SHIFT;
  1323. dd->ibcc_mpl_shift = IBA7220_IBCC_MAXPKTLEN_SHIFT;
  1324. /* Fill in shifts for RcvCtrl. */
  1325. dd->ipath_r_portenable_shift = INFINIPATH_R_PORTENABLE_SHIFT;
  1326. dd->ipath_r_intravail_shift = IBA7220_R_INTRAVAIL_SHIFT;
  1327. dd->ipath_r_tailupd_shift = IBA7220_R_TAILUPD_SHIFT;
  1328. dd->ipath_r_portcfg_shift = IBA7220_R_PORTCFG_SHIFT;
  1329. /* variables for sanity checking interrupt and errors */
  1330. dd->ipath_hwe_bitsextant =
  1331. (INFINIPATH_HWE_RXEMEMPARITYERR_MASK <<
  1332. INFINIPATH_HWE_RXEMEMPARITYERR_SHIFT) |
  1333. (INFINIPATH_HWE_TXEMEMPARITYERR_MASK <<
  1334. INFINIPATH_HWE_TXEMEMPARITYERR_SHIFT) |
  1335. (INFINIPATH_HWE_PCIEMEMPARITYERR_MASK <<
  1336. INFINIPATH_HWE_PCIEMEMPARITYERR_SHIFT) |
  1337. INFINIPATH_HWE_PCIE1PLLFAILED |
  1338. INFINIPATH_HWE_PCIE0PLLFAILED |
  1339. INFINIPATH_HWE_PCIEPOISONEDTLP |
  1340. INFINIPATH_HWE_PCIECPLTIMEOUT |
  1341. INFINIPATH_HWE_PCIEBUSPARITYXTLH |
  1342. INFINIPATH_HWE_PCIEBUSPARITYXADM |
  1343. INFINIPATH_HWE_PCIEBUSPARITYRADM |
  1344. INFINIPATH_HWE_MEMBISTFAILED |
  1345. INFINIPATH_HWE_COREPLL_FBSLIP |
  1346. INFINIPATH_HWE_COREPLL_RFSLIP |
  1347. INFINIPATH_HWE_SERDESPLLFAILED |
  1348. INFINIPATH_HWE_IBCBUSTOSPCPARITYERR |
  1349. INFINIPATH_HWE_IBCBUSFRSPCPARITYERR |
  1350. INFINIPATH_HWE_PCIECPLDATAQUEUEERR |
  1351. INFINIPATH_HWE_PCIECPLHDRQUEUEERR |
  1352. INFINIPATH_HWE_SDMAMEMREADERR |
  1353. INFINIPATH_HWE_CLK_UC_PLLNOTLOCKED |
  1354. INFINIPATH_HWE_PCIESERDESQ0PCLKNOTDETECT |
  1355. INFINIPATH_HWE_PCIESERDESQ1PCLKNOTDETECT |
  1356. INFINIPATH_HWE_PCIESERDESQ2PCLKNOTDETECT |
  1357. INFINIPATH_HWE_PCIESERDESQ3PCLKNOTDETECT |
  1358. INFINIPATH_HWE_DDSRXEQMEMORYPARITYERR |
  1359. INFINIPATH_HWE_IB_UC_MEMORYPARITYERR |
  1360. INFINIPATH_HWE_PCIE_UC_OCT0MEMORYPARITYERR |
  1361. INFINIPATH_HWE_PCIE_UC_OCT1MEMORYPARITYERR;
  1362. dd->ipath_i_bitsextant =
  1363. INFINIPATH_I_SDMAINT | INFINIPATH_I_SDMADISABLED |
  1364. (INFINIPATH_I_RCVURG_MASK << INFINIPATH_I_RCVURG_SHIFT) |
  1365. (INFINIPATH_I_RCVAVAIL_MASK <<
  1366. INFINIPATH_I_RCVAVAIL_SHIFT) |
  1367. INFINIPATH_I_ERROR | INFINIPATH_I_SPIOSENT |
  1368. INFINIPATH_I_SPIOBUFAVAIL | INFINIPATH_I_GPIO |
  1369. INFINIPATH_I_JINT | INFINIPATH_I_SERDESTRIMDONE;
  1370. dd->ipath_e_bitsextant =
  1371. INFINIPATH_E_RFORMATERR | INFINIPATH_E_RVCRC |
  1372. INFINIPATH_E_RICRC | INFINIPATH_E_RMINPKTLEN |
  1373. INFINIPATH_E_RMAXPKTLEN | INFINIPATH_E_RLONGPKTLEN |
  1374. INFINIPATH_E_RSHORTPKTLEN | INFINIPATH_E_RUNEXPCHAR |
  1375. INFINIPATH_E_RUNSUPVL | INFINIPATH_E_REBP |
  1376. INFINIPATH_E_RIBFLOW | INFINIPATH_E_RBADVERSION |
  1377. INFINIPATH_E_RRCVEGRFULL | INFINIPATH_E_RRCVHDRFULL |
  1378. INFINIPATH_E_RBADTID | INFINIPATH_E_RHDRLEN |
  1379. INFINIPATH_E_RHDR | INFINIPATH_E_RIBLOSTLINK |
  1380. INFINIPATH_E_SENDSPECIALTRIGGER |
  1381. INFINIPATH_E_SDMADISABLED | INFINIPATH_E_SMINPKTLEN |
  1382. INFINIPATH_E_SMAXPKTLEN | INFINIPATH_E_SUNDERRUN |
  1383. INFINIPATH_E_SPKTLEN | INFINIPATH_E_SDROPPEDSMPPKT |
  1384. INFINIPATH_E_SDROPPEDDATAPKT |
  1385. INFINIPATH_E_SPIOARMLAUNCH | INFINIPATH_E_SUNEXPERRPKTNUM |
  1386. INFINIPATH_E_SUNSUPVL | INFINIPATH_E_SENDBUFMISUSE |
  1387. INFINIPATH_E_SDMAGENMISMATCH | INFINIPATH_E_SDMAOUTOFBOUND |
  1388. INFINIPATH_E_SDMATAILOUTOFBOUND | INFINIPATH_E_SDMABASE |
  1389. INFINIPATH_E_SDMA1STDESC | INFINIPATH_E_SDMARPYTAG |
  1390. INFINIPATH_E_SDMADWEN | INFINIPATH_E_SDMAMISSINGDW |
  1391. INFINIPATH_E_SDMAUNEXPDATA |
  1392. INFINIPATH_E_IBSTATUSCHANGED | INFINIPATH_E_INVALIDADDR |
  1393. INFINIPATH_E_RESET | INFINIPATH_E_HARDWARE |
  1394. INFINIPATH_E_SDMADESCADDRMISALIGN |
  1395. INFINIPATH_E_INVALIDEEPCMD;
  1396. dd->ipath_i_rcvavail_mask = INFINIPATH_I_RCVAVAIL_MASK;
  1397. dd->ipath_i_rcvurg_mask = INFINIPATH_I_RCVURG_MASK;
  1398. dd->ipath_i_rcvavail_shift = INFINIPATH_I_RCVAVAIL_SHIFT;
  1399. dd->ipath_i_rcvurg_shift = INFINIPATH_I_RCVURG_SHIFT;
  1400. dd->ipath_flags |= IPATH_INTREG_64 | IPATH_HAS_MULT_IB_SPEED
  1401. | IPATH_HAS_LINK_LATENCY;
  1402. /*
  1403. * EEPROM error log 0 is TXE Parity errors. 1 is RXE Parity.
  1404. * 2 is Some Misc, 3 is reserved for future.
  1405. */
  1406. dd->ipath_eep_st_masks[0].hwerrs_to_log =
  1407. INFINIPATH_HWE_TXEMEMPARITYERR_MASK <<
  1408. INFINIPATH_HWE_TXEMEMPARITYERR_SHIFT;
  1409. dd->ipath_eep_st_masks[1].hwerrs_to_log =
  1410. INFINIPATH_HWE_RXEMEMPARITYERR_MASK <<
  1411. INFINIPATH_HWE_RXEMEMPARITYERR_SHIFT;
  1412. dd->ipath_eep_st_masks[2].errs_to_log = INFINIPATH_E_RESET;
  1413. ipath_linkrecovery = 0;
  1414. init_waitqueue_head(&dd->ipath_autoneg_wait);
  1415. INIT_DELAYED_WORK(&dd->ipath_autoneg_work, autoneg_work);
  1416. dd->ipath_link_width_supported = IB_WIDTH_1X | IB_WIDTH_4X;
  1417. dd->ipath_link_speed_supported = IPATH_IB_SDR | IPATH_IB_DDR;
  1418. dd->ipath_link_width_enabled = dd->ipath_link_width_supported;
  1419. dd->ipath_link_speed_enabled = dd->ipath_link_speed_supported;
  1420. /*
  1421. * set the initial values to reasonable default, will be set
  1422. * for real when link is up.
  1423. */
  1424. dd->ipath_link_width_active = IB_WIDTH_4X;
  1425. dd->ipath_link_speed_active = IPATH_IB_SDR;
  1426. dd->delay_mult = rate_to_delay[0][1];
  1427. }
  1428. /*
  1429. * Setup the MSI stuff again after a reset. I'd like to just call
  1430. * pci_enable_msi() and request_irq() again, but when I do that,
  1431. * the MSI enable bit doesn't get set in the command word, and
  1432. * we switch to to a different interrupt vector, which is confusing,
  1433. * so I instead just do it all inline. Perhaps somehow can tie this
  1434. * into the PCIe hotplug support at some point
  1435. * Note, because I'm doing it all here, I don't call pci_disable_msi()
  1436. * or free_irq() at the start of ipath_setup_7220_reset().
  1437. */
  1438. static int ipath_reinit_msi(struct ipath_devdata *dd)
  1439. {
  1440. int ret = 0;
  1441. int pos;
  1442. u16 control;
  1443. if (!dd->ipath_msi_lo) /* Using intX, or init problem */
  1444. goto bail;
  1445. pos = pci_find_capability(dd->pcidev, PCI_CAP_ID_MSI);
  1446. if (!pos) {
  1447. ipath_dev_err(dd, "Can't find MSI capability, "
  1448. "can't restore MSI settings\n");
  1449. goto bail;
  1450. }
  1451. ipath_cdbg(VERBOSE, "Writing msi_lo 0x%x to config offset 0x%x\n",
  1452. dd->ipath_msi_lo, pos + PCI_MSI_ADDRESS_LO);
  1453. pci_write_config_dword(dd->pcidev, pos + PCI_MSI_ADDRESS_LO,
  1454. dd->ipath_msi_lo);
  1455. ipath_cdbg(VERBOSE, "Writing msi_lo 0x%x to config offset 0x%x\n",
  1456. dd->ipath_msi_hi, pos + PCI_MSI_ADDRESS_HI);
  1457. pci_write_config_dword(dd->pcidev, pos + PCI_MSI_ADDRESS_HI,
  1458. dd->ipath_msi_hi);
  1459. pci_read_config_word(dd->pcidev, pos + PCI_MSI_FLAGS, &control);
  1460. if (!(control & PCI_MSI_FLAGS_ENABLE)) {
  1461. ipath_cdbg(VERBOSE, "MSI control at off %x was %x, "
  1462. "setting MSI enable (%x)\n", pos + PCI_MSI_FLAGS,
  1463. control, control | PCI_MSI_FLAGS_ENABLE);
  1464. control |= PCI_MSI_FLAGS_ENABLE;
  1465. pci_write_config_word(dd->pcidev, pos + PCI_MSI_FLAGS,
  1466. control);
  1467. }
  1468. /* now rewrite the data (vector) info */
  1469. pci_write_config_word(dd->pcidev, pos +
  1470. ((control & PCI_MSI_FLAGS_64BIT) ? 12 : 8),
  1471. dd->ipath_msi_data);
  1472. ret = 1;
  1473. bail:
  1474. if (!ret) {
  1475. ipath_dbg("Using INTx, MSI disabled or not configured\n");
  1476. ipath_enable_intx(dd->pcidev);
  1477. ret = 1;
  1478. }
  1479. /*
  1480. * We restore the cachelinesize also, although it doesn't really
  1481. * matter.
  1482. */
  1483. pci_write_config_byte(dd->pcidev, PCI_CACHE_LINE_SIZE,
  1484. dd->ipath_pci_cacheline);
  1485. /* and now set the pci master bit again */
  1486. pci_set_master(dd->pcidev);
  1487. return ret;
  1488. }
  1489. /*
  1490. * This routine sleeps, so it can only be called from user context, not
  1491. * from interrupt context. If we need interrupt context, we can split
  1492. * it into two routines.
  1493. */
  1494. static int ipath_setup_7220_reset(struct ipath_devdata *dd)
  1495. {
  1496. u64 val;
  1497. int i;
  1498. int ret;
  1499. u16 cmdval;
  1500. pci_read_config_word(dd->pcidev, PCI_COMMAND, &cmdval);
  1501. /* Use dev_err so it shows up in logs, etc. */
  1502. ipath_dev_err(dd, "Resetting InfiniPath unit %u\n", dd->ipath_unit);
  1503. /* keep chip from being accessed in a few places */
  1504. dd->ipath_flags &= ~(IPATH_INITTED | IPATH_PRESENT);
  1505. val = dd->ipath_control | INFINIPATH_C_RESET;
  1506. ipath_write_kreg(dd, dd->ipath_kregs->kr_control, val);
  1507. mb();
  1508. for (i = 1; i <= 5; i++) {
  1509. int r;
  1510. /*
  1511. * Allow MBIST, etc. to complete; longer on each retry.
  1512. * We sometimes get machine checks from bus timeout if no
  1513. * response, so for now, make it *really* long.
  1514. */
  1515. msleep(1000 + (1 + i) * 2000);
  1516. r = pci_write_config_dword(dd->pcidev, PCI_BASE_ADDRESS_0,
  1517. dd->ipath_pcibar0);
  1518. if (r)
  1519. ipath_dev_err(dd, "rewrite of BAR0 failed: %d\n", r);
  1520. r = pci_write_config_dword(dd->pcidev, PCI_BASE_ADDRESS_1,
  1521. dd->ipath_pcibar1);
  1522. if (r)
  1523. ipath_dev_err(dd, "rewrite of BAR1 failed: %d\n", r);
  1524. /* now re-enable memory access */
  1525. pci_write_config_word(dd->pcidev, PCI_COMMAND, cmdval);
  1526. r = pci_enable_device(dd->pcidev);
  1527. if (r)
  1528. ipath_dev_err(dd, "pci_enable_device failed after "
  1529. "reset: %d\n", r);
  1530. /*
  1531. * whether it fully enabled or not, mark as present,
  1532. * again (but not INITTED)
  1533. */
  1534. dd->ipath_flags |= IPATH_PRESENT;
  1535. val = ipath_read_kreg64(dd, dd->ipath_kregs->kr_revision);
  1536. if (val == dd->ipath_revision) {
  1537. ipath_cdbg(VERBOSE, "Got matching revision "
  1538. "register %llx on try %d\n",
  1539. (unsigned long long) val, i);
  1540. ret = ipath_reinit_msi(dd);
  1541. goto bail;
  1542. }
  1543. /* Probably getting -1 back */
  1544. ipath_dbg("Didn't get expected revision register, "
  1545. "got %llx, try %d\n", (unsigned long long) val,
  1546. i + 1);
  1547. }
  1548. ret = 0; /* failed */
  1549. bail:
  1550. if (ret)
  1551. ipath_7220_pcie_params(dd, dd->ipath_boardrev);
  1552. return ret;
  1553. }
  1554. /**
  1555. * ipath_7220_put_tid - write a TID to the chip
  1556. * @dd: the infinipath device
  1557. * @tidptr: pointer to the expected TID (in chip) to udpate
  1558. * @tidtype: 0 for eager, 1 for expected
  1559. * @pa: physical address of in memory buffer; ipath_tidinvalid if freeing
  1560. *
  1561. * This exists as a separate routine to allow for selection of the
  1562. * appropriate "flavor". The static calls in cleanup just use the
  1563. * revision-agnostic form, as they are not performance critical.
  1564. */
  1565. static void ipath_7220_put_tid(struct ipath_devdata *dd, u64 __iomem *tidptr,
  1566. u32 type, unsigned long pa)
  1567. {
  1568. if (pa != dd->ipath_tidinvalid) {
  1569. u64 chippa = pa >> IBA7220_TID_PA_SHIFT;
  1570. /* paranoia checks */
  1571. if (pa != (chippa << IBA7220_TID_PA_SHIFT)) {
  1572. dev_info(&dd->pcidev->dev, "BUG: physaddr %lx "
  1573. "not 2KB aligned!\n", pa);
  1574. return;
  1575. }
  1576. if (pa >= (1UL << IBA7220_TID_SZ_SHIFT)) {
  1577. ipath_dev_err(dd,
  1578. "BUG: Physical page address 0x%lx "
  1579. "larger than supported\n", pa);
  1580. return;
  1581. }
  1582. if (type == RCVHQ_RCV_TYPE_EAGER)
  1583. chippa |= dd->ipath_tidtemplate;
  1584. else /* for now, always full 4KB page */
  1585. chippa |= IBA7220_TID_SZ_4K;
  1586. writeq(chippa, tidptr);
  1587. } else
  1588. writeq(pa, tidptr);
  1589. mmiowb();
  1590. }
  1591. /**
  1592. * ipath_7220_clear_tid - clear all TID entries for a port, expected and eager
  1593. * @dd: the infinipath device
  1594. * @port: the port
  1595. *
  1596. * clear all TID entries for a port, expected and eager.
  1597. * Used from ipath_close(). On this chip, TIDs are only 32 bits,
  1598. * not 64, but they are still on 64 bit boundaries, so tidbase
  1599. * is declared as u64 * for the pointer math, even though we write 32 bits
  1600. */
  1601. static void ipath_7220_clear_tids(struct ipath_devdata *dd, unsigned port)
  1602. {
  1603. u64 __iomem *tidbase;
  1604. unsigned long tidinv;
  1605. int i;
  1606. if (!dd->ipath_kregbase)
  1607. return;
  1608. ipath_cdbg(VERBOSE, "Invalidate TIDs for port %u\n", port);
  1609. tidinv = dd->ipath_tidinvalid;
  1610. tidbase = (u64 __iomem *)
  1611. ((char __iomem *)(dd->ipath_kregbase) +
  1612. dd->ipath_rcvtidbase +
  1613. port * dd->ipath_rcvtidcnt * sizeof(*tidbase));
  1614. for (i = 0; i < dd->ipath_rcvtidcnt; i++)
  1615. ipath_7220_put_tid(dd, &tidbase[i], RCVHQ_RCV_TYPE_EXPECTED,
  1616. tidinv);
  1617. tidbase = (u64 __iomem *)
  1618. ((char __iomem *)(dd->ipath_kregbase) +
  1619. dd->ipath_rcvegrbase + port_egrtid_idx(dd, port)
  1620. * sizeof(*tidbase));
  1621. for (i = port ? dd->ipath_rcvegrcnt : dd->ipath_p0_rcvegrcnt; i; i--)
  1622. ipath_7220_put_tid(dd, &tidbase[i-1], RCVHQ_RCV_TYPE_EAGER,
  1623. tidinv);
  1624. }
  1625. /**
  1626. * ipath_7220_tidtemplate - setup constants for TID updates
  1627. * @dd: the infinipath device
  1628. *
  1629. * We setup stuff that we use a lot, to avoid calculating each time
  1630. */
  1631. static void ipath_7220_tidtemplate(struct ipath_devdata *dd)
  1632. {
  1633. /* For now, we always allocate 4KB buffers (at init) so we can
  1634. * receive max size packets. We may want a module parameter to
  1635. * specify 2KB or 4KB and/or make be per port instead of per device
  1636. * for those who want to reduce memory footprint. Note that the
  1637. * ipath_rcvhdrentsize size must be large enough to hold the largest
  1638. * IB header (currently 96 bytes) that we expect to handle (plus of
  1639. * course the 2 dwords of RHF).
  1640. */
  1641. if (dd->ipath_rcvegrbufsize == 2048)
  1642. dd->ipath_tidtemplate = IBA7220_TID_SZ_2K;
  1643. else if (dd->ipath_rcvegrbufsize == 4096)
  1644. dd->ipath_tidtemplate = IBA7220_TID_SZ_4K;
  1645. else {
  1646. dev_info(&dd->pcidev->dev, "BUG: unsupported egrbufsize "
  1647. "%u, using %u\n", dd->ipath_rcvegrbufsize,
  1648. 4096);
  1649. dd->ipath_tidtemplate = IBA7220_TID_SZ_4K;
  1650. }
  1651. dd->ipath_tidinvalid = 0;
  1652. }
  1653. static int ipath_7220_early_init(struct ipath_devdata *dd)
  1654. {
  1655. u32 i, s;
  1656. if (strcmp(int_type, "auto") &&
  1657. strcmp(int_type, "force_msi") &&
  1658. strcmp(int_type, "force_intx")) {
  1659. ipath_dev_err(dd, "Invalid interrupt_type: '%s', expecting "
  1660. "auto, force_msi or force_intx\n", int_type);
  1661. return -EINVAL;
  1662. }
  1663. /*
  1664. * Control[4] has been added to change the arbitration within
  1665. * the SDMA engine between favoring data fetches over descriptor
  1666. * fetches. ipath_sdma_fetch_arb==0 gives data fetches priority.
  1667. */
  1668. if (ipath_sdma_fetch_arb && (dd->ipath_minrev > 1))
  1669. dd->ipath_control |= 1<<4;
  1670. dd->ipath_flags |= IPATH_4BYTE_TID;
  1671. /*
  1672. * For openfabrics, we need to be able to handle an IB header of
  1673. * 24 dwords. HT chip has arbitrary sized receive buffers, so we
  1674. * made them the same size as the PIO buffers. This chip does not
  1675. * handle arbitrary size buffers, so we need the header large enough
  1676. * to handle largest IB header, but still have room for a 2KB MTU
  1677. * standard IB packet.
  1678. */
  1679. dd->ipath_rcvhdrentsize = 24;
  1680. dd->ipath_rcvhdrsize = IPATH_DFLT_RCVHDRSIZE;
  1681. dd->ipath_rhf_offset =
  1682. dd->ipath_rcvhdrentsize - sizeof(u64) / sizeof(u32);
  1683. dd->ipath_rcvegrbufsize = ipath_mtu4096 ? 4096 : 2048;
  1684. /*
  1685. * the min() check here is currently a nop, but it may not always
  1686. * be, depending on just how we do ipath_rcvegrbufsize
  1687. */
  1688. dd->ipath_ibmaxlen = min(ipath_mtu4096 ? dd->ipath_piosize4k :
  1689. dd->ipath_piosize2k,
  1690. dd->ipath_rcvegrbufsize +
  1691. (dd->ipath_rcvhdrentsize << 2));
  1692. dd->ipath_init_ibmaxlen = dd->ipath_ibmaxlen;
  1693. ipath_7220_config_jint(dd, INFINIPATH_JINT_DEFAULT_IDLE_TICKS,
  1694. INFINIPATH_JINT_DEFAULT_MAX_PACKETS);
  1695. if (dd->ipath_boardrev) /* no eeprom on emulator */
  1696. ipath_get_eeprom_info(dd);
  1697. /* start of code to check and print procmon */
  1698. s = ipath_read_kreg32(dd, IPATH_KREG_OFFSET(ProcMon));
  1699. s &= ~(1U<<31); /* clear done bit */
  1700. s |= 1U<<14; /* clear counter (write 1 to clear) */
  1701. ipath_write_kreg(dd, IPATH_KREG_OFFSET(ProcMon), s);
  1702. /* make sure clear_counter low long enough before start */
  1703. ipath_read_kreg32(dd, dd->ipath_kregs->kr_scratch);
  1704. ipath_read_kreg32(dd, dd->ipath_kregs->kr_scratch);
  1705. s &= ~(1U<<14); /* allow counter to count (before starting) */
  1706. ipath_write_kreg(dd, IPATH_KREG_OFFSET(ProcMon), s);
  1707. ipath_read_kreg32(dd, dd->ipath_kregs->kr_scratch);
  1708. ipath_read_kreg32(dd, dd->ipath_kregs->kr_scratch);
  1709. s = ipath_read_kreg32(dd, IPATH_KREG_OFFSET(ProcMon));
  1710. s |= 1U<<15; /* start the counter */
  1711. s &= ~(1U<<31); /* clear done bit */
  1712. s &= ~0x7ffU; /* clear frequency bits */
  1713. s |= 0xe29; /* set frequency bits, in case cleared */
  1714. ipath_write_kreg(dd, IPATH_KREG_OFFSET(ProcMon), s);
  1715. s = 0;
  1716. for (i = 500; i > 0 && !(s&(1ULL<<31)); i--) {
  1717. ipath_read_kreg32(dd, dd->ipath_kregs->kr_scratch);
  1718. s = ipath_read_kreg32(dd, IPATH_KREG_OFFSET(ProcMon));
  1719. }
  1720. if (!(s&(1U<<31)))
  1721. ipath_dev_err(dd, "ProcMon register not valid: 0x%x\n", s);
  1722. else
  1723. ipath_dbg("ProcMon=0x%x, count=0x%x\n", s, (s>>16)&0x1ff);
  1724. return 0;
  1725. }
  1726. /**
  1727. * ipath_init_7220_get_base_info - set chip-specific flags for user code
  1728. * @pd: the infinipath port
  1729. * @kbase: ipath_base_info pointer
  1730. *
  1731. * We set the PCIE flag because the lower bandwidth on PCIe vs
  1732. * HyperTransport can affect some user packet algorithims.
  1733. */
  1734. static int ipath_7220_get_base_info(struct ipath_portdata *pd, void *kbase)
  1735. {
  1736. struct ipath_base_info *kinfo = kbase;
  1737. kinfo->spi_runtime_flags |=
  1738. IPATH_RUNTIME_PCIE | IPATH_RUNTIME_NODMA_RTAIL |
  1739. IPATH_RUNTIME_SDMA;
  1740. return 0;
  1741. }
  1742. static void ipath_7220_free_irq(struct ipath_devdata *dd)
  1743. {
  1744. free_irq(dd->ipath_irq, dd);
  1745. dd->ipath_irq = 0;
  1746. }
  1747. static struct ipath_message_header *
  1748. ipath_7220_get_msgheader(struct ipath_devdata *dd, __le32 *rhf_addr)
  1749. {
  1750. u32 offset = ipath_hdrget_offset(rhf_addr);
  1751. return (struct ipath_message_header *)
  1752. (rhf_addr - dd->ipath_rhf_offset + offset);
  1753. }
  1754. static void ipath_7220_config_ports(struct ipath_devdata *dd, ushort cfgports)
  1755. {
  1756. u32 nchipports;
  1757. nchipports = ipath_read_kreg32(dd, dd->ipath_kregs->kr_portcnt);
  1758. if (!cfgports) {
  1759. int ncpus = num_online_cpus();
  1760. if (ncpus <= 4)
  1761. dd->ipath_portcnt = 5;
  1762. else if (ncpus <= 8)
  1763. dd->ipath_portcnt = 9;
  1764. if (dd->ipath_portcnt)
  1765. ipath_dbg("Auto-configured for %u ports, %d cpus "
  1766. "online\n", dd->ipath_portcnt, ncpus);
  1767. } else if (cfgports <= nchipports)
  1768. dd->ipath_portcnt = cfgports;
  1769. if (!dd->ipath_portcnt) /* none of the above, set to max */
  1770. dd->ipath_portcnt = nchipports;
  1771. /*
  1772. * chip can be configured for 5, 9, or 17 ports, and choice
  1773. * affects number of eager TIDs per port (1K, 2K, 4K).
  1774. */
  1775. if (dd->ipath_portcnt > 9)
  1776. dd->ipath_rcvctrl |= 2ULL << IBA7220_R_PORTCFG_SHIFT;
  1777. else if (dd->ipath_portcnt > 5)
  1778. dd->ipath_rcvctrl |= 1ULL << IBA7220_R_PORTCFG_SHIFT;
  1779. /* else configure for default 5 receive ports */
  1780. ipath_write_kreg(dd, dd->ipath_kregs->kr_rcvctrl,
  1781. dd->ipath_rcvctrl);
  1782. dd->ipath_p0_rcvegrcnt = 2048; /* always */
  1783. if (dd->ipath_flags & IPATH_HAS_SEND_DMA)
  1784. dd->ipath_pioreserved = 1; /* reserve a buffer */
  1785. }
  1786. static int ipath_7220_get_ib_cfg(struct ipath_devdata *dd, int which)
  1787. {
  1788. int lsb, ret = 0;
  1789. u64 maskr; /* right-justified mask */
  1790. switch (which) {
  1791. case IPATH_IB_CFG_HRTBT: /* Get Heartbeat off/enable/auto */
  1792. lsb = IBA7220_IBC_HRTBT_SHIFT;
  1793. maskr = IBA7220_IBC_HRTBT_MASK;
  1794. break;
  1795. case IPATH_IB_CFG_LWID_ENB: /* Get allowed Link-width */
  1796. ret = dd->ipath_link_width_enabled;
  1797. goto done;
  1798. case IPATH_IB_CFG_LWID: /* Get currently active Link-width */
  1799. ret = dd->ipath_link_width_active;
  1800. goto done;
  1801. case IPATH_IB_CFG_SPD_ENB: /* Get allowed Link speeds */
  1802. ret = dd->ipath_link_speed_enabled;
  1803. goto done;
  1804. case IPATH_IB_CFG_SPD: /* Get current Link spd */
  1805. ret = dd->ipath_link_speed_active;
  1806. goto done;
  1807. case IPATH_IB_CFG_RXPOL_ENB: /* Get Auto-RX-polarity enable */
  1808. lsb = IBA7220_IBC_RXPOL_SHIFT;
  1809. maskr = IBA7220_IBC_RXPOL_MASK;
  1810. break;
  1811. case IPATH_IB_CFG_LREV_ENB: /* Get Auto-Lane-reversal enable */
  1812. lsb = IBA7220_IBC_LREV_SHIFT;
  1813. maskr = IBA7220_IBC_LREV_MASK;
  1814. break;
  1815. case IPATH_IB_CFG_LINKLATENCY:
  1816. ret = ipath_read_kreg64(dd, dd->ipath_kregs->kr_ibcddrstatus)
  1817. & IBA7220_DDRSTAT_LINKLAT_MASK;
  1818. goto done;
  1819. default:
  1820. ret = -ENOTSUPP;
  1821. goto done;
  1822. }
  1823. ret = (int)((dd->ipath_ibcddrctrl >> lsb) & maskr);
  1824. done:
  1825. return ret;
  1826. }
  1827. static int ipath_7220_set_ib_cfg(struct ipath_devdata *dd, int which, u32 val)
  1828. {
  1829. int lsb, ret = 0, setforce = 0;
  1830. u64 maskr; /* right-justified mask */
  1831. switch (which) {
  1832. case IPATH_IB_CFG_LIDLMC:
  1833. /*
  1834. * Set LID and LMC. Combined to avoid possible hazard
  1835. * caller puts LMC in 16MSbits, DLID in 16LSbits of val
  1836. */
  1837. lsb = IBA7220_IBC_DLIDLMC_SHIFT;
  1838. maskr = IBA7220_IBC_DLIDLMC_MASK;
  1839. break;
  1840. case IPATH_IB_CFG_HRTBT: /* set Heartbeat off/enable/auto */
  1841. if (val & IPATH_IB_HRTBT_ON &&
  1842. (dd->ipath_flags & IPATH_NO_HRTBT))
  1843. goto bail;
  1844. lsb = IBA7220_IBC_HRTBT_SHIFT;
  1845. maskr = IBA7220_IBC_HRTBT_MASK;
  1846. break;
  1847. case IPATH_IB_CFG_LWID_ENB: /* set allowed Link-width */
  1848. /*
  1849. * As with speed, only write the actual register if
  1850. * the link is currently down, otherwise takes effect
  1851. * on next link change.
  1852. */
  1853. dd->ipath_link_width_enabled = val;
  1854. if ((dd->ipath_flags & (IPATH_LINKDOWN|IPATH_LINKINIT)) !=
  1855. IPATH_LINKDOWN)
  1856. goto bail;
  1857. /*
  1858. * We set the IPATH_IB_FORCE_NOTIFY bit so updown
  1859. * will get called because we want update
  1860. * link_width_active, and the change may not take
  1861. * effect for some time (if we are in POLL), so this
  1862. * flag will force the updown routine to be called
  1863. * on the next ibstatuschange down interrupt, even
  1864. * if it's not an down->up transition.
  1865. */
  1866. val--; /* convert from IB to chip */
  1867. maskr = IBA7220_IBC_WIDTH_MASK;
  1868. lsb = IBA7220_IBC_WIDTH_SHIFT;
  1869. setforce = 1;
  1870. dd->ipath_flags |= IPATH_IB_FORCE_NOTIFY;
  1871. break;
  1872. case IPATH_IB_CFG_SPD_ENB: /* set allowed Link speeds */
  1873. /*
  1874. * If we turn off IB1.2, need to preset SerDes defaults,
  1875. * but not right now. Set a flag for the next time
  1876. * we command the link down. As with width, only write the
  1877. * actual register if the link is currently down, otherwise
  1878. * takes effect on next link change. Since setting is being
  1879. * explictly requested (via MAD or sysfs), clear autoneg
  1880. * failure status if speed autoneg is enabled.
  1881. */
  1882. dd->ipath_link_speed_enabled = val;
  1883. if (dd->ipath_ibcddrctrl & IBA7220_IBC_IBTA_1_2_MASK &&
  1884. !(val & (val - 1)))
  1885. dd->ipath_presets_needed = 1;
  1886. if ((dd->ipath_flags & (IPATH_LINKDOWN|IPATH_LINKINIT)) !=
  1887. IPATH_LINKDOWN)
  1888. goto bail;
  1889. /*
  1890. * We set the IPATH_IB_FORCE_NOTIFY bit so updown
  1891. * will get called because we want update
  1892. * link_speed_active, and the change may not take
  1893. * effect for some time (if we are in POLL), so this
  1894. * flag will force the updown routine to be called
  1895. * on the next ibstatuschange down interrupt, even
  1896. * if it's not an down->up transition. When setting
  1897. * speed autoneg, clear AUTONEG_FAILED.
  1898. */
  1899. if (val == (IPATH_IB_SDR | IPATH_IB_DDR)) {
  1900. val = IBA7220_IBC_SPEED_AUTONEG_MASK |
  1901. IBA7220_IBC_IBTA_1_2_MASK;
  1902. dd->ipath_flags &= ~IPATH_IB_AUTONEG_FAILED;
  1903. } else
  1904. val = val == IPATH_IB_DDR ? IBA7220_IBC_SPEED_DDR
  1905. : IBA7220_IBC_SPEED_SDR;
  1906. maskr = IBA7220_IBC_SPEED_AUTONEG_MASK |
  1907. IBA7220_IBC_IBTA_1_2_MASK;
  1908. lsb = 0; /* speed bits are low bits */
  1909. setforce = 1;
  1910. break;
  1911. case IPATH_IB_CFG_RXPOL_ENB: /* set Auto-RX-polarity enable */
  1912. lsb = IBA7220_IBC_RXPOL_SHIFT;
  1913. maskr = IBA7220_IBC_RXPOL_MASK;
  1914. break;
  1915. case IPATH_IB_CFG_LREV_ENB: /* set Auto-Lane-reversal enable */
  1916. lsb = IBA7220_IBC_LREV_SHIFT;
  1917. maskr = IBA7220_IBC_LREV_MASK;
  1918. break;
  1919. default:
  1920. ret = -ENOTSUPP;
  1921. goto bail;
  1922. }
  1923. dd->ipath_ibcddrctrl &= ~(maskr << lsb);
  1924. dd->ipath_ibcddrctrl |= (((u64) val & maskr) << lsb);
  1925. ipath_write_kreg(dd, dd->ipath_kregs->kr_ibcddrctrl,
  1926. dd->ipath_ibcddrctrl);
  1927. if (setforce)
  1928. dd->ipath_flags |= IPATH_IB_FORCE_NOTIFY;
  1929. bail:
  1930. return ret;
  1931. }
  1932. static void ipath_7220_read_counters(struct ipath_devdata *dd,
  1933. struct infinipath_counters *cntrs)
  1934. {
  1935. u64 *counters = (u64 *) cntrs;
  1936. int i;
  1937. for (i = 0; i < sizeof(*cntrs) / sizeof(u64); i++)
  1938. counters[i] = ipath_snap_cntr(dd, i);
  1939. }
  1940. /* if we are using MSI, try to fallback to INTx */
  1941. static int ipath_7220_intr_fallback(struct ipath_devdata *dd)
  1942. {
  1943. if (dd->ipath_msi_lo) {
  1944. dev_info(&dd->pcidev->dev, "MSI interrupt not detected,"
  1945. " trying INTx interrupts\n");
  1946. ipath_7220_nomsi(dd);
  1947. ipath_enable_intx(dd->pcidev);
  1948. /*
  1949. * some newer kernels require free_irq before disable_msi,
  1950. * and irq can be changed during disable and intx enable
  1951. * and we need to therefore use the pcidev->irq value,
  1952. * not our saved MSI value.
  1953. */
  1954. dd->ipath_irq = dd->pcidev->irq;
  1955. if (request_irq(dd->ipath_irq, ipath_intr, IRQF_SHARED,
  1956. IPATH_DRV_NAME, dd))
  1957. ipath_dev_err(dd,
  1958. "Could not re-request_irq for INTx\n");
  1959. return 1;
  1960. }
  1961. return 0;
  1962. }
  1963. /*
  1964. * reset the XGXS (between serdes and IBC). Slightly less intrusive
  1965. * than resetting the IBC or external link state, and useful in some
  1966. * cases to cause some retraining. To do this right, we reset IBC
  1967. * as well.
  1968. */
  1969. static void ipath_7220_xgxs_reset(struct ipath_devdata *dd)
  1970. {
  1971. u64 val, prev_val;
  1972. prev_val = ipath_read_kreg64(dd, dd->ipath_kregs->kr_xgxsconfig);
  1973. val = prev_val | INFINIPATH_XGXS_RESET;
  1974. prev_val &= ~INFINIPATH_XGXS_RESET; /* be sure */
  1975. ipath_write_kreg(dd, dd->ipath_kregs->kr_control,
  1976. dd->ipath_control & ~INFINIPATH_C_LINKENABLE);
  1977. ipath_write_kreg(dd, dd->ipath_kregs->kr_xgxsconfig, val);
  1978. ipath_read_kreg32(dd, dd->ipath_kregs->kr_scratch);
  1979. ipath_write_kreg(dd, dd->ipath_kregs->kr_xgxsconfig, prev_val);
  1980. ipath_write_kreg(dd, dd->ipath_kregs->kr_control,
  1981. dd->ipath_control);
  1982. }
  1983. /* Still needs cleanup, too much hardwired stuff */
  1984. static void autoneg_send(struct ipath_devdata *dd,
  1985. u32 *hdr, u32 dcnt, u32 *data)
  1986. {
  1987. int i;
  1988. u64 cnt;
  1989. u32 __iomem *piobuf;
  1990. u32 pnum;
  1991. i = 0;
  1992. cnt = 7 + dcnt + 1; /* 7 dword header, dword data, icrc */
  1993. while (!(piobuf = ipath_getpiobuf(dd, cnt, &pnum))) {
  1994. if (i++ > 15) {
  1995. ipath_dbg("Couldn't get pio buffer for send\n");
  1996. return;
  1997. }
  1998. udelay(2);
  1999. }
  2000. if (dd->ipath_flags&IPATH_HAS_PBC_CNT)
  2001. cnt |= 0x80000000UL<<32; /* mark as VL15 */
  2002. writeq(cnt, piobuf);
  2003. ipath_flush_wc();
  2004. __iowrite32_copy(piobuf + 2, hdr, 7);
  2005. __iowrite32_copy(piobuf + 9, data, dcnt);
  2006. ipath_flush_wc();
  2007. }
  2008. /*
  2009. * _start packet gets sent twice at start, _done gets sent twice at end
  2010. */
  2011. static void ipath_autoneg_send(struct ipath_devdata *dd, int which)
  2012. {
  2013. static u32 swapped;
  2014. u32 dw, i, hcnt, dcnt, *data;
  2015. static u32 hdr[7] = { 0xf002ffff, 0x48ffff, 0x6400abba };
  2016. static u32 madpayload_start[0x40] = {
  2017. 0x1810103, 0x1, 0x0, 0x0, 0x2c90000, 0x2c9, 0x0, 0x0,
  2018. 0xffffffff, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
  2019. 0x1, 0x1388, 0x15e, 0x1, /* rest 0's */
  2020. };
  2021. static u32 madpayload_done[0x40] = {
  2022. 0x1810103, 0x1, 0x0, 0x0, 0x2c90000, 0x2c9, 0x0, 0x0,
  2023. 0xffffffff, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
  2024. 0x40000001, 0x1388, 0x15e, /* rest 0's */
  2025. };
  2026. dcnt = sizeof(madpayload_start)/sizeof(madpayload_start[0]);
  2027. hcnt = sizeof(hdr)/sizeof(hdr[0]);
  2028. if (!swapped) {
  2029. /* for maintainability, do it at runtime */
  2030. for (i = 0; i < hcnt; i++) {
  2031. dw = (__force u32) cpu_to_be32(hdr[i]);
  2032. hdr[i] = dw;
  2033. }
  2034. for (i = 0; i < dcnt; i++) {
  2035. dw = (__force u32) cpu_to_be32(madpayload_start[i]);
  2036. madpayload_start[i] = dw;
  2037. dw = (__force u32) cpu_to_be32(madpayload_done[i]);
  2038. madpayload_done[i] = dw;
  2039. }
  2040. swapped = 1;
  2041. }
  2042. data = which ? madpayload_done : madpayload_start;
  2043. ipath_cdbg(PKT, "Sending %s special MADs\n", which?"done":"start");
  2044. autoneg_send(dd, hdr, dcnt, data);
  2045. ipath_read_kreg64(dd, dd->ipath_kregs->kr_scratch);
  2046. udelay(2);
  2047. autoneg_send(dd, hdr, dcnt, data);
  2048. ipath_read_kreg64(dd, dd->ipath_kregs->kr_scratch);
  2049. udelay(2);
  2050. }
  2051. /*
  2052. * Do the absolute minimum to cause an IB speed change, and make it
  2053. * ready, but don't actually trigger the change. The caller will
  2054. * do that when ready (if link is in Polling training state, it will
  2055. * happen immediately, otherwise when link next goes down)
  2056. *
  2057. * This routine should only be used as part of the DDR autonegotation
  2058. * code for devices that are not compliant with IB 1.2 (or code that
  2059. * fixes things up for same).
  2060. *
  2061. * When link has gone down, and autoneg enabled, or autoneg has
  2062. * failed and we give up until next time we set both speeds, and
  2063. * then we want IBTA enabled as well as "use max enabled speed.
  2064. */
  2065. static void set_speed_fast(struct ipath_devdata *dd, u32 speed)
  2066. {
  2067. dd->ipath_ibcddrctrl &= ~(IBA7220_IBC_SPEED_AUTONEG_MASK |
  2068. IBA7220_IBC_IBTA_1_2_MASK |
  2069. (IBA7220_IBC_WIDTH_MASK << IBA7220_IBC_WIDTH_SHIFT));
  2070. if (speed == (IPATH_IB_SDR | IPATH_IB_DDR))
  2071. dd->ipath_ibcddrctrl |= IBA7220_IBC_SPEED_AUTONEG_MASK |
  2072. IBA7220_IBC_IBTA_1_2_MASK;
  2073. else
  2074. dd->ipath_ibcddrctrl |= speed == IPATH_IB_DDR ?
  2075. IBA7220_IBC_SPEED_DDR : IBA7220_IBC_SPEED_SDR;
  2076. /*
  2077. * Convert from IB-style 1 = 1x, 2 = 4x, 3 = auto
  2078. * to chip-centric 0 = 1x, 1 = 4x, 2 = auto
  2079. */
  2080. dd->ipath_ibcddrctrl |= (u64)(dd->ipath_link_width_enabled - 1) <<
  2081. IBA7220_IBC_WIDTH_SHIFT;
  2082. ipath_write_kreg(dd, dd->ipath_kregs->kr_ibcddrctrl,
  2083. dd->ipath_ibcddrctrl);
  2084. ipath_cdbg(VERBOSE, "setup for IB speed (%x) done\n", speed);
  2085. }
  2086. /*
  2087. * this routine is only used when we are not talking to another
  2088. * IB 1.2-compliant device that we think can do DDR.
  2089. * (This includes all existing switch chips as of Oct 2007.)
  2090. * 1.2-compliant devices go directly to DDR prior to reaching INIT
  2091. */
  2092. static void try_auto_neg(struct ipath_devdata *dd)
  2093. {
  2094. /*
  2095. * required for older non-IB1.2 DDR switches. Newer
  2096. * non-IB-compliant switches don't need it, but so far,
  2097. * aren't bothered by it either. "Magic constant"
  2098. */
  2099. ipath_write_kreg(dd, IPATH_KREG_OFFSET(IBNCModeCtrl),
  2100. 0x3b9dc07);
  2101. dd->ipath_flags |= IPATH_IB_AUTONEG_INPROG;
  2102. ipath_autoneg_send(dd, 0);
  2103. set_speed_fast(dd, IPATH_IB_DDR);
  2104. ipath_toggle_rclkrls(dd);
  2105. /* 2 msec is minimum length of a poll cycle */
  2106. schedule_delayed_work(&dd->ipath_autoneg_work,
  2107. msecs_to_jiffies(2));
  2108. }
  2109. static int ipath_7220_ib_updown(struct ipath_devdata *dd, int ibup, u64 ibcs)
  2110. {
  2111. int ret = 0;
  2112. u32 ltstate = ipath_ib_linkstate(dd, ibcs);
  2113. dd->ipath_link_width_active =
  2114. ((ibcs >> IBA7220_IBCS_LINKWIDTH_SHIFT) & 1) ?
  2115. IB_WIDTH_4X : IB_WIDTH_1X;
  2116. dd->ipath_link_speed_active =
  2117. ((ibcs >> IBA7220_IBCS_LINKSPEED_SHIFT) & 1) ?
  2118. IPATH_IB_DDR : IPATH_IB_SDR;
  2119. if (!ibup) {
  2120. /*
  2121. * when link goes down we don't want aeq running, so it
  2122. * won't't interfere with IBC training, etc., and we need
  2123. * to go back to the static SerDes preset values
  2124. */
  2125. if (dd->ipath_x1_fix_tries &&
  2126. ltstate <= INFINIPATH_IBCS_LT_STATE_SLEEPQUIET &&
  2127. ltstate != INFINIPATH_IBCS_LT_STATE_LINKUP)
  2128. dd->ipath_x1_fix_tries = 0;
  2129. if (!(dd->ipath_flags & (IPATH_IB_AUTONEG_FAILED |
  2130. IPATH_IB_AUTONEG_INPROG)))
  2131. set_speed_fast(dd, dd->ipath_link_speed_enabled);
  2132. if (!(dd->ipath_flags & IPATH_IB_AUTONEG_INPROG)) {
  2133. ipath_cdbg(VERBOSE, "Setting RXEQ defaults\n");
  2134. ipath_sd7220_presets(dd);
  2135. }
  2136. /* this might better in ipath_sd7220_presets() */
  2137. ipath_set_relock_poll(dd, ibup);
  2138. } else {
  2139. if (ipath_compat_ddr_negotiate &&
  2140. !(dd->ipath_flags & (IPATH_IB_AUTONEG_FAILED |
  2141. IPATH_IB_AUTONEG_INPROG)) &&
  2142. dd->ipath_link_speed_active == IPATH_IB_SDR &&
  2143. (dd->ipath_link_speed_enabled &
  2144. (IPATH_IB_DDR | IPATH_IB_SDR)) ==
  2145. (IPATH_IB_DDR | IPATH_IB_SDR) &&
  2146. dd->ipath_autoneg_tries < IPATH_AUTONEG_TRIES) {
  2147. /* we are SDR, and DDR auto-negotiation enabled */
  2148. ++dd->ipath_autoneg_tries;
  2149. ipath_dbg("DDR negotiation try, %u/%u\n",
  2150. dd->ipath_autoneg_tries,
  2151. IPATH_AUTONEG_TRIES);
  2152. try_auto_neg(dd);
  2153. ret = 1; /* no other IB status change processing */
  2154. } else if ((dd->ipath_flags & IPATH_IB_AUTONEG_INPROG)
  2155. && dd->ipath_link_speed_active == IPATH_IB_SDR) {
  2156. ipath_autoneg_send(dd, 1);
  2157. set_speed_fast(dd, IPATH_IB_DDR);
  2158. udelay(2);
  2159. ipath_toggle_rclkrls(dd);
  2160. ret = 1; /* no other IB status change processing */
  2161. } else {
  2162. if ((dd->ipath_flags & IPATH_IB_AUTONEG_INPROG) &&
  2163. (dd->ipath_link_speed_active & IPATH_IB_DDR)) {
  2164. ipath_dbg("Got to INIT with DDR autoneg\n");
  2165. dd->ipath_flags &= ~(IPATH_IB_AUTONEG_INPROG
  2166. | IPATH_IB_AUTONEG_FAILED);
  2167. dd->ipath_autoneg_tries = 0;
  2168. /* re-enable SDR, for next link down */
  2169. set_speed_fast(dd,
  2170. dd->ipath_link_speed_enabled);
  2171. wake_up(&dd->ipath_autoneg_wait);
  2172. } else if (dd->ipath_flags & IPATH_IB_AUTONEG_FAILED) {
  2173. /*
  2174. * clear autoneg failure flag, and do setup
  2175. * so we'll try next time link goes down and
  2176. * back to INIT (possibly connected to different
  2177. * device).
  2178. */
  2179. ipath_dbg("INIT %sDR after autoneg failure\n",
  2180. (dd->ipath_link_speed_active &
  2181. IPATH_IB_DDR) ? "D" : "S");
  2182. dd->ipath_flags &= ~IPATH_IB_AUTONEG_FAILED;
  2183. dd->ipath_ibcddrctrl |=
  2184. IBA7220_IBC_IBTA_1_2_MASK;
  2185. ipath_write_kreg(dd,
  2186. IPATH_KREG_OFFSET(IBNCModeCtrl), 0);
  2187. }
  2188. }
  2189. /*
  2190. * if we are in 1X, and are in autoneg width, it
  2191. * could be due to an xgxs problem, so if we haven't
  2192. * already tried, try twice to get to 4X; if we
  2193. * tried, and couldn't, report it, since it will
  2194. * probably not be what is desired.
  2195. */
  2196. if ((dd->ipath_link_width_enabled & (IB_WIDTH_1X |
  2197. IB_WIDTH_4X)) == (IB_WIDTH_1X | IB_WIDTH_4X)
  2198. && dd->ipath_link_width_active == IB_WIDTH_1X
  2199. && dd->ipath_x1_fix_tries < 3) {
  2200. if (++dd->ipath_x1_fix_tries == 3)
  2201. dev_info(&dd->pcidev->dev,
  2202. "IB link is in 1X mode\n");
  2203. else {
  2204. ipath_cdbg(VERBOSE, "IB 1X in "
  2205. "auto-width, try %u to be "
  2206. "sure it's really 1X; "
  2207. "ltstate %u\n",
  2208. dd->ipath_x1_fix_tries,
  2209. ltstate);
  2210. dd->ipath_f_xgxs_reset(dd);
  2211. ret = 1; /* skip other processing */
  2212. }
  2213. }
  2214. if (!ret) {
  2215. dd->delay_mult = rate_to_delay
  2216. [(ibcs >> IBA7220_IBCS_LINKSPEED_SHIFT) & 1]
  2217. [(ibcs >> IBA7220_IBCS_LINKWIDTH_SHIFT) & 1];
  2218. ipath_set_relock_poll(dd, ibup);
  2219. }
  2220. }
  2221. if (!ret)
  2222. ipath_setup_7220_setextled(dd, ipath_ib_linkstate(dd, ibcs),
  2223. ltstate);
  2224. return ret;
  2225. }
  2226. /*
  2227. * Handle the empirically determined mechanism for auto-negotiation
  2228. * of DDR speed with switches.
  2229. */
  2230. static void autoneg_work(struct work_struct *work)
  2231. {
  2232. struct ipath_devdata *dd;
  2233. u64 startms;
  2234. u32 lastlts, i;
  2235. dd = container_of(work, struct ipath_devdata,
  2236. ipath_autoneg_work.work);
  2237. startms = jiffies_to_msecs(jiffies);
  2238. /*
  2239. * busy wait for this first part, it should be at most a
  2240. * few hundred usec, since we scheduled ourselves for 2msec.
  2241. */
  2242. for (i = 0; i < 25; i++) {
  2243. lastlts = ipath_ib_linktrstate(dd, dd->ipath_lastibcstat);
  2244. if (lastlts == INFINIPATH_IBCS_LT_STATE_POLLQUIET) {
  2245. ipath_set_linkstate(dd, IPATH_IB_LINKDOWN_DISABLE);
  2246. break;
  2247. }
  2248. udelay(100);
  2249. }
  2250. if (!(dd->ipath_flags & IPATH_IB_AUTONEG_INPROG))
  2251. goto done; /* we got there early or told to stop */
  2252. /* we expect this to timeout */
  2253. if (wait_event_timeout(dd->ipath_autoneg_wait,
  2254. !(dd->ipath_flags & IPATH_IB_AUTONEG_INPROG),
  2255. msecs_to_jiffies(90)))
  2256. goto done;
  2257. ipath_toggle_rclkrls(dd);
  2258. /* we expect this to timeout */
  2259. if (wait_event_timeout(dd->ipath_autoneg_wait,
  2260. !(dd->ipath_flags & IPATH_IB_AUTONEG_INPROG),
  2261. msecs_to_jiffies(1700)))
  2262. goto done;
  2263. set_speed_fast(dd, IPATH_IB_SDR);
  2264. ipath_toggle_rclkrls(dd);
  2265. /*
  2266. * wait up to 250 msec for link to train and get to INIT at DDR;
  2267. * this should terminate early
  2268. */
  2269. wait_event_timeout(dd->ipath_autoneg_wait,
  2270. !(dd->ipath_flags & IPATH_IB_AUTONEG_INPROG),
  2271. msecs_to_jiffies(250));
  2272. done:
  2273. if (dd->ipath_flags & IPATH_IB_AUTONEG_INPROG) {
  2274. ipath_dbg("Did not get to DDR INIT (%x) after %Lu msecs\n",
  2275. ipath_ib_state(dd, dd->ipath_lastibcstat),
  2276. jiffies_to_msecs(jiffies)-startms);
  2277. dd->ipath_flags &= ~IPATH_IB_AUTONEG_INPROG;
  2278. if (dd->ipath_autoneg_tries == IPATH_AUTONEG_TRIES) {
  2279. dd->ipath_flags |= IPATH_IB_AUTONEG_FAILED;
  2280. ipath_dbg("Giving up on DDR until next IB "
  2281. "link Down\n");
  2282. dd->ipath_autoneg_tries = 0;
  2283. }
  2284. set_speed_fast(dd, dd->ipath_link_speed_enabled);
  2285. }
  2286. }
  2287. /**
  2288. * ipath_init_iba7220_funcs - set up the chip-specific function pointers
  2289. * @dd: the infinipath device
  2290. *
  2291. * This is global, and is called directly at init to set up the
  2292. * chip-specific function pointers for later use.
  2293. */
  2294. void ipath_init_iba7220_funcs(struct ipath_devdata *dd)
  2295. {
  2296. dd->ipath_f_intrsetup = ipath_7220_intconfig;
  2297. dd->ipath_f_bus = ipath_setup_7220_config;
  2298. dd->ipath_f_reset = ipath_setup_7220_reset;
  2299. dd->ipath_f_get_boardname = ipath_7220_boardname;
  2300. dd->ipath_f_init_hwerrors = ipath_7220_init_hwerrors;
  2301. dd->ipath_f_early_init = ipath_7220_early_init;
  2302. dd->ipath_f_handle_hwerrors = ipath_7220_handle_hwerrors;
  2303. dd->ipath_f_quiet_serdes = ipath_7220_quiet_serdes;
  2304. dd->ipath_f_bringup_serdes = ipath_7220_bringup_serdes;
  2305. dd->ipath_f_clear_tids = ipath_7220_clear_tids;
  2306. dd->ipath_f_put_tid = ipath_7220_put_tid;
  2307. dd->ipath_f_cleanup = ipath_setup_7220_cleanup;
  2308. dd->ipath_f_setextled = ipath_setup_7220_setextled;
  2309. dd->ipath_f_get_base_info = ipath_7220_get_base_info;
  2310. dd->ipath_f_free_irq = ipath_7220_free_irq;
  2311. dd->ipath_f_tidtemplate = ipath_7220_tidtemplate;
  2312. dd->ipath_f_intr_fallback = ipath_7220_intr_fallback;
  2313. dd->ipath_f_xgxs_reset = ipath_7220_xgxs_reset;
  2314. dd->ipath_f_get_ib_cfg = ipath_7220_get_ib_cfg;
  2315. dd->ipath_f_set_ib_cfg = ipath_7220_set_ib_cfg;
  2316. dd->ipath_f_config_jint = ipath_7220_config_jint;
  2317. dd->ipath_f_config_ports = ipath_7220_config_ports;
  2318. dd->ipath_f_read_counters = ipath_7220_read_counters;
  2319. dd->ipath_f_get_msgheader = ipath_7220_get_msgheader;
  2320. dd->ipath_f_ib_updown = ipath_7220_ib_updown;
  2321. /* initialize chip-specific variables */
  2322. ipath_init_7220_variables(dd);
  2323. }