qla_os.c 91 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539
  1. /*
  2. * QLogic Fibre Channel HBA Driver
  3. * Copyright (c) 2003-2008 QLogic Corporation
  4. *
  5. * See LICENSE.qla2xxx for copyright and licensing details.
  6. */
  7. #include "qla_def.h"
  8. #include <linux/moduleparam.h>
  9. #include <linux/vmalloc.h>
  10. #include <linux/delay.h>
  11. #include <linux/kthread.h>
  12. #include <linux/mutex.h>
  13. #include <linux/kobject.h>
  14. #include <scsi/scsi_tcq.h>
  15. #include <scsi/scsicam.h>
  16. #include <scsi/scsi_transport.h>
  17. #include <scsi/scsi_transport_fc.h>
  18. /*
  19. * Driver version
  20. */
  21. char qla2x00_version_str[40];
  22. /*
  23. * SRB allocation cache
  24. */
  25. static struct kmem_cache *srb_cachep;
  26. int ql2xlogintimeout = 20;
  27. module_param(ql2xlogintimeout, int, S_IRUGO|S_IRUSR);
  28. MODULE_PARM_DESC(ql2xlogintimeout,
  29. "Login timeout value in seconds.");
  30. int qlport_down_retry;
  31. module_param(qlport_down_retry, int, S_IRUGO|S_IRUSR);
  32. MODULE_PARM_DESC(qlport_down_retry,
  33. "Maximum number of command retries to a port that returns "
  34. "a PORT-DOWN status.");
  35. int ql2xplogiabsentdevice;
  36. module_param(ql2xplogiabsentdevice, int, S_IRUGO|S_IWUSR);
  37. MODULE_PARM_DESC(ql2xplogiabsentdevice,
  38. "Option to enable PLOGI to devices that are not present after "
  39. "a Fabric scan. This is needed for several broken switches. "
  40. "Default is 0 - no PLOGI. 1 - perfom PLOGI.");
  41. int ql2xloginretrycount = 0;
  42. module_param(ql2xloginretrycount, int, S_IRUGO|S_IRUSR);
  43. MODULE_PARM_DESC(ql2xloginretrycount,
  44. "Specify an alternate value for the NVRAM login retry count.");
  45. int ql2xallocfwdump = 1;
  46. module_param(ql2xallocfwdump, int, S_IRUGO|S_IRUSR);
  47. MODULE_PARM_DESC(ql2xallocfwdump,
  48. "Option to enable allocation of memory for a firmware dump "
  49. "during HBA initialization. Memory allocation requirements "
  50. "vary by ISP type. Default is 1 - allocate memory.");
  51. int ql2xextended_error_logging;
  52. module_param(ql2xextended_error_logging, int, S_IRUGO|S_IWUSR);
  53. MODULE_PARM_DESC(ql2xextended_error_logging,
  54. "Option to enable extended error logging, "
  55. "Default is 0 - no logging. 1 - log errors.");
  56. static void qla2x00_free_device(scsi_qla_host_t *);
  57. int ql2xfdmienable=1;
  58. module_param(ql2xfdmienable, int, S_IRUGO|S_IRUSR);
  59. MODULE_PARM_DESC(ql2xfdmienable,
  60. "Enables FDMI registratons "
  61. "Default is 0 - no FDMI. 1 - perfom FDMI.");
  62. #define MAX_Q_DEPTH 32
  63. static int ql2xmaxqdepth = MAX_Q_DEPTH;
  64. module_param(ql2xmaxqdepth, int, S_IRUGO|S_IWUSR);
  65. MODULE_PARM_DESC(ql2xmaxqdepth,
  66. "Maximum queue depth to report for target devices.");
  67. int ql2xiidmaenable=1;
  68. module_param(ql2xiidmaenable, int, S_IRUGO|S_IRUSR);
  69. MODULE_PARM_DESC(ql2xiidmaenable,
  70. "Enables iIDMA settings "
  71. "Default is 1 - perform iIDMA. 0 - no iIDMA.");
  72. int ql2xmaxqueues = 1;
  73. module_param(ql2xmaxqueues, int, S_IRUGO|S_IRUSR);
  74. MODULE_PARM_DESC(ql2xmaxqueues,
  75. "Enables MQ settings "
  76. "Default is 1 for single queue. Set it to number \
  77. of queues in MQ mode.");
  78. int ql2xmultique_tag;
  79. module_param(ql2xmultique_tag, int, S_IRUGO|S_IRUSR);
  80. MODULE_PARM_DESC(ql2xmultique_tag,
  81. "Enables CPU affinity settings for the driver "
  82. "Default is 0 for no affinity of request and response IO. "
  83. "Set it to 1 to turn on the cpu affinity.");
  84. int ql2xfwloadbin;
  85. module_param(ql2xfwloadbin, int, S_IRUGO|S_IRUSR);
  86. MODULE_PARM_DESC(ql2xfwloadbin,
  87. "Option to specify location from which to load ISP firmware:\n"
  88. " 2 -- load firmware via the request_firmware() (hotplug)\n"
  89. " interface.\n"
  90. " 1 -- load firmware from flash.\n"
  91. " 0 -- use default semantics.\n");
  92. /*
  93. * SCSI host template entry points
  94. */
  95. static int qla2xxx_slave_configure(struct scsi_device * device);
  96. static int qla2xxx_slave_alloc(struct scsi_device *);
  97. static int qla2xxx_scan_finished(struct Scsi_Host *, unsigned long time);
  98. static void qla2xxx_scan_start(struct Scsi_Host *);
  99. static void qla2xxx_slave_destroy(struct scsi_device *);
  100. static int qla2xxx_queuecommand(struct scsi_cmnd *cmd,
  101. void (*fn)(struct scsi_cmnd *));
  102. static int qla2xxx_eh_abort(struct scsi_cmnd *);
  103. static int qla2xxx_eh_device_reset(struct scsi_cmnd *);
  104. static int qla2xxx_eh_target_reset(struct scsi_cmnd *);
  105. static int qla2xxx_eh_bus_reset(struct scsi_cmnd *);
  106. static int qla2xxx_eh_host_reset(struct scsi_cmnd *);
  107. static int qla2x00_change_queue_depth(struct scsi_device *, int, int);
  108. static int qla2x00_change_queue_type(struct scsi_device *, int);
  109. struct scsi_host_template qla2xxx_driver_template = {
  110. .module = THIS_MODULE,
  111. .name = QLA2XXX_DRIVER_NAME,
  112. .queuecommand = qla2xxx_queuecommand,
  113. .eh_abort_handler = qla2xxx_eh_abort,
  114. .eh_device_reset_handler = qla2xxx_eh_device_reset,
  115. .eh_target_reset_handler = qla2xxx_eh_target_reset,
  116. .eh_bus_reset_handler = qla2xxx_eh_bus_reset,
  117. .eh_host_reset_handler = qla2xxx_eh_host_reset,
  118. .slave_configure = qla2xxx_slave_configure,
  119. .slave_alloc = qla2xxx_slave_alloc,
  120. .slave_destroy = qla2xxx_slave_destroy,
  121. .scan_finished = qla2xxx_scan_finished,
  122. .scan_start = qla2xxx_scan_start,
  123. .change_queue_depth = qla2x00_change_queue_depth,
  124. .change_queue_type = qla2x00_change_queue_type,
  125. .this_id = -1,
  126. .cmd_per_lun = 3,
  127. .use_clustering = ENABLE_CLUSTERING,
  128. .sg_tablesize = SG_ALL,
  129. .max_sectors = 0xFFFF,
  130. .shost_attrs = qla2x00_host_attrs,
  131. };
  132. static struct scsi_transport_template *qla2xxx_transport_template = NULL;
  133. struct scsi_transport_template *qla2xxx_transport_vport_template = NULL;
  134. /* TODO Convert to inlines
  135. *
  136. * Timer routines
  137. */
  138. __inline__ void
  139. qla2x00_start_timer(scsi_qla_host_t *vha, void *func, unsigned long interval)
  140. {
  141. init_timer(&vha->timer);
  142. vha->timer.expires = jiffies + interval * HZ;
  143. vha->timer.data = (unsigned long)vha;
  144. vha->timer.function = (void (*)(unsigned long))func;
  145. add_timer(&vha->timer);
  146. vha->timer_active = 1;
  147. }
  148. static inline void
  149. qla2x00_restart_timer(scsi_qla_host_t *vha, unsigned long interval)
  150. {
  151. mod_timer(&vha->timer, jiffies + interval * HZ);
  152. }
  153. static __inline__ void
  154. qla2x00_stop_timer(scsi_qla_host_t *vha)
  155. {
  156. del_timer_sync(&vha->timer);
  157. vha->timer_active = 0;
  158. }
  159. static int qla2x00_do_dpc(void *data);
  160. static void qla2x00_rst_aen(scsi_qla_host_t *);
  161. static int qla2x00_mem_alloc(struct qla_hw_data *, uint16_t, uint16_t,
  162. struct req_que **, struct rsp_que **);
  163. static void qla2x00_mem_free(struct qla_hw_data *);
  164. static void qla2x00_sp_free_dma(srb_t *);
  165. /* -------------------------------------------------------------------------- */
  166. static int qla2x00_alloc_queues(struct qla_hw_data *ha)
  167. {
  168. ha->req_q_map = kzalloc(sizeof(struct req_que *) * ha->max_req_queues,
  169. GFP_KERNEL);
  170. if (!ha->req_q_map) {
  171. qla_printk(KERN_WARNING, ha,
  172. "Unable to allocate memory for request queue ptrs\n");
  173. goto fail_req_map;
  174. }
  175. ha->rsp_q_map = kzalloc(sizeof(struct rsp_que *) * ha->max_rsp_queues,
  176. GFP_KERNEL);
  177. if (!ha->rsp_q_map) {
  178. qla_printk(KERN_WARNING, ha,
  179. "Unable to allocate memory for response queue ptrs\n");
  180. goto fail_rsp_map;
  181. }
  182. set_bit(0, ha->rsp_qid_map);
  183. set_bit(0, ha->req_qid_map);
  184. return 1;
  185. fail_rsp_map:
  186. kfree(ha->req_q_map);
  187. ha->req_q_map = NULL;
  188. fail_req_map:
  189. return -ENOMEM;
  190. }
  191. static void qla2x00_free_req_que(struct qla_hw_data *ha, struct req_que *req)
  192. {
  193. if (req && req->ring)
  194. dma_free_coherent(&ha->pdev->dev,
  195. (req->length + 1) * sizeof(request_t),
  196. req->ring, req->dma);
  197. kfree(req);
  198. req = NULL;
  199. }
  200. static void qla2x00_free_rsp_que(struct qla_hw_data *ha, struct rsp_que *rsp)
  201. {
  202. if (rsp && rsp->ring)
  203. dma_free_coherent(&ha->pdev->dev,
  204. (rsp->length + 1) * sizeof(response_t),
  205. rsp->ring, rsp->dma);
  206. kfree(rsp);
  207. rsp = NULL;
  208. }
  209. static void qla2x00_free_queues(struct qla_hw_data *ha)
  210. {
  211. struct req_que *req;
  212. struct rsp_que *rsp;
  213. int cnt;
  214. for (cnt = 0; cnt < ha->max_req_queues; cnt++) {
  215. req = ha->req_q_map[cnt];
  216. qla2x00_free_req_que(ha, req);
  217. }
  218. kfree(ha->req_q_map);
  219. ha->req_q_map = NULL;
  220. for (cnt = 0; cnt < ha->max_rsp_queues; cnt++) {
  221. rsp = ha->rsp_q_map[cnt];
  222. qla2x00_free_rsp_que(ha, rsp);
  223. }
  224. kfree(ha->rsp_q_map);
  225. ha->rsp_q_map = NULL;
  226. }
  227. static int qla25xx_setup_mode(struct scsi_qla_host *vha)
  228. {
  229. uint16_t options = 0;
  230. int ques, req, ret;
  231. struct qla_hw_data *ha = vha->hw;
  232. if (!(ha->fw_attributes & BIT_6)) {
  233. qla_printk(KERN_INFO, ha,
  234. "Firmware is not multi-queue capable\n");
  235. goto fail;
  236. }
  237. if (ql2xmultique_tag) {
  238. /* create a request queue for IO */
  239. options |= BIT_7;
  240. req = qla25xx_create_req_que(ha, options, 0, 0, -1,
  241. QLA_DEFAULT_QUE_QOS);
  242. if (!req) {
  243. qla_printk(KERN_WARNING, ha,
  244. "Can't create request queue\n");
  245. goto fail;
  246. }
  247. ha->wq = create_workqueue("qla2xxx_wq");
  248. vha->req = ha->req_q_map[req];
  249. options |= BIT_1;
  250. for (ques = 1; ques < ha->max_rsp_queues; ques++) {
  251. ret = qla25xx_create_rsp_que(ha, options, 0, 0, req);
  252. if (!ret) {
  253. qla_printk(KERN_WARNING, ha,
  254. "Response Queue create failed\n");
  255. goto fail2;
  256. }
  257. }
  258. ha->flags.cpu_affinity_enabled = 1;
  259. DEBUG2(qla_printk(KERN_INFO, ha,
  260. "CPU affinity mode enabled, no. of response"
  261. " queues:%d, no. of request queues:%d\n",
  262. ha->max_rsp_queues, ha->max_req_queues));
  263. }
  264. return 0;
  265. fail2:
  266. qla25xx_delete_queues(vha);
  267. destroy_workqueue(ha->wq);
  268. ha->wq = NULL;
  269. fail:
  270. ha->mqenable = 0;
  271. kfree(ha->req_q_map);
  272. kfree(ha->rsp_q_map);
  273. ha->max_req_queues = ha->max_rsp_queues = 1;
  274. return 1;
  275. }
  276. static char *
  277. qla2x00_pci_info_str(struct scsi_qla_host *vha, char *str)
  278. {
  279. struct qla_hw_data *ha = vha->hw;
  280. static char *pci_bus_modes[] = {
  281. "33", "66", "100", "133",
  282. };
  283. uint16_t pci_bus;
  284. strcpy(str, "PCI");
  285. pci_bus = (ha->pci_attr & (BIT_9 | BIT_10)) >> 9;
  286. if (pci_bus) {
  287. strcat(str, "-X (");
  288. strcat(str, pci_bus_modes[pci_bus]);
  289. } else {
  290. pci_bus = (ha->pci_attr & BIT_8) >> 8;
  291. strcat(str, " (");
  292. strcat(str, pci_bus_modes[pci_bus]);
  293. }
  294. strcat(str, " MHz)");
  295. return (str);
  296. }
  297. static char *
  298. qla24xx_pci_info_str(struct scsi_qla_host *vha, char *str)
  299. {
  300. static char *pci_bus_modes[] = { "33", "66", "100", "133", };
  301. struct qla_hw_data *ha = vha->hw;
  302. uint32_t pci_bus;
  303. int pcie_reg;
  304. pcie_reg = pci_find_capability(ha->pdev, PCI_CAP_ID_EXP);
  305. if (pcie_reg) {
  306. char lwstr[6];
  307. uint16_t pcie_lstat, lspeed, lwidth;
  308. pcie_reg += 0x12;
  309. pci_read_config_word(ha->pdev, pcie_reg, &pcie_lstat);
  310. lspeed = pcie_lstat & (BIT_0 | BIT_1 | BIT_2 | BIT_3);
  311. lwidth = (pcie_lstat &
  312. (BIT_4 | BIT_5 | BIT_6 | BIT_7 | BIT_8 | BIT_9)) >> 4;
  313. strcpy(str, "PCIe (");
  314. if (lspeed == 1)
  315. strcat(str, "2.5GT/s ");
  316. else if (lspeed == 2)
  317. strcat(str, "5.0GT/s ");
  318. else
  319. strcat(str, "<unknown> ");
  320. snprintf(lwstr, sizeof(lwstr), "x%d)", lwidth);
  321. strcat(str, lwstr);
  322. return str;
  323. }
  324. strcpy(str, "PCI");
  325. pci_bus = (ha->pci_attr & CSRX_PCIX_BUS_MODE_MASK) >> 8;
  326. if (pci_bus == 0 || pci_bus == 8) {
  327. strcat(str, " (");
  328. strcat(str, pci_bus_modes[pci_bus >> 3]);
  329. } else {
  330. strcat(str, "-X ");
  331. if (pci_bus & BIT_2)
  332. strcat(str, "Mode 2");
  333. else
  334. strcat(str, "Mode 1");
  335. strcat(str, " (");
  336. strcat(str, pci_bus_modes[pci_bus & ~BIT_2]);
  337. }
  338. strcat(str, " MHz)");
  339. return str;
  340. }
  341. static char *
  342. qla2x00_fw_version_str(struct scsi_qla_host *vha, char *str)
  343. {
  344. char un_str[10];
  345. struct qla_hw_data *ha = vha->hw;
  346. sprintf(str, "%d.%02d.%02d ", ha->fw_major_version,
  347. ha->fw_minor_version,
  348. ha->fw_subminor_version);
  349. if (ha->fw_attributes & BIT_9) {
  350. strcat(str, "FLX");
  351. return (str);
  352. }
  353. switch (ha->fw_attributes & 0xFF) {
  354. case 0x7:
  355. strcat(str, "EF");
  356. break;
  357. case 0x17:
  358. strcat(str, "TP");
  359. break;
  360. case 0x37:
  361. strcat(str, "IP");
  362. break;
  363. case 0x77:
  364. strcat(str, "VI");
  365. break;
  366. default:
  367. sprintf(un_str, "(%x)", ha->fw_attributes);
  368. strcat(str, un_str);
  369. break;
  370. }
  371. if (ha->fw_attributes & 0x100)
  372. strcat(str, "X");
  373. return (str);
  374. }
  375. static char *
  376. qla24xx_fw_version_str(struct scsi_qla_host *vha, char *str)
  377. {
  378. struct qla_hw_data *ha = vha->hw;
  379. sprintf(str, "%d.%02d.%02d (%x)", ha->fw_major_version,
  380. ha->fw_minor_version, ha->fw_subminor_version, ha->fw_attributes);
  381. return str;
  382. }
  383. static inline srb_t *
  384. qla2x00_get_new_sp(scsi_qla_host_t *vha, fc_port_t *fcport,
  385. struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *))
  386. {
  387. srb_t *sp;
  388. struct qla_hw_data *ha = vha->hw;
  389. sp = mempool_alloc(ha->srb_mempool, GFP_ATOMIC);
  390. if (!sp)
  391. return sp;
  392. sp->fcport = fcport;
  393. sp->cmd = cmd;
  394. sp->flags = 0;
  395. CMD_SP(cmd) = (void *)sp;
  396. cmd->scsi_done = done;
  397. sp->ctx = NULL;
  398. return sp;
  399. }
  400. static int
  401. qla2xxx_queuecommand(struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *))
  402. {
  403. scsi_qla_host_t *vha = shost_priv(cmd->device->host);
  404. fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
  405. struct fc_rport *rport = starget_to_rport(scsi_target(cmd->device));
  406. struct qla_hw_data *ha = vha->hw;
  407. struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
  408. srb_t *sp;
  409. int rval;
  410. if (ha->flags.eeh_busy) {
  411. if (ha->flags.pci_channel_io_perm_failure)
  412. cmd->result = DID_NO_CONNECT << 16;
  413. else
  414. cmd->result = DID_REQUEUE << 16;
  415. goto qc24_fail_command;
  416. }
  417. rval = fc_remote_port_chkready(rport);
  418. if (rval) {
  419. cmd->result = rval;
  420. goto qc24_fail_command;
  421. }
  422. /* Close window on fcport/rport state-transitioning. */
  423. if (fcport->drport)
  424. goto qc24_target_busy;
  425. if (atomic_read(&fcport->state) != FCS_ONLINE) {
  426. if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD ||
  427. atomic_read(&base_vha->loop_state) == LOOP_DEAD) {
  428. cmd->result = DID_NO_CONNECT << 16;
  429. goto qc24_fail_command;
  430. }
  431. goto qc24_target_busy;
  432. }
  433. spin_unlock_irq(vha->host->host_lock);
  434. sp = qla2x00_get_new_sp(base_vha, fcport, cmd, done);
  435. if (!sp)
  436. goto qc24_host_busy_lock;
  437. rval = ha->isp_ops->start_scsi(sp);
  438. if (rval != QLA_SUCCESS)
  439. goto qc24_host_busy_free_sp;
  440. spin_lock_irq(vha->host->host_lock);
  441. return 0;
  442. qc24_host_busy_free_sp:
  443. qla2x00_sp_free_dma(sp);
  444. mempool_free(sp, ha->srb_mempool);
  445. qc24_host_busy_lock:
  446. spin_lock_irq(vha->host->host_lock);
  447. return SCSI_MLQUEUE_HOST_BUSY;
  448. qc24_target_busy:
  449. return SCSI_MLQUEUE_TARGET_BUSY;
  450. qc24_fail_command:
  451. done(cmd);
  452. return 0;
  453. }
  454. /*
  455. * qla2x00_eh_wait_on_command
  456. * Waits for the command to be returned by the Firmware for some
  457. * max time.
  458. *
  459. * Input:
  460. * cmd = Scsi Command to wait on.
  461. *
  462. * Return:
  463. * Not Found : 0
  464. * Found : 1
  465. */
  466. static int
  467. qla2x00_eh_wait_on_command(struct scsi_cmnd *cmd)
  468. {
  469. #define ABORT_POLLING_PERIOD 1000
  470. #define ABORT_WAIT_ITER ((10 * 1000) / (ABORT_POLLING_PERIOD))
  471. unsigned long wait_iter = ABORT_WAIT_ITER;
  472. scsi_qla_host_t *vha = shost_priv(cmd->device->host);
  473. struct qla_hw_data *ha = vha->hw;
  474. int ret = QLA_SUCCESS;
  475. if (unlikely(pci_channel_offline(ha->pdev)) || ha->flags.eeh_busy) {
  476. DEBUG17(qla_printk(KERN_WARNING, ha, "return:eh_wait\n"));
  477. return ret;
  478. }
  479. while (CMD_SP(cmd) && wait_iter--) {
  480. msleep(ABORT_POLLING_PERIOD);
  481. }
  482. if (CMD_SP(cmd))
  483. ret = QLA_FUNCTION_FAILED;
  484. return ret;
  485. }
  486. /*
  487. * qla2x00_wait_for_hba_online
  488. * Wait till the HBA is online after going through
  489. * <= MAX_RETRIES_OF_ISP_ABORT or
  490. * finally HBA is disabled ie marked offline
  491. *
  492. * Input:
  493. * ha - pointer to host adapter structure
  494. *
  495. * Note:
  496. * Does context switching-Release SPIN_LOCK
  497. * (if any) before calling this routine.
  498. *
  499. * Return:
  500. * Success (Adapter is online) : 0
  501. * Failed (Adapter is offline/disabled) : 1
  502. */
  503. int
  504. qla2x00_wait_for_hba_online(scsi_qla_host_t *vha)
  505. {
  506. int return_status;
  507. unsigned long wait_online;
  508. struct qla_hw_data *ha = vha->hw;
  509. scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
  510. wait_online = jiffies + (MAX_LOOP_TIMEOUT * HZ);
  511. while (((test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags)) ||
  512. test_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags) ||
  513. test_bit(ISP_ABORT_RETRY, &base_vha->dpc_flags) ||
  514. ha->dpc_active) && time_before(jiffies, wait_online)) {
  515. msleep(1000);
  516. }
  517. if (base_vha->flags.online)
  518. return_status = QLA_SUCCESS;
  519. else
  520. return_status = QLA_FUNCTION_FAILED;
  521. return (return_status);
  522. }
  523. int
  524. qla2x00_wait_for_chip_reset(scsi_qla_host_t *vha)
  525. {
  526. int return_status;
  527. unsigned long wait_reset;
  528. struct qla_hw_data *ha = vha->hw;
  529. scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
  530. wait_reset = jiffies + (MAX_LOOP_TIMEOUT * HZ);
  531. while (((test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags)) ||
  532. test_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags) ||
  533. test_bit(ISP_ABORT_RETRY, &base_vha->dpc_flags) ||
  534. ha->dpc_active) && time_before(jiffies, wait_reset)) {
  535. msleep(1000);
  536. if (!test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags) &&
  537. ha->flags.chip_reset_done)
  538. break;
  539. }
  540. if (ha->flags.chip_reset_done)
  541. return_status = QLA_SUCCESS;
  542. else
  543. return_status = QLA_FUNCTION_FAILED;
  544. return return_status;
  545. }
  546. /*
  547. * qla2x00_wait_for_loop_ready
  548. * Wait for MAX_LOOP_TIMEOUT(5 min) value for loop
  549. * to be in LOOP_READY state.
  550. * Input:
  551. * ha - pointer to host adapter structure
  552. *
  553. * Note:
  554. * Does context switching-Release SPIN_LOCK
  555. * (if any) before calling this routine.
  556. *
  557. *
  558. * Return:
  559. * Success (LOOP_READY) : 0
  560. * Failed (LOOP_NOT_READY) : 1
  561. */
  562. static inline int
  563. qla2x00_wait_for_loop_ready(scsi_qla_host_t *vha)
  564. {
  565. int return_status = QLA_SUCCESS;
  566. unsigned long loop_timeout ;
  567. struct qla_hw_data *ha = vha->hw;
  568. scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
  569. /* wait for 5 min at the max for loop to be ready */
  570. loop_timeout = jiffies + (MAX_LOOP_TIMEOUT * HZ);
  571. while ((!atomic_read(&base_vha->loop_down_timer) &&
  572. atomic_read(&base_vha->loop_state) == LOOP_DOWN) ||
  573. atomic_read(&base_vha->loop_state) != LOOP_READY) {
  574. if (atomic_read(&base_vha->loop_state) == LOOP_DEAD) {
  575. return_status = QLA_FUNCTION_FAILED;
  576. break;
  577. }
  578. msleep(1000);
  579. if (time_after_eq(jiffies, loop_timeout)) {
  580. return_status = QLA_FUNCTION_FAILED;
  581. break;
  582. }
  583. }
  584. return (return_status);
  585. }
  586. void
  587. qla2x00_abort_fcport_cmds(fc_port_t *fcport)
  588. {
  589. int cnt;
  590. unsigned long flags;
  591. srb_t *sp;
  592. scsi_qla_host_t *vha = fcport->vha;
  593. struct qla_hw_data *ha = vha->hw;
  594. struct req_que *req;
  595. spin_lock_irqsave(&ha->hardware_lock, flags);
  596. req = vha->req;
  597. for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++) {
  598. sp = req->outstanding_cmds[cnt];
  599. if (!sp)
  600. continue;
  601. if (sp->fcport != fcport)
  602. continue;
  603. if (sp->ctx)
  604. continue;
  605. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  606. if (ha->isp_ops->abort_command(sp)) {
  607. DEBUG2(qla_printk(KERN_WARNING, ha,
  608. "Abort failed -- %lx\n",
  609. sp->cmd->serial_number));
  610. } else {
  611. if (qla2x00_eh_wait_on_command(sp->cmd) !=
  612. QLA_SUCCESS)
  613. DEBUG2(qla_printk(KERN_WARNING, ha,
  614. "Abort failed while waiting -- %lx\n",
  615. sp->cmd->serial_number));
  616. }
  617. spin_lock_irqsave(&ha->hardware_lock, flags);
  618. }
  619. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  620. }
  621. /**************************************************************************
  622. * qla2xxx_eh_abort
  623. *
  624. * Description:
  625. * The abort function will abort the specified command.
  626. *
  627. * Input:
  628. * cmd = Linux SCSI command packet to be aborted.
  629. *
  630. * Returns:
  631. * Either SUCCESS or FAILED.
  632. *
  633. * Note:
  634. * Only return FAILED if command not returned by firmware.
  635. **************************************************************************/
  636. static int
  637. qla2xxx_eh_abort(struct scsi_cmnd *cmd)
  638. {
  639. scsi_qla_host_t *vha = shost_priv(cmd->device->host);
  640. srb_t *sp;
  641. int ret, i;
  642. unsigned int id, lun;
  643. unsigned long serial;
  644. unsigned long flags;
  645. int wait = 0;
  646. struct qla_hw_data *ha = vha->hw;
  647. struct req_que *req = vha->req;
  648. srb_t *spt;
  649. fc_block_scsi_eh(cmd);
  650. if (!CMD_SP(cmd))
  651. return SUCCESS;
  652. ret = SUCCESS;
  653. id = cmd->device->id;
  654. lun = cmd->device->lun;
  655. serial = cmd->serial_number;
  656. spt = (srb_t *) CMD_SP(cmd);
  657. if (!spt)
  658. return SUCCESS;
  659. /* Check active list for command command. */
  660. spin_lock_irqsave(&ha->hardware_lock, flags);
  661. for (i = 1; i < MAX_OUTSTANDING_COMMANDS; i++) {
  662. sp = req->outstanding_cmds[i];
  663. if (sp == NULL)
  664. continue;
  665. if (sp->ctx)
  666. continue;
  667. if (sp->cmd != cmd)
  668. continue;
  669. DEBUG2(printk("%s(%ld): aborting sp %p from RISC."
  670. " pid=%ld.\n", __func__, vha->host_no, sp, serial));
  671. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  672. if (ha->isp_ops->abort_command(sp)) {
  673. DEBUG2(printk("%s(%ld): abort_command "
  674. "mbx failed.\n", __func__, vha->host_no));
  675. ret = FAILED;
  676. } else {
  677. DEBUG3(printk("%s(%ld): abort_command "
  678. "mbx success.\n", __func__, vha->host_no));
  679. wait = 1;
  680. }
  681. spin_lock_irqsave(&ha->hardware_lock, flags);
  682. break;
  683. }
  684. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  685. /* Wait for the command to be returned. */
  686. if (wait) {
  687. if (qla2x00_eh_wait_on_command(cmd) != QLA_SUCCESS) {
  688. qla_printk(KERN_ERR, ha,
  689. "scsi(%ld:%d:%d): Abort handler timed out -- %lx "
  690. "%x.\n", vha->host_no, id, lun, serial, ret);
  691. ret = FAILED;
  692. }
  693. }
  694. qla_printk(KERN_INFO, ha,
  695. "scsi(%ld:%d:%d): Abort command issued -- %d %lx %x.\n",
  696. vha->host_no, id, lun, wait, serial, ret);
  697. return ret;
  698. }
  699. enum nexus_wait_type {
  700. WAIT_HOST = 0,
  701. WAIT_TARGET,
  702. WAIT_LUN,
  703. };
  704. static int
  705. qla2x00_eh_wait_for_pending_commands(scsi_qla_host_t *vha, unsigned int t,
  706. unsigned int l, srb_t *sp, enum nexus_wait_type type)
  707. {
  708. int cnt, match, status;
  709. unsigned long flags;
  710. struct qla_hw_data *ha = vha->hw;
  711. struct req_que *req;
  712. status = QLA_SUCCESS;
  713. if (!sp)
  714. return status;
  715. spin_lock_irqsave(&ha->hardware_lock, flags);
  716. req = vha->req;
  717. for (cnt = 1; status == QLA_SUCCESS &&
  718. cnt < MAX_OUTSTANDING_COMMANDS; cnt++) {
  719. sp = req->outstanding_cmds[cnt];
  720. if (!sp)
  721. continue;
  722. if (sp->ctx)
  723. continue;
  724. if (vha->vp_idx != sp->fcport->vha->vp_idx)
  725. continue;
  726. match = 0;
  727. switch (type) {
  728. case WAIT_HOST:
  729. match = 1;
  730. break;
  731. case WAIT_TARGET:
  732. match = sp->cmd->device->id == t;
  733. break;
  734. case WAIT_LUN:
  735. match = (sp->cmd->device->id == t &&
  736. sp->cmd->device->lun == l);
  737. break;
  738. }
  739. if (!match)
  740. continue;
  741. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  742. status = qla2x00_eh_wait_on_command(sp->cmd);
  743. spin_lock_irqsave(&ha->hardware_lock, flags);
  744. }
  745. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  746. return status;
  747. }
  748. static char *reset_errors[] = {
  749. "HBA not online",
  750. "HBA not ready",
  751. "Task management failed",
  752. "Waiting for command completions",
  753. };
  754. static int
  755. __qla2xxx_eh_generic_reset(char *name, enum nexus_wait_type type,
  756. struct scsi_cmnd *cmd, int (*do_reset)(struct fc_port *, unsigned int, int))
  757. {
  758. scsi_qla_host_t *vha = shost_priv(cmd->device->host);
  759. fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
  760. int err;
  761. fc_block_scsi_eh(cmd);
  762. if (!fcport)
  763. return FAILED;
  764. qla_printk(KERN_INFO, vha->hw, "scsi(%ld:%d:%d): %s RESET ISSUED.\n",
  765. vha->host_no, cmd->device->id, cmd->device->lun, name);
  766. err = 0;
  767. if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS)
  768. goto eh_reset_failed;
  769. err = 1;
  770. if (qla2x00_wait_for_loop_ready(vha) != QLA_SUCCESS)
  771. goto eh_reset_failed;
  772. err = 2;
  773. if (do_reset(fcport, cmd->device->lun, cmd->request->cpu + 1)
  774. != QLA_SUCCESS)
  775. goto eh_reset_failed;
  776. err = 3;
  777. if (qla2x00_eh_wait_for_pending_commands(vha, cmd->device->id,
  778. cmd->device->lun, (srb_t *) CMD_SP(cmd), type) != QLA_SUCCESS)
  779. goto eh_reset_failed;
  780. qla_printk(KERN_INFO, vha->hw, "scsi(%ld:%d:%d): %s RESET SUCCEEDED.\n",
  781. vha->host_no, cmd->device->id, cmd->device->lun, name);
  782. return SUCCESS;
  783. eh_reset_failed:
  784. qla_printk(KERN_INFO, vha->hw, "scsi(%ld:%d:%d): %s RESET FAILED: %s.\n"
  785. , vha->host_no, cmd->device->id, cmd->device->lun, name,
  786. reset_errors[err]);
  787. return FAILED;
  788. }
  789. static int
  790. qla2xxx_eh_device_reset(struct scsi_cmnd *cmd)
  791. {
  792. scsi_qla_host_t *vha = shost_priv(cmd->device->host);
  793. struct qla_hw_data *ha = vha->hw;
  794. return __qla2xxx_eh_generic_reset("DEVICE", WAIT_LUN, cmd,
  795. ha->isp_ops->lun_reset);
  796. }
  797. static int
  798. qla2xxx_eh_target_reset(struct scsi_cmnd *cmd)
  799. {
  800. scsi_qla_host_t *vha = shost_priv(cmd->device->host);
  801. struct qla_hw_data *ha = vha->hw;
  802. return __qla2xxx_eh_generic_reset("TARGET", WAIT_TARGET, cmd,
  803. ha->isp_ops->target_reset);
  804. }
  805. /**************************************************************************
  806. * qla2xxx_eh_bus_reset
  807. *
  808. * Description:
  809. * The bus reset function will reset the bus and abort any executing
  810. * commands.
  811. *
  812. * Input:
  813. * cmd = Linux SCSI command packet of the command that cause the
  814. * bus reset.
  815. *
  816. * Returns:
  817. * SUCCESS/FAILURE (defined as macro in scsi.h).
  818. *
  819. **************************************************************************/
  820. static int
  821. qla2xxx_eh_bus_reset(struct scsi_cmnd *cmd)
  822. {
  823. scsi_qla_host_t *vha = shost_priv(cmd->device->host);
  824. fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
  825. int ret = FAILED;
  826. unsigned int id, lun;
  827. unsigned long serial;
  828. srb_t *sp = (srb_t *) CMD_SP(cmd);
  829. fc_block_scsi_eh(cmd);
  830. id = cmd->device->id;
  831. lun = cmd->device->lun;
  832. serial = cmd->serial_number;
  833. if (!fcport)
  834. return ret;
  835. qla_printk(KERN_INFO, vha->hw,
  836. "scsi(%ld:%d:%d): BUS RESET ISSUED.\n", vha->host_no, id, lun);
  837. if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
  838. DEBUG2(printk("%s failed:board disabled\n",__func__));
  839. goto eh_bus_reset_done;
  840. }
  841. if (qla2x00_wait_for_loop_ready(vha) == QLA_SUCCESS) {
  842. if (qla2x00_loop_reset(vha) == QLA_SUCCESS)
  843. ret = SUCCESS;
  844. }
  845. if (ret == FAILED)
  846. goto eh_bus_reset_done;
  847. /* Flush outstanding commands. */
  848. if (qla2x00_eh_wait_for_pending_commands(vha, 0, 0, sp, WAIT_HOST) !=
  849. QLA_SUCCESS)
  850. ret = FAILED;
  851. eh_bus_reset_done:
  852. qla_printk(KERN_INFO, vha->hw, "%s: reset %s\n", __func__,
  853. (ret == FAILED) ? "failed" : "succeded");
  854. return ret;
  855. }
  856. /**************************************************************************
  857. * qla2xxx_eh_host_reset
  858. *
  859. * Description:
  860. * The reset function will reset the Adapter.
  861. *
  862. * Input:
  863. * cmd = Linux SCSI command packet of the command that cause the
  864. * adapter reset.
  865. *
  866. * Returns:
  867. * Either SUCCESS or FAILED.
  868. *
  869. * Note:
  870. **************************************************************************/
  871. static int
  872. qla2xxx_eh_host_reset(struct scsi_cmnd *cmd)
  873. {
  874. scsi_qla_host_t *vha = shost_priv(cmd->device->host);
  875. fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
  876. struct qla_hw_data *ha = vha->hw;
  877. int ret = FAILED;
  878. unsigned int id, lun;
  879. unsigned long serial;
  880. srb_t *sp = (srb_t *) CMD_SP(cmd);
  881. scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
  882. fc_block_scsi_eh(cmd);
  883. id = cmd->device->id;
  884. lun = cmd->device->lun;
  885. serial = cmd->serial_number;
  886. if (!fcport)
  887. return ret;
  888. qla_printk(KERN_INFO, ha,
  889. "scsi(%ld:%d:%d): ADAPTER RESET ISSUED.\n", vha->host_no, id, lun);
  890. if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS)
  891. goto eh_host_reset_lock;
  892. /*
  893. * Fixme-may be dpc thread is active and processing
  894. * loop_resync,so wait a while for it to
  895. * be completed and then issue big hammer.Otherwise
  896. * it may cause I/O failure as big hammer marks the
  897. * devices as lost kicking of the port_down_timer
  898. * while dpc is stuck for the mailbox to complete.
  899. */
  900. qla2x00_wait_for_loop_ready(vha);
  901. if (vha != base_vha) {
  902. if (qla2x00_vp_abort_isp(vha))
  903. goto eh_host_reset_lock;
  904. } else {
  905. if (ha->wq)
  906. flush_workqueue(ha->wq);
  907. set_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
  908. if (qla2x00_abort_isp(base_vha)) {
  909. clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
  910. /* failed. schedule dpc to try */
  911. set_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags);
  912. if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS)
  913. goto eh_host_reset_lock;
  914. }
  915. clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
  916. }
  917. /* Waiting for command to be returned to OS.*/
  918. if (qla2x00_eh_wait_for_pending_commands(vha, 0, 0, sp, WAIT_HOST) ==
  919. QLA_SUCCESS)
  920. ret = SUCCESS;
  921. eh_host_reset_lock:
  922. qla_printk(KERN_INFO, ha, "%s: reset %s\n", __func__,
  923. (ret == FAILED) ? "failed" : "succeded");
  924. return ret;
  925. }
  926. /*
  927. * qla2x00_loop_reset
  928. * Issue loop reset.
  929. *
  930. * Input:
  931. * ha = adapter block pointer.
  932. *
  933. * Returns:
  934. * 0 = success
  935. */
  936. int
  937. qla2x00_loop_reset(scsi_qla_host_t *vha)
  938. {
  939. int ret;
  940. struct fc_port *fcport;
  941. struct qla_hw_data *ha = vha->hw;
  942. if (ha->flags.enable_lip_full_login && !IS_QLA81XX(ha)) {
  943. ret = qla2x00_full_login_lip(vha);
  944. if (ret != QLA_SUCCESS) {
  945. DEBUG2_3(printk("%s(%ld): failed: "
  946. "full_login_lip=%d.\n", __func__, vha->host_no,
  947. ret));
  948. }
  949. atomic_set(&vha->loop_state, LOOP_DOWN);
  950. atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
  951. qla2x00_mark_all_devices_lost(vha, 0);
  952. qla2x00_wait_for_loop_ready(vha);
  953. }
  954. if (ha->flags.enable_lip_reset) {
  955. ret = qla2x00_lip_reset(vha);
  956. if (ret != QLA_SUCCESS) {
  957. DEBUG2_3(printk("%s(%ld): failed: "
  958. "lip_reset=%d.\n", __func__, vha->host_no, ret));
  959. } else
  960. qla2x00_wait_for_loop_ready(vha);
  961. }
  962. if (ha->flags.enable_target_reset) {
  963. list_for_each_entry(fcport, &vha->vp_fcports, list) {
  964. if (fcport->port_type != FCT_TARGET)
  965. continue;
  966. ret = ha->isp_ops->target_reset(fcport, 0, 0);
  967. if (ret != QLA_SUCCESS) {
  968. DEBUG2_3(printk("%s(%ld): bus_reset failed: "
  969. "target_reset=%d d_id=%x.\n", __func__,
  970. vha->host_no, ret, fcport->d_id.b24));
  971. }
  972. }
  973. }
  974. /* Issue marker command only when we are going to start the I/O */
  975. vha->marker_needed = 1;
  976. return QLA_SUCCESS;
  977. }
  978. void
  979. qla2x00_abort_all_cmds(scsi_qla_host_t *vha, int res)
  980. {
  981. int que, cnt;
  982. unsigned long flags;
  983. srb_t *sp;
  984. struct srb_ctx *ctx;
  985. struct qla_hw_data *ha = vha->hw;
  986. struct req_que *req;
  987. spin_lock_irqsave(&ha->hardware_lock, flags);
  988. for (que = 0; que < ha->max_req_queues; que++) {
  989. req = ha->req_q_map[que];
  990. if (!req)
  991. continue;
  992. for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++) {
  993. sp = req->outstanding_cmds[cnt];
  994. if (sp) {
  995. req->outstanding_cmds[cnt] = NULL;
  996. if (!sp->ctx) {
  997. sp->cmd->result = res;
  998. qla2x00_sp_compl(ha, sp);
  999. } else {
  1000. ctx = sp->ctx;
  1001. del_timer_sync(&ctx->timer);
  1002. ctx->free(sp);
  1003. }
  1004. }
  1005. }
  1006. }
  1007. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  1008. }
  1009. static int
  1010. qla2xxx_slave_alloc(struct scsi_device *sdev)
  1011. {
  1012. struct fc_rport *rport = starget_to_rport(scsi_target(sdev));
  1013. if (!rport || fc_remote_port_chkready(rport))
  1014. return -ENXIO;
  1015. sdev->hostdata = *(fc_port_t **)rport->dd_data;
  1016. return 0;
  1017. }
  1018. static int
  1019. qla2xxx_slave_configure(struct scsi_device *sdev)
  1020. {
  1021. scsi_qla_host_t *vha = shost_priv(sdev->host);
  1022. struct qla_hw_data *ha = vha->hw;
  1023. struct fc_rport *rport = starget_to_rport(sdev->sdev_target);
  1024. fc_port_t *fcport = *(fc_port_t **)rport->dd_data;
  1025. struct req_que *req = vha->req;
  1026. if (sdev->tagged_supported)
  1027. scsi_activate_tcq(sdev, req->max_q_depth);
  1028. else
  1029. scsi_deactivate_tcq(sdev, req->max_q_depth);
  1030. rport->dev_loss_tmo = ha->port_down_retry_count;
  1031. if (sdev->type == TYPE_TAPE)
  1032. fcport->flags |= FCF_TAPE_PRESENT;
  1033. return 0;
  1034. }
  1035. static void
  1036. qla2xxx_slave_destroy(struct scsi_device *sdev)
  1037. {
  1038. sdev->hostdata = NULL;
  1039. }
  1040. static void qla2x00_handle_queue_full(struct scsi_device *sdev, int qdepth)
  1041. {
  1042. fc_port_t *fcport = (struct fc_port *) sdev->hostdata;
  1043. if (!scsi_track_queue_full(sdev, qdepth))
  1044. return;
  1045. DEBUG2(qla_printk(KERN_INFO, fcport->vha->hw,
  1046. "scsi(%ld:%d:%d:%d): Queue depth adjusted-down to %d.\n",
  1047. fcport->vha->host_no, sdev->channel, sdev->id, sdev->lun,
  1048. sdev->queue_depth));
  1049. }
  1050. static void qla2x00_adjust_sdev_qdepth_up(struct scsi_device *sdev, int qdepth)
  1051. {
  1052. fc_port_t *fcport = sdev->hostdata;
  1053. struct scsi_qla_host *vha = fcport->vha;
  1054. struct qla_hw_data *ha = vha->hw;
  1055. struct req_que *req = NULL;
  1056. req = vha->req;
  1057. if (!req)
  1058. return;
  1059. if (req->max_q_depth <= sdev->queue_depth || req->max_q_depth < qdepth)
  1060. return;
  1061. if (sdev->ordered_tags)
  1062. scsi_adjust_queue_depth(sdev, MSG_ORDERED_TAG, qdepth);
  1063. else
  1064. scsi_adjust_queue_depth(sdev, MSG_SIMPLE_TAG, qdepth);
  1065. DEBUG2(qla_printk(KERN_INFO, ha,
  1066. "scsi(%ld:%d:%d:%d): Queue depth adjusted-up to %d.\n",
  1067. fcport->vha->host_no, sdev->channel, sdev->id, sdev->lun,
  1068. sdev->queue_depth));
  1069. }
  1070. static int
  1071. qla2x00_change_queue_depth(struct scsi_device *sdev, int qdepth, int reason)
  1072. {
  1073. switch (reason) {
  1074. case SCSI_QDEPTH_DEFAULT:
  1075. scsi_adjust_queue_depth(sdev, scsi_get_tag_type(sdev), qdepth);
  1076. break;
  1077. case SCSI_QDEPTH_QFULL:
  1078. qla2x00_handle_queue_full(sdev, qdepth);
  1079. break;
  1080. case SCSI_QDEPTH_RAMP_UP:
  1081. qla2x00_adjust_sdev_qdepth_up(sdev, qdepth);
  1082. break;
  1083. default:
  1084. return EOPNOTSUPP;
  1085. }
  1086. return sdev->queue_depth;
  1087. }
  1088. static int
  1089. qla2x00_change_queue_type(struct scsi_device *sdev, int tag_type)
  1090. {
  1091. if (sdev->tagged_supported) {
  1092. scsi_set_tag_type(sdev, tag_type);
  1093. if (tag_type)
  1094. scsi_activate_tcq(sdev, sdev->queue_depth);
  1095. else
  1096. scsi_deactivate_tcq(sdev, sdev->queue_depth);
  1097. } else
  1098. tag_type = 0;
  1099. return tag_type;
  1100. }
  1101. /**
  1102. * qla2x00_config_dma_addressing() - Configure OS DMA addressing method.
  1103. * @ha: HA context
  1104. *
  1105. * At exit, the @ha's flags.enable_64bit_addressing set to indicated
  1106. * supported addressing method.
  1107. */
  1108. static void
  1109. qla2x00_config_dma_addressing(struct qla_hw_data *ha)
  1110. {
  1111. /* Assume a 32bit DMA mask. */
  1112. ha->flags.enable_64bit_addressing = 0;
  1113. if (!dma_set_mask(&ha->pdev->dev, DMA_BIT_MASK(64))) {
  1114. /* Any upper-dword bits set? */
  1115. if (MSD(dma_get_required_mask(&ha->pdev->dev)) &&
  1116. !pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(64))) {
  1117. /* Ok, a 64bit DMA mask is applicable. */
  1118. ha->flags.enable_64bit_addressing = 1;
  1119. ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
  1120. ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
  1121. return;
  1122. }
  1123. }
  1124. dma_set_mask(&ha->pdev->dev, DMA_BIT_MASK(32));
  1125. pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(32));
  1126. }
  1127. static void
  1128. qla2x00_enable_intrs(struct qla_hw_data *ha)
  1129. {
  1130. unsigned long flags = 0;
  1131. struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
  1132. spin_lock_irqsave(&ha->hardware_lock, flags);
  1133. ha->interrupts_on = 1;
  1134. /* enable risc and host interrupts */
  1135. WRT_REG_WORD(&reg->ictrl, ICR_EN_INT | ICR_EN_RISC);
  1136. RD_REG_WORD(&reg->ictrl);
  1137. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  1138. }
  1139. static void
  1140. qla2x00_disable_intrs(struct qla_hw_data *ha)
  1141. {
  1142. unsigned long flags = 0;
  1143. struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
  1144. spin_lock_irqsave(&ha->hardware_lock, flags);
  1145. ha->interrupts_on = 0;
  1146. /* disable risc and host interrupts */
  1147. WRT_REG_WORD(&reg->ictrl, 0);
  1148. RD_REG_WORD(&reg->ictrl);
  1149. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  1150. }
  1151. static void
  1152. qla24xx_enable_intrs(struct qla_hw_data *ha)
  1153. {
  1154. unsigned long flags = 0;
  1155. struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
  1156. spin_lock_irqsave(&ha->hardware_lock, flags);
  1157. ha->interrupts_on = 1;
  1158. WRT_REG_DWORD(&reg->ictrl, ICRX_EN_RISC_INT);
  1159. RD_REG_DWORD(&reg->ictrl);
  1160. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  1161. }
  1162. static void
  1163. qla24xx_disable_intrs(struct qla_hw_data *ha)
  1164. {
  1165. unsigned long flags = 0;
  1166. struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
  1167. if (IS_NOPOLLING_TYPE(ha))
  1168. return;
  1169. spin_lock_irqsave(&ha->hardware_lock, flags);
  1170. ha->interrupts_on = 0;
  1171. WRT_REG_DWORD(&reg->ictrl, 0);
  1172. RD_REG_DWORD(&reg->ictrl);
  1173. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  1174. }
  1175. static struct isp_operations qla2100_isp_ops = {
  1176. .pci_config = qla2100_pci_config,
  1177. .reset_chip = qla2x00_reset_chip,
  1178. .chip_diag = qla2x00_chip_diag,
  1179. .config_rings = qla2x00_config_rings,
  1180. .reset_adapter = qla2x00_reset_adapter,
  1181. .nvram_config = qla2x00_nvram_config,
  1182. .update_fw_options = qla2x00_update_fw_options,
  1183. .load_risc = qla2x00_load_risc,
  1184. .pci_info_str = qla2x00_pci_info_str,
  1185. .fw_version_str = qla2x00_fw_version_str,
  1186. .intr_handler = qla2100_intr_handler,
  1187. .enable_intrs = qla2x00_enable_intrs,
  1188. .disable_intrs = qla2x00_disable_intrs,
  1189. .abort_command = qla2x00_abort_command,
  1190. .target_reset = qla2x00_abort_target,
  1191. .lun_reset = qla2x00_lun_reset,
  1192. .fabric_login = qla2x00_login_fabric,
  1193. .fabric_logout = qla2x00_fabric_logout,
  1194. .calc_req_entries = qla2x00_calc_iocbs_32,
  1195. .build_iocbs = qla2x00_build_scsi_iocbs_32,
  1196. .prep_ms_iocb = qla2x00_prep_ms_iocb,
  1197. .prep_ms_fdmi_iocb = qla2x00_prep_ms_fdmi_iocb,
  1198. .read_nvram = qla2x00_read_nvram_data,
  1199. .write_nvram = qla2x00_write_nvram_data,
  1200. .fw_dump = qla2100_fw_dump,
  1201. .beacon_on = NULL,
  1202. .beacon_off = NULL,
  1203. .beacon_blink = NULL,
  1204. .read_optrom = qla2x00_read_optrom_data,
  1205. .write_optrom = qla2x00_write_optrom_data,
  1206. .get_flash_version = qla2x00_get_flash_version,
  1207. .start_scsi = qla2x00_start_scsi,
  1208. };
  1209. static struct isp_operations qla2300_isp_ops = {
  1210. .pci_config = qla2300_pci_config,
  1211. .reset_chip = qla2x00_reset_chip,
  1212. .chip_diag = qla2x00_chip_diag,
  1213. .config_rings = qla2x00_config_rings,
  1214. .reset_adapter = qla2x00_reset_adapter,
  1215. .nvram_config = qla2x00_nvram_config,
  1216. .update_fw_options = qla2x00_update_fw_options,
  1217. .load_risc = qla2x00_load_risc,
  1218. .pci_info_str = qla2x00_pci_info_str,
  1219. .fw_version_str = qla2x00_fw_version_str,
  1220. .intr_handler = qla2300_intr_handler,
  1221. .enable_intrs = qla2x00_enable_intrs,
  1222. .disable_intrs = qla2x00_disable_intrs,
  1223. .abort_command = qla2x00_abort_command,
  1224. .target_reset = qla2x00_abort_target,
  1225. .lun_reset = qla2x00_lun_reset,
  1226. .fabric_login = qla2x00_login_fabric,
  1227. .fabric_logout = qla2x00_fabric_logout,
  1228. .calc_req_entries = qla2x00_calc_iocbs_32,
  1229. .build_iocbs = qla2x00_build_scsi_iocbs_32,
  1230. .prep_ms_iocb = qla2x00_prep_ms_iocb,
  1231. .prep_ms_fdmi_iocb = qla2x00_prep_ms_fdmi_iocb,
  1232. .read_nvram = qla2x00_read_nvram_data,
  1233. .write_nvram = qla2x00_write_nvram_data,
  1234. .fw_dump = qla2300_fw_dump,
  1235. .beacon_on = qla2x00_beacon_on,
  1236. .beacon_off = qla2x00_beacon_off,
  1237. .beacon_blink = qla2x00_beacon_blink,
  1238. .read_optrom = qla2x00_read_optrom_data,
  1239. .write_optrom = qla2x00_write_optrom_data,
  1240. .get_flash_version = qla2x00_get_flash_version,
  1241. .start_scsi = qla2x00_start_scsi,
  1242. };
  1243. static struct isp_operations qla24xx_isp_ops = {
  1244. .pci_config = qla24xx_pci_config,
  1245. .reset_chip = qla24xx_reset_chip,
  1246. .chip_diag = qla24xx_chip_diag,
  1247. .config_rings = qla24xx_config_rings,
  1248. .reset_adapter = qla24xx_reset_adapter,
  1249. .nvram_config = qla24xx_nvram_config,
  1250. .update_fw_options = qla24xx_update_fw_options,
  1251. .load_risc = qla24xx_load_risc,
  1252. .pci_info_str = qla24xx_pci_info_str,
  1253. .fw_version_str = qla24xx_fw_version_str,
  1254. .intr_handler = qla24xx_intr_handler,
  1255. .enable_intrs = qla24xx_enable_intrs,
  1256. .disable_intrs = qla24xx_disable_intrs,
  1257. .abort_command = qla24xx_abort_command,
  1258. .target_reset = qla24xx_abort_target,
  1259. .lun_reset = qla24xx_lun_reset,
  1260. .fabric_login = qla24xx_login_fabric,
  1261. .fabric_logout = qla24xx_fabric_logout,
  1262. .calc_req_entries = NULL,
  1263. .build_iocbs = NULL,
  1264. .prep_ms_iocb = qla24xx_prep_ms_iocb,
  1265. .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
  1266. .read_nvram = qla24xx_read_nvram_data,
  1267. .write_nvram = qla24xx_write_nvram_data,
  1268. .fw_dump = qla24xx_fw_dump,
  1269. .beacon_on = qla24xx_beacon_on,
  1270. .beacon_off = qla24xx_beacon_off,
  1271. .beacon_blink = qla24xx_beacon_blink,
  1272. .read_optrom = qla24xx_read_optrom_data,
  1273. .write_optrom = qla24xx_write_optrom_data,
  1274. .get_flash_version = qla24xx_get_flash_version,
  1275. .start_scsi = qla24xx_start_scsi,
  1276. };
  1277. static struct isp_operations qla25xx_isp_ops = {
  1278. .pci_config = qla25xx_pci_config,
  1279. .reset_chip = qla24xx_reset_chip,
  1280. .chip_diag = qla24xx_chip_diag,
  1281. .config_rings = qla24xx_config_rings,
  1282. .reset_adapter = qla24xx_reset_adapter,
  1283. .nvram_config = qla24xx_nvram_config,
  1284. .update_fw_options = qla24xx_update_fw_options,
  1285. .load_risc = qla24xx_load_risc,
  1286. .pci_info_str = qla24xx_pci_info_str,
  1287. .fw_version_str = qla24xx_fw_version_str,
  1288. .intr_handler = qla24xx_intr_handler,
  1289. .enable_intrs = qla24xx_enable_intrs,
  1290. .disable_intrs = qla24xx_disable_intrs,
  1291. .abort_command = qla24xx_abort_command,
  1292. .target_reset = qla24xx_abort_target,
  1293. .lun_reset = qla24xx_lun_reset,
  1294. .fabric_login = qla24xx_login_fabric,
  1295. .fabric_logout = qla24xx_fabric_logout,
  1296. .calc_req_entries = NULL,
  1297. .build_iocbs = NULL,
  1298. .prep_ms_iocb = qla24xx_prep_ms_iocb,
  1299. .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
  1300. .read_nvram = qla25xx_read_nvram_data,
  1301. .write_nvram = qla25xx_write_nvram_data,
  1302. .fw_dump = qla25xx_fw_dump,
  1303. .beacon_on = qla24xx_beacon_on,
  1304. .beacon_off = qla24xx_beacon_off,
  1305. .beacon_blink = qla24xx_beacon_blink,
  1306. .read_optrom = qla25xx_read_optrom_data,
  1307. .write_optrom = qla24xx_write_optrom_data,
  1308. .get_flash_version = qla24xx_get_flash_version,
  1309. .start_scsi = qla24xx_start_scsi,
  1310. };
  1311. static struct isp_operations qla81xx_isp_ops = {
  1312. .pci_config = qla25xx_pci_config,
  1313. .reset_chip = qla24xx_reset_chip,
  1314. .chip_diag = qla24xx_chip_diag,
  1315. .config_rings = qla24xx_config_rings,
  1316. .reset_adapter = qla24xx_reset_adapter,
  1317. .nvram_config = qla81xx_nvram_config,
  1318. .update_fw_options = qla81xx_update_fw_options,
  1319. .load_risc = qla81xx_load_risc,
  1320. .pci_info_str = qla24xx_pci_info_str,
  1321. .fw_version_str = qla24xx_fw_version_str,
  1322. .intr_handler = qla24xx_intr_handler,
  1323. .enable_intrs = qla24xx_enable_intrs,
  1324. .disable_intrs = qla24xx_disable_intrs,
  1325. .abort_command = qla24xx_abort_command,
  1326. .target_reset = qla24xx_abort_target,
  1327. .lun_reset = qla24xx_lun_reset,
  1328. .fabric_login = qla24xx_login_fabric,
  1329. .fabric_logout = qla24xx_fabric_logout,
  1330. .calc_req_entries = NULL,
  1331. .build_iocbs = NULL,
  1332. .prep_ms_iocb = qla24xx_prep_ms_iocb,
  1333. .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
  1334. .read_nvram = NULL,
  1335. .write_nvram = NULL,
  1336. .fw_dump = qla81xx_fw_dump,
  1337. .beacon_on = qla24xx_beacon_on,
  1338. .beacon_off = qla24xx_beacon_off,
  1339. .beacon_blink = qla24xx_beacon_blink,
  1340. .read_optrom = qla25xx_read_optrom_data,
  1341. .write_optrom = qla24xx_write_optrom_data,
  1342. .get_flash_version = qla24xx_get_flash_version,
  1343. .start_scsi = qla24xx_start_scsi,
  1344. };
  1345. static inline void
  1346. qla2x00_set_isp_flags(struct qla_hw_data *ha)
  1347. {
  1348. ha->device_type = DT_EXTENDED_IDS;
  1349. switch (ha->pdev->device) {
  1350. case PCI_DEVICE_ID_QLOGIC_ISP2100:
  1351. ha->device_type |= DT_ISP2100;
  1352. ha->device_type &= ~DT_EXTENDED_IDS;
  1353. ha->fw_srisc_address = RISC_START_ADDRESS_2100;
  1354. break;
  1355. case PCI_DEVICE_ID_QLOGIC_ISP2200:
  1356. ha->device_type |= DT_ISP2200;
  1357. ha->device_type &= ~DT_EXTENDED_IDS;
  1358. ha->fw_srisc_address = RISC_START_ADDRESS_2100;
  1359. break;
  1360. case PCI_DEVICE_ID_QLOGIC_ISP2300:
  1361. ha->device_type |= DT_ISP2300;
  1362. ha->device_type |= DT_ZIO_SUPPORTED;
  1363. ha->fw_srisc_address = RISC_START_ADDRESS_2300;
  1364. break;
  1365. case PCI_DEVICE_ID_QLOGIC_ISP2312:
  1366. ha->device_type |= DT_ISP2312;
  1367. ha->device_type |= DT_ZIO_SUPPORTED;
  1368. ha->fw_srisc_address = RISC_START_ADDRESS_2300;
  1369. break;
  1370. case PCI_DEVICE_ID_QLOGIC_ISP2322:
  1371. ha->device_type |= DT_ISP2322;
  1372. ha->device_type |= DT_ZIO_SUPPORTED;
  1373. if (ha->pdev->subsystem_vendor == 0x1028 &&
  1374. ha->pdev->subsystem_device == 0x0170)
  1375. ha->device_type |= DT_OEM_001;
  1376. ha->fw_srisc_address = RISC_START_ADDRESS_2300;
  1377. break;
  1378. case PCI_DEVICE_ID_QLOGIC_ISP6312:
  1379. ha->device_type |= DT_ISP6312;
  1380. ha->fw_srisc_address = RISC_START_ADDRESS_2300;
  1381. break;
  1382. case PCI_DEVICE_ID_QLOGIC_ISP6322:
  1383. ha->device_type |= DT_ISP6322;
  1384. ha->fw_srisc_address = RISC_START_ADDRESS_2300;
  1385. break;
  1386. case PCI_DEVICE_ID_QLOGIC_ISP2422:
  1387. ha->device_type |= DT_ISP2422;
  1388. ha->device_type |= DT_ZIO_SUPPORTED;
  1389. ha->device_type |= DT_FWI2;
  1390. ha->device_type |= DT_IIDMA;
  1391. ha->fw_srisc_address = RISC_START_ADDRESS_2400;
  1392. break;
  1393. case PCI_DEVICE_ID_QLOGIC_ISP2432:
  1394. ha->device_type |= DT_ISP2432;
  1395. ha->device_type |= DT_ZIO_SUPPORTED;
  1396. ha->device_type |= DT_FWI2;
  1397. ha->device_type |= DT_IIDMA;
  1398. ha->fw_srisc_address = RISC_START_ADDRESS_2400;
  1399. break;
  1400. case PCI_DEVICE_ID_QLOGIC_ISP8432:
  1401. ha->device_type |= DT_ISP8432;
  1402. ha->device_type |= DT_ZIO_SUPPORTED;
  1403. ha->device_type |= DT_FWI2;
  1404. ha->device_type |= DT_IIDMA;
  1405. ha->fw_srisc_address = RISC_START_ADDRESS_2400;
  1406. break;
  1407. case PCI_DEVICE_ID_QLOGIC_ISP5422:
  1408. ha->device_type |= DT_ISP5422;
  1409. ha->device_type |= DT_FWI2;
  1410. ha->fw_srisc_address = RISC_START_ADDRESS_2400;
  1411. break;
  1412. case PCI_DEVICE_ID_QLOGIC_ISP5432:
  1413. ha->device_type |= DT_ISP5432;
  1414. ha->device_type |= DT_FWI2;
  1415. ha->fw_srisc_address = RISC_START_ADDRESS_2400;
  1416. break;
  1417. case PCI_DEVICE_ID_QLOGIC_ISP2532:
  1418. ha->device_type |= DT_ISP2532;
  1419. ha->device_type |= DT_ZIO_SUPPORTED;
  1420. ha->device_type |= DT_FWI2;
  1421. ha->device_type |= DT_IIDMA;
  1422. ha->fw_srisc_address = RISC_START_ADDRESS_2400;
  1423. break;
  1424. case PCI_DEVICE_ID_QLOGIC_ISP8001:
  1425. ha->device_type |= DT_ISP8001;
  1426. ha->device_type |= DT_ZIO_SUPPORTED;
  1427. ha->device_type |= DT_FWI2;
  1428. ha->device_type |= DT_IIDMA;
  1429. ha->fw_srisc_address = RISC_START_ADDRESS_2400;
  1430. break;
  1431. }
  1432. /* Get adapter physical port no from interrupt pin register. */
  1433. pci_read_config_byte(ha->pdev, PCI_INTERRUPT_PIN, &ha->port_no);
  1434. if (ha->port_no & 1)
  1435. ha->flags.port0 = 1;
  1436. else
  1437. ha->flags.port0 = 0;
  1438. }
  1439. static int
  1440. qla2x00_iospace_config(struct qla_hw_data *ha)
  1441. {
  1442. resource_size_t pio;
  1443. uint16_t msix;
  1444. int cpus;
  1445. if (pci_request_selected_regions(ha->pdev, ha->bars,
  1446. QLA2XXX_DRIVER_NAME)) {
  1447. qla_printk(KERN_WARNING, ha,
  1448. "Failed to reserve PIO/MMIO regions (%s)\n",
  1449. pci_name(ha->pdev));
  1450. goto iospace_error_exit;
  1451. }
  1452. if (!(ha->bars & 1))
  1453. goto skip_pio;
  1454. /* We only need PIO for Flash operations on ISP2312 v2 chips. */
  1455. pio = pci_resource_start(ha->pdev, 0);
  1456. if (pci_resource_flags(ha->pdev, 0) & IORESOURCE_IO) {
  1457. if (pci_resource_len(ha->pdev, 0) < MIN_IOBASE_LEN) {
  1458. qla_printk(KERN_WARNING, ha,
  1459. "Invalid PCI I/O region size (%s)...\n",
  1460. pci_name(ha->pdev));
  1461. pio = 0;
  1462. }
  1463. } else {
  1464. qla_printk(KERN_WARNING, ha,
  1465. "region #0 not a PIO resource (%s)...\n",
  1466. pci_name(ha->pdev));
  1467. pio = 0;
  1468. }
  1469. ha->pio_address = pio;
  1470. skip_pio:
  1471. /* Use MMIO operations for all accesses. */
  1472. if (!(pci_resource_flags(ha->pdev, 1) & IORESOURCE_MEM)) {
  1473. qla_printk(KERN_ERR, ha,
  1474. "region #1 not an MMIO resource (%s), aborting\n",
  1475. pci_name(ha->pdev));
  1476. goto iospace_error_exit;
  1477. }
  1478. if (pci_resource_len(ha->pdev, 1) < MIN_IOBASE_LEN) {
  1479. qla_printk(KERN_ERR, ha,
  1480. "Invalid PCI mem region size (%s), aborting\n",
  1481. pci_name(ha->pdev));
  1482. goto iospace_error_exit;
  1483. }
  1484. ha->iobase = ioremap(pci_resource_start(ha->pdev, 1), MIN_IOBASE_LEN);
  1485. if (!ha->iobase) {
  1486. qla_printk(KERN_ERR, ha,
  1487. "cannot remap MMIO (%s), aborting\n", pci_name(ha->pdev));
  1488. goto iospace_error_exit;
  1489. }
  1490. /* Determine queue resources */
  1491. ha->max_req_queues = ha->max_rsp_queues = 1;
  1492. if ((ql2xmaxqueues <= 1 || ql2xmultique_tag < 1) &&
  1493. (!IS_QLA25XX(ha) && !IS_QLA81XX(ha)))
  1494. goto mqiobase_exit;
  1495. ha->mqiobase = ioremap(pci_resource_start(ha->pdev, 3),
  1496. pci_resource_len(ha->pdev, 3));
  1497. if (ha->mqiobase) {
  1498. /* Read MSIX vector size of the board */
  1499. pci_read_config_word(ha->pdev, QLA_PCI_MSIX_CONTROL, &msix);
  1500. ha->msix_count = msix;
  1501. /* Max queues are bounded by available msix vectors */
  1502. /* queue 0 uses two msix vectors */
  1503. if (ql2xmultique_tag) {
  1504. cpus = num_online_cpus();
  1505. ha->max_rsp_queues = (ha->msix_count - 1 > cpus) ?
  1506. (cpus + 1) : (ha->msix_count - 1);
  1507. ha->max_req_queues = 2;
  1508. } else if (ql2xmaxqueues > 1) {
  1509. ha->max_req_queues = ql2xmaxqueues > QLA_MQ_SIZE ?
  1510. QLA_MQ_SIZE : ql2xmaxqueues;
  1511. DEBUG2(qla_printk(KERN_INFO, ha, "QoS mode set, max no"
  1512. " of request queues:%d\n", ha->max_req_queues));
  1513. }
  1514. qla_printk(KERN_INFO, ha,
  1515. "MSI-X vector count: %d\n", msix);
  1516. } else
  1517. qla_printk(KERN_INFO, ha, "BAR 3 not enabled\n");
  1518. mqiobase_exit:
  1519. ha->msix_count = ha->max_rsp_queues + 1;
  1520. return (0);
  1521. iospace_error_exit:
  1522. return (-ENOMEM);
  1523. }
  1524. static void
  1525. qla2xxx_scan_start(struct Scsi_Host *shost)
  1526. {
  1527. scsi_qla_host_t *vha = shost_priv(shost);
  1528. if (vha->hw->flags.running_gold_fw)
  1529. return;
  1530. set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
  1531. set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
  1532. set_bit(RSCN_UPDATE, &vha->dpc_flags);
  1533. set_bit(NPIV_CONFIG_NEEDED, &vha->dpc_flags);
  1534. }
  1535. static int
  1536. qla2xxx_scan_finished(struct Scsi_Host *shost, unsigned long time)
  1537. {
  1538. scsi_qla_host_t *vha = shost_priv(shost);
  1539. if (!vha->host)
  1540. return 1;
  1541. if (time > vha->hw->loop_reset_delay * HZ)
  1542. return 1;
  1543. return atomic_read(&vha->loop_state) == LOOP_READY;
  1544. }
  1545. /*
  1546. * PCI driver interface
  1547. */
  1548. static int __devinit
  1549. qla2x00_probe_one(struct pci_dev *pdev, const struct pci_device_id *id)
  1550. {
  1551. int ret = -ENODEV;
  1552. struct Scsi_Host *host;
  1553. scsi_qla_host_t *base_vha = NULL;
  1554. struct qla_hw_data *ha;
  1555. char pci_info[30];
  1556. char fw_str[30];
  1557. struct scsi_host_template *sht;
  1558. int bars, max_id, mem_only = 0;
  1559. uint16_t req_length = 0, rsp_length = 0;
  1560. struct req_que *req = NULL;
  1561. struct rsp_que *rsp = NULL;
  1562. bars = pci_select_bars(pdev, IORESOURCE_MEM | IORESOURCE_IO);
  1563. sht = &qla2xxx_driver_template;
  1564. if (pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2422 ||
  1565. pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2432 ||
  1566. pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8432 ||
  1567. pdev->device == PCI_DEVICE_ID_QLOGIC_ISP5422 ||
  1568. pdev->device == PCI_DEVICE_ID_QLOGIC_ISP5432 ||
  1569. pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2532 ||
  1570. pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8001) {
  1571. bars = pci_select_bars(pdev, IORESOURCE_MEM);
  1572. mem_only = 1;
  1573. }
  1574. if (mem_only) {
  1575. if (pci_enable_device_mem(pdev))
  1576. goto probe_out;
  1577. } else {
  1578. if (pci_enable_device(pdev))
  1579. goto probe_out;
  1580. }
  1581. /* This may fail but that's ok */
  1582. pci_enable_pcie_error_reporting(pdev);
  1583. ha = kzalloc(sizeof(struct qla_hw_data), GFP_KERNEL);
  1584. if (!ha) {
  1585. DEBUG(printk("Unable to allocate memory for ha\n"));
  1586. goto probe_out;
  1587. }
  1588. ha->pdev = pdev;
  1589. /* Clear our data area */
  1590. ha->bars = bars;
  1591. ha->mem_only = mem_only;
  1592. spin_lock_init(&ha->hardware_lock);
  1593. /* Set ISP-type information. */
  1594. qla2x00_set_isp_flags(ha);
  1595. /* Set EEH reset type to fundamental if required by hba */
  1596. if ( IS_QLA24XX(ha) || IS_QLA25XX(ha) || IS_QLA81XX(ha)) {
  1597. pdev->needs_freset = 1;
  1598. pci_save_state(pdev);
  1599. }
  1600. /* Configure PCI I/O space */
  1601. ret = qla2x00_iospace_config(ha);
  1602. if (ret)
  1603. goto probe_hw_failed;
  1604. qla_printk(KERN_INFO, ha,
  1605. "Found an ISP%04X, irq %d, iobase 0x%p\n", pdev->device, pdev->irq,
  1606. ha->iobase);
  1607. ha->prev_topology = 0;
  1608. ha->init_cb_size = sizeof(init_cb_t);
  1609. ha->link_data_rate = PORT_SPEED_UNKNOWN;
  1610. ha->optrom_size = OPTROM_SIZE_2300;
  1611. /* Assign ISP specific operations. */
  1612. max_id = MAX_TARGETS_2200;
  1613. if (IS_QLA2100(ha)) {
  1614. max_id = MAX_TARGETS_2100;
  1615. ha->mbx_count = MAILBOX_REGISTER_COUNT_2100;
  1616. req_length = REQUEST_ENTRY_CNT_2100;
  1617. rsp_length = RESPONSE_ENTRY_CNT_2100;
  1618. ha->max_loop_id = SNS_LAST_LOOP_ID_2100;
  1619. ha->gid_list_info_size = 4;
  1620. ha->flash_conf_off = ~0;
  1621. ha->flash_data_off = ~0;
  1622. ha->nvram_conf_off = ~0;
  1623. ha->nvram_data_off = ~0;
  1624. ha->isp_ops = &qla2100_isp_ops;
  1625. } else if (IS_QLA2200(ha)) {
  1626. ha->mbx_count = MAILBOX_REGISTER_COUNT;
  1627. req_length = REQUEST_ENTRY_CNT_2200;
  1628. rsp_length = RESPONSE_ENTRY_CNT_2100;
  1629. ha->max_loop_id = SNS_LAST_LOOP_ID_2100;
  1630. ha->gid_list_info_size = 4;
  1631. ha->flash_conf_off = ~0;
  1632. ha->flash_data_off = ~0;
  1633. ha->nvram_conf_off = ~0;
  1634. ha->nvram_data_off = ~0;
  1635. ha->isp_ops = &qla2100_isp_ops;
  1636. } else if (IS_QLA23XX(ha)) {
  1637. ha->mbx_count = MAILBOX_REGISTER_COUNT;
  1638. req_length = REQUEST_ENTRY_CNT_2200;
  1639. rsp_length = RESPONSE_ENTRY_CNT_2300;
  1640. ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
  1641. ha->gid_list_info_size = 6;
  1642. if (IS_QLA2322(ha) || IS_QLA6322(ha))
  1643. ha->optrom_size = OPTROM_SIZE_2322;
  1644. ha->flash_conf_off = ~0;
  1645. ha->flash_data_off = ~0;
  1646. ha->nvram_conf_off = ~0;
  1647. ha->nvram_data_off = ~0;
  1648. ha->isp_ops = &qla2300_isp_ops;
  1649. } else if (IS_QLA24XX_TYPE(ha)) {
  1650. ha->mbx_count = MAILBOX_REGISTER_COUNT;
  1651. req_length = REQUEST_ENTRY_CNT_24XX;
  1652. rsp_length = RESPONSE_ENTRY_CNT_2300;
  1653. ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
  1654. ha->init_cb_size = sizeof(struct mid_init_cb_24xx);
  1655. ha->gid_list_info_size = 8;
  1656. ha->optrom_size = OPTROM_SIZE_24XX;
  1657. ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA24XX;
  1658. ha->isp_ops = &qla24xx_isp_ops;
  1659. ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
  1660. ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
  1661. ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
  1662. ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
  1663. } else if (IS_QLA25XX(ha)) {
  1664. ha->mbx_count = MAILBOX_REGISTER_COUNT;
  1665. req_length = REQUEST_ENTRY_CNT_24XX;
  1666. rsp_length = RESPONSE_ENTRY_CNT_2300;
  1667. ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
  1668. ha->init_cb_size = sizeof(struct mid_init_cb_24xx);
  1669. ha->gid_list_info_size = 8;
  1670. ha->optrom_size = OPTROM_SIZE_25XX;
  1671. ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
  1672. ha->isp_ops = &qla25xx_isp_ops;
  1673. ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
  1674. ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
  1675. ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
  1676. ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
  1677. } else if (IS_QLA81XX(ha)) {
  1678. ha->mbx_count = MAILBOX_REGISTER_COUNT;
  1679. req_length = REQUEST_ENTRY_CNT_24XX;
  1680. rsp_length = RESPONSE_ENTRY_CNT_2300;
  1681. ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
  1682. ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
  1683. ha->gid_list_info_size = 8;
  1684. ha->optrom_size = OPTROM_SIZE_81XX;
  1685. ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
  1686. ha->isp_ops = &qla81xx_isp_ops;
  1687. ha->flash_conf_off = FARX_ACCESS_FLASH_CONF_81XX;
  1688. ha->flash_data_off = FARX_ACCESS_FLASH_DATA_81XX;
  1689. ha->nvram_conf_off = ~0;
  1690. ha->nvram_data_off = ~0;
  1691. }
  1692. mutex_init(&ha->vport_lock);
  1693. init_completion(&ha->mbx_cmd_comp);
  1694. complete(&ha->mbx_cmd_comp);
  1695. init_completion(&ha->mbx_intr_comp);
  1696. set_bit(0, (unsigned long *) ha->vp_idx_map);
  1697. qla2x00_config_dma_addressing(ha);
  1698. ret = qla2x00_mem_alloc(ha, req_length, rsp_length, &req, &rsp);
  1699. if (!ret) {
  1700. qla_printk(KERN_WARNING, ha,
  1701. "[ERROR] Failed to allocate memory for adapter\n");
  1702. goto probe_hw_failed;
  1703. }
  1704. req->max_q_depth = MAX_Q_DEPTH;
  1705. if (ql2xmaxqdepth != 0 && ql2xmaxqdepth <= 0xffffU)
  1706. req->max_q_depth = ql2xmaxqdepth;
  1707. base_vha = qla2x00_create_host(sht, ha);
  1708. if (!base_vha) {
  1709. qla_printk(KERN_WARNING, ha,
  1710. "[ERROR] Failed to allocate memory for scsi_host\n");
  1711. ret = -ENOMEM;
  1712. qla2x00_mem_free(ha);
  1713. qla2x00_free_req_que(ha, req);
  1714. qla2x00_free_rsp_que(ha, rsp);
  1715. goto probe_hw_failed;
  1716. }
  1717. pci_set_drvdata(pdev, base_vha);
  1718. host = base_vha->host;
  1719. base_vha->req = req;
  1720. host->can_queue = req->length + 128;
  1721. if (IS_QLA2XXX_MIDTYPE(ha))
  1722. base_vha->mgmt_svr_loop_id = 10 + base_vha->vp_idx;
  1723. else
  1724. base_vha->mgmt_svr_loop_id = MANAGEMENT_SERVER +
  1725. base_vha->vp_idx;
  1726. if (IS_QLA2100(ha))
  1727. host->sg_tablesize = 32;
  1728. host->max_id = max_id;
  1729. host->this_id = 255;
  1730. host->cmd_per_lun = 3;
  1731. host->unique_id = host->host_no;
  1732. host->max_cmd_len = MAX_CMDSZ;
  1733. host->max_channel = MAX_BUSES - 1;
  1734. host->max_lun = MAX_LUNS;
  1735. host->transportt = qla2xxx_transport_template;
  1736. /* Set up the irqs */
  1737. ret = qla2x00_request_irqs(ha, rsp);
  1738. if (ret)
  1739. goto probe_init_failed;
  1740. /* Alloc arrays of request and response ring ptrs */
  1741. que_init:
  1742. if (!qla2x00_alloc_queues(ha)) {
  1743. qla_printk(KERN_WARNING, ha,
  1744. "[ERROR] Failed to allocate memory for queue"
  1745. " pointers\n");
  1746. goto probe_init_failed;
  1747. }
  1748. ha->rsp_q_map[0] = rsp;
  1749. ha->req_q_map[0] = req;
  1750. rsp->req = req;
  1751. req->rsp = rsp;
  1752. set_bit(0, ha->req_qid_map);
  1753. set_bit(0, ha->rsp_qid_map);
  1754. /* FWI2-capable only. */
  1755. req->req_q_in = &ha->iobase->isp24.req_q_in;
  1756. req->req_q_out = &ha->iobase->isp24.req_q_out;
  1757. rsp->rsp_q_in = &ha->iobase->isp24.rsp_q_in;
  1758. rsp->rsp_q_out = &ha->iobase->isp24.rsp_q_out;
  1759. if (ha->mqenable) {
  1760. req->req_q_in = &ha->mqiobase->isp25mq.req_q_in;
  1761. req->req_q_out = &ha->mqiobase->isp25mq.req_q_out;
  1762. rsp->rsp_q_in = &ha->mqiobase->isp25mq.rsp_q_in;
  1763. rsp->rsp_q_out = &ha->mqiobase->isp25mq.rsp_q_out;
  1764. }
  1765. if (qla2x00_initialize_adapter(base_vha)) {
  1766. qla_printk(KERN_WARNING, ha,
  1767. "Failed to initialize adapter\n");
  1768. DEBUG2(printk("scsi(%ld): Failed to initialize adapter - "
  1769. "Adapter flags %x.\n",
  1770. base_vha->host_no, base_vha->device_flags));
  1771. ret = -ENODEV;
  1772. goto probe_failed;
  1773. }
  1774. if (ha->mqenable) {
  1775. if (qla25xx_setup_mode(base_vha)) {
  1776. qla_printk(KERN_WARNING, ha,
  1777. "Can't create queues, falling back to single"
  1778. " queue mode\n");
  1779. goto que_init;
  1780. }
  1781. }
  1782. if (ha->flags.running_gold_fw)
  1783. goto skip_dpc;
  1784. /*
  1785. * Startup the kernel thread for this host adapter
  1786. */
  1787. ha->dpc_thread = kthread_create(qla2x00_do_dpc, ha,
  1788. "%s_dpc", base_vha->host_str);
  1789. if (IS_ERR(ha->dpc_thread)) {
  1790. qla_printk(KERN_WARNING, ha,
  1791. "Unable to start DPC thread!\n");
  1792. ret = PTR_ERR(ha->dpc_thread);
  1793. goto probe_failed;
  1794. }
  1795. skip_dpc:
  1796. list_add_tail(&base_vha->list, &ha->vp_list);
  1797. base_vha->host->irq = ha->pdev->irq;
  1798. /* Initialized the timer */
  1799. qla2x00_start_timer(base_vha, qla2x00_timer, WATCH_INTERVAL);
  1800. DEBUG2(printk("DEBUG: detect hba %ld at address = %p\n",
  1801. base_vha->host_no, ha));
  1802. ret = scsi_add_host(host, &pdev->dev);
  1803. if (ret)
  1804. goto probe_failed;
  1805. base_vha->flags.init_done = 1;
  1806. base_vha->flags.online = 1;
  1807. ha->isp_ops->enable_intrs(ha);
  1808. scsi_scan_host(host);
  1809. qla2x00_alloc_sysfs_attr(base_vha);
  1810. qla2x00_init_host_attr(base_vha);
  1811. qla2x00_dfs_setup(base_vha);
  1812. qla_printk(KERN_INFO, ha, "\n"
  1813. " QLogic Fibre Channel HBA Driver: %s\n"
  1814. " QLogic %s - %s\n"
  1815. " ISP%04X: %s @ %s hdma%c, host#=%ld, fw=%s\n",
  1816. qla2x00_version_str, ha->model_number,
  1817. ha->model_desc ? ha->model_desc : "", pdev->device,
  1818. ha->isp_ops->pci_info_str(base_vha, pci_info), pci_name(pdev),
  1819. ha->flags.enable_64bit_addressing ? '+' : '-', base_vha->host_no,
  1820. ha->isp_ops->fw_version_str(base_vha, fw_str));
  1821. return 0;
  1822. probe_init_failed:
  1823. qla2x00_free_req_que(ha, req);
  1824. qla2x00_free_rsp_que(ha, rsp);
  1825. ha->max_req_queues = ha->max_rsp_queues = 0;
  1826. probe_failed:
  1827. if (base_vha->timer_active)
  1828. qla2x00_stop_timer(base_vha);
  1829. base_vha->flags.online = 0;
  1830. if (ha->dpc_thread) {
  1831. struct task_struct *t = ha->dpc_thread;
  1832. ha->dpc_thread = NULL;
  1833. kthread_stop(t);
  1834. }
  1835. qla2x00_free_device(base_vha);
  1836. scsi_host_put(base_vha->host);
  1837. probe_hw_failed:
  1838. if (ha->iobase)
  1839. iounmap(ha->iobase);
  1840. pci_release_selected_regions(ha->pdev, ha->bars);
  1841. kfree(ha);
  1842. ha = NULL;
  1843. probe_out:
  1844. pci_disable_device(pdev);
  1845. return ret;
  1846. }
  1847. static void
  1848. qla2x00_remove_one(struct pci_dev *pdev)
  1849. {
  1850. scsi_qla_host_t *base_vha, *vha, *temp;
  1851. struct qla_hw_data *ha;
  1852. base_vha = pci_get_drvdata(pdev);
  1853. ha = base_vha->hw;
  1854. list_for_each_entry_safe(vha, temp, &ha->vp_list, list) {
  1855. if (vha && vha->fc_vport)
  1856. fc_vport_terminate(vha->fc_vport);
  1857. }
  1858. set_bit(UNLOADING, &base_vha->dpc_flags);
  1859. qla2x00_abort_all_cmds(base_vha, DID_NO_CONNECT << 16);
  1860. qla2x00_dfs_remove(base_vha);
  1861. qla84xx_put_chip(base_vha);
  1862. /* Disable timer */
  1863. if (base_vha->timer_active)
  1864. qla2x00_stop_timer(base_vha);
  1865. base_vha->flags.online = 0;
  1866. /* Flush the work queue and remove it */
  1867. if (ha->wq) {
  1868. flush_workqueue(ha->wq);
  1869. destroy_workqueue(ha->wq);
  1870. ha->wq = NULL;
  1871. }
  1872. /* Kill the kernel thread for this host */
  1873. if (ha->dpc_thread) {
  1874. struct task_struct *t = ha->dpc_thread;
  1875. /*
  1876. * qla2xxx_wake_dpc checks for ->dpc_thread
  1877. * so we need to zero it out.
  1878. */
  1879. ha->dpc_thread = NULL;
  1880. kthread_stop(t);
  1881. }
  1882. qla2x00_free_sysfs_attr(base_vha);
  1883. fc_remove_host(base_vha->host);
  1884. scsi_remove_host(base_vha->host);
  1885. qla2x00_free_device(base_vha);
  1886. scsi_host_put(base_vha->host);
  1887. if (ha->iobase)
  1888. iounmap(ha->iobase);
  1889. if (ha->mqiobase)
  1890. iounmap(ha->mqiobase);
  1891. pci_release_selected_regions(ha->pdev, ha->bars);
  1892. kfree(ha);
  1893. ha = NULL;
  1894. pci_disable_device(pdev);
  1895. pci_set_drvdata(pdev, NULL);
  1896. }
  1897. static void
  1898. qla2x00_free_device(scsi_qla_host_t *vha)
  1899. {
  1900. struct qla_hw_data *ha = vha->hw;
  1901. qla2x00_abort_all_cmds(vha, DID_NO_CONNECT << 16);
  1902. /* Disable timer */
  1903. if (vha->timer_active)
  1904. qla2x00_stop_timer(vha);
  1905. /* Kill the kernel thread for this host */
  1906. if (ha->dpc_thread) {
  1907. struct task_struct *t = ha->dpc_thread;
  1908. /*
  1909. * qla2xxx_wake_dpc checks for ->dpc_thread
  1910. * so we need to zero it out.
  1911. */
  1912. ha->dpc_thread = NULL;
  1913. kthread_stop(t);
  1914. }
  1915. qla25xx_delete_queues(vha);
  1916. if (ha->flags.fce_enabled)
  1917. qla2x00_disable_fce_trace(vha, NULL, NULL);
  1918. if (ha->eft)
  1919. qla2x00_disable_eft_trace(vha);
  1920. /* Stop currently executing firmware. */
  1921. qla2x00_try_to_stop_firmware(vha);
  1922. vha->flags.online = 0;
  1923. /* turn-off interrupts on the card */
  1924. if (ha->interrupts_on)
  1925. ha->isp_ops->disable_intrs(ha);
  1926. qla2x00_free_irqs(vha);
  1927. qla2x00_mem_free(ha);
  1928. qla2x00_free_queues(ha);
  1929. }
  1930. static inline void
  1931. qla2x00_schedule_rport_del(struct scsi_qla_host *vha, fc_port_t *fcport,
  1932. int defer)
  1933. {
  1934. struct fc_rport *rport;
  1935. scsi_qla_host_t *base_vha;
  1936. if (!fcport->rport)
  1937. return;
  1938. rport = fcport->rport;
  1939. if (defer) {
  1940. base_vha = pci_get_drvdata(vha->hw->pdev);
  1941. spin_lock_irq(vha->host->host_lock);
  1942. fcport->drport = rport;
  1943. spin_unlock_irq(vha->host->host_lock);
  1944. set_bit(FCPORT_UPDATE_NEEDED, &base_vha->dpc_flags);
  1945. qla2xxx_wake_dpc(base_vha);
  1946. } else
  1947. fc_remote_port_delete(rport);
  1948. }
  1949. /*
  1950. * qla2x00_mark_device_lost Updates fcport state when device goes offline.
  1951. *
  1952. * Input: ha = adapter block pointer. fcport = port structure pointer.
  1953. *
  1954. * Return: None.
  1955. *
  1956. * Context:
  1957. */
  1958. void qla2x00_mark_device_lost(scsi_qla_host_t *vha, fc_port_t *fcport,
  1959. int do_login, int defer)
  1960. {
  1961. if (atomic_read(&fcport->state) == FCS_ONLINE &&
  1962. vha->vp_idx == fcport->vp_idx) {
  1963. atomic_set(&fcport->state, FCS_DEVICE_LOST);
  1964. qla2x00_schedule_rport_del(vha, fcport, defer);
  1965. }
  1966. /*
  1967. * We may need to retry the login, so don't change the state of the
  1968. * port but do the retries.
  1969. */
  1970. if (atomic_read(&fcport->state) != FCS_DEVICE_DEAD)
  1971. atomic_set(&fcport->state, FCS_DEVICE_LOST);
  1972. if (!do_login)
  1973. return;
  1974. if (fcport->login_retry == 0) {
  1975. fcport->login_retry = vha->hw->login_retry_count;
  1976. set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
  1977. DEBUG(printk("scsi(%ld): Port login retry: "
  1978. "%02x%02x%02x%02x%02x%02x%02x%02x, "
  1979. "id = 0x%04x retry cnt=%d\n",
  1980. vha->host_no,
  1981. fcport->port_name[0],
  1982. fcport->port_name[1],
  1983. fcport->port_name[2],
  1984. fcport->port_name[3],
  1985. fcport->port_name[4],
  1986. fcport->port_name[5],
  1987. fcport->port_name[6],
  1988. fcport->port_name[7],
  1989. fcport->loop_id,
  1990. fcport->login_retry));
  1991. }
  1992. }
  1993. /*
  1994. * qla2x00_mark_all_devices_lost
  1995. * Updates fcport state when device goes offline.
  1996. *
  1997. * Input:
  1998. * ha = adapter block pointer.
  1999. * fcport = port structure pointer.
  2000. *
  2001. * Return:
  2002. * None.
  2003. *
  2004. * Context:
  2005. */
  2006. void
  2007. qla2x00_mark_all_devices_lost(scsi_qla_host_t *vha, int defer)
  2008. {
  2009. fc_port_t *fcport;
  2010. list_for_each_entry(fcport, &vha->vp_fcports, list) {
  2011. if (vha->vp_idx != 0 && vha->vp_idx != fcport->vp_idx)
  2012. continue;
  2013. /*
  2014. * No point in marking the device as lost, if the device is
  2015. * already DEAD.
  2016. */
  2017. if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD)
  2018. continue;
  2019. if (atomic_read(&fcport->state) == FCS_ONLINE) {
  2020. if (defer)
  2021. qla2x00_schedule_rport_del(vha, fcport, defer);
  2022. else if (vha->vp_idx == fcport->vp_idx)
  2023. qla2x00_schedule_rport_del(vha, fcport, defer);
  2024. }
  2025. atomic_set(&fcport->state, FCS_DEVICE_LOST);
  2026. }
  2027. }
  2028. /*
  2029. * qla2x00_mem_alloc
  2030. * Allocates adapter memory.
  2031. *
  2032. * Returns:
  2033. * 0 = success.
  2034. * !0 = failure.
  2035. */
  2036. static int
  2037. qla2x00_mem_alloc(struct qla_hw_data *ha, uint16_t req_len, uint16_t rsp_len,
  2038. struct req_que **req, struct rsp_que **rsp)
  2039. {
  2040. char name[16];
  2041. ha->init_cb = dma_alloc_coherent(&ha->pdev->dev, ha->init_cb_size,
  2042. &ha->init_cb_dma, GFP_KERNEL);
  2043. if (!ha->init_cb)
  2044. goto fail;
  2045. ha->gid_list = dma_alloc_coherent(&ha->pdev->dev, GID_LIST_SIZE,
  2046. &ha->gid_list_dma, GFP_KERNEL);
  2047. if (!ha->gid_list)
  2048. goto fail_free_init_cb;
  2049. ha->srb_mempool = mempool_create_slab_pool(SRB_MIN_REQ, srb_cachep);
  2050. if (!ha->srb_mempool)
  2051. goto fail_free_gid_list;
  2052. /* Get memory for cached NVRAM */
  2053. ha->nvram = kzalloc(MAX_NVRAM_SIZE, GFP_KERNEL);
  2054. if (!ha->nvram)
  2055. goto fail_free_srb_mempool;
  2056. snprintf(name, sizeof(name), "%s_%d", QLA2XXX_DRIVER_NAME,
  2057. ha->pdev->device);
  2058. ha->s_dma_pool = dma_pool_create(name, &ha->pdev->dev,
  2059. DMA_POOL_SIZE, 8, 0);
  2060. if (!ha->s_dma_pool)
  2061. goto fail_free_nvram;
  2062. /* Allocate memory for SNS commands */
  2063. if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
  2064. /* Get consistent memory allocated for SNS commands */
  2065. ha->sns_cmd = dma_alloc_coherent(&ha->pdev->dev,
  2066. sizeof(struct sns_cmd_pkt), &ha->sns_cmd_dma, GFP_KERNEL);
  2067. if (!ha->sns_cmd)
  2068. goto fail_dma_pool;
  2069. } else {
  2070. /* Get consistent memory allocated for MS IOCB */
  2071. ha->ms_iocb = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
  2072. &ha->ms_iocb_dma);
  2073. if (!ha->ms_iocb)
  2074. goto fail_dma_pool;
  2075. /* Get consistent memory allocated for CT SNS commands */
  2076. ha->ct_sns = dma_alloc_coherent(&ha->pdev->dev,
  2077. sizeof(struct ct_sns_pkt), &ha->ct_sns_dma, GFP_KERNEL);
  2078. if (!ha->ct_sns)
  2079. goto fail_free_ms_iocb;
  2080. }
  2081. /* Allocate memory for request ring */
  2082. *req = kzalloc(sizeof(struct req_que), GFP_KERNEL);
  2083. if (!*req) {
  2084. DEBUG(printk("Unable to allocate memory for req\n"));
  2085. goto fail_req;
  2086. }
  2087. (*req)->length = req_len;
  2088. (*req)->ring = dma_alloc_coherent(&ha->pdev->dev,
  2089. ((*req)->length + 1) * sizeof(request_t),
  2090. &(*req)->dma, GFP_KERNEL);
  2091. if (!(*req)->ring) {
  2092. DEBUG(printk("Unable to allocate memory for req_ring\n"));
  2093. goto fail_req_ring;
  2094. }
  2095. /* Allocate memory for response ring */
  2096. *rsp = kzalloc(sizeof(struct rsp_que), GFP_KERNEL);
  2097. if (!*rsp) {
  2098. qla_printk(KERN_WARNING, ha,
  2099. "Unable to allocate memory for rsp\n");
  2100. goto fail_rsp;
  2101. }
  2102. (*rsp)->hw = ha;
  2103. (*rsp)->length = rsp_len;
  2104. (*rsp)->ring = dma_alloc_coherent(&ha->pdev->dev,
  2105. ((*rsp)->length + 1) * sizeof(response_t),
  2106. &(*rsp)->dma, GFP_KERNEL);
  2107. if (!(*rsp)->ring) {
  2108. qla_printk(KERN_WARNING, ha,
  2109. "Unable to allocate memory for rsp_ring\n");
  2110. goto fail_rsp_ring;
  2111. }
  2112. (*req)->rsp = *rsp;
  2113. (*rsp)->req = *req;
  2114. /* Allocate memory for NVRAM data for vports */
  2115. if (ha->nvram_npiv_size) {
  2116. ha->npiv_info = kzalloc(sizeof(struct qla_npiv_entry) *
  2117. ha->nvram_npiv_size, GFP_KERNEL);
  2118. if (!ha->npiv_info) {
  2119. qla_printk(KERN_WARNING, ha,
  2120. "Unable to allocate memory for npiv info\n");
  2121. goto fail_npiv_info;
  2122. }
  2123. } else
  2124. ha->npiv_info = NULL;
  2125. /* Get consistent memory allocated for EX-INIT-CB. */
  2126. if (IS_QLA81XX(ha)) {
  2127. ha->ex_init_cb = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
  2128. &ha->ex_init_cb_dma);
  2129. if (!ha->ex_init_cb)
  2130. goto fail_ex_init_cb;
  2131. }
  2132. INIT_LIST_HEAD(&ha->vp_list);
  2133. return 1;
  2134. fail_ex_init_cb:
  2135. kfree(ha->npiv_info);
  2136. fail_npiv_info:
  2137. dma_free_coherent(&ha->pdev->dev, ((*rsp)->length + 1) *
  2138. sizeof(response_t), (*rsp)->ring, (*rsp)->dma);
  2139. (*rsp)->ring = NULL;
  2140. (*rsp)->dma = 0;
  2141. fail_rsp_ring:
  2142. kfree(*rsp);
  2143. fail_rsp:
  2144. dma_free_coherent(&ha->pdev->dev, ((*req)->length + 1) *
  2145. sizeof(request_t), (*req)->ring, (*req)->dma);
  2146. (*req)->ring = NULL;
  2147. (*req)->dma = 0;
  2148. fail_req_ring:
  2149. kfree(*req);
  2150. fail_req:
  2151. dma_free_coherent(&ha->pdev->dev, sizeof(struct ct_sns_pkt),
  2152. ha->ct_sns, ha->ct_sns_dma);
  2153. ha->ct_sns = NULL;
  2154. ha->ct_sns_dma = 0;
  2155. fail_free_ms_iocb:
  2156. dma_pool_free(ha->s_dma_pool, ha->ms_iocb, ha->ms_iocb_dma);
  2157. ha->ms_iocb = NULL;
  2158. ha->ms_iocb_dma = 0;
  2159. fail_dma_pool:
  2160. dma_pool_destroy(ha->s_dma_pool);
  2161. ha->s_dma_pool = NULL;
  2162. fail_free_nvram:
  2163. kfree(ha->nvram);
  2164. ha->nvram = NULL;
  2165. fail_free_srb_mempool:
  2166. mempool_destroy(ha->srb_mempool);
  2167. ha->srb_mempool = NULL;
  2168. fail_free_gid_list:
  2169. dma_free_coherent(&ha->pdev->dev, GID_LIST_SIZE, ha->gid_list,
  2170. ha->gid_list_dma);
  2171. ha->gid_list = NULL;
  2172. ha->gid_list_dma = 0;
  2173. fail_free_init_cb:
  2174. dma_free_coherent(&ha->pdev->dev, ha->init_cb_size, ha->init_cb,
  2175. ha->init_cb_dma);
  2176. ha->init_cb = NULL;
  2177. ha->init_cb_dma = 0;
  2178. fail:
  2179. DEBUG(printk("%s: Memory allocation failure\n", __func__));
  2180. return -ENOMEM;
  2181. }
  2182. /*
  2183. * qla2x00_mem_free
  2184. * Frees all adapter allocated memory.
  2185. *
  2186. * Input:
  2187. * ha = adapter block pointer.
  2188. */
  2189. static void
  2190. qla2x00_mem_free(struct qla_hw_data *ha)
  2191. {
  2192. if (ha->srb_mempool)
  2193. mempool_destroy(ha->srb_mempool);
  2194. if (ha->fce)
  2195. dma_free_coherent(&ha->pdev->dev, FCE_SIZE, ha->fce,
  2196. ha->fce_dma);
  2197. if (ha->fw_dump) {
  2198. if (ha->eft)
  2199. dma_free_coherent(&ha->pdev->dev,
  2200. ntohl(ha->fw_dump->eft_size), ha->eft, ha->eft_dma);
  2201. vfree(ha->fw_dump);
  2202. }
  2203. if (ha->dcbx_tlv)
  2204. dma_free_coherent(&ha->pdev->dev, DCBX_TLV_DATA_SIZE,
  2205. ha->dcbx_tlv, ha->dcbx_tlv_dma);
  2206. if (ha->xgmac_data)
  2207. dma_free_coherent(&ha->pdev->dev, XGMAC_DATA_SIZE,
  2208. ha->xgmac_data, ha->xgmac_data_dma);
  2209. if (ha->sns_cmd)
  2210. dma_free_coherent(&ha->pdev->dev, sizeof(struct sns_cmd_pkt),
  2211. ha->sns_cmd, ha->sns_cmd_dma);
  2212. if (ha->ct_sns)
  2213. dma_free_coherent(&ha->pdev->dev, sizeof(struct ct_sns_pkt),
  2214. ha->ct_sns, ha->ct_sns_dma);
  2215. if (ha->sfp_data)
  2216. dma_pool_free(ha->s_dma_pool, ha->sfp_data, ha->sfp_data_dma);
  2217. if (ha->edc_data)
  2218. dma_pool_free(ha->s_dma_pool, ha->edc_data, ha->edc_data_dma);
  2219. if (ha->ms_iocb)
  2220. dma_pool_free(ha->s_dma_pool, ha->ms_iocb, ha->ms_iocb_dma);
  2221. if (ha->ex_init_cb)
  2222. dma_pool_free(ha->s_dma_pool, ha->ex_init_cb, ha->ex_init_cb_dma);
  2223. if (ha->s_dma_pool)
  2224. dma_pool_destroy(ha->s_dma_pool);
  2225. if (ha->gid_list)
  2226. dma_free_coherent(&ha->pdev->dev, GID_LIST_SIZE, ha->gid_list,
  2227. ha->gid_list_dma);
  2228. if (ha->init_cb)
  2229. dma_free_coherent(&ha->pdev->dev, ha->init_cb_size,
  2230. ha->init_cb, ha->init_cb_dma);
  2231. vfree(ha->optrom_buffer);
  2232. kfree(ha->nvram);
  2233. kfree(ha->npiv_info);
  2234. ha->srb_mempool = NULL;
  2235. ha->eft = NULL;
  2236. ha->eft_dma = 0;
  2237. ha->sns_cmd = NULL;
  2238. ha->sns_cmd_dma = 0;
  2239. ha->ct_sns = NULL;
  2240. ha->ct_sns_dma = 0;
  2241. ha->ms_iocb = NULL;
  2242. ha->ms_iocb_dma = 0;
  2243. ha->init_cb = NULL;
  2244. ha->init_cb_dma = 0;
  2245. ha->ex_init_cb = NULL;
  2246. ha->ex_init_cb_dma = 0;
  2247. ha->s_dma_pool = NULL;
  2248. ha->gid_list = NULL;
  2249. ha->gid_list_dma = 0;
  2250. ha->fw_dump = NULL;
  2251. ha->fw_dumped = 0;
  2252. ha->fw_dump_reading = 0;
  2253. }
  2254. struct scsi_qla_host *qla2x00_create_host(struct scsi_host_template *sht,
  2255. struct qla_hw_data *ha)
  2256. {
  2257. struct Scsi_Host *host;
  2258. struct scsi_qla_host *vha = NULL;
  2259. host = scsi_host_alloc(sht, sizeof(scsi_qla_host_t));
  2260. if (host == NULL) {
  2261. printk(KERN_WARNING
  2262. "qla2xxx: Couldn't allocate host from scsi layer!\n");
  2263. goto fail;
  2264. }
  2265. /* Clear our data area */
  2266. vha = shost_priv(host);
  2267. memset(vha, 0, sizeof(scsi_qla_host_t));
  2268. vha->host = host;
  2269. vha->host_no = host->host_no;
  2270. vha->hw = ha;
  2271. INIT_LIST_HEAD(&vha->vp_fcports);
  2272. INIT_LIST_HEAD(&vha->work_list);
  2273. INIT_LIST_HEAD(&vha->list);
  2274. spin_lock_init(&vha->work_lock);
  2275. sprintf(vha->host_str, "%s_%ld", QLA2XXX_DRIVER_NAME, vha->host_no);
  2276. return vha;
  2277. fail:
  2278. return vha;
  2279. }
  2280. static struct qla_work_evt *
  2281. qla2x00_alloc_work(struct scsi_qla_host *vha, enum qla_work_type type)
  2282. {
  2283. struct qla_work_evt *e;
  2284. e = kzalloc(sizeof(struct qla_work_evt), GFP_ATOMIC);
  2285. if (!e)
  2286. return NULL;
  2287. INIT_LIST_HEAD(&e->list);
  2288. e->type = type;
  2289. e->flags = QLA_EVT_FLAG_FREE;
  2290. return e;
  2291. }
  2292. static int
  2293. qla2x00_post_work(struct scsi_qla_host *vha, struct qla_work_evt *e)
  2294. {
  2295. unsigned long flags;
  2296. spin_lock_irqsave(&vha->work_lock, flags);
  2297. list_add_tail(&e->list, &vha->work_list);
  2298. spin_unlock_irqrestore(&vha->work_lock, flags);
  2299. qla2xxx_wake_dpc(vha);
  2300. return QLA_SUCCESS;
  2301. }
  2302. int
  2303. qla2x00_post_aen_work(struct scsi_qla_host *vha, enum fc_host_event_code code,
  2304. u32 data)
  2305. {
  2306. struct qla_work_evt *e;
  2307. e = qla2x00_alloc_work(vha, QLA_EVT_AEN);
  2308. if (!e)
  2309. return QLA_FUNCTION_FAILED;
  2310. e->u.aen.code = code;
  2311. e->u.aen.data = data;
  2312. return qla2x00_post_work(vha, e);
  2313. }
  2314. int
  2315. qla2x00_post_idc_ack_work(struct scsi_qla_host *vha, uint16_t *mb)
  2316. {
  2317. struct qla_work_evt *e;
  2318. e = qla2x00_alloc_work(vha, QLA_EVT_IDC_ACK);
  2319. if (!e)
  2320. return QLA_FUNCTION_FAILED;
  2321. memcpy(e->u.idc_ack.mb, mb, QLA_IDC_ACK_REGS * sizeof(uint16_t));
  2322. return qla2x00_post_work(vha, e);
  2323. }
  2324. #define qla2x00_post_async_work(name, type) \
  2325. int qla2x00_post_async_##name##_work( \
  2326. struct scsi_qla_host *vha, \
  2327. fc_port_t *fcport, uint16_t *data) \
  2328. { \
  2329. struct qla_work_evt *e; \
  2330. \
  2331. e = qla2x00_alloc_work(vha, type); \
  2332. if (!e) \
  2333. return QLA_FUNCTION_FAILED; \
  2334. \
  2335. e->u.logio.fcport = fcport; \
  2336. if (data) { \
  2337. e->u.logio.data[0] = data[0]; \
  2338. e->u.logio.data[1] = data[1]; \
  2339. } \
  2340. return qla2x00_post_work(vha, e); \
  2341. }
  2342. qla2x00_post_async_work(login, QLA_EVT_ASYNC_LOGIN);
  2343. qla2x00_post_async_work(login_done, QLA_EVT_ASYNC_LOGIN_DONE);
  2344. qla2x00_post_async_work(logout, QLA_EVT_ASYNC_LOGOUT);
  2345. qla2x00_post_async_work(logout_done, QLA_EVT_ASYNC_LOGOUT_DONE);
  2346. int
  2347. qla2x00_post_uevent_work(struct scsi_qla_host *vha, u32 code)
  2348. {
  2349. struct qla_work_evt *e;
  2350. e = qla2x00_alloc_work(vha, QLA_EVT_UEVENT);
  2351. if (!e)
  2352. return QLA_FUNCTION_FAILED;
  2353. e->u.uevent.code = code;
  2354. return qla2x00_post_work(vha, e);
  2355. }
  2356. static void
  2357. qla2x00_uevent_emit(struct scsi_qla_host *vha, u32 code)
  2358. {
  2359. char event_string[40];
  2360. char *envp[] = { event_string, NULL };
  2361. switch (code) {
  2362. case QLA_UEVENT_CODE_FW_DUMP:
  2363. snprintf(event_string, sizeof(event_string), "FW_DUMP=%ld",
  2364. vha->host_no);
  2365. break;
  2366. default:
  2367. /* do nothing */
  2368. break;
  2369. }
  2370. kobject_uevent_env(&vha->hw->pdev->dev.kobj, KOBJ_CHANGE, envp);
  2371. }
  2372. void
  2373. qla2x00_do_work(struct scsi_qla_host *vha)
  2374. {
  2375. struct qla_work_evt *e, *tmp;
  2376. unsigned long flags;
  2377. LIST_HEAD(work);
  2378. spin_lock_irqsave(&vha->work_lock, flags);
  2379. list_splice_init(&vha->work_list, &work);
  2380. spin_unlock_irqrestore(&vha->work_lock, flags);
  2381. list_for_each_entry_safe(e, tmp, &work, list) {
  2382. list_del_init(&e->list);
  2383. switch (e->type) {
  2384. case QLA_EVT_AEN:
  2385. fc_host_post_event(vha->host, fc_get_event_number(),
  2386. e->u.aen.code, e->u.aen.data);
  2387. break;
  2388. case QLA_EVT_IDC_ACK:
  2389. qla81xx_idc_ack(vha, e->u.idc_ack.mb);
  2390. break;
  2391. case QLA_EVT_ASYNC_LOGIN:
  2392. qla2x00_async_login(vha, e->u.logio.fcport,
  2393. e->u.logio.data);
  2394. break;
  2395. case QLA_EVT_ASYNC_LOGIN_DONE:
  2396. qla2x00_async_login_done(vha, e->u.logio.fcport,
  2397. e->u.logio.data);
  2398. break;
  2399. case QLA_EVT_ASYNC_LOGOUT:
  2400. qla2x00_async_logout(vha, e->u.logio.fcport);
  2401. break;
  2402. case QLA_EVT_ASYNC_LOGOUT_DONE:
  2403. qla2x00_async_logout_done(vha, e->u.logio.fcport,
  2404. e->u.logio.data);
  2405. break;
  2406. case QLA_EVT_UEVENT:
  2407. qla2x00_uevent_emit(vha, e->u.uevent.code);
  2408. break;
  2409. }
  2410. if (e->flags & QLA_EVT_FLAG_FREE)
  2411. kfree(e);
  2412. }
  2413. }
  2414. /* Relogins all the fcports of a vport
  2415. * Context: dpc thread
  2416. */
  2417. void qla2x00_relogin(struct scsi_qla_host *vha)
  2418. {
  2419. fc_port_t *fcport;
  2420. int status;
  2421. uint16_t next_loopid = 0;
  2422. struct qla_hw_data *ha = vha->hw;
  2423. uint16_t data[2];
  2424. list_for_each_entry(fcport, &vha->vp_fcports, list) {
  2425. /*
  2426. * If the port is not ONLINE then try to login
  2427. * to it if we haven't run out of retries.
  2428. */
  2429. if (atomic_read(&fcport->state) !=
  2430. FCS_ONLINE && fcport->login_retry) {
  2431. fcport->login_retry--;
  2432. if (fcport->flags & FCF_FABRIC_DEVICE) {
  2433. if (fcport->flags & FCF_TAPE_PRESENT)
  2434. ha->isp_ops->fabric_logout(vha,
  2435. fcport->loop_id,
  2436. fcport->d_id.b.domain,
  2437. fcport->d_id.b.area,
  2438. fcport->d_id.b.al_pa);
  2439. if (IS_ALOGIO_CAPABLE(ha)) {
  2440. data[0] = 0;
  2441. data[1] = QLA_LOGIO_LOGIN_RETRIED;
  2442. status = qla2x00_post_async_login_work(
  2443. vha, fcport, data);
  2444. if (status == QLA_SUCCESS)
  2445. continue;
  2446. /* Attempt a retry. */
  2447. status = 1;
  2448. } else
  2449. status = qla2x00_fabric_login(vha,
  2450. fcport, &next_loopid);
  2451. } else
  2452. status = qla2x00_local_device_login(vha,
  2453. fcport);
  2454. if (status == QLA_SUCCESS) {
  2455. fcport->old_loop_id = fcport->loop_id;
  2456. DEBUG(printk("scsi(%ld): port login OK: logged "
  2457. "in ID 0x%x\n", vha->host_no, fcport->loop_id));
  2458. qla2x00_update_fcport(vha, fcport);
  2459. } else if (status == 1) {
  2460. set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
  2461. /* retry the login again */
  2462. DEBUG(printk("scsi(%ld): Retrying"
  2463. " %d login again loop_id 0x%x\n",
  2464. vha->host_no, fcport->login_retry,
  2465. fcport->loop_id));
  2466. } else {
  2467. fcport->login_retry = 0;
  2468. }
  2469. if (fcport->login_retry == 0 && status != QLA_SUCCESS)
  2470. fcport->loop_id = FC_NO_LOOP_ID;
  2471. }
  2472. if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
  2473. break;
  2474. }
  2475. }
  2476. /**************************************************************************
  2477. * qla2x00_do_dpc
  2478. * This kernel thread is a task that is schedule by the interrupt handler
  2479. * to perform the background processing for interrupts.
  2480. *
  2481. * Notes:
  2482. * This task always run in the context of a kernel thread. It
  2483. * is kick-off by the driver's detect code and starts up
  2484. * up one per adapter. It immediately goes to sleep and waits for
  2485. * some fibre event. When either the interrupt handler or
  2486. * the timer routine detects a event it will one of the task
  2487. * bits then wake us up.
  2488. **************************************************************************/
  2489. static int
  2490. qla2x00_do_dpc(void *data)
  2491. {
  2492. int rval;
  2493. scsi_qla_host_t *base_vha;
  2494. struct qla_hw_data *ha;
  2495. ha = (struct qla_hw_data *)data;
  2496. base_vha = pci_get_drvdata(ha->pdev);
  2497. set_user_nice(current, -20);
  2498. while (!kthread_should_stop()) {
  2499. DEBUG3(printk("qla2x00: DPC handler sleeping\n"));
  2500. set_current_state(TASK_INTERRUPTIBLE);
  2501. schedule();
  2502. __set_current_state(TASK_RUNNING);
  2503. DEBUG3(printk("qla2x00: DPC handler waking up\n"));
  2504. /* Initialization not yet finished. Don't do anything yet. */
  2505. if (!base_vha->flags.init_done)
  2506. continue;
  2507. if (ha->flags.eeh_busy) {
  2508. DEBUG17(qla_printk(KERN_WARNING, ha,
  2509. "qla2x00_do_dpc: dpc_flags: %lx\n",
  2510. base_vha->dpc_flags));
  2511. continue;
  2512. }
  2513. DEBUG3(printk("scsi(%ld): DPC handler\n", base_vha->host_no));
  2514. ha->dpc_active = 1;
  2515. if (ha->flags.mbox_busy) {
  2516. ha->dpc_active = 0;
  2517. continue;
  2518. }
  2519. qla2x00_do_work(base_vha);
  2520. if (test_and_clear_bit(ISP_ABORT_NEEDED,
  2521. &base_vha->dpc_flags)) {
  2522. DEBUG(printk("scsi(%ld): dpc: sched "
  2523. "qla2x00_abort_isp ha = %p\n",
  2524. base_vha->host_no, ha));
  2525. if (!(test_and_set_bit(ABORT_ISP_ACTIVE,
  2526. &base_vha->dpc_flags))) {
  2527. if (qla2x00_abort_isp(base_vha)) {
  2528. /* failed. retry later */
  2529. set_bit(ISP_ABORT_NEEDED,
  2530. &base_vha->dpc_flags);
  2531. }
  2532. clear_bit(ABORT_ISP_ACTIVE,
  2533. &base_vha->dpc_flags);
  2534. }
  2535. DEBUG(printk("scsi(%ld): dpc: qla2x00_abort_isp end\n",
  2536. base_vha->host_no));
  2537. }
  2538. if (test_bit(FCPORT_UPDATE_NEEDED, &base_vha->dpc_flags)) {
  2539. qla2x00_update_fcports(base_vha);
  2540. clear_bit(FCPORT_UPDATE_NEEDED, &base_vha->dpc_flags);
  2541. }
  2542. if (test_and_clear_bit(RESET_MARKER_NEEDED,
  2543. &base_vha->dpc_flags) &&
  2544. (!(test_and_set_bit(RESET_ACTIVE, &base_vha->dpc_flags)))) {
  2545. DEBUG(printk("scsi(%ld): qla2x00_reset_marker()\n",
  2546. base_vha->host_no));
  2547. qla2x00_rst_aen(base_vha);
  2548. clear_bit(RESET_ACTIVE, &base_vha->dpc_flags);
  2549. }
  2550. /* Retry each device up to login retry count */
  2551. if ((test_and_clear_bit(RELOGIN_NEEDED,
  2552. &base_vha->dpc_flags)) &&
  2553. !test_bit(LOOP_RESYNC_NEEDED, &base_vha->dpc_flags) &&
  2554. atomic_read(&base_vha->loop_state) != LOOP_DOWN) {
  2555. DEBUG(printk("scsi(%ld): qla2x00_port_login()\n",
  2556. base_vha->host_no));
  2557. qla2x00_relogin(base_vha);
  2558. DEBUG(printk("scsi(%ld): qla2x00_port_login - end\n",
  2559. base_vha->host_no));
  2560. }
  2561. if (test_and_clear_bit(LOOP_RESYNC_NEEDED,
  2562. &base_vha->dpc_flags)) {
  2563. DEBUG(printk("scsi(%ld): qla2x00_loop_resync()\n",
  2564. base_vha->host_no));
  2565. if (!(test_and_set_bit(LOOP_RESYNC_ACTIVE,
  2566. &base_vha->dpc_flags))) {
  2567. rval = qla2x00_loop_resync(base_vha);
  2568. clear_bit(LOOP_RESYNC_ACTIVE,
  2569. &base_vha->dpc_flags);
  2570. }
  2571. DEBUG(printk("scsi(%ld): qla2x00_loop_resync - end\n",
  2572. base_vha->host_no));
  2573. }
  2574. if (test_bit(NPIV_CONFIG_NEEDED, &base_vha->dpc_flags) &&
  2575. atomic_read(&base_vha->loop_state) == LOOP_READY) {
  2576. clear_bit(NPIV_CONFIG_NEEDED, &base_vha->dpc_flags);
  2577. qla2xxx_flash_npiv_conf(base_vha);
  2578. }
  2579. if (!ha->interrupts_on)
  2580. ha->isp_ops->enable_intrs(ha);
  2581. if (test_and_clear_bit(BEACON_BLINK_NEEDED,
  2582. &base_vha->dpc_flags))
  2583. ha->isp_ops->beacon_blink(base_vha);
  2584. qla2x00_do_dpc_all_vps(base_vha);
  2585. ha->dpc_active = 0;
  2586. } /* End of while(1) */
  2587. DEBUG(printk("scsi(%ld): DPC handler exiting\n", base_vha->host_no));
  2588. /*
  2589. * Make sure that nobody tries to wake us up again.
  2590. */
  2591. ha->dpc_active = 0;
  2592. /* Cleanup any residual CTX SRBs. */
  2593. qla2x00_abort_all_cmds(base_vha, DID_NO_CONNECT << 16);
  2594. return 0;
  2595. }
  2596. void
  2597. qla2xxx_wake_dpc(struct scsi_qla_host *vha)
  2598. {
  2599. struct qla_hw_data *ha = vha->hw;
  2600. struct task_struct *t = ha->dpc_thread;
  2601. if (!test_bit(UNLOADING, &vha->dpc_flags) && t)
  2602. wake_up_process(t);
  2603. }
  2604. /*
  2605. * qla2x00_rst_aen
  2606. * Processes asynchronous reset.
  2607. *
  2608. * Input:
  2609. * ha = adapter block pointer.
  2610. */
  2611. static void
  2612. qla2x00_rst_aen(scsi_qla_host_t *vha)
  2613. {
  2614. if (vha->flags.online && !vha->flags.reset_active &&
  2615. !atomic_read(&vha->loop_down_timer) &&
  2616. !(test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags))) {
  2617. do {
  2618. clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
  2619. /*
  2620. * Issue marker command only when we are going to start
  2621. * the I/O.
  2622. */
  2623. vha->marker_needed = 1;
  2624. } while (!atomic_read(&vha->loop_down_timer) &&
  2625. (test_bit(RESET_MARKER_NEEDED, &vha->dpc_flags)));
  2626. }
  2627. }
  2628. static void
  2629. qla2x00_sp_free_dma(srb_t *sp)
  2630. {
  2631. struct scsi_cmnd *cmd = sp->cmd;
  2632. if (sp->flags & SRB_DMA_VALID) {
  2633. scsi_dma_unmap(cmd);
  2634. sp->flags &= ~SRB_DMA_VALID;
  2635. }
  2636. CMD_SP(cmd) = NULL;
  2637. }
  2638. void
  2639. qla2x00_sp_compl(struct qla_hw_data *ha, srb_t *sp)
  2640. {
  2641. struct scsi_cmnd *cmd = sp->cmd;
  2642. qla2x00_sp_free_dma(sp);
  2643. mempool_free(sp, ha->srb_mempool);
  2644. cmd->scsi_done(cmd);
  2645. }
  2646. /**************************************************************************
  2647. * qla2x00_timer
  2648. *
  2649. * Description:
  2650. * One second timer
  2651. *
  2652. * Context: Interrupt
  2653. ***************************************************************************/
  2654. void
  2655. qla2x00_timer(scsi_qla_host_t *vha)
  2656. {
  2657. unsigned long cpu_flags = 0;
  2658. fc_port_t *fcport;
  2659. int start_dpc = 0;
  2660. int index;
  2661. srb_t *sp;
  2662. int t;
  2663. uint16_t w;
  2664. struct qla_hw_data *ha = vha->hw;
  2665. struct req_que *req;
  2666. /* Hardware read to raise pending EEH errors during mailbox waits. */
  2667. if (!pci_channel_offline(ha->pdev))
  2668. pci_read_config_word(ha->pdev, PCI_VENDOR_ID, &w);
  2669. /*
  2670. * Ports - Port down timer.
  2671. *
  2672. * Whenever, a port is in the LOST state we start decrementing its port
  2673. * down timer every second until it reaches zero. Once it reaches zero
  2674. * the port it marked DEAD.
  2675. */
  2676. t = 0;
  2677. list_for_each_entry(fcport, &vha->vp_fcports, list) {
  2678. if (fcport->port_type != FCT_TARGET)
  2679. continue;
  2680. if (atomic_read(&fcport->state) == FCS_DEVICE_LOST) {
  2681. if (atomic_read(&fcport->port_down_timer) == 0)
  2682. continue;
  2683. if (atomic_dec_and_test(&fcport->port_down_timer) != 0)
  2684. atomic_set(&fcport->state, FCS_DEVICE_DEAD);
  2685. DEBUG(printk("scsi(%ld): fcport-%d - port retry count: "
  2686. "%d remaining\n",
  2687. vha->host_no,
  2688. t, atomic_read(&fcport->port_down_timer)));
  2689. }
  2690. t++;
  2691. } /* End of for fcport */
  2692. /* Loop down handler. */
  2693. if (atomic_read(&vha->loop_down_timer) > 0 &&
  2694. !(test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags))
  2695. && vha->flags.online) {
  2696. if (atomic_read(&vha->loop_down_timer) ==
  2697. vha->loop_down_abort_time) {
  2698. DEBUG(printk("scsi(%ld): Loop Down - aborting the "
  2699. "queues before time expire\n",
  2700. vha->host_no));
  2701. if (!IS_QLA2100(ha) && vha->link_down_timeout)
  2702. atomic_set(&vha->loop_state, LOOP_DEAD);
  2703. /* Schedule an ISP abort to return any tape commands. */
  2704. /* NPIV - scan physical port only */
  2705. if (!vha->vp_idx) {
  2706. spin_lock_irqsave(&ha->hardware_lock,
  2707. cpu_flags);
  2708. req = ha->req_q_map[0];
  2709. for (index = 1;
  2710. index < MAX_OUTSTANDING_COMMANDS;
  2711. index++) {
  2712. fc_port_t *sfcp;
  2713. sp = req->outstanding_cmds[index];
  2714. if (!sp)
  2715. continue;
  2716. if (sp->ctx)
  2717. continue;
  2718. sfcp = sp->fcport;
  2719. if (!(sfcp->flags & FCF_TAPE_PRESENT))
  2720. continue;
  2721. set_bit(ISP_ABORT_NEEDED,
  2722. &vha->dpc_flags);
  2723. break;
  2724. }
  2725. spin_unlock_irqrestore(&ha->hardware_lock,
  2726. cpu_flags);
  2727. }
  2728. start_dpc++;
  2729. }
  2730. /* if the loop has been down for 4 minutes, reinit adapter */
  2731. if (atomic_dec_and_test(&vha->loop_down_timer) != 0) {
  2732. if (!(vha->device_flags & DFLG_NO_CABLE)) {
  2733. DEBUG(printk("scsi(%ld): Loop down - "
  2734. "aborting ISP.\n",
  2735. vha->host_no));
  2736. qla_printk(KERN_WARNING, ha,
  2737. "Loop down - aborting ISP.\n");
  2738. set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
  2739. }
  2740. }
  2741. DEBUG3(printk("scsi(%ld): Loop Down - seconds remaining %d\n",
  2742. vha->host_no,
  2743. atomic_read(&vha->loop_down_timer)));
  2744. }
  2745. /* Check if beacon LED needs to be blinked */
  2746. if (ha->beacon_blink_led == 1) {
  2747. set_bit(BEACON_BLINK_NEEDED, &vha->dpc_flags);
  2748. start_dpc++;
  2749. }
  2750. /* Process any deferred work. */
  2751. if (!list_empty(&vha->work_list))
  2752. start_dpc++;
  2753. /* Schedule the DPC routine if needed */
  2754. if ((test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags) ||
  2755. test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags) ||
  2756. test_bit(FCPORT_UPDATE_NEEDED, &vha->dpc_flags) ||
  2757. start_dpc ||
  2758. test_bit(RESET_MARKER_NEEDED, &vha->dpc_flags) ||
  2759. test_bit(BEACON_BLINK_NEEDED, &vha->dpc_flags) ||
  2760. test_bit(VP_DPC_NEEDED, &vha->dpc_flags) ||
  2761. test_bit(RELOGIN_NEEDED, &vha->dpc_flags)))
  2762. qla2xxx_wake_dpc(vha);
  2763. qla2x00_restart_timer(vha, WATCH_INTERVAL);
  2764. }
  2765. /* Firmware interface routines. */
  2766. #define FW_BLOBS 7
  2767. #define FW_ISP21XX 0
  2768. #define FW_ISP22XX 1
  2769. #define FW_ISP2300 2
  2770. #define FW_ISP2322 3
  2771. #define FW_ISP24XX 4
  2772. #define FW_ISP25XX 5
  2773. #define FW_ISP81XX 6
  2774. #define FW_FILE_ISP21XX "ql2100_fw.bin"
  2775. #define FW_FILE_ISP22XX "ql2200_fw.bin"
  2776. #define FW_FILE_ISP2300 "ql2300_fw.bin"
  2777. #define FW_FILE_ISP2322 "ql2322_fw.bin"
  2778. #define FW_FILE_ISP24XX "ql2400_fw.bin"
  2779. #define FW_FILE_ISP25XX "ql2500_fw.bin"
  2780. #define FW_FILE_ISP81XX "ql8100_fw.bin"
  2781. static DEFINE_MUTEX(qla_fw_lock);
  2782. static struct fw_blob qla_fw_blobs[FW_BLOBS] = {
  2783. { .name = FW_FILE_ISP21XX, .segs = { 0x1000, 0 }, },
  2784. { .name = FW_FILE_ISP22XX, .segs = { 0x1000, 0 }, },
  2785. { .name = FW_FILE_ISP2300, .segs = { 0x800, 0 }, },
  2786. { .name = FW_FILE_ISP2322, .segs = { 0x800, 0x1c000, 0x1e000, 0 }, },
  2787. { .name = FW_FILE_ISP24XX, },
  2788. { .name = FW_FILE_ISP25XX, },
  2789. { .name = FW_FILE_ISP81XX, },
  2790. };
  2791. struct fw_blob *
  2792. qla2x00_request_firmware(scsi_qla_host_t *vha)
  2793. {
  2794. struct qla_hw_data *ha = vha->hw;
  2795. struct fw_blob *blob;
  2796. blob = NULL;
  2797. if (IS_QLA2100(ha)) {
  2798. blob = &qla_fw_blobs[FW_ISP21XX];
  2799. } else if (IS_QLA2200(ha)) {
  2800. blob = &qla_fw_blobs[FW_ISP22XX];
  2801. } else if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
  2802. blob = &qla_fw_blobs[FW_ISP2300];
  2803. } else if (IS_QLA2322(ha) || IS_QLA6322(ha)) {
  2804. blob = &qla_fw_blobs[FW_ISP2322];
  2805. } else if (IS_QLA24XX_TYPE(ha)) {
  2806. blob = &qla_fw_blobs[FW_ISP24XX];
  2807. } else if (IS_QLA25XX(ha)) {
  2808. blob = &qla_fw_blobs[FW_ISP25XX];
  2809. } else if (IS_QLA81XX(ha)) {
  2810. blob = &qla_fw_blobs[FW_ISP81XX];
  2811. }
  2812. mutex_lock(&qla_fw_lock);
  2813. if (blob->fw)
  2814. goto out;
  2815. if (request_firmware(&blob->fw, blob->name, &ha->pdev->dev)) {
  2816. DEBUG2(printk("scsi(%ld): Failed to load firmware image "
  2817. "(%s).\n", vha->host_no, blob->name));
  2818. blob->fw = NULL;
  2819. blob = NULL;
  2820. goto out;
  2821. }
  2822. out:
  2823. mutex_unlock(&qla_fw_lock);
  2824. return blob;
  2825. }
  2826. static void
  2827. qla2x00_release_firmware(void)
  2828. {
  2829. int idx;
  2830. mutex_lock(&qla_fw_lock);
  2831. for (idx = 0; idx < FW_BLOBS; idx++)
  2832. if (qla_fw_blobs[idx].fw)
  2833. release_firmware(qla_fw_blobs[idx].fw);
  2834. mutex_unlock(&qla_fw_lock);
  2835. }
  2836. static pci_ers_result_t
  2837. qla2xxx_pci_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
  2838. {
  2839. scsi_qla_host_t *vha = pci_get_drvdata(pdev);
  2840. struct qla_hw_data *ha = vha->hw;
  2841. DEBUG2(qla_printk(KERN_WARNING, ha, "error_detected:state %x\n",
  2842. state));
  2843. switch (state) {
  2844. case pci_channel_io_normal:
  2845. ha->flags.eeh_busy = 0;
  2846. return PCI_ERS_RESULT_CAN_RECOVER;
  2847. case pci_channel_io_frozen:
  2848. ha->flags.eeh_busy = 1;
  2849. pci_disable_device(pdev);
  2850. return PCI_ERS_RESULT_NEED_RESET;
  2851. case pci_channel_io_perm_failure:
  2852. ha->flags.pci_channel_io_perm_failure = 1;
  2853. qla2x00_abort_all_cmds(vha, DID_NO_CONNECT << 16);
  2854. return PCI_ERS_RESULT_DISCONNECT;
  2855. }
  2856. return PCI_ERS_RESULT_NEED_RESET;
  2857. }
  2858. static pci_ers_result_t
  2859. qla2xxx_pci_mmio_enabled(struct pci_dev *pdev)
  2860. {
  2861. int risc_paused = 0;
  2862. uint32_t stat;
  2863. unsigned long flags;
  2864. scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
  2865. struct qla_hw_data *ha = base_vha->hw;
  2866. struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
  2867. struct device_reg_24xx __iomem *reg24 = &ha->iobase->isp24;
  2868. spin_lock_irqsave(&ha->hardware_lock, flags);
  2869. if (IS_QLA2100(ha) || IS_QLA2200(ha)){
  2870. stat = RD_REG_DWORD(&reg->hccr);
  2871. if (stat & HCCR_RISC_PAUSE)
  2872. risc_paused = 1;
  2873. } else if (IS_QLA23XX(ha)) {
  2874. stat = RD_REG_DWORD(&reg->u.isp2300.host_status);
  2875. if (stat & HSR_RISC_PAUSED)
  2876. risc_paused = 1;
  2877. } else if (IS_FWI2_CAPABLE(ha)) {
  2878. stat = RD_REG_DWORD(&reg24->host_status);
  2879. if (stat & HSRX_RISC_PAUSED)
  2880. risc_paused = 1;
  2881. }
  2882. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  2883. if (risc_paused) {
  2884. qla_printk(KERN_INFO, ha, "RISC paused -- mmio_enabled, "
  2885. "Dumping firmware!\n");
  2886. ha->isp_ops->fw_dump(base_vha, 0);
  2887. return PCI_ERS_RESULT_NEED_RESET;
  2888. } else
  2889. return PCI_ERS_RESULT_RECOVERED;
  2890. }
  2891. static pci_ers_result_t
  2892. qla2xxx_pci_slot_reset(struct pci_dev *pdev)
  2893. {
  2894. pci_ers_result_t ret = PCI_ERS_RESULT_DISCONNECT;
  2895. scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
  2896. struct qla_hw_data *ha = base_vha->hw;
  2897. int rc;
  2898. DEBUG17(qla_printk(KERN_WARNING, ha, "slot_reset\n"));
  2899. if (ha->mem_only)
  2900. rc = pci_enable_device_mem(pdev);
  2901. else
  2902. rc = pci_enable_device(pdev);
  2903. if (rc) {
  2904. qla_printk(KERN_WARNING, ha,
  2905. "Can't re-enable PCI device after reset.\n");
  2906. return ret;
  2907. }
  2908. if (ha->isp_ops->pci_config(base_vha))
  2909. return ret;
  2910. #ifdef QL_DEBUG_LEVEL_17
  2911. {
  2912. uint8_t b;
  2913. uint32_t i;
  2914. printk("slot_reset_1: ");
  2915. for (i = 0; i < 256; i++) {
  2916. pci_read_config_byte(ha->pdev, i, &b);
  2917. printk("%s%02x", (i%16) ? " " : "\n", b);
  2918. }
  2919. printk("\n");
  2920. }
  2921. #endif
  2922. set_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
  2923. if (qla2x00_abort_isp(base_vha) == QLA_SUCCESS)
  2924. ret = PCI_ERS_RESULT_RECOVERED;
  2925. clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
  2926. DEBUG17(qla_printk(KERN_WARNING, ha,
  2927. "slot_reset-return:ret=%x\n", ret));
  2928. return ret;
  2929. }
  2930. static void
  2931. qla2xxx_pci_resume(struct pci_dev *pdev)
  2932. {
  2933. scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
  2934. struct qla_hw_data *ha = base_vha->hw;
  2935. int ret;
  2936. DEBUG17(qla_printk(KERN_WARNING, ha, "pci_resume\n"));
  2937. ret = qla2x00_wait_for_hba_online(base_vha);
  2938. if (ret != QLA_SUCCESS) {
  2939. qla_printk(KERN_ERR, ha,
  2940. "the device failed to resume I/O "
  2941. "from slot/link_reset");
  2942. }
  2943. ha->flags.eeh_busy = 0;
  2944. pci_cleanup_aer_uncorrect_error_status(pdev);
  2945. }
  2946. static struct pci_error_handlers qla2xxx_err_handler = {
  2947. .error_detected = qla2xxx_pci_error_detected,
  2948. .mmio_enabled = qla2xxx_pci_mmio_enabled,
  2949. .slot_reset = qla2xxx_pci_slot_reset,
  2950. .resume = qla2xxx_pci_resume,
  2951. };
  2952. static struct pci_device_id qla2xxx_pci_tbl[] = {
  2953. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2100) },
  2954. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2200) },
  2955. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2300) },
  2956. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2312) },
  2957. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2322) },
  2958. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP6312) },
  2959. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP6322) },
  2960. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2422) },
  2961. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2432) },
  2962. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8432) },
  2963. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP5422) },
  2964. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP5432) },
  2965. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2532) },
  2966. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8001) },
  2967. { 0 },
  2968. };
  2969. MODULE_DEVICE_TABLE(pci, qla2xxx_pci_tbl);
  2970. static struct pci_driver qla2xxx_pci_driver = {
  2971. .name = QLA2XXX_DRIVER_NAME,
  2972. .driver = {
  2973. .owner = THIS_MODULE,
  2974. },
  2975. .id_table = qla2xxx_pci_tbl,
  2976. .probe = qla2x00_probe_one,
  2977. .remove = qla2x00_remove_one,
  2978. .err_handler = &qla2xxx_err_handler,
  2979. };
  2980. /**
  2981. * qla2x00_module_init - Module initialization.
  2982. **/
  2983. static int __init
  2984. qla2x00_module_init(void)
  2985. {
  2986. int ret = 0;
  2987. /* Allocate cache for SRBs. */
  2988. srb_cachep = kmem_cache_create("qla2xxx_srbs", sizeof(srb_t), 0,
  2989. SLAB_HWCACHE_ALIGN, NULL);
  2990. if (srb_cachep == NULL) {
  2991. printk(KERN_ERR
  2992. "qla2xxx: Unable to allocate SRB cache...Failing load!\n");
  2993. return -ENOMEM;
  2994. }
  2995. /* Derive version string. */
  2996. strcpy(qla2x00_version_str, QLA2XXX_VERSION);
  2997. if (ql2xextended_error_logging)
  2998. strcat(qla2x00_version_str, "-debug");
  2999. qla2xxx_transport_template =
  3000. fc_attach_transport(&qla2xxx_transport_functions);
  3001. if (!qla2xxx_transport_template) {
  3002. kmem_cache_destroy(srb_cachep);
  3003. return -ENODEV;
  3004. }
  3005. qla2xxx_transport_vport_template =
  3006. fc_attach_transport(&qla2xxx_transport_vport_functions);
  3007. if (!qla2xxx_transport_vport_template) {
  3008. kmem_cache_destroy(srb_cachep);
  3009. fc_release_transport(qla2xxx_transport_template);
  3010. return -ENODEV;
  3011. }
  3012. printk(KERN_INFO "QLogic Fibre Channel HBA Driver: %s\n",
  3013. qla2x00_version_str);
  3014. ret = pci_register_driver(&qla2xxx_pci_driver);
  3015. if (ret) {
  3016. kmem_cache_destroy(srb_cachep);
  3017. fc_release_transport(qla2xxx_transport_template);
  3018. fc_release_transport(qla2xxx_transport_vport_template);
  3019. }
  3020. return ret;
  3021. }
  3022. /**
  3023. * qla2x00_module_exit - Module cleanup.
  3024. **/
  3025. static void __exit
  3026. qla2x00_module_exit(void)
  3027. {
  3028. pci_unregister_driver(&qla2xxx_pci_driver);
  3029. qla2x00_release_firmware();
  3030. kmem_cache_destroy(srb_cachep);
  3031. fc_release_transport(qla2xxx_transport_template);
  3032. fc_release_transport(qla2xxx_transport_vport_template);
  3033. }
  3034. module_init(qla2x00_module_init);
  3035. module_exit(qla2x00_module_exit);
  3036. MODULE_AUTHOR("QLogic Corporation");
  3037. MODULE_DESCRIPTION("QLogic Fibre Channel HBA Driver");
  3038. MODULE_LICENSE("GPL");
  3039. MODULE_VERSION(QLA2XXX_VERSION);
  3040. MODULE_FIRMWARE(FW_FILE_ISP21XX);
  3041. MODULE_FIRMWARE(FW_FILE_ISP22XX);
  3042. MODULE_FIRMWARE(FW_FILE_ISP2300);
  3043. MODULE_FIRMWARE(FW_FILE_ISP2322);
  3044. MODULE_FIRMWARE(FW_FILE_ISP24XX);
  3045. MODULE_FIRMWARE(FW_FILE_ISP25XX);
  3046. MODULE_FIRMWARE(FW_FILE_ISP81XX);