qib_iba7322.c 264 KB

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