forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-05-10 9999e48639b3cecb08ffb37358bcba3b48161b29
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 {
....@@ -523,8 +534,7 @@
523534
524535 /* re-init to undo drop from zfcp_fc_adisc() */
525536 port->d_id = ntoh24(adisc_resp->adisc_port_id);
526
- /* port is good, unblock rport without going through erp */
527
- zfcp_scsi_schedule_rport_register(port);
537
+ /* port is still good, nothing to do */
528538 out:
529539 atomic_andnot(ZFCP_STATUS_PORT_LINK_TEST, &port->status);
530540 put_device(&port->dev);
....@@ -584,9 +594,6 @@
584594 int retval;
585595
586596 set_worker_desc("zadisc%16llx", port->wwpn); /* < WORKER_DESC_LEN=24 */
587
- get_device(&port->dev);
588
- port->rport_task = RPORT_DEL;
589
- zfcp_scsi_rport_work(&port->rport_work);
590597
591598 /* only issue one test command at one time per port */
592599 if (atomic_read(&port->status) & ZFCP_STATUS_PORT_LINK_TEST)
....@@ -621,6 +628,48 @@
621628 put_device(&port->dev);
622629 }
623630
631
+/**
632
+ * zfcp_fc_sg_free_table - free memory used by scatterlists
633
+ * @sg: pointer to scatterlist
634
+ * @count: number of scatterlist which are to be free'ed
635
+ * the scatterlist are expected to reference pages always
636
+ */
637
+static void zfcp_fc_sg_free_table(struct scatterlist *sg, int count)
638
+{
639
+ int i;
640
+
641
+ for (i = 0; i < count; i++, sg = sg_next(sg))
642
+ if (sg)
643
+ free_page((unsigned long) sg_virt(sg));
644
+ else
645
+ break;
646
+}
647
+
648
+/**
649
+ * zfcp_fc_sg_setup_table - init scatterlist and allocate, assign buffers
650
+ * @sg: pointer to struct scatterlist
651
+ * @count: number of scatterlists which should be assigned with buffers
652
+ * of size page
653
+ *
654
+ * Returns: 0 on success, -ENOMEM otherwise
655
+ */
656
+static int zfcp_fc_sg_setup_table(struct scatterlist *sg, int count)
657
+{
658
+ void *addr;
659
+ int i;
660
+
661
+ sg_init_table(sg, count);
662
+ for (i = 0; i < count; i++, sg = sg_next(sg)) {
663
+ addr = (void *) get_zeroed_page(GFP_KERNEL);
664
+ if (!addr) {
665
+ zfcp_fc_sg_free_table(sg, i);
666
+ return -ENOMEM;
667
+ }
668
+ sg_set_buf(sg, addr, PAGE_SIZE);
669
+ }
670
+ return 0;
671
+}
672
+
624673 static struct zfcp_fc_req *zfcp_fc_alloc_sg_env(int buf_num)
625674 {
626675 struct zfcp_fc_req *fc_req;
....@@ -629,7 +678,7 @@
629678 if (!fc_req)
630679 return NULL;
631680
632
- if (zfcp_sg_setup_table(&fc_req->sg_rsp, buf_num)) {
681
+ if (zfcp_fc_sg_setup_table(&fc_req->sg_rsp, buf_num)) {
633682 kmem_cache_free(zfcp_fc_req_cache, fc_req);
634683 return NULL;
635684 }
....@@ -787,7 +836,7 @@
787836 break;
788837 }
789838 }
790
- zfcp_sg_free_table(&fc_req->sg_rsp, buf_num);
839
+ zfcp_fc_sg_free_table(&fc_req->sg_rsp, buf_num);
791840 kmem_cache_free(zfcp_fc_req_cache, fc_req);
792841 out:
793842 zfcp_fc_wka_port_put(&adapter->gs->ds);