hc
2023-12-11 d2ccde1c8e90d38cee87a1b0309ad2827f3fd30d
kernel/drivers/s390/scsi/zfcp_fc.c
....@@ -48,7 +48,7 @@
4848 {
4949 if (!port_scan_backoff)
5050 return 0;
51
- return get_random_int() % port_scan_backoff;
51
+ return prandom_u32_max(port_scan_backoff);
5252 }
5353
5454 static void zfcp_fc_port_scan_time(struct zfcp_adapter *adapter)
....@@ -145,27 +145,33 @@
145145
146146 static int zfcp_fc_wka_port_get(struct zfcp_fc_wka_port *wka_port)
147147 {
148
+ int ret = -EIO;
149
+
148150 if (mutex_lock_interruptible(&wka_port->mutex))
149151 return -ERESTARTSYS;
150152
151153 if (wka_port->status == ZFCP_FC_WKA_PORT_OFFLINE ||
152154 wka_port->status == ZFCP_FC_WKA_PORT_CLOSING) {
153155 wka_port->status = ZFCP_FC_WKA_PORT_OPENING;
154
- if (zfcp_fsf_open_wka_port(wka_port))
156
+ if (zfcp_fsf_open_wka_port(wka_port)) {
157
+ /* could not even send request, nothing to wait for */
155158 wka_port->status = ZFCP_FC_WKA_PORT_OFFLINE;
159
+ goto out;
160
+ }
156161 }
157162
158
- mutex_unlock(&wka_port->mutex);
159
-
160
- wait_event(wka_port->completion_wq,
163
+ wait_event(wka_port->opened,
161164 wka_port->status == ZFCP_FC_WKA_PORT_ONLINE ||
162165 wka_port->status == ZFCP_FC_WKA_PORT_OFFLINE);
163166
164167 if (wka_port->status == ZFCP_FC_WKA_PORT_ONLINE) {
165168 atomic_inc(&wka_port->refcount);
166
- return 0;
169
+ ret = 0;
170
+ goto out;
167171 }
168
- return -EIO;
172
+out:
173
+ mutex_unlock(&wka_port->mutex);
174
+ return ret;
169175 }
170176
171177 static void zfcp_fc_wka_port_offline(struct work_struct *work)
....@@ -181,9 +187,12 @@
181187
182188 wka_port->status = ZFCP_FC_WKA_PORT_CLOSING;
183189 if (zfcp_fsf_close_wka_port(wka_port)) {
190
+ /* could not even send request, nothing to wait for */
184191 wka_port->status = ZFCP_FC_WKA_PORT_OFFLINE;
185
- wake_up(&wka_port->completion_wq);
192
+ goto out;
186193 }
194
+ wait_event(wka_port->closed,
195
+ wka_port->status == ZFCP_FC_WKA_PORT_OFFLINE);
187196 out:
188197 mutex_unlock(&wka_port->mutex);
189198 }
....@@ -193,13 +202,15 @@
193202 if (atomic_dec_return(&wka_port->refcount) != 0)
194203 return;
195204 /* wait 10 milliseconds, other reqs might pop in */
196
- schedule_delayed_work(&wka_port->work, HZ / 100);
205
+ queue_delayed_work(wka_port->adapter->work_queue, &wka_port->work,
206
+ msecs_to_jiffies(10));
197207 }
198208
199209 static void zfcp_fc_wka_port_init(struct zfcp_fc_wka_port *wka_port, u32 d_id,
200210 struct zfcp_adapter *adapter)
201211 {
202
- init_waitqueue_head(&wka_port->completion_wq);
212
+ init_waitqueue_head(&wka_port->opened);
213
+ init_waitqueue_head(&wka_port->closed);
203214
204215 wka_port->adapter = adapter;
205216 wka_port->d_id = d_id;
....@@ -325,7 +336,7 @@
325336
326337 /**
327338 * zfcp_fc_incoming_els - handle incoming ELS
328
- * @fsf_req - request which contains incoming ELS
339
+ * @fsf_req: request which contains incoming ELS
329340 */
330341 void zfcp_fc_incoming_els(struct zfcp_fsf_req *fsf_req)
331342 {
....@@ -621,6 +632,48 @@
621632 put_device(&port->dev);
622633 }
623634
635
+/**
636
+ * zfcp_fc_sg_free_table - free memory used by scatterlists
637
+ * @sg: pointer to scatterlist
638
+ * @count: number of scatterlist which are to be free'ed
639
+ * the scatterlist are expected to reference pages always
640
+ */
641
+static void zfcp_fc_sg_free_table(struct scatterlist *sg, int count)
642
+{
643
+ int i;
644
+
645
+ for (i = 0; i < count; i++, sg = sg_next(sg))
646
+ if (sg)
647
+ free_page((unsigned long) sg_virt(sg));
648
+ else
649
+ break;
650
+}
651
+
652
+/**
653
+ * zfcp_fc_sg_setup_table - init scatterlist and allocate, assign buffers
654
+ * @sg: pointer to struct scatterlist
655
+ * @count: number of scatterlists which should be assigned with buffers
656
+ * of size page
657
+ *
658
+ * Returns: 0 on success, -ENOMEM otherwise
659
+ */
660
+static int zfcp_fc_sg_setup_table(struct scatterlist *sg, int count)
661
+{
662
+ void *addr;
663
+ int i;
664
+
665
+ sg_init_table(sg, count);
666
+ for (i = 0; i < count; i++, sg = sg_next(sg)) {
667
+ addr = (void *) get_zeroed_page(GFP_KERNEL);
668
+ if (!addr) {
669
+ zfcp_fc_sg_free_table(sg, i);
670
+ return -ENOMEM;
671
+ }
672
+ sg_set_buf(sg, addr, PAGE_SIZE);
673
+ }
674
+ return 0;
675
+}
676
+
624677 static struct zfcp_fc_req *zfcp_fc_alloc_sg_env(int buf_num)
625678 {
626679 struct zfcp_fc_req *fc_req;
....@@ -629,7 +682,7 @@
629682 if (!fc_req)
630683 return NULL;
631684
632
- if (zfcp_sg_setup_table(&fc_req->sg_rsp, buf_num)) {
685
+ if (zfcp_fc_sg_setup_table(&fc_req->sg_rsp, buf_num)) {
633686 kmem_cache_free(zfcp_fc_req_cache, fc_req);
634687 return NULL;
635688 }
....@@ -787,7 +840,7 @@
787840 break;
788841 }
789842 }
790
- zfcp_sg_free_table(&fc_req->sg_rsp, buf_num);
843
+ zfcp_fc_sg_free_table(&fc_req->sg_rsp, buf_num);
791844 kmem_cache_free(zfcp_fc_req_cache, fc_req);
792845 out:
793846 zfcp_fc_wka_port_put(&adapter->gs->ds);