ql4_os.c 119 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346
  1. /*
  2. * QLogic iSCSI HBA Driver
  3. * Copyright (c) 2003-2010 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 <scsi/scsi_tcq.h>
  12. #include <scsi/scsicam.h>
  13. #include "ql4_def.h"
  14. #include "ql4_version.h"
  15. #include "ql4_glbl.h"
  16. #include "ql4_dbg.h"
  17. #include "ql4_inline.h"
  18. /*
  19. * Driver version
  20. */
  21. static char qla4xxx_version_str[40];
  22. /*
  23. * SRB allocation cache
  24. */
  25. static struct kmem_cache *srb_cachep;
  26. /*
  27. * Module parameter information and variables
  28. */
  29. int ql4xdontresethba = 0;
  30. module_param(ql4xdontresethba, int, S_IRUGO | S_IWUSR);
  31. MODULE_PARM_DESC(ql4xdontresethba,
  32. "Don't reset the HBA for driver recovery \n"
  33. " 0 - It will reset HBA (Default)\n"
  34. " 1 - It will NOT reset HBA");
  35. int ql4xextended_error_logging = 0; /* 0 = off, 1 = log errors */
  36. module_param(ql4xextended_error_logging, int, S_IRUGO | S_IWUSR);
  37. MODULE_PARM_DESC(ql4xextended_error_logging,
  38. "Option to enable extended error logging, "
  39. "Default is 0 - no logging, 1 - debug logging");
  40. int ql4xenablemsix = 1;
  41. module_param(ql4xenablemsix, int, S_IRUGO|S_IWUSR);
  42. MODULE_PARM_DESC(ql4xenablemsix,
  43. "Set to enable MSI or MSI-X interrupt mechanism.\n"
  44. " 0 = enable INTx interrupt mechanism.\n"
  45. " 1 = enable MSI-X interrupt mechanism (Default).\n"
  46. " 2 = enable MSI interrupt mechanism.");
  47. #define QL4_DEF_QDEPTH 32
  48. static int ql4xmaxqdepth = QL4_DEF_QDEPTH;
  49. module_param(ql4xmaxqdepth, int, S_IRUGO | S_IWUSR);
  50. MODULE_PARM_DESC(ql4xmaxqdepth,
  51. "Maximum queue depth to report for target devices.\n"
  52. " Default: 32.");
  53. static int ql4xsess_recovery_tmo = QL4_SESS_RECOVERY_TMO;
  54. module_param(ql4xsess_recovery_tmo, int, S_IRUGO);
  55. MODULE_PARM_DESC(ql4xsess_recovery_tmo,
  56. "Target Session Recovery Timeout.\n"
  57. " Default: 30 sec.");
  58. static int qla4xxx_wait_for_hba_online(struct scsi_qla_host *ha);
  59. /*
  60. * SCSI host template entry points
  61. */
  62. static void qla4xxx_config_dma_addressing(struct scsi_qla_host *ha);
  63. /*
  64. * iSCSI template entry points
  65. */
  66. static int qla4xxx_conn_get_param(struct iscsi_cls_conn *conn,
  67. enum iscsi_param param, char *buf);
  68. static int qla4xxx_host_get_param(struct Scsi_Host *shost,
  69. enum iscsi_host_param param, char *buf);
  70. static int qla4xxx_iface_set_param(struct Scsi_Host *shost, char *data,
  71. int count);
  72. static int qla4xxx_get_iface_param(struct iscsi_iface *iface,
  73. enum iscsi_param_type param_type,
  74. int param, char *buf);
  75. static enum blk_eh_timer_return qla4xxx_eh_cmd_timed_out(struct scsi_cmnd *sc);
  76. static struct iscsi_endpoint *qla4xxx_ep_connect(struct Scsi_Host *shost,
  77. struct sockaddr *dst_addr,
  78. int non_blocking);
  79. static int qla4xxx_ep_poll(struct iscsi_endpoint *ep, int timeout_ms);
  80. static void qla4xxx_ep_disconnect(struct iscsi_endpoint *ep);
  81. static int qla4xxx_get_ep_param(struct iscsi_endpoint *ep,
  82. enum iscsi_param param, char *buf);
  83. static int qla4xxx_conn_start(struct iscsi_cls_conn *conn);
  84. static struct iscsi_cls_conn *
  85. qla4xxx_conn_create(struct iscsi_cls_session *cls_sess, uint32_t conn_idx);
  86. static int qla4xxx_conn_bind(struct iscsi_cls_session *cls_session,
  87. struct iscsi_cls_conn *cls_conn,
  88. uint64_t transport_fd, int is_leading);
  89. static void qla4xxx_conn_destroy(struct iscsi_cls_conn *conn);
  90. static struct iscsi_cls_session *
  91. qla4xxx_session_create(struct iscsi_endpoint *ep, uint16_t cmds_max,
  92. uint16_t qdepth, uint32_t initial_cmdsn);
  93. static void qla4xxx_session_destroy(struct iscsi_cls_session *sess);
  94. static void qla4xxx_task_work(struct work_struct *wdata);
  95. static int qla4xxx_alloc_pdu(struct iscsi_task *, uint8_t);
  96. static int qla4xxx_task_xmit(struct iscsi_task *);
  97. static void qla4xxx_task_cleanup(struct iscsi_task *);
  98. static void qla4xxx_fail_session(struct iscsi_cls_session *cls_session);
  99. static void qla4xxx_conn_get_stats(struct iscsi_cls_conn *cls_conn,
  100. struct iscsi_stats *stats);
  101. /*
  102. * SCSI host template entry points
  103. */
  104. static int qla4xxx_queuecommand(struct Scsi_Host *h, struct scsi_cmnd *cmd);
  105. static int qla4xxx_eh_abort(struct scsi_cmnd *cmd);
  106. static int qla4xxx_eh_device_reset(struct scsi_cmnd *cmd);
  107. static int qla4xxx_eh_target_reset(struct scsi_cmnd *cmd);
  108. static int qla4xxx_eh_host_reset(struct scsi_cmnd *cmd);
  109. static int qla4xxx_slave_alloc(struct scsi_device *device);
  110. static int qla4xxx_slave_configure(struct scsi_device *device);
  111. static void qla4xxx_slave_destroy(struct scsi_device *sdev);
  112. static mode_t ql4_attr_is_visible(int param_type, int param);
  113. static int qla4xxx_host_reset(struct Scsi_Host *shost, int reset_type);
  114. static struct qla4_8xxx_legacy_intr_set legacy_intr[] =
  115. QLA82XX_LEGACY_INTR_CONFIG;
  116. static struct scsi_host_template qla4xxx_driver_template = {
  117. .module = THIS_MODULE,
  118. .name = DRIVER_NAME,
  119. .proc_name = DRIVER_NAME,
  120. .queuecommand = qla4xxx_queuecommand,
  121. .eh_abort_handler = qla4xxx_eh_abort,
  122. .eh_device_reset_handler = qla4xxx_eh_device_reset,
  123. .eh_target_reset_handler = qla4xxx_eh_target_reset,
  124. .eh_host_reset_handler = qla4xxx_eh_host_reset,
  125. .eh_timed_out = qla4xxx_eh_cmd_timed_out,
  126. .slave_configure = qla4xxx_slave_configure,
  127. .slave_alloc = qla4xxx_slave_alloc,
  128. .slave_destroy = qla4xxx_slave_destroy,
  129. .this_id = -1,
  130. .cmd_per_lun = 3,
  131. .use_clustering = ENABLE_CLUSTERING,
  132. .sg_tablesize = SG_ALL,
  133. .max_sectors = 0xFFFF,
  134. .shost_attrs = qla4xxx_host_attrs,
  135. .host_reset = qla4xxx_host_reset,
  136. .vendor_id = SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_QLOGIC,
  137. };
  138. static struct iscsi_transport qla4xxx_iscsi_transport = {
  139. .owner = THIS_MODULE,
  140. .name = DRIVER_NAME,
  141. .caps = CAP_TEXT_NEGO |
  142. CAP_DATA_PATH_OFFLOAD | CAP_HDRDGST |
  143. CAP_DATADGST | CAP_LOGIN_OFFLOAD |
  144. CAP_MULTI_R2T,
  145. .attr_is_visible = ql4_attr_is_visible,
  146. .create_session = qla4xxx_session_create,
  147. .destroy_session = qla4xxx_session_destroy,
  148. .start_conn = qla4xxx_conn_start,
  149. .create_conn = qla4xxx_conn_create,
  150. .bind_conn = qla4xxx_conn_bind,
  151. .stop_conn = iscsi_conn_stop,
  152. .destroy_conn = qla4xxx_conn_destroy,
  153. .set_param = iscsi_set_param,
  154. .get_conn_param = qla4xxx_conn_get_param,
  155. .get_session_param = iscsi_session_get_param,
  156. .get_ep_param = qla4xxx_get_ep_param,
  157. .ep_connect = qla4xxx_ep_connect,
  158. .ep_poll = qla4xxx_ep_poll,
  159. .ep_disconnect = qla4xxx_ep_disconnect,
  160. .get_stats = qla4xxx_conn_get_stats,
  161. .send_pdu = iscsi_conn_send_pdu,
  162. .xmit_task = qla4xxx_task_xmit,
  163. .cleanup_task = qla4xxx_task_cleanup,
  164. .alloc_pdu = qla4xxx_alloc_pdu,
  165. .get_host_param = qla4xxx_host_get_param,
  166. .set_iface_param = qla4xxx_iface_set_param,
  167. .get_iface_param = qla4xxx_get_iface_param,
  168. .bsg_request = qla4xxx_bsg_request,
  169. };
  170. static struct scsi_transport_template *qla4xxx_scsi_transport;
  171. static mode_t ql4_attr_is_visible(int param_type, int param)
  172. {
  173. switch (param_type) {
  174. case ISCSI_HOST_PARAM:
  175. switch (param) {
  176. case ISCSI_HOST_PARAM_HWADDRESS:
  177. case ISCSI_HOST_PARAM_IPADDRESS:
  178. case ISCSI_HOST_PARAM_INITIATOR_NAME:
  179. return S_IRUGO;
  180. default:
  181. return 0;
  182. }
  183. case ISCSI_PARAM:
  184. switch (param) {
  185. case ISCSI_PARAM_CONN_ADDRESS:
  186. case ISCSI_PARAM_CONN_PORT:
  187. case ISCSI_PARAM_TARGET_NAME:
  188. case ISCSI_PARAM_TPGT:
  189. case ISCSI_PARAM_TARGET_ALIAS:
  190. case ISCSI_PARAM_MAX_BURST:
  191. case ISCSI_PARAM_MAX_R2T:
  192. case ISCSI_PARAM_FIRST_BURST:
  193. case ISCSI_PARAM_MAX_RECV_DLENGTH:
  194. case ISCSI_PARAM_MAX_XMIT_DLENGTH:
  195. case ISCSI_PARAM_IFACE_NAME:
  196. return S_IRUGO;
  197. default:
  198. return 0;
  199. }
  200. case ISCSI_NET_PARAM:
  201. switch (param) {
  202. case ISCSI_NET_PARAM_IPV4_ADDR:
  203. case ISCSI_NET_PARAM_IPV4_SUBNET:
  204. case ISCSI_NET_PARAM_IPV4_GW:
  205. case ISCSI_NET_PARAM_IPV4_BOOTPROTO:
  206. case ISCSI_NET_PARAM_IFACE_ENABLE:
  207. case ISCSI_NET_PARAM_IPV6_LINKLOCAL:
  208. case ISCSI_NET_PARAM_IPV6_ADDR:
  209. case ISCSI_NET_PARAM_IPV6_ROUTER:
  210. case ISCSI_NET_PARAM_IPV6_ADDR_AUTOCFG:
  211. case ISCSI_NET_PARAM_IPV6_LINKLOCAL_AUTOCFG:
  212. case ISCSI_NET_PARAM_VLAN_ID:
  213. case ISCSI_NET_PARAM_VLAN_PRIORITY:
  214. case ISCSI_NET_PARAM_VLAN_ENABLED:
  215. case ISCSI_NET_PARAM_MTU:
  216. case ISCSI_NET_PARAM_PORT:
  217. return S_IRUGO;
  218. default:
  219. return 0;
  220. }
  221. }
  222. return 0;
  223. }
  224. static int qla4xxx_get_iface_param(struct iscsi_iface *iface,
  225. enum iscsi_param_type param_type,
  226. int param, char *buf)
  227. {
  228. struct Scsi_Host *shost = iscsi_iface_to_shost(iface);
  229. struct scsi_qla_host *ha = to_qla_host(shost);
  230. int len = -ENOSYS;
  231. if (param_type != ISCSI_NET_PARAM)
  232. return -ENOSYS;
  233. switch (param) {
  234. case ISCSI_NET_PARAM_IPV4_ADDR:
  235. len = sprintf(buf, "%pI4\n", &ha->ip_config.ip_address);
  236. break;
  237. case ISCSI_NET_PARAM_IPV4_SUBNET:
  238. len = sprintf(buf, "%pI4\n", &ha->ip_config.subnet_mask);
  239. break;
  240. case ISCSI_NET_PARAM_IPV4_GW:
  241. len = sprintf(buf, "%pI4\n", &ha->ip_config.gateway);
  242. break;
  243. case ISCSI_NET_PARAM_IFACE_ENABLE:
  244. if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4)
  245. len = sprintf(buf, "%s\n",
  246. (ha->ip_config.ipv4_options &
  247. IPOPT_IPV4_PROTOCOL_ENABLE) ?
  248. "enabled" : "disabled");
  249. else if (iface->iface_type == ISCSI_IFACE_TYPE_IPV6)
  250. len = sprintf(buf, "%s\n",
  251. (ha->ip_config.ipv6_options &
  252. IPV6_OPT_IPV6_PROTOCOL_ENABLE) ?
  253. "enabled" : "disabled");
  254. break;
  255. case ISCSI_NET_PARAM_IPV4_BOOTPROTO:
  256. len = sprintf(buf, "%s\n",
  257. (ha->ip_config.tcp_options & TCPOPT_DHCP_ENABLE) ?
  258. "dhcp" : "static");
  259. break;
  260. case ISCSI_NET_PARAM_IPV6_ADDR:
  261. if (iface->iface_num == 0)
  262. len = sprintf(buf, "%pI6\n", &ha->ip_config.ipv6_addr0);
  263. if (iface->iface_num == 1)
  264. len = sprintf(buf, "%pI6\n", &ha->ip_config.ipv6_addr1);
  265. break;
  266. case ISCSI_NET_PARAM_IPV6_LINKLOCAL:
  267. len = sprintf(buf, "%pI6\n",
  268. &ha->ip_config.ipv6_link_local_addr);
  269. break;
  270. case ISCSI_NET_PARAM_IPV6_ROUTER:
  271. len = sprintf(buf, "%pI6\n",
  272. &ha->ip_config.ipv6_default_router_addr);
  273. break;
  274. case ISCSI_NET_PARAM_IPV6_ADDR_AUTOCFG:
  275. len = sprintf(buf, "%s\n",
  276. (ha->ip_config.ipv6_addl_options &
  277. IPV6_ADDOPT_NEIGHBOR_DISCOVERY_ADDR_ENABLE) ?
  278. "nd" : "static");
  279. break;
  280. case ISCSI_NET_PARAM_IPV6_LINKLOCAL_AUTOCFG:
  281. len = sprintf(buf, "%s\n",
  282. (ha->ip_config.ipv6_addl_options &
  283. IPV6_ADDOPT_AUTOCONFIG_LINK_LOCAL_ADDR) ?
  284. "auto" : "static");
  285. break;
  286. case ISCSI_NET_PARAM_VLAN_ID:
  287. if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4)
  288. len = sprintf(buf, "%d\n",
  289. (ha->ip_config.ipv4_vlan_tag &
  290. ISCSI_MAX_VLAN_ID));
  291. else if (iface->iface_type == ISCSI_IFACE_TYPE_IPV6)
  292. len = sprintf(buf, "%d\n",
  293. (ha->ip_config.ipv6_vlan_tag &
  294. ISCSI_MAX_VLAN_ID));
  295. break;
  296. case ISCSI_NET_PARAM_VLAN_PRIORITY:
  297. if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4)
  298. len = sprintf(buf, "%d\n",
  299. ((ha->ip_config.ipv4_vlan_tag >> 13) &
  300. ISCSI_MAX_VLAN_PRIORITY));
  301. else if (iface->iface_type == ISCSI_IFACE_TYPE_IPV6)
  302. len = sprintf(buf, "%d\n",
  303. ((ha->ip_config.ipv6_vlan_tag >> 13) &
  304. ISCSI_MAX_VLAN_PRIORITY));
  305. break;
  306. case ISCSI_NET_PARAM_VLAN_ENABLED:
  307. if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4)
  308. len = sprintf(buf, "%s\n",
  309. (ha->ip_config.ipv4_options &
  310. IPOPT_VLAN_TAGGING_ENABLE) ?
  311. "enabled" : "disabled");
  312. else if (iface->iface_type == ISCSI_IFACE_TYPE_IPV6)
  313. len = sprintf(buf, "%s\n",
  314. (ha->ip_config.ipv6_options &
  315. IPV6_OPT_VLAN_TAGGING_ENABLE) ?
  316. "enabled" : "disabled");
  317. break;
  318. case ISCSI_NET_PARAM_MTU:
  319. len = sprintf(buf, "%d\n", ha->ip_config.eth_mtu_size);
  320. break;
  321. case ISCSI_NET_PARAM_PORT:
  322. if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4)
  323. len = sprintf(buf, "%d\n", ha->ip_config.ipv4_port);
  324. else if (iface->iface_type == ISCSI_IFACE_TYPE_IPV6)
  325. len = sprintf(buf, "%d\n", ha->ip_config.ipv6_port);
  326. break;
  327. default:
  328. len = -ENOSYS;
  329. }
  330. return len;
  331. }
  332. static struct iscsi_endpoint *
  333. qla4xxx_ep_connect(struct Scsi_Host *shost, struct sockaddr *dst_addr,
  334. int non_blocking)
  335. {
  336. int ret;
  337. struct iscsi_endpoint *ep;
  338. struct qla_endpoint *qla_ep;
  339. struct scsi_qla_host *ha;
  340. struct sockaddr_in *addr;
  341. struct sockaddr_in6 *addr6;
  342. DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
  343. if (!shost) {
  344. ret = -ENXIO;
  345. printk(KERN_ERR "%s: shost is NULL\n",
  346. __func__);
  347. return ERR_PTR(ret);
  348. }
  349. ha = iscsi_host_priv(shost);
  350. ep = iscsi_create_endpoint(sizeof(struct qla_endpoint));
  351. if (!ep) {
  352. ret = -ENOMEM;
  353. return ERR_PTR(ret);
  354. }
  355. qla_ep = ep->dd_data;
  356. memset(qla_ep, 0, sizeof(struct qla_endpoint));
  357. if (dst_addr->sa_family == AF_INET) {
  358. memcpy(&qla_ep->dst_addr, dst_addr, sizeof(struct sockaddr_in));
  359. addr = (struct sockaddr_in *)&qla_ep->dst_addr;
  360. DEBUG2(ql4_printk(KERN_INFO, ha, "%s: %pI4\n", __func__,
  361. (char *)&addr->sin_addr));
  362. } else if (dst_addr->sa_family == AF_INET6) {
  363. memcpy(&qla_ep->dst_addr, dst_addr,
  364. sizeof(struct sockaddr_in6));
  365. addr6 = (struct sockaddr_in6 *)&qla_ep->dst_addr;
  366. DEBUG2(ql4_printk(KERN_INFO, ha, "%s: %pI6\n", __func__,
  367. (char *)&addr6->sin6_addr));
  368. }
  369. qla_ep->host = shost;
  370. return ep;
  371. }
  372. static int qla4xxx_ep_poll(struct iscsi_endpoint *ep, int timeout_ms)
  373. {
  374. struct qla_endpoint *qla_ep;
  375. struct scsi_qla_host *ha;
  376. int ret = 0;
  377. DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
  378. qla_ep = ep->dd_data;
  379. ha = to_qla_host(qla_ep->host);
  380. if (adapter_up(ha))
  381. ret = 1;
  382. return ret;
  383. }
  384. static void qla4xxx_ep_disconnect(struct iscsi_endpoint *ep)
  385. {
  386. DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
  387. iscsi_destroy_endpoint(ep);
  388. }
  389. static int qla4xxx_get_ep_param(struct iscsi_endpoint *ep,
  390. enum iscsi_param param,
  391. char *buf)
  392. {
  393. struct qla_endpoint *qla_ep = ep->dd_data;
  394. struct sockaddr *dst_addr;
  395. DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
  396. switch (param) {
  397. case ISCSI_PARAM_CONN_PORT:
  398. case ISCSI_PARAM_CONN_ADDRESS:
  399. if (!qla_ep)
  400. return -ENOTCONN;
  401. dst_addr = (struct sockaddr *)&qla_ep->dst_addr;
  402. if (!dst_addr)
  403. return -ENOTCONN;
  404. return iscsi_conn_get_addr_param((struct sockaddr_storage *)
  405. &qla_ep->dst_addr, param, buf);
  406. default:
  407. return -ENOSYS;
  408. }
  409. }
  410. static void qla4xxx_conn_get_stats(struct iscsi_cls_conn *cls_conn,
  411. struct iscsi_stats *stats)
  412. {
  413. struct iscsi_session *sess;
  414. struct iscsi_cls_session *cls_sess;
  415. struct ddb_entry *ddb_entry;
  416. struct scsi_qla_host *ha;
  417. struct ql_iscsi_stats *ql_iscsi_stats;
  418. int stats_size;
  419. int ret;
  420. dma_addr_t iscsi_stats_dma;
  421. DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
  422. cls_sess = iscsi_conn_to_session(cls_conn);
  423. sess = cls_sess->dd_data;
  424. ddb_entry = sess->dd_data;
  425. ha = ddb_entry->ha;
  426. stats_size = PAGE_ALIGN(sizeof(struct ql_iscsi_stats));
  427. /* Allocate memory */
  428. ql_iscsi_stats = dma_alloc_coherent(&ha->pdev->dev, stats_size,
  429. &iscsi_stats_dma, GFP_KERNEL);
  430. if (!ql_iscsi_stats) {
  431. ql4_printk(KERN_ERR, ha,
  432. "Unable to allocate memory for iscsi stats\n");
  433. goto exit_get_stats;
  434. }
  435. ret = qla4xxx_get_mgmt_data(ha, ddb_entry->fw_ddb_index, stats_size,
  436. iscsi_stats_dma);
  437. if (ret != QLA_SUCCESS) {
  438. ql4_printk(KERN_ERR, ha,
  439. "Unable to retreive iscsi stats\n");
  440. goto free_stats;
  441. }
  442. /* octets */
  443. stats->txdata_octets = le64_to_cpu(ql_iscsi_stats->tx_data_octets);
  444. stats->rxdata_octets = le64_to_cpu(ql_iscsi_stats->rx_data_octets);
  445. /* xmit pdus */
  446. stats->noptx_pdus = le32_to_cpu(ql_iscsi_stats->tx_nopout_pdus);
  447. stats->scsicmd_pdus = le32_to_cpu(ql_iscsi_stats->tx_scsi_cmd_pdus);
  448. stats->tmfcmd_pdus = le32_to_cpu(ql_iscsi_stats->tx_tmf_cmd_pdus);
  449. stats->login_pdus = le32_to_cpu(ql_iscsi_stats->tx_login_cmd_pdus);
  450. stats->text_pdus = le32_to_cpu(ql_iscsi_stats->tx_text_cmd_pdus);
  451. stats->dataout_pdus = le32_to_cpu(ql_iscsi_stats->tx_scsi_write_pdus);
  452. stats->logout_pdus = le32_to_cpu(ql_iscsi_stats->tx_logout_cmd_pdus);
  453. stats->snack_pdus = le32_to_cpu(ql_iscsi_stats->tx_snack_req_pdus);
  454. /* recv pdus */
  455. stats->noprx_pdus = le32_to_cpu(ql_iscsi_stats->rx_nopin_pdus);
  456. stats->scsirsp_pdus = le32_to_cpu(ql_iscsi_stats->rx_scsi_resp_pdus);
  457. stats->tmfrsp_pdus = le32_to_cpu(ql_iscsi_stats->rx_tmf_resp_pdus);
  458. stats->textrsp_pdus = le32_to_cpu(ql_iscsi_stats->rx_text_resp_pdus);
  459. stats->datain_pdus = le32_to_cpu(ql_iscsi_stats->rx_scsi_read_pdus);
  460. stats->logoutrsp_pdus =
  461. le32_to_cpu(ql_iscsi_stats->rx_logout_resp_pdus);
  462. stats->r2t_pdus = le32_to_cpu(ql_iscsi_stats->rx_r2t_pdus);
  463. stats->async_pdus = le32_to_cpu(ql_iscsi_stats->rx_async_pdus);
  464. stats->rjt_pdus = le32_to_cpu(ql_iscsi_stats->rx_reject_pdus);
  465. free_stats:
  466. dma_free_coherent(&ha->pdev->dev, stats_size, ql_iscsi_stats,
  467. iscsi_stats_dma);
  468. exit_get_stats:
  469. return;
  470. }
  471. static enum blk_eh_timer_return qla4xxx_eh_cmd_timed_out(struct scsi_cmnd *sc)
  472. {
  473. struct iscsi_cls_session *session;
  474. struct iscsi_session *sess;
  475. unsigned long flags;
  476. enum blk_eh_timer_return ret = BLK_EH_NOT_HANDLED;
  477. session = starget_to_session(scsi_target(sc->device));
  478. sess = session->dd_data;
  479. spin_lock_irqsave(&session->lock, flags);
  480. if (session->state == ISCSI_SESSION_FAILED)
  481. ret = BLK_EH_RESET_TIMER;
  482. spin_unlock_irqrestore(&session->lock, flags);
  483. return ret;
  484. }
  485. static int qla4xxx_host_get_param(struct Scsi_Host *shost,
  486. enum iscsi_host_param param, char *buf)
  487. {
  488. struct scsi_qla_host *ha = to_qla_host(shost);
  489. int len;
  490. switch (param) {
  491. case ISCSI_HOST_PARAM_HWADDRESS:
  492. len = sysfs_format_mac(buf, ha->my_mac, MAC_ADDR_LEN);
  493. break;
  494. case ISCSI_HOST_PARAM_IPADDRESS:
  495. len = sprintf(buf, "%pI4\n", &ha->ip_config.ip_address);
  496. break;
  497. case ISCSI_HOST_PARAM_INITIATOR_NAME:
  498. len = sprintf(buf, "%s\n", ha->name_string);
  499. break;
  500. default:
  501. return -ENOSYS;
  502. }
  503. return len;
  504. }
  505. static void qla4xxx_create_ipv4_iface(struct scsi_qla_host *ha)
  506. {
  507. if (ha->iface_ipv4)
  508. return;
  509. /* IPv4 */
  510. ha->iface_ipv4 = iscsi_create_iface(ha->host,
  511. &qla4xxx_iscsi_transport,
  512. ISCSI_IFACE_TYPE_IPV4, 0, 0);
  513. if (!ha->iface_ipv4)
  514. ql4_printk(KERN_ERR, ha, "Could not create IPv4 iSCSI "
  515. "iface0.\n");
  516. }
  517. static void qla4xxx_create_ipv6_iface(struct scsi_qla_host *ha)
  518. {
  519. if (!ha->iface_ipv6_0)
  520. /* IPv6 iface-0 */
  521. ha->iface_ipv6_0 = iscsi_create_iface(ha->host,
  522. &qla4xxx_iscsi_transport,
  523. ISCSI_IFACE_TYPE_IPV6, 0,
  524. 0);
  525. if (!ha->iface_ipv6_0)
  526. ql4_printk(KERN_ERR, ha, "Could not create IPv6 iSCSI "
  527. "iface0.\n");
  528. if (!ha->iface_ipv6_1)
  529. /* IPv6 iface-1 */
  530. ha->iface_ipv6_1 = iscsi_create_iface(ha->host,
  531. &qla4xxx_iscsi_transport,
  532. ISCSI_IFACE_TYPE_IPV6, 1,
  533. 0);
  534. if (!ha->iface_ipv6_1)
  535. ql4_printk(KERN_ERR, ha, "Could not create IPv6 iSCSI "
  536. "iface1.\n");
  537. }
  538. static void qla4xxx_create_ifaces(struct scsi_qla_host *ha)
  539. {
  540. if (ha->ip_config.ipv4_options & IPOPT_IPV4_PROTOCOL_ENABLE)
  541. qla4xxx_create_ipv4_iface(ha);
  542. if (ha->ip_config.ipv6_options & IPV6_OPT_IPV6_PROTOCOL_ENABLE)
  543. qla4xxx_create_ipv6_iface(ha);
  544. }
  545. static void qla4xxx_destroy_ipv4_iface(struct scsi_qla_host *ha)
  546. {
  547. if (ha->iface_ipv4) {
  548. iscsi_destroy_iface(ha->iface_ipv4);
  549. ha->iface_ipv4 = NULL;
  550. }
  551. }
  552. static void qla4xxx_destroy_ipv6_iface(struct scsi_qla_host *ha)
  553. {
  554. if (ha->iface_ipv6_0) {
  555. iscsi_destroy_iface(ha->iface_ipv6_0);
  556. ha->iface_ipv6_0 = NULL;
  557. }
  558. if (ha->iface_ipv6_1) {
  559. iscsi_destroy_iface(ha->iface_ipv6_1);
  560. ha->iface_ipv6_1 = NULL;
  561. }
  562. }
  563. static void qla4xxx_destroy_ifaces(struct scsi_qla_host *ha)
  564. {
  565. qla4xxx_destroy_ipv4_iface(ha);
  566. qla4xxx_destroy_ipv6_iface(ha);
  567. }
  568. static void qla4xxx_set_ipv6(struct scsi_qla_host *ha,
  569. struct iscsi_iface_param_info *iface_param,
  570. struct addr_ctrl_blk *init_fw_cb)
  571. {
  572. /*
  573. * iface_num 0 is valid for IPv6 Addr, linklocal, router, autocfg.
  574. * iface_num 1 is valid only for IPv6 Addr.
  575. */
  576. switch (iface_param->param) {
  577. case ISCSI_NET_PARAM_IPV6_ADDR:
  578. if (iface_param->iface_num & 0x1)
  579. /* IPv6 Addr 1 */
  580. memcpy(init_fw_cb->ipv6_addr1, iface_param->value,
  581. sizeof(init_fw_cb->ipv6_addr1));
  582. else
  583. /* IPv6 Addr 0 */
  584. memcpy(init_fw_cb->ipv6_addr0, iface_param->value,
  585. sizeof(init_fw_cb->ipv6_addr0));
  586. break;
  587. case ISCSI_NET_PARAM_IPV6_LINKLOCAL:
  588. if (iface_param->iface_num & 0x1)
  589. break;
  590. memcpy(init_fw_cb->ipv6_if_id, &iface_param->value[8],
  591. sizeof(init_fw_cb->ipv6_if_id));
  592. break;
  593. case ISCSI_NET_PARAM_IPV6_ROUTER:
  594. if (iface_param->iface_num & 0x1)
  595. break;
  596. memcpy(init_fw_cb->ipv6_dflt_rtr_addr, iface_param->value,
  597. sizeof(init_fw_cb->ipv6_dflt_rtr_addr));
  598. break;
  599. case ISCSI_NET_PARAM_IPV6_ADDR_AUTOCFG:
  600. /* Autocfg applies to even interface */
  601. if (iface_param->iface_num & 0x1)
  602. break;
  603. if (iface_param->value[0] == ISCSI_IPV6_AUTOCFG_DISABLE)
  604. init_fw_cb->ipv6_addtl_opts &=
  605. cpu_to_le16(
  606. ~IPV6_ADDOPT_NEIGHBOR_DISCOVERY_ADDR_ENABLE);
  607. else if (iface_param->value[0] == ISCSI_IPV6_AUTOCFG_ND_ENABLE)
  608. init_fw_cb->ipv6_addtl_opts |=
  609. cpu_to_le16(
  610. IPV6_ADDOPT_NEIGHBOR_DISCOVERY_ADDR_ENABLE);
  611. else
  612. ql4_printk(KERN_ERR, ha, "Invalid autocfg setting for "
  613. "IPv6 addr\n");
  614. break;
  615. case ISCSI_NET_PARAM_IPV6_LINKLOCAL_AUTOCFG:
  616. /* Autocfg applies to even interface */
  617. if (iface_param->iface_num & 0x1)
  618. break;
  619. if (iface_param->value[0] ==
  620. ISCSI_IPV6_LINKLOCAL_AUTOCFG_ENABLE)
  621. init_fw_cb->ipv6_addtl_opts |= cpu_to_le16(
  622. IPV6_ADDOPT_AUTOCONFIG_LINK_LOCAL_ADDR);
  623. else if (iface_param->value[0] ==
  624. ISCSI_IPV6_LINKLOCAL_AUTOCFG_DISABLE)
  625. init_fw_cb->ipv6_addtl_opts &= cpu_to_le16(
  626. ~IPV6_ADDOPT_AUTOCONFIG_LINK_LOCAL_ADDR);
  627. else
  628. ql4_printk(KERN_ERR, ha, "Invalid autocfg setting for "
  629. "IPv6 linklocal addr\n");
  630. break;
  631. case ISCSI_NET_PARAM_IPV6_ROUTER_AUTOCFG:
  632. /* Autocfg applies to even interface */
  633. if (iface_param->iface_num & 0x1)
  634. break;
  635. if (iface_param->value[0] == ISCSI_IPV6_ROUTER_AUTOCFG_ENABLE)
  636. memset(init_fw_cb->ipv6_dflt_rtr_addr, 0,
  637. sizeof(init_fw_cb->ipv6_dflt_rtr_addr));
  638. break;
  639. case ISCSI_NET_PARAM_IFACE_ENABLE:
  640. if (iface_param->value[0] == ISCSI_IFACE_ENABLE) {
  641. init_fw_cb->ipv6_opts |=
  642. cpu_to_le16(IPV6_OPT_IPV6_PROTOCOL_ENABLE);
  643. qla4xxx_create_ipv6_iface(ha);
  644. } else {
  645. init_fw_cb->ipv6_opts &=
  646. cpu_to_le16(~IPV6_OPT_IPV6_PROTOCOL_ENABLE &
  647. 0xFFFF);
  648. qla4xxx_destroy_ipv6_iface(ha);
  649. }
  650. break;
  651. case ISCSI_NET_PARAM_VLAN_ID:
  652. if (iface_param->len != sizeof(init_fw_cb->ipv6_vlan_tag))
  653. break;
  654. init_fw_cb->ipv6_vlan_tag =
  655. cpu_to_be16(*(uint16_t *)iface_param->value);
  656. break;
  657. case ISCSI_NET_PARAM_VLAN_ENABLED:
  658. if (iface_param->value[0] == ISCSI_VLAN_ENABLE)
  659. init_fw_cb->ipv6_opts |=
  660. cpu_to_le16(IPV6_OPT_VLAN_TAGGING_ENABLE);
  661. else
  662. init_fw_cb->ipv6_opts &=
  663. cpu_to_le16(~IPV6_OPT_VLAN_TAGGING_ENABLE);
  664. break;
  665. case ISCSI_NET_PARAM_MTU:
  666. init_fw_cb->eth_mtu_size =
  667. cpu_to_le16(*(uint16_t *)iface_param->value);
  668. break;
  669. case ISCSI_NET_PARAM_PORT:
  670. /* Autocfg applies to even interface */
  671. if (iface_param->iface_num & 0x1)
  672. break;
  673. init_fw_cb->ipv6_port =
  674. cpu_to_le16(*(uint16_t *)iface_param->value);
  675. break;
  676. default:
  677. ql4_printk(KERN_ERR, ha, "Unknown IPv6 param = %d\n",
  678. iface_param->param);
  679. break;
  680. }
  681. }
  682. static void qla4xxx_set_ipv4(struct scsi_qla_host *ha,
  683. struct iscsi_iface_param_info *iface_param,
  684. struct addr_ctrl_blk *init_fw_cb)
  685. {
  686. switch (iface_param->param) {
  687. case ISCSI_NET_PARAM_IPV4_ADDR:
  688. memcpy(init_fw_cb->ipv4_addr, iface_param->value,
  689. sizeof(init_fw_cb->ipv4_addr));
  690. break;
  691. case ISCSI_NET_PARAM_IPV4_SUBNET:
  692. memcpy(init_fw_cb->ipv4_subnet, iface_param->value,
  693. sizeof(init_fw_cb->ipv4_subnet));
  694. break;
  695. case ISCSI_NET_PARAM_IPV4_GW:
  696. memcpy(init_fw_cb->ipv4_gw_addr, iface_param->value,
  697. sizeof(init_fw_cb->ipv4_gw_addr));
  698. break;
  699. case ISCSI_NET_PARAM_IPV4_BOOTPROTO:
  700. if (iface_param->value[0] == ISCSI_BOOTPROTO_DHCP)
  701. init_fw_cb->ipv4_tcp_opts |=
  702. cpu_to_le16(TCPOPT_DHCP_ENABLE);
  703. else if (iface_param->value[0] == ISCSI_BOOTPROTO_STATIC)
  704. init_fw_cb->ipv4_tcp_opts &=
  705. cpu_to_le16(~TCPOPT_DHCP_ENABLE);
  706. else
  707. ql4_printk(KERN_ERR, ha, "Invalid IPv4 bootproto\n");
  708. break;
  709. case ISCSI_NET_PARAM_IFACE_ENABLE:
  710. if (iface_param->value[0] == ISCSI_IFACE_ENABLE) {
  711. init_fw_cb->ipv4_ip_opts |=
  712. cpu_to_le16(IPOPT_IPV4_PROTOCOL_ENABLE);
  713. qla4xxx_create_ipv4_iface(ha);
  714. } else {
  715. init_fw_cb->ipv4_ip_opts &=
  716. cpu_to_le16(~IPOPT_IPV4_PROTOCOL_ENABLE &
  717. 0xFFFF);
  718. qla4xxx_destroy_ipv4_iface(ha);
  719. }
  720. break;
  721. case ISCSI_NET_PARAM_VLAN_ID:
  722. if (iface_param->len != sizeof(init_fw_cb->ipv4_vlan_tag))
  723. break;
  724. init_fw_cb->ipv4_vlan_tag =
  725. cpu_to_be16(*(uint16_t *)iface_param->value);
  726. break;
  727. case ISCSI_NET_PARAM_VLAN_ENABLED:
  728. if (iface_param->value[0] == ISCSI_VLAN_ENABLE)
  729. init_fw_cb->ipv4_ip_opts |=
  730. cpu_to_le16(IPOPT_VLAN_TAGGING_ENABLE);
  731. else
  732. init_fw_cb->ipv4_ip_opts &=
  733. cpu_to_le16(~IPOPT_VLAN_TAGGING_ENABLE);
  734. break;
  735. case ISCSI_NET_PARAM_MTU:
  736. init_fw_cb->eth_mtu_size =
  737. cpu_to_le16(*(uint16_t *)iface_param->value);
  738. break;
  739. case ISCSI_NET_PARAM_PORT:
  740. init_fw_cb->ipv4_port =
  741. cpu_to_le16(*(uint16_t *)iface_param->value);
  742. break;
  743. default:
  744. ql4_printk(KERN_ERR, ha, "Unknown IPv4 param = %d\n",
  745. iface_param->param);
  746. break;
  747. }
  748. }
  749. static void
  750. qla4xxx_initcb_to_acb(struct addr_ctrl_blk *init_fw_cb)
  751. {
  752. struct addr_ctrl_blk_def *acb;
  753. acb = (struct addr_ctrl_blk_def *)init_fw_cb;
  754. memset(acb->reserved1, 0, sizeof(acb->reserved1));
  755. memset(acb->reserved2, 0, sizeof(acb->reserved2));
  756. memset(acb->reserved3, 0, sizeof(acb->reserved3));
  757. memset(acb->reserved4, 0, sizeof(acb->reserved4));
  758. memset(acb->reserved5, 0, sizeof(acb->reserved5));
  759. memset(acb->reserved6, 0, sizeof(acb->reserved6));
  760. memset(acb->reserved7, 0, sizeof(acb->reserved7));
  761. memset(acb->reserved8, 0, sizeof(acb->reserved8));
  762. memset(acb->reserved9, 0, sizeof(acb->reserved9));
  763. memset(acb->reserved10, 0, sizeof(acb->reserved10));
  764. memset(acb->reserved11, 0, sizeof(acb->reserved11));
  765. memset(acb->reserved12, 0, sizeof(acb->reserved12));
  766. memset(acb->reserved13, 0, sizeof(acb->reserved13));
  767. memset(acb->reserved14, 0, sizeof(acb->reserved14));
  768. memset(acb->reserved15, 0, sizeof(acb->reserved15));
  769. }
  770. static int
  771. qla4xxx_iface_set_param(struct Scsi_Host *shost, char *data, int count)
  772. {
  773. struct scsi_qla_host *ha = to_qla_host(shost);
  774. int rval = 0;
  775. struct iscsi_iface_param_info *iface_param = NULL;
  776. struct addr_ctrl_blk *init_fw_cb = NULL;
  777. dma_addr_t init_fw_cb_dma;
  778. uint32_t mbox_cmd[MBOX_REG_COUNT];
  779. uint32_t mbox_sts[MBOX_REG_COUNT];
  780. uint32_t total_param_count;
  781. uint32_t length;
  782. init_fw_cb = dma_alloc_coherent(&ha->pdev->dev,
  783. sizeof(struct addr_ctrl_blk),
  784. &init_fw_cb_dma, GFP_KERNEL);
  785. if (!init_fw_cb) {
  786. ql4_printk(KERN_ERR, ha, "%s: Unable to alloc init_cb\n",
  787. __func__);
  788. return -ENOMEM;
  789. }
  790. memset(init_fw_cb, 0, sizeof(struct addr_ctrl_blk));
  791. memset(&mbox_cmd, 0, sizeof(mbox_cmd));
  792. memset(&mbox_sts, 0, sizeof(mbox_sts));
  793. if (qla4xxx_get_ifcb(ha, &mbox_cmd[0], &mbox_sts[0], init_fw_cb_dma)) {
  794. ql4_printk(KERN_ERR, ha, "%s: get ifcb failed\n", __func__);
  795. rval = -EIO;
  796. goto exit_init_fw_cb;
  797. }
  798. total_param_count = count;
  799. iface_param = (struct iscsi_iface_param_info *)data;
  800. for ( ; total_param_count != 0; total_param_count--) {
  801. length = iface_param->len;
  802. if (iface_param->param_type != ISCSI_NET_PARAM)
  803. continue;
  804. switch (iface_param->iface_type) {
  805. case ISCSI_IFACE_TYPE_IPV4:
  806. switch (iface_param->iface_num) {
  807. case 0:
  808. qla4xxx_set_ipv4(ha, iface_param, init_fw_cb);
  809. break;
  810. default:
  811. /* Cannot have more than one IPv4 interface */
  812. ql4_printk(KERN_ERR, ha, "Invalid IPv4 iface "
  813. "number = %d\n",
  814. iface_param->iface_num);
  815. break;
  816. }
  817. break;
  818. case ISCSI_IFACE_TYPE_IPV6:
  819. switch (iface_param->iface_num) {
  820. case 0:
  821. case 1:
  822. qla4xxx_set_ipv6(ha, iface_param, init_fw_cb);
  823. break;
  824. default:
  825. /* Cannot have more than two IPv6 interface */
  826. ql4_printk(KERN_ERR, ha, "Invalid IPv6 iface "
  827. "number = %d\n",
  828. iface_param->iface_num);
  829. break;
  830. }
  831. break;
  832. default:
  833. ql4_printk(KERN_ERR, ha, "Invalid iface type\n");
  834. break;
  835. }
  836. iface_param = (struct iscsi_iface_param_info *)
  837. ((uint8_t *)iface_param +
  838. sizeof(struct iscsi_iface_param_info) + length);
  839. }
  840. init_fw_cb->cookie = cpu_to_le32(0x11BEAD5A);
  841. rval = qla4xxx_set_flash(ha, init_fw_cb_dma, FLASH_SEGMENT_IFCB,
  842. sizeof(struct addr_ctrl_blk),
  843. FLASH_OPT_RMW_COMMIT);
  844. if (rval != QLA_SUCCESS) {
  845. ql4_printk(KERN_ERR, ha, "%s: set flash mbx failed\n",
  846. __func__);
  847. rval = -EIO;
  848. goto exit_init_fw_cb;
  849. }
  850. qla4xxx_disable_acb(ha);
  851. qla4xxx_initcb_to_acb(init_fw_cb);
  852. rval = qla4xxx_set_acb(ha, &mbox_cmd[0], &mbox_sts[0], init_fw_cb_dma);
  853. if (rval != QLA_SUCCESS) {
  854. ql4_printk(KERN_ERR, ha, "%s: set acb mbx failed\n",
  855. __func__);
  856. rval = -EIO;
  857. goto exit_init_fw_cb;
  858. }
  859. memset(init_fw_cb, 0, sizeof(struct addr_ctrl_blk));
  860. qla4xxx_update_local_ifcb(ha, &mbox_cmd[0], &mbox_sts[0], init_fw_cb,
  861. init_fw_cb_dma);
  862. exit_init_fw_cb:
  863. dma_free_coherent(&ha->pdev->dev, sizeof(struct addr_ctrl_blk),
  864. init_fw_cb, init_fw_cb_dma);
  865. return rval;
  866. }
  867. static int qla4xxx_conn_get_param(struct iscsi_cls_conn *cls_conn,
  868. enum iscsi_param param, char *buf)
  869. {
  870. struct iscsi_conn *conn;
  871. struct qla_conn *qla_conn;
  872. struct sockaddr *dst_addr;
  873. int len = 0;
  874. conn = cls_conn->dd_data;
  875. qla_conn = conn->dd_data;
  876. dst_addr = &qla_conn->qla_ep->dst_addr;
  877. switch (param) {
  878. case ISCSI_PARAM_CONN_PORT:
  879. case ISCSI_PARAM_CONN_ADDRESS:
  880. return iscsi_conn_get_addr_param((struct sockaddr_storage *)
  881. dst_addr, param, buf);
  882. default:
  883. return iscsi_conn_get_param(cls_conn, param, buf);
  884. }
  885. return len;
  886. }
  887. static struct iscsi_cls_session *
  888. qla4xxx_session_create(struct iscsi_endpoint *ep,
  889. uint16_t cmds_max, uint16_t qdepth,
  890. uint32_t initial_cmdsn)
  891. {
  892. struct iscsi_cls_session *cls_sess;
  893. struct scsi_qla_host *ha;
  894. struct qla_endpoint *qla_ep;
  895. struct ddb_entry *ddb_entry;
  896. uint32_t ddb_index;
  897. uint32_t mbx_sts = 0;
  898. struct iscsi_session *sess;
  899. struct sockaddr *dst_addr;
  900. int ret;
  901. DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
  902. if (!ep) {
  903. printk(KERN_ERR "qla4xxx: missing ep.\n");
  904. return NULL;
  905. }
  906. qla_ep = ep->dd_data;
  907. dst_addr = (struct sockaddr *)&qla_ep->dst_addr;
  908. ha = to_qla_host(qla_ep->host);
  909. get_ddb_index:
  910. ddb_index = find_first_zero_bit(ha->ddb_idx_map, MAX_DDB_ENTRIES);
  911. if (ddb_index >= MAX_DDB_ENTRIES) {
  912. DEBUG2(ql4_printk(KERN_INFO, ha,
  913. "Free DDB index not available\n"));
  914. return NULL;
  915. }
  916. if (test_and_set_bit(ddb_index, ha->ddb_idx_map))
  917. goto get_ddb_index;
  918. DEBUG2(ql4_printk(KERN_INFO, ha,
  919. "Found a free DDB index at %d\n", ddb_index));
  920. ret = qla4xxx_req_ddb_entry(ha, ddb_index, &mbx_sts);
  921. if (ret == QLA_ERROR) {
  922. if (mbx_sts == MBOX_STS_COMMAND_ERROR) {
  923. ql4_printk(KERN_INFO, ha,
  924. "DDB index = %d not available trying next\n",
  925. ddb_index);
  926. goto get_ddb_index;
  927. }
  928. DEBUG2(ql4_printk(KERN_INFO, ha,
  929. "Free FW DDB not available\n"));
  930. return NULL;
  931. }
  932. cls_sess = iscsi_session_setup(&qla4xxx_iscsi_transport, qla_ep->host,
  933. cmds_max, sizeof(struct ddb_entry),
  934. sizeof(struct ql4_task_data),
  935. initial_cmdsn, ddb_index);
  936. if (!cls_sess)
  937. return NULL;
  938. sess = cls_sess->dd_data;
  939. ddb_entry = sess->dd_data;
  940. ddb_entry->fw_ddb_index = ddb_index;
  941. ddb_entry->fw_ddb_device_state = DDB_DS_NO_CONNECTION_ACTIVE;
  942. ddb_entry->ha = ha;
  943. ddb_entry->sess = cls_sess;
  944. cls_sess->recovery_tmo = ql4xsess_recovery_tmo;
  945. ha->fw_ddb_index_map[ddb_entry->fw_ddb_index] = ddb_entry;
  946. ha->tot_ddbs++;
  947. return cls_sess;
  948. }
  949. static void qla4xxx_session_destroy(struct iscsi_cls_session *cls_sess)
  950. {
  951. struct iscsi_session *sess;
  952. struct ddb_entry *ddb_entry;
  953. struct scsi_qla_host *ha;
  954. unsigned long flags;
  955. DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
  956. sess = cls_sess->dd_data;
  957. ddb_entry = sess->dd_data;
  958. ha = ddb_entry->ha;
  959. qla4xxx_clear_ddb_entry(ha, ddb_entry->fw_ddb_index);
  960. spin_lock_irqsave(&ha->hardware_lock, flags);
  961. qla4xxx_free_ddb(ha, ddb_entry);
  962. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  963. iscsi_session_teardown(cls_sess);
  964. }
  965. static struct iscsi_cls_conn *
  966. qla4xxx_conn_create(struct iscsi_cls_session *cls_sess, uint32_t conn_idx)
  967. {
  968. struct iscsi_cls_conn *cls_conn;
  969. struct iscsi_session *sess;
  970. struct ddb_entry *ddb_entry;
  971. DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
  972. cls_conn = iscsi_conn_setup(cls_sess, sizeof(struct qla_conn),
  973. conn_idx);
  974. sess = cls_sess->dd_data;
  975. ddb_entry = sess->dd_data;
  976. ddb_entry->conn = cls_conn;
  977. return cls_conn;
  978. }
  979. static int qla4xxx_conn_bind(struct iscsi_cls_session *cls_session,
  980. struct iscsi_cls_conn *cls_conn,
  981. uint64_t transport_fd, int is_leading)
  982. {
  983. struct iscsi_conn *conn;
  984. struct qla_conn *qla_conn;
  985. struct iscsi_endpoint *ep;
  986. DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
  987. if (iscsi_conn_bind(cls_session, cls_conn, is_leading))
  988. return -EINVAL;
  989. ep = iscsi_lookup_endpoint(transport_fd);
  990. conn = cls_conn->dd_data;
  991. qla_conn = conn->dd_data;
  992. qla_conn->qla_ep = ep->dd_data;
  993. return 0;
  994. }
  995. static int qla4xxx_conn_start(struct iscsi_cls_conn *cls_conn)
  996. {
  997. struct iscsi_cls_session *cls_sess = iscsi_conn_to_session(cls_conn);
  998. struct iscsi_session *sess;
  999. struct ddb_entry *ddb_entry;
  1000. struct scsi_qla_host *ha;
  1001. struct dev_db_entry *fw_ddb_entry;
  1002. dma_addr_t fw_ddb_entry_dma;
  1003. uint32_t mbx_sts = 0;
  1004. int ret = 0;
  1005. int status = QLA_SUCCESS;
  1006. DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
  1007. sess = cls_sess->dd_data;
  1008. ddb_entry = sess->dd_data;
  1009. ha = ddb_entry->ha;
  1010. fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
  1011. &fw_ddb_entry_dma, GFP_KERNEL);
  1012. if (!fw_ddb_entry) {
  1013. ql4_printk(KERN_ERR, ha,
  1014. "%s: Unable to allocate dma buffer\n", __func__);
  1015. return -ENOMEM;
  1016. }
  1017. ret = qla4xxx_set_param_ddbentry(ha, ddb_entry, cls_conn, &mbx_sts);
  1018. if (ret) {
  1019. /* If iscsid is stopped and started then no need to do
  1020. * set param again since ddb state will be already
  1021. * active and FW does not allow set ddb to an
  1022. * active session.
  1023. */
  1024. if (mbx_sts)
  1025. if (ddb_entry->fw_ddb_device_state ==
  1026. DDB_DS_SESSION_ACTIVE)
  1027. goto exit_set_param;
  1028. ql4_printk(KERN_ERR, ha, "%s: Failed set param for index[%d]\n",
  1029. __func__, ddb_entry->fw_ddb_index);
  1030. goto exit_conn_start;
  1031. }
  1032. status = qla4xxx_conn_open(ha, ddb_entry->fw_ddb_index);
  1033. if (status == QLA_ERROR) {
  1034. ql4_printk(KERN_ERR, ha, "%s: Login failed: %s\n", __func__,
  1035. sess->targetname);
  1036. ret = -EINVAL;
  1037. goto exit_conn_start;
  1038. }
  1039. if (ddb_entry->fw_ddb_device_state == DDB_DS_NO_CONNECTION_ACTIVE)
  1040. ddb_entry->fw_ddb_device_state = DDB_DS_LOGIN_IN_PROCESS;
  1041. DEBUG2(printk(KERN_INFO "%s: DDB state [%d]\n", __func__,
  1042. ddb_entry->fw_ddb_device_state));
  1043. exit_set_param:
  1044. iscsi_conn_start(cls_conn);
  1045. ret = 0;
  1046. exit_conn_start:
  1047. dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
  1048. fw_ddb_entry, fw_ddb_entry_dma);
  1049. return ret;
  1050. }
  1051. static void qla4xxx_conn_destroy(struct iscsi_cls_conn *cls_conn)
  1052. {
  1053. struct iscsi_cls_session *cls_sess = iscsi_conn_to_session(cls_conn);
  1054. struct iscsi_session *sess;
  1055. struct scsi_qla_host *ha;
  1056. struct ddb_entry *ddb_entry;
  1057. int options;
  1058. DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
  1059. sess = cls_sess->dd_data;
  1060. ddb_entry = sess->dd_data;
  1061. ha = ddb_entry->ha;
  1062. options = LOGOUT_OPTION_CLOSE_SESSION;
  1063. if (qla4xxx_session_logout_ddb(ha, ddb_entry, options) == QLA_ERROR)
  1064. ql4_printk(KERN_ERR, ha, "%s: Logout failed\n", __func__);
  1065. }
  1066. static void qla4xxx_task_work(struct work_struct *wdata)
  1067. {
  1068. struct ql4_task_data *task_data;
  1069. struct scsi_qla_host *ha;
  1070. struct passthru_status *sts;
  1071. struct iscsi_task *task;
  1072. struct iscsi_hdr *hdr;
  1073. uint8_t *data;
  1074. uint32_t data_len;
  1075. struct iscsi_conn *conn;
  1076. int hdr_len;
  1077. itt_t itt;
  1078. task_data = container_of(wdata, struct ql4_task_data, task_work);
  1079. ha = task_data->ha;
  1080. task = task_data->task;
  1081. sts = &task_data->sts;
  1082. hdr_len = sizeof(struct iscsi_hdr);
  1083. DEBUG3(printk(KERN_INFO "Status returned\n"));
  1084. DEBUG3(qla4xxx_dump_buffer(sts, 64));
  1085. DEBUG3(printk(KERN_INFO "Response buffer"));
  1086. DEBUG3(qla4xxx_dump_buffer(task_data->resp_buffer, 64));
  1087. conn = task->conn;
  1088. switch (sts->completionStatus) {
  1089. case PASSTHRU_STATUS_COMPLETE:
  1090. hdr = (struct iscsi_hdr *)task_data->resp_buffer;
  1091. /* Assign back the itt in hdr, until we use the PREASSIGN_TAG */
  1092. itt = sts->handle;
  1093. hdr->itt = itt;
  1094. data = task_data->resp_buffer + hdr_len;
  1095. data_len = task_data->resp_len - hdr_len;
  1096. iscsi_complete_pdu(conn, hdr, data, data_len);
  1097. break;
  1098. default:
  1099. ql4_printk(KERN_ERR, ha, "Passthru failed status = 0x%x\n",
  1100. sts->completionStatus);
  1101. break;
  1102. }
  1103. return;
  1104. }
  1105. static int qla4xxx_alloc_pdu(struct iscsi_task *task, uint8_t opcode)
  1106. {
  1107. struct ql4_task_data *task_data;
  1108. struct iscsi_session *sess;
  1109. struct ddb_entry *ddb_entry;
  1110. struct scsi_qla_host *ha;
  1111. int hdr_len;
  1112. sess = task->conn->session;
  1113. ddb_entry = sess->dd_data;
  1114. ha = ddb_entry->ha;
  1115. task_data = task->dd_data;
  1116. memset(task_data, 0, sizeof(struct ql4_task_data));
  1117. if (task->sc) {
  1118. ql4_printk(KERN_INFO, ha,
  1119. "%s: SCSI Commands not implemented\n", __func__);
  1120. return -EINVAL;
  1121. }
  1122. hdr_len = sizeof(struct iscsi_hdr);
  1123. task_data->ha = ha;
  1124. task_data->task = task;
  1125. if (task->data_count) {
  1126. task_data->data_dma = dma_map_single(&ha->pdev->dev, task->data,
  1127. task->data_count,
  1128. PCI_DMA_TODEVICE);
  1129. }
  1130. DEBUG2(ql4_printk(KERN_INFO, ha, "%s: MaxRecvLen %u, iscsi hrd %d\n",
  1131. __func__, task->conn->max_recv_dlength, hdr_len));
  1132. task_data->resp_len = task->conn->max_recv_dlength;
  1133. task_data->resp_buffer = dma_alloc_coherent(&ha->pdev->dev,
  1134. task_data->resp_len,
  1135. &task_data->resp_dma,
  1136. GFP_ATOMIC);
  1137. if (!task_data->resp_buffer)
  1138. goto exit_alloc_pdu;
  1139. task_data->req_buffer = dma_alloc_coherent(&ha->pdev->dev,
  1140. task->data_count + hdr_len,
  1141. &task_data->req_dma,
  1142. GFP_ATOMIC);
  1143. if (!task_data->req_buffer)
  1144. goto exit_alloc_pdu;
  1145. task->hdr = task_data->req_buffer;
  1146. INIT_WORK(&task_data->task_work, qla4xxx_task_work);
  1147. return 0;
  1148. exit_alloc_pdu:
  1149. if (task_data->resp_buffer)
  1150. dma_free_coherent(&ha->pdev->dev, task_data->resp_len,
  1151. task_data->resp_buffer, task_data->resp_dma);
  1152. if (task_data->req_buffer)
  1153. dma_free_coherent(&ha->pdev->dev, task->data_count + hdr_len,
  1154. task_data->req_buffer, task_data->req_dma);
  1155. return -ENOMEM;
  1156. }
  1157. static void qla4xxx_task_cleanup(struct iscsi_task *task)
  1158. {
  1159. struct ql4_task_data *task_data;
  1160. struct iscsi_session *sess;
  1161. struct ddb_entry *ddb_entry;
  1162. struct scsi_qla_host *ha;
  1163. int hdr_len;
  1164. hdr_len = sizeof(struct iscsi_hdr);
  1165. sess = task->conn->session;
  1166. ddb_entry = sess->dd_data;
  1167. ha = ddb_entry->ha;
  1168. task_data = task->dd_data;
  1169. if (task->data_count) {
  1170. dma_unmap_single(&ha->pdev->dev, task_data->data_dma,
  1171. task->data_count, PCI_DMA_TODEVICE);
  1172. }
  1173. DEBUG2(ql4_printk(KERN_INFO, ha, "%s: MaxRecvLen %u, iscsi hrd %d\n",
  1174. __func__, task->conn->max_recv_dlength, hdr_len));
  1175. dma_free_coherent(&ha->pdev->dev, task_data->resp_len,
  1176. task_data->resp_buffer, task_data->resp_dma);
  1177. dma_free_coherent(&ha->pdev->dev, task->data_count + hdr_len,
  1178. task_data->req_buffer, task_data->req_dma);
  1179. return;
  1180. }
  1181. static int qla4xxx_task_xmit(struct iscsi_task *task)
  1182. {
  1183. struct scsi_cmnd *sc = task->sc;
  1184. struct iscsi_session *sess = task->conn->session;
  1185. struct ddb_entry *ddb_entry = sess->dd_data;
  1186. struct scsi_qla_host *ha = ddb_entry->ha;
  1187. if (!sc)
  1188. return qla4xxx_send_passthru0(task);
  1189. ql4_printk(KERN_INFO, ha, "%s: scsi cmd xmit not implemented\n",
  1190. __func__);
  1191. return -ENOSYS;
  1192. }
  1193. void qla4xxx_update_session_conn_param(struct scsi_qla_host *ha,
  1194. struct ddb_entry *ddb_entry)
  1195. {
  1196. struct iscsi_cls_session *cls_sess;
  1197. struct iscsi_cls_conn *cls_conn;
  1198. struct iscsi_session *sess;
  1199. struct iscsi_conn *conn;
  1200. uint32_t ddb_state;
  1201. dma_addr_t fw_ddb_entry_dma;
  1202. struct dev_db_entry *fw_ddb_entry;
  1203. fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
  1204. &fw_ddb_entry_dma, GFP_KERNEL);
  1205. if (!fw_ddb_entry) {
  1206. ql4_printk(KERN_ERR, ha,
  1207. "%s: Unable to allocate dma buffer\n", __func__);
  1208. return;
  1209. }
  1210. if (qla4xxx_get_fwddb_entry(ha, ddb_entry->fw_ddb_index, fw_ddb_entry,
  1211. fw_ddb_entry_dma, NULL, NULL, &ddb_state,
  1212. NULL, NULL, NULL) == QLA_ERROR) {
  1213. DEBUG2(ql4_printk(KERN_ERR, ha, "scsi%ld: %s: failed "
  1214. "get_ddb_entry for fw_ddb_index %d\n",
  1215. ha->host_no, __func__,
  1216. ddb_entry->fw_ddb_index));
  1217. return;
  1218. }
  1219. cls_sess = ddb_entry->sess;
  1220. sess = cls_sess->dd_data;
  1221. cls_conn = ddb_entry->conn;
  1222. conn = cls_conn->dd_data;
  1223. /* Update params */
  1224. conn->max_recv_dlength = BYTE_UNITS *
  1225. le16_to_cpu(fw_ddb_entry->iscsi_max_rcv_data_seg_len);
  1226. conn->max_xmit_dlength = BYTE_UNITS *
  1227. le16_to_cpu(fw_ddb_entry->iscsi_max_snd_data_seg_len);
  1228. sess->initial_r2t_en =
  1229. (BIT_10 & le16_to_cpu(fw_ddb_entry->iscsi_options));
  1230. sess->max_r2t = le16_to_cpu(fw_ddb_entry->iscsi_max_outsnd_r2t);
  1231. sess->imm_data_en = (BIT_11 & le16_to_cpu(fw_ddb_entry->iscsi_options));
  1232. sess->first_burst = BYTE_UNITS *
  1233. le16_to_cpu(fw_ddb_entry->iscsi_first_burst_len);
  1234. sess->max_burst = BYTE_UNITS *
  1235. le16_to_cpu(fw_ddb_entry->iscsi_max_burst_len);
  1236. sess->time2wait = le16_to_cpu(fw_ddb_entry->iscsi_def_time2wait);
  1237. sess->time2retain = le16_to_cpu(fw_ddb_entry->iscsi_def_time2retain);
  1238. sess->tpgt = le32_to_cpu(fw_ddb_entry->tgt_portal_grp);
  1239. memcpy(sess->initiatorname, ha->name_string,
  1240. min(sizeof(ha->name_string), sizeof(sess->initiatorname)));
  1241. }
  1242. /*
  1243. * Timer routines
  1244. */
  1245. static void qla4xxx_start_timer(struct scsi_qla_host *ha, void *func,
  1246. unsigned long interval)
  1247. {
  1248. DEBUG(printk("scsi: %s: Starting timer thread for adapter %d\n",
  1249. __func__, ha->host->host_no));
  1250. init_timer(&ha->timer);
  1251. ha->timer.expires = jiffies + interval * HZ;
  1252. ha->timer.data = (unsigned long)ha;
  1253. ha->timer.function = (void (*)(unsigned long))func;
  1254. add_timer(&ha->timer);
  1255. ha->timer_active = 1;
  1256. }
  1257. static void qla4xxx_stop_timer(struct scsi_qla_host *ha)
  1258. {
  1259. del_timer_sync(&ha->timer);
  1260. ha->timer_active = 0;
  1261. }
  1262. /***
  1263. * qla4xxx_mark_device_missing - blocks the session
  1264. * @cls_session: Pointer to the session to be blocked
  1265. * @ddb_entry: Pointer to device database entry
  1266. *
  1267. * This routine marks a device missing and close connection.
  1268. **/
  1269. void qla4xxx_mark_device_missing(struct iscsi_cls_session *cls_session)
  1270. {
  1271. iscsi_block_session(cls_session);
  1272. }
  1273. /**
  1274. * qla4xxx_mark_all_devices_missing - mark all devices as missing.
  1275. * @ha: Pointer to host adapter structure.
  1276. *
  1277. * This routine marks a device missing and resets the relogin retry count.
  1278. **/
  1279. void qla4xxx_mark_all_devices_missing(struct scsi_qla_host *ha)
  1280. {
  1281. iscsi_host_for_each_session(ha->host, qla4xxx_mark_device_missing);
  1282. }
  1283. static struct srb* qla4xxx_get_new_srb(struct scsi_qla_host *ha,
  1284. struct ddb_entry *ddb_entry,
  1285. struct scsi_cmnd *cmd)
  1286. {
  1287. struct srb *srb;
  1288. srb = mempool_alloc(ha->srb_mempool, GFP_ATOMIC);
  1289. if (!srb)
  1290. return srb;
  1291. kref_init(&srb->srb_ref);
  1292. srb->ha = ha;
  1293. srb->ddb = ddb_entry;
  1294. srb->cmd = cmd;
  1295. srb->flags = 0;
  1296. CMD_SP(cmd) = (void *)srb;
  1297. return srb;
  1298. }
  1299. static void qla4xxx_srb_free_dma(struct scsi_qla_host *ha, struct srb *srb)
  1300. {
  1301. struct scsi_cmnd *cmd = srb->cmd;
  1302. if (srb->flags & SRB_DMA_VALID) {
  1303. scsi_dma_unmap(cmd);
  1304. srb->flags &= ~SRB_DMA_VALID;
  1305. }
  1306. CMD_SP(cmd) = NULL;
  1307. }
  1308. void qla4xxx_srb_compl(struct kref *ref)
  1309. {
  1310. struct srb *srb = container_of(ref, struct srb, srb_ref);
  1311. struct scsi_cmnd *cmd = srb->cmd;
  1312. struct scsi_qla_host *ha = srb->ha;
  1313. qla4xxx_srb_free_dma(ha, srb);
  1314. mempool_free(srb, ha->srb_mempool);
  1315. cmd->scsi_done(cmd);
  1316. }
  1317. /**
  1318. * qla4xxx_queuecommand - scsi layer issues scsi command to driver.
  1319. * @host: scsi host
  1320. * @cmd: Pointer to Linux's SCSI command structure
  1321. *
  1322. * Remarks:
  1323. * This routine is invoked by Linux to send a SCSI command to the driver.
  1324. * The mid-level driver tries to ensure that queuecommand never gets
  1325. * invoked concurrently with itself or the interrupt handler (although
  1326. * the interrupt handler may call this routine as part of request-
  1327. * completion handling). Unfortunely, it sometimes calls the scheduler
  1328. * in interrupt context which is a big NO! NO!.
  1329. **/
  1330. static int qla4xxx_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *cmd)
  1331. {
  1332. struct scsi_qla_host *ha = to_qla_host(host);
  1333. struct ddb_entry *ddb_entry = cmd->device->hostdata;
  1334. struct iscsi_cls_session *sess = ddb_entry->sess;
  1335. struct srb *srb;
  1336. int rval;
  1337. if (test_bit(AF_EEH_BUSY, &ha->flags)) {
  1338. if (test_bit(AF_PCI_CHANNEL_IO_PERM_FAILURE, &ha->flags))
  1339. cmd->result = DID_NO_CONNECT << 16;
  1340. else
  1341. cmd->result = DID_REQUEUE << 16;
  1342. goto qc_fail_command;
  1343. }
  1344. if (!sess) {
  1345. cmd->result = DID_IMM_RETRY << 16;
  1346. goto qc_fail_command;
  1347. }
  1348. rval = iscsi_session_chkready(sess);
  1349. if (rval) {
  1350. cmd->result = rval;
  1351. goto qc_fail_command;
  1352. }
  1353. if (test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags) ||
  1354. test_bit(DPC_RESET_ACTIVE, &ha->dpc_flags) ||
  1355. test_bit(DPC_RESET_HA, &ha->dpc_flags) ||
  1356. test_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags) ||
  1357. test_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags) ||
  1358. !test_bit(AF_ONLINE, &ha->flags) ||
  1359. !test_bit(AF_LINK_UP, &ha->flags) ||
  1360. test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags))
  1361. goto qc_host_busy;
  1362. srb = qla4xxx_get_new_srb(ha, ddb_entry, cmd);
  1363. if (!srb)
  1364. goto qc_host_busy;
  1365. rval = qla4xxx_send_command_to_isp(ha, srb);
  1366. if (rval != QLA_SUCCESS)
  1367. goto qc_host_busy_free_sp;
  1368. return 0;
  1369. qc_host_busy_free_sp:
  1370. qla4xxx_srb_free_dma(ha, srb);
  1371. mempool_free(srb, ha->srb_mempool);
  1372. qc_host_busy:
  1373. return SCSI_MLQUEUE_HOST_BUSY;
  1374. qc_fail_command:
  1375. cmd->scsi_done(cmd);
  1376. return 0;
  1377. }
  1378. /**
  1379. * qla4xxx_mem_free - frees memory allocated to adapter
  1380. * @ha: Pointer to host adapter structure.
  1381. *
  1382. * Frees memory previously allocated by qla4xxx_mem_alloc
  1383. **/
  1384. static void qla4xxx_mem_free(struct scsi_qla_host *ha)
  1385. {
  1386. if (ha->queues)
  1387. dma_free_coherent(&ha->pdev->dev, ha->queues_len, ha->queues,
  1388. ha->queues_dma);
  1389. ha->queues_len = 0;
  1390. ha->queues = NULL;
  1391. ha->queues_dma = 0;
  1392. ha->request_ring = NULL;
  1393. ha->request_dma = 0;
  1394. ha->response_ring = NULL;
  1395. ha->response_dma = 0;
  1396. ha->shadow_regs = NULL;
  1397. ha->shadow_regs_dma = 0;
  1398. /* Free srb pool. */
  1399. if (ha->srb_mempool)
  1400. mempool_destroy(ha->srb_mempool);
  1401. ha->srb_mempool = NULL;
  1402. if (ha->chap_dma_pool)
  1403. dma_pool_destroy(ha->chap_dma_pool);
  1404. if (ha->chap_list)
  1405. vfree(ha->chap_list);
  1406. ha->chap_list = NULL;
  1407. /* release io space registers */
  1408. if (is_qla8022(ha)) {
  1409. if (ha->nx_pcibase)
  1410. iounmap(
  1411. (struct device_reg_82xx __iomem *)ha->nx_pcibase);
  1412. } else if (ha->reg)
  1413. iounmap(ha->reg);
  1414. pci_release_regions(ha->pdev);
  1415. }
  1416. /**
  1417. * qla4xxx_mem_alloc - allocates memory for use by adapter.
  1418. * @ha: Pointer to host adapter structure
  1419. *
  1420. * Allocates DMA memory for request and response queues. Also allocates memory
  1421. * for srbs.
  1422. **/
  1423. static int qla4xxx_mem_alloc(struct scsi_qla_host *ha)
  1424. {
  1425. unsigned long align;
  1426. /* Allocate contiguous block of DMA memory for queues. */
  1427. ha->queues_len = ((REQUEST_QUEUE_DEPTH * QUEUE_SIZE) +
  1428. (RESPONSE_QUEUE_DEPTH * QUEUE_SIZE) +
  1429. sizeof(struct shadow_regs) +
  1430. MEM_ALIGN_VALUE +
  1431. (PAGE_SIZE - 1)) & ~(PAGE_SIZE - 1);
  1432. ha->queues = dma_alloc_coherent(&ha->pdev->dev, ha->queues_len,
  1433. &ha->queues_dma, GFP_KERNEL);
  1434. if (ha->queues == NULL) {
  1435. ql4_printk(KERN_WARNING, ha,
  1436. "Memory Allocation failed - queues.\n");
  1437. goto mem_alloc_error_exit;
  1438. }
  1439. memset(ha->queues, 0, ha->queues_len);
  1440. /*
  1441. * As per RISC alignment requirements -- the bus-address must be a
  1442. * multiple of the request-ring size (in bytes).
  1443. */
  1444. align = 0;
  1445. if ((unsigned long)ha->queues_dma & (MEM_ALIGN_VALUE - 1))
  1446. align = MEM_ALIGN_VALUE - ((unsigned long)ha->queues_dma &
  1447. (MEM_ALIGN_VALUE - 1));
  1448. /* Update request and response queue pointers. */
  1449. ha->request_dma = ha->queues_dma + align;
  1450. ha->request_ring = (struct queue_entry *) (ha->queues + align);
  1451. ha->response_dma = ha->queues_dma + align +
  1452. (REQUEST_QUEUE_DEPTH * QUEUE_SIZE);
  1453. ha->response_ring = (struct queue_entry *) (ha->queues + align +
  1454. (REQUEST_QUEUE_DEPTH *
  1455. QUEUE_SIZE));
  1456. ha->shadow_regs_dma = ha->queues_dma + align +
  1457. (REQUEST_QUEUE_DEPTH * QUEUE_SIZE) +
  1458. (RESPONSE_QUEUE_DEPTH * QUEUE_SIZE);
  1459. ha->shadow_regs = (struct shadow_regs *) (ha->queues + align +
  1460. (REQUEST_QUEUE_DEPTH *
  1461. QUEUE_SIZE) +
  1462. (RESPONSE_QUEUE_DEPTH *
  1463. QUEUE_SIZE));
  1464. /* Allocate memory for srb pool. */
  1465. ha->srb_mempool = mempool_create(SRB_MIN_REQ, mempool_alloc_slab,
  1466. mempool_free_slab, srb_cachep);
  1467. if (ha->srb_mempool == NULL) {
  1468. ql4_printk(KERN_WARNING, ha,
  1469. "Memory Allocation failed - SRB Pool.\n");
  1470. goto mem_alloc_error_exit;
  1471. }
  1472. ha->chap_dma_pool = dma_pool_create("ql4_chap", &ha->pdev->dev,
  1473. CHAP_DMA_BLOCK_SIZE, 8, 0);
  1474. if (ha->chap_dma_pool == NULL) {
  1475. ql4_printk(KERN_WARNING, ha,
  1476. "%s: chap_dma_pool allocation failed..\n", __func__);
  1477. goto mem_alloc_error_exit;
  1478. }
  1479. return QLA_SUCCESS;
  1480. mem_alloc_error_exit:
  1481. qla4xxx_mem_free(ha);
  1482. return QLA_ERROR;
  1483. }
  1484. /**
  1485. * qla4_8xxx_check_fw_alive - Check firmware health
  1486. * @ha: Pointer to host adapter structure.
  1487. *
  1488. * Context: Interrupt
  1489. **/
  1490. static void qla4_8xxx_check_fw_alive(struct scsi_qla_host *ha)
  1491. {
  1492. uint32_t fw_heartbeat_counter, halt_status;
  1493. fw_heartbeat_counter = qla4_8xxx_rd_32(ha, QLA82XX_PEG_ALIVE_COUNTER);
  1494. /* If PEG_ALIVE_COUNTER is 0xffffffff, AER/EEH is in progress, ignore */
  1495. if (fw_heartbeat_counter == 0xffffffff) {
  1496. DEBUG2(printk(KERN_WARNING "scsi%ld: %s: Device in frozen "
  1497. "state, QLA82XX_PEG_ALIVE_COUNTER is 0xffffffff\n",
  1498. ha->host_no, __func__));
  1499. return;
  1500. }
  1501. if (ha->fw_heartbeat_counter == fw_heartbeat_counter) {
  1502. ha->seconds_since_last_heartbeat++;
  1503. /* FW not alive after 2 seconds */
  1504. if (ha->seconds_since_last_heartbeat == 2) {
  1505. ha->seconds_since_last_heartbeat = 0;
  1506. halt_status = qla4_8xxx_rd_32(ha,
  1507. QLA82XX_PEG_HALT_STATUS1);
  1508. ql4_printk(KERN_INFO, ha,
  1509. "scsi(%ld): %s, Dumping hw/fw registers:\n "
  1510. " PEG_HALT_STATUS1: 0x%x, PEG_HALT_STATUS2:"
  1511. " 0x%x,\n PEG_NET_0_PC: 0x%x, PEG_NET_1_PC:"
  1512. " 0x%x,\n PEG_NET_2_PC: 0x%x, PEG_NET_3_PC:"
  1513. " 0x%x,\n PEG_NET_4_PC: 0x%x\n",
  1514. ha->host_no, __func__, halt_status,
  1515. qla4_8xxx_rd_32(ha,
  1516. QLA82XX_PEG_HALT_STATUS2),
  1517. qla4_8xxx_rd_32(ha, QLA82XX_CRB_PEG_NET_0 +
  1518. 0x3c),
  1519. qla4_8xxx_rd_32(ha, QLA82XX_CRB_PEG_NET_1 +
  1520. 0x3c),
  1521. qla4_8xxx_rd_32(ha, QLA82XX_CRB_PEG_NET_2 +
  1522. 0x3c),
  1523. qla4_8xxx_rd_32(ha, QLA82XX_CRB_PEG_NET_3 +
  1524. 0x3c),
  1525. qla4_8xxx_rd_32(ha, QLA82XX_CRB_PEG_NET_4 +
  1526. 0x3c));
  1527. /* Since we cannot change dev_state in interrupt
  1528. * context, set appropriate DPC flag then wakeup
  1529. * DPC */
  1530. if (halt_status & HALT_STATUS_UNRECOVERABLE)
  1531. set_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags);
  1532. else {
  1533. printk("scsi%ld: %s: detect abort needed!\n",
  1534. ha->host_no, __func__);
  1535. set_bit(DPC_RESET_HA, &ha->dpc_flags);
  1536. }
  1537. qla4xxx_wake_dpc(ha);
  1538. qla4xxx_mailbox_premature_completion(ha);
  1539. }
  1540. } else
  1541. ha->seconds_since_last_heartbeat = 0;
  1542. ha->fw_heartbeat_counter = fw_heartbeat_counter;
  1543. }
  1544. /**
  1545. * qla4_8xxx_watchdog - Poll dev state
  1546. * @ha: Pointer to host adapter structure.
  1547. *
  1548. * Context: Interrupt
  1549. **/
  1550. void qla4_8xxx_watchdog(struct scsi_qla_host *ha)
  1551. {
  1552. uint32_t dev_state;
  1553. dev_state = qla4_8xxx_rd_32(ha, QLA82XX_CRB_DEV_STATE);
  1554. /* don't poll if reset is going on */
  1555. if (!(test_bit(DPC_RESET_ACTIVE, &ha->dpc_flags) ||
  1556. test_bit(DPC_RESET_HA, &ha->dpc_flags) ||
  1557. test_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags))) {
  1558. if (dev_state == QLA82XX_DEV_NEED_RESET &&
  1559. !test_bit(DPC_RESET_HA, &ha->dpc_flags)) {
  1560. if (!ql4xdontresethba) {
  1561. ql4_printk(KERN_INFO, ha, "%s: HW State: "
  1562. "NEED RESET!\n", __func__);
  1563. set_bit(DPC_RESET_HA, &ha->dpc_flags);
  1564. qla4xxx_wake_dpc(ha);
  1565. qla4xxx_mailbox_premature_completion(ha);
  1566. }
  1567. } else if (dev_state == QLA82XX_DEV_NEED_QUIESCENT &&
  1568. !test_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags)) {
  1569. ql4_printk(KERN_INFO, ha, "%s: HW State: NEED QUIES!\n",
  1570. __func__);
  1571. set_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags);
  1572. qla4xxx_wake_dpc(ha);
  1573. } else {
  1574. /* Check firmware health */
  1575. qla4_8xxx_check_fw_alive(ha);
  1576. }
  1577. }
  1578. }
  1579. /**
  1580. * qla4xxx_timer - checks every second for work to do.
  1581. * @ha: Pointer to host adapter structure.
  1582. **/
  1583. static void qla4xxx_timer(struct scsi_qla_host *ha)
  1584. {
  1585. int start_dpc = 0;
  1586. uint16_t w;
  1587. /* If we are in the middle of AER/EEH processing
  1588. * skip any processing and reschedule the timer
  1589. */
  1590. if (test_bit(AF_EEH_BUSY, &ha->flags)) {
  1591. mod_timer(&ha->timer, jiffies + HZ);
  1592. return;
  1593. }
  1594. /* Hardware read to trigger an EEH error during mailbox waits. */
  1595. if (!pci_channel_offline(ha->pdev))
  1596. pci_read_config_word(ha->pdev, PCI_VENDOR_ID, &w);
  1597. if (is_qla8022(ha)) {
  1598. qla4_8xxx_watchdog(ha);
  1599. }
  1600. if (!is_qla8022(ha)) {
  1601. /* Check for heartbeat interval. */
  1602. if (ha->firmware_options & FWOPT_HEARTBEAT_ENABLE &&
  1603. ha->heartbeat_interval != 0) {
  1604. ha->seconds_since_last_heartbeat++;
  1605. if (ha->seconds_since_last_heartbeat >
  1606. ha->heartbeat_interval + 2)
  1607. set_bit(DPC_RESET_HA, &ha->dpc_flags);
  1608. }
  1609. }
  1610. /* Wakeup the dpc routine for this adapter, if needed. */
  1611. if (start_dpc ||
  1612. test_bit(DPC_RESET_HA, &ha->dpc_flags) ||
  1613. test_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags) ||
  1614. test_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags) ||
  1615. test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags) ||
  1616. test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags) ||
  1617. test_bit(DPC_GET_DHCP_IP_ADDR, &ha->dpc_flags) ||
  1618. test_bit(DPC_LINK_CHANGED, &ha->dpc_flags) ||
  1619. test_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags) ||
  1620. test_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags) ||
  1621. test_bit(DPC_AEN, &ha->dpc_flags)) {
  1622. DEBUG2(printk("scsi%ld: %s: scheduling dpc routine"
  1623. " - dpc flags = 0x%lx\n",
  1624. ha->host_no, __func__, ha->dpc_flags));
  1625. qla4xxx_wake_dpc(ha);
  1626. }
  1627. /* Reschedule timer thread to call us back in one second */
  1628. mod_timer(&ha->timer, jiffies + HZ);
  1629. DEBUG2(ha->seconds_since_last_intr++);
  1630. }
  1631. /**
  1632. * qla4xxx_cmd_wait - waits for all outstanding commands to complete
  1633. * @ha: Pointer to host adapter structure.
  1634. *
  1635. * This routine stalls the driver until all outstanding commands are returned.
  1636. * Caller must release the Hardware Lock prior to calling this routine.
  1637. **/
  1638. static int qla4xxx_cmd_wait(struct scsi_qla_host *ha)
  1639. {
  1640. uint32_t index = 0;
  1641. unsigned long flags;
  1642. struct scsi_cmnd *cmd;
  1643. unsigned long wtime = jiffies + (WAIT_CMD_TOV * HZ);
  1644. DEBUG2(ql4_printk(KERN_INFO, ha, "Wait up to %d seconds for cmds to "
  1645. "complete\n", WAIT_CMD_TOV));
  1646. while (!time_after_eq(jiffies, wtime)) {
  1647. spin_lock_irqsave(&ha->hardware_lock, flags);
  1648. /* Find a command that hasn't completed. */
  1649. for (index = 0; index < ha->host->can_queue; index++) {
  1650. cmd = scsi_host_find_tag(ha->host, index);
  1651. /*
  1652. * We cannot just check if the index is valid,
  1653. * becase if we are run from the scsi eh, then
  1654. * the scsi/block layer is going to prevent
  1655. * the tag from being released.
  1656. */
  1657. if (cmd != NULL && CMD_SP(cmd))
  1658. break;
  1659. }
  1660. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  1661. /* If No Commands are pending, wait is complete */
  1662. if (index == ha->host->can_queue)
  1663. return QLA_SUCCESS;
  1664. msleep(1000);
  1665. }
  1666. /* If we timed out on waiting for commands to come back
  1667. * return ERROR. */
  1668. return QLA_ERROR;
  1669. }
  1670. int qla4xxx_hw_reset(struct scsi_qla_host *ha)
  1671. {
  1672. uint32_t ctrl_status;
  1673. unsigned long flags = 0;
  1674. DEBUG2(printk(KERN_ERR "scsi%ld: %s\n", ha->host_no, __func__));
  1675. if (ql4xxx_lock_drvr_wait(ha) != QLA_SUCCESS)
  1676. return QLA_ERROR;
  1677. spin_lock_irqsave(&ha->hardware_lock, flags);
  1678. /*
  1679. * If the SCSI Reset Interrupt bit is set, clear it.
  1680. * Otherwise, the Soft Reset won't work.
  1681. */
  1682. ctrl_status = readw(&ha->reg->ctrl_status);
  1683. if ((ctrl_status & CSR_SCSI_RESET_INTR) != 0)
  1684. writel(set_rmask(CSR_SCSI_RESET_INTR), &ha->reg->ctrl_status);
  1685. /* Issue Soft Reset */
  1686. writel(set_rmask(CSR_SOFT_RESET), &ha->reg->ctrl_status);
  1687. readl(&ha->reg->ctrl_status);
  1688. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  1689. return QLA_SUCCESS;
  1690. }
  1691. /**
  1692. * qla4xxx_soft_reset - performs soft reset.
  1693. * @ha: Pointer to host adapter structure.
  1694. **/
  1695. int qla4xxx_soft_reset(struct scsi_qla_host *ha)
  1696. {
  1697. uint32_t max_wait_time;
  1698. unsigned long flags = 0;
  1699. int status;
  1700. uint32_t ctrl_status;
  1701. status = qla4xxx_hw_reset(ha);
  1702. if (status != QLA_SUCCESS)
  1703. return status;
  1704. status = QLA_ERROR;
  1705. /* Wait until the Network Reset Intr bit is cleared */
  1706. max_wait_time = RESET_INTR_TOV;
  1707. do {
  1708. spin_lock_irqsave(&ha->hardware_lock, flags);
  1709. ctrl_status = readw(&ha->reg->ctrl_status);
  1710. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  1711. if ((ctrl_status & CSR_NET_RESET_INTR) == 0)
  1712. break;
  1713. msleep(1000);
  1714. } while ((--max_wait_time));
  1715. if ((ctrl_status & CSR_NET_RESET_INTR) != 0) {
  1716. DEBUG2(printk(KERN_WARNING
  1717. "scsi%ld: Network Reset Intr not cleared by "
  1718. "Network function, clearing it now!\n",
  1719. ha->host_no));
  1720. spin_lock_irqsave(&ha->hardware_lock, flags);
  1721. writel(set_rmask(CSR_NET_RESET_INTR), &ha->reg->ctrl_status);
  1722. readl(&ha->reg->ctrl_status);
  1723. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  1724. }
  1725. /* Wait until the firmware tells us the Soft Reset is done */
  1726. max_wait_time = SOFT_RESET_TOV;
  1727. do {
  1728. spin_lock_irqsave(&ha->hardware_lock, flags);
  1729. ctrl_status = readw(&ha->reg->ctrl_status);
  1730. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  1731. if ((ctrl_status & CSR_SOFT_RESET) == 0) {
  1732. status = QLA_SUCCESS;
  1733. break;
  1734. }
  1735. msleep(1000);
  1736. } while ((--max_wait_time));
  1737. /*
  1738. * Also, make sure that the SCSI Reset Interrupt bit has been cleared
  1739. * after the soft reset has taken place.
  1740. */
  1741. spin_lock_irqsave(&ha->hardware_lock, flags);
  1742. ctrl_status = readw(&ha->reg->ctrl_status);
  1743. if ((ctrl_status & CSR_SCSI_RESET_INTR) != 0) {
  1744. writel(set_rmask(CSR_SCSI_RESET_INTR), &ha->reg->ctrl_status);
  1745. readl(&ha->reg->ctrl_status);
  1746. }
  1747. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  1748. /* If soft reset fails then most probably the bios on other
  1749. * function is also enabled.
  1750. * Since the initialization is sequential the other fn
  1751. * wont be able to acknowledge the soft reset.
  1752. * Issue a force soft reset to workaround this scenario.
  1753. */
  1754. if (max_wait_time == 0) {
  1755. /* Issue Force Soft Reset */
  1756. spin_lock_irqsave(&ha->hardware_lock, flags);
  1757. writel(set_rmask(CSR_FORCE_SOFT_RESET), &ha->reg->ctrl_status);
  1758. readl(&ha->reg->ctrl_status);
  1759. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  1760. /* Wait until the firmware tells us the Soft Reset is done */
  1761. max_wait_time = SOFT_RESET_TOV;
  1762. do {
  1763. spin_lock_irqsave(&ha->hardware_lock, flags);
  1764. ctrl_status = readw(&ha->reg->ctrl_status);
  1765. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  1766. if ((ctrl_status & CSR_FORCE_SOFT_RESET) == 0) {
  1767. status = QLA_SUCCESS;
  1768. break;
  1769. }
  1770. msleep(1000);
  1771. } while ((--max_wait_time));
  1772. }
  1773. return status;
  1774. }
  1775. /**
  1776. * qla4xxx_abort_active_cmds - returns all outstanding i/o requests to O.S.
  1777. * @ha: Pointer to host adapter structure.
  1778. * @res: returned scsi status
  1779. *
  1780. * This routine is called just prior to a HARD RESET to return all
  1781. * outstanding commands back to the Operating System.
  1782. * Caller should make sure that the following locks are released
  1783. * before this calling routine: Hardware lock, and io_request_lock.
  1784. **/
  1785. static void qla4xxx_abort_active_cmds(struct scsi_qla_host *ha, int res)
  1786. {
  1787. struct srb *srb;
  1788. int i;
  1789. unsigned long flags;
  1790. spin_lock_irqsave(&ha->hardware_lock, flags);
  1791. for (i = 0; i < ha->host->can_queue; i++) {
  1792. srb = qla4xxx_del_from_active_array(ha, i);
  1793. if (srb != NULL) {
  1794. srb->cmd->result = res;
  1795. kref_put(&srb->srb_ref, qla4xxx_srb_compl);
  1796. }
  1797. }
  1798. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  1799. }
  1800. void qla4xxx_dead_adapter_cleanup(struct scsi_qla_host *ha)
  1801. {
  1802. clear_bit(AF_ONLINE, &ha->flags);
  1803. /* Disable the board */
  1804. ql4_printk(KERN_INFO, ha, "Disabling the board\n");
  1805. qla4xxx_abort_active_cmds(ha, DID_NO_CONNECT << 16);
  1806. qla4xxx_mark_all_devices_missing(ha);
  1807. clear_bit(AF_INIT_DONE, &ha->flags);
  1808. }
  1809. static void qla4xxx_fail_session(struct iscsi_cls_session *cls_session)
  1810. {
  1811. struct iscsi_session *sess;
  1812. struct ddb_entry *ddb_entry;
  1813. sess = cls_session->dd_data;
  1814. ddb_entry = sess->dd_data;
  1815. ddb_entry->fw_ddb_device_state = DDB_DS_SESSION_FAILED;
  1816. iscsi_session_failure(cls_session->dd_data, ISCSI_ERR_CONN_FAILED);
  1817. }
  1818. /**
  1819. * qla4xxx_recover_adapter - recovers adapter after a fatal error
  1820. * @ha: Pointer to host adapter structure.
  1821. **/
  1822. static int qla4xxx_recover_adapter(struct scsi_qla_host *ha)
  1823. {
  1824. int status = QLA_ERROR;
  1825. uint8_t reset_chip = 0;
  1826. /* Stall incoming I/O until we are done */
  1827. scsi_block_requests(ha->host);
  1828. clear_bit(AF_ONLINE, &ha->flags);
  1829. clear_bit(AF_LINK_UP, &ha->flags);
  1830. DEBUG2(ql4_printk(KERN_INFO, ha, "%s: adapter OFFLINE\n", __func__));
  1831. set_bit(DPC_RESET_ACTIVE, &ha->dpc_flags);
  1832. iscsi_host_for_each_session(ha->host, qla4xxx_fail_session);
  1833. if (test_bit(DPC_RESET_HA, &ha->dpc_flags))
  1834. reset_chip = 1;
  1835. /* For the DPC_RESET_HA_INTR case (ISP-4xxx specific)
  1836. * do not reset adapter, jump to initialize_adapter */
  1837. if (test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags)) {
  1838. status = QLA_SUCCESS;
  1839. goto recover_ha_init_adapter;
  1840. }
  1841. /* For the ISP-82xx adapter, issue a stop_firmware if invoked
  1842. * from eh_host_reset or ioctl module */
  1843. if (is_qla8022(ha) && !reset_chip &&
  1844. test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags)) {
  1845. DEBUG2(ql4_printk(KERN_INFO, ha,
  1846. "scsi%ld: %s - Performing stop_firmware...\n",
  1847. ha->host_no, __func__));
  1848. status = ha->isp_ops->reset_firmware(ha);
  1849. if (status == QLA_SUCCESS) {
  1850. if (!test_bit(AF_FW_RECOVERY, &ha->flags))
  1851. qla4xxx_cmd_wait(ha);
  1852. ha->isp_ops->disable_intrs(ha);
  1853. qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
  1854. qla4xxx_abort_active_cmds(ha, DID_RESET << 16);
  1855. } else {
  1856. /* If the stop_firmware fails then
  1857. * reset the entire chip */
  1858. reset_chip = 1;
  1859. clear_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags);
  1860. set_bit(DPC_RESET_HA, &ha->dpc_flags);
  1861. }
  1862. }
  1863. /* Issue full chip reset if recovering from a catastrophic error,
  1864. * or if stop_firmware fails for ISP-82xx.
  1865. * This is the default case for ISP-4xxx */
  1866. if (!is_qla8022(ha) || reset_chip) {
  1867. if (!test_bit(AF_FW_RECOVERY, &ha->flags))
  1868. qla4xxx_cmd_wait(ha);
  1869. qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
  1870. qla4xxx_abort_active_cmds(ha, DID_RESET << 16);
  1871. DEBUG2(ql4_printk(KERN_INFO, ha,
  1872. "scsi%ld: %s - Performing chip reset..\n",
  1873. ha->host_no, __func__));
  1874. status = ha->isp_ops->reset_chip(ha);
  1875. }
  1876. /* Flush any pending ddb changed AENs */
  1877. qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
  1878. recover_ha_init_adapter:
  1879. /* Upon successful firmware/chip reset, re-initialize the adapter */
  1880. if (status == QLA_SUCCESS) {
  1881. /* For ISP-4xxx, force function 1 to always initialize
  1882. * before function 3 to prevent both funcions from
  1883. * stepping on top of the other */
  1884. if (!is_qla8022(ha) && (ha->mac_index == 3))
  1885. ssleep(6);
  1886. /* NOTE: AF_ONLINE flag set upon successful completion of
  1887. * qla4xxx_initialize_adapter */
  1888. status = qla4xxx_initialize_adapter(ha);
  1889. }
  1890. /* Retry failed adapter initialization, if necessary
  1891. * Do not retry initialize_adapter for RESET_HA_INTR (ISP-4xxx specific)
  1892. * case to prevent ping-pong resets between functions */
  1893. if (!test_bit(AF_ONLINE, &ha->flags) &&
  1894. !test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags)) {
  1895. /* Adapter initialization failed, see if we can retry
  1896. * resetting the ha.
  1897. * Since we don't want to block the DPC for too long
  1898. * with multiple resets in the same thread,
  1899. * utilize DPC to retry */
  1900. if (!test_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags)) {
  1901. ha->retry_reset_ha_cnt = MAX_RESET_HA_RETRIES;
  1902. DEBUG2(printk("scsi%ld: recover adapter - retrying "
  1903. "(%d) more times\n", ha->host_no,
  1904. ha->retry_reset_ha_cnt));
  1905. set_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags);
  1906. status = QLA_ERROR;
  1907. } else {
  1908. if (ha->retry_reset_ha_cnt > 0) {
  1909. /* Schedule another Reset HA--DPC will retry */
  1910. ha->retry_reset_ha_cnt--;
  1911. DEBUG2(printk("scsi%ld: recover adapter - "
  1912. "retry remaining %d\n",
  1913. ha->host_no,
  1914. ha->retry_reset_ha_cnt));
  1915. status = QLA_ERROR;
  1916. }
  1917. if (ha->retry_reset_ha_cnt == 0) {
  1918. /* Recover adapter retries have been exhausted.
  1919. * Adapter DEAD */
  1920. DEBUG2(printk("scsi%ld: recover adapter "
  1921. "failed - board disabled\n",
  1922. ha->host_no));
  1923. qla4xxx_dead_adapter_cleanup(ha);
  1924. clear_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags);
  1925. clear_bit(DPC_RESET_HA, &ha->dpc_flags);
  1926. clear_bit(DPC_RESET_HA_FW_CONTEXT,
  1927. &ha->dpc_flags);
  1928. status = QLA_ERROR;
  1929. }
  1930. }
  1931. } else {
  1932. clear_bit(DPC_RESET_HA, &ha->dpc_flags);
  1933. clear_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags);
  1934. clear_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags);
  1935. }
  1936. ha->adapter_error_count++;
  1937. if (test_bit(AF_ONLINE, &ha->flags))
  1938. ha->isp_ops->enable_intrs(ha);
  1939. scsi_unblock_requests(ha->host);
  1940. clear_bit(DPC_RESET_ACTIVE, &ha->dpc_flags);
  1941. DEBUG2(printk("scsi%ld: recover adapter: %s\n", ha->host_no,
  1942. status == QLA_ERROR ? "FAILED" : "SUCCEEDED"));
  1943. return status;
  1944. }
  1945. static void qla4xxx_relogin_devices(struct iscsi_cls_session *cls_session)
  1946. {
  1947. struct iscsi_session *sess;
  1948. struct ddb_entry *ddb_entry;
  1949. struct scsi_qla_host *ha;
  1950. sess = cls_session->dd_data;
  1951. ddb_entry = sess->dd_data;
  1952. ha = ddb_entry->ha;
  1953. if (!iscsi_is_session_online(cls_session)) {
  1954. if (ddb_entry->fw_ddb_device_state == DDB_DS_SESSION_ACTIVE) {
  1955. ql4_printk(KERN_INFO, ha, "scsi%ld: %s: ddb[%d]"
  1956. " unblock session\n", ha->host_no, __func__,
  1957. ddb_entry->fw_ddb_index);
  1958. iscsi_unblock_session(ddb_entry->sess);
  1959. } else {
  1960. /* Trigger relogin */
  1961. iscsi_session_failure(cls_session->dd_data,
  1962. ISCSI_ERR_CONN_FAILED);
  1963. }
  1964. }
  1965. }
  1966. static void qla4xxx_relogin_all_devices(struct scsi_qla_host *ha)
  1967. {
  1968. iscsi_host_for_each_session(ha->host, qla4xxx_relogin_devices);
  1969. }
  1970. void qla4xxx_wake_dpc(struct scsi_qla_host *ha)
  1971. {
  1972. if (ha->dpc_thread)
  1973. queue_work(ha->dpc_thread, &ha->dpc_work);
  1974. }
  1975. /**
  1976. * qla4xxx_do_dpc - dpc routine
  1977. * @data: in our case pointer to adapter structure
  1978. *
  1979. * This routine is a task that is schedule by the interrupt handler
  1980. * to perform the background processing for interrupts. We put it
  1981. * on a task queue that is consumed whenever the scheduler runs; that's
  1982. * so you can do anything (i.e. put the process to sleep etc). In fact,
  1983. * the mid-level tries to sleep when it reaches the driver threshold
  1984. * "host->can_queue". This can cause a panic if we were in our interrupt code.
  1985. **/
  1986. static void qla4xxx_do_dpc(struct work_struct *work)
  1987. {
  1988. struct scsi_qla_host *ha =
  1989. container_of(work, struct scsi_qla_host, dpc_work);
  1990. int status = QLA_ERROR;
  1991. DEBUG2(printk("scsi%ld: %s: DPC handler waking up."
  1992. "flags = 0x%08lx, dpc_flags = 0x%08lx\n",
  1993. ha->host_no, __func__, ha->flags, ha->dpc_flags))
  1994. /* Initialization not yet finished. Don't do anything yet. */
  1995. if (!test_bit(AF_INIT_DONE, &ha->flags))
  1996. return;
  1997. if (test_bit(AF_EEH_BUSY, &ha->flags)) {
  1998. DEBUG2(printk(KERN_INFO "scsi%ld: %s: flags = %lx\n",
  1999. ha->host_no, __func__, ha->flags));
  2000. return;
  2001. }
  2002. if (is_qla8022(ha)) {
  2003. if (test_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags)) {
  2004. qla4_8xxx_idc_lock(ha);
  2005. qla4_8xxx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
  2006. QLA82XX_DEV_FAILED);
  2007. qla4_8xxx_idc_unlock(ha);
  2008. ql4_printk(KERN_INFO, ha, "HW State: FAILED\n");
  2009. qla4_8xxx_device_state_handler(ha);
  2010. }
  2011. if (test_and_clear_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags)) {
  2012. qla4_8xxx_need_qsnt_handler(ha);
  2013. }
  2014. }
  2015. if (!test_bit(DPC_RESET_ACTIVE, &ha->dpc_flags) &&
  2016. (test_bit(DPC_RESET_HA, &ha->dpc_flags) ||
  2017. test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags) ||
  2018. test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags))) {
  2019. if (ql4xdontresethba) {
  2020. DEBUG2(printk("scsi%ld: %s: Don't Reset HBA\n",
  2021. ha->host_no, __func__));
  2022. clear_bit(DPC_RESET_HA, &ha->dpc_flags);
  2023. clear_bit(DPC_RESET_HA_INTR, &ha->dpc_flags);
  2024. clear_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags);
  2025. goto dpc_post_reset_ha;
  2026. }
  2027. if (test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags) ||
  2028. test_bit(DPC_RESET_HA, &ha->dpc_flags))
  2029. qla4xxx_recover_adapter(ha);
  2030. if (test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags)) {
  2031. uint8_t wait_time = RESET_INTR_TOV;
  2032. while ((readw(&ha->reg->ctrl_status) &
  2033. (CSR_SOFT_RESET | CSR_FORCE_SOFT_RESET)) != 0) {
  2034. if (--wait_time == 0)
  2035. break;
  2036. msleep(1000);
  2037. }
  2038. if (wait_time == 0)
  2039. DEBUG2(printk("scsi%ld: %s: SR|FSR "
  2040. "bit not cleared-- resetting\n",
  2041. ha->host_no, __func__));
  2042. qla4xxx_abort_active_cmds(ha, DID_RESET << 16);
  2043. if (ql4xxx_lock_drvr_wait(ha) == QLA_SUCCESS) {
  2044. qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
  2045. status = qla4xxx_recover_adapter(ha);
  2046. }
  2047. clear_bit(DPC_RESET_HA_INTR, &ha->dpc_flags);
  2048. if (status == QLA_SUCCESS)
  2049. ha->isp_ops->enable_intrs(ha);
  2050. }
  2051. }
  2052. dpc_post_reset_ha:
  2053. /* ---- process AEN? --- */
  2054. if (test_and_clear_bit(DPC_AEN, &ha->dpc_flags))
  2055. qla4xxx_process_aen(ha, PROCESS_ALL_AENS);
  2056. /* ---- Get DHCP IP Address? --- */
  2057. if (test_and_clear_bit(DPC_GET_DHCP_IP_ADDR, &ha->dpc_flags))
  2058. qla4xxx_get_dhcp_ip_address(ha);
  2059. /* ---- link change? --- */
  2060. if (test_and_clear_bit(DPC_LINK_CHANGED, &ha->dpc_flags)) {
  2061. if (!test_bit(AF_LINK_UP, &ha->flags)) {
  2062. /* ---- link down? --- */
  2063. qla4xxx_mark_all_devices_missing(ha);
  2064. } else {
  2065. /* ---- link up? --- *
  2066. * F/W will auto login to all devices ONLY ONCE after
  2067. * link up during driver initialization and runtime
  2068. * fatal error recovery. Therefore, the driver must
  2069. * manually relogin to devices when recovering from
  2070. * connection failures, logouts, expired KATO, etc. */
  2071. qla4xxx_relogin_all_devices(ha);
  2072. }
  2073. }
  2074. }
  2075. /**
  2076. * qla4xxx_free_adapter - release the adapter
  2077. * @ha: pointer to adapter structure
  2078. **/
  2079. static void qla4xxx_free_adapter(struct scsi_qla_host *ha)
  2080. {
  2081. if (test_bit(AF_INTERRUPTS_ON, &ha->flags)) {
  2082. /* Turn-off interrupts on the card. */
  2083. ha->isp_ops->disable_intrs(ha);
  2084. }
  2085. /* Remove timer thread, if present */
  2086. if (ha->timer_active)
  2087. qla4xxx_stop_timer(ha);
  2088. /* Kill the kernel thread for this host */
  2089. if (ha->dpc_thread)
  2090. destroy_workqueue(ha->dpc_thread);
  2091. /* Kill the kernel thread for this host */
  2092. if (ha->task_wq)
  2093. destroy_workqueue(ha->task_wq);
  2094. /* Put firmware in known state */
  2095. ha->isp_ops->reset_firmware(ha);
  2096. if (is_qla8022(ha)) {
  2097. qla4_8xxx_idc_lock(ha);
  2098. qla4_8xxx_clear_drv_active(ha);
  2099. qla4_8xxx_idc_unlock(ha);
  2100. }
  2101. /* Detach interrupts */
  2102. if (test_and_clear_bit(AF_IRQ_ATTACHED, &ha->flags))
  2103. qla4xxx_free_irqs(ha);
  2104. /* free extra memory */
  2105. qla4xxx_mem_free(ha);
  2106. }
  2107. int qla4_8xxx_iospace_config(struct scsi_qla_host *ha)
  2108. {
  2109. int status = 0;
  2110. uint8_t revision_id;
  2111. unsigned long mem_base, mem_len, db_base, db_len;
  2112. struct pci_dev *pdev = ha->pdev;
  2113. status = pci_request_regions(pdev, DRIVER_NAME);
  2114. if (status) {
  2115. printk(KERN_WARNING
  2116. "scsi(%ld) Failed to reserve PIO regions (%s) "
  2117. "status=%d\n", ha->host_no, pci_name(pdev), status);
  2118. goto iospace_error_exit;
  2119. }
  2120. pci_read_config_byte(pdev, PCI_REVISION_ID, &revision_id);
  2121. DEBUG2(printk(KERN_INFO "%s: revision-id=%d\n",
  2122. __func__, revision_id));
  2123. ha->revision_id = revision_id;
  2124. /* remap phys address */
  2125. mem_base = pci_resource_start(pdev, 0); /* 0 is for BAR 0 */
  2126. mem_len = pci_resource_len(pdev, 0);
  2127. DEBUG2(printk(KERN_INFO "%s: ioremap from %lx a size of %lx\n",
  2128. __func__, mem_base, mem_len));
  2129. /* mapping of pcibase pointer */
  2130. ha->nx_pcibase = (unsigned long)ioremap(mem_base, mem_len);
  2131. if (!ha->nx_pcibase) {
  2132. printk(KERN_ERR
  2133. "cannot remap MMIO (%s), aborting\n", pci_name(pdev));
  2134. pci_release_regions(ha->pdev);
  2135. goto iospace_error_exit;
  2136. }
  2137. /* Mapping of IO base pointer, door bell read and write pointer */
  2138. /* mapping of IO base pointer */
  2139. ha->qla4_8xxx_reg =
  2140. (struct device_reg_82xx __iomem *)((uint8_t *)ha->nx_pcibase +
  2141. 0xbc000 + (ha->pdev->devfn << 11));
  2142. db_base = pci_resource_start(pdev, 4); /* doorbell is on bar 4 */
  2143. db_len = pci_resource_len(pdev, 4);
  2144. ha->nx_db_wr_ptr = (ha->pdev->devfn == 4 ? QLA82XX_CAM_RAM_DB1 :
  2145. QLA82XX_CAM_RAM_DB2);
  2146. return 0;
  2147. iospace_error_exit:
  2148. return -ENOMEM;
  2149. }
  2150. /***
  2151. * qla4xxx_iospace_config - maps registers
  2152. * @ha: pointer to adapter structure
  2153. *
  2154. * This routines maps HBA's registers from the pci address space
  2155. * into the kernel virtual address space for memory mapped i/o.
  2156. **/
  2157. int qla4xxx_iospace_config(struct scsi_qla_host *ha)
  2158. {
  2159. unsigned long pio, pio_len, pio_flags;
  2160. unsigned long mmio, mmio_len, mmio_flags;
  2161. pio = pci_resource_start(ha->pdev, 0);
  2162. pio_len = pci_resource_len(ha->pdev, 0);
  2163. pio_flags = pci_resource_flags(ha->pdev, 0);
  2164. if (pio_flags & IORESOURCE_IO) {
  2165. if (pio_len < MIN_IOBASE_LEN) {
  2166. ql4_printk(KERN_WARNING, ha,
  2167. "Invalid PCI I/O region size\n");
  2168. pio = 0;
  2169. }
  2170. } else {
  2171. ql4_printk(KERN_WARNING, ha, "region #0 not a PIO resource\n");
  2172. pio = 0;
  2173. }
  2174. /* Use MMIO operations for all accesses. */
  2175. mmio = pci_resource_start(ha->pdev, 1);
  2176. mmio_len = pci_resource_len(ha->pdev, 1);
  2177. mmio_flags = pci_resource_flags(ha->pdev, 1);
  2178. if (!(mmio_flags & IORESOURCE_MEM)) {
  2179. ql4_printk(KERN_ERR, ha,
  2180. "region #0 not an MMIO resource, aborting\n");
  2181. goto iospace_error_exit;
  2182. }
  2183. if (mmio_len < MIN_IOBASE_LEN) {
  2184. ql4_printk(KERN_ERR, ha,
  2185. "Invalid PCI mem region size, aborting\n");
  2186. goto iospace_error_exit;
  2187. }
  2188. if (pci_request_regions(ha->pdev, DRIVER_NAME)) {
  2189. ql4_printk(KERN_WARNING, ha,
  2190. "Failed to reserve PIO/MMIO regions\n");
  2191. goto iospace_error_exit;
  2192. }
  2193. ha->pio_address = pio;
  2194. ha->pio_length = pio_len;
  2195. ha->reg = ioremap(mmio, MIN_IOBASE_LEN);
  2196. if (!ha->reg) {
  2197. ql4_printk(KERN_ERR, ha,
  2198. "cannot remap MMIO, aborting\n");
  2199. goto iospace_error_exit;
  2200. }
  2201. return 0;
  2202. iospace_error_exit:
  2203. return -ENOMEM;
  2204. }
  2205. static struct isp_operations qla4xxx_isp_ops = {
  2206. .iospace_config = qla4xxx_iospace_config,
  2207. .pci_config = qla4xxx_pci_config,
  2208. .disable_intrs = qla4xxx_disable_intrs,
  2209. .enable_intrs = qla4xxx_enable_intrs,
  2210. .start_firmware = qla4xxx_start_firmware,
  2211. .intr_handler = qla4xxx_intr_handler,
  2212. .interrupt_service_routine = qla4xxx_interrupt_service_routine,
  2213. .reset_chip = qla4xxx_soft_reset,
  2214. .reset_firmware = qla4xxx_hw_reset,
  2215. .queue_iocb = qla4xxx_queue_iocb,
  2216. .complete_iocb = qla4xxx_complete_iocb,
  2217. .rd_shdw_req_q_out = qla4xxx_rd_shdw_req_q_out,
  2218. .rd_shdw_rsp_q_in = qla4xxx_rd_shdw_rsp_q_in,
  2219. .get_sys_info = qla4xxx_get_sys_info,
  2220. };
  2221. static struct isp_operations qla4_8xxx_isp_ops = {
  2222. .iospace_config = qla4_8xxx_iospace_config,
  2223. .pci_config = qla4_8xxx_pci_config,
  2224. .disable_intrs = qla4_8xxx_disable_intrs,
  2225. .enable_intrs = qla4_8xxx_enable_intrs,
  2226. .start_firmware = qla4_8xxx_load_risc,
  2227. .intr_handler = qla4_8xxx_intr_handler,
  2228. .interrupt_service_routine = qla4_8xxx_interrupt_service_routine,
  2229. .reset_chip = qla4_8xxx_isp_reset,
  2230. .reset_firmware = qla4_8xxx_stop_firmware,
  2231. .queue_iocb = qla4_8xxx_queue_iocb,
  2232. .complete_iocb = qla4_8xxx_complete_iocb,
  2233. .rd_shdw_req_q_out = qla4_8xxx_rd_shdw_req_q_out,
  2234. .rd_shdw_rsp_q_in = qla4_8xxx_rd_shdw_rsp_q_in,
  2235. .get_sys_info = qla4_8xxx_get_sys_info,
  2236. };
  2237. uint16_t qla4xxx_rd_shdw_req_q_out(struct scsi_qla_host *ha)
  2238. {
  2239. return (uint16_t)le32_to_cpu(ha->shadow_regs->req_q_out);
  2240. }
  2241. uint16_t qla4_8xxx_rd_shdw_req_q_out(struct scsi_qla_host *ha)
  2242. {
  2243. return (uint16_t)le32_to_cpu(readl(&ha->qla4_8xxx_reg->req_q_out));
  2244. }
  2245. uint16_t qla4xxx_rd_shdw_rsp_q_in(struct scsi_qla_host *ha)
  2246. {
  2247. return (uint16_t)le32_to_cpu(ha->shadow_regs->rsp_q_in);
  2248. }
  2249. uint16_t qla4_8xxx_rd_shdw_rsp_q_in(struct scsi_qla_host *ha)
  2250. {
  2251. return (uint16_t)le32_to_cpu(readl(&ha->qla4_8xxx_reg->rsp_q_in));
  2252. }
  2253. static ssize_t qla4xxx_show_boot_eth_info(void *data, int type, char *buf)
  2254. {
  2255. struct scsi_qla_host *ha = data;
  2256. char *str = buf;
  2257. int rc;
  2258. switch (type) {
  2259. case ISCSI_BOOT_ETH_FLAGS:
  2260. rc = sprintf(str, "%d\n", SYSFS_FLAG_FW_SEL_BOOT);
  2261. break;
  2262. case ISCSI_BOOT_ETH_INDEX:
  2263. rc = sprintf(str, "0\n");
  2264. break;
  2265. case ISCSI_BOOT_ETH_MAC:
  2266. rc = sysfs_format_mac(str, ha->my_mac,
  2267. MAC_ADDR_LEN);
  2268. break;
  2269. default:
  2270. rc = -ENOSYS;
  2271. break;
  2272. }
  2273. return rc;
  2274. }
  2275. static mode_t qla4xxx_eth_get_attr_visibility(void *data, int type)
  2276. {
  2277. int rc;
  2278. switch (type) {
  2279. case ISCSI_BOOT_ETH_FLAGS:
  2280. case ISCSI_BOOT_ETH_MAC:
  2281. case ISCSI_BOOT_ETH_INDEX:
  2282. rc = S_IRUGO;
  2283. break;
  2284. default:
  2285. rc = 0;
  2286. break;
  2287. }
  2288. return rc;
  2289. }
  2290. static ssize_t qla4xxx_show_boot_ini_info(void *data, int type, char *buf)
  2291. {
  2292. struct scsi_qla_host *ha = data;
  2293. char *str = buf;
  2294. int rc;
  2295. switch (type) {
  2296. case ISCSI_BOOT_INI_INITIATOR_NAME:
  2297. rc = sprintf(str, "%s\n", ha->name_string);
  2298. break;
  2299. default:
  2300. rc = -ENOSYS;
  2301. break;
  2302. }
  2303. return rc;
  2304. }
  2305. static mode_t qla4xxx_ini_get_attr_visibility(void *data, int type)
  2306. {
  2307. int rc;
  2308. switch (type) {
  2309. case ISCSI_BOOT_INI_INITIATOR_NAME:
  2310. rc = S_IRUGO;
  2311. break;
  2312. default:
  2313. rc = 0;
  2314. break;
  2315. }
  2316. return rc;
  2317. }
  2318. static ssize_t
  2319. qla4xxx_show_boot_tgt_info(struct ql4_boot_session_info *boot_sess, int type,
  2320. char *buf)
  2321. {
  2322. struct ql4_conn_info *boot_conn = &boot_sess->conn_list[0];
  2323. char *str = buf;
  2324. int rc;
  2325. switch (type) {
  2326. case ISCSI_BOOT_TGT_NAME:
  2327. rc = sprintf(buf, "%s\n", (char *)&boot_sess->target_name);
  2328. break;
  2329. case ISCSI_BOOT_TGT_IP_ADDR:
  2330. if (boot_sess->conn_list[0].dest_ipaddr.ip_type == 0x1)
  2331. rc = sprintf(buf, "%pI4\n",
  2332. &boot_conn->dest_ipaddr.ip_address);
  2333. else
  2334. rc = sprintf(str, "%pI6\n",
  2335. &boot_conn->dest_ipaddr.ip_address);
  2336. break;
  2337. case ISCSI_BOOT_TGT_PORT:
  2338. rc = sprintf(str, "%d\n", boot_conn->dest_port);
  2339. break;
  2340. case ISCSI_BOOT_TGT_CHAP_NAME:
  2341. rc = sprintf(str, "%.*s\n",
  2342. boot_conn->chap.target_chap_name_length,
  2343. (char *)&boot_conn->chap.target_chap_name);
  2344. break;
  2345. case ISCSI_BOOT_TGT_CHAP_SECRET:
  2346. rc = sprintf(str, "%.*s\n",
  2347. boot_conn->chap.target_secret_length,
  2348. (char *)&boot_conn->chap.target_secret);
  2349. break;
  2350. case ISCSI_BOOT_TGT_REV_CHAP_NAME:
  2351. rc = sprintf(str, "%.*s\n",
  2352. boot_conn->chap.intr_chap_name_length,
  2353. (char *)&boot_conn->chap.intr_chap_name);
  2354. break;
  2355. case ISCSI_BOOT_TGT_REV_CHAP_SECRET:
  2356. rc = sprintf(str, "%.*s\n",
  2357. boot_conn->chap.intr_secret_length,
  2358. (char *)&boot_conn->chap.intr_secret);
  2359. break;
  2360. case ISCSI_BOOT_TGT_FLAGS:
  2361. rc = sprintf(str, "%d\n", SYSFS_FLAG_FW_SEL_BOOT);
  2362. break;
  2363. case ISCSI_BOOT_TGT_NIC_ASSOC:
  2364. rc = sprintf(str, "0\n");
  2365. break;
  2366. default:
  2367. rc = -ENOSYS;
  2368. break;
  2369. }
  2370. return rc;
  2371. }
  2372. static ssize_t qla4xxx_show_boot_tgt_pri_info(void *data, int type, char *buf)
  2373. {
  2374. struct scsi_qla_host *ha = data;
  2375. struct ql4_boot_session_info *boot_sess = &(ha->boot_tgt.boot_pri_sess);
  2376. return qla4xxx_show_boot_tgt_info(boot_sess, type, buf);
  2377. }
  2378. static ssize_t qla4xxx_show_boot_tgt_sec_info(void *data, int type, char *buf)
  2379. {
  2380. struct scsi_qla_host *ha = data;
  2381. struct ql4_boot_session_info *boot_sess = &(ha->boot_tgt.boot_sec_sess);
  2382. return qla4xxx_show_boot_tgt_info(boot_sess, type, buf);
  2383. }
  2384. static mode_t qla4xxx_tgt_get_attr_visibility(void *data, int type)
  2385. {
  2386. int rc;
  2387. switch (type) {
  2388. case ISCSI_BOOT_TGT_NAME:
  2389. case ISCSI_BOOT_TGT_IP_ADDR:
  2390. case ISCSI_BOOT_TGT_PORT:
  2391. case ISCSI_BOOT_TGT_CHAP_NAME:
  2392. case ISCSI_BOOT_TGT_CHAP_SECRET:
  2393. case ISCSI_BOOT_TGT_REV_CHAP_NAME:
  2394. case ISCSI_BOOT_TGT_REV_CHAP_SECRET:
  2395. case ISCSI_BOOT_TGT_NIC_ASSOC:
  2396. case ISCSI_BOOT_TGT_FLAGS:
  2397. rc = S_IRUGO;
  2398. break;
  2399. default:
  2400. rc = 0;
  2401. break;
  2402. }
  2403. return rc;
  2404. }
  2405. static void qla4xxx_boot_release(void *data)
  2406. {
  2407. struct scsi_qla_host *ha = data;
  2408. scsi_host_put(ha->host);
  2409. }
  2410. static int get_fw_boot_info(struct scsi_qla_host *ha, uint16_t ddb_index[])
  2411. {
  2412. dma_addr_t buf_dma;
  2413. uint32_t addr, pri_addr, sec_addr;
  2414. uint32_t offset;
  2415. uint16_t func_num;
  2416. uint8_t val;
  2417. uint8_t *buf = NULL;
  2418. size_t size = 13 * sizeof(uint8_t);
  2419. int ret = QLA_SUCCESS;
  2420. func_num = PCI_FUNC(ha->pdev->devfn);
  2421. DEBUG2(ql4_printk(KERN_INFO, ha,
  2422. "%s: Get FW boot info for 0x%x func %d\n", __func__,
  2423. (is_qla4032(ha) ? PCI_DEVICE_ID_QLOGIC_ISP4032 :
  2424. PCI_DEVICE_ID_QLOGIC_ISP8022), func_num));
  2425. if (is_qla4032(ha)) {
  2426. if (func_num == 1) {
  2427. addr = NVRAM_PORT0_BOOT_MODE;
  2428. pri_addr = NVRAM_PORT0_BOOT_PRI_TGT;
  2429. sec_addr = NVRAM_PORT0_BOOT_SEC_TGT;
  2430. } else if (func_num == 3) {
  2431. addr = NVRAM_PORT1_BOOT_MODE;
  2432. pri_addr = NVRAM_PORT1_BOOT_PRI_TGT;
  2433. sec_addr = NVRAM_PORT1_BOOT_SEC_TGT;
  2434. } else {
  2435. ret = QLA_ERROR;
  2436. goto exit_boot_info;
  2437. }
  2438. /* Check Boot Mode */
  2439. val = rd_nvram_byte(ha, addr);
  2440. if (!(val & 0x07)) {
  2441. DEBUG2(ql4_printk(KERN_ERR, ha,
  2442. "%s: Failed Boot options : 0x%x\n",
  2443. __func__, val));
  2444. ret = QLA_ERROR;
  2445. goto exit_boot_info;
  2446. }
  2447. /* get primary valid target index */
  2448. val = rd_nvram_byte(ha, pri_addr);
  2449. if (val & BIT_7)
  2450. ddb_index[0] = (val & 0x7f);
  2451. /* get secondary valid target index */
  2452. val = rd_nvram_byte(ha, sec_addr);
  2453. if (val & BIT_7)
  2454. ddb_index[1] = (val & 0x7f);
  2455. } else if (is_qla8022(ha)) {
  2456. buf = dma_alloc_coherent(&ha->pdev->dev, size,
  2457. &buf_dma, GFP_KERNEL);
  2458. if (!buf) {
  2459. DEBUG2(ql4_printk(KERN_ERR, ha,
  2460. "%s: Unable to allocate dma buffer\n",
  2461. __func__));
  2462. ret = QLA_ERROR;
  2463. goto exit_boot_info;
  2464. }
  2465. if (ha->port_num == 0)
  2466. offset = BOOT_PARAM_OFFSET_PORT0;
  2467. else if (ha->port_num == 1)
  2468. offset = BOOT_PARAM_OFFSET_PORT1;
  2469. else {
  2470. ret = QLA_ERROR;
  2471. goto exit_boot_info_free;
  2472. }
  2473. addr = FLASH_RAW_ACCESS_ADDR + (ha->hw.flt_iscsi_param * 4) +
  2474. offset;
  2475. if (qla4xxx_get_flash(ha, buf_dma, addr,
  2476. 13 * sizeof(uint8_t)) != QLA_SUCCESS) {
  2477. DEBUG2(ql4_printk(KERN_ERR, ha, "scsi%ld: %s: Get Flash"
  2478. "failed\n", ha->host_no, __func__));
  2479. ret = QLA_ERROR;
  2480. goto exit_boot_info_free;
  2481. }
  2482. /* Check Boot Mode */
  2483. if (!(buf[1] & 0x07)) {
  2484. DEBUG2(ql4_printk(KERN_INFO, ha,
  2485. "Failed: Boot options : 0x%x\n",
  2486. buf[1]));
  2487. ret = QLA_ERROR;
  2488. goto exit_boot_info_free;
  2489. }
  2490. /* get primary valid target index */
  2491. if (buf[2] & BIT_7)
  2492. ddb_index[0] = buf[2] & 0x7f;
  2493. /* get secondary valid target index */
  2494. if (buf[11] & BIT_7)
  2495. ddb_index[1] = buf[11] & 0x7f;
  2496. } else {
  2497. ret = QLA_ERROR;
  2498. goto exit_boot_info;
  2499. }
  2500. DEBUG2(ql4_printk(KERN_INFO, ha, "%s: Primary target ID %d, Secondary"
  2501. " target ID %d\n", __func__, ddb_index[0],
  2502. ddb_index[1]));
  2503. exit_boot_info_free:
  2504. dma_free_coherent(&ha->pdev->dev, size, buf, buf_dma);
  2505. exit_boot_info:
  2506. return ret;
  2507. }
  2508. /**
  2509. * qla4xxx_get_bidi_chap - Get a BIDI CHAP user and password
  2510. * @ha: pointer to adapter structure
  2511. * @username: CHAP username to be returned
  2512. * @password: CHAP password to be returned
  2513. *
  2514. * If a boot entry has BIDI CHAP enabled then we need to set the BIDI CHAP
  2515. * user and password in the sysfs entry in /sys/firmware/iscsi_boot#/.
  2516. * So from the CHAP cache find the first BIDI CHAP entry and set it
  2517. * to the boot record in sysfs.
  2518. **/
  2519. static int qla4xxx_get_bidi_chap(struct scsi_qla_host *ha, char *username,
  2520. char *password)
  2521. {
  2522. int i, ret = -EINVAL;
  2523. int max_chap_entries = 0;
  2524. struct ql4_chap_table *chap_table;
  2525. if (is_qla8022(ha))
  2526. max_chap_entries = (ha->hw.flt_chap_size / 2) /
  2527. sizeof(struct ql4_chap_table);
  2528. else
  2529. max_chap_entries = MAX_CHAP_ENTRIES_40XX;
  2530. if (!ha->chap_list) {
  2531. ql4_printk(KERN_ERR, ha, "Do not have CHAP table cache\n");
  2532. return ret;
  2533. }
  2534. mutex_lock(&ha->chap_sem);
  2535. for (i = 0; i < max_chap_entries; i++) {
  2536. chap_table = (struct ql4_chap_table *)ha->chap_list + i;
  2537. if (chap_table->cookie !=
  2538. __constant_cpu_to_le16(CHAP_VALID_COOKIE)) {
  2539. continue;
  2540. }
  2541. if (chap_table->flags & BIT_7) /* local */
  2542. continue;
  2543. if (!(chap_table->flags & BIT_6)) /* Not BIDI */
  2544. continue;
  2545. strncpy(password, chap_table->secret, QL4_CHAP_MAX_SECRET_LEN);
  2546. strncpy(username, chap_table->name, QL4_CHAP_MAX_NAME_LEN);
  2547. ret = 0;
  2548. break;
  2549. }
  2550. mutex_unlock(&ha->chap_sem);
  2551. return ret;
  2552. }
  2553. static int qla4xxx_get_boot_target(struct scsi_qla_host *ha,
  2554. struct ql4_boot_session_info *boot_sess,
  2555. uint16_t ddb_index)
  2556. {
  2557. struct ql4_conn_info *boot_conn = &boot_sess->conn_list[0];
  2558. struct dev_db_entry *fw_ddb_entry;
  2559. dma_addr_t fw_ddb_entry_dma;
  2560. uint16_t idx;
  2561. uint16_t options;
  2562. int ret = QLA_SUCCESS;
  2563. fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
  2564. &fw_ddb_entry_dma, GFP_KERNEL);
  2565. if (!fw_ddb_entry) {
  2566. DEBUG2(ql4_printk(KERN_ERR, ha,
  2567. "%s: Unable to allocate dma buffer.\n",
  2568. __func__));
  2569. ret = QLA_ERROR;
  2570. return ret;
  2571. }
  2572. if (qla4xxx_bootdb_by_index(ha, fw_ddb_entry,
  2573. fw_ddb_entry_dma, ddb_index)) {
  2574. DEBUG2(ql4_printk(KERN_ERR, ha,
  2575. "%s: Flash DDB read Failed\n", __func__));
  2576. ret = QLA_ERROR;
  2577. goto exit_boot_target;
  2578. }
  2579. /* Update target name and IP from DDB */
  2580. memcpy(boot_sess->target_name, fw_ddb_entry->iscsi_name,
  2581. min(sizeof(boot_sess->target_name),
  2582. sizeof(fw_ddb_entry->iscsi_name)));
  2583. options = le16_to_cpu(fw_ddb_entry->options);
  2584. if (options & DDB_OPT_IPV6_DEVICE) {
  2585. memcpy(&boot_conn->dest_ipaddr.ip_address,
  2586. &fw_ddb_entry->ip_addr[0], IPv6_ADDR_LEN);
  2587. } else {
  2588. boot_conn->dest_ipaddr.ip_type = 0x1;
  2589. memcpy(&boot_conn->dest_ipaddr.ip_address,
  2590. &fw_ddb_entry->ip_addr[0], IP_ADDR_LEN);
  2591. }
  2592. boot_conn->dest_port = le16_to_cpu(fw_ddb_entry->port);
  2593. /* update chap information */
  2594. idx = __le16_to_cpu(fw_ddb_entry->chap_tbl_idx);
  2595. if (BIT_7 & le16_to_cpu(fw_ddb_entry->iscsi_options)) {
  2596. DEBUG2(ql4_printk(KERN_INFO, ha, "Setting chap\n"));
  2597. ret = qla4xxx_get_chap(ha, (char *)&boot_conn->chap.
  2598. target_chap_name,
  2599. (char *)&boot_conn->chap.target_secret,
  2600. idx);
  2601. if (ret) {
  2602. ql4_printk(KERN_ERR, ha, "Failed to set chap\n");
  2603. ret = QLA_ERROR;
  2604. goto exit_boot_target;
  2605. }
  2606. boot_conn->chap.target_chap_name_length = QL4_CHAP_MAX_NAME_LEN;
  2607. boot_conn->chap.target_secret_length = QL4_CHAP_MAX_SECRET_LEN;
  2608. }
  2609. if (BIT_4 & le16_to_cpu(fw_ddb_entry->iscsi_options)) {
  2610. DEBUG2(ql4_printk(KERN_INFO, ha, "Setting BIDI chap\n"));
  2611. ret = qla4xxx_get_bidi_chap(ha,
  2612. (char *)&boot_conn->chap.intr_chap_name,
  2613. (char *)&boot_conn->chap.intr_secret);
  2614. if (ret) {
  2615. ql4_printk(KERN_ERR, ha, "Failed to set BIDI chap\n");
  2616. ret = QLA_ERROR;
  2617. goto exit_boot_target;
  2618. }
  2619. boot_conn->chap.intr_chap_name_length = QL4_CHAP_MAX_NAME_LEN;
  2620. boot_conn->chap.intr_secret_length = QL4_CHAP_MAX_SECRET_LEN;
  2621. }
  2622. exit_boot_target:
  2623. dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
  2624. fw_ddb_entry, fw_ddb_entry_dma);
  2625. return ret;
  2626. }
  2627. static int qla4xxx_get_boot_info(struct scsi_qla_host *ha)
  2628. {
  2629. uint16_t ddb_index[2];
  2630. int ret = QLA_ERROR;
  2631. int rval;
  2632. memset(ddb_index, 0, sizeof(ddb_index));
  2633. ddb_index[0] = 0xffff;
  2634. ddb_index[1] = 0xffff;
  2635. ret = get_fw_boot_info(ha, ddb_index);
  2636. if (ret != QLA_SUCCESS) {
  2637. DEBUG2(ql4_printk(KERN_ERR, ha,
  2638. "%s: Failed to set boot info.\n", __func__));
  2639. return ret;
  2640. }
  2641. if (ddb_index[0] == 0xffff)
  2642. goto sec_target;
  2643. rval = qla4xxx_get_boot_target(ha, &(ha->boot_tgt.boot_pri_sess),
  2644. ddb_index[0]);
  2645. if (rval != QLA_SUCCESS) {
  2646. DEBUG2(ql4_printk(KERN_ERR, ha, "%s: Failed to get "
  2647. "primary target\n", __func__));
  2648. } else
  2649. ret = QLA_SUCCESS;
  2650. sec_target:
  2651. if (ddb_index[1] == 0xffff)
  2652. goto exit_get_boot_info;
  2653. rval = qla4xxx_get_boot_target(ha, &(ha->boot_tgt.boot_sec_sess),
  2654. ddb_index[1]);
  2655. if (rval != QLA_SUCCESS) {
  2656. DEBUG2(ql4_printk(KERN_ERR, ha, "%s: Failed to get "
  2657. "secondary target\n", __func__));
  2658. } else
  2659. ret = QLA_SUCCESS;
  2660. exit_get_boot_info:
  2661. return ret;
  2662. }
  2663. static int qla4xxx_setup_boot_info(struct scsi_qla_host *ha)
  2664. {
  2665. struct iscsi_boot_kobj *boot_kobj;
  2666. if (qla4xxx_get_boot_info(ha) != QLA_SUCCESS)
  2667. return 0;
  2668. ha->boot_kset = iscsi_boot_create_host_kset(ha->host->host_no);
  2669. if (!ha->boot_kset)
  2670. goto kset_free;
  2671. if (!scsi_host_get(ha->host))
  2672. goto kset_free;
  2673. boot_kobj = iscsi_boot_create_target(ha->boot_kset, 0, ha,
  2674. qla4xxx_show_boot_tgt_pri_info,
  2675. qla4xxx_tgt_get_attr_visibility,
  2676. qla4xxx_boot_release);
  2677. if (!boot_kobj)
  2678. goto put_host;
  2679. if (!scsi_host_get(ha->host))
  2680. goto kset_free;
  2681. boot_kobj = iscsi_boot_create_target(ha->boot_kset, 1, ha,
  2682. qla4xxx_show_boot_tgt_sec_info,
  2683. qla4xxx_tgt_get_attr_visibility,
  2684. qla4xxx_boot_release);
  2685. if (!boot_kobj)
  2686. goto put_host;
  2687. if (!scsi_host_get(ha->host))
  2688. goto kset_free;
  2689. boot_kobj = iscsi_boot_create_initiator(ha->boot_kset, 0, ha,
  2690. qla4xxx_show_boot_ini_info,
  2691. qla4xxx_ini_get_attr_visibility,
  2692. qla4xxx_boot_release);
  2693. if (!boot_kobj)
  2694. goto put_host;
  2695. if (!scsi_host_get(ha->host))
  2696. goto kset_free;
  2697. boot_kobj = iscsi_boot_create_ethernet(ha->boot_kset, 0, ha,
  2698. qla4xxx_show_boot_eth_info,
  2699. qla4xxx_eth_get_attr_visibility,
  2700. qla4xxx_boot_release);
  2701. if (!boot_kobj)
  2702. goto put_host;
  2703. return 0;
  2704. put_host:
  2705. scsi_host_put(ha->host);
  2706. kset_free:
  2707. iscsi_boot_destroy_kset(ha->boot_kset);
  2708. return -ENOMEM;
  2709. }
  2710. /**
  2711. * qla4xxx_create chap_list - Create CHAP list from FLASH
  2712. * @ha: pointer to adapter structure
  2713. *
  2714. * Read flash and make a list of CHAP entries, during login when a CHAP entry
  2715. * is received, it will be checked in this list. If entry exist then the CHAP
  2716. * entry index is set in the DDB. If CHAP entry does not exist in this list
  2717. * then a new entry is added in FLASH in CHAP table and the index obtained is
  2718. * used in the DDB.
  2719. **/
  2720. static void qla4xxx_create_chap_list(struct scsi_qla_host *ha)
  2721. {
  2722. int rval = 0;
  2723. uint8_t *chap_flash_data = NULL;
  2724. uint32_t offset;
  2725. dma_addr_t chap_dma;
  2726. uint32_t chap_size = 0;
  2727. if (is_qla40XX(ha))
  2728. chap_size = MAX_CHAP_ENTRIES_40XX *
  2729. sizeof(struct ql4_chap_table);
  2730. else /* Single region contains CHAP info for both
  2731. * ports which is divided into half for each port.
  2732. */
  2733. chap_size = ha->hw.flt_chap_size / 2;
  2734. chap_flash_data = dma_alloc_coherent(&ha->pdev->dev, chap_size,
  2735. &chap_dma, GFP_KERNEL);
  2736. if (!chap_flash_data) {
  2737. ql4_printk(KERN_ERR, ha, "No memory for chap_flash_data\n");
  2738. return;
  2739. }
  2740. if (is_qla40XX(ha))
  2741. offset = FLASH_CHAP_OFFSET;
  2742. else {
  2743. offset = FLASH_RAW_ACCESS_ADDR + (ha->hw.flt_region_chap << 2);
  2744. if (ha->port_num == 1)
  2745. offset += chap_size;
  2746. }
  2747. rval = qla4xxx_get_flash(ha, chap_dma, offset, chap_size);
  2748. if (rval != QLA_SUCCESS)
  2749. goto exit_chap_list;
  2750. if (ha->chap_list == NULL)
  2751. ha->chap_list = vmalloc(chap_size);
  2752. if (ha->chap_list == NULL) {
  2753. ql4_printk(KERN_ERR, ha, "No memory for ha->chap_list\n");
  2754. goto exit_chap_list;
  2755. }
  2756. memcpy(ha->chap_list, chap_flash_data, chap_size);
  2757. exit_chap_list:
  2758. dma_free_coherent(&ha->pdev->dev, chap_size,
  2759. chap_flash_data, chap_dma);
  2760. return;
  2761. }
  2762. /**
  2763. * qla4xxx_probe_adapter - callback function to probe HBA
  2764. * @pdev: pointer to pci_dev structure
  2765. * @pci_device_id: pointer to pci_device entry
  2766. *
  2767. * This routine will probe for Qlogic 4xxx iSCSI host adapters.
  2768. * It returns zero if successful. It also initializes all data necessary for
  2769. * the driver.
  2770. **/
  2771. static int __devinit qla4xxx_probe_adapter(struct pci_dev *pdev,
  2772. const struct pci_device_id *ent)
  2773. {
  2774. int ret = -ENODEV, status;
  2775. struct Scsi_Host *host;
  2776. struct scsi_qla_host *ha;
  2777. uint8_t init_retry_count = 0;
  2778. char buf[34];
  2779. struct qla4_8xxx_legacy_intr_set *nx_legacy_intr;
  2780. uint32_t dev_state;
  2781. if (pci_enable_device(pdev))
  2782. return -1;
  2783. host = iscsi_host_alloc(&qla4xxx_driver_template, sizeof(*ha), 0);
  2784. if (host == NULL) {
  2785. printk(KERN_WARNING
  2786. "qla4xxx: Couldn't allocate host from scsi layer!\n");
  2787. goto probe_disable_device;
  2788. }
  2789. /* Clear our data area */
  2790. ha = to_qla_host(host);
  2791. memset(ha, 0, sizeof(*ha));
  2792. /* Save the information from PCI BIOS. */
  2793. ha->pdev = pdev;
  2794. ha->host = host;
  2795. ha->host_no = host->host_no;
  2796. pci_enable_pcie_error_reporting(pdev);
  2797. /* Setup Runtime configurable options */
  2798. if (is_qla8022(ha)) {
  2799. ha->isp_ops = &qla4_8xxx_isp_ops;
  2800. rwlock_init(&ha->hw_lock);
  2801. ha->qdr_sn_window = -1;
  2802. ha->ddr_mn_window = -1;
  2803. ha->curr_window = 255;
  2804. ha->func_num = PCI_FUNC(ha->pdev->devfn);
  2805. nx_legacy_intr = &legacy_intr[ha->func_num];
  2806. ha->nx_legacy_intr.int_vec_bit = nx_legacy_intr->int_vec_bit;
  2807. ha->nx_legacy_intr.tgt_status_reg =
  2808. nx_legacy_intr->tgt_status_reg;
  2809. ha->nx_legacy_intr.tgt_mask_reg = nx_legacy_intr->tgt_mask_reg;
  2810. ha->nx_legacy_intr.pci_int_reg = nx_legacy_intr->pci_int_reg;
  2811. } else {
  2812. ha->isp_ops = &qla4xxx_isp_ops;
  2813. }
  2814. /* Set EEH reset type to fundamental if required by hba */
  2815. if (is_qla8022(ha))
  2816. pdev->needs_freset = 1;
  2817. /* Configure PCI I/O space. */
  2818. ret = ha->isp_ops->iospace_config(ha);
  2819. if (ret)
  2820. goto probe_failed_ioconfig;
  2821. ql4_printk(KERN_INFO, ha, "Found an ISP%04x, irq %d, iobase 0x%p\n",
  2822. pdev->device, pdev->irq, ha->reg);
  2823. qla4xxx_config_dma_addressing(ha);
  2824. /* Initialize lists and spinlocks. */
  2825. INIT_LIST_HEAD(&ha->free_srb_q);
  2826. mutex_init(&ha->mbox_sem);
  2827. mutex_init(&ha->chap_sem);
  2828. init_completion(&ha->mbx_intr_comp);
  2829. init_completion(&ha->disable_acb_comp);
  2830. spin_lock_init(&ha->hardware_lock);
  2831. /* Allocate dma buffers */
  2832. if (qla4xxx_mem_alloc(ha)) {
  2833. ql4_printk(KERN_WARNING, ha,
  2834. "[ERROR] Failed to allocate memory for adapter\n");
  2835. ret = -ENOMEM;
  2836. goto probe_failed;
  2837. }
  2838. host->cmd_per_lun = 3;
  2839. host->max_channel = 0;
  2840. host->max_lun = MAX_LUNS - 1;
  2841. host->max_id = MAX_TARGETS;
  2842. host->max_cmd_len = IOCB_MAX_CDB_LEN;
  2843. host->can_queue = MAX_SRBS ;
  2844. host->transportt = qla4xxx_scsi_transport;
  2845. ret = scsi_init_shared_tag_map(host, MAX_SRBS);
  2846. if (ret) {
  2847. ql4_printk(KERN_WARNING, ha,
  2848. "%s: scsi_init_shared_tag_map failed\n", __func__);
  2849. goto probe_failed;
  2850. }
  2851. pci_set_drvdata(pdev, ha);
  2852. ret = scsi_add_host(host, &pdev->dev);
  2853. if (ret)
  2854. goto probe_failed;
  2855. if (is_qla8022(ha))
  2856. (void) qla4_8xxx_get_flash_info(ha);
  2857. /*
  2858. * Initialize the Host adapter request/response queues and
  2859. * firmware
  2860. * NOTE: interrupts enabled upon successful completion
  2861. */
  2862. status = qla4xxx_initialize_adapter(ha);
  2863. while ((!test_bit(AF_ONLINE, &ha->flags)) &&
  2864. init_retry_count++ < MAX_INIT_RETRIES) {
  2865. if (is_qla8022(ha)) {
  2866. qla4_8xxx_idc_lock(ha);
  2867. dev_state = qla4_8xxx_rd_32(ha, QLA82XX_CRB_DEV_STATE);
  2868. qla4_8xxx_idc_unlock(ha);
  2869. if (dev_state == QLA82XX_DEV_FAILED) {
  2870. ql4_printk(KERN_WARNING, ha, "%s: don't retry "
  2871. "initialize adapter. H/W is in failed state\n",
  2872. __func__);
  2873. break;
  2874. }
  2875. }
  2876. DEBUG2(printk("scsi: %s: retrying adapter initialization "
  2877. "(%d)\n", __func__, init_retry_count));
  2878. if (ha->isp_ops->reset_chip(ha) == QLA_ERROR)
  2879. continue;
  2880. status = qla4xxx_initialize_adapter(ha);
  2881. }
  2882. if (!test_bit(AF_ONLINE, &ha->flags)) {
  2883. ql4_printk(KERN_WARNING, ha, "Failed to initialize adapter\n");
  2884. if (is_qla8022(ha) && ql4xdontresethba) {
  2885. /* Put the device in failed state. */
  2886. DEBUG2(printk(KERN_ERR "HW STATE: FAILED\n"));
  2887. qla4_8xxx_idc_lock(ha);
  2888. qla4_8xxx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
  2889. QLA82XX_DEV_FAILED);
  2890. qla4_8xxx_idc_unlock(ha);
  2891. }
  2892. ret = -ENODEV;
  2893. goto remove_host;
  2894. }
  2895. /* Startup the kernel thread for this host adapter. */
  2896. DEBUG2(printk("scsi: %s: Starting kernel thread for "
  2897. "qla4xxx_dpc\n", __func__));
  2898. sprintf(buf, "qla4xxx_%lu_dpc", ha->host_no);
  2899. ha->dpc_thread = create_singlethread_workqueue(buf);
  2900. if (!ha->dpc_thread) {
  2901. ql4_printk(KERN_WARNING, ha, "Unable to start DPC thread!\n");
  2902. ret = -ENODEV;
  2903. goto remove_host;
  2904. }
  2905. INIT_WORK(&ha->dpc_work, qla4xxx_do_dpc);
  2906. sprintf(buf, "qla4xxx_%lu_task", ha->host_no);
  2907. ha->task_wq = alloc_workqueue(buf, WQ_MEM_RECLAIM, 1);
  2908. if (!ha->task_wq) {
  2909. ql4_printk(KERN_WARNING, ha, "Unable to start task thread!\n");
  2910. ret = -ENODEV;
  2911. goto remove_host;
  2912. }
  2913. /* For ISP-82XX, request_irqs is called in qla4_8xxx_load_risc
  2914. * (which is called indirectly by qla4xxx_initialize_adapter),
  2915. * so that irqs will be registered after crbinit but before
  2916. * mbx_intr_enable.
  2917. */
  2918. if (!is_qla8022(ha)) {
  2919. ret = qla4xxx_request_irqs(ha);
  2920. if (ret) {
  2921. ql4_printk(KERN_WARNING, ha, "Failed to reserve "
  2922. "interrupt %d already in use.\n", pdev->irq);
  2923. goto remove_host;
  2924. }
  2925. }
  2926. pci_save_state(ha->pdev);
  2927. ha->isp_ops->enable_intrs(ha);
  2928. /* Start timer thread. */
  2929. qla4xxx_start_timer(ha, qla4xxx_timer, 1);
  2930. set_bit(AF_INIT_DONE, &ha->flags);
  2931. printk(KERN_INFO
  2932. " QLogic iSCSI HBA Driver version: %s\n"
  2933. " QLogic ISP%04x @ %s, host#=%ld, fw=%02d.%02d.%02d.%02d\n",
  2934. qla4xxx_version_str, ha->pdev->device, pci_name(ha->pdev),
  2935. ha->host_no, ha->firmware_version[0], ha->firmware_version[1],
  2936. ha->patch_number, ha->build_number);
  2937. qla4xxx_create_chap_list(ha);
  2938. if (qla4xxx_setup_boot_info(ha))
  2939. ql4_printk(KERN_ERR, ha, "%s:ISCSI boot info setup failed\n",
  2940. __func__);
  2941. qla4xxx_create_ifaces(ha);
  2942. return 0;
  2943. remove_host:
  2944. scsi_remove_host(ha->host);
  2945. probe_failed:
  2946. qla4xxx_free_adapter(ha);
  2947. probe_failed_ioconfig:
  2948. pci_disable_pcie_error_reporting(pdev);
  2949. scsi_host_put(ha->host);
  2950. probe_disable_device:
  2951. pci_disable_device(pdev);
  2952. return ret;
  2953. }
  2954. /**
  2955. * qla4xxx_prevent_other_port_reinit - prevent other port from re-initialize
  2956. * @ha: pointer to adapter structure
  2957. *
  2958. * Mark the other ISP-4xxx port to indicate that the driver is being removed,
  2959. * so that the other port will not re-initialize while in the process of
  2960. * removing the ha due to driver unload or hba hotplug.
  2961. **/
  2962. static void qla4xxx_prevent_other_port_reinit(struct scsi_qla_host *ha)
  2963. {
  2964. struct scsi_qla_host *other_ha = NULL;
  2965. struct pci_dev *other_pdev = NULL;
  2966. int fn = ISP4XXX_PCI_FN_2;
  2967. /*iscsi function numbers for ISP4xxx is 1 and 3*/
  2968. if (PCI_FUNC(ha->pdev->devfn) & BIT_1)
  2969. fn = ISP4XXX_PCI_FN_1;
  2970. other_pdev =
  2971. pci_get_domain_bus_and_slot(pci_domain_nr(ha->pdev->bus),
  2972. ha->pdev->bus->number, PCI_DEVFN(PCI_SLOT(ha->pdev->devfn),
  2973. fn));
  2974. /* Get other_ha if other_pdev is valid and state is enable*/
  2975. if (other_pdev) {
  2976. if (atomic_read(&other_pdev->enable_cnt)) {
  2977. other_ha = pci_get_drvdata(other_pdev);
  2978. if (other_ha) {
  2979. set_bit(AF_HA_REMOVAL, &other_ha->flags);
  2980. DEBUG2(ql4_printk(KERN_INFO, ha, "%s: "
  2981. "Prevent %s reinit\n", __func__,
  2982. dev_name(&other_ha->pdev->dev)));
  2983. }
  2984. }
  2985. pci_dev_put(other_pdev);
  2986. }
  2987. }
  2988. /**
  2989. * qla4xxx_remove_adapter - calback function to remove adapter.
  2990. * @pci_dev: PCI device pointer
  2991. **/
  2992. static void __devexit qla4xxx_remove_adapter(struct pci_dev *pdev)
  2993. {
  2994. struct scsi_qla_host *ha;
  2995. ha = pci_get_drvdata(pdev);
  2996. if (!is_qla8022(ha))
  2997. qla4xxx_prevent_other_port_reinit(ha);
  2998. /* destroy iface from sysfs */
  2999. qla4xxx_destroy_ifaces(ha);
  3000. if (ha->boot_kset)
  3001. iscsi_boot_destroy_kset(ha->boot_kset);
  3002. scsi_remove_host(ha->host);
  3003. qla4xxx_free_adapter(ha);
  3004. scsi_host_put(ha->host);
  3005. pci_disable_pcie_error_reporting(pdev);
  3006. pci_disable_device(pdev);
  3007. pci_set_drvdata(pdev, NULL);
  3008. }
  3009. /**
  3010. * qla4xxx_config_dma_addressing() - Configure OS DMA addressing method.
  3011. * @ha: HA context
  3012. *
  3013. * At exit, the @ha's flags.enable_64bit_addressing set to indicated
  3014. * supported addressing method.
  3015. */
  3016. static void qla4xxx_config_dma_addressing(struct scsi_qla_host *ha)
  3017. {
  3018. int retval;
  3019. /* Update our PCI device dma_mask for full 64 bit mask */
  3020. if (pci_set_dma_mask(ha->pdev, DMA_BIT_MASK(64)) == 0) {
  3021. if (pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(64))) {
  3022. dev_dbg(&ha->pdev->dev,
  3023. "Failed to set 64 bit PCI consistent mask; "
  3024. "using 32 bit.\n");
  3025. retval = pci_set_consistent_dma_mask(ha->pdev,
  3026. DMA_BIT_MASK(32));
  3027. }
  3028. } else
  3029. retval = pci_set_dma_mask(ha->pdev, DMA_BIT_MASK(32));
  3030. }
  3031. static int qla4xxx_slave_alloc(struct scsi_device *sdev)
  3032. {
  3033. struct iscsi_cls_session *cls_sess;
  3034. struct iscsi_session *sess;
  3035. struct ddb_entry *ddb;
  3036. int queue_depth = QL4_DEF_QDEPTH;
  3037. cls_sess = starget_to_session(sdev->sdev_target);
  3038. sess = cls_sess->dd_data;
  3039. ddb = sess->dd_data;
  3040. sdev->hostdata = ddb;
  3041. sdev->tagged_supported = 1;
  3042. if (ql4xmaxqdepth != 0 && ql4xmaxqdepth <= 0xffffU)
  3043. queue_depth = ql4xmaxqdepth;
  3044. scsi_activate_tcq(sdev, queue_depth);
  3045. return 0;
  3046. }
  3047. static int qla4xxx_slave_configure(struct scsi_device *sdev)
  3048. {
  3049. sdev->tagged_supported = 1;
  3050. return 0;
  3051. }
  3052. static void qla4xxx_slave_destroy(struct scsi_device *sdev)
  3053. {
  3054. scsi_deactivate_tcq(sdev, 1);
  3055. }
  3056. /**
  3057. * qla4xxx_del_from_active_array - returns an active srb
  3058. * @ha: Pointer to host adapter structure.
  3059. * @index: index into the active_array
  3060. *
  3061. * This routine removes and returns the srb at the specified index
  3062. **/
  3063. struct srb *qla4xxx_del_from_active_array(struct scsi_qla_host *ha,
  3064. uint32_t index)
  3065. {
  3066. struct srb *srb = NULL;
  3067. struct scsi_cmnd *cmd = NULL;
  3068. cmd = scsi_host_find_tag(ha->host, index);
  3069. if (!cmd)
  3070. return srb;
  3071. srb = (struct srb *)CMD_SP(cmd);
  3072. if (!srb)
  3073. return srb;
  3074. /* update counters */
  3075. if (srb->flags & SRB_DMA_VALID) {
  3076. ha->req_q_count += srb->iocb_cnt;
  3077. ha->iocb_cnt -= srb->iocb_cnt;
  3078. if (srb->cmd)
  3079. srb->cmd->host_scribble =
  3080. (unsigned char *)(unsigned long) MAX_SRBS;
  3081. }
  3082. return srb;
  3083. }
  3084. /**
  3085. * qla4xxx_eh_wait_on_command - waits for command to be returned by firmware
  3086. * @ha: Pointer to host adapter structure.
  3087. * @cmd: Scsi Command to wait on.
  3088. *
  3089. * This routine waits for the command to be returned by the Firmware
  3090. * for some max time.
  3091. **/
  3092. static int qla4xxx_eh_wait_on_command(struct scsi_qla_host *ha,
  3093. struct scsi_cmnd *cmd)
  3094. {
  3095. int done = 0;
  3096. struct srb *rp;
  3097. uint32_t max_wait_time = EH_WAIT_CMD_TOV;
  3098. int ret = SUCCESS;
  3099. /* Dont wait on command if PCI error is being handled
  3100. * by PCI AER driver
  3101. */
  3102. if (unlikely(pci_channel_offline(ha->pdev)) ||
  3103. (test_bit(AF_EEH_BUSY, &ha->flags))) {
  3104. ql4_printk(KERN_WARNING, ha, "scsi%ld: Return from %s\n",
  3105. ha->host_no, __func__);
  3106. return ret;
  3107. }
  3108. do {
  3109. /* Checking to see if its returned to OS */
  3110. rp = (struct srb *) CMD_SP(cmd);
  3111. if (rp == NULL) {
  3112. done++;
  3113. break;
  3114. }
  3115. msleep(2000);
  3116. } while (max_wait_time--);
  3117. return done;
  3118. }
  3119. /**
  3120. * qla4xxx_wait_for_hba_online - waits for HBA to come online
  3121. * @ha: Pointer to host adapter structure
  3122. **/
  3123. static int qla4xxx_wait_for_hba_online(struct scsi_qla_host *ha)
  3124. {
  3125. unsigned long wait_online;
  3126. wait_online = jiffies + (HBA_ONLINE_TOV * HZ);
  3127. while (time_before(jiffies, wait_online)) {
  3128. if (adapter_up(ha))
  3129. return QLA_SUCCESS;
  3130. msleep(2000);
  3131. }
  3132. return QLA_ERROR;
  3133. }
  3134. /**
  3135. * qla4xxx_eh_wait_for_commands - wait for active cmds to finish.
  3136. * @ha: pointer to HBA
  3137. * @t: target id
  3138. * @l: lun id
  3139. *
  3140. * This function waits for all outstanding commands to a lun to complete. It
  3141. * returns 0 if all pending commands are returned and 1 otherwise.
  3142. **/
  3143. static int qla4xxx_eh_wait_for_commands(struct scsi_qla_host *ha,
  3144. struct scsi_target *stgt,
  3145. struct scsi_device *sdev)
  3146. {
  3147. int cnt;
  3148. int status = 0;
  3149. struct scsi_cmnd *cmd;
  3150. /*
  3151. * Waiting for all commands for the designated target or dev
  3152. * in the active array
  3153. */
  3154. for (cnt = 0; cnt < ha->host->can_queue; cnt++) {
  3155. cmd = scsi_host_find_tag(ha->host, cnt);
  3156. if (cmd && stgt == scsi_target(cmd->device) &&
  3157. (!sdev || sdev == cmd->device)) {
  3158. if (!qla4xxx_eh_wait_on_command(ha, cmd)) {
  3159. status++;
  3160. break;
  3161. }
  3162. }
  3163. }
  3164. return status;
  3165. }
  3166. /**
  3167. * qla4xxx_eh_abort - callback for abort task.
  3168. * @cmd: Pointer to Linux's SCSI command structure
  3169. *
  3170. * This routine is called by the Linux OS to abort the specified
  3171. * command.
  3172. **/
  3173. static int qla4xxx_eh_abort(struct scsi_cmnd *cmd)
  3174. {
  3175. struct scsi_qla_host *ha = to_qla_host(cmd->device->host);
  3176. unsigned int id = cmd->device->id;
  3177. unsigned int lun = cmd->device->lun;
  3178. unsigned long flags;
  3179. struct srb *srb = NULL;
  3180. int ret = SUCCESS;
  3181. int wait = 0;
  3182. ql4_printk(KERN_INFO, ha,
  3183. "scsi%ld:%d:%d: Abort command issued cmd=%p\n",
  3184. ha->host_no, id, lun, cmd);
  3185. spin_lock_irqsave(&ha->hardware_lock, flags);
  3186. srb = (struct srb *) CMD_SP(cmd);
  3187. if (!srb) {
  3188. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  3189. return SUCCESS;
  3190. }
  3191. kref_get(&srb->srb_ref);
  3192. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  3193. if (qla4xxx_abort_task(ha, srb) != QLA_SUCCESS) {
  3194. DEBUG3(printk("scsi%ld:%d:%d: Abort_task mbx failed.\n",
  3195. ha->host_no, id, lun));
  3196. ret = FAILED;
  3197. } else {
  3198. DEBUG3(printk("scsi%ld:%d:%d: Abort_task mbx success.\n",
  3199. ha->host_no, id, lun));
  3200. wait = 1;
  3201. }
  3202. kref_put(&srb->srb_ref, qla4xxx_srb_compl);
  3203. /* Wait for command to complete */
  3204. if (wait) {
  3205. if (!qla4xxx_eh_wait_on_command(ha, cmd)) {
  3206. DEBUG2(printk("scsi%ld:%d:%d: Abort handler timed out\n",
  3207. ha->host_no, id, lun));
  3208. ret = FAILED;
  3209. }
  3210. }
  3211. ql4_printk(KERN_INFO, ha,
  3212. "scsi%ld:%d:%d: Abort command - %s\n",
  3213. ha->host_no, id, lun, (ret == SUCCESS) ? "succeeded" : "failed");
  3214. return ret;
  3215. }
  3216. /**
  3217. * qla4xxx_eh_device_reset - callback for target reset.
  3218. * @cmd: Pointer to Linux's SCSI command structure
  3219. *
  3220. * This routine is called by the Linux OS to reset all luns on the
  3221. * specified target.
  3222. **/
  3223. static int qla4xxx_eh_device_reset(struct scsi_cmnd *cmd)
  3224. {
  3225. struct scsi_qla_host *ha = to_qla_host(cmd->device->host);
  3226. struct ddb_entry *ddb_entry = cmd->device->hostdata;
  3227. int ret = FAILED, stat;
  3228. if (!ddb_entry)
  3229. return ret;
  3230. ret = iscsi_block_scsi_eh(cmd);
  3231. if (ret)
  3232. return ret;
  3233. ret = FAILED;
  3234. ql4_printk(KERN_INFO, ha,
  3235. "scsi%ld:%d:%d:%d: DEVICE RESET ISSUED.\n", ha->host_no,
  3236. cmd->device->channel, cmd->device->id, cmd->device->lun);
  3237. DEBUG2(printk(KERN_INFO
  3238. "scsi%ld: DEVICE_RESET cmd=%p jiffies = 0x%lx, to=%x,"
  3239. "dpc_flags=%lx, status=%x allowed=%d\n", ha->host_no,
  3240. cmd, jiffies, cmd->request->timeout / HZ,
  3241. ha->dpc_flags, cmd->result, cmd->allowed));
  3242. /* FIXME: wait for hba to go online */
  3243. stat = qla4xxx_reset_lun(ha, ddb_entry, cmd->device->lun);
  3244. if (stat != QLA_SUCCESS) {
  3245. ql4_printk(KERN_INFO, ha, "DEVICE RESET FAILED. %d\n", stat);
  3246. goto eh_dev_reset_done;
  3247. }
  3248. if (qla4xxx_eh_wait_for_commands(ha, scsi_target(cmd->device),
  3249. cmd->device)) {
  3250. ql4_printk(KERN_INFO, ha,
  3251. "DEVICE RESET FAILED - waiting for "
  3252. "commands.\n");
  3253. goto eh_dev_reset_done;
  3254. }
  3255. /* Send marker. */
  3256. if (qla4xxx_send_marker_iocb(ha, ddb_entry, cmd->device->lun,
  3257. MM_LUN_RESET) != QLA_SUCCESS)
  3258. goto eh_dev_reset_done;
  3259. ql4_printk(KERN_INFO, ha,
  3260. "scsi(%ld:%d:%d:%d): DEVICE RESET SUCCEEDED.\n",
  3261. ha->host_no, cmd->device->channel, cmd->device->id,
  3262. cmd->device->lun);
  3263. ret = SUCCESS;
  3264. eh_dev_reset_done:
  3265. return ret;
  3266. }
  3267. /**
  3268. * qla4xxx_eh_target_reset - callback for target reset.
  3269. * @cmd: Pointer to Linux's SCSI command structure
  3270. *
  3271. * This routine is called by the Linux OS to reset the target.
  3272. **/
  3273. static int qla4xxx_eh_target_reset(struct scsi_cmnd *cmd)
  3274. {
  3275. struct scsi_qla_host *ha = to_qla_host(cmd->device->host);
  3276. struct ddb_entry *ddb_entry = cmd->device->hostdata;
  3277. int stat, ret;
  3278. if (!ddb_entry)
  3279. return FAILED;
  3280. ret = iscsi_block_scsi_eh(cmd);
  3281. if (ret)
  3282. return ret;
  3283. starget_printk(KERN_INFO, scsi_target(cmd->device),
  3284. "WARM TARGET RESET ISSUED.\n");
  3285. DEBUG2(printk(KERN_INFO
  3286. "scsi%ld: TARGET_DEVICE_RESET cmd=%p jiffies = 0x%lx, "
  3287. "to=%x,dpc_flags=%lx, status=%x allowed=%d\n",
  3288. ha->host_no, cmd, jiffies, cmd->request->timeout / HZ,
  3289. ha->dpc_flags, cmd->result, cmd->allowed));
  3290. stat = qla4xxx_reset_target(ha, ddb_entry);
  3291. if (stat != QLA_SUCCESS) {
  3292. starget_printk(KERN_INFO, scsi_target(cmd->device),
  3293. "WARM TARGET RESET FAILED.\n");
  3294. return FAILED;
  3295. }
  3296. if (qla4xxx_eh_wait_for_commands(ha, scsi_target(cmd->device),
  3297. NULL)) {
  3298. starget_printk(KERN_INFO, scsi_target(cmd->device),
  3299. "WARM TARGET DEVICE RESET FAILED - "
  3300. "waiting for commands.\n");
  3301. return FAILED;
  3302. }
  3303. /* Send marker. */
  3304. if (qla4xxx_send_marker_iocb(ha, ddb_entry, cmd->device->lun,
  3305. MM_TGT_WARM_RESET) != QLA_SUCCESS) {
  3306. starget_printk(KERN_INFO, scsi_target(cmd->device),
  3307. "WARM TARGET DEVICE RESET FAILED - "
  3308. "marker iocb failed.\n");
  3309. return FAILED;
  3310. }
  3311. starget_printk(KERN_INFO, scsi_target(cmd->device),
  3312. "WARM TARGET RESET SUCCEEDED.\n");
  3313. return SUCCESS;
  3314. }
  3315. /**
  3316. * qla4xxx_eh_host_reset - kernel callback
  3317. * @cmd: Pointer to Linux's SCSI command structure
  3318. *
  3319. * This routine is invoked by the Linux kernel to perform fatal error
  3320. * recovery on the specified adapter.
  3321. **/
  3322. static int qla4xxx_eh_host_reset(struct scsi_cmnd *cmd)
  3323. {
  3324. int return_status = FAILED;
  3325. struct scsi_qla_host *ha;
  3326. ha = to_qla_host(cmd->device->host);
  3327. if (ql4xdontresethba) {
  3328. DEBUG2(printk("scsi%ld: %s: Don't Reset HBA\n",
  3329. ha->host_no, __func__));
  3330. return FAILED;
  3331. }
  3332. ql4_printk(KERN_INFO, ha,
  3333. "scsi(%ld:%d:%d:%d): HOST RESET ISSUED.\n", ha->host_no,
  3334. cmd->device->channel, cmd->device->id, cmd->device->lun);
  3335. if (qla4xxx_wait_for_hba_online(ha) != QLA_SUCCESS) {
  3336. DEBUG2(printk("scsi%ld:%d: %s: Unable to reset host. Adapter "
  3337. "DEAD.\n", ha->host_no, cmd->device->channel,
  3338. __func__));
  3339. return FAILED;
  3340. }
  3341. if (!test_bit(DPC_RESET_HA, &ha->dpc_flags)) {
  3342. if (is_qla8022(ha))
  3343. set_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags);
  3344. else
  3345. set_bit(DPC_RESET_HA, &ha->dpc_flags);
  3346. }
  3347. if (qla4xxx_recover_adapter(ha) == QLA_SUCCESS)
  3348. return_status = SUCCESS;
  3349. ql4_printk(KERN_INFO, ha, "HOST RESET %s.\n",
  3350. return_status == FAILED ? "FAILED" : "SUCCEEDED");
  3351. return return_status;
  3352. }
  3353. static int qla4xxx_context_reset(struct scsi_qla_host *ha)
  3354. {
  3355. uint32_t mbox_cmd[MBOX_REG_COUNT];
  3356. uint32_t mbox_sts[MBOX_REG_COUNT];
  3357. struct addr_ctrl_blk_def *acb = NULL;
  3358. uint32_t acb_len = sizeof(struct addr_ctrl_blk_def);
  3359. int rval = QLA_SUCCESS;
  3360. dma_addr_t acb_dma;
  3361. acb = dma_alloc_coherent(&ha->pdev->dev,
  3362. sizeof(struct addr_ctrl_blk_def),
  3363. &acb_dma, GFP_KERNEL);
  3364. if (!acb) {
  3365. ql4_printk(KERN_ERR, ha, "%s: Unable to alloc acb\n",
  3366. __func__);
  3367. rval = -ENOMEM;
  3368. goto exit_port_reset;
  3369. }
  3370. memset(acb, 0, acb_len);
  3371. rval = qla4xxx_get_acb(ha, acb_dma, PRIMARI_ACB, acb_len);
  3372. if (rval != QLA_SUCCESS) {
  3373. rval = -EIO;
  3374. goto exit_free_acb;
  3375. }
  3376. rval = qla4xxx_disable_acb(ha);
  3377. if (rval != QLA_SUCCESS) {
  3378. rval = -EIO;
  3379. goto exit_free_acb;
  3380. }
  3381. wait_for_completion_timeout(&ha->disable_acb_comp,
  3382. DISABLE_ACB_TOV * HZ);
  3383. rval = qla4xxx_set_acb(ha, &mbox_cmd[0], &mbox_sts[0], acb_dma);
  3384. if (rval != QLA_SUCCESS) {
  3385. rval = -EIO;
  3386. goto exit_free_acb;
  3387. }
  3388. exit_free_acb:
  3389. dma_free_coherent(&ha->pdev->dev, sizeof(struct addr_ctrl_blk_def),
  3390. acb, acb_dma);
  3391. exit_port_reset:
  3392. DEBUG2(ql4_printk(KERN_INFO, ha, "%s %s\n", __func__,
  3393. rval == QLA_SUCCESS ? "SUCCEEDED" : "FAILED"));
  3394. return rval;
  3395. }
  3396. static int qla4xxx_host_reset(struct Scsi_Host *shost, int reset_type)
  3397. {
  3398. struct scsi_qla_host *ha = to_qla_host(shost);
  3399. int rval = QLA_SUCCESS;
  3400. if (ql4xdontresethba) {
  3401. DEBUG2(ql4_printk(KERN_INFO, ha, "%s: Don't Reset HBA\n",
  3402. __func__));
  3403. rval = -EPERM;
  3404. goto exit_host_reset;
  3405. }
  3406. rval = qla4xxx_wait_for_hba_online(ha);
  3407. if (rval != QLA_SUCCESS) {
  3408. DEBUG2(ql4_printk(KERN_INFO, ha, "%s: Unable to reset host "
  3409. "adapter\n", __func__));
  3410. rval = -EIO;
  3411. goto exit_host_reset;
  3412. }
  3413. if (test_bit(DPC_RESET_HA, &ha->dpc_flags))
  3414. goto recover_adapter;
  3415. switch (reset_type) {
  3416. case SCSI_ADAPTER_RESET:
  3417. set_bit(DPC_RESET_HA, &ha->dpc_flags);
  3418. break;
  3419. case SCSI_FIRMWARE_RESET:
  3420. if (!test_bit(DPC_RESET_HA, &ha->dpc_flags)) {
  3421. if (is_qla8022(ha))
  3422. /* set firmware context reset */
  3423. set_bit(DPC_RESET_HA_FW_CONTEXT,
  3424. &ha->dpc_flags);
  3425. else {
  3426. rval = qla4xxx_context_reset(ha);
  3427. goto exit_host_reset;
  3428. }
  3429. }
  3430. break;
  3431. }
  3432. recover_adapter:
  3433. rval = qla4xxx_recover_adapter(ha);
  3434. if (rval != QLA_SUCCESS) {
  3435. DEBUG2(ql4_printk(KERN_INFO, ha, "%s: recover adapter fail\n",
  3436. __func__));
  3437. rval = -EIO;
  3438. }
  3439. exit_host_reset:
  3440. return rval;
  3441. }
  3442. /* PCI AER driver recovers from all correctable errors w/o
  3443. * driver intervention. For uncorrectable errors PCI AER
  3444. * driver calls the following device driver's callbacks
  3445. *
  3446. * - Fatal Errors - link_reset
  3447. * - Non-Fatal Errors - driver's pci_error_detected() which
  3448. * returns CAN_RECOVER, NEED_RESET or DISCONNECT.
  3449. *
  3450. * PCI AER driver calls
  3451. * CAN_RECOVER - driver's pci_mmio_enabled(), mmio_enabled
  3452. * returns RECOVERED or NEED_RESET if fw_hung
  3453. * NEED_RESET - driver's slot_reset()
  3454. * DISCONNECT - device is dead & cannot recover
  3455. * RECOVERED - driver's pci_resume()
  3456. */
  3457. static pci_ers_result_t
  3458. qla4xxx_pci_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
  3459. {
  3460. struct scsi_qla_host *ha = pci_get_drvdata(pdev);
  3461. ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: error detected:state %x\n",
  3462. ha->host_no, __func__, state);
  3463. if (!is_aer_supported(ha))
  3464. return PCI_ERS_RESULT_NONE;
  3465. switch (state) {
  3466. case pci_channel_io_normal:
  3467. clear_bit(AF_EEH_BUSY, &ha->flags);
  3468. return PCI_ERS_RESULT_CAN_RECOVER;
  3469. case pci_channel_io_frozen:
  3470. set_bit(AF_EEH_BUSY, &ha->flags);
  3471. qla4xxx_mailbox_premature_completion(ha);
  3472. qla4xxx_free_irqs(ha);
  3473. pci_disable_device(pdev);
  3474. /* Return back all IOs */
  3475. qla4xxx_abort_active_cmds(ha, DID_RESET << 16);
  3476. return PCI_ERS_RESULT_NEED_RESET;
  3477. case pci_channel_io_perm_failure:
  3478. set_bit(AF_EEH_BUSY, &ha->flags);
  3479. set_bit(AF_PCI_CHANNEL_IO_PERM_FAILURE, &ha->flags);
  3480. qla4xxx_abort_active_cmds(ha, DID_NO_CONNECT << 16);
  3481. return PCI_ERS_RESULT_DISCONNECT;
  3482. }
  3483. return PCI_ERS_RESULT_NEED_RESET;
  3484. }
  3485. /**
  3486. * qla4xxx_pci_mmio_enabled() gets called if
  3487. * qla4xxx_pci_error_detected() returns PCI_ERS_RESULT_CAN_RECOVER
  3488. * and read/write to the device still works.
  3489. **/
  3490. static pci_ers_result_t
  3491. qla4xxx_pci_mmio_enabled(struct pci_dev *pdev)
  3492. {
  3493. struct scsi_qla_host *ha = pci_get_drvdata(pdev);
  3494. if (!is_aer_supported(ha))
  3495. return PCI_ERS_RESULT_NONE;
  3496. return PCI_ERS_RESULT_RECOVERED;
  3497. }
  3498. static uint32_t qla4_8xxx_error_recovery(struct scsi_qla_host *ha)
  3499. {
  3500. uint32_t rval = QLA_ERROR;
  3501. uint32_t ret = 0;
  3502. int fn;
  3503. struct pci_dev *other_pdev = NULL;
  3504. ql4_printk(KERN_WARNING, ha, "scsi%ld: In %s\n", ha->host_no, __func__);
  3505. set_bit(DPC_RESET_ACTIVE, &ha->dpc_flags);
  3506. if (test_bit(AF_ONLINE, &ha->flags)) {
  3507. clear_bit(AF_ONLINE, &ha->flags);
  3508. clear_bit(AF_LINK_UP, &ha->flags);
  3509. iscsi_host_for_each_session(ha->host, qla4xxx_fail_session);
  3510. qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
  3511. }
  3512. fn = PCI_FUNC(ha->pdev->devfn);
  3513. while (fn > 0) {
  3514. fn--;
  3515. ql4_printk(KERN_INFO, ha, "scsi%ld: %s: Finding PCI device at "
  3516. "func %x\n", ha->host_no, __func__, fn);
  3517. /* Get the pci device given the domain, bus,
  3518. * slot/function number */
  3519. other_pdev =
  3520. pci_get_domain_bus_and_slot(pci_domain_nr(ha->pdev->bus),
  3521. ha->pdev->bus->number, PCI_DEVFN(PCI_SLOT(ha->pdev->devfn),
  3522. fn));
  3523. if (!other_pdev)
  3524. continue;
  3525. if (atomic_read(&other_pdev->enable_cnt)) {
  3526. ql4_printk(KERN_INFO, ha, "scsi%ld: %s: Found PCI "
  3527. "func in enabled state%x\n", ha->host_no,
  3528. __func__, fn);
  3529. pci_dev_put(other_pdev);
  3530. break;
  3531. }
  3532. pci_dev_put(other_pdev);
  3533. }
  3534. /* The first function on the card, the reset owner will
  3535. * start & initialize the firmware. The other functions
  3536. * on the card will reset the firmware context
  3537. */
  3538. if (!fn) {
  3539. ql4_printk(KERN_INFO, ha, "scsi%ld: %s: devfn being reset "
  3540. "0x%x is the owner\n", ha->host_no, __func__,
  3541. ha->pdev->devfn);
  3542. qla4_8xxx_idc_lock(ha);
  3543. qla4_8xxx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
  3544. QLA82XX_DEV_COLD);
  3545. qla4_8xxx_wr_32(ha, QLA82XX_CRB_DRV_IDC_VERSION,
  3546. QLA82XX_IDC_VERSION);
  3547. qla4_8xxx_idc_unlock(ha);
  3548. clear_bit(AF_FW_RECOVERY, &ha->flags);
  3549. rval = qla4xxx_initialize_adapter(ha);
  3550. qla4_8xxx_idc_lock(ha);
  3551. if (rval != QLA_SUCCESS) {
  3552. ql4_printk(KERN_INFO, ha, "scsi%ld: %s: HW State: "
  3553. "FAILED\n", ha->host_no, __func__);
  3554. qla4_8xxx_clear_drv_active(ha);
  3555. qla4_8xxx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
  3556. QLA82XX_DEV_FAILED);
  3557. } else {
  3558. ql4_printk(KERN_INFO, ha, "scsi%ld: %s: HW State: "
  3559. "READY\n", ha->host_no, __func__);
  3560. qla4_8xxx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
  3561. QLA82XX_DEV_READY);
  3562. /* Clear driver state register */
  3563. qla4_8xxx_wr_32(ha, QLA82XX_CRB_DRV_STATE, 0);
  3564. qla4_8xxx_set_drv_active(ha);
  3565. ret = qla4xxx_request_irqs(ha);
  3566. if (ret) {
  3567. ql4_printk(KERN_WARNING, ha, "Failed to "
  3568. "reserve interrupt %d already in use.\n",
  3569. ha->pdev->irq);
  3570. rval = QLA_ERROR;
  3571. } else {
  3572. ha->isp_ops->enable_intrs(ha);
  3573. rval = QLA_SUCCESS;
  3574. }
  3575. }
  3576. qla4_8xxx_idc_unlock(ha);
  3577. } else {
  3578. ql4_printk(KERN_INFO, ha, "scsi%ld: %s: devfn 0x%x is not "
  3579. "the reset owner\n", ha->host_no, __func__,
  3580. ha->pdev->devfn);
  3581. if ((qla4_8xxx_rd_32(ha, QLA82XX_CRB_DEV_STATE) ==
  3582. QLA82XX_DEV_READY)) {
  3583. clear_bit(AF_FW_RECOVERY, &ha->flags);
  3584. rval = qla4xxx_initialize_adapter(ha);
  3585. if (rval == QLA_SUCCESS) {
  3586. ret = qla4xxx_request_irqs(ha);
  3587. if (ret) {
  3588. ql4_printk(KERN_WARNING, ha, "Failed to"
  3589. " reserve interrupt %d already in"
  3590. " use.\n", ha->pdev->irq);
  3591. rval = QLA_ERROR;
  3592. } else {
  3593. ha->isp_ops->enable_intrs(ha);
  3594. rval = QLA_SUCCESS;
  3595. }
  3596. }
  3597. qla4_8xxx_idc_lock(ha);
  3598. qla4_8xxx_set_drv_active(ha);
  3599. qla4_8xxx_idc_unlock(ha);
  3600. }
  3601. }
  3602. clear_bit(DPC_RESET_ACTIVE, &ha->dpc_flags);
  3603. return rval;
  3604. }
  3605. static pci_ers_result_t
  3606. qla4xxx_pci_slot_reset(struct pci_dev *pdev)
  3607. {
  3608. pci_ers_result_t ret = PCI_ERS_RESULT_DISCONNECT;
  3609. struct scsi_qla_host *ha = pci_get_drvdata(pdev);
  3610. int rc;
  3611. ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: slot_reset\n",
  3612. ha->host_no, __func__);
  3613. if (!is_aer_supported(ha))
  3614. return PCI_ERS_RESULT_NONE;
  3615. /* Restore the saved state of PCIe device -
  3616. * BAR registers, PCI Config space, PCIX, MSI,
  3617. * IOV states
  3618. */
  3619. pci_restore_state(pdev);
  3620. /* pci_restore_state() clears the saved_state flag of the device
  3621. * save restored state which resets saved_state flag
  3622. */
  3623. pci_save_state(pdev);
  3624. /* Initialize device or resume if in suspended state */
  3625. rc = pci_enable_device(pdev);
  3626. if (rc) {
  3627. ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: Can't re-enable "
  3628. "device after reset\n", ha->host_no, __func__);
  3629. goto exit_slot_reset;
  3630. }
  3631. ha->isp_ops->disable_intrs(ha);
  3632. if (is_qla8022(ha)) {
  3633. if (qla4_8xxx_error_recovery(ha) == QLA_SUCCESS) {
  3634. ret = PCI_ERS_RESULT_RECOVERED;
  3635. goto exit_slot_reset;
  3636. } else
  3637. goto exit_slot_reset;
  3638. }
  3639. exit_slot_reset:
  3640. ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: Return=%x\n"
  3641. "device after reset\n", ha->host_no, __func__, ret);
  3642. return ret;
  3643. }
  3644. static void
  3645. qla4xxx_pci_resume(struct pci_dev *pdev)
  3646. {
  3647. struct scsi_qla_host *ha = pci_get_drvdata(pdev);
  3648. int ret;
  3649. ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: pci_resume\n",
  3650. ha->host_no, __func__);
  3651. ret = qla4xxx_wait_for_hba_online(ha);
  3652. if (ret != QLA_SUCCESS) {
  3653. ql4_printk(KERN_ERR, ha, "scsi%ld: %s: the device failed to "
  3654. "resume I/O from slot/link_reset\n", ha->host_no,
  3655. __func__);
  3656. }
  3657. pci_cleanup_aer_uncorrect_error_status(pdev);
  3658. clear_bit(AF_EEH_BUSY, &ha->flags);
  3659. }
  3660. static struct pci_error_handlers qla4xxx_err_handler = {
  3661. .error_detected = qla4xxx_pci_error_detected,
  3662. .mmio_enabled = qla4xxx_pci_mmio_enabled,
  3663. .slot_reset = qla4xxx_pci_slot_reset,
  3664. .resume = qla4xxx_pci_resume,
  3665. };
  3666. static struct pci_device_id qla4xxx_pci_tbl[] = {
  3667. {
  3668. .vendor = PCI_VENDOR_ID_QLOGIC,
  3669. .device = PCI_DEVICE_ID_QLOGIC_ISP4010,
  3670. .subvendor = PCI_ANY_ID,
  3671. .subdevice = PCI_ANY_ID,
  3672. },
  3673. {
  3674. .vendor = PCI_VENDOR_ID_QLOGIC,
  3675. .device = PCI_DEVICE_ID_QLOGIC_ISP4022,
  3676. .subvendor = PCI_ANY_ID,
  3677. .subdevice = PCI_ANY_ID,
  3678. },
  3679. {
  3680. .vendor = PCI_VENDOR_ID_QLOGIC,
  3681. .device = PCI_DEVICE_ID_QLOGIC_ISP4032,
  3682. .subvendor = PCI_ANY_ID,
  3683. .subdevice = PCI_ANY_ID,
  3684. },
  3685. {
  3686. .vendor = PCI_VENDOR_ID_QLOGIC,
  3687. .device = PCI_DEVICE_ID_QLOGIC_ISP8022,
  3688. .subvendor = PCI_ANY_ID,
  3689. .subdevice = PCI_ANY_ID,
  3690. },
  3691. {0, 0},
  3692. };
  3693. MODULE_DEVICE_TABLE(pci, qla4xxx_pci_tbl);
  3694. static struct pci_driver qla4xxx_pci_driver = {
  3695. .name = DRIVER_NAME,
  3696. .id_table = qla4xxx_pci_tbl,
  3697. .probe = qla4xxx_probe_adapter,
  3698. .remove = qla4xxx_remove_adapter,
  3699. .err_handler = &qla4xxx_err_handler,
  3700. };
  3701. static int __init qla4xxx_module_init(void)
  3702. {
  3703. int ret;
  3704. /* Allocate cache for SRBs. */
  3705. srb_cachep = kmem_cache_create("qla4xxx_srbs", sizeof(struct srb), 0,
  3706. SLAB_HWCACHE_ALIGN, NULL);
  3707. if (srb_cachep == NULL) {
  3708. printk(KERN_ERR
  3709. "%s: Unable to allocate SRB cache..."
  3710. "Failing load!\n", DRIVER_NAME);
  3711. ret = -ENOMEM;
  3712. goto no_srp_cache;
  3713. }
  3714. /* Derive version string. */
  3715. strcpy(qla4xxx_version_str, QLA4XXX_DRIVER_VERSION);
  3716. if (ql4xextended_error_logging)
  3717. strcat(qla4xxx_version_str, "-debug");
  3718. qla4xxx_scsi_transport =
  3719. iscsi_register_transport(&qla4xxx_iscsi_transport);
  3720. if (!qla4xxx_scsi_transport){
  3721. ret = -ENODEV;
  3722. goto release_srb_cache;
  3723. }
  3724. ret = pci_register_driver(&qla4xxx_pci_driver);
  3725. if (ret)
  3726. goto unregister_transport;
  3727. printk(KERN_INFO "QLogic iSCSI HBA Driver\n");
  3728. return 0;
  3729. unregister_transport:
  3730. iscsi_unregister_transport(&qla4xxx_iscsi_transport);
  3731. release_srb_cache:
  3732. kmem_cache_destroy(srb_cachep);
  3733. no_srp_cache:
  3734. return ret;
  3735. }
  3736. static void __exit qla4xxx_module_exit(void)
  3737. {
  3738. pci_unregister_driver(&qla4xxx_pci_driver);
  3739. iscsi_unregister_transport(&qla4xxx_iscsi_transport);
  3740. kmem_cache_destroy(srb_cachep);
  3741. }
  3742. module_init(qla4xxx_module_init);
  3743. module_exit(qla4xxx_module_exit);
  3744. MODULE_AUTHOR("QLogic Corporation");
  3745. MODULE_DESCRIPTION("QLogic iSCSI HBA Driver");
  3746. MODULE_LICENSE("GPL");
  3747. MODULE_VERSION(QLA4XXX_DRIVER_VERSION);