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 | 9d05ce2 | 2009-11-24 16:54:09 +0100 | [diff] [blame] | 12 | #include <linux/types.h> |
| 13 | #include <scsi/fc/fc_els.h> |
| 14 | #include <scsi/libfc.h> |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 15 | #include "zfcp_ext.h" |
Christof Schmitt | 9d05ce2 | 2009-11-24 16:54:09 +0100 | [diff] [blame] | 16 | #include "zfcp_fc.h" |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 17 | |
Christof Schmitt | 9d05ce2 | 2009-11-24 16:54:09 +0100 | [diff] [blame] | 18 | static u32 zfcp_fc_rscn_range_mask[] = { |
| 19 | [ELS_ADDR_FMT_PORT] = 0xFFFFFF, |
| 20 | [ELS_ADDR_FMT_AREA] = 0xFFFF00, |
| 21 | [ELS_ADDR_FMT_DOM] = 0xFF0000, |
| 22 | [ELS_ADDR_FMT_FAB] = 0x000000, |
Christof Schmitt | e0d7fcb | 2008-12-19 16:56:58 +0100 | [diff] [blame] | 23 | }; |
| 24 | |
Christof Schmitt | bd0072e | 2009-11-24 16:54:11 +0100 | [diff] [blame] | 25 | static int zfcp_fc_wka_port_get(struct zfcp_fc_wka_port *wka_port) |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 26 | { |
| 27 | if (mutex_lock_interruptible(&wka_port->mutex)) |
| 28 | return -ERESTARTSYS; |
| 29 | |
Christof Schmitt | bd0072e | 2009-11-24 16:54:11 +0100 | [diff] [blame] | 30 | if (wka_port->status == ZFCP_FC_WKA_PORT_OFFLINE || |
| 31 | wka_port->status == ZFCP_FC_WKA_PORT_CLOSING) { |
| 32 | wka_port->status = ZFCP_FC_WKA_PORT_OPENING; |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 33 | if (zfcp_fsf_open_wka_port(wka_port)) |
Christof Schmitt | bd0072e | 2009-11-24 16:54:11 +0100 | [diff] [blame] | 34 | wka_port->status = ZFCP_FC_WKA_PORT_OFFLINE; |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 35 | } |
| 36 | |
| 37 | mutex_unlock(&wka_port->mutex); |
| 38 | |
Swen Schillig | 27f492c | 2009-07-13 15:06:13 +0200 | [diff] [blame] | 39 | wait_event(wka_port->completion_wq, |
Christof Schmitt | bd0072e | 2009-11-24 16:54:11 +0100 | [diff] [blame] | 40 | wka_port->status == ZFCP_FC_WKA_PORT_ONLINE || |
| 41 | wka_port->status == ZFCP_FC_WKA_PORT_OFFLINE); |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 42 | |
Christof Schmitt | bd0072e | 2009-11-24 16:54:11 +0100 | [diff] [blame] | 43 | if (wka_port->status == ZFCP_FC_WKA_PORT_ONLINE) { |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 44 | atomic_inc(&wka_port->refcount); |
| 45 | return 0; |
| 46 | } |
| 47 | return -EIO; |
| 48 | } |
| 49 | |
Swen Schillig | 6f53a2d | 2009-08-18 15:43:23 +0200 | [diff] [blame] | 50 | static void zfcp_fc_wka_port_offline(struct work_struct *work) |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 51 | { |
Jean Delvare | bf6aede | 2009-04-02 16:56:54 -0700 | [diff] [blame] | 52 | struct delayed_work *dw = to_delayed_work(work); |
Christof Schmitt | bd0072e | 2009-11-24 16:54:11 +0100 | [diff] [blame] | 53 | struct zfcp_fc_wka_port *wka_port = |
| 54 | container_of(dw, struct zfcp_fc_wka_port, work); |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 55 | |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 56 | mutex_lock(&wka_port->mutex); |
| 57 | if ((atomic_read(&wka_port->refcount) != 0) || |
Christof Schmitt | bd0072e | 2009-11-24 16:54:11 +0100 | [diff] [blame] | 58 | (wka_port->status != ZFCP_FC_WKA_PORT_ONLINE)) |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 59 | goto out; |
| 60 | |
Christof Schmitt | bd0072e | 2009-11-24 16:54:11 +0100 | [diff] [blame] | 61 | wka_port->status = ZFCP_FC_WKA_PORT_CLOSING; |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 62 | if (zfcp_fsf_close_wka_port(wka_port)) { |
Christof Schmitt | bd0072e | 2009-11-24 16:54:11 +0100 | [diff] [blame] | 63 | wka_port->status = ZFCP_FC_WKA_PORT_OFFLINE; |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 64 | wake_up(&wka_port->completion_wq); |
| 65 | } |
| 66 | out: |
| 67 | mutex_unlock(&wka_port->mutex); |
| 68 | } |
| 69 | |
Christof Schmitt | bd0072e | 2009-11-24 16:54:11 +0100 | [diff] [blame] | 70 | static void zfcp_fc_wka_port_put(struct zfcp_fc_wka_port *wka_port) |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 71 | { |
| 72 | if (atomic_dec_return(&wka_port->refcount) != 0) |
| 73 | return; |
Martin Olsson | 19af5cd | 2009-04-23 11:37:37 +0200 | [diff] [blame] | 74 | /* wait 10 milliseconds, other reqs might pop in */ |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 75 | schedule_delayed_work(&wka_port->work, HZ / 100); |
| 76 | } |
| 77 | |
Christof Schmitt | bd0072e | 2009-11-24 16:54:11 +0100 | [diff] [blame] | 78 | static void zfcp_fc_wka_port_init(struct zfcp_fc_wka_port *wka_port, u32 d_id, |
Sven Schuetz | 9d544f2 | 2009-04-06 18:31:47 +0200 | [diff] [blame] | 79 | struct zfcp_adapter *adapter) |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 80 | { |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 81 | init_waitqueue_head(&wka_port->completion_wq); |
| 82 | |
| 83 | wka_port->adapter = adapter; |
Sven Schuetz | 9d544f2 | 2009-04-06 18:31:47 +0200 | [diff] [blame] | 84 | wka_port->d_id = d_id; |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 85 | |
Christof Schmitt | bd0072e | 2009-11-24 16:54:11 +0100 | [diff] [blame] | 86 | wka_port->status = ZFCP_FC_WKA_PORT_OFFLINE; |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 87 | atomic_set(&wka_port->refcount, 0); |
| 88 | mutex_init(&wka_port->mutex); |
Swen Schillig | 6f53a2d | 2009-08-18 15:43:23 +0200 | [diff] [blame] | 89 | INIT_DELAYED_WORK(&wka_port->work, zfcp_fc_wka_port_offline); |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 90 | } |
| 91 | |
Christof Schmitt | bd0072e | 2009-11-24 16:54:11 +0100 | [diff] [blame] | 92 | static void zfcp_fc_wka_port_force_offline(struct zfcp_fc_wka_port *wka) |
Swen Schillig | 828bc12 | 2009-04-17 15:08:05 +0200 | [diff] [blame] | 93 | { |
| 94 | cancel_delayed_work_sync(&wka->work); |
| 95 | mutex_lock(&wka->mutex); |
Christof Schmitt | bd0072e | 2009-11-24 16:54:11 +0100 | [diff] [blame] | 96 | wka->status = ZFCP_FC_WKA_PORT_OFFLINE; |
Swen Schillig | 828bc12 | 2009-04-17 15:08:05 +0200 | [diff] [blame] | 97 | mutex_unlock(&wka->mutex); |
| 98 | } |
| 99 | |
Christof Schmitt | bd0072e | 2009-11-24 16:54:11 +0100 | [diff] [blame] | 100 | void zfcp_fc_wka_ports_force_offline(struct zfcp_fc_wka_ports *gs) |
Christof Schmitt | 55c770f | 2009-08-18 15:43:12 +0200 | [diff] [blame] | 101 | { |
Swen Schillig | f3450c7 | 2009-11-24 16:53:59 +0100 | [diff] [blame] | 102 | if (!gs) |
| 103 | return; |
Christof Schmitt | 55c770f | 2009-08-18 15:43:12 +0200 | [diff] [blame] | 104 | zfcp_fc_wka_port_force_offline(&gs->ms); |
| 105 | zfcp_fc_wka_port_force_offline(&gs->ts); |
| 106 | zfcp_fc_wka_port_force_offline(&gs->ds); |
| 107 | zfcp_fc_wka_port_force_offline(&gs->as); |
Christof Schmitt | 55c770f | 2009-08-18 15:43:12 +0200 | [diff] [blame] | 108 | } |
| 109 | |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 110 | static void _zfcp_fc_incoming_rscn(struct zfcp_fsf_req *fsf_req, u32 range, |
Christof Schmitt | 9d05ce2 | 2009-11-24 16:54:09 +0100 | [diff] [blame] | 111 | struct fc_els_rscn_page *page) |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 112 | { |
| 113 | unsigned long flags; |
Swen Schillig | ecf0c77 | 2009-11-24 16:53:58 +0100 | [diff] [blame] | 114 | struct zfcp_adapter *adapter = fsf_req->adapter; |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 115 | struct zfcp_port *port; |
| 116 | |
Swen Schillig | ecf0c77 | 2009-11-24 16:53:58 +0100 | [diff] [blame] | 117 | read_lock_irqsave(&adapter->port_list_lock, flags); |
| 118 | list_for_each_entry(port, &adapter->port_list, list) { |
Christof Schmitt | 9d05ce2 | 2009-11-24 16:54:09 +0100 | [diff] [blame] | 119 | if ((port->d_id & range) == (ntoh24(page->rscn_fid) & range)) |
Swen Schillig | 6f53a2d | 2009-08-18 15:43:23 +0200 | [diff] [blame] | 120 | zfcp_fc_test_link(port); |
Swen Schillig | ea460a8 | 2009-05-15 13:18:20 +0200 | [diff] [blame] | 121 | if (!port->d_id) |
| 122 | zfcp_erp_port_reopen(port, |
| 123 | ZFCP_STATUS_COMMON_ERP_FAILED, |
| 124 | "fcrscn1", NULL); |
| 125 | } |
Swen Schillig | ecf0c77 | 2009-11-24 16:53:58 +0100 | [diff] [blame] | 126 | read_unlock_irqrestore(&adapter->port_list_lock, flags); |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 127 | } |
| 128 | |
| 129 | static void zfcp_fc_incoming_rscn(struct zfcp_fsf_req *fsf_req) |
| 130 | { |
| 131 | struct fsf_status_read_buffer *status_buffer = (void *)fsf_req->data; |
Christof Schmitt | 9d05ce2 | 2009-11-24 16:54:09 +0100 | [diff] [blame] | 132 | struct fc_els_rscn *head; |
| 133 | struct fc_els_rscn_page *page; |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 134 | u16 i; |
| 135 | u16 no_entries; |
Christof Schmitt | 9d05ce2 | 2009-11-24 16:54:09 +0100 | [diff] [blame] | 136 | unsigned int afmt; |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 137 | |
Christof Schmitt | 9d05ce2 | 2009-11-24 16:54:09 +0100 | [diff] [blame] | 138 | head = (struct fc_els_rscn *) status_buffer->payload.data; |
| 139 | page = (struct fc_els_rscn_page *) head; |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 140 | |
| 141 | /* see FC-FS */ |
Christof Schmitt | 9d05ce2 | 2009-11-24 16:54:09 +0100 | [diff] [blame] | 142 | no_entries = head->rscn_plen / sizeof(struct fc_els_rscn_page); |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 143 | |
| 144 | for (i = 1; i < no_entries; i++) { |
| 145 | /* skip head and start with 1st element */ |
Christof Schmitt | 9d05ce2 | 2009-11-24 16:54:09 +0100 | [diff] [blame] | 146 | page++; |
| 147 | afmt = page->rscn_page_flags & ELS_RSCN_ADDR_FMT_MASK; |
| 148 | _zfcp_fc_incoming_rscn(fsf_req, zfcp_fc_rscn_range_mask[afmt], |
| 149 | page); |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 150 | } |
Swen Schillig | 9eae07e | 2009-11-24 16:54:06 +0100 | [diff] [blame] | 151 | queue_work(fsf_req->adapter->work_queue, &fsf_req->adapter->scan_work); |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 152 | } |
| 153 | |
Swen Schillig | 7ba58c9 | 2008-10-01 12:42:18 +0200 | [diff] [blame] | 154 | 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] | 155 | { |
Swen Schillig | ecf0c77 | 2009-11-24 16:53:58 +0100 | [diff] [blame] | 156 | unsigned long flags; |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 157 | struct zfcp_adapter *adapter = req->adapter; |
| 158 | struct zfcp_port *port; |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 159 | |
Swen Schillig | ecf0c77 | 2009-11-24 16:53:58 +0100 | [diff] [blame] | 160 | read_lock_irqsave(&adapter->port_list_lock, flags); |
| 161 | list_for_each_entry(port, &adapter->port_list, list) |
| 162 | if (port->wwpn == wwpn) { |
| 163 | zfcp_erp_port_forced_reopen(port, 0, "fciwwp1", req); |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 164 | break; |
Swen Schillig | ecf0c77 | 2009-11-24 16:53:58 +0100 | [diff] [blame] | 165 | } |
| 166 | read_unlock_irqrestore(&adapter->port_list_lock, flags); |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 167 | } |
| 168 | |
| 169 | static void zfcp_fc_incoming_plogi(struct zfcp_fsf_req *req) |
| 170 | { |
Christof Schmitt | 9d05ce2 | 2009-11-24 16:54:09 +0100 | [diff] [blame] | 171 | struct fsf_status_read_buffer *status_buffer; |
| 172 | struct fc_els_flogi *plogi; |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 173 | |
Christof Schmitt | 9d05ce2 | 2009-11-24 16:54:09 +0100 | [diff] [blame] | 174 | status_buffer = (struct fsf_status_read_buffer *) req->data; |
| 175 | plogi = (struct fc_els_flogi *) status_buffer->payload.data; |
| 176 | zfcp_fc_incoming_wwpn(req, plogi->fl_wwpn); |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 177 | } |
| 178 | |
| 179 | static void zfcp_fc_incoming_logo(struct zfcp_fsf_req *req) |
| 180 | { |
| 181 | struct fsf_status_read_buffer *status_buffer = |
| 182 | (struct fsf_status_read_buffer *)req->data; |
Christof Schmitt | 9d05ce2 | 2009-11-24 16:54:09 +0100 | [diff] [blame] | 183 | struct fc_els_logo *logo = |
| 184 | (struct fc_els_logo *) status_buffer->payload.data; |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 185 | |
Christof Schmitt | 9d05ce2 | 2009-11-24 16:54:09 +0100 | [diff] [blame] | 186 | zfcp_fc_incoming_wwpn(req, logo->fl_n_port_wwn); |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 187 | } |
| 188 | |
| 189 | /** |
| 190 | * zfcp_fc_incoming_els - handle incoming ELS |
| 191 | * @fsf_req - request which contains incoming ELS |
| 192 | */ |
| 193 | void zfcp_fc_incoming_els(struct zfcp_fsf_req *fsf_req) |
| 194 | { |
| 195 | struct fsf_status_read_buffer *status_buffer = |
| 196 | (struct fsf_status_read_buffer *) fsf_req->data; |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 197 | unsigned int els_type = status_buffer->payload.data[0]; |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 198 | |
Swen Schillig | 5771710 | 2009-08-18 15:43:21 +0200 | [diff] [blame] | 199 | zfcp_dbf_san_incoming_els(fsf_req); |
Christof Schmitt | 9d05ce2 | 2009-11-24 16:54:09 +0100 | [diff] [blame] | 200 | if (els_type == ELS_PLOGI) |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 201 | zfcp_fc_incoming_plogi(fsf_req); |
Christof Schmitt | 9d05ce2 | 2009-11-24 16:54:09 +0100 | [diff] [blame] | 202 | else if (els_type == ELS_LOGO) |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 203 | zfcp_fc_incoming_logo(fsf_req); |
Christof Schmitt | 9d05ce2 | 2009-11-24 16:54:09 +0100 | [diff] [blame] | 204 | else if (els_type == ELS_RSCN) |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 205 | zfcp_fc_incoming_rscn(fsf_req); |
| 206 | } |
| 207 | |
Christof Schmitt | 7c7dc19 | 2009-11-24 16:54:13 +0100 | [diff] [blame^] | 208 | static void zfcp_fc_ns_gid_pn_eval(void *data) |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 209 | { |
Christof Schmitt | 7c7dc19 | 2009-11-24 16:54:13 +0100 | [diff] [blame^] | 210 | struct zfcp_fc_gid_pn *gid_pn = data; |
| 211 | struct zfcp_fsf_ct_els *ct = &gid_pn->ct; |
Christof Schmitt | dbf5dfe | 2009-11-24 16:54:10 +0100 | [diff] [blame] | 212 | struct zfcp_fc_gid_pn_req *gid_pn_req = sg_virt(ct->req); |
| 213 | struct zfcp_fc_gid_pn_resp *gid_pn_resp = sg_virt(ct->resp); |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 214 | struct zfcp_port *port = gid_pn->port; |
| 215 | |
| 216 | if (ct->status) |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 217 | return; |
Christof Schmitt | dbf5dfe | 2009-11-24 16:54:10 +0100 | [diff] [blame] | 218 | if (gid_pn_resp->ct_hdr.ct_cmd != FC_FS_ACC) |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 219 | return; |
Christof Schmitt | a5b11dd | 2009-03-02 13:08:54 +0100 | [diff] [blame] | 220 | |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 221 | /* paranoia */ |
Christof Schmitt | dbf5dfe | 2009-11-24 16:54:10 +0100 | [diff] [blame] | 222 | if (gid_pn_req->gid_pn.fn_wwpn != port->wwpn) |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 223 | return; |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 224 | /* looks like a valid d_id */ |
Christof Schmitt | dbf5dfe | 2009-11-24 16:54:10 +0100 | [diff] [blame] | 225 | port->d_id = ntoh24(gid_pn_resp->gid_pn.fp_fid); |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 226 | } |
| 227 | |
Christof Schmitt | 7c7dc19 | 2009-11-24 16:54:13 +0100 | [diff] [blame^] | 228 | static void zfcp_fc_complete(void *data) |
| 229 | { |
| 230 | complete(data); |
| 231 | } |
| 232 | |
Christof Schmitt | 799b76d | 2009-08-18 15:43:20 +0200 | [diff] [blame] | 233 | static int zfcp_fc_ns_gid_pn_request(struct zfcp_port *port, |
Christof Schmitt | dbf5dfe | 2009-11-24 16:54:10 +0100 | [diff] [blame] | 234 | struct zfcp_fc_gid_pn *gid_pn) |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 235 | { |
Christof Schmitt | 799b76d | 2009-08-18 15:43:20 +0200 | [diff] [blame] | 236 | struct zfcp_adapter *adapter = port->adapter; |
Christof Schmitt | 7c7dc19 | 2009-11-24 16:54:13 +0100 | [diff] [blame^] | 237 | DECLARE_COMPLETION_ONSTACK(completion); |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 238 | int ret; |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 239 | |
| 240 | /* setup parameters for send generic command */ |
Christof Schmitt | 799b76d | 2009-08-18 15:43:20 +0200 | [diff] [blame] | 241 | gid_pn->port = port; |
Christof Schmitt | 7c7dc19 | 2009-11-24 16:54:13 +0100 | [diff] [blame^] | 242 | gid_pn->ct.handler = zfcp_fc_complete; |
| 243 | gid_pn->ct.handler_data = &completion; |
Christof Schmitt | dbf5dfe | 2009-11-24 16:54:10 +0100 | [diff] [blame] | 244 | gid_pn->ct.req = &gid_pn->sg_req; |
| 245 | gid_pn->ct.resp = &gid_pn->sg_resp; |
| 246 | sg_init_one(&gid_pn->sg_req, &gid_pn->gid_pn_req, |
| 247 | sizeof(struct zfcp_fc_gid_pn_req)); |
| 248 | sg_init_one(&gid_pn->sg_resp, &gid_pn->gid_pn_resp, |
| 249 | sizeof(struct zfcp_fc_gid_pn_resp)); |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 250 | |
| 251 | /* setup nameserver request */ |
Christof Schmitt | dbf5dfe | 2009-11-24 16:54:10 +0100 | [diff] [blame] | 252 | gid_pn->gid_pn_req.ct_hdr.ct_rev = FC_CT_REV; |
| 253 | gid_pn->gid_pn_req.ct_hdr.ct_fs_type = FC_FST_DIR; |
| 254 | gid_pn->gid_pn_req.ct_hdr.ct_fs_subtype = FC_NS_SUBTYPE; |
| 255 | gid_pn->gid_pn_req.ct_hdr.ct_options = 0; |
| 256 | gid_pn->gid_pn_req.ct_hdr.ct_cmd = FC_NS_GID_PN; |
| 257 | gid_pn->gid_pn_req.ct_hdr.ct_mr_size = ZFCP_FC_CT_SIZE_PAGE / 4; |
| 258 | gid_pn->gid_pn_req.gid_pn.fn_wwpn = port->wwpn; |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 259 | |
Christof Schmitt | 7c7dc19 | 2009-11-24 16:54:13 +0100 | [diff] [blame^] | 260 | ret = zfcp_fsf_send_ct(&adapter->gs->ds, &gid_pn->ct, |
| 261 | adapter->pool.gid_pn_req); |
| 262 | if (!ret) { |
| 263 | wait_for_completion(&completion); |
| 264 | zfcp_fc_ns_gid_pn_eval(gid_pn); |
| 265 | } |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 266 | return ret; |
| 267 | } |
| 268 | |
| 269 | /** |
| 270 | * zfcp_fc_ns_gid_pn_request - initiate GID_PN nameserver request |
Christof Schmitt | 799b76d | 2009-08-18 15:43:20 +0200 | [diff] [blame] | 271 | * @port: port where GID_PN request is needed |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 272 | * return: -ENOMEM on error, 0 otherwise |
| 273 | */ |
Christof Schmitt | 799b76d | 2009-08-18 15:43:20 +0200 | [diff] [blame] | 274 | static int zfcp_fc_ns_gid_pn(struct zfcp_port *port) |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 275 | { |
| 276 | int ret; |
Christof Schmitt | dbf5dfe | 2009-11-24 16:54:10 +0100 | [diff] [blame] | 277 | struct zfcp_fc_gid_pn *gid_pn; |
Christof Schmitt | 799b76d | 2009-08-18 15:43:20 +0200 | [diff] [blame] | 278 | struct zfcp_adapter *adapter = port->adapter; |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 279 | |
Christof Schmitt | dbf5dfe | 2009-11-24 16:54:10 +0100 | [diff] [blame] | 280 | gid_pn = mempool_alloc(adapter->pool.gid_pn, GFP_ATOMIC); |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 281 | if (!gid_pn) |
| 282 | return -ENOMEM; |
| 283 | |
| 284 | memset(gid_pn, 0, sizeof(*gid_pn)); |
| 285 | |
Swen Schillig | 6f53a2d | 2009-08-18 15:43:23 +0200 | [diff] [blame] | 286 | ret = zfcp_fc_wka_port_get(&adapter->gs->ds); |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 287 | if (ret) |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 288 | goto out; |
| 289 | |
Christof Schmitt | 799b76d | 2009-08-18 15:43:20 +0200 | [diff] [blame] | 290 | ret = zfcp_fc_ns_gid_pn_request(port, gid_pn); |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 291 | |
Swen Schillig | 6f53a2d | 2009-08-18 15:43:23 +0200 | [diff] [blame] | 292 | zfcp_fc_wka_port_put(&adapter->gs->ds); |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 293 | out: |
Christof Schmitt | dbf5dfe | 2009-11-24 16:54:10 +0100 | [diff] [blame] | 294 | mempool_free(gid_pn, adapter->pool.gid_pn); |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 295 | return ret; |
| 296 | } |
| 297 | |
Christof Schmitt | 799b76d | 2009-08-18 15:43:20 +0200 | [diff] [blame] | 298 | void zfcp_fc_port_did_lookup(struct work_struct *work) |
| 299 | { |
| 300 | int ret; |
| 301 | struct zfcp_port *port = container_of(work, struct zfcp_port, |
| 302 | gid_pn_work); |
| 303 | |
| 304 | ret = zfcp_fc_ns_gid_pn(port); |
| 305 | if (ret) { |
| 306 | /* could not issue gid_pn for some reason */ |
| 307 | zfcp_erp_adapter_reopen(port->adapter, 0, "fcgpn_1", NULL); |
| 308 | goto out; |
| 309 | } |
| 310 | |
| 311 | if (!port->d_id) { |
| 312 | zfcp_erp_port_failed(port, "fcgpn_2", NULL); |
| 313 | goto out; |
| 314 | } |
| 315 | |
| 316 | zfcp_erp_port_reopen(port, 0, "fcgpn_3", NULL); |
| 317 | out: |
Swen Schillig | f3450c7 | 2009-11-24 16:53:59 +0100 | [diff] [blame] | 318 | put_device(&port->sysfs_device); |
Christof Schmitt | 799b76d | 2009-08-18 15:43:20 +0200 | [diff] [blame] | 319 | } |
| 320 | |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 321 | /** |
Christof Schmitt | 934aeb587 | 2009-10-14 11:00:43 +0200 | [diff] [blame] | 322 | * zfcp_fc_trigger_did_lookup - trigger the d_id lookup using a GID_PN request |
| 323 | * @port: The zfcp_port to lookup the d_id for. |
| 324 | */ |
| 325 | void zfcp_fc_trigger_did_lookup(struct zfcp_port *port) |
| 326 | { |
Swen Schillig | f3450c7 | 2009-11-24 16:53:59 +0100 | [diff] [blame] | 327 | get_device(&port->sysfs_device); |
Christof Schmitt | 934aeb587 | 2009-10-14 11:00:43 +0200 | [diff] [blame] | 328 | if (!queue_work(port->adapter->work_queue, &port->gid_pn_work)) |
Swen Schillig | f3450c7 | 2009-11-24 16:53:59 +0100 | [diff] [blame] | 329 | put_device(&port->sysfs_device); |
Christof Schmitt | 934aeb587 | 2009-10-14 11:00:43 +0200 | [diff] [blame] | 330 | } |
| 331 | |
| 332 | /** |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 333 | * zfcp_fc_plogi_evaluate - evaluate PLOGI playload |
| 334 | * @port: zfcp_port structure |
| 335 | * @plogi: plogi payload |
| 336 | * |
| 337 | * Evaluate PLOGI playload and copy important fields into zfcp_port structure |
| 338 | */ |
Christof Schmitt | 9d05ce2 | 2009-11-24 16:54:09 +0100 | [diff] [blame] | 339 | void zfcp_fc_plogi_evaluate(struct zfcp_port *port, struct fc_els_flogi *plogi) |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 340 | { |
Christof Schmitt | 9d05ce2 | 2009-11-24 16:54:09 +0100 | [diff] [blame] | 341 | if (plogi->fl_wwpn != port->wwpn) { |
| 342 | port->d_id = 0; |
| 343 | dev_warn(&port->adapter->ccw_device->dev, |
| 344 | "A port opened with WWPN 0x%016Lx returned data that " |
| 345 | "identifies it as WWPN 0x%016Lx\n", |
| 346 | (unsigned long long) port->wwpn, |
| 347 | (unsigned long long) plogi->fl_wwpn); |
| 348 | return; |
| 349 | } |
| 350 | |
| 351 | port->wwnn = plogi->fl_wwnn; |
| 352 | port->maxframe_size = plogi->fl_csp.sp_bb_data; |
| 353 | |
| 354 | if (plogi->fl_cssp[0].cp_class & FC_CPC_VALID) |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 355 | port->supported_classes |= FC_COS_CLASS1; |
Christof Schmitt | 9d05ce2 | 2009-11-24 16:54:09 +0100 | [diff] [blame] | 356 | if (plogi->fl_cssp[1].cp_class & FC_CPC_VALID) |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 357 | port->supported_classes |= FC_COS_CLASS2; |
Christof Schmitt | 9d05ce2 | 2009-11-24 16:54:09 +0100 | [diff] [blame] | 358 | if (plogi->fl_cssp[2].cp_class & FC_CPC_VALID) |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 359 | port->supported_classes |= FC_COS_CLASS3; |
Christof Schmitt | 9d05ce2 | 2009-11-24 16:54:09 +0100 | [diff] [blame] | 360 | if (plogi->fl_cssp[3].cp_class & FC_CPC_VALID) |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 361 | port->supported_classes |= FC_COS_CLASS4; |
| 362 | } |
| 363 | |
Christof Schmitt | 7c7dc19 | 2009-11-24 16:54:13 +0100 | [diff] [blame^] | 364 | static void zfcp_fc_adisc_handler(void *data) |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 365 | { |
Christof Schmitt | 7c7dc19 | 2009-11-24 16:54:13 +0100 | [diff] [blame^] | 366 | struct zfcp_fc_els_adisc *adisc = data; |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 367 | struct zfcp_port *port = adisc->els.port; |
Christof Schmitt | 9d05ce2 | 2009-11-24 16:54:09 +0100 | [diff] [blame] | 368 | struct fc_els_adisc *adisc_resp = &adisc->adisc_resp; |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 369 | |
Christof Schmitt | 3968ce8 | 2008-07-02 10:56:32 +0200 | [diff] [blame] | 370 | if (adisc->els.status) { |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 371 | /* request rejected or timed out */ |
Swen Schillig | 5b43e71 | 2009-04-17 15:08:10 +0200 | [diff] [blame] | 372 | zfcp_erp_port_forced_reopen(port, ZFCP_STATUS_COMMON_ERP_FAILED, |
| 373 | "fcadh_1", NULL); |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 374 | goto out; |
| 375 | } |
| 376 | |
| 377 | if (!port->wwnn) |
Christof Schmitt | 9d05ce2 | 2009-11-24 16:54:09 +0100 | [diff] [blame] | 378 | port->wwnn = adisc_resp->adisc_wwnn; |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 379 | |
Christof Schmitt | 9d05ce2 | 2009-11-24 16:54:09 +0100 | [diff] [blame] | 380 | if ((port->wwpn != adisc_resp->adisc_wwpn) || |
Christof Schmitt | a2fa0ae | 2009-03-02 13:09:08 +0100 | [diff] [blame] | 381 | !(atomic_read(&port->status) & ZFCP_STATUS_COMMON_OPEN)) { |
Swen Schillig | 2409549 | 2009-03-02 13:09:07 +0100 | [diff] [blame] | 382 | zfcp_erp_port_reopen(port, ZFCP_STATUS_COMMON_ERP_FAILED, |
| 383 | "fcadh_2", NULL); |
Christof Schmitt | a2fa0ae | 2009-03-02 13:09:08 +0100 | [diff] [blame] | 384 | goto out; |
| 385 | } |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 386 | |
Christof Schmitt | a2fa0ae | 2009-03-02 13:09:08 +0100 | [diff] [blame] | 387 | /* port is good, unblock rport without going through erp */ |
| 388 | zfcp_scsi_schedule_rport_register(port); |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 389 | out: |
Christof Schmitt | 14e242e | 2009-08-18 15:43:11 +0200 | [diff] [blame] | 390 | atomic_clear_mask(ZFCP_STATUS_PORT_LINK_TEST, &port->status); |
Swen Schillig | f3450c7 | 2009-11-24 16:53:59 +0100 | [diff] [blame] | 391 | put_device(&port->sysfs_device); |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 392 | kfree(adisc); |
| 393 | } |
| 394 | |
| 395 | static int zfcp_fc_adisc(struct zfcp_port *port) |
| 396 | { |
Christof Schmitt | 9d05ce2 | 2009-11-24 16:54:09 +0100 | [diff] [blame] | 397 | struct zfcp_fc_els_adisc *adisc; |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 398 | struct zfcp_adapter *adapter = port->adapter; |
| 399 | |
Christof Schmitt | 9d05ce2 | 2009-11-24 16:54:09 +0100 | [diff] [blame] | 400 | adisc = kzalloc(sizeof(struct zfcp_fc_els_adisc), GFP_ATOMIC); |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 401 | if (!adisc) |
| 402 | return -ENOMEM; |
| 403 | |
Christof Schmitt | 7c7dc19 | 2009-11-24 16:54:13 +0100 | [diff] [blame^] | 404 | adisc->els.port = port; |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 405 | adisc->els.req = &adisc->req; |
| 406 | adisc->els.resp = &adisc->resp; |
Christof Schmitt | 9d05ce2 | 2009-11-24 16:54:09 +0100 | [diff] [blame] | 407 | sg_init_one(adisc->els.req, &adisc->adisc_req, |
| 408 | sizeof(struct fc_els_adisc)); |
| 409 | sg_init_one(adisc->els.resp, &adisc->adisc_resp, |
| 410 | sizeof(struct fc_els_adisc)); |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 411 | |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 412 | adisc->els.handler = zfcp_fc_adisc_handler; |
Christof Schmitt | 7c7dc19 | 2009-11-24 16:54:13 +0100 | [diff] [blame^] | 413 | adisc->els.handler_data = adisc; |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 414 | |
| 415 | /* acc. to FC-FS, hard_nport_id in ADISC should not be set for ports |
| 416 | without FC-AL-2 capability, so we don't set it */ |
Christof Schmitt | 9d05ce2 | 2009-11-24 16:54:09 +0100 | [diff] [blame] | 417 | adisc->adisc_req.adisc_wwpn = fc_host_port_name(adapter->scsi_host); |
| 418 | adisc->adisc_req.adisc_wwnn = fc_host_node_name(adapter->scsi_host); |
Christof Schmitt | 7c7dc19 | 2009-11-24 16:54:13 +0100 | [diff] [blame^] | 419 | adisc->adisc_req.adisc_cmd = ELS_ADISC; |
Christof Schmitt | 9d05ce2 | 2009-11-24 16:54:09 +0100 | [diff] [blame] | 420 | hton24(adisc->adisc_req.adisc_port_id, |
| 421 | fc_host_port_id(adapter->scsi_host)); |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 422 | |
Christof Schmitt | 7c7dc19 | 2009-11-24 16:54:13 +0100 | [diff] [blame^] | 423 | return zfcp_fsf_send_els(adapter, port->d_id, &adisc->els); |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 424 | } |
| 425 | |
Christof Schmitt | 8fdf30d | 2009-03-02 13:09:01 +0100 | [diff] [blame] | 426 | void zfcp_fc_link_test_work(struct work_struct *work) |
| 427 | { |
| 428 | struct zfcp_port *port = |
| 429 | container_of(work, struct zfcp_port, test_link_work); |
| 430 | int retval; |
| 431 | |
Swen Schillig | f3450c7 | 2009-11-24 16:53:59 +0100 | [diff] [blame] | 432 | get_device(&port->sysfs_device); |
Christof Schmitt | a2fa0ae | 2009-03-02 13:09:08 +0100 | [diff] [blame] | 433 | port->rport_task = RPORT_DEL; |
| 434 | zfcp_scsi_rport_work(&port->rport_work); |
| 435 | |
Christof Schmitt | 14e242e | 2009-08-18 15:43:11 +0200 | [diff] [blame] | 436 | /* only issue one test command at one time per port */ |
| 437 | if (atomic_read(&port->status) & ZFCP_STATUS_PORT_LINK_TEST) |
| 438 | goto out; |
| 439 | |
| 440 | atomic_set_mask(ZFCP_STATUS_PORT_LINK_TEST, &port->status); |
| 441 | |
Christof Schmitt | 8fdf30d | 2009-03-02 13:09:01 +0100 | [diff] [blame] | 442 | retval = zfcp_fc_adisc(port); |
| 443 | if (retval == 0) |
| 444 | return; |
| 445 | |
| 446 | /* send of ADISC was not possible */ |
Christof Schmitt | 14e242e | 2009-08-18 15:43:11 +0200 | [diff] [blame] | 447 | atomic_clear_mask(ZFCP_STATUS_PORT_LINK_TEST, &port->status); |
Christof Schmitt | a2fa0ae | 2009-03-02 13:09:08 +0100 | [diff] [blame] | 448 | zfcp_erp_port_forced_reopen(port, 0, "fcltwk1", NULL); |
| 449 | |
Christof Schmitt | 14e242e | 2009-08-18 15:43:11 +0200 | [diff] [blame] | 450 | out: |
Swen Schillig | f3450c7 | 2009-11-24 16:53:59 +0100 | [diff] [blame] | 451 | put_device(&port->sysfs_device); |
Christof Schmitt | 8fdf30d | 2009-03-02 13:09:01 +0100 | [diff] [blame] | 452 | } |
| 453 | |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 454 | /** |
Swen Schillig | 6f53a2d | 2009-08-18 15:43:23 +0200 | [diff] [blame] | 455 | * zfcp_fc_test_link - lightweight link test procedure |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 456 | * @port: port to be tested |
| 457 | * |
| 458 | * Test status of a link to a remote port using the ELS command ADISC. |
| 459 | * If there is a problem with the remote port, error recovery steps |
| 460 | * will be triggered. |
| 461 | */ |
Swen Schillig | 6f53a2d | 2009-08-18 15:43:23 +0200 | [diff] [blame] | 462 | void zfcp_fc_test_link(struct zfcp_port *port) |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 463 | { |
Swen Schillig | f3450c7 | 2009-11-24 16:53:59 +0100 | [diff] [blame] | 464 | get_device(&port->sysfs_device); |
Swen Schillig | 4544683 | 2009-08-18 15:43:17 +0200 | [diff] [blame] | 465 | if (!queue_work(port->adapter->work_queue, &port->test_link_work)) |
Swen Schillig | f3450c7 | 2009-11-24 16:53:59 +0100 | [diff] [blame] | 466 | put_device(&port->sysfs_device); |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 467 | } |
Swen Schillig | cc8c282 | 2008-06-10 18:21:00 +0200 | [diff] [blame] | 468 | |
Christof Schmitt | dbf5dfe | 2009-11-24 16:54:10 +0100 | [diff] [blame] | 469 | static void zfcp_free_sg_env(struct zfcp_fc_gpn_ft *gpn_ft, int buf_num) |
Swen Schillig | cc8c282 | 2008-06-10 18:21:00 +0200 | [diff] [blame] | 470 | { |
| 471 | struct scatterlist *sg = &gpn_ft->sg_req; |
| 472 | |
Swen Schillig | a4623c4 | 2009-08-18 15:43:15 +0200 | [diff] [blame] | 473 | kmem_cache_free(zfcp_data.gpn_ft_cache, sg_virt(sg)); |
Christof Schmitt | 39eb7e9 | 2008-12-19 16:57:01 +0100 | [diff] [blame] | 474 | zfcp_sg_free_table(gpn_ft->sg_resp, buf_num); |
Swen Schillig | cc8c282 | 2008-06-10 18:21:00 +0200 | [diff] [blame] | 475 | |
| 476 | kfree(gpn_ft); |
| 477 | } |
| 478 | |
Christof Schmitt | dbf5dfe | 2009-11-24 16:54:10 +0100 | [diff] [blame] | 479 | static struct zfcp_fc_gpn_ft *zfcp_alloc_sg_env(int buf_num) |
Swen Schillig | cc8c282 | 2008-06-10 18:21:00 +0200 | [diff] [blame] | 480 | { |
Christof Schmitt | dbf5dfe | 2009-11-24 16:54:10 +0100 | [diff] [blame] | 481 | struct zfcp_fc_gpn_ft *gpn_ft; |
| 482 | struct zfcp_fc_gpn_ft_req *req; |
Swen Schillig | cc8c282 | 2008-06-10 18:21:00 +0200 | [diff] [blame] | 483 | |
| 484 | gpn_ft = kzalloc(sizeof(*gpn_ft), GFP_KERNEL); |
| 485 | if (!gpn_ft) |
| 486 | return NULL; |
| 487 | |
Swen Schillig | a4623c4 | 2009-08-18 15:43:15 +0200 | [diff] [blame] | 488 | req = kmem_cache_alloc(zfcp_data.gpn_ft_cache, GFP_KERNEL); |
Swen Schillig | cc8c282 | 2008-06-10 18:21:00 +0200 | [diff] [blame] | 489 | if (!req) { |
| 490 | kfree(gpn_ft); |
| 491 | gpn_ft = NULL; |
| 492 | goto out; |
| 493 | } |
| 494 | sg_init_one(&gpn_ft->sg_req, req, sizeof(*req)); |
| 495 | |
Christof Schmitt | 39eb7e9 | 2008-12-19 16:57:01 +0100 | [diff] [blame] | 496 | if (zfcp_sg_setup_table(gpn_ft->sg_resp, buf_num)) { |
| 497 | zfcp_free_sg_env(gpn_ft, buf_num); |
Swen Schillig | cc8c282 | 2008-06-10 18:21:00 +0200 | [diff] [blame] | 498 | gpn_ft = NULL; |
| 499 | } |
| 500 | out: |
| 501 | return gpn_ft; |
| 502 | } |
| 503 | |
| 504 | |
Christof Schmitt | dbf5dfe | 2009-11-24 16:54:10 +0100 | [diff] [blame] | 505 | static int zfcp_fc_send_gpn_ft(struct zfcp_fc_gpn_ft *gpn_ft, |
Swen Schillig | 6f53a2d | 2009-08-18 15:43:23 +0200 | [diff] [blame] | 506 | struct zfcp_adapter *adapter, int max_bytes) |
Swen Schillig | cc8c282 | 2008-06-10 18:21:00 +0200 | [diff] [blame] | 507 | { |
Christof Schmitt | 7c7dc19 | 2009-11-24 16:54:13 +0100 | [diff] [blame^] | 508 | struct zfcp_fsf_ct_els *ct = &gpn_ft->ct; |
Christof Schmitt | dbf5dfe | 2009-11-24 16:54:10 +0100 | [diff] [blame] | 509 | struct zfcp_fc_gpn_ft_req *req = sg_virt(&gpn_ft->sg_req); |
Christof Schmitt | 7c7dc19 | 2009-11-24 16:54:13 +0100 | [diff] [blame^] | 510 | DECLARE_COMPLETION_ONSTACK(completion); |
Swen Schillig | cc8c282 | 2008-06-10 18:21:00 +0200 | [diff] [blame] | 511 | int ret; |
| 512 | |
| 513 | /* prepare CT IU for GPN_FT */ |
Christof Schmitt | dbf5dfe | 2009-11-24 16:54:10 +0100 | [diff] [blame] | 514 | req->ct_hdr.ct_rev = FC_CT_REV; |
| 515 | req->ct_hdr.ct_fs_type = FC_FST_DIR; |
| 516 | req->ct_hdr.ct_fs_subtype = FC_NS_SUBTYPE; |
| 517 | req->ct_hdr.ct_options = 0; |
| 518 | req->ct_hdr.ct_cmd = FC_NS_GPN_FT; |
| 519 | req->ct_hdr.ct_mr_size = max_bytes / 4; |
| 520 | req->gpn_ft.fn_domain_id_scope = 0; |
| 521 | req->gpn_ft.fn_area_id_scope = 0; |
| 522 | req->gpn_ft.fn_fc4_type = FC_TYPE_FCP; |
Swen Schillig | cc8c282 | 2008-06-10 18:21:00 +0200 | [diff] [blame] | 523 | |
| 524 | /* prepare zfcp_send_ct */ |
Christof Schmitt | 7c7dc19 | 2009-11-24 16:54:13 +0100 | [diff] [blame^] | 525 | ct->handler = zfcp_fc_complete; |
| 526 | ct->handler_data = &completion; |
Swen Schillig | cc8c282 | 2008-06-10 18:21:00 +0200 | [diff] [blame] | 527 | ct->req = &gpn_ft->sg_req; |
| 528 | ct->resp = gpn_ft->sg_resp; |
Swen Schillig | cc8c282 | 2008-06-10 18:21:00 +0200 | [diff] [blame] | 529 | |
Christof Schmitt | 7c7dc19 | 2009-11-24 16:54:13 +0100 | [diff] [blame^] | 530 | ret = zfcp_fsf_send_ct(&adapter->gs->ds, ct, NULL); |
Swen Schillig | cc8c282 | 2008-06-10 18:21:00 +0200 | [diff] [blame] | 531 | if (!ret) |
Christof Schmitt | 7c7dc19 | 2009-11-24 16:54:13 +0100 | [diff] [blame^] | 532 | wait_for_completion(&completion); |
Swen Schillig | cc8c282 | 2008-06-10 18:21:00 +0200 | [diff] [blame] | 533 | return ret; |
| 534 | } |
| 535 | |
Swen Schillig | f3450c7 | 2009-11-24 16:53:59 +0100 | [diff] [blame] | 536 | static void zfcp_fc_validate_port(struct zfcp_port *port, struct list_head *lh) |
Swen Schillig | cc8c282 | 2008-06-10 18:21:00 +0200 | [diff] [blame] | 537 | { |
Martin Petermann | 6ab35c0 | 2009-04-17 15:08:13 +0200 | [diff] [blame] | 538 | if (!(atomic_read(&port->status) & ZFCP_STATUS_COMMON_NOESC)) |
| 539 | return; |
| 540 | |
Swen Schillig | cc8c282 | 2008-06-10 18:21:00 +0200 | [diff] [blame] | 541 | atomic_clear_mask(ZFCP_STATUS_COMMON_NOESC, &port->status); |
| 542 | |
Christof Schmitt | 0406289 | 2008-10-01 12:42:20 +0200 | [diff] [blame] | 543 | if ((port->supported_classes != 0) || |
Swen Schillig | f3450c7 | 2009-11-24 16:53:59 +0100 | [diff] [blame] | 544 | !list_empty(&port->unit_list)) |
Swen Schillig | cc8c282 | 2008-06-10 18:21:00 +0200 | [diff] [blame] | 545 | return; |
Swen Schillig | f3450c7 | 2009-11-24 16:53:59 +0100 | [diff] [blame] | 546 | |
Swen Schillig | f3450c7 | 2009-11-24 16:53:59 +0100 | [diff] [blame] | 547 | list_move_tail(&port->list, lh); |
Swen Schillig | cc8c282 | 2008-06-10 18:21:00 +0200 | [diff] [blame] | 548 | } |
| 549 | |
Christof Schmitt | 7c7dc19 | 2009-11-24 16:54:13 +0100 | [diff] [blame^] | 550 | static int zfcp_fc_eval_gpn_ft(struct zfcp_fc_gpn_ft *gpn_ft, |
| 551 | struct zfcp_adapter *adapter, int max_entries) |
Swen Schillig | cc8c282 | 2008-06-10 18:21:00 +0200 | [diff] [blame] | 552 | { |
Christof Schmitt | 7c7dc19 | 2009-11-24 16:54:13 +0100 | [diff] [blame^] | 553 | struct zfcp_fsf_ct_els *ct = &gpn_ft->ct; |
Swen Schillig | cc8c282 | 2008-06-10 18:21:00 +0200 | [diff] [blame] | 554 | struct scatterlist *sg = gpn_ft->sg_resp; |
Christof Schmitt | dbf5dfe | 2009-11-24 16:54:10 +0100 | [diff] [blame] | 555 | struct fc_ct_hdr *hdr = sg_virt(sg); |
| 556 | struct fc_gpn_ft_resp *acc = sg_virt(sg); |
Swen Schillig | cc8c282 | 2008-06-10 18:21:00 +0200 | [diff] [blame] | 557 | struct zfcp_port *port, *tmp; |
Swen Schillig | ecf0c77 | 2009-11-24 16:53:58 +0100 | [diff] [blame] | 558 | unsigned long flags; |
Swen Schillig | f3450c7 | 2009-11-24 16:53:59 +0100 | [diff] [blame] | 559 | LIST_HEAD(remove_lh); |
Swen Schillig | cc8c282 | 2008-06-10 18:21:00 +0200 | [diff] [blame] | 560 | u32 d_id; |
Christof Schmitt | 47f7bba | 2008-08-21 13:43:33 +0200 | [diff] [blame] | 561 | int ret = 0, x, last = 0; |
Swen Schillig | cc8c282 | 2008-06-10 18:21:00 +0200 | [diff] [blame] | 562 | |
| 563 | if (ct->status) |
| 564 | return -EIO; |
| 565 | |
Christof Schmitt | dbf5dfe | 2009-11-24 16:54:10 +0100 | [diff] [blame] | 566 | if (hdr->ct_cmd != FC_FS_ACC) { |
| 567 | if (hdr->ct_reason == FC_BA_RJT_UNABLE) |
Swen Schillig | cc8c282 | 2008-06-10 18:21:00 +0200 | [diff] [blame] | 568 | return -EAGAIN; /* might be a temporary condition */ |
| 569 | return -EIO; |
| 570 | } |
| 571 | |
Christof Schmitt | dbf5dfe | 2009-11-24 16:54:10 +0100 | [diff] [blame] | 572 | if (hdr->ct_mr_size) { |
Christof Schmitt | 39eb7e9 | 2008-12-19 16:57:01 +0100 | [diff] [blame] | 573 | dev_warn(&adapter->ccw_device->dev, |
| 574 | "The name server reported %d words residual data\n", |
Christof Schmitt | dbf5dfe | 2009-11-24 16:54:10 +0100 | [diff] [blame] | 575 | hdr->ct_mr_size); |
Swen Schillig | cc8c282 | 2008-06-10 18:21:00 +0200 | [diff] [blame] | 576 | return -E2BIG; |
Christof Schmitt | 39eb7e9 | 2008-12-19 16:57:01 +0100 | [diff] [blame] | 577 | } |
Swen Schillig | cc8c282 | 2008-06-10 18:21:00 +0200 | [diff] [blame] | 578 | |
Swen Schillig | cc8c282 | 2008-06-10 18:21:00 +0200 | [diff] [blame] | 579 | /* first entry is the header */ |
Christof Schmitt | 39eb7e9 | 2008-12-19 16:57:01 +0100 | [diff] [blame] | 580 | for (x = 1; x < max_entries && !last; x++) { |
Christof Schmitt | dbf5dfe | 2009-11-24 16:54:10 +0100 | [diff] [blame] | 581 | if (x % (ZFCP_FC_GPN_FT_ENT_PAGE + 1)) |
Swen Schillig | cc8c282 | 2008-06-10 18:21:00 +0200 | [diff] [blame] | 582 | acc++; |
| 583 | else |
| 584 | acc = sg_virt(++sg); |
| 585 | |
Christof Schmitt | dbf5dfe | 2009-11-24 16:54:10 +0100 | [diff] [blame] | 586 | last = acc->fp_flags & FC_NS_FID_LAST; |
| 587 | d_id = ntoh24(acc->fp_fid); |
Swen Schillig | cc8c282 | 2008-06-10 18:21:00 +0200 | [diff] [blame] | 588 | |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 589 | /* don't attach ports with a well known address */ |
Christof Schmitt | dbf5dfe | 2009-11-24 16:54:10 +0100 | [diff] [blame] | 590 | if (d_id >= FC_FID_WELL_KNOWN_BASE) |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 591 | continue; |
Swen Schillig | cc8c282 | 2008-06-10 18:21:00 +0200 | [diff] [blame] | 592 | /* skip the adapter's port and known remote ports */ |
Christof Schmitt | dbf5dfe | 2009-11-24 16:54:10 +0100 | [diff] [blame] | 593 | if (acc->fp_wwpn == fc_host_port_name(adapter->scsi_host)) |
Swen Schillig | cc8c282 | 2008-06-10 18:21:00 +0200 | [diff] [blame] | 594 | continue; |
| 595 | |
Christof Schmitt | dbf5dfe | 2009-11-24 16:54:10 +0100 | [diff] [blame] | 596 | port = zfcp_port_enqueue(adapter, acc->fp_wwpn, |
Swen Schillig | cc8c282 | 2008-06-10 18:21:00 +0200 | [diff] [blame] | 597 | ZFCP_STATUS_COMMON_NOESC, d_id); |
Swen Schillig | ecf0c77 | 2009-11-24 16:53:58 +0100 | [diff] [blame] | 598 | if (!IS_ERR(port)) |
Swen Schillig | 5ffd51a | 2009-03-02 13:09:04 +0100 | [diff] [blame] | 599 | zfcp_erp_port_reopen(port, 0, "fcegpf1", NULL); |
Swen Schillig | ecf0c77 | 2009-11-24 16:53:58 +0100 | [diff] [blame] | 600 | else if (PTR_ERR(port) != -EEXIST) |
| 601 | ret = PTR_ERR(port); |
Swen Schillig | cc8c282 | 2008-06-10 18:21:00 +0200 | [diff] [blame] | 602 | } |
| 603 | |
| 604 | zfcp_erp_wait(adapter); |
Swen Schillig | ecf0c77 | 2009-11-24 16:53:58 +0100 | [diff] [blame] | 605 | write_lock_irqsave(&adapter->port_list_lock, flags); |
| 606 | list_for_each_entry_safe(port, tmp, &adapter->port_list, list) |
Swen Schillig | f3450c7 | 2009-11-24 16:53:59 +0100 | [diff] [blame] | 607 | zfcp_fc_validate_port(port, &remove_lh); |
Swen Schillig | ecf0c77 | 2009-11-24 16:53:58 +0100 | [diff] [blame] | 608 | write_unlock_irqrestore(&adapter->port_list_lock, flags); |
Swen Schillig | f3450c7 | 2009-11-24 16:53:59 +0100 | [diff] [blame] | 609 | |
| 610 | list_for_each_entry_safe(port, tmp, &remove_lh, list) { |
| 611 | zfcp_erp_port_shutdown(port, 0, "fcegpf2", NULL); |
| 612 | zfcp_device_unregister(&port->sysfs_device, |
| 613 | &zfcp_sysfs_port_attrs); |
| 614 | } |
| 615 | |
Swen Schillig | cc8c282 | 2008-06-10 18:21:00 +0200 | [diff] [blame] | 616 | return ret; |
| 617 | } |
| 618 | |
| 619 | /** |
Swen Schillig | 6f53a2d | 2009-08-18 15:43:23 +0200 | [diff] [blame] | 620 | * zfcp_fc_scan_ports - scan remote ports and attach new ports |
Swen Schillig | 9eae07e | 2009-11-24 16:54:06 +0100 | [diff] [blame] | 621 | * @work: reference to scheduled work |
Swen Schillig | cc8c282 | 2008-06-10 18:21:00 +0200 | [diff] [blame] | 622 | */ |
Swen Schillig | 9eae07e | 2009-11-24 16:54:06 +0100 | [diff] [blame] | 623 | void zfcp_fc_scan_ports(struct work_struct *work) |
Swen Schillig | cc8c282 | 2008-06-10 18:21:00 +0200 | [diff] [blame] | 624 | { |
Swen Schillig | 9eae07e | 2009-11-24 16:54:06 +0100 | [diff] [blame] | 625 | struct zfcp_adapter *adapter = container_of(work, struct zfcp_adapter, |
| 626 | scan_work); |
Swen Schillig | cc8c282 | 2008-06-10 18:21:00 +0200 | [diff] [blame] | 627 | int ret, i; |
Christof Schmitt | dbf5dfe | 2009-11-24 16:54:10 +0100 | [diff] [blame] | 628 | struct zfcp_fc_gpn_ft *gpn_ft; |
Christof Schmitt | 39eb7e9 | 2008-12-19 16:57:01 +0100 | [diff] [blame] | 629 | int chain, max_entries, buf_num, max_bytes; |
| 630 | |
| 631 | chain = adapter->adapter_features & FSF_FEATURE_ELS_CT_CHAINED_SBALS; |
Christof Schmitt | dbf5dfe | 2009-11-24 16:54:10 +0100 | [diff] [blame] | 632 | buf_num = chain ? ZFCP_FC_GPN_FT_NUM_BUFS : 1; |
| 633 | max_entries = chain ? ZFCP_FC_GPN_FT_MAX_ENT : ZFCP_FC_GPN_FT_ENT_PAGE; |
| 634 | max_bytes = chain ? ZFCP_FC_GPN_FT_MAX_SIZE : ZFCP_FC_CT_SIZE_PAGE; |
Swen Schillig | cc8c282 | 2008-06-10 18:21:00 +0200 | [diff] [blame] | 635 | |
Swen Schillig | 306b6ed | 2009-04-17 15:08:02 +0200 | [diff] [blame] | 636 | if (fc_host_port_type(adapter->scsi_host) != FC_PORTTYPE_NPORT && |
| 637 | fc_host_port_type(adapter->scsi_host) != FC_PORTTYPE_NPIV) |
Swen Schillig | 9eae07e | 2009-11-24 16:54:06 +0100 | [diff] [blame] | 638 | return; |
Swen Schillig | cc8c282 | 2008-06-10 18:21:00 +0200 | [diff] [blame] | 639 | |
Swen Schillig | 9eae07e | 2009-11-24 16:54:06 +0100 | [diff] [blame] | 640 | if (zfcp_fc_wka_port_get(&adapter->gs->ds)) |
| 641 | return; |
Swen Schillig | cc8c282 | 2008-06-10 18:21:00 +0200 | [diff] [blame] | 642 | |
Christof Schmitt | 39eb7e9 | 2008-12-19 16:57:01 +0100 | [diff] [blame] | 643 | gpn_ft = zfcp_alloc_sg_env(buf_num); |
Swen Schillig | 9eae07e | 2009-11-24 16:54:06 +0100 | [diff] [blame] | 644 | if (!gpn_ft) |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 645 | goto out; |
Swen Schillig | cc8c282 | 2008-06-10 18:21:00 +0200 | [diff] [blame] | 646 | |
| 647 | for (i = 0; i < 3; i++) { |
Swen Schillig | 6f53a2d | 2009-08-18 15:43:23 +0200 | [diff] [blame] | 648 | ret = zfcp_fc_send_gpn_ft(gpn_ft, adapter, max_bytes); |
Swen Schillig | cc8c282 | 2008-06-10 18:21:00 +0200 | [diff] [blame] | 649 | if (!ret) { |
Christof Schmitt | 7c7dc19 | 2009-11-24 16:54:13 +0100 | [diff] [blame^] | 650 | ret = zfcp_fc_eval_gpn_ft(gpn_ft, adapter, max_entries); |
Swen Schillig | cc8c282 | 2008-06-10 18:21:00 +0200 | [diff] [blame] | 651 | if (ret == -EAGAIN) |
| 652 | ssleep(1); |
| 653 | else |
| 654 | break; |
| 655 | } |
| 656 | } |
Christof Schmitt | 39eb7e9 | 2008-12-19 16:57:01 +0100 | [diff] [blame] | 657 | zfcp_free_sg_env(gpn_ft, buf_num); |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 658 | out: |
Swen Schillig | 6f53a2d | 2009-08-18 15:43:23 +0200 | [diff] [blame] | 659 | zfcp_fc_wka_port_put(&adapter->gs->ds); |
Swen Schillig | cc8c282 | 2008-06-10 18:21:00 +0200 | [diff] [blame] | 660 | } |
| 661 | |
Christof Schmitt | 7c7dc19 | 2009-11-24 16:54:13 +0100 | [diff] [blame^] | 662 | static void zfcp_fc_ct_els_job_handler(void *data) |
Sven Schuetz | 9d544f2 | 2009-04-06 18:31:47 +0200 | [diff] [blame] | 663 | { |
Christof Schmitt | 7c7dc19 | 2009-11-24 16:54:13 +0100 | [diff] [blame^] | 664 | struct fc_bsg_job *job = data; |
| 665 | struct zfcp_fsf_ct_els *zfcp_ct_els = job->dd_data; |
| 666 | int status = zfcp_ct_els->status; |
| 667 | int reply_status; |
Sven Schuetz | 9d544f2 | 2009-04-06 18:31:47 +0200 | [diff] [blame] | 668 | |
Christof Schmitt | 7c7dc19 | 2009-11-24 16:54:13 +0100 | [diff] [blame^] | 669 | reply_status = status ? FC_CTELS_STATUS_REJECT : FC_CTELS_STATUS_OK; |
| 670 | job->reply->reply_data.ctels_reply.status = reply_status; |
| 671 | job->reply->reply_payload_rcv_len = job->reply_payload.payload_len; |
Sven Schuetz | 9d544f2 | 2009-04-06 18:31:47 +0200 | [diff] [blame] | 672 | job->job_done(job); |
Sven Schuetz | 9d544f2 | 2009-04-06 18:31:47 +0200 | [diff] [blame] | 673 | } |
| 674 | |
Christof Schmitt | 7c7dc19 | 2009-11-24 16:54:13 +0100 | [diff] [blame^] | 675 | static int zfcp_fc_exec_els_job(struct fc_bsg_job *job, |
| 676 | struct zfcp_adapter *adapter) |
Sven Schuetz | 9d544f2 | 2009-04-06 18:31:47 +0200 | [diff] [blame] | 677 | { |
Christof Schmitt | 7c7dc19 | 2009-11-24 16:54:13 +0100 | [diff] [blame^] | 678 | struct zfcp_fsf_ct_els *els = job->dd_data; |
Sven Schuetz | 9d544f2 | 2009-04-06 18:31:47 +0200 | [diff] [blame] | 679 | struct fc_rport *rport = job->rport; |
Sven Schuetz | 9d544f2 | 2009-04-06 18:31:47 +0200 | [diff] [blame] | 680 | struct zfcp_port *port; |
Christof Schmitt | 7c7dc19 | 2009-11-24 16:54:13 +0100 | [diff] [blame^] | 681 | u32 d_id; |
Sven Schuetz | 9d544f2 | 2009-04-06 18:31:47 +0200 | [diff] [blame] | 682 | |
Sven Schuetz | 9d544f2 | 2009-04-06 18:31:47 +0200 | [diff] [blame] | 683 | if (rport) { |
Swen Schillig | ea945ff | 2009-08-18 15:43:24 +0200 | [diff] [blame] | 684 | port = zfcp_get_port_by_wwpn(adapter, rport->port_name); |
Christof Schmitt | 7c7dc19 | 2009-11-24 16:54:13 +0100 | [diff] [blame^] | 685 | if (!port) |
Sven Schuetz | 9d544f2 | 2009-04-06 18:31:47 +0200 | [diff] [blame] | 686 | return -EINVAL; |
Swen Schillig | ecf0c77 | 2009-11-24 16:53:58 +0100 | [diff] [blame] | 687 | |
Christof Schmitt | 7c7dc19 | 2009-11-24 16:54:13 +0100 | [diff] [blame^] | 688 | d_id = port->d_id; |
Swen Schillig | f3450c7 | 2009-11-24 16:53:59 +0100 | [diff] [blame] | 689 | put_device(&port->sysfs_device); |
Christof Schmitt | 7c7dc19 | 2009-11-24 16:54:13 +0100 | [diff] [blame^] | 690 | } else |
| 691 | d_id = ntoh24(job->request->rqst_data.h_els.port_id); |
Sven Schuetz | 9d544f2 | 2009-04-06 18:31:47 +0200 | [diff] [blame] | 692 | |
Christof Schmitt | 7c7dc19 | 2009-11-24 16:54:13 +0100 | [diff] [blame^] | 693 | return zfcp_fsf_send_els(adapter, d_id, els); |
Sven Schuetz | 9d544f2 | 2009-04-06 18:31:47 +0200 | [diff] [blame] | 694 | } |
| 695 | |
Christof Schmitt | 7c7dc19 | 2009-11-24 16:54:13 +0100 | [diff] [blame^] | 696 | static int zfcp_fc_exec_ct_job(struct fc_bsg_job *job, |
| 697 | struct zfcp_adapter *adapter) |
Sven Schuetz | 9d544f2 | 2009-04-06 18:31:47 +0200 | [diff] [blame] | 698 | { |
| 699 | int ret; |
| 700 | u8 gs_type; |
Christof Schmitt | 7c7dc19 | 2009-11-24 16:54:13 +0100 | [diff] [blame^] | 701 | struct zfcp_fsf_ct_els *ct = job->dd_data; |
| 702 | struct zfcp_fc_wka_port *wka_port; |
Sven Schuetz | 9d544f2 | 2009-04-06 18:31:47 +0200 | [diff] [blame] | 703 | u32 preamble_word1; |
| 704 | |
Sven Schuetz | 9d544f2 | 2009-04-06 18:31:47 +0200 | [diff] [blame] | 705 | preamble_word1 = job->request->rqst_data.r_ct.preamble_word1; |
| 706 | gs_type = (preamble_word1 & 0xff000000) >> 24; |
| 707 | |
| 708 | switch (gs_type) { |
| 709 | case FC_FST_ALIAS: |
Christof Schmitt | 7c7dc19 | 2009-11-24 16:54:13 +0100 | [diff] [blame^] | 710 | wka_port = &adapter->gs->as; |
Sven Schuetz | 9d544f2 | 2009-04-06 18:31:47 +0200 | [diff] [blame] | 711 | break; |
| 712 | case FC_FST_MGMT: |
Christof Schmitt | 7c7dc19 | 2009-11-24 16:54:13 +0100 | [diff] [blame^] | 713 | wka_port = &adapter->gs->ms; |
Sven Schuetz | 9d544f2 | 2009-04-06 18:31:47 +0200 | [diff] [blame] | 714 | break; |
| 715 | case FC_FST_TIME: |
Christof Schmitt | 7c7dc19 | 2009-11-24 16:54:13 +0100 | [diff] [blame^] | 716 | wka_port = &adapter->gs->ts; |
Sven Schuetz | 9d544f2 | 2009-04-06 18:31:47 +0200 | [diff] [blame] | 717 | break; |
| 718 | case FC_FST_DIR: |
Christof Schmitt | 7c7dc19 | 2009-11-24 16:54:13 +0100 | [diff] [blame^] | 719 | wka_port = &adapter->gs->ds; |
Sven Schuetz | 9d544f2 | 2009-04-06 18:31:47 +0200 | [diff] [blame] | 720 | break; |
| 721 | default: |
Sven Schuetz | 9d544f2 | 2009-04-06 18:31:47 +0200 | [diff] [blame] | 722 | return -EINVAL; /* no such service */ |
| 723 | } |
| 724 | |
Christof Schmitt | 7c7dc19 | 2009-11-24 16:54:13 +0100 | [diff] [blame^] | 725 | ret = zfcp_fc_wka_port_get(wka_port); |
| 726 | if (ret) |
Sven Schuetz | 9d544f2 | 2009-04-06 18:31:47 +0200 | [diff] [blame] | 727 | return ret; |
Sven Schuetz | 9d544f2 | 2009-04-06 18:31:47 +0200 | [diff] [blame] | 728 | |
Christof Schmitt | 7c7dc19 | 2009-11-24 16:54:13 +0100 | [diff] [blame^] | 729 | ret = zfcp_fsf_send_ct(wka_port, ct, NULL); |
| 730 | if (ret) |
| 731 | zfcp_fc_wka_port_put(wka_port); |
Sven Schuetz | 9d544f2 | 2009-04-06 18:31:47 +0200 | [diff] [blame] | 732 | |
Sven Schuetz | 9d544f2 | 2009-04-06 18:31:47 +0200 | [diff] [blame] | 733 | return ret; |
| 734 | } |
Swen Schillig | d5a282a | 2009-08-18 15:43:22 +0200 | [diff] [blame] | 735 | |
Christof Schmitt | 7c7dc19 | 2009-11-24 16:54:13 +0100 | [diff] [blame^] | 736 | int zfcp_fc_exec_bsg_job(struct fc_bsg_job *job) |
| 737 | { |
| 738 | struct Scsi_Host *shost; |
| 739 | struct zfcp_adapter *adapter; |
| 740 | struct zfcp_fsf_ct_els *ct_els = job->dd_data; |
| 741 | |
| 742 | shost = job->rport ? rport_to_shost(job->rport) : job->shost; |
| 743 | adapter = (struct zfcp_adapter *)shost->hostdata[0]; |
| 744 | |
| 745 | if (!(atomic_read(&adapter->status) & ZFCP_STATUS_COMMON_OPEN)) |
| 746 | return -EINVAL; |
| 747 | |
| 748 | ct_els->req = job->request_payload.sg_list; |
| 749 | ct_els->resp = job->reply_payload.sg_list; |
| 750 | ct_els->handler = zfcp_fc_ct_els_job_handler; |
| 751 | ct_els->handler_data = job; |
| 752 | |
| 753 | switch (job->request->msgcode) { |
| 754 | case FC_BSG_RPT_ELS: |
| 755 | case FC_BSG_HST_ELS_NOLOGIN: |
| 756 | return zfcp_fc_exec_els_job(job, adapter); |
| 757 | case FC_BSG_RPT_CT: |
| 758 | case FC_BSG_HST_CT: |
| 759 | return zfcp_fc_exec_ct_job(job, adapter); |
| 760 | default: |
| 761 | return -EINVAL; |
| 762 | } |
| 763 | } |
| 764 | |
Swen Schillig | d5a282a | 2009-08-18 15:43:22 +0200 | [diff] [blame] | 765 | int zfcp_fc_gs_setup(struct zfcp_adapter *adapter) |
| 766 | { |
Christof Schmitt | bd0072e | 2009-11-24 16:54:11 +0100 | [diff] [blame] | 767 | struct zfcp_fc_wka_ports *wka_ports; |
Swen Schillig | d5a282a | 2009-08-18 15:43:22 +0200 | [diff] [blame] | 768 | |
Christof Schmitt | bd0072e | 2009-11-24 16:54:11 +0100 | [diff] [blame] | 769 | wka_ports = kzalloc(sizeof(struct zfcp_fc_wka_ports), GFP_KERNEL); |
Swen Schillig | d5a282a | 2009-08-18 15:43:22 +0200 | [diff] [blame] | 770 | if (!wka_ports) |
| 771 | return -ENOMEM; |
| 772 | |
| 773 | adapter->gs = wka_ports; |
| 774 | zfcp_fc_wka_port_init(&wka_ports->ms, FC_FID_MGMT_SERV, adapter); |
| 775 | zfcp_fc_wka_port_init(&wka_ports->ts, FC_FID_TIME_SERV, adapter); |
| 776 | zfcp_fc_wka_port_init(&wka_ports->ds, FC_FID_DIR_SERV, adapter); |
| 777 | zfcp_fc_wka_port_init(&wka_ports->as, FC_FID_ALIASES, adapter); |
Swen Schillig | d5a282a | 2009-08-18 15:43:22 +0200 | [diff] [blame] | 778 | |
| 779 | return 0; |
| 780 | } |
| 781 | |
| 782 | void zfcp_fc_gs_destroy(struct zfcp_adapter *adapter) |
| 783 | { |
| 784 | kfree(adapter->gs); |
| 785 | adapter->gs = NULL; |
| 786 | } |
| 787 | |