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 | * |
Heiko Carstens | a53c8fa | 2012-07-20 11:15:04 +0200 | [diff] [blame] | 6 | * Copyright IBM Corp. 2008, 2010 |
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> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 13 | #include <linux/slab.h> |
Christof Schmitt | 038d944 | 2011-02-22 19:54:48 +0100 | [diff] [blame] | 14 | #include <linux/utsname.h> |
Christof Schmitt | 9d05ce2 | 2009-11-24 16:54:09 +0100 | [diff] [blame] | 15 | #include <scsi/fc/fc_els.h> |
| 16 | #include <scsi/libfc.h> |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 17 | #include "zfcp_ext.h" |
Christof Schmitt | 9d05ce2 | 2009-11-24 16:54:09 +0100 | [diff] [blame] | 18 | #include "zfcp_fc.h" |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 19 | |
Christof Schmitt | 087897e | 2011-02-22 19:54:41 +0100 | [diff] [blame] | 20 | struct kmem_cache *zfcp_fc_req_cache; |
| 21 | |
Christof Schmitt | 9d05ce2 | 2009-11-24 16:54:09 +0100 | [diff] [blame] | 22 | static u32 zfcp_fc_rscn_range_mask[] = { |
| 23 | [ELS_ADDR_FMT_PORT] = 0xFFFFFF, |
| 24 | [ELS_ADDR_FMT_AREA] = 0xFFFF00, |
| 25 | [ELS_ADDR_FMT_DOM] = 0xFF0000, |
| 26 | [ELS_ADDR_FMT_FAB] = 0x000000, |
Christof Schmitt | e0d7fcb | 2008-12-19 16:56:58 +0100 | [diff] [blame] | 27 | }; |
| 28 | |
Steffen Maier | 43f60cb | 2012-09-04 15:23:35 +0200 | [diff] [blame] | 29 | static bool no_auto_port_rescan; |
| 30 | module_param_named(no_auto_port_rescan, no_auto_port_rescan, bool, 0600); |
| 31 | MODULE_PARM_DESC(no_auto_port_rescan, |
| 32 | "no automatic port_rescan (default off)"); |
| 33 | |
| 34 | void zfcp_fc_conditional_port_scan(struct zfcp_adapter *adapter) |
| 35 | { |
| 36 | if (no_auto_port_rescan) |
| 37 | return; |
| 38 | |
| 39 | queue_work(adapter->work_queue, &adapter->scan_work); |
| 40 | } |
| 41 | |
| 42 | void zfcp_fc_inverse_conditional_port_scan(struct zfcp_adapter *adapter) |
| 43 | { |
| 44 | if (!no_auto_port_rescan) |
| 45 | return; |
| 46 | |
| 47 | queue_work(adapter->work_queue, &adapter->scan_work); |
| 48 | } |
| 49 | |
Sven Schuetz | 2d1e547 | 2010-07-16 15:37:39 +0200 | [diff] [blame] | 50 | /** |
| 51 | * zfcp_fc_post_event - post event to userspace via fc_transport |
| 52 | * @work: work struct with enqueued events |
| 53 | */ |
| 54 | void zfcp_fc_post_event(struct work_struct *work) |
| 55 | { |
| 56 | struct zfcp_fc_event *event = NULL, *tmp = NULL; |
| 57 | LIST_HEAD(tmp_lh); |
| 58 | struct zfcp_fc_events *events = container_of(work, |
| 59 | struct zfcp_fc_events, work); |
| 60 | struct zfcp_adapter *adapter = container_of(events, struct zfcp_adapter, |
| 61 | events); |
| 62 | |
| 63 | spin_lock_bh(&events->list_lock); |
| 64 | list_splice_init(&events->list, &tmp_lh); |
| 65 | spin_unlock_bh(&events->list_lock); |
| 66 | |
| 67 | list_for_each_entry_safe(event, tmp, &tmp_lh, list) { |
| 68 | fc_host_post_event(adapter->scsi_host, fc_get_event_number(), |
| 69 | event->code, event->data); |
| 70 | list_del(&event->list); |
| 71 | kfree(event); |
| 72 | } |
| 73 | |
| 74 | } |
| 75 | |
| 76 | /** |
| 77 | * zfcp_fc_enqueue_event - safely enqueue FC HBA API event from irq context |
| 78 | * @adapter: The adapter where to enqueue the event |
| 79 | * @event_code: The event code (as defined in fc_host_event_code in |
| 80 | * scsi_transport_fc.h) |
| 81 | * @event_data: The event data (e.g. n_port page in case of els) |
| 82 | */ |
| 83 | void zfcp_fc_enqueue_event(struct zfcp_adapter *adapter, |
| 84 | enum fc_host_event_code event_code, u32 event_data) |
| 85 | { |
| 86 | struct zfcp_fc_event *event; |
| 87 | |
| 88 | event = kmalloc(sizeof(struct zfcp_fc_event), GFP_ATOMIC); |
| 89 | if (!event) |
| 90 | return; |
| 91 | |
| 92 | event->code = event_code; |
| 93 | event->data = event_data; |
| 94 | |
| 95 | spin_lock(&adapter->events.list_lock); |
| 96 | list_add_tail(&event->list, &adapter->events.list); |
| 97 | spin_unlock(&adapter->events.list_lock); |
| 98 | |
| 99 | queue_work(adapter->work_queue, &adapter->events.work); |
| 100 | } |
| 101 | |
Christof Schmitt | bd0072e | 2009-11-24 16:54:11 +0100 | [diff] [blame] | 102 | 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] | 103 | { |
| 104 | if (mutex_lock_interruptible(&wka_port->mutex)) |
| 105 | return -ERESTARTSYS; |
| 106 | |
Christof Schmitt | bd0072e | 2009-11-24 16:54:11 +0100 | [diff] [blame] | 107 | if (wka_port->status == ZFCP_FC_WKA_PORT_OFFLINE || |
| 108 | wka_port->status == ZFCP_FC_WKA_PORT_CLOSING) { |
| 109 | wka_port->status = ZFCP_FC_WKA_PORT_OPENING; |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 110 | if (zfcp_fsf_open_wka_port(wka_port)) |
Christof Schmitt | bd0072e | 2009-11-24 16:54:11 +0100 | [diff] [blame] | 111 | wka_port->status = ZFCP_FC_WKA_PORT_OFFLINE; |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 112 | } |
| 113 | |
| 114 | mutex_unlock(&wka_port->mutex); |
| 115 | |
Swen Schillig | 27f492c | 2009-07-13 15:06:13 +0200 | [diff] [blame] | 116 | wait_event(wka_port->completion_wq, |
Christof Schmitt | bd0072e | 2009-11-24 16:54:11 +0100 | [diff] [blame] | 117 | wka_port->status == ZFCP_FC_WKA_PORT_ONLINE || |
| 118 | wka_port->status == ZFCP_FC_WKA_PORT_OFFLINE); |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 119 | |
Christof Schmitt | bd0072e | 2009-11-24 16:54:11 +0100 | [diff] [blame] | 120 | if (wka_port->status == ZFCP_FC_WKA_PORT_ONLINE) { |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 121 | atomic_inc(&wka_port->refcount); |
| 122 | return 0; |
| 123 | } |
| 124 | return -EIO; |
| 125 | } |
| 126 | |
Swen Schillig | 6f53a2d | 2009-08-18 15:43:23 +0200 | [diff] [blame] | 127 | static void zfcp_fc_wka_port_offline(struct work_struct *work) |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 128 | { |
Jean Delvare | bf6aede | 2009-04-02 16:56:54 -0700 | [diff] [blame] | 129 | struct delayed_work *dw = to_delayed_work(work); |
Christof Schmitt | bd0072e | 2009-11-24 16:54:11 +0100 | [diff] [blame] | 130 | struct zfcp_fc_wka_port *wka_port = |
| 131 | container_of(dw, struct zfcp_fc_wka_port, work); |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 132 | |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 133 | mutex_lock(&wka_port->mutex); |
| 134 | if ((atomic_read(&wka_port->refcount) != 0) || |
Christof Schmitt | bd0072e | 2009-11-24 16:54:11 +0100 | [diff] [blame] | 135 | (wka_port->status != ZFCP_FC_WKA_PORT_ONLINE)) |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 136 | goto out; |
| 137 | |
Christof Schmitt | bd0072e | 2009-11-24 16:54:11 +0100 | [diff] [blame] | 138 | wka_port->status = ZFCP_FC_WKA_PORT_CLOSING; |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 139 | if (zfcp_fsf_close_wka_port(wka_port)) { |
Christof Schmitt | bd0072e | 2009-11-24 16:54:11 +0100 | [diff] [blame] | 140 | wka_port->status = ZFCP_FC_WKA_PORT_OFFLINE; |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 141 | wake_up(&wka_port->completion_wq); |
| 142 | } |
| 143 | out: |
| 144 | mutex_unlock(&wka_port->mutex); |
| 145 | } |
| 146 | |
Christof Schmitt | bd0072e | 2009-11-24 16:54:11 +0100 | [diff] [blame] | 147 | 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] | 148 | { |
| 149 | if (atomic_dec_return(&wka_port->refcount) != 0) |
| 150 | return; |
Martin Olsson | 19af5cd | 2009-04-23 11:37:37 +0200 | [diff] [blame] | 151 | /* wait 10 milliseconds, other reqs might pop in */ |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 152 | schedule_delayed_work(&wka_port->work, HZ / 100); |
| 153 | } |
| 154 | |
Christof Schmitt | bd0072e | 2009-11-24 16:54:11 +0100 | [diff] [blame] | 155 | 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] | 156 | struct zfcp_adapter *adapter) |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 157 | { |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 158 | init_waitqueue_head(&wka_port->completion_wq); |
| 159 | |
| 160 | wka_port->adapter = adapter; |
Sven Schuetz | 9d544f2 | 2009-04-06 18:31:47 +0200 | [diff] [blame] | 161 | wka_port->d_id = d_id; |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 162 | |
Christof Schmitt | bd0072e | 2009-11-24 16:54:11 +0100 | [diff] [blame] | 163 | wka_port->status = ZFCP_FC_WKA_PORT_OFFLINE; |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 164 | atomic_set(&wka_port->refcount, 0); |
| 165 | mutex_init(&wka_port->mutex); |
Swen Schillig | 6f53a2d | 2009-08-18 15:43:23 +0200 | [diff] [blame] | 166 | INIT_DELAYED_WORK(&wka_port->work, zfcp_fc_wka_port_offline); |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 167 | } |
| 168 | |
Christof Schmitt | bd0072e | 2009-11-24 16:54:11 +0100 | [diff] [blame] | 169 | 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] | 170 | { |
| 171 | cancel_delayed_work_sync(&wka->work); |
| 172 | mutex_lock(&wka->mutex); |
Christof Schmitt | bd0072e | 2009-11-24 16:54:11 +0100 | [diff] [blame] | 173 | wka->status = ZFCP_FC_WKA_PORT_OFFLINE; |
Swen Schillig | 828bc12 | 2009-04-17 15:08:05 +0200 | [diff] [blame] | 174 | mutex_unlock(&wka->mutex); |
| 175 | } |
| 176 | |
Christof Schmitt | bd0072e | 2009-11-24 16:54:11 +0100 | [diff] [blame] | 177 | 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] | 178 | { |
Swen Schillig | f3450c7 | 2009-11-24 16:53:59 +0100 | [diff] [blame] | 179 | if (!gs) |
| 180 | return; |
Christof Schmitt | 55c770f | 2009-08-18 15:43:12 +0200 | [diff] [blame] | 181 | zfcp_fc_wka_port_force_offline(&gs->ms); |
| 182 | zfcp_fc_wka_port_force_offline(&gs->ts); |
| 183 | zfcp_fc_wka_port_force_offline(&gs->ds); |
| 184 | zfcp_fc_wka_port_force_offline(&gs->as); |
Christof Schmitt | 55c770f | 2009-08-18 15:43:12 +0200 | [diff] [blame] | 185 | } |
| 186 | |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 187 | 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] | 188 | struct fc_els_rscn_page *page) |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 189 | { |
| 190 | unsigned long flags; |
Swen Schillig | ecf0c77 | 2009-11-24 16:53:58 +0100 | [diff] [blame] | 191 | struct zfcp_adapter *adapter = fsf_req->adapter; |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 192 | struct zfcp_port *port; |
| 193 | |
Swen Schillig | ecf0c77 | 2009-11-24 16:53:58 +0100 | [diff] [blame] | 194 | read_lock_irqsave(&adapter->port_list_lock, flags); |
| 195 | list_for_each_entry(port, &adapter->port_list, list) { |
Christof Schmitt | 9d05ce2 | 2009-11-24 16:54:09 +0100 | [diff] [blame] | 196 | if ((port->d_id & range) == (ntoh24(page->rscn_fid) & range)) |
Swen Schillig | 6f53a2d | 2009-08-18 15:43:23 +0200 | [diff] [blame] | 197 | zfcp_fc_test_link(port); |
Swen Schillig | ea460a8 | 2009-05-15 13:18:20 +0200 | [diff] [blame] | 198 | if (!port->d_id) |
| 199 | zfcp_erp_port_reopen(port, |
| 200 | ZFCP_STATUS_COMMON_ERP_FAILED, |
Swen Schillig | ea4a3a6 | 2010-12-02 15:16:16 +0100 | [diff] [blame] | 201 | "fcrscn1"); |
Swen Schillig | ea460a8 | 2009-05-15 13:18:20 +0200 | [diff] [blame] | 202 | } |
Swen Schillig | ecf0c77 | 2009-11-24 16:53:58 +0100 | [diff] [blame] | 203 | read_unlock_irqrestore(&adapter->port_list_lock, flags); |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 204 | } |
| 205 | |
| 206 | static void zfcp_fc_incoming_rscn(struct zfcp_fsf_req *fsf_req) |
| 207 | { |
| 208 | struct fsf_status_read_buffer *status_buffer = (void *)fsf_req->data; |
Christof Schmitt | 9d05ce2 | 2009-11-24 16:54:09 +0100 | [diff] [blame] | 209 | struct fc_els_rscn *head; |
| 210 | struct fc_els_rscn_page *page; |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 211 | u16 i; |
| 212 | u16 no_entries; |
Christof Schmitt | 9d05ce2 | 2009-11-24 16:54:09 +0100 | [diff] [blame] | 213 | unsigned int afmt; |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 214 | |
Christof Schmitt | 9d05ce2 | 2009-11-24 16:54:09 +0100 | [diff] [blame] | 215 | head = (struct fc_els_rscn *) status_buffer->payload.data; |
| 216 | page = (struct fc_els_rscn_page *) head; |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 217 | |
| 218 | /* see FC-FS */ |
Christof Schmitt | 9d05ce2 | 2009-11-24 16:54:09 +0100 | [diff] [blame] | 219 | no_entries = head->rscn_plen / sizeof(struct fc_els_rscn_page); |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 220 | |
| 221 | for (i = 1; i < no_entries; i++) { |
| 222 | /* skip head and start with 1st element */ |
Christof Schmitt | 9d05ce2 | 2009-11-24 16:54:09 +0100 | [diff] [blame] | 223 | page++; |
| 224 | afmt = page->rscn_page_flags & ELS_RSCN_ADDR_FMT_MASK; |
| 225 | _zfcp_fc_incoming_rscn(fsf_req, zfcp_fc_rscn_range_mask[afmt], |
| 226 | page); |
Sven Schuetz | 2d1e547 | 2010-07-16 15:37:39 +0200 | [diff] [blame] | 227 | zfcp_fc_enqueue_event(fsf_req->adapter, FCH_EVT_RSCN, |
| 228 | *(u32 *)page); |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 229 | } |
Steffen Maier | 43f60cb | 2012-09-04 15:23:35 +0200 | [diff] [blame] | 230 | zfcp_fc_conditional_port_scan(fsf_req->adapter); |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 231 | } |
| 232 | |
Swen Schillig | 7ba58c9 | 2008-10-01 12:42:18 +0200 | [diff] [blame] | 233 | 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] | 234 | { |
Swen Schillig | ecf0c77 | 2009-11-24 16:53:58 +0100 | [diff] [blame] | 235 | unsigned long flags; |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 236 | struct zfcp_adapter *adapter = req->adapter; |
| 237 | struct zfcp_port *port; |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 238 | |
Swen Schillig | ecf0c77 | 2009-11-24 16:53:58 +0100 | [diff] [blame] | 239 | read_lock_irqsave(&adapter->port_list_lock, flags); |
| 240 | list_for_each_entry(port, &adapter->port_list, list) |
| 241 | if (port->wwpn == wwpn) { |
Swen Schillig | ea4a3a6 | 2010-12-02 15:16:16 +0100 | [diff] [blame] | 242 | zfcp_erp_port_forced_reopen(port, 0, "fciwwp1"); |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 243 | break; |
Swen Schillig | ecf0c77 | 2009-11-24 16:53:58 +0100 | [diff] [blame] | 244 | } |
| 245 | read_unlock_irqrestore(&adapter->port_list_lock, flags); |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 246 | } |
| 247 | |
| 248 | static void zfcp_fc_incoming_plogi(struct zfcp_fsf_req *req) |
| 249 | { |
Christof Schmitt | 9d05ce2 | 2009-11-24 16:54:09 +0100 | [diff] [blame] | 250 | struct fsf_status_read_buffer *status_buffer; |
| 251 | struct fc_els_flogi *plogi; |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 252 | |
Christof Schmitt | 9d05ce2 | 2009-11-24 16:54:09 +0100 | [diff] [blame] | 253 | status_buffer = (struct fsf_status_read_buffer *) req->data; |
| 254 | plogi = (struct fc_els_flogi *) status_buffer->payload.data; |
| 255 | zfcp_fc_incoming_wwpn(req, plogi->fl_wwpn); |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 256 | } |
| 257 | |
| 258 | static void zfcp_fc_incoming_logo(struct zfcp_fsf_req *req) |
| 259 | { |
| 260 | struct fsf_status_read_buffer *status_buffer = |
| 261 | (struct fsf_status_read_buffer *)req->data; |
Christof Schmitt | 9d05ce2 | 2009-11-24 16:54:09 +0100 | [diff] [blame] | 262 | struct fc_els_logo *logo = |
| 263 | (struct fc_els_logo *) status_buffer->payload.data; |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 264 | |
Christof Schmitt | 9d05ce2 | 2009-11-24 16:54:09 +0100 | [diff] [blame] | 265 | zfcp_fc_incoming_wwpn(req, logo->fl_n_port_wwn); |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 266 | } |
| 267 | |
| 268 | /** |
| 269 | * zfcp_fc_incoming_els - handle incoming ELS |
| 270 | * @fsf_req - request which contains incoming ELS |
| 271 | */ |
| 272 | void zfcp_fc_incoming_els(struct zfcp_fsf_req *fsf_req) |
| 273 | { |
| 274 | struct fsf_status_read_buffer *status_buffer = |
| 275 | (struct fsf_status_read_buffer *) fsf_req->data; |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 276 | unsigned int els_type = status_buffer->payload.data[0]; |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 277 | |
Swen Schillig | 2c55b75 | 2010-12-02 15:16:13 +0100 | [diff] [blame] | 278 | zfcp_dbf_san_in_els("fciels1", fsf_req); |
Christof Schmitt | 9d05ce2 | 2009-11-24 16:54:09 +0100 | [diff] [blame] | 279 | if (els_type == ELS_PLOGI) |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 280 | zfcp_fc_incoming_plogi(fsf_req); |
Christof Schmitt | 9d05ce2 | 2009-11-24 16:54:09 +0100 | [diff] [blame] | 281 | else if (els_type == ELS_LOGO) |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 282 | zfcp_fc_incoming_logo(fsf_req); |
Christof Schmitt | 9d05ce2 | 2009-11-24 16:54:09 +0100 | [diff] [blame] | 283 | else if (els_type == ELS_RSCN) |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 284 | zfcp_fc_incoming_rscn(fsf_req); |
| 285 | } |
| 286 | |
Christof Schmitt | fcf7e61 | 2011-02-22 19:54:42 +0100 | [diff] [blame] | 287 | static void zfcp_fc_ns_gid_pn_eval(struct zfcp_fc_req *fc_req) |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 288 | { |
Christof Schmitt | fcf7e61 | 2011-02-22 19:54:42 +0100 | [diff] [blame] | 289 | struct zfcp_fsf_ct_els *ct_els = &fc_req->ct_els; |
| 290 | struct zfcp_fc_gid_pn_rsp *gid_pn_rsp = &fc_req->u.gid_pn.rsp; |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 291 | |
Christof Schmitt | fcf7e61 | 2011-02-22 19:54:42 +0100 | [diff] [blame] | 292 | if (ct_els->status) |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 293 | return; |
Christof Schmitt | fcf7e61 | 2011-02-22 19:54:42 +0100 | [diff] [blame] | 294 | if (gid_pn_rsp->ct_hdr.ct_cmd != FC_FS_ACC) |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 295 | return; |
Christof Schmitt | a5b11dd | 2009-03-02 13:08:54 +0100 | [diff] [blame] | 296 | |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 297 | /* looks like a valid d_id */ |
Christof Schmitt | fcf7e61 | 2011-02-22 19:54:42 +0100 | [diff] [blame] | 298 | ct_els->port->d_id = ntoh24(gid_pn_rsp->gid_pn.fp_fid); |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 299 | } |
| 300 | |
Christof Schmitt | 7c7dc19 | 2009-11-24 16:54:13 +0100 | [diff] [blame] | 301 | static void zfcp_fc_complete(void *data) |
| 302 | { |
| 303 | complete(data); |
| 304 | } |
| 305 | |
Christof Schmitt | fcf7e61 | 2011-02-22 19:54:42 +0100 | [diff] [blame] | 306 | static void zfcp_fc_ct_ns_init(struct fc_ct_hdr *ct_hdr, u16 cmd, u16 mr_size) |
| 307 | { |
| 308 | ct_hdr->ct_rev = FC_CT_REV; |
| 309 | ct_hdr->ct_fs_type = FC_FST_DIR; |
| 310 | ct_hdr->ct_fs_subtype = FC_NS_SUBTYPE; |
| 311 | ct_hdr->ct_cmd = cmd; |
| 312 | ct_hdr->ct_mr_size = mr_size / 4; |
| 313 | } |
| 314 | |
Christof Schmitt | 799b76d | 2009-08-18 15:43:20 +0200 | [diff] [blame] | 315 | static int zfcp_fc_ns_gid_pn_request(struct zfcp_port *port, |
Christof Schmitt | fcf7e61 | 2011-02-22 19:54:42 +0100 | [diff] [blame] | 316 | struct zfcp_fc_req *fc_req) |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 317 | { |
Christof Schmitt | 799b76d | 2009-08-18 15:43:20 +0200 | [diff] [blame] | 318 | struct zfcp_adapter *adapter = port->adapter; |
Christof Schmitt | 7c7dc19 | 2009-11-24 16:54:13 +0100 | [diff] [blame] | 319 | DECLARE_COMPLETION_ONSTACK(completion); |
Christof Schmitt | fcf7e61 | 2011-02-22 19:54:42 +0100 | [diff] [blame] | 320 | struct zfcp_fc_gid_pn_req *gid_pn_req = &fc_req->u.gid_pn.req; |
| 321 | struct zfcp_fc_gid_pn_rsp *gid_pn_rsp = &fc_req->u.gid_pn.rsp; |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 322 | int ret; |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 323 | |
| 324 | /* setup parameters for send generic command */ |
Christof Schmitt | fcf7e61 | 2011-02-22 19:54:42 +0100 | [diff] [blame] | 325 | fc_req->ct_els.port = port; |
| 326 | fc_req->ct_els.handler = zfcp_fc_complete; |
| 327 | fc_req->ct_els.handler_data = &completion; |
| 328 | fc_req->ct_els.req = &fc_req->sg_req; |
| 329 | fc_req->ct_els.resp = &fc_req->sg_rsp; |
| 330 | sg_init_one(&fc_req->sg_req, gid_pn_req, sizeof(*gid_pn_req)); |
| 331 | sg_init_one(&fc_req->sg_rsp, gid_pn_rsp, sizeof(*gid_pn_rsp)); |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 332 | |
Christof Schmitt | fcf7e61 | 2011-02-22 19:54:42 +0100 | [diff] [blame] | 333 | zfcp_fc_ct_ns_init(&gid_pn_req->ct_hdr, |
| 334 | FC_NS_GID_PN, ZFCP_FC_CT_SIZE_PAGE); |
| 335 | gid_pn_req->gid_pn.fn_wwpn = port->wwpn; |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 336 | |
Christof Schmitt | fcf7e61 | 2011-02-22 19:54:42 +0100 | [diff] [blame] | 337 | ret = zfcp_fsf_send_ct(&adapter->gs->ds, &fc_req->ct_els, |
Swen Schillig | 51375ee | 2010-01-14 17:19:02 +0100 | [diff] [blame] | 338 | adapter->pool.gid_pn_req, |
| 339 | ZFCP_FC_CTELS_TMO); |
Christof Schmitt | 7c7dc19 | 2009-11-24 16:54:13 +0100 | [diff] [blame] | 340 | if (!ret) { |
| 341 | wait_for_completion(&completion); |
Christof Schmitt | fcf7e61 | 2011-02-22 19:54:42 +0100 | [diff] [blame] | 342 | zfcp_fc_ns_gid_pn_eval(fc_req); |
Christof Schmitt | 7c7dc19 | 2009-11-24 16:54:13 +0100 | [diff] [blame] | 343 | } |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 344 | return ret; |
| 345 | } |
| 346 | |
| 347 | /** |
Christof Schmitt | fcf7e61 | 2011-02-22 19:54:42 +0100 | [diff] [blame] | 348 | * zfcp_fc_ns_gid_pn - initiate GID_PN nameserver request |
Christof Schmitt | 799b76d | 2009-08-18 15:43:20 +0200 | [diff] [blame] | 349 | * @port: port where GID_PN request is needed |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 350 | * return: -ENOMEM on error, 0 otherwise |
| 351 | */ |
Christof Schmitt | 799b76d | 2009-08-18 15:43:20 +0200 | [diff] [blame] | 352 | static int zfcp_fc_ns_gid_pn(struct zfcp_port *port) |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 353 | { |
| 354 | int ret; |
Christof Schmitt | fcf7e61 | 2011-02-22 19:54:42 +0100 | [diff] [blame] | 355 | struct zfcp_fc_req *fc_req; |
Christof Schmitt | 799b76d | 2009-08-18 15:43:20 +0200 | [diff] [blame] | 356 | struct zfcp_adapter *adapter = port->adapter; |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 357 | |
Christof Schmitt | fcf7e61 | 2011-02-22 19:54:42 +0100 | [diff] [blame] | 358 | fc_req = mempool_alloc(adapter->pool.gid_pn, GFP_ATOMIC); |
| 359 | if (!fc_req) |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 360 | return -ENOMEM; |
| 361 | |
Christof Schmitt | fcf7e61 | 2011-02-22 19:54:42 +0100 | [diff] [blame] | 362 | memset(fc_req, 0, sizeof(*fc_req)); |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 363 | |
Swen Schillig | 6f53a2d | 2009-08-18 15:43:23 +0200 | [diff] [blame] | 364 | ret = zfcp_fc_wka_port_get(&adapter->gs->ds); |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 365 | if (ret) |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 366 | goto out; |
| 367 | |
Christof Schmitt | fcf7e61 | 2011-02-22 19:54:42 +0100 | [diff] [blame] | 368 | ret = zfcp_fc_ns_gid_pn_request(port, fc_req); |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 369 | |
Swen Schillig | 6f53a2d | 2009-08-18 15:43:23 +0200 | [diff] [blame] | 370 | zfcp_fc_wka_port_put(&adapter->gs->ds); |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 371 | out: |
Christof Schmitt | fcf7e61 | 2011-02-22 19:54:42 +0100 | [diff] [blame] | 372 | mempool_free(fc_req, adapter->pool.gid_pn); |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 373 | return ret; |
| 374 | } |
| 375 | |
Christof Schmitt | 799b76d | 2009-08-18 15:43:20 +0200 | [diff] [blame] | 376 | void zfcp_fc_port_did_lookup(struct work_struct *work) |
| 377 | { |
| 378 | int ret; |
| 379 | struct zfcp_port *port = container_of(work, struct zfcp_port, |
| 380 | gid_pn_work); |
| 381 | |
| 382 | ret = zfcp_fc_ns_gid_pn(port); |
| 383 | if (ret) { |
| 384 | /* could not issue gid_pn for some reason */ |
Swen Schillig | ea4a3a6 | 2010-12-02 15:16:16 +0100 | [diff] [blame] | 385 | zfcp_erp_adapter_reopen(port->adapter, 0, "fcgpn_1"); |
Christof Schmitt | 799b76d | 2009-08-18 15:43:20 +0200 | [diff] [blame] | 386 | goto out; |
| 387 | } |
| 388 | |
| 389 | if (!port->d_id) { |
Swen Schillig | edaed85 | 2010-09-08 14:40:01 +0200 | [diff] [blame] | 390 | zfcp_erp_set_port_status(port, ZFCP_STATUS_COMMON_ERP_FAILED); |
Christof Schmitt | 799b76d | 2009-08-18 15:43:20 +0200 | [diff] [blame] | 391 | goto out; |
| 392 | } |
| 393 | |
Swen Schillig | ea4a3a6 | 2010-12-02 15:16:16 +0100 | [diff] [blame] | 394 | zfcp_erp_port_reopen(port, 0, "fcgpn_3"); |
Christof Schmitt | 799b76d | 2009-08-18 15:43:20 +0200 | [diff] [blame] | 395 | out: |
Christof Schmitt | 615f59e | 2010-02-17 11:18:56 +0100 | [diff] [blame] | 396 | put_device(&port->dev); |
Christof Schmitt | 799b76d | 2009-08-18 15:43:20 +0200 | [diff] [blame] | 397 | } |
| 398 | |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 399 | /** |
Christof Schmitt | 934aeb587 | 2009-10-14 11:00:43 +0200 | [diff] [blame] | 400 | * zfcp_fc_trigger_did_lookup - trigger the d_id lookup using a GID_PN request |
| 401 | * @port: The zfcp_port to lookup the d_id for. |
| 402 | */ |
| 403 | void zfcp_fc_trigger_did_lookup(struct zfcp_port *port) |
| 404 | { |
Christof Schmitt | 615f59e | 2010-02-17 11:18:56 +0100 | [diff] [blame] | 405 | get_device(&port->dev); |
Christof Schmitt | 934aeb587 | 2009-10-14 11:00:43 +0200 | [diff] [blame] | 406 | if (!queue_work(port->adapter->work_queue, &port->gid_pn_work)) |
Christof Schmitt | 615f59e | 2010-02-17 11:18:56 +0100 | [diff] [blame] | 407 | put_device(&port->dev); |
Christof Schmitt | 934aeb587 | 2009-10-14 11:00:43 +0200 | [diff] [blame] | 408 | } |
| 409 | |
| 410 | /** |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 411 | * zfcp_fc_plogi_evaluate - evaluate PLOGI playload |
| 412 | * @port: zfcp_port structure |
| 413 | * @plogi: plogi payload |
| 414 | * |
| 415 | * Evaluate PLOGI playload and copy important fields into zfcp_port structure |
| 416 | */ |
Christof Schmitt | 9d05ce2 | 2009-11-24 16:54:09 +0100 | [diff] [blame] | 417 | 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] | 418 | { |
Christof Schmitt | 9d05ce2 | 2009-11-24 16:54:09 +0100 | [diff] [blame] | 419 | if (plogi->fl_wwpn != port->wwpn) { |
| 420 | port->d_id = 0; |
| 421 | dev_warn(&port->adapter->ccw_device->dev, |
| 422 | "A port opened with WWPN 0x%016Lx returned data that " |
| 423 | "identifies it as WWPN 0x%016Lx\n", |
| 424 | (unsigned long long) port->wwpn, |
| 425 | (unsigned long long) plogi->fl_wwpn); |
| 426 | return; |
| 427 | } |
| 428 | |
| 429 | port->wwnn = plogi->fl_wwnn; |
| 430 | port->maxframe_size = plogi->fl_csp.sp_bb_data; |
| 431 | |
| 432 | if (plogi->fl_cssp[0].cp_class & FC_CPC_VALID) |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 433 | port->supported_classes |= FC_COS_CLASS1; |
Christof Schmitt | 9d05ce2 | 2009-11-24 16:54:09 +0100 | [diff] [blame] | 434 | if (plogi->fl_cssp[1].cp_class & FC_CPC_VALID) |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 435 | port->supported_classes |= FC_COS_CLASS2; |
Christof Schmitt | 9d05ce2 | 2009-11-24 16:54:09 +0100 | [diff] [blame] | 436 | if (plogi->fl_cssp[2].cp_class & FC_CPC_VALID) |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 437 | port->supported_classes |= FC_COS_CLASS3; |
Christof Schmitt | 9d05ce2 | 2009-11-24 16:54:09 +0100 | [diff] [blame] | 438 | if (plogi->fl_cssp[3].cp_class & FC_CPC_VALID) |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 439 | port->supported_classes |= FC_COS_CLASS4; |
| 440 | } |
| 441 | |
Christof Schmitt | 7c7dc19 | 2009-11-24 16:54:13 +0100 | [diff] [blame] | 442 | static void zfcp_fc_adisc_handler(void *data) |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 443 | { |
Christof Schmitt | 087897e | 2011-02-22 19:54:41 +0100 | [diff] [blame] | 444 | struct zfcp_fc_req *fc_req = data; |
| 445 | struct zfcp_port *port = fc_req->ct_els.port; |
| 446 | struct fc_els_adisc *adisc_resp = &fc_req->u.adisc.rsp; |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 447 | |
Christof Schmitt | 087897e | 2011-02-22 19:54:41 +0100 | [diff] [blame] | 448 | if (fc_req->ct_els.status) { |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 449 | /* request rejected or timed out */ |
Swen Schillig | 5b43e71 | 2009-04-17 15:08:10 +0200 | [diff] [blame] | 450 | zfcp_erp_port_forced_reopen(port, ZFCP_STATUS_COMMON_ERP_FAILED, |
Swen Schillig | ea4a3a6 | 2010-12-02 15:16:16 +0100 | [diff] [blame] | 451 | "fcadh_1"); |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 452 | goto out; |
| 453 | } |
| 454 | |
| 455 | if (!port->wwnn) |
Christof Schmitt | 9d05ce2 | 2009-11-24 16:54:09 +0100 | [diff] [blame] | 456 | port->wwnn = adisc_resp->adisc_wwnn; |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 457 | |
Christof Schmitt | 9d05ce2 | 2009-11-24 16:54:09 +0100 | [diff] [blame] | 458 | if ((port->wwpn != adisc_resp->adisc_wwpn) || |
Christof Schmitt | a2fa0ae | 2009-03-02 13:09:08 +0100 | [diff] [blame] | 459 | !(atomic_read(&port->status) & ZFCP_STATUS_COMMON_OPEN)) { |
Swen Schillig | 2409549 | 2009-03-02 13:09:07 +0100 | [diff] [blame] | 460 | zfcp_erp_port_reopen(port, ZFCP_STATUS_COMMON_ERP_FAILED, |
Swen Schillig | ea4a3a6 | 2010-12-02 15:16:16 +0100 | [diff] [blame] | 461 | "fcadh_2"); |
Christof Schmitt | a2fa0ae | 2009-03-02 13:09:08 +0100 | [diff] [blame] | 462 | goto out; |
| 463 | } |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 464 | |
Christof Schmitt | a2fa0ae | 2009-03-02 13:09:08 +0100 | [diff] [blame] | 465 | /* port is good, unblock rport without going through erp */ |
| 466 | zfcp_scsi_schedule_rport_register(port); |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 467 | out: |
Christof Schmitt | 14e242e | 2009-08-18 15:43:11 +0200 | [diff] [blame] | 468 | atomic_clear_mask(ZFCP_STATUS_PORT_LINK_TEST, &port->status); |
Christof Schmitt | 615f59e | 2010-02-17 11:18:56 +0100 | [diff] [blame] | 469 | put_device(&port->dev); |
Christof Schmitt | 087897e | 2011-02-22 19:54:41 +0100 | [diff] [blame] | 470 | kmem_cache_free(zfcp_fc_req_cache, fc_req); |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 471 | } |
| 472 | |
| 473 | static int zfcp_fc_adisc(struct zfcp_port *port) |
| 474 | { |
Christof Schmitt | 087897e | 2011-02-22 19:54:41 +0100 | [diff] [blame] | 475 | struct zfcp_fc_req *fc_req; |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 476 | struct zfcp_adapter *adapter = port->adapter; |
Christof Schmitt | 087897e | 2011-02-22 19:54:41 +0100 | [diff] [blame] | 477 | struct Scsi_Host *shost = adapter->scsi_host; |
Christof Schmitt | ee74462 | 2009-11-24 16:54:14 +0100 | [diff] [blame] | 478 | int ret; |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 479 | |
Christof Schmitt | 087897e | 2011-02-22 19:54:41 +0100 | [diff] [blame] | 480 | fc_req = kmem_cache_zalloc(zfcp_fc_req_cache, GFP_ATOMIC); |
| 481 | if (!fc_req) |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 482 | return -ENOMEM; |
| 483 | |
Christof Schmitt | 087897e | 2011-02-22 19:54:41 +0100 | [diff] [blame] | 484 | fc_req->ct_els.port = port; |
| 485 | fc_req->ct_els.req = &fc_req->sg_req; |
| 486 | fc_req->ct_els.resp = &fc_req->sg_rsp; |
| 487 | sg_init_one(&fc_req->sg_req, &fc_req->u.adisc.req, |
Christof Schmitt | 9d05ce2 | 2009-11-24 16:54:09 +0100 | [diff] [blame] | 488 | sizeof(struct fc_els_adisc)); |
Christof Schmitt | 087897e | 2011-02-22 19:54:41 +0100 | [diff] [blame] | 489 | sg_init_one(&fc_req->sg_rsp, &fc_req->u.adisc.rsp, |
Christof Schmitt | 9d05ce2 | 2009-11-24 16:54:09 +0100 | [diff] [blame] | 490 | sizeof(struct fc_els_adisc)); |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 491 | |
Christof Schmitt | 087897e | 2011-02-22 19:54:41 +0100 | [diff] [blame] | 492 | fc_req->ct_els.handler = zfcp_fc_adisc_handler; |
| 493 | fc_req->ct_els.handler_data = fc_req; |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 494 | |
| 495 | /* acc. to FC-FS, hard_nport_id in ADISC should not be set for ports |
| 496 | without FC-AL-2 capability, so we don't set it */ |
Christof Schmitt | 087897e | 2011-02-22 19:54:41 +0100 | [diff] [blame] | 497 | fc_req->u.adisc.req.adisc_wwpn = fc_host_port_name(shost); |
| 498 | fc_req->u.adisc.req.adisc_wwnn = fc_host_node_name(shost); |
| 499 | fc_req->u.adisc.req.adisc_cmd = ELS_ADISC; |
| 500 | hton24(fc_req->u.adisc.req.adisc_port_id, fc_host_port_id(shost)); |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 501 | |
Christof Schmitt | 087897e | 2011-02-22 19:54:41 +0100 | [diff] [blame] | 502 | ret = zfcp_fsf_send_els(adapter, port->d_id, &fc_req->ct_els, |
Swen Schillig | 51375ee | 2010-01-14 17:19:02 +0100 | [diff] [blame] | 503 | ZFCP_FC_CTELS_TMO); |
Christof Schmitt | ee74462 | 2009-11-24 16:54:14 +0100 | [diff] [blame] | 504 | if (ret) |
Christof Schmitt | 087897e | 2011-02-22 19:54:41 +0100 | [diff] [blame] | 505 | kmem_cache_free(zfcp_fc_req_cache, fc_req); |
Christof Schmitt | ee74462 | 2009-11-24 16:54:14 +0100 | [diff] [blame] | 506 | |
| 507 | return ret; |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 508 | } |
| 509 | |
Christof Schmitt | 8fdf30d | 2009-03-02 13:09:01 +0100 | [diff] [blame] | 510 | void zfcp_fc_link_test_work(struct work_struct *work) |
| 511 | { |
| 512 | struct zfcp_port *port = |
| 513 | container_of(work, struct zfcp_port, test_link_work); |
| 514 | int retval; |
| 515 | |
Christof Schmitt | 615f59e | 2010-02-17 11:18:56 +0100 | [diff] [blame] | 516 | get_device(&port->dev); |
Christof Schmitt | a2fa0ae | 2009-03-02 13:09:08 +0100 | [diff] [blame] | 517 | port->rport_task = RPORT_DEL; |
| 518 | zfcp_scsi_rport_work(&port->rport_work); |
| 519 | |
Christof Schmitt | 14e242e | 2009-08-18 15:43:11 +0200 | [diff] [blame] | 520 | /* only issue one test command at one time per port */ |
| 521 | if (atomic_read(&port->status) & ZFCP_STATUS_PORT_LINK_TEST) |
| 522 | goto out; |
| 523 | |
| 524 | atomic_set_mask(ZFCP_STATUS_PORT_LINK_TEST, &port->status); |
| 525 | |
Christof Schmitt | 8fdf30d | 2009-03-02 13:09:01 +0100 | [diff] [blame] | 526 | retval = zfcp_fc_adisc(port); |
| 527 | if (retval == 0) |
| 528 | return; |
| 529 | |
| 530 | /* send of ADISC was not possible */ |
Christof Schmitt | 14e242e | 2009-08-18 15:43:11 +0200 | [diff] [blame] | 531 | atomic_clear_mask(ZFCP_STATUS_PORT_LINK_TEST, &port->status); |
Swen Schillig | ea4a3a6 | 2010-12-02 15:16:16 +0100 | [diff] [blame] | 532 | zfcp_erp_port_forced_reopen(port, 0, "fcltwk1"); |
Christof Schmitt | a2fa0ae | 2009-03-02 13:09:08 +0100 | [diff] [blame] | 533 | |
Christof Schmitt | 14e242e | 2009-08-18 15:43:11 +0200 | [diff] [blame] | 534 | out: |
Christof Schmitt | 615f59e | 2010-02-17 11:18:56 +0100 | [diff] [blame] | 535 | put_device(&port->dev); |
Christof Schmitt | 8fdf30d | 2009-03-02 13:09:01 +0100 | [diff] [blame] | 536 | } |
| 537 | |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 538 | /** |
Swen Schillig | 6f53a2d | 2009-08-18 15:43:23 +0200 | [diff] [blame] | 539 | * zfcp_fc_test_link - lightweight link test procedure |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 540 | * @port: port to be tested |
| 541 | * |
| 542 | * Test status of a link to a remote port using the ELS command ADISC. |
| 543 | * If there is a problem with the remote port, error recovery steps |
| 544 | * will be triggered. |
| 545 | */ |
Swen Schillig | 6f53a2d | 2009-08-18 15:43:23 +0200 | [diff] [blame] | 546 | void zfcp_fc_test_link(struct zfcp_port *port) |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 547 | { |
Christof Schmitt | 615f59e | 2010-02-17 11:18:56 +0100 | [diff] [blame] | 548 | get_device(&port->dev); |
Swen Schillig | 4544683 | 2009-08-18 15:43:17 +0200 | [diff] [blame] | 549 | if (!queue_work(port->adapter->work_queue, &port->test_link_work)) |
Christof Schmitt | 615f59e | 2010-02-17 11:18:56 +0100 | [diff] [blame] | 550 | put_device(&port->dev); |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 551 | } |
Swen Schillig | cc8c282 | 2008-06-10 18:21:00 +0200 | [diff] [blame] | 552 | |
Christof Schmitt | f977322 | 2011-02-22 19:54:43 +0100 | [diff] [blame] | 553 | static struct zfcp_fc_req *zfcp_alloc_sg_env(int buf_num) |
Swen Schillig | cc8c282 | 2008-06-10 18:21:00 +0200 | [diff] [blame] | 554 | { |
Christof Schmitt | f977322 | 2011-02-22 19:54:43 +0100 | [diff] [blame] | 555 | struct zfcp_fc_req *fc_req; |
Swen Schillig | cc8c282 | 2008-06-10 18:21:00 +0200 | [diff] [blame] | 556 | |
Christof Schmitt | f977322 | 2011-02-22 19:54:43 +0100 | [diff] [blame] | 557 | fc_req = kmem_cache_zalloc(zfcp_fc_req_cache, GFP_KERNEL); |
| 558 | if (!fc_req) |
Swen Schillig | cc8c282 | 2008-06-10 18:21:00 +0200 | [diff] [blame] | 559 | return NULL; |
| 560 | |
Christof Schmitt | f977322 | 2011-02-22 19:54:43 +0100 | [diff] [blame] | 561 | if (zfcp_sg_setup_table(&fc_req->sg_rsp, buf_num)) { |
| 562 | kmem_cache_free(zfcp_fc_req_cache, fc_req); |
| 563 | return NULL; |
Swen Schillig | cc8c282 | 2008-06-10 18:21:00 +0200 | [diff] [blame] | 564 | } |
Swen Schillig | cc8c282 | 2008-06-10 18:21:00 +0200 | [diff] [blame] | 565 | |
Christof Schmitt | f977322 | 2011-02-22 19:54:43 +0100 | [diff] [blame] | 566 | sg_init_one(&fc_req->sg_req, &fc_req->u.gpn_ft.req, |
| 567 | sizeof(struct zfcp_fc_gpn_ft_req)); |
| 568 | |
| 569 | return fc_req; |
Swen Schillig | cc8c282 | 2008-06-10 18:21:00 +0200 | [diff] [blame] | 570 | } |
| 571 | |
Christof Schmitt | f977322 | 2011-02-22 19:54:43 +0100 | [diff] [blame] | 572 | static int zfcp_fc_send_gpn_ft(struct zfcp_fc_req *fc_req, |
Swen Schillig | 6f53a2d | 2009-08-18 15:43:23 +0200 | [diff] [blame] | 573 | struct zfcp_adapter *adapter, int max_bytes) |
Swen Schillig | cc8c282 | 2008-06-10 18:21:00 +0200 | [diff] [blame] | 574 | { |
Christof Schmitt | f977322 | 2011-02-22 19:54:43 +0100 | [diff] [blame] | 575 | struct zfcp_fsf_ct_els *ct_els = &fc_req->ct_els; |
| 576 | struct zfcp_fc_gpn_ft_req *req = &fc_req->u.gpn_ft.req; |
Christof Schmitt | 7c7dc19 | 2009-11-24 16:54:13 +0100 | [diff] [blame] | 577 | DECLARE_COMPLETION_ONSTACK(completion); |
Swen Schillig | cc8c282 | 2008-06-10 18:21:00 +0200 | [diff] [blame] | 578 | int ret; |
| 579 | |
Christof Schmitt | f977322 | 2011-02-22 19:54:43 +0100 | [diff] [blame] | 580 | zfcp_fc_ct_ns_init(&req->ct_hdr, FC_NS_GPN_FT, max_bytes); |
Christof Schmitt | dbf5dfe | 2009-11-24 16:54:10 +0100 | [diff] [blame] | 581 | req->gpn_ft.fn_fc4_type = FC_TYPE_FCP; |
Swen Schillig | cc8c282 | 2008-06-10 18:21:00 +0200 | [diff] [blame] | 582 | |
Christof Schmitt | f977322 | 2011-02-22 19:54:43 +0100 | [diff] [blame] | 583 | ct_els->handler = zfcp_fc_complete; |
| 584 | ct_els->handler_data = &completion; |
| 585 | ct_els->req = &fc_req->sg_req; |
| 586 | ct_els->resp = &fc_req->sg_rsp; |
Swen Schillig | cc8c282 | 2008-06-10 18:21:00 +0200 | [diff] [blame] | 587 | |
Christof Schmitt | f977322 | 2011-02-22 19:54:43 +0100 | [diff] [blame] | 588 | ret = zfcp_fsf_send_ct(&adapter->gs->ds, ct_els, NULL, |
Swen Schillig | 51375ee | 2010-01-14 17:19:02 +0100 | [diff] [blame] | 589 | ZFCP_FC_CTELS_TMO); |
Swen Schillig | cc8c282 | 2008-06-10 18:21:00 +0200 | [diff] [blame] | 590 | if (!ret) |
Christof Schmitt | 7c7dc19 | 2009-11-24 16:54:13 +0100 | [diff] [blame] | 591 | wait_for_completion(&completion); |
Swen Schillig | cc8c282 | 2008-06-10 18:21:00 +0200 | [diff] [blame] | 592 | return ret; |
| 593 | } |
| 594 | |
Swen Schillig | f3450c7 | 2009-11-24 16:53:59 +0100 | [diff] [blame] | 595 | 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] | 596 | { |
Martin Petermann | 6ab35c0 | 2009-04-17 15:08:13 +0200 | [diff] [blame] | 597 | if (!(atomic_read(&port->status) & ZFCP_STATUS_COMMON_NOESC)) |
| 598 | return; |
| 599 | |
Swen Schillig | cc8c282 | 2008-06-10 18:21:00 +0200 | [diff] [blame] | 600 | atomic_clear_mask(ZFCP_STATUS_COMMON_NOESC, &port->status); |
| 601 | |
Christof Schmitt | 0406289 | 2008-10-01 12:42:20 +0200 | [diff] [blame] | 602 | if ((port->supported_classes != 0) || |
Swen Schillig | f3450c7 | 2009-11-24 16:53:59 +0100 | [diff] [blame] | 603 | !list_empty(&port->unit_list)) |
Swen Schillig | cc8c282 | 2008-06-10 18:21:00 +0200 | [diff] [blame] | 604 | return; |
Swen Schillig | f3450c7 | 2009-11-24 16:53:59 +0100 | [diff] [blame] | 605 | |
Swen Schillig | f3450c7 | 2009-11-24 16:53:59 +0100 | [diff] [blame] | 606 | list_move_tail(&port->list, lh); |
Swen Schillig | cc8c282 | 2008-06-10 18:21:00 +0200 | [diff] [blame] | 607 | } |
| 608 | |
Christof Schmitt | f977322 | 2011-02-22 19:54:43 +0100 | [diff] [blame] | 609 | static int zfcp_fc_eval_gpn_ft(struct zfcp_fc_req *fc_req, |
Christof Schmitt | 7c7dc19 | 2009-11-24 16:54:13 +0100 | [diff] [blame] | 610 | struct zfcp_adapter *adapter, int max_entries) |
Swen Schillig | cc8c282 | 2008-06-10 18:21:00 +0200 | [diff] [blame] | 611 | { |
Christof Schmitt | f977322 | 2011-02-22 19:54:43 +0100 | [diff] [blame] | 612 | struct zfcp_fsf_ct_els *ct_els = &fc_req->ct_els; |
| 613 | struct scatterlist *sg = &fc_req->sg_rsp; |
Christof Schmitt | dbf5dfe | 2009-11-24 16:54:10 +0100 | [diff] [blame] | 614 | struct fc_ct_hdr *hdr = sg_virt(sg); |
| 615 | struct fc_gpn_ft_resp *acc = sg_virt(sg); |
Swen Schillig | cc8c282 | 2008-06-10 18:21:00 +0200 | [diff] [blame] | 616 | struct zfcp_port *port, *tmp; |
Swen Schillig | ecf0c77 | 2009-11-24 16:53:58 +0100 | [diff] [blame] | 617 | unsigned long flags; |
Swen Schillig | f3450c7 | 2009-11-24 16:53:59 +0100 | [diff] [blame] | 618 | LIST_HEAD(remove_lh); |
Swen Schillig | cc8c282 | 2008-06-10 18:21:00 +0200 | [diff] [blame] | 619 | u32 d_id; |
Christof Schmitt | 47f7bba | 2008-08-21 13:43:33 +0200 | [diff] [blame] | 620 | int ret = 0, x, last = 0; |
Swen Schillig | cc8c282 | 2008-06-10 18:21:00 +0200 | [diff] [blame] | 621 | |
Christof Schmitt | f977322 | 2011-02-22 19:54:43 +0100 | [diff] [blame] | 622 | if (ct_els->status) |
Swen Schillig | cc8c282 | 2008-06-10 18:21:00 +0200 | [diff] [blame] | 623 | return -EIO; |
| 624 | |
Christof Schmitt | dbf5dfe | 2009-11-24 16:54:10 +0100 | [diff] [blame] | 625 | if (hdr->ct_cmd != FC_FS_ACC) { |
| 626 | if (hdr->ct_reason == FC_BA_RJT_UNABLE) |
Swen Schillig | cc8c282 | 2008-06-10 18:21:00 +0200 | [diff] [blame] | 627 | return -EAGAIN; /* might be a temporary condition */ |
| 628 | return -EIO; |
| 629 | } |
| 630 | |
Christof Schmitt | dbf5dfe | 2009-11-24 16:54:10 +0100 | [diff] [blame] | 631 | if (hdr->ct_mr_size) { |
Christof Schmitt | 39eb7e9a | 2008-12-19 16:57:01 +0100 | [diff] [blame] | 632 | dev_warn(&adapter->ccw_device->dev, |
| 633 | "The name server reported %d words residual data\n", |
Christof Schmitt | dbf5dfe | 2009-11-24 16:54:10 +0100 | [diff] [blame] | 634 | hdr->ct_mr_size); |
Swen Schillig | cc8c282 | 2008-06-10 18:21:00 +0200 | [diff] [blame] | 635 | return -E2BIG; |
Christof Schmitt | 39eb7e9a | 2008-12-19 16:57:01 +0100 | [diff] [blame] | 636 | } |
Swen Schillig | cc8c282 | 2008-06-10 18:21:00 +0200 | [diff] [blame] | 637 | |
Swen Schillig | cc8c282 | 2008-06-10 18:21:00 +0200 | [diff] [blame] | 638 | /* first entry is the header */ |
Christof Schmitt | 39eb7e9a | 2008-12-19 16:57:01 +0100 | [diff] [blame] | 639 | for (x = 1; x < max_entries && !last; x++) { |
Christof Schmitt | dbf5dfe | 2009-11-24 16:54:10 +0100 | [diff] [blame] | 640 | if (x % (ZFCP_FC_GPN_FT_ENT_PAGE + 1)) |
Swen Schillig | cc8c282 | 2008-06-10 18:21:00 +0200 | [diff] [blame] | 641 | acc++; |
| 642 | else |
| 643 | acc = sg_virt(++sg); |
| 644 | |
Christof Schmitt | dbf5dfe | 2009-11-24 16:54:10 +0100 | [diff] [blame] | 645 | last = acc->fp_flags & FC_NS_FID_LAST; |
| 646 | d_id = ntoh24(acc->fp_fid); |
Swen Schillig | cc8c282 | 2008-06-10 18:21:00 +0200 | [diff] [blame] | 647 | |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 648 | /* don't attach ports with a well known address */ |
Christof Schmitt | dbf5dfe | 2009-11-24 16:54:10 +0100 | [diff] [blame] | 649 | if (d_id >= FC_FID_WELL_KNOWN_BASE) |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 650 | continue; |
Swen Schillig | cc8c282 | 2008-06-10 18:21:00 +0200 | [diff] [blame] | 651 | /* skip the adapter's port and known remote ports */ |
Christof Schmitt | dbf5dfe | 2009-11-24 16:54:10 +0100 | [diff] [blame] | 652 | if (acc->fp_wwpn == fc_host_port_name(adapter->scsi_host)) |
Swen Schillig | cc8c282 | 2008-06-10 18:21:00 +0200 | [diff] [blame] | 653 | continue; |
| 654 | |
Christof Schmitt | dbf5dfe | 2009-11-24 16:54:10 +0100 | [diff] [blame] | 655 | port = zfcp_port_enqueue(adapter, acc->fp_wwpn, |
Swen Schillig | cc8c282 | 2008-06-10 18:21:00 +0200 | [diff] [blame] | 656 | ZFCP_STATUS_COMMON_NOESC, d_id); |
Swen Schillig | ecf0c77 | 2009-11-24 16:53:58 +0100 | [diff] [blame] | 657 | if (!IS_ERR(port)) |
Swen Schillig | ea4a3a6 | 2010-12-02 15:16:16 +0100 | [diff] [blame] | 658 | zfcp_erp_port_reopen(port, 0, "fcegpf1"); |
Swen Schillig | ecf0c77 | 2009-11-24 16:53:58 +0100 | [diff] [blame] | 659 | else if (PTR_ERR(port) != -EEXIST) |
| 660 | ret = PTR_ERR(port); |
Swen Schillig | cc8c282 | 2008-06-10 18:21:00 +0200 | [diff] [blame] | 661 | } |
| 662 | |
| 663 | zfcp_erp_wait(adapter); |
Swen Schillig | ecf0c77 | 2009-11-24 16:53:58 +0100 | [diff] [blame] | 664 | write_lock_irqsave(&adapter->port_list_lock, flags); |
| 665 | list_for_each_entry_safe(port, tmp, &adapter->port_list, list) |
Swen Schillig | f3450c7 | 2009-11-24 16:53:59 +0100 | [diff] [blame] | 666 | zfcp_fc_validate_port(port, &remove_lh); |
Swen Schillig | ecf0c77 | 2009-11-24 16:53:58 +0100 | [diff] [blame] | 667 | write_unlock_irqrestore(&adapter->port_list_lock, flags); |
Swen Schillig | f3450c7 | 2009-11-24 16:53:59 +0100 | [diff] [blame] | 668 | |
| 669 | list_for_each_entry_safe(port, tmp, &remove_lh, list) { |
Swen Schillig | ea4a3a6 | 2010-12-02 15:16:16 +0100 | [diff] [blame] | 670 | zfcp_erp_port_shutdown(port, 0, "fcegpf2"); |
Sebastian Ott | 83d4e1c | 2013-04-26 16:13:48 +0200 | [diff] [blame] | 671 | device_unregister(&port->dev); |
Swen Schillig | f3450c7 | 2009-11-24 16:53:59 +0100 | [diff] [blame] | 672 | } |
| 673 | |
Swen Schillig | cc8c282 | 2008-06-10 18:21:00 +0200 | [diff] [blame] | 674 | return ret; |
| 675 | } |
| 676 | |
| 677 | /** |
Swen Schillig | 6f53a2d | 2009-08-18 15:43:23 +0200 | [diff] [blame] | 678 | * zfcp_fc_scan_ports - scan remote ports and attach new ports |
Swen Schillig | 9eae07e | 2009-11-24 16:54:06 +0100 | [diff] [blame] | 679 | * @work: reference to scheduled work |
Swen Schillig | cc8c282 | 2008-06-10 18:21:00 +0200 | [diff] [blame] | 680 | */ |
Swen Schillig | 9eae07e | 2009-11-24 16:54:06 +0100 | [diff] [blame] | 681 | void zfcp_fc_scan_ports(struct work_struct *work) |
Swen Schillig | cc8c282 | 2008-06-10 18:21:00 +0200 | [diff] [blame] | 682 | { |
Swen Schillig | 9eae07e | 2009-11-24 16:54:06 +0100 | [diff] [blame] | 683 | struct zfcp_adapter *adapter = container_of(work, struct zfcp_adapter, |
| 684 | scan_work); |
Swen Schillig | cc8c282 | 2008-06-10 18:21:00 +0200 | [diff] [blame] | 685 | int ret, i; |
Christof Schmitt | f977322 | 2011-02-22 19:54:43 +0100 | [diff] [blame] | 686 | struct zfcp_fc_req *fc_req; |
Christof Schmitt | 39eb7e9a | 2008-12-19 16:57:01 +0100 | [diff] [blame] | 687 | int chain, max_entries, buf_num, max_bytes; |
| 688 | |
| 689 | chain = adapter->adapter_features & FSF_FEATURE_ELS_CT_CHAINED_SBALS; |
Christof Schmitt | dbf5dfe | 2009-11-24 16:54:10 +0100 | [diff] [blame] | 690 | buf_num = chain ? ZFCP_FC_GPN_FT_NUM_BUFS : 1; |
| 691 | max_entries = chain ? ZFCP_FC_GPN_FT_MAX_ENT : ZFCP_FC_GPN_FT_ENT_PAGE; |
| 692 | 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] | 693 | |
Swen Schillig | 306b6ed | 2009-04-17 15:08:02 +0200 | [diff] [blame] | 694 | if (fc_host_port_type(adapter->scsi_host) != FC_PORTTYPE_NPORT && |
| 695 | fc_host_port_type(adapter->scsi_host) != FC_PORTTYPE_NPIV) |
Swen Schillig | 9eae07e | 2009-11-24 16:54:06 +0100 | [diff] [blame] | 696 | return; |
Swen Schillig | cc8c282 | 2008-06-10 18:21:00 +0200 | [diff] [blame] | 697 | |
Swen Schillig | 9eae07e | 2009-11-24 16:54:06 +0100 | [diff] [blame] | 698 | if (zfcp_fc_wka_port_get(&adapter->gs->ds)) |
| 699 | return; |
Swen Schillig | cc8c282 | 2008-06-10 18:21:00 +0200 | [diff] [blame] | 700 | |
Christof Schmitt | f977322 | 2011-02-22 19:54:43 +0100 | [diff] [blame] | 701 | fc_req = zfcp_alloc_sg_env(buf_num); |
| 702 | if (!fc_req) |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 703 | goto out; |
Swen Schillig | cc8c282 | 2008-06-10 18:21:00 +0200 | [diff] [blame] | 704 | |
| 705 | for (i = 0; i < 3; i++) { |
Christof Schmitt | f977322 | 2011-02-22 19:54:43 +0100 | [diff] [blame] | 706 | ret = zfcp_fc_send_gpn_ft(fc_req, adapter, max_bytes); |
Swen Schillig | cc8c282 | 2008-06-10 18:21:00 +0200 | [diff] [blame] | 707 | if (!ret) { |
Christof Schmitt | f977322 | 2011-02-22 19:54:43 +0100 | [diff] [blame] | 708 | ret = zfcp_fc_eval_gpn_ft(fc_req, adapter, max_entries); |
Swen Schillig | cc8c282 | 2008-06-10 18:21:00 +0200 | [diff] [blame] | 709 | if (ret == -EAGAIN) |
| 710 | ssleep(1); |
| 711 | else |
| 712 | break; |
| 713 | } |
| 714 | } |
Christof Schmitt | f977322 | 2011-02-22 19:54:43 +0100 | [diff] [blame] | 715 | zfcp_sg_free_table(&fc_req->sg_rsp, buf_num); |
| 716 | kmem_cache_free(zfcp_fc_req_cache, fc_req); |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 717 | out: |
Swen Schillig | 6f53a2d | 2009-08-18 15:43:23 +0200 | [diff] [blame] | 718 | zfcp_fc_wka_port_put(&adapter->gs->ds); |
Swen Schillig | cc8c282 | 2008-06-10 18:21:00 +0200 | [diff] [blame] | 719 | } |
| 720 | |
Christof Schmitt | 038d944 | 2011-02-22 19:54:48 +0100 | [diff] [blame] | 721 | static int zfcp_fc_gspn(struct zfcp_adapter *adapter, |
| 722 | struct zfcp_fc_req *fc_req) |
| 723 | { |
| 724 | DECLARE_COMPLETION_ONSTACK(completion); |
| 725 | char devno[] = "DEVNO:"; |
| 726 | struct zfcp_fsf_ct_els *ct_els = &fc_req->ct_els; |
| 727 | struct zfcp_fc_gspn_req *gspn_req = &fc_req->u.gspn.req; |
| 728 | struct zfcp_fc_gspn_rsp *gspn_rsp = &fc_req->u.gspn.rsp; |
| 729 | int ret; |
| 730 | |
| 731 | zfcp_fc_ct_ns_init(&gspn_req->ct_hdr, FC_NS_GSPN_ID, |
| 732 | FC_SYMBOLIC_NAME_SIZE); |
| 733 | hton24(gspn_req->gspn.fp_fid, fc_host_port_id(adapter->scsi_host)); |
| 734 | |
| 735 | sg_init_one(&fc_req->sg_req, gspn_req, sizeof(*gspn_req)); |
| 736 | sg_init_one(&fc_req->sg_rsp, gspn_rsp, sizeof(*gspn_rsp)); |
| 737 | |
| 738 | ct_els->handler = zfcp_fc_complete; |
| 739 | ct_els->handler_data = &completion; |
| 740 | ct_els->req = &fc_req->sg_req; |
| 741 | ct_els->resp = &fc_req->sg_rsp; |
| 742 | |
| 743 | ret = zfcp_fsf_send_ct(&adapter->gs->ds, ct_els, NULL, |
| 744 | ZFCP_FC_CTELS_TMO); |
| 745 | if (ret) |
| 746 | return ret; |
| 747 | |
| 748 | wait_for_completion(&completion); |
| 749 | if (ct_els->status) |
| 750 | return ct_els->status; |
| 751 | |
| 752 | if (fc_host_port_type(adapter->scsi_host) == FC_PORTTYPE_NPIV && |
| 753 | !(strstr(gspn_rsp->gspn.fp_name, devno))) |
| 754 | snprintf(fc_host_symbolic_name(adapter->scsi_host), |
| 755 | FC_SYMBOLIC_NAME_SIZE, "%s%s %s NAME: %s", |
| 756 | gspn_rsp->gspn.fp_name, devno, |
| 757 | dev_name(&adapter->ccw_device->dev), |
| 758 | init_utsname()->nodename); |
| 759 | else |
| 760 | strlcpy(fc_host_symbolic_name(adapter->scsi_host), |
| 761 | gspn_rsp->gspn.fp_name, FC_SYMBOLIC_NAME_SIZE); |
| 762 | |
| 763 | return 0; |
| 764 | } |
| 765 | |
| 766 | static void zfcp_fc_rspn(struct zfcp_adapter *adapter, |
| 767 | struct zfcp_fc_req *fc_req) |
| 768 | { |
| 769 | DECLARE_COMPLETION_ONSTACK(completion); |
| 770 | struct Scsi_Host *shost = adapter->scsi_host; |
| 771 | struct zfcp_fsf_ct_els *ct_els = &fc_req->ct_els; |
| 772 | struct zfcp_fc_rspn_req *rspn_req = &fc_req->u.rspn.req; |
| 773 | struct fc_ct_hdr *rspn_rsp = &fc_req->u.rspn.rsp; |
| 774 | int ret, len; |
| 775 | |
| 776 | zfcp_fc_ct_ns_init(&rspn_req->ct_hdr, FC_NS_RSPN_ID, |
| 777 | FC_SYMBOLIC_NAME_SIZE); |
| 778 | hton24(rspn_req->rspn.fr_fid.fp_fid, fc_host_port_id(shost)); |
| 779 | len = strlcpy(rspn_req->rspn.fr_name, fc_host_symbolic_name(shost), |
| 780 | FC_SYMBOLIC_NAME_SIZE); |
| 781 | rspn_req->rspn.fr_name_len = len; |
| 782 | |
| 783 | sg_init_one(&fc_req->sg_req, rspn_req, sizeof(*rspn_req)); |
| 784 | sg_init_one(&fc_req->sg_rsp, rspn_rsp, sizeof(*rspn_rsp)); |
| 785 | |
| 786 | ct_els->handler = zfcp_fc_complete; |
| 787 | ct_els->handler_data = &completion; |
| 788 | ct_els->req = &fc_req->sg_req; |
| 789 | ct_els->resp = &fc_req->sg_rsp; |
| 790 | |
| 791 | ret = zfcp_fsf_send_ct(&adapter->gs->ds, ct_els, NULL, |
| 792 | ZFCP_FC_CTELS_TMO); |
| 793 | if (!ret) |
| 794 | wait_for_completion(&completion); |
| 795 | } |
| 796 | |
| 797 | /** |
| 798 | * zfcp_fc_sym_name_update - Retrieve and update the symbolic port name |
| 799 | * @work: ns_up_work of the adapter where to update the symbolic port name |
| 800 | * |
| 801 | * Retrieve the current symbolic port name that may have been set by |
| 802 | * the hardware using the GSPN request and update the fc_host |
| 803 | * symbolic_name sysfs attribute. When running in NPIV mode (and hence |
| 804 | * the port name is unique for this system), update the symbolic port |
| 805 | * name to add Linux specific information and update the FC nameserver |
| 806 | * using the RSPN request. |
| 807 | */ |
| 808 | void zfcp_fc_sym_name_update(struct work_struct *work) |
| 809 | { |
| 810 | struct zfcp_adapter *adapter = container_of(work, struct zfcp_adapter, |
| 811 | ns_up_work); |
| 812 | int ret; |
| 813 | struct zfcp_fc_req *fc_req; |
| 814 | |
| 815 | if (fc_host_port_type(adapter->scsi_host) != FC_PORTTYPE_NPORT && |
| 816 | fc_host_port_type(adapter->scsi_host) != FC_PORTTYPE_NPIV) |
| 817 | return; |
| 818 | |
| 819 | fc_req = kmem_cache_zalloc(zfcp_fc_req_cache, GFP_KERNEL); |
| 820 | if (!fc_req) |
| 821 | return; |
| 822 | |
| 823 | ret = zfcp_fc_wka_port_get(&adapter->gs->ds); |
| 824 | if (ret) |
| 825 | goto out_free; |
| 826 | |
| 827 | ret = zfcp_fc_gspn(adapter, fc_req); |
| 828 | if (ret || fc_host_port_type(adapter->scsi_host) != FC_PORTTYPE_NPIV) |
| 829 | goto out_ds_put; |
| 830 | |
| 831 | memset(fc_req, 0, sizeof(*fc_req)); |
| 832 | zfcp_fc_rspn(adapter, fc_req); |
| 833 | |
| 834 | out_ds_put: |
| 835 | zfcp_fc_wka_port_put(&adapter->gs->ds); |
| 836 | out_free: |
| 837 | kmem_cache_free(zfcp_fc_req_cache, fc_req); |
| 838 | } |
| 839 | |
Christof Schmitt | 7c7dc19 | 2009-11-24 16:54:13 +0100 | [diff] [blame] | 840 | static void zfcp_fc_ct_els_job_handler(void *data) |
Sven Schuetz | 9d544f2 | 2009-04-06 18:31:47 +0200 | [diff] [blame] | 841 | { |
Christof Schmitt | 7c7dc19 | 2009-11-24 16:54:13 +0100 | [diff] [blame] | 842 | struct fc_bsg_job *job = data; |
| 843 | struct zfcp_fsf_ct_els *zfcp_ct_els = job->dd_data; |
Swen Schillig | 7dec9cf | 2010-01-26 17:49:19 +0100 | [diff] [blame] | 844 | struct fc_bsg_reply *jr = job->reply; |
Sven Schuetz | 9d544f2 | 2009-04-06 18:31:47 +0200 | [diff] [blame] | 845 | |
Swen Schillig | 7dec9cf | 2010-01-26 17:49:19 +0100 | [diff] [blame] | 846 | jr->reply_payload_rcv_len = job->reply_payload.payload_len; |
| 847 | jr->reply_data.ctels_reply.status = FC_CTELS_STATUS_OK; |
| 848 | jr->result = zfcp_ct_els->status ? -EIO : 0; |
Sven Schuetz | 9d544f2 | 2009-04-06 18:31:47 +0200 | [diff] [blame] | 849 | job->job_done(job); |
Sven Schuetz | 9d544f2 | 2009-04-06 18:31:47 +0200 | [diff] [blame] | 850 | } |
| 851 | |
Christof Schmitt | f09d545 | 2010-01-13 17:52:36 +0100 | [diff] [blame] | 852 | static struct zfcp_fc_wka_port *zfcp_fc_job_wka_port(struct fc_bsg_job *job) |
| 853 | { |
| 854 | u32 preamble_word1; |
| 855 | u8 gs_type; |
| 856 | struct zfcp_adapter *adapter; |
| 857 | |
| 858 | preamble_word1 = job->request->rqst_data.r_ct.preamble_word1; |
| 859 | gs_type = (preamble_word1 & 0xff000000) >> 24; |
| 860 | |
| 861 | adapter = (struct zfcp_adapter *) job->shost->hostdata[0]; |
| 862 | |
| 863 | switch (gs_type) { |
| 864 | case FC_FST_ALIAS: |
| 865 | return &adapter->gs->as; |
| 866 | case FC_FST_MGMT: |
| 867 | return &adapter->gs->ms; |
| 868 | case FC_FST_TIME: |
| 869 | return &adapter->gs->ts; |
| 870 | break; |
| 871 | case FC_FST_DIR: |
| 872 | return &adapter->gs->ds; |
| 873 | break; |
| 874 | default: |
| 875 | return NULL; |
| 876 | } |
| 877 | } |
| 878 | |
| 879 | static void zfcp_fc_ct_job_handler(void *data) |
| 880 | { |
| 881 | struct fc_bsg_job *job = data; |
| 882 | struct zfcp_fc_wka_port *wka_port; |
| 883 | |
| 884 | wka_port = zfcp_fc_job_wka_port(job); |
| 885 | zfcp_fc_wka_port_put(wka_port); |
| 886 | |
| 887 | zfcp_fc_ct_els_job_handler(data); |
| 888 | } |
| 889 | |
Christof Schmitt | 7c7dc19 | 2009-11-24 16:54:13 +0100 | [diff] [blame] | 890 | static int zfcp_fc_exec_els_job(struct fc_bsg_job *job, |
| 891 | struct zfcp_adapter *adapter) |
Sven Schuetz | 9d544f2 | 2009-04-06 18:31:47 +0200 | [diff] [blame] | 892 | { |
Christof Schmitt | 7c7dc19 | 2009-11-24 16:54:13 +0100 | [diff] [blame] | 893 | struct zfcp_fsf_ct_els *els = job->dd_data; |
Sven Schuetz | 9d544f2 | 2009-04-06 18:31:47 +0200 | [diff] [blame] | 894 | struct fc_rport *rport = job->rport; |
Sven Schuetz | 9d544f2 | 2009-04-06 18:31:47 +0200 | [diff] [blame] | 895 | struct zfcp_port *port; |
Christof Schmitt | 7c7dc19 | 2009-11-24 16:54:13 +0100 | [diff] [blame] | 896 | u32 d_id; |
Sven Schuetz | 9d544f2 | 2009-04-06 18:31:47 +0200 | [diff] [blame] | 897 | |
Sven Schuetz | 9d544f2 | 2009-04-06 18:31:47 +0200 | [diff] [blame] | 898 | if (rport) { |
Swen Schillig | ea945ff | 2009-08-18 15:43:24 +0200 | [diff] [blame] | 899 | port = zfcp_get_port_by_wwpn(adapter, rport->port_name); |
Christof Schmitt | 7c7dc19 | 2009-11-24 16:54:13 +0100 | [diff] [blame] | 900 | if (!port) |
Sven Schuetz | 9d544f2 | 2009-04-06 18:31:47 +0200 | [diff] [blame] | 901 | return -EINVAL; |
Swen Schillig | ecf0c77 | 2009-11-24 16:53:58 +0100 | [diff] [blame] | 902 | |
Christof Schmitt | 7c7dc19 | 2009-11-24 16:54:13 +0100 | [diff] [blame] | 903 | d_id = port->d_id; |
Christof Schmitt | 615f59e | 2010-02-17 11:18:56 +0100 | [diff] [blame] | 904 | put_device(&port->dev); |
Christof Schmitt | 7c7dc19 | 2009-11-24 16:54:13 +0100 | [diff] [blame] | 905 | } else |
| 906 | d_id = ntoh24(job->request->rqst_data.h_els.port_id); |
Sven Schuetz | 9d544f2 | 2009-04-06 18:31:47 +0200 | [diff] [blame] | 907 | |
Christof Schmitt | f09d545 | 2010-01-13 17:52:36 +0100 | [diff] [blame] | 908 | els->handler = zfcp_fc_ct_els_job_handler; |
Swen Schillig | 51375ee | 2010-01-14 17:19:02 +0100 | [diff] [blame] | 909 | return zfcp_fsf_send_els(adapter, d_id, els, job->req->timeout / HZ); |
Sven Schuetz | 9d544f2 | 2009-04-06 18:31:47 +0200 | [diff] [blame] | 910 | } |
| 911 | |
Christof Schmitt | 7c7dc19 | 2009-11-24 16:54:13 +0100 | [diff] [blame] | 912 | static int zfcp_fc_exec_ct_job(struct fc_bsg_job *job, |
| 913 | struct zfcp_adapter *adapter) |
Sven Schuetz | 9d544f2 | 2009-04-06 18:31:47 +0200 | [diff] [blame] | 914 | { |
| 915 | int ret; |
Christof Schmitt | 7c7dc19 | 2009-11-24 16:54:13 +0100 | [diff] [blame] | 916 | struct zfcp_fsf_ct_els *ct = job->dd_data; |
| 917 | struct zfcp_fc_wka_port *wka_port; |
Sven Schuetz | 9d544f2 | 2009-04-06 18:31:47 +0200 | [diff] [blame] | 918 | |
Christof Schmitt | f09d545 | 2010-01-13 17:52:36 +0100 | [diff] [blame] | 919 | wka_port = zfcp_fc_job_wka_port(job); |
| 920 | if (!wka_port) |
| 921 | return -EINVAL; |
Sven Schuetz | 9d544f2 | 2009-04-06 18:31:47 +0200 | [diff] [blame] | 922 | |
Christof Schmitt | 7c7dc19 | 2009-11-24 16:54:13 +0100 | [diff] [blame] | 923 | ret = zfcp_fc_wka_port_get(wka_port); |
| 924 | if (ret) |
Sven Schuetz | 9d544f2 | 2009-04-06 18:31:47 +0200 | [diff] [blame] | 925 | return ret; |
Sven Schuetz | 9d544f2 | 2009-04-06 18:31:47 +0200 | [diff] [blame] | 926 | |
Christof Schmitt | f09d545 | 2010-01-13 17:52:36 +0100 | [diff] [blame] | 927 | ct->handler = zfcp_fc_ct_job_handler; |
Swen Schillig | 51375ee | 2010-01-14 17:19:02 +0100 | [diff] [blame] | 928 | ret = zfcp_fsf_send_ct(wka_port, ct, NULL, job->req->timeout / HZ); |
Christof Schmitt | 7c7dc19 | 2009-11-24 16:54:13 +0100 | [diff] [blame] | 929 | if (ret) |
| 930 | zfcp_fc_wka_port_put(wka_port); |
Sven Schuetz | 9d544f2 | 2009-04-06 18:31:47 +0200 | [diff] [blame] | 931 | |
Sven Schuetz | 9d544f2 | 2009-04-06 18:31:47 +0200 | [diff] [blame] | 932 | return ret; |
| 933 | } |
Swen Schillig | d5a282a | 2009-08-18 15:43:22 +0200 | [diff] [blame] | 934 | |
Christof Schmitt | 7c7dc19 | 2009-11-24 16:54:13 +0100 | [diff] [blame] | 935 | int zfcp_fc_exec_bsg_job(struct fc_bsg_job *job) |
| 936 | { |
| 937 | struct Scsi_Host *shost; |
| 938 | struct zfcp_adapter *adapter; |
| 939 | struct zfcp_fsf_ct_els *ct_els = job->dd_data; |
| 940 | |
| 941 | shost = job->rport ? rport_to_shost(job->rport) : job->shost; |
| 942 | adapter = (struct zfcp_adapter *)shost->hostdata[0]; |
| 943 | |
| 944 | if (!(atomic_read(&adapter->status) & ZFCP_STATUS_COMMON_OPEN)) |
| 945 | return -EINVAL; |
| 946 | |
| 947 | ct_els->req = job->request_payload.sg_list; |
| 948 | ct_els->resp = job->reply_payload.sg_list; |
Christof Schmitt | 7c7dc19 | 2009-11-24 16:54:13 +0100 | [diff] [blame] | 949 | ct_els->handler_data = job; |
| 950 | |
| 951 | switch (job->request->msgcode) { |
| 952 | case FC_BSG_RPT_ELS: |
| 953 | case FC_BSG_HST_ELS_NOLOGIN: |
| 954 | return zfcp_fc_exec_els_job(job, adapter); |
| 955 | case FC_BSG_RPT_CT: |
| 956 | case FC_BSG_HST_CT: |
| 957 | return zfcp_fc_exec_ct_job(job, adapter); |
| 958 | default: |
| 959 | return -EINVAL; |
| 960 | } |
| 961 | } |
| 962 | |
Swen Schillig | 491ca44 | 2010-01-14 17:19:01 +0100 | [diff] [blame] | 963 | int zfcp_fc_timeout_bsg_job(struct fc_bsg_job *job) |
| 964 | { |
| 965 | /* hardware tracks timeout, reset bsg timeout to not interfere */ |
| 966 | return -EAGAIN; |
| 967 | } |
| 968 | |
Swen Schillig | d5a282a | 2009-08-18 15:43:22 +0200 | [diff] [blame] | 969 | int zfcp_fc_gs_setup(struct zfcp_adapter *adapter) |
| 970 | { |
Christof Schmitt | bd0072e | 2009-11-24 16:54:11 +0100 | [diff] [blame] | 971 | struct zfcp_fc_wka_ports *wka_ports; |
Swen Schillig | d5a282a | 2009-08-18 15:43:22 +0200 | [diff] [blame] | 972 | |
Christof Schmitt | bd0072e | 2009-11-24 16:54:11 +0100 | [diff] [blame] | 973 | wka_ports = kzalloc(sizeof(struct zfcp_fc_wka_ports), GFP_KERNEL); |
Swen Schillig | d5a282a | 2009-08-18 15:43:22 +0200 | [diff] [blame] | 974 | if (!wka_ports) |
| 975 | return -ENOMEM; |
| 976 | |
| 977 | adapter->gs = wka_ports; |
| 978 | zfcp_fc_wka_port_init(&wka_ports->ms, FC_FID_MGMT_SERV, adapter); |
| 979 | zfcp_fc_wka_port_init(&wka_ports->ts, FC_FID_TIME_SERV, adapter); |
| 980 | zfcp_fc_wka_port_init(&wka_ports->ds, FC_FID_DIR_SERV, adapter); |
| 981 | zfcp_fc_wka_port_init(&wka_ports->as, FC_FID_ALIASES, adapter); |
Swen Schillig | d5a282a | 2009-08-18 15:43:22 +0200 | [diff] [blame] | 982 | |
| 983 | return 0; |
| 984 | } |
| 985 | |
| 986 | void zfcp_fc_gs_destroy(struct zfcp_adapter *adapter) |
| 987 | { |
| 988 | kfree(adapter->gs); |
| 989 | adapter->gs = NULL; |
| 990 | } |
| 991 | |