qla_os.c 74 KB

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