ql4_os.c 116 KB

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