ql4_os.c 119 KB

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