ql4_os.c 47 KB

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