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