ql4_os.c 46 KB

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