qla_os.c 82 KB

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