qib_iba7322.c 266 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563
  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. qib_stats.sps_ints++;
  2790. if (dd->int_counter != (u32) -1)
  2791. dd->int_counter++;
  2792. /* handle "errors" of various kinds first, device ahead of port */
  2793. if (unlikely(istat & (~QIB_I_BITSEXTANT | QIB_I_GPIO |
  2794. QIB_I_C_ERROR | INT_MASK_P(Err, 0) |
  2795. INT_MASK_P(Err, 1))))
  2796. unlikely_7322_intr(dd, istat);
  2797. /*
  2798. * Clear the interrupt bits we found set, relatively early, so we
  2799. * "know" know the chip will have seen this by the time we process
  2800. * the queue, and will re-interrupt if necessary. The processor
  2801. * itself won't take the interrupt again until we return.
  2802. */
  2803. qib_write_kreg(dd, kr_intclear, istat);
  2804. /*
  2805. * Handle kernel receive queues before checking for pio buffers
  2806. * available since receives can overflow; piobuf waiters can afford
  2807. * a few extra cycles, since they were waiting anyway.
  2808. */
  2809. ctxtrbits = istat & (QIB_I_RCVAVAIL_MASK | QIB_I_RCVURG_MASK);
  2810. if (ctxtrbits) {
  2811. rmask = (1ULL << QIB_I_RCVAVAIL_LSB) |
  2812. (1ULL << QIB_I_RCVURG_LSB);
  2813. for (i = 0; i < dd->first_user_ctxt; i++) {
  2814. if (ctxtrbits & rmask) {
  2815. ctxtrbits &= ~rmask;
  2816. if (dd->rcd[i])
  2817. qib_kreceive(dd->rcd[i], NULL, &npkts);
  2818. }
  2819. rmask <<= 1;
  2820. }
  2821. if (ctxtrbits) {
  2822. ctxtrbits = (ctxtrbits >> QIB_I_RCVAVAIL_LSB) |
  2823. (ctxtrbits >> QIB_I_RCVURG_LSB);
  2824. qib_handle_urcv(dd, ctxtrbits);
  2825. }
  2826. }
  2827. if (istat & (QIB_I_P_SDMAINT(0) | QIB_I_P_SDMAINT(1)))
  2828. sdma_7322_intr(dd, istat);
  2829. if ((istat & QIB_I_SPIOBUFAVAIL) && (dd->flags & QIB_INITTED))
  2830. qib_ib_piobufavail(dd);
  2831. ret = IRQ_HANDLED;
  2832. bail:
  2833. return ret;
  2834. }
  2835. /*
  2836. * Dedicated receive packet available interrupt handler.
  2837. */
  2838. static irqreturn_t qib_7322pintr(int irq, void *data)
  2839. {
  2840. struct qib_ctxtdata *rcd = data;
  2841. struct qib_devdata *dd = rcd->dd;
  2842. u32 npkts;
  2843. if ((dd->flags & (QIB_PRESENT | QIB_BADINTR)) != QIB_PRESENT)
  2844. /*
  2845. * This return value is not great, but we do not want the
  2846. * interrupt core code to remove our interrupt handler
  2847. * because we don't appear to be handling an interrupt
  2848. * during a chip reset.
  2849. */
  2850. return IRQ_HANDLED;
  2851. qib_stats.sps_ints++;
  2852. if (dd->int_counter != (u32) -1)
  2853. dd->int_counter++;
  2854. /* Clear the interrupt bit we expect to be set. */
  2855. qib_write_kreg(dd, kr_intclear, ((1ULL << QIB_I_RCVAVAIL_LSB) |
  2856. (1ULL << QIB_I_RCVURG_LSB)) << rcd->ctxt);
  2857. qib_kreceive(rcd, NULL, &npkts);
  2858. return IRQ_HANDLED;
  2859. }
  2860. /*
  2861. * Dedicated Send buffer available interrupt handler.
  2862. */
  2863. static irqreturn_t qib_7322bufavail(int irq, void *data)
  2864. {
  2865. struct qib_devdata *dd = data;
  2866. if ((dd->flags & (QIB_PRESENT | QIB_BADINTR)) != QIB_PRESENT)
  2867. /*
  2868. * This return value is not great, but we do not want the
  2869. * interrupt core code to remove our interrupt handler
  2870. * because we don't appear to be handling an interrupt
  2871. * during a chip reset.
  2872. */
  2873. return IRQ_HANDLED;
  2874. qib_stats.sps_ints++;
  2875. if (dd->int_counter != (u32) -1)
  2876. dd->int_counter++;
  2877. /* Clear the interrupt bit we expect to be set. */
  2878. qib_write_kreg(dd, kr_intclear, QIB_I_SPIOBUFAVAIL);
  2879. /* qib_ib_piobufavail() will clear the want PIO interrupt if needed */
  2880. if (dd->flags & QIB_INITTED)
  2881. qib_ib_piobufavail(dd);
  2882. else
  2883. qib_wantpiobuf_7322_intr(dd, 0);
  2884. return IRQ_HANDLED;
  2885. }
  2886. /*
  2887. * Dedicated Send DMA interrupt handler.
  2888. */
  2889. static irqreturn_t sdma_intr(int irq, void *data)
  2890. {
  2891. struct qib_pportdata *ppd = data;
  2892. struct qib_devdata *dd = ppd->dd;
  2893. if ((dd->flags & (QIB_PRESENT | QIB_BADINTR)) != QIB_PRESENT)
  2894. /*
  2895. * This return value is not great, but we do not want the
  2896. * interrupt core code to remove our interrupt handler
  2897. * because we don't appear to be handling an interrupt
  2898. * during a chip reset.
  2899. */
  2900. return IRQ_HANDLED;
  2901. qib_stats.sps_ints++;
  2902. if (dd->int_counter != (u32) -1)
  2903. dd->int_counter++;
  2904. /* Clear the interrupt bit we expect to be set. */
  2905. qib_write_kreg(dd, kr_intclear, ppd->hw_pidx ?
  2906. INT_MASK_P(SDma, 1) : INT_MASK_P(SDma, 0));
  2907. qib_sdma_intr(ppd);
  2908. return IRQ_HANDLED;
  2909. }
  2910. /*
  2911. * Dedicated Send DMA idle interrupt handler.
  2912. */
  2913. static irqreturn_t sdma_idle_intr(int irq, void *data)
  2914. {
  2915. struct qib_pportdata *ppd = data;
  2916. struct qib_devdata *dd = ppd->dd;
  2917. if ((dd->flags & (QIB_PRESENT | QIB_BADINTR)) != QIB_PRESENT)
  2918. /*
  2919. * This return value is not great, but we do not want the
  2920. * interrupt core code to remove our interrupt handler
  2921. * because we don't appear to be handling an interrupt
  2922. * during a chip reset.
  2923. */
  2924. return IRQ_HANDLED;
  2925. qib_stats.sps_ints++;
  2926. if (dd->int_counter != (u32) -1)
  2927. dd->int_counter++;
  2928. /* Clear the interrupt bit we expect to be set. */
  2929. qib_write_kreg(dd, kr_intclear, ppd->hw_pidx ?
  2930. INT_MASK_P(SDmaIdle, 1) : INT_MASK_P(SDmaIdle, 0));
  2931. qib_sdma_intr(ppd);
  2932. return IRQ_HANDLED;
  2933. }
  2934. /*
  2935. * Dedicated Send DMA progress interrupt handler.
  2936. */
  2937. static irqreturn_t sdma_progress_intr(int irq, void *data)
  2938. {
  2939. struct qib_pportdata *ppd = data;
  2940. struct qib_devdata *dd = ppd->dd;
  2941. if ((dd->flags & (QIB_PRESENT | QIB_BADINTR)) != QIB_PRESENT)
  2942. /*
  2943. * This return value is not great, but we do not want the
  2944. * interrupt core code to remove our interrupt handler
  2945. * because we don't appear to be handling an interrupt
  2946. * during a chip reset.
  2947. */
  2948. return IRQ_HANDLED;
  2949. qib_stats.sps_ints++;
  2950. if (dd->int_counter != (u32) -1)
  2951. dd->int_counter++;
  2952. /* Clear the interrupt bit we expect to be set. */
  2953. qib_write_kreg(dd, kr_intclear, ppd->hw_pidx ?
  2954. INT_MASK_P(SDmaProgress, 1) :
  2955. INT_MASK_P(SDmaProgress, 0));
  2956. qib_sdma_intr(ppd);
  2957. return IRQ_HANDLED;
  2958. }
  2959. /*
  2960. * Dedicated Send DMA cleanup interrupt handler.
  2961. */
  2962. static irqreturn_t sdma_cleanup_intr(int irq, void *data)
  2963. {
  2964. struct qib_pportdata *ppd = data;
  2965. struct qib_devdata *dd = ppd->dd;
  2966. if ((dd->flags & (QIB_PRESENT | QIB_BADINTR)) != QIB_PRESENT)
  2967. /*
  2968. * This return value is not great, but we do not want the
  2969. * interrupt core code to remove our interrupt handler
  2970. * because we don't appear to be handling an interrupt
  2971. * during a chip reset.
  2972. */
  2973. return IRQ_HANDLED;
  2974. qib_stats.sps_ints++;
  2975. if (dd->int_counter != (u32) -1)
  2976. dd->int_counter++;
  2977. /* Clear the interrupt bit we expect to be set. */
  2978. qib_write_kreg(dd, kr_intclear, ppd->hw_pidx ?
  2979. INT_MASK_PM(SDmaCleanupDone, 1) :
  2980. INT_MASK_PM(SDmaCleanupDone, 0));
  2981. qib_sdma_process_event(ppd, qib_sdma_event_e20_hw_started);
  2982. return IRQ_HANDLED;
  2983. }
  2984. #ifdef CONFIG_INFINIBAND_QIB_DCA
  2985. static void reset_dca_notifier(struct qib_devdata *dd, struct qib_msix_entry *m)
  2986. {
  2987. if (!m->dca)
  2988. return;
  2989. qib_devinfo(dd->pcidev,
  2990. "Disabling notifier on HCA %d irq %d\n",
  2991. dd->unit,
  2992. m->msix.vector);
  2993. irq_set_affinity_notifier(
  2994. m->msix.vector,
  2995. NULL);
  2996. m->notifier = NULL;
  2997. }
  2998. static void setup_dca_notifier(struct qib_devdata *dd, struct qib_msix_entry *m)
  2999. {
  3000. struct qib_irq_notify *n;
  3001. if (!m->dca)
  3002. return;
  3003. n = kzalloc(sizeof(*n), GFP_KERNEL);
  3004. if (n) {
  3005. int ret;
  3006. m->notifier = n;
  3007. n->notify.irq = m->msix.vector;
  3008. n->notify.notify = qib_irq_notifier_notify;
  3009. n->notify.release = qib_irq_notifier_release;
  3010. n->arg = m->arg;
  3011. n->rcv = m->rcv;
  3012. qib_devinfo(dd->pcidev,
  3013. "set notifier irq %d rcv %d notify %p\n",
  3014. n->notify.irq, n->rcv, &n->notify);
  3015. ret = irq_set_affinity_notifier(
  3016. n->notify.irq,
  3017. &n->notify);
  3018. if (ret) {
  3019. m->notifier = NULL;
  3020. kfree(n);
  3021. }
  3022. }
  3023. }
  3024. #endif
  3025. /*
  3026. * Set up our chip-specific interrupt handler.
  3027. * The interrupt type has already been setup, so
  3028. * we just need to do the registration and error checking.
  3029. * If we are using MSIx interrupts, we may fall back to
  3030. * INTx later, if the interrupt handler doesn't get called
  3031. * within 1/2 second (see verify_interrupt()).
  3032. */
  3033. static void qib_setup_7322_interrupt(struct qib_devdata *dd, int clearpend)
  3034. {
  3035. int ret, i, msixnum;
  3036. u64 redirect[6];
  3037. u64 mask;
  3038. const struct cpumask *local_mask;
  3039. int firstcpu, secondcpu = 0, currrcvcpu = 0;
  3040. if (!dd->num_pports)
  3041. return;
  3042. if (clearpend) {
  3043. /*
  3044. * if not switching interrupt types, be sure interrupts are
  3045. * disabled, and then clear anything pending at this point,
  3046. * because we are starting clean.
  3047. */
  3048. qib_7322_set_intr_state(dd, 0);
  3049. /* clear the reset error, init error/hwerror mask */
  3050. qib_7322_init_hwerrors(dd);
  3051. /* clear any interrupt bits that might be set */
  3052. qib_write_kreg(dd, kr_intclear, ~0ULL);
  3053. /* make sure no pending MSIx intr, and clear diag reg */
  3054. qib_write_kreg(dd, kr_intgranted, ~0ULL);
  3055. qib_write_kreg(dd, kr_vecclr_wo_int, ~0ULL);
  3056. }
  3057. if (!dd->cspec->num_msix_entries) {
  3058. /* Try to get INTx interrupt */
  3059. try_intx:
  3060. if (!dd->pcidev->irq) {
  3061. qib_dev_err(dd,
  3062. "irq is 0, BIOS error? Interrupts won't work\n");
  3063. goto bail;
  3064. }
  3065. ret = request_irq(dd->pcidev->irq, qib_7322intr,
  3066. IRQF_SHARED, QIB_DRV_NAME, dd);
  3067. if (ret) {
  3068. qib_dev_err(dd,
  3069. "Couldn't setup INTx interrupt (irq=%d): %d\n",
  3070. dd->pcidev->irq, ret);
  3071. goto bail;
  3072. }
  3073. dd->cspec->irq = dd->pcidev->irq;
  3074. dd->cspec->main_int_mask = ~0ULL;
  3075. goto bail;
  3076. }
  3077. /* Try to get MSIx interrupts */
  3078. memset(redirect, 0, sizeof redirect);
  3079. mask = ~0ULL;
  3080. msixnum = 0;
  3081. local_mask = cpumask_of_pcibus(dd->pcidev->bus);
  3082. firstcpu = cpumask_first(local_mask);
  3083. if (firstcpu >= nr_cpu_ids ||
  3084. cpumask_weight(local_mask) == num_online_cpus()) {
  3085. local_mask = topology_core_cpumask(0);
  3086. firstcpu = cpumask_first(local_mask);
  3087. }
  3088. if (firstcpu < nr_cpu_ids) {
  3089. secondcpu = cpumask_next(firstcpu, local_mask);
  3090. if (secondcpu >= nr_cpu_ids)
  3091. secondcpu = firstcpu;
  3092. currrcvcpu = secondcpu;
  3093. }
  3094. for (i = 0; msixnum < dd->cspec->num_msix_entries; i++) {
  3095. irq_handler_t handler;
  3096. void *arg;
  3097. u64 val;
  3098. int lsb, reg, sh;
  3099. #ifdef CONFIG_INFINIBAND_QIB_DCA
  3100. int dca = 0;
  3101. #endif
  3102. dd->cspec->msix_entries[msixnum].
  3103. name[sizeof(dd->cspec->msix_entries[msixnum].name) - 1]
  3104. = '\0';
  3105. if (i < ARRAY_SIZE(irq_table)) {
  3106. if (irq_table[i].port) {
  3107. /* skip if for a non-configured port */
  3108. if (irq_table[i].port > dd->num_pports)
  3109. continue;
  3110. arg = dd->pport + irq_table[i].port - 1;
  3111. } else
  3112. arg = dd;
  3113. #ifdef CONFIG_INFINIBAND_QIB_DCA
  3114. dca = irq_table[i].dca;
  3115. #endif
  3116. lsb = irq_table[i].lsb;
  3117. handler = irq_table[i].handler;
  3118. snprintf(dd->cspec->msix_entries[msixnum].name,
  3119. sizeof(dd->cspec->msix_entries[msixnum].name)
  3120. - 1,
  3121. QIB_DRV_NAME "%d%s", dd->unit,
  3122. irq_table[i].name);
  3123. } else {
  3124. unsigned ctxt;
  3125. ctxt = i - ARRAY_SIZE(irq_table);
  3126. /* per krcvq context receive interrupt */
  3127. arg = dd->rcd[ctxt];
  3128. if (!arg)
  3129. continue;
  3130. if (qib_krcvq01_no_msi && ctxt < 2)
  3131. continue;
  3132. #ifdef CONFIG_INFINIBAND_QIB_DCA
  3133. dca = 1;
  3134. #endif
  3135. lsb = QIB_I_RCVAVAIL_LSB + ctxt;
  3136. handler = qib_7322pintr;
  3137. snprintf(dd->cspec->msix_entries[msixnum].name,
  3138. sizeof(dd->cspec->msix_entries[msixnum].name)
  3139. - 1,
  3140. QIB_DRV_NAME "%d (kctx)", dd->unit);
  3141. }
  3142. ret = request_irq(
  3143. dd->cspec->msix_entries[msixnum].msix.vector,
  3144. handler, 0, dd->cspec->msix_entries[msixnum].name,
  3145. arg);
  3146. if (ret) {
  3147. /*
  3148. * Shouldn't happen since the enable said we could
  3149. * have as many as we are trying to setup here.
  3150. */
  3151. qib_dev_err(dd,
  3152. "Couldn't setup MSIx interrupt (vec=%d, irq=%d): %d\n",
  3153. msixnum,
  3154. dd->cspec->msix_entries[msixnum].msix.vector,
  3155. ret);
  3156. qib_7322_nomsix(dd);
  3157. goto try_intx;
  3158. }
  3159. dd->cspec->msix_entries[msixnum].arg = arg;
  3160. #ifdef CONFIG_INFINIBAND_QIB_DCA
  3161. dd->cspec->msix_entries[msixnum].dca = dca;
  3162. dd->cspec->msix_entries[msixnum].rcv =
  3163. handler == qib_7322pintr;
  3164. #endif
  3165. if (lsb >= 0) {
  3166. reg = lsb / IBA7322_REDIRECT_VEC_PER_REG;
  3167. sh = (lsb % IBA7322_REDIRECT_VEC_PER_REG) *
  3168. SYM_LSB(IntRedirect0, vec1);
  3169. mask &= ~(1ULL << lsb);
  3170. redirect[reg] |= ((u64) msixnum) << sh;
  3171. }
  3172. val = qib_read_kreg64(dd, 2 * msixnum + 1 +
  3173. (QIB_7322_MsixTable_OFFS / sizeof(u64)));
  3174. if (firstcpu < nr_cpu_ids &&
  3175. zalloc_cpumask_var(
  3176. &dd->cspec->msix_entries[msixnum].mask,
  3177. GFP_KERNEL)) {
  3178. if (handler == qib_7322pintr) {
  3179. cpumask_set_cpu(currrcvcpu,
  3180. dd->cspec->msix_entries[msixnum].mask);
  3181. currrcvcpu = cpumask_next(currrcvcpu,
  3182. local_mask);
  3183. if (currrcvcpu >= nr_cpu_ids)
  3184. currrcvcpu = secondcpu;
  3185. } else {
  3186. cpumask_set_cpu(firstcpu,
  3187. dd->cspec->msix_entries[msixnum].mask);
  3188. }
  3189. irq_set_affinity_hint(
  3190. dd->cspec->msix_entries[msixnum].msix.vector,
  3191. dd->cspec->msix_entries[msixnum].mask);
  3192. }
  3193. msixnum++;
  3194. }
  3195. /* Initialize the vector mapping */
  3196. for (i = 0; i < ARRAY_SIZE(redirect); i++)
  3197. qib_write_kreg(dd, kr_intredirect + i, redirect[i]);
  3198. dd->cspec->main_int_mask = mask;
  3199. tasklet_init(&dd->error_tasklet, qib_error_tasklet,
  3200. (unsigned long)dd);
  3201. bail:;
  3202. }
  3203. /**
  3204. * qib_7322_boardname - fill in the board name and note features
  3205. * @dd: the qlogic_ib device
  3206. *
  3207. * info will be based on the board revision register
  3208. */
  3209. static unsigned qib_7322_boardname(struct qib_devdata *dd)
  3210. {
  3211. /* Will need enumeration of board-types here */
  3212. char *n;
  3213. u32 boardid, namelen;
  3214. unsigned features = DUAL_PORT_CAP;
  3215. boardid = SYM_FIELD(dd->revision, Revision, BoardID);
  3216. switch (boardid) {
  3217. case 0:
  3218. n = "InfiniPath_QLE7342_Emulation";
  3219. break;
  3220. case 1:
  3221. n = "InfiniPath_QLE7340";
  3222. dd->flags |= QIB_HAS_QSFP;
  3223. features = PORT_SPD_CAP;
  3224. break;
  3225. case 2:
  3226. n = "InfiniPath_QLE7342";
  3227. dd->flags |= QIB_HAS_QSFP;
  3228. break;
  3229. case 3:
  3230. n = "InfiniPath_QMI7342";
  3231. break;
  3232. case 4:
  3233. n = "InfiniPath_Unsupported7342";
  3234. qib_dev_err(dd, "Unsupported version of QMH7342\n");
  3235. features = 0;
  3236. break;
  3237. case BOARD_QMH7342:
  3238. n = "InfiniPath_QMH7342";
  3239. features = 0x24;
  3240. break;
  3241. case BOARD_QME7342:
  3242. n = "InfiniPath_QME7342";
  3243. break;
  3244. case 8:
  3245. n = "InfiniPath_QME7362";
  3246. dd->flags |= QIB_HAS_QSFP;
  3247. break;
  3248. case 15:
  3249. n = "InfiniPath_QLE7342_TEST";
  3250. dd->flags |= QIB_HAS_QSFP;
  3251. break;
  3252. default:
  3253. n = "InfiniPath_QLE73xy_UNKNOWN";
  3254. qib_dev_err(dd, "Unknown 7322 board type %u\n", boardid);
  3255. break;
  3256. }
  3257. dd->board_atten = 1; /* index into txdds_Xdr */
  3258. namelen = strlen(n) + 1;
  3259. dd->boardname = kmalloc(namelen, GFP_KERNEL);
  3260. if (!dd->boardname)
  3261. qib_dev_err(dd, "Failed allocation for board name: %s\n", n);
  3262. else
  3263. snprintf(dd->boardname, namelen, "%s", n);
  3264. snprintf(dd->boardversion, sizeof(dd->boardversion),
  3265. "ChipABI %u.%u, %s, InfiniPath%u %u.%u, SW Compat %u\n",
  3266. QIB_CHIP_VERS_MAJ, QIB_CHIP_VERS_MIN, dd->boardname,
  3267. (unsigned)SYM_FIELD(dd->revision, Revision_R, Arch),
  3268. dd->majrev, dd->minrev,
  3269. (unsigned)SYM_FIELD(dd->revision, Revision_R, SW));
  3270. if (qib_singleport && (features >> PORT_SPD_CAP_SHIFT) & PORT_SPD_CAP) {
  3271. qib_devinfo(dd->pcidev,
  3272. "IB%u: Forced to single port mode by module parameter\n",
  3273. dd->unit);
  3274. features &= PORT_SPD_CAP;
  3275. }
  3276. return features;
  3277. }
  3278. /*
  3279. * This routine sleeps, so it can only be called from user context, not
  3280. * from interrupt context.
  3281. */
  3282. static int qib_do_7322_reset(struct qib_devdata *dd)
  3283. {
  3284. u64 val;
  3285. u64 *msix_vecsave;
  3286. int i, msix_entries, ret = 1;
  3287. u16 cmdval;
  3288. u8 int_line, clinesz;
  3289. unsigned long flags;
  3290. /* Use dev_err so it shows up in logs, etc. */
  3291. qib_dev_err(dd, "Resetting InfiniPath unit %u\n", dd->unit);
  3292. qib_pcie_getcmd(dd, &cmdval, &int_line, &clinesz);
  3293. msix_entries = dd->cspec->num_msix_entries;
  3294. /* no interrupts till re-initted */
  3295. qib_7322_set_intr_state(dd, 0);
  3296. if (msix_entries) {
  3297. qib_7322_nomsix(dd);
  3298. /* can be up to 512 bytes, too big for stack */
  3299. msix_vecsave = kmalloc(2 * dd->cspec->num_msix_entries *
  3300. sizeof(u64), GFP_KERNEL);
  3301. if (!msix_vecsave)
  3302. qib_dev_err(dd, "No mem to save MSIx data\n");
  3303. } else
  3304. msix_vecsave = NULL;
  3305. /*
  3306. * Core PCI (as of 2.6.18) doesn't save or rewrite the full vector
  3307. * info that is set up by the BIOS, so we have to save and restore
  3308. * it ourselves. There is some risk something could change it,
  3309. * after we save it, but since we have disabled the MSIx, it
  3310. * shouldn't be touched...
  3311. */
  3312. for (i = 0; i < msix_entries; i++) {
  3313. u64 vecaddr, vecdata;
  3314. vecaddr = qib_read_kreg64(dd, 2 * i +
  3315. (QIB_7322_MsixTable_OFFS / sizeof(u64)));
  3316. vecdata = qib_read_kreg64(dd, 1 + 2 * i +
  3317. (QIB_7322_MsixTable_OFFS / sizeof(u64)));
  3318. if (msix_vecsave) {
  3319. msix_vecsave[2 * i] = vecaddr;
  3320. /* save it without the masked bit set */
  3321. msix_vecsave[1 + 2 * i] = vecdata & ~0x100000000ULL;
  3322. }
  3323. }
  3324. dd->pport->cpspec->ibdeltainprog = 0;
  3325. dd->pport->cpspec->ibsymdelta = 0;
  3326. dd->pport->cpspec->iblnkerrdelta = 0;
  3327. dd->pport->cpspec->ibmalfdelta = 0;
  3328. dd->int_counter = 0; /* so we check interrupts work again */
  3329. /*
  3330. * Keep chip from being accessed until we are ready. Use
  3331. * writeq() directly, to allow the write even though QIB_PRESENT
  3332. * isn't set.
  3333. */
  3334. dd->flags &= ~(QIB_INITTED | QIB_PRESENT | QIB_BADINTR);
  3335. dd->flags |= QIB_DOING_RESET;
  3336. val = dd->control | QLOGIC_IB_C_RESET;
  3337. writeq(val, &dd->kregbase[kr_control]);
  3338. for (i = 1; i <= 5; i++) {
  3339. /*
  3340. * Allow MBIST, etc. to complete; longer on each retry.
  3341. * We sometimes get machine checks from bus timeout if no
  3342. * response, so for now, make it *really* long.
  3343. */
  3344. msleep(1000 + (1 + i) * 3000);
  3345. qib_pcie_reenable(dd, cmdval, int_line, clinesz);
  3346. /*
  3347. * Use readq directly, so we don't need to mark it as PRESENT
  3348. * until we get a successful indication that all is well.
  3349. */
  3350. val = readq(&dd->kregbase[kr_revision]);
  3351. if (val == dd->revision)
  3352. break;
  3353. if (i == 5) {
  3354. qib_dev_err(dd,
  3355. "Failed to initialize after reset, unusable\n");
  3356. ret = 0;
  3357. goto bail;
  3358. }
  3359. }
  3360. dd->flags |= QIB_PRESENT; /* it's back */
  3361. if (msix_entries) {
  3362. /* restore the MSIx vector address and data if saved above */
  3363. for (i = 0; i < msix_entries; i++) {
  3364. dd->cspec->msix_entries[i].msix.entry = i;
  3365. if (!msix_vecsave || !msix_vecsave[2 * i])
  3366. continue;
  3367. qib_write_kreg(dd, 2 * i +
  3368. (QIB_7322_MsixTable_OFFS / sizeof(u64)),
  3369. msix_vecsave[2 * i]);
  3370. qib_write_kreg(dd, 1 + 2 * i +
  3371. (QIB_7322_MsixTable_OFFS / sizeof(u64)),
  3372. msix_vecsave[1 + 2 * i]);
  3373. }
  3374. }
  3375. /* initialize the remaining registers. */
  3376. for (i = 0; i < dd->num_pports; ++i)
  3377. write_7322_init_portregs(&dd->pport[i]);
  3378. write_7322_initregs(dd);
  3379. if (qib_pcie_params(dd, dd->lbus_width,
  3380. &dd->cspec->num_msix_entries,
  3381. dd->cspec->msix_entries))
  3382. qib_dev_err(dd,
  3383. "Reset failed to setup PCIe or interrupts; continuing anyway\n");
  3384. qib_setup_7322_interrupt(dd, 1);
  3385. for (i = 0; i < dd->num_pports; ++i) {
  3386. struct qib_pportdata *ppd = &dd->pport[i];
  3387. spin_lock_irqsave(&ppd->lflags_lock, flags);
  3388. ppd->lflags |= QIBL_IB_FORCE_NOTIFY;
  3389. ppd->lflags &= ~QIBL_IB_AUTONEG_FAILED;
  3390. spin_unlock_irqrestore(&ppd->lflags_lock, flags);
  3391. }
  3392. bail:
  3393. dd->flags &= ~QIB_DOING_RESET; /* OK or not, no longer resetting */
  3394. kfree(msix_vecsave);
  3395. return ret;
  3396. }
  3397. /**
  3398. * qib_7322_put_tid - write a TID to the chip
  3399. * @dd: the qlogic_ib device
  3400. * @tidptr: pointer to the expected TID (in chip) to update
  3401. * @tidtype: 0 for eager, 1 for expected
  3402. * @pa: physical address of in memory buffer; tidinvalid if freeing
  3403. */
  3404. static void qib_7322_put_tid(struct qib_devdata *dd, u64 __iomem *tidptr,
  3405. u32 type, unsigned long pa)
  3406. {
  3407. if (!(dd->flags & QIB_PRESENT))
  3408. return;
  3409. if (pa != dd->tidinvalid) {
  3410. u64 chippa = pa >> IBA7322_TID_PA_SHIFT;
  3411. /* paranoia checks */
  3412. if (pa != (chippa << IBA7322_TID_PA_SHIFT)) {
  3413. qib_dev_err(dd, "Physaddr %lx not 2KB aligned!\n",
  3414. pa);
  3415. return;
  3416. }
  3417. if (chippa >= (1UL << IBA7322_TID_SZ_SHIFT)) {
  3418. qib_dev_err(dd,
  3419. "Physical page address 0x%lx larger than supported\n",
  3420. pa);
  3421. return;
  3422. }
  3423. if (type == RCVHQ_RCV_TYPE_EAGER)
  3424. chippa |= dd->tidtemplate;
  3425. else /* for now, always full 4KB page */
  3426. chippa |= IBA7322_TID_SZ_4K;
  3427. pa = chippa;
  3428. }
  3429. writeq(pa, tidptr);
  3430. mmiowb();
  3431. }
  3432. /**
  3433. * qib_7322_clear_tids - clear all TID entries for a ctxt, expected and eager
  3434. * @dd: the qlogic_ib device
  3435. * @ctxt: the ctxt
  3436. *
  3437. * clear all TID entries for a ctxt, expected and eager.
  3438. * Used from qib_close().
  3439. */
  3440. static void qib_7322_clear_tids(struct qib_devdata *dd,
  3441. struct qib_ctxtdata *rcd)
  3442. {
  3443. u64 __iomem *tidbase;
  3444. unsigned long tidinv;
  3445. u32 ctxt;
  3446. int i;
  3447. if (!dd->kregbase || !rcd)
  3448. return;
  3449. ctxt = rcd->ctxt;
  3450. tidinv = dd->tidinvalid;
  3451. tidbase = (u64 __iomem *)
  3452. ((char __iomem *) dd->kregbase +
  3453. dd->rcvtidbase +
  3454. ctxt * dd->rcvtidcnt * sizeof(*tidbase));
  3455. for (i = 0; i < dd->rcvtidcnt; i++)
  3456. qib_7322_put_tid(dd, &tidbase[i], RCVHQ_RCV_TYPE_EXPECTED,
  3457. tidinv);
  3458. tidbase = (u64 __iomem *)
  3459. ((char __iomem *) dd->kregbase +
  3460. dd->rcvegrbase +
  3461. rcd->rcvegr_tid_base * sizeof(*tidbase));
  3462. for (i = 0; i < rcd->rcvegrcnt; i++)
  3463. qib_7322_put_tid(dd, &tidbase[i], RCVHQ_RCV_TYPE_EAGER,
  3464. tidinv);
  3465. }
  3466. /**
  3467. * qib_7322_tidtemplate - setup constants for TID updates
  3468. * @dd: the qlogic_ib device
  3469. *
  3470. * We setup stuff that we use a lot, to avoid calculating each time
  3471. */
  3472. static void qib_7322_tidtemplate(struct qib_devdata *dd)
  3473. {
  3474. /*
  3475. * For now, we always allocate 4KB buffers (at init) so we can
  3476. * receive max size packets. We may want a module parameter to
  3477. * specify 2KB or 4KB and/or make it per port instead of per device
  3478. * for those who want to reduce memory footprint. Note that the
  3479. * rcvhdrentsize size must be large enough to hold the largest
  3480. * IB header (currently 96 bytes) that we expect to handle (plus of
  3481. * course the 2 dwords of RHF).
  3482. */
  3483. if (dd->rcvegrbufsize == 2048)
  3484. dd->tidtemplate = IBA7322_TID_SZ_2K;
  3485. else if (dd->rcvegrbufsize == 4096)
  3486. dd->tidtemplate = IBA7322_TID_SZ_4K;
  3487. dd->tidinvalid = 0;
  3488. }
  3489. /**
  3490. * qib_init_7322_get_base_info - set chip-specific flags for user code
  3491. * @rcd: the qlogic_ib ctxt
  3492. * @kbase: qib_base_info pointer
  3493. *
  3494. * We set the PCIE flag because the lower bandwidth on PCIe vs
  3495. * HyperTransport can affect some user packet algorithims.
  3496. */
  3497. static int qib_7322_get_base_info(struct qib_ctxtdata *rcd,
  3498. struct qib_base_info *kinfo)
  3499. {
  3500. kinfo->spi_runtime_flags |= QIB_RUNTIME_CTXT_MSB_IN_QP |
  3501. QIB_RUNTIME_PCIE | QIB_RUNTIME_NODMA_RTAIL |
  3502. QIB_RUNTIME_HDRSUPP | QIB_RUNTIME_SDMA;
  3503. if (rcd->dd->cspec->r1)
  3504. kinfo->spi_runtime_flags |= QIB_RUNTIME_RCHK;
  3505. if (rcd->dd->flags & QIB_USE_SPCL_TRIG)
  3506. kinfo->spi_runtime_flags |= QIB_RUNTIME_SPECIAL_TRIGGER;
  3507. return 0;
  3508. }
  3509. static struct qib_message_header *
  3510. qib_7322_get_msgheader(struct qib_devdata *dd, __le32 *rhf_addr)
  3511. {
  3512. u32 offset = qib_hdrget_offset(rhf_addr);
  3513. return (struct qib_message_header *)
  3514. (rhf_addr - dd->rhf_offset + offset);
  3515. }
  3516. /*
  3517. * Configure number of contexts.
  3518. */
  3519. static void qib_7322_config_ctxts(struct qib_devdata *dd)
  3520. {
  3521. unsigned long flags;
  3522. u32 nchipctxts;
  3523. nchipctxts = qib_read_kreg32(dd, kr_contextcnt);
  3524. dd->cspec->numctxts = nchipctxts;
  3525. if (qib_n_krcv_queues > 1 && dd->num_pports) {
  3526. dd->first_user_ctxt = NUM_IB_PORTS +
  3527. (qib_n_krcv_queues - 1) * dd->num_pports;
  3528. if (dd->first_user_ctxt > nchipctxts)
  3529. dd->first_user_ctxt = nchipctxts;
  3530. dd->n_krcv_queues = dd->first_user_ctxt / dd->num_pports;
  3531. } else {
  3532. dd->first_user_ctxt = NUM_IB_PORTS;
  3533. dd->n_krcv_queues = 1;
  3534. }
  3535. if (!qib_cfgctxts) {
  3536. int nctxts = dd->first_user_ctxt + num_online_cpus();
  3537. if (nctxts <= 6)
  3538. dd->ctxtcnt = 6;
  3539. else if (nctxts <= 10)
  3540. dd->ctxtcnt = 10;
  3541. else if (nctxts <= nchipctxts)
  3542. dd->ctxtcnt = nchipctxts;
  3543. } else if (qib_cfgctxts < dd->num_pports)
  3544. dd->ctxtcnt = dd->num_pports;
  3545. else if (qib_cfgctxts <= nchipctxts)
  3546. dd->ctxtcnt = qib_cfgctxts;
  3547. if (!dd->ctxtcnt) /* none of the above, set to max */
  3548. dd->ctxtcnt = nchipctxts;
  3549. /*
  3550. * Chip can be configured for 6, 10, or 18 ctxts, and choice
  3551. * affects number of eager TIDs per ctxt (1K, 2K, 4K).
  3552. * Lock to be paranoid about later motion, etc.
  3553. */
  3554. spin_lock_irqsave(&dd->cspec->rcvmod_lock, flags);
  3555. if (dd->ctxtcnt > 10)
  3556. dd->rcvctrl |= 2ULL << SYM_LSB(RcvCtrl, ContextCfg);
  3557. else if (dd->ctxtcnt > 6)
  3558. dd->rcvctrl |= 1ULL << SYM_LSB(RcvCtrl, ContextCfg);
  3559. /* else configure for default 6 receive ctxts */
  3560. /* The XRC opcode is 5. */
  3561. dd->rcvctrl |= 5ULL << SYM_LSB(RcvCtrl, XrcTypeCode);
  3562. /*
  3563. * RcvCtrl *must* be written here so that the
  3564. * chip understands how to change rcvegrcnt below.
  3565. */
  3566. qib_write_kreg(dd, kr_rcvctrl, dd->rcvctrl);
  3567. spin_unlock_irqrestore(&dd->cspec->rcvmod_lock, flags);
  3568. /* kr_rcvegrcnt changes based on the number of contexts enabled */
  3569. dd->cspec->rcvegrcnt = qib_read_kreg32(dd, kr_rcvegrcnt);
  3570. if (qib_rcvhdrcnt)
  3571. dd->rcvhdrcnt = max(dd->cspec->rcvegrcnt, qib_rcvhdrcnt);
  3572. else
  3573. dd->rcvhdrcnt = 2 * max(dd->cspec->rcvegrcnt,
  3574. dd->num_pports > 1 ? 1024U : 2048U);
  3575. }
  3576. static int qib_7322_get_ib_cfg(struct qib_pportdata *ppd, int which)
  3577. {
  3578. int lsb, ret = 0;
  3579. u64 maskr; /* right-justified mask */
  3580. switch (which) {
  3581. case QIB_IB_CFG_LWID_ENB: /* Get allowed Link-width */
  3582. ret = ppd->link_width_enabled;
  3583. goto done;
  3584. case QIB_IB_CFG_LWID: /* Get currently active Link-width */
  3585. ret = ppd->link_width_active;
  3586. goto done;
  3587. case QIB_IB_CFG_SPD_ENB: /* Get allowed Link speeds */
  3588. ret = ppd->link_speed_enabled;
  3589. goto done;
  3590. case QIB_IB_CFG_SPD: /* Get current Link spd */
  3591. ret = ppd->link_speed_active;
  3592. goto done;
  3593. case QIB_IB_CFG_RXPOL_ENB: /* Get Auto-RX-polarity enable */
  3594. lsb = SYM_LSB(IBCCtrlB_0, IB_POLARITY_REV_SUPP);
  3595. maskr = SYM_RMASK(IBCCtrlB_0, IB_POLARITY_REV_SUPP);
  3596. break;
  3597. case QIB_IB_CFG_LREV_ENB: /* Get Auto-Lane-reversal enable */
  3598. lsb = SYM_LSB(IBCCtrlB_0, IB_LANE_REV_SUPPORTED);
  3599. maskr = SYM_RMASK(IBCCtrlB_0, IB_LANE_REV_SUPPORTED);
  3600. break;
  3601. case QIB_IB_CFG_LINKLATENCY:
  3602. ret = qib_read_kreg_port(ppd, krp_ibcstatus_b) &
  3603. SYM_MASK(IBCStatusB_0, LinkRoundTripLatency);
  3604. goto done;
  3605. case QIB_IB_CFG_OP_VLS:
  3606. ret = ppd->vls_operational;
  3607. goto done;
  3608. case QIB_IB_CFG_VL_HIGH_CAP:
  3609. ret = 16;
  3610. goto done;
  3611. case QIB_IB_CFG_VL_LOW_CAP:
  3612. ret = 16;
  3613. goto done;
  3614. case QIB_IB_CFG_OVERRUN_THRESH: /* IB overrun threshold */
  3615. ret = SYM_FIELD(ppd->cpspec->ibcctrl_a, IBCCtrlA_0,
  3616. OverrunThreshold);
  3617. goto done;
  3618. case QIB_IB_CFG_PHYERR_THRESH: /* IB PHY error threshold */
  3619. ret = SYM_FIELD(ppd->cpspec->ibcctrl_a, IBCCtrlA_0,
  3620. PhyerrThreshold);
  3621. goto done;
  3622. case QIB_IB_CFG_LINKDEFAULT: /* IB link default (sleep/poll) */
  3623. /* will only take effect when the link state changes */
  3624. ret = (ppd->cpspec->ibcctrl_a &
  3625. SYM_MASK(IBCCtrlA_0, LinkDownDefaultState)) ?
  3626. IB_LINKINITCMD_SLEEP : IB_LINKINITCMD_POLL;
  3627. goto done;
  3628. case QIB_IB_CFG_HRTBT: /* Get Heartbeat off/enable/auto */
  3629. lsb = IBA7322_IBC_HRTBT_LSB;
  3630. maskr = IBA7322_IBC_HRTBT_RMASK; /* OR of AUTO and ENB */
  3631. break;
  3632. case QIB_IB_CFG_PMA_TICKS:
  3633. /*
  3634. * 0x00 = 10x link transfer rate or 4 nsec. for 2.5Gbs
  3635. * Since the clock is always 250MHz, the value is 3, 1 or 0.
  3636. */
  3637. if (ppd->link_speed_active == QIB_IB_QDR)
  3638. ret = 3;
  3639. else if (ppd->link_speed_active == QIB_IB_DDR)
  3640. ret = 1;
  3641. else
  3642. ret = 0;
  3643. goto done;
  3644. default:
  3645. ret = -EINVAL;
  3646. goto done;
  3647. }
  3648. ret = (int)((ppd->cpspec->ibcctrl_b >> lsb) & maskr);
  3649. done:
  3650. return ret;
  3651. }
  3652. /*
  3653. * Below again cribbed liberally from older version. Do not lean
  3654. * heavily on it.
  3655. */
  3656. #define IBA7322_IBC_DLIDLMC_SHIFT QIB_7322_IBCCtrlB_0_IB_DLID_LSB
  3657. #define IBA7322_IBC_DLIDLMC_MASK (QIB_7322_IBCCtrlB_0_IB_DLID_RMASK \
  3658. | (QIB_7322_IBCCtrlB_0_IB_DLID_MASK_RMASK << 16))
  3659. static int qib_7322_set_ib_cfg(struct qib_pportdata *ppd, int which, u32 val)
  3660. {
  3661. struct qib_devdata *dd = ppd->dd;
  3662. u64 maskr; /* right-justified mask */
  3663. int lsb, ret = 0;
  3664. u16 lcmd, licmd;
  3665. unsigned long flags;
  3666. switch (which) {
  3667. case QIB_IB_CFG_LIDLMC:
  3668. /*
  3669. * Set LID and LMC. Combined to avoid possible hazard
  3670. * caller puts LMC in 16MSbits, DLID in 16LSbits of val
  3671. */
  3672. lsb = IBA7322_IBC_DLIDLMC_SHIFT;
  3673. maskr = IBA7322_IBC_DLIDLMC_MASK;
  3674. /*
  3675. * For header-checking, the SLID in the packet will
  3676. * be masked with SendIBSLMCMask, and compared
  3677. * with SendIBSLIDAssignMask. Make sure we do not
  3678. * set any bits not covered by the mask, or we get
  3679. * false-positives.
  3680. */
  3681. qib_write_kreg_port(ppd, krp_sendslid,
  3682. val & (val >> 16) & SendIBSLIDAssignMask);
  3683. qib_write_kreg_port(ppd, krp_sendslidmask,
  3684. (val >> 16) & SendIBSLMCMask);
  3685. break;
  3686. case QIB_IB_CFG_LWID_ENB: /* set allowed Link-width */
  3687. ppd->link_width_enabled = val;
  3688. /* convert IB value to chip register value */
  3689. if (val == IB_WIDTH_1X)
  3690. val = 0;
  3691. else if (val == IB_WIDTH_4X)
  3692. val = 1;
  3693. else
  3694. val = 3;
  3695. maskr = SYM_RMASK(IBCCtrlB_0, IB_NUM_CHANNELS);
  3696. lsb = SYM_LSB(IBCCtrlB_0, IB_NUM_CHANNELS);
  3697. break;
  3698. case QIB_IB_CFG_SPD_ENB: /* set allowed Link speeds */
  3699. /*
  3700. * As with width, only write the actual register if the
  3701. * link is currently down, otherwise takes effect on next
  3702. * link change. Since setting is being explicitly requested
  3703. * (via MAD or sysfs), clear autoneg failure status if speed
  3704. * autoneg is enabled.
  3705. */
  3706. ppd->link_speed_enabled = val;
  3707. val <<= IBA7322_IBC_SPEED_LSB;
  3708. maskr = IBA7322_IBC_SPEED_MASK | IBA7322_IBC_IBTA_1_2_MASK |
  3709. IBA7322_IBC_MAX_SPEED_MASK;
  3710. if (val & (val - 1)) {
  3711. /* Muliple speeds enabled */
  3712. val |= IBA7322_IBC_IBTA_1_2_MASK |
  3713. IBA7322_IBC_MAX_SPEED_MASK;
  3714. spin_lock_irqsave(&ppd->lflags_lock, flags);
  3715. ppd->lflags &= ~QIBL_IB_AUTONEG_FAILED;
  3716. spin_unlock_irqrestore(&ppd->lflags_lock, flags);
  3717. } else if (val & IBA7322_IBC_SPEED_QDR)
  3718. val |= IBA7322_IBC_IBTA_1_2_MASK;
  3719. /* IBTA 1.2 mode + min/max + speed bits are contiguous */
  3720. lsb = SYM_LSB(IBCCtrlB_0, IB_ENHANCED_MODE);
  3721. break;
  3722. case QIB_IB_CFG_RXPOL_ENB: /* set Auto-RX-polarity enable */
  3723. lsb = SYM_LSB(IBCCtrlB_0, IB_POLARITY_REV_SUPP);
  3724. maskr = SYM_RMASK(IBCCtrlB_0, IB_POLARITY_REV_SUPP);
  3725. break;
  3726. case QIB_IB_CFG_LREV_ENB: /* set Auto-Lane-reversal enable */
  3727. lsb = SYM_LSB(IBCCtrlB_0, IB_LANE_REV_SUPPORTED);
  3728. maskr = SYM_RMASK(IBCCtrlB_0, IB_LANE_REV_SUPPORTED);
  3729. break;
  3730. case QIB_IB_CFG_OVERRUN_THRESH: /* IB overrun threshold */
  3731. maskr = SYM_FIELD(ppd->cpspec->ibcctrl_a, IBCCtrlA_0,
  3732. OverrunThreshold);
  3733. if (maskr != val) {
  3734. ppd->cpspec->ibcctrl_a &=
  3735. ~SYM_MASK(IBCCtrlA_0, OverrunThreshold);
  3736. ppd->cpspec->ibcctrl_a |= (u64) val <<
  3737. SYM_LSB(IBCCtrlA_0, OverrunThreshold);
  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_PHYERR_THRESH: /* IB PHY error threshold */
  3744. maskr = SYM_FIELD(ppd->cpspec->ibcctrl_a, IBCCtrlA_0,
  3745. PhyerrThreshold);
  3746. if (maskr != val) {
  3747. ppd->cpspec->ibcctrl_a &=
  3748. ~SYM_MASK(IBCCtrlA_0, PhyerrThreshold);
  3749. ppd->cpspec->ibcctrl_a |= (u64) val <<
  3750. SYM_LSB(IBCCtrlA_0, PhyerrThreshold);
  3751. qib_write_kreg_port(ppd, krp_ibcctrl_a,
  3752. ppd->cpspec->ibcctrl_a);
  3753. qib_write_kreg(dd, kr_scratch, 0ULL);
  3754. }
  3755. goto bail;
  3756. case QIB_IB_CFG_PKEYS: /* update pkeys */
  3757. maskr = (u64) ppd->pkeys[0] | ((u64) ppd->pkeys[1] << 16) |
  3758. ((u64) ppd->pkeys[2] << 32) |
  3759. ((u64) ppd->pkeys[3] << 48);
  3760. qib_write_kreg_port(ppd, krp_partitionkey, maskr);
  3761. goto bail;
  3762. case QIB_IB_CFG_LINKDEFAULT: /* IB link default (sleep/poll) */
  3763. /* will only take effect when the link state changes */
  3764. if (val == IB_LINKINITCMD_POLL)
  3765. ppd->cpspec->ibcctrl_a &=
  3766. ~SYM_MASK(IBCCtrlA_0, LinkDownDefaultState);
  3767. else /* SLEEP */
  3768. ppd->cpspec->ibcctrl_a |=
  3769. SYM_MASK(IBCCtrlA_0, LinkDownDefaultState);
  3770. qib_write_kreg_port(ppd, krp_ibcctrl_a, ppd->cpspec->ibcctrl_a);
  3771. qib_write_kreg(dd, kr_scratch, 0ULL);
  3772. goto bail;
  3773. case QIB_IB_CFG_MTU: /* update the MTU in IBC */
  3774. /*
  3775. * Update our housekeeping variables, and set IBC max
  3776. * size, same as init code; max IBC is max we allow in
  3777. * buffer, less the qword pbc, plus 1 for ICRC, in dwords
  3778. * Set even if it's unchanged, print debug message only
  3779. * on changes.
  3780. */
  3781. val = (ppd->ibmaxlen >> 2) + 1;
  3782. ppd->cpspec->ibcctrl_a &= ~SYM_MASK(IBCCtrlA_0, MaxPktLen);
  3783. ppd->cpspec->ibcctrl_a |= (u64)val <<
  3784. SYM_LSB(IBCCtrlA_0, MaxPktLen);
  3785. qib_write_kreg_port(ppd, krp_ibcctrl_a,
  3786. ppd->cpspec->ibcctrl_a);
  3787. qib_write_kreg(dd, kr_scratch, 0ULL);
  3788. goto bail;
  3789. case QIB_IB_CFG_LSTATE: /* set the IB link state */
  3790. switch (val & 0xffff0000) {
  3791. case IB_LINKCMD_DOWN:
  3792. lcmd = QLOGIC_IB_IBCC_LINKCMD_DOWN;
  3793. ppd->cpspec->ibmalfusesnap = 1;
  3794. ppd->cpspec->ibmalfsnap = read_7322_creg32_port(ppd,
  3795. crp_errlink);
  3796. if (!ppd->cpspec->ibdeltainprog &&
  3797. qib_compat_ddr_negotiate) {
  3798. ppd->cpspec->ibdeltainprog = 1;
  3799. ppd->cpspec->ibsymsnap =
  3800. read_7322_creg32_port(ppd,
  3801. crp_ibsymbolerr);
  3802. ppd->cpspec->iblnkerrsnap =
  3803. read_7322_creg32_port(ppd,
  3804. crp_iblinkerrrecov);
  3805. }
  3806. break;
  3807. case IB_LINKCMD_ARMED:
  3808. lcmd = QLOGIC_IB_IBCC_LINKCMD_ARMED;
  3809. if (ppd->cpspec->ibmalfusesnap) {
  3810. ppd->cpspec->ibmalfusesnap = 0;
  3811. ppd->cpspec->ibmalfdelta +=
  3812. read_7322_creg32_port(ppd,
  3813. crp_errlink) -
  3814. ppd->cpspec->ibmalfsnap;
  3815. }
  3816. break;
  3817. case IB_LINKCMD_ACTIVE:
  3818. lcmd = QLOGIC_IB_IBCC_LINKCMD_ACTIVE;
  3819. break;
  3820. default:
  3821. ret = -EINVAL;
  3822. qib_dev_err(dd, "bad linkcmd req 0x%x\n", val >> 16);
  3823. goto bail;
  3824. }
  3825. switch (val & 0xffff) {
  3826. case IB_LINKINITCMD_NOP:
  3827. licmd = 0;
  3828. break;
  3829. case IB_LINKINITCMD_POLL:
  3830. licmd = QLOGIC_IB_IBCC_LINKINITCMD_POLL;
  3831. break;
  3832. case IB_LINKINITCMD_SLEEP:
  3833. licmd = QLOGIC_IB_IBCC_LINKINITCMD_SLEEP;
  3834. break;
  3835. case IB_LINKINITCMD_DISABLE:
  3836. licmd = QLOGIC_IB_IBCC_LINKINITCMD_DISABLE;
  3837. ppd->cpspec->chase_end = 0;
  3838. /*
  3839. * stop state chase counter and timer, if running.
  3840. * wait forpending timer, but don't clear .data (ppd)!
  3841. */
  3842. if (ppd->cpspec->chase_timer.expires) {
  3843. del_timer_sync(&ppd->cpspec->chase_timer);
  3844. ppd->cpspec->chase_timer.expires = 0;
  3845. }
  3846. break;
  3847. default:
  3848. ret = -EINVAL;
  3849. qib_dev_err(dd, "bad linkinitcmd req 0x%x\n",
  3850. val & 0xffff);
  3851. goto bail;
  3852. }
  3853. qib_set_ib_7322_lstate(ppd, lcmd, licmd);
  3854. goto bail;
  3855. case QIB_IB_CFG_OP_VLS:
  3856. if (ppd->vls_operational != val) {
  3857. ppd->vls_operational = val;
  3858. set_vls(ppd);
  3859. }
  3860. goto bail;
  3861. case QIB_IB_CFG_VL_HIGH_LIMIT:
  3862. qib_write_kreg_port(ppd, krp_highprio_limit, val);
  3863. goto bail;
  3864. case QIB_IB_CFG_HRTBT: /* set Heartbeat off/enable/auto */
  3865. if (val > 3) {
  3866. ret = -EINVAL;
  3867. goto bail;
  3868. }
  3869. lsb = IBA7322_IBC_HRTBT_LSB;
  3870. maskr = IBA7322_IBC_HRTBT_RMASK; /* OR of AUTO and ENB */
  3871. break;
  3872. case QIB_IB_CFG_PORT:
  3873. /* val is the port number of the switch we are connected to. */
  3874. if (ppd->dd->cspec->r1) {
  3875. cancel_delayed_work(&ppd->cpspec->ipg_work);
  3876. ppd->cpspec->ipg_tries = 0;
  3877. }
  3878. goto bail;
  3879. default:
  3880. ret = -EINVAL;
  3881. goto bail;
  3882. }
  3883. ppd->cpspec->ibcctrl_b &= ~(maskr << lsb);
  3884. ppd->cpspec->ibcctrl_b |= (((u64) val & maskr) << lsb);
  3885. qib_write_kreg_port(ppd, krp_ibcctrl_b, ppd->cpspec->ibcctrl_b);
  3886. qib_write_kreg(dd, kr_scratch, 0);
  3887. bail:
  3888. return ret;
  3889. }
  3890. static int qib_7322_set_loopback(struct qib_pportdata *ppd, const char *what)
  3891. {
  3892. int ret = 0;
  3893. u64 val, ctrlb;
  3894. /* only IBC loopback, may add serdes and xgxs loopbacks later */
  3895. if (!strncmp(what, "ibc", 3)) {
  3896. ppd->cpspec->ibcctrl_a |= SYM_MASK(IBCCtrlA_0,
  3897. Loopback);
  3898. val = 0; /* disable heart beat, so link will come up */
  3899. qib_devinfo(ppd->dd->pcidev, "Enabling IB%u:%u IBC loopback\n",
  3900. ppd->dd->unit, ppd->port);
  3901. } else if (!strncmp(what, "off", 3)) {
  3902. ppd->cpspec->ibcctrl_a &= ~SYM_MASK(IBCCtrlA_0,
  3903. Loopback);
  3904. /* enable heart beat again */
  3905. val = IBA7322_IBC_HRTBT_RMASK << IBA7322_IBC_HRTBT_LSB;
  3906. qib_devinfo(ppd->dd->pcidev,
  3907. "Disabling IB%u:%u IBC loopback (normal)\n",
  3908. ppd->dd->unit, ppd->port);
  3909. } else
  3910. ret = -EINVAL;
  3911. if (!ret) {
  3912. qib_write_kreg_port(ppd, krp_ibcctrl_a,
  3913. ppd->cpspec->ibcctrl_a);
  3914. ctrlb = ppd->cpspec->ibcctrl_b & ~(IBA7322_IBC_HRTBT_MASK
  3915. << IBA7322_IBC_HRTBT_LSB);
  3916. ppd->cpspec->ibcctrl_b = ctrlb | val;
  3917. qib_write_kreg_port(ppd, krp_ibcctrl_b,
  3918. ppd->cpspec->ibcctrl_b);
  3919. qib_write_kreg(ppd->dd, kr_scratch, 0);
  3920. }
  3921. return ret;
  3922. }
  3923. static void get_vl_weights(struct qib_pportdata *ppd, unsigned regno,
  3924. struct ib_vl_weight_elem *vl)
  3925. {
  3926. unsigned i;
  3927. for (i = 0; i < 16; i++, regno++, vl++) {
  3928. u32 val = qib_read_kreg_port(ppd, regno);
  3929. vl->vl = (val >> SYM_LSB(LowPriority0_0, VirtualLane)) &
  3930. SYM_RMASK(LowPriority0_0, VirtualLane);
  3931. vl->weight = (val >> SYM_LSB(LowPriority0_0, Weight)) &
  3932. SYM_RMASK(LowPriority0_0, Weight);
  3933. }
  3934. }
  3935. static void set_vl_weights(struct qib_pportdata *ppd, unsigned regno,
  3936. struct ib_vl_weight_elem *vl)
  3937. {
  3938. unsigned i;
  3939. for (i = 0; i < 16; i++, regno++, vl++) {
  3940. u64 val;
  3941. val = ((vl->vl & SYM_RMASK(LowPriority0_0, VirtualLane)) <<
  3942. SYM_LSB(LowPriority0_0, VirtualLane)) |
  3943. ((vl->weight & SYM_RMASK(LowPriority0_0, Weight)) <<
  3944. SYM_LSB(LowPriority0_0, Weight));
  3945. qib_write_kreg_port(ppd, regno, val);
  3946. }
  3947. if (!(ppd->p_sendctrl & SYM_MASK(SendCtrl_0, IBVLArbiterEn))) {
  3948. struct qib_devdata *dd = ppd->dd;
  3949. unsigned long flags;
  3950. spin_lock_irqsave(&dd->sendctrl_lock, flags);
  3951. ppd->p_sendctrl |= SYM_MASK(SendCtrl_0, IBVLArbiterEn);
  3952. qib_write_kreg_port(ppd, krp_sendctrl, ppd->p_sendctrl);
  3953. qib_write_kreg(dd, kr_scratch, 0);
  3954. spin_unlock_irqrestore(&dd->sendctrl_lock, flags);
  3955. }
  3956. }
  3957. static int qib_7322_get_ib_table(struct qib_pportdata *ppd, int which, void *t)
  3958. {
  3959. switch (which) {
  3960. case QIB_IB_TBL_VL_HIGH_ARB:
  3961. get_vl_weights(ppd, krp_highprio_0, t);
  3962. break;
  3963. case QIB_IB_TBL_VL_LOW_ARB:
  3964. get_vl_weights(ppd, krp_lowprio_0, t);
  3965. break;
  3966. default:
  3967. return -EINVAL;
  3968. }
  3969. return 0;
  3970. }
  3971. static int qib_7322_set_ib_table(struct qib_pportdata *ppd, int which, void *t)
  3972. {
  3973. switch (which) {
  3974. case QIB_IB_TBL_VL_HIGH_ARB:
  3975. set_vl_weights(ppd, krp_highprio_0, t);
  3976. break;
  3977. case QIB_IB_TBL_VL_LOW_ARB:
  3978. set_vl_weights(ppd, krp_lowprio_0, t);
  3979. break;
  3980. default:
  3981. return -EINVAL;
  3982. }
  3983. return 0;
  3984. }
  3985. static void qib_update_7322_usrhead(struct qib_ctxtdata *rcd, u64 hd,
  3986. u32 updegr, u32 egrhd, u32 npkts)
  3987. {
  3988. /*
  3989. * Need to write timeout register before updating rcvhdrhead to ensure
  3990. * that the timer is enabled on reception of a packet.
  3991. */
  3992. if (hd >> IBA7322_HDRHEAD_PKTINT_SHIFT)
  3993. adjust_rcv_timeout(rcd, npkts);
  3994. if (updegr)
  3995. qib_write_ureg(rcd->dd, ur_rcvegrindexhead, egrhd, rcd->ctxt);
  3996. mmiowb();
  3997. qib_write_ureg(rcd->dd, ur_rcvhdrhead, hd, rcd->ctxt);
  3998. qib_write_ureg(rcd->dd, ur_rcvhdrhead, hd, rcd->ctxt);
  3999. mmiowb();
  4000. }
  4001. static u32 qib_7322_hdrqempty(struct qib_ctxtdata *rcd)
  4002. {
  4003. u32 head, tail;
  4004. head = qib_read_ureg32(rcd->dd, ur_rcvhdrhead, rcd->ctxt);
  4005. if (rcd->rcvhdrtail_kvaddr)
  4006. tail = qib_get_rcvhdrtail(rcd);
  4007. else
  4008. tail = qib_read_ureg32(rcd->dd, ur_rcvhdrtail, rcd->ctxt);
  4009. return head == tail;
  4010. }
  4011. #define RCVCTRL_COMMON_MODS (QIB_RCVCTRL_CTXT_ENB | \
  4012. QIB_RCVCTRL_CTXT_DIS | \
  4013. QIB_RCVCTRL_TIDFLOW_ENB | \
  4014. QIB_RCVCTRL_TIDFLOW_DIS | \
  4015. QIB_RCVCTRL_TAILUPD_ENB | \
  4016. QIB_RCVCTRL_TAILUPD_DIS | \
  4017. QIB_RCVCTRL_INTRAVAIL_ENB | \
  4018. QIB_RCVCTRL_INTRAVAIL_DIS | \
  4019. QIB_RCVCTRL_BP_ENB | \
  4020. QIB_RCVCTRL_BP_DIS)
  4021. #define RCVCTRL_PORT_MODS (QIB_RCVCTRL_CTXT_ENB | \
  4022. QIB_RCVCTRL_CTXT_DIS | \
  4023. QIB_RCVCTRL_PKEY_DIS | \
  4024. QIB_RCVCTRL_PKEY_ENB)
  4025. /*
  4026. * Modify the RCVCTRL register in chip-specific way. This
  4027. * is a function because bit positions and (future) register
  4028. * location is chip-specifc, but the needed operations are
  4029. * generic. <op> is a bit-mask because we often want to
  4030. * do multiple modifications.
  4031. */
  4032. static void rcvctrl_7322_mod(struct qib_pportdata *ppd, unsigned int op,
  4033. int ctxt)
  4034. {
  4035. struct qib_devdata *dd = ppd->dd;
  4036. struct qib_ctxtdata *rcd;
  4037. u64 mask, val;
  4038. unsigned long flags;
  4039. spin_lock_irqsave(&dd->cspec->rcvmod_lock, flags);
  4040. if (op & QIB_RCVCTRL_TIDFLOW_ENB)
  4041. dd->rcvctrl |= SYM_MASK(RcvCtrl, TidFlowEnable);
  4042. if (op & QIB_RCVCTRL_TIDFLOW_DIS)
  4043. dd->rcvctrl &= ~SYM_MASK(RcvCtrl, TidFlowEnable);
  4044. if (op & QIB_RCVCTRL_TAILUPD_ENB)
  4045. dd->rcvctrl |= SYM_MASK(RcvCtrl, TailUpd);
  4046. if (op & QIB_RCVCTRL_TAILUPD_DIS)
  4047. dd->rcvctrl &= ~SYM_MASK(RcvCtrl, TailUpd);
  4048. if (op & QIB_RCVCTRL_PKEY_ENB)
  4049. ppd->p_rcvctrl &= ~SYM_MASK(RcvCtrl_0, RcvPartitionKeyDisable);
  4050. if (op & QIB_RCVCTRL_PKEY_DIS)
  4051. ppd->p_rcvctrl |= SYM_MASK(RcvCtrl_0, RcvPartitionKeyDisable);
  4052. if (ctxt < 0) {
  4053. mask = (1ULL << dd->ctxtcnt) - 1;
  4054. rcd = NULL;
  4055. } else {
  4056. mask = (1ULL << ctxt);
  4057. rcd = dd->rcd[ctxt];
  4058. }
  4059. if ((op & QIB_RCVCTRL_CTXT_ENB) && rcd) {
  4060. ppd->p_rcvctrl |=
  4061. (mask << SYM_LSB(RcvCtrl_0, ContextEnableKernel));
  4062. if (!(dd->flags & QIB_NODMA_RTAIL)) {
  4063. op |= QIB_RCVCTRL_TAILUPD_ENB; /* need reg write */
  4064. dd->rcvctrl |= SYM_MASK(RcvCtrl, TailUpd);
  4065. }
  4066. /* Write these registers before the context is enabled. */
  4067. qib_write_kreg_ctxt(dd, krc_rcvhdrtailaddr, ctxt,
  4068. rcd->rcvhdrqtailaddr_phys);
  4069. qib_write_kreg_ctxt(dd, krc_rcvhdraddr, ctxt,
  4070. rcd->rcvhdrq_phys);
  4071. rcd->seq_cnt = 1;
  4072. }
  4073. if (op & QIB_RCVCTRL_CTXT_DIS)
  4074. ppd->p_rcvctrl &=
  4075. ~(mask << SYM_LSB(RcvCtrl_0, ContextEnableKernel));
  4076. if (op & QIB_RCVCTRL_BP_ENB)
  4077. dd->rcvctrl |= mask << SYM_LSB(RcvCtrl, dontDropRHQFull);
  4078. if (op & QIB_RCVCTRL_BP_DIS)
  4079. dd->rcvctrl &= ~(mask << SYM_LSB(RcvCtrl, dontDropRHQFull));
  4080. if (op & QIB_RCVCTRL_INTRAVAIL_ENB)
  4081. dd->rcvctrl |= (mask << SYM_LSB(RcvCtrl, IntrAvail));
  4082. if (op & QIB_RCVCTRL_INTRAVAIL_DIS)
  4083. dd->rcvctrl &= ~(mask << SYM_LSB(RcvCtrl, IntrAvail));
  4084. /*
  4085. * Decide which registers to write depending on the ops enabled.
  4086. * Special case is "flush" (no bits set at all)
  4087. * which needs to write both.
  4088. */
  4089. if (op == 0 || (op & RCVCTRL_COMMON_MODS))
  4090. qib_write_kreg(dd, kr_rcvctrl, dd->rcvctrl);
  4091. if (op == 0 || (op & RCVCTRL_PORT_MODS))
  4092. qib_write_kreg_port(ppd, krp_rcvctrl, ppd->p_rcvctrl);
  4093. if ((op & QIB_RCVCTRL_CTXT_ENB) && dd->rcd[ctxt]) {
  4094. /*
  4095. * Init the context registers also; if we were
  4096. * disabled, tail and head should both be zero
  4097. * already from the enable, but since we don't
  4098. * know, we have to do it explicitly.
  4099. */
  4100. val = qib_read_ureg32(dd, ur_rcvegrindextail, ctxt);
  4101. qib_write_ureg(dd, ur_rcvegrindexhead, val, ctxt);
  4102. /* be sure enabling write seen; hd/tl should be 0 */
  4103. (void) qib_read_kreg32(dd, kr_scratch);
  4104. val = qib_read_ureg32(dd, ur_rcvhdrtail, ctxt);
  4105. dd->rcd[ctxt]->head = val;
  4106. /* If kctxt, interrupt on next receive. */
  4107. if (ctxt < dd->first_user_ctxt)
  4108. val |= dd->rhdrhead_intr_off;
  4109. qib_write_ureg(dd, ur_rcvhdrhead, val, ctxt);
  4110. } else if ((op & QIB_RCVCTRL_INTRAVAIL_ENB) &&
  4111. dd->rcd[ctxt] && dd->rhdrhead_intr_off) {
  4112. /* arm rcv interrupt */
  4113. val = dd->rcd[ctxt]->head | dd->rhdrhead_intr_off;
  4114. qib_write_ureg(dd, ur_rcvhdrhead, val, ctxt);
  4115. }
  4116. if (op & QIB_RCVCTRL_CTXT_DIS) {
  4117. unsigned f;
  4118. /* Now that the context is disabled, clear these registers. */
  4119. if (ctxt >= 0) {
  4120. qib_write_kreg_ctxt(dd, krc_rcvhdrtailaddr, ctxt, 0);
  4121. qib_write_kreg_ctxt(dd, krc_rcvhdraddr, ctxt, 0);
  4122. for (f = 0; f < NUM_TIDFLOWS_CTXT; f++)
  4123. qib_write_ureg(dd, ur_rcvflowtable + f,
  4124. TIDFLOW_ERRBITS, ctxt);
  4125. } else {
  4126. unsigned i;
  4127. for (i = 0; i < dd->cfgctxts; i++) {
  4128. qib_write_kreg_ctxt(dd, krc_rcvhdrtailaddr,
  4129. i, 0);
  4130. qib_write_kreg_ctxt(dd, krc_rcvhdraddr, i, 0);
  4131. for (f = 0; f < NUM_TIDFLOWS_CTXT; f++)
  4132. qib_write_ureg(dd, ur_rcvflowtable + f,
  4133. TIDFLOW_ERRBITS, i);
  4134. }
  4135. }
  4136. }
  4137. spin_unlock_irqrestore(&dd->cspec->rcvmod_lock, flags);
  4138. }
  4139. /*
  4140. * Modify the SENDCTRL register in chip-specific way. This
  4141. * is a function where there are multiple such registers with
  4142. * slightly different layouts.
  4143. * The chip doesn't allow back-to-back sendctrl writes, so write
  4144. * the scratch register after writing sendctrl.
  4145. *
  4146. * Which register is written depends on the operation.
  4147. * Most operate on the common register, while
  4148. * SEND_ENB and SEND_DIS operate on the per-port ones.
  4149. * SEND_ENB is included in common because it can change SPCL_TRIG
  4150. */
  4151. #define SENDCTRL_COMMON_MODS (\
  4152. QIB_SENDCTRL_CLEAR | \
  4153. QIB_SENDCTRL_AVAIL_DIS | \
  4154. QIB_SENDCTRL_AVAIL_ENB | \
  4155. QIB_SENDCTRL_AVAIL_BLIP | \
  4156. QIB_SENDCTRL_DISARM | \
  4157. QIB_SENDCTRL_DISARM_ALL | \
  4158. QIB_SENDCTRL_SEND_ENB)
  4159. #define SENDCTRL_PORT_MODS (\
  4160. QIB_SENDCTRL_CLEAR | \
  4161. QIB_SENDCTRL_SEND_ENB | \
  4162. QIB_SENDCTRL_SEND_DIS | \
  4163. QIB_SENDCTRL_FLUSH)
  4164. static void sendctrl_7322_mod(struct qib_pportdata *ppd, u32 op)
  4165. {
  4166. struct qib_devdata *dd = ppd->dd;
  4167. u64 tmp_dd_sendctrl;
  4168. unsigned long flags;
  4169. spin_lock_irqsave(&dd->sendctrl_lock, flags);
  4170. /* First the dd ones that are "sticky", saved in shadow */
  4171. if (op & QIB_SENDCTRL_CLEAR)
  4172. dd->sendctrl = 0;
  4173. if (op & QIB_SENDCTRL_AVAIL_DIS)
  4174. dd->sendctrl &= ~SYM_MASK(SendCtrl, SendBufAvailUpd);
  4175. else if (op & QIB_SENDCTRL_AVAIL_ENB) {
  4176. dd->sendctrl |= SYM_MASK(SendCtrl, SendBufAvailUpd);
  4177. if (dd->flags & QIB_USE_SPCL_TRIG)
  4178. dd->sendctrl |= SYM_MASK(SendCtrl, SpecialTriggerEn);
  4179. }
  4180. /* Then the ppd ones that are "sticky", saved in shadow */
  4181. if (op & QIB_SENDCTRL_SEND_DIS)
  4182. ppd->p_sendctrl &= ~SYM_MASK(SendCtrl_0, SendEnable);
  4183. else if (op & QIB_SENDCTRL_SEND_ENB)
  4184. ppd->p_sendctrl |= SYM_MASK(SendCtrl_0, SendEnable);
  4185. if (op & QIB_SENDCTRL_DISARM_ALL) {
  4186. u32 i, last;
  4187. tmp_dd_sendctrl = dd->sendctrl;
  4188. last = dd->piobcnt2k + dd->piobcnt4k + NUM_VL15_BUFS;
  4189. /*
  4190. * Disarm any buffers that are not yet launched,
  4191. * disabling updates until done.
  4192. */
  4193. tmp_dd_sendctrl &= ~SYM_MASK(SendCtrl, SendBufAvailUpd);
  4194. for (i = 0; i < last; i++) {
  4195. qib_write_kreg(dd, kr_sendctrl,
  4196. tmp_dd_sendctrl |
  4197. SYM_MASK(SendCtrl, Disarm) | i);
  4198. qib_write_kreg(dd, kr_scratch, 0);
  4199. }
  4200. }
  4201. if (op & QIB_SENDCTRL_FLUSH) {
  4202. u64 tmp_ppd_sendctrl = ppd->p_sendctrl;
  4203. /*
  4204. * Now drain all the fifos. The Abort bit should never be
  4205. * needed, so for now, at least, we don't use it.
  4206. */
  4207. tmp_ppd_sendctrl |=
  4208. SYM_MASK(SendCtrl_0, TxeDrainRmFifo) |
  4209. SYM_MASK(SendCtrl_0, TxeDrainLaFifo) |
  4210. SYM_MASK(SendCtrl_0, TxeBypassIbc);
  4211. qib_write_kreg_port(ppd, krp_sendctrl, tmp_ppd_sendctrl);
  4212. qib_write_kreg(dd, kr_scratch, 0);
  4213. }
  4214. tmp_dd_sendctrl = dd->sendctrl;
  4215. if (op & QIB_SENDCTRL_DISARM)
  4216. tmp_dd_sendctrl |= SYM_MASK(SendCtrl, Disarm) |
  4217. ((op & QIB_7322_SendCtrl_DisarmSendBuf_RMASK) <<
  4218. SYM_LSB(SendCtrl, DisarmSendBuf));
  4219. if ((op & QIB_SENDCTRL_AVAIL_BLIP) &&
  4220. (dd->sendctrl & SYM_MASK(SendCtrl, SendBufAvailUpd)))
  4221. tmp_dd_sendctrl &= ~SYM_MASK(SendCtrl, SendBufAvailUpd);
  4222. if (op == 0 || (op & SENDCTRL_COMMON_MODS)) {
  4223. qib_write_kreg(dd, kr_sendctrl, tmp_dd_sendctrl);
  4224. qib_write_kreg(dd, kr_scratch, 0);
  4225. }
  4226. if (op == 0 || (op & SENDCTRL_PORT_MODS)) {
  4227. qib_write_kreg_port(ppd, krp_sendctrl, ppd->p_sendctrl);
  4228. qib_write_kreg(dd, kr_scratch, 0);
  4229. }
  4230. if (op & QIB_SENDCTRL_AVAIL_BLIP) {
  4231. qib_write_kreg(dd, kr_sendctrl, dd->sendctrl);
  4232. qib_write_kreg(dd, kr_scratch, 0);
  4233. }
  4234. spin_unlock_irqrestore(&dd->sendctrl_lock, flags);
  4235. if (op & QIB_SENDCTRL_FLUSH) {
  4236. u32 v;
  4237. /*
  4238. * ensure writes have hit chip, then do a few
  4239. * more reads, to allow DMA of pioavail registers
  4240. * to occur, so in-memory copy is in sync with
  4241. * the chip. Not always safe to sleep.
  4242. */
  4243. v = qib_read_kreg32(dd, kr_scratch);
  4244. qib_write_kreg(dd, kr_scratch, v);
  4245. v = qib_read_kreg32(dd, kr_scratch);
  4246. qib_write_kreg(dd, kr_scratch, v);
  4247. qib_read_kreg32(dd, kr_scratch);
  4248. }
  4249. }
  4250. #define _PORT_VIRT_FLAG 0x8000U /* "virtual", need adjustments */
  4251. #define _PORT_64BIT_FLAG 0x10000U /* not "virtual", but 64bit */
  4252. #define _PORT_CNTR_IDXMASK 0x7fffU /* mask off flags above */
  4253. /**
  4254. * qib_portcntr_7322 - read a per-port chip counter
  4255. * @ppd: the qlogic_ib pport
  4256. * @creg: the counter to read (not a chip offset)
  4257. */
  4258. static u64 qib_portcntr_7322(struct qib_pportdata *ppd, u32 reg)
  4259. {
  4260. struct qib_devdata *dd = ppd->dd;
  4261. u64 ret = 0ULL;
  4262. u16 creg;
  4263. /* 0xffff for unimplemented or synthesized counters */
  4264. static const u32 xlator[] = {
  4265. [QIBPORTCNTR_PKTSEND] = crp_pktsend | _PORT_64BIT_FLAG,
  4266. [QIBPORTCNTR_WORDSEND] = crp_wordsend | _PORT_64BIT_FLAG,
  4267. [QIBPORTCNTR_PSXMITDATA] = crp_psxmitdatacount,
  4268. [QIBPORTCNTR_PSXMITPKTS] = crp_psxmitpktscount,
  4269. [QIBPORTCNTR_PSXMITWAIT] = crp_psxmitwaitcount,
  4270. [QIBPORTCNTR_SENDSTALL] = crp_sendstall,
  4271. [QIBPORTCNTR_PKTRCV] = crp_pktrcv | _PORT_64BIT_FLAG,
  4272. [QIBPORTCNTR_PSRCVDATA] = crp_psrcvdatacount,
  4273. [QIBPORTCNTR_PSRCVPKTS] = crp_psrcvpktscount,
  4274. [QIBPORTCNTR_RCVEBP] = crp_rcvebp,
  4275. [QIBPORTCNTR_RCVOVFL] = crp_rcvovfl,
  4276. [QIBPORTCNTR_WORDRCV] = crp_wordrcv | _PORT_64BIT_FLAG,
  4277. [QIBPORTCNTR_RXDROPPKT] = 0xffff, /* not needed for 7322 */
  4278. [QIBPORTCNTR_RXLOCALPHYERR] = crp_rxotherlocalphyerr,
  4279. [QIBPORTCNTR_RXVLERR] = crp_rxvlerr,
  4280. [QIBPORTCNTR_ERRICRC] = crp_erricrc,
  4281. [QIBPORTCNTR_ERRVCRC] = crp_errvcrc,
  4282. [QIBPORTCNTR_ERRLPCRC] = crp_errlpcrc,
  4283. [QIBPORTCNTR_BADFORMAT] = crp_badformat,
  4284. [QIBPORTCNTR_ERR_RLEN] = crp_err_rlen,
  4285. [QIBPORTCNTR_IBSYMBOLERR] = crp_ibsymbolerr,
  4286. [QIBPORTCNTR_INVALIDRLEN] = crp_invalidrlen,
  4287. [QIBPORTCNTR_UNSUPVL] = crp_txunsupvl,
  4288. [QIBPORTCNTR_EXCESSBUFOVFL] = crp_excessbufferovfl,
  4289. [QIBPORTCNTR_ERRLINK] = crp_errlink,
  4290. [QIBPORTCNTR_IBLINKDOWN] = crp_iblinkdown,
  4291. [QIBPORTCNTR_IBLINKERRRECOV] = crp_iblinkerrrecov,
  4292. [QIBPORTCNTR_LLI] = crp_locallinkintegrityerr,
  4293. [QIBPORTCNTR_VL15PKTDROP] = crp_vl15droppedpkt,
  4294. [QIBPORTCNTR_ERRPKEY] = crp_errpkey,
  4295. /*
  4296. * the next 3 aren't really counters, but were implemented
  4297. * as counters in older chips, so still get accessed as
  4298. * though they were counters from this code.
  4299. */
  4300. [QIBPORTCNTR_PSINTERVAL] = krp_psinterval,
  4301. [QIBPORTCNTR_PSSTART] = krp_psstart,
  4302. [QIBPORTCNTR_PSSTAT] = krp_psstat,
  4303. /* pseudo-counter, summed for all ports */
  4304. [QIBPORTCNTR_KHDROVFL] = 0xffff,
  4305. };
  4306. if (reg >= ARRAY_SIZE(xlator)) {
  4307. qib_devinfo(ppd->dd->pcidev,
  4308. "Unimplemented portcounter %u\n", reg);
  4309. goto done;
  4310. }
  4311. creg = xlator[reg] & _PORT_CNTR_IDXMASK;
  4312. /* handle non-counters and special cases first */
  4313. if (reg == QIBPORTCNTR_KHDROVFL) {
  4314. int i;
  4315. /* sum over all kernel contexts (skip if mini_init) */
  4316. for (i = 0; dd->rcd && i < dd->first_user_ctxt; i++) {
  4317. struct qib_ctxtdata *rcd = dd->rcd[i];
  4318. if (!rcd || rcd->ppd != ppd)
  4319. continue;
  4320. ret += read_7322_creg32(dd, cr_base_egrovfl + i);
  4321. }
  4322. goto done;
  4323. } else if (reg == QIBPORTCNTR_RXDROPPKT) {
  4324. /*
  4325. * Used as part of the synthesis of port_rcv_errors
  4326. * in the verbs code for IBTA counters. Not needed for 7322,
  4327. * because all the errors are already counted by other cntrs.
  4328. */
  4329. goto done;
  4330. } else if (reg == QIBPORTCNTR_PSINTERVAL ||
  4331. reg == QIBPORTCNTR_PSSTART || reg == QIBPORTCNTR_PSSTAT) {
  4332. /* were counters in older chips, now per-port kernel regs */
  4333. ret = qib_read_kreg_port(ppd, creg);
  4334. goto done;
  4335. }
  4336. /*
  4337. * Only fast increment counters are 64 bits; use 32 bit reads to
  4338. * avoid two independent reads when on Opteron.
  4339. */
  4340. if (xlator[reg] & _PORT_64BIT_FLAG)
  4341. ret = read_7322_creg_port(ppd, creg);
  4342. else
  4343. ret = read_7322_creg32_port(ppd, creg);
  4344. if (creg == crp_ibsymbolerr) {
  4345. if (ppd->cpspec->ibdeltainprog)
  4346. ret -= ret - ppd->cpspec->ibsymsnap;
  4347. ret -= ppd->cpspec->ibsymdelta;
  4348. } else if (creg == crp_iblinkerrrecov) {
  4349. if (ppd->cpspec->ibdeltainprog)
  4350. ret -= ret - ppd->cpspec->iblnkerrsnap;
  4351. ret -= ppd->cpspec->iblnkerrdelta;
  4352. } else if (creg == crp_errlink)
  4353. ret -= ppd->cpspec->ibmalfdelta;
  4354. else if (creg == crp_iblinkdown)
  4355. ret += ppd->cpspec->iblnkdowndelta;
  4356. done:
  4357. return ret;
  4358. }
  4359. /*
  4360. * Device counter names (not port-specific), one line per stat,
  4361. * single string. Used by utilities like ipathstats to print the stats
  4362. * in a way which works for different versions of drivers, without changing
  4363. * the utility. Names need to be 12 chars or less (w/o newline), for proper
  4364. * display by utility.
  4365. * Non-error counters are first.
  4366. * Start of "error" conters is indicated by a leading "E " on the first
  4367. * "error" counter, and doesn't count in label length.
  4368. * The EgrOvfl list needs to be last so we truncate them at the configured
  4369. * context count for the device.
  4370. * cntr7322indices contains the corresponding register indices.
  4371. */
  4372. static const char cntr7322names[] =
  4373. "Interrupts\n"
  4374. "HostBusStall\n"
  4375. "E RxTIDFull\n"
  4376. "RxTIDInvalid\n"
  4377. "RxTIDFloDrop\n" /* 7322 only */
  4378. "Ctxt0EgrOvfl\n"
  4379. "Ctxt1EgrOvfl\n"
  4380. "Ctxt2EgrOvfl\n"
  4381. "Ctxt3EgrOvfl\n"
  4382. "Ctxt4EgrOvfl\n"
  4383. "Ctxt5EgrOvfl\n"
  4384. "Ctxt6EgrOvfl\n"
  4385. "Ctxt7EgrOvfl\n"
  4386. "Ctxt8EgrOvfl\n"
  4387. "Ctxt9EgrOvfl\n"
  4388. "Ctx10EgrOvfl\n"
  4389. "Ctx11EgrOvfl\n"
  4390. "Ctx12EgrOvfl\n"
  4391. "Ctx13EgrOvfl\n"
  4392. "Ctx14EgrOvfl\n"
  4393. "Ctx15EgrOvfl\n"
  4394. "Ctx16EgrOvfl\n"
  4395. "Ctx17EgrOvfl\n"
  4396. ;
  4397. static const u32 cntr7322indices[] = {
  4398. cr_lbint | _PORT_64BIT_FLAG,
  4399. cr_lbstall | _PORT_64BIT_FLAG,
  4400. cr_tidfull,
  4401. cr_tidinvalid,
  4402. cr_rxtidflowdrop,
  4403. cr_base_egrovfl + 0,
  4404. cr_base_egrovfl + 1,
  4405. cr_base_egrovfl + 2,
  4406. cr_base_egrovfl + 3,
  4407. cr_base_egrovfl + 4,
  4408. cr_base_egrovfl + 5,
  4409. cr_base_egrovfl + 6,
  4410. cr_base_egrovfl + 7,
  4411. cr_base_egrovfl + 8,
  4412. cr_base_egrovfl + 9,
  4413. cr_base_egrovfl + 10,
  4414. cr_base_egrovfl + 11,
  4415. cr_base_egrovfl + 12,
  4416. cr_base_egrovfl + 13,
  4417. cr_base_egrovfl + 14,
  4418. cr_base_egrovfl + 15,
  4419. cr_base_egrovfl + 16,
  4420. cr_base_egrovfl + 17,
  4421. };
  4422. /*
  4423. * same as cntr7322names and cntr7322indices, but for port-specific counters.
  4424. * portcntr7322indices is somewhat complicated by some registers needing
  4425. * adjustments of various kinds, and those are ORed with _PORT_VIRT_FLAG
  4426. */
  4427. static const char portcntr7322names[] =
  4428. "TxPkt\n"
  4429. "TxFlowPkt\n"
  4430. "TxWords\n"
  4431. "RxPkt\n"
  4432. "RxFlowPkt\n"
  4433. "RxWords\n"
  4434. "TxFlowStall\n"
  4435. "TxDmaDesc\n" /* 7220 and 7322-only */
  4436. "E RxDlidFltr\n" /* 7220 and 7322-only */
  4437. "IBStatusChng\n"
  4438. "IBLinkDown\n"
  4439. "IBLnkRecov\n"
  4440. "IBRxLinkErr\n"
  4441. "IBSymbolErr\n"
  4442. "RxLLIErr\n"
  4443. "RxBadFormat\n"
  4444. "RxBadLen\n"
  4445. "RxBufOvrfl\n"
  4446. "RxEBP\n"
  4447. "RxFlowCtlErr\n"
  4448. "RxICRCerr\n"
  4449. "RxLPCRCerr\n"
  4450. "RxVCRCerr\n"
  4451. "RxInvalLen\n"
  4452. "RxInvalPKey\n"
  4453. "RxPktDropped\n"
  4454. "TxBadLength\n"
  4455. "TxDropped\n"
  4456. "TxInvalLen\n"
  4457. "TxUnderrun\n"
  4458. "TxUnsupVL\n"
  4459. "RxLclPhyErr\n" /* 7220 and 7322-only from here down */
  4460. "RxVL15Drop\n"
  4461. "RxVlErr\n"
  4462. "XcessBufOvfl\n"
  4463. "RxQPBadCtxt\n" /* 7322-only from here down */
  4464. "TXBadHeader\n"
  4465. ;
  4466. static const u32 portcntr7322indices[] = {
  4467. QIBPORTCNTR_PKTSEND | _PORT_VIRT_FLAG,
  4468. crp_pktsendflow,
  4469. QIBPORTCNTR_WORDSEND | _PORT_VIRT_FLAG,
  4470. QIBPORTCNTR_PKTRCV | _PORT_VIRT_FLAG,
  4471. crp_pktrcvflowctrl,
  4472. QIBPORTCNTR_WORDRCV | _PORT_VIRT_FLAG,
  4473. QIBPORTCNTR_SENDSTALL | _PORT_VIRT_FLAG,
  4474. crp_txsdmadesc | _PORT_64BIT_FLAG,
  4475. crp_rxdlidfltr,
  4476. crp_ibstatuschange,
  4477. QIBPORTCNTR_IBLINKDOWN | _PORT_VIRT_FLAG,
  4478. QIBPORTCNTR_IBLINKERRRECOV | _PORT_VIRT_FLAG,
  4479. QIBPORTCNTR_ERRLINK | _PORT_VIRT_FLAG,
  4480. QIBPORTCNTR_IBSYMBOLERR | _PORT_VIRT_FLAG,
  4481. QIBPORTCNTR_LLI | _PORT_VIRT_FLAG,
  4482. QIBPORTCNTR_BADFORMAT | _PORT_VIRT_FLAG,
  4483. QIBPORTCNTR_ERR_RLEN | _PORT_VIRT_FLAG,
  4484. QIBPORTCNTR_RCVOVFL | _PORT_VIRT_FLAG,
  4485. QIBPORTCNTR_RCVEBP | _PORT_VIRT_FLAG,
  4486. crp_rcvflowctrlviol,
  4487. QIBPORTCNTR_ERRICRC | _PORT_VIRT_FLAG,
  4488. QIBPORTCNTR_ERRLPCRC | _PORT_VIRT_FLAG,
  4489. QIBPORTCNTR_ERRVCRC | _PORT_VIRT_FLAG,
  4490. QIBPORTCNTR_INVALIDRLEN | _PORT_VIRT_FLAG,
  4491. QIBPORTCNTR_ERRPKEY | _PORT_VIRT_FLAG,
  4492. QIBPORTCNTR_RXDROPPKT | _PORT_VIRT_FLAG,
  4493. crp_txminmaxlenerr,
  4494. crp_txdroppedpkt,
  4495. crp_txlenerr,
  4496. crp_txunderrun,
  4497. crp_txunsupvl,
  4498. QIBPORTCNTR_RXLOCALPHYERR | _PORT_VIRT_FLAG,
  4499. QIBPORTCNTR_VL15PKTDROP | _PORT_VIRT_FLAG,
  4500. QIBPORTCNTR_RXVLERR | _PORT_VIRT_FLAG,
  4501. QIBPORTCNTR_EXCESSBUFOVFL | _PORT_VIRT_FLAG,
  4502. crp_rxqpinvalidctxt,
  4503. crp_txhdrerr,
  4504. };
  4505. /* do all the setup to make the counter reads efficient later */
  4506. static void init_7322_cntrnames(struct qib_devdata *dd)
  4507. {
  4508. int i, j = 0;
  4509. char *s;
  4510. for (i = 0, s = (char *)cntr7322names; s && j <= dd->cfgctxts;
  4511. i++) {
  4512. /* we always have at least one counter before the egrovfl */
  4513. if (!j && !strncmp("Ctxt0EgrOvfl", s + 1, 12))
  4514. j = 1;
  4515. s = strchr(s + 1, '\n');
  4516. if (s && j)
  4517. j++;
  4518. }
  4519. dd->cspec->ncntrs = i;
  4520. if (!s)
  4521. /* full list; size is without terminating null */
  4522. dd->cspec->cntrnamelen = sizeof(cntr7322names) - 1;
  4523. else
  4524. dd->cspec->cntrnamelen = 1 + s - cntr7322names;
  4525. dd->cspec->cntrs = kmalloc(dd->cspec->ncntrs
  4526. * sizeof(u64), GFP_KERNEL);
  4527. if (!dd->cspec->cntrs)
  4528. qib_dev_err(dd, "Failed allocation for counters\n");
  4529. for (i = 0, s = (char *)portcntr7322names; s; i++)
  4530. s = strchr(s + 1, '\n');
  4531. dd->cspec->nportcntrs = i - 1;
  4532. dd->cspec->portcntrnamelen = sizeof(portcntr7322names) - 1;
  4533. for (i = 0; i < dd->num_pports; ++i) {
  4534. dd->pport[i].cpspec->portcntrs = kmalloc(dd->cspec->nportcntrs
  4535. * sizeof(u64), GFP_KERNEL);
  4536. if (!dd->pport[i].cpspec->portcntrs)
  4537. qib_dev_err(dd,
  4538. "Failed allocation for portcounters\n");
  4539. }
  4540. }
  4541. static u32 qib_read_7322cntrs(struct qib_devdata *dd, loff_t pos, char **namep,
  4542. u64 **cntrp)
  4543. {
  4544. u32 ret;
  4545. if (namep) {
  4546. ret = dd->cspec->cntrnamelen;
  4547. if (pos >= ret)
  4548. ret = 0; /* final read after getting everything */
  4549. else
  4550. *namep = (char *) cntr7322names;
  4551. } else {
  4552. u64 *cntr = dd->cspec->cntrs;
  4553. int i;
  4554. ret = dd->cspec->ncntrs * sizeof(u64);
  4555. if (!cntr || pos >= ret) {
  4556. /* everything read, or couldn't get memory */
  4557. ret = 0;
  4558. goto done;
  4559. }
  4560. *cntrp = cntr;
  4561. for (i = 0; i < dd->cspec->ncntrs; i++)
  4562. if (cntr7322indices[i] & _PORT_64BIT_FLAG)
  4563. *cntr++ = read_7322_creg(dd,
  4564. cntr7322indices[i] &
  4565. _PORT_CNTR_IDXMASK);
  4566. else
  4567. *cntr++ = read_7322_creg32(dd,
  4568. cntr7322indices[i]);
  4569. }
  4570. done:
  4571. return ret;
  4572. }
  4573. static u32 qib_read_7322portcntrs(struct qib_devdata *dd, loff_t pos, u32 port,
  4574. char **namep, u64 **cntrp)
  4575. {
  4576. u32 ret;
  4577. if (namep) {
  4578. ret = dd->cspec->portcntrnamelen;
  4579. if (pos >= ret)
  4580. ret = 0; /* final read after getting everything */
  4581. else
  4582. *namep = (char *)portcntr7322names;
  4583. } else {
  4584. struct qib_pportdata *ppd = &dd->pport[port];
  4585. u64 *cntr = ppd->cpspec->portcntrs;
  4586. int i;
  4587. ret = dd->cspec->nportcntrs * sizeof(u64);
  4588. if (!cntr || pos >= ret) {
  4589. /* everything read, or couldn't get memory */
  4590. ret = 0;
  4591. goto done;
  4592. }
  4593. *cntrp = cntr;
  4594. for (i = 0; i < dd->cspec->nportcntrs; i++) {
  4595. if (portcntr7322indices[i] & _PORT_VIRT_FLAG)
  4596. *cntr++ = qib_portcntr_7322(ppd,
  4597. portcntr7322indices[i] &
  4598. _PORT_CNTR_IDXMASK);
  4599. else if (portcntr7322indices[i] & _PORT_64BIT_FLAG)
  4600. *cntr++ = read_7322_creg_port(ppd,
  4601. portcntr7322indices[i] &
  4602. _PORT_CNTR_IDXMASK);
  4603. else
  4604. *cntr++ = read_7322_creg32_port(ppd,
  4605. portcntr7322indices[i]);
  4606. }
  4607. }
  4608. done:
  4609. return ret;
  4610. }
  4611. /**
  4612. * qib_get_7322_faststats - get word counters from chip before they overflow
  4613. * @opaque - contains a pointer to the qlogic_ib device qib_devdata
  4614. *
  4615. * VESTIGIAL IBA7322 has no "small fast counters", so the only
  4616. * real purpose of this function is to maintain the notion of
  4617. * "active time", which in turn is only logged into the eeprom,
  4618. * which we don;t have, yet, for 7322-based boards.
  4619. *
  4620. * called from add_timer
  4621. */
  4622. static void qib_get_7322_faststats(unsigned long opaque)
  4623. {
  4624. struct qib_devdata *dd = (struct qib_devdata *) opaque;
  4625. struct qib_pportdata *ppd;
  4626. unsigned long flags;
  4627. u64 traffic_wds;
  4628. int pidx;
  4629. for (pidx = 0; pidx < dd->num_pports; ++pidx) {
  4630. ppd = dd->pport + pidx;
  4631. /*
  4632. * If port isn't enabled or not operational ports, or
  4633. * diags is running (can cause memory diags to fail)
  4634. * skip this port this time.
  4635. */
  4636. if (!ppd->link_speed_supported || !(dd->flags & QIB_INITTED)
  4637. || dd->diag_client)
  4638. continue;
  4639. /*
  4640. * Maintain an activity timer, based on traffic
  4641. * exceeding a threshold, so we need to check the word-counts
  4642. * even if they are 64-bit.
  4643. */
  4644. traffic_wds = qib_portcntr_7322(ppd, QIBPORTCNTR_WORDRCV) +
  4645. qib_portcntr_7322(ppd, QIBPORTCNTR_WORDSEND);
  4646. spin_lock_irqsave(&ppd->dd->eep_st_lock, flags);
  4647. traffic_wds -= ppd->dd->traffic_wds;
  4648. ppd->dd->traffic_wds += traffic_wds;
  4649. if (traffic_wds >= QIB_TRAFFIC_ACTIVE_THRESHOLD)
  4650. atomic_add(ACTIVITY_TIMER, &ppd->dd->active_time);
  4651. spin_unlock_irqrestore(&ppd->dd->eep_st_lock, flags);
  4652. if (ppd->cpspec->qdr_dfe_on && (ppd->link_speed_active &
  4653. QIB_IB_QDR) &&
  4654. (ppd->lflags & (QIBL_LINKINIT | QIBL_LINKARMED |
  4655. QIBL_LINKACTIVE)) &&
  4656. ppd->cpspec->qdr_dfe_time &&
  4657. time_is_before_jiffies(ppd->cpspec->qdr_dfe_time)) {
  4658. ppd->cpspec->qdr_dfe_on = 0;
  4659. qib_write_kreg_port(ppd, krp_static_adapt_dis(2),
  4660. ppd->dd->cspec->r1 ?
  4661. QDR_STATIC_ADAPT_INIT_R1 :
  4662. QDR_STATIC_ADAPT_INIT);
  4663. force_h1(ppd);
  4664. }
  4665. }
  4666. mod_timer(&dd->stats_timer, jiffies + HZ * ACTIVITY_TIMER);
  4667. }
  4668. /*
  4669. * If we were using MSIx, try to fallback to INTx.
  4670. */
  4671. static int qib_7322_intr_fallback(struct qib_devdata *dd)
  4672. {
  4673. if (!dd->cspec->num_msix_entries)
  4674. return 0; /* already using INTx */
  4675. qib_devinfo(dd->pcidev,
  4676. "MSIx interrupt not detected, trying INTx interrupts\n");
  4677. qib_7322_nomsix(dd);
  4678. qib_enable_intx(dd->pcidev);
  4679. qib_setup_7322_interrupt(dd, 0);
  4680. return 1;
  4681. }
  4682. /*
  4683. * Reset the XGXS (between serdes and IBC). Slightly less intrusive
  4684. * than resetting the IBC or external link state, and useful in some
  4685. * cases to cause some retraining. To do this right, we reset IBC
  4686. * as well, then return to previous state (which may be still in reset)
  4687. * NOTE: some callers of this "know" this writes the current value
  4688. * of cpspec->ibcctrl_a as part of it's operation, so if that changes,
  4689. * check all callers.
  4690. */
  4691. static void qib_7322_mini_pcs_reset(struct qib_pportdata *ppd)
  4692. {
  4693. u64 val;
  4694. struct qib_devdata *dd = ppd->dd;
  4695. const u64 reset_bits = SYM_MASK(IBPCSConfig_0, xcv_rreset) |
  4696. SYM_MASK(IBPCSConfig_0, xcv_treset) |
  4697. SYM_MASK(IBPCSConfig_0, tx_rx_reset);
  4698. val = qib_read_kreg_port(ppd, krp_ib_pcsconfig);
  4699. qib_write_kreg(dd, kr_hwerrmask,
  4700. dd->cspec->hwerrmask & ~HWE_MASK(statusValidNoEop));
  4701. qib_write_kreg_port(ppd, krp_ibcctrl_a,
  4702. ppd->cpspec->ibcctrl_a &
  4703. ~SYM_MASK(IBCCtrlA_0, IBLinkEn));
  4704. qib_write_kreg_port(ppd, krp_ib_pcsconfig, val | reset_bits);
  4705. qib_read_kreg32(dd, kr_scratch);
  4706. qib_write_kreg_port(ppd, krp_ib_pcsconfig, val & ~reset_bits);
  4707. qib_write_kreg_port(ppd, krp_ibcctrl_a, ppd->cpspec->ibcctrl_a);
  4708. qib_write_kreg(dd, kr_scratch, 0ULL);
  4709. qib_write_kreg(dd, kr_hwerrclear,
  4710. SYM_MASK(HwErrClear, statusValidNoEopClear));
  4711. qib_write_kreg(dd, kr_hwerrmask, dd->cspec->hwerrmask);
  4712. }
  4713. /*
  4714. * This code for non-IBTA-compliant IB speed negotiation is only known to
  4715. * work for the SDR to DDR transition, and only between an HCA and a switch
  4716. * with recent firmware. It is based on observed heuristics, rather than
  4717. * actual knowledge of the non-compliant speed negotiation.
  4718. * It has a number of hard-coded fields, since the hope is to rewrite this
  4719. * when a spec is available on how the negoation is intended to work.
  4720. */
  4721. static void autoneg_7322_sendpkt(struct qib_pportdata *ppd, u32 *hdr,
  4722. u32 dcnt, u32 *data)
  4723. {
  4724. int i;
  4725. u64 pbc;
  4726. u32 __iomem *piobuf;
  4727. u32 pnum, control, len;
  4728. struct qib_devdata *dd = ppd->dd;
  4729. i = 0;
  4730. len = 7 + dcnt + 1; /* 7 dword header, dword data, icrc */
  4731. control = qib_7322_setpbc_control(ppd, len, 0, 15);
  4732. pbc = ((u64) control << 32) | len;
  4733. while (!(piobuf = qib_7322_getsendbuf(ppd, pbc, &pnum))) {
  4734. if (i++ > 15)
  4735. return;
  4736. udelay(2);
  4737. }
  4738. /* disable header check on this packet, since it can't be valid */
  4739. dd->f_txchk_change(dd, pnum, 1, TXCHK_CHG_TYPE_DIS1, NULL);
  4740. writeq(pbc, piobuf);
  4741. qib_flush_wc();
  4742. qib_pio_copy(piobuf + 2, hdr, 7);
  4743. qib_pio_copy(piobuf + 9, data, dcnt);
  4744. if (dd->flags & QIB_USE_SPCL_TRIG) {
  4745. u32 spcl_off = (pnum >= dd->piobcnt2k) ? 2047 : 1023;
  4746. qib_flush_wc();
  4747. __raw_writel(0xaebecede, piobuf + spcl_off);
  4748. }
  4749. qib_flush_wc();
  4750. qib_sendbuf_done(dd, pnum);
  4751. /* and re-enable hdr check */
  4752. dd->f_txchk_change(dd, pnum, 1, TXCHK_CHG_TYPE_ENAB1, NULL);
  4753. }
  4754. /*
  4755. * _start packet gets sent twice at start, _done gets sent twice at end
  4756. */
  4757. static void qib_autoneg_7322_send(struct qib_pportdata *ppd, int which)
  4758. {
  4759. struct qib_devdata *dd = ppd->dd;
  4760. static u32 swapped;
  4761. u32 dw, i, hcnt, dcnt, *data;
  4762. static u32 hdr[7] = { 0xf002ffff, 0x48ffff, 0x6400abba };
  4763. static u32 madpayload_start[0x40] = {
  4764. 0x1810103, 0x1, 0x0, 0x0, 0x2c90000, 0x2c9, 0x0, 0x0,
  4765. 0xffffffff, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
  4766. 0x1, 0x1388, 0x15e, 0x1, /* rest 0's */
  4767. };
  4768. static u32 madpayload_done[0x40] = {
  4769. 0x1810103, 0x1, 0x0, 0x0, 0x2c90000, 0x2c9, 0x0, 0x0,
  4770. 0xffffffff, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
  4771. 0x40000001, 0x1388, 0x15e, /* rest 0's */
  4772. };
  4773. dcnt = ARRAY_SIZE(madpayload_start);
  4774. hcnt = ARRAY_SIZE(hdr);
  4775. if (!swapped) {
  4776. /* for maintainability, do it at runtime */
  4777. for (i = 0; i < hcnt; i++) {
  4778. dw = (__force u32) cpu_to_be32(hdr[i]);
  4779. hdr[i] = dw;
  4780. }
  4781. for (i = 0; i < dcnt; i++) {
  4782. dw = (__force u32) cpu_to_be32(madpayload_start[i]);
  4783. madpayload_start[i] = dw;
  4784. dw = (__force u32) cpu_to_be32(madpayload_done[i]);
  4785. madpayload_done[i] = dw;
  4786. }
  4787. swapped = 1;
  4788. }
  4789. data = which ? madpayload_done : madpayload_start;
  4790. autoneg_7322_sendpkt(ppd, hdr, dcnt, data);
  4791. qib_read_kreg64(dd, kr_scratch);
  4792. udelay(2);
  4793. autoneg_7322_sendpkt(ppd, hdr, dcnt, data);
  4794. qib_read_kreg64(dd, kr_scratch);
  4795. udelay(2);
  4796. }
  4797. /*
  4798. * Do the absolute minimum to cause an IB speed change, and make it
  4799. * ready, but don't actually trigger the change. The caller will
  4800. * do that when ready (if link is in Polling training state, it will
  4801. * happen immediately, otherwise when link next goes down)
  4802. *
  4803. * This routine should only be used as part of the DDR autonegotation
  4804. * code for devices that are not compliant with IB 1.2 (or code that
  4805. * fixes things up for same).
  4806. *
  4807. * When link has gone down, and autoneg enabled, or autoneg has
  4808. * failed and we give up until next time we set both speeds, and
  4809. * then we want IBTA enabled as well as "use max enabled speed.
  4810. */
  4811. static void set_7322_ibspeed_fast(struct qib_pportdata *ppd, u32 speed)
  4812. {
  4813. u64 newctrlb;
  4814. newctrlb = ppd->cpspec->ibcctrl_b & ~(IBA7322_IBC_SPEED_MASK |
  4815. IBA7322_IBC_IBTA_1_2_MASK |
  4816. IBA7322_IBC_MAX_SPEED_MASK);
  4817. if (speed & (speed - 1)) /* multiple speeds */
  4818. newctrlb |= (speed << IBA7322_IBC_SPEED_LSB) |
  4819. IBA7322_IBC_IBTA_1_2_MASK |
  4820. IBA7322_IBC_MAX_SPEED_MASK;
  4821. else
  4822. newctrlb |= speed == QIB_IB_QDR ?
  4823. IBA7322_IBC_SPEED_QDR | IBA7322_IBC_IBTA_1_2_MASK :
  4824. ((speed == QIB_IB_DDR ?
  4825. IBA7322_IBC_SPEED_DDR : IBA7322_IBC_SPEED_SDR));
  4826. if (newctrlb == ppd->cpspec->ibcctrl_b)
  4827. return;
  4828. ppd->cpspec->ibcctrl_b = newctrlb;
  4829. qib_write_kreg_port(ppd, krp_ibcctrl_b, ppd->cpspec->ibcctrl_b);
  4830. qib_write_kreg(ppd->dd, kr_scratch, 0);
  4831. }
  4832. /*
  4833. * This routine is only used when we are not talking to another
  4834. * IB 1.2-compliant device that we think can do DDR.
  4835. * (This includes all existing switch chips as of Oct 2007.)
  4836. * 1.2-compliant devices go directly to DDR prior to reaching INIT
  4837. */
  4838. static void try_7322_autoneg(struct qib_pportdata *ppd)
  4839. {
  4840. unsigned long flags;
  4841. spin_lock_irqsave(&ppd->lflags_lock, flags);
  4842. ppd->lflags |= QIBL_IB_AUTONEG_INPROG;
  4843. spin_unlock_irqrestore(&ppd->lflags_lock, flags);
  4844. qib_autoneg_7322_send(ppd, 0);
  4845. set_7322_ibspeed_fast(ppd, QIB_IB_DDR);
  4846. qib_7322_mini_pcs_reset(ppd);
  4847. /* 2 msec is minimum length of a poll cycle */
  4848. queue_delayed_work(ib_wq, &ppd->cpspec->autoneg_work,
  4849. msecs_to_jiffies(2));
  4850. }
  4851. /*
  4852. * Handle the empirically determined mechanism for auto-negotiation
  4853. * of DDR speed with switches.
  4854. */
  4855. static void autoneg_7322_work(struct work_struct *work)
  4856. {
  4857. struct qib_pportdata *ppd;
  4858. struct qib_devdata *dd;
  4859. u64 startms;
  4860. u32 i;
  4861. unsigned long flags;
  4862. ppd = container_of(work, struct qib_chippport_specific,
  4863. autoneg_work.work)->ppd;
  4864. dd = ppd->dd;
  4865. startms = jiffies_to_msecs(jiffies);
  4866. /*
  4867. * Busy wait for this first part, it should be at most a
  4868. * few hundred usec, since we scheduled ourselves for 2msec.
  4869. */
  4870. for (i = 0; i < 25; i++) {
  4871. if (SYM_FIELD(ppd->lastibcstat, IBCStatusA_0, LinkState)
  4872. == IB_7322_LT_STATE_POLLQUIET) {
  4873. qib_set_linkstate(ppd, QIB_IB_LINKDOWN_DISABLE);
  4874. break;
  4875. }
  4876. udelay(100);
  4877. }
  4878. if (!(ppd->lflags & QIBL_IB_AUTONEG_INPROG))
  4879. goto done; /* we got there early or told to stop */
  4880. /* we expect this to timeout */
  4881. if (wait_event_timeout(ppd->cpspec->autoneg_wait,
  4882. !(ppd->lflags & QIBL_IB_AUTONEG_INPROG),
  4883. msecs_to_jiffies(90)))
  4884. goto done;
  4885. qib_7322_mini_pcs_reset(ppd);
  4886. /* we expect this to timeout */
  4887. if (wait_event_timeout(ppd->cpspec->autoneg_wait,
  4888. !(ppd->lflags & QIBL_IB_AUTONEG_INPROG),
  4889. msecs_to_jiffies(1700)))
  4890. goto done;
  4891. qib_7322_mini_pcs_reset(ppd);
  4892. set_7322_ibspeed_fast(ppd, QIB_IB_SDR);
  4893. /*
  4894. * Wait up to 250 msec for link to train and get to INIT at DDR;
  4895. * this should terminate early.
  4896. */
  4897. wait_event_timeout(ppd->cpspec->autoneg_wait,
  4898. !(ppd->lflags & QIBL_IB_AUTONEG_INPROG),
  4899. msecs_to_jiffies(250));
  4900. done:
  4901. if (ppd->lflags & QIBL_IB_AUTONEG_INPROG) {
  4902. spin_lock_irqsave(&ppd->lflags_lock, flags);
  4903. ppd->lflags &= ~QIBL_IB_AUTONEG_INPROG;
  4904. if (ppd->cpspec->autoneg_tries == AUTONEG_TRIES) {
  4905. ppd->lflags |= QIBL_IB_AUTONEG_FAILED;
  4906. ppd->cpspec->autoneg_tries = 0;
  4907. }
  4908. spin_unlock_irqrestore(&ppd->lflags_lock, flags);
  4909. set_7322_ibspeed_fast(ppd, ppd->link_speed_enabled);
  4910. }
  4911. }
  4912. /*
  4913. * This routine is used to request IPG set in the QLogic switch.
  4914. * Only called if r1.
  4915. */
  4916. static void try_7322_ipg(struct qib_pportdata *ppd)
  4917. {
  4918. struct qib_ibport *ibp = &ppd->ibport_data;
  4919. struct ib_mad_send_buf *send_buf;
  4920. struct ib_mad_agent *agent;
  4921. struct ib_smp *smp;
  4922. unsigned delay;
  4923. int ret;
  4924. agent = ibp->send_agent;
  4925. if (!agent)
  4926. goto retry;
  4927. send_buf = ib_create_send_mad(agent, 0, 0, 0, IB_MGMT_MAD_HDR,
  4928. IB_MGMT_MAD_DATA, GFP_ATOMIC);
  4929. if (IS_ERR(send_buf))
  4930. goto retry;
  4931. if (!ibp->smi_ah) {
  4932. struct ib_ah *ah;
  4933. ah = qib_create_qp0_ah(ibp, be16_to_cpu(IB_LID_PERMISSIVE));
  4934. if (IS_ERR(ah))
  4935. ret = PTR_ERR(ah);
  4936. else {
  4937. send_buf->ah = ah;
  4938. ibp->smi_ah = to_iah(ah);
  4939. ret = 0;
  4940. }
  4941. } else {
  4942. send_buf->ah = &ibp->smi_ah->ibah;
  4943. ret = 0;
  4944. }
  4945. smp = send_buf->mad;
  4946. smp->base_version = IB_MGMT_BASE_VERSION;
  4947. smp->mgmt_class = IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE;
  4948. smp->class_version = 1;
  4949. smp->method = IB_MGMT_METHOD_SEND;
  4950. smp->hop_cnt = 1;
  4951. smp->attr_id = QIB_VENDOR_IPG;
  4952. smp->attr_mod = 0;
  4953. if (!ret)
  4954. ret = ib_post_send_mad(send_buf, NULL);
  4955. if (ret)
  4956. ib_free_send_mad(send_buf);
  4957. retry:
  4958. delay = 2 << ppd->cpspec->ipg_tries;
  4959. queue_delayed_work(ib_wq, &ppd->cpspec->ipg_work,
  4960. msecs_to_jiffies(delay));
  4961. }
  4962. /*
  4963. * Timeout handler for setting IPG.
  4964. * Only called if r1.
  4965. */
  4966. static void ipg_7322_work(struct work_struct *work)
  4967. {
  4968. struct qib_pportdata *ppd;
  4969. ppd = container_of(work, struct qib_chippport_specific,
  4970. ipg_work.work)->ppd;
  4971. if ((ppd->lflags & (QIBL_LINKINIT | QIBL_LINKARMED | QIBL_LINKACTIVE))
  4972. && ++ppd->cpspec->ipg_tries <= 10)
  4973. try_7322_ipg(ppd);
  4974. }
  4975. static u32 qib_7322_iblink_state(u64 ibcs)
  4976. {
  4977. u32 state = (u32)SYM_FIELD(ibcs, IBCStatusA_0, LinkState);
  4978. switch (state) {
  4979. case IB_7322_L_STATE_INIT:
  4980. state = IB_PORT_INIT;
  4981. break;
  4982. case IB_7322_L_STATE_ARM:
  4983. state = IB_PORT_ARMED;
  4984. break;
  4985. case IB_7322_L_STATE_ACTIVE:
  4986. /* fall through */
  4987. case IB_7322_L_STATE_ACT_DEFER:
  4988. state = IB_PORT_ACTIVE;
  4989. break;
  4990. default: /* fall through */
  4991. case IB_7322_L_STATE_DOWN:
  4992. state = IB_PORT_DOWN;
  4993. break;
  4994. }
  4995. return state;
  4996. }
  4997. /* returns the IBTA port state, rather than the IBC link training state */
  4998. static u8 qib_7322_phys_portstate(u64 ibcs)
  4999. {
  5000. u8 state = (u8)SYM_FIELD(ibcs, IBCStatusA_0, LinkTrainingState);
  5001. return qib_7322_physportstate[state];
  5002. }
  5003. static int qib_7322_ib_updown(struct qib_pportdata *ppd, int ibup, u64 ibcs)
  5004. {
  5005. int ret = 0, symadj = 0;
  5006. unsigned long flags;
  5007. int mult;
  5008. spin_lock_irqsave(&ppd->lflags_lock, flags);
  5009. ppd->lflags &= ~QIBL_IB_FORCE_NOTIFY;
  5010. spin_unlock_irqrestore(&ppd->lflags_lock, flags);
  5011. /* Update our picture of width and speed from chip */
  5012. if (ibcs & SYM_MASK(IBCStatusA_0, LinkSpeedQDR)) {
  5013. ppd->link_speed_active = QIB_IB_QDR;
  5014. mult = 4;
  5015. } else if (ibcs & SYM_MASK(IBCStatusA_0, LinkSpeedActive)) {
  5016. ppd->link_speed_active = QIB_IB_DDR;
  5017. mult = 2;
  5018. } else {
  5019. ppd->link_speed_active = QIB_IB_SDR;
  5020. mult = 1;
  5021. }
  5022. if (ibcs & SYM_MASK(IBCStatusA_0, LinkWidthActive)) {
  5023. ppd->link_width_active = IB_WIDTH_4X;
  5024. mult *= 4;
  5025. } else
  5026. ppd->link_width_active = IB_WIDTH_1X;
  5027. ppd->delay_mult = ib_rate_to_delay[mult_to_ib_rate(mult)];
  5028. if (!ibup) {
  5029. u64 clr;
  5030. /* Link went down. */
  5031. /* do IPG MAD again after linkdown, even if last time failed */
  5032. ppd->cpspec->ipg_tries = 0;
  5033. clr = qib_read_kreg_port(ppd, krp_ibcstatus_b) &
  5034. (SYM_MASK(IBCStatusB_0, heartbeat_timed_out) |
  5035. SYM_MASK(IBCStatusB_0, heartbeat_crosstalk));
  5036. if (clr)
  5037. qib_write_kreg_port(ppd, krp_ibcstatus_b, clr);
  5038. if (!(ppd->lflags & (QIBL_IB_AUTONEG_FAILED |
  5039. QIBL_IB_AUTONEG_INPROG)))
  5040. set_7322_ibspeed_fast(ppd, ppd->link_speed_enabled);
  5041. if (!(ppd->lflags & QIBL_IB_AUTONEG_INPROG)) {
  5042. struct qib_qsfp_data *qd =
  5043. &ppd->cpspec->qsfp_data;
  5044. /* unlock the Tx settings, speed may change */
  5045. qib_write_kreg_port(ppd, krp_tx_deemph_override,
  5046. SYM_MASK(IBSD_TX_DEEMPHASIS_OVERRIDE_0,
  5047. reset_tx_deemphasis_override));
  5048. qib_cancel_sends(ppd);
  5049. /* on link down, ensure sane pcs state */
  5050. qib_7322_mini_pcs_reset(ppd);
  5051. /* schedule the qsfp refresh which should turn the link
  5052. off */
  5053. if (ppd->dd->flags & QIB_HAS_QSFP) {
  5054. qd->t_insert = jiffies;
  5055. queue_work(ib_wq, &qd->work);
  5056. }
  5057. spin_lock_irqsave(&ppd->sdma_lock, flags);
  5058. if (__qib_sdma_running(ppd))
  5059. __qib_sdma_process_event(ppd,
  5060. qib_sdma_event_e70_go_idle);
  5061. spin_unlock_irqrestore(&ppd->sdma_lock, flags);
  5062. }
  5063. clr = read_7322_creg32_port(ppd, crp_iblinkdown);
  5064. if (clr == ppd->cpspec->iblnkdownsnap)
  5065. ppd->cpspec->iblnkdowndelta++;
  5066. } else {
  5067. if (qib_compat_ddr_negotiate &&
  5068. !(ppd->lflags & (QIBL_IB_AUTONEG_FAILED |
  5069. QIBL_IB_AUTONEG_INPROG)) &&
  5070. ppd->link_speed_active == QIB_IB_SDR &&
  5071. (ppd->link_speed_enabled & QIB_IB_DDR)
  5072. && ppd->cpspec->autoneg_tries < AUTONEG_TRIES) {
  5073. /* we are SDR, and auto-negotiation enabled */
  5074. ++ppd->cpspec->autoneg_tries;
  5075. if (!ppd->cpspec->ibdeltainprog) {
  5076. ppd->cpspec->ibdeltainprog = 1;
  5077. ppd->cpspec->ibsymdelta +=
  5078. read_7322_creg32_port(ppd,
  5079. crp_ibsymbolerr) -
  5080. ppd->cpspec->ibsymsnap;
  5081. ppd->cpspec->iblnkerrdelta +=
  5082. read_7322_creg32_port(ppd,
  5083. crp_iblinkerrrecov) -
  5084. ppd->cpspec->iblnkerrsnap;
  5085. }
  5086. try_7322_autoneg(ppd);
  5087. ret = 1; /* no other IB status change processing */
  5088. } else if ((ppd->lflags & QIBL_IB_AUTONEG_INPROG) &&
  5089. ppd->link_speed_active == QIB_IB_SDR) {
  5090. qib_autoneg_7322_send(ppd, 1);
  5091. set_7322_ibspeed_fast(ppd, QIB_IB_DDR);
  5092. qib_7322_mini_pcs_reset(ppd);
  5093. udelay(2);
  5094. ret = 1; /* no other IB status change processing */
  5095. } else if ((ppd->lflags & QIBL_IB_AUTONEG_INPROG) &&
  5096. (ppd->link_speed_active & QIB_IB_DDR)) {
  5097. spin_lock_irqsave(&ppd->lflags_lock, flags);
  5098. ppd->lflags &= ~(QIBL_IB_AUTONEG_INPROG |
  5099. QIBL_IB_AUTONEG_FAILED);
  5100. spin_unlock_irqrestore(&ppd->lflags_lock, flags);
  5101. ppd->cpspec->autoneg_tries = 0;
  5102. /* re-enable SDR, for next link down */
  5103. set_7322_ibspeed_fast(ppd, ppd->link_speed_enabled);
  5104. wake_up(&ppd->cpspec->autoneg_wait);
  5105. symadj = 1;
  5106. } else if (ppd->lflags & QIBL_IB_AUTONEG_FAILED) {
  5107. /*
  5108. * Clear autoneg failure flag, and do setup
  5109. * so we'll try next time link goes down and
  5110. * back to INIT (possibly connected to a
  5111. * different device).
  5112. */
  5113. spin_lock_irqsave(&ppd->lflags_lock, flags);
  5114. ppd->lflags &= ~QIBL_IB_AUTONEG_FAILED;
  5115. spin_unlock_irqrestore(&ppd->lflags_lock, flags);
  5116. ppd->cpspec->ibcctrl_b |= IBA7322_IBC_IBTA_1_2_MASK;
  5117. symadj = 1;
  5118. }
  5119. if (!(ppd->lflags & QIBL_IB_AUTONEG_INPROG)) {
  5120. symadj = 1;
  5121. if (ppd->dd->cspec->r1 && ppd->cpspec->ipg_tries <= 10)
  5122. try_7322_ipg(ppd);
  5123. if (!ppd->cpspec->recovery_init)
  5124. setup_7322_link_recovery(ppd, 0);
  5125. ppd->cpspec->qdr_dfe_time = jiffies +
  5126. msecs_to_jiffies(QDR_DFE_DISABLE_DELAY);
  5127. }
  5128. ppd->cpspec->ibmalfusesnap = 0;
  5129. ppd->cpspec->ibmalfsnap = read_7322_creg32_port(ppd,
  5130. crp_errlink);
  5131. }
  5132. if (symadj) {
  5133. ppd->cpspec->iblnkdownsnap =
  5134. read_7322_creg32_port(ppd, crp_iblinkdown);
  5135. if (ppd->cpspec->ibdeltainprog) {
  5136. ppd->cpspec->ibdeltainprog = 0;
  5137. ppd->cpspec->ibsymdelta += read_7322_creg32_port(ppd,
  5138. crp_ibsymbolerr) - ppd->cpspec->ibsymsnap;
  5139. ppd->cpspec->iblnkerrdelta += read_7322_creg32_port(ppd,
  5140. crp_iblinkerrrecov) - ppd->cpspec->iblnkerrsnap;
  5141. }
  5142. } else if (!ibup && qib_compat_ddr_negotiate &&
  5143. !ppd->cpspec->ibdeltainprog &&
  5144. !(ppd->lflags & QIBL_IB_AUTONEG_INPROG)) {
  5145. ppd->cpspec->ibdeltainprog = 1;
  5146. ppd->cpspec->ibsymsnap = read_7322_creg32_port(ppd,
  5147. crp_ibsymbolerr);
  5148. ppd->cpspec->iblnkerrsnap = read_7322_creg32_port(ppd,
  5149. crp_iblinkerrrecov);
  5150. }
  5151. if (!ret)
  5152. qib_setup_7322_setextled(ppd, ibup);
  5153. return ret;
  5154. }
  5155. /*
  5156. * Does read/modify/write to appropriate registers to
  5157. * set output and direction bits selected by mask.
  5158. * these are in their canonical postions (e.g. lsb of
  5159. * dir will end up in D48 of extctrl on existing chips).
  5160. * returns contents of GP Inputs.
  5161. */
  5162. static int gpio_7322_mod(struct qib_devdata *dd, u32 out, u32 dir, u32 mask)
  5163. {
  5164. u64 read_val, new_out;
  5165. unsigned long flags;
  5166. if (mask) {
  5167. /* some bits being written, lock access to GPIO */
  5168. dir &= mask;
  5169. out &= mask;
  5170. spin_lock_irqsave(&dd->cspec->gpio_lock, flags);
  5171. dd->cspec->extctrl &= ~((u64)mask << SYM_LSB(EXTCtrl, GPIOOe));
  5172. dd->cspec->extctrl |= ((u64) dir << SYM_LSB(EXTCtrl, GPIOOe));
  5173. new_out = (dd->cspec->gpio_out & ~mask) | out;
  5174. qib_write_kreg(dd, kr_extctrl, dd->cspec->extctrl);
  5175. qib_write_kreg(dd, kr_gpio_out, new_out);
  5176. dd->cspec->gpio_out = new_out;
  5177. spin_unlock_irqrestore(&dd->cspec->gpio_lock, flags);
  5178. }
  5179. /*
  5180. * It is unlikely that a read at this time would get valid
  5181. * data on a pin whose direction line was set in the same
  5182. * call to this function. We include the read here because
  5183. * that allows us to potentially combine a change on one pin with
  5184. * a read on another, and because the old code did something like
  5185. * this.
  5186. */
  5187. read_val = qib_read_kreg64(dd, kr_extstatus);
  5188. return SYM_FIELD(read_val, EXTStatus, GPIOIn);
  5189. }
  5190. /* Enable writes to config EEPROM, if possible. Returns previous state */
  5191. static int qib_7322_eeprom_wen(struct qib_devdata *dd, int wen)
  5192. {
  5193. int prev_wen;
  5194. u32 mask;
  5195. mask = 1 << QIB_EEPROM_WEN_NUM;
  5196. prev_wen = ~gpio_7322_mod(dd, 0, 0, 0) >> QIB_EEPROM_WEN_NUM;
  5197. gpio_7322_mod(dd, wen ? 0 : mask, mask, mask);
  5198. return prev_wen & 1;
  5199. }
  5200. /*
  5201. * Read fundamental info we need to use the chip. These are
  5202. * the registers that describe chip capabilities, and are
  5203. * saved in shadow registers.
  5204. */
  5205. static void get_7322_chip_params(struct qib_devdata *dd)
  5206. {
  5207. u64 val;
  5208. u32 piobufs;
  5209. int mtu;
  5210. dd->palign = qib_read_kreg32(dd, kr_pagealign);
  5211. dd->uregbase = qib_read_kreg32(dd, kr_userregbase);
  5212. dd->rcvtidcnt = qib_read_kreg32(dd, kr_rcvtidcnt);
  5213. dd->rcvtidbase = qib_read_kreg32(dd, kr_rcvtidbase);
  5214. dd->rcvegrbase = qib_read_kreg32(dd, kr_rcvegrbase);
  5215. dd->piobufbase = qib_read_kreg64(dd, kr_sendpiobufbase);
  5216. dd->pio2k_bufbase = dd->piobufbase & 0xffffffff;
  5217. val = qib_read_kreg64(dd, kr_sendpiobufcnt);
  5218. dd->piobcnt2k = val & ~0U;
  5219. dd->piobcnt4k = val >> 32;
  5220. val = qib_read_kreg64(dd, kr_sendpiosize);
  5221. dd->piosize2k = val & ~0U;
  5222. dd->piosize4k = val >> 32;
  5223. mtu = ib_mtu_enum_to_int(qib_ibmtu);
  5224. if (mtu == -1)
  5225. mtu = QIB_DEFAULT_MTU;
  5226. dd->pport[0].ibmtu = (u32)mtu;
  5227. dd->pport[1].ibmtu = (u32)mtu;
  5228. /* these may be adjusted in init_chip_wc_pat() */
  5229. dd->pio2kbase = (u32 __iomem *)
  5230. ((char __iomem *) dd->kregbase + dd->pio2k_bufbase);
  5231. dd->pio4kbase = (u32 __iomem *)
  5232. ((char __iomem *) dd->kregbase +
  5233. (dd->piobufbase >> 32));
  5234. /*
  5235. * 4K buffers take 2 pages; we use roundup just to be
  5236. * paranoid; we calculate it once here, rather than on
  5237. * ever buf allocate
  5238. */
  5239. dd->align4k = ALIGN(dd->piosize4k, dd->palign);
  5240. piobufs = dd->piobcnt4k + dd->piobcnt2k + NUM_VL15_BUFS;
  5241. dd->pioavregs = ALIGN(piobufs, sizeof(u64) * BITS_PER_BYTE / 2) /
  5242. (sizeof(u64) * BITS_PER_BYTE / 2);
  5243. }
  5244. /*
  5245. * The chip base addresses in cspec and cpspec have to be set
  5246. * after possible init_chip_wc_pat(), rather than in
  5247. * get_7322_chip_params(), so split out as separate function
  5248. */
  5249. static void qib_7322_set_baseaddrs(struct qib_devdata *dd)
  5250. {
  5251. u32 cregbase;
  5252. cregbase = qib_read_kreg32(dd, kr_counterregbase);
  5253. dd->cspec->cregbase = (u64 __iomem *)(cregbase +
  5254. (char __iomem *)dd->kregbase);
  5255. dd->egrtidbase = (u64 __iomem *)
  5256. ((char __iomem *) dd->kregbase + dd->rcvegrbase);
  5257. /* port registers are defined as relative to base of chip */
  5258. dd->pport[0].cpspec->kpregbase =
  5259. (u64 __iomem *)((char __iomem *)dd->kregbase);
  5260. dd->pport[1].cpspec->kpregbase =
  5261. (u64 __iomem *)(dd->palign +
  5262. (char __iomem *)dd->kregbase);
  5263. dd->pport[0].cpspec->cpregbase =
  5264. (u64 __iomem *)(qib_read_kreg_port(&dd->pport[0],
  5265. kr_counterregbase) + (char __iomem *)dd->kregbase);
  5266. dd->pport[1].cpspec->cpregbase =
  5267. (u64 __iomem *)(qib_read_kreg_port(&dd->pport[1],
  5268. kr_counterregbase) + (char __iomem *)dd->kregbase);
  5269. }
  5270. /*
  5271. * This is a fairly special-purpose observer, so we only support
  5272. * the port-specific parts of SendCtrl
  5273. */
  5274. #define SENDCTRL_SHADOWED (SYM_MASK(SendCtrl_0, SendEnable) | \
  5275. SYM_MASK(SendCtrl_0, SDmaEnable) | \
  5276. SYM_MASK(SendCtrl_0, SDmaIntEnable) | \
  5277. SYM_MASK(SendCtrl_0, SDmaSingleDescriptor) | \
  5278. SYM_MASK(SendCtrl_0, SDmaHalt) | \
  5279. SYM_MASK(SendCtrl_0, IBVLArbiterEn) | \
  5280. SYM_MASK(SendCtrl_0, ForceCreditUpToDate))
  5281. static int sendctrl_hook(struct qib_devdata *dd,
  5282. const struct diag_observer *op, u32 offs,
  5283. u64 *data, u64 mask, int only_32)
  5284. {
  5285. unsigned long flags;
  5286. unsigned idx;
  5287. unsigned pidx;
  5288. struct qib_pportdata *ppd = NULL;
  5289. u64 local_data, all_bits;
  5290. /*
  5291. * The fixed correspondence between Physical ports and pports is
  5292. * severed. We need to hunt for the ppd that corresponds
  5293. * to the offset we got. And we have to do that without admitting
  5294. * we know the stride, apparently.
  5295. */
  5296. for (pidx = 0; pidx < dd->num_pports; ++pidx) {
  5297. u64 __iomem *psptr;
  5298. u32 psoffs;
  5299. ppd = dd->pport + pidx;
  5300. if (!ppd->cpspec->kpregbase)
  5301. continue;
  5302. psptr = ppd->cpspec->kpregbase + krp_sendctrl;
  5303. psoffs = (u32) (psptr - dd->kregbase) * sizeof(*psptr);
  5304. if (psoffs == offs)
  5305. break;
  5306. }
  5307. /* If pport is not being managed by driver, just avoid shadows. */
  5308. if (pidx >= dd->num_pports)
  5309. ppd = NULL;
  5310. /* In any case, "idx" is flat index in kreg space */
  5311. idx = offs / sizeof(u64);
  5312. all_bits = ~0ULL;
  5313. if (only_32)
  5314. all_bits >>= 32;
  5315. spin_lock_irqsave(&dd->sendctrl_lock, flags);
  5316. if (!ppd || (mask & all_bits) != all_bits) {
  5317. /*
  5318. * At least some mask bits are zero, so we need
  5319. * to read. The judgement call is whether from
  5320. * reg or shadow. First-cut: read reg, and complain
  5321. * if any bits which should be shadowed are different
  5322. * from their shadowed value.
  5323. */
  5324. if (only_32)
  5325. local_data = (u64)qib_read_kreg32(dd, idx);
  5326. else
  5327. local_data = qib_read_kreg64(dd, idx);
  5328. *data = (local_data & ~mask) | (*data & mask);
  5329. }
  5330. if (mask) {
  5331. /*
  5332. * At least some mask bits are one, so we need
  5333. * to write, but only shadow some bits.
  5334. */
  5335. u64 sval, tval; /* Shadowed, transient */
  5336. /*
  5337. * New shadow val is bits we don't want to touch,
  5338. * ORed with bits we do, that are intended for shadow.
  5339. */
  5340. if (ppd) {
  5341. sval = ppd->p_sendctrl & ~mask;
  5342. sval |= *data & SENDCTRL_SHADOWED & mask;
  5343. ppd->p_sendctrl = sval;
  5344. } else
  5345. sval = *data & SENDCTRL_SHADOWED & mask;
  5346. tval = sval | (*data & ~SENDCTRL_SHADOWED & mask);
  5347. qib_write_kreg(dd, idx, tval);
  5348. qib_write_kreg(dd, kr_scratch, 0Ull);
  5349. }
  5350. spin_unlock_irqrestore(&dd->sendctrl_lock, flags);
  5351. return only_32 ? 4 : 8;
  5352. }
  5353. static const struct diag_observer sendctrl_0_observer = {
  5354. sendctrl_hook, KREG_IDX(SendCtrl_0) * sizeof(u64),
  5355. KREG_IDX(SendCtrl_0) * sizeof(u64)
  5356. };
  5357. static const struct diag_observer sendctrl_1_observer = {
  5358. sendctrl_hook, KREG_IDX(SendCtrl_1) * sizeof(u64),
  5359. KREG_IDX(SendCtrl_1) * sizeof(u64)
  5360. };
  5361. static ushort sdma_fetch_prio = 8;
  5362. module_param_named(sdma_fetch_prio, sdma_fetch_prio, ushort, S_IRUGO);
  5363. MODULE_PARM_DESC(sdma_fetch_prio, "SDMA descriptor fetch priority");
  5364. /* Besides logging QSFP events, we set appropriate TxDDS values */
  5365. static void init_txdds_table(struct qib_pportdata *ppd, int override);
  5366. static void qsfp_7322_event(struct work_struct *work)
  5367. {
  5368. struct qib_qsfp_data *qd;
  5369. struct qib_pportdata *ppd;
  5370. unsigned long pwrup;
  5371. unsigned long flags;
  5372. int ret;
  5373. u32 le2;
  5374. qd = container_of(work, struct qib_qsfp_data, work);
  5375. ppd = qd->ppd;
  5376. pwrup = qd->t_insert +
  5377. msecs_to_jiffies(QSFP_PWR_LAG_MSEC - QSFP_MODPRS_LAG_MSEC);
  5378. /* Delay for 20 msecs to allow ModPrs resistor to setup */
  5379. mdelay(QSFP_MODPRS_LAG_MSEC);
  5380. if (!qib_qsfp_mod_present(ppd)) {
  5381. ppd->cpspec->qsfp_data.modpresent = 0;
  5382. /* Set the physical link to disabled */
  5383. qib_set_ib_7322_lstate(ppd, 0,
  5384. QLOGIC_IB_IBCC_LINKINITCMD_DISABLE);
  5385. spin_lock_irqsave(&ppd->lflags_lock, flags);
  5386. ppd->lflags &= ~QIBL_LINKV;
  5387. spin_unlock_irqrestore(&ppd->lflags_lock, flags);
  5388. } else {
  5389. /*
  5390. * Some QSFP's not only do not respond until the full power-up
  5391. * time, but may behave badly if we try. So hold off responding
  5392. * to insertion.
  5393. */
  5394. while (1) {
  5395. if (time_is_before_jiffies(pwrup))
  5396. break;
  5397. msleep(20);
  5398. }
  5399. ret = qib_refresh_qsfp_cache(ppd, &qd->cache);
  5400. /*
  5401. * Need to change LE2 back to defaults if we couldn't
  5402. * read the cable type (to handle cable swaps), so do this
  5403. * even on failure to read cable information. We don't
  5404. * get here for QME, so IS_QME check not needed here.
  5405. */
  5406. if (!ret && !ppd->dd->cspec->r1) {
  5407. if (QSFP_IS_ACTIVE_FAR(qd->cache.tech))
  5408. le2 = LE2_QME;
  5409. else if (qd->cache.atten[1] >= qib_long_atten &&
  5410. QSFP_IS_CU(qd->cache.tech))
  5411. le2 = LE2_5m;
  5412. else
  5413. le2 = LE2_DEFAULT;
  5414. } else
  5415. le2 = LE2_DEFAULT;
  5416. ibsd_wr_allchans(ppd, 13, (le2 << 7), BMASK(9, 7));
  5417. /*
  5418. * We always change parameteters, since we can choose
  5419. * values for cables without eeproms, and the cable may have
  5420. * changed from a cable with full or partial eeprom content
  5421. * to one with partial or no content.
  5422. */
  5423. init_txdds_table(ppd, 0);
  5424. /* The physical link is being re-enabled only when the
  5425. * previous state was DISABLED and the VALID bit is not
  5426. * set. This should only happen when the cable has been
  5427. * physically pulled. */
  5428. if (!ppd->cpspec->qsfp_data.modpresent &&
  5429. (ppd->lflags & (QIBL_LINKV | QIBL_IB_LINK_DISABLED))) {
  5430. ppd->cpspec->qsfp_data.modpresent = 1;
  5431. qib_set_ib_7322_lstate(ppd, 0,
  5432. QLOGIC_IB_IBCC_LINKINITCMD_SLEEP);
  5433. spin_lock_irqsave(&ppd->lflags_lock, flags);
  5434. ppd->lflags |= QIBL_LINKV;
  5435. spin_unlock_irqrestore(&ppd->lflags_lock, flags);
  5436. }
  5437. }
  5438. }
  5439. /*
  5440. * There is little we can do but complain to the user if QSFP
  5441. * initialization fails.
  5442. */
  5443. static void qib_init_7322_qsfp(struct qib_pportdata *ppd)
  5444. {
  5445. unsigned long flags;
  5446. struct qib_qsfp_data *qd = &ppd->cpspec->qsfp_data;
  5447. struct qib_devdata *dd = ppd->dd;
  5448. u64 mod_prs_bit = QSFP_GPIO_MOD_PRS_N;
  5449. mod_prs_bit <<= (QSFP_GPIO_PORT2_SHIFT * ppd->hw_pidx);
  5450. qd->ppd = ppd;
  5451. qib_qsfp_init(qd, qsfp_7322_event);
  5452. spin_lock_irqsave(&dd->cspec->gpio_lock, flags);
  5453. dd->cspec->extctrl |= (mod_prs_bit << SYM_LSB(EXTCtrl, GPIOInvert));
  5454. dd->cspec->gpio_mask |= mod_prs_bit;
  5455. qib_write_kreg(dd, kr_extctrl, dd->cspec->extctrl);
  5456. qib_write_kreg(dd, kr_gpio_mask, dd->cspec->gpio_mask);
  5457. spin_unlock_irqrestore(&dd->cspec->gpio_lock, flags);
  5458. }
  5459. /*
  5460. * called at device initialization time, and also if the txselect
  5461. * module parameter is changed. This is used for cables that don't
  5462. * have valid QSFP EEPROMs (not present, or attenuation is zero).
  5463. * We initialize to the default, then if there is a specific
  5464. * unit,port match, we use that (and set it immediately, for the
  5465. * current speed, if the link is at INIT or better).
  5466. * String format is "default# unit#,port#=# ... u,p=#", separators must
  5467. * be a SPACE character. A newline terminates. The u,p=# tuples may
  5468. * optionally have "u,p=#,#", where the final # is the H1 value
  5469. * The last specific match is used (actually, all are used, but last
  5470. * one is the one that winds up set); if none at all, fall back on default.
  5471. */
  5472. static void set_no_qsfp_atten(struct qib_devdata *dd, int change)
  5473. {
  5474. char *nxt, *str;
  5475. u32 pidx, unit, port, deflt, h1;
  5476. unsigned long val;
  5477. int any = 0, seth1;
  5478. int txdds_size;
  5479. str = txselect_list;
  5480. /* default number is validated in setup_txselect() */
  5481. deflt = simple_strtoul(str, &nxt, 0);
  5482. for (pidx = 0; pidx < dd->num_pports; ++pidx)
  5483. dd->pport[pidx].cpspec->no_eep = deflt;
  5484. txdds_size = TXDDS_TABLE_SZ + TXDDS_EXTRA_SZ;
  5485. if (IS_QME(dd) || IS_QMH(dd))
  5486. txdds_size += TXDDS_MFG_SZ;
  5487. while (*nxt && nxt[1]) {
  5488. str = ++nxt;
  5489. unit = simple_strtoul(str, &nxt, 0);
  5490. if (nxt == str || !*nxt || *nxt != ',') {
  5491. while (*nxt && *nxt++ != ' ') /* skip to next, if any */
  5492. ;
  5493. continue;
  5494. }
  5495. str = ++nxt;
  5496. port = simple_strtoul(str, &nxt, 0);
  5497. if (nxt == str || *nxt != '=') {
  5498. while (*nxt && *nxt++ != ' ') /* skip to next, if any */
  5499. ;
  5500. continue;
  5501. }
  5502. str = ++nxt;
  5503. val = simple_strtoul(str, &nxt, 0);
  5504. if (nxt == str) {
  5505. while (*nxt && *nxt++ != ' ') /* skip to next, if any */
  5506. ;
  5507. continue;
  5508. }
  5509. if (val >= txdds_size)
  5510. continue;
  5511. seth1 = 0;
  5512. h1 = 0; /* gcc thinks it might be used uninitted */
  5513. if (*nxt == ',' && nxt[1]) {
  5514. str = ++nxt;
  5515. h1 = (u32)simple_strtoul(str, &nxt, 0);
  5516. if (nxt == str)
  5517. while (*nxt && *nxt++ != ' ') /* skip */
  5518. ;
  5519. else
  5520. seth1 = 1;
  5521. }
  5522. for (pidx = 0; dd->unit == unit && pidx < dd->num_pports;
  5523. ++pidx) {
  5524. struct qib_pportdata *ppd = &dd->pport[pidx];
  5525. if (ppd->port != port || !ppd->link_speed_supported)
  5526. continue;
  5527. ppd->cpspec->no_eep = val;
  5528. if (seth1)
  5529. ppd->cpspec->h1_val = h1;
  5530. /* now change the IBC and serdes, overriding generic */
  5531. init_txdds_table(ppd, 1);
  5532. /* Re-enable the physical state machine on mezz boards
  5533. * now that the correct settings have been set.
  5534. * QSFP boards are handles by the QSFP event handler */
  5535. if (IS_QMH(dd) || IS_QME(dd))
  5536. qib_set_ib_7322_lstate(ppd, 0,
  5537. QLOGIC_IB_IBCC_LINKINITCMD_SLEEP);
  5538. any++;
  5539. }
  5540. if (*nxt == '\n')
  5541. break; /* done */
  5542. }
  5543. if (change && !any) {
  5544. /* no specific setting, use the default.
  5545. * Change the IBC and serdes, but since it's
  5546. * general, don't override specific settings.
  5547. */
  5548. for (pidx = 0; pidx < dd->num_pports; ++pidx)
  5549. if (dd->pport[pidx].link_speed_supported)
  5550. init_txdds_table(&dd->pport[pidx], 0);
  5551. }
  5552. }
  5553. /* handle the txselect parameter changing */
  5554. static int setup_txselect(const char *str, struct kernel_param *kp)
  5555. {
  5556. struct qib_devdata *dd;
  5557. unsigned long val;
  5558. char *n;
  5559. if (strlen(str) >= MAX_ATTEN_LEN) {
  5560. pr_info("txselect_values string too long\n");
  5561. return -ENOSPC;
  5562. }
  5563. val = simple_strtoul(str, &n, 0);
  5564. if (n == str || val >= (TXDDS_TABLE_SZ + TXDDS_EXTRA_SZ +
  5565. TXDDS_MFG_SZ)) {
  5566. pr_info("txselect_values must start with a number < %d\n",
  5567. TXDDS_TABLE_SZ + TXDDS_EXTRA_SZ + TXDDS_MFG_SZ);
  5568. return -EINVAL;
  5569. }
  5570. strcpy(txselect_list, str);
  5571. list_for_each_entry(dd, &qib_dev_list, list)
  5572. if (dd->deviceid == PCI_DEVICE_ID_QLOGIC_IB_7322)
  5573. set_no_qsfp_atten(dd, 1);
  5574. return 0;
  5575. }
  5576. /*
  5577. * Write the final few registers that depend on some of the
  5578. * init setup. Done late in init, just before bringing up
  5579. * the serdes.
  5580. */
  5581. static int qib_late_7322_initreg(struct qib_devdata *dd)
  5582. {
  5583. int ret = 0, n;
  5584. u64 val;
  5585. qib_write_kreg(dd, kr_rcvhdrentsize, dd->rcvhdrentsize);
  5586. qib_write_kreg(dd, kr_rcvhdrsize, dd->rcvhdrsize);
  5587. qib_write_kreg(dd, kr_rcvhdrcnt, dd->rcvhdrcnt);
  5588. qib_write_kreg(dd, kr_sendpioavailaddr, dd->pioavailregs_phys);
  5589. val = qib_read_kreg64(dd, kr_sendpioavailaddr);
  5590. if (val != dd->pioavailregs_phys) {
  5591. qib_dev_err(dd,
  5592. "Catastrophic software error, SendPIOAvailAddr written as %lx, read back as %llx\n",
  5593. (unsigned long) dd->pioavailregs_phys,
  5594. (unsigned long long) val);
  5595. ret = -EINVAL;
  5596. }
  5597. n = dd->piobcnt2k + dd->piobcnt4k + NUM_VL15_BUFS;
  5598. qib_7322_txchk_change(dd, 0, n, TXCHK_CHG_TYPE_KERN, NULL);
  5599. /* driver sends get pkey, lid, etc. checking also, to catch bugs */
  5600. qib_7322_txchk_change(dd, 0, n, TXCHK_CHG_TYPE_ENAB1, NULL);
  5601. qib_register_observer(dd, &sendctrl_0_observer);
  5602. qib_register_observer(dd, &sendctrl_1_observer);
  5603. dd->control &= ~QLOGIC_IB_C_SDMAFETCHPRIOEN;
  5604. qib_write_kreg(dd, kr_control, dd->control);
  5605. /*
  5606. * Set SendDmaFetchPriority and init Tx params, including
  5607. * QSFP handler on boards that have QSFP.
  5608. * First set our default attenuation entry for cables that
  5609. * don't have valid attenuation.
  5610. */
  5611. set_no_qsfp_atten(dd, 0);
  5612. for (n = 0; n < dd->num_pports; ++n) {
  5613. struct qib_pportdata *ppd = dd->pport + n;
  5614. qib_write_kreg_port(ppd, krp_senddmaprioritythld,
  5615. sdma_fetch_prio & 0xf);
  5616. /* Initialize qsfp if present on board. */
  5617. if (dd->flags & QIB_HAS_QSFP)
  5618. qib_init_7322_qsfp(ppd);
  5619. }
  5620. dd->control |= QLOGIC_IB_C_SDMAFETCHPRIOEN;
  5621. qib_write_kreg(dd, kr_control, dd->control);
  5622. return ret;
  5623. }
  5624. /* per IB port errors. */
  5625. #define SENDCTRL_PIBP (MASK_ACROSS(0, 1) | MASK_ACROSS(3, 3) | \
  5626. MASK_ACROSS(8, 15))
  5627. #define RCVCTRL_PIBP (MASK_ACROSS(0, 17) | MASK_ACROSS(39, 41))
  5628. #define ERRS_PIBP (MASK_ACROSS(57, 58) | MASK_ACROSS(54, 54) | \
  5629. MASK_ACROSS(36, 49) | MASK_ACROSS(29, 34) | MASK_ACROSS(14, 17) | \
  5630. MASK_ACROSS(0, 11))
  5631. /*
  5632. * Write the initialization per-port registers that need to be done at
  5633. * driver load and after reset completes (i.e., that aren't done as part
  5634. * of other init procedures called from qib_init.c).
  5635. * Some of these should be redundant on reset, but play safe.
  5636. */
  5637. static void write_7322_init_portregs(struct qib_pportdata *ppd)
  5638. {
  5639. u64 val;
  5640. int i;
  5641. if (!ppd->link_speed_supported) {
  5642. /* no buffer credits for this port */
  5643. for (i = 1; i < 8; i++)
  5644. qib_write_kreg_port(ppd, krp_rxcreditvl0 + i, 0);
  5645. qib_write_kreg_port(ppd, krp_ibcctrl_b, 0);
  5646. qib_write_kreg(ppd->dd, kr_scratch, 0);
  5647. return;
  5648. }
  5649. /*
  5650. * Set the number of supported virtual lanes in IBC,
  5651. * for flow control packet handling on unsupported VLs
  5652. */
  5653. val = qib_read_kreg_port(ppd, krp_ibsdtestiftx);
  5654. val &= ~SYM_MASK(IB_SDTEST_IF_TX_0, VL_CAP);
  5655. val |= (u64)(ppd->vls_supported - 1) <<
  5656. SYM_LSB(IB_SDTEST_IF_TX_0, VL_CAP);
  5657. qib_write_kreg_port(ppd, krp_ibsdtestiftx, val);
  5658. qib_write_kreg_port(ppd, krp_rcvbthqp, QIB_KD_QP);
  5659. /* enable tx header checking */
  5660. qib_write_kreg_port(ppd, krp_sendcheckcontrol, IBA7322_SENDCHK_PKEY |
  5661. IBA7322_SENDCHK_BTHQP | IBA7322_SENDCHK_SLID |
  5662. IBA7322_SENDCHK_RAW_IPV6 | IBA7322_SENDCHK_MINSZ);
  5663. qib_write_kreg_port(ppd, krp_ncmodectrl,
  5664. SYM_MASK(IBNCModeCtrl_0, ScrambleCapLocal));
  5665. /*
  5666. * Unconditionally clear the bufmask bits. If SDMA is
  5667. * enabled, we'll set them appropriately later.
  5668. */
  5669. qib_write_kreg_port(ppd, krp_senddmabufmask0, 0);
  5670. qib_write_kreg_port(ppd, krp_senddmabufmask1, 0);
  5671. qib_write_kreg_port(ppd, krp_senddmabufmask2, 0);
  5672. if (ppd->dd->cspec->r1)
  5673. ppd->p_sendctrl |= SYM_MASK(SendCtrl_0, ForceCreditUpToDate);
  5674. }
  5675. /*
  5676. * Write the initialization per-device registers that need to be done at
  5677. * driver load and after reset completes (i.e., that aren't done as part
  5678. * of other init procedures called from qib_init.c). Also write per-port
  5679. * registers that are affected by overall device config, such as QP mapping
  5680. * Some of these should be redundant on reset, but play safe.
  5681. */
  5682. static void write_7322_initregs(struct qib_devdata *dd)
  5683. {
  5684. struct qib_pportdata *ppd;
  5685. int i, pidx;
  5686. u64 val;
  5687. /* Set Multicast QPs received by port 2 to map to context one. */
  5688. qib_write_kreg(dd, KREG_IDX(RcvQPMulticastContext_1), 1);
  5689. for (pidx = 0; pidx < dd->num_pports; ++pidx) {
  5690. unsigned n, regno;
  5691. unsigned long flags;
  5692. if (dd->n_krcv_queues < 2 ||
  5693. !dd->pport[pidx].link_speed_supported)
  5694. continue;
  5695. ppd = &dd->pport[pidx];
  5696. /* be paranoid against later code motion, etc. */
  5697. spin_lock_irqsave(&dd->cspec->rcvmod_lock, flags);
  5698. ppd->p_rcvctrl |= SYM_MASK(RcvCtrl_0, RcvQPMapEnable);
  5699. spin_unlock_irqrestore(&dd->cspec->rcvmod_lock, flags);
  5700. /* Initialize QP to context mapping */
  5701. regno = krp_rcvqpmaptable;
  5702. val = 0;
  5703. if (dd->num_pports > 1)
  5704. n = dd->first_user_ctxt / dd->num_pports;
  5705. else
  5706. n = dd->first_user_ctxt - 1;
  5707. for (i = 0; i < 32; ) {
  5708. unsigned ctxt;
  5709. if (dd->num_pports > 1)
  5710. ctxt = (i % n) * dd->num_pports + pidx;
  5711. else if (i % n)
  5712. ctxt = (i % n) + 1;
  5713. else
  5714. ctxt = ppd->hw_pidx;
  5715. val |= ctxt << (5 * (i % 6));
  5716. i++;
  5717. if (i % 6 == 0) {
  5718. qib_write_kreg_port(ppd, regno, val);
  5719. val = 0;
  5720. regno++;
  5721. }
  5722. }
  5723. qib_write_kreg_port(ppd, regno, val);
  5724. }
  5725. /*
  5726. * Setup up interrupt mitigation for kernel contexts, but
  5727. * not user contexts (user contexts use interrupts when
  5728. * stalled waiting for any packet, so want those interrupts
  5729. * right away).
  5730. */
  5731. for (i = 0; i < dd->first_user_ctxt; i++) {
  5732. dd->cspec->rcvavail_timeout[i] = rcv_int_timeout;
  5733. qib_write_kreg(dd, kr_rcvavailtimeout + i, rcv_int_timeout);
  5734. }
  5735. /*
  5736. * Initialize as (disabled) rcvflow tables. Application code
  5737. * will setup each flow as it uses the flow.
  5738. * Doesn't clear any of the error bits that might be set.
  5739. */
  5740. val = TIDFLOW_ERRBITS; /* these are W1C */
  5741. for (i = 0; i < dd->cfgctxts; i++) {
  5742. int flow;
  5743. for (flow = 0; flow < NUM_TIDFLOWS_CTXT; flow++)
  5744. qib_write_ureg(dd, ur_rcvflowtable+flow, val, i);
  5745. }
  5746. /*
  5747. * dual cards init to dual port recovery, single port cards to
  5748. * the one port. Dual port cards may later adjust to 1 port,
  5749. * and then back to dual port if both ports are connected
  5750. * */
  5751. if (dd->num_pports)
  5752. setup_7322_link_recovery(dd->pport, dd->num_pports > 1);
  5753. }
  5754. static int qib_init_7322_variables(struct qib_devdata *dd)
  5755. {
  5756. struct qib_pportdata *ppd;
  5757. unsigned features, pidx, sbufcnt;
  5758. int ret, mtu;
  5759. u32 sbufs, updthresh;
  5760. /* pport structs are contiguous, allocated after devdata */
  5761. ppd = (struct qib_pportdata *)(dd + 1);
  5762. dd->pport = ppd;
  5763. ppd[0].dd = dd;
  5764. ppd[1].dd = dd;
  5765. dd->cspec = (struct qib_chip_specific *)(ppd + 2);
  5766. ppd[0].cpspec = (struct qib_chippport_specific *)(dd->cspec + 1);
  5767. ppd[1].cpspec = &ppd[0].cpspec[1];
  5768. ppd[0].cpspec->ppd = &ppd[0]; /* for autoneg_7322_work() */
  5769. ppd[1].cpspec->ppd = &ppd[1]; /* for autoneg_7322_work() */
  5770. spin_lock_init(&dd->cspec->rcvmod_lock);
  5771. spin_lock_init(&dd->cspec->gpio_lock);
  5772. /* we haven't yet set QIB_PRESENT, so use read directly */
  5773. dd->revision = readq(&dd->kregbase[kr_revision]);
  5774. if ((dd->revision & 0xffffffffU) == 0xffffffffU) {
  5775. qib_dev_err(dd,
  5776. "Revision register read failure, giving up initialization\n");
  5777. ret = -ENODEV;
  5778. goto bail;
  5779. }
  5780. dd->flags |= QIB_PRESENT; /* now register routines work */
  5781. dd->majrev = (u8) SYM_FIELD(dd->revision, Revision_R, ChipRevMajor);
  5782. dd->minrev = (u8) SYM_FIELD(dd->revision, Revision_R, ChipRevMinor);
  5783. dd->cspec->r1 = dd->minrev == 1;
  5784. get_7322_chip_params(dd);
  5785. features = qib_7322_boardname(dd);
  5786. /* now that piobcnt2k and 4k set, we can allocate these */
  5787. sbufcnt = dd->piobcnt2k + dd->piobcnt4k +
  5788. NUM_VL15_BUFS + BITS_PER_LONG - 1;
  5789. sbufcnt /= BITS_PER_LONG;
  5790. dd->cspec->sendchkenable = kmalloc(sbufcnt *
  5791. sizeof(*dd->cspec->sendchkenable), GFP_KERNEL);
  5792. dd->cspec->sendgrhchk = kmalloc(sbufcnt *
  5793. sizeof(*dd->cspec->sendgrhchk), GFP_KERNEL);
  5794. dd->cspec->sendibchk = kmalloc(sbufcnt *
  5795. sizeof(*dd->cspec->sendibchk), GFP_KERNEL);
  5796. if (!dd->cspec->sendchkenable || !dd->cspec->sendgrhchk ||
  5797. !dd->cspec->sendibchk) {
  5798. qib_dev_err(dd, "Failed allocation for hdrchk bitmaps\n");
  5799. ret = -ENOMEM;
  5800. goto bail;
  5801. }
  5802. ppd = dd->pport;
  5803. /*
  5804. * GPIO bits for TWSI data and clock,
  5805. * used for serial EEPROM.
  5806. */
  5807. dd->gpio_sda_num = _QIB_GPIO_SDA_NUM;
  5808. dd->gpio_scl_num = _QIB_GPIO_SCL_NUM;
  5809. dd->twsi_eeprom_dev = QIB_TWSI_EEPROM_DEV;
  5810. dd->flags |= QIB_HAS_INTX | QIB_HAS_LINK_LATENCY |
  5811. QIB_NODMA_RTAIL | QIB_HAS_VLSUPP | QIB_HAS_HDRSUPP |
  5812. QIB_HAS_THRESH_UPDATE |
  5813. (sdma_idle_cnt ? QIB_HAS_SDMA_TIMEOUT : 0);
  5814. dd->flags |= qib_special_trigger ?
  5815. QIB_USE_SPCL_TRIG : QIB_HAS_SEND_DMA;
  5816. /*
  5817. * Setup initial values. These may change when PAT is enabled, but
  5818. * we need these to do initial chip register accesses.
  5819. */
  5820. qib_7322_set_baseaddrs(dd);
  5821. mtu = ib_mtu_enum_to_int(qib_ibmtu);
  5822. if (mtu == -1)
  5823. mtu = QIB_DEFAULT_MTU;
  5824. dd->cspec->int_enable_mask = QIB_I_BITSEXTANT;
  5825. /* all hwerrors become interrupts, unless special purposed */
  5826. dd->cspec->hwerrmask = ~0ULL;
  5827. /* link_recovery setup causes these errors, so ignore them,
  5828. * other than clearing them when they occur */
  5829. dd->cspec->hwerrmask &=
  5830. ~(SYM_MASK(HwErrMask, IBSerdesPClkNotDetectMask_0) |
  5831. SYM_MASK(HwErrMask, IBSerdesPClkNotDetectMask_1) |
  5832. HWE_MASK(LATriggered));
  5833. for (pidx = 0; pidx < NUM_IB_PORTS; ++pidx) {
  5834. struct qib_chippport_specific *cp = ppd->cpspec;
  5835. ppd->link_speed_supported = features & PORT_SPD_CAP;
  5836. features >>= PORT_SPD_CAP_SHIFT;
  5837. if (!ppd->link_speed_supported) {
  5838. /* single port mode (7340, or configured) */
  5839. dd->skip_kctxt_mask |= 1 << pidx;
  5840. if (pidx == 0) {
  5841. /* Make sure port is disabled. */
  5842. qib_write_kreg_port(ppd, krp_rcvctrl, 0);
  5843. qib_write_kreg_port(ppd, krp_ibcctrl_a, 0);
  5844. ppd[0] = ppd[1];
  5845. dd->cspec->hwerrmask &= ~(SYM_MASK(HwErrMask,
  5846. IBSerdesPClkNotDetectMask_0)
  5847. | SYM_MASK(HwErrMask,
  5848. SDmaMemReadErrMask_0));
  5849. dd->cspec->int_enable_mask &= ~(
  5850. SYM_MASK(IntMask, SDmaCleanupDoneMask_0) |
  5851. SYM_MASK(IntMask, SDmaIdleIntMask_0) |
  5852. SYM_MASK(IntMask, SDmaProgressIntMask_0) |
  5853. SYM_MASK(IntMask, SDmaIntMask_0) |
  5854. SYM_MASK(IntMask, ErrIntMask_0) |
  5855. SYM_MASK(IntMask, SendDoneIntMask_0));
  5856. } else {
  5857. /* Make sure port is disabled. */
  5858. qib_write_kreg_port(ppd, krp_rcvctrl, 0);
  5859. qib_write_kreg_port(ppd, krp_ibcctrl_a, 0);
  5860. dd->cspec->hwerrmask &= ~(SYM_MASK(HwErrMask,
  5861. IBSerdesPClkNotDetectMask_1)
  5862. | SYM_MASK(HwErrMask,
  5863. SDmaMemReadErrMask_1));
  5864. dd->cspec->int_enable_mask &= ~(
  5865. SYM_MASK(IntMask, SDmaCleanupDoneMask_1) |
  5866. SYM_MASK(IntMask, SDmaIdleIntMask_1) |
  5867. SYM_MASK(IntMask, SDmaProgressIntMask_1) |
  5868. SYM_MASK(IntMask, SDmaIntMask_1) |
  5869. SYM_MASK(IntMask, ErrIntMask_1) |
  5870. SYM_MASK(IntMask, SendDoneIntMask_1));
  5871. }
  5872. continue;
  5873. }
  5874. dd->num_pports++;
  5875. qib_init_pportdata(ppd, dd, pidx, dd->num_pports);
  5876. ppd->link_width_supported = IB_WIDTH_1X | IB_WIDTH_4X;
  5877. ppd->link_width_enabled = IB_WIDTH_4X;
  5878. ppd->link_speed_enabled = ppd->link_speed_supported;
  5879. /*
  5880. * Set the initial values to reasonable default, will be set
  5881. * for real when link is up.
  5882. */
  5883. ppd->link_width_active = IB_WIDTH_4X;
  5884. ppd->link_speed_active = QIB_IB_SDR;
  5885. ppd->delay_mult = ib_rate_to_delay[IB_RATE_10_GBPS];
  5886. switch (qib_num_cfg_vls) {
  5887. case 1:
  5888. ppd->vls_supported = IB_VL_VL0;
  5889. break;
  5890. case 2:
  5891. ppd->vls_supported = IB_VL_VL0_1;
  5892. break;
  5893. default:
  5894. qib_devinfo(dd->pcidev,
  5895. "Invalid num_vls %u, using 4 VLs\n",
  5896. qib_num_cfg_vls);
  5897. qib_num_cfg_vls = 4;
  5898. /* fall through */
  5899. case 4:
  5900. ppd->vls_supported = IB_VL_VL0_3;
  5901. break;
  5902. case 8:
  5903. if (mtu <= 2048)
  5904. ppd->vls_supported = IB_VL_VL0_7;
  5905. else {
  5906. qib_devinfo(dd->pcidev,
  5907. "Invalid num_vls %u for MTU %d "
  5908. ", using 4 VLs\n",
  5909. qib_num_cfg_vls, mtu);
  5910. ppd->vls_supported = IB_VL_VL0_3;
  5911. qib_num_cfg_vls = 4;
  5912. }
  5913. break;
  5914. }
  5915. ppd->vls_operational = ppd->vls_supported;
  5916. init_waitqueue_head(&cp->autoneg_wait);
  5917. INIT_DELAYED_WORK(&cp->autoneg_work,
  5918. autoneg_7322_work);
  5919. if (ppd->dd->cspec->r1)
  5920. INIT_DELAYED_WORK(&cp->ipg_work, ipg_7322_work);
  5921. /*
  5922. * For Mez and similar cards, no qsfp info, so do
  5923. * the "cable info" setup here. Can be overridden
  5924. * in adapter-specific routines.
  5925. */
  5926. if (!(dd->flags & QIB_HAS_QSFP)) {
  5927. if (!IS_QMH(dd) && !IS_QME(dd))
  5928. qib_devinfo(dd->pcidev,
  5929. "IB%u:%u: Unknown mezzanine card type\n",
  5930. dd->unit, ppd->port);
  5931. cp->h1_val = IS_QMH(dd) ? H1_FORCE_QMH : H1_FORCE_QME;
  5932. /*
  5933. * Choose center value as default tx serdes setting
  5934. * until changed through module parameter.
  5935. */
  5936. ppd->cpspec->no_eep = IS_QMH(dd) ?
  5937. TXDDS_TABLE_SZ + 2 : TXDDS_TABLE_SZ + 4;
  5938. } else
  5939. cp->h1_val = H1_FORCE_VAL;
  5940. /* Avoid writes to chip for mini_init */
  5941. if (!qib_mini_init)
  5942. write_7322_init_portregs(ppd);
  5943. init_timer(&cp->chase_timer);
  5944. cp->chase_timer.function = reenable_chase;
  5945. cp->chase_timer.data = (unsigned long)ppd;
  5946. ppd++;
  5947. }
  5948. dd->rcvhdrentsize = qib_rcvhdrentsize ?
  5949. qib_rcvhdrentsize : QIB_RCVHDR_ENTSIZE;
  5950. dd->rcvhdrsize = qib_rcvhdrsize ?
  5951. qib_rcvhdrsize : QIB_DFLT_RCVHDRSIZE;
  5952. dd->rhf_offset = dd->rcvhdrentsize - sizeof(u64) / sizeof(u32);
  5953. /* we always allocate at least 2048 bytes for eager buffers */
  5954. dd->rcvegrbufsize = max(mtu, 2048);
  5955. BUG_ON(!is_power_of_2(dd->rcvegrbufsize));
  5956. dd->rcvegrbufsize_shift = ilog2(dd->rcvegrbufsize);
  5957. qib_7322_tidtemplate(dd);
  5958. /*
  5959. * We can request a receive interrupt for 1 or
  5960. * more packets from current offset.
  5961. */
  5962. dd->rhdrhead_intr_off =
  5963. (u64) rcv_int_count << IBA7322_HDRHEAD_PKTINT_SHIFT;
  5964. /* setup the stats timer; the add_timer is done at end of init */
  5965. init_timer(&dd->stats_timer);
  5966. dd->stats_timer.function = qib_get_7322_faststats;
  5967. dd->stats_timer.data = (unsigned long) dd;
  5968. dd->ureg_align = 0x10000; /* 64KB alignment */
  5969. dd->piosize2kmax_dwords = dd->piosize2k >> 2;
  5970. qib_7322_config_ctxts(dd);
  5971. qib_set_ctxtcnt(dd);
  5972. if (qib_wc_pat) {
  5973. resource_size_t vl15off;
  5974. /*
  5975. * We do not set WC on the VL15 buffers to avoid
  5976. * a rare problem with unaligned writes from
  5977. * interrupt-flushed store buffers, so we need
  5978. * to map those separately here. We can't solve
  5979. * this for the rarely used mtrr case.
  5980. */
  5981. ret = init_chip_wc_pat(dd, 0);
  5982. if (ret)
  5983. goto bail;
  5984. /* vl15 buffers start just after the 4k buffers */
  5985. vl15off = dd->physaddr + (dd->piobufbase >> 32) +
  5986. dd->piobcnt4k * dd->align4k;
  5987. dd->piovl15base = ioremap_nocache(vl15off,
  5988. NUM_VL15_BUFS * dd->align4k);
  5989. if (!dd->piovl15base) {
  5990. ret = -ENOMEM;
  5991. goto bail;
  5992. }
  5993. }
  5994. qib_7322_set_baseaddrs(dd); /* set chip access pointers now */
  5995. ret = 0;
  5996. if (qib_mini_init)
  5997. goto bail;
  5998. if (!dd->num_pports) {
  5999. qib_dev_err(dd, "No ports enabled, giving up initialization\n");
  6000. goto bail; /* no error, so can still figure out why err */
  6001. }
  6002. write_7322_initregs(dd);
  6003. ret = qib_create_ctxts(dd);
  6004. init_7322_cntrnames(dd);
  6005. updthresh = 8U; /* update threshold */
  6006. /* use all of 4KB buffers for the kernel SDMA, zero if !SDMA.
  6007. * reserve the update threshold amount for other kernel use, such
  6008. * as sending SMI, MAD, and ACKs, or 3, whichever is greater,
  6009. * unless we aren't enabling SDMA, in which case we want to use
  6010. * all the 4k bufs for the kernel.
  6011. * if this was less than the update threshold, we could wait
  6012. * a long time for an update. Coded this way because we
  6013. * sometimes change the update threshold for various reasons,
  6014. * and we want this to remain robust.
  6015. */
  6016. if (dd->flags & QIB_HAS_SEND_DMA) {
  6017. dd->cspec->sdmabufcnt = dd->piobcnt4k;
  6018. sbufs = updthresh > 3 ? updthresh : 3;
  6019. } else {
  6020. dd->cspec->sdmabufcnt = 0;
  6021. sbufs = dd->piobcnt4k;
  6022. }
  6023. dd->cspec->lastbuf_for_pio = dd->piobcnt2k + dd->piobcnt4k -
  6024. dd->cspec->sdmabufcnt;
  6025. dd->lastctxt_piobuf = dd->cspec->lastbuf_for_pio - sbufs;
  6026. dd->cspec->lastbuf_for_pio--; /* range is <= , not < */
  6027. dd->last_pio = dd->cspec->lastbuf_for_pio;
  6028. dd->pbufsctxt = (dd->cfgctxts > dd->first_user_ctxt) ?
  6029. dd->lastctxt_piobuf / (dd->cfgctxts - dd->first_user_ctxt) : 0;
  6030. /*
  6031. * If we have 16 user contexts, we will have 7 sbufs
  6032. * per context, so reduce the update threshold to match. We
  6033. * want to update before we actually run out, at low pbufs/ctxt
  6034. * so give ourselves some margin.
  6035. */
  6036. if (dd->pbufsctxt >= 2 && dd->pbufsctxt - 2 < updthresh)
  6037. updthresh = dd->pbufsctxt - 2;
  6038. dd->cspec->updthresh_dflt = updthresh;
  6039. dd->cspec->updthresh = updthresh;
  6040. /* before full enable, no interrupts, no locking needed */
  6041. dd->sendctrl |= ((updthresh & SYM_RMASK(SendCtrl, AvailUpdThld))
  6042. << SYM_LSB(SendCtrl, AvailUpdThld)) |
  6043. SYM_MASK(SendCtrl, SendBufAvailPad64Byte);
  6044. dd->psxmitwait_supported = 1;
  6045. dd->psxmitwait_check_rate = QIB_7322_PSXMITWAIT_CHECK_RATE;
  6046. bail:
  6047. if (!dd->ctxtcnt)
  6048. dd->ctxtcnt = 1; /* for other initialization code */
  6049. return ret;
  6050. }
  6051. static u32 __iomem *qib_7322_getsendbuf(struct qib_pportdata *ppd, u64 pbc,
  6052. u32 *pbufnum)
  6053. {
  6054. u32 first, last, plen = pbc & QIB_PBC_LENGTH_MASK;
  6055. struct qib_devdata *dd = ppd->dd;
  6056. /* last is same for 2k and 4k, because we use 4k if all 2k busy */
  6057. if (pbc & PBC_7322_VL15_SEND) {
  6058. first = dd->piobcnt2k + dd->piobcnt4k + ppd->hw_pidx;
  6059. last = first;
  6060. } else {
  6061. if ((plen + 1) > dd->piosize2kmax_dwords)
  6062. first = dd->piobcnt2k;
  6063. else
  6064. first = 0;
  6065. last = dd->cspec->lastbuf_for_pio;
  6066. }
  6067. return qib_getsendbuf_range(dd, pbufnum, first, last);
  6068. }
  6069. static void qib_set_cntr_7322_sample(struct qib_pportdata *ppd, u32 intv,
  6070. u32 start)
  6071. {
  6072. qib_write_kreg_port(ppd, krp_psinterval, intv);
  6073. qib_write_kreg_port(ppd, krp_psstart, start);
  6074. }
  6075. /*
  6076. * Must be called with sdma_lock held, or before init finished.
  6077. */
  6078. static void qib_sdma_set_7322_desc_cnt(struct qib_pportdata *ppd, unsigned cnt)
  6079. {
  6080. qib_write_kreg_port(ppd, krp_senddmadesccnt, cnt);
  6081. }
  6082. /*
  6083. * sdma_lock should be acquired before calling this routine
  6084. */
  6085. static void dump_sdma_7322_state(struct qib_pportdata *ppd)
  6086. {
  6087. u64 reg, reg1, reg2;
  6088. reg = qib_read_kreg_port(ppd, krp_senddmastatus);
  6089. qib_dev_porterr(ppd->dd, ppd->port,
  6090. "SDMA senddmastatus: 0x%016llx\n", reg);
  6091. reg = qib_read_kreg_port(ppd, krp_sendctrl);
  6092. qib_dev_porterr(ppd->dd, ppd->port,
  6093. "SDMA sendctrl: 0x%016llx\n", reg);
  6094. reg = qib_read_kreg_port(ppd, krp_senddmabase);
  6095. qib_dev_porterr(ppd->dd, ppd->port,
  6096. "SDMA senddmabase: 0x%016llx\n", reg);
  6097. reg = qib_read_kreg_port(ppd, krp_senddmabufmask0);
  6098. reg1 = qib_read_kreg_port(ppd, krp_senddmabufmask1);
  6099. reg2 = qib_read_kreg_port(ppd, krp_senddmabufmask2);
  6100. qib_dev_porterr(ppd->dd, ppd->port,
  6101. "SDMA senddmabufmask 0:%llx 1:%llx 2:%llx\n",
  6102. reg, reg1, reg2);
  6103. /* get bufuse bits, clear them, and print them again if non-zero */
  6104. reg = qib_read_kreg_port(ppd, krp_senddmabuf_use0);
  6105. qib_write_kreg_port(ppd, krp_senddmabuf_use0, reg);
  6106. reg1 = qib_read_kreg_port(ppd, krp_senddmabuf_use1);
  6107. qib_write_kreg_port(ppd, krp_senddmabuf_use0, reg1);
  6108. reg2 = qib_read_kreg_port(ppd, krp_senddmabuf_use2);
  6109. qib_write_kreg_port(ppd, krp_senddmabuf_use0, reg2);
  6110. /* 0 and 1 should always be zero, so print as short form */
  6111. qib_dev_porterr(ppd->dd, ppd->port,
  6112. "SDMA current senddmabuf_use 0:%llx 1:%llx 2:%llx\n",
  6113. reg, reg1, reg2);
  6114. reg = qib_read_kreg_port(ppd, krp_senddmabuf_use0);
  6115. reg1 = qib_read_kreg_port(ppd, krp_senddmabuf_use1);
  6116. reg2 = qib_read_kreg_port(ppd, krp_senddmabuf_use2);
  6117. /* 0 and 1 should always be zero, so print as short form */
  6118. qib_dev_porterr(ppd->dd, ppd->port,
  6119. "SDMA cleared senddmabuf_use 0:%llx 1:%llx 2:%llx\n",
  6120. reg, reg1, reg2);
  6121. reg = qib_read_kreg_port(ppd, krp_senddmatail);
  6122. qib_dev_porterr(ppd->dd, ppd->port,
  6123. "SDMA senddmatail: 0x%016llx\n", reg);
  6124. reg = qib_read_kreg_port(ppd, krp_senddmahead);
  6125. qib_dev_porterr(ppd->dd, ppd->port,
  6126. "SDMA senddmahead: 0x%016llx\n", reg);
  6127. reg = qib_read_kreg_port(ppd, krp_senddmaheadaddr);
  6128. qib_dev_porterr(ppd->dd, ppd->port,
  6129. "SDMA senddmaheadaddr: 0x%016llx\n", reg);
  6130. reg = qib_read_kreg_port(ppd, krp_senddmalengen);
  6131. qib_dev_porterr(ppd->dd, ppd->port,
  6132. "SDMA senddmalengen: 0x%016llx\n", reg);
  6133. reg = qib_read_kreg_port(ppd, krp_senddmadesccnt);
  6134. qib_dev_porterr(ppd->dd, ppd->port,
  6135. "SDMA senddmadesccnt: 0x%016llx\n", reg);
  6136. reg = qib_read_kreg_port(ppd, krp_senddmaidlecnt);
  6137. qib_dev_porterr(ppd->dd, ppd->port,
  6138. "SDMA senddmaidlecnt: 0x%016llx\n", reg);
  6139. reg = qib_read_kreg_port(ppd, krp_senddmaprioritythld);
  6140. qib_dev_porterr(ppd->dd, ppd->port,
  6141. "SDMA senddmapriorityhld: 0x%016llx\n", reg);
  6142. reg = qib_read_kreg_port(ppd, krp_senddmareloadcnt);
  6143. qib_dev_porterr(ppd->dd, ppd->port,
  6144. "SDMA senddmareloadcnt: 0x%016llx\n", reg);
  6145. dump_sdma_state(ppd);
  6146. }
  6147. static struct sdma_set_state_action sdma_7322_action_table[] = {
  6148. [qib_sdma_state_s00_hw_down] = {
  6149. .go_s99_running_tofalse = 1,
  6150. .op_enable = 0,
  6151. .op_intenable = 0,
  6152. .op_halt = 0,
  6153. .op_drain = 0,
  6154. },
  6155. [qib_sdma_state_s10_hw_start_up_wait] = {
  6156. .op_enable = 0,
  6157. .op_intenable = 1,
  6158. .op_halt = 1,
  6159. .op_drain = 0,
  6160. },
  6161. [qib_sdma_state_s20_idle] = {
  6162. .op_enable = 1,
  6163. .op_intenable = 1,
  6164. .op_halt = 1,
  6165. .op_drain = 0,
  6166. },
  6167. [qib_sdma_state_s30_sw_clean_up_wait] = {
  6168. .op_enable = 0,
  6169. .op_intenable = 1,
  6170. .op_halt = 1,
  6171. .op_drain = 0,
  6172. },
  6173. [qib_sdma_state_s40_hw_clean_up_wait] = {
  6174. .op_enable = 1,
  6175. .op_intenable = 1,
  6176. .op_halt = 1,
  6177. .op_drain = 0,
  6178. },
  6179. [qib_sdma_state_s50_hw_halt_wait] = {
  6180. .op_enable = 1,
  6181. .op_intenable = 1,
  6182. .op_halt = 1,
  6183. .op_drain = 1,
  6184. },
  6185. [qib_sdma_state_s99_running] = {
  6186. .op_enable = 1,
  6187. .op_intenable = 1,
  6188. .op_halt = 0,
  6189. .op_drain = 0,
  6190. .go_s99_running_totrue = 1,
  6191. },
  6192. };
  6193. static void qib_7322_sdma_init_early(struct qib_pportdata *ppd)
  6194. {
  6195. ppd->sdma_state.set_state_action = sdma_7322_action_table;
  6196. }
  6197. static int init_sdma_7322_regs(struct qib_pportdata *ppd)
  6198. {
  6199. struct qib_devdata *dd = ppd->dd;
  6200. unsigned lastbuf, erstbuf;
  6201. u64 senddmabufmask[3] = { 0 };
  6202. int n, ret = 0;
  6203. qib_write_kreg_port(ppd, krp_senddmabase, ppd->sdma_descq_phys);
  6204. qib_sdma_7322_setlengen(ppd);
  6205. qib_sdma_update_7322_tail(ppd, 0); /* Set SendDmaTail */
  6206. qib_write_kreg_port(ppd, krp_senddmareloadcnt, sdma_idle_cnt);
  6207. qib_write_kreg_port(ppd, krp_senddmadesccnt, 0);
  6208. qib_write_kreg_port(ppd, krp_senddmaheadaddr, ppd->sdma_head_phys);
  6209. if (dd->num_pports)
  6210. n = dd->cspec->sdmabufcnt / dd->num_pports; /* no remainder */
  6211. else
  6212. n = dd->cspec->sdmabufcnt; /* failsafe for init */
  6213. erstbuf = (dd->piobcnt2k + dd->piobcnt4k) -
  6214. ((dd->num_pports == 1 || ppd->port == 2) ? n :
  6215. dd->cspec->sdmabufcnt);
  6216. lastbuf = erstbuf + n;
  6217. ppd->sdma_state.first_sendbuf = erstbuf;
  6218. ppd->sdma_state.last_sendbuf = lastbuf;
  6219. for (; erstbuf < lastbuf; ++erstbuf) {
  6220. unsigned word = erstbuf / BITS_PER_LONG;
  6221. unsigned bit = erstbuf & (BITS_PER_LONG - 1);
  6222. BUG_ON(word >= 3);
  6223. senddmabufmask[word] |= 1ULL << bit;
  6224. }
  6225. qib_write_kreg_port(ppd, krp_senddmabufmask0, senddmabufmask[0]);
  6226. qib_write_kreg_port(ppd, krp_senddmabufmask1, senddmabufmask[1]);
  6227. qib_write_kreg_port(ppd, krp_senddmabufmask2, senddmabufmask[2]);
  6228. return ret;
  6229. }
  6230. /* sdma_lock must be held */
  6231. static u16 qib_sdma_7322_gethead(struct qib_pportdata *ppd)
  6232. {
  6233. struct qib_devdata *dd = ppd->dd;
  6234. int sane;
  6235. int use_dmahead;
  6236. u16 swhead;
  6237. u16 swtail;
  6238. u16 cnt;
  6239. u16 hwhead;
  6240. use_dmahead = __qib_sdma_running(ppd) &&
  6241. (dd->flags & QIB_HAS_SDMA_TIMEOUT);
  6242. retry:
  6243. hwhead = use_dmahead ?
  6244. (u16) le64_to_cpu(*ppd->sdma_head_dma) :
  6245. (u16) qib_read_kreg_port(ppd, krp_senddmahead);
  6246. swhead = ppd->sdma_descq_head;
  6247. swtail = ppd->sdma_descq_tail;
  6248. cnt = ppd->sdma_descq_cnt;
  6249. if (swhead < swtail)
  6250. /* not wrapped */
  6251. sane = (hwhead >= swhead) & (hwhead <= swtail);
  6252. else if (swhead > swtail)
  6253. /* wrapped around */
  6254. sane = ((hwhead >= swhead) && (hwhead < cnt)) ||
  6255. (hwhead <= swtail);
  6256. else
  6257. /* empty */
  6258. sane = (hwhead == swhead);
  6259. if (unlikely(!sane)) {
  6260. if (use_dmahead) {
  6261. /* try one more time, directly from the register */
  6262. use_dmahead = 0;
  6263. goto retry;
  6264. }
  6265. /* proceed as if no progress */
  6266. hwhead = swhead;
  6267. }
  6268. return hwhead;
  6269. }
  6270. static int qib_sdma_7322_busy(struct qib_pportdata *ppd)
  6271. {
  6272. u64 hwstatus = qib_read_kreg_port(ppd, krp_senddmastatus);
  6273. return (hwstatus & SYM_MASK(SendDmaStatus_0, ScoreBoardDrainInProg)) ||
  6274. (hwstatus & SYM_MASK(SendDmaStatus_0, HaltInProg)) ||
  6275. !(hwstatus & SYM_MASK(SendDmaStatus_0, InternalSDmaHalt)) ||
  6276. !(hwstatus & SYM_MASK(SendDmaStatus_0, ScbEmpty));
  6277. }
  6278. /*
  6279. * Compute the amount of delay before sending the next packet if the
  6280. * port's send rate differs from the static rate set for the QP.
  6281. * The delay affects the next packet and the amount of the delay is
  6282. * based on the length of the this packet.
  6283. */
  6284. static u32 qib_7322_setpbc_control(struct qib_pportdata *ppd, u32 plen,
  6285. u8 srate, u8 vl)
  6286. {
  6287. u8 snd_mult = ppd->delay_mult;
  6288. u8 rcv_mult = ib_rate_to_delay[srate];
  6289. u32 ret;
  6290. ret = rcv_mult > snd_mult ? ((plen + 1) >> 1) * snd_mult : 0;
  6291. /* Indicate VL15, else set the VL in the control word */
  6292. if (vl == 15)
  6293. ret |= PBC_7322_VL15_SEND_CTRL;
  6294. else
  6295. ret |= vl << PBC_VL_NUM_LSB;
  6296. ret |= ((u32)(ppd->hw_pidx)) << PBC_PORT_SEL_LSB;
  6297. return ret;
  6298. }
  6299. /*
  6300. * Enable the per-port VL15 send buffers for use.
  6301. * They follow the rest of the buffers, without a config parameter.
  6302. * This was in initregs, but that is done before the shadow
  6303. * is set up, and this has to be done after the shadow is
  6304. * set up.
  6305. */
  6306. static void qib_7322_initvl15_bufs(struct qib_devdata *dd)
  6307. {
  6308. unsigned vl15bufs;
  6309. vl15bufs = dd->piobcnt2k + dd->piobcnt4k;
  6310. qib_chg_pioavailkernel(dd, vl15bufs, NUM_VL15_BUFS,
  6311. TXCHK_CHG_TYPE_KERN, NULL);
  6312. }
  6313. static void qib_7322_init_ctxt(struct qib_ctxtdata *rcd)
  6314. {
  6315. if (rcd->ctxt < NUM_IB_PORTS) {
  6316. if (rcd->dd->num_pports > 1) {
  6317. rcd->rcvegrcnt = KCTXT0_EGRCNT / 2;
  6318. rcd->rcvegr_tid_base = rcd->ctxt ? rcd->rcvegrcnt : 0;
  6319. } else {
  6320. rcd->rcvegrcnt = KCTXT0_EGRCNT;
  6321. rcd->rcvegr_tid_base = 0;
  6322. }
  6323. } else {
  6324. rcd->rcvegrcnt = rcd->dd->cspec->rcvegrcnt;
  6325. rcd->rcvegr_tid_base = KCTXT0_EGRCNT +
  6326. (rcd->ctxt - NUM_IB_PORTS) * rcd->rcvegrcnt;
  6327. }
  6328. }
  6329. #define QTXSLEEPS 5000
  6330. static void qib_7322_txchk_change(struct qib_devdata *dd, u32 start,
  6331. u32 len, u32 which, struct qib_ctxtdata *rcd)
  6332. {
  6333. int i;
  6334. const int last = start + len - 1;
  6335. const int lastr = last / BITS_PER_LONG;
  6336. u32 sleeps = 0;
  6337. int wait = rcd != NULL;
  6338. unsigned long flags;
  6339. while (wait) {
  6340. unsigned long shadow;
  6341. int cstart, previ = -1;
  6342. /*
  6343. * when flipping from kernel to user, we can't change
  6344. * the checking type if the buffer is allocated to the
  6345. * driver. It's OK the other direction, because it's
  6346. * from close, and we have just disarm'ed all the
  6347. * buffers. All the kernel to kernel changes are also
  6348. * OK.
  6349. */
  6350. for (cstart = start; cstart <= last; cstart++) {
  6351. i = ((2 * cstart) + QLOGIC_IB_SENDPIOAVAIL_BUSY_SHIFT)
  6352. / BITS_PER_LONG;
  6353. if (i != previ) {
  6354. shadow = (unsigned long)
  6355. le64_to_cpu(dd->pioavailregs_dma[i]);
  6356. previ = i;
  6357. }
  6358. if (test_bit(((2 * cstart) +
  6359. QLOGIC_IB_SENDPIOAVAIL_BUSY_SHIFT)
  6360. % BITS_PER_LONG, &shadow))
  6361. break;
  6362. }
  6363. if (cstart > last)
  6364. break;
  6365. if (sleeps == QTXSLEEPS)
  6366. break;
  6367. /* make sure we see an updated copy next time around */
  6368. sendctrl_7322_mod(dd->pport, QIB_SENDCTRL_AVAIL_BLIP);
  6369. sleeps++;
  6370. msleep(20);
  6371. }
  6372. switch (which) {
  6373. case TXCHK_CHG_TYPE_DIS1:
  6374. /*
  6375. * disable checking on a range; used by diags; just
  6376. * one buffer, but still written generically
  6377. */
  6378. for (i = start; i <= last; i++)
  6379. clear_bit(i, dd->cspec->sendchkenable);
  6380. break;
  6381. case TXCHK_CHG_TYPE_ENAB1:
  6382. /*
  6383. * (re)enable checking on a range; used by diags; just
  6384. * one buffer, but still written generically; read
  6385. * scratch to be sure buffer actually triggered, not
  6386. * just flushed from processor.
  6387. */
  6388. qib_read_kreg32(dd, kr_scratch);
  6389. for (i = start; i <= last; i++)
  6390. set_bit(i, dd->cspec->sendchkenable);
  6391. break;
  6392. case TXCHK_CHG_TYPE_KERN:
  6393. /* usable by kernel */
  6394. for (i = start; i <= last; i++) {
  6395. set_bit(i, dd->cspec->sendibchk);
  6396. clear_bit(i, dd->cspec->sendgrhchk);
  6397. }
  6398. spin_lock_irqsave(&dd->uctxt_lock, flags);
  6399. /* see if we need to raise avail update threshold */
  6400. for (i = dd->first_user_ctxt;
  6401. dd->cspec->updthresh != dd->cspec->updthresh_dflt
  6402. && i < dd->cfgctxts; i++)
  6403. if (dd->rcd[i] && dd->rcd[i]->subctxt_cnt &&
  6404. ((dd->rcd[i]->piocnt / dd->rcd[i]->subctxt_cnt) - 1)
  6405. < dd->cspec->updthresh_dflt)
  6406. break;
  6407. spin_unlock_irqrestore(&dd->uctxt_lock, flags);
  6408. if (i == dd->cfgctxts) {
  6409. spin_lock_irqsave(&dd->sendctrl_lock, flags);
  6410. dd->cspec->updthresh = dd->cspec->updthresh_dflt;
  6411. dd->sendctrl &= ~SYM_MASK(SendCtrl, AvailUpdThld);
  6412. dd->sendctrl |= (dd->cspec->updthresh &
  6413. SYM_RMASK(SendCtrl, AvailUpdThld)) <<
  6414. SYM_LSB(SendCtrl, AvailUpdThld);
  6415. spin_unlock_irqrestore(&dd->sendctrl_lock, flags);
  6416. sendctrl_7322_mod(dd->pport, QIB_SENDCTRL_AVAIL_BLIP);
  6417. }
  6418. break;
  6419. case TXCHK_CHG_TYPE_USER:
  6420. /* for user process */
  6421. for (i = start; i <= last; i++) {
  6422. clear_bit(i, dd->cspec->sendibchk);
  6423. set_bit(i, dd->cspec->sendgrhchk);
  6424. }
  6425. spin_lock_irqsave(&dd->sendctrl_lock, flags);
  6426. if (rcd && rcd->subctxt_cnt && ((rcd->piocnt
  6427. / rcd->subctxt_cnt) - 1) < dd->cspec->updthresh) {
  6428. dd->cspec->updthresh = (rcd->piocnt /
  6429. rcd->subctxt_cnt) - 1;
  6430. dd->sendctrl &= ~SYM_MASK(SendCtrl, AvailUpdThld);
  6431. dd->sendctrl |= (dd->cspec->updthresh &
  6432. SYM_RMASK(SendCtrl, AvailUpdThld))
  6433. << SYM_LSB(SendCtrl, AvailUpdThld);
  6434. spin_unlock_irqrestore(&dd->sendctrl_lock, flags);
  6435. sendctrl_7322_mod(dd->pport, QIB_SENDCTRL_AVAIL_BLIP);
  6436. } else
  6437. spin_unlock_irqrestore(&dd->sendctrl_lock, flags);
  6438. break;
  6439. default:
  6440. break;
  6441. }
  6442. for (i = start / BITS_PER_LONG; which >= 2 && i <= lastr; ++i)
  6443. qib_write_kreg(dd, kr_sendcheckmask + i,
  6444. dd->cspec->sendchkenable[i]);
  6445. for (i = start / BITS_PER_LONG; which < 2 && i <= lastr; ++i) {
  6446. qib_write_kreg(dd, kr_sendgrhcheckmask + i,
  6447. dd->cspec->sendgrhchk[i]);
  6448. qib_write_kreg(dd, kr_sendibpktmask + i,
  6449. dd->cspec->sendibchk[i]);
  6450. }
  6451. /*
  6452. * Be sure whatever we did was seen by the chip and acted upon,
  6453. * before we return. Mostly important for which >= 2.
  6454. */
  6455. qib_read_kreg32(dd, kr_scratch);
  6456. }
  6457. /* useful for trigger analyzers, etc. */
  6458. static void writescratch(struct qib_devdata *dd, u32 val)
  6459. {
  6460. qib_write_kreg(dd, kr_scratch, val);
  6461. }
  6462. /* Dummy for now, use chip regs soon */
  6463. static int qib_7322_tempsense_rd(struct qib_devdata *dd, int regnum)
  6464. {
  6465. return -ENXIO;
  6466. }
  6467. /**
  6468. * qib_init_iba7322_funcs - set up the chip-specific function pointers
  6469. * @dev: the pci_dev for qlogic_ib device
  6470. * @ent: pci_device_id struct for this dev
  6471. *
  6472. * Also allocates, inits, and returns the devdata struct for this
  6473. * device instance
  6474. *
  6475. * This is global, and is called directly at init to set up the
  6476. * chip-specific function pointers for later use.
  6477. */
  6478. struct qib_devdata *qib_init_iba7322_funcs(struct pci_dev *pdev,
  6479. const struct pci_device_id *ent)
  6480. {
  6481. struct qib_devdata *dd;
  6482. int ret, i;
  6483. u32 tabsize, actual_cnt = 0;
  6484. dd = qib_alloc_devdata(pdev,
  6485. NUM_IB_PORTS * sizeof(struct qib_pportdata) +
  6486. sizeof(struct qib_chip_specific) +
  6487. NUM_IB_PORTS * sizeof(struct qib_chippport_specific));
  6488. if (IS_ERR(dd))
  6489. goto bail;
  6490. dd->f_bringup_serdes = qib_7322_bringup_serdes;
  6491. dd->f_cleanup = qib_setup_7322_cleanup;
  6492. dd->f_clear_tids = qib_7322_clear_tids;
  6493. dd->f_free_irq = qib_7322_free_irq;
  6494. dd->f_get_base_info = qib_7322_get_base_info;
  6495. dd->f_get_msgheader = qib_7322_get_msgheader;
  6496. dd->f_getsendbuf = qib_7322_getsendbuf;
  6497. dd->f_gpio_mod = gpio_7322_mod;
  6498. dd->f_eeprom_wen = qib_7322_eeprom_wen;
  6499. dd->f_hdrqempty = qib_7322_hdrqempty;
  6500. dd->f_ib_updown = qib_7322_ib_updown;
  6501. dd->f_init_ctxt = qib_7322_init_ctxt;
  6502. dd->f_initvl15_bufs = qib_7322_initvl15_bufs;
  6503. dd->f_intr_fallback = qib_7322_intr_fallback;
  6504. dd->f_late_initreg = qib_late_7322_initreg;
  6505. dd->f_setpbc_control = qib_7322_setpbc_control;
  6506. dd->f_portcntr = qib_portcntr_7322;
  6507. dd->f_put_tid = qib_7322_put_tid;
  6508. dd->f_quiet_serdes = qib_7322_mini_quiet_serdes;
  6509. dd->f_rcvctrl = rcvctrl_7322_mod;
  6510. dd->f_read_cntrs = qib_read_7322cntrs;
  6511. dd->f_read_portcntrs = qib_read_7322portcntrs;
  6512. dd->f_reset = qib_do_7322_reset;
  6513. dd->f_init_sdma_regs = init_sdma_7322_regs;
  6514. dd->f_sdma_busy = qib_sdma_7322_busy;
  6515. dd->f_sdma_gethead = qib_sdma_7322_gethead;
  6516. dd->f_sdma_sendctrl = qib_7322_sdma_sendctrl;
  6517. dd->f_sdma_set_desc_cnt = qib_sdma_set_7322_desc_cnt;
  6518. dd->f_sdma_update_tail = qib_sdma_update_7322_tail;
  6519. dd->f_sendctrl = sendctrl_7322_mod;
  6520. dd->f_set_armlaunch = qib_set_7322_armlaunch;
  6521. dd->f_set_cntr_sample = qib_set_cntr_7322_sample;
  6522. dd->f_iblink_state = qib_7322_iblink_state;
  6523. dd->f_ibphys_portstate = qib_7322_phys_portstate;
  6524. dd->f_get_ib_cfg = qib_7322_get_ib_cfg;
  6525. dd->f_set_ib_cfg = qib_7322_set_ib_cfg;
  6526. dd->f_set_ib_loopback = qib_7322_set_loopback;
  6527. dd->f_get_ib_table = qib_7322_get_ib_table;
  6528. dd->f_set_ib_table = qib_7322_set_ib_table;
  6529. dd->f_set_intr_state = qib_7322_set_intr_state;
  6530. dd->f_setextled = qib_setup_7322_setextled;
  6531. dd->f_txchk_change = qib_7322_txchk_change;
  6532. dd->f_update_usrhead = qib_update_7322_usrhead;
  6533. dd->f_wantpiobuf_intr = qib_wantpiobuf_7322_intr;
  6534. dd->f_xgxs_reset = qib_7322_mini_pcs_reset;
  6535. dd->f_sdma_hw_clean_up = qib_7322_sdma_hw_clean_up;
  6536. dd->f_sdma_hw_start_up = qib_7322_sdma_hw_start_up;
  6537. dd->f_sdma_init_early = qib_7322_sdma_init_early;
  6538. dd->f_writescratch = writescratch;
  6539. dd->f_tempsense_rd = qib_7322_tempsense_rd;
  6540. #ifdef CONFIG_INFINIBAND_QIB_DCA
  6541. dd->f_notify_dca = qib_7322_notify_dca;
  6542. #endif
  6543. /*
  6544. * Do remaining PCIe setup and save PCIe values in dd.
  6545. * Any error printing is already done by the init code.
  6546. * On return, we have the chip mapped, but chip registers
  6547. * are not set up until start of qib_init_7322_variables.
  6548. */
  6549. ret = qib_pcie_ddinit(dd, pdev, ent);
  6550. if (ret < 0)
  6551. goto bail_free;
  6552. /* initialize chip-specific variables */
  6553. ret = qib_init_7322_variables(dd);
  6554. if (ret)
  6555. goto bail_cleanup;
  6556. if (qib_mini_init || !dd->num_pports)
  6557. goto bail;
  6558. /*
  6559. * Determine number of vectors we want; depends on port count
  6560. * and number of configured kernel receive queues actually used.
  6561. * Should also depend on whether sdma is enabled or not, but
  6562. * that's such a rare testing case it's not worth worrying about.
  6563. */
  6564. tabsize = dd->first_user_ctxt + ARRAY_SIZE(irq_table);
  6565. for (i = 0; i < tabsize; i++)
  6566. if ((i < ARRAY_SIZE(irq_table) &&
  6567. irq_table[i].port <= dd->num_pports) ||
  6568. (i >= ARRAY_SIZE(irq_table) &&
  6569. dd->rcd[i - ARRAY_SIZE(irq_table)]))
  6570. actual_cnt++;
  6571. /* reduce by ctxt's < 2 */
  6572. if (qib_krcvq01_no_msi)
  6573. actual_cnt -= dd->num_pports;
  6574. tabsize = actual_cnt;
  6575. dd->cspec->msix_entries = kzalloc(tabsize *
  6576. sizeof(struct qib_msix_entry), GFP_KERNEL);
  6577. if (!dd->cspec->msix_entries) {
  6578. qib_dev_err(dd, "No memory for MSIx table\n");
  6579. tabsize = 0;
  6580. }
  6581. for (i = 0; i < tabsize; i++)
  6582. dd->cspec->msix_entries[i].msix.entry = i;
  6583. if (qib_pcie_params(dd, 8, &tabsize, dd->cspec->msix_entries))
  6584. qib_dev_err(dd,
  6585. "Failed to setup PCIe or interrupts; continuing anyway\n");
  6586. /* may be less than we wanted, if not enough available */
  6587. dd->cspec->num_msix_entries = tabsize;
  6588. /* setup interrupt handler */
  6589. qib_setup_7322_interrupt(dd, 1);
  6590. /* clear diagctrl register, in case diags were running and crashed */
  6591. qib_write_kreg(dd, kr_hwdiagctrl, 0);
  6592. #ifdef CONFIG_INFINIBAND_QIB_DCA
  6593. if (!dca_add_requester(&pdev->dev)) {
  6594. qib_devinfo(dd->pcidev, "DCA enabled\n");
  6595. dd->flags |= QIB_DCA_ENABLED;
  6596. qib_setup_dca(dd);
  6597. }
  6598. #endif
  6599. goto bail;
  6600. bail_cleanup:
  6601. qib_pcie_ddcleanup(dd);
  6602. bail_free:
  6603. qib_free_devdata(dd);
  6604. dd = ERR_PTR(ret);
  6605. bail:
  6606. return dd;
  6607. }
  6608. /*
  6609. * Set the table entry at the specified index from the table specifed.
  6610. * There are 3 * TXDDS_TABLE_SZ entries in all per port, with the first
  6611. * TXDDS_TABLE_SZ for SDR, the next for DDR, and the last for QDR.
  6612. * 'idx' below addresses the correct entry, while its 4 LSBs select the
  6613. * corresponding entry (one of TXDDS_TABLE_SZ) from the selected table.
  6614. */
  6615. #define DDS_ENT_AMP_LSB 14
  6616. #define DDS_ENT_MAIN_LSB 9
  6617. #define DDS_ENT_POST_LSB 5
  6618. #define DDS_ENT_PRE_XTRA_LSB 3
  6619. #define DDS_ENT_PRE_LSB 0
  6620. /*
  6621. * Set one entry in the TxDDS table for spec'd port
  6622. * ridx picks one of the entries, while tp points
  6623. * to the appropriate table entry.
  6624. */
  6625. static void set_txdds(struct qib_pportdata *ppd, int ridx,
  6626. const struct txdds_ent *tp)
  6627. {
  6628. struct qib_devdata *dd = ppd->dd;
  6629. u32 pack_ent;
  6630. int regidx;
  6631. /* Get correct offset in chip-space, and in source table */
  6632. regidx = KREG_IBPORT_IDX(IBSD_DDS_MAP_TABLE) + ridx;
  6633. /*
  6634. * We do not use qib_write_kreg_port() because it was intended
  6635. * only for registers in the lower "port specific" pages.
  6636. * So do index calculation by hand.
  6637. */
  6638. if (ppd->hw_pidx)
  6639. regidx += (dd->palign / sizeof(u64));
  6640. pack_ent = tp->amp << DDS_ENT_AMP_LSB;
  6641. pack_ent |= tp->main << DDS_ENT_MAIN_LSB;
  6642. pack_ent |= tp->pre << DDS_ENT_PRE_LSB;
  6643. pack_ent |= tp->post << DDS_ENT_POST_LSB;
  6644. qib_write_kreg(dd, regidx, pack_ent);
  6645. /* Prevent back-to-back writes by hitting scratch */
  6646. qib_write_kreg(ppd->dd, kr_scratch, 0);
  6647. }
  6648. static const struct vendor_txdds_ent vendor_txdds[] = {
  6649. { /* Amphenol 1m 30awg NoEq */
  6650. { 0x41, 0x50, 0x48 }, "584470002 ",
  6651. { 10, 0, 0, 5 }, { 10, 0, 0, 9 }, { 7, 1, 0, 13 },
  6652. },
  6653. { /* Amphenol 3m 28awg NoEq */
  6654. { 0x41, 0x50, 0x48 }, "584470004 ",
  6655. { 0, 0, 0, 8 }, { 0, 0, 0, 11 }, { 0, 1, 7, 15 },
  6656. },
  6657. { /* Finisar 3m OM2 Optical */
  6658. { 0x00, 0x90, 0x65 }, "FCBG410QB1C03-QL",
  6659. { 0, 0, 0, 3 }, { 0, 0, 0, 4 }, { 0, 0, 0, 13 },
  6660. },
  6661. { /* Finisar 30m OM2 Optical */
  6662. { 0x00, 0x90, 0x65 }, "FCBG410QB1C30-QL",
  6663. { 0, 0, 0, 1 }, { 0, 0, 0, 5 }, { 0, 0, 0, 11 },
  6664. },
  6665. { /* Finisar Default OM2 Optical */
  6666. { 0x00, 0x90, 0x65 }, NULL,
  6667. { 0, 0, 0, 2 }, { 0, 0, 0, 5 }, { 0, 0, 0, 12 },
  6668. },
  6669. { /* Gore 1m 30awg NoEq */
  6670. { 0x00, 0x21, 0x77 }, "QSN3300-1 ",
  6671. { 0, 0, 0, 6 }, { 0, 0, 0, 9 }, { 0, 1, 0, 15 },
  6672. },
  6673. { /* Gore 2m 30awg NoEq */
  6674. { 0x00, 0x21, 0x77 }, "QSN3300-2 ",
  6675. { 0, 0, 0, 8 }, { 0, 0, 0, 10 }, { 0, 1, 7, 15 },
  6676. },
  6677. { /* Gore 1m 28awg NoEq */
  6678. { 0x00, 0x21, 0x77 }, "QSN3800-1 ",
  6679. { 0, 0, 0, 6 }, { 0, 0, 0, 8 }, { 0, 1, 0, 15 },
  6680. },
  6681. { /* Gore 3m 28awg NoEq */
  6682. { 0x00, 0x21, 0x77 }, "QSN3800-3 ",
  6683. { 0, 0, 0, 9 }, { 0, 0, 0, 13 }, { 0, 1, 7, 15 },
  6684. },
  6685. { /* Gore 5m 24awg Eq */
  6686. { 0x00, 0x21, 0x77 }, "QSN7000-5 ",
  6687. { 0, 0, 0, 7 }, { 0, 0, 0, 9 }, { 0, 1, 3, 15 },
  6688. },
  6689. { /* Gore 7m 24awg Eq */
  6690. { 0x00, 0x21, 0x77 }, "QSN7000-7 ",
  6691. { 0, 0, 0, 9 }, { 0, 0, 0, 11 }, { 0, 2, 6, 15 },
  6692. },
  6693. { /* Gore 5m 26awg Eq */
  6694. { 0x00, 0x21, 0x77 }, "QSN7600-5 ",
  6695. { 0, 0, 0, 8 }, { 0, 0, 0, 11 }, { 0, 1, 9, 13 },
  6696. },
  6697. { /* Gore 7m 26awg Eq */
  6698. { 0x00, 0x21, 0x77 }, "QSN7600-7 ",
  6699. { 0, 0, 0, 8 }, { 0, 0, 0, 11 }, { 10, 1, 8, 15 },
  6700. },
  6701. { /* Intersil 12m 24awg Active */
  6702. { 0x00, 0x30, 0xB4 }, "QLX4000CQSFP1224",
  6703. { 0, 0, 0, 2 }, { 0, 0, 0, 5 }, { 0, 3, 0, 9 },
  6704. },
  6705. { /* Intersil 10m 28awg Active */
  6706. { 0x00, 0x30, 0xB4 }, "QLX4000CQSFP1028",
  6707. { 0, 0, 0, 6 }, { 0, 0, 0, 4 }, { 0, 2, 0, 2 },
  6708. },
  6709. { /* Intersil 7m 30awg Active */
  6710. { 0x00, 0x30, 0xB4 }, "QLX4000CQSFP0730",
  6711. { 0, 0, 0, 6 }, { 0, 0, 0, 4 }, { 0, 1, 0, 3 },
  6712. },
  6713. { /* Intersil 5m 32awg Active */
  6714. { 0x00, 0x30, 0xB4 }, "QLX4000CQSFP0532",
  6715. { 0, 0, 0, 6 }, { 0, 0, 0, 6 }, { 0, 2, 0, 8 },
  6716. },
  6717. { /* Intersil Default Active */
  6718. { 0x00, 0x30, 0xB4 }, NULL,
  6719. { 0, 0, 0, 6 }, { 0, 0, 0, 5 }, { 0, 2, 0, 5 },
  6720. },
  6721. { /* Luxtera 20m Active Optical */
  6722. { 0x00, 0x25, 0x63 }, NULL,
  6723. { 0, 0, 0, 5 }, { 0, 0, 0, 8 }, { 0, 2, 0, 12 },
  6724. },
  6725. { /* Molex 1M Cu loopback */
  6726. { 0x00, 0x09, 0x3A }, "74763-0025 ",
  6727. { 2, 2, 6, 15 }, { 2, 2, 6, 15 }, { 2, 2, 6, 15 },
  6728. },
  6729. { /* Molex 2m 28awg NoEq */
  6730. { 0x00, 0x09, 0x3A }, "74757-2201 ",
  6731. { 0, 0, 0, 6 }, { 0, 0, 0, 9 }, { 0, 1, 1, 15 },
  6732. },
  6733. };
  6734. static const struct txdds_ent txdds_sdr[TXDDS_TABLE_SZ] = {
  6735. /* amp, pre, main, post */
  6736. { 2, 2, 15, 6 }, /* Loopback */
  6737. { 0, 0, 0, 1 }, /* 2 dB */
  6738. { 0, 0, 0, 2 }, /* 3 dB */
  6739. { 0, 0, 0, 3 }, /* 4 dB */
  6740. { 0, 0, 0, 4 }, /* 5 dB */
  6741. { 0, 0, 0, 5 }, /* 6 dB */
  6742. { 0, 0, 0, 6 }, /* 7 dB */
  6743. { 0, 0, 0, 7 }, /* 8 dB */
  6744. { 0, 0, 0, 8 }, /* 9 dB */
  6745. { 0, 0, 0, 9 }, /* 10 dB */
  6746. { 0, 0, 0, 10 }, /* 11 dB */
  6747. { 0, 0, 0, 11 }, /* 12 dB */
  6748. { 0, 0, 0, 12 }, /* 13 dB */
  6749. { 0, 0, 0, 13 }, /* 14 dB */
  6750. { 0, 0, 0, 14 }, /* 15 dB */
  6751. { 0, 0, 0, 15 }, /* 16 dB */
  6752. };
  6753. static const struct txdds_ent txdds_ddr[TXDDS_TABLE_SZ] = {
  6754. /* amp, pre, main, post */
  6755. { 2, 2, 15, 6 }, /* Loopback */
  6756. { 0, 0, 0, 8 }, /* 2 dB */
  6757. { 0, 0, 0, 8 }, /* 3 dB */
  6758. { 0, 0, 0, 9 }, /* 4 dB */
  6759. { 0, 0, 0, 9 }, /* 5 dB */
  6760. { 0, 0, 0, 10 }, /* 6 dB */
  6761. { 0, 0, 0, 10 }, /* 7 dB */
  6762. { 0, 0, 0, 11 }, /* 8 dB */
  6763. { 0, 0, 0, 11 }, /* 9 dB */
  6764. { 0, 0, 0, 12 }, /* 10 dB */
  6765. { 0, 0, 0, 12 }, /* 11 dB */
  6766. { 0, 0, 0, 13 }, /* 12 dB */
  6767. { 0, 0, 0, 13 }, /* 13 dB */
  6768. { 0, 0, 0, 14 }, /* 14 dB */
  6769. { 0, 0, 0, 14 }, /* 15 dB */
  6770. { 0, 0, 0, 15 }, /* 16 dB */
  6771. };
  6772. static const struct txdds_ent txdds_qdr[TXDDS_TABLE_SZ] = {
  6773. /* amp, pre, main, post */
  6774. { 2, 2, 15, 6 }, /* Loopback */
  6775. { 0, 1, 0, 7 }, /* 2 dB (also QMH7342) */
  6776. { 0, 1, 0, 9 }, /* 3 dB (also QMH7342) */
  6777. { 0, 1, 0, 11 }, /* 4 dB */
  6778. { 0, 1, 0, 13 }, /* 5 dB */
  6779. { 0, 1, 0, 15 }, /* 6 dB */
  6780. { 0, 1, 3, 15 }, /* 7 dB */
  6781. { 0, 1, 7, 15 }, /* 8 dB */
  6782. { 0, 1, 7, 15 }, /* 9 dB */
  6783. { 0, 1, 8, 15 }, /* 10 dB */
  6784. { 0, 1, 9, 15 }, /* 11 dB */
  6785. { 0, 1, 10, 15 }, /* 12 dB */
  6786. { 0, 2, 6, 15 }, /* 13 dB */
  6787. { 0, 2, 7, 15 }, /* 14 dB */
  6788. { 0, 2, 8, 15 }, /* 15 dB */
  6789. { 0, 2, 9, 15 }, /* 16 dB */
  6790. };
  6791. /*
  6792. * extra entries for use with txselect, for indices >= TXDDS_TABLE_SZ.
  6793. * These are mostly used for mez cards going through connectors
  6794. * and backplane traces, but can be used to add other "unusual"
  6795. * table values as well.
  6796. */
  6797. static const struct txdds_ent txdds_extra_sdr[TXDDS_EXTRA_SZ] = {
  6798. /* amp, pre, main, post */
  6799. { 0, 0, 0, 1 }, /* QMH7342 backplane settings */
  6800. { 0, 0, 0, 1 }, /* QMH7342 backplane settings */
  6801. { 0, 0, 0, 2 }, /* QMH7342 backplane settings */
  6802. { 0, 0, 0, 2 }, /* QMH7342 backplane settings */
  6803. { 0, 0, 0, 3 }, /* QMH7342 backplane settings */
  6804. { 0, 0, 0, 4 }, /* QMH7342 backplane settings */
  6805. { 0, 1, 4, 15 }, /* QME7342 backplane settings 1.0 */
  6806. { 0, 1, 3, 15 }, /* QME7342 backplane settings 1.0 */
  6807. { 0, 1, 0, 12 }, /* QME7342 backplane settings 1.0 */
  6808. { 0, 1, 0, 11 }, /* QME7342 backplane settings 1.0 */
  6809. { 0, 1, 0, 9 }, /* QME7342 backplane settings 1.0 */
  6810. { 0, 1, 0, 14 }, /* QME7342 backplane settings 1.0 */
  6811. { 0, 1, 2, 15 }, /* QME7342 backplane settings 1.0 */
  6812. { 0, 1, 0, 11 }, /* QME7342 backplane settings 1.1 */
  6813. { 0, 1, 0, 7 }, /* QME7342 backplane settings 1.1 */
  6814. { 0, 1, 0, 9 }, /* QME7342 backplane settings 1.1 */
  6815. { 0, 1, 0, 6 }, /* QME7342 backplane settings 1.1 */
  6816. { 0, 1, 0, 8 }, /* QME7342 backplane settings 1.1 */
  6817. };
  6818. static const struct txdds_ent txdds_extra_ddr[TXDDS_EXTRA_SZ] = {
  6819. /* amp, pre, main, post */
  6820. { 0, 0, 0, 7 }, /* QMH7342 backplane settings */
  6821. { 0, 0, 0, 7 }, /* QMH7342 backplane settings */
  6822. { 0, 0, 0, 8 }, /* QMH7342 backplane settings */
  6823. { 0, 0, 0, 8 }, /* QMH7342 backplane settings */
  6824. { 0, 0, 0, 9 }, /* QMH7342 backplane settings */
  6825. { 0, 0, 0, 10 }, /* QMH7342 backplane settings */
  6826. { 0, 1, 4, 15 }, /* QME7342 backplane settings 1.0 */
  6827. { 0, 1, 3, 15 }, /* QME7342 backplane settings 1.0 */
  6828. { 0, 1, 0, 12 }, /* QME7342 backplane settings 1.0 */
  6829. { 0, 1, 0, 11 }, /* QME7342 backplane settings 1.0 */
  6830. { 0, 1, 0, 9 }, /* QME7342 backplane settings 1.0 */
  6831. { 0, 1, 0, 14 }, /* QME7342 backplane settings 1.0 */
  6832. { 0, 1, 2, 15 }, /* QME7342 backplane settings 1.0 */
  6833. { 0, 1, 0, 11 }, /* QME7342 backplane settings 1.1 */
  6834. { 0, 1, 0, 7 }, /* QME7342 backplane settings 1.1 */
  6835. { 0, 1, 0, 9 }, /* QME7342 backplane settings 1.1 */
  6836. { 0, 1, 0, 6 }, /* QME7342 backplane settings 1.1 */
  6837. { 0, 1, 0, 8 }, /* QME7342 backplane settings 1.1 */
  6838. };
  6839. static const struct txdds_ent txdds_extra_qdr[TXDDS_EXTRA_SZ] = {
  6840. /* amp, pre, main, post */
  6841. { 0, 1, 0, 4 }, /* QMH7342 backplane settings */
  6842. { 0, 1, 0, 5 }, /* QMH7342 backplane settings */
  6843. { 0, 1, 0, 6 }, /* QMH7342 backplane settings */
  6844. { 0, 1, 0, 8 }, /* QMH7342 backplane settings */
  6845. { 0, 1, 0, 10 }, /* QMH7342 backplane settings */
  6846. { 0, 1, 0, 12 }, /* QMH7342 backplane settings */
  6847. { 0, 1, 4, 15 }, /* QME7342 backplane settings 1.0 */
  6848. { 0, 1, 3, 15 }, /* QME7342 backplane settings 1.0 */
  6849. { 0, 1, 0, 12 }, /* QME7342 backplane settings 1.0 */
  6850. { 0, 1, 0, 11 }, /* QME7342 backplane settings 1.0 */
  6851. { 0, 1, 0, 9 }, /* QME7342 backplane settings 1.0 */
  6852. { 0, 1, 0, 14 }, /* QME7342 backplane settings 1.0 */
  6853. { 0, 1, 2, 15 }, /* QME7342 backplane settings 1.0 */
  6854. { 0, 1, 0, 11 }, /* QME7342 backplane settings 1.1 */
  6855. { 0, 1, 0, 7 }, /* QME7342 backplane settings 1.1 */
  6856. { 0, 1, 0, 9 }, /* QME7342 backplane settings 1.1 */
  6857. { 0, 1, 0, 6 }, /* QME7342 backplane settings 1.1 */
  6858. { 0, 1, 0, 8 }, /* QME7342 backplane settings 1.1 */
  6859. };
  6860. static const struct txdds_ent txdds_extra_mfg[TXDDS_MFG_SZ] = {
  6861. /* amp, pre, main, post */
  6862. { 0, 0, 0, 0 }, /* QME7342 mfg settings */
  6863. { 0, 0, 0, 6 }, /* QME7342 P2 mfg settings */
  6864. };
  6865. static const struct txdds_ent *get_atten_table(const struct txdds_ent *txdds,
  6866. unsigned atten)
  6867. {
  6868. /*
  6869. * The attenuation table starts at 2dB for entry 1,
  6870. * with entry 0 being the loopback entry.
  6871. */
  6872. if (atten <= 2)
  6873. atten = 1;
  6874. else if (atten > TXDDS_TABLE_SZ)
  6875. atten = TXDDS_TABLE_SZ - 1;
  6876. else
  6877. atten--;
  6878. return txdds + atten;
  6879. }
  6880. /*
  6881. * if override is set, the module parameter txselect has a value
  6882. * for this specific port, so use it, rather than our normal mechanism.
  6883. */
  6884. static void find_best_ent(struct qib_pportdata *ppd,
  6885. const struct txdds_ent **sdr_dds,
  6886. const struct txdds_ent **ddr_dds,
  6887. const struct txdds_ent **qdr_dds, int override)
  6888. {
  6889. struct qib_qsfp_cache *qd = &ppd->cpspec->qsfp_data.cache;
  6890. int idx;
  6891. /* Search table of known cables */
  6892. for (idx = 0; !override && idx < ARRAY_SIZE(vendor_txdds); ++idx) {
  6893. const struct vendor_txdds_ent *v = vendor_txdds + idx;
  6894. if (!memcmp(v->oui, qd->oui, QSFP_VOUI_LEN) &&
  6895. (!v->partnum ||
  6896. !memcmp(v->partnum, qd->partnum, QSFP_PN_LEN))) {
  6897. *sdr_dds = &v->sdr;
  6898. *ddr_dds = &v->ddr;
  6899. *qdr_dds = &v->qdr;
  6900. return;
  6901. }
  6902. }
  6903. /* Active cables don't have attenuation so we only set SERDES
  6904. * settings to account for the attenuation of the board traces. */
  6905. if (!override && QSFP_IS_ACTIVE(qd->tech)) {
  6906. *sdr_dds = txdds_sdr + ppd->dd->board_atten;
  6907. *ddr_dds = txdds_ddr + ppd->dd->board_atten;
  6908. *qdr_dds = txdds_qdr + ppd->dd->board_atten;
  6909. return;
  6910. }
  6911. if (!override && QSFP_HAS_ATTEN(qd->tech) && (qd->atten[0] ||
  6912. qd->atten[1])) {
  6913. *sdr_dds = get_atten_table(txdds_sdr, qd->atten[0]);
  6914. *ddr_dds = get_atten_table(txdds_ddr, qd->atten[0]);
  6915. *qdr_dds = get_atten_table(txdds_qdr, qd->atten[1]);
  6916. return;
  6917. } else if (ppd->cpspec->no_eep < TXDDS_TABLE_SZ) {
  6918. /*
  6919. * If we have no (or incomplete) data from the cable
  6920. * EEPROM, or no QSFP, or override is set, use the
  6921. * module parameter value to index into the attentuation
  6922. * table.
  6923. */
  6924. idx = ppd->cpspec->no_eep;
  6925. *sdr_dds = &txdds_sdr[idx];
  6926. *ddr_dds = &txdds_ddr[idx];
  6927. *qdr_dds = &txdds_qdr[idx];
  6928. } else if (ppd->cpspec->no_eep < (TXDDS_TABLE_SZ + TXDDS_EXTRA_SZ)) {
  6929. /* similar to above, but index into the "extra" table. */
  6930. idx = ppd->cpspec->no_eep - TXDDS_TABLE_SZ;
  6931. *sdr_dds = &txdds_extra_sdr[idx];
  6932. *ddr_dds = &txdds_extra_ddr[idx];
  6933. *qdr_dds = &txdds_extra_qdr[idx];
  6934. } else if ((IS_QME(ppd->dd) || IS_QMH(ppd->dd)) &&
  6935. ppd->cpspec->no_eep < (TXDDS_TABLE_SZ + TXDDS_EXTRA_SZ +
  6936. TXDDS_MFG_SZ)) {
  6937. idx = ppd->cpspec->no_eep - (TXDDS_TABLE_SZ + TXDDS_EXTRA_SZ);
  6938. pr_info("IB%u:%u use idx %u into txdds_mfg\n",
  6939. ppd->dd->unit, ppd->port, idx);
  6940. *sdr_dds = &txdds_extra_mfg[idx];
  6941. *ddr_dds = &txdds_extra_mfg[idx];
  6942. *qdr_dds = &txdds_extra_mfg[idx];
  6943. } else {
  6944. /* this shouldn't happen, it's range checked */
  6945. *sdr_dds = txdds_sdr + qib_long_atten;
  6946. *ddr_dds = txdds_ddr + qib_long_atten;
  6947. *qdr_dds = txdds_qdr + qib_long_atten;
  6948. }
  6949. }
  6950. static void init_txdds_table(struct qib_pportdata *ppd, int override)
  6951. {
  6952. const struct txdds_ent *sdr_dds, *ddr_dds, *qdr_dds;
  6953. struct txdds_ent *dds;
  6954. int idx;
  6955. int single_ent = 0;
  6956. find_best_ent(ppd, &sdr_dds, &ddr_dds, &qdr_dds, override);
  6957. /* for mez cards or override, use the selected value for all entries */
  6958. if (!(ppd->dd->flags & QIB_HAS_QSFP) || override)
  6959. single_ent = 1;
  6960. /* Fill in the first entry with the best entry found. */
  6961. set_txdds(ppd, 0, sdr_dds);
  6962. set_txdds(ppd, TXDDS_TABLE_SZ, ddr_dds);
  6963. set_txdds(ppd, 2 * TXDDS_TABLE_SZ, qdr_dds);
  6964. if (ppd->lflags & (QIBL_LINKINIT | QIBL_LINKARMED |
  6965. QIBL_LINKACTIVE)) {
  6966. dds = (struct txdds_ent *)(ppd->link_speed_active ==
  6967. QIB_IB_QDR ? qdr_dds :
  6968. (ppd->link_speed_active ==
  6969. QIB_IB_DDR ? ddr_dds : sdr_dds));
  6970. write_tx_serdes_param(ppd, dds);
  6971. }
  6972. /* Fill in the remaining entries with the default table values. */
  6973. for (idx = 1; idx < ARRAY_SIZE(txdds_sdr); ++idx) {
  6974. set_txdds(ppd, idx, single_ent ? sdr_dds : txdds_sdr + idx);
  6975. set_txdds(ppd, idx + TXDDS_TABLE_SZ,
  6976. single_ent ? ddr_dds : txdds_ddr + idx);
  6977. set_txdds(ppd, idx + 2 * TXDDS_TABLE_SZ,
  6978. single_ent ? qdr_dds : txdds_qdr + idx);
  6979. }
  6980. }
  6981. #define KR_AHB_ACC KREG_IDX(ahb_access_ctrl)
  6982. #define KR_AHB_TRANS KREG_IDX(ahb_transaction_reg)
  6983. #define AHB_TRANS_RDY SYM_MASK(ahb_transaction_reg, ahb_rdy)
  6984. #define AHB_ADDR_LSB SYM_LSB(ahb_transaction_reg, ahb_address)
  6985. #define AHB_DATA_LSB SYM_LSB(ahb_transaction_reg, ahb_data)
  6986. #define AHB_WR SYM_MASK(ahb_transaction_reg, write_not_read)
  6987. #define AHB_TRANS_TRIES 10
  6988. /*
  6989. * The chan argument is 0=chan0, 1=chan1, 2=pll, 3=chan2, 4=chan4,
  6990. * 5=subsystem which is why most calls have "chan + chan >> 1"
  6991. * for the channel argument.
  6992. */
  6993. static u32 ahb_mod(struct qib_devdata *dd, int quad, int chan, int addr,
  6994. u32 data, u32 mask)
  6995. {
  6996. u32 rd_data, wr_data, sz_mask;
  6997. u64 trans, acc, prev_acc;
  6998. u32 ret = 0xBAD0BAD;
  6999. int tries;
  7000. prev_acc = qib_read_kreg64(dd, KR_AHB_ACC);
  7001. /* From this point on, make sure we return access */
  7002. acc = (quad << 1) | 1;
  7003. qib_write_kreg(dd, KR_AHB_ACC, acc);
  7004. for (tries = 1; tries < AHB_TRANS_TRIES; ++tries) {
  7005. trans = qib_read_kreg64(dd, KR_AHB_TRANS);
  7006. if (trans & AHB_TRANS_RDY)
  7007. break;
  7008. }
  7009. if (tries >= AHB_TRANS_TRIES) {
  7010. qib_dev_err(dd, "No ahb_rdy in %d tries\n", AHB_TRANS_TRIES);
  7011. goto bail;
  7012. }
  7013. /* If mask is not all 1s, we need to read, but different SerDes
  7014. * entities have different sizes
  7015. */
  7016. sz_mask = (1UL << ((quad == 1) ? 32 : 16)) - 1;
  7017. wr_data = data & mask & sz_mask;
  7018. if ((~mask & sz_mask) != 0) {
  7019. trans = ((chan << 6) | addr) << (AHB_ADDR_LSB + 1);
  7020. qib_write_kreg(dd, KR_AHB_TRANS, trans);
  7021. for (tries = 1; tries < AHB_TRANS_TRIES; ++tries) {
  7022. trans = qib_read_kreg64(dd, KR_AHB_TRANS);
  7023. if (trans & AHB_TRANS_RDY)
  7024. break;
  7025. }
  7026. if (tries >= AHB_TRANS_TRIES) {
  7027. qib_dev_err(dd, "No Rd ahb_rdy in %d tries\n",
  7028. AHB_TRANS_TRIES);
  7029. goto bail;
  7030. }
  7031. /* Re-read in case host split reads and read data first */
  7032. trans = qib_read_kreg64(dd, KR_AHB_TRANS);
  7033. rd_data = (uint32_t)(trans >> AHB_DATA_LSB);
  7034. wr_data |= (rd_data & ~mask & sz_mask);
  7035. }
  7036. /* If mask is not zero, we need to write. */
  7037. if (mask & sz_mask) {
  7038. trans = ((chan << 6) | addr) << (AHB_ADDR_LSB + 1);
  7039. trans |= ((uint64_t)wr_data << AHB_DATA_LSB);
  7040. trans |= AHB_WR;
  7041. qib_write_kreg(dd, KR_AHB_TRANS, trans);
  7042. for (tries = 1; tries < AHB_TRANS_TRIES; ++tries) {
  7043. trans = qib_read_kreg64(dd, KR_AHB_TRANS);
  7044. if (trans & AHB_TRANS_RDY)
  7045. break;
  7046. }
  7047. if (tries >= AHB_TRANS_TRIES) {
  7048. qib_dev_err(dd, "No Wr ahb_rdy in %d tries\n",
  7049. AHB_TRANS_TRIES);
  7050. goto bail;
  7051. }
  7052. }
  7053. ret = wr_data;
  7054. bail:
  7055. qib_write_kreg(dd, KR_AHB_ACC, prev_acc);
  7056. return ret;
  7057. }
  7058. static void ibsd_wr_allchans(struct qib_pportdata *ppd, int addr, unsigned data,
  7059. unsigned mask)
  7060. {
  7061. struct qib_devdata *dd = ppd->dd;
  7062. int chan;
  7063. u32 rbc;
  7064. for (chan = 0; chan < SERDES_CHANS; ++chan) {
  7065. ahb_mod(dd, IBSD(ppd->hw_pidx), (chan + (chan >> 1)), addr,
  7066. data, mask);
  7067. rbc = ahb_mod(dd, IBSD(ppd->hw_pidx), (chan + (chan >> 1)),
  7068. addr, 0, 0);
  7069. }
  7070. }
  7071. static void serdes_7322_los_enable(struct qib_pportdata *ppd, int enable)
  7072. {
  7073. u64 data = qib_read_kreg_port(ppd, krp_serdesctrl);
  7074. u8 state = SYM_FIELD(data, IBSerdesCtrl_0, RXLOSEN);
  7075. if (enable && !state) {
  7076. pr_info("IB%u:%u Turning LOS on\n",
  7077. ppd->dd->unit, ppd->port);
  7078. data |= SYM_MASK(IBSerdesCtrl_0, RXLOSEN);
  7079. } else if (!enable && state) {
  7080. pr_info("IB%u:%u Turning LOS off\n",
  7081. ppd->dd->unit, ppd->port);
  7082. data &= ~SYM_MASK(IBSerdesCtrl_0, RXLOSEN);
  7083. }
  7084. qib_write_kreg_port(ppd, krp_serdesctrl, data);
  7085. }
  7086. static int serdes_7322_init(struct qib_pportdata *ppd)
  7087. {
  7088. int ret = 0;
  7089. if (ppd->dd->cspec->r1)
  7090. ret = serdes_7322_init_old(ppd);
  7091. else
  7092. ret = serdes_7322_init_new(ppd);
  7093. return ret;
  7094. }
  7095. static int serdes_7322_init_old(struct qib_pportdata *ppd)
  7096. {
  7097. u32 le_val;
  7098. /*
  7099. * Initialize the Tx DDS tables. Also done every QSFP event,
  7100. * for adapters with QSFP
  7101. */
  7102. init_txdds_table(ppd, 0);
  7103. /* ensure no tx overrides from earlier driver loads */
  7104. qib_write_kreg_port(ppd, krp_tx_deemph_override,
  7105. SYM_MASK(IBSD_TX_DEEMPHASIS_OVERRIDE_0,
  7106. reset_tx_deemphasis_override));
  7107. /* Patch some SerDes defaults to "Better for IB" */
  7108. /* Timing Loop Bandwidth: cdr_timing[11:9] = 0 */
  7109. ibsd_wr_allchans(ppd, 2, 0, BMASK(11, 9));
  7110. /* Termination: rxtermctrl_r2d addr 11 bits [12:11] = 1 */
  7111. ibsd_wr_allchans(ppd, 11, (1 << 11), BMASK(12, 11));
  7112. /* Enable LE2: rxle2en_r2a addr 13 bit [6] = 1 */
  7113. ibsd_wr_allchans(ppd, 13, (1 << 6), (1 << 6));
  7114. /* May be overridden in qsfp_7322_event */
  7115. le_val = IS_QME(ppd->dd) ? LE2_QME : LE2_DEFAULT;
  7116. ibsd_wr_allchans(ppd, 13, (le_val << 7), BMASK(9, 7));
  7117. /* enable LE1 adaptation for all but QME, which is disabled */
  7118. le_val = IS_QME(ppd->dd) ? 0 : 1;
  7119. ibsd_wr_allchans(ppd, 13, (le_val << 5), (1 << 5));
  7120. /* Clear cmode-override, may be set from older driver */
  7121. ahb_mod(ppd->dd, IBSD(ppd->hw_pidx), 5, 10, 0 << 14, 1 << 14);
  7122. /* Timing Recovery: rxtapsel addr 5 bits [9:8] = 0 */
  7123. ibsd_wr_allchans(ppd, 5, (0 << 8), BMASK(9, 8));
  7124. /* setup LoS params; these are subsystem, so chan == 5 */
  7125. /* LoS filter threshold_count on, ch 0-3, set to 8 */
  7126. ahb_mod(ppd->dd, IBSD(ppd->hw_pidx), 5, 5, 8 << 11, BMASK(14, 11));
  7127. ahb_mod(ppd->dd, IBSD(ppd->hw_pidx), 5, 7, 8 << 4, BMASK(7, 4));
  7128. ahb_mod(ppd->dd, IBSD(ppd->hw_pidx), 5, 8, 8 << 11, BMASK(14, 11));
  7129. ahb_mod(ppd->dd, IBSD(ppd->hw_pidx), 5, 10, 8 << 4, BMASK(7, 4));
  7130. /* LoS filter threshold_count off, ch 0-3, set to 4 */
  7131. ahb_mod(ppd->dd, IBSD(ppd->hw_pidx), 5, 6, 4 << 0, BMASK(3, 0));
  7132. ahb_mod(ppd->dd, IBSD(ppd->hw_pidx), 5, 7, 4 << 8, BMASK(11, 8));
  7133. ahb_mod(ppd->dd, IBSD(ppd->hw_pidx), 5, 9, 4 << 0, BMASK(3, 0));
  7134. ahb_mod(ppd->dd, IBSD(ppd->hw_pidx), 5, 10, 4 << 8, BMASK(11, 8));
  7135. /* LoS filter select enabled */
  7136. ahb_mod(ppd->dd, IBSD(ppd->hw_pidx), 5, 9, 1 << 15, 1 << 15);
  7137. /* LoS target data: SDR=4, DDR=2, QDR=1 */
  7138. ibsd_wr_allchans(ppd, 14, (1 << 3), BMASK(5, 3)); /* QDR */
  7139. ibsd_wr_allchans(ppd, 20, (2 << 10), BMASK(12, 10)); /* DDR */
  7140. ibsd_wr_allchans(ppd, 20, (4 << 13), BMASK(15, 13)); /* SDR */
  7141. serdes_7322_los_enable(ppd, 1);
  7142. /* rxbistena; set 0 to avoid effects of it switch later */
  7143. ibsd_wr_allchans(ppd, 9, 0 << 15, 1 << 15);
  7144. /* Configure 4 DFE taps, and only they adapt */
  7145. ibsd_wr_allchans(ppd, 16, 0 << 0, BMASK(1, 0));
  7146. /* gain hi stop 32 (22) (6:1) lo stop 7 (10:7) target 22 (13) (15:11) */
  7147. le_val = (ppd->dd->cspec->r1 || IS_QME(ppd->dd)) ? 0xb6c0 : 0x6bac;
  7148. ibsd_wr_allchans(ppd, 21, le_val, 0xfffe);
  7149. /*
  7150. * Set receive adaptation mode. SDR and DDR adaptation are
  7151. * always on, and QDR is initially enabled; later disabled.
  7152. */
  7153. qib_write_kreg_port(ppd, krp_static_adapt_dis(0), 0ULL);
  7154. qib_write_kreg_port(ppd, krp_static_adapt_dis(1), 0ULL);
  7155. qib_write_kreg_port(ppd, krp_static_adapt_dis(2),
  7156. ppd->dd->cspec->r1 ?
  7157. QDR_STATIC_ADAPT_DOWN_R1 : QDR_STATIC_ADAPT_DOWN);
  7158. ppd->cpspec->qdr_dfe_on = 1;
  7159. /* FLoop LOS gate: PPM filter enabled */
  7160. ibsd_wr_allchans(ppd, 38, 0 << 10, 1 << 10);
  7161. /* rx offset center enabled */
  7162. ibsd_wr_allchans(ppd, 12, 1 << 4, 1 << 4);
  7163. if (!ppd->dd->cspec->r1) {
  7164. ibsd_wr_allchans(ppd, 12, 1 << 12, 1 << 12);
  7165. ibsd_wr_allchans(ppd, 12, 2 << 8, 0x0f << 8);
  7166. }
  7167. /* Set the frequency loop bandwidth to 15 */
  7168. ibsd_wr_allchans(ppd, 2, 15 << 5, BMASK(8, 5));
  7169. return 0;
  7170. }
  7171. static int serdes_7322_init_new(struct qib_pportdata *ppd)
  7172. {
  7173. unsigned long tend;
  7174. u32 le_val, rxcaldone;
  7175. int chan, chan_done = (1 << SERDES_CHANS) - 1;
  7176. /* Clear cmode-override, may be set from older driver */
  7177. ahb_mod(ppd->dd, IBSD(ppd->hw_pidx), 5, 10, 0 << 14, 1 << 14);
  7178. /* ensure no tx overrides from earlier driver loads */
  7179. qib_write_kreg_port(ppd, krp_tx_deemph_override,
  7180. SYM_MASK(IBSD_TX_DEEMPHASIS_OVERRIDE_0,
  7181. reset_tx_deemphasis_override));
  7182. /* START OF LSI SUGGESTED SERDES BRINGUP */
  7183. /* Reset - Calibration Setup */
  7184. /* Stop DFE adaptaion */
  7185. ibsd_wr_allchans(ppd, 1, 0, BMASK(9, 1));
  7186. /* Disable LE1 */
  7187. ibsd_wr_allchans(ppd, 13, 0, BMASK(5, 5));
  7188. /* Disable autoadapt for LE1 */
  7189. ibsd_wr_allchans(ppd, 1, 0, BMASK(15, 15));
  7190. /* Disable LE2 */
  7191. ibsd_wr_allchans(ppd, 13, 0, BMASK(6, 6));
  7192. /* Disable VGA */
  7193. ibsd_wr_allchans(ppd, 5, 0, BMASK(0, 0));
  7194. /* Disable AFE Offset Cancel */
  7195. ibsd_wr_allchans(ppd, 12, 0, BMASK(12, 12));
  7196. /* Disable Timing Loop */
  7197. ibsd_wr_allchans(ppd, 2, 0, BMASK(3, 3));
  7198. /* Disable Frequency Loop */
  7199. ibsd_wr_allchans(ppd, 2, 0, BMASK(4, 4));
  7200. /* Disable Baseline Wander Correction */
  7201. ibsd_wr_allchans(ppd, 13, 0, BMASK(13, 13));
  7202. /* Disable RX Calibration */
  7203. ibsd_wr_allchans(ppd, 4, 0, BMASK(10, 10));
  7204. /* Disable RX Offset Calibration */
  7205. ibsd_wr_allchans(ppd, 12, 0, BMASK(4, 4));
  7206. /* Select BB CDR */
  7207. ibsd_wr_allchans(ppd, 2, (1 << 15), BMASK(15, 15));
  7208. /* CDR Step Size */
  7209. ibsd_wr_allchans(ppd, 5, 0, BMASK(9, 8));
  7210. /* Enable phase Calibration */
  7211. ibsd_wr_allchans(ppd, 12, (1 << 5), BMASK(5, 5));
  7212. /* DFE Bandwidth [2:14-12] */
  7213. ibsd_wr_allchans(ppd, 2, (4 << 12), BMASK(14, 12));
  7214. /* DFE Config (4 taps only) */
  7215. ibsd_wr_allchans(ppd, 16, 0, BMASK(1, 0));
  7216. /* Gain Loop Bandwidth */
  7217. if (!ppd->dd->cspec->r1) {
  7218. ibsd_wr_allchans(ppd, 12, 1 << 12, BMASK(12, 12));
  7219. ibsd_wr_allchans(ppd, 12, 2 << 8, BMASK(11, 8));
  7220. } else {
  7221. ibsd_wr_allchans(ppd, 19, (3 << 11), BMASK(13, 11));
  7222. }
  7223. /* Baseline Wander Correction Gain [13:4-0] (leave as default) */
  7224. /* Baseline Wander Correction Gain [3:7-5] (leave as default) */
  7225. /* Data Rate Select [5:7-6] (leave as default) */
  7226. /* RX Parallel Word Width [3:10-8] (leave as default) */
  7227. /* RX REST */
  7228. /* Single- or Multi-channel reset */
  7229. /* RX Analog reset */
  7230. /* RX Digital reset */
  7231. ibsd_wr_allchans(ppd, 0, 0, BMASK(15, 13));
  7232. msleep(20);
  7233. /* RX Analog reset */
  7234. ibsd_wr_allchans(ppd, 0, (1 << 14), BMASK(14, 14));
  7235. msleep(20);
  7236. /* RX Digital reset */
  7237. ibsd_wr_allchans(ppd, 0, (1 << 13), BMASK(13, 13));
  7238. msleep(20);
  7239. /* setup LoS params; these are subsystem, so chan == 5 */
  7240. /* LoS filter threshold_count on, ch 0-3, set to 8 */
  7241. ahb_mod(ppd->dd, IBSD(ppd->hw_pidx), 5, 5, 8 << 11, BMASK(14, 11));
  7242. ahb_mod(ppd->dd, IBSD(ppd->hw_pidx), 5, 7, 8 << 4, BMASK(7, 4));
  7243. ahb_mod(ppd->dd, IBSD(ppd->hw_pidx), 5, 8, 8 << 11, BMASK(14, 11));
  7244. ahb_mod(ppd->dd, IBSD(ppd->hw_pidx), 5, 10, 8 << 4, BMASK(7, 4));
  7245. /* LoS filter threshold_count off, ch 0-3, set to 4 */
  7246. ahb_mod(ppd->dd, IBSD(ppd->hw_pidx), 5, 6, 4 << 0, BMASK(3, 0));
  7247. ahb_mod(ppd->dd, IBSD(ppd->hw_pidx), 5, 7, 4 << 8, BMASK(11, 8));
  7248. ahb_mod(ppd->dd, IBSD(ppd->hw_pidx), 5, 9, 4 << 0, BMASK(3, 0));
  7249. ahb_mod(ppd->dd, IBSD(ppd->hw_pidx), 5, 10, 4 << 8, BMASK(11, 8));
  7250. /* LoS filter select enabled */
  7251. ahb_mod(ppd->dd, IBSD(ppd->hw_pidx), 5, 9, 1 << 15, 1 << 15);
  7252. /* LoS target data: SDR=4, DDR=2, QDR=1 */
  7253. ibsd_wr_allchans(ppd, 14, (1 << 3), BMASK(5, 3)); /* QDR */
  7254. ibsd_wr_allchans(ppd, 20, (2 << 10), BMASK(12, 10)); /* DDR */
  7255. ibsd_wr_allchans(ppd, 20, (4 << 13), BMASK(15, 13)); /* SDR */
  7256. /* Turn on LOS on initial SERDES init */
  7257. serdes_7322_los_enable(ppd, 1);
  7258. /* FLoop LOS gate: PPM filter enabled */
  7259. ibsd_wr_allchans(ppd, 38, 0 << 10, 1 << 10);
  7260. /* RX LATCH CALIBRATION */
  7261. /* Enable Eyefinder Phase Calibration latch */
  7262. ibsd_wr_allchans(ppd, 15, 1, BMASK(0, 0));
  7263. /* Enable RX Offset Calibration latch */
  7264. ibsd_wr_allchans(ppd, 12, (1 << 4), BMASK(4, 4));
  7265. msleep(20);
  7266. /* Start Calibration */
  7267. ibsd_wr_allchans(ppd, 4, (1 << 10), BMASK(10, 10));
  7268. tend = jiffies + msecs_to_jiffies(500);
  7269. while (chan_done && !time_is_before_jiffies(tend)) {
  7270. msleep(20);
  7271. for (chan = 0; chan < SERDES_CHANS; ++chan) {
  7272. rxcaldone = ahb_mod(ppd->dd, IBSD(ppd->hw_pidx),
  7273. (chan + (chan >> 1)),
  7274. 25, 0, 0);
  7275. if ((~rxcaldone & (u32)BMASK(9, 9)) == 0 &&
  7276. (~chan_done & (1 << chan)) == 0)
  7277. chan_done &= ~(1 << chan);
  7278. }
  7279. }
  7280. if (chan_done) {
  7281. pr_info("Serdes %d calibration not done after .5 sec: 0x%x\n",
  7282. IBSD(ppd->hw_pidx), chan_done);
  7283. } else {
  7284. for (chan = 0; chan < SERDES_CHANS; ++chan) {
  7285. rxcaldone = ahb_mod(ppd->dd, IBSD(ppd->hw_pidx),
  7286. (chan + (chan >> 1)),
  7287. 25, 0, 0);
  7288. if ((~rxcaldone & (u32)BMASK(10, 10)) == 0)
  7289. pr_info("Serdes %d chan %d calibration failed\n",
  7290. IBSD(ppd->hw_pidx), chan);
  7291. }
  7292. }
  7293. /* Turn off Calibration */
  7294. ibsd_wr_allchans(ppd, 4, 0, BMASK(10, 10));
  7295. msleep(20);
  7296. /* BRING RX UP */
  7297. /* Set LE2 value (May be overridden in qsfp_7322_event) */
  7298. le_val = IS_QME(ppd->dd) ? LE2_QME : LE2_DEFAULT;
  7299. ibsd_wr_allchans(ppd, 13, (le_val << 7), BMASK(9, 7));
  7300. /* Set LE2 Loop bandwidth */
  7301. ibsd_wr_allchans(ppd, 3, (7 << 5), BMASK(7, 5));
  7302. /* Enable LE2 */
  7303. ibsd_wr_allchans(ppd, 13, (1 << 6), BMASK(6, 6));
  7304. msleep(20);
  7305. /* Enable H0 only */
  7306. ibsd_wr_allchans(ppd, 1, 1, BMASK(9, 1));
  7307. /* gain hi stop 32 (22) (6:1) lo stop 7 (10:7) target 22 (13) (15:11) */
  7308. le_val = (ppd->dd->cspec->r1 || IS_QME(ppd->dd)) ? 0xb6c0 : 0x6bac;
  7309. ibsd_wr_allchans(ppd, 21, le_val, 0xfffe);
  7310. /* Enable VGA */
  7311. ibsd_wr_allchans(ppd, 5, 0, BMASK(0, 0));
  7312. msleep(20);
  7313. /* Set Frequency Loop Bandwidth */
  7314. ibsd_wr_allchans(ppd, 2, (15 << 5), BMASK(8, 5));
  7315. /* Enable Frequency Loop */
  7316. ibsd_wr_allchans(ppd, 2, (1 << 4), BMASK(4, 4));
  7317. /* Set Timing Loop Bandwidth */
  7318. ibsd_wr_allchans(ppd, 2, 0, BMASK(11, 9));
  7319. /* Enable Timing Loop */
  7320. ibsd_wr_allchans(ppd, 2, (1 << 3), BMASK(3, 3));
  7321. msleep(50);
  7322. /* Enable DFE
  7323. * Set receive adaptation mode. SDR and DDR adaptation are
  7324. * always on, and QDR is initially enabled; later disabled.
  7325. */
  7326. qib_write_kreg_port(ppd, krp_static_adapt_dis(0), 0ULL);
  7327. qib_write_kreg_port(ppd, krp_static_adapt_dis(1), 0ULL);
  7328. qib_write_kreg_port(ppd, krp_static_adapt_dis(2),
  7329. ppd->dd->cspec->r1 ?
  7330. QDR_STATIC_ADAPT_DOWN_R1 : QDR_STATIC_ADAPT_DOWN);
  7331. ppd->cpspec->qdr_dfe_on = 1;
  7332. /* Disable LE1 */
  7333. ibsd_wr_allchans(ppd, 13, (0 << 5), (1 << 5));
  7334. /* Disable auto adapt for LE1 */
  7335. ibsd_wr_allchans(ppd, 1, (0 << 15), BMASK(15, 15));
  7336. msleep(20);
  7337. /* Enable AFE Offset Cancel */
  7338. ibsd_wr_allchans(ppd, 12, (1 << 12), BMASK(12, 12));
  7339. /* Enable Baseline Wander Correction */
  7340. ibsd_wr_allchans(ppd, 12, (1 << 13), BMASK(13, 13));
  7341. /* Termination: rxtermctrl_r2d addr 11 bits [12:11] = 1 */
  7342. ibsd_wr_allchans(ppd, 11, (1 << 11), BMASK(12, 11));
  7343. /* VGA output common mode */
  7344. ibsd_wr_allchans(ppd, 12, (3 << 2), BMASK(3, 2));
  7345. /*
  7346. * Initialize the Tx DDS tables. Also done every QSFP event,
  7347. * for adapters with QSFP
  7348. */
  7349. init_txdds_table(ppd, 0);
  7350. return 0;
  7351. }
  7352. /* start adjust QMH serdes parameters */
  7353. static void set_man_code(struct qib_pportdata *ppd, int chan, int code)
  7354. {
  7355. ahb_mod(ppd->dd, IBSD(ppd->hw_pidx), (chan + (chan >> 1)),
  7356. 9, code << 9, 0x3f << 9);
  7357. }
  7358. static void set_man_mode_h1(struct qib_pportdata *ppd, int chan,
  7359. int enable, u32 tapenable)
  7360. {
  7361. if (enable)
  7362. ahb_mod(ppd->dd, IBSD(ppd->hw_pidx), (chan + (chan >> 1)),
  7363. 1, 3 << 10, 0x1f << 10);
  7364. else
  7365. ahb_mod(ppd->dd, IBSD(ppd->hw_pidx), (chan + (chan >> 1)),
  7366. 1, 0, 0x1f << 10);
  7367. }
  7368. /* Set clock to 1, 0, 1, 0 */
  7369. static void clock_man(struct qib_pportdata *ppd, int chan)
  7370. {
  7371. ahb_mod(ppd->dd, IBSD(ppd->hw_pidx), (chan + (chan >> 1)),
  7372. 4, 0x4000, 0x4000);
  7373. ahb_mod(ppd->dd, IBSD(ppd->hw_pidx), (chan + (chan >> 1)),
  7374. 4, 0, 0x4000);
  7375. ahb_mod(ppd->dd, IBSD(ppd->hw_pidx), (chan + (chan >> 1)),
  7376. 4, 0x4000, 0x4000);
  7377. ahb_mod(ppd->dd, IBSD(ppd->hw_pidx), (chan + (chan >> 1)),
  7378. 4, 0, 0x4000);
  7379. }
  7380. /*
  7381. * write the current Tx serdes pre,post,main,amp settings into the serdes.
  7382. * The caller must pass the settings appropriate for the current speed,
  7383. * or not care if they are correct for the current speed.
  7384. */
  7385. static void write_tx_serdes_param(struct qib_pportdata *ppd,
  7386. struct txdds_ent *txdds)
  7387. {
  7388. u64 deemph;
  7389. deemph = qib_read_kreg_port(ppd, krp_tx_deemph_override);
  7390. /* field names for amp, main, post, pre, respectively */
  7391. deemph &= ~(SYM_MASK(IBSD_TX_DEEMPHASIS_OVERRIDE_0, txampcntl_d2a) |
  7392. SYM_MASK(IBSD_TX_DEEMPHASIS_OVERRIDE_0, txc0_ena) |
  7393. SYM_MASK(IBSD_TX_DEEMPHASIS_OVERRIDE_0, txcp1_ena) |
  7394. SYM_MASK(IBSD_TX_DEEMPHASIS_OVERRIDE_0, txcn1_ena));
  7395. deemph |= SYM_MASK(IBSD_TX_DEEMPHASIS_OVERRIDE_0,
  7396. tx_override_deemphasis_select);
  7397. deemph |= (txdds->amp & SYM_RMASK(IBSD_TX_DEEMPHASIS_OVERRIDE_0,
  7398. txampcntl_d2a)) << SYM_LSB(IBSD_TX_DEEMPHASIS_OVERRIDE_0,
  7399. txampcntl_d2a);
  7400. deemph |= (txdds->main & SYM_RMASK(IBSD_TX_DEEMPHASIS_OVERRIDE_0,
  7401. txc0_ena)) << SYM_LSB(IBSD_TX_DEEMPHASIS_OVERRIDE_0,
  7402. txc0_ena);
  7403. deemph |= (txdds->post & SYM_RMASK(IBSD_TX_DEEMPHASIS_OVERRIDE_0,
  7404. txcp1_ena)) << SYM_LSB(IBSD_TX_DEEMPHASIS_OVERRIDE_0,
  7405. txcp1_ena);
  7406. deemph |= (txdds->pre & SYM_RMASK(IBSD_TX_DEEMPHASIS_OVERRIDE_0,
  7407. txcn1_ena)) << SYM_LSB(IBSD_TX_DEEMPHASIS_OVERRIDE_0,
  7408. txcn1_ena);
  7409. qib_write_kreg_port(ppd, krp_tx_deemph_override, deemph);
  7410. }
  7411. /*
  7412. * Set the parameters for mez cards on link bounce, so they are
  7413. * always exactly what was requested. Similar logic to init_txdds
  7414. * but does just the serdes.
  7415. */
  7416. static void adj_tx_serdes(struct qib_pportdata *ppd)
  7417. {
  7418. const struct txdds_ent *sdr_dds, *ddr_dds, *qdr_dds;
  7419. struct txdds_ent *dds;
  7420. find_best_ent(ppd, &sdr_dds, &ddr_dds, &qdr_dds, 1);
  7421. dds = (struct txdds_ent *)(ppd->link_speed_active == QIB_IB_QDR ?
  7422. qdr_dds : (ppd->link_speed_active == QIB_IB_DDR ?
  7423. ddr_dds : sdr_dds));
  7424. write_tx_serdes_param(ppd, dds);
  7425. }
  7426. /* set QDR forced value for H1, if needed */
  7427. static void force_h1(struct qib_pportdata *ppd)
  7428. {
  7429. int chan;
  7430. ppd->cpspec->qdr_reforce = 0;
  7431. if (!ppd->dd->cspec->r1)
  7432. return;
  7433. for (chan = 0; chan < SERDES_CHANS; chan++) {
  7434. set_man_mode_h1(ppd, chan, 1, 0);
  7435. set_man_code(ppd, chan, ppd->cpspec->h1_val);
  7436. clock_man(ppd, chan);
  7437. set_man_mode_h1(ppd, chan, 0, 0);
  7438. }
  7439. }
  7440. #define SJA_EN SYM_MASK(SPC_JTAG_ACCESS_REG, SPC_JTAG_ACCESS_EN)
  7441. #define BISTEN_LSB SYM_LSB(SPC_JTAG_ACCESS_REG, bist_en)
  7442. #define R_OPCODE_LSB 3
  7443. #define R_OP_NOP 0
  7444. #define R_OP_SHIFT 2
  7445. #define R_OP_UPDATE 3
  7446. #define R_TDI_LSB 2
  7447. #define R_TDO_LSB 1
  7448. #define R_RDY 1
  7449. static int qib_r_grab(struct qib_devdata *dd)
  7450. {
  7451. u64 val;
  7452. val = SJA_EN;
  7453. qib_write_kreg(dd, kr_r_access, val);
  7454. qib_read_kreg32(dd, kr_scratch);
  7455. return 0;
  7456. }
  7457. /* qib_r_wait_for_rdy() not only waits for the ready bit, it
  7458. * returns the current state of R_TDO
  7459. */
  7460. static int qib_r_wait_for_rdy(struct qib_devdata *dd)
  7461. {
  7462. u64 val;
  7463. int timeout;
  7464. for (timeout = 0; timeout < 100 ; ++timeout) {
  7465. val = qib_read_kreg32(dd, kr_r_access);
  7466. if (val & R_RDY)
  7467. return (val >> R_TDO_LSB) & 1;
  7468. }
  7469. return -1;
  7470. }
  7471. static int qib_r_shift(struct qib_devdata *dd, int bisten,
  7472. int len, u8 *inp, u8 *outp)
  7473. {
  7474. u64 valbase, val;
  7475. int ret, pos;
  7476. valbase = SJA_EN | (bisten << BISTEN_LSB) |
  7477. (R_OP_SHIFT << R_OPCODE_LSB);
  7478. ret = qib_r_wait_for_rdy(dd);
  7479. if (ret < 0)
  7480. goto bail;
  7481. for (pos = 0; pos < len; ++pos) {
  7482. val = valbase;
  7483. if (outp) {
  7484. outp[pos >> 3] &= ~(1 << (pos & 7));
  7485. outp[pos >> 3] |= (ret << (pos & 7));
  7486. }
  7487. if (inp) {
  7488. int tdi = inp[pos >> 3] >> (pos & 7);
  7489. val |= ((tdi & 1) << R_TDI_LSB);
  7490. }
  7491. qib_write_kreg(dd, kr_r_access, val);
  7492. qib_read_kreg32(dd, kr_scratch);
  7493. ret = qib_r_wait_for_rdy(dd);
  7494. if (ret < 0)
  7495. break;
  7496. }
  7497. /* Restore to NOP between operations. */
  7498. val = SJA_EN | (bisten << BISTEN_LSB);
  7499. qib_write_kreg(dd, kr_r_access, val);
  7500. qib_read_kreg32(dd, kr_scratch);
  7501. ret = qib_r_wait_for_rdy(dd);
  7502. if (ret >= 0)
  7503. ret = pos;
  7504. bail:
  7505. return ret;
  7506. }
  7507. static int qib_r_update(struct qib_devdata *dd, int bisten)
  7508. {
  7509. u64 val;
  7510. int ret;
  7511. val = SJA_EN | (bisten << BISTEN_LSB) | (R_OP_UPDATE << R_OPCODE_LSB);
  7512. ret = qib_r_wait_for_rdy(dd);
  7513. if (ret >= 0) {
  7514. qib_write_kreg(dd, kr_r_access, val);
  7515. qib_read_kreg32(dd, kr_scratch);
  7516. }
  7517. return ret;
  7518. }
  7519. #define BISTEN_PORT_SEL 15
  7520. #define LEN_PORT_SEL 625
  7521. #define BISTEN_AT 17
  7522. #define LEN_AT 156
  7523. #define BISTEN_ETM 16
  7524. #define LEN_ETM 632
  7525. #define BIT2BYTE(x) (((x) + BITS_PER_BYTE - 1) / BITS_PER_BYTE)
  7526. /* these are common for all IB port use cases. */
  7527. static u8 reset_at[BIT2BYTE(LEN_AT)] = {
  7528. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  7529. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00,
  7530. };
  7531. static u8 reset_atetm[BIT2BYTE(LEN_ETM)] = {
  7532. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  7533. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  7534. 0x00, 0x00, 0x00, 0x80, 0xe3, 0x81, 0x73, 0x3c, 0x70, 0x8e,
  7535. 0x07, 0xce, 0xf1, 0xc0, 0x39, 0x1e, 0x38, 0xc7, 0x03, 0xe7,
  7536. 0x78, 0xe0, 0x1c, 0x0f, 0x9c, 0x7f, 0x80, 0x73, 0x0f, 0x70,
  7537. 0xde, 0x01, 0xce, 0x39, 0xc0, 0xf9, 0x06, 0x38, 0xd7, 0x00,
  7538. 0xe7, 0x19, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  7539. 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
  7540. };
  7541. static u8 at[BIT2BYTE(LEN_AT)] = {
  7542. 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00,
  7543. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00,
  7544. };
  7545. /* used for IB1 or IB2, only one in use */
  7546. static u8 atetm_1port[BIT2BYTE(LEN_ETM)] = {
  7547. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  7548. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  7549. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  7550. 0x00, 0x10, 0xf2, 0x80, 0x83, 0x1e, 0x38, 0x00, 0x00, 0x00,
  7551. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  7552. 0x00, 0x00, 0x50, 0xf4, 0x41, 0x00, 0x18, 0x78, 0xc8, 0x03,
  7553. 0x07, 0x7b, 0xa0, 0x3e, 0x00, 0x02, 0x00, 0x00, 0x18, 0x00,
  7554. 0x18, 0x00, 0x00, 0x00, 0x00, 0x4b, 0x00, 0x00, 0x00,
  7555. };
  7556. /* used when both IB1 and IB2 are in use */
  7557. static u8 atetm_2port[BIT2BYTE(LEN_ETM)] = {
  7558. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  7559. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x79,
  7560. 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  7561. 0x00, 0x00, 0xf8, 0x80, 0x83, 0x1e, 0x38, 0xe0, 0x03, 0x05,
  7562. 0x7b, 0xa0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80,
  7563. 0xa2, 0x0f, 0x50, 0xf4, 0x41, 0x00, 0x18, 0x78, 0xd1, 0x07,
  7564. 0x02, 0x7c, 0x80, 0x3e, 0x00, 0x02, 0x00, 0x00, 0x3e, 0x00,
  7565. 0x02, 0x00, 0x00, 0x00, 0x00, 0x64, 0x00, 0x00, 0x00,
  7566. };
  7567. /* used when only IB1 is in use */
  7568. static u8 portsel_port1[BIT2BYTE(LEN_PORT_SEL)] = {
  7569. 0x32, 0x65, 0xa4, 0x7b, 0x10, 0x98, 0xdc, 0xfe, 0x13, 0x13,
  7570. 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x73, 0x0c, 0x0c, 0x0c,
  7571. 0x0c, 0x0c, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13,
  7572. 0x13, 0x78, 0x78, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13,
  7573. 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x74, 0x32,
  7574. 0x32, 0x32, 0x32, 0x32, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14,
  7575. 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14,
  7576. 0x14, 0x14, 0x9f, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
  7577. };
  7578. /* used when only IB2 is in use */
  7579. static u8 portsel_port2[BIT2BYTE(LEN_PORT_SEL)] = {
  7580. 0x32, 0x65, 0xa4, 0x7b, 0x10, 0x98, 0xdc, 0xfe, 0x39, 0x39,
  7581. 0x39, 0x39, 0x39, 0x39, 0x39, 0x39, 0x73, 0x32, 0x32, 0x32,
  7582. 0x32, 0x32, 0x39, 0x39, 0x39, 0x39, 0x39, 0x39, 0x39, 0x39,
  7583. 0x39, 0x78, 0x78, 0x39, 0x39, 0x39, 0x39, 0x39, 0x39, 0x39,
  7584. 0x3a, 0x3a, 0x3a, 0x3a, 0x3a, 0x3a, 0x3a, 0x3a, 0x74, 0x32,
  7585. 0x32, 0x32, 0x32, 0x32, 0x3a, 0x3a, 0x3a, 0x3a, 0x3a, 0x3a,
  7586. 0x3a, 0x3a, 0x3a, 0x3a, 0x3a, 0x3a, 0x3a, 0x3a, 0x3a, 0x3a,
  7587. 0x3a, 0x3a, 0x9f, 0x01, 0x00, 0x00, 0x00, 0x00, 0x01,
  7588. };
  7589. /* used when both IB1 and IB2 are in use */
  7590. static u8 portsel_2port[BIT2BYTE(LEN_PORT_SEL)] = {
  7591. 0x32, 0xba, 0x54, 0x76, 0x10, 0x98, 0xdc, 0xfe, 0x13, 0x13,
  7592. 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x73, 0x0c, 0x0c, 0x0c,
  7593. 0x0c, 0x0c, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13,
  7594. 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13,
  7595. 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x74, 0x32,
  7596. 0x32, 0x32, 0x32, 0x32, 0x14, 0x14, 0x14, 0x14, 0x14, 0x3a,
  7597. 0x3a, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14,
  7598. 0x14, 0x14, 0x9f, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
  7599. };
  7600. /*
  7601. * Do setup to properly handle IB link recovery; if port is zero, we
  7602. * are initializing to cover both ports; otherwise we are initializing
  7603. * to cover a single port card, or the port has reached INIT and we may
  7604. * need to switch coverage types.
  7605. */
  7606. static void setup_7322_link_recovery(struct qib_pportdata *ppd, u32 both)
  7607. {
  7608. u8 *portsel, *etm;
  7609. struct qib_devdata *dd = ppd->dd;
  7610. if (!ppd->dd->cspec->r1)
  7611. return;
  7612. if (!both) {
  7613. dd->cspec->recovery_ports_initted++;
  7614. ppd->cpspec->recovery_init = 1;
  7615. }
  7616. if (!both && dd->cspec->recovery_ports_initted == 1) {
  7617. portsel = ppd->port == 1 ? portsel_port1 : portsel_port2;
  7618. etm = atetm_1port;
  7619. } else {
  7620. portsel = portsel_2port;
  7621. etm = atetm_2port;
  7622. }
  7623. if (qib_r_grab(dd) < 0 ||
  7624. qib_r_shift(dd, BISTEN_ETM, LEN_ETM, reset_atetm, NULL) < 0 ||
  7625. qib_r_update(dd, BISTEN_ETM) < 0 ||
  7626. qib_r_shift(dd, BISTEN_AT, LEN_AT, reset_at, NULL) < 0 ||
  7627. qib_r_update(dd, BISTEN_AT) < 0 ||
  7628. qib_r_shift(dd, BISTEN_PORT_SEL, LEN_PORT_SEL,
  7629. portsel, NULL) < 0 ||
  7630. qib_r_update(dd, BISTEN_PORT_SEL) < 0 ||
  7631. qib_r_shift(dd, BISTEN_AT, LEN_AT, at, NULL) < 0 ||
  7632. qib_r_update(dd, BISTEN_AT) < 0 ||
  7633. qib_r_shift(dd, BISTEN_ETM, LEN_ETM, etm, NULL) < 0 ||
  7634. qib_r_update(dd, BISTEN_ETM) < 0)
  7635. qib_dev_err(dd, "Failed IB link recovery setup\n");
  7636. }
  7637. static void check_7322_rxe_status(struct qib_pportdata *ppd)
  7638. {
  7639. struct qib_devdata *dd = ppd->dd;
  7640. u64 fmask;
  7641. if (dd->cspec->recovery_ports_initted != 1)
  7642. return; /* rest doesn't apply to dualport */
  7643. qib_write_kreg(dd, kr_control, dd->control |
  7644. SYM_MASK(Control, FreezeMode));
  7645. (void)qib_read_kreg64(dd, kr_scratch);
  7646. udelay(3); /* ibcreset asserted 400ns, be sure that's over */
  7647. fmask = qib_read_kreg64(dd, kr_act_fmask);
  7648. if (!fmask) {
  7649. /*
  7650. * require a powercycle before we'll work again, and make
  7651. * sure we get no more interrupts, and don't turn off
  7652. * freeze.
  7653. */
  7654. ppd->dd->cspec->stay_in_freeze = 1;
  7655. qib_7322_set_intr_state(ppd->dd, 0);
  7656. qib_write_kreg(dd, kr_fmask, 0ULL);
  7657. qib_dev_err(dd, "HCA unusable until powercycled\n");
  7658. return; /* eventually reset */
  7659. }
  7660. qib_write_kreg(ppd->dd, kr_hwerrclear,
  7661. SYM_MASK(HwErrClear, IBSerdesPClkNotDetectClear_1));
  7662. /* don't do the full clear_freeze(), not needed for this */
  7663. qib_write_kreg(dd, kr_control, dd->control);
  7664. qib_read_kreg32(dd, kr_scratch);
  7665. /* take IBC out of reset */
  7666. if (ppd->link_speed_supported) {
  7667. ppd->cpspec->ibcctrl_a &=
  7668. ~SYM_MASK(IBCCtrlA_0, IBStatIntReductionEn);
  7669. qib_write_kreg_port(ppd, krp_ibcctrl_a,
  7670. ppd->cpspec->ibcctrl_a);
  7671. qib_read_kreg32(dd, kr_scratch);
  7672. if (ppd->lflags & QIBL_IB_LINK_DISABLED)
  7673. qib_set_ib_7322_lstate(ppd, 0,
  7674. QLOGIC_IB_IBCC_LINKINITCMD_DISABLE);
  7675. }
  7676. }