ql4_init.c 35 KB

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