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