ql4_os.c 50 KB

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