qla_os.c 83 KB

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