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