| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* ------------------------------------------------------------ | 
|  | 2 | * ibmvscsi.c | 
|  | 3 | * (C) Copyright IBM Corporation 1994, 2004 | 
|  | 4 | * Authors: Colin DeVilbiss (devilbis@us.ibm.com) | 
|  | 5 | *          Santiago Leon (santil@us.ibm.com) | 
|  | 6 | *          Dave Boutcher (sleddog@us.ibm.com) | 
|  | 7 | * | 
|  | 8 | * This program is free software; you can redistribute it and/or modify | 
|  | 9 | * it under the terms of the GNU General Public License as published by | 
|  | 10 | * the Free Software Foundation; either version 2 of the License, or | 
|  | 11 | * (at your option) any later version. | 
|  | 12 | * | 
|  | 13 | * This program is distributed in the hope that it will be useful, | 
|  | 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | 
|  | 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
|  | 16 | * GNU General Public License for more details. | 
|  | 17 | * | 
|  | 18 | * You should have received a copy of the GNU General Public License | 
|  | 19 | * along with this program; if not, write to the Free Software | 
|  | 20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 | 
|  | 21 | * USA | 
|  | 22 | * | 
|  | 23 | * ------------------------------------------------------------ | 
|  | 24 | * Emulation of a SCSI host adapter for Virtual I/O devices | 
|  | 25 | * | 
|  | 26 | * This driver supports the SCSI adapter implemented by the IBM | 
|  | 27 | * Power5 firmware.  That SCSI adapter is not a physical adapter, | 
|  | 28 | * but allows Linux SCSI peripheral drivers to directly | 
|  | 29 | * access devices in another logical partition on the physical system. | 
|  | 30 | * | 
|  | 31 | * The virtual adapter(s) are present in the open firmware device | 
|  | 32 | * tree just like real adapters. | 
|  | 33 | * | 
|  | 34 | * One of the capabilities provided on these systems is the ability | 
|  | 35 | * to DMA between partitions.  The architecture states that for VSCSI, | 
|  | 36 | * the server side is allowed to DMA to and from the client.  The client | 
|  | 37 | * is never trusted to DMA to or from the server directly. | 
|  | 38 | * | 
|  | 39 | * Messages are sent between partitions on a "Command/Response Queue" | 
|  | 40 | * (CRQ), which is just a buffer of 16 byte entries in the receiver's | 
|  | 41 | * Senders cannot access the buffer directly, but send messages by | 
|  | 42 | * making a hypervisor call and passing in the 16 bytes.  The hypervisor | 
|  | 43 | * puts the message in the next 16 byte space in round-robbin fashion, | 
|  | 44 | * turns on the high order bit of the message (the valid bit), and | 
|  | 45 | * generates an interrupt to the receiver (if interrupts are turned on.) | 
|  | 46 | * The receiver just turns off the valid bit when they have copied out | 
|  | 47 | * the message. | 
|  | 48 | * | 
|  | 49 | * The VSCSI client builds a SCSI Remote Protocol (SRP) Information Unit | 
|  | 50 | * (IU) (as defined in the T10 standard available at www.t10.org), gets | 
|  | 51 | * a DMA address for the message, and sends it to the server as the | 
|  | 52 | * payload of a CRQ message.  The server DMAs the SRP IU and processes it, | 
|  | 53 | * including doing any additional data transfers.  When it is done, it | 
|  | 54 | * DMAs the SRP response back to the same address as the request came from, | 
|  | 55 | * and sends a CRQ message back to inform the client that the request has | 
|  | 56 | * completed. | 
|  | 57 | * | 
|  | 58 | * Note that some of the underlying infrastructure is different between | 
|  | 59 | * machines conforming to the "RS/6000 Platform Architecture" (RPA) and | 
|  | 60 | * the older iSeries hypervisor models.  To support both, some low level | 
|  | 61 | * routines have been broken out into rpa_vscsi.c and iseries_vscsi.c. | 
|  | 62 | * The Makefile should pick one, not two, not zero, of these. | 
|  | 63 | * | 
|  | 64 | * TODO: This is currently pretty tied to the IBM i/pSeries hypervisor | 
|  | 65 | * interfaces.  It would be really nice to abstract this above an RDMA | 
|  | 66 | * layer. | 
|  | 67 | */ | 
|  | 68 |  | 
|  | 69 | #include <linux/module.h> | 
|  | 70 | #include <linux/moduleparam.h> | 
|  | 71 | #include <linux/dma-mapping.h> | 
|  | 72 | #include <linux/delay.h> | 
| Brian King | 126c5cc | 2009-06-08 16:19:08 -0500 | [diff] [blame] | 73 | #include <linux/of.h> | 
| David Woodhouse | d3849d5 | 2007-09-22 08:29:36 +1000 | [diff] [blame] | 74 | #include <asm/firmware.h> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | #include <asm/vio.h> | 
|  | 76 | #include <scsi/scsi.h> | 
|  | 77 | #include <scsi/scsi_cmnd.h> | 
|  | 78 | #include <scsi/scsi_host.h> | 
|  | 79 | #include <scsi/scsi_device.h> | 
| FUJITA Tomonori | 4d68041 | 2007-06-27 16:32:50 +0900 | [diff] [blame] | 80 | #include <scsi/scsi_transport_srp.h> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | #include "ibmvscsi.h" | 
|  | 82 |  | 
|  | 83 | /* The values below are somewhat arbitrary default values, but | 
|  | 84 | * OS/400 will use 3 busses (disks, CDs, tapes, I think.) | 
|  | 85 | * Note that there are 3 bits of channel value, 6 bits of id, and | 
|  | 86 | * 5 bits of LUN. | 
|  | 87 | */ | 
|  | 88 | static int max_id = 64; | 
|  | 89 | static int max_channel = 3; | 
| Robert Jennings | e1a5ce5 | 2009-06-08 16:19:03 -0500 | [diff] [blame] | 90 | static int init_timeout = 300; | 
|  | 91 | static int login_timeout = 60; | 
|  | 92 | static int info_timeout = 30; | 
|  | 93 | static int abort_timeout = 60; | 
|  | 94 | static int reset_timeout = 60; | 
| Robert Jennings | a897ff2 | 2007-03-28 12:45:46 -0500 | [diff] [blame] | 95 | static int max_requests = IBMVSCSI_MAX_REQUESTS_DEFAULT; | 
| Brian King | 4f10aae | 2008-12-17 17:19:33 -0600 | [diff] [blame] | 96 | static int max_events = IBMVSCSI_MAX_REQUESTS_DEFAULT + 2; | 
| Robert Jennings | c1988e3 | 2009-06-08 16:19:07 -0500 | [diff] [blame] | 97 | static int fast_fail = 1; | 
| Brian King | 126c5cc | 2009-06-08 16:19:08 -0500 | [diff] [blame] | 98 | static int client_reserve = 1; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 99 |  | 
| FUJITA Tomonori | 4d68041 | 2007-06-27 16:32:50 +0900 | [diff] [blame] | 100 | static struct scsi_transport_template *ibmvscsi_transport_template; | 
|  | 101 |  | 
| Dave C Boutcher | 2b541f8 | 2006-01-19 13:34:44 -0600 | [diff] [blame] | 102 | #define IBMVSCSI_VERSION "1.5.8" | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 103 |  | 
| David Woodhouse | d3849d5 | 2007-09-22 08:29:36 +1000 | [diff] [blame] | 104 | static struct ibmvscsi_ops *ibmvscsi_ops; | 
|  | 105 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 106 | MODULE_DESCRIPTION("IBM Virtual SCSI"); | 
|  | 107 | MODULE_AUTHOR("Dave Boutcher"); | 
|  | 108 | MODULE_LICENSE("GPL"); | 
|  | 109 | MODULE_VERSION(IBMVSCSI_VERSION); | 
|  | 110 |  | 
|  | 111 | module_param_named(max_id, max_id, int, S_IRUGO | S_IWUSR); | 
|  | 112 | MODULE_PARM_DESC(max_id, "Largest ID value for each channel"); | 
|  | 113 | module_param_named(max_channel, max_channel, int, S_IRUGO | S_IWUSR); | 
|  | 114 | MODULE_PARM_DESC(max_channel, "Largest channel value"); | 
|  | 115 | module_param_named(init_timeout, init_timeout, int, S_IRUGO | S_IWUSR); | 
|  | 116 | MODULE_PARM_DESC(init_timeout, "Initialization timeout in seconds"); | 
| Brian King | 21465ed | 2008-12-08 17:01:47 -0600 | [diff] [blame] | 117 | module_param_named(max_requests, max_requests, int, S_IRUGO); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 118 | MODULE_PARM_DESC(max_requests, "Maximum requests for this adapter"); | 
| Robert Jennings | c1988e3 | 2009-06-08 16:19:07 -0500 | [diff] [blame] | 119 | module_param_named(fast_fail, fast_fail, int, S_IRUGO | S_IWUSR); | 
|  | 120 | MODULE_PARM_DESC(fast_fail, "Enable fast fail. [Default=1]"); | 
| Brian King | 126c5cc | 2009-06-08 16:19:08 -0500 | [diff] [blame] | 121 | module_param_named(client_reserve, client_reserve, int, S_IRUGO ); | 
|  | 122 | MODULE_PARM_DESC(client_reserve, "Attempt client managed reserve/release"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 123 |  | 
|  | 124 | /* ------------------------------------------------------------ | 
|  | 125 | * Routines for the event pool and event structs | 
|  | 126 | */ | 
|  | 127 | /** | 
|  | 128 | * initialize_event_pool: - Allocates and initializes the event pool for a host | 
|  | 129 | * @pool:	event_pool to be initialized | 
|  | 130 | * @size:	Number of events in pool | 
|  | 131 | * @hostdata:	ibmvscsi_host_data who owns the event pool | 
|  | 132 | * | 
|  | 133 | * Returns zero on success. | 
|  | 134 | */ | 
|  | 135 | static int initialize_event_pool(struct event_pool *pool, | 
|  | 136 | int size, struct ibmvscsi_host_data *hostdata) | 
|  | 137 | { | 
|  | 138 | int i; | 
|  | 139 |  | 
|  | 140 | pool->size = size; | 
|  | 141 | pool->next = 0; | 
| FUJITA Tomonori | 4c021dd13 | 2006-04-07 19:10:03 +0900 | [diff] [blame] | 142 | pool->events = kcalloc(pool->size, sizeof(*pool->events), GFP_KERNEL); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 143 | if (!pool->events) | 
|  | 144 | return -ENOMEM; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 145 |  | 
|  | 146 | pool->iu_storage = | 
|  | 147 | dma_alloc_coherent(hostdata->dev, | 
|  | 148 | pool->size * sizeof(*pool->iu_storage), | 
|  | 149 | &pool->iu_token, 0); | 
|  | 150 | if (!pool->iu_storage) { | 
|  | 151 | kfree(pool->events); | 
|  | 152 | return -ENOMEM; | 
|  | 153 | } | 
|  | 154 |  | 
|  | 155 | for (i = 0; i < pool->size; ++i) { | 
|  | 156 | struct srp_event_struct *evt = &pool->events[i]; | 
|  | 157 | memset(&evt->crq, 0x00, sizeof(evt->crq)); | 
|  | 158 | atomic_set(&evt->free, 1); | 
|  | 159 | evt->crq.valid = 0x80; | 
|  | 160 | evt->crq.IU_length = sizeof(*evt->xfer_iu); | 
|  | 161 | evt->crq.IU_data_ptr = pool->iu_token + | 
|  | 162 | sizeof(*evt->xfer_iu) * i; | 
|  | 163 | evt->xfer_iu = pool->iu_storage + i; | 
|  | 164 | evt->hostdata = hostdata; | 
| James Bottomley | 4dddbc2 | 2005-09-06 17:11:54 -0500 | [diff] [blame] | 165 | evt->ext_list = NULL; | 
|  | 166 | evt->ext_list_token = 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 167 | } | 
|  | 168 |  | 
|  | 169 | return 0; | 
|  | 170 | } | 
|  | 171 |  | 
|  | 172 | /** | 
|  | 173 | * release_event_pool: - Frees memory of an event pool of a host | 
|  | 174 | * @pool:	event_pool to be released | 
|  | 175 | * @hostdata:	ibmvscsi_host_data who owns the even pool | 
|  | 176 | * | 
|  | 177 | * Returns zero on success. | 
|  | 178 | */ | 
|  | 179 | static void release_event_pool(struct event_pool *pool, | 
|  | 180 | struct ibmvscsi_host_data *hostdata) | 
|  | 181 | { | 
|  | 182 | int i, in_use = 0; | 
| James Bottomley | 4dddbc2 | 2005-09-06 17:11:54 -0500 | [diff] [blame] | 183 | for (i = 0; i < pool->size; ++i) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 184 | if (atomic_read(&pool->events[i].free) != 1) | 
|  | 185 | ++in_use; | 
| James Bottomley | 4dddbc2 | 2005-09-06 17:11:54 -0500 | [diff] [blame] | 186 | if (pool->events[i].ext_list) { | 
|  | 187 | dma_free_coherent(hostdata->dev, | 
| FUJITA Tomonori | ef26567 | 2006-03-26 03:57:14 +0900 | [diff] [blame] | 188 | SG_ALL * sizeof(struct srp_direct_buf), | 
| James Bottomley | 4dddbc2 | 2005-09-06 17:11:54 -0500 | [diff] [blame] | 189 | pool->events[i].ext_list, | 
|  | 190 | pool->events[i].ext_list_token); | 
|  | 191 | } | 
|  | 192 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 193 | if (in_use) | 
| Brian King | 6c0a60e | 2007-06-13 17:12:19 -0500 | [diff] [blame] | 194 | dev_warn(hostdata->dev, "releasing event pool with %d " | 
|  | 195 | "events still in use?\n", in_use); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 196 | kfree(pool->events); | 
|  | 197 | dma_free_coherent(hostdata->dev, | 
|  | 198 | pool->size * sizeof(*pool->iu_storage), | 
|  | 199 | pool->iu_storage, pool->iu_token); | 
|  | 200 | } | 
|  | 201 |  | 
|  | 202 | /** | 
|  | 203 | * valid_event_struct: - Determines if event is valid. | 
|  | 204 | * @pool:	event_pool that contains the event | 
|  | 205 | * @evt:	srp_event_struct to be checked for validity | 
|  | 206 | * | 
|  | 207 | * Returns zero if event is invalid, one otherwise. | 
|  | 208 | */ | 
|  | 209 | static int valid_event_struct(struct event_pool *pool, | 
|  | 210 | struct srp_event_struct *evt) | 
|  | 211 | { | 
|  | 212 | int index = evt - pool->events; | 
|  | 213 | if (index < 0 || index >= pool->size)	/* outside of bounds */ | 
|  | 214 | return 0; | 
|  | 215 | if (evt != pool->events + index)	/* unaligned */ | 
|  | 216 | return 0; | 
|  | 217 | return 1; | 
|  | 218 | } | 
|  | 219 |  | 
|  | 220 | /** | 
|  | 221 | * ibmvscsi_free-event_struct: - Changes status of event to "free" | 
|  | 222 | * @pool:	event_pool that contains the event | 
|  | 223 | * @evt:	srp_event_struct to be modified | 
|  | 224 | * | 
|  | 225 | */ | 
|  | 226 | static void free_event_struct(struct event_pool *pool, | 
|  | 227 | struct srp_event_struct *evt) | 
|  | 228 | { | 
|  | 229 | if (!valid_event_struct(pool, evt)) { | 
| Brian King | 6c0a60e | 2007-06-13 17:12:19 -0500 | [diff] [blame] | 230 | dev_err(evt->hostdata->dev, "Freeing invalid event_struct %p " | 
|  | 231 | "(not in pool %p)\n", evt, pool->events); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 232 | return; | 
|  | 233 | } | 
|  | 234 | if (atomic_inc_return(&evt->free) != 1) { | 
| Brian King | 6c0a60e | 2007-06-13 17:12:19 -0500 | [diff] [blame] | 235 | dev_err(evt->hostdata->dev, "Freeing event_struct %p " | 
|  | 236 | "which is not in use!\n", evt); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 237 | return; | 
|  | 238 | } | 
|  | 239 | } | 
|  | 240 |  | 
|  | 241 | /** | 
|  | 242 | * get_evt_struct: - Gets the next free event in pool | 
|  | 243 | * @pool:	event_pool that contains the events to be searched | 
|  | 244 | * | 
|  | 245 | * Returns the next event in "free" state, and NULL if none are free. | 
|  | 246 | * Note that no synchronization is done here, we assume the host_lock | 
|  | 247 | * will syncrhonze things. | 
|  | 248 | */ | 
|  | 249 | static struct srp_event_struct *get_event_struct(struct event_pool *pool) | 
|  | 250 | { | 
|  | 251 | int i; | 
|  | 252 | int poolsize = pool->size; | 
|  | 253 | int offset = pool->next; | 
|  | 254 |  | 
|  | 255 | for (i = 0; i < poolsize; i++) { | 
|  | 256 | offset = (offset + 1) % poolsize; | 
|  | 257 | if (!atomic_dec_if_positive(&pool->events[offset].free)) { | 
|  | 258 | pool->next = offset; | 
|  | 259 | return &pool->events[offset]; | 
|  | 260 | } | 
|  | 261 | } | 
|  | 262 |  | 
|  | 263 | printk(KERN_ERR "ibmvscsi: found no event struct in pool!\n"); | 
|  | 264 | return NULL; | 
|  | 265 | } | 
|  | 266 |  | 
|  | 267 | /** | 
|  | 268 | * init_event_struct: Initialize fields in an event struct that are always | 
|  | 269 | *                    required. | 
|  | 270 | * @evt:        The event | 
|  | 271 | * @done:       Routine to call when the event is responded to | 
|  | 272 | * @format:     SRP or MAD format | 
|  | 273 | * @timeout:    timeout value set in the CRQ | 
|  | 274 | */ | 
|  | 275 | static void init_event_struct(struct srp_event_struct *evt_struct, | 
|  | 276 | void (*done) (struct srp_event_struct *), | 
|  | 277 | u8 format, | 
|  | 278 | int timeout) | 
|  | 279 | { | 
|  | 280 | evt_struct->cmnd = NULL; | 
|  | 281 | evt_struct->cmnd_done = NULL; | 
|  | 282 | evt_struct->sync_srp = NULL; | 
|  | 283 | evt_struct->crq.format = format; | 
|  | 284 | evt_struct->crq.timeout = timeout; | 
|  | 285 | evt_struct->done = done; | 
|  | 286 | } | 
|  | 287 |  | 
|  | 288 | /* ------------------------------------------------------------ | 
|  | 289 | * Routines for receiving SCSI responses from the hosting partition | 
|  | 290 | */ | 
|  | 291 |  | 
|  | 292 | /** | 
|  | 293 | * set_srp_direction: Set the fields in the srp related to data | 
|  | 294 | *     direction and number of buffers based on the direction in | 
|  | 295 | *     the scsi_cmnd and the number of buffers | 
|  | 296 | */ | 
|  | 297 | static void set_srp_direction(struct scsi_cmnd *cmd, | 
|  | 298 | struct srp_cmd *srp_cmd, | 
|  | 299 | int numbuf) | 
|  | 300 | { | 
| FUJITA Tomonori | ef26567 | 2006-03-26 03:57:14 +0900 | [diff] [blame] | 301 | u8 fmt; | 
|  | 302 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 303 | if (numbuf == 0) | 
|  | 304 | return; | 
|  | 305 |  | 
| FUJITA Tomonori | ef26567 | 2006-03-26 03:57:14 +0900 | [diff] [blame] | 306 | if (numbuf == 1) | 
|  | 307 | fmt = SRP_DATA_DESC_DIRECT; | 
|  | 308 | else { | 
|  | 309 | fmt = SRP_DATA_DESC_INDIRECT; | 
|  | 310 | numbuf = min(numbuf, MAX_INDIRECT_BUFS); | 
|  | 311 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 312 | if (cmd->sc_data_direction == DMA_TO_DEVICE) | 
| FUJITA Tomonori | ef26567 | 2006-03-26 03:57:14 +0900 | [diff] [blame] | 313 | srp_cmd->data_out_desc_cnt = numbuf; | 
|  | 314 | else | 
|  | 315 | srp_cmd->data_in_desc_cnt = numbuf; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 316 | } | 
| FUJITA Tomonori | ef26567 | 2006-03-26 03:57:14 +0900 | [diff] [blame] | 317 |  | 
|  | 318 | if (cmd->sc_data_direction == DMA_TO_DEVICE) | 
|  | 319 | srp_cmd->buf_fmt = fmt << 4; | 
|  | 320 | else | 
|  | 321 | srp_cmd->buf_fmt = fmt; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 322 | } | 
|  | 323 |  | 
| FUJITA Tomonori | ef26567 | 2006-03-26 03:57:14 +0900 | [diff] [blame] | 324 | static void unmap_sg_list(int num_entries, | 
| James Bottomley | 4dddbc2 | 2005-09-06 17:11:54 -0500 | [diff] [blame] | 325 | struct device *dev, | 
| FUJITA Tomonori | ef26567 | 2006-03-26 03:57:14 +0900 | [diff] [blame] | 326 | struct srp_direct_buf *md) | 
|  | 327 | { | 
| James Bottomley | 4dddbc2 | 2005-09-06 17:11:54 -0500 | [diff] [blame] | 328 | int i; | 
|  | 329 |  | 
| FUJITA Tomonori | ef26567 | 2006-03-26 03:57:14 +0900 | [diff] [blame] | 330 | for (i = 0; i < num_entries; ++i) | 
|  | 331 | dma_unmap_single(dev, md[i].va, md[i].len, DMA_BIDIRECTIONAL); | 
| James Bottomley | 4dddbc2 | 2005-09-06 17:11:54 -0500 | [diff] [blame] | 332 | } | 
|  | 333 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 334 | /** | 
|  | 335 | * unmap_cmd_data: - Unmap data pointed in srp_cmd based on the format | 
|  | 336 | * @cmd:	srp_cmd whose additional_data member will be unmapped | 
|  | 337 | * @dev:	device for which the memory is mapped | 
|  | 338 | * | 
|  | 339 | */ | 
| James Bottomley | 4dddbc2 | 2005-09-06 17:11:54 -0500 | [diff] [blame] | 340 | static void unmap_cmd_data(struct srp_cmd *cmd, | 
|  | 341 | struct srp_event_struct *evt_struct, | 
|  | 342 | struct device *dev) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 343 | { | 
| FUJITA Tomonori | ef26567 | 2006-03-26 03:57:14 +0900 | [diff] [blame] | 344 | u8 out_fmt, in_fmt; | 
|  | 345 |  | 
|  | 346 | out_fmt = cmd->buf_fmt >> 4; | 
|  | 347 | in_fmt = cmd->buf_fmt & ((1U << 4) - 1); | 
|  | 348 |  | 
|  | 349 | if (out_fmt == SRP_NO_DATA_DESC && in_fmt == SRP_NO_DATA_DESC) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 350 | return; | 
| FUJITA Tomonori | ef26567 | 2006-03-26 03:57:14 +0900 | [diff] [blame] | 351 | else if (out_fmt == SRP_DATA_DESC_DIRECT || | 
|  | 352 | in_fmt == SRP_DATA_DESC_DIRECT) { | 
|  | 353 | struct srp_direct_buf *data = | 
|  | 354 | (struct srp_direct_buf *) cmd->add_data; | 
|  | 355 | dma_unmap_single(dev, data->va, data->len, DMA_BIDIRECTIONAL); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 356 | } else { | 
| FUJITA Tomonori | ef26567 | 2006-03-26 03:57:14 +0900 | [diff] [blame] | 357 | struct srp_indirect_buf *indirect = | 
|  | 358 | (struct srp_indirect_buf *) cmd->add_data; | 
|  | 359 | int num_mapped = indirect->table_desc.len / | 
|  | 360 | sizeof(struct srp_direct_buf); | 
| James Bottomley | 4dddbc2 | 2005-09-06 17:11:54 -0500 | [diff] [blame] | 361 |  | 
|  | 362 | if (num_mapped <= MAX_INDIRECT_BUFS) { | 
| FUJITA Tomonori | ef26567 | 2006-03-26 03:57:14 +0900 | [diff] [blame] | 363 | unmap_sg_list(num_mapped, dev, &indirect->desc_list[0]); | 
| James Bottomley | 4dddbc2 | 2005-09-06 17:11:54 -0500 | [diff] [blame] | 364 | return; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 365 | } | 
| James Bottomley | 4dddbc2 | 2005-09-06 17:11:54 -0500 | [diff] [blame] | 366 |  | 
|  | 367 | unmap_sg_list(num_mapped, dev, evt_struct->ext_list); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 368 | } | 
|  | 369 | } | 
|  | 370 |  | 
| FUJITA Tomonori | 9413d7b | 2007-05-26 00:32:58 +0900 | [diff] [blame] | 371 | static int map_sg_list(struct scsi_cmnd *cmd, int nseg, | 
| FUJITA Tomonori | ef26567 | 2006-03-26 03:57:14 +0900 | [diff] [blame] | 372 | struct srp_direct_buf *md) | 
| James Bottomley | 4dddbc2 | 2005-09-06 17:11:54 -0500 | [diff] [blame] | 373 | { | 
|  | 374 | int i; | 
| FUJITA Tomonori | 9413d7b | 2007-05-26 00:32:58 +0900 | [diff] [blame] | 375 | struct scatterlist *sg; | 
| James Bottomley | 4dddbc2 | 2005-09-06 17:11:54 -0500 | [diff] [blame] | 376 | u64 total_length = 0; | 
|  | 377 |  | 
| FUJITA Tomonori | 9413d7b | 2007-05-26 00:32:58 +0900 | [diff] [blame] | 378 | scsi_for_each_sg(cmd, sg, nseg, i) { | 
| FUJITA Tomonori | ef26567 | 2006-03-26 03:57:14 +0900 | [diff] [blame] | 379 | struct srp_direct_buf *descr = md + i; | 
| FUJITA Tomonori | 9413d7b | 2007-05-26 00:32:58 +0900 | [diff] [blame] | 380 | descr->va = sg_dma_address(sg); | 
|  | 381 | descr->len = sg_dma_len(sg); | 
| FUJITA Tomonori | ef26567 | 2006-03-26 03:57:14 +0900 | [diff] [blame] | 382 | descr->key = 0; | 
| FUJITA Tomonori | 9413d7b | 2007-05-26 00:32:58 +0900 | [diff] [blame] | 383 | total_length += sg_dma_len(sg); | 
| James Bottomley | 4dddbc2 | 2005-09-06 17:11:54 -0500 | [diff] [blame] | 384 | } | 
|  | 385 | return total_length; | 
|  | 386 | } | 
|  | 387 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 388 | /** | 
|  | 389 | * map_sg_data: - Maps dma for a scatterlist and initializes decriptor fields | 
|  | 390 | * @cmd:	Scsi_Cmnd with the scatterlist | 
|  | 391 | * @srp_cmd:	srp_cmd that contains the memory descriptor | 
|  | 392 | * @dev:	device for which to map dma memory | 
|  | 393 | * | 
|  | 394 | * Called by map_data_for_srp_cmd() when building srp cmd from scsi cmd. | 
|  | 395 | * Returns 1 on success. | 
|  | 396 | */ | 
|  | 397 | static int map_sg_data(struct scsi_cmnd *cmd, | 
| James Bottomley | 4dddbc2 | 2005-09-06 17:11:54 -0500 | [diff] [blame] | 398 | struct srp_event_struct *evt_struct, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 399 | struct srp_cmd *srp_cmd, struct device *dev) | 
|  | 400 | { | 
|  | 401 |  | 
| James Bottomley | 4dddbc2 | 2005-09-06 17:11:54 -0500 | [diff] [blame] | 402 | int sg_mapped; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 403 | u64 total_length = 0; | 
| FUJITA Tomonori | ef26567 | 2006-03-26 03:57:14 +0900 | [diff] [blame] | 404 | struct srp_direct_buf *data = | 
|  | 405 | (struct srp_direct_buf *) srp_cmd->add_data; | 
|  | 406 | struct srp_indirect_buf *indirect = | 
|  | 407 | (struct srp_indirect_buf *) data; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 408 |  | 
| FUJITA Tomonori | 9413d7b | 2007-05-26 00:32:58 +0900 | [diff] [blame] | 409 | sg_mapped = scsi_dma_map(cmd); | 
|  | 410 | if (!sg_mapped) | 
|  | 411 | return 1; | 
|  | 412 | else if (sg_mapped < 0) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 413 | return 0; | 
|  | 414 |  | 
|  | 415 | set_srp_direction(cmd, srp_cmd, sg_mapped); | 
|  | 416 |  | 
|  | 417 | /* special case; we can use a single direct descriptor */ | 
|  | 418 | if (sg_mapped == 1) { | 
| FUJITA Tomonori | 9413d7b | 2007-05-26 00:32:58 +0900 | [diff] [blame] | 419 | map_sg_list(cmd, sg_mapped, data); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 420 | return 1; | 
|  | 421 | } | 
|  | 422 |  | 
| FUJITA Tomonori | ef26567 | 2006-03-26 03:57:14 +0900 | [diff] [blame] | 423 | indirect->table_desc.va = 0; | 
|  | 424 | indirect->table_desc.len = sg_mapped * sizeof(struct srp_direct_buf); | 
|  | 425 | indirect->table_desc.key = 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 426 |  | 
| James Bottomley | 4dddbc2 | 2005-09-06 17:11:54 -0500 | [diff] [blame] | 427 | if (sg_mapped <= MAX_INDIRECT_BUFS) { | 
| FUJITA Tomonori | 9413d7b | 2007-05-26 00:32:58 +0900 | [diff] [blame] | 428 | total_length = map_sg_list(cmd, sg_mapped, | 
| FUJITA Tomonori | ef26567 | 2006-03-26 03:57:14 +0900 | [diff] [blame] | 429 | &indirect->desc_list[0]); | 
|  | 430 | indirect->len = total_length; | 
| James Bottomley | 4dddbc2 | 2005-09-06 17:11:54 -0500 | [diff] [blame] | 431 | return 1; | 
|  | 432 | } | 
|  | 433 |  | 
|  | 434 | /* get indirect table */ | 
|  | 435 | if (!evt_struct->ext_list) { | 
| FUJITA Tomonori | ef26567 | 2006-03-26 03:57:14 +0900 | [diff] [blame] | 436 | evt_struct->ext_list = (struct srp_direct_buf *) | 
| FUJITA Tomonori | 9413d7b | 2007-05-26 00:32:58 +0900 | [diff] [blame] | 437 | dma_alloc_coherent(dev, | 
| FUJITA Tomonori | ef26567 | 2006-03-26 03:57:14 +0900 | [diff] [blame] | 438 | SG_ALL * sizeof(struct srp_direct_buf), | 
|  | 439 | &evt_struct->ext_list_token, 0); | 
| James Bottomley | 4dddbc2 | 2005-09-06 17:11:54 -0500 | [diff] [blame] | 440 | if (!evt_struct->ext_list) { | 
| Robert Jennings | 7912a0a | 2008-07-24 04:35:27 +1000 | [diff] [blame] | 441 | if (!firmware_has_feature(FW_FEATURE_CMO)) | 
|  | 442 | sdev_printk(KERN_ERR, cmd->device, | 
|  | 443 | "Can't allocate memory " | 
|  | 444 | "for indirect table\n"); | 
| Robert Jennings | e637d55 | 2009-01-22 13:40:09 -0600 | [diff] [blame] | 445 | scsi_dma_unmap(cmd); | 
| James Bottomley | 4dddbc2 | 2005-09-06 17:11:54 -0500 | [diff] [blame] | 446 | return 0; | 
| James Bottomley | 4dddbc2 | 2005-09-06 17:11:54 -0500 | [diff] [blame] | 447 | } | 
|  | 448 | } | 
|  | 449 |  | 
| FUJITA Tomonori | 9413d7b | 2007-05-26 00:32:58 +0900 | [diff] [blame] | 450 | total_length = map_sg_list(cmd, sg_mapped, evt_struct->ext_list); | 
| James Bottomley | 4dddbc2 | 2005-09-06 17:11:54 -0500 | [diff] [blame] | 451 |  | 
| FUJITA Tomonori | ef26567 | 2006-03-26 03:57:14 +0900 | [diff] [blame] | 452 | indirect->len = total_length; | 
|  | 453 | indirect->table_desc.va = evt_struct->ext_list_token; | 
|  | 454 | indirect->table_desc.len = sg_mapped * sizeof(indirect->desc_list[0]); | 
|  | 455 | memcpy(indirect->desc_list, evt_struct->ext_list, | 
|  | 456 | MAX_INDIRECT_BUFS * sizeof(struct srp_direct_buf)); | 
| James Bottomley | 4dddbc2 | 2005-09-06 17:11:54 -0500 | [diff] [blame] | 457 | return 1; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 458 | } | 
|  | 459 |  | 
|  | 460 | /** | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 461 | * map_data_for_srp_cmd: - Calls functions to map data for srp cmds | 
|  | 462 | * @cmd:	struct scsi_cmnd with the memory to be mapped | 
|  | 463 | * @srp_cmd:	srp_cmd that contains the memory descriptor | 
|  | 464 | * @dev:	dma device for which to map dma memory | 
|  | 465 | * | 
|  | 466 | * Called by scsi_cmd_to_srp_cmd() when converting scsi cmds to srp cmds | 
|  | 467 | * Returns 1 on success. | 
|  | 468 | */ | 
|  | 469 | static int map_data_for_srp_cmd(struct scsi_cmnd *cmd, | 
| James Bottomley | 4dddbc2 | 2005-09-06 17:11:54 -0500 | [diff] [blame] | 470 | struct srp_event_struct *evt_struct, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 471 | struct srp_cmd *srp_cmd, struct device *dev) | 
|  | 472 | { | 
|  | 473 | switch (cmd->sc_data_direction) { | 
|  | 474 | case DMA_FROM_DEVICE: | 
|  | 475 | case DMA_TO_DEVICE: | 
|  | 476 | break; | 
|  | 477 | case DMA_NONE: | 
|  | 478 | return 1; | 
|  | 479 | case DMA_BIDIRECTIONAL: | 
| Brian King | 6c0a60e | 2007-06-13 17:12:19 -0500 | [diff] [blame] | 480 | sdev_printk(KERN_ERR, cmd->device, | 
|  | 481 | "Can't map DMA_BIDIRECTIONAL to read/write\n"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 482 | return 0; | 
|  | 483 | default: | 
| Brian King | 6c0a60e | 2007-06-13 17:12:19 -0500 | [diff] [blame] | 484 | sdev_printk(KERN_ERR, cmd->device, | 
|  | 485 | "Unknown data direction 0x%02x; can't map!\n", | 
|  | 486 | cmd->sc_data_direction); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 487 | return 0; | 
|  | 488 | } | 
|  | 489 |  | 
| FUJITA Tomonori | 9413d7b | 2007-05-26 00:32:58 +0900 | [diff] [blame] | 490 | return map_sg_data(cmd, evt_struct, srp_cmd, dev); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 491 | } | 
|  | 492 |  | 
| Brian King | 3d0e91f | 2007-06-13 17:12:26 -0500 | [diff] [blame] | 493 | /** | 
|  | 494 | * purge_requests: Our virtual adapter just shut down.  purge any sent requests | 
|  | 495 | * @hostdata:    the adapter | 
|  | 496 | */ | 
|  | 497 | static void purge_requests(struct ibmvscsi_host_data *hostdata, int error_code) | 
|  | 498 | { | 
|  | 499 | struct srp_event_struct *tmp_evt, *pos; | 
|  | 500 | unsigned long flags; | 
|  | 501 |  | 
|  | 502 | spin_lock_irqsave(hostdata->host->host_lock, flags); | 
|  | 503 | list_for_each_entry_safe(tmp_evt, pos, &hostdata->sent, list) { | 
|  | 504 | list_del(&tmp_evt->list); | 
|  | 505 | del_timer(&tmp_evt->timer); | 
|  | 506 | if (tmp_evt->cmnd) { | 
|  | 507 | tmp_evt->cmnd->result = (error_code << 16); | 
|  | 508 | unmap_cmd_data(&tmp_evt->iu.srp.cmd, | 
|  | 509 | tmp_evt, | 
|  | 510 | tmp_evt->hostdata->dev); | 
|  | 511 | if (tmp_evt->cmnd_done) | 
|  | 512 | tmp_evt->cmnd_done(tmp_evt->cmnd); | 
|  | 513 | } else if (tmp_evt->done) | 
|  | 514 | tmp_evt->done(tmp_evt); | 
|  | 515 | free_event_struct(&tmp_evt->hostdata->pool, tmp_evt); | 
|  | 516 | } | 
|  | 517 | spin_unlock_irqrestore(hostdata->host->host_lock, flags); | 
|  | 518 | } | 
|  | 519 |  | 
|  | 520 | /** | 
|  | 521 | * ibmvscsi_reset_host - Reset the connection to the server | 
|  | 522 | * @hostdata:	struct ibmvscsi_host_data to reset | 
|  | 523 | */ | 
|  | 524 | static void ibmvscsi_reset_host(struct ibmvscsi_host_data *hostdata) | 
|  | 525 | { | 
|  | 526 | scsi_block_requests(hostdata->host); | 
|  | 527 | atomic_set(&hostdata->request_limit, 0); | 
|  | 528 |  | 
|  | 529 | purge_requests(hostdata, DID_ERROR); | 
| David Woodhouse | d3849d5 | 2007-09-22 08:29:36 +1000 | [diff] [blame] | 530 | if ((ibmvscsi_ops->reset_crq_queue(&hostdata->queue, hostdata)) || | 
|  | 531 | (ibmvscsi_ops->send_crq(hostdata, 0xC001000000000000LL, 0)) || | 
| Brian King | 3d0e91f | 2007-06-13 17:12:26 -0500 | [diff] [blame] | 532 | (vio_enable_interrupts(to_vio_dev(hostdata->dev)))) { | 
|  | 533 | atomic_set(&hostdata->request_limit, -1); | 
|  | 534 | dev_err(hostdata->dev, "error after reset\n"); | 
|  | 535 | } | 
|  | 536 |  | 
|  | 537 | scsi_unblock_requests(hostdata->host); | 
|  | 538 | } | 
|  | 539 |  | 
|  | 540 | /** | 
|  | 541 | * ibmvscsi_timeout - Internal command timeout handler | 
|  | 542 | * @evt_struct:	struct srp_event_struct that timed out | 
|  | 543 | * | 
|  | 544 | * Called when an internally generated command times out | 
|  | 545 | */ | 
|  | 546 | static void ibmvscsi_timeout(struct srp_event_struct *evt_struct) | 
|  | 547 | { | 
|  | 548 | struct ibmvscsi_host_data *hostdata = evt_struct->hostdata; | 
|  | 549 |  | 
|  | 550 | dev_err(hostdata->dev, "Command timed out (%x). Resetting connection\n", | 
|  | 551 | evt_struct->iu.srp.cmd.opcode); | 
|  | 552 |  | 
|  | 553 | ibmvscsi_reset_host(hostdata); | 
|  | 554 | } | 
|  | 555 |  | 
|  | 556 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 557 | /* ------------------------------------------------------------ | 
|  | 558 | * Routines for sending and receiving SRPs | 
|  | 559 | */ | 
|  | 560 | /** | 
|  | 561 | * ibmvscsi_send_srp_event: - Transforms event to u64 array and calls send_crq() | 
|  | 562 | * @evt_struct:	evt_struct to be sent | 
|  | 563 | * @hostdata:	ibmvscsi_host_data of host | 
| Brian King | 3d0e91f | 2007-06-13 17:12:26 -0500 | [diff] [blame] | 564 | * @timeout:	timeout in seconds - 0 means do not time command | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 565 | * | 
|  | 566 | * Returns the value returned from ibmvscsi_send_crq(). (Zero for success) | 
|  | 567 | * Note that this routine assumes that host_lock is held for synchronization | 
|  | 568 | */ | 
|  | 569 | static int ibmvscsi_send_srp_event(struct srp_event_struct *evt_struct, | 
| Brian King | 3d0e91f | 2007-06-13 17:12:26 -0500 | [diff] [blame] | 570 | struct ibmvscsi_host_data *hostdata, | 
|  | 571 | unsigned long timeout) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 572 | { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 573 | u64 *crq_as_u64 = (u64 *) &evt_struct->crq; | 
| Robert Jennings | 3c887e8 | 2007-10-30 11:37:07 -0500 | [diff] [blame] | 574 | int request_status = 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 575 | int rc; | 
|  | 576 |  | 
| Robert Jennings | a897ff2 | 2007-03-28 12:45:46 -0500 | [diff] [blame] | 577 | /* If we have exhausted our request limit, just fail this request, | 
|  | 578 | * unless it is for a reset or abort. | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 579 | * Note that there are rare cases involving driver generated requests | 
|  | 580 | * (such as task management requests) that the mid layer may think we | 
|  | 581 | * can handle more requests (can_queue) when we actually can't | 
|  | 582 | */ | 
| Dave C Boutcher | cefbda2 | 2006-06-12 21:22:51 -0500 | [diff] [blame] | 583 | if (evt_struct->crq.format == VIOSRP_SRP_FORMAT) { | 
|  | 584 | request_status = | 
|  | 585 | atomic_dec_if_positive(&hostdata->request_limit); | 
|  | 586 | /* If request limit was -1 when we started, it is now even | 
|  | 587 | * less than that | 
|  | 588 | */ | 
|  | 589 | if (request_status < -1) | 
|  | 590 | goto send_error; | 
| Robert Jennings | a897ff2 | 2007-03-28 12:45:46 -0500 | [diff] [blame] | 591 | /* Otherwise, we may have run out of requests. */ | 
| Robert Jennings | 3c887e8 | 2007-10-30 11:37:07 -0500 | [diff] [blame] | 592 | /* If request limit was 0 when we started the adapter is in the | 
|  | 593 | * process of performing a login with the server adapter, or | 
|  | 594 | * we may have run out of requests. | 
|  | 595 | */ | 
|  | 596 | else if (request_status == -1 && | 
|  | 597 | evt_struct->iu.srp.login_req.opcode != SRP_LOGIN_REQ) | 
|  | 598 | goto send_busy; | 
| Robert Jennings | a897ff2 | 2007-03-28 12:45:46 -0500 | [diff] [blame] | 599 | /* Abort and reset calls should make it through. | 
|  | 600 | * Nothing except abort and reset should use the last two | 
|  | 601 | * slots unless we had two or less to begin with. | 
|  | 602 | */ | 
|  | 603 | else if (request_status < 2 && | 
|  | 604 | evt_struct->iu.srp.cmd.opcode != SRP_TSK_MGMT) { | 
|  | 605 | /* In the case that we have less than two requests | 
|  | 606 | * available, check the server limit as a combination | 
|  | 607 | * of the request limit and the number of requests | 
|  | 608 | * in-flight (the size of the send list).  If the | 
|  | 609 | * server limit is greater than 2, return busy so | 
|  | 610 | * that the last two are reserved for reset and abort. | 
|  | 611 | */ | 
|  | 612 | int server_limit = request_status; | 
|  | 613 | struct srp_event_struct *tmp_evt; | 
|  | 614 |  | 
|  | 615 | list_for_each_entry(tmp_evt, &hostdata->sent, list) { | 
|  | 616 | server_limit++; | 
|  | 617 | } | 
|  | 618 |  | 
|  | 619 | if (server_limit > 2) | 
|  | 620 | goto send_busy; | 
|  | 621 | } | 
| Dave C Boutcher | cefbda2 | 2006-06-12 21:22:51 -0500 | [diff] [blame] | 622 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 623 |  | 
|  | 624 | /* Copy the IU into the transfer area */ | 
|  | 625 | *evt_struct->xfer_iu = evt_struct->iu; | 
| FUJITA Tomonori | ef26567 | 2006-03-26 03:57:14 +0900 | [diff] [blame] | 626 | evt_struct->xfer_iu->srp.rsp.tag = (u64)evt_struct; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 627 |  | 
|  | 628 | /* Add this to the sent list.  We need to do this | 
|  | 629 | * before we actually send | 
|  | 630 | * in case it comes back REALLY fast | 
|  | 631 | */ | 
|  | 632 | list_add_tail(&evt_struct->list, &hostdata->sent); | 
|  | 633 |  | 
| Brian King | 3d0e91f | 2007-06-13 17:12:26 -0500 | [diff] [blame] | 634 | init_timer(&evt_struct->timer); | 
|  | 635 | if (timeout) { | 
|  | 636 | evt_struct->timer.data = (unsigned long) evt_struct; | 
|  | 637 | evt_struct->timer.expires = jiffies + (timeout * HZ); | 
|  | 638 | evt_struct->timer.function = (void (*)(unsigned long))ibmvscsi_timeout; | 
|  | 639 | add_timer(&evt_struct->timer); | 
|  | 640 | } | 
|  | 641 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 642 | if ((rc = | 
| David Woodhouse | d3849d5 | 2007-09-22 08:29:36 +1000 | [diff] [blame] | 643 | ibmvscsi_ops->send_crq(hostdata, crq_as_u64[0], crq_as_u64[1])) != 0) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 644 | list_del(&evt_struct->list); | 
| Brian King | 3d0e91f | 2007-06-13 17:12:26 -0500 | [diff] [blame] | 645 | del_timer(&evt_struct->timer); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 646 |  | 
| Robert Jennings | 860784c | 2007-11-12 09:00:23 -0600 | [diff] [blame] | 647 | /* If send_crq returns H_CLOSED, return SCSI_MLQUEUE_HOST_BUSY. | 
|  | 648 | * Firmware will send a CRQ with a transport event (0xFF) to | 
|  | 649 | * tell this client what has happened to the transport.  This | 
|  | 650 | * will be handled in ibmvscsi_handle_crq() | 
|  | 651 | */ | 
|  | 652 | if (rc == H_CLOSED) { | 
|  | 653 | dev_warn(hostdata->dev, "send warning. " | 
|  | 654 | "Receive queue closed, will retry.\n"); | 
|  | 655 | goto send_busy; | 
|  | 656 | } | 
| Brian King | 6c0a60e | 2007-06-13 17:12:19 -0500 | [diff] [blame] | 657 | dev_err(hostdata->dev, "send error %d\n", rc); | 
| Robert Jennings | a897ff2 | 2007-03-28 12:45:46 -0500 | [diff] [blame] | 658 | atomic_inc(&hostdata->request_limit); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 659 | goto send_error; | 
|  | 660 | } | 
|  | 661 |  | 
|  | 662 | return 0; | 
|  | 663 |  | 
| Dave C Boutcher | cefbda2 | 2006-06-12 21:22:51 -0500 | [diff] [blame] | 664 | send_busy: | 
| James Bottomley | 4dddbc2 | 2005-09-06 17:11:54 -0500 | [diff] [blame] | 665 | unmap_cmd_data(&evt_struct->iu.srp.cmd, evt_struct, hostdata->dev); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 666 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 667 | free_event_struct(&hostdata->pool, evt_struct); | 
| Robert Jennings | 3c887e8 | 2007-10-30 11:37:07 -0500 | [diff] [blame] | 668 | if (request_status != -1) | 
|  | 669 | atomic_inc(&hostdata->request_limit); | 
| Robert Jennings | a897ff2 | 2007-03-28 12:45:46 -0500 | [diff] [blame] | 670 | return SCSI_MLQUEUE_HOST_BUSY; | 
| Dave C Boutcher | cefbda2 | 2006-06-12 21:22:51 -0500 | [diff] [blame] | 671 |  | 
|  | 672 | send_error: | 
|  | 673 | unmap_cmd_data(&evt_struct->iu.srp.cmd, evt_struct, hostdata->dev); | 
|  | 674 |  | 
|  | 675 | if (evt_struct->cmnd != NULL) { | 
|  | 676 | evt_struct->cmnd->result = DID_ERROR << 16; | 
|  | 677 | evt_struct->cmnd_done(evt_struct->cmnd); | 
|  | 678 | } else if (evt_struct->done) | 
|  | 679 | evt_struct->done(evt_struct); | 
|  | 680 |  | 
|  | 681 | free_event_struct(&hostdata->pool, evt_struct); | 
|  | 682 | return 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 683 | } | 
|  | 684 |  | 
|  | 685 | /** | 
|  | 686 | * handle_cmd_rsp: -  Handle responses from commands | 
|  | 687 | * @evt_struct:	srp_event_struct to be handled | 
|  | 688 | * | 
|  | 689 | * Used as a callback by when sending scsi cmds. | 
|  | 690 | * Gets called by ibmvscsi_handle_crq() | 
|  | 691 | */ | 
|  | 692 | static void handle_cmd_rsp(struct srp_event_struct *evt_struct) | 
|  | 693 | { | 
|  | 694 | struct srp_rsp *rsp = &evt_struct->xfer_iu->srp.rsp; | 
|  | 695 | struct scsi_cmnd *cmnd = evt_struct->cmnd; | 
|  | 696 |  | 
| FUJITA Tomonori | ef26567 | 2006-03-26 03:57:14 +0900 | [diff] [blame] | 697 | if (unlikely(rsp->opcode != SRP_RSP)) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 698 | if (printk_ratelimit()) | 
| Brian King | 6c0a60e | 2007-06-13 17:12:19 -0500 | [diff] [blame] | 699 | dev_warn(evt_struct->hostdata->dev, | 
|  | 700 | "bad SRP RSP type %d\n", rsp->opcode); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 701 | } | 
|  | 702 |  | 
|  | 703 | if (cmnd) { | 
| Brian King | c3a3b55 | 2008-04-25 16:58:29 -0500 | [diff] [blame] | 704 | cmnd->result |= rsp->status; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 705 | if (((cmnd->result >> 1) & 0x1f) == CHECK_CONDITION) | 
|  | 706 | memcpy(cmnd->sense_buffer, | 
| FUJITA Tomonori | ef26567 | 2006-03-26 03:57:14 +0900 | [diff] [blame] | 707 | rsp->data, | 
|  | 708 | rsp->sense_data_len); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 709 | unmap_cmd_data(&evt_struct->iu.srp.cmd, | 
| James Bottomley | 4dddbc2 | 2005-09-06 17:11:54 -0500 | [diff] [blame] | 710 | evt_struct, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 711 | evt_struct->hostdata->dev); | 
|  | 712 |  | 
| FUJITA Tomonori | ef26567 | 2006-03-26 03:57:14 +0900 | [diff] [blame] | 713 | if (rsp->flags & SRP_RSP_FLAG_DOOVER) | 
| FUJITA Tomonori | 9413d7b | 2007-05-26 00:32:58 +0900 | [diff] [blame] | 714 | scsi_set_resid(cmnd, rsp->data_out_res_cnt); | 
| FUJITA Tomonori | ef26567 | 2006-03-26 03:57:14 +0900 | [diff] [blame] | 715 | else if (rsp->flags & SRP_RSP_FLAG_DIOVER) | 
| FUJITA Tomonori | 9413d7b | 2007-05-26 00:32:58 +0900 | [diff] [blame] | 716 | scsi_set_resid(cmnd, rsp->data_in_res_cnt); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 717 | } | 
|  | 718 |  | 
|  | 719 | if (evt_struct->cmnd_done) | 
|  | 720 | evt_struct->cmnd_done(cmnd); | 
|  | 721 | } | 
|  | 722 |  | 
|  | 723 | /** | 
|  | 724 | * lun_from_dev: - Returns the lun of the scsi device | 
|  | 725 | * @dev:	struct scsi_device | 
|  | 726 | * | 
|  | 727 | */ | 
|  | 728 | static inline u16 lun_from_dev(struct scsi_device *dev) | 
|  | 729 | { | 
|  | 730 | return (0x2 << 14) | (dev->id << 8) | (dev->channel << 5) | dev->lun; | 
|  | 731 | } | 
|  | 732 |  | 
|  | 733 | /** | 
|  | 734 | * ibmvscsi_queue: - The queuecommand function of the scsi template | 
|  | 735 | * @cmd:	struct scsi_cmnd to be executed | 
|  | 736 | * @done:	Callback function to be called when cmd is completed | 
|  | 737 | */ | 
|  | 738 | static int ibmvscsi_queuecommand(struct scsi_cmnd *cmnd, | 
|  | 739 | void (*done) (struct scsi_cmnd *)) | 
|  | 740 | { | 
|  | 741 | struct srp_cmd *srp_cmd; | 
|  | 742 | struct srp_event_struct *evt_struct; | 
| FUJITA Tomonori | ef26567 | 2006-03-26 03:57:14 +0900 | [diff] [blame] | 743 | struct srp_indirect_buf *indirect; | 
| FUJITA Tomonori | 7603e02 | 2007-07-23 09:28:40 +0900 | [diff] [blame] | 744 | struct ibmvscsi_host_data *hostdata = shost_priv(cmnd->device->host); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 745 | u16 lun = lun_from_dev(cmnd->device); | 
| FUJITA Tomonori | ef26567 | 2006-03-26 03:57:14 +0900 | [diff] [blame] | 746 | u8 out_fmt, in_fmt; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 747 |  | 
| Brian King | c3a3b55 | 2008-04-25 16:58:29 -0500 | [diff] [blame] | 748 | cmnd->result = (DID_OK << 16); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 749 | evt_struct = get_event_struct(&hostdata->pool); | 
|  | 750 | if (!evt_struct) | 
|  | 751 | return SCSI_MLQUEUE_HOST_BUSY; | 
|  | 752 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 753 | /* Set up the actual SRP IU */ | 
|  | 754 | srp_cmd = &evt_struct->iu.srp.cmd; | 
| FUJITA Tomonori | ef26567 | 2006-03-26 03:57:14 +0900 | [diff] [blame] | 755 | memset(srp_cmd, 0x00, SRP_MAX_IU_LEN); | 
|  | 756 | srp_cmd->opcode = SRP_CMD; | 
| Boaz Harrosh | 64a87b2 | 2008-04-30 11:19:47 +0300 | [diff] [blame] | 757 | memcpy(srp_cmd->cdb, cmnd->cmnd, sizeof(srp_cmd->cdb)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 758 | srp_cmd->lun = ((u64) lun) << 48; | 
|  | 759 |  | 
| James Bottomley | 4dddbc2 | 2005-09-06 17:11:54 -0500 | [diff] [blame] | 760 | if (!map_data_for_srp_cmd(cmnd, evt_struct, srp_cmd, hostdata->dev)) { | 
| Robert Jennings | 7912a0a | 2008-07-24 04:35:27 +1000 | [diff] [blame] | 761 | if (!firmware_has_feature(FW_FEATURE_CMO)) | 
|  | 762 | sdev_printk(KERN_ERR, cmnd->device, | 
|  | 763 | "couldn't convert cmd to srp_cmd\n"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 764 | free_event_struct(&hostdata->pool, evt_struct); | 
|  | 765 | return SCSI_MLQUEUE_HOST_BUSY; | 
|  | 766 | } | 
|  | 767 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 768 | init_event_struct(evt_struct, | 
|  | 769 | handle_cmd_rsp, | 
|  | 770 | VIOSRP_SRP_FORMAT, | 
| Jens Axboe | 242f9dc | 2008-09-14 05:55:09 -0700 | [diff] [blame] | 771 | cmnd->request->timeout/HZ); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 772 |  | 
|  | 773 | evt_struct->cmnd = cmnd; | 
|  | 774 | evt_struct->cmnd_done = done; | 
|  | 775 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 776 | /* Fix up dma address of the buffer itself */ | 
| FUJITA Tomonori | ef26567 | 2006-03-26 03:57:14 +0900 | [diff] [blame] | 777 | indirect = (struct srp_indirect_buf *) srp_cmd->add_data; | 
|  | 778 | out_fmt = srp_cmd->buf_fmt >> 4; | 
|  | 779 | in_fmt = srp_cmd->buf_fmt & ((1U << 4) - 1); | 
|  | 780 | if ((in_fmt == SRP_DATA_DESC_INDIRECT || | 
|  | 781 | out_fmt == SRP_DATA_DESC_INDIRECT) && | 
|  | 782 | indirect->table_desc.va == 0) { | 
|  | 783 | indirect->table_desc.va = evt_struct->crq.IU_data_ptr + | 
|  | 784 | offsetof(struct srp_cmd, add_data) + | 
|  | 785 | offsetof(struct srp_indirect_buf, desc_list); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 786 | } | 
|  | 787 |  | 
| Brian King | 3d0e91f | 2007-06-13 17:12:26 -0500 | [diff] [blame] | 788 | return ibmvscsi_send_srp_event(evt_struct, hostdata, 0); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 789 | } | 
|  | 790 |  | 
|  | 791 | /* ------------------------------------------------------------ | 
|  | 792 | * Routines for driver initialization | 
|  | 793 | */ | 
| Brian King | 3507e13 | 2009-06-08 16:19:04 -0500 | [diff] [blame] | 794 |  | 
|  | 795 | /** | 
| Brian King | 126c5cc | 2009-06-08 16:19:08 -0500 | [diff] [blame] | 796 | * map_persist_bufs: - Pre-map persistent data for adapter logins | 
|  | 797 | * @hostdata:   ibmvscsi_host_data of host | 
|  | 798 | * | 
|  | 799 | * Map the capabilities and adapter info DMA buffers to avoid runtime failures. | 
|  | 800 | * Return 1 on error, 0 on success. | 
|  | 801 | */ | 
|  | 802 | static int map_persist_bufs(struct ibmvscsi_host_data *hostdata) | 
|  | 803 | { | 
|  | 804 |  | 
|  | 805 | hostdata->caps_addr = dma_map_single(hostdata->dev, &hostdata->caps, | 
|  | 806 | sizeof(hostdata->caps), DMA_BIDIRECTIONAL); | 
|  | 807 |  | 
|  | 808 | if (dma_mapping_error(hostdata->dev, hostdata->caps_addr)) { | 
|  | 809 | dev_err(hostdata->dev, "Unable to map capabilities buffer!\n"); | 
|  | 810 | return 1; | 
|  | 811 | } | 
|  | 812 |  | 
|  | 813 | hostdata->adapter_info_addr = dma_map_single(hostdata->dev, | 
|  | 814 | &hostdata->madapter_info, | 
|  | 815 | sizeof(hostdata->madapter_info), | 
|  | 816 | DMA_BIDIRECTIONAL); | 
|  | 817 | if (dma_mapping_error(hostdata->dev, hostdata->adapter_info_addr)) { | 
|  | 818 | dev_err(hostdata->dev, "Unable to map adapter info buffer!\n"); | 
|  | 819 | dma_unmap_single(hostdata->dev, hostdata->caps_addr, | 
|  | 820 | sizeof(hostdata->caps), DMA_BIDIRECTIONAL); | 
|  | 821 | return 1; | 
|  | 822 | } | 
|  | 823 |  | 
|  | 824 | return 0; | 
|  | 825 | } | 
|  | 826 |  | 
|  | 827 | /** | 
|  | 828 | * unmap_persist_bufs: - Unmap persistent data needed for adapter logins | 
|  | 829 | * @hostdata:   ibmvscsi_host_data of host | 
|  | 830 | * | 
|  | 831 | * Unmap the capabilities and adapter info DMA buffers | 
|  | 832 | */ | 
|  | 833 | static void unmap_persist_bufs(struct ibmvscsi_host_data *hostdata) | 
|  | 834 | { | 
|  | 835 | dma_unmap_single(hostdata->dev, hostdata->caps_addr, | 
|  | 836 | sizeof(hostdata->caps), DMA_BIDIRECTIONAL); | 
|  | 837 |  | 
|  | 838 | dma_unmap_single(hostdata->dev, hostdata->adapter_info_addr, | 
|  | 839 | sizeof(hostdata->madapter_info), DMA_BIDIRECTIONAL); | 
|  | 840 | } | 
|  | 841 |  | 
|  | 842 | /** | 
| Brian King | 3507e13 | 2009-06-08 16:19:04 -0500 | [diff] [blame] | 843 | * login_rsp: - Handle response to SRP login request | 
|  | 844 | * @evt_struct:	srp_event_struct with the response | 
|  | 845 | * | 
|  | 846 | * Used as a "done" callback by when sending srp_login. Gets called | 
|  | 847 | * by ibmvscsi_handle_crq() | 
|  | 848 | */ | 
|  | 849 | static void login_rsp(struct srp_event_struct *evt_struct) | 
|  | 850 | { | 
|  | 851 | struct ibmvscsi_host_data *hostdata = evt_struct->hostdata; | 
|  | 852 | switch (evt_struct->xfer_iu->srp.login_rsp.opcode) { | 
|  | 853 | case SRP_LOGIN_RSP:	/* it worked! */ | 
|  | 854 | break; | 
|  | 855 | case SRP_LOGIN_REJ:	/* refused! */ | 
|  | 856 | dev_info(hostdata->dev, "SRP_LOGIN_REJ reason %u\n", | 
|  | 857 | evt_struct->xfer_iu->srp.login_rej.reason); | 
|  | 858 | /* Login failed.  */ | 
|  | 859 | atomic_set(&hostdata->request_limit, -1); | 
|  | 860 | return; | 
|  | 861 | default: | 
|  | 862 | dev_err(hostdata->dev, "Invalid login response typecode 0x%02x!\n", | 
|  | 863 | evt_struct->xfer_iu->srp.login_rsp.opcode); | 
|  | 864 | /* Login failed.  */ | 
|  | 865 | atomic_set(&hostdata->request_limit, -1); | 
|  | 866 | return; | 
|  | 867 | } | 
|  | 868 |  | 
|  | 869 | dev_info(hostdata->dev, "SRP_LOGIN succeeded\n"); | 
| Brian King | 126c5cc | 2009-06-08 16:19:08 -0500 | [diff] [blame] | 870 | hostdata->client_migrated = 0; | 
| Brian King | 3507e13 | 2009-06-08 16:19:04 -0500 | [diff] [blame] | 871 |  | 
|  | 872 | /* Now we know what the real request-limit is. | 
|  | 873 | * This value is set rather than added to request_limit because | 
|  | 874 | * request_limit could have been set to -1 by this client. | 
|  | 875 | */ | 
|  | 876 | atomic_set(&hostdata->request_limit, | 
|  | 877 | evt_struct->xfer_iu->srp.login_rsp.req_lim_delta); | 
|  | 878 |  | 
|  | 879 | /* If we had any pending I/Os, kick them */ | 
|  | 880 | scsi_unblock_requests(hostdata->host); | 
|  | 881 | } | 
|  | 882 |  | 
|  | 883 | /** | 
|  | 884 | * send_srp_login: - Sends the srp login | 
|  | 885 | * @hostdata:	ibmvscsi_host_data of host | 
|  | 886 | * | 
|  | 887 | * Returns zero if successful. | 
|  | 888 | */ | 
|  | 889 | static int send_srp_login(struct ibmvscsi_host_data *hostdata) | 
|  | 890 | { | 
|  | 891 | int rc; | 
|  | 892 | unsigned long flags; | 
|  | 893 | struct srp_login_req *login; | 
|  | 894 | struct srp_event_struct *evt_struct = get_event_struct(&hostdata->pool); | 
|  | 895 |  | 
|  | 896 | BUG_ON(!evt_struct); | 
|  | 897 | init_event_struct(evt_struct, login_rsp, | 
|  | 898 | VIOSRP_SRP_FORMAT, login_timeout); | 
|  | 899 |  | 
|  | 900 | login = &evt_struct->iu.srp.login_req; | 
|  | 901 | memset(login, 0, sizeof(*login)); | 
|  | 902 | login->opcode = SRP_LOGIN_REQ; | 
|  | 903 | login->req_it_iu_len = sizeof(union srp_iu); | 
|  | 904 | login->req_buf_fmt = SRP_BUF_FORMAT_DIRECT | SRP_BUF_FORMAT_INDIRECT; | 
|  | 905 |  | 
|  | 906 | spin_lock_irqsave(hostdata->host->host_lock, flags); | 
|  | 907 | /* Start out with a request limit of 0, since this is negotiated in | 
|  | 908 | * the login request we are just sending and login requests always | 
|  | 909 | * get sent by the driver regardless of request_limit. | 
|  | 910 | */ | 
|  | 911 | atomic_set(&hostdata->request_limit, 0); | 
|  | 912 |  | 
|  | 913 | rc = ibmvscsi_send_srp_event(evt_struct, hostdata, login_timeout * 2); | 
|  | 914 | spin_unlock_irqrestore(hostdata->host->host_lock, flags); | 
|  | 915 | dev_info(hostdata->dev, "sent SRP login\n"); | 
|  | 916 | return rc; | 
|  | 917 | }; | 
|  | 918 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 919 | /** | 
| Brian King | 126c5cc | 2009-06-08 16:19:08 -0500 | [diff] [blame] | 920 | * capabilities_rsp: - Handle response to MAD adapter capabilities request | 
|  | 921 | * @evt_struct:	srp_event_struct with the response | 
|  | 922 | * | 
|  | 923 | * Used as a "done" callback by when sending adapter_info. | 
|  | 924 | */ | 
|  | 925 | static void capabilities_rsp(struct srp_event_struct *evt_struct) | 
|  | 926 | { | 
|  | 927 | struct ibmvscsi_host_data *hostdata = evt_struct->hostdata; | 
|  | 928 |  | 
|  | 929 | if (evt_struct->xfer_iu->mad.capabilities.common.status) { | 
|  | 930 | dev_err(hostdata->dev, "error 0x%X getting capabilities info\n", | 
|  | 931 | evt_struct->xfer_iu->mad.capabilities.common.status); | 
|  | 932 | } else { | 
|  | 933 | if (hostdata->caps.migration.common.server_support != SERVER_SUPPORTS_CAP) | 
|  | 934 | dev_info(hostdata->dev, "Partition migration not supported\n"); | 
|  | 935 |  | 
|  | 936 | if (client_reserve) { | 
|  | 937 | if (hostdata->caps.reserve.common.server_support == | 
|  | 938 | SERVER_SUPPORTS_CAP) | 
|  | 939 | dev_info(hostdata->dev, "Client reserve enabled\n"); | 
|  | 940 | else | 
|  | 941 | dev_info(hostdata->dev, "Client reserve not supported\n"); | 
|  | 942 | } | 
|  | 943 | } | 
|  | 944 |  | 
|  | 945 | send_srp_login(hostdata); | 
|  | 946 | } | 
|  | 947 |  | 
|  | 948 | /** | 
|  | 949 | * send_mad_capabilities: - Sends the mad capabilities request | 
|  | 950 | *      and stores the result so it can be retrieved with | 
|  | 951 | * @hostdata:	ibmvscsi_host_data of host | 
|  | 952 | */ | 
|  | 953 | static void send_mad_capabilities(struct ibmvscsi_host_data *hostdata) | 
|  | 954 | { | 
|  | 955 | struct viosrp_capabilities *req; | 
|  | 956 | struct srp_event_struct *evt_struct; | 
|  | 957 | unsigned long flags; | 
|  | 958 | struct device_node *of_node = hostdata->dev->archdata.of_node; | 
|  | 959 | const char *location; | 
|  | 960 |  | 
|  | 961 | evt_struct = get_event_struct(&hostdata->pool); | 
|  | 962 | BUG_ON(!evt_struct); | 
|  | 963 |  | 
|  | 964 | init_event_struct(evt_struct, capabilities_rsp, | 
|  | 965 | VIOSRP_MAD_FORMAT, info_timeout); | 
|  | 966 |  | 
|  | 967 | req = &evt_struct->iu.mad.capabilities; | 
|  | 968 | memset(req, 0, sizeof(*req)); | 
|  | 969 |  | 
|  | 970 | hostdata->caps.flags = CAP_LIST_SUPPORTED; | 
|  | 971 | if (hostdata->client_migrated) | 
|  | 972 | hostdata->caps.flags |= CLIENT_MIGRATED; | 
|  | 973 |  | 
|  | 974 | strncpy(hostdata->caps.name, dev_name(&hostdata->host->shost_gendev), | 
|  | 975 | sizeof(hostdata->caps.name)); | 
|  | 976 | hostdata->caps.name[sizeof(hostdata->caps.name) - 1] = '\0'; | 
|  | 977 |  | 
|  | 978 | location = of_get_property(of_node, "ibm,loc-code", NULL); | 
|  | 979 | location = location ? location : dev_name(hostdata->dev); | 
|  | 980 | strncpy(hostdata->caps.loc, location, sizeof(hostdata->caps.loc)); | 
|  | 981 | hostdata->caps.loc[sizeof(hostdata->caps.loc) - 1] = '\0'; | 
|  | 982 |  | 
|  | 983 | req->common.type = VIOSRP_CAPABILITIES_TYPE; | 
|  | 984 | req->buffer = hostdata->caps_addr; | 
|  | 985 |  | 
|  | 986 | hostdata->caps.migration.common.cap_type = MIGRATION_CAPABILITIES; | 
|  | 987 | hostdata->caps.migration.common.length = sizeof(hostdata->caps.migration); | 
|  | 988 | hostdata->caps.migration.common.server_support = SERVER_SUPPORTS_CAP; | 
|  | 989 | hostdata->caps.migration.ecl = 1; | 
|  | 990 |  | 
|  | 991 | if (client_reserve) { | 
|  | 992 | hostdata->caps.reserve.common.cap_type = RESERVATION_CAPABILITIES; | 
|  | 993 | hostdata->caps.reserve.common.length = sizeof(hostdata->caps.reserve); | 
|  | 994 | hostdata->caps.reserve.common.server_support = SERVER_SUPPORTS_CAP; | 
|  | 995 | hostdata->caps.reserve.type = CLIENT_RESERVE_SCSI_2; | 
|  | 996 | req->common.length = sizeof(hostdata->caps); | 
|  | 997 | } else | 
|  | 998 | req->common.length = sizeof(hostdata->caps) - sizeof(hostdata->caps.reserve); | 
|  | 999 |  | 
|  | 1000 | spin_lock_irqsave(hostdata->host->host_lock, flags); | 
|  | 1001 | if (ibmvscsi_send_srp_event(evt_struct, hostdata, info_timeout * 2)) | 
|  | 1002 | dev_err(hostdata->dev, "couldn't send CAPABILITIES_REQ!\n"); | 
|  | 1003 | spin_unlock_irqrestore(hostdata->host->host_lock, flags); | 
|  | 1004 | }; | 
|  | 1005 |  | 
|  | 1006 | /** | 
| Robert Jennings | c1988e3 | 2009-06-08 16:19:07 -0500 | [diff] [blame] | 1007 | * fast_fail_rsp: - Handle response to MAD enable fast fail | 
|  | 1008 | * @evt_struct:	srp_event_struct with the response | 
|  | 1009 | * | 
|  | 1010 | * Used as a "done" callback by when sending enable fast fail. Gets called | 
|  | 1011 | * by ibmvscsi_handle_crq() | 
|  | 1012 | */ | 
|  | 1013 | static void fast_fail_rsp(struct srp_event_struct *evt_struct) | 
|  | 1014 | { | 
|  | 1015 | struct ibmvscsi_host_data *hostdata = evt_struct->hostdata; | 
|  | 1016 | u8 status = evt_struct->xfer_iu->mad.fast_fail.common.status; | 
|  | 1017 |  | 
|  | 1018 | if (status == VIOSRP_MAD_NOT_SUPPORTED) | 
|  | 1019 | dev_err(hostdata->dev, "fast_fail not supported in server\n"); | 
|  | 1020 | else if (status == VIOSRP_MAD_FAILED) | 
|  | 1021 | dev_err(hostdata->dev, "fast_fail request failed\n"); | 
|  | 1022 | else if (status != VIOSRP_MAD_SUCCESS) | 
|  | 1023 | dev_err(hostdata->dev, "error 0x%X enabling fast_fail\n", status); | 
|  | 1024 |  | 
| Brian King | 126c5cc | 2009-06-08 16:19:08 -0500 | [diff] [blame] | 1025 | send_mad_capabilities(hostdata); | 
| Robert Jennings | c1988e3 | 2009-06-08 16:19:07 -0500 | [diff] [blame] | 1026 | } | 
|  | 1027 |  | 
|  | 1028 | /** | 
|  | 1029 | * init_host - Start host initialization | 
|  | 1030 | * @hostdata:	ibmvscsi_host_data of host | 
|  | 1031 | * | 
|  | 1032 | * Returns zero if successful. | 
|  | 1033 | */ | 
|  | 1034 | static int enable_fast_fail(struct ibmvscsi_host_data *hostdata) | 
|  | 1035 | { | 
|  | 1036 | int rc; | 
|  | 1037 | unsigned long flags; | 
|  | 1038 | struct viosrp_fast_fail *fast_fail_mad; | 
|  | 1039 | struct srp_event_struct *evt_struct; | 
|  | 1040 |  | 
| Brian King | 126c5cc | 2009-06-08 16:19:08 -0500 | [diff] [blame] | 1041 | if (!fast_fail) { | 
|  | 1042 | send_mad_capabilities(hostdata); | 
|  | 1043 | return 0; | 
|  | 1044 | } | 
| Robert Jennings | c1988e3 | 2009-06-08 16:19:07 -0500 | [diff] [blame] | 1045 |  | 
|  | 1046 | evt_struct = get_event_struct(&hostdata->pool); | 
|  | 1047 | BUG_ON(!evt_struct); | 
|  | 1048 |  | 
|  | 1049 | init_event_struct(evt_struct, fast_fail_rsp, VIOSRP_MAD_FORMAT, info_timeout); | 
|  | 1050 |  | 
|  | 1051 | fast_fail_mad = &evt_struct->iu.mad.fast_fail; | 
|  | 1052 | memset(fast_fail_mad, 0, sizeof(*fast_fail_mad)); | 
|  | 1053 | fast_fail_mad->common.type = VIOSRP_ENABLE_FAST_FAIL; | 
|  | 1054 | fast_fail_mad->common.length = sizeof(*fast_fail_mad); | 
|  | 1055 |  | 
|  | 1056 | spin_lock_irqsave(hostdata->host->host_lock, flags); | 
|  | 1057 | rc = ibmvscsi_send_srp_event(evt_struct, hostdata, info_timeout * 2); | 
|  | 1058 | spin_unlock_irqrestore(hostdata->host->host_lock, flags); | 
|  | 1059 | return rc; | 
|  | 1060 | } | 
|  | 1061 |  | 
|  | 1062 | /** | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1063 | * adapter_info_rsp: - Handle response to MAD adapter info request | 
|  | 1064 | * @evt_struct:	srp_event_struct with the response | 
|  | 1065 | * | 
|  | 1066 | * Used as a "done" callback by when sending adapter_info. Gets called | 
|  | 1067 | * by ibmvscsi_handle_crq() | 
|  | 1068 | */ | 
|  | 1069 | static void adapter_info_rsp(struct srp_event_struct *evt_struct) | 
|  | 1070 | { | 
|  | 1071 | struct ibmvscsi_host_data *hostdata = evt_struct->hostdata; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1072 |  | 
|  | 1073 | if (evt_struct->xfer_iu->mad.adapter_info.common.status) { | 
| Brian King | 6c0a60e | 2007-06-13 17:12:19 -0500 | [diff] [blame] | 1074 | dev_err(hostdata->dev, "error %d getting adapter info\n", | 
|  | 1075 | evt_struct->xfer_iu->mad.adapter_info.common.status); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1076 | } else { | 
| Brian King | 6c0a60e | 2007-06-13 17:12:19 -0500 | [diff] [blame] | 1077 | dev_info(hostdata->dev, "host srp version: %s, " | 
|  | 1078 | "host partition %s (%d), OS %d, max io %u\n", | 
|  | 1079 | hostdata->madapter_info.srp_version, | 
|  | 1080 | hostdata->madapter_info.partition_name, | 
|  | 1081 | hostdata->madapter_info.partition_number, | 
|  | 1082 | hostdata->madapter_info.os_type, | 
|  | 1083 | hostdata->madapter_info.port_max_txu[0]); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1084 |  | 
|  | 1085 | if (hostdata->madapter_info.port_max_txu[0]) | 
|  | 1086 | hostdata->host->max_sectors = | 
|  | 1087 | hostdata->madapter_info.port_max_txu[0] >> 9; | 
| Dave C Boutcher | 154fb61 | 2005-09-13 10:09:02 -0500 | [diff] [blame] | 1088 |  | 
|  | 1089 | if (hostdata->madapter_info.os_type == 3 && | 
|  | 1090 | strcmp(hostdata->madapter_info.srp_version, "1.6a") <= 0) { | 
| Brian King | 6c0a60e | 2007-06-13 17:12:19 -0500 | [diff] [blame] | 1091 | dev_err(hostdata->dev, "host (Ver. %s) doesn't support large transfers\n", | 
|  | 1092 | hostdata->madapter_info.srp_version); | 
|  | 1093 | dev_err(hostdata->dev, "limiting scatterlists to %d\n", | 
|  | 1094 | MAX_INDIRECT_BUFS); | 
| Dave C Boutcher | 154fb61 | 2005-09-13 10:09:02 -0500 | [diff] [blame] | 1095 | hostdata->host->sg_tablesize = MAX_INDIRECT_BUFS; | 
|  | 1096 | } | 
| Brian King | e08afeb | 2009-06-23 17:14:01 -0500 | [diff] [blame] | 1097 |  | 
|  | 1098 | if (hostdata->madapter_info.os_type == 3) { | 
|  | 1099 | enable_fast_fail(hostdata); | 
|  | 1100 | return; | 
|  | 1101 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1102 | } | 
| Brian King | 3507e13 | 2009-06-08 16:19:04 -0500 | [diff] [blame] | 1103 |  | 
| Brian King | e08afeb | 2009-06-23 17:14:01 -0500 | [diff] [blame] | 1104 | send_srp_login(hostdata); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1105 | } | 
|  | 1106 |  | 
|  | 1107 | /** | 
|  | 1108 | * send_mad_adapter_info: - Sends the mad adapter info request | 
|  | 1109 | *      and stores the result so it can be retrieved with | 
|  | 1110 | *      sysfs.  We COULD consider causing a failure if the | 
|  | 1111 | *      returned SRP version doesn't match ours. | 
|  | 1112 | * @hostdata:	ibmvscsi_host_data of host | 
|  | 1113 | * | 
|  | 1114 | * Returns zero if successful. | 
|  | 1115 | */ | 
|  | 1116 | static void send_mad_adapter_info(struct ibmvscsi_host_data *hostdata) | 
|  | 1117 | { | 
|  | 1118 | struct viosrp_adapter_info *req; | 
|  | 1119 | struct srp_event_struct *evt_struct; | 
| Brian King | 06f923c | 2007-06-13 17:12:33 -0500 | [diff] [blame] | 1120 | unsigned long flags; | 
| FUJITA Tomonori | e5dbfa6 | 2006-04-14 13:52:18 +0900 | [diff] [blame] | 1121 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1122 | evt_struct = get_event_struct(&hostdata->pool); | 
| Brian King | 3507e13 | 2009-06-08 16:19:04 -0500 | [diff] [blame] | 1123 | BUG_ON(!evt_struct); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1124 |  | 
|  | 1125 | init_event_struct(evt_struct, | 
|  | 1126 | adapter_info_rsp, | 
|  | 1127 | VIOSRP_MAD_FORMAT, | 
| Robert Jennings | e1a5ce5 | 2009-06-08 16:19:03 -0500 | [diff] [blame] | 1128 | info_timeout); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1129 |  | 
|  | 1130 | req = &evt_struct->iu.mad.adapter_info; | 
|  | 1131 | memset(req, 0x00, sizeof(*req)); | 
|  | 1132 |  | 
|  | 1133 | req->common.type = VIOSRP_ADAPTER_INFO_TYPE; | 
|  | 1134 | req->common.length = sizeof(hostdata->madapter_info); | 
| Brian King | 126c5cc | 2009-06-08 16:19:08 -0500 | [diff] [blame] | 1135 | req->buffer = hostdata->adapter_info_addr; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1136 |  | 
| Brian King | 06f923c | 2007-06-13 17:12:33 -0500 | [diff] [blame] | 1137 | spin_lock_irqsave(hostdata->host->host_lock, flags); | 
| Brian King | 126c5cc | 2009-06-08 16:19:08 -0500 | [diff] [blame] | 1138 | if (ibmvscsi_send_srp_event(evt_struct, hostdata, info_timeout * 2)) | 
| Brian King | 6c0a60e | 2007-06-13 17:12:19 -0500 | [diff] [blame] | 1139 | dev_err(hostdata->dev, "couldn't send ADAPTER_INFO_REQ!\n"); | 
| Brian King | 06f923c | 2007-06-13 17:12:33 -0500 | [diff] [blame] | 1140 | spin_unlock_irqrestore(hostdata->host->host_lock, flags); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1141 | }; | 
|  | 1142 |  | 
|  | 1143 | /** | 
| Brian King | 3507e13 | 2009-06-08 16:19:04 -0500 | [diff] [blame] | 1144 | * init_adapter: Start virtual adapter initialization sequence | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1145 | * | 
| Brian King | 3507e13 | 2009-06-08 16:19:04 -0500 | [diff] [blame] | 1146 | */ | 
|  | 1147 | static void init_adapter(struct ibmvscsi_host_data *hostdata) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1148 | { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1149 | send_mad_adapter_info(hostdata); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1150 | } | 
|  | 1151 |  | 
|  | 1152 | /** | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1153 | * sync_completion: Signal that a synchronous command has completed | 
|  | 1154 | * Note that after returning from this call, the evt_struct is freed. | 
|  | 1155 | * the caller waiting on this completion shouldn't touch the evt_struct | 
|  | 1156 | * again. | 
|  | 1157 | */ | 
|  | 1158 | static void sync_completion(struct srp_event_struct *evt_struct) | 
|  | 1159 | { | 
|  | 1160 | /* copy the response back */ | 
|  | 1161 | if (evt_struct->sync_srp) | 
|  | 1162 | *evt_struct->sync_srp = *evt_struct->xfer_iu; | 
|  | 1163 |  | 
|  | 1164 | complete(&evt_struct->comp); | 
|  | 1165 | } | 
|  | 1166 |  | 
|  | 1167 | /** | 
|  | 1168 | * ibmvscsi_abort: Abort a command...from scsi host template | 
|  | 1169 | * send this over to the server and wait synchronously for the response | 
|  | 1170 | */ | 
|  | 1171 | static int ibmvscsi_eh_abort_handler(struct scsi_cmnd *cmd) | 
|  | 1172 | { | 
| FUJITA Tomonori | 7603e02 | 2007-07-23 09:28:40 +0900 | [diff] [blame] | 1173 | struct ibmvscsi_host_data *hostdata = shost_priv(cmd->device->host); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1174 | struct srp_tsk_mgmt *tsk_mgmt; | 
|  | 1175 | struct srp_event_struct *evt; | 
|  | 1176 | struct srp_event_struct *tmp_evt, *found_evt; | 
|  | 1177 | union viosrp_iu srp_rsp; | 
|  | 1178 | int rsp_rc; | 
| Dave C Boutcher | be042f2 | 2005-08-15 16:52:58 -0500 | [diff] [blame] | 1179 | unsigned long flags; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1180 | u16 lun = lun_from_dev(cmd->device); | 
| Robert Jennings | 860784c | 2007-11-12 09:00:23 -0600 | [diff] [blame] | 1181 | unsigned long wait_switch = 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1182 |  | 
|  | 1183 | /* First, find this command in our sent list so we can figure | 
|  | 1184 | * out the correct tag | 
|  | 1185 | */ | 
| Dave C Boutcher | be042f2 | 2005-08-15 16:52:58 -0500 | [diff] [blame] | 1186 | spin_lock_irqsave(hostdata->host->host_lock, flags); | 
| Robert Jennings | 860784c | 2007-11-12 09:00:23 -0600 | [diff] [blame] | 1187 | wait_switch = jiffies + (init_timeout * HZ); | 
|  | 1188 | do { | 
|  | 1189 | found_evt = NULL; | 
|  | 1190 | list_for_each_entry(tmp_evt, &hostdata->sent, list) { | 
|  | 1191 | if (tmp_evt->cmnd == cmd) { | 
|  | 1192 | found_evt = tmp_evt; | 
|  | 1193 | break; | 
|  | 1194 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1195 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1196 |  | 
| Robert Jennings | 860784c | 2007-11-12 09:00:23 -0600 | [diff] [blame] | 1197 | if (!found_evt) { | 
|  | 1198 | spin_unlock_irqrestore(hostdata->host->host_lock, flags); | 
|  | 1199 | return SUCCESS; | 
|  | 1200 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1201 |  | 
| Robert Jennings | 860784c | 2007-11-12 09:00:23 -0600 | [diff] [blame] | 1202 | evt = get_event_struct(&hostdata->pool); | 
|  | 1203 | if (evt == NULL) { | 
|  | 1204 | spin_unlock_irqrestore(hostdata->host->host_lock, flags); | 
|  | 1205 | sdev_printk(KERN_ERR, cmd->device, | 
|  | 1206 | "failed to allocate abort event\n"); | 
|  | 1207 | return FAILED; | 
|  | 1208 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1209 |  | 
| Robert Jennings | 860784c | 2007-11-12 09:00:23 -0600 | [diff] [blame] | 1210 | init_event_struct(evt, | 
|  | 1211 | sync_completion, | 
|  | 1212 | VIOSRP_SRP_FORMAT, | 
| Robert Jennings | e1a5ce5 | 2009-06-08 16:19:03 -0500 | [diff] [blame] | 1213 | abort_timeout); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1214 |  | 
| Robert Jennings | 860784c | 2007-11-12 09:00:23 -0600 | [diff] [blame] | 1215 | tsk_mgmt = &evt->iu.srp.tsk_mgmt; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1216 |  | 
| Robert Jennings | 860784c | 2007-11-12 09:00:23 -0600 | [diff] [blame] | 1217 | /* Set up an abort SRP command */ | 
|  | 1218 | memset(tsk_mgmt, 0x00, sizeof(*tsk_mgmt)); | 
|  | 1219 | tsk_mgmt->opcode = SRP_TSK_MGMT; | 
|  | 1220 | tsk_mgmt->lun = ((u64) lun) << 48; | 
|  | 1221 | tsk_mgmt->tsk_mgmt_func = SRP_TSK_ABORT_TASK; | 
|  | 1222 | tsk_mgmt->task_tag = (u64) found_evt; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1223 |  | 
| Robert Jennings | 860784c | 2007-11-12 09:00:23 -0600 | [diff] [blame] | 1224 | evt->sync_srp = &srp_rsp; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1225 |  | 
| Robert Jennings | 860784c | 2007-11-12 09:00:23 -0600 | [diff] [blame] | 1226 | init_completion(&evt->comp); | 
| Robert Jennings | e1a5ce5 | 2009-06-08 16:19:03 -0500 | [diff] [blame] | 1227 | rsp_rc = ibmvscsi_send_srp_event(evt, hostdata, abort_timeout * 2); | 
| Robert Jennings | 860784c | 2007-11-12 09:00:23 -0600 | [diff] [blame] | 1228 |  | 
|  | 1229 | if (rsp_rc != SCSI_MLQUEUE_HOST_BUSY) | 
|  | 1230 | break; | 
|  | 1231 |  | 
|  | 1232 | spin_unlock_irqrestore(hostdata->host->host_lock, flags); | 
|  | 1233 | msleep(10); | 
|  | 1234 | spin_lock_irqsave(hostdata->host->host_lock, flags); | 
|  | 1235 | } while (time_before(jiffies, wait_switch)); | 
|  | 1236 |  | 
| Dave C Boutcher | be042f2 | 2005-08-15 16:52:58 -0500 | [diff] [blame] | 1237 | spin_unlock_irqrestore(hostdata->host->host_lock, flags); | 
| Robert Jennings | 860784c | 2007-11-12 09:00:23 -0600 | [diff] [blame] | 1238 |  | 
| Dave C Boutcher | be042f2 | 2005-08-15 16:52:58 -0500 | [diff] [blame] | 1239 | if (rsp_rc != 0) { | 
| Brian King | 6c0a60e | 2007-06-13 17:12:19 -0500 | [diff] [blame] | 1240 | sdev_printk(KERN_ERR, cmd->device, | 
|  | 1241 | "failed to send abort() event. rc=%d\n", rsp_rc); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1242 | return FAILED; | 
|  | 1243 | } | 
|  | 1244 |  | 
| Robert Jennings | 860784c | 2007-11-12 09:00:23 -0600 | [diff] [blame] | 1245 | sdev_printk(KERN_INFO, cmd->device, | 
| Ingo Molnar | fe33332 | 2009-01-06 14:26:03 +0000 | [diff] [blame] | 1246 | "aborting command. lun 0x%llx, tag 0x%llx\n", | 
| Robert Jennings | 860784c | 2007-11-12 09:00:23 -0600 | [diff] [blame] | 1247 | (((u64) lun) << 48), (u64) found_evt); | 
|  | 1248 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1249 | wait_for_completion(&evt->comp); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1250 |  | 
|  | 1251 | /* make sure we got a good response */ | 
| FUJITA Tomonori | ef26567 | 2006-03-26 03:57:14 +0900 | [diff] [blame] | 1252 | if (unlikely(srp_rsp.srp.rsp.opcode != SRP_RSP)) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1253 | if (printk_ratelimit()) | 
| Brian King | 6c0a60e | 2007-06-13 17:12:19 -0500 | [diff] [blame] | 1254 | sdev_printk(KERN_WARNING, cmd->device, "abort bad SRP RSP type %d\n", | 
|  | 1255 | srp_rsp.srp.rsp.opcode); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1256 | return FAILED; | 
|  | 1257 | } | 
|  | 1258 |  | 
| FUJITA Tomonori | ef26567 | 2006-03-26 03:57:14 +0900 | [diff] [blame] | 1259 | if (srp_rsp.srp.rsp.flags & SRP_RSP_FLAG_RSPVALID) | 
|  | 1260 | rsp_rc = *((int *)srp_rsp.srp.rsp.data); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1261 | else | 
|  | 1262 | rsp_rc = srp_rsp.srp.rsp.status; | 
|  | 1263 |  | 
|  | 1264 | if (rsp_rc) { | 
|  | 1265 | if (printk_ratelimit()) | 
| Brian King | 6c0a60e | 2007-06-13 17:12:19 -0500 | [diff] [blame] | 1266 | sdev_printk(KERN_WARNING, cmd->device, | 
| Ingo Molnar | fe33332 | 2009-01-06 14:26:03 +0000 | [diff] [blame] | 1267 | "abort code %d for task tag 0x%llx\n", | 
| Brian King | 6c0a60e | 2007-06-13 17:12:19 -0500 | [diff] [blame] | 1268 | rsp_rc, tsk_mgmt->task_tag); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1269 | return FAILED; | 
|  | 1270 | } | 
|  | 1271 |  | 
|  | 1272 | /* Because we dropped the spinlock above, it's possible | 
|  | 1273 | * The event is no longer in our list.  Make sure it didn't | 
|  | 1274 | * complete while we were aborting | 
|  | 1275 | */ | 
| Dave C Boutcher | be042f2 | 2005-08-15 16:52:58 -0500 | [diff] [blame] | 1276 | spin_lock_irqsave(hostdata->host->host_lock, flags); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1277 | found_evt = NULL; | 
|  | 1278 | list_for_each_entry(tmp_evt, &hostdata->sent, list) { | 
|  | 1279 | if (tmp_evt->cmnd == cmd) { | 
|  | 1280 | found_evt = tmp_evt; | 
|  | 1281 | break; | 
|  | 1282 | } | 
|  | 1283 | } | 
|  | 1284 |  | 
|  | 1285 | if (found_evt == NULL) { | 
| Dave C Boutcher | be042f2 | 2005-08-15 16:52:58 -0500 | [diff] [blame] | 1286 | spin_unlock_irqrestore(hostdata->host->host_lock, flags); | 
| Ingo Molnar | fe33332 | 2009-01-06 14:26:03 +0000 | [diff] [blame] | 1287 | sdev_printk(KERN_INFO, cmd->device, "aborted task tag 0x%llx completed\n", | 
| Brian King | 6c0a60e | 2007-06-13 17:12:19 -0500 | [diff] [blame] | 1288 | tsk_mgmt->task_tag); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1289 | return SUCCESS; | 
|  | 1290 | } | 
|  | 1291 |  | 
| Ingo Molnar | fe33332 | 2009-01-06 14:26:03 +0000 | [diff] [blame] | 1292 | sdev_printk(KERN_INFO, cmd->device, "successfully aborted task tag 0x%llx\n", | 
| Brian King | 6c0a60e | 2007-06-13 17:12:19 -0500 | [diff] [blame] | 1293 | tsk_mgmt->task_tag); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1294 |  | 
|  | 1295 | cmd->result = (DID_ABORT << 16); | 
|  | 1296 | list_del(&found_evt->list); | 
| James Bottomley | 4dddbc2 | 2005-09-06 17:11:54 -0500 | [diff] [blame] | 1297 | unmap_cmd_data(&found_evt->iu.srp.cmd, found_evt, | 
|  | 1298 | found_evt->hostdata->dev); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1299 | free_event_struct(&found_evt->hostdata->pool, found_evt); | 
| Dave C Boutcher | be042f2 | 2005-08-15 16:52:58 -0500 | [diff] [blame] | 1300 | spin_unlock_irqrestore(hostdata->host->host_lock, flags); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1301 | atomic_inc(&hostdata->request_limit); | 
|  | 1302 | return SUCCESS; | 
|  | 1303 | } | 
|  | 1304 |  | 
|  | 1305 | /** | 
|  | 1306 | * ibmvscsi_eh_device_reset_handler: Reset a single LUN...from scsi host | 
|  | 1307 | * template send this over to the server and wait synchronously for the | 
|  | 1308 | * response | 
|  | 1309 | */ | 
|  | 1310 | static int ibmvscsi_eh_device_reset_handler(struct scsi_cmnd *cmd) | 
|  | 1311 | { | 
| FUJITA Tomonori | 7603e02 | 2007-07-23 09:28:40 +0900 | [diff] [blame] | 1312 | struct ibmvscsi_host_data *hostdata = shost_priv(cmd->device->host); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1313 | struct srp_tsk_mgmt *tsk_mgmt; | 
|  | 1314 | struct srp_event_struct *evt; | 
|  | 1315 | struct srp_event_struct *tmp_evt, *pos; | 
|  | 1316 | union viosrp_iu srp_rsp; | 
|  | 1317 | int rsp_rc; | 
| Dave C Boutcher | be042f2 | 2005-08-15 16:52:58 -0500 | [diff] [blame] | 1318 | unsigned long flags; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1319 | u16 lun = lun_from_dev(cmd->device); | 
| Robert Jennings | 860784c | 2007-11-12 09:00:23 -0600 | [diff] [blame] | 1320 | unsigned long wait_switch = 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1321 |  | 
| Dave C Boutcher | be042f2 | 2005-08-15 16:52:58 -0500 | [diff] [blame] | 1322 | spin_lock_irqsave(hostdata->host->host_lock, flags); | 
| Robert Jennings | 860784c | 2007-11-12 09:00:23 -0600 | [diff] [blame] | 1323 | wait_switch = jiffies + (init_timeout * HZ); | 
|  | 1324 | do { | 
|  | 1325 | evt = get_event_struct(&hostdata->pool); | 
|  | 1326 | if (evt == NULL) { | 
|  | 1327 | spin_unlock_irqrestore(hostdata->host->host_lock, flags); | 
|  | 1328 | sdev_printk(KERN_ERR, cmd->device, | 
|  | 1329 | "failed to allocate reset event\n"); | 
|  | 1330 | return FAILED; | 
|  | 1331 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1332 |  | 
| Robert Jennings | 860784c | 2007-11-12 09:00:23 -0600 | [diff] [blame] | 1333 | init_event_struct(evt, | 
|  | 1334 | sync_completion, | 
|  | 1335 | VIOSRP_SRP_FORMAT, | 
| Robert Jennings | e1a5ce5 | 2009-06-08 16:19:03 -0500 | [diff] [blame] | 1336 | reset_timeout); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1337 |  | 
| Robert Jennings | 860784c | 2007-11-12 09:00:23 -0600 | [diff] [blame] | 1338 | tsk_mgmt = &evt->iu.srp.tsk_mgmt; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1339 |  | 
| Robert Jennings | 860784c | 2007-11-12 09:00:23 -0600 | [diff] [blame] | 1340 | /* Set up a lun reset SRP command */ | 
|  | 1341 | memset(tsk_mgmt, 0x00, sizeof(*tsk_mgmt)); | 
|  | 1342 | tsk_mgmt->opcode = SRP_TSK_MGMT; | 
|  | 1343 | tsk_mgmt->lun = ((u64) lun) << 48; | 
|  | 1344 | tsk_mgmt->tsk_mgmt_func = SRP_TSK_LUN_RESET; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1345 |  | 
| Robert Jennings | 860784c | 2007-11-12 09:00:23 -0600 | [diff] [blame] | 1346 | evt->sync_srp = &srp_rsp; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1347 |  | 
| Robert Jennings | 860784c | 2007-11-12 09:00:23 -0600 | [diff] [blame] | 1348 | init_completion(&evt->comp); | 
| Robert Jennings | e1a5ce5 | 2009-06-08 16:19:03 -0500 | [diff] [blame] | 1349 | rsp_rc = ibmvscsi_send_srp_event(evt, hostdata, reset_timeout * 2); | 
| Robert Jennings | 860784c | 2007-11-12 09:00:23 -0600 | [diff] [blame] | 1350 |  | 
|  | 1351 | if (rsp_rc != SCSI_MLQUEUE_HOST_BUSY) | 
|  | 1352 | break; | 
|  | 1353 |  | 
|  | 1354 | spin_unlock_irqrestore(hostdata->host->host_lock, flags); | 
|  | 1355 | msleep(10); | 
|  | 1356 | spin_lock_irqsave(hostdata->host->host_lock, flags); | 
|  | 1357 | } while (time_before(jiffies, wait_switch)); | 
|  | 1358 |  | 
| Dave C Boutcher | be042f2 | 2005-08-15 16:52:58 -0500 | [diff] [blame] | 1359 | spin_unlock_irqrestore(hostdata->host->host_lock, flags); | 
| Robert Jennings | 860784c | 2007-11-12 09:00:23 -0600 | [diff] [blame] | 1360 |  | 
| Dave C Boutcher | be042f2 | 2005-08-15 16:52:58 -0500 | [diff] [blame] | 1361 | if (rsp_rc != 0) { | 
| Brian King | 6c0a60e | 2007-06-13 17:12:19 -0500 | [diff] [blame] | 1362 | sdev_printk(KERN_ERR, cmd->device, | 
|  | 1363 | "failed to send reset event. rc=%d\n", rsp_rc); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1364 | return FAILED; | 
|  | 1365 | } | 
|  | 1366 |  | 
| Ingo Molnar | fe33332 | 2009-01-06 14:26:03 +0000 | [diff] [blame] | 1367 | sdev_printk(KERN_INFO, cmd->device, "resetting device. lun 0x%llx\n", | 
| Robert Jennings | 860784c | 2007-11-12 09:00:23 -0600 | [diff] [blame] | 1368 | (((u64) lun) << 48)); | 
|  | 1369 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1370 | wait_for_completion(&evt->comp); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1371 |  | 
|  | 1372 | /* make sure we got a good response */ | 
| FUJITA Tomonori | ef26567 | 2006-03-26 03:57:14 +0900 | [diff] [blame] | 1373 | if (unlikely(srp_rsp.srp.rsp.opcode != SRP_RSP)) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1374 | if (printk_ratelimit()) | 
| Brian King | 6c0a60e | 2007-06-13 17:12:19 -0500 | [diff] [blame] | 1375 | sdev_printk(KERN_WARNING, cmd->device, "reset bad SRP RSP type %d\n", | 
|  | 1376 | srp_rsp.srp.rsp.opcode); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1377 | return FAILED; | 
|  | 1378 | } | 
|  | 1379 |  | 
| FUJITA Tomonori | ef26567 | 2006-03-26 03:57:14 +0900 | [diff] [blame] | 1380 | if (srp_rsp.srp.rsp.flags & SRP_RSP_FLAG_RSPVALID) | 
|  | 1381 | rsp_rc = *((int *)srp_rsp.srp.rsp.data); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1382 | else | 
|  | 1383 | rsp_rc = srp_rsp.srp.rsp.status; | 
|  | 1384 |  | 
|  | 1385 | if (rsp_rc) { | 
|  | 1386 | if (printk_ratelimit()) | 
| Brian King | 6c0a60e | 2007-06-13 17:12:19 -0500 | [diff] [blame] | 1387 | sdev_printk(KERN_WARNING, cmd->device, | 
| Ingo Molnar | fe33332 | 2009-01-06 14:26:03 +0000 | [diff] [blame] | 1388 | "reset code %d for task tag 0x%llx\n", | 
| Brian King | 6c0a60e | 2007-06-13 17:12:19 -0500 | [diff] [blame] | 1389 | rsp_rc, tsk_mgmt->task_tag); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1390 | return FAILED; | 
|  | 1391 | } | 
|  | 1392 |  | 
|  | 1393 | /* We need to find all commands for this LUN that have not yet been | 
|  | 1394 | * responded to, and fail them with DID_RESET | 
|  | 1395 | */ | 
| Dave C Boutcher | be042f2 | 2005-08-15 16:52:58 -0500 | [diff] [blame] | 1396 | spin_lock_irqsave(hostdata->host->host_lock, flags); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1397 | list_for_each_entry_safe(tmp_evt, pos, &hostdata->sent, list) { | 
|  | 1398 | if ((tmp_evt->cmnd) && (tmp_evt->cmnd->device == cmd->device)) { | 
|  | 1399 | if (tmp_evt->cmnd) | 
|  | 1400 | tmp_evt->cmnd->result = (DID_RESET << 16); | 
|  | 1401 | list_del(&tmp_evt->list); | 
| James Bottomley | 4dddbc2 | 2005-09-06 17:11:54 -0500 | [diff] [blame] | 1402 | unmap_cmd_data(&tmp_evt->iu.srp.cmd, tmp_evt, | 
|  | 1403 | tmp_evt->hostdata->dev); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1404 | free_event_struct(&tmp_evt->hostdata->pool, | 
|  | 1405 | tmp_evt); | 
|  | 1406 | atomic_inc(&hostdata->request_limit); | 
|  | 1407 | if (tmp_evt->cmnd_done) | 
|  | 1408 | tmp_evt->cmnd_done(tmp_evt->cmnd); | 
|  | 1409 | else if (tmp_evt->done) | 
|  | 1410 | tmp_evt->done(tmp_evt); | 
|  | 1411 | } | 
|  | 1412 | } | 
| Dave C Boutcher | be042f2 | 2005-08-15 16:52:58 -0500 | [diff] [blame] | 1413 | spin_unlock_irqrestore(hostdata->host->host_lock, flags); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1414 | return SUCCESS; | 
|  | 1415 | } | 
|  | 1416 |  | 
|  | 1417 | /** | 
| Brian King | 3d0e91f | 2007-06-13 17:12:26 -0500 | [diff] [blame] | 1418 | * ibmvscsi_eh_host_reset_handler - Reset the connection to the server | 
|  | 1419 | * @cmd:	struct scsi_cmnd having problems | 
|  | 1420 | */ | 
|  | 1421 | static int ibmvscsi_eh_host_reset_handler(struct scsi_cmnd *cmd) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1422 | { | 
| Brian King | 3d0e91f | 2007-06-13 17:12:26 -0500 | [diff] [blame] | 1423 | unsigned long wait_switch = 0; | 
| FUJITA Tomonori | 7603e02 | 2007-07-23 09:28:40 +0900 | [diff] [blame] | 1424 | struct ibmvscsi_host_data *hostdata = shost_priv(cmd->device->host); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1425 |  | 
| Brian King | 3d0e91f | 2007-06-13 17:12:26 -0500 | [diff] [blame] | 1426 | dev_err(hostdata->dev, "Resetting connection due to error recovery\n"); | 
|  | 1427 |  | 
|  | 1428 | ibmvscsi_reset_host(hostdata); | 
|  | 1429 |  | 
|  | 1430 | for (wait_switch = jiffies + (init_timeout * HZ); | 
|  | 1431 | time_before(jiffies, wait_switch) && | 
|  | 1432 | atomic_read(&hostdata->request_limit) < 2;) { | 
|  | 1433 |  | 
|  | 1434 | msleep(10); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1435 | } | 
| Brian King | 3d0e91f | 2007-06-13 17:12:26 -0500 | [diff] [blame] | 1436 |  | 
|  | 1437 | if (atomic_read(&hostdata->request_limit) <= 0) | 
|  | 1438 | return FAILED; | 
|  | 1439 |  | 
|  | 1440 | return SUCCESS; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1441 | } | 
|  | 1442 |  | 
|  | 1443 | /** | 
|  | 1444 | * ibmvscsi_handle_crq: - Handles and frees received events in the CRQ | 
|  | 1445 | * @crq:	Command/Response queue | 
|  | 1446 | * @hostdata:	ibmvscsi_host_data of host | 
|  | 1447 | * | 
|  | 1448 | */ | 
|  | 1449 | void ibmvscsi_handle_crq(struct viosrp_crq *crq, | 
|  | 1450 | struct ibmvscsi_host_data *hostdata) | 
|  | 1451 | { | 
| Brian King | 6c0a60e | 2007-06-13 17:12:19 -0500 | [diff] [blame] | 1452 | long rc; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1453 | unsigned long flags; | 
|  | 1454 | struct srp_event_struct *evt_struct = | 
|  | 1455 | (struct srp_event_struct *)crq->IU_data_ptr; | 
|  | 1456 | switch (crq->valid) { | 
|  | 1457 | case 0xC0:		/* initialization */ | 
|  | 1458 | switch (crq->format) { | 
|  | 1459 | case 0x01:	/* Initialization message */ | 
| Brian King | 6c0a60e | 2007-06-13 17:12:19 -0500 | [diff] [blame] | 1460 | dev_info(hostdata->dev, "partner initialized\n"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1461 | /* Send back a response */ | 
| David Woodhouse | d3849d5 | 2007-09-22 08:29:36 +1000 | [diff] [blame] | 1462 | if ((rc = ibmvscsi_ops->send_crq(hostdata, | 
|  | 1463 | 0xC002000000000000LL, 0)) == 0) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1464 | /* Now login */ | 
| Brian King | 3507e13 | 2009-06-08 16:19:04 -0500 | [diff] [blame] | 1465 | init_adapter(hostdata); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1466 | } else { | 
| Brian King | 6c0a60e | 2007-06-13 17:12:19 -0500 | [diff] [blame] | 1467 | dev_err(hostdata->dev, "Unable to send init rsp. rc=%ld\n", rc); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1468 | } | 
|  | 1469 |  | 
|  | 1470 | break; | 
|  | 1471 | case 0x02:	/* Initialization response */ | 
| Brian King | 6c0a60e | 2007-06-13 17:12:19 -0500 | [diff] [blame] | 1472 | dev_info(hostdata->dev, "partner initialization complete\n"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1473 |  | 
|  | 1474 | /* Now login */ | 
| Brian King | 3507e13 | 2009-06-08 16:19:04 -0500 | [diff] [blame] | 1475 | init_adapter(hostdata); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1476 | break; | 
|  | 1477 | default: | 
| Brian King | 6c0a60e | 2007-06-13 17:12:19 -0500 | [diff] [blame] | 1478 | dev_err(hostdata->dev, "unknown crq message type: %d\n", crq->format); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1479 | } | 
|  | 1480 | return; | 
| Dave C Boutcher | 2b541f8 | 2006-01-19 13:34:44 -0600 | [diff] [blame] | 1481 | case 0xFF:	/* Hypervisor telling us the connection is closed */ | 
|  | 1482 | scsi_block_requests(hostdata->host); | 
| Dave C Boutcher | cefbda2 | 2006-06-12 21:22:51 -0500 | [diff] [blame] | 1483 | atomic_set(&hostdata->request_limit, 0); | 
| Dave C Boutcher | 2b541f8 | 2006-01-19 13:34:44 -0600 | [diff] [blame] | 1484 | if (crq->format == 0x06) { | 
|  | 1485 | /* We need to re-setup the interpartition connection */ | 
| Brian King | 6c0a60e | 2007-06-13 17:12:19 -0500 | [diff] [blame] | 1486 | dev_info(hostdata->dev, "Re-enabling adapter!\n"); | 
| Brian King | 126c5cc | 2009-06-08 16:19:08 -0500 | [diff] [blame] | 1487 | hostdata->client_migrated = 1; | 
| Dave C Boutcher | 2b541f8 | 2006-01-19 13:34:44 -0600 | [diff] [blame] | 1488 | purge_requests(hostdata, DID_REQUEUE); | 
| David Woodhouse | d3849d5 | 2007-09-22 08:29:36 +1000 | [diff] [blame] | 1489 | if ((ibmvscsi_ops->reenable_crq_queue(&hostdata->queue, | 
|  | 1490 | hostdata)) || | 
|  | 1491 | (ibmvscsi_ops->send_crq(hostdata, | 
|  | 1492 | 0xC001000000000000LL, 0))) { | 
| Dave C Boutcher | cefbda2 | 2006-06-12 21:22:51 -0500 | [diff] [blame] | 1493 | atomic_set(&hostdata->request_limit, | 
|  | 1494 | -1); | 
| Brian King | 6c0a60e | 2007-06-13 17:12:19 -0500 | [diff] [blame] | 1495 | dev_err(hostdata->dev, "error after enable\n"); | 
| Dave C Boutcher | cefbda2 | 2006-06-12 21:22:51 -0500 | [diff] [blame] | 1496 | } | 
| Dave C Boutcher | 2b541f8 | 2006-01-19 13:34:44 -0600 | [diff] [blame] | 1497 | } else { | 
| Brian King | 6c0a60e | 2007-06-13 17:12:19 -0500 | [diff] [blame] | 1498 | dev_err(hostdata->dev, "Virtual adapter failed rc %d!\n", | 
|  | 1499 | crq->format); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1500 |  | 
| Dave C Boutcher | 2b541f8 | 2006-01-19 13:34:44 -0600 | [diff] [blame] | 1501 | purge_requests(hostdata, DID_ERROR); | 
| David Woodhouse | d3849d5 | 2007-09-22 08:29:36 +1000 | [diff] [blame] | 1502 | if ((ibmvscsi_ops->reset_crq_queue(&hostdata->queue, | 
|  | 1503 | hostdata)) || | 
|  | 1504 | (ibmvscsi_ops->send_crq(hostdata, | 
|  | 1505 | 0xC001000000000000LL, 0))) { | 
| Dave C Boutcher | cefbda2 | 2006-06-12 21:22:51 -0500 | [diff] [blame] | 1506 | atomic_set(&hostdata->request_limit, | 
|  | 1507 | -1); | 
| Brian King | 6c0a60e | 2007-06-13 17:12:19 -0500 | [diff] [blame] | 1508 | dev_err(hostdata->dev, "error after reset\n"); | 
| Dave C Boutcher | cefbda2 | 2006-06-12 21:22:51 -0500 | [diff] [blame] | 1509 | } | 
| Dave C Boutcher | 2b541f8 | 2006-01-19 13:34:44 -0600 | [diff] [blame] | 1510 | } | 
|  | 1511 | scsi_unblock_requests(hostdata->host); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1512 | return; | 
|  | 1513 | case 0x80:		/* real payload */ | 
|  | 1514 | break; | 
|  | 1515 | default: | 
| Brian King | 6c0a60e | 2007-06-13 17:12:19 -0500 | [diff] [blame] | 1516 | dev_err(hostdata->dev, "got an invalid message type 0x%02x\n", | 
|  | 1517 | crq->valid); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1518 | return; | 
|  | 1519 | } | 
|  | 1520 |  | 
|  | 1521 | /* The only kind of payload CRQs we should get are responses to | 
|  | 1522 | * things we send. Make sure this response is to something we | 
|  | 1523 | * actually sent | 
|  | 1524 | */ | 
|  | 1525 | if (!valid_event_struct(&hostdata->pool, evt_struct)) { | 
| Brian King | 6c0a60e | 2007-06-13 17:12:19 -0500 | [diff] [blame] | 1526 | dev_err(hostdata->dev, "returned correlation_token 0x%p is invalid!\n", | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1527 | (void *)crq->IU_data_ptr); | 
|  | 1528 | return; | 
|  | 1529 | } | 
|  | 1530 |  | 
|  | 1531 | if (atomic_read(&evt_struct->free)) { | 
| Brian King | 6c0a60e | 2007-06-13 17:12:19 -0500 | [diff] [blame] | 1532 | dev_err(hostdata->dev, "received duplicate correlation_token 0x%p!\n", | 
|  | 1533 | (void *)crq->IU_data_ptr); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1534 | return; | 
|  | 1535 | } | 
|  | 1536 |  | 
|  | 1537 | if (crq->format == VIOSRP_SRP_FORMAT) | 
| FUJITA Tomonori | ef26567 | 2006-03-26 03:57:14 +0900 | [diff] [blame] | 1538 | atomic_add(evt_struct->xfer_iu->srp.rsp.req_lim_delta, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1539 | &hostdata->request_limit); | 
|  | 1540 |  | 
| Brian King | 3d0e91f | 2007-06-13 17:12:26 -0500 | [diff] [blame] | 1541 | del_timer(&evt_struct->timer); | 
|  | 1542 |  | 
| Brian King | ca61668 | 2008-05-19 10:27:56 -0500 | [diff] [blame] | 1543 | if ((crq->status != VIOSRP_OK && crq->status != VIOSRP_OK2) && evt_struct->cmnd) | 
| Brian King | c3a3b55 | 2008-04-25 16:58:29 -0500 | [diff] [blame] | 1544 | evt_struct->cmnd->result = DID_ERROR << 16; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1545 | if (evt_struct->done) | 
|  | 1546 | evt_struct->done(evt_struct); | 
|  | 1547 | else | 
| Brian King | 6c0a60e | 2007-06-13 17:12:19 -0500 | [diff] [blame] | 1548 | dev_err(hostdata->dev, "returned done() is NULL; not running it!\n"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1549 |  | 
|  | 1550 | /* | 
|  | 1551 | * Lock the host_lock before messing with these structures, since we | 
|  | 1552 | * are running in a task context | 
|  | 1553 | */ | 
|  | 1554 | spin_lock_irqsave(evt_struct->hostdata->host->host_lock, flags); | 
|  | 1555 | list_del(&evt_struct->list); | 
|  | 1556 | free_event_struct(&evt_struct->hostdata->pool, evt_struct); | 
|  | 1557 | spin_unlock_irqrestore(evt_struct->hostdata->host->host_lock, flags); | 
|  | 1558 | } | 
|  | 1559 |  | 
|  | 1560 | /** | 
|  | 1561 | * ibmvscsi_get_host_config: Send the command to the server to get host | 
|  | 1562 | * configuration data.  The data is opaque to us. | 
|  | 1563 | */ | 
|  | 1564 | static int ibmvscsi_do_host_config(struct ibmvscsi_host_data *hostdata, | 
|  | 1565 | unsigned char *buffer, int length) | 
|  | 1566 | { | 
|  | 1567 | struct viosrp_host_config *host_config; | 
|  | 1568 | struct srp_event_struct *evt_struct; | 
| Brian King | 06f923c | 2007-06-13 17:12:33 -0500 | [diff] [blame] | 1569 | unsigned long flags; | 
| FUJITA Tomonori | e5dbfa6 | 2006-04-14 13:52:18 +0900 | [diff] [blame] | 1570 | dma_addr_t addr; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1571 | int rc; | 
|  | 1572 |  | 
|  | 1573 | evt_struct = get_event_struct(&hostdata->pool); | 
|  | 1574 | if (!evt_struct) { | 
| Brian King | 6c0a60e | 2007-06-13 17:12:19 -0500 | [diff] [blame] | 1575 | dev_err(hostdata->dev, "couldn't allocate event for HOST_CONFIG!\n"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1576 | return -1; | 
|  | 1577 | } | 
|  | 1578 |  | 
|  | 1579 | init_event_struct(evt_struct, | 
|  | 1580 | sync_completion, | 
|  | 1581 | VIOSRP_MAD_FORMAT, | 
| Robert Jennings | e1a5ce5 | 2009-06-08 16:19:03 -0500 | [diff] [blame] | 1582 | info_timeout); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1583 |  | 
|  | 1584 | host_config = &evt_struct->iu.mad.host_config; | 
|  | 1585 |  | 
|  | 1586 | /* Set up a lun reset SRP command */ | 
|  | 1587 | memset(host_config, 0x00, sizeof(*host_config)); | 
|  | 1588 | host_config->common.type = VIOSRP_HOST_CONFIG_TYPE; | 
|  | 1589 | host_config->common.length = length; | 
| FUJITA Tomonori | e5dbfa6 | 2006-04-14 13:52:18 +0900 | [diff] [blame] | 1590 | host_config->buffer = addr = dma_map_single(hostdata->dev, buffer, | 
|  | 1591 | length, | 
|  | 1592 | DMA_BIDIRECTIONAL); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1593 |  | 
| FUJITA Tomonori | 8d8bb39 | 2008-07-25 19:44:49 -0700 | [diff] [blame] | 1594 | if (dma_mapping_error(hostdata->dev, host_config->buffer)) { | 
| Robert Jennings | 7912a0a | 2008-07-24 04:35:27 +1000 | [diff] [blame] | 1595 | if (!firmware_has_feature(FW_FEATURE_CMO)) | 
|  | 1596 | dev_err(hostdata->dev, | 
|  | 1597 | "dma_mapping error getting host config\n"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1598 | free_event_struct(&hostdata->pool, evt_struct); | 
|  | 1599 | return -1; | 
|  | 1600 | } | 
|  | 1601 |  | 
|  | 1602 | init_completion(&evt_struct->comp); | 
| Brian King | 06f923c | 2007-06-13 17:12:33 -0500 | [diff] [blame] | 1603 | spin_lock_irqsave(hostdata->host->host_lock, flags); | 
| Robert Jennings | e1a5ce5 | 2009-06-08 16:19:03 -0500 | [diff] [blame] | 1604 | rc = ibmvscsi_send_srp_event(evt_struct, hostdata, info_timeout * 2); | 
| Brian King | 06f923c | 2007-06-13 17:12:33 -0500 | [diff] [blame] | 1605 | spin_unlock_irqrestore(hostdata->host->host_lock, flags); | 
| FUJITA Tomonori | e5dbfa6 | 2006-04-14 13:52:18 +0900 | [diff] [blame] | 1606 | if (rc == 0) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1607 | wait_for_completion(&evt_struct->comp); | 
| FUJITA Tomonori | e5dbfa6 | 2006-04-14 13:52:18 +0900 | [diff] [blame] | 1608 | dma_unmap_single(hostdata->dev, addr, length, DMA_BIDIRECTIONAL); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1609 |  | 
|  | 1610 | return rc; | 
|  | 1611 | } | 
|  | 1612 |  | 
| Robert Jennings | 0979c84 | 2007-03-29 12:30:40 -0500 | [diff] [blame] | 1613 | /** | 
|  | 1614 | * ibmvscsi_slave_configure: Set the "allow_restart" flag for each disk. | 
|  | 1615 | * @sdev:	struct scsi_device device to configure | 
|  | 1616 | * | 
|  | 1617 | * Enable allow_restart for a device if it is a disk.  Adjust the | 
|  | 1618 | * queue_depth here also as is required by the documentation for | 
|  | 1619 | * struct scsi_host_template. | 
|  | 1620 | */ | 
|  | 1621 | static int ibmvscsi_slave_configure(struct scsi_device *sdev) | 
|  | 1622 | { | 
|  | 1623 | struct Scsi_Host *shost = sdev->host; | 
|  | 1624 | unsigned long lock_flags = 0; | 
|  | 1625 |  | 
|  | 1626 | spin_lock_irqsave(shost->host_lock, lock_flags); | 
| Brian King | d1a357f | 2007-10-25 16:06:34 -0500 | [diff] [blame] | 1627 | if (sdev->type == TYPE_DISK) { | 
| Robert Jennings | 0979c84 | 2007-03-29 12:30:40 -0500 | [diff] [blame] | 1628 | sdev->allow_restart = 1; | 
| Robert Jennings | e1a5ce5 | 2009-06-08 16:19:03 -0500 | [diff] [blame] | 1629 | blk_queue_rq_timeout(sdev->request_queue, 120 * HZ); | 
| Brian King | d1a357f | 2007-10-25 16:06:34 -0500 | [diff] [blame] | 1630 | } | 
| Robert Jennings | 0979c84 | 2007-03-29 12:30:40 -0500 | [diff] [blame] | 1631 | scsi_adjust_queue_depth(sdev, 0, shost->cmd_per_lun); | 
|  | 1632 | spin_unlock_irqrestore(shost->host_lock, lock_flags); | 
|  | 1633 | return 0; | 
|  | 1634 | } | 
|  | 1635 |  | 
| Brian King | 742d25b | 2007-05-29 15:46:14 -0500 | [diff] [blame] | 1636 | /** | 
|  | 1637 | * ibmvscsi_change_queue_depth - Change the device's queue depth | 
|  | 1638 | * @sdev:	scsi device struct | 
|  | 1639 | * @qdepth:	depth to set | 
| Mike Christie | e881a17 | 2009-10-15 17:46:39 -0700 | [diff] [blame] | 1640 | * @reason:	calling context | 
| Brian King | 742d25b | 2007-05-29 15:46:14 -0500 | [diff] [blame] | 1641 | * | 
|  | 1642 | * Return value: | 
|  | 1643 | * 	actual depth set | 
|  | 1644 | **/ | 
| Mike Christie | e881a17 | 2009-10-15 17:46:39 -0700 | [diff] [blame] | 1645 | static int ibmvscsi_change_queue_depth(struct scsi_device *sdev, int qdepth, | 
|  | 1646 | int reason) | 
| Brian King | 742d25b | 2007-05-29 15:46:14 -0500 | [diff] [blame] | 1647 | { | 
| Mike Christie | e881a17 | 2009-10-15 17:46:39 -0700 | [diff] [blame] | 1648 | if (reason != SCSI_QDEPTH_DEFAULT) | 
|  | 1649 | return -EOPNOTSUPP; | 
|  | 1650 |  | 
| Brian King | 742d25b | 2007-05-29 15:46:14 -0500 | [diff] [blame] | 1651 | if (qdepth > IBMVSCSI_MAX_CMDS_PER_LUN) | 
|  | 1652 | qdepth = IBMVSCSI_MAX_CMDS_PER_LUN; | 
|  | 1653 |  | 
|  | 1654 | scsi_adjust_queue_depth(sdev, 0, qdepth); | 
|  | 1655 | return sdev->queue_depth; | 
|  | 1656 | } | 
|  | 1657 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1658 | /* ------------------------------------------------------------ | 
|  | 1659 | * sysfs attributes | 
|  | 1660 | */ | 
| Brian King | 126c5cc | 2009-06-08 16:19:08 -0500 | [diff] [blame] | 1661 | static ssize_t show_host_vhost_loc(struct device *dev, | 
|  | 1662 | struct device_attribute *attr, char *buf) | 
|  | 1663 | { | 
|  | 1664 | struct Scsi_Host *shost = class_to_shost(dev); | 
|  | 1665 | struct ibmvscsi_host_data *hostdata = shost_priv(shost); | 
|  | 1666 | int len; | 
|  | 1667 |  | 
|  | 1668 | len = snprintf(buf, sizeof(hostdata->caps.loc), "%s\n", | 
|  | 1669 | hostdata->caps.loc); | 
|  | 1670 | return len; | 
|  | 1671 | } | 
|  | 1672 |  | 
|  | 1673 | static struct device_attribute ibmvscsi_host_vhost_loc = { | 
|  | 1674 | .attr = { | 
|  | 1675 | .name = "vhost_loc", | 
|  | 1676 | .mode = S_IRUGO, | 
|  | 1677 | }, | 
|  | 1678 | .show = show_host_vhost_loc, | 
|  | 1679 | }; | 
|  | 1680 |  | 
|  | 1681 | static ssize_t show_host_vhost_name(struct device *dev, | 
|  | 1682 | struct device_attribute *attr, char *buf) | 
|  | 1683 | { | 
|  | 1684 | struct Scsi_Host *shost = class_to_shost(dev); | 
|  | 1685 | struct ibmvscsi_host_data *hostdata = shost_priv(shost); | 
|  | 1686 | int len; | 
|  | 1687 |  | 
|  | 1688 | len = snprintf(buf, sizeof(hostdata->caps.name), "%s\n", | 
|  | 1689 | hostdata->caps.name); | 
|  | 1690 | return len; | 
|  | 1691 | } | 
|  | 1692 |  | 
|  | 1693 | static struct device_attribute ibmvscsi_host_vhost_name = { | 
|  | 1694 | .attr = { | 
|  | 1695 | .name = "vhost_name", | 
|  | 1696 | .mode = S_IRUGO, | 
|  | 1697 | }, | 
|  | 1698 | .show = show_host_vhost_name, | 
|  | 1699 | }; | 
|  | 1700 |  | 
| Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1701 | static ssize_t show_host_srp_version(struct device *dev, | 
|  | 1702 | struct device_attribute *attr, char *buf) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1703 | { | 
| Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1704 | struct Scsi_Host *shost = class_to_shost(dev); | 
| FUJITA Tomonori | 7603e02 | 2007-07-23 09:28:40 +0900 | [diff] [blame] | 1705 | struct ibmvscsi_host_data *hostdata = shost_priv(shost); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1706 | int len; | 
|  | 1707 |  | 
|  | 1708 | len = snprintf(buf, PAGE_SIZE, "%s\n", | 
|  | 1709 | hostdata->madapter_info.srp_version); | 
|  | 1710 | return len; | 
|  | 1711 | } | 
|  | 1712 |  | 
| Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1713 | static struct device_attribute ibmvscsi_host_srp_version = { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1714 | .attr = { | 
|  | 1715 | .name = "srp_version", | 
|  | 1716 | .mode = S_IRUGO, | 
|  | 1717 | }, | 
|  | 1718 | .show = show_host_srp_version, | 
|  | 1719 | }; | 
|  | 1720 |  | 
| Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1721 | static ssize_t show_host_partition_name(struct device *dev, | 
|  | 1722 | struct device_attribute *attr, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1723 | char *buf) | 
|  | 1724 | { | 
| Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1725 | struct Scsi_Host *shost = class_to_shost(dev); | 
| FUJITA Tomonori | 7603e02 | 2007-07-23 09:28:40 +0900 | [diff] [blame] | 1726 | struct ibmvscsi_host_data *hostdata = shost_priv(shost); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1727 | int len; | 
|  | 1728 |  | 
|  | 1729 | len = snprintf(buf, PAGE_SIZE, "%s\n", | 
|  | 1730 | hostdata->madapter_info.partition_name); | 
|  | 1731 | return len; | 
|  | 1732 | } | 
|  | 1733 |  | 
| Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1734 | static struct device_attribute ibmvscsi_host_partition_name = { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1735 | .attr = { | 
|  | 1736 | .name = "partition_name", | 
|  | 1737 | .mode = S_IRUGO, | 
|  | 1738 | }, | 
|  | 1739 | .show = show_host_partition_name, | 
|  | 1740 | }; | 
|  | 1741 |  | 
| Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1742 | static ssize_t show_host_partition_number(struct device *dev, | 
|  | 1743 | struct device_attribute *attr, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1744 | char *buf) | 
|  | 1745 | { | 
| Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1746 | struct Scsi_Host *shost = class_to_shost(dev); | 
| FUJITA Tomonori | 7603e02 | 2007-07-23 09:28:40 +0900 | [diff] [blame] | 1747 | struct ibmvscsi_host_data *hostdata = shost_priv(shost); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1748 | int len; | 
|  | 1749 |  | 
|  | 1750 | len = snprintf(buf, PAGE_SIZE, "%d\n", | 
|  | 1751 | hostdata->madapter_info.partition_number); | 
|  | 1752 | return len; | 
|  | 1753 | } | 
|  | 1754 |  | 
| Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1755 | static struct device_attribute ibmvscsi_host_partition_number = { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1756 | .attr = { | 
|  | 1757 | .name = "partition_number", | 
|  | 1758 | .mode = S_IRUGO, | 
|  | 1759 | }, | 
|  | 1760 | .show = show_host_partition_number, | 
|  | 1761 | }; | 
|  | 1762 |  | 
| Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1763 | static ssize_t show_host_mad_version(struct device *dev, | 
|  | 1764 | struct device_attribute *attr, char *buf) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1765 | { | 
| Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1766 | struct Scsi_Host *shost = class_to_shost(dev); | 
| FUJITA Tomonori | 7603e02 | 2007-07-23 09:28:40 +0900 | [diff] [blame] | 1767 | struct ibmvscsi_host_data *hostdata = shost_priv(shost); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1768 | int len; | 
|  | 1769 |  | 
|  | 1770 | len = snprintf(buf, PAGE_SIZE, "%d\n", | 
|  | 1771 | hostdata->madapter_info.mad_version); | 
|  | 1772 | return len; | 
|  | 1773 | } | 
|  | 1774 |  | 
| Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1775 | static struct device_attribute ibmvscsi_host_mad_version = { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1776 | .attr = { | 
|  | 1777 | .name = "mad_version", | 
|  | 1778 | .mode = S_IRUGO, | 
|  | 1779 | }, | 
|  | 1780 | .show = show_host_mad_version, | 
|  | 1781 | }; | 
|  | 1782 |  | 
| Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1783 | static ssize_t show_host_os_type(struct device *dev, | 
|  | 1784 | struct device_attribute *attr, char *buf) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1785 | { | 
| Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1786 | struct Scsi_Host *shost = class_to_shost(dev); | 
| FUJITA Tomonori | 7603e02 | 2007-07-23 09:28:40 +0900 | [diff] [blame] | 1787 | struct ibmvscsi_host_data *hostdata = shost_priv(shost); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1788 | int len; | 
|  | 1789 |  | 
|  | 1790 | len = snprintf(buf, PAGE_SIZE, "%d\n", hostdata->madapter_info.os_type); | 
|  | 1791 | return len; | 
|  | 1792 | } | 
|  | 1793 |  | 
| Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1794 | static struct device_attribute ibmvscsi_host_os_type = { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1795 | .attr = { | 
|  | 1796 | .name = "os_type", | 
|  | 1797 | .mode = S_IRUGO, | 
|  | 1798 | }, | 
|  | 1799 | .show = show_host_os_type, | 
|  | 1800 | }; | 
|  | 1801 |  | 
| Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1802 | static ssize_t show_host_config(struct device *dev, | 
|  | 1803 | struct device_attribute *attr, char *buf) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1804 | { | 
| Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1805 | struct Scsi_Host *shost = class_to_shost(dev); | 
| FUJITA Tomonori | 7603e02 | 2007-07-23 09:28:40 +0900 | [diff] [blame] | 1806 | struct ibmvscsi_host_data *hostdata = shost_priv(shost); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1807 |  | 
|  | 1808 | /* returns null-terminated host config data */ | 
|  | 1809 | if (ibmvscsi_do_host_config(hostdata, buf, PAGE_SIZE) == 0) | 
|  | 1810 | return strlen(buf); | 
|  | 1811 | else | 
|  | 1812 | return 0; | 
|  | 1813 | } | 
|  | 1814 |  | 
| Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1815 | static struct device_attribute ibmvscsi_host_config = { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1816 | .attr = { | 
|  | 1817 | .name = "config", | 
|  | 1818 | .mode = S_IRUGO, | 
|  | 1819 | }, | 
|  | 1820 | .show = show_host_config, | 
|  | 1821 | }; | 
|  | 1822 |  | 
| Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1823 | static struct device_attribute *ibmvscsi_attrs[] = { | 
| Brian King | 126c5cc | 2009-06-08 16:19:08 -0500 | [diff] [blame] | 1824 | &ibmvscsi_host_vhost_loc, | 
|  | 1825 | &ibmvscsi_host_vhost_name, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1826 | &ibmvscsi_host_srp_version, | 
|  | 1827 | &ibmvscsi_host_partition_name, | 
|  | 1828 | &ibmvscsi_host_partition_number, | 
|  | 1829 | &ibmvscsi_host_mad_version, | 
|  | 1830 | &ibmvscsi_host_os_type, | 
|  | 1831 | &ibmvscsi_host_config, | 
|  | 1832 | NULL | 
|  | 1833 | }; | 
|  | 1834 |  | 
|  | 1835 | /* ------------------------------------------------------------ | 
|  | 1836 | * SCSI driver registration | 
|  | 1837 | */ | 
|  | 1838 | static struct scsi_host_template driver_template = { | 
|  | 1839 | .module = THIS_MODULE, | 
|  | 1840 | .name = "IBM POWER Virtual SCSI Adapter " IBMVSCSI_VERSION, | 
|  | 1841 | .proc_name = "ibmvscsi", | 
|  | 1842 | .queuecommand = ibmvscsi_queuecommand, | 
|  | 1843 | .eh_abort_handler = ibmvscsi_eh_abort_handler, | 
|  | 1844 | .eh_device_reset_handler = ibmvscsi_eh_device_reset_handler, | 
| Brian King | 3d0e91f | 2007-06-13 17:12:26 -0500 | [diff] [blame] | 1845 | .eh_host_reset_handler = ibmvscsi_eh_host_reset_handler, | 
| Robert Jennings | 0979c84 | 2007-03-29 12:30:40 -0500 | [diff] [blame] | 1846 | .slave_configure = ibmvscsi_slave_configure, | 
| Brian King | 742d25b | 2007-05-29 15:46:14 -0500 | [diff] [blame] | 1847 | .change_queue_depth = ibmvscsi_change_queue_depth, | 
| Robert Jennings | 7912a0a | 2008-07-24 04:35:27 +1000 | [diff] [blame] | 1848 | .cmd_per_lun = IBMVSCSI_CMDS_PER_LUN_DEFAULT, | 
| Robert Jennings | a897ff2 | 2007-03-28 12:45:46 -0500 | [diff] [blame] | 1849 | .can_queue = IBMVSCSI_MAX_REQUESTS_DEFAULT, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1850 | .this_id = -1, | 
| James Bottomley | 4dddbc2 | 2005-09-06 17:11:54 -0500 | [diff] [blame] | 1851 | .sg_tablesize = SG_ALL, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1852 | .use_clustering = ENABLE_CLUSTERING, | 
|  | 1853 | .shost_attrs = ibmvscsi_attrs, | 
|  | 1854 | }; | 
|  | 1855 |  | 
|  | 1856 | /** | 
| Robert Jennings | 7912a0a | 2008-07-24 04:35:27 +1000 | [diff] [blame] | 1857 | * ibmvscsi_get_desired_dma - Calculate IO memory desired by the driver | 
|  | 1858 | * | 
|  | 1859 | * @vdev: struct vio_dev for the device whose desired IO mem is to be returned | 
|  | 1860 | * | 
|  | 1861 | * Return value: | 
|  | 1862 | *	Number of bytes of IO data the driver will need to perform well. | 
|  | 1863 | */ | 
|  | 1864 | static unsigned long ibmvscsi_get_desired_dma(struct vio_dev *vdev) | 
|  | 1865 | { | 
|  | 1866 | /* iu_storage data allocated in initialize_event_pool */ | 
| Brian King | 4f10aae | 2008-12-17 17:19:33 -0600 | [diff] [blame] | 1867 | unsigned long desired_io = max_events * sizeof(union viosrp_iu); | 
| Robert Jennings | 7912a0a | 2008-07-24 04:35:27 +1000 | [diff] [blame] | 1868 |  | 
|  | 1869 | /* add io space for sg data */ | 
| Brian King | 004dd5e | 2008-08-15 10:48:47 -0500 | [diff] [blame] | 1870 | desired_io += (IBMVSCSI_MAX_SECTORS_DEFAULT * 512 * | 
| Robert Jennings | 7912a0a | 2008-07-24 04:35:27 +1000 | [diff] [blame] | 1871 | IBMVSCSI_CMDS_PER_LUN_DEFAULT); | 
|  | 1872 |  | 
|  | 1873 | return desired_io; | 
|  | 1874 | } | 
|  | 1875 |  | 
|  | 1876 | /** | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1877 | * Called by bus code for each adapter | 
|  | 1878 | */ | 
|  | 1879 | static int ibmvscsi_probe(struct vio_dev *vdev, const struct vio_device_id *id) | 
|  | 1880 | { | 
|  | 1881 | struct ibmvscsi_host_data *hostdata; | 
|  | 1882 | struct Scsi_Host *host; | 
|  | 1883 | struct device *dev = &vdev->dev; | 
| FUJITA Tomonori | 4d68041 | 2007-06-27 16:32:50 +0900 | [diff] [blame] | 1884 | struct srp_rport_identifiers ids; | 
|  | 1885 | struct srp_rport *rport; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1886 | unsigned long wait_switch = 0; | 
| Dave C Boutcher | cefbda2 | 2006-06-12 21:22:51 -0500 | [diff] [blame] | 1887 | int rc; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1888 |  | 
| Greg Kroah-Hartman | 559fde7 | 2009-05-04 12:40:54 -0700 | [diff] [blame] | 1889 | dev_set_drvdata(&vdev->dev, NULL); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1890 |  | 
|  | 1891 | host = scsi_host_alloc(&driver_template, sizeof(*hostdata)); | 
|  | 1892 | if (!host) { | 
| Brian King | 6c0a60e | 2007-06-13 17:12:19 -0500 | [diff] [blame] | 1893 | dev_err(&vdev->dev, "couldn't allocate host data\n"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1894 | goto scsi_host_alloc_failed; | 
|  | 1895 | } | 
|  | 1896 |  | 
| FUJITA Tomonori | 4d68041 | 2007-06-27 16:32:50 +0900 | [diff] [blame] | 1897 | host->transportt = ibmvscsi_transport_template; | 
| FUJITA Tomonori | 7603e02 | 2007-07-23 09:28:40 +0900 | [diff] [blame] | 1898 | hostdata = shost_priv(host); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1899 | memset(hostdata, 0x00, sizeof(*hostdata)); | 
|  | 1900 | INIT_LIST_HEAD(&hostdata->sent); | 
|  | 1901 | hostdata->host = host; | 
|  | 1902 | hostdata->dev = dev; | 
|  | 1903 | atomic_set(&hostdata->request_limit, -1); | 
| Robert Jennings | 7912a0a | 2008-07-24 04:35:27 +1000 | [diff] [blame] | 1904 | hostdata->host->max_sectors = IBMVSCSI_MAX_SECTORS_DEFAULT; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1905 |  | 
| Brian King | 126c5cc | 2009-06-08 16:19:08 -0500 | [diff] [blame] | 1906 | if (map_persist_bufs(hostdata)) { | 
|  | 1907 | dev_err(&vdev->dev, "couldn't map persistent buffers\n"); | 
|  | 1908 | goto persist_bufs_failed; | 
|  | 1909 | } | 
|  | 1910 |  | 
| Brian King | 4f10aae | 2008-12-17 17:19:33 -0600 | [diff] [blame] | 1911 | rc = ibmvscsi_ops->init_crq_queue(&hostdata->queue, hostdata, max_events); | 
| Dave C Boutcher | cefbda2 | 2006-06-12 21:22:51 -0500 | [diff] [blame] | 1912 | if (rc != 0 && rc != H_RESOURCE) { | 
| Brian King | 6c0a60e | 2007-06-13 17:12:19 -0500 | [diff] [blame] | 1913 | dev_err(&vdev->dev, "couldn't initialize crq. rc=%d\n", rc); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1914 | goto init_crq_failed; | 
|  | 1915 | } | 
| Brian King | 4f10aae | 2008-12-17 17:19:33 -0600 | [diff] [blame] | 1916 | if (initialize_event_pool(&hostdata->pool, max_events, hostdata) != 0) { | 
| Brian King | 6c0a60e | 2007-06-13 17:12:19 -0500 | [diff] [blame] | 1917 | dev_err(&vdev->dev, "couldn't initialize event pool\n"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1918 | goto init_pool_failed; | 
|  | 1919 | } | 
|  | 1920 |  | 
|  | 1921 | host->max_lun = 8; | 
|  | 1922 | host->max_id = max_id; | 
|  | 1923 | host->max_channel = max_channel; | 
| Brian King | fbc56f0 | 2009-06-08 16:19:01 -0500 | [diff] [blame] | 1924 | host->max_cmd_len = 16; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1925 |  | 
|  | 1926 | if (scsi_add_host(hostdata->host, hostdata->dev)) | 
|  | 1927 | goto add_host_failed; | 
|  | 1928 |  | 
| FUJITA Tomonori | 4d68041 | 2007-06-27 16:32:50 +0900 | [diff] [blame] | 1929 | /* we don't have a proper target_port_id so let's use the fake one */ | 
|  | 1930 | memcpy(ids.port_id, hostdata->madapter_info.partition_name, | 
|  | 1931 | sizeof(ids.port_id)); | 
| FUJITA Tomonori | aebd5e4 | 2007-07-11 15:08:15 +0900 | [diff] [blame] | 1932 | ids.roles = SRP_RPORT_ROLE_TARGET; | 
| FUJITA Tomonori | 4d68041 | 2007-06-27 16:32:50 +0900 | [diff] [blame] | 1933 | rport = srp_rport_add(host, &ids); | 
|  | 1934 | if (IS_ERR(rport)) | 
|  | 1935 | goto add_srp_port_failed; | 
|  | 1936 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1937 | /* Try to send an initialization message.  Note that this is allowed | 
|  | 1938 | * to fail if the other end is not acive.  In that case we don't | 
|  | 1939 | * want to scan | 
|  | 1940 | */ | 
| David Woodhouse | d3849d5 | 2007-09-22 08:29:36 +1000 | [diff] [blame] | 1941 | if (ibmvscsi_ops->send_crq(hostdata, 0xC001000000000000LL, 0) == 0 | 
| Dave C Boutcher | cefbda2 | 2006-06-12 21:22:51 -0500 | [diff] [blame] | 1942 | || rc == H_RESOURCE) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1943 | /* | 
|  | 1944 | * Wait around max init_timeout secs for the adapter to finish | 
|  | 1945 | * initializing. When we are done initializing, we will have a | 
|  | 1946 | * valid request_limit.  We don't want Linux scanning before | 
|  | 1947 | * we are ready. | 
|  | 1948 | */ | 
|  | 1949 | for (wait_switch = jiffies + (init_timeout * HZ); | 
|  | 1950 | time_before(jiffies, wait_switch) && | 
|  | 1951 | atomic_read(&hostdata->request_limit) < 2;) { | 
|  | 1952 |  | 
|  | 1953 | msleep(10); | 
|  | 1954 | } | 
|  | 1955 |  | 
|  | 1956 | /* if we now have a valid request_limit, initiate a scan */ | 
|  | 1957 | if (atomic_read(&hostdata->request_limit) > 0) | 
|  | 1958 | scsi_scan_host(host); | 
|  | 1959 | } | 
|  | 1960 |  | 
| Greg Kroah-Hartman | 559fde7 | 2009-05-04 12:40:54 -0700 | [diff] [blame] | 1961 | dev_set_drvdata(&vdev->dev, hostdata); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1962 | return 0; | 
|  | 1963 |  | 
| FUJITA Tomonori | 4d68041 | 2007-06-27 16:32:50 +0900 | [diff] [blame] | 1964 | add_srp_port_failed: | 
|  | 1965 | scsi_remove_host(hostdata->host); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1966 | add_host_failed: | 
|  | 1967 | release_event_pool(&hostdata->pool, hostdata); | 
|  | 1968 | init_pool_failed: | 
| Brian King | 4f10aae | 2008-12-17 17:19:33 -0600 | [diff] [blame] | 1969 | ibmvscsi_ops->release_crq_queue(&hostdata->queue, hostdata, max_events); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1970 | init_crq_failed: | 
| Brian King | 126c5cc | 2009-06-08 16:19:08 -0500 | [diff] [blame] | 1971 | unmap_persist_bufs(hostdata); | 
|  | 1972 | persist_bufs_failed: | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1973 | scsi_host_put(host); | 
|  | 1974 | scsi_host_alloc_failed: | 
|  | 1975 | return -1; | 
|  | 1976 | } | 
|  | 1977 |  | 
|  | 1978 | static int ibmvscsi_remove(struct vio_dev *vdev) | 
|  | 1979 | { | 
| Greg Kroah-Hartman | 559fde7 | 2009-05-04 12:40:54 -0700 | [diff] [blame] | 1980 | struct ibmvscsi_host_data *hostdata = dev_get_drvdata(&vdev->dev); | 
| Brian King | 126c5cc | 2009-06-08 16:19:08 -0500 | [diff] [blame] | 1981 | unmap_persist_bufs(hostdata); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1982 | release_event_pool(&hostdata->pool, hostdata); | 
| David Woodhouse | d3849d5 | 2007-09-22 08:29:36 +1000 | [diff] [blame] | 1983 | ibmvscsi_ops->release_crq_queue(&hostdata->queue, hostdata, | 
| Brian King | 4f10aae | 2008-12-17 17:19:33 -0600 | [diff] [blame] | 1984 | max_events); | 
| FUJITA Tomonori | 4d68041 | 2007-06-27 16:32:50 +0900 | [diff] [blame] | 1985 |  | 
|  | 1986 | srp_remove_host(hostdata->host); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1987 | scsi_remove_host(hostdata->host); | 
|  | 1988 | scsi_host_put(hostdata->host); | 
|  | 1989 |  | 
|  | 1990 | return 0; | 
|  | 1991 | } | 
|  | 1992 |  | 
|  | 1993 | /** | 
|  | 1994 | * ibmvscsi_device_table: Used by vio.c to match devices in the device tree we | 
|  | 1995 | * support. | 
|  | 1996 | */ | 
|  | 1997 | static struct vio_device_id ibmvscsi_device_table[] __devinitdata = { | 
|  | 1998 | {"vscsi", "IBM,v-scsi"}, | 
| Stephen Rothwell | fb120da | 2005-08-17 16:42:59 +1000 | [diff] [blame] | 1999 | { "", "" } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2000 | }; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2001 | MODULE_DEVICE_TABLE(vio, ibmvscsi_device_table); | 
| Stephen Rothwell | 915124d | 2005-10-24 15:12:22 +1000 | [diff] [blame] | 2002 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2003 | static struct vio_driver ibmvscsi_driver = { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2004 | .id_table = ibmvscsi_device_table, | 
|  | 2005 | .probe = ibmvscsi_probe, | 
| Stephen Rothwell | 6fdf539 | 2005-10-24 14:53:21 +1000 | [diff] [blame] | 2006 | .remove = ibmvscsi_remove, | 
| Robert Jennings | 7912a0a | 2008-07-24 04:35:27 +1000 | [diff] [blame] | 2007 | .get_desired_dma = ibmvscsi_get_desired_dma, | 
| Stephen Rothwell | 6fdf539 | 2005-10-24 14:53:21 +1000 | [diff] [blame] | 2008 | .driver = { | 
|  | 2009 | .name = "ibmvscsi", | 
| Stephen Rothwell | 915124d | 2005-10-24 15:12:22 +1000 | [diff] [blame] | 2010 | .owner = THIS_MODULE, | 
| Stephen Rothwell | 6fdf539 | 2005-10-24 14:53:21 +1000 | [diff] [blame] | 2011 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2012 | }; | 
|  | 2013 |  | 
| FUJITA Tomonori | 4d68041 | 2007-06-27 16:32:50 +0900 | [diff] [blame] | 2014 | static struct srp_function_template ibmvscsi_transport_functions = { | 
|  | 2015 | }; | 
|  | 2016 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2017 | int __init ibmvscsi_module_init(void) | 
|  | 2018 | { | 
| FUJITA Tomonori | 4d68041 | 2007-06-27 16:32:50 +0900 | [diff] [blame] | 2019 | int ret; | 
|  | 2020 |  | 
| Brian King | 4f10aae | 2008-12-17 17:19:33 -0600 | [diff] [blame] | 2021 | /* Ensure we have two requests to do error recovery */ | 
|  | 2022 | driver_template.can_queue = max_requests; | 
|  | 2023 | max_events = max_requests + 2; | 
|  | 2024 |  | 
| David Woodhouse | d3849d5 | 2007-09-22 08:29:36 +1000 | [diff] [blame] | 2025 | if (firmware_has_feature(FW_FEATURE_ISERIES)) | 
|  | 2026 | ibmvscsi_ops = &iseriesvscsi_ops; | 
|  | 2027 | else if (firmware_has_feature(FW_FEATURE_VIO)) | 
|  | 2028 | ibmvscsi_ops = &rpavscsi_ops; | 
|  | 2029 | else | 
|  | 2030 | return -ENODEV; | 
|  | 2031 |  | 
| FUJITA Tomonori | 4d68041 | 2007-06-27 16:32:50 +0900 | [diff] [blame] | 2032 | ibmvscsi_transport_template = | 
|  | 2033 | srp_attach_transport(&ibmvscsi_transport_functions); | 
|  | 2034 | if (!ibmvscsi_transport_template) | 
|  | 2035 | return -ENOMEM; | 
|  | 2036 |  | 
|  | 2037 | ret = vio_register_driver(&ibmvscsi_driver); | 
|  | 2038 | if (ret) | 
|  | 2039 | srp_release_transport(ibmvscsi_transport_template); | 
|  | 2040 | return ret; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2041 | } | 
|  | 2042 |  | 
|  | 2043 | void __exit ibmvscsi_module_exit(void) | 
|  | 2044 | { | 
|  | 2045 | vio_unregister_driver(&ibmvscsi_driver); | 
| FUJITA Tomonori | 4d68041 | 2007-06-27 16:32:50 +0900 | [diff] [blame] | 2046 | srp_release_transport(ibmvscsi_transport_template); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2047 | } | 
|  | 2048 |  | 
|  | 2049 | module_init(ibmvscsi_module_init); | 
|  | 2050 | module_exit(ibmvscsi_module_exit); |