qib_iba7322.c 250 KB

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