qib_iba7322.c 262 KB

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