ql4_mbx.c 52 KB

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