ql4_os.c 119 KB

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