Skip to content

Commit f28f16d

Browse files
tyreldmartinkpetersen
authored andcommitted
scsi: ibmvfc: Make channel allocation generic
With the coming of NVMeoF support the driver will need to also allocate channels for NVMe. Implement generic channel allocation wrappers that can be used for both SCSI and NVMeoF protocol setup. Signed-off-by: Tyrel Datwyler <tyreld@linux.ibm.com> Link: https://lore.kernel.org/r/20230921225435.3537728-9-tyreld@linux.ibm.com Reviewed-by: Brian King <brking@linux.vnet.ibm.com> Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
1 parent 9e56054 commit f28f16d

File tree

1 file changed

+75
-52
lines changed

1 file changed

+75
-52
lines changed

drivers/scsi/ibmvscsi/ibmvfc.c

Lines changed: 75 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,8 @@ static void ibmvfc_npiv_logout(struct ibmvfc_host *);
163163
static void ibmvfc_tgt_implicit_logout_and_del(struct ibmvfc_target *);
164164
static void ibmvfc_tgt_move_login(struct ibmvfc_target *);
165165

166-
static void ibmvfc_dereg_sub_crqs(struct ibmvfc_host *);
167-
static void ibmvfc_reg_sub_crqs(struct ibmvfc_host *);
166+
static void ibmvfc_dereg_sub_crqs(struct ibmvfc_host *, struct ibmvfc_channels *);
167+
static void ibmvfc_reg_sub_crqs(struct ibmvfc_host *, struct ibmvfc_channels *);
168168

169169
static const char *unknown_error = "unknown error";
170170

@@ -925,7 +925,7 @@ static int ibmvfc_reenable_crq_queue(struct ibmvfc_host *vhost)
925925
struct vio_dev *vdev = to_vio_dev(vhost->dev);
926926
unsigned long flags;
927927

928-
ibmvfc_dereg_sub_crqs(vhost);
928+
ibmvfc_dereg_sub_crqs(vhost, &vhost->scsi_scrqs);
929929

930930
/* Re-enable the CRQ */
931931
do {
@@ -944,7 +944,7 @@ static int ibmvfc_reenable_crq_queue(struct ibmvfc_host *vhost)
944944
spin_unlock(vhost->crq.q_lock);
945945
spin_unlock_irqrestore(vhost->host->host_lock, flags);
946946

947-
ibmvfc_reg_sub_crqs(vhost);
947+
ibmvfc_reg_sub_crqs(vhost, &vhost->scsi_scrqs);
948948

949949
return rc;
950950
}
@@ -963,7 +963,7 @@ static int ibmvfc_reset_crq(struct ibmvfc_host *vhost)
963963
struct vio_dev *vdev = to_vio_dev(vhost->dev);
964964
struct ibmvfc_queue *crq = &vhost->crq;
965965

966-
ibmvfc_dereg_sub_crqs(vhost);
966+
ibmvfc_dereg_sub_crqs(vhost, &vhost->scsi_scrqs);
967967

968968
/* Close the CRQ */
969969
do {
@@ -996,7 +996,7 @@ static int ibmvfc_reset_crq(struct ibmvfc_host *vhost)
996996
spin_unlock(vhost->crq.q_lock);
997997
spin_unlock_irqrestore(vhost->host->host_lock, flags);
998998

999-
ibmvfc_reg_sub_crqs(vhost);
999+
ibmvfc_reg_sub_crqs(vhost, &vhost->scsi_scrqs);
10001000

10011001
return rc;
10021002
}
@@ -5906,12 +5906,13 @@ static int ibmvfc_init_crq(struct ibmvfc_host *vhost)
59065906
return retrc;
59075907
}
59085908

5909-
static int ibmvfc_register_scsi_channel(struct ibmvfc_host *vhost,
5910-
int index)
5909+
static int ibmvfc_register_channel(struct ibmvfc_host *vhost,
5910+
struct ibmvfc_channels *channels,
5911+
int index)
59115912
{
59125913
struct device *dev = vhost->dev;
59135914
struct vio_dev *vdev = to_vio_dev(dev);
5914-
struct ibmvfc_queue *scrq = &vhost->scsi_scrqs.scrqs[index];
5915+
struct ibmvfc_queue *scrq = &channels->scrqs[index];
59155916
int rc = -ENOMEM;
59165917

59175918
ENTER;
@@ -5959,11 +5960,13 @@ static int ibmvfc_register_scsi_channel(struct ibmvfc_host *vhost,
59595960
return rc;
59605961
}
59615962

5962-
static void ibmvfc_deregister_scsi_channel(struct ibmvfc_host *vhost, int index)
5963+
static void ibmvfc_deregister_channel(struct ibmvfc_host *vhost,
5964+
struct ibmvfc_channels *channels,
5965+
int index)
59635966
{
59645967
struct device *dev = vhost->dev;
59655968
struct vio_dev *vdev = to_vio_dev(dev);
5966-
struct ibmvfc_queue *scrq = &vhost->scsi_scrqs.scrqs[index];
5969+
struct ibmvfc_queue *scrq = &channels->scrqs[index];
59675970
long rc;
59685971

59695972
ENTER;
@@ -5987,18 +5990,19 @@ static void ibmvfc_deregister_scsi_channel(struct ibmvfc_host *vhost, int index)
59875990
LEAVE;
59885991
}
59895992

5990-
static void ibmvfc_reg_sub_crqs(struct ibmvfc_host *vhost)
5993+
static void ibmvfc_reg_sub_crqs(struct ibmvfc_host *vhost,
5994+
struct ibmvfc_channels *channels)
59915995
{
59925996
int i, j;
59935997

59945998
ENTER;
5995-
if (!vhost->mq_enabled || !vhost->scsi_scrqs.scrqs)
5999+
if (!vhost->mq_enabled || !channels->scrqs)
59966000
return;
59976001

5998-
for (i = 0; i < nr_scsi_hw_queues; i++) {
5999-
if (ibmvfc_register_scsi_channel(vhost, i)) {
6002+
for (i = 0; i < channels->max_queues; i++) {
6003+
if (ibmvfc_register_channel(vhost, channels, i)) {
60006004
for (j = i; j > 0; j--)
6001-
ibmvfc_deregister_scsi_channel(vhost, j - 1);
6005+
ibmvfc_deregister_channel(vhost, channels, j - 1);
60026006
vhost->do_enquiry = 0;
60036007
return;
60046008
}
@@ -6007,77 +6011,96 @@ static void ibmvfc_reg_sub_crqs(struct ibmvfc_host *vhost)
60076011
LEAVE;
60086012
}
60096013

6010-
static void ibmvfc_dereg_sub_crqs(struct ibmvfc_host *vhost)
6014+
static void ibmvfc_dereg_sub_crqs(struct ibmvfc_host *vhost,
6015+
struct ibmvfc_channels *channels)
60116016
{
60126017
int i;
60136018

60146019
ENTER;
6015-
if (!vhost->mq_enabled || !vhost->scsi_scrqs.scrqs)
6020+
if (!vhost->mq_enabled || !channels->scrqs)
60166021
return;
60176022

6018-
for (i = 0; i < nr_scsi_hw_queues; i++)
6019-
ibmvfc_deregister_scsi_channel(vhost, i);
6023+
for (i = 0; i < channels->max_queues; i++)
6024+
ibmvfc_deregister_channel(vhost, channels, i);
60206025

60216026
LEAVE;
60226027
}
60236028

6024-
static void ibmvfc_init_sub_crqs(struct ibmvfc_host *vhost)
6029+
static int ibmvfc_alloc_channels(struct ibmvfc_host *vhost,
6030+
struct ibmvfc_channels *channels)
60256031
{
60266032
struct ibmvfc_queue *scrq;
60276033
int i, j;
6034+
int rc = 0;
60286035

6036+
channels->scrqs = kcalloc(channels->max_queues,
6037+
sizeof(*channels->scrqs),
6038+
GFP_KERNEL);
6039+
if (!channels->scrqs)
6040+
return -ENOMEM;
6041+
6042+
for (i = 0; i < channels->max_queues; i++) {
6043+
scrq = &channels->scrqs[i];
6044+
rc = ibmvfc_alloc_queue(vhost, scrq, IBMVFC_SUB_CRQ_FMT);
6045+
if (rc) {
6046+
for (j = i; j > 0; j--) {
6047+
scrq = &channels->scrqs[j - 1];
6048+
ibmvfc_free_queue(vhost, scrq);
6049+
}
6050+
kfree(channels->scrqs);
6051+
channels->scrqs = NULL;
6052+
channels->active_queues = 0;
6053+
return rc;
6054+
}
6055+
}
6056+
6057+
return rc;
6058+
}
6059+
6060+
static void ibmvfc_init_sub_crqs(struct ibmvfc_host *vhost)
6061+
{
60296062
ENTER;
60306063
if (!vhost->mq_enabled)
60316064
return;
60326065

6033-
vhost->scsi_scrqs.scrqs = kcalloc(nr_scsi_hw_queues,
6034-
sizeof(*vhost->scsi_scrqs.scrqs),
6035-
GFP_KERNEL);
6036-
if (!vhost->scsi_scrqs.scrqs) {
6066+
if (ibmvfc_alloc_channels(vhost, &vhost->scsi_scrqs)) {
60376067
vhost->do_enquiry = 0;
6068+
vhost->mq_enabled = 0;
60386069
return;
60396070
}
60406071

6041-
for (i = 0; i < nr_scsi_hw_queues; i++) {
6042-
scrq = &vhost->scsi_scrqs.scrqs[i];
6043-
if (ibmvfc_alloc_queue(vhost, scrq, IBMVFC_SUB_CRQ_FMT)) {
6044-
for (j = i; j > 0; j--) {
6045-
scrq = &vhost->scsi_scrqs.scrqs[j - 1];
6046-
ibmvfc_free_queue(vhost, scrq);
6047-
}
6048-
kfree(vhost->scsi_scrqs.scrqs);
6049-
vhost->scsi_scrqs.scrqs = NULL;
6050-
vhost->scsi_scrqs.active_queues = 0;
6051-
vhost->do_enquiry = 0;
6052-
vhost->mq_enabled = 0;
6053-
return;
6054-
}
6055-
}
6056-
6057-
ibmvfc_reg_sub_crqs(vhost);
6072+
ibmvfc_reg_sub_crqs(vhost, &vhost->scsi_scrqs);
60586073

60596074
LEAVE;
60606075
}
60616076

6062-
static void ibmvfc_release_sub_crqs(struct ibmvfc_host *vhost)
6077+
static void ibmvfc_release_channels(struct ibmvfc_host *vhost,
6078+
struct ibmvfc_channels *channels)
60636079
{
60646080
struct ibmvfc_queue *scrq;
60656081
int i;
60666082

6083+
if (channels->scrqs) {
6084+
for (i = 0; i < channels->max_queues; i++) {
6085+
scrq = &channels->scrqs[i];
6086+
ibmvfc_free_queue(vhost, scrq);
6087+
}
6088+
6089+
kfree(channels->scrqs);
6090+
channels->scrqs = NULL;
6091+
channels->active_queues = 0;
6092+
}
6093+
}
6094+
6095+
static void ibmvfc_release_sub_crqs(struct ibmvfc_host *vhost)
6096+
{
60676097
ENTER;
60686098
if (!vhost->scsi_scrqs.scrqs)
60696099
return;
60706100

6071-
ibmvfc_dereg_sub_crqs(vhost);
6072-
6073-
for (i = 0; i < nr_scsi_hw_queues; i++) {
6074-
scrq = &vhost->scsi_scrqs.scrqs[i];
6075-
ibmvfc_free_queue(vhost, scrq);
6076-
}
6101+
ibmvfc_dereg_sub_crqs(vhost, &vhost->scsi_scrqs);
60776102

6078-
kfree(vhost->scsi_scrqs.scrqs);
6079-
vhost->scsi_scrqs.scrqs = NULL;
6080-
vhost->scsi_scrqs.active_queues = 0;
6103+
ibmvfc_release_channels(vhost, &vhost->scsi_scrqs);
60816104
LEAVE;
60826105
}
60836106

0 commit comments

Comments
 (0)