1 /*******************************************************************************
2 * IBM Virtual SCSI Target Driver
3 * Copyright (C) 2003-2005 Dave Boutcher (boutcher@us.ibm.com) IBM Corp.
4 * Santiago Leon (santil@us.ibm.com) IBM Corp.
5 * Linda Xie (lxie@us.ibm.com) IBM Corp.
7 * Copyright (C) 2005-2011 FUJITA Tomonori <tomof@acm.org>
8 * Copyright (C) 2010 Nicholas A. Bellinger <nab@kernel.org>
10 * Authors: Bryant G. Ly <bryantly@linux.vnet.ibm.com>
11 * Authors: Michael Cyr <mikecyr@linux.vnet.ibm.com>
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 ****************************************************************************/
25 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
27 #include <linux/module.h>
28 #include <linux/kernel.h>
29 #include <linux/slab.h>
30 #include <linux/types.h>
31 #include <linux/list.h>
32 #include <linux/string.h>
34 #include <target/target_core_base.h>
35 #include <target/target_core_fabric.h>
37 #include <asm/hvcall.h>
40 #include <scsi/viosrp.h>
42 #include "ibmvscsi_tgt.h"
44 #define IBMVSCSIS_VERSION "v0.2"
46 #define INITIAL_SRP_LIMIT 1024
47 #define DEFAULT_MAX_SECTORS 256
48 #define MAX_TXU 1024 * 1024
50 static uint max_vdma_size = MAX_H_COPY_RDMA;
52 static char system_id[SYS_ID_NAME_LEN] = "";
53 static char partition_name[PARTITION_NAMELEN] = "UNKNOWN";
54 static uint partition_number = -1;
56 /* Adapter list and lock to control it */
57 static DEFINE_SPINLOCK(ibmvscsis_dev_lock);
58 static LIST_HEAD(ibmvscsis_dev_list);
60 static long ibmvscsis_parse_command(struct scsi_info *vscsi,
61 struct viosrp_crq *crq);
63 static void ibmvscsis_adapter_idle(struct scsi_info *vscsi);
65 static void ibmvscsis_determine_resid(struct se_cmd *se_cmd,
68 u32 residual_count = se_cmd->residual_count;
73 if (se_cmd->se_cmd_flags & SCF_UNDERFLOW_BIT) {
74 if (se_cmd->data_direction == DMA_TO_DEVICE) {
75 /* residual data from an underflow write */
76 rsp->flags = SRP_RSP_FLAG_DOUNDER;
77 rsp->data_out_res_cnt = cpu_to_be32(residual_count);
78 } else if (se_cmd->data_direction == DMA_FROM_DEVICE) {
79 /* residual data from an underflow read */
80 rsp->flags = SRP_RSP_FLAG_DIUNDER;
81 rsp->data_in_res_cnt = cpu_to_be32(residual_count);
83 } else if (se_cmd->se_cmd_flags & SCF_OVERFLOW_BIT) {
84 if (se_cmd->data_direction == DMA_TO_DEVICE) {
85 /* residual data from an overflow write */
86 rsp->flags = SRP_RSP_FLAG_DOOVER;
87 rsp->data_out_res_cnt = cpu_to_be32(residual_count);
88 } else if (se_cmd->data_direction == DMA_FROM_DEVICE) {
89 /* residual data from an overflow read */
90 rsp->flags = SRP_RSP_FLAG_DIOVER;
91 rsp->data_in_res_cnt = cpu_to_be32(residual_count);
97 * connection_broken() - Determine if the connection to the client is good
98 * @vscsi: Pointer to our adapter structure
100 * This function attempts to send a ping MAD to the client. If the call to
101 * queue the request returns H_CLOSED then the connection has been broken
102 * and the function returns TRUE.
104 * EXECUTION ENVIRONMENT:
105 * Interrupt or Process environment
107 static bool connection_broken(struct scsi_info *vscsi)
109 struct viosrp_crq *crq;
110 u64 buffer[2] = { 0, 0 };
114 /* create a PING crq */
115 crq = (struct viosrp_crq *)&buffer;
116 crq->valid = VALID_CMD_RESP_EL;
117 crq->format = MESSAGE_IN_CRQ;
120 h_return_code = h_send_crq(vscsi->dds.unit_id,
121 cpu_to_be64(buffer[MSG_HI]),
122 cpu_to_be64(buffer[MSG_LOW]));
124 pr_debug("connection_broken: rc %ld\n", h_return_code);
126 if (h_return_code == H_CLOSED)
133 * ibmvscsis_unregister_command_q() - Helper Function-Unregister Command Queue
134 * @vscsi: Pointer to our adapter structure
136 * This function calls h_free_q then frees the interrupt bit etc.
137 * It must release the lock before doing so because of the time it can take
138 * for h_free_crq in PHYP
139 * NOTE: the caller must make sure that state and or flags will prevent
140 * interrupt handler from scheduling work.
141 * NOTE: anyone calling this function may need to set the CRQ_CLOSED flag
142 * we can't do it here, because we don't have the lock
144 * EXECUTION ENVIRONMENT:
147 static long ibmvscsis_unregister_command_q(struct scsi_info *vscsi)
150 long rc = ADAPT_SUCCESS;
154 qrc = h_free_crq(vscsi->dds.unit_id);
161 dev_err(&vscsi->dev, "unregister_command_q: error from h_free_crq %ld\n",
167 case H_LONG_BUSY_ORDER_1_MSEC:
168 /* msleep not good for small values */
169 usleep_range(1000, 2000);
172 case H_LONG_BUSY_ORDER_10_MSEC:
173 usleep_range(10000, 20000);
176 case H_LONG_BUSY_ORDER_100_MSEC:
180 case H_LONG_BUSY_ORDER_1_SEC:
184 case H_LONG_BUSY_ORDER_10_SEC:
188 case H_LONG_BUSY_ORDER_100_SEC:
193 dev_err(&vscsi->dev, "unregister_command_q: unknown error %ld from h_free_crq\n",
200 * dont wait more then 300 seconds
201 * ticks are in milliseconds more or less
203 if (ticks > 300000 && qrc != H_SUCCESS) {
205 dev_err(&vscsi->dev, "Excessive wait for h_free_crq\n");
207 } while (qrc != H_SUCCESS && rc == ADAPT_SUCCESS);
209 pr_debug("Freeing CRQ: phyp rc %ld, rc %ld\n", qrc, rc);
215 * ibmvscsis_delete_client_info() - Helper function to Delete Client Info
216 * @vscsi: Pointer to our adapter structure
217 * @client_closed: True if client closed its queue
219 * Deletes information specific to the client when the client goes away
221 * EXECUTION ENVIRONMENT:
222 * Interrupt or Process
224 static void ibmvscsis_delete_client_info(struct scsi_info *vscsi,
227 vscsi->client_cap = 0;
230 * Some things we don't want to clear if we're closing the queue,
231 * because some clients don't resend the host handshake when they
232 * get a transport event.
235 vscsi->client_data.os_type = 0;
239 * ibmvscsis_free_command_q() - Free Command Queue
240 * @vscsi: Pointer to our adapter structure
242 * This function calls unregister_command_q, then clears interrupts and
243 * any pending interrupt acknowledgments associated with the command q.
244 * It also clears memory if there is no error.
246 * PHYP did not meet the PAPR architecture so that we must give up the
247 * lock. This causes a timing hole regarding state change. To close the
248 * hole this routine does accounting on any change that occurred during
249 * the time the lock is not held.
250 * NOTE: must give up and then acquire the interrupt lock, the caller must
251 * make sure that state and or flags will prevent interrupt handler from
254 * EXECUTION ENVIRONMENT:
255 * Process level, interrupt lock is held
257 static long ibmvscsis_free_command_q(struct scsi_info *vscsi)
260 u32 flags_under_lock;
261 u16 state_under_lock;
262 long rc = ADAPT_SUCCESS;
264 if (!(vscsi->flags & CRQ_CLOSED)) {
265 vio_disable_interrupts(vscsi->dma_dev);
267 state_under_lock = vscsi->new_state;
268 flags_under_lock = vscsi->flags;
269 vscsi->phyp_acr_state = 0;
270 vscsi->phyp_acr_flags = 0;
272 spin_unlock_bh(&vscsi->intr_lock);
273 rc = ibmvscsis_unregister_command_q(vscsi);
274 spin_lock_bh(&vscsi->intr_lock);
276 if (state_under_lock != vscsi->new_state)
277 vscsi->phyp_acr_state = vscsi->new_state;
279 vscsi->phyp_acr_flags = ((~flags_under_lock) & vscsi->flags);
281 if (rc == ADAPT_SUCCESS) {
282 bytes = vscsi->cmd_q.size * PAGE_SIZE;
283 memset(vscsi->cmd_q.base_addr, 0, bytes);
284 vscsi->cmd_q.index = 0;
285 vscsi->flags |= CRQ_CLOSED;
287 ibmvscsis_delete_client_info(vscsi, false);
290 pr_debug("free_command_q: flags 0x%x, state 0x%hx, acr_flags 0x%x, acr_state 0x%hx\n",
291 vscsi->flags, vscsi->state, vscsi->phyp_acr_flags,
292 vscsi->phyp_acr_state);
298 * ibmvscsis_cmd_q_dequeue() - Get valid Command element
299 * @mask: Mask to use in case index wraps
300 * @current_index: Current index into command queue
301 * @base_addr: Pointer to start of command queue
303 * Returns a pointer to a valid command element or NULL, if the command
306 * EXECUTION ENVIRONMENT:
307 * Interrupt environment, interrupt lock held
309 static struct viosrp_crq *ibmvscsis_cmd_q_dequeue(uint mask,
311 struct viosrp_crq *base_addr)
313 struct viosrp_crq *ptr;
315 ptr = base_addr + *current_index;
318 *current_index = (*current_index + 1) & mask;
328 * ibmvscsis_send_init_message() - send initialize message to the client
329 * @vscsi: Pointer to our adapter structure
330 * @format: Which Init Message format to send
332 * EXECUTION ENVIRONMENT:
333 * Interrupt environment interrupt lock held
335 static long ibmvscsis_send_init_message(struct scsi_info *vscsi, u8 format)
337 struct viosrp_crq *crq;
338 u64 buffer[2] = { 0, 0 };
341 crq = (struct viosrp_crq *)&buffer;
342 crq->valid = VALID_INIT_MSG;
343 crq->format = format;
344 rc = h_send_crq(vscsi->dds.unit_id, cpu_to_be64(buffer[MSG_HI]),
345 cpu_to_be64(buffer[MSG_LOW]));
351 * ibmvscsis_check_init_msg() - Check init message valid
352 * @vscsi: Pointer to our adapter structure
353 * @format: Pointer to return format of Init Message, if any.
354 * Set to UNUSED_FORMAT if no Init Message in queue.
356 * Checks if an initialize message was queued by the initiatior
357 * after the queue was created and before the interrupt was enabled.
359 * EXECUTION ENVIRONMENT:
360 * Process level only, interrupt lock held
362 static long ibmvscsis_check_init_msg(struct scsi_info *vscsi, uint *format)
364 struct viosrp_crq *crq;
365 long rc = ADAPT_SUCCESS;
367 crq = ibmvscsis_cmd_q_dequeue(vscsi->cmd_q.mask, &vscsi->cmd_q.index,
368 vscsi->cmd_q.base_addr);
370 *format = (uint)UNUSED_FORMAT;
371 } else if (crq->valid == VALID_INIT_MSG && crq->format == INIT_MSG) {
372 *format = (uint)INIT_MSG;
373 crq->valid = INVALIDATE_CMD_RESP_EL;
377 * the caller has ensured no initialize message was
378 * sent after the queue was
379 * created so there should be no other message on the queue.
381 crq = ibmvscsis_cmd_q_dequeue(vscsi->cmd_q.mask,
383 vscsi->cmd_q.base_addr);
385 *format = (uint)(crq->format);
387 crq->valid = INVALIDATE_CMD_RESP_EL;
391 *format = (uint)(crq->format);
393 crq->valid = INVALIDATE_CMD_RESP_EL;
401 * ibmvscsis_disconnect() - Helper function to disconnect
402 * @work: Pointer to work_struct, gives access to our adapter structure
404 * An error has occurred or the driver received a Transport event,
405 * and the driver is requesting that the command queue be de-registered
406 * in a safe manner. If there is no outstanding I/O then we can stop the
407 * queue. If we are restarting the queue it will be reflected in the
408 * the state of the adapter.
410 * EXECUTION ENVIRONMENT:
411 * Process environment
413 static void ibmvscsis_disconnect(struct work_struct *work)
415 struct scsi_info *vscsi = container_of(work, struct scsi_info,
418 bool wait_idle = false;
420 spin_lock_bh(&vscsi->intr_lock);
421 new_state = vscsi->new_state;
422 vscsi->new_state = 0;
424 pr_debug("disconnect: flags 0x%x, state 0x%hx\n", vscsi->flags,
428 * check which state we are in and see if we
429 * should transitition to the new state
431 switch (vscsi->state) {
432 /* Should never be called while in this state. */
435 * Can never transition from this state;
436 * igonore errors and logout.
441 /* can transition from this state to UNCONFIGURING */
443 if (new_state == UNCONFIGURING)
444 vscsi->state = new_state;
448 * Can transition from this state to to unconfiguring
451 case ERR_DISCONNECT_RECONNECT:
455 vscsi->state = new_state;
465 /* can transition from this state to UNCONFIGURING */
466 case ERR_DISCONNECTED:
467 if (new_state == UNCONFIGURING)
468 vscsi->state = new_state;
474 vscsi->state = new_state;
475 vscsi->flags |= RESPONSE_Q_DOWN;
476 vscsi->flags &= ~(SCHEDULE_DISCONNECT |
477 DISCONNECT_SCHEDULED);
479 if (vscsi->flags & CFG_SLEEPING) {
480 vscsi->flags &= ~CFG_SLEEPING;
481 complete(&vscsi->unconfig);
485 /* should never happen */
487 case ERR_DISCONNECT_RECONNECT:
489 dev_err(&vscsi->dev, "disconnect: invalid state %d for WAIT_IDLE\n",
498 vscsi->flags |= RESPONSE_Q_DOWN;
499 vscsi->state = new_state;
500 vscsi->flags &= ~(SCHEDULE_DISCONNECT |
501 DISCONNECT_SCHEDULED);
502 ibmvscsis_free_command_q(vscsi);
505 case ERR_DISCONNECT_RECONNECT:
506 vscsi->state = new_state;
512 * Initiator has not done a successful srp login
513 * or has done a successful srp logout ( adapter was not
514 * busy). In the first case there can be responses queued
515 * waiting for space on the initiators response queue (MAD)
516 * The second case the adapter is idle. Assume the worse case,
517 * i.e. the second case.
519 case WAIT_CONNECTION:
523 vscsi->state = new_state;
526 /* can transition from this state to UNCONFIGURING */
528 if (new_state == UNCONFIGURING)
529 vscsi->state = new_state;
536 pr_debug("disconnect start wait, active %d, sched %d\n",
537 (int)list_empty(&vscsi->active_q),
538 (int)list_empty(&vscsi->schedule_q));
539 if (!list_empty(&vscsi->active_q) ||
540 !list_empty(&vscsi->schedule_q)) {
541 vscsi->flags |= WAIT_FOR_IDLE;
542 pr_debug("disconnect flags 0x%x\n", vscsi->flags);
544 * This routine is can not be called with the interrupt
547 spin_unlock_bh(&vscsi->intr_lock);
548 wait_for_completion(&vscsi->wait_idle);
549 spin_lock_bh(&vscsi->intr_lock);
551 pr_debug("disconnect stop wait\n");
553 ibmvscsis_adapter_idle(vscsi);
556 spin_unlock_bh(&vscsi->intr_lock);
560 * ibmvscsis_post_disconnect() - Schedule the disconnect
561 * @vscsi: Pointer to our adapter structure
562 * @new_state: State to move to after disconnecting
563 * @flag_bits: Flags to turn on in adapter structure
565 * If it's already been scheduled, then see if we need to "upgrade"
566 * the new state (if the one passed in is more "severe" than the
570 * interrupt lock is held
572 static void ibmvscsis_post_disconnect(struct scsi_info *vscsi, uint new_state,
577 /* check the validity of the new state */
581 case ERR_DISCONNECT_RECONNECT:
586 dev_err(&vscsi->dev, "post_disconnect: Invalid new state %d\n",
591 vscsi->flags |= flag_bits;
593 pr_debug("post_disconnect: new_state 0x%x, flag_bits 0x%x, vscsi->flags 0x%x, state %hx\n",
594 new_state, flag_bits, vscsi->flags, vscsi->state);
596 if (!(vscsi->flags & (DISCONNECT_SCHEDULED | SCHEDULE_DISCONNECT))) {
597 vscsi->flags |= SCHEDULE_DISCONNECT;
598 vscsi->new_state = new_state;
600 INIT_WORK(&vscsi->proc_work, ibmvscsis_disconnect);
601 (void)queue_work(vscsi->work_q, &vscsi->proc_work);
603 if (vscsi->new_state)
604 state = vscsi->new_state;
606 state = vscsi->state;
613 case ERR_DISCONNECTED:
616 if (new_state == UNCONFIGURING)
617 vscsi->new_state = new_state;
620 case ERR_DISCONNECT_RECONNECT:
624 vscsi->new_state = new_state;
633 case WAIT_CONNECTION:
636 vscsi->new_state = new_state;
644 pr_debug("Leaving post_disconnect: flags 0x%x, new_state 0x%x\n",
645 vscsi->flags, vscsi->new_state);
649 * ibmvscsis_handle_init_compl_msg() - Respond to an Init Complete Message
650 * @vscsi: Pointer to our adapter structure
652 * Must be called with interrupt lock held.
654 static long ibmvscsis_handle_init_compl_msg(struct scsi_info *vscsi)
656 long rc = ADAPT_SUCCESS;
658 switch (vscsi->state) {
661 case ERR_DISCONNECT_RECONNECT:
662 case ERR_DISCONNECTED:
668 case WAIT_CONNECTION:
669 vscsi->state = CONNECTED;
678 dev_err(&vscsi->dev, "init_msg: invalid state %d to get init compl msg\n",
680 ibmvscsis_post_disconnect(vscsi, ERR_DISCONNECT_RECONNECT, 0);
688 * ibmvscsis_handle_init_msg() - Respond to an Init Message
689 * @vscsi: Pointer to our adapter structure
691 * Must be called with interrupt lock held.
693 static long ibmvscsis_handle_init_msg(struct scsi_info *vscsi)
695 long rc = ADAPT_SUCCESS;
697 switch (vscsi->state) {
698 case WAIT_CONNECTION:
699 rc = ibmvscsis_send_init_message(vscsi, INIT_COMPLETE_MSG);
702 vscsi->state = CONNECTED;
706 dev_err(&vscsi->dev, "init_msg: failed to send, rc %ld\n",
708 ibmvscsis_post_disconnect(vscsi, ERR_DISCONNECT, 0);
712 dev_err(&vscsi->dev, "init_msg: failed to send, rc %ld\n",
715 ibmvscsis_post_disconnect(vscsi,
716 ERR_DISCONNECT_RECONNECT, 0);
720 pr_warn("init_msg: failed to send, rc %ld\n", rc);
739 case ERR_DISCONNECT_RECONNECT:
740 case ERR_DISCONNECTED:
743 dev_err(&vscsi->dev, "init_msg: invalid state %d to get init msg\n",
745 ibmvscsis_post_disconnect(vscsi, ERR_DISCONNECT_RECONNECT, 0);
753 * ibmvscsis_init_msg() - Respond to an init message
754 * @vscsi: Pointer to our adapter structure
755 * @crq: Pointer to CRQ element containing the Init Message
757 * EXECUTION ENVIRONMENT:
758 * Interrupt, interrupt lock held
760 static long ibmvscsis_init_msg(struct scsi_info *vscsi, struct viosrp_crq *crq)
762 long rc = ADAPT_SUCCESS;
764 pr_debug("init_msg: state 0x%hx\n", vscsi->state);
766 rc = h_vioctl(vscsi->dds.unit_id, H_GET_PARTNER_INFO,
767 (u64)vscsi->map_ioba | ((u64)PAGE_SIZE << 32), 0, 0, 0,
769 if (rc == H_SUCCESS) {
770 vscsi->client_data.partition_number =
771 be64_to_cpu(*(u64 *)vscsi->map_buf);
772 pr_debug("init_msg, part num %d\n",
773 vscsi->client_data.partition_number);
775 pr_debug("init_msg h_vioctl rc %ld\n", rc);
779 if (crq->format == INIT_MSG) {
780 rc = ibmvscsis_handle_init_msg(vscsi);
781 } else if (crq->format == INIT_COMPLETE_MSG) {
782 rc = ibmvscsis_handle_init_compl_msg(vscsi);
785 dev_err(&vscsi->dev, "init_msg: invalid format %d\n",
787 ibmvscsis_post_disconnect(vscsi, ERR_DISCONNECT_RECONNECT, 0);
794 * ibmvscsis_establish_new_q() - Establish new CRQ queue
795 * @vscsi: Pointer to our adapter structure
797 * Must be called with interrupt lock held.
799 static long ibmvscsis_establish_new_q(struct scsi_info *vscsi)
801 long rc = ADAPT_SUCCESS;
804 vscsi->flags &= PRESERVE_FLAG_FIELDS;
805 vscsi->rsp_q_timer.timer_pops = 0;
809 rc = vio_enable_interrupts(vscsi->dma_dev);
811 pr_warn("establish_new_q: failed to enable interrupts, rc %ld\n",
816 rc = ibmvscsis_check_init_msg(vscsi, &format);
818 dev_err(&vscsi->dev, "establish_new_q: check_init_msg failed, rc %ld\n",
823 if (format == UNUSED_FORMAT) {
824 rc = ibmvscsis_send_init_message(vscsi, INIT_MSG);
837 vscsi->state = UNDEFINED;
841 } else if (format == INIT_MSG) {
842 rc = ibmvscsis_handle_init_msg(vscsi);
849 * ibmvscsis_reset_queue() - Reset CRQ Queue
850 * @vscsi: Pointer to our adapter structure
852 * This function calls h_free_q and then calls h_reg_q and does all
853 * of the bookkeeping to get us back to where we can communicate.
855 * Actually, we don't always call h_free_crq. A problem was discovered
856 * where one partition would close and reopen his queue, which would
857 * cause his partner to get a transport event, which would cause him to
858 * close and reopen his queue, which would cause the original partition
859 * to get a transport event, etc., etc. To prevent this, we don't
860 * actually close our queue if the client initiated the reset, (i.e.
861 * either we got a transport event or we have detected that the client's
864 * EXECUTION ENVIRONMENT:
865 * Process environment, called with interrupt lock held
867 static void ibmvscsis_reset_queue(struct scsi_info *vscsi)
870 long rc = ADAPT_SUCCESS;
872 pr_debug("reset_queue: flags 0x%x\n", vscsi->flags);
874 /* don't reset, the client did it for us */
875 if (vscsi->flags & (CLIENT_FAILED | TRANS_EVENT)) {
876 vscsi->flags &= PRESERVE_FLAG_FIELDS;
877 vscsi->rsp_q_timer.timer_pops = 0;
880 vscsi->state = WAIT_CONNECTION;
881 vio_enable_interrupts(vscsi->dma_dev);
883 rc = ibmvscsis_free_command_q(vscsi);
884 if (rc == ADAPT_SUCCESS) {
885 vscsi->state = WAIT_CONNECTION;
887 bytes = vscsi->cmd_q.size * PAGE_SIZE;
888 rc = h_reg_crq(vscsi->dds.unit_id,
889 vscsi->cmd_q.crq_token, bytes);
890 if (rc == H_CLOSED || rc == H_SUCCESS) {
891 rc = ibmvscsis_establish_new_q(vscsi);
894 if (rc != ADAPT_SUCCESS) {
895 pr_debug("reset_queue: reg_crq rc %ld\n", rc);
897 vscsi->state = ERR_DISCONNECTED;
898 vscsi->flags |= RESPONSE_Q_DOWN;
899 ibmvscsis_free_command_q(vscsi);
902 vscsi->state = ERR_DISCONNECTED;
903 vscsi->flags |= RESPONSE_Q_DOWN;
909 * ibmvscsis_free_cmd_resources() - Free command resources
910 * @vscsi: Pointer to our adapter structure
911 * @cmd: Command which is not longer in use
913 * Must be called with interrupt lock held.
915 static void ibmvscsis_free_cmd_resources(struct scsi_info *vscsi,
916 struct ibmvscsis_cmd *cmd)
918 struct iu_entry *iue = cmd->iue;
921 case TASK_MANAGEMENT:
924 * When the queue goes down this value is cleared, so it
925 * cannot be cleared in this general purpose function.
931 vscsi->flags &= ~PROCESSING_MAD;
936 dev_err(&vscsi->dev, "free_cmd_resources unknown type %d\n",
942 list_add_tail(&cmd->list, &vscsi->free_cmd);
945 if (list_empty(&vscsi->active_q) && list_empty(&vscsi->schedule_q) &&
946 list_empty(&vscsi->waiting_rsp) && (vscsi->flags & WAIT_FOR_IDLE)) {
947 vscsi->flags &= ~WAIT_FOR_IDLE;
948 complete(&vscsi->wait_idle);
953 * ibmvscsis_trans_event() - Handle a Transport Event
954 * @vscsi: Pointer to our adapter structure
955 * @crq: Pointer to CRQ entry containing the Transport Event
957 * Do the logic to close the I_T nexus. This function may not
958 * behave to specification.
960 * EXECUTION ENVIRONMENT:
961 * Interrupt, interrupt lock held
963 static long ibmvscsis_trans_event(struct scsi_info *vscsi,
964 struct viosrp_crq *crq)
966 long rc = ADAPT_SUCCESS;
968 pr_debug("trans_event: format %d, flags 0x%x, state 0x%hx\n",
969 (int)crq->format, vscsi->flags, vscsi->state);
971 switch (crq->format) {
974 case PARTNER_DEREGISTER:
975 ibmvscsis_delete_client_info(vscsi, true);
980 dev_err(&vscsi->dev, "trans_event: invalid format %d\n",
982 ibmvscsis_post_disconnect(vscsi, ERR_DISCONNECT,
987 if (rc == ADAPT_SUCCESS) {
988 switch (vscsi->state) {
990 case ERR_DISCONNECTED:
995 vscsi->flags |= (RESPONSE_Q_DOWN | TRANS_EVENT);
1001 case WAIT_CONNECTION:
1005 ibmvscsis_post_disconnect(vscsi, WAIT_IDLE,
1010 case SRP_PROCESSING:
1011 if ((vscsi->debit > 0) ||
1012 !list_empty(&vscsi->schedule_q) ||
1013 !list_empty(&vscsi->waiting_rsp) ||
1014 !list_empty(&vscsi->active_q)) {
1015 pr_debug("debit %d, sched %d, wait %d, active %d\n",
1017 (int)list_empty(&vscsi->schedule_q),
1018 (int)list_empty(&vscsi->waiting_rsp),
1019 (int)list_empty(&vscsi->active_q));
1020 pr_warn("connection lost with outstanding work\n");
1022 pr_debug("trans_event: SRP Processing, but no outstanding work\n");
1025 ibmvscsis_post_disconnect(vscsi, WAIT_IDLE,
1030 case ERR_DISCONNECT:
1031 case ERR_DISCONNECT_RECONNECT:
1033 vscsi->flags |= (RESPONSE_Q_DOWN | TRANS_EVENT);
1038 rc = vscsi->flags & SCHEDULE_DISCONNECT;
1040 pr_debug("Leaving trans_event: flags 0x%x, state 0x%hx, rc %ld\n",
1041 vscsi->flags, vscsi->state, rc);
1047 * ibmvscsis_poll_cmd_q() - Poll Command Queue
1048 * @vscsi: Pointer to our adapter structure
1050 * Called to handle command elements that may have arrived while
1051 * interrupts were disabled.
1053 * EXECUTION ENVIRONMENT:
1054 * intr_lock must be held
1056 static void ibmvscsis_poll_cmd_q(struct scsi_info *vscsi)
1058 struct viosrp_crq *crq;
1063 pr_debug("poll_cmd_q: flags 0x%x, state 0x%hx, q index %ud\n",
1064 vscsi->flags, vscsi->state, vscsi->cmd_q.index);
1066 rc = vscsi->flags & SCHEDULE_DISCONNECT;
1067 crq = vscsi->cmd_q.base_addr + vscsi->cmd_q.index;
1073 vscsi->cmd_q.index =
1074 (vscsi->cmd_q.index + 1) & vscsi->cmd_q.mask;
1077 rc = ibmvscsis_parse_command(vscsi, crq);
1079 if ((uint)crq->valid == VALID_TRANS_EVENT) {
1081 * must service the transport layer events even
1082 * in an error state, dont break out until all
1083 * the consecutive transport events have been
1086 rc = ibmvscsis_trans_event(vscsi, crq);
1087 } else if (vscsi->flags & TRANS_EVENT) {
1089 * if a tranport event has occurred leave
1090 * everything but transport events on the queue
1092 pr_debug("poll_cmd_q, ignoring\n");
1095 * need to decrement the queue index so we can
1096 * look at the elment again
1098 if (vscsi->cmd_q.index)
1099 vscsi->cmd_q.index -= 1;
1102 * index is at 0 it just wrapped.
1103 * have it index last element in q
1105 vscsi->cmd_q.index = vscsi->cmd_q.mask;
1110 crq->valid = INVALIDATE_CMD_RESP_EL;
1112 crq = vscsi->cmd_q.base_addr + vscsi->cmd_q.index;
1119 vio_enable_interrupts(vscsi->dma_dev);
1121 pr_debug("poll_cmd_q, reenabling interrupts\n");
1129 pr_debug("Leaving poll_cmd_q: rc %ld\n", rc);
1133 * ibmvscsis_free_cmd_qs() - Free elements in queue
1134 * @vscsi: Pointer to our adapter structure
1136 * Free all of the elements on all queues that are waiting for
1140 * Called with interrupt lock held
1142 static void ibmvscsis_free_cmd_qs(struct scsi_info *vscsi)
1144 struct ibmvscsis_cmd *cmd, *nxt;
1146 pr_debug("free_cmd_qs: waiting_rsp empty %d, timer starter %d\n",
1147 (int)list_empty(&vscsi->waiting_rsp),
1148 vscsi->rsp_q_timer.started);
1150 list_for_each_entry_safe(cmd, nxt, &vscsi->waiting_rsp, list) {
1151 list_del(&cmd->list);
1152 ibmvscsis_free_cmd_resources(vscsi, cmd);
1157 * ibmvscsis_get_free_cmd() - Get free command from list
1158 * @vscsi: Pointer to our adapter structure
1160 * Must be called with interrupt lock held.
1162 static struct ibmvscsis_cmd *ibmvscsis_get_free_cmd(struct scsi_info *vscsi)
1164 struct ibmvscsis_cmd *cmd = NULL;
1165 struct iu_entry *iue;
1167 iue = srp_iu_get(&vscsi->target);
1169 cmd = list_first_entry_or_null(&vscsi->free_cmd,
1170 struct ibmvscsis_cmd, list);
1173 cmd->abort_cmd = NULL;
1174 cmd->flags &= ~(DELAY_SEND);
1175 list_del(&cmd->list);
1177 cmd->type = UNSET_TYPE;
1178 memset(&cmd->se_cmd, 0, sizeof(cmd->se_cmd));
1188 * ibmvscsis_adapter_idle() - Helper function to handle idle adapter
1189 * @vscsi: Pointer to our adapter structure
1191 * This function is called when the adapter is idle when the driver
1192 * is attempting to clear an error condition.
1193 * The adapter is considered busy if any of its cmd queues
1194 * are non-empty. This function can be invoked
1195 * from the off level disconnect function.
1197 * EXECUTION ENVIRONMENT:
1198 * Process environment called with interrupt lock held
1200 static void ibmvscsis_adapter_idle(struct scsi_info *vscsi)
1202 int free_qs = false;
1204 pr_debug("adapter_idle: flags 0x%x, state 0x%hx\n", vscsi->flags,
1207 /* Only need to free qs if we're disconnecting from client */
1208 if (vscsi->state != WAIT_CONNECTION || vscsi->flags & TRANS_EVENT)
1211 switch (vscsi->state) {
1213 ibmvscsis_free_command_q(vscsi);
1216 if (vscsi->flags & CFG_SLEEPING) {
1217 vscsi->flags &= ~CFG_SLEEPING;
1218 complete(&vscsi->unconfig);
1221 case ERR_DISCONNECT_RECONNECT:
1222 ibmvscsis_reset_queue(vscsi);
1223 pr_debug("adapter_idle, disc_rec: flags 0x%x\n", vscsi->flags);
1226 case ERR_DISCONNECT:
1227 ibmvscsis_free_command_q(vscsi);
1228 vscsi->flags &= ~(SCHEDULE_DISCONNECT | DISCONNECT_SCHEDULED);
1229 vscsi->flags |= RESPONSE_Q_DOWN;
1230 if (vscsi->tport.enabled)
1231 vscsi->state = ERR_DISCONNECTED;
1233 vscsi->state = WAIT_ENABLED;
1234 pr_debug("adapter_idle, disc: flags 0x%x, state 0x%hx\n",
1235 vscsi->flags, vscsi->state);
1239 vscsi->rsp_q_timer.timer_pops = 0;
1242 if (vscsi->flags & TRANS_EVENT) {
1243 vscsi->state = WAIT_CONNECTION;
1244 vscsi->flags &= PRESERVE_FLAG_FIELDS;
1246 vscsi->state = CONNECTED;
1247 vscsi->flags &= ~DISCONNECT_SCHEDULED;
1250 pr_debug("adapter_idle, wait: flags 0x%x, state 0x%hx\n",
1251 vscsi->flags, vscsi->state);
1252 ibmvscsis_poll_cmd_q(vscsi);
1255 case ERR_DISCONNECTED:
1256 vscsi->flags &= ~DISCONNECT_SCHEDULED;
1257 pr_debug("adapter_idle, disconnected: flags 0x%x, state 0x%hx\n",
1258 vscsi->flags, vscsi->state);
1262 dev_err(&vscsi->dev, "adapter_idle: in invalid state %d\n",
1268 ibmvscsis_free_cmd_qs(vscsi);
1271 * There is a timing window where we could lose a disconnect request.
1272 * The known path to this window occurs during the DISCONNECT_RECONNECT
1273 * case above: reset_queue calls free_command_q, which will release the
1274 * interrupt lock. During that time, a new post_disconnect call can be
1275 * made with a "more severe" state (DISCONNECT or UNCONFIGURING).
1276 * Because the DISCONNECT_SCHEDULED flag is already set, post_disconnect
1277 * will only set the new_state. Now free_command_q reacquires the intr
1278 * lock and clears the DISCONNECT_SCHEDULED flag (using PRESERVE_FLAG_
1279 * FIELDS), and the disconnect is lost. This is particularly bad when
1280 * the new disconnect was for UNCONFIGURING, since the unconfigure hangs
1282 * Fix is that free command queue sets acr state and acr flags if there
1283 * is a change under the lock
1284 * note free command queue writes to this state it clears it
1285 * before releasing the lock, different drivers call the free command
1286 * queue different times so dont initialize above
1288 if (vscsi->phyp_acr_state != 0) {
1290 * set any bits in flags that may have been cleared by
1291 * a call to free command queue in switch statement
1294 vscsi->flags |= vscsi->phyp_acr_flags;
1295 ibmvscsis_post_disconnect(vscsi, vscsi->phyp_acr_state, 0);
1296 vscsi->phyp_acr_state = 0;
1297 vscsi->phyp_acr_flags = 0;
1299 pr_debug("adapter_idle: flags 0x%x, state 0x%hx, acr_flags 0x%x, acr_state 0x%hx\n",
1300 vscsi->flags, vscsi->state, vscsi->phyp_acr_flags,
1301 vscsi->phyp_acr_state);
1304 pr_debug("Leaving adapter_idle: flags 0x%x, state 0x%hx, new_state 0x%x\n",
1305 vscsi->flags, vscsi->state, vscsi->new_state);
1309 * ibmvscsis_copy_crq_packet() - Copy CRQ Packet
1310 * @vscsi: Pointer to our adapter structure
1311 * @cmd: Pointer to command element to use to process the request
1312 * @crq: Pointer to CRQ entry containing the request
1314 * Copy the srp information unit from the hosted
1315 * partition using remote dma
1317 * EXECUTION ENVIRONMENT:
1318 * Interrupt, interrupt lock held
1320 static long ibmvscsis_copy_crq_packet(struct scsi_info *vscsi,
1321 struct ibmvscsis_cmd *cmd,
1322 struct viosrp_crq *crq)
1324 struct iu_entry *iue = cmd->iue;
1328 len = be16_to_cpu(crq->IU_length);
1329 if ((len > SRP_MAX_IU_LEN) || (len == 0)) {
1330 dev_err(&vscsi->dev, "copy_crq: Invalid len %d passed", len);
1331 ibmvscsis_post_disconnect(vscsi, ERR_DISCONNECT_RECONNECT, 0);
1332 return SRP_VIOLATION;
1335 rc = h_copy_rdma(len, vscsi->dds.window[REMOTE].liobn,
1336 be64_to_cpu(crq->IU_data_ptr),
1337 vscsi->dds.window[LOCAL].liobn, iue->sbuf->dma);
1341 cmd->init_time = mftb();
1342 iue->remote_token = crq->IU_data_ptr;
1344 pr_debug("copy_crq: ioba 0x%llx, init_time 0x%llx\n",
1345 be64_to_cpu(crq->IU_data_ptr), cmd->init_time);
1348 if (connection_broken(vscsi))
1349 ibmvscsis_post_disconnect(vscsi,
1350 ERR_DISCONNECT_RECONNECT,
1354 ibmvscsis_post_disconnect(vscsi,
1355 ERR_DISCONNECT_RECONNECT, 0);
1357 dev_err(&vscsi->dev, "copy_crq: h_copy_rdma failed, rc %ld\n",
1363 dev_err(&vscsi->dev, "copy_crq: h_copy_rdma failed, rc %ld\n",
1365 ibmvscsis_post_disconnect(vscsi, ERR_DISCONNECT_RECONNECT, 0);
1373 * ibmvscsis_adapter_info - Service an Adapter Info MAnagement Data gram
1374 * @vscsi: Pointer to our adapter structure
1375 * @iue: Information Unit containing the Adapter Info MAD request
1377 * EXECUTION ENVIRONMENT:
1378 * Interrupt adapter lock is held
1380 static long ibmvscsis_adapter_info(struct scsi_info *vscsi,
1381 struct iu_entry *iue)
1383 struct viosrp_adapter_info *mad = &vio_iu(iue)->mad.adapter_info;
1384 struct mad_adapter_info_data *info;
1389 mad->common.status = cpu_to_be16(VIOSRP_MAD_SUCCESS);
1391 if (be16_to_cpu(mad->common.length) > sizeof(*info)) {
1392 mad->common.status = cpu_to_be16(VIOSRP_MAD_FAILED);
1396 info = dma_alloc_coherent(&vscsi->dma_dev->dev, sizeof(*info), &token,
1399 dev_err(&vscsi->dev, "bad dma_alloc_coherent %p\n",
1401 mad->common.status = cpu_to_be16(VIOSRP_MAD_FAILED);
1405 /* Get remote info */
1406 rc = h_copy_rdma(be16_to_cpu(mad->common.length),
1407 vscsi->dds.window[REMOTE].liobn,
1408 be64_to_cpu(mad->buffer),
1409 vscsi->dds.window[LOCAL].liobn, token);
1411 if (rc != H_SUCCESS) {
1412 if (rc == H_PERMISSION) {
1413 if (connection_broken(vscsi))
1414 flag_bits = (RESPONSE_Q_DOWN | CLIENT_FAILED);
1416 pr_warn("adapter_info: h_copy_rdma from client failed, rc %ld\n",
1418 pr_debug("adapter_info: ioba 0x%llx, flags 0x%x, flag_bits 0x%x\n",
1419 be64_to_cpu(mad->buffer), vscsi->flags, flag_bits);
1420 ibmvscsis_post_disconnect(vscsi, ERR_DISCONNECT_RECONNECT,
1426 * Copy client info, but ignore partition number, which we
1427 * already got from phyp - unless we failed to get it from
1428 * phyp (e.g. if we're running on a p5 system).
1430 if (vscsi->client_data.partition_number == 0)
1431 vscsi->client_data.partition_number =
1432 be32_to_cpu(info->partition_number);
1433 strncpy(vscsi->client_data.srp_version, info->srp_version,
1434 sizeof(vscsi->client_data.srp_version));
1435 strncpy(vscsi->client_data.partition_name, info->partition_name,
1436 sizeof(vscsi->client_data.partition_name));
1437 vscsi->client_data.mad_version = be32_to_cpu(info->mad_version);
1438 vscsi->client_data.os_type = be32_to_cpu(info->os_type);
1441 strncpy(info->srp_version, SRP_VERSION,
1442 sizeof(info->srp_version));
1443 strncpy(info->partition_name, vscsi->dds.partition_name,
1444 sizeof(info->partition_name));
1445 info->partition_number = cpu_to_be32(vscsi->dds.partition_num);
1446 info->mad_version = cpu_to_be32(MAD_VERSION_1);
1447 info->os_type = cpu_to_be32(LINUX);
1448 memset(&info->port_max_txu[0], 0, sizeof(info->port_max_txu));
1449 info->port_max_txu[0] = cpu_to_be32(MAX_TXU);
1452 rc = h_copy_rdma(sizeof(*info), vscsi->dds.window[LOCAL].liobn,
1453 token, vscsi->dds.window[REMOTE].liobn,
1454 be64_to_cpu(mad->buffer));
1462 if (connection_broken(vscsi))
1463 flag_bits = (RESPONSE_Q_DOWN | CLIENT_FAILED);
1465 dev_err(&vscsi->dev, "adapter_info: h_copy_rdma to client failed, rc %ld\n",
1467 ibmvscsis_post_disconnect(vscsi,
1468 ERR_DISCONNECT_RECONNECT,
1474 dma_free_coherent(&vscsi->dma_dev->dev, sizeof(*info), info, token);
1475 pr_debug("Leaving adapter_info, rc %ld\n", rc);
1481 * ibmvscsis_cap_mad() - Service a Capabilities MAnagement Data gram
1482 * @vscsi: Pointer to our adapter structure
1483 * @iue: Information Unit containing the Capabilities MAD request
1485 * NOTE: if you return an error from this routine you must be
1486 * disconnecting or you will cause a hang
1488 * EXECUTION ENVIRONMENT:
1489 * Interrupt called with adapter lock held
1491 static int ibmvscsis_cap_mad(struct scsi_info *vscsi, struct iu_entry *iue)
1493 struct viosrp_capabilities *mad = &vio_iu(iue)->mad.capabilities;
1494 struct capabilities *cap;
1495 struct mad_capability_common *common;
1497 u16 olen, len, status, min_len, cap_len;
1502 olen = be16_to_cpu(mad->common.length);
1504 * struct capabilities hardcodes a couple capabilities after the
1505 * header, but the capabilities can actually be in any order.
1507 min_len = offsetof(struct capabilities, migration);
1508 if ((olen < min_len) || (olen > PAGE_SIZE)) {
1509 pr_warn("cap_mad: invalid len %d\n", olen);
1510 mad->common.status = cpu_to_be16(VIOSRP_MAD_FAILED);
1514 cap = dma_alloc_coherent(&vscsi->dma_dev->dev, olen, &token,
1517 dev_err(&vscsi->dev, "bad dma_alloc_coherent %p\n",
1519 mad->common.status = cpu_to_be16(VIOSRP_MAD_FAILED);
1522 rc = h_copy_rdma(olen, vscsi->dds.window[REMOTE].liobn,
1523 be64_to_cpu(mad->buffer),
1524 vscsi->dds.window[LOCAL].liobn, token);
1525 if (rc == H_SUCCESS) {
1526 strncpy(cap->name, dev_name(&vscsi->dma_dev->dev),
1529 len = olen - min_len;
1530 status = VIOSRP_MAD_SUCCESS;
1531 common = (struct mad_capability_common *)&cap->migration;
1533 while ((len > 0) && (status == VIOSRP_MAD_SUCCESS) && !rc) {
1534 pr_debug("cap_mad: len left %hd, cap type %d, cap len %hd\n",
1535 len, be32_to_cpu(common->cap_type),
1536 be16_to_cpu(common->length));
1538 cap_len = be16_to_cpu(common->length);
1539 if (cap_len > len) {
1540 dev_err(&vscsi->dev, "cap_mad: cap len mismatch with total len\n");
1541 status = VIOSRP_MAD_FAILED;
1546 dev_err(&vscsi->dev, "cap_mad: cap len is 0\n");
1547 status = VIOSRP_MAD_FAILED;
1551 switch (common->cap_type) {
1553 pr_debug("cap_mad: unsupported capability\n");
1554 common->server_support = 0;
1555 flag = cpu_to_be32((u32)CAP_LIST_SUPPORTED);
1556 cap->flags &= ~flag;
1560 len = len - cap_len;
1561 common = (struct mad_capability_common *)
1562 ((char *)common + cap_len);
1565 mad->common.status = cpu_to_be16(status);
1568 rc = h_copy_rdma(olen, vscsi->dds.window[LOCAL].liobn, token,
1569 vscsi->dds.window[REMOTE].liobn,
1570 be64_to_cpu(mad->buffer));
1572 if (rc != H_SUCCESS) {
1573 pr_debug("cap_mad: failed to copy to client, rc %ld\n",
1576 if (rc == H_PERMISSION) {
1577 if (connection_broken(vscsi))
1578 flag_bits = (RESPONSE_Q_DOWN |
1582 pr_warn("cap_mad: error copying data to client, rc %ld\n",
1584 ibmvscsis_post_disconnect(vscsi,
1585 ERR_DISCONNECT_RECONNECT,
1590 dma_free_coherent(&vscsi->dma_dev->dev, olen, cap, token);
1592 pr_debug("Leaving cap_mad, rc %ld, client_cap 0x%x\n",
1593 rc, vscsi->client_cap);
1599 * ibmvscsis_process_mad() - Service a MAnagement Data gram
1600 * @vscsi: Pointer to our adapter structure
1601 * @iue: Information Unit containing the MAD request
1603 * Must be called with interrupt lock held.
1605 static long ibmvscsis_process_mad(struct scsi_info *vscsi, struct iu_entry *iue)
1607 struct mad_common *mad = (struct mad_common *)&vio_iu(iue)->mad;
1608 struct viosrp_empty_iu *empty;
1609 long rc = ADAPT_SUCCESS;
1611 switch (be32_to_cpu(mad->type)) {
1612 case VIOSRP_EMPTY_IU_TYPE:
1613 empty = &vio_iu(iue)->mad.empty_iu;
1614 vscsi->empty_iu_id = be64_to_cpu(empty->buffer);
1615 vscsi->empty_iu_tag = be64_to_cpu(empty->common.tag);
1616 mad->status = cpu_to_be16(VIOSRP_MAD_SUCCESS);
1618 case VIOSRP_ADAPTER_INFO_TYPE:
1619 rc = ibmvscsis_adapter_info(vscsi, iue);
1621 case VIOSRP_CAPABILITIES_TYPE:
1622 rc = ibmvscsis_cap_mad(vscsi, iue);
1624 case VIOSRP_ENABLE_FAST_FAIL:
1625 if (vscsi->state == CONNECTED) {
1626 vscsi->fast_fail = true;
1627 mad->status = cpu_to_be16(VIOSRP_MAD_SUCCESS);
1629 pr_warn("fast fail mad sent after login\n");
1630 mad->status = cpu_to_be16(VIOSRP_MAD_FAILED);
1634 mad->status = cpu_to_be16(VIOSRP_MAD_NOT_SUPPORTED);
1642 * srp_snd_msg_failed() - Handle an error when sending a response
1643 * @vscsi: Pointer to our adapter structure
1644 * @rc: The return code from the h_send_crq command
1646 * Must be called with interrupt lock held.
1648 static void srp_snd_msg_failed(struct scsi_info *vscsi, long rc)
1652 if (rc != H_DROPPED) {
1653 ibmvscsis_free_cmd_qs(vscsi);
1656 vscsi->flags |= CLIENT_FAILED;
1658 /* don't flag the same problem multiple times */
1659 if (!(vscsi->flags & RESPONSE_Q_DOWN)) {
1660 vscsi->flags |= RESPONSE_Q_DOWN;
1661 if (!(vscsi->state & (ERR_DISCONNECT |
1662 ERR_DISCONNECT_RECONNECT |
1663 ERR_DISCONNECTED | UNDEFINED))) {
1664 dev_err(&vscsi->dev, "snd_msg_failed: setting RESPONSE_Q_DOWN, state 0x%hx, flags 0x%x, rc %ld\n",
1665 vscsi->state, vscsi->flags, rc);
1667 ibmvscsis_post_disconnect(vscsi,
1668 ERR_DISCONNECT_RECONNECT, 0);
1674 * The response queue is full.
1675 * If the server is processing SRP requests, i.e.
1676 * the client has successfully done an
1677 * SRP_LOGIN, then it will wait forever for room in
1678 * the queue. However if the system admin
1679 * is attempting to unconfigure the server then one
1680 * or more children will be in a state where
1681 * they are being removed. So if there is even one
1682 * child being removed then the driver assumes
1683 * the system admin is attempting to break the
1684 * connection with the client and MAX_TIMER_POPS
1687 if ((vscsi->rsp_q_timer.timer_pops < MAX_TIMER_POPS) ||
1688 (vscsi->state == SRP_PROCESSING)) {
1689 pr_debug("snd_msg_failed: response queue full, flags 0x%x, timer started %d, pops %d\n",
1690 vscsi->flags, (int)vscsi->rsp_q_timer.started,
1691 vscsi->rsp_q_timer.timer_pops);
1694 * Check if the timer is running; if it
1695 * is not then start it up.
1697 if (!vscsi->rsp_q_timer.started) {
1698 if (vscsi->rsp_q_timer.timer_pops <
1700 kt = ktime_set(0, WAIT_NANO_SECONDS);
1703 * slide the timeslice if the maximum
1704 * timer pops have already happened
1706 kt = ktime_set(WAIT_SECONDS, 0);
1709 vscsi->rsp_q_timer.started = true;
1710 hrtimer_start(&vscsi->rsp_q_timer.timer, kt,
1715 * TBD: Do we need to worry about this? Need to get
1719 * waited a long time and it appears the system admin
1720 * is bring this driver down
1722 vscsi->flags |= RESPONSE_Q_DOWN;
1723 ibmvscsis_free_cmd_qs(vscsi);
1725 * if the driver is already attempting to disconnect
1726 * from the client and has already logged an error
1727 * trace this event but don't put it in the error log
1729 if (!(vscsi->state & (ERR_DISCONNECT |
1730 ERR_DISCONNECT_RECONNECT |
1731 ERR_DISCONNECTED | UNDEFINED))) {
1732 dev_err(&vscsi->dev, "client crq full too long\n");
1733 ibmvscsis_post_disconnect(vscsi,
1734 ERR_DISCONNECT_RECONNECT,
1741 * ibmvscsis_send_messages() - Send a Response
1742 * @vscsi: Pointer to our adapter structure
1744 * Send a response, first checking the waiting queue. Responses are
1745 * sent in order they are received. If the response cannot be sent,
1746 * because the client queue is full, it stays on the waiting queue.
1749 * Called with interrupt lock held
1751 static void ibmvscsis_send_messages(struct scsi_info *vscsi)
1754 /* note do not attempt to access the IU_data_ptr with this pointer
1757 struct viosrp_crq *crq = (struct viosrp_crq *)&msg_hi;
1758 struct ibmvscsis_cmd *cmd, *nxt;
1759 struct iu_entry *iue;
1760 long rc = ADAPT_SUCCESS;
1763 if (!(vscsi->flags & RESPONSE_Q_DOWN)) {
1766 list_for_each_entry_safe(cmd, nxt, &vscsi->waiting_rsp,
1769 * Check to make sure abort cmd gets processed
1770 * prior to the abort tmr cmd
1772 if (cmd->flags & DELAY_SEND)
1775 if (cmd->abort_cmd) {
1777 cmd->abort_cmd->flags &= ~(DELAY_SEND);
1778 cmd->abort_cmd = NULL;
1782 * If CMD_T_ABORTED w/o CMD_T_TAS scenarios and
1783 * the case where LIO issued a
1784 * ABORT_TASK: Sending TMR_TASK_DOES_NOT_EXIST
1785 * case then we dont send a response, since it
1788 if (cmd->se_cmd.transport_state & CMD_T_ABORTED &&
1789 !(cmd->se_cmd.transport_state & CMD_T_TAS)) {
1790 list_del(&cmd->list);
1791 ibmvscsis_free_cmd_resources(vscsi,
1794 * With a successfully aborted op
1795 * through LIO we want to increment the
1796 * the vscsi credit so that when we dont
1797 * send a rsp to the original scsi abort
1798 * op (h_send_crq), but the tm rsp to
1799 * the abort is sent, the credit is
1800 * correctly sent with the abort tm rsp.
1801 * We would need 1 for the abort tm rsp
1802 * and 1 credit for the aborted scsi op.
1803 * Thus we need to increment here.
1804 * Also we want to increment the credit
1805 * here because we want to make sure
1806 * cmd is actually released first
1807 * otherwise the client will think it
1808 * it can send a new cmd, and we could
1809 * find ourselves short of cmd elements.
1815 crq->valid = VALID_CMD_RESP_EL;
1816 crq->format = cmd->rsp.format;
1818 if (cmd->flags & CMD_FAST_FAIL)
1819 crq->status = VIOSRP_ADAPTER_FAIL;
1821 crq->IU_length = cpu_to_be16(cmd->rsp.len);
1823 rc = h_send_crq(vscsi->dma_dev->unit_address,
1824 be64_to_cpu(msg_hi),
1825 be64_to_cpu(cmd->rsp.tag));
1827 pr_debug("send_messages: cmd %p, tag 0x%llx, rc %ld\n",
1828 cmd, be64_to_cpu(cmd->rsp.tag), rc);
1830 /* if all ok free up the command
1833 if (rc == H_SUCCESS) {
1834 /* some movement has occurred */
1835 vscsi->rsp_q_timer.timer_pops = 0;
1836 list_del(&cmd->list);
1838 ibmvscsis_free_cmd_resources(vscsi,
1841 srp_snd_msg_failed(vscsi, rc);
1850 * The timer could pop with the queue empty. If
1851 * this happens, rc will always indicate a
1852 * success; clear the pop count.
1854 vscsi->rsp_q_timer.timer_pops = 0;
1857 ibmvscsis_free_cmd_qs(vscsi);
1861 /* Called with intr lock held */
1862 static void ibmvscsis_send_mad_resp(struct scsi_info *vscsi,
1863 struct ibmvscsis_cmd *cmd,
1864 struct viosrp_crq *crq)
1866 struct iu_entry *iue = cmd->iue;
1867 struct mad_common *mad = (struct mad_common *)&vio_iu(iue)->mad;
1872 rc = h_copy_rdma(sizeof(struct mad_common),
1873 vscsi->dds.window[LOCAL].liobn, iue->sbuf->dma,
1874 vscsi->dds.window[REMOTE].liobn,
1875 be64_to_cpu(crq->IU_data_ptr));
1877 cmd->rsp.format = VIOSRP_MAD_FORMAT;
1878 cmd->rsp.len = sizeof(struct mad_common);
1879 cmd->rsp.tag = mad->tag;
1880 list_add_tail(&cmd->list, &vscsi->waiting_rsp);
1881 ibmvscsis_send_messages(vscsi);
1883 pr_debug("Error sending mad response, rc %ld\n", rc);
1884 if (rc == H_PERMISSION) {
1885 if (connection_broken(vscsi))
1886 flag_bits = (RESPONSE_Q_DOWN | CLIENT_FAILED);
1888 dev_err(&vscsi->dev, "mad: failed to copy to client, rc %ld\n",
1891 ibmvscsis_free_cmd_resources(vscsi, cmd);
1892 ibmvscsis_post_disconnect(vscsi, ERR_DISCONNECT_RECONNECT,
1898 * ibmvscsis_mad() - Service a MAnagement Data gram.
1899 * @vscsi: Pointer to our adapter structure
1900 * @crq: Pointer to the CRQ entry containing the MAD request
1902 * EXECUTION ENVIRONMENT:
1903 * Interrupt, called with adapter lock held
1905 static long ibmvscsis_mad(struct scsi_info *vscsi, struct viosrp_crq *crq)
1907 struct iu_entry *iue;
1908 struct ibmvscsis_cmd *cmd;
1909 struct mad_common *mad;
1910 long rc = ADAPT_SUCCESS;
1912 switch (vscsi->state) {
1914 * We have not exchanged Init Msgs yet, so this MAD was sent
1915 * before the last Transport Event; client will not be
1916 * expecting a response.
1918 case WAIT_CONNECTION:
1919 pr_debug("mad: in Wait Connection state, ignoring MAD, flags %d\n",
1921 return ADAPT_SUCCESS;
1923 case SRP_PROCESSING:
1928 * We should never get here while we're in these states.
1929 * Just log an error and get out.
1933 case ERR_DISCONNECT:
1934 case ERR_DISCONNECT_RECONNECT:
1936 dev_err(&vscsi->dev, "mad: invalid adapter state %d for mad\n",
1938 return ADAPT_SUCCESS;
1941 cmd = ibmvscsis_get_free_cmd(vscsi);
1943 dev_err(&vscsi->dev, "mad: failed to get cmd, debit %d\n",
1945 ibmvscsis_post_disconnect(vscsi, ERR_DISCONNECT_RECONNECT, 0);
1949 cmd->type = ADAPTER_MAD;
1951 rc = ibmvscsis_copy_crq_packet(vscsi, cmd, crq);
1953 mad = (struct mad_common *)&vio_iu(iue)->mad;
1955 pr_debug("mad: type %d\n", be32_to_cpu(mad->type));
1957 rc = ibmvscsis_process_mad(vscsi, iue);
1959 pr_debug("mad: status %hd, rc %ld\n", be16_to_cpu(mad->status),
1963 ibmvscsis_send_mad_resp(vscsi, cmd, crq);
1965 ibmvscsis_free_cmd_resources(vscsi, cmd);
1968 pr_debug("Leaving mad, rc %ld\n", rc);
1973 * ibmvscsis_login_rsp() - Create/copy a login response notice to the client
1974 * @vscsi: Pointer to our adapter structure
1975 * @cmd: Pointer to the command for the SRP Login request
1977 * EXECUTION ENVIRONMENT:
1978 * Interrupt, interrupt lock held
1980 static long ibmvscsis_login_rsp(struct scsi_info *vscsi,
1981 struct ibmvscsis_cmd *cmd)
1983 struct iu_entry *iue = cmd->iue;
1984 struct srp_login_rsp *rsp = &vio_iu(iue)->srp.login_rsp;
1985 struct format_code *fmt;
1987 long rc = ADAPT_SUCCESS;
1989 memset(rsp, 0, sizeof(struct srp_login_rsp));
1991 rsp->opcode = SRP_LOGIN_RSP;
1992 rsp->req_lim_delta = cpu_to_be32(vscsi->request_limit);
1993 rsp->tag = cmd->rsp.tag;
1994 rsp->max_it_iu_len = cpu_to_be32(SRP_MAX_IU_LEN);
1995 rsp->max_ti_iu_len = cpu_to_be32(SRP_MAX_IU_LEN);
1996 fmt = (struct format_code *)&rsp->buf_fmt;
1997 fmt->buffers = SUPPORTED_FORMATS;
2000 cmd->rsp.len = sizeof(struct srp_login_rsp);
2003 rc = h_copy_rdma(cmd->rsp.len, vscsi->dds.window[LOCAL].liobn,
2004 iue->sbuf->dma, vscsi->dds.window[REMOTE].liobn,
2005 be64_to_cpu(iue->remote_token));
2012 if (connection_broken(vscsi))
2013 flag_bits = RESPONSE_Q_DOWN | CLIENT_FAILED;
2014 dev_err(&vscsi->dev, "login_rsp: error copying to client, rc %ld\n",
2016 ibmvscsis_post_disconnect(vscsi, ERR_DISCONNECT_RECONNECT,
2022 dev_err(&vscsi->dev, "login_rsp: error copying to client, rc %ld\n",
2024 ibmvscsis_post_disconnect(vscsi, ERR_DISCONNECT_RECONNECT, 0);
2032 * ibmvscsis_srp_login_rej() - Create/copy a login rejection notice to client
2033 * @vscsi: Pointer to our adapter structure
2034 * @cmd: Pointer to the command for the SRP Login request
2035 * @reason: The reason the SRP Login is being rejected, per SRP protocol
2037 * EXECUTION ENVIRONMENT:
2038 * Interrupt, interrupt lock held
2040 static long ibmvscsis_srp_login_rej(struct scsi_info *vscsi,
2041 struct ibmvscsis_cmd *cmd, u32 reason)
2043 struct iu_entry *iue = cmd->iue;
2044 struct srp_login_rej *rej = &vio_iu(iue)->srp.login_rej;
2045 struct format_code *fmt;
2047 long rc = ADAPT_SUCCESS;
2049 memset(rej, 0, sizeof(*rej));
2051 rej->opcode = SRP_LOGIN_REJ;
2052 rej->reason = cpu_to_be32(reason);
2053 rej->tag = cmd->rsp.tag;
2054 fmt = (struct format_code *)&rej->buf_fmt;
2055 fmt->buffers = SUPPORTED_FORMATS;
2057 cmd->rsp.len = sizeof(*rej);
2060 rc = h_copy_rdma(cmd->rsp.len, vscsi->dds.window[LOCAL].liobn,
2061 iue->sbuf->dma, vscsi->dds.window[REMOTE].liobn,
2062 be64_to_cpu(iue->remote_token));
2068 if (connection_broken(vscsi))
2069 flag_bits = RESPONSE_Q_DOWN | CLIENT_FAILED;
2070 dev_err(&vscsi->dev, "login_rej: error copying to client, rc %ld\n",
2072 ibmvscsis_post_disconnect(vscsi, ERR_DISCONNECT_RECONNECT,
2078 dev_err(&vscsi->dev, "login_rej: error copying to client, rc %ld\n",
2080 ibmvscsis_post_disconnect(vscsi, ERR_DISCONNECT_RECONNECT, 0);
2087 static int ibmvscsis_make_nexus(struct ibmvscsis_tport *tport)
2089 char *name = tport->tport_name;
2090 struct ibmvscsis_nexus *nexus;
2093 if (tport->ibmv_nexus) {
2094 pr_debug("tport->ibmv_nexus already exists\n");
2098 nexus = kzalloc(sizeof(*nexus), GFP_KERNEL);
2100 pr_err("Unable to allocate struct ibmvscsis_nexus\n");
2104 nexus->se_sess = target_alloc_session(&tport->se_tpg, 0, 0,
2105 TARGET_PROT_NORMAL, name, nexus,
2107 if (IS_ERR(nexus->se_sess)) {
2108 rc = PTR_ERR(nexus->se_sess);
2109 goto transport_init_fail;
2112 tport->ibmv_nexus = nexus;
2116 transport_init_fail:
2121 static int ibmvscsis_drop_nexus(struct ibmvscsis_tport *tport)
2123 struct se_session *se_sess;
2124 struct ibmvscsis_nexus *nexus;
2126 nexus = tport->ibmv_nexus;
2130 se_sess = nexus->se_sess;
2135 * Release the SCSI I_T Nexus to the emulated ibmvscsis Target Port
2137 target_wait_for_sess_cmds(se_sess);
2138 transport_deregister_session_configfs(se_sess);
2139 transport_deregister_session(se_sess);
2140 tport->ibmv_nexus = NULL;
2147 * ibmvscsis_srp_login() - Process an SRP Login Request
2148 * @vscsi: Pointer to our adapter structure
2149 * @cmd: Command element to use to process the SRP Login request
2150 * @crq: Pointer to CRQ entry containing the SRP Login request
2152 * EXECUTION ENVIRONMENT:
2153 * Interrupt, called with interrupt lock held
2155 static long ibmvscsis_srp_login(struct scsi_info *vscsi,
2156 struct ibmvscsis_cmd *cmd,
2157 struct viosrp_crq *crq)
2159 struct iu_entry *iue = cmd->iue;
2160 struct srp_login_req *req = &vio_iu(iue)->srp.login_req;
2162 __be64 id_extension;
2165 struct format_code *fmt;
2167 long rc = ADAPT_SUCCESS;
2169 iport = (struct port_id *)req->initiator_port_id;
2170 tport = (struct port_id *)req->target_port_id;
2171 fmt = (struct format_code *)&req->req_buf_fmt;
2172 if (be32_to_cpu(req->req_it_iu_len) > SRP_MAX_IU_LEN)
2173 reason = SRP_LOGIN_REJ_REQ_IT_IU_LENGTH_TOO_LARGE;
2174 else if (be32_to_cpu(req->req_it_iu_len) < 64)
2175 reason = SRP_LOGIN_REJ_UNABLE_ESTABLISH_CHANNEL;
2176 else if ((be64_to_cpu(iport->id_extension) > (MAX_NUM_PORTS - 1)) ||
2177 (be64_to_cpu(tport->id_extension) > (MAX_NUM_PORTS - 1)))
2178 reason = SRP_LOGIN_REJ_UNABLE_ASSOCIATE_CHANNEL;
2179 else if (req->req_flags & SRP_MULTICHAN_MULTI)
2180 reason = SRP_LOGIN_REJ_MULTI_CHANNEL_UNSUPPORTED;
2181 else if (fmt->buffers & (~SUPPORTED_FORMATS))
2182 reason = SRP_LOGIN_REJ_UNSUPPORTED_DESCRIPTOR_FMT;
2183 else if ((fmt->buffers & SUPPORTED_FORMATS) == 0)
2184 reason = SRP_LOGIN_REJ_UNSUPPORTED_DESCRIPTOR_FMT;
2186 if (vscsi->state == SRP_PROCESSING)
2187 reason = SRP_LOGIN_REJ_CHANNEL_LIMIT_REACHED;
2189 rc = ibmvscsis_make_nexus(&vscsi->tport);
2191 reason = SRP_LOGIN_REJ_UNABLE_ESTABLISH_CHANNEL;
2193 cmd->rsp.format = VIOSRP_SRP_FORMAT;
2194 cmd->rsp.tag = req->tag;
2196 pr_debug("srp_login: reason 0x%x\n", reason);
2199 rc = ibmvscsis_srp_login_rej(vscsi, cmd, reason);
2201 rc = ibmvscsis_login_rsp(vscsi, cmd);
2205 vscsi->state = SRP_PROCESSING;
2207 list_add_tail(&cmd->list, &vscsi->waiting_rsp);
2208 ibmvscsis_send_messages(vscsi);
2210 ibmvscsis_free_cmd_resources(vscsi, cmd);
2213 pr_debug("Leaving srp_login, rc %ld\n", rc);
2218 * ibmvscsis_srp_i_logout() - Helper Function to close I_T Nexus
2219 * @vscsi: Pointer to our adapter structure
2220 * @cmd: Command element to use to process the Implicit Logout request
2221 * @crq: Pointer to CRQ entry containing the Implicit Logout request
2223 * Do the logic to close the I_T nexus. This function may not
2224 * behave to specification.
2226 * EXECUTION ENVIRONMENT:
2227 * Interrupt, interrupt lock held
2229 static long ibmvscsis_srp_i_logout(struct scsi_info *vscsi,
2230 struct ibmvscsis_cmd *cmd,
2231 struct viosrp_crq *crq)
2233 struct iu_entry *iue = cmd->iue;
2234 struct srp_i_logout *log_out = &vio_iu(iue)->srp.i_logout;
2235 long rc = ADAPT_SUCCESS;
2237 if ((vscsi->debit > 0) || !list_empty(&vscsi->schedule_q) ||
2238 !list_empty(&vscsi->waiting_rsp)) {
2239 dev_err(&vscsi->dev, "i_logout: outstanding work\n");
2240 ibmvscsis_post_disconnect(vscsi, ERR_DISCONNECT, 0);
2242 cmd->rsp.format = SRP_FORMAT;
2243 cmd->rsp.tag = log_out->tag;
2244 cmd->rsp.len = sizeof(struct mad_common);
2245 list_add_tail(&cmd->list, &vscsi->waiting_rsp);
2246 ibmvscsis_send_messages(vscsi);
2248 ibmvscsis_post_disconnect(vscsi, WAIT_IDLE, 0);
2254 /* Called with intr lock held */
2255 static void ibmvscsis_srp_cmd(struct scsi_info *vscsi, struct viosrp_crq *crq)
2257 struct ibmvscsis_cmd *cmd;
2258 struct iu_entry *iue;
2259 struct srp_cmd *srp;
2260 struct srp_tsk_mgmt *tsk;
2263 if (vscsi->request_limit - vscsi->debit <= 0) {
2264 /* Client has exceeded request limit */
2265 dev_err(&vscsi->dev, "Client exceeded the request limit (%d), debit %d\n",
2266 vscsi->request_limit, vscsi->debit);
2267 ibmvscsis_post_disconnect(vscsi, ERR_DISCONNECT_RECONNECT, 0);
2271 cmd = ibmvscsis_get_free_cmd(vscsi);
2273 dev_err(&vscsi->dev, "srp_cmd failed to get cmd, debit %d\n",
2275 ibmvscsis_post_disconnect(vscsi, ERR_DISCONNECT_RECONNECT, 0);
2279 srp = &vio_iu(iue)->srp.cmd;
2281 rc = ibmvscsis_copy_crq_packet(vscsi, cmd, crq);
2283 ibmvscsis_free_cmd_resources(vscsi, cmd);
2287 if (vscsi->state == SRP_PROCESSING) {
2288 switch (srp->opcode) {
2290 rc = ibmvscsis_srp_login(vscsi, cmd, crq);
2294 tsk = &vio_iu(iue)->srp.tsk_mgmt;
2295 pr_debug("tsk_mgmt tag: %llu (0x%llx)\n", tsk->tag,
2297 cmd->rsp.tag = tsk->tag;
2299 cmd->type = TASK_MANAGEMENT;
2300 list_add_tail(&cmd->list, &vscsi->schedule_q);
2301 queue_work(vscsi->work_q, &cmd->work);
2305 pr_debug("srp_cmd tag: %llu (0x%llx)\n", srp->tag,
2307 cmd->rsp.tag = srp->tag;
2309 cmd->type = SCSI_CDB;
2311 * We want to keep track of work waiting for
2314 list_add_tail(&cmd->list, &vscsi->schedule_q);
2315 queue_work(vscsi->work_q, &cmd->work);
2319 rc = ibmvscsis_srp_i_logout(vscsi, cmd, crq);
2325 ibmvscsis_free_cmd_resources(vscsi, cmd);
2326 dev_err(&vscsi->dev, "invalid srp cmd, opcode %d\n",
2328 ibmvscsis_post_disconnect(vscsi,
2329 ERR_DISCONNECT_RECONNECT, 0);
2332 } else if (srp->opcode == SRP_LOGIN_REQ && vscsi->state == CONNECTED) {
2333 rc = ibmvscsis_srp_login(vscsi, cmd, crq);
2335 ibmvscsis_free_cmd_resources(vscsi, cmd);
2336 dev_err(&vscsi->dev, "Invalid state %d to handle srp cmd\n",
2338 ibmvscsis_post_disconnect(vscsi, ERR_DISCONNECT_RECONNECT, 0);
2343 * ibmvscsis_ping_response() - Respond to a ping request
2344 * @vscsi: Pointer to our adapter structure
2346 * Let the client know that the server is alive and waiting on
2347 * its native I/O stack.
2348 * If any type of error occurs from the call to queue a ping
2349 * response then the client is either not accepting or receiving
2350 * interrupts. Disconnect with an error.
2352 * EXECUTION ENVIRONMENT:
2353 * Interrupt, interrupt lock held
2355 static long ibmvscsis_ping_response(struct scsi_info *vscsi)
2357 struct viosrp_crq *crq;
2358 u64 buffer[2] = { 0, 0 };
2361 crq = (struct viosrp_crq *)&buffer;
2362 crq->valid = VALID_CMD_RESP_EL;
2363 crq->format = (u8)MESSAGE_IN_CRQ;
2364 crq->status = PING_RESPONSE;
2366 rc = h_send_crq(vscsi->dds.unit_id, cpu_to_be64(buffer[MSG_HI]),
2367 cpu_to_be64(buffer[MSG_LOW]));
2373 vscsi->flags |= CLIENT_FAILED;
2375 vscsi->flags |= RESPONSE_Q_DOWN;
2377 dev_err(&vscsi->dev, "ping_response: h_send_crq failed, rc %ld\n",
2379 ibmvscsis_post_disconnect(vscsi, ERR_DISCONNECT_RECONNECT, 0);
2382 dev_err(&vscsi->dev, "ping_response: h_send_crq returned unknown rc %ld\n",
2384 ibmvscsis_post_disconnect(vscsi, ERR_DISCONNECT, 0);
2392 * ibmvscsis_parse_command() - Parse an element taken from the cmd rsp queue.
2393 * @vscsi: Pointer to our adapter structure
2394 * @crq: Pointer to CRQ element containing the SRP request
2396 * This function will return success if the command queue element is valid
2397 * and the srp iu or MAD request it pointed to was also valid. That does
2398 * not mean that an error was not returned to the client.
2400 * EXECUTION ENVIRONMENT:
2401 * Interrupt, intr lock held
2403 static long ibmvscsis_parse_command(struct scsi_info *vscsi,
2404 struct viosrp_crq *crq)
2406 long rc = ADAPT_SUCCESS;
2408 switch (crq->valid) {
2409 case VALID_CMD_RESP_EL:
2410 switch (crq->format) {
2415 if (vscsi->flags & PROCESSING_MAD) {
2417 dev_err(&vscsi->dev, "parse_command: already processing mad\n");
2418 ibmvscsis_post_disconnect(vscsi,
2419 ERR_DISCONNECT_RECONNECT,
2422 vscsi->flags |= PROCESSING_MAD;
2423 rc = ibmvscsis_mad(vscsi, crq);
2428 ibmvscsis_srp_cmd(vscsi, crq);
2431 case MESSAGE_IN_CRQ:
2432 if (crq->status == PING)
2433 ibmvscsis_ping_response(vscsi);
2437 dev_err(&vscsi->dev, "parse_command: invalid format %d\n",
2439 ibmvscsis_post_disconnect(vscsi,
2440 ERR_DISCONNECT_RECONNECT, 0);
2445 case VALID_TRANS_EVENT:
2446 rc = ibmvscsis_trans_event(vscsi, crq);
2449 case VALID_INIT_MSG:
2450 rc = ibmvscsis_init_msg(vscsi, crq);
2454 dev_err(&vscsi->dev, "parse_command: invalid valid field %d\n",
2456 ibmvscsis_post_disconnect(vscsi, ERR_DISCONNECT_RECONNECT, 0);
2461 * Return only what the interrupt handler cares
2462 * about. Most errors we keep right on trucking.
2464 rc = vscsi->flags & SCHEDULE_DISCONNECT;
2469 static int read_dma_window(struct scsi_info *vscsi)
2471 struct vio_dev *vdev = vscsi->dma_dev;
2472 const __be32 *dma_window;
2475 /* TODO Using of_parse_dma_window would be better, but it doesn't give
2476 * a way to read multiple windows without already knowing the size of
2477 * a window or the number of windows.
2479 dma_window = (const __be32 *)vio_get_attribute(vdev,
2480 "ibm,my-dma-window",
2483 pr_err("Couldn't find ibm,my-dma-window property\n");
2487 vscsi->dds.window[LOCAL].liobn = be32_to_cpu(*dma_window);
2490 prop = (const __be32 *)vio_get_attribute(vdev, "ibm,#dma-address-cells",
2493 pr_warn("Couldn't find ibm,#dma-address-cells property\n");
2496 dma_window += be32_to_cpu(*prop);
2499 prop = (const __be32 *)vio_get_attribute(vdev, "ibm,#dma-size-cells",
2502 pr_warn("Couldn't find ibm,#dma-size-cells property\n");
2505 dma_window += be32_to_cpu(*prop);
2508 /* dma_window should point to the second window now */
2509 vscsi->dds.window[REMOTE].liobn = be32_to_cpu(*dma_window);
2514 static struct ibmvscsis_tport *ibmvscsis_lookup_port(const char *name)
2516 struct ibmvscsis_tport *tport = NULL;
2517 struct vio_dev *vdev;
2518 struct scsi_info *vscsi;
2520 spin_lock_bh(&ibmvscsis_dev_lock);
2521 list_for_each_entry(vscsi, &ibmvscsis_dev_list, list) {
2522 vdev = vscsi->dma_dev;
2523 if (!strcmp(dev_name(&vdev->dev), name)) {
2524 tport = &vscsi->tport;
2528 spin_unlock_bh(&ibmvscsis_dev_lock);
2534 * ibmvscsis_parse_cmd() - Parse SRP Command
2535 * @vscsi: Pointer to our adapter structure
2536 * @cmd: Pointer to command element with SRP command
2538 * Parse the srp command; if it is valid then submit it to tcm.
2539 * Note: The return code does not reflect the status of the SCSI CDB.
2541 * EXECUTION ENVIRONMENT:
2544 static void ibmvscsis_parse_cmd(struct scsi_info *vscsi,
2545 struct ibmvscsis_cmd *cmd)
2547 struct iu_entry *iue = cmd->iue;
2548 struct srp_cmd *srp = (struct srp_cmd *)iue->sbuf->buf;
2549 struct ibmvscsis_nexus *nexus;
2551 enum dma_data_direction dir;
2555 nexus = vscsi->tport.ibmv_nexus;
2557 * additional length in bytes. Note that the SRP spec says that
2558 * additional length is in 4-byte words, but technically the
2559 * additional length field is only the upper 6 bits of the byte.
2560 * The lower 2 bits are reserved. If the lower 2 bits are 0 (as
2561 * all reserved fields should be), then interpreting the byte as
2562 * an int will yield the length in bytes.
2564 if (srp->add_cdb_len & 0x03) {
2565 dev_err(&vscsi->dev, "parse_cmd: reserved bits set in IU\n");
2566 spin_lock_bh(&vscsi->intr_lock);
2567 ibmvscsis_post_disconnect(vscsi, ERR_DISCONNECT_RECONNECT, 0);
2568 ibmvscsis_free_cmd_resources(vscsi, cmd);
2569 spin_unlock_bh(&vscsi->intr_lock);
2573 if (srp_get_desc_table(srp, &dir, &data_len)) {
2574 dev_err(&vscsi->dev, "0x%llx: parsing SRP descriptor table failed.\n",
2579 cmd->rsp.sol_not = srp->sol_not;
2581 switch (srp->task_attr) {
2582 case SRP_SIMPLE_TASK:
2583 attr = TCM_SIMPLE_TAG;
2585 case SRP_ORDERED_TASK:
2586 attr = TCM_ORDERED_TAG;
2589 attr = TCM_HEAD_TAG;
2595 dev_err(&vscsi->dev, "Invalid task attribute %d\n",
2600 cmd->se_cmd.tag = be64_to_cpu(srp->tag);
2602 spin_lock_bh(&vscsi->intr_lock);
2603 list_add_tail(&cmd->list, &vscsi->active_q);
2604 spin_unlock_bh(&vscsi->intr_lock);
2606 srp->lun.scsi_lun[0] &= 0x3f;
2608 rc = target_submit_cmd(&cmd->se_cmd, nexus->se_sess, srp->cdb,
2609 cmd->sense_buf, scsilun_to_int(&srp->lun),
2610 data_len, attr, dir, 0);
2612 dev_err(&vscsi->dev, "target_submit_cmd failed, rc %d\n", rc);
2613 spin_lock_bh(&vscsi->intr_lock);
2614 list_del(&cmd->list);
2615 ibmvscsis_free_cmd_resources(vscsi, cmd);
2616 spin_unlock_bh(&vscsi->intr_lock);
2622 spin_lock_bh(&vscsi->intr_lock);
2623 ibmvscsis_post_disconnect(vscsi, ERR_DISCONNECT_RECONNECT, 0);
2624 spin_unlock_bh(&vscsi->intr_lock);
2628 * ibmvscsis_parse_task() - Parse SRP Task Management Request
2629 * @vscsi: Pointer to our adapter structure
2630 * @cmd: Pointer to command element with SRP task management request
2632 * Parse the srp task management request; if it is valid then submit it to tcm.
2633 * Note: The return code does not reflect the status of the task management
2636 * EXECUTION ENVIRONMENT:
2639 static void ibmvscsis_parse_task(struct scsi_info *vscsi,
2640 struct ibmvscsis_cmd *cmd)
2642 struct iu_entry *iue = cmd->iue;
2643 struct srp_tsk_mgmt *srp_tsk = &vio_iu(iue)->srp.tsk_mgmt;
2645 u64 tag_to_abort = 0;
2647 struct ibmvscsis_nexus *nexus;
2649 nexus = vscsi->tport.ibmv_nexus;
2651 cmd->rsp.sol_not = srp_tsk->sol_not;
2653 switch (srp_tsk->tsk_mgmt_func) {
2654 case SRP_TSK_ABORT_TASK:
2655 tcm_type = TMR_ABORT_TASK;
2656 tag_to_abort = be64_to_cpu(srp_tsk->task_tag);
2658 case SRP_TSK_ABORT_TASK_SET:
2659 tcm_type = TMR_ABORT_TASK_SET;
2661 case SRP_TSK_CLEAR_TASK_SET:
2662 tcm_type = TMR_CLEAR_TASK_SET;
2664 case SRP_TSK_LUN_RESET:
2665 tcm_type = TMR_LUN_RESET;
2667 case SRP_TSK_CLEAR_ACA:
2668 tcm_type = TMR_CLEAR_ACA;
2671 dev_err(&vscsi->dev, "unknown task mgmt func %d\n",
2672 srp_tsk->tsk_mgmt_func);
2673 cmd->se_cmd.se_tmr_req->response =
2674 TMR_TASK_MGMT_FUNCTION_NOT_SUPPORTED;
2680 cmd->se_cmd.tag = be64_to_cpu(srp_tsk->tag);
2682 spin_lock_bh(&vscsi->intr_lock);
2683 list_add_tail(&cmd->list, &vscsi->active_q);
2684 spin_unlock_bh(&vscsi->intr_lock);
2686 srp_tsk->lun.scsi_lun[0] &= 0x3f;
2688 pr_debug("calling submit_tmr, func %d\n",
2689 srp_tsk->tsk_mgmt_func);
2690 rc = target_submit_tmr(&cmd->se_cmd, nexus->se_sess, NULL,
2691 scsilun_to_int(&srp_tsk->lun), srp_tsk,
2692 tcm_type, GFP_KERNEL, tag_to_abort, 0);
2694 dev_err(&vscsi->dev, "target_submit_tmr failed, rc %d\n",
2696 spin_lock_bh(&vscsi->intr_lock);
2697 list_del(&cmd->list);
2698 spin_unlock_bh(&vscsi->intr_lock);
2699 cmd->se_cmd.se_tmr_req->response =
2700 TMR_FUNCTION_REJECTED;
2705 transport_send_check_condition_and_sense(&cmd->se_cmd, 0, 0);
2708 static void ibmvscsis_scheduler(struct work_struct *work)
2710 struct ibmvscsis_cmd *cmd = container_of(work, struct ibmvscsis_cmd,
2712 struct scsi_info *vscsi = cmd->adapter;
2714 spin_lock_bh(&vscsi->intr_lock);
2716 /* Remove from schedule_q */
2717 list_del(&cmd->list);
2719 /* Don't submit cmd if we're disconnecting */
2720 if (vscsi->flags & (SCHEDULE_DISCONNECT | DISCONNECT_SCHEDULED)) {
2721 ibmvscsis_free_cmd_resources(vscsi, cmd);
2723 /* ibmvscsis_disconnect might be waiting for us */
2724 if (list_empty(&vscsi->active_q) &&
2725 list_empty(&vscsi->schedule_q) &&
2726 (vscsi->flags & WAIT_FOR_IDLE)) {
2727 vscsi->flags &= ~WAIT_FOR_IDLE;
2728 complete(&vscsi->wait_idle);
2731 spin_unlock_bh(&vscsi->intr_lock);
2735 spin_unlock_bh(&vscsi->intr_lock);
2737 switch (cmd->type) {
2739 ibmvscsis_parse_cmd(vscsi, cmd);
2741 case TASK_MANAGEMENT:
2742 ibmvscsis_parse_task(vscsi, cmd);
2745 dev_err(&vscsi->dev, "scheduler, invalid cmd type %d\n",
2747 spin_lock_bh(&vscsi->intr_lock);
2748 ibmvscsis_free_cmd_resources(vscsi, cmd);
2749 spin_unlock_bh(&vscsi->intr_lock);
2754 static int ibmvscsis_alloc_cmds(struct scsi_info *vscsi, int num)
2756 struct ibmvscsis_cmd *cmd;
2759 INIT_LIST_HEAD(&vscsi->free_cmd);
2760 vscsi->cmd_pool = kcalloc(num, sizeof(struct ibmvscsis_cmd),
2762 if (!vscsi->cmd_pool)
2765 for (i = 0, cmd = (struct ibmvscsis_cmd *)vscsi->cmd_pool; i < num;
2767 cmd->abort_cmd = NULL;
2768 cmd->adapter = vscsi;
2769 INIT_WORK(&cmd->work, ibmvscsis_scheduler);
2770 list_add_tail(&cmd->list, &vscsi->free_cmd);
2776 static void ibmvscsis_free_cmds(struct scsi_info *vscsi)
2778 kfree(vscsi->cmd_pool);
2779 vscsi->cmd_pool = NULL;
2780 INIT_LIST_HEAD(&vscsi->free_cmd);
2784 * ibmvscsis_service_wait_q() - Service Waiting Queue
2785 * @timer: Pointer to timer which has expired
2787 * This routine is called when the timer pops to service the waiting
2788 * queue. Elements on the queue have completed, their responses have been
2789 * copied to the client, but the client's response queue was full so
2790 * the queue message could not be sent. The routine grabs the proper locks
2791 * and calls send messages.
2793 * EXECUTION ENVIRONMENT:
2794 * called at interrupt level
2796 static enum hrtimer_restart ibmvscsis_service_wait_q(struct hrtimer *timer)
2798 struct timer_cb *p_timer = container_of(timer, struct timer_cb, timer);
2799 struct scsi_info *vscsi = container_of(p_timer, struct scsi_info,
2802 spin_lock_bh(&vscsi->intr_lock);
2803 p_timer->timer_pops += 1;
2804 p_timer->started = false;
2805 ibmvscsis_send_messages(vscsi);
2806 spin_unlock_bh(&vscsi->intr_lock);
2808 return HRTIMER_NORESTART;
2811 static long ibmvscsis_alloctimer(struct scsi_info *vscsi)
2813 struct timer_cb *p_timer;
2815 p_timer = &vscsi->rsp_q_timer;
2816 hrtimer_init(&p_timer->timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
2818 p_timer->timer.function = ibmvscsis_service_wait_q;
2819 p_timer->started = false;
2820 p_timer->timer_pops = 0;
2822 return ADAPT_SUCCESS;
2825 static void ibmvscsis_freetimer(struct scsi_info *vscsi)
2827 struct timer_cb *p_timer;
2829 p_timer = &vscsi->rsp_q_timer;
2831 (void)hrtimer_cancel(&p_timer->timer);
2833 p_timer->started = false;
2834 p_timer->timer_pops = 0;
2837 static irqreturn_t ibmvscsis_interrupt(int dummy, void *data)
2839 struct scsi_info *vscsi = data;
2841 vio_disable_interrupts(vscsi->dma_dev);
2842 tasklet_schedule(&vscsi->work_task);
2848 * ibmvscsis_enable_change_state() - Set new state based on enabled status
2849 * @vscsi: Pointer to our adapter structure
2851 * This function determines our new state now that we are enabled. This
2852 * may involve sending an Init Complete message to the client.
2854 * Must be called with interrupt lock held.
2856 static long ibmvscsis_enable_change_state(struct scsi_info *vscsi)
2859 long rc = ADAPT_SUCCESS;
2861 bytes = vscsi->cmd_q.size * PAGE_SIZE;
2862 rc = h_reg_crq(vscsi->dds.unit_id, vscsi->cmd_q.crq_token, bytes);
2863 if (rc == H_CLOSED || rc == H_SUCCESS) {
2864 vscsi->state = WAIT_CONNECTION;
2865 rc = ibmvscsis_establish_new_q(vscsi);
2868 if (rc != ADAPT_SUCCESS) {
2869 vscsi->state = ERR_DISCONNECTED;
2870 vscsi->flags |= RESPONSE_Q_DOWN;
2877 * ibmvscsis_create_command_q() - Create Command Queue
2878 * @vscsi: Pointer to our adapter structure
2879 * @num_cmds: Currently unused. In the future, may be used to determine
2880 * the size of the CRQ.
2882 * Allocates memory for command queue maps remote memory into an ioba
2883 * initializes the command response queue
2885 * EXECUTION ENVIRONMENT:
2886 * Process level only
2888 static long ibmvscsis_create_command_q(struct scsi_info *vscsi, int num_cmds)
2891 struct vio_dev *vdev = vscsi->dma_dev;
2893 /* We might support multiple pages in the future, but just 1 for now */
2896 vscsi->cmd_q.size = pages;
2898 vscsi->cmd_q.base_addr =
2899 (struct viosrp_crq *)get_zeroed_page(GFP_KERNEL);
2900 if (!vscsi->cmd_q.base_addr)
2903 vscsi->cmd_q.mask = ((uint)pages * CRQ_PER_PAGE) - 1;
2905 vscsi->cmd_q.crq_token = dma_map_single(&vdev->dev,
2906 vscsi->cmd_q.base_addr,
2907 PAGE_SIZE, DMA_BIDIRECTIONAL);
2908 if (dma_mapping_error(&vdev->dev, vscsi->cmd_q.crq_token)) {
2909 free_page((unsigned long)vscsi->cmd_q.base_addr);
2917 * ibmvscsis_destroy_command_q - Destroy Command Queue
2918 * @vscsi: Pointer to our adapter structure
2920 * Releases memory for command queue and unmaps mapped remote memory.
2922 * EXECUTION ENVIRONMENT:
2923 * Process level only
2925 static void ibmvscsis_destroy_command_q(struct scsi_info *vscsi)
2927 dma_unmap_single(&vscsi->dma_dev->dev, vscsi->cmd_q.crq_token,
2928 PAGE_SIZE, DMA_BIDIRECTIONAL);
2929 free_page((unsigned long)vscsi->cmd_q.base_addr);
2930 vscsi->cmd_q.base_addr = NULL;
2931 vscsi->state = NO_QUEUE;
2934 static u8 ibmvscsis_fast_fail(struct scsi_info *vscsi,
2935 struct ibmvscsis_cmd *cmd)
2937 struct iu_entry *iue = cmd->iue;
2938 struct se_cmd *se_cmd = &cmd->se_cmd;
2939 struct srp_cmd *srp = (struct srp_cmd *)iue->sbuf->buf;
2940 struct scsi_sense_hdr sshdr;
2941 u8 rc = se_cmd->scsi_status;
2943 if (vscsi->fast_fail && (READ_CMD(srp->cdb) || WRITE_CMD(srp->cdb)))
2944 if (scsi_normalize_sense(se_cmd->sense_buffer,
2945 se_cmd->scsi_sense_length, &sshdr))
2946 if (sshdr.sense_key == HARDWARE_ERROR &&
2947 (se_cmd->residual_count == 0 ||
2948 se_cmd->residual_count == se_cmd->data_length)) {
2950 cmd->flags |= CMD_FAST_FAIL;
2957 * srp_build_response() - Build an SRP response buffer
2958 * @vscsi: Pointer to our adapter structure
2959 * @cmd: Pointer to command for which to send the response
2960 * @len_p: Where to return the length of the IU response sent. This
2961 * is needed to construct the CRQ response.
2963 * Build the SRP response buffer and copy it to the client's memory space.
2965 static long srp_build_response(struct scsi_info *vscsi,
2966 struct ibmvscsis_cmd *cmd, uint *len_p)
2968 struct iu_entry *iue = cmd->iue;
2969 struct se_cmd *se_cmd = &cmd->se_cmd;
2970 struct srp_rsp *rsp;
2975 long rc = ADAPT_SUCCESS;
2977 spin_lock_bh(&vscsi->intr_lock);
2979 rsp = &vio_iu(iue)->srp.rsp;
2981 memset(rsp, 0, len);
2984 rsp->opcode = SRP_RSP;
2986 rsp->req_lim_delta = cpu_to_be32(1 + vscsi->credit);
2987 rsp->tag = cmd->rsp.tag;
2990 if (cmd->type == SCSI_CDB) {
2991 rsp->status = ibmvscsis_fast_fail(vscsi, cmd);
2993 pr_debug("build_resp: cmd %p, scsi status %d\n", cmd,
2995 ibmvscsis_determine_resid(se_cmd, rsp);
2996 if (se_cmd->scsi_sense_length && se_cmd->sense_buffer) {
2997 rsp->sense_data_len =
2998 cpu_to_be32(se_cmd->scsi_sense_length);
2999 rsp->flags |= SRP_RSP_FLAG_SNSVALID;
3000 len += se_cmd->scsi_sense_length;
3001 memcpy(data, se_cmd->sense_buffer,
3002 se_cmd->scsi_sense_length);
3004 rsp->sol_not = (cmd->rsp.sol_not & UCSOLNT) >>
3006 } else if (cmd->flags & CMD_FAST_FAIL) {
3007 pr_debug("build_resp: cmd %p, fast fail\n", cmd);
3008 rsp->sol_not = (cmd->rsp.sol_not & UCSOLNT) >>
3011 rsp->sol_not = (cmd->rsp.sol_not & SCSOLNT) >>
3015 /* this is task management */
3017 rsp->resp_data_len = cpu_to_be32(4);
3018 rsp->flags |= SRP_RSP_FLAG_RSPVALID;
3020 switch (se_cmd->se_tmr_req->response) {
3021 case TMR_FUNCTION_COMPLETE:
3022 case TMR_TASK_DOES_NOT_EXIST:
3023 rsp_code = SRP_TASK_MANAGEMENT_FUNCTION_COMPLETE;
3024 rsp->sol_not = (cmd->rsp.sol_not & SCSOLNT) >>
3027 case TMR_TASK_MGMT_FUNCTION_NOT_SUPPORTED:
3028 case TMR_LUN_DOES_NOT_EXIST:
3029 rsp_code = SRP_TASK_MANAGEMENT_FUNCTION_NOT_SUPPORTED;
3030 rsp->sol_not = (cmd->rsp.sol_not & UCSOLNT) >>
3033 case TMR_FUNCTION_FAILED:
3034 case TMR_FUNCTION_REJECTED:
3036 rsp_code = SRP_TASK_MANAGEMENT_FUNCTION_FAILED;
3037 rsp->sol_not = (cmd->rsp.sol_not & UCSOLNT) >>
3042 tsk_status = (u32 *)data;
3043 *tsk_status = cpu_to_be32(rsp_code);
3044 data = (char *)(tsk_status + 1);
3049 rc = h_copy_rdma(len, vscsi->dds.window[LOCAL].liobn, iue->sbuf->dma,
3050 vscsi->dds.window[REMOTE].liobn,
3051 be64_to_cpu(iue->remote_token));
3059 if (connection_broken(vscsi))
3060 vscsi->flags |= RESPONSE_Q_DOWN | CLIENT_FAILED;
3062 dev_err(&vscsi->dev, "build_response: error copying to client, rc %ld, flags 0x%x, state 0x%hx\n",
3063 rc, vscsi->flags, vscsi->state);
3068 dev_err(&vscsi->dev, "build_response: error copying to client, rc %ld\n",
3073 spin_unlock_bh(&vscsi->intr_lock);
3078 static int ibmvscsis_rdma(struct ibmvscsis_cmd *cmd, struct scatterlist *sg,
3079 int nsg, struct srp_direct_buf *md, int nmd,
3080 enum dma_data_direction dir, unsigned int bytes)
3082 struct iu_entry *iue = cmd->iue;
3083 struct srp_target *target = iue->target;
3084 struct scsi_info *vscsi = target->ldata;
3085 struct scatterlist *sgp;
3086 dma_addr_t client_ioba, server_ioba;
3088 ulong client_len, server_len;
3103 if (client_len == 0) {
3104 if (md_idx >= nmd) {
3105 dev_err(&vscsi->dev, "rdma: ran out of client memory descriptors\n");
3109 client_ioba = be64_to_cpu(md[md_idx].va);
3110 client_len = be32_to_cpu(md[md_idx].len);
3112 if (server_len == 0) {
3114 dev_err(&vscsi->dev, "rdma: ran out of scatter/gather list\n");
3118 server_ioba = sg_dma_address(sgp);
3119 server_len = sg_dma_len(sgp);
3124 if (buf_len > client_len)
3125 buf_len = client_len;
3127 if (buf_len > server_len)
3128 buf_len = server_len;
3130 if (buf_len > max_vdma_size)
3131 buf_len = max_vdma_size;
3133 if (dir == DMA_TO_DEVICE) {
3134 /* read from client */
3135 rc = h_copy_rdma(buf_len,
3136 vscsi->dds.window[REMOTE].liobn,
3138 vscsi->dds.window[LOCAL].liobn,
3141 /* The h_copy_rdma will cause phyp, running in another
3142 * partition, to read memory, so we need to make sure
3143 * the data has been written out, hence these syncs.
3145 /* ensure that everything is in memory */
3147 /* ensure that memory has been made visible */
3149 rc = h_copy_rdma(buf_len,
3150 vscsi->dds.window[LOCAL].liobn,
3152 vscsi->dds.window[REMOTE].liobn,
3161 if (connection_broken(vscsi)) {
3162 spin_lock_bh(&vscsi->intr_lock);
3164 (RESPONSE_Q_DOWN | CLIENT_FAILED);
3165 spin_unlock_bh(&vscsi->intr_lock);
3167 dev_err(&vscsi->dev, "rdma: h_copy_rdma failed, rc %ld\n",
3172 dev_err(&vscsi->dev, "rdma: unknown error %ld from h_copy_rdma\n",
3180 client_len -= buf_len;
3181 if (client_len == 0)
3184 client_ioba += buf_len;
3186 server_len -= buf_len;
3187 if (server_len == 0)
3190 server_ioba += buf_len;
3201 * ibmvscsis_handle_crq() - Handle CRQ
3202 * @data: Pointer to our adapter structure
3204 * Read the command elements from the command queue and copy the payloads
3205 * associated with the command elements to local memory and execute the
3208 * Note: this is an edge triggered interrupt. It can not be shared.
3210 static void ibmvscsis_handle_crq(unsigned long data)
3212 struct scsi_info *vscsi = (struct scsi_info *)data;
3213 struct viosrp_crq *crq;
3218 spin_lock_bh(&vscsi->intr_lock);
3220 pr_debug("got interrupt\n");
3223 * if we are in a path where we are waiting for all pending commands
3224 * to complete because we received a transport event and anything in
3225 * the command queue is for a new connection, do nothing
3227 if (TARGET_STOP(vscsi)) {
3228 vio_enable_interrupts(vscsi->dma_dev);
3230 pr_debug("handle_crq, don't process: flags 0x%x, state 0x%hx\n",
3231 vscsi->flags, vscsi->state);
3232 spin_unlock_bh(&vscsi->intr_lock);
3236 rc = vscsi->flags & SCHEDULE_DISCONNECT;
3237 crq = vscsi->cmd_q.base_addr + vscsi->cmd_q.index;
3243 * These are edege triggered interrupts. After dropping out of
3244 * the while loop, the code must check for work since an
3245 * interrupt could be lost, and an elment be left on the queue,
3249 vscsi->cmd_q.index =
3250 (vscsi->cmd_q.index + 1) & vscsi->cmd_q.mask;
3253 rc = ibmvscsis_parse_command(vscsi, crq);
3255 if ((uint)crq->valid == VALID_TRANS_EVENT) {
3257 * must service the transport layer events even
3258 * in an error state, dont break out until all
3259 * the consecutive transport events have been
3262 rc = ibmvscsis_trans_event(vscsi, crq);
3263 } else if (vscsi->flags & TRANS_EVENT) {
3265 * if a transport event has occurred leave
3266 * everything but transport events on the queue
3268 * need to decrement the queue index so we can
3269 * look at the element again
3271 if (vscsi->cmd_q.index)
3272 vscsi->cmd_q.index -= 1;
3275 * index is at 0 it just wrapped.
3276 * have it index last element in q
3278 vscsi->cmd_q.index = vscsi->cmd_q.mask;
3283 crq->valid = INVALIDATE_CMD_RESP_EL;
3285 crq = vscsi->cmd_q.base_addr + vscsi->cmd_q.index;
3292 vio_enable_interrupts(vscsi->dma_dev);
3294 pr_debug("handle_crq, reenabling interrupts\n");
3301 pr_debug("handle_crq, error: flags 0x%x, state 0x%hx, crq index 0x%x\n",
3302 vscsi->flags, vscsi->state, vscsi->cmd_q.index);
3305 pr_debug("Leaving handle_crq: schedule_q empty %d, flags 0x%x, state 0x%hx\n",
3306 (int)list_empty(&vscsi->schedule_q), vscsi->flags,
3309 spin_unlock_bh(&vscsi->intr_lock);
3312 static int ibmvscsis_probe(struct vio_dev *vdev,
3313 const struct vio_device_id *id)
3315 struct scsi_info *vscsi;
3320 vscsi = kzalloc(sizeof(*vscsi), GFP_KERNEL);
3323 pr_err("probe: allocation of adapter failed\n");
3327 vscsi->dma_dev = vdev;
3328 vscsi->dev = vdev->dev;
3329 INIT_LIST_HEAD(&vscsi->schedule_q);
3330 INIT_LIST_HEAD(&vscsi->waiting_rsp);
3331 INIT_LIST_HEAD(&vscsi->active_q);
3333 snprintf(vscsi->tport.tport_name, IBMVSCSIS_NAMELEN, "%s",
3334 dev_name(&vdev->dev));
3336 pr_debug("probe tport_name: %s\n", vscsi->tport.tport_name);
3338 rc = read_dma_window(vscsi);
3341 pr_debug("Probe: liobn 0x%x, riobn 0x%x\n",
3342 vscsi->dds.window[LOCAL].liobn,
3343 vscsi->dds.window[REMOTE].liobn);
3345 snprintf(vscsi->eye, sizeof(vscsi->eye), "VSCSI %s", vdev->name);
3347 vscsi->dds.unit_id = vdev->unit_address;
3348 strscpy(vscsi->dds.partition_name, partition_name,
3349 sizeof(vscsi->dds.partition_name));
3350 vscsi->dds.partition_num = partition_number;
3352 spin_lock_bh(&ibmvscsis_dev_lock);
3353 list_add_tail(&vscsi->list, &ibmvscsis_dev_list);
3354 spin_unlock_bh(&ibmvscsis_dev_lock);
3357 * TBD: How do we determine # of cmds to request? Do we know how
3358 * many "children" we have?
3360 vscsi->request_limit = INITIAL_SRP_LIMIT;
3361 rc = srp_target_alloc(&vscsi->target, &vdev->dev, vscsi->request_limit,
3366 vscsi->target.ldata = vscsi;
3368 rc = ibmvscsis_alloc_cmds(vscsi, vscsi->request_limit);
3370 dev_err(&vscsi->dev, "alloc_cmds failed, rc %d, num %d\n",
3371 rc, vscsi->request_limit);
3376 * Note: the lock is used in freeing timers, so must initialize
3377 * first so that ordering in case of error is correct.
3379 spin_lock_init(&vscsi->intr_lock);
3381 rc = ibmvscsis_alloctimer(vscsi);
3383 dev_err(&vscsi->dev, "probe: alloctimer failed, rc %d\n", rc);
3387 rc = ibmvscsis_create_command_q(vscsi, 256);
3389 dev_err(&vscsi->dev, "probe: create_command_q failed, rc %d\n",
3394 vscsi->map_buf = kzalloc(PAGE_SIZE, GFP_KERNEL);
3395 if (!vscsi->map_buf) {
3397 dev_err(&vscsi->dev, "probe: allocating cmd buffer failed\n");
3401 vscsi->map_ioba = dma_map_single(&vdev->dev, vscsi->map_buf, PAGE_SIZE,
3403 if (dma_mapping_error(&vdev->dev, vscsi->map_ioba)) {
3405 dev_err(&vscsi->dev, "probe: error mapping command buffer\n");
3409 hrc = h_vioctl(vscsi->dds.unit_id, H_GET_PARTNER_INFO,
3410 (u64)vscsi->map_ioba | ((u64)PAGE_SIZE << 32), 0, 0, 0,
3412 if (hrc == H_SUCCESS)
3413 vscsi->client_data.partition_number =
3414 be64_to_cpu(*(u64 *)vscsi->map_buf);
3416 * We expect the VIOCTL to fail if we're configured as "any
3417 * client can connect" and the client isn't activated yet.
3418 * We'll make the call again when he sends an init msg.
3420 pr_debug("probe hrc %ld, client partition num %d\n",
3421 hrc, vscsi->client_data.partition_number);
3423 tasklet_init(&vscsi->work_task, ibmvscsis_handle_crq,
3424 (unsigned long)vscsi);
3426 init_completion(&vscsi->wait_idle);
3427 init_completion(&vscsi->unconfig);
3429 snprintf(wq_name, 24, "ibmvscsis%s", dev_name(&vdev->dev));
3430 vscsi->work_q = create_workqueue(wq_name);
3431 if (!vscsi->work_q) {
3433 dev_err(&vscsi->dev, "create_workqueue failed\n");
3437 rc = request_irq(vdev->irq, ibmvscsis_interrupt, 0, "ibmvscsis", vscsi);
3440 dev_err(&vscsi->dev, "probe: request_irq failed, rc %d\n", rc);
3444 vscsi->state = WAIT_ENABLED;
3446 dev_set_drvdata(&vdev->dev, vscsi);
3451 destroy_workqueue(vscsi->work_q);
3453 dma_unmap_single(&vdev->dev, vscsi->map_ioba, PAGE_SIZE,
3456 kfree(vscsi->map_buf);
3458 tasklet_kill(&vscsi->work_task);
3459 ibmvscsis_unregister_command_q(vscsi);
3460 ibmvscsis_destroy_command_q(vscsi);
3462 ibmvscsis_freetimer(vscsi);
3464 ibmvscsis_free_cmds(vscsi);
3466 srp_target_free(&vscsi->target);
3468 spin_lock_bh(&ibmvscsis_dev_lock);
3469 list_del(&vscsi->list);
3470 spin_unlock_bh(&ibmvscsis_dev_lock);
3477 static int ibmvscsis_remove(struct vio_dev *vdev)
3479 struct scsi_info *vscsi = dev_get_drvdata(&vdev->dev);
3481 pr_debug("remove (%s)\n", dev_name(&vscsi->dma_dev->dev));
3483 spin_lock_bh(&vscsi->intr_lock);
3484 ibmvscsis_post_disconnect(vscsi, UNCONFIGURING, 0);
3485 vscsi->flags |= CFG_SLEEPING;
3486 spin_unlock_bh(&vscsi->intr_lock);
3487 wait_for_completion(&vscsi->unconfig);
3489 vio_disable_interrupts(vdev);
3490 free_irq(vdev->irq, vscsi);
3491 destroy_workqueue(vscsi->work_q);
3492 dma_unmap_single(&vdev->dev, vscsi->map_ioba, PAGE_SIZE,
3494 kfree(vscsi->map_buf);
3495 tasklet_kill(&vscsi->work_task);
3496 ibmvscsis_destroy_command_q(vscsi);
3497 ibmvscsis_freetimer(vscsi);
3498 ibmvscsis_free_cmds(vscsi);
3499 srp_target_free(&vscsi->target);
3500 spin_lock_bh(&ibmvscsis_dev_lock);
3501 list_del(&vscsi->list);
3502 spin_unlock_bh(&ibmvscsis_dev_lock);
3508 static ssize_t system_id_show(struct device *dev,
3509 struct device_attribute *attr, char *buf)
3511 return snprintf(buf, PAGE_SIZE, "%s\n", system_id);
3514 static ssize_t partition_number_show(struct device *dev,
3515 struct device_attribute *attr, char *buf)
3517 return snprintf(buf, PAGE_SIZE, "%x\n", partition_number);
3520 static ssize_t unit_address_show(struct device *dev,
3521 struct device_attribute *attr, char *buf)
3523 struct scsi_info *vscsi = container_of(dev, struct scsi_info, dev);
3525 return snprintf(buf, PAGE_SIZE, "%x\n", vscsi->dma_dev->unit_address);
3528 static int ibmvscsis_get_system_info(void)
3530 struct device_node *rootdn, *vdevdn;
3531 const char *id, *model, *name;
3534 rootdn = of_find_node_by_path("/");
3538 model = of_get_property(rootdn, "model", NULL);
3539 id = of_get_property(rootdn, "system-id", NULL);
3541 snprintf(system_id, sizeof(system_id), "%s-%s", model, id);
3543 name = of_get_property(rootdn, "ibm,partition-name", NULL);
3545 strncpy(partition_name, name, sizeof(partition_name));
3547 num = of_get_property(rootdn, "ibm,partition-no", NULL);
3549 partition_number = of_read_number(num, 1);
3551 of_node_put(rootdn);
3553 vdevdn = of_find_node_by_path("/vdevice");
3557 mvds = of_get_property(vdevdn, "ibm,max-virtual-dma-size",
3560 max_vdma_size = *mvds;
3561 of_node_put(vdevdn);
3567 static char *ibmvscsis_get_fabric_name(void)
3572 static char *ibmvscsis_get_fabric_wwn(struct se_portal_group *se_tpg)
3574 struct ibmvscsis_tport *tport =
3575 container_of(se_tpg, struct ibmvscsis_tport, se_tpg);
3577 return tport->tport_name;
3580 static u16 ibmvscsis_get_tag(struct se_portal_group *se_tpg)
3582 struct ibmvscsis_tport *tport =
3583 container_of(se_tpg, struct ibmvscsis_tport, se_tpg);
3585 return tport->tport_tpgt;
3588 static u32 ibmvscsis_get_default_depth(struct se_portal_group *se_tpg)
3593 static int ibmvscsis_check_true(struct se_portal_group *se_tpg)
3598 static int ibmvscsis_check_false(struct se_portal_group *se_tpg)
3603 static u32 ibmvscsis_tpg_get_inst_index(struct se_portal_group *se_tpg)
3608 static int ibmvscsis_check_stop_free(struct se_cmd *se_cmd)
3610 return target_put_sess_cmd(se_cmd);
3613 static void ibmvscsis_release_cmd(struct se_cmd *se_cmd)
3615 struct ibmvscsis_cmd *cmd = container_of(se_cmd, struct ibmvscsis_cmd,
3617 struct scsi_info *vscsi = cmd->adapter;
3619 spin_lock_bh(&vscsi->intr_lock);
3620 /* Remove from active_q */
3621 list_move_tail(&cmd->list, &vscsi->waiting_rsp);
3622 ibmvscsis_send_messages(vscsi);
3623 spin_unlock_bh(&vscsi->intr_lock);
3626 static u32 ibmvscsis_sess_get_index(struct se_session *se_sess)
3631 static int ibmvscsis_write_pending(struct se_cmd *se_cmd)
3633 struct ibmvscsis_cmd *cmd = container_of(se_cmd, struct ibmvscsis_cmd,
3635 struct scsi_info *vscsi = cmd->adapter;
3636 struct iu_entry *iue = cmd->iue;
3640 * If CLIENT_FAILED OR RESPONSE_Q_DOWN, then just return success
3641 * since LIO can't do anything about it, and we dont want to
3642 * attempt an srp_transfer_data.
3644 if ((vscsi->flags & (CLIENT_FAILED | RESPONSE_Q_DOWN))) {
3645 pr_err("write_pending failed since: %d\n", vscsi->flags);
3649 rc = srp_transfer_data(cmd, &vio_iu(iue)->srp.cmd, ibmvscsis_rdma,
3652 pr_err("srp_transfer_data() failed: %d\n", rc);
3656 * We now tell TCM to add this WRITE CDB directly into the TCM storage
3657 * object execution queue.
3659 target_execute_cmd(se_cmd);
3663 static int ibmvscsis_write_pending_status(struct se_cmd *se_cmd)
3668 static void ibmvscsis_set_default_node_attrs(struct se_node_acl *nacl)
3672 static int ibmvscsis_get_cmd_state(struct se_cmd *se_cmd)
3677 static int ibmvscsis_queue_data_in(struct se_cmd *se_cmd)
3679 struct ibmvscsis_cmd *cmd = container_of(se_cmd, struct ibmvscsis_cmd,
3681 struct iu_entry *iue = cmd->iue;
3682 struct scsi_info *vscsi = cmd->adapter;
3687 rc = srp_transfer_data(cmd, &vio_iu(iue)->srp.cmd, ibmvscsis_rdma, 1,
3690 pr_err("srp_transfer_data failed: %d\n", rc);
3691 sd = se_cmd->sense_buffer;
3692 se_cmd->scsi_sense_length = 18;
3693 memset(se_cmd->sense_buffer, 0, se_cmd->scsi_sense_length);
3694 /* Logical Unit Communication Time-out asc/ascq = 0x0801 */
3695 scsi_build_sense_buffer(0, se_cmd->sense_buffer, MEDIUM_ERROR,
3699 srp_build_response(vscsi, cmd, &len);
3700 cmd->rsp.format = SRP_FORMAT;
3706 static int ibmvscsis_queue_status(struct se_cmd *se_cmd)
3708 struct ibmvscsis_cmd *cmd = container_of(se_cmd, struct ibmvscsis_cmd,
3710 struct scsi_info *vscsi = cmd->adapter;
3713 pr_debug("queue_status %p\n", se_cmd);
3715 srp_build_response(vscsi, cmd, &len);
3716 cmd->rsp.format = SRP_FORMAT;
3722 static void ibmvscsis_queue_tm_rsp(struct se_cmd *se_cmd)
3724 struct ibmvscsis_cmd *cmd = container_of(se_cmd, struct ibmvscsis_cmd,
3726 struct scsi_info *vscsi = cmd->adapter;
3727 struct ibmvscsis_cmd *cmd_itr;
3728 struct iu_entry *iue = iue = cmd->iue;
3729 struct srp_tsk_mgmt *srp_tsk = &vio_iu(iue)->srp.tsk_mgmt;
3730 u64 tag_to_abort = be64_to_cpu(srp_tsk->task_tag);
3733 pr_debug("queue_tm_rsp %p, status %d\n",
3734 se_cmd, (int)se_cmd->se_tmr_req->response);
3736 if (srp_tsk->tsk_mgmt_func == SRP_TSK_ABORT_TASK &&
3737 cmd->se_cmd.se_tmr_req->response == TMR_TASK_DOES_NOT_EXIST) {
3738 spin_lock_bh(&vscsi->intr_lock);
3739 list_for_each_entry(cmd_itr, &vscsi->active_q, list) {
3740 if (tag_to_abort == cmd_itr->se_cmd.tag) {
3741 cmd_itr->abort_cmd = cmd;
3742 cmd->flags |= DELAY_SEND;
3746 spin_unlock_bh(&vscsi->intr_lock);
3749 srp_build_response(vscsi, cmd, &len);
3750 cmd->rsp.format = SRP_FORMAT;
3754 static void ibmvscsis_aborted_task(struct se_cmd *se_cmd)
3756 pr_debug("ibmvscsis_aborted_task %p task_tag: %llu\n",
3757 se_cmd, se_cmd->tag);
3760 static struct se_wwn *ibmvscsis_make_tport(struct target_fabric_configfs *tf,
3761 struct config_group *group,
3764 struct ibmvscsis_tport *tport;
3766 tport = ibmvscsis_lookup_port(name);
3768 tport->tport_proto_id = SCSI_PROTOCOL_SRP;
3769 pr_debug("make_tport(%s), pointer:%p, tport_id:%x\n",
3770 name, tport, tport->tport_proto_id);
3771 return &tport->tport_wwn;
3774 return ERR_PTR(-EINVAL);
3777 static void ibmvscsis_drop_tport(struct se_wwn *wwn)
3779 struct ibmvscsis_tport *tport = container_of(wwn,
3780 struct ibmvscsis_tport,
3783 pr_debug("drop_tport(%s)\n",
3784 config_item_name(&tport->tport_wwn.wwn_group.cg_item));
3787 static struct se_portal_group *ibmvscsis_make_tpg(struct se_wwn *wwn,
3788 struct config_group *group,
3791 struct ibmvscsis_tport *tport =
3792 container_of(wwn, struct ibmvscsis_tport, tport_wwn);
3795 tport->releasing = false;
3797 rc = core_tpg_register(&tport->tport_wwn, &tport->se_tpg,
3798 tport->tport_proto_id);
3802 return &tport->se_tpg;
3805 static void ibmvscsis_drop_tpg(struct se_portal_group *se_tpg)
3807 struct ibmvscsis_tport *tport = container_of(se_tpg,
3808 struct ibmvscsis_tport,
3811 tport->releasing = true;
3812 tport->enabled = false;
3815 * Release the virtual I_T Nexus for this ibmvscsis TPG
3817 ibmvscsis_drop_nexus(tport);
3819 * Deregister the se_tpg from TCM..
3821 core_tpg_deregister(se_tpg);
3824 static ssize_t ibmvscsis_wwn_version_show(struct config_item *item,
3827 return scnprintf(page, PAGE_SIZE, "%s\n", IBMVSCSIS_VERSION);
3829 CONFIGFS_ATTR_RO(ibmvscsis_wwn_, version);
3831 static struct configfs_attribute *ibmvscsis_wwn_attrs[] = {
3832 &ibmvscsis_wwn_attr_version,
3836 static ssize_t ibmvscsis_tpg_enable_show(struct config_item *item,
3839 struct se_portal_group *se_tpg = to_tpg(item);
3840 struct ibmvscsis_tport *tport = container_of(se_tpg,
3841 struct ibmvscsis_tport,
3844 return snprintf(page, PAGE_SIZE, "%d\n", (tport->enabled) ? 1 : 0);
3847 static ssize_t ibmvscsis_tpg_enable_store(struct config_item *item,
3848 const char *page, size_t count)
3850 struct se_portal_group *se_tpg = to_tpg(item);
3851 struct ibmvscsis_tport *tport = container_of(se_tpg,
3852 struct ibmvscsis_tport,
3854 struct scsi_info *vscsi = container_of(tport, struct scsi_info, tport);
3859 rc = kstrtoul(page, 0, &tmp);
3861 pr_err("Unable to extract srpt_tpg_store_enable\n");
3865 if ((tmp != 0) && (tmp != 1)) {
3866 pr_err("Illegal value for srpt_tpg_store_enable\n");
3871 spin_lock_bh(&vscsi->intr_lock);
3872 tport->enabled = true;
3873 lrc = ibmvscsis_enable_change_state(vscsi);
3875 pr_err("enable_change_state failed, rc %ld state %d\n",
3877 spin_unlock_bh(&vscsi->intr_lock);
3879 spin_lock_bh(&vscsi->intr_lock);
3880 tport->enabled = false;
3881 /* This simulates the server going down */
3882 ibmvscsis_post_disconnect(vscsi, ERR_DISCONNECT, 0);
3883 spin_unlock_bh(&vscsi->intr_lock);
3886 pr_debug("tpg_enable_store, tmp %ld, state %d\n", tmp, vscsi->state);
3890 CONFIGFS_ATTR(ibmvscsis_tpg_, enable);
3892 static struct configfs_attribute *ibmvscsis_tpg_attrs[] = {
3893 &ibmvscsis_tpg_attr_enable,
3897 static const struct target_core_fabric_ops ibmvscsis_ops = {
3898 .module = THIS_MODULE,
3899 .name = "ibmvscsis",
3900 .max_data_sg_nents = MAX_TXU / PAGE_SIZE,
3901 .get_fabric_name = ibmvscsis_get_fabric_name,
3902 .tpg_get_wwn = ibmvscsis_get_fabric_wwn,
3903 .tpg_get_tag = ibmvscsis_get_tag,
3904 .tpg_get_default_depth = ibmvscsis_get_default_depth,
3905 .tpg_check_demo_mode = ibmvscsis_check_true,
3906 .tpg_check_demo_mode_cache = ibmvscsis_check_true,
3907 .tpg_check_demo_mode_write_protect = ibmvscsis_check_false,
3908 .tpg_check_prod_mode_write_protect = ibmvscsis_check_false,
3909 .tpg_get_inst_index = ibmvscsis_tpg_get_inst_index,
3910 .check_stop_free = ibmvscsis_check_stop_free,
3911 .release_cmd = ibmvscsis_release_cmd,
3912 .sess_get_index = ibmvscsis_sess_get_index,
3913 .write_pending = ibmvscsis_write_pending,
3914 .write_pending_status = ibmvscsis_write_pending_status,
3915 .set_default_node_attributes = ibmvscsis_set_default_node_attrs,
3916 .get_cmd_state = ibmvscsis_get_cmd_state,
3917 .queue_data_in = ibmvscsis_queue_data_in,
3918 .queue_status = ibmvscsis_queue_status,
3919 .queue_tm_rsp = ibmvscsis_queue_tm_rsp,
3920 .aborted_task = ibmvscsis_aborted_task,
3922 * Setup function pointers for logic in target_core_fabric_configfs.c
3924 .fabric_make_wwn = ibmvscsis_make_tport,
3925 .fabric_drop_wwn = ibmvscsis_drop_tport,
3926 .fabric_make_tpg = ibmvscsis_make_tpg,
3927 .fabric_drop_tpg = ibmvscsis_drop_tpg,
3929 .tfc_wwn_attrs = ibmvscsis_wwn_attrs,
3930 .tfc_tpg_base_attrs = ibmvscsis_tpg_attrs,
3933 static void ibmvscsis_dev_release(struct device *dev) {};
3935 static struct class_attribute ibmvscsis_class_attrs[] = {
3939 static struct device_attribute dev_attr_system_id =
3940 __ATTR(system_id, S_IRUGO, system_id_show, NULL);
3942 static struct device_attribute dev_attr_partition_number =
3943 __ATTR(partition_number, S_IRUGO, partition_number_show, NULL);
3945 static struct device_attribute dev_attr_unit_address =
3946 __ATTR(unit_address, S_IRUGO, unit_address_show, NULL);
3948 static struct attribute *ibmvscsis_dev_attrs[] = {
3949 &dev_attr_system_id.attr,
3950 &dev_attr_partition_number.attr,
3951 &dev_attr_unit_address.attr,
3953 ATTRIBUTE_GROUPS(ibmvscsis_dev);
3955 static struct class ibmvscsis_class = {
3956 .name = "ibmvscsis",
3957 .dev_release = ibmvscsis_dev_release,
3958 .class_attrs = ibmvscsis_class_attrs,
3959 .dev_groups = ibmvscsis_dev_groups,
3962 static struct vio_device_id ibmvscsis_device_table[] = {
3963 { "v-scsi-host", "IBM,v-scsi-host" },
3966 MODULE_DEVICE_TABLE(vio, ibmvscsis_device_table);
3968 static struct vio_driver ibmvscsis_driver = {
3969 .name = "ibmvscsis",
3970 .id_table = ibmvscsis_device_table,
3971 .probe = ibmvscsis_probe,
3972 .remove = ibmvscsis_remove,
3976 * ibmvscsis_init() - Kernel Module initialization
3978 * Note: vio_register_driver() registers callback functions, and at least one
3979 * of those callback functions calls TCM - Linux IO Target Subsystem, thus
3980 * the SCSI Target template must be registered before vio_register_driver()
3983 static int __init ibmvscsis_init(void)
3987 rc = ibmvscsis_get_system_info();
3989 pr_err("rc %d from get_system_info\n", rc);
3993 rc = class_register(&ibmvscsis_class);
3995 pr_err("failed class register\n");
3999 rc = target_register_template(&ibmvscsis_ops);
4001 pr_err("rc %d from target_register_template\n", rc);
4002 goto unregister_class;
4005 rc = vio_register_driver(&ibmvscsis_driver);
4007 pr_err("rc %d from vio_register_driver\n", rc);
4008 goto unregister_target;
4014 target_unregister_template(&ibmvscsis_ops);
4016 class_unregister(&ibmvscsis_class);
4021 static void __exit ibmvscsis_exit(void)
4023 pr_info("Unregister IBM virtual SCSI host driver\n");
4024 vio_unregister_driver(&ibmvscsis_driver);
4025 target_unregister_template(&ibmvscsis_ops);
4026 class_unregister(&ibmvscsis_class);
4029 MODULE_DESCRIPTION("IBMVSCSIS fabric driver");
4030 MODULE_AUTHOR("Bryant G. Ly and Michael Cyr");
4031 MODULE_LICENSE("GPL");
4032 MODULE_VERSION(IBMVSCSIS_VERSION);
4033 module_init(ibmvscsis_init);
4034 module_exit(ibmvscsis_exit);