ql4_init.c 31 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132
  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. }