ql4_mbx.c 57 KB

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