Skip to contentSkip to conversation

scsi: fnic: Use mempool for receive frames

PATCH Applied Karan Tilak Kumar 3 participants 9 messages Feb 17 – Feb 28

Subsystems (2)
lore
Share & tools
lore

Karan Tilak Kumar

author maintainer
#0 lore raw

PATCH 1/5 scsi: fnic: Use mempool for receive frames

The receive frames are constantly replenished so we should rather use a mempool here.

fip_frame_queue is an rxq. De-alloc it in fnic_free_rxq. Incorporate review comments from Hannes:
Modify fnic_free_txq to have same arguments as fnic_free_rxq

---
 drivers/scsi/fnic/fnic.h      |  4 ++-
 drivers/scsi/fnic/fnic_fcs.c  | 54 ++++++++++++++++++++++++-----------
 drivers/scsi/fnic/fnic_main.c | 28 ++++++++++++++++--
 drivers/scsi/fnic/fnic_scsi.c |  2 +-
 4 files changed, 66 insertions(+), 22 deletions(-)
drivers/scsi/fnic/fnic.h +3 -1
index 42237eb3222f..88b47ea04ab2 100644
@@ -438,6 +438,7 @@ struct fnic {
 	struct list_head tx_queue;
 	mempool_t *frame_pool;
 	mempool_t *frame_elem_pool;
+	mempool_t *frame_recv_pool;
 	struct work_struct tport_work;
 	struct list_head tport_event_list;
 
@@ -541,7 +542,8 @@ fnic_chk_state_flags_locked(struct fnic *fnic, unsigned long st_flags)
 }
 void __fnic_set_state_flags(struct fnic *, unsigned long, unsigned long);
 void fnic_dump_fchost_stats(struct Scsi_Host *, struct fc_host_statistics *);
-void fnic_free_txq(struct list_head *head);
+void fnic_free_txq(struct fnic *fnic);
+void fnic_free_rxq(struct fnic *fnic);
 int fnic_get_desc_by_devid(struct pci_dev *pdev, char **desc,
 						   char **subsys_desc);
 void fnic_fdls_link_status_change(struct fnic *fnic, int linkup);
drivers/scsi/fnic/fnic_fcs.c +37 -17

126 lines not on this page · raw message

drivers/scsi/fnic/fnic_main.c +25 -3
index 4cc4077ea53c..1c1fdf2a389e 100644
@@ -40,6 +40,7 @@ static struct kmem_cache *fnic_sgl_cache[FNIC_SGL_NUM_CACHES];
 static struct kmem_cache *fnic_io_req_cache;
 static struct kmem_cache *fdls_frame_cache;
 static struct kmem_cache *fdls_frame_elem_cache;
+static struct kmem_cache *fdls_frame_recv_cache;
 static LIST_HEAD(fnic_list);
 static DEFINE_SPINLOCK(fnic_list_lock);
 static DEFINE_IDA(fnic_ida);
@@ -554,6 +555,7 @@ static int fnic_cleanup(struct fnic *fnic)
 	mempool_destroy(fnic->io_req_pool);
 	mempool_destroy(fnic->frame_pool);
 	mempool_destroy(fnic->frame_elem_pool);
+	mempool_destroy(fnic->frame_recv_pool);
 	for (i = 0; i < FNIC_SGL_NUM_CACHES; i++)
 		mempool_destroy(fnic->io_sgl_pool[i]);
 
@@ -928,6 +930,14 @@ static int fnic_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
 	}
 	fnic->frame_elem_pool = pool;
 
+	pool = mempool_create_slab_pool(FDLS_MIN_FRAMES,
+						fdls_frame_recv_cache);
+	if (!pool) {
+		err = -ENOMEM;
+		goto err_out_fdls_frame_recv_pool;
+	}
+	fnic->frame_recv_pool = pool;
+
 	/* setup vlan config, hw inserts vlan header */
 	fnic->vlan_hw_insert = 1;
 	fnic->vlan_id = 0;
@@ -1085,6 +1095,8 @@ static int fnic_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
 	}
 	vnic_dev_notify_unset(fnic->vdev);
 err_out_fnic_notify_set:
+	mempool_destroy(fnic->frame_recv_pool);
+err_out_fdls_frame_recv_pool:
 	mempool_destroy(fnic->frame_elem_pool);
 err_out_fdls_frame_elem_pool:
 	mempool_destroy(fnic->frame_pool);
@@ -1157,7 +1169,6 @@ static void fnic_remove(struct pci_dev *pdev)
 		timer_delete_sync(&fnic->enode_ka_timer);
 		timer_delete_sync(&fnic->vn_ka_timer);
 
-		fnic_free_txq(&fnic->fip_frame_queue);
 		fnic_fcoe_reset_vlans(fnic);
 	}
 
@@ -1177,8 +1188,8 @@ static void fnic_remove(struct pci_dev *pdev)
 	list_del(&fnic->list);
 	spin_unlock_irqrestore(&fnic_list_lock, flags);
 
-	fnic_free_txq(&fnic->frame_queue);
-	fnic_free_txq(&fnic->tx_queue);
+	fnic_free_rxq(fnic);
+	fnic_free_txq(fnic);
 
 	vnic_dev_notify_unset(fnic->vdev);
 	fnic_free_intr(fnic);
@@ -1287,6 +1298,15 @@ static int __init fnic_init_module(void)
 		goto err_create_fdls_frame_cache_elem;
 	}
 
+	fdls_frame_recv_cache = kmem_cache_create("fdls_frame_recv",
+						  FNIC_FRAME_HT_ROOM,
+						  0, SLAB_HWCACHE_ALIGN, NULL);
+	if (!fdls_frame_recv_cache) {
+		pr_err("fnic fdls frame recv cach create failed\n");
+		err = -ENOMEM;
+		goto err_create_fdls_frame_recv_cache;
+	}
+
 	fnic_event_queue =
 		alloc_ordered_workqueue("%s", WQ_MEM_RECLAIM, "fnic_event_wq");
 	if (!fnic_event_queue) {
@@ -1339,6 +1359,8 @@ static int __init fnic_init_module(void)
 	if (pc_rscn_handling_feature_flag == PC_RSCN_HANDLING_FEATURE_ON)
 		destroy_workqueue(reset_fnic_work_queue);
 err_create_reset_fnic_workq:
+	kmem_cache_destroy(fdls_frame_recv_cache);
+err_create_fdls_frame_recv_cache:
 	destroy_workqueue(fnic_event_queue);
 err_create_fnic_workq:
 	kmem_cache_destroy(fdls_frame_elem_cache);
drivers/scsi/fnic/fnic_scsi.c +1 -1
index 29d7aca06958..1494aeb908ba 100644
@@ -777,7 +777,7 @@ static int fnic_fcpio_fw_reset_cmpl_handler(struct fnic *fnic,
 	 */
 	if (ret) {
 		spin_unlock_irqrestore(&fnic->fnic_lock, flags);
-		fnic_free_txq(&fnic->tx_queue);
+		fnic_free_txq(fnic);
 		goto reset_cmpl_handler_end;
 	}
 
Signature · 1 line
2.47.1
author maintainer
#1 lore raw

PATCH 2/5 scsi: fnic: Do not use GFP_ZERO for mempools

One cannot use the GFP_ZERO flag for mempool allocation, so use memset() instead.

---
 drivers/scsi/fnic/fnic_fcs.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/scsi/fnic/fnic_fcs.c +4 -4
index f6d6ad64983f..2b543d570051 100644
@@ -519,13 +519,13 @@ static void fnic_rq_cmpl_frame_recv(struct vnic_rq *rq, struct cq_desc
 
 	spin_unlock_irqrestore(&fnic->fnic_lock, flags);
 
-	frame_elem = mempool_alloc(fnic->frame_elem_pool,
-					GFP_ATOMIC | __GFP_ZERO);
+	frame_elem = mempool_alloc(fnic->frame_elem_pool, GFP_ATOMIC);
 	if (!frame_elem) {
 		FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
 				 "Failed to allocate memory for frame elem");
 		goto drop;
 	}
+	memset(frame_elem, 0, sizeof(struct fnic_frame_list));
 	frame_elem->fp = fp;
 	frame_elem->rx_ethhdr_stripped = ethhdr_stripped;
 	frame_elem->frame_len = bytes_written;
@@ -704,13 +704,13 @@ fdls_send_fcoe_frame(struct fnic *fnic, void *frame, int frame_size,
 	 */
 	if ((fnic->state != FNIC_IN_FC_MODE)
 		&& (fnic->state != FNIC_IN_ETH_MODE)) {
-		frame_elem = mempool_alloc(fnic->frame_elem_pool,
-						GFP_ATOMIC | __GFP_ZERO);
+		frame_elem = mempool_alloc(fnic->frame_elem_pool, GFP_ATOMIC);
 		if (!frame_elem) {
 			FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
 				 "Failed to allocate memory for frame elem");
 			return -ENOMEM;
 		}
+		memset(frame_elem, 0, sizeof(struct fnic_frame_list));
 
 		FNIC_FCS_DBG(KERN_DEBUG, fnic->host, fnic->fnic_num,
 			"Queueing FC frame: sid/did/type/oxid = 0x%x/0x%x/0x%x/0x%x\n",
Signature · 1 line
2.47.1
#2 lore raw

Re: [PATCH 2/5] scsi: fnic: Do not use GFP_ZERO for mempools

Quoted 3 lines · Karan Tilak Kumar

One cannot use the GFP_ZERO flag for mempool allocation, so use memset() instead.

This kind of thing could easily translate into a static checker rule.

KTODO: make a static checker rule to not pass GFP_ZERO to mempool_alloc()

regards,
dan carpenter

#3 lore raw

RE: [PATCH 2/5] scsi: fnic: Do not use GFP_ZERO for mempools

Quoted 6 lines · Dan Carpenter
Quoted 3 lines · Karan Tilak Kumar

One cannot use the GFP_ZERO flag for mempool allocation, so use memset() instead.

Quoted 7 lines

This kind of thing could easily translate into a static checker rule.

KTODO: make a static checker rule to not pass GFP_ZERO to mempool_alloc()

regards,
dan carpenter

Thanks for your insights, Dan.

Regards,
Karan

author maintainer
#4 lore raw

PATCH 3/5 scsi: fnic: Rename fnic_scsi_fcpio_reset()

In reply to Karan Tilak Kumar

The function has no dependency on SCSI/FCP, so rename it to fnic_fcpio_reset() and move it to fnic_fcs.c

---
 drivers/scsi/fnic/fdls_disc.c |  4 +--
 drivers/scsi/fnic/fip.c       |  2 +-
 drivers/scsi/fnic/fnic.h      |  1 -
 drivers/scsi/fnic/fnic_fcs.c  | 50 ++++++++++++++++++++++++++++++++
 drivers/scsi/fnic/fnic_fdls.h |  2 +-
 drivers/scsi/fnic/fnic_scsi.c | 54 +----------------------------------
 6 files changed, 55 insertions(+), 58 deletions(-)
drivers/scsi/fnic/fdls_disc.c +2 -2
index ae37f85f618b..d276f1d696f8 100644
@@ -4613,7 +4613,7 @@ void fnic_fdls_disc_start(struct fnic_iport_s *iport)
 	if (!iport->usefip) {
 		if (iport->flags & FNIC_FIRST_LINK_UP) {
 			spin_unlock_irqrestore(&fnic->fnic_lock, fnic->lock_flags);
-			fnic_scsi_fcpio_reset(iport->fnic);
+			fnic_fcpio_reset(iport->fnic);
 			spin_lock_irqsave(&fnic->fnic_lock, fnic->lock_flags);
 
 			iport->flags &= ~FNIC_FIRST_LINK_UP;
@@ -5072,7 +5072,7 @@ void fnic_fdls_link_down(struct fnic_iport_s *iport)
 	iport->fabric.flags = 0;
 
 	spin_unlock_irqrestore(&fnic->fnic_lock, fnic->lock_flags);
-	fnic_scsi_fcpio_reset(iport->fnic);
+	fnic_fcpio_reset(iport->fnic);
 	spin_lock_irqsave(&fnic->fnic_lock, fnic->lock_flags);
 	list_for_each_entry_safe(tport, next, &iport->tport_list, links) {
 		FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
drivers/scsi/fnic/fip.c +1 -1
index ce62ab1180bd..6926bb1de163 100644
@@ -737,7 +737,7 @@ void fnic_work_on_fip_timer(struct work_struct *work)
 		if (memcmp(iport->selected_fcf.fcf_mac, zmac, ETH_ALEN) != 0) {
 
 			if (iport->flags & FNIC_FIRST_LINK_UP) {
-				fnic_scsi_fcpio_reset(iport->fnic);
+				fnic_fcpio_reset(iport->fnic);
 				iport->flags &= ~FNIC_FIRST_LINK_UP;
 			}
 
drivers/scsi/fnic/fnic.h +0 -1
index 88b47ea04ab2..f1b6c7978231 100644
@@ -513,7 +513,6 @@ int fnic_host_reset(struct Scsi_Host *shost);
 void fnic_reset(struct Scsi_Host *shost);
 int fnic_issue_fc_host_lip(struct Scsi_Host *shost);
 void fnic_get_host_port_state(struct Scsi_Host *shost);
-void fnic_scsi_fcpio_reset(struct fnic *fnic);
 int fnic_wq_copy_cmpl_handler(struct fnic *fnic, int copy_work_to_do, unsigned int cq_index);
 int fnic_wq_cmpl_handler(struct fnic *fnic, int);
 int fnic_flogi_reg_handler(struct fnic *fnic, u32);
drivers/scsi/fnic/fnic_fcs.c +50 -0

53 lines not on this page · raw message

drivers/scsi/fnic/fnic_fdls.h +1 -1
index 531d0b37e450..e2959120c4f9 100644
@@ -410,6 +410,7 @@ void fnic_fdls_add_tport(struct fnic_iport_s *iport,
 void fnic_fdls_remove_tport(struct fnic_iport_s *iport,
 			    struct fnic_tport_s *tport,
 			    unsigned long flags);
+void fnic_fcpio_reset(struct fnic *fnic);
 
 /* fip.c */
 void fnic_fcoe_send_vlan_req(struct fnic *fnic);
@@ -422,7 +423,6 @@ void fnic_handle_fip_timer(struct timer_list *t);
 extern void fdls_fabric_timer_callback(struct timer_list *t);
 
 /* fnic_scsi.c */
-void fnic_scsi_fcpio_reset(struct fnic *fnic);
 extern void fdls_fabric_timer_callback(struct timer_list *t);
 void fnic_rport_exch_reset(struct fnic *fnic, u32 fcid);
 int fnic_fdls_register_portid(struct fnic_iport_s *iport, u32 port_id,
drivers/scsi/fnic/fnic_scsi.c +1 -53

63 lines not on this page · raw message

Signature · 1 line
2.47.1
author maintainer
#5 lore raw

PATCH 4/5 scsi: fnic: Refactor in_remove flag and call to fnic_fcpio_reset()

In reply to Karan Tilak Kumar

Modify logic to remove unnecessary acquire/release of spinlock to set in_remove flag. There's also no need to check for init status to call fnic_fcpio_reset.

---
 drivers/scsi/fnic/fnic_scsi.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)
drivers/scsi/fnic/fnic_scsi.c +2 -5
index 05b203b9b69b..7e41bb8a7628 100644
@@ -1972,14 +1972,11 @@ void fnic_scsi_unload(struct fnic *fnic)
 	 */
 	spin_lock_irqsave(&fnic->fnic_lock, flags);
 	fnic->iport.state = FNIC_IPORT_STATE_LINK_WAIT;
-	spin_unlock_irqrestore(&fnic->fnic_lock, flags);
-
-	if (fdls_get_state(&fnic->iport.fabric) != FDLS_STATE_INIT)
-		fnic_fcpio_reset(fnic);
-	spin_lock_irqsave(&fnic->fnic_lock, flags);
 	fnic->in_remove = 1;
 	spin_unlock_irqrestore(&fnic->fnic_lock, flags);
 
+	fnic_fcpio_reset(fnic);
+
 	fnic_flush_tport_event_list(fnic);
 	fnic_delete_fcp_tports(fnic);
 }
Signature · 1 line
2.47.1
author maintainer
#6 lore raw

PATCH 5/5 scsi: fnic: Bump up version number

In reply to Karan Tilak Kumar

Bump up version number.

---
 drivers/scsi/fnic/fnic.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/scsi/fnic/fnic.h +1 -1
index f1b6c7978231..8724d64f2525 100644
@@ -30,7 +30,7 @@
 
 #define DRV_NAME		"fnic"
 #define DRV_DESCRIPTION		"Cisco FCoE HBA Driver"
-#define DRV_VERSION		"1.8.0.2"
+#define DRV_VERSION		"1.8.0.3"
 #define PFX			DRV_NAME ": "
 #define DFX                     DRV_NAME "%d: "
 
Signature · 1 line
2.47.1
#8 lore raw
In reply to Karan Tilak Kumar
Quoted 8 lines · Karan Tilak Kumar

The receive frames are constantly replenished so we should rather use a mempool here.

fip_frame_queue is an rxq. De-alloc it in fnic_free_rxq. Incorporate review comments from Hannes:
Modify fnic_free_txq to have same arguments as fnic_free_rxq

[...]

Applied to 7.1/scsi-queue, thanks!

[1/5] scsi: fnic: Use mempool for receive frames

      https://git.kernel.org/mkp/scsi/c/0e07baae55bc
[2/5] scsi: fnic: Do not use GFP_ZERO for mempools
      https://git.kernel.org/mkp/scsi/c/a59d1caf1ded
[3/5] scsi: fnic: Rename fnic_scsi_fcpio_reset()
      https://git.kernel.org/mkp/scsi/c/31eda39bfd46
[4/5] scsi: fnic: Refactor in_remove flag and call to fnic_fcpio_reset()
      https://git.kernel.org/mkp/scsi/c/927b5282df64
[5/5] scsi: fnic: Bump up version number
      https://git.kernel.org/mkp/scsi/c/47e088c9d1a0
Signature · 1 line
Martin K. Petersen