qla_os.c 86 KB

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