ql4_init.c 31 KB

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