qla_os.c 87 KB

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