ql4_os.c 47 KB

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