ql4_init.c 35 KB

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