18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */ 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * QLogic iSCSI HBA Driver 48c2ecf20Sopenharmony_ci * Copyright (c) 2003-2013 QLogic Corporation 58c2ecf20Sopenharmony_ci */ 68c2ecf20Sopenharmony_ci 78c2ecf20Sopenharmony_ci/* 88c2ecf20Sopenharmony_ci * 98c2ecf20Sopenharmony_ci * qla4xxx_lookup_ddb_by_fw_index 108c2ecf20Sopenharmony_ci * This routine locates a device handle given the firmware device 118c2ecf20Sopenharmony_ci * database index. If device doesn't exist, returns NULL. 128c2ecf20Sopenharmony_ci * 138c2ecf20Sopenharmony_ci * Input: 148c2ecf20Sopenharmony_ci * ha - Pointer to host adapter structure. 158c2ecf20Sopenharmony_ci * fw_ddb_index - Firmware's device database index 168c2ecf20Sopenharmony_ci * 178c2ecf20Sopenharmony_ci * Returns: 188c2ecf20Sopenharmony_ci * Pointer to the corresponding internal device database structure 198c2ecf20Sopenharmony_ci */ 208c2ecf20Sopenharmony_cistatic inline struct ddb_entry * 218c2ecf20Sopenharmony_ciqla4xxx_lookup_ddb_by_fw_index(struct scsi_qla_host *ha, uint32_t fw_ddb_index) 228c2ecf20Sopenharmony_ci{ 238c2ecf20Sopenharmony_ci struct ddb_entry *ddb_entry = NULL; 248c2ecf20Sopenharmony_ci 258c2ecf20Sopenharmony_ci if ((fw_ddb_index < MAX_DDB_ENTRIES) && 268c2ecf20Sopenharmony_ci (ha->fw_ddb_index_map[fw_ddb_index] != 278c2ecf20Sopenharmony_ci (struct ddb_entry *) INVALID_ENTRY)) { 288c2ecf20Sopenharmony_ci ddb_entry = ha->fw_ddb_index_map[fw_ddb_index]; 298c2ecf20Sopenharmony_ci } 308c2ecf20Sopenharmony_ci 318c2ecf20Sopenharmony_ci DEBUG3(printk("scsi%d: %s: ddb [%d], ddb_entry = %p\n", 328c2ecf20Sopenharmony_ci ha->host_no, __func__, fw_ddb_index, ddb_entry)); 338c2ecf20Sopenharmony_ci 348c2ecf20Sopenharmony_ci return ddb_entry; 358c2ecf20Sopenharmony_ci} 368c2ecf20Sopenharmony_ci 378c2ecf20Sopenharmony_cistatic inline void 388c2ecf20Sopenharmony_ci__qla4xxx_enable_intrs(struct scsi_qla_host *ha) 398c2ecf20Sopenharmony_ci{ 408c2ecf20Sopenharmony_ci if (is_qla4022(ha) | is_qla4032(ha)) { 418c2ecf20Sopenharmony_ci writel(set_rmask(IMR_SCSI_INTR_ENABLE), 428c2ecf20Sopenharmony_ci &ha->reg->u1.isp4022.intr_mask); 438c2ecf20Sopenharmony_ci readl(&ha->reg->u1.isp4022.intr_mask); 448c2ecf20Sopenharmony_ci } else { 458c2ecf20Sopenharmony_ci writel(set_rmask(CSR_SCSI_INTR_ENABLE), &ha->reg->ctrl_status); 468c2ecf20Sopenharmony_ci readl(&ha->reg->ctrl_status); 478c2ecf20Sopenharmony_ci } 488c2ecf20Sopenharmony_ci set_bit(AF_INTERRUPTS_ON, &ha->flags); 498c2ecf20Sopenharmony_ci} 508c2ecf20Sopenharmony_ci 518c2ecf20Sopenharmony_cistatic inline void 528c2ecf20Sopenharmony_ci__qla4xxx_disable_intrs(struct scsi_qla_host *ha) 538c2ecf20Sopenharmony_ci{ 548c2ecf20Sopenharmony_ci if (is_qla4022(ha) | is_qla4032(ha)) { 558c2ecf20Sopenharmony_ci writel(clr_rmask(IMR_SCSI_INTR_ENABLE), 568c2ecf20Sopenharmony_ci &ha->reg->u1.isp4022.intr_mask); 578c2ecf20Sopenharmony_ci readl(&ha->reg->u1.isp4022.intr_mask); 588c2ecf20Sopenharmony_ci } else { 598c2ecf20Sopenharmony_ci writel(clr_rmask(CSR_SCSI_INTR_ENABLE), &ha->reg->ctrl_status); 608c2ecf20Sopenharmony_ci readl(&ha->reg->ctrl_status); 618c2ecf20Sopenharmony_ci } 628c2ecf20Sopenharmony_ci clear_bit(AF_INTERRUPTS_ON, &ha->flags); 638c2ecf20Sopenharmony_ci} 648c2ecf20Sopenharmony_ci 658c2ecf20Sopenharmony_cistatic inline void 668c2ecf20Sopenharmony_ciqla4xxx_enable_intrs(struct scsi_qla_host *ha) 678c2ecf20Sopenharmony_ci{ 688c2ecf20Sopenharmony_ci unsigned long flags; 698c2ecf20Sopenharmony_ci 708c2ecf20Sopenharmony_ci spin_lock_irqsave(&ha->hardware_lock, flags); 718c2ecf20Sopenharmony_ci __qla4xxx_enable_intrs(ha); 728c2ecf20Sopenharmony_ci spin_unlock_irqrestore(&ha->hardware_lock, flags); 738c2ecf20Sopenharmony_ci} 748c2ecf20Sopenharmony_ci 758c2ecf20Sopenharmony_cistatic inline void 768c2ecf20Sopenharmony_ciqla4xxx_disable_intrs(struct scsi_qla_host *ha) 778c2ecf20Sopenharmony_ci{ 788c2ecf20Sopenharmony_ci unsigned long flags; 798c2ecf20Sopenharmony_ci 808c2ecf20Sopenharmony_ci spin_lock_irqsave(&ha->hardware_lock, flags); 818c2ecf20Sopenharmony_ci __qla4xxx_disable_intrs(ha); 828c2ecf20Sopenharmony_ci spin_unlock_irqrestore(&ha->hardware_lock, flags); 838c2ecf20Sopenharmony_ci} 848c2ecf20Sopenharmony_ci 858c2ecf20Sopenharmony_cistatic inline int qla4xxx_get_chap_type(struct ql4_chap_table *chap_entry) 868c2ecf20Sopenharmony_ci{ 878c2ecf20Sopenharmony_ci int type; 888c2ecf20Sopenharmony_ci 898c2ecf20Sopenharmony_ci if (chap_entry->flags & BIT_7) 908c2ecf20Sopenharmony_ci type = LOCAL_CHAP; 918c2ecf20Sopenharmony_ci else 928c2ecf20Sopenharmony_ci type = BIDI_CHAP; 938c2ecf20Sopenharmony_ci 948c2ecf20Sopenharmony_ci return type; 958c2ecf20Sopenharmony_ci} 96