Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

scsi: lpfc: vmid: Functions to manage VMIDs

Implement routines to save, retrieve, and remove the VMIDs from the data
structure. A hash table is used to save the VMIDs and the corresponding
UUIDs associated with the application/VMs.

Link: https://lore.kernel.org/r/20210608043556.274139-9-muneendra.kumar@broadcom.com
Reviewed-by: Hannes Reinecke <hare@suse.de>
Signed-off-by: Gaurav Srivastava <gaurav.srivastava@broadcom.com>
Signed-off-by: James Smart <jsmart2021@gmail.com>
Signed-off-by: Muneendra Kumar <muneendra.kumar@broadcom.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>

authored by

Gaurav Srivastava and committed by
Martin K. Petersen
dc50715e 7e473de7

+118
+118
drivers/scsi/lpfc/lpfc_scsi.c
··· 28 28 #include <asm/unaligned.h> 29 29 #include <linux/t10-pi.h> 30 30 #include <linux/crc-t10dif.h> 31 + #include <linux/blk-cgroup.h> 31 32 #include <net/checksum.h> 32 33 33 34 #include <scsi/scsi.h> ··· 87 86 lpfc_release_scsi_buf_s3(struct lpfc_hba *phba, struct lpfc_io_buf *psb); 88 87 static int 89 88 lpfc_prot_group_type(struct lpfc_hba *phba, struct scsi_cmnd *sc); 89 + static void 90 + lpfc_put_vmid_in_hashtable(struct lpfc_vport *vport, u32 hash, 91 + struct lpfc_vmid *vmp); 92 + static void lpfc_vmid_update_entry(struct lpfc_vport *vport, struct scsi_cmnd 93 + *cmd, struct lpfc_vmid *vmp, 94 + union lpfc_vmid_io_tag *tag); 95 + static void lpfc_vmid_assign_cs_ctl(struct lpfc_vport *vport, 96 + struct lpfc_vmid *vmid); 90 97 91 98 static inline unsigned 92 99 lpfc_cmd_blksize(struct scsi_cmnd *sc) ··· 5166 5157 5167 5158 if (phba->cfg_poll & DISABLE_FCP_RING_INT) 5168 5159 lpfc_poll_rearm_timer(phba); 5160 + } 5161 + } 5162 + 5163 + /* 5164 + * lpfc_get_vmid_from_hashtable - search the UUID in the hash table 5165 + * @vport: The virtual port for which this call is being executed. 5166 + * @hash: calculated hash value 5167 + * @buf: uuid associated with the VE 5168 + * Return the VMID entry associated with the UUID 5169 + * Make sure to acquire the appropriate lock before invoking this routine. 5170 + */ 5171 + struct lpfc_vmid *lpfc_get_vmid_from_hashtable(struct lpfc_vport *vport, 5172 + u32 hash, u8 *buf) 5173 + { 5174 + struct lpfc_vmid *vmp; 5175 + 5176 + hash_for_each_possible(vport->hash_table, vmp, hnode, hash) { 5177 + if (memcmp(&vmp->host_vmid[0], buf, 16) == 0) 5178 + return vmp; 5179 + } 5180 + return NULL; 5181 + } 5182 + 5183 + /* 5184 + * lpfc_put_vmid_in_hashtable - put the VMID in the hash table 5185 + * @vport: The virtual port for which this call is being executed. 5186 + * @hash - calculated hash value 5187 + * @vmp: Pointer to a VMID entry representing a VM sending I/O 5188 + * 5189 + * This routine will insert the newly acquired VMID entity in the hash table. 5190 + * Make sure to acquire the appropriate lock before invoking this routine. 5191 + */ 5192 + static void 5193 + lpfc_put_vmid_in_hashtable(struct lpfc_vport *vport, u32 hash, 5194 + struct lpfc_vmid *vmp) 5195 + { 5196 + hash_add(vport->hash_table, &vmp->hnode, hash); 5197 + } 5198 + 5199 + /* 5200 + * lpfc_vmid_hash_fn - create a hash value of the UUID 5201 + * @vmid: uuid associated with the VE 5202 + * @len: length of the VMID string 5203 + * Returns the calculated hash value 5204 + */ 5205 + int lpfc_vmid_hash_fn(const char *vmid, int len) 5206 + { 5207 + int c; 5208 + int hash = 0; 5209 + 5210 + if (len == 0) 5211 + return 0; 5212 + while (len--) { 5213 + c = *vmid++; 5214 + if (c >= 'A' && c <= 'Z') 5215 + c += 'a' - 'A'; 5216 + 5217 + hash = (hash + (c << LPFC_VMID_HASH_SHIFT) + 5218 + (c >> LPFC_VMID_HASH_SHIFT)) * 19; 5219 + } 5220 + 5221 + return hash & LPFC_VMID_HASH_MASK; 5222 + } 5223 + 5224 + /* 5225 + * lpfc_vmid_update_entry - update the vmid entry in the hash table 5226 + * @vport: The virtual port for which this call is being executed. 5227 + * @cmd: address of scsi cmd descriptor 5228 + * @vmp: Pointer to a VMID entry representing a VM sending I/O 5229 + * @tag: VMID tag 5230 + */ 5231 + static void lpfc_vmid_update_entry(struct lpfc_vport *vport, struct scsi_cmnd 5232 + *cmd, struct lpfc_vmid *vmp, 5233 + union lpfc_vmid_io_tag *tag) 5234 + { 5235 + u64 *lta; 5236 + 5237 + if (vport->vmid_priority_tagging) 5238 + tag->cs_ctl_vmid = vmp->un.cs_ctl_vmid; 5239 + else 5240 + tag->app_id = vmp->un.app_id; 5241 + 5242 + if (cmd->sc_data_direction == DMA_TO_DEVICE) 5243 + vmp->io_wr_cnt++; 5244 + else 5245 + vmp->io_rd_cnt++; 5246 + 5247 + /* update the last access timestamp in the table */ 5248 + lta = per_cpu_ptr(vmp->last_io_time, raw_smp_processor_id()); 5249 + *lta = jiffies; 5250 + } 5251 + 5252 + static void lpfc_vmid_assign_cs_ctl(struct lpfc_vport *vport, 5253 + struct lpfc_vmid *vmid) 5254 + { 5255 + u32 hash; 5256 + struct lpfc_vmid *pvmid; 5257 + 5258 + if (vport->port_type == LPFC_PHYSICAL_PORT) { 5259 + vmid->un.cs_ctl_vmid = lpfc_vmid_get_cs_ctl(vport); 5260 + } else { 5261 + hash = lpfc_vmid_hash_fn(vmid->host_vmid, vmid->vmid_len); 5262 + pvmid = 5263 + lpfc_get_vmid_from_hashtable(vport->phba->pport, hash, 5264 + vmid->host_vmid); 5265 + if (pvmid) 5266 + vmid->un.cs_ctl_vmid = pvmid->un.cs_ctl_vmid; 5267 + else 5268 + vmid->un.cs_ctl_vmid = lpfc_vmid_get_cs_ctl(vport); 5169 5269 } 5170 5270 } 5171 5271