12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340 |
- /*
- * QLogic iSCSI HBA Driver
- * Copyright (c) 2003-2006 QLogic Corporation
- *
- * See LICENSE.qla4xxx for copyright and licensing details.
- */
- #include "ql4_def.h"
- /*
- * QLogic ISP4xxx Hardware Support Function Prototypes.
- */
- static void ql4xxx_set_mac_number(struct scsi_qla_host *ha)
- {
- uint32_t value;
- uint8_t func_number;
- unsigned long flags;
- /* Get the function number */
- spin_lock_irqsave(&ha->hardware_lock, flags);
- value = readw(&ha->reg->ctrl_status);
- spin_unlock_irqrestore(&ha->hardware_lock, flags);
- func_number = (uint8_t) ((value >> 4) & 0x30);
- switch (value & ISP_CONTROL_FN_MASK) {
- case ISP_CONTROL_FN0_SCSI:
- ha->mac_index = 1;
- break;
- case ISP_CONTROL_FN1_SCSI:
- ha->mac_index = 3;
- break;
- default:
- DEBUG2(printk("scsi%ld: %s: Invalid function number, "
- "ispControlStatus = 0x%x\n", ha->host_no,
- __func__, value));
- break;
- }
- DEBUG2(printk("scsi%ld: %s: mac_index %d.\n", ha->host_no, __func__,
- ha->mac_index));
- }
- /**
- * qla4xxx_free_ddb - deallocate ddb
- * @ha: pointer to host adapter structure.
- * @ddb_entry: pointer to device database entry
- *
- * This routine deallocates and unlinks the specified ddb_entry from the
- * adapter's
- **/
- void qla4xxx_free_ddb(struct scsi_qla_host *ha, struct ddb_entry *ddb_entry)
- {
- /* Remove device entry from list */
- list_del_init(&ddb_entry->list);
- /* Remove device pointer from index mapping arrays */
- ha->fw_ddb_index_map[ddb_entry->fw_ddb_index] =
- (struct ddb_entry *) INVALID_ENTRY;
- ha->tot_ddbs--;
- /* Free memory and scsi-ml struct for device entry */
- qla4xxx_destroy_sess(ddb_entry);
- }
- /**
- * qla4xxx_free_ddb_list - deallocate all ddbs
- * @ha: pointer to host adapter structure.
- *
- * This routine deallocates and removes all devices on the sppecified adapter.
- **/
- void qla4xxx_free_ddb_list(struct scsi_qla_host *ha)
- {
- struct list_head *ptr;
- struct ddb_entry *ddb_entry;
- while (!list_empty(&ha->ddb_list)) {
- ptr = ha->ddb_list.next;
- /* Free memory for device entry and remove */
- ddb_entry = list_entry(ptr, struct ddb_entry, list);
- qla4xxx_free_ddb(ha, ddb_entry);
- }
- }
- /**
- * qla4xxx_init_rings - initialize hw queues
- * @ha: pointer to host adapter structure.
- *
- * This routine initializes the internal queues for the specified adapter.
- * The QLA4010 requires us to restart the queues at index 0.
- * The QLA4000 doesn't care, so just default to QLA4010's requirement.
- **/
- int qla4xxx_init_rings(struct scsi_qla_host *ha)
- {
- unsigned long flags = 0;
- /* Initialize request queue. */
- spin_lock_irqsave(&ha->hardware_lock, flags);
- ha->request_out = 0;
- ha->request_in = 0;
- ha->request_ptr = &ha->request_ring[ha->request_in];
- ha->req_q_count = REQUEST_QUEUE_DEPTH;
- /* Initialize response queue. */
- ha->response_in = 0;
- ha->response_out = 0;
- ha->response_ptr = &ha->response_ring[ha->response_out];
- /*
- * Initialize DMA Shadow registers. The firmware is really supposed to
- * take care of this, but on some uniprocessor systems, the shadow
- * registers aren't cleared-- causing the interrupt_handler to think
- * there are responses to be processed when there aren't.
- */
- ha->shadow_regs->req_q_out = __constant_cpu_to_le32(0);
- ha->shadow_regs->rsp_q_in = __constant_cpu_to_le32(0);
- wmb();
- writel(0, &ha->reg->req_q_in);
- writel(0, &ha->reg->rsp_q_out);
- readl(&ha->reg->rsp_q_out);
- spin_unlock_irqrestore(&ha->hardware_lock, flags);
- return QLA_SUCCESS;
- }
- /**
- * qla4xxx_validate_mac_address - validate adapter MAC address(es)
- * @ha: pointer to host adapter structure.
- *
- **/
- static int qla4xxx_validate_mac_address(struct scsi_qla_host *ha)
- {
- struct flash_sys_info *sys_info;
- dma_addr_t sys_info_dma;
- int status = QLA_ERROR;
- sys_info = dma_alloc_coherent(&ha->pdev->dev, sizeof(*sys_info),
- &sys_info_dma, GFP_KERNEL);
- if (sys_info == NULL) {
- DEBUG2(printk("scsi%ld: %s: Unable to allocate dma buffer.\n",
- ha->host_no, __func__));
- goto exit_validate_mac_no_free;
- }
- memset(sys_info, 0, sizeof(*sys_info));
- /* Get flash sys info */
- if (qla4xxx_get_flash(ha, sys_info_dma, FLASH_OFFSET_SYS_INFO,
- sizeof(*sys_info)) != QLA_SUCCESS) {
- DEBUG2(printk("scsi%ld: %s: get_flash FLASH_OFFSET_SYS_INFO "
- "failed\n", ha->host_no, __func__));
- goto exit_validate_mac;
- }
- /* Save M.A.C. address & serial_number */
- memcpy(ha->my_mac, &sys_info->physAddr[0].address[0],
- min(sizeof(ha->my_mac),
- sizeof(sys_info->physAddr[0].address)));
- memcpy(ha->serial_number, &sys_info->acSerialNumber,
- min(sizeof(ha->serial_number),
- sizeof(sys_info->acSerialNumber)));
- status = QLA_SUCCESS;
- exit_validate_mac:
- dma_free_coherent(&ha->pdev->dev, sizeof(*sys_info), sys_info,
- sys_info_dma);
- exit_validate_mac_no_free:
- return status;
- }
- /**
- * qla4xxx_init_local_data - initialize adapter specific local data
- * @ha: pointer to host adapter structure.
- *
- **/
- static int qla4xxx_init_local_data(struct scsi_qla_host *ha)
- {
- /* Initilize aen queue */
- ha->aen_q_count = MAX_AEN_ENTRIES;
- return qla4xxx_get_firmware_status(ha);
- }
- static int qla4xxx_fw_ready(struct scsi_qla_host *ha)
- {
- uint32_t timeout_count;
- int ready = 0;
- DEBUG2(dev_info(&ha->pdev->dev, "Waiting for Firmware Ready..\n"));
- for (timeout_count = ADAPTER_INIT_TOV; timeout_count > 0;
- timeout_count--) {
- if (test_and_clear_bit(DPC_GET_DHCP_IP_ADDR, &ha->dpc_flags))
- qla4xxx_get_dhcp_ip_address(ha);
- /* Get firmware state. */
- if (qla4xxx_get_firmware_state(ha) != QLA_SUCCESS) {
- DEBUG2(printk("scsi%ld: %s: unable to get firmware "
- "state\n", ha->host_no, __func__));
- break;
- }
- if (ha->firmware_state & FW_STATE_ERROR) {
- DEBUG2(printk("scsi%ld: %s: an unrecoverable error has"
- " occurred\n", ha->host_no, __func__));
- break;
- }
- if (ha->firmware_state & FW_STATE_CONFIG_WAIT) {
- /*
- * The firmware has not yet been issued an Initialize
- * Firmware command, so issue it now.
- */
- if (qla4xxx_initialize_fw_cb(ha) == QLA_ERROR)
- break;
- /* Go back and test for ready state - no wait. */
- continue;
- }
- if (ha->firmware_state == FW_STATE_READY) {
- DEBUG2(dev_info(&ha->pdev->dev, "Firmware Ready..\n"));
- /* The firmware is ready to process SCSI commands. */
- DEBUG2(dev_info(&ha->pdev->dev,
- "scsi%ld: %s: MEDIA TYPE - %s\n",
- ha->host_no,
- __func__, (ha->addl_fw_state &
- FW_ADDSTATE_OPTICAL_MEDIA)
- != 0 ? "OPTICAL" : "COPPER"));
- DEBUG2(dev_info(&ha->pdev->dev,
- "scsi%ld: %s: DHCP STATE Enabled "
- "%s\n",
- ha->host_no, __func__,
- (ha->addl_fw_state &
- FW_ADDSTATE_DHCP_ENABLED) != 0 ?
- "YES" : "NO"));
- DEBUG2(dev_info(&ha->pdev->dev,
- "scsi%ld: %s: LINK %s\n",
- ha->host_no, __func__,
- (ha->addl_fw_state &
- FW_ADDSTATE_LINK_UP) != 0 ?
- "UP" : "DOWN"));
- DEBUG2(dev_info(&ha->pdev->dev,
- "scsi%ld: %s: iSNS Service "
- "Started %s\n",
- ha->host_no, __func__,
- (ha->addl_fw_state &
- FW_ADDSTATE_ISNS_SVC_ENABLED) != 0 ?
- "YES" : "NO"));
- ready = 1;
- break;
- }
- DEBUG2(printk("scsi%ld: %s: waiting on fw, state=%x:%x - "
- "seconds expired= %d\n", ha->host_no, __func__,
- ha->firmware_state, ha->addl_fw_state,
- timeout_count));
- msleep(1000);
- } /* end of for */
- if (timeout_count <= 0)
- DEBUG2(printk("scsi%ld: %s: FW Initialization timed out!\n",
- ha->host_no, __func__));
- if (ha->firmware_state & FW_STATE_DHCP_IN_PROGRESS) {
- DEBUG2(printk("scsi%ld: %s: FW is reporting its waiting to"
- " grab an IP address from DHCP server\n",
- ha->host_no, __func__));
- ready = 1;
- }
- return ready;
- }
- /**
- * qla4xxx_init_firmware - initializes the firmware.
- * @ha: pointer to host adapter structure.
- *
- **/
- static int qla4xxx_init_firmware(struct scsi_qla_host *ha)
- {
- int status = QLA_ERROR;
- dev_info(&ha->pdev->dev, "Initializing firmware..\n");
- if (qla4xxx_initialize_fw_cb(ha) == QLA_ERROR) {
- DEBUG2(printk("scsi%ld: %s: Failed to initialize firmware "
- "control block\n", ha->host_no, __func__));
- return status;
- }
- if (!qla4xxx_fw_ready(ha))
- return status;
- set_bit(AF_ONLINE, &ha->flags);
- return qla4xxx_get_firmware_status(ha);
- }
- static struct ddb_entry* qla4xxx_get_ddb_entry(struct scsi_qla_host *ha,
- uint32_t fw_ddb_index)
- {
- struct dev_db_entry *fw_ddb_entry = NULL;
- dma_addr_t fw_ddb_entry_dma;
- struct ddb_entry *ddb_entry = NULL;
- int found = 0;
- uint32_t device_state;
- /* Make sure the dma buffer is valid */
- fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev,
- sizeof(*fw_ddb_entry),
- &fw_ddb_entry_dma, GFP_KERNEL);
- if (fw_ddb_entry == NULL) {
- DEBUG2(printk("scsi%ld: %s: Unable to allocate dma buffer.\n",
- ha->host_no, __func__));
- return NULL;
- }
- if (qla4xxx_get_fwddb_entry(ha, fw_ddb_index, fw_ddb_entry,
- fw_ddb_entry_dma, NULL, NULL,
- &device_state, NULL, NULL, NULL) ==
- QLA_ERROR) {
- DEBUG2(printk("scsi%ld: %s: failed get_ddb_entry for "
- "fw_ddb_index %d\n", ha->host_no, __func__,
- fw_ddb_index));
- return NULL;
- }
- /* Allocate DDB if not already allocated. */
- DEBUG2(printk("scsi%ld: %s: Looking for ddb[%d]\n", ha->host_no,
- __func__, fw_ddb_index));
- list_for_each_entry(ddb_entry, &ha->ddb_list, list) {
- if (memcmp(ddb_entry->iscsi_name, fw_ddb_entry->iscsiName,
- ISCSI_NAME_SIZE) == 0) {
- found++;
- break;
- }
- }
- if (!found) {
- DEBUG2(printk("scsi%ld: %s: ddb[%d] not found - allocating "
- "new ddb\n", ha->host_no, __func__,
- fw_ddb_index));
- ddb_entry = qla4xxx_alloc_ddb(ha, fw_ddb_index);
- }
- /* if not found allocate new ddb */
- dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry), fw_ddb_entry,
- fw_ddb_entry_dma);
- return ddb_entry;
- }
- /**
- * qla4xxx_update_ddb_entry - update driver's internal ddb
- * @ha: pointer to host adapter structure.
- * @ddb_entry: pointer to device database structure to be filled
- * @fw_ddb_index: index of the ddb entry in fw ddb table
- *
- * This routine updates the driver's internal device database entry
- * with information retrieved from the firmware's device database
- * entry for the specified device. The ddb_entry->fw_ddb_index field
- * must be initialized prior to calling this routine
- *
- **/
- int qla4xxx_update_ddb_entry(struct scsi_qla_host *ha,
- struct ddb_entry *ddb_entry,
- uint32_t fw_ddb_index)
- {
- struct dev_db_entry *fw_ddb_entry = NULL;
- dma_addr_t fw_ddb_entry_dma;
- int status = QLA_ERROR;
- if (ddb_entry == NULL) {
- DEBUG2(printk("scsi%ld: %s: ddb_entry is NULL\n", ha->host_no,
- __func__));
- goto exit_update_ddb;
- }
- /* Make sure the dma buffer is valid */
- fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev,
- sizeof(*fw_ddb_entry),
- &fw_ddb_entry_dma, GFP_KERNEL);
- if (fw_ddb_entry == NULL) {
- DEBUG2(printk("scsi%ld: %s: Unable to allocate dma buffer.\n",
- ha->host_no, __func__));
- goto exit_update_ddb;
- }
- if (qla4xxx_get_fwddb_entry(ha, fw_ddb_index, fw_ddb_entry,
- fw_ddb_entry_dma, NULL, NULL,
- &ddb_entry->fw_ddb_device_state, NULL,
- &ddb_entry->tcp_source_port_num,
- &ddb_entry->connection_id) ==
- QLA_ERROR) {
- DEBUG2(printk("scsi%ld: %s: failed get_ddb_entry for "
- "fw_ddb_index %d\n", ha->host_no, __func__,
- fw_ddb_index));
- goto exit_update_ddb;
- }
- status = QLA_SUCCESS;
- ddb_entry->target_session_id = le16_to_cpu(fw_ddb_entry->TSID);
- ddb_entry->task_mgmt_timeout =
- le16_to_cpu(fw_ddb_entry->taskMngmntTimeout);
- ddb_entry->CmdSn = 0;
- ddb_entry->exe_throttle = le16_to_cpu(fw_ddb_entry->exeThrottle);
- ddb_entry->default_relogin_timeout =
- le16_to_cpu(fw_ddb_entry->taskMngmntTimeout);
- ddb_entry->default_time2wait = le16_to_cpu(fw_ddb_entry->minTime2Wait);
- /* Update index in case it changed */
- ddb_entry->fw_ddb_index = fw_ddb_index;
- ha->fw_ddb_index_map[fw_ddb_index] = ddb_entry;
- ddb_entry->port = le16_to_cpu(fw_ddb_entry->portNumber);
- ddb_entry->tpgt = le32_to_cpu(fw_ddb_entry->TargetPortalGroup);
- memcpy(&ddb_entry->iscsi_name[0], &fw_ddb_entry->iscsiName[0],
- min(sizeof(ddb_entry->iscsi_name),
- sizeof(fw_ddb_entry->iscsiName)));
- memcpy(&ddb_entry->ip_addr[0], &fw_ddb_entry->ipAddr[0],
- min(sizeof(ddb_entry->ip_addr), sizeof(fw_ddb_entry->ipAddr)));
- DEBUG2(printk("scsi%ld: %s: ddb[%d] - State= %x status= %d.\n",
- ha->host_no, __func__, fw_ddb_index,
- ddb_entry->fw_ddb_device_state, status));
- exit_update_ddb:
- if (fw_ddb_entry)
- dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
- fw_ddb_entry, fw_ddb_entry_dma);
- return status;
- }
- /**
- * qla4xxx_alloc_ddb - allocate device database entry
- * @ha: Pointer to host adapter structure.
- * @fw_ddb_index: Firmware's device database index
- *
- * This routine allocates a ddb_entry, ititializes some values, and
- * inserts it into the ddb list.
- **/
- struct ddb_entry * qla4xxx_alloc_ddb(struct scsi_qla_host *ha,
- uint32_t fw_ddb_index)
- {
- struct ddb_entry *ddb_entry;
- DEBUG2(printk("scsi%ld: %s: fw_ddb_index [%d]\n", ha->host_no,
- __func__, fw_ddb_index));
- ddb_entry = qla4xxx_alloc_sess(ha);
- if (ddb_entry == NULL) {
- DEBUG2(printk("scsi%ld: %s: Unable to allocate memory "
- "to add fw_ddb_index [%d]\n",
- ha->host_no, __func__, fw_ddb_index));
- return ddb_entry;
- }
- ddb_entry->fw_ddb_index = fw_ddb_index;
- atomic_set(&ddb_entry->port_down_timer, ha->port_down_retry_count);
- atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
- atomic_set(&ddb_entry->relogin_timer, 0);
- atomic_set(&ddb_entry->relogin_retry_count, 0);
- atomic_set(&ddb_entry->state, DDB_STATE_ONLINE);
- list_add_tail(&ddb_entry->list, &ha->ddb_list);
- ha->fw_ddb_index_map[fw_ddb_index] = ddb_entry;
- ha->tot_ddbs++;
- return ddb_entry;
- }
- /**
- * qla4xxx_configure_ddbs - builds driver ddb list
- * @ha: Pointer to host adapter structure.
- *
- * This routine searches for all valid firmware ddb entries and builds
- * an internal ddb list. Ddbs that are considered valid are those with
- * a device state of SESSION_ACTIVE.
- **/
- static int qla4xxx_build_ddb_list(struct scsi_qla_host *ha)
- {
- int status = QLA_SUCCESS;
- uint32_t fw_ddb_index = 0;
- uint32_t next_fw_ddb_index = 0;
- uint32_t ddb_state;
- uint32_t conn_err, err_code;
- struct ddb_entry *ddb_entry;
- dev_info(&ha->pdev->dev, "Initializing DDBs ...\n");
- for (fw_ddb_index = 0; fw_ddb_index < MAX_DDB_ENTRIES;
- fw_ddb_index = next_fw_ddb_index) {
- /* First, let's see if a device exists here */
- if (qla4xxx_get_fwddb_entry(ha, fw_ddb_index, NULL, 0, NULL,
- &next_fw_ddb_index, &ddb_state,
- &conn_err, NULL, NULL) ==
- QLA_ERROR) {
- DEBUG2(printk("scsi%ld: %s: get_ddb_entry, "
- "fw_ddb_index %d failed", ha->host_no,
- __func__, fw_ddb_index));
- return QLA_ERROR;
- }
- DEBUG2(printk("scsi%ld: %s: Getting DDB[%d] ddbstate=0x%x, "
- "next_fw_ddb_index=%d.\n", ha->host_no, __func__,
- fw_ddb_index, ddb_state, next_fw_ddb_index));
- /* Issue relogin, if necessary. */
- if (ddb_state == DDB_DS_SESSION_FAILED ||
- ddb_state == DDB_DS_NO_CONNECTION_ACTIVE) {
- /* Try and login to device */
- DEBUG2(printk("scsi%ld: %s: Login to DDB[%d]\n",
- ha->host_no, __func__, fw_ddb_index));
- err_code = ((conn_err & 0x00ff0000) >> 16);
- if (err_code == 0x1c || err_code == 0x06) {
- DEBUG2(printk("scsi%ld: %s send target "
- "completed "
- "or access denied failure\n",
- ha->host_no, __func__));
- } else
- qla4xxx_set_ddb_entry(ha, fw_ddb_index, 0);
- }
- if (ddb_state != DDB_DS_SESSION_ACTIVE)
- goto next_one;
- /*
- * if fw_ddb with session active state found,
- * add to ddb_list
- */
- DEBUG2(printk("scsi%ld: %s: DDB[%d] added to list\n",
- ha->host_no, __func__, fw_ddb_index));
- /* Add DDB to internal our ddb list. */
- ddb_entry = qla4xxx_get_ddb_entry(ha, fw_ddb_index);
- if (ddb_entry == NULL) {
- DEBUG2(printk("scsi%ld: %s: Unable to allocate memory "
- "for device at fw_ddb_index %d\n",
- ha->host_no, __func__, fw_ddb_index));
- return QLA_ERROR;
- }
- /* Fill in the device structure */
- if (qla4xxx_update_ddb_entry(ha, ddb_entry, fw_ddb_index) ==
- QLA_ERROR) {
- ha->fw_ddb_index_map[fw_ddb_index] =
- (struct ddb_entry *)INVALID_ENTRY;
- DEBUG2(printk("scsi%ld: %s: update_ddb_entry failed "
- "for fw_ddb_index %d.\n",
- ha->host_no, __func__, fw_ddb_index));
- return QLA_ERROR;
- }
- next_one:
- /* We know we've reached the last device when
- * next_fw_ddb_index is 0 */
- if (next_fw_ddb_index == 0)
- break;
- }
- dev_info(&ha->pdev->dev, "DDB list done..\n");
- return status;
- }
- struct qla4_relog_scan {
- int halt_wait;
- uint32_t conn_err;
- uint32_t err_code;
- uint32_t fw_ddb_index;
- uint32_t next_fw_ddb_index;
- uint32_t fw_ddb_device_state;
- };
- static int qla4_test_rdy(struct scsi_qla_host *ha, struct qla4_relog_scan *rs)
- {
- struct ddb_entry *ddb_entry;
- /*
- * Don't want to do a relogin if connection
- * error is 0x1c.
- */
- rs->err_code = ((rs->conn_err & 0x00ff0000) >> 16);
- if (rs->err_code == 0x1c || rs->err_code == 0x06) {
- DEBUG2(printk(
- "scsi%ld: %s send target"
- " completed or "
- "access denied failure\n",
- ha->host_no, __func__));
- } else {
- /* We either have a device that is in
- * the process of relogging in or a
- * device that is waiting to be
- * relogged in */
- rs->halt_wait = 0;
- ddb_entry = qla4xxx_lookup_ddb_by_fw_index(ha,
- rs->fw_ddb_index);
- if (ddb_entry == NULL)
- return QLA_ERROR;
- if (ddb_entry->dev_scan_wait_to_start_relogin != 0
- && time_after_eq(jiffies,
- ddb_entry->
- dev_scan_wait_to_start_relogin))
- {
- ddb_entry->dev_scan_wait_to_start_relogin = 0;
- qla4xxx_set_ddb_entry(ha, rs->fw_ddb_index, 0);
- }
- }
- return QLA_SUCCESS;
- }
- static int qla4_scan_for_relogin(struct scsi_qla_host *ha,
- struct qla4_relog_scan *rs)
- {
- int error;
- /* scan for relogins
- * ----------------- */
- for (rs->fw_ddb_index = 0; rs->fw_ddb_index < MAX_DDB_ENTRIES;
- rs->fw_ddb_index = rs->next_fw_ddb_index) {
- if (qla4xxx_get_fwddb_entry(ha, rs->fw_ddb_index, NULL, 0,
- NULL, &rs->next_fw_ddb_index,
- &rs->fw_ddb_device_state,
- &rs->conn_err, NULL, NULL)
- == QLA_ERROR)
- return QLA_ERROR;
- if (rs->fw_ddb_device_state == DDB_DS_LOGIN_IN_PROCESS)
- rs->halt_wait = 0;
- if (rs->fw_ddb_device_state == DDB_DS_SESSION_FAILED ||
- rs->fw_ddb_device_state == DDB_DS_NO_CONNECTION_ACTIVE) {
- error = qla4_test_rdy(ha, rs);
- if (error)
- return error;
- }
- /* We know we've reached the last device when
- * next_fw_ddb_index is 0 */
- if (rs->next_fw_ddb_index == 0)
- break;
- }
- return QLA_SUCCESS;
- }
- /**
- * qla4xxx_devices_ready - wait for target devices to be logged in
- * @ha: pointer to adapter structure
- *
- * This routine waits up to ql4xdiscoverywait seconds
- * F/W database during driver load time.
- **/
- static int qla4xxx_devices_ready(struct scsi_qla_host *ha)
- {
- int error;
- unsigned long discovery_wtime;
- struct qla4_relog_scan rs;
- discovery_wtime = jiffies + (ql4xdiscoverywait * HZ);
- DEBUG(printk("Waiting (%d) for devices ...\n", ql4xdiscoverywait));
- do {
- /* poll for AEN. */
- qla4xxx_get_firmware_state(ha);
- if (test_and_clear_bit(DPC_AEN, &ha->dpc_flags)) {
- /* Set time-between-relogin timer */
- qla4xxx_process_aen(ha, RELOGIN_DDB_CHANGED_AENS);
- }
- /* if no relogins active or needed, halt discvery wait */
- rs.halt_wait = 1;
- error = qla4_scan_for_relogin(ha, &rs);
- if (rs.halt_wait) {
- DEBUG2(printk("scsi%ld: %s: Delay halted. Devices "
- "Ready.\n", ha->host_no, __func__));
- return QLA_SUCCESS;
- }
- msleep(2000);
- } while (!time_after_eq(jiffies, discovery_wtime));
- DEBUG3(qla4xxx_get_conn_event_log(ha));
- return QLA_SUCCESS;
- }
- static void qla4xxx_flush_AENS(struct scsi_qla_host *ha)
- {
- unsigned long wtime;
- /* Flush the 0x8014 AEN from the firmware as a result of
- * Auto connect. We are basically doing get_firmware_ddb()
- * to determine whether we need to log back in or not.
- * Trying to do a set ddb before we have processed 0x8014
- * will result in another set_ddb() for the same ddb. In other
- * words there will be stale entries in the aen_q.
- */
- wtime = jiffies + (2 * HZ);
- do {
- if (qla4xxx_get_firmware_state(ha) == QLA_SUCCESS)
- if (ha->firmware_state & (BIT_2 | BIT_0))
- return;
- if (test_and_clear_bit(DPC_AEN, &ha->dpc_flags))
- qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
- msleep(1000);
- } while (!time_after_eq(jiffies, wtime));
- }
- static int qla4xxx_initialize_ddb_list(struct scsi_qla_host *ha)
- {
- uint16_t fw_ddb_index;
- int status = QLA_SUCCESS;
- /* free the ddb list if is not empty */
- if (!list_empty(&ha->ddb_list))
- qla4xxx_free_ddb_list(ha);
- for (fw_ddb_index = 0; fw_ddb_index < MAX_DDB_ENTRIES; fw_ddb_index++)
- ha->fw_ddb_index_map[fw_ddb_index] =
- (struct ddb_entry *)INVALID_ENTRY;
- ha->tot_ddbs = 0;
- qla4xxx_flush_AENS(ha);
- /*
- * First perform device discovery for active
- * fw ddb indexes and build
- * ddb list.
- */
- if ((status = qla4xxx_build_ddb_list(ha)) == QLA_ERROR)
- return status;
- /* Wait for an AEN */
- qla4xxx_devices_ready(ha);
- /*
- * Targets can come online after the inital discovery, so processing
- * the aens here will catch them.
- */
- if (test_and_clear_bit(DPC_AEN, &ha->dpc_flags))
- qla4xxx_process_aen(ha, PROCESS_ALL_AENS);
- return status;
- }
- /**
- * qla4xxx_update_ddb_list - update the driver ddb list
- * @ha: pointer to host adapter structure.
- *
- * This routine obtains device information from the F/W database after
- * firmware or adapter resets. The device table is preserved.
- **/
- int qla4xxx_reinitialize_ddb_list(struct scsi_qla_host *ha)
- {
- int status = QLA_SUCCESS;
- struct ddb_entry *ddb_entry, *detemp;
- /* Update the device information for all devices. */
- list_for_each_entry_safe(ddb_entry, detemp, &ha->ddb_list, list) {
- qla4xxx_update_ddb_entry(ha, ddb_entry,
- ddb_entry->fw_ddb_index);
- if (ddb_entry->fw_ddb_device_state == DDB_DS_SESSION_ACTIVE) {
- atomic_set(&ddb_entry->state, DDB_STATE_ONLINE);
- DEBUG2(printk ("scsi%ld: %s: ddb index [%d] marked "
- "ONLINE\n", ha->host_no, __func__,
- ddb_entry->fw_ddb_index));
- } else if (atomic_read(&ddb_entry->state) == DDB_STATE_ONLINE)
- qla4xxx_mark_device_missing(ha, ddb_entry);
- }
- return status;
- }
- /**
- * qla4xxx_relogin_device - re-establish session
- * @ha: Pointer to host adapter structure.
- * @ddb_entry: Pointer to device database entry
- *
- * This routine does a session relogin with the specified device.
- * The ddb entry must be assigned prior to making this call.
- **/
- int qla4xxx_relogin_device(struct scsi_qla_host *ha,
- struct ddb_entry * ddb_entry)
- {
- uint16_t relogin_timer;
- relogin_timer = max(ddb_entry->default_relogin_timeout,
- (uint16_t)RELOGIN_TOV);
- atomic_set(&ddb_entry->relogin_timer, relogin_timer);
- DEBUG2(printk("scsi%ld: Relogin index [%d]. TOV=%d\n", ha->host_no,
- ddb_entry->fw_ddb_index, relogin_timer));
- qla4xxx_set_ddb_entry(ha, ddb_entry->fw_ddb_index, 0);
- return QLA_SUCCESS;
- }
- /**
- * qla4010_get_topcat_presence - check if it is QLA4040 TopCat Chip
- * @ha: Pointer to host adapter structure.
- *
- **/
- static int qla4010_get_topcat_presence(struct scsi_qla_host *ha)
- {
- unsigned long flags;
- uint16_t topcat;
- if (ql4xxx_lock_nvram(ha) != QLA_SUCCESS)
- return QLA_ERROR;
- spin_lock_irqsave(&ha->hardware_lock, flags);
- topcat = rd_nvram_word(ha, offsetof(struct eeprom_data,
- isp4010.topcat));
- spin_unlock_irqrestore(&ha->hardware_lock, flags);
- if ((topcat & TOPCAT_MASK) == TOPCAT_PRESENT)
- set_bit(AF_TOPCAT_CHIP_PRESENT, &ha->flags);
- else
- clear_bit(AF_TOPCAT_CHIP_PRESENT, &ha->flags);
- ql4xxx_unlock_nvram(ha);
- return QLA_SUCCESS;
- }
- static int qla4xxx_config_nvram(struct scsi_qla_host *ha)
- {
- unsigned long flags;
- union external_hw_config_reg extHwConfig;
- DEBUG2(printk("scsi%ld: %s: Get EEProm parameters \n", ha->host_no,
- __func__));
- if (ql4xxx_lock_flash(ha) != QLA_SUCCESS)
- return (QLA_ERROR);
- if (ql4xxx_lock_nvram(ha) != QLA_SUCCESS) {
- ql4xxx_unlock_flash(ha);
- return (QLA_ERROR);
- }
- /* Get EEPRom Parameters from NVRAM and validate */
- dev_info(&ha->pdev->dev, "Configuring NVRAM ...\n");
- if (qla4xxx_is_nvram_configuration_valid(ha) == QLA_SUCCESS) {
- spin_lock_irqsave(&ha->hardware_lock, flags);
- extHwConfig.Asuint32_t =
- rd_nvram_word(ha, eeprom_ext_hw_conf_offset(ha));
- spin_unlock_irqrestore(&ha->hardware_lock, flags);
- } else {
- /*
- * QLogic adapters should always have a valid NVRAM.
- * If not valid, do not load.
- */
- dev_warn(&ha->pdev->dev,
- "scsi%ld: %s: EEProm checksum invalid. "
- "Please update your EEPROM\n", ha->host_no,
- __func__);
- /* set defaults */
- if (is_qla4010(ha))
- extHwConfig.Asuint32_t = 0x1912;
- else if (is_qla4022(ha))
- extHwConfig.Asuint32_t = 0x0023;
- }
- DEBUG(printk("scsi%ld: %s: Setting extHwConfig to 0xFFFF%04x\n",
- ha->host_no, __func__, extHwConfig.Asuint32_t));
- spin_lock_irqsave(&ha->hardware_lock, flags);
- writel((0xFFFF << 16) | extHwConfig.Asuint32_t, isp_ext_hw_conf(ha));
- readl(isp_ext_hw_conf(ha));
- spin_unlock_irqrestore(&ha->hardware_lock, flags);
- ql4xxx_unlock_nvram(ha);
- ql4xxx_unlock_flash(ha);
- return (QLA_SUCCESS);
- }
- static void qla4x00_pci_config(struct scsi_qla_host *ha)
- {
- uint16_t w, mwi;
- dev_info(&ha->pdev->dev, "Configuring PCI space...\n");
- pci_set_master(ha->pdev);
- mwi = 0;
- if (pci_set_mwi(ha->pdev))
- mwi = PCI_COMMAND_INVALIDATE;
- /*
- * We want to respect framework's setting of PCI configuration space
- * command register and also want to make sure that all bits of
- * interest to us are properly set in command register.
- */
- pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
- w |= mwi | (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
- w &= ~PCI_COMMAND_INTX_DISABLE;
- pci_write_config_word(ha->pdev, PCI_COMMAND, w);
- }
- static int qla4xxx_start_firmware_from_flash(struct scsi_qla_host *ha)
- {
- int status = QLA_ERROR;
- uint32_t max_wait_time;
- unsigned long flags;
- uint32_t mbox_status;
- dev_info(&ha->pdev->dev, "Starting firmware ...\n");
- /*
- * Start firmware from flash ROM
- *
- * WORKAROUND: Stuff a non-constant value that the firmware can
- * use as a seed for a random number generator in MB7 prior to
- * setting BOOT_ENABLE. Fixes problem where the TCP
- * connections use the same TCP ports after each reboot,
- * causing some connections to not get re-established.
- */
- DEBUG(printk("scsi%d: %s: Start firmware from flash ROM\n",
- ha->host_no, __func__));
- spin_lock_irqsave(&ha->hardware_lock, flags);
- writel(jiffies, &ha->reg->mailbox[7]);
- if (is_qla4022(ha))
- writel(set_rmask(NVR_WRITE_ENABLE),
- &ha->reg->u1.isp4022.nvram);
- writel(set_rmask(CSR_BOOT_ENABLE), &ha->reg->ctrl_status);
- readl(&ha->reg->ctrl_status);
- spin_unlock_irqrestore(&ha->hardware_lock, flags);
- /* Wait for firmware to come UP. */
- max_wait_time = FIRMWARE_UP_TOV * 4;
- do {
- uint32_t ctrl_status;
- spin_lock_irqsave(&ha->hardware_lock, flags);
- ctrl_status = readw(&ha->reg->ctrl_status);
- mbox_status = readw(&ha->reg->mailbox[0]);
- spin_unlock_irqrestore(&ha->hardware_lock, flags);
- if (ctrl_status & set_rmask(CSR_SCSI_PROCESSOR_INTR))
- break;
- if (mbox_status == MBOX_STS_COMMAND_COMPLETE)
- break;
- DEBUG2(printk("scsi%ld: %s: Waiting for boot firmware to "
- "complete... ctrl_sts=0x%x, remaining=%d\n",
- ha->host_no, __func__, ctrl_status,
- max_wait_time));
- msleep(250);
- } while ((max_wait_time--));
- if (mbox_status == MBOX_STS_COMMAND_COMPLETE) {
- DEBUG(printk("scsi%ld: %s: Firmware has started\n",
- ha->host_no, __func__));
- spin_lock_irqsave(&ha->hardware_lock, flags);
- writel(set_rmask(CSR_SCSI_PROCESSOR_INTR),
- &ha->reg->ctrl_status);
- readl(&ha->reg->ctrl_status);
- spin_unlock_irqrestore(&ha->hardware_lock, flags);
- status = QLA_SUCCESS;
- } else {
- printk(KERN_INFO "scsi%ld: %s: Boot firmware failed "
- "- mbox status 0x%x\n", ha->host_no, __func__,
- mbox_status);
- status = QLA_ERROR;
- }
- return status;
- }
- static int ql4xxx_lock_drvr_wait(struct scsi_qla_host *a)
- {
- #define QL4_LOCK_DRVR_WAIT 300
- #define QL4_LOCK_DRVR_SLEEP 100
- int drvr_wait = QL4_LOCK_DRVR_WAIT;
- while (drvr_wait) {
- if (ql4xxx_lock_drvr(a) == 0) {
- msleep(QL4_LOCK_DRVR_SLEEP);
- if (drvr_wait) {
- DEBUG2(printk("scsi%ld: %s: Waiting for "
- "Global Init Semaphore...n",
- a->host_no,
- __func__));
- }
- drvr_wait -= QL4_LOCK_DRVR_SLEEP;
- } else {
- DEBUG2(printk("scsi%ld: %s: Global Init Semaphore "
- "acquired.n", a->host_no, __func__));
- return QLA_SUCCESS;
- }
- }
- return QLA_ERROR;
- }
- /**
- * qla4xxx_start_firmware - starts qla4xxx firmware
- * @ha: Pointer to host adapter structure.
- *
- * This routine performs the neccessary steps to start the firmware for
- * the QLA4010 adapter.
- **/
- static int qla4xxx_start_firmware(struct scsi_qla_host *ha)
- {
- unsigned long flags = 0;
- uint32_t mbox_status;
- int status = QLA_ERROR;
- int soft_reset = 1;
- int config_chip = 0;
- if (is_qla4010(ha)){
- if (qla4010_get_topcat_presence(ha) != QLA_SUCCESS)
- return QLA_ERROR;
- }
- if (is_qla4022(ha))
- ql4xxx_set_mac_number(ha);
- if (ql4xxx_lock_drvr_wait(ha) != QLA_SUCCESS)
- return QLA_ERROR;
- spin_lock_irqsave(&ha->hardware_lock, flags);
- DEBUG2(printk("scsi%ld: %s: port_ctrl = 0x%08X\n", ha->host_no,
- __func__, readw(isp_port_ctrl(ha))));
- DEBUG(printk("scsi%ld: %s: port_status = 0x%08X\n", ha->host_no,
- __func__, readw(isp_port_status(ha))));
- /* Is Hardware already initialized? */
- if ((readw(isp_port_ctrl(ha)) & 0x8000) != 0) {
- DEBUG(printk("scsi%ld: %s: Hardware has already been "
- "initialized\n", ha->host_no, __func__));
- /* Receive firmware boot acknowledgement */
- mbox_status = readw(&ha->reg->mailbox[0]);
- DEBUG2(printk("scsi%ld: %s: H/W Config complete - mbox[0]= "
- "0x%x\n", ha->host_no, __func__, mbox_status));
- /* Is firmware already booted? */
- if (mbox_status == 0) {
- /* F/W not running, must be config by net driver */
- config_chip = 1;
- soft_reset = 0;
- } else {
- writel(set_rmask(CSR_SCSI_PROCESSOR_INTR),
- &ha->reg->ctrl_status);
- readl(&ha->reg->ctrl_status);
- spin_unlock_irqrestore(&ha->hardware_lock, flags);
- if (qla4xxx_get_firmware_state(ha) == QLA_SUCCESS) {
- DEBUG2(printk("scsi%ld: %s: Get firmware "
- "state -- state = 0x%x\n",
- ha->host_no,
- __func__, ha->firmware_state));
- /* F/W is running */
- if (ha->firmware_state &
- FW_STATE_CONFIG_WAIT) {
- DEBUG2(printk("scsi%ld: %s: Firmware "
- "in known state -- "
- "config and "
- "boot, state = 0x%x\n",
- ha->host_no, __func__,
- ha->firmware_state));
- config_chip = 1;
- soft_reset = 0;
- }
- } else {
- DEBUG2(printk("scsi%ld: %s: Firmware in "
- "unknown state -- resetting,"
- " state = "
- "0x%x\n", ha->host_no, __func__,
- ha->firmware_state));
- }
- spin_lock_irqsave(&ha->hardware_lock, flags);
- }
- } else {
- DEBUG(printk("scsi%ld: %s: H/W initialization hasn't been "
- "started - resetting\n", ha->host_no, __func__));
- }
- spin_unlock_irqrestore(&ha->hardware_lock, flags);
- DEBUG(printk("scsi%ld: %s: Flags soft_rest=%d, config= %d\n ",
- ha->host_no, __func__, soft_reset, config_chip));
- if (soft_reset) {
- DEBUG(printk("scsi%ld: %s: Issue Soft Reset\n", ha->host_no,
- __func__));
- status = qla4xxx_soft_reset(ha);
- if (status == QLA_ERROR) {
- DEBUG(printk("scsi%d: %s: Soft Reset failed!\n",
- ha->host_no, __func__));
- ql4xxx_unlock_drvr(ha);
- return QLA_ERROR;
- }
- config_chip = 1;
- /* Reset clears the semaphore, so aquire again */
- if (ql4xxx_lock_drvr_wait(ha) != QLA_SUCCESS)
- return QLA_ERROR;
- }
- if (config_chip) {
- if ((status = qla4xxx_config_nvram(ha)) == QLA_SUCCESS)
- status = qla4xxx_start_firmware_from_flash(ha);
- }
- ql4xxx_unlock_drvr(ha);
- if (status == QLA_SUCCESS) {
- qla4xxx_get_fw_version(ha);
- if (test_and_clear_bit(AF_GET_CRASH_RECORD, &ha->flags))
- qla4xxx_get_crash_record(ha);
- } else {
- DEBUG(printk("scsi%ld: %s: Firmware has NOT started\n",
- ha->host_no, __func__));
- }
- return status;
- }
- /**
- * qla4xxx_initialize_adapter - initiailizes hba
- * @ha: Pointer to host adapter structure.
- * @renew_ddb_list: Indicates what to do with the adapter's ddb list
- * after adapter recovery has completed.
- * 0=preserve ddb list, 1=destroy and rebuild ddb list
- *
- * This routine parforms all of the steps necessary to initialize the adapter.
- *
- **/
- int qla4xxx_initialize_adapter(struct scsi_qla_host *ha,
- uint8_t renew_ddb_list)
- {
- int status = QLA_ERROR;
- int8_t ip_address[IP_ADDR_LEN] = {0} ;
- ha->eeprom_cmd_data = 0;
- qla4x00_pci_config(ha);
- qla4xxx_disable_intrs(ha);
- /* Initialize the Host adapter request/response queues and firmware */
- if (qla4xxx_start_firmware(ha) == QLA_ERROR)
- return status;
- if (qla4xxx_validate_mac_address(ha) == QLA_ERROR)
- return status;
- if (qla4xxx_init_local_data(ha) == QLA_ERROR)
- return status;
- status = qla4xxx_init_firmware(ha);
- if (status == QLA_ERROR)
- return status;
- /*
- * FW is waiting to get an IP address from DHCP server: Skip building
- * the ddb_list and wait for DHCP lease acquired aen to come in
- * followed by 0x8014 aen" to trigger the tgt discovery process.
- */
- if (ha->firmware_state & FW_STATE_DHCP_IN_PROGRESS)
- return status;
- /* Skip device discovery if ip and subnet is zero */
- if (memcmp(ha->ip_address, ip_address, IP_ADDR_LEN) == 0 ||
- memcmp(ha->subnet_mask, ip_address, IP_ADDR_LEN) == 0)
- return status;
- if (renew_ddb_list == PRESERVE_DDB_LIST) {
- /*
- * We want to preserve lun states (i.e. suspended, etc.)
- * for recovery initiated by the driver. So just update
- * the device states for the existing ddb_list.
- */
- qla4xxx_reinitialize_ddb_list(ha);
- } else if (renew_ddb_list == REBUILD_DDB_LIST) {
- /*
- * We want to build the ddb_list from scratch during
- * driver initialization and recovery initiated by the
- * INT_HBA_RESET IOCTL.
- */
- status = qla4xxx_initialize_ddb_list(ha);
- if (status == QLA_ERROR) {
- DEBUG2(printk("%s(%ld) Error occurred during build"
- "ddb list\n", __func__, ha->host_no));
- goto exit_init_hba;
- }
- }
- if (!ha->tot_ddbs) {
- DEBUG2(printk("scsi%ld: Failed to initialize devices or none "
- "present in Firmware device database\n",
- ha->host_no));
- }
- exit_init_hba:
- return status;
- }
- /**
- * qla4xxx_add_device_dynamically - ddb addition due to an AEN
- * @ha: Pointer to host adapter structure.
- * @fw_ddb_index: Firmware's device database index
- *
- * This routine processes adds a device as a result of an 8014h AEN.
- **/
- static void qla4xxx_add_device_dynamically(struct scsi_qla_host *ha,
- uint32_t fw_ddb_index)
- {
- struct ddb_entry * ddb_entry;
- /* First allocate a device structure */
- ddb_entry = qla4xxx_get_ddb_entry(ha, fw_ddb_index);
- if (ddb_entry == NULL) {
- DEBUG2(printk(KERN_WARNING
- "scsi%ld: Unable to allocate memory to add "
- "fw_ddb_index %d\n", ha->host_no, fw_ddb_index));
- return;
- }
- if (qla4xxx_update_ddb_entry(ha, ddb_entry, fw_ddb_index) ==
- QLA_ERROR) {
- ha->fw_ddb_index_map[fw_ddb_index] =
- (struct ddb_entry *)INVALID_ENTRY;
- DEBUG2(printk(KERN_WARNING
- "scsi%ld: failed to add new device at index "
- "[%d]\n Unable to retrieve fw ddb entry\n",
- ha->host_no, fw_ddb_index));
- qla4xxx_free_ddb(ha, ddb_entry);
- return;
- }
- if (qla4xxx_add_sess(ddb_entry)) {
- DEBUG2(printk(KERN_WARNING
- "scsi%ld: failed to add new device at index "
- "[%d]\n Unable to add connection and session\n",
- ha->host_no, fw_ddb_index));
- qla4xxx_free_ddb(ha, ddb_entry);
- }
- }
- /**
- * qla4xxx_process_ddb_changed - process ddb state change
- * @ha - Pointer to host adapter structure.
- * @fw_ddb_index - Firmware's device database index
- * @state - Device state
- *
- * This routine processes a Decive Database Changed AEN Event.
- **/
- int qla4xxx_process_ddb_changed(struct scsi_qla_host *ha,
- uint32_t fw_ddb_index, uint32_t state)
- {
- struct ddb_entry * ddb_entry;
- uint32_t old_fw_ddb_device_state;
- /* check for out of range index */
- if (fw_ddb_index >= MAX_DDB_ENTRIES)
- return QLA_ERROR;
- /* Get the corresponging ddb entry */
- ddb_entry = qla4xxx_lookup_ddb_by_fw_index(ha, fw_ddb_index);
- /* Device does not currently exist in our database. */
- if (ddb_entry == NULL) {
- if (state == DDB_DS_SESSION_ACTIVE)
- qla4xxx_add_device_dynamically(ha, fw_ddb_index);
- return QLA_SUCCESS;
- }
- /* Device already exists in our database. */
- old_fw_ddb_device_state = ddb_entry->fw_ddb_device_state;
- DEBUG2(printk("scsi%ld: %s DDB - old state= 0x%x, new state=0x%x for "
- "index [%d]\n", ha->host_no, __func__,
- ddb_entry->fw_ddb_device_state, state, fw_ddb_index));
- if (old_fw_ddb_device_state == state &&
- state == DDB_DS_SESSION_ACTIVE) {
- /* Do nothing, state not changed. */
- return QLA_SUCCESS;
- }
- ddb_entry->fw_ddb_device_state = state;
- /* Device is back online. */
- if (ddb_entry->fw_ddb_device_state == DDB_DS_SESSION_ACTIVE) {
- atomic_set(&ddb_entry->port_down_timer,
- ha->port_down_retry_count);
- atomic_set(&ddb_entry->state, DDB_STATE_ONLINE);
- atomic_set(&ddb_entry->relogin_retry_count, 0);
- atomic_set(&ddb_entry->relogin_timer, 0);
- clear_bit(DF_RELOGIN, &ddb_entry->flags);
- clear_bit(DF_NO_RELOGIN, &ddb_entry->flags);
- iscsi_if_create_session_done(ddb_entry->conn);
- /*
- * Change the lun state to READY in case the lun TIMEOUT before
- * the device came back.
- */
- } else {
- /* Device went away, try to relogin. */
- /* Mark device missing */
- if (atomic_read(&ddb_entry->state) == DDB_STATE_ONLINE)
- qla4xxx_mark_device_missing(ha, ddb_entry);
- /*
- * Relogin if device state changed to a not active state.
- * However, do not relogin if this aen is a result of an IOCTL
- * logout (DF_NO_RELOGIN) or if this is a discovered device.
- */
- if (ddb_entry->fw_ddb_device_state == DDB_DS_SESSION_FAILED &&
- !test_bit(DF_RELOGIN, &ddb_entry->flags) &&
- !test_bit(DF_NO_RELOGIN, &ddb_entry->flags) &&
- !test_bit(DF_ISNS_DISCOVERED, &ddb_entry->flags)) {
- /*
- * This triggers a relogin. After the relogin_timer
- * expires, the relogin gets scheduled. We must wait a
- * minimum amount of time since receiving an 0x8014 AEN
- * with failed device_state or a logout response before
- * we can issue another relogin.
- */
- /* Firmware padds this timeout: (time2wait +1).
- * Driver retry to login should be longer than F/W.
- * Otherwise F/W will fail
- * set_ddb() mbx cmd with 0x4005 since it still
- * counting down its time2wait.
- */
- atomic_set(&ddb_entry->relogin_timer, 0);
- atomic_set(&ddb_entry->retry_relogin_timer,
- ddb_entry->default_time2wait + 4);
- }
- }
- return QLA_SUCCESS;
- }
|