Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 1 | /* |
| 2 | * zfcp device driver |
| 3 | * |
| 4 | * Fibre Channel related functions for the zfcp device driver. |
| 5 | * |
Christof Schmitt | a2fa0ae | 2009-03-02 13:09:08 +0100 | [diff] [blame] | 6 | * Copyright IBM Corporation 2008, 2009 |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 7 | */ |
| 8 | |
Christof Schmitt | ecf39d4 | 2008-12-25 13:39:53 +0100 | [diff] [blame] | 9 | #define KMSG_COMPONENT "zfcp" |
| 10 | #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt |
| 11 | |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 12 | #include "zfcp_ext.h" |
| 13 | |
Christof Schmitt | e0d7fcb | 2008-12-19 16:56:58 +0100 | [diff] [blame] | 14 | enum rscn_address_format { |
| 15 | RSCN_PORT_ADDRESS = 0x0, |
| 16 | RSCN_AREA_ADDRESS = 0x1, |
| 17 | RSCN_DOMAIN_ADDRESS = 0x2, |
| 18 | RSCN_FABRIC_ADDRESS = 0x3, |
| 19 | }; |
| 20 | |
| 21 | static u32 rscn_range_mask[] = { |
| 22 | [RSCN_PORT_ADDRESS] = 0xFFFFFF, |
| 23 | [RSCN_AREA_ADDRESS] = 0xFFFF00, |
| 24 | [RSCN_DOMAIN_ADDRESS] = 0xFF0000, |
| 25 | [RSCN_FABRIC_ADDRESS] = 0x000000, |
| 26 | }; |
| 27 | |
Swen Schillig | cc8c282 | 2008-06-10 18:21:00 +0200 | [diff] [blame] | 28 | struct gpn_ft_resp_acc { |
| 29 | u8 control; |
| 30 | u8 port_id[3]; |
| 31 | u8 reserved[4]; |
| 32 | u64 wwpn; |
| 33 | } __attribute__ ((packed)); |
| 34 | |
Christof Schmitt | 39eb7e9a | 2008-12-19 16:57:01 +0100 | [diff] [blame] | 35 | #define ZFCP_CT_SIZE_ONE_PAGE (PAGE_SIZE - sizeof(struct ct_hdr)) |
| 36 | #define ZFCP_GPN_FT_ENTRIES (ZFCP_CT_SIZE_ONE_PAGE \ |
| 37 | / sizeof(struct gpn_ft_resp_acc)) |
Swen Schillig | cc8c282 | 2008-06-10 18:21:00 +0200 | [diff] [blame] | 38 | #define ZFCP_GPN_FT_BUFFERS 4 |
Christof Schmitt | 39eb7e9a | 2008-12-19 16:57:01 +0100 | [diff] [blame] | 39 | #define ZFCP_GPN_FT_MAX_SIZE (ZFCP_GPN_FT_BUFFERS * PAGE_SIZE \ |
| 40 | - sizeof(struct ct_hdr)) |
Swen Schillig | cc8c282 | 2008-06-10 18:21:00 +0200 | [diff] [blame] | 41 | #define ZFCP_GPN_FT_MAX_ENTRIES ZFCP_GPN_FT_BUFFERS * (ZFCP_GPN_FT_ENTRIES + 1) |
| 42 | |
| 43 | struct ct_iu_gpn_ft_resp { |
| 44 | struct ct_hdr header; |
| 45 | struct gpn_ft_resp_acc accept[ZFCP_GPN_FT_ENTRIES]; |
| 46 | } __attribute__ ((packed)); |
| 47 | |
| 48 | struct zfcp_gpn_ft { |
| 49 | struct zfcp_send_ct ct; |
| 50 | struct scatterlist sg_req; |
| 51 | struct scatterlist sg_resp[ZFCP_GPN_FT_BUFFERS]; |
| 52 | }; |
| 53 | |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 54 | struct zfcp_fc_ns_handler_data { |
| 55 | struct completion done; |
| 56 | void (*handler)(unsigned long); |
| 57 | unsigned long handler_data; |
| 58 | }; |
| 59 | |
Swen Schillig | 6f53a2d | 2009-08-18 15:43:23 +0200 | [diff] [blame] | 60 | static int zfcp_fc_wka_port_get(struct zfcp_wka_port *wka_port) |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 61 | { |
| 62 | if (mutex_lock_interruptible(&wka_port->mutex)) |
| 63 | return -ERESTARTSYS; |
| 64 | |
Christof Schmitt | 1c1cba1 | 2008-11-26 18:07:36 +0100 | [diff] [blame] | 65 | if (wka_port->status == ZFCP_WKA_PORT_OFFLINE || |
| 66 | wka_port->status == ZFCP_WKA_PORT_CLOSING) { |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 67 | wka_port->status = ZFCP_WKA_PORT_OPENING; |
| 68 | if (zfcp_fsf_open_wka_port(wka_port)) |
| 69 | wka_port->status = ZFCP_WKA_PORT_OFFLINE; |
| 70 | } |
| 71 | |
| 72 | mutex_unlock(&wka_port->mutex); |
| 73 | |
Swen Schillig | 27f492c | 2009-07-13 15:06:13 +0200 | [diff] [blame] | 74 | wait_event(wka_port->completion_wq, |
| 75 | wka_port->status == ZFCP_WKA_PORT_ONLINE || |
| 76 | wka_port->status == ZFCP_WKA_PORT_OFFLINE); |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 77 | |
| 78 | if (wka_port->status == ZFCP_WKA_PORT_ONLINE) { |
| 79 | atomic_inc(&wka_port->refcount); |
| 80 | return 0; |
| 81 | } |
| 82 | return -EIO; |
| 83 | } |
| 84 | |
Swen Schillig | 6f53a2d | 2009-08-18 15:43:23 +0200 | [diff] [blame] | 85 | static void zfcp_fc_wka_port_offline(struct work_struct *work) |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 86 | { |
Jean Delvare | bf6aede | 2009-04-02 16:56:54 -0700 | [diff] [blame] | 87 | struct delayed_work *dw = to_delayed_work(work); |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 88 | struct zfcp_wka_port *wka_port = |
| 89 | container_of(dw, struct zfcp_wka_port, work); |
| 90 | |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 91 | mutex_lock(&wka_port->mutex); |
| 92 | if ((atomic_read(&wka_port->refcount) != 0) || |
| 93 | (wka_port->status != ZFCP_WKA_PORT_ONLINE)) |
| 94 | goto out; |
| 95 | |
| 96 | wka_port->status = ZFCP_WKA_PORT_CLOSING; |
| 97 | if (zfcp_fsf_close_wka_port(wka_port)) { |
| 98 | wka_port->status = ZFCP_WKA_PORT_OFFLINE; |
| 99 | wake_up(&wka_port->completion_wq); |
| 100 | } |
| 101 | out: |
| 102 | mutex_unlock(&wka_port->mutex); |
| 103 | } |
| 104 | |
Swen Schillig | 6f53a2d | 2009-08-18 15:43:23 +0200 | [diff] [blame] | 105 | static void zfcp_fc_wka_port_put(struct zfcp_wka_port *wka_port) |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 106 | { |
| 107 | if (atomic_dec_return(&wka_port->refcount) != 0) |
| 108 | return; |
Martin Olsson | 19af5cd | 2009-04-23 11:37:37 +0200 | [diff] [blame] | 109 | /* wait 10 milliseconds, other reqs might pop in */ |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 110 | schedule_delayed_work(&wka_port->work, HZ / 100); |
| 111 | } |
| 112 | |
Sven Schuetz | 9d544f2 | 2009-04-06 18:31:47 +0200 | [diff] [blame] | 113 | static void zfcp_fc_wka_port_init(struct zfcp_wka_port *wka_port, u32 d_id, |
| 114 | struct zfcp_adapter *adapter) |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 115 | { |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 116 | init_waitqueue_head(&wka_port->completion_wq); |
| 117 | |
| 118 | wka_port->adapter = adapter; |
Sven Schuetz | 9d544f2 | 2009-04-06 18:31:47 +0200 | [diff] [blame] | 119 | wka_port->d_id = d_id; |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 120 | |
| 121 | wka_port->status = ZFCP_WKA_PORT_OFFLINE; |
| 122 | atomic_set(&wka_port->refcount, 0); |
| 123 | mutex_init(&wka_port->mutex); |
Swen Schillig | 6f53a2d | 2009-08-18 15:43:23 +0200 | [diff] [blame] | 124 | INIT_DELAYED_WORK(&wka_port->work, zfcp_fc_wka_port_offline); |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 125 | } |
| 126 | |
Christof Schmitt | 55c770f | 2009-08-18 15:43:12 +0200 | [diff] [blame] | 127 | static void zfcp_fc_wka_port_force_offline(struct zfcp_wka_port *wka) |
Swen Schillig | 828bc12 | 2009-04-17 15:08:05 +0200 | [diff] [blame] | 128 | { |
| 129 | cancel_delayed_work_sync(&wka->work); |
| 130 | mutex_lock(&wka->mutex); |
| 131 | wka->status = ZFCP_WKA_PORT_OFFLINE; |
| 132 | mutex_unlock(&wka->mutex); |
| 133 | } |
| 134 | |
Christof Schmitt | 55c770f | 2009-08-18 15:43:12 +0200 | [diff] [blame] | 135 | void zfcp_fc_wka_ports_force_offline(struct zfcp_wka_ports *gs) |
| 136 | { |
| 137 | zfcp_fc_wka_port_force_offline(&gs->ms); |
| 138 | zfcp_fc_wka_port_force_offline(&gs->ts); |
| 139 | zfcp_fc_wka_port_force_offline(&gs->ds); |
| 140 | zfcp_fc_wka_port_force_offline(&gs->as); |
| 141 | zfcp_fc_wka_port_force_offline(&gs->ks); |
| 142 | } |
| 143 | |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 144 | static void _zfcp_fc_incoming_rscn(struct zfcp_fsf_req *fsf_req, u32 range, |
| 145 | struct fcp_rscn_element *elem) |
| 146 | { |
| 147 | unsigned long flags; |
Swen Schillig | ecf0c77 | 2009-11-24 16:53:58 +0100 | [diff] [blame^] | 148 | struct zfcp_adapter *adapter = fsf_req->adapter; |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 149 | struct zfcp_port *port; |
| 150 | |
Swen Schillig | ecf0c77 | 2009-11-24 16:53:58 +0100 | [diff] [blame^] | 151 | read_lock_irqsave(&adapter->port_list_lock, flags); |
| 152 | list_for_each_entry(port, &adapter->port_list, list) { |
Swen Schillig | 2409549 | 2009-03-02 13:09:07 +0100 | [diff] [blame] | 153 | if ((port->d_id & range) == (elem->nport_did & range)) |
Swen Schillig | 6f53a2d | 2009-08-18 15:43:23 +0200 | [diff] [blame] | 154 | zfcp_fc_test_link(port); |
Swen Schillig | ea460a8 | 2009-05-15 13:18:20 +0200 | [diff] [blame] | 155 | if (!port->d_id) |
| 156 | zfcp_erp_port_reopen(port, |
| 157 | ZFCP_STATUS_COMMON_ERP_FAILED, |
| 158 | "fcrscn1", NULL); |
| 159 | } |
Swen Schillig | ecf0c77 | 2009-11-24 16:53:58 +0100 | [diff] [blame^] | 160 | read_unlock_irqrestore(&adapter->port_list_lock, flags); |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 161 | } |
| 162 | |
| 163 | static void zfcp_fc_incoming_rscn(struct zfcp_fsf_req *fsf_req) |
| 164 | { |
| 165 | struct fsf_status_read_buffer *status_buffer = (void *)fsf_req->data; |
| 166 | struct fcp_rscn_head *fcp_rscn_head; |
| 167 | struct fcp_rscn_element *fcp_rscn_element; |
| 168 | u16 i; |
| 169 | u16 no_entries; |
| 170 | u32 range_mask; |
| 171 | |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 172 | fcp_rscn_head = (struct fcp_rscn_head *) status_buffer->payload.data; |
| 173 | fcp_rscn_element = (struct fcp_rscn_element *) fcp_rscn_head; |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 174 | |
| 175 | /* see FC-FS */ |
| 176 | no_entries = fcp_rscn_head->payload_len / |
| 177 | sizeof(struct fcp_rscn_element); |
| 178 | |
| 179 | for (i = 1; i < no_entries; i++) { |
| 180 | /* skip head and start with 1st element */ |
| 181 | fcp_rscn_element++; |
Christof Schmitt | e0d7fcb | 2008-12-19 16:56:58 +0100 | [diff] [blame] | 182 | range_mask = rscn_range_mask[fcp_rscn_element->addr_format]; |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 183 | _zfcp_fc_incoming_rscn(fsf_req, range_mask, fcp_rscn_element); |
| 184 | } |
Swen Schillig | cc8c282 | 2008-06-10 18:21:00 +0200 | [diff] [blame] | 185 | schedule_work(&fsf_req->adapter->scan_work); |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 186 | } |
| 187 | |
Swen Schillig | 7ba58c9 | 2008-10-01 12:42:18 +0200 | [diff] [blame] | 188 | 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] | 189 | { |
Swen Schillig | ecf0c77 | 2009-11-24 16:53:58 +0100 | [diff] [blame^] | 190 | unsigned long flags; |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 191 | struct zfcp_adapter *adapter = req->adapter; |
| 192 | struct zfcp_port *port; |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 193 | |
Swen Schillig | ecf0c77 | 2009-11-24 16:53:58 +0100 | [diff] [blame^] | 194 | read_lock_irqsave(&adapter->port_list_lock, flags); |
| 195 | list_for_each_entry(port, &adapter->port_list, list) |
| 196 | if (port->wwpn == wwpn) { |
| 197 | zfcp_erp_port_forced_reopen(port, 0, "fciwwp1", req); |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 198 | break; |
Swen Schillig | ecf0c77 | 2009-11-24 16:53:58 +0100 | [diff] [blame^] | 199 | } |
| 200 | read_unlock_irqrestore(&adapter->port_list_lock, flags); |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 201 | } |
| 202 | |
| 203 | static void zfcp_fc_incoming_plogi(struct zfcp_fsf_req *req) |
| 204 | { |
| 205 | struct fsf_status_read_buffer *status_buffer = |
| 206 | (struct fsf_status_read_buffer *)req->data; |
| 207 | struct fsf_plogi *els_plogi = |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 208 | (struct fsf_plogi *) status_buffer->payload.data; |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 209 | |
| 210 | zfcp_fc_incoming_wwpn(req, els_plogi->serv_param.wwpn); |
| 211 | } |
| 212 | |
| 213 | static void zfcp_fc_incoming_logo(struct zfcp_fsf_req *req) |
| 214 | { |
| 215 | struct fsf_status_read_buffer *status_buffer = |
| 216 | (struct fsf_status_read_buffer *)req->data; |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 217 | struct fcp_logo *els_logo = |
| 218 | (struct fcp_logo *) status_buffer->payload.data; |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 219 | |
| 220 | zfcp_fc_incoming_wwpn(req, els_logo->nport_wwpn); |
| 221 | } |
| 222 | |
| 223 | /** |
| 224 | * zfcp_fc_incoming_els - handle incoming ELS |
| 225 | * @fsf_req - request which contains incoming ELS |
| 226 | */ |
| 227 | void zfcp_fc_incoming_els(struct zfcp_fsf_req *fsf_req) |
| 228 | { |
| 229 | struct fsf_status_read_buffer *status_buffer = |
| 230 | (struct fsf_status_read_buffer *) fsf_req->data; |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 231 | unsigned int els_type = status_buffer->payload.data[0]; |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 232 | |
Swen Schillig | 5771710 | 2009-08-18 15:43:21 +0200 | [diff] [blame] | 233 | zfcp_dbf_san_incoming_els(fsf_req); |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 234 | if (els_type == LS_PLOGI) |
| 235 | zfcp_fc_incoming_plogi(fsf_req); |
| 236 | else if (els_type == LS_LOGO) |
| 237 | zfcp_fc_incoming_logo(fsf_req); |
| 238 | else if (els_type == LS_RSCN) |
| 239 | zfcp_fc_incoming_rscn(fsf_req); |
| 240 | } |
| 241 | |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 242 | static void zfcp_fc_ns_handler(unsigned long data) |
| 243 | { |
| 244 | struct zfcp_fc_ns_handler_data *compl_rec = |
| 245 | (struct zfcp_fc_ns_handler_data *) data; |
| 246 | |
| 247 | if (compl_rec->handler) |
| 248 | compl_rec->handler(compl_rec->handler_data); |
| 249 | |
| 250 | complete(&compl_rec->done); |
| 251 | } |
| 252 | |
| 253 | static void zfcp_fc_ns_gid_pn_eval(unsigned long data) |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 254 | { |
| 255 | struct zfcp_gid_pn_data *gid_pn = (struct zfcp_gid_pn_data *) data; |
| 256 | struct zfcp_send_ct *ct = &gid_pn->ct; |
| 257 | struct ct_iu_gid_pn_req *ct_iu_req = sg_virt(ct->req); |
| 258 | struct ct_iu_gid_pn_resp *ct_iu_resp = sg_virt(ct->resp); |
| 259 | struct zfcp_port *port = gid_pn->port; |
| 260 | |
| 261 | if (ct->status) |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 262 | return; |
Christof Schmitt | a5b11dd | 2009-03-02 13:08:54 +0100 | [diff] [blame] | 263 | if (ct_iu_resp->header.cmd_rsp_code != ZFCP_CT_ACCEPT) |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 264 | return; |
Christof Schmitt | a5b11dd | 2009-03-02 13:08:54 +0100 | [diff] [blame] | 265 | |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 266 | /* paranoia */ |
| 267 | if (ct_iu_req->wwpn != port->wwpn) |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 268 | return; |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 269 | /* looks like a valid d_id */ |
| 270 | port->d_id = ct_iu_resp->d_id & ZFCP_DID_MASK; |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 271 | } |
| 272 | |
Christof Schmitt | 799b76d | 2009-08-18 15:43:20 +0200 | [diff] [blame] | 273 | static int zfcp_fc_ns_gid_pn_request(struct zfcp_port *port, |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 274 | struct zfcp_gid_pn_data *gid_pn) |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 275 | { |
Christof Schmitt | 799b76d | 2009-08-18 15:43:20 +0200 | [diff] [blame] | 276 | struct zfcp_adapter *adapter = port->adapter; |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 277 | struct zfcp_fc_ns_handler_data compl_rec; |
| 278 | int ret; |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 279 | |
| 280 | /* setup parameters for send generic command */ |
Christof Schmitt | 799b76d | 2009-08-18 15:43:20 +0200 | [diff] [blame] | 281 | gid_pn->port = port; |
Sven Schuetz | 9d544f2 | 2009-04-06 18:31:47 +0200 | [diff] [blame] | 282 | gid_pn->ct.wka_port = &adapter->gs->ds; |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 283 | gid_pn->ct.handler = zfcp_fc_ns_handler; |
| 284 | gid_pn->ct.handler_data = (unsigned long) &compl_rec; |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 285 | gid_pn->ct.req = &gid_pn->req; |
| 286 | gid_pn->ct.resp = &gid_pn->resp; |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 287 | sg_init_one(&gid_pn->req, &gid_pn->ct_iu_req, |
| 288 | sizeof(struct ct_iu_gid_pn_req)); |
| 289 | sg_init_one(&gid_pn->resp, &gid_pn->ct_iu_resp, |
| 290 | sizeof(struct ct_iu_gid_pn_resp)); |
| 291 | |
| 292 | /* setup nameserver request */ |
| 293 | gid_pn->ct_iu_req.header.revision = ZFCP_CT_REVISION; |
| 294 | gid_pn->ct_iu_req.header.gs_type = ZFCP_CT_DIRECTORY_SERVICE; |
| 295 | gid_pn->ct_iu_req.header.gs_subtype = ZFCP_CT_NAME_SERVER; |
| 296 | gid_pn->ct_iu_req.header.options = ZFCP_CT_SYNCHRONOUS; |
| 297 | gid_pn->ct_iu_req.header.cmd_rsp_code = ZFCP_CT_GID_PN; |
Christof Schmitt | 39eb7e9a | 2008-12-19 16:57:01 +0100 | [diff] [blame] | 298 | gid_pn->ct_iu_req.header.max_res_size = ZFCP_CT_SIZE_ONE_PAGE / 4; |
Christof Schmitt | 799b76d | 2009-08-18 15:43:20 +0200 | [diff] [blame] | 299 | gid_pn->ct_iu_req.wwpn = port->wwpn; |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 300 | |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 301 | init_completion(&compl_rec.done); |
| 302 | compl_rec.handler = zfcp_fc_ns_gid_pn_eval; |
| 303 | compl_rec.handler_data = (unsigned long) gid_pn; |
Christof Schmitt | 799b76d | 2009-08-18 15:43:20 +0200 | [diff] [blame] | 304 | ret = zfcp_fsf_send_ct(&gid_pn->ct, adapter->pool.gid_pn_req); |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 305 | if (!ret) |
| 306 | wait_for_completion(&compl_rec.done); |
| 307 | return ret; |
| 308 | } |
| 309 | |
| 310 | /** |
| 311 | * zfcp_fc_ns_gid_pn_request - initiate GID_PN nameserver request |
Christof Schmitt | 799b76d | 2009-08-18 15:43:20 +0200 | [diff] [blame] | 312 | * @port: port where GID_PN request is needed |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 313 | * return: -ENOMEM on error, 0 otherwise |
| 314 | */ |
Christof Schmitt | 799b76d | 2009-08-18 15:43:20 +0200 | [diff] [blame] | 315 | static int zfcp_fc_ns_gid_pn(struct zfcp_port *port) |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 316 | { |
| 317 | int ret; |
| 318 | struct zfcp_gid_pn_data *gid_pn; |
Christof Schmitt | 799b76d | 2009-08-18 15:43:20 +0200 | [diff] [blame] | 319 | struct zfcp_adapter *adapter = port->adapter; |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 320 | |
Swen Schillig | a4623c4 | 2009-08-18 15:43:15 +0200 | [diff] [blame] | 321 | gid_pn = mempool_alloc(adapter->pool.gid_pn_data, GFP_ATOMIC); |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 322 | if (!gid_pn) |
| 323 | return -ENOMEM; |
| 324 | |
| 325 | memset(gid_pn, 0, sizeof(*gid_pn)); |
| 326 | |
Swen Schillig | 6f53a2d | 2009-08-18 15:43:23 +0200 | [diff] [blame] | 327 | ret = zfcp_fc_wka_port_get(&adapter->gs->ds); |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 328 | if (ret) |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 329 | goto out; |
| 330 | |
Christof Schmitt | 799b76d | 2009-08-18 15:43:20 +0200 | [diff] [blame] | 331 | ret = zfcp_fc_ns_gid_pn_request(port, gid_pn); |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 332 | |
Swen Schillig | 6f53a2d | 2009-08-18 15:43:23 +0200 | [diff] [blame] | 333 | zfcp_fc_wka_port_put(&adapter->gs->ds); |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 334 | out: |
Swen Schillig | a4623c4 | 2009-08-18 15:43:15 +0200 | [diff] [blame] | 335 | mempool_free(gid_pn, adapter->pool.gid_pn_data); |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 336 | return ret; |
| 337 | } |
| 338 | |
Christof Schmitt | 799b76d | 2009-08-18 15:43:20 +0200 | [diff] [blame] | 339 | void zfcp_fc_port_did_lookup(struct work_struct *work) |
| 340 | { |
| 341 | int ret; |
| 342 | struct zfcp_port *port = container_of(work, struct zfcp_port, |
| 343 | gid_pn_work); |
| 344 | |
| 345 | ret = zfcp_fc_ns_gid_pn(port); |
| 346 | if (ret) { |
| 347 | /* could not issue gid_pn for some reason */ |
| 348 | zfcp_erp_adapter_reopen(port->adapter, 0, "fcgpn_1", NULL); |
| 349 | goto out; |
| 350 | } |
| 351 | |
| 352 | if (!port->d_id) { |
| 353 | zfcp_erp_port_failed(port, "fcgpn_2", NULL); |
| 354 | goto out; |
| 355 | } |
| 356 | |
| 357 | zfcp_erp_port_reopen(port, 0, "fcgpn_3", NULL); |
| 358 | out: |
| 359 | zfcp_port_put(port); |
| 360 | } |
| 361 | |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 362 | /** |
Christof Schmitt | 934aeb587 | 2009-10-14 11:00:43 +0200 | [diff] [blame] | 363 | * zfcp_fc_trigger_did_lookup - trigger the d_id lookup using a GID_PN request |
| 364 | * @port: The zfcp_port to lookup the d_id for. |
| 365 | */ |
| 366 | void zfcp_fc_trigger_did_lookup(struct zfcp_port *port) |
| 367 | { |
| 368 | zfcp_port_get(port); |
| 369 | if (!queue_work(port->adapter->work_queue, &port->gid_pn_work)) |
| 370 | zfcp_port_put(port); |
| 371 | } |
| 372 | |
| 373 | /** |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 374 | * zfcp_fc_plogi_evaluate - evaluate PLOGI playload |
| 375 | * @port: zfcp_port structure |
| 376 | * @plogi: plogi payload |
| 377 | * |
| 378 | * Evaluate PLOGI playload and copy important fields into zfcp_port structure |
| 379 | */ |
| 380 | void zfcp_fc_plogi_evaluate(struct zfcp_port *port, struct fsf_plogi *plogi) |
| 381 | { |
| 382 | port->maxframe_size = plogi->serv_param.common_serv_param[7] | |
| 383 | ((plogi->serv_param.common_serv_param[6] & 0x0F) << 8); |
| 384 | if (plogi->serv_param.class1_serv_param[0] & 0x80) |
| 385 | port->supported_classes |= FC_COS_CLASS1; |
| 386 | if (plogi->serv_param.class2_serv_param[0] & 0x80) |
| 387 | port->supported_classes |= FC_COS_CLASS2; |
| 388 | if (plogi->serv_param.class3_serv_param[0] & 0x80) |
| 389 | port->supported_classes |= FC_COS_CLASS3; |
| 390 | if (plogi->serv_param.class4_serv_param[0] & 0x80) |
| 391 | port->supported_classes |= FC_COS_CLASS4; |
| 392 | } |
| 393 | |
| 394 | struct zfcp_els_adisc { |
| 395 | struct zfcp_send_els els; |
| 396 | struct scatterlist req; |
| 397 | struct scatterlist resp; |
| 398 | struct zfcp_ls_adisc ls_adisc; |
Swen Schillig | 44cc76f | 2008-10-01 12:42:16 +0200 | [diff] [blame] | 399 | struct zfcp_ls_adisc ls_adisc_acc; |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 400 | }; |
| 401 | |
| 402 | static void zfcp_fc_adisc_handler(unsigned long data) |
| 403 | { |
| 404 | struct zfcp_els_adisc *adisc = (struct zfcp_els_adisc *) data; |
| 405 | struct zfcp_port *port = adisc->els.port; |
Swen Schillig | 44cc76f | 2008-10-01 12:42:16 +0200 | [diff] [blame] | 406 | struct zfcp_ls_adisc *ls_adisc = &adisc->ls_adisc_acc; |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 407 | |
Christof Schmitt | 3968ce8 | 2008-07-02 10:56:32 +0200 | [diff] [blame] | 408 | if (adisc->els.status) { |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 409 | /* request rejected or timed out */ |
Swen Schillig | 5b43e71 | 2009-04-17 15:08:10 +0200 | [diff] [blame] | 410 | zfcp_erp_port_forced_reopen(port, ZFCP_STATUS_COMMON_ERP_FAILED, |
| 411 | "fcadh_1", NULL); |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 412 | goto out; |
| 413 | } |
| 414 | |
| 415 | if (!port->wwnn) |
| 416 | port->wwnn = ls_adisc->wwnn; |
| 417 | |
Swen Schillig | 2409549 | 2009-03-02 13:09:07 +0100 | [diff] [blame] | 418 | if ((port->wwpn != ls_adisc->wwpn) || |
Christof Schmitt | a2fa0ae | 2009-03-02 13:09:08 +0100 | [diff] [blame] | 419 | !(atomic_read(&port->status) & ZFCP_STATUS_COMMON_OPEN)) { |
Swen Schillig | 2409549 | 2009-03-02 13:09:07 +0100 | [diff] [blame] | 420 | zfcp_erp_port_reopen(port, ZFCP_STATUS_COMMON_ERP_FAILED, |
| 421 | "fcadh_2", NULL); |
Christof Schmitt | a2fa0ae | 2009-03-02 13:09:08 +0100 | [diff] [blame] | 422 | goto out; |
| 423 | } |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 424 | |
Christof Schmitt | a2fa0ae | 2009-03-02 13:09:08 +0100 | [diff] [blame] | 425 | /* port is good, unblock rport without going through erp */ |
| 426 | zfcp_scsi_schedule_rport_register(port); |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 427 | out: |
Christof Schmitt | 14e242e | 2009-08-18 15:43:11 +0200 | [diff] [blame] | 428 | atomic_clear_mask(ZFCP_STATUS_PORT_LINK_TEST, &port->status); |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 429 | zfcp_port_put(port); |
| 430 | kfree(adisc); |
| 431 | } |
| 432 | |
| 433 | static int zfcp_fc_adisc(struct zfcp_port *port) |
| 434 | { |
| 435 | struct zfcp_els_adisc *adisc; |
| 436 | struct zfcp_adapter *adapter = port->adapter; |
| 437 | |
| 438 | adisc = kzalloc(sizeof(struct zfcp_els_adisc), GFP_ATOMIC); |
| 439 | if (!adisc) |
| 440 | return -ENOMEM; |
| 441 | |
| 442 | adisc->els.req = &adisc->req; |
| 443 | adisc->els.resp = &adisc->resp; |
| 444 | sg_init_one(adisc->els.req, &adisc->ls_adisc, |
| 445 | sizeof(struct zfcp_ls_adisc)); |
| 446 | sg_init_one(adisc->els.resp, &adisc->ls_adisc_acc, |
Swen Schillig | 44cc76f | 2008-10-01 12:42:16 +0200 | [diff] [blame] | 447 | sizeof(struct zfcp_ls_adisc)); |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 448 | |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 449 | adisc->els.adapter = adapter; |
| 450 | adisc->els.port = port; |
| 451 | adisc->els.d_id = port->d_id; |
| 452 | adisc->els.handler = zfcp_fc_adisc_handler; |
| 453 | adisc->els.handler_data = (unsigned long) adisc; |
| 454 | adisc->els.ls_code = adisc->ls_adisc.code = ZFCP_LS_ADISC; |
| 455 | |
| 456 | /* acc. to FC-FS, hard_nport_id in ADISC should not be set for ports |
| 457 | without FC-AL-2 capability, so we don't set it */ |
| 458 | adisc->ls_adisc.wwpn = fc_host_port_name(adapter->scsi_host); |
| 459 | adisc->ls_adisc.wwnn = fc_host_node_name(adapter->scsi_host); |
| 460 | adisc->ls_adisc.nport_id = fc_host_port_id(adapter->scsi_host); |
| 461 | |
| 462 | return zfcp_fsf_send_els(&adisc->els); |
| 463 | } |
| 464 | |
Christof Schmitt | 8fdf30d | 2009-03-02 13:09:01 +0100 | [diff] [blame] | 465 | void zfcp_fc_link_test_work(struct work_struct *work) |
| 466 | { |
| 467 | struct zfcp_port *port = |
| 468 | container_of(work, struct zfcp_port, test_link_work); |
| 469 | int retval; |
| 470 | |
Christof Schmitt | a2fa0ae | 2009-03-02 13:09:08 +0100 | [diff] [blame] | 471 | zfcp_port_get(port); |
| 472 | port->rport_task = RPORT_DEL; |
| 473 | zfcp_scsi_rport_work(&port->rport_work); |
| 474 | |
Christof Schmitt | 14e242e | 2009-08-18 15:43:11 +0200 | [diff] [blame] | 475 | /* only issue one test command at one time per port */ |
| 476 | if (atomic_read(&port->status) & ZFCP_STATUS_PORT_LINK_TEST) |
| 477 | goto out; |
| 478 | |
| 479 | atomic_set_mask(ZFCP_STATUS_PORT_LINK_TEST, &port->status); |
| 480 | |
Christof Schmitt | 8fdf30d | 2009-03-02 13:09:01 +0100 | [diff] [blame] | 481 | retval = zfcp_fc_adisc(port); |
| 482 | if (retval == 0) |
| 483 | return; |
| 484 | |
| 485 | /* send of ADISC was not possible */ |
Christof Schmitt | 14e242e | 2009-08-18 15:43:11 +0200 | [diff] [blame] | 486 | atomic_clear_mask(ZFCP_STATUS_PORT_LINK_TEST, &port->status); |
Christof Schmitt | a2fa0ae | 2009-03-02 13:09:08 +0100 | [diff] [blame] | 487 | zfcp_erp_port_forced_reopen(port, 0, "fcltwk1", NULL); |
| 488 | |
Christof Schmitt | 14e242e | 2009-08-18 15:43:11 +0200 | [diff] [blame] | 489 | out: |
Christof Schmitt | 8fdf30d | 2009-03-02 13:09:01 +0100 | [diff] [blame] | 490 | zfcp_port_put(port); |
Christof Schmitt | 8fdf30d | 2009-03-02 13:09:01 +0100 | [diff] [blame] | 491 | } |
| 492 | |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 493 | /** |
Swen Schillig | 6f53a2d | 2009-08-18 15:43:23 +0200 | [diff] [blame] | 494 | * zfcp_fc_test_link - lightweight link test procedure |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 495 | * @port: port to be tested |
| 496 | * |
| 497 | * Test status of a link to a remote port using the ELS command ADISC. |
| 498 | * If there is a problem with the remote port, error recovery steps |
| 499 | * will be triggered. |
| 500 | */ |
Swen Schillig | 6f53a2d | 2009-08-18 15:43:23 +0200 | [diff] [blame] | 501 | void zfcp_fc_test_link(struct zfcp_port *port) |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 502 | { |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 503 | zfcp_port_get(port); |
Swen Schillig | 4544683 | 2009-08-18 15:43:17 +0200 | [diff] [blame] | 504 | if (!queue_work(port->adapter->work_queue, &port->test_link_work)) |
Christof Schmitt | 8fdf30d | 2009-03-02 13:09:01 +0100 | [diff] [blame] | 505 | zfcp_port_put(port); |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 506 | } |
Swen Schillig | cc8c282 | 2008-06-10 18:21:00 +0200 | [diff] [blame] | 507 | |
Christof Schmitt | 39eb7e9a | 2008-12-19 16:57:01 +0100 | [diff] [blame] | 508 | static void zfcp_free_sg_env(struct zfcp_gpn_ft *gpn_ft, int buf_num) |
Swen Schillig | cc8c282 | 2008-06-10 18:21:00 +0200 | [diff] [blame] | 509 | { |
| 510 | struct scatterlist *sg = &gpn_ft->sg_req; |
| 511 | |
Swen Schillig | a4623c4 | 2009-08-18 15:43:15 +0200 | [diff] [blame] | 512 | kmem_cache_free(zfcp_data.gpn_ft_cache, sg_virt(sg)); |
Christof Schmitt | 39eb7e9a | 2008-12-19 16:57:01 +0100 | [diff] [blame] | 513 | zfcp_sg_free_table(gpn_ft->sg_resp, buf_num); |
Swen Schillig | cc8c282 | 2008-06-10 18:21:00 +0200 | [diff] [blame] | 514 | |
| 515 | kfree(gpn_ft); |
| 516 | } |
| 517 | |
Christof Schmitt | 39eb7e9a | 2008-12-19 16:57:01 +0100 | [diff] [blame] | 518 | static struct zfcp_gpn_ft *zfcp_alloc_sg_env(int buf_num) |
Swen Schillig | cc8c282 | 2008-06-10 18:21:00 +0200 | [diff] [blame] | 519 | { |
| 520 | struct zfcp_gpn_ft *gpn_ft; |
| 521 | struct ct_iu_gpn_ft_req *req; |
| 522 | |
| 523 | gpn_ft = kzalloc(sizeof(*gpn_ft), GFP_KERNEL); |
| 524 | if (!gpn_ft) |
| 525 | return NULL; |
| 526 | |
Swen Schillig | a4623c4 | 2009-08-18 15:43:15 +0200 | [diff] [blame] | 527 | req = kmem_cache_alloc(zfcp_data.gpn_ft_cache, GFP_KERNEL); |
Swen Schillig | cc8c282 | 2008-06-10 18:21:00 +0200 | [diff] [blame] | 528 | if (!req) { |
| 529 | kfree(gpn_ft); |
| 530 | gpn_ft = NULL; |
| 531 | goto out; |
| 532 | } |
| 533 | sg_init_one(&gpn_ft->sg_req, req, sizeof(*req)); |
| 534 | |
Christof Schmitt | 39eb7e9a | 2008-12-19 16:57:01 +0100 | [diff] [blame] | 535 | if (zfcp_sg_setup_table(gpn_ft->sg_resp, buf_num)) { |
| 536 | zfcp_free_sg_env(gpn_ft, buf_num); |
Swen Schillig | cc8c282 | 2008-06-10 18:21:00 +0200 | [diff] [blame] | 537 | gpn_ft = NULL; |
| 538 | } |
| 539 | out: |
| 540 | return gpn_ft; |
| 541 | } |
| 542 | |
| 543 | |
Swen Schillig | 6f53a2d | 2009-08-18 15:43:23 +0200 | [diff] [blame] | 544 | static int zfcp_fc_send_gpn_ft(struct zfcp_gpn_ft *gpn_ft, |
| 545 | struct zfcp_adapter *adapter, int max_bytes) |
Swen Schillig | cc8c282 | 2008-06-10 18:21:00 +0200 | [diff] [blame] | 546 | { |
| 547 | struct zfcp_send_ct *ct = &gpn_ft->ct; |
| 548 | struct ct_iu_gpn_ft_req *req = sg_virt(&gpn_ft->sg_req); |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 549 | struct zfcp_fc_ns_handler_data compl_rec; |
Swen Schillig | cc8c282 | 2008-06-10 18:21:00 +0200 | [diff] [blame] | 550 | int ret; |
| 551 | |
| 552 | /* prepare CT IU for GPN_FT */ |
| 553 | req->header.revision = ZFCP_CT_REVISION; |
| 554 | req->header.gs_type = ZFCP_CT_DIRECTORY_SERVICE; |
| 555 | req->header.gs_subtype = ZFCP_CT_NAME_SERVER; |
| 556 | req->header.options = ZFCP_CT_SYNCHRONOUS; |
| 557 | req->header.cmd_rsp_code = ZFCP_CT_GPN_FT; |
Christof Schmitt | 39eb7e9a | 2008-12-19 16:57:01 +0100 | [diff] [blame] | 558 | req->header.max_res_size = max_bytes / 4; |
Swen Schillig | cc8c282 | 2008-06-10 18:21:00 +0200 | [diff] [blame] | 559 | req->flags = 0; |
| 560 | req->domain_id_scope = 0; |
| 561 | req->area_id_scope = 0; |
| 562 | req->fc4_type = ZFCP_CT_SCSI_FCP; |
| 563 | |
| 564 | /* prepare zfcp_send_ct */ |
Sven Schuetz | 9d544f2 | 2009-04-06 18:31:47 +0200 | [diff] [blame] | 565 | ct->wka_port = &adapter->gs->ds; |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 566 | ct->handler = zfcp_fc_ns_handler; |
| 567 | ct->handler_data = (unsigned long)&compl_rec; |
Swen Schillig | cc8c282 | 2008-06-10 18:21:00 +0200 | [diff] [blame] | 568 | ct->req = &gpn_ft->sg_req; |
| 569 | ct->resp = gpn_ft->sg_resp; |
Swen Schillig | cc8c282 | 2008-06-10 18:21:00 +0200 | [diff] [blame] | 570 | |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 571 | init_completion(&compl_rec.done); |
| 572 | compl_rec.handler = NULL; |
Christof Schmitt | 799b76d | 2009-08-18 15:43:20 +0200 | [diff] [blame] | 573 | ret = zfcp_fsf_send_ct(ct, NULL); |
Swen Schillig | cc8c282 | 2008-06-10 18:21:00 +0200 | [diff] [blame] | 574 | if (!ret) |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 575 | wait_for_completion(&compl_rec.done); |
Swen Schillig | cc8c282 | 2008-06-10 18:21:00 +0200 | [diff] [blame] | 576 | return ret; |
| 577 | } |
| 578 | |
Swen Schillig | 6f53a2d | 2009-08-18 15:43:23 +0200 | [diff] [blame] | 579 | static void zfcp_fc_validate_port(struct zfcp_port *port) |
Swen Schillig | cc8c282 | 2008-06-10 18:21:00 +0200 | [diff] [blame] | 580 | { |
Martin Petermann | 6ab35c0 | 2009-04-17 15:08:13 +0200 | [diff] [blame] | 581 | if (!(atomic_read(&port->status) & ZFCP_STATUS_COMMON_NOESC)) |
| 582 | return; |
| 583 | |
Swen Schillig | cc8c282 | 2008-06-10 18:21:00 +0200 | [diff] [blame] | 584 | atomic_clear_mask(ZFCP_STATUS_COMMON_NOESC, &port->status); |
| 585 | |
Christof Schmitt | 0406289 | 2008-10-01 12:42:20 +0200 | [diff] [blame] | 586 | if ((port->supported_classes != 0) || |
Swen Schillig | ecf0c77 | 2009-11-24 16:53:58 +0100 | [diff] [blame^] | 587 | !list_empty(&port->unit_list)) { |
Swen Schillig | cc8c282 | 2008-06-10 18:21:00 +0200 | [diff] [blame] | 588 | zfcp_port_put(port); |
| 589 | return; |
| 590 | } |
Swen Schillig | 5ffd51a | 2009-03-02 13:09:04 +0100 | [diff] [blame] | 591 | zfcp_erp_port_shutdown(port, 0, "fcpval1", NULL); |
Swen Schillig | cc8c282 | 2008-06-10 18:21:00 +0200 | [diff] [blame] | 592 | zfcp_port_put(port); |
| 593 | zfcp_port_dequeue(port); |
| 594 | } |
| 595 | |
Swen Schillig | 6f53a2d | 2009-08-18 15:43:23 +0200 | [diff] [blame] | 596 | static int zfcp_fc_eval_gpn_ft(struct zfcp_gpn_ft *gpn_ft, int max_entries) |
Swen Schillig | cc8c282 | 2008-06-10 18:21:00 +0200 | [diff] [blame] | 597 | { |
| 598 | struct zfcp_send_ct *ct = &gpn_ft->ct; |
| 599 | struct scatterlist *sg = gpn_ft->sg_resp; |
| 600 | struct ct_hdr *hdr = sg_virt(sg); |
| 601 | struct gpn_ft_resp_acc *acc = sg_virt(sg); |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 602 | struct zfcp_adapter *adapter = ct->wka_port->adapter; |
Swen Schillig | cc8c282 | 2008-06-10 18:21:00 +0200 | [diff] [blame] | 603 | struct zfcp_port *port, *tmp; |
Swen Schillig | ecf0c77 | 2009-11-24 16:53:58 +0100 | [diff] [blame^] | 604 | unsigned long flags; |
Swen Schillig | cc8c282 | 2008-06-10 18:21:00 +0200 | [diff] [blame] | 605 | u32 d_id; |
Christof Schmitt | 47f7bba | 2008-08-21 13:43:33 +0200 | [diff] [blame] | 606 | int ret = 0, x, last = 0; |
Swen Schillig | cc8c282 | 2008-06-10 18:21:00 +0200 | [diff] [blame] | 607 | |
| 608 | if (ct->status) |
| 609 | return -EIO; |
| 610 | |
| 611 | if (hdr->cmd_rsp_code != ZFCP_CT_ACCEPT) { |
| 612 | if (hdr->reason_code == ZFCP_CT_UNABLE_TO_PERFORM_CMD) |
| 613 | return -EAGAIN; /* might be a temporary condition */ |
| 614 | return -EIO; |
| 615 | } |
| 616 | |
Christof Schmitt | 39eb7e9a | 2008-12-19 16:57:01 +0100 | [diff] [blame] | 617 | if (hdr->max_res_size) { |
| 618 | dev_warn(&adapter->ccw_device->dev, |
| 619 | "The name server reported %d words residual data\n", |
| 620 | hdr->max_res_size); |
Swen Schillig | cc8c282 | 2008-06-10 18:21:00 +0200 | [diff] [blame] | 621 | return -E2BIG; |
Christof Schmitt | 39eb7e9a | 2008-12-19 16:57:01 +0100 | [diff] [blame] | 622 | } |
Swen Schillig | cc8c282 | 2008-06-10 18:21:00 +0200 | [diff] [blame] | 623 | |
Christof Schmitt | 24680de | 2009-08-18 15:43:28 +0200 | [diff] [blame] | 624 | mutex_lock(&zfcp_data.config_mutex); |
Swen Schillig | cc8c282 | 2008-06-10 18:21:00 +0200 | [diff] [blame] | 625 | |
| 626 | /* first entry is the header */ |
Christof Schmitt | 39eb7e9a | 2008-12-19 16:57:01 +0100 | [diff] [blame] | 627 | for (x = 1; x < max_entries && !last; x++) { |
Swen Schillig | cc8c282 | 2008-06-10 18:21:00 +0200 | [diff] [blame] | 628 | if (x % (ZFCP_GPN_FT_ENTRIES + 1)) |
| 629 | acc++; |
| 630 | else |
| 631 | acc = sg_virt(++sg); |
| 632 | |
Christof Schmitt | 47f7bba | 2008-08-21 13:43:33 +0200 | [diff] [blame] | 633 | last = acc->control & 0x80; |
Swen Schillig | cc8c282 | 2008-06-10 18:21:00 +0200 | [diff] [blame] | 634 | d_id = acc->port_id[0] << 16 | acc->port_id[1] << 8 | |
| 635 | acc->port_id[2]; |
| 636 | |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 637 | /* don't attach ports with a well known address */ |
| 638 | if ((d_id & ZFCP_DID_WKA) == ZFCP_DID_WKA) |
| 639 | continue; |
Swen Schillig | cc8c282 | 2008-06-10 18:21:00 +0200 | [diff] [blame] | 640 | /* skip the adapter's port and known remote ports */ |
Swen Schillig | 9528539 | 2008-08-21 13:43:35 +0200 | [diff] [blame] | 641 | if (acc->wwpn == fc_host_port_name(adapter->scsi_host)) |
Swen Schillig | cc8c282 | 2008-06-10 18:21:00 +0200 | [diff] [blame] | 642 | continue; |
| 643 | |
| 644 | port = zfcp_port_enqueue(adapter, acc->wwpn, |
Swen Schillig | cc8c282 | 2008-06-10 18:21:00 +0200 | [diff] [blame] | 645 | ZFCP_STATUS_COMMON_NOESC, d_id); |
Swen Schillig | ecf0c77 | 2009-11-24 16:53:58 +0100 | [diff] [blame^] | 646 | if (!IS_ERR(port)) |
Swen Schillig | 5ffd51a | 2009-03-02 13:09:04 +0100 | [diff] [blame] | 647 | zfcp_erp_port_reopen(port, 0, "fcegpf1", NULL); |
Swen Schillig | ecf0c77 | 2009-11-24 16:53:58 +0100 | [diff] [blame^] | 648 | else if (PTR_ERR(port) != -EEXIST) |
| 649 | ret = PTR_ERR(port); |
Swen Schillig | cc8c282 | 2008-06-10 18:21:00 +0200 | [diff] [blame] | 650 | } |
| 651 | |
| 652 | zfcp_erp_wait(adapter); |
Swen Schillig | ecf0c77 | 2009-11-24 16:53:58 +0100 | [diff] [blame^] | 653 | write_lock_irqsave(&adapter->port_list_lock, flags); |
| 654 | list_for_each_entry_safe(port, tmp, &adapter->port_list, list) |
Swen Schillig | 6f53a2d | 2009-08-18 15:43:23 +0200 | [diff] [blame] | 655 | zfcp_fc_validate_port(port); |
Swen Schillig | ecf0c77 | 2009-11-24 16:53:58 +0100 | [diff] [blame^] | 656 | write_unlock_irqrestore(&adapter->port_list_lock, flags); |
Christof Schmitt | 24680de | 2009-08-18 15:43:28 +0200 | [diff] [blame] | 657 | mutex_unlock(&zfcp_data.config_mutex); |
Swen Schillig | cc8c282 | 2008-06-10 18:21:00 +0200 | [diff] [blame] | 658 | return ret; |
| 659 | } |
| 660 | |
| 661 | /** |
Swen Schillig | 6f53a2d | 2009-08-18 15:43:23 +0200 | [diff] [blame] | 662 | * zfcp_fc_scan_ports - scan remote ports and attach new ports |
Swen Schillig | cc8c282 | 2008-06-10 18:21:00 +0200 | [diff] [blame] | 663 | * @adapter: pointer to struct zfcp_adapter |
| 664 | */ |
Swen Schillig | 6f53a2d | 2009-08-18 15:43:23 +0200 | [diff] [blame] | 665 | int zfcp_fc_scan_ports(struct zfcp_adapter *adapter) |
Swen Schillig | cc8c282 | 2008-06-10 18:21:00 +0200 | [diff] [blame] | 666 | { |
| 667 | int ret, i; |
| 668 | struct zfcp_gpn_ft *gpn_ft; |
Christof Schmitt | 39eb7e9a | 2008-12-19 16:57:01 +0100 | [diff] [blame] | 669 | int chain, max_entries, buf_num, max_bytes; |
| 670 | |
| 671 | chain = adapter->adapter_features & FSF_FEATURE_ELS_CT_CHAINED_SBALS; |
| 672 | buf_num = chain ? ZFCP_GPN_FT_BUFFERS : 1; |
| 673 | max_entries = chain ? ZFCP_GPN_FT_MAX_ENTRIES : ZFCP_GPN_FT_ENTRIES; |
| 674 | max_bytes = chain ? ZFCP_GPN_FT_MAX_SIZE : ZFCP_CT_SIZE_ONE_PAGE; |
Swen Schillig | cc8c282 | 2008-06-10 18:21:00 +0200 | [diff] [blame] | 675 | |
Swen Schillig | 306b6ed | 2009-04-17 15:08:02 +0200 | [diff] [blame] | 676 | if (fc_host_port_type(adapter->scsi_host) != FC_PORTTYPE_NPORT && |
| 677 | fc_host_port_type(adapter->scsi_host) != FC_PORTTYPE_NPIV) |
Swen Schillig | cc8c282 | 2008-06-10 18:21:00 +0200 | [diff] [blame] | 678 | return 0; |
| 679 | |
Swen Schillig | 6f53a2d | 2009-08-18 15:43:23 +0200 | [diff] [blame] | 680 | ret = zfcp_fc_wka_port_get(&adapter->gs->ds); |
Swen Schillig | cc8c282 | 2008-06-10 18:21:00 +0200 | [diff] [blame] | 681 | if (ret) |
| 682 | return ret; |
| 683 | |
Christof Schmitt | 39eb7e9a | 2008-12-19 16:57:01 +0100 | [diff] [blame] | 684 | gpn_ft = zfcp_alloc_sg_env(buf_num); |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 685 | if (!gpn_ft) { |
| 686 | ret = -ENOMEM; |
| 687 | goto out; |
| 688 | } |
Swen Schillig | cc8c282 | 2008-06-10 18:21:00 +0200 | [diff] [blame] | 689 | |
| 690 | for (i = 0; i < 3; i++) { |
Swen Schillig | 6f53a2d | 2009-08-18 15:43:23 +0200 | [diff] [blame] | 691 | ret = zfcp_fc_send_gpn_ft(gpn_ft, adapter, max_bytes); |
Swen Schillig | cc8c282 | 2008-06-10 18:21:00 +0200 | [diff] [blame] | 692 | if (!ret) { |
Swen Schillig | 6f53a2d | 2009-08-18 15:43:23 +0200 | [diff] [blame] | 693 | ret = zfcp_fc_eval_gpn_ft(gpn_ft, max_entries); |
Swen Schillig | cc8c282 | 2008-06-10 18:21:00 +0200 | [diff] [blame] | 694 | if (ret == -EAGAIN) |
| 695 | ssleep(1); |
| 696 | else |
| 697 | break; |
| 698 | } |
| 699 | } |
Christof Schmitt | 39eb7e9a | 2008-12-19 16:57:01 +0100 | [diff] [blame] | 700 | zfcp_free_sg_env(gpn_ft, buf_num); |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 701 | out: |
Swen Schillig | 6f53a2d | 2009-08-18 15:43:23 +0200 | [diff] [blame] | 702 | zfcp_fc_wka_port_put(&adapter->gs->ds); |
Swen Schillig | cc8c282 | 2008-06-10 18:21:00 +0200 | [diff] [blame] | 703 | return ret; |
| 704 | } |
| 705 | |
| 706 | |
Swen Schillig | 6f53a2d | 2009-08-18 15:43:23 +0200 | [diff] [blame] | 707 | void _zfcp_fc_scan_ports_later(struct work_struct *work) |
Swen Schillig | cc8c282 | 2008-06-10 18:21:00 +0200 | [diff] [blame] | 708 | { |
Swen Schillig | 6f53a2d | 2009-08-18 15:43:23 +0200 | [diff] [blame] | 709 | zfcp_fc_scan_ports(container_of(work, struct zfcp_adapter, scan_work)); |
Swen Schillig | cc8c282 | 2008-06-10 18:21:00 +0200 | [diff] [blame] | 710 | } |
Sven Schuetz | 9d544f2 | 2009-04-06 18:31:47 +0200 | [diff] [blame] | 711 | |
| 712 | struct zfcp_els_fc_job { |
| 713 | struct zfcp_send_els els; |
| 714 | struct fc_bsg_job *job; |
| 715 | }; |
| 716 | |
| 717 | static void zfcp_fc_generic_els_handler(unsigned long data) |
| 718 | { |
| 719 | struct zfcp_els_fc_job *els_fc_job = (struct zfcp_els_fc_job *) data; |
| 720 | struct fc_bsg_job *job = els_fc_job->job; |
| 721 | struct fc_bsg_reply *reply = job->reply; |
| 722 | |
| 723 | if (els_fc_job->els.status) { |
| 724 | /* request rejected or timed out */ |
| 725 | reply->reply_data.ctels_reply.status = FC_CTELS_STATUS_REJECT; |
| 726 | goto out; |
| 727 | } |
| 728 | |
| 729 | reply->reply_data.ctels_reply.status = FC_CTELS_STATUS_OK; |
Christof Schmitt | dc577d5 | 2009-05-15 13:18:22 +0200 | [diff] [blame] | 730 | reply->reply_payload_rcv_len = job->reply_payload.payload_len; |
Sven Schuetz | 9d544f2 | 2009-04-06 18:31:47 +0200 | [diff] [blame] | 731 | |
| 732 | out: |
| 733 | job->state_flags = FC_RQST_STATE_DONE; |
| 734 | job->job_done(job); |
| 735 | kfree(els_fc_job); |
| 736 | } |
| 737 | |
| 738 | int zfcp_fc_execute_els_fc_job(struct fc_bsg_job *job) |
| 739 | { |
| 740 | struct zfcp_els_fc_job *els_fc_job; |
| 741 | struct fc_rport *rport = job->rport; |
| 742 | struct Scsi_Host *shost; |
| 743 | struct zfcp_adapter *adapter; |
| 744 | struct zfcp_port *port; |
| 745 | u8 *port_did; |
| 746 | |
| 747 | shost = rport ? rport_to_shost(rport) : job->shost; |
| 748 | adapter = (struct zfcp_adapter *)shost->hostdata[0]; |
| 749 | |
| 750 | if (!(atomic_read(&adapter->status) & ZFCP_STATUS_COMMON_OPEN)) |
| 751 | return -EINVAL; |
| 752 | |
| 753 | els_fc_job = kzalloc(sizeof(struct zfcp_els_fc_job), GFP_KERNEL); |
| 754 | if (!els_fc_job) |
| 755 | return -ENOMEM; |
| 756 | |
| 757 | els_fc_job->els.adapter = adapter; |
| 758 | if (rport) { |
Swen Schillig | ea945ff | 2009-08-18 15:43:24 +0200 | [diff] [blame] | 759 | port = zfcp_get_port_by_wwpn(adapter, rport->port_name); |
Sven Schuetz | 9d544f2 | 2009-04-06 18:31:47 +0200 | [diff] [blame] | 760 | if (!port) { |
| 761 | kfree(els_fc_job); |
| 762 | return -EINVAL; |
| 763 | } |
Swen Schillig | ecf0c77 | 2009-11-24 16:53:58 +0100 | [diff] [blame^] | 764 | |
| 765 | els_fc_job->els.d_id = port->d_id; |
| 766 | zfcp_port_put(port); |
Sven Schuetz | 9d544f2 | 2009-04-06 18:31:47 +0200 | [diff] [blame] | 767 | } else { |
| 768 | port_did = job->request->rqst_data.h_els.port_id; |
| 769 | els_fc_job->els.d_id = (port_did[0] << 16) + |
| 770 | (port_did[1] << 8) + port_did[2]; |
| 771 | } |
| 772 | |
| 773 | els_fc_job->els.req = job->request_payload.sg_list; |
| 774 | els_fc_job->els.resp = job->reply_payload.sg_list; |
| 775 | els_fc_job->els.handler = zfcp_fc_generic_els_handler; |
| 776 | els_fc_job->els.handler_data = (unsigned long) els_fc_job; |
| 777 | els_fc_job->job = job; |
| 778 | |
| 779 | return zfcp_fsf_send_els(&els_fc_job->els); |
| 780 | } |
| 781 | |
| 782 | struct zfcp_ct_fc_job { |
| 783 | struct zfcp_send_ct ct; |
| 784 | struct fc_bsg_job *job; |
| 785 | }; |
| 786 | |
| 787 | static void zfcp_fc_generic_ct_handler(unsigned long data) |
| 788 | { |
| 789 | struct zfcp_ct_fc_job *ct_fc_job = (struct zfcp_ct_fc_job *) data; |
| 790 | struct fc_bsg_job *job = ct_fc_job->job; |
| 791 | |
| 792 | job->reply->reply_data.ctels_reply.status = ct_fc_job->ct.status ? |
| 793 | FC_CTELS_STATUS_REJECT : FC_CTELS_STATUS_OK; |
Christof Schmitt | dc577d5 | 2009-05-15 13:18:22 +0200 | [diff] [blame] | 794 | job->reply->reply_payload_rcv_len = job->reply_payload.payload_len; |
Sven Schuetz | 9d544f2 | 2009-04-06 18:31:47 +0200 | [diff] [blame] | 795 | job->state_flags = FC_RQST_STATE_DONE; |
Sven Schuetz | 9d544f2 | 2009-04-06 18:31:47 +0200 | [diff] [blame] | 796 | job->job_done(job); |
| 797 | |
Swen Schillig | 6f53a2d | 2009-08-18 15:43:23 +0200 | [diff] [blame] | 798 | zfcp_fc_wka_port_put(ct_fc_job->ct.wka_port); |
Sven Schuetz | 9d544f2 | 2009-04-06 18:31:47 +0200 | [diff] [blame] | 799 | |
| 800 | kfree(ct_fc_job); |
| 801 | } |
| 802 | |
| 803 | int zfcp_fc_execute_ct_fc_job(struct fc_bsg_job *job) |
| 804 | { |
| 805 | int ret; |
| 806 | u8 gs_type; |
| 807 | struct fc_rport *rport = job->rport; |
| 808 | struct Scsi_Host *shost; |
| 809 | struct zfcp_adapter *adapter; |
| 810 | struct zfcp_ct_fc_job *ct_fc_job; |
| 811 | u32 preamble_word1; |
| 812 | |
| 813 | shost = rport ? rport_to_shost(rport) : job->shost; |
| 814 | |
| 815 | adapter = (struct zfcp_adapter *)shost->hostdata[0]; |
| 816 | if (!(atomic_read(&adapter->status) & ZFCP_STATUS_COMMON_OPEN)) |
| 817 | return -EINVAL; |
| 818 | |
| 819 | ct_fc_job = kzalloc(sizeof(struct zfcp_ct_fc_job), GFP_KERNEL); |
| 820 | if (!ct_fc_job) |
| 821 | return -ENOMEM; |
| 822 | |
| 823 | preamble_word1 = job->request->rqst_data.r_ct.preamble_word1; |
| 824 | gs_type = (preamble_word1 & 0xff000000) >> 24; |
| 825 | |
| 826 | switch (gs_type) { |
| 827 | case FC_FST_ALIAS: |
| 828 | ct_fc_job->ct.wka_port = &adapter->gs->as; |
| 829 | break; |
| 830 | case FC_FST_MGMT: |
| 831 | ct_fc_job->ct.wka_port = &adapter->gs->ms; |
| 832 | break; |
| 833 | case FC_FST_TIME: |
| 834 | ct_fc_job->ct.wka_port = &adapter->gs->ts; |
| 835 | break; |
| 836 | case FC_FST_DIR: |
| 837 | ct_fc_job->ct.wka_port = &adapter->gs->ds; |
| 838 | break; |
| 839 | default: |
| 840 | kfree(ct_fc_job); |
| 841 | return -EINVAL; /* no such service */ |
| 842 | } |
| 843 | |
Swen Schillig | 6f53a2d | 2009-08-18 15:43:23 +0200 | [diff] [blame] | 844 | ret = zfcp_fc_wka_port_get(ct_fc_job->ct.wka_port); |
Sven Schuetz | 9d544f2 | 2009-04-06 18:31:47 +0200 | [diff] [blame] | 845 | if (ret) { |
| 846 | kfree(ct_fc_job); |
| 847 | return ret; |
| 848 | } |
| 849 | |
| 850 | ct_fc_job->ct.req = job->request_payload.sg_list; |
| 851 | ct_fc_job->ct.resp = job->reply_payload.sg_list; |
Sven Schuetz | 9d544f2 | 2009-04-06 18:31:47 +0200 | [diff] [blame] | 852 | ct_fc_job->ct.handler = zfcp_fc_generic_ct_handler; |
| 853 | ct_fc_job->ct.handler_data = (unsigned long) ct_fc_job; |
| 854 | ct_fc_job->ct.completion = NULL; |
| 855 | ct_fc_job->job = job; |
| 856 | |
Christof Schmitt | 799b76d | 2009-08-18 15:43:20 +0200 | [diff] [blame] | 857 | ret = zfcp_fsf_send_ct(&ct_fc_job->ct, NULL); |
Sven Schuetz | 9d544f2 | 2009-04-06 18:31:47 +0200 | [diff] [blame] | 858 | if (ret) { |
| 859 | kfree(ct_fc_job); |
Swen Schillig | 6f53a2d | 2009-08-18 15:43:23 +0200 | [diff] [blame] | 860 | zfcp_fc_wka_port_put(ct_fc_job->ct.wka_port); |
Sven Schuetz | 9d544f2 | 2009-04-06 18:31:47 +0200 | [diff] [blame] | 861 | } |
| 862 | return ret; |
| 863 | } |
Swen Schillig | d5a282a | 2009-08-18 15:43:22 +0200 | [diff] [blame] | 864 | |
| 865 | int zfcp_fc_gs_setup(struct zfcp_adapter *adapter) |
| 866 | { |
| 867 | struct zfcp_wka_ports *wka_ports; |
| 868 | |
| 869 | wka_ports = kzalloc(sizeof(struct zfcp_wka_ports), GFP_KERNEL); |
| 870 | if (!wka_ports) |
| 871 | return -ENOMEM; |
| 872 | |
| 873 | adapter->gs = wka_ports; |
| 874 | zfcp_fc_wka_port_init(&wka_ports->ms, FC_FID_MGMT_SERV, adapter); |
| 875 | zfcp_fc_wka_port_init(&wka_ports->ts, FC_FID_TIME_SERV, adapter); |
| 876 | zfcp_fc_wka_port_init(&wka_ports->ds, FC_FID_DIR_SERV, adapter); |
| 877 | zfcp_fc_wka_port_init(&wka_ports->as, FC_FID_ALIASES, adapter); |
| 878 | zfcp_fc_wka_port_init(&wka_ports->ks, FC_FID_SEC_KEY, adapter); |
| 879 | |
| 880 | return 0; |
| 881 | } |
| 882 | |
| 883 | void zfcp_fc_gs_destroy(struct zfcp_adapter *adapter) |
| 884 | { |
| 885 | kfree(adapter->gs); |
| 886 | adapter->gs = NULL; |
| 887 | } |
| 888 | |