ql4_init.c 35 KB

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