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 | * |
| 6 | * Copyright IBM Corporation 2008 |
| 7 | */ |
| 8 | |
| 9 | #include "zfcp_ext.h" |
| 10 | |
Swen Schillig | cc8c282 | 2008-06-10 18:21:00 +0200 | [diff] [blame] | 11 | struct ct_iu_gpn_ft_req { |
| 12 | struct ct_hdr header; |
| 13 | u8 flags; |
| 14 | u8 domain_id_scope; |
| 15 | u8 area_id_scope; |
| 16 | u8 fc4_type; |
| 17 | } __attribute__ ((packed)); |
| 18 | |
| 19 | struct gpn_ft_resp_acc { |
| 20 | u8 control; |
| 21 | u8 port_id[3]; |
| 22 | u8 reserved[4]; |
| 23 | u64 wwpn; |
| 24 | } __attribute__ ((packed)); |
| 25 | |
| 26 | #define ZFCP_GPN_FT_ENTRIES ((PAGE_SIZE - sizeof(struct ct_hdr)) \ |
| 27 | / sizeof(struct gpn_ft_resp_acc)) |
| 28 | #define ZFCP_GPN_FT_BUFFERS 4 |
| 29 | #define ZFCP_GPN_FT_MAX_ENTRIES ZFCP_GPN_FT_BUFFERS * (ZFCP_GPN_FT_ENTRIES + 1) |
| 30 | |
| 31 | struct ct_iu_gpn_ft_resp { |
| 32 | struct ct_hdr header; |
| 33 | struct gpn_ft_resp_acc accept[ZFCP_GPN_FT_ENTRIES]; |
| 34 | } __attribute__ ((packed)); |
| 35 | |
| 36 | struct zfcp_gpn_ft { |
| 37 | struct zfcp_send_ct ct; |
| 38 | struct scatterlist sg_req; |
| 39 | struct scatterlist sg_resp[ZFCP_GPN_FT_BUFFERS]; |
| 40 | }; |
| 41 | |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 42 | struct zfcp_fc_ns_handler_data { |
| 43 | struct completion done; |
| 44 | void (*handler)(unsigned long); |
| 45 | unsigned long handler_data; |
| 46 | }; |
| 47 | |
| 48 | static int zfcp_wka_port_get(struct zfcp_wka_port *wka_port) |
| 49 | { |
| 50 | if (mutex_lock_interruptible(&wka_port->mutex)) |
| 51 | return -ERESTARTSYS; |
| 52 | |
| 53 | if (wka_port->status != ZFCP_WKA_PORT_ONLINE) { |
| 54 | wka_port->status = ZFCP_WKA_PORT_OPENING; |
| 55 | if (zfcp_fsf_open_wka_port(wka_port)) |
| 56 | wka_port->status = ZFCP_WKA_PORT_OFFLINE; |
| 57 | } |
| 58 | |
| 59 | mutex_unlock(&wka_port->mutex); |
| 60 | |
| 61 | wait_event_timeout( |
| 62 | wka_port->completion_wq, |
| 63 | wka_port->status == ZFCP_WKA_PORT_ONLINE || |
| 64 | wka_port->status == ZFCP_WKA_PORT_OFFLINE, |
| 65 | HZ >> 1); |
| 66 | |
| 67 | if (wka_port->status == ZFCP_WKA_PORT_ONLINE) { |
| 68 | atomic_inc(&wka_port->refcount); |
| 69 | return 0; |
| 70 | } |
| 71 | return -EIO; |
| 72 | } |
| 73 | |
| 74 | static void zfcp_wka_port_offline(struct work_struct *work) |
| 75 | { |
| 76 | struct delayed_work *dw = container_of(work, struct delayed_work, work); |
| 77 | struct zfcp_wka_port *wka_port = |
| 78 | container_of(dw, struct zfcp_wka_port, work); |
| 79 | |
| 80 | wait_event(wka_port->completion_wq, |
| 81 | atomic_read(&wka_port->refcount) == 0); |
| 82 | |
| 83 | mutex_lock(&wka_port->mutex); |
| 84 | if ((atomic_read(&wka_port->refcount) != 0) || |
| 85 | (wka_port->status != ZFCP_WKA_PORT_ONLINE)) |
| 86 | goto out; |
| 87 | |
| 88 | wka_port->status = ZFCP_WKA_PORT_CLOSING; |
| 89 | if (zfcp_fsf_close_wka_port(wka_port)) { |
| 90 | wka_port->status = ZFCP_WKA_PORT_OFFLINE; |
| 91 | wake_up(&wka_port->completion_wq); |
| 92 | } |
| 93 | out: |
| 94 | mutex_unlock(&wka_port->mutex); |
| 95 | } |
| 96 | |
| 97 | static void zfcp_wka_port_put(struct zfcp_wka_port *wka_port) |
| 98 | { |
| 99 | if (atomic_dec_return(&wka_port->refcount) != 0) |
| 100 | return; |
| 101 | /* wait 10 miliseconds, other reqs might pop in */ |
| 102 | schedule_delayed_work(&wka_port->work, HZ / 100); |
| 103 | } |
| 104 | |
| 105 | void zfcp_fc_nameserver_init(struct zfcp_adapter *adapter) |
| 106 | { |
| 107 | struct zfcp_wka_port *wka_port = &adapter->nsp; |
| 108 | |
| 109 | init_waitqueue_head(&wka_port->completion_wq); |
| 110 | |
| 111 | wka_port->adapter = adapter; |
| 112 | wka_port->d_id = ZFCP_DID_DIRECTORY_SERVICE; |
| 113 | |
| 114 | wka_port->status = ZFCP_WKA_PORT_OFFLINE; |
| 115 | atomic_set(&wka_port->refcount, 0); |
| 116 | mutex_init(&wka_port->mutex); |
| 117 | INIT_DELAYED_WORK(&wka_port->work, zfcp_wka_port_offline); |
| 118 | } |
| 119 | |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 120 | static void _zfcp_fc_incoming_rscn(struct zfcp_fsf_req *fsf_req, u32 range, |
| 121 | struct fcp_rscn_element *elem) |
| 122 | { |
| 123 | unsigned long flags; |
| 124 | struct zfcp_port *port; |
| 125 | |
| 126 | read_lock_irqsave(&zfcp_data.config_lock, flags); |
| 127 | list_for_each_entry(port, &fsf_req->adapter->port_list_head, list) { |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 128 | /* FIXME: ZFCP_STATUS_PORT_DID_DID check is racy */ |
Swen Schillig | 44cc76f | 2008-10-01 12:42:16 +0200 | [diff] [blame] | 129 | if (!(atomic_read(&port->status) & ZFCP_STATUS_PORT_DID_DID)) |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 130 | /* Try to connect to unused ports anyway. */ |
| 131 | zfcp_erp_port_reopen(port, |
| 132 | ZFCP_STATUS_COMMON_ERP_FAILED, |
| 133 | 82, fsf_req); |
| 134 | else if ((port->d_id & range) == (elem->nport_did & range)) |
| 135 | /* Check connection status for connected ports */ |
| 136 | zfcp_test_link(port); |
| 137 | } |
| 138 | read_unlock_irqrestore(&zfcp_data.config_lock, flags); |
| 139 | } |
| 140 | |
| 141 | static void zfcp_fc_incoming_rscn(struct zfcp_fsf_req *fsf_req) |
| 142 | { |
| 143 | struct fsf_status_read_buffer *status_buffer = (void *)fsf_req->data; |
| 144 | struct fcp_rscn_head *fcp_rscn_head; |
| 145 | struct fcp_rscn_element *fcp_rscn_element; |
| 146 | u16 i; |
| 147 | u16 no_entries; |
| 148 | u32 range_mask; |
| 149 | |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 150 | fcp_rscn_head = (struct fcp_rscn_head *) status_buffer->payload.data; |
| 151 | fcp_rscn_element = (struct fcp_rscn_element *) fcp_rscn_head; |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 152 | |
| 153 | /* see FC-FS */ |
| 154 | no_entries = fcp_rscn_head->payload_len / |
| 155 | sizeof(struct fcp_rscn_element); |
| 156 | |
| 157 | for (i = 1; i < no_entries; i++) { |
| 158 | /* skip head and start with 1st element */ |
| 159 | fcp_rscn_element++; |
| 160 | switch (fcp_rscn_element->addr_format) { |
| 161 | case ZFCP_PORT_ADDRESS: |
| 162 | range_mask = ZFCP_PORTS_RANGE_PORT; |
| 163 | break; |
| 164 | case ZFCP_AREA_ADDRESS: |
| 165 | range_mask = ZFCP_PORTS_RANGE_AREA; |
| 166 | break; |
| 167 | case ZFCP_DOMAIN_ADDRESS: |
| 168 | range_mask = ZFCP_PORTS_RANGE_DOMAIN; |
| 169 | break; |
| 170 | case ZFCP_FABRIC_ADDRESS: |
| 171 | range_mask = ZFCP_PORTS_RANGE_FABRIC; |
| 172 | break; |
| 173 | default: |
| 174 | continue; |
| 175 | } |
| 176 | _zfcp_fc_incoming_rscn(fsf_req, range_mask, fcp_rscn_element); |
| 177 | } |
Swen Schillig | cc8c282 | 2008-06-10 18:21:00 +0200 | [diff] [blame] | 178 | schedule_work(&fsf_req->adapter->scan_work); |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 179 | } |
| 180 | |
Swen Schillig | 7ba58c9 | 2008-10-01 12:42:18 +0200 | [diff] [blame^] | 181 | 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] | 182 | { |
| 183 | struct zfcp_adapter *adapter = req->adapter; |
| 184 | struct zfcp_port *port; |
| 185 | unsigned long flags; |
| 186 | |
| 187 | read_lock_irqsave(&zfcp_data.config_lock, flags); |
| 188 | list_for_each_entry(port, &adapter->port_list_head, list) |
| 189 | if (port->wwpn == wwpn) |
| 190 | break; |
| 191 | read_unlock_irqrestore(&zfcp_data.config_lock, flags); |
| 192 | |
| 193 | if (port && (port->wwpn == wwpn)) |
| 194 | zfcp_erp_port_forced_reopen(port, 0, 83, req); |
| 195 | } |
| 196 | |
| 197 | static void zfcp_fc_incoming_plogi(struct zfcp_fsf_req *req) |
| 198 | { |
| 199 | struct fsf_status_read_buffer *status_buffer = |
| 200 | (struct fsf_status_read_buffer *)req->data; |
| 201 | struct fsf_plogi *els_plogi = |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 202 | (struct fsf_plogi *) status_buffer->payload.data; |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 203 | |
| 204 | zfcp_fc_incoming_wwpn(req, els_plogi->serv_param.wwpn); |
| 205 | } |
| 206 | |
| 207 | static void zfcp_fc_incoming_logo(struct zfcp_fsf_req *req) |
| 208 | { |
| 209 | struct fsf_status_read_buffer *status_buffer = |
| 210 | (struct fsf_status_read_buffer *)req->data; |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 211 | struct fcp_logo *els_logo = |
| 212 | (struct fcp_logo *) status_buffer->payload.data; |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 213 | |
| 214 | zfcp_fc_incoming_wwpn(req, els_logo->nport_wwpn); |
| 215 | } |
| 216 | |
| 217 | /** |
| 218 | * zfcp_fc_incoming_els - handle incoming ELS |
| 219 | * @fsf_req - request which contains incoming ELS |
| 220 | */ |
| 221 | void zfcp_fc_incoming_els(struct zfcp_fsf_req *fsf_req) |
| 222 | { |
| 223 | struct fsf_status_read_buffer *status_buffer = |
| 224 | (struct fsf_status_read_buffer *) fsf_req->data; |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 225 | unsigned int els_type = status_buffer->payload.data[0]; |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 226 | |
| 227 | zfcp_san_dbf_event_incoming_els(fsf_req); |
| 228 | if (els_type == LS_PLOGI) |
| 229 | zfcp_fc_incoming_plogi(fsf_req); |
| 230 | else if (els_type == LS_LOGO) |
| 231 | zfcp_fc_incoming_logo(fsf_req); |
| 232 | else if (els_type == LS_RSCN) |
| 233 | zfcp_fc_incoming_rscn(fsf_req); |
| 234 | } |
| 235 | |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 236 | static void zfcp_fc_ns_handler(unsigned long data) |
| 237 | { |
| 238 | struct zfcp_fc_ns_handler_data *compl_rec = |
| 239 | (struct zfcp_fc_ns_handler_data *) data; |
| 240 | |
| 241 | if (compl_rec->handler) |
| 242 | compl_rec->handler(compl_rec->handler_data); |
| 243 | |
| 244 | complete(&compl_rec->done); |
| 245 | } |
| 246 | |
| 247 | static void zfcp_fc_ns_gid_pn_eval(unsigned long data) |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 248 | { |
| 249 | struct zfcp_gid_pn_data *gid_pn = (struct zfcp_gid_pn_data *) data; |
| 250 | struct zfcp_send_ct *ct = &gid_pn->ct; |
| 251 | struct ct_iu_gid_pn_req *ct_iu_req = sg_virt(ct->req); |
| 252 | struct ct_iu_gid_pn_resp *ct_iu_resp = sg_virt(ct->resp); |
| 253 | struct zfcp_port *port = gid_pn->port; |
| 254 | |
| 255 | if (ct->status) |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 256 | return; |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 257 | if (ct_iu_resp->header.cmd_rsp_code != ZFCP_CT_ACCEPT) { |
| 258 | atomic_set_mask(ZFCP_STATUS_PORT_INVALID_WWPN, &port->status); |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 259 | return; |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 260 | } |
| 261 | /* paranoia */ |
| 262 | if (ct_iu_req->wwpn != port->wwpn) |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 263 | return; |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 264 | /* looks like a valid d_id */ |
| 265 | port->d_id = ct_iu_resp->d_id & ZFCP_DID_MASK; |
| 266 | atomic_set_mask(ZFCP_STATUS_PORT_DID_DID, &port->status); |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 267 | } |
| 268 | |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 269 | int static zfcp_fc_ns_gid_pn_request(struct zfcp_erp_action *erp_action, |
| 270 | struct zfcp_gid_pn_data *gid_pn) |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 271 | { |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 272 | struct zfcp_adapter *adapter = erp_action->adapter; |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 273 | struct zfcp_fc_ns_handler_data compl_rec; |
| 274 | int ret; |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 275 | |
| 276 | /* setup parameters for send generic command */ |
| 277 | gid_pn->port = erp_action->port; |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 278 | gid_pn->ct.wka_port = &adapter->nsp; |
| 279 | gid_pn->ct.handler = zfcp_fc_ns_handler; |
| 280 | gid_pn->ct.handler_data = (unsigned long) &compl_rec; |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 281 | gid_pn->ct.timeout = ZFCP_NS_GID_PN_TIMEOUT; |
| 282 | gid_pn->ct.req = &gid_pn->req; |
| 283 | gid_pn->ct.resp = &gid_pn->resp; |
| 284 | gid_pn->ct.req_count = 1; |
| 285 | gid_pn->ct.resp_count = 1; |
| 286 | sg_init_one(&gid_pn->req, &gid_pn->ct_iu_req, |
| 287 | sizeof(struct ct_iu_gid_pn_req)); |
| 288 | sg_init_one(&gid_pn->resp, &gid_pn->ct_iu_resp, |
| 289 | sizeof(struct ct_iu_gid_pn_resp)); |
| 290 | |
| 291 | /* setup nameserver request */ |
| 292 | gid_pn->ct_iu_req.header.revision = ZFCP_CT_REVISION; |
| 293 | gid_pn->ct_iu_req.header.gs_type = ZFCP_CT_DIRECTORY_SERVICE; |
| 294 | gid_pn->ct_iu_req.header.gs_subtype = ZFCP_CT_NAME_SERVER; |
| 295 | gid_pn->ct_iu_req.header.options = ZFCP_CT_SYNCHRONOUS; |
| 296 | gid_pn->ct_iu_req.header.cmd_rsp_code = ZFCP_CT_GID_PN; |
| 297 | gid_pn->ct_iu_req.header.max_res_size = ZFCP_CT_MAX_SIZE; |
| 298 | gid_pn->ct_iu_req.wwpn = erp_action->port->wwpn; |
| 299 | |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 300 | init_completion(&compl_rec.done); |
| 301 | compl_rec.handler = zfcp_fc_ns_gid_pn_eval; |
| 302 | compl_rec.handler_data = (unsigned long) gid_pn; |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 303 | ret = zfcp_fsf_send_ct(&gid_pn->ct, adapter->pool.fsf_req_erp, |
| 304 | erp_action); |
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 |
| 312 | * @erp_action: pointer to zfcp_erp_action where GID_PN request is needed |
| 313 | * return: -ENOMEM on error, 0 otherwise |
| 314 | */ |
| 315 | int zfcp_fc_ns_gid_pn(struct zfcp_erp_action *erp_action) |
| 316 | { |
| 317 | int ret; |
| 318 | struct zfcp_gid_pn_data *gid_pn; |
| 319 | struct zfcp_adapter *adapter = erp_action->adapter; |
| 320 | |
| 321 | gid_pn = mempool_alloc(adapter->pool.data_gid_pn, GFP_ATOMIC); |
| 322 | if (!gid_pn) |
| 323 | return -ENOMEM; |
| 324 | |
| 325 | memset(gid_pn, 0, sizeof(*gid_pn)); |
| 326 | |
| 327 | ret = zfcp_wka_port_get(&adapter->nsp); |
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 | |
| 331 | ret = zfcp_fc_ns_gid_pn_request(erp_action, gid_pn); |
| 332 | |
| 333 | zfcp_wka_port_put(&adapter->nsp); |
| 334 | out: |
| 335 | mempool_free(gid_pn, adapter->pool.data_gid_pn); |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 336 | return ret; |
| 337 | } |
| 338 | |
| 339 | /** |
| 340 | * zfcp_fc_plogi_evaluate - evaluate PLOGI playload |
| 341 | * @port: zfcp_port structure |
| 342 | * @plogi: plogi payload |
| 343 | * |
| 344 | * Evaluate PLOGI playload and copy important fields into zfcp_port structure |
| 345 | */ |
| 346 | void zfcp_fc_plogi_evaluate(struct zfcp_port *port, struct fsf_plogi *plogi) |
| 347 | { |
| 348 | port->maxframe_size = plogi->serv_param.common_serv_param[7] | |
| 349 | ((plogi->serv_param.common_serv_param[6] & 0x0F) << 8); |
| 350 | if (plogi->serv_param.class1_serv_param[0] & 0x80) |
| 351 | port->supported_classes |= FC_COS_CLASS1; |
| 352 | if (plogi->serv_param.class2_serv_param[0] & 0x80) |
| 353 | port->supported_classes |= FC_COS_CLASS2; |
| 354 | if (plogi->serv_param.class3_serv_param[0] & 0x80) |
| 355 | port->supported_classes |= FC_COS_CLASS3; |
| 356 | if (plogi->serv_param.class4_serv_param[0] & 0x80) |
| 357 | port->supported_classes |= FC_COS_CLASS4; |
| 358 | } |
| 359 | |
| 360 | struct zfcp_els_adisc { |
| 361 | struct zfcp_send_els els; |
| 362 | struct scatterlist req; |
| 363 | struct scatterlist resp; |
| 364 | struct zfcp_ls_adisc ls_adisc; |
Swen Schillig | 44cc76f | 2008-10-01 12:42:16 +0200 | [diff] [blame] | 365 | struct zfcp_ls_adisc ls_adisc_acc; |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 366 | }; |
| 367 | |
| 368 | static void zfcp_fc_adisc_handler(unsigned long data) |
| 369 | { |
| 370 | struct zfcp_els_adisc *adisc = (struct zfcp_els_adisc *) data; |
| 371 | struct zfcp_port *port = adisc->els.port; |
Swen Schillig | 44cc76f | 2008-10-01 12:42:16 +0200 | [diff] [blame] | 372 | struct zfcp_ls_adisc *ls_adisc = &adisc->ls_adisc_acc; |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 373 | |
Christof Schmitt | 3968ce8 | 2008-07-02 10:56:32 +0200 | [diff] [blame] | 374 | if (adisc->els.status) { |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 375 | /* request rejected or timed out */ |
| 376 | zfcp_erp_port_forced_reopen(port, 0, 63, NULL); |
| 377 | goto out; |
| 378 | } |
| 379 | |
| 380 | if (!port->wwnn) |
| 381 | port->wwnn = ls_adisc->wwnn; |
| 382 | |
| 383 | if (port->wwpn != ls_adisc->wwpn) |
| 384 | zfcp_erp_port_reopen(port, 0, 64, NULL); |
| 385 | |
| 386 | out: |
| 387 | zfcp_port_put(port); |
| 388 | kfree(adisc); |
| 389 | } |
| 390 | |
| 391 | static int zfcp_fc_adisc(struct zfcp_port *port) |
| 392 | { |
| 393 | struct zfcp_els_adisc *adisc; |
| 394 | struct zfcp_adapter *adapter = port->adapter; |
| 395 | |
| 396 | adisc = kzalloc(sizeof(struct zfcp_els_adisc), GFP_ATOMIC); |
| 397 | if (!adisc) |
| 398 | return -ENOMEM; |
| 399 | |
| 400 | adisc->els.req = &adisc->req; |
| 401 | adisc->els.resp = &adisc->resp; |
| 402 | sg_init_one(adisc->els.req, &adisc->ls_adisc, |
| 403 | sizeof(struct zfcp_ls_adisc)); |
| 404 | sg_init_one(adisc->els.resp, &adisc->ls_adisc_acc, |
Swen Schillig | 44cc76f | 2008-10-01 12:42:16 +0200 | [diff] [blame] | 405 | sizeof(struct zfcp_ls_adisc)); |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 406 | |
| 407 | adisc->els.req_count = 1; |
| 408 | adisc->els.resp_count = 1; |
| 409 | adisc->els.adapter = adapter; |
| 410 | adisc->els.port = port; |
| 411 | adisc->els.d_id = port->d_id; |
| 412 | adisc->els.handler = zfcp_fc_adisc_handler; |
| 413 | adisc->els.handler_data = (unsigned long) adisc; |
| 414 | adisc->els.ls_code = adisc->ls_adisc.code = ZFCP_LS_ADISC; |
| 415 | |
| 416 | /* acc. to FC-FS, hard_nport_id in ADISC should not be set for ports |
| 417 | without FC-AL-2 capability, so we don't set it */ |
| 418 | adisc->ls_adisc.wwpn = fc_host_port_name(adapter->scsi_host); |
| 419 | adisc->ls_adisc.wwnn = fc_host_node_name(adapter->scsi_host); |
| 420 | adisc->ls_adisc.nport_id = fc_host_port_id(adapter->scsi_host); |
| 421 | |
| 422 | return zfcp_fsf_send_els(&adisc->els); |
| 423 | } |
| 424 | |
| 425 | /** |
| 426 | * zfcp_test_link - lightweight link test procedure |
| 427 | * @port: port to be tested |
| 428 | * |
| 429 | * Test status of a link to a remote port using the ELS command ADISC. |
| 430 | * If there is a problem with the remote port, error recovery steps |
| 431 | * will be triggered. |
| 432 | */ |
| 433 | void zfcp_test_link(struct zfcp_port *port) |
| 434 | { |
| 435 | int retval; |
| 436 | |
| 437 | zfcp_port_get(port); |
| 438 | retval = zfcp_fc_adisc(port); |
Swen Schillig | 9528539 | 2008-08-21 13:43:35 +0200 | [diff] [blame] | 439 | if (retval == 0) |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 440 | return; |
| 441 | |
| 442 | /* send of ADISC was not possible */ |
| 443 | zfcp_port_put(port); |
Swen Schillig | 9528539 | 2008-08-21 13:43:35 +0200 | [diff] [blame] | 444 | if (retval != -EBUSY) |
| 445 | zfcp_erp_port_forced_reopen(port, 0, 65, NULL); |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 446 | } |
Swen Schillig | cc8c282 | 2008-06-10 18:21:00 +0200 | [diff] [blame] | 447 | |
Swen Schillig | cc8c282 | 2008-06-10 18:21:00 +0200 | [diff] [blame] | 448 | static void zfcp_free_sg_env(struct zfcp_gpn_ft *gpn_ft) |
| 449 | { |
| 450 | struct scatterlist *sg = &gpn_ft->sg_req; |
| 451 | |
| 452 | kfree(sg_virt(sg)); /* free request buffer */ |
| 453 | zfcp_sg_free_table(gpn_ft->sg_resp, ZFCP_GPN_FT_BUFFERS); |
| 454 | |
| 455 | kfree(gpn_ft); |
| 456 | } |
| 457 | |
| 458 | static struct zfcp_gpn_ft *zfcp_alloc_sg_env(void) |
| 459 | { |
| 460 | struct zfcp_gpn_ft *gpn_ft; |
| 461 | struct ct_iu_gpn_ft_req *req; |
| 462 | |
| 463 | gpn_ft = kzalloc(sizeof(*gpn_ft), GFP_KERNEL); |
| 464 | if (!gpn_ft) |
| 465 | return NULL; |
| 466 | |
| 467 | req = kzalloc(sizeof(struct ct_iu_gpn_ft_req), GFP_KERNEL); |
| 468 | if (!req) { |
| 469 | kfree(gpn_ft); |
| 470 | gpn_ft = NULL; |
| 471 | goto out; |
| 472 | } |
| 473 | sg_init_one(&gpn_ft->sg_req, req, sizeof(*req)); |
| 474 | |
| 475 | if (zfcp_sg_setup_table(gpn_ft->sg_resp, ZFCP_GPN_FT_BUFFERS)) { |
| 476 | zfcp_free_sg_env(gpn_ft); |
| 477 | gpn_ft = NULL; |
| 478 | } |
| 479 | out: |
| 480 | return gpn_ft; |
| 481 | } |
| 482 | |
| 483 | |
| 484 | static int zfcp_scan_issue_gpn_ft(struct zfcp_gpn_ft *gpn_ft, |
| 485 | struct zfcp_adapter *adapter) |
| 486 | { |
| 487 | struct zfcp_send_ct *ct = &gpn_ft->ct; |
| 488 | 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] | 489 | struct zfcp_fc_ns_handler_data compl_rec; |
Swen Schillig | cc8c282 | 2008-06-10 18:21:00 +0200 | [diff] [blame] | 490 | int ret; |
| 491 | |
| 492 | /* prepare CT IU for GPN_FT */ |
| 493 | req->header.revision = ZFCP_CT_REVISION; |
| 494 | req->header.gs_type = ZFCP_CT_DIRECTORY_SERVICE; |
| 495 | req->header.gs_subtype = ZFCP_CT_NAME_SERVER; |
| 496 | req->header.options = ZFCP_CT_SYNCHRONOUS; |
| 497 | req->header.cmd_rsp_code = ZFCP_CT_GPN_FT; |
| 498 | req->header.max_res_size = (sizeof(struct gpn_ft_resp_acc) * |
| 499 | (ZFCP_GPN_FT_MAX_ENTRIES - 1)) >> 2; |
| 500 | req->flags = 0; |
| 501 | req->domain_id_scope = 0; |
| 502 | req->area_id_scope = 0; |
| 503 | req->fc4_type = ZFCP_CT_SCSI_FCP; |
| 504 | |
| 505 | /* prepare zfcp_send_ct */ |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 506 | ct->wka_port = &adapter->nsp; |
| 507 | ct->handler = zfcp_fc_ns_handler; |
| 508 | ct->handler_data = (unsigned long)&compl_rec; |
Swen Schillig | cc8c282 | 2008-06-10 18:21:00 +0200 | [diff] [blame] | 509 | ct->timeout = 10; |
| 510 | ct->req = &gpn_ft->sg_req; |
| 511 | ct->resp = gpn_ft->sg_resp; |
| 512 | ct->req_count = 1; |
| 513 | ct->resp_count = ZFCP_GPN_FT_BUFFERS; |
| 514 | |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 515 | init_completion(&compl_rec.done); |
| 516 | compl_rec.handler = NULL; |
Swen Schillig | cc8c282 | 2008-06-10 18:21:00 +0200 | [diff] [blame] | 517 | ret = zfcp_fsf_send_ct(ct, NULL, NULL); |
| 518 | if (!ret) |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 519 | wait_for_completion(&compl_rec.done); |
Swen Schillig | cc8c282 | 2008-06-10 18:21:00 +0200 | [diff] [blame] | 520 | return ret; |
| 521 | } |
| 522 | |
| 523 | static void zfcp_validate_port(struct zfcp_port *port) |
| 524 | { |
| 525 | struct zfcp_adapter *adapter = port->adapter; |
| 526 | |
| 527 | atomic_clear_mask(ZFCP_STATUS_COMMON_NOESC, &port->status); |
| 528 | |
Swen Schillig | cc8c282 | 2008-06-10 18:21:00 +0200 | [diff] [blame] | 529 | if ((port->supported_classes != 0) || (port->units != 0)) { |
| 530 | zfcp_port_put(port); |
| 531 | return; |
| 532 | } |
| 533 | zfcp_erp_port_shutdown(port, 0, 151, NULL); |
| 534 | zfcp_erp_wait(adapter); |
| 535 | zfcp_port_put(port); |
| 536 | zfcp_port_dequeue(port); |
| 537 | } |
| 538 | |
| 539 | static int zfcp_scan_eval_gpn_ft(struct zfcp_gpn_ft *gpn_ft) |
| 540 | { |
| 541 | struct zfcp_send_ct *ct = &gpn_ft->ct; |
| 542 | struct scatterlist *sg = gpn_ft->sg_resp; |
| 543 | struct ct_hdr *hdr = sg_virt(sg); |
| 544 | struct gpn_ft_resp_acc *acc = sg_virt(sg); |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 545 | struct zfcp_adapter *adapter = ct->wka_port->adapter; |
Swen Schillig | cc8c282 | 2008-06-10 18:21:00 +0200 | [diff] [blame] | 546 | struct zfcp_port *port, *tmp; |
| 547 | u32 d_id; |
Christof Schmitt | 47f7bba | 2008-08-21 13:43:33 +0200 | [diff] [blame] | 548 | int ret = 0, x, last = 0; |
Swen Schillig | cc8c282 | 2008-06-10 18:21:00 +0200 | [diff] [blame] | 549 | |
| 550 | if (ct->status) |
| 551 | return -EIO; |
| 552 | |
| 553 | if (hdr->cmd_rsp_code != ZFCP_CT_ACCEPT) { |
| 554 | if (hdr->reason_code == ZFCP_CT_UNABLE_TO_PERFORM_CMD) |
| 555 | return -EAGAIN; /* might be a temporary condition */ |
| 556 | return -EIO; |
| 557 | } |
| 558 | |
| 559 | if (hdr->max_res_size) |
| 560 | return -E2BIG; |
| 561 | |
| 562 | down(&zfcp_data.config_sema); |
| 563 | |
| 564 | /* first entry is the header */ |
Christof Schmitt | 47f7bba | 2008-08-21 13:43:33 +0200 | [diff] [blame] | 565 | for (x = 1; x < ZFCP_GPN_FT_MAX_ENTRIES && !last; x++) { |
Swen Schillig | cc8c282 | 2008-06-10 18:21:00 +0200 | [diff] [blame] | 566 | if (x % (ZFCP_GPN_FT_ENTRIES + 1)) |
| 567 | acc++; |
| 568 | else |
| 569 | acc = sg_virt(++sg); |
| 570 | |
Christof Schmitt | 47f7bba | 2008-08-21 13:43:33 +0200 | [diff] [blame] | 571 | last = acc->control & 0x80; |
Swen Schillig | cc8c282 | 2008-06-10 18:21:00 +0200 | [diff] [blame] | 572 | d_id = acc->port_id[0] << 16 | acc->port_id[1] << 8 | |
| 573 | acc->port_id[2]; |
| 574 | |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 575 | /* don't attach ports with a well known address */ |
| 576 | if ((d_id & ZFCP_DID_WKA) == ZFCP_DID_WKA) |
| 577 | continue; |
Swen Schillig | cc8c282 | 2008-06-10 18:21:00 +0200 | [diff] [blame] | 578 | /* skip the adapter's port and known remote ports */ |
Swen Schillig | 9528539 | 2008-08-21 13:43:35 +0200 | [diff] [blame] | 579 | if (acc->wwpn == fc_host_port_name(adapter->scsi_host)) |
Swen Schillig | cc8c282 | 2008-06-10 18:21:00 +0200 | [diff] [blame] | 580 | continue; |
Swen Schillig | 9528539 | 2008-08-21 13:43:35 +0200 | [diff] [blame] | 581 | port = zfcp_get_port_by_wwpn(adapter, acc->wwpn); |
| 582 | if (port) { |
| 583 | zfcp_port_get(port); |
| 584 | continue; |
| 585 | } |
Swen Schillig | cc8c282 | 2008-06-10 18:21:00 +0200 | [diff] [blame] | 586 | |
| 587 | port = zfcp_port_enqueue(adapter, acc->wwpn, |
| 588 | ZFCP_STATUS_PORT_DID_DID | |
| 589 | ZFCP_STATUS_COMMON_NOESC, d_id); |
Swen Schillig | 317e6b6 | 2008-07-02 10:56:37 +0200 | [diff] [blame] | 590 | if (IS_ERR(port)) |
| 591 | ret = PTR_ERR(port); |
Swen Schillig | cc8c282 | 2008-06-10 18:21:00 +0200 | [diff] [blame] | 592 | else |
Swen Schillig | 317e6b6 | 2008-07-02 10:56:37 +0200 | [diff] [blame] | 593 | zfcp_erp_port_reopen(port, 0, 149, NULL); |
Swen Schillig | cc8c282 | 2008-06-10 18:21:00 +0200 | [diff] [blame] | 594 | } |
| 595 | |
| 596 | zfcp_erp_wait(adapter); |
| 597 | list_for_each_entry_safe(port, tmp, &adapter->port_list_head, list) |
| 598 | zfcp_validate_port(port); |
| 599 | up(&zfcp_data.config_sema); |
| 600 | return ret; |
| 601 | } |
| 602 | |
| 603 | /** |
| 604 | * zfcp_scan_ports - scan remote ports and attach new ports |
| 605 | * @adapter: pointer to struct zfcp_adapter |
| 606 | */ |
| 607 | int zfcp_scan_ports(struct zfcp_adapter *adapter) |
| 608 | { |
| 609 | int ret, i; |
| 610 | struct zfcp_gpn_ft *gpn_ft; |
| 611 | |
Swen Schillig | c57a39a | 2008-07-02 10:56:31 +0200 | [diff] [blame] | 612 | zfcp_erp_wait(adapter); /* wait until adapter is finished with ERP */ |
Swen Schillig | cc8c282 | 2008-06-10 18:21:00 +0200 | [diff] [blame] | 613 | if (fc_host_port_type(adapter->scsi_host) != FC_PORTTYPE_NPORT) |
| 614 | return 0; |
| 615 | |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 616 | ret = zfcp_wka_port_get(&adapter->nsp); |
Swen Schillig | cc8c282 | 2008-06-10 18:21:00 +0200 | [diff] [blame] | 617 | if (ret) |
| 618 | return ret; |
| 619 | |
| 620 | gpn_ft = zfcp_alloc_sg_env(); |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 621 | if (!gpn_ft) { |
| 622 | ret = -ENOMEM; |
| 623 | goto out; |
| 624 | } |
Swen Schillig | cc8c282 | 2008-06-10 18:21:00 +0200 | [diff] [blame] | 625 | |
| 626 | for (i = 0; i < 3; i++) { |
| 627 | ret = zfcp_scan_issue_gpn_ft(gpn_ft, adapter); |
| 628 | if (!ret) { |
| 629 | ret = zfcp_scan_eval_gpn_ft(gpn_ft); |
| 630 | if (ret == -EAGAIN) |
| 631 | ssleep(1); |
| 632 | else |
| 633 | break; |
| 634 | } |
| 635 | } |
| 636 | zfcp_free_sg_env(gpn_ft); |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 637 | out: |
| 638 | zfcp_wka_port_put(&adapter->nsp); |
Swen Schillig | cc8c282 | 2008-06-10 18:21:00 +0200 | [diff] [blame] | 639 | return ret; |
| 640 | } |
| 641 | |
| 642 | |
| 643 | void _zfcp_scan_ports_later(struct work_struct *work) |
| 644 | { |
| 645 | zfcp_scan_ports(container_of(work, struct zfcp_adapter, scan_work)); |
| 646 | } |