qib_iba7322.c 265 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554
  1. /*
  2. * Copyright (c) 2012 Intel Corporation. All rights reserved.
  3. * Copyright (c) 2008 - 2012 QLogic Corporation. 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 7322 chip
  36. */
  37. #include <linux/interrupt.h>
  38. #include <linux/pci.h>
  39. #include <linux/delay.h>
  40. #include <linux/io.h>
  41. #include <linux/jiffies.h>
  42. #include <linux/module.h>
  43. #include <rdma/ib_verbs.h>
  44. #include <rdma/ib_smi.h>
  45. #ifdef CONFIG_INFINIBAND_QIB_DCA
  46. #include <linux/dca.h>
  47. #endif
  48. #include "qib.h"
  49. #include "qib_7322_regs.h"
  50. #include "qib_qsfp.h"
  51. #include "qib_mad.h"
  52. #include "qib_verbs.h"
  53. #undef pr_fmt
  54. #define pr_fmt(fmt) QIB_DRV_NAME " " fmt
  55. static void qib_setup_7322_setextled(struct qib_pportdata *, u32);
  56. static void qib_7322_handle_hwerrors(struct qib_devdata *, char *, size_t);
  57. static void sendctrl_7322_mod(struct qib_pportdata *ppd, u32 op);
  58. static irqreturn_t qib_7322intr(int irq, void *data);
  59. static irqreturn_t qib_7322bufavail(int irq, void *data);
  60. static irqreturn_t sdma_intr(int irq, void *data);
  61. static irqreturn_t sdma_idle_intr(int irq, void *data);
  62. static irqreturn_t sdma_progress_intr(int irq, void *data);
  63. static irqreturn_t sdma_cleanup_intr(int irq, void *data);
  64. static void qib_7322_txchk_change(struct qib_devdata *, u32, u32, u32,
  65. struct qib_ctxtdata *rcd);
  66. static u8 qib_7322_phys_portstate(u64);
  67. static u32 qib_7322_iblink_state(u64);
  68. static void qib_set_ib_7322_lstate(struct qib_pportdata *ppd, u16 linkcmd,
  69. u16 linitcmd);
  70. static void force_h1(struct qib_pportdata *);
  71. static void adj_tx_serdes(struct qib_pportdata *);
  72. static u32 qib_7322_setpbc_control(struct qib_pportdata *, u32, u8, u8);
  73. static void qib_7322_mini_pcs_reset(struct qib_pportdata *);
  74. static u32 ahb_mod(struct qib_devdata *, int, int, int, u32, u32);
  75. static void ibsd_wr_allchans(struct qib_pportdata *, int, unsigned, unsigned);
  76. static void serdes_7322_los_enable(struct qib_pportdata *, int);
  77. static int serdes_7322_init_old(struct qib_pportdata *);
  78. static int serdes_7322_init_new(struct qib_pportdata *);
  79. static void dump_sdma_7322_state(struct qib_pportdata *);
  80. #define BMASK(msb, lsb) (((1 << ((msb) + 1 - (lsb))) - 1) << (lsb))
  81. /* LE2 serdes values for different cases */
  82. #define LE2_DEFAULT 5
  83. #define LE2_5m 4
  84. #define LE2_QME 0
  85. /* Below is special-purpose, so only really works for the IB SerDes blocks. */
  86. #define IBSD(hw_pidx) (hw_pidx + 2)
  87. /* these are variables for documentation and experimentation purposes */
  88. static const unsigned rcv_int_timeout = 375;
  89. static const unsigned rcv_int_count = 16;
  90. static const unsigned sdma_idle_cnt = 64;
  91. /* Time to stop altering Rx Equalization parameters, after link up. */
  92. #define RXEQ_DISABLE_MSECS 2500
  93. /*
  94. * Number of VLs we are configured to use (to allow for more
  95. * credits per vl, etc.)
  96. */
  97. ushort qib_num_cfg_vls = 2;
  98. module_param_named(num_vls, qib_num_cfg_vls, ushort, S_IRUGO);
  99. MODULE_PARM_DESC(num_vls, "Set number of Virtual Lanes to use (1-8)");
  100. static ushort qib_chase = 1;
  101. module_param_named(chase, qib_chase, ushort, S_IRUGO);
  102. MODULE_PARM_DESC(chase, "Enable state chase handling");
  103. static ushort qib_long_atten = 10; /* 10 dB ~= 5m length */
  104. module_param_named(long_attenuation, qib_long_atten, ushort, S_IRUGO);
  105. MODULE_PARM_DESC(long_attenuation, \
  106. "attenuation cutoff (dB) for long copper cable setup");
  107. static ushort qib_singleport;
  108. module_param_named(singleport, qib_singleport, ushort, S_IRUGO);
  109. MODULE_PARM_DESC(singleport, "Use only IB port 1; more per-port buffer space");
  110. static ushort qib_krcvq01_no_msi;
  111. module_param_named(krcvq01_no_msi, qib_krcvq01_no_msi, ushort, S_IRUGO);
  112. MODULE_PARM_DESC(krcvq01_no_msi, "No MSI for kctx < 2");
  113. /*
  114. * Receive header queue sizes
  115. */
  116. static unsigned qib_rcvhdrcnt;
  117. module_param_named(rcvhdrcnt, qib_rcvhdrcnt, uint, S_IRUGO);
  118. MODULE_PARM_DESC(rcvhdrcnt, "receive header count");
  119. static unsigned qib_rcvhdrsize;
  120. module_param_named(rcvhdrsize, qib_rcvhdrsize, uint, S_IRUGO);
  121. MODULE_PARM_DESC(rcvhdrsize, "receive header size in 32-bit words");
  122. static unsigned qib_rcvhdrentsize;
  123. module_param_named(rcvhdrentsize, qib_rcvhdrentsize, uint, S_IRUGO);
  124. MODULE_PARM_DESC(rcvhdrentsize, "receive header entry size in 32-bit words");
  125. #define MAX_ATTEN_LEN 64 /* plenty for any real system */
  126. /* for read back, default index is ~5m copper cable */
  127. static char txselect_list[MAX_ATTEN_LEN] = "10";
  128. static struct kparam_string kp_txselect = {
  129. .string = txselect_list,
  130. .maxlen = MAX_ATTEN_LEN
  131. };
  132. static int setup_txselect(const char *, struct kernel_param *);
  133. module_param_call(txselect, setup_txselect, param_get_string,
  134. &kp_txselect, S_IWUSR | S_IRUGO);
  135. MODULE_PARM_DESC(txselect, \
  136. "Tx serdes indices (for no QSFP or invalid QSFP data)");
  137. #define BOARD_QME7342 5
  138. #define BOARD_QMH7342 6
  139. #define IS_QMH(dd) (SYM_FIELD((dd)->revision, Revision, BoardID) == \
  140. BOARD_QMH7342)
  141. #define IS_QME(dd) (SYM_FIELD((dd)->revision, Revision, BoardID) == \
  142. BOARD_QME7342)
  143. #define KREG_IDX(regname) (QIB_7322_##regname##_OFFS / sizeof(u64))
  144. #define KREG_IBPORT_IDX(regname) ((QIB_7322_##regname##_0_OFFS / sizeof(u64)))
  145. #define MASK_ACROSS(lsb, msb) \
  146. (((1ULL << ((msb) + 1 - (lsb))) - 1) << (lsb))
  147. #define SYM_RMASK(regname, fldname) ((u64) \
  148. QIB_7322_##regname##_##fldname##_RMASK)
  149. #define SYM_MASK(regname, fldname) ((u64) \
  150. QIB_7322_##regname##_##fldname##_RMASK << \
  151. QIB_7322_##regname##_##fldname##_LSB)
  152. #define SYM_FIELD(value, regname, fldname) ((u64) \
  153. (((value) >> SYM_LSB(regname, fldname)) & \
  154. SYM_RMASK(regname, fldname)))
  155. /* useful for things like LaFifoEmpty_0...7, TxCreditOK_0...7, etc. */
  156. #define SYM_FIELD_ACROSS(value, regname, fldname, nbits) \
  157. (((value) >> SYM_LSB(regname, fldname)) & MASK_ACROSS(0, nbits))
  158. #define HWE_MASK(fldname) SYM_MASK(HwErrMask, fldname##Mask)
  159. #define ERR_MASK(fldname) SYM_MASK(ErrMask, fldname##Mask)
  160. #define ERR_MASK_N(fldname) SYM_MASK(ErrMask_0, fldname##Mask)
  161. #define INT_MASK(fldname) SYM_MASK(IntMask, fldname##IntMask)
  162. #define INT_MASK_P(fldname, port) SYM_MASK(IntMask, fldname##IntMask##_##port)
  163. /* Below because most, but not all, fields of IntMask have that full suffix */
  164. #define INT_MASK_PM(fldname, port) SYM_MASK(IntMask, fldname##Mask##_##port)
  165. #define SYM_LSB(regname, fldname) (QIB_7322_##regname##_##fldname##_LSB)
  166. /*
  167. * the size bits give us 2^N, in KB units. 0 marks as invalid,
  168. * and 7 is reserved. We currently use only 2KB and 4KB
  169. */
  170. #define IBA7322_TID_SZ_SHIFT QIB_7322_RcvTIDArray0_RT_BufSize_LSB
  171. #define IBA7322_TID_SZ_2K (1UL<<IBA7322_TID_SZ_SHIFT) /* 2KB */
  172. #define IBA7322_TID_SZ_4K (2UL<<IBA7322_TID_SZ_SHIFT) /* 4KB */
  173. #define IBA7322_TID_PA_SHIFT 11U /* TID addr in chip stored w/o low bits */
  174. #define SendIBSLIDAssignMask \
  175. QIB_7322_SendIBSLIDAssign_0_SendIBSLIDAssign_15_0_RMASK
  176. #define SendIBSLMCMask \
  177. QIB_7322_SendIBSLIDMask_0_SendIBSLIDMask_15_0_RMASK
  178. #define ExtLED_IB1_YEL SYM_MASK(EXTCtrl, LEDPort0YellowOn)
  179. #define ExtLED_IB1_GRN SYM_MASK(EXTCtrl, LEDPort0GreenOn)
  180. #define ExtLED_IB2_YEL SYM_MASK(EXTCtrl, LEDPort1YellowOn)
  181. #define ExtLED_IB2_GRN SYM_MASK(EXTCtrl, LEDPort1GreenOn)
  182. #define ExtLED_IB1_MASK (ExtLED_IB1_YEL | ExtLED_IB1_GRN)
  183. #define ExtLED_IB2_MASK (ExtLED_IB2_YEL | ExtLED_IB2_GRN)
  184. #define _QIB_GPIO_SDA_NUM 1
  185. #define _QIB_GPIO_SCL_NUM 0
  186. #define QIB_EEPROM_WEN_NUM 14
  187. #define QIB_TWSI_EEPROM_DEV 0xA2 /* All Production 7322 cards. */
  188. /* HW counter clock is at 4nsec */
  189. #define QIB_7322_PSXMITWAIT_CHECK_RATE 4000
  190. /* full speed IB port 1 only */
  191. #define PORT_SPD_CAP (QIB_IB_SDR | QIB_IB_DDR | QIB_IB_QDR)
  192. #define PORT_SPD_CAP_SHIFT 3
  193. /* full speed featuremask, both ports */
  194. #define DUAL_PORT_CAP (PORT_SPD_CAP | (PORT_SPD_CAP << PORT_SPD_CAP_SHIFT))
  195. /*
  196. * This file contains almost all the chip-specific register information and
  197. * access functions for the FAKED QLogic InfiniPath 7322 PCI-Express chip.
  198. */
  199. /* Use defines to tie machine-generated names to lower-case names */
  200. #define kr_contextcnt KREG_IDX(ContextCnt)
  201. #define kr_control KREG_IDX(Control)
  202. #define kr_counterregbase KREG_IDX(CntrRegBase)
  203. #define kr_errclear KREG_IDX(ErrClear)
  204. #define kr_errmask KREG_IDX(ErrMask)
  205. #define kr_errstatus KREG_IDX(ErrStatus)
  206. #define kr_extctrl KREG_IDX(EXTCtrl)
  207. #define kr_extstatus KREG_IDX(EXTStatus)
  208. #define kr_gpio_clear KREG_IDX(GPIOClear)
  209. #define kr_gpio_mask KREG_IDX(GPIOMask)
  210. #define kr_gpio_out KREG_IDX(GPIOOut)
  211. #define kr_gpio_status KREG_IDX(GPIOStatus)
  212. #define kr_hwdiagctrl KREG_IDX(HwDiagCtrl)
  213. #define kr_debugportval KREG_IDX(DebugPortValueReg)
  214. #define kr_fmask KREG_IDX(feature_mask)
  215. #define kr_act_fmask KREG_IDX(active_feature_mask)
  216. #define kr_hwerrclear KREG_IDX(HwErrClear)
  217. #define kr_hwerrmask KREG_IDX(HwErrMask)
  218. #define kr_hwerrstatus KREG_IDX(HwErrStatus)
  219. #define kr_intclear KREG_IDX(IntClear)
  220. #define kr_intmask KREG_IDX(IntMask)
  221. #define kr_intredirect KREG_IDX(IntRedirect0)
  222. #define kr_intstatus KREG_IDX(IntStatus)
  223. #define kr_pagealign KREG_IDX(PageAlign)
  224. #define kr_rcvavailtimeout KREG_IDX(RcvAvailTimeOut0)
  225. #define kr_rcvctrl KREG_IDX(RcvCtrl) /* Common, but chip also has per-port */
  226. #define kr_rcvegrbase KREG_IDX(RcvEgrBase)
  227. #define kr_rcvegrcnt KREG_IDX(RcvEgrCnt)
  228. #define kr_rcvhdrcnt KREG_IDX(RcvHdrCnt)
  229. #define kr_rcvhdrentsize KREG_IDX(RcvHdrEntSize)
  230. #define kr_rcvhdrsize KREG_IDX(RcvHdrSize)
  231. #define kr_rcvtidbase KREG_IDX(RcvTIDBase)
  232. #define kr_rcvtidcnt KREG_IDX(RcvTIDCnt)
  233. #define kr_revision KREG_IDX(Revision)
  234. #define kr_scratch KREG_IDX(Scratch)
  235. #define kr_sendbuffererror KREG_IDX(SendBufErr0) /* and base for 1 and 2 */
  236. #define kr_sendcheckmask KREG_IDX(SendCheckMask0) /* and 1, 2 */
  237. #define kr_sendctrl KREG_IDX(SendCtrl)
  238. #define kr_sendgrhcheckmask KREG_IDX(SendGRHCheckMask0) /* and 1, 2 */
  239. #define kr_sendibpktmask KREG_IDX(SendIBPacketMask0) /* and 1, 2 */
  240. #define kr_sendpioavailaddr KREG_IDX(SendBufAvailAddr)
  241. #define kr_sendpiobufbase KREG_IDX(SendBufBase)
  242. #define kr_sendpiobufcnt KREG_IDX(SendBufCnt)
  243. #define kr_sendpiosize KREG_IDX(SendBufSize)
  244. #define kr_sendregbase KREG_IDX(SendRegBase)
  245. #define kr_sendbufavail0 KREG_IDX(SendBufAvail0)
  246. #define kr_userregbase KREG_IDX(UserRegBase)
  247. #define kr_intgranted KREG_IDX(Int_Granted)
  248. #define kr_vecclr_wo_int KREG_IDX(vec_clr_without_int)
  249. #define kr_intblocked KREG_IDX(IntBlocked)
  250. #define kr_r_access KREG_IDX(SPC_JTAG_ACCESS_REG)
  251. /*
  252. * per-port kernel registers. Access only with qib_read_kreg_port()
  253. * or qib_write_kreg_port()
  254. */
  255. #define krp_errclear KREG_IBPORT_IDX(ErrClear)
  256. #define krp_errmask KREG_IBPORT_IDX(ErrMask)
  257. #define krp_errstatus KREG_IBPORT_IDX(ErrStatus)
  258. #define krp_highprio_0 KREG_IBPORT_IDX(HighPriority0)
  259. #define krp_highprio_limit KREG_IBPORT_IDX(HighPriorityLimit)
  260. #define krp_hrtbt_guid KREG_IBPORT_IDX(HRTBT_GUID)
  261. #define krp_ib_pcsconfig KREG_IBPORT_IDX(IBPCSConfig)
  262. #define krp_ibcctrl_a KREG_IBPORT_IDX(IBCCtrlA)
  263. #define krp_ibcctrl_b KREG_IBPORT_IDX(IBCCtrlB)
  264. #define krp_ibcctrl_c KREG_IBPORT_IDX(IBCCtrlC)
  265. #define krp_ibcstatus_a KREG_IBPORT_IDX(IBCStatusA)
  266. #define krp_ibcstatus_b KREG_IBPORT_IDX(IBCStatusB)
  267. #define krp_txestatus KREG_IBPORT_IDX(TXEStatus)
  268. #define krp_lowprio_0 KREG_IBPORT_IDX(LowPriority0)
  269. #define krp_ncmodectrl KREG_IBPORT_IDX(IBNCModeCtrl)
  270. #define krp_partitionkey KREG_IBPORT_IDX(RcvPartitionKey)
  271. #define krp_psinterval KREG_IBPORT_IDX(PSInterval)
  272. #define krp_psstart KREG_IBPORT_IDX(PSStart)
  273. #define krp_psstat KREG_IBPORT_IDX(PSStat)
  274. #define krp_rcvbthqp KREG_IBPORT_IDX(RcvBTHQP)
  275. #define krp_rcvctrl KREG_IBPORT_IDX(RcvCtrl)
  276. #define krp_rcvpktledcnt KREG_IBPORT_IDX(RcvPktLEDCnt)
  277. #define krp_rcvqpmaptable KREG_IBPORT_IDX(RcvQPMapTableA)
  278. #define krp_rxcreditvl0 KREG_IBPORT_IDX(RxCreditVL0)
  279. #define krp_rxcreditvl15 (KREG_IBPORT_IDX(RxCreditVL0)+15)
  280. #define krp_sendcheckcontrol KREG_IBPORT_IDX(SendCheckControl)
  281. #define krp_sendctrl KREG_IBPORT_IDX(SendCtrl)
  282. #define krp_senddmabase KREG_IBPORT_IDX(SendDmaBase)
  283. #define krp_senddmabufmask0 KREG_IBPORT_IDX(SendDmaBufMask0)
  284. #define krp_senddmabufmask1 (KREG_IBPORT_IDX(SendDmaBufMask0) + 1)
  285. #define krp_senddmabufmask2 (KREG_IBPORT_IDX(SendDmaBufMask0) + 2)
  286. #define krp_senddmabuf_use0 KREG_IBPORT_IDX(SendDmaBufUsed0)
  287. #define krp_senddmabuf_use1 (KREG_IBPORT_IDX(SendDmaBufUsed0) + 1)
  288. #define krp_senddmabuf_use2 (KREG_IBPORT_IDX(SendDmaBufUsed0) + 2)
  289. #define krp_senddmadesccnt KREG_IBPORT_IDX(SendDmaDescCnt)
  290. #define krp_senddmahead KREG_IBPORT_IDX(SendDmaHead)
  291. #define krp_senddmaheadaddr KREG_IBPORT_IDX(SendDmaHeadAddr)
  292. #define krp_senddmaidlecnt KREG_IBPORT_IDX(SendDmaIdleCnt)
  293. #define krp_senddmalengen KREG_IBPORT_IDX(SendDmaLenGen)
  294. #define krp_senddmaprioritythld KREG_IBPORT_IDX(SendDmaPriorityThld)
  295. #define krp_senddmareloadcnt KREG_IBPORT_IDX(SendDmaReloadCnt)
  296. #define krp_senddmastatus KREG_IBPORT_IDX(SendDmaStatus)
  297. #define krp_senddmatail KREG_IBPORT_IDX(SendDmaTail)
  298. #define krp_sendhdrsymptom KREG_IBPORT_IDX(SendHdrErrSymptom)
  299. #define krp_sendslid KREG_IBPORT_IDX(SendIBSLIDAssign)
  300. #define krp_sendslidmask KREG_IBPORT_IDX(SendIBSLIDMask)
  301. #define krp_ibsdtestiftx KREG_IBPORT_IDX(IB_SDTEST_IF_TX)
  302. #define krp_adapt_dis_timer KREG_IBPORT_IDX(ADAPT_DISABLE_TIMER_THRESHOLD)
  303. #define krp_tx_deemph_override KREG_IBPORT_IDX(IBSD_TX_DEEMPHASIS_OVERRIDE)
  304. #define krp_serdesctrl KREG_IBPORT_IDX(IBSerdesCtrl)
  305. /*
  306. * Per-context kernel registers. Access only with qib_read_kreg_ctxt()
  307. * or qib_write_kreg_ctxt()
  308. */
  309. #define krc_rcvhdraddr KREG_IDX(RcvHdrAddr0)
  310. #define krc_rcvhdrtailaddr KREG_IDX(RcvHdrTailAddr0)
  311. /*
  312. * TID Flow table, per context. Reduces
  313. * number of hdrq updates to one per flow (or on errors).
  314. * context 0 and 1 share same memory, but have distinct
  315. * addresses. Since for now, we never use expected sends
  316. * on kernel contexts, we don't worry about that (we initialize
  317. * those entries for ctxt 0/1 on driver load twice, for example).
  318. */
  319. #define NUM_TIDFLOWS_CTXT 0x20 /* 0x20 per context; have to hardcode */
  320. #define ur_rcvflowtable (KREG_IDX(RcvTIDFlowTable0) - KREG_IDX(RcvHdrTail0))
  321. /* these are the error bits in the tid flows, and are W1C */
  322. #define TIDFLOW_ERRBITS ( \
  323. (SYM_MASK(RcvTIDFlowTable0, GenMismatch) << \
  324. SYM_LSB(RcvTIDFlowTable0, GenMismatch)) | \
  325. (SYM_MASK(RcvTIDFlowTable0, SeqMismatch) << \
  326. SYM_LSB(RcvTIDFlowTable0, SeqMismatch)))
  327. /* Most (not all) Counters are per-IBport.
  328. * Requires LBIntCnt is at offset 0 in the group
  329. */
  330. #define CREG_IDX(regname) \
  331. ((QIB_7322_##regname##_0_OFFS - QIB_7322_LBIntCnt_OFFS) / sizeof(u64))
  332. #define crp_badformat CREG_IDX(RxVersionErrCnt)
  333. #define crp_err_rlen CREG_IDX(RxLenErrCnt)
  334. #define crp_erricrc CREG_IDX(RxICRCErrCnt)
  335. #define crp_errlink CREG_IDX(RxLinkMalformCnt)
  336. #define crp_errlpcrc CREG_IDX(RxLPCRCErrCnt)
  337. #define crp_errpkey CREG_IDX(RxPKeyMismatchCnt)
  338. #define crp_errvcrc CREG_IDX(RxVCRCErrCnt)
  339. #define crp_excessbufferovfl CREG_IDX(ExcessBufferOvflCnt)
  340. #define crp_iblinkdown CREG_IDX(IBLinkDownedCnt)
  341. #define crp_iblinkerrrecov CREG_IDX(IBLinkErrRecoveryCnt)
  342. #define crp_ibstatuschange CREG_IDX(IBStatusChangeCnt)
  343. #define crp_ibsymbolerr CREG_IDX(IBSymbolErrCnt)
  344. #define crp_invalidrlen CREG_IDX(RxMaxMinLenErrCnt)
  345. #define crp_locallinkintegrityerr CREG_IDX(LocalLinkIntegrityErrCnt)
  346. #define crp_pktrcv CREG_IDX(RxDataPktCnt)
  347. #define crp_pktrcvflowctrl CREG_IDX(RxFlowPktCnt)
  348. #define crp_pktsend CREG_IDX(TxDataPktCnt)
  349. #define crp_pktsendflow CREG_IDX(TxFlowPktCnt)
  350. #define crp_psrcvdatacount CREG_IDX(PSRcvDataCount)
  351. #define crp_psrcvpktscount CREG_IDX(PSRcvPktsCount)
  352. #define crp_psxmitdatacount CREG_IDX(PSXmitDataCount)
  353. #define crp_psxmitpktscount CREG_IDX(PSXmitPktsCount)
  354. #define crp_psxmitwaitcount CREG_IDX(PSXmitWaitCount)
  355. #define crp_rcvebp CREG_IDX(RxEBPCnt)
  356. #define crp_rcvflowctrlviol CREG_IDX(RxFlowCtrlViolCnt)
  357. #define crp_rcvovfl CREG_IDX(RxBufOvflCnt)
  358. #define crp_rxdlidfltr CREG_IDX(RxDlidFltrCnt)
  359. #define crp_rxdroppkt CREG_IDX(RxDroppedPktCnt)
  360. #define crp_rxotherlocalphyerr CREG_IDX(RxOtherLocalPhyErrCnt)
  361. #define crp_rxqpinvalidctxt CREG_IDX(RxQPInvalidContextCnt)
  362. #define crp_rxvlerr CREG_IDX(RxVlErrCnt)
  363. #define crp_sendstall CREG_IDX(TxFlowStallCnt)
  364. #define crp_txdroppedpkt CREG_IDX(TxDroppedPktCnt)
  365. #define crp_txhdrerr CREG_IDX(TxHeadersErrCnt)
  366. #define crp_txlenerr CREG_IDX(TxLenErrCnt)
  367. #define crp_txminmaxlenerr CREG_IDX(TxMaxMinLenErrCnt)
  368. #define crp_txsdmadesc CREG_IDX(TxSDmaDescCnt)
  369. #define crp_txunderrun CREG_IDX(TxUnderrunCnt)
  370. #define crp_txunsupvl CREG_IDX(TxUnsupVLErrCnt)
  371. #define crp_vl15droppedpkt CREG_IDX(RxVL15DroppedPktCnt)
  372. #define crp_wordrcv CREG_IDX(RxDwordCnt)
  373. #define crp_wordsend CREG_IDX(TxDwordCnt)
  374. #define crp_tx_creditstalls CREG_IDX(TxCreditUpToDateTimeOut)
  375. /* these are the (few) counters that are not port-specific */
  376. #define CREG_DEVIDX(regname) ((QIB_7322_##regname##_OFFS - \
  377. QIB_7322_LBIntCnt_OFFS) / sizeof(u64))
  378. #define cr_base_egrovfl CREG_DEVIDX(RxP0HdrEgrOvflCnt)
  379. #define cr_lbint CREG_DEVIDX(LBIntCnt)
  380. #define cr_lbstall CREG_DEVIDX(LBFlowStallCnt)
  381. #define cr_pcieretrydiag CREG_DEVIDX(PcieRetryBufDiagQwordCnt)
  382. #define cr_rxtidflowdrop CREG_DEVIDX(RxTidFlowDropCnt)
  383. #define cr_tidfull CREG_DEVIDX(RxTIDFullErrCnt)
  384. #define cr_tidinvalid CREG_DEVIDX(RxTIDValidErrCnt)
  385. /* no chip register for # of IB ports supported, so define */
  386. #define NUM_IB_PORTS 2
  387. /* 1 VL15 buffer per hardware IB port, no register for this, so define */
  388. #define NUM_VL15_BUFS NUM_IB_PORTS
  389. /*
  390. * context 0 and 1 are special, and there is no chip register that
  391. * defines this value, so we have to define it here.
  392. * These are all allocated to either 0 or 1 for single port
  393. * hardware configuration, otherwise each gets half
  394. */
  395. #define KCTXT0_EGRCNT 2048
  396. /* values for vl and port fields in PBC, 7322-specific */
  397. #define PBC_PORT_SEL_LSB 26
  398. #define PBC_PORT_SEL_RMASK 1
  399. #define PBC_VL_NUM_LSB 27
  400. #define PBC_VL_NUM_RMASK 7
  401. #define PBC_7322_VL15_SEND (1ULL << 63) /* pbc; VL15, no credit check */
  402. #define PBC_7322_VL15_SEND_CTRL (1ULL << 31) /* control version of same */
  403. static u8 ib_rate_to_delay[IB_RATE_120_GBPS + 1] = {
  404. [IB_RATE_2_5_GBPS] = 16,
  405. [IB_RATE_5_GBPS] = 8,
  406. [IB_RATE_10_GBPS] = 4,
  407. [IB_RATE_20_GBPS] = 2,
  408. [IB_RATE_30_GBPS] = 2,
  409. [IB_RATE_40_GBPS] = 1
  410. };
  411. #define IBA7322_LINKSPEED_SHIFT SYM_LSB(IBCStatusA_0, LinkSpeedActive)
  412. #define IBA7322_LINKWIDTH_SHIFT SYM_LSB(IBCStatusA_0, LinkWidthActive)
  413. /* link training states, from IBC */
  414. #define IB_7322_LT_STATE_DISABLED 0x00
  415. #define IB_7322_LT_STATE_LINKUP 0x01
  416. #define IB_7322_LT_STATE_POLLACTIVE 0x02
  417. #define IB_7322_LT_STATE_POLLQUIET 0x03
  418. #define IB_7322_LT_STATE_SLEEPDELAY 0x04
  419. #define IB_7322_LT_STATE_SLEEPQUIET 0x05
  420. #define IB_7322_LT_STATE_CFGDEBOUNCE 0x08
  421. #define IB_7322_LT_STATE_CFGRCVFCFG 0x09
  422. #define IB_7322_LT_STATE_CFGWAITRMT 0x0a
  423. #define IB_7322_LT_STATE_CFGIDLE 0x0b
  424. #define IB_7322_LT_STATE_RECOVERRETRAIN 0x0c
  425. #define IB_7322_LT_STATE_TXREVLANES 0x0d
  426. #define IB_7322_LT_STATE_RECOVERWAITRMT 0x0e
  427. #define IB_7322_LT_STATE_RECOVERIDLE 0x0f
  428. #define IB_7322_LT_STATE_CFGENH 0x10
  429. #define IB_7322_LT_STATE_CFGTEST 0x11
  430. #define IB_7322_LT_STATE_CFGWAITRMTTEST 0x12
  431. #define IB_7322_LT_STATE_CFGWAITENH 0x13
  432. /* link state machine states from IBC */
  433. #define IB_7322_L_STATE_DOWN 0x0
  434. #define IB_7322_L_STATE_INIT 0x1
  435. #define IB_7322_L_STATE_ARM 0x2
  436. #define IB_7322_L_STATE_ACTIVE 0x3
  437. #define IB_7322_L_STATE_ACT_DEFER 0x4
  438. static const u8 qib_7322_physportstate[0x20] = {
  439. [IB_7322_LT_STATE_DISABLED] = IB_PHYSPORTSTATE_DISABLED,
  440. [IB_7322_LT_STATE_LINKUP] = IB_PHYSPORTSTATE_LINKUP,
  441. [IB_7322_LT_STATE_POLLACTIVE] = IB_PHYSPORTSTATE_POLL,
  442. [IB_7322_LT_STATE_POLLQUIET] = IB_PHYSPORTSTATE_POLL,
  443. [IB_7322_LT_STATE_SLEEPDELAY] = IB_PHYSPORTSTATE_SLEEP,
  444. [IB_7322_LT_STATE_SLEEPQUIET] = IB_PHYSPORTSTATE_SLEEP,
  445. [IB_7322_LT_STATE_CFGDEBOUNCE] = IB_PHYSPORTSTATE_CFG_TRAIN,
  446. [IB_7322_LT_STATE_CFGRCVFCFG] =
  447. IB_PHYSPORTSTATE_CFG_TRAIN,
  448. [IB_7322_LT_STATE_CFGWAITRMT] =
  449. IB_PHYSPORTSTATE_CFG_TRAIN,
  450. [IB_7322_LT_STATE_CFGIDLE] = IB_PHYSPORTSTATE_CFG_IDLE,
  451. [IB_7322_LT_STATE_RECOVERRETRAIN] =
  452. IB_PHYSPORTSTATE_LINK_ERR_RECOVER,
  453. [IB_7322_LT_STATE_RECOVERWAITRMT] =
  454. IB_PHYSPORTSTATE_LINK_ERR_RECOVER,
  455. [IB_7322_LT_STATE_RECOVERIDLE] =
  456. IB_PHYSPORTSTATE_LINK_ERR_RECOVER,
  457. [IB_7322_LT_STATE_CFGENH] = IB_PHYSPORTSTATE_CFG_ENH,
  458. [IB_7322_LT_STATE_CFGTEST] = IB_PHYSPORTSTATE_CFG_TRAIN,
  459. [IB_7322_LT_STATE_CFGWAITRMTTEST] =
  460. IB_PHYSPORTSTATE_CFG_TRAIN,
  461. [IB_7322_LT_STATE_CFGWAITENH] =
  462. IB_PHYSPORTSTATE_CFG_WAIT_ENH,
  463. [0x14] = IB_PHYSPORTSTATE_CFG_TRAIN,
  464. [0x15] = IB_PHYSPORTSTATE_CFG_TRAIN,
  465. [0x16] = IB_PHYSPORTSTATE_CFG_TRAIN,
  466. [0x17] = IB_PHYSPORTSTATE_CFG_TRAIN
  467. };
  468. #ifdef CONFIG_INFINIBAND_QIB_DCA
  469. struct qib_irq_notify {
  470. int rcv;
  471. void *arg;
  472. struct irq_affinity_notify notify;
  473. };
  474. #endif
  475. struct qib_chip_specific {
  476. u64 __iomem *cregbase;
  477. u64 *cntrs;
  478. spinlock_t rcvmod_lock; /* protect rcvctrl shadow changes */
  479. spinlock_t gpio_lock; /* RMW of shadows/regs for ExtCtrl and GPIO */
  480. u64 main_int_mask; /* clear bits which have dedicated handlers */
  481. u64 int_enable_mask; /* for per port interrupts in single port mode */
  482. u64 errormask;
  483. u64 hwerrmask;
  484. u64 gpio_out; /* shadow of kr_gpio_out, for rmw ops */
  485. u64 gpio_mask; /* shadow the gpio mask register */
  486. u64 extctrl; /* shadow the gpio output enable, etc... */
  487. u32 ncntrs;
  488. u32 nportcntrs;
  489. u32 cntrnamelen;
  490. u32 portcntrnamelen;
  491. u32 numctxts;
  492. u32 rcvegrcnt;
  493. u32 updthresh; /* current AvailUpdThld */
  494. u32 updthresh_dflt; /* default AvailUpdThld */
  495. u32 r1;
  496. int irq;
  497. u32 num_msix_entries;
  498. u32 sdmabufcnt;
  499. u32 lastbuf_for_pio;
  500. u32 stay_in_freeze;
  501. u32 recovery_ports_initted;
  502. #ifdef CONFIG_INFINIBAND_QIB_DCA
  503. u32 dca_ctrl;
  504. int rhdr_cpu[18];
  505. int sdma_cpu[2];
  506. u64 dca_rcvhdr_ctrl[5]; /* B, C, D, E, F */
  507. #endif
  508. struct qib_msix_entry *msix_entries;
  509. unsigned long *sendchkenable;
  510. unsigned long *sendgrhchk;
  511. unsigned long *sendibchk;
  512. u32 rcvavail_timeout[18];
  513. char emsgbuf[128]; /* for device error interrupt msg buffer */
  514. };
  515. /* Table of entries in "human readable" form Tx Emphasis. */
  516. struct txdds_ent {
  517. u8 amp;
  518. u8 pre;
  519. u8 main;
  520. u8 post;
  521. };
  522. struct vendor_txdds_ent {
  523. u8 oui[QSFP_VOUI_LEN];
  524. u8 *partnum;
  525. struct txdds_ent sdr;
  526. struct txdds_ent ddr;
  527. struct txdds_ent qdr;
  528. };
  529. static void write_tx_serdes_param(struct qib_pportdata *, struct txdds_ent *);
  530. #define TXDDS_TABLE_SZ 16 /* number of entries per speed in onchip table */
  531. #define TXDDS_EXTRA_SZ 18 /* number of extra tx settings entries */
  532. #define TXDDS_MFG_SZ 2 /* number of mfg tx settings entries */
  533. #define SERDES_CHANS 4 /* yes, it's obvious, but one less magic number */
  534. #define H1_FORCE_VAL 8
  535. #define H1_FORCE_QME 1 /* may be overridden via setup_txselect() */
  536. #define H1_FORCE_QMH 7 /* may be overridden via setup_txselect() */
  537. /* The static and dynamic registers are paired, and the pairs indexed by spd */
  538. #define krp_static_adapt_dis(spd) (KREG_IBPORT_IDX(ADAPT_DISABLE_STATIC_SDR) \
  539. + ((spd) * 2))
  540. #define QDR_DFE_DISABLE_DELAY 4000 /* msec after LINKUP */
  541. #define QDR_STATIC_ADAPT_DOWN 0xf0f0f0f0ULL /* link down, H1-H4 QDR adapts */
  542. #define QDR_STATIC_ADAPT_DOWN_R1 0ULL /* r1 link down, H1-H4 QDR adapts */
  543. #define QDR_STATIC_ADAPT_INIT 0xffffffffffULL /* up, disable H0,H1-8, LE */
  544. #define QDR_STATIC_ADAPT_INIT_R1 0xf0ffffffffULL /* r1 up, disable H0,H1-8 */
  545. struct qib_chippport_specific {
  546. u64 __iomem *kpregbase;
  547. u64 __iomem *cpregbase;
  548. u64 *portcntrs;
  549. struct qib_pportdata *ppd;
  550. wait_queue_head_t autoneg_wait;
  551. struct delayed_work autoneg_work;
  552. struct delayed_work ipg_work;
  553. struct timer_list chase_timer;
  554. /*
  555. * these 5 fields are used to establish deltas for IB symbol
  556. * errors and linkrecovery errors. They can be reported on
  557. * some chips during link negotiation prior to INIT, and with
  558. * DDR when faking DDR negotiations with non-IBTA switches.
  559. * The chip counters are adjusted at driver unload if there is
  560. * a non-zero delta.
  561. */
  562. u64 ibdeltainprog;
  563. u64 ibsymdelta;
  564. u64 ibsymsnap;
  565. u64 iblnkerrdelta;
  566. u64 iblnkerrsnap;
  567. u64 iblnkdownsnap;
  568. u64 iblnkdowndelta;
  569. u64 ibmalfdelta;
  570. u64 ibmalfsnap;
  571. u64 ibcctrl_a; /* krp_ibcctrl_a shadow */
  572. u64 ibcctrl_b; /* krp_ibcctrl_b shadow */
  573. unsigned long qdr_dfe_time;
  574. unsigned long chase_end;
  575. u32 autoneg_tries;
  576. u32 recovery_init;
  577. u32 qdr_dfe_on;
  578. u32 qdr_reforce;
  579. /*
  580. * Per-bay per-channel rcv QMH H1 values and Tx values for QDR.
  581. * entry zero is unused, to simplify indexing
  582. */
  583. u8 h1_val;
  584. u8 no_eep; /* txselect table index to use if no qsfp info */
  585. u8 ipg_tries;
  586. u8 ibmalfusesnap;
  587. struct qib_qsfp_data qsfp_data;
  588. char epmsgbuf[192]; /* for port error interrupt msg buffer */
  589. char sdmamsgbuf[192]; /* for per-port sdma error messages */
  590. };
  591. static struct {
  592. const char *name;
  593. irq_handler_t handler;
  594. int lsb;
  595. int port; /* 0 if not port-specific, else port # */
  596. int dca;
  597. } irq_table[] = {
  598. { "", qib_7322intr, -1, 0, 0 },
  599. { " (buf avail)", qib_7322bufavail,
  600. SYM_LSB(IntStatus, SendBufAvail), 0, 0},
  601. { " (sdma 0)", sdma_intr,
  602. SYM_LSB(IntStatus, SDmaInt_0), 1, 1 },
  603. { " (sdma 1)", sdma_intr,
  604. SYM_LSB(IntStatus, SDmaInt_1), 2, 1 },
  605. { " (sdmaI 0)", sdma_idle_intr,
  606. SYM_LSB(IntStatus, SDmaIdleInt_0), 1, 1},
  607. { " (sdmaI 1)", sdma_idle_intr,
  608. SYM_LSB(IntStatus, SDmaIdleInt_1), 2, 1},
  609. { " (sdmaP 0)", sdma_progress_intr,
  610. SYM_LSB(IntStatus, SDmaProgressInt_0), 1, 1 },
  611. { " (sdmaP 1)", sdma_progress_intr,
  612. SYM_LSB(IntStatus, SDmaProgressInt_1), 2, 1 },
  613. { " (sdmaC 0)", sdma_cleanup_intr,
  614. SYM_LSB(IntStatus, SDmaCleanupDone_0), 1, 0 },
  615. { " (sdmaC 1)", sdma_cleanup_intr,
  616. SYM_LSB(IntStatus, SDmaCleanupDone_1), 2 , 0},
  617. };
  618. #ifdef CONFIG_INFINIBAND_QIB_DCA
  619. static const struct dca_reg_map {
  620. int shadow_inx;
  621. int lsb;
  622. u64 mask;
  623. u16 regno;
  624. } dca_rcvhdr_reg_map[] = {
  625. { 0, SYM_LSB(DCACtrlB, RcvHdrq0DCAOPH),
  626. ~SYM_MASK(DCACtrlB, RcvHdrq0DCAOPH) , KREG_IDX(DCACtrlB) },
  627. { 0, SYM_LSB(DCACtrlB, RcvHdrq1DCAOPH),
  628. ~SYM_MASK(DCACtrlB, RcvHdrq1DCAOPH) , KREG_IDX(DCACtrlB) },
  629. { 0, SYM_LSB(DCACtrlB, RcvHdrq2DCAOPH),
  630. ~SYM_MASK(DCACtrlB, RcvHdrq2DCAOPH) , KREG_IDX(DCACtrlB) },
  631. { 0, SYM_LSB(DCACtrlB, RcvHdrq3DCAOPH),
  632. ~SYM_MASK(DCACtrlB, RcvHdrq3DCAOPH) , KREG_IDX(DCACtrlB) },
  633. { 1, SYM_LSB(DCACtrlC, RcvHdrq4DCAOPH),
  634. ~SYM_MASK(DCACtrlC, RcvHdrq4DCAOPH) , KREG_IDX(DCACtrlC) },
  635. { 1, SYM_LSB(DCACtrlC, RcvHdrq5DCAOPH),
  636. ~SYM_MASK(DCACtrlC, RcvHdrq5DCAOPH) , KREG_IDX(DCACtrlC) },
  637. { 1, SYM_LSB(DCACtrlC, RcvHdrq6DCAOPH),
  638. ~SYM_MASK(DCACtrlC, RcvHdrq6DCAOPH) , KREG_IDX(DCACtrlC) },
  639. { 1, SYM_LSB(DCACtrlC, RcvHdrq7DCAOPH),
  640. ~SYM_MASK(DCACtrlC, RcvHdrq7DCAOPH) , KREG_IDX(DCACtrlC) },
  641. { 2, SYM_LSB(DCACtrlD, RcvHdrq8DCAOPH),
  642. ~SYM_MASK(DCACtrlD, RcvHdrq8DCAOPH) , KREG_IDX(DCACtrlD) },
  643. { 2, SYM_LSB(DCACtrlD, RcvHdrq9DCAOPH),
  644. ~SYM_MASK(DCACtrlD, RcvHdrq9DCAOPH) , KREG_IDX(DCACtrlD) },
  645. { 2, SYM_LSB(DCACtrlD, RcvHdrq10DCAOPH),
  646. ~SYM_MASK(DCACtrlD, RcvHdrq10DCAOPH) , KREG_IDX(DCACtrlD) },
  647. { 2, SYM_LSB(DCACtrlD, RcvHdrq11DCAOPH),
  648. ~SYM_MASK(DCACtrlD, RcvHdrq11DCAOPH) , KREG_IDX(DCACtrlD) },
  649. { 3, SYM_LSB(DCACtrlE, RcvHdrq12DCAOPH),
  650. ~SYM_MASK(DCACtrlE, RcvHdrq12DCAOPH) , KREG_IDX(DCACtrlE) },
  651. { 3, SYM_LSB(DCACtrlE, RcvHdrq13DCAOPH),
  652. ~SYM_MASK(DCACtrlE, RcvHdrq13DCAOPH) , KREG_IDX(DCACtrlE) },
  653. { 3, SYM_LSB(DCACtrlE, RcvHdrq14DCAOPH),
  654. ~SYM_MASK(DCACtrlE, RcvHdrq14DCAOPH) , KREG_IDX(DCACtrlE) },
  655. { 3, SYM_LSB(DCACtrlE, RcvHdrq15DCAOPH),
  656. ~SYM_MASK(DCACtrlE, RcvHdrq15DCAOPH) , KREG_IDX(DCACtrlE) },
  657. { 4, SYM_LSB(DCACtrlF, RcvHdrq16DCAOPH),
  658. ~SYM_MASK(DCACtrlF, RcvHdrq16DCAOPH) , KREG_IDX(DCACtrlF) },
  659. { 4, SYM_LSB(DCACtrlF, RcvHdrq17DCAOPH),
  660. ~SYM_MASK(DCACtrlF, RcvHdrq17DCAOPH) , KREG_IDX(DCACtrlF) },
  661. };
  662. #endif
  663. /* ibcctrl bits */
  664. #define QLOGIC_IB_IBCC_LINKINITCMD_DISABLE 1
  665. /* cycle through TS1/TS2 till OK */
  666. #define QLOGIC_IB_IBCC_LINKINITCMD_POLL 2
  667. /* wait for TS1, then go on */
  668. #define QLOGIC_IB_IBCC_LINKINITCMD_SLEEP 3
  669. #define QLOGIC_IB_IBCC_LINKINITCMD_SHIFT 16
  670. #define QLOGIC_IB_IBCC_LINKCMD_DOWN 1 /* move to 0x11 */
  671. #define QLOGIC_IB_IBCC_LINKCMD_ARMED 2 /* move to 0x21 */
  672. #define QLOGIC_IB_IBCC_LINKCMD_ACTIVE 3 /* move to 0x31 */
  673. #define BLOB_7322_IBCHG 0x101
  674. static inline void qib_write_kreg(const struct qib_devdata *dd,
  675. const u32 regno, u64 value);
  676. static inline u32 qib_read_kreg32(const struct qib_devdata *, const u32);
  677. static void write_7322_initregs(struct qib_devdata *);
  678. static void write_7322_init_portregs(struct qib_pportdata *);
  679. static void setup_7322_link_recovery(struct qib_pportdata *, u32);
  680. static void check_7322_rxe_status(struct qib_pportdata *);
  681. static u32 __iomem *qib_7322_getsendbuf(struct qib_pportdata *, u64, u32 *);
  682. #ifdef CONFIG_INFINIBAND_QIB_DCA
  683. static void qib_setup_dca(struct qib_devdata *dd);
  684. static void setup_dca_notifier(struct qib_devdata *dd,
  685. struct qib_msix_entry *m);
  686. static void reset_dca_notifier(struct qib_devdata *dd,
  687. struct qib_msix_entry *m);
  688. #endif
  689. /**
  690. * qib_read_ureg32 - read 32-bit virtualized per-context register
  691. * @dd: device
  692. * @regno: register number
  693. * @ctxt: context number
  694. *
  695. * Return the contents of a register that is virtualized to be per context.
  696. * Returns -1 on errors (not distinguishable from valid contents at
  697. * runtime; we may add a separate error variable at some point).
  698. */
  699. static inline u32 qib_read_ureg32(const struct qib_devdata *dd,
  700. enum qib_ureg regno, int ctxt)
  701. {
  702. if (!dd->kregbase || !(dd->flags & QIB_PRESENT))
  703. return 0;
  704. return readl(regno + (u64 __iomem *)(
  705. (dd->ureg_align * ctxt) + (dd->userbase ?
  706. (char __iomem *)dd->userbase :
  707. (char __iomem *)dd->kregbase + dd->uregbase)));
  708. }
  709. /**
  710. * qib_read_ureg - read virtualized per-context register
  711. * @dd: device
  712. * @regno: register number
  713. * @ctxt: context number
  714. *
  715. * Return the contents of a register that is virtualized to be per context.
  716. * Returns -1 on errors (not distinguishable from valid contents at
  717. * runtime; we may add a separate error variable at some point).
  718. */
  719. static inline u64 qib_read_ureg(const struct qib_devdata *dd,
  720. enum qib_ureg regno, int ctxt)
  721. {
  722. if (!dd->kregbase || !(dd->flags & QIB_PRESENT))
  723. return 0;
  724. return readq(regno + (u64 __iomem *)(
  725. (dd->ureg_align * ctxt) + (dd->userbase ?
  726. (char __iomem *)dd->userbase :
  727. (char __iomem *)dd->kregbase + dd->uregbase)));
  728. }
  729. /**
  730. * qib_write_ureg - write virtualized per-context register
  731. * @dd: device
  732. * @regno: register number
  733. * @value: value
  734. * @ctxt: context
  735. *
  736. * Write the contents of a register that is virtualized to be per context.
  737. */
  738. static inline void qib_write_ureg(const struct qib_devdata *dd,
  739. enum qib_ureg regno, u64 value, int ctxt)
  740. {
  741. u64 __iomem *ubase;
  742. if (dd->userbase)
  743. ubase = (u64 __iomem *)
  744. ((char __iomem *) dd->userbase +
  745. dd->ureg_align * ctxt);
  746. else
  747. ubase = (u64 __iomem *)
  748. (dd->uregbase +
  749. (char __iomem *) dd->kregbase +
  750. dd->ureg_align * ctxt);
  751. if (dd->kregbase && (dd->flags & QIB_PRESENT))
  752. writeq(value, &ubase[regno]);
  753. }
  754. static inline u32 qib_read_kreg32(const struct qib_devdata *dd,
  755. const u32 regno)
  756. {
  757. if (!dd->kregbase || !(dd->flags & QIB_PRESENT))
  758. return -1;
  759. return readl((u32 __iomem *) &dd->kregbase[regno]);
  760. }
  761. static inline u64 qib_read_kreg64(const struct qib_devdata *dd,
  762. const u32 regno)
  763. {
  764. if (!dd->kregbase || !(dd->flags & QIB_PRESENT))
  765. return -1;
  766. return readq(&dd->kregbase[regno]);
  767. }
  768. static inline void qib_write_kreg(const struct qib_devdata *dd,
  769. const u32 regno, u64 value)
  770. {
  771. if (dd->kregbase && (dd->flags & QIB_PRESENT))
  772. writeq(value, &dd->kregbase[regno]);
  773. }
  774. /*
  775. * not many sanity checks for the port-specific kernel register routines,
  776. * since they are only used when it's known to be safe.
  777. */
  778. static inline u64 qib_read_kreg_port(const struct qib_pportdata *ppd,
  779. const u16 regno)
  780. {
  781. if (!ppd->cpspec->kpregbase || !(ppd->dd->flags & QIB_PRESENT))
  782. return 0ULL;
  783. return readq(&ppd->cpspec->kpregbase[regno]);
  784. }
  785. static inline void qib_write_kreg_port(const struct qib_pportdata *ppd,
  786. const u16 regno, u64 value)
  787. {
  788. if (ppd->cpspec && ppd->dd && ppd->cpspec->kpregbase &&
  789. (ppd->dd->flags & QIB_PRESENT))
  790. writeq(value, &ppd->cpspec->kpregbase[regno]);
  791. }
  792. /**
  793. * qib_write_kreg_ctxt - write a device's per-ctxt 64-bit kernel register
  794. * @dd: the qlogic_ib device
  795. * @regno: the register number to write
  796. * @ctxt: the context containing the register
  797. * @value: the value to write
  798. */
  799. static inline void qib_write_kreg_ctxt(const struct qib_devdata *dd,
  800. const u16 regno, unsigned ctxt,
  801. u64 value)
  802. {
  803. qib_write_kreg(dd, regno + ctxt, value);
  804. }
  805. static inline u64 read_7322_creg(const struct qib_devdata *dd, u16 regno)
  806. {
  807. if (!dd->cspec->cregbase || !(dd->flags & QIB_PRESENT))
  808. return 0;
  809. return readq(&dd->cspec->cregbase[regno]);
  810. }
  811. static inline u32 read_7322_creg32(const struct qib_devdata *dd, u16 regno)
  812. {
  813. if (!dd->cspec->cregbase || !(dd->flags & QIB_PRESENT))
  814. return 0;
  815. return readl(&dd->cspec->cregbase[regno]);
  816. }
  817. static inline void write_7322_creg_port(const struct qib_pportdata *ppd,
  818. u16 regno, u64 value)
  819. {
  820. if (ppd->cpspec && ppd->cpspec->cpregbase &&
  821. (ppd->dd->flags & QIB_PRESENT))
  822. writeq(value, &ppd->cpspec->cpregbase[regno]);
  823. }
  824. static inline u64 read_7322_creg_port(const struct qib_pportdata *ppd,
  825. u16 regno)
  826. {
  827. if (!ppd->cpspec || !ppd->cpspec->cpregbase ||
  828. !(ppd->dd->flags & QIB_PRESENT))
  829. return 0;
  830. return readq(&ppd->cpspec->cpregbase[regno]);
  831. }
  832. static inline u32 read_7322_creg32_port(const struct qib_pportdata *ppd,
  833. u16 regno)
  834. {
  835. if (!ppd->cpspec || !ppd->cpspec->cpregbase ||
  836. !(ppd->dd->flags & QIB_PRESENT))
  837. return 0;
  838. return readl(&ppd->cpspec->cpregbase[regno]);
  839. }
  840. /* bits in Control register */
  841. #define QLOGIC_IB_C_RESET SYM_MASK(Control, SyncReset)
  842. #define QLOGIC_IB_C_SDMAFETCHPRIOEN SYM_MASK(Control, SDmaDescFetchPriorityEn)
  843. /* bits in general interrupt regs */
  844. #define QIB_I_RCVURG_LSB SYM_LSB(IntMask, RcvUrg0IntMask)
  845. #define QIB_I_RCVURG_RMASK MASK_ACROSS(0, 17)
  846. #define QIB_I_RCVURG_MASK (QIB_I_RCVURG_RMASK << QIB_I_RCVURG_LSB)
  847. #define QIB_I_RCVAVAIL_LSB SYM_LSB(IntMask, RcvAvail0IntMask)
  848. #define QIB_I_RCVAVAIL_RMASK MASK_ACROSS(0, 17)
  849. #define QIB_I_RCVAVAIL_MASK (QIB_I_RCVAVAIL_RMASK << QIB_I_RCVAVAIL_LSB)
  850. #define QIB_I_C_ERROR INT_MASK(Err)
  851. #define QIB_I_SPIOSENT (INT_MASK_P(SendDone, 0) | INT_MASK_P(SendDone, 1))
  852. #define QIB_I_SPIOBUFAVAIL INT_MASK(SendBufAvail)
  853. #define QIB_I_GPIO INT_MASK(AssertGPIO)
  854. #define QIB_I_P_SDMAINT(pidx) \
  855. (INT_MASK_P(SDma, pidx) | INT_MASK_P(SDmaIdle, pidx) | \
  856. INT_MASK_P(SDmaProgress, pidx) | \
  857. INT_MASK_PM(SDmaCleanupDone, pidx))
  858. /* Interrupt bits that are "per port" */
  859. #define QIB_I_P_BITSEXTANT(pidx) \
  860. (INT_MASK_P(Err, pidx) | INT_MASK_P(SendDone, pidx) | \
  861. INT_MASK_P(SDma, pidx) | INT_MASK_P(SDmaIdle, pidx) | \
  862. INT_MASK_P(SDmaProgress, pidx) | \
  863. INT_MASK_PM(SDmaCleanupDone, pidx))
  864. /* Interrupt bits that are common to a device */
  865. /* currently unused: QIB_I_SPIOSENT */
  866. #define QIB_I_C_BITSEXTANT \
  867. (QIB_I_RCVURG_MASK | QIB_I_RCVAVAIL_MASK | \
  868. QIB_I_SPIOSENT | \
  869. QIB_I_C_ERROR | QIB_I_SPIOBUFAVAIL | QIB_I_GPIO)
  870. #define QIB_I_BITSEXTANT (QIB_I_C_BITSEXTANT | \
  871. QIB_I_P_BITSEXTANT(0) | QIB_I_P_BITSEXTANT(1))
  872. /*
  873. * Error bits that are "per port".
  874. */
  875. #define QIB_E_P_IBSTATUSCHANGED ERR_MASK_N(IBStatusChanged)
  876. #define QIB_E_P_SHDR ERR_MASK_N(SHeadersErr)
  877. #define QIB_E_P_VL15_BUF_MISUSE ERR_MASK_N(VL15BufMisuseErr)
  878. #define QIB_E_P_SND_BUF_MISUSE ERR_MASK_N(SendBufMisuseErr)
  879. #define QIB_E_P_SUNSUPVL ERR_MASK_N(SendUnsupportedVLErr)
  880. #define QIB_E_P_SUNEXP_PKTNUM ERR_MASK_N(SendUnexpectedPktNumErr)
  881. #define QIB_E_P_SDROP_DATA ERR_MASK_N(SendDroppedDataPktErr)
  882. #define QIB_E_P_SDROP_SMP ERR_MASK_N(SendDroppedSmpPktErr)
  883. #define QIB_E_P_SPKTLEN ERR_MASK_N(SendPktLenErr)
  884. #define QIB_E_P_SUNDERRUN ERR_MASK_N(SendUnderRunErr)
  885. #define QIB_E_P_SMAXPKTLEN ERR_MASK_N(SendMaxPktLenErr)
  886. #define QIB_E_P_SMINPKTLEN ERR_MASK_N(SendMinPktLenErr)
  887. #define QIB_E_P_RIBLOSTLINK ERR_MASK_N(RcvIBLostLinkErr)
  888. #define QIB_E_P_RHDR ERR_MASK_N(RcvHdrErr)
  889. #define QIB_E_P_RHDRLEN ERR_MASK_N(RcvHdrLenErr)
  890. #define QIB_E_P_RBADTID ERR_MASK_N(RcvBadTidErr)
  891. #define QIB_E_P_RBADVERSION ERR_MASK_N(RcvBadVersionErr)
  892. #define QIB_E_P_RIBFLOW ERR_MASK_N(RcvIBFlowErr)
  893. #define QIB_E_P_REBP ERR_MASK_N(RcvEBPErr)
  894. #define QIB_E_P_RUNSUPVL ERR_MASK_N(RcvUnsupportedVLErr)
  895. #define QIB_E_P_RUNEXPCHAR ERR_MASK_N(RcvUnexpectedCharErr)
  896. #define QIB_E_P_RSHORTPKTLEN ERR_MASK_N(RcvShortPktLenErr)
  897. #define QIB_E_P_RLONGPKTLEN ERR_MASK_N(RcvLongPktLenErr)
  898. #define QIB_E_P_RMAXPKTLEN ERR_MASK_N(RcvMaxPktLenErr)
  899. #define QIB_E_P_RMINPKTLEN ERR_MASK_N(RcvMinPktLenErr)
  900. #define QIB_E_P_RICRC ERR_MASK_N(RcvICRCErr)
  901. #define QIB_E_P_RVCRC ERR_MASK_N(RcvVCRCErr)
  902. #define QIB_E_P_RFORMATERR ERR_MASK_N(RcvFormatErr)
  903. #define QIB_E_P_SDMA1STDESC ERR_MASK_N(SDma1stDescErr)
  904. #define QIB_E_P_SDMABASE ERR_MASK_N(SDmaBaseErr)
  905. #define QIB_E_P_SDMADESCADDRMISALIGN ERR_MASK_N(SDmaDescAddrMisalignErr)
  906. #define QIB_E_P_SDMADWEN ERR_MASK_N(SDmaDwEnErr)
  907. #define QIB_E_P_SDMAGENMISMATCH ERR_MASK_N(SDmaGenMismatchErr)
  908. #define QIB_E_P_SDMAHALT ERR_MASK_N(SDmaHaltErr)
  909. #define QIB_E_P_SDMAMISSINGDW ERR_MASK_N(SDmaMissingDwErr)
  910. #define QIB_E_P_SDMAOUTOFBOUND ERR_MASK_N(SDmaOutOfBoundErr)
  911. #define QIB_E_P_SDMARPYTAG ERR_MASK_N(SDmaRpyTagErr)
  912. #define QIB_E_P_SDMATAILOUTOFBOUND ERR_MASK_N(SDmaTailOutOfBoundErr)
  913. #define QIB_E_P_SDMAUNEXPDATA ERR_MASK_N(SDmaUnexpDataErr)
  914. /* Error bits that are common to a device */
  915. #define QIB_E_RESET ERR_MASK(ResetNegated)
  916. #define QIB_E_HARDWARE ERR_MASK(HardwareErr)
  917. #define QIB_E_INVALIDADDR ERR_MASK(InvalidAddrErr)
  918. /*
  919. * Per chip (rather than per-port) errors. Most either do
  920. * nothing but trigger a print (because they self-recover, or
  921. * always occur in tandem with other errors that handle the
  922. * issue), or because they indicate errors with no recovery,
  923. * but we want to know that they happened.
  924. */
  925. #define QIB_E_SBUF_VL15_MISUSE ERR_MASK(SBufVL15MisUseErr)
  926. #define QIB_E_BADEEP ERR_MASK(InvalidEEPCmd)
  927. #define QIB_E_VLMISMATCH ERR_MASK(SendVLMismatchErr)
  928. #define QIB_E_ARMLAUNCH ERR_MASK(SendArmLaunchErr)
  929. #define QIB_E_SPCLTRIG ERR_MASK(SendSpecialTriggerErr)
  930. #define QIB_E_RRCVHDRFULL ERR_MASK(RcvHdrFullErr)
  931. #define QIB_E_RRCVEGRFULL ERR_MASK(RcvEgrFullErr)
  932. #define QIB_E_RCVCTXTSHARE ERR_MASK(RcvContextShareErr)
  933. /* SDMA chip errors (not per port)
  934. * QIB_E_SDMA_BUF_DUP needs no special handling, because we will also get
  935. * the SDMAHALT error immediately, so we just print the dup error via the
  936. * E_AUTO mechanism. This is true of most of the per-port fatal errors
  937. * as well, but since this is port-independent, by definition, it's
  938. * handled a bit differently. SDMA_VL15 and SDMA_WRONG_PORT are per
  939. * packet send errors, and so are handled in the same manner as other
  940. * per-packet errors.
  941. */
  942. #define QIB_E_SDMA_VL15 ERR_MASK(SDmaVL15Err)
  943. #define QIB_E_SDMA_WRONG_PORT ERR_MASK(SDmaWrongPortErr)
  944. #define QIB_E_SDMA_BUF_DUP ERR_MASK(SDmaBufMaskDuplicateErr)
  945. /*
  946. * Below functionally equivalent to legacy QLOGIC_IB_E_PKTERRS
  947. * it is used to print "common" packet errors.
  948. */
  949. #define QIB_E_P_PKTERRS (QIB_E_P_SPKTLEN |\
  950. QIB_E_P_SDROP_DATA | QIB_E_P_RVCRC |\
  951. QIB_E_P_RICRC | QIB_E_P_RSHORTPKTLEN |\
  952. QIB_E_P_VL15_BUF_MISUSE | QIB_E_P_SHDR | \
  953. QIB_E_P_REBP)
  954. /* Error Bits that Packet-related (Receive, per-port) */
  955. #define QIB_E_P_RPKTERRS (\
  956. QIB_E_P_RHDRLEN | QIB_E_P_RBADTID | \
  957. QIB_E_P_RBADVERSION | QIB_E_P_RHDR | \
  958. QIB_E_P_RLONGPKTLEN | QIB_E_P_RSHORTPKTLEN |\
  959. QIB_E_P_RMAXPKTLEN | QIB_E_P_RMINPKTLEN | \
  960. QIB_E_P_RFORMATERR | QIB_E_P_RUNSUPVL | \
  961. QIB_E_P_RUNEXPCHAR | QIB_E_P_RIBFLOW | QIB_E_P_REBP)
  962. /*
  963. * Error bits that are Send-related (per port)
  964. * (ARMLAUNCH excluded from E_SPKTERRS because it gets special handling).
  965. * All of these potentially need to have a buffer disarmed
  966. */
  967. #define QIB_E_P_SPKTERRS (\
  968. QIB_E_P_SUNEXP_PKTNUM |\
  969. QIB_E_P_SDROP_DATA | QIB_E_P_SDROP_SMP |\
  970. QIB_E_P_SMAXPKTLEN |\
  971. QIB_E_P_VL15_BUF_MISUSE | QIB_E_P_SHDR | \
  972. QIB_E_P_SMINPKTLEN | QIB_E_P_SPKTLEN | \
  973. QIB_E_P_SND_BUF_MISUSE | QIB_E_P_SUNSUPVL)
  974. #define QIB_E_SPKTERRS ( \
  975. QIB_E_SBUF_VL15_MISUSE | QIB_E_VLMISMATCH | \
  976. ERR_MASK_N(SendUnsupportedVLErr) | \
  977. QIB_E_SPCLTRIG | QIB_E_SDMA_VL15 | QIB_E_SDMA_WRONG_PORT)
  978. #define QIB_E_P_SDMAERRS ( \
  979. QIB_E_P_SDMAHALT | \
  980. QIB_E_P_SDMADESCADDRMISALIGN | \
  981. QIB_E_P_SDMAUNEXPDATA | \
  982. QIB_E_P_SDMAMISSINGDW | \
  983. QIB_E_P_SDMADWEN | \
  984. QIB_E_P_SDMARPYTAG | \
  985. QIB_E_P_SDMA1STDESC | \
  986. QIB_E_P_SDMABASE | \
  987. QIB_E_P_SDMATAILOUTOFBOUND | \
  988. QIB_E_P_SDMAOUTOFBOUND | \
  989. QIB_E_P_SDMAGENMISMATCH)
  990. /*
  991. * This sets some bits more than once, but makes it more obvious which
  992. * bits are not handled under other categories, and the repeat definition
  993. * is not a problem.
  994. */
  995. #define QIB_E_P_BITSEXTANT ( \
  996. QIB_E_P_SPKTERRS | QIB_E_P_PKTERRS | QIB_E_P_RPKTERRS | \
  997. QIB_E_P_RIBLOSTLINK | QIB_E_P_IBSTATUSCHANGED | \
  998. QIB_E_P_SND_BUF_MISUSE | QIB_E_P_SUNDERRUN | \
  999. QIB_E_P_SHDR | QIB_E_P_VL15_BUF_MISUSE | QIB_E_P_SDMAERRS \
  1000. )
  1001. /*
  1002. * These are errors that can occur when the link
  1003. * changes state while a packet is being sent or received. This doesn't
  1004. * cover things like EBP or VCRC that can be the result of a sending
  1005. * having the link change state, so we receive a "known bad" packet.
  1006. * All of these are "per port", so renamed:
  1007. */
  1008. #define QIB_E_P_LINK_PKTERRS (\
  1009. QIB_E_P_SDROP_DATA | QIB_E_P_SDROP_SMP |\
  1010. QIB_E_P_SMINPKTLEN | QIB_E_P_SPKTLEN |\
  1011. QIB_E_P_RSHORTPKTLEN | QIB_E_P_RMINPKTLEN |\
  1012. QIB_E_P_RUNEXPCHAR)
  1013. /*
  1014. * This sets some bits more than once, but makes it more obvious which
  1015. * bits are not handled under other categories (such as QIB_E_SPKTERRS),
  1016. * and the repeat definition is not a problem.
  1017. */
  1018. #define QIB_E_C_BITSEXTANT (\
  1019. QIB_E_HARDWARE | QIB_E_INVALIDADDR | QIB_E_BADEEP |\
  1020. QIB_E_ARMLAUNCH | QIB_E_VLMISMATCH | QIB_E_RRCVHDRFULL |\
  1021. QIB_E_RRCVEGRFULL | QIB_E_RESET | QIB_E_SBUF_VL15_MISUSE)
  1022. /* Likewise Neuter E_SPKT_ERRS_IGNORE */
  1023. #define E_SPKT_ERRS_IGNORE 0
  1024. #define QIB_EXTS_MEMBIST_DISABLED \
  1025. SYM_MASK(EXTStatus, MemBISTDisabled)
  1026. #define QIB_EXTS_MEMBIST_ENDTEST \
  1027. SYM_MASK(EXTStatus, MemBISTEndTest)
  1028. #define QIB_E_SPIOARMLAUNCH \
  1029. ERR_MASK(SendArmLaunchErr)
  1030. #define IBA7322_IBCC_LINKINITCMD_MASK SYM_RMASK(IBCCtrlA_0, LinkInitCmd)
  1031. #define IBA7322_IBCC_LINKCMD_SHIFT SYM_LSB(IBCCtrlA_0, LinkCmd)
  1032. /*
  1033. * IBTA_1_2 is set when multiple speeds are enabled (normal),
  1034. * and also if forced QDR (only QDR enabled). It's enabled for the
  1035. * forced QDR case so that scrambling will be enabled by the TS3
  1036. * exchange, when supported by both sides of the link.
  1037. */
  1038. #define IBA7322_IBC_IBTA_1_2_MASK SYM_MASK(IBCCtrlB_0, IB_ENHANCED_MODE)
  1039. #define IBA7322_IBC_MAX_SPEED_MASK SYM_MASK(IBCCtrlB_0, SD_SPEED)
  1040. #define IBA7322_IBC_SPEED_QDR SYM_MASK(IBCCtrlB_0, SD_SPEED_QDR)
  1041. #define IBA7322_IBC_SPEED_DDR SYM_MASK(IBCCtrlB_0, SD_SPEED_DDR)
  1042. #define IBA7322_IBC_SPEED_SDR SYM_MASK(IBCCtrlB_0, SD_SPEED_SDR)
  1043. #define IBA7322_IBC_SPEED_MASK (SYM_MASK(IBCCtrlB_0, SD_SPEED_SDR) | \
  1044. SYM_MASK(IBCCtrlB_0, SD_SPEED_DDR) | SYM_MASK(IBCCtrlB_0, SD_SPEED_QDR))
  1045. #define IBA7322_IBC_SPEED_LSB SYM_LSB(IBCCtrlB_0, SD_SPEED_SDR)
  1046. #define IBA7322_LEDBLINK_OFF_SHIFT SYM_LSB(RcvPktLEDCnt_0, OFFperiod)
  1047. #define IBA7322_LEDBLINK_ON_SHIFT SYM_LSB(RcvPktLEDCnt_0, ONperiod)
  1048. #define IBA7322_IBC_WIDTH_AUTONEG SYM_MASK(IBCCtrlB_0, IB_NUM_CHANNELS)
  1049. #define IBA7322_IBC_WIDTH_4X_ONLY (1<<SYM_LSB(IBCCtrlB_0, IB_NUM_CHANNELS))
  1050. #define IBA7322_IBC_WIDTH_1X_ONLY (0<<SYM_LSB(IBCCtrlB_0, IB_NUM_CHANNELS))
  1051. #define IBA7322_IBC_RXPOL_MASK SYM_MASK(IBCCtrlB_0, IB_POLARITY_REV_SUPP)
  1052. #define IBA7322_IBC_RXPOL_LSB SYM_LSB(IBCCtrlB_0, IB_POLARITY_REV_SUPP)
  1053. #define IBA7322_IBC_HRTBT_MASK (SYM_MASK(IBCCtrlB_0, HRTBT_AUTO) | \
  1054. SYM_MASK(IBCCtrlB_0, HRTBT_ENB))
  1055. #define IBA7322_IBC_HRTBT_RMASK (IBA7322_IBC_HRTBT_MASK >> \
  1056. SYM_LSB(IBCCtrlB_0, HRTBT_ENB))
  1057. #define IBA7322_IBC_HRTBT_LSB SYM_LSB(IBCCtrlB_0, HRTBT_ENB)
  1058. #define IBA7322_REDIRECT_VEC_PER_REG 12
  1059. #define IBA7322_SENDCHK_PKEY SYM_MASK(SendCheckControl_0, PKey_En)
  1060. #define IBA7322_SENDCHK_BTHQP SYM_MASK(SendCheckControl_0, BTHQP_En)
  1061. #define IBA7322_SENDCHK_SLID SYM_MASK(SendCheckControl_0, SLID_En)
  1062. #define IBA7322_SENDCHK_RAW_IPV6 SYM_MASK(SendCheckControl_0, RawIPV6_En)
  1063. #define IBA7322_SENDCHK_MINSZ SYM_MASK(SendCheckControl_0, PacketTooSmall_En)
  1064. #define AUTONEG_TRIES 3 /* sequential retries to negotiate DDR */
  1065. #define HWE_AUTO(fldname) { .mask = SYM_MASK(HwErrMask, fldname##Mask), \
  1066. .msg = #fldname , .sz = sizeof(#fldname) }
  1067. #define HWE_AUTO_P(fldname, port) { .mask = SYM_MASK(HwErrMask, \
  1068. fldname##Mask##_##port), .msg = #fldname , .sz = sizeof(#fldname) }
  1069. static const struct qib_hwerror_msgs qib_7322_hwerror_msgs[] = {
  1070. HWE_AUTO_P(IBSerdesPClkNotDetect, 1),
  1071. HWE_AUTO_P(IBSerdesPClkNotDetect, 0),
  1072. HWE_AUTO(PCIESerdesPClkNotDetect),
  1073. HWE_AUTO(PowerOnBISTFailed),
  1074. HWE_AUTO(TempsenseTholdReached),
  1075. HWE_AUTO(MemoryErr),
  1076. HWE_AUTO(PCIeBusParityErr),
  1077. HWE_AUTO(PcieCplTimeout),
  1078. HWE_AUTO(PciePoisonedTLP),
  1079. HWE_AUTO_P(SDmaMemReadErr, 1),
  1080. HWE_AUTO_P(SDmaMemReadErr, 0),
  1081. HWE_AUTO_P(IBCBusFromSPCParityErr, 1),
  1082. HWE_AUTO_P(IBCBusToSPCParityErr, 1),
  1083. HWE_AUTO_P(IBCBusFromSPCParityErr, 0),
  1084. HWE_AUTO(statusValidNoEop),
  1085. HWE_AUTO(LATriggered),
  1086. { .mask = 0, .sz = 0 }
  1087. };
  1088. #define E_AUTO(fldname) { .mask = SYM_MASK(ErrMask, fldname##Mask), \
  1089. .msg = #fldname, .sz = sizeof(#fldname) }
  1090. #define E_P_AUTO(fldname) { .mask = SYM_MASK(ErrMask_0, fldname##Mask), \
  1091. .msg = #fldname, .sz = sizeof(#fldname) }
  1092. static const struct qib_hwerror_msgs qib_7322error_msgs[] = {
  1093. E_AUTO(RcvEgrFullErr),
  1094. E_AUTO(RcvHdrFullErr),
  1095. E_AUTO(ResetNegated),
  1096. E_AUTO(HardwareErr),
  1097. E_AUTO(InvalidAddrErr),
  1098. E_AUTO(SDmaVL15Err),
  1099. E_AUTO(SBufVL15MisUseErr),
  1100. E_AUTO(InvalidEEPCmd),
  1101. E_AUTO(RcvContextShareErr),
  1102. E_AUTO(SendVLMismatchErr),
  1103. E_AUTO(SendArmLaunchErr),
  1104. E_AUTO(SendSpecialTriggerErr),
  1105. E_AUTO(SDmaWrongPortErr),
  1106. E_AUTO(SDmaBufMaskDuplicateErr),
  1107. { .mask = 0, .sz = 0 }
  1108. };
  1109. static const struct qib_hwerror_msgs qib_7322p_error_msgs[] = {
  1110. E_P_AUTO(IBStatusChanged),
  1111. E_P_AUTO(SHeadersErr),
  1112. E_P_AUTO(VL15BufMisuseErr),
  1113. /*
  1114. * SDmaHaltErr is not really an error, make it clearer;
  1115. */
  1116. {.mask = SYM_MASK(ErrMask_0, SDmaHaltErrMask), .msg = "SDmaHalted",
  1117. .sz = 11},
  1118. E_P_AUTO(SDmaDescAddrMisalignErr),
  1119. E_P_AUTO(SDmaUnexpDataErr),
  1120. E_P_AUTO(SDmaMissingDwErr),
  1121. E_P_AUTO(SDmaDwEnErr),
  1122. E_P_AUTO(SDmaRpyTagErr),
  1123. E_P_AUTO(SDma1stDescErr),
  1124. E_P_AUTO(SDmaBaseErr),
  1125. E_P_AUTO(SDmaTailOutOfBoundErr),
  1126. E_P_AUTO(SDmaOutOfBoundErr),
  1127. E_P_AUTO(SDmaGenMismatchErr),
  1128. E_P_AUTO(SendBufMisuseErr),
  1129. E_P_AUTO(SendUnsupportedVLErr),
  1130. E_P_AUTO(SendUnexpectedPktNumErr),
  1131. E_P_AUTO(SendDroppedDataPktErr),
  1132. E_P_AUTO(SendDroppedSmpPktErr),
  1133. E_P_AUTO(SendPktLenErr),
  1134. E_P_AUTO(SendUnderRunErr),
  1135. E_P_AUTO(SendMaxPktLenErr),
  1136. E_P_AUTO(SendMinPktLenErr),
  1137. E_P_AUTO(RcvIBLostLinkErr),
  1138. E_P_AUTO(RcvHdrErr),
  1139. E_P_AUTO(RcvHdrLenErr),
  1140. E_P_AUTO(RcvBadTidErr),
  1141. E_P_AUTO(RcvBadVersionErr),
  1142. E_P_AUTO(RcvIBFlowErr),
  1143. E_P_AUTO(RcvEBPErr),
  1144. E_P_AUTO(RcvUnsupportedVLErr),
  1145. E_P_AUTO(RcvUnexpectedCharErr),
  1146. E_P_AUTO(RcvShortPktLenErr),
  1147. E_P_AUTO(RcvLongPktLenErr),
  1148. E_P_AUTO(RcvMaxPktLenErr),
  1149. E_P_AUTO(RcvMinPktLenErr),
  1150. E_P_AUTO(RcvICRCErr),
  1151. E_P_AUTO(RcvVCRCErr),
  1152. E_P_AUTO(RcvFormatErr),
  1153. { .mask = 0, .sz = 0 }
  1154. };
  1155. /*
  1156. * Below generates "auto-message" for interrupts not specific to any port or
  1157. * context
  1158. */
  1159. #define INTR_AUTO(fldname) { .mask = SYM_MASK(IntMask, fldname##Mask), \
  1160. .msg = #fldname, .sz = sizeof(#fldname) }
  1161. /* Below generates "auto-message" for interrupts specific to a port */
  1162. #define INTR_AUTO_P(fldname) { .mask = MASK_ACROSS(\
  1163. SYM_LSB(IntMask, fldname##Mask##_0), \
  1164. SYM_LSB(IntMask, fldname##Mask##_1)), \
  1165. .msg = #fldname "_P", .sz = sizeof(#fldname "_P") }
  1166. /* For some reason, the SerDesTrimDone bits are reversed */
  1167. #define INTR_AUTO_PI(fldname) { .mask = MASK_ACROSS(\
  1168. SYM_LSB(IntMask, fldname##Mask##_1), \
  1169. SYM_LSB(IntMask, fldname##Mask##_0)), \
  1170. .msg = #fldname "_P", .sz = sizeof(#fldname "_P") }
  1171. /*
  1172. * Below generates "auto-message" for interrupts specific to a context,
  1173. * with ctxt-number appended
  1174. */
  1175. #define INTR_AUTO_C(fldname) { .mask = MASK_ACROSS(\
  1176. SYM_LSB(IntMask, fldname##0IntMask), \
  1177. SYM_LSB(IntMask, fldname##17IntMask)), \
  1178. .msg = #fldname "_C", .sz = sizeof(#fldname "_C") }
  1179. static const struct qib_hwerror_msgs qib_7322_intr_msgs[] = {
  1180. INTR_AUTO_P(SDmaInt),
  1181. INTR_AUTO_P(SDmaProgressInt),
  1182. INTR_AUTO_P(SDmaIdleInt),
  1183. INTR_AUTO_P(SDmaCleanupDone),
  1184. INTR_AUTO_C(RcvUrg),
  1185. INTR_AUTO_P(ErrInt),
  1186. INTR_AUTO(ErrInt), /* non-port-specific errs */
  1187. INTR_AUTO(AssertGPIOInt),
  1188. INTR_AUTO_P(SendDoneInt),
  1189. INTR_AUTO(SendBufAvailInt),
  1190. INTR_AUTO_C(RcvAvail),
  1191. { .mask = 0, .sz = 0 }
  1192. };
  1193. #define TXSYMPTOM_AUTO_P(fldname) \
  1194. { .mask = SYM_MASK(SendHdrErrSymptom_0, fldname), \
  1195. .msg = #fldname, .sz = sizeof(#fldname) }
  1196. static const struct qib_hwerror_msgs hdrchk_msgs[] = {
  1197. TXSYMPTOM_AUTO_P(NonKeyPacket),
  1198. TXSYMPTOM_AUTO_P(GRHFail),
  1199. TXSYMPTOM_AUTO_P(PkeyFail),
  1200. TXSYMPTOM_AUTO_P(QPFail),
  1201. TXSYMPTOM_AUTO_P(SLIDFail),
  1202. TXSYMPTOM_AUTO_P(RawIPV6),
  1203. TXSYMPTOM_AUTO_P(PacketTooSmall),
  1204. { .mask = 0, .sz = 0 }
  1205. };
  1206. #define IBA7322_HDRHEAD_PKTINT_SHIFT 32 /* interrupt cnt in upper 32 bits */
  1207. /*
  1208. * Called when we might have an error that is specific to a particular
  1209. * PIO buffer, and may need to cancel that buffer, so it can be re-used,
  1210. * because we don't need to force the update of pioavail
  1211. */
  1212. static void qib_disarm_7322_senderrbufs(struct qib_pportdata *ppd)
  1213. {
  1214. struct qib_devdata *dd = ppd->dd;
  1215. u32 i;
  1216. int any;
  1217. u32 piobcnt = dd->piobcnt2k + dd->piobcnt4k + NUM_VL15_BUFS;
  1218. u32 regcnt = (piobcnt + BITS_PER_LONG - 1) / BITS_PER_LONG;
  1219. unsigned long sbuf[4];
  1220. /*
  1221. * It's possible that sendbuffererror could have bits set; might
  1222. * have already done this as a result of hardware error handling.
  1223. */
  1224. any = 0;
  1225. for (i = 0; i < regcnt; ++i) {
  1226. sbuf[i] = qib_read_kreg64(dd, kr_sendbuffererror + i);
  1227. if (sbuf[i]) {
  1228. any = 1;
  1229. qib_write_kreg(dd, kr_sendbuffererror + i, sbuf[i]);
  1230. }
  1231. }
  1232. if (any)
  1233. qib_disarm_piobufs_set(dd, sbuf, piobcnt);
  1234. }
  1235. /* No txe_recover yet, if ever */
  1236. /* No decode__errors yet */
  1237. static void err_decode(char *msg, size_t len, u64 errs,
  1238. const struct qib_hwerror_msgs *msp)
  1239. {
  1240. u64 these, lmask;
  1241. int took, multi, n = 0;
  1242. while (errs && msp && msp->mask) {
  1243. multi = (msp->mask & (msp->mask - 1));
  1244. while (errs & msp->mask) {
  1245. these = (errs & msp->mask);
  1246. lmask = (these & (these - 1)) ^ these;
  1247. if (len) {
  1248. if (n++) {
  1249. /* separate the strings */
  1250. *msg++ = ',';
  1251. len--;
  1252. }
  1253. BUG_ON(!msp->sz);
  1254. /* msp->sz counts the nul */
  1255. took = min_t(size_t, msp->sz - (size_t)1, len);
  1256. memcpy(msg, msp->msg, took);
  1257. len -= took;
  1258. msg += took;
  1259. if (len)
  1260. *msg = '\0';
  1261. }
  1262. errs &= ~lmask;
  1263. if (len && multi) {
  1264. /* More than one bit this mask */
  1265. int idx = -1;
  1266. while (lmask & msp->mask) {
  1267. ++idx;
  1268. lmask >>= 1;
  1269. }
  1270. took = scnprintf(msg, len, "_%d", idx);
  1271. len -= took;
  1272. msg += took;
  1273. }
  1274. }
  1275. ++msp;
  1276. }
  1277. /* If some bits are left, show in hex. */
  1278. if (len && errs)
  1279. snprintf(msg, len, "%sMORE:%llX", n ? "," : "",
  1280. (unsigned long long) errs);
  1281. }
  1282. /* only called if r1 set */
  1283. static void flush_fifo(struct qib_pportdata *ppd)
  1284. {
  1285. struct qib_devdata *dd = ppd->dd;
  1286. u32 __iomem *piobuf;
  1287. u32 bufn;
  1288. u32 *hdr;
  1289. u64 pbc;
  1290. const unsigned hdrwords = 7;
  1291. static struct qib_ib_header ibhdr = {
  1292. .lrh[0] = cpu_to_be16(0xF000 | QIB_LRH_BTH),
  1293. .lrh[1] = IB_LID_PERMISSIVE,
  1294. .lrh[2] = cpu_to_be16(hdrwords + SIZE_OF_CRC),
  1295. .lrh[3] = IB_LID_PERMISSIVE,
  1296. .u.oth.bth[0] = cpu_to_be32(
  1297. (IB_OPCODE_UD_SEND_ONLY << 24) | QIB_DEFAULT_P_KEY),
  1298. .u.oth.bth[1] = cpu_to_be32(0),
  1299. .u.oth.bth[2] = cpu_to_be32(0),
  1300. .u.oth.u.ud.deth[0] = cpu_to_be32(0),
  1301. .u.oth.u.ud.deth[1] = cpu_to_be32(0),
  1302. };
  1303. /*
  1304. * Send a dummy VL15 packet to flush the launch FIFO.
  1305. * This will not actually be sent since the TxeBypassIbc bit is set.
  1306. */
  1307. pbc = PBC_7322_VL15_SEND |
  1308. (((u64)ppd->hw_pidx) << (PBC_PORT_SEL_LSB + 32)) |
  1309. (hdrwords + SIZE_OF_CRC);
  1310. piobuf = qib_7322_getsendbuf(ppd, pbc, &bufn);
  1311. if (!piobuf)
  1312. return;
  1313. writeq(pbc, piobuf);
  1314. hdr = (u32 *) &ibhdr;
  1315. if (dd->flags & QIB_PIO_FLUSH_WC) {
  1316. qib_flush_wc();
  1317. qib_pio_copy(piobuf + 2, hdr, hdrwords - 1);
  1318. qib_flush_wc();
  1319. __raw_writel(hdr[hdrwords - 1], piobuf + hdrwords + 1);
  1320. qib_flush_wc();
  1321. } else
  1322. qib_pio_copy(piobuf + 2, hdr, hdrwords);
  1323. qib_sendbuf_done(dd, bufn);
  1324. }
  1325. /*
  1326. * This is called with interrupts disabled and sdma_lock held.
  1327. */
  1328. static void qib_7322_sdma_sendctrl(struct qib_pportdata *ppd, unsigned op)
  1329. {
  1330. struct qib_devdata *dd = ppd->dd;
  1331. u64 set_sendctrl = 0;
  1332. u64 clr_sendctrl = 0;
  1333. if (op & QIB_SDMA_SENDCTRL_OP_ENABLE)
  1334. set_sendctrl |= SYM_MASK(SendCtrl_0, SDmaEnable);
  1335. else
  1336. clr_sendctrl |= SYM_MASK(SendCtrl_0, SDmaEnable);
  1337. if (op & QIB_SDMA_SENDCTRL_OP_INTENABLE)
  1338. set_sendctrl |= SYM_MASK(SendCtrl_0, SDmaIntEnable);
  1339. else
  1340. clr_sendctrl |= SYM_MASK(SendCtrl_0, SDmaIntEnable);
  1341. if (op & QIB_SDMA_SENDCTRL_OP_HALT)
  1342. set_sendctrl |= SYM_MASK(SendCtrl_0, SDmaHalt);
  1343. else
  1344. clr_sendctrl |= SYM_MASK(SendCtrl_0, SDmaHalt);
  1345. if (op & QIB_SDMA_SENDCTRL_OP_DRAIN)
  1346. set_sendctrl |= SYM_MASK(SendCtrl_0, TxeBypassIbc) |
  1347. SYM_MASK(SendCtrl_0, TxeAbortIbc) |
  1348. SYM_MASK(SendCtrl_0, TxeDrainRmFifo);
  1349. else
  1350. clr_sendctrl |= SYM_MASK(SendCtrl_0, TxeBypassIbc) |
  1351. SYM_MASK(SendCtrl_0, TxeAbortIbc) |
  1352. SYM_MASK(SendCtrl_0, TxeDrainRmFifo);
  1353. spin_lock(&dd->sendctrl_lock);
  1354. /* If we are draining everything, block sends first */
  1355. if (op & QIB_SDMA_SENDCTRL_OP_DRAIN) {
  1356. ppd->p_sendctrl &= ~SYM_MASK(SendCtrl_0, SendEnable);
  1357. qib_write_kreg_port(ppd, krp_sendctrl, ppd->p_sendctrl);
  1358. qib_write_kreg(dd, kr_scratch, 0);
  1359. }
  1360. ppd->p_sendctrl |= set_sendctrl;
  1361. ppd->p_sendctrl &= ~clr_sendctrl;
  1362. if (op & QIB_SDMA_SENDCTRL_OP_CLEANUP)
  1363. qib_write_kreg_port(ppd, krp_sendctrl,
  1364. ppd->p_sendctrl |
  1365. SYM_MASK(SendCtrl_0, SDmaCleanup));
  1366. else
  1367. qib_write_kreg_port(ppd, krp_sendctrl, ppd->p_sendctrl);
  1368. qib_write_kreg(dd, kr_scratch, 0);
  1369. if (op & QIB_SDMA_SENDCTRL_OP_DRAIN) {
  1370. ppd->p_sendctrl |= SYM_MASK(SendCtrl_0, SendEnable);
  1371. qib_write_kreg_port(ppd, krp_sendctrl, ppd->p_sendctrl);
  1372. qib_write_kreg(dd, kr_scratch, 0);
  1373. }
  1374. spin_unlock(&dd->sendctrl_lock);
  1375. if ((op & QIB_SDMA_SENDCTRL_OP_DRAIN) && ppd->dd->cspec->r1)
  1376. flush_fifo(ppd);
  1377. }
  1378. static void qib_7322_sdma_hw_clean_up(struct qib_pportdata *ppd)
  1379. {
  1380. __qib_sdma_process_event(ppd, qib_sdma_event_e50_hw_cleaned);
  1381. }
  1382. static void qib_sdma_7322_setlengen(struct qib_pportdata *ppd)
  1383. {
  1384. /*
  1385. * Set SendDmaLenGen and clear and set
  1386. * the MSB of the generation count to enable generation checking
  1387. * and load the internal generation counter.
  1388. */
  1389. qib_write_kreg_port(ppd, krp_senddmalengen, ppd->sdma_descq_cnt);
  1390. qib_write_kreg_port(ppd, krp_senddmalengen,
  1391. ppd->sdma_descq_cnt |
  1392. (1ULL << QIB_7322_SendDmaLenGen_0_Generation_MSB));
  1393. }
  1394. /*
  1395. * Must be called with sdma_lock held, or before init finished.
  1396. */
  1397. static void qib_sdma_update_7322_tail(struct qib_pportdata *ppd, u16 tail)
  1398. {
  1399. /* Commit writes to memory and advance the tail on the chip */
  1400. wmb();
  1401. ppd->sdma_descq_tail = tail;
  1402. qib_write_kreg_port(ppd, krp_senddmatail, tail);
  1403. }
  1404. /*
  1405. * This is called with interrupts disabled and sdma_lock held.
  1406. */
  1407. static void qib_7322_sdma_hw_start_up(struct qib_pportdata *ppd)
  1408. {
  1409. /*
  1410. * Drain all FIFOs.
  1411. * The hardware doesn't require this but we do it so that verbs
  1412. * and user applications don't wait for link active to send stale
  1413. * data.
  1414. */
  1415. sendctrl_7322_mod(ppd, QIB_SENDCTRL_FLUSH);
  1416. qib_sdma_7322_setlengen(ppd);
  1417. qib_sdma_update_7322_tail(ppd, 0); /* Set SendDmaTail */
  1418. ppd->sdma_head_dma[0] = 0;
  1419. qib_7322_sdma_sendctrl(ppd,
  1420. ppd->sdma_state.current_op | QIB_SDMA_SENDCTRL_OP_CLEANUP);
  1421. }
  1422. #define DISABLES_SDMA ( \
  1423. QIB_E_P_SDMAHALT | \
  1424. QIB_E_P_SDMADESCADDRMISALIGN | \
  1425. QIB_E_P_SDMAMISSINGDW | \
  1426. QIB_E_P_SDMADWEN | \
  1427. QIB_E_P_SDMARPYTAG | \
  1428. QIB_E_P_SDMA1STDESC | \
  1429. QIB_E_P_SDMABASE | \
  1430. QIB_E_P_SDMATAILOUTOFBOUND | \
  1431. QIB_E_P_SDMAOUTOFBOUND | \
  1432. QIB_E_P_SDMAGENMISMATCH)
  1433. static void sdma_7322_p_errors(struct qib_pportdata *ppd, u64 errs)
  1434. {
  1435. unsigned long flags;
  1436. struct qib_devdata *dd = ppd->dd;
  1437. errs &= QIB_E_P_SDMAERRS;
  1438. err_decode(ppd->cpspec->sdmamsgbuf, sizeof(ppd->cpspec->sdmamsgbuf),
  1439. errs, qib_7322p_error_msgs);
  1440. if (errs & QIB_E_P_SDMAUNEXPDATA)
  1441. qib_dev_err(dd, "IB%u:%u SDmaUnexpData\n", dd->unit,
  1442. ppd->port);
  1443. spin_lock_irqsave(&ppd->sdma_lock, flags);
  1444. if (errs != QIB_E_P_SDMAHALT) {
  1445. /* SDMA errors have QIB_E_P_SDMAHALT and another bit set */
  1446. qib_dev_porterr(dd, ppd->port,
  1447. "SDMA %s 0x%016llx %s\n",
  1448. qib_sdma_state_names[ppd->sdma_state.current_state],
  1449. errs, ppd->cpspec->sdmamsgbuf);
  1450. dump_sdma_7322_state(ppd);
  1451. }
  1452. switch (ppd->sdma_state.current_state) {
  1453. case qib_sdma_state_s00_hw_down:
  1454. break;
  1455. case qib_sdma_state_s10_hw_start_up_wait:
  1456. if (errs & QIB_E_P_SDMAHALT)
  1457. __qib_sdma_process_event(ppd,
  1458. qib_sdma_event_e20_hw_started);
  1459. break;
  1460. case qib_sdma_state_s20_idle:
  1461. break;
  1462. case qib_sdma_state_s30_sw_clean_up_wait:
  1463. break;
  1464. case qib_sdma_state_s40_hw_clean_up_wait:
  1465. if (errs & QIB_E_P_SDMAHALT)
  1466. __qib_sdma_process_event(ppd,
  1467. qib_sdma_event_e50_hw_cleaned);
  1468. break;
  1469. case qib_sdma_state_s50_hw_halt_wait:
  1470. if (errs & QIB_E_P_SDMAHALT)
  1471. __qib_sdma_process_event(ppd,
  1472. qib_sdma_event_e60_hw_halted);
  1473. break;
  1474. case qib_sdma_state_s99_running:
  1475. __qib_sdma_process_event(ppd, qib_sdma_event_e7322_err_halted);
  1476. __qib_sdma_process_event(ppd, qib_sdma_event_e60_hw_halted);
  1477. break;
  1478. }
  1479. spin_unlock_irqrestore(&ppd->sdma_lock, flags);
  1480. }
  1481. /*
  1482. * handle per-device errors (not per-port errors)
  1483. */
  1484. static noinline void handle_7322_errors(struct qib_devdata *dd)
  1485. {
  1486. char *msg;
  1487. u64 iserr = 0;
  1488. u64 errs;
  1489. u64 mask;
  1490. int log_idx;
  1491. qib_stats.sps_errints++;
  1492. errs = qib_read_kreg64(dd, kr_errstatus);
  1493. if (!errs) {
  1494. qib_devinfo(dd->pcidev,
  1495. "device error interrupt, but no error bits set!\n");
  1496. goto done;
  1497. }
  1498. /* don't report errors that are masked */
  1499. errs &= dd->cspec->errormask;
  1500. msg = dd->cspec->emsgbuf;
  1501. /* do these first, they are most important */
  1502. if (errs & QIB_E_HARDWARE) {
  1503. *msg = '\0';
  1504. qib_7322_handle_hwerrors(dd, msg, sizeof dd->cspec->emsgbuf);
  1505. } else
  1506. for (log_idx = 0; log_idx < QIB_EEP_LOG_CNT; ++log_idx)
  1507. if (errs & dd->eep_st_masks[log_idx].errs_to_log)
  1508. qib_inc_eeprom_err(dd, log_idx, 1);
  1509. if (errs & QIB_E_SPKTERRS) {
  1510. qib_disarm_7322_senderrbufs(dd->pport);
  1511. qib_stats.sps_txerrs++;
  1512. } else if (errs & QIB_E_INVALIDADDR)
  1513. qib_stats.sps_txerrs++;
  1514. else if (errs & QIB_E_ARMLAUNCH) {
  1515. qib_stats.sps_txerrs++;
  1516. qib_disarm_7322_senderrbufs(dd->pport);
  1517. }
  1518. qib_write_kreg(dd, kr_errclear, errs);
  1519. /*
  1520. * The ones we mask off are handled specially below
  1521. * or above. Also mask SDMADISABLED by default as it
  1522. * is too chatty.
  1523. */
  1524. mask = QIB_E_HARDWARE;
  1525. *msg = '\0';
  1526. err_decode(msg, sizeof dd->cspec->emsgbuf, errs & ~mask,
  1527. qib_7322error_msgs);
  1528. /*
  1529. * Getting reset is a tragedy for all ports. Mark the device
  1530. * _and_ the ports as "offline" in way meaningful to each.
  1531. */
  1532. if (errs & QIB_E_RESET) {
  1533. int pidx;
  1534. qib_dev_err(dd,
  1535. "Got reset, requires re-init (unload and reload driver)\n");
  1536. dd->flags &= ~QIB_INITTED; /* needs re-init */
  1537. /* mark as having had error */
  1538. *dd->devstatusp |= QIB_STATUS_HWERROR;
  1539. for (pidx = 0; pidx < dd->num_pports; ++pidx)
  1540. if (dd->pport[pidx].link_speed_supported)
  1541. *dd->pport[pidx].statusp &= ~QIB_STATUS_IB_CONF;
  1542. }
  1543. if (*msg && iserr)
  1544. qib_dev_err(dd, "%s error\n", msg);
  1545. /*
  1546. * If there were hdrq or egrfull errors, wake up any processes
  1547. * waiting in poll. We used to try to check which contexts had
  1548. * the overflow, but given the cost of that and the chip reads
  1549. * to support it, it's better to just wake everybody up if we
  1550. * get an overflow; waiters can poll again if it's not them.
  1551. */
  1552. if (errs & (ERR_MASK(RcvEgrFullErr) | ERR_MASK(RcvHdrFullErr))) {
  1553. qib_handle_urcv(dd, ~0U);
  1554. if (errs & ERR_MASK(RcvEgrFullErr))
  1555. qib_stats.sps_buffull++;
  1556. else
  1557. qib_stats.sps_hdrfull++;
  1558. }
  1559. done:
  1560. return;
  1561. }
  1562. static void qib_error_tasklet(unsigned long data)
  1563. {
  1564. struct qib_devdata *dd = (struct qib_devdata *)data;
  1565. handle_7322_errors(dd);
  1566. qib_write_kreg(dd, kr_errmask, dd->cspec->errormask);
  1567. }
  1568. static void reenable_chase(unsigned long opaque)
  1569. {
  1570. struct qib_pportdata *ppd = (struct qib_pportdata *)opaque;
  1571. ppd->cpspec->chase_timer.expires = 0;
  1572. qib_set_ib_7322_lstate(ppd, QLOGIC_IB_IBCC_LINKCMD_DOWN,
  1573. QLOGIC_IB_IBCC_LINKINITCMD_POLL);
  1574. }
  1575. static void disable_chase(struct qib_pportdata *ppd, unsigned long tnow,
  1576. u8 ibclt)
  1577. {
  1578. ppd->cpspec->chase_end = 0;
  1579. if (!qib_chase)
  1580. return;
  1581. qib_set_ib_7322_lstate(ppd, QLOGIC_IB_IBCC_LINKCMD_DOWN,
  1582. QLOGIC_IB_IBCC_LINKINITCMD_DISABLE);
  1583. ppd->cpspec->chase_timer.expires = jiffies + QIB_CHASE_DIS_TIME;
  1584. add_timer(&ppd->cpspec->chase_timer);
  1585. }
  1586. static void handle_serdes_issues(struct qib_pportdata *ppd, u64 ibcst)
  1587. {
  1588. u8 ibclt;
  1589. unsigned long tnow;
  1590. ibclt = (u8)SYM_FIELD(ibcst, IBCStatusA_0, LinkTrainingState);
  1591. /*
  1592. * Detect and handle the state chase issue, where we can
  1593. * get stuck if we are unlucky on timing on both sides of
  1594. * the link. If we are, we disable, set a timer, and
  1595. * then re-enable.
  1596. */
  1597. switch (ibclt) {
  1598. case IB_7322_LT_STATE_CFGRCVFCFG:
  1599. case IB_7322_LT_STATE_CFGWAITRMT:
  1600. case IB_7322_LT_STATE_TXREVLANES:
  1601. case IB_7322_LT_STATE_CFGENH:
  1602. tnow = jiffies;
  1603. if (ppd->cpspec->chase_end &&
  1604. time_after(tnow, ppd->cpspec->chase_end))
  1605. disable_chase(ppd, tnow, ibclt);
  1606. else if (!ppd->cpspec->chase_end)
  1607. ppd->cpspec->chase_end = tnow + QIB_CHASE_TIME;
  1608. break;
  1609. default:
  1610. ppd->cpspec->chase_end = 0;
  1611. break;
  1612. }
  1613. if (((ibclt >= IB_7322_LT_STATE_CFGTEST &&
  1614. ibclt <= IB_7322_LT_STATE_CFGWAITENH) ||
  1615. ibclt == IB_7322_LT_STATE_LINKUP) &&
  1616. (ibcst & SYM_MASK(IBCStatusA_0, LinkSpeedQDR))) {
  1617. force_h1(ppd);
  1618. ppd->cpspec->qdr_reforce = 1;
  1619. if (!ppd->dd->cspec->r1)
  1620. serdes_7322_los_enable(ppd, 0);
  1621. } else if (ppd->cpspec->qdr_reforce &&
  1622. (ibcst & SYM_MASK(IBCStatusA_0, LinkSpeedQDR)) &&
  1623. (ibclt == IB_7322_LT_STATE_CFGENH ||
  1624. ibclt == IB_7322_LT_STATE_CFGIDLE ||
  1625. ibclt == IB_7322_LT_STATE_LINKUP))
  1626. force_h1(ppd);
  1627. if ((IS_QMH(ppd->dd) || IS_QME(ppd->dd)) &&
  1628. ppd->link_speed_enabled == QIB_IB_QDR &&
  1629. (ibclt == IB_7322_LT_STATE_CFGTEST ||
  1630. ibclt == IB_7322_LT_STATE_CFGENH ||
  1631. (ibclt >= IB_7322_LT_STATE_POLLACTIVE &&
  1632. ibclt <= IB_7322_LT_STATE_SLEEPQUIET)))
  1633. adj_tx_serdes(ppd);
  1634. if (ibclt != IB_7322_LT_STATE_LINKUP) {
  1635. u8 ltstate = qib_7322_phys_portstate(ibcst);
  1636. u8 pibclt = (u8)SYM_FIELD(ppd->lastibcstat, IBCStatusA_0,
  1637. LinkTrainingState);
  1638. if (!ppd->dd->cspec->r1 &&
  1639. pibclt == IB_7322_LT_STATE_LINKUP &&
  1640. ltstate != IB_PHYSPORTSTATE_LINK_ERR_RECOVER &&
  1641. ltstate != IB_PHYSPORTSTATE_RECOVERY_RETRAIN &&
  1642. ltstate != IB_PHYSPORTSTATE_RECOVERY_WAITRMT &&
  1643. ltstate != IB_PHYSPORTSTATE_RECOVERY_IDLE)
  1644. /* If the link went down (but no into recovery,
  1645. * turn LOS back on */
  1646. serdes_7322_los_enable(ppd, 1);
  1647. if (!ppd->cpspec->qdr_dfe_on &&
  1648. ibclt <= IB_7322_LT_STATE_SLEEPQUIET) {
  1649. ppd->cpspec->qdr_dfe_on = 1;
  1650. ppd->cpspec->qdr_dfe_time = 0;
  1651. /* On link down, reenable QDR adaptation */
  1652. qib_write_kreg_port(ppd, krp_static_adapt_dis(2),
  1653. ppd->dd->cspec->r1 ?
  1654. QDR_STATIC_ADAPT_DOWN_R1 :
  1655. QDR_STATIC_ADAPT_DOWN);
  1656. pr_info(
  1657. "IB%u:%u re-enabled QDR adaptation ibclt %x\n",
  1658. ppd->dd->unit, ppd->port, ibclt);
  1659. }
  1660. }
  1661. }
  1662. static int qib_7322_set_ib_cfg(struct qib_pportdata *, int, u32);
  1663. /*
  1664. * This is per-pport error handling.
  1665. * will likely get it's own MSIx interrupt (one for each port,
  1666. * although just a single handler).
  1667. */
  1668. static noinline void handle_7322_p_errors(struct qib_pportdata *ppd)
  1669. {
  1670. char *msg;
  1671. u64 ignore_this_time = 0, iserr = 0, errs, fmask;
  1672. struct qib_devdata *dd = ppd->dd;
  1673. /* do this as soon as possible */
  1674. fmask = qib_read_kreg64(dd, kr_act_fmask);
  1675. if (!fmask)
  1676. check_7322_rxe_status(ppd);
  1677. errs = qib_read_kreg_port(ppd, krp_errstatus);
  1678. if (!errs)
  1679. qib_devinfo(dd->pcidev,
  1680. "Port%d error interrupt, but no error bits set!\n",
  1681. ppd->port);
  1682. if (!fmask)
  1683. errs &= ~QIB_E_P_IBSTATUSCHANGED;
  1684. if (!errs)
  1685. goto done;
  1686. msg = ppd->cpspec->epmsgbuf;
  1687. *msg = '\0';
  1688. if (errs & ~QIB_E_P_BITSEXTANT) {
  1689. err_decode(msg, sizeof ppd->cpspec->epmsgbuf,
  1690. errs & ~QIB_E_P_BITSEXTANT, qib_7322p_error_msgs);
  1691. if (!*msg)
  1692. snprintf(msg, sizeof ppd->cpspec->epmsgbuf,
  1693. "no others");
  1694. qib_dev_porterr(dd, ppd->port,
  1695. "error interrupt with unknown errors 0x%016Lx set (and %s)\n",
  1696. (errs & ~QIB_E_P_BITSEXTANT), msg);
  1697. *msg = '\0';
  1698. }
  1699. if (errs & QIB_E_P_SHDR) {
  1700. u64 symptom;
  1701. /* determine cause, then write to clear */
  1702. symptom = qib_read_kreg_port(ppd, krp_sendhdrsymptom);
  1703. qib_write_kreg_port(ppd, krp_sendhdrsymptom, 0);
  1704. err_decode(msg, sizeof ppd->cpspec->epmsgbuf, symptom,
  1705. hdrchk_msgs);
  1706. *msg = '\0';
  1707. /* senderrbuf cleared in SPKTERRS below */
  1708. }
  1709. if (errs & QIB_E_P_SPKTERRS) {
  1710. if ((errs & QIB_E_P_LINK_PKTERRS) &&
  1711. !(ppd->lflags & QIBL_LINKACTIVE)) {
  1712. /*
  1713. * This can happen when trying to bring the link
  1714. * up, but the IB link changes state at the "wrong"
  1715. * time. The IB logic then complains that the packet
  1716. * isn't valid. We don't want to confuse people, so
  1717. * we just don't print them, except at debug
  1718. */
  1719. err_decode(msg, sizeof ppd->cpspec->epmsgbuf,
  1720. (errs & QIB_E_P_LINK_PKTERRS),
  1721. qib_7322p_error_msgs);
  1722. *msg = '\0';
  1723. ignore_this_time = errs & QIB_E_P_LINK_PKTERRS;
  1724. }
  1725. qib_disarm_7322_senderrbufs(ppd);
  1726. } else if ((errs & QIB_E_P_LINK_PKTERRS) &&
  1727. !(ppd->lflags & QIBL_LINKACTIVE)) {
  1728. /*
  1729. * This can happen when SMA is trying to bring the link
  1730. * up, but the IB link changes state at the "wrong" time.
  1731. * The IB logic then complains that the packet isn't
  1732. * valid. We don't want to confuse people, so we just
  1733. * don't print them, except at debug
  1734. */
  1735. err_decode(msg, sizeof ppd->cpspec->epmsgbuf, errs,
  1736. qib_7322p_error_msgs);
  1737. ignore_this_time = errs & QIB_E_P_LINK_PKTERRS;
  1738. *msg = '\0';
  1739. }
  1740. qib_write_kreg_port(ppd, krp_errclear, errs);
  1741. errs &= ~ignore_this_time;
  1742. if (!errs)
  1743. goto done;
  1744. if (errs & QIB_E_P_RPKTERRS)
  1745. qib_stats.sps_rcverrs++;
  1746. if (errs & QIB_E_P_SPKTERRS)
  1747. qib_stats.sps_txerrs++;
  1748. iserr = errs & ~(QIB_E_P_RPKTERRS | QIB_E_P_PKTERRS);
  1749. if (errs & QIB_E_P_SDMAERRS)
  1750. sdma_7322_p_errors(ppd, errs);
  1751. if (errs & QIB_E_P_IBSTATUSCHANGED) {
  1752. u64 ibcs;
  1753. u8 ltstate;
  1754. ibcs = qib_read_kreg_port(ppd, krp_ibcstatus_a);
  1755. ltstate = qib_7322_phys_portstate(ibcs);
  1756. if (!(ppd->lflags & QIBL_IB_AUTONEG_INPROG))
  1757. handle_serdes_issues(ppd, ibcs);
  1758. if (!(ppd->cpspec->ibcctrl_a &
  1759. SYM_MASK(IBCCtrlA_0, IBStatIntReductionEn))) {
  1760. /*
  1761. * We got our interrupt, so init code should be
  1762. * happy and not try alternatives. Now squelch
  1763. * other "chatter" from link-negotiation (pre Init)
  1764. */
  1765. ppd->cpspec->ibcctrl_a |=
  1766. SYM_MASK(IBCCtrlA_0, IBStatIntReductionEn);
  1767. qib_write_kreg_port(ppd, krp_ibcctrl_a,
  1768. ppd->cpspec->ibcctrl_a);
  1769. }
  1770. /* Update our picture of width and speed from chip */
  1771. ppd->link_width_active =
  1772. (ibcs & SYM_MASK(IBCStatusA_0, LinkWidthActive)) ?
  1773. IB_WIDTH_4X : IB_WIDTH_1X;
  1774. ppd->link_speed_active = (ibcs & SYM_MASK(IBCStatusA_0,
  1775. LinkSpeedQDR)) ? QIB_IB_QDR : (ibcs &
  1776. SYM_MASK(IBCStatusA_0, LinkSpeedActive)) ?
  1777. QIB_IB_DDR : QIB_IB_SDR;
  1778. if ((ppd->lflags & QIBL_IB_LINK_DISABLED) && ltstate !=
  1779. IB_PHYSPORTSTATE_DISABLED)
  1780. qib_set_ib_7322_lstate(ppd, 0,
  1781. QLOGIC_IB_IBCC_LINKINITCMD_DISABLE);
  1782. else
  1783. /*
  1784. * Since going into a recovery state causes the link
  1785. * state to go down and since recovery is transitory,
  1786. * it is better if we "miss" ever seeing the link
  1787. * training state go into recovery (i.e., ignore this
  1788. * transition for link state special handling purposes)
  1789. * without updating lastibcstat.
  1790. */
  1791. if (ltstate != IB_PHYSPORTSTATE_LINK_ERR_RECOVER &&
  1792. ltstate != IB_PHYSPORTSTATE_RECOVERY_RETRAIN &&
  1793. ltstate != IB_PHYSPORTSTATE_RECOVERY_WAITRMT &&
  1794. ltstate != IB_PHYSPORTSTATE_RECOVERY_IDLE)
  1795. qib_handle_e_ibstatuschanged(ppd, ibcs);
  1796. }
  1797. if (*msg && iserr)
  1798. qib_dev_porterr(dd, ppd->port, "%s error\n", msg);
  1799. if (ppd->state_wanted & ppd->lflags)
  1800. wake_up_interruptible(&ppd->state_wait);
  1801. done:
  1802. return;
  1803. }
  1804. /* enable/disable chip from delivering interrupts */
  1805. static void qib_7322_set_intr_state(struct qib_devdata *dd, u32 enable)
  1806. {
  1807. if (enable) {
  1808. if (dd->flags & QIB_BADINTR)
  1809. return;
  1810. qib_write_kreg(dd, kr_intmask, dd->cspec->int_enable_mask);
  1811. /* cause any pending enabled interrupts to be re-delivered */
  1812. qib_write_kreg(dd, kr_intclear, 0ULL);
  1813. if (dd->cspec->num_msix_entries) {
  1814. /* and same for MSIx */
  1815. u64 val = qib_read_kreg64(dd, kr_intgranted);
  1816. if (val)
  1817. qib_write_kreg(dd, kr_intgranted, val);
  1818. }
  1819. } else
  1820. qib_write_kreg(dd, kr_intmask, 0ULL);
  1821. }
  1822. /*
  1823. * Try to cleanup as much as possible for anything that might have gone
  1824. * wrong while in freeze mode, such as pio buffers being written by user
  1825. * processes (causing armlaunch), send errors due to going into freeze mode,
  1826. * etc., and try to avoid causing extra interrupts while doing so.
  1827. * Forcibly update the in-memory pioavail register copies after cleanup
  1828. * because the chip won't do it while in freeze mode (the register values
  1829. * themselves are kept correct).
  1830. * Make sure that we don't lose any important interrupts by using the chip
  1831. * feature that says that writing 0 to a bit in *clear that is set in
  1832. * *status will cause an interrupt to be generated again (if allowed by
  1833. * the *mask value).
  1834. * This is in chip-specific code because of all of the register accesses,
  1835. * even though the details are similar on most chips.
  1836. */
  1837. static void qib_7322_clear_freeze(struct qib_devdata *dd)
  1838. {
  1839. int pidx;
  1840. /* disable error interrupts, to avoid confusion */
  1841. qib_write_kreg(dd, kr_errmask, 0ULL);
  1842. for (pidx = 0; pidx < dd->num_pports; ++pidx)
  1843. if (dd->pport[pidx].link_speed_supported)
  1844. qib_write_kreg_port(dd->pport + pidx, krp_errmask,
  1845. 0ULL);
  1846. /* also disable interrupts; errormask is sometimes overwriten */
  1847. qib_7322_set_intr_state(dd, 0);
  1848. /* clear the freeze, and be sure chip saw it */
  1849. qib_write_kreg(dd, kr_control, dd->control);
  1850. qib_read_kreg32(dd, kr_scratch);
  1851. /*
  1852. * Force new interrupt if any hwerr, error or interrupt bits are
  1853. * still set, and clear "safe" send packet errors related to freeze
  1854. * and cancelling sends. Re-enable error interrupts before possible
  1855. * force of re-interrupt on pending interrupts.
  1856. */
  1857. qib_write_kreg(dd, kr_hwerrclear, 0ULL);
  1858. qib_write_kreg(dd, kr_errclear, E_SPKT_ERRS_IGNORE);
  1859. qib_write_kreg(dd, kr_errmask, dd->cspec->errormask);
  1860. /* We need to purge per-port errs and reset mask, too */
  1861. for (pidx = 0; pidx < dd->num_pports; ++pidx) {
  1862. if (!dd->pport[pidx].link_speed_supported)
  1863. continue;
  1864. qib_write_kreg_port(dd->pport + pidx, krp_errclear, ~0Ull);
  1865. qib_write_kreg_port(dd->pport + pidx, krp_errmask, ~0Ull);
  1866. }
  1867. qib_7322_set_intr_state(dd, 1);
  1868. }
  1869. /* no error handling to speak of */
  1870. /**
  1871. * qib_7322_handle_hwerrors - display hardware errors.
  1872. * @dd: the qlogic_ib device
  1873. * @msg: the output buffer
  1874. * @msgl: the size of the output buffer
  1875. *
  1876. * Use same msg buffer as regular errors to avoid excessive stack
  1877. * use. Most hardware errors are catastrophic, but for right now,
  1878. * we'll print them and continue. We reuse the same message buffer as
  1879. * qib_handle_errors() to avoid excessive stack usage.
  1880. */
  1881. static void qib_7322_handle_hwerrors(struct qib_devdata *dd, char *msg,
  1882. size_t msgl)
  1883. {
  1884. u64 hwerrs;
  1885. u32 ctrl;
  1886. int isfatal = 0;
  1887. hwerrs = qib_read_kreg64(dd, kr_hwerrstatus);
  1888. if (!hwerrs)
  1889. goto bail;
  1890. if (hwerrs == ~0ULL) {
  1891. qib_dev_err(dd,
  1892. "Read of hardware error status failed (all bits set); ignoring\n");
  1893. goto bail;
  1894. }
  1895. qib_stats.sps_hwerrs++;
  1896. /* Always clear the error status register, except BIST fail */
  1897. qib_write_kreg(dd, kr_hwerrclear, hwerrs &
  1898. ~HWE_MASK(PowerOnBISTFailed));
  1899. hwerrs &= dd->cspec->hwerrmask;
  1900. /* no EEPROM logging, yet */
  1901. if (hwerrs)
  1902. qib_devinfo(dd->pcidev,
  1903. "Hardware error: hwerr=0x%llx (cleared)\n",
  1904. (unsigned long long) hwerrs);
  1905. ctrl = qib_read_kreg32(dd, kr_control);
  1906. if ((ctrl & SYM_MASK(Control, FreezeMode)) && !dd->diag_client) {
  1907. /*
  1908. * No recovery yet...
  1909. */
  1910. if ((hwerrs & ~HWE_MASK(LATriggered)) ||
  1911. dd->cspec->stay_in_freeze) {
  1912. /*
  1913. * If any set that we aren't ignoring only make the
  1914. * complaint once, in case it's stuck or recurring,
  1915. * and we get here multiple times
  1916. * Force link down, so switch knows, and
  1917. * LEDs are turned off.
  1918. */
  1919. if (dd->flags & QIB_INITTED)
  1920. isfatal = 1;
  1921. } else
  1922. qib_7322_clear_freeze(dd);
  1923. }
  1924. if (hwerrs & HWE_MASK(PowerOnBISTFailed)) {
  1925. isfatal = 1;
  1926. strlcpy(msg,
  1927. "[Memory BIST test failed, InfiniPath hardware unusable]",
  1928. msgl);
  1929. /* ignore from now on, so disable until driver reloaded */
  1930. dd->cspec->hwerrmask &= ~HWE_MASK(PowerOnBISTFailed);
  1931. qib_write_kreg(dd, kr_hwerrmask, dd->cspec->hwerrmask);
  1932. }
  1933. err_decode(msg, msgl, hwerrs, qib_7322_hwerror_msgs);
  1934. /* Ignore esoteric PLL failures et al. */
  1935. qib_dev_err(dd, "%s hardware error\n", msg);
  1936. if (hwerrs &
  1937. (SYM_MASK(HwErrMask, SDmaMemReadErrMask_0) |
  1938. SYM_MASK(HwErrMask, SDmaMemReadErrMask_1))) {
  1939. int pidx = 0;
  1940. int err;
  1941. unsigned long flags;
  1942. struct qib_pportdata *ppd = dd->pport;
  1943. for (; pidx < dd->num_pports; ++pidx, ppd++) {
  1944. err = 0;
  1945. if (pidx == 0 && (hwerrs &
  1946. SYM_MASK(HwErrMask, SDmaMemReadErrMask_0)))
  1947. err++;
  1948. if (pidx == 1 && (hwerrs &
  1949. SYM_MASK(HwErrMask, SDmaMemReadErrMask_1)))
  1950. err++;
  1951. if (err) {
  1952. spin_lock_irqsave(&ppd->sdma_lock, flags);
  1953. dump_sdma_7322_state(ppd);
  1954. spin_unlock_irqrestore(&ppd->sdma_lock, flags);
  1955. }
  1956. }
  1957. }
  1958. if (isfatal && !dd->diag_client) {
  1959. qib_dev_err(dd,
  1960. "Fatal Hardware Error, no longer usable, SN %.16s\n",
  1961. dd->serial);
  1962. /*
  1963. * for /sys status file and user programs to print; if no
  1964. * trailing brace is copied, we'll know it was truncated.
  1965. */
  1966. if (dd->freezemsg)
  1967. snprintf(dd->freezemsg, dd->freezelen,
  1968. "{%s}", msg);
  1969. qib_disable_after_error(dd);
  1970. }
  1971. bail:;
  1972. }
  1973. /**
  1974. * qib_7322_init_hwerrors - enable hardware errors
  1975. * @dd: the qlogic_ib device
  1976. *
  1977. * now that we have finished initializing everything that might reasonably
  1978. * cause a hardware error, and cleared those errors bits as they occur,
  1979. * we can enable hardware errors in the mask (potentially enabling
  1980. * freeze mode), and enable hardware errors as errors (along with
  1981. * everything else) in errormask
  1982. */
  1983. static void qib_7322_init_hwerrors(struct qib_devdata *dd)
  1984. {
  1985. int pidx;
  1986. u64 extsval;
  1987. extsval = qib_read_kreg64(dd, kr_extstatus);
  1988. if (!(extsval & (QIB_EXTS_MEMBIST_DISABLED |
  1989. QIB_EXTS_MEMBIST_ENDTEST)))
  1990. qib_dev_err(dd, "MemBIST did not complete!\n");
  1991. /* never clear BIST failure, so reported on each driver load */
  1992. qib_write_kreg(dd, kr_hwerrclear, ~HWE_MASK(PowerOnBISTFailed));
  1993. qib_write_kreg(dd, kr_hwerrmask, dd->cspec->hwerrmask);
  1994. /* clear all */
  1995. qib_write_kreg(dd, kr_errclear, ~0ULL);
  1996. /* enable errors that are masked, at least this first time. */
  1997. qib_write_kreg(dd, kr_errmask, ~0ULL);
  1998. dd->cspec->errormask = qib_read_kreg64(dd, kr_errmask);
  1999. for (pidx = 0; pidx < dd->num_pports; ++pidx)
  2000. if (dd->pport[pidx].link_speed_supported)
  2001. qib_write_kreg_port(dd->pport + pidx, krp_errmask,
  2002. ~0ULL);
  2003. }
  2004. /*
  2005. * Disable and enable the armlaunch error. Used for PIO bandwidth testing
  2006. * on chips that are count-based, rather than trigger-based. There is no
  2007. * reference counting, but that's also fine, given the intended use.
  2008. * Only chip-specific because it's all register accesses
  2009. */
  2010. static void qib_set_7322_armlaunch(struct qib_devdata *dd, u32 enable)
  2011. {
  2012. if (enable) {
  2013. qib_write_kreg(dd, kr_errclear, QIB_E_SPIOARMLAUNCH);
  2014. dd->cspec->errormask |= QIB_E_SPIOARMLAUNCH;
  2015. } else
  2016. dd->cspec->errormask &= ~QIB_E_SPIOARMLAUNCH;
  2017. qib_write_kreg(dd, kr_errmask, dd->cspec->errormask);
  2018. }
  2019. /*
  2020. * Formerly took parameter <which> in pre-shifted,
  2021. * pre-merged form with LinkCmd and LinkInitCmd
  2022. * together, and assuming the zero was NOP.
  2023. */
  2024. static void qib_set_ib_7322_lstate(struct qib_pportdata *ppd, u16 linkcmd,
  2025. u16 linitcmd)
  2026. {
  2027. u64 mod_wd;
  2028. struct qib_devdata *dd = ppd->dd;
  2029. unsigned long flags;
  2030. if (linitcmd == QLOGIC_IB_IBCC_LINKINITCMD_DISABLE) {
  2031. /*
  2032. * If we are told to disable, note that so link-recovery
  2033. * code does not attempt to bring us back up.
  2034. * Also reset everything that we can, so we start
  2035. * completely clean when re-enabled (before we
  2036. * actually issue the disable to the IBC)
  2037. */
  2038. qib_7322_mini_pcs_reset(ppd);
  2039. spin_lock_irqsave(&ppd->lflags_lock, flags);
  2040. ppd->lflags |= QIBL_IB_LINK_DISABLED;
  2041. spin_unlock_irqrestore(&ppd->lflags_lock, flags);
  2042. } else if (linitcmd || linkcmd == QLOGIC_IB_IBCC_LINKCMD_DOWN) {
  2043. /*
  2044. * Any other linkinitcmd will lead to LINKDOWN and then
  2045. * to INIT (if all is well), so clear flag to let
  2046. * link-recovery code attempt to bring us back up.
  2047. */
  2048. spin_lock_irqsave(&ppd->lflags_lock, flags);
  2049. ppd->lflags &= ~QIBL_IB_LINK_DISABLED;
  2050. spin_unlock_irqrestore(&ppd->lflags_lock, flags);
  2051. /*
  2052. * Clear status change interrupt reduction so the
  2053. * new state is seen.
  2054. */
  2055. ppd->cpspec->ibcctrl_a &=
  2056. ~SYM_MASK(IBCCtrlA_0, IBStatIntReductionEn);
  2057. }
  2058. mod_wd = (linkcmd << IBA7322_IBCC_LINKCMD_SHIFT) |
  2059. (linitcmd << QLOGIC_IB_IBCC_LINKINITCMD_SHIFT);
  2060. qib_write_kreg_port(ppd, krp_ibcctrl_a, ppd->cpspec->ibcctrl_a |
  2061. mod_wd);
  2062. /* write to chip to prevent back-to-back writes of ibc reg */
  2063. qib_write_kreg(dd, kr_scratch, 0);
  2064. }
  2065. /*
  2066. * The total RCV buffer memory is 64KB, used for both ports, and is
  2067. * in units of 64 bytes (same as IB flow control credit unit).
  2068. * The consumedVL unit in the same registers are in 32 byte units!
  2069. * So, a VL15 packet needs 4.50 IB credits, and 9 rx buffer chunks,
  2070. * and we can therefore allocate just 9 IB credits for 2 VL15 packets
  2071. * in krp_rxcreditvl15, rather than 10.
  2072. */
  2073. #define RCV_BUF_UNITSZ 64
  2074. #define NUM_RCV_BUF_UNITS(dd) ((64 * 1024) / (RCV_BUF_UNITSZ * dd->num_pports))
  2075. static void set_vls(struct qib_pportdata *ppd)
  2076. {
  2077. int i, numvls, totcred, cred_vl, vl0extra;
  2078. struct qib_devdata *dd = ppd->dd;
  2079. u64 val;
  2080. numvls = qib_num_vls(ppd->vls_operational);
  2081. /*
  2082. * Set up per-VL credits. Below is kluge based on these assumptions:
  2083. * 1) port is disabled at the time early_init is called.
  2084. * 2) give VL15 17 credits, for two max-plausible packets.
  2085. * 3) Give VL0-N the rest, with any rounding excess used for VL0
  2086. */
  2087. /* 2 VL15 packets @ 288 bytes each (including IB headers) */
  2088. totcred = NUM_RCV_BUF_UNITS(dd);
  2089. cred_vl = (2 * 288 + RCV_BUF_UNITSZ - 1) / RCV_BUF_UNITSZ;
  2090. totcred -= cred_vl;
  2091. qib_write_kreg_port(ppd, krp_rxcreditvl15, (u64) cred_vl);
  2092. cred_vl = totcred / numvls;
  2093. vl0extra = totcred - cred_vl * numvls;
  2094. qib_write_kreg_port(ppd, krp_rxcreditvl0, cred_vl + vl0extra);
  2095. for (i = 1; i < numvls; i++)
  2096. qib_write_kreg_port(ppd, krp_rxcreditvl0 + i, cred_vl);
  2097. for (; i < 8; i++) /* no buffer space for other VLs */
  2098. qib_write_kreg_port(ppd, krp_rxcreditvl0 + i, 0);
  2099. /* Notify IBC that credits need to be recalculated */
  2100. val = qib_read_kreg_port(ppd, krp_ibsdtestiftx);
  2101. val |= SYM_MASK(IB_SDTEST_IF_TX_0, CREDIT_CHANGE);
  2102. qib_write_kreg_port(ppd, krp_ibsdtestiftx, val);
  2103. qib_write_kreg(dd, kr_scratch, 0ULL);
  2104. val &= ~SYM_MASK(IB_SDTEST_IF_TX_0, CREDIT_CHANGE);
  2105. qib_write_kreg_port(ppd, krp_ibsdtestiftx, val);
  2106. for (i = 0; i < numvls; i++)
  2107. val = qib_read_kreg_port(ppd, krp_rxcreditvl0 + i);
  2108. val = qib_read_kreg_port(ppd, krp_rxcreditvl15);
  2109. /* Change the number of operational VLs */
  2110. ppd->cpspec->ibcctrl_a = (ppd->cpspec->ibcctrl_a &
  2111. ~SYM_MASK(IBCCtrlA_0, NumVLane)) |
  2112. ((u64)(numvls - 1) << SYM_LSB(IBCCtrlA_0, NumVLane));
  2113. qib_write_kreg_port(ppd, krp_ibcctrl_a, ppd->cpspec->ibcctrl_a);
  2114. qib_write_kreg(dd, kr_scratch, 0ULL);
  2115. }
  2116. /*
  2117. * The code that deals with actual SerDes is in serdes_7322_init().
  2118. * Compared to the code for iba7220, it is minimal.
  2119. */
  2120. static int serdes_7322_init(struct qib_pportdata *ppd);
  2121. /**
  2122. * qib_7322_bringup_serdes - bring up the serdes
  2123. * @ppd: physical port on the qlogic_ib device
  2124. */
  2125. static int qib_7322_bringup_serdes(struct qib_pportdata *ppd)
  2126. {
  2127. struct qib_devdata *dd = ppd->dd;
  2128. u64 val, guid, ibc;
  2129. unsigned long flags;
  2130. int ret = 0;
  2131. /*
  2132. * SerDes model not in Pd, but still need to
  2133. * set up much of IBCCtrl and IBCDDRCtrl; move elsewhere
  2134. * eventually.
  2135. */
  2136. /* Put IBC in reset, sends disabled (should be in reset already) */
  2137. ppd->cpspec->ibcctrl_a &= ~SYM_MASK(IBCCtrlA_0, IBLinkEn);
  2138. qib_write_kreg_port(ppd, krp_ibcctrl_a, ppd->cpspec->ibcctrl_a);
  2139. qib_write_kreg(dd, kr_scratch, 0ULL);
  2140. /* ensure previous Tx parameters are not still forced */
  2141. qib_write_kreg_port(ppd, krp_tx_deemph_override,
  2142. SYM_MASK(IBSD_TX_DEEMPHASIS_OVERRIDE_0,
  2143. reset_tx_deemphasis_override));
  2144. if (qib_compat_ddr_negotiate) {
  2145. ppd->cpspec->ibdeltainprog = 1;
  2146. ppd->cpspec->ibsymsnap = read_7322_creg32_port(ppd,
  2147. crp_ibsymbolerr);
  2148. ppd->cpspec->iblnkerrsnap = read_7322_creg32_port(ppd,
  2149. crp_iblinkerrrecov);
  2150. }
  2151. /* flowcontrolwatermark is in units of KBytes */
  2152. ibc = 0x5ULL << SYM_LSB(IBCCtrlA_0, FlowCtrlWaterMark);
  2153. /*
  2154. * Flow control is sent this often, even if no changes in
  2155. * buffer space occur. Units are 128ns for this chip.
  2156. * Set to 3usec.
  2157. */
  2158. ibc |= 24ULL << SYM_LSB(IBCCtrlA_0, FlowCtrlPeriod);
  2159. /* max error tolerance */
  2160. ibc |= 0xfULL << SYM_LSB(IBCCtrlA_0, PhyerrThreshold);
  2161. /* IB credit flow control. */
  2162. ibc |= 0xfULL << SYM_LSB(IBCCtrlA_0, OverrunThreshold);
  2163. /*
  2164. * set initial max size pkt IBC will send, including ICRC; it's the
  2165. * PIO buffer size in dwords, less 1; also see qib_set_mtu()
  2166. */
  2167. ibc |= ((u64)(ppd->ibmaxlen >> 2) + 1) <<
  2168. SYM_LSB(IBCCtrlA_0, MaxPktLen);
  2169. ppd->cpspec->ibcctrl_a = ibc; /* without linkcmd or linkinitcmd! */
  2170. /*
  2171. * Reset the PCS interface to the serdes (and also ibc, which is still
  2172. * in reset from above). Writes new value of ibcctrl_a as last step.
  2173. */
  2174. qib_7322_mini_pcs_reset(ppd);
  2175. if (!ppd->cpspec->ibcctrl_b) {
  2176. unsigned lse = ppd->link_speed_enabled;
  2177. /*
  2178. * Not on re-init after reset, establish shadow
  2179. * and force initial config.
  2180. */
  2181. ppd->cpspec->ibcctrl_b = qib_read_kreg_port(ppd,
  2182. krp_ibcctrl_b);
  2183. ppd->cpspec->ibcctrl_b &= ~(IBA7322_IBC_SPEED_QDR |
  2184. IBA7322_IBC_SPEED_DDR |
  2185. IBA7322_IBC_SPEED_SDR |
  2186. IBA7322_IBC_WIDTH_AUTONEG |
  2187. SYM_MASK(IBCCtrlB_0, IB_LANE_REV_SUPPORTED));
  2188. if (lse & (lse - 1)) /* Muliple speeds enabled */
  2189. ppd->cpspec->ibcctrl_b |=
  2190. (lse << IBA7322_IBC_SPEED_LSB) |
  2191. IBA7322_IBC_IBTA_1_2_MASK |
  2192. IBA7322_IBC_MAX_SPEED_MASK;
  2193. else
  2194. ppd->cpspec->ibcctrl_b |= (lse == QIB_IB_QDR) ?
  2195. IBA7322_IBC_SPEED_QDR |
  2196. IBA7322_IBC_IBTA_1_2_MASK :
  2197. (lse == QIB_IB_DDR) ?
  2198. IBA7322_IBC_SPEED_DDR :
  2199. IBA7322_IBC_SPEED_SDR;
  2200. if ((ppd->link_width_enabled & (IB_WIDTH_1X | IB_WIDTH_4X)) ==
  2201. (IB_WIDTH_1X | IB_WIDTH_4X))
  2202. ppd->cpspec->ibcctrl_b |= IBA7322_IBC_WIDTH_AUTONEG;
  2203. else
  2204. ppd->cpspec->ibcctrl_b |=
  2205. ppd->link_width_enabled == IB_WIDTH_4X ?
  2206. IBA7322_IBC_WIDTH_4X_ONLY :
  2207. IBA7322_IBC_WIDTH_1X_ONLY;
  2208. /* always enable these on driver reload, not sticky */
  2209. ppd->cpspec->ibcctrl_b |= (IBA7322_IBC_RXPOL_MASK |
  2210. IBA7322_IBC_HRTBT_MASK);
  2211. }
  2212. qib_write_kreg_port(ppd, krp_ibcctrl_b, ppd->cpspec->ibcctrl_b);
  2213. /* setup so we have more time at CFGTEST to change H1 */
  2214. val = qib_read_kreg_port(ppd, krp_ibcctrl_c);
  2215. val &= ~SYM_MASK(IBCCtrlC_0, IB_FRONT_PORCH);
  2216. val |= 0xfULL << SYM_LSB(IBCCtrlC_0, IB_FRONT_PORCH);
  2217. qib_write_kreg_port(ppd, krp_ibcctrl_c, val);
  2218. serdes_7322_init(ppd);
  2219. guid = be64_to_cpu(ppd->guid);
  2220. if (!guid) {
  2221. if (dd->base_guid)
  2222. guid = be64_to_cpu(dd->base_guid) + ppd->port - 1;
  2223. ppd->guid = cpu_to_be64(guid);
  2224. }
  2225. qib_write_kreg_port(ppd, krp_hrtbt_guid, guid);
  2226. /* write to chip to prevent back-to-back writes of ibc reg */
  2227. qib_write_kreg(dd, kr_scratch, 0);
  2228. /* Enable port */
  2229. ppd->cpspec->ibcctrl_a |= SYM_MASK(IBCCtrlA_0, IBLinkEn);
  2230. set_vls(ppd);
  2231. /* initially come up DISABLED, without sending anything. */
  2232. val = ppd->cpspec->ibcctrl_a | (QLOGIC_IB_IBCC_LINKINITCMD_DISABLE <<
  2233. QLOGIC_IB_IBCC_LINKINITCMD_SHIFT);
  2234. qib_write_kreg_port(ppd, krp_ibcctrl_a, val);
  2235. qib_write_kreg(dd, kr_scratch, 0ULL);
  2236. /* clear the linkinit cmds */
  2237. ppd->cpspec->ibcctrl_a = val & ~SYM_MASK(IBCCtrlA_0, LinkInitCmd);
  2238. /* be paranoid against later code motion, etc. */
  2239. spin_lock_irqsave(&dd->cspec->rcvmod_lock, flags);
  2240. ppd->p_rcvctrl |= SYM_MASK(RcvCtrl_0, RcvIBPortEnable);
  2241. qib_write_kreg_port(ppd, krp_rcvctrl, ppd->p_rcvctrl);
  2242. spin_unlock_irqrestore(&dd->cspec->rcvmod_lock, flags);
  2243. /* Also enable IBSTATUSCHG interrupt. */
  2244. val = qib_read_kreg_port(ppd, krp_errmask);
  2245. qib_write_kreg_port(ppd, krp_errmask,
  2246. val | ERR_MASK_N(IBStatusChanged));
  2247. /* Always zero until we start messing with SerDes for real */
  2248. return ret;
  2249. }
  2250. /**
  2251. * qib_7322_quiet_serdes - set serdes to txidle
  2252. * @dd: the qlogic_ib device
  2253. * Called when driver is being unloaded
  2254. */
  2255. static void qib_7322_mini_quiet_serdes(struct qib_pportdata *ppd)
  2256. {
  2257. u64 val;
  2258. unsigned long flags;
  2259. qib_set_ib_7322_lstate(ppd, 0, QLOGIC_IB_IBCC_LINKINITCMD_DISABLE);
  2260. spin_lock_irqsave(&ppd->lflags_lock, flags);
  2261. ppd->lflags &= ~QIBL_IB_AUTONEG_INPROG;
  2262. spin_unlock_irqrestore(&ppd->lflags_lock, flags);
  2263. wake_up(&ppd->cpspec->autoneg_wait);
  2264. cancel_delayed_work_sync(&ppd->cpspec->autoneg_work);
  2265. if (ppd->dd->cspec->r1)
  2266. cancel_delayed_work_sync(&ppd->cpspec->ipg_work);
  2267. ppd->cpspec->chase_end = 0;
  2268. if (ppd->cpspec->chase_timer.data) /* if initted */
  2269. del_timer_sync(&ppd->cpspec->chase_timer);
  2270. /*
  2271. * Despite the name, actually disables IBC as well. Do it when
  2272. * we are as sure as possible that no more packets can be
  2273. * received, following the down and the PCS reset.
  2274. * The actual disabling happens in qib_7322_mini_pci_reset(),
  2275. * along with the PCS being reset.
  2276. */
  2277. ppd->cpspec->ibcctrl_a &= ~SYM_MASK(IBCCtrlA_0, IBLinkEn);
  2278. qib_7322_mini_pcs_reset(ppd);
  2279. /*
  2280. * Update the adjusted counters so the adjustment persists
  2281. * across driver reload.
  2282. */
  2283. if (ppd->cpspec->ibsymdelta || ppd->cpspec->iblnkerrdelta ||
  2284. ppd->cpspec->ibdeltainprog || ppd->cpspec->iblnkdowndelta) {
  2285. struct qib_devdata *dd = ppd->dd;
  2286. u64 diagc;
  2287. /* enable counter writes */
  2288. diagc = qib_read_kreg64(dd, kr_hwdiagctrl);
  2289. qib_write_kreg(dd, kr_hwdiagctrl,
  2290. diagc | SYM_MASK(HwDiagCtrl, CounterWrEnable));
  2291. if (ppd->cpspec->ibsymdelta || ppd->cpspec->ibdeltainprog) {
  2292. val = read_7322_creg32_port(ppd, crp_ibsymbolerr);
  2293. if (ppd->cpspec->ibdeltainprog)
  2294. val -= val - ppd->cpspec->ibsymsnap;
  2295. val -= ppd->cpspec->ibsymdelta;
  2296. write_7322_creg_port(ppd, crp_ibsymbolerr, val);
  2297. }
  2298. if (ppd->cpspec->iblnkerrdelta || ppd->cpspec->ibdeltainprog) {
  2299. val = read_7322_creg32_port(ppd, crp_iblinkerrrecov);
  2300. if (ppd->cpspec->ibdeltainprog)
  2301. val -= val - ppd->cpspec->iblnkerrsnap;
  2302. val -= ppd->cpspec->iblnkerrdelta;
  2303. write_7322_creg_port(ppd, crp_iblinkerrrecov, val);
  2304. }
  2305. if (ppd->cpspec->iblnkdowndelta) {
  2306. val = read_7322_creg32_port(ppd, crp_iblinkdown);
  2307. val += ppd->cpspec->iblnkdowndelta;
  2308. write_7322_creg_port(ppd, crp_iblinkdown, val);
  2309. }
  2310. /*
  2311. * No need to save ibmalfdelta since IB perfcounters
  2312. * are cleared on driver reload.
  2313. */
  2314. /* and disable counter writes */
  2315. qib_write_kreg(dd, kr_hwdiagctrl, diagc);
  2316. }
  2317. }
  2318. /**
  2319. * qib_setup_7322_setextled - set the state of the two external LEDs
  2320. * @ppd: physical port on the qlogic_ib device
  2321. * @on: whether the link is up or not
  2322. *
  2323. * The exact combo of LEDs if on is true is determined by looking
  2324. * at the ibcstatus.
  2325. *
  2326. * These LEDs indicate the physical and logical state of IB link.
  2327. * For this chip (at least with recommended board pinouts), LED1
  2328. * is Yellow (logical state) and LED2 is Green (physical state),
  2329. *
  2330. * Note: We try to match the Mellanox HCA LED behavior as best
  2331. * we can. Green indicates physical link state is OK (something is
  2332. * plugged in, and we can train).
  2333. * Amber indicates the link is logically up (ACTIVE).
  2334. * Mellanox further blinks the amber LED to indicate data packet
  2335. * activity, but we have no hardware support for that, so it would
  2336. * require waking up every 10-20 msecs and checking the counters
  2337. * on the chip, and then turning the LED off if appropriate. That's
  2338. * visible overhead, so not something we will do.
  2339. */
  2340. static void qib_setup_7322_setextled(struct qib_pportdata *ppd, u32 on)
  2341. {
  2342. struct qib_devdata *dd = ppd->dd;
  2343. u64 extctl, ledblink = 0, val;
  2344. unsigned long flags;
  2345. int yel, grn;
  2346. /*
  2347. * The diags use the LED to indicate diag info, so we leave
  2348. * the external LED alone when the diags are running.
  2349. */
  2350. if (dd->diag_client)
  2351. return;
  2352. /* Allow override of LED display for, e.g. Locating system in rack */
  2353. if (ppd->led_override) {
  2354. grn = (ppd->led_override & QIB_LED_PHYS);
  2355. yel = (ppd->led_override & QIB_LED_LOG);
  2356. } else if (on) {
  2357. val = qib_read_kreg_port(ppd, krp_ibcstatus_a);
  2358. grn = qib_7322_phys_portstate(val) ==
  2359. IB_PHYSPORTSTATE_LINKUP;
  2360. yel = qib_7322_iblink_state(val) == IB_PORT_ACTIVE;
  2361. } else {
  2362. grn = 0;
  2363. yel = 0;
  2364. }
  2365. spin_lock_irqsave(&dd->cspec->gpio_lock, flags);
  2366. extctl = dd->cspec->extctrl & (ppd->port == 1 ?
  2367. ~ExtLED_IB1_MASK : ~ExtLED_IB2_MASK);
  2368. if (grn) {
  2369. extctl |= ppd->port == 1 ? ExtLED_IB1_GRN : ExtLED_IB2_GRN;
  2370. /*
  2371. * Counts are in chip clock (4ns) periods.
  2372. * This is 1/16 sec (66.6ms) on,
  2373. * 3/16 sec (187.5 ms) off, with packets rcvd.
  2374. */
  2375. ledblink = ((66600 * 1000UL / 4) << IBA7322_LEDBLINK_ON_SHIFT) |
  2376. ((187500 * 1000UL / 4) << IBA7322_LEDBLINK_OFF_SHIFT);
  2377. }
  2378. if (yel)
  2379. extctl |= ppd->port == 1 ? ExtLED_IB1_YEL : ExtLED_IB2_YEL;
  2380. dd->cspec->extctrl = extctl;
  2381. qib_write_kreg(dd, kr_extctrl, dd->cspec->extctrl);
  2382. spin_unlock_irqrestore(&dd->cspec->gpio_lock, flags);
  2383. if (ledblink) /* blink the LED on packet receive */
  2384. qib_write_kreg_port(ppd, krp_rcvpktledcnt, ledblink);
  2385. }
  2386. #ifdef CONFIG_INFINIBAND_QIB_DCA
  2387. static int qib_7322_notify_dca(struct qib_devdata *dd, unsigned long event)
  2388. {
  2389. switch (event) {
  2390. case DCA_PROVIDER_ADD:
  2391. if (dd->flags & QIB_DCA_ENABLED)
  2392. break;
  2393. if (!dca_add_requester(&dd->pcidev->dev)) {
  2394. qib_devinfo(dd->pcidev, "DCA enabled\n");
  2395. dd->flags |= QIB_DCA_ENABLED;
  2396. qib_setup_dca(dd);
  2397. }
  2398. break;
  2399. case DCA_PROVIDER_REMOVE:
  2400. if (dd->flags & QIB_DCA_ENABLED) {
  2401. dca_remove_requester(&dd->pcidev->dev);
  2402. dd->flags &= ~QIB_DCA_ENABLED;
  2403. dd->cspec->dca_ctrl = 0;
  2404. qib_write_kreg(dd, KREG_IDX(DCACtrlA),
  2405. dd->cspec->dca_ctrl);
  2406. }
  2407. break;
  2408. }
  2409. return 0;
  2410. }
  2411. static void qib_update_rhdrq_dca(struct qib_ctxtdata *rcd, int cpu)
  2412. {
  2413. struct qib_devdata *dd = rcd->dd;
  2414. struct qib_chip_specific *cspec = dd->cspec;
  2415. if (!(dd->flags & QIB_DCA_ENABLED))
  2416. return;
  2417. if (cspec->rhdr_cpu[rcd->ctxt] != cpu) {
  2418. const struct dca_reg_map *rmp;
  2419. cspec->rhdr_cpu[rcd->ctxt] = cpu;
  2420. rmp = &dca_rcvhdr_reg_map[rcd->ctxt];
  2421. cspec->dca_rcvhdr_ctrl[rmp->shadow_inx] &= rmp->mask;
  2422. cspec->dca_rcvhdr_ctrl[rmp->shadow_inx] |=
  2423. (u64) dca3_get_tag(&dd->pcidev->dev, cpu) << rmp->lsb;
  2424. qib_devinfo(dd->pcidev,
  2425. "Ctxt %d cpu %d dca %llx\n", rcd->ctxt, cpu,
  2426. (long long) cspec->dca_rcvhdr_ctrl[rmp->shadow_inx]);
  2427. qib_write_kreg(dd, rmp->regno,
  2428. cspec->dca_rcvhdr_ctrl[rmp->shadow_inx]);
  2429. cspec->dca_ctrl |= SYM_MASK(DCACtrlA, RcvHdrqDCAEnable);
  2430. qib_write_kreg(dd, KREG_IDX(DCACtrlA), cspec->dca_ctrl);
  2431. }
  2432. }
  2433. static void qib_update_sdma_dca(struct qib_pportdata *ppd, int cpu)
  2434. {
  2435. struct qib_devdata *dd = ppd->dd;
  2436. struct qib_chip_specific *cspec = dd->cspec;
  2437. unsigned pidx = ppd->port - 1;
  2438. if (!(dd->flags & QIB_DCA_ENABLED))
  2439. return;
  2440. if (cspec->sdma_cpu[pidx] != cpu) {
  2441. cspec->sdma_cpu[pidx] = cpu;
  2442. cspec->dca_rcvhdr_ctrl[4] &= ~(ppd->hw_pidx ?
  2443. SYM_MASK(DCACtrlF, SendDma1DCAOPH) :
  2444. SYM_MASK(DCACtrlF, SendDma0DCAOPH));
  2445. cspec->dca_rcvhdr_ctrl[4] |=
  2446. (u64) dca3_get_tag(&dd->pcidev->dev, cpu) <<
  2447. (ppd->hw_pidx ?
  2448. SYM_LSB(DCACtrlF, SendDma1DCAOPH) :
  2449. SYM_LSB(DCACtrlF, SendDma0DCAOPH));
  2450. qib_devinfo(dd->pcidev,
  2451. "sdma %d cpu %d dca %llx\n", ppd->hw_pidx, cpu,
  2452. (long long) cspec->dca_rcvhdr_ctrl[4]);
  2453. qib_write_kreg(dd, KREG_IDX(DCACtrlF),
  2454. cspec->dca_rcvhdr_ctrl[4]);
  2455. cspec->dca_ctrl |= ppd->hw_pidx ?
  2456. SYM_MASK(DCACtrlA, SendDMAHead1DCAEnable) :
  2457. SYM_MASK(DCACtrlA, SendDMAHead0DCAEnable);
  2458. qib_write_kreg(dd, KREG_IDX(DCACtrlA), cspec->dca_ctrl);
  2459. }
  2460. }
  2461. static void qib_setup_dca(struct qib_devdata *dd)
  2462. {
  2463. struct qib_chip_specific *cspec = dd->cspec;
  2464. int i;
  2465. for (i = 0; i < ARRAY_SIZE(cspec->rhdr_cpu); i++)
  2466. cspec->rhdr_cpu[i] = -1;
  2467. for (i = 0; i < ARRAY_SIZE(cspec->sdma_cpu); i++)
  2468. cspec->sdma_cpu[i] = -1;
  2469. cspec->dca_rcvhdr_ctrl[0] =
  2470. (1ULL << SYM_LSB(DCACtrlB, RcvHdrq0DCAXfrCnt)) |
  2471. (1ULL << SYM_LSB(DCACtrlB, RcvHdrq1DCAXfrCnt)) |
  2472. (1ULL << SYM_LSB(DCACtrlB, RcvHdrq2DCAXfrCnt)) |
  2473. (1ULL << SYM_LSB(DCACtrlB, RcvHdrq3DCAXfrCnt));
  2474. cspec->dca_rcvhdr_ctrl[1] =
  2475. (1ULL << SYM_LSB(DCACtrlC, RcvHdrq4DCAXfrCnt)) |
  2476. (1ULL << SYM_LSB(DCACtrlC, RcvHdrq5DCAXfrCnt)) |
  2477. (1ULL << SYM_LSB(DCACtrlC, RcvHdrq6DCAXfrCnt)) |
  2478. (1ULL << SYM_LSB(DCACtrlC, RcvHdrq7DCAXfrCnt));
  2479. cspec->dca_rcvhdr_ctrl[2] =
  2480. (1ULL << SYM_LSB(DCACtrlD, RcvHdrq8DCAXfrCnt)) |
  2481. (1ULL << SYM_LSB(DCACtrlD, RcvHdrq9DCAXfrCnt)) |
  2482. (1ULL << SYM_LSB(DCACtrlD, RcvHdrq10DCAXfrCnt)) |
  2483. (1ULL << SYM_LSB(DCACtrlD, RcvHdrq11DCAXfrCnt));
  2484. cspec->dca_rcvhdr_ctrl[3] =
  2485. (1ULL << SYM_LSB(DCACtrlE, RcvHdrq12DCAXfrCnt)) |
  2486. (1ULL << SYM_LSB(DCACtrlE, RcvHdrq13DCAXfrCnt)) |
  2487. (1ULL << SYM_LSB(DCACtrlE, RcvHdrq14DCAXfrCnt)) |
  2488. (1ULL << SYM_LSB(DCACtrlE, RcvHdrq15DCAXfrCnt));
  2489. cspec->dca_rcvhdr_ctrl[4] =
  2490. (1ULL << SYM_LSB(DCACtrlF, RcvHdrq16DCAXfrCnt)) |
  2491. (1ULL << SYM_LSB(DCACtrlF, RcvHdrq17DCAXfrCnt));
  2492. for (i = 0; i < ARRAY_SIZE(cspec->sdma_cpu); i++)
  2493. qib_write_kreg(dd, KREG_IDX(DCACtrlB) + i,
  2494. cspec->dca_rcvhdr_ctrl[i]);
  2495. for (i = 0; i < cspec->num_msix_entries; i++)
  2496. setup_dca_notifier(dd, &cspec->msix_entries[i]);
  2497. }
  2498. static void qib_irq_notifier_notify(struct irq_affinity_notify *notify,
  2499. const cpumask_t *mask)
  2500. {
  2501. struct qib_irq_notify *n =
  2502. container_of(notify, struct qib_irq_notify, notify);
  2503. int cpu = cpumask_first(mask);
  2504. if (n->rcv) {
  2505. struct qib_ctxtdata *rcd = (struct qib_ctxtdata *)n->arg;
  2506. qib_update_rhdrq_dca(rcd, cpu);
  2507. } else {
  2508. struct qib_pportdata *ppd = (struct qib_pportdata *)n->arg;
  2509. qib_update_sdma_dca(ppd, cpu);
  2510. }
  2511. }
  2512. static void qib_irq_notifier_release(struct kref *ref)
  2513. {
  2514. struct qib_irq_notify *n =
  2515. container_of(ref, struct qib_irq_notify, notify.kref);
  2516. struct qib_devdata *dd;
  2517. if (n->rcv) {
  2518. struct qib_ctxtdata *rcd = (struct qib_ctxtdata *)n->arg;
  2519. dd = rcd->dd;
  2520. } else {
  2521. struct qib_pportdata *ppd = (struct qib_pportdata *)n->arg;
  2522. dd = ppd->dd;
  2523. }
  2524. qib_devinfo(dd->pcidev,
  2525. "release on HCA notify 0x%p n 0x%p\n", ref, n);
  2526. kfree(n);
  2527. }
  2528. #endif
  2529. /*
  2530. * Disable MSIx interrupt if enabled, call generic MSIx code
  2531. * to cleanup, and clear pending MSIx interrupts.
  2532. * Used for fallback to INTx, after reset, and when MSIx setup fails.
  2533. */
  2534. static void qib_7322_nomsix(struct qib_devdata *dd)
  2535. {
  2536. u64 intgranted;
  2537. int n;
  2538. dd->cspec->main_int_mask = ~0ULL;
  2539. n = dd->cspec->num_msix_entries;
  2540. if (n) {
  2541. int i;
  2542. dd->cspec->num_msix_entries = 0;
  2543. for (i = 0; i < n; i++) {
  2544. #ifdef CONFIG_INFINIBAND_QIB_DCA
  2545. reset_dca_notifier(dd, &dd->cspec->msix_entries[i]);
  2546. #endif
  2547. irq_set_affinity_hint(
  2548. dd->cspec->msix_entries[i].msix.vector, NULL);
  2549. free_cpumask_var(dd->cspec->msix_entries[i].mask);
  2550. free_irq(dd->cspec->msix_entries[i].msix.vector,
  2551. dd->cspec->msix_entries[i].arg);
  2552. }
  2553. qib_nomsix(dd);
  2554. }
  2555. /* make sure no MSIx interrupts are left pending */
  2556. intgranted = qib_read_kreg64(dd, kr_intgranted);
  2557. if (intgranted)
  2558. qib_write_kreg(dd, kr_intgranted, intgranted);
  2559. }
  2560. static void qib_7322_free_irq(struct qib_devdata *dd)
  2561. {
  2562. if (dd->cspec->irq) {
  2563. free_irq(dd->cspec->irq, dd);
  2564. dd->cspec->irq = 0;
  2565. }
  2566. qib_7322_nomsix(dd);
  2567. }
  2568. static void qib_setup_7322_cleanup(struct qib_devdata *dd)
  2569. {
  2570. int i;
  2571. #ifdef CONFIG_INFINIBAND_QIB_DCA
  2572. if (dd->flags & QIB_DCA_ENABLED) {
  2573. dca_remove_requester(&dd->pcidev->dev);
  2574. dd->flags &= ~QIB_DCA_ENABLED;
  2575. dd->cspec->dca_ctrl = 0;
  2576. qib_write_kreg(dd, KREG_IDX(DCACtrlA), dd->cspec->dca_ctrl);
  2577. }
  2578. #endif
  2579. qib_7322_free_irq(dd);
  2580. kfree(dd->cspec->cntrs);
  2581. kfree(dd->cspec->sendchkenable);
  2582. kfree(dd->cspec->sendgrhchk);
  2583. kfree(dd->cspec->sendibchk);
  2584. kfree(dd->cspec->msix_entries);
  2585. for (i = 0; i < dd->num_pports; i++) {
  2586. unsigned long flags;
  2587. u32 mask = QSFP_GPIO_MOD_PRS_N |
  2588. (QSFP_GPIO_MOD_PRS_N << QSFP_GPIO_PORT2_SHIFT);
  2589. kfree(dd->pport[i].cpspec->portcntrs);
  2590. if (dd->flags & QIB_HAS_QSFP) {
  2591. spin_lock_irqsave(&dd->cspec->gpio_lock, flags);
  2592. dd->cspec->gpio_mask &= ~mask;
  2593. qib_write_kreg(dd, kr_gpio_mask, dd->cspec->gpio_mask);
  2594. spin_unlock_irqrestore(&dd->cspec->gpio_lock, flags);
  2595. qib_qsfp_deinit(&dd->pport[i].cpspec->qsfp_data);
  2596. }
  2597. if (dd->pport[i].ibport_data.smi_ah)
  2598. ib_destroy_ah(&dd->pport[i].ibport_data.smi_ah->ibah);
  2599. }
  2600. }
  2601. /* handle SDMA interrupts */
  2602. static void sdma_7322_intr(struct qib_devdata *dd, u64 istat)
  2603. {
  2604. struct qib_pportdata *ppd0 = &dd->pport[0];
  2605. struct qib_pportdata *ppd1 = &dd->pport[1];
  2606. u64 intr0 = istat & (INT_MASK_P(SDma, 0) |
  2607. INT_MASK_P(SDmaIdle, 0) | INT_MASK_P(SDmaProgress, 0));
  2608. u64 intr1 = istat & (INT_MASK_P(SDma, 1) |
  2609. INT_MASK_P(SDmaIdle, 1) | INT_MASK_P(SDmaProgress, 1));
  2610. if (intr0)
  2611. qib_sdma_intr(ppd0);
  2612. if (intr1)
  2613. qib_sdma_intr(ppd1);
  2614. if (istat & INT_MASK_PM(SDmaCleanupDone, 0))
  2615. qib_sdma_process_event(ppd0, qib_sdma_event_e20_hw_started);
  2616. if (istat & INT_MASK_PM(SDmaCleanupDone, 1))
  2617. qib_sdma_process_event(ppd1, qib_sdma_event_e20_hw_started);
  2618. }
  2619. /*
  2620. * Set or clear the Send buffer available interrupt enable bit.
  2621. */
  2622. static void qib_wantpiobuf_7322_intr(struct qib_devdata *dd, u32 needint)
  2623. {
  2624. unsigned long flags;
  2625. spin_lock_irqsave(&dd->sendctrl_lock, flags);
  2626. if (needint)
  2627. dd->sendctrl |= SYM_MASK(SendCtrl, SendIntBufAvail);
  2628. else
  2629. dd->sendctrl &= ~SYM_MASK(SendCtrl, SendIntBufAvail);
  2630. qib_write_kreg(dd, kr_sendctrl, dd->sendctrl);
  2631. qib_write_kreg(dd, kr_scratch, 0ULL);
  2632. spin_unlock_irqrestore(&dd->sendctrl_lock, flags);
  2633. }
  2634. /*
  2635. * Somehow got an interrupt with reserved bits set in interrupt status.
  2636. * Print a message so we know it happened, then clear them.
  2637. * keep mainline interrupt handler cache-friendly
  2638. */
  2639. static noinline void unknown_7322_ibits(struct qib_devdata *dd, u64 istat)
  2640. {
  2641. u64 kills;
  2642. char msg[128];
  2643. kills = istat & ~QIB_I_BITSEXTANT;
  2644. qib_dev_err(dd,
  2645. "Clearing reserved interrupt(s) 0x%016llx: %s\n",
  2646. (unsigned long long) kills, msg);
  2647. qib_write_kreg(dd, kr_intmask, (dd->cspec->int_enable_mask & ~kills));
  2648. }
  2649. /* keep mainline interrupt handler cache-friendly */
  2650. static noinline void unknown_7322_gpio_intr(struct qib_devdata *dd)
  2651. {
  2652. u32 gpiostatus;
  2653. int handled = 0;
  2654. int pidx;
  2655. /*
  2656. * Boards for this chip currently don't use GPIO interrupts,
  2657. * so clear by writing GPIOstatus to GPIOclear, and complain
  2658. * to developer. To avoid endless repeats, clear
  2659. * the bits in the mask, since there is some kind of
  2660. * programming error or chip problem.
  2661. */
  2662. gpiostatus = qib_read_kreg32(dd, kr_gpio_status);
  2663. /*
  2664. * In theory, writing GPIOstatus to GPIOclear could
  2665. * have a bad side-effect on some diagnostic that wanted
  2666. * to poll for a status-change, but the various shadows
  2667. * make that problematic at best. Diags will just suppress
  2668. * all GPIO interrupts during such tests.
  2669. */
  2670. qib_write_kreg(dd, kr_gpio_clear, gpiostatus);
  2671. /*
  2672. * Check for QSFP MOD_PRS changes
  2673. * only works for single port if IB1 != pidx1
  2674. */
  2675. for (pidx = 0; pidx < dd->num_pports && (dd->flags & QIB_HAS_QSFP);
  2676. ++pidx) {
  2677. struct qib_pportdata *ppd;
  2678. struct qib_qsfp_data *qd;
  2679. u32 mask;
  2680. if (!dd->pport[pidx].link_speed_supported)
  2681. continue;
  2682. mask = QSFP_GPIO_MOD_PRS_N;
  2683. ppd = dd->pport + pidx;
  2684. mask <<= (QSFP_GPIO_PORT2_SHIFT * ppd->hw_pidx);
  2685. if (gpiostatus & dd->cspec->gpio_mask & mask) {
  2686. u64 pins;
  2687. qd = &ppd->cpspec->qsfp_data;
  2688. gpiostatus &= ~mask;
  2689. pins = qib_read_kreg64(dd, kr_extstatus);
  2690. pins >>= SYM_LSB(EXTStatus, GPIOIn);
  2691. if (!(pins & mask)) {
  2692. ++handled;
  2693. qd->t_insert = jiffies;
  2694. queue_work(ib_wq, &qd->work);
  2695. }
  2696. }
  2697. }
  2698. if (gpiostatus && !handled) {
  2699. const u32 mask = qib_read_kreg32(dd, kr_gpio_mask);
  2700. u32 gpio_irq = mask & gpiostatus;
  2701. /*
  2702. * Clear any troublemakers, and update chip from shadow
  2703. */
  2704. dd->cspec->gpio_mask &= ~gpio_irq;
  2705. qib_write_kreg(dd, kr_gpio_mask, dd->cspec->gpio_mask);
  2706. }
  2707. }
  2708. /*
  2709. * Handle errors and unusual events first, separate function
  2710. * to improve cache hits for fast path interrupt handling.
  2711. */
  2712. static noinline void unlikely_7322_intr(struct qib_devdata *dd, u64 istat)
  2713. {
  2714. if (istat & ~QIB_I_BITSEXTANT)
  2715. unknown_7322_ibits(dd, istat);
  2716. if (istat & QIB_I_GPIO)
  2717. unknown_7322_gpio_intr(dd);
  2718. if (istat & QIB_I_C_ERROR) {
  2719. qib_write_kreg(dd, kr_errmask, 0ULL);
  2720. tasklet_schedule(&dd->error_tasklet);
  2721. }
  2722. if (istat & INT_MASK_P(Err, 0) && dd->rcd[0])
  2723. handle_7322_p_errors(dd->rcd[0]->ppd);
  2724. if (istat & INT_MASK_P(Err, 1) && dd->rcd[1])
  2725. handle_7322_p_errors(dd->rcd[1]->ppd);
  2726. }
  2727. /*
  2728. * Dynamically adjust the rcv int timeout for a context based on incoming
  2729. * packet rate.
  2730. */
  2731. static void adjust_rcv_timeout(struct qib_ctxtdata *rcd, int npkts)
  2732. {
  2733. struct qib_devdata *dd = rcd->dd;
  2734. u32 timeout = dd->cspec->rcvavail_timeout[rcd->ctxt];
  2735. /*
  2736. * Dynamically adjust idle timeout on chip
  2737. * based on number of packets processed.
  2738. */
  2739. if (npkts < rcv_int_count && timeout > 2)
  2740. timeout >>= 1;
  2741. else if (npkts >= rcv_int_count && timeout < rcv_int_timeout)
  2742. timeout = min(timeout << 1, rcv_int_timeout);
  2743. else
  2744. return;
  2745. dd->cspec->rcvavail_timeout[rcd->ctxt] = timeout;
  2746. qib_write_kreg(dd, kr_rcvavailtimeout + rcd->ctxt, timeout);
  2747. }
  2748. /*
  2749. * This is the main interrupt handler.
  2750. * It will normally only be used for low frequency interrupts but may
  2751. * have to handle all interrupts if INTx is enabled or fewer than normal
  2752. * MSIx interrupts were allocated.
  2753. * This routine should ignore the interrupt bits for any of the
  2754. * dedicated MSIx handlers.
  2755. */
  2756. static irqreturn_t qib_7322intr(int irq, void *data)
  2757. {
  2758. struct qib_devdata *dd = data;
  2759. irqreturn_t ret;
  2760. u64 istat;
  2761. u64 ctxtrbits;
  2762. u64 rmask;
  2763. unsigned i;
  2764. u32 npkts;
  2765. if ((dd->flags & (QIB_PRESENT | QIB_BADINTR)) != QIB_PRESENT) {
  2766. /*
  2767. * This return value is not great, but we do not want the
  2768. * interrupt core code to remove our interrupt handler
  2769. * because we don't appear to be handling an interrupt
  2770. * during a chip reset.
  2771. */
  2772. ret = IRQ_HANDLED;
  2773. goto bail;
  2774. }
  2775. istat = qib_read_kreg64(dd, kr_intstatus);
  2776. if (unlikely(istat == ~0ULL)) {
  2777. qib_bad_intrstatus(dd);
  2778. qib_dev_err(dd, "Interrupt status all f's, skipping\n");
  2779. /* don't know if it was our interrupt or not */
  2780. ret = IRQ_NONE;
  2781. goto bail;
  2782. }
  2783. istat &= dd->cspec->main_int_mask;
  2784. if (unlikely(!istat)) {
  2785. /* already handled, or shared and not us */
  2786. ret = IRQ_NONE;
  2787. goto bail;
  2788. }
  2789. this_cpu_inc(*dd->int_counter);
  2790. /* handle "errors" of various kinds first, device ahead of port */
  2791. if (unlikely(istat & (~QIB_I_BITSEXTANT | QIB_I_GPIO |
  2792. QIB_I_C_ERROR | INT_MASK_P(Err, 0) |
  2793. INT_MASK_P(Err, 1))))
  2794. unlikely_7322_intr(dd, istat);
  2795. /*
  2796. * Clear the interrupt bits we found set, relatively early, so we
  2797. * "know" know the chip will have seen this by the time we process
  2798. * the queue, and will re-interrupt if necessary. The processor
  2799. * itself won't take the interrupt again until we return.
  2800. */
  2801. qib_write_kreg(dd, kr_intclear, istat);
  2802. /*
  2803. * Handle kernel receive queues before checking for pio buffers
  2804. * available since receives can overflow; piobuf waiters can afford
  2805. * a few extra cycles, since they were waiting anyway.
  2806. */
  2807. ctxtrbits = istat & (QIB_I_RCVAVAIL_MASK | QIB_I_RCVURG_MASK);
  2808. if (ctxtrbits) {
  2809. rmask = (1ULL << QIB_I_RCVAVAIL_LSB) |
  2810. (1ULL << QIB_I_RCVURG_LSB);
  2811. for (i = 0; i < dd->first_user_ctxt; i++) {
  2812. if (ctxtrbits & rmask) {
  2813. ctxtrbits &= ~rmask;
  2814. if (dd->rcd[i])
  2815. qib_kreceive(dd->rcd[i], NULL, &npkts);
  2816. }
  2817. rmask <<= 1;
  2818. }
  2819. if (ctxtrbits) {
  2820. ctxtrbits = (ctxtrbits >> QIB_I_RCVAVAIL_LSB) |
  2821. (ctxtrbits >> QIB_I_RCVURG_LSB);
  2822. qib_handle_urcv(dd, ctxtrbits);
  2823. }
  2824. }
  2825. if (istat & (QIB_I_P_SDMAINT(0) | QIB_I_P_SDMAINT(1)))
  2826. sdma_7322_intr(dd, istat);
  2827. if ((istat & QIB_I_SPIOBUFAVAIL) && (dd->flags & QIB_INITTED))
  2828. qib_ib_piobufavail(dd);
  2829. ret = IRQ_HANDLED;
  2830. bail:
  2831. return ret;
  2832. }
  2833. /*
  2834. * Dedicated receive packet available interrupt handler.
  2835. */
  2836. static irqreturn_t qib_7322pintr(int irq, void *data)
  2837. {
  2838. struct qib_ctxtdata *rcd = data;
  2839. struct qib_devdata *dd = rcd->dd;
  2840. u32 npkts;
  2841. if ((dd->flags & (QIB_PRESENT | QIB_BADINTR)) != QIB_PRESENT)
  2842. /*
  2843. * This return value is not great, but we do not want the
  2844. * interrupt core code to remove our interrupt handler
  2845. * because we don't appear to be handling an interrupt
  2846. * during a chip reset.
  2847. */
  2848. return IRQ_HANDLED;
  2849. this_cpu_inc(*dd->int_counter);
  2850. /* Clear the interrupt bit we expect to be set. */
  2851. qib_write_kreg(dd, kr_intclear, ((1ULL << QIB_I_RCVAVAIL_LSB) |
  2852. (1ULL << QIB_I_RCVURG_LSB)) << rcd->ctxt);
  2853. qib_kreceive(rcd, NULL, &npkts);
  2854. return IRQ_HANDLED;
  2855. }
  2856. /*
  2857. * Dedicated Send buffer available interrupt handler.
  2858. */
  2859. static irqreturn_t qib_7322bufavail(int irq, void *data)
  2860. {
  2861. struct qib_devdata *dd = data;
  2862. if ((dd->flags & (QIB_PRESENT | QIB_BADINTR)) != QIB_PRESENT)
  2863. /*
  2864. * This return value is not great, but we do not want the
  2865. * interrupt core code to remove our interrupt handler
  2866. * because we don't appear to be handling an interrupt
  2867. * during a chip reset.
  2868. */
  2869. return IRQ_HANDLED;
  2870. this_cpu_inc(*dd->int_counter);
  2871. /* Clear the interrupt bit we expect to be set. */
  2872. qib_write_kreg(dd, kr_intclear, QIB_I_SPIOBUFAVAIL);
  2873. /* qib_ib_piobufavail() will clear the want PIO interrupt if needed */
  2874. if (dd->flags & QIB_INITTED)
  2875. qib_ib_piobufavail(dd);
  2876. else
  2877. qib_wantpiobuf_7322_intr(dd, 0);
  2878. return IRQ_HANDLED;
  2879. }
  2880. /*
  2881. * Dedicated Send DMA interrupt handler.
  2882. */
  2883. static irqreturn_t sdma_intr(int irq, void *data)
  2884. {
  2885. struct qib_pportdata *ppd = data;
  2886. struct qib_devdata *dd = ppd->dd;
  2887. if ((dd->flags & (QIB_PRESENT | QIB_BADINTR)) != QIB_PRESENT)
  2888. /*
  2889. * This return value is not great, but we do not want the
  2890. * interrupt core code to remove our interrupt handler
  2891. * because we don't appear to be handling an interrupt
  2892. * during a chip reset.
  2893. */
  2894. return IRQ_HANDLED;
  2895. this_cpu_inc(*dd->int_counter);
  2896. /* Clear the interrupt bit we expect to be set. */
  2897. qib_write_kreg(dd, kr_intclear, ppd->hw_pidx ?
  2898. INT_MASK_P(SDma, 1) : INT_MASK_P(SDma, 0));
  2899. qib_sdma_intr(ppd);
  2900. return IRQ_HANDLED;
  2901. }
  2902. /*
  2903. * Dedicated Send DMA idle interrupt handler.
  2904. */
  2905. static irqreturn_t sdma_idle_intr(int irq, void *data)
  2906. {
  2907. struct qib_pportdata *ppd = data;
  2908. struct qib_devdata *dd = ppd->dd;
  2909. if ((dd->flags & (QIB_PRESENT | QIB_BADINTR)) != QIB_PRESENT)
  2910. /*
  2911. * This return value is not great, but we do not want the
  2912. * interrupt core code to remove our interrupt handler
  2913. * because we don't appear to be handling an interrupt
  2914. * during a chip reset.
  2915. */
  2916. return IRQ_HANDLED;
  2917. this_cpu_inc(*dd->int_counter);
  2918. /* Clear the interrupt bit we expect to be set. */
  2919. qib_write_kreg(dd, kr_intclear, ppd->hw_pidx ?
  2920. INT_MASK_P(SDmaIdle, 1) : INT_MASK_P(SDmaIdle, 0));
  2921. qib_sdma_intr(ppd);
  2922. return IRQ_HANDLED;
  2923. }
  2924. /*
  2925. * Dedicated Send DMA progress interrupt handler.
  2926. */
  2927. static irqreturn_t sdma_progress_intr(int irq, void *data)
  2928. {
  2929. struct qib_pportdata *ppd = data;
  2930. struct qib_devdata *dd = ppd->dd;
  2931. if ((dd->flags & (QIB_PRESENT | QIB_BADINTR)) != QIB_PRESENT)
  2932. /*
  2933. * This return value is not great, but we do not want the
  2934. * interrupt core code to remove our interrupt handler
  2935. * because we don't appear to be handling an interrupt
  2936. * during a chip reset.
  2937. */
  2938. return IRQ_HANDLED;
  2939. this_cpu_inc(*dd->int_counter);
  2940. /* Clear the interrupt bit we expect to be set. */
  2941. qib_write_kreg(dd, kr_intclear, ppd->hw_pidx ?
  2942. INT_MASK_P(SDmaProgress, 1) :
  2943. INT_MASK_P(SDmaProgress, 0));
  2944. qib_sdma_intr(ppd);
  2945. return IRQ_HANDLED;
  2946. }
  2947. /*
  2948. * Dedicated Send DMA cleanup interrupt handler.
  2949. */
  2950. static irqreturn_t sdma_cleanup_intr(int irq, void *data)
  2951. {
  2952. struct qib_pportdata *ppd = data;
  2953. struct qib_devdata *dd = ppd->dd;
  2954. if ((dd->flags & (QIB_PRESENT | QIB_BADINTR)) != QIB_PRESENT)
  2955. /*
  2956. * This return value is not great, but we do not want the
  2957. * interrupt core code to remove our interrupt handler
  2958. * because we don't appear to be handling an interrupt
  2959. * during a chip reset.
  2960. */
  2961. return IRQ_HANDLED;
  2962. this_cpu_inc(*dd->int_counter);
  2963. /* Clear the interrupt bit we expect to be set. */
  2964. qib_write_kreg(dd, kr_intclear, ppd->hw_pidx ?
  2965. INT_MASK_PM(SDmaCleanupDone, 1) :
  2966. INT_MASK_PM(SDmaCleanupDone, 0));
  2967. qib_sdma_process_event(ppd, qib_sdma_event_e20_hw_started);
  2968. return IRQ_HANDLED;
  2969. }
  2970. #ifdef CONFIG_INFINIBAND_QIB_DCA
  2971. static void reset_dca_notifier(struct qib_devdata *dd, struct qib_msix_entry *m)
  2972. {
  2973. if (!m->dca)
  2974. return;
  2975. qib_devinfo(dd->pcidev,
  2976. "Disabling notifier on HCA %d irq %d\n",
  2977. dd->unit,
  2978. m->msix.vector);
  2979. irq_set_affinity_notifier(
  2980. m->msix.vector,
  2981. NULL);
  2982. m->notifier = NULL;
  2983. }
  2984. static void setup_dca_notifier(struct qib_devdata *dd, struct qib_msix_entry *m)
  2985. {
  2986. struct qib_irq_notify *n;
  2987. if (!m->dca)
  2988. return;
  2989. n = kzalloc(sizeof(*n), GFP_KERNEL);
  2990. if (n) {
  2991. int ret;
  2992. m->notifier = n;
  2993. n->notify.irq = m->msix.vector;
  2994. n->notify.notify = qib_irq_notifier_notify;
  2995. n->notify.release = qib_irq_notifier_release;
  2996. n->arg = m->arg;
  2997. n->rcv = m->rcv;
  2998. qib_devinfo(dd->pcidev,
  2999. "set notifier irq %d rcv %d notify %p\n",
  3000. n->notify.irq, n->rcv, &n->notify);
  3001. ret = irq_set_affinity_notifier(
  3002. n->notify.irq,
  3003. &n->notify);
  3004. if (ret) {
  3005. m->notifier = NULL;
  3006. kfree(n);
  3007. }
  3008. }
  3009. }
  3010. #endif
  3011. /*
  3012. * Set up our chip-specific interrupt handler.
  3013. * The interrupt type has already been setup, so
  3014. * we just need to do the registration and error checking.
  3015. * If we are using MSIx interrupts, we may fall back to
  3016. * INTx later, if the interrupt handler doesn't get called
  3017. * within 1/2 second (see verify_interrupt()).
  3018. */
  3019. static void qib_setup_7322_interrupt(struct qib_devdata *dd, int clearpend)
  3020. {
  3021. int ret, i, msixnum;
  3022. u64 redirect[6];
  3023. u64 mask;
  3024. const struct cpumask *local_mask;
  3025. int firstcpu, secondcpu = 0, currrcvcpu = 0;
  3026. if (!dd->num_pports)
  3027. return;
  3028. if (clearpend) {
  3029. /*
  3030. * if not switching interrupt types, be sure interrupts are
  3031. * disabled, and then clear anything pending at this point,
  3032. * because we are starting clean.
  3033. */
  3034. qib_7322_set_intr_state(dd, 0);
  3035. /* clear the reset error, init error/hwerror mask */
  3036. qib_7322_init_hwerrors(dd);
  3037. /* clear any interrupt bits that might be set */
  3038. qib_write_kreg(dd, kr_intclear, ~0ULL);
  3039. /* make sure no pending MSIx intr, and clear diag reg */
  3040. qib_write_kreg(dd, kr_intgranted, ~0ULL);
  3041. qib_write_kreg(dd, kr_vecclr_wo_int, ~0ULL);
  3042. }
  3043. if (!dd->cspec->num_msix_entries) {
  3044. /* Try to get INTx interrupt */
  3045. try_intx:
  3046. if (!dd->pcidev->irq) {
  3047. qib_dev_err(dd,
  3048. "irq is 0, BIOS error? Interrupts won't work\n");
  3049. goto bail;
  3050. }
  3051. ret = request_irq(dd->pcidev->irq, qib_7322intr,
  3052. IRQF_SHARED, QIB_DRV_NAME, dd);
  3053. if (ret) {
  3054. qib_dev_err(dd,
  3055. "Couldn't setup INTx interrupt (irq=%d): %d\n",
  3056. dd->pcidev->irq, ret);
  3057. goto bail;
  3058. }
  3059. dd->cspec->irq = dd->pcidev->irq;
  3060. dd->cspec->main_int_mask = ~0ULL;
  3061. goto bail;
  3062. }
  3063. /* Try to get MSIx interrupts */
  3064. memset(redirect, 0, sizeof redirect);
  3065. mask = ~0ULL;
  3066. msixnum = 0;
  3067. local_mask = cpumask_of_pcibus(dd->pcidev->bus);
  3068. firstcpu = cpumask_first(local_mask);
  3069. if (firstcpu >= nr_cpu_ids ||
  3070. cpumask_weight(local_mask) == num_online_cpus()) {
  3071. local_mask = topology_core_cpumask(0);
  3072. firstcpu = cpumask_first(local_mask);
  3073. }
  3074. if (firstcpu < nr_cpu_ids) {
  3075. secondcpu = cpumask_next(firstcpu, local_mask);
  3076. if (secondcpu >= nr_cpu_ids)
  3077. secondcpu = firstcpu;
  3078. currrcvcpu = secondcpu;
  3079. }
  3080. for (i = 0; msixnum < dd->cspec->num_msix_entries; i++) {
  3081. irq_handler_t handler;
  3082. void *arg;
  3083. u64 val;
  3084. int lsb, reg, sh;
  3085. #ifdef CONFIG_INFINIBAND_QIB_DCA
  3086. int dca = 0;
  3087. #endif
  3088. dd->cspec->msix_entries[msixnum].
  3089. name[sizeof(dd->cspec->msix_entries[msixnum].name) - 1]
  3090. = '\0';
  3091. if (i < ARRAY_SIZE(irq_table)) {
  3092. if (irq_table[i].port) {
  3093. /* skip if for a non-configured port */
  3094. if (irq_table[i].port > dd->num_pports)
  3095. continue;
  3096. arg = dd->pport + irq_table[i].port - 1;
  3097. } else
  3098. arg = dd;
  3099. #ifdef CONFIG_INFINIBAND_QIB_DCA
  3100. dca = irq_table[i].dca;
  3101. #endif
  3102. lsb = irq_table[i].lsb;
  3103. handler = irq_table[i].handler;
  3104. snprintf(dd->cspec->msix_entries[msixnum].name,
  3105. sizeof(dd->cspec->msix_entries[msixnum].name)
  3106. - 1,
  3107. QIB_DRV_NAME "%d%s", dd->unit,
  3108. irq_table[i].name);
  3109. } else {
  3110. unsigned ctxt;
  3111. ctxt = i - ARRAY_SIZE(irq_table);
  3112. /* per krcvq context receive interrupt */
  3113. arg = dd->rcd[ctxt];
  3114. if (!arg)
  3115. continue;
  3116. if (qib_krcvq01_no_msi && ctxt < 2)
  3117. continue;
  3118. #ifdef CONFIG_INFINIBAND_QIB_DCA
  3119. dca = 1;
  3120. #endif
  3121. lsb = QIB_I_RCVAVAIL_LSB + ctxt;
  3122. handler = qib_7322pintr;
  3123. snprintf(dd->cspec->msix_entries[msixnum].name,
  3124. sizeof(dd->cspec->msix_entries[msixnum].name)
  3125. - 1,
  3126. QIB_DRV_NAME "%d (kctx)", dd->unit);
  3127. }
  3128. ret = request_irq(
  3129. dd->cspec->msix_entries[msixnum].msix.vector,
  3130. handler, 0, dd->cspec->msix_entries[msixnum].name,
  3131. arg);
  3132. if (ret) {
  3133. /*
  3134. * Shouldn't happen since the enable said we could
  3135. * have as many as we are trying to setup here.
  3136. */
  3137. qib_dev_err(dd,
  3138. "Couldn't setup MSIx interrupt (vec=%d, irq=%d): %d\n",
  3139. msixnum,
  3140. dd->cspec->msix_entries[msixnum].msix.vector,
  3141. ret);
  3142. qib_7322_nomsix(dd);
  3143. goto try_intx;
  3144. }
  3145. dd->cspec->msix_entries[msixnum].arg = arg;
  3146. #ifdef CONFIG_INFINIBAND_QIB_DCA
  3147. dd->cspec->msix_entries[msixnum].dca = dca;
  3148. dd->cspec->msix_entries[msixnum].rcv =
  3149. handler == qib_7322pintr;
  3150. #endif
  3151. if (lsb >= 0) {
  3152. reg = lsb / IBA7322_REDIRECT_VEC_PER_REG;
  3153. sh = (lsb % IBA7322_REDIRECT_VEC_PER_REG) *
  3154. SYM_LSB(IntRedirect0, vec1);
  3155. mask &= ~(1ULL << lsb);
  3156. redirect[reg] |= ((u64) msixnum) << sh;
  3157. }
  3158. val = qib_read_kreg64(dd, 2 * msixnum + 1 +
  3159. (QIB_7322_MsixTable_OFFS / sizeof(u64)));
  3160. if (firstcpu < nr_cpu_ids &&
  3161. zalloc_cpumask_var(
  3162. &dd->cspec->msix_entries[msixnum].mask,
  3163. GFP_KERNEL)) {
  3164. if (handler == qib_7322pintr) {
  3165. cpumask_set_cpu(currrcvcpu,
  3166. dd->cspec->msix_entries[msixnum].mask);
  3167. currrcvcpu = cpumask_next(currrcvcpu,
  3168. local_mask);
  3169. if (currrcvcpu >= nr_cpu_ids)
  3170. currrcvcpu = secondcpu;
  3171. } else {
  3172. cpumask_set_cpu(firstcpu,
  3173. dd->cspec->msix_entries[msixnum].mask);
  3174. }
  3175. irq_set_affinity_hint(
  3176. dd->cspec->msix_entries[msixnum].msix.vector,
  3177. dd->cspec->msix_entries[msixnum].mask);
  3178. }
  3179. msixnum++;
  3180. }
  3181. /* Initialize the vector mapping */
  3182. for (i = 0; i < ARRAY_SIZE(redirect); i++)
  3183. qib_write_kreg(dd, kr_intredirect + i, redirect[i]);
  3184. dd->cspec->main_int_mask = mask;
  3185. tasklet_init(&dd->error_tasklet, qib_error_tasklet,
  3186. (unsigned long)dd);
  3187. bail:;
  3188. }
  3189. /**
  3190. * qib_7322_boardname - fill in the board name and note features
  3191. * @dd: the qlogic_ib device
  3192. *
  3193. * info will be based on the board revision register
  3194. */
  3195. static unsigned qib_7322_boardname(struct qib_devdata *dd)
  3196. {
  3197. /* Will need enumeration of board-types here */
  3198. char *n;
  3199. u32 boardid, namelen;
  3200. unsigned features = DUAL_PORT_CAP;
  3201. boardid = SYM_FIELD(dd->revision, Revision, BoardID);
  3202. switch (boardid) {
  3203. case 0:
  3204. n = "InfiniPath_QLE7342_Emulation";
  3205. break;
  3206. case 1:
  3207. n = "InfiniPath_QLE7340";
  3208. dd->flags |= QIB_HAS_QSFP;
  3209. features = PORT_SPD_CAP;
  3210. break;
  3211. case 2:
  3212. n = "InfiniPath_QLE7342";
  3213. dd->flags |= QIB_HAS_QSFP;
  3214. break;
  3215. case 3:
  3216. n = "InfiniPath_QMI7342";
  3217. break;
  3218. case 4:
  3219. n = "InfiniPath_Unsupported7342";
  3220. qib_dev_err(dd, "Unsupported version of QMH7342\n");
  3221. features = 0;
  3222. break;
  3223. case BOARD_QMH7342:
  3224. n = "InfiniPath_QMH7342";
  3225. features = 0x24;
  3226. break;
  3227. case BOARD_QME7342:
  3228. n = "InfiniPath_QME7342";
  3229. break;
  3230. case 8:
  3231. n = "InfiniPath_QME7362";
  3232. dd->flags |= QIB_HAS_QSFP;
  3233. break;
  3234. case 15:
  3235. n = "InfiniPath_QLE7342_TEST";
  3236. dd->flags |= QIB_HAS_QSFP;
  3237. break;
  3238. default:
  3239. n = "InfiniPath_QLE73xy_UNKNOWN";
  3240. qib_dev_err(dd, "Unknown 7322 board type %u\n", boardid);
  3241. break;
  3242. }
  3243. dd->board_atten = 1; /* index into txdds_Xdr */
  3244. namelen = strlen(n) + 1;
  3245. dd->boardname = kmalloc(namelen, GFP_KERNEL);
  3246. if (!dd->boardname)
  3247. qib_dev_err(dd, "Failed allocation for board name: %s\n", n);
  3248. else
  3249. snprintf(dd->boardname, namelen, "%s", n);
  3250. snprintf(dd->boardversion, sizeof(dd->boardversion),
  3251. "ChipABI %u.%u, %s, InfiniPath%u %u.%u, SW Compat %u\n",
  3252. QIB_CHIP_VERS_MAJ, QIB_CHIP_VERS_MIN, dd->boardname,
  3253. (unsigned)SYM_FIELD(dd->revision, Revision_R, Arch),
  3254. dd->majrev, dd->minrev,
  3255. (unsigned)SYM_FIELD(dd->revision, Revision_R, SW));
  3256. if (qib_singleport && (features >> PORT_SPD_CAP_SHIFT) & PORT_SPD_CAP) {
  3257. qib_devinfo(dd->pcidev,
  3258. "IB%u: Forced to single port mode by module parameter\n",
  3259. dd->unit);
  3260. features &= PORT_SPD_CAP;
  3261. }
  3262. return features;
  3263. }
  3264. /*
  3265. * This routine sleeps, so it can only be called from user context, not
  3266. * from interrupt context.
  3267. */
  3268. static int qib_do_7322_reset(struct qib_devdata *dd)
  3269. {
  3270. u64 val;
  3271. u64 *msix_vecsave;
  3272. int i, msix_entries, ret = 1;
  3273. u16 cmdval;
  3274. u8 int_line, clinesz;
  3275. unsigned long flags;
  3276. /* Use dev_err so it shows up in logs, etc. */
  3277. qib_dev_err(dd, "Resetting InfiniPath unit %u\n", dd->unit);
  3278. qib_pcie_getcmd(dd, &cmdval, &int_line, &clinesz);
  3279. msix_entries = dd->cspec->num_msix_entries;
  3280. /* no interrupts till re-initted */
  3281. qib_7322_set_intr_state(dd, 0);
  3282. if (msix_entries) {
  3283. qib_7322_nomsix(dd);
  3284. /* can be up to 512 bytes, too big for stack */
  3285. msix_vecsave = kmalloc(2 * dd->cspec->num_msix_entries *
  3286. sizeof(u64), GFP_KERNEL);
  3287. if (!msix_vecsave)
  3288. qib_dev_err(dd, "No mem to save MSIx data\n");
  3289. } else
  3290. msix_vecsave = NULL;
  3291. /*
  3292. * Core PCI (as of 2.6.18) doesn't save or rewrite the full vector
  3293. * info that is set up by the BIOS, so we have to save and restore
  3294. * it ourselves. There is some risk something could change it,
  3295. * after we save it, but since we have disabled the MSIx, it
  3296. * shouldn't be touched...
  3297. */
  3298. for (i = 0; i < msix_entries; i++) {
  3299. u64 vecaddr, vecdata;
  3300. vecaddr = qib_read_kreg64(dd, 2 * i +
  3301. (QIB_7322_MsixTable_OFFS / sizeof(u64)));
  3302. vecdata = qib_read_kreg64(dd, 1 + 2 * i +
  3303. (QIB_7322_MsixTable_OFFS / sizeof(u64)));
  3304. if (msix_vecsave) {
  3305. msix_vecsave[2 * i] = vecaddr;
  3306. /* save it without the masked bit set */
  3307. msix_vecsave[1 + 2 * i] = vecdata & ~0x100000000ULL;
  3308. }
  3309. }
  3310. dd->pport->cpspec->ibdeltainprog = 0;
  3311. dd->pport->cpspec->ibsymdelta = 0;
  3312. dd->pport->cpspec->iblnkerrdelta = 0;
  3313. dd->pport->cpspec->ibmalfdelta = 0;
  3314. /* so we check interrupts work again */
  3315. dd->z_int_counter = qib_int_counter(dd);
  3316. /*
  3317. * Keep chip from being accessed until we are ready. Use
  3318. * writeq() directly, to allow the write even though QIB_PRESENT
  3319. * isn't set.
  3320. */
  3321. dd->flags &= ~(QIB_INITTED | QIB_PRESENT | QIB_BADINTR);
  3322. dd->flags |= QIB_DOING_RESET;
  3323. val = dd->control | QLOGIC_IB_C_RESET;
  3324. writeq(val, &dd->kregbase[kr_control]);
  3325. for (i = 1; i <= 5; i++) {
  3326. /*
  3327. * Allow MBIST, etc. to complete; longer on each retry.
  3328. * We sometimes get machine checks from bus timeout if no
  3329. * response, so for now, make it *really* long.
  3330. */
  3331. msleep(1000 + (1 + i) * 3000);
  3332. qib_pcie_reenable(dd, cmdval, int_line, clinesz);
  3333. /*
  3334. * Use readq directly, so we don't need to mark it as PRESENT
  3335. * until we get a successful indication that all is well.
  3336. */
  3337. val = readq(&dd->kregbase[kr_revision]);
  3338. if (val == dd->revision)
  3339. break;
  3340. if (i == 5) {
  3341. qib_dev_err(dd,
  3342. "Failed to initialize after reset, unusable\n");
  3343. ret = 0;
  3344. goto bail;
  3345. }
  3346. }
  3347. dd->flags |= QIB_PRESENT; /* it's back */
  3348. if (msix_entries) {
  3349. /* restore the MSIx vector address and data if saved above */
  3350. for (i = 0; i < msix_entries; i++) {
  3351. dd->cspec->msix_entries[i].msix.entry = i;
  3352. if (!msix_vecsave || !msix_vecsave[2 * i])
  3353. continue;
  3354. qib_write_kreg(dd, 2 * i +
  3355. (QIB_7322_MsixTable_OFFS / sizeof(u64)),
  3356. msix_vecsave[2 * i]);
  3357. qib_write_kreg(dd, 1 + 2 * i +
  3358. (QIB_7322_MsixTable_OFFS / sizeof(u64)),
  3359. msix_vecsave[1 + 2 * i]);
  3360. }
  3361. }
  3362. /* initialize the remaining registers. */
  3363. for (i = 0; i < dd->num_pports; ++i)
  3364. write_7322_init_portregs(&dd->pport[i]);
  3365. write_7322_initregs(dd);
  3366. if (qib_pcie_params(dd, dd->lbus_width,
  3367. &dd->cspec->num_msix_entries,
  3368. dd->cspec->msix_entries))
  3369. qib_dev_err(dd,
  3370. "Reset failed to setup PCIe or interrupts; continuing anyway\n");
  3371. qib_setup_7322_interrupt(dd, 1);
  3372. for (i = 0; i < dd->num_pports; ++i) {
  3373. struct qib_pportdata *ppd = &dd->pport[i];
  3374. spin_lock_irqsave(&ppd->lflags_lock, flags);
  3375. ppd->lflags |= QIBL_IB_FORCE_NOTIFY;
  3376. ppd->lflags &= ~QIBL_IB_AUTONEG_FAILED;
  3377. spin_unlock_irqrestore(&ppd->lflags_lock, flags);
  3378. }
  3379. bail:
  3380. dd->flags &= ~QIB_DOING_RESET; /* OK or not, no longer resetting */
  3381. kfree(msix_vecsave);
  3382. return ret;
  3383. }
  3384. /**
  3385. * qib_7322_put_tid - write a TID to the chip
  3386. * @dd: the qlogic_ib device
  3387. * @tidptr: pointer to the expected TID (in chip) to update
  3388. * @tidtype: 0 for eager, 1 for expected
  3389. * @pa: physical address of in memory buffer; tidinvalid if freeing
  3390. */
  3391. static void qib_7322_put_tid(struct qib_devdata *dd, u64 __iomem *tidptr,
  3392. u32 type, unsigned long pa)
  3393. {
  3394. if (!(dd->flags & QIB_PRESENT))
  3395. return;
  3396. if (pa != dd->tidinvalid) {
  3397. u64 chippa = pa >> IBA7322_TID_PA_SHIFT;
  3398. /* paranoia checks */
  3399. if (pa != (chippa << IBA7322_TID_PA_SHIFT)) {
  3400. qib_dev_err(dd, "Physaddr %lx not 2KB aligned!\n",
  3401. pa);
  3402. return;
  3403. }
  3404. if (chippa >= (1UL << IBA7322_TID_SZ_SHIFT)) {
  3405. qib_dev_err(dd,
  3406. "Physical page address 0x%lx larger than supported\n",
  3407. pa);
  3408. return;
  3409. }
  3410. if (type == RCVHQ_RCV_TYPE_EAGER)
  3411. chippa |= dd->tidtemplate;
  3412. else /* for now, always full 4KB page */
  3413. chippa |= IBA7322_TID_SZ_4K;
  3414. pa = chippa;
  3415. }
  3416. writeq(pa, tidptr);
  3417. mmiowb();
  3418. }
  3419. /**
  3420. * qib_7322_clear_tids - clear all TID entries for a ctxt, expected and eager
  3421. * @dd: the qlogic_ib device
  3422. * @ctxt: the ctxt
  3423. *
  3424. * clear all TID entries for a ctxt, expected and eager.
  3425. * Used from qib_close().
  3426. */
  3427. static void qib_7322_clear_tids(struct qib_devdata *dd,
  3428. struct qib_ctxtdata *rcd)
  3429. {
  3430. u64 __iomem *tidbase;
  3431. unsigned long tidinv;
  3432. u32 ctxt;
  3433. int i;
  3434. if (!dd->kregbase || !rcd)
  3435. return;
  3436. ctxt = rcd->ctxt;
  3437. tidinv = dd->tidinvalid;
  3438. tidbase = (u64 __iomem *)
  3439. ((char __iomem *) dd->kregbase +
  3440. dd->rcvtidbase +
  3441. ctxt * dd->rcvtidcnt * sizeof(*tidbase));
  3442. for (i = 0; i < dd->rcvtidcnt; i++)
  3443. qib_7322_put_tid(dd, &tidbase[i], RCVHQ_RCV_TYPE_EXPECTED,
  3444. tidinv);
  3445. tidbase = (u64 __iomem *)
  3446. ((char __iomem *) dd->kregbase +
  3447. dd->rcvegrbase +
  3448. rcd->rcvegr_tid_base * sizeof(*tidbase));
  3449. for (i = 0; i < rcd->rcvegrcnt; i++)
  3450. qib_7322_put_tid(dd, &tidbase[i], RCVHQ_RCV_TYPE_EAGER,
  3451. tidinv);
  3452. }
  3453. /**
  3454. * qib_7322_tidtemplate - setup constants for TID updates
  3455. * @dd: the qlogic_ib device
  3456. *
  3457. * We setup stuff that we use a lot, to avoid calculating each time
  3458. */
  3459. static void qib_7322_tidtemplate(struct qib_devdata *dd)
  3460. {
  3461. /*
  3462. * For now, we always allocate 4KB buffers (at init) so we can
  3463. * receive max size packets. We may want a module parameter to
  3464. * specify 2KB or 4KB and/or make it per port instead of per device
  3465. * for those who want to reduce memory footprint. Note that the
  3466. * rcvhdrentsize size must be large enough to hold the largest
  3467. * IB header (currently 96 bytes) that we expect to handle (plus of
  3468. * course the 2 dwords of RHF).
  3469. */
  3470. if (dd->rcvegrbufsize == 2048)
  3471. dd->tidtemplate = IBA7322_TID_SZ_2K;
  3472. else if (dd->rcvegrbufsize == 4096)
  3473. dd->tidtemplate = IBA7322_TID_SZ_4K;
  3474. dd->tidinvalid = 0;
  3475. }
  3476. /**
  3477. * qib_init_7322_get_base_info - set chip-specific flags for user code
  3478. * @rcd: the qlogic_ib ctxt
  3479. * @kbase: qib_base_info pointer
  3480. *
  3481. * We set the PCIE flag because the lower bandwidth on PCIe vs
  3482. * HyperTransport can affect some user packet algorithims.
  3483. */
  3484. static int qib_7322_get_base_info(struct qib_ctxtdata *rcd,
  3485. struct qib_base_info *kinfo)
  3486. {
  3487. kinfo->spi_runtime_flags |= QIB_RUNTIME_CTXT_MSB_IN_QP |
  3488. QIB_RUNTIME_PCIE | QIB_RUNTIME_NODMA_RTAIL |
  3489. QIB_RUNTIME_HDRSUPP | QIB_RUNTIME_SDMA;
  3490. if (rcd->dd->cspec->r1)
  3491. kinfo->spi_runtime_flags |= QIB_RUNTIME_RCHK;
  3492. if (rcd->dd->flags & QIB_USE_SPCL_TRIG)
  3493. kinfo->spi_runtime_flags |= QIB_RUNTIME_SPECIAL_TRIGGER;
  3494. return 0;
  3495. }
  3496. static struct qib_message_header *
  3497. qib_7322_get_msgheader(struct qib_devdata *dd, __le32 *rhf_addr)
  3498. {
  3499. u32 offset = qib_hdrget_offset(rhf_addr);
  3500. return (struct qib_message_header *)
  3501. (rhf_addr - dd->rhf_offset + offset);
  3502. }
  3503. /*
  3504. * Configure number of contexts.
  3505. */
  3506. static void qib_7322_config_ctxts(struct qib_devdata *dd)
  3507. {
  3508. unsigned long flags;
  3509. u32 nchipctxts;
  3510. nchipctxts = qib_read_kreg32(dd, kr_contextcnt);
  3511. dd->cspec->numctxts = nchipctxts;
  3512. if (qib_n_krcv_queues > 1 && dd->num_pports) {
  3513. dd->first_user_ctxt = NUM_IB_PORTS +
  3514. (qib_n_krcv_queues - 1) * dd->num_pports;
  3515. if (dd->first_user_ctxt > nchipctxts)
  3516. dd->first_user_ctxt = nchipctxts;
  3517. dd->n_krcv_queues = dd->first_user_ctxt / dd->num_pports;
  3518. } else {
  3519. dd->first_user_ctxt = NUM_IB_PORTS;
  3520. dd->n_krcv_queues = 1;
  3521. }
  3522. if (!qib_cfgctxts) {
  3523. int nctxts = dd->first_user_ctxt + num_online_cpus();
  3524. if (nctxts <= 6)
  3525. dd->ctxtcnt = 6;
  3526. else if (nctxts <= 10)
  3527. dd->ctxtcnt = 10;
  3528. else if (nctxts <= nchipctxts)
  3529. dd->ctxtcnt = nchipctxts;
  3530. } else if (qib_cfgctxts < dd->num_pports)
  3531. dd->ctxtcnt = dd->num_pports;
  3532. else if (qib_cfgctxts <= nchipctxts)
  3533. dd->ctxtcnt = qib_cfgctxts;
  3534. if (!dd->ctxtcnt) /* none of the above, set to max */
  3535. dd->ctxtcnt = nchipctxts;
  3536. /*
  3537. * Chip can be configured for 6, 10, or 18 ctxts, and choice
  3538. * affects number of eager TIDs per ctxt (1K, 2K, 4K).
  3539. * Lock to be paranoid about later motion, etc.
  3540. */
  3541. spin_lock_irqsave(&dd->cspec->rcvmod_lock, flags);
  3542. if (dd->ctxtcnt > 10)
  3543. dd->rcvctrl |= 2ULL << SYM_LSB(RcvCtrl, ContextCfg);
  3544. else if (dd->ctxtcnt > 6)
  3545. dd->rcvctrl |= 1ULL << SYM_LSB(RcvCtrl, ContextCfg);
  3546. /* else configure for default 6 receive ctxts */
  3547. /* The XRC opcode is 5. */
  3548. dd->rcvctrl |= 5ULL << SYM_LSB(RcvCtrl, XrcTypeCode);
  3549. /*
  3550. * RcvCtrl *must* be written here so that the
  3551. * chip understands how to change rcvegrcnt below.
  3552. */
  3553. qib_write_kreg(dd, kr_rcvctrl, dd->rcvctrl);
  3554. spin_unlock_irqrestore(&dd->cspec->rcvmod_lock, flags);
  3555. /* kr_rcvegrcnt changes based on the number of contexts enabled */
  3556. dd->cspec->rcvegrcnt = qib_read_kreg32(dd, kr_rcvegrcnt);
  3557. if (qib_rcvhdrcnt)
  3558. dd->rcvhdrcnt = max(dd->cspec->rcvegrcnt, qib_rcvhdrcnt);
  3559. else
  3560. dd->rcvhdrcnt = 2 * max(dd->cspec->rcvegrcnt,
  3561. dd->num_pports > 1 ? 1024U : 2048U);
  3562. }
  3563. static int qib_7322_get_ib_cfg(struct qib_pportdata *ppd, int which)
  3564. {
  3565. int lsb, ret = 0;
  3566. u64 maskr; /* right-justified mask */
  3567. switch (which) {
  3568. case QIB_IB_CFG_LWID_ENB: /* Get allowed Link-width */
  3569. ret = ppd->link_width_enabled;
  3570. goto done;
  3571. case QIB_IB_CFG_LWID: /* Get currently active Link-width */
  3572. ret = ppd->link_width_active;
  3573. goto done;
  3574. case QIB_IB_CFG_SPD_ENB: /* Get allowed Link speeds */
  3575. ret = ppd->link_speed_enabled;
  3576. goto done;
  3577. case QIB_IB_CFG_SPD: /* Get current Link spd */
  3578. ret = ppd->link_speed_active;
  3579. goto done;
  3580. case QIB_IB_CFG_RXPOL_ENB: /* Get Auto-RX-polarity enable */
  3581. lsb = SYM_LSB(IBCCtrlB_0, IB_POLARITY_REV_SUPP);
  3582. maskr = SYM_RMASK(IBCCtrlB_0, IB_POLARITY_REV_SUPP);
  3583. break;
  3584. case QIB_IB_CFG_LREV_ENB: /* Get Auto-Lane-reversal enable */
  3585. lsb = SYM_LSB(IBCCtrlB_0, IB_LANE_REV_SUPPORTED);
  3586. maskr = SYM_RMASK(IBCCtrlB_0, IB_LANE_REV_SUPPORTED);
  3587. break;
  3588. case QIB_IB_CFG_LINKLATENCY:
  3589. ret = qib_read_kreg_port(ppd, krp_ibcstatus_b) &
  3590. SYM_MASK(IBCStatusB_0, LinkRoundTripLatency);
  3591. goto done;
  3592. case QIB_IB_CFG_OP_VLS:
  3593. ret = ppd->vls_operational;
  3594. goto done;
  3595. case QIB_IB_CFG_VL_HIGH_CAP:
  3596. ret = 16;
  3597. goto done;
  3598. case QIB_IB_CFG_VL_LOW_CAP:
  3599. ret = 16;
  3600. goto done;
  3601. case QIB_IB_CFG_OVERRUN_THRESH: /* IB overrun threshold */
  3602. ret = SYM_FIELD(ppd->cpspec->ibcctrl_a, IBCCtrlA_0,
  3603. OverrunThreshold);
  3604. goto done;
  3605. case QIB_IB_CFG_PHYERR_THRESH: /* IB PHY error threshold */
  3606. ret = SYM_FIELD(ppd->cpspec->ibcctrl_a, IBCCtrlA_0,
  3607. PhyerrThreshold);
  3608. goto done;
  3609. case QIB_IB_CFG_LINKDEFAULT: /* IB link default (sleep/poll) */
  3610. /* will only take effect when the link state changes */
  3611. ret = (ppd->cpspec->ibcctrl_a &
  3612. SYM_MASK(IBCCtrlA_0, LinkDownDefaultState)) ?
  3613. IB_LINKINITCMD_SLEEP : IB_LINKINITCMD_POLL;
  3614. goto done;
  3615. case QIB_IB_CFG_HRTBT: /* Get Heartbeat off/enable/auto */
  3616. lsb = IBA7322_IBC_HRTBT_LSB;
  3617. maskr = IBA7322_IBC_HRTBT_RMASK; /* OR of AUTO and ENB */
  3618. break;
  3619. case QIB_IB_CFG_PMA_TICKS:
  3620. /*
  3621. * 0x00 = 10x link transfer rate or 4 nsec. for 2.5Gbs
  3622. * Since the clock is always 250MHz, the value is 3, 1 or 0.
  3623. */
  3624. if (ppd->link_speed_active == QIB_IB_QDR)
  3625. ret = 3;
  3626. else if (ppd->link_speed_active == QIB_IB_DDR)
  3627. ret = 1;
  3628. else
  3629. ret = 0;
  3630. goto done;
  3631. default:
  3632. ret = -EINVAL;
  3633. goto done;
  3634. }
  3635. ret = (int)((ppd->cpspec->ibcctrl_b >> lsb) & maskr);
  3636. done:
  3637. return ret;
  3638. }
  3639. /*
  3640. * Below again cribbed liberally from older version. Do not lean
  3641. * heavily on it.
  3642. */
  3643. #define IBA7322_IBC_DLIDLMC_SHIFT QIB_7322_IBCCtrlB_0_IB_DLID_LSB
  3644. #define IBA7322_IBC_DLIDLMC_MASK (QIB_7322_IBCCtrlB_0_IB_DLID_RMASK \
  3645. | (QIB_7322_IBCCtrlB_0_IB_DLID_MASK_RMASK << 16))
  3646. static int qib_7322_set_ib_cfg(struct qib_pportdata *ppd, int which, u32 val)
  3647. {
  3648. struct qib_devdata *dd = ppd->dd;
  3649. u64 maskr; /* right-justified mask */
  3650. int lsb, ret = 0;
  3651. u16 lcmd, licmd;
  3652. unsigned long flags;
  3653. switch (which) {
  3654. case QIB_IB_CFG_LIDLMC:
  3655. /*
  3656. * Set LID and LMC. Combined to avoid possible hazard
  3657. * caller puts LMC in 16MSbits, DLID in 16LSbits of val
  3658. */
  3659. lsb = IBA7322_IBC_DLIDLMC_SHIFT;
  3660. maskr = IBA7322_IBC_DLIDLMC_MASK;
  3661. /*
  3662. * For header-checking, the SLID in the packet will
  3663. * be masked with SendIBSLMCMask, and compared
  3664. * with SendIBSLIDAssignMask. Make sure we do not
  3665. * set any bits not covered by the mask, or we get
  3666. * false-positives.
  3667. */
  3668. qib_write_kreg_port(ppd, krp_sendslid,
  3669. val & (val >> 16) & SendIBSLIDAssignMask);
  3670. qib_write_kreg_port(ppd, krp_sendslidmask,
  3671. (val >> 16) & SendIBSLMCMask);
  3672. break;
  3673. case QIB_IB_CFG_LWID_ENB: /* set allowed Link-width */
  3674. ppd->link_width_enabled = val;
  3675. /* convert IB value to chip register value */
  3676. if (val == IB_WIDTH_1X)
  3677. val = 0;
  3678. else if (val == IB_WIDTH_4X)
  3679. val = 1;
  3680. else
  3681. val = 3;
  3682. maskr = SYM_RMASK(IBCCtrlB_0, IB_NUM_CHANNELS);
  3683. lsb = SYM_LSB(IBCCtrlB_0, IB_NUM_CHANNELS);
  3684. break;
  3685. case QIB_IB_CFG_SPD_ENB: /* set allowed Link speeds */
  3686. /*
  3687. * As with width, only write the actual register if the
  3688. * link is currently down, otherwise takes effect on next
  3689. * link change. Since setting is being explicitly requested
  3690. * (via MAD or sysfs), clear autoneg failure status if speed
  3691. * autoneg is enabled.
  3692. */
  3693. ppd->link_speed_enabled = val;
  3694. val <<= IBA7322_IBC_SPEED_LSB;
  3695. maskr = IBA7322_IBC_SPEED_MASK | IBA7322_IBC_IBTA_1_2_MASK |
  3696. IBA7322_IBC_MAX_SPEED_MASK;
  3697. if (val & (val - 1)) {
  3698. /* Muliple speeds enabled */
  3699. val |= IBA7322_IBC_IBTA_1_2_MASK |
  3700. IBA7322_IBC_MAX_SPEED_MASK;
  3701. spin_lock_irqsave(&ppd->lflags_lock, flags);
  3702. ppd->lflags &= ~QIBL_IB_AUTONEG_FAILED;
  3703. spin_unlock_irqrestore(&ppd->lflags_lock, flags);
  3704. } else if (val & IBA7322_IBC_SPEED_QDR)
  3705. val |= IBA7322_IBC_IBTA_1_2_MASK;
  3706. /* IBTA 1.2 mode + min/max + speed bits are contiguous */
  3707. lsb = SYM_LSB(IBCCtrlB_0, IB_ENHANCED_MODE);
  3708. break;
  3709. case QIB_IB_CFG_RXPOL_ENB: /* set Auto-RX-polarity enable */
  3710. lsb = SYM_LSB(IBCCtrlB_0, IB_POLARITY_REV_SUPP);
  3711. maskr = SYM_RMASK(IBCCtrlB_0, IB_POLARITY_REV_SUPP);
  3712. break;
  3713. case QIB_IB_CFG_LREV_ENB: /* set Auto-Lane-reversal enable */
  3714. lsb = SYM_LSB(IBCCtrlB_0, IB_LANE_REV_SUPPORTED);
  3715. maskr = SYM_RMASK(IBCCtrlB_0, IB_LANE_REV_SUPPORTED);
  3716. break;
  3717. case QIB_IB_CFG_OVERRUN_THRESH: /* IB overrun threshold */
  3718. maskr = SYM_FIELD(ppd->cpspec->ibcctrl_a, IBCCtrlA_0,
  3719. OverrunThreshold);
  3720. if (maskr != val) {
  3721. ppd->cpspec->ibcctrl_a &=
  3722. ~SYM_MASK(IBCCtrlA_0, OverrunThreshold);
  3723. ppd->cpspec->ibcctrl_a |= (u64) val <<
  3724. SYM_LSB(IBCCtrlA_0, OverrunThreshold);
  3725. qib_write_kreg_port(ppd, krp_ibcctrl_a,
  3726. ppd->cpspec->ibcctrl_a);
  3727. qib_write_kreg(dd, kr_scratch, 0ULL);
  3728. }
  3729. goto bail;
  3730. case QIB_IB_CFG_PHYERR_THRESH: /* IB PHY error threshold */
  3731. maskr = SYM_FIELD(ppd->cpspec->ibcctrl_a, IBCCtrlA_0,
  3732. PhyerrThreshold);
  3733. if (maskr != val) {
  3734. ppd->cpspec->ibcctrl_a &=
  3735. ~SYM_MASK(IBCCtrlA_0, PhyerrThreshold);
  3736. ppd->cpspec->ibcctrl_a |= (u64) val <<
  3737. SYM_LSB(IBCCtrlA_0, PhyerrThreshold);
  3738. qib_write_kreg_port(ppd, krp_ibcctrl_a,
  3739. ppd->cpspec->ibcctrl_a);
  3740. qib_write_kreg(dd, kr_scratch, 0ULL);
  3741. }
  3742. goto bail;
  3743. case QIB_IB_CFG_PKEYS: /* update pkeys */
  3744. maskr = (u64) ppd->pkeys[0] | ((u64) ppd->pkeys[1] << 16) |
  3745. ((u64) ppd->pkeys[2] << 32) |
  3746. ((u64) ppd->pkeys[3] << 48);
  3747. qib_write_kreg_port(ppd, krp_partitionkey, maskr);
  3748. goto bail;
  3749. case QIB_IB_CFG_LINKDEFAULT: /* IB link default (sleep/poll) */
  3750. /* will only take effect when the link state changes */
  3751. if (val == IB_LINKINITCMD_POLL)
  3752. ppd->cpspec->ibcctrl_a &=
  3753. ~SYM_MASK(IBCCtrlA_0, LinkDownDefaultState);
  3754. else /* SLEEP */
  3755. ppd->cpspec->ibcctrl_a |=
  3756. SYM_MASK(IBCCtrlA_0, LinkDownDefaultState);
  3757. qib_write_kreg_port(ppd, krp_ibcctrl_a, ppd->cpspec->ibcctrl_a);
  3758. qib_write_kreg(dd, kr_scratch, 0ULL);
  3759. goto bail;
  3760. case QIB_IB_CFG_MTU: /* update the MTU in IBC */
  3761. /*
  3762. * Update our housekeeping variables, and set IBC max
  3763. * size, same as init code; max IBC is max we allow in
  3764. * buffer, less the qword pbc, plus 1 for ICRC, in dwords
  3765. * Set even if it's unchanged, print debug message only
  3766. * on changes.
  3767. */
  3768. val = (ppd->ibmaxlen >> 2) + 1;
  3769. ppd->cpspec->ibcctrl_a &= ~SYM_MASK(IBCCtrlA_0, MaxPktLen);
  3770. ppd->cpspec->ibcctrl_a |= (u64)val <<
  3771. SYM_LSB(IBCCtrlA_0, MaxPktLen);
  3772. qib_write_kreg_port(ppd, krp_ibcctrl_a,
  3773. ppd->cpspec->ibcctrl_a);
  3774. qib_write_kreg(dd, kr_scratch, 0ULL);
  3775. goto bail;
  3776. case QIB_IB_CFG_LSTATE: /* set the IB link state */
  3777. switch (val & 0xffff0000) {
  3778. case IB_LINKCMD_DOWN:
  3779. lcmd = QLOGIC_IB_IBCC_LINKCMD_DOWN;
  3780. ppd->cpspec->ibmalfusesnap = 1;
  3781. ppd->cpspec->ibmalfsnap = read_7322_creg32_port(ppd,
  3782. crp_errlink);
  3783. if (!ppd->cpspec->ibdeltainprog &&
  3784. qib_compat_ddr_negotiate) {
  3785. ppd->cpspec->ibdeltainprog = 1;
  3786. ppd->cpspec->ibsymsnap =
  3787. read_7322_creg32_port(ppd,
  3788. crp_ibsymbolerr);
  3789. ppd->cpspec->iblnkerrsnap =
  3790. read_7322_creg32_port(ppd,
  3791. crp_iblinkerrrecov);
  3792. }
  3793. break;
  3794. case IB_LINKCMD_ARMED:
  3795. lcmd = QLOGIC_IB_IBCC_LINKCMD_ARMED;
  3796. if (ppd->cpspec->ibmalfusesnap) {
  3797. ppd->cpspec->ibmalfusesnap = 0;
  3798. ppd->cpspec->ibmalfdelta +=
  3799. read_7322_creg32_port(ppd,
  3800. crp_errlink) -
  3801. ppd->cpspec->ibmalfsnap;
  3802. }
  3803. break;
  3804. case IB_LINKCMD_ACTIVE:
  3805. lcmd = QLOGIC_IB_IBCC_LINKCMD_ACTIVE;
  3806. break;
  3807. default:
  3808. ret = -EINVAL;
  3809. qib_dev_err(dd, "bad linkcmd req 0x%x\n", val >> 16);
  3810. goto bail;
  3811. }
  3812. switch (val & 0xffff) {
  3813. case IB_LINKINITCMD_NOP:
  3814. licmd = 0;
  3815. break;
  3816. case IB_LINKINITCMD_POLL:
  3817. licmd = QLOGIC_IB_IBCC_LINKINITCMD_POLL;
  3818. break;
  3819. case IB_LINKINITCMD_SLEEP:
  3820. licmd = QLOGIC_IB_IBCC_LINKINITCMD_SLEEP;
  3821. break;
  3822. case IB_LINKINITCMD_DISABLE:
  3823. licmd = QLOGIC_IB_IBCC_LINKINITCMD_DISABLE;
  3824. ppd->cpspec->chase_end = 0;
  3825. /*
  3826. * stop state chase counter and timer, if running.
  3827. * wait forpending timer, but don't clear .data (ppd)!
  3828. */
  3829. if (ppd->cpspec->chase_timer.expires) {
  3830. del_timer_sync(&ppd->cpspec->chase_timer);
  3831. ppd->cpspec->chase_timer.expires = 0;
  3832. }
  3833. break;
  3834. default:
  3835. ret = -EINVAL;
  3836. qib_dev_err(dd, "bad linkinitcmd req 0x%x\n",
  3837. val & 0xffff);
  3838. goto bail;
  3839. }
  3840. qib_set_ib_7322_lstate(ppd, lcmd, licmd);
  3841. goto bail;
  3842. case QIB_IB_CFG_OP_VLS:
  3843. if (ppd->vls_operational != val) {
  3844. ppd->vls_operational = val;
  3845. set_vls(ppd);
  3846. }
  3847. goto bail;
  3848. case QIB_IB_CFG_VL_HIGH_LIMIT:
  3849. qib_write_kreg_port(ppd, krp_highprio_limit, val);
  3850. goto bail;
  3851. case QIB_IB_CFG_HRTBT: /* set Heartbeat off/enable/auto */
  3852. if (val > 3) {
  3853. ret = -EINVAL;
  3854. goto bail;
  3855. }
  3856. lsb = IBA7322_IBC_HRTBT_LSB;
  3857. maskr = IBA7322_IBC_HRTBT_RMASK; /* OR of AUTO and ENB */
  3858. break;
  3859. case QIB_IB_CFG_PORT:
  3860. /* val is the port number of the switch we are connected to. */
  3861. if (ppd->dd->cspec->r1) {
  3862. cancel_delayed_work(&ppd->cpspec->ipg_work);
  3863. ppd->cpspec->ipg_tries = 0;
  3864. }
  3865. goto bail;
  3866. default:
  3867. ret = -EINVAL;
  3868. goto bail;
  3869. }
  3870. ppd->cpspec->ibcctrl_b &= ~(maskr << lsb);
  3871. ppd->cpspec->ibcctrl_b |= (((u64) val & maskr) << lsb);
  3872. qib_write_kreg_port(ppd, krp_ibcctrl_b, ppd->cpspec->ibcctrl_b);
  3873. qib_write_kreg(dd, kr_scratch, 0);
  3874. bail:
  3875. return ret;
  3876. }
  3877. static int qib_7322_set_loopback(struct qib_pportdata *ppd, const char *what)
  3878. {
  3879. int ret = 0;
  3880. u64 val, ctrlb;
  3881. /* only IBC loopback, may add serdes and xgxs loopbacks later */
  3882. if (!strncmp(what, "ibc", 3)) {
  3883. ppd->cpspec->ibcctrl_a |= SYM_MASK(IBCCtrlA_0,
  3884. Loopback);
  3885. val = 0; /* disable heart beat, so link will come up */
  3886. qib_devinfo(ppd->dd->pcidev, "Enabling IB%u:%u IBC loopback\n",
  3887. ppd->dd->unit, ppd->port);
  3888. } else if (!strncmp(what, "off", 3)) {
  3889. ppd->cpspec->ibcctrl_a &= ~SYM_MASK(IBCCtrlA_0,
  3890. Loopback);
  3891. /* enable heart beat again */
  3892. val = IBA7322_IBC_HRTBT_RMASK << IBA7322_IBC_HRTBT_LSB;
  3893. qib_devinfo(ppd->dd->pcidev,
  3894. "Disabling IB%u:%u IBC loopback (normal)\n",
  3895. ppd->dd->unit, ppd->port);
  3896. } else
  3897. ret = -EINVAL;
  3898. if (!ret) {
  3899. qib_write_kreg_port(ppd, krp_ibcctrl_a,
  3900. ppd->cpspec->ibcctrl_a);
  3901. ctrlb = ppd->cpspec->ibcctrl_b & ~(IBA7322_IBC_HRTBT_MASK
  3902. << IBA7322_IBC_HRTBT_LSB);
  3903. ppd->cpspec->ibcctrl_b = ctrlb | val;
  3904. qib_write_kreg_port(ppd, krp_ibcctrl_b,
  3905. ppd->cpspec->ibcctrl_b);
  3906. qib_write_kreg(ppd->dd, kr_scratch, 0);
  3907. }
  3908. return ret;
  3909. }
  3910. static void get_vl_weights(struct qib_pportdata *ppd, unsigned regno,
  3911. struct ib_vl_weight_elem *vl)
  3912. {
  3913. unsigned i;
  3914. for (i = 0; i < 16; i++, regno++, vl++) {
  3915. u32 val = qib_read_kreg_port(ppd, regno);
  3916. vl->vl = (val >> SYM_LSB(LowPriority0_0, VirtualLane)) &
  3917. SYM_RMASK(LowPriority0_0, VirtualLane);
  3918. vl->weight = (val >> SYM_LSB(LowPriority0_0, Weight)) &
  3919. SYM_RMASK(LowPriority0_0, Weight);
  3920. }
  3921. }
  3922. static void set_vl_weights(struct qib_pportdata *ppd, unsigned regno,
  3923. struct ib_vl_weight_elem *vl)
  3924. {
  3925. unsigned i;
  3926. for (i = 0; i < 16; i++, regno++, vl++) {
  3927. u64 val;
  3928. val = ((vl->vl & SYM_RMASK(LowPriority0_0, VirtualLane)) <<
  3929. SYM_LSB(LowPriority0_0, VirtualLane)) |
  3930. ((vl->weight & SYM_RMASK(LowPriority0_0, Weight)) <<
  3931. SYM_LSB(LowPriority0_0, Weight));
  3932. qib_write_kreg_port(ppd, regno, val);
  3933. }
  3934. if (!(ppd->p_sendctrl & SYM_MASK(SendCtrl_0, IBVLArbiterEn))) {
  3935. struct qib_devdata *dd = ppd->dd;
  3936. unsigned long flags;
  3937. spin_lock_irqsave(&dd->sendctrl_lock, flags);
  3938. ppd->p_sendctrl |= SYM_MASK(SendCtrl_0, IBVLArbiterEn);
  3939. qib_write_kreg_port(ppd, krp_sendctrl, ppd->p_sendctrl);
  3940. qib_write_kreg(dd, kr_scratch, 0);
  3941. spin_unlock_irqrestore(&dd->sendctrl_lock, flags);
  3942. }
  3943. }
  3944. static int qib_7322_get_ib_table(struct qib_pportdata *ppd, int which, void *t)
  3945. {
  3946. switch (which) {
  3947. case QIB_IB_TBL_VL_HIGH_ARB:
  3948. get_vl_weights(ppd, krp_highprio_0, t);
  3949. break;
  3950. case QIB_IB_TBL_VL_LOW_ARB:
  3951. get_vl_weights(ppd, krp_lowprio_0, t);
  3952. break;
  3953. default:
  3954. return -EINVAL;
  3955. }
  3956. return 0;
  3957. }
  3958. static int qib_7322_set_ib_table(struct qib_pportdata *ppd, int which, void *t)
  3959. {
  3960. switch (which) {
  3961. case QIB_IB_TBL_VL_HIGH_ARB:
  3962. set_vl_weights(ppd, krp_highprio_0, t);
  3963. break;
  3964. case QIB_IB_TBL_VL_LOW_ARB:
  3965. set_vl_weights(ppd, krp_lowprio_0, t);
  3966. break;
  3967. default:
  3968. return -EINVAL;
  3969. }
  3970. return 0;
  3971. }
  3972. static void qib_update_7322_usrhead(struct qib_ctxtdata *rcd, u64 hd,
  3973. u32 updegr, u32 egrhd, u32 npkts)
  3974. {
  3975. /*
  3976. * Need to write timeout register before updating rcvhdrhead to ensure
  3977. * that the timer is enabled on reception of a packet.
  3978. */
  3979. if (hd >> IBA7322_HDRHEAD_PKTINT_SHIFT)
  3980. adjust_rcv_timeout(rcd, npkts);
  3981. if (updegr)
  3982. qib_write_ureg(rcd->dd, ur_rcvegrindexhead, egrhd, rcd->ctxt);
  3983. mmiowb();
  3984. qib_write_ureg(rcd->dd, ur_rcvhdrhead, hd, rcd->ctxt);
  3985. qib_write_ureg(rcd->dd, ur_rcvhdrhead, hd, rcd->ctxt);
  3986. mmiowb();
  3987. }
  3988. static u32 qib_7322_hdrqempty(struct qib_ctxtdata *rcd)
  3989. {
  3990. u32 head, tail;
  3991. head = qib_read_ureg32(rcd->dd, ur_rcvhdrhead, rcd->ctxt);
  3992. if (rcd->rcvhdrtail_kvaddr)
  3993. tail = qib_get_rcvhdrtail(rcd);
  3994. else
  3995. tail = qib_read_ureg32(rcd->dd, ur_rcvhdrtail, rcd->ctxt);
  3996. return head == tail;
  3997. }
  3998. #define RCVCTRL_COMMON_MODS (QIB_RCVCTRL_CTXT_ENB | \
  3999. QIB_RCVCTRL_CTXT_DIS | \
  4000. QIB_RCVCTRL_TIDFLOW_ENB | \
  4001. QIB_RCVCTRL_TIDFLOW_DIS | \
  4002. QIB_RCVCTRL_TAILUPD_ENB | \
  4003. QIB_RCVCTRL_TAILUPD_DIS | \
  4004. QIB_RCVCTRL_INTRAVAIL_ENB | \
  4005. QIB_RCVCTRL_INTRAVAIL_DIS | \
  4006. QIB_RCVCTRL_BP_ENB | \
  4007. QIB_RCVCTRL_BP_DIS)
  4008. #define RCVCTRL_PORT_MODS (QIB_RCVCTRL_CTXT_ENB | \
  4009. QIB_RCVCTRL_CTXT_DIS | \
  4010. QIB_RCVCTRL_PKEY_DIS | \
  4011. QIB_RCVCTRL_PKEY_ENB)
  4012. /*
  4013. * Modify the RCVCTRL register in chip-specific way. This
  4014. * is a function because bit positions and (future) register
  4015. * location is chip-specifc, but the needed operations are
  4016. * generic. <op> is a bit-mask because we often want to
  4017. * do multiple modifications.
  4018. */
  4019. static void rcvctrl_7322_mod(struct qib_pportdata *ppd, unsigned int op,
  4020. int ctxt)
  4021. {
  4022. struct qib_devdata *dd = ppd->dd;
  4023. struct qib_ctxtdata *rcd;
  4024. u64 mask, val;
  4025. unsigned long flags;
  4026. spin_lock_irqsave(&dd->cspec->rcvmod_lock, flags);
  4027. if (op & QIB_RCVCTRL_TIDFLOW_ENB)
  4028. dd->rcvctrl |= SYM_MASK(RcvCtrl, TidFlowEnable);
  4029. if (op & QIB_RCVCTRL_TIDFLOW_DIS)
  4030. dd->rcvctrl &= ~SYM_MASK(RcvCtrl, TidFlowEnable);
  4031. if (op & QIB_RCVCTRL_TAILUPD_ENB)
  4032. dd->rcvctrl |= SYM_MASK(RcvCtrl, TailUpd);
  4033. if (op & QIB_RCVCTRL_TAILUPD_DIS)
  4034. dd->rcvctrl &= ~SYM_MASK(RcvCtrl, TailUpd);
  4035. if (op & QIB_RCVCTRL_PKEY_ENB)
  4036. ppd->p_rcvctrl &= ~SYM_MASK(RcvCtrl_0, RcvPartitionKeyDisable);
  4037. if (op & QIB_RCVCTRL_PKEY_DIS)
  4038. ppd->p_rcvctrl |= SYM_MASK(RcvCtrl_0, RcvPartitionKeyDisable);
  4039. if (ctxt < 0) {
  4040. mask = (1ULL << dd->ctxtcnt) - 1;
  4041. rcd = NULL;
  4042. } else {
  4043. mask = (1ULL << ctxt);
  4044. rcd = dd->rcd[ctxt];
  4045. }
  4046. if ((op & QIB_RCVCTRL_CTXT_ENB) && rcd) {
  4047. ppd->p_rcvctrl |=
  4048. (mask << SYM_LSB(RcvCtrl_0, ContextEnableKernel));
  4049. if (!(dd->flags & QIB_NODMA_RTAIL)) {
  4050. op |= QIB_RCVCTRL_TAILUPD_ENB; /* need reg write */
  4051. dd->rcvctrl |= SYM_MASK(RcvCtrl, TailUpd);
  4052. }
  4053. /* Write these registers before the context is enabled. */
  4054. qib_write_kreg_ctxt(dd, krc_rcvhdrtailaddr, ctxt,
  4055. rcd->rcvhdrqtailaddr_phys);
  4056. qib_write_kreg_ctxt(dd, krc_rcvhdraddr, ctxt,
  4057. rcd->rcvhdrq_phys);
  4058. rcd->seq_cnt = 1;
  4059. }
  4060. if (op & QIB_RCVCTRL_CTXT_DIS)
  4061. ppd->p_rcvctrl &=
  4062. ~(mask << SYM_LSB(RcvCtrl_0, ContextEnableKernel));
  4063. if (op & QIB_RCVCTRL_BP_ENB)
  4064. dd->rcvctrl |= mask << SYM_LSB(RcvCtrl, dontDropRHQFull);
  4065. if (op & QIB_RCVCTRL_BP_DIS)
  4066. dd->rcvctrl &= ~(mask << SYM_LSB(RcvCtrl, dontDropRHQFull));
  4067. if (op & QIB_RCVCTRL_INTRAVAIL_ENB)
  4068. dd->rcvctrl |= (mask << SYM_LSB(RcvCtrl, IntrAvail));
  4069. if (op & QIB_RCVCTRL_INTRAVAIL_DIS)
  4070. dd->rcvctrl &= ~(mask << SYM_LSB(RcvCtrl, IntrAvail));
  4071. /*
  4072. * Decide which registers to write depending on the ops enabled.
  4073. * Special case is "flush" (no bits set at all)
  4074. * which needs to write both.
  4075. */
  4076. if (op == 0 || (op & RCVCTRL_COMMON_MODS))
  4077. qib_write_kreg(dd, kr_rcvctrl, dd->rcvctrl);
  4078. if (op == 0 || (op & RCVCTRL_PORT_MODS))
  4079. qib_write_kreg_port(ppd, krp_rcvctrl, ppd->p_rcvctrl);
  4080. if ((op & QIB_RCVCTRL_CTXT_ENB) && dd->rcd[ctxt]) {
  4081. /*
  4082. * Init the context registers also; if we were
  4083. * disabled, tail and head should both be zero
  4084. * already from the enable, but since we don't
  4085. * know, we have to do it explicitly.
  4086. */
  4087. val = qib_read_ureg32(dd, ur_rcvegrindextail, ctxt);
  4088. qib_write_ureg(dd, ur_rcvegrindexhead, val, ctxt);
  4089. /* be sure enabling write seen; hd/tl should be 0 */
  4090. (void) qib_read_kreg32(dd, kr_scratch);
  4091. val = qib_read_ureg32(dd, ur_rcvhdrtail, ctxt);
  4092. dd->rcd[ctxt]->head = val;
  4093. /* If kctxt, interrupt on next receive. */
  4094. if (ctxt < dd->first_user_ctxt)
  4095. val |= dd->rhdrhead_intr_off;
  4096. qib_write_ureg(dd, ur_rcvhdrhead, val, ctxt);
  4097. } else if ((op & QIB_RCVCTRL_INTRAVAIL_ENB) &&
  4098. dd->rcd[ctxt] && dd->rhdrhead_intr_off) {
  4099. /* arm rcv interrupt */
  4100. val = dd->rcd[ctxt]->head | dd->rhdrhead_intr_off;
  4101. qib_write_ureg(dd, ur_rcvhdrhead, val, ctxt);
  4102. }
  4103. if (op & QIB_RCVCTRL_CTXT_DIS) {
  4104. unsigned f;
  4105. /* Now that the context is disabled, clear these registers. */
  4106. if (ctxt >= 0) {
  4107. qib_write_kreg_ctxt(dd, krc_rcvhdrtailaddr, ctxt, 0);
  4108. qib_write_kreg_ctxt(dd, krc_rcvhdraddr, ctxt, 0);
  4109. for (f = 0; f < NUM_TIDFLOWS_CTXT; f++)
  4110. qib_write_ureg(dd, ur_rcvflowtable + f,
  4111. TIDFLOW_ERRBITS, ctxt);
  4112. } else {
  4113. unsigned i;
  4114. for (i = 0; i < dd->cfgctxts; i++) {
  4115. qib_write_kreg_ctxt(dd, krc_rcvhdrtailaddr,
  4116. i, 0);
  4117. qib_write_kreg_ctxt(dd, krc_rcvhdraddr, i, 0);
  4118. for (f = 0; f < NUM_TIDFLOWS_CTXT; f++)
  4119. qib_write_ureg(dd, ur_rcvflowtable + f,
  4120. TIDFLOW_ERRBITS, i);
  4121. }
  4122. }
  4123. }
  4124. spin_unlock_irqrestore(&dd->cspec->rcvmod_lock, flags);
  4125. }
  4126. /*
  4127. * Modify the SENDCTRL register in chip-specific way. This
  4128. * is a function where there are multiple such registers with
  4129. * slightly different layouts.
  4130. * The chip doesn't allow back-to-back sendctrl writes, so write
  4131. * the scratch register after writing sendctrl.
  4132. *
  4133. * Which register is written depends on the operation.
  4134. * Most operate on the common register, while
  4135. * SEND_ENB and SEND_DIS operate on the per-port ones.
  4136. * SEND_ENB is included in common because it can change SPCL_TRIG
  4137. */
  4138. #define SENDCTRL_COMMON_MODS (\
  4139. QIB_SENDCTRL_CLEAR | \
  4140. QIB_SENDCTRL_AVAIL_DIS | \
  4141. QIB_SENDCTRL_AVAIL_ENB | \
  4142. QIB_SENDCTRL_AVAIL_BLIP | \
  4143. QIB_SENDCTRL_DISARM | \
  4144. QIB_SENDCTRL_DISARM_ALL | \
  4145. QIB_SENDCTRL_SEND_ENB)
  4146. #define SENDCTRL_PORT_MODS (\
  4147. QIB_SENDCTRL_CLEAR | \
  4148. QIB_SENDCTRL_SEND_ENB | \
  4149. QIB_SENDCTRL_SEND_DIS | \
  4150. QIB_SENDCTRL_FLUSH)
  4151. static void sendctrl_7322_mod(struct qib_pportdata *ppd, u32 op)
  4152. {
  4153. struct qib_devdata *dd = ppd->dd;
  4154. u64 tmp_dd_sendctrl;
  4155. unsigned long flags;
  4156. spin_lock_irqsave(&dd->sendctrl_lock, flags);
  4157. /* First the dd ones that are "sticky", saved in shadow */
  4158. if (op & QIB_SENDCTRL_CLEAR)
  4159. dd->sendctrl = 0;
  4160. if (op & QIB_SENDCTRL_AVAIL_DIS)
  4161. dd->sendctrl &= ~SYM_MASK(SendCtrl, SendBufAvailUpd);
  4162. else if (op & QIB_SENDCTRL_AVAIL_ENB) {
  4163. dd->sendctrl |= SYM_MASK(SendCtrl, SendBufAvailUpd);
  4164. if (dd->flags & QIB_USE_SPCL_TRIG)
  4165. dd->sendctrl |= SYM_MASK(SendCtrl, SpecialTriggerEn);
  4166. }
  4167. /* Then the ppd ones that are "sticky", saved in shadow */
  4168. if (op & QIB_SENDCTRL_SEND_DIS)
  4169. ppd->p_sendctrl &= ~SYM_MASK(SendCtrl_0, SendEnable);
  4170. else if (op & QIB_SENDCTRL_SEND_ENB)
  4171. ppd->p_sendctrl |= SYM_MASK(SendCtrl_0, SendEnable);
  4172. if (op & QIB_SENDCTRL_DISARM_ALL) {
  4173. u32 i, last;
  4174. tmp_dd_sendctrl = dd->sendctrl;
  4175. last = dd->piobcnt2k + dd->piobcnt4k + NUM_VL15_BUFS;
  4176. /*
  4177. * Disarm any buffers that are not yet launched,
  4178. * disabling updates until done.
  4179. */
  4180. tmp_dd_sendctrl &= ~SYM_MASK(SendCtrl, SendBufAvailUpd);
  4181. for (i = 0; i < last; i++) {
  4182. qib_write_kreg(dd, kr_sendctrl,
  4183. tmp_dd_sendctrl |
  4184. SYM_MASK(SendCtrl, Disarm) | i);
  4185. qib_write_kreg(dd, kr_scratch, 0);
  4186. }
  4187. }
  4188. if (op & QIB_SENDCTRL_FLUSH) {
  4189. u64 tmp_ppd_sendctrl = ppd->p_sendctrl;
  4190. /*
  4191. * Now drain all the fifos. The Abort bit should never be
  4192. * needed, so for now, at least, we don't use it.
  4193. */
  4194. tmp_ppd_sendctrl |=
  4195. SYM_MASK(SendCtrl_0, TxeDrainRmFifo) |
  4196. SYM_MASK(SendCtrl_0, TxeDrainLaFifo) |
  4197. SYM_MASK(SendCtrl_0, TxeBypassIbc);
  4198. qib_write_kreg_port(ppd, krp_sendctrl, tmp_ppd_sendctrl);
  4199. qib_write_kreg(dd, kr_scratch, 0);
  4200. }
  4201. tmp_dd_sendctrl = dd->sendctrl;
  4202. if (op & QIB_SENDCTRL_DISARM)
  4203. tmp_dd_sendctrl |= SYM_MASK(SendCtrl, Disarm) |
  4204. ((op & QIB_7322_SendCtrl_DisarmSendBuf_RMASK) <<
  4205. SYM_LSB(SendCtrl, DisarmSendBuf));
  4206. if ((op & QIB_SENDCTRL_AVAIL_BLIP) &&
  4207. (dd->sendctrl & SYM_MASK(SendCtrl, SendBufAvailUpd)))
  4208. tmp_dd_sendctrl &= ~SYM_MASK(SendCtrl, SendBufAvailUpd);
  4209. if (op == 0 || (op & SENDCTRL_COMMON_MODS)) {
  4210. qib_write_kreg(dd, kr_sendctrl, tmp_dd_sendctrl);
  4211. qib_write_kreg(dd, kr_scratch, 0);
  4212. }
  4213. if (op == 0 || (op & SENDCTRL_PORT_MODS)) {
  4214. qib_write_kreg_port(ppd, krp_sendctrl, ppd->p_sendctrl);
  4215. qib_write_kreg(dd, kr_scratch, 0);
  4216. }
  4217. if (op & QIB_SENDCTRL_AVAIL_BLIP) {
  4218. qib_write_kreg(dd, kr_sendctrl, dd->sendctrl);
  4219. qib_write_kreg(dd, kr_scratch, 0);
  4220. }
  4221. spin_unlock_irqrestore(&dd->sendctrl_lock, flags);
  4222. if (op & QIB_SENDCTRL_FLUSH) {
  4223. u32 v;
  4224. /*
  4225. * ensure writes have hit chip, then do a few
  4226. * more reads, to allow DMA of pioavail registers
  4227. * to occur, so in-memory copy is in sync with
  4228. * the chip. Not always safe to sleep.
  4229. */
  4230. v = qib_read_kreg32(dd, kr_scratch);
  4231. qib_write_kreg(dd, kr_scratch, v);
  4232. v = qib_read_kreg32(dd, kr_scratch);
  4233. qib_write_kreg(dd, kr_scratch, v);
  4234. qib_read_kreg32(dd, kr_scratch);
  4235. }
  4236. }
  4237. #define _PORT_VIRT_FLAG 0x8000U /* "virtual", need adjustments */
  4238. #define _PORT_64BIT_FLAG 0x10000U /* not "virtual", but 64bit */
  4239. #define _PORT_CNTR_IDXMASK 0x7fffU /* mask off flags above */
  4240. /**
  4241. * qib_portcntr_7322 - read a per-port chip counter
  4242. * @ppd: the qlogic_ib pport
  4243. * @creg: the counter to read (not a chip offset)
  4244. */
  4245. static u64 qib_portcntr_7322(struct qib_pportdata *ppd, u32 reg)
  4246. {
  4247. struct qib_devdata *dd = ppd->dd;
  4248. u64 ret = 0ULL;
  4249. u16 creg;
  4250. /* 0xffff for unimplemented or synthesized counters */
  4251. static const u32 xlator[] = {
  4252. [QIBPORTCNTR_PKTSEND] = crp_pktsend | _PORT_64BIT_FLAG,
  4253. [QIBPORTCNTR_WORDSEND] = crp_wordsend | _PORT_64BIT_FLAG,
  4254. [QIBPORTCNTR_PSXMITDATA] = crp_psxmitdatacount,
  4255. [QIBPORTCNTR_PSXMITPKTS] = crp_psxmitpktscount,
  4256. [QIBPORTCNTR_PSXMITWAIT] = crp_psxmitwaitcount,
  4257. [QIBPORTCNTR_SENDSTALL] = crp_sendstall,
  4258. [QIBPORTCNTR_PKTRCV] = crp_pktrcv | _PORT_64BIT_FLAG,
  4259. [QIBPORTCNTR_PSRCVDATA] = crp_psrcvdatacount,
  4260. [QIBPORTCNTR_PSRCVPKTS] = crp_psrcvpktscount,
  4261. [QIBPORTCNTR_RCVEBP] = crp_rcvebp,
  4262. [QIBPORTCNTR_RCVOVFL] = crp_rcvovfl,
  4263. [QIBPORTCNTR_WORDRCV] = crp_wordrcv | _PORT_64BIT_FLAG,
  4264. [QIBPORTCNTR_RXDROPPKT] = 0xffff, /* not needed for 7322 */
  4265. [QIBPORTCNTR_RXLOCALPHYERR] = crp_rxotherlocalphyerr,
  4266. [QIBPORTCNTR_RXVLERR] = crp_rxvlerr,
  4267. [QIBPORTCNTR_ERRICRC] = crp_erricrc,
  4268. [QIBPORTCNTR_ERRVCRC] = crp_errvcrc,
  4269. [QIBPORTCNTR_ERRLPCRC] = crp_errlpcrc,
  4270. [QIBPORTCNTR_BADFORMAT] = crp_badformat,
  4271. [QIBPORTCNTR_ERR_RLEN] = crp_err_rlen,
  4272. [QIBPORTCNTR_IBSYMBOLERR] = crp_ibsymbolerr,
  4273. [QIBPORTCNTR_INVALIDRLEN] = crp_invalidrlen,
  4274. [QIBPORTCNTR_UNSUPVL] = crp_txunsupvl,
  4275. [QIBPORTCNTR_EXCESSBUFOVFL] = crp_excessbufferovfl,
  4276. [QIBPORTCNTR_ERRLINK] = crp_errlink,
  4277. [QIBPORTCNTR_IBLINKDOWN] = crp_iblinkdown,
  4278. [QIBPORTCNTR_IBLINKERRRECOV] = crp_iblinkerrrecov,
  4279. [QIBPORTCNTR_LLI] = crp_locallinkintegrityerr,
  4280. [QIBPORTCNTR_VL15PKTDROP] = crp_vl15droppedpkt,
  4281. [QIBPORTCNTR_ERRPKEY] = crp_errpkey,
  4282. /*
  4283. * the next 3 aren't really counters, but were implemented
  4284. * as counters in older chips, so still get accessed as
  4285. * though they were counters from this code.
  4286. */
  4287. [QIBPORTCNTR_PSINTERVAL] = krp_psinterval,
  4288. [QIBPORTCNTR_PSSTART] = krp_psstart,
  4289. [QIBPORTCNTR_PSSTAT] = krp_psstat,
  4290. /* pseudo-counter, summed for all ports */
  4291. [QIBPORTCNTR_KHDROVFL] = 0xffff,
  4292. };
  4293. if (reg >= ARRAY_SIZE(xlator)) {
  4294. qib_devinfo(ppd->dd->pcidev,
  4295. "Unimplemented portcounter %u\n", reg);
  4296. goto done;
  4297. }
  4298. creg = xlator[reg] & _PORT_CNTR_IDXMASK;
  4299. /* handle non-counters and special cases first */
  4300. if (reg == QIBPORTCNTR_KHDROVFL) {
  4301. int i;
  4302. /* sum over all kernel contexts (skip if mini_init) */
  4303. for (i = 0; dd->rcd && i < dd->first_user_ctxt; i++) {
  4304. struct qib_ctxtdata *rcd = dd->rcd[i];
  4305. if (!rcd || rcd->ppd != ppd)
  4306. continue;
  4307. ret += read_7322_creg32(dd, cr_base_egrovfl + i);
  4308. }
  4309. goto done;
  4310. } else if (reg == QIBPORTCNTR_RXDROPPKT) {
  4311. /*
  4312. * Used as part of the synthesis of port_rcv_errors
  4313. * in the verbs code for IBTA counters. Not needed for 7322,
  4314. * because all the errors are already counted by other cntrs.
  4315. */
  4316. goto done;
  4317. } else if (reg == QIBPORTCNTR_PSINTERVAL ||
  4318. reg == QIBPORTCNTR_PSSTART || reg == QIBPORTCNTR_PSSTAT) {
  4319. /* were counters in older chips, now per-port kernel regs */
  4320. ret = qib_read_kreg_port(ppd, creg);
  4321. goto done;
  4322. }
  4323. /*
  4324. * Only fast increment counters are 64 bits; use 32 bit reads to
  4325. * avoid two independent reads when on Opteron.
  4326. */
  4327. if (xlator[reg] & _PORT_64BIT_FLAG)
  4328. ret = read_7322_creg_port(ppd, creg);
  4329. else
  4330. ret = read_7322_creg32_port(ppd, creg);
  4331. if (creg == crp_ibsymbolerr) {
  4332. if (ppd->cpspec->ibdeltainprog)
  4333. ret -= ret - ppd->cpspec->ibsymsnap;
  4334. ret -= ppd->cpspec->ibsymdelta;
  4335. } else if (creg == crp_iblinkerrrecov) {
  4336. if (ppd->cpspec->ibdeltainprog)
  4337. ret -= ret - ppd->cpspec->iblnkerrsnap;
  4338. ret -= ppd->cpspec->iblnkerrdelta;
  4339. } else if (creg == crp_errlink)
  4340. ret -= ppd->cpspec->ibmalfdelta;
  4341. else if (creg == crp_iblinkdown)
  4342. ret += ppd->cpspec->iblnkdowndelta;
  4343. done:
  4344. return ret;
  4345. }
  4346. /*
  4347. * Device counter names (not port-specific), one line per stat,
  4348. * single string. Used by utilities like ipathstats to print the stats
  4349. * in a way which works for different versions of drivers, without changing
  4350. * the utility. Names need to be 12 chars or less (w/o newline), for proper
  4351. * display by utility.
  4352. * Non-error counters are first.
  4353. * Start of "error" conters is indicated by a leading "E " on the first
  4354. * "error" counter, and doesn't count in label length.
  4355. * The EgrOvfl list needs to be last so we truncate them at the configured
  4356. * context count for the device.
  4357. * cntr7322indices contains the corresponding register indices.
  4358. */
  4359. static const char cntr7322names[] =
  4360. "Interrupts\n"
  4361. "HostBusStall\n"
  4362. "E RxTIDFull\n"
  4363. "RxTIDInvalid\n"
  4364. "RxTIDFloDrop\n" /* 7322 only */
  4365. "Ctxt0EgrOvfl\n"
  4366. "Ctxt1EgrOvfl\n"
  4367. "Ctxt2EgrOvfl\n"
  4368. "Ctxt3EgrOvfl\n"
  4369. "Ctxt4EgrOvfl\n"
  4370. "Ctxt5EgrOvfl\n"
  4371. "Ctxt6EgrOvfl\n"
  4372. "Ctxt7EgrOvfl\n"
  4373. "Ctxt8EgrOvfl\n"
  4374. "Ctxt9EgrOvfl\n"
  4375. "Ctx10EgrOvfl\n"
  4376. "Ctx11EgrOvfl\n"
  4377. "Ctx12EgrOvfl\n"
  4378. "Ctx13EgrOvfl\n"
  4379. "Ctx14EgrOvfl\n"
  4380. "Ctx15EgrOvfl\n"
  4381. "Ctx16EgrOvfl\n"
  4382. "Ctx17EgrOvfl\n"
  4383. ;
  4384. static const u32 cntr7322indices[] = {
  4385. cr_lbint | _PORT_64BIT_FLAG,
  4386. cr_lbstall | _PORT_64BIT_FLAG,
  4387. cr_tidfull,
  4388. cr_tidinvalid,
  4389. cr_rxtidflowdrop,
  4390. cr_base_egrovfl + 0,
  4391. cr_base_egrovfl + 1,
  4392. cr_base_egrovfl + 2,
  4393. cr_base_egrovfl + 3,
  4394. cr_base_egrovfl + 4,
  4395. cr_base_egrovfl + 5,
  4396. cr_base_egrovfl + 6,
  4397. cr_base_egrovfl + 7,
  4398. cr_base_egrovfl + 8,
  4399. cr_base_egrovfl + 9,
  4400. cr_base_egrovfl + 10,
  4401. cr_base_egrovfl + 11,
  4402. cr_base_egrovfl + 12,
  4403. cr_base_egrovfl + 13,
  4404. cr_base_egrovfl + 14,
  4405. cr_base_egrovfl + 15,
  4406. cr_base_egrovfl + 16,
  4407. cr_base_egrovfl + 17,
  4408. };
  4409. /*
  4410. * same as cntr7322names and cntr7322indices, but for port-specific counters.
  4411. * portcntr7322indices is somewhat complicated by some registers needing
  4412. * adjustments of various kinds, and those are ORed with _PORT_VIRT_FLAG
  4413. */
  4414. static const char portcntr7322names[] =
  4415. "TxPkt\n"
  4416. "TxFlowPkt\n"
  4417. "TxWords\n"
  4418. "RxPkt\n"
  4419. "RxFlowPkt\n"
  4420. "RxWords\n"
  4421. "TxFlowStall\n"
  4422. "TxDmaDesc\n" /* 7220 and 7322-only */
  4423. "E RxDlidFltr\n" /* 7220 and 7322-only */
  4424. "IBStatusChng\n"
  4425. "IBLinkDown\n"
  4426. "IBLnkRecov\n"
  4427. "IBRxLinkErr\n"
  4428. "IBSymbolErr\n"
  4429. "RxLLIErr\n"
  4430. "RxBadFormat\n"
  4431. "RxBadLen\n"
  4432. "RxBufOvrfl\n"
  4433. "RxEBP\n"
  4434. "RxFlowCtlErr\n"
  4435. "RxICRCerr\n"
  4436. "RxLPCRCerr\n"
  4437. "RxVCRCerr\n"
  4438. "RxInvalLen\n"
  4439. "RxInvalPKey\n"
  4440. "RxPktDropped\n"
  4441. "TxBadLength\n"
  4442. "TxDropped\n"
  4443. "TxInvalLen\n"
  4444. "TxUnderrun\n"
  4445. "TxUnsupVL\n"
  4446. "RxLclPhyErr\n" /* 7220 and 7322-only from here down */
  4447. "RxVL15Drop\n"
  4448. "RxVlErr\n"
  4449. "XcessBufOvfl\n"
  4450. "RxQPBadCtxt\n" /* 7322-only from here down */
  4451. "TXBadHeader\n"
  4452. ;
  4453. static const u32 portcntr7322indices[] = {
  4454. QIBPORTCNTR_PKTSEND | _PORT_VIRT_FLAG,
  4455. crp_pktsendflow,
  4456. QIBPORTCNTR_WORDSEND | _PORT_VIRT_FLAG,
  4457. QIBPORTCNTR_PKTRCV | _PORT_VIRT_FLAG,
  4458. crp_pktrcvflowctrl,
  4459. QIBPORTCNTR_WORDRCV | _PORT_VIRT_FLAG,
  4460. QIBPORTCNTR_SENDSTALL | _PORT_VIRT_FLAG,
  4461. crp_txsdmadesc | _PORT_64BIT_FLAG,
  4462. crp_rxdlidfltr,
  4463. crp_ibstatuschange,
  4464. QIBPORTCNTR_IBLINKDOWN | _PORT_VIRT_FLAG,
  4465. QIBPORTCNTR_IBLINKERRRECOV | _PORT_VIRT_FLAG,
  4466. QIBPORTCNTR_ERRLINK | _PORT_VIRT_FLAG,
  4467. QIBPORTCNTR_IBSYMBOLERR | _PORT_VIRT_FLAG,
  4468. QIBPORTCNTR_LLI | _PORT_VIRT_FLAG,
  4469. QIBPORTCNTR_BADFORMAT | _PORT_VIRT_FLAG,
  4470. QIBPORTCNTR_ERR_RLEN | _PORT_VIRT_FLAG,
  4471. QIBPORTCNTR_RCVOVFL | _PORT_VIRT_FLAG,
  4472. QIBPORTCNTR_RCVEBP | _PORT_VIRT_FLAG,
  4473. crp_rcvflowctrlviol,
  4474. QIBPORTCNTR_ERRICRC | _PORT_VIRT_FLAG,
  4475. QIBPORTCNTR_ERRLPCRC | _PORT_VIRT_FLAG,
  4476. QIBPORTCNTR_ERRVCRC | _PORT_VIRT_FLAG,
  4477. QIBPORTCNTR_INVALIDRLEN | _PORT_VIRT_FLAG,
  4478. QIBPORTCNTR_ERRPKEY | _PORT_VIRT_FLAG,
  4479. QIBPORTCNTR_RXDROPPKT | _PORT_VIRT_FLAG,
  4480. crp_txminmaxlenerr,
  4481. crp_txdroppedpkt,
  4482. crp_txlenerr,
  4483. crp_txunderrun,
  4484. crp_txunsupvl,
  4485. QIBPORTCNTR_RXLOCALPHYERR | _PORT_VIRT_FLAG,
  4486. QIBPORTCNTR_VL15PKTDROP | _PORT_VIRT_FLAG,
  4487. QIBPORTCNTR_RXVLERR | _PORT_VIRT_FLAG,
  4488. QIBPORTCNTR_EXCESSBUFOVFL | _PORT_VIRT_FLAG,
  4489. crp_rxqpinvalidctxt,
  4490. crp_txhdrerr,
  4491. };
  4492. /* do all the setup to make the counter reads efficient later */
  4493. static void init_7322_cntrnames(struct qib_devdata *dd)
  4494. {
  4495. int i, j = 0;
  4496. char *s;
  4497. for (i = 0, s = (char *)cntr7322names; s && j <= dd->cfgctxts;
  4498. i++) {
  4499. /* we always have at least one counter before the egrovfl */
  4500. if (!j && !strncmp("Ctxt0EgrOvfl", s + 1, 12))
  4501. j = 1;
  4502. s = strchr(s + 1, '\n');
  4503. if (s && j)
  4504. j++;
  4505. }
  4506. dd->cspec->ncntrs = i;
  4507. if (!s)
  4508. /* full list; size is without terminating null */
  4509. dd->cspec->cntrnamelen = sizeof(cntr7322names) - 1;
  4510. else
  4511. dd->cspec->cntrnamelen = 1 + s - cntr7322names;
  4512. dd->cspec->cntrs = kmalloc(dd->cspec->ncntrs
  4513. * sizeof(u64), GFP_KERNEL);
  4514. if (!dd->cspec->cntrs)
  4515. qib_dev_err(dd, "Failed allocation for counters\n");
  4516. for (i = 0, s = (char *)portcntr7322names; s; i++)
  4517. s = strchr(s + 1, '\n');
  4518. dd->cspec->nportcntrs = i - 1;
  4519. dd->cspec->portcntrnamelen = sizeof(portcntr7322names) - 1;
  4520. for (i = 0; i < dd->num_pports; ++i) {
  4521. dd->pport[i].cpspec->portcntrs = kmalloc(dd->cspec->nportcntrs
  4522. * sizeof(u64), GFP_KERNEL);
  4523. if (!dd->pport[i].cpspec->portcntrs)
  4524. qib_dev_err(dd,
  4525. "Failed allocation for portcounters\n");
  4526. }
  4527. }
  4528. static u32 qib_read_7322cntrs(struct qib_devdata *dd, loff_t pos, char **namep,
  4529. u64 **cntrp)
  4530. {
  4531. u32 ret;
  4532. if (namep) {
  4533. ret = dd->cspec->cntrnamelen;
  4534. if (pos >= ret)
  4535. ret = 0; /* final read after getting everything */
  4536. else
  4537. *namep = (char *) cntr7322names;
  4538. } else {
  4539. u64 *cntr = dd->cspec->cntrs;
  4540. int i;
  4541. ret = dd->cspec->ncntrs * sizeof(u64);
  4542. if (!cntr || pos >= ret) {
  4543. /* everything read, or couldn't get memory */
  4544. ret = 0;
  4545. goto done;
  4546. }
  4547. *cntrp = cntr;
  4548. for (i = 0; i < dd->cspec->ncntrs; i++)
  4549. if (cntr7322indices[i] & _PORT_64BIT_FLAG)
  4550. *cntr++ = read_7322_creg(dd,
  4551. cntr7322indices[i] &
  4552. _PORT_CNTR_IDXMASK);
  4553. else
  4554. *cntr++ = read_7322_creg32(dd,
  4555. cntr7322indices[i]);
  4556. }
  4557. done:
  4558. return ret;
  4559. }
  4560. static u32 qib_read_7322portcntrs(struct qib_devdata *dd, loff_t pos, u32 port,
  4561. char **namep, u64 **cntrp)
  4562. {
  4563. u32 ret;
  4564. if (namep) {
  4565. ret = dd->cspec->portcntrnamelen;
  4566. if (pos >= ret)
  4567. ret = 0; /* final read after getting everything */
  4568. else
  4569. *namep = (char *)portcntr7322names;
  4570. } else {
  4571. struct qib_pportdata *ppd = &dd->pport[port];
  4572. u64 *cntr = ppd->cpspec->portcntrs;
  4573. int i;
  4574. ret = dd->cspec->nportcntrs * sizeof(u64);
  4575. if (!cntr || pos >= ret) {
  4576. /* everything read, or couldn't get memory */
  4577. ret = 0;
  4578. goto done;
  4579. }
  4580. *cntrp = cntr;
  4581. for (i = 0; i < dd->cspec->nportcntrs; i++) {
  4582. if (portcntr7322indices[i] & _PORT_VIRT_FLAG)
  4583. *cntr++ = qib_portcntr_7322(ppd,
  4584. portcntr7322indices[i] &
  4585. _PORT_CNTR_IDXMASK);
  4586. else if (portcntr7322indices[i] & _PORT_64BIT_FLAG)
  4587. *cntr++ = read_7322_creg_port(ppd,
  4588. portcntr7322indices[i] &
  4589. _PORT_CNTR_IDXMASK);
  4590. else
  4591. *cntr++ = read_7322_creg32_port(ppd,
  4592. portcntr7322indices[i]);
  4593. }
  4594. }
  4595. done:
  4596. return ret;
  4597. }
  4598. /**
  4599. * qib_get_7322_faststats - get word counters from chip before they overflow
  4600. * @opaque - contains a pointer to the qlogic_ib device qib_devdata
  4601. *
  4602. * VESTIGIAL IBA7322 has no "small fast counters", so the only
  4603. * real purpose of this function is to maintain the notion of
  4604. * "active time", which in turn is only logged into the eeprom,
  4605. * which we don;t have, yet, for 7322-based boards.
  4606. *
  4607. * called from add_timer
  4608. */
  4609. static void qib_get_7322_faststats(unsigned long opaque)
  4610. {
  4611. struct qib_devdata *dd = (struct qib_devdata *) opaque;
  4612. struct qib_pportdata *ppd;
  4613. unsigned long flags;
  4614. u64 traffic_wds;
  4615. int pidx;
  4616. for (pidx = 0; pidx < dd->num_pports; ++pidx) {
  4617. ppd = dd->pport + pidx;
  4618. /*
  4619. * If port isn't enabled or not operational ports, or
  4620. * diags is running (can cause memory diags to fail)
  4621. * skip this port this time.
  4622. */
  4623. if (!ppd->link_speed_supported || !(dd->flags & QIB_INITTED)
  4624. || dd->diag_client)
  4625. continue;
  4626. /*
  4627. * Maintain an activity timer, based on traffic
  4628. * exceeding a threshold, so we need to check the word-counts
  4629. * even if they are 64-bit.
  4630. */
  4631. traffic_wds = qib_portcntr_7322(ppd, QIBPORTCNTR_WORDRCV) +
  4632. qib_portcntr_7322(ppd, QIBPORTCNTR_WORDSEND);
  4633. spin_lock_irqsave(&ppd->dd->eep_st_lock, flags);
  4634. traffic_wds -= ppd->dd->traffic_wds;
  4635. ppd->dd->traffic_wds += traffic_wds;
  4636. if (traffic_wds >= QIB_TRAFFIC_ACTIVE_THRESHOLD)
  4637. atomic_add(ACTIVITY_TIMER, &ppd->dd->active_time);
  4638. spin_unlock_irqrestore(&ppd->dd->eep_st_lock, flags);
  4639. if (ppd->cpspec->qdr_dfe_on && (ppd->link_speed_active &
  4640. QIB_IB_QDR) &&
  4641. (ppd->lflags & (QIBL_LINKINIT | QIBL_LINKARMED |
  4642. QIBL_LINKACTIVE)) &&
  4643. ppd->cpspec->qdr_dfe_time &&
  4644. time_is_before_jiffies(ppd->cpspec->qdr_dfe_time)) {
  4645. ppd->cpspec->qdr_dfe_on = 0;
  4646. qib_write_kreg_port(ppd, krp_static_adapt_dis(2),
  4647. ppd->dd->cspec->r1 ?
  4648. QDR_STATIC_ADAPT_INIT_R1 :
  4649. QDR_STATIC_ADAPT_INIT);
  4650. force_h1(ppd);
  4651. }
  4652. }
  4653. mod_timer(&dd->stats_timer, jiffies + HZ * ACTIVITY_TIMER);
  4654. }
  4655. /*
  4656. * If we were using MSIx, try to fallback to INTx.
  4657. */
  4658. static int qib_7322_intr_fallback(struct qib_devdata *dd)
  4659. {
  4660. if (!dd->cspec->num_msix_entries)
  4661. return 0; /* already using INTx */
  4662. qib_devinfo(dd->pcidev,
  4663. "MSIx interrupt not detected, trying INTx interrupts\n");
  4664. qib_7322_nomsix(dd);
  4665. qib_enable_intx(dd->pcidev);
  4666. qib_setup_7322_interrupt(dd, 0);
  4667. return 1;
  4668. }
  4669. /*
  4670. * Reset the XGXS (between serdes and IBC). Slightly less intrusive
  4671. * than resetting the IBC or external link state, and useful in some
  4672. * cases to cause some retraining. To do this right, we reset IBC
  4673. * as well, then return to previous state (which may be still in reset)
  4674. * NOTE: some callers of this "know" this writes the current value
  4675. * of cpspec->ibcctrl_a as part of it's operation, so if that changes,
  4676. * check all callers.
  4677. */
  4678. static void qib_7322_mini_pcs_reset(struct qib_pportdata *ppd)
  4679. {
  4680. u64 val;
  4681. struct qib_devdata *dd = ppd->dd;
  4682. const u64 reset_bits = SYM_MASK(IBPCSConfig_0, xcv_rreset) |
  4683. SYM_MASK(IBPCSConfig_0, xcv_treset) |
  4684. SYM_MASK(IBPCSConfig_0, tx_rx_reset);
  4685. val = qib_read_kreg_port(ppd, krp_ib_pcsconfig);
  4686. qib_write_kreg(dd, kr_hwerrmask,
  4687. dd->cspec->hwerrmask & ~HWE_MASK(statusValidNoEop));
  4688. qib_write_kreg_port(ppd, krp_ibcctrl_a,
  4689. ppd->cpspec->ibcctrl_a &
  4690. ~SYM_MASK(IBCCtrlA_0, IBLinkEn));
  4691. qib_write_kreg_port(ppd, krp_ib_pcsconfig, val | reset_bits);
  4692. qib_read_kreg32(dd, kr_scratch);
  4693. qib_write_kreg_port(ppd, krp_ib_pcsconfig, val & ~reset_bits);
  4694. qib_write_kreg_port(ppd, krp_ibcctrl_a, ppd->cpspec->ibcctrl_a);
  4695. qib_write_kreg(dd, kr_scratch, 0ULL);
  4696. qib_write_kreg(dd, kr_hwerrclear,
  4697. SYM_MASK(HwErrClear, statusValidNoEopClear));
  4698. qib_write_kreg(dd, kr_hwerrmask, dd->cspec->hwerrmask);
  4699. }
  4700. /*
  4701. * This code for non-IBTA-compliant IB speed negotiation is only known to
  4702. * work for the SDR to DDR transition, and only between an HCA and a switch
  4703. * with recent firmware. It is based on observed heuristics, rather than
  4704. * actual knowledge of the non-compliant speed negotiation.
  4705. * It has a number of hard-coded fields, since the hope is to rewrite this
  4706. * when a spec is available on how the negoation is intended to work.
  4707. */
  4708. static void autoneg_7322_sendpkt(struct qib_pportdata *ppd, u32 *hdr,
  4709. u32 dcnt, u32 *data)
  4710. {
  4711. int i;
  4712. u64 pbc;
  4713. u32 __iomem *piobuf;
  4714. u32 pnum, control, len;
  4715. struct qib_devdata *dd = ppd->dd;
  4716. i = 0;
  4717. len = 7 + dcnt + 1; /* 7 dword header, dword data, icrc */
  4718. control = qib_7322_setpbc_control(ppd, len, 0, 15);
  4719. pbc = ((u64) control << 32) | len;
  4720. while (!(piobuf = qib_7322_getsendbuf(ppd, pbc, &pnum))) {
  4721. if (i++ > 15)
  4722. return;
  4723. udelay(2);
  4724. }
  4725. /* disable header check on this packet, since it can't be valid */
  4726. dd->f_txchk_change(dd, pnum, 1, TXCHK_CHG_TYPE_DIS1, NULL);
  4727. writeq(pbc, piobuf);
  4728. qib_flush_wc();
  4729. qib_pio_copy(piobuf + 2, hdr, 7);
  4730. qib_pio_copy(piobuf + 9, data, dcnt);
  4731. if (dd->flags & QIB_USE_SPCL_TRIG) {
  4732. u32 spcl_off = (pnum >= dd->piobcnt2k) ? 2047 : 1023;
  4733. qib_flush_wc();
  4734. __raw_writel(0xaebecede, piobuf + spcl_off);
  4735. }
  4736. qib_flush_wc();
  4737. qib_sendbuf_done(dd, pnum);
  4738. /* and re-enable hdr check */
  4739. dd->f_txchk_change(dd, pnum, 1, TXCHK_CHG_TYPE_ENAB1, NULL);
  4740. }
  4741. /*
  4742. * _start packet gets sent twice at start, _done gets sent twice at end
  4743. */
  4744. static void qib_autoneg_7322_send(struct qib_pportdata *ppd, int which)
  4745. {
  4746. struct qib_devdata *dd = ppd->dd;
  4747. static u32 swapped;
  4748. u32 dw, i, hcnt, dcnt, *data;
  4749. static u32 hdr[7] = { 0xf002ffff, 0x48ffff, 0x6400abba };
  4750. static u32 madpayload_start[0x40] = {
  4751. 0x1810103, 0x1, 0x0, 0x0, 0x2c90000, 0x2c9, 0x0, 0x0,
  4752. 0xffffffff, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
  4753. 0x1, 0x1388, 0x15e, 0x1, /* rest 0's */
  4754. };
  4755. static u32 madpayload_done[0x40] = {
  4756. 0x1810103, 0x1, 0x0, 0x0, 0x2c90000, 0x2c9, 0x0, 0x0,
  4757. 0xffffffff, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
  4758. 0x40000001, 0x1388, 0x15e, /* rest 0's */
  4759. };
  4760. dcnt = ARRAY_SIZE(madpayload_start);
  4761. hcnt = ARRAY_SIZE(hdr);
  4762. if (!swapped) {
  4763. /* for maintainability, do it at runtime */
  4764. for (i = 0; i < hcnt; i++) {
  4765. dw = (__force u32) cpu_to_be32(hdr[i]);
  4766. hdr[i] = dw;
  4767. }
  4768. for (i = 0; i < dcnt; i++) {
  4769. dw = (__force u32) cpu_to_be32(madpayload_start[i]);
  4770. madpayload_start[i] = dw;
  4771. dw = (__force u32) cpu_to_be32(madpayload_done[i]);
  4772. madpayload_done[i] = dw;
  4773. }
  4774. swapped = 1;
  4775. }
  4776. data = which ? madpayload_done : madpayload_start;
  4777. autoneg_7322_sendpkt(ppd, hdr, dcnt, data);
  4778. qib_read_kreg64(dd, kr_scratch);
  4779. udelay(2);
  4780. autoneg_7322_sendpkt(ppd, hdr, dcnt, data);
  4781. qib_read_kreg64(dd, kr_scratch);
  4782. udelay(2);
  4783. }
  4784. /*
  4785. * Do the absolute minimum to cause an IB speed change, and make it
  4786. * ready, but don't actually trigger the change. The caller will
  4787. * do that when ready (if link is in Polling training state, it will
  4788. * happen immediately, otherwise when link next goes down)
  4789. *
  4790. * This routine should only be used as part of the DDR autonegotation
  4791. * code for devices that are not compliant with IB 1.2 (or code that
  4792. * fixes things up for same).
  4793. *
  4794. * When link has gone down, and autoneg enabled, or autoneg has
  4795. * failed and we give up until next time we set both speeds, and
  4796. * then we want IBTA enabled as well as "use max enabled speed.
  4797. */
  4798. static void set_7322_ibspeed_fast(struct qib_pportdata *ppd, u32 speed)
  4799. {
  4800. u64 newctrlb;
  4801. newctrlb = ppd->cpspec->ibcctrl_b & ~(IBA7322_IBC_SPEED_MASK |
  4802. IBA7322_IBC_IBTA_1_2_MASK |
  4803. IBA7322_IBC_MAX_SPEED_MASK);
  4804. if (speed & (speed - 1)) /* multiple speeds */
  4805. newctrlb |= (speed << IBA7322_IBC_SPEED_LSB) |
  4806. IBA7322_IBC_IBTA_1_2_MASK |
  4807. IBA7322_IBC_MAX_SPEED_MASK;
  4808. else
  4809. newctrlb |= speed == QIB_IB_QDR ?
  4810. IBA7322_IBC_SPEED_QDR | IBA7322_IBC_IBTA_1_2_MASK :
  4811. ((speed == QIB_IB_DDR ?
  4812. IBA7322_IBC_SPEED_DDR : IBA7322_IBC_SPEED_SDR));
  4813. if (newctrlb == ppd->cpspec->ibcctrl_b)
  4814. return;
  4815. ppd->cpspec->ibcctrl_b = newctrlb;
  4816. qib_write_kreg_port(ppd, krp_ibcctrl_b, ppd->cpspec->ibcctrl_b);
  4817. qib_write_kreg(ppd->dd, kr_scratch, 0);
  4818. }
  4819. /*
  4820. * This routine is only used when we are not talking to another
  4821. * IB 1.2-compliant device that we think can do DDR.
  4822. * (This includes all existing switch chips as of Oct 2007.)
  4823. * 1.2-compliant devices go directly to DDR prior to reaching INIT
  4824. */
  4825. static void try_7322_autoneg(struct qib_pportdata *ppd)
  4826. {
  4827. unsigned long flags;
  4828. spin_lock_irqsave(&ppd->lflags_lock, flags);
  4829. ppd->lflags |= QIBL_IB_AUTONEG_INPROG;
  4830. spin_unlock_irqrestore(&ppd->lflags_lock, flags);
  4831. qib_autoneg_7322_send(ppd, 0);
  4832. set_7322_ibspeed_fast(ppd, QIB_IB_DDR);
  4833. qib_7322_mini_pcs_reset(ppd);
  4834. /* 2 msec is minimum length of a poll cycle */
  4835. queue_delayed_work(ib_wq, &ppd->cpspec->autoneg_work,
  4836. msecs_to_jiffies(2));
  4837. }
  4838. /*
  4839. * Handle the empirically determined mechanism for auto-negotiation
  4840. * of DDR speed with switches.
  4841. */
  4842. static void autoneg_7322_work(struct work_struct *work)
  4843. {
  4844. struct qib_pportdata *ppd;
  4845. struct qib_devdata *dd;
  4846. u64 startms;
  4847. u32 i;
  4848. unsigned long flags;
  4849. ppd = container_of(work, struct qib_chippport_specific,
  4850. autoneg_work.work)->ppd;
  4851. dd = ppd->dd;
  4852. startms = jiffies_to_msecs(jiffies);
  4853. /*
  4854. * Busy wait for this first part, it should be at most a
  4855. * few hundred usec, since we scheduled ourselves for 2msec.
  4856. */
  4857. for (i = 0; i < 25; i++) {
  4858. if (SYM_FIELD(ppd->lastibcstat, IBCStatusA_0, LinkState)
  4859. == IB_7322_LT_STATE_POLLQUIET) {
  4860. qib_set_linkstate(ppd, QIB_IB_LINKDOWN_DISABLE);
  4861. break;
  4862. }
  4863. udelay(100);
  4864. }
  4865. if (!(ppd->lflags & QIBL_IB_AUTONEG_INPROG))
  4866. goto done; /* we got there early or told to stop */
  4867. /* we expect this to timeout */
  4868. if (wait_event_timeout(ppd->cpspec->autoneg_wait,
  4869. !(ppd->lflags & QIBL_IB_AUTONEG_INPROG),
  4870. msecs_to_jiffies(90)))
  4871. goto done;
  4872. qib_7322_mini_pcs_reset(ppd);
  4873. /* we expect this to timeout */
  4874. if (wait_event_timeout(ppd->cpspec->autoneg_wait,
  4875. !(ppd->lflags & QIBL_IB_AUTONEG_INPROG),
  4876. msecs_to_jiffies(1700)))
  4877. goto done;
  4878. qib_7322_mini_pcs_reset(ppd);
  4879. set_7322_ibspeed_fast(ppd, QIB_IB_SDR);
  4880. /*
  4881. * Wait up to 250 msec for link to train and get to INIT at DDR;
  4882. * this should terminate early.
  4883. */
  4884. wait_event_timeout(ppd->cpspec->autoneg_wait,
  4885. !(ppd->lflags & QIBL_IB_AUTONEG_INPROG),
  4886. msecs_to_jiffies(250));
  4887. done:
  4888. if (ppd->lflags & QIBL_IB_AUTONEG_INPROG) {
  4889. spin_lock_irqsave(&ppd->lflags_lock, flags);
  4890. ppd->lflags &= ~QIBL_IB_AUTONEG_INPROG;
  4891. if (ppd->cpspec->autoneg_tries == AUTONEG_TRIES) {
  4892. ppd->lflags |= QIBL_IB_AUTONEG_FAILED;
  4893. ppd->cpspec->autoneg_tries = 0;
  4894. }
  4895. spin_unlock_irqrestore(&ppd->lflags_lock, flags);
  4896. set_7322_ibspeed_fast(ppd, ppd->link_speed_enabled);
  4897. }
  4898. }
  4899. /*
  4900. * This routine is used to request IPG set in the QLogic switch.
  4901. * Only called if r1.
  4902. */
  4903. static void try_7322_ipg(struct qib_pportdata *ppd)
  4904. {
  4905. struct qib_ibport *ibp = &ppd->ibport_data;
  4906. struct ib_mad_send_buf *send_buf;
  4907. struct ib_mad_agent *agent;
  4908. struct ib_smp *smp;
  4909. unsigned delay;
  4910. int ret;
  4911. agent = ibp->send_agent;
  4912. if (!agent)
  4913. goto retry;
  4914. send_buf = ib_create_send_mad(agent, 0, 0, 0, IB_MGMT_MAD_HDR,
  4915. IB_MGMT_MAD_DATA, GFP_ATOMIC);
  4916. if (IS_ERR(send_buf))
  4917. goto retry;
  4918. if (!ibp->smi_ah) {
  4919. struct ib_ah *ah;
  4920. ah = qib_create_qp0_ah(ibp, be16_to_cpu(IB_LID_PERMISSIVE));
  4921. if (IS_ERR(ah))
  4922. ret = PTR_ERR(ah);
  4923. else {
  4924. send_buf->ah = ah;
  4925. ibp->smi_ah = to_iah(ah);
  4926. ret = 0;
  4927. }
  4928. } else {
  4929. send_buf->ah = &ibp->smi_ah->ibah;
  4930. ret = 0;
  4931. }
  4932. smp = send_buf->mad;
  4933. smp->base_version = IB_MGMT_BASE_VERSION;
  4934. smp->mgmt_class = IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE;
  4935. smp->class_version = 1;
  4936. smp->method = IB_MGMT_METHOD_SEND;
  4937. smp->hop_cnt = 1;
  4938. smp->attr_id = QIB_VENDOR_IPG;
  4939. smp->attr_mod = 0;
  4940. if (!ret)
  4941. ret = ib_post_send_mad(send_buf, NULL);
  4942. if (ret)
  4943. ib_free_send_mad(send_buf);
  4944. retry:
  4945. delay = 2 << ppd->cpspec->ipg_tries;
  4946. queue_delayed_work(ib_wq, &ppd->cpspec->ipg_work,
  4947. msecs_to_jiffies(delay));
  4948. }
  4949. /*
  4950. * Timeout handler for setting IPG.
  4951. * Only called if r1.
  4952. */
  4953. static void ipg_7322_work(struct work_struct *work)
  4954. {
  4955. struct qib_pportdata *ppd;
  4956. ppd = container_of(work, struct qib_chippport_specific,
  4957. ipg_work.work)->ppd;
  4958. if ((ppd->lflags & (QIBL_LINKINIT | QIBL_LINKARMED | QIBL_LINKACTIVE))
  4959. && ++ppd->cpspec->ipg_tries <= 10)
  4960. try_7322_ipg(ppd);
  4961. }
  4962. static u32 qib_7322_iblink_state(u64 ibcs)
  4963. {
  4964. u32 state = (u32)SYM_FIELD(ibcs, IBCStatusA_0, LinkState);
  4965. switch (state) {
  4966. case IB_7322_L_STATE_INIT:
  4967. state = IB_PORT_INIT;
  4968. break;
  4969. case IB_7322_L_STATE_ARM:
  4970. state = IB_PORT_ARMED;
  4971. break;
  4972. case IB_7322_L_STATE_ACTIVE:
  4973. /* fall through */
  4974. case IB_7322_L_STATE_ACT_DEFER:
  4975. state = IB_PORT_ACTIVE;
  4976. break;
  4977. default: /* fall through */
  4978. case IB_7322_L_STATE_DOWN:
  4979. state = IB_PORT_DOWN;
  4980. break;
  4981. }
  4982. return state;
  4983. }
  4984. /* returns the IBTA port state, rather than the IBC link training state */
  4985. static u8 qib_7322_phys_portstate(u64 ibcs)
  4986. {
  4987. u8 state = (u8)SYM_FIELD(ibcs, IBCStatusA_0, LinkTrainingState);
  4988. return qib_7322_physportstate[state];
  4989. }
  4990. static int qib_7322_ib_updown(struct qib_pportdata *ppd, int ibup, u64 ibcs)
  4991. {
  4992. int ret = 0, symadj = 0;
  4993. unsigned long flags;
  4994. int mult;
  4995. spin_lock_irqsave(&ppd->lflags_lock, flags);
  4996. ppd->lflags &= ~QIBL_IB_FORCE_NOTIFY;
  4997. spin_unlock_irqrestore(&ppd->lflags_lock, flags);
  4998. /* Update our picture of width and speed from chip */
  4999. if (ibcs & SYM_MASK(IBCStatusA_0, LinkSpeedQDR)) {
  5000. ppd->link_speed_active = QIB_IB_QDR;
  5001. mult = 4;
  5002. } else if (ibcs & SYM_MASK(IBCStatusA_0, LinkSpeedActive)) {
  5003. ppd->link_speed_active = QIB_IB_DDR;
  5004. mult = 2;
  5005. } else {
  5006. ppd->link_speed_active = QIB_IB_SDR;
  5007. mult = 1;
  5008. }
  5009. if (ibcs & SYM_MASK(IBCStatusA_0, LinkWidthActive)) {
  5010. ppd->link_width_active = IB_WIDTH_4X;
  5011. mult *= 4;
  5012. } else
  5013. ppd->link_width_active = IB_WIDTH_1X;
  5014. ppd->delay_mult = ib_rate_to_delay[mult_to_ib_rate(mult)];
  5015. if (!ibup) {
  5016. u64 clr;
  5017. /* Link went down. */
  5018. /* do IPG MAD again after linkdown, even if last time failed */
  5019. ppd->cpspec->ipg_tries = 0;
  5020. clr = qib_read_kreg_port(ppd, krp_ibcstatus_b) &
  5021. (SYM_MASK(IBCStatusB_0, heartbeat_timed_out) |
  5022. SYM_MASK(IBCStatusB_0, heartbeat_crosstalk));
  5023. if (clr)
  5024. qib_write_kreg_port(ppd, krp_ibcstatus_b, clr);
  5025. if (!(ppd->lflags & (QIBL_IB_AUTONEG_FAILED |
  5026. QIBL_IB_AUTONEG_INPROG)))
  5027. set_7322_ibspeed_fast(ppd, ppd->link_speed_enabled);
  5028. if (!(ppd->lflags & QIBL_IB_AUTONEG_INPROG)) {
  5029. struct qib_qsfp_data *qd =
  5030. &ppd->cpspec->qsfp_data;
  5031. /* unlock the Tx settings, speed may change */
  5032. qib_write_kreg_port(ppd, krp_tx_deemph_override,
  5033. SYM_MASK(IBSD_TX_DEEMPHASIS_OVERRIDE_0,
  5034. reset_tx_deemphasis_override));
  5035. qib_cancel_sends(ppd);
  5036. /* on link down, ensure sane pcs state */
  5037. qib_7322_mini_pcs_reset(ppd);
  5038. /* schedule the qsfp refresh which should turn the link
  5039. off */
  5040. if (ppd->dd->flags & QIB_HAS_QSFP) {
  5041. qd->t_insert = jiffies;
  5042. queue_work(ib_wq, &qd->work);
  5043. }
  5044. spin_lock_irqsave(&ppd->sdma_lock, flags);
  5045. if (__qib_sdma_running(ppd))
  5046. __qib_sdma_process_event(ppd,
  5047. qib_sdma_event_e70_go_idle);
  5048. spin_unlock_irqrestore(&ppd->sdma_lock, flags);
  5049. }
  5050. clr = read_7322_creg32_port(ppd, crp_iblinkdown);
  5051. if (clr == ppd->cpspec->iblnkdownsnap)
  5052. ppd->cpspec->iblnkdowndelta++;
  5053. } else {
  5054. if (qib_compat_ddr_negotiate &&
  5055. !(ppd->lflags & (QIBL_IB_AUTONEG_FAILED |
  5056. QIBL_IB_AUTONEG_INPROG)) &&
  5057. ppd->link_speed_active == QIB_IB_SDR &&
  5058. (ppd->link_speed_enabled & QIB_IB_DDR)
  5059. && ppd->cpspec->autoneg_tries < AUTONEG_TRIES) {
  5060. /* we are SDR, and auto-negotiation enabled */
  5061. ++ppd->cpspec->autoneg_tries;
  5062. if (!ppd->cpspec->ibdeltainprog) {
  5063. ppd->cpspec->ibdeltainprog = 1;
  5064. ppd->cpspec->ibsymdelta +=
  5065. read_7322_creg32_port(ppd,
  5066. crp_ibsymbolerr) -
  5067. ppd->cpspec->ibsymsnap;
  5068. ppd->cpspec->iblnkerrdelta +=
  5069. read_7322_creg32_port(ppd,
  5070. crp_iblinkerrrecov) -
  5071. ppd->cpspec->iblnkerrsnap;
  5072. }
  5073. try_7322_autoneg(ppd);
  5074. ret = 1; /* no other IB status change processing */
  5075. } else if ((ppd->lflags & QIBL_IB_AUTONEG_INPROG) &&
  5076. ppd->link_speed_active == QIB_IB_SDR) {
  5077. qib_autoneg_7322_send(ppd, 1);
  5078. set_7322_ibspeed_fast(ppd, QIB_IB_DDR);
  5079. qib_7322_mini_pcs_reset(ppd);
  5080. udelay(2);
  5081. ret = 1; /* no other IB status change processing */
  5082. } else if ((ppd->lflags & QIBL_IB_AUTONEG_INPROG) &&
  5083. (ppd->link_speed_active & QIB_IB_DDR)) {
  5084. spin_lock_irqsave(&ppd->lflags_lock, flags);
  5085. ppd->lflags &= ~(QIBL_IB_AUTONEG_INPROG |
  5086. QIBL_IB_AUTONEG_FAILED);
  5087. spin_unlock_irqrestore(&ppd->lflags_lock, flags);
  5088. ppd->cpspec->autoneg_tries = 0;
  5089. /* re-enable SDR, for next link down */
  5090. set_7322_ibspeed_fast(ppd, ppd->link_speed_enabled);
  5091. wake_up(&ppd->cpspec->autoneg_wait);
  5092. symadj = 1;
  5093. } else if (ppd->lflags & QIBL_IB_AUTONEG_FAILED) {
  5094. /*
  5095. * Clear autoneg failure flag, and do setup
  5096. * so we'll try next time link goes down and
  5097. * back to INIT (possibly connected to a
  5098. * different device).
  5099. */
  5100. spin_lock_irqsave(&ppd->lflags_lock, flags);
  5101. ppd->lflags &= ~QIBL_IB_AUTONEG_FAILED;
  5102. spin_unlock_irqrestore(&ppd->lflags_lock, flags);
  5103. ppd->cpspec->ibcctrl_b |= IBA7322_IBC_IBTA_1_2_MASK;
  5104. symadj = 1;
  5105. }
  5106. if (!(ppd->lflags & QIBL_IB_AUTONEG_INPROG)) {
  5107. symadj = 1;
  5108. if (ppd->dd->cspec->r1 && ppd->cpspec->ipg_tries <= 10)
  5109. try_7322_ipg(ppd);
  5110. if (!ppd->cpspec->recovery_init)
  5111. setup_7322_link_recovery(ppd, 0);
  5112. ppd->cpspec->qdr_dfe_time = jiffies +
  5113. msecs_to_jiffies(QDR_DFE_DISABLE_DELAY);
  5114. }
  5115. ppd->cpspec->ibmalfusesnap = 0;
  5116. ppd->cpspec->ibmalfsnap = read_7322_creg32_port(ppd,
  5117. crp_errlink);
  5118. }
  5119. if (symadj) {
  5120. ppd->cpspec->iblnkdownsnap =
  5121. read_7322_creg32_port(ppd, crp_iblinkdown);
  5122. if (ppd->cpspec->ibdeltainprog) {
  5123. ppd->cpspec->ibdeltainprog = 0;
  5124. ppd->cpspec->ibsymdelta += read_7322_creg32_port(ppd,
  5125. crp_ibsymbolerr) - ppd->cpspec->ibsymsnap;
  5126. ppd->cpspec->iblnkerrdelta += read_7322_creg32_port(ppd,
  5127. crp_iblinkerrrecov) - ppd->cpspec->iblnkerrsnap;
  5128. }
  5129. } else if (!ibup && qib_compat_ddr_negotiate &&
  5130. !ppd->cpspec->ibdeltainprog &&
  5131. !(ppd->lflags & QIBL_IB_AUTONEG_INPROG)) {
  5132. ppd->cpspec->ibdeltainprog = 1;
  5133. ppd->cpspec->ibsymsnap = read_7322_creg32_port(ppd,
  5134. crp_ibsymbolerr);
  5135. ppd->cpspec->iblnkerrsnap = read_7322_creg32_port(ppd,
  5136. crp_iblinkerrrecov);
  5137. }
  5138. if (!ret)
  5139. qib_setup_7322_setextled(ppd, ibup);
  5140. return ret;
  5141. }
  5142. /*
  5143. * Does read/modify/write to appropriate registers to
  5144. * set output and direction bits selected by mask.
  5145. * these are in their canonical postions (e.g. lsb of
  5146. * dir will end up in D48 of extctrl on existing chips).
  5147. * returns contents of GP Inputs.
  5148. */
  5149. static int gpio_7322_mod(struct qib_devdata *dd, u32 out, u32 dir, u32 mask)
  5150. {
  5151. u64 read_val, new_out;
  5152. unsigned long flags;
  5153. if (mask) {
  5154. /* some bits being written, lock access to GPIO */
  5155. dir &= mask;
  5156. out &= mask;
  5157. spin_lock_irqsave(&dd->cspec->gpio_lock, flags);
  5158. dd->cspec->extctrl &= ~((u64)mask << SYM_LSB(EXTCtrl, GPIOOe));
  5159. dd->cspec->extctrl |= ((u64) dir << SYM_LSB(EXTCtrl, GPIOOe));
  5160. new_out = (dd->cspec->gpio_out & ~mask) | out;
  5161. qib_write_kreg(dd, kr_extctrl, dd->cspec->extctrl);
  5162. qib_write_kreg(dd, kr_gpio_out, new_out);
  5163. dd->cspec->gpio_out = new_out;
  5164. spin_unlock_irqrestore(&dd->cspec->gpio_lock, flags);
  5165. }
  5166. /*
  5167. * It is unlikely that a read at this time would get valid
  5168. * data on a pin whose direction line was set in the same
  5169. * call to this function. We include the read here because
  5170. * that allows us to potentially combine a change on one pin with
  5171. * a read on another, and because the old code did something like
  5172. * this.
  5173. */
  5174. read_val = qib_read_kreg64(dd, kr_extstatus);
  5175. return SYM_FIELD(read_val, EXTStatus, GPIOIn);
  5176. }
  5177. /* Enable writes to config EEPROM, if possible. Returns previous state */
  5178. static int qib_7322_eeprom_wen(struct qib_devdata *dd, int wen)
  5179. {
  5180. int prev_wen;
  5181. u32 mask;
  5182. mask = 1 << QIB_EEPROM_WEN_NUM;
  5183. prev_wen = ~gpio_7322_mod(dd, 0, 0, 0) >> QIB_EEPROM_WEN_NUM;
  5184. gpio_7322_mod(dd, wen ? 0 : mask, mask, mask);
  5185. return prev_wen & 1;
  5186. }
  5187. /*
  5188. * Read fundamental info we need to use the chip. These are
  5189. * the registers that describe chip capabilities, and are
  5190. * saved in shadow registers.
  5191. */
  5192. static void get_7322_chip_params(struct qib_devdata *dd)
  5193. {
  5194. u64 val;
  5195. u32 piobufs;
  5196. int mtu;
  5197. dd->palign = qib_read_kreg32(dd, kr_pagealign);
  5198. dd->uregbase = qib_read_kreg32(dd, kr_userregbase);
  5199. dd->rcvtidcnt = qib_read_kreg32(dd, kr_rcvtidcnt);
  5200. dd->rcvtidbase = qib_read_kreg32(dd, kr_rcvtidbase);
  5201. dd->rcvegrbase = qib_read_kreg32(dd, kr_rcvegrbase);
  5202. dd->piobufbase = qib_read_kreg64(dd, kr_sendpiobufbase);
  5203. dd->pio2k_bufbase = dd->piobufbase & 0xffffffff;
  5204. val = qib_read_kreg64(dd, kr_sendpiobufcnt);
  5205. dd->piobcnt2k = val & ~0U;
  5206. dd->piobcnt4k = val >> 32;
  5207. val = qib_read_kreg64(dd, kr_sendpiosize);
  5208. dd->piosize2k = val & ~0U;
  5209. dd->piosize4k = val >> 32;
  5210. mtu = ib_mtu_enum_to_int(qib_ibmtu);
  5211. if (mtu == -1)
  5212. mtu = QIB_DEFAULT_MTU;
  5213. dd->pport[0].ibmtu = (u32)mtu;
  5214. dd->pport[1].ibmtu = (u32)mtu;
  5215. /* these may be adjusted in init_chip_wc_pat() */
  5216. dd->pio2kbase = (u32 __iomem *)
  5217. ((char __iomem *) dd->kregbase + dd->pio2k_bufbase);
  5218. dd->pio4kbase = (u32 __iomem *)
  5219. ((char __iomem *) dd->kregbase +
  5220. (dd->piobufbase >> 32));
  5221. /*
  5222. * 4K buffers take 2 pages; we use roundup just to be
  5223. * paranoid; we calculate it once here, rather than on
  5224. * ever buf allocate
  5225. */
  5226. dd->align4k = ALIGN(dd->piosize4k, dd->palign);
  5227. piobufs = dd->piobcnt4k + dd->piobcnt2k + NUM_VL15_BUFS;
  5228. dd->pioavregs = ALIGN(piobufs, sizeof(u64) * BITS_PER_BYTE / 2) /
  5229. (sizeof(u64) * BITS_PER_BYTE / 2);
  5230. }
  5231. /*
  5232. * The chip base addresses in cspec and cpspec have to be set
  5233. * after possible init_chip_wc_pat(), rather than in
  5234. * get_7322_chip_params(), so split out as separate function
  5235. */
  5236. static void qib_7322_set_baseaddrs(struct qib_devdata *dd)
  5237. {
  5238. u32 cregbase;
  5239. cregbase = qib_read_kreg32(dd, kr_counterregbase);
  5240. dd->cspec->cregbase = (u64 __iomem *)(cregbase +
  5241. (char __iomem *)dd->kregbase);
  5242. dd->egrtidbase = (u64 __iomem *)
  5243. ((char __iomem *) dd->kregbase + dd->rcvegrbase);
  5244. /* port registers are defined as relative to base of chip */
  5245. dd->pport[0].cpspec->kpregbase =
  5246. (u64 __iomem *)((char __iomem *)dd->kregbase);
  5247. dd->pport[1].cpspec->kpregbase =
  5248. (u64 __iomem *)(dd->palign +
  5249. (char __iomem *)dd->kregbase);
  5250. dd->pport[0].cpspec->cpregbase =
  5251. (u64 __iomem *)(qib_read_kreg_port(&dd->pport[0],
  5252. kr_counterregbase) + (char __iomem *)dd->kregbase);
  5253. dd->pport[1].cpspec->cpregbase =
  5254. (u64 __iomem *)(qib_read_kreg_port(&dd->pport[1],
  5255. kr_counterregbase) + (char __iomem *)dd->kregbase);
  5256. }
  5257. /*
  5258. * This is a fairly special-purpose observer, so we only support
  5259. * the port-specific parts of SendCtrl
  5260. */
  5261. #define SENDCTRL_SHADOWED (SYM_MASK(SendCtrl_0, SendEnable) | \
  5262. SYM_MASK(SendCtrl_0, SDmaEnable) | \
  5263. SYM_MASK(SendCtrl_0, SDmaIntEnable) | \
  5264. SYM_MASK(SendCtrl_0, SDmaSingleDescriptor) | \
  5265. SYM_MASK(SendCtrl_0, SDmaHalt) | \
  5266. SYM_MASK(SendCtrl_0, IBVLArbiterEn) | \
  5267. SYM_MASK(SendCtrl_0, ForceCreditUpToDate))
  5268. static int sendctrl_hook(struct qib_devdata *dd,
  5269. const struct diag_observer *op, u32 offs,
  5270. u64 *data, u64 mask, int only_32)
  5271. {
  5272. unsigned long flags;
  5273. unsigned idx;
  5274. unsigned pidx;
  5275. struct qib_pportdata *ppd = NULL;
  5276. u64 local_data, all_bits;
  5277. /*
  5278. * The fixed correspondence between Physical ports and pports is
  5279. * severed. We need to hunt for the ppd that corresponds
  5280. * to the offset we got. And we have to do that without admitting
  5281. * we know the stride, apparently.
  5282. */
  5283. for (pidx = 0; pidx < dd->num_pports; ++pidx) {
  5284. u64 __iomem *psptr;
  5285. u32 psoffs;
  5286. ppd = dd->pport + pidx;
  5287. if (!ppd->cpspec->kpregbase)
  5288. continue;
  5289. psptr = ppd->cpspec->kpregbase + krp_sendctrl;
  5290. psoffs = (u32) (psptr - dd->kregbase) * sizeof(*psptr);
  5291. if (psoffs == offs)
  5292. break;
  5293. }
  5294. /* If pport is not being managed by driver, just avoid shadows. */
  5295. if (pidx >= dd->num_pports)
  5296. ppd = NULL;
  5297. /* In any case, "idx" is flat index in kreg space */
  5298. idx = offs / sizeof(u64);
  5299. all_bits = ~0ULL;
  5300. if (only_32)
  5301. all_bits >>= 32;
  5302. spin_lock_irqsave(&dd->sendctrl_lock, flags);
  5303. if (!ppd || (mask & all_bits) != all_bits) {
  5304. /*
  5305. * At least some mask bits are zero, so we need
  5306. * to read. The judgement call is whether from
  5307. * reg or shadow. First-cut: read reg, and complain
  5308. * if any bits which should be shadowed are different
  5309. * from their shadowed value.
  5310. */
  5311. if (only_32)
  5312. local_data = (u64)qib_read_kreg32(dd, idx);
  5313. else
  5314. local_data = qib_read_kreg64(dd, idx);
  5315. *data = (local_data & ~mask) | (*data & mask);
  5316. }
  5317. if (mask) {
  5318. /*
  5319. * At least some mask bits are one, so we need
  5320. * to write, but only shadow some bits.
  5321. */
  5322. u64 sval, tval; /* Shadowed, transient */
  5323. /*
  5324. * New shadow val is bits we don't want to touch,
  5325. * ORed with bits we do, that are intended for shadow.
  5326. */
  5327. if (ppd) {
  5328. sval = ppd->p_sendctrl & ~mask;
  5329. sval |= *data & SENDCTRL_SHADOWED & mask;
  5330. ppd->p_sendctrl = sval;
  5331. } else
  5332. sval = *data & SENDCTRL_SHADOWED & mask;
  5333. tval = sval | (*data & ~SENDCTRL_SHADOWED & mask);
  5334. qib_write_kreg(dd, idx, tval);
  5335. qib_write_kreg(dd, kr_scratch, 0Ull);
  5336. }
  5337. spin_unlock_irqrestore(&dd->sendctrl_lock, flags);
  5338. return only_32 ? 4 : 8;
  5339. }
  5340. static const struct diag_observer sendctrl_0_observer = {
  5341. sendctrl_hook, KREG_IDX(SendCtrl_0) * sizeof(u64),
  5342. KREG_IDX(SendCtrl_0) * sizeof(u64)
  5343. };
  5344. static const struct diag_observer sendctrl_1_observer = {
  5345. sendctrl_hook, KREG_IDX(SendCtrl_1) * sizeof(u64),
  5346. KREG_IDX(SendCtrl_1) * sizeof(u64)
  5347. };
  5348. static ushort sdma_fetch_prio = 8;
  5349. module_param_named(sdma_fetch_prio, sdma_fetch_prio, ushort, S_IRUGO);
  5350. MODULE_PARM_DESC(sdma_fetch_prio, "SDMA descriptor fetch priority");
  5351. /* Besides logging QSFP events, we set appropriate TxDDS values */
  5352. static void init_txdds_table(struct qib_pportdata *ppd, int override);
  5353. static void qsfp_7322_event(struct work_struct *work)
  5354. {
  5355. struct qib_qsfp_data *qd;
  5356. struct qib_pportdata *ppd;
  5357. unsigned long pwrup;
  5358. unsigned long flags;
  5359. int ret;
  5360. u32 le2;
  5361. qd = container_of(work, struct qib_qsfp_data, work);
  5362. ppd = qd->ppd;
  5363. pwrup = qd->t_insert +
  5364. msecs_to_jiffies(QSFP_PWR_LAG_MSEC - QSFP_MODPRS_LAG_MSEC);
  5365. /* Delay for 20 msecs to allow ModPrs resistor to setup */
  5366. mdelay(QSFP_MODPRS_LAG_MSEC);
  5367. if (!qib_qsfp_mod_present(ppd)) {
  5368. ppd->cpspec->qsfp_data.modpresent = 0;
  5369. /* Set the physical link to disabled */
  5370. qib_set_ib_7322_lstate(ppd, 0,
  5371. QLOGIC_IB_IBCC_LINKINITCMD_DISABLE);
  5372. spin_lock_irqsave(&ppd->lflags_lock, flags);
  5373. ppd->lflags &= ~QIBL_LINKV;
  5374. spin_unlock_irqrestore(&ppd->lflags_lock, flags);
  5375. } else {
  5376. /*
  5377. * Some QSFP's not only do not respond until the full power-up
  5378. * time, but may behave badly if we try. So hold off responding
  5379. * to insertion.
  5380. */
  5381. while (1) {
  5382. if (time_is_before_jiffies(pwrup))
  5383. break;
  5384. msleep(20);
  5385. }
  5386. ret = qib_refresh_qsfp_cache(ppd, &qd->cache);
  5387. /*
  5388. * Need to change LE2 back to defaults if we couldn't
  5389. * read the cable type (to handle cable swaps), so do this
  5390. * even on failure to read cable information. We don't
  5391. * get here for QME, so IS_QME check not needed here.
  5392. */
  5393. if (!ret && !ppd->dd->cspec->r1) {
  5394. if (QSFP_IS_ACTIVE_FAR(qd->cache.tech))
  5395. le2 = LE2_QME;
  5396. else if (qd->cache.atten[1] >= qib_long_atten &&
  5397. QSFP_IS_CU(qd->cache.tech))
  5398. le2 = LE2_5m;
  5399. else
  5400. le2 = LE2_DEFAULT;
  5401. } else
  5402. le2 = LE2_DEFAULT;
  5403. ibsd_wr_allchans(ppd, 13, (le2 << 7), BMASK(9, 7));
  5404. /*
  5405. * We always change parameteters, since we can choose
  5406. * values for cables without eeproms, and the cable may have
  5407. * changed from a cable with full or partial eeprom content
  5408. * to one with partial or no content.
  5409. */
  5410. init_txdds_table(ppd, 0);
  5411. /* The physical link is being re-enabled only when the
  5412. * previous state was DISABLED and the VALID bit is not
  5413. * set. This should only happen when the cable has been
  5414. * physically pulled. */
  5415. if (!ppd->cpspec->qsfp_data.modpresent &&
  5416. (ppd->lflags & (QIBL_LINKV | QIBL_IB_LINK_DISABLED))) {
  5417. ppd->cpspec->qsfp_data.modpresent = 1;
  5418. qib_set_ib_7322_lstate(ppd, 0,
  5419. QLOGIC_IB_IBCC_LINKINITCMD_SLEEP);
  5420. spin_lock_irqsave(&ppd->lflags_lock, flags);
  5421. ppd->lflags |= QIBL_LINKV;
  5422. spin_unlock_irqrestore(&ppd->lflags_lock, flags);
  5423. }
  5424. }
  5425. }
  5426. /*
  5427. * There is little we can do but complain to the user if QSFP
  5428. * initialization fails.
  5429. */
  5430. static void qib_init_7322_qsfp(struct qib_pportdata *ppd)
  5431. {
  5432. unsigned long flags;
  5433. struct qib_qsfp_data *qd = &ppd->cpspec->qsfp_data;
  5434. struct qib_devdata *dd = ppd->dd;
  5435. u64 mod_prs_bit = QSFP_GPIO_MOD_PRS_N;
  5436. mod_prs_bit <<= (QSFP_GPIO_PORT2_SHIFT * ppd->hw_pidx);
  5437. qd->ppd = ppd;
  5438. qib_qsfp_init(qd, qsfp_7322_event);
  5439. spin_lock_irqsave(&dd->cspec->gpio_lock, flags);
  5440. dd->cspec->extctrl |= (mod_prs_bit << SYM_LSB(EXTCtrl, GPIOInvert));
  5441. dd->cspec->gpio_mask |= mod_prs_bit;
  5442. qib_write_kreg(dd, kr_extctrl, dd->cspec->extctrl);
  5443. qib_write_kreg(dd, kr_gpio_mask, dd->cspec->gpio_mask);
  5444. spin_unlock_irqrestore(&dd->cspec->gpio_lock, flags);
  5445. }
  5446. /*
  5447. * called at device initialization time, and also if the txselect
  5448. * module parameter is changed. This is used for cables that don't
  5449. * have valid QSFP EEPROMs (not present, or attenuation is zero).
  5450. * We initialize to the default, then if there is a specific
  5451. * unit,port match, we use that (and set it immediately, for the
  5452. * current speed, if the link is at INIT or better).
  5453. * String format is "default# unit#,port#=# ... u,p=#", separators must
  5454. * be a SPACE character. A newline terminates. The u,p=# tuples may
  5455. * optionally have "u,p=#,#", where the final # is the H1 value
  5456. * The last specific match is used (actually, all are used, but last
  5457. * one is the one that winds up set); if none at all, fall back on default.
  5458. */
  5459. static void set_no_qsfp_atten(struct qib_devdata *dd, int change)
  5460. {
  5461. char *nxt, *str;
  5462. u32 pidx, unit, port, deflt, h1;
  5463. unsigned long val;
  5464. int any = 0, seth1;
  5465. int txdds_size;
  5466. str = txselect_list;
  5467. /* default number is validated in setup_txselect() */
  5468. deflt = simple_strtoul(str, &nxt, 0);
  5469. for (pidx = 0; pidx < dd->num_pports; ++pidx)
  5470. dd->pport[pidx].cpspec->no_eep = deflt;
  5471. txdds_size = TXDDS_TABLE_SZ + TXDDS_EXTRA_SZ;
  5472. if (IS_QME(dd) || IS_QMH(dd))
  5473. txdds_size += TXDDS_MFG_SZ;
  5474. while (*nxt && nxt[1]) {
  5475. str = ++nxt;
  5476. unit = simple_strtoul(str, &nxt, 0);
  5477. if (nxt == str || !*nxt || *nxt != ',') {
  5478. while (*nxt && *nxt++ != ' ') /* skip to next, if any */
  5479. ;
  5480. continue;
  5481. }
  5482. str = ++nxt;
  5483. port = simple_strtoul(str, &nxt, 0);
  5484. if (nxt == str || *nxt != '=') {
  5485. while (*nxt && *nxt++ != ' ') /* skip to next, if any */
  5486. ;
  5487. continue;
  5488. }
  5489. str = ++nxt;
  5490. val = simple_strtoul(str, &nxt, 0);
  5491. if (nxt == str) {
  5492. while (*nxt && *nxt++ != ' ') /* skip to next, if any */
  5493. ;
  5494. continue;
  5495. }
  5496. if (val >= txdds_size)
  5497. continue;
  5498. seth1 = 0;
  5499. h1 = 0; /* gcc thinks it might be used uninitted */
  5500. if (*nxt == ',' && nxt[1]) {
  5501. str = ++nxt;
  5502. h1 = (u32)simple_strtoul(str, &nxt, 0);
  5503. if (nxt == str)
  5504. while (*nxt && *nxt++ != ' ') /* skip */
  5505. ;
  5506. else
  5507. seth1 = 1;
  5508. }
  5509. for (pidx = 0; dd->unit == unit && pidx < dd->num_pports;
  5510. ++pidx) {
  5511. struct qib_pportdata *ppd = &dd->pport[pidx];
  5512. if (ppd->port != port || !ppd->link_speed_supported)
  5513. continue;
  5514. ppd->cpspec->no_eep = val;
  5515. if (seth1)
  5516. ppd->cpspec->h1_val = h1;
  5517. /* now change the IBC and serdes, overriding generic */
  5518. init_txdds_table(ppd, 1);
  5519. /* Re-enable the physical state machine on mezz boards
  5520. * now that the correct settings have been set.
  5521. * QSFP boards are handles by the QSFP event handler */
  5522. if (IS_QMH(dd) || IS_QME(dd))
  5523. qib_set_ib_7322_lstate(ppd, 0,
  5524. QLOGIC_IB_IBCC_LINKINITCMD_SLEEP);
  5525. any++;
  5526. }
  5527. if (*nxt == '\n')
  5528. break; /* done */
  5529. }
  5530. if (change && !any) {
  5531. /* no specific setting, use the default.
  5532. * Change the IBC and serdes, but since it's
  5533. * general, don't override specific settings.
  5534. */
  5535. for (pidx = 0; pidx < dd->num_pports; ++pidx)
  5536. if (dd->pport[pidx].link_speed_supported)
  5537. init_txdds_table(&dd->pport[pidx], 0);
  5538. }
  5539. }
  5540. /* handle the txselect parameter changing */
  5541. static int setup_txselect(const char *str, struct kernel_param *kp)
  5542. {
  5543. struct qib_devdata *dd;
  5544. unsigned long val;
  5545. char *n;
  5546. if (strlen(str) >= MAX_ATTEN_LEN) {
  5547. pr_info("txselect_values string too long\n");
  5548. return -ENOSPC;
  5549. }
  5550. val = simple_strtoul(str, &n, 0);
  5551. if (n == str || val >= (TXDDS_TABLE_SZ + TXDDS_EXTRA_SZ +
  5552. TXDDS_MFG_SZ)) {
  5553. pr_info("txselect_values must start with a number < %d\n",
  5554. TXDDS_TABLE_SZ + TXDDS_EXTRA_SZ + TXDDS_MFG_SZ);
  5555. return -EINVAL;
  5556. }
  5557. strcpy(txselect_list, str);
  5558. list_for_each_entry(dd, &qib_dev_list, list)
  5559. if (dd->deviceid == PCI_DEVICE_ID_QLOGIC_IB_7322)
  5560. set_no_qsfp_atten(dd, 1);
  5561. return 0;
  5562. }
  5563. /*
  5564. * Write the final few registers that depend on some of the
  5565. * init setup. Done late in init, just before bringing up
  5566. * the serdes.
  5567. */
  5568. static int qib_late_7322_initreg(struct qib_devdata *dd)
  5569. {
  5570. int ret = 0, n;
  5571. u64 val;
  5572. qib_write_kreg(dd, kr_rcvhdrentsize, dd->rcvhdrentsize);
  5573. qib_write_kreg(dd, kr_rcvhdrsize, dd->rcvhdrsize);
  5574. qib_write_kreg(dd, kr_rcvhdrcnt, dd->rcvhdrcnt);
  5575. qib_write_kreg(dd, kr_sendpioavailaddr, dd->pioavailregs_phys);
  5576. val = qib_read_kreg64(dd, kr_sendpioavailaddr);
  5577. if (val != dd->pioavailregs_phys) {
  5578. qib_dev_err(dd,
  5579. "Catastrophic software error, SendPIOAvailAddr written as %lx, read back as %llx\n",
  5580. (unsigned long) dd->pioavailregs_phys,
  5581. (unsigned long long) val);
  5582. ret = -EINVAL;
  5583. }
  5584. n = dd->piobcnt2k + dd->piobcnt4k + NUM_VL15_BUFS;
  5585. qib_7322_txchk_change(dd, 0, n, TXCHK_CHG_TYPE_KERN, NULL);
  5586. /* driver sends get pkey, lid, etc. checking also, to catch bugs */
  5587. qib_7322_txchk_change(dd, 0, n, TXCHK_CHG_TYPE_ENAB1, NULL);
  5588. qib_register_observer(dd, &sendctrl_0_observer);
  5589. qib_register_observer(dd, &sendctrl_1_observer);
  5590. dd->control &= ~QLOGIC_IB_C_SDMAFETCHPRIOEN;
  5591. qib_write_kreg(dd, kr_control, dd->control);
  5592. /*
  5593. * Set SendDmaFetchPriority and init Tx params, including
  5594. * QSFP handler on boards that have QSFP.
  5595. * First set our default attenuation entry for cables that
  5596. * don't have valid attenuation.
  5597. */
  5598. set_no_qsfp_atten(dd, 0);
  5599. for (n = 0; n < dd->num_pports; ++n) {
  5600. struct qib_pportdata *ppd = dd->pport + n;
  5601. qib_write_kreg_port(ppd, krp_senddmaprioritythld,
  5602. sdma_fetch_prio & 0xf);
  5603. /* Initialize qsfp if present on board. */
  5604. if (dd->flags & QIB_HAS_QSFP)
  5605. qib_init_7322_qsfp(ppd);
  5606. }
  5607. dd->control |= QLOGIC_IB_C_SDMAFETCHPRIOEN;
  5608. qib_write_kreg(dd, kr_control, dd->control);
  5609. return ret;
  5610. }
  5611. /* per IB port errors. */
  5612. #define SENDCTRL_PIBP (MASK_ACROSS(0, 1) | MASK_ACROSS(3, 3) | \
  5613. MASK_ACROSS(8, 15))
  5614. #define RCVCTRL_PIBP (MASK_ACROSS(0, 17) | MASK_ACROSS(39, 41))
  5615. #define ERRS_PIBP (MASK_ACROSS(57, 58) | MASK_ACROSS(54, 54) | \
  5616. MASK_ACROSS(36, 49) | MASK_ACROSS(29, 34) | MASK_ACROSS(14, 17) | \
  5617. MASK_ACROSS(0, 11))
  5618. /*
  5619. * Write the initialization per-port registers that need to be done at
  5620. * driver load and after reset completes (i.e., that aren't done as part
  5621. * of other init procedures called from qib_init.c).
  5622. * Some of these should be redundant on reset, but play safe.
  5623. */
  5624. static void write_7322_init_portregs(struct qib_pportdata *ppd)
  5625. {
  5626. u64 val;
  5627. int i;
  5628. if (!ppd->link_speed_supported) {
  5629. /* no buffer credits for this port */
  5630. for (i = 1; i < 8; i++)
  5631. qib_write_kreg_port(ppd, krp_rxcreditvl0 + i, 0);
  5632. qib_write_kreg_port(ppd, krp_ibcctrl_b, 0);
  5633. qib_write_kreg(ppd->dd, kr_scratch, 0);
  5634. return;
  5635. }
  5636. /*
  5637. * Set the number of supported virtual lanes in IBC,
  5638. * for flow control packet handling on unsupported VLs
  5639. */
  5640. val = qib_read_kreg_port(ppd, krp_ibsdtestiftx);
  5641. val &= ~SYM_MASK(IB_SDTEST_IF_TX_0, VL_CAP);
  5642. val |= (u64)(ppd->vls_supported - 1) <<
  5643. SYM_LSB(IB_SDTEST_IF_TX_0, VL_CAP);
  5644. qib_write_kreg_port(ppd, krp_ibsdtestiftx, val);
  5645. qib_write_kreg_port(ppd, krp_rcvbthqp, QIB_KD_QP);
  5646. /* enable tx header checking */
  5647. qib_write_kreg_port(ppd, krp_sendcheckcontrol, IBA7322_SENDCHK_PKEY |
  5648. IBA7322_SENDCHK_BTHQP | IBA7322_SENDCHK_SLID |
  5649. IBA7322_SENDCHK_RAW_IPV6 | IBA7322_SENDCHK_MINSZ);
  5650. qib_write_kreg_port(ppd, krp_ncmodectrl,
  5651. SYM_MASK(IBNCModeCtrl_0, ScrambleCapLocal));
  5652. /*
  5653. * Unconditionally clear the bufmask bits. If SDMA is
  5654. * enabled, we'll set them appropriately later.
  5655. */
  5656. qib_write_kreg_port(ppd, krp_senddmabufmask0, 0);
  5657. qib_write_kreg_port(ppd, krp_senddmabufmask1, 0);
  5658. qib_write_kreg_port(ppd, krp_senddmabufmask2, 0);
  5659. if (ppd->dd->cspec->r1)
  5660. ppd->p_sendctrl |= SYM_MASK(SendCtrl_0, ForceCreditUpToDate);
  5661. }
  5662. /*
  5663. * Write the initialization per-device registers that need to be done at
  5664. * driver load and after reset completes (i.e., that aren't done as part
  5665. * of other init procedures called from qib_init.c). Also write per-port
  5666. * registers that are affected by overall device config, such as QP mapping
  5667. * Some of these should be redundant on reset, but play safe.
  5668. */
  5669. static void write_7322_initregs(struct qib_devdata *dd)
  5670. {
  5671. struct qib_pportdata *ppd;
  5672. int i, pidx;
  5673. u64 val;
  5674. /* Set Multicast QPs received by port 2 to map to context one. */
  5675. qib_write_kreg(dd, KREG_IDX(RcvQPMulticastContext_1), 1);
  5676. for (pidx = 0; pidx < dd->num_pports; ++pidx) {
  5677. unsigned n, regno;
  5678. unsigned long flags;
  5679. if (dd->n_krcv_queues < 2 ||
  5680. !dd->pport[pidx].link_speed_supported)
  5681. continue;
  5682. ppd = &dd->pport[pidx];
  5683. /* be paranoid against later code motion, etc. */
  5684. spin_lock_irqsave(&dd->cspec->rcvmod_lock, flags);
  5685. ppd->p_rcvctrl |= SYM_MASK(RcvCtrl_0, RcvQPMapEnable);
  5686. spin_unlock_irqrestore(&dd->cspec->rcvmod_lock, flags);
  5687. /* Initialize QP to context mapping */
  5688. regno = krp_rcvqpmaptable;
  5689. val = 0;
  5690. if (dd->num_pports > 1)
  5691. n = dd->first_user_ctxt / dd->num_pports;
  5692. else
  5693. n = dd->first_user_ctxt - 1;
  5694. for (i = 0; i < 32; ) {
  5695. unsigned ctxt;
  5696. if (dd->num_pports > 1)
  5697. ctxt = (i % n) * dd->num_pports + pidx;
  5698. else if (i % n)
  5699. ctxt = (i % n) + 1;
  5700. else
  5701. ctxt = ppd->hw_pidx;
  5702. val |= ctxt << (5 * (i % 6));
  5703. i++;
  5704. if (i % 6 == 0) {
  5705. qib_write_kreg_port(ppd, regno, val);
  5706. val = 0;
  5707. regno++;
  5708. }
  5709. }
  5710. qib_write_kreg_port(ppd, regno, val);
  5711. }
  5712. /*
  5713. * Setup up interrupt mitigation for kernel contexts, but
  5714. * not user contexts (user contexts use interrupts when
  5715. * stalled waiting for any packet, so want those interrupts
  5716. * right away).
  5717. */
  5718. for (i = 0; i < dd->first_user_ctxt; i++) {
  5719. dd->cspec->rcvavail_timeout[i] = rcv_int_timeout;
  5720. qib_write_kreg(dd, kr_rcvavailtimeout + i, rcv_int_timeout);
  5721. }
  5722. /*
  5723. * Initialize as (disabled) rcvflow tables. Application code
  5724. * will setup each flow as it uses the flow.
  5725. * Doesn't clear any of the error bits that might be set.
  5726. */
  5727. val = TIDFLOW_ERRBITS; /* these are W1C */
  5728. for (i = 0; i < dd->cfgctxts; i++) {
  5729. int flow;
  5730. for (flow = 0; flow < NUM_TIDFLOWS_CTXT; flow++)
  5731. qib_write_ureg(dd, ur_rcvflowtable+flow, val, i);
  5732. }
  5733. /*
  5734. * dual cards init to dual port recovery, single port cards to
  5735. * the one port. Dual port cards may later adjust to 1 port,
  5736. * and then back to dual port if both ports are connected
  5737. * */
  5738. if (dd->num_pports)
  5739. setup_7322_link_recovery(dd->pport, dd->num_pports > 1);
  5740. }
  5741. static int qib_init_7322_variables(struct qib_devdata *dd)
  5742. {
  5743. struct qib_pportdata *ppd;
  5744. unsigned features, pidx, sbufcnt;
  5745. int ret, mtu;
  5746. u32 sbufs, updthresh;
  5747. /* pport structs are contiguous, allocated after devdata */
  5748. ppd = (struct qib_pportdata *)(dd + 1);
  5749. dd->pport = ppd;
  5750. ppd[0].dd = dd;
  5751. ppd[1].dd = dd;
  5752. dd->cspec = (struct qib_chip_specific *)(ppd + 2);
  5753. ppd[0].cpspec = (struct qib_chippport_specific *)(dd->cspec + 1);
  5754. ppd[1].cpspec = &ppd[0].cpspec[1];
  5755. ppd[0].cpspec->ppd = &ppd[0]; /* for autoneg_7322_work() */
  5756. ppd[1].cpspec->ppd = &ppd[1]; /* for autoneg_7322_work() */
  5757. spin_lock_init(&dd->cspec->rcvmod_lock);
  5758. spin_lock_init(&dd->cspec->gpio_lock);
  5759. /* we haven't yet set QIB_PRESENT, so use read directly */
  5760. dd->revision = readq(&dd->kregbase[kr_revision]);
  5761. if ((dd->revision & 0xffffffffU) == 0xffffffffU) {
  5762. qib_dev_err(dd,
  5763. "Revision register read failure, giving up initialization\n");
  5764. ret = -ENODEV;
  5765. goto bail;
  5766. }
  5767. dd->flags |= QIB_PRESENT; /* now register routines work */
  5768. dd->majrev = (u8) SYM_FIELD(dd->revision, Revision_R, ChipRevMajor);
  5769. dd->minrev = (u8) SYM_FIELD(dd->revision, Revision_R, ChipRevMinor);
  5770. dd->cspec->r1 = dd->minrev == 1;
  5771. get_7322_chip_params(dd);
  5772. features = qib_7322_boardname(dd);
  5773. /* now that piobcnt2k and 4k set, we can allocate these */
  5774. sbufcnt = dd->piobcnt2k + dd->piobcnt4k +
  5775. NUM_VL15_BUFS + BITS_PER_LONG - 1;
  5776. sbufcnt /= BITS_PER_LONG;
  5777. dd->cspec->sendchkenable = kmalloc(sbufcnt *
  5778. sizeof(*dd->cspec->sendchkenable), GFP_KERNEL);
  5779. dd->cspec->sendgrhchk = kmalloc(sbufcnt *
  5780. sizeof(*dd->cspec->sendgrhchk), GFP_KERNEL);
  5781. dd->cspec->sendibchk = kmalloc(sbufcnt *
  5782. sizeof(*dd->cspec->sendibchk), GFP_KERNEL);
  5783. if (!dd->cspec->sendchkenable || !dd->cspec->sendgrhchk ||
  5784. !dd->cspec->sendibchk) {
  5785. qib_dev_err(dd, "Failed allocation for hdrchk bitmaps\n");
  5786. ret = -ENOMEM;
  5787. goto bail;
  5788. }
  5789. ppd = dd->pport;
  5790. /*
  5791. * GPIO bits for TWSI data and clock,
  5792. * used for serial EEPROM.
  5793. */
  5794. dd->gpio_sda_num = _QIB_GPIO_SDA_NUM;
  5795. dd->gpio_scl_num = _QIB_GPIO_SCL_NUM;
  5796. dd->twsi_eeprom_dev = QIB_TWSI_EEPROM_DEV;
  5797. dd->flags |= QIB_HAS_INTX | QIB_HAS_LINK_LATENCY |
  5798. QIB_NODMA_RTAIL | QIB_HAS_VLSUPP | QIB_HAS_HDRSUPP |
  5799. QIB_HAS_THRESH_UPDATE |
  5800. (sdma_idle_cnt ? QIB_HAS_SDMA_TIMEOUT : 0);
  5801. dd->flags |= qib_special_trigger ?
  5802. QIB_USE_SPCL_TRIG : QIB_HAS_SEND_DMA;
  5803. /*
  5804. * Setup initial values. These may change when PAT is enabled, but
  5805. * we need these to do initial chip register accesses.
  5806. */
  5807. qib_7322_set_baseaddrs(dd);
  5808. mtu = ib_mtu_enum_to_int(qib_ibmtu);
  5809. if (mtu == -1)
  5810. mtu = QIB_DEFAULT_MTU;
  5811. dd->cspec->int_enable_mask = QIB_I_BITSEXTANT;
  5812. /* all hwerrors become interrupts, unless special purposed */
  5813. dd->cspec->hwerrmask = ~0ULL;
  5814. /* link_recovery setup causes these errors, so ignore them,
  5815. * other than clearing them when they occur */
  5816. dd->cspec->hwerrmask &=
  5817. ~(SYM_MASK(HwErrMask, IBSerdesPClkNotDetectMask_0) |
  5818. SYM_MASK(HwErrMask, IBSerdesPClkNotDetectMask_1) |
  5819. HWE_MASK(LATriggered));
  5820. for (pidx = 0; pidx < NUM_IB_PORTS; ++pidx) {
  5821. struct qib_chippport_specific *cp = ppd->cpspec;
  5822. ppd->link_speed_supported = features & PORT_SPD_CAP;
  5823. features >>= PORT_SPD_CAP_SHIFT;
  5824. if (!ppd->link_speed_supported) {
  5825. /* single port mode (7340, or configured) */
  5826. dd->skip_kctxt_mask |= 1 << pidx;
  5827. if (pidx == 0) {
  5828. /* Make sure port is disabled. */
  5829. qib_write_kreg_port(ppd, krp_rcvctrl, 0);
  5830. qib_write_kreg_port(ppd, krp_ibcctrl_a, 0);
  5831. ppd[0] = ppd[1];
  5832. dd->cspec->hwerrmask &= ~(SYM_MASK(HwErrMask,
  5833. IBSerdesPClkNotDetectMask_0)
  5834. | SYM_MASK(HwErrMask,
  5835. SDmaMemReadErrMask_0));
  5836. dd->cspec->int_enable_mask &= ~(
  5837. SYM_MASK(IntMask, SDmaCleanupDoneMask_0) |
  5838. SYM_MASK(IntMask, SDmaIdleIntMask_0) |
  5839. SYM_MASK(IntMask, SDmaProgressIntMask_0) |
  5840. SYM_MASK(IntMask, SDmaIntMask_0) |
  5841. SYM_MASK(IntMask, ErrIntMask_0) |
  5842. SYM_MASK(IntMask, SendDoneIntMask_0));
  5843. } else {
  5844. /* Make sure port is disabled. */
  5845. qib_write_kreg_port(ppd, krp_rcvctrl, 0);
  5846. qib_write_kreg_port(ppd, krp_ibcctrl_a, 0);
  5847. dd->cspec->hwerrmask &= ~(SYM_MASK(HwErrMask,
  5848. IBSerdesPClkNotDetectMask_1)
  5849. | SYM_MASK(HwErrMask,
  5850. SDmaMemReadErrMask_1));
  5851. dd->cspec->int_enable_mask &= ~(
  5852. SYM_MASK(IntMask, SDmaCleanupDoneMask_1) |
  5853. SYM_MASK(IntMask, SDmaIdleIntMask_1) |
  5854. SYM_MASK(IntMask, SDmaProgressIntMask_1) |
  5855. SYM_MASK(IntMask, SDmaIntMask_1) |
  5856. SYM_MASK(IntMask, ErrIntMask_1) |
  5857. SYM_MASK(IntMask, SendDoneIntMask_1));
  5858. }
  5859. continue;
  5860. }
  5861. dd->num_pports++;
  5862. ret = qib_init_pportdata(ppd, dd, pidx, dd->num_pports);
  5863. if (ret) {
  5864. dd->num_pports--;
  5865. goto bail;
  5866. }
  5867. ppd->link_width_supported = IB_WIDTH_1X | IB_WIDTH_4X;
  5868. ppd->link_width_enabled = IB_WIDTH_4X;
  5869. ppd->link_speed_enabled = ppd->link_speed_supported;
  5870. /*
  5871. * Set the initial values to reasonable default, will be set
  5872. * for real when link is up.
  5873. */
  5874. ppd->link_width_active = IB_WIDTH_4X;
  5875. ppd->link_speed_active = QIB_IB_SDR;
  5876. ppd->delay_mult = ib_rate_to_delay[IB_RATE_10_GBPS];
  5877. switch (qib_num_cfg_vls) {
  5878. case 1:
  5879. ppd->vls_supported = IB_VL_VL0;
  5880. break;
  5881. case 2:
  5882. ppd->vls_supported = IB_VL_VL0_1;
  5883. break;
  5884. default:
  5885. qib_devinfo(dd->pcidev,
  5886. "Invalid num_vls %u, using 4 VLs\n",
  5887. qib_num_cfg_vls);
  5888. qib_num_cfg_vls = 4;
  5889. /* fall through */
  5890. case 4:
  5891. ppd->vls_supported = IB_VL_VL0_3;
  5892. break;
  5893. case 8:
  5894. if (mtu <= 2048)
  5895. ppd->vls_supported = IB_VL_VL0_7;
  5896. else {
  5897. qib_devinfo(dd->pcidev,
  5898. "Invalid num_vls %u for MTU %d "
  5899. ", using 4 VLs\n",
  5900. qib_num_cfg_vls, mtu);
  5901. ppd->vls_supported = IB_VL_VL0_3;
  5902. qib_num_cfg_vls = 4;
  5903. }
  5904. break;
  5905. }
  5906. ppd->vls_operational = ppd->vls_supported;
  5907. init_waitqueue_head(&cp->autoneg_wait);
  5908. INIT_DELAYED_WORK(&cp->autoneg_work,
  5909. autoneg_7322_work);
  5910. if (ppd->dd->cspec->r1)
  5911. INIT_DELAYED_WORK(&cp->ipg_work, ipg_7322_work);
  5912. /*
  5913. * For Mez and similar cards, no qsfp info, so do
  5914. * the "cable info" setup here. Can be overridden
  5915. * in adapter-specific routines.
  5916. */
  5917. if (!(dd->flags & QIB_HAS_QSFP)) {
  5918. if (!IS_QMH(dd) && !IS_QME(dd))
  5919. qib_devinfo(dd->pcidev,
  5920. "IB%u:%u: Unknown mezzanine card type\n",
  5921. dd->unit, ppd->port);
  5922. cp->h1_val = IS_QMH(dd) ? H1_FORCE_QMH : H1_FORCE_QME;
  5923. /*
  5924. * Choose center value as default tx serdes setting
  5925. * until changed through module parameter.
  5926. */
  5927. ppd->cpspec->no_eep = IS_QMH(dd) ?
  5928. TXDDS_TABLE_SZ + 2 : TXDDS_TABLE_SZ + 4;
  5929. } else
  5930. cp->h1_val = H1_FORCE_VAL;
  5931. /* Avoid writes to chip for mini_init */
  5932. if (!qib_mini_init)
  5933. write_7322_init_portregs(ppd);
  5934. init_timer(&cp->chase_timer);
  5935. cp->chase_timer.function = reenable_chase;
  5936. cp->chase_timer.data = (unsigned long)ppd;
  5937. ppd++;
  5938. }
  5939. dd->rcvhdrentsize = qib_rcvhdrentsize ?
  5940. qib_rcvhdrentsize : QIB_RCVHDR_ENTSIZE;
  5941. dd->rcvhdrsize = qib_rcvhdrsize ?
  5942. qib_rcvhdrsize : QIB_DFLT_RCVHDRSIZE;
  5943. dd->rhf_offset = dd->rcvhdrentsize - sizeof(u64) / sizeof(u32);
  5944. /* we always allocate at least 2048 bytes for eager buffers */
  5945. dd->rcvegrbufsize = max(mtu, 2048);
  5946. BUG_ON(!is_power_of_2(dd->rcvegrbufsize));
  5947. dd->rcvegrbufsize_shift = ilog2(dd->rcvegrbufsize);
  5948. qib_7322_tidtemplate(dd);
  5949. /*
  5950. * We can request a receive interrupt for 1 or
  5951. * more packets from current offset.
  5952. */
  5953. dd->rhdrhead_intr_off =
  5954. (u64) rcv_int_count << IBA7322_HDRHEAD_PKTINT_SHIFT;
  5955. /* setup the stats timer; the add_timer is done at end of init */
  5956. init_timer(&dd->stats_timer);
  5957. dd->stats_timer.function = qib_get_7322_faststats;
  5958. dd->stats_timer.data = (unsigned long) dd;
  5959. dd->ureg_align = 0x10000; /* 64KB alignment */
  5960. dd->piosize2kmax_dwords = dd->piosize2k >> 2;
  5961. qib_7322_config_ctxts(dd);
  5962. qib_set_ctxtcnt(dd);
  5963. if (qib_wc_pat) {
  5964. resource_size_t vl15off;
  5965. /*
  5966. * We do not set WC on the VL15 buffers to avoid
  5967. * a rare problem with unaligned writes from
  5968. * interrupt-flushed store buffers, so we need
  5969. * to map those separately here. We can't solve
  5970. * this for the rarely used mtrr case.
  5971. */
  5972. ret = init_chip_wc_pat(dd, 0);
  5973. if (ret)
  5974. goto bail;
  5975. /* vl15 buffers start just after the 4k buffers */
  5976. vl15off = dd->physaddr + (dd->piobufbase >> 32) +
  5977. dd->piobcnt4k * dd->align4k;
  5978. dd->piovl15base = ioremap_nocache(vl15off,
  5979. NUM_VL15_BUFS * dd->align4k);
  5980. if (!dd->piovl15base) {
  5981. ret = -ENOMEM;
  5982. goto bail;
  5983. }
  5984. }
  5985. qib_7322_set_baseaddrs(dd); /* set chip access pointers now */
  5986. ret = 0;
  5987. if (qib_mini_init)
  5988. goto bail;
  5989. if (!dd->num_pports) {
  5990. qib_dev_err(dd, "No ports enabled, giving up initialization\n");
  5991. goto bail; /* no error, so can still figure out why err */
  5992. }
  5993. write_7322_initregs(dd);
  5994. ret = qib_create_ctxts(dd);
  5995. init_7322_cntrnames(dd);
  5996. updthresh = 8U; /* update threshold */
  5997. /* use all of 4KB buffers for the kernel SDMA, zero if !SDMA.
  5998. * reserve the update threshold amount for other kernel use, such
  5999. * as sending SMI, MAD, and ACKs, or 3, whichever is greater,
  6000. * unless we aren't enabling SDMA, in which case we want to use
  6001. * all the 4k bufs for the kernel.
  6002. * if this was less than the update threshold, we could wait
  6003. * a long time for an update. Coded this way because we
  6004. * sometimes change the update threshold for various reasons,
  6005. * and we want this to remain robust.
  6006. */
  6007. if (dd->flags & QIB_HAS_SEND_DMA) {
  6008. dd->cspec->sdmabufcnt = dd->piobcnt4k;
  6009. sbufs = updthresh > 3 ? updthresh : 3;
  6010. } else {
  6011. dd->cspec->sdmabufcnt = 0;
  6012. sbufs = dd->piobcnt4k;
  6013. }
  6014. dd->cspec->lastbuf_for_pio = dd->piobcnt2k + dd->piobcnt4k -
  6015. dd->cspec->sdmabufcnt;
  6016. dd->lastctxt_piobuf = dd->cspec->lastbuf_for_pio - sbufs;
  6017. dd->cspec->lastbuf_for_pio--; /* range is <= , not < */
  6018. dd->last_pio = dd->cspec->lastbuf_for_pio;
  6019. dd->pbufsctxt = (dd->cfgctxts > dd->first_user_ctxt) ?
  6020. dd->lastctxt_piobuf / (dd->cfgctxts - dd->first_user_ctxt) : 0;
  6021. /*
  6022. * If we have 16 user contexts, we will have 7 sbufs
  6023. * per context, so reduce the update threshold to match. We
  6024. * want to update before we actually run out, at low pbufs/ctxt
  6025. * so give ourselves some margin.
  6026. */
  6027. if (dd->pbufsctxt >= 2 && dd->pbufsctxt - 2 < updthresh)
  6028. updthresh = dd->pbufsctxt - 2;
  6029. dd->cspec->updthresh_dflt = updthresh;
  6030. dd->cspec->updthresh = updthresh;
  6031. /* before full enable, no interrupts, no locking needed */
  6032. dd->sendctrl |= ((updthresh & SYM_RMASK(SendCtrl, AvailUpdThld))
  6033. << SYM_LSB(SendCtrl, AvailUpdThld)) |
  6034. SYM_MASK(SendCtrl, SendBufAvailPad64Byte);
  6035. dd->psxmitwait_supported = 1;
  6036. dd->psxmitwait_check_rate = QIB_7322_PSXMITWAIT_CHECK_RATE;
  6037. bail:
  6038. if (!dd->ctxtcnt)
  6039. dd->ctxtcnt = 1; /* for other initialization code */
  6040. return ret;
  6041. }
  6042. static u32 __iomem *qib_7322_getsendbuf(struct qib_pportdata *ppd, u64 pbc,
  6043. u32 *pbufnum)
  6044. {
  6045. u32 first, last, plen = pbc & QIB_PBC_LENGTH_MASK;
  6046. struct qib_devdata *dd = ppd->dd;
  6047. /* last is same for 2k and 4k, because we use 4k if all 2k busy */
  6048. if (pbc & PBC_7322_VL15_SEND) {
  6049. first = dd->piobcnt2k + dd->piobcnt4k + ppd->hw_pidx;
  6050. last = first;
  6051. } else {
  6052. if ((plen + 1) > dd->piosize2kmax_dwords)
  6053. first = dd->piobcnt2k;
  6054. else
  6055. first = 0;
  6056. last = dd->cspec->lastbuf_for_pio;
  6057. }
  6058. return qib_getsendbuf_range(dd, pbufnum, first, last);
  6059. }
  6060. static void qib_set_cntr_7322_sample(struct qib_pportdata *ppd, u32 intv,
  6061. u32 start)
  6062. {
  6063. qib_write_kreg_port(ppd, krp_psinterval, intv);
  6064. qib_write_kreg_port(ppd, krp_psstart, start);
  6065. }
  6066. /*
  6067. * Must be called with sdma_lock held, or before init finished.
  6068. */
  6069. static void qib_sdma_set_7322_desc_cnt(struct qib_pportdata *ppd, unsigned cnt)
  6070. {
  6071. qib_write_kreg_port(ppd, krp_senddmadesccnt, cnt);
  6072. }
  6073. /*
  6074. * sdma_lock should be acquired before calling this routine
  6075. */
  6076. static void dump_sdma_7322_state(struct qib_pportdata *ppd)
  6077. {
  6078. u64 reg, reg1, reg2;
  6079. reg = qib_read_kreg_port(ppd, krp_senddmastatus);
  6080. qib_dev_porterr(ppd->dd, ppd->port,
  6081. "SDMA senddmastatus: 0x%016llx\n", reg);
  6082. reg = qib_read_kreg_port(ppd, krp_sendctrl);
  6083. qib_dev_porterr(ppd->dd, ppd->port,
  6084. "SDMA sendctrl: 0x%016llx\n", reg);
  6085. reg = qib_read_kreg_port(ppd, krp_senddmabase);
  6086. qib_dev_porterr(ppd->dd, ppd->port,
  6087. "SDMA senddmabase: 0x%016llx\n", reg);
  6088. reg = qib_read_kreg_port(ppd, krp_senddmabufmask0);
  6089. reg1 = qib_read_kreg_port(ppd, krp_senddmabufmask1);
  6090. reg2 = qib_read_kreg_port(ppd, krp_senddmabufmask2);
  6091. qib_dev_porterr(ppd->dd, ppd->port,
  6092. "SDMA senddmabufmask 0:%llx 1:%llx 2:%llx\n",
  6093. reg, reg1, reg2);
  6094. /* get bufuse bits, clear them, and print them again if non-zero */
  6095. reg = qib_read_kreg_port(ppd, krp_senddmabuf_use0);
  6096. qib_write_kreg_port(ppd, krp_senddmabuf_use0, reg);
  6097. reg1 = qib_read_kreg_port(ppd, krp_senddmabuf_use1);
  6098. qib_write_kreg_port(ppd, krp_senddmabuf_use0, reg1);
  6099. reg2 = qib_read_kreg_port(ppd, krp_senddmabuf_use2);
  6100. qib_write_kreg_port(ppd, krp_senddmabuf_use0, reg2);
  6101. /* 0 and 1 should always be zero, so print as short form */
  6102. qib_dev_porterr(ppd->dd, ppd->port,
  6103. "SDMA current senddmabuf_use 0:%llx 1:%llx 2:%llx\n",
  6104. reg, reg1, reg2);
  6105. reg = qib_read_kreg_port(ppd, krp_senddmabuf_use0);
  6106. reg1 = qib_read_kreg_port(ppd, krp_senddmabuf_use1);
  6107. reg2 = qib_read_kreg_port(ppd, krp_senddmabuf_use2);
  6108. /* 0 and 1 should always be zero, so print as short form */
  6109. qib_dev_porterr(ppd->dd, ppd->port,
  6110. "SDMA cleared senddmabuf_use 0:%llx 1:%llx 2:%llx\n",
  6111. reg, reg1, reg2);
  6112. reg = qib_read_kreg_port(ppd, krp_senddmatail);
  6113. qib_dev_porterr(ppd->dd, ppd->port,
  6114. "SDMA senddmatail: 0x%016llx\n", reg);
  6115. reg = qib_read_kreg_port(ppd, krp_senddmahead);
  6116. qib_dev_porterr(ppd->dd, ppd->port,
  6117. "SDMA senddmahead: 0x%016llx\n", reg);
  6118. reg = qib_read_kreg_port(ppd, krp_senddmaheadaddr);
  6119. qib_dev_porterr(ppd->dd, ppd->port,
  6120. "SDMA senddmaheadaddr: 0x%016llx\n", reg);
  6121. reg = qib_read_kreg_port(ppd, krp_senddmalengen);
  6122. qib_dev_porterr(ppd->dd, ppd->port,
  6123. "SDMA senddmalengen: 0x%016llx\n", reg);
  6124. reg = qib_read_kreg_port(ppd, krp_senddmadesccnt);
  6125. qib_dev_porterr(ppd->dd, ppd->port,
  6126. "SDMA senddmadesccnt: 0x%016llx\n", reg);
  6127. reg = qib_read_kreg_port(ppd, krp_senddmaidlecnt);
  6128. qib_dev_porterr(ppd->dd, ppd->port,
  6129. "SDMA senddmaidlecnt: 0x%016llx\n", reg);
  6130. reg = qib_read_kreg_port(ppd, krp_senddmaprioritythld);
  6131. qib_dev_porterr(ppd->dd, ppd->port,
  6132. "SDMA senddmapriorityhld: 0x%016llx\n", reg);
  6133. reg = qib_read_kreg_port(ppd, krp_senddmareloadcnt);
  6134. qib_dev_porterr(ppd->dd, ppd->port,
  6135. "SDMA senddmareloadcnt: 0x%016llx\n", reg);
  6136. dump_sdma_state(ppd);
  6137. }
  6138. static struct sdma_set_state_action sdma_7322_action_table[] = {
  6139. [qib_sdma_state_s00_hw_down] = {
  6140. .go_s99_running_tofalse = 1,
  6141. .op_enable = 0,
  6142. .op_intenable = 0,
  6143. .op_halt = 0,
  6144. .op_drain = 0,
  6145. },
  6146. [qib_sdma_state_s10_hw_start_up_wait] = {
  6147. .op_enable = 0,
  6148. .op_intenable = 1,
  6149. .op_halt = 1,
  6150. .op_drain = 0,
  6151. },
  6152. [qib_sdma_state_s20_idle] = {
  6153. .op_enable = 1,
  6154. .op_intenable = 1,
  6155. .op_halt = 1,
  6156. .op_drain = 0,
  6157. },
  6158. [qib_sdma_state_s30_sw_clean_up_wait] = {
  6159. .op_enable = 0,
  6160. .op_intenable = 1,
  6161. .op_halt = 1,
  6162. .op_drain = 0,
  6163. },
  6164. [qib_sdma_state_s40_hw_clean_up_wait] = {
  6165. .op_enable = 1,
  6166. .op_intenable = 1,
  6167. .op_halt = 1,
  6168. .op_drain = 0,
  6169. },
  6170. [qib_sdma_state_s50_hw_halt_wait] = {
  6171. .op_enable = 1,
  6172. .op_intenable = 1,
  6173. .op_halt = 1,
  6174. .op_drain = 1,
  6175. },
  6176. [qib_sdma_state_s99_running] = {
  6177. .op_enable = 1,
  6178. .op_intenable = 1,
  6179. .op_halt = 0,
  6180. .op_drain = 0,
  6181. .go_s99_running_totrue = 1,
  6182. },
  6183. };
  6184. static void qib_7322_sdma_init_early(struct qib_pportdata *ppd)
  6185. {
  6186. ppd->sdma_state.set_state_action = sdma_7322_action_table;
  6187. }
  6188. static int init_sdma_7322_regs(struct qib_pportdata *ppd)
  6189. {
  6190. struct qib_devdata *dd = ppd->dd;
  6191. unsigned lastbuf, erstbuf;
  6192. u64 senddmabufmask[3] = { 0 };
  6193. int n, ret = 0;
  6194. qib_write_kreg_port(ppd, krp_senddmabase, ppd->sdma_descq_phys);
  6195. qib_sdma_7322_setlengen(ppd);
  6196. qib_sdma_update_7322_tail(ppd, 0); /* Set SendDmaTail */
  6197. qib_write_kreg_port(ppd, krp_senddmareloadcnt, sdma_idle_cnt);
  6198. qib_write_kreg_port(ppd, krp_senddmadesccnt, 0);
  6199. qib_write_kreg_port(ppd, krp_senddmaheadaddr, ppd->sdma_head_phys);
  6200. if (dd->num_pports)
  6201. n = dd->cspec->sdmabufcnt / dd->num_pports; /* no remainder */
  6202. else
  6203. n = dd->cspec->sdmabufcnt; /* failsafe for init */
  6204. erstbuf = (dd->piobcnt2k + dd->piobcnt4k) -
  6205. ((dd->num_pports == 1 || ppd->port == 2) ? n :
  6206. dd->cspec->sdmabufcnt);
  6207. lastbuf = erstbuf + n;
  6208. ppd->sdma_state.first_sendbuf = erstbuf;
  6209. ppd->sdma_state.last_sendbuf = lastbuf;
  6210. for (; erstbuf < lastbuf; ++erstbuf) {
  6211. unsigned word = erstbuf / BITS_PER_LONG;
  6212. unsigned bit = erstbuf & (BITS_PER_LONG - 1);
  6213. BUG_ON(word >= 3);
  6214. senddmabufmask[word] |= 1ULL << bit;
  6215. }
  6216. qib_write_kreg_port(ppd, krp_senddmabufmask0, senddmabufmask[0]);
  6217. qib_write_kreg_port(ppd, krp_senddmabufmask1, senddmabufmask[1]);
  6218. qib_write_kreg_port(ppd, krp_senddmabufmask2, senddmabufmask[2]);
  6219. return ret;
  6220. }
  6221. /* sdma_lock must be held */
  6222. static u16 qib_sdma_7322_gethead(struct qib_pportdata *ppd)
  6223. {
  6224. struct qib_devdata *dd = ppd->dd;
  6225. int sane;
  6226. int use_dmahead;
  6227. u16 swhead;
  6228. u16 swtail;
  6229. u16 cnt;
  6230. u16 hwhead;
  6231. use_dmahead = __qib_sdma_running(ppd) &&
  6232. (dd->flags & QIB_HAS_SDMA_TIMEOUT);
  6233. retry:
  6234. hwhead = use_dmahead ?
  6235. (u16) le64_to_cpu(*ppd->sdma_head_dma) :
  6236. (u16) qib_read_kreg_port(ppd, krp_senddmahead);
  6237. swhead = ppd->sdma_descq_head;
  6238. swtail = ppd->sdma_descq_tail;
  6239. cnt = ppd->sdma_descq_cnt;
  6240. if (swhead < swtail)
  6241. /* not wrapped */
  6242. sane = (hwhead >= swhead) & (hwhead <= swtail);
  6243. else if (swhead > swtail)
  6244. /* wrapped around */
  6245. sane = ((hwhead >= swhead) && (hwhead < cnt)) ||
  6246. (hwhead <= swtail);
  6247. else
  6248. /* empty */
  6249. sane = (hwhead == swhead);
  6250. if (unlikely(!sane)) {
  6251. if (use_dmahead) {
  6252. /* try one more time, directly from the register */
  6253. use_dmahead = 0;
  6254. goto retry;
  6255. }
  6256. /* proceed as if no progress */
  6257. hwhead = swhead;
  6258. }
  6259. return hwhead;
  6260. }
  6261. static int qib_sdma_7322_busy(struct qib_pportdata *ppd)
  6262. {
  6263. u64 hwstatus = qib_read_kreg_port(ppd, krp_senddmastatus);
  6264. return (hwstatus & SYM_MASK(SendDmaStatus_0, ScoreBoardDrainInProg)) ||
  6265. (hwstatus & SYM_MASK(SendDmaStatus_0, HaltInProg)) ||
  6266. !(hwstatus & SYM_MASK(SendDmaStatus_0, InternalSDmaHalt)) ||
  6267. !(hwstatus & SYM_MASK(SendDmaStatus_0, ScbEmpty));
  6268. }
  6269. /*
  6270. * Compute the amount of delay before sending the next packet if the
  6271. * port's send rate differs from the static rate set for the QP.
  6272. * The delay affects the next packet and the amount of the delay is
  6273. * based on the length of the this packet.
  6274. */
  6275. static u32 qib_7322_setpbc_control(struct qib_pportdata *ppd, u32 plen,
  6276. u8 srate, u8 vl)
  6277. {
  6278. u8 snd_mult = ppd->delay_mult;
  6279. u8 rcv_mult = ib_rate_to_delay[srate];
  6280. u32 ret;
  6281. ret = rcv_mult > snd_mult ? ((plen + 1) >> 1) * snd_mult : 0;
  6282. /* Indicate VL15, else set the VL in the control word */
  6283. if (vl == 15)
  6284. ret |= PBC_7322_VL15_SEND_CTRL;
  6285. else
  6286. ret |= vl << PBC_VL_NUM_LSB;
  6287. ret |= ((u32)(ppd->hw_pidx)) << PBC_PORT_SEL_LSB;
  6288. return ret;
  6289. }
  6290. /*
  6291. * Enable the per-port VL15 send buffers for use.
  6292. * They follow the rest of the buffers, without a config parameter.
  6293. * This was in initregs, but that is done before the shadow
  6294. * is set up, and this has to be done after the shadow is
  6295. * set up.
  6296. */
  6297. static void qib_7322_initvl15_bufs(struct qib_devdata *dd)
  6298. {
  6299. unsigned vl15bufs;
  6300. vl15bufs = dd->piobcnt2k + dd->piobcnt4k;
  6301. qib_chg_pioavailkernel(dd, vl15bufs, NUM_VL15_BUFS,
  6302. TXCHK_CHG_TYPE_KERN, NULL);
  6303. }
  6304. static void qib_7322_init_ctxt(struct qib_ctxtdata *rcd)
  6305. {
  6306. if (rcd->ctxt < NUM_IB_PORTS) {
  6307. if (rcd->dd->num_pports > 1) {
  6308. rcd->rcvegrcnt = KCTXT0_EGRCNT / 2;
  6309. rcd->rcvegr_tid_base = rcd->ctxt ? rcd->rcvegrcnt : 0;
  6310. } else {
  6311. rcd->rcvegrcnt = KCTXT0_EGRCNT;
  6312. rcd->rcvegr_tid_base = 0;
  6313. }
  6314. } else {
  6315. rcd->rcvegrcnt = rcd->dd->cspec->rcvegrcnt;
  6316. rcd->rcvegr_tid_base = KCTXT0_EGRCNT +
  6317. (rcd->ctxt - NUM_IB_PORTS) * rcd->rcvegrcnt;
  6318. }
  6319. }
  6320. #define QTXSLEEPS 5000
  6321. static void qib_7322_txchk_change(struct qib_devdata *dd, u32 start,
  6322. u32 len, u32 which, struct qib_ctxtdata *rcd)
  6323. {
  6324. int i;
  6325. const int last = start + len - 1;
  6326. const int lastr = last / BITS_PER_LONG;
  6327. u32 sleeps = 0;
  6328. int wait = rcd != NULL;
  6329. unsigned long flags;
  6330. while (wait) {
  6331. unsigned long shadow;
  6332. int cstart, previ = -1;
  6333. /*
  6334. * when flipping from kernel to user, we can't change
  6335. * the checking type if the buffer is allocated to the
  6336. * driver. It's OK the other direction, because it's
  6337. * from close, and we have just disarm'ed all the
  6338. * buffers. All the kernel to kernel changes are also
  6339. * OK.
  6340. */
  6341. for (cstart = start; cstart <= last; cstart++) {
  6342. i = ((2 * cstart) + QLOGIC_IB_SENDPIOAVAIL_BUSY_SHIFT)
  6343. / BITS_PER_LONG;
  6344. if (i != previ) {
  6345. shadow = (unsigned long)
  6346. le64_to_cpu(dd->pioavailregs_dma[i]);
  6347. previ = i;
  6348. }
  6349. if (test_bit(((2 * cstart) +
  6350. QLOGIC_IB_SENDPIOAVAIL_BUSY_SHIFT)
  6351. % BITS_PER_LONG, &shadow))
  6352. break;
  6353. }
  6354. if (cstart > last)
  6355. break;
  6356. if (sleeps == QTXSLEEPS)
  6357. break;
  6358. /* make sure we see an updated copy next time around */
  6359. sendctrl_7322_mod(dd->pport, QIB_SENDCTRL_AVAIL_BLIP);
  6360. sleeps++;
  6361. msleep(20);
  6362. }
  6363. switch (which) {
  6364. case TXCHK_CHG_TYPE_DIS1:
  6365. /*
  6366. * disable checking on a range; used by diags; just
  6367. * one buffer, but still written generically
  6368. */
  6369. for (i = start; i <= last; i++)
  6370. clear_bit(i, dd->cspec->sendchkenable);
  6371. break;
  6372. case TXCHK_CHG_TYPE_ENAB1:
  6373. /*
  6374. * (re)enable checking on a range; used by diags; just
  6375. * one buffer, but still written generically; read
  6376. * scratch to be sure buffer actually triggered, not
  6377. * just flushed from processor.
  6378. */
  6379. qib_read_kreg32(dd, kr_scratch);
  6380. for (i = start; i <= last; i++)
  6381. set_bit(i, dd->cspec->sendchkenable);
  6382. break;
  6383. case TXCHK_CHG_TYPE_KERN:
  6384. /* usable by kernel */
  6385. for (i = start; i <= last; i++) {
  6386. set_bit(i, dd->cspec->sendibchk);
  6387. clear_bit(i, dd->cspec->sendgrhchk);
  6388. }
  6389. spin_lock_irqsave(&dd->uctxt_lock, flags);
  6390. /* see if we need to raise avail update threshold */
  6391. for (i = dd->first_user_ctxt;
  6392. dd->cspec->updthresh != dd->cspec->updthresh_dflt
  6393. && i < dd->cfgctxts; i++)
  6394. if (dd->rcd[i] && dd->rcd[i]->subctxt_cnt &&
  6395. ((dd->rcd[i]->piocnt / dd->rcd[i]->subctxt_cnt) - 1)
  6396. < dd->cspec->updthresh_dflt)
  6397. break;
  6398. spin_unlock_irqrestore(&dd->uctxt_lock, flags);
  6399. if (i == dd->cfgctxts) {
  6400. spin_lock_irqsave(&dd->sendctrl_lock, flags);
  6401. dd->cspec->updthresh = dd->cspec->updthresh_dflt;
  6402. dd->sendctrl &= ~SYM_MASK(SendCtrl, AvailUpdThld);
  6403. dd->sendctrl |= (dd->cspec->updthresh &
  6404. SYM_RMASK(SendCtrl, AvailUpdThld)) <<
  6405. SYM_LSB(SendCtrl, AvailUpdThld);
  6406. spin_unlock_irqrestore(&dd->sendctrl_lock, flags);
  6407. sendctrl_7322_mod(dd->pport, QIB_SENDCTRL_AVAIL_BLIP);
  6408. }
  6409. break;
  6410. case TXCHK_CHG_TYPE_USER:
  6411. /* for user process */
  6412. for (i = start; i <= last; i++) {
  6413. clear_bit(i, dd->cspec->sendibchk);
  6414. set_bit(i, dd->cspec->sendgrhchk);
  6415. }
  6416. spin_lock_irqsave(&dd->sendctrl_lock, flags);
  6417. if (rcd && rcd->subctxt_cnt && ((rcd->piocnt
  6418. / rcd->subctxt_cnt) - 1) < dd->cspec->updthresh) {
  6419. dd->cspec->updthresh = (rcd->piocnt /
  6420. rcd->subctxt_cnt) - 1;
  6421. dd->sendctrl &= ~SYM_MASK(SendCtrl, AvailUpdThld);
  6422. dd->sendctrl |= (dd->cspec->updthresh &
  6423. SYM_RMASK(SendCtrl, AvailUpdThld))
  6424. << SYM_LSB(SendCtrl, AvailUpdThld);
  6425. spin_unlock_irqrestore(&dd->sendctrl_lock, flags);
  6426. sendctrl_7322_mod(dd->pport, QIB_SENDCTRL_AVAIL_BLIP);
  6427. } else
  6428. spin_unlock_irqrestore(&dd->sendctrl_lock, flags);
  6429. break;
  6430. default:
  6431. break;
  6432. }
  6433. for (i = start / BITS_PER_LONG; which >= 2 && i <= lastr; ++i)
  6434. qib_write_kreg(dd, kr_sendcheckmask + i,
  6435. dd->cspec->sendchkenable[i]);
  6436. for (i = start / BITS_PER_LONG; which < 2 && i <= lastr; ++i) {
  6437. qib_write_kreg(dd, kr_sendgrhcheckmask + i,
  6438. dd->cspec->sendgrhchk[i]);
  6439. qib_write_kreg(dd, kr_sendibpktmask + i,
  6440. dd->cspec->sendibchk[i]);
  6441. }
  6442. /*
  6443. * Be sure whatever we did was seen by the chip and acted upon,
  6444. * before we return. Mostly important for which >= 2.
  6445. */
  6446. qib_read_kreg32(dd, kr_scratch);
  6447. }
  6448. /* useful for trigger analyzers, etc. */
  6449. static void writescratch(struct qib_devdata *dd, u32 val)
  6450. {
  6451. qib_write_kreg(dd, kr_scratch, val);
  6452. }
  6453. /* Dummy for now, use chip regs soon */
  6454. static int qib_7322_tempsense_rd(struct qib_devdata *dd, int regnum)
  6455. {
  6456. return -ENXIO;
  6457. }
  6458. /**
  6459. * qib_init_iba7322_funcs - set up the chip-specific function pointers
  6460. * @dev: the pci_dev for qlogic_ib device
  6461. * @ent: pci_device_id struct for this dev
  6462. *
  6463. * Also allocates, inits, and returns the devdata struct for this
  6464. * device instance
  6465. *
  6466. * This is global, and is called directly at init to set up the
  6467. * chip-specific function pointers for later use.
  6468. */
  6469. struct qib_devdata *qib_init_iba7322_funcs(struct pci_dev *pdev,
  6470. const struct pci_device_id *ent)
  6471. {
  6472. struct qib_devdata *dd;
  6473. int ret, i;
  6474. u32 tabsize, actual_cnt = 0;
  6475. dd = qib_alloc_devdata(pdev,
  6476. NUM_IB_PORTS * sizeof(struct qib_pportdata) +
  6477. sizeof(struct qib_chip_specific) +
  6478. NUM_IB_PORTS * sizeof(struct qib_chippport_specific));
  6479. if (IS_ERR(dd))
  6480. goto bail;
  6481. dd->f_bringup_serdes = qib_7322_bringup_serdes;
  6482. dd->f_cleanup = qib_setup_7322_cleanup;
  6483. dd->f_clear_tids = qib_7322_clear_tids;
  6484. dd->f_free_irq = qib_7322_free_irq;
  6485. dd->f_get_base_info = qib_7322_get_base_info;
  6486. dd->f_get_msgheader = qib_7322_get_msgheader;
  6487. dd->f_getsendbuf = qib_7322_getsendbuf;
  6488. dd->f_gpio_mod = gpio_7322_mod;
  6489. dd->f_eeprom_wen = qib_7322_eeprom_wen;
  6490. dd->f_hdrqempty = qib_7322_hdrqempty;
  6491. dd->f_ib_updown = qib_7322_ib_updown;
  6492. dd->f_init_ctxt = qib_7322_init_ctxt;
  6493. dd->f_initvl15_bufs = qib_7322_initvl15_bufs;
  6494. dd->f_intr_fallback = qib_7322_intr_fallback;
  6495. dd->f_late_initreg = qib_late_7322_initreg;
  6496. dd->f_setpbc_control = qib_7322_setpbc_control;
  6497. dd->f_portcntr = qib_portcntr_7322;
  6498. dd->f_put_tid = qib_7322_put_tid;
  6499. dd->f_quiet_serdes = qib_7322_mini_quiet_serdes;
  6500. dd->f_rcvctrl = rcvctrl_7322_mod;
  6501. dd->f_read_cntrs = qib_read_7322cntrs;
  6502. dd->f_read_portcntrs = qib_read_7322portcntrs;
  6503. dd->f_reset = qib_do_7322_reset;
  6504. dd->f_init_sdma_regs = init_sdma_7322_regs;
  6505. dd->f_sdma_busy = qib_sdma_7322_busy;
  6506. dd->f_sdma_gethead = qib_sdma_7322_gethead;
  6507. dd->f_sdma_sendctrl = qib_7322_sdma_sendctrl;
  6508. dd->f_sdma_set_desc_cnt = qib_sdma_set_7322_desc_cnt;
  6509. dd->f_sdma_update_tail = qib_sdma_update_7322_tail;
  6510. dd->f_sendctrl = sendctrl_7322_mod;
  6511. dd->f_set_armlaunch = qib_set_7322_armlaunch;
  6512. dd->f_set_cntr_sample = qib_set_cntr_7322_sample;
  6513. dd->f_iblink_state = qib_7322_iblink_state;
  6514. dd->f_ibphys_portstate = qib_7322_phys_portstate;
  6515. dd->f_get_ib_cfg = qib_7322_get_ib_cfg;
  6516. dd->f_set_ib_cfg = qib_7322_set_ib_cfg;
  6517. dd->f_set_ib_loopback = qib_7322_set_loopback;
  6518. dd->f_get_ib_table = qib_7322_get_ib_table;
  6519. dd->f_set_ib_table = qib_7322_set_ib_table;
  6520. dd->f_set_intr_state = qib_7322_set_intr_state;
  6521. dd->f_setextled = qib_setup_7322_setextled;
  6522. dd->f_txchk_change = qib_7322_txchk_change;
  6523. dd->f_update_usrhead = qib_update_7322_usrhead;
  6524. dd->f_wantpiobuf_intr = qib_wantpiobuf_7322_intr;
  6525. dd->f_xgxs_reset = qib_7322_mini_pcs_reset;
  6526. dd->f_sdma_hw_clean_up = qib_7322_sdma_hw_clean_up;
  6527. dd->f_sdma_hw_start_up = qib_7322_sdma_hw_start_up;
  6528. dd->f_sdma_init_early = qib_7322_sdma_init_early;
  6529. dd->f_writescratch = writescratch;
  6530. dd->f_tempsense_rd = qib_7322_tempsense_rd;
  6531. #ifdef CONFIG_INFINIBAND_QIB_DCA
  6532. dd->f_notify_dca = qib_7322_notify_dca;
  6533. #endif
  6534. /*
  6535. * Do remaining PCIe setup and save PCIe values in dd.
  6536. * Any error printing is already done by the init code.
  6537. * On return, we have the chip mapped, but chip registers
  6538. * are not set up until start of qib_init_7322_variables.
  6539. */
  6540. ret = qib_pcie_ddinit(dd, pdev, ent);
  6541. if (ret < 0)
  6542. goto bail_free;
  6543. /* initialize chip-specific variables */
  6544. ret = qib_init_7322_variables(dd);
  6545. if (ret)
  6546. goto bail_cleanup;
  6547. if (qib_mini_init || !dd->num_pports)
  6548. goto bail;
  6549. /*
  6550. * Determine number of vectors we want; depends on port count
  6551. * and number of configured kernel receive queues actually used.
  6552. * Should also depend on whether sdma is enabled or not, but
  6553. * that's such a rare testing case it's not worth worrying about.
  6554. */
  6555. tabsize = dd->first_user_ctxt + ARRAY_SIZE(irq_table);
  6556. for (i = 0; i < tabsize; i++)
  6557. if ((i < ARRAY_SIZE(irq_table) &&
  6558. irq_table[i].port <= dd->num_pports) ||
  6559. (i >= ARRAY_SIZE(irq_table) &&
  6560. dd->rcd[i - ARRAY_SIZE(irq_table)]))
  6561. actual_cnt++;
  6562. /* reduce by ctxt's < 2 */
  6563. if (qib_krcvq01_no_msi)
  6564. actual_cnt -= dd->num_pports;
  6565. tabsize = actual_cnt;
  6566. dd->cspec->msix_entries = kzalloc(tabsize *
  6567. sizeof(struct qib_msix_entry), GFP_KERNEL);
  6568. if (!dd->cspec->msix_entries) {
  6569. qib_dev_err(dd, "No memory for MSIx table\n");
  6570. tabsize = 0;
  6571. }
  6572. for (i = 0; i < tabsize; i++)
  6573. dd->cspec->msix_entries[i].msix.entry = i;
  6574. if (qib_pcie_params(dd, 8, &tabsize, dd->cspec->msix_entries))
  6575. qib_dev_err(dd,
  6576. "Failed to setup PCIe or interrupts; continuing anyway\n");
  6577. /* may be less than we wanted, if not enough available */
  6578. dd->cspec->num_msix_entries = tabsize;
  6579. /* setup interrupt handler */
  6580. qib_setup_7322_interrupt(dd, 1);
  6581. /* clear diagctrl register, in case diags were running and crashed */
  6582. qib_write_kreg(dd, kr_hwdiagctrl, 0);
  6583. #ifdef CONFIG_INFINIBAND_QIB_DCA
  6584. if (!dca_add_requester(&pdev->dev)) {
  6585. qib_devinfo(dd->pcidev, "DCA enabled\n");
  6586. dd->flags |= QIB_DCA_ENABLED;
  6587. qib_setup_dca(dd);
  6588. }
  6589. #endif
  6590. goto bail;
  6591. bail_cleanup:
  6592. qib_pcie_ddcleanup(dd);
  6593. bail_free:
  6594. qib_free_devdata(dd);
  6595. dd = ERR_PTR(ret);
  6596. bail:
  6597. return dd;
  6598. }
  6599. /*
  6600. * Set the table entry at the specified index from the table specifed.
  6601. * There are 3 * TXDDS_TABLE_SZ entries in all per port, with the first
  6602. * TXDDS_TABLE_SZ for SDR, the next for DDR, and the last for QDR.
  6603. * 'idx' below addresses the correct entry, while its 4 LSBs select the
  6604. * corresponding entry (one of TXDDS_TABLE_SZ) from the selected table.
  6605. */
  6606. #define DDS_ENT_AMP_LSB 14
  6607. #define DDS_ENT_MAIN_LSB 9
  6608. #define DDS_ENT_POST_LSB 5
  6609. #define DDS_ENT_PRE_XTRA_LSB 3
  6610. #define DDS_ENT_PRE_LSB 0
  6611. /*
  6612. * Set one entry in the TxDDS table for spec'd port
  6613. * ridx picks one of the entries, while tp points
  6614. * to the appropriate table entry.
  6615. */
  6616. static void set_txdds(struct qib_pportdata *ppd, int ridx,
  6617. const struct txdds_ent *tp)
  6618. {
  6619. struct qib_devdata *dd = ppd->dd;
  6620. u32 pack_ent;
  6621. int regidx;
  6622. /* Get correct offset in chip-space, and in source table */
  6623. regidx = KREG_IBPORT_IDX(IBSD_DDS_MAP_TABLE) + ridx;
  6624. /*
  6625. * We do not use qib_write_kreg_port() because it was intended
  6626. * only for registers in the lower "port specific" pages.
  6627. * So do index calculation by hand.
  6628. */
  6629. if (ppd->hw_pidx)
  6630. regidx += (dd->palign / sizeof(u64));
  6631. pack_ent = tp->amp << DDS_ENT_AMP_LSB;
  6632. pack_ent |= tp->main << DDS_ENT_MAIN_LSB;
  6633. pack_ent |= tp->pre << DDS_ENT_PRE_LSB;
  6634. pack_ent |= tp->post << DDS_ENT_POST_LSB;
  6635. qib_write_kreg(dd, regidx, pack_ent);
  6636. /* Prevent back-to-back writes by hitting scratch */
  6637. qib_write_kreg(ppd->dd, kr_scratch, 0);
  6638. }
  6639. static const struct vendor_txdds_ent vendor_txdds[] = {
  6640. { /* Amphenol 1m 30awg NoEq */
  6641. { 0x41, 0x50, 0x48 }, "584470002 ",
  6642. { 10, 0, 0, 5 }, { 10, 0, 0, 9 }, { 7, 1, 0, 13 },
  6643. },
  6644. { /* Amphenol 3m 28awg NoEq */
  6645. { 0x41, 0x50, 0x48 }, "584470004 ",
  6646. { 0, 0, 0, 8 }, { 0, 0, 0, 11 }, { 0, 1, 7, 15 },
  6647. },
  6648. { /* Finisar 3m OM2 Optical */
  6649. { 0x00, 0x90, 0x65 }, "FCBG410QB1C03-QL",
  6650. { 0, 0, 0, 3 }, { 0, 0, 0, 4 }, { 0, 0, 0, 13 },
  6651. },
  6652. { /* Finisar 30m OM2 Optical */
  6653. { 0x00, 0x90, 0x65 }, "FCBG410QB1C30-QL",
  6654. { 0, 0, 0, 1 }, { 0, 0, 0, 5 }, { 0, 0, 0, 11 },
  6655. },
  6656. { /* Finisar Default OM2 Optical */
  6657. { 0x00, 0x90, 0x65 }, NULL,
  6658. { 0, 0, 0, 2 }, { 0, 0, 0, 5 }, { 0, 0, 0, 12 },
  6659. },
  6660. { /* Gore 1m 30awg NoEq */
  6661. { 0x00, 0x21, 0x77 }, "QSN3300-1 ",
  6662. { 0, 0, 0, 6 }, { 0, 0, 0, 9 }, { 0, 1, 0, 15 },
  6663. },
  6664. { /* Gore 2m 30awg NoEq */
  6665. { 0x00, 0x21, 0x77 }, "QSN3300-2 ",
  6666. { 0, 0, 0, 8 }, { 0, 0, 0, 10 }, { 0, 1, 7, 15 },
  6667. },
  6668. { /* Gore 1m 28awg NoEq */
  6669. { 0x00, 0x21, 0x77 }, "QSN3800-1 ",
  6670. { 0, 0, 0, 6 }, { 0, 0, 0, 8 }, { 0, 1, 0, 15 },
  6671. },
  6672. { /* Gore 3m 28awg NoEq */
  6673. { 0x00, 0x21, 0x77 }, "QSN3800-3 ",
  6674. { 0, 0, 0, 9 }, { 0, 0, 0, 13 }, { 0, 1, 7, 15 },
  6675. },
  6676. { /* Gore 5m 24awg Eq */
  6677. { 0x00, 0x21, 0x77 }, "QSN7000-5 ",
  6678. { 0, 0, 0, 7 }, { 0, 0, 0, 9 }, { 0, 1, 3, 15 },
  6679. },
  6680. { /* Gore 7m 24awg Eq */
  6681. { 0x00, 0x21, 0x77 }, "QSN7000-7 ",
  6682. { 0, 0, 0, 9 }, { 0, 0, 0, 11 }, { 0, 2, 6, 15 },
  6683. },
  6684. { /* Gore 5m 26awg Eq */
  6685. { 0x00, 0x21, 0x77 }, "QSN7600-5 ",
  6686. { 0, 0, 0, 8 }, { 0, 0, 0, 11 }, { 0, 1, 9, 13 },
  6687. },
  6688. { /* Gore 7m 26awg Eq */
  6689. { 0x00, 0x21, 0x77 }, "QSN7600-7 ",
  6690. { 0, 0, 0, 8 }, { 0, 0, 0, 11 }, { 10, 1, 8, 15 },
  6691. },
  6692. { /* Intersil 12m 24awg Active */
  6693. { 0x00, 0x30, 0xB4 }, "QLX4000CQSFP1224",
  6694. { 0, 0, 0, 2 }, { 0, 0, 0, 5 }, { 0, 3, 0, 9 },
  6695. },
  6696. { /* Intersil 10m 28awg Active */
  6697. { 0x00, 0x30, 0xB4 }, "QLX4000CQSFP1028",
  6698. { 0, 0, 0, 6 }, { 0, 0, 0, 4 }, { 0, 2, 0, 2 },
  6699. },
  6700. { /* Intersil 7m 30awg Active */
  6701. { 0x00, 0x30, 0xB4 }, "QLX4000CQSFP0730",
  6702. { 0, 0, 0, 6 }, { 0, 0, 0, 4 }, { 0, 1, 0, 3 },
  6703. },
  6704. { /* Intersil 5m 32awg Active */
  6705. { 0x00, 0x30, 0xB4 }, "QLX4000CQSFP0532",
  6706. { 0, 0, 0, 6 }, { 0, 0, 0, 6 }, { 0, 2, 0, 8 },
  6707. },
  6708. { /* Intersil Default Active */
  6709. { 0x00, 0x30, 0xB4 }, NULL,
  6710. { 0, 0, 0, 6 }, { 0, 0, 0, 5 }, { 0, 2, 0, 5 },
  6711. },
  6712. { /* Luxtera 20m Active Optical */
  6713. { 0x00, 0x25, 0x63 }, NULL,
  6714. { 0, 0, 0, 5 }, { 0, 0, 0, 8 }, { 0, 2, 0, 12 },
  6715. },
  6716. { /* Molex 1M Cu loopback */
  6717. { 0x00, 0x09, 0x3A }, "74763-0025 ",
  6718. { 2, 2, 6, 15 }, { 2, 2, 6, 15 }, { 2, 2, 6, 15 },
  6719. },
  6720. { /* Molex 2m 28awg NoEq */
  6721. { 0x00, 0x09, 0x3A }, "74757-2201 ",
  6722. { 0, 0, 0, 6 }, { 0, 0, 0, 9 }, { 0, 1, 1, 15 },
  6723. },
  6724. };
  6725. static const struct txdds_ent txdds_sdr[TXDDS_TABLE_SZ] = {
  6726. /* amp, pre, main, post */
  6727. { 2, 2, 15, 6 }, /* Loopback */
  6728. { 0, 0, 0, 1 }, /* 2 dB */
  6729. { 0, 0, 0, 2 }, /* 3 dB */
  6730. { 0, 0, 0, 3 }, /* 4 dB */
  6731. { 0, 0, 0, 4 }, /* 5 dB */
  6732. { 0, 0, 0, 5 }, /* 6 dB */
  6733. { 0, 0, 0, 6 }, /* 7 dB */
  6734. { 0, 0, 0, 7 }, /* 8 dB */
  6735. { 0, 0, 0, 8 }, /* 9 dB */
  6736. { 0, 0, 0, 9 }, /* 10 dB */
  6737. { 0, 0, 0, 10 }, /* 11 dB */
  6738. { 0, 0, 0, 11 }, /* 12 dB */
  6739. { 0, 0, 0, 12 }, /* 13 dB */
  6740. { 0, 0, 0, 13 }, /* 14 dB */
  6741. { 0, 0, 0, 14 }, /* 15 dB */
  6742. { 0, 0, 0, 15 }, /* 16 dB */
  6743. };
  6744. static const struct txdds_ent txdds_ddr[TXDDS_TABLE_SZ] = {
  6745. /* amp, pre, main, post */
  6746. { 2, 2, 15, 6 }, /* Loopback */
  6747. { 0, 0, 0, 8 }, /* 2 dB */
  6748. { 0, 0, 0, 8 }, /* 3 dB */
  6749. { 0, 0, 0, 9 }, /* 4 dB */
  6750. { 0, 0, 0, 9 }, /* 5 dB */
  6751. { 0, 0, 0, 10 }, /* 6 dB */
  6752. { 0, 0, 0, 10 }, /* 7 dB */
  6753. { 0, 0, 0, 11 }, /* 8 dB */
  6754. { 0, 0, 0, 11 }, /* 9 dB */
  6755. { 0, 0, 0, 12 }, /* 10 dB */
  6756. { 0, 0, 0, 12 }, /* 11 dB */
  6757. { 0, 0, 0, 13 }, /* 12 dB */
  6758. { 0, 0, 0, 13 }, /* 13 dB */
  6759. { 0, 0, 0, 14 }, /* 14 dB */
  6760. { 0, 0, 0, 14 }, /* 15 dB */
  6761. { 0, 0, 0, 15 }, /* 16 dB */
  6762. };
  6763. static const struct txdds_ent txdds_qdr[TXDDS_TABLE_SZ] = {
  6764. /* amp, pre, main, post */
  6765. { 2, 2, 15, 6 }, /* Loopback */
  6766. { 0, 1, 0, 7 }, /* 2 dB (also QMH7342) */
  6767. { 0, 1, 0, 9 }, /* 3 dB (also QMH7342) */
  6768. { 0, 1, 0, 11 }, /* 4 dB */
  6769. { 0, 1, 0, 13 }, /* 5 dB */
  6770. { 0, 1, 0, 15 }, /* 6 dB */
  6771. { 0, 1, 3, 15 }, /* 7 dB */
  6772. { 0, 1, 7, 15 }, /* 8 dB */
  6773. { 0, 1, 7, 15 }, /* 9 dB */
  6774. { 0, 1, 8, 15 }, /* 10 dB */
  6775. { 0, 1, 9, 15 }, /* 11 dB */
  6776. { 0, 1, 10, 15 }, /* 12 dB */
  6777. { 0, 2, 6, 15 }, /* 13 dB */
  6778. { 0, 2, 7, 15 }, /* 14 dB */
  6779. { 0, 2, 8, 15 }, /* 15 dB */
  6780. { 0, 2, 9, 15 }, /* 16 dB */
  6781. };
  6782. /*
  6783. * extra entries for use with txselect, for indices >= TXDDS_TABLE_SZ.
  6784. * These are mostly used for mez cards going through connectors
  6785. * and backplane traces, but can be used to add other "unusual"
  6786. * table values as well.
  6787. */
  6788. static const struct txdds_ent txdds_extra_sdr[TXDDS_EXTRA_SZ] = {
  6789. /* amp, pre, main, post */
  6790. { 0, 0, 0, 1 }, /* QMH7342 backplane settings */
  6791. { 0, 0, 0, 1 }, /* QMH7342 backplane settings */
  6792. { 0, 0, 0, 2 }, /* QMH7342 backplane settings */
  6793. { 0, 0, 0, 2 }, /* QMH7342 backplane settings */
  6794. { 0, 0, 0, 3 }, /* QMH7342 backplane settings */
  6795. { 0, 0, 0, 4 }, /* QMH7342 backplane settings */
  6796. { 0, 1, 4, 15 }, /* QME7342 backplane settings 1.0 */
  6797. { 0, 1, 3, 15 }, /* QME7342 backplane settings 1.0 */
  6798. { 0, 1, 0, 12 }, /* QME7342 backplane settings 1.0 */
  6799. { 0, 1, 0, 11 }, /* QME7342 backplane settings 1.0 */
  6800. { 0, 1, 0, 9 }, /* QME7342 backplane settings 1.0 */
  6801. { 0, 1, 0, 14 }, /* QME7342 backplane settings 1.0 */
  6802. { 0, 1, 2, 15 }, /* QME7342 backplane settings 1.0 */
  6803. { 0, 1, 0, 11 }, /* QME7342 backplane settings 1.1 */
  6804. { 0, 1, 0, 7 }, /* QME7342 backplane settings 1.1 */
  6805. { 0, 1, 0, 9 }, /* QME7342 backplane settings 1.1 */
  6806. { 0, 1, 0, 6 }, /* QME7342 backplane settings 1.1 */
  6807. { 0, 1, 0, 8 }, /* QME7342 backplane settings 1.1 */
  6808. };
  6809. static const struct txdds_ent txdds_extra_ddr[TXDDS_EXTRA_SZ] = {
  6810. /* amp, pre, main, post */
  6811. { 0, 0, 0, 7 }, /* QMH7342 backplane settings */
  6812. { 0, 0, 0, 7 }, /* QMH7342 backplane settings */
  6813. { 0, 0, 0, 8 }, /* QMH7342 backplane settings */
  6814. { 0, 0, 0, 8 }, /* QMH7342 backplane settings */
  6815. { 0, 0, 0, 9 }, /* QMH7342 backplane settings */
  6816. { 0, 0, 0, 10 }, /* QMH7342 backplane settings */
  6817. { 0, 1, 4, 15 }, /* QME7342 backplane settings 1.0 */
  6818. { 0, 1, 3, 15 }, /* QME7342 backplane settings 1.0 */
  6819. { 0, 1, 0, 12 }, /* QME7342 backplane settings 1.0 */
  6820. { 0, 1, 0, 11 }, /* QME7342 backplane settings 1.0 */
  6821. { 0, 1, 0, 9 }, /* QME7342 backplane settings 1.0 */
  6822. { 0, 1, 0, 14 }, /* QME7342 backplane settings 1.0 */
  6823. { 0, 1, 2, 15 }, /* QME7342 backplane settings 1.0 */
  6824. { 0, 1, 0, 11 }, /* QME7342 backplane settings 1.1 */
  6825. { 0, 1, 0, 7 }, /* QME7342 backplane settings 1.1 */
  6826. { 0, 1, 0, 9 }, /* QME7342 backplane settings 1.1 */
  6827. { 0, 1, 0, 6 }, /* QME7342 backplane settings 1.1 */
  6828. { 0, 1, 0, 8 }, /* QME7342 backplane settings 1.1 */
  6829. };
  6830. static const struct txdds_ent txdds_extra_qdr[TXDDS_EXTRA_SZ] = {
  6831. /* amp, pre, main, post */
  6832. { 0, 1, 0, 4 }, /* QMH7342 backplane settings */
  6833. { 0, 1, 0, 5 }, /* QMH7342 backplane settings */
  6834. { 0, 1, 0, 6 }, /* QMH7342 backplane settings */
  6835. { 0, 1, 0, 8 }, /* QMH7342 backplane settings */
  6836. { 0, 1, 0, 10 }, /* QMH7342 backplane settings */
  6837. { 0, 1, 0, 12 }, /* QMH7342 backplane settings */
  6838. { 0, 1, 4, 15 }, /* QME7342 backplane settings 1.0 */
  6839. { 0, 1, 3, 15 }, /* QME7342 backplane settings 1.0 */
  6840. { 0, 1, 0, 12 }, /* QME7342 backplane settings 1.0 */
  6841. { 0, 1, 0, 11 }, /* QME7342 backplane settings 1.0 */
  6842. { 0, 1, 0, 9 }, /* QME7342 backplane settings 1.0 */
  6843. { 0, 1, 0, 14 }, /* QME7342 backplane settings 1.0 */
  6844. { 0, 1, 2, 15 }, /* QME7342 backplane settings 1.0 */
  6845. { 0, 1, 0, 11 }, /* QME7342 backplane settings 1.1 */
  6846. { 0, 1, 0, 7 }, /* QME7342 backplane settings 1.1 */
  6847. { 0, 1, 0, 9 }, /* QME7342 backplane settings 1.1 */
  6848. { 0, 1, 0, 6 }, /* QME7342 backplane settings 1.1 */
  6849. { 0, 1, 0, 8 }, /* QME7342 backplane settings 1.1 */
  6850. };
  6851. static const struct txdds_ent txdds_extra_mfg[TXDDS_MFG_SZ] = {
  6852. /* amp, pre, main, post */
  6853. { 0, 0, 0, 0 }, /* QME7342 mfg settings */
  6854. { 0, 0, 0, 6 }, /* QME7342 P2 mfg settings */
  6855. };
  6856. static const struct txdds_ent *get_atten_table(const struct txdds_ent *txdds,
  6857. unsigned atten)
  6858. {
  6859. /*
  6860. * The attenuation table starts at 2dB for entry 1,
  6861. * with entry 0 being the loopback entry.
  6862. */
  6863. if (atten <= 2)
  6864. atten = 1;
  6865. else if (atten > TXDDS_TABLE_SZ)
  6866. atten = TXDDS_TABLE_SZ - 1;
  6867. else
  6868. atten--;
  6869. return txdds + atten;
  6870. }
  6871. /*
  6872. * if override is set, the module parameter txselect has a value
  6873. * for this specific port, so use it, rather than our normal mechanism.
  6874. */
  6875. static void find_best_ent(struct qib_pportdata *ppd,
  6876. const struct txdds_ent **sdr_dds,
  6877. const struct txdds_ent **ddr_dds,
  6878. const struct txdds_ent **qdr_dds, int override)
  6879. {
  6880. struct qib_qsfp_cache *qd = &ppd->cpspec->qsfp_data.cache;
  6881. int idx;
  6882. /* Search table of known cables */
  6883. for (idx = 0; !override && idx < ARRAY_SIZE(vendor_txdds); ++idx) {
  6884. const struct vendor_txdds_ent *v = vendor_txdds + idx;
  6885. if (!memcmp(v->oui, qd->oui, QSFP_VOUI_LEN) &&
  6886. (!v->partnum ||
  6887. !memcmp(v->partnum, qd->partnum, QSFP_PN_LEN))) {
  6888. *sdr_dds = &v->sdr;
  6889. *ddr_dds = &v->ddr;
  6890. *qdr_dds = &v->qdr;
  6891. return;
  6892. }
  6893. }
  6894. /* Active cables don't have attenuation so we only set SERDES
  6895. * settings to account for the attenuation of the board traces. */
  6896. if (!override && QSFP_IS_ACTIVE(qd->tech)) {
  6897. *sdr_dds = txdds_sdr + ppd->dd->board_atten;
  6898. *ddr_dds = txdds_ddr + ppd->dd->board_atten;
  6899. *qdr_dds = txdds_qdr + ppd->dd->board_atten;
  6900. return;
  6901. }
  6902. if (!override && QSFP_HAS_ATTEN(qd->tech) && (qd->atten[0] ||
  6903. qd->atten[1])) {
  6904. *sdr_dds = get_atten_table(txdds_sdr, qd->atten[0]);
  6905. *ddr_dds = get_atten_table(txdds_ddr, qd->atten[0]);
  6906. *qdr_dds = get_atten_table(txdds_qdr, qd->atten[1]);
  6907. return;
  6908. } else if (ppd->cpspec->no_eep < TXDDS_TABLE_SZ) {
  6909. /*
  6910. * If we have no (or incomplete) data from the cable
  6911. * EEPROM, or no QSFP, or override is set, use the
  6912. * module parameter value to index into the attentuation
  6913. * table.
  6914. */
  6915. idx = ppd->cpspec->no_eep;
  6916. *sdr_dds = &txdds_sdr[idx];
  6917. *ddr_dds = &txdds_ddr[idx];
  6918. *qdr_dds = &txdds_qdr[idx];
  6919. } else if (ppd->cpspec->no_eep < (TXDDS_TABLE_SZ + TXDDS_EXTRA_SZ)) {
  6920. /* similar to above, but index into the "extra" table. */
  6921. idx = ppd->cpspec->no_eep - TXDDS_TABLE_SZ;
  6922. *sdr_dds = &txdds_extra_sdr[idx];
  6923. *ddr_dds = &txdds_extra_ddr[idx];
  6924. *qdr_dds = &txdds_extra_qdr[idx];
  6925. } else if ((IS_QME(ppd->dd) || IS_QMH(ppd->dd)) &&
  6926. ppd->cpspec->no_eep < (TXDDS_TABLE_SZ + TXDDS_EXTRA_SZ +
  6927. TXDDS_MFG_SZ)) {
  6928. idx = ppd->cpspec->no_eep - (TXDDS_TABLE_SZ + TXDDS_EXTRA_SZ);
  6929. pr_info("IB%u:%u use idx %u into txdds_mfg\n",
  6930. ppd->dd->unit, ppd->port, idx);
  6931. *sdr_dds = &txdds_extra_mfg[idx];
  6932. *ddr_dds = &txdds_extra_mfg[idx];
  6933. *qdr_dds = &txdds_extra_mfg[idx];
  6934. } else {
  6935. /* this shouldn't happen, it's range checked */
  6936. *sdr_dds = txdds_sdr + qib_long_atten;
  6937. *ddr_dds = txdds_ddr + qib_long_atten;
  6938. *qdr_dds = txdds_qdr + qib_long_atten;
  6939. }
  6940. }
  6941. static void init_txdds_table(struct qib_pportdata *ppd, int override)
  6942. {
  6943. const struct txdds_ent *sdr_dds, *ddr_dds, *qdr_dds;
  6944. struct txdds_ent *dds;
  6945. int idx;
  6946. int single_ent = 0;
  6947. find_best_ent(ppd, &sdr_dds, &ddr_dds, &qdr_dds, override);
  6948. /* for mez cards or override, use the selected value for all entries */
  6949. if (!(ppd->dd->flags & QIB_HAS_QSFP) || override)
  6950. single_ent = 1;
  6951. /* Fill in the first entry with the best entry found. */
  6952. set_txdds(ppd, 0, sdr_dds);
  6953. set_txdds(ppd, TXDDS_TABLE_SZ, ddr_dds);
  6954. set_txdds(ppd, 2 * TXDDS_TABLE_SZ, qdr_dds);
  6955. if (ppd->lflags & (QIBL_LINKINIT | QIBL_LINKARMED |
  6956. QIBL_LINKACTIVE)) {
  6957. dds = (struct txdds_ent *)(ppd->link_speed_active ==
  6958. QIB_IB_QDR ? qdr_dds :
  6959. (ppd->link_speed_active ==
  6960. QIB_IB_DDR ? ddr_dds : sdr_dds));
  6961. write_tx_serdes_param(ppd, dds);
  6962. }
  6963. /* Fill in the remaining entries with the default table values. */
  6964. for (idx = 1; idx < ARRAY_SIZE(txdds_sdr); ++idx) {
  6965. set_txdds(ppd, idx, single_ent ? sdr_dds : txdds_sdr + idx);
  6966. set_txdds(ppd, idx + TXDDS_TABLE_SZ,
  6967. single_ent ? ddr_dds : txdds_ddr + idx);
  6968. set_txdds(ppd, idx + 2 * TXDDS_TABLE_SZ,
  6969. single_ent ? qdr_dds : txdds_qdr + idx);
  6970. }
  6971. }
  6972. #define KR_AHB_ACC KREG_IDX(ahb_access_ctrl)
  6973. #define KR_AHB_TRANS KREG_IDX(ahb_transaction_reg)
  6974. #define AHB_TRANS_RDY SYM_MASK(ahb_transaction_reg, ahb_rdy)
  6975. #define AHB_ADDR_LSB SYM_LSB(ahb_transaction_reg, ahb_address)
  6976. #define AHB_DATA_LSB SYM_LSB(ahb_transaction_reg, ahb_data)
  6977. #define AHB_WR SYM_MASK(ahb_transaction_reg, write_not_read)
  6978. #define AHB_TRANS_TRIES 10
  6979. /*
  6980. * The chan argument is 0=chan0, 1=chan1, 2=pll, 3=chan2, 4=chan4,
  6981. * 5=subsystem which is why most calls have "chan + chan >> 1"
  6982. * for the channel argument.
  6983. */
  6984. static u32 ahb_mod(struct qib_devdata *dd, int quad, int chan, int addr,
  6985. u32 data, u32 mask)
  6986. {
  6987. u32 rd_data, wr_data, sz_mask;
  6988. u64 trans, acc, prev_acc;
  6989. u32 ret = 0xBAD0BAD;
  6990. int tries;
  6991. prev_acc = qib_read_kreg64(dd, KR_AHB_ACC);
  6992. /* From this point on, make sure we return access */
  6993. acc = (quad << 1) | 1;
  6994. qib_write_kreg(dd, KR_AHB_ACC, acc);
  6995. for (tries = 1; tries < AHB_TRANS_TRIES; ++tries) {
  6996. trans = qib_read_kreg64(dd, KR_AHB_TRANS);
  6997. if (trans & AHB_TRANS_RDY)
  6998. break;
  6999. }
  7000. if (tries >= AHB_TRANS_TRIES) {
  7001. qib_dev_err(dd, "No ahb_rdy in %d tries\n", AHB_TRANS_TRIES);
  7002. goto bail;
  7003. }
  7004. /* If mask is not all 1s, we need to read, but different SerDes
  7005. * entities have different sizes
  7006. */
  7007. sz_mask = (1UL << ((quad == 1) ? 32 : 16)) - 1;
  7008. wr_data = data & mask & sz_mask;
  7009. if ((~mask & sz_mask) != 0) {
  7010. trans = ((chan << 6) | addr) << (AHB_ADDR_LSB + 1);
  7011. qib_write_kreg(dd, KR_AHB_TRANS, trans);
  7012. for (tries = 1; tries < AHB_TRANS_TRIES; ++tries) {
  7013. trans = qib_read_kreg64(dd, KR_AHB_TRANS);
  7014. if (trans & AHB_TRANS_RDY)
  7015. break;
  7016. }
  7017. if (tries >= AHB_TRANS_TRIES) {
  7018. qib_dev_err(dd, "No Rd ahb_rdy in %d tries\n",
  7019. AHB_TRANS_TRIES);
  7020. goto bail;
  7021. }
  7022. /* Re-read in case host split reads and read data first */
  7023. trans = qib_read_kreg64(dd, KR_AHB_TRANS);
  7024. rd_data = (uint32_t)(trans >> AHB_DATA_LSB);
  7025. wr_data |= (rd_data & ~mask & sz_mask);
  7026. }
  7027. /* If mask is not zero, we need to write. */
  7028. if (mask & sz_mask) {
  7029. trans = ((chan << 6) | addr) << (AHB_ADDR_LSB + 1);
  7030. trans |= ((uint64_t)wr_data << AHB_DATA_LSB);
  7031. trans |= AHB_WR;
  7032. qib_write_kreg(dd, KR_AHB_TRANS, trans);
  7033. for (tries = 1; tries < AHB_TRANS_TRIES; ++tries) {
  7034. trans = qib_read_kreg64(dd, KR_AHB_TRANS);
  7035. if (trans & AHB_TRANS_RDY)
  7036. break;
  7037. }
  7038. if (tries >= AHB_TRANS_TRIES) {
  7039. qib_dev_err(dd, "No Wr ahb_rdy in %d tries\n",
  7040. AHB_TRANS_TRIES);
  7041. goto bail;
  7042. }
  7043. }
  7044. ret = wr_data;
  7045. bail:
  7046. qib_write_kreg(dd, KR_AHB_ACC, prev_acc);
  7047. return ret;
  7048. }
  7049. static void ibsd_wr_allchans(struct qib_pportdata *ppd, int addr, unsigned data,
  7050. unsigned mask)
  7051. {
  7052. struct qib_devdata *dd = ppd->dd;
  7053. int chan;
  7054. u32 rbc;
  7055. for (chan = 0; chan < SERDES_CHANS; ++chan) {
  7056. ahb_mod(dd, IBSD(ppd->hw_pidx), (chan + (chan >> 1)), addr,
  7057. data, mask);
  7058. rbc = ahb_mod(dd, IBSD(ppd->hw_pidx), (chan + (chan >> 1)),
  7059. addr, 0, 0);
  7060. }
  7061. }
  7062. static void serdes_7322_los_enable(struct qib_pportdata *ppd, int enable)
  7063. {
  7064. u64 data = qib_read_kreg_port(ppd, krp_serdesctrl);
  7065. u8 state = SYM_FIELD(data, IBSerdesCtrl_0, RXLOSEN);
  7066. if (enable && !state) {
  7067. pr_info("IB%u:%u Turning LOS on\n",
  7068. ppd->dd->unit, ppd->port);
  7069. data |= SYM_MASK(IBSerdesCtrl_0, RXLOSEN);
  7070. } else if (!enable && state) {
  7071. pr_info("IB%u:%u Turning LOS off\n",
  7072. ppd->dd->unit, ppd->port);
  7073. data &= ~SYM_MASK(IBSerdesCtrl_0, RXLOSEN);
  7074. }
  7075. qib_write_kreg_port(ppd, krp_serdesctrl, data);
  7076. }
  7077. static int serdes_7322_init(struct qib_pportdata *ppd)
  7078. {
  7079. int ret = 0;
  7080. if (ppd->dd->cspec->r1)
  7081. ret = serdes_7322_init_old(ppd);
  7082. else
  7083. ret = serdes_7322_init_new(ppd);
  7084. return ret;
  7085. }
  7086. static int serdes_7322_init_old(struct qib_pportdata *ppd)
  7087. {
  7088. u32 le_val;
  7089. /*
  7090. * Initialize the Tx DDS tables. Also done every QSFP event,
  7091. * for adapters with QSFP
  7092. */
  7093. init_txdds_table(ppd, 0);
  7094. /* ensure no tx overrides from earlier driver loads */
  7095. qib_write_kreg_port(ppd, krp_tx_deemph_override,
  7096. SYM_MASK(IBSD_TX_DEEMPHASIS_OVERRIDE_0,
  7097. reset_tx_deemphasis_override));
  7098. /* Patch some SerDes defaults to "Better for IB" */
  7099. /* Timing Loop Bandwidth: cdr_timing[11:9] = 0 */
  7100. ibsd_wr_allchans(ppd, 2, 0, BMASK(11, 9));
  7101. /* Termination: rxtermctrl_r2d addr 11 bits [12:11] = 1 */
  7102. ibsd_wr_allchans(ppd, 11, (1 << 11), BMASK(12, 11));
  7103. /* Enable LE2: rxle2en_r2a addr 13 bit [6] = 1 */
  7104. ibsd_wr_allchans(ppd, 13, (1 << 6), (1 << 6));
  7105. /* May be overridden in qsfp_7322_event */
  7106. le_val = IS_QME(ppd->dd) ? LE2_QME : LE2_DEFAULT;
  7107. ibsd_wr_allchans(ppd, 13, (le_val << 7), BMASK(9, 7));
  7108. /* enable LE1 adaptation for all but QME, which is disabled */
  7109. le_val = IS_QME(ppd->dd) ? 0 : 1;
  7110. ibsd_wr_allchans(ppd, 13, (le_val << 5), (1 << 5));
  7111. /* Clear cmode-override, may be set from older driver */
  7112. ahb_mod(ppd->dd, IBSD(ppd->hw_pidx), 5, 10, 0 << 14, 1 << 14);
  7113. /* Timing Recovery: rxtapsel addr 5 bits [9:8] = 0 */
  7114. ibsd_wr_allchans(ppd, 5, (0 << 8), BMASK(9, 8));
  7115. /* setup LoS params; these are subsystem, so chan == 5 */
  7116. /* LoS filter threshold_count on, ch 0-3, set to 8 */
  7117. ahb_mod(ppd->dd, IBSD(ppd->hw_pidx), 5, 5, 8 << 11, BMASK(14, 11));
  7118. ahb_mod(ppd->dd, IBSD(ppd->hw_pidx), 5, 7, 8 << 4, BMASK(7, 4));
  7119. ahb_mod(ppd->dd, IBSD(ppd->hw_pidx), 5, 8, 8 << 11, BMASK(14, 11));
  7120. ahb_mod(ppd->dd, IBSD(ppd->hw_pidx), 5, 10, 8 << 4, BMASK(7, 4));
  7121. /* LoS filter threshold_count off, ch 0-3, set to 4 */
  7122. ahb_mod(ppd->dd, IBSD(ppd->hw_pidx), 5, 6, 4 << 0, BMASK(3, 0));
  7123. ahb_mod(ppd->dd, IBSD(ppd->hw_pidx), 5, 7, 4 << 8, BMASK(11, 8));
  7124. ahb_mod(ppd->dd, IBSD(ppd->hw_pidx), 5, 9, 4 << 0, BMASK(3, 0));
  7125. ahb_mod(ppd->dd, IBSD(ppd->hw_pidx), 5, 10, 4 << 8, BMASK(11, 8));
  7126. /* LoS filter select enabled */
  7127. ahb_mod(ppd->dd, IBSD(ppd->hw_pidx), 5, 9, 1 << 15, 1 << 15);
  7128. /* LoS target data: SDR=4, DDR=2, QDR=1 */
  7129. ibsd_wr_allchans(ppd, 14, (1 << 3), BMASK(5, 3)); /* QDR */
  7130. ibsd_wr_allchans(ppd, 20, (2 << 10), BMASK(12, 10)); /* DDR */
  7131. ibsd_wr_allchans(ppd, 20, (4 << 13), BMASK(15, 13)); /* SDR */
  7132. serdes_7322_los_enable(ppd, 1);
  7133. /* rxbistena; set 0 to avoid effects of it switch later */
  7134. ibsd_wr_allchans(ppd, 9, 0 << 15, 1 << 15);
  7135. /* Configure 4 DFE taps, and only they adapt */
  7136. ibsd_wr_allchans(ppd, 16, 0 << 0, BMASK(1, 0));
  7137. /* gain hi stop 32 (22) (6:1) lo stop 7 (10:7) target 22 (13) (15:11) */
  7138. le_val = (ppd->dd->cspec->r1 || IS_QME(ppd->dd)) ? 0xb6c0 : 0x6bac;
  7139. ibsd_wr_allchans(ppd, 21, le_val, 0xfffe);
  7140. /*
  7141. * Set receive adaptation mode. SDR and DDR adaptation are
  7142. * always on, and QDR is initially enabled; later disabled.
  7143. */
  7144. qib_write_kreg_port(ppd, krp_static_adapt_dis(0), 0ULL);
  7145. qib_write_kreg_port(ppd, krp_static_adapt_dis(1), 0ULL);
  7146. qib_write_kreg_port(ppd, krp_static_adapt_dis(2),
  7147. ppd->dd->cspec->r1 ?
  7148. QDR_STATIC_ADAPT_DOWN_R1 : QDR_STATIC_ADAPT_DOWN);
  7149. ppd->cpspec->qdr_dfe_on = 1;
  7150. /* FLoop LOS gate: PPM filter enabled */
  7151. ibsd_wr_allchans(ppd, 38, 0 << 10, 1 << 10);
  7152. /* rx offset center enabled */
  7153. ibsd_wr_allchans(ppd, 12, 1 << 4, 1 << 4);
  7154. if (!ppd->dd->cspec->r1) {
  7155. ibsd_wr_allchans(ppd, 12, 1 << 12, 1 << 12);
  7156. ibsd_wr_allchans(ppd, 12, 2 << 8, 0x0f << 8);
  7157. }
  7158. /* Set the frequency loop bandwidth to 15 */
  7159. ibsd_wr_allchans(ppd, 2, 15 << 5, BMASK(8, 5));
  7160. return 0;
  7161. }
  7162. static int serdes_7322_init_new(struct qib_pportdata *ppd)
  7163. {
  7164. unsigned long tend;
  7165. u32 le_val, rxcaldone;
  7166. int chan, chan_done = (1 << SERDES_CHANS) - 1;
  7167. /* Clear cmode-override, may be set from older driver */
  7168. ahb_mod(ppd->dd, IBSD(ppd->hw_pidx), 5, 10, 0 << 14, 1 << 14);
  7169. /* ensure no tx overrides from earlier driver loads */
  7170. qib_write_kreg_port(ppd, krp_tx_deemph_override,
  7171. SYM_MASK(IBSD_TX_DEEMPHASIS_OVERRIDE_0,
  7172. reset_tx_deemphasis_override));
  7173. /* START OF LSI SUGGESTED SERDES BRINGUP */
  7174. /* Reset - Calibration Setup */
  7175. /* Stop DFE adaptaion */
  7176. ibsd_wr_allchans(ppd, 1, 0, BMASK(9, 1));
  7177. /* Disable LE1 */
  7178. ibsd_wr_allchans(ppd, 13, 0, BMASK(5, 5));
  7179. /* Disable autoadapt for LE1 */
  7180. ibsd_wr_allchans(ppd, 1, 0, BMASK(15, 15));
  7181. /* Disable LE2 */
  7182. ibsd_wr_allchans(ppd, 13, 0, BMASK(6, 6));
  7183. /* Disable VGA */
  7184. ibsd_wr_allchans(ppd, 5, 0, BMASK(0, 0));
  7185. /* Disable AFE Offset Cancel */
  7186. ibsd_wr_allchans(ppd, 12, 0, BMASK(12, 12));
  7187. /* Disable Timing Loop */
  7188. ibsd_wr_allchans(ppd, 2, 0, BMASK(3, 3));
  7189. /* Disable Frequency Loop */
  7190. ibsd_wr_allchans(ppd, 2, 0, BMASK(4, 4));
  7191. /* Disable Baseline Wander Correction */
  7192. ibsd_wr_allchans(ppd, 13, 0, BMASK(13, 13));
  7193. /* Disable RX Calibration */
  7194. ibsd_wr_allchans(ppd, 4, 0, BMASK(10, 10));
  7195. /* Disable RX Offset Calibration */
  7196. ibsd_wr_allchans(ppd, 12, 0, BMASK(4, 4));
  7197. /* Select BB CDR */
  7198. ibsd_wr_allchans(ppd, 2, (1 << 15), BMASK(15, 15));
  7199. /* CDR Step Size */
  7200. ibsd_wr_allchans(ppd, 5, 0, BMASK(9, 8));
  7201. /* Enable phase Calibration */
  7202. ibsd_wr_allchans(ppd, 12, (1 << 5), BMASK(5, 5));
  7203. /* DFE Bandwidth [2:14-12] */
  7204. ibsd_wr_allchans(ppd, 2, (4 << 12), BMASK(14, 12));
  7205. /* DFE Config (4 taps only) */
  7206. ibsd_wr_allchans(ppd, 16, 0, BMASK(1, 0));
  7207. /* Gain Loop Bandwidth */
  7208. if (!ppd->dd->cspec->r1) {
  7209. ibsd_wr_allchans(ppd, 12, 1 << 12, BMASK(12, 12));
  7210. ibsd_wr_allchans(ppd, 12, 2 << 8, BMASK(11, 8));
  7211. } else {
  7212. ibsd_wr_allchans(ppd, 19, (3 << 11), BMASK(13, 11));
  7213. }
  7214. /* Baseline Wander Correction Gain [13:4-0] (leave as default) */
  7215. /* Baseline Wander Correction Gain [3:7-5] (leave as default) */
  7216. /* Data Rate Select [5:7-6] (leave as default) */
  7217. /* RX Parallel Word Width [3:10-8] (leave as default) */
  7218. /* RX REST */
  7219. /* Single- or Multi-channel reset */
  7220. /* RX Analog reset */
  7221. /* RX Digital reset */
  7222. ibsd_wr_allchans(ppd, 0, 0, BMASK(15, 13));
  7223. msleep(20);
  7224. /* RX Analog reset */
  7225. ibsd_wr_allchans(ppd, 0, (1 << 14), BMASK(14, 14));
  7226. msleep(20);
  7227. /* RX Digital reset */
  7228. ibsd_wr_allchans(ppd, 0, (1 << 13), BMASK(13, 13));
  7229. msleep(20);
  7230. /* setup LoS params; these are subsystem, so chan == 5 */
  7231. /* LoS filter threshold_count on, ch 0-3, set to 8 */
  7232. ahb_mod(ppd->dd, IBSD(ppd->hw_pidx), 5, 5, 8 << 11, BMASK(14, 11));
  7233. ahb_mod(ppd->dd, IBSD(ppd->hw_pidx), 5, 7, 8 << 4, BMASK(7, 4));
  7234. ahb_mod(ppd->dd, IBSD(ppd->hw_pidx), 5, 8, 8 << 11, BMASK(14, 11));
  7235. ahb_mod(ppd->dd, IBSD(ppd->hw_pidx), 5, 10, 8 << 4, BMASK(7, 4));
  7236. /* LoS filter threshold_count off, ch 0-3, set to 4 */
  7237. ahb_mod(ppd->dd, IBSD(ppd->hw_pidx), 5, 6, 4 << 0, BMASK(3, 0));
  7238. ahb_mod(ppd->dd, IBSD(ppd->hw_pidx), 5, 7, 4 << 8, BMASK(11, 8));
  7239. ahb_mod(ppd->dd, IBSD(ppd->hw_pidx), 5, 9, 4 << 0, BMASK(3, 0));
  7240. ahb_mod(ppd->dd, IBSD(ppd->hw_pidx), 5, 10, 4 << 8, BMASK(11, 8));
  7241. /* LoS filter select enabled */
  7242. ahb_mod(ppd->dd, IBSD(ppd->hw_pidx), 5, 9, 1 << 15, 1 << 15);
  7243. /* LoS target data: SDR=4, DDR=2, QDR=1 */
  7244. ibsd_wr_allchans(ppd, 14, (1 << 3), BMASK(5, 3)); /* QDR */
  7245. ibsd_wr_allchans(ppd, 20, (2 << 10), BMASK(12, 10)); /* DDR */
  7246. ibsd_wr_allchans(ppd, 20, (4 << 13), BMASK(15, 13)); /* SDR */
  7247. /* Turn on LOS on initial SERDES init */
  7248. serdes_7322_los_enable(ppd, 1);
  7249. /* FLoop LOS gate: PPM filter enabled */
  7250. ibsd_wr_allchans(ppd, 38, 0 << 10, 1 << 10);
  7251. /* RX LATCH CALIBRATION */
  7252. /* Enable Eyefinder Phase Calibration latch */
  7253. ibsd_wr_allchans(ppd, 15, 1, BMASK(0, 0));
  7254. /* Enable RX Offset Calibration latch */
  7255. ibsd_wr_allchans(ppd, 12, (1 << 4), BMASK(4, 4));
  7256. msleep(20);
  7257. /* Start Calibration */
  7258. ibsd_wr_allchans(ppd, 4, (1 << 10), BMASK(10, 10));
  7259. tend = jiffies + msecs_to_jiffies(500);
  7260. while (chan_done && !time_is_before_jiffies(tend)) {
  7261. msleep(20);
  7262. for (chan = 0; chan < SERDES_CHANS; ++chan) {
  7263. rxcaldone = ahb_mod(ppd->dd, IBSD(ppd->hw_pidx),
  7264. (chan + (chan >> 1)),
  7265. 25, 0, 0);
  7266. if ((~rxcaldone & (u32)BMASK(9, 9)) == 0 &&
  7267. (~chan_done & (1 << chan)) == 0)
  7268. chan_done &= ~(1 << chan);
  7269. }
  7270. }
  7271. if (chan_done) {
  7272. pr_info("Serdes %d calibration not done after .5 sec: 0x%x\n",
  7273. IBSD(ppd->hw_pidx), chan_done);
  7274. } else {
  7275. for (chan = 0; chan < SERDES_CHANS; ++chan) {
  7276. rxcaldone = ahb_mod(ppd->dd, IBSD(ppd->hw_pidx),
  7277. (chan + (chan >> 1)),
  7278. 25, 0, 0);
  7279. if ((~rxcaldone & (u32)BMASK(10, 10)) == 0)
  7280. pr_info("Serdes %d chan %d calibration failed\n",
  7281. IBSD(ppd->hw_pidx), chan);
  7282. }
  7283. }
  7284. /* Turn off Calibration */
  7285. ibsd_wr_allchans(ppd, 4, 0, BMASK(10, 10));
  7286. msleep(20);
  7287. /* BRING RX UP */
  7288. /* Set LE2 value (May be overridden in qsfp_7322_event) */
  7289. le_val = IS_QME(ppd->dd) ? LE2_QME : LE2_DEFAULT;
  7290. ibsd_wr_allchans(ppd, 13, (le_val << 7), BMASK(9, 7));
  7291. /* Set LE2 Loop bandwidth */
  7292. ibsd_wr_allchans(ppd, 3, (7 << 5), BMASK(7, 5));
  7293. /* Enable LE2 */
  7294. ibsd_wr_allchans(ppd, 13, (1 << 6), BMASK(6, 6));
  7295. msleep(20);
  7296. /* Enable H0 only */
  7297. ibsd_wr_allchans(ppd, 1, 1, BMASK(9, 1));
  7298. /* gain hi stop 32 (22) (6:1) lo stop 7 (10:7) target 22 (13) (15:11) */
  7299. le_val = (ppd->dd->cspec->r1 || IS_QME(ppd->dd)) ? 0xb6c0 : 0x6bac;
  7300. ibsd_wr_allchans(ppd, 21, le_val, 0xfffe);
  7301. /* Enable VGA */
  7302. ibsd_wr_allchans(ppd, 5, 0, BMASK(0, 0));
  7303. msleep(20);
  7304. /* Set Frequency Loop Bandwidth */
  7305. ibsd_wr_allchans(ppd, 2, (15 << 5), BMASK(8, 5));
  7306. /* Enable Frequency Loop */
  7307. ibsd_wr_allchans(ppd, 2, (1 << 4), BMASK(4, 4));
  7308. /* Set Timing Loop Bandwidth */
  7309. ibsd_wr_allchans(ppd, 2, 0, BMASK(11, 9));
  7310. /* Enable Timing Loop */
  7311. ibsd_wr_allchans(ppd, 2, (1 << 3), BMASK(3, 3));
  7312. msleep(50);
  7313. /* Enable DFE
  7314. * Set receive adaptation mode. SDR and DDR adaptation are
  7315. * always on, and QDR is initially enabled; later disabled.
  7316. */
  7317. qib_write_kreg_port(ppd, krp_static_adapt_dis(0), 0ULL);
  7318. qib_write_kreg_port(ppd, krp_static_adapt_dis(1), 0ULL);
  7319. qib_write_kreg_port(ppd, krp_static_adapt_dis(2),
  7320. ppd->dd->cspec->r1 ?
  7321. QDR_STATIC_ADAPT_DOWN_R1 : QDR_STATIC_ADAPT_DOWN);
  7322. ppd->cpspec->qdr_dfe_on = 1;
  7323. /* Disable LE1 */
  7324. ibsd_wr_allchans(ppd, 13, (0 << 5), (1 << 5));
  7325. /* Disable auto adapt for LE1 */
  7326. ibsd_wr_allchans(ppd, 1, (0 << 15), BMASK(15, 15));
  7327. msleep(20);
  7328. /* Enable AFE Offset Cancel */
  7329. ibsd_wr_allchans(ppd, 12, (1 << 12), BMASK(12, 12));
  7330. /* Enable Baseline Wander Correction */
  7331. ibsd_wr_allchans(ppd, 12, (1 << 13), BMASK(13, 13));
  7332. /* Termination: rxtermctrl_r2d addr 11 bits [12:11] = 1 */
  7333. ibsd_wr_allchans(ppd, 11, (1 << 11), BMASK(12, 11));
  7334. /* VGA output common mode */
  7335. ibsd_wr_allchans(ppd, 12, (3 << 2), BMASK(3, 2));
  7336. /*
  7337. * Initialize the Tx DDS tables. Also done every QSFP event,
  7338. * for adapters with QSFP
  7339. */
  7340. init_txdds_table(ppd, 0);
  7341. return 0;
  7342. }
  7343. /* start adjust QMH serdes parameters */
  7344. static void set_man_code(struct qib_pportdata *ppd, int chan, int code)
  7345. {
  7346. ahb_mod(ppd->dd, IBSD(ppd->hw_pidx), (chan + (chan >> 1)),
  7347. 9, code << 9, 0x3f << 9);
  7348. }
  7349. static void set_man_mode_h1(struct qib_pportdata *ppd, int chan,
  7350. int enable, u32 tapenable)
  7351. {
  7352. if (enable)
  7353. ahb_mod(ppd->dd, IBSD(ppd->hw_pidx), (chan + (chan >> 1)),
  7354. 1, 3 << 10, 0x1f << 10);
  7355. else
  7356. ahb_mod(ppd->dd, IBSD(ppd->hw_pidx), (chan + (chan >> 1)),
  7357. 1, 0, 0x1f << 10);
  7358. }
  7359. /* Set clock to 1, 0, 1, 0 */
  7360. static void clock_man(struct qib_pportdata *ppd, int chan)
  7361. {
  7362. ahb_mod(ppd->dd, IBSD(ppd->hw_pidx), (chan + (chan >> 1)),
  7363. 4, 0x4000, 0x4000);
  7364. ahb_mod(ppd->dd, IBSD(ppd->hw_pidx), (chan + (chan >> 1)),
  7365. 4, 0, 0x4000);
  7366. ahb_mod(ppd->dd, IBSD(ppd->hw_pidx), (chan + (chan >> 1)),
  7367. 4, 0x4000, 0x4000);
  7368. ahb_mod(ppd->dd, IBSD(ppd->hw_pidx), (chan + (chan >> 1)),
  7369. 4, 0, 0x4000);
  7370. }
  7371. /*
  7372. * write the current Tx serdes pre,post,main,amp settings into the serdes.
  7373. * The caller must pass the settings appropriate for the current speed,
  7374. * or not care if they are correct for the current speed.
  7375. */
  7376. static void write_tx_serdes_param(struct qib_pportdata *ppd,
  7377. struct txdds_ent *txdds)
  7378. {
  7379. u64 deemph;
  7380. deemph = qib_read_kreg_port(ppd, krp_tx_deemph_override);
  7381. /* field names for amp, main, post, pre, respectively */
  7382. deemph &= ~(SYM_MASK(IBSD_TX_DEEMPHASIS_OVERRIDE_0, txampcntl_d2a) |
  7383. SYM_MASK(IBSD_TX_DEEMPHASIS_OVERRIDE_0, txc0_ena) |
  7384. SYM_MASK(IBSD_TX_DEEMPHASIS_OVERRIDE_0, txcp1_ena) |
  7385. SYM_MASK(IBSD_TX_DEEMPHASIS_OVERRIDE_0, txcn1_ena));
  7386. deemph |= SYM_MASK(IBSD_TX_DEEMPHASIS_OVERRIDE_0,
  7387. tx_override_deemphasis_select);
  7388. deemph |= (txdds->amp & SYM_RMASK(IBSD_TX_DEEMPHASIS_OVERRIDE_0,
  7389. txampcntl_d2a)) << SYM_LSB(IBSD_TX_DEEMPHASIS_OVERRIDE_0,
  7390. txampcntl_d2a);
  7391. deemph |= (txdds->main & SYM_RMASK(IBSD_TX_DEEMPHASIS_OVERRIDE_0,
  7392. txc0_ena)) << SYM_LSB(IBSD_TX_DEEMPHASIS_OVERRIDE_0,
  7393. txc0_ena);
  7394. deemph |= (txdds->post & SYM_RMASK(IBSD_TX_DEEMPHASIS_OVERRIDE_0,
  7395. txcp1_ena)) << SYM_LSB(IBSD_TX_DEEMPHASIS_OVERRIDE_0,
  7396. txcp1_ena);
  7397. deemph |= (txdds->pre & SYM_RMASK(IBSD_TX_DEEMPHASIS_OVERRIDE_0,
  7398. txcn1_ena)) << SYM_LSB(IBSD_TX_DEEMPHASIS_OVERRIDE_0,
  7399. txcn1_ena);
  7400. qib_write_kreg_port(ppd, krp_tx_deemph_override, deemph);
  7401. }
  7402. /*
  7403. * Set the parameters for mez cards on link bounce, so they are
  7404. * always exactly what was requested. Similar logic to init_txdds
  7405. * but does just the serdes.
  7406. */
  7407. static void adj_tx_serdes(struct qib_pportdata *ppd)
  7408. {
  7409. const struct txdds_ent *sdr_dds, *ddr_dds, *qdr_dds;
  7410. struct txdds_ent *dds;
  7411. find_best_ent(ppd, &sdr_dds, &ddr_dds, &qdr_dds, 1);
  7412. dds = (struct txdds_ent *)(ppd->link_speed_active == QIB_IB_QDR ?
  7413. qdr_dds : (ppd->link_speed_active == QIB_IB_DDR ?
  7414. ddr_dds : sdr_dds));
  7415. write_tx_serdes_param(ppd, dds);
  7416. }
  7417. /* set QDR forced value for H1, if needed */
  7418. static void force_h1(struct qib_pportdata *ppd)
  7419. {
  7420. int chan;
  7421. ppd->cpspec->qdr_reforce = 0;
  7422. if (!ppd->dd->cspec->r1)
  7423. return;
  7424. for (chan = 0; chan < SERDES_CHANS; chan++) {
  7425. set_man_mode_h1(ppd, chan, 1, 0);
  7426. set_man_code(ppd, chan, ppd->cpspec->h1_val);
  7427. clock_man(ppd, chan);
  7428. set_man_mode_h1(ppd, chan, 0, 0);
  7429. }
  7430. }
  7431. #define SJA_EN SYM_MASK(SPC_JTAG_ACCESS_REG, SPC_JTAG_ACCESS_EN)
  7432. #define BISTEN_LSB SYM_LSB(SPC_JTAG_ACCESS_REG, bist_en)
  7433. #define R_OPCODE_LSB 3
  7434. #define R_OP_NOP 0
  7435. #define R_OP_SHIFT 2
  7436. #define R_OP_UPDATE 3
  7437. #define R_TDI_LSB 2
  7438. #define R_TDO_LSB 1
  7439. #define R_RDY 1
  7440. static int qib_r_grab(struct qib_devdata *dd)
  7441. {
  7442. u64 val;
  7443. val = SJA_EN;
  7444. qib_write_kreg(dd, kr_r_access, val);
  7445. qib_read_kreg32(dd, kr_scratch);
  7446. return 0;
  7447. }
  7448. /* qib_r_wait_for_rdy() not only waits for the ready bit, it
  7449. * returns the current state of R_TDO
  7450. */
  7451. static int qib_r_wait_for_rdy(struct qib_devdata *dd)
  7452. {
  7453. u64 val;
  7454. int timeout;
  7455. for (timeout = 0; timeout < 100 ; ++timeout) {
  7456. val = qib_read_kreg32(dd, kr_r_access);
  7457. if (val & R_RDY)
  7458. return (val >> R_TDO_LSB) & 1;
  7459. }
  7460. return -1;
  7461. }
  7462. static int qib_r_shift(struct qib_devdata *dd, int bisten,
  7463. int len, u8 *inp, u8 *outp)
  7464. {
  7465. u64 valbase, val;
  7466. int ret, pos;
  7467. valbase = SJA_EN | (bisten << BISTEN_LSB) |
  7468. (R_OP_SHIFT << R_OPCODE_LSB);
  7469. ret = qib_r_wait_for_rdy(dd);
  7470. if (ret < 0)
  7471. goto bail;
  7472. for (pos = 0; pos < len; ++pos) {
  7473. val = valbase;
  7474. if (outp) {
  7475. outp[pos >> 3] &= ~(1 << (pos & 7));
  7476. outp[pos >> 3] |= (ret << (pos & 7));
  7477. }
  7478. if (inp) {
  7479. int tdi = inp[pos >> 3] >> (pos & 7);
  7480. val |= ((tdi & 1) << R_TDI_LSB);
  7481. }
  7482. qib_write_kreg(dd, kr_r_access, val);
  7483. qib_read_kreg32(dd, kr_scratch);
  7484. ret = qib_r_wait_for_rdy(dd);
  7485. if (ret < 0)
  7486. break;
  7487. }
  7488. /* Restore to NOP between operations. */
  7489. val = SJA_EN | (bisten << BISTEN_LSB);
  7490. qib_write_kreg(dd, kr_r_access, val);
  7491. qib_read_kreg32(dd, kr_scratch);
  7492. ret = qib_r_wait_for_rdy(dd);
  7493. if (ret >= 0)
  7494. ret = pos;
  7495. bail:
  7496. return ret;
  7497. }
  7498. static int qib_r_update(struct qib_devdata *dd, int bisten)
  7499. {
  7500. u64 val;
  7501. int ret;
  7502. val = SJA_EN | (bisten << BISTEN_LSB) | (R_OP_UPDATE << R_OPCODE_LSB);
  7503. ret = qib_r_wait_for_rdy(dd);
  7504. if (ret >= 0) {
  7505. qib_write_kreg(dd, kr_r_access, val);
  7506. qib_read_kreg32(dd, kr_scratch);
  7507. }
  7508. return ret;
  7509. }
  7510. #define BISTEN_PORT_SEL 15
  7511. #define LEN_PORT_SEL 625
  7512. #define BISTEN_AT 17
  7513. #define LEN_AT 156
  7514. #define BISTEN_ETM 16
  7515. #define LEN_ETM 632
  7516. #define BIT2BYTE(x) (((x) + BITS_PER_BYTE - 1) / BITS_PER_BYTE)
  7517. /* these are common for all IB port use cases. */
  7518. static u8 reset_at[BIT2BYTE(LEN_AT)] = {
  7519. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  7520. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00,
  7521. };
  7522. static u8 reset_atetm[BIT2BYTE(LEN_ETM)] = {
  7523. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  7524. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  7525. 0x00, 0x00, 0x00, 0x80, 0xe3, 0x81, 0x73, 0x3c, 0x70, 0x8e,
  7526. 0x07, 0xce, 0xf1, 0xc0, 0x39, 0x1e, 0x38, 0xc7, 0x03, 0xe7,
  7527. 0x78, 0xe0, 0x1c, 0x0f, 0x9c, 0x7f, 0x80, 0x73, 0x0f, 0x70,
  7528. 0xde, 0x01, 0xce, 0x39, 0xc0, 0xf9, 0x06, 0x38, 0xd7, 0x00,
  7529. 0xe7, 0x19, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  7530. 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
  7531. };
  7532. static u8 at[BIT2BYTE(LEN_AT)] = {
  7533. 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00,
  7534. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00,
  7535. };
  7536. /* used for IB1 or IB2, only one in use */
  7537. static u8 atetm_1port[BIT2BYTE(LEN_ETM)] = {
  7538. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  7539. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  7540. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  7541. 0x00, 0x10, 0xf2, 0x80, 0x83, 0x1e, 0x38, 0x00, 0x00, 0x00,
  7542. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  7543. 0x00, 0x00, 0x50, 0xf4, 0x41, 0x00, 0x18, 0x78, 0xc8, 0x03,
  7544. 0x07, 0x7b, 0xa0, 0x3e, 0x00, 0x02, 0x00, 0x00, 0x18, 0x00,
  7545. 0x18, 0x00, 0x00, 0x00, 0x00, 0x4b, 0x00, 0x00, 0x00,
  7546. };
  7547. /* used when both IB1 and IB2 are in use */
  7548. static u8 atetm_2port[BIT2BYTE(LEN_ETM)] = {
  7549. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  7550. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x79,
  7551. 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  7552. 0x00, 0x00, 0xf8, 0x80, 0x83, 0x1e, 0x38, 0xe0, 0x03, 0x05,
  7553. 0x7b, 0xa0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80,
  7554. 0xa2, 0x0f, 0x50, 0xf4, 0x41, 0x00, 0x18, 0x78, 0xd1, 0x07,
  7555. 0x02, 0x7c, 0x80, 0x3e, 0x00, 0x02, 0x00, 0x00, 0x3e, 0x00,
  7556. 0x02, 0x00, 0x00, 0x00, 0x00, 0x64, 0x00, 0x00, 0x00,
  7557. };
  7558. /* used when only IB1 is in use */
  7559. static u8 portsel_port1[BIT2BYTE(LEN_PORT_SEL)] = {
  7560. 0x32, 0x65, 0xa4, 0x7b, 0x10, 0x98, 0xdc, 0xfe, 0x13, 0x13,
  7561. 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x73, 0x0c, 0x0c, 0x0c,
  7562. 0x0c, 0x0c, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13,
  7563. 0x13, 0x78, 0x78, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13,
  7564. 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x74, 0x32,
  7565. 0x32, 0x32, 0x32, 0x32, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14,
  7566. 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14,
  7567. 0x14, 0x14, 0x9f, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
  7568. };
  7569. /* used when only IB2 is in use */
  7570. static u8 portsel_port2[BIT2BYTE(LEN_PORT_SEL)] = {
  7571. 0x32, 0x65, 0xa4, 0x7b, 0x10, 0x98, 0xdc, 0xfe, 0x39, 0x39,
  7572. 0x39, 0x39, 0x39, 0x39, 0x39, 0x39, 0x73, 0x32, 0x32, 0x32,
  7573. 0x32, 0x32, 0x39, 0x39, 0x39, 0x39, 0x39, 0x39, 0x39, 0x39,
  7574. 0x39, 0x78, 0x78, 0x39, 0x39, 0x39, 0x39, 0x39, 0x39, 0x39,
  7575. 0x3a, 0x3a, 0x3a, 0x3a, 0x3a, 0x3a, 0x3a, 0x3a, 0x74, 0x32,
  7576. 0x32, 0x32, 0x32, 0x32, 0x3a, 0x3a, 0x3a, 0x3a, 0x3a, 0x3a,
  7577. 0x3a, 0x3a, 0x3a, 0x3a, 0x3a, 0x3a, 0x3a, 0x3a, 0x3a, 0x3a,
  7578. 0x3a, 0x3a, 0x9f, 0x01, 0x00, 0x00, 0x00, 0x00, 0x01,
  7579. };
  7580. /* used when both IB1 and IB2 are in use */
  7581. static u8 portsel_2port[BIT2BYTE(LEN_PORT_SEL)] = {
  7582. 0x32, 0xba, 0x54, 0x76, 0x10, 0x98, 0xdc, 0xfe, 0x13, 0x13,
  7583. 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x73, 0x0c, 0x0c, 0x0c,
  7584. 0x0c, 0x0c, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13,
  7585. 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13,
  7586. 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x74, 0x32,
  7587. 0x32, 0x32, 0x32, 0x32, 0x14, 0x14, 0x14, 0x14, 0x14, 0x3a,
  7588. 0x3a, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14,
  7589. 0x14, 0x14, 0x9f, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
  7590. };
  7591. /*
  7592. * Do setup to properly handle IB link recovery; if port is zero, we
  7593. * are initializing to cover both ports; otherwise we are initializing
  7594. * to cover a single port card, or the port has reached INIT and we may
  7595. * need to switch coverage types.
  7596. */
  7597. static void setup_7322_link_recovery(struct qib_pportdata *ppd, u32 both)
  7598. {
  7599. u8 *portsel, *etm;
  7600. struct qib_devdata *dd = ppd->dd;
  7601. if (!ppd->dd->cspec->r1)
  7602. return;
  7603. if (!both) {
  7604. dd->cspec->recovery_ports_initted++;
  7605. ppd->cpspec->recovery_init = 1;
  7606. }
  7607. if (!both && dd->cspec->recovery_ports_initted == 1) {
  7608. portsel = ppd->port == 1 ? portsel_port1 : portsel_port2;
  7609. etm = atetm_1port;
  7610. } else {
  7611. portsel = portsel_2port;
  7612. etm = atetm_2port;
  7613. }
  7614. if (qib_r_grab(dd) < 0 ||
  7615. qib_r_shift(dd, BISTEN_ETM, LEN_ETM, reset_atetm, NULL) < 0 ||
  7616. qib_r_update(dd, BISTEN_ETM) < 0 ||
  7617. qib_r_shift(dd, BISTEN_AT, LEN_AT, reset_at, NULL) < 0 ||
  7618. qib_r_update(dd, BISTEN_AT) < 0 ||
  7619. qib_r_shift(dd, BISTEN_PORT_SEL, LEN_PORT_SEL,
  7620. portsel, NULL) < 0 ||
  7621. qib_r_update(dd, BISTEN_PORT_SEL) < 0 ||
  7622. qib_r_shift(dd, BISTEN_AT, LEN_AT, at, NULL) < 0 ||
  7623. qib_r_update(dd, BISTEN_AT) < 0 ||
  7624. qib_r_shift(dd, BISTEN_ETM, LEN_ETM, etm, NULL) < 0 ||
  7625. qib_r_update(dd, BISTEN_ETM) < 0)
  7626. qib_dev_err(dd, "Failed IB link recovery setup\n");
  7627. }
  7628. static void check_7322_rxe_status(struct qib_pportdata *ppd)
  7629. {
  7630. struct qib_devdata *dd = ppd->dd;
  7631. u64 fmask;
  7632. if (dd->cspec->recovery_ports_initted != 1)
  7633. return; /* rest doesn't apply to dualport */
  7634. qib_write_kreg(dd, kr_control, dd->control |
  7635. SYM_MASK(Control, FreezeMode));
  7636. (void)qib_read_kreg64(dd, kr_scratch);
  7637. udelay(3); /* ibcreset asserted 400ns, be sure that's over */
  7638. fmask = qib_read_kreg64(dd, kr_act_fmask);
  7639. if (!fmask) {
  7640. /*
  7641. * require a powercycle before we'll work again, and make
  7642. * sure we get no more interrupts, and don't turn off
  7643. * freeze.
  7644. */
  7645. ppd->dd->cspec->stay_in_freeze = 1;
  7646. qib_7322_set_intr_state(ppd->dd, 0);
  7647. qib_write_kreg(dd, kr_fmask, 0ULL);
  7648. qib_dev_err(dd, "HCA unusable until powercycled\n");
  7649. return; /* eventually reset */
  7650. }
  7651. qib_write_kreg(ppd->dd, kr_hwerrclear,
  7652. SYM_MASK(HwErrClear, IBSerdesPClkNotDetectClear_1));
  7653. /* don't do the full clear_freeze(), not needed for this */
  7654. qib_write_kreg(dd, kr_control, dd->control);
  7655. qib_read_kreg32(dd, kr_scratch);
  7656. /* take IBC out of reset */
  7657. if (ppd->link_speed_supported) {
  7658. ppd->cpspec->ibcctrl_a &=
  7659. ~SYM_MASK(IBCCtrlA_0, IBStatIntReductionEn);
  7660. qib_write_kreg_port(ppd, krp_ibcctrl_a,
  7661. ppd->cpspec->ibcctrl_a);
  7662. qib_read_kreg32(dd, kr_scratch);
  7663. if (ppd->lflags & QIBL_IB_LINK_DISABLED)
  7664. qib_set_ib_7322_lstate(ppd, 0,
  7665. QLOGIC_IB_IBCC_LINKINITCMD_DISABLE);
  7666. }
  7667. }