ql4_init.c 35 KB

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