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