ql4_os.c 47 KB

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