9 #define KMSG_COMPONENT "zfcp"
10 #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
12 #include <linux/types.h>
13 #include <linux/slab.h>
14 #include <linux/utsname.h>
22 static u32 zfcp_fc_rscn_range_mask[] = {
29 static bool no_auto_port_rescan;
32 "no automatic port_rescan (default off)");
36 if (no_auto_port_rescan)
44 if (!no_auto_port_rescan)
59 struct zfcp_fc_events, work);
63 spin_lock_bh(&events->list_lock);
64 list_splice_init(&events->list, &tmp_lh);
65 spin_unlock_bh(&events->list_lock);
86 struct zfcp_fc_event *
event;
95 spin_lock(&adapter->
events.list_lock);
97 spin_unlock(&adapter->
events.list_lock);
102 static int zfcp_fc_wka_port_get(
struct zfcp_fc_wka_port *wka_port)
107 if (wka_port->status == ZFCP_FC_WKA_PORT_OFFLINE ||
108 wka_port->status == ZFCP_FC_WKA_PORT_CLOSING) {
109 wka_port->status = ZFCP_FC_WKA_PORT_OPENING;
111 wka_port->status = ZFCP_FC_WKA_PORT_OFFLINE;
117 wka_port->status == ZFCP_FC_WKA_PORT_ONLINE ||
118 wka_port->status == ZFCP_FC_WKA_PORT_OFFLINE);
120 if (wka_port->status == ZFCP_FC_WKA_PORT_ONLINE) {
130 struct zfcp_fc_wka_port *wka_port =
135 (wka_port->status != ZFCP_FC_WKA_PORT_ONLINE))
138 wka_port->status = ZFCP_FC_WKA_PORT_CLOSING;
140 wka_port->status = ZFCP_FC_WKA_PORT_OFFLINE;
141 wake_up(&wka_port->completion_wq);
147 static void zfcp_fc_wka_port_put(
struct zfcp_fc_wka_port *wka_port)
155 static void zfcp_fc_wka_port_init(
struct zfcp_fc_wka_port *wka_port,
u32 d_id,
161 wka_port->d_id =
d_id;
163 wka_port->status = ZFCP_FC_WKA_PORT_OFFLINE;
169 static void zfcp_fc_wka_port_force_offline(
struct zfcp_fc_wka_port *wka)
173 wka->status = ZFCP_FC_WKA_PORT_OFFLINE;
181 zfcp_fc_wka_port_force_offline(&gs->ms);
182 zfcp_fc_wka_port_force_offline(&gs->ts);
183 zfcp_fc_wka_port_force_offline(&gs->ds);
184 zfcp_fc_wka_port_force_offline(&gs->as);
206 static void zfcp_fc_incoming_rscn(
struct zfcp_fsf_req *fsf_req)
225 _zfcp_fc_incoming_rscn(fsf_req, zfcp_fc_rscn_range_mask[afmt],
241 if (port->wwpn == wwpn) {
255 zfcp_fc_incoming_wwpn(req, plogi->
fl_wwpn);
265 zfcp_fc_incoming_wwpn(req, logo->fl_n_port_wwn);
276 unsigned int els_type = status_buffer->
payload.
data[0];
280 zfcp_fc_incoming_plogi(fsf_req);
282 zfcp_fc_incoming_logo(fsf_req);
284 zfcp_fc_incoming_rscn(fsf_req);
287 static void zfcp_fc_ns_gid_pn_eval(
struct zfcp_fc_req *fc_req)
290 struct zfcp_fc_gid_pn_rsp *gid_pn_rsp = &fc_req->u.gid_pn.rsp;
294 if (gid_pn_rsp->ct_hdr.ct_cmd !=
FC_FS_ACC)
298 ct_els->
port->d_id =
ntoh24(gid_pn_rsp->gid_pn.fp_fid);
301 static void zfcp_fc_complete(
void *
data)
315 static int zfcp_fc_ns_gid_pn_request(
struct zfcp_port *port,
316 struct zfcp_fc_req *fc_req)
320 struct zfcp_fc_gid_pn_req *gid_pn_req = &fc_req->u.gid_pn.req;
321 struct zfcp_fc_gid_pn_rsp *gid_pn_rsp = &fc_req->u.gid_pn.rsp;
325 fc_req->ct_els.port =
port;
326 fc_req->ct_els.handler = zfcp_fc_complete;
328 fc_req->ct_els.req = &fc_req->sg_req;
329 fc_req->ct_els.resp = &fc_req->sg_rsp;
330 sg_init_one(&fc_req->sg_req, gid_pn_req,
sizeof(*gid_pn_req));
331 sg_init_one(&fc_req->sg_rsp, gid_pn_rsp,
sizeof(*gid_pn_rsp));
333 zfcp_fc_ct_ns_init(&gid_pn_req->ct_hdr,
335 gid_pn_req->gid_pn.fn_wwpn = port->
wwpn;
338 adapter->
pool.gid_pn_req,
342 zfcp_fc_ns_gid_pn_eval(fc_req);
352 static int zfcp_fc_ns_gid_pn(
struct zfcp_port *port)
355 struct zfcp_fc_req *fc_req;
362 memset(fc_req, 0,
sizeof(*fc_req));
364 ret = zfcp_fc_wka_port_get(&adapter->
gs->ds);
368 ret = zfcp_fc_ns_gid_pn_request(port, fc_req);
370 zfcp_fc_wka_port_put(&adapter->
gs->ds);
382 ret = zfcp_fc_ns_gid_pn(port);
422 "A port opened with WWPN 0x%016Lx returned data that "
423 "identifies it as WWPN 0x%016Lx\n",
424 (
unsigned long long) port->
wwpn,
425 (
unsigned long long) plogi->
fl_wwpn);
442 static void zfcp_fc_adisc_handler(
void *
data)
444 struct zfcp_fc_req *fc_req =
data;
445 struct zfcp_port *port = fc_req->ct_els.port;
448 if (fc_req->ct_els.status) {
473 static int zfcp_fc_adisc(
struct zfcp_port *port)
475 struct zfcp_fc_req *fc_req;
480 fc_req = kmem_cache_zalloc(zfcp_fc_req_cache,
GFP_ATOMIC);
484 fc_req->ct_els.port =
port;
485 fc_req->ct_els.req = &fc_req->sg_req;
486 fc_req->ct_els.resp = &fc_req->sg_rsp;
492 fc_req->ct_els.handler = zfcp_fc_adisc_handler;
493 fc_req->ct_els.handler_data = fc_req;
499 fc_req->u.adisc.req.adisc_cmd =
ELS_ADISC;
526 retval = zfcp_fc_adisc(port);
553 static struct zfcp_fc_req *zfcp_alloc_sg_env(
int buf_num)
555 struct zfcp_fc_req *fc_req;
557 fc_req = kmem_cache_zalloc(zfcp_fc_req_cache,
GFP_KERNEL);
566 sg_init_one(&fc_req->sg_req, &fc_req->u.gpn_ft.req,
567 sizeof(
struct zfcp_fc_gpn_ft_req));
572 static int zfcp_fc_send_gpn_ft(
struct zfcp_fc_req *fc_req,
576 struct zfcp_fc_gpn_ft_req *
req = &fc_req->u.gpn_ft.req;
580 zfcp_fc_ct_ns_init(&req->ct_hdr,
FC_NS_GPN_FT, max_bytes);
583 ct_els->
handler = zfcp_fc_complete;
585 ct_els->
req = &fc_req->sg_req;
586 ct_els->
resp = &fc_req->sg_rsp;
606 list_move_tail(&port->
list, lh);
609 static int zfcp_fc_eval_gpn_ft(
struct zfcp_fc_req *fc_req,
620 int ret = 0,
x,
last = 0;
633 "The name server reported %d words residual data\n",
639 for (
x = 1;
x < max_entries && !last;
x++) {
659 else if (PTR_ERR(port) != -
EEXIST)
666 zfcp_fc_validate_port(port, &remove_lh);
686 struct zfcp_fc_req *fc_req;
698 if (zfcp_fc_wka_port_get(&adapter->
gs->ds))
701 fc_req = zfcp_alloc_sg_env(buf_num);
705 for (i = 0; i < 3; i++) {
706 ret = zfcp_fc_send_gpn_ft(fc_req, adapter, max_bytes);
708 ret = zfcp_fc_eval_gpn_ft(fc_req, adapter, max_entries);
718 zfcp_fc_wka_port_put(&adapter->
gs->ds);
722 struct zfcp_fc_req *fc_req)
725 char devno[] =
"DEVNO:";
727 struct zfcp_fc_gspn_req *gspn_req = &fc_req->u.gspn.
req;
728 struct zfcp_fc_gspn_rsp *gspn_rsp = &fc_req->u.gspn.rsp;
735 sg_init_one(&fc_req->sg_req, gspn_req,
sizeof(*gspn_req));
736 sg_init_one(&fc_req->sg_rsp, gspn_rsp,
sizeof(*gspn_rsp));
738 ct_els->
handler = zfcp_fc_complete;
740 ct_els->
req = &fc_req->sg_req;
741 ct_els->
resp = &fc_req->sg_rsp;
753 !(
strstr(gspn_rsp->gspn.fp_name, devno)))
756 gspn_rsp->gspn.fp_name, devno,
758 init_utsname()->nodename);
767 struct zfcp_fc_req *fc_req)
772 struct zfcp_fc_rspn_req *rspn_req = &fc_req->u.rspn.
req;
773 struct fc_ct_hdr *rspn_rsp = &fc_req->u.rspn.rsp;
781 rspn_req->rspn.fr_name_len = len;
783 sg_init_one(&fc_req->sg_req, rspn_req,
sizeof(*rspn_req));
784 sg_init_one(&fc_req->sg_rsp, rspn_rsp,
sizeof(*rspn_rsp));
786 ct_els->
handler = zfcp_fc_complete;
788 ct_els->
req = &fc_req->sg_req;
789 ct_els->
resp = &fc_req->sg_rsp;
813 struct zfcp_fc_req *fc_req;
819 fc_req = kmem_cache_zalloc(zfcp_fc_req_cache,
GFP_KERNEL);
823 ret = zfcp_fc_wka_port_get(&adapter->
gs->ds);
827 ret = zfcp_fc_gspn(adapter, fc_req);
831 memset(fc_req, 0,
sizeof(*fc_req));
832 zfcp_fc_rspn(adapter, fc_req);
835 zfcp_fc_wka_port_put(&adapter->
gs->ds);
840 static void zfcp_fc_ct_els_job_handler(
void *data)
852 static struct zfcp_fc_wka_port *zfcp_fc_job_wka_port(
struct fc_bsg_job *job)
858 preamble_word1 = job->
request->rqst_data.r_ct.preamble_word1;
859 gs_type = (preamble_word1 & 0xff000000) >> 24;
865 return &adapter->
gs->as;
867 return &adapter->
gs->ms;
869 return &adapter->
gs->ts;
872 return &adapter->
gs->ds;
879 static void zfcp_fc_ct_job_handler(
void *data)
882 struct zfcp_fc_wka_port *wka_port;
884 wka_port = zfcp_fc_job_wka_port(job);
885 zfcp_fc_wka_port_put(wka_port);
887 zfcp_fc_ct_els_job_handler(data);
890 static int zfcp_fc_exec_els_job(
struct fc_bsg_job *job,
908 els->
handler = zfcp_fc_ct_els_job_handler;
912 static int zfcp_fc_exec_ct_job(
struct fc_bsg_job *job,
917 struct zfcp_fc_wka_port *wka_port;
919 wka_port = zfcp_fc_job_wka_port(job);
923 ret = zfcp_fc_wka_port_get(wka_port);
927 ct->
handler = zfcp_fc_ct_job_handler;
930 zfcp_fc_wka_port_put(wka_port);
951 switch (job->
request->msgcode) {
954 return zfcp_fc_exec_els_job(job, adapter);
957 return zfcp_fc_exec_ct_job(job, adapter);
971 struct zfcp_fc_wka_ports *wka_ports;
973 wka_ports = kzalloc(
sizeof(
struct zfcp_fc_wka_ports),
GFP_KERNEL);
977 adapter->
gs = wka_ports;