qib_iba7322.c 264 KB

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