diff options
author | David C Somayajulu <david.somayajulu@qlogic.com> | 2007-05-23 20:55:40 -0400 |
---|---|---|
committer | James Bottomley <jejb@mulgrave.il.steeleye.com> | 2007-05-26 12:47:35 -0400 |
commit | 92b7273608da2c681f54fd36d182a582673ed260 (patch) | |
tree | 69be334661a46206d5b57b481be2b19dd90f7db0 /drivers/scsi/qla4xxx/ql4_init.c | |
parent | b2854316574d1fa2f1b85ad336d4a88aee5dd140 (diff) |
[SCSI] qla4xxx: ql4_init.c bugfixes
In qla4xxx_get_ddb_entry() and qla4xxx_add_device_dynamically()
differentiate between a target which has been newly added vs a target
which went offline temporarily and is online again. In
qla4xxx_build_ddb_list() firmware ddb state needs to be updated by
calling qla4xxx_get_ddb_entry(). Fix qla4x00_pci_config() and clean up
code.
Signed-off-by: David Somayajulu <david.somayajulu@qlogic.com>
Signed-off-by: Mike Christie <michaelc@cs.wisc.edu>
Signed-off-by: James Bottomley <James.Bottomley@SteelEye.com>
Diffstat (limited to 'drivers/scsi/qla4xxx/ql4_init.c')
-rw-r--r-- | drivers/scsi/qla4xxx/ql4_init.c | 92 |
1 files changed, 63 insertions, 29 deletions
diff --git a/drivers/scsi/qla4xxx/ql4_init.c b/drivers/scsi/qla4xxx/ql4_init.c index 6365df268612..d8c064c2afc3 100644 --- a/drivers/scsi/qla4xxx/ql4_init.c +++ b/drivers/scsi/qla4xxx/ql4_init.c | |||
@@ -6,6 +6,9 @@ | |||
6 | */ | 6 | */ |
7 | 7 | ||
8 | #include "ql4_def.h" | 8 | #include "ql4_def.h" |
9 | #include "ql4_glbl.h" | ||
10 | #include "ql4_dbg.h" | ||
11 | #include "ql4_inline.h" | ||
9 | 12 | ||
10 | static struct ddb_entry * qla4xxx_alloc_ddb(struct scsi_qla_host *ha, | 13 | static struct ddb_entry * qla4xxx_alloc_ddb(struct scsi_qla_host *ha, |
11 | uint32_t fw_ddb_index); | 14 | uint32_t fw_ddb_index); |
@@ -300,12 +303,12 @@ static int qla4xxx_init_firmware(struct scsi_qla_host *ha) | |||
300 | if (!qla4xxx_fw_ready(ha)) | 303 | if (!qla4xxx_fw_ready(ha)) |
301 | return status; | 304 | return status; |
302 | 305 | ||
303 | set_bit(AF_ONLINE, &ha->flags); | ||
304 | return qla4xxx_get_firmware_status(ha); | 306 | return qla4xxx_get_firmware_status(ha); |
305 | } | 307 | } |
306 | 308 | ||
307 | static struct ddb_entry* qla4xxx_get_ddb_entry(struct scsi_qla_host *ha, | 309 | static struct ddb_entry* qla4xxx_get_ddb_entry(struct scsi_qla_host *ha, |
308 | uint32_t fw_ddb_index) | 310 | uint32_t fw_ddb_index, |
311 | uint32_t *new_tgt) | ||
309 | { | 312 | { |
310 | struct dev_db_entry *fw_ddb_entry = NULL; | 313 | struct dev_db_entry *fw_ddb_entry = NULL; |
311 | dma_addr_t fw_ddb_entry_dma; | 314 | dma_addr_t fw_ddb_entry_dma; |
@@ -313,6 +316,7 @@ static struct ddb_entry* qla4xxx_get_ddb_entry(struct scsi_qla_host *ha, | |||
313 | int found = 0; | 316 | int found = 0; |
314 | uint32_t device_state; | 317 | uint32_t device_state; |
315 | 318 | ||
319 | *new_tgt = 0; | ||
316 | /* Make sure the dma buffer is valid */ | 320 | /* Make sure the dma buffer is valid */ |
317 | fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, | 321 | fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, |
318 | sizeof(*fw_ddb_entry), | 322 | sizeof(*fw_ddb_entry), |
@@ -337,7 +341,7 @@ static struct ddb_entry* qla4xxx_get_ddb_entry(struct scsi_qla_host *ha, | |||
337 | DEBUG2(printk("scsi%ld: %s: Looking for ddb[%d]\n", ha->host_no, | 341 | DEBUG2(printk("scsi%ld: %s: Looking for ddb[%d]\n", ha->host_no, |
338 | __func__, fw_ddb_index)); | 342 | __func__, fw_ddb_index)); |
339 | list_for_each_entry(ddb_entry, &ha->ddb_list, list) { | 343 | list_for_each_entry(ddb_entry, &ha->ddb_list, list) { |
340 | if (memcmp(ddb_entry->iscsi_name, fw_ddb_entry->iscsiName, | 344 | if (memcmp(ddb_entry->iscsi_name, fw_ddb_entry->iscsi_name, |
341 | ISCSI_NAME_SIZE) == 0) { | 345 | ISCSI_NAME_SIZE) == 0) { |
342 | found++; | 346 | found++; |
343 | break; | 347 | break; |
@@ -348,6 +352,7 @@ static struct ddb_entry* qla4xxx_get_ddb_entry(struct scsi_qla_host *ha, | |||
348 | DEBUG2(printk("scsi%ld: %s: ddb[%d] not found - allocating " | 352 | DEBUG2(printk("scsi%ld: %s: ddb[%d] not found - allocating " |
349 | "new ddb\n", ha->host_no, __func__, | 353 | "new ddb\n", ha->host_no, __func__, |
350 | fw_ddb_index)); | 354 | fw_ddb_index)); |
355 | *new_tgt = 1; | ||
351 | ddb_entry = qla4xxx_alloc_ddb(ha, fw_ddb_index); | 356 | ddb_entry = qla4xxx_alloc_ddb(ha, fw_ddb_index); |
352 | } | 357 | } |
353 | 358 | ||
@@ -409,26 +414,26 @@ static int qla4xxx_update_ddb_entry(struct scsi_qla_host *ha, | |||
409 | } | 414 | } |
410 | 415 | ||
411 | status = QLA_SUCCESS; | 416 | status = QLA_SUCCESS; |
412 | ddb_entry->target_session_id = le16_to_cpu(fw_ddb_entry->TSID); | 417 | ddb_entry->target_session_id = le16_to_cpu(fw_ddb_entry->tsid); |
413 | ddb_entry->task_mgmt_timeout = | 418 | ddb_entry->task_mgmt_timeout = |
414 | le16_to_cpu(fw_ddb_entry->taskMngmntTimeout); | 419 | le16_to_cpu(fw_ddb_entry->def_timeout); |
415 | ddb_entry->CmdSn = 0; | 420 | ddb_entry->CmdSn = 0; |
416 | ddb_entry->exe_throttle = le16_to_cpu(fw_ddb_entry->exeThrottle); | 421 | ddb_entry->exe_throttle = le16_to_cpu(fw_ddb_entry->exec_throttle); |
417 | ddb_entry->default_relogin_timeout = | 422 | ddb_entry->default_relogin_timeout = |
418 | le16_to_cpu(fw_ddb_entry->taskMngmntTimeout); | 423 | le16_to_cpu(fw_ddb_entry->def_timeout); |
419 | ddb_entry->default_time2wait = le16_to_cpu(fw_ddb_entry->minTime2Wait); | 424 | ddb_entry->default_time2wait = le16_to_cpu(fw_ddb_entry->iscsi_def_time2wait); |
420 | 425 | ||
421 | /* Update index in case it changed */ | 426 | /* Update index in case it changed */ |
422 | ddb_entry->fw_ddb_index = fw_ddb_index; | 427 | ddb_entry->fw_ddb_index = fw_ddb_index; |
423 | ha->fw_ddb_index_map[fw_ddb_index] = ddb_entry; | 428 | ha->fw_ddb_index_map[fw_ddb_index] = ddb_entry; |
424 | 429 | ||
425 | ddb_entry->port = le16_to_cpu(fw_ddb_entry->portNumber); | 430 | ddb_entry->port = le16_to_cpu(fw_ddb_entry->port); |
426 | ddb_entry->tpgt = le32_to_cpu(fw_ddb_entry->TargetPortalGroup); | 431 | ddb_entry->tpgt = le32_to_cpu(fw_ddb_entry->tgt_portal_grp); |
427 | memcpy(&ddb_entry->iscsi_name[0], &fw_ddb_entry->iscsiName[0], | 432 | memcpy(&ddb_entry->iscsi_name[0], &fw_ddb_entry->iscsi_name[0], |
428 | min(sizeof(ddb_entry->iscsi_name), | 433 | min(sizeof(ddb_entry->iscsi_name), |
429 | sizeof(fw_ddb_entry->iscsiName))); | 434 | sizeof(fw_ddb_entry->iscsi_name))); |
430 | memcpy(&ddb_entry->ip_addr[0], &fw_ddb_entry->ipAddr[0], | 435 | memcpy(&ddb_entry->ip_addr[0], &fw_ddb_entry->ip_addr[0], |
431 | min(sizeof(ddb_entry->ip_addr), sizeof(fw_ddb_entry->ipAddr))); | 436 | min(sizeof(ddb_entry->ip_addr), sizeof(fw_ddb_entry->ip_addr))); |
432 | 437 | ||
433 | DEBUG2(printk("scsi%ld: %s: ddb[%d] - State= %x status= %d.\n", | 438 | DEBUG2(printk("scsi%ld: %s: ddb[%d] - State= %x status= %d.\n", |
434 | ha->host_no, __func__, fw_ddb_index, | 439 | ha->host_no, __func__, fw_ddb_index, |
@@ -495,6 +500,7 @@ static int qla4xxx_build_ddb_list(struct scsi_qla_host *ha) | |||
495 | uint32_t ddb_state; | 500 | uint32_t ddb_state; |
496 | uint32_t conn_err, err_code; | 501 | uint32_t conn_err, err_code; |
497 | struct ddb_entry *ddb_entry; | 502 | struct ddb_entry *ddb_entry; |
503 | uint32_t new_tgt; | ||
498 | 504 | ||
499 | dev_info(&ha->pdev->dev, "Initializing DDBs ...\n"); | 505 | dev_info(&ha->pdev->dev, "Initializing DDBs ...\n"); |
500 | for (fw_ddb_index = 0; fw_ddb_index < MAX_DDB_ENTRIES; | 506 | for (fw_ddb_index = 0; fw_ddb_index < MAX_DDB_ENTRIES; |
@@ -526,8 +532,19 @@ static int qla4xxx_build_ddb_list(struct scsi_qla_host *ha) | |||
526 | "completed " | 532 | "completed " |
527 | "or access denied failure\n", | 533 | "or access denied failure\n", |
528 | ha->host_no, __func__)); | 534 | ha->host_no, __func__)); |
529 | } else | 535 | } else { |
530 | qla4xxx_set_ddb_entry(ha, fw_ddb_index, 0); | 536 | qla4xxx_set_ddb_entry(ha, fw_ddb_index, 0); |
537 | if (qla4xxx_get_fwddb_entry(ha, fw_ddb_index, | ||
538 | NULL, 0, NULL, &next_fw_ddb_index, | ||
539 | &ddb_state, &conn_err, NULL, NULL) | ||
540 | == QLA_ERROR) { | ||
541 | DEBUG2(printk("scsi%ld: %s:" | ||
542 | "get_ddb_entry %d failed\n", | ||
543 | ha->host_no, | ||
544 | __func__, fw_ddb_index)); | ||
545 | return QLA_ERROR; | ||
546 | } | ||
547 | } | ||
531 | } | 548 | } |
532 | 549 | ||
533 | if (ddb_state != DDB_DS_SESSION_ACTIVE) | 550 | if (ddb_state != DDB_DS_SESSION_ACTIVE) |
@@ -540,7 +557,7 @@ static int qla4xxx_build_ddb_list(struct scsi_qla_host *ha) | |||
540 | ha->host_no, __func__, fw_ddb_index)); | 557 | ha->host_no, __func__, fw_ddb_index)); |
541 | 558 | ||
542 | /* Add DDB to internal our ddb list. */ | 559 | /* Add DDB to internal our ddb list. */ |
543 | ddb_entry = qla4xxx_get_ddb_entry(ha, fw_ddb_index); | 560 | ddb_entry = qla4xxx_get_ddb_entry(ha, fw_ddb_index, &new_tgt); |
544 | if (ddb_entry == NULL) { | 561 | if (ddb_entry == NULL) { |
545 | DEBUG2(printk("scsi%ld: %s: Unable to allocate memory " | 562 | DEBUG2(printk("scsi%ld: %s: Unable to allocate memory " |
546 | "for device at fw_ddb_index %d\n", | 563 | "for device at fw_ddb_index %d\n", |
@@ -865,21 +882,19 @@ static int qla4xxx_config_nvram(struct scsi_qla_host *ha) | |||
865 | 882 | ||
866 | static void qla4x00_pci_config(struct scsi_qla_host *ha) | 883 | static void qla4x00_pci_config(struct scsi_qla_host *ha) |
867 | { | 884 | { |
868 | uint16_t w, mwi; | 885 | uint16_t w; |
869 | 886 | ||
870 | dev_info(&ha->pdev->dev, "Configuring PCI space...\n"); | 887 | dev_info(&ha->pdev->dev, "Configuring PCI space...\n"); |
871 | 888 | ||
872 | pci_set_master(ha->pdev); | 889 | pci_set_master(ha->pdev); |
873 | mwi = 0; | 890 | pci_set_mwi(ha->pdev); |
874 | if (pci_set_mwi(ha->pdev)) | ||
875 | mwi = PCI_COMMAND_INVALIDATE; | ||
876 | /* | 891 | /* |
877 | * We want to respect framework's setting of PCI configuration space | 892 | * We want to respect framework's setting of PCI configuration space |
878 | * command register and also want to make sure that all bits of | 893 | * command register and also want to make sure that all bits of |
879 | * interest to us are properly set in command register. | 894 | * interest to us are properly set in command register. |
880 | */ | 895 | */ |
881 | pci_read_config_word(ha->pdev, PCI_COMMAND, &w); | 896 | pci_read_config_word(ha->pdev, PCI_COMMAND, &w); |
882 | w |= mwi | (PCI_COMMAND_PARITY | PCI_COMMAND_SERR); | 897 | w |= PCI_COMMAND_PARITY | PCI_COMMAND_SERR; |
883 | w &= ~PCI_COMMAND_INTX_DISABLE; | 898 | w &= ~PCI_COMMAND_INTX_DISABLE; |
884 | pci_write_config_word(ha->pdev, PCI_COMMAND, w); | 899 | pci_write_config_word(ha->pdev, PCI_COMMAND, w); |
885 | } | 900 | } |
@@ -911,6 +926,9 @@ static int qla4xxx_start_firmware_from_flash(struct scsi_qla_host *ha) | |||
911 | writel(set_rmask(NVR_WRITE_ENABLE), | 926 | writel(set_rmask(NVR_WRITE_ENABLE), |
912 | &ha->reg->u1.isp4022.nvram); | 927 | &ha->reg->u1.isp4022.nvram); |
913 | 928 | ||
929 | writel(2, &ha->reg->mailbox[6]); | ||
930 | readl(&ha->reg->mailbox[6]); | ||
931 | |||
914 | writel(set_rmask(CSR_BOOT_ENABLE), &ha->reg->ctrl_status); | 932 | writel(set_rmask(CSR_BOOT_ENABLE), &ha->reg->ctrl_status); |
915 | readl(&ha->reg->ctrl_status); | 933 | readl(&ha->reg->ctrl_status); |
916 | spin_unlock_irqrestore(&ha->hardware_lock, flags); | 934 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
@@ -958,25 +976,25 @@ static int qla4xxx_start_firmware_from_flash(struct scsi_qla_host *ha) | |||
958 | return status; | 976 | return status; |
959 | } | 977 | } |
960 | 978 | ||
961 | int ql4xxx_lock_drvr_wait(struct scsi_qla_host *ha) | 979 | int ql4xxx_lock_drvr_wait(struct scsi_qla_host *a) |
962 | { | 980 | { |
963 | #define QL4_LOCK_DRVR_WAIT 30 | 981 | #define QL4_LOCK_DRVR_WAIT 60 |
964 | #define QL4_LOCK_DRVR_SLEEP 1 | 982 | #define QL4_LOCK_DRVR_SLEEP 1 |
965 | 983 | ||
966 | int drvr_wait = QL4_LOCK_DRVR_WAIT; | 984 | int drvr_wait = QL4_LOCK_DRVR_WAIT; |
967 | while (drvr_wait) { | 985 | while (drvr_wait) { |
968 | if (ql4xxx_lock_drvr(ha) == 0) { | 986 | if (ql4xxx_lock_drvr(a) == 0) { |
969 | ssleep(QL4_LOCK_DRVR_SLEEP); | 987 | ssleep(QL4_LOCK_DRVR_SLEEP); |
970 | if (drvr_wait) { | 988 | if (drvr_wait) { |
971 | DEBUG2(printk("scsi%ld: %s: Waiting for " | 989 | DEBUG2(printk("scsi%ld: %s: Waiting for " |
972 | "Global Init Semaphore(%d)...n", | 990 | "Global Init Semaphore(%d)...\n", |
973 | ha->host_no, | 991 | a->host_no, |
974 | __func__, drvr_wait)); | 992 | __func__, drvr_wait)); |
975 | } | 993 | } |
976 | drvr_wait -= QL4_LOCK_DRVR_SLEEP; | 994 | drvr_wait -= QL4_LOCK_DRVR_SLEEP; |
977 | } else { | 995 | } else { |
978 | DEBUG2(printk("scsi%ld: %s: Global Init Semaphore " | 996 | DEBUG2(printk("scsi%ld: %s: Global Init Semaphore " |
979 | "acquired.n", ha->host_no, __func__)); | 997 | "acquired\n", a->host_no, __func__)); |
980 | return QLA_SUCCESS; | 998 | return QLA_SUCCESS; |
981 | } | 999 | } |
982 | } | 1000 | } |
@@ -1142,8 +1160,10 @@ int qla4xxx_initialize_adapter(struct scsi_qla_host *ha, | |||
1142 | * the ddb_list and wait for DHCP lease acquired aen to come in | 1160 | * the ddb_list and wait for DHCP lease acquired aen to come in |
1143 | * followed by 0x8014 aen" to trigger the tgt discovery process. | 1161 | * followed by 0x8014 aen" to trigger the tgt discovery process. |
1144 | */ | 1162 | */ |
1145 | if (ha->firmware_state & FW_STATE_DHCP_IN_PROGRESS) | 1163 | if (ha->firmware_state & FW_STATE_DHCP_IN_PROGRESS){ |
1164 | set_bit(AF_ONLINE, &ha->flags); | ||
1146 | return status; | 1165 | return status; |
1166 | } | ||
1147 | 1167 | ||
1148 | /* Skip device discovery if ip and subnet is zero */ | 1168 | /* Skip device discovery if ip and subnet is zero */ |
1149 | if (memcmp(ha->ip_address, ip_address, IP_ADDR_LEN) == 0 || | 1169 | if (memcmp(ha->ip_address, ip_address, IP_ADDR_LEN) == 0 || |
@@ -1177,6 +1197,7 @@ int qla4xxx_initialize_adapter(struct scsi_qla_host *ha, | |||
1177 | ha->host_no)); | 1197 | ha->host_no)); |
1178 | } | 1198 | } |
1179 | 1199 | ||
1200 | set_bit(AF_ONLINE, &ha->flags); | ||
1180 | exit_init_hba: | 1201 | exit_init_hba: |
1181 | return status; | 1202 | return status; |
1182 | 1203 | ||
@@ -1193,9 +1214,10 @@ static void qla4xxx_add_device_dynamically(struct scsi_qla_host *ha, | |||
1193 | uint32_t fw_ddb_index) | 1214 | uint32_t fw_ddb_index) |
1194 | { | 1215 | { |
1195 | struct ddb_entry * ddb_entry; | 1216 | struct ddb_entry * ddb_entry; |
1217 | uint32_t new_tgt; | ||
1196 | 1218 | ||
1197 | /* First allocate a device structure */ | 1219 | /* First allocate a device structure */ |
1198 | ddb_entry = qla4xxx_get_ddb_entry(ha, fw_ddb_index); | 1220 | ddb_entry = qla4xxx_get_ddb_entry(ha, fw_ddb_index, &new_tgt); |
1199 | if (ddb_entry == NULL) { | 1221 | if (ddb_entry == NULL) { |
1200 | DEBUG2(printk(KERN_WARNING | 1222 | DEBUG2(printk(KERN_WARNING |
1201 | "scsi%ld: Unable to allocate memory to add " | 1223 | "scsi%ld: Unable to allocate memory to add " |
@@ -1203,6 +1225,18 @@ static void qla4xxx_add_device_dynamically(struct scsi_qla_host *ha, | |||
1203 | return; | 1225 | return; |
1204 | } | 1226 | } |
1205 | 1227 | ||
1228 | if (!new_tgt && (ddb_entry->fw_ddb_index != fw_ddb_index)) { | ||
1229 | /* Target has been bound to a new fw_ddb_index */ | ||
1230 | qla4xxx_free_ddb(ha, ddb_entry); | ||
1231 | ddb_entry = qla4xxx_alloc_ddb(ha, fw_ddb_index); | ||
1232 | if (ddb_entry == NULL) { | ||
1233 | DEBUG2(printk(KERN_WARNING | ||
1234 | "scsi%ld: Unable to allocate memory" | ||
1235 | " to add fw_ddb_index %d\n", | ||
1236 | ha->host_no, fw_ddb_index)); | ||
1237 | return; | ||
1238 | } | ||
1239 | } | ||
1206 | if (qla4xxx_update_ddb_entry(ha, ddb_entry, fw_ddb_index) == | 1240 | if (qla4xxx_update_ddb_entry(ha, ddb_entry, fw_ddb_index) == |
1207 | QLA_ERROR) { | 1241 | QLA_ERROR) { |
1208 | ha->fw_ddb_index_map[fw_ddb_index] = | 1242 | ha->fw_ddb_index_map[fw_ddb_index] = |