Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 2 | /* |
| 3 | * zfcp device driver |
| 4 | * |
| 5 | * Fibre Channel related functions for the zfcp device driver. |
| 6 | * |
Steffen Maier | ab8ab4b | 2017-07-28 12:30:59 +0200 | [diff] [blame] | 7 | * Copyright IBM Corp. 2008, 2017 |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 8 | */ |
| 9 | |
Christof Schmitt | ecf39d4 | 2008-12-25 13:39:53 +0100 | [diff] [blame] | 10 | #define KMSG_COMPONENT "zfcp" |
| 11 | #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt |
| 12 | |
Christof Schmitt | 9d05ce2 | 2009-11-24 16:54:09 +0100 | [diff] [blame] | 13 | #include <linux/types.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 14 | #include <linux/slab.h> |
Christof Schmitt | 038d944 | 2011-02-22 19:54:48 +0100 | [diff] [blame] | 15 | #include <linux/utsname.h> |
Martin Peschke | 18f87a6 | 2014-11-13 14:59:48 +0100 | [diff] [blame] | 16 | #include <linux/random.h> |
Johannes Thumshirn | 75cc8cf | 2016-11-17 10:31:19 +0100 | [diff] [blame] | 17 | #include <linux/bsg-lib.h> |
Christof Schmitt | 9d05ce2 | 2009-11-24 16:54:09 +0100 | [diff] [blame] | 18 | #include <scsi/fc/fc_els.h> |
| 19 | #include <scsi/libfc.h> |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 20 | #include "zfcp_ext.h" |
Christof Schmitt | 9d05ce2 | 2009-11-24 16:54:09 +0100 | [diff] [blame] | 21 | #include "zfcp_fc.h" |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 22 | |
Christof Schmitt | 087897e | 2011-02-22 19:54:41 +0100 | [diff] [blame] | 23 | struct kmem_cache *zfcp_fc_req_cache; |
| 24 | |
Christof Schmitt | 9d05ce2 | 2009-11-24 16:54:09 +0100 | [diff] [blame] | 25 | static u32 zfcp_fc_rscn_range_mask[] = { |
| 26 | [ELS_ADDR_FMT_PORT] = 0xFFFFFF, |
| 27 | [ELS_ADDR_FMT_AREA] = 0xFFFF00, |
| 28 | [ELS_ADDR_FMT_DOM] = 0xFF0000, |
| 29 | [ELS_ADDR_FMT_FAB] = 0x000000, |
Christof Schmitt | e0d7fcb | 2008-12-19 16:56:58 +0100 | [diff] [blame] | 30 | }; |
| 31 | |
Steffen Maier | 43f60cb | 2012-09-04 15:23:35 +0200 | [diff] [blame] | 32 | static bool no_auto_port_rescan; |
Martin Peschke | b096ef8 | 2017-07-28 12:31:07 +0200 | [diff] [blame] | 33 | module_param(no_auto_port_rescan, bool, 0600); |
Steffen Maier | 43f60cb | 2012-09-04 15:23:35 +0200 | [diff] [blame] | 34 | MODULE_PARM_DESC(no_auto_port_rescan, |
| 35 | "no automatic port_rescan (default off)"); |
| 36 | |
Martin Peschke | 18f87a6 | 2014-11-13 14:59:48 +0100 | [diff] [blame] | 37 | static unsigned int port_scan_backoff = 500; |
| 38 | module_param(port_scan_backoff, uint, 0600); |
| 39 | MODULE_PARM_DESC(port_scan_backoff, |
| 40 | "upper limit of port scan random backoff in msecs (default 500)"); |
| 41 | |
| 42 | static unsigned int port_scan_ratelimit = 60000; |
| 43 | module_param(port_scan_ratelimit, uint, 0600); |
| 44 | MODULE_PARM_DESC(port_scan_ratelimit, |
| 45 | "minimum interval between port scans in msecs (default 60000)"); |
| 46 | |
| 47 | unsigned int zfcp_fc_port_scan_backoff(void) |
| 48 | { |
| 49 | if (!port_scan_backoff) |
| 50 | return 0; |
| 51 | return get_random_int() % port_scan_backoff; |
| 52 | } |
| 53 | |
| 54 | static void zfcp_fc_port_scan_time(struct zfcp_adapter *adapter) |
| 55 | { |
| 56 | unsigned long interval = msecs_to_jiffies(port_scan_ratelimit); |
| 57 | unsigned long backoff = msecs_to_jiffies(zfcp_fc_port_scan_backoff()); |
| 58 | |
| 59 | adapter->next_port_scan = jiffies + interval + backoff; |
| 60 | } |
| 61 | |
| 62 | static void zfcp_fc_port_scan(struct zfcp_adapter *adapter) |
| 63 | { |
| 64 | unsigned long now = jiffies; |
| 65 | unsigned long next = adapter->next_port_scan; |
| 66 | unsigned long delay = 0, max; |
| 67 | |
| 68 | /* delay only needed within waiting period */ |
| 69 | if (time_before(now, next)) { |
| 70 | delay = next - now; |
| 71 | /* paranoia: never ever delay scans longer than specified */ |
| 72 | max = msecs_to_jiffies(port_scan_ratelimit + port_scan_backoff); |
| 73 | delay = min(delay, max); |
| 74 | } |
| 75 | |
| 76 | queue_delayed_work(adapter->work_queue, &adapter->scan_work, delay); |
| 77 | } |
| 78 | |
Steffen Maier | 43f60cb | 2012-09-04 15:23:35 +0200 | [diff] [blame] | 79 | void zfcp_fc_conditional_port_scan(struct zfcp_adapter *adapter) |
| 80 | { |
| 81 | if (no_auto_port_rescan) |
| 82 | return; |
| 83 | |
Martin Peschke | 18f87a6 | 2014-11-13 14:59:48 +0100 | [diff] [blame] | 84 | zfcp_fc_port_scan(adapter); |
Steffen Maier | 43f60cb | 2012-09-04 15:23:35 +0200 | [diff] [blame] | 85 | } |
| 86 | |
| 87 | void zfcp_fc_inverse_conditional_port_scan(struct zfcp_adapter *adapter) |
| 88 | { |
| 89 | if (!no_auto_port_rescan) |
| 90 | return; |
| 91 | |
Martin Peschke | 18f87a6 | 2014-11-13 14:59:48 +0100 | [diff] [blame] | 92 | zfcp_fc_port_scan(adapter); |
Steffen Maier | 43f60cb | 2012-09-04 15:23:35 +0200 | [diff] [blame] | 93 | } |
| 94 | |
Sven Schuetz | 2d1e547 | 2010-07-16 15:37:39 +0200 | [diff] [blame] | 95 | /** |
| 96 | * zfcp_fc_post_event - post event to userspace via fc_transport |
| 97 | * @work: work struct with enqueued events |
| 98 | */ |
| 99 | void zfcp_fc_post_event(struct work_struct *work) |
| 100 | { |
| 101 | struct zfcp_fc_event *event = NULL, *tmp = NULL; |
| 102 | LIST_HEAD(tmp_lh); |
| 103 | struct zfcp_fc_events *events = container_of(work, |
| 104 | struct zfcp_fc_events, work); |
| 105 | struct zfcp_adapter *adapter = container_of(events, struct zfcp_adapter, |
| 106 | events); |
| 107 | |
| 108 | spin_lock_bh(&events->list_lock); |
| 109 | list_splice_init(&events->list, &tmp_lh); |
| 110 | spin_unlock_bh(&events->list_lock); |
| 111 | |
| 112 | list_for_each_entry_safe(event, tmp, &tmp_lh, list) { |
| 113 | fc_host_post_event(adapter->scsi_host, fc_get_event_number(), |
| 114 | event->code, event->data); |
| 115 | list_del(&event->list); |
| 116 | kfree(event); |
| 117 | } |
| 118 | |
| 119 | } |
| 120 | |
| 121 | /** |
| 122 | * zfcp_fc_enqueue_event - safely enqueue FC HBA API event from irq context |
| 123 | * @adapter: The adapter where to enqueue the event |
| 124 | * @event_code: The event code (as defined in fc_host_event_code in |
| 125 | * scsi_transport_fc.h) |
| 126 | * @event_data: The event data (e.g. n_port page in case of els) |
| 127 | */ |
| 128 | void zfcp_fc_enqueue_event(struct zfcp_adapter *adapter, |
| 129 | enum fc_host_event_code event_code, u32 event_data) |
| 130 | { |
| 131 | struct zfcp_fc_event *event; |
| 132 | |
| 133 | event = kmalloc(sizeof(struct zfcp_fc_event), GFP_ATOMIC); |
| 134 | if (!event) |
| 135 | return; |
| 136 | |
| 137 | event->code = event_code; |
| 138 | event->data = event_data; |
| 139 | |
| 140 | spin_lock(&adapter->events.list_lock); |
| 141 | list_add_tail(&event->list, &adapter->events.list); |
| 142 | spin_unlock(&adapter->events.list_lock); |
| 143 | |
| 144 | queue_work(adapter->work_queue, &adapter->events.work); |
| 145 | } |
| 146 | |
Christof Schmitt | bd0072e | 2009-11-24 16:54:11 +0100 | [diff] [blame] | 147 | static int zfcp_fc_wka_port_get(struct zfcp_fc_wka_port *wka_port) |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 148 | { |
| 149 | if (mutex_lock_interruptible(&wka_port->mutex)) |
| 150 | return -ERESTARTSYS; |
| 151 | |
Christof Schmitt | bd0072e | 2009-11-24 16:54:11 +0100 | [diff] [blame] | 152 | if (wka_port->status == ZFCP_FC_WKA_PORT_OFFLINE || |
| 153 | wka_port->status == ZFCP_FC_WKA_PORT_CLOSING) { |
| 154 | wka_port->status = ZFCP_FC_WKA_PORT_OPENING; |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 155 | if (zfcp_fsf_open_wka_port(wka_port)) |
Christof Schmitt | bd0072e | 2009-11-24 16:54:11 +0100 | [diff] [blame] | 156 | wka_port->status = ZFCP_FC_WKA_PORT_OFFLINE; |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 157 | } |
| 158 | |
| 159 | mutex_unlock(&wka_port->mutex); |
| 160 | |
Swen Schillig | 27f492c | 2009-07-13 15:06:13 +0200 | [diff] [blame] | 161 | wait_event(wka_port->completion_wq, |
Christof Schmitt | bd0072e | 2009-11-24 16:54:11 +0100 | [diff] [blame] | 162 | wka_port->status == ZFCP_FC_WKA_PORT_ONLINE || |
| 163 | wka_port->status == ZFCP_FC_WKA_PORT_OFFLINE); |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 164 | |
Christof Schmitt | bd0072e | 2009-11-24 16:54:11 +0100 | [diff] [blame] | 165 | if (wka_port->status == ZFCP_FC_WKA_PORT_ONLINE) { |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 166 | atomic_inc(&wka_port->refcount); |
| 167 | return 0; |
| 168 | } |
| 169 | return -EIO; |
| 170 | } |
| 171 | |
Swen Schillig | 6f53a2d | 2009-08-18 15:43:23 +0200 | [diff] [blame] | 172 | static void zfcp_fc_wka_port_offline(struct work_struct *work) |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 173 | { |
Jean Delvare | bf6aede | 2009-04-02 16:56:54 -0700 | [diff] [blame] | 174 | struct delayed_work *dw = to_delayed_work(work); |
Christof Schmitt | bd0072e | 2009-11-24 16:54:11 +0100 | [diff] [blame] | 175 | struct zfcp_fc_wka_port *wka_port = |
| 176 | container_of(dw, struct zfcp_fc_wka_port, work); |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 177 | |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 178 | mutex_lock(&wka_port->mutex); |
| 179 | if ((atomic_read(&wka_port->refcount) != 0) || |
Christof Schmitt | bd0072e | 2009-11-24 16:54:11 +0100 | [diff] [blame] | 180 | (wka_port->status != ZFCP_FC_WKA_PORT_ONLINE)) |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 181 | goto out; |
| 182 | |
Christof Schmitt | bd0072e | 2009-11-24 16:54:11 +0100 | [diff] [blame] | 183 | wka_port->status = ZFCP_FC_WKA_PORT_CLOSING; |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 184 | if (zfcp_fsf_close_wka_port(wka_port)) { |
Christof Schmitt | bd0072e | 2009-11-24 16:54:11 +0100 | [diff] [blame] | 185 | wka_port->status = ZFCP_FC_WKA_PORT_OFFLINE; |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 186 | wake_up(&wka_port->completion_wq); |
| 187 | } |
| 188 | out: |
| 189 | mutex_unlock(&wka_port->mutex); |
| 190 | } |
| 191 | |
Christof Schmitt | bd0072e | 2009-11-24 16:54:11 +0100 | [diff] [blame] | 192 | static void zfcp_fc_wka_port_put(struct zfcp_fc_wka_port *wka_port) |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 193 | { |
| 194 | if (atomic_dec_return(&wka_port->refcount) != 0) |
| 195 | return; |
Martin Olsson | 19af5cd | 2009-04-23 11:37:37 +0200 | [diff] [blame] | 196 | /* wait 10 milliseconds, other reqs might pop in */ |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 197 | schedule_delayed_work(&wka_port->work, HZ / 100); |
| 198 | } |
| 199 | |
Christof Schmitt | bd0072e | 2009-11-24 16:54:11 +0100 | [diff] [blame] | 200 | static void zfcp_fc_wka_port_init(struct zfcp_fc_wka_port *wka_port, u32 d_id, |
Sven Schuetz | 9d544f2 | 2009-04-06 18:31:47 +0200 | [diff] [blame] | 201 | struct zfcp_adapter *adapter) |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 202 | { |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 203 | init_waitqueue_head(&wka_port->completion_wq); |
| 204 | |
| 205 | wka_port->adapter = adapter; |
Sven Schuetz | 9d544f2 | 2009-04-06 18:31:47 +0200 | [diff] [blame] | 206 | wka_port->d_id = d_id; |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 207 | |
Christof Schmitt | bd0072e | 2009-11-24 16:54:11 +0100 | [diff] [blame] | 208 | wka_port->status = ZFCP_FC_WKA_PORT_OFFLINE; |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 209 | atomic_set(&wka_port->refcount, 0); |
| 210 | mutex_init(&wka_port->mutex); |
Swen Schillig | 6f53a2d | 2009-08-18 15:43:23 +0200 | [diff] [blame] | 211 | INIT_DELAYED_WORK(&wka_port->work, zfcp_fc_wka_port_offline); |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 212 | } |
| 213 | |
Christof Schmitt | bd0072e | 2009-11-24 16:54:11 +0100 | [diff] [blame] | 214 | static void zfcp_fc_wka_port_force_offline(struct zfcp_fc_wka_port *wka) |
Swen Schillig | 828bc12 | 2009-04-17 15:08:05 +0200 | [diff] [blame] | 215 | { |
| 216 | cancel_delayed_work_sync(&wka->work); |
| 217 | mutex_lock(&wka->mutex); |
Christof Schmitt | bd0072e | 2009-11-24 16:54:11 +0100 | [diff] [blame] | 218 | wka->status = ZFCP_FC_WKA_PORT_OFFLINE; |
Swen Schillig | 828bc12 | 2009-04-17 15:08:05 +0200 | [diff] [blame] | 219 | mutex_unlock(&wka->mutex); |
| 220 | } |
| 221 | |
Christof Schmitt | bd0072e | 2009-11-24 16:54:11 +0100 | [diff] [blame] | 222 | void zfcp_fc_wka_ports_force_offline(struct zfcp_fc_wka_ports *gs) |
Christof Schmitt | 55c770f | 2009-08-18 15:43:12 +0200 | [diff] [blame] | 223 | { |
Swen Schillig | f3450c7 | 2009-11-24 16:53:59 +0100 | [diff] [blame] | 224 | if (!gs) |
| 225 | return; |
Christof Schmitt | 55c770f | 2009-08-18 15:43:12 +0200 | [diff] [blame] | 226 | zfcp_fc_wka_port_force_offline(&gs->ms); |
| 227 | zfcp_fc_wka_port_force_offline(&gs->ts); |
| 228 | zfcp_fc_wka_port_force_offline(&gs->ds); |
| 229 | zfcp_fc_wka_port_force_offline(&gs->as); |
Christof Schmitt | 55c770f | 2009-08-18 15:43:12 +0200 | [diff] [blame] | 230 | } |
| 231 | |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 232 | static void _zfcp_fc_incoming_rscn(struct zfcp_fsf_req *fsf_req, u32 range, |
Christof Schmitt | 9d05ce2 | 2009-11-24 16:54:09 +0100 | [diff] [blame] | 233 | struct fc_els_rscn_page *page) |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 234 | { |
| 235 | unsigned long flags; |
Swen Schillig | ecf0c77 | 2009-11-24 16:53:58 +0100 | [diff] [blame] | 236 | struct zfcp_adapter *adapter = fsf_req->adapter; |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 237 | struct zfcp_port *port; |
| 238 | |
Swen Schillig | ecf0c77 | 2009-11-24 16:53:58 +0100 | [diff] [blame] | 239 | read_lock_irqsave(&adapter->port_list_lock, flags); |
| 240 | list_for_each_entry(port, &adapter->port_list, list) { |
Christof Schmitt | 9d05ce2 | 2009-11-24 16:54:09 +0100 | [diff] [blame] | 241 | if ((port->d_id & range) == (ntoh24(page->rscn_fid) & range)) |
Swen Schillig | 6f53a2d | 2009-08-18 15:43:23 +0200 | [diff] [blame] | 242 | zfcp_fc_test_link(port); |
Swen Schillig | ea460a8 | 2009-05-15 13:18:20 +0200 | [diff] [blame] | 243 | if (!port->d_id) |
| 244 | zfcp_erp_port_reopen(port, |
| 245 | ZFCP_STATUS_COMMON_ERP_FAILED, |
Swen Schillig | ea4a3a6 | 2010-12-02 15:16:16 +0100 | [diff] [blame] | 246 | "fcrscn1"); |
Swen Schillig | ea460a8 | 2009-05-15 13:18:20 +0200 | [diff] [blame] | 247 | } |
Swen Schillig | ecf0c77 | 2009-11-24 16:53:58 +0100 | [diff] [blame] | 248 | read_unlock_irqrestore(&adapter->port_list_lock, flags); |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 249 | } |
| 250 | |
| 251 | static void zfcp_fc_incoming_rscn(struct zfcp_fsf_req *fsf_req) |
| 252 | { |
| 253 | struct fsf_status_read_buffer *status_buffer = (void *)fsf_req->data; |
Christof Schmitt | 9d05ce2 | 2009-11-24 16:54:09 +0100 | [diff] [blame] | 254 | struct fc_els_rscn *head; |
| 255 | struct fc_els_rscn_page *page; |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 256 | u16 i; |
| 257 | u16 no_entries; |
Christof Schmitt | 9d05ce2 | 2009-11-24 16:54:09 +0100 | [diff] [blame] | 258 | unsigned int afmt; |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 259 | |
Christof Schmitt | 9d05ce2 | 2009-11-24 16:54:09 +0100 | [diff] [blame] | 260 | head = (struct fc_els_rscn *) status_buffer->payload.data; |
| 261 | page = (struct fc_els_rscn_page *) head; |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 262 | |
| 263 | /* see FC-FS */ |
Steffen Maier | 9d464fc | 2017-07-28 12:31:02 +0200 | [diff] [blame] | 264 | no_entries = be16_to_cpu(head->rscn_plen) / |
| 265 | sizeof(struct fc_els_rscn_page); |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 266 | |
| 267 | for (i = 1; i < no_entries; i++) { |
| 268 | /* skip head and start with 1st element */ |
Christof Schmitt | 9d05ce2 | 2009-11-24 16:54:09 +0100 | [diff] [blame] | 269 | page++; |
| 270 | afmt = page->rscn_page_flags & ELS_RSCN_ADDR_FMT_MASK; |
| 271 | _zfcp_fc_incoming_rscn(fsf_req, zfcp_fc_rscn_range_mask[afmt], |
| 272 | page); |
Sven Schuetz | 2d1e547 | 2010-07-16 15:37:39 +0200 | [diff] [blame] | 273 | zfcp_fc_enqueue_event(fsf_req->adapter, FCH_EVT_RSCN, |
| 274 | *(u32 *)page); |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 275 | } |
Steffen Maier | 43f60cb | 2012-09-04 15:23:35 +0200 | [diff] [blame] | 276 | zfcp_fc_conditional_port_scan(fsf_req->adapter); |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 277 | } |
| 278 | |
Swen Schillig | 7ba58c9 | 2008-10-01 12:42:18 +0200 | [diff] [blame] | 279 | static void zfcp_fc_incoming_wwpn(struct zfcp_fsf_req *req, u64 wwpn) |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 280 | { |
Swen Schillig | ecf0c77 | 2009-11-24 16:53:58 +0100 | [diff] [blame] | 281 | unsigned long flags; |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 282 | struct zfcp_adapter *adapter = req->adapter; |
| 283 | struct zfcp_port *port; |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 284 | |
Swen Schillig | ecf0c77 | 2009-11-24 16:53:58 +0100 | [diff] [blame] | 285 | read_lock_irqsave(&adapter->port_list_lock, flags); |
| 286 | list_for_each_entry(port, &adapter->port_list, list) |
| 287 | if (port->wwpn == wwpn) { |
Swen Schillig | ea4a3a6 | 2010-12-02 15:16:16 +0100 | [diff] [blame] | 288 | zfcp_erp_port_forced_reopen(port, 0, "fciwwp1"); |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 289 | break; |
Swen Schillig | ecf0c77 | 2009-11-24 16:53:58 +0100 | [diff] [blame] | 290 | } |
| 291 | read_unlock_irqrestore(&adapter->port_list_lock, flags); |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 292 | } |
| 293 | |
| 294 | static void zfcp_fc_incoming_plogi(struct zfcp_fsf_req *req) |
| 295 | { |
Christof Schmitt | 9d05ce2 | 2009-11-24 16:54:09 +0100 | [diff] [blame] | 296 | struct fsf_status_read_buffer *status_buffer; |
| 297 | struct fc_els_flogi *plogi; |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 298 | |
Christof Schmitt | 9d05ce2 | 2009-11-24 16:54:09 +0100 | [diff] [blame] | 299 | status_buffer = (struct fsf_status_read_buffer *) req->data; |
| 300 | plogi = (struct fc_els_flogi *) status_buffer->payload.data; |
Steffen Maier | 9d464fc | 2017-07-28 12:31:02 +0200 | [diff] [blame] | 301 | zfcp_fc_incoming_wwpn(req, be64_to_cpu(plogi->fl_wwpn)); |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 302 | } |
| 303 | |
| 304 | static void zfcp_fc_incoming_logo(struct zfcp_fsf_req *req) |
| 305 | { |
| 306 | struct fsf_status_read_buffer *status_buffer = |
| 307 | (struct fsf_status_read_buffer *)req->data; |
Christof Schmitt | 9d05ce2 | 2009-11-24 16:54:09 +0100 | [diff] [blame] | 308 | struct fc_els_logo *logo = |
| 309 | (struct fc_els_logo *) status_buffer->payload.data; |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 310 | |
Steffen Maier | 9d464fc | 2017-07-28 12:31:02 +0200 | [diff] [blame] | 311 | zfcp_fc_incoming_wwpn(req, be64_to_cpu(logo->fl_n_port_wwn)); |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 312 | } |
| 313 | |
| 314 | /** |
| 315 | * zfcp_fc_incoming_els - handle incoming ELS |
| 316 | * @fsf_req - request which contains incoming ELS |
| 317 | */ |
| 318 | void zfcp_fc_incoming_els(struct zfcp_fsf_req *fsf_req) |
| 319 | { |
| 320 | struct fsf_status_read_buffer *status_buffer = |
| 321 | (struct fsf_status_read_buffer *) fsf_req->data; |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 322 | unsigned int els_type = status_buffer->payload.data[0]; |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 323 | |
Swen Schillig | 2c55b75 | 2010-12-02 15:16:13 +0100 | [diff] [blame] | 324 | zfcp_dbf_san_in_els("fciels1", fsf_req); |
Christof Schmitt | 9d05ce2 | 2009-11-24 16:54:09 +0100 | [diff] [blame] | 325 | if (els_type == ELS_PLOGI) |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 326 | zfcp_fc_incoming_plogi(fsf_req); |
Christof Schmitt | 9d05ce2 | 2009-11-24 16:54:09 +0100 | [diff] [blame] | 327 | else if (els_type == ELS_LOGO) |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 328 | zfcp_fc_incoming_logo(fsf_req); |
Christof Schmitt | 9d05ce2 | 2009-11-24 16:54:09 +0100 | [diff] [blame] | 329 | else if (els_type == ELS_RSCN) |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 330 | zfcp_fc_incoming_rscn(fsf_req); |
| 331 | } |
| 332 | |
Christof Schmitt | fcf7e61 | 2011-02-22 19:54:42 +0100 | [diff] [blame] | 333 | static void zfcp_fc_ns_gid_pn_eval(struct zfcp_fc_req *fc_req) |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 334 | { |
Christof Schmitt | fcf7e61 | 2011-02-22 19:54:42 +0100 | [diff] [blame] | 335 | struct zfcp_fsf_ct_els *ct_els = &fc_req->ct_els; |
| 336 | struct zfcp_fc_gid_pn_rsp *gid_pn_rsp = &fc_req->u.gid_pn.rsp; |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 337 | |
Christof Schmitt | fcf7e61 | 2011-02-22 19:54:42 +0100 | [diff] [blame] | 338 | if (ct_els->status) |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 339 | return; |
Steffen Maier | 9d464fc | 2017-07-28 12:31:02 +0200 | [diff] [blame] | 340 | if (gid_pn_rsp->ct_hdr.ct_cmd != cpu_to_be16(FC_FS_ACC)) |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 341 | return; |
Christof Schmitt | a5b11dd | 2009-03-02 13:08:54 +0100 | [diff] [blame] | 342 | |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 343 | /* looks like a valid d_id */ |
Christof Schmitt | fcf7e61 | 2011-02-22 19:54:42 +0100 | [diff] [blame] | 344 | ct_els->port->d_id = ntoh24(gid_pn_rsp->gid_pn.fp_fid); |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 345 | } |
| 346 | |
Christof Schmitt | 7c7dc19 | 2009-11-24 16:54:13 +0100 | [diff] [blame] | 347 | static void zfcp_fc_complete(void *data) |
| 348 | { |
| 349 | complete(data); |
| 350 | } |
| 351 | |
Christof Schmitt | fcf7e61 | 2011-02-22 19:54:42 +0100 | [diff] [blame] | 352 | static void zfcp_fc_ct_ns_init(struct fc_ct_hdr *ct_hdr, u16 cmd, u16 mr_size) |
| 353 | { |
| 354 | ct_hdr->ct_rev = FC_CT_REV; |
| 355 | ct_hdr->ct_fs_type = FC_FST_DIR; |
| 356 | ct_hdr->ct_fs_subtype = FC_NS_SUBTYPE; |
Steffen Maier | 9d464fc | 2017-07-28 12:31:02 +0200 | [diff] [blame] | 357 | ct_hdr->ct_cmd = cpu_to_be16(cmd); |
| 358 | ct_hdr->ct_mr_size = cpu_to_be16(mr_size / 4); |
Christof Schmitt | fcf7e61 | 2011-02-22 19:54:42 +0100 | [diff] [blame] | 359 | } |
| 360 | |
Christof Schmitt | 799b76d | 2009-08-18 15:43:20 +0200 | [diff] [blame] | 361 | static int zfcp_fc_ns_gid_pn_request(struct zfcp_port *port, |
Christof Schmitt | fcf7e61 | 2011-02-22 19:54:42 +0100 | [diff] [blame] | 362 | struct zfcp_fc_req *fc_req) |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 363 | { |
Christof Schmitt | 799b76d | 2009-08-18 15:43:20 +0200 | [diff] [blame] | 364 | struct zfcp_adapter *adapter = port->adapter; |
Christof Schmitt | 7c7dc19 | 2009-11-24 16:54:13 +0100 | [diff] [blame] | 365 | DECLARE_COMPLETION_ONSTACK(completion); |
Christof Schmitt | fcf7e61 | 2011-02-22 19:54:42 +0100 | [diff] [blame] | 366 | struct zfcp_fc_gid_pn_req *gid_pn_req = &fc_req->u.gid_pn.req; |
| 367 | struct zfcp_fc_gid_pn_rsp *gid_pn_rsp = &fc_req->u.gid_pn.rsp; |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 368 | int ret; |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 369 | |
| 370 | /* setup parameters for send generic command */ |
Christof Schmitt | fcf7e61 | 2011-02-22 19:54:42 +0100 | [diff] [blame] | 371 | fc_req->ct_els.port = port; |
| 372 | fc_req->ct_els.handler = zfcp_fc_complete; |
| 373 | fc_req->ct_els.handler_data = &completion; |
| 374 | fc_req->ct_els.req = &fc_req->sg_req; |
| 375 | fc_req->ct_els.resp = &fc_req->sg_rsp; |
| 376 | sg_init_one(&fc_req->sg_req, gid_pn_req, sizeof(*gid_pn_req)); |
| 377 | sg_init_one(&fc_req->sg_rsp, gid_pn_rsp, sizeof(*gid_pn_rsp)); |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 378 | |
Christof Schmitt | fcf7e61 | 2011-02-22 19:54:42 +0100 | [diff] [blame] | 379 | zfcp_fc_ct_ns_init(&gid_pn_req->ct_hdr, |
| 380 | FC_NS_GID_PN, ZFCP_FC_CT_SIZE_PAGE); |
Steffen Maier | 9d464fc | 2017-07-28 12:31:02 +0200 | [diff] [blame] | 381 | gid_pn_req->gid_pn.fn_wwpn = cpu_to_be64(port->wwpn); |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 382 | |
Christof Schmitt | fcf7e61 | 2011-02-22 19:54:42 +0100 | [diff] [blame] | 383 | ret = zfcp_fsf_send_ct(&adapter->gs->ds, &fc_req->ct_els, |
Swen Schillig | 51375ee | 2010-01-14 17:19:02 +0100 | [diff] [blame] | 384 | adapter->pool.gid_pn_req, |
| 385 | ZFCP_FC_CTELS_TMO); |
Christof Schmitt | 7c7dc19 | 2009-11-24 16:54:13 +0100 | [diff] [blame] | 386 | if (!ret) { |
| 387 | wait_for_completion(&completion); |
Christof Schmitt | fcf7e61 | 2011-02-22 19:54:42 +0100 | [diff] [blame] | 388 | zfcp_fc_ns_gid_pn_eval(fc_req); |
Christof Schmitt | 7c7dc19 | 2009-11-24 16:54:13 +0100 | [diff] [blame] | 389 | } |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 390 | return ret; |
| 391 | } |
| 392 | |
| 393 | /** |
Christof Schmitt | fcf7e61 | 2011-02-22 19:54:42 +0100 | [diff] [blame] | 394 | * zfcp_fc_ns_gid_pn - initiate GID_PN nameserver request |
Christof Schmitt | 799b76d | 2009-08-18 15:43:20 +0200 | [diff] [blame] | 395 | * @port: port where GID_PN request is needed |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 396 | * return: -ENOMEM on error, 0 otherwise |
| 397 | */ |
Christof Schmitt | 799b76d | 2009-08-18 15:43:20 +0200 | [diff] [blame] | 398 | static int zfcp_fc_ns_gid_pn(struct zfcp_port *port) |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 399 | { |
| 400 | int ret; |
Christof Schmitt | fcf7e61 | 2011-02-22 19:54:42 +0100 | [diff] [blame] | 401 | struct zfcp_fc_req *fc_req; |
Christof Schmitt | 799b76d | 2009-08-18 15:43:20 +0200 | [diff] [blame] | 402 | struct zfcp_adapter *adapter = port->adapter; |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 403 | |
Christof Schmitt | fcf7e61 | 2011-02-22 19:54:42 +0100 | [diff] [blame] | 404 | fc_req = mempool_alloc(adapter->pool.gid_pn, GFP_ATOMIC); |
| 405 | if (!fc_req) |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 406 | return -ENOMEM; |
| 407 | |
Christof Schmitt | fcf7e61 | 2011-02-22 19:54:42 +0100 | [diff] [blame] | 408 | memset(fc_req, 0, sizeof(*fc_req)); |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 409 | |
Swen Schillig | 6f53a2d | 2009-08-18 15:43:23 +0200 | [diff] [blame] | 410 | ret = zfcp_fc_wka_port_get(&adapter->gs->ds); |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 411 | if (ret) |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 412 | goto out; |
| 413 | |
Christof Schmitt | fcf7e61 | 2011-02-22 19:54:42 +0100 | [diff] [blame] | 414 | ret = zfcp_fc_ns_gid_pn_request(port, fc_req); |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 415 | |
Swen Schillig | 6f53a2d | 2009-08-18 15:43:23 +0200 | [diff] [blame] | 416 | zfcp_fc_wka_port_put(&adapter->gs->ds); |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 417 | out: |
Christof Schmitt | fcf7e61 | 2011-02-22 19:54:42 +0100 | [diff] [blame] | 418 | mempool_free(fc_req, adapter->pool.gid_pn); |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 419 | return ret; |
| 420 | } |
| 421 | |
Christof Schmitt | 799b76d | 2009-08-18 15:43:20 +0200 | [diff] [blame] | 422 | void zfcp_fc_port_did_lookup(struct work_struct *work) |
| 423 | { |
| 424 | int ret; |
| 425 | struct zfcp_port *port = container_of(work, struct zfcp_port, |
| 426 | gid_pn_work); |
| 427 | |
Steffen Maier | 5c750d5 | 2018-05-17 19:14:57 +0200 | [diff] [blame] | 428 | set_worker_desc("zgidpn%16llx", port->wwpn); /* < WORKER_DESC_LEN=24 */ |
Christof Schmitt | 799b76d | 2009-08-18 15:43:20 +0200 | [diff] [blame] | 429 | ret = zfcp_fc_ns_gid_pn(port); |
| 430 | if (ret) { |
| 431 | /* could not issue gid_pn for some reason */ |
Swen Schillig | ea4a3a6 | 2010-12-02 15:16:16 +0100 | [diff] [blame] | 432 | zfcp_erp_adapter_reopen(port->adapter, 0, "fcgpn_1"); |
Christof Schmitt | 799b76d | 2009-08-18 15:43:20 +0200 | [diff] [blame] | 433 | goto out; |
| 434 | } |
| 435 | |
| 436 | if (!port->d_id) { |
Swen Schillig | edaed85 | 2010-09-08 14:40:01 +0200 | [diff] [blame] | 437 | zfcp_erp_set_port_status(port, ZFCP_STATUS_COMMON_ERP_FAILED); |
Christof Schmitt | 799b76d | 2009-08-18 15:43:20 +0200 | [diff] [blame] | 438 | goto out; |
| 439 | } |
| 440 | |
Swen Schillig | ea4a3a6 | 2010-12-02 15:16:16 +0100 | [diff] [blame] | 441 | zfcp_erp_port_reopen(port, 0, "fcgpn_3"); |
Christof Schmitt | 799b76d | 2009-08-18 15:43:20 +0200 | [diff] [blame] | 442 | out: |
Christof Schmitt | 615f59e | 2010-02-17 11:18:56 +0100 | [diff] [blame] | 443 | put_device(&port->dev); |
Christof Schmitt | 799b76d | 2009-08-18 15:43:20 +0200 | [diff] [blame] | 444 | } |
| 445 | |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 446 | /** |
Christof Schmitt | 934aeb587 | 2009-10-14 11:00:43 +0200 | [diff] [blame] | 447 | * zfcp_fc_trigger_did_lookup - trigger the d_id lookup using a GID_PN request |
| 448 | * @port: The zfcp_port to lookup the d_id for. |
| 449 | */ |
| 450 | void zfcp_fc_trigger_did_lookup(struct zfcp_port *port) |
| 451 | { |
Christof Schmitt | 615f59e | 2010-02-17 11:18:56 +0100 | [diff] [blame] | 452 | get_device(&port->dev); |
Christof Schmitt | 934aeb587 | 2009-10-14 11:00:43 +0200 | [diff] [blame] | 453 | if (!queue_work(port->adapter->work_queue, &port->gid_pn_work)) |
Christof Schmitt | 615f59e | 2010-02-17 11:18:56 +0100 | [diff] [blame] | 454 | put_device(&port->dev); |
Christof Schmitt | 934aeb587 | 2009-10-14 11:00:43 +0200 | [diff] [blame] | 455 | } |
| 456 | |
| 457 | /** |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 458 | * zfcp_fc_plogi_evaluate - evaluate PLOGI playload |
| 459 | * @port: zfcp_port structure |
| 460 | * @plogi: plogi payload |
| 461 | * |
| 462 | * Evaluate PLOGI playload and copy important fields into zfcp_port structure |
| 463 | */ |
Christof Schmitt | 9d05ce2 | 2009-11-24 16:54:09 +0100 | [diff] [blame] | 464 | void zfcp_fc_plogi_evaluate(struct zfcp_port *port, struct fc_els_flogi *plogi) |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 465 | { |
Steffen Maier | 9d464fc | 2017-07-28 12:31:02 +0200 | [diff] [blame] | 466 | if (be64_to_cpu(plogi->fl_wwpn) != port->wwpn) { |
Christof Schmitt | 9d05ce2 | 2009-11-24 16:54:09 +0100 | [diff] [blame] | 467 | port->d_id = 0; |
| 468 | dev_warn(&port->adapter->ccw_device->dev, |
| 469 | "A port opened with WWPN 0x%016Lx returned data that " |
| 470 | "identifies it as WWPN 0x%016Lx\n", |
| 471 | (unsigned long long) port->wwpn, |
Steffen Maier | 9d464fc | 2017-07-28 12:31:02 +0200 | [diff] [blame] | 472 | (unsigned long long) be64_to_cpu(plogi->fl_wwpn)); |
Christof Schmitt | 9d05ce2 | 2009-11-24 16:54:09 +0100 | [diff] [blame] | 473 | return; |
| 474 | } |
| 475 | |
Steffen Maier | 9d464fc | 2017-07-28 12:31:02 +0200 | [diff] [blame] | 476 | port->wwnn = be64_to_cpu(plogi->fl_wwnn); |
| 477 | port->maxframe_size = be16_to_cpu(plogi->fl_csp.sp_bb_data); |
Christof Schmitt | 9d05ce2 | 2009-11-24 16:54:09 +0100 | [diff] [blame] | 478 | |
Steffen Maier | 9d464fc | 2017-07-28 12:31:02 +0200 | [diff] [blame] | 479 | if (plogi->fl_cssp[0].cp_class & cpu_to_be16(FC_CPC_VALID)) |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 480 | port->supported_classes |= FC_COS_CLASS1; |
Steffen Maier | 9d464fc | 2017-07-28 12:31:02 +0200 | [diff] [blame] | 481 | if (plogi->fl_cssp[1].cp_class & cpu_to_be16(FC_CPC_VALID)) |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 482 | port->supported_classes |= FC_COS_CLASS2; |
Steffen Maier | 9d464fc | 2017-07-28 12:31:02 +0200 | [diff] [blame] | 483 | if (plogi->fl_cssp[2].cp_class & cpu_to_be16(FC_CPC_VALID)) |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 484 | port->supported_classes |= FC_COS_CLASS3; |
Steffen Maier | 9d464fc | 2017-07-28 12:31:02 +0200 | [diff] [blame] | 485 | if (plogi->fl_cssp[3].cp_class & cpu_to_be16(FC_CPC_VALID)) |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 486 | port->supported_classes |= FC_COS_CLASS4; |
| 487 | } |
| 488 | |
Christof Schmitt | 7c7dc19 | 2009-11-24 16:54:13 +0100 | [diff] [blame] | 489 | static void zfcp_fc_adisc_handler(void *data) |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 490 | { |
Christof Schmitt | 087897e | 2011-02-22 19:54:41 +0100 | [diff] [blame] | 491 | struct zfcp_fc_req *fc_req = data; |
| 492 | struct zfcp_port *port = fc_req->ct_els.port; |
| 493 | struct fc_els_adisc *adisc_resp = &fc_req->u.adisc.rsp; |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 494 | |
Christof Schmitt | 087897e | 2011-02-22 19:54:41 +0100 | [diff] [blame] | 495 | if (fc_req->ct_els.status) { |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 496 | /* request rejected or timed out */ |
Swen Schillig | 5b43e71 | 2009-04-17 15:08:10 +0200 | [diff] [blame] | 497 | zfcp_erp_port_forced_reopen(port, ZFCP_STATUS_COMMON_ERP_FAILED, |
Swen Schillig | ea4a3a6 | 2010-12-02 15:16:16 +0100 | [diff] [blame] | 498 | "fcadh_1"); |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 499 | goto out; |
| 500 | } |
| 501 | |
| 502 | if (!port->wwnn) |
Steffen Maier | 9d464fc | 2017-07-28 12:31:02 +0200 | [diff] [blame] | 503 | port->wwnn = be64_to_cpu(adisc_resp->adisc_wwnn); |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 504 | |
Steffen Maier | 9d464fc | 2017-07-28 12:31:02 +0200 | [diff] [blame] | 505 | if ((port->wwpn != be64_to_cpu(adisc_resp->adisc_wwpn)) || |
Christof Schmitt | a2fa0ae | 2009-03-02 13:09:08 +0100 | [diff] [blame] | 506 | !(atomic_read(&port->status) & ZFCP_STATUS_COMMON_OPEN)) { |
Swen Schillig | 2409549 | 2009-03-02 13:09:07 +0100 | [diff] [blame] | 507 | zfcp_erp_port_reopen(port, ZFCP_STATUS_COMMON_ERP_FAILED, |
Swen Schillig | ea4a3a6 | 2010-12-02 15:16:16 +0100 | [diff] [blame] | 508 | "fcadh_2"); |
Christof Schmitt | a2fa0ae | 2009-03-02 13:09:08 +0100 | [diff] [blame] | 509 | goto out; |
| 510 | } |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 511 | |
Christof Schmitt | a2fa0ae | 2009-03-02 13:09:08 +0100 | [diff] [blame] | 512 | /* port is good, unblock rport without going through erp */ |
| 513 | zfcp_scsi_schedule_rport_register(port); |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 514 | out: |
Peter Zijlstra | 805de8f4 | 2015-04-24 01:12:32 +0200 | [diff] [blame] | 515 | atomic_andnot(ZFCP_STATUS_PORT_LINK_TEST, &port->status); |
Christof Schmitt | 615f59e | 2010-02-17 11:18:56 +0100 | [diff] [blame] | 516 | put_device(&port->dev); |
Christof Schmitt | 087897e | 2011-02-22 19:54:41 +0100 | [diff] [blame] | 517 | kmem_cache_free(zfcp_fc_req_cache, fc_req); |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 518 | } |
| 519 | |
| 520 | static int zfcp_fc_adisc(struct zfcp_port *port) |
| 521 | { |
Christof Schmitt | 087897e | 2011-02-22 19:54:41 +0100 | [diff] [blame] | 522 | struct zfcp_fc_req *fc_req; |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 523 | struct zfcp_adapter *adapter = port->adapter; |
Christof Schmitt | 087897e | 2011-02-22 19:54:41 +0100 | [diff] [blame] | 524 | struct Scsi_Host *shost = adapter->scsi_host; |
Christof Schmitt | ee74462 | 2009-11-24 16:54:14 +0100 | [diff] [blame] | 525 | int ret; |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 526 | |
Christof Schmitt | 087897e | 2011-02-22 19:54:41 +0100 | [diff] [blame] | 527 | fc_req = kmem_cache_zalloc(zfcp_fc_req_cache, GFP_ATOMIC); |
| 528 | if (!fc_req) |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 529 | return -ENOMEM; |
| 530 | |
Christof Schmitt | 087897e | 2011-02-22 19:54:41 +0100 | [diff] [blame] | 531 | fc_req->ct_els.port = port; |
| 532 | fc_req->ct_els.req = &fc_req->sg_req; |
| 533 | fc_req->ct_els.resp = &fc_req->sg_rsp; |
| 534 | sg_init_one(&fc_req->sg_req, &fc_req->u.adisc.req, |
Christof Schmitt | 9d05ce2 | 2009-11-24 16:54:09 +0100 | [diff] [blame] | 535 | sizeof(struct fc_els_adisc)); |
Christof Schmitt | 087897e | 2011-02-22 19:54:41 +0100 | [diff] [blame] | 536 | sg_init_one(&fc_req->sg_rsp, &fc_req->u.adisc.rsp, |
Christof Schmitt | 9d05ce2 | 2009-11-24 16:54:09 +0100 | [diff] [blame] | 537 | sizeof(struct fc_els_adisc)); |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 538 | |
Christof Schmitt | 087897e | 2011-02-22 19:54:41 +0100 | [diff] [blame] | 539 | fc_req->ct_els.handler = zfcp_fc_adisc_handler; |
| 540 | fc_req->ct_els.handler_data = fc_req; |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 541 | |
| 542 | /* acc. to FC-FS, hard_nport_id in ADISC should not be set for ports |
| 543 | without FC-AL-2 capability, so we don't set it */ |
Steffen Maier | 9d464fc | 2017-07-28 12:31:02 +0200 | [diff] [blame] | 544 | fc_req->u.adisc.req.adisc_wwpn = cpu_to_be64(fc_host_port_name(shost)); |
| 545 | fc_req->u.adisc.req.adisc_wwnn = cpu_to_be64(fc_host_node_name(shost)); |
Christof Schmitt | 087897e | 2011-02-22 19:54:41 +0100 | [diff] [blame] | 546 | fc_req->u.adisc.req.adisc_cmd = ELS_ADISC; |
| 547 | hton24(fc_req->u.adisc.req.adisc_port_id, fc_host_port_id(shost)); |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 548 | |
Christof Schmitt | 087897e | 2011-02-22 19:54:41 +0100 | [diff] [blame] | 549 | ret = zfcp_fsf_send_els(adapter, port->d_id, &fc_req->ct_els, |
Swen Schillig | 51375ee | 2010-01-14 17:19:02 +0100 | [diff] [blame] | 550 | ZFCP_FC_CTELS_TMO); |
Christof Schmitt | ee74462 | 2009-11-24 16:54:14 +0100 | [diff] [blame] | 551 | if (ret) |
Christof Schmitt | 087897e | 2011-02-22 19:54:41 +0100 | [diff] [blame] | 552 | kmem_cache_free(zfcp_fc_req_cache, fc_req); |
Christof Schmitt | ee74462 | 2009-11-24 16:54:14 +0100 | [diff] [blame] | 553 | |
| 554 | return ret; |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 555 | } |
| 556 | |
Christof Schmitt | 8fdf30d | 2009-03-02 13:09:01 +0100 | [diff] [blame] | 557 | void zfcp_fc_link_test_work(struct work_struct *work) |
| 558 | { |
| 559 | struct zfcp_port *port = |
| 560 | container_of(work, struct zfcp_port, test_link_work); |
| 561 | int retval; |
| 562 | |
Steffen Maier | 5c750d5 | 2018-05-17 19:14:57 +0200 | [diff] [blame] | 563 | set_worker_desc("zadisc%16llx", port->wwpn); /* < WORKER_DESC_LEN=24 */ |
Christof Schmitt | 615f59e | 2010-02-17 11:18:56 +0100 | [diff] [blame] | 564 | get_device(&port->dev); |
Christof Schmitt | a2fa0ae | 2009-03-02 13:09:08 +0100 | [diff] [blame] | 565 | port->rport_task = RPORT_DEL; |
| 566 | zfcp_scsi_rport_work(&port->rport_work); |
| 567 | |
Christof Schmitt | 14e242e | 2009-08-18 15:43:11 +0200 | [diff] [blame] | 568 | /* only issue one test command at one time per port */ |
| 569 | if (atomic_read(&port->status) & ZFCP_STATUS_PORT_LINK_TEST) |
| 570 | goto out; |
| 571 | |
Peter Zijlstra | 805de8f4 | 2015-04-24 01:12:32 +0200 | [diff] [blame] | 572 | atomic_or(ZFCP_STATUS_PORT_LINK_TEST, &port->status); |
Christof Schmitt | 14e242e | 2009-08-18 15:43:11 +0200 | [diff] [blame] | 573 | |
Christof Schmitt | 8fdf30d | 2009-03-02 13:09:01 +0100 | [diff] [blame] | 574 | retval = zfcp_fc_adisc(port); |
| 575 | if (retval == 0) |
| 576 | return; |
| 577 | |
| 578 | /* send of ADISC was not possible */ |
Peter Zijlstra | 805de8f4 | 2015-04-24 01:12:32 +0200 | [diff] [blame] | 579 | atomic_andnot(ZFCP_STATUS_PORT_LINK_TEST, &port->status); |
Swen Schillig | ea4a3a6 | 2010-12-02 15:16:16 +0100 | [diff] [blame] | 580 | zfcp_erp_port_forced_reopen(port, 0, "fcltwk1"); |
Christof Schmitt | a2fa0ae | 2009-03-02 13:09:08 +0100 | [diff] [blame] | 581 | |
Christof Schmitt | 14e242e | 2009-08-18 15:43:11 +0200 | [diff] [blame] | 582 | out: |
Christof Schmitt | 615f59e | 2010-02-17 11:18:56 +0100 | [diff] [blame] | 583 | put_device(&port->dev); |
Christof Schmitt | 8fdf30d | 2009-03-02 13:09:01 +0100 | [diff] [blame] | 584 | } |
| 585 | |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 586 | /** |
Swen Schillig | 6f53a2d | 2009-08-18 15:43:23 +0200 | [diff] [blame] | 587 | * zfcp_fc_test_link - lightweight link test procedure |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 588 | * @port: port to be tested |
| 589 | * |
| 590 | * Test status of a link to a remote port using the ELS command ADISC. |
| 591 | * If there is a problem with the remote port, error recovery steps |
| 592 | * will be triggered. |
| 593 | */ |
Swen Schillig | 6f53a2d | 2009-08-18 15:43:23 +0200 | [diff] [blame] | 594 | void zfcp_fc_test_link(struct zfcp_port *port) |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 595 | { |
Christof Schmitt | 615f59e | 2010-02-17 11:18:56 +0100 | [diff] [blame] | 596 | get_device(&port->dev); |
Swen Schillig | 4544683 | 2009-08-18 15:43:17 +0200 | [diff] [blame] | 597 | if (!queue_work(port->adapter->work_queue, &port->test_link_work)) |
Christof Schmitt | 615f59e | 2010-02-17 11:18:56 +0100 | [diff] [blame] | 598 | put_device(&port->dev); |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 599 | } |
Swen Schillig | cc8c282 | 2008-06-10 18:21:00 +0200 | [diff] [blame] | 600 | |
Steffen Maier | d39eda5 | 2018-05-17 19:14:58 +0200 | [diff] [blame^] | 601 | static struct zfcp_fc_req *zfcp_fc_alloc_sg_env(int buf_num) |
Swen Schillig | cc8c282 | 2008-06-10 18:21:00 +0200 | [diff] [blame] | 602 | { |
Christof Schmitt | f977322 | 2011-02-22 19:54:43 +0100 | [diff] [blame] | 603 | struct zfcp_fc_req *fc_req; |
Swen Schillig | cc8c282 | 2008-06-10 18:21:00 +0200 | [diff] [blame] | 604 | |
Christof Schmitt | f977322 | 2011-02-22 19:54:43 +0100 | [diff] [blame] | 605 | fc_req = kmem_cache_zalloc(zfcp_fc_req_cache, GFP_KERNEL); |
| 606 | if (!fc_req) |
Swen Schillig | cc8c282 | 2008-06-10 18:21:00 +0200 | [diff] [blame] | 607 | return NULL; |
| 608 | |
Christof Schmitt | f977322 | 2011-02-22 19:54:43 +0100 | [diff] [blame] | 609 | if (zfcp_sg_setup_table(&fc_req->sg_rsp, buf_num)) { |
| 610 | kmem_cache_free(zfcp_fc_req_cache, fc_req); |
| 611 | return NULL; |
Swen Schillig | cc8c282 | 2008-06-10 18:21:00 +0200 | [diff] [blame] | 612 | } |
Swen Schillig | cc8c282 | 2008-06-10 18:21:00 +0200 | [diff] [blame] | 613 | |
Christof Schmitt | f977322 | 2011-02-22 19:54:43 +0100 | [diff] [blame] | 614 | sg_init_one(&fc_req->sg_req, &fc_req->u.gpn_ft.req, |
| 615 | sizeof(struct zfcp_fc_gpn_ft_req)); |
| 616 | |
| 617 | return fc_req; |
Swen Schillig | cc8c282 | 2008-06-10 18:21:00 +0200 | [diff] [blame] | 618 | } |
| 619 | |
Christof Schmitt | f977322 | 2011-02-22 19:54:43 +0100 | [diff] [blame] | 620 | static int zfcp_fc_send_gpn_ft(struct zfcp_fc_req *fc_req, |
Swen Schillig | 6f53a2d | 2009-08-18 15:43:23 +0200 | [diff] [blame] | 621 | struct zfcp_adapter *adapter, int max_bytes) |
Swen Schillig | cc8c282 | 2008-06-10 18:21:00 +0200 | [diff] [blame] | 622 | { |
Christof Schmitt | f977322 | 2011-02-22 19:54:43 +0100 | [diff] [blame] | 623 | struct zfcp_fsf_ct_els *ct_els = &fc_req->ct_els; |
| 624 | struct zfcp_fc_gpn_ft_req *req = &fc_req->u.gpn_ft.req; |
Christof Schmitt | 7c7dc19 | 2009-11-24 16:54:13 +0100 | [diff] [blame] | 625 | DECLARE_COMPLETION_ONSTACK(completion); |
Swen Schillig | cc8c282 | 2008-06-10 18:21:00 +0200 | [diff] [blame] | 626 | int ret; |
| 627 | |
Christof Schmitt | f977322 | 2011-02-22 19:54:43 +0100 | [diff] [blame] | 628 | zfcp_fc_ct_ns_init(&req->ct_hdr, FC_NS_GPN_FT, max_bytes); |
Christof Schmitt | dbf5dfe | 2009-11-24 16:54:10 +0100 | [diff] [blame] | 629 | req->gpn_ft.fn_fc4_type = FC_TYPE_FCP; |
Swen Schillig | cc8c282 | 2008-06-10 18:21:00 +0200 | [diff] [blame] | 630 | |
Christof Schmitt | f977322 | 2011-02-22 19:54:43 +0100 | [diff] [blame] | 631 | ct_els->handler = zfcp_fc_complete; |
| 632 | ct_els->handler_data = &completion; |
| 633 | ct_els->req = &fc_req->sg_req; |
| 634 | ct_els->resp = &fc_req->sg_rsp; |
Swen Schillig | cc8c282 | 2008-06-10 18:21:00 +0200 | [diff] [blame] | 635 | |
Christof Schmitt | f977322 | 2011-02-22 19:54:43 +0100 | [diff] [blame] | 636 | ret = zfcp_fsf_send_ct(&adapter->gs->ds, ct_els, NULL, |
Swen Schillig | 51375ee | 2010-01-14 17:19:02 +0100 | [diff] [blame] | 637 | ZFCP_FC_CTELS_TMO); |
Swen Schillig | cc8c282 | 2008-06-10 18:21:00 +0200 | [diff] [blame] | 638 | if (!ret) |
Christof Schmitt | 7c7dc19 | 2009-11-24 16:54:13 +0100 | [diff] [blame] | 639 | wait_for_completion(&completion); |
Swen Schillig | cc8c282 | 2008-06-10 18:21:00 +0200 | [diff] [blame] | 640 | return ret; |
| 641 | } |
| 642 | |
Swen Schillig | f3450c7 | 2009-11-24 16:53:59 +0100 | [diff] [blame] | 643 | static void zfcp_fc_validate_port(struct zfcp_port *port, struct list_head *lh) |
Swen Schillig | cc8c282 | 2008-06-10 18:21:00 +0200 | [diff] [blame] | 644 | { |
Martin Petermann | 6ab35c0 | 2009-04-17 15:08:13 +0200 | [diff] [blame] | 645 | if (!(atomic_read(&port->status) & ZFCP_STATUS_COMMON_NOESC)) |
| 646 | return; |
| 647 | |
Peter Zijlstra | 805de8f4 | 2015-04-24 01:12:32 +0200 | [diff] [blame] | 648 | atomic_andnot(ZFCP_STATUS_COMMON_NOESC, &port->status); |
Swen Schillig | cc8c282 | 2008-06-10 18:21:00 +0200 | [diff] [blame] | 649 | |
Christof Schmitt | 0406289 | 2008-10-01 12:42:20 +0200 | [diff] [blame] | 650 | if ((port->supported_classes != 0) || |
Swen Schillig | f3450c7 | 2009-11-24 16:53:59 +0100 | [diff] [blame] | 651 | !list_empty(&port->unit_list)) |
Swen Schillig | cc8c282 | 2008-06-10 18:21:00 +0200 | [diff] [blame] | 652 | return; |
Swen Schillig | f3450c7 | 2009-11-24 16:53:59 +0100 | [diff] [blame] | 653 | |
Swen Schillig | f3450c7 | 2009-11-24 16:53:59 +0100 | [diff] [blame] | 654 | list_move_tail(&port->list, lh); |
Swen Schillig | cc8c282 | 2008-06-10 18:21:00 +0200 | [diff] [blame] | 655 | } |
| 656 | |
Christof Schmitt | f977322 | 2011-02-22 19:54:43 +0100 | [diff] [blame] | 657 | static int zfcp_fc_eval_gpn_ft(struct zfcp_fc_req *fc_req, |
Christof Schmitt | 7c7dc19 | 2009-11-24 16:54:13 +0100 | [diff] [blame] | 658 | struct zfcp_adapter *adapter, int max_entries) |
Swen Schillig | cc8c282 | 2008-06-10 18:21:00 +0200 | [diff] [blame] | 659 | { |
Christof Schmitt | f977322 | 2011-02-22 19:54:43 +0100 | [diff] [blame] | 660 | struct zfcp_fsf_ct_els *ct_els = &fc_req->ct_els; |
| 661 | struct scatterlist *sg = &fc_req->sg_rsp; |
Christof Schmitt | dbf5dfe | 2009-11-24 16:54:10 +0100 | [diff] [blame] | 662 | struct fc_ct_hdr *hdr = sg_virt(sg); |
| 663 | struct fc_gpn_ft_resp *acc = sg_virt(sg); |
Swen Schillig | cc8c282 | 2008-06-10 18:21:00 +0200 | [diff] [blame] | 664 | struct zfcp_port *port, *tmp; |
Swen Schillig | ecf0c77 | 2009-11-24 16:53:58 +0100 | [diff] [blame] | 665 | unsigned long flags; |
Swen Schillig | f3450c7 | 2009-11-24 16:53:59 +0100 | [diff] [blame] | 666 | LIST_HEAD(remove_lh); |
Swen Schillig | cc8c282 | 2008-06-10 18:21:00 +0200 | [diff] [blame] | 667 | u32 d_id; |
Christof Schmitt | 47f7bba | 2008-08-21 13:43:33 +0200 | [diff] [blame] | 668 | int ret = 0, x, last = 0; |
Swen Schillig | cc8c282 | 2008-06-10 18:21:00 +0200 | [diff] [blame] | 669 | |
Christof Schmitt | f977322 | 2011-02-22 19:54:43 +0100 | [diff] [blame] | 670 | if (ct_els->status) |
Swen Schillig | cc8c282 | 2008-06-10 18:21:00 +0200 | [diff] [blame] | 671 | return -EIO; |
| 672 | |
Steffen Maier | 9d464fc | 2017-07-28 12:31:02 +0200 | [diff] [blame] | 673 | if (hdr->ct_cmd != cpu_to_be16(FC_FS_ACC)) { |
Steffen Maier | ab8ab4b | 2017-07-28 12:30:59 +0200 | [diff] [blame] | 674 | if (hdr->ct_reason == FC_FS_RJT_UNABL) |
Swen Schillig | cc8c282 | 2008-06-10 18:21:00 +0200 | [diff] [blame] | 675 | return -EAGAIN; /* might be a temporary condition */ |
| 676 | return -EIO; |
| 677 | } |
| 678 | |
Christof Schmitt | dbf5dfe | 2009-11-24 16:54:10 +0100 | [diff] [blame] | 679 | if (hdr->ct_mr_size) { |
Christof Schmitt | 39eb7e9a | 2008-12-19 16:57:01 +0100 | [diff] [blame] | 680 | dev_warn(&adapter->ccw_device->dev, |
| 681 | "The name server reported %d words residual data\n", |
Christof Schmitt | dbf5dfe | 2009-11-24 16:54:10 +0100 | [diff] [blame] | 682 | hdr->ct_mr_size); |
Swen Schillig | cc8c282 | 2008-06-10 18:21:00 +0200 | [diff] [blame] | 683 | return -E2BIG; |
Christof Schmitt | 39eb7e9a | 2008-12-19 16:57:01 +0100 | [diff] [blame] | 684 | } |
Swen Schillig | cc8c282 | 2008-06-10 18:21:00 +0200 | [diff] [blame] | 685 | |
Swen Schillig | cc8c282 | 2008-06-10 18:21:00 +0200 | [diff] [blame] | 686 | /* first entry is the header */ |
Christof Schmitt | 39eb7e9a | 2008-12-19 16:57:01 +0100 | [diff] [blame] | 687 | for (x = 1; x < max_entries && !last; x++) { |
Christof Schmitt | dbf5dfe | 2009-11-24 16:54:10 +0100 | [diff] [blame] | 688 | if (x % (ZFCP_FC_GPN_FT_ENT_PAGE + 1)) |
Swen Schillig | cc8c282 | 2008-06-10 18:21:00 +0200 | [diff] [blame] | 689 | acc++; |
| 690 | else |
| 691 | acc = sg_virt(++sg); |
| 692 | |
Christof Schmitt | dbf5dfe | 2009-11-24 16:54:10 +0100 | [diff] [blame] | 693 | last = acc->fp_flags & FC_NS_FID_LAST; |
| 694 | d_id = ntoh24(acc->fp_fid); |
Swen Schillig | cc8c282 | 2008-06-10 18:21:00 +0200 | [diff] [blame] | 695 | |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 696 | /* don't attach ports with a well known address */ |
Christof Schmitt | dbf5dfe | 2009-11-24 16:54:10 +0100 | [diff] [blame] | 697 | if (d_id >= FC_FID_WELL_KNOWN_BASE) |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 698 | continue; |
Swen Schillig | cc8c282 | 2008-06-10 18:21:00 +0200 | [diff] [blame] | 699 | /* skip the adapter's port and known remote ports */ |
Steffen Maier | 9d464fc | 2017-07-28 12:31:02 +0200 | [diff] [blame] | 700 | if (be64_to_cpu(acc->fp_wwpn) == |
| 701 | fc_host_port_name(adapter->scsi_host)) |
Swen Schillig | cc8c282 | 2008-06-10 18:21:00 +0200 | [diff] [blame] | 702 | continue; |
| 703 | |
Steffen Maier | 9d464fc | 2017-07-28 12:31:02 +0200 | [diff] [blame] | 704 | port = zfcp_port_enqueue(adapter, be64_to_cpu(acc->fp_wwpn), |
Swen Schillig | cc8c282 | 2008-06-10 18:21:00 +0200 | [diff] [blame] | 705 | ZFCP_STATUS_COMMON_NOESC, d_id); |
Swen Schillig | ecf0c77 | 2009-11-24 16:53:58 +0100 | [diff] [blame] | 706 | if (!IS_ERR(port)) |
Swen Schillig | ea4a3a6 | 2010-12-02 15:16:16 +0100 | [diff] [blame] | 707 | zfcp_erp_port_reopen(port, 0, "fcegpf1"); |
Swen Schillig | ecf0c77 | 2009-11-24 16:53:58 +0100 | [diff] [blame] | 708 | else if (PTR_ERR(port) != -EEXIST) |
| 709 | ret = PTR_ERR(port); |
Swen Schillig | cc8c282 | 2008-06-10 18:21:00 +0200 | [diff] [blame] | 710 | } |
| 711 | |
| 712 | zfcp_erp_wait(adapter); |
Swen Schillig | ecf0c77 | 2009-11-24 16:53:58 +0100 | [diff] [blame] | 713 | write_lock_irqsave(&adapter->port_list_lock, flags); |
| 714 | list_for_each_entry_safe(port, tmp, &adapter->port_list, list) |
Swen Schillig | f3450c7 | 2009-11-24 16:53:59 +0100 | [diff] [blame] | 715 | zfcp_fc_validate_port(port, &remove_lh); |
Swen Schillig | ecf0c77 | 2009-11-24 16:53:58 +0100 | [diff] [blame] | 716 | write_unlock_irqrestore(&adapter->port_list_lock, flags); |
Swen Schillig | f3450c7 | 2009-11-24 16:53:59 +0100 | [diff] [blame] | 717 | |
| 718 | list_for_each_entry_safe(port, tmp, &remove_lh, list) { |
Swen Schillig | ea4a3a6 | 2010-12-02 15:16:16 +0100 | [diff] [blame] | 719 | zfcp_erp_port_shutdown(port, 0, "fcegpf2"); |
Sebastian Ott | 83d4e1c | 2013-04-26 16:13:48 +0200 | [diff] [blame] | 720 | device_unregister(&port->dev); |
Swen Schillig | f3450c7 | 2009-11-24 16:53:59 +0100 | [diff] [blame] | 721 | } |
| 722 | |
Swen Schillig | cc8c282 | 2008-06-10 18:21:00 +0200 | [diff] [blame] | 723 | return ret; |
| 724 | } |
| 725 | |
| 726 | /** |
Swen Schillig | 6f53a2d | 2009-08-18 15:43:23 +0200 | [diff] [blame] | 727 | * zfcp_fc_scan_ports - scan remote ports and attach new ports |
Swen Schillig | 9eae07e | 2009-11-24 16:54:06 +0100 | [diff] [blame] | 728 | * @work: reference to scheduled work |
Swen Schillig | cc8c282 | 2008-06-10 18:21:00 +0200 | [diff] [blame] | 729 | */ |
Swen Schillig | 9eae07e | 2009-11-24 16:54:06 +0100 | [diff] [blame] | 730 | void zfcp_fc_scan_ports(struct work_struct *work) |
Swen Schillig | cc8c282 | 2008-06-10 18:21:00 +0200 | [diff] [blame] | 731 | { |
Martin Peschke | 18f87a6 | 2014-11-13 14:59:48 +0100 | [diff] [blame] | 732 | struct delayed_work *dw = to_delayed_work(work); |
| 733 | struct zfcp_adapter *adapter = container_of(dw, struct zfcp_adapter, |
Swen Schillig | 9eae07e | 2009-11-24 16:54:06 +0100 | [diff] [blame] | 734 | scan_work); |
Swen Schillig | cc8c282 | 2008-06-10 18:21:00 +0200 | [diff] [blame] | 735 | int ret, i; |
Christof Schmitt | f977322 | 2011-02-22 19:54:43 +0100 | [diff] [blame] | 736 | struct zfcp_fc_req *fc_req; |
Christof Schmitt | 39eb7e9a | 2008-12-19 16:57:01 +0100 | [diff] [blame] | 737 | int chain, max_entries, buf_num, max_bytes; |
| 738 | |
Martin Peschke | 18f87a6 | 2014-11-13 14:59:48 +0100 | [diff] [blame] | 739 | zfcp_fc_port_scan_time(adapter); |
| 740 | |
Christof Schmitt | 39eb7e9a | 2008-12-19 16:57:01 +0100 | [diff] [blame] | 741 | chain = adapter->adapter_features & FSF_FEATURE_ELS_CT_CHAINED_SBALS; |
Christof Schmitt | dbf5dfe | 2009-11-24 16:54:10 +0100 | [diff] [blame] | 742 | buf_num = chain ? ZFCP_FC_GPN_FT_NUM_BUFS : 1; |
| 743 | max_entries = chain ? ZFCP_FC_GPN_FT_MAX_ENT : ZFCP_FC_GPN_FT_ENT_PAGE; |
| 744 | max_bytes = chain ? ZFCP_FC_GPN_FT_MAX_SIZE : ZFCP_FC_CT_SIZE_PAGE; |
Swen Schillig | cc8c282 | 2008-06-10 18:21:00 +0200 | [diff] [blame] | 745 | |
Swen Schillig | 306b6ed | 2009-04-17 15:08:02 +0200 | [diff] [blame] | 746 | if (fc_host_port_type(adapter->scsi_host) != FC_PORTTYPE_NPORT && |
| 747 | fc_host_port_type(adapter->scsi_host) != FC_PORTTYPE_NPIV) |
Swen Schillig | 9eae07e | 2009-11-24 16:54:06 +0100 | [diff] [blame] | 748 | return; |
Swen Schillig | cc8c282 | 2008-06-10 18:21:00 +0200 | [diff] [blame] | 749 | |
Swen Schillig | 9eae07e | 2009-11-24 16:54:06 +0100 | [diff] [blame] | 750 | if (zfcp_fc_wka_port_get(&adapter->gs->ds)) |
| 751 | return; |
Swen Schillig | cc8c282 | 2008-06-10 18:21:00 +0200 | [diff] [blame] | 752 | |
Steffen Maier | d39eda5 | 2018-05-17 19:14:58 +0200 | [diff] [blame^] | 753 | fc_req = zfcp_fc_alloc_sg_env(buf_num); |
Christof Schmitt | f977322 | 2011-02-22 19:54:43 +0100 | [diff] [blame] | 754 | if (!fc_req) |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 755 | goto out; |
Swen Schillig | cc8c282 | 2008-06-10 18:21:00 +0200 | [diff] [blame] | 756 | |
| 757 | for (i = 0; i < 3; i++) { |
Christof Schmitt | f977322 | 2011-02-22 19:54:43 +0100 | [diff] [blame] | 758 | ret = zfcp_fc_send_gpn_ft(fc_req, adapter, max_bytes); |
Swen Schillig | cc8c282 | 2008-06-10 18:21:00 +0200 | [diff] [blame] | 759 | if (!ret) { |
Christof Schmitt | f977322 | 2011-02-22 19:54:43 +0100 | [diff] [blame] | 760 | ret = zfcp_fc_eval_gpn_ft(fc_req, adapter, max_entries); |
Swen Schillig | cc8c282 | 2008-06-10 18:21:00 +0200 | [diff] [blame] | 761 | if (ret == -EAGAIN) |
| 762 | ssleep(1); |
| 763 | else |
| 764 | break; |
| 765 | } |
| 766 | } |
Christof Schmitt | f977322 | 2011-02-22 19:54:43 +0100 | [diff] [blame] | 767 | zfcp_sg_free_table(&fc_req->sg_rsp, buf_num); |
| 768 | kmem_cache_free(zfcp_fc_req_cache, fc_req); |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 769 | out: |
Swen Schillig | 6f53a2d | 2009-08-18 15:43:23 +0200 | [diff] [blame] | 770 | zfcp_fc_wka_port_put(&adapter->gs->ds); |
Swen Schillig | cc8c282 | 2008-06-10 18:21:00 +0200 | [diff] [blame] | 771 | } |
| 772 | |
Christof Schmitt | 038d944 | 2011-02-22 19:54:48 +0100 | [diff] [blame] | 773 | static int zfcp_fc_gspn(struct zfcp_adapter *adapter, |
| 774 | struct zfcp_fc_req *fc_req) |
| 775 | { |
| 776 | DECLARE_COMPLETION_ONSTACK(completion); |
| 777 | char devno[] = "DEVNO:"; |
| 778 | struct zfcp_fsf_ct_els *ct_els = &fc_req->ct_els; |
| 779 | struct zfcp_fc_gspn_req *gspn_req = &fc_req->u.gspn.req; |
| 780 | struct zfcp_fc_gspn_rsp *gspn_rsp = &fc_req->u.gspn.rsp; |
| 781 | int ret; |
| 782 | |
| 783 | zfcp_fc_ct_ns_init(&gspn_req->ct_hdr, FC_NS_GSPN_ID, |
| 784 | FC_SYMBOLIC_NAME_SIZE); |
| 785 | hton24(gspn_req->gspn.fp_fid, fc_host_port_id(adapter->scsi_host)); |
| 786 | |
| 787 | sg_init_one(&fc_req->sg_req, gspn_req, sizeof(*gspn_req)); |
| 788 | sg_init_one(&fc_req->sg_rsp, gspn_rsp, sizeof(*gspn_rsp)); |
| 789 | |
| 790 | ct_els->handler = zfcp_fc_complete; |
| 791 | ct_els->handler_data = &completion; |
| 792 | ct_els->req = &fc_req->sg_req; |
| 793 | ct_els->resp = &fc_req->sg_rsp; |
| 794 | |
| 795 | ret = zfcp_fsf_send_ct(&adapter->gs->ds, ct_els, NULL, |
| 796 | ZFCP_FC_CTELS_TMO); |
| 797 | if (ret) |
| 798 | return ret; |
| 799 | |
| 800 | wait_for_completion(&completion); |
| 801 | if (ct_els->status) |
| 802 | return ct_els->status; |
| 803 | |
| 804 | if (fc_host_port_type(adapter->scsi_host) == FC_PORTTYPE_NPIV && |
| 805 | !(strstr(gspn_rsp->gspn.fp_name, devno))) |
| 806 | snprintf(fc_host_symbolic_name(adapter->scsi_host), |
| 807 | FC_SYMBOLIC_NAME_SIZE, "%s%s %s NAME: %s", |
| 808 | gspn_rsp->gspn.fp_name, devno, |
| 809 | dev_name(&adapter->ccw_device->dev), |
| 810 | init_utsname()->nodename); |
| 811 | else |
| 812 | strlcpy(fc_host_symbolic_name(adapter->scsi_host), |
| 813 | gspn_rsp->gspn.fp_name, FC_SYMBOLIC_NAME_SIZE); |
| 814 | |
| 815 | return 0; |
| 816 | } |
| 817 | |
| 818 | static void zfcp_fc_rspn(struct zfcp_adapter *adapter, |
| 819 | struct zfcp_fc_req *fc_req) |
| 820 | { |
| 821 | DECLARE_COMPLETION_ONSTACK(completion); |
| 822 | struct Scsi_Host *shost = adapter->scsi_host; |
| 823 | struct zfcp_fsf_ct_els *ct_els = &fc_req->ct_els; |
| 824 | struct zfcp_fc_rspn_req *rspn_req = &fc_req->u.rspn.req; |
| 825 | struct fc_ct_hdr *rspn_rsp = &fc_req->u.rspn.rsp; |
| 826 | int ret, len; |
| 827 | |
| 828 | zfcp_fc_ct_ns_init(&rspn_req->ct_hdr, FC_NS_RSPN_ID, |
| 829 | FC_SYMBOLIC_NAME_SIZE); |
| 830 | hton24(rspn_req->rspn.fr_fid.fp_fid, fc_host_port_id(shost)); |
| 831 | len = strlcpy(rspn_req->rspn.fr_name, fc_host_symbolic_name(shost), |
| 832 | FC_SYMBOLIC_NAME_SIZE); |
| 833 | rspn_req->rspn.fr_name_len = len; |
| 834 | |
| 835 | sg_init_one(&fc_req->sg_req, rspn_req, sizeof(*rspn_req)); |
| 836 | sg_init_one(&fc_req->sg_rsp, rspn_rsp, sizeof(*rspn_rsp)); |
| 837 | |
| 838 | ct_els->handler = zfcp_fc_complete; |
| 839 | ct_els->handler_data = &completion; |
| 840 | ct_els->req = &fc_req->sg_req; |
| 841 | ct_els->resp = &fc_req->sg_rsp; |
| 842 | |
| 843 | ret = zfcp_fsf_send_ct(&adapter->gs->ds, ct_els, NULL, |
| 844 | ZFCP_FC_CTELS_TMO); |
| 845 | if (!ret) |
| 846 | wait_for_completion(&completion); |
| 847 | } |
| 848 | |
| 849 | /** |
| 850 | * zfcp_fc_sym_name_update - Retrieve and update the symbolic port name |
| 851 | * @work: ns_up_work of the adapter where to update the symbolic port name |
| 852 | * |
| 853 | * Retrieve the current symbolic port name that may have been set by |
| 854 | * the hardware using the GSPN request and update the fc_host |
| 855 | * symbolic_name sysfs attribute. When running in NPIV mode (and hence |
| 856 | * the port name is unique for this system), update the symbolic port |
| 857 | * name to add Linux specific information and update the FC nameserver |
| 858 | * using the RSPN request. |
| 859 | */ |
| 860 | void zfcp_fc_sym_name_update(struct work_struct *work) |
| 861 | { |
| 862 | struct zfcp_adapter *adapter = container_of(work, struct zfcp_adapter, |
| 863 | ns_up_work); |
| 864 | int ret; |
| 865 | struct zfcp_fc_req *fc_req; |
| 866 | |
| 867 | if (fc_host_port_type(adapter->scsi_host) != FC_PORTTYPE_NPORT && |
| 868 | fc_host_port_type(adapter->scsi_host) != FC_PORTTYPE_NPIV) |
| 869 | return; |
| 870 | |
| 871 | fc_req = kmem_cache_zalloc(zfcp_fc_req_cache, GFP_KERNEL); |
| 872 | if (!fc_req) |
| 873 | return; |
| 874 | |
| 875 | ret = zfcp_fc_wka_port_get(&adapter->gs->ds); |
| 876 | if (ret) |
| 877 | goto out_free; |
| 878 | |
| 879 | ret = zfcp_fc_gspn(adapter, fc_req); |
| 880 | if (ret || fc_host_port_type(adapter->scsi_host) != FC_PORTTYPE_NPIV) |
| 881 | goto out_ds_put; |
| 882 | |
| 883 | memset(fc_req, 0, sizeof(*fc_req)); |
| 884 | zfcp_fc_rspn(adapter, fc_req); |
| 885 | |
| 886 | out_ds_put: |
| 887 | zfcp_fc_wka_port_put(&adapter->gs->ds); |
| 888 | out_free: |
| 889 | kmem_cache_free(zfcp_fc_req_cache, fc_req); |
| 890 | } |
| 891 | |
Christof Schmitt | 7c7dc19 | 2009-11-24 16:54:13 +0100 | [diff] [blame] | 892 | static void zfcp_fc_ct_els_job_handler(void *data) |
Sven Schuetz | 9d544f2 | 2009-04-06 18:31:47 +0200 | [diff] [blame] | 893 | { |
Johannes Thumshirn | 75cc8cf | 2016-11-17 10:31:19 +0100 | [diff] [blame] | 894 | struct bsg_job *job = data; |
Christof Schmitt | 7c7dc19 | 2009-11-24 16:54:13 +0100 | [diff] [blame] | 895 | struct zfcp_fsf_ct_els *zfcp_ct_els = job->dd_data; |
Swen Schillig | 7dec9cf | 2010-01-26 17:49:19 +0100 | [diff] [blame] | 896 | struct fc_bsg_reply *jr = job->reply; |
Sven Schuetz | 9d544f2 | 2009-04-06 18:31:47 +0200 | [diff] [blame] | 897 | |
Swen Schillig | 7dec9cf | 2010-01-26 17:49:19 +0100 | [diff] [blame] | 898 | jr->reply_payload_rcv_len = job->reply_payload.payload_len; |
| 899 | jr->reply_data.ctels_reply.status = FC_CTELS_STATUS_OK; |
| 900 | jr->result = zfcp_ct_els->status ? -EIO : 0; |
Johannes Thumshirn | 0654816 | 2016-11-17 10:31:22 +0100 | [diff] [blame] | 901 | bsg_job_done(job, jr->result, jr->reply_payload_rcv_len); |
Sven Schuetz | 9d544f2 | 2009-04-06 18:31:47 +0200 | [diff] [blame] | 902 | } |
| 903 | |
Johannes Thumshirn | 75cc8cf | 2016-11-17 10:31:19 +0100 | [diff] [blame] | 904 | static struct zfcp_fc_wka_port *zfcp_fc_job_wka_port(struct bsg_job *job) |
Christof Schmitt | f09d545 | 2010-01-13 17:52:36 +0100 | [diff] [blame] | 905 | { |
| 906 | u32 preamble_word1; |
| 907 | u8 gs_type; |
| 908 | struct zfcp_adapter *adapter; |
Johannes Thumshirn | 01e0e15 | 2016-11-17 10:31:12 +0100 | [diff] [blame] | 909 | struct fc_bsg_request *bsg_request = job->request; |
Johannes Thumshirn | 1d69b12 | 2016-11-17 10:31:15 +0100 | [diff] [blame] | 910 | struct fc_rport *rport = fc_bsg_to_rport(job); |
Johannes Thumshirn | cd21c60 | 2016-11-17 10:31:14 +0100 | [diff] [blame] | 911 | struct Scsi_Host *shost; |
Christof Schmitt | f09d545 | 2010-01-13 17:52:36 +0100 | [diff] [blame] | 912 | |
Johannes Thumshirn | 01e0e15 | 2016-11-17 10:31:12 +0100 | [diff] [blame] | 913 | preamble_word1 = bsg_request->rqst_data.r_ct.preamble_word1; |
Christof Schmitt | f09d545 | 2010-01-13 17:52:36 +0100 | [diff] [blame] | 914 | gs_type = (preamble_word1 & 0xff000000) >> 24; |
| 915 | |
Johannes Thumshirn | 1d69b12 | 2016-11-17 10:31:15 +0100 | [diff] [blame] | 916 | shost = rport ? rport_to_shost(rport) : fc_bsg_to_shost(job); |
Johannes Thumshirn | cd21c60 | 2016-11-17 10:31:14 +0100 | [diff] [blame] | 917 | adapter = (struct zfcp_adapter *) shost->hostdata[0]; |
Christof Schmitt | f09d545 | 2010-01-13 17:52:36 +0100 | [diff] [blame] | 918 | |
| 919 | switch (gs_type) { |
| 920 | case FC_FST_ALIAS: |
| 921 | return &adapter->gs->as; |
| 922 | case FC_FST_MGMT: |
| 923 | return &adapter->gs->ms; |
| 924 | case FC_FST_TIME: |
| 925 | return &adapter->gs->ts; |
| 926 | break; |
| 927 | case FC_FST_DIR: |
| 928 | return &adapter->gs->ds; |
| 929 | break; |
| 930 | default: |
| 931 | return NULL; |
| 932 | } |
| 933 | } |
| 934 | |
| 935 | static void zfcp_fc_ct_job_handler(void *data) |
| 936 | { |
Johannes Thumshirn | 75cc8cf | 2016-11-17 10:31:19 +0100 | [diff] [blame] | 937 | struct bsg_job *job = data; |
Christof Schmitt | f09d545 | 2010-01-13 17:52:36 +0100 | [diff] [blame] | 938 | struct zfcp_fc_wka_port *wka_port; |
| 939 | |
| 940 | wka_port = zfcp_fc_job_wka_port(job); |
| 941 | zfcp_fc_wka_port_put(wka_port); |
| 942 | |
| 943 | zfcp_fc_ct_els_job_handler(data); |
| 944 | } |
| 945 | |
Johannes Thumshirn | 75cc8cf | 2016-11-17 10:31:19 +0100 | [diff] [blame] | 946 | static int zfcp_fc_exec_els_job(struct bsg_job *job, |
Christof Schmitt | 7c7dc19 | 2009-11-24 16:54:13 +0100 | [diff] [blame] | 947 | struct zfcp_adapter *adapter) |
Sven Schuetz | 9d544f2 | 2009-04-06 18:31:47 +0200 | [diff] [blame] | 948 | { |
Christof Schmitt | 7c7dc19 | 2009-11-24 16:54:13 +0100 | [diff] [blame] | 949 | struct zfcp_fsf_ct_els *els = job->dd_data; |
Johannes Thumshirn | 1d69b12 | 2016-11-17 10:31:15 +0100 | [diff] [blame] | 950 | struct fc_rport *rport = fc_bsg_to_rport(job); |
Johannes Thumshirn | 01e0e15 | 2016-11-17 10:31:12 +0100 | [diff] [blame] | 951 | struct fc_bsg_request *bsg_request = job->request; |
Sven Schuetz | 9d544f2 | 2009-04-06 18:31:47 +0200 | [diff] [blame] | 952 | struct zfcp_port *port; |
Christof Schmitt | 7c7dc19 | 2009-11-24 16:54:13 +0100 | [diff] [blame] | 953 | u32 d_id; |
Sven Schuetz | 9d544f2 | 2009-04-06 18:31:47 +0200 | [diff] [blame] | 954 | |
Sven Schuetz | 9d544f2 | 2009-04-06 18:31:47 +0200 | [diff] [blame] | 955 | if (rport) { |
Swen Schillig | ea945ff | 2009-08-18 15:43:24 +0200 | [diff] [blame] | 956 | port = zfcp_get_port_by_wwpn(adapter, rport->port_name); |
Christof Schmitt | 7c7dc19 | 2009-11-24 16:54:13 +0100 | [diff] [blame] | 957 | if (!port) |
Sven Schuetz | 9d544f2 | 2009-04-06 18:31:47 +0200 | [diff] [blame] | 958 | return -EINVAL; |
Swen Schillig | ecf0c77 | 2009-11-24 16:53:58 +0100 | [diff] [blame] | 959 | |
Christof Schmitt | 7c7dc19 | 2009-11-24 16:54:13 +0100 | [diff] [blame] | 960 | d_id = port->d_id; |
Christof Schmitt | 615f59e | 2010-02-17 11:18:56 +0100 | [diff] [blame] | 961 | put_device(&port->dev); |
Christof Schmitt | 7c7dc19 | 2009-11-24 16:54:13 +0100 | [diff] [blame] | 962 | } else |
Johannes Thumshirn | 01e0e15 | 2016-11-17 10:31:12 +0100 | [diff] [blame] | 963 | d_id = ntoh24(bsg_request->rqst_data.h_els.port_id); |
Sven Schuetz | 9d544f2 | 2009-04-06 18:31:47 +0200 | [diff] [blame] | 964 | |
Christof Schmitt | f09d545 | 2010-01-13 17:52:36 +0100 | [diff] [blame] | 965 | els->handler = zfcp_fc_ct_els_job_handler; |
Christoph Hellwig | 31156ec | 2018-03-13 17:28:39 +0100 | [diff] [blame] | 966 | return zfcp_fsf_send_els(adapter, d_id, els, job->timeout / HZ); |
Sven Schuetz | 9d544f2 | 2009-04-06 18:31:47 +0200 | [diff] [blame] | 967 | } |
| 968 | |
Johannes Thumshirn | 75cc8cf | 2016-11-17 10:31:19 +0100 | [diff] [blame] | 969 | static int zfcp_fc_exec_ct_job(struct bsg_job *job, |
Christof Schmitt | 7c7dc19 | 2009-11-24 16:54:13 +0100 | [diff] [blame] | 970 | struct zfcp_adapter *adapter) |
Sven Schuetz | 9d544f2 | 2009-04-06 18:31:47 +0200 | [diff] [blame] | 971 | { |
| 972 | int ret; |
Christof Schmitt | 7c7dc19 | 2009-11-24 16:54:13 +0100 | [diff] [blame] | 973 | struct zfcp_fsf_ct_els *ct = job->dd_data; |
| 974 | struct zfcp_fc_wka_port *wka_port; |
Sven Schuetz | 9d544f2 | 2009-04-06 18:31:47 +0200 | [diff] [blame] | 975 | |
Christof Schmitt | f09d545 | 2010-01-13 17:52:36 +0100 | [diff] [blame] | 976 | wka_port = zfcp_fc_job_wka_port(job); |
| 977 | if (!wka_port) |
| 978 | return -EINVAL; |
Sven Schuetz | 9d544f2 | 2009-04-06 18:31:47 +0200 | [diff] [blame] | 979 | |
Christof Schmitt | 7c7dc19 | 2009-11-24 16:54:13 +0100 | [diff] [blame] | 980 | ret = zfcp_fc_wka_port_get(wka_port); |
| 981 | if (ret) |
Sven Schuetz | 9d544f2 | 2009-04-06 18:31:47 +0200 | [diff] [blame] | 982 | return ret; |
Sven Schuetz | 9d544f2 | 2009-04-06 18:31:47 +0200 | [diff] [blame] | 983 | |
Christof Schmitt | f09d545 | 2010-01-13 17:52:36 +0100 | [diff] [blame] | 984 | ct->handler = zfcp_fc_ct_job_handler; |
Christoph Hellwig | 31156ec | 2018-03-13 17:28:39 +0100 | [diff] [blame] | 985 | ret = zfcp_fsf_send_ct(wka_port, ct, NULL, job->timeout / HZ); |
Christof Schmitt | 7c7dc19 | 2009-11-24 16:54:13 +0100 | [diff] [blame] | 986 | if (ret) |
| 987 | zfcp_fc_wka_port_put(wka_port); |
Sven Schuetz | 9d544f2 | 2009-04-06 18:31:47 +0200 | [diff] [blame] | 988 | |
Sven Schuetz | 9d544f2 | 2009-04-06 18:31:47 +0200 | [diff] [blame] | 989 | return ret; |
| 990 | } |
Swen Schillig | d5a282a | 2009-08-18 15:43:22 +0200 | [diff] [blame] | 991 | |
Johannes Thumshirn | 75cc8cf | 2016-11-17 10:31:19 +0100 | [diff] [blame] | 992 | int zfcp_fc_exec_bsg_job(struct bsg_job *job) |
Christof Schmitt | 7c7dc19 | 2009-11-24 16:54:13 +0100 | [diff] [blame] | 993 | { |
| 994 | struct Scsi_Host *shost; |
| 995 | struct zfcp_adapter *adapter; |
| 996 | struct zfcp_fsf_ct_els *ct_els = job->dd_data; |
Johannes Thumshirn | 01e0e15 | 2016-11-17 10:31:12 +0100 | [diff] [blame] | 997 | struct fc_bsg_request *bsg_request = job->request; |
Johannes Thumshirn | 1d69b12 | 2016-11-17 10:31:15 +0100 | [diff] [blame] | 998 | struct fc_rport *rport = fc_bsg_to_rport(job); |
Christof Schmitt | 7c7dc19 | 2009-11-24 16:54:13 +0100 | [diff] [blame] | 999 | |
Johannes Thumshirn | 1d69b12 | 2016-11-17 10:31:15 +0100 | [diff] [blame] | 1000 | shost = rport ? rport_to_shost(rport) : fc_bsg_to_shost(job); |
Christof Schmitt | 7c7dc19 | 2009-11-24 16:54:13 +0100 | [diff] [blame] | 1001 | adapter = (struct zfcp_adapter *)shost->hostdata[0]; |
| 1002 | |
| 1003 | if (!(atomic_read(&adapter->status) & ZFCP_STATUS_COMMON_OPEN)) |
| 1004 | return -EINVAL; |
| 1005 | |
| 1006 | ct_els->req = job->request_payload.sg_list; |
| 1007 | ct_els->resp = job->reply_payload.sg_list; |
Christof Schmitt | 7c7dc19 | 2009-11-24 16:54:13 +0100 | [diff] [blame] | 1008 | ct_els->handler_data = job; |
| 1009 | |
Johannes Thumshirn | 01e0e15 | 2016-11-17 10:31:12 +0100 | [diff] [blame] | 1010 | switch (bsg_request->msgcode) { |
Christof Schmitt | 7c7dc19 | 2009-11-24 16:54:13 +0100 | [diff] [blame] | 1011 | case FC_BSG_RPT_ELS: |
| 1012 | case FC_BSG_HST_ELS_NOLOGIN: |
| 1013 | return zfcp_fc_exec_els_job(job, adapter); |
| 1014 | case FC_BSG_RPT_CT: |
| 1015 | case FC_BSG_HST_CT: |
| 1016 | return zfcp_fc_exec_ct_job(job, adapter); |
| 1017 | default: |
| 1018 | return -EINVAL; |
| 1019 | } |
| 1020 | } |
| 1021 | |
Johannes Thumshirn | 75cc8cf | 2016-11-17 10:31:19 +0100 | [diff] [blame] | 1022 | int zfcp_fc_timeout_bsg_job(struct bsg_job *job) |
Swen Schillig | 491ca44 | 2010-01-14 17:19:01 +0100 | [diff] [blame] | 1023 | { |
| 1024 | /* hardware tracks timeout, reset bsg timeout to not interfere */ |
| 1025 | return -EAGAIN; |
| 1026 | } |
| 1027 | |
Swen Schillig | d5a282a | 2009-08-18 15:43:22 +0200 | [diff] [blame] | 1028 | int zfcp_fc_gs_setup(struct zfcp_adapter *adapter) |
| 1029 | { |
Christof Schmitt | bd0072e | 2009-11-24 16:54:11 +0100 | [diff] [blame] | 1030 | struct zfcp_fc_wka_ports *wka_ports; |
Swen Schillig | d5a282a | 2009-08-18 15:43:22 +0200 | [diff] [blame] | 1031 | |
Christof Schmitt | bd0072e | 2009-11-24 16:54:11 +0100 | [diff] [blame] | 1032 | wka_ports = kzalloc(sizeof(struct zfcp_fc_wka_ports), GFP_KERNEL); |
Swen Schillig | d5a282a | 2009-08-18 15:43:22 +0200 | [diff] [blame] | 1033 | if (!wka_ports) |
| 1034 | return -ENOMEM; |
| 1035 | |
| 1036 | adapter->gs = wka_ports; |
| 1037 | zfcp_fc_wka_port_init(&wka_ports->ms, FC_FID_MGMT_SERV, adapter); |
| 1038 | zfcp_fc_wka_port_init(&wka_ports->ts, FC_FID_TIME_SERV, adapter); |
| 1039 | zfcp_fc_wka_port_init(&wka_ports->ds, FC_FID_DIR_SERV, adapter); |
| 1040 | zfcp_fc_wka_port_init(&wka_ports->as, FC_FID_ALIASES, adapter); |
Swen Schillig | d5a282a | 2009-08-18 15:43:22 +0200 | [diff] [blame] | 1041 | |
| 1042 | return 0; |
| 1043 | } |
| 1044 | |
| 1045 | void zfcp_fc_gs_destroy(struct zfcp_adapter *adapter) |
| 1046 | { |
| 1047 | kfree(adapter->gs); |
| 1048 | adapter->gs = NULL; |
| 1049 | } |
| 1050 | |