.. | .. |
---|
48 | 48 | { |
---|
49 | 49 | if (!port_scan_backoff) |
---|
50 | 50 | return 0; |
---|
51 | | - return get_random_int() % port_scan_backoff; |
---|
| 51 | + return prandom_u32_max(port_scan_backoff); |
---|
52 | 52 | } |
---|
53 | 53 | |
---|
54 | 54 | static void zfcp_fc_port_scan_time(struct zfcp_adapter *adapter) |
---|
.. | .. |
---|
145 | 145 | |
---|
146 | 146 | static int zfcp_fc_wka_port_get(struct zfcp_fc_wka_port *wka_port) |
---|
147 | 147 | { |
---|
| 148 | + int ret = -EIO; |
---|
| 149 | + |
---|
148 | 150 | if (mutex_lock_interruptible(&wka_port->mutex)) |
---|
149 | 151 | return -ERESTARTSYS; |
---|
150 | 152 | |
---|
151 | 153 | if (wka_port->status == ZFCP_FC_WKA_PORT_OFFLINE || |
---|
152 | 154 | wka_port->status == ZFCP_FC_WKA_PORT_CLOSING) { |
---|
153 | 155 | 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 */ |
---|
155 | 158 | wka_port->status = ZFCP_FC_WKA_PORT_OFFLINE; |
---|
| 159 | + goto out; |
---|
| 160 | + } |
---|
156 | 161 | } |
---|
157 | 162 | |
---|
158 | | - mutex_unlock(&wka_port->mutex); |
---|
159 | | - |
---|
160 | | - wait_event(wka_port->completion_wq, |
---|
| 163 | + wait_event(wka_port->opened, |
---|
161 | 164 | wka_port->status == ZFCP_FC_WKA_PORT_ONLINE || |
---|
162 | 165 | wka_port->status == ZFCP_FC_WKA_PORT_OFFLINE); |
---|
163 | 166 | |
---|
164 | 167 | if (wka_port->status == ZFCP_FC_WKA_PORT_ONLINE) { |
---|
165 | 168 | atomic_inc(&wka_port->refcount); |
---|
166 | | - return 0; |
---|
| 169 | + ret = 0; |
---|
| 170 | + goto out; |
---|
167 | 171 | } |
---|
168 | | - return -EIO; |
---|
| 172 | +out: |
---|
| 173 | + mutex_unlock(&wka_port->mutex); |
---|
| 174 | + return ret; |
---|
169 | 175 | } |
---|
170 | 176 | |
---|
171 | 177 | static void zfcp_fc_wka_port_offline(struct work_struct *work) |
---|
.. | .. |
---|
181 | 187 | |
---|
182 | 188 | wka_port->status = ZFCP_FC_WKA_PORT_CLOSING; |
---|
183 | 189 | if (zfcp_fsf_close_wka_port(wka_port)) { |
---|
| 190 | + /* could not even send request, nothing to wait for */ |
---|
184 | 191 | wka_port->status = ZFCP_FC_WKA_PORT_OFFLINE; |
---|
185 | | - wake_up(&wka_port->completion_wq); |
---|
| 192 | + goto out; |
---|
186 | 193 | } |
---|
| 194 | + wait_event(wka_port->closed, |
---|
| 195 | + wka_port->status == ZFCP_FC_WKA_PORT_OFFLINE); |
---|
187 | 196 | out: |
---|
188 | 197 | mutex_unlock(&wka_port->mutex); |
---|
189 | 198 | } |
---|
.. | .. |
---|
193 | 202 | if (atomic_dec_return(&wka_port->refcount) != 0) |
---|
194 | 203 | return; |
---|
195 | 204 | /* 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)); |
---|
197 | 207 | } |
---|
198 | 208 | |
---|
199 | 209 | static void zfcp_fc_wka_port_init(struct zfcp_fc_wka_port *wka_port, u32 d_id, |
---|
200 | 210 | struct zfcp_adapter *adapter) |
---|
201 | 211 | { |
---|
202 | | - init_waitqueue_head(&wka_port->completion_wq); |
---|
| 212 | + init_waitqueue_head(&wka_port->opened); |
---|
| 213 | + init_waitqueue_head(&wka_port->closed); |
---|
203 | 214 | |
---|
204 | 215 | wka_port->adapter = adapter; |
---|
205 | 216 | wka_port->d_id = d_id; |
---|
.. | .. |
---|
325 | 336 | |
---|
326 | 337 | /** |
---|
327 | 338 | * zfcp_fc_incoming_els - handle incoming ELS |
---|
328 | | - * @fsf_req - request which contains incoming ELS |
---|
| 339 | + * @fsf_req: request which contains incoming ELS |
---|
329 | 340 | */ |
---|
330 | 341 | void zfcp_fc_incoming_els(struct zfcp_fsf_req *fsf_req) |
---|
331 | 342 | { |
---|
.. | .. |
---|
523 | 534 | |
---|
524 | 535 | /* re-init to undo drop from zfcp_fc_adisc() */ |
---|
525 | 536 | 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 */ |
---|
528 | 538 | out: |
---|
529 | 539 | atomic_andnot(ZFCP_STATUS_PORT_LINK_TEST, &port->status); |
---|
530 | 540 | put_device(&port->dev); |
---|
.. | .. |
---|
584 | 594 | int retval; |
---|
585 | 595 | |
---|
586 | 596 | 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); |
---|
590 | 597 | |
---|
591 | 598 | /* only issue one test command at one time per port */ |
---|
592 | 599 | if (atomic_read(&port->status) & ZFCP_STATUS_PORT_LINK_TEST) |
---|
.. | .. |
---|
621 | 628 | put_device(&port->dev); |
---|
622 | 629 | } |
---|
623 | 630 | |
---|
| 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 | + |
---|
624 | 673 | static struct zfcp_fc_req *zfcp_fc_alloc_sg_env(int buf_num) |
---|
625 | 674 | { |
---|
626 | 675 | struct zfcp_fc_req *fc_req; |
---|
.. | .. |
---|
629 | 678 | if (!fc_req) |
---|
630 | 679 | return NULL; |
---|
631 | 680 | |
---|
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)) { |
---|
633 | 682 | kmem_cache_free(zfcp_fc_req_cache, fc_req); |
---|
634 | 683 | return NULL; |
---|
635 | 684 | } |
---|
.. | .. |
---|
787 | 836 | break; |
---|
788 | 837 | } |
---|
789 | 838 | } |
---|
790 | | - zfcp_sg_free_table(&fc_req->sg_rsp, buf_num); |
---|
| 839 | + zfcp_fc_sg_free_table(&fc_req->sg_rsp, buf_num); |
---|
791 | 840 | kmem_cache_free(zfcp_fc_req_cache, fc_req); |
---|
792 | 841 | out: |
---|
793 | 842 | zfcp_fc_wka_port_put(&adapter->gs->ds); |
---|