xref: /linux/drivers/scsi/qla4xxx/ql4_inline.h (revision c532de5a67a70f8533d495f8f2aaa9a0491c3ad0)
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3  * QLogic iSCSI HBA Driver
4  * Copyright (c)  2003-2013 QLogic Corporation
5  */
6 
7 /*
8  *
9  * qla4xxx_lookup_ddb_by_fw_index
10  *	This routine locates a device handle given the firmware device
11  *	database index.	 If device doesn't exist, returns NULL.
12  *
13  * Input:
14  *	ha - Pointer to host adapter structure.
15  *	fw_ddb_index - Firmware's device database index
16  *
17  * Returns:
18  *	Pointer to the corresponding internal device database structure
19  */
20 static inline struct ddb_entry *
21 qla4xxx_lookup_ddb_by_fw_index(struct scsi_qla_host *ha, uint32_t fw_ddb_index)
22 {
23 	struct ddb_entry *ddb_entry = NULL;
24 
25 	if ((fw_ddb_index < MAX_DDB_ENTRIES) &&
26 	    (ha->fw_ddb_index_map[fw_ddb_index] !=
27 		(struct ddb_entry *) INVALID_ENTRY)) {
28 		ddb_entry = ha->fw_ddb_index_map[fw_ddb_index];
29 	}
30 
31 	DEBUG3(printk("scsi%d: %s: ddb [%d], ddb_entry = %p\n",
32 	    ha->host_no, __func__, fw_ddb_index, ddb_entry));
33 
34 	return ddb_entry;
35 }
36 
37 static inline void
38 __qla4xxx_enable_intrs(struct scsi_qla_host *ha)
39 {
40 	if (is_qla4022(ha) | is_qla4032(ha)) {
41 		writel(set_rmask(IMR_SCSI_INTR_ENABLE),
42 		       &ha->reg->u1.isp4022.intr_mask);
43 		readl(&ha->reg->u1.isp4022.intr_mask);
44 	} else {
45 		writel(set_rmask(CSR_SCSI_INTR_ENABLE), &ha->reg->ctrl_status);
46 		readl(&ha->reg->ctrl_status);
47 	}
48 	set_bit(AF_INTERRUPTS_ON, &ha->flags);
49 }
50 
51 static inline void
52 __qla4xxx_disable_intrs(struct scsi_qla_host *ha)
53 {
54 	if (is_qla4022(ha) | is_qla4032(ha)) {
55 		writel(clr_rmask(IMR_SCSI_INTR_ENABLE),
56 		       &ha->reg->u1.isp4022.intr_mask);
57 		readl(&ha->reg->u1.isp4022.intr_mask);
58 	} else {
59 		writel(clr_rmask(CSR_SCSI_INTR_ENABLE), &ha->reg->ctrl_status);
60 		readl(&ha->reg->ctrl_status);
61 	}
62 	clear_bit(AF_INTERRUPTS_ON, &ha->flags);
63 }
64 
65 static inline void
66 qla4xxx_enable_intrs(struct scsi_qla_host *ha)
67 {
68 	unsigned long flags;
69 
70 	spin_lock_irqsave(&ha->hardware_lock, flags);
71 	__qla4xxx_enable_intrs(ha);
72 	spin_unlock_irqrestore(&ha->hardware_lock, flags);
73 }
74 
75 static inline void
76 qla4xxx_disable_intrs(struct scsi_qla_host *ha)
77 {
78 	unsigned long flags;
79 
80 	spin_lock_irqsave(&ha->hardware_lock, flags);
81 	__qla4xxx_disable_intrs(ha);
82 	spin_unlock_irqrestore(&ha->hardware_lock, flags);
83 }
84 
85 static inline int qla4xxx_get_chap_type(struct ql4_chap_table *chap_entry)
86 {
87 	int type;
88 
89 	if (chap_entry->flags & BIT_7)
90 		type = LOCAL_CHAP;
91 	else
92 		type = BIDI_CHAP;
93 
94 	return type;
95 }
96