qla_os.c 75 KB

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