qla_os.c 78 KB

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