qla_os.c 77 KB

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