qla_os.c 63 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581
  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/smp_lock.h>
  11. #include <linux/delay.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 kmem_cache_t *srb_cachep;
  24. /*
  25. * Ioctl related information.
  26. */
  27. static 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 = 30;
  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 ql2xfwloadbin=1;
  48. module_param(ql2xfwloadbin, int, S_IRUGO|S_IRUSR);
  49. MODULE_PARM_DESC(ql2xfwloadbin,
  50. "Load ISP2xxx firmware image via hotplug.");
  51. static void qla2x00_free_device(scsi_qla_host_t *);
  52. static void qla2x00_config_dma_addressing(scsi_qla_host_t *ha);
  53. int ql2xfdmienable;
  54. module_param(ql2xfdmienable, int, S_IRUGO|S_IRUSR);
  55. MODULE_PARM_DESC(ql2xfdmienable,
  56. "Enables FDMI registratons "
  57. "Default is 0 - no FDMI. 1 - perfom FDMI.");
  58. /*
  59. * SCSI host template entry points
  60. */
  61. static int qla2xxx_slave_configure(struct scsi_device * device);
  62. static int qla2xxx_slave_alloc(struct scsi_device *);
  63. static void qla2xxx_slave_destroy(struct scsi_device *);
  64. static int qla2x00_queuecommand(struct scsi_cmnd *cmd,
  65. void (*fn)(struct scsi_cmnd *));
  66. static int qla24xx_queuecommand(struct scsi_cmnd *cmd,
  67. void (*fn)(struct scsi_cmnd *));
  68. static int qla2xxx_eh_abort(struct scsi_cmnd *);
  69. static int qla2xxx_eh_device_reset(struct scsi_cmnd *);
  70. static int qla2xxx_eh_bus_reset(struct scsi_cmnd *);
  71. static int qla2xxx_eh_host_reset(struct scsi_cmnd *);
  72. static int qla2x00_loop_reset(scsi_qla_host_t *ha);
  73. static int qla2x00_device_reset(scsi_qla_host_t *, fc_port_t *);
  74. static int qla2x00_change_queue_depth(struct scsi_device *, int);
  75. static int qla2x00_change_queue_type(struct scsi_device *, int);
  76. static struct scsi_host_template qla2x00_driver_template = {
  77. .module = THIS_MODULE,
  78. .name = "qla2xxx",
  79. .queuecommand = qla2x00_queuecommand,
  80. .eh_abort_handler = qla2xxx_eh_abort,
  81. .eh_device_reset_handler = qla2xxx_eh_device_reset,
  82. .eh_bus_reset_handler = qla2xxx_eh_bus_reset,
  83. .eh_host_reset_handler = qla2xxx_eh_host_reset,
  84. .slave_configure = qla2xxx_slave_configure,
  85. .slave_alloc = qla2xxx_slave_alloc,
  86. .slave_destroy = qla2xxx_slave_destroy,
  87. .change_queue_depth = qla2x00_change_queue_depth,
  88. .change_queue_type = qla2x00_change_queue_type,
  89. .this_id = -1,
  90. .cmd_per_lun = 3,
  91. .use_clustering = ENABLE_CLUSTERING,
  92. .sg_tablesize = SG_ALL,
  93. /*
  94. * The RISC allows for each command to transfer (2^32-1) bytes of data,
  95. * which equates to 0x800000 sectors.
  96. */
  97. .max_sectors = 0xFFFF,
  98. .shost_attrs = qla2x00_host_attrs,
  99. };
  100. static struct scsi_host_template qla24xx_driver_template = {
  101. .module = THIS_MODULE,
  102. .name = "qla2xxx",
  103. .queuecommand = qla24xx_queuecommand,
  104. .eh_abort_handler = qla2xxx_eh_abort,
  105. .eh_device_reset_handler = qla2xxx_eh_device_reset,
  106. .eh_bus_reset_handler = qla2xxx_eh_bus_reset,
  107. .eh_host_reset_handler = qla2xxx_eh_host_reset,
  108. .slave_configure = qla2xxx_slave_configure,
  109. .slave_alloc = qla2xxx_slave_alloc,
  110. .slave_destroy = qla2xxx_slave_destroy,
  111. .change_queue_depth = qla2x00_change_queue_depth,
  112. .change_queue_type = qla2x00_change_queue_type,
  113. .this_id = -1,
  114. .cmd_per_lun = 3,
  115. .use_clustering = ENABLE_CLUSTERING,
  116. .sg_tablesize = SG_ALL,
  117. .max_sectors = 0xFFFF,
  118. .shost_attrs = qla2x00_host_attrs,
  119. };
  120. static struct scsi_transport_template *qla2xxx_transport_template = NULL;
  121. /* TODO Convert to inlines
  122. *
  123. * Timer routines
  124. */
  125. #define WATCH_INTERVAL 1 /* number of seconds */
  126. static void qla2x00_timer(scsi_qla_host_t *);
  127. static __inline__ void qla2x00_start_timer(scsi_qla_host_t *,
  128. void *, unsigned long);
  129. static __inline__ void qla2x00_restart_timer(scsi_qla_host_t *, unsigned long);
  130. static __inline__ void qla2x00_stop_timer(scsi_qla_host_t *);
  131. static inline void
  132. qla2x00_start_timer(scsi_qla_host_t *ha, void *func, unsigned long interval)
  133. {
  134. init_timer(&ha->timer);
  135. ha->timer.expires = jiffies + interval * HZ;
  136. ha->timer.data = (unsigned long)ha;
  137. ha->timer.function = (void (*)(unsigned long))func;
  138. add_timer(&ha->timer);
  139. ha->timer_active = 1;
  140. }
  141. static inline void
  142. qla2x00_restart_timer(scsi_qla_host_t *ha, unsigned long interval)
  143. {
  144. mod_timer(&ha->timer, jiffies + interval * HZ);
  145. }
  146. static __inline__ void
  147. qla2x00_stop_timer(scsi_qla_host_t *ha)
  148. {
  149. del_timer_sync(&ha->timer);
  150. ha->timer_active = 0;
  151. }
  152. static int qla2x00_do_dpc(void *data);
  153. static void qla2x00_rst_aen(scsi_qla_host_t *);
  154. static uint8_t qla2x00_mem_alloc(scsi_qla_host_t *);
  155. static void qla2x00_mem_free(scsi_qla_host_t *ha);
  156. static int qla2x00_allocate_sp_pool( scsi_qla_host_t *ha);
  157. static void qla2x00_free_sp_pool(scsi_qla_host_t *ha);
  158. static void qla2x00_sp_free_dma(scsi_qla_host_t *, srb_t *);
  159. void qla2x00_sp_compl(scsi_qla_host_t *ha, srb_t *);
  160. /* -------------------------------------------------------------------------- */
  161. static char *
  162. qla2x00_pci_info_str(struct scsi_qla_host *ha, char *str)
  163. {
  164. static char *pci_bus_modes[] = {
  165. "33", "66", "100", "133",
  166. };
  167. uint16_t pci_bus;
  168. strcpy(str, "PCI");
  169. pci_bus = (ha->pci_attr & (BIT_9 | BIT_10)) >> 9;
  170. if (pci_bus) {
  171. strcat(str, "-X (");
  172. strcat(str, pci_bus_modes[pci_bus]);
  173. } else {
  174. pci_bus = (ha->pci_attr & BIT_8) >> 8;
  175. strcat(str, " (");
  176. strcat(str, pci_bus_modes[pci_bus]);
  177. }
  178. strcat(str, " MHz)");
  179. return (str);
  180. }
  181. static char *
  182. qla24xx_pci_info_str(struct scsi_qla_host *ha, char *str)
  183. {
  184. static char *pci_bus_modes[] = { "33", "66", "100", "133", };
  185. uint32_t pci_bus;
  186. int pcie_reg;
  187. pcie_reg = pci_find_capability(ha->pdev, PCI_CAP_ID_EXP);
  188. if (pcie_reg) {
  189. char lwstr[6];
  190. uint16_t pcie_lstat, lspeed, lwidth;
  191. pcie_reg += 0x12;
  192. pci_read_config_word(ha->pdev, pcie_reg, &pcie_lstat);
  193. lspeed = pcie_lstat & (BIT_0 | BIT_1 | BIT_2 | BIT_3);
  194. lwidth = (pcie_lstat &
  195. (BIT_4 | BIT_5 | BIT_6 | BIT_7 | BIT_8 | BIT_9)) >> 4;
  196. strcpy(str, "PCIe (");
  197. if (lspeed == 1)
  198. strcat(str, "2.5Gb/s ");
  199. else
  200. strcat(str, "<unknown> ");
  201. snprintf(lwstr, sizeof(lwstr), "x%d)", lwidth);
  202. strcat(str, lwstr);
  203. return str;
  204. }
  205. strcpy(str, "PCI");
  206. pci_bus = (ha->pci_attr & CSRX_PCIX_BUS_MODE_MASK) >> 8;
  207. if (pci_bus == 0 || pci_bus == 8) {
  208. strcat(str, " (");
  209. strcat(str, pci_bus_modes[pci_bus >> 3]);
  210. } else {
  211. strcat(str, "-X ");
  212. if (pci_bus & BIT_2)
  213. strcat(str, "Mode 2");
  214. else
  215. strcat(str, "Mode 1");
  216. strcat(str, " (");
  217. strcat(str, pci_bus_modes[pci_bus & ~BIT_2]);
  218. }
  219. strcat(str, " MHz)");
  220. return str;
  221. }
  222. char *
  223. qla2x00_fw_version_str(struct scsi_qla_host *ha, char *str)
  224. {
  225. char un_str[10];
  226. sprintf(str, "%d.%02d.%02d ", ha->fw_major_version,
  227. ha->fw_minor_version,
  228. ha->fw_subminor_version);
  229. if (ha->fw_attributes & BIT_9) {
  230. strcat(str, "FLX");
  231. return (str);
  232. }
  233. switch (ha->fw_attributes & 0xFF) {
  234. case 0x7:
  235. strcat(str, "EF");
  236. break;
  237. case 0x17:
  238. strcat(str, "TP");
  239. break;
  240. case 0x37:
  241. strcat(str, "IP");
  242. break;
  243. case 0x77:
  244. strcat(str, "VI");
  245. break;
  246. default:
  247. sprintf(un_str, "(%x)", ha->fw_attributes);
  248. strcat(str, un_str);
  249. break;
  250. }
  251. if (ha->fw_attributes & 0x100)
  252. strcat(str, "X");
  253. return (str);
  254. }
  255. char *
  256. qla24xx_fw_version_str(struct scsi_qla_host *ha, char *str)
  257. {
  258. sprintf(str, "%d.%02d.%02d ", ha->fw_major_version,
  259. ha->fw_minor_version,
  260. ha->fw_subminor_version);
  261. if (ha->fw_attributes & BIT_0)
  262. strcat(str, "[Class 2] ");
  263. if (ha->fw_attributes & BIT_1)
  264. strcat(str, "[IP] ");
  265. if (ha->fw_attributes & BIT_2)
  266. strcat(str, "[Multi-ID] ");
  267. if (ha->fw_attributes & BIT_13)
  268. strcat(str, "[Experimental]");
  269. return str;
  270. }
  271. static inline srb_t *
  272. qla2x00_get_new_sp(scsi_qla_host_t *ha, fc_port_t *fcport,
  273. struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *))
  274. {
  275. srb_t *sp;
  276. sp = mempool_alloc(ha->srb_mempool, GFP_ATOMIC);
  277. if (!sp)
  278. return sp;
  279. atomic_set(&sp->ref_count, 1);
  280. sp->ha = ha;
  281. sp->fcport = fcport;
  282. sp->cmd = cmd;
  283. sp->flags = 0;
  284. CMD_SP(cmd) = (void *)sp;
  285. cmd->scsi_done = done;
  286. return sp;
  287. }
  288. static int
  289. qla2x00_queuecommand(struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *))
  290. {
  291. scsi_qla_host_t *ha = to_qla_host(cmd->device->host);
  292. fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
  293. srb_t *sp;
  294. int rval;
  295. if (!fcport) {
  296. cmd->result = DID_NO_CONNECT << 16;
  297. goto qc_fail_command;
  298. }
  299. if (atomic_read(&fcport->state) != FCS_ONLINE) {
  300. if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD ||
  301. atomic_read(&ha->loop_state) == LOOP_DEAD) {
  302. cmd->result = DID_NO_CONNECT << 16;
  303. goto qc_fail_command;
  304. }
  305. goto qc_host_busy;
  306. }
  307. spin_unlock_irq(ha->host->host_lock);
  308. sp = qla2x00_get_new_sp(ha, fcport, cmd, done);
  309. if (!sp)
  310. goto qc_host_busy_lock;
  311. rval = qla2x00_start_scsi(sp);
  312. if (rval != QLA_SUCCESS)
  313. goto qc_host_busy_free_sp;
  314. spin_lock_irq(ha->host->host_lock);
  315. return 0;
  316. qc_host_busy_free_sp:
  317. qla2x00_sp_free_dma(ha, sp);
  318. mempool_free(sp, ha->srb_mempool);
  319. qc_host_busy_lock:
  320. spin_lock_irq(ha->host->host_lock);
  321. qc_host_busy:
  322. return SCSI_MLQUEUE_HOST_BUSY;
  323. qc_fail_command:
  324. done(cmd);
  325. return 0;
  326. }
  327. static int
  328. qla24xx_queuecommand(struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *))
  329. {
  330. scsi_qla_host_t *ha = to_qla_host(cmd->device->host);
  331. fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
  332. srb_t *sp;
  333. int rval;
  334. if (!fcport) {
  335. cmd->result = DID_NO_CONNECT << 16;
  336. goto qc24_fail_command;
  337. }
  338. if (atomic_read(&fcport->state) != FCS_ONLINE) {
  339. if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD ||
  340. atomic_read(&ha->loop_state) == LOOP_DEAD) {
  341. cmd->result = DID_NO_CONNECT << 16;
  342. goto qc24_fail_command;
  343. }
  344. goto qc24_host_busy;
  345. }
  346. spin_unlock_irq(ha->host->host_lock);
  347. sp = qla2x00_get_new_sp(ha, fcport, cmd, done);
  348. if (!sp)
  349. goto qc24_host_busy_lock;
  350. rval = qla24xx_start_scsi(sp);
  351. if (rval != QLA_SUCCESS)
  352. goto qc24_host_busy_free_sp;
  353. spin_lock_irq(ha->host->host_lock);
  354. return 0;
  355. qc24_host_busy_free_sp:
  356. qla2x00_sp_free_dma(ha, sp);
  357. mempool_free(sp, ha->srb_mempool);
  358. qc24_host_busy_lock:
  359. spin_lock_irq(ha->host->host_lock);
  360. qc24_host_busy:
  361. return SCSI_MLQUEUE_HOST_BUSY;
  362. qc24_fail_command:
  363. done(cmd);
  364. return 0;
  365. }
  366. /*
  367. * qla2x00_eh_wait_on_command
  368. * Waits for the command to be returned by the Firmware for some
  369. * max time.
  370. *
  371. * Input:
  372. * ha = actual ha whose done queue will contain the command
  373. * returned by firmware.
  374. * cmd = Scsi Command to wait on.
  375. * flag = Abort/Reset(Bus or Device Reset)
  376. *
  377. * Return:
  378. * Not Found : 0
  379. * Found : 1
  380. */
  381. static int
  382. qla2x00_eh_wait_on_command(scsi_qla_host_t *ha, struct scsi_cmnd *cmd)
  383. {
  384. #define ABORT_POLLING_PERIOD 1000
  385. #define ABORT_WAIT_ITER ((10 * 1000) / (ABORT_POLLING_PERIOD))
  386. unsigned long wait_iter = ABORT_WAIT_ITER;
  387. int ret = QLA_SUCCESS;
  388. while (CMD_SP(cmd)) {
  389. msleep(ABORT_POLLING_PERIOD);
  390. if (--wait_iter)
  391. break;
  392. }
  393. if (CMD_SP(cmd))
  394. ret = QLA_FUNCTION_FAILED;
  395. return ret;
  396. }
  397. /*
  398. * qla2x00_wait_for_hba_online
  399. * Wait till the HBA is online after going through
  400. * <= MAX_RETRIES_OF_ISP_ABORT or
  401. * finally HBA is disabled ie marked offline
  402. *
  403. * Input:
  404. * ha - pointer to host adapter structure
  405. *
  406. * Note:
  407. * Does context switching-Release SPIN_LOCK
  408. * (if any) before calling this routine.
  409. *
  410. * Return:
  411. * Success (Adapter is online) : 0
  412. * Failed (Adapter is offline/disabled) : 1
  413. */
  414. static int
  415. qla2x00_wait_for_hba_online(scsi_qla_host_t *ha)
  416. {
  417. int return_status;
  418. unsigned long wait_online;
  419. wait_online = jiffies + (MAX_LOOP_TIMEOUT * HZ);
  420. while (((test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags)) ||
  421. test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags) ||
  422. test_bit(ISP_ABORT_RETRY, &ha->dpc_flags) ||
  423. ha->dpc_active) && time_before(jiffies, wait_online)) {
  424. msleep(1000);
  425. }
  426. if (ha->flags.online)
  427. return_status = QLA_SUCCESS;
  428. else
  429. return_status = QLA_FUNCTION_FAILED;
  430. DEBUG2(printk("%s return_status=%d\n",__func__,return_status));
  431. return (return_status);
  432. }
  433. /*
  434. * qla2x00_wait_for_loop_ready
  435. * Wait for MAX_LOOP_TIMEOUT(5 min) value for loop
  436. * to be in LOOP_READY state.
  437. * Input:
  438. * ha - pointer to host adapter structure
  439. *
  440. * Note:
  441. * Does context switching-Release SPIN_LOCK
  442. * (if any) before calling this routine.
  443. *
  444. *
  445. * Return:
  446. * Success (LOOP_READY) : 0
  447. * Failed (LOOP_NOT_READY) : 1
  448. */
  449. static inline int
  450. qla2x00_wait_for_loop_ready(scsi_qla_host_t *ha)
  451. {
  452. int return_status = QLA_SUCCESS;
  453. unsigned long loop_timeout ;
  454. /* wait for 5 min at the max for loop to be ready */
  455. loop_timeout = jiffies + (MAX_LOOP_TIMEOUT * HZ);
  456. while ((!atomic_read(&ha->loop_down_timer) &&
  457. atomic_read(&ha->loop_state) == LOOP_DOWN) ||
  458. atomic_read(&ha->loop_state) != LOOP_READY) {
  459. msleep(1000);
  460. if (time_after_eq(jiffies, loop_timeout)) {
  461. return_status = QLA_FUNCTION_FAILED;
  462. break;
  463. }
  464. }
  465. return (return_status);
  466. }
  467. /**************************************************************************
  468. * qla2xxx_eh_abort
  469. *
  470. * Description:
  471. * The abort function will abort the specified command.
  472. *
  473. * Input:
  474. * cmd = Linux SCSI command packet to be aborted.
  475. *
  476. * Returns:
  477. * Either SUCCESS or FAILED.
  478. *
  479. * Note:
  480. **************************************************************************/
  481. int
  482. qla2xxx_eh_abort(struct scsi_cmnd *cmd)
  483. {
  484. scsi_qla_host_t *ha = to_qla_host(cmd->device->host);
  485. srb_t *sp;
  486. int ret, i;
  487. unsigned int id, lun;
  488. unsigned long serial;
  489. unsigned long flags;
  490. if (!CMD_SP(cmd))
  491. return FAILED;
  492. ret = FAILED;
  493. id = cmd->device->id;
  494. lun = cmd->device->lun;
  495. serial = cmd->serial_number;
  496. /* Check active list for command command. */
  497. spin_lock_irqsave(&ha->hardware_lock, flags);
  498. for (i = 1; i < MAX_OUTSTANDING_COMMANDS; i++) {
  499. sp = ha->outstanding_cmds[i];
  500. if (sp == NULL)
  501. continue;
  502. if (sp->cmd != cmd)
  503. continue;
  504. DEBUG2(printk("%s(%ld): aborting sp %p from RISC. pid=%ld "
  505. "sp->state=%x\n", __func__, ha->host_no, sp, serial,
  506. sp->state));
  507. DEBUG3(qla2x00_print_scsi_cmd(cmd);)
  508. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  509. if (ha->isp_ops.abort_command(ha, sp)) {
  510. DEBUG2(printk("%s(%ld): abort_command "
  511. "mbx failed.\n", __func__, ha->host_no));
  512. } else {
  513. DEBUG3(printk("%s(%ld): abort_command "
  514. "mbx success.\n", __func__, ha->host_no));
  515. ret = SUCCESS;
  516. }
  517. spin_lock_irqsave(&ha->hardware_lock, flags);
  518. break;
  519. }
  520. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  521. /* Wait for the command to be returned. */
  522. if (ret == SUCCESS) {
  523. if (qla2x00_eh_wait_on_command(ha, cmd) != QLA_SUCCESS) {
  524. qla_printk(KERN_ERR, ha,
  525. "scsi(%ld:%d:%d): Abort handler timed out -- %lx "
  526. "%x.\n", ha->host_no, id, lun, serial, ret);
  527. }
  528. }
  529. qla_printk(KERN_INFO, ha,
  530. "scsi(%ld:%d:%d): Abort command issued -- %lx %x.\n", ha->host_no,
  531. id, lun, serial, ret);
  532. return ret;
  533. }
  534. /**************************************************************************
  535. * qla2x00_eh_wait_for_pending_target_commands
  536. *
  537. * Description:
  538. * Waits for all the commands to come back from the specified target.
  539. *
  540. * Input:
  541. * ha - pointer to scsi_qla_host structure.
  542. * t - target
  543. * Returns:
  544. * Either SUCCESS or FAILED.
  545. *
  546. * Note:
  547. **************************************************************************/
  548. static int
  549. qla2x00_eh_wait_for_pending_target_commands(scsi_qla_host_t *ha, unsigned int t)
  550. {
  551. int cnt;
  552. int status;
  553. srb_t *sp;
  554. struct scsi_cmnd *cmd;
  555. unsigned long flags;
  556. status = 0;
  557. /*
  558. * Waiting for all commands for the designated target in the active
  559. * array
  560. */
  561. for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++) {
  562. spin_lock_irqsave(&ha->hardware_lock, flags);
  563. sp = ha->outstanding_cmds[cnt];
  564. if (sp) {
  565. cmd = sp->cmd;
  566. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  567. if (cmd->device->id == t) {
  568. if (!qla2x00_eh_wait_on_command(ha, cmd)) {
  569. status = 1;
  570. break;
  571. }
  572. }
  573. } else {
  574. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  575. }
  576. }
  577. return (status);
  578. }
  579. /**************************************************************************
  580. * qla2xxx_eh_device_reset
  581. *
  582. * Description:
  583. * The device reset function will reset the target and abort any
  584. * executing commands.
  585. *
  586. * NOTE: The use of SP is undefined within this context. Do *NOT*
  587. * attempt to use this value, even if you determine it is
  588. * non-null.
  589. *
  590. * Input:
  591. * cmd = Linux SCSI command packet of the command that cause the
  592. * bus device reset.
  593. *
  594. * Returns:
  595. * SUCCESS/FAILURE (defined as macro in scsi.h).
  596. *
  597. **************************************************************************/
  598. int
  599. qla2xxx_eh_device_reset(struct scsi_cmnd *cmd)
  600. {
  601. scsi_qla_host_t *ha = to_qla_host(cmd->device->host);
  602. fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
  603. srb_t *sp;
  604. int ret;
  605. unsigned int id, lun;
  606. unsigned long serial;
  607. ret = FAILED;
  608. id = cmd->device->id;
  609. lun = cmd->device->lun;
  610. serial = cmd->serial_number;
  611. sp = (srb_t *) CMD_SP(cmd);
  612. if (!sp || !fcport)
  613. return ret;
  614. qla_printk(KERN_INFO, ha,
  615. "scsi(%ld:%d:%d): DEVICE RESET ISSUED.\n", ha->host_no, id, lun);
  616. if (qla2x00_wait_for_hba_online(ha) != QLA_SUCCESS)
  617. goto eh_dev_reset_done;
  618. if (qla2x00_wait_for_loop_ready(ha) == QLA_SUCCESS) {
  619. if (qla2x00_device_reset(ha, fcport) == 0)
  620. ret = SUCCESS;
  621. #if defined(LOGOUT_AFTER_DEVICE_RESET)
  622. if (ret == SUCCESS) {
  623. if (fcport->flags & FC_FABRIC_DEVICE) {
  624. ha->isp_ops.fabric_logout(ha, fcport->loop_id);
  625. qla2x00_mark_device_lost(ha, fcport);
  626. }
  627. }
  628. #endif
  629. } else {
  630. DEBUG2(printk(KERN_INFO
  631. "%s failed: loop not ready\n",__func__);)
  632. }
  633. if (ret == FAILED) {
  634. DEBUG3(printk("%s(%ld): device reset failed\n",
  635. __func__, ha->host_no));
  636. qla_printk(KERN_INFO, ha, "%s: device reset failed\n",
  637. __func__);
  638. goto eh_dev_reset_done;
  639. }
  640. /* Flush outstanding commands. */
  641. if (qla2x00_eh_wait_for_pending_target_commands(ha, id))
  642. ret = FAILED;
  643. if (ret == FAILED) {
  644. DEBUG3(printk("%s(%ld): failed while waiting for commands\n",
  645. __func__, ha->host_no));
  646. qla_printk(KERN_INFO, ha,
  647. "%s: failed while waiting for commands\n", __func__);
  648. } else
  649. qla_printk(KERN_INFO, ha,
  650. "scsi(%ld:%d:%d): DEVICE RESET SUCCEEDED.\n", ha->host_no,
  651. id, lun);
  652. eh_dev_reset_done:
  653. return ret;
  654. }
  655. /**************************************************************************
  656. * qla2x00_eh_wait_for_pending_commands
  657. *
  658. * Description:
  659. * Waits for all the commands to come back from the specified host.
  660. *
  661. * Input:
  662. * ha - pointer to scsi_qla_host structure.
  663. *
  664. * Returns:
  665. * 1 : SUCCESS
  666. * 0 : FAILED
  667. *
  668. * Note:
  669. **************************************************************************/
  670. static int
  671. qla2x00_eh_wait_for_pending_commands(scsi_qla_host_t *ha)
  672. {
  673. int cnt;
  674. int status;
  675. srb_t *sp;
  676. struct scsi_cmnd *cmd;
  677. unsigned long flags;
  678. status = 1;
  679. /*
  680. * Waiting for all commands for the designated target in the active
  681. * array
  682. */
  683. for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++) {
  684. spin_lock_irqsave(&ha->hardware_lock, flags);
  685. sp = ha->outstanding_cmds[cnt];
  686. if (sp) {
  687. cmd = sp->cmd;
  688. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  689. status = qla2x00_eh_wait_on_command(ha, cmd);
  690. if (status == 0)
  691. break;
  692. }
  693. else {
  694. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  695. }
  696. }
  697. return (status);
  698. }
  699. /**************************************************************************
  700. * qla2xxx_eh_bus_reset
  701. *
  702. * Description:
  703. * The bus reset function will reset the bus and abort any executing
  704. * commands.
  705. *
  706. * Input:
  707. * cmd = Linux SCSI command packet of the command that cause the
  708. * bus reset.
  709. *
  710. * Returns:
  711. * SUCCESS/FAILURE (defined as macro in scsi.h).
  712. *
  713. **************************************************************************/
  714. int
  715. qla2xxx_eh_bus_reset(struct scsi_cmnd *cmd)
  716. {
  717. scsi_qla_host_t *ha = to_qla_host(cmd->device->host);
  718. fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
  719. srb_t *sp;
  720. int ret;
  721. unsigned int id, lun;
  722. unsigned long serial;
  723. ret = FAILED;
  724. id = cmd->device->id;
  725. lun = cmd->device->lun;
  726. serial = cmd->serial_number;
  727. sp = (srb_t *) CMD_SP(cmd);
  728. if (!sp || !fcport)
  729. return ret;
  730. qla_printk(KERN_INFO, ha,
  731. "scsi(%ld:%d:%d): LOOP RESET ISSUED.\n", ha->host_no, id, lun);
  732. if (qla2x00_wait_for_hba_online(ha) != QLA_SUCCESS) {
  733. DEBUG2(printk("%s failed:board disabled\n",__func__));
  734. goto eh_bus_reset_done;
  735. }
  736. if (qla2x00_wait_for_loop_ready(ha) == QLA_SUCCESS) {
  737. if (qla2x00_loop_reset(ha) == QLA_SUCCESS)
  738. ret = SUCCESS;
  739. }
  740. if (ret == FAILED)
  741. goto eh_bus_reset_done;
  742. /* Flush outstanding commands. */
  743. if (!qla2x00_eh_wait_for_pending_commands(ha))
  744. ret = FAILED;
  745. eh_bus_reset_done:
  746. qla_printk(KERN_INFO, ha, "%s: reset %s\n", __func__,
  747. (ret == FAILED) ? "failed" : "succeded");
  748. return ret;
  749. }
  750. /**************************************************************************
  751. * qla2xxx_eh_host_reset
  752. *
  753. * Description:
  754. * The reset function will reset the Adapter.
  755. *
  756. * Input:
  757. * cmd = Linux SCSI command packet of the command that cause the
  758. * adapter reset.
  759. *
  760. * Returns:
  761. * Either SUCCESS or FAILED.
  762. *
  763. * Note:
  764. **************************************************************************/
  765. int
  766. qla2xxx_eh_host_reset(struct scsi_cmnd *cmd)
  767. {
  768. scsi_qla_host_t *ha = to_qla_host(cmd->device->host);
  769. fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
  770. srb_t *sp;
  771. int ret;
  772. unsigned int id, lun;
  773. unsigned long serial;
  774. ret = FAILED;
  775. id = cmd->device->id;
  776. lun = cmd->device->lun;
  777. serial = cmd->serial_number;
  778. sp = (srb_t *) CMD_SP(cmd);
  779. if (!sp || !fcport)
  780. return ret;
  781. qla_printk(KERN_INFO, ha,
  782. "scsi(%ld:%d:%d): ADAPTER RESET ISSUED.\n", ha->host_no, id, lun);
  783. if (qla2x00_wait_for_hba_online(ha) != QLA_SUCCESS)
  784. goto eh_host_reset_lock;
  785. /*
  786. * Fixme-may be dpc thread is active and processing
  787. * loop_resync,so wait a while for it to
  788. * be completed and then issue big hammer.Otherwise
  789. * it may cause I/O failure as big hammer marks the
  790. * devices as lost kicking of the port_down_timer
  791. * while dpc is stuck for the mailbox to complete.
  792. */
  793. qla2x00_wait_for_loop_ready(ha);
  794. set_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags);
  795. if (qla2x00_abort_isp(ha)) {
  796. clear_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags);
  797. /* failed. schedule dpc to try */
  798. set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
  799. if (qla2x00_wait_for_hba_online(ha) != QLA_SUCCESS)
  800. goto eh_host_reset_lock;
  801. }
  802. clear_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags);
  803. /* Waiting for our command in done_queue to be returned to OS.*/
  804. if (qla2x00_eh_wait_for_pending_commands(ha))
  805. ret = SUCCESS;
  806. eh_host_reset_lock:
  807. qla_printk(KERN_INFO, ha, "%s: reset %s\n", __func__,
  808. (ret == FAILED) ? "failed" : "succeded");
  809. return ret;
  810. }
  811. /*
  812. * qla2x00_loop_reset
  813. * Issue loop reset.
  814. *
  815. * Input:
  816. * ha = adapter block pointer.
  817. *
  818. * Returns:
  819. * 0 = success
  820. */
  821. static int
  822. qla2x00_loop_reset(scsi_qla_host_t *ha)
  823. {
  824. int status = QLA_SUCCESS;
  825. struct fc_port *fcport;
  826. if (ha->flags.enable_lip_reset) {
  827. status = qla2x00_lip_reset(ha);
  828. }
  829. if (status == QLA_SUCCESS && ha->flags.enable_target_reset) {
  830. list_for_each_entry(fcport, &ha->fcports, list) {
  831. if (fcport->port_type != FCT_TARGET)
  832. continue;
  833. status = qla2x00_device_reset(ha, fcport);
  834. if (status != QLA_SUCCESS)
  835. break;
  836. }
  837. }
  838. if (status == QLA_SUCCESS &&
  839. ((!ha->flags.enable_target_reset &&
  840. !ha->flags.enable_lip_reset) ||
  841. ha->flags.enable_lip_full_login)) {
  842. status = qla2x00_full_login_lip(ha);
  843. }
  844. /* Issue marker command only when we are going to start the I/O */
  845. ha->marker_needed = 1;
  846. if (status) {
  847. /* Empty */
  848. DEBUG2_3(printk("%s(%ld): **** FAILED ****\n",
  849. __func__,
  850. ha->host_no);)
  851. } else {
  852. /* Empty */
  853. DEBUG3(printk("%s(%ld): exiting normally.\n",
  854. __func__,
  855. ha->host_no);)
  856. }
  857. return(status);
  858. }
  859. /*
  860. * qla2x00_device_reset
  861. * Issue bus device reset message to the target.
  862. *
  863. * Input:
  864. * ha = adapter block pointer.
  865. * t = SCSI ID.
  866. * TARGET_QUEUE_LOCK must be released.
  867. * ADAPTER_STATE_LOCK must be released.
  868. *
  869. * Context:
  870. * Kernel context.
  871. */
  872. static int
  873. qla2x00_device_reset(scsi_qla_host_t *ha, fc_port_t *reset_fcport)
  874. {
  875. /* Abort Target command will clear Reservation */
  876. return ha->isp_ops.abort_target(reset_fcport);
  877. }
  878. static int
  879. qla2xxx_slave_alloc(struct scsi_device *sdev)
  880. {
  881. struct fc_rport *rport = starget_to_rport(scsi_target(sdev));
  882. if (!rport)
  883. return -ENXIO;
  884. sdev->hostdata = rport->dd_data;
  885. return 0;
  886. }
  887. static int
  888. qla2xxx_slave_configure(struct scsi_device *sdev)
  889. {
  890. scsi_qla_host_t *ha = to_qla_host(sdev->host);
  891. struct fc_rport *rport = starget_to_rport(sdev->sdev_target);
  892. if (sdev->tagged_supported)
  893. scsi_activate_tcq(sdev, 32);
  894. else
  895. scsi_deactivate_tcq(sdev, 32);
  896. rport->dev_loss_tmo = ha->port_down_retry_count + 5;
  897. return 0;
  898. }
  899. static void
  900. qla2xxx_slave_destroy(struct scsi_device *sdev)
  901. {
  902. sdev->hostdata = NULL;
  903. }
  904. static int
  905. qla2x00_change_queue_depth(struct scsi_device *sdev, int qdepth)
  906. {
  907. scsi_adjust_queue_depth(sdev, scsi_get_tag_type(sdev), qdepth);
  908. return sdev->queue_depth;
  909. }
  910. static int
  911. qla2x00_change_queue_type(struct scsi_device *sdev, int tag_type)
  912. {
  913. if (sdev->tagged_supported) {
  914. scsi_set_tag_type(sdev, tag_type);
  915. if (tag_type)
  916. scsi_activate_tcq(sdev, sdev->queue_depth);
  917. else
  918. scsi_deactivate_tcq(sdev, sdev->queue_depth);
  919. } else
  920. tag_type = 0;
  921. return tag_type;
  922. }
  923. /**
  924. * qla2x00_config_dma_addressing() - Configure OS DMA addressing method.
  925. * @ha: HA context
  926. *
  927. * At exit, the @ha's flags.enable_64bit_addressing set to indicated
  928. * supported addressing method.
  929. */
  930. static void
  931. qla2x00_config_dma_addressing(scsi_qla_host_t *ha)
  932. {
  933. /* Assume a 32bit DMA mask. */
  934. ha->flags.enable_64bit_addressing = 0;
  935. if (!dma_set_mask(&ha->pdev->dev, DMA_64BIT_MASK)) {
  936. /* Any upper-dword bits set? */
  937. if (MSD(dma_get_required_mask(&ha->pdev->dev)) &&
  938. !pci_set_consistent_dma_mask(ha->pdev, DMA_64BIT_MASK)) {
  939. /* Ok, a 64bit DMA mask is applicable. */
  940. ha->flags.enable_64bit_addressing = 1;
  941. ha->isp_ops.calc_req_entries = qla2x00_calc_iocbs_64;
  942. ha->isp_ops.build_iocbs = qla2x00_build_scsi_iocbs_64;
  943. return;
  944. }
  945. }
  946. dma_set_mask(&ha->pdev->dev, DMA_32BIT_MASK);
  947. pci_set_consistent_dma_mask(ha->pdev, DMA_32BIT_MASK);
  948. }
  949. static int
  950. qla2x00_iospace_config(scsi_qla_host_t *ha)
  951. {
  952. unsigned long pio, pio_len, pio_flags;
  953. unsigned long mmio, mmio_len, mmio_flags;
  954. /* We only need PIO for Flash operations on ISP2312 v2 chips. */
  955. pio = pci_resource_start(ha->pdev, 0);
  956. pio_len = pci_resource_len(ha->pdev, 0);
  957. pio_flags = pci_resource_flags(ha->pdev, 0);
  958. if (pio_flags & IORESOURCE_IO) {
  959. if (pio_len < MIN_IOBASE_LEN) {
  960. qla_printk(KERN_WARNING, ha,
  961. "Invalid PCI I/O region size (%s)...\n",
  962. pci_name(ha->pdev));
  963. pio = 0;
  964. }
  965. } else {
  966. qla_printk(KERN_WARNING, ha,
  967. "region #0 not a PIO resource (%s)...\n",
  968. pci_name(ha->pdev));
  969. pio = 0;
  970. }
  971. /* Use MMIO operations for all accesses. */
  972. mmio = pci_resource_start(ha->pdev, 1);
  973. mmio_len = pci_resource_len(ha->pdev, 1);
  974. mmio_flags = pci_resource_flags(ha->pdev, 1);
  975. if (!(mmio_flags & IORESOURCE_MEM)) {
  976. qla_printk(KERN_ERR, ha,
  977. "region #0 not an MMIO resource (%s), aborting\n",
  978. pci_name(ha->pdev));
  979. goto iospace_error_exit;
  980. }
  981. if (mmio_len < MIN_IOBASE_LEN) {
  982. qla_printk(KERN_ERR, ha,
  983. "Invalid PCI mem region size (%s), aborting\n",
  984. pci_name(ha->pdev));
  985. goto iospace_error_exit;
  986. }
  987. if (pci_request_regions(ha->pdev, ha->brd_info->drv_name)) {
  988. qla_printk(KERN_WARNING, ha,
  989. "Failed to reserve PIO/MMIO regions (%s)\n",
  990. pci_name(ha->pdev));
  991. goto iospace_error_exit;
  992. }
  993. ha->pio_address = pio;
  994. ha->pio_length = pio_len;
  995. ha->iobase = ioremap(mmio, MIN_IOBASE_LEN);
  996. if (!ha->iobase) {
  997. qla_printk(KERN_ERR, ha,
  998. "cannot remap MMIO (%s), aborting\n", pci_name(ha->pdev));
  999. goto iospace_error_exit;
  1000. }
  1001. return (0);
  1002. iospace_error_exit:
  1003. return (-ENOMEM);
  1004. }
  1005. static void
  1006. qla2x00_enable_intrs(scsi_qla_host_t *ha)
  1007. {
  1008. unsigned long flags = 0;
  1009. struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
  1010. spin_lock_irqsave(&ha->hardware_lock, flags);
  1011. ha->interrupts_on = 1;
  1012. /* enable risc and host interrupts */
  1013. WRT_REG_WORD(&reg->ictrl, ICR_EN_INT | ICR_EN_RISC);
  1014. RD_REG_WORD(&reg->ictrl);
  1015. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  1016. }
  1017. static void
  1018. qla2x00_disable_intrs(scsi_qla_host_t *ha)
  1019. {
  1020. unsigned long flags = 0;
  1021. struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
  1022. spin_lock_irqsave(&ha->hardware_lock, flags);
  1023. ha->interrupts_on = 0;
  1024. /* disable risc and host interrupts */
  1025. WRT_REG_WORD(&reg->ictrl, 0);
  1026. RD_REG_WORD(&reg->ictrl);
  1027. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  1028. }
  1029. static void
  1030. qla24xx_enable_intrs(scsi_qla_host_t *ha)
  1031. {
  1032. unsigned long flags = 0;
  1033. struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
  1034. spin_lock_irqsave(&ha->hardware_lock, flags);
  1035. ha->interrupts_on = 1;
  1036. WRT_REG_DWORD(&reg->ictrl, ICRX_EN_RISC_INT);
  1037. RD_REG_DWORD(&reg->ictrl);
  1038. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  1039. }
  1040. static void
  1041. qla24xx_disable_intrs(scsi_qla_host_t *ha)
  1042. {
  1043. unsigned long flags = 0;
  1044. struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
  1045. spin_lock_irqsave(&ha->hardware_lock, flags);
  1046. ha->interrupts_on = 0;
  1047. WRT_REG_DWORD(&reg->ictrl, 0);
  1048. RD_REG_DWORD(&reg->ictrl);
  1049. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  1050. }
  1051. /*
  1052. * PCI driver interface
  1053. */
  1054. int qla2x00_probe_one(struct pci_dev *pdev, struct qla_board_info *brd_info)
  1055. {
  1056. int ret = -ENODEV;
  1057. device_reg_t __iomem *reg;
  1058. struct Scsi_Host *host;
  1059. scsi_qla_host_t *ha;
  1060. unsigned long flags = 0;
  1061. unsigned long wait_switch = 0;
  1062. char pci_info[20];
  1063. char fw_str[30];
  1064. fc_port_t *fcport;
  1065. if (pci_enable_device(pdev))
  1066. goto probe_out;
  1067. host = scsi_host_alloc(brd_info->sht ? brd_info->sht:
  1068. &qla2x00_driver_template, sizeof(scsi_qla_host_t));
  1069. if (host == NULL) {
  1070. printk(KERN_WARNING
  1071. "qla2xxx: Couldn't allocate host from scsi layer!\n");
  1072. goto probe_disable_device;
  1073. }
  1074. /* Clear our data area */
  1075. ha = (scsi_qla_host_t *)host->hostdata;
  1076. memset(ha, 0, sizeof(scsi_qla_host_t));
  1077. ha->pdev = pdev;
  1078. ha->host = host;
  1079. ha->host_no = host->host_no;
  1080. ha->brd_info = brd_info;
  1081. sprintf(ha->host_str, "%s_%ld", ha->brd_info->drv_name, ha->host_no);
  1082. ha->dpc_pid = -1;
  1083. /* Configure PCI I/O space */
  1084. ret = qla2x00_iospace_config(ha);
  1085. if (ret)
  1086. goto probe_failed;
  1087. qla_printk(KERN_INFO, ha,
  1088. "Found an %s, irq %d, iobase 0x%p\n", ha->brd_info->isp_name,
  1089. pdev->irq, ha->iobase);
  1090. spin_lock_init(&ha->hardware_lock);
  1091. ha->prev_topology = 0;
  1092. ha->ports = MAX_BUSES;
  1093. ha->init_cb_size = sizeof(init_cb_t);
  1094. ha->mgmt_svr_loop_id = MANAGEMENT_SERVER;
  1095. /* Assign ISP specific operations. */
  1096. ha->isp_ops.pci_config = qla2100_pci_config;
  1097. ha->isp_ops.reset_chip = qla2x00_reset_chip;
  1098. ha->isp_ops.chip_diag = qla2x00_chip_diag;
  1099. ha->isp_ops.config_rings = qla2x00_config_rings;
  1100. ha->isp_ops.reset_adapter = qla2x00_reset_adapter;
  1101. ha->isp_ops.nvram_config = qla2x00_nvram_config;
  1102. ha->isp_ops.update_fw_options = qla2x00_update_fw_options;
  1103. ha->isp_ops.load_risc = qla2x00_load_risc;
  1104. ha->isp_ops.pci_info_str = qla2x00_pci_info_str;
  1105. ha->isp_ops.fw_version_str = qla2x00_fw_version_str;
  1106. ha->isp_ops.intr_handler = qla2100_intr_handler;
  1107. ha->isp_ops.enable_intrs = qla2x00_enable_intrs;
  1108. ha->isp_ops.disable_intrs = qla2x00_disable_intrs;
  1109. ha->isp_ops.abort_command = qla2x00_abort_command;
  1110. ha->isp_ops.abort_target = qla2x00_abort_target;
  1111. ha->isp_ops.fabric_login = qla2x00_login_fabric;
  1112. ha->isp_ops.fabric_logout = qla2x00_fabric_logout;
  1113. ha->isp_ops.calc_req_entries = qla2x00_calc_iocbs_32;
  1114. ha->isp_ops.build_iocbs = qla2x00_build_scsi_iocbs_32;
  1115. ha->isp_ops.prep_ms_iocb = qla2x00_prep_ms_iocb;
  1116. ha->isp_ops.prep_ms_fdmi_iocb = qla2x00_prep_ms_fdmi_iocb;
  1117. ha->isp_ops.read_nvram = qla2x00_read_nvram_data;
  1118. ha->isp_ops.write_nvram = qla2x00_write_nvram_data;
  1119. ha->isp_ops.fw_dump = qla2100_fw_dump;
  1120. ha->isp_ops.ascii_fw_dump = qla2100_ascii_fw_dump;
  1121. if (IS_QLA2100(ha)) {
  1122. host->max_id = MAX_TARGETS_2100;
  1123. ha->mbx_count = MAILBOX_REGISTER_COUNT_2100;
  1124. ha->request_q_length = REQUEST_ENTRY_CNT_2100;
  1125. ha->response_q_length = RESPONSE_ENTRY_CNT_2100;
  1126. ha->last_loop_id = SNS_LAST_LOOP_ID_2100;
  1127. host->sg_tablesize = 32;
  1128. ha->gid_list_info_size = 4;
  1129. } else if (IS_QLA2200(ha)) {
  1130. host->max_id = MAX_TARGETS_2200;
  1131. ha->mbx_count = MAILBOX_REGISTER_COUNT;
  1132. ha->request_q_length = REQUEST_ENTRY_CNT_2200;
  1133. ha->response_q_length = RESPONSE_ENTRY_CNT_2100;
  1134. ha->last_loop_id = SNS_LAST_LOOP_ID_2100;
  1135. ha->gid_list_info_size = 4;
  1136. } else if (IS_QLA23XX(ha)) {
  1137. host->max_id = MAX_TARGETS_2200;
  1138. ha->mbx_count = MAILBOX_REGISTER_COUNT;
  1139. ha->request_q_length = REQUEST_ENTRY_CNT_2200;
  1140. ha->response_q_length = RESPONSE_ENTRY_CNT_2300;
  1141. ha->last_loop_id = SNS_LAST_LOOP_ID_2300;
  1142. ha->isp_ops.pci_config = qla2300_pci_config;
  1143. ha->isp_ops.intr_handler = qla2300_intr_handler;
  1144. ha->isp_ops.fw_dump = qla2300_fw_dump;
  1145. ha->isp_ops.ascii_fw_dump = qla2300_ascii_fw_dump;
  1146. ha->gid_list_info_size = 6;
  1147. } else if (IS_QLA24XX(ha) || IS_QLA25XX(ha)) {
  1148. host->max_id = MAX_TARGETS_2200;
  1149. ha->mbx_count = MAILBOX_REGISTER_COUNT;
  1150. ha->request_q_length = REQUEST_ENTRY_CNT_24XX;
  1151. ha->response_q_length = RESPONSE_ENTRY_CNT_2300;
  1152. ha->last_loop_id = SNS_LAST_LOOP_ID_2300;
  1153. ha->init_cb_size = sizeof(struct init_cb_24xx);
  1154. ha->mgmt_svr_loop_id = 10;
  1155. ha->isp_ops.pci_config = qla24xx_pci_config;
  1156. ha->isp_ops.reset_chip = qla24xx_reset_chip;
  1157. ha->isp_ops.chip_diag = qla24xx_chip_diag;
  1158. ha->isp_ops.config_rings = qla24xx_config_rings;
  1159. ha->isp_ops.reset_adapter = qla24xx_reset_adapter;
  1160. ha->isp_ops.nvram_config = qla24xx_nvram_config;
  1161. ha->isp_ops.update_fw_options = qla24xx_update_fw_options;
  1162. ha->isp_ops.load_risc = qla24xx_load_risc_flash;
  1163. if (ql2xfwloadbin)
  1164. ha->isp_ops.load_risc = qla24xx_load_risc_hotplug;
  1165. ha->isp_ops.pci_info_str = qla24xx_pci_info_str;
  1166. ha->isp_ops.fw_version_str = qla24xx_fw_version_str;
  1167. ha->isp_ops.intr_handler = qla24xx_intr_handler;
  1168. ha->isp_ops.enable_intrs = qla24xx_enable_intrs;
  1169. ha->isp_ops.disable_intrs = qla24xx_disable_intrs;
  1170. ha->isp_ops.abort_command = qla24xx_abort_command;
  1171. ha->isp_ops.abort_target = qla24xx_abort_target;
  1172. ha->isp_ops.fabric_login = qla24xx_login_fabric;
  1173. ha->isp_ops.fabric_logout = qla24xx_fabric_logout;
  1174. ha->isp_ops.prep_ms_iocb = qla24xx_prep_ms_iocb;
  1175. ha->isp_ops.prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb;
  1176. ha->isp_ops.read_nvram = qla24xx_read_nvram_data;
  1177. ha->isp_ops.write_nvram = qla24xx_write_nvram_data;
  1178. ha->isp_ops.fw_dump = qla24xx_fw_dump;
  1179. ha->isp_ops.ascii_fw_dump = qla24xx_ascii_fw_dump;
  1180. ha->gid_list_info_size = 8;
  1181. }
  1182. host->can_queue = ha->request_q_length + 128;
  1183. /* load the F/W, read paramaters, and init the H/W */
  1184. ha->instance = num_hosts;
  1185. init_MUTEX(&ha->mbx_cmd_sem);
  1186. init_MUTEX_LOCKED(&ha->mbx_intr_sem);
  1187. INIT_LIST_HEAD(&ha->list);
  1188. INIT_LIST_HEAD(&ha->fcports);
  1189. INIT_LIST_HEAD(&ha->rscn_fcports);
  1190. /*
  1191. * These locks are used to prevent more than one CPU
  1192. * from modifying the queue at the same time. The
  1193. * higher level "host_lock" will reduce most
  1194. * contention for these locks.
  1195. */
  1196. spin_lock_init(&ha->mbx_reg_lock);
  1197. init_completion(&ha->dpc_inited);
  1198. init_completion(&ha->dpc_exited);
  1199. qla2x00_config_dma_addressing(ha);
  1200. if (qla2x00_mem_alloc(ha)) {
  1201. qla_printk(KERN_WARNING, ha,
  1202. "[ERROR] Failed to allocate memory for adapter\n");
  1203. ret = -ENOMEM;
  1204. goto probe_failed;
  1205. }
  1206. if (qla2x00_initialize_adapter(ha) &&
  1207. !(ha->device_flags & DFLG_NO_CABLE)) {
  1208. qla_printk(KERN_WARNING, ha,
  1209. "Failed to initialize adapter\n");
  1210. DEBUG2(printk("scsi(%ld): Failed to initialize adapter - "
  1211. "Adapter flags %x.\n",
  1212. ha->host_no, ha->device_flags));
  1213. ret = -ENODEV;
  1214. goto probe_failed;
  1215. }
  1216. /*
  1217. * Startup the kernel thread for this host adapter
  1218. */
  1219. ha->dpc_should_die = 0;
  1220. ha->dpc_pid = kernel_thread(qla2x00_do_dpc, ha, 0);
  1221. if (ha->dpc_pid < 0) {
  1222. qla_printk(KERN_WARNING, ha,
  1223. "Unable to start DPC thread!\n");
  1224. ret = -ENODEV;
  1225. goto probe_failed;
  1226. }
  1227. wait_for_completion(&ha->dpc_inited);
  1228. host->this_id = 255;
  1229. host->cmd_per_lun = 3;
  1230. host->unique_id = ha->instance;
  1231. host->max_cmd_len = MAX_CMDSZ;
  1232. host->max_channel = ha->ports - 1;
  1233. host->max_lun = MAX_LUNS;
  1234. host->transportt = qla2xxx_transport_template;
  1235. ret = request_irq(pdev->irq, ha->isp_ops.intr_handler,
  1236. SA_INTERRUPT|SA_SHIRQ, ha->brd_info->drv_name, ha);
  1237. if (ret) {
  1238. qla_printk(KERN_WARNING, ha,
  1239. "Failed to reserve interrupt %d already in use.\n",
  1240. pdev->irq);
  1241. goto probe_failed;
  1242. }
  1243. host->irq = pdev->irq;
  1244. /* Initialized the timer */
  1245. qla2x00_start_timer(ha, qla2x00_timer, WATCH_INTERVAL);
  1246. DEBUG2(printk("DEBUG: detect hba %ld at address = %p\n",
  1247. ha->host_no, ha));
  1248. ha->isp_ops.disable_intrs(ha);
  1249. spin_lock_irqsave(&ha->hardware_lock, flags);
  1250. reg = ha->iobase;
  1251. if (IS_QLA24XX(ha) || IS_QLA25XX(ha)) {
  1252. WRT_REG_DWORD(&reg->isp24.hccr, HCCRX_CLR_HOST_INT);
  1253. WRT_REG_DWORD(&reg->isp24.hccr, HCCRX_CLR_RISC_INT);
  1254. } else {
  1255. WRT_REG_WORD(&reg->isp.semaphore, 0);
  1256. WRT_REG_WORD(&reg->isp.hccr, HCCR_CLR_RISC_INT);
  1257. WRT_REG_WORD(&reg->isp.hccr, HCCR_CLR_HOST_INT);
  1258. /* Enable proper parity */
  1259. if (!IS_QLA2100(ha) && !IS_QLA2200(ha)) {
  1260. if (IS_QLA2300(ha))
  1261. /* SRAM parity */
  1262. WRT_REG_WORD(&reg->isp.hccr,
  1263. (HCCR_ENABLE_PARITY + 0x1));
  1264. else
  1265. /* SRAM, Instruction RAM and GP RAM parity */
  1266. WRT_REG_WORD(&reg->isp.hccr,
  1267. (HCCR_ENABLE_PARITY + 0x7));
  1268. }
  1269. }
  1270. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  1271. ha->isp_ops.enable_intrs(ha);
  1272. /* v2.19.5b6 */
  1273. /*
  1274. * Wait around max loop_reset_delay secs for the devices to come
  1275. * on-line. We don't want Linux scanning before we are ready.
  1276. *
  1277. */
  1278. for (wait_switch = jiffies + (ha->loop_reset_delay * HZ);
  1279. time_before(jiffies,wait_switch) &&
  1280. !(ha->device_flags & (DFLG_NO_CABLE | DFLG_FABRIC_DEVICES))
  1281. && (ha->device_flags & SWITCH_FOUND) ;) {
  1282. qla2x00_check_fabric_devices(ha);
  1283. msleep(10);
  1284. }
  1285. pci_set_drvdata(pdev, ha);
  1286. ha->flags.init_done = 1;
  1287. num_hosts++;
  1288. ret = scsi_add_host(host, &pdev->dev);
  1289. if (ret)
  1290. goto probe_failed;
  1291. qla2x00_alloc_sysfs_attr(ha);
  1292. qla2x00_init_host_attr(ha);
  1293. qla_printk(KERN_INFO, ha, "\n"
  1294. " QLogic Fibre Channel HBA Driver: %s\n"
  1295. " QLogic %s - %s\n"
  1296. " %s: %s @ %s hdma%c, host#=%ld, fw=%s\n", qla2x00_version_str,
  1297. ha->model_number, ha->model_desc ? ha->model_desc: "",
  1298. ha->brd_info->isp_name, ha->isp_ops.pci_info_str(ha, pci_info),
  1299. pci_name(pdev), ha->flags.enable_64bit_addressing ? '+': '-',
  1300. ha->host_no, ha->isp_ops.fw_version_str(ha, fw_str));
  1301. /* Go with fc_rport registration. */
  1302. list_for_each_entry(fcport, &ha->fcports, list)
  1303. qla2x00_reg_remote_port(ha, fcport);
  1304. return 0;
  1305. probe_failed:
  1306. qla2x00_free_device(ha);
  1307. scsi_host_put(host);
  1308. probe_disable_device:
  1309. pci_disable_device(pdev);
  1310. probe_out:
  1311. return ret;
  1312. }
  1313. EXPORT_SYMBOL_GPL(qla2x00_probe_one);
  1314. void qla2x00_remove_one(struct pci_dev *pdev)
  1315. {
  1316. scsi_qla_host_t *ha;
  1317. ha = pci_get_drvdata(pdev);
  1318. qla2x00_free_sysfs_attr(ha);
  1319. fc_remove_host(ha->host);
  1320. scsi_remove_host(ha->host);
  1321. qla2x00_free_device(ha);
  1322. scsi_host_put(ha->host);
  1323. pci_set_drvdata(pdev, NULL);
  1324. }
  1325. EXPORT_SYMBOL_GPL(qla2x00_remove_one);
  1326. static void
  1327. qla2x00_free_device(scsi_qla_host_t *ha)
  1328. {
  1329. int ret;
  1330. /* Abort any outstanding IO descriptors. */
  1331. if (!IS_QLA2100(ha) && !IS_QLA2200(ha))
  1332. qla2x00_cancel_io_descriptors(ha);
  1333. /* Disable timer */
  1334. if (ha->timer_active)
  1335. qla2x00_stop_timer(ha);
  1336. /* Kill the kernel thread for this host */
  1337. if (ha->dpc_pid >= 0) {
  1338. ha->dpc_should_die = 1;
  1339. wmb();
  1340. ret = kill_proc(ha->dpc_pid, SIGHUP, 1);
  1341. if (ret) {
  1342. qla_printk(KERN_ERR, ha,
  1343. "Unable to signal DPC thread -- (%d)\n", ret);
  1344. /* TODO: SOMETHING MORE??? */
  1345. } else {
  1346. wait_for_completion(&ha->dpc_exited);
  1347. }
  1348. }
  1349. /* Stop currently executing firmware. */
  1350. qla2x00_stop_firmware(ha);
  1351. /* turn-off interrupts on the card */
  1352. if (ha->interrupts_on)
  1353. ha->isp_ops.disable_intrs(ha);
  1354. qla2x00_mem_free(ha);
  1355. ha->flags.online = 0;
  1356. /* Detach interrupts */
  1357. if (ha->pdev->irq)
  1358. free_irq(ha->pdev->irq, ha);
  1359. /* release io space registers */
  1360. if (ha->iobase)
  1361. iounmap(ha->iobase);
  1362. pci_release_regions(ha->pdev);
  1363. pci_disable_device(ha->pdev);
  1364. }
  1365. /*
  1366. * qla2x00_mark_device_lost Updates fcport state when device goes offline.
  1367. *
  1368. * Input: ha = adapter block pointer. fcport = port structure pointer.
  1369. *
  1370. * Return: None.
  1371. *
  1372. * Context:
  1373. */
  1374. void qla2x00_mark_device_lost(scsi_qla_host_t *ha, fc_port_t *fcport,
  1375. int do_login)
  1376. {
  1377. if (atomic_read(&fcport->state) == FCS_ONLINE && fcport->rport)
  1378. fc_remote_port_block(fcport->rport);
  1379. /*
  1380. * We may need to retry the login, so don't change the state of the
  1381. * port but do the retries.
  1382. */
  1383. if (atomic_read(&fcport->state) != FCS_DEVICE_DEAD)
  1384. atomic_set(&fcport->state, FCS_DEVICE_LOST);
  1385. if (!do_login)
  1386. return;
  1387. if (fcport->login_retry == 0) {
  1388. fcport->login_retry = ha->login_retry_count;
  1389. set_bit(RELOGIN_NEEDED, &ha->dpc_flags);
  1390. DEBUG(printk("scsi(%ld): Port login retry: "
  1391. "%02x%02x%02x%02x%02x%02x%02x%02x, "
  1392. "id = 0x%04x retry cnt=%d\n",
  1393. ha->host_no,
  1394. fcport->port_name[0],
  1395. fcport->port_name[1],
  1396. fcport->port_name[2],
  1397. fcport->port_name[3],
  1398. fcport->port_name[4],
  1399. fcport->port_name[5],
  1400. fcport->port_name[6],
  1401. fcport->port_name[7],
  1402. fcport->loop_id,
  1403. fcport->login_retry));
  1404. }
  1405. }
  1406. /*
  1407. * qla2x00_mark_all_devices_lost
  1408. * Updates fcport state when device goes offline.
  1409. *
  1410. * Input:
  1411. * ha = adapter block pointer.
  1412. * fcport = port structure pointer.
  1413. *
  1414. * Return:
  1415. * None.
  1416. *
  1417. * Context:
  1418. */
  1419. void
  1420. qla2x00_mark_all_devices_lost(scsi_qla_host_t *ha)
  1421. {
  1422. fc_port_t *fcport;
  1423. list_for_each_entry(fcport, &ha->fcports, list) {
  1424. if (fcport->port_type != FCT_TARGET)
  1425. continue;
  1426. /*
  1427. * No point in marking the device as lost, if the device is
  1428. * already DEAD.
  1429. */
  1430. if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD)
  1431. continue;
  1432. if (atomic_read(&fcport->state) == FCS_ONLINE && fcport->rport)
  1433. fc_remote_port_block(fcport->rport);
  1434. atomic_set(&fcport->state, FCS_DEVICE_LOST);
  1435. }
  1436. }
  1437. /*
  1438. * qla2x00_mem_alloc
  1439. * Allocates adapter memory.
  1440. *
  1441. * Returns:
  1442. * 0 = success.
  1443. * 1 = failure.
  1444. */
  1445. static uint8_t
  1446. qla2x00_mem_alloc(scsi_qla_host_t *ha)
  1447. {
  1448. char name[16];
  1449. uint8_t status = 1;
  1450. int retry= 10;
  1451. do {
  1452. /*
  1453. * This will loop only once if everything goes well, else some
  1454. * number of retries will be performed to get around a kernel
  1455. * bug where available mem is not allocated until after a
  1456. * little delay and a retry.
  1457. */
  1458. ha->request_ring = dma_alloc_coherent(&ha->pdev->dev,
  1459. (ha->request_q_length + 1) * sizeof(request_t),
  1460. &ha->request_dma, GFP_KERNEL);
  1461. if (ha->request_ring == NULL) {
  1462. qla_printk(KERN_WARNING, ha,
  1463. "Memory Allocation failed - request_ring\n");
  1464. qla2x00_mem_free(ha);
  1465. msleep(100);
  1466. continue;
  1467. }
  1468. ha->response_ring = dma_alloc_coherent(&ha->pdev->dev,
  1469. (ha->response_q_length + 1) * sizeof(response_t),
  1470. &ha->response_dma, GFP_KERNEL);
  1471. if (ha->response_ring == NULL) {
  1472. qla_printk(KERN_WARNING, ha,
  1473. "Memory Allocation failed - response_ring\n");
  1474. qla2x00_mem_free(ha);
  1475. msleep(100);
  1476. continue;
  1477. }
  1478. ha->gid_list = dma_alloc_coherent(&ha->pdev->dev, GID_LIST_SIZE,
  1479. &ha->gid_list_dma, GFP_KERNEL);
  1480. if (ha->gid_list == NULL) {
  1481. qla_printk(KERN_WARNING, ha,
  1482. "Memory Allocation failed - gid_list\n");
  1483. qla2x00_mem_free(ha);
  1484. msleep(100);
  1485. continue;
  1486. }
  1487. ha->rlc_rsp = dma_alloc_coherent(&ha->pdev->dev,
  1488. sizeof(rpt_lun_cmd_rsp_t), &ha->rlc_rsp_dma, GFP_KERNEL);
  1489. if (ha->rlc_rsp == NULL) {
  1490. qla_printk(KERN_WARNING, ha,
  1491. "Memory Allocation failed - rlc");
  1492. qla2x00_mem_free(ha);
  1493. msleep(100);
  1494. continue;
  1495. }
  1496. snprintf(name, sizeof(name), "qla2xxx_%ld", ha->host_no);
  1497. ha->s_dma_pool = dma_pool_create(name, &ha->pdev->dev,
  1498. DMA_POOL_SIZE, 8, 0);
  1499. if (ha->s_dma_pool == NULL) {
  1500. qla_printk(KERN_WARNING, ha,
  1501. "Memory Allocation failed - s_dma_pool\n");
  1502. qla2x00_mem_free(ha);
  1503. msleep(100);
  1504. continue;
  1505. }
  1506. /* get consistent memory allocated for init control block */
  1507. ha->init_cb = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
  1508. &ha->init_cb_dma);
  1509. if (ha->init_cb == NULL) {
  1510. qla_printk(KERN_WARNING, ha,
  1511. "Memory Allocation failed - init_cb\n");
  1512. qla2x00_mem_free(ha);
  1513. msleep(100);
  1514. continue;
  1515. }
  1516. memset(ha->init_cb, 0, ha->init_cb_size);
  1517. /* Get consistent memory allocated for Get Port Database cmd */
  1518. ha->iodesc_pd = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
  1519. &ha->iodesc_pd_dma);
  1520. if (ha->iodesc_pd == NULL) {
  1521. /* error */
  1522. qla_printk(KERN_WARNING, ha,
  1523. "Memory Allocation failed - iodesc_pd\n");
  1524. qla2x00_mem_free(ha);
  1525. msleep(100);
  1526. continue;
  1527. }
  1528. memset(ha->iodesc_pd, 0, PORT_DATABASE_SIZE);
  1529. /* Allocate ioctl related memory. */
  1530. if (qla2x00_alloc_ioctl_mem(ha)) {
  1531. qla_printk(KERN_WARNING, ha,
  1532. "Memory Allocation failed - ioctl_mem\n");
  1533. qla2x00_mem_free(ha);
  1534. msleep(100);
  1535. continue;
  1536. }
  1537. if (qla2x00_allocate_sp_pool(ha)) {
  1538. qla_printk(KERN_WARNING, ha,
  1539. "Memory Allocation failed - "
  1540. "qla2x00_allocate_sp_pool()\n");
  1541. qla2x00_mem_free(ha);
  1542. msleep(100);
  1543. continue;
  1544. }
  1545. /* Allocate memory for SNS commands */
  1546. if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
  1547. /* Get consistent memory allocated for SNS commands */
  1548. ha->sns_cmd = dma_alloc_coherent(&ha->pdev->dev,
  1549. sizeof(struct sns_cmd_pkt), &ha->sns_cmd_dma,
  1550. GFP_KERNEL);
  1551. if (ha->sns_cmd == NULL) {
  1552. /* error */
  1553. qla_printk(KERN_WARNING, ha,
  1554. "Memory Allocation failed - sns_cmd\n");
  1555. qla2x00_mem_free(ha);
  1556. msleep(100);
  1557. continue;
  1558. }
  1559. memset(ha->sns_cmd, 0, sizeof(struct sns_cmd_pkt));
  1560. } else {
  1561. /* Get consistent memory allocated for MS IOCB */
  1562. ha->ms_iocb = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
  1563. &ha->ms_iocb_dma);
  1564. if (ha->ms_iocb == NULL) {
  1565. /* error */
  1566. qla_printk(KERN_WARNING, ha,
  1567. "Memory Allocation failed - ms_iocb\n");
  1568. qla2x00_mem_free(ha);
  1569. msleep(100);
  1570. continue;
  1571. }
  1572. memset(ha->ms_iocb, 0, sizeof(ms_iocb_entry_t));
  1573. /*
  1574. * Get consistent memory allocated for CT SNS
  1575. * commands
  1576. */
  1577. ha->ct_sns = dma_alloc_coherent(&ha->pdev->dev,
  1578. sizeof(struct ct_sns_pkt), &ha->ct_sns_dma,
  1579. GFP_KERNEL);
  1580. if (ha->ct_sns == NULL) {
  1581. /* error */
  1582. qla_printk(KERN_WARNING, ha,
  1583. "Memory Allocation failed - ct_sns\n");
  1584. qla2x00_mem_free(ha);
  1585. msleep(100);
  1586. continue;
  1587. }
  1588. memset(ha->ct_sns, 0, sizeof(struct ct_sns_pkt));
  1589. }
  1590. /* Done all allocations without any error. */
  1591. status = 0;
  1592. } while (retry-- && status != 0);
  1593. if (status) {
  1594. printk(KERN_WARNING
  1595. "%s(): **** FAILED ****\n", __func__);
  1596. }
  1597. return(status);
  1598. }
  1599. /*
  1600. * qla2x00_mem_free
  1601. * Frees all adapter allocated memory.
  1602. *
  1603. * Input:
  1604. * ha = adapter block pointer.
  1605. */
  1606. static void
  1607. qla2x00_mem_free(scsi_qla_host_t *ha)
  1608. {
  1609. struct list_head *fcpl, *fcptemp;
  1610. fc_port_t *fcport;
  1611. unsigned int wtime;/* max wait time if mbx cmd is busy. */
  1612. if (ha == NULL) {
  1613. /* error */
  1614. DEBUG2(printk("%s(): ERROR invalid ha pointer.\n", __func__));
  1615. return;
  1616. }
  1617. /* Make sure all other threads are stopped. */
  1618. wtime = 60 * 1000;
  1619. while (ha->dpc_wait && wtime)
  1620. wtime = msleep_interruptible(wtime);
  1621. /* free ioctl memory */
  1622. qla2x00_free_ioctl_mem(ha);
  1623. /* free sp pool */
  1624. qla2x00_free_sp_pool(ha);
  1625. if (ha->sns_cmd)
  1626. dma_free_coherent(&ha->pdev->dev, sizeof(struct sns_cmd_pkt),
  1627. ha->sns_cmd, ha->sns_cmd_dma);
  1628. if (ha->ct_sns)
  1629. dma_free_coherent(&ha->pdev->dev, sizeof(struct ct_sns_pkt),
  1630. ha->ct_sns, ha->ct_sns_dma);
  1631. if (ha->ms_iocb)
  1632. dma_pool_free(ha->s_dma_pool, ha->ms_iocb, ha->ms_iocb_dma);
  1633. if (ha->iodesc_pd)
  1634. dma_pool_free(ha->s_dma_pool, ha->iodesc_pd, ha->iodesc_pd_dma);
  1635. if (ha->init_cb)
  1636. dma_pool_free(ha->s_dma_pool, ha->init_cb, ha->init_cb_dma);
  1637. if (ha->s_dma_pool)
  1638. dma_pool_destroy(ha->s_dma_pool);
  1639. if (ha->rlc_rsp)
  1640. dma_free_coherent(&ha->pdev->dev,
  1641. sizeof(rpt_lun_cmd_rsp_t), ha->rlc_rsp,
  1642. ha->rlc_rsp_dma);
  1643. if (ha->gid_list)
  1644. dma_free_coherent(&ha->pdev->dev, GID_LIST_SIZE, ha->gid_list,
  1645. ha->gid_list_dma);
  1646. if (ha->response_ring)
  1647. dma_free_coherent(&ha->pdev->dev,
  1648. (ha->response_q_length + 1) * sizeof(response_t),
  1649. ha->response_ring, ha->response_dma);
  1650. if (ha->request_ring)
  1651. dma_free_coherent(&ha->pdev->dev,
  1652. (ha->request_q_length + 1) * sizeof(request_t),
  1653. ha->request_ring, ha->request_dma);
  1654. ha->sns_cmd = NULL;
  1655. ha->sns_cmd_dma = 0;
  1656. ha->ct_sns = NULL;
  1657. ha->ct_sns_dma = 0;
  1658. ha->ms_iocb = NULL;
  1659. ha->ms_iocb_dma = 0;
  1660. ha->iodesc_pd = NULL;
  1661. ha->iodesc_pd_dma = 0;
  1662. ha->init_cb = NULL;
  1663. ha->init_cb_dma = 0;
  1664. ha->s_dma_pool = NULL;
  1665. ha->rlc_rsp = NULL;
  1666. ha->rlc_rsp_dma = 0;
  1667. ha->gid_list = NULL;
  1668. ha->gid_list_dma = 0;
  1669. ha->response_ring = NULL;
  1670. ha->response_dma = 0;
  1671. ha->request_ring = NULL;
  1672. ha->request_dma = 0;
  1673. list_for_each_safe(fcpl, fcptemp, &ha->fcports) {
  1674. fcport = list_entry(fcpl, fc_port_t, list);
  1675. /* fc ports */
  1676. list_del_init(&fcport->list);
  1677. kfree(fcport);
  1678. }
  1679. INIT_LIST_HEAD(&ha->fcports);
  1680. if (ha->fw_dump)
  1681. free_pages((unsigned long)ha->fw_dump, ha->fw_dump_order);
  1682. vfree(ha->fw_dump24);
  1683. vfree(ha->fw_dump_buffer);
  1684. ha->fw_dump = NULL;
  1685. ha->fw_dump24 = NULL;
  1686. ha->fw_dumped = 0;
  1687. ha->fw_dump_reading = 0;
  1688. ha->fw_dump_buffer = NULL;
  1689. }
  1690. /*
  1691. * qla2x00_allocate_sp_pool
  1692. * This routine is called during initialization to allocate
  1693. * memory for local srb_t.
  1694. *
  1695. * Input:
  1696. * ha = adapter block pointer.
  1697. *
  1698. * Context:
  1699. * Kernel context.
  1700. *
  1701. * Note: Sets the ref_count for non Null sp to one.
  1702. */
  1703. static int
  1704. qla2x00_allocate_sp_pool(scsi_qla_host_t *ha)
  1705. {
  1706. int rval;
  1707. rval = QLA_SUCCESS;
  1708. ha->srb_mempool = mempool_create(SRB_MIN_REQ, mempool_alloc_slab,
  1709. mempool_free_slab, srb_cachep);
  1710. if (ha->srb_mempool == NULL) {
  1711. qla_printk(KERN_INFO, ha, "Unable to allocate SRB mempool.\n");
  1712. rval = QLA_FUNCTION_FAILED;
  1713. }
  1714. return (rval);
  1715. }
  1716. /*
  1717. * This routine frees all adapter allocated memory.
  1718. *
  1719. */
  1720. static void
  1721. qla2x00_free_sp_pool( scsi_qla_host_t *ha)
  1722. {
  1723. if (ha->srb_mempool) {
  1724. mempool_destroy(ha->srb_mempool);
  1725. ha->srb_mempool = NULL;
  1726. }
  1727. }
  1728. /**************************************************************************
  1729. * qla2x00_do_dpc
  1730. * This kernel thread is a task that is schedule by the interrupt handler
  1731. * to perform the background processing for interrupts.
  1732. *
  1733. * Notes:
  1734. * This task always run in the context of a kernel thread. It
  1735. * is kick-off by the driver's detect code and starts up
  1736. * up one per adapter. It immediately goes to sleep and waits for
  1737. * some fibre event. When either the interrupt handler or
  1738. * the timer routine detects a event it will one of the task
  1739. * bits then wake us up.
  1740. **************************************************************************/
  1741. static int
  1742. qla2x00_do_dpc(void *data)
  1743. {
  1744. DECLARE_MUTEX_LOCKED(sem);
  1745. scsi_qla_host_t *ha;
  1746. fc_port_t *fcport;
  1747. uint8_t status;
  1748. uint16_t next_loopid;
  1749. ha = (scsi_qla_host_t *)data;
  1750. lock_kernel();
  1751. daemonize("%s_dpc", ha->host_str);
  1752. allow_signal(SIGHUP);
  1753. ha->dpc_wait = &sem;
  1754. set_user_nice(current, -20);
  1755. unlock_kernel();
  1756. complete(&ha->dpc_inited);
  1757. while (1) {
  1758. DEBUG3(printk("qla2x00: DPC handler sleeping\n"));
  1759. if (down_interruptible(&sem))
  1760. break;
  1761. if (ha->dpc_should_die)
  1762. break;
  1763. DEBUG3(printk("qla2x00: DPC handler waking up\n"));
  1764. /* Initialization not yet finished. Don't do anything yet. */
  1765. if (!ha->flags.init_done || ha->dpc_active)
  1766. continue;
  1767. DEBUG3(printk("scsi(%ld): DPC handler\n", ha->host_no));
  1768. ha->dpc_active = 1;
  1769. if (ha->flags.mbox_busy) {
  1770. ha->dpc_active = 0;
  1771. continue;
  1772. }
  1773. if (test_and_clear_bit(ISP_ABORT_NEEDED, &ha->dpc_flags)) {
  1774. DEBUG(printk("scsi(%ld): dpc: sched "
  1775. "qla2x00_abort_isp ha = %p\n",
  1776. ha->host_no, ha));
  1777. if (!(test_and_set_bit(ABORT_ISP_ACTIVE,
  1778. &ha->dpc_flags))) {
  1779. if (qla2x00_abort_isp(ha)) {
  1780. /* failed. retry later */
  1781. set_bit(ISP_ABORT_NEEDED,
  1782. &ha->dpc_flags);
  1783. }
  1784. clear_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags);
  1785. }
  1786. DEBUG(printk("scsi(%ld): dpc: qla2x00_abort_isp end\n",
  1787. ha->host_no));
  1788. }
  1789. if (test_and_clear_bit(RESET_MARKER_NEEDED, &ha->dpc_flags) &&
  1790. (!(test_and_set_bit(RESET_ACTIVE, &ha->dpc_flags)))) {
  1791. DEBUG(printk("scsi(%ld): qla2x00_reset_marker()\n",
  1792. ha->host_no));
  1793. qla2x00_rst_aen(ha);
  1794. clear_bit(RESET_ACTIVE, &ha->dpc_flags);
  1795. }
  1796. /* Retry each device up to login retry count */
  1797. if ((test_and_clear_bit(RELOGIN_NEEDED, &ha->dpc_flags)) &&
  1798. !test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags) &&
  1799. atomic_read(&ha->loop_state) != LOOP_DOWN) {
  1800. DEBUG(printk("scsi(%ld): qla2x00_port_login()\n",
  1801. ha->host_no));
  1802. next_loopid = 0;
  1803. list_for_each_entry(fcport, &ha->fcports, list) {
  1804. if (fcport->port_type != FCT_TARGET)
  1805. continue;
  1806. /*
  1807. * If the port is not ONLINE then try to login
  1808. * to it if we haven't run out of retries.
  1809. */
  1810. if (atomic_read(&fcport->state) != FCS_ONLINE &&
  1811. fcport->login_retry) {
  1812. fcport->login_retry--;
  1813. if (fcport->flags & FCF_FABRIC_DEVICE) {
  1814. if (fcport->flags &
  1815. FCF_TAPE_PRESENT)
  1816. ha->isp_ops.fabric_logout(
  1817. ha, fcport->loop_id,
  1818. fcport->d_id.b.domain,
  1819. fcport->d_id.b.area,
  1820. fcport->d_id.b.al_pa);
  1821. status = qla2x00_fabric_login(
  1822. ha, fcport, &next_loopid);
  1823. } else
  1824. status =
  1825. qla2x00_local_device_login(
  1826. ha, fcport->loop_id);
  1827. if (status == QLA_SUCCESS) {
  1828. fcport->old_loop_id = fcport->loop_id;
  1829. DEBUG(printk("scsi(%ld): port login OK: logged in ID 0x%x\n",
  1830. ha->host_no, fcport->loop_id));
  1831. fcport->port_login_retry_count =
  1832. ha->port_down_retry_count * PORT_RETRY_TIME;
  1833. atomic_set(&fcport->state, FCS_ONLINE);
  1834. atomic_set(&fcport->port_down_timer,
  1835. ha->port_down_retry_count * PORT_RETRY_TIME);
  1836. fcport->login_retry = 0;
  1837. } else if (status == 1) {
  1838. set_bit(RELOGIN_NEEDED, &ha->dpc_flags);
  1839. /* retry the login again */
  1840. DEBUG(printk("scsi(%ld): Retrying %d login again loop_id 0x%x\n",
  1841. ha->host_no,
  1842. fcport->login_retry, fcport->loop_id));
  1843. } else {
  1844. fcport->login_retry = 0;
  1845. }
  1846. }
  1847. if (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags))
  1848. break;
  1849. }
  1850. DEBUG(printk("scsi(%ld): qla2x00_port_login - end\n",
  1851. ha->host_no));
  1852. }
  1853. if ((test_bit(LOGIN_RETRY_NEEDED, &ha->dpc_flags)) &&
  1854. atomic_read(&ha->loop_state) != LOOP_DOWN) {
  1855. clear_bit(LOGIN_RETRY_NEEDED, &ha->dpc_flags);
  1856. DEBUG(printk("scsi(%ld): qla2x00_login_retry()\n",
  1857. ha->host_no));
  1858. set_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
  1859. DEBUG(printk("scsi(%ld): qla2x00_login_retry - end\n",
  1860. ha->host_no));
  1861. }
  1862. if (test_and_clear_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)) {
  1863. DEBUG(printk("scsi(%ld): qla2x00_loop_resync()\n",
  1864. ha->host_no));
  1865. if (!(test_and_set_bit(LOOP_RESYNC_ACTIVE,
  1866. &ha->dpc_flags))) {
  1867. qla2x00_loop_resync(ha);
  1868. clear_bit(LOOP_RESYNC_ACTIVE, &ha->dpc_flags);
  1869. }
  1870. DEBUG(printk("scsi(%ld): qla2x00_loop_resync - end\n",
  1871. ha->host_no));
  1872. }
  1873. if (test_and_clear_bit(FCPORT_RESCAN_NEEDED, &ha->dpc_flags)) {
  1874. DEBUG(printk("scsi(%ld): Rescan flagged fcports...\n",
  1875. ha->host_no));
  1876. qla2x00_rescan_fcports(ha);
  1877. DEBUG(printk("scsi(%ld): Rescan flagged fcports..."
  1878. "end.\n",
  1879. ha->host_no));
  1880. }
  1881. if (!ha->interrupts_on)
  1882. ha->isp_ops.enable_intrs(ha);
  1883. ha->dpc_active = 0;
  1884. } /* End of while(1) */
  1885. DEBUG(printk("scsi(%ld): DPC handler exiting\n", ha->host_no));
  1886. /*
  1887. * Make sure that nobody tries to wake us up again.
  1888. */
  1889. ha->dpc_wait = NULL;
  1890. ha->dpc_active = 0;
  1891. complete_and_exit(&ha->dpc_exited, 0);
  1892. }
  1893. /*
  1894. * qla2x00_rst_aen
  1895. * Processes asynchronous reset.
  1896. *
  1897. * Input:
  1898. * ha = adapter block pointer.
  1899. */
  1900. static void
  1901. qla2x00_rst_aen(scsi_qla_host_t *ha)
  1902. {
  1903. if (ha->flags.online && !ha->flags.reset_active &&
  1904. !atomic_read(&ha->loop_down_timer) &&
  1905. !(test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags))) {
  1906. do {
  1907. clear_bit(RESET_MARKER_NEEDED, &ha->dpc_flags);
  1908. /*
  1909. * Issue marker command only when we are going to start
  1910. * the I/O.
  1911. */
  1912. ha->marker_needed = 1;
  1913. } while (!atomic_read(&ha->loop_down_timer) &&
  1914. (test_bit(RESET_MARKER_NEEDED, &ha->dpc_flags)));
  1915. }
  1916. }
  1917. static void
  1918. qla2x00_sp_free_dma(scsi_qla_host_t *ha, srb_t *sp)
  1919. {
  1920. struct scsi_cmnd *cmd = sp->cmd;
  1921. if (sp->flags & SRB_DMA_VALID) {
  1922. if (cmd->use_sg) {
  1923. dma_unmap_sg(&ha->pdev->dev, cmd->request_buffer,
  1924. cmd->use_sg, cmd->sc_data_direction);
  1925. } else if (cmd->request_bufflen) {
  1926. dma_unmap_single(&ha->pdev->dev, sp->dma_handle,
  1927. cmd->request_bufflen, cmd->sc_data_direction);
  1928. }
  1929. sp->flags &= ~SRB_DMA_VALID;
  1930. }
  1931. CMD_SP(cmd) = NULL;
  1932. }
  1933. void
  1934. qla2x00_sp_compl(scsi_qla_host_t *ha, srb_t *sp)
  1935. {
  1936. struct scsi_cmnd *cmd = sp->cmd;
  1937. qla2x00_sp_free_dma(ha, sp);
  1938. mempool_free(sp, ha->srb_mempool);
  1939. cmd->scsi_done(cmd);
  1940. }
  1941. /**************************************************************************
  1942. * qla2x00_timer
  1943. *
  1944. * Description:
  1945. * One second timer
  1946. *
  1947. * Context: Interrupt
  1948. ***************************************************************************/
  1949. static void
  1950. qla2x00_timer(scsi_qla_host_t *ha)
  1951. {
  1952. unsigned long cpu_flags = 0;
  1953. fc_port_t *fcport;
  1954. int start_dpc = 0;
  1955. int index;
  1956. srb_t *sp;
  1957. int t;
  1958. /*
  1959. * Ports - Port down timer.
  1960. *
  1961. * Whenever, a port is in the LOST state we start decrementing its port
  1962. * down timer every second until it reaches zero. Once it reaches zero
  1963. * the port it marked DEAD.
  1964. */
  1965. t = 0;
  1966. list_for_each_entry(fcport, &ha->fcports, list) {
  1967. if (fcport->port_type != FCT_TARGET)
  1968. continue;
  1969. if (atomic_read(&fcport->state) == FCS_DEVICE_LOST) {
  1970. if (atomic_read(&fcport->port_down_timer) == 0)
  1971. continue;
  1972. if (atomic_dec_and_test(&fcport->port_down_timer) != 0)
  1973. atomic_set(&fcport->state, FCS_DEVICE_DEAD);
  1974. DEBUG(printk("scsi(%ld): fcport-%d - port retry count: "
  1975. "%d remaining\n",
  1976. ha->host_no,
  1977. t, atomic_read(&fcport->port_down_timer)));
  1978. }
  1979. t++;
  1980. } /* End of for fcport */
  1981. /* Loop down handler. */
  1982. if (atomic_read(&ha->loop_down_timer) > 0 &&
  1983. !(test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags)) && ha->flags.online) {
  1984. if (atomic_read(&ha->loop_down_timer) ==
  1985. ha->loop_down_abort_time) {
  1986. DEBUG(printk("scsi(%ld): Loop Down - aborting the "
  1987. "queues before time expire\n",
  1988. ha->host_no));
  1989. if (!IS_QLA2100(ha) && ha->link_down_timeout)
  1990. atomic_set(&ha->loop_state, LOOP_DEAD);
  1991. /* Schedule an ISP abort to return any tape commands. */
  1992. spin_lock_irqsave(&ha->hardware_lock, cpu_flags);
  1993. for (index = 1; index < MAX_OUTSTANDING_COMMANDS;
  1994. index++) {
  1995. fc_port_t *sfcp;
  1996. sp = ha->outstanding_cmds[index];
  1997. if (!sp)
  1998. continue;
  1999. sfcp = sp->fcport;
  2000. if (!(sfcp->flags & FCF_TAPE_PRESENT))
  2001. continue;
  2002. set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
  2003. break;
  2004. }
  2005. spin_unlock_irqrestore(&ha->hardware_lock, cpu_flags);
  2006. set_bit(ABORT_QUEUES_NEEDED, &ha->dpc_flags);
  2007. start_dpc++;
  2008. }
  2009. /* if the loop has been down for 4 minutes, reinit adapter */
  2010. if (atomic_dec_and_test(&ha->loop_down_timer) != 0) {
  2011. DEBUG(printk("scsi(%ld): Loop down exceed 4 mins - "
  2012. "restarting queues.\n",
  2013. ha->host_no));
  2014. set_bit(RESTART_QUEUES_NEEDED, &ha->dpc_flags);
  2015. start_dpc++;
  2016. if (!(ha->device_flags & DFLG_NO_CABLE)) {
  2017. DEBUG(printk("scsi(%ld): Loop down - "
  2018. "aborting ISP.\n",
  2019. ha->host_no));
  2020. qla_printk(KERN_WARNING, ha,
  2021. "Loop down - aborting ISP.\n");
  2022. set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
  2023. }
  2024. }
  2025. DEBUG3(printk("scsi(%ld): Loop Down - seconds remaining %d\n",
  2026. ha->host_no,
  2027. atomic_read(&ha->loop_down_timer)));
  2028. }
  2029. /* Schedule the DPC routine if needed */
  2030. if ((test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags) ||
  2031. test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags) ||
  2032. start_dpc ||
  2033. test_bit(LOGIN_RETRY_NEEDED, &ha->dpc_flags) ||
  2034. test_bit(RESET_MARKER_NEEDED, &ha->dpc_flags) ||
  2035. test_bit(RELOGIN_NEEDED, &ha->dpc_flags)) &&
  2036. ha->dpc_wait && !ha->dpc_active) {
  2037. up(ha->dpc_wait);
  2038. }
  2039. qla2x00_restart_timer(ha, WATCH_INTERVAL);
  2040. }
  2041. /* XXX(hch): crude hack to emulate a down_timeout() */
  2042. int
  2043. qla2x00_down_timeout(struct semaphore *sema, unsigned long timeout)
  2044. {
  2045. const unsigned int step = 100; /* msecs */
  2046. unsigned int iterations = jiffies_to_msecs(timeout)/100;
  2047. do {
  2048. if (!down_trylock(sema))
  2049. return 0;
  2050. if (msleep_interruptible(step))
  2051. break;
  2052. } while (--iterations >= 0);
  2053. return -ETIMEDOUT;
  2054. }
  2055. static struct qla_board_info qla_board_tbl[] = {
  2056. {
  2057. .drv_name = "qla2400",
  2058. .isp_name = "ISP2422",
  2059. .fw_fname = "ql2400_fw.bin",
  2060. .sht = &qla24xx_driver_template,
  2061. },
  2062. {
  2063. .drv_name = "qla2400",
  2064. .isp_name = "ISP2432",
  2065. .fw_fname = "ql2400_fw.bin",
  2066. .sht = &qla24xx_driver_template,
  2067. },
  2068. };
  2069. static struct pci_device_id qla2xxx_pci_tbl[] = {
  2070. {
  2071. .vendor = PCI_VENDOR_ID_QLOGIC,
  2072. .device = PCI_DEVICE_ID_QLOGIC_ISP2422,
  2073. .subvendor = PCI_ANY_ID,
  2074. .subdevice = PCI_ANY_ID,
  2075. .driver_data = (unsigned long)&qla_board_tbl[0],
  2076. },
  2077. {
  2078. .vendor = PCI_VENDOR_ID_QLOGIC,
  2079. .device = PCI_DEVICE_ID_QLOGIC_ISP2432,
  2080. .subvendor = PCI_ANY_ID,
  2081. .subdevice = PCI_ANY_ID,
  2082. .driver_data = (unsigned long)&qla_board_tbl[1],
  2083. },
  2084. {0, 0},
  2085. };
  2086. MODULE_DEVICE_TABLE(pci, qla2xxx_pci_tbl);
  2087. static int __devinit
  2088. qla2xxx_probe_one(struct pci_dev *pdev, const struct pci_device_id *id)
  2089. {
  2090. return qla2x00_probe_one(pdev,
  2091. (struct qla_board_info *)id->driver_data);
  2092. }
  2093. static void __devexit
  2094. qla2xxx_remove_one(struct pci_dev *pdev)
  2095. {
  2096. qla2x00_remove_one(pdev);
  2097. }
  2098. static struct pci_driver qla2xxx_pci_driver = {
  2099. .name = "qla2xxx",
  2100. .id_table = qla2xxx_pci_tbl,
  2101. .probe = qla2xxx_probe_one,
  2102. .remove = __devexit_p(qla2xxx_remove_one),
  2103. };
  2104. /**
  2105. * qla2x00_module_init - Module initialization.
  2106. **/
  2107. static int __init
  2108. qla2x00_module_init(void)
  2109. {
  2110. int ret = 0;
  2111. /* Allocate cache for SRBs. */
  2112. srb_cachep = kmem_cache_create("qla2xxx_srbs", sizeof(srb_t), 0,
  2113. SLAB_HWCACHE_ALIGN, NULL, NULL);
  2114. if (srb_cachep == NULL) {
  2115. printk(KERN_ERR
  2116. "qla2xxx: Unable to allocate SRB cache...Failing load!\n");
  2117. return -ENOMEM;
  2118. }
  2119. /* Derive version string. */
  2120. strcpy(qla2x00_version_str, QLA2XXX_VERSION);
  2121. #if DEBUG_QLA2100
  2122. strcat(qla2x00_version_str, "-debug");
  2123. #endif
  2124. qla2xxx_transport_template =
  2125. fc_attach_transport(&qla2xxx_transport_functions);
  2126. if (!qla2xxx_transport_template)
  2127. return -ENODEV;
  2128. printk(KERN_INFO "QLogic Fibre Channel HBA Driver\n");
  2129. ret = pci_module_init(&qla2xxx_pci_driver);
  2130. if (ret) {
  2131. kmem_cache_destroy(srb_cachep);
  2132. fc_release_transport(qla2xxx_transport_template);
  2133. }
  2134. return ret;
  2135. }
  2136. /**
  2137. * qla2x00_module_exit - Module cleanup.
  2138. **/
  2139. static void __exit
  2140. qla2x00_module_exit(void)
  2141. {
  2142. pci_unregister_driver(&qla2xxx_pci_driver);
  2143. kmem_cache_destroy(srb_cachep);
  2144. fc_release_transport(qla2xxx_transport_template);
  2145. }
  2146. module_init(qla2x00_module_init);
  2147. module_exit(qla2x00_module_exit);
  2148. MODULE_AUTHOR("QLogic Corporation");
  2149. MODULE_DESCRIPTION("QLogic Fibre Channel HBA Driver");
  2150. MODULE_LICENSE("GPL");
  2151. MODULE_VERSION(QLA2XXX_VERSION);