ql4_init.c 34 KB

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