ql4_os.c 283 KB

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