ql4_mbx.c 58 KB

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