ql4_os.c 234 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308
  1. /*
  2. * QLogic iSCSI HBA Driver
  3. * Copyright (c) 2003-2013 QLogic Corporation
  4. *
  5. * See LICENSE.qla4xxx for copyright and licensing details.
  6. */
  7. #include <linux/moduleparam.h>
  8. #include <linux/slab.h>
  9. #include <linux/blkdev.h>
  10. #include <linux/iscsi_boot_sysfs.h>
  11. #include <linux/inet.h>
  12. #include <scsi/scsi_tcq.h>
  13. #include <scsi/scsicam.h>
  14. #include "ql4_def.h"
  15. #include "ql4_version.h"
  16. #include "ql4_glbl.h"
  17. #include "ql4_dbg.h"
  18. #include "ql4_inline.h"
  19. #include "ql4_83xx.h"
  20. /*
  21. * Driver version
  22. */
  23. static char qla4xxx_version_str[40];
  24. /*
  25. * SRB allocation cache
  26. */
  27. static struct kmem_cache *srb_cachep;
  28. /*
  29. * Module parameter information and variables
  30. */
  31. static int ql4xdisablesysfsboot = 1;
  32. module_param(ql4xdisablesysfsboot, int, S_IRUGO | S_IWUSR);
  33. MODULE_PARM_DESC(ql4xdisablesysfsboot,
  34. " Set to disable exporting boot targets to sysfs.\n"
  35. "\t\t 0 - Export boot targets\n"
  36. "\t\t 1 - Do not export boot targets (Default)");
  37. int ql4xdontresethba;
  38. module_param(ql4xdontresethba, int, S_IRUGO | S_IWUSR);
  39. MODULE_PARM_DESC(ql4xdontresethba,
  40. " Don't reset the HBA for driver recovery.\n"
  41. "\t\t 0 - It will reset HBA (Default)\n"
  42. "\t\t 1 - It will NOT reset HBA");
  43. int ql4xextended_error_logging;
  44. module_param(ql4xextended_error_logging, int, S_IRUGO | S_IWUSR);
  45. MODULE_PARM_DESC(ql4xextended_error_logging,
  46. " Option to enable extended error logging.\n"
  47. "\t\t 0 - no logging (Default)\n"
  48. "\t\t 2 - debug logging");
  49. int ql4xenablemsix = 1;
  50. module_param(ql4xenablemsix, int, S_IRUGO|S_IWUSR);
  51. MODULE_PARM_DESC(ql4xenablemsix,
  52. " Set to enable MSI or MSI-X interrupt mechanism.\n"
  53. "\t\t 0 = enable INTx interrupt mechanism.\n"
  54. "\t\t 1 = enable MSI-X interrupt mechanism (Default).\n"
  55. "\t\t 2 = enable MSI interrupt mechanism.");
  56. #define QL4_DEF_QDEPTH 32
  57. static int ql4xmaxqdepth = QL4_DEF_QDEPTH;
  58. module_param(ql4xmaxqdepth, int, S_IRUGO | S_IWUSR);
  59. MODULE_PARM_DESC(ql4xmaxqdepth,
  60. " Maximum queue depth to report for target devices.\n"
  61. "\t\t Default: 32.");
  62. static int ql4xqfulltracking = 1;
  63. module_param(ql4xqfulltracking, int, S_IRUGO | S_IWUSR);
  64. MODULE_PARM_DESC(ql4xqfulltracking,
  65. " Enable or disable dynamic tracking and adjustment of\n"
  66. "\t\t scsi device queue depth.\n"
  67. "\t\t 0 - Disable.\n"
  68. "\t\t 1 - Enable. (Default)");
  69. static int ql4xsess_recovery_tmo = QL4_SESS_RECOVERY_TMO;
  70. module_param(ql4xsess_recovery_tmo, int, S_IRUGO);
  71. MODULE_PARM_DESC(ql4xsess_recovery_tmo,
  72. " Target Session Recovery Timeout.\n"
  73. "\t\t Default: 120 sec.");
  74. int ql4xmdcapmask = 0x1F;
  75. module_param(ql4xmdcapmask, int, S_IRUGO);
  76. MODULE_PARM_DESC(ql4xmdcapmask,
  77. " Set the Minidump driver capture mask level.\n"
  78. "\t\t Default is 0x1F.\n"
  79. "\t\t Can be set to 0x3, 0x7, 0xF, 0x1F, 0x3F, 0x7F");
  80. int ql4xenablemd = 1;
  81. module_param(ql4xenablemd, int, S_IRUGO | S_IWUSR);
  82. MODULE_PARM_DESC(ql4xenablemd,
  83. " Set to enable minidump.\n"
  84. "\t\t 0 - disable minidump\n"
  85. "\t\t 1 - enable minidump (Default)");
  86. static int qla4xxx_wait_for_hba_online(struct scsi_qla_host *ha);
  87. /*
  88. * SCSI host template entry points
  89. */
  90. static void qla4xxx_config_dma_addressing(struct scsi_qla_host *ha);
  91. /*
  92. * iSCSI template entry points
  93. */
  94. static int qla4xxx_session_get_param(struct iscsi_cls_session *cls_sess,
  95. enum iscsi_param param, char *buf);
  96. static int qla4xxx_conn_get_param(struct iscsi_cls_conn *conn,
  97. enum iscsi_param param, char *buf);
  98. static int qla4xxx_host_get_param(struct Scsi_Host *shost,
  99. enum iscsi_host_param param, char *buf);
  100. static int qla4xxx_iface_set_param(struct Scsi_Host *shost, void *data,
  101. uint32_t len);
  102. static int qla4xxx_get_iface_param(struct iscsi_iface *iface,
  103. enum iscsi_param_type param_type,
  104. int param, char *buf);
  105. static enum blk_eh_timer_return qla4xxx_eh_cmd_timed_out(struct scsi_cmnd *sc);
  106. static struct iscsi_endpoint *qla4xxx_ep_connect(struct Scsi_Host *shost,
  107. struct sockaddr *dst_addr,
  108. int non_blocking);
  109. static int qla4xxx_ep_poll(struct iscsi_endpoint *ep, int timeout_ms);
  110. static void qla4xxx_ep_disconnect(struct iscsi_endpoint *ep);
  111. static int qla4xxx_get_ep_param(struct iscsi_endpoint *ep,
  112. enum iscsi_param param, char *buf);
  113. static int qla4xxx_conn_start(struct iscsi_cls_conn *conn);
  114. static struct iscsi_cls_conn *
  115. qla4xxx_conn_create(struct iscsi_cls_session *cls_sess, uint32_t conn_idx);
  116. static int qla4xxx_conn_bind(struct iscsi_cls_session *cls_session,
  117. struct iscsi_cls_conn *cls_conn,
  118. uint64_t transport_fd, int is_leading);
  119. static void qla4xxx_conn_destroy(struct iscsi_cls_conn *conn);
  120. static struct iscsi_cls_session *
  121. qla4xxx_session_create(struct iscsi_endpoint *ep, uint16_t cmds_max,
  122. uint16_t qdepth, uint32_t initial_cmdsn);
  123. static void qla4xxx_session_destroy(struct iscsi_cls_session *sess);
  124. static void qla4xxx_task_work(struct work_struct *wdata);
  125. static int qla4xxx_alloc_pdu(struct iscsi_task *, uint8_t);
  126. static int qla4xxx_task_xmit(struct iscsi_task *);
  127. static void qla4xxx_task_cleanup(struct iscsi_task *);
  128. static void qla4xxx_fail_session(struct iscsi_cls_session *cls_session);
  129. static void qla4xxx_conn_get_stats(struct iscsi_cls_conn *cls_conn,
  130. struct iscsi_stats *stats);
  131. static int qla4xxx_send_ping(struct Scsi_Host *shost, uint32_t iface_num,
  132. uint32_t iface_type, uint32_t payload_size,
  133. uint32_t pid, struct sockaddr *dst_addr);
  134. static int qla4xxx_get_chap_list(struct Scsi_Host *shost, uint16_t chap_tbl_idx,
  135. uint32_t *num_entries, char *buf);
  136. static int qla4xxx_delete_chap(struct Scsi_Host *shost, uint16_t chap_tbl_idx);
  137. /*
  138. * SCSI host template entry points
  139. */
  140. static int qla4xxx_queuecommand(struct Scsi_Host *h, struct scsi_cmnd *cmd);
  141. static int qla4xxx_eh_abort(struct scsi_cmnd *cmd);
  142. static int qla4xxx_eh_device_reset(struct scsi_cmnd *cmd);
  143. static int qla4xxx_eh_target_reset(struct scsi_cmnd *cmd);
  144. static int qla4xxx_eh_host_reset(struct scsi_cmnd *cmd);
  145. static int qla4xxx_slave_alloc(struct scsi_device *device);
  146. static int qla4xxx_slave_configure(struct scsi_device *device);
  147. static void qla4xxx_slave_destroy(struct scsi_device *sdev);
  148. static umode_t qla4_attr_is_visible(int param_type, int param);
  149. static int qla4xxx_host_reset(struct Scsi_Host *shost, int reset_type);
  150. static int qla4xxx_change_queue_depth(struct scsi_device *sdev, int qdepth,
  151. int reason);
  152. /*
  153. * iSCSI Flash DDB sysfs entry points
  154. */
  155. static int
  156. qla4xxx_sysfs_ddb_set_param(struct iscsi_bus_flash_session *fnode_sess,
  157. struct iscsi_bus_flash_conn *fnode_conn,
  158. void *data, int len);
  159. static int
  160. qla4xxx_sysfs_ddb_get_param(struct iscsi_bus_flash_session *fnode_sess,
  161. int param, char *buf);
  162. static int qla4xxx_sysfs_ddb_add(struct Scsi_Host *shost, const char *buf,
  163. int len);
  164. static int
  165. qla4xxx_sysfs_ddb_delete(struct iscsi_bus_flash_session *fnode_sess);
  166. static int qla4xxx_sysfs_ddb_login(struct iscsi_bus_flash_session *fnode_sess,
  167. struct iscsi_bus_flash_conn *fnode_conn);
  168. static int qla4xxx_sysfs_ddb_logout(struct iscsi_bus_flash_session *fnode_sess,
  169. struct iscsi_bus_flash_conn *fnode_conn);
  170. static int qla4xxx_sysfs_ddb_logout_sid(struct iscsi_cls_session *cls_sess);
  171. static struct qla4_8xxx_legacy_intr_set legacy_intr[] =
  172. QLA82XX_LEGACY_INTR_CONFIG;
  173. static struct scsi_host_template qla4xxx_driver_template = {
  174. .module = THIS_MODULE,
  175. .name = DRIVER_NAME,
  176. .proc_name = DRIVER_NAME,
  177. .queuecommand = qla4xxx_queuecommand,
  178. .eh_abort_handler = qla4xxx_eh_abort,
  179. .eh_device_reset_handler = qla4xxx_eh_device_reset,
  180. .eh_target_reset_handler = qla4xxx_eh_target_reset,
  181. .eh_host_reset_handler = qla4xxx_eh_host_reset,
  182. .eh_timed_out = qla4xxx_eh_cmd_timed_out,
  183. .slave_configure = qla4xxx_slave_configure,
  184. .slave_alloc = qla4xxx_slave_alloc,
  185. .slave_destroy = qla4xxx_slave_destroy,
  186. .change_queue_depth = qla4xxx_change_queue_depth,
  187. .this_id = -1,
  188. .cmd_per_lun = 3,
  189. .use_clustering = ENABLE_CLUSTERING,
  190. .sg_tablesize = SG_ALL,
  191. .max_sectors = 0xFFFF,
  192. .shost_attrs = qla4xxx_host_attrs,
  193. .host_reset = qla4xxx_host_reset,
  194. .vendor_id = SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_QLOGIC,
  195. };
  196. static struct iscsi_transport qla4xxx_iscsi_transport = {
  197. .owner = THIS_MODULE,
  198. .name = DRIVER_NAME,
  199. .caps = CAP_TEXT_NEGO |
  200. CAP_DATA_PATH_OFFLOAD | CAP_HDRDGST |
  201. CAP_DATADGST | CAP_LOGIN_OFFLOAD |
  202. CAP_MULTI_R2T,
  203. .attr_is_visible = qla4_attr_is_visible,
  204. .create_session = qla4xxx_session_create,
  205. .destroy_session = qla4xxx_session_destroy,
  206. .start_conn = qla4xxx_conn_start,
  207. .create_conn = qla4xxx_conn_create,
  208. .bind_conn = qla4xxx_conn_bind,
  209. .stop_conn = iscsi_conn_stop,
  210. .destroy_conn = qla4xxx_conn_destroy,
  211. .set_param = iscsi_set_param,
  212. .get_conn_param = qla4xxx_conn_get_param,
  213. .get_session_param = qla4xxx_session_get_param,
  214. .get_ep_param = qla4xxx_get_ep_param,
  215. .ep_connect = qla4xxx_ep_connect,
  216. .ep_poll = qla4xxx_ep_poll,
  217. .ep_disconnect = qla4xxx_ep_disconnect,
  218. .get_stats = qla4xxx_conn_get_stats,
  219. .send_pdu = iscsi_conn_send_pdu,
  220. .xmit_task = qla4xxx_task_xmit,
  221. .cleanup_task = qla4xxx_task_cleanup,
  222. .alloc_pdu = qla4xxx_alloc_pdu,
  223. .get_host_param = qla4xxx_host_get_param,
  224. .set_iface_param = qla4xxx_iface_set_param,
  225. .get_iface_param = qla4xxx_get_iface_param,
  226. .bsg_request = qla4xxx_bsg_request,
  227. .send_ping = qla4xxx_send_ping,
  228. .get_chap = qla4xxx_get_chap_list,
  229. .delete_chap = qla4xxx_delete_chap,
  230. .get_flashnode_param = qla4xxx_sysfs_ddb_get_param,
  231. .set_flashnode_param = qla4xxx_sysfs_ddb_set_param,
  232. .new_flashnode = qla4xxx_sysfs_ddb_add,
  233. .del_flashnode = qla4xxx_sysfs_ddb_delete,
  234. .login_flashnode = qla4xxx_sysfs_ddb_login,
  235. .logout_flashnode = qla4xxx_sysfs_ddb_logout,
  236. .logout_flashnode_sid = qla4xxx_sysfs_ddb_logout_sid,
  237. };
  238. static struct scsi_transport_template *qla4xxx_scsi_transport;
  239. static int qla4xxx_send_ping(struct Scsi_Host *shost, uint32_t iface_num,
  240. uint32_t iface_type, uint32_t payload_size,
  241. uint32_t pid, struct sockaddr *dst_addr)
  242. {
  243. struct scsi_qla_host *ha = to_qla_host(shost);
  244. struct sockaddr_in *addr;
  245. struct sockaddr_in6 *addr6;
  246. uint32_t options = 0;
  247. uint8_t ipaddr[IPv6_ADDR_LEN];
  248. int rval;
  249. memset(ipaddr, 0, IPv6_ADDR_LEN);
  250. /* IPv4 to IPv4 */
  251. if ((iface_type == ISCSI_IFACE_TYPE_IPV4) &&
  252. (dst_addr->sa_family == AF_INET)) {
  253. addr = (struct sockaddr_in *)dst_addr;
  254. memcpy(ipaddr, &addr->sin_addr.s_addr, IP_ADDR_LEN);
  255. DEBUG2(ql4_printk(KERN_INFO, ha, "%s: IPv4 Ping src: %pI4 "
  256. "dest: %pI4\n", __func__,
  257. &ha->ip_config.ip_address, ipaddr));
  258. rval = qla4xxx_ping_iocb(ha, options, payload_size, pid,
  259. ipaddr);
  260. if (rval)
  261. rval = -EINVAL;
  262. } else if ((iface_type == ISCSI_IFACE_TYPE_IPV6) &&
  263. (dst_addr->sa_family == AF_INET6)) {
  264. /* IPv6 to IPv6 */
  265. addr6 = (struct sockaddr_in6 *)dst_addr;
  266. memcpy(ipaddr, &addr6->sin6_addr.in6_u.u6_addr8, IPv6_ADDR_LEN);
  267. options |= PING_IPV6_PROTOCOL_ENABLE;
  268. /* Ping using LinkLocal address */
  269. if ((iface_num == 0) || (iface_num == 1)) {
  270. DEBUG2(ql4_printk(KERN_INFO, ha, "%s: LinkLocal Ping "
  271. "src: %pI6 dest: %pI6\n", __func__,
  272. &ha->ip_config.ipv6_link_local_addr,
  273. ipaddr));
  274. options |= PING_IPV6_LINKLOCAL_ADDR;
  275. rval = qla4xxx_ping_iocb(ha, options, payload_size,
  276. pid, ipaddr);
  277. } else {
  278. ql4_printk(KERN_WARNING, ha, "%s: iface num = %d "
  279. "not supported\n", __func__, iface_num);
  280. rval = -ENOSYS;
  281. goto exit_send_ping;
  282. }
  283. /*
  284. * If ping using LinkLocal address fails, try ping using
  285. * IPv6 address
  286. */
  287. if (rval != QLA_SUCCESS) {
  288. options &= ~PING_IPV6_LINKLOCAL_ADDR;
  289. if (iface_num == 0) {
  290. options |= PING_IPV6_ADDR0;
  291. DEBUG2(ql4_printk(KERN_INFO, ha, "%s: IPv6 "
  292. "Ping src: %pI6 "
  293. "dest: %pI6\n", __func__,
  294. &ha->ip_config.ipv6_addr0,
  295. ipaddr));
  296. } else if (iface_num == 1) {
  297. options |= PING_IPV6_ADDR1;
  298. DEBUG2(ql4_printk(KERN_INFO, ha, "%s: IPv6 "
  299. "Ping src: %pI6 "
  300. "dest: %pI6\n", __func__,
  301. &ha->ip_config.ipv6_addr1,
  302. ipaddr));
  303. }
  304. rval = qla4xxx_ping_iocb(ha, options, payload_size,
  305. pid, ipaddr);
  306. if (rval)
  307. rval = -EINVAL;
  308. }
  309. } else
  310. rval = -ENOSYS;
  311. exit_send_ping:
  312. return rval;
  313. }
  314. static umode_t qla4_attr_is_visible(int param_type, int param)
  315. {
  316. switch (param_type) {
  317. case ISCSI_HOST_PARAM:
  318. switch (param) {
  319. case ISCSI_HOST_PARAM_HWADDRESS:
  320. case ISCSI_HOST_PARAM_IPADDRESS:
  321. case ISCSI_HOST_PARAM_INITIATOR_NAME:
  322. case ISCSI_HOST_PARAM_PORT_STATE:
  323. case ISCSI_HOST_PARAM_PORT_SPEED:
  324. return S_IRUGO;
  325. default:
  326. return 0;
  327. }
  328. case ISCSI_PARAM:
  329. switch (param) {
  330. case ISCSI_PARAM_PERSISTENT_ADDRESS:
  331. case ISCSI_PARAM_PERSISTENT_PORT:
  332. case ISCSI_PARAM_CONN_ADDRESS:
  333. case ISCSI_PARAM_CONN_PORT:
  334. case ISCSI_PARAM_TARGET_NAME:
  335. case ISCSI_PARAM_TPGT:
  336. case ISCSI_PARAM_TARGET_ALIAS:
  337. case ISCSI_PARAM_MAX_BURST:
  338. case ISCSI_PARAM_MAX_R2T:
  339. case ISCSI_PARAM_FIRST_BURST:
  340. case ISCSI_PARAM_MAX_RECV_DLENGTH:
  341. case ISCSI_PARAM_MAX_XMIT_DLENGTH:
  342. case ISCSI_PARAM_IFACE_NAME:
  343. case ISCSI_PARAM_CHAP_OUT_IDX:
  344. case ISCSI_PARAM_CHAP_IN_IDX:
  345. case ISCSI_PARAM_USERNAME:
  346. case ISCSI_PARAM_PASSWORD:
  347. case ISCSI_PARAM_USERNAME_IN:
  348. case ISCSI_PARAM_PASSWORD_IN:
  349. case ISCSI_PARAM_AUTO_SND_TGT_DISABLE:
  350. case ISCSI_PARAM_DISCOVERY_SESS:
  351. case ISCSI_PARAM_PORTAL_TYPE:
  352. case ISCSI_PARAM_CHAP_AUTH_EN:
  353. case ISCSI_PARAM_DISCOVERY_LOGOUT_EN:
  354. case ISCSI_PARAM_BIDI_CHAP_EN:
  355. case ISCSI_PARAM_DISCOVERY_AUTH_OPTIONAL:
  356. case ISCSI_PARAM_DEF_TIME2WAIT:
  357. case ISCSI_PARAM_DEF_TIME2RETAIN:
  358. case ISCSI_PARAM_HDRDGST_EN:
  359. case ISCSI_PARAM_DATADGST_EN:
  360. case ISCSI_PARAM_INITIAL_R2T_EN:
  361. case ISCSI_PARAM_IMM_DATA_EN:
  362. case ISCSI_PARAM_PDU_INORDER_EN:
  363. case ISCSI_PARAM_DATASEQ_INORDER_EN:
  364. case ISCSI_PARAM_MAX_SEGMENT_SIZE:
  365. case ISCSI_PARAM_TCP_TIMESTAMP_STAT:
  366. case ISCSI_PARAM_TCP_WSF_DISABLE:
  367. case ISCSI_PARAM_TCP_NAGLE_DISABLE:
  368. case ISCSI_PARAM_TCP_TIMER_SCALE:
  369. case ISCSI_PARAM_TCP_TIMESTAMP_EN:
  370. case ISCSI_PARAM_TCP_XMIT_WSF:
  371. case ISCSI_PARAM_TCP_RECV_WSF:
  372. case ISCSI_PARAM_IP_FRAGMENT_DISABLE:
  373. case ISCSI_PARAM_IPV4_TOS:
  374. case ISCSI_PARAM_IPV6_TC:
  375. case ISCSI_PARAM_IPV6_FLOW_LABEL:
  376. case ISCSI_PARAM_IS_FW_ASSIGNED_IPV6:
  377. case ISCSI_PARAM_KEEPALIVE_TMO:
  378. case ISCSI_PARAM_LOCAL_PORT:
  379. case ISCSI_PARAM_ISID:
  380. case ISCSI_PARAM_TSID:
  381. case ISCSI_PARAM_DEF_TASKMGMT_TMO:
  382. case ISCSI_PARAM_ERL:
  383. case ISCSI_PARAM_STATSN:
  384. case ISCSI_PARAM_EXP_STATSN:
  385. case ISCSI_PARAM_DISCOVERY_PARENT_IDX:
  386. case ISCSI_PARAM_DISCOVERY_PARENT_TYPE:
  387. return S_IRUGO;
  388. default:
  389. return 0;
  390. }
  391. case ISCSI_NET_PARAM:
  392. switch (param) {
  393. case ISCSI_NET_PARAM_IPV4_ADDR:
  394. case ISCSI_NET_PARAM_IPV4_SUBNET:
  395. case ISCSI_NET_PARAM_IPV4_GW:
  396. case ISCSI_NET_PARAM_IPV4_BOOTPROTO:
  397. case ISCSI_NET_PARAM_IFACE_ENABLE:
  398. case ISCSI_NET_PARAM_IPV6_LINKLOCAL:
  399. case ISCSI_NET_PARAM_IPV6_ADDR:
  400. case ISCSI_NET_PARAM_IPV6_ROUTER:
  401. case ISCSI_NET_PARAM_IPV6_ADDR_AUTOCFG:
  402. case ISCSI_NET_PARAM_IPV6_LINKLOCAL_AUTOCFG:
  403. case ISCSI_NET_PARAM_VLAN_ID:
  404. case ISCSI_NET_PARAM_VLAN_PRIORITY:
  405. case ISCSI_NET_PARAM_VLAN_ENABLED:
  406. case ISCSI_NET_PARAM_MTU:
  407. case ISCSI_NET_PARAM_PORT:
  408. return S_IRUGO;
  409. default:
  410. return 0;
  411. }
  412. case ISCSI_FLASHNODE_PARAM:
  413. switch (param) {
  414. case ISCSI_FLASHNODE_IS_FW_ASSIGNED_IPV6:
  415. case ISCSI_FLASHNODE_PORTAL_TYPE:
  416. case ISCSI_FLASHNODE_AUTO_SND_TGT_DISABLE:
  417. case ISCSI_FLASHNODE_DISCOVERY_SESS:
  418. case ISCSI_FLASHNODE_ENTRY_EN:
  419. case ISCSI_FLASHNODE_HDR_DGST_EN:
  420. case ISCSI_FLASHNODE_DATA_DGST_EN:
  421. case ISCSI_FLASHNODE_IMM_DATA_EN:
  422. case ISCSI_FLASHNODE_INITIAL_R2T_EN:
  423. case ISCSI_FLASHNODE_DATASEQ_INORDER:
  424. case ISCSI_FLASHNODE_PDU_INORDER:
  425. case ISCSI_FLASHNODE_CHAP_AUTH_EN:
  426. case ISCSI_FLASHNODE_SNACK_REQ_EN:
  427. case ISCSI_FLASHNODE_DISCOVERY_LOGOUT_EN:
  428. case ISCSI_FLASHNODE_BIDI_CHAP_EN:
  429. case ISCSI_FLASHNODE_DISCOVERY_AUTH_OPTIONAL:
  430. case ISCSI_FLASHNODE_ERL:
  431. case ISCSI_FLASHNODE_TCP_TIMESTAMP_STAT:
  432. case ISCSI_FLASHNODE_TCP_NAGLE_DISABLE:
  433. case ISCSI_FLASHNODE_TCP_WSF_DISABLE:
  434. case ISCSI_FLASHNODE_TCP_TIMER_SCALE:
  435. case ISCSI_FLASHNODE_TCP_TIMESTAMP_EN:
  436. case ISCSI_FLASHNODE_IP_FRAG_DISABLE:
  437. case ISCSI_FLASHNODE_MAX_RECV_DLENGTH:
  438. case ISCSI_FLASHNODE_MAX_XMIT_DLENGTH:
  439. case ISCSI_FLASHNODE_FIRST_BURST:
  440. case ISCSI_FLASHNODE_DEF_TIME2WAIT:
  441. case ISCSI_FLASHNODE_DEF_TIME2RETAIN:
  442. case ISCSI_FLASHNODE_MAX_R2T:
  443. case ISCSI_FLASHNODE_KEEPALIVE_TMO:
  444. case ISCSI_FLASHNODE_ISID:
  445. case ISCSI_FLASHNODE_TSID:
  446. case ISCSI_FLASHNODE_PORT:
  447. case ISCSI_FLASHNODE_MAX_BURST:
  448. case ISCSI_FLASHNODE_DEF_TASKMGMT_TMO:
  449. case ISCSI_FLASHNODE_IPADDR:
  450. case ISCSI_FLASHNODE_ALIAS:
  451. case ISCSI_FLASHNODE_REDIRECT_IPADDR:
  452. case ISCSI_FLASHNODE_MAX_SEGMENT_SIZE:
  453. case ISCSI_FLASHNODE_LOCAL_PORT:
  454. case ISCSI_FLASHNODE_IPV4_TOS:
  455. case ISCSI_FLASHNODE_IPV6_TC:
  456. case ISCSI_FLASHNODE_IPV6_FLOW_LABEL:
  457. case ISCSI_FLASHNODE_NAME:
  458. case ISCSI_FLASHNODE_TPGT:
  459. case ISCSI_FLASHNODE_LINK_LOCAL_IPV6:
  460. case ISCSI_FLASHNODE_DISCOVERY_PARENT_IDX:
  461. case ISCSI_FLASHNODE_DISCOVERY_PARENT_TYPE:
  462. case ISCSI_FLASHNODE_TCP_XMIT_WSF:
  463. case ISCSI_FLASHNODE_TCP_RECV_WSF:
  464. case ISCSI_FLASHNODE_CHAP_OUT_IDX:
  465. case ISCSI_FLASHNODE_USERNAME:
  466. case ISCSI_FLASHNODE_PASSWORD:
  467. case ISCSI_FLASHNODE_STATSN:
  468. case ISCSI_FLASHNODE_EXP_STATSN:
  469. case ISCSI_FLASHNODE_IS_BOOT_TGT:
  470. return S_IRUGO;
  471. default:
  472. return 0;
  473. }
  474. }
  475. return 0;
  476. }
  477. static int qla4xxx_get_chap_list(struct Scsi_Host *shost, uint16_t chap_tbl_idx,
  478. uint32_t *num_entries, char *buf)
  479. {
  480. struct scsi_qla_host *ha = to_qla_host(shost);
  481. struct ql4_chap_table *chap_table;
  482. struct iscsi_chap_rec *chap_rec;
  483. int max_chap_entries = 0;
  484. int valid_chap_entries = 0;
  485. int ret = 0, i;
  486. if (is_qla80XX(ha))
  487. max_chap_entries = (ha->hw.flt_chap_size / 2) /
  488. sizeof(struct ql4_chap_table);
  489. else
  490. max_chap_entries = MAX_CHAP_ENTRIES_40XX;
  491. ql4_printk(KERN_INFO, ha, "%s: num_entries = %d, CHAP idx = %d\n",
  492. __func__, *num_entries, chap_tbl_idx);
  493. if (!buf) {
  494. ret = -ENOMEM;
  495. goto exit_get_chap_list;
  496. }
  497. chap_rec = (struct iscsi_chap_rec *) buf;
  498. mutex_lock(&ha->chap_sem);
  499. for (i = chap_tbl_idx; i < max_chap_entries; i++) {
  500. chap_table = (struct ql4_chap_table *)ha->chap_list + i;
  501. if (chap_table->cookie !=
  502. __constant_cpu_to_le16(CHAP_VALID_COOKIE))
  503. continue;
  504. chap_rec->chap_tbl_idx = i;
  505. strncpy(chap_rec->username, chap_table->name,
  506. ISCSI_CHAP_AUTH_NAME_MAX_LEN);
  507. strncpy(chap_rec->password, chap_table->secret,
  508. QL4_CHAP_MAX_SECRET_LEN);
  509. chap_rec->password_length = chap_table->secret_len;
  510. if (chap_table->flags & BIT_7) /* local */
  511. chap_rec->chap_type = CHAP_TYPE_OUT;
  512. if (chap_table->flags & BIT_6) /* peer */
  513. chap_rec->chap_type = CHAP_TYPE_IN;
  514. chap_rec++;
  515. valid_chap_entries++;
  516. if (valid_chap_entries == *num_entries)
  517. break;
  518. else
  519. continue;
  520. }
  521. mutex_unlock(&ha->chap_sem);
  522. exit_get_chap_list:
  523. ql4_printk(KERN_INFO, ha, "%s: Valid CHAP Entries = %d\n",
  524. __func__, valid_chap_entries);
  525. *num_entries = valid_chap_entries;
  526. return ret;
  527. }
  528. static int __qla4xxx_is_chap_active(struct device *dev, void *data)
  529. {
  530. int ret = 0;
  531. uint16_t *chap_tbl_idx = (uint16_t *) data;
  532. struct iscsi_cls_session *cls_session;
  533. struct iscsi_session *sess;
  534. struct ddb_entry *ddb_entry;
  535. if (!iscsi_is_session_dev(dev))
  536. goto exit_is_chap_active;
  537. cls_session = iscsi_dev_to_session(dev);
  538. sess = cls_session->dd_data;
  539. ddb_entry = sess->dd_data;
  540. if (iscsi_session_chkready(cls_session))
  541. goto exit_is_chap_active;
  542. if (ddb_entry->chap_tbl_idx == *chap_tbl_idx)
  543. ret = 1;
  544. exit_is_chap_active:
  545. return ret;
  546. }
  547. static int qla4xxx_is_chap_active(struct Scsi_Host *shost,
  548. uint16_t chap_tbl_idx)
  549. {
  550. int ret = 0;
  551. ret = device_for_each_child(&shost->shost_gendev, &chap_tbl_idx,
  552. __qla4xxx_is_chap_active);
  553. return ret;
  554. }
  555. static int qla4xxx_delete_chap(struct Scsi_Host *shost, uint16_t chap_tbl_idx)
  556. {
  557. struct scsi_qla_host *ha = to_qla_host(shost);
  558. struct ql4_chap_table *chap_table;
  559. dma_addr_t chap_dma;
  560. int max_chap_entries = 0;
  561. uint32_t offset = 0;
  562. uint32_t chap_size;
  563. int ret = 0;
  564. chap_table = dma_pool_alloc(ha->chap_dma_pool, GFP_KERNEL, &chap_dma);
  565. if (chap_table == NULL)
  566. return -ENOMEM;
  567. memset(chap_table, 0, sizeof(struct ql4_chap_table));
  568. if (is_qla80XX(ha))
  569. max_chap_entries = (ha->hw.flt_chap_size / 2) /
  570. sizeof(struct ql4_chap_table);
  571. else
  572. max_chap_entries = MAX_CHAP_ENTRIES_40XX;
  573. if (chap_tbl_idx > max_chap_entries) {
  574. ret = -EINVAL;
  575. goto exit_delete_chap;
  576. }
  577. /* Check if chap index is in use.
  578. * If chap is in use don't delet chap entry */
  579. ret = qla4xxx_is_chap_active(shost, chap_tbl_idx);
  580. if (ret) {
  581. ql4_printk(KERN_INFO, ha, "CHAP entry %d is in use, cannot "
  582. "delete from flash\n", chap_tbl_idx);
  583. ret = -EBUSY;
  584. goto exit_delete_chap;
  585. }
  586. chap_size = sizeof(struct ql4_chap_table);
  587. if (is_qla40XX(ha))
  588. offset = FLASH_CHAP_OFFSET | (chap_tbl_idx * chap_size);
  589. else {
  590. offset = FLASH_RAW_ACCESS_ADDR + (ha->hw.flt_region_chap << 2);
  591. /* flt_chap_size is CHAP table size for both ports
  592. * so divide it by 2 to calculate the offset for second port
  593. */
  594. if (ha->port_num == 1)
  595. offset += (ha->hw.flt_chap_size / 2);
  596. offset += (chap_tbl_idx * chap_size);
  597. }
  598. ret = qla4xxx_get_flash(ha, chap_dma, offset, chap_size);
  599. if (ret != QLA_SUCCESS) {
  600. ret = -EINVAL;
  601. goto exit_delete_chap;
  602. }
  603. DEBUG2(ql4_printk(KERN_INFO, ha, "Chap Cookie: x%x\n",
  604. __le16_to_cpu(chap_table->cookie)));
  605. if (__le16_to_cpu(chap_table->cookie) != CHAP_VALID_COOKIE) {
  606. ql4_printk(KERN_ERR, ha, "No valid chap entry found\n");
  607. goto exit_delete_chap;
  608. }
  609. chap_table->cookie = __constant_cpu_to_le16(0xFFFF);
  610. offset = FLASH_CHAP_OFFSET |
  611. (chap_tbl_idx * sizeof(struct ql4_chap_table));
  612. ret = qla4xxx_set_flash(ha, chap_dma, offset, chap_size,
  613. FLASH_OPT_RMW_COMMIT);
  614. if (ret == QLA_SUCCESS && ha->chap_list) {
  615. mutex_lock(&ha->chap_sem);
  616. /* Update ha chap_list cache */
  617. memcpy((struct ql4_chap_table *)ha->chap_list + chap_tbl_idx,
  618. chap_table, sizeof(struct ql4_chap_table));
  619. mutex_unlock(&ha->chap_sem);
  620. }
  621. if (ret != QLA_SUCCESS)
  622. ret = -EINVAL;
  623. exit_delete_chap:
  624. dma_pool_free(ha->chap_dma_pool, chap_table, chap_dma);
  625. return ret;
  626. }
  627. static int qla4xxx_get_iface_param(struct iscsi_iface *iface,
  628. enum iscsi_param_type param_type,
  629. int param, char *buf)
  630. {
  631. struct Scsi_Host *shost = iscsi_iface_to_shost(iface);
  632. struct scsi_qla_host *ha = to_qla_host(shost);
  633. int len = -ENOSYS;
  634. if (param_type != ISCSI_NET_PARAM)
  635. return -ENOSYS;
  636. switch (param) {
  637. case ISCSI_NET_PARAM_IPV4_ADDR:
  638. len = sprintf(buf, "%pI4\n", &ha->ip_config.ip_address);
  639. break;
  640. case ISCSI_NET_PARAM_IPV4_SUBNET:
  641. len = sprintf(buf, "%pI4\n", &ha->ip_config.subnet_mask);
  642. break;
  643. case ISCSI_NET_PARAM_IPV4_GW:
  644. len = sprintf(buf, "%pI4\n", &ha->ip_config.gateway);
  645. break;
  646. case ISCSI_NET_PARAM_IFACE_ENABLE:
  647. if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4)
  648. len = sprintf(buf, "%s\n",
  649. (ha->ip_config.ipv4_options &
  650. IPOPT_IPV4_PROTOCOL_ENABLE) ?
  651. "enabled" : "disabled");
  652. else if (iface->iface_type == ISCSI_IFACE_TYPE_IPV6)
  653. len = sprintf(buf, "%s\n",
  654. (ha->ip_config.ipv6_options &
  655. IPV6_OPT_IPV6_PROTOCOL_ENABLE) ?
  656. "enabled" : "disabled");
  657. break;
  658. case ISCSI_NET_PARAM_IPV4_BOOTPROTO:
  659. len = sprintf(buf, "%s\n",
  660. (ha->ip_config.tcp_options & TCPOPT_DHCP_ENABLE) ?
  661. "dhcp" : "static");
  662. break;
  663. case ISCSI_NET_PARAM_IPV6_ADDR:
  664. if (iface->iface_num == 0)
  665. len = sprintf(buf, "%pI6\n", &ha->ip_config.ipv6_addr0);
  666. if (iface->iface_num == 1)
  667. len = sprintf(buf, "%pI6\n", &ha->ip_config.ipv6_addr1);
  668. break;
  669. case ISCSI_NET_PARAM_IPV6_LINKLOCAL:
  670. len = sprintf(buf, "%pI6\n",
  671. &ha->ip_config.ipv6_link_local_addr);
  672. break;
  673. case ISCSI_NET_PARAM_IPV6_ROUTER:
  674. len = sprintf(buf, "%pI6\n",
  675. &ha->ip_config.ipv6_default_router_addr);
  676. break;
  677. case ISCSI_NET_PARAM_IPV6_ADDR_AUTOCFG:
  678. len = sprintf(buf, "%s\n",
  679. (ha->ip_config.ipv6_addl_options &
  680. IPV6_ADDOPT_NEIGHBOR_DISCOVERY_ADDR_ENABLE) ?
  681. "nd" : "static");
  682. break;
  683. case ISCSI_NET_PARAM_IPV6_LINKLOCAL_AUTOCFG:
  684. len = sprintf(buf, "%s\n",
  685. (ha->ip_config.ipv6_addl_options &
  686. IPV6_ADDOPT_AUTOCONFIG_LINK_LOCAL_ADDR) ?
  687. "auto" : "static");
  688. break;
  689. case ISCSI_NET_PARAM_VLAN_ID:
  690. if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4)
  691. len = sprintf(buf, "%d\n",
  692. (ha->ip_config.ipv4_vlan_tag &
  693. ISCSI_MAX_VLAN_ID));
  694. else if (iface->iface_type == ISCSI_IFACE_TYPE_IPV6)
  695. len = sprintf(buf, "%d\n",
  696. (ha->ip_config.ipv6_vlan_tag &
  697. ISCSI_MAX_VLAN_ID));
  698. break;
  699. case ISCSI_NET_PARAM_VLAN_PRIORITY:
  700. if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4)
  701. len = sprintf(buf, "%d\n",
  702. ((ha->ip_config.ipv4_vlan_tag >> 13) &
  703. ISCSI_MAX_VLAN_PRIORITY));
  704. else if (iface->iface_type == ISCSI_IFACE_TYPE_IPV6)
  705. len = sprintf(buf, "%d\n",
  706. ((ha->ip_config.ipv6_vlan_tag >> 13) &
  707. ISCSI_MAX_VLAN_PRIORITY));
  708. break;
  709. case ISCSI_NET_PARAM_VLAN_ENABLED:
  710. if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4)
  711. len = sprintf(buf, "%s\n",
  712. (ha->ip_config.ipv4_options &
  713. IPOPT_VLAN_TAGGING_ENABLE) ?
  714. "enabled" : "disabled");
  715. else if (iface->iface_type == ISCSI_IFACE_TYPE_IPV6)
  716. len = sprintf(buf, "%s\n",
  717. (ha->ip_config.ipv6_options &
  718. IPV6_OPT_VLAN_TAGGING_ENABLE) ?
  719. "enabled" : "disabled");
  720. break;
  721. case ISCSI_NET_PARAM_MTU:
  722. len = sprintf(buf, "%d\n", ha->ip_config.eth_mtu_size);
  723. break;
  724. case ISCSI_NET_PARAM_PORT:
  725. if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4)
  726. len = sprintf(buf, "%d\n", ha->ip_config.ipv4_port);
  727. else if (iface->iface_type == ISCSI_IFACE_TYPE_IPV6)
  728. len = sprintf(buf, "%d\n", ha->ip_config.ipv6_port);
  729. break;
  730. default:
  731. len = -ENOSYS;
  732. }
  733. return len;
  734. }
  735. static struct iscsi_endpoint *
  736. qla4xxx_ep_connect(struct Scsi_Host *shost, struct sockaddr *dst_addr,
  737. int non_blocking)
  738. {
  739. int ret;
  740. struct iscsi_endpoint *ep;
  741. struct qla_endpoint *qla_ep;
  742. struct scsi_qla_host *ha;
  743. struct sockaddr_in *addr;
  744. struct sockaddr_in6 *addr6;
  745. DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
  746. if (!shost) {
  747. ret = -ENXIO;
  748. printk(KERN_ERR "%s: shost is NULL\n",
  749. __func__);
  750. return ERR_PTR(ret);
  751. }
  752. ha = iscsi_host_priv(shost);
  753. ep = iscsi_create_endpoint(sizeof(struct qla_endpoint));
  754. if (!ep) {
  755. ret = -ENOMEM;
  756. return ERR_PTR(ret);
  757. }
  758. qla_ep = ep->dd_data;
  759. memset(qla_ep, 0, sizeof(struct qla_endpoint));
  760. if (dst_addr->sa_family == AF_INET) {
  761. memcpy(&qla_ep->dst_addr, dst_addr, sizeof(struct sockaddr_in));
  762. addr = (struct sockaddr_in *)&qla_ep->dst_addr;
  763. DEBUG2(ql4_printk(KERN_INFO, ha, "%s: %pI4\n", __func__,
  764. (char *)&addr->sin_addr));
  765. } else if (dst_addr->sa_family == AF_INET6) {
  766. memcpy(&qla_ep->dst_addr, dst_addr,
  767. sizeof(struct sockaddr_in6));
  768. addr6 = (struct sockaddr_in6 *)&qla_ep->dst_addr;
  769. DEBUG2(ql4_printk(KERN_INFO, ha, "%s: %pI6\n", __func__,
  770. (char *)&addr6->sin6_addr));
  771. }
  772. qla_ep->host = shost;
  773. return ep;
  774. }
  775. static int qla4xxx_ep_poll(struct iscsi_endpoint *ep, int timeout_ms)
  776. {
  777. struct qla_endpoint *qla_ep;
  778. struct scsi_qla_host *ha;
  779. int ret = 0;
  780. DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
  781. qla_ep = ep->dd_data;
  782. ha = to_qla_host(qla_ep->host);
  783. if (adapter_up(ha) && !test_bit(AF_BUILD_DDB_LIST, &ha->flags))
  784. ret = 1;
  785. return ret;
  786. }
  787. static void qla4xxx_ep_disconnect(struct iscsi_endpoint *ep)
  788. {
  789. DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
  790. iscsi_destroy_endpoint(ep);
  791. }
  792. static int qla4xxx_get_ep_param(struct iscsi_endpoint *ep,
  793. enum iscsi_param param,
  794. char *buf)
  795. {
  796. struct qla_endpoint *qla_ep = ep->dd_data;
  797. struct sockaddr *dst_addr;
  798. DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
  799. switch (param) {
  800. case ISCSI_PARAM_CONN_PORT:
  801. case ISCSI_PARAM_CONN_ADDRESS:
  802. if (!qla_ep)
  803. return -ENOTCONN;
  804. dst_addr = (struct sockaddr *)&qla_ep->dst_addr;
  805. if (!dst_addr)
  806. return -ENOTCONN;
  807. return iscsi_conn_get_addr_param((struct sockaddr_storage *)
  808. &qla_ep->dst_addr, param, buf);
  809. default:
  810. return -ENOSYS;
  811. }
  812. }
  813. static void qla4xxx_conn_get_stats(struct iscsi_cls_conn *cls_conn,
  814. struct iscsi_stats *stats)
  815. {
  816. struct iscsi_session *sess;
  817. struct iscsi_cls_session *cls_sess;
  818. struct ddb_entry *ddb_entry;
  819. struct scsi_qla_host *ha;
  820. struct ql_iscsi_stats *ql_iscsi_stats;
  821. int stats_size;
  822. int ret;
  823. dma_addr_t iscsi_stats_dma;
  824. DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
  825. cls_sess = iscsi_conn_to_session(cls_conn);
  826. sess = cls_sess->dd_data;
  827. ddb_entry = sess->dd_data;
  828. ha = ddb_entry->ha;
  829. stats_size = PAGE_ALIGN(sizeof(struct ql_iscsi_stats));
  830. /* Allocate memory */
  831. ql_iscsi_stats = dma_alloc_coherent(&ha->pdev->dev, stats_size,
  832. &iscsi_stats_dma, GFP_KERNEL);
  833. if (!ql_iscsi_stats) {
  834. ql4_printk(KERN_ERR, ha,
  835. "Unable to allocate memory for iscsi stats\n");
  836. goto exit_get_stats;
  837. }
  838. ret = qla4xxx_get_mgmt_data(ha, ddb_entry->fw_ddb_index, stats_size,
  839. iscsi_stats_dma);
  840. if (ret != QLA_SUCCESS) {
  841. ql4_printk(KERN_ERR, ha,
  842. "Unable to retrieve iscsi stats\n");
  843. goto free_stats;
  844. }
  845. /* octets */
  846. stats->txdata_octets = le64_to_cpu(ql_iscsi_stats->tx_data_octets);
  847. stats->rxdata_octets = le64_to_cpu(ql_iscsi_stats->rx_data_octets);
  848. /* xmit pdus */
  849. stats->noptx_pdus = le32_to_cpu(ql_iscsi_stats->tx_nopout_pdus);
  850. stats->scsicmd_pdus = le32_to_cpu(ql_iscsi_stats->tx_scsi_cmd_pdus);
  851. stats->tmfcmd_pdus = le32_to_cpu(ql_iscsi_stats->tx_tmf_cmd_pdus);
  852. stats->login_pdus = le32_to_cpu(ql_iscsi_stats->tx_login_cmd_pdus);
  853. stats->text_pdus = le32_to_cpu(ql_iscsi_stats->tx_text_cmd_pdus);
  854. stats->dataout_pdus = le32_to_cpu(ql_iscsi_stats->tx_scsi_write_pdus);
  855. stats->logout_pdus = le32_to_cpu(ql_iscsi_stats->tx_logout_cmd_pdus);
  856. stats->snack_pdus = le32_to_cpu(ql_iscsi_stats->tx_snack_req_pdus);
  857. /* recv pdus */
  858. stats->noprx_pdus = le32_to_cpu(ql_iscsi_stats->rx_nopin_pdus);
  859. stats->scsirsp_pdus = le32_to_cpu(ql_iscsi_stats->rx_scsi_resp_pdus);
  860. stats->tmfrsp_pdus = le32_to_cpu(ql_iscsi_stats->rx_tmf_resp_pdus);
  861. stats->textrsp_pdus = le32_to_cpu(ql_iscsi_stats->rx_text_resp_pdus);
  862. stats->datain_pdus = le32_to_cpu(ql_iscsi_stats->rx_scsi_read_pdus);
  863. stats->logoutrsp_pdus =
  864. le32_to_cpu(ql_iscsi_stats->rx_logout_resp_pdus);
  865. stats->r2t_pdus = le32_to_cpu(ql_iscsi_stats->rx_r2t_pdus);
  866. stats->async_pdus = le32_to_cpu(ql_iscsi_stats->rx_async_pdus);
  867. stats->rjt_pdus = le32_to_cpu(ql_iscsi_stats->rx_reject_pdus);
  868. free_stats:
  869. dma_free_coherent(&ha->pdev->dev, stats_size, ql_iscsi_stats,
  870. iscsi_stats_dma);
  871. exit_get_stats:
  872. return;
  873. }
  874. static enum blk_eh_timer_return qla4xxx_eh_cmd_timed_out(struct scsi_cmnd *sc)
  875. {
  876. struct iscsi_cls_session *session;
  877. struct iscsi_session *sess;
  878. unsigned long flags;
  879. enum blk_eh_timer_return ret = BLK_EH_NOT_HANDLED;
  880. session = starget_to_session(scsi_target(sc->device));
  881. sess = session->dd_data;
  882. spin_lock_irqsave(&session->lock, flags);
  883. if (session->state == ISCSI_SESSION_FAILED)
  884. ret = BLK_EH_RESET_TIMER;
  885. spin_unlock_irqrestore(&session->lock, flags);
  886. return ret;
  887. }
  888. static void qla4xxx_set_port_speed(struct Scsi_Host *shost)
  889. {
  890. struct scsi_qla_host *ha = to_qla_host(shost);
  891. struct iscsi_cls_host *ihost = shost->shost_data;
  892. uint32_t speed = ISCSI_PORT_SPEED_UNKNOWN;
  893. qla4xxx_get_firmware_state(ha);
  894. switch (ha->addl_fw_state & 0x0F00) {
  895. case FW_ADDSTATE_LINK_SPEED_10MBPS:
  896. speed = ISCSI_PORT_SPEED_10MBPS;
  897. break;
  898. case FW_ADDSTATE_LINK_SPEED_100MBPS:
  899. speed = ISCSI_PORT_SPEED_100MBPS;
  900. break;
  901. case FW_ADDSTATE_LINK_SPEED_1GBPS:
  902. speed = ISCSI_PORT_SPEED_1GBPS;
  903. break;
  904. case FW_ADDSTATE_LINK_SPEED_10GBPS:
  905. speed = ISCSI_PORT_SPEED_10GBPS;
  906. break;
  907. }
  908. ihost->port_speed = speed;
  909. }
  910. static void qla4xxx_set_port_state(struct Scsi_Host *shost)
  911. {
  912. struct scsi_qla_host *ha = to_qla_host(shost);
  913. struct iscsi_cls_host *ihost = shost->shost_data;
  914. uint32_t state = ISCSI_PORT_STATE_DOWN;
  915. if (test_bit(AF_LINK_UP, &ha->flags))
  916. state = ISCSI_PORT_STATE_UP;
  917. ihost->port_state = state;
  918. }
  919. static int qla4xxx_host_get_param(struct Scsi_Host *shost,
  920. enum iscsi_host_param param, char *buf)
  921. {
  922. struct scsi_qla_host *ha = to_qla_host(shost);
  923. int len;
  924. switch (param) {
  925. case ISCSI_HOST_PARAM_HWADDRESS:
  926. len = sysfs_format_mac(buf, ha->my_mac, MAC_ADDR_LEN);
  927. break;
  928. case ISCSI_HOST_PARAM_IPADDRESS:
  929. len = sprintf(buf, "%pI4\n", &ha->ip_config.ip_address);
  930. break;
  931. case ISCSI_HOST_PARAM_INITIATOR_NAME:
  932. len = sprintf(buf, "%s\n", ha->name_string);
  933. break;
  934. case ISCSI_HOST_PARAM_PORT_STATE:
  935. qla4xxx_set_port_state(shost);
  936. len = sprintf(buf, "%s\n", iscsi_get_port_state_name(shost));
  937. break;
  938. case ISCSI_HOST_PARAM_PORT_SPEED:
  939. qla4xxx_set_port_speed(shost);
  940. len = sprintf(buf, "%s\n", iscsi_get_port_speed_name(shost));
  941. break;
  942. default:
  943. return -ENOSYS;
  944. }
  945. return len;
  946. }
  947. static void qla4xxx_create_ipv4_iface(struct scsi_qla_host *ha)
  948. {
  949. if (ha->iface_ipv4)
  950. return;
  951. /* IPv4 */
  952. ha->iface_ipv4 = iscsi_create_iface(ha->host,
  953. &qla4xxx_iscsi_transport,
  954. ISCSI_IFACE_TYPE_IPV4, 0, 0);
  955. if (!ha->iface_ipv4)
  956. ql4_printk(KERN_ERR, ha, "Could not create IPv4 iSCSI "
  957. "iface0.\n");
  958. }
  959. static void qla4xxx_create_ipv6_iface(struct scsi_qla_host *ha)
  960. {
  961. if (!ha->iface_ipv6_0)
  962. /* IPv6 iface-0 */
  963. ha->iface_ipv6_0 = iscsi_create_iface(ha->host,
  964. &qla4xxx_iscsi_transport,
  965. ISCSI_IFACE_TYPE_IPV6, 0,
  966. 0);
  967. if (!ha->iface_ipv6_0)
  968. ql4_printk(KERN_ERR, ha, "Could not create IPv6 iSCSI "
  969. "iface0.\n");
  970. if (!ha->iface_ipv6_1)
  971. /* IPv6 iface-1 */
  972. ha->iface_ipv6_1 = iscsi_create_iface(ha->host,
  973. &qla4xxx_iscsi_transport,
  974. ISCSI_IFACE_TYPE_IPV6, 1,
  975. 0);
  976. if (!ha->iface_ipv6_1)
  977. ql4_printk(KERN_ERR, ha, "Could not create IPv6 iSCSI "
  978. "iface1.\n");
  979. }
  980. static void qla4xxx_create_ifaces(struct scsi_qla_host *ha)
  981. {
  982. if (ha->ip_config.ipv4_options & IPOPT_IPV4_PROTOCOL_ENABLE)
  983. qla4xxx_create_ipv4_iface(ha);
  984. if (ha->ip_config.ipv6_options & IPV6_OPT_IPV6_PROTOCOL_ENABLE)
  985. qla4xxx_create_ipv6_iface(ha);
  986. }
  987. static void qla4xxx_destroy_ipv4_iface(struct scsi_qla_host *ha)
  988. {
  989. if (ha->iface_ipv4) {
  990. iscsi_destroy_iface(ha->iface_ipv4);
  991. ha->iface_ipv4 = NULL;
  992. }
  993. }
  994. static void qla4xxx_destroy_ipv6_iface(struct scsi_qla_host *ha)
  995. {
  996. if (ha->iface_ipv6_0) {
  997. iscsi_destroy_iface(ha->iface_ipv6_0);
  998. ha->iface_ipv6_0 = NULL;
  999. }
  1000. if (ha->iface_ipv6_1) {
  1001. iscsi_destroy_iface(ha->iface_ipv6_1);
  1002. ha->iface_ipv6_1 = NULL;
  1003. }
  1004. }
  1005. static void qla4xxx_destroy_ifaces(struct scsi_qla_host *ha)
  1006. {
  1007. qla4xxx_destroy_ipv4_iface(ha);
  1008. qla4xxx_destroy_ipv6_iface(ha);
  1009. }
  1010. static void qla4xxx_set_ipv6(struct scsi_qla_host *ha,
  1011. struct iscsi_iface_param_info *iface_param,
  1012. struct addr_ctrl_blk *init_fw_cb)
  1013. {
  1014. /*
  1015. * iface_num 0 is valid for IPv6 Addr, linklocal, router, autocfg.
  1016. * iface_num 1 is valid only for IPv6 Addr.
  1017. */
  1018. switch (iface_param->param) {
  1019. case ISCSI_NET_PARAM_IPV6_ADDR:
  1020. if (iface_param->iface_num & 0x1)
  1021. /* IPv6 Addr 1 */
  1022. memcpy(init_fw_cb->ipv6_addr1, iface_param->value,
  1023. sizeof(init_fw_cb->ipv6_addr1));
  1024. else
  1025. /* IPv6 Addr 0 */
  1026. memcpy(init_fw_cb->ipv6_addr0, iface_param->value,
  1027. sizeof(init_fw_cb->ipv6_addr0));
  1028. break;
  1029. case ISCSI_NET_PARAM_IPV6_LINKLOCAL:
  1030. if (iface_param->iface_num & 0x1)
  1031. break;
  1032. memcpy(init_fw_cb->ipv6_if_id, &iface_param->value[8],
  1033. sizeof(init_fw_cb->ipv6_if_id));
  1034. break;
  1035. case ISCSI_NET_PARAM_IPV6_ROUTER:
  1036. if (iface_param->iface_num & 0x1)
  1037. break;
  1038. memcpy(init_fw_cb->ipv6_dflt_rtr_addr, iface_param->value,
  1039. sizeof(init_fw_cb->ipv6_dflt_rtr_addr));
  1040. break;
  1041. case ISCSI_NET_PARAM_IPV6_ADDR_AUTOCFG:
  1042. /* Autocfg applies to even interface */
  1043. if (iface_param->iface_num & 0x1)
  1044. break;
  1045. if (iface_param->value[0] == ISCSI_IPV6_AUTOCFG_DISABLE)
  1046. init_fw_cb->ipv6_addtl_opts &=
  1047. cpu_to_le16(
  1048. ~IPV6_ADDOPT_NEIGHBOR_DISCOVERY_ADDR_ENABLE);
  1049. else if (iface_param->value[0] == ISCSI_IPV6_AUTOCFG_ND_ENABLE)
  1050. init_fw_cb->ipv6_addtl_opts |=
  1051. cpu_to_le16(
  1052. IPV6_ADDOPT_NEIGHBOR_DISCOVERY_ADDR_ENABLE);
  1053. else
  1054. ql4_printk(KERN_ERR, ha, "Invalid autocfg setting for "
  1055. "IPv6 addr\n");
  1056. break;
  1057. case ISCSI_NET_PARAM_IPV6_LINKLOCAL_AUTOCFG:
  1058. /* Autocfg applies to even interface */
  1059. if (iface_param->iface_num & 0x1)
  1060. break;
  1061. if (iface_param->value[0] ==
  1062. ISCSI_IPV6_LINKLOCAL_AUTOCFG_ENABLE)
  1063. init_fw_cb->ipv6_addtl_opts |= cpu_to_le16(
  1064. IPV6_ADDOPT_AUTOCONFIG_LINK_LOCAL_ADDR);
  1065. else if (iface_param->value[0] ==
  1066. ISCSI_IPV6_LINKLOCAL_AUTOCFG_DISABLE)
  1067. init_fw_cb->ipv6_addtl_opts &= cpu_to_le16(
  1068. ~IPV6_ADDOPT_AUTOCONFIG_LINK_LOCAL_ADDR);
  1069. else
  1070. ql4_printk(KERN_ERR, ha, "Invalid autocfg setting for "
  1071. "IPv6 linklocal addr\n");
  1072. break;
  1073. case ISCSI_NET_PARAM_IPV6_ROUTER_AUTOCFG:
  1074. /* Autocfg applies to even interface */
  1075. if (iface_param->iface_num & 0x1)
  1076. break;
  1077. if (iface_param->value[0] == ISCSI_IPV6_ROUTER_AUTOCFG_ENABLE)
  1078. memset(init_fw_cb->ipv6_dflt_rtr_addr, 0,
  1079. sizeof(init_fw_cb->ipv6_dflt_rtr_addr));
  1080. break;
  1081. case ISCSI_NET_PARAM_IFACE_ENABLE:
  1082. if (iface_param->value[0] == ISCSI_IFACE_ENABLE) {
  1083. init_fw_cb->ipv6_opts |=
  1084. cpu_to_le16(IPV6_OPT_IPV6_PROTOCOL_ENABLE);
  1085. qla4xxx_create_ipv6_iface(ha);
  1086. } else {
  1087. init_fw_cb->ipv6_opts &=
  1088. cpu_to_le16(~IPV6_OPT_IPV6_PROTOCOL_ENABLE &
  1089. 0xFFFF);
  1090. qla4xxx_destroy_ipv6_iface(ha);
  1091. }
  1092. break;
  1093. case ISCSI_NET_PARAM_VLAN_TAG:
  1094. if (iface_param->len != sizeof(init_fw_cb->ipv6_vlan_tag))
  1095. break;
  1096. init_fw_cb->ipv6_vlan_tag =
  1097. cpu_to_be16(*(uint16_t *)iface_param->value);
  1098. break;
  1099. case ISCSI_NET_PARAM_VLAN_ENABLED:
  1100. if (iface_param->value[0] == ISCSI_VLAN_ENABLE)
  1101. init_fw_cb->ipv6_opts |=
  1102. cpu_to_le16(IPV6_OPT_VLAN_TAGGING_ENABLE);
  1103. else
  1104. init_fw_cb->ipv6_opts &=
  1105. cpu_to_le16(~IPV6_OPT_VLAN_TAGGING_ENABLE);
  1106. break;
  1107. case ISCSI_NET_PARAM_MTU:
  1108. init_fw_cb->eth_mtu_size =
  1109. cpu_to_le16(*(uint16_t *)iface_param->value);
  1110. break;
  1111. case ISCSI_NET_PARAM_PORT:
  1112. /* Autocfg applies to even interface */
  1113. if (iface_param->iface_num & 0x1)
  1114. break;
  1115. init_fw_cb->ipv6_port =
  1116. cpu_to_le16(*(uint16_t *)iface_param->value);
  1117. break;
  1118. default:
  1119. ql4_printk(KERN_ERR, ha, "Unknown IPv6 param = %d\n",
  1120. iface_param->param);
  1121. break;
  1122. }
  1123. }
  1124. static void qla4xxx_set_ipv4(struct scsi_qla_host *ha,
  1125. struct iscsi_iface_param_info *iface_param,
  1126. struct addr_ctrl_blk *init_fw_cb)
  1127. {
  1128. switch (iface_param->param) {
  1129. case ISCSI_NET_PARAM_IPV4_ADDR:
  1130. memcpy(init_fw_cb->ipv4_addr, iface_param->value,
  1131. sizeof(init_fw_cb->ipv4_addr));
  1132. break;
  1133. case ISCSI_NET_PARAM_IPV4_SUBNET:
  1134. memcpy(init_fw_cb->ipv4_subnet, iface_param->value,
  1135. sizeof(init_fw_cb->ipv4_subnet));
  1136. break;
  1137. case ISCSI_NET_PARAM_IPV4_GW:
  1138. memcpy(init_fw_cb->ipv4_gw_addr, iface_param->value,
  1139. sizeof(init_fw_cb->ipv4_gw_addr));
  1140. break;
  1141. case ISCSI_NET_PARAM_IPV4_BOOTPROTO:
  1142. if (iface_param->value[0] == ISCSI_BOOTPROTO_DHCP)
  1143. init_fw_cb->ipv4_tcp_opts |=
  1144. cpu_to_le16(TCPOPT_DHCP_ENABLE);
  1145. else if (iface_param->value[0] == ISCSI_BOOTPROTO_STATIC)
  1146. init_fw_cb->ipv4_tcp_opts &=
  1147. cpu_to_le16(~TCPOPT_DHCP_ENABLE);
  1148. else
  1149. ql4_printk(KERN_ERR, ha, "Invalid IPv4 bootproto\n");
  1150. break;
  1151. case ISCSI_NET_PARAM_IFACE_ENABLE:
  1152. if (iface_param->value[0] == ISCSI_IFACE_ENABLE) {
  1153. init_fw_cb->ipv4_ip_opts |=
  1154. cpu_to_le16(IPOPT_IPV4_PROTOCOL_ENABLE);
  1155. qla4xxx_create_ipv4_iface(ha);
  1156. } else {
  1157. init_fw_cb->ipv4_ip_opts &=
  1158. cpu_to_le16(~IPOPT_IPV4_PROTOCOL_ENABLE &
  1159. 0xFFFF);
  1160. qla4xxx_destroy_ipv4_iface(ha);
  1161. }
  1162. break;
  1163. case ISCSI_NET_PARAM_VLAN_TAG:
  1164. if (iface_param->len != sizeof(init_fw_cb->ipv4_vlan_tag))
  1165. break;
  1166. init_fw_cb->ipv4_vlan_tag =
  1167. cpu_to_be16(*(uint16_t *)iface_param->value);
  1168. break;
  1169. case ISCSI_NET_PARAM_VLAN_ENABLED:
  1170. if (iface_param->value[0] == ISCSI_VLAN_ENABLE)
  1171. init_fw_cb->ipv4_ip_opts |=
  1172. cpu_to_le16(IPOPT_VLAN_TAGGING_ENABLE);
  1173. else
  1174. init_fw_cb->ipv4_ip_opts &=
  1175. cpu_to_le16(~IPOPT_VLAN_TAGGING_ENABLE);
  1176. break;
  1177. case ISCSI_NET_PARAM_MTU:
  1178. init_fw_cb->eth_mtu_size =
  1179. cpu_to_le16(*(uint16_t *)iface_param->value);
  1180. break;
  1181. case ISCSI_NET_PARAM_PORT:
  1182. init_fw_cb->ipv4_port =
  1183. cpu_to_le16(*(uint16_t *)iface_param->value);
  1184. break;
  1185. default:
  1186. ql4_printk(KERN_ERR, ha, "Unknown IPv4 param = %d\n",
  1187. iface_param->param);
  1188. break;
  1189. }
  1190. }
  1191. static void
  1192. qla4xxx_initcb_to_acb(struct addr_ctrl_blk *init_fw_cb)
  1193. {
  1194. struct addr_ctrl_blk_def *acb;
  1195. acb = (struct addr_ctrl_blk_def *)init_fw_cb;
  1196. memset(acb->reserved1, 0, sizeof(acb->reserved1));
  1197. memset(acb->reserved2, 0, sizeof(acb->reserved2));
  1198. memset(acb->reserved3, 0, sizeof(acb->reserved3));
  1199. memset(acb->reserved4, 0, sizeof(acb->reserved4));
  1200. memset(acb->reserved5, 0, sizeof(acb->reserved5));
  1201. memset(acb->reserved6, 0, sizeof(acb->reserved6));
  1202. memset(acb->reserved7, 0, sizeof(acb->reserved7));
  1203. memset(acb->reserved8, 0, sizeof(acb->reserved8));
  1204. memset(acb->reserved9, 0, sizeof(acb->reserved9));
  1205. memset(acb->reserved10, 0, sizeof(acb->reserved10));
  1206. memset(acb->reserved11, 0, sizeof(acb->reserved11));
  1207. memset(acb->reserved12, 0, sizeof(acb->reserved12));
  1208. memset(acb->reserved13, 0, sizeof(acb->reserved13));
  1209. memset(acb->reserved14, 0, sizeof(acb->reserved14));
  1210. memset(acb->reserved15, 0, sizeof(acb->reserved15));
  1211. }
  1212. static int
  1213. qla4xxx_iface_set_param(struct Scsi_Host *shost, void *data, uint32_t len)
  1214. {
  1215. struct scsi_qla_host *ha = to_qla_host(shost);
  1216. int rval = 0;
  1217. struct iscsi_iface_param_info *iface_param = NULL;
  1218. struct addr_ctrl_blk *init_fw_cb = NULL;
  1219. dma_addr_t init_fw_cb_dma;
  1220. uint32_t mbox_cmd[MBOX_REG_COUNT];
  1221. uint32_t mbox_sts[MBOX_REG_COUNT];
  1222. uint32_t rem = len;
  1223. struct nlattr *attr;
  1224. init_fw_cb = dma_alloc_coherent(&ha->pdev->dev,
  1225. sizeof(struct addr_ctrl_blk),
  1226. &init_fw_cb_dma, GFP_KERNEL);
  1227. if (!init_fw_cb) {
  1228. ql4_printk(KERN_ERR, ha, "%s: Unable to alloc init_cb\n",
  1229. __func__);
  1230. return -ENOMEM;
  1231. }
  1232. memset(init_fw_cb, 0, sizeof(struct addr_ctrl_blk));
  1233. memset(&mbox_cmd, 0, sizeof(mbox_cmd));
  1234. memset(&mbox_sts, 0, sizeof(mbox_sts));
  1235. if (qla4xxx_get_ifcb(ha, &mbox_cmd[0], &mbox_sts[0], init_fw_cb_dma)) {
  1236. ql4_printk(KERN_ERR, ha, "%s: get ifcb failed\n", __func__);
  1237. rval = -EIO;
  1238. goto exit_init_fw_cb;
  1239. }
  1240. nla_for_each_attr(attr, data, len, rem) {
  1241. iface_param = nla_data(attr);
  1242. if (iface_param->param_type != ISCSI_NET_PARAM)
  1243. continue;
  1244. switch (iface_param->iface_type) {
  1245. case ISCSI_IFACE_TYPE_IPV4:
  1246. switch (iface_param->iface_num) {
  1247. case 0:
  1248. qla4xxx_set_ipv4(ha, iface_param, init_fw_cb);
  1249. break;
  1250. default:
  1251. /* Cannot have more than one IPv4 interface */
  1252. ql4_printk(KERN_ERR, ha, "Invalid IPv4 iface "
  1253. "number = %d\n",
  1254. iface_param->iface_num);
  1255. break;
  1256. }
  1257. break;
  1258. case ISCSI_IFACE_TYPE_IPV6:
  1259. switch (iface_param->iface_num) {
  1260. case 0:
  1261. case 1:
  1262. qla4xxx_set_ipv6(ha, iface_param, init_fw_cb);
  1263. break;
  1264. default:
  1265. /* Cannot have more than two IPv6 interface */
  1266. ql4_printk(KERN_ERR, ha, "Invalid IPv6 iface "
  1267. "number = %d\n",
  1268. iface_param->iface_num);
  1269. break;
  1270. }
  1271. break;
  1272. default:
  1273. ql4_printk(KERN_ERR, ha, "Invalid iface type\n");
  1274. break;
  1275. }
  1276. }
  1277. init_fw_cb->cookie = cpu_to_le32(0x11BEAD5A);
  1278. rval = qla4xxx_set_flash(ha, init_fw_cb_dma, FLASH_SEGMENT_IFCB,
  1279. sizeof(struct addr_ctrl_blk),
  1280. FLASH_OPT_RMW_COMMIT);
  1281. if (rval != QLA_SUCCESS) {
  1282. ql4_printk(KERN_ERR, ha, "%s: set flash mbx failed\n",
  1283. __func__);
  1284. rval = -EIO;
  1285. goto exit_init_fw_cb;
  1286. }
  1287. rval = qla4xxx_disable_acb(ha);
  1288. if (rval != QLA_SUCCESS) {
  1289. ql4_printk(KERN_ERR, ha, "%s: disable acb mbx failed\n",
  1290. __func__);
  1291. rval = -EIO;
  1292. goto exit_init_fw_cb;
  1293. }
  1294. wait_for_completion_timeout(&ha->disable_acb_comp,
  1295. DISABLE_ACB_TOV * HZ);
  1296. qla4xxx_initcb_to_acb(init_fw_cb);
  1297. rval = qla4xxx_set_acb(ha, &mbox_cmd[0], &mbox_sts[0], init_fw_cb_dma);
  1298. if (rval != QLA_SUCCESS) {
  1299. ql4_printk(KERN_ERR, ha, "%s: set acb mbx failed\n",
  1300. __func__);
  1301. rval = -EIO;
  1302. goto exit_init_fw_cb;
  1303. }
  1304. memset(init_fw_cb, 0, sizeof(struct addr_ctrl_blk));
  1305. qla4xxx_update_local_ifcb(ha, &mbox_cmd[0], &mbox_sts[0], init_fw_cb,
  1306. init_fw_cb_dma);
  1307. exit_init_fw_cb:
  1308. dma_free_coherent(&ha->pdev->dev, sizeof(struct addr_ctrl_blk),
  1309. init_fw_cb, init_fw_cb_dma);
  1310. return rval;
  1311. }
  1312. static int qla4xxx_session_get_param(struct iscsi_cls_session *cls_sess,
  1313. enum iscsi_param param, char *buf)
  1314. {
  1315. struct iscsi_session *sess = cls_sess->dd_data;
  1316. struct ddb_entry *ddb_entry = sess->dd_data;
  1317. struct scsi_qla_host *ha = ddb_entry->ha;
  1318. int rval, len;
  1319. uint16_t idx;
  1320. switch (param) {
  1321. case ISCSI_PARAM_CHAP_IN_IDX:
  1322. rval = qla4xxx_get_chap_index(ha, sess->username_in,
  1323. sess->password_in, BIDI_CHAP,
  1324. &idx);
  1325. if (rval)
  1326. len = sprintf(buf, "\n");
  1327. else
  1328. len = sprintf(buf, "%hu\n", idx);
  1329. break;
  1330. case ISCSI_PARAM_CHAP_OUT_IDX:
  1331. rval = qla4xxx_get_chap_index(ha, sess->username,
  1332. sess->password, LOCAL_CHAP,
  1333. &idx);
  1334. if (rval)
  1335. len = sprintf(buf, "\n");
  1336. else
  1337. len = sprintf(buf, "%hu\n", idx);
  1338. break;
  1339. default:
  1340. return iscsi_session_get_param(cls_sess, param, buf);
  1341. }
  1342. return len;
  1343. }
  1344. static int qla4xxx_conn_get_param(struct iscsi_cls_conn *cls_conn,
  1345. enum iscsi_param param, char *buf)
  1346. {
  1347. struct iscsi_conn *conn;
  1348. struct qla_conn *qla_conn;
  1349. struct sockaddr *dst_addr;
  1350. int len = 0;
  1351. conn = cls_conn->dd_data;
  1352. qla_conn = conn->dd_data;
  1353. dst_addr = (struct sockaddr *)&qla_conn->qla_ep->dst_addr;
  1354. switch (param) {
  1355. case ISCSI_PARAM_CONN_PORT:
  1356. case ISCSI_PARAM_CONN_ADDRESS:
  1357. return iscsi_conn_get_addr_param((struct sockaddr_storage *)
  1358. dst_addr, param, buf);
  1359. default:
  1360. return iscsi_conn_get_param(cls_conn, param, buf);
  1361. }
  1362. return len;
  1363. }
  1364. int qla4xxx_get_ddb_index(struct scsi_qla_host *ha, uint16_t *ddb_index)
  1365. {
  1366. uint32_t mbx_sts = 0;
  1367. uint16_t tmp_ddb_index;
  1368. int ret;
  1369. get_ddb_index:
  1370. tmp_ddb_index = find_first_zero_bit(ha->ddb_idx_map, MAX_DDB_ENTRIES);
  1371. if (tmp_ddb_index >= MAX_DDB_ENTRIES) {
  1372. DEBUG2(ql4_printk(KERN_INFO, ha,
  1373. "Free DDB index not available\n"));
  1374. ret = QLA_ERROR;
  1375. goto exit_get_ddb_index;
  1376. }
  1377. if (test_and_set_bit(tmp_ddb_index, ha->ddb_idx_map))
  1378. goto get_ddb_index;
  1379. DEBUG2(ql4_printk(KERN_INFO, ha,
  1380. "Found a free DDB index at %d\n", tmp_ddb_index));
  1381. ret = qla4xxx_req_ddb_entry(ha, tmp_ddb_index, &mbx_sts);
  1382. if (ret == QLA_ERROR) {
  1383. if (mbx_sts == MBOX_STS_COMMAND_ERROR) {
  1384. ql4_printk(KERN_INFO, ha,
  1385. "DDB index = %d not available trying next\n",
  1386. tmp_ddb_index);
  1387. goto get_ddb_index;
  1388. }
  1389. DEBUG2(ql4_printk(KERN_INFO, ha,
  1390. "Free FW DDB not available\n"));
  1391. }
  1392. *ddb_index = tmp_ddb_index;
  1393. exit_get_ddb_index:
  1394. return ret;
  1395. }
  1396. static int qla4xxx_match_ipaddress(struct scsi_qla_host *ha,
  1397. struct ddb_entry *ddb_entry,
  1398. char *existing_ipaddr,
  1399. char *user_ipaddr)
  1400. {
  1401. uint8_t dst_ipaddr[IPv6_ADDR_LEN];
  1402. char formatted_ipaddr[DDB_IPADDR_LEN];
  1403. int status = QLA_SUCCESS, ret = 0;
  1404. if (ddb_entry->fw_ddb_entry.options & DDB_OPT_IPV6_DEVICE) {
  1405. ret = in6_pton(user_ipaddr, strlen(user_ipaddr), dst_ipaddr,
  1406. '\0', NULL);
  1407. if (ret == 0) {
  1408. status = QLA_ERROR;
  1409. goto out_match;
  1410. }
  1411. ret = sprintf(formatted_ipaddr, "%pI6", dst_ipaddr);
  1412. } else {
  1413. ret = in4_pton(user_ipaddr, strlen(user_ipaddr), dst_ipaddr,
  1414. '\0', NULL);
  1415. if (ret == 0) {
  1416. status = QLA_ERROR;
  1417. goto out_match;
  1418. }
  1419. ret = sprintf(formatted_ipaddr, "%pI4", dst_ipaddr);
  1420. }
  1421. if (strcmp(existing_ipaddr, formatted_ipaddr))
  1422. status = QLA_ERROR;
  1423. out_match:
  1424. return status;
  1425. }
  1426. static int qla4xxx_match_fwdb_session(struct scsi_qla_host *ha,
  1427. struct iscsi_cls_conn *cls_conn)
  1428. {
  1429. int idx = 0, max_ddbs, rval;
  1430. struct iscsi_cls_session *cls_sess = iscsi_conn_to_session(cls_conn);
  1431. struct iscsi_session *sess, *existing_sess;
  1432. struct iscsi_conn *conn, *existing_conn;
  1433. struct ddb_entry *ddb_entry;
  1434. sess = cls_sess->dd_data;
  1435. conn = cls_conn->dd_data;
  1436. if (sess->targetname == NULL ||
  1437. conn->persistent_address == NULL ||
  1438. conn->persistent_port == 0)
  1439. return QLA_ERROR;
  1440. max_ddbs = is_qla40XX(ha) ? MAX_DEV_DB_ENTRIES_40XX :
  1441. MAX_DEV_DB_ENTRIES;
  1442. for (idx = 0; idx < max_ddbs; idx++) {
  1443. ddb_entry = qla4xxx_lookup_ddb_by_fw_index(ha, idx);
  1444. if (ddb_entry == NULL)
  1445. continue;
  1446. if (ddb_entry->ddb_type != FLASH_DDB)
  1447. continue;
  1448. existing_sess = ddb_entry->sess->dd_data;
  1449. existing_conn = ddb_entry->conn->dd_data;
  1450. if (existing_sess->targetname == NULL ||
  1451. existing_conn->persistent_address == NULL ||
  1452. existing_conn->persistent_port == 0)
  1453. continue;
  1454. DEBUG2(ql4_printk(KERN_INFO, ha,
  1455. "IQN = %s User IQN = %s\n",
  1456. existing_sess->targetname,
  1457. sess->targetname));
  1458. DEBUG2(ql4_printk(KERN_INFO, ha,
  1459. "IP = %s User IP = %s\n",
  1460. existing_conn->persistent_address,
  1461. conn->persistent_address));
  1462. DEBUG2(ql4_printk(KERN_INFO, ha,
  1463. "Port = %d User Port = %d\n",
  1464. existing_conn->persistent_port,
  1465. conn->persistent_port));
  1466. if (strcmp(existing_sess->targetname, sess->targetname))
  1467. continue;
  1468. rval = qla4xxx_match_ipaddress(ha, ddb_entry,
  1469. existing_conn->persistent_address,
  1470. conn->persistent_address);
  1471. if (rval == QLA_ERROR)
  1472. continue;
  1473. if (existing_conn->persistent_port != conn->persistent_port)
  1474. continue;
  1475. break;
  1476. }
  1477. if (idx == max_ddbs)
  1478. return QLA_ERROR;
  1479. DEBUG2(ql4_printk(KERN_INFO, ha,
  1480. "Match found in fwdb sessions\n"));
  1481. return QLA_SUCCESS;
  1482. }
  1483. static struct iscsi_cls_session *
  1484. qla4xxx_session_create(struct iscsi_endpoint *ep,
  1485. uint16_t cmds_max, uint16_t qdepth,
  1486. uint32_t initial_cmdsn)
  1487. {
  1488. struct iscsi_cls_session *cls_sess;
  1489. struct scsi_qla_host *ha;
  1490. struct qla_endpoint *qla_ep;
  1491. struct ddb_entry *ddb_entry;
  1492. uint16_t ddb_index;
  1493. struct iscsi_session *sess;
  1494. struct sockaddr *dst_addr;
  1495. int ret;
  1496. DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
  1497. if (!ep) {
  1498. printk(KERN_ERR "qla4xxx: missing ep.\n");
  1499. return NULL;
  1500. }
  1501. qla_ep = ep->dd_data;
  1502. dst_addr = (struct sockaddr *)&qla_ep->dst_addr;
  1503. ha = to_qla_host(qla_ep->host);
  1504. ret = qla4xxx_get_ddb_index(ha, &ddb_index);
  1505. if (ret == QLA_ERROR)
  1506. return NULL;
  1507. cls_sess = iscsi_session_setup(&qla4xxx_iscsi_transport, qla_ep->host,
  1508. cmds_max, sizeof(struct ddb_entry),
  1509. sizeof(struct ql4_task_data),
  1510. initial_cmdsn, ddb_index);
  1511. if (!cls_sess)
  1512. return NULL;
  1513. sess = cls_sess->dd_data;
  1514. ddb_entry = sess->dd_data;
  1515. ddb_entry->fw_ddb_index = ddb_index;
  1516. ddb_entry->fw_ddb_device_state = DDB_DS_NO_CONNECTION_ACTIVE;
  1517. ddb_entry->ha = ha;
  1518. ddb_entry->sess = cls_sess;
  1519. ddb_entry->unblock_sess = qla4xxx_unblock_ddb;
  1520. ddb_entry->ddb_change = qla4xxx_ddb_change;
  1521. cls_sess->recovery_tmo = ql4xsess_recovery_tmo;
  1522. ha->fw_ddb_index_map[ddb_entry->fw_ddb_index] = ddb_entry;
  1523. ha->tot_ddbs++;
  1524. return cls_sess;
  1525. }
  1526. static void qla4xxx_session_destroy(struct iscsi_cls_session *cls_sess)
  1527. {
  1528. struct iscsi_session *sess;
  1529. struct ddb_entry *ddb_entry;
  1530. struct scsi_qla_host *ha;
  1531. unsigned long flags, wtime;
  1532. struct dev_db_entry *fw_ddb_entry = NULL;
  1533. dma_addr_t fw_ddb_entry_dma;
  1534. uint32_t ddb_state;
  1535. int ret;
  1536. DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
  1537. sess = cls_sess->dd_data;
  1538. ddb_entry = sess->dd_data;
  1539. ha = ddb_entry->ha;
  1540. fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
  1541. &fw_ddb_entry_dma, GFP_KERNEL);
  1542. if (!fw_ddb_entry) {
  1543. ql4_printk(KERN_ERR, ha,
  1544. "%s: Unable to allocate dma buffer\n", __func__);
  1545. goto destroy_session;
  1546. }
  1547. wtime = jiffies + (HZ * LOGOUT_TOV);
  1548. do {
  1549. ret = qla4xxx_get_fwddb_entry(ha, ddb_entry->fw_ddb_index,
  1550. fw_ddb_entry, fw_ddb_entry_dma,
  1551. NULL, NULL, &ddb_state, NULL,
  1552. NULL, NULL);
  1553. if (ret == QLA_ERROR)
  1554. goto destroy_session;
  1555. if ((ddb_state == DDB_DS_NO_CONNECTION_ACTIVE) ||
  1556. (ddb_state == DDB_DS_SESSION_FAILED))
  1557. goto destroy_session;
  1558. schedule_timeout_uninterruptible(HZ);
  1559. } while ((time_after(wtime, jiffies)));
  1560. destroy_session:
  1561. qla4xxx_clear_ddb_entry(ha, ddb_entry->fw_ddb_index);
  1562. spin_lock_irqsave(&ha->hardware_lock, flags);
  1563. qla4xxx_free_ddb(ha, ddb_entry);
  1564. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  1565. iscsi_session_teardown(cls_sess);
  1566. if (fw_ddb_entry)
  1567. dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
  1568. fw_ddb_entry, fw_ddb_entry_dma);
  1569. }
  1570. static struct iscsi_cls_conn *
  1571. qla4xxx_conn_create(struct iscsi_cls_session *cls_sess, uint32_t conn_idx)
  1572. {
  1573. struct iscsi_cls_conn *cls_conn;
  1574. struct iscsi_session *sess;
  1575. struct ddb_entry *ddb_entry;
  1576. DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
  1577. cls_conn = iscsi_conn_setup(cls_sess, sizeof(struct qla_conn),
  1578. conn_idx);
  1579. if (!cls_conn)
  1580. return NULL;
  1581. sess = cls_sess->dd_data;
  1582. ddb_entry = sess->dd_data;
  1583. ddb_entry->conn = cls_conn;
  1584. return cls_conn;
  1585. }
  1586. static int qla4xxx_conn_bind(struct iscsi_cls_session *cls_session,
  1587. struct iscsi_cls_conn *cls_conn,
  1588. uint64_t transport_fd, int is_leading)
  1589. {
  1590. struct iscsi_conn *conn;
  1591. struct qla_conn *qla_conn;
  1592. struct iscsi_endpoint *ep;
  1593. DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
  1594. if (iscsi_conn_bind(cls_session, cls_conn, is_leading))
  1595. return -EINVAL;
  1596. ep = iscsi_lookup_endpoint(transport_fd);
  1597. conn = cls_conn->dd_data;
  1598. qla_conn = conn->dd_data;
  1599. qla_conn->qla_ep = ep->dd_data;
  1600. return 0;
  1601. }
  1602. static int qla4xxx_conn_start(struct iscsi_cls_conn *cls_conn)
  1603. {
  1604. struct iscsi_cls_session *cls_sess = iscsi_conn_to_session(cls_conn);
  1605. struct iscsi_session *sess;
  1606. struct ddb_entry *ddb_entry;
  1607. struct scsi_qla_host *ha;
  1608. struct dev_db_entry *fw_ddb_entry = NULL;
  1609. dma_addr_t fw_ddb_entry_dma;
  1610. uint32_t mbx_sts = 0;
  1611. int ret = 0;
  1612. int status = QLA_SUCCESS;
  1613. DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
  1614. sess = cls_sess->dd_data;
  1615. ddb_entry = sess->dd_data;
  1616. ha = ddb_entry->ha;
  1617. /* Check if we have matching FW DDB, if yes then do not
  1618. * login to this target. This could cause target to logout previous
  1619. * connection
  1620. */
  1621. ret = qla4xxx_match_fwdb_session(ha, cls_conn);
  1622. if (ret == QLA_SUCCESS) {
  1623. ql4_printk(KERN_INFO, ha,
  1624. "Session already exist in FW.\n");
  1625. ret = -EEXIST;
  1626. goto exit_conn_start;
  1627. }
  1628. fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
  1629. &fw_ddb_entry_dma, GFP_KERNEL);
  1630. if (!fw_ddb_entry) {
  1631. ql4_printk(KERN_ERR, ha,
  1632. "%s: Unable to allocate dma buffer\n", __func__);
  1633. ret = -ENOMEM;
  1634. goto exit_conn_start;
  1635. }
  1636. ret = qla4xxx_set_param_ddbentry(ha, ddb_entry, cls_conn, &mbx_sts);
  1637. if (ret) {
  1638. /* If iscsid is stopped and started then no need to do
  1639. * set param again since ddb state will be already
  1640. * active and FW does not allow set ddb to an
  1641. * active session.
  1642. */
  1643. if (mbx_sts)
  1644. if (ddb_entry->fw_ddb_device_state ==
  1645. DDB_DS_SESSION_ACTIVE) {
  1646. ddb_entry->unblock_sess(ddb_entry->sess);
  1647. goto exit_set_param;
  1648. }
  1649. ql4_printk(KERN_ERR, ha, "%s: Failed set param for index[%d]\n",
  1650. __func__, ddb_entry->fw_ddb_index);
  1651. goto exit_conn_start;
  1652. }
  1653. status = qla4xxx_conn_open(ha, ddb_entry->fw_ddb_index);
  1654. if (status == QLA_ERROR) {
  1655. ql4_printk(KERN_ERR, ha, "%s: Login failed: %s\n", __func__,
  1656. sess->targetname);
  1657. ret = -EINVAL;
  1658. goto exit_conn_start;
  1659. }
  1660. if (ddb_entry->fw_ddb_device_state == DDB_DS_NO_CONNECTION_ACTIVE)
  1661. ddb_entry->fw_ddb_device_state = DDB_DS_LOGIN_IN_PROCESS;
  1662. DEBUG2(printk(KERN_INFO "%s: DDB state [%d]\n", __func__,
  1663. ddb_entry->fw_ddb_device_state));
  1664. exit_set_param:
  1665. ret = 0;
  1666. exit_conn_start:
  1667. if (fw_ddb_entry)
  1668. dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
  1669. fw_ddb_entry, fw_ddb_entry_dma);
  1670. return ret;
  1671. }
  1672. static void qla4xxx_conn_destroy(struct iscsi_cls_conn *cls_conn)
  1673. {
  1674. struct iscsi_cls_session *cls_sess = iscsi_conn_to_session(cls_conn);
  1675. struct iscsi_session *sess;
  1676. struct scsi_qla_host *ha;
  1677. struct ddb_entry *ddb_entry;
  1678. int options;
  1679. DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
  1680. sess = cls_sess->dd_data;
  1681. ddb_entry = sess->dd_data;
  1682. ha = ddb_entry->ha;
  1683. options = LOGOUT_OPTION_CLOSE_SESSION;
  1684. if (qla4xxx_session_logout_ddb(ha, ddb_entry, options) == QLA_ERROR)
  1685. ql4_printk(KERN_ERR, ha, "%s: Logout failed\n", __func__);
  1686. }
  1687. static void qla4xxx_task_work(struct work_struct *wdata)
  1688. {
  1689. struct ql4_task_data *task_data;
  1690. struct scsi_qla_host *ha;
  1691. struct passthru_status *sts;
  1692. struct iscsi_task *task;
  1693. struct iscsi_hdr *hdr;
  1694. uint8_t *data;
  1695. uint32_t data_len;
  1696. struct iscsi_conn *conn;
  1697. int hdr_len;
  1698. itt_t itt;
  1699. task_data = container_of(wdata, struct ql4_task_data, task_work);
  1700. ha = task_data->ha;
  1701. task = task_data->task;
  1702. sts = &task_data->sts;
  1703. hdr_len = sizeof(struct iscsi_hdr);
  1704. DEBUG3(printk(KERN_INFO "Status returned\n"));
  1705. DEBUG3(qla4xxx_dump_buffer(sts, 64));
  1706. DEBUG3(printk(KERN_INFO "Response buffer"));
  1707. DEBUG3(qla4xxx_dump_buffer(task_data->resp_buffer, 64));
  1708. conn = task->conn;
  1709. switch (sts->completionStatus) {
  1710. case PASSTHRU_STATUS_COMPLETE:
  1711. hdr = (struct iscsi_hdr *)task_data->resp_buffer;
  1712. /* Assign back the itt in hdr, until we use the PREASSIGN_TAG */
  1713. itt = sts->handle;
  1714. hdr->itt = itt;
  1715. data = task_data->resp_buffer + hdr_len;
  1716. data_len = task_data->resp_len - hdr_len;
  1717. iscsi_complete_pdu(conn, hdr, data, data_len);
  1718. break;
  1719. default:
  1720. ql4_printk(KERN_ERR, ha, "Passthru failed status = 0x%x\n",
  1721. sts->completionStatus);
  1722. break;
  1723. }
  1724. return;
  1725. }
  1726. static int qla4xxx_alloc_pdu(struct iscsi_task *task, uint8_t opcode)
  1727. {
  1728. struct ql4_task_data *task_data;
  1729. struct iscsi_session *sess;
  1730. struct ddb_entry *ddb_entry;
  1731. struct scsi_qla_host *ha;
  1732. int hdr_len;
  1733. sess = task->conn->session;
  1734. ddb_entry = sess->dd_data;
  1735. ha = ddb_entry->ha;
  1736. task_data = task->dd_data;
  1737. memset(task_data, 0, sizeof(struct ql4_task_data));
  1738. if (task->sc) {
  1739. ql4_printk(KERN_INFO, ha,
  1740. "%s: SCSI Commands not implemented\n", __func__);
  1741. return -EINVAL;
  1742. }
  1743. hdr_len = sizeof(struct iscsi_hdr);
  1744. task_data->ha = ha;
  1745. task_data->task = task;
  1746. if (task->data_count) {
  1747. task_data->data_dma = dma_map_single(&ha->pdev->dev, task->data,
  1748. task->data_count,
  1749. PCI_DMA_TODEVICE);
  1750. }
  1751. DEBUG2(ql4_printk(KERN_INFO, ha, "%s: MaxRecvLen %u, iscsi hrd %d\n",
  1752. __func__, task->conn->max_recv_dlength, hdr_len));
  1753. task_data->resp_len = task->conn->max_recv_dlength + hdr_len;
  1754. task_data->resp_buffer = dma_alloc_coherent(&ha->pdev->dev,
  1755. task_data->resp_len,
  1756. &task_data->resp_dma,
  1757. GFP_ATOMIC);
  1758. if (!task_data->resp_buffer)
  1759. goto exit_alloc_pdu;
  1760. task_data->req_len = task->data_count + hdr_len;
  1761. task_data->req_buffer = dma_alloc_coherent(&ha->pdev->dev,
  1762. task_data->req_len,
  1763. &task_data->req_dma,
  1764. GFP_ATOMIC);
  1765. if (!task_data->req_buffer)
  1766. goto exit_alloc_pdu;
  1767. task->hdr = task_data->req_buffer;
  1768. INIT_WORK(&task_data->task_work, qla4xxx_task_work);
  1769. return 0;
  1770. exit_alloc_pdu:
  1771. if (task_data->resp_buffer)
  1772. dma_free_coherent(&ha->pdev->dev, task_data->resp_len,
  1773. task_data->resp_buffer, task_data->resp_dma);
  1774. if (task_data->req_buffer)
  1775. dma_free_coherent(&ha->pdev->dev, task_data->req_len,
  1776. task_data->req_buffer, task_data->req_dma);
  1777. return -ENOMEM;
  1778. }
  1779. static void qla4xxx_task_cleanup(struct iscsi_task *task)
  1780. {
  1781. struct ql4_task_data *task_data;
  1782. struct iscsi_session *sess;
  1783. struct ddb_entry *ddb_entry;
  1784. struct scsi_qla_host *ha;
  1785. int hdr_len;
  1786. hdr_len = sizeof(struct iscsi_hdr);
  1787. sess = task->conn->session;
  1788. ddb_entry = sess->dd_data;
  1789. ha = ddb_entry->ha;
  1790. task_data = task->dd_data;
  1791. if (task->data_count) {
  1792. dma_unmap_single(&ha->pdev->dev, task_data->data_dma,
  1793. task->data_count, PCI_DMA_TODEVICE);
  1794. }
  1795. DEBUG2(ql4_printk(KERN_INFO, ha, "%s: MaxRecvLen %u, iscsi hrd %d\n",
  1796. __func__, task->conn->max_recv_dlength, hdr_len));
  1797. dma_free_coherent(&ha->pdev->dev, task_data->resp_len,
  1798. task_data->resp_buffer, task_data->resp_dma);
  1799. dma_free_coherent(&ha->pdev->dev, task_data->req_len,
  1800. task_data->req_buffer, task_data->req_dma);
  1801. return;
  1802. }
  1803. static int qla4xxx_task_xmit(struct iscsi_task *task)
  1804. {
  1805. struct scsi_cmnd *sc = task->sc;
  1806. struct iscsi_session *sess = task->conn->session;
  1807. struct ddb_entry *ddb_entry = sess->dd_data;
  1808. struct scsi_qla_host *ha = ddb_entry->ha;
  1809. if (!sc)
  1810. return qla4xxx_send_passthru0(task);
  1811. ql4_printk(KERN_INFO, ha, "%s: scsi cmd xmit not implemented\n",
  1812. __func__);
  1813. return -ENOSYS;
  1814. }
  1815. static int qla4xxx_copy_from_fwddb_param(struct iscsi_bus_flash_session *sess,
  1816. struct iscsi_bus_flash_conn *conn,
  1817. struct dev_db_entry *fw_ddb_entry)
  1818. {
  1819. unsigned long options = 0;
  1820. int rc = 0;
  1821. options = le16_to_cpu(fw_ddb_entry->options);
  1822. conn->is_fw_assigned_ipv6 = test_bit(OPT_IS_FW_ASSIGNED_IPV6, &options);
  1823. if (test_bit(OPT_IPV6_DEVICE, &options)) {
  1824. rc = iscsi_switch_str_param(&sess->portal_type,
  1825. PORTAL_TYPE_IPV6);
  1826. if (rc)
  1827. goto exit_copy;
  1828. } else {
  1829. rc = iscsi_switch_str_param(&sess->portal_type,
  1830. PORTAL_TYPE_IPV4);
  1831. if (rc)
  1832. goto exit_copy;
  1833. }
  1834. sess->auto_snd_tgt_disable = test_bit(OPT_AUTO_SENDTGTS_DISABLE,
  1835. &options);
  1836. sess->discovery_sess = test_bit(OPT_DISC_SESSION, &options);
  1837. sess->entry_state = test_bit(OPT_ENTRY_STATE, &options);
  1838. options = le16_to_cpu(fw_ddb_entry->iscsi_options);
  1839. conn->hdrdgst_en = test_bit(ISCSIOPT_HEADER_DIGEST_EN, &options);
  1840. conn->datadgst_en = test_bit(ISCSIOPT_DATA_DIGEST_EN, &options);
  1841. sess->imm_data_en = test_bit(ISCSIOPT_IMMEDIATE_DATA_EN, &options);
  1842. sess->initial_r2t_en = test_bit(ISCSIOPT_INITIAL_R2T_EN, &options);
  1843. sess->dataseq_inorder_en = test_bit(ISCSIOPT_DATA_SEQ_IN_ORDER,
  1844. &options);
  1845. sess->pdu_inorder_en = test_bit(ISCSIOPT_DATA_PDU_IN_ORDER, &options);
  1846. sess->chap_auth_en = test_bit(ISCSIOPT_CHAP_AUTH_EN, &options);
  1847. conn->snack_req_en = test_bit(ISCSIOPT_SNACK_REQ_EN, &options);
  1848. sess->discovery_logout_en = test_bit(ISCSIOPT_DISCOVERY_LOGOUT_EN,
  1849. &options);
  1850. sess->bidi_chap_en = test_bit(ISCSIOPT_BIDI_CHAP_EN, &options);
  1851. sess->discovery_auth_optional =
  1852. test_bit(ISCSIOPT_DISCOVERY_AUTH_OPTIONAL, &options);
  1853. if (test_bit(ISCSIOPT_ERL1, &options))
  1854. sess->erl |= BIT_1;
  1855. if (test_bit(ISCSIOPT_ERL0, &options))
  1856. sess->erl |= BIT_0;
  1857. options = le16_to_cpu(fw_ddb_entry->tcp_options);
  1858. conn->tcp_timestamp_stat = test_bit(TCPOPT_TIMESTAMP_STAT, &options);
  1859. conn->tcp_nagle_disable = test_bit(TCPOPT_NAGLE_DISABLE, &options);
  1860. conn->tcp_wsf_disable = test_bit(TCPOPT_WSF_DISABLE, &options);
  1861. if (test_bit(TCPOPT_TIMER_SCALE3, &options))
  1862. conn->tcp_timer_scale |= BIT_3;
  1863. if (test_bit(TCPOPT_TIMER_SCALE2, &options))
  1864. conn->tcp_timer_scale |= BIT_2;
  1865. if (test_bit(TCPOPT_TIMER_SCALE1, &options))
  1866. conn->tcp_timer_scale |= BIT_1;
  1867. conn->tcp_timer_scale >>= 1;
  1868. conn->tcp_timestamp_en = test_bit(TCPOPT_TIMESTAMP_EN, &options);
  1869. options = le16_to_cpu(fw_ddb_entry->ip_options);
  1870. conn->fragment_disable = test_bit(IPOPT_FRAGMENT_DISABLE, &options);
  1871. conn->max_recv_dlength = BYTE_UNITS *
  1872. le16_to_cpu(fw_ddb_entry->iscsi_max_rcv_data_seg_len);
  1873. conn->max_xmit_dlength = BYTE_UNITS *
  1874. le16_to_cpu(fw_ddb_entry->iscsi_max_snd_data_seg_len);
  1875. sess->first_burst = BYTE_UNITS *
  1876. le16_to_cpu(fw_ddb_entry->iscsi_first_burst_len);
  1877. sess->max_burst = BYTE_UNITS *
  1878. le16_to_cpu(fw_ddb_entry->iscsi_max_burst_len);
  1879. sess->max_r2t = le16_to_cpu(fw_ddb_entry->iscsi_max_outsnd_r2t);
  1880. sess->time2wait = le16_to_cpu(fw_ddb_entry->iscsi_def_time2wait);
  1881. sess->time2retain = le16_to_cpu(fw_ddb_entry->iscsi_def_time2retain);
  1882. sess->tpgt = le32_to_cpu(fw_ddb_entry->tgt_portal_grp);
  1883. conn->max_segment_size = le16_to_cpu(fw_ddb_entry->mss);
  1884. conn->tcp_xmit_wsf = fw_ddb_entry->tcp_xmt_wsf;
  1885. conn->tcp_recv_wsf = fw_ddb_entry->tcp_rcv_wsf;
  1886. conn->ipv6_flow_label = le16_to_cpu(fw_ddb_entry->ipv6_flow_lbl);
  1887. conn->keepalive_timeout = le16_to_cpu(fw_ddb_entry->ka_timeout);
  1888. conn->local_port = le16_to_cpu(fw_ddb_entry->lcl_port);
  1889. conn->statsn = le32_to_cpu(fw_ddb_entry->stat_sn);
  1890. conn->exp_statsn = le32_to_cpu(fw_ddb_entry->exp_stat_sn);
  1891. sess->discovery_parent_idx = le16_to_cpu(fw_ddb_entry->ddb_link);
  1892. sess->discovery_parent_type = le16_to_cpu(fw_ddb_entry->ddb_link);
  1893. sess->chap_out_idx = le16_to_cpu(fw_ddb_entry->chap_tbl_idx);
  1894. sess->tsid = le16_to_cpu(fw_ddb_entry->tsid);
  1895. sess->default_taskmgmt_timeout =
  1896. le16_to_cpu(fw_ddb_entry->def_timeout);
  1897. conn->port = le16_to_cpu(fw_ddb_entry->port);
  1898. options = le16_to_cpu(fw_ddb_entry->options);
  1899. conn->ipaddress = kzalloc(IPv6_ADDR_LEN, GFP_KERNEL);
  1900. if (!conn->ipaddress) {
  1901. rc = -ENOMEM;
  1902. goto exit_copy;
  1903. }
  1904. conn->redirect_ipaddr = kzalloc(IPv6_ADDR_LEN, GFP_KERNEL);
  1905. if (!conn->redirect_ipaddr) {
  1906. rc = -ENOMEM;
  1907. goto exit_copy;
  1908. }
  1909. memcpy(conn->ipaddress, fw_ddb_entry->ip_addr, IPv6_ADDR_LEN);
  1910. memcpy(conn->redirect_ipaddr, fw_ddb_entry->tgt_addr, IPv6_ADDR_LEN);
  1911. if (test_bit(OPT_IPV6_DEVICE, &options)) {
  1912. conn->ipv6_traffic_class = fw_ddb_entry->ipv4_tos;
  1913. conn->link_local_ipv6_addr = kzalloc(IPv6_ADDR_LEN, GFP_KERNEL);
  1914. if (!conn->link_local_ipv6_addr) {
  1915. rc = -ENOMEM;
  1916. goto exit_copy;
  1917. }
  1918. memcpy(conn->link_local_ipv6_addr,
  1919. fw_ddb_entry->link_local_ipv6_addr, IPv6_ADDR_LEN);
  1920. } else {
  1921. conn->ipv4_tos = fw_ddb_entry->ipv4_tos;
  1922. }
  1923. if (fw_ddb_entry->iscsi_name[0]) {
  1924. rc = iscsi_switch_str_param(&sess->targetname,
  1925. (char *)fw_ddb_entry->iscsi_name);
  1926. if (rc)
  1927. goto exit_copy;
  1928. }
  1929. if (fw_ddb_entry->iscsi_alias[0]) {
  1930. rc = iscsi_switch_str_param(&sess->targetalias,
  1931. (char *)fw_ddb_entry->iscsi_alias);
  1932. if (rc)
  1933. goto exit_copy;
  1934. }
  1935. COPY_ISID(sess->isid, fw_ddb_entry->isid);
  1936. exit_copy:
  1937. return rc;
  1938. }
  1939. static int qla4xxx_copy_to_fwddb_param(struct iscsi_bus_flash_session *sess,
  1940. struct iscsi_bus_flash_conn *conn,
  1941. struct dev_db_entry *fw_ddb_entry)
  1942. {
  1943. uint16_t options;
  1944. int rc = 0;
  1945. options = le16_to_cpu(fw_ddb_entry->options);
  1946. SET_BITVAL(conn->is_fw_assigned_ipv6, options, BIT_11);
  1947. if (!strncmp(sess->portal_type, PORTAL_TYPE_IPV6, 4))
  1948. options |= BIT_8;
  1949. else
  1950. options &= ~BIT_8;
  1951. SET_BITVAL(sess->auto_snd_tgt_disable, options, BIT_6);
  1952. SET_BITVAL(sess->discovery_sess, options, BIT_4);
  1953. SET_BITVAL(sess->entry_state, options, BIT_3);
  1954. fw_ddb_entry->options = cpu_to_le16(options);
  1955. options = le16_to_cpu(fw_ddb_entry->iscsi_options);
  1956. SET_BITVAL(conn->hdrdgst_en, options, BIT_13);
  1957. SET_BITVAL(conn->datadgst_en, options, BIT_12);
  1958. SET_BITVAL(sess->imm_data_en, options, BIT_11);
  1959. SET_BITVAL(sess->initial_r2t_en, options, BIT_10);
  1960. SET_BITVAL(sess->dataseq_inorder_en, options, BIT_9);
  1961. SET_BITVAL(sess->pdu_inorder_en, options, BIT_8);
  1962. SET_BITVAL(sess->chap_auth_en, options, BIT_7);
  1963. SET_BITVAL(conn->snack_req_en, options, BIT_6);
  1964. SET_BITVAL(sess->discovery_logout_en, options, BIT_5);
  1965. SET_BITVAL(sess->bidi_chap_en, options, BIT_4);
  1966. SET_BITVAL(sess->discovery_auth_optional, options, BIT_3);
  1967. SET_BITVAL(sess->erl & BIT_1, options, BIT_1);
  1968. SET_BITVAL(sess->erl & BIT_0, options, BIT_0);
  1969. fw_ddb_entry->iscsi_options = cpu_to_le16(options);
  1970. options = le16_to_cpu(fw_ddb_entry->tcp_options);
  1971. SET_BITVAL(conn->tcp_timestamp_stat, options, BIT_6);
  1972. SET_BITVAL(conn->tcp_nagle_disable, options, BIT_5);
  1973. SET_BITVAL(conn->tcp_wsf_disable, options, BIT_4);
  1974. SET_BITVAL(conn->tcp_timer_scale & BIT_2, options, BIT_3);
  1975. SET_BITVAL(conn->tcp_timer_scale & BIT_1, options, BIT_2);
  1976. SET_BITVAL(conn->tcp_timer_scale & BIT_0, options, BIT_1);
  1977. SET_BITVAL(conn->tcp_timestamp_en, options, BIT_0);
  1978. fw_ddb_entry->tcp_options = cpu_to_le16(options);
  1979. options = le16_to_cpu(fw_ddb_entry->ip_options);
  1980. SET_BITVAL(conn->fragment_disable, options, BIT_4);
  1981. fw_ddb_entry->ip_options = cpu_to_le16(options);
  1982. fw_ddb_entry->iscsi_max_outsnd_r2t = cpu_to_le16(sess->max_r2t);
  1983. fw_ddb_entry->iscsi_max_rcv_data_seg_len =
  1984. cpu_to_le16(conn->max_recv_dlength / BYTE_UNITS);
  1985. fw_ddb_entry->iscsi_max_snd_data_seg_len =
  1986. cpu_to_le16(conn->max_xmit_dlength / BYTE_UNITS);
  1987. fw_ddb_entry->iscsi_first_burst_len =
  1988. cpu_to_le16(sess->first_burst / BYTE_UNITS);
  1989. fw_ddb_entry->iscsi_max_burst_len = cpu_to_le16(sess->max_burst /
  1990. BYTE_UNITS);
  1991. fw_ddb_entry->iscsi_def_time2wait = cpu_to_le16(sess->time2wait);
  1992. fw_ddb_entry->iscsi_def_time2retain = cpu_to_le16(sess->time2retain);
  1993. fw_ddb_entry->tgt_portal_grp = cpu_to_le16(sess->tpgt);
  1994. fw_ddb_entry->mss = cpu_to_le16(conn->max_segment_size);
  1995. fw_ddb_entry->tcp_xmt_wsf = (uint8_t) cpu_to_le32(conn->tcp_xmit_wsf);
  1996. fw_ddb_entry->tcp_rcv_wsf = (uint8_t) cpu_to_le32(conn->tcp_recv_wsf);
  1997. fw_ddb_entry->ipv6_flow_lbl = cpu_to_le16(conn->ipv6_flow_label);
  1998. fw_ddb_entry->ka_timeout = cpu_to_le16(conn->keepalive_timeout);
  1999. fw_ddb_entry->lcl_port = cpu_to_le16(conn->local_port);
  2000. fw_ddb_entry->stat_sn = cpu_to_le32(conn->statsn);
  2001. fw_ddb_entry->exp_stat_sn = cpu_to_le32(conn->exp_statsn);
  2002. fw_ddb_entry->ddb_link = cpu_to_le16(sess->discovery_parent_idx);
  2003. fw_ddb_entry->chap_tbl_idx = cpu_to_le16(sess->chap_out_idx);
  2004. fw_ddb_entry->tsid = cpu_to_le16(sess->tsid);
  2005. fw_ddb_entry->port = cpu_to_le16(conn->port);
  2006. fw_ddb_entry->def_timeout =
  2007. cpu_to_le16(sess->default_taskmgmt_timeout);
  2008. if (!strncmp(sess->portal_type, PORTAL_TYPE_IPV6, 4))
  2009. fw_ddb_entry->ipv4_tos = conn->ipv6_traffic_class;
  2010. else
  2011. fw_ddb_entry->ipv4_tos = conn->ipv4_tos;
  2012. if (conn->ipaddress)
  2013. memcpy(fw_ddb_entry->ip_addr, conn->ipaddress,
  2014. sizeof(fw_ddb_entry->ip_addr));
  2015. if (conn->redirect_ipaddr)
  2016. memcpy(fw_ddb_entry->tgt_addr, conn->redirect_ipaddr,
  2017. sizeof(fw_ddb_entry->tgt_addr));
  2018. if (conn->link_local_ipv6_addr)
  2019. memcpy(fw_ddb_entry->link_local_ipv6_addr,
  2020. conn->link_local_ipv6_addr,
  2021. sizeof(fw_ddb_entry->link_local_ipv6_addr));
  2022. if (sess->targetname)
  2023. memcpy(fw_ddb_entry->iscsi_name, sess->targetname,
  2024. sizeof(fw_ddb_entry->iscsi_name));
  2025. if (sess->targetalias)
  2026. memcpy(fw_ddb_entry->iscsi_alias, sess->targetalias,
  2027. sizeof(fw_ddb_entry->iscsi_alias));
  2028. COPY_ISID(fw_ddb_entry->isid, sess->isid);
  2029. return rc;
  2030. }
  2031. static void qla4xxx_copy_to_sess_conn_params(struct iscsi_conn *conn,
  2032. struct iscsi_session *sess,
  2033. struct dev_db_entry *fw_ddb_entry)
  2034. {
  2035. unsigned long options = 0;
  2036. uint16_t ddb_link;
  2037. uint16_t disc_parent;
  2038. options = le16_to_cpu(fw_ddb_entry->options);
  2039. conn->is_fw_assigned_ipv6 = test_bit(OPT_IS_FW_ASSIGNED_IPV6, &options);
  2040. sess->auto_snd_tgt_disable = test_bit(OPT_AUTO_SENDTGTS_DISABLE,
  2041. &options);
  2042. sess->discovery_sess = test_bit(OPT_DISC_SESSION, &options);
  2043. options = le16_to_cpu(fw_ddb_entry->iscsi_options);
  2044. conn->hdrdgst_en = test_bit(ISCSIOPT_HEADER_DIGEST_EN, &options);
  2045. conn->datadgst_en = test_bit(ISCSIOPT_DATA_DIGEST_EN, &options);
  2046. sess->imm_data_en = test_bit(ISCSIOPT_IMMEDIATE_DATA_EN, &options);
  2047. sess->initial_r2t_en = test_bit(ISCSIOPT_INITIAL_R2T_EN, &options);
  2048. sess->dataseq_inorder_en = test_bit(ISCSIOPT_DATA_SEQ_IN_ORDER,
  2049. &options);
  2050. sess->pdu_inorder_en = test_bit(ISCSIOPT_DATA_PDU_IN_ORDER, &options);
  2051. sess->chap_auth_en = test_bit(ISCSIOPT_CHAP_AUTH_EN, &options);
  2052. sess->discovery_logout_en = test_bit(ISCSIOPT_DISCOVERY_LOGOUT_EN,
  2053. &options);
  2054. sess->bidi_chap_en = test_bit(ISCSIOPT_BIDI_CHAP_EN, &options);
  2055. sess->discovery_auth_optional =
  2056. test_bit(ISCSIOPT_DISCOVERY_AUTH_OPTIONAL, &options);
  2057. if (test_bit(ISCSIOPT_ERL1, &options))
  2058. sess->erl |= BIT_1;
  2059. if (test_bit(ISCSIOPT_ERL0, &options))
  2060. sess->erl |= BIT_0;
  2061. options = le16_to_cpu(fw_ddb_entry->tcp_options);
  2062. conn->tcp_timestamp_stat = test_bit(TCPOPT_TIMESTAMP_STAT, &options);
  2063. conn->tcp_nagle_disable = test_bit(TCPOPT_NAGLE_DISABLE, &options);
  2064. conn->tcp_wsf_disable = test_bit(TCPOPT_WSF_DISABLE, &options);
  2065. if (test_bit(TCPOPT_TIMER_SCALE3, &options))
  2066. conn->tcp_timer_scale |= BIT_3;
  2067. if (test_bit(TCPOPT_TIMER_SCALE2, &options))
  2068. conn->tcp_timer_scale |= BIT_2;
  2069. if (test_bit(TCPOPT_TIMER_SCALE1, &options))
  2070. conn->tcp_timer_scale |= BIT_1;
  2071. conn->tcp_timer_scale >>= 1;
  2072. conn->tcp_timestamp_en = test_bit(TCPOPT_TIMESTAMP_EN, &options);
  2073. options = le16_to_cpu(fw_ddb_entry->ip_options);
  2074. conn->fragment_disable = test_bit(IPOPT_FRAGMENT_DISABLE, &options);
  2075. conn->max_recv_dlength = BYTE_UNITS *
  2076. le16_to_cpu(fw_ddb_entry->iscsi_max_rcv_data_seg_len);
  2077. conn->max_xmit_dlength = BYTE_UNITS *
  2078. le16_to_cpu(fw_ddb_entry->iscsi_max_snd_data_seg_len);
  2079. sess->max_r2t = le16_to_cpu(fw_ddb_entry->iscsi_max_outsnd_r2t);
  2080. sess->first_burst = BYTE_UNITS *
  2081. le16_to_cpu(fw_ddb_entry->iscsi_first_burst_len);
  2082. sess->max_burst = BYTE_UNITS *
  2083. le16_to_cpu(fw_ddb_entry->iscsi_max_burst_len);
  2084. sess->time2wait = le16_to_cpu(fw_ddb_entry->iscsi_def_time2wait);
  2085. sess->time2retain = le16_to_cpu(fw_ddb_entry->iscsi_def_time2retain);
  2086. sess->tpgt = le32_to_cpu(fw_ddb_entry->tgt_portal_grp);
  2087. conn->max_segment_size = le16_to_cpu(fw_ddb_entry->mss);
  2088. conn->tcp_xmit_wsf = fw_ddb_entry->tcp_xmt_wsf;
  2089. conn->tcp_recv_wsf = fw_ddb_entry->tcp_rcv_wsf;
  2090. conn->ipv4_tos = fw_ddb_entry->ipv4_tos;
  2091. conn->keepalive_tmo = le16_to_cpu(fw_ddb_entry->ka_timeout);
  2092. conn->local_port = le16_to_cpu(fw_ddb_entry->lcl_port);
  2093. conn->statsn = le32_to_cpu(fw_ddb_entry->stat_sn);
  2094. conn->exp_statsn = le32_to_cpu(fw_ddb_entry->exp_stat_sn);
  2095. sess->tsid = le16_to_cpu(fw_ddb_entry->tsid);
  2096. COPY_ISID(sess->isid, fw_ddb_entry->isid);
  2097. ddb_link = le16_to_cpu(fw_ddb_entry->ddb_link);
  2098. if (ddb_link < MAX_DDB_ENTRIES)
  2099. sess->discovery_parent_idx = ddb_link;
  2100. else
  2101. sess->discovery_parent_idx = DDB_NO_LINK;
  2102. if (ddb_link == DDB_ISNS)
  2103. disc_parent = ISCSI_DISC_PARENT_ISNS;
  2104. else if (ddb_link == DDB_NO_LINK)
  2105. disc_parent = ISCSI_DISC_PARENT_UNKNOWN;
  2106. else if (ddb_link < MAX_DDB_ENTRIES)
  2107. disc_parent = ISCSI_DISC_PARENT_SENDTGT;
  2108. else
  2109. disc_parent = ISCSI_DISC_PARENT_UNKNOWN;
  2110. iscsi_set_param(conn->cls_conn, ISCSI_PARAM_DISCOVERY_PARENT_TYPE,
  2111. iscsi_get_discovery_parent_name(disc_parent), 0);
  2112. iscsi_set_param(conn->cls_conn, ISCSI_PARAM_TARGET_ALIAS,
  2113. (char *)fw_ddb_entry->iscsi_alias, 0);
  2114. }
  2115. static void qla4xxx_copy_fwddb_param(struct scsi_qla_host *ha,
  2116. struct dev_db_entry *fw_ddb_entry,
  2117. struct iscsi_cls_session *cls_sess,
  2118. struct iscsi_cls_conn *cls_conn)
  2119. {
  2120. int buflen = 0;
  2121. struct iscsi_session *sess;
  2122. struct ddb_entry *ddb_entry;
  2123. struct iscsi_conn *conn;
  2124. char ip_addr[DDB_IPADDR_LEN];
  2125. uint16_t options = 0;
  2126. sess = cls_sess->dd_data;
  2127. ddb_entry = sess->dd_data;
  2128. conn = cls_conn->dd_data;
  2129. ddb_entry->chap_tbl_idx = le16_to_cpu(fw_ddb_entry->chap_tbl_idx);
  2130. qla4xxx_copy_to_sess_conn_params(conn, sess, fw_ddb_entry);
  2131. sess->def_taskmgmt_tmo = le16_to_cpu(fw_ddb_entry->def_timeout);
  2132. conn->persistent_port = le16_to_cpu(fw_ddb_entry->port);
  2133. memset(ip_addr, 0, sizeof(ip_addr));
  2134. options = le16_to_cpu(fw_ddb_entry->options);
  2135. if (options & DDB_OPT_IPV6_DEVICE) {
  2136. iscsi_set_param(cls_conn, ISCSI_PARAM_PORTAL_TYPE, "ipv6", 4);
  2137. memset(ip_addr, 0, sizeof(ip_addr));
  2138. sprintf(ip_addr, "%pI6", fw_ddb_entry->ip_addr);
  2139. } else {
  2140. iscsi_set_param(cls_conn, ISCSI_PARAM_PORTAL_TYPE, "ipv4", 4);
  2141. sprintf(ip_addr, "%pI4", fw_ddb_entry->ip_addr);
  2142. }
  2143. iscsi_set_param(cls_conn, ISCSI_PARAM_PERSISTENT_ADDRESS,
  2144. (char *)ip_addr, buflen);
  2145. iscsi_set_param(cls_conn, ISCSI_PARAM_TARGET_NAME,
  2146. (char *)fw_ddb_entry->iscsi_name, buflen);
  2147. iscsi_set_param(cls_conn, ISCSI_PARAM_INITIATOR_NAME,
  2148. (char *)ha->name_string, buflen);
  2149. }
  2150. void qla4xxx_update_session_conn_fwddb_param(struct scsi_qla_host *ha,
  2151. struct ddb_entry *ddb_entry)
  2152. {
  2153. struct iscsi_cls_session *cls_sess;
  2154. struct iscsi_cls_conn *cls_conn;
  2155. uint32_t ddb_state;
  2156. dma_addr_t fw_ddb_entry_dma;
  2157. struct dev_db_entry *fw_ddb_entry;
  2158. fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
  2159. &fw_ddb_entry_dma, GFP_KERNEL);
  2160. if (!fw_ddb_entry) {
  2161. ql4_printk(KERN_ERR, ha,
  2162. "%s: Unable to allocate dma buffer\n", __func__);
  2163. goto exit_session_conn_fwddb_param;
  2164. }
  2165. if (qla4xxx_get_fwddb_entry(ha, ddb_entry->fw_ddb_index, fw_ddb_entry,
  2166. fw_ddb_entry_dma, NULL, NULL, &ddb_state,
  2167. NULL, NULL, NULL) == QLA_ERROR) {
  2168. DEBUG2(ql4_printk(KERN_ERR, ha, "scsi%ld: %s: failed "
  2169. "get_ddb_entry for fw_ddb_index %d\n",
  2170. ha->host_no, __func__,
  2171. ddb_entry->fw_ddb_index));
  2172. goto exit_session_conn_fwddb_param;
  2173. }
  2174. cls_sess = ddb_entry->sess;
  2175. cls_conn = ddb_entry->conn;
  2176. /* Update params */
  2177. qla4xxx_copy_fwddb_param(ha, fw_ddb_entry, cls_sess, cls_conn);
  2178. exit_session_conn_fwddb_param:
  2179. if (fw_ddb_entry)
  2180. dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
  2181. fw_ddb_entry, fw_ddb_entry_dma);
  2182. }
  2183. void qla4xxx_update_session_conn_param(struct scsi_qla_host *ha,
  2184. struct ddb_entry *ddb_entry)
  2185. {
  2186. struct iscsi_cls_session *cls_sess;
  2187. struct iscsi_cls_conn *cls_conn;
  2188. struct iscsi_session *sess;
  2189. struct iscsi_conn *conn;
  2190. uint32_t ddb_state;
  2191. dma_addr_t fw_ddb_entry_dma;
  2192. struct dev_db_entry *fw_ddb_entry;
  2193. fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
  2194. &fw_ddb_entry_dma, GFP_KERNEL);
  2195. if (!fw_ddb_entry) {
  2196. ql4_printk(KERN_ERR, ha,
  2197. "%s: Unable to allocate dma buffer\n", __func__);
  2198. goto exit_session_conn_param;
  2199. }
  2200. if (qla4xxx_get_fwddb_entry(ha, ddb_entry->fw_ddb_index, fw_ddb_entry,
  2201. fw_ddb_entry_dma, NULL, NULL, &ddb_state,
  2202. NULL, NULL, NULL) == QLA_ERROR) {
  2203. DEBUG2(ql4_printk(KERN_ERR, ha, "scsi%ld: %s: failed "
  2204. "get_ddb_entry for fw_ddb_index %d\n",
  2205. ha->host_no, __func__,
  2206. ddb_entry->fw_ddb_index));
  2207. goto exit_session_conn_param;
  2208. }
  2209. cls_sess = ddb_entry->sess;
  2210. sess = cls_sess->dd_data;
  2211. cls_conn = ddb_entry->conn;
  2212. conn = cls_conn->dd_data;
  2213. /* Update timers after login */
  2214. ddb_entry->default_relogin_timeout =
  2215. (le16_to_cpu(fw_ddb_entry->def_timeout) > LOGIN_TOV) &&
  2216. (le16_to_cpu(fw_ddb_entry->def_timeout) < LOGIN_TOV * 10) ?
  2217. le16_to_cpu(fw_ddb_entry->def_timeout) : LOGIN_TOV;
  2218. ddb_entry->default_time2wait =
  2219. le16_to_cpu(fw_ddb_entry->iscsi_def_time2wait);
  2220. /* Update params */
  2221. ddb_entry->chap_tbl_idx = le16_to_cpu(fw_ddb_entry->chap_tbl_idx);
  2222. qla4xxx_copy_to_sess_conn_params(conn, sess, fw_ddb_entry);
  2223. memcpy(sess->initiatorname, ha->name_string,
  2224. min(sizeof(ha->name_string), sizeof(sess->initiatorname)));
  2225. exit_session_conn_param:
  2226. if (fw_ddb_entry)
  2227. dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
  2228. fw_ddb_entry, fw_ddb_entry_dma);
  2229. }
  2230. /*
  2231. * Timer routines
  2232. */
  2233. static void qla4xxx_start_timer(struct scsi_qla_host *ha, void *func,
  2234. unsigned long interval)
  2235. {
  2236. DEBUG(printk("scsi: %s: Starting timer thread for adapter %d\n",
  2237. __func__, ha->host->host_no));
  2238. init_timer(&ha->timer);
  2239. ha->timer.expires = jiffies + interval * HZ;
  2240. ha->timer.data = (unsigned long)ha;
  2241. ha->timer.function = (void (*)(unsigned long))func;
  2242. add_timer(&ha->timer);
  2243. ha->timer_active = 1;
  2244. }
  2245. static void qla4xxx_stop_timer(struct scsi_qla_host *ha)
  2246. {
  2247. del_timer_sync(&ha->timer);
  2248. ha->timer_active = 0;
  2249. }
  2250. /***
  2251. * qla4xxx_mark_device_missing - blocks the session
  2252. * @cls_session: Pointer to the session to be blocked
  2253. * @ddb_entry: Pointer to device database entry
  2254. *
  2255. * This routine marks a device missing and close connection.
  2256. **/
  2257. void qla4xxx_mark_device_missing(struct iscsi_cls_session *cls_session)
  2258. {
  2259. iscsi_block_session(cls_session);
  2260. }
  2261. /**
  2262. * qla4xxx_mark_all_devices_missing - mark all devices as missing.
  2263. * @ha: Pointer to host adapter structure.
  2264. *
  2265. * This routine marks a device missing and resets the relogin retry count.
  2266. **/
  2267. void qla4xxx_mark_all_devices_missing(struct scsi_qla_host *ha)
  2268. {
  2269. iscsi_host_for_each_session(ha->host, qla4xxx_mark_device_missing);
  2270. }
  2271. static struct srb* qla4xxx_get_new_srb(struct scsi_qla_host *ha,
  2272. struct ddb_entry *ddb_entry,
  2273. struct scsi_cmnd *cmd)
  2274. {
  2275. struct srb *srb;
  2276. srb = mempool_alloc(ha->srb_mempool, GFP_ATOMIC);
  2277. if (!srb)
  2278. return srb;
  2279. kref_init(&srb->srb_ref);
  2280. srb->ha = ha;
  2281. srb->ddb = ddb_entry;
  2282. srb->cmd = cmd;
  2283. srb->flags = 0;
  2284. CMD_SP(cmd) = (void *)srb;
  2285. return srb;
  2286. }
  2287. static void qla4xxx_srb_free_dma(struct scsi_qla_host *ha, struct srb *srb)
  2288. {
  2289. struct scsi_cmnd *cmd = srb->cmd;
  2290. if (srb->flags & SRB_DMA_VALID) {
  2291. scsi_dma_unmap(cmd);
  2292. srb->flags &= ~SRB_DMA_VALID;
  2293. }
  2294. CMD_SP(cmd) = NULL;
  2295. }
  2296. void qla4xxx_srb_compl(struct kref *ref)
  2297. {
  2298. struct srb *srb = container_of(ref, struct srb, srb_ref);
  2299. struct scsi_cmnd *cmd = srb->cmd;
  2300. struct scsi_qla_host *ha = srb->ha;
  2301. qla4xxx_srb_free_dma(ha, srb);
  2302. mempool_free(srb, ha->srb_mempool);
  2303. cmd->scsi_done(cmd);
  2304. }
  2305. /**
  2306. * qla4xxx_queuecommand - scsi layer issues scsi command to driver.
  2307. * @host: scsi host
  2308. * @cmd: Pointer to Linux's SCSI command structure
  2309. *
  2310. * Remarks:
  2311. * This routine is invoked by Linux to send a SCSI command to the driver.
  2312. * The mid-level driver tries to ensure that queuecommand never gets
  2313. * invoked concurrently with itself or the interrupt handler (although
  2314. * the interrupt handler may call this routine as part of request-
  2315. * completion handling). Unfortunely, it sometimes calls the scheduler
  2316. * in interrupt context which is a big NO! NO!.
  2317. **/
  2318. static int qla4xxx_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *cmd)
  2319. {
  2320. struct scsi_qla_host *ha = to_qla_host(host);
  2321. struct ddb_entry *ddb_entry = cmd->device->hostdata;
  2322. struct iscsi_cls_session *sess = ddb_entry->sess;
  2323. struct srb *srb;
  2324. int rval;
  2325. if (test_bit(AF_EEH_BUSY, &ha->flags)) {
  2326. if (test_bit(AF_PCI_CHANNEL_IO_PERM_FAILURE, &ha->flags))
  2327. cmd->result = DID_NO_CONNECT << 16;
  2328. else
  2329. cmd->result = DID_REQUEUE << 16;
  2330. goto qc_fail_command;
  2331. }
  2332. if (!sess) {
  2333. cmd->result = DID_IMM_RETRY << 16;
  2334. goto qc_fail_command;
  2335. }
  2336. rval = iscsi_session_chkready(sess);
  2337. if (rval) {
  2338. cmd->result = rval;
  2339. goto qc_fail_command;
  2340. }
  2341. if (test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags) ||
  2342. test_bit(DPC_RESET_ACTIVE, &ha->dpc_flags) ||
  2343. test_bit(DPC_RESET_HA, &ha->dpc_flags) ||
  2344. test_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags) ||
  2345. test_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags) ||
  2346. !test_bit(AF_ONLINE, &ha->flags) ||
  2347. !test_bit(AF_LINK_UP, &ha->flags) ||
  2348. test_bit(AF_LOOPBACK, &ha->flags) ||
  2349. test_bit(DPC_POST_IDC_ACK, &ha->dpc_flags) ||
  2350. test_bit(DPC_RESTORE_ACB, &ha->dpc_flags) ||
  2351. test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags))
  2352. goto qc_host_busy;
  2353. srb = qla4xxx_get_new_srb(ha, ddb_entry, cmd);
  2354. if (!srb)
  2355. goto qc_host_busy;
  2356. rval = qla4xxx_send_command_to_isp(ha, srb);
  2357. if (rval != QLA_SUCCESS)
  2358. goto qc_host_busy_free_sp;
  2359. return 0;
  2360. qc_host_busy_free_sp:
  2361. qla4xxx_srb_free_dma(ha, srb);
  2362. mempool_free(srb, ha->srb_mempool);
  2363. qc_host_busy:
  2364. return SCSI_MLQUEUE_HOST_BUSY;
  2365. qc_fail_command:
  2366. cmd->scsi_done(cmd);
  2367. return 0;
  2368. }
  2369. /**
  2370. * qla4xxx_mem_free - frees memory allocated to adapter
  2371. * @ha: Pointer to host adapter structure.
  2372. *
  2373. * Frees memory previously allocated by qla4xxx_mem_alloc
  2374. **/
  2375. static void qla4xxx_mem_free(struct scsi_qla_host *ha)
  2376. {
  2377. if (ha->queues)
  2378. dma_free_coherent(&ha->pdev->dev, ha->queues_len, ha->queues,
  2379. ha->queues_dma);
  2380. if (ha->fw_dump)
  2381. vfree(ha->fw_dump);
  2382. ha->queues_len = 0;
  2383. ha->queues = NULL;
  2384. ha->queues_dma = 0;
  2385. ha->request_ring = NULL;
  2386. ha->request_dma = 0;
  2387. ha->response_ring = NULL;
  2388. ha->response_dma = 0;
  2389. ha->shadow_regs = NULL;
  2390. ha->shadow_regs_dma = 0;
  2391. ha->fw_dump = NULL;
  2392. ha->fw_dump_size = 0;
  2393. /* Free srb pool. */
  2394. if (ha->srb_mempool)
  2395. mempool_destroy(ha->srb_mempool);
  2396. ha->srb_mempool = NULL;
  2397. if (ha->chap_dma_pool)
  2398. dma_pool_destroy(ha->chap_dma_pool);
  2399. if (ha->chap_list)
  2400. vfree(ha->chap_list);
  2401. ha->chap_list = NULL;
  2402. if (ha->fw_ddb_dma_pool)
  2403. dma_pool_destroy(ha->fw_ddb_dma_pool);
  2404. /* release io space registers */
  2405. if (is_qla8022(ha)) {
  2406. if (ha->nx_pcibase)
  2407. iounmap(
  2408. (struct device_reg_82xx __iomem *)ha->nx_pcibase);
  2409. } else if (is_qla8032(ha) || is_qla8042(ha)) {
  2410. if (ha->nx_pcibase)
  2411. iounmap(
  2412. (struct device_reg_83xx __iomem *)ha->nx_pcibase);
  2413. } else if (ha->reg) {
  2414. iounmap(ha->reg);
  2415. }
  2416. if (ha->reset_tmplt.buff)
  2417. vfree(ha->reset_tmplt.buff);
  2418. pci_release_regions(ha->pdev);
  2419. }
  2420. /**
  2421. * qla4xxx_mem_alloc - allocates memory for use by adapter.
  2422. * @ha: Pointer to host adapter structure
  2423. *
  2424. * Allocates DMA memory for request and response queues. Also allocates memory
  2425. * for srbs.
  2426. **/
  2427. static int qla4xxx_mem_alloc(struct scsi_qla_host *ha)
  2428. {
  2429. unsigned long align;
  2430. /* Allocate contiguous block of DMA memory for queues. */
  2431. ha->queues_len = ((REQUEST_QUEUE_DEPTH * QUEUE_SIZE) +
  2432. (RESPONSE_QUEUE_DEPTH * QUEUE_SIZE) +
  2433. sizeof(struct shadow_regs) +
  2434. MEM_ALIGN_VALUE +
  2435. (PAGE_SIZE - 1)) & ~(PAGE_SIZE - 1);
  2436. ha->queues = dma_alloc_coherent(&ha->pdev->dev, ha->queues_len,
  2437. &ha->queues_dma, GFP_KERNEL);
  2438. if (ha->queues == NULL) {
  2439. ql4_printk(KERN_WARNING, ha,
  2440. "Memory Allocation failed - queues.\n");
  2441. goto mem_alloc_error_exit;
  2442. }
  2443. memset(ha->queues, 0, ha->queues_len);
  2444. /*
  2445. * As per RISC alignment requirements -- the bus-address must be a
  2446. * multiple of the request-ring size (in bytes).
  2447. */
  2448. align = 0;
  2449. if ((unsigned long)ha->queues_dma & (MEM_ALIGN_VALUE - 1))
  2450. align = MEM_ALIGN_VALUE - ((unsigned long)ha->queues_dma &
  2451. (MEM_ALIGN_VALUE - 1));
  2452. /* Update request and response queue pointers. */
  2453. ha->request_dma = ha->queues_dma + align;
  2454. ha->request_ring = (struct queue_entry *) (ha->queues + align);
  2455. ha->response_dma = ha->queues_dma + align +
  2456. (REQUEST_QUEUE_DEPTH * QUEUE_SIZE);
  2457. ha->response_ring = (struct queue_entry *) (ha->queues + align +
  2458. (REQUEST_QUEUE_DEPTH *
  2459. QUEUE_SIZE));
  2460. ha->shadow_regs_dma = ha->queues_dma + align +
  2461. (REQUEST_QUEUE_DEPTH * QUEUE_SIZE) +
  2462. (RESPONSE_QUEUE_DEPTH * QUEUE_SIZE);
  2463. ha->shadow_regs = (struct shadow_regs *) (ha->queues + align +
  2464. (REQUEST_QUEUE_DEPTH *
  2465. QUEUE_SIZE) +
  2466. (RESPONSE_QUEUE_DEPTH *
  2467. QUEUE_SIZE));
  2468. /* Allocate memory for srb pool. */
  2469. ha->srb_mempool = mempool_create(SRB_MIN_REQ, mempool_alloc_slab,
  2470. mempool_free_slab, srb_cachep);
  2471. if (ha->srb_mempool == NULL) {
  2472. ql4_printk(KERN_WARNING, ha,
  2473. "Memory Allocation failed - SRB Pool.\n");
  2474. goto mem_alloc_error_exit;
  2475. }
  2476. ha->chap_dma_pool = dma_pool_create("ql4_chap", &ha->pdev->dev,
  2477. CHAP_DMA_BLOCK_SIZE, 8, 0);
  2478. if (ha->chap_dma_pool == NULL) {
  2479. ql4_printk(KERN_WARNING, ha,
  2480. "%s: chap_dma_pool allocation failed..\n", __func__);
  2481. goto mem_alloc_error_exit;
  2482. }
  2483. ha->fw_ddb_dma_pool = dma_pool_create("ql4_fw_ddb", &ha->pdev->dev,
  2484. DDB_DMA_BLOCK_SIZE, 8, 0);
  2485. if (ha->fw_ddb_dma_pool == NULL) {
  2486. ql4_printk(KERN_WARNING, ha,
  2487. "%s: fw_ddb_dma_pool allocation failed..\n",
  2488. __func__);
  2489. goto mem_alloc_error_exit;
  2490. }
  2491. return QLA_SUCCESS;
  2492. mem_alloc_error_exit:
  2493. qla4xxx_mem_free(ha);
  2494. return QLA_ERROR;
  2495. }
  2496. /**
  2497. * qla4_8xxx_check_temp - Check the ISP82XX temperature.
  2498. * @ha: adapter block pointer.
  2499. *
  2500. * Note: The caller should not hold the idc lock.
  2501. **/
  2502. static int qla4_8xxx_check_temp(struct scsi_qla_host *ha)
  2503. {
  2504. uint32_t temp, temp_state, temp_val;
  2505. int status = QLA_SUCCESS;
  2506. temp = qla4_8xxx_rd_direct(ha, QLA8XXX_CRB_TEMP_STATE);
  2507. temp_state = qla82xx_get_temp_state(temp);
  2508. temp_val = qla82xx_get_temp_val(temp);
  2509. if (temp_state == QLA82XX_TEMP_PANIC) {
  2510. ql4_printk(KERN_WARNING, ha, "Device temperature %d degrees C"
  2511. " exceeds maximum allowed. Hardware has been shut"
  2512. " down.\n", temp_val);
  2513. status = QLA_ERROR;
  2514. } else if (temp_state == QLA82XX_TEMP_WARN) {
  2515. if (ha->temperature == QLA82XX_TEMP_NORMAL)
  2516. ql4_printk(KERN_WARNING, ha, "Device temperature %d"
  2517. " degrees C exceeds operating range."
  2518. " Immediate action needed.\n", temp_val);
  2519. } else {
  2520. if (ha->temperature == QLA82XX_TEMP_WARN)
  2521. ql4_printk(KERN_INFO, ha, "Device temperature is"
  2522. " now %d degrees C in normal range.\n",
  2523. temp_val);
  2524. }
  2525. ha->temperature = temp_state;
  2526. return status;
  2527. }
  2528. /**
  2529. * qla4_8xxx_check_fw_alive - Check firmware health
  2530. * @ha: Pointer to host adapter structure.
  2531. *
  2532. * Context: Interrupt
  2533. **/
  2534. static int qla4_8xxx_check_fw_alive(struct scsi_qla_host *ha)
  2535. {
  2536. uint32_t fw_heartbeat_counter;
  2537. int status = QLA_SUCCESS;
  2538. fw_heartbeat_counter = qla4_8xxx_rd_direct(ha,
  2539. QLA8XXX_PEG_ALIVE_COUNTER);
  2540. /* If PEG_ALIVE_COUNTER is 0xffffffff, AER/EEH is in progress, ignore */
  2541. if (fw_heartbeat_counter == 0xffffffff) {
  2542. DEBUG2(printk(KERN_WARNING "scsi%ld: %s: Device in frozen "
  2543. "state, QLA82XX_PEG_ALIVE_COUNTER is 0xffffffff\n",
  2544. ha->host_no, __func__));
  2545. return status;
  2546. }
  2547. if (ha->fw_heartbeat_counter == fw_heartbeat_counter) {
  2548. ha->seconds_since_last_heartbeat++;
  2549. /* FW not alive after 2 seconds */
  2550. if (ha->seconds_since_last_heartbeat == 2) {
  2551. ha->seconds_since_last_heartbeat = 0;
  2552. qla4_8xxx_dump_peg_reg(ha);
  2553. status = QLA_ERROR;
  2554. }
  2555. } else
  2556. ha->seconds_since_last_heartbeat = 0;
  2557. ha->fw_heartbeat_counter = fw_heartbeat_counter;
  2558. return status;
  2559. }
  2560. static void qla4_8xxx_process_fw_error(struct scsi_qla_host *ha)
  2561. {
  2562. uint32_t halt_status;
  2563. int halt_status_unrecoverable = 0;
  2564. halt_status = qla4_8xxx_rd_direct(ha, QLA8XXX_PEG_HALT_STATUS1);
  2565. if (is_qla8022(ha)) {
  2566. ql4_printk(KERN_INFO, ha, "%s: disabling pause transmit on port 0 & 1.\n",
  2567. __func__);
  2568. qla4_82xx_wr_32(ha, QLA82XX_CRB_NIU + 0x98,
  2569. CRB_NIU_XG_PAUSE_CTL_P0 |
  2570. CRB_NIU_XG_PAUSE_CTL_P1);
  2571. if (QLA82XX_FWERROR_CODE(halt_status) == 0x67)
  2572. ql4_printk(KERN_ERR, ha, "%s: Firmware aborted with error code 0x00006700. Device is being reset\n",
  2573. __func__);
  2574. if (halt_status & HALT_STATUS_UNRECOVERABLE)
  2575. halt_status_unrecoverable = 1;
  2576. } else if (is_qla8032(ha) || is_qla8042(ha)) {
  2577. if (halt_status & QLA83XX_HALT_STATUS_FW_RESET)
  2578. ql4_printk(KERN_ERR, ha, "%s: Firmware error detected device is being reset\n",
  2579. __func__);
  2580. else if (halt_status & QLA83XX_HALT_STATUS_UNRECOVERABLE)
  2581. halt_status_unrecoverable = 1;
  2582. }
  2583. /*
  2584. * Since we cannot change dev_state in interrupt context,
  2585. * set appropriate DPC flag then wakeup DPC
  2586. */
  2587. if (halt_status_unrecoverable) {
  2588. set_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags);
  2589. } else {
  2590. ql4_printk(KERN_INFO, ha, "%s: detect abort needed!\n",
  2591. __func__);
  2592. set_bit(DPC_RESET_HA, &ha->dpc_flags);
  2593. }
  2594. qla4xxx_mailbox_premature_completion(ha);
  2595. qla4xxx_wake_dpc(ha);
  2596. }
  2597. /**
  2598. * qla4_8xxx_watchdog - Poll dev state
  2599. * @ha: Pointer to host adapter structure.
  2600. *
  2601. * Context: Interrupt
  2602. **/
  2603. void qla4_8xxx_watchdog(struct scsi_qla_host *ha)
  2604. {
  2605. uint32_t dev_state;
  2606. uint32_t idc_ctrl;
  2607. /* don't poll if reset is going on */
  2608. if (!(test_bit(DPC_RESET_ACTIVE, &ha->dpc_flags) ||
  2609. test_bit(DPC_RESET_HA, &ha->dpc_flags) ||
  2610. test_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags))) {
  2611. dev_state = qla4_8xxx_rd_direct(ha, QLA8XXX_CRB_DEV_STATE);
  2612. if (qla4_8xxx_check_temp(ha)) {
  2613. if (is_qla8022(ha)) {
  2614. ql4_printk(KERN_INFO, ha, "disabling pause transmit on port 0 & 1.\n");
  2615. qla4_82xx_wr_32(ha, QLA82XX_CRB_NIU + 0x98,
  2616. CRB_NIU_XG_PAUSE_CTL_P0 |
  2617. CRB_NIU_XG_PAUSE_CTL_P1);
  2618. }
  2619. set_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags);
  2620. qla4xxx_wake_dpc(ha);
  2621. } else if (dev_state == QLA8XXX_DEV_NEED_RESET &&
  2622. !test_bit(DPC_RESET_HA, &ha->dpc_flags)) {
  2623. ql4_printk(KERN_INFO, ha, "%s: HW State: NEED RESET!\n",
  2624. __func__);
  2625. if (is_qla8032(ha) || is_qla8042(ha)) {
  2626. idc_ctrl = qla4_83xx_rd_reg(ha,
  2627. QLA83XX_IDC_DRV_CTRL);
  2628. if (!(idc_ctrl & GRACEFUL_RESET_BIT1)) {
  2629. ql4_printk(KERN_INFO, ha, "%s: Graceful reset bit is not set\n",
  2630. __func__);
  2631. qla4xxx_mailbox_premature_completion(
  2632. ha);
  2633. }
  2634. }
  2635. if ((is_qla8032(ha) || is_qla8042(ha)) ||
  2636. (is_qla8022(ha) && !ql4xdontresethba)) {
  2637. set_bit(DPC_RESET_HA, &ha->dpc_flags);
  2638. qla4xxx_wake_dpc(ha);
  2639. }
  2640. } else if (dev_state == QLA8XXX_DEV_NEED_QUIESCENT &&
  2641. !test_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags)) {
  2642. ql4_printk(KERN_INFO, ha, "%s: HW State: NEED QUIES!\n",
  2643. __func__);
  2644. set_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags);
  2645. qla4xxx_wake_dpc(ha);
  2646. } else {
  2647. /* Check firmware health */
  2648. if (qla4_8xxx_check_fw_alive(ha))
  2649. qla4_8xxx_process_fw_error(ha);
  2650. }
  2651. }
  2652. }
  2653. static void qla4xxx_check_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
  2654. {
  2655. struct iscsi_session *sess;
  2656. struct ddb_entry *ddb_entry;
  2657. struct scsi_qla_host *ha;
  2658. sess = cls_sess->dd_data;
  2659. ddb_entry = sess->dd_data;
  2660. ha = ddb_entry->ha;
  2661. if (!(ddb_entry->ddb_type == FLASH_DDB))
  2662. return;
  2663. if (adapter_up(ha) && !test_bit(DF_RELOGIN, &ddb_entry->flags) &&
  2664. !iscsi_is_session_online(cls_sess)) {
  2665. if (atomic_read(&ddb_entry->retry_relogin_timer) !=
  2666. INVALID_ENTRY) {
  2667. if (atomic_read(&ddb_entry->retry_relogin_timer) ==
  2668. 0) {
  2669. atomic_set(&ddb_entry->retry_relogin_timer,
  2670. INVALID_ENTRY);
  2671. set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
  2672. set_bit(DF_RELOGIN, &ddb_entry->flags);
  2673. DEBUG2(ql4_printk(KERN_INFO, ha,
  2674. "%s: index [%d] login device\n",
  2675. __func__, ddb_entry->fw_ddb_index));
  2676. } else
  2677. atomic_dec(&ddb_entry->retry_relogin_timer);
  2678. }
  2679. }
  2680. /* Wait for relogin to timeout */
  2681. if (atomic_read(&ddb_entry->relogin_timer) &&
  2682. (atomic_dec_and_test(&ddb_entry->relogin_timer) != 0)) {
  2683. /*
  2684. * If the relogin times out and the device is
  2685. * still NOT ONLINE then try and relogin again.
  2686. */
  2687. if (!iscsi_is_session_online(cls_sess)) {
  2688. /* Reset retry relogin timer */
  2689. atomic_inc(&ddb_entry->relogin_retry_count);
  2690. DEBUG2(ql4_printk(KERN_INFO, ha,
  2691. "%s: index[%d] relogin timed out-retrying"
  2692. " relogin (%d), retry (%d)\n", __func__,
  2693. ddb_entry->fw_ddb_index,
  2694. atomic_read(&ddb_entry->relogin_retry_count),
  2695. ddb_entry->default_time2wait + 4));
  2696. set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
  2697. atomic_set(&ddb_entry->retry_relogin_timer,
  2698. ddb_entry->default_time2wait + 4);
  2699. }
  2700. }
  2701. }
  2702. /**
  2703. * qla4xxx_timer - checks every second for work to do.
  2704. * @ha: Pointer to host adapter structure.
  2705. **/
  2706. static void qla4xxx_timer(struct scsi_qla_host *ha)
  2707. {
  2708. int start_dpc = 0;
  2709. uint16_t w;
  2710. iscsi_host_for_each_session(ha->host, qla4xxx_check_relogin_flash_ddb);
  2711. /* If we are in the middle of AER/EEH processing
  2712. * skip any processing and reschedule the timer
  2713. */
  2714. if (test_bit(AF_EEH_BUSY, &ha->flags)) {
  2715. mod_timer(&ha->timer, jiffies + HZ);
  2716. return;
  2717. }
  2718. /* Hardware read to trigger an EEH error during mailbox waits. */
  2719. if (!pci_channel_offline(ha->pdev))
  2720. pci_read_config_word(ha->pdev, PCI_VENDOR_ID, &w);
  2721. if (is_qla80XX(ha))
  2722. qla4_8xxx_watchdog(ha);
  2723. if (is_qla40XX(ha)) {
  2724. /* Check for heartbeat interval. */
  2725. if (ha->firmware_options & FWOPT_HEARTBEAT_ENABLE &&
  2726. ha->heartbeat_interval != 0) {
  2727. ha->seconds_since_last_heartbeat++;
  2728. if (ha->seconds_since_last_heartbeat >
  2729. ha->heartbeat_interval + 2)
  2730. set_bit(DPC_RESET_HA, &ha->dpc_flags);
  2731. }
  2732. }
  2733. /* Process any deferred work. */
  2734. if (!list_empty(&ha->work_list))
  2735. start_dpc++;
  2736. /* Wakeup the dpc routine for this adapter, if needed. */
  2737. if (start_dpc ||
  2738. test_bit(DPC_RESET_HA, &ha->dpc_flags) ||
  2739. test_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags) ||
  2740. test_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags) ||
  2741. test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags) ||
  2742. test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags) ||
  2743. test_bit(DPC_GET_DHCP_IP_ADDR, &ha->dpc_flags) ||
  2744. test_bit(DPC_LINK_CHANGED, &ha->dpc_flags) ||
  2745. test_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags) ||
  2746. test_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags) ||
  2747. test_bit(DPC_AEN, &ha->dpc_flags)) {
  2748. DEBUG2(printk("scsi%ld: %s: scheduling dpc routine"
  2749. " - dpc flags = 0x%lx\n",
  2750. ha->host_no, __func__, ha->dpc_flags));
  2751. qla4xxx_wake_dpc(ha);
  2752. }
  2753. /* Reschedule timer thread to call us back in one second */
  2754. mod_timer(&ha->timer, jiffies + HZ);
  2755. DEBUG2(ha->seconds_since_last_intr++);
  2756. }
  2757. /**
  2758. * qla4xxx_cmd_wait - waits for all outstanding commands to complete
  2759. * @ha: Pointer to host adapter structure.
  2760. *
  2761. * This routine stalls the driver until all outstanding commands are returned.
  2762. * Caller must release the Hardware Lock prior to calling this routine.
  2763. **/
  2764. static int qla4xxx_cmd_wait(struct scsi_qla_host *ha)
  2765. {
  2766. uint32_t index = 0;
  2767. unsigned long flags;
  2768. struct scsi_cmnd *cmd;
  2769. unsigned long wtime = jiffies + (WAIT_CMD_TOV * HZ);
  2770. DEBUG2(ql4_printk(KERN_INFO, ha, "Wait up to %d seconds for cmds to "
  2771. "complete\n", WAIT_CMD_TOV));
  2772. while (!time_after_eq(jiffies, wtime)) {
  2773. spin_lock_irqsave(&ha->hardware_lock, flags);
  2774. /* Find a command that hasn't completed. */
  2775. for (index = 0; index < ha->host->can_queue; index++) {
  2776. cmd = scsi_host_find_tag(ha->host, index);
  2777. /*
  2778. * We cannot just check if the index is valid,
  2779. * becase if we are run from the scsi eh, then
  2780. * the scsi/block layer is going to prevent
  2781. * the tag from being released.
  2782. */
  2783. if (cmd != NULL && CMD_SP(cmd))
  2784. break;
  2785. }
  2786. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  2787. /* If No Commands are pending, wait is complete */
  2788. if (index == ha->host->can_queue)
  2789. return QLA_SUCCESS;
  2790. msleep(1000);
  2791. }
  2792. /* If we timed out on waiting for commands to come back
  2793. * return ERROR. */
  2794. return QLA_ERROR;
  2795. }
  2796. int qla4xxx_hw_reset(struct scsi_qla_host *ha)
  2797. {
  2798. uint32_t ctrl_status;
  2799. unsigned long flags = 0;
  2800. DEBUG2(printk(KERN_ERR "scsi%ld: %s\n", ha->host_no, __func__));
  2801. if (ql4xxx_lock_drvr_wait(ha) != QLA_SUCCESS)
  2802. return QLA_ERROR;
  2803. spin_lock_irqsave(&ha->hardware_lock, flags);
  2804. /*
  2805. * If the SCSI Reset Interrupt bit is set, clear it.
  2806. * Otherwise, the Soft Reset won't work.
  2807. */
  2808. ctrl_status = readw(&ha->reg->ctrl_status);
  2809. if ((ctrl_status & CSR_SCSI_RESET_INTR) != 0)
  2810. writel(set_rmask(CSR_SCSI_RESET_INTR), &ha->reg->ctrl_status);
  2811. /* Issue Soft Reset */
  2812. writel(set_rmask(CSR_SOFT_RESET), &ha->reg->ctrl_status);
  2813. readl(&ha->reg->ctrl_status);
  2814. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  2815. return QLA_SUCCESS;
  2816. }
  2817. /**
  2818. * qla4xxx_soft_reset - performs soft reset.
  2819. * @ha: Pointer to host adapter structure.
  2820. **/
  2821. int qla4xxx_soft_reset(struct scsi_qla_host *ha)
  2822. {
  2823. uint32_t max_wait_time;
  2824. unsigned long flags = 0;
  2825. int status;
  2826. uint32_t ctrl_status;
  2827. status = qla4xxx_hw_reset(ha);
  2828. if (status != QLA_SUCCESS)
  2829. return status;
  2830. status = QLA_ERROR;
  2831. /* Wait until the Network Reset Intr bit is cleared */
  2832. max_wait_time = RESET_INTR_TOV;
  2833. do {
  2834. spin_lock_irqsave(&ha->hardware_lock, flags);
  2835. ctrl_status = readw(&ha->reg->ctrl_status);
  2836. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  2837. if ((ctrl_status & CSR_NET_RESET_INTR) == 0)
  2838. break;
  2839. msleep(1000);
  2840. } while ((--max_wait_time));
  2841. if ((ctrl_status & CSR_NET_RESET_INTR) != 0) {
  2842. DEBUG2(printk(KERN_WARNING
  2843. "scsi%ld: Network Reset Intr not cleared by "
  2844. "Network function, clearing it now!\n",
  2845. ha->host_no));
  2846. spin_lock_irqsave(&ha->hardware_lock, flags);
  2847. writel(set_rmask(CSR_NET_RESET_INTR), &ha->reg->ctrl_status);
  2848. readl(&ha->reg->ctrl_status);
  2849. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  2850. }
  2851. /* Wait until the firmware tells us the Soft Reset is done */
  2852. max_wait_time = SOFT_RESET_TOV;
  2853. do {
  2854. spin_lock_irqsave(&ha->hardware_lock, flags);
  2855. ctrl_status = readw(&ha->reg->ctrl_status);
  2856. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  2857. if ((ctrl_status & CSR_SOFT_RESET) == 0) {
  2858. status = QLA_SUCCESS;
  2859. break;
  2860. }
  2861. msleep(1000);
  2862. } while ((--max_wait_time));
  2863. /*
  2864. * Also, make sure that the SCSI Reset Interrupt bit has been cleared
  2865. * after the soft reset has taken place.
  2866. */
  2867. spin_lock_irqsave(&ha->hardware_lock, flags);
  2868. ctrl_status = readw(&ha->reg->ctrl_status);
  2869. if ((ctrl_status & CSR_SCSI_RESET_INTR) != 0) {
  2870. writel(set_rmask(CSR_SCSI_RESET_INTR), &ha->reg->ctrl_status);
  2871. readl(&ha->reg->ctrl_status);
  2872. }
  2873. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  2874. /* If soft reset fails then most probably the bios on other
  2875. * function is also enabled.
  2876. * Since the initialization is sequential the other fn
  2877. * wont be able to acknowledge the soft reset.
  2878. * Issue a force soft reset to workaround this scenario.
  2879. */
  2880. if (max_wait_time == 0) {
  2881. /* Issue Force Soft Reset */
  2882. spin_lock_irqsave(&ha->hardware_lock, flags);
  2883. writel(set_rmask(CSR_FORCE_SOFT_RESET), &ha->reg->ctrl_status);
  2884. readl(&ha->reg->ctrl_status);
  2885. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  2886. /* Wait until the firmware tells us the Soft Reset is done */
  2887. max_wait_time = SOFT_RESET_TOV;
  2888. do {
  2889. spin_lock_irqsave(&ha->hardware_lock, flags);
  2890. ctrl_status = readw(&ha->reg->ctrl_status);
  2891. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  2892. if ((ctrl_status & CSR_FORCE_SOFT_RESET) == 0) {
  2893. status = QLA_SUCCESS;
  2894. break;
  2895. }
  2896. msleep(1000);
  2897. } while ((--max_wait_time));
  2898. }
  2899. return status;
  2900. }
  2901. /**
  2902. * qla4xxx_abort_active_cmds - returns all outstanding i/o requests to O.S.
  2903. * @ha: Pointer to host adapter structure.
  2904. * @res: returned scsi status
  2905. *
  2906. * This routine is called just prior to a HARD RESET to return all
  2907. * outstanding commands back to the Operating System.
  2908. * Caller should make sure that the following locks are released
  2909. * before this calling routine: Hardware lock, and io_request_lock.
  2910. **/
  2911. static void qla4xxx_abort_active_cmds(struct scsi_qla_host *ha, int res)
  2912. {
  2913. struct srb *srb;
  2914. int i;
  2915. unsigned long flags;
  2916. spin_lock_irqsave(&ha->hardware_lock, flags);
  2917. for (i = 0; i < ha->host->can_queue; i++) {
  2918. srb = qla4xxx_del_from_active_array(ha, i);
  2919. if (srb != NULL) {
  2920. srb->cmd->result = res;
  2921. kref_put(&srb->srb_ref, qla4xxx_srb_compl);
  2922. }
  2923. }
  2924. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  2925. }
  2926. void qla4xxx_dead_adapter_cleanup(struct scsi_qla_host *ha)
  2927. {
  2928. clear_bit(AF_ONLINE, &ha->flags);
  2929. /* Disable the board */
  2930. ql4_printk(KERN_INFO, ha, "Disabling the board\n");
  2931. qla4xxx_abort_active_cmds(ha, DID_NO_CONNECT << 16);
  2932. qla4xxx_mark_all_devices_missing(ha);
  2933. clear_bit(AF_INIT_DONE, &ha->flags);
  2934. }
  2935. static void qla4xxx_fail_session(struct iscsi_cls_session *cls_session)
  2936. {
  2937. struct iscsi_session *sess;
  2938. struct ddb_entry *ddb_entry;
  2939. sess = cls_session->dd_data;
  2940. ddb_entry = sess->dd_data;
  2941. ddb_entry->fw_ddb_device_state = DDB_DS_SESSION_FAILED;
  2942. if (ddb_entry->ddb_type == FLASH_DDB)
  2943. iscsi_block_session(ddb_entry->sess);
  2944. else
  2945. iscsi_session_failure(cls_session->dd_data,
  2946. ISCSI_ERR_CONN_FAILED);
  2947. }
  2948. /**
  2949. * qla4xxx_recover_adapter - recovers adapter after a fatal error
  2950. * @ha: Pointer to host adapter structure.
  2951. **/
  2952. static int qla4xxx_recover_adapter(struct scsi_qla_host *ha)
  2953. {
  2954. int status = QLA_ERROR;
  2955. uint8_t reset_chip = 0;
  2956. uint32_t dev_state;
  2957. unsigned long wait;
  2958. /* Stall incoming I/O until we are done */
  2959. scsi_block_requests(ha->host);
  2960. clear_bit(AF_ONLINE, &ha->flags);
  2961. clear_bit(AF_LINK_UP, &ha->flags);
  2962. DEBUG2(ql4_printk(KERN_INFO, ha, "%s: adapter OFFLINE\n", __func__));
  2963. set_bit(DPC_RESET_ACTIVE, &ha->dpc_flags);
  2964. if ((is_qla8032(ha) || is_qla8042(ha)) &&
  2965. !test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags)) {
  2966. ql4_printk(KERN_INFO, ha, "%s: disabling pause transmit on port 0 & 1.\n",
  2967. __func__);
  2968. /* disable pause frame for ISP83xx */
  2969. qla4_83xx_disable_pause(ha);
  2970. }
  2971. iscsi_host_for_each_session(ha->host, qla4xxx_fail_session);
  2972. if (test_bit(DPC_RESET_HA, &ha->dpc_flags))
  2973. reset_chip = 1;
  2974. /* For the DPC_RESET_HA_INTR case (ISP-4xxx specific)
  2975. * do not reset adapter, jump to initialize_adapter */
  2976. if (test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags)) {
  2977. status = QLA_SUCCESS;
  2978. goto recover_ha_init_adapter;
  2979. }
  2980. /* For the ISP-8xxx adapter, issue a stop_firmware if invoked
  2981. * from eh_host_reset or ioctl module */
  2982. if (is_qla80XX(ha) && !reset_chip &&
  2983. test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags)) {
  2984. DEBUG2(ql4_printk(KERN_INFO, ha,
  2985. "scsi%ld: %s - Performing stop_firmware...\n",
  2986. ha->host_no, __func__));
  2987. status = ha->isp_ops->reset_firmware(ha);
  2988. if (status == QLA_SUCCESS) {
  2989. if (!test_bit(AF_FW_RECOVERY, &ha->flags))
  2990. qla4xxx_cmd_wait(ha);
  2991. ha->isp_ops->disable_intrs(ha);
  2992. qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
  2993. qla4xxx_abort_active_cmds(ha, DID_RESET << 16);
  2994. } else {
  2995. /* If the stop_firmware fails then
  2996. * reset the entire chip */
  2997. reset_chip = 1;
  2998. clear_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags);
  2999. set_bit(DPC_RESET_HA, &ha->dpc_flags);
  3000. }
  3001. }
  3002. /* Issue full chip reset if recovering from a catastrophic error,
  3003. * or if stop_firmware fails for ISP-8xxx.
  3004. * This is the default case for ISP-4xxx */
  3005. if (is_qla40XX(ha) || reset_chip) {
  3006. if (is_qla40XX(ha))
  3007. goto chip_reset;
  3008. /* Check if 8XXX firmware is alive or not
  3009. * We may have arrived here from NEED_RESET
  3010. * detection only */
  3011. if (test_bit(AF_FW_RECOVERY, &ha->flags))
  3012. goto chip_reset;
  3013. wait = jiffies + (FW_ALIVE_WAIT_TOV * HZ);
  3014. while (time_before(jiffies, wait)) {
  3015. if (qla4_8xxx_check_fw_alive(ha)) {
  3016. qla4xxx_mailbox_premature_completion(ha);
  3017. break;
  3018. }
  3019. set_current_state(TASK_UNINTERRUPTIBLE);
  3020. schedule_timeout(HZ);
  3021. }
  3022. chip_reset:
  3023. if (!test_bit(AF_FW_RECOVERY, &ha->flags))
  3024. qla4xxx_cmd_wait(ha);
  3025. qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
  3026. qla4xxx_abort_active_cmds(ha, DID_RESET << 16);
  3027. DEBUG2(ql4_printk(KERN_INFO, ha,
  3028. "scsi%ld: %s - Performing chip reset..\n",
  3029. ha->host_no, __func__));
  3030. status = ha->isp_ops->reset_chip(ha);
  3031. }
  3032. /* Flush any pending ddb changed AENs */
  3033. qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
  3034. recover_ha_init_adapter:
  3035. /* Upon successful firmware/chip reset, re-initialize the adapter */
  3036. if (status == QLA_SUCCESS) {
  3037. /* For ISP-4xxx, force function 1 to always initialize
  3038. * before function 3 to prevent both funcions from
  3039. * stepping on top of the other */
  3040. if (is_qla40XX(ha) && (ha->mac_index == 3))
  3041. ssleep(6);
  3042. /* NOTE: AF_ONLINE flag set upon successful completion of
  3043. * qla4xxx_initialize_adapter */
  3044. status = qla4xxx_initialize_adapter(ha, RESET_ADAPTER);
  3045. }
  3046. /* Retry failed adapter initialization, if necessary
  3047. * Do not retry initialize_adapter for RESET_HA_INTR (ISP-4xxx specific)
  3048. * case to prevent ping-pong resets between functions */
  3049. if (!test_bit(AF_ONLINE, &ha->flags) &&
  3050. !test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags)) {
  3051. /* Adapter initialization failed, see if we can retry
  3052. * resetting the ha.
  3053. * Since we don't want to block the DPC for too long
  3054. * with multiple resets in the same thread,
  3055. * utilize DPC to retry */
  3056. if (is_qla80XX(ha)) {
  3057. ha->isp_ops->idc_lock(ha);
  3058. dev_state = qla4_8xxx_rd_direct(ha,
  3059. QLA8XXX_CRB_DEV_STATE);
  3060. ha->isp_ops->idc_unlock(ha);
  3061. if (dev_state == QLA8XXX_DEV_FAILED) {
  3062. ql4_printk(KERN_INFO, ha, "%s: don't retry "
  3063. "recover adapter. H/W is in Failed "
  3064. "state\n", __func__);
  3065. qla4xxx_dead_adapter_cleanup(ha);
  3066. clear_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags);
  3067. clear_bit(DPC_RESET_HA, &ha->dpc_flags);
  3068. clear_bit(DPC_RESET_HA_FW_CONTEXT,
  3069. &ha->dpc_flags);
  3070. status = QLA_ERROR;
  3071. goto exit_recover;
  3072. }
  3073. }
  3074. if (!test_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags)) {
  3075. ha->retry_reset_ha_cnt = MAX_RESET_HA_RETRIES;
  3076. DEBUG2(printk("scsi%ld: recover adapter - retrying "
  3077. "(%d) more times\n", ha->host_no,
  3078. ha->retry_reset_ha_cnt));
  3079. set_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags);
  3080. status = QLA_ERROR;
  3081. } else {
  3082. if (ha->retry_reset_ha_cnt > 0) {
  3083. /* Schedule another Reset HA--DPC will retry */
  3084. ha->retry_reset_ha_cnt--;
  3085. DEBUG2(printk("scsi%ld: recover adapter - "
  3086. "retry remaining %d\n",
  3087. ha->host_no,
  3088. ha->retry_reset_ha_cnt));
  3089. status = QLA_ERROR;
  3090. }
  3091. if (ha->retry_reset_ha_cnt == 0) {
  3092. /* Recover adapter retries have been exhausted.
  3093. * Adapter DEAD */
  3094. DEBUG2(printk("scsi%ld: recover adapter "
  3095. "failed - board disabled\n",
  3096. ha->host_no));
  3097. qla4xxx_dead_adapter_cleanup(ha);
  3098. clear_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags);
  3099. clear_bit(DPC_RESET_HA, &ha->dpc_flags);
  3100. clear_bit(DPC_RESET_HA_FW_CONTEXT,
  3101. &ha->dpc_flags);
  3102. status = QLA_ERROR;
  3103. }
  3104. }
  3105. } else {
  3106. clear_bit(DPC_RESET_HA, &ha->dpc_flags);
  3107. clear_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags);
  3108. clear_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags);
  3109. }
  3110. exit_recover:
  3111. ha->adapter_error_count++;
  3112. if (test_bit(AF_ONLINE, &ha->flags))
  3113. ha->isp_ops->enable_intrs(ha);
  3114. scsi_unblock_requests(ha->host);
  3115. clear_bit(DPC_RESET_ACTIVE, &ha->dpc_flags);
  3116. DEBUG2(printk("scsi%ld: recover adapter: %s\n", ha->host_no,
  3117. status == QLA_ERROR ? "FAILED" : "SUCCEEDED"));
  3118. return status;
  3119. }
  3120. static void qla4xxx_relogin_devices(struct iscsi_cls_session *cls_session)
  3121. {
  3122. struct iscsi_session *sess;
  3123. struct ddb_entry *ddb_entry;
  3124. struct scsi_qla_host *ha;
  3125. sess = cls_session->dd_data;
  3126. ddb_entry = sess->dd_data;
  3127. ha = ddb_entry->ha;
  3128. if (!iscsi_is_session_online(cls_session)) {
  3129. if (ddb_entry->fw_ddb_device_state == DDB_DS_SESSION_ACTIVE) {
  3130. ql4_printk(KERN_INFO, ha, "scsi%ld: %s: ddb[%d]"
  3131. " unblock session\n", ha->host_no, __func__,
  3132. ddb_entry->fw_ddb_index);
  3133. iscsi_unblock_session(ddb_entry->sess);
  3134. } else {
  3135. /* Trigger relogin */
  3136. if (ddb_entry->ddb_type == FLASH_DDB) {
  3137. if (!(test_bit(DF_RELOGIN, &ddb_entry->flags) ||
  3138. test_bit(DF_DISABLE_RELOGIN,
  3139. &ddb_entry->flags)))
  3140. qla4xxx_arm_relogin_timer(ddb_entry);
  3141. } else
  3142. iscsi_session_failure(cls_session->dd_data,
  3143. ISCSI_ERR_CONN_FAILED);
  3144. }
  3145. }
  3146. }
  3147. int qla4xxx_unblock_flash_ddb(struct iscsi_cls_session *cls_session)
  3148. {
  3149. struct iscsi_session *sess;
  3150. struct ddb_entry *ddb_entry;
  3151. struct scsi_qla_host *ha;
  3152. sess = cls_session->dd_data;
  3153. ddb_entry = sess->dd_data;
  3154. ha = ddb_entry->ha;
  3155. ql4_printk(KERN_INFO, ha, "scsi%ld: %s: ddb[%d]"
  3156. " unblock session\n", ha->host_no, __func__,
  3157. ddb_entry->fw_ddb_index);
  3158. iscsi_unblock_session(ddb_entry->sess);
  3159. /* Start scan target */
  3160. if (test_bit(AF_ONLINE, &ha->flags)) {
  3161. ql4_printk(KERN_INFO, ha, "scsi%ld: %s: ddb[%d]"
  3162. " start scan\n", ha->host_no, __func__,
  3163. ddb_entry->fw_ddb_index);
  3164. scsi_queue_work(ha->host, &ddb_entry->sess->scan_work);
  3165. }
  3166. return QLA_SUCCESS;
  3167. }
  3168. int qla4xxx_unblock_ddb(struct iscsi_cls_session *cls_session)
  3169. {
  3170. struct iscsi_session *sess;
  3171. struct ddb_entry *ddb_entry;
  3172. struct scsi_qla_host *ha;
  3173. int status = QLA_SUCCESS;
  3174. sess = cls_session->dd_data;
  3175. ddb_entry = sess->dd_data;
  3176. ha = ddb_entry->ha;
  3177. ql4_printk(KERN_INFO, ha, "scsi%ld: %s: ddb[%d]"
  3178. " unblock user space session\n", ha->host_no, __func__,
  3179. ddb_entry->fw_ddb_index);
  3180. if (!iscsi_is_session_online(cls_session)) {
  3181. iscsi_conn_start(ddb_entry->conn);
  3182. iscsi_conn_login_event(ddb_entry->conn,
  3183. ISCSI_CONN_STATE_LOGGED_IN);
  3184. } else {
  3185. ql4_printk(KERN_INFO, ha,
  3186. "scsi%ld: %s: ddb[%d] session [%d] already logged in\n",
  3187. ha->host_no, __func__, ddb_entry->fw_ddb_index,
  3188. cls_session->sid);
  3189. status = QLA_ERROR;
  3190. }
  3191. return status;
  3192. }
  3193. static void qla4xxx_relogin_all_devices(struct scsi_qla_host *ha)
  3194. {
  3195. iscsi_host_for_each_session(ha->host, qla4xxx_relogin_devices);
  3196. }
  3197. static void qla4xxx_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
  3198. {
  3199. uint16_t relogin_timer;
  3200. struct iscsi_session *sess;
  3201. struct ddb_entry *ddb_entry;
  3202. struct scsi_qla_host *ha;
  3203. sess = cls_sess->dd_data;
  3204. ddb_entry = sess->dd_data;
  3205. ha = ddb_entry->ha;
  3206. relogin_timer = max(ddb_entry->default_relogin_timeout,
  3207. (uint16_t)RELOGIN_TOV);
  3208. atomic_set(&ddb_entry->relogin_timer, relogin_timer);
  3209. DEBUG2(ql4_printk(KERN_INFO, ha,
  3210. "scsi%ld: Relogin index [%d]. TOV=%d\n", ha->host_no,
  3211. ddb_entry->fw_ddb_index, relogin_timer));
  3212. qla4xxx_login_flash_ddb(cls_sess);
  3213. }
  3214. static void qla4xxx_dpc_relogin(struct iscsi_cls_session *cls_sess)
  3215. {
  3216. struct iscsi_session *sess;
  3217. struct ddb_entry *ddb_entry;
  3218. struct scsi_qla_host *ha;
  3219. sess = cls_sess->dd_data;
  3220. ddb_entry = sess->dd_data;
  3221. ha = ddb_entry->ha;
  3222. if (!(ddb_entry->ddb_type == FLASH_DDB))
  3223. return;
  3224. if (test_bit(DF_DISABLE_RELOGIN, &ddb_entry->flags))
  3225. return;
  3226. if (test_and_clear_bit(DF_RELOGIN, &ddb_entry->flags) &&
  3227. !iscsi_is_session_online(cls_sess)) {
  3228. DEBUG2(ql4_printk(KERN_INFO, ha,
  3229. "relogin issued\n"));
  3230. qla4xxx_relogin_flash_ddb(cls_sess);
  3231. }
  3232. }
  3233. void qla4xxx_wake_dpc(struct scsi_qla_host *ha)
  3234. {
  3235. if (ha->dpc_thread)
  3236. queue_work(ha->dpc_thread, &ha->dpc_work);
  3237. }
  3238. static struct qla4_work_evt *
  3239. qla4xxx_alloc_work(struct scsi_qla_host *ha, uint32_t data_size,
  3240. enum qla4_work_type type)
  3241. {
  3242. struct qla4_work_evt *e;
  3243. uint32_t size = sizeof(struct qla4_work_evt) + data_size;
  3244. e = kzalloc(size, GFP_ATOMIC);
  3245. if (!e)
  3246. return NULL;
  3247. INIT_LIST_HEAD(&e->list);
  3248. e->type = type;
  3249. return e;
  3250. }
  3251. static void qla4xxx_post_work(struct scsi_qla_host *ha,
  3252. struct qla4_work_evt *e)
  3253. {
  3254. unsigned long flags;
  3255. spin_lock_irqsave(&ha->work_lock, flags);
  3256. list_add_tail(&e->list, &ha->work_list);
  3257. spin_unlock_irqrestore(&ha->work_lock, flags);
  3258. qla4xxx_wake_dpc(ha);
  3259. }
  3260. int qla4xxx_post_aen_work(struct scsi_qla_host *ha,
  3261. enum iscsi_host_event_code aen_code,
  3262. uint32_t data_size, uint8_t *data)
  3263. {
  3264. struct qla4_work_evt *e;
  3265. e = qla4xxx_alloc_work(ha, data_size, QLA4_EVENT_AEN);
  3266. if (!e)
  3267. return QLA_ERROR;
  3268. e->u.aen.code = aen_code;
  3269. e->u.aen.data_size = data_size;
  3270. memcpy(e->u.aen.data, data, data_size);
  3271. qla4xxx_post_work(ha, e);
  3272. return QLA_SUCCESS;
  3273. }
  3274. int qla4xxx_post_ping_evt_work(struct scsi_qla_host *ha,
  3275. uint32_t status, uint32_t pid,
  3276. uint32_t data_size, uint8_t *data)
  3277. {
  3278. struct qla4_work_evt *e;
  3279. e = qla4xxx_alloc_work(ha, data_size, QLA4_EVENT_PING_STATUS);
  3280. if (!e)
  3281. return QLA_ERROR;
  3282. e->u.ping.status = status;
  3283. e->u.ping.pid = pid;
  3284. e->u.ping.data_size = data_size;
  3285. memcpy(e->u.ping.data, data, data_size);
  3286. qla4xxx_post_work(ha, e);
  3287. return QLA_SUCCESS;
  3288. }
  3289. static void qla4xxx_do_work(struct scsi_qla_host *ha)
  3290. {
  3291. struct qla4_work_evt *e, *tmp;
  3292. unsigned long flags;
  3293. LIST_HEAD(work);
  3294. spin_lock_irqsave(&ha->work_lock, flags);
  3295. list_splice_init(&ha->work_list, &work);
  3296. spin_unlock_irqrestore(&ha->work_lock, flags);
  3297. list_for_each_entry_safe(e, tmp, &work, list) {
  3298. list_del_init(&e->list);
  3299. switch (e->type) {
  3300. case QLA4_EVENT_AEN:
  3301. iscsi_post_host_event(ha->host_no,
  3302. &qla4xxx_iscsi_transport,
  3303. e->u.aen.code,
  3304. e->u.aen.data_size,
  3305. e->u.aen.data);
  3306. break;
  3307. case QLA4_EVENT_PING_STATUS:
  3308. iscsi_ping_comp_event(ha->host_no,
  3309. &qla4xxx_iscsi_transport,
  3310. e->u.ping.status,
  3311. e->u.ping.pid,
  3312. e->u.ping.data_size,
  3313. e->u.ping.data);
  3314. break;
  3315. default:
  3316. ql4_printk(KERN_WARNING, ha, "event type: 0x%x not "
  3317. "supported", e->type);
  3318. }
  3319. kfree(e);
  3320. }
  3321. }
  3322. /**
  3323. * qla4xxx_do_dpc - dpc routine
  3324. * @data: in our case pointer to adapter structure
  3325. *
  3326. * This routine is a task that is schedule by the interrupt handler
  3327. * to perform the background processing for interrupts. We put it
  3328. * on a task queue that is consumed whenever the scheduler runs; that's
  3329. * so you can do anything (i.e. put the process to sleep etc). In fact,
  3330. * the mid-level tries to sleep when it reaches the driver threshold
  3331. * "host->can_queue". This can cause a panic if we were in our interrupt code.
  3332. **/
  3333. static void qla4xxx_do_dpc(struct work_struct *work)
  3334. {
  3335. struct scsi_qla_host *ha =
  3336. container_of(work, struct scsi_qla_host, dpc_work);
  3337. int status = QLA_ERROR;
  3338. DEBUG2(printk("scsi%ld: %s: DPC handler waking up."
  3339. "flags = 0x%08lx, dpc_flags = 0x%08lx\n",
  3340. ha->host_no, __func__, ha->flags, ha->dpc_flags))
  3341. /* Initialization not yet finished. Don't do anything yet. */
  3342. if (!test_bit(AF_INIT_DONE, &ha->flags))
  3343. return;
  3344. if (test_bit(AF_EEH_BUSY, &ha->flags)) {
  3345. DEBUG2(printk(KERN_INFO "scsi%ld: %s: flags = %lx\n",
  3346. ha->host_no, __func__, ha->flags));
  3347. return;
  3348. }
  3349. /* post events to application */
  3350. qla4xxx_do_work(ha);
  3351. if (is_qla80XX(ha)) {
  3352. if (test_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags)) {
  3353. if (is_qla8032(ha) || is_qla8042(ha)) {
  3354. ql4_printk(KERN_INFO, ha, "%s: disabling pause transmit on port 0 & 1.\n",
  3355. __func__);
  3356. /* disable pause frame for ISP83xx */
  3357. qla4_83xx_disable_pause(ha);
  3358. }
  3359. ha->isp_ops->idc_lock(ha);
  3360. qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DEV_STATE,
  3361. QLA8XXX_DEV_FAILED);
  3362. ha->isp_ops->idc_unlock(ha);
  3363. ql4_printk(KERN_INFO, ha, "HW State: FAILED\n");
  3364. qla4_8xxx_device_state_handler(ha);
  3365. }
  3366. if (test_bit(DPC_POST_IDC_ACK, &ha->dpc_flags)) {
  3367. if (is_qla8042(ha)) {
  3368. if (ha->idc_info.info2 &
  3369. ENABLE_INTERNAL_LOOPBACK) {
  3370. ql4_printk(KERN_INFO, ha, "%s: Disabling ACB\n",
  3371. __func__);
  3372. status = qla4_84xx_config_acb(ha,
  3373. ACB_CONFIG_DISABLE);
  3374. if (status != QLA_SUCCESS) {
  3375. ql4_printk(KERN_INFO, ha, "%s: ACB config failed\n",
  3376. __func__);
  3377. }
  3378. }
  3379. }
  3380. qla4_83xx_post_idc_ack(ha);
  3381. clear_bit(DPC_POST_IDC_ACK, &ha->dpc_flags);
  3382. }
  3383. if (is_qla8042(ha) &&
  3384. test_bit(DPC_RESTORE_ACB, &ha->dpc_flags)) {
  3385. ql4_printk(KERN_INFO, ha, "%s: Restoring ACB\n",
  3386. __func__);
  3387. if (qla4_84xx_config_acb(ha, ACB_CONFIG_SET) !=
  3388. QLA_SUCCESS) {
  3389. ql4_printk(KERN_INFO, ha, "%s: ACB config failed ",
  3390. __func__);
  3391. }
  3392. clear_bit(DPC_RESTORE_ACB, &ha->dpc_flags);
  3393. }
  3394. if (test_and_clear_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags)) {
  3395. qla4_8xxx_need_qsnt_handler(ha);
  3396. }
  3397. }
  3398. if (!test_bit(DPC_RESET_ACTIVE, &ha->dpc_flags) &&
  3399. (test_bit(DPC_RESET_HA, &ha->dpc_flags) ||
  3400. test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags) ||
  3401. test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags))) {
  3402. if ((is_qla8022(ha) && ql4xdontresethba) ||
  3403. ((is_qla8032(ha) || is_qla8042(ha)) &&
  3404. qla4_83xx_idc_dontreset(ha))) {
  3405. DEBUG2(printk("scsi%ld: %s: Don't Reset HBA\n",
  3406. ha->host_no, __func__));
  3407. clear_bit(DPC_RESET_HA, &ha->dpc_flags);
  3408. clear_bit(DPC_RESET_HA_INTR, &ha->dpc_flags);
  3409. clear_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags);
  3410. goto dpc_post_reset_ha;
  3411. }
  3412. if (test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags) ||
  3413. test_bit(DPC_RESET_HA, &ha->dpc_flags))
  3414. qla4xxx_recover_adapter(ha);
  3415. if (test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags)) {
  3416. uint8_t wait_time = RESET_INTR_TOV;
  3417. while ((readw(&ha->reg->ctrl_status) &
  3418. (CSR_SOFT_RESET | CSR_FORCE_SOFT_RESET)) != 0) {
  3419. if (--wait_time == 0)
  3420. break;
  3421. msleep(1000);
  3422. }
  3423. if (wait_time == 0)
  3424. DEBUG2(printk("scsi%ld: %s: SR|FSR "
  3425. "bit not cleared-- resetting\n",
  3426. ha->host_no, __func__));
  3427. qla4xxx_abort_active_cmds(ha, DID_RESET << 16);
  3428. if (ql4xxx_lock_drvr_wait(ha) == QLA_SUCCESS) {
  3429. qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
  3430. status = qla4xxx_recover_adapter(ha);
  3431. }
  3432. clear_bit(DPC_RESET_HA_INTR, &ha->dpc_flags);
  3433. if (status == QLA_SUCCESS)
  3434. ha->isp_ops->enable_intrs(ha);
  3435. }
  3436. }
  3437. dpc_post_reset_ha:
  3438. /* ---- process AEN? --- */
  3439. if (test_and_clear_bit(DPC_AEN, &ha->dpc_flags))
  3440. qla4xxx_process_aen(ha, PROCESS_ALL_AENS);
  3441. /* ---- Get DHCP IP Address? --- */
  3442. if (test_and_clear_bit(DPC_GET_DHCP_IP_ADDR, &ha->dpc_flags))
  3443. qla4xxx_get_dhcp_ip_address(ha);
  3444. /* ---- relogin device? --- */
  3445. if (adapter_up(ha) &&
  3446. test_and_clear_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags)) {
  3447. iscsi_host_for_each_session(ha->host, qla4xxx_dpc_relogin);
  3448. }
  3449. /* ---- link change? --- */
  3450. if (!test_bit(AF_LOOPBACK, &ha->flags) &&
  3451. test_and_clear_bit(DPC_LINK_CHANGED, &ha->dpc_flags)) {
  3452. if (!test_bit(AF_LINK_UP, &ha->flags)) {
  3453. /* ---- link down? --- */
  3454. qla4xxx_mark_all_devices_missing(ha);
  3455. } else {
  3456. /* ---- link up? --- *
  3457. * F/W will auto login to all devices ONLY ONCE after
  3458. * link up during driver initialization and runtime
  3459. * fatal error recovery. Therefore, the driver must
  3460. * manually relogin to devices when recovering from
  3461. * connection failures, logouts, expired KATO, etc. */
  3462. if (test_and_clear_bit(AF_BUILD_DDB_LIST, &ha->flags)) {
  3463. qla4xxx_build_ddb_list(ha, ha->is_reset);
  3464. iscsi_host_for_each_session(ha->host,
  3465. qla4xxx_login_flash_ddb);
  3466. } else
  3467. qla4xxx_relogin_all_devices(ha);
  3468. }
  3469. }
  3470. }
  3471. /**
  3472. * qla4xxx_free_adapter - release the adapter
  3473. * @ha: pointer to adapter structure
  3474. **/
  3475. static void qla4xxx_free_adapter(struct scsi_qla_host *ha)
  3476. {
  3477. qla4xxx_abort_active_cmds(ha, DID_NO_CONNECT << 16);
  3478. /* Turn-off interrupts on the card. */
  3479. ha->isp_ops->disable_intrs(ha);
  3480. if (is_qla40XX(ha)) {
  3481. writel(set_rmask(CSR_SCSI_PROCESSOR_INTR),
  3482. &ha->reg->ctrl_status);
  3483. readl(&ha->reg->ctrl_status);
  3484. } else if (is_qla8022(ha)) {
  3485. writel(0, &ha->qla4_82xx_reg->host_int);
  3486. readl(&ha->qla4_82xx_reg->host_int);
  3487. } else if (is_qla8032(ha) || is_qla8042(ha)) {
  3488. writel(0, &ha->qla4_83xx_reg->risc_intr);
  3489. readl(&ha->qla4_83xx_reg->risc_intr);
  3490. }
  3491. /* Remove timer thread, if present */
  3492. if (ha->timer_active)
  3493. qla4xxx_stop_timer(ha);
  3494. /* Kill the kernel thread for this host */
  3495. if (ha->dpc_thread)
  3496. destroy_workqueue(ha->dpc_thread);
  3497. /* Kill the kernel thread for this host */
  3498. if (ha->task_wq)
  3499. destroy_workqueue(ha->task_wq);
  3500. /* Put firmware in known state */
  3501. ha->isp_ops->reset_firmware(ha);
  3502. if (is_qla80XX(ha)) {
  3503. ha->isp_ops->idc_lock(ha);
  3504. qla4_8xxx_clear_drv_active(ha);
  3505. ha->isp_ops->idc_unlock(ha);
  3506. }
  3507. /* Detach interrupts */
  3508. qla4xxx_free_irqs(ha);
  3509. /* free extra memory */
  3510. qla4xxx_mem_free(ha);
  3511. }
  3512. int qla4_8xxx_iospace_config(struct scsi_qla_host *ha)
  3513. {
  3514. int status = 0;
  3515. unsigned long mem_base, mem_len, db_base, db_len;
  3516. struct pci_dev *pdev = ha->pdev;
  3517. status = pci_request_regions(pdev, DRIVER_NAME);
  3518. if (status) {
  3519. printk(KERN_WARNING
  3520. "scsi(%ld) Failed to reserve PIO regions (%s) "
  3521. "status=%d\n", ha->host_no, pci_name(pdev), status);
  3522. goto iospace_error_exit;
  3523. }
  3524. DEBUG2(printk(KERN_INFO "%s: revision-id=%d\n",
  3525. __func__, pdev->revision));
  3526. ha->revision_id = pdev->revision;
  3527. /* remap phys address */
  3528. mem_base = pci_resource_start(pdev, 0); /* 0 is for BAR 0 */
  3529. mem_len = pci_resource_len(pdev, 0);
  3530. DEBUG2(printk(KERN_INFO "%s: ioremap from %lx a size of %lx\n",
  3531. __func__, mem_base, mem_len));
  3532. /* mapping of pcibase pointer */
  3533. ha->nx_pcibase = (unsigned long)ioremap(mem_base, mem_len);
  3534. if (!ha->nx_pcibase) {
  3535. printk(KERN_ERR
  3536. "cannot remap MMIO (%s), aborting\n", pci_name(pdev));
  3537. pci_release_regions(ha->pdev);
  3538. goto iospace_error_exit;
  3539. }
  3540. /* Mapping of IO base pointer, door bell read and write pointer */
  3541. /* mapping of IO base pointer */
  3542. if (is_qla8022(ha)) {
  3543. ha->qla4_82xx_reg = (struct device_reg_82xx __iomem *)
  3544. ((uint8_t *)ha->nx_pcibase + 0xbc000 +
  3545. (ha->pdev->devfn << 11));
  3546. ha->nx_db_wr_ptr = (ha->pdev->devfn == 4 ? QLA82XX_CAM_RAM_DB1 :
  3547. QLA82XX_CAM_RAM_DB2);
  3548. } else if (is_qla8032(ha) || is_qla8042(ha)) {
  3549. ha->qla4_83xx_reg = (struct device_reg_83xx __iomem *)
  3550. ((uint8_t *)ha->nx_pcibase);
  3551. }
  3552. db_base = pci_resource_start(pdev, 4); /* doorbell is on bar 4 */
  3553. db_len = pci_resource_len(pdev, 4);
  3554. return 0;
  3555. iospace_error_exit:
  3556. return -ENOMEM;
  3557. }
  3558. /***
  3559. * qla4xxx_iospace_config - maps registers
  3560. * @ha: pointer to adapter structure
  3561. *
  3562. * This routines maps HBA's registers from the pci address space
  3563. * into the kernel virtual address space for memory mapped i/o.
  3564. **/
  3565. int qla4xxx_iospace_config(struct scsi_qla_host *ha)
  3566. {
  3567. unsigned long pio, pio_len, pio_flags;
  3568. unsigned long mmio, mmio_len, mmio_flags;
  3569. pio = pci_resource_start(ha->pdev, 0);
  3570. pio_len = pci_resource_len(ha->pdev, 0);
  3571. pio_flags = pci_resource_flags(ha->pdev, 0);
  3572. if (pio_flags & IORESOURCE_IO) {
  3573. if (pio_len < MIN_IOBASE_LEN) {
  3574. ql4_printk(KERN_WARNING, ha,
  3575. "Invalid PCI I/O region size\n");
  3576. pio = 0;
  3577. }
  3578. } else {
  3579. ql4_printk(KERN_WARNING, ha, "region #0 not a PIO resource\n");
  3580. pio = 0;
  3581. }
  3582. /* Use MMIO operations for all accesses. */
  3583. mmio = pci_resource_start(ha->pdev, 1);
  3584. mmio_len = pci_resource_len(ha->pdev, 1);
  3585. mmio_flags = pci_resource_flags(ha->pdev, 1);
  3586. if (!(mmio_flags & IORESOURCE_MEM)) {
  3587. ql4_printk(KERN_ERR, ha,
  3588. "region #0 not an MMIO resource, aborting\n");
  3589. goto iospace_error_exit;
  3590. }
  3591. if (mmio_len < MIN_IOBASE_LEN) {
  3592. ql4_printk(KERN_ERR, ha,
  3593. "Invalid PCI mem region size, aborting\n");
  3594. goto iospace_error_exit;
  3595. }
  3596. if (pci_request_regions(ha->pdev, DRIVER_NAME)) {
  3597. ql4_printk(KERN_WARNING, ha,
  3598. "Failed to reserve PIO/MMIO regions\n");
  3599. goto iospace_error_exit;
  3600. }
  3601. ha->pio_address = pio;
  3602. ha->pio_length = pio_len;
  3603. ha->reg = ioremap(mmio, MIN_IOBASE_LEN);
  3604. if (!ha->reg) {
  3605. ql4_printk(KERN_ERR, ha,
  3606. "cannot remap MMIO, aborting\n");
  3607. goto iospace_error_exit;
  3608. }
  3609. return 0;
  3610. iospace_error_exit:
  3611. return -ENOMEM;
  3612. }
  3613. static struct isp_operations qla4xxx_isp_ops = {
  3614. .iospace_config = qla4xxx_iospace_config,
  3615. .pci_config = qla4xxx_pci_config,
  3616. .disable_intrs = qla4xxx_disable_intrs,
  3617. .enable_intrs = qla4xxx_enable_intrs,
  3618. .start_firmware = qla4xxx_start_firmware,
  3619. .intr_handler = qla4xxx_intr_handler,
  3620. .interrupt_service_routine = qla4xxx_interrupt_service_routine,
  3621. .reset_chip = qla4xxx_soft_reset,
  3622. .reset_firmware = qla4xxx_hw_reset,
  3623. .queue_iocb = qla4xxx_queue_iocb,
  3624. .complete_iocb = qla4xxx_complete_iocb,
  3625. .rd_shdw_req_q_out = qla4xxx_rd_shdw_req_q_out,
  3626. .rd_shdw_rsp_q_in = qla4xxx_rd_shdw_rsp_q_in,
  3627. .get_sys_info = qla4xxx_get_sys_info,
  3628. .queue_mailbox_command = qla4xxx_queue_mbox_cmd,
  3629. .process_mailbox_interrupt = qla4xxx_process_mbox_intr,
  3630. };
  3631. static struct isp_operations qla4_82xx_isp_ops = {
  3632. .iospace_config = qla4_8xxx_iospace_config,
  3633. .pci_config = qla4_8xxx_pci_config,
  3634. .disable_intrs = qla4_82xx_disable_intrs,
  3635. .enable_intrs = qla4_82xx_enable_intrs,
  3636. .start_firmware = qla4_8xxx_load_risc,
  3637. .restart_firmware = qla4_82xx_try_start_fw,
  3638. .intr_handler = qla4_82xx_intr_handler,
  3639. .interrupt_service_routine = qla4_82xx_interrupt_service_routine,
  3640. .need_reset = qla4_8xxx_need_reset,
  3641. .reset_chip = qla4_82xx_isp_reset,
  3642. .reset_firmware = qla4_8xxx_stop_firmware,
  3643. .queue_iocb = qla4_82xx_queue_iocb,
  3644. .complete_iocb = qla4_82xx_complete_iocb,
  3645. .rd_shdw_req_q_out = qla4_82xx_rd_shdw_req_q_out,
  3646. .rd_shdw_rsp_q_in = qla4_82xx_rd_shdw_rsp_q_in,
  3647. .get_sys_info = qla4_8xxx_get_sys_info,
  3648. .rd_reg_direct = qla4_82xx_rd_32,
  3649. .wr_reg_direct = qla4_82xx_wr_32,
  3650. .rd_reg_indirect = qla4_82xx_md_rd_32,
  3651. .wr_reg_indirect = qla4_82xx_md_wr_32,
  3652. .idc_lock = qla4_82xx_idc_lock,
  3653. .idc_unlock = qla4_82xx_idc_unlock,
  3654. .rom_lock_recovery = qla4_82xx_rom_lock_recovery,
  3655. .queue_mailbox_command = qla4_82xx_queue_mbox_cmd,
  3656. .process_mailbox_interrupt = qla4_82xx_process_mbox_intr,
  3657. };
  3658. static struct isp_operations qla4_83xx_isp_ops = {
  3659. .iospace_config = qla4_8xxx_iospace_config,
  3660. .pci_config = qla4_8xxx_pci_config,
  3661. .disable_intrs = qla4_83xx_disable_intrs,
  3662. .enable_intrs = qla4_83xx_enable_intrs,
  3663. .start_firmware = qla4_8xxx_load_risc,
  3664. .restart_firmware = qla4_83xx_start_firmware,
  3665. .intr_handler = qla4_83xx_intr_handler,
  3666. .interrupt_service_routine = qla4_83xx_interrupt_service_routine,
  3667. .need_reset = qla4_8xxx_need_reset,
  3668. .reset_chip = qla4_83xx_isp_reset,
  3669. .reset_firmware = qla4_8xxx_stop_firmware,
  3670. .queue_iocb = qla4_83xx_queue_iocb,
  3671. .complete_iocb = qla4_83xx_complete_iocb,
  3672. .rd_shdw_req_q_out = qla4xxx_rd_shdw_req_q_out,
  3673. .rd_shdw_rsp_q_in = qla4xxx_rd_shdw_rsp_q_in,
  3674. .get_sys_info = qla4_8xxx_get_sys_info,
  3675. .rd_reg_direct = qla4_83xx_rd_reg,
  3676. .wr_reg_direct = qla4_83xx_wr_reg,
  3677. .rd_reg_indirect = qla4_83xx_rd_reg_indirect,
  3678. .wr_reg_indirect = qla4_83xx_wr_reg_indirect,
  3679. .idc_lock = qla4_83xx_drv_lock,
  3680. .idc_unlock = qla4_83xx_drv_unlock,
  3681. .rom_lock_recovery = qla4_83xx_rom_lock_recovery,
  3682. .queue_mailbox_command = qla4_83xx_queue_mbox_cmd,
  3683. .process_mailbox_interrupt = qla4_83xx_process_mbox_intr,
  3684. };
  3685. uint16_t qla4xxx_rd_shdw_req_q_out(struct scsi_qla_host *ha)
  3686. {
  3687. return (uint16_t)le32_to_cpu(ha->shadow_regs->req_q_out);
  3688. }
  3689. uint16_t qla4_82xx_rd_shdw_req_q_out(struct scsi_qla_host *ha)
  3690. {
  3691. return (uint16_t)le32_to_cpu(readl(&ha->qla4_82xx_reg->req_q_out));
  3692. }
  3693. uint16_t qla4xxx_rd_shdw_rsp_q_in(struct scsi_qla_host *ha)
  3694. {
  3695. return (uint16_t)le32_to_cpu(ha->shadow_regs->rsp_q_in);
  3696. }
  3697. uint16_t qla4_82xx_rd_shdw_rsp_q_in(struct scsi_qla_host *ha)
  3698. {
  3699. return (uint16_t)le32_to_cpu(readl(&ha->qla4_82xx_reg->rsp_q_in));
  3700. }
  3701. static ssize_t qla4xxx_show_boot_eth_info(void *data, int type, char *buf)
  3702. {
  3703. struct scsi_qla_host *ha = data;
  3704. char *str = buf;
  3705. int rc;
  3706. switch (type) {
  3707. case ISCSI_BOOT_ETH_FLAGS:
  3708. rc = sprintf(str, "%d\n", SYSFS_FLAG_FW_SEL_BOOT);
  3709. break;
  3710. case ISCSI_BOOT_ETH_INDEX:
  3711. rc = sprintf(str, "0\n");
  3712. break;
  3713. case ISCSI_BOOT_ETH_MAC:
  3714. rc = sysfs_format_mac(str, ha->my_mac,
  3715. MAC_ADDR_LEN);
  3716. break;
  3717. default:
  3718. rc = -ENOSYS;
  3719. break;
  3720. }
  3721. return rc;
  3722. }
  3723. static umode_t qla4xxx_eth_get_attr_visibility(void *data, int type)
  3724. {
  3725. int rc;
  3726. switch (type) {
  3727. case ISCSI_BOOT_ETH_FLAGS:
  3728. case ISCSI_BOOT_ETH_MAC:
  3729. case ISCSI_BOOT_ETH_INDEX:
  3730. rc = S_IRUGO;
  3731. break;
  3732. default:
  3733. rc = 0;
  3734. break;
  3735. }
  3736. return rc;
  3737. }
  3738. static ssize_t qla4xxx_show_boot_ini_info(void *data, int type, char *buf)
  3739. {
  3740. struct scsi_qla_host *ha = data;
  3741. char *str = buf;
  3742. int rc;
  3743. switch (type) {
  3744. case ISCSI_BOOT_INI_INITIATOR_NAME:
  3745. rc = sprintf(str, "%s\n", ha->name_string);
  3746. break;
  3747. default:
  3748. rc = -ENOSYS;
  3749. break;
  3750. }
  3751. return rc;
  3752. }
  3753. static umode_t qla4xxx_ini_get_attr_visibility(void *data, int type)
  3754. {
  3755. int rc;
  3756. switch (type) {
  3757. case ISCSI_BOOT_INI_INITIATOR_NAME:
  3758. rc = S_IRUGO;
  3759. break;
  3760. default:
  3761. rc = 0;
  3762. break;
  3763. }
  3764. return rc;
  3765. }
  3766. static ssize_t
  3767. qla4xxx_show_boot_tgt_info(struct ql4_boot_session_info *boot_sess, int type,
  3768. char *buf)
  3769. {
  3770. struct ql4_conn_info *boot_conn = &boot_sess->conn_list[0];
  3771. char *str = buf;
  3772. int rc;
  3773. switch (type) {
  3774. case ISCSI_BOOT_TGT_NAME:
  3775. rc = sprintf(buf, "%s\n", (char *)&boot_sess->target_name);
  3776. break;
  3777. case ISCSI_BOOT_TGT_IP_ADDR:
  3778. if (boot_sess->conn_list[0].dest_ipaddr.ip_type == 0x1)
  3779. rc = sprintf(buf, "%pI4\n",
  3780. &boot_conn->dest_ipaddr.ip_address);
  3781. else
  3782. rc = sprintf(str, "%pI6\n",
  3783. &boot_conn->dest_ipaddr.ip_address);
  3784. break;
  3785. case ISCSI_BOOT_TGT_PORT:
  3786. rc = sprintf(str, "%d\n", boot_conn->dest_port);
  3787. break;
  3788. case ISCSI_BOOT_TGT_CHAP_NAME:
  3789. rc = sprintf(str, "%.*s\n",
  3790. boot_conn->chap.target_chap_name_length,
  3791. (char *)&boot_conn->chap.target_chap_name);
  3792. break;
  3793. case ISCSI_BOOT_TGT_CHAP_SECRET:
  3794. rc = sprintf(str, "%.*s\n",
  3795. boot_conn->chap.target_secret_length,
  3796. (char *)&boot_conn->chap.target_secret);
  3797. break;
  3798. case ISCSI_BOOT_TGT_REV_CHAP_NAME:
  3799. rc = sprintf(str, "%.*s\n",
  3800. boot_conn->chap.intr_chap_name_length,
  3801. (char *)&boot_conn->chap.intr_chap_name);
  3802. break;
  3803. case ISCSI_BOOT_TGT_REV_CHAP_SECRET:
  3804. rc = sprintf(str, "%.*s\n",
  3805. boot_conn->chap.intr_secret_length,
  3806. (char *)&boot_conn->chap.intr_secret);
  3807. break;
  3808. case ISCSI_BOOT_TGT_FLAGS:
  3809. rc = sprintf(str, "%d\n", SYSFS_FLAG_FW_SEL_BOOT);
  3810. break;
  3811. case ISCSI_BOOT_TGT_NIC_ASSOC:
  3812. rc = sprintf(str, "0\n");
  3813. break;
  3814. default:
  3815. rc = -ENOSYS;
  3816. break;
  3817. }
  3818. return rc;
  3819. }
  3820. static ssize_t qla4xxx_show_boot_tgt_pri_info(void *data, int type, char *buf)
  3821. {
  3822. struct scsi_qla_host *ha = data;
  3823. struct ql4_boot_session_info *boot_sess = &(ha->boot_tgt.boot_pri_sess);
  3824. return qla4xxx_show_boot_tgt_info(boot_sess, type, buf);
  3825. }
  3826. static ssize_t qla4xxx_show_boot_tgt_sec_info(void *data, int type, char *buf)
  3827. {
  3828. struct scsi_qla_host *ha = data;
  3829. struct ql4_boot_session_info *boot_sess = &(ha->boot_tgt.boot_sec_sess);
  3830. return qla4xxx_show_boot_tgt_info(boot_sess, type, buf);
  3831. }
  3832. static umode_t qla4xxx_tgt_get_attr_visibility(void *data, int type)
  3833. {
  3834. int rc;
  3835. switch (type) {
  3836. case ISCSI_BOOT_TGT_NAME:
  3837. case ISCSI_BOOT_TGT_IP_ADDR:
  3838. case ISCSI_BOOT_TGT_PORT:
  3839. case ISCSI_BOOT_TGT_CHAP_NAME:
  3840. case ISCSI_BOOT_TGT_CHAP_SECRET:
  3841. case ISCSI_BOOT_TGT_REV_CHAP_NAME:
  3842. case ISCSI_BOOT_TGT_REV_CHAP_SECRET:
  3843. case ISCSI_BOOT_TGT_NIC_ASSOC:
  3844. case ISCSI_BOOT_TGT_FLAGS:
  3845. rc = S_IRUGO;
  3846. break;
  3847. default:
  3848. rc = 0;
  3849. break;
  3850. }
  3851. return rc;
  3852. }
  3853. static void qla4xxx_boot_release(void *data)
  3854. {
  3855. struct scsi_qla_host *ha = data;
  3856. scsi_host_put(ha->host);
  3857. }
  3858. static int get_fw_boot_info(struct scsi_qla_host *ha, uint16_t ddb_index[])
  3859. {
  3860. dma_addr_t buf_dma;
  3861. uint32_t addr, pri_addr, sec_addr;
  3862. uint32_t offset;
  3863. uint16_t func_num;
  3864. uint8_t val;
  3865. uint8_t *buf = NULL;
  3866. size_t size = 13 * sizeof(uint8_t);
  3867. int ret = QLA_SUCCESS;
  3868. func_num = PCI_FUNC(ha->pdev->devfn);
  3869. ql4_printk(KERN_INFO, ha, "%s: Get FW boot info for 0x%x func %d\n",
  3870. __func__, ha->pdev->device, func_num);
  3871. if (is_qla40XX(ha)) {
  3872. if (func_num == 1) {
  3873. addr = NVRAM_PORT0_BOOT_MODE;
  3874. pri_addr = NVRAM_PORT0_BOOT_PRI_TGT;
  3875. sec_addr = NVRAM_PORT0_BOOT_SEC_TGT;
  3876. } else if (func_num == 3) {
  3877. addr = NVRAM_PORT1_BOOT_MODE;
  3878. pri_addr = NVRAM_PORT1_BOOT_PRI_TGT;
  3879. sec_addr = NVRAM_PORT1_BOOT_SEC_TGT;
  3880. } else {
  3881. ret = QLA_ERROR;
  3882. goto exit_boot_info;
  3883. }
  3884. /* Check Boot Mode */
  3885. val = rd_nvram_byte(ha, addr);
  3886. if (!(val & 0x07)) {
  3887. DEBUG2(ql4_printk(KERN_INFO, ha, "%s: Adapter boot "
  3888. "options : 0x%x\n", __func__, val));
  3889. ret = QLA_ERROR;
  3890. goto exit_boot_info;
  3891. }
  3892. /* get primary valid target index */
  3893. val = rd_nvram_byte(ha, pri_addr);
  3894. if (val & BIT_7)
  3895. ddb_index[0] = (val & 0x7f);
  3896. /* get secondary valid target index */
  3897. val = rd_nvram_byte(ha, sec_addr);
  3898. if (val & BIT_7)
  3899. ddb_index[1] = (val & 0x7f);
  3900. } else if (is_qla80XX(ha)) {
  3901. buf = dma_alloc_coherent(&ha->pdev->dev, size,
  3902. &buf_dma, GFP_KERNEL);
  3903. if (!buf) {
  3904. DEBUG2(ql4_printk(KERN_ERR, ha,
  3905. "%s: Unable to allocate dma buffer\n",
  3906. __func__));
  3907. ret = QLA_ERROR;
  3908. goto exit_boot_info;
  3909. }
  3910. if (ha->port_num == 0)
  3911. offset = BOOT_PARAM_OFFSET_PORT0;
  3912. else if (ha->port_num == 1)
  3913. offset = BOOT_PARAM_OFFSET_PORT1;
  3914. else {
  3915. ret = QLA_ERROR;
  3916. goto exit_boot_info_free;
  3917. }
  3918. addr = FLASH_RAW_ACCESS_ADDR + (ha->hw.flt_iscsi_param * 4) +
  3919. offset;
  3920. if (qla4xxx_get_flash(ha, buf_dma, addr,
  3921. 13 * sizeof(uint8_t)) != QLA_SUCCESS) {
  3922. DEBUG2(ql4_printk(KERN_ERR, ha, "scsi%ld: %s: Get Flash"
  3923. " failed\n", ha->host_no, __func__));
  3924. ret = QLA_ERROR;
  3925. goto exit_boot_info_free;
  3926. }
  3927. /* Check Boot Mode */
  3928. if (!(buf[1] & 0x07)) {
  3929. DEBUG2(ql4_printk(KERN_INFO, ha, "Firmware boot options"
  3930. " : 0x%x\n", buf[1]));
  3931. ret = QLA_ERROR;
  3932. goto exit_boot_info_free;
  3933. }
  3934. /* get primary valid target index */
  3935. if (buf[2] & BIT_7)
  3936. ddb_index[0] = buf[2] & 0x7f;
  3937. /* get secondary valid target index */
  3938. if (buf[11] & BIT_7)
  3939. ddb_index[1] = buf[11] & 0x7f;
  3940. } else {
  3941. ret = QLA_ERROR;
  3942. goto exit_boot_info;
  3943. }
  3944. DEBUG2(ql4_printk(KERN_INFO, ha, "%s: Primary target ID %d, Secondary"
  3945. " target ID %d\n", __func__, ddb_index[0],
  3946. ddb_index[1]));
  3947. exit_boot_info_free:
  3948. dma_free_coherent(&ha->pdev->dev, size, buf, buf_dma);
  3949. exit_boot_info:
  3950. ha->pri_ddb_idx = ddb_index[0];
  3951. ha->sec_ddb_idx = ddb_index[1];
  3952. return ret;
  3953. }
  3954. /**
  3955. * qla4xxx_get_bidi_chap - Get a BIDI CHAP user and password
  3956. * @ha: pointer to adapter structure
  3957. * @username: CHAP username to be returned
  3958. * @password: CHAP password to be returned
  3959. *
  3960. * If a boot entry has BIDI CHAP enabled then we need to set the BIDI CHAP
  3961. * user and password in the sysfs entry in /sys/firmware/iscsi_boot#/.
  3962. * So from the CHAP cache find the first BIDI CHAP entry and set it
  3963. * to the boot record in sysfs.
  3964. **/
  3965. static int qla4xxx_get_bidi_chap(struct scsi_qla_host *ha, char *username,
  3966. char *password)
  3967. {
  3968. int i, ret = -EINVAL;
  3969. int max_chap_entries = 0;
  3970. struct ql4_chap_table *chap_table;
  3971. if (is_qla80XX(ha))
  3972. max_chap_entries = (ha->hw.flt_chap_size / 2) /
  3973. sizeof(struct ql4_chap_table);
  3974. else
  3975. max_chap_entries = MAX_CHAP_ENTRIES_40XX;
  3976. if (!ha->chap_list) {
  3977. ql4_printk(KERN_ERR, ha, "Do not have CHAP table cache\n");
  3978. return ret;
  3979. }
  3980. mutex_lock(&ha->chap_sem);
  3981. for (i = 0; i < max_chap_entries; i++) {
  3982. chap_table = (struct ql4_chap_table *)ha->chap_list + i;
  3983. if (chap_table->cookie !=
  3984. __constant_cpu_to_le16(CHAP_VALID_COOKIE)) {
  3985. continue;
  3986. }
  3987. if (chap_table->flags & BIT_7) /* local */
  3988. continue;
  3989. if (!(chap_table->flags & BIT_6)) /* Not BIDI */
  3990. continue;
  3991. strncpy(password, chap_table->secret, QL4_CHAP_MAX_SECRET_LEN);
  3992. strncpy(username, chap_table->name, QL4_CHAP_MAX_NAME_LEN);
  3993. ret = 0;
  3994. break;
  3995. }
  3996. mutex_unlock(&ha->chap_sem);
  3997. return ret;
  3998. }
  3999. static int qla4xxx_get_boot_target(struct scsi_qla_host *ha,
  4000. struct ql4_boot_session_info *boot_sess,
  4001. uint16_t ddb_index)
  4002. {
  4003. struct ql4_conn_info *boot_conn = &boot_sess->conn_list[0];
  4004. struct dev_db_entry *fw_ddb_entry;
  4005. dma_addr_t fw_ddb_entry_dma;
  4006. uint16_t idx;
  4007. uint16_t options;
  4008. int ret = QLA_SUCCESS;
  4009. fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
  4010. &fw_ddb_entry_dma, GFP_KERNEL);
  4011. if (!fw_ddb_entry) {
  4012. DEBUG2(ql4_printk(KERN_ERR, ha,
  4013. "%s: Unable to allocate dma buffer.\n",
  4014. __func__));
  4015. ret = QLA_ERROR;
  4016. return ret;
  4017. }
  4018. if (qla4xxx_bootdb_by_index(ha, fw_ddb_entry,
  4019. fw_ddb_entry_dma, ddb_index)) {
  4020. DEBUG2(ql4_printk(KERN_INFO, ha, "%s: No Flash DDB found at "
  4021. "index [%d]\n", __func__, ddb_index));
  4022. ret = QLA_ERROR;
  4023. goto exit_boot_target;
  4024. }
  4025. /* Update target name and IP from DDB */
  4026. memcpy(boot_sess->target_name, fw_ddb_entry->iscsi_name,
  4027. min(sizeof(boot_sess->target_name),
  4028. sizeof(fw_ddb_entry->iscsi_name)));
  4029. options = le16_to_cpu(fw_ddb_entry->options);
  4030. if (options & DDB_OPT_IPV6_DEVICE) {
  4031. memcpy(&boot_conn->dest_ipaddr.ip_address,
  4032. &fw_ddb_entry->ip_addr[0], IPv6_ADDR_LEN);
  4033. } else {
  4034. boot_conn->dest_ipaddr.ip_type = 0x1;
  4035. memcpy(&boot_conn->dest_ipaddr.ip_address,
  4036. &fw_ddb_entry->ip_addr[0], IP_ADDR_LEN);
  4037. }
  4038. boot_conn->dest_port = le16_to_cpu(fw_ddb_entry->port);
  4039. /* update chap information */
  4040. idx = __le16_to_cpu(fw_ddb_entry->chap_tbl_idx);
  4041. if (BIT_7 & le16_to_cpu(fw_ddb_entry->iscsi_options)) {
  4042. DEBUG2(ql4_printk(KERN_INFO, ha, "Setting chap\n"));
  4043. ret = qla4xxx_get_chap(ha, (char *)&boot_conn->chap.
  4044. target_chap_name,
  4045. (char *)&boot_conn->chap.target_secret,
  4046. idx);
  4047. if (ret) {
  4048. ql4_printk(KERN_ERR, ha, "Failed to set chap\n");
  4049. ret = QLA_ERROR;
  4050. goto exit_boot_target;
  4051. }
  4052. boot_conn->chap.target_chap_name_length = QL4_CHAP_MAX_NAME_LEN;
  4053. boot_conn->chap.target_secret_length = QL4_CHAP_MAX_SECRET_LEN;
  4054. }
  4055. if (BIT_4 & le16_to_cpu(fw_ddb_entry->iscsi_options)) {
  4056. DEBUG2(ql4_printk(KERN_INFO, ha, "Setting BIDI chap\n"));
  4057. ret = qla4xxx_get_bidi_chap(ha,
  4058. (char *)&boot_conn->chap.intr_chap_name,
  4059. (char *)&boot_conn->chap.intr_secret);
  4060. if (ret) {
  4061. ql4_printk(KERN_ERR, ha, "Failed to set BIDI chap\n");
  4062. ret = QLA_ERROR;
  4063. goto exit_boot_target;
  4064. }
  4065. boot_conn->chap.intr_chap_name_length = QL4_CHAP_MAX_NAME_LEN;
  4066. boot_conn->chap.intr_secret_length = QL4_CHAP_MAX_SECRET_LEN;
  4067. }
  4068. exit_boot_target:
  4069. dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
  4070. fw_ddb_entry, fw_ddb_entry_dma);
  4071. return ret;
  4072. }
  4073. static int qla4xxx_get_boot_info(struct scsi_qla_host *ha)
  4074. {
  4075. uint16_t ddb_index[2];
  4076. int ret = QLA_ERROR;
  4077. int rval;
  4078. memset(ddb_index, 0, sizeof(ddb_index));
  4079. ddb_index[0] = 0xffff;
  4080. ddb_index[1] = 0xffff;
  4081. ret = get_fw_boot_info(ha, ddb_index);
  4082. if (ret != QLA_SUCCESS) {
  4083. DEBUG2(ql4_printk(KERN_INFO, ha,
  4084. "%s: No boot target configured.\n", __func__));
  4085. return ret;
  4086. }
  4087. if (ql4xdisablesysfsboot)
  4088. return QLA_SUCCESS;
  4089. if (ddb_index[0] == 0xffff)
  4090. goto sec_target;
  4091. rval = qla4xxx_get_boot_target(ha, &(ha->boot_tgt.boot_pri_sess),
  4092. ddb_index[0]);
  4093. if (rval != QLA_SUCCESS) {
  4094. DEBUG2(ql4_printk(KERN_INFO, ha, "%s: Primary boot target not "
  4095. "configured\n", __func__));
  4096. } else
  4097. ret = QLA_SUCCESS;
  4098. sec_target:
  4099. if (ddb_index[1] == 0xffff)
  4100. goto exit_get_boot_info;
  4101. rval = qla4xxx_get_boot_target(ha, &(ha->boot_tgt.boot_sec_sess),
  4102. ddb_index[1]);
  4103. if (rval != QLA_SUCCESS) {
  4104. DEBUG2(ql4_printk(KERN_INFO, ha, "%s: Secondary boot target not"
  4105. " configured\n", __func__));
  4106. } else
  4107. ret = QLA_SUCCESS;
  4108. exit_get_boot_info:
  4109. return ret;
  4110. }
  4111. static int qla4xxx_setup_boot_info(struct scsi_qla_host *ha)
  4112. {
  4113. struct iscsi_boot_kobj *boot_kobj;
  4114. if (qla4xxx_get_boot_info(ha) != QLA_SUCCESS)
  4115. return QLA_ERROR;
  4116. if (ql4xdisablesysfsboot) {
  4117. ql4_printk(KERN_INFO, ha,
  4118. "%s: syfsboot disabled - driver will trigger login "
  4119. "and publish session for discovery .\n", __func__);
  4120. return QLA_SUCCESS;
  4121. }
  4122. ha->boot_kset = iscsi_boot_create_host_kset(ha->host->host_no);
  4123. if (!ha->boot_kset)
  4124. goto kset_free;
  4125. if (!scsi_host_get(ha->host))
  4126. goto kset_free;
  4127. boot_kobj = iscsi_boot_create_target(ha->boot_kset, 0, ha,
  4128. qla4xxx_show_boot_tgt_pri_info,
  4129. qla4xxx_tgt_get_attr_visibility,
  4130. qla4xxx_boot_release);
  4131. if (!boot_kobj)
  4132. goto put_host;
  4133. if (!scsi_host_get(ha->host))
  4134. goto kset_free;
  4135. boot_kobj = iscsi_boot_create_target(ha->boot_kset, 1, ha,
  4136. qla4xxx_show_boot_tgt_sec_info,
  4137. qla4xxx_tgt_get_attr_visibility,
  4138. qla4xxx_boot_release);
  4139. if (!boot_kobj)
  4140. goto put_host;
  4141. if (!scsi_host_get(ha->host))
  4142. goto kset_free;
  4143. boot_kobj = iscsi_boot_create_initiator(ha->boot_kset, 0, ha,
  4144. qla4xxx_show_boot_ini_info,
  4145. qla4xxx_ini_get_attr_visibility,
  4146. qla4xxx_boot_release);
  4147. if (!boot_kobj)
  4148. goto put_host;
  4149. if (!scsi_host_get(ha->host))
  4150. goto kset_free;
  4151. boot_kobj = iscsi_boot_create_ethernet(ha->boot_kset, 0, ha,
  4152. qla4xxx_show_boot_eth_info,
  4153. qla4xxx_eth_get_attr_visibility,
  4154. qla4xxx_boot_release);
  4155. if (!boot_kobj)
  4156. goto put_host;
  4157. return QLA_SUCCESS;
  4158. put_host:
  4159. scsi_host_put(ha->host);
  4160. kset_free:
  4161. iscsi_boot_destroy_kset(ha->boot_kset);
  4162. return -ENOMEM;
  4163. }
  4164. /**
  4165. * qla4xxx_create chap_list - Create CHAP list from FLASH
  4166. * @ha: pointer to adapter structure
  4167. *
  4168. * Read flash and make a list of CHAP entries, during login when a CHAP entry
  4169. * is received, it will be checked in this list. If entry exist then the CHAP
  4170. * entry index is set in the DDB. If CHAP entry does not exist in this list
  4171. * then a new entry is added in FLASH in CHAP table and the index obtained is
  4172. * used in the DDB.
  4173. **/
  4174. static void qla4xxx_create_chap_list(struct scsi_qla_host *ha)
  4175. {
  4176. int rval = 0;
  4177. uint8_t *chap_flash_data = NULL;
  4178. uint32_t offset;
  4179. dma_addr_t chap_dma;
  4180. uint32_t chap_size = 0;
  4181. if (is_qla40XX(ha))
  4182. chap_size = MAX_CHAP_ENTRIES_40XX *
  4183. sizeof(struct ql4_chap_table);
  4184. else /* Single region contains CHAP info for both
  4185. * ports which is divided into half for each port.
  4186. */
  4187. chap_size = ha->hw.flt_chap_size / 2;
  4188. chap_flash_data = dma_alloc_coherent(&ha->pdev->dev, chap_size,
  4189. &chap_dma, GFP_KERNEL);
  4190. if (!chap_flash_data) {
  4191. ql4_printk(KERN_ERR, ha, "No memory for chap_flash_data\n");
  4192. return;
  4193. }
  4194. if (is_qla40XX(ha))
  4195. offset = FLASH_CHAP_OFFSET;
  4196. else {
  4197. offset = FLASH_RAW_ACCESS_ADDR + (ha->hw.flt_region_chap << 2);
  4198. if (ha->port_num == 1)
  4199. offset += chap_size;
  4200. }
  4201. rval = qla4xxx_get_flash(ha, chap_dma, offset, chap_size);
  4202. if (rval != QLA_SUCCESS)
  4203. goto exit_chap_list;
  4204. if (ha->chap_list == NULL)
  4205. ha->chap_list = vmalloc(chap_size);
  4206. if (ha->chap_list == NULL) {
  4207. ql4_printk(KERN_ERR, ha, "No memory for ha->chap_list\n");
  4208. goto exit_chap_list;
  4209. }
  4210. memcpy(ha->chap_list, chap_flash_data, chap_size);
  4211. exit_chap_list:
  4212. dma_free_coherent(&ha->pdev->dev, chap_size,
  4213. chap_flash_data, chap_dma);
  4214. }
  4215. static void qla4xxx_get_param_ddb(struct ddb_entry *ddb_entry,
  4216. struct ql4_tuple_ddb *tddb)
  4217. {
  4218. struct scsi_qla_host *ha;
  4219. struct iscsi_cls_session *cls_sess;
  4220. struct iscsi_cls_conn *cls_conn;
  4221. struct iscsi_session *sess;
  4222. struct iscsi_conn *conn;
  4223. DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
  4224. ha = ddb_entry->ha;
  4225. cls_sess = ddb_entry->sess;
  4226. sess = cls_sess->dd_data;
  4227. cls_conn = ddb_entry->conn;
  4228. conn = cls_conn->dd_data;
  4229. tddb->tpgt = sess->tpgt;
  4230. tddb->port = conn->persistent_port;
  4231. strncpy(tddb->iscsi_name, sess->targetname, ISCSI_NAME_SIZE);
  4232. strncpy(tddb->ip_addr, conn->persistent_address, DDB_IPADDR_LEN);
  4233. }
  4234. static void qla4xxx_convert_param_ddb(struct dev_db_entry *fw_ddb_entry,
  4235. struct ql4_tuple_ddb *tddb,
  4236. uint8_t *flash_isid)
  4237. {
  4238. uint16_t options = 0;
  4239. tddb->tpgt = le32_to_cpu(fw_ddb_entry->tgt_portal_grp);
  4240. memcpy(&tddb->iscsi_name[0], &fw_ddb_entry->iscsi_name[0],
  4241. min(sizeof(tddb->iscsi_name), sizeof(fw_ddb_entry->iscsi_name)));
  4242. options = le16_to_cpu(fw_ddb_entry->options);
  4243. if (options & DDB_OPT_IPV6_DEVICE)
  4244. sprintf(tddb->ip_addr, "%pI6", fw_ddb_entry->ip_addr);
  4245. else
  4246. sprintf(tddb->ip_addr, "%pI4", fw_ddb_entry->ip_addr);
  4247. tddb->port = le16_to_cpu(fw_ddb_entry->port);
  4248. if (flash_isid == NULL)
  4249. memcpy(&tddb->isid[0], &fw_ddb_entry->isid[0],
  4250. sizeof(tddb->isid));
  4251. else
  4252. memcpy(&tddb->isid[0], &flash_isid[0], sizeof(tddb->isid));
  4253. }
  4254. static int qla4xxx_compare_tuple_ddb(struct scsi_qla_host *ha,
  4255. struct ql4_tuple_ddb *old_tddb,
  4256. struct ql4_tuple_ddb *new_tddb,
  4257. uint8_t is_isid_compare)
  4258. {
  4259. if (strcmp(old_tddb->iscsi_name, new_tddb->iscsi_name))
  4260. return QLA_ERROR;
  4261. if (strcmp(old_tddb->ip_addr, new_tddb->ip_addr))
  4262. return QLA_ERROR;
  4263. if (old_tddb->port != new_tddb->port)
  4264. return QLA_ERROR;
  4265. /* For multi sessions, driver generates the ISID, so do not compare
  4266. * ISID in reset path since it would be a comparison between the
  4267. * driver generated ISID and firmware generated ISID. This could
  4268. * lead to adding duplicated DDBs in the list as driver generated
  4269. * ISID would not match firmware generated ISID.
  4270. */
  4271. if (is_isid_compare) {
  4272. DEBUG2(ql4_printk(KERN_INFO, ha, "%s: old ISID [%02x%02x%02x"
  4273. "%02x%02x%02x] New ISID [%02x%02x%02x%02x%02x%02x]\n",
  4274. __func__, old_tddb->isid[5], old_tddb->isid[4],
  4275. old_tddb->isid[3], old_tddb->isid[2], old_tddb->isid[1],
  4276. old_tddb->isid[0], new_tddb->isid[5], new_tddb->isid[4],
  4277. new_tddb->isid[3], new_tddb->isid[2], new_tddb->isid[1],
  4278. new_tddb->isid[0]));
  4279. if (memcmp(&old_tddb->isid[0], &new_tddb->isid[0],
  4280. sizeof(old_tddb->isid)))
  4281. return QLA_ERROR;
  4282. }
  4283. DEBUG2(ql4_printk(KERN_INFO, ha,
  4284. "Match Found, fw[%d,%d,%s,%s], [%d,%d,%s,%s]",
  4285. old_tddb->port, old_tddb->tpgt, old_tddb->ip_addr,
  4286. old_tddb->iscsi_name, new_tddb->port, new_tddb->tpgt,
  4287. new_tddb->ip_addr, new_tddb->iscsi_name));
  4288. return QLA_SUCCESS;
  4289. }
  4290. static int qla4xxx_is_session_exists(struct scsi_qla_host *ha,
  4291. struct dev_db_entry *fw_ddb_entry)
  4292. {
  4293. struct ddb_entry *ddb_entry;
  4294. struct ql4_tuple_ddb *fw_tddb = NULL;
  4295. struct ql4_tuple_ddb *tmp_tddb = NULL;
  4296. int idx;
  4297. int ret = QLA_ERROR;
  4298. fw_tddb = vzalloc(sizeof(*fw_tddb));
  4299. if (!fw_tddb) {
  4300. DEBUG2(ql4_printk(KERN_WARNING, ha,
  4301. "Memory Allocation failed.\n"));
  4302. ret = QLA_SUCCESS;
  4303. goto exit_check;
  4304. }
  4305. tmp_tddb = vzalloc(sizeof(*tmp_tddb));
  4306. if (!tmp_tddb) {
  4307. DEBUG2(ql4_printk(KERN_WARNING, ha,
  4308. "Memory Allocation failed.\n"));
  4309. ret = QLA_SUCCESS;
  4310. goto exit_check;
  4311. }
  4312. qla4xxx_convert_param_ddb(fw_ddb_entry, fw_tddb, NULL);
  4313. for (idx = 0; idx < MAX_DDB_ENTRIES; idx++) {
  4314. ddb_entry = qla4xxx_lookup_ddb_by_fw_index(ha, idx);
  4315. if (ddb_entry == NULL)
  4316. continue;
  4317. qla4xxx_get_param_ddb(ddb_entry, tmp_tddb);
  4318. if (!qla4xxx_compare_tuple_ddb(ha, fw_tddb, tmp_tddb, false)) {
  4319. ret = QLA_SUCCESS; /* found */
  4320. goto exit_check;
  4321. }
  4322. }
  4323. exit_check:
  4324. if (fw_tddb)
  4325. vfree(fw_tddb);
  4326. if (tmp_tddb)
  4327. vfree(tmp_tddb);
  4328. return ret;
  4329. }
  4330. /**
  4331. * qla4xxx_check_existing_isid - check if target with same isid exist
  4332. * in target list
  4333. * @list_nt: list of target
  4334. * @isid: isid to check
  4335. *
  4336. * This routine return QLA_SUCCESS if target with same isid exist
  4337. **/
  4338. static int qla4xxx_check_existing_isid(struct list_head *list_nt, uint8_t *isid)
  4339. {
  4340. struct qla_ddb_index *nt_ddb_idx, *nt_ddb_idx_tmp;
  4341. struct dev_db_entry *fw_ddb_entry;
  4342. list_for_each_entry_safe(nt_ddb_idx, nt_ddb_idx_tmp, list_nt, list) {
  4343. fw_ddb_entry = &nt_ddb_idx->fw_ddb;
  4344. if (memcmp(&fw_ddb_entry->isid[0], &isid[0],
  4345. sizeof(nt_ddb_idx->fw_ddb.isid)) == 0) {
  4346. return QLA_SUCCESS;
  4347. }
  4348. }
  4349. return QLA_ERROR;
  4350. }
  4351. /**
  4352. * qla4xxx_update_isid - compare ddbs and updated isid
  4353. * @ha: Pointer to host adapter structure.
  4354. * @list_nt: list of nt target
  4355. * @fw_ddb_entry: firmware ddb entry
  4356. *
  4357. * This routine update isid if ddbs have same iqn, same isid and
  4358. * different IP addr.
  4359. * Return QLA_SUCCESS if isid is updated.
  4360. **/
  4361. static int qla4xxx_update_isid(struct scsi_qla_host *ha,
  4362. struct list_head *list_nt,
  4363. struct dev_db_entry *fw_ddb_entry)
  4364. {
  4365. uint8_t base_value, i;
  4366. base_value = fw_ddb_entry->isid[1] & 0x1f;
  4367. for (i = 0; i < 8; i++) {
  4368. fw_ddb_entry->isid[1] = (base_value | (i << 5));
  4369. if (qla4xxx_check_existing_isid(list_nt, fw_ddb_entry->isid))
  4370. break;
  4371. }
  4372. if (!qla4xxx_check_existing_isid(list_nt, fw_ddb_entry->isid))
  4373. return QLA_ERROR;
  4374. return QLA_SUCCESS;
  4375. }
  4376. /**
  4377. * qla4xxx_should_update_isid - check if isid need to update
  4378. * @ha: Pointer to host adapter structure.
  4379. * @old_tddb: ddb tuple
  4380. * @new_tddb: ddb tuple
  4381. *
  4382. * Return QLA_SUCCESS if different IP, different PORT, same iqn,
  4383. * same isid
  4384. **/
  4385. static int qla4xxx_should_update_isid(struct scsi_qla_host *ha,
  4386. struct ql4_tuple_ddb *old_tddb,
  4387. struct ql4_tuple_ddb *new_tddb)
  4388. {
  4389. if (strcmp(old_tddb->ip_addr, new_tddb->ip_addr) == 0) {
  4390. /* Same ip */
  4391. if (old_tddb->port == new_tddb->port)
  4392. return QLA_ERROR;
  4393. }
  4394. if (strcmp(old_tddb->iscsi_name, new_tddb->iscsi_name))
  4395. /* different iqn */
  4396. return QLA_ERROR;
  4397. if (memcmp(&old_tddb->isid[0], &new_tddb->isid[0],
  4398. sizeof(old_tddb->isid)))
  4399. /* different isid */
  4400. return QLA_ERROR;
  4401. return QLA_SUCCESS;
  4402. }
  4403. /**
  4404. * qla4xxx_is_flash_ddb_exists - check if fw_ddb_entry already exists in list_nt
  4405. * @ha: Pointer to host adapter structure.
  4406. * @list_nt: list of nt target.
  4407. * @fw_ddb_entry: firmware ddb entry.
  4408. *
  4409. * This routine check if fw_ddb_entry already exists in list_nt to avoid
  4410. * duplicate ddb in list_nt.
  4411. * Return QLA_SUCCESS if duplicate ddb exit in list_nl.
  4412. * Note: This function also update isid of DDB if required.
  4413. **/
  4414. static int qla4xxx_is_flash_ddb_exists(struct scsi_qla_host *ha,
  4415. struct list_head *list_nt,
  4416. struct dev_db_entry *fw_ddb_entry)
  4417. {
  4418. struct qla_ddb_index *nt_ddb_idx, *nt_ddb_idx_tmp;
  4419. struct ql4_tuple_ddb *fw_tddb = NULL;
  4420. struct ql4_tuple_ddb *tmp_tddb = NULL;
  4421. int rval, ret = QLA_ERROR;
  4422. fw_tddb = vzalloc(sizeof(*fw_tddb));
  4423. if (!fw_tddb) {
  4424. DEBUG2(ql4_printk(KERN_WARNING, ha,
  4425. "Memory Allocation failed.\n"));
  4426. ret = QLA_SUCCESS;
  4427. goto exit_check;
  4428. }
  4429. tmp_tddb = vzalloc(sizeof(*tmp_tddb));
  4430. if (!tmp_tddb) {
  4431. DEBUG2(ql4_printk(KERN_WARNING, ha,
  4432. "Memory Allocation failed.\n"));
  4433. ret = QLA_SUCCESS;
  4434. goto exit_check;
  4435. }
  4436. qla4xxx_convert_param_ddb(fw_ddb_entry, fw_tddb, NULL);
  4437. list_for_each_entry_safe(nt_ddb_idx, nt_ddb_idx_tmp, list_nt, list) {
  4438. qla4xxx_convert_param_ddb(&nt_ddb_idx->fw_ddb, tmp_tddb,
  4439. nt_ddb_idx->flash_isid);
  4440. ret = qla4xxx_compare_tuple_ddb(ha, fw_tddb, tmp_tddb, true);
  4441. /* found duplicate ddb */
  4442. if (ret == QLA_SUCCESS)
  4443. goto exit_check;
  4444. }
  4445. list_for_each_entry_safe(nt_ddb_idx, nt_ddb_idx_tmp, list_nt, list) {
  4446. qla4xxx_convert_param_ddb(&nt_ddb_idx->fw_ddb, tmp_tddb, NULL);
  4447. ret = qla4xxx_should_update_isid(ha, tmp_tddb, fw_tddb);
  4448. if (ret == QLA_SUCCESS) {
  4449. rval = qla4xxx_update_isid(ha, list_nt, fw_ddb_entry);
  4450. if (rval == QLA_SUCCESS)
  4451. ret = QLA_ERROR;
  4452. else
  4453. ret = QLA_SUCCESS;
  4454. goto exit_check;
  4455. }
  4456. }
  4457. exit_check:
  4458. if (fw_tddb)
  4459. vfree(fw_tddb);
  4460. if (tmp_tddb)
  4461. vfree(tmp_tddb);
  4462. return ret;
  4463. }
  4464. static void qla4xxx_free_ddb_list(struct list_head *list_ddb)
  4465. {
  4466. struct qla_ddb_index *ddb_idx, *ddb_idx_tmp;
  4467. list_for_each_entry_safe(ddb_idx, ddb_idx_tmp, list_ddb, list) {
  4468. list_del_init(&ddb_idx->list);
  4469. vfree(ddb_idx);
  4470. }
  4471. }
  4472. static struct iscsi_endpoint *qla4xxx_get_ep_fwdb(struct scsi_qla_host *ha,
  4473. struct dev_db_entry *fw_ddb_entry)
  4474. {
  4475. struct iscsi_endpoint *ep;
  4476. struct sockaddr_in *addr;
  4477. struct sockaddr_in6 *addr6;
  4478. struct sockaddr *t_addr;
  4479. struct sockaddr_storage *dst_addr;
  4480. char *ip;
  4481. /* TODO: need to destroy on unload iscsi_endpoint*/
  4482. dst_addr = vmalloc(sizeof(*dst_addr));
  4483. if (!dst_addr)
  4484. return NULL;
  4485. if (fw_ddb_entry->options & DDB_OPT_IPV6_DEVICE) {
  4486. t_addr = (struct sockaddr *)dst_addr;
  4487. t_addr->sa_family = AF_INET6;
  4488. addr6 = (struct sockaddr_in6 *)dst_addr;
  4489. ip = (char *)&addr6->sin6_addr;
  4490. memcpy(ip, fw_ddb_entry->ip_addr, IPv6_ADDR_LEN);
  4491. addr6->sin6_port = htons(le16_to_cpu(fw_ddb_entry->port));
  4492. } else {
  4493. t_addr = (struct sockaddr *)dst_addr;
  4494. t_addr->sa_family = AF_INET;
  4495. addr = (struct sockaddr_in *)dst_addr;
  4496. ip = (char *)&addr->sin_addr;
  4497. memcpy(ip, fw_ddb_entry->ip_addr, IP_ADDR_LEN);
  4498. addr->sin_port = htons(le16_to_cpu(fw_ddb_entry->port));
  4499. }
  4500. ep = qla4xxx_ep_connect(ha->host, (struct sockaddr *)dst_addr, 0);
  4501. vfree(dst_addr);
  4502. return ep;
  4503. }
  4504. static int qla4xxx_verify_boot_idx(struct scsi_qla_host *ha, uint16_t idx)
  4505. {
  4506. if (ql4xdisablesysfsboot)
  4507. return QLA_SUCCESS;
  4508. if (idx == ha->pri_ddb_idx || idx == ha->sec_ddb_idx)
  4509. return QLA_ERROR;
  4510. return QLA_SUCCESS;
  4511. }
  4512. static void qla4xxx_setup_flash_ddb_entry(struct scsi_qla_host *ha,
  4513. struct ddb_entry *ddb_entry,
  4514. uint16_t idx)
  4515. {
  4516. uint16_t def_timeout;
  4517. ddb_entry->ddb_type = FLASH_DDB;
  4518. ddb_entry->fw_ddb_index = INVALID_ENTRY;
  4519. ddb_entry->fw_ddb_device_state = DDB_DS_NO_CONNECTION_ACTIVE;
  4520. ddb_entry->ha = ha;
  4521. ddb_entry->unblock_sess = qla4xxx_unblock_flash_ddb;
  4522. ddb_entry->ddb_change = qla4xxx_flash_ddb_change;
  4523. atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
  4524. atomic_set(&ddb_entry->relogin_timer, 0);
  4525. atomic_set(&ddb_entry->relogin_retry_count, 0);
  4526. def_timeout = le16_to_cpu(ddb_entry->fw_ddb_entry.def_timeout);
  4527. ddb_entry->default_relogin_timeout =
  4528. (def_timeout > LOGIN_TOV) && (def_timeout < LOGIN_TOV * 10) ?
  4529. def_timeout : LOGIN_TOV;
  4530. ddb_entry->default_time2wait =
  4531. le16_to_cpu(ddb_entry->fw_ddb_entry.iscsi_def_time2wait);
  4532. if (ql4xdisablesysfsboot &&
  4533. (idx == ha->pri_ddb_idx || idx == ha->sec_ddb_idx))
  4534. set_bit(DF_BOOT_TGT, &ddb_entry->flags);
  4535. }
  4536. static void qla4xxx_wait_for_ip_configuration(struct scsi_qla_host *ha)
  4537. {
  4538. uint32_t idx = 0;
  4539. uint32_t ip_idx[IP_ADDR_COUNT] = {0, 1, 2, 3}; /* 4 IP interfaces */
  4540. uint32_t sts[MBOX_REG_COUNT];
  4541. uint32_t ip_state;
  4542. unsigned long wtime;
  4543. int ret;
  4544. wtime = jiffies + (HZ * IP_CONFIG_TOV);
  4545. do {
  4546. for (idx = 0; idx < IP_ADDR_COUNT; idx++) {
  4547. if (ip_idx[idx] == -1)
  4548. continue;
  4549. ret = qla4xxx_get_ip_state(ha, 0, ip_idx[idx], sts);
  4550. if (ret == QLA_ERROR) {
  4551. ip_idx[idx] = -1;
  4552. continue;
  4553. }
  4554. ip_state = (sts[1] & IP_STATE_MASK) >> IP_STATE_SHIFT;
  4555. DEBUG2(ql4_printk(KERN_INFO, ha,
  4556. "Waiting for IP state for idx = %d, state = 0x%x\n",
  4557. ip_idx[idx], ip_state));
  4558. if (ip_state == IP_ADDRSTATE_UNCONFIGURED ||
  4559. ip_state == IP_ADDRSTATE_INVALID ||
  4560. ip_state == IP_ADDRSTATE_PREFERRED ||
  4561. ip_state == IP_ADDRSTATE_DEPRICATED ||
  4562. ip_state == IP_ADDRSTATE_DISABLING)
  4563. ip_idx[idx] = -1;
  4564. }
  4565. /* Break if all IP states checked */
  4566. if ((ip_idx[0] == -1) &&
  4567. (ip_idx[1] == -1) &&
  4568. (ip_idx[2] == -1) &&
  4569. (ip_idx[3] == -1))
  4570. break;
  4571. schedule_timeout_uninterruptible(HZ);
  4572. } while (time_after(wtime, jiffies));
  4573. }
  4574. static void qla4xxx_build_st_list(struct scsi_qla_host *ha,
  4575. struct list_head *list_st)
  4576. {
  4577. struct qla_ddb_index *st_ddb_idx;
  4578. int max_ddbs;
  4579. int fw_idx_size;
  4580. struct dev_db_entry *fw_ddb_entry;
  4581. dma_addr_t fw_ddb_dma;
  4582. int ret;
  4583. uint32_t idx = 0, next_idx = 0;
  4584. uint32_t state = 0, conn_err = 0;
  4585. uint16_t conn_id = 0;
  4586. fw_ddb_entry = dma_pool_alloc(ha->fw_ddb_dma_pool, GFP_KERNEL,
  4587. &fw_ddb_dma);
  4588. if (fw_ddb_entry == NULL) {
  4589. DEBUG2(ql4_printk(KERN_ERR, ha, "Out of memory\n"));
  4590. goto exit_st_list;
  4591. }
  4592. max_ddbs = is_qla40XX(ha) ? MAX_DEV_DB_ENTRIES_40XX :
  4593. MAX_DEV_DB_ENTRIES;
  4594. fw_idx_size = sizeof(struct qla_ddb_index);
  4595. for (idx = 0; idx < max_ddbs; idx = next_idx) {
  4596. ret = qla4xxx_get_fwddb_entry(ha, idx, fw_ddb_entry, fw_ddb_dma,
  4597. NULL, &next_idx, &state,
  4598. &conn_err, NULL, &conn_id);
  4599. if (ret == QLA_ERROR)
  4600. break;
  4601. /* Ignore DDB if invalid state (unassigned) */
  4602. if (state == DDB_DS_UNASSIGNED)
  4603. goto continue_next_st;
  4604. /* Check if ST, add to the list_st */
  4605. if (strlen((char *) fw_ddb_entry->iscsi_name) != 0)
  4606. goto continue_next_st;
  4607. st_ddb_idx = vzalloc(fw_idx_size);
  4608. if (!st_ddb_idx)
  4609. break;
  4610. st_ddb_idx->fw_ddb_idx = idx;
  4611. list_add_tail(&st_ddb_idx->list, list_st);
  4612. continue_next_st:
  4613. if (next_idx == 0)
  4614. break;
  4615. }
  4616. exit_st_list:
  4617. if (fw_ddb_entry)
  4618. dma_pool_free(ha->fw_ddb_dma_pool, fw_ddb_entry, fw_ddb_dma);
  4619. }
  4620. /**
  4621. * qla4xxx_remove_failed_ddb - Remove inactive or failed ddb from list
  4622. * @ha: pointer to adapter structure
  4623. * @list_ddb: List from which failed ddb to be removed
  4624. *
  4625. * Iterate over the list of DDBs and find and remove DDBs that are either in
  4626. * no connection active state or failed state
  4627. **/
  4628. static void qla4xxx_remove_failed_ddb(struct scsi_qla_host *ha,
  4629. struct list_head *list_ddb)
  4630. {
  4631. struct qla_ddb_index *ddb_idx, *ddb_idx_tmp;
  4632. uint32_t next_idx = 0;
  4633. uint32_t state = 0, conn_err = 0;
  4634. int ret;
  4635. list_for_each_entry_safe(ddb_idx, ddb_idx_tmp, list_ddb, list) {
  4636. ret = qla4xxx_get_fwddb_entry(ha, ddb_idx->fw_ddb_idx,
  4637. NULL, 0, NULL, &next_idx, &state,
  4638. &conn_err, NULL, NULL);
  4639. if (ret == QLA_ERROR)
  4640. continue;
  4641. if (state == DDB_DS_NO_CONNECTION_ACTIVE ||
  4642. state == DDB_DS_SESSION_FAILED) {
  4643. list_del_init(&ddb_idx->list);
  4644. vfree(ddb_idx);
  4645. }
  4646. }
  4647. }
  4648. static int qla4xxx_sess_conn_setup(struct scsi_qla_host *ha,
  4649. struct dev_db_entry *fw_ddb_entry,
  4650. int is_reset, uint16_t idx)
  4651. {
  4652. struct iscsi_cls_session *cls_sess;
  4653. struct iscsi_session *sess;
  4654. struct iscsi_cls_conn *cls_conn;
  4655. struct iscsi_endpoint *ep;
  4656. uint16_t cmds_max = 32;
  4657. uint16_t conn_id = 0;
  4658. uint32_t initial_cmdsn = 0;
  4659. int ret = QLA_SUCCESS;
  4660. struct ddb_entry *ddb_entry = NULL;
  4661. /* Create session object, with INVALID_ENTRY,
  4662. * the targer_id would get set when we issue the login
  4663. */
  4664. cls_sess = iscsi_session_setup(&qla4xxx_iscsi_transport, ha->host,
  4665. cmds_max, sizeof(struct ddb_entry),
  4666. sizeof(struct ql4_task_data),
  4667. initial_cmdsn, INVALID_ENTRY);
  4668. if (!cls_sess) {
  4669. ret = QLA_ERROR;
  4670. goto exit_setup;
  4671. }
  4672. /*
  4673. * so calling module_put function to decrement the
  4674. * reference count.
  4675. **/
  4676. module_put(qla4xxx_iscsi_transport.owner);
  4677. sess = cls_sess->dd_data;
  4678. ddb_entry = sess->dd_data;
  4679. ddb_entry->sess = cls_sess;
  4680. cls_sess->recovery_tmo = ql4xsess_recovery_tmo;
  4681. memcpy(&ddb_entry->fw_ddb_entry, fw_ddb_entry,
  4682. sizeof(struct dev_db_entry));
  4683. qla4xxx_setup_flash_ddb_entry(ha, ddb_entry, idx);
  4684. cls_conn = iscsi_conn_setup(cls_sess, sizeof(struct qla_conn), conn_id);
  4685. if (!cls_conn) {
  4686. ret = QLA_ERROR;
  4687. goto exit_setup;
  4688. }
  4689. ddb_entry->conn = cls_conn;
  4690. /* Setup ep, for displaying attributes in sysfs */
  4691. ep = qla4xxx_get_ep_fwdb(ha, fw_ddb_entry);
  4692. if (ep) {
  4693. ep->conn = cls_conn;
  4694. cls_conn->ep = ep;
  4695. } else {
  4696. DEBUG2(ql4_printk(KERN_ERR, ha, "Unable to get ep\n"));
  4697. ret = QLA_ERROR;
  4698. goto exit_setup;
  4699. }
  4700. /* Update sess/conn params */
  4701. qla4xxx_copy_fwddb_param(ha, fw_ddb_entry, cls_sess, cls_conn);
  4702. if (is_reset == RESET_ADAPTER) {
  4703. iscsi_block_session(cls_sess);
  4704. /* Use the relogin path to discover new devices
  4705. * by short-circuting the logic of setting
  4706. * timer to relogin - instead set the flags
  4707. * to initiate login right away.
  4708. */
  4709. set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
  4710. set_bit(DF_RELOGIN, &ddb_entry->flags);
  4711. }
  4712. exit_setup:
  4713. return ret;
  4714. }
  4715. static void qla4xxx_build_nt_list(struct scsi_qla_host *ha,
  4716. struct list_head *list_nt, int is_reset)
  4717. {
  4718. struct dev_db_entry *fw_ddb_entry;
  4719. dma_addr_t fw_ddb_dma;
  4720. int max_ddbs;
  4721. int fw_idx_size;
  4722. int ret;
  4723. uint32_t idx = 0, next_idx = 0;
  4724. uint32_t state = 0, conn_err = 0;
  4725. uint16_t conn_id = 0;
  4726. struct qla_ddb_index *nt_ddb_idx;
  4727. fw_ddb_entry = dma_pool_alloc(ha->fw_ddb_dma_pool, GFP_KERNEL,
  4728. &fw_ddb_dma);
  4729. if (fw_ddb_entry == NULL) {
  4730. DEBUG2(ql4_printk(KERN_ERR, ha, "Out of memory\n"));
  4731. goto exit_nt_list;
  4732. }
  4733. max_ddbs = is_qla40XX(ha) ? MAX_DEV_DB_ENTRIES_40XX :
  4734. MAX_DEV_DB_ENTRIES;
  4735. fw_idx_size = sizeof(struct qla_ddb_index);
  4736. for (idx = 0; idx < max_ddbs; idx = next_idx) {
  4737. ret = qla4xxx_get_fwddb_entry(ha, idx, fw_ddb_entry, fw_ddb_dma,
  4738. NULL, &next_idx, &state,
  4739. &conn_err, NULL, &conn_id);
  4740. if (ret == QLA_ERROR)
  4741. break;
  4742. if (qla4xxx_verify_boot_idx(ha, idx) != QLA_SUCCESS)
  4743. goto continue_next_nt;
  4744. /* Check if NT, then add to list it */
  4745. if (strlen((char *) fw_ddb_entry->iscsi_name) == 0)
  4746. goto continue_next_nt;
  4747. if (!(state == DDB_DS_NO_CONNECTION_ACTIVE ||
  4748. state == DDB_DS_SESSION_FAILED))
  4749. goto continue_next_nt;
  4750. DEBUG2(ql4_printk(KERN_INFO, ha,
  4751. "Adding DDB to session = 0x%x\n", idx));
  4752. if (is_reset == INIT_ADAPTER) {
  4753. nt_ddb_idx = vmalloc(fw_idx_size);
  4754. if (!nt_ddb_idx)
  4755. break;
  4756. nt_ddb_idx->fw_ddb_idx = idx;
  4757. /* Copy original isid as it may get updated in function
  4758. * qla4xxx_update_isid(). We need original isid in
  4759. * function qla4xxx_compare_tuple_ddb to find duplicate
  4760. * target */
  4761. memcpy(&nt_ddb_idx->flash_isid[0],
  4762. &fw_ddb_entry->isid[0],
  4763. sizeof(nt_ddb_idx->flash_isid));
  4764. ret = qla4xxx_is_flash_ddb_exists(ha, list_nt,
  4765. fw_ddb_entry);
  4766. if (ret == QLA_SUCCESS) {
  4767. /* free nt_ddb_idx and do not add to list_nt */
  4768. vfree(nt_ddb_idx);
  4769. goto continue_next_nt;
  4770. }
  4771. /* Copy updated isid */
  4772. memcpy(&nt_ddb_idx->fw_ddb, fw_ddb_entry,
  4773. sizeof(struct dev_db_entry));
  4774. list_add_tail(&nt_ddb_idx->list, list_nt);
  4775. } else if (is_reset == RESET_ADAPTER) {
  4776. if (qla4xxx_is_session_exists(ha, fw_ddb_entry) ==
  4777. QLA_SUCCESS)
  4778. goto continue_next_nt;
  4779. }
  4780. ret = qla4xxx_sess_conn_setup(ha, fw_ddb_entry, is_reset, idx);
  4781. if (ret == QLA_ERROR)
  4782. goto exit_nt_list;
  4783. continue_next_nt:
  4784. if (next_idx == 0)
  4785. break;
  4786. }
  4787. exit_nt_list:
  4788. if (fw_ddb_entry)
  4789. dma_pool_free(ha->fw_ddb_dma_pool, fw_ddb_entry, fw_ddb_dma);
  4790. }
  4791. static void qla4xxx_build_new_nt_list(struct scsi_qla_host *ha,
  4792. struct list_head *list_nt)
  4793. {
  4794. struct dev_db_entry *fw_ddb_entry;
  4795. dma_addr_t fw_ddb_dma;
  4796. int max_ddbs;
  4797. int fw_idx_size;
  4798. int ret;
  4799. uint32_t idx = 0, next_idx = 0;
  4800. uint32_t state = 0, conn_err = 0;
  4801. uint16_t conn_id = 0;
  4802. struct qla_ddb_index *nt_ddb_idx;
  4803. fw_ddb_entry = dma_pool_alloc(ha->fw_ddb_dma_pool, GFP_KERNEL,
  4804. &fw_ddb_dma);
  4805. if (fw_ddb_entry == NULL) {
  4806. DEBUG2(ql4_printk(KERN_ERR, ha, "Out of memory\n"));
  4807. goto exit_new_nt_list;
  4808. }
  4809. max_ddbs = is_qla40XX(ha) ? MAX_DEV_DB_ENTRIES_40XX :
  4810. MAX_DEV_DB_ENTRIES;
  4811. fw_idx_size = sizeof(struct qla_ddb_index);
  4812. for (idx = 0; idx < max_ddbs; idx = next_idx) {
  4813. ret = qla4xxx_get_fwddb_entry(ha, idx, fw_ddb_entry, fw_ddb_dma,
  4814. NULL, &next_idx, &state,
  4815. &conn_err, NULL, &conn_id);
  4816. if (ret == QLA_ERROR)
  4817. break;
  4818. /* Check if NT, then add it to list */
  4819. if (strlen((char *)fw_ddb_entry->iscsi_name) == 0)
  4820. goto continue_next_new_nt;
  4821. if (!(state == DDB_DS_NO_CONNECTION_ACTIVE))
  4822. goto continue_next_new_nt;
  4823. DEBUG2(ql4_printk(KERN_INFO, ha,
  4824. "Adding DDB to session = 0x%x\n", idx));
  4825. nt_ddb_idx = vmalloc(fw_idx_size);
  4826. if (!nt_ddb_idx)
  4827. break;
  4828. nt_ddb_idx->fw_ddb_idx = idx;
  4829. ret = qla4xxx_is_session_exists(ha, fw_ddb_entry);
  4830. if (ret == QLA_SUCCESS) {
  4831. /* free nt_ddb_idx and do not add to list_nt */
  4832. vfree(nt_ddb_idx);
  4833. goto continue_next_new_nt;
  4834. }
  4835. list_add_tail(&nt_ddb_idx->list, list_nt);
  4836. ret = qla4xxx_sess_conn_setup(ha, fw_ddb_entry, RESET_ADAPTER,
  4837. idx);
  4838. if (ret == QLA_ERROR)
  4839. goto exit_new_nt_list;
  4840. continue_next_new_nt:
  4841. if (next_idx == 0)
  4842. break;
  4843. }
  4844. exit_new_nt_list:
  4845. if (fw_ddb_entry)
  4846. dma_pool_free(ha->fw_ddb_dma_pool, fw_ddb_entry, fw_ddb_dma);
  4847. }
  4848. /**
  4849. * qla4xxx_sysfs_ddb_is_non_persistent - check for non-persistence of ddb entry
  4850. * @dev: dev associated with the sysfs entry
  4851. * @data: pointer to flashnode session object
  4852. *
  4853. * Returns:
  4854. * 1: if flashnode entry is non-persistent
  4855. * 0: if flashnode entry is persistent
  4856. **/
  4857. static int qla4xxx_sysfs_ddb_is_non_persistent(struct device *dev, void *data)
  4858. {
  4859. struct iscsi_bus_flash_session *fnode_sess;
  4860. if (!iscsi_flashnode_bus_match(dev, NULL))
  4861. return 0;
  4862. fnode_sess = iscsi_dev_to_flash_session(dev);
  4863. return (fnode_sess->flash_state == DEV_DB_NON_PERSISTENT);
  4864. }
  4865. /**
  4866. * qla4xxx_sysfs_ddb_tgt_create - Create sysfs entry for target
  4867. * @ha: pointer to host
  4868. * @fw_ddb_entry: flash ddb data
  4869. * @idx: target index
  4870. * @user: if set then this call is made from userland else from kernel
  4871. *
  4872. * Returns:
  4873. * On sucess: QLA_SUCCESS
  4874. * On failure: QLA_ERROR
  4875. *
  4876. * This create separate sysfs entries for session and connection attributes of
  4877. * the given fw ddb entry.
  4878. * If this is invoked as a result of a userspace call then the entry is marked
  4879. * as nonpersistent using flash_state field.
  4880. **/
  4881. static int qla4xxx_sysfs_ddb_tgt_create(struct scsi_qla_host *ha,
  4882. struct dev_db_entry *fw_ddb_entry,
  4883. uint16_t *idx, int user)
  4884. {
  4885. struct iscsi_bus_flash_session *fnode_sess = NULL;
  4886. struct iscsi_bus_flash_conn *fnode_conn = NULL;
  4887. int rc = QLA_ERROR;
  4888. fnode_sess = iscsi_create_flashnode_sess(ha->host, *idx,
  4889. &qla4xxx_iscsi_transport, 0);
  4890. if (!fnode_sess) {
  4891. ql4_printk(KERN_ERR, ha,
  4892. "%s: Unable to create session sysfs entry for flashnode %d of host%lu\n",
  4893. __func__, *idx, ha->host_no);
  4894. goto exit_tgt_create;
  4895. }
  4896. fnode_conn = iscsi_create_flashnode_conn(ha->host, fnode_sess,
  4897. &qla4xxx_iscsi_transport, 0);
  4898. if (!fnode_conn) {
  4899. ql4_printk(KERN_ERR, ha,
  4900. "%s: Unable to create conn sysfs entry for flashnode %d of host%lu\n",
  4901. __func__, *idx, ha->host_no);
  4902. goto free_sess;
  4903. }
  4904. if (user) {
  4905. fnode_sess->flash_state = DEV_DB_NON_PERSISTENT;
  4906. } else {
  4907. fnode_sess->flash_state = DEV_DB_PERSISTENT;
  4908. if (*idx == ha->pri_ddb_idx || *idx == ha->sec_ddb_idx)
  4909. fnode_sess->is_boot_target = 1;
  4910. else
  4911. fnode_sess->is_boot_target = 0;
  4912. }
  4913. rc = qla4xxx_copy_from_fwddb_param(fnode_sess, fnode_conn,
  4914. fw_ddb_entry);
  4915. ql4_printk(KERN_INFO, ha, "%s: sysfs entry %s created\n",
  4916. __func__, fnode_sess->dev.kobj.name);
  4917. ql4_printk(KERN_INFO, ha, "%s: sysfs entry %s created\n",
  4918. __func__, fnode_conn->dev.kobj.name);
  4919. return QLA_SUCCESS;
  4920. free_sess:
  4921. iscsi_destroy_flashnode_sess(fnode_sess);
  4922. exit_tgt_create:
  4923. return QLA_ERROR;
  4924. }
  4925. /**
  4926. * qla4xxx_sysfs_ddb_add - Add new ddb entry in flash
  4927. * @shost: pointer to host
  4928. * @buf: type of ddb entry (ipv4/ipv6)
  4929. * @len: length of buf
  4930. *
  4931. * This creates new ddb entry in the flash by finding first free index and
  4932. * storing default ddb there. And then create sysfs entry for the new ddb entry.
  4933. **/
  4934. static int qla4xxx_sysfs_ddb_add(struct Scsi_Host *shost, const char *buf,
  4935. int len)
  4936. {
  4937. struct scsi_qla_host *ha = to_qla_host(shost);
  4938. struct dev_db_entry *fw_ddb_entry = NULL;
  4939. dma_addr_t fw_ddb_entry_dma;
  4940. struct device *dev;
  4941. uint16_t idx = 0;
  4942. uint16_t max_ddbs = 0;
  4943. uint32_t options = 0;
  4944. uint32_t rval = QLA_ERROR;
  4945. if (strncasecmp(PORTAL_TYPE_IPV4, buf, 4) &&
  4946. strncasecmp(PORTAL_TYPE_IPV6, buf, 4)) {
  4947. DEBUG2(ql4_printk(KERN_ERR, ha, "%s: Invalid portal type\n",
  4948. __func__));
  4949. goto exit_ddb_add;
  4950. }
  4951. max_ddbs = is_qla40XX(ha) ? MAX_PRST_DEV_DB_ENTRIES :
  4952. MAX_DEV_DB_ENTRIES;
  4953. fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
  4954. &fw_ddb_entry_dma, GFP_KERNEL);
  4955. if (!fw_ddb_entry) {
  4956. DEBUG2(ql4_printk(KERN_ERR, ha,
  4957. "%s: Unable to allocate dma buffer\n",
  4958. __func__));
  4959. goto exit_ddb_add;
  4960. }
  4961. dev = iscsi_find_flashnode_sess(ha->host, NULL,
  4962. qla4xxx_sysfs_ddb_is_non_persistent);
  4963. if (dev) {
  4964. ql4_printk(KERN_ERR, ha,
  4965. "%s: A non-persistent entry %s found\n",
  4966. __func__, dev->kobj.name);
  4967. put_device(dev);
  4968. goto exit_ddb_add;
  4969. }
  4970. /* Index 0 and 1 are reserved for boot target entries */
  4971. for (idx = 2; idx < max_ddbs; idx++) {
  4972. if (qla4xxx_flashdb_by_index(ha, fw_ddb_entry,
  4973. fw_ddb_entry_dma, idx))
  4974. break;
  4975. }
  4976. if (idx == max_ddbs)
  4977. goto exit_ddb_add;
  4978. if (!strncasecmp("ipv6", buf, 4))
  4979. options |= IPV6_DEFAULT_DDB_ENTRY;
  4980. rval = qla4xxx_get_default_ddb(ha, options, fw_ddb_entry_dma);
  4981. if (rval == QLA_ERROR)
  4982. goto exit_ddb_add;
  4983. rval = qla4xxx_sysfs_ddb_tgt_create(ha, fw_ddb_entry, &idx, 1);
  4984. exit_ddb_add:
  4985. if (fw_ddb_entry)
  4986. dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
  4987. fw_ddb_entry, fw_ddb_entry_dma);
  4988. if (rval == QLA_SUCCESS)
  4989. return idx;
  4990. else
  4991. return -EIO;
  4992. }
  4993. /**
  4994. * qla4xxx_sysfs_ddb_apply - write the target ddb contents to Flash
  4995. * @fnode_sess: pointer to session attrs of flash ddb entry
  4996. * @fnode_conn: pointer to connection attrs of flash ddb entry
  4997. *
  4998. * This writes the contents of target ddb buffer to Flash with a valid cookie
  4999. * value in order to make the ddb entry persistent.
  5000. **/
  5001. static int qla4xxx_sysfs_ddb_apply(struct iscsi_bus_flash_session *fnode_sess,
  5002. struct iscsi_bus_flash_conn *fnode_conn)
  5003. {
  5004. struct Scsi_Host *shost = iscsi_flash_session_to_shost(fnode_sess);
  5005. struct scsi_qla_host *ha = to_qla_host(shost);
  5006. uint32_t dev_db_start_offset = FLASH_OFFSET_DB_INFO;
  5007. struct dev_db_entry *fw_ddb_entry = NULL;
  5008. dma_addr_t fw_ddb_entry_dma;
  5009. uint32_t options = 0;
  5010. int rval = 0;
  5011. fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
  5012. &fw_ddb_entry_dma, GFP_KERNEL);
  5013. if (!fw_ddb_entry) {
  5014. DEBUG2(ql4_printk(KERN_ERR, ha,
  5015. "%s: Unable to allocate dma buffer\n",
  5016. __func__));
  5017. rval = -ENOMEM;
  5018. goto exit_ddb_apply;
  5019. }
  5020. if (!strncasecmp(fnode_sess->portal_type, PORTAL_TYPE_IPV6, 4))
  5021. options |= IPV6_DEFAULT_DDB_ENTRY;
  5022. rval = qla4xxx_get_default_ddb(ha, options, fw_ddb_entry_dma);
  5023. if (rval == QLA_ERROR)
  5024. goto exit_ddb_apply;
  5025. dev_db_start_offset += (fnode_sess->target_id *
  5026. sizeof(*fw_ddb_entry));
  5027. qla4xxx_copy_to_fwddb_param(fnode_sess, fnode_conn, fw_ddb_entry);
  5028. fw_ddb_entry->cookie = DDB_VALID_COOKIE;
  5029. rval = qla4xxx_set_flash(ha, fw_ddb_entry_dma, dev_db_start_offset,
  5030. sizeof(*fw_ddb_entry), FLASH_OPT_RMW_COMMIT);
  5031. if (rval == QLA_SUCCESS) {
  5032. fnode_sess->flash_state = DEV_DB_PERSISTENT;
  5033. ql4_printk(KERN_INFO, ha,
  5034. "%s: flash node %u of host %lu written to flash\n",
  5035. __func__, fnode_sess->target_id, ha->host_no);
  5036. } else {
  5037. rval = -EIO;
  5038. ql4_printk(KERN_ERR, ha,
  5039. "%s: Error while writing flash node %u of host %lu to flash\n",
  5040. __func__, fnode_sess->target_id, ha->host_no);
  5041. }
  5042. exit_ddb_apply:
  5043. if (fw_ddb_entry)
  5044. dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
  5045. fw_ddb_entry, fw_ddb_entry_dma);
  5046. return rval;
  5047. }
  5048. static ssize_t qla4xxx_sysfs_ddb_conn_open(struct scsi_qla_host *ha,
  5049. struct dev_db_entry *fw_ddb_entry,
  5050. uint16_t idx)
  5051. {
  5052. struct dev_db_entry *ddb_entry = NULL;
  5053. dma_addr_t ddb_entry_dma;
  5054. unsigned long wtime;
  5055. uint32_t mbx_sts = 0;
  5056. uint32_t state = 0, conn_err = 0;
  5057. uint16_t tmo = 0;
  5058. int ret = 0;
  5059. ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*ddb_entry),
  5060. &ddb_entry_dma, GFP_KERNEL);
  5061. if (!ddb_entry) {
  5062. DEBUG2(ql4_printk(KERN_ERR, ha,
  5063. "%s: Unable to allocate dma buffer\n",
  5064. __func__));
  5065. return QLA_ERROR;
  5066. }
  5067. memcpy(ddb_entry, fw_ddb_entry, sizeof(*ddb_entry));
  5068. ret = qla4xxx_set_ddb_entry(ha, idx, ddb_entry_dma, &mbx_sts);
  5069. if (ret != QLA_SUCCESS) {
  5070. DEBUG2(ql4_printk(KERN_ERR, ha,
  5071. "%s: Unable to set ddb entry for index %d\n",
  5072. __func__, idx));
  5073. goto exit_ddb_conn_open;
  5074. }
  5075. qla4xxx_conn_open(ha, idx);
  5076. /* To ensure that sendtargets is done, wait for at least 12 secs */
  5077. tmo = ((ha->def_timeout > LOGIN_TOV) &&
  5078. (ha->def_timeout < LOGIN_TOV * 10) ?
  5079. ha->def_timeout : LOGIN_TOV);
  5080. DEBUG2(ql4_printk(KERN_INFO, ha,
  5081. "Default time to wait for login to ddb %d\n", tmo));
  5082. wtime = jiffies + (HZ * tmo);
  5083. do {
  5084. ret = qla4xxx_get_fwddb_entry(ha, idx, NULL, 0, NULL,
  5085. NULL, &state, &conn_err, NULL,
  5086. NULL);
  5087. if (ret == QLA_ERROR)
  5088. continue;
  5089. if (state == DDB_DS_NO_CONNECTION_ACTIVE ||
  5090. state == DDB_DS_SESSION_FAILED)
  5091. break;
  5092. schedule_timeout_uninterruptible(HZ / 10);
  5093. } while (time_after(wtime, jiffies));
  5094. exit_ddb_conn_open:
  5095. if (ddb_entry)
  5096. dma_free_coherent(&ha->pdev->dev, sizeof(*ddb_entry),
  5097. ddb_entry, ddb_entry_dma);
  5098. return ret;
  5099. }
  5100. static int qla4xxx_ddb_login_st(struct scsi_qla_host *ha,
  5101. struct dev_db_entry *fw_ddb_entry)
  5102. {
  5103. struct qla_ddb_index *ddb_idx, *ddb_idx_tmp;
  5104. struct list_head list_nt;
  5105. uint16_t ddb_index;
  5106. int ret = 0;
  5107. if (test_bit(AF_ST_DISCOVERY_IN_PROGRESS, &ha->flags)) {
  5108. ql4_printk(KERN_WARNING, ha,
  5109. "%s: A discovery already in progress!\n", __func__);
  5110. return QLA_ERROR;
  5111. }
  5112. INIT_LIST_HEAD(&list_nt);
  5113. set_bit(AF_ST_DISCOVERY_IN_PROGRESS, &ha->flags);
  5114. ret = qla4xxx_get_ddb_index(ha, &ddb_index);
  5115. if (ret == QLA_ERROR)
  5116. goto exit_login_st_clr_bit;
  5117. ret = qla4xxx_sysfs_ddb_conn_open(ha, fw_ddb_entry, ddb_index);
  5118. if (ret == QLA_ERROR)
  5119. goto exit_login_st;
  5120. qla4xxx_build_new_nt_list(ha, &list_nt);
  5121. list_for_each_entry_safe(ddb_idx, ddb_idx_tmp, &list_nt, list) {
  5122. list_del_init(&ddb_idx->list);
  5123. qla4xxx_clear_ddb_entry(ha, ddb_idx->fw_ddb_idx);
  5124. vfree(ddb_idx);
  5125. }
  5126. exit_login_st:
  5127. if (qla4xxx_clear_ddb_entry(ha, ddb_index) == QLA_ERROR) {
  5128. ql4_printk(KERN_ERR, ha,
  5129. "Unable to clear DDB index = 0x%x\n", ddb_index);
  5130. }
  5131. clear_bit(ddb_index, ha->ddb_idx_map);
  5132. exit_login_st_clr_bit:
  5133. clear_bit(AF_ST_DISCOVERY_IN_PROGRESS, &ha->flags);
  5134. return ret;
  5135. }
  5136. static int qla4xxx_ddb_login_nt(struct scsi_qla_host *ha,
  5137. struct dev_db_entry *fw_ddb_entry,
  5138. uint16_t idx)
  5139. {
  5140. int ret = QLA_ERROR;
  5141. ret = qla4xxx_is_session_exists(ha, fw_ddb_entry);
  5142. if (ret != QLA_SUCCESS)
  5143. ret = qla4xxx_sess_conn_setup(ha, fw_ddb_entry, RESET_ADAPTER,
  5144. idx);
  5145. else
  5146. ret = -EPERM;
  5147. return ret;
  5148. }
  5149. /**
  5150. * qla4xxx_sysfs_ddb_login - Login to the specified target
  5151. * @fnode_sess: pointer to session attrs of flash ddb entry
  5152. * @fnode_conn: pointer to connection attrs of flash ddb entry
  5153. *
  5154. * This logs in to the specified target
  5155. **/
  5156. static int qla4xxx_sysfs_ddb_login(struct iscsi_bus_flash_session *fnode_sess,
  5157. struct iscsi_bus_flash_conn *fnode_conn)
  5158. {
  5159. struct Scsi_Host *shost = iscsi_flash_session_to_shost(fnode_sess);
  5160. struct scsi_qla_host *ha = to_qla_host(shost);
  5161. struct dev_db_entry *fw_ddb_entry = NULL;
  5162. dma_addr_t fw_ddb_entry_dma;
  5163. uint32_t options = 0;
  5164. int ret = 0;
  5165. if (fnode_sess->flash_state == DEV_DB_NON_PERSISTENT) {
  5166. ql4_printk(KERN_ERR, ha,
  5167. "%s: Target info is not persistent\n", __func__);
  5168. ret = -EIO;
  5169. goto exit_ddb_login;
  5170. }
  5171. fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
  5172. &fw_ddb_entry_dma, GFP_KERNEL);
  5173. if (!fw_ddb_entry) {
  5174. DEBUG2(ql4_printk(KERN_ERR, ha,
  5175. "%s: Unable to allocate dma buffer\n",
  5176. __func__));
  5177. ret = -ENOMEM;
  5178. goto exit_ddb_login;
  5179. }
  5180. if (!strncasecmp(fnode_sess->portal_type, PORTAL_TYPE_IPV6, 4))
  5181. options |= IPV6_DEFAULT_DDB_ENTRY;
  5182. ret = qla4xxx_get_default_ddb(ha, options, fw_ddb_entry_dma);
  5183. if (ret == QLA_ERROR)
  5184. goto exit_ddb_login;
  5185. qla4xxx_copy_to_fwddb_param(fnode_sess, fnode_conn, fw_ddb_entry);
  5186. fw_ddb_entry->cookie = DDB_VALID_COOKIE;
  5187. if (strlen((char *)fw_ddb_entry->iscsi_name) == 0)
  5188. ret = qla4xxx_ddb_login_st(ha, fw_ddb_entry);
  5189. else
  5190. ret = qla4xxx_ddb_login_nt(ha, fw_ddb_entry,
  5191. fnode_sess->target_id);
  5192. if (ret > 0)
  5193. ret = -EIO;
  5194. exit_ddb_login:
  5195. if (fw_ddb_entry)
  5196. dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
  5197. fw_ddb_entry, fw_ddb_entry_dma);
  5198. return ret;
  5199. }
  5200. /**
  5201. * qla4xxx_sysfs_ddb_logout_sid - Logout session for the specified target
  5202. * @cls_sess: pointer to session to be logged out
  5203. *
  5204. * This performs session log out from the specified target
  5205. **/
  5206. static int qla4xxx_sysfs_ddb_logout_sid(struct iscsi_cls_session *cls_sess)
  5207. {
  5208. struct iscsi_session *sess;
  5209. struct ddb_entry *ddb_entry = NULL;
  5210. struct scsi_qla_host *ha;
  5211. struct dev_db_entry *fw_ddb_entry = NULL;
  5212. dma_addr_t fw_ddb_entry_dma;
  5213. unsigned long flags;
  5214. unsigned long wtime;
  5215. uint32_t ddb_state;
  5216. int options;
  5217. int ret = 0;
  5218. sess = cls_sess->dd_data;
  5219. ddb_entry = sess->dd_data;
  5220. ha = ddb_entry->ha;
  5221. if (ddb_entry->ddb_type != FLASH_DDB) {
  5222. ql4_printk(KERN_ERR, ha, "%s: Not a flash node session\n",
  5223. __func__);
  5224. ret = -ENXIO;
  5225. goto exit_ddb_logout;
  5226. }
  5227. if (test_bit(DF_BOOT_TGT, &ddb_entry->flags)) {
  5228. ql4_printk(KERN_ERR, ha,
  5229. "%s: Logout from boot target entry is not permitted.\n",
  5230. __func__);
  5231. ret = -EPERM;
  5232. goto exit_ddb_logout;
  5233. }
  5234. fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
  5235. &fw_ddb_entry_dma, GFP_KERNEL);
  5236. if (!fw_ddb_entry) {
  5237. ql4_printk(KERN_ERR, ha,
  5238. "%s: Unable to allocate dma buffer\n", __func__);
  5239. ret = -ENOMEM;
  5240. goto exit_ddb_logout;
  5241. }
  5242. if (test_and_set_bit(DF_DISABLE_RELOGIN, &ddb_entry->flags))
  5243. goto ddb_logout_init;
  5244. ret = qla4xxx_get_fwddb_entry(ha, ddb_entry->fw_ddb_index,
  5245. fw_ddb_entry, fw_ddb_entry_dma,
  5246. NULL, NULL, &ddb_state, NULL,
  5247. NULL, NULL);
  5248. if (ret == QLA_ERROR)
  5249. goto ddb_logout_init;
  5250. if (ddb_state == DDB_DS_SESSION_ACTIVE)
  5251. goto ddb_logout_init;
  5252. /* wait until next relogin is triggered using DF_RELOGIN and
  5253. * clear DF_RELOGIN to avoid invocation of further relogin
  5254. */
  5255. wtime = jiffies + (HZ * RELOGIN_TOV);
  5256. do {
  5257. if (test_and_clear_bit(DF_RELOGIN, &ddb_entry->flags))
  5258. goto ddb_logout_init;
  5259. schedule_timeout_uninterruptible(HZ);
  5260. } while ((time_after(wtime, jiffies)));
  5261. ddb_logout_init:
  5262. atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
  5263. atomic_set(&ddb_entry->relogin_timer, 0);
  5264. options = LOGOUT_OPTION_CLOSE_SESSION;
  5265. qla4xxx_session_logout_ddb(ha, ddb_entry, options);
  5266. memset(fw_ddb_entry, 0, sizeof(*fw_ddb_entry));
  5267. wtime = jiffies + (HZ * LOGOUT_TOV);
  5268. do {
  5269. ret = qla4xxx_get_fwddb_entry(ha, ddb_entry->fw_ddb_index,
  5270. fw_ddb_entry, fw_ddb_entry_dma,
  5271. NULL, NULL, &ddb_state, NULL,
  5272. NULL, NULL);
  5273. if (ret == QLA_ERROR)
  5274. goto ddb_logout_clr_sess;
  5275. if ((ddb_state == DDB_DS_NO_CONNECTION_ACTIVE) ||
  5276. (ddb_state == DDB_DS_SESSION_FAILED))
  5277. goto ddb_logout_clr_sess;
  5278. schedule_timeout_uninterruptible(HZ);
  5279. } while ((time_after(wtime, jiffies)));
  5280. ddb_logout_clr_sess:
  5281. qla4xxx_clear_ddb_entry(ha, ddb_entry->fw_ddb_index);
  5282. /*
  5283. * we have decremented the reference count of the driver
  5284. * when we setup the session to have the driver unload
  5285. * to be seamless without actually destroying the
  5286. * session
  5287. **/
  5288. try_module_get(qla4xxx_iscsi_transport.owner);
  5289. iscsi_destroy_endpoint(ddb_entry->conn->ep);
  5290. spin_lock_irqsave(&ha->hardware_lock, flags);
  5291. qla4xxx_free_ddb(ha, ddb_entry);
  5292. clear_bit(ddb_entry->fw_ddb_index, ha->ddb_idx_map);
  5293. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  5294. iscsi_session_teardown(ddb_entry->sess);
  5295. clear_bit(DF_DISABLE_RELOGIN, &ddb_entry->flags);
  5296. ret = QLA_SUCCESS;
  5297. exit_ddb_logout:
  5298. if (fw_ddb_entry)
  5299. dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
  5300. fw_ddb_entry, fw_ddb_entry_dma);
  5301. return ret;
  5302. }
  5303. /**
  5304. * qla4xxx_sysfs_ddb_logout - Logout from the specified target
  5305. * @fnode_sess: pointer to session attrs of flash ddb entry
  5306. * @fnode_conn: pointer to connection attrs of flash ddb entry
  5307. *
  5308. * This performs log out from the specified target
  5309. **/
  5310. static int qla4xxx_sysfs_ddb_logout(struct iscsi_bus_flash_session *fnode_sess,
  5311. struct iscsi_bus_flash_conn *fnode_conn)
  5312. {
  5313. struct Scsi_Host *shost = iscsi_flash_session_to_shost(fnode_sess);
  5314. struct scsi_qla_host *ha = to_qla_host(shost);
  5315. struct ql4_tuple_ddb *flash_tddb = NULL;
  5316. struct ql4_tuple_ddb *tmp_tddb = NULL;
  5317. struct dev_db_entry *fw_ddb_entry = NULL;
  5318. struct ddb_entry *ddb_entry = NULL;
  5319. dma_addr_t fw_ddb_dma;
  5320. uint32_t next_idx = 0;
  5321. uint32_t state = 0, conn_err = 0;
  5322. uint16_t conn_id = 0;
  5323. int idx, index;
  5324. int status, ret = 0;
  5325. fw_ddb_entry = dma_pool_alloc(ha->fw_ddb_dma_pool, GFP_KERNEL,
  5326. &fw_ddb_dma);
  5327. if (fw_ddb_entry == NULL) {
  5328. ql4_printk(KERN_ERR, ha, "%s:Out of memory\n", __func__);
  5329. ret = -ENOMEM;
  5330. goto exit_ddb_logout;
  5331. }
  5332. flash_tddb = vzalloc(sizeof(*flash_tddb));
  5333. if (!flash_tddb) {
  5334. ql4_printk(KERN_WARNING, ha,
  5335. "%s:Memory Allocation failed.\n", __func__);
  5336. ret = -ENOMEM;
  5337. goto exit_ddb_logout;
  5338. }
  5339. tmp_tddb = vzalloc(sizeof(*tmp_tddb));
  5340. if (!tmp_tddb) {
  5341. ql4_printk(KERN_WARNING, ha,
  5342. "%s:Memory Allocation failed.\n", __func__);
  5343. ret = -ENOMEM;
  5344. goto exit_ddb_logout;
  5345. }
  5346. if (!fnode_sess->targetname) {
  5347. ql4_printk(KERN_ERR, ha,
  5348. "%s:Cannot logout from SendTarget entry\n",
  5349. __func__);
  5350. ret = -EPERM;
  5351. goto exit_ddb_logout;
  5352. }
  5353. if (fnode_sess->is_boot_target) {
  5354. ql4_printk(KERN_ERR, ha,
  5355. "%s: Logout from boot target entry is not permitted.\n",
  5356. __func__);
  5357. ret = -EPERM;
  5358. goto exit_ddb_logout;
  5359. }
  5360. strncpy(flash_tddb->iscsi_name, fnode_sess->targetname,
  5361. ISCSI_NAME_SIZE);
  5362. if (!strncmp(fnode_sess->portal_type, PORTAL_TYPE_IPV6, 4))
  5363. sprintf(flash_tddb->ip_addr, "%pI6", fnode_conn->ipaddress);
  5364. else
  5365. sprintf(flash_tddb->ip_addr, "%pI4", fnode_conn->ipaddress);
  5366. flash_tddb->tpgt = fnode_sess->tpgt;
  5367. flash_tddb->port = fnode_conn->port;
  5368. COPY_ISID(flash_tddb->isid, fnode_sess->isid);
  5369. for (idx = 0; idx < MAX_DDB_ENTRIES; idx++) {
  5370. ddb_entry = qla4xxx_lookup_ddb_by_fw_index(ha, idx);
  5371. if (ddb_entry == NULL)
  5372. continue;
  5373. if (ddb_entry->ddb_type != FLASH_DDB)
  5374. continue;
  5375. index = ddb_entry->sess->target_id;
  5376. status = qla4xxx_get_fwddb_entry(ha, index, fw_ddb_entry,
  5377. fw_ddb_dma, NULL, &next_idx,
  5378. &state, &conn_err, NULL,
  5379. &conn_id);
  5380. if (status == QLA_ERROR) {
  5381. ret = -ENOMEM;
  5382. break;
  5383. }
  5384. qla4xxx_convert_param_ddb(fw_ddb_entry, tmp_tddb, NULL);
  5385. status = qla4xxx_compare_tuple_ddb(ha, flash_tddb, tmp_tddb,
  5386. true);
  5387. if (status == QLA_SUCCESS) {
  5388. ret = qla4xxx_sysfs_ddb_logout_sid(ddb_entry->sess);
  5389. break;
  5390. }
  5391. }
  5392. if (idx == MAX_DDB_ENTRIES)
  5393. ret = -ESRCH;
  5394. exit_ddb_logout:
  5395. if (flash_tddb)
  5396. vfree(flash_tddb);
  5397. if (tmp_tddb)
  5398. vfree(tmp_tddb);
  5399. if (fw_ddb_entry)
  5400. dma_pool_free(ha->fw_ddb_dma_pool, fw_ddb_entry, fw_ddb_dma);
  5401. return ret;
  5402. }
  5403. static int
  5404. qla4xxx_sysfs_ddb_get_param(struct iscsi_bus_flash_session *fnode_sess,
  5405. int param, char *buf)
  5406. {
  5407. struct Scsi_Host *shost = iscsi_flash_session_to_shost(fnode_sess);
  5408. struct scsi_qla_host *ha = to_qla_host(shost);
  5409. struct iscsi_bus_flash_conn *fnode_conn;
  5410. struct ql4_chap_table chap_tbl;
  5411. struct device *dev;
  5412. int parent_type;
  5413. int rc = 0;
  5414. dev = iscsi_find_flashnode_conn(fnode_sess);
  5415. if (!dev)
  5416. return -EIO;
  5417. fnode_conn = iscsi_dev_to_flash_conn(dev);
  5418. switch (param) {
  5419. case ISCSI_FLASHNODE_IS_FW_ASSIGNED_IPV6:
  5420. rc = sprintf(buf, "%u\n", fnode_conn->is_fw_assigned_ipv6);
  5421. break;
  5422. case ISCSI_FLASHNODE_PORTAL_TYPE:
  5423. rc = sprintf(buf, "%s\n", fnode_sess->portal_type);
  5424. break;
  5425. case ISCSI_FLASHNODE_AUTO_SND_TGT_DISABLE:
  5426. rc = sprintf(buf, "%u\n", fnode_sess->auto_snd_tgt_disable);
  5427. break;
  5428. case ISCSI_FLASHNODE_DISCOVERY_SESS:
  5429. rc = sprintf(buf, "%u\n", fnode_sess->discovery_sess);
  5430. break;
  5431. case ISCSI_FLASHNODE_ENTRY_EN:
  5432. rc = sprintf(buf, "%u\n", fnode_sess->entry_state);
  5433. break;
  5434. case ISCSI_FLASHNODE_HDR_DGST_EN:
  5435. rc = sprintf(buf, "%u\n", fnode_conn->hdrdgst_en);
  5436. break;
  5437. case ISCSI_FLASHNODE_DATA_DGST_EN:
  5438. rc = sprintf(buf, "%u\n", fnode_conn->datadgst_en);
  5439. break;
  5440. case ISCSI_FLASHNODE_IMM_DATA_EN:
  5441. rc = sprintf(buf, "%u\n", fnode_sess->imm_data_en);
  5442. break;
  5443. case ISCSI_FLASHNODE_INITIAL_R2T_EN:
  5444. rc = sprintf(buf, "%u\n", fnode_sess->initial_r2t_en);
  5445. break;
  5446. case ISCSI_FLASHNODE_DATASEQ_INORDER:
  5447. rc = sprintf(buf, "%u\n", fnode_sess->dataseq_inorder_en);
  5448. break;
  5449. case ISCSI_FLASHNODE_PDU_INORDER:
  5450. rc = sprintf(buf, "%u\n", fnode_sess->pdu_inorder_en);
  5451. break;
  5452. case ISCSI_FLASHNODE_CHAP_AUTH_EN:
  5453. rc = sprintf(buf, "%u\n", fnode_sess->chap_auth_en);
  5454. break;
  5455. case ISCSI_FLASHNODE_SNACK_REQ_EN:
  5456. rc = sprintf(buf, "%u\n", fnode_conn->snack_req_en);
  5457. break;
  5458. case ISCSI_FLASHNODE_DISCOVERY_LOGOUT_EN:
  5459. rc = sprintf(buf, "%u\n", fnode_sess->discovery_logout_en);
  5460. break;
  5461. case ISCSI_FLASHNODE_BIDI_CHAP_EN:
  5462. rc = sprintf(buf, "%u\n", fnode_sess->bidi_chap_en);
  5463. break;
  5464. case ISCSI_FLASHNODE_DISCOVERY_AUTH_OPTIONAL:
  5465. rc = sprintf(buf, "%u\n", fnode_sess->discovery_auth_optional);
  5466. break;
  5467. case ISCSI_FLASHNODE_ERL:
  5468. rc = sprintf(buf, "%u\n", fnode_sess->erl);
  5469. break;
  5470. case ISCSI_FLASHNODE_TCP_TIMESTAMP_STAT:
  5471. rc = sprintf(buf, "%u\n", fnode_conn->tcp_timestamp_stat);
  5472. break;
  5473. case ISCSI_FLASHNODE_TCP_NAGLE_DISABLE:
  5474. rc = sprintf(buf, "%u\n", fnode_conn->tcp_nagle_disable);
  5475. break;
  5476. case ISCSI_FLASHNODE_TCP_WSF_DISABLE:
  5477. rc = sprintf(buf, "%u\n", fnode_conn->tcp_wsf_disable);
  5478. break;
  5479. case ISCSI_FLASHNODE_TCP_TIMER_SCALE:
  5480. rc = sprintf(buf, "%u\n", fnode_conn->tcp_timer_scale);
  5481. break;
  5482. case ISCSI_FLASHNODE_TCP_TIMESTAMP_EN:
  5483. rc = sprintf(buf, "%u\n", fnode_conn->tcp_timestamp_en);
  5484. break;
  5485. case ISCSI_FLASHNODE_IP_FRAG_DISABLE:
  5486. rc = sprintf(buf, "%u\n", fnode_conn->fragment_disable);
  5487. break;
  5488. case ISCSI_FLASHNODE_MAX_RECV_DLENGTH:
  5489. rc = sprintf(buf, "%u\n", fnode_conn->max_recv_dlength);
  5490. break;
  5491. case ISCSI_FLASHNODE_MAX_XMIT_DLENGTH:
  5492. rc = sprintf(buf, "%u\n", fnode_conn->max_xmit_dlength);
  5493. break;
  5494. case ISCSI_FLASHNODE_FIRST_BURST:
  5495. rc = sprintf(buf, "%u\n", fnode_sess->first_burst);
  5496. break;
  5497. case ISCSI_FLASHNODE_DEF_TIME2WAIT:
  5498. rc = sprintf(buf, "%u\n", fnode_sess->time2wait);
  5499. break;
  5500. case ISCSI_FLASHNODE_DEF_TIME2RETAIN:
  5501. rc = sprintf(buf, "%u\n", fnode_sess->time2retain);
  5502. break;
  5503. case ISCSI_FLASHNODE_MAX_R2T:
  5504. rc = sprintf(buf, "%u\n", fnode_sess->max_r2t);
  5505. break;
  5506. case ISCSI_FLASHNODE_KEEPALIVE_TMO:
  5507. rc = sprintf(buf, "%u\n", fnode_conn->keepalive_timeout);
  5508. break;
  5509. case ISCSI_FLASHNODE_ISID:
  5510. rc = sprintf(buf, "%02x%02x%02x%02x%02x%02x\n",
  5511. fnode_sess->isid[0], fnode_sess->isid[1],
  5512. fnode_sess->isid[2], fnode_sess->isid[3],
  5513. fnode_sess->isid[4], fnode_sess->isid[5]);
  5514. break;
  5515. case ISCSI_FLASHNODE_TSID:
  5516. rc = sprintf(buf, "%u\n", fnode_sess->tsid);
  5517. break;
  5518. case ISCSI_FLASHNODE_PORT:
  5519. rc = sprintf(buf, "%d\n", fnode_conn->port);
  5520. break;
  5521. case ISCSI_FLASHNODE_MAX_BURST:
  5522. rc = sprintf(buf, "%u\n", fnode_sess->max_burst);
  5523. break;
  5524. case ISCSI_FLASHNODE_DEF_TASKMGMT_TMO:
  5525. rc = sprintf(buf, "%u\n",
  5526. fnode_sess->default_taskmgmt_timeout);
  5527. break;
  5528. case ISCSI_FLASHNODE_IPADDR:
  5529. if (!strncmp(fnode_sess->portal_type, PORTAL_TYPE_IPV6, 4))
  5530. rc = sprintf(buf, "%pI6\n", fnode_conn->ipaddress);
  5531. else
  5532. rc = sprintf(buf, "%pI4\n", fnode_conn->ipaddress);
  5533. break;
  5534. case ISCSI_FLASHNODE_ALIAS:
  5535. if (fnode_sess->targetalias)
  5536. rc = sprintf(buf, "%s\n", fnode_sess->targetalias);
  5537. else
  5538. rc = sprintf(buf, "\n");
  5539. break;
  5540. case ISCSI_FLASHNODE_REDIRECT_IPADDR:
  5541. if (!strncmp(fnode_sess->portal_type, PORTAL_TYPE_IPV6, 4))
  5542. rc = sprintf(buf, "%pI6\n",
  5543. fnode_conn->redirect_ipaddr);
  5544. else
  5545. rc = sprintf(buf, "%pI4\n",
  5546. fnode_conn->redirect_ipaddr);
  5547. break;
  5548. case ISCSI_FLASHNODE_MAX_SEGMENT_SIZE:
  5549. rc = sprintf(buf, "%u\n", fnode_conn->max_segment_size);
  5550. break;
  5551. case ISCSI_FLASHNODE_LOCAL_PORT:
  5552. rc = sprintf(buf, "%u\n", fnode_conn->local_port);
  5553. break;
  5554. case ISCSI_FLASHNODE_IPV4_TOS:
  5555. rc = sprintf(buf, "%u\n", fnode_conn->ipv4_tos);
  5556. break;
  5557. case ISCSI_FLASHNODE_IPV6_TC:
  5558. if (!strncmp(fnode_sess->portal_type, PORTAL_TYPE_IPV6, 4))
  5559. rc = sprintf(buf, "%u\n",
  5560. fnode_conn->ipv6_traffic_class);
  5561. else
  5562. rc = sprintf(buf, "\n");
  5563. break;
  5564. case ISCSI_FLASHNODE_IPV6_FLOW_LABEL:
  5565. rc = sprintf(buf, "%u\n", fnode_conn->ipv6_flow_label);
  5566. break;
  5567. case ISCSI_FLASHNODE_LINK_LOCAL_IPV6:
  5568. if (!strncmp(fnode_sess->portal_type, PORTAL_TYPE_IPV6, 4))
  5569. rc = sprintf(buf, "%pI6\n",
  5570. fnode_conn->link_local_ipv6_addr);
  5571. else
  5572. rc = sprintf(buf, "\n");
  5573. break;
  5574. case ISCSI_FLASHNODE_DISCOVERY_PARENT_IDX:
  5575. rc = sprintf(buf, "%u\n", fnode_sess->discovery_parent_idx);
  5576. break;
  5577. case ISCSI_FLASHNODE_DISCOVERY_PARENT_TYPE:
  5578. if (fnode_sess->discovery_parent_type == DDB_ISNS)
  5579. parent_type = ISCSI_DISC_PARENT_ISNS;
  5580. else if (fnode_sess->discovery_parent_type == DDB_NO_LINK)
  5581. parent_type = ISCSI_DISC_PARENT_UNKNOWN;
  5582. else if (fnode_sess->discovery_parent_type < MAX_DDB_ENTRIES)
  5583. parent_type = ISCSI_DISC_PARENT_SENDTGT;
  5584. else
  5585. parent_type = ISCSI_DISC_PARENT_UNKNOWN;
  5586. rc = sprintf(buf, "%s\n",
  5587. iscsi_get_discovery_parent_name(parent_type));
  5588. break;
  5589. case ISCSI_FLASHNODE_NAME:
  5590. if (fnode_sess->targetname)
  5591. rc = sprintf(buf, "%s\n", fnode_sess->targetname);
  5592. else
  5593. rc = sprintf(buf, "\n");
  5594. break;
  5595. case ISCSI_FLASHNODE_TPGT:
  5596. rc = sprintf(buf, "%u\n", fnode_sess->tpgt);
  5597. break;
  5598. case ISCSI_FLASHNODE_TCP_XMIT_WSF:
  5599. rc = sprintf(buf, "%u\n", fnode_conn->tcp_xmit_wsf);
  5600. break;
  5601. case ISCSI_FLASHNODE_TCP_RECV_WSF:
  5602. rc = sprintf(buf, "%u\n", fnode_conn->tcp_recv_wsf);
  5603. break;
  5604. case ISCSI_FLASHNODE_CHAP_OUT_IDX:
  5605. rc = sprintf(buf, "%u\n", fnode_sess->chap_out_idx);
  5606. break;
  5607. case ISCSI_FLASHNODE_USERNAME:
  5608. if (fnode_sess->chap_auth_en) {
  5609. qla4xxx_get_uni_chap_at_index(ha,
  5610. chap_tbl.name,
  5611. chap_tbl.secret,
  5612. fnode_sess->chap_out_idx);
  5613. rc = sprintf(buf, "%s\n", chap_tbl.name);
  5614. } else {
  5615. rc = sprintf(buf, "\n");
  5616. }
  5617. break;
  5618. case ISCSI_FLASHNODE_PASSWORD:
  5619. if (fnode_sess->chap_auth_en) {
  5620. qla4xxx_get_uni_chap_at_index(ha,
  5621. chap_tbl.name,
  5622. chap_tbl.secret,
  5623. fnode_sess->chap_out_idx);
  5624. rc = sprintf(buf, "%s\n", chap_tbl.secret);
  5625. } else {
  5626. rc = sprintf(buf, "\n");
  5627. }
  5628. break;
  5629. case ISCSI_FLASHNODE_STATSN:
  5630. rc = sprintf(buf, "%u\n", fnode_conn->statsn);
  5631. break;
  5632. case ISCSI_FLASHNODE_EXP_STATSN:
  5633. rc = sprintf(buf, "%u\n", fnode_conn->exp_statsn);
  5634. break;
  5635. case ISCSI_FLASHNODE_IS_BOOT_TGT:
  5636. rc = sprintf(buf, "%u\n", fnode_sess->is_boot_target);
  5637. break;
  5638. default:
  5639. rc = -ENOSYS;
  5640. break;
  5641. }
  5642. put_device(dev);
  5643. return rc;
  5644. }
  5645. /**
  5646. * qla4xxx_sysfs_ddb_set_param - Set parameter for firmware DDB entry
  5647. * @fnode_sess: pointer to session attrs of flash ddb entry
  5648. * @fnode_conn: pointer to connection attrs of flash ddb entry
  5649. * @data: Parameters and their values to update
  5650. * @len: len of data
  5651. *
  5652. * This sets the parameter of flash ddb entry and writes them to flash
  5653. **/
  5654. static int
  5655. qla4xxx_sysfs_ddb_set_param(struct iscsi_bus_flash_session *fnode_sess,
  5656. struct iscsi_bus_flash_conn *fnode_conn,
  5657. void *data, int len)
  5658. {
  5659. struct Scsi_Host *shost = iscsi_flash_session_to_shost(fnode_sess);
  5660. struct scsi_qla_host *ha = to_qla_host(shost);
  5661. struct iscsi_flashnode_param_info *fnode_param;
  5662. struct nlattr *attr;
  5663. int rc = QLA_ERROR;
  5664. uint32_t rem = len;
  5665. nla_for_each_attr(attr, data, len, rem) {
  5666. fnode_param = nla_data(attr);
  5667. switch (fnode_param->param) {
  5668. case ISCSI_FLASHNODE_IS_FW_ASSIGNED_IPV6:
  5669. fnode_conn->is_fw_assigned_ipv6 = fnode_param->value[0];
  5670. break;
  5671. case ISCSI_FLASHNODE_PORTAL_TYPE:
  5672. memcpy(fnode_sess->portal_type, fnode_param->value,
  5673. strlen(fnode_sess->portal_type));
  5674. break;
  5675. case ISCSI_FLASHNODE_AUTO_SND_TGT_DISABLE:
  5676. fnode_sess->auto_snd_tgt_disable =
  5677. fnode_param->value[0];
  5678. break;
  5679. case ISCSI_FLASHNODE_DISCOVERY_SESS:
  5680. fnode_sess->discovery_sess = fnode_param->value[0];
  5681. break;
  5682. case ISCSI_FLASHNODE_ENTRY_EN:
  5683. fnode_sess->entry_state = fnode_param->value[0];
  5684. break;
  5685. case ISCSI_FLASHNODE_HDR_DGST_EN:
  5686. fnode_conn->hdrdgst_en = fnode_param->value[0];
  5687. break;
  5688. case ISCSI_FLASHNODE_DATA_DGST_EN:
  5689. fnode_conn->datadgst_en = fnode_param->value[0];
  5690. break;
  5691. case ISCSI_FLASHNODE_IMM_DATA_EN:
  5692. fnode_sess->imm_data_en = fnode_param->value[0];
  5693. break;
  5694. case ISCSI_FLASHNODE_INITIAL_R2T_EN:
  5695. fnode_sess->initial_r2t_en = fnode_param->value[0];
  5696. break;
  5697. case ISCSI_FLASHNODE_DATASEQ_INORDER:
  5698. fnode_sess->dataseq_inorder_en = fnode_param->value[0];
  5699. break;
  5700. case ISCSI_FLASHNODE_PDU_INORDER:
  5701. fnode_sess->pdu_inorder_en = fnode_param->value[0];
  5702. break;
  5703. case ISCSI_FLASHNODE_CHAP_AUTH_EN:
  5704. fnode_sess->chap_auth_en = fnode_param->value[0];
  5705. break;
  5706. case ISCSI_FLASHNODE_SNACK_REQ_EN:
  5707. fnode_conn->snack_req_en = fnode_param->value[0];
  5708. break;
  5709. case ISCSI_FLASHNODE_DISCOVERY_LOGOUT_EN:
  5710. fnode_sess->discovery_logout_en = fnode_param->value[0];
  5711. break;
  5712. case ISCSI_FLASHNODE_BIDI_CHAP_EN:
  5713. fnode_sess->bidi_chap_en = fnode_param->value[0];
  5714. break;
  5715. case ISCSI_FLASHNODE_DISCOVERY_AUTH_OPTIONAL:
  5716. fnode_sess->discovery_auth_optional =
  5717. fnode_param->value[0];
  5718. break;
  5719. case ISCSI_FLASHNODE_ERL:
  5720. fnode_sess->erl = fnode_param->value[0];
  5721. break;
  5722. case ISCSI_FLASHNODE_TCP_TIMESTAMP_STAT:
  5723. fnode_conn->tcp_timestamp_stat = fnode_param->value[0];
  5724. break;
  5725. case ISCSI_FLASHNODE_TCP_NAGLE_DISABLE:
  5726. fnode_conn->tcp_nagle_disable = fnode_param->value[0];
  5727. break;
  5728. case ISCSI_FLASHNODE_TCP_WSF_DISABLE:
  5729. fnode_conn->tcp_wsf_disable = fnode_param->value[0];
  5730. break;
  5731. case ISCSI_FLASHNODE_TCP_TIMER_SCALE:
  5732. fnode_conn->tcp_timer_scale = fnode_param->value[0];
  5733. break;
  5734. case ISCSI_FLASHNODE_TCP_TIMESTAMP_EN:
  5735. fnode_conn->tcp_timestamp_en = fnode_param->value[0];
  5736. break;
  5737. case ISCSI_FLASHNODE_IP_FRAG_DISABLE:
  5738. fnode_conn->fragment_disable = fnode_param->value[0];
  5739. break;
  5740. case ISCSI_FLASHNODE_MAX_RECV_DLENGTH:
  5741. fnode_conn->max_recv_dlength =
  5742. *(unsigned *)fnode_param->value;
  5743. break;
  5744. case ISCSI_FLASHNODE_MAX_XMIT_DLENGTH:
  5745. fnode_conn->max_xmit_dlength =
  5746. *(unsigned *)fnode_param->value;
  5747. break;
  5748. case ISCSI_FLASHNODE_FIRST_BURST:
  5749. fnode_sess->first_burst =
  5750. *(unsigned *)fnode_param->value;
  5751. break;
  5752. case ISCSI_FLASHNODE_DEF_TIME2WAIT:
  5753. fnode_sess->time2wait = *(uint16_t *)fnode_param->value;
  5754. break;
  5755. case ISCSI_FLASHNODE_DEF_TIME2RETAIN:
  5756. fnode_sess->time2retain =
  5757. *(uint16_t *)fnode_param->value;
  5758. break;
  5759. case ISCSI_FLASHNODE_MAX_R2T:
  5760. fnode_sess->max_r2t =
  5761. *(uint16_t *)fnode_param->value;
  5762. break;
  5763. case ISCSI_FLASHNODE_KEEPALIVE_TMO:
  5764. fnode_conn->keepalive_timeout =
  5765. *(uint16_t *)fnode_param->value;
  5766. break;
  5767. case ISCSI_FLASHNODE_ISID:
  5768. memcpy(fnode_sess->isid, fnode_param->value,
  5769. sizeof(fnode_sess->isid));
  5770. break;
  5771. case ISCSI_FLASHNODE_TSID:
  5772. fnode_sess->tsid = *(uint16_t *)fnode_param->value;
  5773. break;
  5774. case ISCSI_FLASHNODE_PORT:
  5775. fnode_conn->port = *(uint16_t *)fnode_param->value;
  5776. break;
  5777. case ISCSI_FLASHNODE_MAX_BURST:
  5778. fnode_sess->max_burst = *(unsigned *)fnode_param->value;
  5779. break;
  5780. case ISCSI_FLASHNODE_DEF_TASKMGMT_TMO:
  5781. fnode_sess->default_taskmgmt_timeout =
  5782. *(uint16_t *)fnode_param->value;
  5783. break;
  5784. case ISCSI_FLASHNODE_IPADDR:
  5785. memcpy(fnode_conn->ipaddress, fnode_param->value,
  5786. IPv6_ADDR_LEN);
  5787. break;
  5788. case ISCSI_FLASHNODE_ALIAS:
  5789. rc = iscsi_switch_str_param(&fnode_sess->targetalias,
  5790. (char *)fnode_param->value);
  5791. break;
  5792. case ISCSI_FLASHNODE_REDIRECT_IPADDR:
  5793. memcpy(fnode_conn->redirect_ipaddr, fnode_param->value,
  5794. IPv6_ADDR_LEN);
  5795. break;
  5796. case ISCSI_FLASHNODE_MAX_SEGMENT_SIZE:
  5797. fnode_conn->max_segment_size =
  5798. *(unsigned *)fnode_param->value;
  5799. break;
  5800. case ISCSI_FLASHNODE_LOCAL_PORT:
  5801. fnode_conn->local_port =
  5802. *(uint16_t *)fnode_param->value;
  5803. break;
  5804. case ISCSI_FLASHNODE_IPV4_TOS:
  5805. fnode_conn->ipv4_tos = fnode_param->value[0];
  5806. break;
  5807. case ISCSI_FLASHNODE_IPV6_TC:
  5808. fnode_conn->ipv6_traffic_class = fnode_param->value[0];
  5809. break;
  5810. case ISCSI_FLASHNODE_IPV6_FLOW_LABEL:
  5811. fnode_conn->ipv6_flow_label = fnode_param->value[0];
  5812. break;
  5813. case ISCSI_FLASHNODE_NAME:
  5814. rc = iscsi_switch_str_param(&fnode_sess->targetname,
  5815. (char *)fnode_param->value);
  5816. break;
  5817. case ISCSI_FLASHNODE_TPGT:
  5818. fnode_sess->tpgt = *(uint16_t *)fnode_param->value;
  5819. break;
  5820. case ISCSI_FLASHNODE_LINK_LOCAL_IPV6:
  5821. memcpy(fnode_conn->link_local_ipv6_addr,
  5822. fnode_param->value, IPv6_ADDR_LEN);
  5823. break;
  5824. case ISCSI_FLASHNODE_DISCOVERY_PARENT_IDX:
  5825. fnode_sess->discovery_parent_idx =
  5826. *(uint16_t *)fnode_param->value;
  5827. break;
  5828. case ISCSI_FLASHNODE_TCP_XMIT_WSF:
  5829. fnode_conn->tcp_xmit_wsf =
  5830. *(uint8_t *)fnode_param->value;
  5831. break;
  5832. case ISCSI_FLASHNODE_TCP_RECV_WSF:
  5833. fnode_conn->tcp_recv_wsf =
  5834. *(uint8_t *)fnode_param->value;
  5835. break;
  5836. case ISCSI_FLASHNODE_STATSN:
  5837. fnode_conn->statsn = *(uint32_t *)fnode_param->value;
  5838. break;
  5839. case ISCSI_FLASHNODE_EXP_STATSN:
  5840. fnode_conn->exp_statsn =
  5841. *(uint32_t *)fnode_param->value;
  5842. break;
  5843. default:
  5844. ql4_printk(KERN_ERR, ha,
  5845. "%s: No such sysfs attribute\n", __func__);
  5846. rc = -ENOSYS;
  5847. goto exit_set_param;
  5848. }
  5849. }
  5850. rc = qla4xxx_sysfs_ddb_apply(fnode_sess, fnode_conn);
  5851. exit_set_param:
  5852. return rc;
  5853. }
  5854. /**
  5855. * qla4xxx_sysfs_ddb_delete - Delete firmware DDB entry
  5856. * @fnode_sess: pointer to session attrs of flash ddb entry
  5857. *
  5858. * This invalidates the flash ddb entry at the given index
  5859. **/
  5860. static int qla4xxx_sysfs_ddb_delete(struct iscsi_bus_flash_session *fnode_sess)
  5861. {
  5862. struct Scsi_Host *shost = iscsi_flash_session_to_shost(fnode_sess);
  5863. struct scsi_qla_host *ha = to_qla_host(shost);
  5864. uint32_t dev_db_start_offset;
  5865. uint32_t dev_db_end_offset;
  5866. struct dev_db_entry *fw_ddb_entry = NULL;
  5867. dma_addr_t fw_ddb_entry_dma;
  5868. uint16_t *ddb_cookie = NULL;
  5869. size_t ddb_size = 0;
  5870. void *pddb = NULL;
  5871. int target_id;
  5872. int rc = 0;
  5873. if (fnode_sess->is_boot_target) {
  5874. rc = -EPERM;
  5875. DEBUG2(ql4_printk(KERN_ERR, ha,
  5876. "%s: Deletion of boot target entry is not permitted.\n",
  5877. __func__));
  5878. goto exit_ddb_del;
  5879. }
  5880. if (fnode_sess->flash_state == DEV_DB_NON_PERSISTENT)
  5881. goto sysfs_ddb_del;
  5882. if (is_qla40XX(ha)) {
  5883. dev_db_start_offset = FLASH_OFFSET_DB_INFO;
  5884. dev_db_end_offset = FLASH_OFFSET_DB_END;
  5885. dev_db_start_offset += (fnode_sess->target_id *
  5886. sizeof(*fw_ddb_entry));
  5887. ddb_size = sizeof(*fw_ddb_entry);
  5888. } else {
  5889. dev_db_start_offset = FLASH_RAW_ACCESS_ADDR +
  5890. (ha->hw.flt_region_ddb << 2);
  5891. /* flt_ddb_size is DDB table size for both ports
  5892. * so divide it by 2 to calculate the offset for second port
  5893. */
  5894. if (ha->port_num == 1)
  5895. dev_db_start_offset += (ha->hw.flt_ddb_size / 2);
  5896. dev_db_end_offset = dev_db_start_offset +
  5897. (ha->hw.flt_ddb_size / 2);
  5898. dev_db_start_offset += (fnode_sess->target_id *
  5899. sizeof(*fw_ddb_entry));
  5900. dev_db_start_offset += offsetof(struct dev_db_entry, cookie);
  5901. ddb_size = sizeof(*ddb_cookie);
  5902. }
  5903. DEBUG2(ql4_printk(KERN_ERR, ha, "%s: start offset=%u, end offset=%u\n",
  5904. __func__, dev_db_start_offset, dev_db_end_offset));
  5905. if (dev_db_start_offset > dev_db_end_offset) {
  5906. rc = -EIO;
  5907. DEBUG2(ql4_printk(KERN_ERR, ha, "%s:Invalid DDB index %u\n",
  5908. __func__, fnode_sess->target_id));
  5909. goto exit_ddb_del;
  5910. }
  5911. pddb = dma_alloc_coherent(&ha->pdev->dev, ddb_size,
  5912. &fw_ddb_entry_dma, GFP_KERNEL);
  5913. if (!pddb) {
  5914. rc = -ENOMEM;
  5915. DEBUG2(ql4_printk(KERN_ERR, ha,
  5916. "%s: Unable to allocate dma buffer\n",
  5917. __func__));
  5918. goto exit_ddb_del;
  5919. }
  5920. if (is_qla40XX(ha)) {
  5921. fw_ddb_entry = pddb;
  5922. memset(fw_ddb_entry, 0, ddb_size);
  5923. ddb_cookie = &fw_ddb_entry->cookie;
  5924. } else {
  5925. ddb_cookie = pddb;
  5926. }
  5927. /* invalidate the cookie */
  5928. *ddb_cookie = 0xFFEE;
  5929. qla4xxx_set_flash(ha, fw_ddb_entry_dma, dev_db_start_offset,
  5930. ddb_size, FLASH_OPT_RMW_COMMIT);
  5931. sysfs_ddb_del:
  5932. target_id = fnode_sess->target_id;
  5933. iscsi_destroy_flashnode_sess(fnode_sess);
  5934. ql4_printk(KERN_INFO, ha,
  5935. "%s: session and conn entries for flashnode %u of host %lu deleted\n",
  5936. __func__, target_id, ha->host_no);
  5937. exit_ddb_del:
  5938. if (pddb)
  5939. dma_free_coherent(&ha->pdev->dev, ddb_size, pddb,
  5940. fw_ddb_entry_dma);
  5941. return rc;
  5942. }
  5943. /**
  5944. * qla4xxx_sysfs_ddb_export - Create sysfs entries for firmware DDBs
  5945. * @ha: pointer to adapter structure
  5946. *
  5947. * Export the firmware DDB for all send targets and normal targets to sysfs.
  5948. **/
  5949. static int qla4xxx_sysfs_ddb_export(struct scsi_qla_host *ha)
  5950. {
  5951. struct dev_db_entry *fw_ddb_entry = NULL;
  5952. dma_addr_t fw_ddb_entry_dma;
  5953. uint16_t max_ddbs;
  5954. uint16_t idx = 0;
  5955. int ret = QLA_SUCCESS;
  5956. fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev,
  5957. sizeof(*fw_ddb_entry),
  5958. &fw_ddb_entry_dma, GFP_KERNEL);
  5959. if (!fw_ddb_entry) {
  5960. DEBUG2(ql4_printk(KERN_ERR, ha,
  5961. "%s: Unable to allocate dma buffer\n",
  5962. __func__));
  5963. return -ENOMEM;
  5964. }
  5965. max_ddbs = is_qla40XX(ha) ? MAX_PRST_DEV_DB_ENTRIES :
  5966. MAX_DEV_DB_ENTRIES;
  5967. for (idx = 0; idx < max_ddbs; idx++) {
  5968. if (qla4xxx_flashdb_by_index(ha, fw_ddb_entry, fw_ddb_entry_dma,
  5969. idx))
  5970. continue;
  5971. ret = qla4xxx_sysfs_ddb_tgt_create(ha, fw_ddb_entry, &idx, 0);
  5972. if (ret) {
  5973. ret = -EIO;
  5974. break;
  5975. }
  5976. }
  5977. dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry), fw_ddb_entry,
  5978. fw_ddb_entry_dma);
  5979. return ret;
  5980. }
  5981. static void qla4xxx_sysfs_ddb_remove(struct scsi_qla_host *ha)
  5982. {
  5983. iscsi_destroy_all_flashnode(ha->host);
  5984. }
  5985. /**
  5986. * qla4xxx_build_ddb_list - Build ddb list and setup sessions
  5987. * @ha: pointer to adapter structure
  5988. * @is_reset: Is this init path or reset path
  5989. *
  5990. * Create a list of sendtargets (st) from firmware DDBs, issue send targets
  5991. * using connection open, then create the list of normal targets (nt)
  5992. * from firmware DDBs. Based on the list of nt setup session and connection
  5993. * objects.
  5994. **/
  5995. void qla4xxx_build_ddb_list(struct scsi_qla_host *ha, int is_reset)
  5996. {
  5997. uint16_t tmo = 0;
  5998. struct list_head list_st, list_nt;
  5999. struct qla_ddb_index *st_ddb_idx, *st_ddb_idx_tmp;
  6000. unsigned long wtime;
  6001. if (!test_bit(AF_LINK_UP, &ha->flags)) {
  6002. set_bit(AF_BUILD_DDB_LIST, &ha->flags);
  6003. ha->is_reset = is_reset;
  6004. return;
  6005. }
  6006. INIT_LIST_HEAD(&list_st);
  6007. INIT_LIST_HEAD(&list_nt);
  6008. qla4xxx_build_st_list(ha, &list_st);
  6009. /* Before issuing conn open mbox, ensure all IPs states are configured
  6010. * Note, conn open fails if IPs are not configured
  6011. */
  6012. qla4xxx_wait_for_ip_configuration(ha);
  6013. /* Go thru the STs and fire the sendtargets by issuing conn open mbx */
  6014. list_for_each_entry_safe(st_ddb_idx, st_ddb_idx_tmp, &list_st, list) {
  6015. qla4xxx_conn_open(ha, st_ddb_idx->fw_ddb_idx);
  6016. }
  6017. /* Wait to ensure all sendtargets are done for min 12 sec wait */
  6018. tmo = ((ha->def_timeout > LOGIN_TOV) &&
  6019. (ha->def_timeout < LOGIN_TOV * 10) ?
  6020. ha->def_timeout : LOGIN_TOV);
  6021. DEBUG2(ql4_printk(KERN_INFO, ha,
  6022. "Default time to wait for build ddb %d\n", tmo));
  6023. wtime = jiffies + (HZ * tmo);
  6024. do {
  6025. if (list_empty(&list_st))
  6026. break;
  6027. qla4xxx_remove_failed_ddb(ha, &list_st);
  6028. schedule_timeout_uninterruptible(HZ / 10);
  6029. } while (time_after(wtime, jiffies));
  6030. /* Free up the sendtargets list */
  6031. qla4xxx_free_ddb_list(&list_st);
  6032. qla4xxx_build_nt_list(ha, &list_nt, is_reset);
  6033. qla4xxx_free_ddb_list(&list_nt);
  6034. qla4xxx_free_ddb_index(ha);
  6035. }
  6036. /**
  6037. * qla4xxx_wait_login_resp_boot_tgt - Wait for iSCSI boot target login
  6038. * response.
  6039. * @ha: pointer to adapter structure
  6040. *
  6041. * When the boot entry is normal iSCSI target then DF_BOOT_TGT flag will be
  6042. * set in DDB and we will wait for login response of boot targets during
  6043. * probe.
  6044. **/
  6045. static void qla4xxx_wait_login_resp_boot_tgt(struct scsi_qla_host *ha)
  6046. {
  6047. struct ddb_entry *ddb_entry;
  6048. struct dev_db_entry *fw_ddb_entry = NULL;
  6049. dma_addr_t fw_ddb_entry_dma;
  6050. unsigned long wtime;
  6051. uint32_t ddb_state;
  6052. int max_ddbs, idx, ret;
  6053. max_ddbs = is_qla40XX(ha) ? MAX_DEV_DB_ENTRIES_40XX :
  6054. MAX_DEV_DB_ENTRIES;
  6055. fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
  6056. &fw_ddb_entry_dma, GFP_KERNEL);
  6057. if (!fw_ddb_entry) {
  6058. ql4_printk(KERN_ERR, ha,
  6059. "%s: Unable to allocate dma buffer\n", __func__);
  6060. goto exit_login_resp;
  6061. }
  6062. wtime = jiffies + (HZ * BOOT_LOGIN_RESP_TOV);
  6063. for (idx = 0; idx < max_ddbs; idx++) {
  6064. ddb_entry = qla4xxx_lookup_ddb_by_fw_index(ha, idx);
  6065. if (ddb_entry == NULL)
  6066. continue;
  6067. if (test_bit(DF_BOOT_TGT, &ddb_entry->flags)) {
  6068. DEBUG2(ql4_printk(KERN_INFO, ha,
  6069. "%s: DDB index [%d]\n", __func__,
  6070. ddb_entry->fw_ddb_index));
  6071. do {
  6072. ret = qla4xxx_get_fwddb_entry(ha,
  6073. ddb_entry->fw_ddb_index,
  6074. fw_ddb_entry, fw_ddb_entry_dma,
  6075. NULL, NULL, &ddb_state, NULL,
  6076. NULL, NULL);
  6077. if (ret == QLA_ERROR)
  6078. goto exit_login_resp;
  6079. if ((ddb_state == DDB_DS_SESSION_ACTIVE) ||
  6080. (ddb_state == DDB_DS_SESSION_FAILED))
  6081. break;
  6082. schedule_timeout_uninterruptible(HZ);
  6083. } while ((time_after(wtime, jiffies)));
  6084. if (!time_after(wtime, jiffies)) {
  6085. DEBUG2(ql4_printk(KERN_INFO, ha,
  6086. "%s: Login response wait timer expired\n",
  6087. __func__));
  6088. goto exit_login_resp;
  6089. }
  6090. }
  6091. }
  6092. exit_login_resp:
  6093. if (fw_ddb_entry)
  6094. dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
  6095. fw_ddb_entry, fw_ddb_entry_dma);
  6096. }
  6097. /**
  6098. * qla4xxx_probe_adapter - callback function to probe HBA
  6099. * @pdev: pointer to pci_dev structure
  6100. * @pci_device_id: pointer to pci_device entry
  6101. *
  6102. * This routine will probe for Qlogic 4xxx iSCSI host adapters.
  6103. * It returns zero if successful. It also initializes all data necessary for
  6104. * the driver.
  6105. **/
  6106. static int qla4xxx_probe_adapter(struct pci_dev *pdev,
  6107. const struct pci_device_id *ent)
  6108. {
  6109. int ret = -ENODEV, status;
  6110. struct Scsi_Host *host;
  6111. struct scsi_qla_host *ha;
  6112. uint8_t init_retry_count = 0;
  6113. char buf[34];
  6114. struct qla4_8xxx_legacy_intr_set *nx_legacy_intr;
  6115. uint32_t dev_state;
  6116. if (pci_enable_device(pdev))
  6117. return -1;
  6118. host = iscsi_host_alloc(&qla4xxx_driver_template, sizeof(*ha), 0);
  6119. if (host == NULL) {
  6120. printk(KERN_WARNING
  6121. "qla4xxx: Couldn't allocate host from scsi layer!\n");
  6122. goto probe_disable_device;
  6123. }
  6124. /* Clear our data area */
  6125. ha = to_qla_host(host);
  6126. memset(ha, 0, sizeof(*ha));
  6127. /* Save the information from PCI BIOS. */
  6128. ha->pdev = pdev;
  6129. ha->host = host;
  6130. ha->host_no = host->host_no;
  6131. ha->func_num = PCI_FUNC(ha->pdev->devfn);
  6132. pci_enable_pcie_error_reporting(pdev);
  6133. /* Setup Runtime configurable options */
  6134. if (is_qla8022(ha)) {
  6135. ha->isp_ops = &qla4_82xx_isp_ops;
  6136. ha->reg_tbl = (uint32_t *) qla4_82xx_reg_tbl;
  6137. ha->qdr_sn_window = -1;
  6138. ha->ddr_mn_window = -1;
  6139. ha->curr_window = 255;
  6140. nx_legacy_intr = &legacy_intr[ha->func_num];
  6141. ha->nx_legacy_intr.int_vec_bit = nx_legacy_intr->int_vec_bit;
  6142. ha->nx_legacy_intr.tgt_status_reg =
  6143. nx_legacy_intr->tgt_status_reg;
  6144. ha->nx_legacy_intr.tgt_mask_reg = nx_legacy_intr->tgt_mask_reg;
  6145. ha->nx_legacy_intr.pci_int_reg = nx_legacy_intr->pci_int_reg;
  6146. } else if (is_qla8032(ha) || is_qla8042(ha)) {
  6147. ha->isp_ops = &qla4_83xx_isp_ops;
  6148. ha->reg_tbl = (uint32_t *)qla4_83xx_reg_tbl;
  6149. } else {
  6150. ha->isp_ops = &qla4xxx_isp_ops;
  6151. }
  6152. if (is_qla80XX(ha)) {
  6153. rwlock_init(&ha->hw_lock);
  6154. ha->pf_bit = ha->func_num << 16;
  6155. /* Set EEH reset type to fundamental if required by hba */
  6156. pdev->needs_freset = 1;
  6157. }
  6158. /* Configure PCI I/O space. */
  6159. ret = ha->isp_ops->iospace_config(ha);
  6160. if (ret)
  6161. goto probe_failed_ioconfig;
  6162. ql4_printk(KERN_INFO, ha, "Found an ISP%04x, irq %d, iobase 0x%p\n",
  6163. pdev->device, pdev->irq, ha->reg);
  6164. qla4xxx_config_dma_addressing(ha);
  6165. /* Initialize lists and spinlocks. */
  6166. INIT_LIST_HEAD(&ha->free_srb_q);
  6167. mutex_init(&ha->mbox_sem);
  6168. mutex_init(&ha->chap_sem);
  6169. init_completion(&ha->mbx_intr_comp);
  6170. init_completion(&ha->disable_acb_comp);
  6171. spin_lock_init(&ha->hardware_lock);
  6172. spin_lock_init(&ha->work_lock);
  6173. /* Initialize work list */
  6174. INIT_LIST_HEAD(&ha->work_list);
  6175. /* Allocate dma buffers */
  6176. if (qla4xxx_mem_alloc(ha)) {
  6177. ql4_printk(KERN_WARNING, ha,
  6178. "[ERROR] Failed to allocate memory for adapter\n");
  6179. ret = -ENOMEM;
  6180. goto probe_failed;
  6181. }
  6182. host->cmd_per_lun = 3;
  6183. host->max_channel = 0;
  6184. host->max_lun = MAX_LUNS - 1;
  6185. host->max_id = MAX_TARGETS;
  6186. host->max_cmd_len = IOCB_MAX_CDB_LEN;
  6187. host->can_queue = MAX_SRBS ;
  6188. host->transportt = qla4xxx_scsi_transport;
  6189. ret = scsi_init_shared_tag_map(host, MAX_SRBS);
  6190. if (ret) {
  6191. ql4_printk(KERN_WARNING, ha,
  6192. "%s: scsi_init_shared_tag_map failed\n", __func__);
  6193. goto probe_failed;
  6194. }
  6195. pci_set_drvdata(pdev, ha);
  6196. ret = scsi_add_host(host, &pdev->dev);
  6197. if (ret)
  6198. goto probe_failed;
  6199. if (is_qla80XX(ha))
  6200. qla4_8xxx_get_flash_info(ha);
  6201. if (is_qla8032(ha) || is_qla8042(ha)) {
  6202. qla4_83xx_read_reset_template(ha);
  6203. /*
  6204. * NOTE: If ql4dontresethba==1, set IDC_CTRL DONTRESET_BIT0.
  6205. * If DONRESET_BIT0 is set, drivers should not set dev_state
  6206. * to NEED_RESET. But if NEED_RESET is set, drivers should
  6207. * should honor the reset.
  6208. */
  6209. if (ql4xdontresethba == 1)
  6210. qla4_83xx_set_idc_dontreset(ha);
  6211. }
  6212. /*
  6213. * Initialize the Host adapter request/response queues and
  6214. * firmware
  6215. * NOTE: interrupts enabled upon successful completion
  6216. */
  6217. status = qla4xxx_initialize_adapter(ha, INIT_ADAPTER);
  6218. /* Dont retry adapter initialization if IRQ allocation failed */
  6219. if (is_qla80XX(ha) && !test_bit(AF_IRQ_ATTACHED, &ha->flags)) {
  6220. ql4_printk(KERN_WARNING, ha, "%s: Skipping retry of adapter initialization\n",
  6221. __func__);
  6222. goto skip_retry_init;
  6223. }
  6224. while ((!test_bit(AF_ONLINE, &ha->flags)) &&
  6225. init_retry_count++ < MAX_INIT_RETRIES) {
  6226. if (is_qla80XX(ha)) {
  6227. ha->isp_ops->idc_lock(ha);
  6228. dev_state = qla4_8xxx_rd_direct(ha,
  6229. QLA8XXX_CRB_DEV_STATE);
  6230. ha->isp_ops->idc_unlock(ha);
  6231. if (dev_state == QLA8XXX_DEV_FAILED) {
  6232. ql4_printk(KERN_WARNING, ha, "%s: don't retry "
  6233. "initialize adapter. H/W is in failed state\n",
  6234. __func__);
  6235. break;
  6236. }
  6237. }
  6238. DEBUG2(printk("scsi: %s: retrying adapter initialization "
  6239. "(%d)\n", __func__, init_retry_count));
  6240. if (ha->isp_ops->reset_chip(ha) == QLA_ERROR)
  6241. continue;
  6242. status = qla4xxx_initialize_adapter(ha, INIT_ADAPTER);
  6243. }
  6244. skip_retry_init:
  6245. if (!test_bit(AF_ONLINE, &ha->flags)) {
  6246. ql4_printk(KERN_WARNING, ha, "Failed to initialize adapter\n");
  6247. if ((is_qla8022(ha) && ql4xdontresethba) ||
  6248. ((is_qla8032(ha) || is_qla8042(ha)) &&
  6249. qla4_83xx_idc_dontreset(ha))) {
  6250. /* Put the device in failed state. */
  6251. DEBUG2(printk(KERN_ERR "HW STATE: FAILED\n"));
  6252. ha->isp_ops->idc_lock(ha);
  6253. qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DEV_STATE,
  6254. QLA8XXX_DEV_FAILED);
  6255. ha->isp_ops->idc_unlock(ha);
  6256. }
  6257. ret = -ENODEV;
  6258. goto remove_host;
  6259. }
  6260. /* Startup the kernel thread for this host adapter. */
  6261. DEBUG2(printk("scsi: %s: Starting kernel thread for "
  6262. "qla4xxx_dpc\n", __func__));
  6263. sprintf(buf, "qla4xxx_%lu_dpc", ha->host_no);
  6264. ha->dpc_thread = create_singlethread_workqueue(buf);
  6265. if (!ha->dpc_thread) {
  6266. ql4_printk(KERN_WARNING, ha, "Unable to start DPC thread!\n");
  6267. ret = -ENODEV;
  6268. goto remove_host;
  6269. }
  6270. INIT_WORK(&ha->dpc_work, qla4xxx_do_dpc);
  6271. ha->task_wq = alloc_workqueue("qla4xxx_%lu_task", WQ_MEM_RECLAIM, 1,
  6272. ha->host_no);
  6273. if (!ha->task_wq) {
  6274. ql4_printk(KERN_WARNING, ha, "Unable to start task thread!\n");
  6275. ret = -ENODEV;
  6276. goto remove_host;
  6277. }
  6278. /*
  6279. * For ISP-8XXX, request_irqs is called in qla4_8xxx_load_risc
  6280. * (which is called indirectly by qla4xxx_initialize_adapter),
  6281. * so that irqs will be registered after crbinit but before
  6282. * mbx_intr_enable.
  6283. */
  6284. if (is_qla40XX(ha)) {
  6285. ret = qla4xxx_request_irqs(ha);
  6286. if (ret) {
  6287. ql4_printk(KERN_WARNING, ha, "Failed to reserve "
  6288. "interrupt %d already in use.\n", pdev->irq);
  6289. goto remove_host;
  6290. }
  6291. }
  6292. pci_save_state(ha->pdev);
  6293. ha->isp_ops->enable_intrs(ha);
  6294. /* Start timer thread. */
  6295. qla4xxx_start_timer(ha, qla4xxx_timer, 1);
  6296. set_bit(AF_INIT_DONE, &ha->flags);
  6297. qla4_8xxx_alloc_sysfs_attr(ha);
  6298. printk(KERN_INFO
  6299. " QLogic iSCSI HBA Driver version: %s\n"
  6300. " QLogic ISP%04x @ %s, host#=%ld, fw=%02d.%02d.%02d.%02d\n",
  6301. qla4xxx_version_str, ha->pdev->device, pci_name(ha->pdev),
  6302. ha->host_no, ha->fw_info.fw_major, ha->fw_info.fw_minor,
  6303. ha->fw_info.fw_patch, ha->fw_info.fw_build);
  6304. /* Set the driver version */
  6305. if (is_qla80XX(ha))
  6306. qla4_8xxx_set_param(ha, SET_DRVR_VERSION);
  6307. if (qla4xxx_setup_boot_info(ha))
  6308. ql4_printk(KERN_ERR, ha,
  6309. "%s: No iSCSI boot target configured\n", __func__);
  6310. if (qla4xxx_sysfs_ddb_export(ha))
  6311. ql4_printk(KERN_ERR, ha,
  6312. "%s: Error exporting ddb to sysfs\n", __func__);
  6313. /* Perform the build ddb list and login to each */
  6314. qla4xxx_build_ddb_list(ha, INIT_ADAPTER);
  6315. iscsi_host_for_each_session(ha->host, qla4xxx_login_flash_ddb);
  6316. qla4xxx_wait_login_resp_boot_tgt(ha);
  6317. qla4xxx_create_chap_list(ha);
  6318. qla4xxx_create_ifaces(ha);
  6319. return 0;
  6320. remove_host:
  6321. scsi_remove_host(ha->host);
  6322. probe_failed:
  6323. qla4xxx_free_adapter(ha);
  6324. probe_failed_ioconfig:
  6325. pci_disable_pcie_error_reporting(pdev);
  6326. scsi_host_put(ha->host);
  6327. probe_disable_device:
  6328. pci_disable_device(pdev);
  6329. return ret;
  6330. }
  6331. /**
  6332. * qla4xxx_prevent_other_port_reinit - prevent other port from re-initialize
  6333. * @ha: pointer to adapter structure
  6334. *
  6335. * Mark the other ISP-4xxx port to indicate that the driver is being removed,
  6336. * so that the other port will not re-initialize while in the process of
  6337. * removing the ha due to driver unload or hba hotplug.
  6338. **/
  6339. static void qla4xxx_prevent_other_port_reinit(struct scsi_qla_host *ha)
  6340. {
  6341. struct scsi_qla_host *other_ha = NULL;
  6342. struct pci_dev *other_pdev = NULL;
  6343. int fn = ISP4XXX_PCI_FN_2;
  6344. /*iscsi function numbers for ISP4xxx is 1 and 3*/
  6345. if (PCI_FUNC(ha->pdev->devfn) & BIT_1)
  6346. fn = ISP4XXX_PCI_FN_1;
  6347. other_pdev =
  6348. pci_get_domain_bus_and_slot(pci_domain_nr(ha->pdev->bus),
  6349. ha->pdev->bus->number, PCI_DEVFN(PCI_SLOT(ha->pdev->devfn),
  6350. fn));
  6351. /* Get other_ha if other_pdev is valid and state is enable*/
  6352. if (other_pdev) {
  6353. if (atomic_read(&other_pdev->enable_cnt)) {
  6354. other_ha = pci_get_drvdata(other_pdev);
  6355. if (other_ha) {
  6356. set_bit(AF_HA_REMOVAL, &other_ha->flags);
  6357. DEBUG2(ql4_printk(KERN_INFO, ha, "%s: "
  6358. "Prevent %s reinit\n", __func__,
  6359. dev_name(&other_ha->pdev->dev)));
  6360. }
  6361. }
  6362. pci_dev_put(other_pdev);
  6363. }
  6364. }
  6365. static void qla4xxx_destroy_fw_ddb_session(struct scsi_qla_host *ha)
  6366. {
  6367. struct ddb_entry *ddb_entry;
  6368. int options;
  6369. int idx;
  6370. for (idx = 0; idx < MAX_DDB_ENTRIES; idx++) {
  6371. ddb_entry = qla4xxx_lookup_ddb_by_fw_index(ha, idx);
  6372. if ((ddb_entry != NULL) &&
  6373. (ddb_entry->ddb_type == FLASH_DDB)) {
  6374. options = LOGOUT_OPTION_CLOSE_SESSION;
  6375. if (qla4xxx_session_logout_ddb(ha, ddb_entry, options)
  6376. == QLA_ERROR)
  6377. ql4_printk(KERN_ERR, ha, "%s: Logout failed\n",
  6378. __func__);
  6379. qla4xxx_clear_ddb_entry(ha, ddb_entry->fw_ddb_index);
  6380. /*
  6381. * we have decremented the reference count of the driver
  6382. * when we setup the session to have the driver unload
  6383. * to be seamless without actually destroying the
  6384. * session
  6385. **/
  6386. try_module_get(qla4xxx_iscsi_transport.owner);
  6387. iscsi_destroy_endpoint(ddb_entry->conn->ep);
  6388. qla4xxx_free_ddb(ha, ddb_entry);
  6389. iscsi_session_teardown(ddb_entry->sess);
  6390. }
  6391. }
  6392. }
  6393. /**
  6394. * qla4xxx_remove_adapter - callback function to remove adapter.
  6395. * @pci_dev: PCI device pointer
  6396. **/
  6397. static void qla4xxx_remove_adapter(struct pci_dev *pdev)
  6398. {
  6399. struct scsi_qla_host *ha;
  6400. /*
  6401. * If the PCI device is disabled then it means probe_adapter had
  6402. * failed and resources already cleaned up on probe_adapter exit.
  6403. */
  6404. if (!pci_is_enabled(pdev))
  6405. return;
  6406. ha = pci_get_drvdata(pdev);
  6407. if (is_qla40XX(ha))
  6408. qla4xxx_prevent_other_port_reinit(ha);
  6409. /* destroy iface from sysfs */
  6410. qla4xxx_destroy_ifaces(ha);
  6411. if ((!ql4xdisablesysfsboot) && ha->boot_kset)
  6412. iscsi_boot_destroy_kset(ha->boot_kset);
  6413. qla4xxx_destroy_fw_ddb_session(ha);
  6414. qla4_8xxx_free_sysfs_attr(ha);
  6415. qla4xxx_sysfs_ddb_remove(ha);
  6416. scsi_remove_host(ha->host);
  6417. qla4xxx_free_adapter(ha);
  6418. scsi_host_put(ha->host);
  6419. pci_disable_pcie_error_reporting(pdev);
  6420. pci_disable_device(pdev);
  6421. }
  6422. /**
  6423. * qla4xxx_config_dma_addressing() - Configure OS DMA addressing method.
  6424. * @ha: HA context
  6425. *
  6426. * At exit, the @ha's flags.enable_64bit_addressing set to indicated
  6427. * supported addressing method.
  6428. */
  6429. static void qla4xxx_config_dma_addressing(struct scsi_qla_host *ha)
  6430. {
  6431. int retval;
  6432. /* Update our PCI device dma_mask for full 64 bit mask */
  6433. if (pci_set_dma_mask(ha->pdev, DMA_BIT_MASK(64)) == 0) {
  6434. if (pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(64))) {
  6435. dev_dbg(&ha->pdev->dev,
  6436. "Failed to set 64 bit PCI consistent mask; "
  6437. "using 32 bit.\n");
  6438. retval = pci_set_consistent_dma_mask(ha->pdev,
  6439. DMA_BIT_MASK(32));
  6440. }
  6441. } else
  6442. retval = pci_set_dma_mask(ha->pdev, DMA_BIT_MASK(32));
  6443. }
  6444. static int qla4xxx_slave_alloc(struct scsi_device *sdev)
  6445. {
  6446. struct iscsi_cls_session *cls_sess;
  6447. struct iscsi_session *sess;
  6448. struct ddb_entry *ddb;
  6449. int queue_depth = QL4_DEF_QDEPTH;
  6450. cls_sess = starget_to_session(sdev->sdev_target);
  6451. sess = cls_sess->dd_data;
  6452. ddb = sess->dd_data;
  6453. sdev->hostdata = ddb;
  6454. sdev->tagged_supported = 1;
  6455. if (ql4xmaxqdepth != 0 && ql4xmaxqdepth <= 0xffffU)
  6456. queue_depth = ql4xmaxqdepth;
  6457. scsi_activate_tcq(sdev, queue_depth);
  6458. return 0;
  6459. }
  6460. static int qla4xxx_slave_configure(struct scsi_device *sdev)
  6461. {
  6462. sdev->tagged_supported = 1;
  6463. return 0;
  6464. }
  6465. static void qla4xxx_slave_destroy(struct scsi_device *sdev)
  6466. {
  6467. scsi_deactivate_tcq(sdev, 1);
  6468. }
  6469. static int qla4xxx_change_queue_depth(struct scsi_device *sdev, int qdepth,
  6470. int reason)
  6471. {
  6472. if (!ql4xqfulltracking)
  6473. return -EOPNOTSUPP;
  6474. return iscsi_change_queue_depth(sdev, qdepth, reason);
  6475. }
  6476. /**
  6477. * qla4xxx_del_from_active_array - returns an active srb
  6478. * @ha: Pointer to host adapter structure.
  6479. * @index: index into the active_array
  6480. *
  6481. * This routine removes and returns the srb at the specified index
  6482. **/
  6483. struct srb *qla4xxx_del_from_active_array(struct scsi_qla_host *ha,
  6484. uint32_t index)
  6485. {
  6486. struct srb *srb = NULL;
  6487. struct scsi_cmnd *cmd = NULL;
  6488. cmd = scsi_host_find_tag(ha->host, index);
  6489. if (!cmd)
  6490. return srb;
  6491. srb = (struct srb *)CMD_SP(cmd);
  6492. if (!srb)
  6493. return srb;
  6494. /* update counters */
  6495. if (srb->flags & SRB_DMA_VALID) {
  6496. ha->iocb_cnt -= srb->iocb_cnt;
  6497. if (srb->cmd)
  6498. srb->cmd->host_scribble =
  6499. (unsigned char *)(unsigned long) MAX_SRBS;
  6500. }
  6501. return srb;
  6502. }
  6503. /**
  6504. * qla4xxx_eh_wait_on_command - waits for command to be returned by firmware
  6505. * @ha: Pointer to host adapter structure.
  6506. * @cmd: Scsi Command to wait on.
  6507. *
  6508. * This routine waits for the command to be returned by the Firmware
  6509. * for some max time.
  6510. **/
  6511. static int qla4xxx_eh_wait_on_command(struct scsi_qla_host *ha,
  6512. struct scsi_cmnd *cmd)
  6513. {
  6514. int done = 0;
  6515. struct srb *rp;
  6516. uint32_t max_wait_time = EH_WAIT_CMD_TOV;
  6517. int ret = SUCCESS;
  6518. /* Dont wait on command if PCI error is being handled
  6519. * by PCI AER driver
  6520. */
  6521. if (unlikely(pci_channel_offline(ha->pdev)) ||
  6522. (test_bit(AF_EEH_BUSY, &ha->flags))) {
  6523. ql4_printk(KERN_WARNING, ha, "scsi%ld: Return from %s\n",
  6524. ha->host_no, __func__);
  6525. return ret;
  6526. }
  6527. do {
  6528. /* Checking to see if its returned to OS */
  6529. rp = (struct srb *) CMD_SP(cmd);
  6530. if (rp == NULL) {
  6531. done++;
  6532. break;
  6533. }
  6534. msleep(2000);
  6535. } while (max_wait_time--);
  6536. return done;
  6537. }
  6538. /**
  6539. * qla4xxx_wait_for_hba_online - waits for HBA to come online
  6540. * @ha: Pointer to host adapter structure
  6541. **/
  6542. static int qla4xxx_wait_for_hba_online(struct scsi_qla_host *ha)
  6543. {
  6544. unsigned long wait_online;
  6545. wait_online = jiffies + (HBA_ONLINE_TOV * HZ);
  6546. while (time_before(jiffies, wait_online)) {
  6547. if (adapter_up(ha))
  6548. return QLA_SUCCESS;
  6549. msleep(2000);
  6550. }
  6551. return QLA_ERROR;
  6552. }
  6553. /**
  6554. * qla4xxx_eh_wait_for_commands - wait for active cmds to finish.
  6555. * @ha: pointer to HBA
  6556. * @t: target id
  6557. * @l: lun id
  6558. *
  6559. * This function waits for all outstanding commands to a lun to complete. It
  6560. * returns 0 if all pending commands are returned and 1 otherwise.
  6561. **/
  6562. static int qla4xxx_eh_wait_for_commands(struct scsi_qla_host *ha,
  6563. struct scsi_target *stgt,
  6564. struct scsi_device *sdev)
  6565. {
  6566. int cnt;
  6567. int status = 0;
  6568. struct scsi_cmnd *cmd;
  6569. /*
  6570. * Waiting for all commands for the designated target or dev
  6571. * in the active array
  6572. */
  6573. for (cnt = 0; cnt < ha->host->can_queue; cnt++) {
  6574. cmd = scsi_host_find_tag(ha->host, cnt);
  6575. if (cmd && stgt == scsi_target(cmd->device) &&
  6576. (!sdev || sdev == cmd->device)) {
  6577. if (!qla4xxx_eh_wait_on_command(ha, cmd)) {
  6578. status++;
  6579. break;
  6580. }
  6581. }
  6582. }
  6583. return status;
  6584. }
  6585. /**
  6586. * qla4xxx_eh_abort - callback for abort task.
  6587. * @cmd: Pointer to Linux's SCSI command structure
  6588. *
  6589. * This routine is called by the Linux OS to abort the specified
  6590. * command.
  6591. **/
  6592. static int qla4xxx_eh_abort(struct scsi_cmnd *cmd)
  6593. {
  6594. struct scsi_qla_host *ha = to_qla_host(cmd->device->host);
  6595. unsigned int id = cmd->device->id;
  6596. unsigned int lun = cmd->device->lun;
  6597. unsigned long flags;
  6598. struct srb *srb = NULL;
  6599. int ret = SUCCESS;
  6600. int wait = 0;
  6601. ql4_printk(KERN_INFO, ha,
  6602. "scsi%ld:%d:%d: Abort command issued cmd=%p\n",
  6603. ha->host_no, id, lun, cmd);
  6604. spin_lock_irqsave(&ha->hardware_lock, flags);
  6605. srb = (struct srb *) CMD_SP(cmd);
  6606. if (!srb) {
  6607. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  6608. return SUCCESS;
  6609. }
  6610. kref_get(&srb->srb_ref);
  6611. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  6612. if (qla4xxx_abort_task(ha, srb) != QLA_SUCCESS) {
  6613. DEBUG3(printk("scsi%ld:%d:%d: Abort_task mbx failed.\n",
  6614. ha->host_no, id, lun));
  6615. ret = FAILED;
  6616. } else {
  6617. DEBUG3(printk("scsi%ld:%d:%d: Abort_task mbx success.\n",
  6618. ha->host_no, id, lun));
  6619. wait = 1;
  6620. }
  6621. kref_put(&srb->srb_ref, qla4xxx_srb_compl);
  6622. /* Wait for command to complete */
  6623. if (wait) {
  6624. if (!qla4xxx_eh_wait_on_command(ha, cmd)) {
  6625. DEBUG2(printk("scsi%ld:%d:%d: Abort handler timed out\n",
  6626. ha->host_no, id, lun));
  6627. ret = FAILED;
  6628. }
  6629. }
  6630. ql4_printk(KERN_INFO, ha,
  6631. "scsi%ld:%d:%d: Abort command - %s\n",
  6632. ha->host_no, id, lun, (ret == SUCCESS) ? "succeeded" : "failed");
  6633. return ret;
  6634. }
  6635. /**
  6636. * qla4xxx_eh_device_reset - callback for target reset.
  6637. * @cmd: Pointer to Linux's SCSI command structure
  6638. *
  6639. * This routine is called by the Linux OS to reset all luns on the
  6640. * specified target.
  6641. **/
  6642. static int qla4xxx_eh_device_reset(struct scsi_cmnd *cmd)
  6643. {
  6644. struct scsi_qla_host *ha = to_qla_host(cmd->device->host);
  6645. struct ddb_entry *ddb_entry = cmd->device->hostdata;
  6646. int ret = FAILED, stat;
  6647. if (!ddb_entry)
  6648. return ret;
  6649. ret = iscsi_block_scsi_eh(cmd);
  6650. if (ret)
  6651. return ret;
  6652. ret = FAILED;
  6653. ql4_printk(KERN_INFO, ha,
  6654. "scsi%ld:%d:%d:%d: DEVICE RESET ISSUED.\n", ha->host_no,
  6655. cmd->device->channel, cmd->device->id, cmd->device->lun);
  6656. DEBUG2(printk(KERN_INFO
  6657. "scsi%ld: DEVICE_RESET cmd=%p jiffies = 0x%lx, to=%x,"
  6658. "dpc_flags=%lx, status=%x allowed=%d\n", ha->host_no,
  6659. cmd, jiffies, cmd->request->timeout / HZ,
  6660. ha->dpc_flags, cmd->result, cmd->allowed));
  6661. /* FIXME: wait for hba to go online */
  6662. stat = qla4xxx_reset_lun(ha, ddb_entry, cmd->device->lun);
  6663. if (stat != QLA_SUCCESS) {
  6664. ql4_printk(KERN_INFO, ha, "DEVICE RESET FAILED. %d\n", stat);
  6665. goto eh_dev_reset_done;
  6666. }
  6667. if (qla4xxx_eh_wait_for_commands(ha, scsi_target(cmd->device),
  6668. cmd->device)) {
  6669. ql4_printk(KERN_INFO, ha,
  6670. "DEVICE RESET FAILED - waiting for "
  6671. "commands.\n");
  6672. goto eh_dev_reset_done;
  6673. }
  6674. /* Send marker. */
  6675. if (qla4xxx_send_marker_iocb(ha, ddb_entry, cmd->device->lun,
  6676. MM_LUN_RESET) != QLA_SUCCESS)
  6677. goto eh_dev_reset_done;
  6678. ql4_printk(KERN_INFO, ha,
  6679. "scsi(%ld:%d:%d:%d): DEVICE RESET SUCCEEDED.\n",
  6680. ha->host_no, cmd->device->channel, cmd->device->id,
  6681. cmd->device->lun);
  6682. ret = SUCCESS;
  6683. eh_dev_reset_done:
  6684. return ret;
  6685. }
  6686. /**
  6687. * qla4xxx_eh_target_reset - callback for target reset.
  6688. * @cmd: Pointer to Linux's SCSI command structure
  6689. *
  6690. * This routine is called by the Linux OS to reset the target.
  6691. **/
  6692. static int qla4xxx_eh_target_reset(struct scsi_cmnd *cmd)
  6693. {
  6694. struct scsi_qla_host *ha = to_qla_host(cmd->device->host);
  6695. struct ddb_entry *ddb_entry = cmd->device->hostdata;
  6696. int stat, ret;
  6697. if (!ddb_entry)
  6698. return FAILED;
  6699. ret = iscsi_block_scsi_eh(cmd);
  6700. if (ret)
  6701. return ret;
  6702. starget_printk(KERN_INFO, scsi_target(cmd->device),
  6703. "WARM TARGET RESET ISSUED.\n");
  6704. DEBUG2(printk(KERN_INFO
  6705. "scsi%ld: TARGET_DEVICE_RESET cmd=%p jiffies = 0x%lx, "
  6706. "to=%x,dpc_flags=%lx, status=%x allowed=%d\n",
  6707. ha->host_no, cmd, jiffies, cmd->request->timeout / HZ,
  6708. ha->dpc_flags, cmd->result, cmd->allowed));
  6709. stat = qla4xxx_reset_target(ha, ddb_entry);
  6710. if (stat != QLA_SUCCESS) {
  6711. starget_printk(KERN_INFO, scsi_target(cmd->device),
  6712. "WARM TARGET RESET FAILED.\n");
  6713. return FAILED;
  6714. }
  6715. if (qla4xxx_eh_wait_for_commands(ha, scsi_target(cmd->device),
  6716. NULL)) {
  6717. starget_printk(KERN_INFO, scsi_target(cmd->device),
  6718. "WARM TARGET DEVICE RESET FAILED - "
  6719. "waiting for commands.\n");
  6720. return FAILED;
  6721. }
  6722. /* Send marker. */
  6723. if (qla4xxx_send_marker_iocb(ha, ddb_entry, cmd->device->lun,
  6724. MM_TGT_WARM_RESET) != QLA_SUCCESS) {
  6725. starget_printk(KERN_INFO, scsi_target(cmd->device),
  6726. "WARM TARGET DEVICE RESET FAILED - "
  6727. "marker iocb failed.\n");
  6728. return FAILED;
  6729. }
  6730. starget_printk(KERN_INFO, scsi_target(cmd->device),
  6731. "WARM TARGET RESET SUCCEEDED.\n");
  6732. return SUCCESS;
  6733. }
  6734. /**
  6735. * qla4xxx_is_eh_active - check if error handler is running
  6736. * @shost: Pointer to SCSI Host struct
  6737. *
  6738. * This routine finds that if reset host is called in EH
  6739. * scenario or from some application like sg_reset
  6740. **/
  6741. static int qla4xxx_is_eh_active(struct Scsi_Host *shost)
  6742. {
  6743. if (shost->shost_state == SHOST_RECOVERY)
  6744. return 1;
  6745. return 0;
  6746. }
  6747. /**
  6748. * qla4xxx_eh_host_reset - kernel callback
  6749. * @cmd: Pointer to Linux's SCSI command structure
  6750. *
  6751. * This routine is invoked by the Linux kernel to perform fatal error
  6752. * recovery on the specified adapter.
  6753. **/
  6754. static int qla4xxx_eh_host_reset(struct scsi_cmnd *cmd)
  6755. {
  6756. int return_status = FAILED;
  6757. struct scsi_qla_host *ha;
  6758. ha = to_qla_host(cmd->device->host);
  6759. if ((is_qla8032(ha) || is_qla8042(ha)) && ql4xdontresethba)
  6760. qla4_83xx_set_idc_dontreset(ha);
  6761. /*
  6762. * For ISP8324 and ISP8042, if IDC_CTRL DONTRESET_BIT0 is set by other
  6763. * protocol drivers, we should not set device_state to NEED_RESET
  6764. */
  6765. if (ql4xdontresethba ||
  6766. ((is_qla8032(ha) || is_qla8042(ha)) &&
  6767. qla4_83xx_idc_dontreset(ha))) {
  6768. DEBUG2(printk("scsi%ld: %s: Don't Reset HBA\n",
  6769. ha->host_no, __func__));
  6770. /* Clear outstanding srb in queues */
  6771. if (qla4xxx_is_eh_active(cmd->device->host))
  6772. qla4xxx_abort_active_cmds(ha, DID_ABORT << 16);
  6773. return FAILED;
  6774. }
  6775. ql4_printk(KERN_INFO, ha,
  6776. "scsi(%ld:%d:%d:%d): HOST RESET ISSUED.\n", ha->host_no,
  6777. cmd->device->channel, cmd->device->id, cmd->device->lun);
  6778. if (qla4xxx_wait_for_hba_online(ha) != QLA_SUCCESS) {
  6779. DEBUG2(printk("scsi%ld:%d: %s: Unable to reset host. Adapter "
  6780. "DEAD.\n", ha->host_no, cmd->device->channel,
  6781. __func__));
  6782. return FAILED;
  6783. }
  6784. if (!test_bit(DPC_RESET_HA, &ha->dpc_flags)) {
  6785. if (is_qla80XX(ha))
  6786. set_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags);
  6787. else
  6788. set_bit(DPC_RESET_HA, &ha->dpc_flags);
  6789. }
  6790. if (qla4xxx_recover_adapter(ha) == QLA_SUCCESS)
  6791. return_status = SUCCESS;
  6792. ql4_printk(KERN_INFO, ha, "HOST RESET %s.\n",
  6793. return_status == FAILED ? "FAILED" : "SUCCEEDED");
  6794. return return_status;
  6795. }
  6796. static int qla4xxx_context_reset(struct scsi_qla_host *ha)
  6797. {
  6798. uint32_t mbox_cmd[MBOX_REG_COUNT];
  6799. uint32_t mbox_sts[MBOX_REG_COUNT];
  6800. struct addr_ctrl_blk_def *acb = NULL;
  6801. uint32_t acb_len = sizeof(struct addr_ctrl_blk_def);
  6802. int rval = QLA_SUCCESS;
  6803. dma_addr_t acb_dma;
  6804. acb = dma_alloc_coherent(&ha->pdev->dev,
  6805. sizeof(struct addr_ctrl_blk_def),
  6806. &acb_dma, GFP_KERNEL);
  6807. if (!acb) {
  6808. ql4_printk(KERN_ERR, ha, "%s: Unable to alloc acb\n",
  6809. __func__);
  6810. rval = -ENOMEM;
  6811. goto exit_port_reset;
  6812. }
  6813. memset(acb, 0, acb_len);
  6814. rval = qla4xxx_get_acb(ha, acb_dma, PRIMARI_ACB, acb_len);
  6815. if (rval != QLA_SUCCESS) {
  6816. rval = -EIO;
  6817. goto exit_free_acb;
  6818. }
  6819. rval = qla4xxx_disable_acb(ha);
  6820. if (rval != QLA_SUCCESS) {
  6821. rval = -EIO;
  6822. goto exit_free_acb;
  6823. }
  6824. wait_for_completion_timeout(&ha->disable_acb_comp,
  6825. DISABLE_ACB_TOV * HZ);
  6826. rval = qla4xxx_set_acb(ha, &mbox_cmd[0], &mbox_sts[0], acb_dma);
  6827. if (rval != QLA_SUCCESS) {
  6828. rval = -EIO;
  6829. goto exit_free_acb;
  6830. }
  6831. exit_free_acb:
  6832. dma_free_coherent(&ha->pdev->dev, sizeof(struct addr_ctrl_blk_def),
  6833. acb, acb_dma);
  6834. exit_port_reset:
  6835. DEBUG2(ql4_printk(KERN_INFO, ha, "%s %s\n", __func__,
  6836. rval == QLA_SUCCESS ? "SUCCEEDED" : "FAILED"));
  6837. return rval;
  6838. }
  6839. static int qla4xxx_host_reset(struct Scsi_Host *shost, int reset_type)
  6840. {
  6841. struct scsi_qla_host *ha = to_qla_host(shost);
  6842. int rval = QLA_SUCCESS;
  6843. uint32_t idc_ctrl;
  6844. if (ql4xdontresethba) {
  6845. DEBUG2(ql4_printk(KERN_INFO, ha, "%s: Don't Reset HBA\n",
  6846. __func__));
  6847. rval = -EPERM;
  6848. goto exit_host_reset;
  6849. }
  6850. if (test_bit(DPC_RESET_HA, &ha->dpc_flags))
  6851. goto recover_adapter;
  6852. switch (reset_type) {
  6853. case SCSI_ADAPTER_RESET:
  6854. set_bit(DPC_RESET_HA, &ha->dpc_flags);
  6855. break;
  6856. case SCSI_FIRMWARE_RESET:
  6857. if (!test_bit(DPC_RESET_HA, &ha->dpc_flags)) {
  6858. if (is_qla80XX(ha))
  6859. /* set firmware context reset */
  6860. set_bit(DPC_RESET_HA_FW_CONTEXT,
  6861. &ha->dpc_flags);
  6862. else {
  6863. rval = qla4xxx_context_reset(ha);
  6864. goto exit_host_reset;
  6865. }
  6866. }
  6867. break;
  6868. }
  6869. recover_adapter:
  6870. /* For ISP8324 and ISP8042 set graceful reset bit in IDC_DRV_CTRL if
  6871. * reset is issued by application */
  6872. if ((is_qla8032(ha) || is_qla8042(ha)) &&
  6873. test_bit(DPC_RESET_HA, &ha->dpc_flags)) {
  6874. idc_ctrl = qla4_83xx_rd_reg(ha, QLA83XX_IDC_DRV_CTRL);
  6875. qla4_83xx_wr_reg(ha, QLA83XX_IDC_DRV_CTRL,
  6876. (idc_ctrl | GRACEFUL_RESET_BIT1));
  6877. }
  6878. rval = qla4xxx_recover_adapter(ha);
  6879. if (rval != QLA_SUCCESS) {
  6880. DEBUG2(ql4_printk(KERN_INFO, ha, "%s: recover adapter fail\n",
  6881. __func__));
  6882. rval = -EIO;
  6883. }
  6884. exit_host_reset:
  6885. return rval;
  6886. }
  6887. /* PCI AER driver recovers from all correctable errors w/o
  6888. * driver intervention. For uncorrectable errors PCI AER
  6889. * driver calls the following device driver's callbacks
  6890. *
  6891. * - Fatal Errors - link_reset
  6892. * - Non-Fatal Errors - driver's pci_error_detected() which
  6893. * returns CAN_RECOVER, NEED_RESET or DISCONNECT.
  6894. *
  6895. * PCI AER driver calls
  6896. * CAN_RECOVER - driver's pci_mmio_enabled(), mmio_enabled
  6897. * returns RECOVERED or NEED_RESET if fw_hung
  6898. * NEED_RESET - driver's slot_reset()
  6899. * DISCONNECT - device is dead & cannot recover
  6900. * RECOVERED - driver's pci_resume()
  6901. */
  6902. static pci_ers_result_t
  6903. qla4xxx_pci_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
  6904. {
  6905. struct scsi_qla_host *ha = pci_get_drvdata(pdev);
  6906. ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: error detected:state %x\n",
  6907. ha->host_no, __func__, state);
  6908. if (!is_aer_supported(ha))
  6909. return PCI_ERS_RESULT_NONE;
  6910. switch (state) {
  6911. case pci_channel_io_normal:
  6912. clear_bit(AF_EEH_BUSY, &ha->flags);
  6913. return PCI_ERS_RESULT_CAN_RECOVER;
  6914. case pci_channel_io_frozen:
  6915. set_bit(AF_EEH_BUSY, &ha->flags);
  6916. qla4xxx_mailbox_premature_completion(ha);
  6917. qla4xxx_free_irqs(ha);
  6918. pci_disable_device(pdev);
  6919. /* Return back all IOs */
  6920. qla4xxx_abort_active_cmds(ha, DID_RESET << 16);
  6921. return PCI_ERS_RESULT_NEED_RESET;
  6922. case pci_channel_io_perm_failure:
  6923. set_bit(AF_EEH_BUSY, &ha->flags);
  6924. set_bit(AF_PCI_CHANNEL_IO_PERM_FAILURE, &ha->flags);
  6925. qla4xxx_abort_active_cmds(ha, DID_NO_CONNECT << 16);
  6926. return PCI_ERS_RESULT_DISCONNECT;
  6927. }
  6928. return PCI_ERS_RESULT_NEED_RESET;
  6929. }
  6930. /**
  6931. * qla4xxx_pci_mmio_enabled() gets called if
  6932. * qla4xxx_pci_error_detected() returns PCI_ERS_RESULT_CAN_RECOVER
  6933. * and read/write to the device still works.
  6934. **/
  6935. static pci_ers_result_t
  6936. qla4xxx_pci_mmio_enabled(struct pci_dev *pdev)
  6937. {
  6938. struct scsi_qla_host *ha = pci_get_drvdata(pdev);
  6939. if (!is_aer_supported(ha))
  6940. return PCI_ERS_RESULT_NONE;
  6941. return PCI_ERS_RESULT_RECOVERED;
  6942. }
  6943. static uint32_t qla4_8xxx_error_recovery(struct scsi_qla_host *ha)
  6944. {
  6945. uint32_t rval = QLA_ERROR;
  6946. int fn;
  6947. struct pci_dev *other_pdev = NULL;
  6948. ql4_printk(KERN_WARNING, ha, "scsi%ld: In %s\n", ha->host_no, __func__);
  6949. set_bit(DPC_RESET_ACTIVE, &ha->dpc_flags);
  6950. if (test_bit(AF_ONLINE, &ha->flags)) {
  6951. clear_bit(AF_ONLINE, &ha->flags);
  6952. clear_bit(AF_LINK_UP, &ha->flags);
  6953. iscsi_host_for_each_session(ha->host, qla4xxx_fail_session);
  6954. qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
  6955. }
  6956. fn = PCI_FUNC(ha->pdev->devfn);
  6957. while (fn > 0) {
  6958. fn--;
  6959. ql4_printk(KERN_INFO, ha, "scsi%ld: %s: Finding PCI device at "
  6960. "func %x\n", ha->host_no, __func__, fn);
  6961. /* Get the pci device given the domain, bus,
  6962. * slot/function number */
  6963. other_pdev =
  6964. pci_get_domain_bus_and_slot(pci_domain_nr(ha->pdev->bus),
  6965. ha->pdev->bus->number, PCI_DEVFN(PCI_SLOT(ha->pdev->devfn),
  6966. fn));
  6967. if (!other_pdev)
  6968. continue;
  6969. if (atomic_read(&other_pdev->enable_cnt)) {
  6970. ql4_printk(KERN_INFO, ha, "scsi%ld: %s: Found PCI "
  6971. "func in enabled state%x\n", ha->host_no,
  6972. __func__, fn);
  6973. pci_dev_put(other_pdev);
  6974. break;
  6975. }
  6976. pci_dev_put(other_pdev);
  6977. }
  6978. /* The first function on the card, the reset owner will
  6979. * start & initialize the firmware. The other functions
  6980. * on the card will reset the firmware context
  6981. */
  6982. if (!fn) {
  6983. ql4_printk(KERN_INFO, ha, "scsi%ld: %s: devfn being reset "
  6984. "0x%x is the owner\n", ha->host_no, __func__,
  6985. ha->pdev->devfn);
  6986. ha->isp_ops->idc_lock(ha);
  6987. qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DEV_STATE,
  6988. QLA8XXX_DEV_COLD);
  6989. ha->isp_ops->idc_unlock(ha);
  6990. rval = qla4_8xxx_update_idc_reg(ha);
  6991. if (rval == QLA_ERROR) {
  6992. ql4_printk(KERN_INFO, ha, "scsi%ld: %s: HW State: FAILED\n",
  6993. ha->host_no, __func__);
  6994. ha->isp_ops->idc_lock(ha);
  6995. qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DEV_STATE,
  6996. QLA8XXX_DEV_FAILED);
  6997. ha->isp_ops->idc_unlock(ha);
  6998. goto exit_error_recovery;
  6999. }
  7000. clear_bit(AF_FW_RECOVERY, &ha->flags);
  7001. rval = qla4xxx_initialize_adapter(ha, RESET_ADAPTER);
  7002. if (rval != QLA_SUCCESS) {
  7003. ql4_printk(KERN_INFO, ha, "scsi%ld: %s: HW State: "
  7004. "FAILED\n", ha->host_no, __func__);
  7005. ha->isp_ops->idc_lock(ha);
  7006. qla4_8xxx_clear_drv_active(ha);
  7007. qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DEV_STATE,
  7008. QLA8XXX_DEV_FAILED);
  7009. ha->isp_ops->idc_unlock(ha);
  7010. } else {
  7011. ql4_printk(KERN_INFO, ha, "scsi%ld: %s: HW State: "
  7012. "READY\n", ha->host_no, __func__);
  7013. ha->isp_ops->idc_lock(ha);
  7014. qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DEV_STATE,
  7015. QLA8XXX_DEV_READY);
  7016. /* Clear driver state register */
  7017. qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DRV_STATE, 0);
  7018. qla4_8xxx_set_drv_active(ha);
  7019. ha->isp_ops->idc_unlock(ha);
  7020. ha->isp_ops->enable_intrs(ha);
  7021. }
  7022. } else {
  7023. ql4_printk(KERN_INFO, ha, "scsi%ld: %s: devfn 0x%x is not "
  7024. "the reset owner\n", ha->host_no, __func__,
  7025. ha->pdev->devfn);
  7026. if ((qla4_8xxx_rd_direct(ha, QLA8XXX_CRB_DEV_STATE) ==
  7027. QLA8XXX_DEV_READY)) {
  7028. clear_bit(AF_FW_RECOVERY, &ha->flags);
  7029. rval = qla4xxx_initialize_adapter(ha, RESET_ADAPTER);
  7030. if (rval == QLA_SUCCESS)
  7031. ha->isp_ops->enable_intrs(ha);
  7032. ha->isp_ops->idc_lock(ha);
  7033. qla4_8xxx_set_drv_active(ha);
  7034. ha->isp_ops->idc_unlock(ha);
  7035. }
  7036. }
  7037. exit_error_recovery:
  7038. clear_bit(DPC_RESET_ACTIVE, &ha->dpc_flags);
  7039. return rval;
  7040. }
  7041. static pci_ers_result_t
  7042. qla4xxx_pci_slot_reset(struct pci_dev *pdev)
  7043. {
  7044. pci_ers_result_t ret = PCI_ERS_RESULT_DISCONNECT;
  7045. struct scsi_qla_host *ha = pci_get_drvdata(pdev);
  7046. int rc;
  7047. ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: slot_reset\n",
  7048. ha->host_no, __func__);
  7049. if (!is_aer_supported(ha))
  7050. return PCI_ERS_RESULT_NONE;
  7051. /* Restore the saved state of PCIe device -
  7052. * BAR registers, PCI Config space, PCIX, MSI,
  7053. * IOV states
  7054. */
  7055. pci_restore_state(pdev);
  7056. /* pci_restore_state() clears the saved_state flag of the device
  7057. * save restored state which resets saved_state flag
  7058. */
  7059. pci_save_state(pdev);
  7060. /* Initialize device or resume if in suspended state */
  7061. rc = pci_enable_device(pdev);
  7062. if (rc) {
  7063. ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: Can't re-enable "
  7064. "device after reset\n", ha->host_no, __func__);
  7065. goto exit_slot_reset;
  7066. }
  7067. ha->isp_ops->disable_intrs(ha);
  7068. if (is_qla80XX(ha)) {
  7069. if (qla4_8xxx_error_recovery(ha) == QLA_SUCCESS) {
  7070. ret = PCI_ERS_RESULT_RECOVERED;
  7071. goto exit_slot_reset;
  7072. } else
  7073. goto exit_slot_reset;
  7074. }
  7075. exit_slot_reset:
  7076. ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: Return=%x\n"
  7077. "device after reset\n", ha->host_no, __func__, ret);
  7078. return ret;
  7079. }
  7080. static void
  7081. qla4xxx_pci_resume(struct pci_dev *pdev)
  7082. {
  7083. struct scsi_qla_host *ha = pci_get_drvdata(pdev);
  7084. int ret;
  7085. ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: pci_resume\n",
  7086. ha->host_no, __func__);
  7087. ret = qla4xxx_wait_for_hba_online(ha);
  7088. if (ret != QLA_SUCCESS) {
  7089. ql4_printk(KERN_ERR, ha, "scsi%ld: %s: the device failed to "
  7090. "resume I/O from slot/link_reset\n", ha->host_no,
  7091. __func__);
  7092. }
  7093. pci_cleanup_aer_uncorrect_error_status(pdev);
  7094. clear_bit(AF_EEH_BUSY, &ha->flags);
  7095. }
  7096. static const struct pci_error_handlers qla4xxx_err_handler = {
  7097. .error_detected = qla4xxx_pci_error_detected,
  7098. .mmio_enabled = qla4xxx_pci_mmio_enabled,
  7099. .slot_reset = qla4xxx_pci_slot_reset,
  7100. .resume = qla4xxx_pci_resume,
  7101. };
  7102. static struct pci_device_id qla4xxx_pci_tbl[] = {
  7103. {
  7104. .vendor = PCI_VENDOR_ID_QLOGIC,
  7105. .device = PCI_DEVICE_ID_QLOGIC_ISP4010,
  7106. .subvendor = PCI_ANY_ID,
  7107. .subdevice = PCI_ANY_ID,
  7108. },
  7109. {
  7110. .vendor = PCI_VENDOR_ID_QLOGIC,
  7111. .device = PCI_DEVICE_ID_QLOGIC_ISP4022,
  7112. .subvendor = PCI_ANY_ID,
  7113. .subdevice = PCI_ANY_ID,
  7114. },
  7115. {
  7116. .vendor = PCI_VENDOR_ID_QLOGIC,
  7117. .device = PCI_DEVICE_ID_QLOGIC_ISP4032,
  7118. .subvendor = PCI_ANY_ID,
  7119. .subdevice = PCI_ANY_ID,
  7120. },
  7121. {
  7122. .vendor = PCI_VENDOR_ID_QLOGIC,
  7123. .device = PCI_DEVICE_ID_QLOGIC_ISP8022,
  7124. .subvendor = PCI_ANY_ID,
  7125. .subdevice = PCI_ANY_ID,
  7126. },
  7127. {
  7128. .vendor = PCI_VENDOR_ID_QLOGIC,
  7129. .device = PCI_DEVICE_ID_QLOGIC_ISP8324,
  7130. .subvendor = PCI_ANY_ID,
  7131. .subdevice = PCI_ANY_ID,
  7132. },
  7133. {
  7134. .vendor = PCI_VENDOR_ID_QLOGIC,
  7135. .device = PCI_DEVICE_ID_QLOGIC_ISP8042,
  7136. .subvendor = PCI_ANY_ID,
  7137. .subdevice = PCI_ANY_ID,
  7138. },
  7139. {0, 0},
  7140. };
  7141. MODULE_DEVICE_TABLE(pci, qla4xxx_pci_tbl);
  7142. static struct pci_driver qla4xxx_pci_driver = {
  7143. .name = DRIVER_NAME,
  7144. .id_table = qla4xxx_pci_tbl,
  7145. .probe = qla4xxx_probe_adapter,
  7146. .remove = qla4xxx_remove_adapter,
  7147. .err_handler = &qla4xxx_err_handler,
  7148. };
  7149. static int __init qla4xxx_module_init(void)
  7150. {
  7151. int ret;
  7152. /* Allocate cache for SRBs. */
  7153. srb_cachep = kmem_cache_create("qla4xxx_srbs", sizeof(struct srb), 0,
  7154. SLAB_HWCACHE_ALIGN, NULL);
  7155. if (srb_cachep == NULL) {
  7156. printk(KERN_ERR
  7157. "%s: Unable to allocate SRB cache..."
  7158. "Failing load!\n", DRIVER_NAME);
  7159. ret = -ENOMEM;
  7160. goto no_srp_cache;
  7161. }
  7162. /* Derive version string. */
  7163. strcpy(qla4xxx_version_str, QLA4XXX_DRIVER_VERSION);
  7164. if (ql4xextended_error_logging)
  7165. strcat(qla4xxx_version_str, "-debug");
  7166. qla4xxx_scsi_transport =
  7167. iscsi_register_transport(&qla4xxx_iscsi_transport);
  7168. if (!qla4xxx_scsi_transport){
  7169. ret = -ENODEV;
  7170. goto release_srb_cache;
  7171. }
  7172. ret = pci_register_driver(&qla4xxx_pci_driver);
  7173. if (ret)
  7174. goto unregister_transport;
  7175. printk(KERN_INFO "QLogic iSCSI HBA Driver\n");
  7176. return 0;
  7177. unregister_transport:
  7178. iscsi_unregister_transport(&qla4xxx_iscsi_transport);
  7179. release_srb_cache:
  7180. kmem_cache_destroy(srb_cachep);
  7181. no_srp_cache:
  7182. return ret;
  7183. }
  7184. static void __exit qla4xxx_module_exit(void)
  7185. {
  7186. pci_unregister_driver(&qla4xxx_pci_driver);
  7187. iscsi_unregister_transport(&qla4xxx_iscsi_transport);
  7188. kmem_cache_destroy(srb_cachep);
  7189. }
  7190. module_init(qla4xxx_module_init);
  7191. module_exit(qla4xxx_module_exit);
  7192. MODULE_AUTHOR("QLogic Corporation");
  7193. MODULE_DESCRIPTION("QLogic iSCSI HBA Driver");
  7194. MODULE_LICENSE("GPL");
  7195. MODULE_VERSION(QLA4XXX_DRIVER_VERSION);