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