ql4_mbx.c 54 KB

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