ql4_mbx.c 55 KB

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