qla_os.c 82 KB

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