ql4_os.c 233 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269
  1. /*
  2. * QLogic iSCSI HBA Driver
  3. * Copyright (c) 2003-2012 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->ipv4_tos = conn->ipv4_tos;
  1998. fw_ddb_entry->ipv6_flow_lbl = cpu_to_le16(conn->ipv6_flow_label);
  1999. fw_ddb_entry->ka_timeout = cpu_to_le16(conn->keepalive_timeout);
  2000. fw_ddb_entry->lcl_port = cpu_to_le16(conn->local_port);
  2001. fw_ddb_entry->stat_sn = cpu_to_le32(conn->statsn);
  2002. fw_ddb_entry->exp_stat_sn = cpu_to_le32(conn->exp_statsn);
  2003. fw_ddb_entry->ddb_link = cpu_to_le16(sess->discovery_parent_type);
  2004. fw_ddb_entry->chap_tbl_idx = cpu_to_le16(sess->chap_out_idx);
  2005. fw_ddb_entry->tsid = cpu_to_le16(sess->tsid);
  2006. fw_ddb_entry->port = cpu_to_le16(conn->port);
  2007. fw_ddb_entry->def_timeout =
  2008. cpu_to_le16(sess->default_taskmgmt_timeout);
  2009. if (conn->ipaddress)
  2010. memcpy(fw_ddb_entry->ip_addr, conn->ipaddress,
  2011. sizeof(fw_ddb_entry->ip_addr));
  2012. if (conn->redirect_ipaddr)
  2013. memcpy(fw_ddb_entry->tgt_addr, conn->redirect_ipaddr,
  2014. sizeof(fw_ddb_entry->tgt_addr));
  2015. if (conn->link_local_ipv6_addr)
  2016. memcpy(fw_ddb_entry->link_local_ipv6_addr,
  2017. conn->link_local_ipv6_addr,
  2018. sizeof(fw_ddb_entry->link_local_ipv6_addr));
  2019. if (sess->targetname)
  2020. memcpy(fw_ddb_entry->iscsi_name, sess->targetname,
  2021. sizeof(fw_ddb_entry->iscsi_name));
  2022. if (sess->targetalias)
  2023. memcpy(fw_ddb_entry->iscsi_alias, sess->targetalias,
  2024. sizeof(fw_ddb_entry->iscsi_alias));
  2025. COPY_ISID(fw_ddb_entry->isid, sess->isid);
  2026. return rc;
  2027. }
  2028. static void qla4xxx_copy_to_sess_conn_params(struct iscsi_conn *conn,
  2029. struct iscsi_session *sess,
  2030. struct dev_db_entry *fw_ddb_entry)
  2031. {
  2032. unsigned long options = 0;
  2033. uint16_t ddb_link;
  2034. uint16_t disc_parent;
  2035. options = le16_to_cpu(fw_ddb_entry->options);
  2036. conn->is_fw_assigned_ipv6 = test_bit(OPT_IS_FW_ASSIGNED_IPV6, &options);
  2037. sess->auto_snd_tgt_disable = test_bit(OPT_AUTO_SENDTGTS_DISABLE,
  2038. &options);
  2039. sess->discovery_sess = test_bit(OPT_DISC_SESSION, &options);
  2040. options = le16_to_cpu(fw_ddb_entry->iscsi_options);
  2041. conn->hdrdgst_en = test_bit(ISCSIOPT_HEADER_DIGEST_EN, &options);
  2042. conn->datadgst_en = test_bit(ISCSIOPT_DATA_DIGEST_EN, &options);
  2043. sess->imm_data_en = test_bit(ISCSIOPT_IMMEDIATE_DATA_EN, &options);
  2044. sess->initial_r2t_en = test_bit(ISCSIOPT_INITIAL_R2T_EN, &options);
  2045. sess->dataseq_inorder_en = test_bit(ISCSIOPT_DATA_SEQ_IN_ORDER,
  2046. &options);
  2047. sess->pdu_inorder_en = test_bit(ISCSIOPT_DATA_PDU_IN_ORDER, &options);
  2048. sess->chap_auth_en = test_bit(ISCSIOPT_CHAP_AUTH_EN, &options);
  2049. sess->discovery_logout_en = test_bit(ISCSIOPT_DISCOVERY_LOGOUT_EN,
  2050. &options);
  2051. sess->bidi_chap_en = test_bit(ISCSIOPT_BIDI_CHAP_EN, &options);
  2052. sess->discovery_auth_optional =
  2053. test_bit(ISCSIOPT_DISCOVERY_AUTH_OPTIONAL, &options);
  2054. if (test_bit(ISCSIOPT_ERL1, &options))
  2055. sess->erl |= BIT_1;
  2056. if (test_bit(ISCSIOPT_ERL0, &options))
  2057. sess->erl |= BIT_0;
  2058. options = le16_to_cpu(fw_ddb_entry->tcp_options);
  2059. conn->tcp_timestamp_stat = test_bit(TCPOPT_TIMESTAMP_STAT, &options);
  2060. conn->tcp_nagle_disable = test_bit(TCPOPT_NAGLE_DISABLE, &options);
  2061. conn->tcp_wsf_disable = test_bit(TCPOPT_WSF_DISABLE, &options);
  2062. if (test_bit(TCPOPT_TIMER_SCALE3, &options))
  2063. conn->tcp_timer_scale |= BIT_3;
  2064. if (test_bit(TCPOPT_TIMER_SCALE2, &options))
  2065. conn->tcp_timer_scale |= BIT_2;
  2066. if (test_bit(TCPOPT_TIMER_SCALE1, &options))
  2067. conn->tcp_timer_scale |= BIT_1;
  2068. conn->tcp_timer_scale >>= 1;
  2069. conn->tcp_timestamp_en = test_bit(TCPOPT_TIMESTAMP_EN, &options);
  2070. options = le16_to_cpu(fw_ddb_entry->ip_options);
  2071. conn->fragment_disable = test_bit(IPOPT_FRAGMENT_DISABLE, &options);
  2072. conn->max_recv_dlength = BYTE_UNITS *
  2073. le16_to_cpu(fw_ddb_entry->iscsi_max_rcv_data_seg_len);
  2074. conn->max_xmit_dlength = BYTE_UNITS *
  2075. le16_to_cpu(fw_ddb_entry->iscsi_max_snd_data_seg_len);
  2076. sess->max_r2t = le16_to_cpu(fw_ddb_entry->iscsi_max_outsnd_r2t);
  2077. sess->first_burst = BYTE_UNITS *
  2078. le16_to_cpu(fw_ddb_entry->iscsi_first_burst_len);
  2079. sess->max_burst = BYTE_UNITS *
  2080. le16_to_cpu(fw_ddb_entry->iscsi_max_burst_len);
  2081. sess->time2wait = le16_to_cpu(fw_ddb_entry->iscsi_def_time2wait);
  2082. sess->time2retain = le16_to_cpu(fw_ddb_entry->iscsi_def_time2retain);
  2083. sess->tpgt = le32_to_cpu(fw_ddb_entry->tgt_portal_grp);
  2084. conn->max_segment_size = le16_to_cpu(fw_ddb_entry->mss);
  2085. conn->tcp_xmit_wsf = fw_ddb_entry->tcp_xmt_wsf;
  2086. conn->tcp_recv_wsf = fw_ddb_entry->tcp_rcv_wsf;
  2087. conn->ipv4_tos = fw_ddb_entry->ipv4_tos;
  2088. conn->keepalive_tmo = le16_to_cpu(fw_ddb_entry->ka_timeout);
  2089. conn->local_port = le16_to_cpu(fw_ddb_entry->lcl_port);
  2090. conn->statsn = le32_to_cpu(fw_ddb_entry->stat_sn);
  2091. conn->exp_statsn = le32_to_cpu(fw_ddb_entry->exp_stat_sn);
  2092. sess->tsid = le16_to_cpu(fw_ddb_entry->tsid);
  2093. COPY_ISID(sess->isid, fw_ddb_entry->isid);
  2094. ddb_link = le16_to_cpu(fw_ddb_entry->ddb_link);
  2095. if (ddb_link < MAX_DDB_ENTRIES)
  2096. sess->discovery_parent_idx = ddb_link;
  2097. else
  2098. sess->discovery_parent_idx = DDB_NO_LINK;
  2099. if (ddb_link == DDB_ISNS)
  2100. disc_parent = ISCSI_DISC_PARENT_ISNS;
  2101. else if (ddb_link == DDB_NO_LINK)
  2102. disc_parent = ISCSI_DISC_PARENT_UNKNOWN;
  2103. else if (ddb_link < MAX_DDB_ENTRIES)
  2104. disc_parent = ISCSI_DISC_PARENT_SENDTGT;
  2105. else
  2106. disc_parent = ISCSI_DISC_PARENT_UNKNOWN;
  2107. iscsi_set_param(conn->cls_conn, ISCSI_PARAM_DISCOVERY_PARENT_TYPE,
  2108. iscsi_get_discovery_parent_name(disc_parent), 0);
  2109. iscsi_set_param(conn->cls_conn, ISCSI_PARAM_TARGET_ALIAS,
  2110. (char *)fw_ddb_entry->iscsi_alias, 0);
  2111. }
  2112. static void qla4xxx_copy_fwddb_param(struct scsi_qla_host *ha,
  2113. struct dev_db_entry *fw_ddb_entry,
  2114. struct iscsi_cls_session *cls_sess,
  2115. struct iscsi_cls_conn *cls_conn)
  2116. {
  2117. int buflen = 0;
  2118. struct iscsi_session *sess;
  2119. struct ddb_entry *ddb_entry;
  2120. struct iscsi_conn *conn;
  2121. char ip_addr[DDB_IPADDR_LEN];
  2122. uint16_t options = 0;
  2123. sess = cls_sess->dd_data;
  2124. ddb_entry = sess->dd_data;
  2125. conn = cls_conn->dd_data;
  2126. ddb_entry->chap_tbl_idx = le16_to_cpu(fw_ddb_entry->chap_tbl_idx);
  2127. qla4xxx_copy_to_sess_conn_params(conn, sess, fw_ddb_entry);
  2128. sess->def_taskmgmt_tmo = le16_to_cpu(fw_ddb_entry->def_timeout);
  2129. conn->persistent_port = le16_to_cpu(fw_ddb_entry->port);
  2130. memset(ip_addr, 0, sizeof(ip_addr));
  2131. options = le16_to_cpu(fw_ddb_entry->options);
  2132. if (options & DDB_OPT_IPV6_DEVICE) {
  2133. iscsi_set_param(cls_conn, ISCSI_PARAM_PORTAL_TYPE, "ipv6", 4);
  2134. memset(ip_addr, 0, sizeof(ip_addr));
  2135. sprintf(ip_addr, "%pI6", fw_ddb_entry->ip_addr);
  2136. } else {
  2137. iscsi_set_param(cls_conn, ISCSI_PARAM_PORTAL_TYPE, "ipv4", 4);
  2138. sprintf(ip_addr, "%pI4", fw_ddb_entry->ip_addr);
  2139. }
  2140. iscsi_set_param(cls_conn, ISCSI_PARAM_PERSISTENT_ADDRESS,
  2141. (char *)ip_addr, buflen);
  2142. iscsi_set_param(cls_conn, ISCSI_PARAM_TARGET_NAME,
  2143. (char *)fw_ddb_entry->iscsi_name, buflen);
  2144. iscsi_set_param(cls_conn, ISCSI_PARAM_INITIATOR_NAME,
  2145. (char *)ha->name_string, buflen);
  2146. }
  2147. void qla4xxx_update_session_conn_fwddb_param(struct scsi_qla_host *ha,
  2148. struct ddb_entry *ddb_entry)
  2149. {
  2150. struct iscsi_cls_session *cls_sess;
  2151. struct iscsi_cls_conn *cls_conn;
  2152. uint32_t ddb_state;
  2153. dma_addr_t fw_ddb_entry_dma;
  2154. struct dev_db_entry *fw_ddb_entry;
  2155. fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
  2156. &fw_ddb_entry_dma, GFP_KERNEL);
  2157. if (!fw_ddb_entry) {
  2158. ql4_printk(KERN_ERR, ha,
  2159. "%s: Unable to allocate dma buffer\n", __func__);
  2160. goto exit_session_conn_fwddb_param;
  2161. }
  2162. if (qla4xxx_get_fwddb_entry(ha, ddb_entry->fw_ddb_index, fw_ddb_entry,
  2163. fw_ddb_entry_dma, NULL, NULL, &ddb_state,
  2164. NULL, NULL, NULL) == QLA_ERROR) {
  2165. DEBUG2(ql4_printk(KERN_ERR, ha, "scsi%ld: %s: failed "
  2166. "get_ddb_entry for fw_ddb_index %d\n",
  2167. ha->host_no, __func__,
  2168. ddb_entry->fw_ddb_index));
  2169. goto exit_session_conn_fwddb_param;
  2170. }
  2171. cls_sess = ddb_entry->sess;
  2172. cls_conn = ddb_entry->conn;
  2173. /* Update params */
  2174. qla4xxx_copy_fwddb_param(ha, fw_ddb_entry, cls_sess, cls_conn);
  2175. exit_session_conn_fwddb_param:
  2176. if (fw_ddb_entry)
  2177. dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
  2178. fw_ddb_entry, fw_ddb_entry_dma);
  2179. }
  2180. void qla4xxx_update_session_conn_param(struct scsi_qla_host *ha,
  2181. struct ddb_entry *ddb_entry)
  2182. {
  2183. struct iscsi_cls_session *cls_sess;
  2184. struct iscsi_cls_conn *cls_conn;
  2185. struct iscsi_session *sess;
  2186. struct iscsi_conn *conn;
  2187. uint32_t ddb_state;
  2188. dma_addr_t fw_ddb_entry_dma;
  2189. struct dev_db_entry *fw_ddb_entry;
  2190. fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
  2191. &fw_ddb_entry_dma, GFP_KERNEL);
  2192. if (!fw_ddb_entry) {
  2193. ql4_printk(KERN_ERR, ha,
  2194. "%s: Unable to allocate dma buffer\n", __func__);
  2195. goto exit_session_conn_param;
  2196. }
  2197. if (qla4xxx_get_fwddb_entry(ha, ddb_entry->fw_ddb_index, fw_ddb_entry,
  2198. fw_ddb_entry_dma, NULL, NULL, &ddb_state,
  2199. NULL, NULL, NULL) == QLA_ERROR) {
  2200. DEBUG2(ql4_printk(KERN_ERR, ha, "scsi%ld: %s: failed "
  2201. "get_ddb_entry for fw_ddb_index %d\n",
  2202. ha->host_no, __func__,
  2203. ddb_entry->fw_ddb_index));
  2204. goto exit_session_conn_param;
  2205. }
  2206. cls_sess = ddb_entry->sess;
  2207. sess = cls_sess->dd_data;
  2208. cls_conn = ddb_entry->conn;
  2209. conn = cls_conn->dd_data;
  2210. /* Update timers after login */
  2211. ddb_entry->default_relogin_timeout =
  2212. (le16_to_cpu(fw_ddb_entry->def_timeout) > LOGIN_TOV) &&
  2213. (le16_to_cpu(fw_ddb_entry->def_timeout) < LOGIN_TOV * 10) ?
  2214. le16_to_cpu(fw_ddb_entry->def_timeout) : LOGIN_TOV;
  2215. ddb_entry->default_time2wait =
  2216. le16_to_cpu(fw_ddb_entry->iscsi_def_time2wait);
  2217. /* Update params */
  2218. ddb_entry->chap_tbl_idx = le16_to_cpu(fw_ddb_entry->chap_tbl_idx);
  2219. qla4xxx_copy_to_sess_conn_params(conn, sess, fw_ddb_entry);
  2220. memcpy(sess->initiatorname, ha->name_string,
  2221. min(sizeof(ha->name_string), sizeof(sess->initiatorname)));
  2222. exit_session_conn_param:
  2223. if (fw_ddb_entry)
  2224. dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
  2225. fw_ddb_entry, fw_ddb_entry_dma);
  2226. }
  2227. /*
  2228. * Timer routines
  2229. */
  2230. static void qla4xxx_start_timer(struct scsi_qla_host *ha, void *func,
  2231. unsigned long interval)
  2232. {
  2233. DEBUG(printk("scsi: %s: Starting timer thread for adapter %d\n",
  2234. __func__, ha->host->host_no));
  2235. init_timer(&ha->timer);
  2236. ha->timer.expires = jiffies + interval * HZ;
  2237. ha->timer.data = (unsigned long)ha;
  2238. ha->timer.function = (void (*)(unsigned long))func;
  2239. add_timer(&ha->timer);
  2240. ha->timer_active = 1;
  2241. }
  2242. static void qla4xxx_stop_timer(struct scsi_qla_host *ha)
  2243. {
  2244. del_timer_sync(&ha->timer);
  2245. ha->timer_active = 0;
  2246. }
  2247. /***
  2248. * qla4xxx_mark_device_missing - blocks the session
  2249. * @cls_session: Pointer to the session to be blocked
  2250. * @ddb_entry: Pointer to device database entry
  2251. *
  2252. * This routine marks a device missing and close connection.
  2253. **/
  2254. void qla4xxx_mark_device_missing(struct iscsi_cls_session *cls_session)
  2255. {
  2256. iscsi_block_session(cls_session);
  2257. }
  2258. /**
  2259. * qla4xxx_mark_all_devices_missing - mark all devices as missing.
  2260. * @ha: Pointer to host adapter structure.
  2261. *
  2262. * This routine marks a device missing and resets the relogin retry count.
  2263. **/
  2264. void qla4xxx_mark_all_devices_missing(struct scsi_qla_host *ha)
  2265. {
  2266. iscsi_host_for_each_session(ha->host, qla4xxx_mark_device_missing);
  2267. }
  2268. static struct srb* qla4xxx_get_new_srb(struct scsi_qla_host *ha,
  2269. struct ddb_entry *ddb_entry,
  2270. struct scsi_cmnd *cmd)
  2271. {
  2272. struct srb *srb;
  2273. srb = mempool_alloc(ha->srb_mempool, GFP_ATOMIC);
  2274. if (!srb)
  2275. return srb;
  2276. kref_init(&srb->srb_ref);
  2277. srb->ha = ha;
  2278. srb->ddb = ddb_entry;
  2279. srb->cmd = cmd;
  2280. srb->flags = 0;
  2281. CMD_SP(cmd) = (void *)srb;
  2282. return srb;
  2283. }
  2284. static void qla4xxx_srb_free_dma(struct scsi_qla_host *ha, struct srb *srb)
  2285. {
  2286. struct scsi_cmnd *cmd = srb->cmd;
  2287. if (srb->flags & SRB_DMA_VALID) {
  2288. scsi_dma_unmap(cmd);
  2289. srb->flags &= ~SRB_DMA_VALID;
  2290. }
  2291. CMD_SP(cmd) = NULL;
  2292. }
  2293. void qla4xxx_srb_compl(struct kref *ref)
  2294. {
  2295. struct srb *srb = container_of(ref, struct srb, srb_ref);
  2296. struct scsi_cmnd *cmd = srb->cmd;
  2297. struct scsi_qla_host *ha = srb->ha;
  2298. qla4xxx_srb_free_dma(ha, srb);
  2299. mempool_free(srb, ha->srb_mempool);
  2300. cmd->scsi_done(cmd);
  2301. }
  2302. /**
  2303. * qla4xxx_queuecommand - scsi layer issues scsi command to driver.
  2304. * @host: scsi host
  2305. * @cmd: Pointer to Linux's SCSI command structure
  2306. *
  2307. * Remarks:
  2308. * This routine is invoked by Linux to send a SCSI command to the driver.
  2309. * The mid-level driver tries to ensure that queuecommand never gets
  2310. * invoked concurrently with itself or the interrupt handler (although
  2311. * the interrupt handler may call this routine as part of request-
  2312. * completion handling). Unfortunely, it sometimes calls the scheduler
  2313. * in interrupt context which is a big NO! NO!.
  2314. **/
  2315. static int qla4xxx_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *cmd)
  2316. {
  2317. struct scsi_qla_host *ha = to_qla_host(host);
  2318. struct ddb_entry *ddb_entry = cmd->device->hostdata;
  2319. struct iscsi_cls_session *sess = ddb_entry->sess;
  2320. struct srb *srb;
  2321. int rval;
  2322. if (test_bit(AF_EEH_BUSY, &ha->flags)) {
  2323. if (test_bit(AF_PCI_CHANNEL_IO_PERM_FAILURE, &ha->flags))
  2324. cmd->result = DID_NO_CONNECT << 16;
  2325. else
  2326. cmd->result = DID_REQUEUE << 16;
  2327. goto qc_fail_command;
  2328. }
  2329. if (!sess) {
  2330. cmd->result = DID_IMM_RETRY << 16;
  2331. goto qc_fail_command;
  2332. }
  2333. rval = iscsi_session_chkready(sess);
  2334. if (rval) {
  2335. cmd->result = rval;
  2336. goto qc_fail_command;
  2337. }
  2338. if (test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags) ||
  2339. test_bit(DPC_RESET_ACTIVE, &ha->dpc_flags) ||
  2340. test_bit(DPC_RESET_HA, &ha->dpc_flags) ||
  2341. test_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags) ||
  2342. test_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags) ||
  2343. !test_bit(AF_ONLINE, &ha->flags) ||
  2344. !test_bit(AF_LINK_UP, &ha->flags) ||
  2345. test_bit(AF_LOOPBACK, &ha->flags) ||
  2346. test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags))
  2347. goto qc_host_busy;
  2348. srb = qla4xxx_get_new_srb(ha, ddb_entry, cmd);
  2349. if (!srb)
  2350. goto qc_host_busy;
  2351. rval = qla4xxx_send_command_to_isp(ha, srb);
  2352. if (rval != QLA_SUCCESS)
  2353. goto qc_host_busy_free_sp;
  2354. return 0;
  2355. qc_host_busy_free_sp:
  2356. qla4xxx_srb_free_dma(ha, srb);
  2357. mempool_free(srb, ha->srb_mempool);
  2358. qc_host_busy:
  2359. return SCSI_MLQUEUE_HOST_BUSY;
  2360. qc_fail_command:
  2361. cmd->scsi_done(cmd);
  2362. return 0;
  2363. }
  2364. /**
  2365. * qla4xxx_mem_free - frees memory allocated to adapter
  2366. * @ha: Pointer to host adapter structure.
  2367. *
  2368. * Frees memory previously allocated by qla4xxx_mem_alloc
  2369. **/
  2370. static void qla4xxx_mem_free(struct scsi_qla_host *ha)
  2371. {
  2372. if (ha->queues)
  2373. dma_free_coherent(&ha->pdev->dev, ha->queues_len, ha->queues,
  2374. ha->queues_dma);
  2375. if (ha->fw_dump)
  2376. vfree(ha->fw_dump);
  2377. ha->queues_len = 0;
  2378. ha->queues = NULL;
  2379. ha->queues_dma = 0;
  2380. ha->request_ring = NULL;
  2381. ha->request_dma = 0;
  2382. ha->response_ring = NULL;
  2383. ha->response_dma = 0;
  2384. ha->shadow_regs = NULL;
  2385. ha->shadow_regs_dma = 0;
  2386. ha->fw_dump = NULL;
  2387. ha->fw_dump_size = 0;
  2388. /* Free srb pool. */
  2389. if (ha->srb_mempool)
  2390. mempool_destroy(ha->srb_mempool);
  2391. ha->srb_mempool = NULL;
  2392. if (ha->chap_dma_pool)
  2393. dma_pool_destroy(ha->chap_dma_pool);
  2394. if (ha->chap_list)
  2395. vfree(ha->chap_list);
  2396. ha->chap_list = NULL;
  2397. if (ha->fw_ddb_dma_pool)
  2398. dma_pool_destroy(ha->fw_ddb_dma_pool);
  2399. /* release io space registers */
  2400. if (is_qla8022(ha)) {
  2401. if (ha->nx_pcibase)
  2402. iounmap(
  2403. (struct device_reg_82xx __iomem *)ha->nx_pcibase);
  2404. } else if (is_qla8032(ha)) {
  2405. if (ha->nx_pcibase)
  2406. iounmap(
  2407. (struct device_reg_83xx __iomem *)ha->nx_pcibase);
  2408. } else if (ha->reg) {
  2409. iounmap(ha->reg);
  2410. }
  2411. if (ha->reset_tmplt.buff)
  2412. vfree(ha->reset_tmplt.buff);
  2413. pci_release_regions(ha->pdev);
  2414. }
  2415. /**
  2416. * qla4xxx_mem_alloc - allocates memory for use by adapter.
  2417. * @ha: Pointer to host adapter structure
  2418. *
  2419. * Allocates DMA memory for request and response queues. Also allocates memory
  2420. * for srbs.
  2421. **/
  2422. static int qla4xxx_mem_alloc(struct scsi_qla_host *ha)
  2423. {
  2424. unsigned long align;
  2425. /* Allocate contiguous block of DMA memory for queues. */
  2426. ha->queues_len = ((REQUEST_QUEUE_DEPTH * QUEUE_SIZE) +
  2427. (RESPONSE_QUEUE_DEPTH * QUEUE_SIZE) +
  2428. sizeof(struct shadow_regs) +
  2429. MEM_ALIGN_VALUE +
  2430. (PAGE_SIZE - 1)) & ~(PAGE_SIZE - 1);
  2431. ha->queues = dma_alloc_coherent(&ha->pdev->dev, ha->queues_len,
  2432. &ha->queues_dma, GFP_KERNEL);
  2433. if (ha->queues == NULL) {
  2434. ql4_printk(KERN_WARNING, ha,
  2435. "Memory Allocation failed - queues.\n");
  2436. goto mem_alloc_error_exit;
  2437. }
  2438. memset(ha->queues, 0, ha->queues_len);
  2439. /*
  2440. * As per RISC alignment requirements -- the bus-address must be a
  2441. * multiple of the request-ring size (in bytes).
  2442. */
  2443. align = 0;
  2444. if ((unsigned long)ha->queues_dma & (MEM_ALIGN_VALUE - 1))
  2445. align = MEM_ALIGN_VALUE - ((unsigned long)ha->queues_dma &
  2446. (MEM_ALIGN_VALUE - 1));
  2447. /* Update request and response queue pointers. */
  2448. ha->request_dma = ha->queues_dma + align;
  2449. ha->request_ring = (struct queue_entry *) (ha->queues + align);
  2450. ha->response_dma = ha->queues_dma + align +
  2451. (REQUEST_QUEUE_DEPTH * QUEUE_SIZE);
  2452. ha->response_ring = (struct queue_entry *) (ha->queues + align +
  2453. (REQUEST_QUEUE_DEPTH *
  2454. QUEUE_SIZE));
  2455. ha->shadow_regs_dma = ha->queues_dma + align +
  2456. (REQUEST_QUEUE_DEPTH * QUEUE_SIZE) +
  2457. (RESPONSE_QUEUE_DEPTH * QUEUE_SIZE);
  2458. ha->shadow_regs = (struct shadow_regs *) (ha->queues + align +
  2459. (REQUEST_QUEUE_DEPTH *
  2460. QUEUE_SIZE) +
  2461. (RESPONSE_QUEUE_DEPTH *
  2462. QUEUE_SIZE));
  2463. /* Allocate memory for srb pool. */
  2464. ha->srb_mempool = mempool_create(SRB_MIN_REQ, mempool_alloc_slab,
  2465. mempool_free_slab, srb_cachep);
  2466. if (ha->srb_mempool == NULL) {
  2467. ql4_printk(KERN_WARNING, ha,
  2468. "Memory Allocation failed - SRB Pool.\n");
  2469. goto mem_alloc_error_exit;
  2470. }
  2471. ha->chap_dma_pool = dma_pool_create("ql4_chap", &ha->pdev->dev,
  2472. CHAP_DMA_BLOCK_SIZE, 8, 0);
  2473. if (ha->chap_dma_pool == NULL) {
  2474. ql4_printk(KERN_WARNING, ha,
  2475. "%s: chap_dma_pool allocation failed..\n", __func__);
  2476. goto mem_alloc_error_exit;
  2477. }
  2478. ha->fw_ddb_dma_pool = dma_pool_create("ql4_fw_ddb", &ha->pdev->dev,
  2479. DDB_DMA_BLOCK_SIZE, 8, 0);
  2480. if (ha->fw_ddb_dma_pool == NULL) {
  2481. ql4_printk(KERN_WARNING, ha,
  2482. "%s: fw_ddb_dma_pool allocation failed..\n",
  2483. __func__);
  2484. goto mem_alloc_error_exit;
  2485. }
  2486. return QLA_SUCCESS;
  2487. mem_alloc_error_exit:
  2488. qla4xxx_mem_free(ha);
  2489. return QLA_ERROR;
  2490. }
  2491. /**
  2492. * qla4_8xxx_check_temp - Check the ISP82XX temperature.
  2493. * @ha: adapter block pointer.
  2494. *
  2495. * Note: The caller should not hold the idc lock.
  2496. **/
  2497. static int qla4_8xxx_check_temp(struct scsi_qla_host *ha)
  2498. {
  2499. uint32_t temp, temp_state, temp_val;
  2500. int status = QLA_SUCCESS;
  2501. temp = qla4_8xxx_rd_direct(ha, QLA8XXX_CRB_TEMP_STATE);
  2502. temp_state = qla82xx_get_temp_state(temp);
  2503. temp_val = qla82xx_get_temp_val(temp);
  2504. if (temp_state == QLA82XX_TEMP_PANIC) {
  2505. ql4_printk(KERN_WARNING, ha, "Device temperature %d degrees C"
  2506. " exceeds maximum allowed. Hardware has been shut"
  2507. " down.\n", temp_val);
  2508. status = QLA_ERROR;
  2509. } else if (temp_state == QLA82XX_TEMP_WARN) {
  2510. if (ha->temperature == QLA82XX_TEMP_NORMAL)
  2511. ql4_printk(KERN_WARNING, ha, "Device temperature %d"
  2512. " degrees C exceeds operating range."
  2513. " Immediate action needed.\n", temp_val);
  2514. } else {
  2515. if (ha->temperature == QLA82XX_TEMP_WARN)
  2516. ql4_printk(KERN_INFO, ha, "Device temperature is"
  2517. " now %d degrees C in normal range.\n",
  2518. temp_val);
  2519. }
  2520. ha->temperature = temp_state;
  2521. return status;
  2522. }
  2523. /**
  2524. * qla4_8xxx_check_fw_alive - Check firmware health
  2525. * @ha: Pointer to host adapter structure.
  2526. *
  2527. * Context: Interrupt
  2528. **/
  2529. static int qla4_8xxx_check_fw_alive(struct scsi_qla_host *ha)
  2530. {
  2531. uint32_t fw_heartbeat_counter;
  2532. int status = QLA_SUCCESS;
  2533. fw_heartbeat_counter = qla4_8xxx_rd_direct(ha,
  2534. QLA8XXX_PEG_ALIVE_COUNTER);
  2535. /* If PEG_ALIVE_COUNTER is 0xffffffff, AER/EEH is in progress, ignore */
  2536. if (fw_heartbeat_counter == 0xffffffff) {
  2537. DEBUG2(printk(KERN_WARNING "scsi%ld: %s: Device in frozen "
  2538. "state, QLA82XX_PEG_ALIVE_COUNTER is 0xffffffff\n",
  2539. ha->host_no, __func__));
  2540. return status;
  2541. }
  2542. if (ha->fw_heartbeat_counter == fw_heartbeat_counter) {
  2543. ha->seconds_since_last_heartbeat++;
  2544. /* FW not alive after 2 seconds */
  2545. if (ha->seconds_since_last_heartbeat == 2) {
  2546. ha->seconds_since_last_heartbeat = 0;
  2547. qla4_8xxx_dump_peg_reg(ha);
  2548. status = QLA_ERROR;
  2549. }
  2550. } else
  2551. ha->seconds_since_last_heartbeat = 0;
  2552. ha->fw_heartbeat_counter = fw_heartbeat_counter;
  2553. return status;
  2554. }
  2555. static void qla4_8xxx_process_fw_error(struct scsi_qla_host *ha)
  2556. {
  2557. uint32_t halt_status;
  2558. int halt_status_unrecoverable = 0;
  2559. halt_status = qla4_8xxx_rd_direct(ha, QLA8XXX_PEG_HALT_STATUS1);
  2560. if (is_qla8022(ha)) {
  2561. ql4_printk(KERN_INFO, ha, "%s: disabling pause transmit on port 0 & 1.\n",
  2562. __func__);
  2563. qla4_82xx_wr_32(ha, QLA82XX_CRB_NIU + 0x98,
  2564. CRB_NIU_XG_PAUSE_CTL_P0 |
  2565. CRB_NIU_XG_PAUSE_CTL_P1);
  2566. if (QLA82XX_FWERROR_CODE(halt_status) == 0x67)
  2567. ql4_printk(KERN_ERR, ha, "%s: Firmware aborted with error code 0x00006700. Device is being reset\n",
  2568. __func__);
  2569. if (halt_status & HALT_STATUS_UNRECOVERABLE)
  2570. halt_status_unrecoverable = 1;
  2571. } else if (is_qla8032(ha)) {
  2572. if (halt_status & QLA83XX_HALT_STATUS_FW_RESET)
  2573. ql4_printk(KERN_ERR, ha, "%s: Firmware error detected device is being reset\n",
  2574. __func__);
  2575. else if (halt_status & QLA83XX_HALT_STATUS_UNRECOVERABLE)
  2576. halt_status_unrecoverable = 1;
  2577. }
  2578. /*
  2579. * Since we cannot change dev_state in interrupt context,
  2580. * set appropriate DPC flag then wakeup DPC
  2581. */
  2582. if (halt_status_unrecoverable) {
  2583. set_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags);
  2584. } else {
  2585. ql4_printk(KERN_INFO, ha, "%s: detect abort needed!\n",
  2586. __func__);
  2587. set_bit(DPC_RESET_HA, &ha->dpc_flags);
  2588. }
  2589. qla4xxx_mailbox_premature_completion(ha);
  2590. qla4xxx_wake_dpc(ha);
  2591. }
  2592. /**
  2593. * qla4_8xxx_watchdog - Poll dev state
  2594. * @ha: Pointer to host adapter structure.
  2595. *
  2596. * Context: Interrupt
  2597. **/
  2598. void qla4_8xxx_watchdog(struct scsi_qla_host *ha)
  2599. {
  2600. uint32_t dev_state;
  2601. uint32_t idc_ctrl;
  2602. /* don't poll if reset is going on */
  2603. if (!(test_bit(DPC_RESET_ACTIVE, &ha->dpc_flags) ||
  2604. test_bit(DPC_RESET_HA, &ha->dpc_flags) ||
  2605. test_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags))) {
  2606. dev_state = qla4_8xxx_rd_direct(ha, QLA8XXX_CRB_DEV_STATE);
  2607. if (qla4_8xxx_check_temp(ha)) {
  2608. if (is_qla8022(ha)) {
  2609. ql4_printk(KERN_INFO, ha, "disabling pause transmit on port 0 & 1.\n");
  2610. qla4_82xx_wr_32(ha, QLA82XX_CRB_NIU + 0x98,
  2611. CRB_NIU_XG_PAUSE_CTL_P0 |
  2612. CRB_NIU_XG_PAUSE_CTL_P1);
  2613. }
  2614. set_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags);
  2615. qla4xxx_wake_dpc(ha);
  2616. } else if (dev_state == QLA8XXX_DEV_NEED_RESET &&
  2617. !test_bit(DPC_RESET_HA, &ha->dpc_flags)) {
  2618. ql4_printk(KERN_INFO, ha, "%s: HW State: NEED RESET!\n",
  2619. __func__);
  2620. if (is_qla8032(ha)) {
  2621. idc_ctrl = qla4_83xx_rd_reg(ha,
  2622. QLA83XX_IDC_DRV_CTRL);
  2623. if (!(idc_ctrl & GRACEFUL_RESET_BIT1)) {
  2624. ql4_printk(KERN_INFO, ha, "%s: Graceful reset bit is not set\n",
  2625. __func__);
  2626. qla4xxx_mailbox_premature_completion(
  2627. ha);
  2628. }
  2629. }
  2630. if (is_qla8032(ha) ||
  2631. (is_qla8022(ha) && !ql4xdontresethba)) {
  2632. set_bit(DPC_RESET_HA, &ha->dpc_flags);
  2633. qla4xxx_wake_dpc(ha);
  2634. }
  2635. } else if (dev_state == QLA8XXX_DEV_NEED_QUIESCENT &&
  2636. !test_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags)) {
  2637. ql4_printk(KERN_INFO, ha, "%s: HW State: NEED QUIES!\n",
  2638. __func__);
  2639. set_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags);
  2640. qla4xxx_wake_dpc(ha);
  2641. } else {
  2642. /* Check firmware health */
  2643. if (qla4_8xxx_check_fw_alive(ha))
  2644. qla4_8xxx_process_fw_error(ha);
  2645. }
  2646. }
  2647. }
  2648. static void qla4xxx_check_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
  2649. {
  2650. struct iscsi_session *sess;
  2651. struct ddb_entry *ddb_entry;
  2652. struct scsi_qla_host *ha;
  2653. sess = cls_sess->dd_data;
  2654. ddb_entry = sess->dd_data;
  2655. ha = ddb_entry->ha;
  2656. if (!(ddb_entry->ddb_type == FLASH_DDB))
  2657. return;
  2658. if (adapter_up(ha) && !test_bit(DF_RELOGIN, &ddb_entry->flags) &&
  2659. !iscsi_is_session_online(cls_sess)) {
  2660. if (atomic_read(&ddb_entry->retry_relogin_timer) !=
  2661. INVALID_ENTRY) {
  2662. if (atomic_read(&ddb_entry->retry_relogin_timer) ==
  2663. 0) {
  2664. atomic_set(&ddb_entry->retry_relogin_timer,
  2665. INVALID_ENTRY);
  2666. set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
  2667. set_bit(DF_RELOGIN, &ddb_entry->flags);
  2668. DEBUG2(ql4_printk(KERN_INFO, ha,
  2669. "%s: index [%d] login device\n",
  2670. __func__, ddb_entry->fw_ddb_index));
  2671. } else
  2672. atomic_dec(&ddb_entry->retry_relogin_timer);
  2673. }
  2674. }
  2675. /* Wait for relogin to timeout */
  2676. if (atomic_read(&ddb_entry->relogin_timer) &&
  2677. (atomic_dec_and_test(&ddb_entry->relogin_timer) != 0)) {
  2678. /*
  2679. * If the relogin times out and the device is
  2680. * still NOT ONLINE then try and relogin again.
  2681. */
  2682. if (!iscsi_is_session_online(cls_sess)) {
  2683. /* Reset retry relogin timer */
  2684. atomic_inc(&ddb_entry->relogin_retry_count);
  2685. DEBUG2(ql4_printk(KERN_INFO, ha,
  2686. "%s: index[%d] relogin timed out-retrying"
  2687. " relogin (%d), retry (%d)\n", __func__,
  2688. ddb_entry->fw_ddb_index,
  2689. atomic_read(&ddb_entry->relogin_retry_count),
  2690. ddb_entry->default_time2wait + 4));
  2691. set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
  2692. atomic_set(&ddb_entry->retry_relogin_timer,
  2693. ddb_entry->default_time2wait + 4);
  2694. }
  2695. }
  2696. }
  2697. /**
  2698. * qla4xxx_timer - checks every second for work to do.
  2699. * @ha: Pointer to host adapter structure.
  2700. **/
  2701. static void qla4xxx_timer(struct scsi_qla_host *ha)
  2702. {
  2703. int start_dpc = 0;
  2704. uint16_t w;
  2705. iscsi_host_for_each_session(ha->host, qla4xxx_check_relogin_flash_ddb);
  2706. /* If we are in the middle of AER/EEH processing
  2707. * skip any processing and reschedule the timer
  2708. */
  2709. if (test_bit(AF_EEH_BUSY, &ha->flags)) {
  2710. mod_timer(&ha->timer, jiffies + HZ);
  2711. return;
  2712. }
  2713. /* Hardware read to trigger an EEH error during mailbox waits. */
  2714. if (!pci_channel_offline(ha->pdev))
  2715. pci_read_config_word(ha->pdev, PCI_VENDOR_ID, &w);
  2716. if (is_qla80XX(ha))
  2717. qla4_8xxx_watchdog(ha);
  2718. if (is_qla40XX(ha)) {
  2719. /* Check for heartbeat interval. */
  2720. if (ha->firmware_options & FWOPT_HEARTBEAT_ENABLE &&
  2721. ha->heartbeat_interval != 0) {
  2722. ha->seconds_since_last_heartbeat++;
  2723. if (ha->seconds_since_last_heartbeat >
  2724. ha->heartbeat_interval + 2)
  2725. set_bit(DPC_RESET_HA, &ha->dpc_flags);
  2726. }
  2727. }
  2728. /* Process any deferred work. */
  2729. if (!list_empty(&ha->work_list))
  2730. start_dpc++;
  2731. /* Wakeup the dpc routine for this adapter, if needed. */
  2732. if (start_dpc ||
  2733. test_bit(DPC_RESET_HA, &ha->dpc_flags) ||
  2734. test_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags) ||
  2735. test_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags) ||
  2736. test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags) ||
  2737. test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags) ||
  2738. test_bit(DPC_GET_DHCP_IP_ADDR, &ha->dpc_flags) ||
  2739. test_bit(DPC_LINK_CHANGED, &ha->dpc_flags) ||
  2740. test_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags) ||
  2741. test_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags) ||
  2742. test_bit(DPC_AEN, &ha->dpc_flags)) {
  2743. DEBUG2(printk("scsi%ld: %s: scheduling dpc routine"
  2744. " - dpc flags = 0x%lx\n",
  2745. ha->host_no, __func__, ha->dpc_flags));
  2746. qla4xxx_wake_dpc(ha);
  2747. }
  2748. /* Reschedule timer thread to call us back in one second */
  2749. mod_timer(&ha->timer, jiffies + HZ);
  2750. DEBUG2(ha->seconds_since_last_intr++);
  2751. }
  2752. /**
  2753. * qla4xxx_cmd_wait - waits for all outstanding commands to complete
  2754. * @ha: Pointer to host adapter structure.
  2755. *
  2756. * This routine stalls the driver until all outstanding commands are returned.
  2757. * Caller must release the Hardware Lock prior to calling this routine.
  2758. **/
  2759. static int qla4xxx_cmd_wait(struct scsi_qla_host *ha)
  2760. {
  2761. uint32_t index = 0;
  2762. unsigned long flags;
  2763. struct scsi_cmnd *cmd;
  2764. unsigned long wtime = jiffies + (WAIT_CMD_TOV * HZ);
  2765. DEBUG2(ql4_printk(KERN_INFO, ha, "Wait up to %d seconds for cmds to "
  2766. "complete\n", WAIT_CMD_TOV));
  2767. while (!time_after_eq(jiffies, wtime)) {
  2768. spin_lock_irqsave(&ha->hardware_lock, flags);
  2769. /* Find a command that hasn't completed. */
  2770. for (index = 0; index < ha->host->can_queue; index++) {
  2771. cmd = scsi_host_find_tag(ha->host, index);
  2772. /*
  2773. * We cannot just check if the index is valid,
  2774. * becase if we are run from the scsi eh, then
  2775. * the scsi/block layer is going to prevent
  2776. * the tag from being released.
  2777. */
  2778. if (cmd != NULL && CMD_SP(cmd))
  2779. break;
  2780. }
  2781. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  2782. /* If No Commands are pending, wait is complete */
  2783. if (index == ha->host->can_queue)
  2784. return QLA_SUCCESS;
  2785. msleep(1000);
  2786. }
  2787. /* If we timed out on waiting for commands to come back
  2788. * return ERROR. */
  2789. return QLA_ERROR;
  2790. }
  2791. int qla4xxx_hw_reset(struct scsi_qla_host *ha)
  2792. {
  2793. uint32_t ctrl_status;
  2794. unsigned long flags = 0;
  2795. DEBUG2(printk(KERN_ERR "scsi%ld: %s\n", ha->host_no, __func__));
  2796. if (ql4xxx_lock_drvr_wait(ha) != QLA_SUCCESS)
  2797. return QLA_ERROR;
  2798. spin_lock_irqsave(&ha->hardware_lock, flags);
  2799. /*
  2800. * If the SCSI Reset Interrupt bit is set, clear it.
  2801. * Otherwise, the Soft Reset won't work.
  2802. */
  2803. ctrl_status = readw(&ha->reg->ctrl_status);
  2804. if ((ctrl_status & CSR_SCSI_RESET_INTR) != 0)
  2805. writel(set_rmask(CSR_SCSI_RESET_INTR), &ha->reg->ctrl_status);
  2806. /* Issue Soft Reset */
  2807. writel(set_rmask(CSR_SOFT_RESET), &ha->reg->ctrl_status);
  2808. readl(&ha->reg->ctrl_status);
  2809. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  2810. return QLA_SUCCESS;
  2811. }
  2812. /**
  2813. * qla4xxx_soft_reset - performs soft reset.
  2814. * @ha: Pointer to host adapter structure.
  2815. **/
  2816. int qla4xxx_soft_reset(struct scsi_qla_host *ha)
  2817. {
  2818. uint32_t max_wait_time;
  2819. unsigned long flags = 0;
  2820. int status;
  2821. uint32_t ctrl_status;
  2822. status = qla4xxx_hw_reset(ha);
  2823. if (status != QLA_SUCCESS)
  2824. return status;
  2825. status = QLA_ERROR;
  2826. /* Wait until the Network Reset Intr bit is cleared */
  2827. max_wait_time = RESET_INTR_TOV;
  2828. do {
  2829. spin_lock_irqsave(&ha->hardware_lock, flags);
  2830. ctrl_status = readw(&ha->reg->ctrl_status);
  2831. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  2832. if ((ctrl_status & CSR_NET_RESET_INTR) == 0)
  2833. break;
  2834. msleep(1000);
  2835. } while ((--max_wait_time));
  2836. if ((ctrl_status & CSR_NET_RESET_INTR) != 0) {
  2837. DEBUG2(printk(KERN_WARNING
  2838. "scsi%ld: Network Reset Intr not cleared by "
  2839. "Network function, clearing it now!\n",
  2840. ha->host_no));
  2841. spin_lock_irqsave(&ha->hardware_lock, flags);
  2842. writel(set_rmask(CSR_NET_RESET_INTR), &ha->reg->ctrl_status);
  2843. readl(&ha->reg->ctrl_status);
  2844. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  2845. }
  2846. /* Wait until the firmware tells us the Soft Reset is done */
  2847. max_wait_time = SOFT_RESET_TOV;
  2848. do {
  2849. spin_lock_irqsave(&ha->hardware_lock, flags);
  2850. ctrl_status = readw(&ha->reg->ctrl_status);
  2851. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  2852. if ((ctrl_status & CSR_SOFT_RESET) == 0) {
  2853. status = QLA_SUCCESS;
  2854. break;
  2855. }
  2856. msleep(1000);
  2857. } while ((--max_wait_time));
  2858. /*
  2859. * Also, make sure that the SCSI Reset Interrupt bit has been cleared
  2860. * after the soft reset has taken place.
  2861. */
  2862. spin_lock_irqsave(&ha->hardware_lock, flags);
  2863. ctrl_status = readw(&ha->reg->ctrl_status);
  2864. if ((ctrl_status & CSR_SCSI_RESET_INTR) != 0) {
  2865. writel(set_rmask(CSR_SCSI_RESET_INTR), &ha->reg->ctrl_status);
  2866. readl(&ha->reg->ctrl_status);
  2867. }
  2868. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  2869. /* If soft reset fails then most probably the bios on other
  2870. * function is also enabled.
  2871. * Since the initialization is sequential the other fn
  2872. * wont be able to acknowledge the soft reset.
  2873. * Issue a force soft reset to workaround this scenario.
  2874. */
  2875. if (max_wait_time == 0) {
  2876. /* Issue Force Soft Reset */
  2877. spin_lock_irqsave(&ha->hardware_lock, flags);
  2878. writel(set_rmask(CSR_FORCE_SOFT_RESET), &ha->reg->ctrl_status);
  2879. readl(&ha->reg->ctrl_status);
  2880. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  2881. /* Wait until the firmware tells us the Soft Reset is done */
  2882. max_wait_time = SOFT_RESET_TOV;
  2883. do {
  2884. spin_lock_irqsave(&ha->hardware_lock, flags);
  2885. ctrl_status = readw(&ha->reg->ctrl_status);
  2886. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  2887. if ((ctrl_status & CSR_FORCE_SOFT_RESET) == 0) {
  2888. status = QLA_SUCCESS;
  2889. break;
  2890. }
  2891. msleep(1000);
  2892. } while ((--max_wait_time));
  2893. }
  2894. return status;
  2895. }
  2896. /**
  2897. * qla4xxx_abort_active_cmds - returns all outstanding i/o requests to O.S.
  2898. * @ha: Pointer to host adapter structure.
  2899. * @res: returned scsi status
  2900. *
  2901. * This routine is called just prior to a HARD RESET to return all
  2902. * outstanding commands back to the Operating System.
  2903. * Caller should make sure that the following locks are released
  2904. * before this calling routine: Hardware lock, and io_request_lock.
  2905. **/
  2906. static void qla4xxx_abort_active_cmds(struct scsi_qla_host *ha, int res)
  2907. {
  2908. struct srb *srb;
  2909. int i;
  2910. unsigned long flags;
  2911. spin_lock_irqsave(&ha->hardware_lock, flags);
  2912. for (i = 0; i < ha->host->can_queue; i++) {
  2913. srb = qla4xxx_del_from_active_array(ha, i);
  2914. if (srb != NULL) {
  2915. srb->cmd->result = res;
  2916. kref_put(&srb->srb_ref, qla4xxx_srb_compl);
  2917. }
  2918. }
  2919. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  2920. }
  2921. void qla4xxx_dead_adapter_cleanup(struct scsi_qla_host *ha)
  2922. {
  2923. clear_bit(AF_ONLINE, &ha->flags);
  2924. /* Disable the board */
  2925. ql4_printk(KERN_INFO, ha, "Disabling the board\n");
  2926. qla4xxx_abort_active_cmds(ha, DID_NO_CONNECT << 16);
  2927. qla4xxx_mark_all_devices_missing(ha);
  2928. clear_bit(AF_INIT_DONE, &ha->flags);
  2929. }
  2930. static void qla4xxx_fail_session(struct iscsi_cls_session *cls_session)
  2931. {
  2932. struct iscsi_session *sess;
  2933. struct ddb_entry *ddb_entry;
  2934. sess = cls_session->dd_data;
  2935. ddb_entry = sess->dd_data;
  2936. ddb_entry->fw_ddb_device_state = DDB_DS_SESSION_FAILED;
  2937. if (ddb_entry->ddb_type == FLASH_DDB)
  2938. iscsi_block_session(ddb_entry->sess);
  2939. else
  2940. iscsi_session_failure(cls_session->dd_data,
  2941. ISCSI_ERR_CONN_FAILED);
  2942. }
  2943. /**
  2944. * qla4xxx_recover_adapter - recovers adapter after a fatal error
  2945. * @ha: Pointer to host adapter structure.
  2946. **/
  2947. static int qla4xxx_recover_adapter(struct scsi_qla_host *ha)
  2948. {
  2949. int status = QLA_ERROR;
  2950. uint8_t reset_chip = 0;
  2951. uint32_t dev_state;
  2952. unsigned long wait;
  2953. /* Stall incoming I/O until we are done */
  2954. scsi_block_requests(ha->host);
  2955. clear_bit(AF_ONLINE, &ha->flags);
  2956. clear_bit(AF_LINK_UP, &ha->flags);
  2957. DEBUG2(ql4_printk(KERN_INFO, ha, "%s: adapter OFFLINE\n", __func__));
  2958. set_bit(DPC_RESET_ACTIVE, &ha->dpc_flags);
  2959. if (is_qla8032(ha) &&
  2960. !test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags)) {
  2961. ql4_printk(KERN_INFO, ha, "%s: disabling pause transmit on port 0 & 1.\n",
  2962. __func__);
  2963. /* disable pause frame for ISP83xx */
  2964. qla4_83xx_disable_pause(ha);
  2965. }
  2966. iscsi_host_for_each_session(ha->host, qla4xxx_fail_session);
  2967. if (test_bit(DPC_RESET_HA, &ha->dpc_flags))
  2968. reset_chip = 1;
  2969. /* For the DPC_RESET_HA_INTR case (ISP-4xxx specific)
  2970. * do not reset adapter, jump to initialize_adapter */
  2971. if (test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags)) {
  2972. status = QLA_SUCCESS;
  2973. goto recover_ha_init_adapter;
  2974. }
  2975. /* For the ISP-8xxx adapter, issue a stop_firmware if invoked
  2976. * from eh_host_reset or ioctl module */
  2977. if (is_qla80XX(ha) && !reset_chip &&
  2978. test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags)) {
  2979. DEBUG2(ql4_printk(KERN_INFO, ha,
  2980. "scsi%ld: %s - Performing stop_firmware...\n",
  2981. ha->host_no, __func__));
  2982. status = ha->isp_ops->reset_firmware(ha);
  2983. if (status == QLA_SUCCESS) {
  2984. if (!test_bit(AF_FW_RECOVERY, &ha->flags))
  2985. qla4xxx_cmd_wait(ha);
  2986. ha->isp_ops->disable_intrs(ha);
  2987. qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
  2988. qla4xxx_abort_active_cmds(ha, DID_RESET << 16);
  2989. } else {
  2990. /* If the stop_firmware fails then
  2991. * reset the entire chip */
  2992. reset_chip = 1;
  2993. clear_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags);
  2994. set_bit(DPC_RESET_HA, &ha->dpc_flags);
  2995. }
  2996. }
  2997. /* Issue full chip reset if recovering from a catastrophic error,
  2998. * or if stop_firmware fails for ISP-8xxx.
  2999. * This is the default case for ISP-4xxx */
  3000. if (is_qla40XX(ha) || reset_chip) {
  3001. if (is_qla40XX(ha))
  3002. goto chip_reset;
  3003. /* Check if 8XXX firmware is alive or not
  3004. * We may have arrived here from NEED_RESET
  3005. * detection only */
  3006. if (test_bit(AF_FW_RECOVERY, &ha->flags))
  3007. goto chip_reset;
  3008. wait = jiffies + (FW_ALIVE_WAIT_TOV * HZ);
  3009. while (time_before(jiffies, wait)) {
  3010. if (qla4_8xxx_check_fw_alive(ha)) {
  3011. qla4xxx_mailbox_premature_completion(ha);
  3012. break;
  3013. }
  3014. set_current_state(TASK_UNINTERRUPTIBLE);
  3015. schedule_timeout(HZ);
  3016. }
  3017. chip_reset:
  3018. if (!test_bit(AF_FW_RECOVERY, &ha->flags))
  3019. qla4xxx_cmd_wait(ha);
  3020. qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
  3021. qla4xxx_abort_active_cmds(ha, DID_RESET << 16);
  3022. DEBUG2(ql4_printk(KERN_INFO, ha,
  3023. "scsi%ld: %s - Performing chip reset..\n",
  3024. ha->host_no, __func__));
  3025. status = ha->isp_ops->reset_chip(ha);
  3026. }
  3027. /* Flush any pending ddb changed AENs */
  3028. qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
  3029. recover_ha_init_adapter:
  3030. /* Upon successful firmware/chip reset, re-initialize the adapter */
  3031. if (status == QLA_SUCCESS) {
  3032. /* For ISP-4xxx, force function 1 to always initialize
  3033. * before function 3 to prevent both funcions from
  3034. * stepping on top of the other */
  3035. if (is_qla40XX(ha) && (ha->mac_index == 3))
  3036. ssleep(6);
  3037. /* NOTE: AF_ONLINE flag set upon successful completion of
  3038. * qla4xxx_initialize_adapter */
  3039. status = qla4xxx_initialize_adapter(ha, RESET_ADAPTER);
  3040. }
  3041. /* Retry failed adapter initialization, if necessary
  3042. * Do not retry initialize_adapter for RESET_HA_INTR (ISP-4xxx specific)
  3043. * case to prevent ping-pong resets between functions */
  3044. if (!test_bit(AF_ONLINE, &ha->flags) &&
  3045. !test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags)) {
  3046. /* Adapter initialization failed, see if we can retry
  3047. * resetting the ha.
  3048. * Since we don't want to block the DPC for too long
  3049. * with multiple resets in the same thread,
  3050. * utilize DPC to retry */
  3051. if (is_qla80XX(ha)) {
  3052. ha->isp_ops->idc_lock(ha);
  3053. dev_state = qla4_8xxx_rd_direct(ha,
  3054. QLA8XXX_CRB_DEV_STATE);
  3055. ha->isp_ops->idc_unlock(ha);
  3056. if (dev_state == QLA8XXX_DEV_FAILED) {
  3057. ql4_printk(KERN_INFO, ha, "%s: don't retry "
  3058. "recover adapter. H/W is in Failed "
  3059. "state\n", __func__);
  3060. qla4xxx_dead_adapter_cleanup(ha);
  3061. clear_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags);
  3062. clear_bit(DPC_RESET_HA, &ha->dpc_flags);
  3063. clear_bit(DPC_RESET_HA_FW_CONTEXT,
  3064. &ha->dpc_flags);
  3065. status = QLA_ERROR;
  3066. goto exit_recover;
  3067. }
  3068. }
  3069. if (!test_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags)) {
  3070. ha->retry_reset_ha_cnt = MAX_RESET_HA_RETRIES;
  3071. DEBUG2(printk("scsi%ld: recover adapter - retrying "
  3072. "(%d) more times\n", ha->host_no,
  3073. ha->retry_reset_ha_cnt));
  3074. set_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags);
  3075. status = QLA_ERROR;
  3076. } else {
  3077. if (ha->retry_reset_ha_cnt > 0) {
  3078. /* Schedule another Reset HA--DPC will retry */
  3079. ha->retry_reset_ha_cnt--;
  3080. DEBUG2(printk("scsi%ld: recover adapter - "
  3081. "retry remaining %d\n",
  3082. ha->host_no,
  3083. ha->retry_reset_ha_cnt));
  3084. status = QLA_ERROR;
  3085. }
  3086. if (ha->retry_reset_ha_cnt == 0) {
  3087. /* Recover adapter retries have been exhausted.
  3088. * Adapter DEAD */
  3089. DEBUG2(printk("scsi%ld: recover adapter "
  3090. "failed - board disabled\n",
  3091. ha->host_no));
  3092. qla4xxx_dead_adapter_cleanup(ha);
  3093. clear_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags);
  3094. clear_bit(DPC_RESET_HA, &ha->dpc_flags);
  3095. clear_bit(DPC_RESET_HA_FW_CONTEXT,
  3096. &ha->dpc_flags);
  3097. status = QLA_ERROR;
  3098. }
  3099. }
  3100. } else {
  3101. clear_bit(DPC_RESET_HA, &ha->dpc_flags);
  3102. clear_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags);
  3103. clear_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags);
  3104. }
  3105. exit_recover:
  3106. ha->adapter_error_count++;
  3107. if (test_bit(AF_ONLINE, &ha->flags))
  3108. ha->isp_ops->enable_intrs(ha);
  3109. scsi_unblock_requests(ha->host);
  3110. clear_bit(DPC_RESET_ACTIVE, &ha->dpc_flags);
  3111. DEBUG2(printk("scsi%ld: recover adapter: %s\n", ha->host_no,
  3112. status == QLA_ERROR ? "FAILED" : "SUCCEEDED"));
  3113. return status;
  3114. }
  3115. static void qla4xxx_relogin_devices(struct iscsi_cls_session *cls_session)
  3116. {
  3117. struct iscsi_session *sess;
  3118. struct ddb_entry *ddb_entry;
  3119. struct scsi_qla_host *ha;
  3120. sess = cls_session->dd_data;
  3121. ddb_entry = sess->dd_data;
  3122. ha = ddb_entry->ha;
  3123. if (!iscsi_is_session_online(cls_session)) {
  3124. if (ddb_entry->fw_ddb_device_state == DDB_DS_SESSION_ACTIVE) {
  3125. ql4_printk(KERN_INFO, ha, "scsi%ld: %s: ddb[%d]"
  3126. " unblock session\n", ha->host_no, __func__,
  3127. ddb_entry->fw_ddb_index);
  3128. iscsi_unblock_session(ddb_entry->sess);
  3129. } else {
  3130. /* Trigger relogin */
  3131. if (ddb_entry->ddb_type == FLASH_DDB) {
  3132. if (!(test_bit(DF_RELOGIN, &ddb_entry->flags) ||
  3133. test_bit(DF_DISABLE_RELOGIN,
  3134. &ddb_entry->flags)))
  3135. qla4xxx_arm_relogin_timer(ddb_entry);
  3136. } else
  3137. iscsi_session_failure(cls_session->dd_data,
  3138. ISCSI_ERR_CONN_FAILED);
  3139. }
  3140. }
  3141. }
  3142. int qla4xxx_unblock_flash_ddb(struct iscsi_cls_session *cls_session)
  3143. {
  3144. struct iscsi_session *sess;
  3145. struct ddb_entry *ddb_entry;
  3146. struct scsi_qla_host *ha;
  3147. sess = cls_session->dd_data;
  3148. ddb_entry = sess->dd_data;
  3149. ha = ddb_entry->ha;
  3150. ql4_printk(KERN_INFO, ha, "scsi%ld: %s: ddb[%d]"
  3151. " unblock session\n", ha->host_no, __func__,
  3152. ddb_entry->fw_ddb_index);
  3153. iscsi_unblock_session(ddb_entry->sess);
  3154. /* Start scan target */
  3155. if (test_bit(AF_ONLINE, &ha->flags)) {
  3156. ql4_printk(KERN_INFO, ha, "scsi%ld: %s: ddb[%d]"
  3157. " start scan\n", ha->host_no, __func__,
  3158. ddb_entry->fw_ddb_index);
  3159. scsi_queue_work(ha->host, &ddb_entry->sess->scan_work);
  3160. }
  3161. return QLA_SUCCESS;
  3162. }
  3163. int qla4xxx_unblock_ddb(struct iscsi_cls_session *cls_session)
  3164. {
  3165. struct iscsi_session *sess;
  3166. struct ddb_entry *ddb_entry;
  3167. struct scsi_qla_host *ha;
  3168. int status = QLA_SUCCESS;
  3169. sess = cls_session->dd_data;
  3170. ddb_entry = sess->dd_data;
  3171. ha = ddb_entry->ha;
  3172. ql4_printk(KERN_INFO, ha, "scsi%ld: %s: ddb[%d]"
  3173. " unblock user space session\n", ha->host_no, __func__,
  3174. ddb_entry->fw_ddb_index);
  3175. if (!iscsi_is_session_online(cls_session)) {
  3176. iscsi_conn_start(ddb_entry->conn);
  3177. iscsi_conn_login_event(ddb_entry->conn,
  3178. ISCSI_CONN_STATE_LOGGED_IN);
  3179. } else {
  3180. ql4_printk(KERN_INFO, ha,
  3181. "scsi%ld: %s: ddb[%d] session [%d] already logged in\n",
  3182. ha->host_no, __func__, ddb_entry->fw_ddb_index,
  3183. cls_session->sid);
  3184. status = QLA_ERROR;
  3185. }
  3186. return status;
  3187. }
  3188. static void qla4xxx_relogin_all_devices(struct scsi_qla_host *ha)
  3189. {
  3190. iscsi_host_for_each_session(ha->host, qla4xxx_relogin_devices);
  3191. }
  3192. static void qla4xxx_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
  3193. {
  3194. uint16_t relogin_timer;
  3195. struct iscsi_session *sess;
  3196. struct ddb_entry *ddb_entry;
  3197. struct scsi_qla_host *ha;
  3198. sess = cls_sess->dd_data;
  3199. ddb_entry = sess->dd_data;
  3200. ha = ddb_entry->ha;
  3201. relogin_timer = max(ddb_entry->default_relogin_timeout,
  3202. (uint16_t)RELOGIN_TOV);
  3203. atomic_set(&ddb_entry->relogin_timer, relogin_timer);
  3204. DEBUG2(ql4_printk(KERN_INFO, ha,
  3205. "scsi%ld: Relogin index [%d]. TOV=%d\n", ha->host_no,
  3206. ddb_entry->fw_ddb_index, relogin_timer));
  3207. qla4xxx_login_flash_ddb(cls_sess);
  3208. }
  3209. static void qla4xxx_dpc_relogin(struct iscsi_cls_session *cls_sess)
  3210. {
  3211. struct iscsi_session *sess;
  3212. struct ddb_entry *ddb_entry;
  3213. struct scsi_qla_host *ha;
  3214. sess = cls_sess->dd_data;
  3215. ddb_entry = sess->dd_data;
  3216. ha = ddb_entry->ha;
  3217. if (!(ddb_entry->ddb_type == FLASH_DDB))
  3218. return;
  3219. if (test_bit(DF_DISABLE_RELOGIN, &ddb_entry->flags))
  3220. return;
  3221. if (test_and_clear_bit(DF_RELOGIN, &ddb_entry->flags) &&
  3222. !iscsi_is_session_online(cls_sess)) {
  3223. DEBUG2(ql4_printk(KERN_INFO, ha,
  3224. "relogin issued\n"));
  3225. qla4xxx_relogin_flash_ddb(cls_sess);
  3226. }
  3227. }
  3228. void qla4xxx_wake_dpc(struct scsi_qla_host *ha)
  3229. {
  3230. if (ha->dpc_thread)
  3231. queue_work(ha->dpc_thread, &ha->dpc_work);
  3232. }
  3233. static struct qla4_work_evt *
  3234. qla4xxx_alloc_work(struct scsi_qla_host *ha, uint32_t data_size,
  3235. enum qla4_work_type type)
  3236. {
  3237. struct qla4_work_evt *e;
  3238. uint32_t size = sizeof(struct qla4_work_evt) + data_size;
  3239. e = kzalloc(size, GFP_ATOMIC);
  3240. if (!e)
  3241. return NULL;
  3242. INIT_LIST_HEAD(&e->list);
  3243. e->type = type;
  3244. return e;
  3245. }
  3246. static void qla4xxx_post_work(struct scsi_qla_host *ha,
  3247. struct qla4_work_evt *e)
  3248. {
  3249. unsigned long flags;
  3250. spin_lock_irqsave(&ha->work_lock, flags);
  3251. list_add_tail(&e->list, &ha->work_list);
  3252. spin_unlock_irqrestore(&ha->work_lock, flags);
  3253. qla4xxx_wake_dpc(ha);
  3254. }
  3255. int qla4xxx_post_aen_work(struct scsi_qla_host *ha,
  3256. enum iscsi_host_event_code aen_code,
  3257. uint32_t data_size, uint8_t *data)
  3258. {
  3259. struct qla4_work_evt *e;
  3260. e = qla4xxx_alloc_work(ha, data_size, QLA4_EVENT_AEN);
  3261. if (!e)
  3262. return QLA_ERROR;
  3263. e->u.aen.code = aen_code;
  3264. e->u.aen.data_size = data_size;
  3265. memcpy(e->u.aen.data, data, data_size);
  3266. qla4xxx_post_work(ha, e);
  3267. return QLA_SUCCESS;
  3268. }
  3269. int qla4xxx_post_ping_evt_work(struct scsi_qla_host *ha,
  3270. uint32_t status, uint32_t pid,
  3271. uint32_t data_size, uint8_t *data)
  3272. {
  3273. struct qla4_work_evt *e;
  3274. e = qla4xxx_alloc_work(ha, data_size, QLA4_EVENT_PING_STATUS);
  3275. if (!e)
  3276. return QLA_ERROR;
  3277. e->u.ping.status = status;
  3278. e->u.ping.pid = pid;
  3279. e->u.ping.data_size = data_size;
  3280. memcpy(e->u.ping.data, data, data_size);
  3281. qla4xxx_post_work(ha, e);
  3282. return QLA_SUCCESS;
  3283. }
  3284. static void qla4xxx_do_work(struct scsi_qla_host *ha)
  3285. {
  3286. struct qla4_work_evt *e, *tmp;
  3287. unsigned long flags;
  3288. LIST_HEAD(work);
  3289. spin_lock_irqsave(&ha->work_lock, flags);
  3290. list_splice_init(&ha->work_list, &work);
  3291. spin_unlock_irqrestore(&ha->work_lock, flags);
  3292. list_for_each_entry_safe(e, tmp, &work, list) {
  3293. list_del_init(&e->list);
  3294. switch (e->type) {
  3295. case QLA4_EVENT_AEN:
  3296. iscsi_post_host_event(ha->host_no,
  3297. &qla4xxx_iscsi_transport,
  3298. e->u.aen.code,
  3299. e->u.aen.data_size,
  3300. e->u.aen.data);
  3301. break;
  3302. case QLA4_EVENT_PING_STATUS:
  3303. iscsi_ping_comp_event(ha->host_no,
  3304. &qla4xxx_iscsi_transport,
  3305. e->u.ping.status,
  3306. e->u.ping.pid,
  3307. e->u.ping.data_size,
  3308. e->u.ping.data);
  3309. break;
  3310. default:
  3311. ql4_printk(KERN_WARNING, ha, "event type: 0x%x not "
  3312. "supported", e->type);
  3313. }
  3314. kfree(e);
  3315. }
  3316. }
  3317. /**
  3318. * qla4xxx_do_dpc - dpc routine
  3319. * @data: in our case pointer to adapter structure
  3320. *
  3321. * This routine is a task that is schedule by the interrupt handler
  3322. * to perform the background processing for interrupts. We put it
  3323. * on a task queue that is consumed whenever the scheduler runs; that's
  3324. * so you can do anything (i.e. put the process to sleep etc). In fact,
  3325. * the mid-level tries to sleep when it reaches the driver threshold
  3326. * "host->can_queue". This can cause a panic if we were in our interrupt code.
  3327. **/
  3328. static void qla4xxx_do_dpc(struct work_struct *work)
  3329. {
  3330. struct scsi_qla_host *ha =
  3331. container_of(work, struct scsi_qla_host, dpc_work);
  3332. int status = QLA_ERROR;
  3333. DEBUG2(printk("scsi%ld: %s: DPC handler waking up."
  3334. "flags = 0x%08lx, dpc_flags = 0x%08lx\n",
  3335. ha->host_no, __func__, ha->flags, ha->dpc_flags))
  3336. /* Initialization not yet finished. Don't do anything yet. */
  3337. if (!test_bit(AF_INIT_DONE, &ha->flags))
  3338. return;
  3339. if (test_bit(AF_EEH_BUSY, &ha->flags)) {
  3340. DEBUG2(printk(KERN_INFO "scsi%ld: %s: flags = %lx\n",
  3341. ha->host_no, __func__, ha->flags));
  3342. return;
  3343. }
  3344. /* post events to application */
  3345. qla4xxx_do_work(ha);
  3346. if (is_qla80XX(ha)) {
  3347. if (test_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags)) {
  3348. if (is_qla8032(ha)) {
  3349. ql4_printk(KERN_INFO, ha, "%s: disabling pause transmit on port 0 & 1.\n",
  3350. __func__);
  3351. /* disable pause frame for ISP83xx */
  3352. qla4_83xx_disable_pause(ha);
  3353. }
  3354. ha->isp_ops->idc_lock(ha);
  3355. qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DEV_STATE,
  3356. QLA8XXX_DEV_FAILED);
  3357. ha->isp_ops->idc_unlock(ha);
  3358. ql4_printk(KERN_INFO, ha, "HW State: FAILED\n");
  3359. qla4_8xxx_device_state_handler(ha);
  3360. }
  3361. if (test_and_clear_bit(DPC_POST_IDC_ACK, &ha->dpc_flags))
  3362. qla4_83xx_post_idc_ack(ha);
  3363. if (test_and_clear_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags)) {
  3364. qla4_8xxx_need_qsnt_handler(ha);
  3365. }
  3366. }
  3367. if (!test_bit(DPC_RESET_ACTIVE, &ha->dpc_flags) &&
  3368. (test_bit(DPC_RESET_HA, &ha->dpc_flags) ||
  3369. test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags) ||
  3370. test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags))) {
  3371. if ((is_qla8022(ha) && ql4xdontresethba) ||
  3372. (is_qla8032(ha) && qla4_83xx_idc_dontreset(ha))) {
  3373. DEBUG2(printk("scsi%ld: %s: Don't Reset HBA\n",
  3374. ha->host_no, __func__));
  3375. clear_bit(DPC_RESET_HA, &ha->dpc_flags);
  3376. clear_bit(DPC_RESET_HA_INTR, &ha->dpc_flags);
  3377. clear_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags);
  3378. goto dpc_post_reset_ha;
  3379. }
  3380. if (test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags) ||
  3381. test_bit(DPC_RESET_HA, &ha->dpc_flags))
  3382. qla4xxx_recover_adapter(ha);
  3383. if (test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags)) {
  3384. uint8_t wait_time = RESET_INTR_TOV;
  3385. while ((readw(&ha->reg->ctrl_status) &
  3386. (CSR_SOFT_RESET | CSR_FORCE_SOFT_RESET)) != 0) {
  3387. if (--wait_time == 0)
  3388. break;
  3389. msleep(1000);
  3390. }
  3391. if (wait_time == 0)
  3392. DEBUG2(printk("scsi%ld: %s: SR|FSR "
  3393. "bit not cleared-- resetting\n",
  3394. ha->host_no, __func__));
  3395. qla4xxx_abort_active_cmds(ha, DID_RESET << 16);
  3396. if (ql4xxx_lock_drvr_wait(ha) == QLA_SUCCESS) {
  3397. qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
  3398. status = qla4xxx_recover_adapter(ha);
  3399. }
  3400. clear_bit(DPC_RESET_HA_INTR, &ha->dpc_flags);
  3401. if (status == QLA_SUCCESS)
  3402. ha->isp_ops->enable_intrs(ha);
  3403. }
  3404. }
  3405. dpc_post_reset_ha:
  3406. /* ---- process AEN? --- */
  3407. if (test_and_clear_bit(DPC_AEN, &ha->dpc_flags))
  3408. qla4xxx_process_aen(ha, PROCESS_ALL_AENS);
  3409. /* ---- Get DHCP IP Address? --- */
  3410. if (test_and_clear_bit(DPC_GET_DHCP_IP_ADDR, &ha->dpc_flags))
  3411. qla4xxx_get_dhcp_ip_address(ha);
  3412. /* ---- relogin device? --- */
  3413. if (adapter_up(ha) &&
  3414. test_and_clear_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags)) {
  3415. iscsi_host_for_each_session(ha->host, qla4xxx_dpc_relogin);
  3416. }
  3417. /* ---- link change? --- */
  3418. if (!test_bit(AF_LOOPBACK, &ha->flags) &&
  3419. test_and_clear_bit(DPC_LINK_CHANGED, &ha->dpc_flags)) {
  3420. if (!test_bit(AF_LINK_UP, &ha->flags)) {
  3421. /* ---- link down? --- */
  3422. qla4xxx_mark_all_devices_missing(ha);
  3423. } else {
  3424. /* ---- link up? --- *
  3425. * F/W will auto login to all devices ONLY ONCE after
  3426. * link up during driver initialization and runtime
  3427. * fatal error recovery. Therefore, the driver must
  3428. * manually relogin to devices when recovering from
  3429. * connection failures, logouts, expired KATO, etc. */
  3430. if (test_and_clear_bit(AF_BUILD_DDB_LIST, &ha->flags)) {
  3431. qla4xxx_build_ddb_list(ha, ha->is_reset);
  3432. iscsi_host_for_each_session(ha->host,
  3433. qla4xxx_login_flash_ddb);
  3434. } else
  3435. qla4xxx_relogin_all_devices(ha);
  3436. }
  3437. }
  3438. }
  3439. /**
  3440. * qla4xxx_free_adapter - release the adapter
  3441. * @ha: pointer to adapter structure
  3442. **/
  3443. static void qla4xxx_free_adapter(struct scsi_qla_host *ha)
  3444. {
  3445. qla4xxx_abort_active_cmds(ha, DID_NO_CONNECT << 16);
  3446. /* Turn-off interrupts on the card. */
  3447. ha->isp_ops->disable_intrs(ha);
  3448. if (is_qla40XX(ha)) {
  3449. writel(set_rmask(CSR_SCSI_PROCESSOR_INTR),
  3450. &ha->reg->ctrl_status);
  3451. readl(&ha->reg->ctrl_status);
  3452. } else if (is_qla8022(ha)) {
  3453. writel(0, &ha->qla4_82xx_reg->host_int);
  3454. readl(&ha->qla4_82xx_reg->host_int);
  3455. } else if (is_qla8032(ha)) {
  3456. writel(0, &ha->qla4_83xx_reg->risc_intr);
  3457. readl(&ha->qla4_83xx_reg->risc_intr);
  3458. }
  3459. /* Remove timer thread, if present */
  3460. if (ha->timer_active)
  3461. qla4xxx_stop_timer(ha);
  3462. /* Kill the kernel thread for this host */
  3463. if (ha->dpc_thread)
  3464. destroy_workqueue(ha->dpc_thread);
  3465. /* Kill the kernel thread for this host */
  3466. if (ha->task_wq)
  3467. destroy_workqueue(ha->task_wq);
  3468. /* Put firmware in known state */
  3469. ha->isp_ops->reset_firmware(ha);
  3470. if (is_qla80XX(ha)) {
  3471. ha->isp_ops->idc_lock(ha);
  3472. qla4_8xxx_clear_drv_active(ha);
  3473. ha->isp_ops->idc_unlock(ha);
  3474. }
  3475. /* Detach interrupts */
  3476. qla4xxx_free_irqs(ha);
  3477. /* free extra memory */
  3478. qla4xxx_mem_free(ha);
  3479. }
  3480. int qla4_8xxx_iospace_config(struct scsi_qla_host *ha)
  3481. {
  3482. int status = 0;
  3483. unsigned long mem_base, mem_len, db_base, db_len;
  3484. struct pci_dev *pdev = ha->pdev;
  3485. status = pci_request_regions(pdev, DRIVER_NAME);
  3486. if (status) {
  3487. printk(KERN_WARNING
  3488. "scsi(%ld) Failed to reserve PIO regions (%s) "
  3489. "status=%d\n", ha->host_no, pci_name(pdev), status);
  3490. goto iospace_error_exit;
  3491. }
  3492. DEBUG2(printk(KERN_INFO "%s: revision-id=%d\n",
  3493. __func__, pdev->revision));
  3494. ha->revision_id = pdev->revision;
  3495. /* remap phys address */
  3496. mem_base = pci_resource_start(pdev, 0); /* 0 is for BAR 0 */
  3497. mem_len = pci_resource_len(pdev, 0);
  3498. DEBUG2(printk(KERN_INFO "%s: ioremap from %lx a size of %lx\n",
  3499. __func__, mem_base, mem_len));
  3500. /* mapping of pcibase pointer */
  3501. ha->nx_pcibase = (unsigned long)ioremap(mem_base, mem_len);
  3502. if (!ha->nx_pcibase) {
  3503. printk(KERN_ERR
  3504. "cannot remap MMIO (%s), aborting\n", pci_name(pdev));
  3505. pci_release_regions(ha->pdev);
  3506. goto iospace_error_exit;
  3507. }
  3508. /* Mapping of IO base pointer, door bell read and write pointer */
  3509. /* mapping of IO base pointer */
  3510. if (is_qla8022(ha)) {
  3511. ha->qla4_82xx_reg = (struct device_reg_82xx __iomem *)
  3512. ((uint8_t *)ha->nx_pcibase + 0xbc000 +
  3513. (ha->pdev->devfn << 11));
  3514. ha->nx_db_wr_ptr = (ha->pdev->devfn == 4 ? QLA82XX_CAM_RAM_DB1 :
  3515. QLA82XX_CAM_RAM_DB2);
  3516. } else if (is_qla8032(ha)) {
  3517. ha->qla4_83xx_reg = (struct device_reg_83xx __iomem *)
  3518. ((uint8_t *)ha->nx_pcibase);
  3519. }
  3520. db_base = pci_resource_start(pdev, 4); /* doorbell is on bar 4 */
  3521. db_len = pci_resource_len(pdev, 4);
  3522. return 0;
  3523. iospace_error_exit:
  3524. return -ENOMEM;
  3525. }
  3526. /***
  3527. * qla4xxx_iospace_config - maps registers
  3528. * @ha: pointer to adapter structure
  3529. *
  3530. * This routines maps HBA's registers from the pci address space
  3531. * into the kernel virtual address space for memory mapped i/o.
  3532. **/
  3533. int qla4xxx_iospace_config(struct scsi_qla_host *ha)
  3534. {
  3535. unsigned long pio, pio_len, pio_flags;
  3536. unsigned long mmio, mmio_len, mmio_flags;
  3537. pio = pci_resource_start(ha->pdev, 0);
  3538. pio_len = pci_resource_len(ha->pdev, 0);
  3539. pio_flags = pci_resource_flags(ha->pdev, 0);
  3540. if (pio_flags & IORESOURCE_IO) {
  3541. if (pio_len < MIN_IOBASE_LEN) {
  3542. ql4_printk(KERN_WARNING, ha,
  3543. "Invalid PCI I/O region size\n");
  3544. pio = 0;
  3545. }
  3546. } else {
  3547. ql4_printk(KERN_WARNING, ha, "region #0 not a PIO resource\n");
  3548. pio = 0;
  3549. }
  3550. /* Use MMIO operations for all accesses. */
  3551. mmio = pci_resource_start(ha->pdev, 1);
  3552. mmio_len = pci_resource_len(ha->pdev, 1);
  3553. mmio_flags = pci_resource_flags(ha->pdev, 1);
  3554. if (!(mmio_flags & IORESOURCE_MEM)) {
  3555. ql4_printk(KERN_ERR, ha,
  3556. "region #0 not an MMIO resource, aborting\n");
  3557. goto iospace_error_exit;
  3558. }
  3559. if (mmio_len < MIN_IOBASE_LEN) {
  3560. ql4_printk(KERN_ERR, ha,
  3561. "Invalid PCI mem region size, aborting\n");
  3562. goto iospace_error_exit;
  3563. }
  3564. if (pci_request_regions(ha->pdev, DRIVER_NAME)) {
  3565. ql4_printk(KERN_WARNING, ha,
  3566. "Failed to reserve PIO/MMIO regions\n");
  3567. goto iospace_error_exit;
  3568. }
  3569. ha->pio_address = pio;
  3570. ha->pio_length = pio_len;
  3571. ha->reg = ioremap(mmio, MIN_IOBASE_LEN);
  3572. if (!ha->reg) {
  3573. ql4_printk(KERN_ERR, ha,
  3574. "cannot remap MMIO, aborting\n");
  3575. goto iospace_error_exit;
  3576. }
  3577. return 0;
  3578. iospace_error_exit:
  3579. return -ENOMEM;
  3580. }
  3581. static struct isp_operations qla4xxx_isp_ops = {
  3582. .iospace_config = qla4xxx_iospace_config,
  3583. .pci_config = qla4xxx_pci_config,
  3584. .disable_intrs = qla4xxx_disable_intrs,
  3585. .enable_intrs = qla4xxx_enable_intrs,
  3586. .start_firmware = qla4xxx_start_firmware,
  3587. .intr_handler = qla4xxx_intr_handler,
  3588. .interrupt_service_routine = qla4xxx_interrupt_service_routine,
  3589. .reset_chip = qla4xxx_soft_reset,
  3590. .reset_firmware = qla4xxx_hw_reset,
  3591. .queue_iocb = qla4xxx_queue_iocb,
  3592. .complete_iocb = qla4xxx_complete_iocb,
  3593. .rd_shdw_req_q_out = qla4xxx_rd_shdw_req_q_out,
  3594. .rd_shdw_rsp_q_in = qla4xxx_rd_shdw_rsp_q_in,
  3595. .get_sys_info = qla4xxx_get_sys_info,
  3596. .queue_mailbox_command = qla4xxx_queue_mbox_cmd,
  3597. .process_mailbox_interrupt = qla4xxx_process_mbox_intr,
  3598. };
  3599. static struct isp_operations qla4_82xx_isp_ops = {
  3600. .iospace_config = qla4_8xxx_iospace_config,
  3601. .pci_config = qla4_8xxx_pci_config,
  3602. .disable_intrs = qla4_82xx_disable_intrs,
  3603. .enable_intrs = qla4_82xx_enable_intrs,
  3604. .start_firmware = qla4_8xxx_load_risc,
  3605. .restart_firmware = qla4_82xx_try_start_fw,
  3606. .intr_handler = qla4_82xx_intr_handler,
  3607. .interrupt_service_routine = qla4_82xx_interrupt_service_routine,
  3608. .need_reset = qla4_8xxx_need_reset,
  3609. .reset_chip = qla4_82xx_isp_reset,
  3610. .reset_firmware = qla4_8xxx_stop_firmware,
  3611. .queue_iocb = qla4_82xx_queue_iocb,
  3612. .complete_iocb = qla4_82xx_complete_iocb,
  3613. .rd_shdw_req_q_out = qla4_82xx_rd_shdw_req_q_out,
  3614. .rd_shdw_rsp_q_in = qla4_82xx_rd_shdw_rsp_q_in,
  3615. .get_sys_info = qla4_8xxx_get_sys_info,
  3616. .rd_reg_direct = qla4_82xx_rd_32,
  3617. .wr_reg_direct = qla4_82xx_wr_32,
  3618. .rd_reg_indirect = qla4_82xx_md_rd_32,
  3619. .wr_reg_indirect = qla4_82xx_md_wr_32,
  3620. .idc_lock = qla4_82xx_idc_lock,
  3621. .idc_unlock = qla4_82xx_idc_unlock,
  3622. .rom_lock_recovery = qla4_82xx_rom_lock_recovery,
  3623. .queue_mailbox_command = qla4_82xx_queue_mbox_cmd,
  3624. .process_mailbox_interrupt = qla4_82xx_process_mbox_intr,
  3625. };
  3626. static struct isp_operations qla4_83xx_isp_ops = {
  3627. .iospace_config = qla4_8xxx_iospace_config,
  3628. .pci_config = qla4_8xxx_pci_config,
  3629. .disable_intrs = qla4_83xx_disable_intrs,
  3630. .enable_intrs = qla4_83xx_enable_intrs,
  3631. .start_firmware = qla4_8xxx_load_risc,
  3632. .restart_firmware = qla4_83xx_start_firmware,
  3633. .intr_handler = qla4_83xx_intr_handler,
  3634. .interrupt_service_routine = qla4_83xx_interrupt_service_routine,
  3635. .need_reset = qla4_8xxx_need_reset,
  3636. .reset_chip = qla4_83xx_isp_reset,
  3637. .reset_firmware = qla4_8xxx_stop_firmware,
  3638. .queue_iocb = qla4_83xx_queue_iocb,
  3639. .complete_iocb = qla4_83xx_complete_iocb,
  3640. .rd_shdw_req_q_out = qla4xxx_rd_shdw_req_q_out,
  3641. .rd_shdw_rsp_q_in = qla4xxx_rd_shdw_rsp_q_in,
  3642. .get_sys_info = qla4_8xxx_get_sys_info,
  3643. .rd_reg_direct = qla4_83xx_rd_reg,
  3644. .wr_reg_direct = qla4_83xx_wr_reg,
  3645. .rd_reg_indirect = qla4_83xx_rd_reg_indirect,
  3646. .wr_reg_indirect = qla4_83xx_wr_reg_indirect,
  3647. .idc_lock = qla4_83xx_drv_lock,
  3648. .idc_unlock = qla4_83xx_drv_unlock,
  3649. .rom_lock_recovery = qla4_83xx_rom_lock_recovery,
  3650. .queue_mailbox_command = qla4_83xx_queue_mbox_cmd,
  3651. .process_mailbox_interrupt = qla4_83xx_process_mbox_intr,
  3652. };
  3653. uint16_t qla4xxx_rd_shdw_req_q_out(struct scsi_qla_host *ha)
  3654. {
  3655. return (uint16_t)le32_to_cpu(ha->shadow_regs->req_q_out);
  3656. }
  3657. uint16_t qla4_82xx_rd_shdw_req_q_out(struct scsi_qla_host *ha)
  3658. {
  3659. return (uint16_t)le32_to_cpu(readl(&ha->qla4_82xx_reg->req_q_out));
  3660. }
  3661. uint16_t qla4xxx_rd_shdw_rsp_q_in(struct scsi_qla_host *ha)
  3662. {
  3663. return (uint16_t)le32_to_cpu(ha->shadow_regs->rsp_q_in);
  3664. }
  3665. uint16_t qla4_82xx_rd_shdw_rsp_q_in(struct scsi_qla_host *ha)
  3666. {
  3667. return (uint16_t)le32_to_cpu(readl(&ha->qla4_82xx_reg->rsp_q_in));
  3668. }
  3669. static ssize_t qla4xxx_show_boot_eth_info(void *data, int type, char *buf)
  3670. {
  3671. struct scsi_qla_host *ha = data;
  3672. char *str = buf;
  3673. int rc;
  3674. switch (type) {
  3675. case ISCSI_BOOT_ETH_FLAGS:
  3676. rc = sprintf(str, "%d\n", SYSFS_FLAG_FW_SEL_BOOT);
  3677. break;
  3678. case ISCSI_BOOT_ETH_INDEX:
  3679. rc = sprintf(str, "0\n");
  3680. break;
  3681. case ISCSI_BOOT_ETH_MAC:
  3682. rc = sysfs_format_mac(str, ha->my_mac,
  3683. MAC_ADDR_LEN);
  3684. break;
  3685. default:
  3686. rc = -ENOSYS;
  3687. break;
  3688. }
  3689. return rc;
  3690. }
  3691. static umode_t qla4xxx_eth_get_attr_visibility(void *data, int type)
  3692. {
  3693. int rc;
  3694. switch (type) {
  3695. case ISCSI_BOOT_ETH_FLAGS:
  3696. case ISCSI_BOOT_ETH_MAC:
  3697. case ISCSI_BOOT_ETH_INDEX:
  3698. rc = S_IRUGO;
  3699. break;
  3700. default:
  3701. rc = 0;
  3702. break;
  3703. }
  3704. return rc;
  3705. }
  3706. static ssize_t qla4xxx_show_boot_ini_info(void *data, int type, char *buf)
  3707. {
  3708. struct scsi_qla_host *ha = data;
  3709. char *str = buf;
  3710. int rc;
  3711. switch (type) {
  3712. case ISCSI_BOOT_INI_INITIATOR_NAME:
  3713. rc = sprintf(str, "%s\n", ha->name_string);
  3714. break;
  3715. default:
  3716. rc = -ENOSYS;
  3717. break;
  3718. }
  3719. return rc;
  3720. }
  3721. static umode_t qla4xxx_ini_get_attr_visibility(void *data, int type)
  3722. {
  3723. int rc;
  3724. switch (type) {
  3725. case ISCSI_BOOT_INI_INITIATOR_NAME:
  3726. rc = S_IRUGO;
  3727. break;
  3728. default:
  3729. rc = 0;
  3730. break;
  3731. }
  3732. return rc;
  3733. }
  3734. static ssize_t
  3735. qla4xxx_show_boot_tgt_info(struct ql4_boot_session_info *boot_sess, int type,
  3736. char *buf)
  3737. {
  3738. struct ql4_conn_info *boot_conn = &boot_sess->conn_list[0];
  3739. char *str = buf;
  3740. int rc;
  3741. switch (type) {
  3742. case ISCSI_BOOT_TGT_NAME:
  3743. rc = sprintf(buf, "%s\n", (char *)&boot_sess->target_name);
  3744. break;
  3745. case ISCSI_BOOT_TGT_IP_ADDR:
  3746. if (boot_sess->conn_list[0].dest_ipaddr.ip_type == 0x1)
  3747. rc = sprintf(buf, "%pI4\n",
  3748. &boot_conn->dest_ipaddr.ip_address);
  3749. else
  3750. rc = sprintf(str, "%pI6\n",
  3751. &boot_conn->dest_ipaddr.ip_address);
  3752. break;
  3753. case ISCSI_BOOT_TGT_PORT:
  3754. rc = sprintf(str, "%d\n", boot_conn->dest_port);
  3755. break;
  3756. case ISCSI_BOOT_TGT_CHAP_NAME:
  3757. rc = sprintf(str, "%.*s\n",
  3758. boot_conn->chap.target_chap_name_length,
  3759. (char *)&boot_conn->chap.target_chap_name);
  3760. break;
  3761. case ISCSI_BOOT_TGT_CHAP_SECRET:
  3762. rc = sprintf(str, "%.*s\n",
  3763. boot_conn->chap.target_secret_length,
  3764. (char *)&boot_conn->chap.target_secret);
  3765. break;
  3766. case ISCSI_BOOT_TGT_REV_CHAP_NAME:
  3767. rc = sprintf(str, "%.*s\n",
  3768. boot_conn->chap.intr_chap_name_length,
  3769. (char *)&boot_conn->chap.intr_chap_name);
  3770. break;
  3771. case ISCSI_BOOT_TGT_REV_CHAP_SECRET:
  3772. rc = sprintf(str, "%.*s\n",
  3773. boot_conn->chap.intr_secret_length,
  3774. (char *)&boot_conn->chap.intr_secret);
  3775. break;
  3776. case ISCSI_BOOT_TGT_FLAGS:
  3777. rc = sprintf(str, "%d\n", SYSFS_FLAG_FW_SEL_BOOT);
  3778. break;
  3779. case ISCSI_BOOT_TGT_NIC_ASSOC:
  3780. rc = sprintf(str, "0\n");
  3781. break;
  3782. default:
  3783. rc = -ENOSYS;
  3784. break;
  3785. }
  3786. return rc;
  3787. }
  3788. static ssize_t qla4xxx_show_boot_tgt_pri_info(void *data, int type, char *buf)
  3789. {
  3790. struct scsi_qla_host *ha = data;
  3791. struct ql4_boot_session_info *boot_sess = &(ha->boot_tgt.boot_pri_sess);
  3792. return qla4xxx_show_boot_tgt_info(boot_sess, type, buf);
  3793. }
  3794. static ssize_t qla4xxx_show_boot_tgt_sec_info(void *data, int type, char *buf)
  3795. {
  3796. struct scsi_qla_host *ha = data;
  3797. struct ql4_boot_session_info *boot_sess = &(ha->boot_tgt.boot_sec_sess);
  3798. return qla4xxx_show_boot_tgt_info(boot_sess, type, buf);
  3799. }
  3800. static umode_t qla4xxx_tgt_get_attr_visibility(void *data, int type)
  3801. {
  3802. int rc;
  3803. switch (type) {
  3804. case ISCSI_BOOT_TGT_NAME:
  3805. case ISCSI_BOOT_TGT_IP_ADDR:
  3806. case ISCSI_BOOT_TGT_PORT:
  3807. case ISCSI_BOOT_TGT_CHAP_NAME:
  3808. case ISCSI_BOOT_TGT_CHAP_SECRET:
  3809. case ISCSI_BOOT_TGT_REV_CHAP_NAME:
  3810. case ISCSI_BOOT_TGT_REV_CHAP_SECRET:
  3811. case ISCSI_BOOT_TGT_NIC_ASSOC:
  3812. case ISCSI_BOOT_TGT_FLAGS:
  3813. rc = S_IRUGO;
  3814. break;
  3815. default:
  3816. rc = 0;
  3817. break;
  3818. }
  3819. return rc;
  3820. }
  3821. static void qla4xxx_boot_release(void *data)
  3822. {
  3823. struct scsi_qla_host *ha = data;
  3824. scsi_host_put(ha->host);
  3825. }
  3826. static int get_fw_boot_info(struct scsi_qla_host *ha, uint16_t ddb_index[])
  3827. {
  3828. dma_addr_t buf_dma;
  3829. uint32_t addr, pri_addr, sec_addr;
  3830. uint32_t offset;
  3831. uint16_t func_num;
  3832. uint8_t val;
  3833. uint8_t *buf = NULL;
  3834. size_t size = 13 * sizeof(uint8_t);
  3835. int ret = QLA_SUCCESS;
  3836. func_num = PCI_FUNC(ha->pdev->devfn);
  3837. ql4_printk(KERN_INFO, ha, "%s: Get FW boot info for 0x%x func %d\n",
  3838. __func__, ha->pdev->device, func_num);
  3839. if (is_qla40XX(ha)) {
  3840. if (func_num == 1) {
  3841. addr = NVRAM_PORT0_BOOT_MODE;
  3842. pri_addr = NVRAM_PORT0_BOOT_PRI_TGT;
  3843. sec_addr = NVRAM_PORT0_BOOT_SEC_TGT;
  3844. } else if (func_num == 3) {
  3845. addr = NVRAM_PORT1_BOOT_MODE;
  3846. pri_addr = NVRAM_PORT1_BOOT_PRI_TGT;
  3847. sec_addr = NVRAM_PORT1_BOOT_SEC_TGT;
  3848. } else {
  3849. ret = QLA_ERROR;
  3850. goto exit_boot_info;
  3851. }
  3852. /* Check Boot Mode */
  3853. val = rd_nvram_byte(ha, addr);
  3854. if (!(val & 0x07)) {
  3855. DEBUG2(ql4_printk(KERN_INFO, ha, "%s: Adapter boot "
  3856. "options : 0x%x\n", __func__, val));
  3857. ret = QLA_ERROR;
  3858. goto exit_boot_info;
  3859. }
  3860. /* get primary valid target index */
  3861. val = rd_nvram_byte(ha, pri_addr);
  3862. if (val & BIT_7)
  3863. ddb_index[0] = (val & 0x7f);
  3864. /* get secondary valid target index */
  3865. val = rd_nvram_byte(ha, sec_addr);
  3866. if (val & BIT_7)
  3867. ddb_index[1] = (val & 0x7f);
  3868. } else if (is_qla80XX(ha)) {
  3869. buf = dma_alloc_coherent(&ha->pdev->dev, size,
  3870. &buf_dma, GFP_KERNEL);
  3871. if (!buf) {
  3872. DEBUG2(ql4_printk(KERN_ERR, ha,
  3873. "%s: Unable to allocate dma buffer\n",
  3874. __func__));
  3875. ret = QLA_ERROR;
  3876. goto exit_boot_info;
  3877. }
  3878. if (ha->port_num == 0)
  3879. offset = BOOT_PARAM_OFFSET_PORT0;
  3880. else if (ha->port_num == 1)
  3881. offset = BOOT_PARAM_OFFSET_PORT1;
  3882. else {
  3883. ret = QLA_ERROR;
  3884. goto exit_boot_info_free;
  3885. }
  3886. addr = FLASH_RAW_ACCESS_ADDR + (ha->hw.flt_iscsi_param * 4) +
  3887. offset;
  3888. if (qla4xxx_get_flash(ha, buf_dma, addr,
  3889. 13 * sizeof(uint8_t)) != QLA_SUCCESS) {
  3890. DEBUG2(ql4_printk(KERN_ERR, ha, "scsi%ld: %s: Get Flash"
  3891. " failed\n", ha->host_no, __func__));
  3892. ret = QLA_ERROR;
  3893. goto exit_boot_info_free;
  3894. }
  3895. /* Check Boot Mode */
  3896. if (!(buf[1] & 0x07)) {
  3897. DEBUG2(ql4_printk(KERN_INFO, ha, "Firmware boot options"
  3898. " : 0x%x\n", buf[1]));
  3899. ret = QLA_ERROR;
  3900. goto exit_boot_info_free;
  3901. }
  3902. /* get primary valid target index */
  3903. if (buf[2] & BIT_7)
  3904. ddb_index[0] = buf[2] & 0x7f;
  3905. /* get secondary valid target index */
  3906. if (buf[11] & BIT_7)
  3907. ddb_index[1] = buf[11] & 0x7f;
  3908. } else {
  3909. ret = QLA_ERROR;
  3910. goto exit_boot_info;
  3911. }
  3912. DEBUG2(ql4_printk(KERN_INFO, ha, "%s: Primary target ID %d, Secondary"
  3913. " target ID %d\n", __func__, ddb_index[0],
  3914. ddb_index[1]));
  3915. exit_boot_info_free:
  3916. dma_free_coherent(&ha->pdev->dev, size, buf, buf_dma);
  3917. exit_boot_info:
  3918. ha->pri_ddb_idx = ddb_index[0];
  3919. ha->sec_ddb_idx = ddb_index[1];
  3920. return ret;
  3921. }
  3922. /**
  3923. * qla4xxx_get_bidi_chap - Get a BIDI CHAP user and password
  3924. * @ha: pointer to adapter structure
  3925. * @username: CHAP username to be returned
  3926. * @password: CHAP password to be returned
  3927. *
  3928. * If a boot entry has BIDI CHAP enabled then we need to set the BIDI CHAP
  3929. * user and password in the sysfs entry in /sys/firmware/iscsi_boot#/.
  3930. * So from the CHAP cache find the first BIDI CHAP entry and set it
  3931. * to the boot record in sysfs.
  3932. **/
  3933. static int qla4xxx_get_bidi_chap(struct scsi_qla_host *ha, char *username,
  3934. char *password)
  3935. {
  3936. int i, ret = -EINVAL;
  3937. int max_chap_entries = 0;
  3938. struct ql4_chap_table *chap_table;
  3939. if (is_qla80XX(ha))
  3940. max_chap_entries = (ha->hw.flt_chap_size / 2) /
  3941. sizeof(struct ql4_chap_table);
  3942. else
  3943. max_chap_entries = MAX_CHAP_ENTRIES_40XX;
  3944. if (!ha->chap_list) {
  3945. ql4_printk(KERN_ERR, ha, "Do not have CHAP table cache\n");
  3946. return ret;
  3947. }
  3948. mutex_lock(&ha->chap_sem);
  3949. for (i = 0; i < max_chap_entries; i++) {
  3950. chap_table = (struct ql4_chap_table *)ha->chap_list + i;
  3951. if (chap_table->cookie !=
  3952. __constant_cpu_to_le16(CHAP_VALID_COOKIE)) {
  3953. continue;
  3954. }
  3955. if (chap_table->flags & BIT_7) /* local */
  3956. continue;
  3957. if (!(chap_table->flags & BIT_6)) /* Not BIDI */
  3958. continue;
  3959. strncpy(password, chap_table->secret, QL4_CHAP_MAX_SECRET_LEN);
  3960. strncpy(username, chap_table->name, QL4_CHAP_MAX_NAME_LEN);
  3961. ret = 0;
  3962. break;
  3963. }
  3964. mutex_unlock(&ha->chap_sem);
  3965. return ret;
  3966. }
  3967. static int qla4xxx_get_boot_target(struct scsi_qla_host *ha,
  3968. struct ql4_boot_session_info *boot_sess,
  3969. uint16_t ddb_index)
  3970. {
  3971. struct ql4_conn_info *boot_conn = &boot_sess->conn_list[0];
  3972. struct dev_db_entry *fw_ddb_entry;
  3973. dma_addr_t fw_ddb_entry_dma;
  3974. uint16_t idx;
  3975. uint16_t options;
  3976. int ret = QLA_SUCCESS;
  3977. fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
  3978. &fw_ddb_entry_dma, GFP_KERNEL);
  3979. if (!fw_ddb_entry) {
  3980. DEBUG2(ql4_printk(KERN_ERR, ha,
  3981. "%s: Unable to allocate dma buffer.\n",
  3982. __func__));
  3983. ret = QLA_ERROR;
  3984. return ret;
  3985. }
  3986. if (qla4xxx_bootdb_by_index(ha, fw_ddb_entry,
  3987. fw_ddb_entry_dma, ddb_index)) {
  3988. DEBUG2(ql4_printk(KERN_INFO, ha, "%s: No Flash DDB found at "
  3989. "index [%d]\n", __func__, ddb_index));
  3990. ret = QLA_ERROR;
  3991. goto exit_boot_target;
  3992. }
  3993. /* Update target name and IP from DDB */
  3994. memcpy(boot_sess->target_name, fw_ddb_entry->iscsi_name,
  3995. min(sizeof(boot_sess->target_name),
  3996. sizeof(fw_ddb_entry->iscsi_name)));
  3997. options = le16_to_cpu(fw_ddb_entry->options);
  3998. if (options & DDB_OPT_IPV6_DEVICE) {
  3999. memcpy(&boot_conn->dest_ipaddr.ip_address,
  4000. &fw_ddb_entry->ip_addr[0], IPv6_ADDR_LEN);
  4001. } else {
  4002. boot_conn->dest_ipaddr.ip_type = 0x1;
  4003. memcpy(&boot_conn->dest_ipaddr.ip_address,
  4004. &fw_ddb_entry->ip_addr[0], IP_ADDR_LEN);
  4005. }
  4006. boot_conn->dest_port = le16_to_cpu(fw_ddb_entry->port);
  4007. /* update chap information */
  4008. idx = __le16_to_cpu(fw_ddb_entry->chap_tbl_idx);
  4009. if (BIT_7 & le16_to_cpu(fw_ddb_entry->iscsi_options)) {
  4010. DEBUG2(ql4_printk(KERN_INFO, ha, "Setting chap\n"));
  4011. ret = qla4xxx_get_chap(ha, (char *)&boot_conn->chap.
  4012. target_chap_name,
  4013. (char *)&boot_conn->chap.target_secret,
  4014. idx);
  4015. if (ret) {
  4016. ql4_printk(KERN_ERR, ha, "Failed to set chap\n");
  4017. ret = QLA_ERROR;
  4018. goto exit_boot_target;
  4019. }
  4020. boot_conn->chap.target_chap_name_length = QL4_CHAP_MAX_NAME_LEN;
  4021. boot_conn->chap.target_secret_length = QL4_CHAP_MAX_SECRET_LEN;
  4022. }
  4023. if (BIT_4 & le16_to_cpu(fw_ddb_entry->iscsi_options)) {
  4024. DEBUG2(ql4_printk(KERN_INFO, ha, "Setting BIDI chap\n"));
  4025. ret = qla4xxx_get_bidi_chap(ha,
  4026. (char *)&boot_conn->chap.intr_chap_name,
  4027. (char *)&boot_conn->chap.intr_secret);
  4028. if (ret) {
  4029. ql4_printk(KERN_ERR, ha, "Failed to set BIDI chap\n");
  4030. ret = QLA_ERROR;
  4031. goto exit_boot_target;
  4032. }
  4033. boot_conn->chap.intr_chap_name_length = QL4_CHAP_MAX_NAME_LEN;
  4034. boot_conn->chap.intr_secret_length = QL4_CHAP_MAX_SECRET_LEN;
  4035. }
  4036. exit_boot_target:
  4037. dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
  4038. fw_ddb_entry, fw_ddb_entry_dma);
  4039. return ret;
  4040. }
  4041. static int qla4xxx_get_boot_info(struct scsi_qla_host *ha)
  4042. {
  4043. uint16_t ddb_index[2];
  4044. int ret = QLA_ERROR;
  4045. int rval;
  4046. memset(ddb_index, 0, sizeof(ddb_index));
  4047. ddb_index[0] = 0xffff;
  4048. ddb_index[1] = 0xffff;
  4049. ret = get_fw_boot_info(ha, ddb_index);
  4050. if (ret != QLA_SUCCESS) {
  4051. DEBUG2(ql4_printk(KERN_INFO, ha,
  4052. "%s: No boot target configured.\n", __func__));
  4053. return ret;
  4054. }
  4055. if (ql4xdisablesysfsboot)
  4056. return QLA_SUCCESS;
  4057. if (ddb_index[0] == 0xffff)
  4058. goto sec_target;
  4059. rval = qla4xxx_get_boot_target(ha, &(ha->boot_tgt.boot_pri_sess),
  4060. ddb_index[0]);
  4061. if (rval != QLA_SUCCESS) {
  4062. DEBUG2(ql4_printk(KERN_INFO, ha, "%s: Primary boot target not "
  4063. "configured\n", __func__));
  4064. } else
  4065. ret = QLA_SUCCESS;
  4066. sec_target:
  4067. if (ddb_index[1] == 0xffff)
  4068. goto exit_get_boot_info;
  4069. rval = qla4xxx_get_boot_target(ha, &(ha->boot_tgt.boot_sec_sess),
  4070. ddb_index[1]);
  4071. if (rval != QLA_SUCCESS) {
  4072. DEBUG2(ql4_printk(KERN_INFO, ha, "%s: Secondary boot target not"
  4073. " configured\n", __func__));
  4074. } else
  4075. ret = QLA_SUCCESS;
  4076. exit_get_boot_info:
  4077. return ret;
  4078. }
  4079. static int qla4xxx_setup_boot_info(struct scsi_qla_host *ha)
  4080. {
  4081. struct iscsi_boot_kobj *boot_kobj;
  4082. if (qla4xxx_get_boot_info(ha) != QLA_SUCCESS)
  4083. return QLA_ERROR;
  4084. if (ql4xdisablesysfsboot) {
  4085. ql4_printk(KERN_INFO, ha,
  4086. "%s: syfsboot disabled - driver will trigger login "
  4087. "and publish session for discovery .\n", __func__);
  4088. return QLA_SUCCESS;
  4089. }
  4090. ha->boot_kset = iscsi_boot_create_host_kset(ha->host->host_no);
  4091. if (!ha->boot_kset)
  4092. goto kset_free;
  4093. if (!scsi_host_get(ha->host))
  4094. goto kset_free;
  4095. boot_kobj = iscsi_boot_create_target(ha->boot_kset, 0, ha,
  4096. qla4xxx_show_boot_tgt_pri_info,
  4097. qla4xxx_tgt_get_attr_visibility,
  4098. qla4xxx_boot_release);
  4099. if (!boot_kobj)
  4100. goto put_host;
  4101. if (!scsi_host_get(ha->host))
  4102. goto kset_free;
  4103. boot_kobj = iscsi_boot_create_target(ha->boot_kset, 1, ha,
  4104. qla4xxx_show_boot_tgt_sec_info,
  4105. qla4xxx_tgt_get_attr_visibility,
  4106. qla4xxx_boot_release);
  4107. if (!boot_kobj)
  4108. goto put_host;
  4109. if (!scsi_host_get(ha->host))
  4110. goto kset_free;
  4111. boot_kobj = iscsi_boot_create_initiator(ha->boot_kset, 0, ha,
  4112. qla4xxx_show_boot_ini_info,
  4113. qla4xxx_ini_get_attr_visibility,
  4114. qla4xxx_boot_release);
  4115. if (!boot_kobj)
  4116. goto put_host;
  4117. if (!scsi_host_get(ha->host))
  4118. goto kset_free;
  4119. boot_kobj = iscsi_boot_create_ethernet(ha->boot_kset, 0, ha,
  4120. qla4xxx_show_boot_eth_info,
  4121. qla4xxx_eth_get_attr_visibility,
  4122. qla4xxx_boot_release);
  4123. if (!boot_kobj)
  4124. goto put_host;
  4125. return QLA_SUCCESS;
  4126. put_host:
  4127. scsi_host_put(ha->host);
  4128. kset_free:
  4129. iscsi_boot_destroy_kset(ha->boot_kset);
  4130. return -ENOMEM;
  4131. }
  4132. /**
  4133. * qla4xxx_create chap_list - Create CHAP list from FLASH
  4134. * @ha: pointer to adapter structure
  4135. *
  4136. * Read flash and make a list of CHAP entries, during login when a CHAP entry
  4137. * is received, it will be checked in this list. If entry exist then the CHAP
  4138. * entry index is set in the DDB. If CHAP entry does not exist in this list
  4139. * then a new entry is added in FLASH in CHAP table and the index obtained is
  4140. * used in the DDB.
  4141. **/
  4142. static void qla4xxx_create_chap_list(struct scsi_qla_host *ha)
  4143. {
  4144. int rval = 0;
  4145. uint8_t *chap_flash_data = NULL;
  4146. uint32_t offset;
  4147. dma_addr_t chap_dma;
  4148. uint32_t chap_size = 0;
  4149. if (is_qla40XX(ha))
  4150. chap_size = MAX_CHAP_ENTRIES_40XX *
  4151. sizeof(struct ql4_chap_table);
  4152. else /* Single region contains CHAP info for both
  4153. * ports which is divided into half for each port.
  4154. */
  4155. chap_size = ha->hw.flt_chap_size / 2;
  4156. chap_flash_data = dma_alloc_coherent(&ha->pdev->dev, chap_size,
  4157. &chap_dma, GFP_KERNEL);
  4158. if (!chap_flash_data) {
  4159. ql4_printk(KERN_ERR, ha, "No memory for chap_flash_data\n");
  4160. return;
  4161. }
  4162. if (is_qla40XX(ha))
  4163. offset = FLASH_CHAP_OFFSET;
  4164. else {
  4165. offset = FLASH_RAW_ACCESS_ADDR + (ha->hw.flt_region_chap << 2);
  4166. if (ha->port_num == 1)
  4167. offset += chap_size;
  4168. }
  4169. rval = qla4xxx_get_flash(ha, chap_dma, offset, chap_size);
  4170. if (rval != QLA_SUCCESS)
  4171. goto exit_chap_list;
  4172. if (ha->chap_list == NULL)
  4173. ha->chap_list = vmalloc(chap_size);
  4174. if (ha->chap_list == NULL) {
  4175. ql4_printk(KERN_ERR, ha, "No memory for ha->chap_list\n");
  4176. goto exit_chap_list;
  4177. }
  4178. memcpy(ha->chap_list, chap_flash_data, chap_size);
  4179. exit_chap_list:
  4180. dma_free_coherent(&ha->pdev->dev, chap_size,
  4181. chap_flash_data, chap_dma);
  4182. }
  4183. static void qla4xxx_get_param_ddb(struct ddb_entry *ddb_entry,
  4184. struct ql4_tuple_ddb *tddb)
  4185. {
  4186. struct scsi_qla_host *ha;
  4187. struct iscsi_cls_session *cls_sess;
  4188. struct iscsi_cls_conn *cls_conn;
  4189. struct iscsi_session *sess;
  4190. struct iscsi_conn *conn;
  4191. DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
  4192. ha = ddb_entry->ha;
  4193. cls_sess = ddb_entry->sess;
  4194. sess = cls_sess->dd_data;
  4195. cls_conn = ddb_entry->conn;
  4196. conn = cls_conn->dd_data;
  4197. tddb->tpgt = sess->tpgt;
  4198. tddb->port = conn->persistent_port;
  4199. strncpy(tddb->iscsi_name, sess->targetname, ISCSI_NAME_SIZE);
  4200. strncpy(tddb->ip_addr, conn->persistent_address, DDB_IPADDR_LEN);
  4201. }
  4202. static void qla4xxx_convert_param_ddb(struct dev_db_entry *fw_ddb_entry,
  4203. struct ql4_tuple_ddb *tddb,
  4204. uint8_t *flash_isid)
  4205. {
  4206. uint16_t options = 0;
  4207. tddb->tpgt = le32_to_cpu(fw_ddb_entry->tgt_portal_grp);
  4208. memcpy(&tddb->iscsi_name[0], &fw_ddb_entry->iscsi_name[0],
  4209. min(sizeof(tddb->iscsi_name), sizeof(fw_ddb_entry->iscsi_name)));
  4210. options = le16_to_cpu(fw_ddb_entry->options);
  4211. if (options & DDB_OPT_IPV6_DEVICE)
  4212. sprintf(tddb->ip_addr, "%pI6", fw_ddb_entry->ip_addr);
  4213. else
  4214. sprintf(tddb->ip_addr, "%pI4", fw_ddb_entry->ip_addr);
  4215. tddb->port = le16_to_cpu(fw_ddb_entry->port);
  4216. if (flash_isid == NULL)
  4217. memcpy(&tddb->isid[0], &fw_ddb_entry->isid[0],
  4218. sizeof(tddb->isid));
  4219. else
  4220. memcpy(&tddb->isid[0], &flash_isid[0], sizeof(tddb->isid));
  4221. }
  4222. static int qla4xxx_compare_tuple_ddb(struct scsi_qla_host *ha,
  4223. struct ql4_tuple_ddb *old_tddb,
  4224. struct ql4_tuple_ddb *new_tddb,
  4225. uint8_t is_isid_compare)
  4226. {
  4227. if (strcmp(old_tddb->iscsi_name, new_tddb->iscsi_name))
  4228. return QLA_ERROR;
  4229. if (strcmp(old_tddb->ip_addr, new_tddb->ip_addr))
  4230. return QLA_ERROR;
  4231. if (old_tddb->port != new_tddb->port)
  4232. return QLA_ERROR;
  4233. /* For multi sessions, driver generates the ISID, so do not compare
  4234. * ISID in reset path since it would be a comparison between the
  4235. * driver generated ISID and firmware generated ISID. This could
  4236. * lead to adding duplicated DDBs in the list as driver generated
  4237. * ISID would not match firmware generated ISID.
  4238. */
  4239. if (is_isid_compare) {
  4240. DEBUG2(ql4_printk(KERN_INFO, ha, "%s: old ISID [%02x%02x%02x"
  4241. "%02x%02x%02x] New ISID [%02x%02x%02x%02x%02x%02x]\n",
  4242. __func__, old_tddb->isid[5], old_tddb->isid[4],
  4243. old_tddb->isid[3], old_tddb->isid[2], old_tddb->isid[1],
  4244. old_tddb->isid[0], new_tddb->isid[5], new_tddb->isid[4],
  4245. new_tddb->isid[3], new_tddb->isid[2], new_tddb->isid[1],
  4246. new_tddb->isid[0]));
  4247. if (memcmp(&old_tddb->isid[0], &new_tddb->isid[0],
  4248. sizeof(old_tddb->isid)))
  4249. return QLA_ERROR;
  4250. }
  4251. DEBUG2(ql4_printk(KERN_INFO, ha,
  4252. "Match Found, fw[%d,%d,%s,%s], [%d,%d,%s,%s]",
  4253. old_tddb->port, old_tddb->tpgt, old_tddb->ip_addr,
  4254. old_tddb->iscsi_name, new_tddb->port, new_tddb->tpgt,
  4255. new_tddb->ip_addr, new_tddb->iscsi_name));
  4256. return QLA_SUCCESS;
  4257. }
  4258. static int qla4xxx_is_session_exists(struct scsi_qla_host *ha,
  4259. struct dev_db_entry *fw_ddb_entry)
  4260. {
  4261. struct ddb_entry *ddb_entry;
  4262. struct ql4_tuple_ddb *fw_tddb = NULL;
  4263. struct ql4_tuple_ddb *tmp_tddb = NULL;
  4264. int idx;
  4265. int ret = QLA_ERROR;
  4266. fw_tddb = vzalloc(sizeof(*fw_tddb));
  4267. if (!fw_tddb) {
  4268. DEBUG2(ql4_printk(KERN_WARNING, ha,
  4269. "Memory Allocation failed.\n"));
  4270. ret = QLA_SUCCESS;
  4271. goto exit_check;
  4272. }
  4273. tmp_tddb = vzalloc(sizeof(*tmp_tddb));
  4274. if (!tmp_tddb) {
  4275. DEBUG2(ql4_printk(KERN_WARNING, ha,
  4276. "Memory Allocation failed.\n"));
  4277. ret = QLA_SUCCESS;
  4278. goto exit_check;
  4279. }
  4280. qla4xxx_convert_param_ddb(fw_ddb_entry, fw_tddb, NULL);
  4281. for (idx = 0; idx < MAX_DDB_ENTRIES; idx++) {
  4282. ddb_entry = qla4xxx_lookup_ddb_by_fw_index(ha, idx);
  4283. if (ddb_entry == NULL)
  4284. continue;
  4285. qla4xxx_get_param_ddb(ddb_entry, tmp_tddb);
  4286. if (!qla4xxx_compare_tuple_ddb(ha, fw_tddb, tmp_tddb, false)) {
  4287. ret = QLA_SUCCESS; /* found */
  4288. goto exit_check;
  4289. }
  4290. }
  4291. exit_check:
  4292. if (fw_tddb)
  4293. vfree(fw_tddb);
  4294. if (tmp_tddb)
  4295. vfree(tmp_tddb);
  4296. return ret;
  4297. }
  4298. /**
  4299. * qla4xxx_check_existing_isid - check if target with same isid exist
  4300. * in target list
  4301. * @list_nt: list of target
  4302. * @isid: isid to check
  4303. *
  4304. * This routine return QLA_SUCCESS if target with same isid exist
  4305. **/
  4306. static int qla4xxx_check_existing_isid(struct list_head *list_nt, uint8_t *isid)
  4307. {
  4308. struct qla_ddb_index *nt_ddb_idx, *nt_ddb_idx_tmp;
  4309. struct dev_db_entry *fw_ddb_entry;
  4310. list_for_each_entry_safe(nt_ddb_idx, nt_ddb_idx_tmp, list_nt, list) {
  4311. fw_ddb_entry = &nt_ddb_idx->fw_ddb;
  4312. if (memcmp(&fw_ddb_entry->isid[0], &isid[0],
  4313. sizeof(nt_ddb_idx->fw_ddb.isid)) == 0) {
  4314. return QLA_SUCCESS;
  4315. }
  4316. }
  4317. return QLA_ERROR;
  4318. }
  4319. /**
  4320. * qla4xxx_update_isid - compare ddbs and updated isid
  4321. * @ha: Pointer to host adapter structure.
  4322. * @list_nt: list of nt target
  4323. * @fw_ddb_entry: firmware ddb entry
  4324. *
  4325. * This routine update isid if ddbs have same iqn, same isid and
  4326. * different IP addr.
  4327. * Return QLA_SUCCESS if isid is updated.
  4328. **/
  4329. static int qla4xxx_update_isid(struct scsi_qla_host *ha,
  4330. struct list_head *list_nt,
  4331. struct dev_db_entry *fw_ddb_entry)
  4332. {
  4333. uint8_t base_value, i;
  4334. base_value = fw_ddb_entry->isid[1] & 0x1f;
  4335. for (i = 0; i < 8; i++) {
  4336. fw_ddb_entry->isid[1] = (base_value | (i << 5));
  4337. if (qla4xxx_check_existing_isid(list_nt, fw_ddb_entry->isid))
  4338. break;
  4339. }
  4340. if (!qla4xxx_check_existing_isid(list_nt, fw_ddb_entry->isid))
  4341. return QLA_ERROR;
  4342. return QLA_SUCCESS;
  4343. }
  4344. /**
  4345. * qla4xxx_should_update_isid - check if isid need to update
  4346. * @ha: Pointer to host adapter structure.
  4347. * @old_tddb: ddb tuple
  4348. * @new_tddb: ddb tuple
  4349. *
  4350. * Return QLA_SUCCESS if different IP, different PORT, same iqn,
  4351. * same isid
  4352. **/
  4353. static int qla4xxx_should_update_isid(struct scsi_qla_host *ha,
  4354. struct ql4_tuple_ddb *old_tddb,
  4355. struct ql4_tuple_ddb *new_tddb)
  4356. {
  4357. if (strcmp(old_tddb->ip_addr, new_tddb->ip_addr) == 0) {
  4358. /* Same ip */
  4359. if (old_tddb->port == new_tddb->port)
  4360. return QLA_ERROR;
  4361. }
  4362. if (strcmp(old_tddb->iscsi_name, new_tddb->iscsi_name))
  4363. /* different iqn */
  4364. return QLA_ERROR;
  4365. if (memcmp(&old_tddb->isid[0], &new_tddb->isid[0],
  4366. sizeof(old_tddb->isid)))
  4367. /* different isid */
  4368. return QLA_ERROR;
  4369. return QLA_SUCCESS;
  4370. }
  4371. /**
  4372. * qla4xxx_is_flash_ddb_exists - check if fw_ddb_entry already exists in list_nt
  4373. * @ha: Pointer to host adapter structure.
  4374. * @list_nt: list of nt target.
  4375. * @fw_ddb_entry: firmware ddb entry.
  4376. *
  4377. * This routine check if fw_ddb_entry already exists in list_nt to avoid
  4378. * duplicate ddb in list_nt.
  4379. * Return QLA_SUCCESS if duplicate ddb exit in list_nl.
  4380. * Note: This function also update isid of DDB if required.
  4381. **/
  4382. static int qla4xxx_is_flash_ddb_exists(struct scsi_qla_host *ha,
  4383. struct list_head *list_nt,
  4384. struct dev_db_entry *fw_ddb_entry)
  4385. {
  4386. struct qla_ddb_index *nt_ddb_idx, *nt_ddb_idx_tmp;
  4387. struct ql4_tuple_ddb *fw_tddb = NULL;
  4388. struct ql4_tuple_ddb *tmp_tddb = NULL;
  4389. int rval, ret = QLA_ERROR;
  4390. fw_tddb = vzalloc(sizeof(*fw_tddb));
  4391. if (!fw_tddb) {
  4392. DEBUG2(ql4_printk(KERN_WARNING, ha,
  4393. "Memory Allocation failed.\n"));
  4394. ret = QLA_SUCCESS;
  4395. goto exit_check;
  4396. }
  4397. tmp_tddb = vzalloc(sizeof(*tmp_tddb));
  4398. if (!tmp_tddb) {
  4399. DEBUG2(ql4_printk(KERN_WARNING, ha,
  4400. "Memory Allocation failed.\n"));
  4401. ret = QLA_SUCCESS;
  4402. goto exit_check;
  4403. }
  4404. qla4xxx_convert_param_ddb(fw_ddb_entry, fw_tddb, NULL);
  4405. list_for_each_entry_safe(nt_ddb_idx, nt_ddb_idx_tmp, list_nt, list) {
  4406. qla4xxx_convert_param_ddb(&nt_ddb_idx->fw_ddb, tmp_tddb,
  4407. nt_ddb_idx->flash_isid);
  4408. ret = qla4xxx_compare_tuple_ddb(ha, fw_tddb, tmp_tddb, true);
  4409. /* found duplicate ddb */
  4410. if (ret == QLA_SUCCESS)
  4411. goto exit_check;
  4412. }
  4413. list_for_each_entry_safe(nt_ddb_idx, nt_ddb_idx_tmp, list_nt, list) {
  4414. qla4xxx_convert_param_ddb(&nt_ddb_idx->fw_ddb, tmp_tddb, NULL);
  4415. ret = qla4xxx_should_update_isid(ha, tmp_tddb, fw_tddb);
  4416. if (ret == QLA_SUCCESS) {
  4417. rval = qla4xxx_update_isid(ha, list_nt, fw_ddb_entry);
  4418. if (rval == QLA_SUCCESS)
  4419. ret = QLA_ERROR;
  4420. else
  4421. ret = QLA_SUCCESS;
  4422. goto exit_check;
  4423. }
  4424. }
  4425. exit_check:
  4426. if (fw_tddb)
  4427. vfree(fw_tddb);
  4428. if (tmp_tddb)
  4429. vfree(tmp_tddb);
  4430. return ret;
  4431. }
  4432. static void qla4xxx_free_ddb_list(struct list_head *list_ddb)
  4433. {
  4434. struct qla_ddb_index *ddb_idx, *ddb_idx_tmp;
  4435. list_for_each_entry_safe(ddb_idx, ddb_idx_tmp, list_ddb, list) {
  4436. list_del_init(&ddb_idx->list);
  4437. vfree(ddb_idx);
  4438. }
  4439. }
  4440. static struct iscsi_endpoint *qla4xxx_get_ep_fwdb(struct scsi_qla_host *ha,
  4441. struct dev_db_entry *fw_ddb_entry)
  4442. {
  4443. struct iscsi_endpoint *ep;
  4444. struct sockaddr_in *addr;
  4445. struct sockaddr_in6 *addr6;
  4446. struct sockaddr *t_addr;
  4447. struct sockaddr_storage *dst_addr;
  4448. char *ip;
  4449. /* TODO: need to destroy on unload iscsi_endpoint*/
  4450. dst_addr = vmalloc(sizeof(*dst_addr));
  4451. if (!dst_addr)
  4452. return NULL;
  4453. if (fw_ddb_entry->options & DDB_OPT_IPV6_DEVICE) {
  4454. t_addr = (struct sockaddr *)dst_addr;
  4455. t_addr->sa_family = AF_INET6;
  4456. addr6 = (struct sockaddr_in6 *)dst_addr;
  4457. ip = (char *)&addr6->sin6_addr;
  4458. memcpy(ip, fw_ddb_entry->ip_addr, IPv6_ADDR_LEN);
  4459. addr6->sin6_port = htons(le16_to_cpu(fw_ddb_entry->port));
  4460. } else {
  4461. t_addr = (struct sockaddr *)dst_addr;
  4462. t_addr->sa_family = AF_INET;
  4463. addr = (struct sockaddr_in *)dst_addr;
  4464. ip = (char *)&addr->sin_addr;
  4465. memcpy(ip, fw_ddb_entry->ip_addr, IP_ADDR_LEN);
  4466. addr->sin_port = htons(le16_to_cpu(fw_ddb_entry->port));
  4467. }
  4468. ep = qla4xxx_ep_connect(ha->host, (struct sockaddr *)dst_addr, 0);
  4469. vfree(dst_addr);
  4470. return ep;
  4471. }
  4472. static int qla4xxx_verify_boot_idx(struct scsi_qla_host *ha, uint16_t idx)
  4473. {
  4474. if (ql4xdisablesysfsboot)
  4475. return QLA_SUCCESS;
  4476. if (idx == ha->pri_ddb_idx || idx == ha->sec_ddb_idx)
  4477. return QLA_ERROR;
  4478. return QLA_SUCCESS;
  4479. }
  4480. static void qla4xxx_setup_flash_ddb_entry(struct scsi_qla_host *ha,
  4481. struct ddb_entry *ddb_entry,
  4482. uint16_t idx)
  4483. {
  4484. uint16_t def_timeout;
  4485. ddb_entry->ddb_type = FLASH_DDB;
  4486. ddb_entry->fw_ddb_index = INVALID_ENTRY;
  4487. ddb_entry->fw_ddb_device_state = DDB_DS_NO_CONNECTION_ACTIVE;
  4488. ddb_entry->ha = ha;
  4489. ddb_entry->unblock_sess = qla4xxx_unblock_flash_ddb;
  4490. ddb_entry->ddb_change = qla4xxx_flash_ddb_change;
  4491. atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
  4492. atomic_set(&ddb_entry->relogin_timer, 0);
  4493. atomic_set(&ddb_entry->relogin_retry_count, 0);
  4494. def_timeout = le16_to_cpu(ddb_entry->fw_ddb_entry.def_timeout);
  4495. ddb_entry->default_relogin_timeout =
  4496. (def_timeout > LOGIN_TOV) && (def_timeout < LOGIN_TOV * 10) ?
  4497. def_timeout : LOGIN_TOV;
  4498. ddb_entry->default_time2wait =
  4499. le16_to_cpu(ddb_entry->fw_ddb_entry.iscsi_def_time2wait);
  4500. if (ql4xdisablesysfsboot &&
  4501. (idx == ha->pri_ddb_idx || idx == ha->sec_ddb_idx))
  4502. set_bit(DF_BOOT_TGT, &ddb_entry->flags);
  4503. }
  4504. static void qla4xxx_wait_for_ip_configuration(struct scsi_qla_host *ha)
  4505. {
  4506. uint32_t idx = 0;
  4507. uint32_t ip_idx[IP_ADDR_COUNT] = {0, 1, 2, 3}; /* 4 IP interfaces */
  4508. uint32_t sts[MBOX_REG_COUNT];
  4509. uint32_t ip_state;
  4510. unsigned long wtime;
  4511. int ret;
  4512. wtime = jiffies + (HZ * IP_CONFIG_TOV);
  4513. do {
  4514. for (idx = 0; idx < IP_ADDR_COUNT; idx++) {
  4515. if (ip_idx[idx] == -1)
  4516. continue;
  4517. ret = qla4xxx_get_ip_state(ha, 0, ip_idx[idx], sts);
  4518. if (ret == QLA_ERROR) {
  4519. ip_idx[idx] = -1;
  4520. continue;
  4521. }
  4522. ip_state = (sts[1] & IP_STATE_MASK) >> IP_STATE_SHIFT;
  4523. DEBUG2(ql4_printk(KERN_INFO, ha,
  4524. "Waiting for IP state for idx = %d, state = 0x%x\n",
  4525. ip_idx[idx], ip_state));
  4526. if (ip_state == IP_ADDRSTATE_UNCONFIGURED ||
  4527. ip_state == IP_ADDRSTATE_INVALID ||
  4528. ip_state == IP_ADDRSTATE_PREFERRED ||
  4529. ip_state == IP_ADDRSTATE_DEPRICATED ||
  4530. ip_state == IP_ADDRSTATE_DISABLING)
  4531. ip_idx[idx] = -1;
  4532. }
  4533. /* Break if all IP states checked */
  4534. if ((ip_idx[0] == -1) &&
  4535. (ip_idx[1] == -1) &&
  4536. (ip_idx[2] == -1) &&
  4537. (ip_idx[3] == -1))
  4538. break;
  4539. schedule_timeout_uninterruptible(HZ);
  4540. } while (time_after(wtime, jiffies));
  4541. }
  4542. static void qla4xxx_build_st_list(struct scsi_qla_host *ha,
  4543. struct list_head *list_st)
  4544. {
  4545. struct qla_ddb_index *st_ddb_idx;
  4546. int max_ddbs;
  4547. int fw_idx_size;
  4548. struct dev_db_entry *fw_ddb_entry;
  4549. dma_addr_t fw_ddb_dma;
  4550. int ret;
  4551. uint32_t idx = 0, next_idx = 0;
  4552. uint32_t state = 0, conn_err = 0;
  4553. uint16_t conn_id = 0;
  4554. fw_ddb_entry = dma_pool_alloc(ha->fw_ddb_dma_pool, GFP_KERNEL,
  4555. &fw_ddb_dma);
  4556. if (fw_ddb_entry == NULL) {
  4557. DEBUG2(ql4_printk(KERN_ERR, ha, "Out of memory\n"));
  4558. goto exit_st_list;
  4559. }
  4560. max_ddbs = is_qla40XX(ha) ? MAX_DEV_DB_ENTRIES_40XX :
  4561. MAX_DEV_DB_ENTRIES;
  4562. fw_idx_size = sizeof(struct qla_ddb_index);
  4563. for (idx = 0; idx < max_ddbs; idx = next_idx) {
  4564. ret = qla4xxx_get_fwddb_entry(ha, idx, fw_ddb_entry, fw_ddb_dma,
  4565. NULL, &next_idx, &state,
  4566. &conn_err, NULL, &conn_id);
  4567. if (ret == QLA_ERROR)
  4568. break;
  4569. /* Ignore DDB if invalid state (unassigned) */
  4570. if (state == DDB_DS_UNASSIGNED)
  4571. goto continue_next_st;
  4572. /* Check if ST, add to the list_st */
  4573. if (strlen((char *) fw_ddb_entry->iscsi_name) != 0)
  4574. goto continue_next_st;
  4575. st_ddb_idx = vzalloc(fw_idx_size);
  4576. if (!st_ddb_idx)
  4577. break;
  4578. st_ddb_idx->fw_ddb_idx = idx;
  4579. list_add_tail(&st_ddb_idx->list, list_st);
  4580. continue_next_st:
  4581. if (next_idx == 0)
  4582. break;
  4583. }
  4584. exit_st_list:
  4585. if (fw_ddb_entry)
  4586. dma_pool_free(ha->fw_ddb_dma_pool, fw_ddb_entry, fw_ddb_dma);
  4587. }
  4588. /**
  4589. * qla4xxx_remove_failed_ddb - Remove inactive or failed ddb from list
  4590. * @ha: pointer to adapter structure
  4591. * @list_ddb: List from which failed ddb to be removed
  4592. *
  4593. * Iterate over the list of DDBs and find and remove DDBs that are either in
  4594. * no connection active state or failed state
  4595. **/
  4596. static void qla4xxx_remove_failed_ddb(struct scsi_qla_host *ha,
  4597. struct list_head *list_ddb)
  4598. {
  4599. struct qla_ddb_index *ddb_idx, *ddb_idx_tmp;
  4600. uint32_t next_idx = 0;
  4601. uint32_t state = 0, conn_err = 0;
  4602. int ret;
  4603. list_for_each_entry_safe(ddb_idx, ddb_idx_tmp, list_ddb, list) {
  4604. ret = qla4xxx_get_fwddb_entry(ha, ddb_idx->fw_ddb_idx,
  4605. NULL, 0, NULL, &next_idx, &state,
  4606. &conn_err, NULL, NULL);
  4607. if (ret == QLA_ERROR)
  4608. continue;
  4609. if (state == DDB_DS_NO_CONNECTION_ACTIVE ||
  4610. state == DDB_DS_SESSION_FAILED) {
  4611. list_del_init(&ddb_idx->list);
  4612. vfree(ddb_idx);
  4613. }
  4614. }
  4615. }
  4616. static int qla4xxx_sess_conn_setup(struct scsi_qla_host *ha,
  4617. struct dev_db_entry *fw_ddb_entry,
  4618. int is_reset, uint16_t idx)
  4619. {
  4620. struct iscsi_cls_session *cls_sess;
  4621. struct iscsi_session *sess;
  4622. struct iscsi_cls_conn *cls_conn;
  4623. struct iscsi_endpoint *ep;
  4624. uint16_t cmds_max = 32;
  4625. uint16_t conn_id = 0;
  4626. uint32_t initial_cmdsn = 0;
  4627. int ret = QLA_SUCCESS;
  4628. struct ddb_entry *ddb_entry = NULL;
  4629. /* Create session object, with INVALID_ENTRY,
  4630. * the targer_id would get set when we issue the login
  4631. */
  4632. cls_sess = iscsi_session_setup(&qla4xxx_iscsi_transport, ha->host,
  4633. cmds_max, sizeof(struct ddb_entry),
  4634. sizeof(struct ql4_task_data),
  4635. initial_cmdsn, INVALID_ENTRY);
  4636. if (!cls_sess) {
  4637. ret = QLA_ERROR;
  4638. goto exit_setup;
  4639. }
  4640. /*
  4641. * so calling module_put function to decrement the
  4642. * reference count.
  4643. **/
  4644. module_put(qla4xxx_iscsi_transport.owner);
  4645. sess = cls_sess->dd_data;
  4646. ddb_entry = sess->dd_data;
  4647. ddb_entry->sess = cls_sess;
  4648. cls_sess->recovery_tmo = ql4xsess_recovery_tmo;
  4649. memcpy(&ddb_entry->fw_ddb_entry, fw_ddb_entry,
  4650. sizeof(struct dev_db_entry));
  4651. qla4xxx_setup_flash_ddb_entry(ha, ddb_entry, idx);
  4652. cls_conn = iscsi_conn_setup(cls_sess, sizeof(struct qla_conn), conn_id);
  4653. if (!cls_conn) {
  4654. ret = QLA_ERROR;
  4655. goto exit_setup;
  4656. }
  4657. ddb_entry->conn = cls_conn;
  4658. /* Setup ep, for displaying attributes in sysfs */
  4659. ep = qla4xxx_get_ep_fwdb(ha, fw_ddb_entry);
  4660. if (ep) {
  4661. ep->conn = cls_conn;
  4662. cls_conn->ep = ep;
  4663. } else {
  4664. DEBUG2(ql4_printk(KERN_ERR, ha, "Unable to get ep\n"));
  4665. ret = QLA_ERROR;
  4666. goto exit_setup;
  4667. }
  4668. /* Update sess/conn params */
  4669. qla4xxx_copy_fwddb_param(ha, fw_ddb_entry, cls_sess, cls_conn);
  4670. if (is_reset == RESET_ADAPTER) {
  4671. iscsi_block_session(cls_sess);
  4672. /* Use the relogin path to discover new devices
  4673. * by short-circuting the logic of setting
  4674. * timer to relogin - instead set the flags
  4675. * to initiate login right away.
  4676. */
  4677. set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
  4678. set_bit(DF_RELOGIN, &ddb_entry->flags);
  4679. }
  4680. exit_setup:
  4681. return ret;
  4682. }
  4683. static void qla4xxx_build_nt_list(struct scsi_qla_host *ha,
  4684. struct list_head *list_nt, int is_reset)
  4685. {
  4686. struct dev_db_entry *fw_ddb_entry;
  4687. dma_addr_t fw_ddb_dma;
  4688. int max_ddbs;
  4689. int fw_idx_size;
  4690. int ret;
  4691. uint32_t idx = 0, next_idx = 0;
  4692. uint32_t state = 0, conn_err = 0;
  4693. uint16_t conn_id = 0;
  4694. struct qla_ddb_index *nt_ddb_idx;
  4695. fw_ddb_entry = dma_pool_alloc(ha->fw_ddb_dma_pool, GFP_KERNEL,
  4696. &fw_ddb_dma);
  4697. if (fw_ddb_entry == NULL) {
  4698. DEBUG2(ql4_printk(KERN_ERR, ha, "Out of memory\n"));
  4699. goto exit_nt_list;
  4700. }
  4701. max_ddbs = is_qla40XX(ha) ? MAX_DEV_DB_ENTRIES_40XX :
  4702. MAX_DEV_DB_ENTRIES;
  4703. fw_idx_size = sizeof(struct qla_ddb_index);
  4704. for (idx = 0; idx < max_ddbs; idx = next_idx) {
  4705. ret = qla4xxx_get_fwddb_entry(ha, idx, fw_ddb_entry, fw_ddb_dma,
  4706. NULL, &next_idx, &state,
  4707. &conn_err, NULL, &conn_id);
  4708. if (ret == QLA_ERROR)
  4709. break;
  4710. if (qla4xxx_verify_boot_idx(ha, idx) != QLA_SUCCESS)
  4711. goto continue_next_nt;
  4712. /* Check if NT, then add to list it */
  4713. if (strlen((char *) fw_ddb_entry->iscsi_name) == 0)
  4714. goto continue_next_nt;
  4715. if (!(state == DDB_DS_NO_CONNECTION_ACTIVE ||
  4716. state == DDB_DS_SESSION_FAILED))
  4717. goto continue_next_nt;
  4718. DEBUG2(ql4_printk(KERN_INFO, ha,
  4719. "Adding DDB to session = 0x%x\n", idx));
  4720. if (is_reset == INIT_ADAPTER) {
  4721. nt_ddb_idx = vmalloc(fw_idx_size);
  4722. if (!nt_ddb_idx)
  4723. break;
  4724. nt_ddb_idx->fw_ddb_idx = idx;
  4725. /* Copy original isid as it may get updated in function
  4726. * qla4xxx_update_isid(). We need original isid in
  4727. * function qla4xxx_compare_tuple_ddb to find duplicate
  4728. * target */
  4729. memcpy(&nt_ddb_idx->flash_isid[0],
  4730. &fw_ddb_entry->isid[0],
  4731. sizeof(nt_ddb_idx->flash_isid));
  4732. ret = qla4xxx_is_flash_ddb_exists(ha, list_nt,
  4733. fw_ddb_entry);
  4734. if (ret == QLA_SUCCESS) {
  4735. /* free nt_ddb_idx and do not add to list_nt */
  4736. vfree(nt_ddb_idx);
  4737. goto continue_next_nt;
  4738. }
  4739. /* Copy updated isid */
  4740. memcpy(&nt_ddb_idx->fw_ddb, fw_ddb_entry,
  4741. sizeof(struct dev_db_entry));
  4742. list_add_tail(&nt_ddb_idx->list, list_nt);
  4743. } else if (is_reset == RESET_ADAPTER) {
  4744. if (qla4xxx_is_session_exists(ha, fw_ddb_entry) ==
  4745. QLA_SUCCESS)
  4746. goto continue_next_nt;
  4747. }
  4748. ret = qla4xxx_sess_conn_setup(ha, fw_ddb_entry, is_reset, idx);
  4749. if (ret == QLA_ERROR)
  4750. goto exit_nt_list;
  4751. continue_next_nt:
  4752. if (next_idx == 0)
  4753. break;
  4754. }
  4755. exit_nt_list:
  4756. if (fw_ddb_entry)
  4757. dma_pool_free(ha->fw_ddb_dma_pool, fw_ddb_entry, fw_ddb_dma);
  4758. }
  4759. static void qla4xxx_build_new_nt_list(struct scsi_qla_host *ha,
  4760. struct list_head *list_nt)
  4761. {
  4762. struct dev_db_entry *fw_ddb_entry;
  4763. dma_addr_t fw_ddb_dma;
  4764. int max_ddbs;
  4765. int fw_idx_size;
  4766. int ret;
  4767. uint32_t idx = 0, next_idx = 0;
  4768. uint32_t state = 0, conn_err = 0;
  4769. uint16_t conn_id = 0;
  4770. struct qla_ddb_index *nt_ddb_idx;
  4771. fw_ddb_entry = dma_pool_alloc(ha->fw_ddb_dma_pool, GFP_KERNEL,
  4772. &fw_ddb_dma);
  4773. if (fw_ddb_entry == NULL) {
  4774. DEBUG2(ql4_printk(KERN_ERR, ha, "Out of memory\n"));
  4775. goto exit_new_nt_list;
  4776. }
  4777. max_ddbs = is_qla40XX(ha) ? MAX_DEV_DB_ENTRIES_40XX :
  4778. MAX_DEV_DB_ENTRIES;
  4779. fw_idx_size = sizeof(struct qla_ddb_index);
  4780. for (idx = 0; idx < max_ddbs; idx = next_idx) {
  4781. ret = qla4xxx_get_fwddb_entry(ha, idx, fw_ddb_entry, fw_ddb_dma,
  4782. NULL, &next_idx, &state,
  4783. &conn_err, NULL, &conn_id);
  4784. if (ret == QLA_ERROR)
  4785. break;
  4786. /* Check if NT, then add it to list */
  4787. if (strlen((char *)fw_ddb_entry->iscsi_name) == 0)
  4788. goto continue_next_new_nt;
  4789. if (!(state == DDB_DS_NO_CONNECTION_ACTIVE))
  4790. goto continue_next_new_nt;
  4791. DEBUG2(ql4_printk(KERN_INFO, ha,
  4792. "Adding DDB to session = 0x%x\n", idx));
  4793. nt_ddb_idx = vmalloc(fw_idx_size);
  4794. if (!nt_ddb_idx)
  4795. break;
  4796. nt_ddb_idx->fw_ddb_idx = idx;
  4797. ret = qla4xxx_is_session_exists(ha, fw_ddb_entry);
  4798. if (ret == QLA_SUCCESS) {
  4799. /* free nt_ddb_idx and do not add to list_nt */
  4800. vfree(nt_ddb_idx);
  4801. goto continue_next_new_nt;
  4802. }
  4803. list_add_tail(&nt_ddb_idx->list, list_nt);
  4804. ret = qla4xxx_sess_conn_setup(ha, fw_ddb_entry, RESET_ADAPTER,
  4805. idx);
  4806. if (ret == QLA_ERROR)
  4807. goto exit_new_nt_list;
  4808. continue_next_new_nt:
  4809. if (next_idx == 0)
  4810. break;
  4811. }
  4812. exit_new_nt_list:
  4813. if (fw_ddb_entry)
  4814. dma_pool_free(ha->fw_ddb_dma_pool, fw_ddb_entry, fw_ddb_dma);
  4815. }
  4816. /**
  4817. * qla4xxx_sysfs_ddb_is_non_persistent - check for non-persistence of ddb entry
  4818. * @dev: dev associated with the sysfs entry
  4819. * @data: pointer to flashnode session object
  4820. *
  4821. * Returns:
  4822. * 1: if flashnode entry is non-persistent
  4823. * 0: if flashnode entry is persistent
  4824. **/
  4825. static int qla4xxx_sysfs_ddb_is_non_persistent(struct device *dev, void *data)
  4826. {
  4827. struct iscsi_bus_flash_session *fnode_sess;
  4828. if (!iscsi_flashnode_bus_match(dev, NULL))
  4829. return 0;
  4830. fnode_sess = iscsi_dev_to_flash_session(dev);
  4831. return (fnode_sess->flash_state == DEV_DB_NON_PERSISTENT);
  4832. }
  4833. /**
  4834. * qla4xxx_sysfs_ddb_tgt_create - Create sysfs entry for target
  4835. * @ha: pointer to host
  4836. * @fw_ddb_entry: flash ddb data
  4837. * @idx: target index
  4838. * @user: if set then this call is made from userland else from kernel
  4839. *
  4840. * Returns:
  4841. * On sucess: QLA_SUCCESS
  4842. * On failure: QLA_ERROR
  4843. *
  4844. * This create separate sysfs entries for session and connection attributes of
  4845. * the given fw ddb entry.
  4846. * If this is invoked as a result of a userspace call then the entry is marked
  4847. * as nonpersistent using flash_state field.
  4848. **/
  4849. static int qla4xxx_sysfs_ddb_tgt_create(struct scsi_qla_host *ha,
  4850. struct dev_db_entry *fw_ddb_entry,
  4851. uint16_t *idx, int user)
  4852. {
  4853. struct iscsi_bus_flash_session *fnode_sess = NULL;
  4854. struct iscsi_bus_flash_conn *fnode_conn = NULL;
  4855. int rc = QLA_ERROR;
  4856. fnode_sess = iscsi_create_flashnode_sess(ha->host, *idx,
  4857. &qla4xxx_iscsi_transport, 0);
  4858. if (!fnode_sess) {
  4859. ql4_printk(KERN_ERR, ha,
  4860. "%s: Unable to create session sysfs entry for flashnode %d of host%lu\n",
  4861. __func__, *idx, ha->host_no);
  4862. goto exit_tgt_create;
  4863. }
  4864. fnode_conn = iscsi_create_flashnode_conn(ha->host, fnode_sess,
  4865. &qla4xxx_iscsi_transport, 0);
  4866. if (!fnode_conn) {
  4867. ql4_printk(KERN_ERR, ha,
  4868. "%s: Unable to create conn sysfs entry for flashnode %d of host%lu\n",
  4869. __func__, *idx, ha->host_no);
  4870. goto free_sess;
  4871. }
  4872. if (user) {
  4873. fnode_sess->flash_state = DEV_DB_NON_PERSISTENT;
  4874. } else {
  4875. fnode_sess->flash_state = DEV_DB_PERSISTENT;
  4876. if (*idx == ha->pri_ddb_idx || *idx == ha->sec_ddb_idx)
  4877. fnode_sess->is_boot_target = 1;
  4878. else
  4879. fnode_sess->is_boot_target = 0;
  4880. }
  4881. rc = qla4xxx_copy_from_fwddb_param(fnode_sess, fnode_conn,
  4882. fw_ddb_entry);
  4883. ql4_printk(KERN_INFO, ha, "%s: sysfs entry %s created\n",
  4884. __func__, fnode_sess->dev.kobj.name);
  4885. ql4_printk(KERN_INFO, ha, "%s: sysfs entry %s created\n",
  4886. __func__, fnode_conn->dev.kobj.name);
  4887. return QLA_SUCCESS;
  4888. free_sess:
  4889. iscsi_destroy_flashnode_sess(fnode_sess);
  4890. exit_tgt_create:
  4891. return QLA_ERROR;
  4892. }
  4893. /**
  4894. * qla4xxx_sysfs_ddb_add - Add new ddb entry in flash
  4895. * @shost: pointer to host
  4896. * @buf: type of ddb entry (ipv4/ipv6)
  4897. * @len: length of buf
  4898. *
  4899. * This creates new ddb entry in the flash by finding first free index and
  4900. * storing default ddb there. And then create sysfs entry for the new ddb entry.
  4901. **/
  4902. static int qla4xxx_sysfs_ddb_add(struct Scsi_Host *shost, const char *buf,
  4903. int len)
  4904. {
  4905. struct scsi_qla_host *ha = to_qla_host(shost);
  4906. struct dev_db_entry *fw_ddb_entry = NULL;
  4907. dma_addr_t fw_ddb_entry_dma;
  4908. struct device *dev;
  4909. uint16_t idx = 0;
  4910. uint16_t max_ddbs = 0;
  4911. uint32_t options = 0;
  4912. uint32_t rval = QLA_ERROR;
  4913. if (strncasecmp(PORTAL_TYPE_IPV4, buf, 4) &&
  4914. strncasecmp(PORTAL_TYPE_IPV6, buf, 4)) {
  4915. DEBUG2(ql4_printk(KERN_ERR, ha, "%s: Invalid portal type\n",
  4916. __func__));
  4917. goto exit_ddb_add;
  4918. }
  4919. max_ddbs = is_qla40XX(ha) ? MAX_PRST_DEV_DB_ENTRIES :
  4920. MAX_DEV_DB_ENTRIES;
  4921. fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
  4922. &fw_ddb_entry_dma, GFP_KERNEL);
  4923. if (!fw_ddb_entry) {
  4924. DEBUG2(ql4_printk(KERN_ERR, ha,
  4925. "%s: Unable to allocate dma buffer\n",
  4926. __func__));
  4927. goto exit_ddb_add;
  4928. }
  4929. dev = iscsi_find_flashnode_sess(ha->host, NULL,
  4930. qla4xxx_sysfs_ddb_is_non_persistent);
  4931. if (dev) {
  4932. ql4_printk(KERN_ERR, ha,
  4933. "%s: A non-persistent entry %s found\n",
  4934. __func__, dev->kobj.name);
  4935. put_device(dev);
  4936. goto exit_ddb_add;
  4937. }
  4938. for (idx = 0; idx < max_ddbs; idx++) {
  4939. if (qla4xxx_flashdb_by_index(ha, fw_ddb_entry,
  4940. fw_ddb_entry_dma, idx))
  4941. break;
  4942. }
  4943. if (idx == max_ddbs)
  4944. goto exit_ddb_add;
  4945. if (!strncasecmp("ipv6", buf, 4))
  4946. options |= IPV6_DEFAULT_DDB_ENTRY;
  4947. rval = qla4xxx_get_default_ddb(ha, options, fw_ddb_entry_dma);
  4948. if (rval == QLA_ERROR)
  4949. goto exit_ddb_add;
  4950. rval = qla4xxx_sysfs_ddb_tgt_create(ha, fw_ddb_entry, &idx, 1);
  4951. exit_ddb_add:
  4952. if (fw_ddb_entry)
  4953. dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
  4954. fw_ddb_entry, fw_ddb_entry_dma);
  4955. if (rval == QLA_SUCCESS)
  4956. return idx;
  4957. else
  4958. return -EIO;
  4959. }
  4960. /**
  4961. * qla4xxx_sysfs_ddb_apply - write the target ddb contents to Flash
  4962. * @fnode_sess: pointer to session attrs of flash ddb entry
  4963. * @fnode_conn: pointer to connection attrs of flash ddb entry
  4964. *
  4965. * This writes the contents of target ddb buffer to Flash with a valid cookie
  4966. * value in order to make the ddb entry persistent.
  4967. **/
  4968. static int qla4xxx_sysfs_ddb_apply(struct iscsi_bus_flash_session *fnode_sess,
  4969. struct iscsi_bus_flash_conn *fnode_conn)
  4970. {
  4971. struct Scsi_Host *shost = iscsi_flash_session_to_shost(fnode_sess);
  4972. struct scsi_qla_host *ha = to_qla_host(shost);
  4973. uint32_t dev_db_start_offset = FLASH_OFFSET_DB_INFO;
  4974. struct dev_db_entry *fw_ddb_entry = NULL;
  4975. dma_addr_t fw_ddb_entry_dma;
  4976. uint32_t options = 0;
  4977. int rval = 0;
  4978. fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
  4979. &fw_ddb_entry_dma, GFP_KERNEL);
  4980. if (!fw_ddb_entry) {
  4981. DEBUG2(ql4_printk(KERN_ERR, ha,
  4982. "%s: Unable to allocate dma buffer\n",
  4983. __func__));
  4984. rval = -ENOMEM;
  4985. goto exit_ddb_apply;
  4986. }
  4987. if (!strncasecmp(fnode_sess->portal_type, PORTAL_TYPE_IPV6, 4))
  4988. options |= IPV6_DEFAULT_DDB_ENTRY;
  4989. rval = qla4xxx_get_default_ddb(ha, options, fw_ddb_entry_dma);
  4990. if (rval == QLA_ERROR)
  4991. goto exit_ddb_apply;
  4992. dev_db_start_offset += (fnode_sess->target_id *
  4993. sizeof(*fw_ddb_entry));
  4994. qla4xxx_copy_to_fwddb_param(fnode_sess, fnode_conn, fw_ddb_entry);
  4995. fw_ddb_entry->cookie = DDB_VALID_COOKIE;
  4996. rval = qla4xxx_set_flash(ha, fw_ddb_entry_dma, dev_db_start_offset,
  4997. sizeof(*fw_ddb_entry), FLASH_OPT_RMW_COMMIT);
  4998. if (rval == QLA_SUCCESS) {
  4999. fnode_sess->flash_state = DEV_DB_PERSISTENT;
  5000. ql4_printk(KERN_INFO, ha,
  5001. "%s: flash node %u of host %lu written to flash\n",
  5002. __func__, fnode_sess->target_id, ha->host_no);
  5003. } else {
  5004. rval = -EIO;
  5005. ql4_printk(KERN_ERR, ha,
  5006. "%s: Error while writing flash node %u of host %lu to flash\n",
  5007. __func__, fnode_sess->target_id, ha->host_no);
  5008. }
  5009. exit_ddb_apply:
  5010. if (fw_ddb_entry)
  5011. dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
  5012. fw_ddb_entry, fw_ddb_entry_dma);
  5013. return rval;
  5014. }
  5015. static ssize_t qla4xxx_sysfs_ddb_conn_open(struct scsi_qla_host *ha,
  5016. struct dev_db_entry *fw_ddb_entry,
  5017. uint16_t idx)
  5018. {
  5019. struct dev_db_entry *ddb_entry = NULL;
  5020. dma_addr_t ddb_entry_dma;
  5021. unsigned long wtime;
  5022. uint32_t mbx_sts = 0;
  5023. uint32_t state = 0, conn_err = 0;
  5024. uint16_t tmo = 0;
  5025. int ret = 0;
  5026. ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*ddb_entry),
  5027. &ddb_entry_dma, GFP_KERNEL);
  5028. if (!ddb_entry) {
  5029. DEBUG2(ql4_printk(KERN_ERR, ha,
  5030. "%s: Unable to allocate dma buffer\n",
  5031. __func__));
  5032. return QLA_ERROR;
  5033. }
  5034. memcpy(ddb_entry, fw_ddb_entry, sizeof(*ddb_entry));
  5035. ret = qla4xxx_set_ddb_entry(ha, idx, ddb_entry_dma, &mbx_sts);
  5036. if (ret != QLA_SUCCESS) {
  5037. DEBUG2(ql4_printk(KERN_ERR, ha,
  5038. "%s: Unable to set ddb entry for index %d\n",
  5039. __func__, idx));
  5040. goto exit_ddb_conn_open;
  5041. }
  5042. qla4xxx_conn_open(ha, idx);
  5043. /* To ensure that sendtargets is done, wait for at least 12 secs */
  5044. tmo = ((ha->def_timeout > LOGIN_TOV) &&
  5045. (ha->def_timeout < LOGIN_TOV * 10) ?
  5046. ha->def_timeout : LOGIN_TOV);
  5047. DEBUG2(ql4_printk(KERN_INFO, ha,
  5048. "Default time to wait for login to ddb %d\n", tmo));
  5049. wtime = jiffies + (HZ * tmo);
  5050. do {
  5051. ret = qla4xxx_get_fwddb_entry(ha, idx, NULL, 0, NULL,
  5052. NULL, &state, &conn_err, NULL,
  5053. NULL);
  5054. if (ret == QLA_ERROR)
  5055. continue;
  5056. if (state == DDB_DS_NO_CONNECTION_ACTIVE ||
  5057. state == DDB_DS_SESSION_FAILED)
  5058. break;
  5059. schedule_timeout_uninterruptible(HZ / 10);
  5060. } while (time_after(wtime, jiffies));
  5061. exit_ddb_conn_open:
  5062. if (ddb_entry)
  5063. dma_free_coherent(&ha->pdev->dev, sizeof(*ddb_entry),
  5064. ddb_entry, ddb_entry_dma);
  5065. return ret;
  5066. }
  5067. static int qla4xxx_ddb_login_st(struct scsi_qla_host *ha,
  5068. struct dev_db_entry *fw_ddb_entry)
  5069. {
  5070. struct qla_ddb_index *ddb_idx, *ddb_idx_tmp;
  5071. struct list_head list_nt;
  5072. uint16_t ddb_index;
  5073. int ret = 0;
  5074. if (test_bit(AF_ST_DISCOVERY_IN_PROGRESS, &ha->flags)) {
  5075. ql4_printk(KERN_WARNING, ha,
  5076. "%s: A discovery already in progress!\n", __func__);
  5077. return QLA_ERROR;
  5078. }
  5079. INIT_LIST_HEAD(&list_nt);
  5080. set_bit(AF_ST_DISCOVERY_IN_PROGRESS, &ha->flags);
  5081. ret = qla4xxx_get_ddb_index(ha, &ddb_index);
  5082. if (ret == QLA_ERROR)
  5083. goto exit_login_st_clr_bit;
  5084. ret = qla4xxx_sysfs_ddb_conn_open(ha, fw_ddb_entry, ddb_index);
  5085. if (ret == QLA_ERROR)
  5086. goto exit_login_st;
  5087. qla4xxx_build_new_nt_list(ha, &list_nt);
  5088. list_for_each_entry_safe(ddb_idx, ddb_idx_tmp, &list_nt, list) {
  5089. list_del_init(&ddb_idx->list);
  5090. qla4xxx_clear_ddb_entry(ha, ddb_idx->fw_ddb_idx);
  5091. vfree(ddb_idx);
  5092. }
  5093. exit_login_st:
  5094. if (qla4xxx_clear_ddb_entry(ha, ddb_index) == QLA_ERROR) {
  5095. ql4_printk(KERN_ERR, ha,
  5096. "Unable to clear DDB index = 0x%x\n", ddb_index);
  5097. }
  5098. clear_bit(ddb_index, ha->ddb_idx_map);
  5099. exit_login_st_clr_bit:
  5100. clear_bit(AF_ST_DISCOVERY_IN_PROGRESS, &ha->flags);
  5101. return ret;
  5102. }
  5103. static int qla4xxx_ddb_login_nt(struct scsi_qla_host *ha,
  5104. struct dev_db_entry *fw_ddb_entry,
  5105. uint16_t idx)
  5106. {
  5107. int ret = QLA_ERROR;
  5108. ret = qla4xxx_is_session_exists(ha, fw_ddb_entry);
  5109. if (ret != QLA_SUCCESS)
  5110. ret = qla4xxx_sess_conn_setup(ha, fw_ddb_entry, RESET_ADAPTER,
  5111. idx);
  5112. else
  5113. ret = -EPERM;
  5114. return ret;
  5115. }
  5116. /**
  5117. * qla4xxx_sysfs_ddb_login - Login to the specified target
  5118. * @fnode_sess: pointer to session attrs of flash ddb entry
  5119. * @fnode_conn: pointer to connection attrs of flash ddb entry
  5120. *
  5121. * This logs in to the specified target
  5122. **/
  5123. static int qla4xxx_sysfs_ddb_login(struct iscsi_bus_flash_session *fnode_sess,
  5124. struct iscsi_bus_flash_conn *fnode_conn)
  5125. {
  5126. struct Scsi_Host *shost = iscsi_flash_session_to_shost(fnode_sess);
  5127. struct scsi_qla_host *ha = to_qla_host(shost);
  5128. struct dev_db_entry *fw_ddb_entry = NULL;
  5129. dma_addr_t fw_ddb_entry_dma;
  5130. uint32_t options = 0;
  5131. int ret = 0;
  5132. if (fnode_sess->flash_state == DEV_DB_NON_PERSISTENT) {
  5133. ql4_printk(KERN_ERR, ha,
  5134. "%s: Target info is not persistent\n", __func__);
  5135. ret = -EIO;
  5136. goto exit_ddb_login;
  5137. }
  5138. fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
  5139. &fw_ddb_entry_dma, GFP_KERNEL);
  5140. if (!fw_ddb_entry) {
  5141. DEBUG2(ql4_printk(KERN_ERR, ha,
  5142. "%s: Unable to allocate dma buffer\n",
  5143. __func__));
  5144. ret = -ENOMEM;
  5145. goto exit_ddb_login;
  5146. }
  5147. if (!strncasecmp(fnode_sess->portal_type, PORTAL_TYPE_IPV6, 4))
  5148. options |= IPV6_DEFAULT_DDB_ENTRY;
  5149. ret = qla4xxx_get_default_ddb(ha, options, fw_ddb_entry_dma);
  5150. if (ret == QLA_ERROR)
  5151. goto exit_ddb_login;
  5152. qla4xxx_copy_to_fwddb_param(fnode_sess, fnode_conn, fw_ddb_entry);
  5153. fw_ddb_entry->cookie = DDB_VALID_COOKIE;
  5154. if (strlen((char *)fw_ddb_entry->iscsi_name) == 0)
  5155. ret = qla4xxx_ddb_login_st(ha, fw_ddb_entry);
  5156. else
  5157. ret = qla4xxx_ddb_login_nt(ha, fw_ddb_entry,
  5158. fnode_sess->target_id);
  5159. if (ret > 0)
  5160. ret = -EIO;
  5161. exit_ddb_login:
  5162. if (fw_ddb_entry)
  5163. dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
  5164. fw_ddb_entry, fw_ddb_entry_dma);
  5165. return ret;
  5166. }
  5167. /**
  5168. * qla4xxx_sysfs_ddb_logout_sid - Logout session for the specified target
  5169. * @cls_sess: pointer to session to be logged out
  5170. *
  5171. * This performs session log out from the specified target
  5172. **/
  5173. static int qla4xxx_sysfs_ddb_logout_sid(struct iscsi_cls_session *cls_sess)
  5174. {
  5175. struct iscsi_session *sess;
  5176. struct ddb_entry *ddb_entry = NULL;
  5177. struct scsi_qla_host *ha;
  5178. struct dev_db_entry *fw_ddb_entry = NULL;
  5179. dma_addr_t fw_ddb_entry_dma;
  5180. unsigned long flags;
  5181. unsigned long wtime;
  5182. uint32_t ddb_state;
  5183. int options;
  5184. int ret = 0;
  5185. sess = cls_sess->dd_data;
  5186. ddb_entry = sess->dd_data;
  5187. ha = ddb_entry->ha;
  5188. if (ddb_entry->ddb_type != FLASH_DDB) {
  5189. ql4_printk(KERN_ERR, ha, "%s: Not a flash node session\n",
  5190. __func__);
  5191. ret = -ENXIO;
  5192. goto exit_ddb_logout;
  5193. }
  5194. if (test_bit(DF_BOOT_TGT, &ddb_entry->flags)) {
  5195. ql4_printk(KERN_ERR, ha,
  5196. "%s: Logout from boot target entry is not permitted.\n",
  5197. __func__);
  5198. ret = -EPERM;
  5199. goto exit_ddb_logout;
  5200. }
  5201. fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
  5202. &fw_ddb_entry_dma, GFP_KERNEL);
  5203. if (!fw_ddb_entry) {
  5204. ql4_printk(KERN_ERR, ha,
  5205. "%s: Unable to allocate dma buffer\n", __func__);
  5206. ret = -ENOMEM;
  5207. goto exit_ddb_logout;
  5208. }
  5209. if (test_and_set_bit(DF_DISABLE_RELOGIN, &ddb_entry->flags))
  5210. goto ddb_logout_init;
  5211. ret = qla4xxx_get_fwddb_entry(ha, ddb_entry->fw_ddb_index,
  5212. fw_ddb_entry, fw_ddb_entry_dma,
  5213. NULL, NULL, &ddb_state, NULL,
  5214. NULL, NULL);
  5215. if (ret == QLA_ERROR)
  5216. goto ddb_logout_init;
  5217. if (ddb_state == DDB_DS_SESSION_ACTIVE)
  5218. goto ddb_logout_init;
  5219. /* wait until next relogin is triggered using DF_RELOGIN and
  5220. * clear DF_RELOGIN to avoid invocation of further relogin
  5221. */
  5222. wtime = jiffies + (HZ * RELOGIN_TOV);
  5223. do {
  5224. if (test_and_clear_bit(DF_RELOGIN, &ddb_entry->flags))
  5225. goto ddb_logout_init;
  5226. schedule_timeout_uninterruptible(HZ);
  5227. } while ((time_after(wtime, jiffies)));
  5228. ddb_logout_init:
  5229. atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
  5230. atomic_set(&ddb_entry->relogin_timer, 0);
  5231. options = LOGOUT_OPTION_CLOSE_SESSION;
  5232. qla4xxx_session_logout_ddb(ha, ddb_entry, options);
  5233. memset(fw_ddb_entry, 0, sizeof(*fw_ddb_entry));
  5234. wtime = jiffies + (HZ * LOGOUT_TOV);
  5235. do {
  5236. ret = qla4xxx_get_fwddb_entry(ha, ddb_entry->fw_ddb_index,
  5237. fw_ddb_entry, fw_ddb_entry_dma,
  5238. NULL, NULL, &ddb_state, NULL,
  5239. NULL, NULL);
  5240. if (ret == QLA_ERROR)
  5241. goto ddb_logout_clr_sess;
  5242. if ((ddb_state == DDB_DS_NO_CONNECTION_ACTIVE) ||
  5243. (ddb_state == DDB_DS_SESSION_FAILED))
  5244. goto ddb_logout_clr_sess;
  5245. schedule_timeout_uninterruptible(HZ);
  5246. } while ((time_after(wtime, jiffies)));
  5247. ddb_logout_clr_sess:
  5248. qla4xxx_clear_ddb_entry(ha, ddb_entry->fw_ddb_index);
  5249. /*
  5250. * we have decremented the reference count of the driver
  5251. * when we setup the session to have the driver unload
  5252. * to be seamless without actually destroying the
  5253. * session
  5254. **/
  5255. try_module_get(qla4xxx_iscsi_transport.owner);
  5256. iscsi_destroy_endpoint(ddb_entry->conn->ep);
  5257. spin_lock_irqsave(&ha->hardware_lock, flags);
  5258. qla4xxx_free_ddb(ha, ddb_entry);
  5259. clear_bit(ddb_entry->fw_ddb_index, ha->ddb_idx_map);
  5260. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  5261. iscsi_session_teardown(ddb_entry->sess);
  5262. clear_bit(DF_DISABLE_RELOGIN, &ddb_entry->flags);
  5263. ret = QLA_SUCCESS;
  5264. exit_ddb_logout:
  5265. if (fw_ddb_entry)
  5266. dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
  5267. fw_ddb_entry, fw_ddb_entry_dma);
  5268. return ret;
  5269. }
  5270. /**
  5271. * qla4xxx_sysfs_ddb_logout - Logout from the specified target
  5272. * @fnode_sess: pointer to session attrs of flash ddb entry
  5273. * @fnode_conn: pointer to connection attrs of flash ddb entry
  5274. *
  5275. * This performs log out from the specified target
  5276. **/
  5277. static int qla4xxx_sysfs_ddb_logout(struct iscsi_bus_flash_session *fnode_sess,
  5278. struct iscsi_bus_flash_conn *fnode_conn)
  5279. {
  5280. struct Scsi_Host *shost = iscsi_flash_session_to_shost(fnode_sess);
  5281. struct scsi_qla_host *ha = to_qla_host(shost);
  5282. struct ql4_tuple_ddb *flash_tddb = NULL;
  5283. struct ql4_tuple_ddb *tmp_tddb = NULL;
  5284. struct dev_db_entry *fw_ddb_entry = NULL;
  5285. struct ddb_entry *ddb_entry = NULL;
  5286. dma_addr_t fw_ddb_dma;
  5287. uint32_t next_idx = 0;
  5288. uint32_t state = 0, conn_err = 0;
  5289. uint16_t conn_id = 0;
  5290. int idx, index;
  5291. int status, ret = 0;
  5292. fw_ddb_entry = dma_pool_alloc(ha->fw_ddb_dma_pool, GFP_KERNEL,
  5293. &fw_ddb_dma);
  5294. if (fw_ddb_entry == NULL) {
  5295. ql4_printk(KERN_ERR, ha, "%s:Out of memory\n", __func__);
  5296. ret = -ENOMEM;
  5297. goto exit_ddb_logout;
  5298. }
  5299. flash_tddb = vzalloc(sizeof(*flash_tddb));
  5300. if (!flash_tddb) {
  5301. ql4_printk(KERN_WARNING, ha,
  5302. "%s:Memory Allocation failed.\n", __func__);
  5303. ret = -ENOMEM;
  5304. goto exit_ddb_logout;
  5305. }
  5306. tmp_tddb = vzalloc(sizeof(*tmp_tddb));
  5307. if (!tmp_tddb) {
  5308. ql4_printk(KERN_WARNING, ha,
  5309. "%s:Memory Allocation failed.\n", __func__);
  5310. ret = -ENOMEM;
  5311. goto exit_ddb_logout;
  5312. }
  5313. if (!fnode_sess->targetname) {
  5314. ql4_printk(KERN_ERR, ha,
  5315. "%s:Cannot logout from SendTarget entry\n",
  5316. __func__);
  5317. ret = -EPERM;
  5318. goto exit_ddb_logout;
  5319. }
  5320. if (fnode_sess->is_boot_target) {
  5321. ql4_printk(KERN_ERR, ha,
  5322. "%s: Logout from boot target entry is not permitted.\n",
  5323. __func__);
  5324. ret = -EPERM;
  5325. goto exit_ddb_logout;
  5326. }
  5327. strncpy(flash_tddb->iscsi_name, fnode_sess->targetname,
  5328. ISCSI_NAME_SIZE);
  5329. if (!strncmp(fnode_sess->portal_type, PORTAL_TYPE_IPV6, 4))
  5330. sprintf(flash_tddb->ip_addr, "%pI6", fnode_conn->ipaddress);
  5331. else
  5332. sprintf(flash_tddb->ip_addr, "%pI4", fnode_conn->ipaddress);
  5333. flash_tddb->tpgt = fnode_sess->tpgt;
  5334. flash_tddb->port = fnode_conn->port;
  5335. COPY_ISID(flash_tddb->isid, fnode_sess->isid);
  5336. for (idx = 0; idx < MAX_DDB_ENTRIES; idx++) {
  5337. ddb_entry = qla4xxx_lookup_ddb_by_fw_index(ha, idx);
  5338. if (ddb_entry == NULL)
  5339. continue;
  5340. if (ddb_entry->ddb_type != FLASH_DDB)
  5341. continue;
  5342. index = ddb_entry->sess->target_id;
  5343. status = qla4xxx_get_fwddb_entry(ha, index, fw_ddb_entry,
  5344. fw_ddb_dma, NULL, &next_idx,
  5345. &state, &conn_err, NULL,
  5346. &conn_id);
  5347. if (status == QLA_ERROR) {
  5348. ret = -ENOMEM;
  5349. break;
  5350. }
  5351. qla4xxx_convert_param_ddb(fw_ddb_entry, tmp_tddb, NULL);
  5352. status = qla4xxx_compare_tuple_ddb(ha, flash_tddb, tmp_tddb,
  5353. true);
  5354. if (status == QLA_SUCCESS) {
  5355. ret = qla4xxx_sysfs_ddb_logout_sid(ddb_entry->sess);
  5356. break;
  5357. }
  5358. }
  5359. if (idx == MAX_DDB_ENTRIES)
  5360. ret = -ESRCH;
  5361. exit_ddb_logout:
  5362. if (flash_tddb)
  5363. vfree(flash_tddb);
  5364. if (tmp_tddb)
  5365. vfree(tmp_tddb);
  5366. if (fw_ddb_entry)
  5367. dma_pool_free(ha->fw_ddb_dma_pool, fw_ddb_entry, fw_ddb_dma);
  5368. return ret;
  5369. }
  5370. static int
  5371. qla4xxx_sysfs_ddb_get_param(struct iscsi_bus_flash_session *fnode_sess,
  5372. int param, char *buf)
  5373. {
  5374. struct Scsi_Host *shost = iscsi_flash_session_to_shost(fnode_sess);
  5375. struct scsi_qla_host *ha = to_qla_host(shost);
  5376. struct iscsi_bus_flash_conn *fnode_conn;
  5377. struct ql4_chap_table chap_tbl;
  5378. struct device *dev;
  5379. int parent_type, parent_index = 0xffff;
  5380. int rc = 0;
  5381. dev = iscsi_find_flashnode_conn(fnode_sess);
  5382. if (!dev)
  5383. return -EIO;
  5384. fnode_conn = iscsi_dev_to_flash_conn(dev);
  5385. switch (param) {
  5386. case ISCSI_FLASHNODE_IS_FW_ASSIGNED_IPV6:
  5387. rc = sprintf(buf, "%u\n", fnode_conn->is_fw_assigned_ipv6);
  5388. break;
  5389. case ISCSI_FLASHNODE_PORTAL_TYPE:
  5390. rc = sprintf(buf, "%s\n", fnode_sess->portal_type);
  5391. break;
  5392. case ISCSI_FLASHNODE_AUTO_SND_TGT_DISABLE:
  5393. rc = sprintf(buf, "%u\n", fnode_sess->auto_snd_tgt_disable);
  5394. break;
  5395. case ISCSI_FLASHNODE_DISCOVERY_SESS:
  5396. rc = sprintf(buf, "%u\n", fnode_sess->discovery_sess);
  5397. break;
  5398. case ISCSI_FLASHNODE_ENTRY_EN:
  5399. rc = sprintf(buf, "%u\n", fnode_sess->entry_state);
  5400. break;
  5401. case ISCSI_FLASHNODE_HDR_DGST_EN:
  5402. rc = sprintf(buf, "%u\n", fnode_conn->hdrdgst_en);
  5403. break;
  5404. case ISCSI_FLASHNODE_DATA_DGST_EN:
  5405. rc = sprintf(buf, "%u\n", fnode_conn->datadgst_en);
  5406. break;
  5407. case ISCSI_FLASHNODE_IMM_DATA_EN:
  5408. rc = sprintf(buf, "%u\n", fnode_sess->imm_data_en);
  5409. break;
  5410. case ISCSI_FLASHNODE_INITIAL_R2T_EN:
  5411. rc = sprintf(buf, "%u\n", fnode_sess->initial_r2t_en);
  5412. break;
  5413. case ISCSI_FLASHNODE_DATASEQ_INORDER:
  5414. rc = sprintf(buf, "%u\n", fnode_sess->dataseq_inorder_en);
  5415. break;
  5416. case ISCSI_FLASHNODE_PDU_INORDER:
  5417. rc = sprintf(buf, "%u\n", fnode_sess->pdu_inorder_en);
  5418. break;
  5419. case ISCSI_FLASHNODE_CHAP_AUTH_EN:
  5420. rc = sprintf(buf, "%u\n", fnode_sess->chap_auth_en);
  5421. break;
  5422. case ISCSI_FLASHNODE_SNACK_REQ_EN:
  5423. rc = sprintf(buf, "%u\n", fnode_conn->snack_req_en);
  5424. break;
  5425. case ISCSI_FLASHNODE_DISCOVERY_LOGOUT_EN:
  5426. rc = sprintf(buf, "%u\n", fnode_sess->discovery_logout_en);
  5427. break;
  5428. case ISCSI_FLASHNODE_BIDI_CHAP_EN:
  5429. rc = sprintf(buf, "%u\n", fnode_sess->bidi_chap_en);
  5430. break;
  5431. case ISCSI_FLASHNODE_DISCOVERY_AUTH_OPTIONAL:
  5432. rc = sprintf(buf, "%u\n", fnode_sess->discovery_auth_optional);
  5433. break;
  5434. case ISCSI_FLASHNODE_ERL:
  5435. rc = sprintf(buf, "%u\n", fnode_sess->erl);
  5436. break;
  5437. case ISCSI_FLASHNODE_TCP_TIMESTAMP_STAT:
  5438. rc = sprintf(buf, "%u\n", fnode_conn->tcp_timestamp_stat);
  5439. break;
  5440. case ISCSI_FLASHNODE_TCP_NAGLE_DISABLE:
  5441. rc = sprintf(buf, "%u\n", fnode_conn->tcp_nagle_disable);
  5442. break;
  5443. case ISCSI_FLASHNODE_TCP_WSF_DISABLE:
  5444. rc = sprintf(buf, "%u\n", fnode_conn->tcp_wsf_disable);
  5445. break;
  5446. case ISCSI_FLASHNODE_TCP_TIMER_SCALE:
  5447. rc = sprintf(buf, "%u\n", fnode_conn->tcp_timer_scale);
  5448. break;
  5449. case ISCSI_FLASHNODE_TCP_TIMESTAMP_EN:
  5450. rc = sprintf(buf, "%u\n", fnode_conn->tcp_timestamp_en);
  5451. break;
  5452. case ISCSI_FLASHNODE_IP_FRAG_DISABLE:
  5453. rc = sprintf(buf, "%u\n", fnode_conn->fragment_disable);
  5454. break;
  5455. case ISCSI_FLASHNODE_MAX_RECV_DLENGTH:
  5456. rc = sprintf(buf, "%u\n", fnode_conn->max_recv_dlength);
  5457. break;
  5458. case ISCSI_FLASHNODE_MAX_XMIT_DLENGTH:
  5459. rc = sprintf(buf, "%u\n", fnode_conn->max_xmit_dlength);
  5460. break;
  5461. case ISCSI_FLASHNODE_FIRST_BURST:
  5462. rc = sprintf(buf, "%u\n", fnode_sess->first_burst);
  5463. break;
  5464. case ISCSI_FLASHNODE_DEF_TIME2WAIT:
  5465. rc = sprintf(buf, "%u\n", fnode_sess->time2wait);
  5466. break;
  5467. case ISCSI_FLASHNODE_DEF_TIME2RETAIN:
  5468. rc = sprintf(buf, "%u\n", fnode_sess->time2retain);
  5469. break;
  5470. case ISCSI_FLASHNODE_MAX_R2T:
  5471. rc = sprintf(buf, "%u\n", fnode_sess->max_r2t);
  5472. break;
  5473. case ISCSI_FLASHNODE_KEEPALIVE_TMO:
  5474. rc = sprintf(buf, "%u\n", fnode_conn->keepalive_timeout);
  5475. break;
  5476. case ISCSI_FLASHNODE_ISID:
  5477. rc = sprintf(buf, "%02x%02x%02x%02x%02x%02x\n",
  5478. fnode_sess->isid[0], fnode_sess->isid[1],
  5479. fnode_sess->isid[2], fnode_sess->isid[3],
  5480. fnode_sess->isid[4], fnode_sess->isid[5]);
  5481. break;
  5482. case ISCSI_FLASHNODE_TSID:
  5483. rc = sprintf(buf, "%u\n", fnode_sess->tsid);
  5484. break;
  5485. case ISCSI_FLASHNODE_PORT:
  5486. rc = sprintf(buf, "%d\n", fnode_conn->port);
  5487. break;
  5488. case ISCSI_FLASHNODE_MAX_BURST:
  5489. rc = sprintf(buf, "%u\n", fnode_sess->max_burst);
  5490. break;
  5491. case ISCSI_FLASHNODE_DEF_TASKMGMT_TMO:
  5492. rc = sprintf(buf, "%u\n",
  5493. fnode_sess->default_taskmgmt_timeout);
  5494. break;
  5495. case ISCSI_FLASHNODE_IPADDR:
  5496. if (!strncmp(fnode_sess->portal_type, PORTAL_TYPE_IPV6, 4))
  5497. rc = sprintf(buf, "%pI6\n", fnode_conn->ipaddress);
  5498. else
  5499. rc = sprintf(buf, "%pI4\n", fnode_conn->ipaddress);
  5500. break;
  5501. case ISCSI_FLASHNODE_ALIAS:
  5502. if (fnode_sess->targetalias)
  5503. rc = sprintf(buf, "%s\n", fnode_sess->targetalias);
  5504. else
  5505. rc = sprintf(buf, "\n");
  5506. break;
  5507. case ISCSI_FLASHNODE_REDIRECT_IPADDR:
  5508. if (!strncmp(fnode_sess->portal_type, PORTAL_TYPE_IPV6, 4))
  5509. rc = sprintf(buf, "%pI6\n",
  5510. fnode_conn->redirect_ipaddr);
  5511. else
  5512. rc = sprintf(buf, "%pI4\n",
  5513. fnode_conn->redirect_ipaddr);
  5514. break;
  5515. case ISCSI_FLASHNODE_MAX_SEGMENT_SIZE:
  5516. rc = sprintf(buf, "%u\n", fnode_conn->max_segment_size);
  5517. break;
  5518. case ISCSI_FLASHNODE_LOCAL_PORT:
  5519. rc = sprintf(buf, "%u\n", fnode_conn->local_port);
  5520. break;
  5521. case ISCSI_FLASHNODE_IPV4_TOS:
  5522. rc = sprintf(buf, "%u\n", fnode_conn->ipv4_tos);
  5523. break;
  5524. case ISCSI_FLASHNODE_IPV6_TC:
  5525. if (!strncmp(fnode_sess->portal_type, PORTAL_TYPE_IPV6, 4))
  5526. rc = sprintf(buf, "%u\n",
  5527. fnode_conn->ipv6_traffic_class);
  5528. else
  5529. rc = sprintf(buf, "\n");
  5530. break;
  5531. case ISCSI_FLASHNODE_IPV6_FLOW_LABEL:
  5532. rc = sprintf(buf, "%u\n", fnode_conn->ipv6_flow_label);
  5533. break;
  5534. case ISCSI_FLASHNODE_LINK_LOCAL_IPV6:
  5535. if (!strncmp(fnode_sess->portal_type, PORTAL_TYPE_IPV6, 4))
  5536. rc = sprintf(buf, "%pI6\n",
  5537. fnode_conn->link_local_ipv6_addr);
  5538. else
  5539. rc = sprintf(buf, "\n");
  5540. break;
  5541. case ISCSI_FLASHNODE_DISCOVERY_PARENT_IDX:
  5542. if (fnode_sess->discovery_parent_idx < MAX_DDB_ENTRIES)
  5543. parent_index = fnode_sess->discovery_parent_idx;
  5544. rc = sprintf(buf, "%u\n", parent_index);
  5545. break;
  5546. case ISCSI_FLASHNODE_DISCOVERY_PARENT_TYPE:
  5547. if (fnode_sess->discovery_parent_type == DDB_ISNS)
  5548. parent_type = ISCSI_DISC_PARENT_ISNS;
  5549. else if (fnode_sess->discovery_parent_type == DDB_NO_LINK)
  5550. parent_type = ISCSI_DISC_PARENT_UNKNOWN;
  5551. else if (fnode_sess->discovery_parent_type < MAX_DDB_ENTRIES)
  5552. parent_type = ISCSI_DISC_PARENT_SENDTGT;
  5553. else
  5554. parent_type = ISCSI_DISC_PARENT_UNKNOWN;
  5555. rc = sprintf(buf, "%s\n",
  5556. iscsi_get_discovery_parent_name(parent_type));
  5557. break;
  5558. case ISCSI_FLASHNODE_NAME:
  5559. if (fnode_sess->targetname)
  5560. rc = sprintf(buf, "%s\n", fnode_sess->targetname);
  5561. else
  5562. rc = sprintf(buf, "\n");
  5563. break;
  5564. case ISCSI_FLASHNODE_TPGT:
  5565. rc = sprintf(buf, "%u\n", fnode_sess->tpgt);
  5566. break;
  5567. case ISCSI_FLASHNODE_TCP_XMIT_WSF:
  5568. rc = sprintf(buf, "%u\n", fnode_conn->tcp_xmit_wsf);
  5569. break;
  5570. case ISCSI_FLASHNODE_TCP_RECV_WSF:
  5571. rc = sprintf(buf, "%u\n", fnode_conn->tcp_recv_wsf);
  5572. break;
  5573. case ISCSI_FLASHNODE_CHAP_OUT_IDX:
  5574. rc = sprintf(buf, "%u\n", fnode_sess->chap_out_idx);
  5575. break;
  5576. case ISCSI_FLASHNODE_USERNAME:
  5577. if (fnode_sess->chap_auth_en) {
  5578. qla4xxx_get_uni_chap_at_index(ha,
  5579. chap_tbl.name,
  5580. chap_tbl.secret,
  5581. fnode_sess->chap_out_idx);
  5582. rc = sprintf(buf, "%s\n", chap_tbl.name);
  5583. } else {
  5584. rc = sprintf(buf, "\n");
  5585. }
  5586. break;
  5587. case ISCSI_FLASHNODE_PASSWORD:
  5588. if (fnode_sess->chap_auth_en) {
  5589. qla4xxx_get_uni_chap_at_index(ha,
  5590. chap_tbl.name,
  5591. chap_tbl.secret,
  5592. fnode_sess->chap_out_idx);
  5593. rc = sprintf(buf, "%s\n", chap_tbl.secret);
  5594. } else {
  5595. rc = sprintf(buf, "\n");
  5596. }
  5597. break;
  5598. case ISCSI_FLASHNODE_STATSN:
  5599. rc = sprintf(buf, "%u\n", fnode_conn->statsn);
  5600. break;
  5601. case ISCSI_FLASHNODE_EXP_STATSN:
  5602. rc = sprintf(buf, "%u\n", fnode_conn->exp_statsn);
  5603. break;
  5604. case ISCSI_FLASHNODE_IS_BOOT_TGT:
  5605. rc = sprintf(buf, "%u\n", fnode_sess->is_boot_target);
  5606. break;
  5607. default:
  5608. rc = -ENOSYS;
  5609. break;
  5610. }
  5611. put_device(dev);
  5612. return rc;
  5613. }
  5614. /**
  5615. * qla4xxx_sysfs_ddb_set_param - Set parameter for firmware DDB entry
  5616. * @fnode_sess: pointer to session attrs of flash ddb entry
  5617. * @fnode_conn: pointer to connection attrs of flash ddb entry
  5618. * @data: Parameters and their values to update
  5619. * @len: len of data
  5620. *
  5621. * This sets the parameter of flash ddb entry and writes them to flash
  5622. **/
  5623. static int
  5624. qla4xxx_sysfs_ddb_set_param(struct iscsi_bus_flash_session *fnode_sess,
  5625. struct iscsi_bus_flash_conn *fnode_conn,
  5626. void *data, int len)
  5627. {
  5628. struct Scsi_Host *shost = iscsi_flash_session_to_shost(fnode_sess);
  5629. struct scsi_qla_host *ha = to_qla_host(shost);
  5630. struct iscsi_flashnode_param_info *fnode_param;
  5631. struct nlattr *attr;
  5632. int rc = QLA_ERROR;
  5633. uint32_t rem = len;
  5634. nla_for_each_attr(attr, data, len, rem) {
  5635. fnode_param = nla_data(attr);
  5636. switch (fnode_param->param) {
  5637. case ISCSI_FLASHNODE_IS_FW_ASSIGNED_IPV6:
  5638. fnode_conn->is_fw_assigned_ipv6 = fnode_param->value[0];
  5639. break;
  5640. case ISCSI_FLASHNODE_PORTAL_TYPE:
  5641. memcpy(fnode_sess->portal_type, fnode_param->value,
  5642. strlen(fnode_sess->portal_type));
  5643. break;
  5644. case ISCSI_FLASHNODE_AUTO_SND_TGT_DISABLE:
  5645. fnode_sess->auto_snd_tgt_disable =
  5646. fnode_param->value[0];
  5647. break;
  5648. case ISCSI_FLASHNODE_DISCOVERY_SESS:
  5649. fnode_sess->discovery_sess = fnode_param->value[0];
  5650. break;
  5651. case ISCSI_FLASHNODE_ENTRY_EN:
  5652. fnode_sess->entry_state = fnode_param->value[0];
  5653. break;
  5654. case ISCSI_FLASHNODE_HDR_DGST_EN:
  5655. fnode_conn->hdrdgst_en = fnode_param->value[0];
  5656. break;
  5657. case ISCSI_FLASHNODE_DATA_DGST_EN:
  5658. fnode_conn->datadgst_en = fnode_param->value[0];
  5659. break;
  5660. case ISCSI_FLASHNODE_IMM_DATA_EN:
  5661. fnode_sess->imm_data_en = fnode_param->value[0];
  5662. break;
  5663. case ISCSI_FLASHNODE_INITIAL_R2T_EN:
  5664. fnode_sess->initial_r2t_en = fnode_param->value[0];
  5665. break;
  5666. case ISCSI_FLASHNODE_DATASEQ_INORDER:
  5667. fnode_sess->dataseq_inorder_en = fnode_param->value[0];
  5668. break;
  5669. case ISCSI_FLASHNODE_PDU_INORDER:
  5670. fnode_sess->pdu_inorder_en = fnode_param->value[0];
  5671. break;
  5672. case ISCSI_FLASHNODE_CHAP_AUTH_EN:
  5673. fnode_sess->chap_auth_en = fnode_param->value[0];
  5674. break;
  5675. case ISCSI_FLASHNODE_SNACK_REQ_EN:
  5676. fnode_conn->snack_req_en = fnode_param->value[0];
  5677. break;
  5678. case ISCSI_FLASHNODE_DISCOVERY_LOGOUT_EN:
  5679. fnode_sess->discovery_logout_en = fnode_param->value[0];
  5680. break;
  5681. case ISCSI_FLASHNODE_BIDI_CHAP_EN:
  5682. fnode_sess->bidi_chap_en = fnode_param->value[0];
  5683. break;
  5684. case ISCSI_FLASHNODE_DISCOVERY_AUTH_OPTIONAL:
  5685. fnode_sess->discovery_auth_optional =
  5686. fnode_param->value[0];
  5687. break;
  5688. case ISCSI_FLASHNODE_ERL:
  5689. fnode_sess->erl = fnode_param->value[0];
  5690. break;
  5691. case ISCSI_FLASHNODE_TCP_TIMESTAMP_STAT:
  5692. fnode_conn->tcp_timestamp_stat = fnode_param->value[0];
  5693. break;
  5694. case ISCSI_FLASHNODE_TCP_NAGLE_DISABLE:
  5695. fnode_conn->tcp_nagle_disable = fnode_param->value[0];
  5696. break;
  5697. case ISCSI_FLASHNODE_TCP_WSF_DISABLE:
  5698. fnode_conn->tcp_wsf_disable = fnode_param->value[0];
  5699. break;
  5700. case ISCSI_FLASHNODE_TCP_TIMER_SCALE:
  5701. fnode_conn->tcp_timer_scale = fnode_param->value[0];
  5702. break;
  5703. case ISCSI_FLASHNODE_TCP_TIMESTAMP_EN:
  5704. fnode_conn->tcp_timestamp_en = fnode_param->value[0];
  5705. break;
  5706. case ISCSI_FLASHNODE_IP_FRAG_DISABLE:
  5707. fnode_conn->fragment_disable = fnode_param->value[0];
  5708. break;
  5709. case ISCSI_FLASHNODE_MAX_RECV_DLENGTH:
  5710. fnode_conn->max_recv_dlength =
  5711. *(unsigned *)fnode_param->value;
  5712. break;
  5713. case ISCSI_FLASHNODE_MAX_XMIT_DLENGTH:
  5714. fnode_conn->max_xmit_dlength =
  5715. *(unsigned *)fnode_param->value;
  5716. break;
  5717. case ISCSI_FLASHNODE_FIRST_BURST:
  5718. fnode_sess->first_burst =
  5719. *(unsigned *)fnode_param->value;
  5720. break;
  5721. case ISCSI_FLASHNODE_DEF_TIME2WAIT:
  5722. fnode_sess->time2wait = *(uint16_t *)fnode_param->value;
  5723. break;
  5724. case ISCSI_FLASHNODE_DEF_TIME2RETAIN:
  5725. fnode_sess->time2retain =
  5726. *(uint16_t *)fnode_param->value;
  5727. break;
  5728. case ISCSI_FLASHNODE_MAX_R2T:
  5729. fnode_sess->max_r2t =
  5730. *(uint16_t *)fnode_param->value;
  5731. break;
  5732. case ISCSI_FLASHNODE_KEEPALIVE_TMO:
  5733. fnode_conn->keepalive_timeout =
  5734. *(uint16_t *)fnode_param->value;
  5735. break;
  5736. case ISCSI_FLASHNODE_ISID:
  5737. memcpy(fnode_sess->isid, fnode_param->value,
  5738. sizeof(fnode_sess->isid));
  5739. break;
  5740. case ISCSI_FLASHNODE_TSID:
  5741. fnode_sess->tsid = *(uint16_t *)fnode_param->value;
  5742. break;
  5743. case ISCSI_FLASHNODE_PORT:
  5744. fnode_conn->port = *(uint16_t *)fnode_param->value;
  5745. break;
  5746. case ISCSI_FLASHNODE_MAX_BURST:
  5747. fnode_sess->max_burst = *(unsigned *)fnode_param->value;
  5748. break;
  5749. case ISCSI_FLASHNODE_DEF_TASKMGMT_TMO:
  5750. fnode_sess->default_taskmgmt_timeout =
  5751. *(uint16_t *)fnode_param->value;
  5752. break;
  5753. case ISCSI_FLASHNODE_IPADDR:
  5754. memcpy(fnode_conn->ipaddress, fnode_param->value,
  5755. IPv6_ADDR_LEN);
  5756. break;
  5757. case ISCSI_FLASHNODE_ALIAS:
  5758. rc = iscsi_switch_str_param(&fnode_sess->targetalias,
  5759. (char *)fnode_param->value);
  5760. break;
  5761. case ISCSI_FLASHNODE_REDIRECT_IPADDR:
  5762. memcpy(fnode_conn->redirect_ipaddr, fnode_param->value,
  5763. IPv6_ADDR_LEN);
  5764. break;
  5765. case ISCSI_FLASHNODE_MAX_SEGMENT_SIZE:
  5766. fnode_conn->max_segment_size =
  5767. *(unsigned *)fnode_param->value;
  5768. break;
  5769. case ISCSI_FLASHNODE_LOCAL_PORT:
  5770. fnode_conn->local_port =
  5771. *(uint16_t *)fnode_param->value;
  5772. break;
  5773. case ISCSI_FLASHNODE_IPV4_TOS:
  5774. fnode_conn->ipv4_tos = fnode_param->value[0];
  5775. break;
  5776. case ISCSI_FLASHNODE_IPV6_TC:
  5777. fnode_conn->ipv6_traffic_class = fnode_param->value[0];
  5778. break;
  5779. case ISCSI_FLASHNODE_IPV6_FLOW_LABEL:
  5780. fnode_conn->ipv6_flow_label = fnode_param->value[0];
  5781. break;
  5782. case ISCSI_FLASHNODE_NAME:
  5783. rc = iscsi_switch_str_param(&fnode_sess->targetname,
  5784. (char *)fnode_param->value);
  5785. break;
  5786. case ISCSI_FLASHNODE_TPGT:
  5787. fnode_sess->tpgt = *(uint16_t *)fnode_param->value;
  5788. break;
  5789. case ISCSI_FLASHNODE_LINK_LOCAL_IPV6:
  5790. memcpy(fnode_conn->link_local_ipv6_addr,
  5791. fnode_param->value, IPv6_ADDR_LEN);
  5792. break;
  5793. case ISCSI_FLASHNODE_DISCOVERY_PARENT_TYPE:
  5794. fnode_sess->discovery_parent_type =
  5795. *(uint16_t *)fnode_param->value;
  5796. break;
  5797. case ISCSI_FLASHNODE_TCP_XMIT_WSF:
  5798. fnode_conn->tcp_xmit_wsf =
  5799. *(uint8_t *)fnode_param->value;
  5800. break;
  5801. case ISCSI_FLASHNODE_TCP_RECV_WSF:
  5802. fnode_conn->tcp_recv_wsf =
  5803. *(uint8_t *)fnode_param->value;
  5804. break;
  5805. case ISCSI_FLASHNODE_STATSN:
  5806. fnode_conn->statsn = *(uint32_t *)fnode_param->value;
  5807. break;
  5808. case ISCSI_FLASHNODE_EXP_STATSN:
  5809. fnode_conn->exp_statsn =
  5810. *(uint32_t *)fnode_param->value;
  5811. break;
  5812. default:
  5813. ql4_printk(KERN_ERR, ha,
  5814. "%s: No such sysfs attribute\n", __func__);
  5815. rc = -ENOSYS;
  5816. goto exit_set_param;
  5817. }
  5818. }
  5819. rc = qla4xxx_sysfs_ddb_apply(fnode_sess, fnode_conn);
  5820. exit_set_param:
  5821. return rc;
  5822. }
  5823. /**
  5824. * qla4xxx_sysfs_ddb_delete - Delete firmware DDB entry
  5825. * @fnode_sess: pointer to session attrs of flash ddb entry
  5826. *
  5827. * This invalidates the flash ddb entry at the given index
  5828. **/
  5829. static int qla4xxx_sysfs_ddb_delete(struct iscsi_bus_flash_session *fnode_sess)
  5830. {
  5831. struct Scsi_Host *shost = iscsi_flash_session_to_shost(fnode_sess);
  5832. struct scsi_qla_host *ha = to_qla_host(shost);
  5833. uint32_t dev_db_start_offset;
  5834. uint32_t dev_db_end_offset;
  5835. struct dev_db_entry *fw_ddb_entry = NULL;
  5836. dma_addr_t fw_ddb_entry_dma;
  5837. uint16_t *ddb_cookie = NULL;
  5838. size_t ddb_size = 0;
  5839. void *pddb = NULL;
  5840. int target_id;
  5841. int rc = 0;
  5842. if (fnode_sess->is_boot_target) {
  5843. rc = -EPERM;
  5844. DEBUG2(ql4_printk(KERN_ERR, ha,
  5845. "%s: Deletion of boot target entry is not permitted.\n",
  5846. __func__));
  5847. goto exit_ddb_del;
  5848. }
  5849. if (fnode_sess->flash_state == DEV_DB_NON_PERSISTENT)
  5850. goto sysfs_ddb_del;
  5851. if (is_qla40XX(ha)) {
  5852. dev_db_start_offset = FLASH_OFFSET_DB_INFO;
  5853. dev_db_end_offset = FLASH_OFFSET_DB_END;
  5854. dev_db_start_offset += (fnode_sess->target_id *
  5855. sizeof(*fw_ddb_entry));
  5856. ddb_size = sizeof(*fw_ddb_entry);
  5857. } else {
  5858. dev_db_start_offset = FLASH_RAW_ACCESS_ADDR +
  5859. (ha->hw.flt_region_ddb << 2);
  5860. /* flt_ddb_size is DDB table size for both ports
  5861. * so divide it by 2 to calculate the offset for second port
  5862. */
  5863. if (ha->port_num == 1)
  5864. dev_db_start_offset += (ha->hw.flt_ddb_size / 2);
  5865. dev_db_end_offset = dev_db_start_offset +
  5866. (ha->hw.flt_ddb_size / 2);
  5867. dev_db_start_offset += (fnode_sess->target_id *
  5868. sizeof(*fw_ddb_entry));
  5869. dev_db_start_offset += offsetof(struct dev_db_entry, cookie);
  5870. ddb_size = sizeof(*ddb_cookie);
  5871. }
  5872. DEBUG2(ql4_printk(KERN_ERR, ha, "%s: start offset=%u, end offset=%u\n",
  5873. __func__, dev_db_start_offset, dev_db_end_offset));
  5874. if (dev_db_start_offset > dev_db_end_offset) {
  5875. rc = -EIO;
  5876. DEBUG2(ql4_printk(KERN_ERR, ha, "%s:Invalid DDB index %u\n",
  5877. __func__, fnode_sess->target_id));
  5878. goto exit_ddb_del;
  5879. }
  5880. pddb = dma_alloc_coherent(&ha->pdev->dev, ddb_size,
  5881. &fw_ddb_entry_dma, GFP_KERNEL);
  5882. if (!pddb) {
  5883. rc = -ENOMEM;
  5884. DEBUG2(ql4_printk(KERN_ERR, ha,
  5885. "%s: Unable to allocate dma buffer\n",
  5886. __func__));
  5887. goto exit_ddb_del;
  5888. }
  5889. if (is_qla40XX(ha)) {
  5890. fw_ddb_entry = pddb;
  5891. memset(fw_ddb_entry, 0, ddb_size);
  5892. ddb_cookie = &fw_ddb_entry->cookie;
  5893. } else {
  5894. ddb_cookie = pddb;
  5895. }
  5896. /* invalidate the cookie */
  5897. *ddb_cookie = 0xFFEE;
  5898. qla4xxx_set_flash(ha, fw_ddb_entry_dma, dev_db_start_offset,
  5899. ddb_size, FLASH_OPT_RMW_COMMIT);
  5900. sysfs_ddb_del:
  5901. target_id = fnode_sess->target_id;
  5902. iscsi_destroy_flashnode_sess(fnode_sess);
  5903. ql4_printk(KERN_INFO, ha,
  5904. "%s: session and conn entries for flashnode %u of host %lu deleted\n",
  5905. __func__, target_id, ha->host_no);
  5906. exit_ddb_del:
  5907. if (pddb)
  5908. dma_free_coherent(&ha->pdev->dev, ddb_size, pddb,
  5909. fw_ddb_entry_dma);
  5910. return rc;
  5911. }
  5912. /**
  5913. * qla4xxx_sysfs_ddb_export - Create sysfs entries for firmware DDBs
  5914. * @ha: pointer to adapter structure
  5915. *
  5916. * Export the firmware DDB for all send targets and normal targets to sysfs.
  5917. **/
  5918. static int qla4xxx_sysfs_ddb_export(struct scsi_qla_host *ha)
  5919. {
  5920. struct dev_db_entry *fw_ddb_entry = NULL;
  5921. dma_addr_t fw_ddb_entry_dma;
  5922. uint16_t max_ddbs;
  5923. uint16_t idx = 0;
  5924. int ret = QLA_SUCCESS;
  5925. fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev,
  5926. sizeof(*fw_ddb_entry),
  5927. &fw_ddb_entry_dma, GFP_KERNEL);
  5928. if (!fw_ddb_entry) {
  5929. DEBUG2(ql4_printk(KERN_ERR, ha,
  5930. "%s: Unable to allocate dma buffer\n",
  5931. __func__));
  5932. return -ENOMEM;
  5933. }
  5934. max_ddbs = is_qla40XX(ha) ? MAX_PRST_DEV_DB_ENTRIES :
  5935. MAX_DEV_DB_ENTRIES;
  5936. for (idx = 0; idx < max_ddbs; idx++) {
  5937. if (qla4xxx_flashdb_by_index(ha, fw_ddb_entry, fw_ddb_entry_dma,
  5938. idx))
  5939. continue;
  5940. ret = qla4xxx_sysfs_ddb_tgt_create(ha, fw_ddb_entry, &idx, 0);
  5941. if (ret) {
  5942. ret = -EIO;
  5943. break;
  5944. }
  5945. }
  5946. dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry), fw_ddb_entry,
  5947. fw_ddb_entry_dma);
  5948. return ret;
  5949. }
  5950. static void qla4xxx_sysfs_ddb_remove(struct scsi_qla_host *ha)
  5951. {
  5952. iscsi_destroy_all_flashnode(ha->host);
  5953. }
  5954. /**
  5955. * qla4xxx_build_ddb_list - Build ddb list and setup sessions
  5956. * @ha: pointer to adapter structure
  5957. * @is_reset: Is this init path or reset path
  5958. *
  5959. * Create a list of sendtargets (st) from firmware DDBs, issue send targets
  5960. * using connection open, then create the list of normal targets (nt)
  5961. * from firmware DDBs. Based on the list of nt setup session and connection
  5962. * objects.
  5963. **/
  5964. void qla4xxx_build_ddb_list(struct scsi_qla_host *ha, int is_reset)
  5965. {
  5966. uint16_t tmo = 0;
  5967. struct list_head list_st, list_nt;
  5968. struct qla_ddb_index *st_ddb_idx, *st_ddb_idx_tmp;
  5969. unsigned long wtime;
  5970. if (!test_bit(AF_LINK_UP, &ha->flags)) {
  5971. set_bit(AF_BUILD_DDB_LIST, &ha->flags);
  5972. ha->is_reset = is_reset;
  5973. return;
  5974. }
  5975. INIT_LIST_HEAD(&list_st);
  5976. INIT_LIST_HEAD(&list_nt);
  5977. qla4xxx_build_st_list(ha, &list_st);
  5978. /* Before issuing conn open mbox, ensure all IPs states are configured
  5979. * Note, conn open fails if IPs are not configured
  5980. */
  5981. qla4xxx_wait_for_ip_configuration(ha);
  5982. /* Go thru the STs and fire the sendtargets by issuing conn open mbx */
  5983. list_for_each_entry_safe(st_ddb_idx, st_ddb_idx_tmp, &list_st, list) {
  5984. qla4xxx_conn_open(ha, st_ddb_idx->fw_ddb_idx);
  5985. }
  5986. /* Wait to ensure all sendtargets are done for min 12 sec wait */
  5987. tmo = ((ha->def_timeout > LOGIN_TOV) &&
  5988. (ha->def_timeout < LOGIN_TOV * 10) ?
  5989. ha->def_timeout : LOGIN_TOV);
  5990. DEBUG2(ql4_printk(KERN_INFO, ha,
  5991. "Default time to wait for build ddb %d\n", tmo));
  5992. wtime = jiffies + (HZ * tmo);
  5993. do {
  5994. if (list_empty(&list_st))
  5995. break;
  5996. qla4xxx_remove_failed_ddb(ha, &list_st);
  5997. schedule_timeout_uninterruptible(HZ / 10);
  5998. } while (time_after(wtime, jiffies));
  5999. /* Free up the sendtargets list */
  6000. qla4xxx_free_ddb_list(&list_st);
  6001. qla4xxx_build_nt_list(ha, &list_nt, is_reset);
  6002. qla4xxx_free_ddb_list(&list_nt);
  6003. qla4xxx_free_ddb_index(ha);
  6004. }
  6005. /**
  6006. * qla4xxx_wait_login_resp_boot_tgt - Wait for iSCSI boot target login
  6007. * response.
  6008. * @ha: pointer to adapter structure
  6009. *
  6010. * When the boot entry is normal iSCSI target then DF_BOOT_TGT flag will be
  6011. * set in DDB and we will wait for login response of boot targets during
  6012. * probe.
  6013. **/
  6014. static void qla4xxx_wait_login_resp_boot_tgt(struct scsi_qla_host *ha)
  6015. {
  6016. struct ddb_entry *ddb_entry;
  6017. struct dev_db_entry *fw_ddb_entry = NULL;
  6018. dma_addr_t fw_ddb_entry_dma;
  6019. unsigned long wtime;
  6020. uint32_t ddb_state;
  6021. int max_ddbs, idx, ret;
  6022. max_ddbs = is_qla40XX(ha) ? MAX_DEV_DB_ENTRIES_40XX :
  6023. MAX_DEV_DB_ENTRIES;
  6024. fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
  6025. &fw_ddb_entry_dma, GFP_KERNEL);
  6026. if (!fw_ddb_entry) {
  6027. ql4_printk(KERN_ERR, ha,
  6028. "%s: Unable to allocate dma buffer\n", __func__);
  6029. goto exit_login_resp;
  6030. }
  6031. wtime = jiffies + (HZ * BOOT_LOGIN_RESP_TOV);
  6032. for (idx = 0; idx < max_ddbs; idx++) {
  6033. ddb_entry = qla4xxx_lookup_ddb_by_fw_index(ha, idx);
  6034. if (ddb_entry == NULL)
  6035. continue;
  6036. if (test_bit(DF_BOOT_TGT, &ddb_entry->flags)) {
  6037. DEBUG2(ql4_printk(KERN_INFO, ha,
  6038. "%s: DDB index [%d]\n", __func__,
  6039. ddb_entry->fw_ddb_index));
  6040. do {
  6041. ret = qla4xxx_get_fwddb_entry(ha,
  6042. ddb_entry->fw_ddb_index,
  6043. fw_ddb_entry, fw_ddb_entry_dma,
  6044. NULL, NULL, &ddb_state, NULL,
  6045. NULL, NULL);
  6046. if (ret == QLA_ERROR)
  6047. goto exit_login_resp;
  6048. if ((ddb_state == DDB_DS_SESSION_ACTIVE) ||
  6049. (ddb_state == DDB_DS_SESSION_FAILED))
  6050. break;
  6051. schedule_timeout_uninterruptible(HZ);
  6052. } while ((time_after(wtime, jiffies)));
  6053. if (!time_after(wtime, jiffies)) {
  6054. DEBUG2(ql4_printk(KERN_INFO, ha,
  6055. "%s: Login response wait timer expired\n",
  6056. __func__));
  6057. goto exit_login_resp;
  6058. }
  6059. }
  6060. }
  6061. exit_login_resp:
  6062. if (fw_ddb_entry)
  6063. dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
  6064. fw_ddb_entry, fw_ddb_entry_dma);
  6065. }
  6066. /**
  6067. * qla4xxx_probe_adapter - callback function to probe HBA
  6068. * @pdev: pointer to pci_dev structure
  6069. * @pci_device_id: pointer to pci_device entry
  6070. *
  6071. * This routine will probe for Qlogic 4xxx iSCSI host adapters.
  6072. * It returns zero if successful. It also initializes all data necessary for
  6073. * the driver.
  6074. **/
  6075. static int qla4xxx_probe_adapter(struct pci_dev *pdev,
  6076. const struct pci_device_id *ent)
  6077. {
  6078. int ret = -ENODEV, status;
  6079. struct Scsi_Host *host;
  6080. struct scsi_qla_host *ha;
  6081. uint8_t init_retry_count = 0;
  6082. char buf[34];
  6083. struct qla4_8xxx_legacy_intr_set *nx_legacy_intr;
  6084. uint32_t dev_state;
  6085. if (pci_enable_device(pdev))
  6086. return -1;
  6087. host = iscsi_host_alloc(&qla4xxx_driver_template, sizeof(*ha), 0);
  6088. if (host == NULL) {
  6089. printk(KERN_WARNING
  6090. "qla4xxx: Couldn't allocate host from scsi layer!\n");
  6091. goto probe_disable_device;
  6092. }
  6093. /* Clear our data area */
  6094. ha = to_qla_host(host);
  6095. memset(ha, 0, sizeof(*ha));
  6096. /* Save the information from PCI BIOS. */
  6097. ha->pdev = pdev;
  6098. ha->host = host;
  6099. ha->host_no = host->host_no;
  6100. ha->func_num = PCI_FUNC(ha->pdev->devfn);
  6101. pci_enable_pcie_error_reporting(pdev);
  6102. /* Setup Runtime configurable options */
  6103. if (is_qla8022(ha)) {
  6104. ha->isp_ops = &qla4_82xx_isp_ops;
  6105. ha->reg_tbl = (uint32_t *) qla4_82xx_reg_tbl;
  6106. ha->qdr_sn_window = -1;
  6107. ha->ddr_mn_window = -1;
  6108. ha->curr_window = 255;
  6109. nx_legacy_intr = &legacy_intr[ha->func_num];
  6110. ha->nx_legacy_intr.int_vec_bit = nx_legacy_intr->int_vec_bit;
  6111. ha->nx_legacy_intr.tgt_status_reg =
  6112. nx_legacy_intr->tgt_status_reg;
  6113. ha->nx_legacy_intr.tgt_mask_reg = nx_legacy_intr->tgt_mask_reg;
  6114. ha->nx_legacy_intr.pci_int_reg = nx_legacy_intr->pci_int_reg;
  6115. } else if (is_qla8032(ha)) {
  6116. ha->isp_ops = &qla4_83xx_isp_ops;
  6117. ha->reg_tbl = (uint32_t *)qla4_83xx_reg_tbl;
  6118. } else {
  6119. ha->isp_ops = &qla4xxx_isp_ops;
  6120. }
  6121. if (is_qla80XX(ha)) {
  6122. rwlock_init(&ha->hw_lock);
  6123. ha->pf_bit = ha->func_num << 16;
  6124. /* Set EEH reset type to fundamental if required by hba */
  6125. pdev->needs_freset = 1;
  6126. }
  6127. /* Configure PCI I/O space. */
  6128. ret = ha->isp_ops->iospace_config(ha);
  6129. if (ret)
  6130. goto probe_failed_ioconfig;
  6131. ql4_printk(KERN_INFO, ha, "Found an ISP%04x, irq %d, iobase 0x%p\n",
  6132. pdev->device, pdev->irq, ha->reg);
  6133. qla4xxx_config_dma_addressing(ha);
  6134. /* Initialize lists and spinlocks. */
  6135. INIT_LIST_HEAD(&ha->free_srb_q);
  6136. mutex_init(&ha->mbox_sem);
  6137. mutex_init(&ha->chap_sem);
  6138. init_completion(&ha->mbx_intr_comp);
  6139. init_completion(&ha->disable_acb_comp);
  6140. spin_lock_init(&ha->hardware_lock);
  6141. spin_lock_init(&ha->work_lock);
  6142. /* Initialize work list */
  6143. INIT_LIST_HEAD(&ha->work_list);
  6144. /* Allocate dma buffers */
  6145. if (qla4xxx_mem_alloc(ha)) {
  6146. ql4_printk(KERN_WARNING, ha,
  6147. "[ERROR] Failed to allocate memory for adapter\n");
  6148. ret = -ENOMEM;
  6149. goto probe_failed;
  6150. }
  6151. host->cmd_per_lun = 3;
  6152. host->max_channel = 0;
  6153. host->max_lun = MAX_LUNS - 1;
  6154. host->max_id = MAX_TARGETS;
  6155. host->max_cmd_len = IOCB_MAX_CDB_LEN;
  6156. host->can_queue = MAX_SRBS ;
  6157. host->transportt = qla4xxx_scsi_transport;
  6158. ret = scsi_init_shared_tag_map(host, MAX_SRBS);
  6159. if (ret) {
  6160. ql4_printk(KERN_WARNING, ha,
  6161. "%s: scsi_init_shared_tag_map failed\n", __func__);
  6162. goto probe_failed;
  6163. }
  6164. pci_set_drvdata(pdev, ha);
  6165. ret = scsi_add_host(host, &pdev->dev);
  6166. if (ret)
  6167. goto probe_failed;
  6168. if (is_qla80XX(ha))
  6169. qla4_8xxx_get_flash_info(ha);
  6170. if (is_qla8032(ha)) {
  6171. qla4_83xx_read_reset_template(ha);
  6172. /*
  6173. * NOTE: If ql4dontresethba==1, set IDC_CTRL DONTRESET_BIT0.
  6174. * If DONRESET_BIT0 is set, drivers should not set dev_state
  6175. * to NEED_RESET. But if NEED_RESET is set, drivers should
  6176. * should honor the reset.
  6177. */
  6178. if (ql4xdontresethba == 1)
  6179. qla4_83xx_set_idc_dontreset(ha);
  6180. }
  6181. /*
  6182. * Initialize the Host adapter request/response queues and
  6183. * firmware
  6184. * NOTE: interrupts enabled upon successful completion
  6185. */
  6186. status = qla4xxx_initialize_adapter(ha, INIT_ADAPTER);
  6187. /* Dont retry adapter initialization if IRQ allocation failed */
  6188. if (is_qla80XX(ha) && !test_bit(AF_IRQ_ATTACHED, &ha->flags)) {
  6189. ql4_printk(KERN_WARNING, ha, "%s: Skipping retry of adapter initialization\n",
  6190. __func__);
  6191. goto skip_retry_init;
  6192. }
  6193. while ((!test_bit(AF_ONLINE, &ha->flags)) &&
  6194. init_retry_count++ < MAX_INIT_RETRIES) {
  6195. if (is_qla80XX(ha)) {
  6196. ha->isp_ops->idc_lock(ha);
  6197. dev_state = qla4_8xxx_rd_direct(ha,
  6198. QLA8XXX_CRB_DEV_STATE);
  6199. ha->isp_ops->idc_unlock(ha);
  6200. if (dev_state == QLA8XXX_DEV_FAILED) {
  6201. ql4_printk(KERN_WARNING, ha, "%s: don't retry "
  6202. "initialize adapter. H/W is in failed state\n",
  6203. __func__);
  6204. break;
  6205. }
  6206. }
  6207. DEBUG2(printk("scsi: %s: retrying adapter initialization "
  6208. "(%d)\n", __func__, init_retry_count));
  6209. if (ha->isp_ops->reset_chip(ha) == QLA_ERROR)
  6210. continue;
  6211. status = qla4xxx_initialize_adapter(ha, INIT_ADAPTER);
  6212. }
  6213. skip_retry_init:
  6214. if (!test_bit(AF_ONLINE, &ha->flags)) {
  6215. ql4_printk(KERN_WARNING, ha, "Failed to initialize adapter\n");
  6216. if ((is_qla8022(ha) && ql4xdontresethba) ||
  6217. (is_qla8032(ha) && qla4_83xx_idc_dontreset(ha))) {
  6218. /* Put the device in failed state. */
  6219. DEBUG2(printk(KERN_ERR "HW STATE: FAILED\n"));
  6220. ha->isp_ops->idc_lock(ha);
  6221. qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DEV_STATE,
  6222. QLA8XXX_DEV_FAILED);
  6223. ha->isp_ops->idc_unlock(ha);
  6224. }
  6225. ret = -ENODEV;
  6226. goto remove_host;
  6227. }
  6228. /* Startup the kernel thread for this host adapter. */
  6229. DEBUG2(printk("scsi: %s: Starting kernel thread for "
  6230. "qla4xxx_dpc\n", __func__));
  6231. sprintf(buf, "qla4xxx_%lu_dpc", ha->host_no);
  6232. ha->dpc_thread = create_singlethread_workqueue(buf);
  6233. if (!ha->dpc_thread) {
  6234. ql4_printk(KERN_WARNING, ha, "Unable to start DPC thread!\n");
  6235. ret = -ENODEV;
  6236. goto remove_host;
  6237. }
  6238. INIT_WORK(&ha->dpc_work, qla4xxx_do_dpc);
  6239. ha->task_wq = alloc_workqueue("qla4xxx_%lu_task", WQ_MEM_RECLAIM, 1,
  6240. ha->host_no);
  6241. if (!ha->task_wq) {
  6242. ql4_printk(KERN_WARNING, ha, "Unable to start task thread!\n");
  6243. ret = -ENODEV;
  6244. goto remove_host;
  6245. }
  6246. /*
  6247. * For ISP-8XXX, request_irqs is called in qla4_8xxx_load_risc
  6248. * (which is called indirectly by qla4xxx_initialize_adapter),
  6249. * so that irqs will be registered after crbinit but before
  6250. * mbx_intr_enable.
  6251. */
  6252. if (is_qla40XX(ha)) {
  6253. ret = qla4xxx_request_irqs(ha);
  6254. if (ret) {
  6255. ql4_printk(KERN_WARNING, ha, "Failed to reserve "
  6256. "interrupt %d already in use.\n", pdev->irq);
  6257. goto remove_host;
  6258. }
  6259. }
  6260. pci_save_state(ha->pdev);
  6261. ha->isp_ops->enable_intrs(ha);
  6262. /* Start timer thread. */
  6263. qla4xxx_start_timer(ha, qla4xxx_timer, 1);
  6264. set_bit(AF_INIT_DONE, &ha->flags);
  6265. qla4_8xxx_alloc_sysfs_attr(ha);
  6266. printk(KERN_INFO
  6267. " QLogic iSCSI HBA Driver version: %s\n"
  6268. " QLogic ISP%04x @ %s, host#=%ld, fw=%02d.%02d.%02d.%02d\n",
  6269. qla4xxx_version_str, ha->pdev->device, pci_name(ha->pdev),
  6270. ha->host_no, ha->firmware_version[0], ha->firmware_version[1],
  6271. ha->patch_number, ha->build_number);
  6272. /* Set the driver version */
  6273. if (is_qla80XX(ha))
  6274. qla4_8xxx_set_param(ha, SET_DRVR_VERSION);
  6275. if (qla4xxx_setup_boot_info(ha))
  6276. ql4_printk(KERN_ERR, ha,
  6277. "%s: No iSCSI boot target configured\n", __func__);
  6278. if (qla4xxx_sysfs_ddb_export(ha))
  6279. ql4_printk(KERN_ERR, ha,
  6280. "%s: Error exporting ddb to sysfs\n", __func__);
  6281. /* Perform the build ddb list and login to each */
  6282. qla4xxx_build_ddb_list(ha, INIT_ADAPTER);
  6283. iscsi_host_for_each_session(ha->host, qla4xxx_login_flash_ddb);
  6284. qla4xxx_wait_login_resp_boot_tgt(ha);
  6285. qla4xxx_create_chap_list(ha);
  6286. qla4xxx_create_ifaces(ha);
  6287. return 0;
  6288. remove_host:
  6289. scsi_remove_host(ha->host);
  6290. probe_failed:
  6291. qla4xxx_free_adapter(ha);
  6292. probe_failed_ioconfig:
  6293. pci_disable_pcie_error_reporting(pdev);
  6294. scsi_host_put(ha->host);
  6295. probe_disable_device:
  6296. pci_disable_device(pdev);
  6297. return ret;
  6298. }
  6299. /**
  6300. * qla4xxx_prevent_other_port_reinit - prevent other port from re-initialize
  6301. * @ha: pointer to adapter structure
  6302. *
  6303. * Mark the other ISP-4xxx port to indicate that the driver is being removed,
  6304. * so that the other port will not re-initialize while in the process of
  6305. * removing the ha due to driver unload or hba hotplug.
  6306. **/
  6307. static void qla4xxx_prevent_other_port_reinit(struct scsi_qla_host *ha)
  6308. {
  6309. struct scsi_qla_host *other_ha = NULL;
  6310. struct pci_dev *other_pdev = NULL;
  6311. int fn = ISP4XXX_PCI_FN_2;
  6312. /*iscsi function numbers for ISP4xxx is 1 and 3*/
  6313. if (PCI_FUNC(ha->pdev->devfn) & BIT_1)
  6314. fn = ISP4XXX_PCI_FN_1;
  6315. other_pdev =
  6316. pci_get_domain_bus_and_slot(pci_domain_nr(ha->pdev->bus),
  6317. ha->pdev->bus->number, PCI_DEVFN(PCI_SLOT(ha->pdev->devfn),
  6318. fn));
  6319. /* Get other_ha if other_pdev is valid and state is enable*/
  6320. if (other_pdev) {
  6321. if (atomic_read(&other_pdev->enable_cnt)) {
  6322. other_ha = pci_get_drvdata(other_pdev);
  6323. if (other_ha) {
  6324. set_bit(AF_HA_REMOVAL, &other_ha->flags);
  6325. DEBUG2(ql4_printk(KERN_INFO, ha, "%s: "
  6326. "Prevent %s reinit\n", __func__,
  6327. dev_name(&other_ha->pdev->dev)));
  6328. }
  6329. }
  6330. pci_dev_put(other_pdev);
  6331. }
  6332. }
  6333. static void qla4xxx_destroy_fw_ddb_session(struct scsi_qla_host *ha)
  6334. {
  6335. struct ddb_entry *ddb_entry;
  6336. int options;
  6337. int idx;
  6338. for (idx = 0; idx < MAX_DDB_ENTRIES; idx++) {
  6339. ddb_entry = qla4xxx_lookup_ddb_by_fw_index(ha, idx);
  6340. if ((ddb_entry != NULL) &&
  6341. (ddb_entry->ddb_type == FLASH_DDB)) {
  6342. options = LOGOUT_OPTION_CLOSE_SESSION;
  6343. if (qla4xxx_session_logout_ddb(ha, ddb_entry, options)
  6344. == QLA_ERROR)
  6345. ql4_printk(KERN_ERR, ha, "%s: Logout failed\n",
  6346. __func__);
  6347. qla4xxx_clear_ddb_entry(ha, ddb_entry->fw_ddb_index);
  6348. /*
  6349. * we have decremented the reference count of the driver
  6350. * when we setup the session to have the driver unload
  6351. * to be seamless without actually destroying the
  6352. * session
  6353. **/
  6354. try_module_get(qla4xxx_iscsi_transport.owner);
  6355. iscsi_destroy_endpoint(ddb_entry->conn->ep);
  6356. qla4xxx_free_ddb(ha, ddb_entry);
  6357. iscsi_session_teardown(ddb_entry->sess);
  6358. }
  6359. }
  6360. }
  6361. /**
  6362. * qla4xxx_remove_adapter - callback function to remove adapter.
  6363. * @pci_dev: PCI device pointer
  6364. **/
  6365. static void qla4xxx_remove_adapter(struct pci_dev *pdev)
  6366. {
  6367. struct scsi_qla_host *ha;
  6368. /*
  6369. * If the PCI device is disabled then it means probe_adapter had
  6370. * failed and resources already cleaned up on probe_adapter exit.
  6371. */
  6372. if (!pci_is_enabled(pdev))
  6373. return;
  6374. ha = pci_get_drvdata(pdev);
  6375. if (is_qla40XX(ha))
  6376. qla4xxx_prevent_other_port_reinit(ha);
  6377. /* destroy iface from sysfs */
  6378. qla4xxx_destroy_ifaces(ha);
  6379. if ((!ql4xdisablesysfsboot) && ha->boot_kset)
  6380. iscsi_boot_destroy_kset(ha->boot_kset);
  6381. qla4xxx_destroy_fw_ddb_session(ha);
  6382. qla4_8xxx_free_sysfs_attr(ha);
  6383. qla4xxx_sysfs_ddb_remove(ha);
  6384. scsi_remove_host(ha->host);
  6385. qla4xxx_free_adapter(ha);
  6386. scsi_host_put(ha->host);
  6387. pci_disable_pcie_error_reporting(pdev);
  6388. pci_disable_device(pdev);
  6389. pci_set_drvdata(pdev, NULL);
  6390. }
  6391. /**
  6392. * qla4xxx_config_dma_addressing() - Configure OS DMA addressing method.
  6393. * @ha: HA context
  6394. *
  6395. * At exit, the @ha's flags.enable_64bit_addressing set to indicated
  6396. * supported addressing method.
  6397. */
  6398. static void qla4xxx_config_dma_addressing(struct scsi_qla_host *ha)
  6399. {
  6400. int retval;
  6401. /* Update our PCI device dma_mask for full 64 bit mask */
  6402. if (pci_set_dma_mask(ha->pdev, DMA_BIT_MASK(64)) == 0) {
  6403. if (pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(64))) {
  6404. dev_dbg(&ha->pdev->dev,
  6405. "Failed to set 64 bit PCI consistent mask; "
  6406. "using 32 bit.\n");
  6407. retval = pci_set_consistent_dma_mask(ha->pdev,
  6408. DMA_BIT_MASK(32));
  6409. }
  6410. } else
  6411. retval = pci_set_dma_mask(ha->pdev, DMA_BIT_MASK(32));
  6412. }
  6413. static int qla4xxx_slave_alloc(struct scsi_device *sdev)
  6414. {
  6415. struct iscsi_cls_session *cls_sess;
  6416. struct iscsi_session *sess;
  6417. struct ddb_entry *ddb;
  6418. int queue_depth = QL4_DEF_QDEPTH;
  6419. cls_sess = starget_to_session(sdev->sdev_target);
  6420. sess = cls_sess->dd_data;
  6421. ddb = sess->dd_data;
  6422. sdev->hostdata = ddb;
  6423. sdev->tagged_supported = 1;
  6424. if (ql4xmaxqdepth != 0 && ql4xmaxqdepth <= 0xffffU)
  6425. queue_depth = ql4xmaxqdepth;
  6426. scsi_activate_tcq(sdev, queue_depth);
  6427. return 0;
  6428. }
  6429. static int qla4xxx_slave_configure(struct scsi_device *sdev)
  6430. {
  6431. sdev->tagged_supported = 1;
  6432. return 0;
  6433. }
  6434. static void qla4xxx_slave_destroy(struct scsi_device *sdev)
  6435. {
  6436. scsi_deactivate_tcq(sdev, 1);
  6437. }
  6438. static int qla4xxx_change_queue_depth(struct scsi_device *sdev, int qdepth,
  6439. int reason)
  6440. {
  6441. if (!ql4xqfulltracking)
  6442. return -EOPNOTSUPP;
  6443. return iscsi_change_queue_depth(sdev, qdepth, reason);
  6444. }
  6445. /**
  6446. * qla4xxx_del_from_active_array - returns an active srb
  6447. * @ha: Pointer to host adapter structure.
  6448. * @index: index into the active_array
  6449. *
  6450. * This routine removes and returns the srb at the specified index
  6451. **/
  6452. struct srb *qla4xxx_del_from_active_array(struct scsi_qla_host *ha,
  6453. uint32_t index)
  6454. {
  6455. struct srb *srb = NULL;
  6456. struct scsi_cmnd *cmd = NULL;
  6457. cmd = scsi_host_find_tag(ha->host, index);
  6458. if (!cmd)
  6459. return srb;
  6460. srb = (struct srb *)CMD_SP(cmd);
  6461. if (!srb)
  6462. return srb;
  6463. /* update counters */
  6464. if (srb->flags & SRB_DMA_VALID) {
  6465. ha->iocb_cnt -= srb->iocb_cnt;
  6466. if (srb->cmd)
  6467. srb->cmd->host_scribble =
  6468. (unsigned char *)(unsigned long) MAX_SRBS;
  6469. }
  6470. return srb;
  6471. }
  6472. /**
  6473. * qla4xxx_eh_wait_on_command - waits for command to be returned by firmware
  6474. * @ha: Pointer to host adapter structure.
  6475. * @cmd: Scsi Command to wait on.
  6476. *
  6477. * This routine waits for the command to be returned by the Firmware
  6478. * for some max time.
  6479. **/
  6480. static int qla4xxx_eh_wait_on_command(struct scsi_qla_host *ha,
  6481. struct scsi_cmnd *cmd)
  6482. {
  6483. int done = 0;
  6484. struct srb *rp;
  6485. uint32_t max_wait_time = EH_WAIT_CMD_TOV;
  6486. int ret = SUCCESS;
  6487. /* Dont wait on command if PCI error is being handled
  6488. * by PCI AER driver
  6489. */
  6490. if (unlikely(pci_channel_offline(ha->pdev)) ||
  6491. (test_bit(AF_EEH_BUSY, &ha->flags))) {
  6492. ql4_printk(KERN_WARNING, ha, "scsi%ld: Return from %s\n",
  6493. ha->host_no, __func__);
  6494. return ret;
  6495. }
  6496. do {
  6497. /* Checking to see if its returned to OS */
  6498. rp = (struct srb *) CMD_SP(cmd);
  6499. if (rp == NULL) {
  6500. done++;
  6501. break;
  6502. }
  6503. msleep(2000);
  6504. } while (max_wait_time--);
  6505. return done;
  6506. }
  6507. /**
  6508. * qla4xxx_wait_for_hba_online - waits for HBA to come online
  6509. * @ha: Pointer to host adapter structure
  6510. **/
  6511. static int qla4xxx_wait_for_hba_online(struct scsi_qla_host *ha)
  6512. {
  6513. unsigned long wait_online;
  6514. wait_online = jiffies + (HBA_ONLINE_TOV * HZ);
  6515. while (time_before(jiffies, wait_online)) {
  6516. if (adapter_up(ha))
  6517. return QLA_SUCCESS;
  6518. msleep(2000);
  6519. }
  6520. return QLA_ERROR;
  6521. }
  6522. /**
  6523. * qla4xxx_eh_wait_for_commands - wait for active cmds to finish.
  6524. * @ha: pointer to HBA
  6525. * @t: target id
  6526. * @l: lun id
  6527. *
  6528. * This function waits for all outstanding commands to a lun to complete. It
  6529. * returns 0 if all pending commands are returned and 1 otherwise.
  6530. **/
  6531. static int qla4xxx_eh_wait_for_commands(struct scsi_qla_host *ha,
  6532. struct scsi_target *stgt,
  6533. struct scsi_device *sdev)
  6534. {
  6535. int cnt;
  6536. int status = 0;
  6537. struct scsi_cmnd *cmd;
  6538. /*
  6539. * Waiting for all commands for the designated target or dev
  6540. * in the active array
  6541. */
  6542. for (cnt = 0; cnt < ha->host->can_queue; cnt++) {
  6543. cmd = scsi_host_find_tag(ha->host, cnt);
  6544. if (cmd && stgt == scsi_target(cmd->device) &&
  6545. (!sdev || sdev == cmd->device)) {
  6546. if (!qla4xxx_eh_wait_on_command(ha, cmd)) {
  6547. status++;
  6548. break;
  6549. }
  6550. }
  6551. }
  6552. return status;
  6553. }
  6554. /**
  6555. * qla4xxx_eh_abort - callback for abort task.
  6556. * @cmd: Pointer to Linux's SCSI command structure
  6557. *
  6558. * This routine is called by the Linux OS to abort the specified
  6559. * command.
  6560. **/
  6561. static int qla4xxx_eh_abort(struct scsi_cmnd *cmd)
  6562. {
  6563. struct scsi_qla_host *ha = to_qla_host(cmd->device->host);
  6564. unsigned int id = cmd->device->id;
  6565. unsigned int lun = cmd->device->lun;
  6566. unsigned long flags;
  6567. struct srb *srb = NULL;
  6568. int ret = SUCCESS;
  6569. int wait = 0;
  6570. ql4_printk(KERN_INFO, ha,
  6571. "scsi%ld:%d:%d: Abort command issued cmd=%p\n",
  6572. ha->host_no, id, lun, cmd);
  6573. spin_lock_irqsave(&ha->hardware_lock, flags);
  6574. srb = (struct srb *) CMD_SP(cmd);
  6575. if (!srb) {
  6576. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  6577. return SUCCESS;
  6578. }
  6579. kref_get(&srb->srb_ref);
  6580. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  6581. if (qla4xxx_abort_task(ha, srb) != QLA_SUCCESS) {
  6582. DEBUG3(printk("scsi%ld:%d:%d: Abort_task mbx failed.\n",
  6583. ha->host_no, id, lun));
  6584. ret = FAILED;
  6585. } else {
  6586. DEBUG3(printk("scsi%ld:%d:%d: Abort_task mbx success.\n",
  6587. ha->host_no, id, lun));
  6588. wait = 1;
  6589. }
  6590. kref_put(&srb->srb_ref, qla4xxx_srb_compl);
  6591. /* Wait for command to complete */
  6592. if (wait) {
  6593. if (!qla4xxx_eh_wait_on_command(ha, cmd)) {
  6594. DEBUG2(printk("scsi%ld:%d:%d: Abort handler timed out\n",
  6595. ha->host_no, id, lun));
  6596. ret = FAILED;
  6597. }
  6598. }
  6599. ql4_printk(KERN_INFO, ha,
  6600. "scsi%ld:%d:%d: Abort command - %s\n",
  6601. ha->host_no, id, lun, (ret == SUCCESS) ? "succeeded" : "failed");
  6602. return ret;
  6603. }
  6604. /**
  6605. * qla4xxx_eh_device_reset - callback for target reset.
  6606. * @cmd: Pointer to Linux's SCSI command structure
  6607. *
  6608. * This routine is called by the Linux OS to reset all luns on the
  6609. * specified target.
  6610. **/
  6611. static int qla4xxx_eh_device_reset(struct scsi_cmnd *cmd)
  6612. {
  6613. struct scsi_qla_host *ha = to_qla_host(cmd->device->host);
  6614. struct ddb_entry *ddb_entry = cmd->device->hostdata;
  6615. int ret = FAILED, stat;
  6616. if (!ddb_entry)
  6617. return ret;
  6618. ret = iscsi_block_scsi_eh(cmd);
  6619. if (ret)
  6620. return ret;
  6621. ret = FAILED;
  6622. ql4_printk(KERN_INFO, ha,
  6623. "scsi%ld:%d:%d:%d: DEVICE RESET ISSUED.\n", ha->host_no,
  6624. cmd->device->channel, cmd->device->id, cmd->device->lun);
  6625. DEBUG2(printk(KERN_INFO
  6626. "scsi%ld: DEVICE_RESET cmd=%p jiffies = 0x%lx, to=%x,"
  6627. "dpc_flags=%lx, status=%x allowed=%d\n", ha->host_no,
  6628. cmd, jiffies, cmd->request->timeout / HZ,
  6629. ha->dpc_flags, cmd->result, cmd->allowed));
  6630. /* FIXME: wait for hba to go online */
  6631. stat = qla4xxx_reset_lun(ha, ddb_entry, cmd->device->lun);
  6632. if (stat != QLA_SUCCESS) {
  6633. ql4_printk(KERN_INFO, ha, "DEVICE RESET FAILED. %d\n", stat);
  6634. goto eh_dev_reset_done;
  6635. }
  6636. if (qla4xxx_eh_wait_for_commands(ha, scsi_target(cmd->device),
  6637. cmd->device)) {
  6638. ql4_printk(KERN_INFO, ha,
  6639. "DEVICE RESET FAILED - waiting for "
  6640. "commands.\n");
  6641. goto eh_dev_reset_done;
  6642. }
  6643. /* Send marker. */
  6644. if (qla4xxx_send_marker_iocb(ha, ddb_entry, cmd->device->lun,
  6645. MM_LUN_RESET) != QLA_SUCCESS)
  6646. goto eh_dev_reset_done;
  6647. ql4_printk(KERN_INFO, ha,
  6648. "scsi(%ld:%d:%d:%d): DEVICE RESET SUCCEEDED.\n",
  6649. ha->host_no, cmd->device->channel, cmd->device->id,
  6650. cmd->device->lun);
  6651. ret = SUCCESS;
  6652. eh_dev_reset_done:
  6653. return ret;
  6654. }
  6655. /**
  6656. * qla4xxx_eh_target_reset - callback for target reset.
  6657. * @cmd: Pointer to Linux's SCSI command structure
  6658. *
  6659. * This routine is called by the Linux OS to reset the target.
  6660. **/
  6661. static int qla4xxx_eh_target_reset(struct scsi_cmnd *cmd)
  6662. {
  6663. struct scsi_qla_host *ha = to_qla_host(cmd->device->host);
  6664. struct ddb_entry *ddb_entry = cmd->device->hostdata;
  6665. int stat, ret;
  6666. if (!ddb_entry)
  6667. return FAILED;
  6668. ret = iscsi_block_scsi_eh(cmd);
  6669. if (ret)
  6670. return ret;
  6671. starget_printk(KERN_INFO, scsi_target(cmd->device),
  6672. "WARM TARGET RESET ISSUED.\n");
  6673. DEBUG2(printk(KERN_INFO
  6674. "scsi%ld: TARGET_DEVICE_RESET cmd=%p jiffies = 0x%lx, "
  6675. "to=%x,dpc_flags=%lx, status=%x allowed=%d\n",
  6676. ha->host_no, cmd, jiffies, cmd->request->timeout / HZ,
  6677. ha->dpc_flags, cmd->result, cmd->allowed));
  6678. stat = qla4xxx_reset_target(ha, ddb_entry);
  6679. if (stat != QLA_SUCCESS) {
  6680. starget_printk(KERN_INFO, scsi_target(cmd->device),
  6681. "WARM TARGET RESET FAILED.\n");
  6682. return FAILED;
  6683. }
  6684. if (qla4xxx_eh_wait_for_commands(ha, scsi_target(cmd->device),
  6685. NULL)) {
  6686. starget_printk(KERN_INFO, scsi_target(cmd->device),
  6687. "WARM TARGET DEVICE RESET FAILED - "
  6688. "waiting for commands.\n");
  6689. return FAILED;
  6690. }
  6691. /* Send marker. */
  6692. if (qla4xxx_send_marker_iocb(ha, ddb_entry, cmd->device->lun,
  6693. MM_TGT_WARM_RESET) != QLA_SUCCESS) {
  6694. starget_printk(KERN_INFO, scsi_target(cmd->device),
  6695. "WARM TARGET DEVICE RESET FAILED - "
  6696. "marker iocb failed.\n");
  6697. return FAILED;
  6698. }
  6699. starget_printk(KERN_INFO, scsi_target(cmd->device),
  6700. "WARM TARGET RESET SUCCEEDED.\n");
  6701. return SUCCESS;
  6702. }
  6703. /**
  6704. * qla4xxx_is_eh_active - check if error handler is running
  6705. * @shost: Pointer to SCSI Host struct
  6706. *
  6707. * This routine finds that if reset host is called in EH
  6708. * scenario or from some application like sg_reset
  6709. **/
  6710. static int qla4xxx_is_eh_active(struct Scsi_Host *shost)
  6711. {
  6712. if (shost->shost_state == SHOST_RECOVERY)
  6713. return 1;
  6714. return 0;
  6715. }
  6716. /**
  6717. * qla4xxx_eh_host_reset - kernel callback
  6718. * @cmd: Pointer to Linux's SCSI command structure
  6719. *
  6720. * This routine is invoked by the Linux kernel to perform fatal error
  6721. * recovery on the specified adapter.
  6722. **/
  6723. static int qla4xxx_eh_host_reset(struct scsi_cmnd *cmd)
  6724. {
  6725. int return_status = FAILED;
  6726. struct scsi_qla_host *ha;
  6727. ha = to_qla_host(cmd->device->host);
  6728. if (is_qla8032(ha) && ql4xdontresethba)
  6729. qla4_83xx_set_idc_dontreset(ha);
  6730. /*
  6731. * For ISP8324, if IDC_CTRL DONTRESET_BIT0 is set by other
  6732. * protocol drivers, we should not set device_state to
  6733. * NEED_RESET
  6734. */
  6735. if (ql4xdontresethba ||
  6736. (is_qla8032(ha) && qla4_83xx_idc_dontreset(ha))) {
  6737. DEBUG2(printk("scsi%ld: %s: Don't Reset HBA\n",
  6738. ha->host_no, __func__));
  6739. /* Clear outstanding srb in queues */
  6740. if (qla4xxx_is_eh_active(cmd->device->host))
  6741. qla4xxx_abort_active_cmds(ha, DID_ABORT << 16);
  6742. return FAILED;
  6743. }
  6744. ql4_printk(KERN_INFO, ha,
  6745. "scsi(%ld:%d:%d:%d): HOST RESET ISSUED.\n", ha->host_no,
  6746. cmd->device->channel, cmd->device->id, cmd->device->lun);
  6747. if (qla4xxx_wait_for_hba_online(ha) != QLA_SUCCESS) {
  6748. DEBUG2(printk("scsi%ld:%d: %s: Unable to reset host. Adapter "
  6749. "DEAD.\n", ha->host_no, cmd->device->channel,
  6750. __func__));
  6751. return FAILED;
  6752. }
  6753. if (!test_bit(DPC_RESET_HA, &ha->dpc_flags)) {
  6754. if (is_qla80XX(ha))
  6755. set_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags);
  6756. else
  6757. set_bit(DPC_RESET_HA, &ha->dpc_flags);
  6758. }
  6759. if (qla4xxx_recover_adapter(ha) == QLA_SUCCESS)
  6760. return_status = SUCCESS;
  6761. ql4_printk(KERN_INFO, ha, "HOST RESET %s.\n",
  6762. return_status == FAILED ? "FAILED" : "SUCCEEDED");
  6763. return return_status;
  6764. }
  6765. static int qla4xxx_context_reset(struct scsi_qla_host *ha)
  6766. {
  6767. uint32_t mbox_cmd[MBOX_REG_COUNT];
  6768. uint32_t mbox_sts[MBOX_REG_COUNT];
  6769. struct addr_ctrl_blk_def *acb = NULL;
  6770. uint32_t acb_len = sizeof(struct addr_ctrl_blk_def);
  6771. int rval = QLA_SUCCESS;
  6772. dma_addr_t acb_dma;
  6773. acb = dma_alloc_coherent(&ha->pdev->dev,
  6774. sizeof(struct addr_ctrl_blk_def),
  6775. &acb_dma, GFP_KERNEL);
  6776. if (!acb) {
  6777. ql4_printk(KERN_ERR, ha, "%s: Unable to alloc acb\n",
  6778. __func__);
  6779. rval = -ENOMEM;
  6780. goto exit_port_reset;
  6781. }
  6782. memset(acb, 0, acb_len);
  6783. rval = qla4xxx_get_acb(ha, acb_dma, PRIMARI_ACB, acb_len);
  6784. if (rval != QLA_SUCCESS) {
  6785. rval = -EIO;
  6786. goto exit_free_acb;
  6787. }
  6788. rval = qla4xxx_disable_acb(ha);
  6789. if (rval != QLA_SUCCESS) {
  6790. rval = -EIO;
  6791. goto exit_free_acb;
  6792. }
  6793. wait_for_completion_timeout(&ha->disable_acb_comp,
  6794. DISABLE_ACB_TOV * HZ);
  6795. rval = qla4xxx_set_acb(ha, &mbox_cmd[0], &mbox_sts[0], acb_dma);
  6796. if (rval != QLA_SUCCESS) {
  6797. rval = -EIO;
  6798. goto exit_free_acb;
  6799. }
  6800. exit_free_acb:
  6801. dma_free_coherent(&ha->pdev->dev, sizeof(struct addr_ctrl_blk_def),
  6802. acb, acb_dma);
  6803. exit_port_reset:
  6804. DEBUG2(ql4_printk(KERN_INFO, ha, "%s %s\n", __func__,
  6805. rval == QLA_SUCCESS ? "SUCCEEDED" : "FAILED"));
  6806. return rval;
  6807. }
  6808. static int qla4xxx_host_reset(struct Scsi_Host *shost, int reset_type)
  6809. {
  6810. struct scsi_qla_host *ha = to_qla_host(shost);
  6811. int rval = QLA_SUCCESS;
  6812. uint32_t idc_ctrl;
  6813. if (ql4xdontresethba) {
  6814. DEBUG2(ql4_printk(KERN_INFO, ha, "%s: Don't Reset HBA\n",
  6815. __func__));
  6816. rval = -EPERM;
  6817. goto exit_host_reset;
  6818. }
  6819. if (test_bit(DPC_RESET_HA, &ha->dpc_flags))
  6820. goto recover_adapter;
  6821. switch (reset_type) {
  6822. case SCSI_ADAPTER_RESET:
  6823. set_bit(DPC_RESET_HA, &ha->dpc_flags);
  6824. break;
  6825. case SCSI_FIRMWARE_RESET:
  6826. if (!test_bit(DPC_RESET_HA, &ha->dpc_flags)) {
  6827. if (is_qla80XX(ha))
  6828. /* set firmware context reset */
  6829. set_bit(DPC_RESET_HA_FW_CONTEXT,
  6830. &ha->dpc_flags);
  6831. else {
  6832. rval = qla4xxx_context_reset(ha);
  6833. goto exit_host_reset;
  6834. }
  6835. }
  6836. break;
  6837. }
  6838. recover_adapter:
  6839. /* For ISP83XX set graceful reset bit in IDC_DRV_CTRL if
  6840. * reset is issued by application */
  6841. if (is_qla8032(ha) && test_bit(DPC_RESET_HA, &ha->dpc_flags)) {
  6842. idc_ctrl = qla4_83xx_rd_reg(ha, QLA83XX_IDC_DRV_CTRL);
  6843. qla4_83xx_wr_reg(ha, QLA83XX_IDC_DRV_CTRL,
  6844. (idc_ctrl | GRACEFUL_RESET_BIT1));
  6845. }
  6846. rval = qla4xxx_recover_adapter(ha);
  6847. if (rval != QLA_SUCCESS) {
  6848. DEBUG2(ql4_printk(KERN_INFO, ha, "%s: recover adapter fail\n",
  6849. __func__));
  6850. rval = -EIO;
  6851. }
  6852. exit_host_reset:
  6853. return rval;
  6854. }
  6855. /* PCI AER driver recovers from all correctable errors w/o
  6856. * driver intervention. For uncorrectable errors PCI AER
  6857. * driver calls the following device driver's callbacks
  6858. *
  6859. * - Fatal Errors - link_reset
  6860. * - Non-Fatal Errors - driver's pci_error_detected() which
  6861. * returns CAN_RECOVER, NEED_RESET or DISCONNECT.
  6862. *
  6863. * PCI AER driver calls
  6864. * CAN_RECOVER - driver's pci_mmio_enabled(), mmio_enabled
  6865. * returns RECOVERED or NEED_RESET if fw_hung
  6866. * NEED_RESET - driver's slot_reset()
  6867. * DISCONNECT - device is dead & cannot recover
  6868. * RECOVERED - driver's pci_resume()
  6869. */
  6870. static pci_ers_result_t
  6871. qla4xxx_pci_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
  6872. {
  6873. struct scsi_qla_host *ha = pci_get_drvdata(pdev);
  6874. ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: error detected:state %x\n",
  6875. ha->host_no, __func__, state);
  6876. if (!is_aer_supported(ha))
  6877. return PCI_ERS_RESULT_NONE;
  6878. switch (state) {
  6879. case pci_channel_io_normal:
  6880. clear_bit(AF_EEH_BUSY, &ha->flags);
  6881. return PCI_ERS_RESULT_CAN_RECOVER;
  6882. case pci_channel_io_frozen:
  6883. set_bit(AF_EEH_BUSY, &ha->flags);
  6884. qla4xxx_mailbox_premature_completion(ha);
  6885. qla4xxx_free_irqs(ha);
  6886. pci_disable_device(pdev);
  6887. /* Return back all IOs */
  6888. qla4xxx_abort_active_cmds(ha, DID_RESET << 16);
  6889. return PCI_ERS_RESULT_NEED_RESET;
  6890. case pci_channel_io_perm_failure:
  6891. set_bit(AF_EEH_BUSY, &ha->flags);
  6892. set_bit(AF_PCI_CHANNEL_IO_PERM_FAILURE, &ha->flags);
  6893. qla4xxx_abort_active_cmds(ha, DID_NO_CONNECT << 16);
  6894. return PCI_ERS_RESULT_DISCONNECT;
  6895. }
  6896. return PCI_ERS_RESULT_NEED_RESET;
  6897. }
  6898. /**
  6899. * qla4xxx_pci_mmio_enabled() gets called if
  6900. * qla4xxx_pci_error_detected() returns PCI_ERS_RESULT_CAN_RECOVER
  6901. * and read/write to the device still works.
  6902. **/
  6903. static pci_ers_result_t
  6904. qla4xxx_pci_mmio_enabled(struct pci_dev *pdev)
  6905. {
  6906. struct scsi_qla_host *ha = pci_get_drvdata(pdev);
  6907. if (!is_aer_supported(ha))
  6908. return PCI_ERS_RESULT_NONE;
  6909. return PCI_ERS_RESULT_RECOVERED;
  6910. }
  6911. static uint32_t qla4_8xxx_error_recovery(struct scsi_qla_host *ha)
  6912. {
  6913. uint32_t rval = QLA_ERROR;
  6914. int fn;
  6915. struct pci_dev *other_pdev = NULL;
  6916. ql4_printk(KERN_WARNING, ha, "scsi%ld: In %s\n", ha->host_no, __func__);
  6917. set_bit(DPC_RESET_ACTIVE, &ha->dpc_flags);
  6918. if (test_bit(AF_ONLINE, &ha->flags)) {
  6919. clear_bit(AF_ONLINE, &ha->flags);
  6920. clear_bit(AF_LINK_UP, &ha->flags);
  6921. iscsi_host_for_each_session(ha->host, qla4xxx_fail_session);
  6922. qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
  6923. }
  6924. fn = PCI_FUNC(ha->pdev->devfn);
  6925. while (fn > 0) {
  6926. fn--;
  6927. ql4_printk(KERN_INFO, ha, "scsi%ld: %s: Finding PCI device at "
  6928. "func %x\n", ha->host_no, __func__, fn);
  6929. /* Get the pci device given the domain, bus,
  6930. * slot/function number */
  6931. other_pdev =
  6932. pci_get_domain_bus_and_slot(pci_domain_nr(ha->pdev->bus),
  6933. ha->pdev->bus->number, PCI_DEVFN(PCI_SLOT(ha->pdev->devfn),
  6934. fn));
  6935. if (!other_pdev)
  6936. continue;
  6937. if (atomic_read(&other_pdev->enable_cnt)) {
  6938. ql4_printk(KERN_INFO, ha, "scsi%ld: %s: Found PCI "
  6939. "func in enabled state%x\n", ha->host_no,
  6940. __func__, fn);
  6941. pci_dev_put(other_pdev);
  6942. break;
  6943. }
  6944. pci_dev_put(other_pdev);
  6945. }
  6946. /* The first function on the card, the reset owner will
  6947. * start & initialize the firmware. The other functions
  6948. * on the card will reset the firmware context
  6949. */
  6950. if (!fn) {
  6951. ql4_printk(KERN_INFO, ha, "scsi%ld: %s: devfn being reset "
  6952. "0x%x is the owner\n", ha->host_no, __func__,
  6953. ha->pdev->devfn);
  6954. ha->isp_ops->idc_lock(ha);
  6955. qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DEV_STATE,
  6956. QLA8XXX_DEV_COLD);
  6957. ha->isp_ops->idc_unlock(ha);
  6958. rval = qla4_8xxx_update_idc_reg(ha);
  6959. if (rval == QLA_ERROR) {
  6960. ql4_printk(KERN_INFO, ha, "scsi%ld: %s: HW State: FAILED\n",
  6961. ha->host_no, __func__);
  6962. ha->isp_ops->idc_lock(ha);
  6963. qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DEV_STATE,
  6964. QLA8XXX_DEV_FAILED);
  6965. ha->isp_ops->idc_unlock(ha);
  6966. goto exit_error_recovery;
  6967. }
  6968. clear_bit(AF_FW_RECOVERY, &ha->flags);
  6969. rval = qla4xxx_initialize_adapter(ha, RESET_ADAPTER);
  6970. if (rval != QLA_SUCCESS) {
  6971. ql4_printk(KERN_INFO, ha, "scsi%ld: %s: HW State: "
  6972. "FAILED\n", ha->host_no, __func__);
  6973. ha->isp_ops->idc_lock(ha);
  6974. qla4_8xxx_clear_drv_active(ha);
  6975. qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DEV_STATE,
  6976. QLA8XXX_DEV_FAILED);
  6977. ha->isp_ops->idc_unlock(ha);
  6978. } else {
  6979. ql4_printk(KERN_INFO, ha, "scsi%ld: %s: HW State: "
  6980. "READY\n", ha->host_no, __func__);
  6981. ha->isp_ops->idc_lock(ha);
  6982. qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DEV_STATE,
  6983. QLA8XXX_DEV_READY);
  6984. /* Clear driver state register */
  6985. qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DRV_STATE, 0);
  6986. qla4_8xxx_set_drv_active(ha);
  6987. ha->isp_ops->idc_unlock(ha);
  6988. ha->isp_ops->enable_intrs(ha);
  6989. }
  6990. } else {
  6991. ql4_printk(KERN_INFO, ha, "scsi%ld: %s: devfn 0x%x is not "
  6992. "the reset owner\n", ha->host_no, __func__,
  6993. ha->pdev->devfn);
  6994. if ((qla4_8xxx_rd_direct(ha, QLA8XXX_CRB_DEV_STATE) ==
  6995. QLA8XXX_DEV_READY)) {
  6996. clear_bit(AF_FW_RECOVERY, &ha->flags);
  6997. rval = qla4xxx_initialize_adapter(ha, RESET_ADAPTER);
  6998. if (rval == QLA_SUCCESS)
  6999. ha->isp_ops->enable_intrs(ha);
  7000. ha->isp_ops->idc_lock(ha);
  7001. qla4_8xxx_set_drv_active(ha);
  7002. ha->isp_ops->idc_unlock(ha);
  7003. }
  7004. }
  7005. exit_error_recovery:
  7006. clear_bit(DPC_RESET_ACTIVE, &ha->dpc_flags);
  7007. return rval;
  7008. }
  7009. static pci_ers_result_t
  7010. qla4xxx_pci_slot_reset(struct pci_dev *pdev)
  7011. {
  7012. pci_ers_result_t ret = PCI_ERS_RESULT_DISCONNECT;
  7013. struct scsi_qla_host *ha = pci_get_drvdata(pdev);
  7014. int rc;
  7015. ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: slot_reset\n",
  7016. ha->host_no, __func__);
  7017. if (!is_aer_supported(ha))
  7018. return PCI_ERS_RESULT_NONE;
  7019. /* Restore the saved state of PCIe device -
  7020. * BAR registers, PCI Config space, PCIX, MSI,
  7021. * IOV states
  7022. */
  7023. pci_restore_state(pdev);
  7024. /* pci_restore_state() clears the saved_state flag of the device
  7025. * save restored state which resets saved_state flag
  7026. */
  7027. pci_save_state(pdev);
  7028. /* Initialize device or resume if in suspended state */
  7029. rc = pci_enable_device(pdev);
  7030. if (rc) {
  7031. ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: Can't re-enable "
  7032. "device after reset\n", ha->host_no, __func__);
  7033. goto exit_slot_reset;
  7034. }
  7035. ha->isp_ops->disable_intrs(ha);
  7036. if (is_qla80XX(ha)) {
  7037. if (qla4_8xxx_error_recovery(ha) == QLA_SUCCESS) {
  7038. ret = PCI_ERS_RESULT_RECOVERED;
  7039. goto exit_slot_reset;
  7040. } else
  7041. goto exit_slot_reset;
  7042. }
  7043. exit_slot_reset:
  7044. ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: Return=%x\n"
  7045. "device after reset\n", ha->host_no, __func__, ret);
  7046. return ret;
  7047. }
  7048. static void
  7049. qla4xxx_pci_resume(struct pci_dev *pdev)
  7050. {
  7051. struct scsi_qla_host *ha = pci_get_drvdata(pdev);
  7052. int ret;
  7053. ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: pci_resume\n",
  7054. ha->host_no, __func__);
  7055. ret = qla4xxx_wait_for_hba_online(ha);
  7056. if (ret != QLA_SUCCESS) {
  7057. ql4_printk(KERN_ERR, ha, "scsi%ld: %s: the device failed to "
  7058. "resume I/O from slot/link_reset\n", ha->host_no,
  7059. __func__);
  7060. }
  7061. pci_cleanup_aer_uncorrect_error_status(pdev);
  7062. clear_bit(AF_EEH_BUSY, &ha->flags);
  7063. }
  7064. static const struct pci_error_handlers qla4xxx_err_handler = {
  7065. .error_detected = qla4xxx_pci_error_detected,
  7066. .mmio_enabled = qla4xxx_pci_mmio_enabled,
  7067. .slot_reset = qla4xxx_pci_slot_reset,
  7068. .resume = qla4xxx_pci_resume,
  7069. };
  7070. static struct pci_device_id qla4xxx_pci_tbl[] = {
  7071. {
  7072. .vendor = PCI_VENDOR_ID_QLOGIC,
  7073. .device = PCI_DEVICE_ID_QLOGIC_ISP4010,
  7074. .subvendor = PCI_ANY_ID,
  7075. .subdevice = PCI_ANY_ID,
  7076. },
  7077. {
  7078. .vendor = PCI_VENDOR_ID_QLOGIC,
  7079. .device = PCI_DEVICE_ID_QLOGIC_ISP4022,
  7080. .subvendor = PCI_ANY_ID,
  7081. .subdevice = PCI_ANY_ID,
  7082. },
  7083. {
  7084. .vendor = PCI_VENDOR_ID_QLOGIC,
  7085. .device = PCI_DEVICE_ID_QLOGIC_ISP4032,
  7086. .subvendor = PCI_ANY_ID,
  7087. .subdevice = PCI_ANY_ID,
  7088. },
  7089. {
  7090. .vendor = PCI_VENDOR_ID_QLOGIC,
  7091. .device = PCI_DEVICE_ID_QLOGIC_ISP8022,
  7092. .subvendor = PCI_ANY_ID,
  7093. .subdevice = PCI_ANY_ID,
  7094. },
  7095. {
  7096. .vendor = PCI_VENDOR_ID_QLOGIC,
  7097. .device = PCI_DEVICE_ID_QLOGIC_ISP8324,
  7098. .subvendor = PCI_ANY_ID,
  7099. .subdevice = PCI_ANY_ID,
  7100. },
  7101. {0, 0},
  7102. };
  7103. MODULE_DEVICE_TABLE(pci, qla4xxx_pci_tbl);
  7104. static struct pci_driver qla4xxx_pci_driver = {
  7105. .name = DRIVER_NAME,
  7106. .id_table = qla4xxx_pci_tbl,
  7107. .probe = qla4xxx_probe_adapter,
  7108. .remove = qla4xxx_remove_adapter,
  7109. .err_handler = &qla4xxx_err_handler,
  7110. };
  7111. static int __init qla4xxx_module_init(void)
  7112. {
  7113. int ret;
  7114. /* Allocate cache for SRBs. */
  7115. srb_cachep = kmem_cache_create("qla4xxx_srbs", sizeof(struct srb), 0,
  7116. SLAB_HWCACHE_ALIGN, NULL);
  7117. if (srb_cachep == NULL) {
  7118. printk(KERN_ERR
  7119. "%s: Unable to allocate SRB cache..."
  7120. "Failing load!\n", DRIVER_NAME);
  7121. ret = -ENOMEM;
  7122. goto no_srp_cache;
  7123. }
  7124. /* Derive version string. */
  7125. strcpy(qla4xxx_version_str, QLA4XXX_DRIVER_VERSION);
  7126. if (ql4xextended_error_logging)
  7127. strcat(qla4xxx_version_str, "-debug");
  7128. qla4xxx_scsi_transport =
  7129. iscsi_register_transport(&qla4xxx_iscsi_transport);
  7130. if (!qla4xxx_scsi_transport){
  7131. ret = -ENODEV;
  7132. goto release_srb_cache;
  7133. }
  7134. ret = pci_register_driver(&qla4xxx_pci_driver);
  7135. if (ret)
  7136. goto unregister_transport;
  7137. printk(KERN_INFO "QLogic iSCSI HBA Driver\n");
  7138. return 0;
  7139. unregister_transport:
  7140. iscsi_unregister_transport(&qla4xxx_iscsi_transport);
  7141. release_srb_cache:
  7142. kmem_cache_destroy(srb_cachep);
  7143. no_srp_cache:
  7144. return ret;
  7145. }
  7146. static void __exit qla4xxx_module_exit(void)
  7147. {
  7148. pci_unregister_driver(&qla4xxx_pci_driver);
  7149. iscsi_unregister_transport(&qla4xxx_iscsi_transport);
  7150. kmem_cache_destroy(srb_cachep);
  7151. }
  7152. module_init(qla4xxx_module_init);
  7153. module_exit(qla4xxx_module_exit);
  7154. MODULE_AUTHOR("QLogic Corporation");
  7155. MODULE_DESCRIPTION("QLogic iSCSI HBA Driver");
  7156. MODULE_LICENSE("GPL");
  7157. MODULE_VERSION(QLA4XXX_DRIVER_VERSION);