ql4_os.c 47 KB

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