ql4_mbx.c 32 KB

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