ql4_os.c 49 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822
  1. /*
  2. * QLogic iSCSI HBA Driver
  3. * Copyright (c) 2003-2006 QLogic Corporation
  4. *
  5. * See LICENSE.qla4xxx for copyright and licensing details.
  6. */
  7. #include <linux/moduleparam.h>
  8. #include <linux/slab.h>
  9. #include <scsi/scsi_tcq.h>
  10. #include <scsi/scsicam.h>
  11. #include "ql4_def.h"
  12. #include "ql4_version.h"
  13. #include "ql4_glbl.h"
  14. #include "ql4_dbg.h"
  15. #include "ql4_inline.h"
  16. /*
  17. * Driver version
  18. */
  19. static char qla4xxx_version_str[40];
  20. /*
  21. * SRB allocation cache
  22. */
  23. static struct kmem_cache *srb_cachep;
  24. /*
  25. * Module parameter information and variables
  26. */
  27. int ql4xdiscoverywait = 60;
  28. module_param(ql4xdiscoverywait, int, S_IRUGO | S_IRUSR);
  29. MODULE_PARM_DESC(ql4xdiscoverywait, "Discovery wait time");
  30. int ql4xdontresethba = 0;
  31. module_param(ql4xdontresethba, int, S_IRUGO | S_IRUSR);
  32. MODULE_PARM_DESC(ql4xdontresethba,
  33. "Dont reset the HBA when the driver gets 0x8002 AEN "
  34. " default it will reset hba :0"
  35. " set to 1 to avoid resetting HBA");
  36. int ql4xextended_error_logging = 0; /* 0 = off, 1 = log errors */
  37. module_param(ql4xextended_error_logging, int, S_IRUGO | S_IRUSR);
  38. MODULE_PARM_DESC(ql4xextended_error_logging,
  39. "Option to enable extended error logging, "
  40. "Default is 0 - no logging, 1 - debug logging");
  41. int ql4_mod_unload = 0;
  42. #define QL4_DEF_QDEPTH 32
  43. /*
  44. * SCSI host template entry points
  45. */
  46. static void qla4xxx_config_dma_addressing(struct scsi_qla_host *ha);
  47. /*
  48. * iSCSI template entry points
  49. */
  50. static int qla4xxx_tgt_dscvr(struct Scsi_Host *shost,
  51. enum iscsi_tgt_dscvr type, uint32_t enable,
  52. struct sockaddr *dst_addr);
  53. static int qla4xxx_conn_get_param(struct iscsi_cls_conn *conn,
  54. enum iscsi_param param, char *buf);
  55. static int qla4xxx_sess_get_param(struct iscsi_cls_session *sess,
  56. enum iscsi_param param, char *buf);
  57. static int qla4xxx_host_get_param(struct Scsi_Host *shost,
  58. enum iscsi_host_param param, char *buf);
  59. static void qla4xxx_recovery_timedout(struct iscsi_cls_session *session);
  60. static enum blk_eh_timer_return qla4xxx_eh_cmd_timed_out(struct scsi_cmnd *sc);
  61. /*
  62. * SCSI host template entry points
  63. */
  64. static int qla4xxx_queuecommand(struct scsi_cmnd *cmd,
  65. void (*done) (struct scsi_cmnd *));
  66. static int qla4xxx_eh_device_reset(struct scsi_cmnd *cmd);
  67. static int qla4xxx_eh_target_reset(struct scsi_cmnd *cmd);
  68. static int qla4xxx_eh_host_reset(struct scsi_cmnd *cmd);
  69. static int qla4xxx_slave_alloc(struct scsi_device *device);
  70. static int qla4xxx_slave_configure(struct scsi_device *device);
  71. static void qla4xxx_slave_destroy(struct scsi_device *sdev);
  72. static void qla4xxx_scan_start(struct Scsi_Host *shost);
  73. static struct scsi_host_template qla4xxx_driver_template = {
  74. .module = THIS_MODULE,
  75. .name = DRIVER_NAME,
  76. .proc_name = DRIVER_NAME,
  77. .queuecommand = qla4xxx_queuecommand,
  78. .eh_device_reset_handler = qla4xxx_eh_device_reset,
  79. .eh_target_reset_handler = qla4xxx_eh_target_reset,
  80. .eh_host_reset_handler = qla4xxx_eh_host_reset,
  81. .eh_timed_out = qla4xxx_eh_cmd_timed_out,
  82. .slave_configure = qla4xxx_slave_configure,
  83. .slave_alloc = qla4xxx_slave_alloc,
  84. .slave_destroy = qla4xxx_slave_destroy,
  85. .scan_finished = iscsi_scan_finished,
  86. .scan_start = qla4xxx_scan_start,
  87. .this_id = -1,
  88. .cmd_per_lun = 3,
  89. .use_clustering = ENABLE_CLUSTERING,
  90. .sg_tablesize = SG_ALL,
  91. .max_sectors = 0xFFFF,
  92. };
  93. static struct iscsi_transport qla4xxx_iscsi_transport = {
  94. .owner = THIS_MODULE,
  95. .name = DRIVER_NAME,
  96. .caps = CAP_FW_DB | CAP_SENDTARGETS_OFFLOAD |
  97. CAP_DATA_PATH_OFFLOAD,
  98. .param_mask = ISCSI_CONN_PORT | ISCSI_CONN_ADDRESS |
  99. ISCSI_TARGET_NAME | ISCSI_TPGT,
  100. .host_param_mask = ISCSI_HOST_HWADDRESS |
  101. ISCSI_HOST_IPADDRESS |
  102. ISCSI_HOST_INITIATOR_NAME,
  103. .tgt_dscvr = qla4xxx_tgt_dscvr,
  104. .get_conn_param = qla4xxx_conn_get_param,
  105. .get_session_param = qla4xxx_sess_get_param,
  106. .get_host_param = qla4xxx_host_get_param,
  107. .session_recovery_timedout = qla4xxx_recovery_timedout,
  108. };
  109. static struct scsi_transport_template *qla4xxx_scsi_transport;
  110. static enum blk_eh_timer_return qla4xxx_eh_cmd_timed_out(struct scsi_cmnd *sc)
  111. {
  112. struct iscsi_cls_session *session;
  113. struct ddb_entry *ddb_entry;
  114. session = starget_to_session(scsi_target(sc->device));
  115. ddb_entry = session->dd_data;
  116. /* if we are not logged in then the LLD is going to clean up the cmd */
  117. if (atomic_read(&ddb_entry->state) != DDB_STATE_ONLINE)
  118. return BLK_EH_RESET_TIMER;
  119. else
  120. return BLK_EH_NOT_HANDLED;
  121. }
  122. static void qla4xxx_recovery_timedout(struct iscsi_cls_session *session)
  123. {
  124. struct ddb_entry *ddb_entry = session->dd_data;
  125. struct scsi_qla_host *ha = ddb_entry->ha;
  126. if (atomic_read(&ddb_entry->state) != DDB_STATE_ONLINE) {
  127. atomic_set(&ddb_entry->state, DDB_STATE_DEAD);
  128. DEBUG2(printk("scsi%ld: %s: index [%d] port down retry count "
  129. "of (%d) secs exhausted, marking device DEAD.\n",
  130. ha->host_no, __func__, ddb_entry->fw_ddb_index,
  131. ha->port_down_retry_count));
  132. DEBUG2(printk("scsi%ld: %s: scheduling dpc routine - dpc "
  133. "flags = 0x%lx\n",
  134. ha->host_no, __func__, ha->dpc_flags));
  135. queue_work(ha->dpc_thread, &ha->dpc_work);
  136. }
  137. }
  138. static int qla4xxx_host_get_param(struct Scsi_Host *shost,
  139. enum iscsi_host_param param, char *buf)
  140. {
  141. struct scsi_qla_host *ha = to_qla_host(shost);
  142. int len;
  143. switch (param) {
  144. case ISCSI_HOST_PARAM_HWADDRESS:
  145. len = sysfs_format_mac(buf, ha->my_mac, MAC_ADDR_LEN);
  146. break;
  147. case ISCSI_HOST_PARAM_IPADDRESS:
  148. len = sprintf(buf, "%d.%d.%d.%d\n", ha->ip_address[0],
  149. ha->ip_address[1], ha->ip_address[2],
  150. ha->ip_address[3]);
  151. break;
  152. case ISCSI_HOST_PARAM_INITIATOR_NAME:
  153. len = sprintf(buf, "%s\n", ha->name_string);
  154. break;
  155. default:
  156. return -ENOSYS;
  157. }
  158. return len;
  159. }
  160. static int qla4xxx_sess_get_param(struct iscsi_cls_session *sess,
  161. enum iscsi_param param, char *buf)
  162. {
  163. struct ddb_entry *ddb_entry = sess->dd_data;
  164. int len;
  165. switch (param) {
  166. case ISCSI_PARAM_TARGET_NAME:
  167. len = snprintf(buf, PAGE_SIZE - 1, "%s\n",
  168. ddb_entry->iscsi_name);
  169. break;
  170. case ISCSI_PARAM_TPGT:
  171. len = sprintf(buf, "%u\n", ddb_entry->tpgt);
  172. break;
  173. default:
  174. return -ENOSYS;
  175. }
  176. return len;
  177. }
  178. static int qla4xxx_conn_get_param(struct iscsi_cls_conn *conn,
  179. enum iscsi_param param, char *buf)
  180. {
  181. struct iscsi_cls_session *session;
  182. struct ddb_entry *ddb_entry;
  183. int len;
  184. session = iscsi_dev_to_session(conn->dev.parent);
  185. ddb_entry = session->dd_data;
  186. switch (param) {
  187. case ISCSI_PARAM_CONN_PORT:
  188. len = sprintf(buf, "%hu\n", ddb_entry->port);
  189. break;
  190. case ISCSI_PARAM_CONN_ADDRESS:
  191. /* TODO: what are the ipv6 bits */
  192. len = sprintf(buf, "%pI4\n", &ddb_entry->ip_addr);
  193. break;
  194. default:
  195. return -ENOSYS;
  196. }
  197. return len;
  198. }
  199. static int qla4xxx_tgt_dscvr(struct Scsi_Host *shost,
  200. enum iscsi_tgt_dscvr type, uint32_t enable,
  201. struct sockaddr *dst_addr)
  202. {
  203. struct scsi_qla_host *ha;
  204. struct sockaddr_in *addr;
  205. struct sockaddr_in6 *addr6;
  206. int ret = 0;
  207. ha = (struct scsi_qla_host *) shost->hostdata;
  208. switch (type) {
  209. case ISCSI_TGT_DSCVR_SEND_TARGETS:
  210. if (dst_addr->sa_family == AF_INET) {
  211. addr = (struct sockaddr_in *)dst_addr;
  212. if (qla4xxx_send_tgts(ha, (char *)&addr->sin_addr,
  213. addr->sin_port) != QLA_SUCCESS)
  214. ret = -EIO;
  215. } else if (dst_addr->sa_family == AF_INET6) {
  216. /*
  217. * TODO: fix qla4xxx_send_tgts
  218. */
  219. addr6 = (struct sockaddr_in6 *)dst_addr;
  220. if (qla4xxx_send_tgts(ha, (char *)&addr6->sin6_addr,
  221. addr6->sin6_port) != QLA_SUCCESS)
  222. ret = -EIO;
  223. } else
  224. ret = -ENOSYS;
  225. break;
  226. default:
  227. ret = -ENOSYS;
  228. }
  229. return ret;
  230. }
  231. void qla4xxx_destroy_sess(struct ddb_entry *ddb_entry)
  232. {
  233. if (!ddb_entry->sess)
  234. return;
  235. if (ddb_entry->conn) {
  236. atomic_set(&ddb_entry->state, DDB_STATE_DEAD);
  237. iscsi_remove_session(ddb_entry->sess);
  238. }
  239. iscsi_free_session(ddb_entry->sess);
  240. }
  241. int qla4xxx_add_sess(struct ddb_entry *ddb_entry)
  242. {
  243. int err;
  244. ddb_entry->sess->recovery_tmo = ddb_entry->ha->port_down_retry_count;
  245. err = iscsi_add_session(ddb_entry->sess, ddb_entry->fw_ddb_index);
  246. if (err) {
  247. DEBUG2(printk(KERN_ERR "Could not add session.\n"));
  248. return err;
  249. }
  250. ddb_entry->conn = iscsi_create_conn(ddb_entry->sess, 0, 0);
  251. if (!ddb_entry->conn) {
  252. iscsi_remove_session(ddb_entry->sess);
  253. DEBUG2(printk(KERN_ERR "Could not add connection.\n"));
  254. return -ENOMEM;
  255. }
  256. /* finally ready to go */
  257. iscsi_unblock_session(ddb_entry->sess);
  258. return 0;
  259. }
  260. struct ddb_entry *qla4xxx_alloc_sess(struct scsi_qla_host *ha)
  261. {
  262. struct ddb_entry *ddb_entry;
  263. struct iscsi_cls_session *sess;
  264. sess = iscsi_alloc_session(ha->host, &qla4xxx_iscsi_transport,
  265. sizeof(struct ddb_entry));
  266. if (!sess)
  267. return NULL;
  268. ddb_entry = sess->dd_data;
  269. memset(ddb_entry, 0, sizeof(*ddb_entry));
  270. ddb_entry->ha = ha;
  271. ddb_entry->sess = sess;
  272. return ddb_entry;
  273. }
  274. static void qla4xxx_scan_start(struct Scsi_Host *shost)
  275. {
  276. struct scsi_qla_host *ha = shost_priv(shost);
  277. struct ddb_entry *ddb_entry, *ddbtemp;
  278. /* finish setup of sessions that were already setup in firmware */
  279. list_for_each_entry_safe(ddb_entry, ddbtemp, &ha->ddb_list, list) {
  280. if (ddb_entry->fw_ddb_device_state == DDB_DS_SESSION_ACTIVE)
  281. qla4xxx_add_sess(ddb_entry);
  282. }
  283. }
  284. /*
  285. * Timer routines
  286. */
  287. static void qla4xxx_start_timer(struct scsi_qla_host *ha, void *func,
  288. unsigned long interval)
  289. {
  290. DEBUG(printk("scsi: %s: Starting timer thread for adapter %d\n",
  291. __func__, ha->host->host_no));
  292. init_timer(&ha->timer);
  293. ha->timer.expires = jiffies + interval * HZ;
  294. ha->timer.data = (unsigned long)ha;
  295. ha->timer.function = (void (*)(unsigned long))func;
  296. add_timer(&ha->timer);
  297. ha->timer_active = 1;
  298. }
  299. static void qla4xxx_stop_timer(struct scsi_qla_host *ha)
  300. {
  301. del_timer_sync(&ha->timer);
  302. ha->timer_active = 0;
  303. }
  304. /***
  305. * qla4xxx_mark_device_missing - mark a device as missing.
  306. * @ha: Pointer to host adapter structure.
  307. * @ddb_entry: Pointer to device database entry
  308. *
  309. * This routine marks a device missing and resets the relogin retry count.
  310. **/
  311. void qla4xxx_mark_device_missing(struct scsi_qla_host *ha,
  312. struct ddb_entry *ddb_entry)
  313. {
  314. atomic_set(&ddb_entry->state, DDB_STATE_MISSING);
  315. DEBUG3(printk("scsi%d:%d:%d: index [%d] marked MISSING\n",
  316. ha->host_no, ddb_entry->bus, ddb_entry->target,
  317. ddb_entry->fw_ddb_index));
  318. iscsi_block_session(ddb_entry->sess);
  319. iscsi_conn_error_event(ddb_entry->conn, ISCSI_ERR_CONN_FAILED);
  320. }
  321. static struct srb* qla4xxx_get_new_srb(struct scsi_qla_host *ha,
  322. struct ddb_entry *ddb_entry,
  323. struct scsi_cmnd *cmd,
  324. void (*done)(struct scsi_cmnd *))
  325. {
  326. struct srb *srb;
  327. srb = mempool_alloc(ha->srb_mempool, GFP_ATOMIC);
  328. if (!srb)
  329. return srb;
  330. atomic_set(&srb->ref_count, 1);
  331. srb->ha = ha;
  332. srb->ddb = ddb_entry;
  333. srb->cmd = cmd;
  334. srb->flags = 0;
  335. cmd->SCp.ptr = (void *)srb;
  336. cmd->scsi_done = done;
  337. return srb;
  338. }
  339. static void qla4xxx_srb_free_dma(struct scsi_qla_host *ha, struct srb *srb)
  340. {
  341. struct scsi_cmnd *cmd = srb->cmd;
  342. if (srb->flags & SRB_DMA_VALID) {
  343. scsi_dma_unmap(cmd);
  344. srb->flags &= ~SRB_DMA_VALID;
  345. }
  346. cmd->SCp.ptr = NULL;
  347. }
  348. void qla4xxx_srb_compl(struct scsi_qla_host *ha, struct srb *srb)
  349. {
  350. struct scsi_cmnd *cmd = srb->cmd;
  351. qla4xxx_srb_free_dma(ha, srb);
  352. mempool_free(srb, ha->srb_mempool);
  353. cmd->scsi_done(cmd);
  354. }
  355. /**
  356. * qla4xxx_queuecommand - scsi layer issues scsi command to driver.
  357. * @cmd: Pointer to Linux's SCSI command structure
  358. * @done_fn: Function that the driver calls to notify the SCSI mid-layer
  359. * that the command has been processed.
  360. *
  361. * Remarks:
  362. * This routine is invoked by Linux to send a SCSI command to the driver.
  363. * The mid-level driver tries to ensure that queuecommand never gets
  364. * invoked concurrently with itself or the interrupt handler (although
  365. * the interrupt handler may call this routine as part of request-
  366. * completion handling). Unfortunely, it sometimes calls the scheduler
  367. * in interrupt context which is a big NO! NO!.
  368. **/
  369. static int qla4xxx_queuecommand(struct scsi_cmnd *cmd,
  370. void (*done)(struct scsi_cmnd *))
  371. {
  372. struct scsi_qla_host *ha = to_qla_host(cmd->device->host);
  373. struct ddb_entry *ddb_entry = cmd->device->hostdata;
  374. struct iscsi_cls_session *sess = ddb_entry->sess;
  375. struct srb *srb;
  376. int rval;
  377. if (!sess) {
  378. cmd->result = DID_IMM_RETRY << 16;
  379. goto qc_fail_command;
  380. }
  381. rval = iscsi_session_chkready(sess);
  382. if (rval) {
  383. cmd->result = rval;
  384. goto qc_fail_command;
  385. }
  386. if (atomic_read(&ddb_entry->state) != DDB_STATE_ONLINE) {
  387. if (atomic_read(&ddb_entry->state) == DDB_STATE_DEAD) {
  388. cmd->result = DID_NO_CONNECT << 16;
  389. goto qc_fail_command;
  390. }
  391. return SCSI_MLQUEUE_TARGET_BUSY;
  392. }
  393. if (test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags))
  394. goto qc_host_busy;
  395. spin_unlock_irq(ha->host->host_lock);
  396. srb = qla4xxx_get_new_srb(ha, ddb_entry, cmd, done);
  397. if (!srb)
  398. goto qc_host_busy_lock;
  399. rval = qla4xxx_send_command_to_isp(ha, srb);
  400. if (rval != QLA_SUCCESS)
  401. goto qc_host_busy_free_sp;
  402. spin_lock_irq(ha->host->host_lock);
  403. return 0;
  404. qc_host_busy_free_sp:
  405. qla4xxx_srb_free_dma(ha, srb);
  406. mempool_free(srb, ha->srb_mempool);
  407. qc_host_busy_lock:
  408. spin_lock_irq(ha->host->host_lock);
  409. qc_host_busy:
  410. return SCSI_MLQUEUE_HOST_BUSY;
  411. qc_fail_command:
  412. done(cmd);
  413. return 0;
  414. }
  415. /**
  416. * qla4xxx_mem_free - frees memory allocated to adapter
  417. * @ha: Pointer to host adapter structure.
  418. *
  419. * Frees memory previously allocated by qla4xxx_mem_alloc
  420. **/
  421. static void qla4xxx_mem_free(struct scsi_qla_host *ha)
  422. {
  423. if (ha->queues)
  424. dma_free_coherent(&ha->pdev->dev, ha->queues_len, ha->queues,
  425. ha->queues_dma);
  426. ha->queues_len = 0;
  427. ha->queues = NULL;
  428. ha->queues_dma = 0;
  429. ha->request_ring = NULL;
  430. ha->request_dma = 0;
  431. ha->response_ring = NULL;
  432. ha->response_dma = 0;
  433. ha->shadow_regs = NULL;
  434. ha->shadow_regs_dma = 0;
  435. /* Free srb pool. */
  436. if (ha->srb_mempool)
  437. mempool_destroy(ha->srb_mempool);
  438. ha->srb_mempool = NULL;
  439. /* release io space registers */
  440. if (ha->reg)
  441. iounmap(ha->reg);
  442. pci_release_regions(ha->pdev);
  443. }
  444. /**
  445. * qla4xxx_mem_alloc - allocates memory for use by adapter.
  446. * @ha: Pointer to host adapter structure
  447. *
  448. * Allocates DMA memory for request and response queues. Also allocates memory
  449. * for srbs.
  450. **/
  451. static int qla4xxx_mem_alloc(struct scsi_qla_host *ha)
  452. {
  453. unsigned long align;
  454. /* Allocate contiguous block of DMA memory for queues. */
  455. ha->queues_len = ((REQUEST_QUEUE_DEPTH * QUEUE_SIZE) +
  456. (RESPONSE_QUEUE_DEPTH * QUEUE_SIZE) +
  457. sizeof(struct shadow_regs) +
  458. MEM_ALIGN_VALUE +
  459. (PAGE_SIZE - 1)) & ~(PAGE_SIZE - 1);
  460. ha->queues = dma_alloc_coherent(&ha->pdev->dev, ha->queues_len,
  461. &ha->queues_dma, GFP_KERNEL);
  462. if (ha->queues == NULL) {
  463. dev_warn(&ha->pdev->dev,
  464. "Memory Allocation failed - queues.\n");
  465. goto mem_alloc_error_exit;
  466. }
  467. memset(ha->queues, 0, ha->queues_len);
  468. /*
  469. * As per RISC alignment requirements -- the bus-address must be a
  470. * multiple of the request-ring size (in bytes).
  471. */
  472. align = 0;
  473. if ((unsigned long)ha->queues_dma & (MEM_ALIGN_VALUE - 1))
  474. align = MEM_ALIGN_VALUE - ((unsigned long)ha->queues_dma &
  475. (MEM_ALIGN_VALUE - 1));
  476. /* Update request and response queue pointers. */
  477. ha->request_dma = ha->queues_dma + align;
  478. ha->request_ring = (struct queue_entry *) (ha->queues + align);
  479. ha->response_dma = ha->queues_dma + align +
  480. (REQUEST_QUEUE_DEPTH * QUEUE_SIZE);
  481. ha->response_ring = (struct queue_entry *) (ha->queues + align +
  482. (REQUEST_QUEUE_DEPTH *
  483. QUEUE_SIZE));
  484. ha->shadow_regs_dma = ha->queues_dma + align +
  485. (REQUEST_QUEUE_DEPTH * QUEUE_SIZE) +
  486. (RESPONSE_QUEUE_DEPTH * QUEUE_SIZE);
  487. ha->shadow_regs = (struct shadow_regs *) (ha->queues + align +
  488. (REQUEST_QUEUE_DEPTH *
  489. QUEUE_SIZE) +
  490. (RESPONSE_QUEUE_DEPTH *
  491. QUEUE_SIZE));
  492. /* Allocate memory for srb pool. */
  493. ha->srb_mempool = mempool_create(SRB_MIN_REQ, mempool_alloc_slab,
  494. mempool_free_slab, srb_cachep);
  495. if (ha->srb_mempool == NULL) {
  496. dev_warn(&ha->pdev->dev,
  497. "Memory Allocation failed - SRB Pool.\n");
  498. goto mem_alloc_error_exit;
  499. }
  500. return QLA_SUCCESS;
  501. mem_alloc_error_exit:
  502. qla4xxx_mem_free(ha);
  503. return QLA_ERROR;
  504. }
  505. /**
  506. * qla4xxx_timer - checks every second for work to do.
  507. * @ha: Pointer to host adapter structure.
  508. **/
  509. static void qla4xxx_timer(struct scsi_qla_host *ha)
  510. {
  511. struct ddb_entry *ddb_entry, *dtemp;
  512. int start_dpc = 0;
  513. /* Search for relogin's to time-out and port down retry. */
  514. list_for_each_entry_safe(ddb_entry, dtemp, &ha->ddb_list, list) {
  515. /* Count down time between sending relogins */
  516. if (adapter_up(ha) &&
  517. !test_bit(DF_RELOGIN, &ddb_entry->flags) &&
  518. atomic_read(&ddb_entry->state) != DDB_STATE_ONLINE) {
  519. if (atomic_read(&ddb_entry->retry_relogin_timer) !=
  520. INVALID_ENTRY) {
  521. if (atomic_read(&ddb_entry->retry_relogin_timer)
  522. == 0) {
  523. atomic_set(&ddb_entry->
  524. retry_relogin_timer,
  525. INVALID_ENTRY);
  526. set_bit(DPC_RELOGIN_DEVICE,
  527. &ha->dpc_flags);
  528. set_bit(DF_RELOGIN, &ddb_entry->flags);
  529. DEBUG2(printk("scsi%ld: %s: index [%d]"
  530. " login device\n",
  531. ha->host_no, __func__,
  532. ddb_entry->fw_ddb_index));
  533. } else
  534. atomic_dec(&ddb_entry->
  535. retry_relogin_timer);
  536. }
  537. }
  538. /* Wait for relogin to timeout */
  539. if (atomic_read(&ddb_entry->relogin_timer) &&
  540. (atomic_dec_and_test(&ddb_entry->relogin_timer) != 0)) {
  541. /*
  542. * If the relogin times out and the device is
  543. * still NOT ONLINE then try and relogin again.
  544. */
  545. if (atomic_read(&ddb_entry->state) !=
  546. DDB_STATE_ONLINE &&
  547. ddb_entry->fw_ddb_device_state ==
  548. DDB_DS_SESSION_FAILED) {
  549. /* Reset retry relogin timer */
  550. atomic_inc(&ddb_entry->relogin_retry_count);
  551. DEBUG2(printk("scsi%ld: index[%d] relogin"
  552. " timed out-retrying"
  553. " relogin (%d)\n",
  554. ha->host_no,
  555. ddb_entry->fw_ddb_index,
  556. atomic_read(&ddb_entry->
  557. relogin_retry_count))
  558. );
  559. start_dpc++;
  560. DEBUG(printk("scsi%ld:%d:%d: index [%d] "
  561. "initate relogin after"
  562. " %d seconds\n",
  563. ha->host_no, ddb_entry->bus,
  564. ddb_entry->target,
  565. ddb_entry->fw_ddb_index,
  566. ddb_entry->default_time2wait + 4)
  567. );
  568. atomic_set(&ddb_entry->retry_relogin_timer,
  569. ddb_entry->default_time2wait + 4);
  570. }
  571. }
  572. }
  573. /* Check for heartbeat interval. */
  574. if (ha->firmware_options & FWOPT_HEARTBEAT_ENABLE &&
  575. ha->heartbeat_interval != 0) {
  576. ha->seconds_since_last_heartbeat++;
  577. if (ha->seconds_since_last_heartbeat >
  578. ha->heartbeat_interval + 2)
  579. set_bit(DPC_RESET_HA, &ha->dpc_flags);
  580. }
  581. /* Wakeup the dpc routine for this adapter, if needed. */
  582. if ((start_dpc ||
  583. test_bit(DPC_RESET_HA, &ha->dpc_flags) ||
  584. test_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags) ||
  585. test_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags) ||
  586. test_bit(DPC_RESET_HA_DESTROY_DDB_LIST, &ha->dpc_flags) ||
  587. test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags) ||
  588. test_bit(DPC_GET_DHCP_IP_ADDR, &ha->dpc_flags) ||
  589. test_bit(DPC_LINK_CHANGED, &ha->dpc_flags) ||
  590. test_bit(DPC_AEN, &ha->dpc_flags)) &&
  591. ha->dpc_thread) {
  592. DEBUG2(printk("scsi%ld: %s: scheduling dpc routine"
  593. " - dpc flags = 0x%lx\n",
  594. ha->host_no, __func__, ha->dpc_flags));
  595. queue_work(ha->dpc_thread, &ha->dpc_work);
  596. }
  597. /* Reschedule timer thread to call us back in one second */
  598. mod_timer(&ha->timer, jiffies + HZ);
  599. DEBUG2(ha->seconds_since_last_intr++);
  600. }
  601. /**
  602. * qla4xxx_cmd_wait - waits for all outstanding commands to complete
  603. * @ha: Pointer to host adapter structure.
  604. *
  605. * This routine stalls the driver until all outstanding commands are returned.
  606. * Caller must release the Hardware Lock prior to calling this routine.
  607. **/
  608. static int qla4xxx_cmd_wait(struct scsi_qla_host *ha)
  609. {
  610. uint32_t index = 0;
  611. int stat = QLA_SUCCESS;
  612. unsigned long flags;
  613. struct scsi_cmnd *cmd;
  614. int wait_cnt = WAIT_CMD_TOV; /*
  615. * Initialized for 30 seconds as we
  616. * expect all commands to retuned
  617. * ASAP.
  618. */
  619. while (wait_cnt) {
  620. spin_lock_irqsave(&ha->hardware_lock, flags);
  621. /* Find a command that hasn't completed. */
  622. for (index = 0; index < ha->host->can_queue; index++) {
  623. cmd = scsi_host_find_tag(ha->host, index);
  624. if (cmd != NULL)
  625. break;
  626. }
  627. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  628. /* If No Commands are pending, wait is complete */
  629. if (index == ha->host->can_queue) {
  630. break;
  631. }
  632. /* If we timed out on waiting for commands to come back
  633. * return ERROR.
  634. */
  635. wait_cnt--;
  636. if (wait_cnt == 0)
  637. stat = QLA_ERROR;
  638. else {
  639. msleep(1000);
  640. }
  641. } /* End of While (wait_cnt) */
  642. return stat;
  643. }
  644. void qla4xxx_hw_reset(struct scsi_qla_host *ha)
  645. {
  646. uint32_t ctrl_status;
  647. unsigned long flags = 0;
  648. DEBUG2(printk(KERN_ERR "scsi%ld: %s\n", ha->host_no, __func__));
  649. spin_lock_irqsave(&ha->hardware_lock, flags);
  650. /*
  651. * If the SCSI Reset Interrupt bit is set, clear it.
  652. * Otherwise, the Soft Reset won't work.
  653. */
  654. ctrl_status = readw(&ha->reg->ctrl_status);
  655. if ((ctrl_status & CSR_SCSI_RESET_INTR) != 0)
  656. writel(set_rmask(CSR_SCSI_RESET_INTR), &ha->reg->ctrl_status);
  657. /* Issue Soft Reset */
  658. writel(set_rmask(CSR_SOFT_RESET), &ha->reg->ctrl_status);
  659. readl(&ha->reg->ctrl_status);
  660. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  661. }
  662. /**
  663. * qla4xxx_soft_reset - performs soft reset.
  664. * @ha: Pointer to host adapter structure.
  665. **/
  666. int qla4xxx_soft_reset(struct scsi_qla_host *ha)
  667. {
  668. uint32_t max_wait_time;
  669. unsigned long flags = 0;
  670. int status = QLA_ERROR;
  671. uint32_t ctrl_status;
  672. qla4xxx_hw_reset(ha);
  673. /* Wait until the Network Reset Intr bit is cleared */
  674. max_wait_time = RESET_INTR_TOV;
  675. do {
  676. spin_lock_irqsave(&ha->hardware_lock, flags);
  677. ctrl_status = readw(&ha->reg->ctrl_status);
  678. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  679. if ((ctrl_status & CSR_NET_RESET_INTR) == 0)
  680. break;
  681. msleep(1000);
  682. } while ((--max_wait_time));
  683. if ((ctrl_status & CSR_NET_RESET_INTR) != 0) {
  684. DEBUG2(printk(KERN_WARNING
  685. "scsi%ld: Network Reset Intr not cleared by "
  686. "Network function, clearing it now!\n",
  687. ha->host_no));
  688. spin_lock_irqsave(&ha->hardware_lock, flags);
  689. writel(set_rmask(CSR_NET_RESET_INTR), &ha->reg->ctrl_status);
  690. readl(&ha->reg->ctrl_status);
  691. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  692. }
  693. /* Wait until the firmware tells us the Soft Reset is done */
  694. max_wait_time = SOFT_RESET_TOV;
  695. do {
  696. spin_lock_irqsave(&ha->hardware_lock, flags);
  697. ctrl_status = readw(&ha->reg->ctrl_status);
  698. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  699. if ((ctrl_status & CSR_SOFT_RESET) == 0) {
  700. status = QLA_SUCCESS;
  701. break;
  702. }
  703. msleep(1000);
  704. } while ((--max_wait_time));
  705. /*
  706. * Also, make sure that the SCSI Reset Interrupt bit has been cleared
  707. * after the soft reset has taken place.
  708. */
  709. spin_lock_irqsave(&ha->hardware_lock, flags);
  710. ctrl_status = readw(&ha->reg->ctrl_status);
  711. if ((ctrl_status & CSR_SCSI_RESET_INTR) != 0) {
  712. writel(set_rmask(CSR_SCSI_RESET_INTR), &ha->reg->ctrl_status);
  713. readl(&ha->reg->ctrl_status);
  714. }
  715. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  716. /* If soft reset fails then most probably the bios on other
  717. * function is also enabled.
  718. * Since the initialization is sequential the other fn
  719. * wont be able to acknowledge the soft reset.
  720. * Issue a force soft reset to workaround this scenario.
  721. */
  722. if (max_wait_time == 0) {
  723. /* Issue Force Soft Reset */
  724. spin_lock_irqsave(&ha->hardware_lock, flags);
  725. writel(set_rmask(CSR_FORCE_SOFT_RESET), &ha->reg->ctrl_status);
  726. readl(&ha->reg->ctrl_status);
  727. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  728. /* Wait until the firmware tells us the Soft Reset is done */
  729. max_wait_time = SOFT_RESET_TOV;
  730. do {
  731. spin_lock_irqsave(&ha->hardware_lock, flags);
  732. ctrl_status = readw(&ha->reg->ctrl_status);
  733. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  734. if ((ctrl_status & CSR_FORCE_SOFT_RESET) == 0) {
  735. status = QLA_SUCCESS;
  736. break;
  737. }
  738. msleep(1000);
  739. } while ((--max_wait_time));
  740. }
  741. return status;
  742. }
  743. /**
  744. * qla4xxx_flush_active_srbs - returns all outstanding i/o requests to O.S.
  745. * @ha: Pointer to host adapter structure.
  746. *
  747. * This routine is called just prior to a HARD RESET to return all
  748. * outstanding commands back to the Operating System.
  749. * Caller should make sure that the following locks are released
  750. * before this calling routine: Hardware lock, and io_request_lock.
  751. **/
  752. static void qla4xxx_flush_active_srbs(struct scsi_qla_host *ha)
  753. {
  754. struct srb *srb;
  755. int i;
  756. unsigned long flags;
  757. spin_lock_irqsave(&ha->hardware_lock, flags);
  758. for (i = 0; i < ha->host->can_queue; i++) {
  759. srb = qla4xxx_del_from_active_array(ha, i);
  760. if (srb != NULL) {
  761. srb->cmd->result = DID_RESET << 16;
  762. qla4xxx_srb_compl(ha, srb);
  763. }
  764. }
  765. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  766. }
  767. /**
  768. * qla4xxx_recover_adapter - recovers adapter after a fatal error
  769. * @ha: Pointer to host adapter structure.
  770. * @renew_ddb_list: Indicates what to do with the adapter's ddb list
  771. *
  772. * renew_ddb_list value can be 0=preserve ddb list, 1=destroy and rebuild
  773. * ddb list.
  774. **/
  775. static int qla4xxx_recover_adapter(struct scsi_qla_host *ha,
  776. uint8_t renew_ddb_list)
  777. {
  778. int status;
  779. /* Stall incoming I/O until we are done */
  780. clear_bit(AF_ONLINE, &ha->flags);
  781. DEBUG2(printk("scsi%ld: %s calling qla4xxx_cmd_wait\n", ha->host_no,
  782. __func__));
  783. /* Wait for outstanding commands to complete.
  784. * Stalls the driver for max 30 secs
  785. */
  786. status = qla4xxx_cmd_wait(ha);
  787. qla4xxx_disable_intrs(ha);
  788. /* Flush any pending ddb changed AENs */
  789. qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
  790. qla4xxx_flush_active_srbs(ha);
  791. /* Reset the firmware. If successful, function
  792. * returns with ISP interrupts enabled.
  793. */
  794. DEBUG2(printk("scsi%ld: %s - Performing soft reset..\n",
  795. ha->host_no, __func__));
  796. if (ql4xxx_lock_drvr_wait(ha) == QLA_SUCCESS)
  797. status = qla4xxx_soft_reset(ha);
  798. else
  799. status = QLA_ERROR;
  800. /* Flush any pending ddb changed AENs */
  801. qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
  802. /* Re-initialize firmware. If successful, function returns
  803. * with ISP interrupts enabled */
  804. if (status == QLA_SUCCESS) {
  805. DEBUG2(printk("scsi%ld: %s - Initializing adapter..\n",
  806. ha->host_no, __func__));
  807. /* If successful, AF_ONLINE flag set in
  808. * qla4xxx_initialize_adapter */
  809. status = qla4xxx_initialize_adapter(ha, renew_ddb_list);
  810. }
  811. /* Failed adapter initialization?
  812. * Retry reset_ha only if invoked via DPC (DPC_RESET_HA) */
  813. if ((test_bit(AF_ONLINE, &ha->flags) == 0) &&
  814. (test_bit(DPC_RESET_HA, &ha->dpc_flags))) {
  815. /* Adapter initialization failed, see if we can retry
  816. * resetting the ha */
  817. if (!test_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags)) {
  818. ha->retry_reset_ha_cnt = MAX_RESET_HA_RETRIES;
  819. DEBUG2(printk("scsi%ld: recover adapter - retrying "
  820. "(%d) more times\n", ha->host_no,
  821. ha->retry_reset_ha_cnt));
  822. set_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags);
  823. status = QLA_ERROR;
  824. } else {
  825. if (ha->retry_reset_ha_cnt > 0) {
  826. /* Schedule another Reset HA--DPC will retry */
  827. ha->retry_reset_ha_cnt--;
  828. DEBUG2(printk("scsi%ld: recover adapter - "
  829. "retry remaining %d\n",
  830. ha->host_no,
  831. ha->retry_reset_ha_cnt));
  832. status = QLA_ERROR;
  833. }
  834. if (ha->retry_reset_ha_cnt == 0) {
  835. /* Recover adapter retries have been exhausted.
  836. * Adapter DEAD */
  837. DEBUG2(printk("scsi%ld: recover adapter "
  838. "failed - board disabled\n",
  839. ha->host_no));
  840. qla4xxx_flush_active_srbs(ha);
  841. clear_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags);
  842. clear_bit(DPC_RESET_HA, &ha->dpc_flags);
  843. clear_bit(DPC_RESET_HA_DESTROY_DDB_LIST,
  844. &ha->dpc_flags);
  845. status = QLA_ERROR;
  846. }
  847. }
  848. } else {
  849. clear_bit(DPC_RESET_HA, &ha->dpc_flags);
  850. clear_bit(DPC_RESET_HA_DESTROY_DDB_LIST, &ha->dpc_flags);
  851. clear_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags);
  852. }
  853. ha->adapter_error_count++;
  854. if (status == QLA_SUCCESS)
  855. qla4xxx_enable_intrs(ha);
  856. DEBUG2(printk("scsi%ld: recover adapter .. DONE\n", ha->host_no));
  857. return status;
  858. }
  859. /**
  860. * qla4xxx_do_dpc - dpc routine
  861. * @data: in our case pointer to adapter structure
  862. *
  863. * This routine is a task that is schedule by the interrupt handler
  864. * to perform the background processing for interrupts. We put it
  865. * on a task queue that is consumed whenever the scheduler runs; that's
  866. * so you can do anything (i.e. put the process to sleep etc). In fact,
  867. * the mid-level tries to sleep when it reaches the driver threshold
  868. * "host->can_queue". This can cause a panic if we were in our interrupt code.
  869. **/
  870. static void qla4xxx_do_dpc(struct work_struct *work)
  871. {
  872. struct scsi_qla_host *ha =
  873. container_of(work, struct scsi_qla_host, dpc_work);
  874. struct ddb_entry *ddb_entry, *dtemp;
  875. int status = QLA_ERROR;
  876. DEBUG2(printk("scsi%ld: %s: DPC handler waking up."
  877. "flags = 0x%08lx, dpc_flags = 0x%08lx ctrl_stat = 0x%08x\n",
  878. ha->host_no, __func__, ha->flags, ha->dpc_flags,
  879. readw(&ha->reg->ctrl_status)));
  880. /* Initialization not yet finished. Don't do anything yet. */
  881. if (!test_bit(AF_INIT_DONE, &ha->flags))
  882. return;
  883. if (adapter_up(ha) ||
  884. test_bit(DPC_RESET_HA, &ha->dpc_flags) ||
  885. test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags) ||
  886. test_bit(DPC_RESET_HA_DESTROY_DDB_LIST, &ha->dpc_flags)) {
  887. if (test_bit(DPC_RESET_HA_DESTROY_DDB_LIST, &ha->dpc_flags) ||
  888. test_bit(DPC_RESET_HA, &ha->dpc_flags))
  889. qla4xxx_recover_adapter(ha, PRESERVE_DDB_LIST);
  890. if (test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags)) {
  891. uint8_t wait_time = RESET_INTR_TOV;
  892. while ((readw(&ha->reg->ctrl_status) &
  893. (CSR_SOFT_RESET | CSR_FORCE_SOFT_RESET)) != 0) {
  894. if (--wait_time == 0)
  895. break;
  896. msleep(1000);
  897. }
  898. if (wait_time == 0)
  899. DEBUG2(printk("scsi%ld: %s: SR|FSR "
  900. "bit not cleared-- resetting\n",
  901. ha->host_no, __func__));
  902. qla4xxx_flush_active_srbs(ha);
  903. if (ql4xxx_lock_drvr_wait(ha) == QLA_SUCCESS) {
  904. qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
  905. status = qla4xxx_initialize_adapter(ha,
  906. PRESERVE_DDB_LIST);
  907. }
  908. clear_bit(DPC_RESET_HA_INTR, &ha->dpc_flags);
  909. if (status == QLA_SUCCESS)
  910. qla4xxx_enable_intrs(ha);
  911. }
  912. }
  913. /* ---- process AEN? --- */
  914. if (test_and_clear_bit(DPC_AEN, &ha->dpc_flags))
  915. qla4xxx_process_aen(ha, PROCESS_ALL_AENS);
  916. /* ---- Get DHCP IP Address? --- */
  917. if (test_and_clear_bit(DPC_GET_DHCP_IP_ADDR, &ha->dpc_flags))
  918. qla4xxx_get_dhcp_ip_address(ha);
  919. /* ---- link change? --- */
  920. if (test_and_clear_bit(DPC_LINK_CHANGED, &ha->dpc_flags)) {
  921. if (!test_bit(AF_LINK_UP, &ha->flags)) {
  922. /* ---- link down? --- */
  923. list_for_each_entry_safe(ddb_entry, dtemp,
  924. &ha->ddb_list, list) {
  925. if (atomic_read(&ddb_entry->state) ==
  926. DDB_STATE_ONLINE)
  927. qla4xxx_mark_device_missing(ha,
  928. ddb_entry);
  929. }
  930. } else {
  931. /* ---- link up? --- *
  932. * F/W will auto login to all devices ONLY ONCE after
  933. * link up during driver initialization and runtime
  934. * fatal error recovery. Therefore, the driver must
  935. * manually relogin to devices when recovering from
  936. * connection failures, logouts, expired KATO, etc. */
  937. list_for_each_entry_safe(ddb_entry, dtemp,
  938. &ha->ddb_list, list) {
  939. if ((atomic_read(&ddb_entry->state) ==
  940. DDB_STATE_MISSING) ||
  941. (atomic_read(&ddb_entry->state) ==
  942. DDB_STATE_DEAD)) {
  943. if (ddb_entry->fw_ddb_device_state ==
  944. DDB_DS_SESSION_ACTIVE) {
  945. atomic_set(&ddb_entry->state,
  946. DDB_STATE_ONLINE);
  947. dev_info(&ha->pdev->dev,
  948. "scsi%ld: %s: ddb[%d]"
  949. " os[%d] marked"
  950. " ONLINE\n",
  951. ha->host_no, __func__,
  952. ddb_entry->fw_ddb_index,
  953. ddb_entry->os_target_id);
  954. iscsi_unblock_session(
  955. ddb_entry->sess);
  956. } else
  957. qla4xxx_relogin_device(
  958. ha, ddb_entry);
  959. }
  960. }
  961. }
  962. }
  963. /* ---- relogin device? --- */
  964. if (adapter_up(ha) &&
  965. test_and_clear_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags)) {
  966. list_for_each_entry_safe(ddb_entry, dtemp,
  967. &ha->ddb_list, list) {
  968. if (test_and_clear_bit(DF_RELOGIN, &ddb_entry->flags) &&
  969. atomic_read(&ddb_entry->state) != DDB_STATE_ONLINE)
  970. qla4xxx_relogin_device(ha, ddb_entry);
  971. /*
  972. * If mbx cmd times out there is no point
  973. * in continuing further.
  974. * With large no of targets this can hang
  975. * the system.
  976. */
  977. if (test_bit(DPC_RESET_HA, &ha->dpc_flags)) {
  978. printk(KERN_WARNING "scsi%ld: %s: "
  979. "need to reset hba\n",
  980. ha->host_no, __func__);
  981. break;
  982. }
  983. }
  984. }
  985. }
  986. /**
  987. * qla4xxx_free_adapter - release the adapter
  988. * @ha: pointer to adapter structure
  989. **/
  990. static void qla4xxx_free_adapter(struct scsi_qla_host *ha)
  991. {
  992. if (test_bit(AF_INTERRUPTS_ON, &ha->flags)) {
  993. /* Turn-off interrupts on the card. */
  994. qla4xxx_disable_intrs(ha);
  995. }
  996. /* Kill the kernel thread for this host */
  997. if (ha->dpc_thread)
  998. destroy_workqueue(ha->dpc_thread);
  999. /* Issue Soft Reset to put firmware in unknown state */
  1000. if (ql4xxx_lock_drvr_wait(ha) == QLA_SUCCESS)
  1001. qla4xxx_hw_reset(ha);
  1002. /* Remove timer thread, if present */
  1003. if (ha->timer_active)
  1004. qla4xxx_stop_timer(ha);
  1005. /* Detach interrupts */
  1006. if (test_and_clear_bit(AF_IRQ_ATTACHED, &ha->flags))
  1007. free_irq(ha->pdev->irq, ha);
  1008. /* free extra memory */
  1009. qla4xxx_mem_free(ha);
  1010. pci_disable_device(ha->pdev);
  1011. }
  1012. /***
  1013. * qla4xxx_iospace_config - maps registers
  1014. * @ha: pointer to adapter structure
  1015. *
  1016. * This routines maps HBA's registers from the pci address space
  1017. * into the kernel virtual address space for memory mapped i/o.
  1018. **/
  1019. static int qla4xxx_iospace_config(struct scsi_qla_host *ha)
  1020. {
  1021. unsigned long pio, pio_len, pio_flags;
  1022. unsigned long mmio, mmio_len, mmio_flags;
  1023. pio = pci_resource_start(ha->pdev, 0);
  1024. pio_len = pci_resource_len(ha->pdev, 0);
  1025. pio_flags = pci_resource_flags(ha->pdev, 0);
  1026. if (pio_flags & IORESOURCE_IO) {
  1027. if (pio_len < MIN_IOBASE_LEN) {
  1028. dev_warn(&ha->pdev->dev,
  1029. "Invalid PCI I/O region size\n");
  1030. pio = 0;
  1031. }
  1032. } else {
  1033. dev_warn(&ha->pdev->dev, "region #0 not a PIO resource\n");
  1034. pio = 0;
  1035. }
  1036. /* Use MMIO operations for all accesses. */
  1037. mmio = pci_resource_start(ha->pdev, 1);
  1038. mmio_len = pci_resource_len(ha->pdev, 1);
  1039. mmio_flags = pci_resource_flags(ha->pdev, 1);
  1040. if (!(mmio_flags & IORESOURCE_MEM)) {
  1041. dev_err(&ha->pdev->dev,
  1042. "region #0 not an MMIO resource, aborting\n");
  1043. goto iospace_error_exit;
  1044. }
  1045. if (mmio_len < MIN_IOBASE_LEN) {
  1046. dev_err(&ha->pdev->dev,
  1047. "Invalid PCI mem region size, aborting\n");
  1048. goto iospace_error_exit;
  1049. }
  1050. if (pci_request_regions(ha->pdev, DRIVER_NAME)) {
  1051. dev_warn(&ha->pdev->dev,
  1052. "Failed to reserve PIO/MMIO regions\n");
  1053. goto iospace_error_exit;
  1054. }
  1055. ha->pio_address = pio;
  1056. ha->pio_length = pio_len;
  1057. ha->reg = ioremap(mmio, MIN_IOBASE_LEN);
  1058. if (!ha->reg) {
  1059. dev_err(&ha->pdev->dev,
  1060. "cannot remap MMIO, aborting\n");
  1061. goto iospace_error_exit;
  1062. }
  1063. return 0;
  1064. iospace_error_exit:
  1065. return -ENOMEM;
  1066. }
  1067. /**
  1068. * qla4xxx_probe_adapter - callback function to probe HBA
  1069. * @pdev: pointer to pci_dev structure
  1070. * @pci_device_id: pointer to pci_device entry
  1071. *
  1072. * This routine will probe for Qlogic 4xxx iSCSI host adapters.
  1073. * It returns zero if successful. It also initializes all data necessary for
  1074. * the driver.
  1075. **/
  1076. static int __devinit qla4xxx_probe_adapter(struct pci_dev *pdev,
  1077. const struct pci_device_id *ent)
  1078. {
  1079. int ret = -ENODEV, status;
  1080. struct Scsi_Host *host;
  1081. struct scsi_qla_host *ha;
  1082. uint8_t init_retry_count = 0;
  1083. char buf[34];
  1084. if (pci_enable_device(pdev))
  1085. return -1;
  1086. host = scsi_host_alloc(&qla4xxx_driver_template, sizeof(*ha));
  1087. if (host == NULL) {
  1088. printk(KERN_WARNING
  1089. "qla4xxx: Couldn't allocate host from scsi layer!\n");
  1090. goto probe_disable_device;
  1091. }
  1092. /* Clear our data area */
  1093. ha = (struct scsi_qla_host *) host->hostdata;
  1094. memset(ha, 0, sizeof(*ha));
  1095. /* Save the information from PCI BIOS. */
  1096. ha->pdev = pdev;
  1097. ha->host = host;
  1098. ha->host_no = host->host_no;
  1099. /* Configure PCI I/O space. */
  1100. ret = qla4xxx_iospace_config(ha);
  1101. if (ret)
  1102. goto probe_failed;
  1103. dev_info(&ha->pdev->dev, "Found an ISP%04x, irq %d, iobase 0x%p\n",
  1104. pdev->device, pdev->irq, ha->reg);
  1105. qla4xxx_config_dma_addressing(ha);
  1106. /* Initialize lists and spinlocks. */
  1107. INIT_LIST_HEAD(&ha->ddb_list);
  1108. INIT_LIST_HEAD(&ha->free_srb_q);
  1109. mutex_init(&ha->mbox_sem);
  1110. spin_lock_init(&ha->hardware_lock);
  1111. /* Allocate dma buffers */
  1112. if (qla4xxx_mem_alloc(ha)) {
  1113. dev_warn(&ha->pdev->dev,
  1114. "[ERROR] Failed to allocate memory for adapter\n");
  1115. ret = -ENOMEM;
  1116. goto probe_failed;
  1117. }
  1118. /*
  1119. * Initialize the Host adapter request/response queues and
  1120. * firmware
  1121. * NOTE: interrupts enabled upon successful completion
  1122. */
  1123. status = qla4xxx_initialize_adapter(ha, REBUILD_DDB_LIST);
  1124. while (status == QLA_ERROR && init_retry_count++ < MAX_INIT_RETRIES) {
  1125. DEBUG2(printk("scsi: %s: retrying adapter initialization "
  1126. "(%d)\n", __func__, init_retry_count));
  1127. qla4xxx_soft_reset(ha);
  1128. status = qla4xxx_initialize_adapter(ha, REBUILD_DDB_LIST);
  1129. }
  1130. if (status == QLA_ERROR) {
  1131. dev_warn(&ha->pdev->dev, "Failed to initialize adapter\n");
  1132. ret = -ENODEV;
  1133. goto probe_failed;
  1134. }
  1135. host->cmd_per_lun = 3;
  1136. host->max_channel = 0;
  1137. host->max_lun = MAX_LUNS - 1;
  1138. host->max_id = MAX_TARGETS;
  1139. host->max_cmd_len = IOCB_MAX_CDB_LEN;
  1140. host->can_queue = MAX_SRBS ;
  1141. host->transportt = qla4xxx_scsi_transport;
  1142. ret = scsi_init_shared_tag_map(host, MAX_SRBS);
  1143. if (ret) {
  1144. dev_warn(&ha->pdev->dev, "scsi_init_shared_tag_map failed\n");
  1145. goto probe_failed;
  1146. }
  1147. /* Startup the kernel thread for this host adapter. */
  1148. DEBUG2(printk("scsi: %s: Starting kernel thread for "
  1149. "qla4xxx_dpc\n", __func__));
  1150. sprintf(buf, "qla4xxx_%lu_dpc", ha->host_no);
  1151. ha->dpc_thread = create_singlethread_workqueue(buf);
  1152. if (!ha->dpc_thread) {
  1153. dev_warn(&ha->pdev->dev, "Unable to start DPC thread!\n");
  1154. ret = -ENODEV;
  1155. goto probe_failed;
  1156. }
  1157. INIT_WORK(&ha->dpc_work, qla4xxx_do_dpc);
  1158. ret = request_irq(pdev->irq, qla4xxx_intr_handler,
  1159. IRQF_DISABLED | IRQF_SHARED, "qla4xxx", ha);
  1160. if (ret) {
  1161. dev_warn(&ha->pdev->dev, "Failed to reserve interrupt %d"
  1162. " already in use.\n", pdev->irq);
  1163. goto probe_failed;
  1164. }
  1165. set_bit(AF_IRQ_ATTACHED, &ha->flags);
  1166. host->irq = pdev->irq;
  1167. DEBUG(printk("scsi%d: irq %d attached\n", ha->host_no, ha->pdev->irq));
  1168. qla4xxx_enable_intrs(ha);
  1169. /* Start timer thread. */
  1170. qla4xxx_start_timer(ha, qla4xxx_timer, 1);
  1171. set_bit(AF_INIT_DONE, &ha->flags);
  1172. pci_set_drvdata(pdev, ha);
  1173. ret = scsi_add_host(host, &pdev->dev);
  1174. if (ret)
  1175. goto probe_failed;
  1176. printk(KERN_INFO
  1177. " QLogic iSCSI HBA Driver version: %s\n"
  1178. " QLogic ISP%04x @ %s, host#=%ld, fw=%02d.%02d.%02d.%02d\n",
  1179. qla4xxx_version_str, ha->pdev->device, pci_name(ha->pdev),
  1180. ha->host_no, ha->firmware_version[0], ha->firmware_version[1],
  1181. ha->patch_number, ha->build_number);
  1182. scsi_scan_host(host);
  1183. return 0;
  1184. probe_failed:
  1185. qla4xxx_free_adapter(ha);
  1186. scsi_host_put(ha->host);
  1187. probe_disable_device:
  1188. pci_disable_device(pdev);
  1189. return ret;
  1190. }
  1191. /**
  1192. * qla4xxx_remove_adapter - calback function to remove adapter.
  1193. * @pci_dev: PCI device pointer
  1194. **/
  1195. static void __devexit qla4xxx_remove_adapter(struct pci_dev *pdev)
  1196. {
  1197. struct scsi_qla_host *ha;
  1198. ha = pci_get_drvdata(pdev);
  1199. qla4xxx_disable_intrs(ha);
  1200. while (test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags))
  1201. ssleep(1);
  1202. /* remove devs from iscsi_sessions to scsi_devices */
  1203. qla4xxx_free_ddb_list(ha);
  1204. scsi_remove_host(ha->host);
  1205. qla4xxx_free_adapter(ha);
  1206. scsi_host_put(ha->host);
  1207. pci_set_drvdata(pdev, NULL);
  1208. }
  1209. /**
  1210. * qla4xxx_config_dma_addressing() - Configure OS DMA addressing method.
  1211. * @ha: HA context
  1212. *
  1213. * At exit, the @ha's flags.enable_64bit_addressing set to indicated
  1214. * supported addressing method.
  1215. */
  1216. static void qla4xxx_config_dma_addressing(struct scsi_qla_host *ha)
  1217. {
  1218. int retval;
  1219. /* Update our PCI device dma_mask for full 64 bit mask */
  1220. if (pci_set_dma_mask(ha->pdev, DMA_BIT_MASK(64)) == 0) {
  1221. if (pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(64))) {
  1222. dev_dbg(&ha->pdev->dev,
  1223. "Failed to set 64 bit PCI consistent mask; "
  1224. "using 32 bit.\n");
  1225. retval = pci_set_consistent_dma_mask(ha->pdev,
  1226. DMA_BIT_MASK(32));
  1227. }
  1228. } else
  1229. retval = pci_set_dma_mask(ha->pdev, DMA_BIT_MASK(32));
  1230. }
  1231. static int qla4xxx_slave_alloc(struct scsi_device *sdev)
  1232. {
  1233. struct iscsi_cls_session *sess = starget_to_session(sdev->sdev_target);
  1234. struct ddb_entry *ddb = sess->dd_data;
  1235. sdev->hostdata = ddb;
  1236. sdev->tagged_supported = 1;
  1237. scsi_activate_tcq(sdev, QL4_DEF_QDEPTH);
  1238. return 0;
  1239. }
  1240. static int qla4xxx_slave_configure(struct scsi_device *sdev)
  1241. {
  1242. sdev->tagged_supported = 1;
  1243. return 0;
  1244. }
  1245. static void qla4xxx_slave_destroy(struct scsi_device *sdev)
  1246. {
  1247. scsi_deactivate_tcq(sdev, 1);
  1248. }
  1249. /**
  1250. * qla4xxx_del_from_active_array - returns an active srb
  1251. * @ha: Pointer to host adapter structure.
  1252. * @index: index into the active_array
  1253. *
  1254. * This routine removes and returns the srb at the specified index
  1255. **/
  1256. struct srb * qla4xxx_del_from_active_array(struct scsi_qla_host *ha, uint32_t index)
  1257. {
  1258. struct srb *srb = NULL;
  1259. struct scsi_cmnd *cmd;
  1260. if (!(cmd = scsi_host_find_tag(ha->host, index)))
  1261. return srb;
  1262. if (!(srb = (struct srb *)cmd->host_scribble))
  1263. return srb;
  1264. /* update counters */
  1265. if (srb->flags & SRB_DMA_VALID) {
  1266. ha->req_q_count += srb->iocb_cnt;
  1267. ha->iocb_cnt -= srb->iocb_cnt;
  1268. if (srb->cmd)
  1269. srb->cmd->host_scribble = NULL;
  1270. }
  1271. return srb;
  1272. }
  1273. /**
  1274. * qla4xxx_eh_wait_on_command - waits for command to be returned by firmware
  1275. * @ha: actual ha whose done queue will contain the comd returned by firmware.
  1276. * @cmd: Scsi Command to wait on.
  1277. *
  1278. * This routine waits for the command to be returned by the Firmware
  1279. * for some max time.
  1280. **/
  1281. static int qla4xxx_eh_wait_on_command(struct scsi_qla_host *ha,
  1282. struct scsi_cmnd *cmd)
  1283. {
  1284. int done = 0;
  1285. struct srb *rp;
  1286. uint32_t max_wait_time = EH_WAIT_CMD_TOV;
  1287. do {
  1288. /* Checking to see if its returned to OS */
  1289. rp = (struct srb *) cmd->SCp.ptr;
  1290. if (rp == NULL) {
  1291. done++;
  1292. break;
  1293. }
  1294. msleep(2000);
  1295. } while (max_wait_time--);
  1296. return done;
  1297. }
  1298. /**
  1299. * qla4xxx_wait_for_hba_online - waits for HBA to come online
  1300. * @ha: Pointer to host adapter structure
  1301. **/
  1302. static int qla4xxx_wait_for_hba_online(struct scsi_qla_host *ha)
  1303. {
  1304. unsigned long wait_online;
  1305. wait_online = jiffies + (30 * HZ);
  1306. while (time_before(jiffies, wait_online)) {
  1307. if (adapter_up(ha))
  1308. return QLA_SUCCESS;
  1309. else if (ha->retry_reset_ha_cnt == 0)
  1310. return QLA_ERROR;
  1311. msleep(2000);
  1312. }
  1313. return QLA_ERROR;
  1314. }
  1315. /**
  1316. * qla4xxx_eh_wait_for_commands - wait for active cmds to finish.
  1317. * @ha: pointer to HBA
  1318. * @t: target id
  1319. * @l: lun id
  1320. *
  1321. * This function waits for all outstanding commands to a lun to complete. It
  1322. * returns 0 if all pending commands are returned and 1 otherwise.
  1323. **/
  1324. static int qla4xxx_eh_wait_for_commands(struct scsi_qla_host *ha,
  1325. struct scsi_target *stgt,
  1326. struct scsi_device *sdev)
  1327. {
  1328. int cnt;
  1329. int status = 0;
  1330. struct scsi_cmnd *cmd;
  1331. /*
  1332. * Waiting for all commands for the designated target or dev
  1333. * in the active array
  1334. */
  1335. for (cnt = 0; cnt < ha->host->can_queue; cnt++) {
  1336. cmd = scsi_host_find_tag(ha->host, cnt);
  1337. if (cmd && stgt == scsi_target(cmd->device) &&
  1338. (!sdev || sdev == cmd->device)) {
  1339. if (!qla4xxx_eh_wait_on_command(ha, cmd)) {
  1340. status++;
  1341. break;
  1342. }
  1343. }
  1344. }
  1345. return status;
  1346. }
  1347. /**
  1348. * qla4xxx_eh_device_reset - callback for target reset.
  1349. * @cmd: Pointer to Linux's SCSI command structure
  1350. *
  1351. * This routine is called by the Linux OS to reset all luns on the
  1352. * specified target.
  1353. **/
  1354. static int qla4xxx_eh_device_reset(struct scsi_cmnd *cmd)
  1355. {
  1356. struct scsi_qla_host *ha = to_qla_host(cmd->device->host);
  1357. struct ddb_entry *ddb_entry = cmd->device->hostdata;
  1358. int ret = FAILED, stat;
  1359. if (!ddb_entry)
  1360. return ret;
  1361. dev_info(&ha->pdev->dev,
  1362. "scsi%ld:%d:%d:%d: DEVICE RESET ISSUED.\n", ha->host_no,
  1363. cmd->device->channel, cmd->device->id, cmd->device->lun);
  1364. DEBUG2(printk(KERN_INFO
  1365. "scsi%ld: DEVICE_RESET cmd=%p jiffies = 0x%lx, to=%x,"
  1366. "dpc_flags=%lx, status=%x allowed=%d\n", ha->host_no,
  1367. cmd, jiffies, cmd->request->timeout / HZ,
  1368. ha->dpc_flags, cmd->result, cmd->allowed));
  1369. /* FIXME: wait for hba to go online */
  1370. stat = qla4xxx_reset_lun(ha, ddb_entry, cmd->device->lun);
  1371. if (stat != QLA_SUCCESS) {
  1372. dev_info(&ha->pdev->dev, "DEVICE RESET FAILED. %d\n", stat);
  1373. goto eh_dev_reset_done;
  1374. }
  1375. if (qla4xxx_eh_wait_for_commands(ha, scsi_target(cmd->device),
  1376. cmd->device)) {
  1377. dev_info(&ha->pdev->dev,
  1378. "DEVICE RESET FAILED - waiting for "
  1379. "commands.\n");
  1380. goto eh_dev_reset_done;
  1381. }
  1382. /* Send marker. */
  1383. if (qla4xxx_send_marker_iocb(ha, ddb_entry, cmd->device->lun,
  1384. MM_LUN_RESET) != QLA_SUCCESS)
  1385. goto eh_dev_reset_done;
  1386. dev_info(&ha->pdev->dev,
  1387. "scsi(%ld:%d:%d:%d): DEVICE RESET SUCCEEDED.\n",
  1388. ha->host_no, cmd->device->channel, cmd->device->id,
  1389. cmd->device->lun);
  1390. ret = SUCCESS;
  1391. eh_dev_reset_done:
  1392. return ret;
  1393. }
  1394. /**
  1395. * qla4xxx_eh_target_reset - callback for target reset.
  1396. * @cmd: Pointer to Linux's SCSI command structure
  1397. *
  1398. * This routine is called by the Linux OS to reset the target.
  1399. **/
  1400. static int qla4xxx_eh_target_reset(struct scsi_cmnd *cmd)
  1401. {
  1402. struct scsi_qla_host *ha = to_qla_host(cmd->device->host);
  1403. struct ddb_entry *ddb_entry = cmd->device->hostdata;
  1404. int stat;
  1405. if (!ddb_entry)
  1406. return FAILED;
  1407. starget_printk(KERN_INFO, scsi_target(cmd->device),
  1408. "WARM TARGET RESET ISSUED.\n");
  1409. DEBUG2(printk(KERN_INFO
  1410. "scsi%ld: TARGET_DEVICE_RESET cmd=%p jiffies = 0x%lx, "
  1411. "to=%x,dpc_flags=%lx, status=%x allowed=%d\n",
  1412. ha->host_no, cmd, jiffies, cmd->request->timeout / HZ,
  1413. ha->dpc_flags, cmd->result, cmd->allowed));
  1414. stat = qla4xxx_reset_target(ha, ddb_entry);
  1415. if (stat != QLA_SUCCESS) {
  1416. starget_printk(KERN_INFO, scsi_target(cmd->device),
  1417. "WARM TARGET RESET FAILED.\n");
  1418. return FAILED;
  1419. }
  1420. if (qla4xxx_eh_wait_for_commands(ha, scsi_target(cmd->device),
  1421. NULL)) {
  1422. starget_printk(KERN_INFO, scsi_target(cmd->device),
  1423. "WARM TARGET DEVICE RESET FAILED - "
  1424. "waiting for commands.\n");
  1425. return FAILED;
  1426. }
  1427. /* Send marker. */
  1428. if (qla4xxx_send_marker_iocb(ha, ddb_entry, cmd->device->lun,
  1429. MM_TGT_WARM_RESET) != QLA_SUCCESS) {
  1430. starget_printk(KERN_INFO, scsi_target(cmd->device),
  1431. "WARM TARGET DEVICE RESET FAILED - "
  1432. "marker iocb failed.\n");
  1433. return FAILED;
  1434. }
  1435. starget_printk(KERN_INFO, scsi_target(cmd->device),
  1436. "WARM TARGET RESET SUCCEEDED.\n");
  1437. return SUCCESS;
  1438. }
  1439. /**
  1440. * qla4xxx_eh_host_reset - kernel callback
  1441. * @cmd: Pointer to Linux's SCSI command structure
  1442. *
  1443. * This routine is invoked by the Linux kernel to perform fatal error
  1444. * recovery on the specified adapter.
  1445. **/
  1446. static int qla4xxx_eh_host_reset(struct scsi_cmnd *cmd)
  1447. {
  1448. int return_status = FAILED;
  1449. struct scsi_qla_host *ha;
  1450. ha = (struct scsi_qla_host *) cmd->device->host->hostdata;
  1451. dev_info(&ha->pdev->dev,
  1452. "scsi(%ld:%d:%d:%d): HOST RESET ISSUED.\n", ha->host_no,
  1453. cmd->device->channel, cmd->device->id, cmd->device->lun);
  1454. if (qla4xxx_wait_for_hba_online(ha) != QLA_SUCCESS) {
  1455. DEBUG2(printk("scsi%ld:%d: %s: Unable to reset host. Adapter "
  1456. "DEAD.\n", ha->host_no, cmd->device->channel,
  1457. __func__));
  1458. return FAILED;
  1459. }
  1460. /* make sure the dpc thread is stopped while we reset the hba */
  1461. clear_bit(AF_ONLINE, &ha->flags);
  1462. flush_workqueue(ha->dpc_thread);
  1463. if (qla4xxx_recover_adapter(ha, PRESERVE_DDB_LIST) == QLA_SUCCESS)
  1464. return_status = SUCCESS;
  1465. dev_info(&ha->pdev->dev, "HOST RESET %s.\n",
  1466. return_status == FAILED ? "FAILED" : "SUCCEDED");
  1467. return return_status;
  1468. }
  1469. static struct pci_device_id qla4xxx_pci_tbl[] = {
  1470. {
  1471. .vendor = PCI_VENDOR_ID_QLOGIC,
  1472. .device = PCI_DEVICE_ID_QLOGIC_ISP4010,
  1473. .subvendor = PCI_ANY_ID,
  1474. .subdevice = PCI_ANY_ID,
  1475. },
  1476. {
  1477. .vendor = PCI_VENDOR_ID_QLOGIC,
  1478. .device = PCI_DEVICE_ID_QLOGIC_ISP4022,
  1479. .subvendor = PCI_ANY_ID,
  1480. .subdevice = PCI_ANY_ID,
  1481. },
  1482. {
  1483. .vendor = PCI_VENDOR_ID_QLOGIC,
  1484. .device = PCI_DEVICE_ID_QLOGIC_ISP4032,
  1485. .subvendor = PCI_ANY_ID,
  1486. .subdevice = PCI_ANY_ID,
  1487. },
  1488. {0, 0},
  1489. };
  1490. MODULE_DEVICE_TABLE(pci, qla4xxx_pci_tbl);
  1491. static struct pci_driver qla4xxx_pci_driver = {
  1492. .name = DRIVER_NAME,
  1493. .id_table = qla4xxx_pci_tbl,
  1494. .probe = qla4xxx_probe_adapter,
  1495. .remove = qla4xxx_remove_adapter,
  1496. };
  1497. static int __init qla4xxx_module_init(void)
  1498. {
  1499. int ret;
  1500. /* Allocate cache for SRBs. */
  1501. srb_cachep = kmem_cache_create("qla4xxx_srbs", sizeof(struct srb), 0,
  1502. SLAB_HWCACHE_ALIGN, NULL);
  1503. if (srb_cachep == NULL) {
  1504. printk(KERN_ERR
  1505. "%s: Unable to allocate SRB cache..."
  1506. "Failing load!\n", DRIVER_NAME);
  1507. ret = -ENOMEM;
  1508. goto no_srp_cache;
  1509. }
  1510. /* Derive version string. */
  1511. strcpy(qla4xxx_version_str, QLA4XXX_DRIVER_VERSION);
  1512. if (ql4xextended_error_logging)
  1513. strcat(qla4xxx_version_str, "-debug");
  1514. qla4xxx_scsi_transport =
  1515. iscsi_register_transport(&qla4xxx_iscsi_transport);
  1516. if (!qla4xxx_scsi_transport){
  1517. ret = -ENODEV;
  1518. goto release_srb_cache;
  1519. }
  1520. ret = pci_register_driver(&qla4xxx_pci_driver);
  1521. if (ret)
  1522. goto unregister_transport;
  1523. printk(KERN_INFO "QLogic iSCSI HBA Driver\n");
  1524. return 0;
  1525. unregister_transport:
  1526. iscsi_unregister_transport(&qla4xxx_iscsi_transport);
  1527. release_srb_cache:
  1528. kmem_cache_destroy(srb_cachep);
  1529. no_srp_cache:
  1530. return ret;
  1531. }
  1532. static void __exit qla4xxx_module_exit(void)
  1533. {
  1534. ql4_mod_unload = 1;
  1535. pci_unregister_driver(&qla4xxx_pci_driver);
  1536. iscsi_unregister_transport(&qla4xxx_iscsi_transport);
  1537. kmem_cache_destroy(srb_cachep);
  1538. }
  1539. module_init(qla4xxx_module_init);
  1540. module_exit(qla4xxx_module_exit);
  1541. MODULE_AUTHOR("QLogic Corporation");
  1542. MODULE_DESCRIPTION("QLogic iSCSI HBA Driver");
  1543. MODULE_LICENSE("GPL");
  1544. MODULE_VERSION(QLA4XXX_DRIVER_VERSION);