qib_iba7322.c 247 KB

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