FUJITA Tomonori | 26b1482 | 2006-12-01 03:00:50 +0900 | [diff] [blame] | 1 | /* |
| 2 | * SCSI RDAM Protocol lib functions |
| 3 | * |
| 4 | * Copyright (C) 2006 FUJITA Tomonori <tomof@acm.org> |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or |
| 7 | * modify it under the terms of the GNU General Public License as |
| 8 | * published by the Free Software Foundation; either version 2 of the |
| 9 | * License, or (at your option) any later version. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, but |
| 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 14 | * General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with this program; if not, write to the Free Software |
| 18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA |
| 19 | * 02110-1301 USA |
| 20 | */ |
| 21 | #include <linux/err.h> |
| 22 | #include <linux/kfifo.h> |
| 23 | #include <linux/scatterlist.h> |
| 24 | #include <linux/dma-mapping.h> |
FUJITA Tomonori | 26b1482 | 2006-12-01 03:00:50 +0900 | [diff] [blame] | 25 | #include <scsi/scsi.h> |
| 26 | #include <scsi/scsi_cmnd.h> |
| 27 | #include <scsi/scsi_tcq.h> |
| 28 | #include <scsi/scsi_tgt.h> |
| 29 | #include <scsi/srp.h> |
| 30 | #include <scsi/libsrp.h> |
| 31 | |
| 32 | enum srp_task_attributes { |
| 33 | SRP_SIMPLE_TASK = 0, |
| 34 | SRP_HEAD_TASK = 1, |
| 35 | SRP_ORDERED_TASK = 2, |
| 36 | SRP_ACA_TASK = 4 |
| 37 | }; |
| 38 | |
| 39 | /* tmp - will replace with SCSI logging stuff */ |
| 40 | #define eprintk(fmt, args...) \ |
| 41 | do { \ |
Harvey Harrison | cadbd4a | 2008-07-03 23:47:27 -0700 | [diff] [blame] | 42 | printk("%s(%d) " fmt, __func__, __LINE__, ##args); \ |
FUJITA Tomonori | 26b1482 | 2006-12-01 03:00:50 +0900 | [diff] [blame] | 43 | } while (0) |
| 44 | /* #define dprintk eprintk */ |
| 45 | #define dprintk(fmt, args...) |
| 46 | |
| 47 | static int srp_iu_pool_alloc(struct srp_queue *q, size_t max, |
| 48 | struct srp_buf **ring) |
| 49 | { |
| 50 | int i; |
| 51 | struct iu_entry *iue; |
| 52 | |
| 53 | q->pool = kcalloc(max, sizeof(struct iu_entry *), GFP_KERNEL); |
| 54 | if (!q->pool) |
| 55 | return -ENOMEM; |
| 56 | q->items = kcalloc(max, sizeof(struct iu_entry), GFP_KERNEL); |
| 57 | if (!q->items) |
| 58 | goto free_pool; |
| 59 | |
| 60 | spin_lock_init(&q->lock); |
Stefani Seibold | c1e13f2 | 2009-12-21 14:37:27 -0800 | [diff] [blame] | 61 | kfifo_init(&q->queue, (void *) q->pool, max * sizeof(void *)); |
FUJITA Tomonori | 26b1482 | 2006-12-01 03:00:50 +0900 | [diff] [blame] | 62 | |
| 63 | for (i = 0, iue = q->items; i < max; i++) { |
Stefani Seibold | 7acd72e | 2009-12-21 14:37:28 -0800 | [diff] [blame] | 64 | kfifo_in(&q->queue, (void *) &iue, sizeof(void *)); |
FUJITA Tomonori | 26b1482 | 2006-12-01 03:00:50 +0900 | [diff] [blame] | 65 | iue->sbuf = ring[i]; |
| 66 | iue++; |
| 67 | } |
| 68 | return 0; |
| 69 | |
FUJITA Tomonori | 26b1482 | 2006-12-01 03:00:50 +0900 | [diff] [blame] | 70 | kfree(q->items); |
| 71 | free_pool: |
| 72 | kfree(q->pool); |
| 73 | return -ENOMEM; |
| 74 | } |
| 75 | |
| 76 | static void srp_iu_pool_free(struct srp_queue *q) |
| 77 | { |
| 78 | kfree(q->items); |
| 79 | kfree(q->pool); |
| 80 | } |
| 81 | |
| 82 | static struct srp_buf **srp_ring_alloc(struct device *dev, |
| 83 | size_t max, size_t size) |
| 84 | { |
| 85 | int i; |
| 86 | struct srp_buf **ring; |
| 87 | |
| 88 | ring = kcalloc(max, sizeof(struct srp_buf *), GFP_KERNEL); |
| 89 | if (!ring) |
| 90 | return NULL; |
| 91 | |
| 92 | for (i = 0; i < max; i++) { |
| 93 | ring[i] = kzalloc(sizeof(struct srp_buf), GFP_KERNEL); |
| 94 | if (!ring[i]) |
| 95 | goto out; |
| 96 | ring[i]->buf = dma_alloc_coherent(dev, size, &ring[i]->dma, |
| 97 | GFP_KERNEL); |
| 98 | if (!ring[i]->buf) |
| 99 | goto out; |
| 100 | } |
| 101 | return ring; |
| 102 | |
| 103 | out: |
| 104 | for (i = 0; i < max && ring[i]; i++) { |
| 105 | if (ring[i]->buf) |
| 106 | dma_free_coherent(dev, size, ring[i]->buf, ring[i]->dma); |
| 107 | kfree(ring[i]); |
| 108 | } |
| 109 | kfree(ring); |
| 110 | |
| 111 | return NULL; |
| 112 | } |
| 113 | |
| 114 | static void srp_ring_free(struct device *dev, struct srp_buf **ring, size_t max, |
| 115 | size_t size) |
| 116 | { |
| 117 | int i; |
| 118 | |
| 119 | for (i = 0; i < max; i++) { |
| 120 | dma_free_coherent(dev, size, ring[i]->buf, ring[i]->dma); |
| 121 | kfree(ring[i]); |
| 122 | } |
Bart Van Assche | afffd3d | 2009-08-30 12:36:48 +0200 | [diff] [blame] | 123 | kfree(ring); |
FUJITA Tomonori | 26b1482 | 2006-12-01 03:00:50 +0900 | [diff] [blame] | 124 | } |
| 125 | |
| 126 | int srp_target_alloc(struct srp_target *target, struct device *dev, |
| 127 | size_t nr, size_t iu_size) |
| 128 | { |
| 129 | int err; |
| 130 | |
| 131 | spin_lock_init(&target->lock); |
| 132 | INIT_LIST_HEAD(&target->cmd_queue); |
| 133 | |
| 134 | target->dev = dev; |
Greg Kroah-Hartman | 78c55d7 | 2009-04-30 14:43:31 -0700 | [diff] [blame] | 135 | dev_set_drvdata(target->dev, target); |
FUJITA Tomonori | 26b1482 | 2006-12-01 03:00:50 +0900 | [diff] [blame] | 136 | |
| 137 | target->srp_iu_size = iu_size; |
| 138 | target->rx_ring_size = nr; |
| 139 | target->rx_ring = srp_ring_alloc(target->dev, nr, iu_size); |
| 140 | if (!target->rx_ring) |
| 141 | return -ENOMEM; |
| 142 | err = srp_iu_pool_alloc(&target->iu_queue, nr, target->rx_ring); |
| 143 | if (err) |
| 144 | goto free_ring; |
| 145 | |
| 146 | return 0; |
| 147 | |
| 148 | free_ring: |
| 149 | srp_ring_free(target->dev, target->rx_ring, nr, iu_size); |
| 150 | return -ENOMEM; |
| 151 | } |
| 152 | EXPORT_SYMBOL_GPL(srp_target_alloc); |
| 153 | |
| 154 | void srp_target_free(struct srp_target *target) |
| 155 | { |
| 156 | srp_ring_free(target->dev, target->rx_ring, target->rx_ring_size, |
| 157 | target->srp_iu_size); |
| 158 | srp_iu_pool_free(&target->iu_queue); |
| 159 | } |
| 160 | EXPORT_SYMBOL_GPL(srp_target_free); |
| 161 | |
| 162 | struct iu_entry *srp_iu_get(struct srp_target *target) |
| 163 | { |
| 164 | struct iu_entry *iue = NULL; |
| 165 | |
Stefani Seibold | 9842c38 | 2009-12-21 14:37:29 -0800 | [diff] [blame] | 166 | if (kfifo_out_locked(&target->iu_queue.queue, (void *) &iue, |
| 167 | sizeof(void *), &target->iu_queue.lock) != sizeof(void *)) { |
| 168 | WARN_ONCE(1, "unexpected fifo state"); |
| 169 | return NULL; |
| 170 | } |
FUJITA Tomonori | 26b1482 | 2006-12-01 03:00:50 +0900 | [diff] [blame] | 171 | if (!iue) |
| 172 | return iue; |
| 173 | iue->target = target; |
| 174 | INIT_LIST_HEAD(&iue->ilist); |
| 175 | iue->flags = 0; |
| 176 | return iue; |
| 177 | } |
| 178 | EXPORT_SYMBOL_GPL(srp_iu_get); |
| 179 | |
| 180 | void srp_iu_put(struct iu_entry *iue) |
| 181 | { |
Stefani Seibold | 7acd72e | 2009-12-21 14:37:28 -0800 | [diff] [blame] | 182 | kfifo_in_locked(&iue->target->iu_queue.queue, (void *) &iue, |
Stefani Seibold | c1e13f2 | 2009-12-21 14:37:27 -0800 | [diff] [blame] | 183 | sizeof(void *), &iue->target->iu_queue.lock); |
FUJITA Tomonori | 26b1482 | 2006-12-01 03:00:50 +0900 | [diff] [blame] | 184 | } |
| 185 | EXPORT_SYMBOL_GPL(srp_iu_put); |
| 186 | |
| 187 | static int srp_direct_data(struct scsi_cmnd *sc, struct srp_direct_buf *md, |
| 188 | enum dma_data_direction dir, srp_rdma_t rdma_io, |
| 189 | int dma_map, int ext_desc) |
| 190 | { |
| 191 | struct iu_entry *iue = NULL; |
| 192 | struct scatterlist *sg = NULL; |
| 193 | int err, nsg = 0, len; |
| 194 | |
| 195 | if (dma_map) { |
| 196 | iue = (struct iu_entry *) sc->SCp.ptr; |
FUJITA Tomonori | f10ab66 | 2007-10-25 01:21:30 +0900 | [diff] [blame] | 197 | sg = scsi_sglist(sc); |
FUJITA Tomonori | 26b1482 | 2006-12-01 03:00:50 +0900 | [diff] [blame] | 198 | |
FUJITA Tomonori | f10ab66 | 2007-10-25 01:21:30 +0900 | [diff] [blame] | 199 | dprintk("%p %u %u %d\n", iue, scsi_bufflen(sc), |
| 200 | md->len, scsi_sg_count(sc)); |
FUJITA Tomonori | 26b1482 | 2006-12-01 03:00:50 +0900 | [diff] [blame] | 201 | |
FUJITA Tomonori | f10ab66 | 2007-10-25 01:21:30 +0900 | [diff] [blame] | 202 | nsg = dma_map_sg(iue->target->dev, sg, scsi_sg_count(sc), |
FUJITA Tomonori | 26b1482 | 2006-12-01 03:00:50 +0900 | [diff] [blame] | 203 | DMA_BIDIRECTIONAL); |
| 204 | if (!nsg) { |
FUJITA Tomonori | f10ab66 | 2007-10-25 01:21:30 +0900 | [diff] [blame] | 205 | printk("fail to map %p %d\n", iue, scsi_sg_count(sc)); |
FUJITA Tomonori | 26b1482 | 2006-12-01 03:00:50 +0900 | [diff] [blame] | 206 | return 0; |
| 207 | } |
FUJITA Tomonori | f10ab66 | 2007-10-25 01:21:30 +0900 | [diff] [blame] | 208 | len = min(scsi_bufflen(sc), md->len); |
FUJITA Tomonori | 26b1482 | 2006-12-01 03:00:50 +0900 | [diff] [blame] | 209 | } else |
| 210 | len = md->len; |
| 211 | |
| 212 | err = rdma_io(sc, sg, nsg, md, 1, dir, len); |
| 213 | |
| 214 | if (dma_map) |
| 215 | dma_unmap_sg(iue->target->dev, sg, nsg, DMA_BIDIRECTIONAL); |
| 216 | |
| 217 | return err; |
| 218 | } |
| 219 | |
| 220 | static int srp_indirect_data(struct scsi_cmnd *sc, struct srp_cmd *cmd, |
| 221 | struct srp_indirect_buf *id, |
| 222 | enum dma_data_direction dir, srp_rdma_t rdma_io, |
| 223 | int dma_map, int ext_desc) |
| 224 | { |
| 225 | struct iu_entry *iue = NULL; |
| 226 | struct srp_direct_buf *md = NULL; |
| 227 | struct scatterlist dummy, *sg = NULL; |
| 228 | dma_addr_t token = 0; |
Bastian Blank | ad1331a | 2007-04-07 18:10:00 +0900 | [diff] [blame] | 229 | int err = 0; |
FUJITA Tomonori | 26b1482 | 2006-12-01 03:00:50 +0900 | [diff] [blame] | 230 | int nmd, nsg = 0, len; |
| 231 | |
| 232 | if (dma_map || ext_desc) { |
| 233 | iue = (struct iu_entry *) sc->SCp.ptr; |
FUJITA Tomonori | f10ab66 | 2007-10-25 01:21:30 +0900 | [diff] [blame] | 234 | sg = scsi_sglist(sc); |
FUJITA Tomonori | 26b1482 | 2006-12-01 03:00:50 +0900 | [diff] [blame] | 235 | |
| 236 | dprintk("%p %u %u %d %d\n", |
FUJITA Tomonori | f10ab66 | 2007-10-25 01:21:30 +0900 | [diff] [blame] | 237 | iue, scsi_bufflen(sc), id->len, |
FUJITA Tomonori | 26b1482 | 2006-12-01 03:00:50 +0900 | [diff] [blame] | 238 | cmd->data_in_desc_cnt, cmd->data_out_desc_cnt); |
| 239 | } |
| 240 | |
| 241 | nmd = id->table_desc.len / sizeof(struct srp_direct_buf); |
| 242 | |
| 243 | if ((dir == DMA_FROM_DEVICE && nmd == cmd->data_in_desc_cnt) || |
| 244 | (dir == DMA_TO_DEVICE && nmd == cmd->data_out_desc_cnt)) { |
| 245 | md = &id->desc_list[0]; |
| 246 | goto rdma; |
| 247 | } |
| 248 | |
| 249 | if (ext_desc && dma_map) { |
| 250 | md = dma_alloc_coherent(iue->target->dev, id->table_desc.len, |
| 251 | &token, GFP_KERNEL); |
| 252 | if (!md) { |
| 253 | eprintk("Can't get dma memory %u\n", id->table_desc.len); |
| 254 | return -ENOMEM; |
| 255 | } |
| 256 | |
| 257 | sg_init_one(&dummy, md, id->table_desc.len); |
| 258 | sg_dma_address(&dummy) = token; |
FUJITA Tomonori | bcd4e22 | 2007-05-11 19:10:45 +0900 | [diff] [blame] | 259 | sg_dma_len(&dummy) = id->table_desc.len; |
FUJITA Tomonori | 26b1482 | 2006-12-01 03:00:50 +0900 | [diff] [blame] | 260 | err = rdma_io(sc, &dummy, 1, &id->table_desc, 1, DMA_TO_DEVICE, |
| 261 | id->table_desc.len); |
Bastian Blank | ad1331a | 2007-04-07 18:10:00 +0900 | [diff] [blame] | 262 | if (err) { |
| 263 | eprintk("Error copying indirect table %d\n", err); |
FUJITA Tomonori | 26b1482 | 2006-12-01 03:00:50 +0900 | [diff] [blame] | 264 | goto free_mem; |
| 265 | } |
| 266 | } else { |
| 267 | eprintk("This command uses external indirect buffer\n"); |
| 268 | return -EINVAL; |
| 269 | } |
| 270 | |
| 271 | rdma: |
| 272 | if (dma_map) { |
FUJITA Tomonori | f10ab66 | 2007-10-25 01:21:30 +0900 | [diff] [blame] | 273 | nsg = dma_map_sg(iue->target->dev, sg, scsi_sg_count(sc), |
| 274 | DMA_BIDIRECTIONAL); |
FUJITA Tomonori | 26b1482 | 2006-12-01 03:00:50 +0900 | [diff] [blame] | 275 | if (!nsg) { |
FUJITA Tomonori | f10ab66 | 2007-10-25 01:21:30 +0900 | [diff] [blame] | 276 | eprintk("fail to map %p %d\n", iue, scsi_sg_count(sc)); |
Bastian Blank | ad1331a | 2007-04-07 18:10:00 +0900 | [diff] [blame] | 277 | err = -EIO; |
FUJITA Tomonori | 26b1482 | 2006-12-01 03:00:50 +0900 | [diff] [blame] | 278 | goto free_mem; |
| 279 | } |
FUJITA Tomonori | f10ab66 | 2007-10-25 01:21:30 +0900 | [diff] [blame] | 280 | len = min(scsi_bufflen(sc), id->len); |
FUJITA Tomonori | 26b1482 | 2006-12-01 03:00:50 +0900 | [diff] [blame] | 281 | } else |
| 282 | len = id->len; |
| 283 | |
| 284 | err = rdma_io(sc, sg, nsg, md, nmd, dir, len); |
| 285 | |
| 286 | if (dma_map) |
| 287 | dma_unmap_sg(iue->target->dev, sg, nsg, DMA_BIDIRECTIONAL); |
| 288 | |
| 289 | free_mem: |
| 290 | if (token && dma_map) |
| 291 | dma_free_coherent(iue->target->dev, id->table_desc.len, md, token); |
| 292 | |
Bastian Blank | ad1331a | 2007-04-07 18:10:00 +0900 | [diff] [blame] | 293 | return err; |
FUJITA Tomonori | 26b1482 | 2006-12-01 03:00:50 +0900 | [diff] [blame] | 294 | } |
| 295 | |
| 296 | static int data_out_desc_size(struct srp_cmd *cmd) |
| 297 | { |
| 298 | int size = 0; |
| 299 | u8 fmt = cmd->buf_fmt >> 4; |
| 300 | |
| 301 | switch (fmt) { |
| 302 | case SRP_NO_DATA_DESC: |
| 303 | break; |
| 304 | case SRP_DATA_DESC_DIRECT: |
| 305 | size = sizeof(struct srp_direct_buf); |
| 306 | break; |
| 307 | case SRP_DATA_DESC_INDIRECT: |
| 308 | size = sizeof(struct srp_indirect_buf) + |
| 309 | sizeof(struct srp_direct_buf) * cmd->data_out_desc_cnt; |
| 310 | break; |
| 311 | default: |
| 312 | eprintk("client error. Invalid data_out_format %x\n", fmt); |
| 313 | break; |
| 314 | } |
| 315 | return size; |
| 316 | } |
| 317 | |
| 318 | /* |
| 319 | * TODO: this can be called multiple times for a single command if it |
| 320 | * has very long data. |
| 321 | */ |
| 322 | int srp_transfer_data(struct scsi_cmnd *sc, struct srp_cmd *cmd, |
| 323 | srp_rdma_t rdma_io, int dma_map, int ext_desc) |
| 324 | { |
| 325 | struct srp_direct_buf *md; |
| 326 | struct srp_indirect_buf *id; |
| 327 | enum dma_data_direction dir; |
| 328 | int offset, err = 0; |
| 329 | u8 format; |
| 330 | |
| 331 | offset = cmd->add_cdb_len * 4; |
| 332 | |
| 333 | dir = srp_cmd_direction(cmd); |
| 334 | if (dir == DMA_FROM_DEVICE) |
| 335 | offset += data_out_desc_size(cmd); |
| 336 | |
| 337 | if (dir == DMA_TO_DEVICE) |
| 338 | format = cmd->buf_fmt >> 4; |
| 339 | else |
| 340 | format = cmd->buf_fmt & ((1U << 4) - 1); |
| 341 | |
| 342 | switch (format) { |
| 343 | case SRP_NO_DATA_DESC: |
| 344 | break; |
| 345 | case SRP_DATA_DESC_DIRECT: |
| 346 | md = (struct srp_direct_buf *) |
| 347 | (cmd->add_data + offset); |
| 348 | err = srp_direct_data(sc, md, dir, rdma_io, dma_map, ext_desc); |
| 349 | break; |
| 350 | case SRP_DATA_DESC_INDIRECT: |
| 351 | id = (struct srp_indirect_buf *) |
| 352 | (cmd->add_data + offset); |
| 353 | err = srp_indirect_data(sc, cmd, id, dir, rdma_io, dma_map, |
| 354 | ext_desc); |
| 355 | break; |
| 356 | default: |
| 357 | eprintk("Unknown format %d %x\n", dir, format); |
Bastian Blank | ad1331a | 2007-04-07 18:10:00 +0900 | [diff] [blame] | 358 | err = -EINVAL; |
FUJITA Tomonori | 26b1482 | 2006-12-01 03:00:50 +0900 | [diff] [blame] | 359 | } |
| 360 | |
| 361 | return err; |
| 362 | } |
| 363 | EXPORT_SYMBOL_GPL(srp_transfer_data); |
| 364 | |
| 365 | static int vscsis_data_length(struct srp_cmd *cmd, enum dma_data_direction dir) |
| 366 | { |
| 367 | struct srp_direct_buf *md; |
| 368 | struct srp_indirect_buf *id; |
| 369 | int len = 0, offset = cmd->add_cdb_len * 4; |
| 370 | u8 fmt; |
| 371 | |
| 372 | if (dir == DMA_TO_DEVICE) |
| 373 | fmt = cmd->buf_fmt >> 4; |
| 374 | else { |
| 375 | fmt = cmd->buf_fmt & ((1U << 4) - 1); |
| 376 | offset += data_out_desc_size(cmd); |
| 377 | } |
| 378 | |
| 379 | switch (fmt) { |
| 380 | case SRP_NO_DATA_DESC: |
| 381 | break; |
| 382 | case SRP_DATA_DESC_DIRECT: |
| 383 | md = (struct srp_direct_buf *) (cmd->add_data + offset); |
| 384 | len = md->len; |
| 385 | break; |
| 386 | case SRP_DATA_DESC_INDIRECT: |
| 387 | id = (struct srp_indirect_buf *) (cmd->add_data + offset); |
| 388 | len = id->len; |
| 389 | break; |
| 390 | default: |
| 391 | eprintk("invalid data format %x\n", fmt); |
| 392 | break; |
| 393 | } |
| 394 | return len; |
| 395 | } |
| 396 | |
| 397 | int srp_cmd_queue(struct Scsi_Host *shost, struct srp_cmd *cmd, void *info, |
FUJITA Tomonori | 17b0bcf | 2007-07-11 15:08:21 +0900 | [diff] [blame] | 398 | u64 itn_id, u64 addr) |
FUJITA Tomonori | 26b1482 | 2006-12-01 03:00:50 +0900 | [diff] [blame] | 399 | { |
| 400 | enum dma_data_direction dir; |
| 401 | struct scsi_cmnd *sc; |
| 402 | int tag, len, err; |
| 403 | |
| 404 | switch (cmd->task_attr) { |
| 405 | case SRP_SIMPLE_TASK: |
| 406 | tag = MSG_SIMPLE_TAG; |
| 407 | break; |
| 408 | case SRP_ORDERED_TASK: |
| 409 | tag = MSG_ORDERED_TAG; |
| 410 | break; |
| 411 | case SRP_HEAD_TASK: |
| 412 | tag = MSG_HEAD_TAG; |
| 413 | break; |
| 414 | default: |
| 415 | eprintk("Task attribute %d not supported\n", cmd->task_attr); |
| 416 | tag = MSG_ORDERED_TAG; |
| 417 | } |
| 418 | |
| 419 | dir = srp_cmd_direction(cmd); |
| 420 | len = vscsis_data_length(cmd, dir); |
| 421 | |
| 422 | dprintk("%p %x %lx %d %d %d %llx\n", info, cmd->cdb[0], |
| 423 | cmd->lun, dir, len, tag, (unsigned long long) cmd->tag); |
| 424 | |
| 425 | sc = scsi_host_get_command(shost, dir, GFP_KERNEL); |
| 426 | if (!sc) |
| 427 | return -ENOMEM; |
| 428 | |
| 429 | sc->SCp.ptr = info; |
| 430 | memcpy(sc->cmnd, cmd->cdb, MAX_COMMAND_SIZE); |
Boaz Harrosh | 30b0c37 | 2007-12-13 13:47:40 +0200 | [diff] [blame] | 431 | sc->sdb.length = len; |
| 432 | sc->sdb.table.sgl = (void *) (unsigned long) addr; |
FUJITA Tomonori | 26b1482 | 2006-12-01 03:00:50 +0900 | [diff] [blame] | 433 | sc->tag = tag; |
FUJITA Tomonori | 17b0bcf | 2007-07-11 15:08:21 +0900 | [diff] [blame] | 434 | err = scsi_tgt_queue_command(sc, itn_id, (struct scsi_lun *)&cmd->lun, |
| 435 | cmd->tag); |
FUJITA Tomonori | 26b1482 | 2006-12-01 03:00:50 +0900 | [diff] [blame] | 436 | if (err) |
| 437 | scsi_host_put_command(shost, sc); |
| 438 | |
| 439 | return err; |
| 440 | } |
| 441 | EXPORT_SYMBOL_GPL(srp_cmd_queue); |
| 442 | |
| 443 | MODULE_DESCRIPTION("SCSI RDAM Protocol lib functions"); |
| 444 | MODULE_AUTHOR("FUJITA Tomonori"); |
| 445 | MODULE_LICENSE("GPL"); |