ql4_init.c 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131
  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 <scsi/iscsi_if.h>
  8. #include "ql4_def.h"
  9. #include "ql4_glbl.h"
  10. #include "ql4_dbg.h"
  11. #include "ql4_inline.h"
  12. static void ql4xxx_set_mac_number(struct scsi_qla_host *ha)
  13. {
  14. uint32_t value;
  15. uint8_t func_number;
  16. unsigned long flags;
  17. /* Get the function number */
  18. spin_lock_irqsave(&ha->hardware_lock, flags);
  19. value = readw(&ha->reg->ctrl_status);
  20. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  21. func_number = (uint8_t) ((value >> 4) & 0x30);
  22. switch (value & ISP_CONTROL_FN_MASK) {
  23. case ISP_CONTROL_FN0_SCSI:
  24. ha->mac_index = 1;
  25. break;
  26. case ISP_CONTROL_FN1_SCSI:
  27. ha->mac_index = 3;
  28. break;
  29. default:
  30. DEBUG2(printk("scsi%ld: %s: Invalid function number, "
  31. "ispControlStatus = 0x%x\n", ha->host_no,
  32. __func__, value));
  33. break;
  34. }
  35. DEBUG2(printk("scsi%ld: %s: mac_index %d.\n", ha->host_no, __func__,
  36. ha->mac_index));
  37. }
  38. /**
  39. * qla4xxx_free_ddb - deallocate ddb
  40. * @ha: pointer to host adapter structure.
  41. * @ddb_entry: pointer to device database entry
  42. *
  43. * This routine marks a DDB entry INVALID
  44. **/
  45. void qla4xxx_free_ddb(struct scsi_qla_host *ha,
  46. struct ddb_entry *ddb_entry)
  47. {
  48. /* Remove device pointer from index mapping arrays */
  49. ha->fw_ddb_index_map[ddb_entry->fw_ddb_index] =
  50. (struct ddb_entry *) INVALID_ENTRY;
  51. ha->tot_ddbs--;
  52. }
  53. /**
  54. * qla4xxx_init_response_q_entries() - Initializes response queue entries.
  55. * @ha: HA context
  56. *
  57. * Beginning of request ring has initialization control block already built
  58. * by nvram config routine.
  59. **/
  60. static void qla4xxx_init_response_q_entries(struct scsi_qla_host *ha)
  61. {
  62. uint16_t cnt;
  63. struct response *pkt;
  64. pkt = (struct response *)ha->response_ptr;
  65. for (cnt = 0; cnt < RESPONSE_QUEUE_DEPTH; cnt++) {
  66. pkt->signature = RESPONSE_PROCESSED;
  67. pkt++;
  68. }
  69. }
  70. /**
  71. * qla4xxx_init_rings - initialize hw queues
  72. * @ha: pointer to host adapter structure.
  73. *
  74. * This routine initializes the internal queues for the specified adapter.
  75. * The QLA4010 requires us to restart the queues at index 0.
  76. * The QLA4000 doesn't care, so just default to QLA4010's requirement.
  77. **/
  78. int qla4xxx_init_rings(struct scsi_qla_host *ha)
  79. {
  80. unsigned long flags = 0;
  81. int i;
  82. /* Initialize request queue. */
  83. spin_lock_irqsave(&ha->hardware_lock, flags);
  84. ha->request_out = 0;
  85. ha->request_in = 0;
  86. ha->request_ptr = &ha->request_ring[ha->request_in];
  87. ha->req_q_count = REQUEST_QUEUE_DEPTH;
  88. /* Initialize response queue. */
  89. ha->response_in = 0;
  90. ha->response_out = 0;
  91. ha->response_ptr = &ha->response_ring[ha->response_out];
  92. if (is_qla8022(ha)) {
  93. writel(0,
  94. (unsigned long __iomem *)&ha->qla4_8xxx_reg->req_q_out);
  95. writel(0,
  96. (unsigned long __iomem *)&ha->qla4_8xxx_reg->rsp_q_in);
  97. writel(0,
  98. (unsigned long __iomem *)&ha->qla4_8xxx_reg->rsp_q_out);
  99. } else {
  100. /*
  101. * Initialize DMA Shadow registers. The firmware is really
  102. * supposed to take care of this, but on some uniprocessor
  103. * systems, the shadow registers aren't cleared-- causing
  104. * the interrupt_handler to think there are responses to be
  105. * processed when there aren't.
  106. */
  107. ha->shadow_regs->req_q_out = __constant_cpu_to_le32(0);
  108. ha->shadow_regs->rsp_q_in = __constant_cpu_to_le32(0);
  109. wmb();
  110. writel(0, &ha->reg->req_q_in);
  111. writel(0, &ha->reg->rsp_q_out);
  112. readl(&ha->reg->rsp_q_out);
  113. }
  114. qla4xxx_init_response_q_entries(ha);
  115. /* Initialize mabilbox active array */
  116. for (i = 0; i < MAX_MRB; i++)
  117. ha->active_mrb_array[i] = NULL;
  118. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  119. return QLA_SUCCESS;
  120. }
  121. /**
  122. * qla4xxx_get_sys_info - validate adapter MAC address(es)
  123. * @ha: pointer to host adapter structure.
  124. *
  125. **/
  126. int qla4xxx_get_sys_info(struct scsi_qla_host *ha)
  127. {
  128. struct flash_sys_info *sys_info;
  129. dma_addr_t sys_info_dma;
  130. int status = QLA_ERROR;
  131. sys_info = dma_alloc_coherent(&ha->pdev->dev, sizeof(*sys_info),
  132. &sys_info_dma, GFP_KERNEL);
  133. if (sys_info == NULL) {
  134. DEBUG2(printk("scsi%ld: %s: Unable to allocate dma buffer.\n",
  135. ha->host_no, __func__));
  136. goto exit_get_sys_info_no_free;
  137. }
  138. memset(sys_info, 0, sizeof(*sys_info));
  139. /* Get flash sys info */
  140. if (qla4xxx_get_flash(ha, sys_info_dma, FLASH_OFFSET_SYS_INFO,
  141. sizeof(*sys_info)) != QLA_SUCCESS) {
  142. DEBUG2(printk("scsi%ld: %s: get_flash FLASH_OFFSET_SYS_INFO "
  143. "failed\n", ha->host_no, __func__));
  144. goto exit_get_sys_info;
  145. }
  146. /* Save M.A.C. address & serial_number */
  147. memcpy(ha->my_mac, &sys_info->physAddr[0].address[0],
  148. min(sizeof(ha->my_mac),
  149. sizeof(sys_info->physAddr[0].address)));
  150. memcpy(ha->serial_number, &sys_info->acSerialNumber,
  151. min(sizeof(ha->serial_number),
  152. sizeof(sys_info->acSerialNumber)));
  153. status = QLA_SUCCESS;
  154. exit_get_sys_info:
  155. dma_free_coherent(&ha->pdev->dev, sizeof(*sys_info), sys_info,
  156. sys_info_dma);
  157. exit_get_sys_info_no_free:
  158. return status;
  159. }
  160. /**
  161. * qla4xxx_init_local_data - initialize adapter specific local data
  162. * @ha: pointer to host adapter structure.
  163. *
  164. **/
  165. static int qla4xxx_init_local_data(struct scsi_qla_host *ha)
  166. {
  167. /* Initialize aen queue */
  168. ha->aen_q_count = MAX_AEN_ENTRIES;
  169. return qla4xxx_get_firmware_status(ha);
  170. }
  171. static uint8_t
  172. qla4xxx_wait_for_ip_config(struct scsi_qla_host *ha)
  173. {
  174. uint8_t ipv4_wait = 0;
  175. uint8_t ipv6_wait = 0;
  176. int8_t ip_address[IPv6_ADDR_LEN] = {0} ;
  177. /* If both IPv4 & IPv6 are enabled, possibly only one
  178. * IP address may be acquired, so check to see if we
  179. * need to wait for another */
  180. if (is_ipv4_enabled(ha) && is_ipv6_enabled(ha)) {
  181. if (((ha->addl_fw_state & FW_ADDSTATE_DHCPv4_ENABLED) != 0) &&
  182. ((ha->addl_fw_state &
  183. FW_ADDSTATE_DHCPv4_LEASE_ACQUIRED) == 0)) {
  184. ipv4_wait = 1;
  185. }
  186. if (((ha->ip_config.ipv6_addl_options &
  187. IPV6_ADDOPT_NEIGHBOR_DISCOVERY_ADDR_ENABLE) != 0) &&
  188. ((ha->ip_config.ipv6_link_local_state ==
  189. IP_ADDRSTATE_ACQUIRING) ||
  190. (ha->ip_config.ipv6_addr0_state ==
  191. IP_ADDRSTATE_ACQUIRING) ||
  192. (ha->ip_config.ipv6_addr1_state ==
  193. IP_ADDRSTATE_ACQUIRING))) {
  194. ipv6_wait = 1;
  195. if ((ha->ip_config.ipv6_link_local_state ==
  196. IP_ADDRSTATE_PREFERRED) ||
  197. (ha->ip_config.ipv6_addr0_state ==
  198. IP_ADDRSTATE_PREFERRED) ||
  199. (ha->ip_config.ipv6_addr1_state ==
  200. IP_ADDRSTATE_PREFERRED)) {
  201. DEBUG2(printk(KERN_INFO "scsi%ld: %s: "
  202. "Preferred IP configured."
  203. " Don't wait!\n", ha->host_no,
  204. __func__));
  205. ipv6_wait = 0;
  206. }
  207. if (memcmp(&ha->ip_config.ipv6_default_router_addr,
  208. ip_address, IPv6_ADDR_LEN) == 0) {
  209. DEBUG2(printk(KERN_INFO "scsi%ld: %s: "
  210. "No Router configured. "
  211. "Don't wait!\n", ha->host_no,
  212. __func__));
  213. ipv6_wait = 0;
  214. }
  215. if ((ha->ip_config.ipv6_default_router_state ==
  216. IPV6_RTRSTATE_MANUAL) &&
  217. (ha->ip_config.ipv6_link_local_state ==
  218. IP_ADDRSTATE_TENTATIVE) &&
  219. (memcmp(&ha->ip_config.ipv6_link_local_addr,
  220. &ha->ip_config.ipv6_default_router_addr, 4) ==
  221. 0)) {
  222. DEBUG2(printk("scsi%ld: %s: LinkLocal Router & "
  223. "IP configured. Don't wait!\n",
  224. ha->host_no, __func__));
  225. ipv6_wait = 0;
  226. }
  227. }
  228. if (ipv4_wait || ipv6_wait) {
  229. DEBUG2(printk("scsi%ld: %s: Wait for additional "
  230. "IP(s) \"", ha->host_no, __func__));
  231. if (ipv4_wait)
  232. DEBUG2(printk("IPv4 "));
  233. if (ha->ip_config.ipv6_link_local_state ==
  234. IP_ADDRSTATE_ACQUIRING)
  235. DEBUG2(printk("IPv6LinkLocal "));
  236. if (ha->ip_config.ipv6_addr0_state ==
  237. IP_ADDRSTATE_ACQUIRING)
  238. DEBUG2(printk("IPv6Addr0 "));
  239. if (ha->ip_config.ipv6_addr1_state ==
  240. IP_ADDRSTATE_ACQUIRING)
  241. DEBUG2(printk("IPv6Addr1 "));
  242. DEBUG2(printk("\"\n"));
  243. }
  244. }
  245. return ipv4_wait|ipv6_wait;
  246. }
  247. static int qla4xxx_fw_ready(struct scsi_qla_host *ha)
  248. {
  249. uint32_t timeout_count;
  250. int ready = 0;
  251. DEBUG2(ql4_printk(KERN_INFO, ha, "Waiting for Firmware Ready..\n"));
  252. for (timeout_count = ADAPTER_INIT_TOV; timeout_count > 0;
  253. timeout_count--) {
  254. if (test_and_clear_bit(DPC_GET_DHCP_IP_ADDR, &ha->dpc_flags))
  255. qla4xxx_get_dhcp_ip_address(ha);
  256. /* Get firmware state. */
  257. if (qla4xxx_get_firmware_state(ha) != QLA_SUCCESS) {
  258. DEBUG2(printk("scsi%ld: %s: unable to get firmware "
  259. "state\n", ha->host_no, __func__));
  260. break;
  261. }
  262. if (ha->firmware_state & FW_STATE_ERROR) {
  263. DEBUG2(printk("scsi%ld: %s: an unrecoverable error has"
  264. " occurred\n", ha->host_no, __func__));
  265. break;
  266. }
  267. if (ha->firmware_state & FW_STATE_CONFIG_WAIT) {
  268. /*
  269. * The firmware has not yet been issued an Initialize
  270. * Firmware command, so issue it now.
  271. */
  272. if (qla4xxx_initialize_fw_cb(ha) == QLA_ERROR)
  273. break;
  274. /* Go back and test for ready state - no wait. */
  275. continue;
  276. }
  277. if (ha->firmware_state & FW_STATE_WAIT_AUTOCONNECT) {
  278. DEBUG2(printk(KERN_INFO "scsi%ld: %s: fwstate:"
  279. "AUTOCONNECT in progress\n",
  280. ha->host_no, __func__));
  281. }
  282. if (ha->firmware_state & FW_STATE_CONFIGURING_IP) {
  283. DEBUG2(printk(KERN_INFO "scsi%ld: %s: fwstate:"
  284. " CONFIGURING IP\n",
  285. ha->host_no, __func__));
  286. /*
  287. * Check for link state after 15 secs and if link is
  288. * still DOWN then, cable is unplugged. Ignore "DHCP
  289. * in Progress/CONFIGURING IP" bit to check if firmware
  290. * is in ready state or not after 15 secs.
  291. * This is applicable for both 2.x & 3.x firmware
  292. */
  293. if (timeout_count <= (ADAPTER_INIT_TOV - 15)) {
  294. if (ha->addl_fw_state & FW_ADDSTATE_LINK_UP) {
  295. DEBUG2(printk(KERN_INFO "scsi%ld: %s:"
  296. " LINK UP (Cable plugged)\n",
  297. ha->host_no, __func__));
  298. } else if (ha->firmware_state &
  299. (FW_STATE_CONFIGURING_IP |
  300. FW_STATE_READY)) {
  301. DEBUG2(printk(KERN_INFO "scsi%ld: %s: "
  302. "LINK DOWN (Cable unplugged)\n",
  303. ha->host_no, __func__));
  304. ha->firmware_state = FW_STATE_READY;
  305. }
  306. }
  307. }
  308. if (ha->firmware_state == FW_STATE_READY) {
  309. /* If DHCP IP Addr is available, retrieve it now. */
  310. if (test_and_clear_bit(DPC_GET_DHCP_IP_ADDR,
  311. &ha->dpc_flags))
  312. qla4xxx_get_dhcp_ip_address(ha);
  313. if (!qla4xxx_wait_for_ip_config(ha) ||
  314. timeout_count == 1) {
  315. DEBUG2(ql4_printk(KERN_INFO, ha,
  316. "Firmware Ready..\n"));
  317. /* The firmware is ready to process SCSI
  318. commands. */
  319. DEBUG2(ql4_printk(KERN_INFO, ha,
  320. "scsi%ld: %s: MEDIA TYPE"
  321. " - %s\n", ha->host_no,
  322. __func__, (ha->addl_fw_state &
  323. FW_ADDSTATE_OPTICAL_MEDIA)
  324. != 0 ? "OPTICAL" : "COPPER"));
  325. DEBUG2(ql4_printk(KERN_INFO, ha,
  326. "scsi%ld: %s: DHCPv4 STATE"
  327. " Enabled %s\n", ha->host_no,
  328. __func__, (ha->addl_fw_state &
  329. FW_ADDSTATE_DHCPv4_ENABLED) != 0 ?
  330. "YES" : "NO"));
  331. DEBUG2(ql4_printk(KERN_INFO, ha,
  332. "scsi%ld: %s: LINK %s\n",
  333. ha->host_no, __func__,
  334. (ha->addl_fw_state &
  335. FW_ADDSTATE_LINK_UP) != 0 ?
  336. "UP" : "DOWN"));
  337. DEBUG2(ql4_printk(KERN_INFO, ha,
  338. "scsi%ld: %s: iSNS Service "
  339. "Started %s\n",
  340. ha->host_no, __func__,
  341. (ha->addl_fw_state &
  342. FW_ADDSTATE_ISNS_SVC_ENABLED) != 0 ?
  343. "YES" : "NO"));
  344. ready = 1;
  345. break;
  346. }
  347. }
  348. DEBUG2(printk("scsi%ld: %s: waiting on fw, state=%x:%x - "
  349. "seconds expired= %d\n", ha->host_no, __func__,
  350. ha->firmware_state, ha->addl_fw_state,
  351. timeout_count));
  352. if (is_qla4032(ha) &&
  353. !(ha->addl_fw_state & FW_ADDSTATE_LINK_UP) &&
  354. (timeout_count < ADAPTER_INIT_TOV - 5)) {
  355. break;
  356. }
  357. msleep(1000);
  358. } /* end of for */
  359. if (timeout_count <= 0)
  360. DEBUG2(printk("scsi%ld: %s: FW Initialization timed out!\n",
  361. ha->host_no, __func__));
  362. if (ha->firmware_state & FW_STATE_CONFIGURING_IP) {
  363. DEBUG2(printk("scsi%ld: %s: FW initialized, but is reporting "
  364. "it's waiting to configure an IP address\n",
  365. ha->host_no, __func__));
  366. ready = 1;
  367. } else if (ha->firmware_state & FW_STATE_WAIT_AUTOCONNECT) {
  368. DEBUG2(printk("scsi%ld: %s: FW initialized, but "
  369. "auto-discovery still in process\n",
  370. ha->host_no, __func__));
  371. ready = 1;
  372. }
  373. return ready;
  374. }
  375. /**
  376. * qla4xxx_init_firmware - initializes the firmware.
  377. * @ha: pointer to host adapter structure.
  378. *
  379. **/
  380. static int qla4xxx_init_firmware(struct scsi_qla_host *ha)
  381. {
  382. int status = QLA_ERROR;
  383. if (is_aer_supported(ha) &&
  384. test_bit(AF_PCI_CHANNEL_IO_PERM_FAILURE, &ha->flags))
  385. return status;
  386. /* For 82xx, stop firmware before initializing because if BIOS
  387. * has previously initialized firmware, then driver's initialize
  388. * firmware will fail. */
  389. if (is_qla8022(ha))
  390. qla4_8xxx_stop_firmware(ha);
  391. ql4_printk(KERN_INFO, ha, "Initializing firmware..\n");
  392. if (qla4xxx_initialize_fw_cb(ha) == QLA_ERROR) {
  393. DEBUG2(printk("scsi%ld: %s: Failed to initialize firmware "
  394. "control block\n", ha->host_no, __func__));
  395. return status;
  396. }
  397. if (!qla4xxx_fw_ready(ha))
  398. return status;
  399. return qla4xxx_get_firmware_status(ha);
  400. }
  401. static void qla4xxx_set_model_info(struct scsi_qla_host *ha)
  402. {
  403. uint16_t board_id_string[8];
  404. int i;
  405. int size = sizeof(ha->nvram->isp4022.boardIdStr);
  406. int offset = offsetof(struct eeprom_data, isp4022.boardIdStr) / 2;
  407. for (i = 0; i < (size / 2) ; i++) {
  408. board_id_string[i] = rd_nvram_word(ha, offset);
  409. offset += 1;
  410. }
  411. memcpy(ha->model_name, board_id_string, size);
  412. }
  413. static int qla4xxx_config_nvram(struct scsi_qla_host *ha)
  414. {
  415. unsigned long flags;
  416. union external_hw_config_reg extHwConfig;
  417. DEBUG2(printk("scsi%ld: %s: Get EEProm parameters \n", ha->host_no,
  418. __func__));
  419. if (ql4xxx_lock_flash(ha) != QLA_SUCCESS)
  420. return QLA_ERROR;
  421. if (ql4xxx_lock_nvram(ha) != QLA_SUCCESS) {
  422. ql4xxx_unlock_flash(ha);
  423. return QLA_ERROR;
  424. }
  425. /* Get EEPRom Parameters from NVRAM and validate */
  426. ql4_printk(KERN_INFO, ha, "Configuring NVRAM ...\n");
  427. if (qla4xxx_is_nvram_configuration_valid(ha) == QLA_SUCCESS) {
  428. spin_lock_irqsave(&ha->hardware_lock, flags);
  429. extHwConfig.Asuint32_t =
  430. rd_nvram_word(ha, eeprom_ext_hw_conf_offset(ha));
  431. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  432. } else {
  433. ql4_printk(KERN_WARNING, ha,
  434. "scsi%ld: %s: EEProm checksum invalid. "
  435. "Please update your EEPROM\n", ha->host_no,
  436. __func__);
  437. /* Attempt to set defaults */
  438. if (is_qla4010(ha))
  439. extHwConfig.Asuint32_t = 0x1912;
  440. else if (is_qla4022(ha) | is_qla4032(ha))
  441. extHwConfig.Asuint32_t = 0x0023;
  442. else
  443. return QLA_ERROR;
  444. }
  445. if (is_qla4022(ha) || is_qla4032(ha))
  446. qla4xxx_set_model_info(ha);
  447. else
  448. strcpy(ha->model_name, "QLA4010");
  449. DEBUG(printk("scsi%ld: %s: Setting extHwConfig to 0xFFFF%04x\n",
  450. ha->host_no, __func__, extHwConfig.Asuint32_t));
  451. spin_lock_irqsave(&ha->hardware_lock, flags);
  452. writel((0xFFFF << 16) | extHwConfig.Asuint32_t, isp_ext_hw_conf(ha));
  453. readl(isp_ext_hw_conf(ha));
  454. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  455. ql4xxx_unlock_nvram(ha);
  456. ql4xxx_unlock_flash(ha);
  457. return QLA_SUCCESS;
  458. }
  459. /**
  460. * qla4_8xxx_pci_config() - Setup ISP82xx PCI configuration registers.
  461. * @ha: HA context
  462. */
  463. void qla4_8xxx_pci_config(struct scsi_qla_host *ha)
  464. {
  465. pci_set_master(ha->pdev);
  466. }
  467. void qla4xxx_pci_config(struct scsi_qla_host *ha)
  468. {
  469. uint16_t w;
  470. int status;
  471. ql4_printk(KERN_INFO, ha, "Configuring PCI space...\n");
  472. pci_set_master(ha->pdev);
  473. status = pci_set_mwi(ha->pdev);
  474. /*
  475. * We want to respect framework's setting of PCI configuration space
  476. * command register and also want to make sure that all bits of
  477. * interest to us are properly set in command register.
  478. */
  479. pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
  480. w |= PCI_COMMAND_PARITY | PCI_COMMAND_SERR;
  481. w &= ~PCI_COMMAND_INTX_DISABLE;
  482. pci_write_config_word(ha->pdev, PCI_COMMAND, w);
  483. }
  484. static int qla4xxx_start_firmware_from_flash(struct scsi_qla_host *ha)
  485. {
  486. int status = QLA_ERROR;
  487. unsigned long max_wait_time;
  488. unsigned long flags;
  489. uint32_t mbox_status;
  490. ql4_printk(KERN_INFO, ha, "Starting firmware ...\n");
  491. /*
  492. * Start firmware from flash ROM
  493. *
  494. * WORKAROUND: Stuff a non-constant value that the firmware can
  495. * use as a seed for a random number generator in MB7 prior to
  496. * setting BOOT_ENABLE. Fixes problem where the TCP
  497. * connections use the same TCP ports after each reboot,
  498. * causing some connections to not get re-established.
  499. */
  500. DEBUG(printk("scsi%d: %s: Start firmware from flash ROM\n",
  501. ha->host_no, __func__));
  502. spin_lock_irqsave(&ha->hardware_lock, flags);
  503. writel(jiffies, &ha->reg->mailbox[7]);
  504. if (is_qla4022(ha) | is_qla4032(ha))
  505. writel(set_rmask(NVR_WRITE_ENABLE),
  506. &ha->reg->u1.isp4022.nvram);
  507. writel(2, &ha->reg->mailbox[6]);
  508. readl(&ha->reg->mailbox[6]);
  509. writel(set_rmask(CSR_BOOT_ENABLE), &ha->reg->ctrl_status);
  510. readl(&ha->reg->ctrl_status);
  511. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  512. /* Wait for firmware to come UP. */
  513. DEBUG2(printk(KERN_INFO "scsi%ld: %s: Wait up to %d seconds for "
  514. "boot firmware to complete...\n",
  515. ha->host_no, __func__, FIRMWARE_UP_TOV));
  516. max_wait_time = jiffies + (FIRMWARE_UP_TOV * HZ);
  517. do {
  518. uint32_t ctrl_status;
  519. spin_lock_irqsave(&ha->hardware_lock, flags);
  520. ctrl_status = readw(&ha->reg->ctrl_status);
  521. mbox_status = readw(&ha->reg->mailbox[0]);
  522. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  523. if (ctrl_status & set_rmask(CSR_SCSI_PROCESSOR_INTR))
  524. break;
  525. if (mbox_status == MBOX_STS_COMMAND_COMPLETE)
  526. break;
  527. DEBUG2(printk(KERN_INFO "scsi%ld: %s: Waiting for boot "
  528. "firmware to complete... ctrl_sts=0x%x, remaining=%ld\n",
  529. ha->host_no, __func__, ctrl_status, max_wait_time));
  530. msleep_interruptible(250);
  531. } while (!time_after_eq(jiffies, max_wait_time));
  532. if (mbox_status == MBOX_STS_COMMAND_COMPLETE) {
  533. DEBUG(printk(KERN_INFO "scsi%ld: %s: Firmware has started\n",
  534. ha->host_no, __func__));
  535. spin_lock_irqsave(&ha->hardware_lock, flags);
  536. writel(set_rmask(CSR_SCSI_PROCESSOR_INTR),
  537. &ha->reg->ctrl_status);
  538. readl(&ha->reg->ctrl_status);
  539. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  540. status = QLA_SUCCESS;
  541. } else {
  542. printk(KERN_INFO "scsi%ld: %s: Boot firmware failed "
  543. "- mbox status 0x%x\n", ha->host_no, __func__,
  544. mbox_status);
  545. status = QLA_ERROR;
  546. }
  547. return status;
  548. }
  549. int ql4xxx_lock_drvr_wait(struct scsi_qla_host *a)
  550. {
  551. #define QL4_LOCK_DRVR_WAIT 60
  552. #define QL4_LOCK_DRVR_SLEEP 1
  553. int drvr_wait = QL4_LOCK_DRVR_WAIT;
  554. while (drvr_wait) {
  555. if (ql4xxx_lock_drvr(a) == 0) {
  556. ssleep(QL4_LOCK_DRVR_SLEEP);
  557. if (drvr_wait) {
  558. DEBUG2(printk("scsi%ld: %s: Waiting for "
  559. "Global Init Semaphore(%d)...\n",
  560. a->host_no,
  561. __func__, drvr_wait));
  562. }
  563. drvr_wait -= QL4_LOCK_DRVR_SLEEP;
  564. } else {
  565. DEBUG2(printk("scsi%ld: %s: Global Init Semaphore "
  566. "acquired\n", a->host_no, __func__));
  567. return QLA_SUCCESS;
  568. }
  569. }
  570. return QLA_ERROR;
  571. }
  572. /**
  573. * qla4xxx_start_firmware - starts qla4xxx firmware
  574. * @ha: Pointer to host adapter structure.
  575. *
  576. * This routine performs the necessary steps to start the firmware for
  577. * the QLA4010 adapter.
  578. **/
  579. int qla4xxx_start_firmware(struct scsi_qla_host *ha)
  580. {
  581. unsigned long flags = 0;
  582. uint32_t mbox_status;
  583. int status = QLA_ERROR;
  584. int soft_reset = 1;
  585. int config_chip = 0;
  586. if (is_qla4022(ha) | is_qla4032(ha))
  587. ql4xxx_set_mac_number(ha);
  588. if (ql4xxx_lock_drvr_wait(ha) != QLA_SUCCESS)
  589. return QLA_ERROR;
  590. spin_lock_irqsave(&ha->hardware_lock, flags);
  591. DEBUG2(printk("scsi%ld: %s: port_ctrl = 0x%08X\n", ha->host_no,
  592. __func__, readw(isp_port_ctrl(ha))));
  593. DEBUG(printk("scsi%ld: %s: port_status = 0x%08X\n", ha->host_no,
  594. __func__, readw(isp_port_status(ha))));
  595. /* Is Hardware already initialized? */
  596. if ((readw(isp_port_ctrl(ha)) & 0x8000) != 0) {
  597. DEBUG(printk("scsi%ld: %s: Hardware has already been "
  598. "initialized\n", ha->host_no, __func__));
  599. /* Receive firmware boot acknowledgement */
  600. mbox_status = readw(&ha->reg->mailbox[0]);
  601. DEBUG2(printk("scsi%ld: %s: H/W Config complete - mbox[0]= "
  602. "0x%x\n", ha->host_no, __func__, mbox_status));
  603. /* Is firmware already booted? */
  604. if (mbox_status == 0) {
  605. /* F/W not running, must be config by net driver */
  606. config_chip = 1;
  607. soft_reset = 0;
  608. } else {
  609. writel(set_rmask(CSR_SCSI_PROCESSOR_INTR),
  610. &ha->reg->ctrl_status);
  611. readl(&ha->reg->ctrl_status);
  612. writel(set_rmask(CSR_SCSI_COMPLETION_INTR),
  613. &ha->reg->ctrl_status);
  614. readl(&ha->reg->ctrl_status);
  615. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  616. if (qla4xxx_get_firmware_state(ha) == QLA_SUCCESS) {
  617. DEBUG2(printk("scsi%ld: %s: Get firmware "
  618. "state -- state = 0x%x\n",
  619. ha->host_no,
  620. __func__, ha->firmware_state));
  621. /* F/W is running */
  622. if (ha->firmware_state &
  623. FW_STATE_CONFIG_WAIT) {
  624. DEBUG2(printk("scsi%ld: %s: Firmware "
  625. "in known state -- "
  626. "config and "
  627. "boot, state = 0x%x\n",
  628. ha->host_no, __func__,
  629. ha->firmware_state));
  630. config_chip = 1;
  631. soft_reset = 0;
  632. }
  633. } else {
  634. DEBUG2(printk("scsi%ld: %s: Firmware in "
  635. "unknown state -- resetting,"
  636. " state = "
  637. "0x%x\n", ha->host_no, __func__,
  638. ha->firmware_state));
  639. }
  640. spin_lock_irqsave(&ha->hardware_lock, flags);
  641. }
  642. } else {
  643. DEBUG(printk("scsi%ld: %s: H/W initialization hasn't been "
  644. "started - resetting\n", ha->host_no, __func__));
  645. }
  646. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  647. DEBUG(printk("scsi%ld: %s: Flags soft_rest=%d, config= %d\n ",
  648. ha->host_no, __func__, soft_reset, config_chip));
  649. if (soft_reset) {
  650. DEBUG(printk("scsi%ld: %s: Issue Soft Reset\n", ha->host_no,
  651. __func__));
  652. status = qla4xxx_soft_reset(ha); /* NOTE: acquires drvr
  653. * lock again, but ok */
  654. if (status == QLA_ERROR) {
  655. DEBUG(printk("scsi%d: %s: Soft Reset failed!\n",
  656. ha->host_no, __func__));
  657. ql4xxx_unlock_drvr(ha);
  658. return QLA_ERROR;
  659. }
  660. config_chip = 1;
  661. /* Reset clears the semaphore, so acquire again */
  662. if (ql4xxx_lock_drvr_wait(ha) != QLA_SUCCESS)
  663. return QLA_ERROR;
  664. }
  665. if (config_chip) {
  666. if ((status = qla4xxx_config_nvram(ha)) == QLA_SUCCESS)
  667. status = qla4xxx_start_firmware_from_flash(ha);
  668. }
  669. ql4xxx_unlock_drvr(ha);
  670. if (status == QLA_SUCCESS) {
  671. if (test_and_clear_bit(AF_GET_CRASH_RECORD, &ha->flags))
  672. qla4xxx_get_crash_record(ha);
  673. } else {
  674. DEBUG(printk("scsi%ld: %s: Firmware has NOT started\n",
  675. ha->host_no, __func__));
  676. }
  677. return status;
  678. }
  679. /**
  680. * qla4xxx_free_ddb_index - Free DDBs reserved by firmware
  681. * @ha: pointer to adapter structure
  682. *
  683. * Since firmware is not running in autoconnect mode the DDB indices should
  684. * be freed so that when login happens from user space there are free DDB
  685. * indices available.
  686. **/
  687. void qla4xxx_free_ddb_index(struct scsi_qla_host *ha)
  688. {
  689. int max_ddbs;
  690. int ret;
  691. uint32_t idx = 0, next_idx = 0;
  692. uint32_t state = 0, conn_err = 0;
  693. max_ddbs = is_qla40XX(ha) ? MAX_DEV_DB_ENTRIES_40XX :
  694. MAX_DEV_DB_ENTRIES;
  695. for (idx = 0; idx < max_ddbs; idx = next_idx) {
  696. ret = qla4xxx_get_fwddb_entry(ha, idx, NULL, 0, NULL,
  697. &next_idx, &state, &conn_err,
  698. NULL, NULL);
  699. if (ret == QLA_ERROR) {
  700. next_idx++;
  701. continue;
  702. }
  703. if (state == DDB_DS_NO_CONNECTION_ACTIVE ||
  704. state == DDB_DS_SESSION_FAILED) {
  705. DEBUG2(ql4_printk(KERN_INFO, ha,
  706. "Freeing DDB index = 0x%x\n", idx));
  707. ret = qla4xxx_clear_ddb_entry(ha, idx);
  708. if (ret == QLA_ERROR)
  709. ql4_printk(KERN_ERR, ha,
  710. "Unable to clear DDB index = "
  711. "0x%x\n", idx);
  712. }
  713. if (next_idx == 0)
  714. break;
  715. }
  716. }
  717. /**
  718. * qla4xxx_initialize_adapter - initiailizes hba
  719. * @ha: Pointer to host adapter structure.
  720. *
  721. * This routine parforms all of the steps necessary to initialize the adapter.
  722. *
  723. **/
  724. int qla4xxx_initialize_adapter(struct scsi_qla_host *ha, int is_reset)
  725. {
  726. int status = QLA_ERROR;
  727. ha->eeprom_cmd_data = 0;
  728. ql4_printk(KERN_INFO, ha, "Configuring PCI space...\n");
  729. ha->isp_ops->pci_config(ha);
  730. ha->isp_ops->disable_intrs(ha);
  731. /* Initialize the Host adapter request/response queues and firmware */
  732. if (ha->isp_ops->start_firmware(ha) == QLA_ERROR)
  733. goto exit_init_hba;
  734. if (qla4xxx_about_firmware(ha) == QLA_ERROR)
  735. goto exit_init_hba;
  736. if (ha->isp_ops->get_sys_info(ha) == QLA_ERROR)
  737. goto exit_init_hba;
  738. if (qla4xxx_init_local_data(ha) == QLA_ERROR)
  739. goto exit_init_hba;
  740. status = qla4xxx_init_firmware(ha);
  741. if (status == QLA_ERROR)
  742. goto exit_init_hba;
  743. if (is_reset == RESET_ADAPTER)
  744. qla4xxx_build_ddb_list(ha, is_reset);
  745. set_bit(AF_ONLINE, &ha->flags);
  746. exit_init_hba:
  747. if (is_qla8022(ha) && (status == QLA_ERROR)) {
  748. /* Since interrupts are registered in start_firmware for
  749. * 82xx, release them here if initialize_adapter fails */
  750. qla4xxx_free_irqs(ha);
  751. }
  752. DEBUG2(printk("scsi%ld: initialize adapter: %s\n", ha->host_no,
  753. status == QLA_ERROR ? "FAILED" : "SUCCEEDED"));
  754. return status;
  755. }
  756. int qla4xxx_ddb_change(struct scsi_qla_host *ha, uint32_t fw_ddb_index,
  757. struct ddb_entry *ddb_entry, uint32_t state)
  758. {
  759. uint32_t old_fw_ddb_device_state;
  760. int status = QLA_ERROR;
  761. old_fw_ddb_device_state = ddb_entry->fw_ddb_device_state;
  762. DEBUG2(ql4_printk(KERN_INFO, ha,
  763. "%s: DDB - old state = 0x%x, new state = 0x%x for "
  764. "index [%d]\n", __func__,
  765. ddb_entry->fw_ddb_device_state, state, fw_ddb_index));
  766. ddb_entry->fw_ddb_device_state = state;
  767. switch (old_fw_ddb_device_state) {
  768. case DDB_DS_LOGIN_IN_PROCESS:
  769. switch (state) {
  770. case DDB_DS_SESSION_ACTIVE:
  771. case DDB_DS_DISCOVERY:
  772. ddb_entry->unblock_sess(ddb_entry->sess);
  773. qla4xxx_update_session_conn_param(ha, ddb_entry);
  774. status = QLA_SUCCESS;
  775. break;
  776. case DDB_DS_SESSION_FAILED:
  777. case DDB_DS_NO_CONNECTION_ACTIVE:
  778. iscsi_conn_login_event(ddb_entry->conn,
  779. ISCSI_CONN_STATE_FREE);
  780. status = QLA_SUCCESS;
  781. break;
  782. }
  783. break;
  784. case DDB_DS_SESSION_ACTIVE:
  785. switch (state) {
  786. case DDB_DS_SESSION_FAILED:
  787. /*
  788. * iscsi_session failure will cause userspace to
  789. * stop the connection which in turn would block the
  790. * iscsi_session and start relogin
  791. */
  792. iscsi_session_failure(ddb_entry->sess->dd_data,
  793. ISCSI_ERR_CONN_FAILED);
  794. status = QLA_SUCCESS;
  795. break;
  796. case DDB_DS_NO_CONNECTION_ACTIVE:
  797. clear_bit(fw_ddb_index, ha->ddb_idx_map);
  798. status = QLA_SUCCESS;
  799. break;
  800. }
  801. break;
  802. case DDB_DS_SESSION_FAILED:
  803. switch (state) {
  804. case DDB_DS_SESSION_ACTIVE:
  805. case DDB_DS_DISCOVERY:
  806. ddb_entry->unblock_sess(ddb_entry->sess);
  807. qla4xxx_update_session_conn_param(ha, ddb_entry);
  808. status = QLA_SUCCESS;
  809. break;
  810. case DDB_DS_SESSION_FAILED:
  811. iscsi_session_failure(ddb_entry->sess->dd_data,
  812. ISCSI_ERR_CONN_FAILED);
  813. status = QLA_SUCCESS;
  814. break;
  815. }
  816. break;
  817. default:
  818. DEBUG2(ql4_printk(KERN_INFO, ha, "%s: Unknown Event\n",
  819. __func__));
  820. break;
  821. }
  822. return status;
  823. }
  824. void qla4xxx_arm_relogin_timer(struct ddb_entry *ddb_entry)
  825. {
  826. /*
  827. * This triggers a relogin. After the relogin_timer
  828. * expires, the relogin gets scheduled. We must wait a
  829. * minimum amount of time since receiving an 0x8014 AEN
  830. * with failed device_state or a logout response before
  831. * we can issue another relogin.
  832. *
  833. * Firmware pads this timeout: (time2wait +1).
  834. * Driver retry to login should be longer than F/W.
  835. * Otherwise F/W will fail
  836. * set_ddb() mbx cmd with 0x4005 since it still
  837. * counting down its time2wait.
  838. */
  839. atomic_set(&ddb_entry->relogin_timer, 0);
  840. atomic_set(&ddb_entry->retry_relogin_timer,
  841. ddb_entry->default_time2wait + 4);
  842. }
  843. int qla4xxx_flash_ddb_change(struct scsi_qla_host *ha, uint32_t fw_ddb_index,
  844. struct ddb_entry *ddb_entry, uint32_t state)
  845. {
  846. uint32_t old_fw_ddb_device_state;
  847. int status = QLA_ERROR;
  848. old_fw_ddb_device_state = ddb_entry->fw_ddb_device_state;
  849. DEBUG2(ql4_printk(KERN_INFO, ha,
  850. "%s: DDB - old state = 0x%x, new state = 0x%x for "
  851. "index [%d]\n", __func__,
  852. ddb_entry->fw_ddb_device_state, state, fw_ddb_index));
  853. ddb_entry->fw_ddb_device_state = state;
  854. switch (old_fw_ddb_device_state) {
  855. case DDB_DS_LOGIN_IN_PROCESS:
  856. case DDB_DS_NO_CONNECTION_ACTIVE:
  857. switch (state) {
  858. case DDB_DS_SESSION_ACTIVE:
  859. ddb_entry->unblock_sess(ddb_entry->sess);
  860. qla4xxx_update_session_conn_fwddb_param(ha, ddb_entry);
  861. status = QLA_SUCCESS;
  862. break;
  863. case DDB_DS_SESSION_FAILED:
  864. iscsi_block_session(ddb_entry->sess);
  865. if (!test_bit(DF_RELOGIN, &ddb_entry->flags))
  866. qla4xxx_arm_relogin_timer(ddb_entry);
  867. status = QLA_SUCCESS;
  868. break;
  869. }
  870. break;
  871. case DDB_DS_SESSION_ACTIVE:
  872. switch (state) {
  873. case DDB_DS_SESSION_FAILED:
  874. iscsi_block_session(ddb_entry->sess);
  875. if (!test_bit(DF_RELOGIN, &ddb_entry->flags))
  876. qla4xxx_arm_relogin_timer(ddb_entry);
  877. status = QLA_SUCCESS;
  878. break;
  879. }
  880. break;
  881. case DDB_DS_SESSION_FAILED:
  882. switch (state) {
  883. case DDB_DS_SESSION_ACTIVE:
  884. ddb_entry->unblock_sess(ddb_entry->sess);
  885. qla4xxx_update_session_conn_fwddb_param(ha, ddb_entry);
  886. status = QLA_SUCCESS;
  887. break;
  888. case DDB_DS_SESSION_FAILED:
  889. if (!test_bit(DF_RELOGIN, &ddb_entry->flags))
  890. qla4xxx_arm_relogin_timer(ddb_entry);
  891. status = QLA_SUCCESS;
  892. break;
  893. }
  894. break;
  895. default:
  896. DEBUG2(ql4_printk(KERN_INFO, ha, "%s: Unknown Event\n",
  897. __func__));
  898. break;
  899. }
  900. return status;
  901. }
  902. /**
  903. * qla4xxx_process_ddb_changed - process ddb state change
  904. * @ha - Pointer to host adapter structure.
  905. * @fw_ddb_index - Firmware's device database index
  906. * @state - Device state
  907. *
  908. * This routine processes a Decive Database Changed AEN Event.
  909. **/
  910. int qla4xxx_process_ddb_changed(struct scsi_qla_host *ha,
  911. uint32_t fw_ddb_index,
  912. uint32_t state, uint32_t conn_err)
  913. {
  914. struct ddb_entry *ddb_entry;
  915. int status = QLA_ERROR;
  916. /* check for out of range index */
  917. if (fw_ddb_index >= MAX_DDB_ENTRIES)
  918. goto exit_ddb_event;
  919. /* Get the corresponging ddb entry */
  920. ddb_entry = qla4xxx_lookup_ddb_by_fw_index(ha, fw_ddb_index);
  921. /* Device does not currently exist in our database. */
  922. if (ddb_entry == NULL) {
  923. ql4_printk(KERN_ERR, ha, "%s: No ddb_entry at FW index [%d]\n",
  924. __func__, fw_ddb_index);
  925. if (state == DDB_DS_NO_CONNECTION_ACTIVE)
  926. clear_bit(fw_ddb_index, ha->ddb_idx_map);
  927. goto exit_ddb_event;
  928. }
  929. ddb_entry->ddb_change(ha, fw_ddb_index, ddb_entry, state);
  930. exit_ddb_event:
  931. return status;
  932. }
  933. /**
  934. * qla4xxx_login_flash_ddb - Login to target (DDB)
  935. * @cls_session: Pointer to the session to login
  936. *
  937. * This routine logins to the target.
  938. * Issues setddb and conn open mbx
  939. **/
  940. void qla4xxx_login_flash_ddb(struct iscsi_cls_session *cls_session)
  941. {
  942. struct iscsi_session *sess;
  943. struct ddb_entry *ddb_entry;
  944. struct scsi_qla_host *ha;
  945. struct dev_db_entry *fw_ddb_entry = NULL;
  946. dma_addr_t fw_ddb_dma;
  947. uint32_t mbx_sts = 0;
  948. int ret;
  949. sess = cls_session->dd_data;
  950. ddb_entry = sess->dd_data;
  951. ha = ddb_entry->ha;
  952. if (!test_bit(AF_LINK_UP, &ha->flags))
  953. return;
  954. if (ddb_entry->ddb_type != FLASH_DDB) {
  955. DEBUG2(ql4_printk(KERN_INFO, ha,
  956. "Skipping login to non FLASH DB"));
  957. goto exit_login;
  958. }
  959. fw_ddb_entry = dma_pool_alloc(ha->fw_ddb_dma_pool, GFP_KERNEL,
  960. &fw_ddb_dma);
  961. if (fw_ddb_entry == NULL) {
  962. DEBUG2(ql4_printk(KERN_ERR, ha, "Out of memory\n"));
  963. goto exit_login;
  964. }
  965. if (ddb_entry->fw_ddb_index == INVALID_ENTRY) {
  966. ret = qla4xxx_get_ddb_index(ha, &ddb_entry->fw_ddb_index);
  967. if (ret == QLA_ERROR)
  968. goto exit_login;
  969. ha->fw_ddb_index_map[ddb_entry->fw_ddb_index] = ddb_entry;
  970. ha->tot_ddbs++;
  971. }
  972. memcpy(fw_ddb_entry, &ddb_entry->fw_ddb_entry,
  973. sizeof(struct dev_db_entry));
  974. ddb_entry->sess->target_id = ddb_entry->fw_ddb_index;
  975. ret = qla4xxx_set_ddb_entry(ha, ddb_entry->fw_ddb_index,
  976. fw_ddb_dma, &mbx_sts);
  977. if (ret == QLA_ERROR) {
  978. DEBUG2(ql4_printk(KERN_ERR, ha, "Set DDB failed\n"));
  979. goto exit_login;
  980. }
  981. ddb_entry->fw_ddb_device_state = DDB_DS_LOGIN_IN_PROCESS;
  982. ret = qla4xxx_conn_open(ha, ddb_entry->fw_ddb_index);
  983. if (ret == QLA_ERROR) {
  984. ql4_printk(KERN_ERR, ha, "%s: Login failed: %s\n", __func__,
  985. sess->targetname);
  986. goto exit_login;
  987. }
  988. exit_login:
  989. if (fw_ddb_entry)
  990. dma_pool_free(ha->fw_ddb_dma_pool, fw_ddb_entry, fw_ddb_dma);
  991. }