qla_os.c 74 KB

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