ql4_init.c 34 KB

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