ql4_mbx.c 54 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849
  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 issue 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. spin_lock_irqsave(&ha->hardware_lock, flags);
  81. ha->mbox_status_count = outCount;
  82. for (i = 0; i < outCount; i++)
  83. ha->mbox_status[i] = 0;
  84. if (is_qla8022(ha)) {
  85. /* Load all mailbox registers, except mailbox 0. */
  86. DEBUG5(
  87. printk("scsi%ld: %s: Cmd ", ha->host_no, __func__);
  88. for (i = 0; i < inCount; i++)
  89. printk("mb%d=%04x ", i, mbx_cmd[i]);
  90. printk("\n"));
  91. for (i = 1; i < inCount; i++)
  92. writel(mbx_cmd[i], &ha->qla4_8xxx_reg->mailbox_in[i]);
  93. writel(mbx_cmd[0], &ha->qla4_8xxx_reg->mailbox_in[0]);
  94. readl(&ha->qla4_8xxx_reg->mailbox_in[0]);
  95. writel(HINT_MBX_INT_PENDING, &ha->qla4_8xxx_reg->hint);
  96. } else {
  97. /* Load all mailbox registers, except mailbox 0. */
  98. for (i = 1; i < inCount; i++)
  99. writel(mbx_cmd[i], &ha->reg->mailbox[i]);
  100. /* Wakeup firmware */
  101. writel(mbx_cmd[0], &ha->reg->mailbox[0]);
  102. readl(&ha->reg->mailbox[0]);
  103. writel(set_rmask(CSR_INTR_RISC), &ha->reg->ctrl_status);
  104. readl(&ha->reg->ctrl_status);
  105. }
  106. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  107. /* Wait for completion */
  108. /*
  109. * If we don't want status, don't wait for the mailbox command to
  110. * complete. For example, MBOX_CMD_RESET_FW doesn't return status,
  111. * you must poll the inbound Interrupt Mask for completion.
  112. */
  113. if (outCount == 0) {
  114. status = QLA_SUCCESS;
  115. goto mbox_exit;
  116. }
  117. /*
  118. * Wait for completion: Poll or completion queue
  119. */
  120. if (test_bit(AF_IRQ_ATTACHED, &ha->flags) &&
  121. test_bit(AF_INTERRUPTS_ON, &ha->flags) &&
  122. test_bit(AF_ONLINE, &ha->flags) &&
  123. !test_bit(AF_HA_REMOVAL, &ha->flags)) {
  124. /* Do not poll for completion. Use completion queue */
  125. set_bit(AF_MBOX_COMMAND_NOPOLL, &ha->flags);
  126. wait_for_completion_timeout(&ha->mbx_intr_comp, MBOX_TOV * HZ);
  127. clear_bit(AF_MBOX_COMMAND_NOPOLL, &ha->flags);
  128. } else {
  129. /* Poll for command to complete */
  130. wait_count = jiffies + MBOX_TOV * HZ;
  131. while (test_bit(AF_MBOX_COMMAND_DONE, &ha->flags) == 0) {
  132. if (time_after_eq(jiffies, wait_count))
  133. break;
  134. /*
  135. * Service the interrupt.
  136. * The ISR will save the mailbox status registers
  137. * to a temporary storage location in the adapter
  138. * structure.
  139. */
  140. spin_lock_irqsave(&ha->hardware_lock, flags);
  141. if (is_qla8022(ha)) {
  142. intr_status =
  143. readl(&ha->qla4_8xxx_reg->host_int);
  144. if (intr_status & ISRX_82XX_RISC_INT) {
  145. ha->mbox_status_count = outCount;
  146. intr_status =
  147. readl(&ha->qla4_8xxx_reg->host_status);
  148. ha->isp_ops->interrupt_service_routine(
  149. ha, intr_status);
  150. if (test_bit(AF_INTERRUPTS_ON,
  151. &ha->flags) &&
  152. test_bit(AF_INTx_ENABLED,
  153. &ha->flags))
  154. qla4_8xxx_wr_32(ha,
  155. ha->nx_legacy_intr.tgt_mask_reg,
  156. 0xfbff);
  157. }
  158. } else {
  159. intr_status = readl(&ha->reg->ctrl_status);
  160. if (intr_status & INTR_PENDING) {
  161. /*
  162. * Service the interrupt.
  163. * The ISR will save the mailbox status
  164. * registers to a temporary storage
  165. * location in the adapter structure.
  166. */
  167. ha->mbox_status_count = outCount;
  168. ha->isp_ops->interrupt_service_routine(
  169. ha, intr_status);
  170. }
  171. }
  172. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  173. msleep(10);
  174. }
  175. }
  176. /* Check for mailbox timeout. */
  177. if (!test_bit(AF_MBOX_COMMAND_DONE, &ha->flags)) {
  178. if (is_qla8022(ha) &&
  179. test_bit(AF_FW_RECOVERY, &ha->flags)) {
  180. DEBUG2(ql4_printk(KERN_INFO, ha,
  181. "scsi%ld: %s: prematurely completing mbx cmd as "
  182. "firmware recovery detected\n",
  183. ha->host_no, __func__));
  184. goto mbox_exit;
  185. }
  186. DEBUG2(printk("scsi%ld: Mailbox Cmd 0x%08X timed out ...,"
  187. " Scheduling Adapter Reset\n", ha->host_no,
  188. mbx_cmd[0]));
  189. ha->mailbox_timeout_count++;
  190. mbx_sts[0] = (-1);
  191. set_bit(DPC_RESET_HA, &ha->dpc_flags);
  192. goto mbox_exit;
  193. }
  194. /*
  195. * Copy the mailbox out registers to the caller's mailbox in/out
  196. * structure.
  197. */
  198. spin_lock_irqsave(&ha->hardware_lock, flags);
  199. for (i = 0; i < outCount; i++)
  200. mbx_sts[i] = ha->mbox_status[i];
  201. /* Set return status and error flags (if applicable). */
  202. switch (ha->mbox_status[0]) {
  203. case MBOX_STS_COMMAND_COMPLETE:
  204. status = QLA_SUCCESS;
  205. break;
  206. case MBOX_STS_INTERMEDIATE_COMPLETION:
  207. status = QLA_SUCCESS;
  208. break;
  209. case MBOX_STS_BUSY:
  210. DEBUG2( printk("scsi%ld: %s: Cmd = %08X, ISP BUSY\n",
  211. ha->host_no, __func__, mbx_cmd[0]));
  212. ha->mailbox_timeout_count++;
  213. break;
  214. default:
  215. DEBUG2(printk("scsi%ld: %s: **** FAILED, cmd = %08X, "
  216. "sts = %08X ****\n", ha->host_no, __func__,
  217. mbx_cmd[0], mbx_sts[0]));
  218. break;
  219. }
  220. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  221. mbox_exit:
  222. mutex_lock(&ha->mbox_sem);
  223. clear_bit(AF_MBOX_COMMAND, &ha->flags);
  224. mutex_unlock(&ha->mbox_sem);
  225. clear_bit(AF_MBOX_COMMAND_DONE, &ha->flags);
  226. return status;
  227. }
  228. void qla4xxx_mailbox_premature_completion(struct scsi_qla_host *ha)
  229. {
  230. set_bit(AF_FW_RECOVERY, &ha->flags);
  231. ql4_printk(KERN_INFO, ha, "scsi%ld: %s: set FW RECOVERY!\n",
  232. ha->host_no, __func__);
  233. if (test_bit(AF_MBOX_COMMAND, &ha->flags)) {
  234. if (test_bit(AF_MBOX_COMMAND_NOPOLL, &ha->flags)) {
  235. complete(&ha->mbx_intr_comp);
  236. ql4_printk(KERN_INFO, ha, "scsi%ld: %s: Due to fw "
  237. "recovery, doing premature completion of "
  238. "mbx cmd\n", ha->host_no, __func__);
  239. } else {
  240. set_bit(AF_MBOX_COMMAND_DONE, &ha->flags);
  241. ql4_printk(KERN_INFO, ha, "scsi%ld: %s: Due to fw "
  242. "recovery, doing premature completion of "
  243. "polling mbx cmd\n", ha->host_no, __func__);
  244. }
  245. }
  246. }
  247. static uint8_t
  248. qla4xxx_set_ifcb(struct scsi_qla_host *ha, uint32_t *mbox_cmd,
  249. uint32_t *mbox_sts, dma_addr_t init_fw_cb_dma)
  250. {
  251. memset(mbox_cmd, 0, sizeof(mbox_cmd[0]) * MBOX_REG_COUNT);
  252. memset(mbox_sts, 0, sizeof(mbox_sts[0]) * MBOX_REG_COUNT);
  253. if (is_qla8022(ha))
  254. qla4_8xxx_wr_32(ha, ha->nx_db_wr_ptr, 0);
  255. mbox_cmd[0] = MBOX_CMD_INITIALIZE_FIRMWARE;
  256. mbox_cmd[1] = 0;
  257. mbox_cmd[2] = LSDW(init_fw_cb_dma);
  258. mbox_cmd[3] = MSDW(init_fw_cb_dma);
  259. mbox_cmd[4] = sizeof(struct addr_ctrl_blk);
  260. mbox_cmd[5] = (IFCB_VER_MAX << 8) | IFCB_VER_MIN;
  261. if (qla4xxx_mailbox_command(ha, 6, 6, mbox_cmd, mbox_sts) !=
  262. QLA_SUCCESS) {
  263. DEBUG2(printk(KERN_WARNING "scsi%ld: %s: "
  264. "MBOX_CMD_INITIALIZE_FIRMWARE"
  265. " failed w/ status %04X\n",
  266. ha->host_no, __func__, mbox_sts[0]));
  267. return QLA_ERROR;
  268. }
  269. return QLA_SUCCESS;
  270. }
  271. uint8_t
  272. qla4xxx_get_ifcb(struct scsi_qla_host *ha, uint32_t *mbox_cmd,
  273. uint32_t *mbox_sts, dma_addr_t init_fw_cb_dma)
  274. {
  275. memset(mbox_cmd, 0, sizeof(mbox_cmd[0]) * MBOX_REG_COUNT);
  276. memset(mbox_sts, 0, sizeof(mbox_sts[0]) * MBOX_REG_COUNT);
  277. mbox_cmd[0] = MBOX_CMD_GET_INIT_FW_CTRL_BLOCK;
  278. mbox_cmd[2] = LSDW(init_fw_cb_dma);
  279. mbox_cmd[3] = MSDW(init_fw_cb_dma);
  280. mbox_cmd[4] = sizeof(struct addr_ctrl_blk);
  281. if (qla4xxx_mailbox_command(ha, 5, 5, mbox_cmd, mbox_sts) !=
  282. QLA_SUCCESS) {
  283. DEBUG2(printk(KERN_WARNING "scsi%ld: %s: "
  284. "MBOX_CMD_GET_INIT_FW_CTRL_BLOCK"
  285. " failed w/ status %04X\n",
  286. ha->host_no, __func__, mbox_sts[0]));
  287. return QLA_ERROR;
  288. }
  289. return QLA_SUCCESS;
  290. }
  291. static void
  292. qla4xxx_update_local_ip(struct scsi_qla_host *ha,
  293. struct addr_ctrl_blk *init_fw_cb)
  294. {
  295. ha->ip_config.tcp_options = le16_to_cpu(init_fw_cb->ipv4_tcp_opts);
  296. ha->ip_config.ipv4_options = le16_to_cpu(init_fw_cb->ipv4_ip_opts);
  297. ha->ip_config.ipv4_addr_state =
  298. le16_to_cpu(init_fw_cb->ipv4_addr_state);
  299. ha->ip_config.eth_mtu_size =
  300. le16_to_cpu(init_fw_cb->eth_mtu_size);
  301. ha->ip_config.ipv4_port = le16_to_cpu(init_fw_cb->ipv4_port);
  302. if (ha->acb_version == ACB_SUPPORTED) {
  303. ha->ip_config.ipv6_options = le16_to_cpu(init_fw_cb->ipv6_opts);
  304. ha->ip_config.ipv6_addl_options =
  305. le16_to_cpu(init_fw_cb->ipv6_addtl_opts);
  306. }
  307. /* Save IPv4 Address Info */
  308. memcpy(ha->ip_config.ip_address, init_fw_cb->ipv4_addr,
  309. min(sizeof(ha->ip_config.ip_address),
  310. sizeof(init_fw_cb->ipv4_addr)));
  311. memcpy(ha->ip_config.subnet_mask, init_fw_cb->ipv4_subnet,
  312. min(sizeof(ha->ip_config.subnet_mask),
  313. sizeof(init_fw_cb->ipv4_subnet)));
  314. memcpy(ha->ip_config.gateway, init_fw_cb->ipv4_gw_addr,
  315. min(sizeof(ha->ip_config.gateway),
  316. sizeof(init_fw_cb->ipv4_gw_addr)));
  317. ha->ip_config.ipv4_vlan_tag = be16_to_cpu(init_fw_cb->ipv4_vlan_tag);
  318. if (is_ipv6_enabled(ha)) {
  319. /* Save IPv6 Address */
  320. ha->ip_config.ipv6_link_local_state =
  321. le16_to_cpu(init_fw_cb->ipv6_lnk_lcl_addr_state);
  322. ha->ip_config.ipv6_addr0_state =
  323. le16_to_cpu(init_fw_cb->ipv6_addr0_state);
  324. ha->ip_config.ipv6_addr1_state =
  325. le16_to_cpu(init_fw_cb->ipv6_addr1_state);
  326. ha->ip_config.ipv6_default_router_state =
  327. le16_to_cpu(init_fw_cb->ipv6_dflt_rtr_state);
  328. ha->ip_config.ipv6_link_local_addr.in6_u.u6_addr8[0] = 0xFE;
  329. ha->ip_config.ipv6_link_local_addr.in6_u.u6_addr8[1] = 0x80;
  330. memcpy(&ha->ip_config.ipv6_link_local_addr.in6_u.u6_addr8[8],
  331. init_fw_cb->ipv6_if_id,
  332. min(sizeof(ha->ip_config.ipv6_link_local_addr)/2,
  333. sizeof(init_fw_cb->ipv6_if_id)));
  334. memcpy(&ha->ip_config.ipv6_addr0, init_fw_cb->ipv6_addr0,
  335. min(sizeof(ha->ip_config.ipv6_addr0),
  336. sizeof(init_fw_cb->ipv6_addr0)));
  337. memcpy(&ha->ip_config.ipv6_addr1, init_fw_cb->ipv6_addr1,
  338. min(sizeof(ha->ip_config.ipv6_addr1),
  339. sizeof(init_fw_cb->ipv6_addr1)));
  340. memcpy(&ha->ip_config.ipv6_default_router_addr,
  341. init_fw_cb->ipv6_dflt_rtr_addr,
  342. min(sizeof(ha->ip_config.ipv6_default_router_addr),
  343. sizeof(init_fw_cb->ipv6_dflt_rtr_addr)));
  344. ha->ip_config.ipv6_vlan_tag =
  345. be16_to_cpu(init_fw_cb->ipv6_vlan_tag);
  346. ha->ip_config.ipv6_port = le16_to_cpu(init_fw_cb->ipv6_port);
  347. }
  348. }
  349. uint8_t
  350. qla4xxx_update_local_ifcb(struct scsi_qla_host *ha,
  351. uint32_t *mbox_cmd,
  352. uint32_t *mbox_sts,
  353. struct addr_ctrl_blk *init_fw_cb,
  354. dma_addr_t init_fw_cb_dma)
  355. {
  356. if (qla4xxx_get_ifcb(ha, mbox_cmd, mbox_sts, init_fw_cb_dma)
  357. != QLA_SUCCESS) {
  358. DEBUG2(printk(KERN_WARNING
  359. "scsi%ld: %s: Failed to get init_fw_ctrl_blk\n",
  360. ha->host_no, __func__));
  361. return QLA_ERROR;
  362. }
  363. DEBUG2(qla4xxx_dump_buffer(init_fw_cb, sizeof(struct addr_ctrl_blk)));
  364. /* Save some info in adapter structure. */
  365. ha->acb_version = init_fw_cb->acb_version;
  366. ha->firmware_options = le16_to_cpu(init_fw_cb->fw_options);
  367. ha->heartbeat_interval = init_fw_cb->hb_interval;
  368. memcpy(ha->name_string, init_fw_cb->iscsi_name,
  369. min(sizeof(ha->name_string),
  370. sizeof(init_fw_cb->iscsi_name)));
  371. /*memcpy(ha->alias, init_fw_cb->Alias,
  372. min(sizeof(ha->alias), sizeof(init_fw_cb->Alias)));*/
  373. qla4xxx_update_local_ip(ha, init_fw_cb);
  374. return QLA_SUCCESS;
  375. }
  376. /**
  377. * qla4xxx_initialize_fw_cb - initializes firmware control block.
  378. * @ha: Pointer to host adapter structure.
  379. **/
  380. int qla4xxx_initialize_fw_cb(struct scsi_qla_host * ha)
  381. {
  382. struct addr_ctrl_blk *init_fw_cb;
  383. dma_addr_t init_fw_cb_dma;
  384. uint32_t mbox_cmd[MBOX_REG_COUNT];
  385. uint32_t mbox_sts[MBOX_REG_COUNT];
  386. int status = QLA_ERROR;
  387. init_fw_cb = dma_alloc_coherent(&ha->pdev->dev,
  388. sizeof(struct addr_ctrl_blk),
  389. &init_fw_cb_dma, GFP_KERNEL);
  390. if (init_fw_cb == NULL) {
  391. DEBUG2(printk("scsi%ld: %s: Unable to alloc init_cb\n",
  392. ha->host_no, __func__));
  393. goto exit_init_fw_cb_no_free;
  394. }
  395. memset(init_fw_cb, 0, sizeof(struct addr_ctrl_blk));
  396. /* Get Initialize Firmware Control Block. */
  397. memset(&mbox_cmd, 0, sizeof(mbox_cmd));
  398. memset(&mbox_sts, 0, sizeof(mbox_sts));
  399. if (qla4xxx_get_ifcb(ha, &mbox_cmd[0], &mbox_sts[0], init_fw_cb_dma) !=
  400. QLA_SUCCESS) {
  401. dma_free_coherent(&ha->pdev->dev,
  402. sizeof(struct addr_ctrl_blk),
  403. init_fw_cb, init_fw_cb_dma);
  404. goto exit_init_fw_cb;
  405. }
  406. /* Initialize request and response queues. */
  407. qla4xxx_init_rings(ha);
  408. /* Fill in the request and response queue information. */
  409. init_fw_cb->rqq_consumer_idx = cpu_to_le16(ha->request_out);
  410. init_fw_cb->compq_producer_idx = cpu_to_le16(ha->response_in);
  411. init_fw_cb->rqq_len = __constant_cpu_to_le16(REQUEST_QUEUE_DEPTH);
  412. init_fw_cb->compq_len = __constant_cpu_to_le16(RESPONSE_QUEUE_DEPTH);
  413. init_fw_cb->rqq_addr_lo = cpu_to_le32(LSDW(ha->request_dma));
  414. init_fw_cb->rqq_addr_hi = cpu_to_le32(MSDW(ha->request_dma));
  415. init_fw_cb->compq_addr_lo = cpu_to_le32(LSDW(ha->response_dma));
  416. init_fw_cb->compq_addr_hi = cpu_to_le32(MSDW(ha->response_dma));
  417. init_fw_cb->shdwreg_addr_lo = cpu_to_le32(LSDW(ha->shadow_regs_dma));
  418. init_fw_cb->shdwreg_addr_hi = cpu_to_le32(MSDW(ha->shadow_regs_dma));
  419. /* Set up required options. */
  420. init_fw_cb->fw_options |=
  421. __constant_cpu_to_le16(FWOPT_SESSION_MODE |
  422. FWOPT_INITIATOR_MODE);
  423. if (is_qla8022(ha))
  424. init_fw_cb->fw_options |=
  425. __constant_cpu_to_le16(FWOPT_ENABLE_CRBDB);
  426. init_fw_cb->fw_options &= __constant_cpu_to_le16(~FWOPT_TARGET_MODE);
  427. init_fw_cb->add_fw_options = 0;
  428. init_fw_cb->add_fw_options |=
  429. __constant_cpu_to_le16(ADFWOPT_SERIALIZE_TASK_MGMT);
  430. init_fw_cb->add_fw_options |=
  431. __constant_cpu_to_le16(ADFWOPT_AUTOCONN_DISABLE);
  432. if (qla4xxx_set_ifcb(ha, &mbox_cmd[0], &mbox_sts[0], init_fw_cb_dma)
  433. != QLA_SUCCESS) {
  434. DEBUG2(printk(KERN_WARNING
  435. "scsi%ld: %s: Failed to set init_fw_ctrl_blk\n",
  436. ha->host_no, __func__));
  437. goto exit_init_fw_cb;
  438. }
  439. if (qla4xxx_update_local_ifcb(ha, &mbox_cmd[0], &mbox_sts[0],
  440. init_fw_cb, init_fw_cb_dma) != QLA_SUCCESS) {
  441. DEBUG2(printk("scsi%ld: %s: Failed to update local ifcb\n",
  442. ha->host_no, __func__));
  443. goto exit_init_fw_cb;
  444. }
  445. status = QLA_SUCCESS;
  446. exit_init_fw_cb:
  447. dma_free_coherent(&ha->pdev->dev, sizeof(struct addr_ctrl_blk),
  448. init_fw_cb, init_fw_cb_dma);
  449. exit_init_fw_cb_no_free:
  450. return status;
  451. }
  452. /**
  453. * qla4xxx_get_dhcp_ip_address - gets HBA ip address via DHCP
  454. * @ha: Pointer to host adapter structure.
  455. **/
  456. int qla4xxx_get_dhcp_ip_address(struct scsi_qla_host * ha)
  457. {
  458. struct addr_ctrl_blk *init_fw_cb;
  459. dma_addr_t init_fw_cb_dma;
  460. uint32_t mbox_cmd[MBOX_REG_COUNT];
  461. uint32_t mbox_sts[MBOX_REG_COUNT];
  462. init_fw_cb = dma_alloc_coherent(&ha->pdev->dev,
  463. sizeof(struct addr_ctrl_blk),
  464. &init_fw_cb_dma, GFP_KERNEL);
  465. if (init_fw_cb == NULL) {
  466. printk("scsi%ld: %s: Unable to alloc init_cb\n", ha->host_no,
  467. __func__);
  468. return QLA_ERROR;
  469. }
  470. /* Get Initialize Firmware Control Block. */
  471. memset(init_fw_cb, 0, sizeof(struct addr_ctrl_blk));
  472. if (qla4xxx_get_ifcb(ha, &mbox_cmd[0], &mbox_sts[0], init_fw_cb_dma) !=
  473. QLA_SUCCESS) {
  474. DEBUG2(printk("scsi%ld: %s: Failed to get init_fw_ctrl_blk\n",
  475. ha->host_no, __func__));
  476. dma_free_coherent(&ha->pdev->dev,
  477. sizeof(struct addr_ctrl_blk),
  478. init_fw_cb, init_fw_cb_dma);
  479. return QLA_ERROR;
  480. }
  481. /* Save IP Address. */
  482. qla4xxx_update_local_ip(ha, init_fw_cb);
  483. dma_free_coherent(&ha->pdev->dev, sizeof(struct addr_ctrl_blk),
  484. init_fw_cb, init_fw_cb_dma);
  485. return QLA_SUCCESS;
  486. }
  487. /**
  488. * qla4xxx_get_firmware_state - gets firmware state of HBA
  489. * @ha: Pointer to host adapter structure.
  490. **/
  491. int qla4xxx_get_firmware_state(struct scsi_qla_host * ha)
  492. {
  493. uint32_t mbox_cmd[MBOX_REG_COUNT];
  494. uint32_t mbox_sts[MBOX_REG_COUNT];
  495. /* Get firmware version */
  496. memset(&mbox_cmd, 0, sizeof(mbox_cmd));
  497. memset(&mbox_sts, 0, sizeof(mbox_sts));
  498. mbox_cmd[0] = MBOX_CMD_GET_FW_STATE;
  499. if (qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 4, &mbox_cmd[0], &mbox_sts[0]) !=
  500. QLA_SUCCESS) {
  501. DEBUG2(printk("scsi%ld: %s: MBOX_CMD_GET_FW_STATE failed w/ "
  502. "status %04X\n", ha->host_no, __func__,
  503. mbox_sts[0]));
  504. return QLA_ERROR;
  505. }
  506. ha->firmware_state = mbox_sts[1];
  507. ha->board_id = mbox_sts[2];
  508. ha->addl_fw_state = mbox_sts[3];
  509. DEBUG2(printk("scsi%ld: %s firmware_state=0x%x\n",
  510. ha->host_no, __func__, ha->firmware_state);)
  511. return QLA_SUCCESS;
  512. }
  513. /**
  514. * qla4xxx_get_firmware_status - retrieves firmware status
  515. * @ha: Pointer to host adapter structure.
  516. **/
  517. int qla4xxx_get_firmware_status(struct scsi_qla_host * ha)
  518. {
  519. uint32_t mbox_cmd[MBOX_REG_COUNT];
  520. uint32_t mbox_sts[MBOX_REG_COUNT];
  521. /* Get firmware version */
  522. memset(&mbox_cmd, 0, sizeof(mbox_cmd));
  523. memset(&mbox_sts, 0, sizeof(mbox_sts));
  524. mbox_cmd[0] = MBOX_CMD_GET_FW_STATUS;
  525. if (qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 3, &mbox_cmd[0], &mbox_sts[0]) !=
  526. QLA_SUCCESS) {
  527. DEBUG2(printk("scsi%ld: %s: MBOX_CMD_GET_FW_STATUS failed w/ "
  528. "status %04X\n", ha->host_no, __func__,
  529. mbox_sts[0]));
  530. return QLA_ERROR;
  531. }
  532. ql4_printk(KERN_INFO, ha, "%ld firmare IOCBs available (%d).\n",
  533. ha->host_no, mbox_sts[2]);
  534. return QLA_SUCCESS;
  535. }
  536. /**
  537. * qla4xxx_get_fwddb_entry - retrieves firmware ddb entry
  538. * @ha: Pointer to host adapter structure.
  539. * @fw_ddb_index: Firmware's device database index
  540. * @fw_ddb_entry: Pointer to firmware's device database entry structure
  541. * @num_valid_ddb_entries: Pointer to number of valid ddb entries
  542. * @next_ddb_index: Pointer to next valid device database index
  543. * @fw_ddb_device_state: Pointer to device state
  544. **/
  545. int qla4xxx_get_fwddb_entry(struct scsi_qla_host *ha,
  546. uint16_t fw_ddb_index,
  547. struct dev_db_entry *fw_ddb_entry,
  548. dma_addr_t fw_ddb_entry_dma,
  549. uint32_t *num_valid_ddb_entries,
  550. uint32_t *next_ddb_index,
  551. uint32_t *fw_ddb_device_state,
  552. uint32_t *conn_err_detail,
  553. uint16_t *tcp_source_port_num,
  554. uint16_t *connection_id)
  555. {
  556. int status = QLA_ERROR;
  557. uint16_t options;
  558. uint32_t mbox_cmd[MBOX_REG_COUNT];
  559. uint32_t mbox_sts[MBOX_REG_COUNT];
  560. /* Make sure the device index is valid */
  561. if (fw_ddb_index >= MAX_DDB_ENTRIES) {
  562. DEBUG2(printk("scsi%ld: %s: ddb [%d] out of range.\n",
  563. ha->host_no, __func__, fw_ddb_index));
  564. goto exit_get_fwddb;
  565. }
  566. memset(&mbox_cmd, 0, sizeof(mbox_cmd));
  567. memset(&mbox_sts, 0, sizeof(mbox_sts));
  568. mbox_cmd[0] = MBOX_CMD_GET_DATABASE_ENTRY;
  569. mbox_cmd[1] = (uint32_t) fw_ddb_index;
  570. mbox_cmd[2] = LSDW(fw_ddb_entry_dma);
  571. mbox_cmd[3] = MSDW(fw_ddb_entry_dma);
  572. mbox_cmd[4] = sizeof(struct dev_db_entry);
  573. if (qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 7, &mbox_cmd[0], &mbox_sts[0]) ==
  574. QLA_ERROR) {
  575. DEBUG2(printk("scsi%ld: %s: MBOX_CMD_GET_DATABASE_ENTRY failed"
  576. " with status 0x%04X\n", ha->host_no, __func__,
  577. mbox_sts[0]));
  578. goto exit_get_fwddb;
  579. }
  580. if (fw_ddb_index != mbox_sts[1]) {
  581. DEBUG2(printk("scsi%ld: %s: ddb mismatch [%d] != [%d].\n",
  582. ha->host_no, __func__, fw_ddb_index,
  583. mbox_sts[1]));
  584. goto exit_get_fwddb;
  585. }
  586. if (fw_ddb_entry) {
  587. options = le16_to_cpu(fw_ddb_entry->options);
  588. if (options & DDB_OPT_IPV6_DEVICE) {
  589. ql4_printk(KERN_INFO, ha, "%s: DDB[%d] MB0 %04x Tot %d "
  590. "Next %d State %04x ConnErr %08x %pI6 "
  591. ":%04d \"%s\"\n", __func__, fw_ddb_index,
  592. mbox_sts[0], mbox_sts[2], mbox_sts[3],
  593. mbox_sts[4], mbox_sts[5],
  594. fw_ddb_entry->ip_addr,
  595. le16_to_cpu(fw_ddb_entry->port),
  596. fw_ddb_entry->iscsi_name);
  597. } else {
  598. ql4_printk(KERN_INFO, ha, "%s: DDB[%d] MB0 %04x Tot %d "
  599. "Next %d State %04x ConnErr %08x %pI4 "
  600. ":%04d \"%s\"\n", __func__, fw_ddb_index,
  601. mbox_sts[0], mbox_sts[2], mbox_sts[3],
  602. mbox_sts[4], mbox_sts[5],
  603. fw_ddb_entry->ip_addr,
  604. le16_to_cpu(fw_ddb_entry->port),
  605. fw_ddb_entry->iscsi_name);
  606. }
  607. }
  608. if (num_valid_ddb_entries)
  609. *num_valid_ddb_entries = mbox_sts[2];
  610. if (next_ddb_index)
  611. *next_ddb_index = mbox_sts[3];
  612. if (fw_ddb_device_state)
  613. *fw_ddb_device_state = mbox_sts[4];
  614. /*
  615. * RA: This mailbox has been changed to pass connection error and
  616. * details. Its true for ISP4010 as per Version E - Not sure when it
  617. * was changed. Get the time2wait from the fw_dd_entry field :
  618. * default_time2wait which we call it as minTime2Wait DEV_DB_ENTRY
  619. * struct.
  620. */
  621. if (conn_err_detail)
  622. *conn_err_detail = mbox_sts[5];
  623. if (tcp_source_port_num)
  624. *tcp_source_port_num = (uint16_t) (mbox_sts[6] >> 16);
  625. if (connection_id)
  626. *connection_id = (uint16_t) mbox_sts[6] & 0x00FF;
  627. status = QLA_SUCCESS;
  628. exit_get_fwddb:
  629. return status;
  630. }
  631. int qla4xxx_conn_open(struct scsi_qla_host *ha, uint16_t fw_ddb_index)
  632. {
  633. uint32_t mbox_cmd[MBOX_REG_COUNT];
  634. uint32_t mbox_sts[MBOX_REG_COUNT];
  635. int status;
  636. memset(&mbox_cmd, 0, sizeof(mbox_cmd));
  637. memset(&mbox_sts, 0, sizeof(mbox_sts));
  638. mbox_cmd[0] = MBOX_CMD_CONN_OPEN;
  639. mbox_cmd[1] = fw_ddb_index;
  640. status = qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 2, &mbox_cmd[0],
  641. &mbox_sts[0]);
  642. DEBUG2(ql4_printk(KERN_INFO, ha,
  643. "%s: status = %d mbx0 = 0x%x mbx1 = 0x%x\n",
  644. __func__, status, mbox_sts[0], mbox_sts[1]));
  645. return status;
  646. }
  647. /**
  648. * qla4xxx_set_fwddb_entry - sets a ddb entry.
  649. * @ha: Pointer to host adapter structure.
  650. * @fw_ddb_index: Firmware's device database index
  651. * @fw_ddb_entry_dma: dma address of ddb entry
  652. * @mbx_sts: mailbox 0 to be returned or NULL
  653. *
  654. * This routine initializes or updates the adapter's device database
  655. * entry for the specified device.
  656. **/
  657. int qla4xxx_set_ddb_entry(struct scsi_qla_host * ha, uint16_t fw_ddb_index,
  658. dma_addr_t fw_ddb_entry_dma, uint32_t *mbx_sts)
  659. {
  660. uint32_t mbox_cmd[MBOX_REG_COUNT];
  661. uint32_t mbox_sts[MBOX_REG_COUNT];
  662. int status;
  663. /* Do not wait for completion. The firmware will send us an
  664. * ASTS_DATABASE_CHANGED (0x8014) to notify us of the login status.
  665. */
  666. memset(&mbox_cmd, 0, sizeof(mbox_cmd));
  667. memset(&mbox_sts, 0, sizeof(mbox_sts));
  668. mbox_cmd[0] = MBOX_CMD_SET_DATABASE_ENTRY;
  669. mbox_cmd[1] = (uint32_t) fw_ddb_index;
  670. mbox_cmd[2] = LSDW(fw_ddb_entry_dma);
  671. mbox_cmd[3] = MSDW(fw_ddb_entry_dma);
  672. mbox_cmd[4] = sizeof(struct dev_db_entry);
  673. status = qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 5, &mbox_cmd[0],
  674. &mbox_sts[0]);
  675. if (mbx_sts)
  676. *mbx_sts = mbox_sts[0];
  677. DEBUG2(printk("scsi%ld: %s: status=%d mbx0=0x%x mbx4=0x%x\n",
  678. ha->host_no, __func__, status, mbox_sts[0], mbox_sts[4]);)
  679. return status;
  680. }
  681. int qla4xxx_session_logout_ddb(struct scsi_qla_host *ha,
  682. struct ddb_entry *ddb_entry, int options)
  683. {
  684. int status;
  685. uint32_t mbox_cmd[MBOX_REG_COUNT];
  686. uint32_t mbox_sts[MBOX_REG_COUNT];
  687. memset(&mbox_cmd, 0, sizeof(mbox_cmd));
  688. memset(&mbox_sts, 0, sizeof(mbox_sts));
  689. mbox_cmd[0] = MBOX_CMD_CONN_CLOSE_SESS_LOGOUT;
  690. mbox_cmd[1] = ddb_entry->fw_ddb_index;
  691. mbox_cmd[3] = options;
  692. status = qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 2, &mbox_cmd[0],
  693. &mbox_sts[0]);
  694. if (status != QLA_SUCCESS) {
  695. DEBUG2(ql4_printk(KERN_INFO, ha,
  696. "%s: MBOX_CMD_CONN_CLOSE_SESS_LOGOUT "
  697. "failed sts %04X %04X", __func__,
  698. mbox_sts[0], mbox_sts[1]));
  699. }
  700. return status;
  701. }
  702. /**
  703. * qla4xxx_get_crash_record - retrieves crash record.
  704. * @ha: Pointer to host adapter structure.
  705. *
  706. * This routine retrieves a crash record from the QLA4010 after an 8002h aen.
  707. **/
  708. void qla4xxx_get_crash_record(struct scsi_qla_host * ha)
  709. {
  710. uint32_t mbox_cmd[MBOX_REG_COUNT];
  711. uint32_t mbox_sts[MBOX_REG_COUNT];
  712. struct crash_record *crash_record = NULL;
  713. dma_addr_t crash_record_dma = 0;
  714. uint32_t crash_record_size = 0;
  715. memset(&mbox_cmd, 0, sizeof(mbox_cmd));
  716. memset(&mbox_sts, 0, sizeof(mbox_cmd));
  717. /* Get size of crash record. */
  718. mbox_cmd[0] = MBOX_CMD_GET_CRASH_RECORD;
  719. if (qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 5, &mbox_cmd[0], &mbox_sts[0]) !=
  720. QLA_SUCCESS) {
  721. DEBUG2(printk("scsi%ld: %s: ERROR: Unable to retrieve size!\n",
  722. ha->host_no, __func__));
  723. goto exit_get_crash_record;
  724. }
  725. crash_record_size = mbox_sts[4];
  726. if (crash_record_size == 0) {
  727. DEBUG2(printk("scsi%ld: %s: ERROR: Crash record size is 0!\n",
  728. ha->host_no, __func__));
  729. goto exit_get_crash_record;
  730. }
  731. /* Alloc Memory for Crash Record. */
  732. crash_record = dma_alloc_coherent(&ha->pdev->dev, crash_record_size,
  733. &crash_record_dma, GFP_KERNEL);
  734. if (crash_record == NULL)
  735. goto exit_get_crash_record;
  736. /* Get Crash Record. */
  737. memset(&mbox_cmd, 0, sizeof(mbox_cmd));
  738. memset(&mbox_sts, 0, sizeof(mbox_cmd));
  739. mbox_cmd[0] = MBOX_CMD_GET_CRASH_RECORD;
  740. mbox_cmd[2] = LSDW(crash_record_dma);
  741. mbox_cmd[3] = MSDW(crash_record_dma);
  742. mbox_cmd[4] = crash_record_size;
  743. if (qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 5, &mbox_cmd[0], &mbox_sts[0]) !=
  744. QLA_SUCCESS)
  745. goto exit_get_crash_record;
  746. /* Dump Crash Record. */
  747. exit_get_crash_record:
  748. if (crash_record)
  749. dma_free_coherent(&ha->pdev->dev, crash_record_size,
  750. crash_record, crash_record_dma);
  751. }
  752. /**
  753. * qla4xxx_get_conn_event_log - retrieves connection event log
  754. * @ha: Pointer to host adapter structure.
  755. **/
  756. void qla4xxx_get_conn_event_log(struct scsi_qla_host * ha)
  757. {
  758. uint32_t mbox_cmd[MBOX_REG_COUNT];
  759. uint32_t mbox_sts[MBOX_REG_COUNT];
  760. struct conn_event_log_entry *event_log = NULL;
  761. dma_addr_t event_log_dma = 0;
  762. uint32_t event_log_size = 0;
  763. uint32_t num_valid_entries;
  764. uint32_t oldest_entry = 0;
  765. uint32_t max_event_log_entries;
  766. uint8_t i;
  767. memset(&mbox_cmd, 0, sizeof(mbox_cmd));
  768. memset(&mbox_sts, 0, sizeof(mbox_cmd));
  769. /* Get size of crash record. */
  770. mbox_cmd[0] = MBOX_CMD_GET_CONN_EVENT_LOG;
  771. if (qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 5, &mbox_cmd[0], &mbox_sts[0]) !=
  772. QLA_SUCCESS)
  773. goto exit_get_event_log;
  774. event_log_size = mbox_sts[4];
  775. if (event_log_size == 0)
  776. goto exit_get_event_log;
  777. /* Alloc Memory for Crash Record. */
  778. event_log = dma_alloc_coherent(&ha->pdev->dev, event_log_size,
  779. &event_log_dma, GFP_KERNEL);
  780. if (event_log == NULL)
  781. goto exit_get_event_log;
  782. /* Get Crash Record. */
  783. memset(&mbox_cmd, 0, sizeof(mbox_cmd));
  784. memset(&mbox_sts, 0, sizeof(mbox_cmd));
  785. mbox_cmd[0] = MBOX_CMD_GET_CONN_EVENT_LOG;
  786. mbox_cmd[2] = LSDW(event_log_dma);
  787. mbox_cmd[3] = MSDW(event_log_dma);
  788. if (qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 5, &mbox_cmd[0], &mbox_sts[0]) !=
  789. QLA_SUCCESS) {
  790. DEBUG2(printk("scsi%ld: %s: ERROR: Unable to retrieve event "
  791. "log!\n", ha->host_no, __func__));
  792. goto exit_get_event_log;
  793. }
  794. /* Dump Event Log. */
  795. num_valid_entries = mbox_sts[1];
  796. max_event_log_entries = event_log_size /
  797. sizeof(struct conn_event_log_entry);
  798. if (num_valid_entries > max_event_log_entries)
  799. oldest_entry = num_valid_entries % max_event_log_entries;
  800. DEBUG3(printk("scsi%ld: Connection Event Log Dump (%d entries):\n",
  801. ha->host_no, num_valid_entries));
  802. if (ql4xextended_error_logging == 3) {
  803. if (oldest_entry == 0) {
  804. /* Circular Buffer has not wrapped around */
  805. for (i=0; i < num_valid_entries; i++) {
  806. qla4xxx_dump_buffer((uint8_t *)event_log+
  807. (i*sizeof(*event_log)),
  808. sizeof(*event_log));
  809. }
  810. }
  811. else {
  812. /* Circular Buffer has wrapped around -
  813. * display accordingly*/
  814. for (i=oldest_entry; i < max_event_log_entries; i++) {
  815. qla4xxx_dump_buffer((uint8_t *)event_log+
  816. (i*sizeof(*event_log)),
  817. sizeof(*event_log));
  818. }
  819. for (i=0; i < oldest_entry; i++) {
  820. qla4xxx_dump_buffer((uint8_t *)event_log+
  821. (i*sizeof(*event_log)),
  822. sizeof(*event_log));
  823. }
  824. }
  825. }
  826. exit_get_event_log:
  827. if (event_log)
  828. dma_free_coherent(&ha->pdev->dev, event_log_size, event_log,
  829. event_log_dma);
  830. }
  831. /**
  832. * qla4xxx_abort_task - issues Abort Task
  833. * @ha: Pointer to host adapter structure.
  834. * @srb: Pointer to srb entry
  835. *
  836. * This routine performs a LUN RESET on the specified target/lun.
  837. * The caller must ensure that the ddb_entry and lun_entry pointers
  838. * are valid before calling this routine.
  839. **/
  840. int qla4xxx_abort_task(struct scsi_qla_host *ha, struct srb *srb)
  841. {
  842. uint32_t mbox_cmd[MBOX_REG_COUNT];
  843. uint32_t mbox_sts[MBOX_REG_COUNT];
  844. struct scsi_cmnd *cmd = srb->cmd;
  845. int status = QLA_SUCCESS;
  846. unsigned long flags = 0;
  847. uint32_t index;
  848. /*
  849. * Send abort task command to ISP, so that the ISP will return
  850. * request with ABORT status
  851. */
  852. memset(&mbox_cmd, 0, sizeof(mbox_cmd));
  853. memset(&mbox_sts, 0, sizeof(mbox_sts));
  854. spin_lock_irqsave(&ha->hardware_lock, flags);
  855. index = (unsigned long)(unsigned char *)cmd->host_scribble;
  856. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  857. /* Firmware already posted completion on response queue */
  858. if (index == MAX_SRBS)
  859. return status;
  860. mbox_cmd[0] = MBOX_CMD_ABORT_TASK;
  861. mbox_cmd[1] = srb->ddb->fw_ddb_index;
  862. mbox_cmd[2] = index;
  863. /* Immediate Command Enable */
  864. mbox_cmd[5] = 0x01;
  865. qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 5, &mbox_cmd[0],
  866. &mbox_sts[0]);
  867. if (mbox_sts[0] != MBOX_STS_COMMAND_COMPLETE) {
  868. status = QLA_ERROR;
  869. DEBUG2(printk(KERN_WARNING "scsi%ld:%d:%d: abort task FAILED: "
  870. "mbx0=%04X, mb1=%04X, mb2=%04X, mb3=%04X, mb4=%04X\n",
  871. ha->host_no, cmd->device->id, cmd->device->lun, mbox_sts[0],
  872. mbox_sts[1], mbox_sts[2], mbox_sts[3], mbox_sts[4]));
  873. }
  874. return status;
  875. }
  876. /**
  877. * qla4xxx_reset_lun - issues LUN Reset
  878. * @ha: Pointer to host adapter structure.
  879. * @ddb_entry: Pointer to device database entry
  880. * @lun: lun number
  881. *
  882. * This routine performs a LUN RESET on the specified target/lun.
  883. * The caller must ensure that the ddb_entry and lun_entry pointers
  884. * are valid before calling this routine.
  885. **/
  886. int qla4xxx_reset_lun(struct scsi_qla_host * ha, struct ddb_entry * ddb_entry,
  887. int lun)
  888. {
  889. uint32_t mbox_cmd[MBOX_REG_COUNT];
  890. uint32_t mbox_sts[MBOX_REG_COUNT];
  891. int status = QLA_SUCCESS;
  892. DEBUG2(printk("scsi%ld:%d:%d: lun reset issued\n", ha->host_no,
  893. ddb_entry->fw_ddb_index, lun));
  894. /*
  895. * Send lun reset command to ISP, so that the ISP will return all
  896. * outstanding requests with RESET status
  897. */
  898. memset(&mbox_cmd, 0, sizeof(mbox_cmd));
  899. memset(&mbox_sts, 0, sizeof(mbox_sts));
  900. mbox_cmd[0] = MBOX_CMD_LUN_RESET;
  901. mbox_cmd[1] = ddb_entry->fw_ddb_index;
  902. mbox_cmd[2] = lun << 8;
  903. mbox_cmd[5] = 0x01; /* Immediate Command Enable */
  904. qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 1, &mbox_cmd[0], &mbox_sts[0]);
  905. if (mbox_sts[0] != MBOX_STS_COMMAND_COMPLETE &&
  906. mbox_sts[0] != MBOX_STS_COMMAND_ERROR)
  907. status = QLA_ERROR;
  908. return status;
  909. }
  910. /**
  911. * qla4xxx_reset_target - issues target Reset
  912. * @ha: Pointer to host adapter structure.
  913. * @db_entry: Pointer to device database entry
  914. * @un_entry: Pointer to lun entry structure
  915. *
  916. * This routine performs a TARGET RESET on the specified target.
  917. * The caller must ensure that the ddb_entry pointers
  918. * are valid before calling this routine.
  919. **/
  920. int qla4xxx_reset_target(struct scsi_qla_host *ha,
  921. struct ddb_entry *ddb_entry)
  922. {
  923. uint32_t mbox_cmd[MBOX_REG_COUNT];
  924. uint32_t mbox_sts[MBOX_REG_COUNT];
  925. int status = QLA_SUCCESS;
  926. DEBUG2(printk("scsi%ld:%d: target reset issued\n", ha->host_no,
  927. ddb_entry->fw_ddb_index));
  928. /*
  929. * Send target reset command to ISP, so that the ISP will return all
  930. * outstanding requests with RESET status
  931. */
  932. memset(&mbox_cmd, 0, sizeof(mbox_cmd));
  933. memset(&mbox_sts, 0, sizeof(mbox_sts));
  934. mbox_cmd[0] = MBOX_CMD_TARGET_WARM_RESET;
  935. mbox_cmd[1] = ddb_entry->fw_ddb_index;
  936. mbox_cmd[5] = 0x01; /* Immediate Command Enable */
  937. qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 1, &mbox_cmd[0],
  938. &mbox_sts[0]);
  939. if (mbox_sts[0] != MBOX_STS_COMMAND_COMPLETE &&
  940. mbox_sts[0] != MBOX_STS_COMMAND_ERROR)
  941. status = QLA_ERROR;
  942. return status;
  943. }
  944. int qla4xxx_get_flash(struct scsi_qla_host * ha, dma_addr_t dma_addr,
  945. uint32_t offset, uint32_t len)
  946. {
  947. uint32_t mbox_cmd[MBOX_REG_COUNT];
  948. uint32_t mbox_sts[MBOX_REG_COUNT];
  949. memset(&mbox_cmd, 0, sizeof(mbox_cmd));
  950. memset(&mbox_sts, 0, sizeof(mbox_sts));
  951. mbox_cmd[0] = MBOX_CMD_READ_FLASH;
  952. mbox_cmd[1] = LSDW(dma_addr);
  953. mbox_cmd[2] = MSDW(dma_addr);
  954. mbox_cmd[3] = offset;
  955. mbox_cmd[4] = len;
  956. if (qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 2, &mbox_cmd[0], &mbox_sts[0]) !=
  957. QLA_SUCCESS) {
  958. DEBUG2(printk("scsi%ld: %s: MBOX_CMD_READ_FLASH, failed w/ "
  959. "status %04X %04X, offset %08x, len %08x\n", ha->host_no,
  960. __func__, mbox_sts[0], mbox_sts[1], offset, len));
  961. return QLA_ERROR;
  962. }
  963. return QLA_SUCCESS;
  964. }
  965. /**
  966. * qla4xxx_about_firmware - gets FW, iscsi draft and boot loader version
  967. * @ha: Pointer to host adapter structure.
  968. *
  969. * Retrieves the FW version, iSCSI draft version & bootloader version of HBA.
  970. * Mailboxes 2 & 3 may hold an address for data. Make sure that we write 0 to
  971. * those mailboxes, if unused.
  972. **/
  973. int qla4xxx_about_firmware(struct scsi_qla_host *ha)
  974. {
  975. struct about_fw_info *about_fw = NULL;
  976. dma_addr_t about_fw_dma;
  977. uint32_t mbox_cmd[MBOX_REG_COUNT];
  978. uint32_t mbox_sts[MBOX_REG_COUNT];
  979. int status = QLA_ERROR;
  980. about_fw = dma_alloc_coherent(&ha->pdev->dev,
  981. sizeof(struct about_fw_info),
  982. &about_fw_dma, GFP_KERNEL);
  983. if (!about_fw) {
  984. DEBUG2(ql4_printk(KERN_ERR, ha, "%s: Unable to alloc memory "
  985. "for about_fw\n", __func__));
  986. return status;
  987. }
  988. memset(about_fw, 0, sizeof(struct about_fw_info));
  989. memset(&mbox_cmd, 0, sizeof(mbox_cmd));
  990. memset(&mbox_sts, 0, sizeof(mbox_sts));
  991. mbox_cmd[0] = MBOX_CMD_ABOUT_FW;
  992. mbox_cmd[2] = LSDW(about_fw_dma);
  993. mbox_cmd[3] = MSDW(about_fw_dma);
  994. mbox_cmd[4] = sizeof(struct about_fw_info);
  995. status = qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, MBOX_REG_COUNT,
  996. &mbox_cmd[0], &mbox_sts[0]);
  997. if (status != QLA_SUCCESS) {
  998. DEBUG2(ql4_printk(KERN_WARNING, ha, "%s: MBOX_CMD_ABOUT_FW "
  999. "failed w/ status %04X\n", __func__,
  1000. mbox_sts[0]));
  1001. goto exit_about_fw;
  1002. }
  1003. /* Save version information. */
  1004. ha->firmware_version[0] = le16_to_cpu(about_fw->fw_major);
  1005. ha->firmware_version[1] = le16_to_cpu(about_fw->fw_minor);
  1006. ha->patch_number = le16_to_cpu(about_fw->fw_patch);
  1007. ha->build_number = le16_to_cpu(about_fw->fw_build);
  1008. ha->iscsi_major = le16_to_cpu(about_fw->iscsi_major);
  1009. ha->iscsi_minor = le16_to_cpu(about_fw->iscsi_minor);
  1010. ha->bootload_major = le16_to_cpu(about_fw->bootload_major);
  1011. ha->bootload_minor = le16_to_cpu(about_fw->bootload_minor);
  1012. ha->bootload_patch = le16_to_cpu(about_fw->bootload_patch);
  1013. ha->bootload_build = le16_to_cpu(about_fw->bootload_build);
  1014. status = QLA_SUCCESS;
  1015. exit_about_fw:
  1016. dma_free_coherent(&ha->pdev->dev, sizeof(struct about_fw_info),
  1017. about_fw, about_fw_dma);
  1018. return status;
  1019. }
  1020. static int qla4xxx_get_default_ddb(struct scsi_qla_host *ha, uint32_t options,
  1021. dma_addr_t dma_addr)
  1022. {
  1023. uint32_t mbox_cmd[MBOX_REG_COUNT];
  1024. uint32_t mbox_sts[MBOX_REG_COUNT];
  1025. memset(&mbox_cmd, 0, sizeof(mbox_cmd));
  1026. memset(&mbox_sts, 0, sizeof(mbox_sts));
  1027. mbox_cmd[0] = MBOX_CMD_GET_DATABASE_ENTRY_DEFAULTS;
  1028. mbox_cmd[1] = options;
  1029. mbox_cmd[2] = LSDW(dma_addr);
  1030. mbox_cmd[3] = MSDW(dma_addr);
  1031. if (qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 1, &mbox_cmd[0], &mbox_sts[0]) !=
  1032. QLA_SUCCESS) {
  1033. DEBUG2(printk("scsi%ld: %s: failed status %04X\n",
  1034. ha->host_no, __func__, mbox_sts[0]));
  1035. return QLA_ERROR;
  1036. }
  1037. return QLA_SUCCESS;
  1038. }
  1039. int qla4xxx_req_ddb_entry(struct scsi_qla_host *ha, uint32_t ddb_index,
  1040. uint32_t *mbx_sts)
  1041. {
  1042. int status;
  1043. uint32_t mbox_cmd[MBOX_REG_COUNT];
  1044. uint32_t mbox_sts[MBOX_REG_COUNT];
  1045. memset(&mbox_cmd, 0, sizeof(mbox_cmd));
  1046. memset(&mbox_sts, 0, sizeof(mbox_sts));
  1047. mbox_cmd[0] = MBOX_CMD_REQUEST_DATABASE_ENTRY;
  1048. mbox_cmd[1] = ddb_index;
  1049. status = qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 1, &mbox_cmd[0],
  1050. &mbox_sts[0]);
  1051. if (status != QLA_SUCCESS) {
  1052. DEBUG2(ql4_printk(KERN_ERR, ha, "%s: failed status %04X\n",
  1053. __func__, mbox_sts[0]));
  1054. }
  1055. *mbx_sts = mbox_sts[0];
  1056. return status;
  1057. }
  1058. int qla4xxx_clear_ddb_entry(struct scsi_qla_host *ha, uint32_t ddb_index)
  1059. {
  1060. int status;
  1061. uint32_t mbox_cmd[MBOX_REG_COUNT];
  1062. uint32_t mbox_sts[MBOX_REG_COUNT];
  1063. memset(&mbox_cmd, 0, sizeof(mbox_cmd));
  1064. memset(&mbox_sts, 0, sizeof(mbox_sts));
  1065. mbox_cmd[0] = MBOX_CMD_CLEAR_DATABASE_ENTRY;
  1066. mbox_cmd[1] = ddb_index;
  1067. status = qla4xxx_mailbox_command(ha, 2, 1, &mbox_cmd[0],
  1068. &mbox_sts[0]);
  1069. if (status != QLA_SUCCESS) {
  1070. DEBUG2(ql4_printk(KERN_ERR, ha, "%s: failed status %04X\n",
  1071. __func__, mbox_sts[0]));
  1072. }
  1073. return status;
  1074. }
  1075. int qla4xxx_set_flash(struct scsi_qla_host *ha, dma_addr_t dma_addr,
  1076. uint32_t offset, uint32_t length, uint32_t options)
  1077. {
  1078. uint32_t mbox_cmd[MBOX_REG_COUNT];
  1079. uint32_t mbox_sts[MBOX_REG_COUNT];
  1080. int status = QLA_SUCCESS;
  1081. memset(&mbox_cmd, 0, sizeof(mbox_cmd));
  1082. memset(&mbox_sts, 0, sizeof(mbox_sts));
  1083. mbox_cmd[0] = MBOX_CMD_WRITE_FLASH;
  1084. mbox_cmd[1] = LSDW(dma_addr);
  1085. mbox_cmd[2] = MSDW(dma_addr);
  1086. mbox_cmd[3] = offset;
  1087. mbox_cmd[4] = length;
  1088. mbox_cmd[5] = options;
  1089. status = qla4xxx_mailbox_command(ha, 6, 2, &mbox_cmd[0], &mbox_sts[0]);
  1090. if (status != QLA_SUCCESS) {
  1091. DEBUG2(ql4_printk(KERN_WARNING, ha, "%s: MBOX_CMD_WRITE_FLASH "
  1092. "failed w/ status %04X, mbx1 %04X\n",
  1093. __func__, mbox_sts[0], mbox_sts[1]));
  1094. }
  1095. return status;
  1096. }
  1097. int qla4xxx_bootdb_by_index(struct scsi_qla_host *ha,
  1098. struct dev_db_entry *fw_ddb_entry,
  1099. dma_addr_t fw_ddb_entry_dma, uint16_t ddb_index)
  1100. {
  1101. uint32_t dev_db_start_offset = FLASH_OFFSET_DB_INFO;
  1102. uint32_t dev_db_end_offset;
  1103. int status = QLA_ERROR;
  1104. memset(fw_ddb_entry, 0, sizeof(*fw_ddb_entry));
  1105. dev_db_start_offset += (ddb_index * sizeof(*fw_ddb_entry));
  1106. dev_db_end_offset = FLASH_OFFSET_DB_END;
  1107. if (dev_db_start_offset > dev_db_end_offset) {
  1108. DEBUG2(ql4_printk(KERN_ERR, ha,
  1109. "%s:Invalid DDB index %d", __func__,
  1110. ddb_index));
  1111. goto exit_bootdb_failed;
  1112. }
  1113. if (qla4xxx_get_flash(ha, fw_ddb_entry_dma, dev_db_start_offset,
  1114. sizeof(*fw_ddb_entry)) != QLA_SUCCESS) {
  1115. ql4_printk(KERN_ERR, ha, "scsi%ld: %s: Get Flash"
  1116. "failed\n", ha->host_no, __func__);
  1117. goto exit_bootdb_failed;
  1118. }
  1119. if (fw_ddb_entry->cookie == DDB_VALID_COOKIE)
  1120. status = QLA_SUCCESS;
  1121. exit_bootdb_failed:
  1122. return status;
  1123. }
  1124. int qla4xxx_get_chap(struct scsi_qla_host *ha, char *username, char *password,
  1125. uint16_t idx)
  1126. {
  1127. int ret = 0;
  1128. int rval = QLA_ERROR;
  1129. uint32_t offset = 0, chap_size;
  1130. struct ql4_chap_table *chap_table;
  1131. dma_addr_t chap_dma;
  1132. chap_table = dma_pool_alloc(ha->chap_dma_pool, GFP_KERNEL, &chap_dma);
  1133. if (chap_table == NULL) {
  1134. ret = -ENOMEM;
  1135. goto exit_get_chap;
  1136. }
  1137. chap_size = sizeof(struct ql4_chap_table);
  1138. memset(chap_table, 0, chap_size);
  1139. if (is_qla40XX(ha))
  1140. offset = FLASH_CHAP_OFFSET | (idx * chap_size);
  1141. else {
  1142. offset = FLASH_RAW_ACCESS_ADDR + (ha->hw.flt_region_chap << 2);
  1143. /* flt_chap_size is CHAP table size for both ports
  1144. * so divide it by 2 to calculate the offset for second port
  1145. */
  1146. if (ha->port_num == 1)
  1147. offset += (ha->hw.flt_chap_size / 2);
  1148. offset += (idx * chap_size);
  1149. }
  1150. rval = qla4xxx_get_flash(ha, chap_dma, offset, chap_size);
  1151. if (rval != QLA_SUCCESS) {
  1152. ret = -EINVAL;
  1153. goto exit_get_chap;
  1154. }
  1155. DEBUG2(ql4_printk(KERN_INFO, ha, "Chap Cookie: x%x\n",
  1156. __le16_to_cpu(chap_table->cookie)));
  1157. if (__le16_to_cpu(chap_table->cookie) != CHAP_VALID_COOKIE) {
  1158. ql4_printk(KERN_ERR, ha, "No valid chap entry found\n");
  1159. goto exit_get_chap;
  1160. }
  1161. strncpy(password, chap_table->secret, QL4_CHAP_MAX_SECRET_LEN);
  1162. strncpy(username, chap_table->name, QL4_CHAP_MAX_NAME_LEN);
  1163. chap_table->cookie = __constant_cpu_to_le16(CHAP_VALID_COOKIE);
  1164. exit_get_chap:
  1165. dma_pool_free(ha->chap_dma_pool, chap_table, chap_dma);
  1166. return ret;
  1167. }
  1168. static int qla4xxx_set_chap(struct scsi_qla_host *ha, char *username,
  1169. char *password, uint16_t idx, int bidi)
  1170. {
  1171. int ret = 0;
  1172. int rval = QLA_ERROR;
  1173. uint32_t offset = 0;
  1174. struct ql4_chap_table *chap_table;
  1175. dma_addr_t chap_dma;
  1176. chap_table = dma_pool_alloc(ha->chap_dma_pool, GFP_KERNEL, &chap_dma);
  1177. if (chap_table == NULL) {
  1178. ret = -ENOMEM;
  1179. goto exit_set_chap;
  1180. }
  1181. memset(chap_table, 0, sizeof(struct ql4_chap_table));
  1182. if (bidi)
  1183. chap_table->flags |= BIT_6; /* peer */
  1184. else
  1185. chap_table->flags |= BIT_7; /* local */
  1186. chap_table->secret_len = strlen(password);
  1187. strncpy(chap_table->secret, password, MAX_CHAP_SECRET_LEN);
  1188. strncpy(chap_table->name, username, MAX_CHAP_NAME_LEN);
  1189. chap_table->cookie = __constant_cpu_to_le16(CHAP_VALID_COOKIE);
  1190. offset = FLASH_CHAP_OFFSET | (idx * sizeof(struct ql4_chap_table));
  1191. rval = qla4xxx_set_flash(ha, chap_dma, offset,
  1192. sizeof(struct ql4_chap_table),
  1193. FLASH_OPT_RMW_COMMIT);
  1194. if (rval == QLA_SUCCESS && ha->chap_list) {
  1195. /* Update ha chap_list cache */
  1196. memcpy((struct ql4_chap_table *)ha->chap_list + idx,
  1197. chap_table, sizeof(struct ql4_chap_table));
  1198. }
  1199. dma_pool_free(ha->chap_dma_pool, chap_table, chap_dma);
  1200. if (rval != QLA_SUCCESS)
  1201. ret = -EINVAL;
  1202. exit_set_chap:
  1203. return ret;
  1204. }
  1205. /**
  1206. * qla4xxx_get_chap_index - Get chap index given username and secret
  1207. * @ha: pointer to adapter structure
  1208. * @username: CHAP username to be searched
  1209. * @password: CHAP password to be searched
  1210. * @bidi: Is this a BIDI CHAP
  1211. * @chap_index: CHAP index to be returned
  1212. *
  1213. * Match the username and password in the chap_list, return the index if a
  1214. * match is found. If a match is not found then add the entry in FLASH and
  1215. * return the index at which entry is written in the FLASH.
  1216. **/
  1217. static int qla4xxx_get_chap_index(struct scsi_qla_host *ha, char *username,
  1218. char *password, int bidi, uint16_t *chap_index)
  1219. {
  1220. int i, rval;
  1221. int free_index = -1;
  1222. int found_index = 0;
  1223. int max_chap_entries = 0;
  1224. struct ql4_chap_table *chap_table;
  1225. if (is_qla8022(ha))
  1226. max_chap_entries = (ha->hw.flt_chap_size / 2) /
  1227. sizeof(struct ql4_chap_table);
  1228. else
  1229. max_chap_entries = MAX_CHAP_ENTRIES_40XX;
  1230. if (!ha->chap_list) {
  1231. ql4_printk(KERN_ERR, ha, "Do not have CHAP table cache\n");
  1232. return QLA_ERROR;
  1233. }
  1234. mutex_lock(&ha->chap_sem);
  1235. for (i = 0; i < max_chap_entries; i++) {
  1236. chap_table = (struct ql4_chap_table *)ha->chap_list + i;
  1237. if (chap_table->cookie !=
  1238. __constant_cpu_to_le16(CHAP_VALID_COOKIE)) {
  1239. if (i > MAX_RESRV_CHAP_IDX && free_index == -1)
  1240. free_index = i;
  1241. continue;
  1242. }
  1243. if (bidi) {
  1244. if (chap_table->flags & BIT_7)
  1245. continue;
  1246. } else {
  1247. if (chap_table->flags & BIT_6)
  1248. continue;
  1249. }
  1250. if (!strncmp(chap_table->secret, password,
  1251. MAX_CHAP_SECRET_LEN) &&
  1252. !strncmp(chap_table->name, username,
  1253. MAX_CHAP_NAME_LEN)) {
  1254. *chap_index = i;
  1255. found_index = 1;
  1256. break;
  1257. }
  1258. }
  1259. /* If chap entry is not present and a free index is available then
  1260. * write the entry in flash
  1261. */
  1262. if (!found_index && free_index != -1) {
  1263. rval = qla4xxx_set_chap(ha, username, password,
  1264. free_index, bidi);
  1265. if (!rval) {
  1266. *chap_index = free_index;
  1267. found_index = 1;
  1268. }
  1269. }
  1270. mutex_unlock(&ha->chap_sem);
  1271. if (found_index)
  1272. return QLA_SUCCESS;
  1273. return QLA_ERROR;
  1274. }
  1275. int qla4xxx_conn_close_sess_logout(struct scsi_qla_host *ha,
  1276. uint16_t fw_ddb_index,
  1277. uint16_t connection_id,
  1278. uint16_t option)
  1279. {
  1280. uint32_t mbox_cmd[MBOX_REG_COUNT];
  1281. uint32_t mbox_sts[MBOX_REG_COUNT];
  1282. int status = QLA_SUCCESS;
  1283. memset(&mbox_cmd, 0, sizeof(mbox_cmd));
  1284. memset(&mbox_sts, 0, sizeof(mbox_sts));
  1285. mbox_cmd[0] = MBOX_CMD_CONN_CLOSE_SESS_LOGOUT;
  1286. mbox_cmd[1] = fw_ddb_index;
  1287. mbox_cmd[2] = connection_id;
  1288. mbox_cmd[3] = option;
  1289. status = qla4xxx_mailbox_command(ha, 4, 2, &mbox_cmd[0], &mbox_sts[0]);
  1290. if (status != QLA_SUCCESS) {
  1291. DEBUG2(ql4_printk(KERN_WARNING, ha, "%s: MBOX_CMD_CONN_CLOSE "
  1292. "option %04x failed w/ status %04X %04X\n",
  1293. __func__, option, mbox_sts[0], mbox_sts[1]));
  1294. }
  1295. return status;
  1296. }
  1297. int qla4xxx_disable_acb(struct scsi_qla_host *ha)
  1298. {
  1299. uint32_t mbox_cmd[MBOX_REG_COUNT];
  1300. uint32_t mbox_sts[MBOX_REG_COUNT];
  1301. int status = QLA_SUCCESS;
  1302. memset(&mbox_cmd, 0, sizeof(mbox_cmd));
  1303. memset(&mbox_sts, 0, sizeof(mbox_sts));
  1304. mbox_cmd[0] = MBOX_CMD_DISABLE_ACB;
  1305. status = qla4xxx_mailbox_command(ha, 8, 5, &mbox_cmd[0], &mbox_sts[0]);
  1306. if (status != QLA_SUCCESS) {
  1307. DEBUG2(ql4_printk(KERN_WARNING, ha, "%s: MBOX_CMD_DISABLE_ACB "
  1308. "failed w/ status %04X %04X %04X", __func__,
  1309. mbox_sts[0], mbox_sts[1], mbox_sts[2]));
  1310. }
  1311. return status;
  1312. }
  1313. int qla4xxx_get_acb(struct scsi_qla_host *ha, dma_addr_t acb_dma,
  1314. uint32_t acb_type, uint32_t len)
  1315. {
  1316. uint32_t mbox_cmd[MBOX_REG_COUNT];
  1317. uint32_t mbox_sts[MBOX_REG_COUNT];
  1318. int status = QLA_SUCCESS;
  1319. memset(&mbox_cmd, 0, sizeof(mbox_cmd));
  1320. memset(&mbox_sts, 0, sizeof(mbox_sts));
  1321. mbox_cmd[0] = MBOX_CMD_GET_ACB;
  1322. mbox_cmd[1] = acb_type;
  1323. mbox_cmd[2] = LSDW(acb_dma);
  1324. mbox_cmd[3] = MSDW(acb_dma);
  1325. mbox_cmd[4] = len;
  1326. status = qla4xxx_mailbox_command(ha, 5, 5, &mbox_cmd[0], &mbox_sts[0]);
  1327. if (status != QLA_SUCCESS) {
  1328. DEBUG2(ql4_printk(KERN_WARNING, ha, "%s: MBOX_CMD_GET_ACB "
  1329. "failed w/ status %04X\n", __func__,
  1330. mbox_sts[0]));
  1331. }
  1332. return status;
  1333. }
  1334. int qla4xxx_set_acb(struct scsi_qla_host *ha, uint32_t *mbox_cmd,
  1335. uint32_t *mbox_sts, dma_addr_t acb_dma)
  1336. {
  1337. int status = QLA_SUCCESS;
  1338. memset(mbox_cmd, 0, sizeof(mbox_cmd[0]) * MBOX_REG_COUNT);
  1339. memset(mbox_sts, 0, sizeof(mbox_sts[0]) * MBOX_REG_COUNT);
  1340. mbox_cmd[0] = MBOX_CMD_SET_ACB;
  1341. mbox_cmd[1] = 0; /* Primary ACB */
  1342. mbox_cmd[2] = LSDW(acb_dma);
  1343. mbox_cmd[3] = MSDW(acb_dma);
  1344. mbox_cmd[4] = sizeof(struct addr_ctrl_blk);
  1345. status = qla4xxx_mailbox_command(ha, 5, 5, &mbox_cmd[0], &mbox_sts[0]);
  1346. if (status != QLA_SUCCESS) {
  1347. DEBUG2(ql4_printk(KERN_WARNING, ha, "%s: MBOX_CMD_SET_ACB "
  1348. "failed w/ status %04X\n", __func__,
  1349. mbox_sts[0]));
  1350. }
  1351. return status;
  1352. }
  1353. int qla4xxx_set_param_ddbentry(struct scsi_qla_host *ha,
  1354. struct ddb_entry *ddb_entry,
  1355. struct iscsi_cls_conn *cls_conn,
  1356. uint32_t *mbx_sts)
  1357. {
  1358. struct dev_db_entry *fw_ddb_entry;
  1359. struct iscsi_conn *conn;
  1360. struct iscsi_session *sess;
  1361. struct qla_conn *qla_conn;
  1362. struct sockaddr *dst_addr;
  1363. dma_addr_t fw_ddb_entry_dma;
  1364. int status = QLA_SUCCESS;
  1365. int rval = 0;
  1366. struct sockaddr_in *addr;
  1367. struct sockaddr_in6 *addr6;
  1368. char *ip;
  1369. uint16_t iscsi_opts = 0;
  1370. uint32_t options = 0;
  1371. uint16_t idx;
  1372. fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
  1373. &fw_ddb_entry_dma, GFP_KERNEL);
  1374. if (!fw_ddb_entry) {
  1375. DEBUG2(ql4_printk(KERN_ERR, ha,
  1376. "%s: Unable to allocate dma buffer.\n",
  1377. __func__));
  1378. rval = -ENOMEM;
  1379. goto exit_set_param_no_free;
  1380. }
  1381. conn = cls_conn->dd_data;
  1382. qla_conn = conn->dd_data;
  1383. sess = conn->session;
  1384. dst_addr = &qla_conn->qla_ep->dst_addr;
  1385. if (dst_addr->sa_family == AF_INET6)
  1386. options |= IPV6_DEFAULT_DDB_ENTRY;
  1387. status = qla4xxx_get_default_ddb(ha, options, fw_ddb_entry_dma);
  1388. if (status == QLA_ERROR) {
  1389. rval = -EINVAL;
  1390. goto exit_set_param;
  1391. }
  1392. iscsi_opts = le16_to_cpu(fw_ddb_entry->iscsi_options);
  1393. memset(fw_ddb_entry->iscsi_alias, 0, sizeof(fw_ddb_entry->iscsi_alias));
  1394. memset(fw_ddb_entry->iscsi_name, 0, sizeof(fw_ddb_entry->iscsi_name));
  1395. if (sess->targetname != NULL) {
  1396. memcpy(fw_ddb_entry->iscsi_name, sess->targetname,
  1397. min(strlen(sess->targetname),
  1398. sizeof(fw_ddb_entry->iscsi_name)));
  1399. }
  1400. memset(fw_ddb_entry->ip_addr, 0, sizeof(fw_ddb_entry->ip_addr));
  1401. memset(fw_ddb_entry->tgt_addr, 0, sizeof(fw_ddb_entry->tgt_addr));
  1402. fw_ddb_entry->options = DDB_OPT_TARGET | DDB_OPT_AUTO_SENDTGTS_DISABLE;
  1403. if (dst_addr->sa_family == AF_INET) {
  1404. addr = (struct sockaddr_in *)dst_addr;
  1405. ip = (char *)&addr->sin_addr;
  1406. memcpy(fw_ddb_entry->ip_addr, ip, IP_ADDR_LEN);
  1407. fw_ddb_entry->port = cpu_to_le16(ntohs(addr->sin_port));
  1408. DEBUG2(ql4_printk(KERN_INFO, ha,
  1409. "%s: Destination Address [%pI4]: index [%d]\n",
  1410. __func__, fw_ddb_entry->ip_addr,
  1411. ddb_entry->fw_ddb_index));
  1412. } else if (dst_addr->sa_family == AF_INET6) {
  1413. addr6 = (struct sockaddr_in6 *)dst_addr;
  1414. ip = (char *)&addr6->sin6_addr;
  1415. memcpy(fw_ddb_entry->ip_addr, ip, IPv6_ADDR_LEN);
  1416. fw_ddb_entry->port = cpu_to_le16(ntohs(addr6->sin6_port));
  1417. fw_ddb_entry->options |= DDB_OPT_IPV6_DEVICE;
  1418. DEBUG2(ql4_printk(KERN_INFO, ha,
  1419. "%s: Destination Address [%pI6]: index [%d]\n",
  1420. __func__, fw_ddb_entry->ip_addr,
  1421. ddb_entry->fw_ddb_index));
  1422. } else {
  1423. ql4_printk(KERN_ERR, ha,
  1424. "%s: Failed to get IP Address\n",
  1425. __func__);
  1426. rval = -EINVAL;
  1427. goto exit_set_param;
  1428. }
  1429. /* CHAP */
  1430. if (sess->username != NULL && sess->password != NULL) {
  1431. if (strlen(sess->username) && strlen(sess->password)) {
  1432. iscsi_opts |= BIT_7;
  1433. rval = qla4xxx_get_chap_index(ha, sess->username,
  1434. sess->password,
  1435. LOCAL_CHAP, &idx);
  1436. if (rval)
  1437. goto exit_set_param;
  1438. fw_ddb_entry->chap_tbl_idx = cpu_to_le16(idx);
  1439. }
  1440. }
  1441. if (sess->username_in != NULL && sess->password_in != NULL) {
  1442. /* Check if BIDI CHAP */
  1443. if (strlen(sess->username_in) && strlen(sess->password_in)) {
  1444. iscsi_opts |= BIT_4;
  1445. rval = qla4xxx_get_chap_index(ha, sess->username_in,
  1446. sess->password_in,
  1447. BIDI_CHAP, &idx);
  1448. if (rval)
  1449. goto exit_set_param;
  1450. }
  1451. }
  1452. if (sess->initial_r2t_en)
  1453. iscsi_opts |= BIT_10;
  1454. if (sess->imm_data_en)
  1455. iscsi_opts |= BIT_11;
  1456. fw_ddb_entry->iscsi_options = cpu_to_le16(iscsi_opts);
  1457. if (conn->max_recv_dlength)
  1458. fw_ddb_entry->iscsi_max_rcv_data_seg_len =
  1459. __constant_cpu_to_le16((conn->max_recv_dlength / BYTE_UNITS));
  1460. if (sess->max_r2t)
  1461. fw_ddb_entry->iscsi_max_outsnd_r2t = cpu_to_le16(sess->max_r2t);
  1462. if (sess->first_burst)
  1463. fw_ddb_entry->iscsi_first_burst_len =
  1464. __constant_cpu_to_le16((sess->first_burst / BYTE_UNITS));
  1465. if (sess->max_burst)
  1466. fw_ddb_entry->iscsi_max_burst_len =
  1467. __constant_cpu_to_le16((sess->max_burst / BYTE_UNITS));
  1468. if (sess->time2wait)
  1469. fw_ddb_entry->iscsi_def_time2wait =
  1470. cpu_to_le16(sess->time2wait);
  1471. if (sess->time2retain)
  1472. fw_ddb_entry->iscsi_def_time2retain =
  1473. cpu_to_le16(sess->time2retain);
  1474. status = qla4xxx_set_ddb_entry(ha, ddb_entry->fw_ddb_index,
  1475. fw_ddb_entry_dma, mbx_sts);
  1476. if (status != QLA_SUCCESS)
  1477. rval = -EINVAL;
  1478. exit_set_param:
  1479. dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
  1480. fw_ddb_entry, fw_ddb_entry_dma);
  1481. exit_set_param_no_free:
  1482. return rval;
  1483. }
  1484. int qla4xxx_get_mgmt_data(struct scsi_qla_host *ha, uint16_t fw_ddb_index,
  1485. uint16_t stats_size, dma_addr_t stats_dma)
  1486. {
  1487. int status = QLA_SUCCESS;
  1488. uint32_t mbox_cmd[MBOX_REG_COUNT];
  1489. uint32_t mbox_sts[MBOX_REG_COUNT];
  1490. memset(mbox_cmd, 0, sizeof(mbox_cmd[0]) * MBOX_REG_COUNT);
  1491. memset(mbox_sts, 0, sizeof(mbox_sts[0]) * MBOX_REG_COUNT);
  1492. mbox_cmd[0] = MBOX_CMD_GET_MANAGEMENT_DATA;
  1493. mbox_cmd[1] = fw_ddb_index;
  1494. mbox_cmd[2] = LSDW(stats_dma);
  1495. mbox_cmd[3] = MSDW(stats_dma);
  1496. mbox_cmd[4] = stats_size;
  1497. status = qla4xxx_mailbox_command(ha, 5, 1, &mbox_cmd[0], &mbox_sts[0]);
  1498. if (status != QLA_SUCCESS) {
  1499. DEBUG2(ql4_printk(KERN_WARNING, ha,
  1500. "%s: MBOX_CMD_GET_MANAGEMENT_DATA "
  1501. "failed w/ status %04X\n", __func__,
  1502. mbox_sts[0]));
  1503. }
  1504. return status;
  1505. }
  1506. int qla4xxx_get_ip_state(struct scsi_qla_host *ha, uint32_t acb_idx,
  1507. uint32_t ip_idx, uint32_t *sts)
  1508. {
  1509. uint32_t mbox_cmd[MBOX_REG_COUNT];
  1510. uint32_t mbox_sts[MBOX_REG_COUNT];
  1511. int status = QLA_SUCCESS;
  1512. memset(&mbox_cmd, 0, sizeof(mbox_cmd));
  1513. memset(&mbox_sts, 0, sizeof(mbox_sts));
  1514. mbox_cmd[0] = MBOX_CMD_GET_IP_ADDR_STATE;
  1515. mbox_cmd[1] = acb_idx;
  1516. mbox_cmd[2] = ip_idx;
  1517. status = qla4xxx_mailbox_command(ha, 3, 8, &mbox_cmd[0], &mbox_sts[0]);
  1518. if (status != QLA_SUCCESS) {
  1519. DEBUG2(ql4_printk(KERN_WARNING, ha, "%s: "
  1520. "MBOX_CMD_GET_IP_ADDR_STATE failed w/ "
  1521. "status %04X\n", __func__, mbox_sts[0]));
  1522. }
  1523. memcpy(sts, mbox_sts, sizeof(mbox_sts));
  1524. return status;
  1525. }
  1526. int qla4xxx_get_nvram(struct scsi_qla_host *ha, dma_addr_t nvram_dma,
  1527. uint32_t offset, uint32_t size)
  1528. {
  1529. int status = QLA_SUCCESS;
  1530. uint32_t mbox_cmd[MBOX_REG_COUNT];
  1531. uint32_t mbox_sts[MBOX_REG_COUNT];
  1532. memset(&mbox_cmd, 0, sizeof(mbox_cmd));
  1533. memset(&mbox_sts, 0, sizeof(mbox_sts));
  1534. mbox_cmd[0] = MBOX_CMD_GET_NVRAM;
  1535. mbox_cmd[1] = LSDW(nvram_dma);
  1536. mbox_cmd[2] = MSDW(nvram_dma);
  1537. mbox_cmd[3] = offset;
  1538. mbox_cmd[4] = size;
  1539. status = qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 1, &mbox_cmd[0],
  1540. &mbox_sts[0]);
  1541. if (status != QLA_SUCCESS) {
  1542. DEBUG2(ql4_printk(KERN_ERR, ha, "scsi%ld: %s: failed "
  1543. "status %04X\n", ha->host_no, __func__,
  1544. mbox_sts[0]));
  1545. }
  1546. return status;
  1547. }
  1548. int qla4xxx_set_nvram(struct scsi_qla_host *ha, dma_addr_t nvram_dma,
  1549. uint32_t offset, uint32_t size)
  1550. {
  1551. int status = QLA_SUCCESS;
  1552. uint32_t mbox_cmd[MBOX_REG_COUNT];
  1553. uint32_t mbox_sts[MBOX_REG_COUNT];
  1554. memset(&mbox_cmd, 0, sizeof(mbox_cmd));
  1555. memset(&mbox_sts, 0, sizeof(mbox_sts));
  1556. mbox_cmd[0] = MBOX_CMD_SET_NVRAM;
  1557. mbox_cmd[1] = LSDW(nvram_dma);
  1558. mbox_cmd[2] = MSDW(nvram_dma);
  1559. mbox_cmd[3] = offset;
  1560. mbox_cmd[4] = size;
  1561. status = qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 1, &mbox_cmd[0],
  1562. &mbox_sts[0]);
  1563. if (status != QLA_SUCCESS) {
  1564. DEBUG2(ql4_printk(KERN_ERR, ha, "scsi%ld: %s: failed "
  1565. "status %04X\n", ha->host_no, __func__,
  1566. mbox_sts[0]));
  1567. }
  1568. return status;
  1569. }
  1570. int qla4xxx_restore_factory_defaults(struct scsi_qla_host *ha,
  1571. uint32_t region, uint32_t field0,
  1572. uint32_t field1)
  1573. {
  1574. int status = QLA_SUCCESS;
  1575. uint32_t mbox_cmd[MBOX_REG_COUNT];
  1576. uint32_t mbox_sts[MBOX_REG_COUNT];
  1577. memset(&mbox_cmd, 0, sizeof(mbox_cmd));
  1578. memset(&mbox_sts, 0, sizeof(mbox_sts));
  1579. mbox_cmd[0] = MBOX_CMD_RESTORE_FACTORY_DEFAULTS;
  1580. mbox_cmd[3] = region;
  1581. mbox_cmd[4] = field0;
  1582. mbox_cmd[5] = field1;
  1583. status = qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 3, &mbox_cmd[0],
  1584. &mbox_sts[0]);
  1585. if (status != QLA_SUCCESS) {
  1586. DEBUG2(ql4_printk(KERN_ERR, ha, "scsi%ld: %s: failed "
  1587. "status %04X\n", ha->host_no, __func__,
  1588. mbox_sts[0]));
  1589. }
  1590. return status;
  1591. }