ql4_mbx.c 62 KB

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