ql4_mbx.c 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194
  1. /*
  2. * QLogic iSCSI HBA Driver
  3. * Copyright (c) 2003-2010 QLogic Corporation
  4. *
  5. * See LICENSE.qla4xxx for copyright and licensing details.
  6. */
  7. #include "ql4_def.h"
  8. #include "ql4_glbl.h"
  9. #include "ql4_dbg.h"
  10. #include "ql4_inline.h"
  11. /**
  12. * qla4xxx_mailbox_command - issues mailbox commands
  13. * @ha: Pointer to host adapter structure.
  14. * @inCount: number of mailbox registers to load.
  15. * @outCount: number of mailbox registers to return.
  16. * @mbx_cmd: data pointer for mailbox in registers.
  17. * @mbx_sts: data pointer for mailbox out registers.
  18. *
  19. * This routine isssue mailbox commands and waits for completion.
  20. * If outCount is 0, this routine completes successfully WITHOUT waiting
  21. * for the mailbox command to complete.
  22. **/
  23. int qla4xxx_mailbox_command(struct scsi_qla_host *ha, uint8_t inCount,
  24. uint8_t outCount, uint32_t *mbx_cmd,
  25. uint32_t *mbx_sts)
  26. {
  27. int status = QLA_ERROR;
  28. uint8_t i;
  29. u_long wait_count;
  30. uint32_t intr_status;
  31. unsigned long flags = 0;
  32. uint32_t dev_state;
  33. /* Make sure that pointers are valid */
  34. if (!mbx_cmd || !mbx_sts) {
  35. DEBUG2(printk("scsi%ld: %s: Invalid mbx_cmd or mbx_sts "
  36. "pointer\n", ha->host_no, __func__));
  37. return status;
  38. }
  39. if (is_qla8022(ha)) {
  40. if (test_bit(AF_FW_RECOVERY, &ha->flags)) {
  41. DEBUG2(ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: "
  42. "prematurely completing mbx cmd as firmware "
  43. "recovery detected\n", ha->host_no, __func__));
  44. return status;
  45. }
  46. /* Do not send any mbx cmd if h/w is in failed state*/
  47. qla4_8xxx_idc_lock(ha);
  48. dev_state = qla4_8xxx_rd_32(ha, QLA82XX_CRB_DEV_STATE);
  49. qla4_8xxx_idc_unlock(ha);
  50. if (dev_state == QLA82XX_DEV_FAILED) {
  51. ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: H/W is in "
  52. "failed state, do not send any mailbox commands\n",
  53. ha->host_no, __func__);
  54. return status;
  55. }
  56. }
  57. if ((is_aer_supported(ha)) &&
  58. (test_bit(AF_PCI_CHANNEL_IO_PERM_FAILURE, &ha->flags))) {
  59. DEBUG2(printk(KERN_WARNING "scsi%ld: %s: Perm failure on EEH, "
  60. "timeout MBX Exiting.\n", ha->host_no, __func__));
  61. return status;
  62. }
  63. /* Mailbox code active */
  64. wait_count = MBOX_TOV * 100;
  65. while (wait_count--) {
  66. mutex_lock(&ha->mbox_sem);
  67. if (!test_bit(AF_MBOX_COMMAND, &ha->flags)) {
  68. set_bit(AF_MBOX_COMMAND, &ha->flags);
  69. mutex_unlock(&ha->mbox_sem);
  70. break;
  71. }
  72. mutex_unlock(&ha->mbox_sem);
  73. if (!wait_count) {
  74. DEBUG2(printk("scsi%ld: %s: mbox_sem failed\n",
  75. ha->host_no, __func__));
  76. return status;
  77. }
  78. msleep(10);
  79. }
  80. /* To prevent overwriting mailbox registers for a command that has
  81. * not yet been serviced, check to see if an active command
  82. * (AEN, IOCB, etc.) is interrupting, then service it.
  83. * -----------------------------------------------------------------
  84. */
  85. spin_lock_irqsave(&ha->hardware_lock, flags);
  86. if (!is_qla8022(ha)) {
  87. intr_status = readl(&ha->reg->ctrl_status);
  88. if (intr_status & CSR_SCSI_PROCESSOR_INTR) {
  89. /* Service existing interrupt */
  90. ha->isp_ops->interrupt_service_routine(ha, intr_status);
  91. clear_bit(AF_MBOX_COMMAND_DONE, &ha->flags);
  92. }
  93. }
  94. ha->mbox_status_count = outCount;
  95. for (i = 0; i < outCount; i++)
  96. ha->mbox_status[i] = 0;
  97. if (is_qla8022(ha)) {
  98. /* Load all mailbox registers, except mailbox 0. */
  99. DEBUG5(
  100. printk("scsi%ld: %s: Cmd ", ha->host_no, __func__);
  101. for (i = 0; i < inCount; i++)
  102. printk("mb%d=%04x ", i, mbx_cmd[i]);
  103. printk("\n"));
  104. for (i = 1; i < inCount; i++)
  105. writel(mbx_cmd[i], &ha->qla4_8xxx_reg->mailbox_in[i]);
  106. writel(mbx_cmd[0], &ha->qla4_8xxx_reg->mailbox_in[0]);
  107. readl(&ha->qla4_8xxx_reg->mailbox_in[0]);
  108. writel(HINT_MBX_INT_PENDING, &ha->qla4_8xxx_reg->hint);
  109. } else {
  110. /* Load all mailbox registers, except mailbox 0. */
  111. for (i = 1; i < inCount; i++)
  112. writel(mbx_cmd[i], &ha->reg->mailbox[i]);
  113. /* Wakeup firmware */
  114. writel(mbx_cmd[0], &ha->reg->mailbox[0]);
  115. readl(&ha->reg->mailbox[0]);
  116. writel(set_rmask(CSR_INTR_RISC), &ha->reg->ctrl_status);
  117. readl(&ha->reg->ctrl_status);
  118. }
  119. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  120. /* Wait for completion */
  121. /*
  122. * If we don't want status, don't wait for the mailbox command to
  123. * complete. For example, MBOX_CMD_RESET_FW doesn't return status,
  124. * you must poll the inbound Interrupt Mask for completion.
  125. */
  126. if (outCount == 0) {
  127. status = QLA_SUCCESS;
  128. goto mbox_exit;
  129. }
  130. /*
  131. * Wait for completion: Poll or completion queue
  132. */
  133. if (test_bit(AF_IRQ_ATTACHED, &ha->flags) &&
  134. test_bit(AF_INTERRUPTS_ON, &ha->flags) &&
  135. test_bit(AF_ONLINE, &ha->flags) &&
  136. !test_bit(AF_HBA_GOING_AWAY, &ha->flags)) {
  137. /* Do not poll for completion. Use completion queue */
  138. set_bit(AF_MBOX_COMMAND_NOPOLL, &ha->flags);
  139. wait_for_completion_timeout(&ha->mbx_intr_comp, MBOX_TOV * HZ);
  140. clear_bit(AF_MBOX_COMMAND_NOPOLL, &ha->flags);
  141. } else {
  142. /* Poll for command to complete */
  143. wait_count = jiffies + MBOX_TOV * HZ;
  144. while (test_bit(AF_MBOX_COMMAND_DONE, &ha->flags) == 0) {
  145. if (time_after_eq(jiffies, wait_count))
  146. break;
  147. /*
  148. * Service the interrupt.
  149. * The ISR will save the mailbox status registers
  150. * to a temporary storage location in the adapter
  151. * structure.
  152. */
  153. spin_lock_irqsave(&ha->hardware_lock, flags);
  154. if (is_qla8022(ha)) {
  155. intr_status =
  156. readl(&ha->qla4_8xxx_reg->host_int);
  157. if (intr_status & ISRX_82XX_RISC_INT) {
  158. ha->mbox_status_count = outCount;
  159. intr_status =
  160. readl(&ha->qla4_8xxx_reg->host_status);
  161. ha->isp_ops->interrupt_service_routine(
  162. ha, intr_status);
  163. if (test_bit(AF_INTERRUPTS_ON,
  164. &ha->flags) &&
  165. test_bit(AF_INTx_ENABLED,
  166. &ha->flags))
  167. qla4_8xxx_wr_32(ha,
  168. ha->nx_legacy_intr.tgt_mask_reg,
  169. 0xfbff);
  170. }
  171. } else {
  172. intr_status = readl(&ha->reg->ctrl_status);
  173. if (intr_status & INTR_PENDING) {
  174. /*
  175. * Service the interrupt.
  176. * The ISR will save the mailbox status
  177. * registers to a temporary storage
  178. * location in the adapter structure.
  179. */
  180. ha->mbox_status_count = outCount;
  181. ha->isp_ops->interrupt_service_routine(
  182. ha, intr_status);
  183. }
  184. }
  185. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  186. msleep(10);
  187. }
  188. }
  189. /* Check for mailbox timeout. */
  190. if (!test_bit(AF_MBOX_COMMAND_DONE, &ha->flags)) {
  191. if (is_qla8022(ha) &&
  192. test_bit(AF_FW_RECOVERY, &ha->flags)) {
  193. DEBUG2(ql4_printk(KERN_INFO, ha,
  194. "scsi%ld: %s: prematurely completing mbx cmd as "
  195. "firmware recovery detected\n",
  196. ha->host_no, __func__));
  197. goto mbox_exit;
  198. }
  199. DEBUG2(printk("scsi%ld: Mailbox Cmd 0x%08X timed out ...,"
  200. " Scheduling Adapter Reset\n", ha->host_no,
  201. mbx_cmd[0]));
  202. ha->mailbox_timeout_count++;
  203. mbx_sts[0] = (-1);
  204. set_bit(DPC_RESET_HA, &ha->dpc_flags);
  205. goto mbox_exit;
  206. }
  207. /*
  208. * Copy the mailbox out registers to the caller's mailbox in/out
  209. * structure.
  210. */
  211. spin_lock_irqsave(&ha->hardware_lock, flags);
  212. for (i = 0; i < outCount; i++)
  213. mbx_sts[i] = ha->mbox_status[i];
  214. /* Set return status and error flags (if applicable). */
  215. switch (ha->mbox_status[0]) {
  216. case MBOX_STS_COMMAND_COMPLETE:
  217. status = QLA_SUCCESS;
  218. break;
  219. case MBOX_STS_INTERMEDIATE_COMPLETION:
  220. status = QLA_SUCCESS;
  221. break;
  222. case MBOX_STS_BUSY:
  223. DEBUG2( printk("scsi%ld: %s: Cmd = %08X, ISP BUSY\n",
  224. ha->host_no, __func__, mbx_cmd[0]));
  225. ha->mailbox_timeout_count++;
  226. break;
  227. default:
  228. DEBUG2(printk("scsi%ld: %s: **** FAILED, cmd = %08X, "
  229. "sts = %08X ****\n", ha->host_no, __func__,
  230. mbx_cmd[0], mbx_sts[0]));
  231. break;
  232. }
  233. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  234. mbox_exit:
  235. mutex_lock(&ha->mbox_sem);
  236. clear_bit(AF_MBOX_COMMAND, &ha->flags);
  237. mutex_unlock(&ha->mbox_sem);
  238. clear_bit(AF_MBOX_COMMAND_DONE, &ha->flags);
  239. return status;
  240. }
  241. void qla4xxx_mailbox_premature_completion(struct scsi_qla_host *ha)
  242. {
  243. set_bit(AF_FW_RECOVERY, &ha->flags);
  244. ql4_printk(KERN_INFO, ha, "scsi%ld: %s: set FW RECOVERY!\n",
  245. ha->host_no, __func__);
  246. if (test_bit(AF_MBOX_COMMAND, &ha->flags)) {
  247. if (test_bit(AF_MBOX_COMMAND_NOPOLL, &ha->flags)) {
  248. complete(&ha->mbx_intr_comp);
  249. ql4_printk(KERN_INFO, ha, "scsi%ld: %s: Due to fw "
  250. "recovery, doing premature completion of "
  251. "mbx cmd\n", ha->host_no, __func__);
  252. } else {
  253. set_bit(AF_MBOX_COMMAND_DONE, &ha->flags);
  254. ql4_printk(KERN_INFO, ha, "scsi%ld: %s: Due to fw "
  255. "recovery, doing premature completion of "
  256. "polling mbx cmd\n", ha->host_no, __func__);
  257. }
  258. }
  259. }
  260. static uint8_t
  261. qla4xxx_set_ifcb(struct scsi_qla_host *ha, uint32_t *mbox_cmd,
  262. uint32_t *mbox_sts, dma_addr_t init_fw_cb_dma)
  263. {
  264. memset(mbox_cmd, 0, sizeof(mbox_cmd[0]) * MBOX_REG_COUNT);
  265. memset(mbox_sts, 0, sizeof(mbox_sts[0]) * MBOX_REG_COUNT);
  266. if (is_qla8022(ha))
  267. qla4_8xxx_wr_32(ha, ha->nx_db_wr_ptr, 0);
  268. mbox_cmd[0] = MBOX_CMD_INITIALIZE_FIRMWARE;
  269. mbox_cmd[1] = 0;
  270. mbox_cmd[2] = LSDW(init_fw_cb_dma);
  271. mbox_cmd[3] = MSDW(init_fw_cb_dma);
  272. mbox_cmd[4] = sizeof(struct addr_ctrl_blk);
  273. mbox_cmd[5] = (IFCB_VER_MAX << 8) | IFCB_VER_MIN;
  274. if (qla4xxx_mailbox_command(ha, 6, 6, mbox_cmd, mbox_sts) !=
  275. QLA_SUCCESS) {
  276. DEBUG2(printk(KERN_WARNING "scsi%ld: %s: "
  277. "MBOX_CMD_INITIALIZE_FIRMWARE"
  278. " failed w/ status %04X\n",
  279. ha->host_no, __func__, mbox_sts[0]));
  280. return QLA_ERROR;
  281. }
  282. return QLA_SUCCESS;
  283. }
  284. static uint8_t
  285. qla4xxx_get_ifcb(struct scsi_qla_host *ha, uint32_t *mbox_cmd,
  286. uint32_t *mbox_sts, dma_addr_t init_fw_cb_dma)
  287. {
  288. memset(mbox_cmd, 0, sizeof(mbox_cmd[0]) * MBOX_REG_COUNT);
  289. memset(mbox_sts, 0, sizeof(mbox_sts[0]) * MBOX_REG_COUNT);
  290. mbox_cmd[0] = MBOX_CMD_GET_INIT_FW_CTRL_BLOCK;
  291. mbox_cmd[2] = LSDW(init_fw_cb_dma);
  292. mbox_cmd[3] = MSDW(init_fw_cb_dma);
  293. mbox_cmd[4] = sizeof(struct addr_ctrl_blk);
  294. if (qla4xxx_mailbox_command(ha, 5, 5, mbox_cmd, mbox_sts) !=
  295. QLA_SUCCESS) {
  296. DEBUG2(printk(KERN_WARNING "scsi%ld: %s: "
  297. "MBOX_CMD_GET_INIT_FW_CTRL_BLOCK"
  298. " failed w/ status %04X\n",
  299. ha->host_no, __func__, mbox_sts[0]));
  300. return QLA_ERROR;
  301. }
  302. return QLA_SUCCESS;
  303. }
  304. static void
  305. qla4xxx_update_local_ip(struct scsi_qla_host *ha,
  306. struct addr_ctrl_blk *init_fw_cb)
  307. {
  308. /* Save IPv4 Address Info */
  309. memcpy(ha->ip_address, init_fw_cb->ipv4_addr,
  310. min(sizeof(ha->ip_address), sizeof(init_fw_cb->ipv4_addr)));
  311. memcpy(ha->subnet_mask, init_fw_cb->ipv4_subnet,
  312. min(sizeof(ha->subnet_mask), sizeof(init_fw_cb->ipv4_subnet)));
  313. memcpy(ha->gateway, init_fw_cb->ipv4_gw_addr,
  314. min(sizeof(ha->gateway), sizeof(init_fw_cb->ipv4_gw_addr)));
  315. if (is_ipv6_enabled(ha)) {
  316. /* Save IPv6 Address */
  317. ha->ipv6_link_local_state = init_fw_cb->ipv6_lnk_lcl_addr_state;
  318. ha->ipv6_addr0_state = init_fw_cb->ipv6_addr0_state;
  319. ha->ipv6_addr1_state = init_fw_cb->ipv6_addr1_state;
  320. ha->ipv6_default_router_state = init_fw_cb->ipv6_dflt_rtr_state;
  321. ha->ipv6_link_local_addr.in6_u.u6_addr8[0] = 0xFE;
  322. ha->ipv6_link_local_addr.in6_u.u6_addr8[1] = 0x80;
  323. memcpy(&ha->ipv6_link_local_addr.in6_u.u6_addr8[8],
  324. init_fw_cb->ipv6_if_id,
  325. min(sizeof(ha->ipv6_link_local_addr)/2,
  326. sizeof(init_fw_cb->ipv6_if_id)));
  327. memcpy(&ha->ipv6_addr0, init_fw_cb->ipv6_addr0,
  328. min(sizeof(ha->ipv6_addr0),
  329. sizeof(init_fw_cb->ipv6_addr0)));
  330. memcpy(&ha->ipv6_addr1, init_fw_cb->ipv6_addr1,
  331. min(sizeof(ha->ipv6_addr1),
  332. sizeof(init_fw_cb->ipv6_addr1)));
  333. memcpy(&ha->ipv6_default_router_addr,
  334. init_fw_cb->ipv6_dflt_rtr_addr,
  335. min(sizeof(ha->ipv6_default_router_addr),
  336. sizeof(init_fw_cb->ipv6_dflt_rtr_addr)));
  337. }
  338. }
  339. static uint8_t
  340. qla4xxx_update_local_ifcb(struct scsi_qla_host *ha,
  341. uint32_t *mbox_cmd,
  342. uint32_t *mbox_sts,
  343. struct addr_ctrl_blk *init_fw_cb,
  344. dma_addr_t init_fw_cb_dma)
  345. {
  346. if (qla4xxx_get_ifcb(ha, mbox_cmd, mbox_sts, init_fw_cb_dma)
  347. != QLA_SUCCESS) {
  348. DEBUG2(printk(KERN_WARNING
  349. "scsi%ld: %s: Failed to get init_fw_ctrl_blk\n",
  350. ha->host_no, __func__));
  351. return QLA_ERROR;
  352. }
  353. DEBUG2(qla4xxx_dump_buffer(init_fw_cb, sizeof(struct addr_ctrl_blk)));
  354. /* Save some info in adapter structure. */
  355. ha->acb_version = init_fw_cb->acb_version;
  356. ha->firmware_options = le16_to_cpu(init_fw_cb->fw_options);
  357. ha->tcp_options = le16_to_cpu(init_fw_cb->ipv4_tcp_opts);
  358. ha->ipv4_options = le16_to_cpu(init_fw_cb->ipv4_ip_opts);
  359. ha->ipv4_addr_state = le16_to_cpu(init_fw_cb->ipv4_addr_state);
  360. ha->heartbeat_interval = init_fw_cb->hb_interval;
  361. memcpy(ha->name_string, init_fw_cb->iscsi_name,
  362. min(sizeof(ha->name_string),
  363. sizeof(init_fw_cb->iscsi_name)));
  364. /*memcpy(ha->alias, init_fw_cb->Alias,
  365. min(sizeof(ha->alias), sizeof(init_fw_cb->Alias)));*/
  366. /* Save Command Line Paramater info */
  367. ha->discovery_wait = ql4xdiscoverywait;
  368. if (ha->acb_version == ACB_SUPPORTED) {
  369. ha->ipv6_options = init_fw_cb->ipv6_opts;
  370. ha->ipv6_addl_options = init_fw_cb->ipv6_addtl_opts;
  371. }
  372. qla4xxx_update_local_ip(ha, init_fw_cb);
  373. return QLA_SUCCESS;
  374. }
  375. /**
  376. * qla4xxx_initialize_fw_cb - initializes firmware control block.
  377. * @ha: Pointer to host adapter structure.
  378. **/
  379. int qla4xxx_initialize_fw_cb(struct scsi_qla_host * ha)
  380. {
  381. struct addr_ctrl_blk *init_fw_cb;
  382. dma_addr_t init_fw_cb_dma;
  383. uint32_t mbox_cmd[MBOX_REG_COUNT];
  384. uint32_t mbox_sts[MBOX_REG_COUNT];
  385. int status = QLA_ERROR;
  386. init_fw_cb = dma_alloc_coherent(&ha->pdev->dev,
  387. sizeof(struct addr_ctrl_blk),
  388. &init_fw_cb_dma, GFP_KERNEL);
  389. if (init_fw_cb == NULL) {
  390. DEBUG2(printk("scsi%ld: %s: Unable to alloc init_cb\n",
  391. ha->host_no, __func__));
  392. goto exit_init_fw_cb_no_free;
  393. }
  394. memset(init_fw_cb, 0, sizeof(struct addr_ctrl_blk));
  395. /* Get Initialize Firmware Control Block. */
  396. memset(&mbox_cmd, 0, sizeof(mbox_cmd));
  397. memset(&mbox_sts, 0, sizeof(mbox_sts));
  398. if (qla4xxx_get_ifcb(ha, &mbox_cmd[0], &mbox_sts[0], init_fw_cb_dma) !=
  399. QLA_SUCCESS) {
  400. dma_free_coherent(&ha->pdev->dev,
  401. sizeof(struct addr_ctrl_blk),
  402. init_fw_cb, init_fw_cb_dma);
  403. goto exit_init_fw_cb;
  404. }
  405. /* Initialize request and response queues. */
  406. qla4xxx_init_rings(ha);
  407. /* Fill in the request and response queue information. */
  408. init_fw_cb->rqq_consumer_idx = cpu_to_le16(ha->request_out);
  409. init_fw_cb->compq_producer_idx = cpu_to_le16(ha->response_in);
  410. init_fw_cb->rqq_len = __constant_cpu_to_le16(REQUEST_QUEUE_DEPTH);
  411. init_fw_cb->compq_len = __constant_cpu_to_le16(RESPONSE_QUEUE_DEPTH);
  412. init_fw_cb->rqq_addr_lo = cpu_to_le32(LSDW(ha->request_dma));
  413. init_fw_cb->rqq_addr_hi = cpu_to_le32(MSDW(ha->request_dma));
  414. init_fw_cb->compq_addr_lo = cpu_to_le32(LSDW(ha->response_dma));
  415. init_fw_cb->compq_addr_hi = cpu_to_le32(MSDW(ha->response_dma));
  416. init_fw_cb->shdwreg_addr_lo = cpu_to_le32(LSDW(ha->shadow_regs_dma));
  417. init_fw_cb->shdwreg_addr_hi = cpu_to_le32(MSDW(ha->shadow_regs_dma));
  418. /* Set up required options. */
  419. init_fw_cb->fw_options |=
  420. __constant_cpu_to_le16(FWOPT_SESSION_MODE |
  421. FWOPT_INITIATOR_MODE);
  422. if (is_qla8022(ha))
  423. init_fw_cb->fw_options |=
  424. __constant_cpu_to_le16(FWOPT_ENABLE_CRBDB);
  425. init_fw_cb->fw_options &= __constant_cpu_to_le16(~FWOPT_TARGET_MODE);
  426. if (qla4xxx_set_ifcb(ha, &mbox_cmd[0], &mbox_sts[0], init_fw_cb_dma)
  427. != QLA_SUCCESS) {
  428. DEBUG2(printk(KERN_WARNING
  429. "scsi%ld: %s: Failed to set init_fw_ctrl_blk\n",
  430. ha->host_no, __func__));
  431. goto exit_init_fw_cb;
  432. }
  433. if (qla4xxx_update_local_ifcb(ha, &mbox_cmd[0], &mbox_sts[0],
  434. init_fw_cb, init_fw_cb_dma) != QLA_SUCCESS) {
  435. DEBUG2(printk("scsi%ld: %s: Failed to update local ifcb\n",
  436. ha->host_no, __func__));
  437. goto exit_init_fw_cb;
  438. }
  439. status = QLA_SUCCESS;
  440. exit_init_fw_cb:
  441. dma_free_coherent(&ha->pdev->dev, sizeof(struct addr_ctrl_blk),
  442. init_fw_cb, init_fw_cb_dma);
  443. exit_init_fw_cb_no_free:
  444. return status;
  445. }
  446. /**
  447. * qla4xxx_get_dhcp_ip_address - gets HBA ip address via DHCP
  448. * @ha: Pointer to host adapter structure.
  449. **/
  450. int qla4xxx_get_dhcp_ip_address(struct scsi_qla_host * ha)
  451. {
  452. struct addr_ctrl_blk *init_fw_cb;
  453. dma_addr_t init_fw_cb_dma;
  454. uint32_t mbox_cmd[MBOX_REG_COUNT];
  455. uint32_t mbox_sts[MBOX_REG_COUNT];
  456. init_fw_cb = dma_alloc_coherent(&ha->pdev->dev,
  457. sizeof(struct addr_ctrl_blk),
  458. &init_fw_cb_dma, GFP_KERNEL);
  459. if (init_fw_cb == NULL) {
  460. printk("scsi%ld: %s: Unable to alloc init_cb\n", ha->host_no,
  461. __func__);
  462. return QLA_ERROR;
  463. }
  464. /* Get Initialize Firmware Control Block. */
  465. memset(init_fw_cb, 0, sizeof(struct addr_ctrl_blk));
  466. if (qla4xxx_get_ifcb(ha, &mbox_cmd[0], &mbox_sts[0], init_fw_cb_dma) !=
  467. QLA_SUCCESS) {
  468. DEBUG2(printk("scsi%ld: %s: Failed to get init_fw_ctrl_blk\n",
  469. ha->host_no, __func__));
  470. dma_free_coherent(&ha->pdev->dev,
  471. sizeof(struct addr_ctrl_blk),
  472. init_fw_cb, init_fw_cb_dma);
  473. return QLA_ERROR;
  474. }
  475. /* Save IP Address. */
  476. qla4xxx_update_local_ip(ha, init_fw_cb);
  477. dma_free_coherent(&ha->pdev->dev, sizeof(struct addr_ctrl_blk),
  478. init_fw_cb, init_fw_cb_dma);
  479. return QLA_SUCCESS;
  480. }
  481. /**
  482. * qla4xxx_get_firmware_state - gets firmware state of HBA
  483. * @ha: Pointer to host adapter structure.
  484. **/
  485. int qla4xxx_get_firmware_state(struct scsi_qla_host * ha)
  486. {
  487. uint32_t mbox_cmd[MBOX_REG_COUNT];
  488. uint32_t mbox_sts[MBOX_REG_COUNT];
  489. /* Get firmware version */
  490. memset(&mbox_cmd, 0, sizeof(mbox_cmd));
  491. memset(&mbox_sts, 0, sizeof(mbox_sts));
  492. mbox_cmd[0] = MBOX_CMD_GET_FW_STATE;
  493. if (qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 4, &mbox_cmd[0], &mbox_sts[0]) !=
  494. QLA_SUCCESS) {
  495. DEBUG2(printk("scsi%ld: %s: MBOX_CMD_GET_FW_STATE failed w/ "
  496. "status %04X\n", ha->host_no, __func__,
  497. mbox_sts[0]));
  498. return QLA_ERROR;
  499. }
  500. ha->firmware_state = mbox_sts[1];
  501. ha->board_id = mbox_sts[2];
  502. ha->addl_fw_state = mbox_sts[3];
  503. DEBUG2(printk("scsi%ld: %s firmware_state=0x%x\n",
  504. ha->host_no, __func__, ha->firmware_state);)
  505. return QLA_SUCCESS;
  506. }
  507. /**
  508. * qla4xxx_get_firmware_status - retrieves firmware status
  509. * @ha: Pointer to host adapter structure.
  510. **/
  511. int qla4xxx_get_firmware_status(struct scsi_qla_host * ha)
  512. {
  513. uint32_t mbox_cmd[MBOX_REG_COUNT];
  514. uint32_t mbox_sts[MBOX_REG_COUNT];
  515. /* Get firmware version */
  516. memset(&mbox_cmd, 0, sizeof(mbox_cmd));
  517. memset(&mbox_sts, 0, sizeof(mbox_sts));
  518. mbox_cmd[0] = MBOX_CMD_GET_FW_STATUS;
  519. if (qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 3, &mbox_cmd[0], &mbox_sts[0]) !=
  520. QLA_SUCCESS) {
  521. DEBUG2(printk("scsi%ld: %s: MBOX_CMD_GET_FW_STATUS failed w/ "
  522. "status %04X\n", ha->host_no, __func__,
  523. mbox_sts[0]));
  524. return QLA_ERROR;
  525. }
  526. ql4_printk(KERN_INFO, ha, "%ld firmare IOCBs available (%d).\n",
  527. ha->host_no, mbox_sts[2]);
  528. return QLA_SUCCESS;
  529. }
  530. /**
  531. * qla4xxx_get_fwddb_entry - retrieves firmware ddb entry
  532. * @ha: Pointer to host adapter structure.
  533. * @fw_ddb_index: Firmware's device database index
  534. * @fw_ddb_entry: Pointer to firmware's device database entry structure
  535. * @num_valid_ddb_entries: Pointer to number of valid ddb entries
  536. * @next_ddb_index: Pointer to next valid device database index
  537. * @fw_ddb_device_state: Pointer to device state
  538. **/
  539. int qla4xxx_get_fwddb_entry(struct scsi_qla_host *ha,
  540. uint16_t fw_ddb_index,
  541. struct dev_db_entry *fw_ddb_entry,
  542. dma_addr_t fw_ddb_entry_dma,
  543. uint32_t *num_valid_ddb_entries,
  544. uint32_t *next_ddb_index,
  545. uint32_t *fw_ddb_device_state,
  546. uint32_t *conn_err_detail,
  547. uint16_t *tcp_source_port_num,
  548. uint16_t *connection_id)
  549. {
  550. int status = QLA_ERROR;
  551. uint16_t options;
  552. uint32_t mbox_cmd[MBOX_REG_COUNT];
  553. uint32_t mbox_sts[MBOX_REG_COUNT];
  554. /* Make sure the device index is valid */
  555. if (fw_ddb_index >= MAX_DDB_ENTRIES) {
  556. DEBUG2(printk("scsi%ld: %s: ddb [%d] out of range.\n",
  557. ha->host_no, __func__, fw_ddb_index));
  558. goto exit_get_fwddb;
  559. }
  560. memset(&mbox_cmd, 0, sizeof(mbox_cmd));
  561. memset(&mbox_sts, 0, sizeof(mbox_sts));
  562. mbox_cmd[0] = MBOX_CMD_GET_DATABASE_ENTRY;
  563. mbox_cmd[1] = (uint32_t) fw_ddb_index;
  564. mbox_cmd[2] = LSDW(fw_ddb_entry_dma);
  565. mbox_cmd[3] = MSDW(fw_ddb_entry_dma);
  566. mbox_cmd[4] = sizeof(struct dev_db_entry);
  567. if (qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 7, &mbox_cmd[0], &mbox_sts[0]) ==
  568. QLA_ERROR) {
  569. DEBUG2(printk("scsi%ld: %s: MBOX_CMD_GET_DATABASE_ENTRY failed"
  570. " with status 0x%04X\n", ha->host_no, __func__,
  571. mbox_sts[0]));
  572. goto exit_get_fwddb;
  573. }
  574. if (fw_ddb_index != mbox_sts[1]) {
  575. DEBUG2(printk("scsi%ld: %s: ddb mismatch [%d] != [%d].\n",
  576. ha->host_no, __func__, fw_ddb_index,
  577. mbox_sts[1]));
  578. goto exit_get_fwddb;
  579. }
  580. if (fw_ddb_entry) {
  581. options = le16_to_cpu(fw_ddb_entry->options);
  582. if (options & DDB_OPT_IPV6_DEVICE) {
  583. ql4_printk(KERN_INFO, ha, "%s: DDB[%d] MB0 %04x Tot %d "
  584. "Next %d State %04x ConnErr %08x %pI6 "
  585. ":%04d \"%s\"\n", __func__, fw_ddb_index,
  586. mbox_sts[0], mbox_sts[2], mbox_sts[3],
  587. mbox_sts[4], mbox_sts[5],
  588. fw_ddb_entry->ip_addr,
  589. le16_to_cpu(fw_ddb_entry->port),
  590. fw_ddb_entry->iscsi_name);
  591. } else {
  592. ql4_printk(KERN_INFO, ha, "%s: DDB[%d] MB0 %04x Tot %d "
  593. "Next %d State %04x ConnErr %08x %pI4 "
  594. ":%04d \"%s\"\n", __func__, fw_ddb_index,
  595. mbox_sts[0], mbox_sts[2], mbox_sts[3],
  596. mbox_sts[4], mbox_sts[5],
  597. fw_ddb_entry->ip_addr,
  598. le16_to_cpu(fw_ddb_entry->port),
  599. fw_ddb_entry->iscsi_name);
  600. }
  601. }
  602. if (num_valid_ddb_entries)
  603. *num_valid_ddb_entries = mbox_sts[2];
  604. if (next_ddb_index)
  605. *next_ddb_index = mbox_sts[3];
  606. if (fw_ddb_device_state)
  607. *fw_ddb_device_state = mbox_sts[4];
  608. /*
  609. * RA: This mailbox has been changed to pass connection error and
  610. * details. Its true for ISP4010 as per Version E - Not sure when it
  611. * was changed. Get the time2wait from the fw_dd_entry field :
  612. * default_time2wait which we call it as minTime2Wait DEV_DB_ENTRY
  613. * struct.
  614. */
  615. if (conn_err_detail)
  616. *conn_err_detail = mbox_sts[5];
  617. if (tcp_source_port_num)
  618. *tcp_source_port_num = (uint16_t) (mbox_sts[6] >> 16);
  619. if (connection_id)
  620. *connection_id = (uint16_t) mbox_sts[6] & 0x00FF;
  621. status = QLA_SUCCESS;
  622. exit_get_fwddb:
  623. return status;
  624. }
  625. /**
  626. * qla4xxx_set_fwddb_entry - sets a ddb entry.
  627. * @ha: Pointer to host adapter structure.
  628. * @fw_ddb_index: Firmware's device database index
  629. * @fw_ddb_entry: Pointer to firmware's ddb entry structure, or NULL.
  630. *
  631. * This routine initializes or updates the adapter's device database
  632. * entry for the specified device. It also triggers a login for the
  633. * specified device. Therefore, it may also be used as a secondary
  634. * login routine when a NULL pointer is specified for the fw_ddb_entry.
  635. **/
  636. int qla4xxx_set_ddb_entry(struct scsi_qla_host * ha, uint16_t fw_ddb_index,
  637. dma_addr_t fw_ddb_entry_dma)
  638. {
  639. uint32_t mbox_cmd[MBOX_REG_COUNT];
  640. uint32_t mbox_sts[MBOX_REG_COUNT];
  641. int status;
  642. /* Do not wait for completion. The firmware will send us an
  643. * ASTS_DATABASE_CHANGED (0x8014) to notify us of the login status.
  644. */
  645. memset(&mbox_cmd, 0, sizeof(mbox_cmd));
  646. memset(&mbox_sts, 0, sizeof(mbox_sts));
  647. mbox_cmd[0] = MBOX_CMD_SET_DATABASE_ENTRY;
  648. mbox_cmd[1] = (uint32_t) fw_ddb_index;
  649. mbox_cmd[2] = LSDW(fw_ddb_entry_dma);
  650. mbox_cmd[3] = MSDW(fw_ddb_entry_dma);
  651. mbox_cmd[4] = sizeof(struct dev_db_entry);
  652. status = qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 5, &mbox_cmd[0],
  653. &mbox_sts[0]);
  654. DEBUG2(printk("scsi%ld: %s: status=%d mbx0=0x%x mbx4=0x%x\n",
  655. ha->host_no, __func__, status, mbox_sts[0], mbox_sts[4]);)
  656. return status;
  657. }
  658. /**
  659. * qla4xxx_get_crash_record - retrieves crash record.
  660. * @ha: Pointer to host adapter structure.
  661. *
  662. * This routine retrieves a crash record from the QLA4010 after an 8002h aen.
  663. **/
  664. void qla4xxx_get_crash_record(struct scsi_qla_host * ha)
  665. {
  666. uint32_t mbox_cmd[MBOX_REG_COUNT];
  667. uint32_t mbox_sts[MBOX_REG_COUNT];
  668. struct crash_record *crash_record = NULL;
  669. dma_addr_t crash_record_dma = 0;
  670. uint32_t crash_record_size = 0;
  671. memset(&mbox_cmd, 0, sizeof(mbox_cmd));
  672. memset(&mbox_sts, 0, sizeof(mbox_cmd));
  673. /* Get size of crash record. */
  674. mbox_cmd[0] = MBOX_CMD_GET_CRASH_RECORD;
  675. if (qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 5, &mbox_cmd[0], &mbox_sts[0]) !=
  676. QLA_SUCCESS) {
  677. DEBUG2(printk("scsi%ld: %s: ERROR: Unable to retrieve size!\n",
  678. ha->host_no, __func__));
  679. goto exit_get_crash_record;
  680. }
  681. crash_record_size = mbox_sts[4];
  682. if (crash_record_size == 0) {
  683. DEBUG2(printk("scsi%ld: %s: ERROR: Crash record size is 0!\n",
  684. ha->host_no, __func__));
  685. goto exit_get_crash_record;
  686. }
  687. /* Alloc Memory for Crash Record. */
  688. crash_record = dma_alloc_coherent(&ha->pdev->dev, crash_record_size,
  689. &crash_record_dma, GFP_KERNEL);
  690. if (crash_record == NULL)
  691. goto exit_get_crash_record;
  692. /* Get Crash Record. */
  693. memset(&mbox_cmd, 0, sizeof(mbox_cmd));
  694. memset(&mbox_sts, 0, sizeof(mbox_cmd));
  695. mbox_cmd[0] = MBOX_CMD_GET_CRASH_RECORD;
  696. mbox_cmd[2] = LSDW(crash_record_dma);
  697. mbox_cmd[3] = MSDW(crash_record_dma);
  698. mbox_cmd[4] = crash_record_size;
  699. if (qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 5, &mbox_cmd[0], &mbox_sts[0]) !=
  700. QLA_SUCCESS)
  701. goto exit_get_crash_record;
  702. /* Dump Crash Record. */
  703. exit_get_crash_record:
  704. if (crash_record)
  705. dma_free_coherent(&ha->pdev->dev, crash_record_size,
  706. crash_record, crash_record_dma);
  707. }
  708. /**
  709. * qla4xxx_get_conn_event_log - retrieves connection event log
  710. * @ha: Pointer to host adapter structure.
  711. **/
  712. void qla4xxx_get_conn_event_log(struct scsi_qla_host * ha)
  713. {
  714. uint32_t mbox_cmd[MBOX_REG_COUNT];
  715. uint32_t mbox_sts[MBOX_REG_COUNT];
  716. struct conn_event_log_entry *event_log = NULL;
  717. dma_addr_t event_log_dma = 0;
  718. uint32_t event_log_size = 0;
  719. uint32_t num_valid_entries;
  720. uint32_t oldest_entry = 0;
  721. uint32_t max_event_log_entries;
  722. uint8_t i;
  723. memset(&mbox_cmd, 0, sizeof(mbox_cmd));
  724. memset(&mbox_sts, 0, sizeof(mbox_cmd));
  725. /* Get size of crash record. */
  726. mbox_cmd[0] = MBOX_CMD_GET_CONN_EVENT_LOG;
  727. if (qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 5, &mbox_cmd[0], &mbox_sts[0]) !=
  728. QLA_SUCCESS)
  729. goto exit_get_event_log;
  730. event_log_size = mbox_sts[4];
  731. if (event_log_size == 0)
  732. goto exit_get_event_log;
  733. /* Alloc Memory for Crash Record. */
  734. event_log = dma_alloc_coherent(&ha->pdev->dev, event_log_size,
  735. &event_log_dma, GFP_KERNEL);
  736. if (event_log == NULL)
  737. goto exit_get_event_log;
  738. /* Get Crash Record. */
  739. memset(&mbox_cmd, 0, sizeof(mbox_cmd));
  740. memset(&mbox_sts, 0, sizeof(mbox_cmd));
  741. mbox_cmd[0] = MBOX_CMD_GET_CONN_EVENT_LOG;
  742. mbox_cmd[2] = LSDW(event_log_dma);
  743. mbox_cmd[3] = MSDW(event_log_dma);
  744. if (qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 5, &mbox_cmd[0], &mbox_sts[0]) !=
  745. QLA_SUCCESS) {
  746. DEBUG2(printk("scsi%ld: %s: ERROR: Unable to retrieve event "
  747. "log!\n", ha->host_no, __func__));
  748. goto exit_get_event_log;
  749. }
  750. /* Dump Event Log. */
  751. num_valid_entries = mbox_sts[1];
  752. max_event_log_entries = event_log_size /
  753. sizeof(struct conn_event_log_entry);
  754. if (num_valid_entries > max_event_log_entries)
  755. oldest_entry = num_valid_entries % max_event_log_entries;
  756. DEBUG3(printk("scsi%ld: Connection Event Log Dump (%d entries):\n",
  757. ha->host_no, num_valid_entries));
  758. if (ql4xextended_error_logging == 3) {
  759. if (oldest_entry == 0) {
  760. /* Circular Buffer has not wrapped around */
  761. for (i=0; i < num_valid_entries; i++) {
  762. qla4xxx_dump_buffer((uint8_t *)event_log+
  763. (i*sizeof(*event_log)),
  764. sizeof(*event_log));
  765. }
  766. }
  767. else {
  768. /* Circular Buffer has wrapped around -
  769. * display accordingly*/
  770. for (i=oldest_entry; i < max_event_log_entries; i++) {
  771. qla4xxx_dump_buffer((uint8_t *)event_log+
  772. (i*sizeof(*event_log)),
  773. sizeof(*event_log));
  774. }
  775. for (i=0; i < oldest_entry; i++) {
  776. qla4xxx_dump_buffer((uint8_t *)event_log+
  777. (i*sizeof(*event_log)),
  778. sizeof(*event_log));
  779. }
  780. }
  781. }
  782. exit_get_event_log:
  783. if (event_log)
  784. dma_free_coherent(&ha->pdev->dev, event_log_size, event_log,
  785. event_log_dma);
  786. }
  787. /**
  788. * qla4xxx_abort_task - issues Abort Task
  789. * @ha: Pointer to host adapter structure.
  790. * @srb: Pointer to srb entry
  791. *
  792. * This routine performs a LUN RESET on the specified target/lun.
  793. * The caller must ensure that the ddb_entry and lun_entry pointers
  794. * are valid before calling this routine.
  795. **/
  796. int qla4xxx_abort_task(struct scsi_qla_host *ha, struct srb *srb)
  797. {
  798. uint32_t mbox_cmd[MBOX_REG_COUNT];
  799. uint32_t mbox_sts[MBOX_REG_COUNT];
  800. struct scsi_cmnd *cmd = srb->cmd;
  801. int status = QLA_SUCCESS;
  802. unsigned long flags = 0;
  803. uint32_t index;
  804. /*
  805. * Send abort task command to ISP, so that the ISP will return
  806. * request with ABORT status
  807. */
  808. memset(&mbox_cmd, 0, sizeof(mbox_cmd));
  809. memset(&mbox_sts, 0, sizeof(mbox_sts));
  810. spin_lock_irqsave(&ha->hardware_lock, flags);
  811. index = (unsigned long)(unsigned char *)cmd->host_scribble;
  812. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  813. /* Firmware already posted completion on response queue */
  814. if (index == MAX_SRBS)
  815. return status;
  816. mbox_cmd[0] = MBOX_CMD_ABORT_TASK;
  817. mbox_cmd[1] = srb->ddb->fw_ddb_index;
  818. mbox_cmd[2] = index;
  819. /* Immediate Command Enable */
  820. mbox_cmd[5] = 0x01;
  821. qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 5, &mbox_cmd[0],
  822. &mbox_sts[0]);
  823. if (mbox_sts[0] != MBOX_STS_COMMAND_COMPLETE) {
  824. status = QLA_ERROR;
  825. DEBUG2(printk(KERN_WARNING "scsi%ld:%d:%d: abort task FAILED: "
  826. "mbx0=%04X, mb1=%04X, mb2=%04X, mb3=%04X, mb4=%04X\n",
  827. ha->host_no, cmd->device->id, cmd->device->lun, mbox_sts[0],
  828. mbox_sts[1], mbox_sts[2], mbox_sts[3], mbox_sts[4]));
  829. }
  830. return status;
  831. }
  832. /**
  833. * qla4xxx_reset_lun - issues LUN Reset
  834. * @ha: Pointer to host adapter structure.
  835. * @ddb_entry: Pointer to device database entry
  836. * @lun: lun number
  837. *
  838. * This routine performs a LUN RESET on the specified target/lun.
  839. * The caller must ensure that the ddb_entry and lun_entry pointers
  840. * are valid before calling this routine.
  841. **/
  842. int qla4xxx_reset_lun(struct scsi_qla_host * ha, struct ddb_entry * ddb_entry,
  843. int lun)
  844. {
  845. uint32_t mbox_cmd[MBOX_REG_COUNT];
  846. uint32_t mbox_sts[MBOX_REG_COUNT];
  847. int status = QLA_SUCCESS;
  848. DEBUG2(printk("scsi%ld:%d:%d: lun reset issued\n", ha->host_no,
  849. ddb_entry->fw_ddb_index, lun));
  850. /*
  851. * Send lun reset command to ISP, so that the ISP will return all
  852. * outstanding requests with RESET status
  853. */
  854. memset(&mbox_cmd, 0, sizeof(mbox_cmd));
  855. memset(&mbox_sts, 0, sizeof(mbox_sts));
  856. mbox_cmd[0] = MBOX_CMD_LUN_RESET;
  857. mbox_cmd[1] = ddb_entry->fw_ddb_index;
  858. mbox_cmd[2] = lun << 8;
  859. mbox_cmd[5] = 0x01; /* Immediate Command Enable */
  860. qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 1, &mbox_cmd[0], &mbox_sts[0]);
  861. if (mbox_sts[0] != MBOX_STS_COMMAND_COMPLETE &&
  862. mbox_sts[0] != MBOX_STS_COMMAND_ERROR)
  863. status = QLA_ERROR;
  864. return status;
  865. }
  866. /**
  867. * qla4xxx_reset_target - issues target Reset
  868. * @ha: Pointer to host adapter structure.
  869. * @db_entry: Pointer to device database entry
  870. * @un_entry: Pointer to lun entry structure
  871. *
  872. * This routine performs a TARGET RESET on the specified target.
  873. * The caller must ensure that the ddb_entry pointers
  874. * are valid before calling this routine.
  875. **/
  876. int qla4xxx_reset_target(struct scsi_qla_host *ha,
  877. struct ddb_entry *ddb_entry)
  878. {
  879. uint32_t mbox_cmd[MBOX_REG_COUNT];
  880. uint32_t mbox_sts[MBOX_REG_COUNT];
  881. int status = QLA_SUCCESS;
  882. DEBUG2(printk("scsi%ld:%d: target reset issued\n", ha->host_no,
  883. ddb_entry->fw_ddb_index));
  884. /*
  885. * Send target reset command to ISP, so that the ISP will return all
  886. * outstanding requests with RESET status
  887. */
  888. memset(&mbox_cmd, 0, sizeof(mbox_cmd));
  889. memset(&mbox_sts, 0, sizeof(mbox_sts));
  890. mbox_cmd[0] = MBOX_CMD_TARGET_WARM_RESET;
  891. mbox_cmd[1] = ddb_entry->fw_ddb_index;
  892. mbox_cmd[5] = 0x01; /* Immediate Command Enable */
  893. qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 1, &mbox_cmd[0],
  894. &mbox_sts[0]);
  895. if (mbox_sts[0] != MBOX_STS_COMMAND_COMPLETE &&
  896. mbox_sts[0] != MBOX_STS_COMMAND_ERROR)
  897. status = QLA_ERROR;
  898. return status;
  899. }
  900. int qla4xxx_get_flash(struct scsi_qla_host * ha, dma_addr_t dma_addr,
  901. uint32_t offset, uint32_t len)
  902. {
  903. uint32_t mbox_cmd[MBOX_REG_COUNT];
  904. uint32_t mbox_sts[MBOX_REG_COUNT];
  905. memset(&mbox_cmd, 0, sizeof(mbox_cmd));
  906. memset(&mbox_sts, 0, sizeof(mbox_sts));
  907. mbox_cmd[0] = MBOX_CMD_READ_FLASH;
  908. mbox_cmd[1] = LSDW(dma_addr);
  909. mbox_cmd[2] = MSDW(dma_addr);
  910. mbox_cmd[3] = offset;
  911. mbox_cmd[4] = len;
  912. if (qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 2, &mbox_cmd[0], &mbox_sts[0]) !=
  913. QLA_SUCCESS) {
  914. DEBUG2(printk("scsi%ld: %s: MBOX_CMD_READ_FLASH, failed w/ "
  915. "status %04X %04X, offset %08x, len %08x\n", ha->host_no,
  916. __func__, mbox_sts[0], mbox_sts[1], offset, len));
  917. return QLA_ERROR;
  918. }
  919. return QLA_SUCCESS;
  920. }
  921. /**
  922. * qla4xxx_get_fw_version - gets firmware version
  923. * @ha: Pointer to host adapter structure.
  924. *
  925. * Retrieves the firmware version on HBA. In QLA4010, mailboxes 2 & 3 may
  926. * hold an address for data. Make sure that we write 0 to those mailboxes,
  927. * if unused.
  928. **/
  929. int qla4xxx_get_fw_version(struct scsi_qla_host * ha)
  930. {
  931. uint32_t mbox_cmd[MBOX_REG_COUNT];
  932. uint32_t mbox_sts[MBOX_REG_COUNT];
  933. /* Get firmware version. */
  934. memset(&mbox_cmd, 0, sizeof(mbox_cmd));
  935. memset(&mbox_sts, 0, sizeof(mbox_sts));
  936. mbox_cmd[0] = MBOX_CMD_ABOUT_FW;
  937. if (qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 5, &mbox_cmd[0], &mbox_sts[0]) !=
  938. QLA_SUCCESS) {
  939. DEBUG2(printk("scsi%ld: %s: MBOX_CMD_ABOUT_FW failed w/ "
  940. "status %04X\n", ha->host_no, __func__, mbox_sts[0]));
  941. return QLA_ERROR;
  942. }
  943. /* Save firmware version information. */
  944. ha->firmware_version[0] = mbox_sts[1];
  945. ha->firmware_version[1] = mbox_sts[2];
  946. ha->patch_number = mbox_sts[3];
  947. ha->build_number = mbox_sts[4];
  948. return QLA_SUCCESS;
  949. }
  950. static int qla4xxx_get_default_ddb(struct scsi_qla_host *ha,
  951. dma_addr_t dma_addr)
  952. {
  953. uint32_t mbox_cmd[MBOX_REG_COUNT];
  954. uint32_t mbox_sts[MBOX_REG_COUNT];
  955. memset(&mbox_cmd, 0, sizeof(mbox_cmd));
  956. memset(&mbox_sts, 0, sizeof(mbox_sts));
  957. mbox_cmd[0] = MBOX_CMD_GET_DATABASE_ENTRY_DEFAULTS;
  958. mbox_cmd[2] = LSDW(dma_addr);
  959. mbox_cmd[3] = MSDW(dma_addr);
  960. if (qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 1, &mbox_cmd[0], &mbox_sts[0]) !=
  961. QLA_SUCCESS) {
  962. DEBUG2(printk("scsi%ld: %s: failed status %04X\n",
  963. ha->host_no, __func__, mbox_sts[0]));
  964. return QLA_ERROR;
  965. }
  966. return QLA_SUCCESS;
  967. }
  968. static int qla4xxx_req_ddb_entry(struct scsi_qla_host *ha, uint32_t *ddb_index)
  969. {
  970. uint32_t mbox_cmd[MBOX_REG_COUNT];
  971. uint32_t mbox_sts[MBOX_REG_COUNT];
  972. memset(&mbox_cmd, 0, sizeof(mbox_cmd));
  973. memset(&mbox_sts, 0, sizeof(mbox_sts));
  974. mbox_cmd[0] = MBOX_CMD_REQUEST_DATABASE_ENTRY;
  975. mbox_cmd[1] = MAX_PRST_DEV_DB_ENTRIES;
  976. if (qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 3, &mbox_cmd[0], &mbox_sts[0]) !=
  977. QLA_SUCCESS) {
  978. if (mbox_sts[0] == MBOX_STS_COMMAND_ERROR) {
  979. *ddb_index = mbox_sts[2];
  980. } else {
  981. DEBUG2(printk("scsi%ld: %s: failed status %04X\n",
  982. ha->host_no, __func__, mbox_sts[0]));
  983. return QLA_ERROR;
  984. }
  985. } else {
  986. *ddb_index = MAX_PRST_DEV_DB_ENTRIES;
  987. }
  988. return QLA_SUCCESS;
  989. }
  990. int qla4xxx_send_tgts(struct scsi_qla_host *ha, char *ip, uint16_t port)
  991. {
  992. struct dev_db_entry *fw_ddb_entry;
  993. dma_addr_t fw_ddb_entry_dma;
  994. uint32_t ddb_index;
  995. int ret_val = QLA_SUCCESS;
  996. fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev,
  997. sizeof(*fw_ddb_entry),
  998. &fw_ddb_entry_dma, GFP_KERNEL);
  999. if (!fw_ddb_entry) {
  1000. DEBUG2(printk("scsi%ld: %s: Unable to allocate dma buffer.\n",
  1001. ha->host_no, __func__));
  1002. ret_val = QLA_ERROR;
  1003. goto exit_send_tgts_no_free;
  1004. }
  1005. ret_val = qla4xxx_get_default_ddb(ha, fw_ddb_entry_dma);
  1006. if (ret_val != QLA_SUCCESS)
  1007. goto exit_send_tgts;
  1008. ret_val = qla4xxx_req_ddb_entry(ha, &ddb_index);
  1009. if (ret_val != QLA_SUCCESS)
  1010. goto exit_send_tgts;
  1011. memset(fw_ddb_entry->iscsi_alias, 0,
  1012. sizeof(fw_ddb_entry->iscsi_alias));
  1013. memset(fw_ddb_entry->iscsi_name, 0,
  1014. sizeof(fw_ddb_entry->iscsi_name));
  1015. memset(fw_ddb_entry->ip_addr, 0, sizeof(fw_ddb_entry->ip_addr));
  1016. memset(fw_ddb_entry->tgt_addr, 0,
  1017. sizeof(fw_ddb_entry->tgt_addr));
  1018. fw_ddb_entry->options = (DDB_OPT_DISC_SESSION | DDB_OPT_TARGET);
  1019. fw_ddb_entry->port = cpu_to_le16(ntohs(port));
  1020. fw_ddb_entry->ip_addr[0] = *ip;
  1021. fw_ddb_entry->ip_addr[1] = *(ip + 1);
  1022. fw_ddb_entry->ip_addr[2] = *(ip + 2);
  1023. fw_ddb_entry->ip_addr[3] = *(ip + 3);
  1024. ret_val = qla4xxx_set_ddb_entry(ha, ddb_index, fw_ddb_entry_dma);
  1025. exit_send_tgts:
  1026. dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
  1027. fw_ddb_entry, fw_ddb_entry_dma);
  1028. exit_send_tgts_no_free:
  1029. return ret_val;
  1030. }