ql4_mbx.c 55 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869
  1. /*
  2. * QLogic iSCSI HBA Driver
  3. * Copyright (c) 2003-2010 QLogic Corporation
  4. *
  5. * See LICENSE.qla4xxx for copyright and licensing details.
  6. */
  7. #include "ql4_def.h"
  8. #include "ql4_glbl.h"
  9. #include "ql4_dbg.h"
  10. #include "ql4_inline.h"
  11. /**
  12. * qla4xxx_mailbox_command - issues mailbox commands
  13. * @ha: Pointer to host adapter structure.
  14. * @inCount: number of mailbox registers to load.
  15. * @outCount: number of mailbox registers to return.
  16. * @mbx_cmd: data pointer for mailbox in registers.
  17. * @mbx_sts: data pointer for mailbox out registers.
  18. *
  19. * This routine issue mailbox commands and waits for completion.
  20. * If outCount is 0, this routine completes successfully WITHOUT waiting
  21. * for the mailbox command to complete.
  22. **/
  23. int qla4xxx_mailbox_command(struct scsi_qla_host *ha, uint8_t inCount,
  24. uint8_t outCount, uint32_t *mbx_cmd,
  25. uint32_t *mbx_sts)
  26. {
  27. int status = QLA_ERROR;
  28. uint8_t i;
  29. u_long wait_count;
  30. uint32_t intr_status;
  31. unsigned long flags = 0;
  32. uint32_t dev_state;
  33. /* Make sure that pointers are valid */
  34. if (!mbx_cmd || !mbx_sts) {
  35. DEBUG2(printk("scsi%ld: %s: Invalid mbx_cmd or mbx_sts "
  36. "pointer\n", ha->host_no, __func__));
  37. return status;
  38. }
  39. if (is_qla40XX(ha)) {
  40. if (test_bit(AF_HA_REMOVAL, &ha->flags)) {
  41. DEBUG2(ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: "
  42. "prematurely completing mbx cmd as "
  43. "adapter removal detected\n",
  44. ha->host_no, __func__));
  45. return status;
  46. }
  47. }
  48. if (is_qla8022(ha)) {
  49. if (test_bit(AF_FW_RECOVERY, &ha->flags)) {
  50. DEBUG2(ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: "
  51. "prematurely completing mbx cmd as firmware "
  52. "recovery detected\n", ha->host_no, __func__));
  53. return status;
  54. }
  55. /* Do not send any mbx cmd if h/w is in failed state*/
  56. qla4_8xxx_idc_lock(ha);
  57. dev_state = qla4_8xxx_rd_32(ha, QLA82XX_CRB_DEV_STATE);
  58. qla4_8xxx_idc_unlock(ha);
  59. if (dev_state == QLA82XX_DEV_FAILED) {
  60. ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: H/W is in "
  61. "failed state, do not send any mailbox commands\n",
  62. ha->host_no, __func__);
  63. return status;
  64. }
  65. }
  66. if ((is_aer_supported(ha)) &&
  67. (test_bit(AF_PCI_CHANNEL_IO_PERM_FAILURE, &ha->flags))) {
  68. DEBUG2(printk(KERN_WARNING "scsi%ld: %s: Perm failure on EEH, "
  69. "timeout MBX Exiting.\n", ha->host_no, __func__));
  70. return status;
  71. }
  72. /* Mailbox code active */
  73. wait_count = MBOX_TOV * 100;
  74. while (wait_count--) {
  75. mutex_lock(&ha->mbox_sem);
  76. if (!test_bit(AF_MBOX_COMMAND, &ha->flags)) {
  77. set_bit(AF_MBOX_COMMAND, &ha->flags);
  78. mutex_unlock(&ha->mbox_sem);
  79. break;
  80. }
  81. mutex_unlock(&ha->mbox_sem);
  82. if (!wait_count) {
  83. DEBUG2(printk("scsi%ld: %s: mbox_sem failed\n",
  84. ha->host_no, __func__));
  85. return status;
  86. }
  87. msleep(10);
  88. }
  89. spin_lock_irqsave(&ha->hardware_lock, flags);
  90. ha->mbox_status_count = outCount;
  91. for (i = 0; i < outCount; i++)
  92. ha->mbox_status[i] = 0;
  93. if (is_qla8022(ha)) {
  94. /* Load all mailbox registers, except mailbox 0. */
  95. DEBUG5(
  96. printk("scsi%ld: %s: Cmd ", ha->host_no, __func__);
  97. for (i = 0; i < inCount; i++)
  98. printk("mb%d=%04x ", i, mbx_cmd[i]);
  99. printk("\n"));
  100. for (i = 1; i < inCount; i++)
  101. writel(mbx_cmd[i], &ha->qla4_8xxx_reg->mailbox_in[i]);
  102. writel(mbx_cmd[0], &ha->qla4_8xxx_reg->mailbox_in[0]);
  103. readl(&ha->qla4_8xxx_reg->mailbox_in[0]);
  104. writel(HINT_MBX_INT_PENDING, &ha->qla4_8xxx_reg->hint);
  105. } else {
  106. /* Load all mailbox registers, except mailbox 0. */
  107. for (i = 1; i < inCount; i++)
  108. writel(mbx_cmd[i], &ha->reg->mailbox[i]);
  109. /* Wakeup firmware */
  110. writel(mbx_cmd[0], &ha->reg->mailbox[0]);
  111. readl(&ha->reg->mailbox[0]);
  112. writel(set_rmask(CSR_INTR_RISC), &ha->reg->ctrl_status);
  113. readl(&ha->reg->ctrl_status);
  114. }
  115. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  116. /* Wait for completion */
  117. /*
  118. * If we don't want status, don't wait for the mailbox command to
  119. * complete. For example, MBOX_CMD_RESET_FW doesn't return status,
  120. * you must poll the inbound Interrupt Mask for completion.
  121. */
  122. if (outCount == 0) {
  123. status = QLA_SUCCESS;
  124. goto mbox_exit;
  125. }
  126. /*
  127. * Wait for completion: Poll or completion queue
  128. */
  129. if (test_bit(AF_IRQ_ATTACHED, &ha->flags) &&
  130. test_bit(AF_INTERRUPTS_ON, &ha->flags) &&
  131. test_bit(AF_ONLINE, &ha->flags) &&
  132. !test_bit(AF_HA_REMOVAL, &ha->flags)) {
  133. /* Do not poll for completion. Use completion queue */
  134. set_bit(AF_MBOX_COMMAND_NOPOLL, &ha->flags);
  135. wait_for_completion_timeout(&ha->mbx_intr_comp, MBOX_TOV * HZ);
  136. clear_bit(AF_MBOX_COMMAND_NOPOLL, &ha->flags);
  137. } else {
  138. /* Poll for command to complete */
  139. wait_count = jiffies + MBOX_TOV * HZ;
  140. while (test_bit(AF_MBOX_COMMAND_DONE, &ha->flags) == 0) {
  141. if (time_after_eq(jiffies, wait_count))
  142. break;
  143. /*
  144. * Service the interrupt.
  145. * The ISR will save the mailbox status registers
  146. * to a temporary storage location in the adapter
  147. * structure.
  148. */
  149. spin_lock_irqsave(&ha->hardware_lock, flags);
  150. if (is_qla8022(ha)) {
  151. intr_status =
  152. readl(&ha->qla4_8xxx_reg->host_int);
  153. if (intr_status & ISRX_82XX_RISC_INT) {
  154. ha->mbox_status_count = outCount;
  155. intr_status =
  156. readl(&ha->qla4_8xxx_reg->host_status);
  157. ha->isp_ops->interrupt_service_routine(
  158. ha, intr_status);
  159. if (test_bit(AF_INTERRUPTS_ON,
  160. &ha->flags) &&
  161. test_bit(AF_INTx_ENABLED,
  162. &ha->flags))
  163. qla4_8xxx_wr_32(ha,
  164. ha->nx_legacy_intr.tgt_mask_reg,
  165. 0xfbff);
  166. }
  167. } else {
  168. intr_status = readl(&ha->reg->ctrl_status);
  169. if (intr_status & INTR_PENDING) {
  170. /*
  171. * Service the interrupt.
  172. * The ISR will save the mailbox status
  173. * registers to a temporary storage
  174. * location in the adapter structure.
  175. */
  176. ha->mbox_status_count = outCount;
  177. ha->isp_ops->interrupt_service_routine(
  178. ha, intr_status);
  179. }
  180. }
  181. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  182. msleep(10);
  183. }
  184. }
  185. /* Check for mailbox timeout. */
  186. if (!test_bit(AF_MBOX_COMMAND_DONE, &ha->flags)) {
  187. if (is_qla8022(ha) &&
  188. test_bit(AF_FW_RECOVERY, &ha->flags)) {
  189. DEBUG2(ql4_printk(KERN_INFO, ha,
  190. "scsi%ld: %s: prematurely completing mbx cmd as "
  191. "firmware recovery detected\n",
  192. ha->host_no, __func__));
  193. goto mbox_exit;
  194. }
  195. DEBUG2(printk("scsi%ld: Mailbox Cmd 0x%08X timed out ...,"
  196. " Scheduling Adapter Reset\n", ha->host_no,
  197. mbx_cmd[0]));
  198. ha->mailbox_timeout_count++;
  199. mbx_sts[0] = (-1);
  200. set_bit(DPC_RESET_HA, &ha->dpc_flags);
  201. if (is_qla8022(ha)) {
  202. ql4_printk(KERN_INFO, ha,
  203. "disabling pause transmit on port 0 & 1.\n");
  204. qla4_8xxx_wr_32(ha, QLA82XX_CRB_NIU + 0x98,
  205. CRB_NIU_XG_PAUSE_CTL_P0 |
  206. CRB_NIU_XG_PAUSE_CTL_P1);
  207. }
  208. goto mbox_exit;
  209. }
  210. /*
  211. * Copy the mailbox out registers to the caller's mailbox in/out
  212. * structure.
  213. */
  214. spin_lock_irqsave(&ha->hardware_lock, flags);
  215. for (i = 0; i < outCount; i++)
  216. mbx_sts[i] = ha->mbox_status[i];
  217. /* Set return status and error flags (if applicable). */
  218. switch (ha->mbox_status[0]) {
  219. case MBOX_STS_COMMAND_COMPLETE:
  220. status = QLA_SUCCESS;
  221. break;
  222. case MBOX_STS_INTERMEDIATE_COMPLETION:
  223. status = QLA_SUCCESS;
  224. break;
  225. case MBOX_STS_BUSY:
  226. DEBUG2( printk("scsi%ld: %s: Cmd = %08X, ISP BUSY\n",
  227. ha->host_no, __func__, mbx_cmd[0]));
  228. ha->mailbox_timeout_count++;
  229. break;
  230. default:
  231. DEBUG2(printk("scsi%ld: %s: **** FAILED, cmd = %08X, "
  232. "sts = %08X ****\n", ha->host_no, __func__,
  233. mbx_cmd[0], mbx_sts[0]));
  234. break;
  235. }
  236. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  237. mbox_exit:
  238. mutex_lock(&ha->mbox_sem);
  239. clear_bit(AF_MBOX_COMMAND, &ha->flags);
  240. mutex_unlock(&ha->mbox_sem);
  241. clear_bit(AF_MBOX_COMMAND_DONE, &ha->flags);
  242. return status;
  243. }
  244. void qla4xxx_mailbox_premature_completion(struct scsi_qla_host *ha)
  245. {
  246. set_bit(AF_FW_RECOVERY, &ha->flags);
  247. ql4_printk(KERN_INFO, ha, "scsi%ld: %s: set FW RECOVERY!\n",
  248. ha->host_no, __func__);
  249. if (test_bit(AF_MBOX_COMMAND, &ha->flags)) {
  250. if (test_bit(AF_MBOX_COMMAND_NOPOLL, &ha->flags)) {
  251. complete(&ha->mbx_intr_comp);
  252. ql4_printk(KERN_INFO, ha, "scsi%ld: %s: Due to fw "
  253. "recovery, doing premature completion of "
  254. "mbx cmd\n", ha->host_no, __func__);
  255. } else {
  256. set_bit(AF_MBOX_COMMAND_DONE, &ha->flags);
  257. ql4_printk(KERN_INFO, ha, "scsi%ld: %s: Due to fw "
  258. "recovery, doing premature completion of "
  259. "polling mbx cmd\n", ha->host_no, __func__);
  260. }
  261. }
  262. }
  263. static uint8_t
  264. qla4xxx_set_ifcb(struct scsi_qla_host *ha, uint32_t *mbox_cmd,
  265. uint32_t *mbox_sts, dma_addr_t init_fw_cb_dma)
  266. {
  267. memset(mbox_cmd, 0, sizeof(mbox_cmd[0]) * MBOX_REG_COUNT);
  268. memset(mbox_sts, 0, sizeof(mbox_sts[0]) * MBOX_REG_COUNT);
  269. if (is_qla8022(ha))
  270. qla4_8xxx_wr_32(ha, ha->nx_db_wr_ptr, 0);
  271. mbox_cmd[0] = MBOX_CMD_INITIALIZE_FIRMWARE;
  272. mbox_cmd[1] = 0;
  273. mbox_cmd[2] = LSDW(init_fw_cb_dma);
  274. mbox_cmd[3] = MSDW(init_fw_cb_dma);
  275. mbox_cmd[4] = sizeof(struct addr_ctrl_blk);
  276. mbox_cmd[5] = (IFCB_VER_MAX << 8) | IFCB_VER_MIN;
  277. if (qla4xxx_mailbox_command(ha, 6, 6, mbox_cmd, mbox_sts) !=
  278. QLA_SUCCESS) {
  279. DEBUG2(printk(KERN_WARNING "scsi%ld: %s: "
  280. "MBOX_CMD_INITIALIZE_FIRMWARE"
  281. " failed w/ status %04X\n",
  282. ha->host_no, __func__, mbox_sts[0]));
  283. return QLA_ERROR;
  284. }
  285. return QLA_SUCCESS;
  286. }
  287. uint8_t
  288. qla4xxx_get_ifcb(struct scsi_qla_host *ha, uint32_t *mbox_cmd,
  289. uint32_t *mbox_sts, dma_addr_t init_fw_cb_dma)
  290. {
  291. memset(mbox_cmd, 0, sizeof(mbox_cmd[0]) * MBOX_REG_COUNT);
  292. memset(mbox_sts, 0, sizeof(mbox_sts[0]) * MBOX_REG_COUNT);
  293. mbox_cmd[0] = MBOX_CMD_GET_INIT_FW_CTRL_BLOCK;
  294. mbox_cmd[2] = LSDW(init_fw_cb_dma);
  295. mbox_cmd[3] = MSDW(init_fw_cb_dma);
  296. mbox_cmd[4] = sizeof(struct addr_ctrl_blk);
  297. if (qla4xxx_mailbox_command(ha, 5, 5, mbox_cmd, mbox_sts) !=
  298. QLA_SUCCESS) {
  299. DEBUG2(printk(KERN_WARNING "scsi%ld: %s: "
  300. "MBOX_CMD_GET_INIT_FW_CTRL_BLOCK"
  301. " failed w/ status %04X\n",
  302. ha->host_no, __func__, mbox_sts[0]));
  303. return QLA_ERROR;
  304. }
  305. return QLA_SUCCESS;
  306. }
  307. static void
  308. qla4xxx_update_local_ip(struct scsi_qla_host *ha,
  309. struct addr_ctrl_blk *init_fw_cb)
  310. {
  311. ha->ip_config.tcp_options = le16_to_cpu(init_fw_cb->ipv4_tcp_opts);
  312. ha->ip_config.ipv4_options = le16_to_cpu(init_fw_cb->ipv4_ip_opts);
  313. ha->ip_config.ipv4_addr_state =
  314. le16_to_cpu(init_fw_cb->ipv4_addr_state);
  315. ha->ip_config.eth_mtu_size =
  316. le16_to_cpu(init_fw_cb->eth_mtu_size);
  317. ha->ip_config.ipv4_port = le16_to_cpu(init_fw_cb->ipv4_port);
  318. if (ha->acb_version == ACB_SUPPORTED) {
  319. ha->ip_config.ipv6_options = le16_to_cpu(init_fw_cb->ipv6_opts);
  320. ha->ip_config.ipv6_addl_options =
  321. le16_to_cpu(init_fw_cb->ipv6_addtl_opts);
  322. }
  323. /* Save IPv4 Address Info */
  324. memcpy(ha->ip_config.ip_address, init_fw_cb->ipv4_addr,
  325. min(sizeof(ha->ip_config.ip_address),
  326. sizeof(init_fw_cb->ipv4_addr)));
  327. memcpy(ha->ip_config.subnet_mask, init_fw_cb->ipv4_subnet,
  328. min(sizeof(ha->ip_config.subnet_mask),
  329. sizeof(init_fw_cb->ipv4_subnet)));
  330. memcpy(ha->ip_config.gateway, init_fw_cb->ipv4_gw_addr,
  331. min(sizeof(ha->ip_config.gateway),
  332. sizeof(init_fw_cb->ipv4_gw_addr)));
  333. ha->ip_config.ipv4_vlan_tag = be16_to_cpu(init_fw_cb->ipv4_vlan_tag);
  334. if (is_ipv6_enabled(ha)) {
  335. /* Save IPv6 Address */
  336. ha->ip_config.ipv6_link_local_state =
  337. le16_to_cpu(init_fw_cb->ipv6_lnk_lcl_addr_state);
  338. ha->ip_config.ipv6_addr0_state =
  339. le16_to_cpu(init_fw_cb->ipv6_addr0_state);
  340. ha->ip_config.ipv6_addr1_state =
  341. le16_to_cpu(init_fw_cb->ipv6_addr1_state);
  342. ha->ip_config.ipv6_default_router_state =
  343. le16_to_cpu(init_fw_cb->ipv6_dflt_rtr_state);
  344. ha->ip_config.ipv6_link_local_addr.in6_u.u6_addr8[0] = 0xFE;
  345. ha->ip_config.ipv6_link_local_addr.in6_u.u6_addr8[1] = 0x80;
  346. memcpy(&ha->ip_config.ipv6_link_local_addr.in6_u.u6_addr8[8],
  347. init_fw_cb->ipv6_if_id,
  348. min(sizeof(ha->ip_config.ipv6_link_local_addr)/2,
  349. sizeof(init_fw_cb->ipv6_if_id)));
  350. memcpy(&ha->ip_config.ipv6_addr0, init_fw_cb->ipv6_addr0,
  351. min(sizeof(ha->ip_config.ipv6_addr0),
  352. sizeof(init_fw_cb->ipv6_addr0)));
  353. memcpy(&ha->ip_config.ipv6_addr1, init_fw_cb->ipv6_addr1,
  354. min(sizeof(ha->ip_config.ipv6_addr1),
  355. sizeof(init_fw_cb->ipv6_addr1)));
  356. memcpy(&ha->ip_config.ipv6_default_router_addr,
  357. init_fw_cb->ipv6_dflt_rtr_addr,
  358. min(sizeof(ha->ip_config.ipv6_default_router_addr),
  359. sizeof(init_fw_cb->ipv6_dflt_rtr_addr)));
  360. ha->ip_config.ipv6_vlan_tag =
  361. be16_to_cpu(init_fw_cb->ipv6_vlan_tag);
  362. ha->ip_config.ipv6_port = le16_to_cpu(init_fw_cb->ipv6_port);
  363. }
  364. }
  365. uint8_t
  366. qla4xxx_update_local_ifcb(struct scsi_qla_host *ha,
  367. uint32_t *mbox_cmd,
  368. uint32_t *mbox_sts,
  369. struct addr_ctrl_blk *init_fw_cb,
  370. dma_addr_t init_fw_cb_dma)
  371. {
  372. if (qla4xxx_get_ifcb(ha, mbox_cmd, mbox_sts, init_fw_cb_dma)
  373. != QLA_SUCCESS) {
  374. DEBUG2(printk(KERN_WARNING
  375. "scsi%ld: %s: Failed to get init_fw_ctrl_blk\n",
  376. ha->host_no, __func__));
  377. return QLA_ERROR;
  378. }
  379. DEBUG2(qla4xxx_dump_buffer(init_fw_cb, sizeof(struct addr_ctrl_blk)));
  380. /* Save some info in adapter structure. */
  381. ha->acb_version = init_fw_cb->acb_version;
  382. ha->firmware_options = le16_to_cpu(init_fw_cb->fw_options);
  383. ha->heartbeat_interval = init_fw_cb->hb_interval;
  384. memcpy(ha->name_string, init_fw_cb->iscsi_name,
  385. min(sizeof(ha->name_string),
  386. sizeof(init_fw_cb->iscsi_name)));
  387. ha->def_timeout = le16_to_cpu(init_fw_cb->def_timeout);
  388. /*memcpy(ha->alias, init_fw_cb->Alias,
  389. min(sizeof(ha->alias), sizeof(init_fw_cb->Alias)));*/
  390. qla4xxx_update_local_ip(ha, init_fw_cb);
  391. return QLA_SUCCESS;
  392. }
  393. /**
  394. * qla4xxx_initialize_fw_cb - initializes firmware control block.
  395. * @ha: Pointer to host adapter structure.
  396. **/
  397. int qla4xxx_initialize_fw_cb(struct scsi_qla_host * ha)
  398. {
  399. struct addr_ctrl_blk *init_fw_cb;
  400. dma_addr_t init_fw_cb_dma;
  401. uint32_t mbox_cmd[MBOX_REG_COUNT];
  402. uint32_t mbox_sts[MBOX_REG_COUNT];
  403. int status = QLA_ERROR;
  404. init_fw_cb = dma_alloc_coherent(&ha->pdev->dev,
  405. sizeof(struct addr_ctrl_blk),
  406. &init_fw_cb_dma, GFP_KERNEL);
  407. if (init_fw_cb == NULL) {
  408. DEBUG2(printk("scsi%ld: %s: Unable to alloc init_cb\n",
  409. ha->host_no, __func__));
  410. goto exit_init_fw_cb_no_free;
  411. }
  412. memset(init_fw_cb, 0, sizeof(struct addr_ctrl_blk));
  413. /* Get Initialize Firmware Control Block. */
  414. memset(&mbox_cmd, 0, sizeof(mbox_cmd));
  415. memset(&mbox_sts, 0, sizeof(mbox_sts));
  416. if (qla4xxx_get_ifcb(ha, &mbox_cmd[0], &mbox_sts[0], init_fw_cb_dma) !=
  417. QLA_SUCCESS) {
  418. dma_free_coherent(&ha->pdev->dev,
  419. sizeof(struct addr_ctrl_blk),
  420. init_fw_cb, init_fw_cb_dma);
  421. goto exit_init_fw_cb;
  422. }
  423. /* Initialize request and response queues. */
  424. qla4xxx_init_rings(ha);
  425. /* Fill in the request and response queue information. */
  426. init_fw_cb->rqq_consumer_idx = cpu_to_le16(ha->request_out);
  427. init_fw_cb->compq_producer_idx = cpu_to_le16(ha->response_in);
  428. init_fw_cb->rqq_len = __constant_cpu_to_le16(REQUEST_QUEUE_DEPTH);
  429. init_fw_cb->compq_len = __constant_cpu_to_le16(RESPONSE_QUEUE_DEPTH);
  430. init_fw_cb->rqq_addr_lo = cpu_to_le32(LSDW(ha->request_dma));
  431. init_fw_cb->rqq_addr_hi = cpu_to_le32(MSDW(ha->request_dma));
  432. init_fw_cb->compq_addr_lo = cpu_to_le32(LSDW(ha->response_dma));
  433. init_fw_cb->compq_addr_hi = cpu_to_le32(MSDW(ha->response_dma));
  434. init_fw_cb->shdwreg_addr_lo = cpu_to_le32(LSDW(ha->shadow_regs_dma));
  435. init_fw_cb->shdwreg_addr_hi = cpu_to_le32(MSDW(ha->shadow_regs_dma));
  436. /* Set up required options. */
  437. init_fw_cb->fw_options |=
  438. __constant_cpu_to_le16(FWOPT_SESSION_MODE |
  439. FWOPT_INITIATOR_MODE);
  440. if (is_qla8022(ha))
  441. init_fw_cb->fw_options |=
  442. __constant_cpu_to_le16(FWOPT_ENABLE_CRBDB);
  443. init_fw_cb->fw_options &= __constant_cpu_to_le16(~FWOPT_TARGET_MODE);
  444. init_fw_cb->add_fw_options = 0;
  445. init_fw_cb->add_fw_options |=
  446. __constant_cpu_to_le16(ADFWOPT_SERIALIZE_TASK_MGMT);
  447. init_fw_cb->add_fw_options |=
  448. __constant_cpu_to_le16(ADFWOPT_AUTOCONN_DISABLE);
  449. if (qla4xxx_set_ifcb(ha, &mbox_cmd[0], &mbox_sts[0], init_fw_cb_dma)
  450. != QLA_SUCCESS) {
  451. DEBUG2(printk(KERN_WARNING
  452. "scsi%ld: %s: Failed to set init_fw_ctrl_blk\n",
  453. ha->host_no, __func__));
  454. goto exit_init_fw_cb;
  455. }
  456. if (qla4xxx_update_local_ifcb(ha, &mbox_cmd[0], &mbox_sts[0],
  457. init_fw_cb, init_fw_cb_dma) != QLA_SUCCESS) {
  458. DEBUG2(printk("scsi%ld: %s: Failed to update local ifcb\n",
  459. ha->host_no, __func__));
  460. goto exit_init_fw_cb;
  461. }
  462. status = QLA_SUCCESS;
  463. exit_init_fw_cb:
  464. dma_free_coherent(&ha->pdev->dev, sizeof(struct addr_ctrl_blk),
  465. init_fw_cb, init_fw_cb_dma);
  466. exit_init_fw_cb_no_free:
  467. return status;
  468. }
  469. /**
  470. * qla4xxx_get_dhcp_ip_address - gets HBA ip address via DHCP
  471. * @ha: Pointer to host adapter structure.
  472. **/
  473. int qla4xxx_get_dhcp_ip_address(struct scsi_qla_host * ha)
  474. {
  475. struct addr_ctrl_blk *init_fw_cb;
  476. dma_addr_t init_fw_cb_dma;
  477. uint32_t mbox_cmd[MBOX_REG_COUNT];
  478. uint32_t mbox_sts[MBOX_REG_COUNT];
  479. init_fw_cb = dma_alloc_coherent(&ha->pdev->dev,
  480. sizeof(struct addr_ctrl_blk),
  481. &init_fw_cb_dma, GFP_KERNEL);
  482. if (init_fw_cb == NULL) {
  483. printk("scsi%ld: %s: Unable to alloc init_cb\n", ha->host_no,
  484. __func__);
  485. return QLA_ERROR;
  486. }
  487. /* Get Initialize Firmware Control Block. */
  488. memset(init_fw_cb, 0, sizeof(struct addr_ctrl_blk));
  489. if (qla4xxx_get_ifcb(ha, &mbox_cmd[0], &mbox_sts[0], init_fw_cb_dma) !=
  490. QLA_SUCCESS) {
  491. DEBUG2(printk("scsi%ld: %s: Failed to get init_fw_ctrl_blk\n",
  492. ha->host_no, __func__));
  493. dma_free_coherent(&ha->pdev->dev,
  494. sizeof(struct addr_ctrl_blk),
  495. init_fw_cb, init_fw_cb_dma);
  496. return QLA_ERROR;
  497. }
  498. /* Save IP Address. */
  499. qla4xxx_update_local_ip(ha, init_fw_cb);
  500. dma_free_coherent(&ha->pdev->dev, sizeof(struct addr_ctrl_blk),
  501. init_fw_cb, init_fw_cb_dma);
  502. return QLA_SUCCESS;
  503. }
  504. /**
  505. * qla4xxx_get_firmware_state - gets firmware state of HBA
  506. * @ha: Pointer to host adapter structure.
  507. **/
  508. int qla4xxx_get_firmware_state(struct scsi_qla_host * ha)
  509. {
  510. uint32_t mbox_cmd[MBOX_REG_COUNT];
  511. uint32_t mbox_sts[MBOX_REG_COUNT];
  512. /* Get firmware version */
  513. memset(&mbox_cmd, 0, sizeof(mbox_cmd));
  514. memset(&mbox_sts, 0, sizeof(mbox_sts));
  515. mbox_cmd[0] = MBOX_CMD_GET_FW_STATE;
  516. if (qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 4, &mbox_cmd[0], &mbox_sts[0]) !=
  517. QLA_SUCCESS) {
  518. DEBUG2(printk("scsi%ld: %s: MBOX_CMD_GET_FW_STATE failed w/ "
  519. "status %04X\n", ha->host_no, __func__,
  520. mbox_sts[0]));
  521. return QLA_ERROR;
  522. }
  523. ha->firmware_state = mbox_sts[1];
  524. ha->board_id = mbox_sts[2];
  525. ha->addl_fw_state = mbox_sts[3];
  526. DEBUG2(printk("scsi%ld: %s firmware_state=0x%x\n",
  527. ha->host_no, __func__, ha->firmware_state);)
  528. return QLA_SUCCESS;
  529. }
  530. /**
  531. * qla4xxx_get_firmware_status - retrieves firmware status
  532. * @ha: Pointer to host adapter structure.
  533. **/
  534. int qla4xxx_get_firmware_status(struct scsi_qla_host * ha)
  535. {
  536. uint32_t mbox_cmd[MBOX_REG_COUNT];
  537. uint32_t mbox_sts[MBOX_REG_COUNT];
  538. /* Get firmware version */
  539. memset(&mbox_cmd, 0, sizeof(mbox_cmd));
  540. memset(&mbox_sts, 0, sizeof(mbox_sts));
  541. mbox_cmd[0] = MBOX_CMD_GET_FW_STATUS;
  542. if (qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 3, &mbox_cmd[0], &mbox_sts[0]) !=
  543. QLA_SUCCESS) {
  544. DEBUG2(printk("scsi%ld: %s: MBOX_CMD_GET_FW_STATUS failed w/ "
  545. "status %04X\n", ha->host_no, __func__,
  546. mbox_sts[0]));
  547. return QLA_ERROR;
  548. }
  549. ql4_printk(KERN_INFO, ha, "%ld firmare IOCBs available (%d).\n",
  550. ha->host_no, mbox_sts[2]);
  551. return QLA_SUCCESS;
  552. }
  553. /**
  554. * qla4xxx_get_fwddb_entry - retrieves firmware ddb entry
  555. * @ha: Pointer to host adapter structure.
  556. * @fw_ddb_index: Firmware's device database index
  557. * @fw_ddb_entry: Pointer to firmware's device database entry structure
  558. * @num_valid_ddb_entries: Pointer to number of valid ddb entries
  559. * @next_ddb_index: Pointer to next valid device database index
  560. * @fw_ddb_device_state: Pointer to device state
  561. **/
  562. int qla4xxx_get_fwddb_entry(struct scsi_qla_host *ha,
  563. uint16_t fw_ddb_index,
  564. struct dev_db_entry *fw_ddb_entry,
  565. dma_addr_t fw_ddb_entry_dma,
  566. uint32_t *num_valid_ddb_entries,
  567. uint32_t *next_ddb_index,
  568. uint32_t *fw_ddb_device_state,
  569. uint32_t *conn_err_detail,
  570. uint16_t *tcp_source_port_num,
  571. uint16_t *connection_id)
  572. {
  573. int status = QLA_ERROR;
  574. uint16_t options;
  575. uint32_t mbox_cmd[MBOX_REG_COUNT];
  576. uint32_t mbox_sts[MBOX_REG_COUNT];
  577. /* Make sure the device index is valid */
  578. if (fw_ddb_index >= MAX_DDB_ENTRIES) {
  579. DEBUG2(printk("scsi%ld: %s: ddb [%d] out of range.\n",
  580. ha->host_no, __func__, fw_ddb_index));
  581. goto exit_get_fwddb;
  582. }
  583. memset(&mbox_cmd, 0, sizeof(mbox_cmd));
  584. memset(&mbox_sts, 0, sizeof(mbox_sts));
  585. 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. static 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. mutex_lock(&ha->chap_sem);
  1254. for (i = 0; i < max_chap_entries; i++) {
  1255. chap_table = (struct ql4_chap_table *)ha->chap_list + i;
  1256. if (chap_table->cookie !=
  1257. __constant_cpu_to_le16(CHAP_VALID_COOKIE)) {
  1258. if (i > MAX_RESRV_CHAP_IDX && free_index == -1)
  1259. free_index = i;
  1260. continue;
  1261. }
  1262. if (bidi) {
  1263. if (chap_table->flags & BIT_7)
  1264. continue;
  1265. } else {
  1266. if (chap_table->flags & BIT_6)
  1267. continue;
  1268. }
  1269. if (!strncmp(chap_table->secret, password,
  1270. MAX_CHAP_SECRET_LEN) &&
  1271. !strncmp(chap_table->name, username,
  1272. MAX_CHAP_NAME_LEN)) {
  1273. *chap_index = i;
  1274. found_index = 1;
  1275. break;
  1276. }
  1277. }
  1278. /* If chap entry is not present and a free index is available then
  1279. * write the entry in flash
  1280. */
  1281. if (!found_index && free_index != -1) {
  1282. rval = qla4xxx_set_chap(ha, username, password,
  1283. free_index, bidi);
  1284. if (!rval) {
  1285. *chap_index = free_index;
  1286. found_index = 1;
  1287. }
  1288. }
  1289. mutex_unlock(&ha->chap_sem);
  1290. if (found_index)
  1291. return QLA_SUCCESS;
  1292. return QLA_ERROR;
  1293. }
  1294. int qla4xxx_conn_close_sess_logout(struct scsi_qla_host *ha,
  1295. uint16_t fw_ddb_index,
  1296. uint16_t connection_id,
  1297. uint16_t option)
  1298. {
  1299. uint32_t mbox_cmd[MBOX_REG_COUNT];
  1300. uint32_t mbox_sts[MBOX_REG_COUNT];
  1301. int status = QLA_SUCCESS;
  1302. memset(&mbox_cmd, 0, sizeof(mbox_cmd));
  1303. memset(&mbox_sts, 0, sizeof(mbox_sts));
  1304. mbox_cmd[0] = MBOX_CMD_CONN_CLOSE_SESS_LOGOUT;
  1305. mbox_cmd[1] = fw_ddb_index;
  1306. mbox_cmd[2] = connection_id;
  1307. mbox_cmd[3] = option;
  1308. status = qla4xxx_mailbox_command(ha, 4, 2, &mbox_cmd[0], &mbox_sts[0]);
  1309. if (status != QLA_SUCCESS) {
  1310. DEBUG2(ql4_printk(KERN_WARNING, ha, "%s: MBOX_CMD_CONN_CLOSE "
  1311. "option %04x failed w/ status %04X %04X\n",
  1312. __func__, option, mbox_sts[0], mbox_sts[1]));
  1313. }
  1314. return status;
  1315. }
  1316. int qla4xxx_disable_acb(struct scsi_qla_host *ha)
  1317. {
  1318. uint32_t mbox_cmd[MBOX_REG_COUNT];
  1319. uint32_t mbox_sts[MBOX_REG_COUNT];
  1320. int status = QLA_SUCCESS;
  1321. memset(&mbox_cmd, 0, sizeof(mbox_cmd));
  1322. memset(&mbox_sts, 0, sizeof(mbox_sts));
  1323. mbox_cmd[0] = MBOX_CMD_DISABLE_ACB;
  1324. status = qla4xxx_mailbox_command(ha, 8, 5, &mbox_cmd[0], &mbox_sts[0]);
  1325. if (status != QLA_SUCCESS) {
  1326. DEBUG2(ql4_printk(KERN_WARNING, ha, "%s: MBOX_CMD_DISABLE_ACB "
  1327. "failed w/ status %04X %04X %04X", __func__,
  1328. mbox_sts[0], mbox_sts[1], mbox_sts[2]));
  1329. }
  1330. return status;
  1331. }
  1332. int qla4xxx_get_acb(struct scsi_qla_host *ha, dma_addr_t acb_dma,
  1333. uint32_t acb_type, uint32_t len)
  1334. {
  1335. uint32_t mbox_cmd[MBOX_REG_COUNT];
  1336. uint32_t mbox_sts[MBOX_REG_COUNT];
  1337. int status = QLA_SUCCESS;
  1338. memset(&mbox_cmd, 0, sizeof(mbox_cmd));
  1339. memset(&mbox_sts, 0, sizeof(mbox_sts));
  1340. mbox_cmd[0] = MBOX_CMD_GET_ACB;
  1341. mbox_cmd[1] = acb_type;
  1342. mbox_cmd[2] = LSDW(acb_dma);
  1343. mbox_cmd[3] = MSDW(acb_dma);
  1344. mbox_cmd[4] = len;
  1345. status = qla4xxx_mailbox_command(ha, 5, 5, &mbox_cmd[0], &mbox_sts[0]);
  1346. if (status != QLA_SUCCESS) {
  1347. DEBUG2(ql4_printk(KERN_WARNING, ha, "%s: MBOX_CMD_GET_ACB "
  1348. "failed w/ status %04X\n", __func__,
  1349. mbox_sts[0]));
  1350. }
  1351. return status;
  1352. }
  1353. int qla4xxx_set_acb(struct scsi_qla_host *ha, uint32_t *mbox_cmd,
  1354. uint32_t *mbox_sts, dma_addr_t acb_dma)
  1355. {
  1356. int status = QLA_SUCCESS;
  1357. memset(mbox_cmd, 0, sizeof(mbox_cmd[0]) * MBOX_REG_COUNT);
  1358. memset(mbox_sts, 0, sizeof(mbox_sts[0]) * MBOX_REG_COUNT);
  1359. mbox_cmd[0] = MBOX_CMD_SET_ACB;
  1360. mbox_cmd[1] = 0; /* Primary ACB */
  1361. mbox_cmd[2] = LSDW(acb_dma);
  1362. mbox_cmd[3] = MSDW(acb_dma);
  1363. mbox_cmd[4] = sizeof(struct addr_ctrl_blk);
  1364. status = qla4xxx_mailbox_command(ha, 5, 5, &mbox_cmd[0], &mbox_sts[0]);
  1365. if (status != QLA_SUCCESS) {
  1366. DEBUG2(ql4_printk(KERN_WARNING, ha, "%s: MBOX_CMD_SET_ACB "
  1367. "failed w/ status %04X\n", __func__,
  1368. mbox_sts[0]));
  1369. }
  1370. return status;
  1371. }
  1372. int qla4xxx_set_param_ddbentry(struct scsi_qla_host *ha,
  1373. struct ddb_entry *ddb_entry,
  1374. struct iscsi_cls_conn *cls_conn,
  1375. uint32_t *mbx_sts)
  1376. {
  1377. struct dev_db_entry *fw_ddb_entry;
  1378. struct iscsi_conn *conn;
  1379. struct iscsi_session *sess;
  1380. struct qla_conn *qla_conn;
  1381. struct sockaddr *dst_addr;
  1382. dma_addr_t fw_ddb_entry_dma;
  1383. int status = QLA_SUCCESS;
  1384. int rval = 0;
  1385. struct sockaddr_in *addr;
  1386. struct sockaddr_in6 *addr6;
  1387. char *ip;
  1388. uint16_t iscsi_opts = 0;
  1389. uint32_t options = 0;
  1390. uint16_t idx;
  1391. fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
  1392. &fw_ddb_entry_dma, GFP_KERNEL);
  1393. if (!fw_ddb_entry) {
  1394. DEBUG2(ql4_printk(KERN_ERR, ha,
  1395. "%s: Unable to allocate dma buffer.\n",
  1396. __func__));
  1397. rval = -ENOMEM;
  1398. goto exit_set_param_no_free;
  1399. }
  1400. conn = cls_conn->dd_data;
  1401. qla_conn = conn->dd_data;
  1402. sess = conn->session;
  1403. dst_addr = &qla_conn->qla_ep->dst_addr;
  1404. if (dst_addr->sa_family == AF_INET6)
  1405. options |= IPV6_DEFAULT_DDB_ENTRY;
  1406. status = qla4xxx_get_default_ddb(ha, options, fw_ddb_entry_dma);
  1407. if (status == QLA_ERROR) {
  1408. rval = -EINVAL;
  1409. goto exit_set_param;
  1410. }
  1411. iscsi_opts = le16_to_cpu(fw_ddb_entry->iscsi_options);
  1412. memset(fw_ddb_entry->iscsi_alias, 0, sizeof(fw_ddb_entry->iscsi_alias));
  1413. memset(fw_ddb_entry->iscsi_name, 0, sizeof(fw_ddb_entry->iscsi_name));
  1414. if (sess->targetname != NULL) {
  1415. memcpy(fw_ddb_entry->iscsi_name, sess->targetname,
  1416. min(strlen(sess->targetname),
  1417. sizeof(fw_ddb_entry->iscsi_name)));
  1418. }
  1419. memset(fw_ddb_entry->ip_addr, 0, sizeof(fw_ddb_entry->ip_addr));
  1420. memset(fw_ddb_entry->tgt_addr, 0, sizeof(fw_ddb_entry->tgt_addr));
  1421. fw_ddb_entry->options = DDB_OPT_TARGET | DDB_OPT_AUTO_SENDTGTS_DISABLE;
  1422. if (dst_addr->sa_family == AF_INET) {
  1423. addr = (struct sockaddr_in *)dst_addr;
  1424. ip = (char *)&addr->sin_addr;
  1425. memcpy(fw_ddb_entry->ip_addr, ip, IP_ADDR_LEN);
  1426. fw_ddb_entry->port = cpu_to_le16(ntohs(addr->sin_port));
  1427. DEBUG2(ql4_printk(KERN_INFO, ha,
  1428. "%s: Destination Address [%pI4]: index [%d]\n",
  1429. __func__, fw_ddb_entry->ip_addr,
  1430. ddb_entry->fw_ddb_index));
  1431. } else if (dst_addr->sa_family == AF_INET6) {
  1432. addr6 = (struct sockaddr_in6 *)dst_addr;
  1433. ip = (char *)&addr6->sin6_addr;
  1434. memcpy(fw_ddb_entry->ip_addr, ip, IPv6_ADDR_LEN);
  1435. fw_ddb_entry->port = cpu_to_le16(ntohs(addr6->sin6_port));
  1436. fw_ddb_entry->options |= DDB_OPT_IPV6_DEVICE;
  1437. DEBUG2(ql4_printk(KERN_INFO, ha,
  1438. "%s: Destination Address [%pI6]: index [%d]\n",
  1439. __func__, fw_ddb_entry->ip_addr,
  1440. ddb_entry->fw_ddb_index));
  1441. } else {
  1442. ql4_printk(KERN_ERR, ha,
  1443. "%s: Failed to get IP Address\n",
  1444. __func__);
  1445. rval = -EINVAL;
  1446. goto exit_set_param;
  1447. }
  1448. /* CHAP */
  1449. if (sess->username != NULL && sess->password != NULL) {
  1450. if (strlen(sess->username) && strlen(sess->password)) {
  1451. iscsi_opts |= BIT_7;
  1452. rval = qla4xxx_get_chap_index(ha, sess->username,
  1453. sess->password,
  1454. LOCAL_CHAP, &idx);
  1455. if (rval)
  1456. goto exit_set_param;
  1457. fw_ddb_entry->chap_tbl_idx = cpu_to_le16(idx);
  1458. }
  1459. }
  1460. if (sess->username_in != NULL && sess->password_in != NULL) {
  1461. /* Check if BIDI CHAP */
  1462. if (strlen(sess->username_in) && strlen(sess->password_in)) {
  1463. iscsi_opts |= BIT_4;
  1464. rval = qla4xxx_get_chap_index(ha, sess->username_in,
  1465. sess->password_in,
  1466. BIDI_CHAP, &idx);
  1467. if (rval)
  1468. goto exit_set_param;
  1469. }
  1470. }
  1471. if (sess->initial_r2t_en)
  1472. iscsi_opts |= BIT_10;
  1473. if (sess->imm_data_en)
  1474. iscsi_opts |= BIT_11;
  1475. fw_ddb_entry->iscsi_options = cpu_to_le16(iscsi_opts);
  1476. if (conn->max_recv_dlength)
  1477. fw_ddb_entry->iscsi_max_rcv_data_seg_len =
  1478. __constant_cpu_to_le16((conn->max_recv_dlength / BYTE_UNITS));
  1479. if (sess->max_r2t)
  1480. fw_ddb_entry->iscsi_max_outsnd_r2t = cpu_to_le16(sess->max_r2t);
  1481. if (sess->first_burst)
  1482. fw_ddb_entry->iscsi_first_burst_len =
  1483. __constant_cpu_to_le16((sess->first_burst / BYTE_UNITS));
  1484. if (sess->max_burst)
  1485. fw_ddb_entry->iscsi_max_burst_len =
  1486. __constant_cpu_to_le16((sess->max_burst / BYTE_UNITS));
  1487. if (sess->time2wait)
  1488. fw_ddb_entry->iscsi_def_time2wait =
  1489. cpu_to_le16(sess->time2wait);
  1490. if (sess->time2retain)
  1491. fw_ddb_entry->iscsi_def_time2retain =
  1492. cpu_to_le16(sess->time2retain);
  1493. status = qla4xxx_set_ddb_entry(ha, ddb_entry->fw_ddb_index,
  1494. fw_ddb_entry_dma, mbx_sts);
  1495. if (status != QLA_SUCCESS)
  1496. rval = -EINVAL;
  1497. exit_set_param:
  1498. dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
  1499. fw_ddb_entry, fw_ddb_entry_dma);
  1500. exit_set_param_no_free:
  1501. return rval;
  1502. }
  1503. int qla4xxx_get_mgmt_data(struct scsi_qla_host *ha, uint16_t fw_ddb_index,
  1504. uint16_t stats_size, dma_addr_t stats_dma)
  1505. {
  1506. int status = QLA_SUCCESS;
  1507. uint32_t mbox_cmd[MBOX_REG_COUNT];
  1508. uint32_t mbox_sts[MBOX_REG_COUNT];
  1509. memset(mbox_cmd, 0, sizeof(mbox_cmd[0]) * MBOX_REG_COUNT);
  1510. memset(mbox_sts, 0, sizeof(mbox_sts[0]) * MBOX_REG_COUNT);
  1511. mbox_cmd[0] = MBOX_CMD_GET_MANAGEMENT_DATA;
  1512. mbox_cmd[1] = fw_ddb_index;
  1513. mbox_cmd[2] = LSDW(stats_dma);
  1514. mbox_cmd[3] = MSDW(stats_dma);
  1515. mbox_cmd[4] = stats_size;
  1516. status = qla4xxx_mailbox_command(ha, 5, 1, &mbox_cmd[0], &mbox_sts[0]);
  1517. if (status != QLA_SUCCESS) {
  1518. DEBUG2(ql4_printk(KERN_WARNING, ha,
  1519. "%s: MBOX_CMD_GET_MANAGEMENT_DATA "
  1520. "failed w/ status %04X\n", __func__,
  1521. mbox_sts[0]));
  1522. }
  1523. return status;
  1524. }
  1525. int qla4xxx_get_ip_state(struct scsi_qla_host *ha, uint32_t acb_idx,
  1526. uint32_t ip_idx, uint32_t *sts)
  1527. {
  1528. uint32_t mbox_cmd[MBOX_REG_COUNT];
  1529. uint32_t mbox_sts[MBOX_REG_COUNT];
  1530. int status = QLA_SUCCESS;
  1531. memset(&mbox_cmd, 0, sizeof(mbox_cmd));
  1532. memset(&mbox_sts, 0, sizeof(mbox_sts));
  1533. mbox_cmd[0] = MBOX_CMD_GET_IP_ADDR_STATE;
  1534. mbox_cmd[1] = acb_idx;
  1535. mbox_cmd[2] = ip_idx;
  1536. status = qla4xxx_mailbox_command(ha, 3, 8, &mbox_cmd[0], &mbox_sts[0]);
  1537. if (status != QLA_SUCCESS) {
  1538. DEBUG2(ql4_printk(KERN_WARNING, ha, "%s: "
  1539. "MBOX_CMD_GET_IP_ADDR_STATE failed w/ "
  1540. "status %04X\n", __func__, mbox_sts[0]));
  1541. }
  1542. memcpy(sts, mbox_sts, sizeof(mbox_sts));
  1543. return status;
  1544. }
  1545. int qla4xxx_get_nvram(struct scsi_qla_host *ha, dma_addr_t nvram_dma,
  1546. uint32_t offset, uint32_t size)
  1547. {
  1548. int status = QLA_SUCCESS;
  1549. uint32_t mbox_cmd[MBOX_REG_COUNT];
  1550. uint32_t mbox_sts[MBOX_REG_COUNT];
  1551. memset(&mbox_cmd, 0, sizeof(mbox_cmd));
  1552. memset(&mbox_sts, 0, sizeof(mbox_sts));
  1553. mbox_cmd[0] = MBOX_CMD_GET_NVRAM;
  1554. mbox_cmd[1] = LSDW(nvram_dma);
  1555. mbox_cmd[2] = MSDW(nvram_dma);
  1556. mbox_cmd[3] = offset;
  1557. mbox_cmd[4] = size;
  1558. status = qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 1, &mbox_cmd[0],
  1559. &mbox_sts[0]);
  1560. if (status != QLA_SUCCESS) {
  1561. DEBUG2(ql4_printk(KERN_ERR, ha, "scsi%ld: %s: failed "
  1562. "status %04X\n", ha->host_no, __func__,
  1563. mbox_sts[0]));
  1564. }
  1565. return status;
  1566. }
  1567. int qla4xxx_set_nvram(struct scsi_qla_host *ha, dma_addr_t nvram_dma,
  1568. uint32_t offset, uint32_t size)
  1569. {
  1570. int status = QLA_SUCCESS;
  1571. uint32_t mbox_cmd[MBOX_REG_COUNT];
  1572. uint32_t mbox_sts[MBOX_REG_COUNT];
  1573. memset(&mbox_cmd, 0, sizeof(mbox_cmd));
  1574. memset(&mbox_sts, 0, sizeof(mbox_sts));
  1575. mbox_cmd[0] = MBOX_CMD_SET_NVRAM;
  1576. mbox_cmd[1] = LSDW(nvram_dma);
  1577. mbox_cmd[2] = MSDW(nvram_dma);
  1578. mbox_cmd[3] = offset;
  1579. mbox_cmd[4] = size;
  1580. status = qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 1, &mbox_cmd[0],
  1581. &mbox_sts[0]);
  1582. if (status != QLA_SUCCESS) {
  1583. DEBUG2(ql4_printk(KERN_ERR, ha, "scsi%ld: %s: failed "
  1584. "status %04X\n", ha->host_no, __func__,
  1585. mbox_sts[0]));
  1586. }
  1587. return status;
  1588. }
  1589. int qla4xxx_restore_factory_defaults(struct scsi_qla_host *ha,
  1590. uint32_t region, uint32_t field0,
  1591. uint32_t field1)
  1592. {
  1593. int status = QLA_SUCCESS;
  1594. uint32_t mbox_cmd[MBOX_REG_COUNT];
  1595. uint32_t mbox_sts[MBOX_REG_COUNT];
  1596. memset(&mbox_cmd, 0, sizeof(mbox_cmd));
  1597. memset(&mbox_sts, 0, sizeof(mbox_sts));
  1598. mbox_cmd[0] = MBOX_CMD_RESTORE_FACTORY_DEFAULTS;
  1599. mbox_cmd[3] = region;
  1600. mbox_cmd[4] = field0;
  1601. mbox_cmd[5] = field1;
  1602. status = qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 3, &mbox_cmd[0],
  1603. &mbox_sts[0]);
  1604. if (status != QLA_SUCCESS) {
  1605. DEBUG2(ql4_printk(KERN_ERR, ha, "scsi%ld: %s: failed "
  1606. "status %04X\n", ha->host_no, __func__,
  1607. mbox_sts[0]));
  1608. }
  1609. return status;
  1610. }