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>
33 #include <linux/delay.h>
35 #include <target/target_core_base.h>
36 #include <target/target_core_fabric.h>
38 #include <asm/hvcall.h>
41 #include <scsi/viosrp.h>
43 #include "ibmvscsi_tgt.h"
45 #define IBMVSCSIS_VERSION "v0.2"
47 #define INITIAL_SRP_LIMIT 800
48 #define DEFAULT_MAX_SECTORS 256
49 #define MAX_TXU 1024 * 1024
51 static uint max_vdma_size = MAX_H_COPY_RDMA;
53 static char system_id[SYS_ID_NAME_LEN] = "";
54 static char partition_name[PARTITION_NAMELEN] = "UNKNOWN";
55 static uint partition_number = -1;
57 /* Adapter list and lock to control it */
58 static DEFINE_SPINLOCK(ibmvscsis_dev_lock);
59 static LIST_HEAD(ibmvscsis_dev_list);
61 static long ibmvscsis_parse_command(struct scsi_info *vscsi,
62 struct viosrp_crq *crq);
64 static void ibmvscsis_adapter_idle(struct scsi_info *vscsi);
66 static void ibmvscsis_determine_resid(struct se_cmd *se_cmd,
69 u32 residual_count = se_cmd->residual_count;
74 if (se_cmd->se_cmd_flags & SCF_UNDERFLOW_BIT) {
75 if (se_cmd->data_direction == DMA_TO_DEVICE) {
76 /* residual data from an underflow write */
77 rsp->flags = SRP_RSP_FLAG_DOUNDER;
78 rsp->data_out_res_cnt = cpu_to_be32(residual_count);
79 } else if (se_cmd->data_direction == DMA_FROM_DEVICE) {
80 /* residual data from an underflow read */
81 rsp->flags = SRP_RSP_FLAG_DIUNDER;
82 rsp->data_in_res_cnt = cpu_to_be32(residual_count);
84 } else if (se_cmd->se_cmd_flags & SCF_OVERFLOW_BIT) {
85 if (se_cmd->data_direction == DMA_TO_DEVICE) {
86 /* residual data from an overflow write */
87 rsp->flags = SRP_RSP_FLAG_DOOVER;
88 rsp->data_out_res_cnt = cpu_to_be32(residual_count);
89 } else if (se_cmd->data_direction == DMA_FROM_DEVICE) {
90 /* residual data from an overflow read */
91 rsp->flags = SRP_RSP_FLAG_DIOVER;
92 rsp->data_in_res_cnt = cpu_to_be32(residual_count);
98 * connection_broken() - Determine if the connection to the client is good
99 * @vscsi: Pointer to our adapter structure
101 * This function attempts to send a ping MAD to the client. If the call to
102 * queue the request returns H_CLOSED then the connection has been broken
103 * and the function returns TRUE.
105 * EXECUTION ENVIRONMENT:
106 * Interrupt or Process environment
108 static bool connection_broken(struct scsi_info *vscsi)
110 struct viosrp_crq *crq;
111 u64 buffer[2] = { 0, 0 };
115 /* create a PING crq */
116 crq = (struct viosrp_crq *)&buffer;
117 crq->valid = VALID_CMD_RESP_EL;
118 crq->format = MESSAGE_IN_CRQ;
121 h_return_code = h_send_crq(vscsi->dds.unit_id,
122 cpu_to_be64(buffer[MSG_HI]),
123 cpu_to_be64(buffer[MSG_LOW]));
125 pr_debug("connection_broken: rc %ld\n", h_return_code);
127 if (h_return_code == H_CLOSED)
134 * ibmvscsis_unregister_command_q() - Helper Function-Unregister Command Queue
135 * @vscsi: Pointer to our adapter structure
137 * This function calls h_free_q then frees the interrupt bit etc.
138 * It must release the lock before doing so because of the time it can take
139 * for h_free_crq in PHYP
140 * NOTE: the caller must make sure that state and or flags will prevent
141 * interrupt handler from scheduling work.
142 * NOTE: anyone calling this function may need to set the CRQ_CLOSED flag
143 * we can't do it here, because we don't have the lock
145 * EXECUTION ENVIRONMENT:
148 static long ibmvscsis_unregister_command_q(struct scsi_info *vscsi)
151 long rc = ADAPT_SUCCESS;
155 qrc = h_free_crq(vscsi->dds.unit_id);
162 dev_err(&vscsi->dev, "unregister_command_q: error from h_free_crq %ld\n",
168 case H_LONG_BUSY_ORDER_1_MSEC:
169 /* msleep not good for small values */
170 usleep_range(1000, 2000);
173 case H_LONG_BUSY_ORDER_10_MSEC:
174 usleep_range(10000, 20000);
177 case H_LONG_BUSY_ORDER_100_MSEC:
181 case H_LONG_BUSY_ORDER_1_SEC:
185 case H_LONG_BUSY_ORDER_10_SEC:
189 case H_LONG_BUSY_ORDER_100_SEC:
194 dev_err(&vscsi->dev, "unregister_command_q: unknown error %ld from h_free_crq\n",
201 * dont wait more then 300 seconds
202 * ticks are in milliseconds more or less
204 if (ticks > 300000 && qrc != H_SUCCESS) {
206 dev_err(&vscsi->dev, "Excessive wait for h_free_crq\n");
208 } while (qrc != H_SUCCESS && rc == ADAPT_SUCCESS);
210 pr_debug("Freeing CRQ: phyp rc %ld, rc %ld\n", qrc, rc);
216 * ibmvscsis_delete_client_info() - Helper function to Delete Client Info
217 * @vscsi: Pointer to our adapter structure
218 * @client_closed: True if client closed its queue
220 * Deletes information specific to the client when the client goes away
222 * EXECUTION ENVIRONMENT:
223 * Interrupt or Process
225 static void ibmvscsis_delete_client_info(struct scsi_info *vscsi,
228 vscsi->client_cap = 0;
231 * Some things we don't want to clear if we're closing the queue,
232 * because some clients don't resend the host handshake when they
233 * get a transport event.
236 vscsi->client_data.os_type = 0;
240 * ibmvscsis_free_command_q() - Free Command Queue
241 * @vscsi: Pointer to our adapter structure
243 * This function calls unregister_command_q, then clears interrupts and
244 * any pending interrupt acknowledgments associated with the command q.
245 * It also clears memory if there is no error.
247 * PHYP did not meet the PAPR architecture so that we must give up the
248 * lock. This causes a timing hole regarding state change. To close the
249 * hole this routine does accounting on any change that occurred during
250 * the time the lock is not held.
251 * NOTE: must give up and then acquire the interrupt lock, the caller must
252 * make sure that state and or flags will prevent interrupt handler from
255 * EXECUTION ENVIRONMENT:
256 * Process level, interrupt lock is held
258 static long ibmvscsis_free_command_q(struct scsi_info *vscsi)
261 u32 flags_under_lock;
262 u16 state_under_lock;
263 long rc = ADAPT_SUCCESS;
265 if (!(vscsi->flags & CRQ_CLOSED)) {
266 vio_disable_interrupts(vscsi->dma_dev);
268 state_under_lock = vscsi->new_state;
269 flags_under_lock = vscsi->flags;
270 vscsi->phyp_acr_state = 0;
271 vscsi->phyp_acr_flags = 0;
273 spin_unlock_bh(&vscsi->intr_lock);
274 rc = ibmvscsis_unregister_command_q(vscsi);
275 spin_lock_bh(&vscsi->intr_lock);
277 if (state_under_lock != vscsi->new_state)
278 vscsi->phyp_acr_state = vscsi->new_state;
280 vscsi->phyp_acr_flags = ((~flags_under_lock) & vscsi->flags);
282 if (rc == ADAPT_SUCCESS) {
283 bytes = vscsi->cmd_q.size * PAGE_SIZE;
284 memset(vscsi->cmd_q.base_addr, 0, bytes);
285 vscsi->cmd_q.index = 0;
286 vscsi->flags |= CRQ_CLOSED;
288 ibmvscsis_delete_client_info(vscsi, false);
291 pr_debug("free_command_q: flags 0x%x, state 0x%hx, acr_flags 0x%x, acr_state 0x%hx\n",
292 vscsi->flags, vscsi->state, vscsi->phyp_acr_flags,
293 vscsi->phyp_acr_state);
299 * ibmvscsis_cmd_q_dequeue() - Get valid Command element
300 * @mask: Mask to use in case index wraps
301 * @current_index: Current index into command queue
302 * @base_addr: Pointer to start of command queue
304 * Returns a pointer to a valid command element or NULL, if the command
307 * EXECUTION ENVIRONMENT:
308 * Interrupt environment, interrupt lock held
310 static struct viosrp_crq *ibmvscsis_cmd_q_dequeue(uint mask,
312 struct viosrp_crq *base_addr)
314 struct viosrp_crq *ptr;
316 ptr = base_addr + *current_index;
319 *current_index = (*current_index + 1) & mask;
329 * ibmvscsis_send_init_message() - send initialize message to the client
330 * @vscsi: Pointer to our adapter structure
331 * @format: Which Init Message format to send
333 * EXECUTION ENVIRONMENT:
334 * Interrupt environment interrupt lock held
336 static long ibmvscsis_send_init_message(struct scsi_info *vscsi, u8 format)
338 struct viosrp_crq *crq;
339 u64 buffer[2] = { 0, 0 };
342 crq = (struct viosrp_crq *)&buffer;
343 crq->valid = VALID_INIT_MSG;
344 crq->format = format;
345 rc = h_send_crq(vscsi->dds.unit_id, cpu_to_be64(buffer[MSG_HI]),
346 cpu_to_be64(buffer[MSG_LOW]));
352 * ibmvscsis_check_init_msg() - Check init message valid
353 * @vscsi: Pointer to our adapter structure
354 * @format: Pointer to return format of Init Message, if any.
355 * Set to UNUSED_FORMAT if no Init Message in queue.
357 * Checks if an initialize message was queued by the initiatior
358 * after the queue was created and before the interrupt was enabled.
360 * EXECUTION ENVIRONMENT:
361 * Process level only, interrupt lock held
363 static long ibmvscsis_check_init_msg(struct scsi_info *vscsi, uint *format)
365 struct viosrp_crq *crq;
366 long rc = ADAPT_SUCCESS;
368 crq = ibmvscsis_cmd_q_dequeue(vscsi->cmd_q.mask, &vscsi->cmd_q.index,
369 vscsi->cmd_q.base_addr);
371 *format = (uint)UNUSED_FORMAT;
372 } else if (crq->valid == VALID_INIT_MSG && crq->format == INIT_MSG) {
373 *format = (uint)INIT_MSG;
374 crq->valid = INVALIDATE_CMD_RESP_EL;
378 * the caller has ensured no initialize message was
379 * sent after the queue was
380 * created so there should be no other message on the queue.
382 crq = ibmvscsis_cmd_q_dequeue(vscsi->cmd_q.mask,
384 vscsi->cmd_q.base_addr);
386 *format = (uint)(crq->format);
388 crq->valid = INVALIDATE_CMD_RESP_EL;
392 *format = (uint)(crq->format);
394 crq->valid = INVALIDATE_CMD_RESP_EL;
402 * ibmvscsis_disconnect() - Helper function to disconnect
403 * @work: Pointer to work_struct, gives access to our adapter structure
405 * An error has occurred or the driver received a Transport event,
406 * and the driver is requesting that the command queue be de-registered
407 * in a safe manner. If there is no outstanding I/O then we can stop the
408 * queue. If we are restarting the queue it will be reflected in the
409 * the state of the adapter.
411 * EXECUTION ENVIRONMENT:
412 * Process environment
414 static void ibmvscsis_disconnect(struct work_struct *work)
416 struct scsi_info *vscsi = container_of(work, struct scsi_info,
419 bool wait_idle = false;
421 spin_lock_bh(&vscsi->intr_lock);
422 new_state = vscsi->new_state;
423 vscsi->new_state = 0;
425 pr_debug("disconnect: flags 0x%x, state 0x%hx\n", vscsi->flags,
429 * check which state we are in and see if we
430 * should transitition to the new state
432 switch (vscsi->state) {
433 /* Should never be called while in this state. */
436 * Can never transition from this state;
437 * igonore errors and logout.
442 /* can transition from this state to UNCONFIGURING */
444 if (new_state == UNCONFIGURING)
445 vscsi->state = new_state;
449 * Can transition from this state to to unconfiguring
452 case ERR_DISCONNECT_RECONNECT:
456 vscsi->state = new_state;
466 /* can transition from this state to UNCONFIGURING */
467 case ERR_DISCONNECTED:
468 if (new_state == UNCONFIGURING)
469 vscsi->state = new_state;
475 vscsi->state = new_state;
476 vscsi->flags |= RESPONSE_Q_DOWN;
477 vscsi->flags &= ~(SCHEDULE_DISCONNECT |
478 DISCONNECT_SCHEDULED);
480 if (vscsi->flags & CFG_SLEEPING) {
481 vscsi->flags &= ~CFG_SLEEPING;
482 complete(&vscsi->unconfig);
486 /* should never happen */
488 case ERR_DISCONNECT_RECONNECT:
490 dev_err(&vscsi->dev, "disconnect: invalid state %d for WAIT_IDLE\n",
499 vscsi->flags |= RESPONSE_Q_DOWN;
500 vscsi->state = new_state;
501 vscsi->flags &= ~(SCHEDULE_DISCONNECT |
502 DISCONNECT_SCHEDULED);
503 ibmvscsis_free_command_q(vscsi);
506 case ERR_DISCONNECT_RECONNECT:
507 vscsi->state = new_state;
513 * Initiator has not done a successful srp login
514 * or has done a successful srp logout ( adapter was not
515 * busy). In the first case there can be responses queued
516 * waiting for space on the initiators response queue (MAD)
517 * The second case the adapter is idle. Assume the worse case,
518 * i.e. the second case.
520 case WAIT_CONNECTION:
524 vscsi->state = new_state;
527 /* can transition from this state to UNCONFIGURING */
529 if (new_state == UNCONFIGURING)
530 vscsi->state = new_state;
537 pr_debug("disconnect start wait, active %d, sched %d\n",
538 (int)list_empty(&vscsi->active_q),
539 (int)list_empty(&vscsi->schedule_q));
540 if (!list_empty(&vscsi->active_q) ||
541 !list_empty(&vscsi->schedule_q)) {
542 vscsi->flags |= WAIT_FOR_IDLE;
543 pr_debug("disconnect flags 0x%x\n", vscsi->flags);
545 * This routine is can not be called with the interrupt
548 spin_unlock_bh(&vscsi->intr_lock);
549 wait_for_completion(&vscsi->wait_idle);
550 spin_lock_bh(&vscsi->intr_lock);
552 pr_debug("disconnect stop wait\n");
554 ibmvscsis_adapter_idle(vscsi);
557 spin_unlock_bh(&vscsi->intr_lock);
561 * ibmvscsis_post_disconnect() - Schedule the disconnect
562 * @vscsi: Pointer to our adapter structure
563 * @new_state: State to move to after disconnecting
564 * @flag_bits: Flags to turn on in adapter structure
566 * If it's already been scheduled, then see if we need to "upgrade"
567 * the new state (if the one passed in is more "severe" than the
571 * interrupt lock is held
573 static void ibmvscsis_post_disconnect(struct scsi_info *vscsi, uint new_state,
578 /* check the validity of the new state */
582 case ERR_DISCONNECT_RECONNECT:
587 dev_err(&vscsi->dev, "post_disconnect: Invalid new state %d\n",
592 vscsi->flags |= flag_bits;
594 pr_debug("post_disconnect: new_state 0x%x, flag_bits 0x%x, vscsi->flags 0x%x, state %hx\n",
595 new_state, flag_bits, vscsi->flags, vscsi->state);
597 if (!(vscsi->flags & (DISCONNECT_SCHEDULED | SCHEDULE_DISCONNECT))) {
598 vscsi->flags |= SCHEDULE_DISCONNECT;
599 vscsi->new_state = new_state;
601 INIT_WORK(&vscsi->proc_work, ibmvscsis_disconnect);
602 (void)queue_work(vscsi->work_q, &vscsi->proc_work);
604 if (vscsi->new_state)
605 state = vscsi->new_state;
607 state = vscsi->state;
614 case ERR_DISCONNECTED:
617 if (new_state == UNCONFIGURING)
618 vscsi->new_state = new_state;
621 case ERR_DISCONNECT_RECONNECT:
625 vscsi->new_state = new_state;
634 case WAIT_CONNECTION:
637 vscsi->new_state = new_state;
645 pr_debug("Leaving post_disconnect: flags 0x%x, new_state 0x%x\n",
646 vscsi->flags, vscsi->new_state);
650 * ibmvscsis_handle_init_compl_msg() - Respond to an Init Complete Message
651 * @vscsi: Pointer to our adapter structure
653 * Must be called with interrupt lock held.
655 static long ibmvscsis_handle_init_compl_msg(struct scsi_info *vscsi)
657 long rc = ADAPT_SUCCESS;
659 switch (vscsi->state) {
662 case ERR_DISCONNECT_RECONNECT:
663 case ERR_DISCONNECTED:
669 case WAIT_CONNECTION:
670 vscsi->state = CONNECTED;
679 dev_err(&vscsi->dev, "init_msg: invalid state %d to get init compl msg\n",
681 ibmvscsis_post_disconnect(vscsi, ERR_DISCONNECT_RECONNECT, 0);
689 * ibmvscsis_handle_init_msg() - Respond to an Init Message
690 * @vscsi: Pointer to our adapter structure
692 * Must be called with interrupt lock held.
694 static long ibmvscsis_handle_init_msg(struct scsi_info *vscsi)
696 long rc = ADAPT_SUCCESS;
698 switch (vscsi->state) {
699 case WAIT_CONNECTION:
700 rc = ibmvscsis_send_init_message(vscsi, INIT_COMPLETE_MSG);
703 vscsi->state = CONNECTED;
707 dev_err(&vscsi->dev, "init_msg: failed to send, rc %ld\n",
709 ibmvscsis_post_disconnect(vscsi, ERR_DISCONNECT, 0);
713 dev_err(&vscsi->dev, "init_msg: failed to send, rc %ld\n",
716 ibmvscsis_post_disconnect(vscsi,
717 ERR_DISCONNECT_RECONNECT, 0);
721 pr_warn("init_msg: failed to send, rc %ld\n", rc);
740 case ERR_DISCONNECT_RECONNECT:
741 case ERR_DISCONNECTED:
744 dev_err(&vscsi->dev, "init_msg: invalid state %d to get init msg\n",
746 ibmvscsis_post_disconnect(vscsi, ERR_DISCONNECT_RECONNECT, 0);
754 * ibmvscsis_init_msg() - Respond to an init message
755 * @vscsi: Pointer to our adapter structure
756 * @crq: Pointer to CRQ element containing the Init Message
758 * EXECUTION ENVIRONMENT:
759 * Interrupt, interrupt lock held
761 static long ibmvscsis_init_msg(struct scsi_info *vscsi, struct viosrp_crq *crq)
763 long rc = ADAPT_SUCCESS;
765 pr_debug("init_msg: state 0x%hx\n", vscsi->state);
767 rc = h_vioctl(vscsi->dds.unit_id, H_GET_PARTNER_INFO,
768 (u64)vscsi->map_ioba | ((u64)PAGE_SIZE << 32), 0, 0, 0,
770 if (rc == H_SUCCESS) {
771 vscsi->client_data.partition_number =
772 be64_to_cpu(*(u64 *)vscsi->map_buf);
773 pr_debug("init_msg, part num %d\n",
774 vscsi->client_data.partition_number);
776 pr_debug("init_msg h_vioctl rc %ld\n", rc);
780 if (crq->format == INIT_MSG) {
781 rc = ibmvscsis_handle_init_msg(vscsi);
782 } else if (crq->format == INIT_COMPLETE_MSG) {
783 rc = ibmvscsis_handle_init_compl_msg(vscsi);
786 dev_err(&vscsi->dev, "init_msg: invalid format %d\n",
788 ibmvscsis_post_disconnect(vscsi, ERR_DISCONNECT_RECONNECT, 0);
795 * ibmvscsis_establish_new_q() - Establish new CRQ queue
796 * @vscsi: Pointer to our adapter structure
798 * Must be called with interrupt lock held.
800 static long ibmvscsis_establish_new_q(struct scsi_info *vscsi)
802 long rc = ADAPT_SUCCESS;
805 vscsi->flags &= PRESERVE_FLAG_FIELDS;
806 vscsi->rsp_q_timer.timer_pops = 0;
810 rc = vio_enable_interrupts(vscsi->dma_dev);
812 pr_warn("establish_new_q: failed to enable interrupts, rc %ld\n",
817 rc = ibmvscsis_check_init_msg(vscsi, &format);
819 dev_err(&vscsi->dev, "establish_new_q: check_init_msg failed, rc %ld\n",
824 if (format == UNUSED_FORMAT) {
825 rc = ibmvscsis_send_init_message(vscsi, INIT_MSG);
838 vscsi->state = UNDEFINED;
842 } else if (format == INIT_MSG) {
843 rc = ibmvscsis_handle_init_msg(vscsi);
850 * ibmvscsis_reset_queue() - Reset CRQ Queue
851 * @vscsi: Pointer to our adapter structure
853 * This function calls h_free_q and then calls h_reg_q and does all
854 * of the bookkeeping to get us back to where we can communicate.
856 * Actually, we don't always call h_free_crq. A problem was discovered
857 * where one partition would close and reopen his queue, which would
858 * cause his partner to get a transport event, which would cause him to
859 * close and reopen his queue, which would cause the original partition
860 * to get a transport event, etc., etc. To prevent this, we don't
861 * actually close our queue if the client initiated the reset, (i.e.
862 * either we got a transport event or we have detected that the client's
865 * EXECUTION ENVIRONMENT:
866 * Process environment, called with interrupt lock held
868 static void ibmvscsis_reset_queue(struct scsi_info *vscsi)
871 long rc = ADAPT_SUCCESS;
873 pr_debug("reset_queue: flags 0x%x\n", vscsi->flags);
875 /* don't reset, the client did it for us */
876 if (vscsi->flags & (CLIENT_FAILED | TRANS_EVENT)) {
877 vscsi->flags &= PRESERVE_FLAG_FIELDS;
878 vscsi->rsp_q_timer.timer_pops = 0;
881 vscsi->state = WAIT_CONNECTION;
882 vio_enable_interrupts(vscsi->dma_dev);
884 rc = ibmvscsis_free_command_q(vscsi);
885 if (rc == ADAPT_SUCCESS) {
886 vscsi->state = WAIT_CONNECTION;
888 bytes = vscsi->cmd_q.size * PAGE_SIZE;
889 rc = h_reg_crq(vscsi->dds.unit_id,
890 vscsi->cmd_q.crq_token, bytes);
891 if (rc == H_CLOSED || rc == H_SUCCESS) {
892 rc = ibmvscsis_establish_new_q(vscsi);
895 if (rc != ADAPT_SUCCESS) {
896 pr_debug("reset_queue: reg_crq rc %ld\n", rc);
898 vscsi->state = ERR_DISCONNECTED;
899 vscsi->flags |= RESPONSE_Q_DOWN;
900 ibmvscsis_free_command_q(vscsi);
903 vscsi->state = ERR_DISCONNECTED;
904 vscsi->flags |= RESPONSE_Q_DOWN;
910 * ibmvscsis_free_cmd_resources() - Free command resources
911 * @vscsi: Pointer to our adapter structure
912 * @cmd: Command which is not longer in use
914 * Must be called with interrupt lock held.
916 static void ibmvscsis_free_cmd_resources(struct scsi_info *vscsi,
917 struct ibmvscsis_cmd *cmd)
919 struct iu_entry *iue = cmd->iue;
922 case TASK_MANAGEMENT:
925 * When the queue goes down this value is cleared, so it
926 * cannot be cleared in this general purpose function.
932 vscsi->flags &= ~PROCESSING_MAD;
937 dev_err(&vscsi->dev, "free_cmd_resources unknown type %d\n",
943 list_add_tail(&cmd->list, &vscsi->free_cmd);
946 if (list_empty(&vscsi->active_q) && list_empty(&vscsi->schedule_q) &&
947 list_empty(&vscsi->waiting_rsp) && (vscsi->flags & WAIT_FOR_IDLE)) {
948 vscsi->flags &= ~WAIT_FOR_IDLE;
949 complete(&vscsi->wait_idle);
954 * ibmvscsis_trans_event() - Handle a Transport Event
955 * @vscsi: Pointer to our adapter structure
956 * @crq: Pointer to CRQ entry containing the Transport Event
958 * Do the logic to close the I_T nexus. This function may not
959 * behave to specification.
961 * EXECUTION ENVIRONMENT:
962 * Interrupt, interrupt lock held
964 static long ibmvscsis_trans_event(struct scsi_info *vscsi,
965 struct viosrp_crq *crq)
967 long rc = ADAPT_SUCCESS;
969 pr_debug("trans_event: format %d, flags 0x%x, state 0x%hx\n",
970 (int)crq->format, vscsi->flags, vscsi->state);
972 switch (crq->format) {
975 case PARTNER_DEREGISTER:
976 ibmvscsis_delete_client_info(vscsi, true);
981 dev_err(&vscsi->dev, "trans_event: invalid format %d\n",
983 ibmvscsis_post_disconnect(vscsi, ERR_DISCONNECT,
988 if (rc == ADAPT_SUCCESS) {
989 switch (vscsi->state) {
991 case ERR_DISCONNECTED:
996 vscsi->flags |= (RESPONSE_Q_DOWN | TRANS_EVENT);
1002 case WAIT_CONNECTION:
1006 ibmvscsis_post_disconnect(vscsi, WAIT_IDLE,
1011 case SRP_PROCESSING:
1012 if ((vscsi->debit > 0) ||
1013 !list_empty(&vscsi->schedule_q) ||
1014 !list_empty(&vscsi->waiting_rsp) ||
1015 !list_empty(&vscsi->active_q)) {
1016 pr_debug("debit %d, sched %d, wait %d, active %d\n",
1018 (int)list_empty(&vscsi->schedule_q),
1019 (int)list_empty(&vscsi->waiting_rsp),
1020 (int)list_empty(&vscsi->active_q));
1021 pr_warn("connection lost with outstanding work\n");
1023 pr_debug("trans_event: SRP Processing, but no outstanding work\n");
1026 ibmvscsis_post_disconnect(vscsi, WAIT_IDLE,
1031 case ERR_DISCONNECT:
1032 case ERR_DISCONNECT_RECONNECT:
1034 vscsi->flags |= (RESPONSE_Q_DOWN | TRANS_EVENT);
1039 rc = vscsi->flags & SCHEDULE_DISCONNECT;
1041 pr_debug("Leaving trans_event: flags 0x%x, state 0x%hx, rc %ld\n",
1042 vscsi->flags, vscsi->state, rc);
1048 * ibmvscsis_poll_cmd_q() - Poll Command Queue
1049 * @vscsi: Pointer to our adapter structure
1051 * Called to handle command elements that may have arrived while
1052 * interrupts were disabled.
1054 * EXECUTION ENVIRONMENT:
1055 * intr_lock must be held
1057 static void ibmvscsis_poll_cmd_q(struct scsi_info *vscsi)
1059 struct viosrp_crq *crq;
1064 pr_debug("poll_cmd_q: flags 0x%x, state 0x%hx, q index %ud\n",
1065 vscsi->flags, vscsi->state, vscsi->cmd_q.index);
1067 rc = vscsi->flags & SCHEDULE_DISCONNECT;
1068 crq = vscsi->cmd_q.base_addr + vscsi->cmd_q.index;
1074 vscsi->cmd_q.index =
1075 (vscsi->cmd_q.index + 1) & vscsi->cmd_q.mask;
1078 rc = ibmvscsis_parse_command(vscsi, crq);
1080 if ((uint)crq->valid == VALID_TRANS_EVENT) {
1082 * must service the transport layer events even
1083 * in an error state, dont break out until all
1084 * the consecutive transport events have been
1087 rc = ibmvscsis_trans_event(vscsi, crq);
1088 } else if (vscsi->flags & TRANS_EVENT) {
1090 * if a tranport event has occurred leave
1091 * everything but transport events on the queue
1093 pr_debug("poll_cmd_q, ignoring\n");
1096 * need to decrement the queue index so we can
1097 * look at the elment again
1099 if (vscsi->cmd_q.index)
1100 vscsi->cmd_q.index -= 1;
1103 * index is at 0 it just wrapped.
1104 * have it index last element in q
1106 vscsi->cmd_q.index = vscsi->cmd_q.mask;
1111 crq->valid = INVALIDATE_CMD_RESP_EL;
1113 crq = vscsi->cmd_q.base_addr + vscsi->cmd_q.index;
1120 vio_enable_interrupts(vscsi->dma_dev);
1122 pr_debug("poll_cmd_q, reenabling interrupts\n");
1130 pr_debug("Leaving poll_cmd_q: rc %ld\n", rc);
1134 * ibmvscsis_free_cmd_qs() - Free elements in queue
1135 * @vscsi: Pointer to our adapter structure
1137 * Free all of the elements on all queues that are waiting for
1141 * Called with interrupt lock held
1143 static void ibmvscsis_free_cmd_qs(struct scsi_info *vscsi)
1145 struct ibmvscsis_cmd *cmd, *nxt;
1147 pr_debug("free_cmd_qs: waiting_rsp empty %d, timer starter %d\n",
1148 (int)list_empty(&vscsi->waiting_rsp),
1149 vscsi->rsp_q_timer.started);
1151 list_for_each_entry_safe(cmd, nxt, &vscsi->waiting_rsp, list) {
1152 list_del(&cmd->list);
1153 ibmvscsis_free_cmd_resources(vscsi, cmd);
1158 * ibmvscsis_get_free_cmd() - Get free command from list
1159 * @vscsi: Pointer to our adapter structure
1161 * Must be called with interrupt lock held.
1163 static struct ibmvscsis_cmd *ibmvscsis_get_free_cmd(struct scsi_info *vscsi)
1165 struct ibmvscsis_cmd *cmd = NULL;
1166 struct iu_entry *iue;
1168 iue = srp_iu_get(&vscsi->target);
1170 cmd = list_first_entry_or_null(&vscsi->free_cmd,
1171 struct ibmvscsis_cmd, list);
1174 cmd->abort_cmd = NULL;
1175 cmd->flags &= ~(DELAY_SEND);
1176 list_del(&cmd->list);
1178 cmd->type = UNSET_TYPE;
1179 memset(&cmd->se_cmd, 0, sizeof(cmd->se_cmd));
1189 * ibmvscsis_adapter_idle() - Helper function to handle idle adapter
1190 * @vscsi: Pointer to our adapter structure
1192 * This function is called when the adapter is idle when the driver
1193 * is attempting to clear an error condition.
1194 * The adapter is considered busy if any of its cmd queues
1195 * are non-empty. This function can be invoked
1196 * from the off level disconnect function.
1198 * EXECUTION ENVIRONMENT:
1199 * Process environment called with interrupt lock held
1201 static void ibmvscsis_adapter_idle(struct scsi_info *vscsi)
1203 int free_qs = false;
1205 pr_debug("adapter_idle: flags 0x%x, state 0x%hx\n", vscsi->flags,
1208 /* Only need to free qs if we're disconnecting from client */
1209 if (vscsi->state != WAIT_CONNECTION || vscsi->flags & TRANS_EVENT)
1212 switch (vscsi->state) {
1214 ibmvscsis_free_command_q(vscsi);
1217 if (vscsi->flags & CFG_SLEEPING) {
1218 vscsi->flags &= ~CFG_SLEEPING;
1219 complete(&vscsi->unconfig);
1222 case ERR_DISCONNECT_RECONNECT:
1223 ibmvscsis_reset_queue(vscsi);
1224 pr_debug("adapter_idle, disc_rec: flags 0x%x\n", vscsi->flags);
1227 case ERR_DISCONNECT:
1228 ibmvscsis_free_command_q(vscsi);
1229 vscsi->flags &= ~(SCHEDULE_DISCONNECT | DISCONNECT_SCHEDULED);
1230 vscsi->flags |= RESPONSE_Q_DOWN;
1231 if (vscsi->tport.enabled)
1232 vscsi->state = ERR_DISCONNECTED;
1234 vscsi->state = WAIT_ENABLED;
1235 pr_debug("adapter_idle, disc: flags 0x%x, state 0x%hx\n",
1236 vscsi->flags, vscsi->state);
1240 vscsi->rsp_q_timer.timer_pops = 0;
1243 if (vscsi->flags & TRANS_EVENT) {
1244 vscsi->state = WAIT_CONNECTION;
1245 vscsi->flags &= PRESERVE_FLAG_FIELDS;
1247 vscsi->state = CONNECTED;
1248 vscsi->flags &= ~DISCONNECT_SCHEDULED;
1251 pr_debug("adapter_idle, wait: flags 0x%x, state 0x%hx\n",
1252 vscsi->flags, vscsi->state);
1253 ibmvscsis_poll_cmd_q(vscsi);
1256 case ERR_DISCONNECTED:
1257 vscsi->flags &= ~DISCONNECT_SCHEDULED;
1258 pr_debug("adapter_idle, disconnected: flags 0x%x, state 0x%hx\n",
1259 vscsi->flags, vscsi->state);
1263 dev_err(&vscsi->dev, "adapter_idle: in invalid state %d\n",
1269 ibmvscsis_free_cmd_qs(vscsi);
1272 * There is a timing window where we could lose a disconnect request.
1273 * The known path to this window occurs during the DISCONNECT_RECONNECT
1274 * case above: reset_queue calls free_command_q, which will release the
1275 * interrupt lock. During that time, a new post_disconnect call can be
1276 * made with a "more severe" state (DISCONNECT or UNCONFIGURING).
1277 * Because the DISCONNECT_SCHEDULED flag is already set, post_disconnect
1278 * will only set the new_state. Now free_command_q reacquires the intr
1279 * lock and clears the DISCONNECT_SCHEDULED flag (using PRESERVE_FLAG_
1280 * FIELDS), and the disconnect is lost. This is particularly bad when
1281 * the new disconnect was for UNCONFIGURING, since the unconfigure hangs
1283 * Fix is that free command queue sets acr state and acr flags if there
1284 * is a change under the lock
1285 * note free command queue writes to this state it clears it
1286 * before releasing the lock, different drivers call the free command
1287 * queue different times so dont initialize above
1289 if (vscsi->phyp_acr_state != 0) {
1291 * set any bits in flags that may have been cleared by
1292 * a call to free command queue in switch statement
1295 vscsi->flags |= vscsi->phyp_acr_flags;
1296 ibmvscsis_post_disconnect(vscsi, vscsi->phyp_acr_state, 0);
1297 vscsi->phyp_acr_state = 0;
1298 vscsi->phyp_acr_flags = 0;
1300 pr_debug("adapter_idle: flags 0x%x, state 0x%hx, acr_flags 0x%x, acr_state 0x%hx\n",
1301 vscsi->flags, vscsi->state, vscsi->phyp_acr_flags,
1302 vscsi->phyp_acr_state);
1305 pr_debug("Leaving adapter_idle: flags 0x%x, state 0x%hx, new_state 0x%x\n",
1306 vscsi->flags, vscsi->state, vscsi->new_state);
1310 * ibmvscsis_copy_crq_packet() - Copy CRQ Packet
1311 * @vscsi: Pointer to our adapter structure
1312 * @cmd: Pointer to command element to use to process the request
1313 * @crq: Pointer to CRQ entry containing the request
1315 * Copy the srp information unit from the hosted
1316 * partition using remote dma
1318 * EXECUTION ENVIRONMENT:
1319 * Interrupt, interrupt lock held
1321 static long ibmvscsis_copy_crq_packet(struct scsi_info *vscsi,
1322 struct ibmvscsis_cmd *cmd,
1323 struct viosrp_crq *crq)
1325 struct iu_entry *iue = cmd->iue;
1329 len = be16_to_cpu(crq->IU_length);
1330 if ((len > SRP_MAX_IU_LEN) || (len == 0)) {
1331 dev_err(&vscsi->dev, "copy_crq: Invalid len %d passed", len);
1332 ibmvscsis_post_disconnect(vscsi, ERR_DISCONNECT_RECONNECT, 0);
1333 return SRP_VIOLATION;
1336 rc = h_copy_rdma(len, vscsi->dds.window[REMOTE].liobn,
1337 be64_to_cpu(crq->IU_data_ptr),
1338 vscsi->dds.window[LOCAL].liobn, iue->sbuf->dma);
1342 cmd->init_time = mftb();
1343 iue->remote_token = crq->IU_data_ptr;
1345 pr_debug("copy_crq: ioba 0x%llx, init_time 0x%llx\n",
1346 be64_to_cpu(crq->IU_data_ptr), cmd->init_time);
1349 if (connection_broken(vscsi))
1350 ibmvscsis_post_disconnect(vscsi,
1351 ERR_DISCONNECT_RECONNECT,
1355 ibmvscsis_post_disconnect(vscsi,
1356 ERR_DISCONNECT_RECONNECT, 0);
1358 dev_err(&vscsi->dev, "copy_crq: h_copy_rdma failed, rc %ld\n",
1364 dev_err(&vscsi->dev, "copy_crq: h_copy_rdma failed, rc %ld\n",
1366 ibmvscsis_post_disconnect(vscsi, ERR_DISCONNECT_RECONNECT, 0);
1374 * ibmvscsis_adapter_info - Service an Adapter Info MAnagement Data gram
1375 * @vscsi: Pointer to our adapter structure
1376 * @iue: Information Unit containing the Adapter Info MAD request
1378 * EXECUTION ENVIRONMENT:
1379 * Interrupt adapter lock is held
1381 static long ibmvscsis_adapter_info(struct scsi_info *vscsi,
1382 struct iu_entry *iue)
1384 struct viosrp_adapter_info *mad = &vio_iu(iue)->mad.adapter_info;
1385 struct mad_adapter_info_data *info;
1390 mad->common.status = cpu_to_be16(VIOSRP_MAD_SUCCESS);
1392 if (be16_to_cpu(mad->common.length) > sizeof(*info)) {
1393 mad->common.status = cpu_to_be16(VIOSRP_MAD_FAILED);
1397 info = dma_alloc_coherent(&vscsi->dma_dev->dev, sizeof(*info), &token,
1400 dev_err(&vscsi->dev, "bad dma_alloc_coherent %p\n",
1402 mad->common.status = cpu_to_be16(VIOSRP_MAD_FAILED);
1406 /* Get remote info */
1407 rc = h_copy_rdma(be16_to_cpu(mad->common.length),
1408 vscsi->dds.window[REMOTE].liobn,
1409 be64_to_cpu(mad->buffer),
1410 vscsi->dds.window[LOCAL].liobn, token);
1412 if (rc != H_SUCCESS) {
1413 if (rc == H_PERMISSION) {
1414 if (connection_broken(vscsi))
1415 flag_bits = (RESPONSE_Q_DOWN | CLIENT_FAILED);
1417 pr_warn("adapter_info: h_copy_rdma from client failed, rc %ld\n",
1419 pr_debug("adapter_info: ioba 0x%llx, flags 0x%x, flag_bits 0x%x\n",
1420 be64_to_cpu(mad->buffer), vscsi->flags, flag_bits);
1421 ibmvscsis_post_disconnect(vscsi, ERR_DISCONNECT_RECONNECT,
1427 * Copy client info, but ignore partition number, which we
1428 * already got from phyp - unless we failed to get it from
1429 * phyp (e.g. if we're running on a p5 system).
1431 if (vscsi->client_data.partition_number == 0)
1432 vscsi->client_data.partition_number =
1433 be32_to_cpu(info->partition_number);
1434 strncpy(vscsi->client_data.srp_version, info->srp_version,
1435 sizeof(vscsi->client_data.srp_version));
1436 strncpy(vscsi->client_data.partition_name, info->partition_name,
1437 sizeof(vscsi->client_data.partition_name));
1438 vscsi->client_data.mad_version = be32_to_cpu(info->mad_version);
1439 vscsi->client_data.os_type = be32_to_cpu(info->os_type);
1442 strncpy(info->srp_version, SRP_VERSION,
1443 sizeof(info->srp_version));
1444 strncpy(info->partition_name, vscsi->dds.partition_name,
1445 sizeof(info->partition_name));
1446 info->partition_number = cpu_to_be32(vscsi->dds.partition_num);
1447 info->mad_version = cpu_to_be32(MAD_VERSION_1);
1448 info->os_type = cpu_to_be32(LINUX);
1449 memset(&info->port_max_txu[0], 0, sizeof(info->port_max_txu));
1450 info->port_max_txu[0] = cpu_to_be32(MAX_TXU);
1453 rc = h_copy_rdma(sizeof(*info), vscsi->dds.window[LOCAL].liobn,
1454 token, vscsi->dds.window[REMOTE].liobn,
1455 be64_to_cpu(mad->buffer));
1463 if (connection_broken(vscsi))
1464 flag_bits = (RESPONSE_Q_DOWN | CLIENT_FAILED);
1466 dev_err(&vscsi->dev, "adapter_info: h_copy_rdma to client failed, rc %ld\n",
1468 ibmvscsis_post_disconnect(vscsi,
1469 ERR_DISCONNECT_RECONNECT,
1475 dma_free_coherent(&vscsi->dma_dev->dev, sizeof(*info), info, token);
1476 pr_debug("Leaving adapter_info, rc %ld\n", rc);
1482 * ibmvscsis_cap_mad() - Service a Capabilities MAnagement Data gram
1483 * @vscsi: Pointer to our adapter structure
1484 * @iue: Information Unit containing the Capabilities MAD request
1486 * NOTE: if you return an error from this routine you must be
1487 * disconnecting or you will cause a hang
1489 * EXECUTION ENVIRONMENT:
1490 * Interrupt called with adapter lock held
1492 static int ibmvscsis_cap_mad(struct scsi_info *vscsi, struct iu_entry *iue)
1494 struct viosrp_capabilities *mad = &vio_iu(iue)->mad.capabilities;
1495 struct capabilities *cap;
1496 struct mad_capability_common *common;
1498 u16 olen, len, status, min_len, cap_len;
1503 olen = be16_to_cpu(mad->common.length);
1505 * struct capabilities hardcodes a couple capabilities after the
1506 * header, but the capabilities can actually be in any order.
1508 min_len = offsetof(struct capabilities, migration);
1509 if ((olen < min_len) || (olen > PAGE_SIZE)) {
1510 pr_warn("cap_mad: invalid len %d\n", olen);
1511 mad->common.status = cpu_to_be16(VIOSRP_MAD_FAILED);
1515 cap = dma_alloc_coherent(&vscsi->dma_dev->dev, olen, &token,
1518 dev_err(&vscsi->dev, "bad dma_alloc_coherent %p\n",
1520 mad->common.status = cpu_to_be16(VIOSRP_MAD_FAILED);
1523 rc = h_copy_rdma(olen, vscsi->dds.window[REMOTE].liobn,
1524 be64_to_cpu(mad->buffer),
1525 vscsi->dds.window[LOCAL].liobn, token);
1526 if (rc == H_SUCCESS) {
1527 strncpy(cap->name, dev_name(&vscsi->dma_dev->dev),
1530 len = olen - min_len;
1531 status = VIOSRP_MAD_SUCCESS;
1532 common = (struct mad_capability_common *)&cap->migration;
1534 while ((len > 0) && (status == VIOSRP_MAD_SUCCESS) && !rc) {
1535 pr_debug("cap_mad: len left %hd, cap type %d, cap len %hd\n",
1536 len, be32_to_cpu(common->cap_type),
1537 be16_to_cpu(common->length));
1539 cap_len = be16_to_cpu(common->length);
1540 if (cap_len > len) {
1541 dev_err(&vscsi->dev, "cap_mad: cap len mismatch with total len\n");
1542 status = VIOSRP_MAD_FAILED;
1547 dev_err(&vscsi->dev, "cap_mad: cap len is 0\n");
1548 status = VIOSRP_MAD_FAILED;
1552 switch (common->cap_type) {
1554 pr_debug("cap_mad: unsupported capability\n");
1555 common->server_support = 0;
1556 flag = cpu_to_be32((u32)CAP_LIST_SUPPORTED);
1557 cap->flags &= ~flag;
1561 len = len - cap_len;
1562 common = (struct mad_capability_common *)
1563 ((char *)common + cap_len);
1566 mad->common.status = cpu_to_be16(status);
1569 rc = h_copy_rdma(olen, vscsi->dds.window[LOCAL].liobn, token,
1570 vscsi->dds.window[REMOTE].liobn,
1571 be64_to_cpu(mad->buffer));
1573 if (rc != H_SUCCESS) {
1574 pr_debug("cap_mad: failed to copy to client, rc %ld\n",
1577 if (rc == H_PERMISSION) {
1578 if (connection_broken(vscsi))
1579 flag_bits = (RESPONSE_Q_DOWN |
1583 pr_warn("cap_mad: error copying data to client, rc %ld\n",
1585 ibmvscsis_post_disconnect(vscsi,
1586 ERR_DISCONNECT_RECONNECT,
1591 dma_free_coherent(&vscsi->dma_dev->dev, olen, cap, token);
1593 pr_debug("Leaving cap_mad, rc %ld, client_cap 0x%x\n",
1594 rc, vscsi->client_cap);
1600 * ibmvscsis_process_mad() - Service a MAnagement Data gram
1601 * @vscsi: Pointer to our adapter structure
1602 * @iue: Information Unit containing the MAD request
1604 * Must be called with interrupt lock held.
1606 static long ibmvscsis_process_mad(struct scsi_info *vscsi, struct iu_entry *iue)
1608 struct mad_common *mad = (struct mad_common *)&vio_iu(iue)->mad;
1609 struct viosrp_empty_iu *empty;
1610 long rc = ADAPT_SUCCESS;
1612 switch (be32_to_cpu(mad->type)) {
1613 case VIOSRP_EMPTY_IU_TYPE:
1614 empty = &vio_iu(iue)->mad.empty_iu;
1615 vscsi->empty_iu_id = be64_to_cpu(empty->buffer);
1616 vscsi->empty_iu_tag = be64_to_cpu(empty->common.tag);
1617 mad->status = cpu_to_be16(VIOSRP_MAD_SUCCESS);
1619 case VIOSRP_ADAPTER_INFO_TYPE:
1620 rc = ibmvscsis_adapter_info(vscsi, iue);
1622 case VIOSRP_CAPABILITIES_TYPE:
1623 rc = ibmvscsis_cap_mad(vscsi, iue);
1625 case VIOSRP_ENABLE_FAST_FAIL:
1626 if (vscsi->state == CONNECTED) {
1627 vscsi->fast_fail = true;
1628 mad->status = cpu_to_be16(VIOSRP_MAD_SUCCESS);
1630 pr_warn("fast fail mad sent after login\n");
1631 mad->status = cpu_to_be16(VIOSRP_MAD_FAILED);
1635 mad->status = cpu_to_be16(VIOSRP_MAD_NOT_SUPPORTED);
1643 * srp_snd_msg_failed() - Handle an error when sending a response
1644 * @vscsi: Pointer to our adapter structure
1645 * @rc: The return code from the h_send_crq command
1647 * Must be called with interrupt lock held.
1649 static void srp_snd_msg_failed(struct scsi_info *vscsi, long rc)
1653 if (rc != H_DROPPED) {
1654 ibmvscsis_free_cmd_qs(vscsi);
1657 vscsi->flags |= CLIENT_FAILED;
1659 /* don't flag the same problem multiple times */
1660 if (!(vscsi->flags & RESPONSE_Q_DOWN)) {
1661 vscsi->flags |= RESPONSE_Q_DOWN;
1662 if (!(vscsi->state & (ERR_DISCONNECT |
1663 ERR_DISCONNECT_RECONNECT |
1664 ERR_DISCONNECTED | UNDEFINED))) {
1665 dev_err(&vscsi->dev, "snd_msg_failed: setting RESPONSE_Q_DOWN, state 0x%hx, flags 0x%x, rc %ld\n",
1666 vscsi->state, vscsi->flags, rc);
1668 ibmvscsis_post_disconnect(vscsi,
1669 ERR_DISCONNECT_RECONNECT, 0);
1675 * The response queue is full.
1676 * If the server is processing SRP requests, i.e.
1677 * the client has successfully done an
1678 * SRP_LOGIN, then it will wait forever for room in
1679 * the queue. However if the system admin
1680 * is attempting to unconfigure the server then one
1681 * or more children will be in a state where
1682 * they are being removed. So if there is even one
1683 * child being removed then the driver assumes
1684 * the system admin is attempting to break the
1685 * connection with the client and MAX_TIMER_POPS
1688 if ((vscsi->rsp_q_timer.timer_pops < MAX_TIMER_POPS) ||
1689 (vscsi->state == SRP_PROCESSING)) {
1690 pr_debug("snd_msg_failed: response queue full, flags 0x%x, timer started %d, pops %d\n",
1691 vscsi->flags, (int)vscsi->rsp_q_timer.started,
1692 vscsi->rsp_q_timer.timer_pops);
1695 * Check if the timer is running; if it
1696 * is not then start it up.
1698 if (!vscsi->rsp_q_timer.started) {
1699 if (vscsi->rsp_q_timer.timer_pops <
1701 kt = WAIT_NANO_SECONDS;
1704 * slide the timeslice if the maximum
1705 * timer pops have already happened
1707 kt = ktime_set(WAIT_SECONDS, 0);
1710 vscsi->rsp_q_timer.started = true;
1711 hrtimer_start(&vscsi->rsp_q_timer.timer, kt,
1716 * TBD: Do we need to worry about this? Need to get
1720 * waited a long time and it appears the system admin
1721 * is bring this driver down
1723 vscsi->flags |= RESPONSE_Q_DOWN;
1724 ibmvscsis_free_cmd_qs(vscsi);
1726 * if the driver is already attempting to disconnect
1727 * from the client and has already logged an error
1728 * trace this event but don't put it in the error log
1730 if (!(vscsi->state & (ERR_DISCONNECT |
1731 ERR_DISCONNECT_RECONNECT |
1732 ERR_DISCONNECTED | UNDEFINED))) {
1733 dev_err(&vscsi->dev, "client crq full too long\n");
1734 ibmvscsis_post_disconnect(vscsi,
1735 ERR_DISCONNECT_RECONNECT,
1742 * ibmvscsis_send_messages() - Send a Response
1743 * @vscsi: Pointer to our adapter structure
1745 * Send a response, first checking the waiting queue. Responses are
1746 * sent in order they are received. If the response cannot be sent,
1747 * because the client queue is full, it stays on the waiting queue.
1750 * Called with interrupt lock held
1752 static void ibmvscsis_send_messages(struct scsi_info *vscsi)
1755 /* note do not attempt to access the IU_data_ptr with this pointer
1758 struct viosrp_crq *crq = (struct viosrp_crq *)&msg_hi;
1759 struct ibmvscsis_cmd *cmd, *nxt;
1760 struct iu_entry *iue;
1761 long rc = ADAPT_SUCCESS;
1764 if (!(vscsi->flags & RESPONSE_Q_DOWN)) {
1767 list_for_each_entry_safe(cmd, nxt, &vscsi->waiting_rsp,
1770 * Check to make sure abort cmd gets processed
1771 * prior to the abort tmr cmd
1773 if (cmd->flags & DELAY_SEND)
1776 if (cmd->abort_cmd) {
1778 cmd->abort_cmd->flags &= ~(DELAY_SEND);
1779 cmd->abort_cmd = NULL;
1783 * If CMD_T_ABORTED w/o CMD_T_TAS scenarios and
1784 * the case where LIO issued a
1785 * ABORT_TASK: Sending TMR_TASK_DOES_NOT_EXIST
1786 * case then we dont send a response, since it
1789 if (cmd->se_cmd.transport_state & CMD_T_ABORTED &&
1790 !(cmd->se_cmd.transport_state & CMD_T_TAS)) {
1791 list_del(&cmd->list);
1792 ibmvscsis_free_cmd_resources(vscsi,
1795 * With a successfully aborted op
1796 * through LIO we want to increment the
1797 * the vscsi credit so that when we dont
1798 * send a rsp to the original scsi abort
1799 * op (h_send_crq), but the tm rsp to
1800 * the abort is sent, the credit is
1801 * correctly sent with the abort tm rsp.
1802 * We would need 1 for the abort tm rsp
1803 * and 1 credit for the aborted scsi op.
1804 * Thus we need to increment here.
1805 * Also we want to increment the credit
1806 * here because we want to make sure
1807 * cmd is actually released first
1808 * otherwise the client will think it
1809 * it can send a new cmd, and we could
1810 * find ourselves short of cmd elements.
1816 crq->valid = VALID_CMD_RESP_EL;
1817 crq->format = cmd->rsp.format;
1819 if (cmd->flags & CMD_FAST_FAIL)
1820 crq->status = VIOSRP_ADAPTER_FAIL;
1822 crq->IU_length = cpu_to_be16(cmd->rsp.len);
1824 rc = h_send_crq(vscsi->dma_dev->unit_address,
1825 be64_to_cpu(msg_hi),
1826 be64_to_cpu(cmd->rsp.tag));
1828 pr_debug("send_messages: cmd %p, tag 0x%llx, rc %ld\n",
1829 cmd, be64_to_cpu(cmd->rsp.tag), rc);
1831 /* if all ok free up the command
1834 if (rc == H_SUCCESS) {
1835 /* some movement has occurred */
1836 vscsi->rsp_q_timer.timer_pops = 0;
1837 list_del(&cmd->list);
1839 ibmvscsis_free_cmd_resources(vscsi,
1842 srp_snd_msg_failed(vscsi, rc);
1851 * The timer could pop with the queue empty. If
1852 * this happens, rc will always indicate a
1853 * success; clear the pop count.
1855 vscsi->rsp_q_timer.timer_pops = 0;
1858 ibmvscsis_free_cmd_qs(vscsi);
1862 /* Called with intr lock held */
1863 static void ibmvscsis_send_mad_resp(struct scsi_info *vscsi,
1864 struct ibmvscsis_cmd *cmd,
1865 struct viosrp_crq *crq)
1867 struct iu_entry *iue = cmd->iue;
1868 struct mad_common *mad = (struct mad_common *)&vio_iu(iue)->mad;
1873 rc = h_copy_rdma(sizeof(struct mad_common),
1874 vscsi->dds.window[LOCAL].liobn, iue->sbuf->dma,
1875 vscsi->dds.window[REMOTE].liobn,
1876 be64_to_cpu(crq->IU_data_ptr));
1878 cmd->rsp.format = VIOSRP_MAD_FORMAT;
1879 cmd->rsp.len = sizeof(struct mad_common);
1880 cmd->rsp.tag = mad->tag;
1881 list_add_tail(&cmd->list, &vscsi->waiting_rsp);
1882 ibmvscsis_send_messages(vscsi);
1884 pr_debug("Error sending mad response, rc %ld\n", rc);
1885 if (rc == H_PERMISSION) {
1886 if (connection_broken(vscsi))
1887 flag_bits = (RESPONSE_Q_DOWN | CLIENT_FAILED);
1889 dev_err(&vscsi->dev, "mad: failed to copy to client, rc %ld\n",
1892 ibmvscsis_free_cmd_resources(vscsi, cmd);
1893 ibmvscsis_post_disconnect(vscsi, ERR_DISCONNECT_RECONNECT,
1899 * ibmvscsis_mad() - Service a MAnagement Data gram.
1900 * @vscsi: Pointer to our adapter structure
1901 * @crq: Pointer to the CRQ entry containing the MAD request
1903 * EXECUTION ENVIRONMENT:
1904 * Interrupt, called with adapter lock held
1906 static long ibmvscsis_mad(struct scsi_info *vscsi, struct viosrp_crq *crq)
1908 struct iu_entry *iue;
1909 struct ibmvscsis_cmd *cmd;
1910 struct mad_common *mad;
1911 long rc = ADAPT_SUCCESS;
1913 switch (vscsi->state) {
1915 * We have not exchanged Init Msgs yet, so this MAD was sent
1916 * before the last Transport Event; client will not be
1917 * expecting a response.
1919 case WAIT_CONNECTION:
1920 pr_debug("mad: in Wait Connection state, ignoring MAD, flags %d\n",
1922 return ADAPT_SUCCESS;
1924 case SRP_PROCESSING:
1929 * We should never get here while we're in these states.
1930 * Just log an error and get out.
1934 case ERR_DISCONNECT:
1935 case ERR_DISCONNECT_RECONNECT:
1937 dev_err(&vscsi->dev, "mad: invalid adapter state %d for mad\n",
1939 return ADAPT_SUCCESS;
1942 cmd = ibmvscsis_get_free_cmd(vscsi);
1944 dev_err(&vscsi->dev, "mad: failed to get cmd, debit %d\n",
1946 ibmvscsis_post_disconnect(vscsi, ERR_DISCONNECT_RECONNECT, 0);
1950 cmd->type = ADAPTER_MAD;
1952 rc = ibmvscsis_copy_crq_packet(vscsi, cmd, crq);
1954 mad = (struct mad_common *)&vio_iu(iue)->mad;
1956 pr_debug("mad: type %d\n", be32_to_cpu(mad->type));
1958 rc = ibmvscsis_process_mad(vscsi, iue);
1960 pr_debug("mad: status %hd, rc %ld\n", be16_to_cpu(mad->status),
1964 ibmvscsis_send_mad_resp(vscsi, cmd, crq);
1966 ibmvscsis_free_cmd_resources(vscsi, cmd);
1969 pr_debug("Leaving mad, rc %ld\n", rc);
1974 * ibmvscsis_login_rsp() - Create/copy a login response notice to the client
1975 * @vscsi: Pointer to our adapter structure
1976 * @cmd: Pointer to the command for the SRP Login request
1978 * EXECUTION ENVIRONMENT:
1979 * Interrupt, interrupt lock held
1981 static long ibmvscsis_login_rsp(struct scsi_info *vscsi,
1982 struct ibmvscsis_cmd *cmd)
1984 struct iu_entry *iue = cmd->iue;
1985 struct srp_login_rsp *rsp = &vio_iu(iue)->srp.login_rsp;
1986 struct format_code *fmt;
1988 long rc = ADAPT_SUCCESS;
1990 memset(rsp, 0, sizeof(struct srp_login_rsp));
1992 rsp->opcode = SRP_LOGIN_RSP;
1993 rsp->req_lim_delta = cpu_to_be32(vscsi->request_limit);
1994 rsp->tag = cmd->rsp.tag;
1995 rsp->max_it_iu_len = cpu_to_be32(SRP_MAX_IU_LEN);
1996 rsp->max_ti_iu_len = cpu_to_be32(SRP_MAX_IU_LEN);
1997 fmt = (struct format_code *)&rsp->buf_fmt;
1998 fmt->buffers = SUPPORTED_FORMATS;
2001 cmd->rsp.len = sizeof(struct srp_login_rsp);
2004 rc = h_copy_rdma(cmd->rsp.len, vscsi->dds.window[LOCAL].liobn,
2005 iue->sbuf->dma, vscsi->dds.window[REMOTE].liobn,
2006 be64_to_cpu(iue->remote_token));
2013 if (connection_broken(vscsi))
2014 flag_bits = RESPONSE_Q_DOWN | CLIENT_FAILED;
2015 dev_err(&vscsi->dev, "login_rsp: error copying to client, rc %ld\n",
2017 ibmvscsis_post_disconnect(vscsi, ERR_DISCONNECT_RECONNECT,
2023 dev_err(&vscsi->dev, "login_rsp: error copying to client, rc %ld\n",
2025 ibmvscsis_post_disconnect(vscsi, ERR_DISCONNECT_RECONNECT, 0);
2033 * ibmvscsis_srp_login_rej() - Create/copy a login rejection notice to client
2034 * @vscsi: Pointer to our adapter structure
2035 * @cmd: Pointer to the command for the SRP Login request
2036 * @reason: The reason the SRP Login is being rejected, per SRP protocol
2038 * EXECUTION ENVIRONMENT:
2039 * Interrupt, interrupt lock held
2041 static long ibmvscsis_srp_login_rej(struct scsi_info *vscsi,
2042 struct ibmvscsis_cmd *cmd, u32 reason)
2044 struct iu_entry *iue = cmd->iue;
2045 struct srp_login_rej *rej = &vio_iu(iue)->srp.login_rej;
2046 struct format_code *fmt;
2048 long rc = ADAPT_SUCCESS;
2050 memset(rej, 0, sizeof(*rej));
2052 rej->opcode = SRP_LOGIN_REJ;
2053 rej->reason = cpu_to_be32(reason);
2054 rej->tag = cmd->rsp.tag;
2055 fmt = (struct format_code *)&rej->buf_fmt;
2056 fmt->buffers = SUPPORTED_FORMATS;
2058 cmd->rsp.len = sizeof(*rej);
2061 rc = h_copy_rdma(cmd->rsp.len, vscsi->dds.window[LOCAL].liobn,
2062 iue->sbuf->dma, vscsi->dds.window[REMOTE].liobn,
2063 be64_to_cpu(iue->remote_token));
2069 if (connection_broken(vscsi))
2070 flag_bits = RESPONSE_Q_DOWN | CLIENT_FAILED;
2071 dev_err(&vscsi->dev, "login_rej: error copying to client, rc %ld\n",
2073 ibmvscsis_post_disconnect(vscsi, ERR_DISCONNECT_RECONNECT,
2079 dev_err(&vscsi->dev, "login_rej: error copying to client, rc %ld\n",
2081 ibmvscsis_post_disconnect(vscsi, ERR_DISCONNECT_RECONNECT, 0);
2088 static int ibmvscsis_make_nexus(struct ibmvscsis_tport *tport)
2090 char *name = tport->tport_name;
2091 struct ibmvscsis_nexus *nexus;
2094 if (tport->ibmv_nexus) {
2095 pr_debug("tport->ibmv_nexus already exists\n");
2099 nexus = kzalloc(sizeof(*nexus), GFP_KERNEL);
2101 pr_err("Unable to allocate struct ibmvscsis_nexus\n");
2105 nexus->se_sess = target_alloc_session(&tport->se_tpg, 0, 0,
2106 TARGET_PROT_NORMAL, name, nexus,
2108 if (IS_ERR(nexus->se_sess)) {
2109 rc = PTR_ERR(nexus->se_sess);
2110 goto transport_init_fail;
2113 tport->ibmv_nexus = nexus;
2117 transport_init_fail:
2122 static int ibmvscsis_drop_nexus(struct ibmvscsis_tport *tport)
2124 struct se_session *se_sess;
2125 struct ibmvscsis_nexus *nexus;
2127 nexus = tport->ibmv_nexus;
2131 se_sess = nexus->se_sess;
2136 * Release the SCSI I_T Nexus to the emulated ibmvscsis Target Port
2138 target_wait_for_sess_cmds(se_sess);
2139 transport_deregister_session_configfs(se_sess);
2140 transport_deregister_session(se_sess);
2141 tport->ibmv_nexus = NULL;
2148 * ibmvscsis_srp_login() - Process an SRP Login Request
2149 * @vscsi: Pointer to our adapter structure
2150 * @cmd: Command element to use to process the SRP Login request
2151 * @crq: Pointer to CRQ entry containing the SRP Login request
2153 * EXECUTION ENVIRONMENT:
2154 * Interrupt, called with interrupt lock held
2156 static long ibmvscsis_srp_login(struct scsi_info *vscsi,
2157 struct ibmvscsis_cmd *cmd,
2158 struct viosrp_crq *crq)
2160 struct iu_entry *iue = cmd->iue;
2161 struct srp_login_req *req = &vio_iu(iue)->srp.login_req;
2163 __be64 id_extension;
2166 struct format_code *fmt;
2168 long rc = ADAPT_SUCCESS;
2170 iport = (struct port_id *)req->initiator_port_id;
2171 tport = (struct port_id *)req->target_port_id;
2172 fmt = (struct format_code *)&req->req_buf_fmt;
2173 if (be32_to_cpu(req->req_it_iu_len) > SRP_MAX_IU_LEN)
2174 reason = SRP_LOGIN_REJ_REQ_IT_IU_LENGTH_TOO_LARGE;
2175 else if (be32_to_cpu(req->req_it_iu_len) < 64)
2176 reason = SRP_LOGIN_REJ_UNABLE_ESTABLISH_CHANNEL;
2177 else if ((be64_to_cpu(iport->id_extension) > (MAX_NUM_PORTS - 1)) ||
2178 (be64_to_cpu(tport->id_extension) > (MAX_NUM_PORTS - 1)))
2179 reason = SRP_LOGIN_REJ_UNABLE_ASSOCIATE_CHANNEL;
2180 else if (req->req_flags & SRP_MULTICHAN_MULTI)
2181 reason = SRP_LOGIN_REJ_MULTI_CHANNEL_UNSUPPORTED;
2182 else if (fmt->buffers & (~SUPPORTED_FORMATS))
2183 reason = SRP_LOGIN_REJ_UNSUPPORTED_DESCRIPTOR_FMT;
2184 else if ((fmt->buffers & SUPPORTED_FORMATS) == 0)
2185 reason = SRP_LOGIN_REJ_UNSUPPORTED_DESCRIPTOR_FMT;
2187 if (vscsi->state == SRP_PROCESSING)
2188 reason = SRP_LOGIN_REJ_CHANNEL_LIMIT_REACHED;
2190 rc = ibmvscsis_make_nexus(&vscsi->tport);
2192 reason = SRP_LOGIN_REJ_UNABLE_ESTABLISH_CHANNEL;
2194 cmd->rsp.format = VIOSRP_SRP_FORMAT;
2195 cmd->rsp.tag = req->tag;
2197 pr_debug("srp_login: reason 0x%x\n", reason);
2200 rc = ibmvscsis_srp_login_rej(vscsi, cmd, reason);
2202 rc = ibmvscsis_login_rsp(vscsi, cmd);
2206 vscsi->state = SRP_PROCESSING;
2208 list_add_tail(&cmd->list, &vscsi->waiting_rsp);
2209 ibmvscsis_send_messages(vscsi);
2211 ibmvscsis_free_cmd_resources(vscsi, cmd);
2214 pr_debug("Leaving srp_login, rc %ld\n", rc);
2219 * ibmvscsis_srp_i_logout() - Helper Function to close I_T Nexus
2220 * @vscsi: Pointer to our adapter structure
2221 * @cmd: Command element to use to process the Implicit Logout request
2222 * @crq: Pointer to CRQ entry containing the Implicit Logout request
2224 * Do the logic to close the I_T nexus. This function may not
2225 * behave to specification.
2227 * EXECUTION ENVIRONMENT:
2228 * Interrupt, interrupt lock held
2230 static long ibmvscsis_srp_i_logout(struct scsi_info *vscsi,
2231 struct ibmvscsis_cmd *cmd,
2232 struct viosrp_crq *crq)
2234 struct iu_entry *iue = cmd->iue;
2235 struct srp_i_logout *log_out = &vio_iu(iue)->srp.i_logout;
2236 long rc = ADAPT_SUCCESS;
2238 if ((vscsi->debit > 0) || !list_empty(&vscsi->schedule_q) ||
2239 !list_empty(&vscsi->waiting_rsp)) {
2240 dev_err(&vscsi->dev, "i_logout: outstanding work\n");
2241 ibmvscsis_post_disconnect(vscsi, ERR_DISCONNECT, 0);
2243 cmd->rsp.format = SRP_FORMAT;
2244 cmd->rsp.tag = log_out->tag;
2245 cmd->rsp.len = sizeof(struct mad_common);
2246 list_add_tail(&cmd->list, &vscsi->waiting_rsp);
2247 ibmvscsis_send_messages(vscsi);
2249 ibmvscsis_post_disconnect(vscsi, WAIT_IDLE, 0);
2255 /* Called with intr lock held */
2256 static void ibmvscsis_srp_cmd(struct scsi_info *vscsi, struct viosrp_crq *crq)
2258 struct ibmvscsis_cmd *cmd;
2259 struct iu_entry *iue;
2260 struct srp_cmd *srp;
2261 struct srp_tsk_mgmt *tsk;
2264 if (vscsi->request_limit - vscsi->debit <= 0) {
2265 /* Client has exceeded request limit */
2266 dev_err(&vscsi->dev, "Client exceeded the request limit (%d), debit %d\n",
2267 vscsi->request_limit, vscsi->debit);
2268 ibmvscsis_post_disconnect(vscsi, ERR_DISCONNECT_RECONNECT, 0);
2272 cmd = ibmvscsis_get_free_cmd(vscsi);
2274 dev_err(&vscsi->dev, "srp_cmd failed to get cmd, debit %d\n",
2276 ibmvscsis_post_disconnect(vscsi, ERR_DISCONNECT_RECONNECT, 0);
2280 srp = &vio_iu(iue)->srp.cmd;
2282 rc = ibmvscsis_copy_crq_packet(vscsi, cmd, crq);
2284 ibmvscsis_free_cmd_resources(vscsi, cmd);
2288 if (vscsi->state == SRP_PROCESSING) {
2289 switch (srp->opcode) {
2291 rc = ibmvscsis_srp_login(vscsi, cmd, crq);
2295 tsk = &vio_iu(iue)->srp.tsk_mgmt;
2296 pr_debug("tsk_mgmt tag: %llu (0x%llx)\n", tsk->tag,
2298 cmd->rsp.tag = tsk->tag;
2300 cmd->type = TASK_MANAGEMENT;
2301 list_add_tail(&cmd->list, &vscsi->schedule_q);
2302 queue_work(vscsi->work_q, &cmd->work);
2306 pr_debug("srp_cmd tag: %llu (0x%llx)\n", srp->tag,
2308 cmd->rsp.tag = srp->tag;
2310 cmd->type = SCSI_CDB;
2312 * We want to keep track of work waiting for
2315 list_add_tail(&cmd->list, &vscsi->schedule_q);
2316 queue_work(vscsi->work_q, &cmd->work);
2320 rc = ibmvscsis_srp_i_logout(vscsi, cmd, crq);
2326 ibmvscsis_free_cmd_resources(vscsi, cmd);
2327 dev_err(&vscsi->dev, "invalid srp cmd, opcode %d\n",
2329 ibmvscsis_post_disconnect(vscsi,
2330 ERR_DISCONNECT_RECONNECT, 0);
2333 } else if (srp->opcode == SRP_LOGIN_REQ && vscsi->state == CONNECTED) {
2334 rc = ibmvscsis_srp_login(vscsi, cmd, crq);
2336 ibmvscsis_free_cmd_resources(vscsi, cmd);
2337 dev_err(&vscsi->dev, "Invalid state %d to handle srp cmd\n",
2339 ibmvscsis_post_disconnect(vscsi, ERR_DISCONNECT_RECONNECT, 0);
2344 * ibmvscsis_ping_response() - Respond to a ping request
2345 * @vscsi: Pointer to our adapter structure
2347 * Let the client know that the server is alive and waiting on
2348 * its native I/O stack.
2349 * If any type of error occurs from the call to queue a ping
2350 * response then the client is either not accepting or receiving
2351 * interrupts. Disconnect with an error.
2353 * EXECUTION ENVIRONMENT:
2354 * Interrupt, interrupt lock held
2356 static long ibmvscsis_ping_response(struct scsi_info *vscsi)
2358 struct viosrp_crq *crq;
2359 u64 buffer[2] = { 0, 0 };
2362 crq = (struct viosrp_crq *)&buffer;
2363 crq->valid = VALID_CMD_RESP_EL;
2364 crq->format = (u8)MESSAGE_IN_CRQ;
2365 crq->status = PING_RESPONSE;
2367 rc = h_send_crq(vscsi->dds.unit_id, cpu_to_be64(buffer[MSG_HI]),
2368 cpu_to_be64(buffer[MSG_LOW]));
2374 vscsi->flags |= CLIENT_FAILED;
2376 vscsi->flags |= RESPONSE_Q_DOWN;
2378 dev_err(&vscsi->dev, "ping_response: h_send_crq failed, rc %ld\n",
2380 ibmvscsis_post_disconnect(vscsi, ERR_DISCONNECT_RECONNECT, 0);
2383 dev_err(&vscsi->dev, "ping_response: h_send_crq returned unknown rc %ld\n",
2385 ibmvscsis_post_disconnect(vscsi, ERR_DISCONNECT, 0);
2393 * ibmvscsis_parse_command() - Parse an element taken from the cmd rsp queue.
2394 * @vscsi: Pointer to our adapter structure
2395 * @crq: Pointer to CRQ element containing the SRP request
2397 * This function will return success if the command queue element is valid
2398 * and the srp iu or MAD request it pointed to was also valid. That does
2399 * not mean that an error was not returned to the client.
2401 * EXECUTION ENVIRONMENT:
2402 * Interrupt, intr lock held
2404 static long ibmvscsis_parse_command(struct scsi_info *vscsi,
2405 struct viosrp_crq *crq)
2407 long rc = ADAPT_SUCCESS;
2409 switch (crq->valid) {
2410 case VALID_CMD_RESP_EL:
2411 switch (crq->format) {
2416 if (vscsi->flags & PROCESSING_MAD) {
2418 dev_err(&vscsi->dev, "parse_command: already processing mad\n");
2419 ibmvscsis_post_disconnect(vscsi,
2420 ERR_DISCONNECT_RECONNECT,
2423 vscsi->flags |= PROCESSING_MAD;
2424 rc = ibmvscsis_mad(vscsi, crq);
2429 ibmvscsis_srp_cmd(vscsi, crq);
2432 case MESSAGE_IN_CRQ:
2433 if (crq->status == PING)
2434 ibmvscsis_ping_response(vscsi);
2438 dev_err(&vscsi->dev, "parse_command: invalid format %d\n",
2440 ibmvscsis_post_disconnect(vscsi,
2441 ERR_DISCONNECT_RECONNECT, 0);
2446 case VALID_TRANS_EVENT:
2447 rc = ibmvscsis_trans_event(vscsi, crq);
2450 case VALID_INIT_MSG:
2451 rc = ibmvscsis_init_msg(vscsi, crq);
2455 dev_err(&vscsi->dev, "parse_command: invalid valid field %d\n",
2457 ibmvscsis_post_disconnect(vscsi, ERR_DISCONNECT_RECONNECT, 0);
2462 * Return only what the interrupt handler cares
2463 * about. Most errors we keep right on trucking.
2465 rc = vscsi->flags & SCHEDULE_DISCONNECT;
2470 static int read_dma_window(struct scsi_info *vscsi)
2472 struct vio_dev *vdev = vscsi->dma_dev;
2473 const __be32 *dma_window;
2476 /* TODO Using of_parse_dma_window would be better, but it doesn't give
2477 * a way to read multiple windows without already knowing the size of
2478 * a window or the number of windows.
2480 dma_window = (const __be32 *)vio_get_attribute(vdev,
2481 "ibm,my-dma-window",
2484 pr_err("Couldn't find ibm,my-dma-window property\n");
2488 vscsi->dds.window[LOCAL].liobn = be32_to_cpu(*dma_window);
2491 prop = (const __be32 *)vio_get_attribute(vdev, "ibm,#dma-address-cells",
2494 pr_warn("Couldn't find ibm,#dma-address-cells property\n");
2497 dma_window += be32_to_cpu(*prop);
2500 prop = (const __be32 *)vio_get_attribute(vdev, "ibm,#dma-size-cells",
2503 pr_warn("Couldn't find ibm,#dma-size-cells property\n");
2506 dma_window += be32_to_cpu(*prop);
2509 /* dma_window should point to the second window now */
2510 vscsi->dds.window[REMOTE].liobn = be32_to_cpu(*dma_window);
2515 static struct ibmvscsis_tport *ibmvscsis_lookup_port(const char *name)
2517 struct ibmvscsis_tport *tport = NULL;
2518 struct vio_dev *vdev;
2519 struct scsi_info *vscsi;
2521 spin_lock_bh(&ibmvscsis_dev_lock);
2522 list_for_each_entry(vscsi, &ibmvscsis_dev_list, list) {
2523 vdev = vscsi->dma_dev;
2524 if (!strcmp(dev_name(&vdev->dev), name)) {
2525 tport = &vscsi->tport;
2529 spin_unlock_bh(&ibmvscsis_dev_lock);
2535 * ibmvscsis_parse_cmd() - Parse SRP Command
2536 * @vscsi: Pointer to our adapter structure
2537 * @cmd: Pointer to command element with SRP command
2539 * Parse the srp command; if it is valid then submit it to tcm.
2540 * Note: The return code does not reflect the status of the SCSI CDB.
2542 * EXECUTION ENVIRONMENT:
2545 static void ibmvscsis_parse_cmd(struct scsi_info *vscsi,
2546 struct ibmvscsis_cmd *cmd)
2548 struct iu_entry *iue = cmd->iue;
2549 struct srp_cmd *srp = (struct srp_cmd *)iue->sbuf->buf;
2550 struct ibmvscsis_nexus *nexus;
2552 enum dma_data_direction dir;
2556 nexus = vscsi->tport.ibmv_nexus;
2558 * additional length in bytes. Note that the SRP spec says that
2559 * additional length is in 4-byte words, but technically the
2560 * additional length field is only the upper 6 bits of the byte.
2561 * The lower 2 bits are reserved. If the lower 2 bits are 0 (as
2562 * all reserved fields should be), then interpreting the byte as
2563 * an int will yield the length in bytes.
2565 if (srp->add_cdb_len & 0x03) {
2566 dev_err(&vscsi->dev, "parse_cmd: reserved bits set in IU\n");
2567 spin_lock_bh(&vscsi->intr_lock);
2568 ibmvscsis_post_disconnect(vscsi, ERR_DISCONNECT_RECONNECT, 0);
2569 ibmvscsis_free_cmd_resources(vscsi, cmd);
2570 spin_unlock_bh(&vscsi->intr_lock);
2574 if (srp_get_desc_table(srp, &dir, &data_len)) {
2575 dev_err(&vscsi->dev, "0x%llx: parsing SRP descriptor table failed.\n",
2580 cmd->rsp.sol_not = srp->sol_not;
2582 switch (srp->task_attr) {
2583 case SRP_SIMPLE_TASK:
2584 attr = TCM_SIMPLE_TAG;
2586 case SRP_ORDERED_TASK:
2587 attr = TCM_ORDERED_TAG;
2590 attr = TCM_HEAD_TAG;
2596 dev_err(&vscsi->dev, "Invalid task attribute %d\n",
2601 cmd->se_cmd.tag = be64_to_cpu(srp->tag);
2603 spin_lock_bh(&vscsi->intr_lock);
2604 list_add_tail(&cmd->list, &vscsi->active_q);
2605 spin_unlock_bh(&vscsi->intr_lock);
2607 srp->lun.scsi_lun[0] &= 0x3f;
2609 rc = target_submit_cmd(&cmd->se_cmd, nexus->se_sess, srp->cdb,
2610 cmd->sense_buf, scsilun_to_int(&srp->lun),
2611 data_len, attr, dir, 0);
2613 dev_err(&vscsi->dev, "target_submit_cmd failed, rc %d\n", rc);
2614 spin_lock_bh(&vscsi->intr_lock);
2615 list_del(&cmd->list);
2616 ibmvscsis_free_cmd_resources(vscsi, cmd);
2617 spin_unlock_bh(&vscsi->intr_lock);
2623 spin_lock_bh(&vscsi->intr_lock);
2624 ibmvscsis_post_disconnect(vscsi, ERR_DISCONNECT_RECONNECT, 0);
2625 spin_unlock_bh(&vscsi->intr_lock);
2629 * ibmvscsis_parse_task() - Parse SRP Task Management Request
2630 * @vscsi: Pointer to our adapter structure
2631 * @cmd: Pointer to command element with SRP task management request
2633 * Parse the srp task management request; if it is valid then submit it to tcm.
2634 * Note: The return code does not reflect the status of the task management
2637 * EXECUTION ENVIRONMENT:
2640 static void ibmvscsis_parse_task(struct scsi_info *vscsi,
2641 struct ibmvscsis_cmd *cmd)
2643 struct iu_entry *iue = cmd->iue;
2644 struct srp_tsk_mgmt *srp_tsk = &vio_iu(iue)->srp.tsk_mgmt;
2646 u64 tag_to_abort = 0;
2648 struct ibmvscsis_nexus *nexus;
2650 nexus = vscsi->tport.ibmv_nexus;
2652 cmd->rsp.sol_not = srp_tsk->sol_not;
2654 switch (srp_tsk->tsk_mgmt_func) {
2655 case SRP_TSK_ABORT_TASK:
2656 tcm_type = TMR_ABORT_TASK;
2657 tag_to_abort = be64_to_cpu(srp_tsk->task_tag);
2659 case SRP_TSK_ABORT_TASK_SET:
2660 tcm_type = TMR_ABORT_TASK_SET;
2662 case SRP_TSK_CLEAR_TASK_SET:
2663 tcm_type = TMR_CLEAR_TASK_SET;
2665 case SRP_TSK_LUN_RESET:
2666 tcm_type = TMR_LUN_RESET;
2668 case SRP_TSK_CLEAR_ACA:
2669 tcm_type = TMR_CLEAR_ACA;
2672 dev_err(&vscsi->dev, "unknown task mgmt func %d\n",
2673 srp_tsk->tsk_mgmt_func);
2674 cmd->se_cmd.se_tmr_req->response =
2675 TMR_TASK_MGMT_FUNCTION_NOT_SUPPORTED;
2681 cmd->se_cmd.tag = be64_to_cpu(srp_tsk->tag);
2683 spin_lock_bh(&vscsi->intr_lock);
2684 list_add_tail(&cmd->list, &vscsi->active_q);
2685 spin_unlock_bh(&vscsi->intr_lock);
2687 srp_tsk->lun.scsi_lun[0] &= 0x3f;
2689 pr_debug("calling submit_tmr, func %d\n",
2690 srp_tsk->tsk_mgmt_func);
2691 rc = target_submit_tmr(&cmd->se_cmd, nexus->se_sess, NULL,
2692 scsilun_to_int(&srp_tsk->lun), srp_tsk,
2693 tcm_type, GFP_KERNEL, tag_to_abort, 0);
2695 dev_err(&vscsi->dev, "target_submit_tmr failed, rc %d\n",
2697 spin_lock_bh(&vscsi->intr_lock);
2698 list_del(&cmd->list);
2699 spin_unlock_bh(&vscsi->intr_lock);
2700 cmd->se_cmd.se_tmr_req->response =
2701 TMR_FUNCTION_REJECTED;
2706 transport_send_check_condition_and_sense(&cmd->se_cmd, 0, 0);
2709 static void ibmvscsis_scheduler(struct work_struct *work)
2711 struct ibmvscsis_cmd *cmd = container_of(work, struct ibmvscsis_cmd,
2713 struct scsi_info *vscsi = cmd->adapter;
2715 spin_lock_bh(&vscsi->intr_lock);
2717 /* Remove from schedule_q */
2718 list_del(&cmd->list);
2720 /* Don't submit cmd if we're disconnecting */
2721 if (vscsi->flags & (SCHEDULE_DISCONNECT | DISCONNECT_SCHEDULED)) {
2722 ibmvscsis_free_cmd_resources(vscsi, cmd);
2724 /* ibmvscsis_disconnect might be waiting for us */
2725 if (list_empty(&vscsi->active_q) &&
2726 list_empty(&vscsi->schedule_q) &&
2727 (vscsi->flags & WAIT_FOR_IDLE)) {
2728 vscsi->flags &= ~WAIT_FOR_IDLE;
2729 complete(&vscsi->wait_idle);
2732 spin_unlock_bh(&vscsi->intr_lock);
2736 spin_unlock_bh(&vscsi->intr_lock);
2738 switch (cmd->type) {
2740 ibmvscsis_parse_cmd(vscsi, cmd);
2742 case TASK_MANAGEMENT:
2743 ibmvscsis_parse_task(vscsi, cmd);
2746 dev_err(&vscsi->dev, "scheduler, invalid cmd type %d\n",
2748 spin_lock_bh(&vscsi->intr_lock);
2749 ibmvscsis_free_cmd_resources(vscsi, cmd);
2750 spin_unlock_bh(&vscsi->intr_lock);
2755 static int ibmvscsis_alloc_cmds(struct scsi_info *vscsi, int num)
2757 struct ibmvscsis_cmd *cmd;
2760 INIT_LIST_HEAD(&vscsi->free_cmd);
2761 vscsi->cmd_pool = kcalloc(num, sizeof(struct ibmvscsis_cmd),
2763 if (!vscsi->cmd_pool)
2766 for (i = 0, cmd = (struct ibmvscsis_cmd *)vscsi->cmd_pool; i < num;
2768 cmd->abort_cmd = NULL;
2769 cmd->adapter = vscsi;
2770 INIT_WORK(&cmd->work, ibmvscsis_scheduler);
2771 list_add_tail(&cmd->list, &vscsi->free_cmd);
2777 static void ibmvscsis_free_cmds(struct scsi_info *vscsi)
2779 kfree(vscsi->cmd_pool);
2780 vscsi->cmd_pool = NULL;
2781 INIT_LIST_HEAD(&vscsi->free_cmd);
2785 * ibmvscsis_service_wait_q() - Service Waiting Queue
2786 * @timer: Pointer to timer which has expired
2788 * This routine is called when the timer pops to service the waiting
2789 * queue. Elements on the queue have completed, their responses have been
2790 * copied to the client, but the client's response queue was full so
2791 * the queue message could not be sent. The routine grabs the proper locks
2792 * and calls send messages.
2794 * EXECUTION ENVIRONMENT:
2795 * called at interrupt level
2797 static enum hrtimer_restart ibmvscsis_service_wait_q(struct hrtimer *timer)
2799 struct timer_cb *p_timer = container_of(timer, struct timer_cb, timer);
2800 struct scsi_info *vscsi = container_of(p_timer, struct scsi_info,
2803 spin_lock_bh(&vscsi->intr_lock);
2804 p_timer->timer_pops += 1;
2805 p_timer->started = false;
2806 ibmvscsis_send_messages(vscsi);
2807 spin_unlock_bh(&vscsi->intr_lock);
2809 return HRTIMER_NORESTART;
2812 static long ibmvscsis_alloctimer(struct scsi_info *vscsi)
2814 struct timer_cb *p_timer;
2816 p_timer = &vscsi->rsp_q_timer;
2817 hrtimer_init(&p_timer->timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
2819 p_timer->timer.function = ibmvscsis_service_wait_q;
2820 p_timer->started = false;
2821 p_timer->timer_pops = 0;
2823 return ADAPT_SUCCESS;
2826 static void ibmvscsis_freetimer(struct scsi_info *vscsi)
2828 struct timer_cb *p_timer;
2830 p_timer = &vscsi->rsp_q_timer;
2832 (void)hrtimer_cancel(&p_timer->timer);
2834 p_timer->started = false;
2835 p_timer->timer_pops = 0;
2838 static irqreturn_t ibmvscsis_interrupt(int dummy, void *data)
2840 struct scsi_info *vscsi = data;
2842 vio_disable_interrupts(vscsi->dma_dev);
2843 tasklet_schedule(&vscsi->work_task);
2849 * ibmvscsis_enable_change_state() - Set new state based on enabled status
2850 * @vscsi: Pointer to our adapter structure
2852 * This function determines our new state now that we are enabled. This
2853 * may involve sending an Init Complete message to the client.
2855 * Must be called with interrupt lock held.
2857 static long ibmvscsis_enable_change_state(struct scsi_info *vscsi)
2860 long rc = ADAPT_SUCCESS;
2862 bytes = vscsi->cmd_q.size * PAGE_SIZE;
2863 rc = h_reg_crq(vscsi->dds.unit_id, vscsi->cmd_q.crq_token, bytes);
2864 if (rc == H_CLOSED || rc == H_SUCCESS) {
2865 vscsi->state = WAIT_CONNECTION;
2866 rc = ibmvscsis_establish_new_q(vscsi);
2869 if (rc != ADAPT_SUCCESS) {
2870 vscsi->state = ERR_DISCONNECTED;
2871 vscsi->flags |= RESPONSE_Q_DOWN;
2878 * ibmvscsis_create_command_q() - Create Command Queue
2879 * @vscsi: Pointer to our adapter structure
2880 * @num_cmds: Currently unused. In the future, may be used to determine
2881 * the size of the CRQ.
2883 * Allocates memory for command queue maps remote memory into an ioba
2884 * initializes the command response queue
2886 * EXECUTION ENVIRONMENT:
2887 * Process level only
2889 static long ibmvscsis_create_command_q(struct scsi_info *vscsi, int num_cmds)
2892 struct vio_dev *vdev = vscsi->dma_dev;
2894 /* We might support multiple pages in the future, but just 1 for now */
2897 vscsi->cmd_q.size = pages;
2899 vscsi->cmd_q.base_addr =
2900 (struct viosrp_crq *)get_zeroed_page(GFP_KERNEL);
2901 if (!vscsi->cmd_q.base_addr)
2904 vscsi->cmd_q.mask = ((uint)pages * CRQ_PER_PAGE) - 1;
2906 vscsi->cmd_q.crq_token = dma_map_single(&vdev->dev,
2907 vscsi->cmd_q.base_addr,
2908 PAGE_SIZE, DMA_BIDIRECTIONAL);
2909 if (dma_mapping_error(&vdev->dev, vscsi->cmd_q.crq_token)) {
2910 free_page((unsigned long)vscsi->cmd_q.base_addr);
2918 * ibmvscsis_destroy_command_q - Destroy Command Queue
2919 * @vscsi: Pointer to our adapter structure
2921 * Releases memory for command queue and unmaps mapped remote memory.
2923 * EXECUTION ENVIRONMENT:
2924 * Process level only
2926 static void ibmvscsis_destroy_command_q(struct scsi_info *vscsi)
2928 dma_unmap_single(&vscsi->dma_dev->dev, vscsi->cmd_q.crq_token,
2929 PAGE_SIZE, DMA_BIDIRECTIONAL);
2930 free_page((unsigned long)vscsi->cmd_q.base_addr);
2931 vscsi->cmd_q.base_addr = NULL;
2932 vscsi->state = NO_QUEUE;
2935 static u8 ibmvscsis_fast_fail(struct scsi_info *vscsi,
2936 struct ibmvscsis_cmd *cmd)
2938 struct iu_entry *iue = cmd->iue;
2939 struct se_cmd *se_cmd = &cmd->se_cmd;
2940 struct srp_cmd *srp = (struct srp_cmd *)iue->sbuf->buf;
2941 struct scsi_sense_hdr sshdr;
2942 u8 rc = se_cmd->scsi_status;
2944 if (vscsi->fast_fail && (READ_CMD(srp->cdb) || WRITE_CMD(srp->cdb)))
2945 if (scsi_normalize_sense(se_cmd->sense_buffer,
2946 se_cmd->scsi_sense_length, &sshdr))
2947 if (sshdr.sense_key == HARDWARE_ERROR &&
2948 (se_cmd->residual_count == 0 ||
2949 se_cmd->residual_count == se_cmd->data_length)) {
2951 cmd->flags |= CMD_FAST_FAIL;
2958 * srp_build_response() - Build an SRP response buffer
2959 * @vscsi: Pointer to our adapter structure
2960 * @cmd: Pointer to command for which to send the response
2961 * @len_p: Where to return the length of the IU response sent. This
2962 * is needed to construct the CRQ response.
2964 * Build the SRP response buffer and copy it to the client's memory space.
2966 static long srp_build_response(struct scsi_info *vscsi,
2967 struct ibmvscsis_cmd *cmd, uint *len_p)
2969 struct iu_entry *iue = cmd->iue;
2970 struct se_cmd *se_cmd = &cmd->se_cmd;
2971 struct srp_rsp *rsp;
2976 long rc = ADAPT_SUCCESS;
2978 spin_lock_bh(&vscsi->intr_lock);
2980 rsp = &vio_iu(iue)->srp.rsp;
2982 memset(rsp, 0, len);
2985 rsp->opcode = SRP_RSP;
2987 rsp->req_lim_delta = cpu_to_be32(1 + vscsi->credit);
2988 rsp->tag = cmd->rsp.tag;
2991 if (cmd->type == SCSI_CDB) {
2992 rsp->status = ibmvscsis_fast_fail(vscsi, cmd);
2994 pr_debug("build_resp: cmd %p, scsi status %d\n", cmd,
2996 ibmvscsis_determine_resid(se_cmd, rsp);
2997 if (se_cmd->scsi_sense_length && se_cmd->sense_buffer) {
2998 rsp->sense_data_len =
2999 cpu_to_be32(se_cmd->scsi_sense_length);
3000 rsp->flags |= SRP_RSP_FLAG_SNSVALID;
3001 len += se_cmd->scsi_sense_length;
3002 memcpy(data, se_cmd->sense_buffer,
3003 se_cmd->scsi_sense_length);
3005 rsp->sol_not = (cmd->rsp.sol_not & UCSOLNT) >>
3007 } else if (cmd->flags & CMD_FAST_FAIL) {
3008 pr_debug("build_resp: cmd %p, fast fail\n", cmd);
3009 rsp->sol_not = (cmd->rsp.sol_not & UCSOLNT) >>
3012 rsp->sol_not = (cmd->rsp.sol_not & SCSOLNT) >>
3016 /* this is task management */
3018 rsp->resp_data_len = cpu_to_be32(4);
3019 rsp->flags |= SRP_RSP_FLAG_RSPVALID;
3021 switch (se_cmd->se_tmr_req->response) {
3022 case TMR_FUNCTION_COMPLETE:
3023 case TMR_TASK_DOES_NOT_EXIST:
3024 rsp_code = SRP_TASK_MANAGEMENT_FUNCTION_COMPLETE;
3025 rsp->sol_not = (cmd->rsp.sol_not & SCSOLNT) >>
3028 case TMR_TASK_MGMT_FUNCTION_NOT_SUPPORTED:
3029 case TMR_LUN_DOES_NOT_EXIST:
3030 rsp_code = SRP_TASK_MANAGEMENT_FUNCTION_NOT_SUPPORTED;
3031 rsp->sol_not = (cmd->rsp.sol_not & UCSOLNT) >>
3034 case TMR_FUNCTION_FAILED:
3035 case TMR_FUNCTION_REJECTED:
3037 rsp_code = SRP_TASK_MANAGEMENT_FUNCTION_FAILED;
3038 rsp->sol_not = (cmd->rsp.sol_not & UCSOLNT) >>
3043 tsk_status = (u32 *)data;
3044 *tsk_status = cpu_to_be32(rsp_code);
3045 data = (char *)(tsk_status + 1);
3050 rc = h_copy_rdma(len, vscsi->dds.window[LOCAL].liobn, iue->sbuf->dma,
3051 vscsi->dds.window[REMOTE].liobn,
3052 be64_to_cpu(iue->remote_token));
3060 if (connection_broken(vscsi))
3061 vscsi->flags |= RESPONSE_Q_DOWN | CLIENT_FAILED;
3063 dev_err(&vscsi->dev, "build_response: error copying to client, rc %ld, flags 0x%x, state 0x%hx\n",
3064 rc, vscsi->flags, vscsi->state);
3069 dev_err(&vscsi->dev, "build_response: error copying to client, rc %ld\n",
3074 spin_unlock_bh(&vscsi->intr_lock);
3079 static int ibmvscsis_rdma(struct ibmvscsis_cmd *cmd, struct scatterlist *sg,
3080 int nsg, struct srp_direct_buf *md, int nmd,
3081 enum dma_data_direction dir, unsigned int bytes)
3083 struct iu_entry *iue = cmd->iue;
3084 struct srp_target *target = iue->target;
3085 struct scsi_info *vscsi = target->ldata;
3086 struct scatterlist *sgp;
3087 dma_addr_t client_ioba, server_ioba;
3089 ulong client_len, server_len;
3104 if (client_len == 0) {
3105 if (md_idx >= nmd) {
3106 dev_err(&vscsi->dev, "rdma: ran out of client memory descriptors\n");
3110 client_ioba = be64_to_cpu(md[md_idx].va);
3111 client_len = be32_to_cpu(md[md_idx].len);
3113 if (server_len == 0) {
3115 dev_err(&vscsi->dev, "rdma: ran out of scatter/gather list\n");
3119 server_ioba = sg_dma_address(sgp);
3120 server_len = sg_dma_len(sgp);
3125 if (buf_len > client_len)
3126 buf_len = client_len;
3128 if (buf_len > server_len)
3129 buf_len = server_len;
3131 if (buf_len > max_vdma_size)
3132 buf_len = max_vdma_size;
3134 if (dir == DMA_TO_DEVICE) {
3135 /* read from client */
3136 rc = h_copy_rdma(buf_len,
3137 vscsi->dds.window[REMOTE].liobn,
3139 vscsi->dds.window[LOCAL].liobn,
3142 /* The h_copy_rdma will cause phyp, running in another
3143 * partition, to read memory, so we need to make sure
3144 * the data has been written out, hence these syncs.
3146 /* ensure that everything is in memory */
3148 /* ensure that memory has been made visible */
3150 rc = h_copy_rdma(buf_len,
3151 vscsi->dds.window[LOCAL].liobn,
3153 vscsi->dds.window[REMOTE].liobn,
3162 if (connection_broken(vscsi)) {
3163 spin_lock_bh(&vscsi->intr_lock);
3165 (RESPONSE_Q_DOWN | CLIENT_FAILED);
3166 spin_unlock_bh(&vscsi->intr_lock);
3168 dev_err(&vscsi->dev, "rdma: h_copy_rdma failed, rc %ld\n",
3173 dev_err(&vscsi->dev, "rdma: unknown error %ld from h_copy_rdma\n",
3181 client_len -= buf_len;
3182 if (client_len == 0)
3185 client_ioba += buf_len;
3187 server_len -= buf_len;
3188 if (server_len == 0)
3191 server_ioba += buf_len;
3202 * ibmvscsis_handle_crq() - Handle CRQ
3203 * @data: Pointer to our adapter structure
3205 * Read the command elements from the command queue and copy the payloads
3206 * associated with the command elements to local memory and execute the
3209 * Note: this is an edge triggered interrupt. It can not be shared.
3211 static void ibmvscsis_handle_crq(unsigned long data)
3213 struct scsi_info *vscsi = (struct scsi_info *)data;
3214 struct viosrp_crq *crq;
3219 spin_lock_bh(&vscsi->intr_lock);
3221 pr_debug("got interrupt\n");
3224 * if we are in a path where we are waiting for all pending commands
3225 * to complete because we received a transport event and anything in
3226 * the command queue is for a new connection, do nothing
3228 if (TARGET_STOP(vscsi)) {
3229 vio_enable_interrupts(vscsi->dma_dev);
3231 pr_debug("handle_crq, don't process: flags 0x%x, state 0x%hx\n",
3232 vscsi->flags, vscsi->state);
3233 spin_unlock_bh(&vscsi->intr_lock);
3237 rc = vscsi->flags & SCHEDULE_DISCONNECT;
3238 crq = vscsi->cmd_q.base_addr + vscsi->cmd_q.index;
3244 * These are edege triggered interrupts. After dropping out of
3245 * the while loop, the code must check for work since an
3246 * interrupt could be lost, and an elment be left on the queue,
3250 vscsi->cmd_q.index =
3251 (vscsi->cmd_q.index + 1) & vscsi->cmd_q.mask;
3254 rc = ibmvscsis_parse_command(vscsi, crq);
3256 if ((uint)crq->valid == VALID_TRANS_EVENT) {
3258 * must service the transport layer events even
3259 * in an error state, dont break out until all
3260 * the consecutive transport events have been
3263 rc = ibmvscsis_trans_event(vscsi, crq);
3264 } else if (vscsi->flags & TRANS_EVENT) {
3266 * if a transport event has occurred leave
3267 * everything but transport events on the queue
3269 * need to decrement the queue index so we can
3270 * look at the element again
3272 if (vscsi->cmd_q.index)
3273 vscsi->cmd_q.index -= 1;
3276 * index is at 0 it just wrapped.
3277 * have it index last element in q
3279 vscsi->cmd_q.index = vscsi->cmd_q.mask;
3284 crq->valid = INVALIDATE_CMD_RESP_EL;
3286 crq = vscsi->cmd_q.base_addr + vscsi->cmd_q.index;
3293 vio_enable_interrupts(vscsi->dma_dev);
3295 pr_debug("handle_crq, reenabling interrupts\n");
3302 pr_debug("handle_crq, error: flags 0x%x, state 0x%hx, crq index 0x%x\n",
3303 vscsi->flags, vscsi->state, vscsi->cmd_q.index);
3306 pr_debug("Leaving handle_crq: schedule_q empty %d, flags 0x%x, state 0x%hx\n",
3307 (int)list_empty(&vscsi->schedule_q), vscsi->flags,
3310 spin_unlock_bh(&vscsi->intr_lock);
3313 static int ibmvscsis_probe(struct vio_dev *vdev,
3314 const struct vio_device_id *id)
3316 struct scsi_info *vscsi;
3321 vscsi = kzalloc(sizeof(*vscsi), GFP_KERNEL);
3324 pr_err("probe: allocation of adapter failed\n");
3328 vscsi->dma_dev = vdev;
3329 vscsi->dev = vdev->dev;
3330 INIT_LIST_HEAD(&vscsi->schedule_q);
3331 INIT_LIST_HEAD(&vscsi->waiting_rsp);
3332 INIT_LIST_HEAD(&vscsi->active_q);
3334 snprintf(vscsi->tport.tport_name, IBMVSCSIS_NAMELEN, "%s",
3335 dev_name(&vdev->dev));
3337 pr_debug("probe tport_name: %s\n", vscsi->tport.tport_name);
3339 rc = read_dma_window(vscsi);
3342 pr_debug("Probe: liobn 0x%x, riobn 0x%x\n",
3343 vscsi->dds.window[LOCAL].liobn,
3344 vscsi->dds.window[REMOTE].liobn);
3346 strcpy(vscsi->eye, "VSCSI ");
3347 strncat(vscsi->eye, vdev->name, MAX_EYE);
3349 vscsi->dds.unit_id = vdev->unit_address;
3350 strncpy(vscsi->dds.partition_name, partition_name,
3351 sizeof(vscsi->dds.partition_name));
3352 vscsi->dds.partition_num = partition_number;
3354 spin_lock_bh(&ibmvscsis_dev_lock);
3355 list_add_tail(&vscsi->list, &ibmvscsis_dev_list);
3356 spin_unlock_bh(&ibmvscsis_dev_lock);
3359 * TBD: How do we determine # of cmds to request? Do we know how
3360 * many "children" we have?
3362 vscsi->request_limit = INITIAL_SRP_LIMIT;
3363 rc = srp_target_alloc(&vscsi->target, &vdev->dev, vscsi->request_limit,
3368 vscsi->target.ldata = vscsi;
3370 rc = ibmvscsis_alloc_cmds(vscsi, vscsi->request_limit);
3372 dev_err(&vscsi->dev, "alloc_cmds failed, rc %d, num %d\n",
3373 rc, vscsi->request_limit);
3378 * Note: the lock is used in freeing timers, so must initialize
3379 * first so that ordering in case of error is correct.
3381 spin_lock_init(&vscsi->intr_lock);
3383 rc = ibmvscsis_alloctimer(vscsi);
3385 dev_err(&vscsi->dev, "probe: alloctimer failed, rc %d\n", rc);
3389 rc = ibmvscsis_create_command_q(vscsi, 256);
3391 dev_err(&vscsi->dev, "probe: create_command_q failed, rc %d\n",
3396 vscsi->map_buf = kzalloc(PAGE_SIZE, GFP_KERNEL);
3397 if (!vscsi->map_buf) {
3399 dev_err(&vscsi->dev, "probe: allocating cmd buffer failed\n");
3403 vscsi->map_ioba = dma_map_single(&vdev->dev, vscsi->map_buf, PAGE_SIZE,
3405 if (dma_mapping_error(&vdev->dev, vscsi->map_ioba)) {
3407 dev_err(&vscsi->dev, "probe: error mapping command buffer\n");
3411 hrc = h_vioctl(vscsi->dds.unit_id, H_GET_PARTNER_INFO,
3412 (u64)vscsi->map_ioba | ((u64)PAGE_SIZE << 32), 0, 0, 0,
3414 if (hrc == H_SUCCESS)
3415 vscsi->client_data.partition_number =
3416 be64_to_cpu(*(u64 *)vscsi->map_buf);
3418 * We expect the VIOCTL to fail if we're configured as "any
3419 * client can connect" and the client isn't activated yet.
3420 * We'll make the call again when he sends an init msg.
3422 pr_debug("probe hrc %ld, client partition num %d\n",
3423 hrc, vscsi->client_data.partition_number);
3425 tasklet_init(&vscsi->work_task, ibmvscsis_handle_crq,
3426 (unsigned long)vscsi);
3428 init_completion(&vscsi->wait_idle);
3429 init_completion(&vscsi->unconfig);
3431 snprintf(wq_name, 24, "ibmvscsis%s", dev_name(&vdev->dev));
3432 vscsi->work_q = create_workqueue(wq_name);
3433 if (!vscsi->work_q) {
3435 dev_err(&vscsi->dev, "create_workqueue failed\n");
3439 rc = request_irq(vdev->irq, ibmvscsis_interrupt, 0, "ibmvscsis", vscsi);
3442 dev_err(&vscsi->dev, "probe: request_irq failed, rc %d\n", rc);
3446 vscsi->state = WAIT_ENABLED;
3448 dev_set_drvdata(&vdev->dev, vscsi);
3453 destroy_workqueue(vscsi->work_q);
3455 dma_unmap_single(&vdev->dev, vscsi->map_ioba, PAGE_SIZE,
3458 kfree(vscsi->map_buf);
3460 tasklet_kill(&vscsi->work_task);
3461 ibmvscsis_unregister_command_q(vscsi);
3462 ibmvscsis_destroy_command_q(vscsi);
3464 ibmvscsis_freetimer(vscsi);
3466 ibmvscsis_free_cmds(vscsi);
3468 srp_target_free(&vscsi->target);
3470 spin_lock_bh(&ibmvscsis_dev_lock);
3471 list_del(&vscsi->list);
3472 spin_unlock_bh(&ibmvscsis_dev_lock);
3479 static int ibmvscsis_remove(struct vio_dev *vdev)
3481 struct scsi_info *vscsi = dev_get_drvdata(&vdev->dev);
3483 pr_debug("remove (%s)\n", dev_name(&vscsi->dma_dev->dev));
3485 spin_lock_bh(&vscsi->intr_lock);
3486 ibmvscsis_post_disconnect(vscsi, UNCONFIGURING, 0);
3487 vscsi->flags |= CFG_SLEEPING;
3488 spin_unlock_bh(&vscsi->intr_lock);
3489 wait_for_completion(&vscsi->unconfig);
3491 vio_disable_interrupts(vdev);
3492 free_irq(vdev->irq, vscsi);
3493 destroy_workqueue(vscsi->work_q);
3494 dma_unmap_single(&vdev->dev, vscsi->map_ioba, PAGE_SIZE,
3496 kfree(vscsi->map_buf);
3497 tasklet_kill(&vscsi->work_task);
3498 ibmvscsis_destroy_command_q(vscsi);
3499 ibmvscsis_freetimer(vscsi);
3500 ibmvscsis_free_cmds(vscsi);
3501 srp_target_free(&vscsi->target);
3502 spin_lock_bh(&ibmvscsis_dev_lock);
3503 list_del(&vscsi->list);
3504 spin_unlock_bh(&ibmvscsis_dev_lock);
3510 static ssize_t system_id_show(struct device *dev,
3511 struct device_attribute *attr, char *buf)
3513 return snprintf(buf, PAGE_SIZE, "%s\n", system_id);
3516 static ssize_t partition_number_show(struct device *dev,
3517 struct device_attribute *attr, char *buf)
3519 return snprintf(buf, PAGE_SIZE, "%x\n", partition_number);
3522 static ssize_t unit_address_show(struct device *dev,
3523 struct device_attribute *attr, char *buf)
3525 struct scsi_info *vscsi = container_of(dev, struct scsi_info, dev);
3527 return snprintf(buf, PAGE_SIZE, "%x\n", vscsi->dma_dev->unit_address);
3530 static int ibmvscsis_get_system_info(void)
3532 struct device_node *rootdn, *vdevdn;
3533 const char *id, *model, *name;
3536 rootdn = of_find_node_by_path("/");
3540 model = of_get_property(rootdn, "model", NULL);
3541 id = of_get_property(rootdn, "system-id", NULL);
3543 snprintf(system_id, sizeof(system_id), "%s-%s", model, id);
3545 name = of_get_property(rootdn, "ibm,partition-name", NULL);
3547 strncpy(partition_name, name, sizeof(partition_name));
3549 num = of_get_property(rootdn, "ibm,partition-no", NULL);
3551 partition_number = of_read_number(num, 1);
3553 of_node_put(rootdn);
3555 vdevdn = of_find_node_by_path("/vdevice");
3559 mvds = of_get_property(vdevdn, "ibm,max-virtual-dma-size",
3562 max_vdma_size = *mvds;
3563 of_node_put(vdevdn);
3569 static char *ibmvscsis_get_fabric_name(void)
3574 static char *ibmvscsis_get_fabric_wwn(struct se_portal_group *se_tpg)
3576 struct ibmvscsis_tport *tport =
3577 container_of(se_tpg, struct ibmvscsis_tport, se_tpg);
3579 return tport->tport_name;
3582 static u16 ibmvscsis_get_tag(struct se_portal_group *se_tpg)
3584 struct ibmvscsis_tport *tport =
3585 container_of(se_tpg, struct ibmvscsis_tport, se_tpg);
3587 return tport->tport_tpgt;
3590 static u32 ibmvscsis_get_default_depth(struct se_portal_group *se_tpg)
3595 static int ibmvscsis_check_true(struct se_portal_group *se_tpg)
3600 static int ibmvscsis_check_false(struct se_portal_group *se_tpg)
3605 static u32 ibmvscsis_tpg_get_inst_index(struct se_portal_group *se_tpg)
3610 static int ibmvscsis_check_stop_free(struct se_cmd *se_cmd)
3612 return target_put_sess_cmd(se_cmd);
3615 static void ibmvscsis_release_cmd(struct se_cmd *se_cmd)
3617 struct ibmvscsis_cmd *cmd = container_of(se_cmd, struct ibmvscsis_cmd,
3619 struct scsi_info *vscsi = cmd->adapter;
3621 spin_lock_bh(&vscsi->intr_lock);
3622 /* Remove from active_q */
3623 list_move_tail(&cmd->list, &vscsi->waiting_rsp);
3624 ibmvscsis_send_messages(vscsi);
3625 spin_unlock_bh(&vscsi->intr_lock);
3628 static u32 ibmvscsis_sess_get_index(struct se_session *se_sess)
3633 static int ibmvscsis_write_pending(struct se_cmd *se_cmd)
3635 struct ibmvscsis_cmd *cmd = container_of(se_cmd, struct ibmvscsis_cmd,
3637 struct scsi_info *vscsi = cmd->adapter;
3638 struct iu_entry *iue = cmd->iue;
3642 * If CLIENT_FAILED OR RESPONSE_Q_DOWN, then just return success
3643 * since LIO can't do anything about it, and we dont want to
3644 * attempt an srp_transfer_data.
3646 if ((vscsi->flags & (CLIENT_FAILED | RESPONSE_Q_DOWN))) {
3647 pr_err("write_pending failed since: %d\n", vscsi->flags);
3651 rc = srp_transfer_data(cmd, &vio_iu(iue)->srp.cmd, ibmvscsis_rdma,
3654 pr_err("srp_transfer_data() failed: %d\n", rc);
3658 * We now tell TCM to add this WRITE CDB directly into the TCM storage
3659 * object execution queue.
3661 target_execute_cmd(se_cmd);
3665 static int ibmvscsis_write_pending_status(struct se_cmd *se_cmd)
3670 static void ibmvscsis_set_default_node_attrs(struct se_node_acl *nacl)
3674 static int ibmvscsis_get_cmd_state(struct se_cmd *se_cmd)
3679 static int ibmvscsis_queue_data_in(struct se_cmd *se_cmd)
3681 struct ibmvscsis_cmd *cmd = container_of(se_cmd, struct ibmvscsis_cmd,
3683 struct iu_entry *iue = cmd->iue;
3684 struct scsi_info *vscsi = cmd->adapter;
3689 rc = srp_transfer_data(cmd, &vio_iu(iue)->srp.cmd, ibmvscsis_rdma, 1,
3692 pr_err("srp_transfer_data failed: %d\n", rc);
3693 sd = se_cmd->sense_buffer;
3694 se_cmd->scsi_sense_length = 18;
3695 memset(se_cmd->sense_buffer, 0, se_cmd->scsi_sense_length);
3696 /* Logical Unit Communication Time-out asc/ascq = 0x0801 */
3697 scsi_build_sense_buffer(0, se_cmd->sense_buffer, MEDIUM_ERROR,
3701 srp_build_response(vscsi, cmd, &len);
3702 cmd->rsp.format = SRP_FORMAT;
3708 static int ibmvscsis_queue_status(struct se_cmd *se_cmd)
3710 struct ibmvscsis_cmd *cmd = container_of(se_cmd, struct ibmvscsis_cmd,
3712 struct scsi_info *vscsi = cmd->adapter;
3715 pr_debug("queue_status %p\n", se_cmd);
3717 srp_build_response(vscsi, cmd, &len);
3718 cmd->rsp.format = SRP_FORMAT;
3724 static void ibmvscsis_queue_tm_rsp(struct se_cmd *se_cmd)
3726 struct ibmvscsis_cmd *cmd = container_of(se_cmd, struct ibmvscsis_cmd,
3728 struct scsi_info *vscsi = cmd->adapter;
3729 struct ibmvscsis_cmd *cmd_itr;
3730 struct iu_entry *iue = iue = cmd->iue;
3731 struct srp_tsk_mgmt *srp_tsk = &vio_iu(iue)->srp.tsk_mgmt;
3732 u64 tag_to_abort = be64_to_cpu(srp_tsk->task_tag);
3735 pr_debug("queue_tm_rsp %p, status %d\n",
3736 se_cmd, (int)se_cmd->se_tmr_req->response);
3738 if (srp_tsk->tsk_mgmt_func == SRP_TSK_ABORT_TASK &&
3739 cmd->se_cmd.se_tmr_req->response == TMR_TASK_DOES_NOT_EXIST) {
3740 spin_lock_bh(&vscsi->intr_lock);
3741 list_for_each_entry(cmd_itr, &vscsi->active_q, list) {
3742 if (tag_to_abort == cmd_itr->se_cmd.tag) {
3743 cmd_itr->abort_cmd = cmd;
3744 cmd->flags |= DELAY_SEND;
3748 spin_unlock_bh(&vscsi->intr_lock);
3751 srp_build_response(vscsi, cmd, &len);
3752 cmd->rsp.format = SRP_FORMAT;
3756 static void ibmvscsis_aborted_task(struct se_cmd *se_cmd)
3758 pr_debug("ibmvscsis_aborted_task %p task_tag: %llu\n",
3759 se_cmd, se_cmd->tag);
3762 static struct se_wwn *ibmvscsis_make_tport(struct target_fabric_configfs *tf,
3763 struct config_group *group,
3766 struct ibmvscsis_tport *tport;
3768 tport = ibmvscsis_lookup_port(name);
3770 tport->tport_proto_id = SCSI_PROTOCOL_SRP;
3771 pr_debug("make_tport(%s), pointer:%p, tport_id:%x\n",
3772 name, tport, tport->tport_proto_id);
3773 return &tport->tport_wwn;
3776 return ERR_PTR(-EINVAL);
3779 static void ibmvscsis_drop_tport(struct se_wwn *wwn)
3781 struct ibmvscsis_tport *tport = container_of(wwn,
3782 struct ibmvscsis_tport,
3785 pr_debug("drop_tport(%s)\n",
3786 config_item_name(&tport->tport_wwn.wwn_group.cg_item));
3789 static struct se_portal_group *ibmvscsis_make_tpg(struct se_wwn *wwn,
3790 struct config_group *group,
3793 struct ibmvscsis_tport *tport =
3794 container_of(wwn, struct ibmvscsis_tport, tport_wwn);
3797 tport->releasing = false;
3799 rc = core_tpg_register(&tport->tport_wwn, &tport->se_tpg,
3800 tport->tport_proto_id);
3804 return &tport->se_tpg;
3807 static void ibmvscsis_drop_tpg(struct se_portal_group *se_tpg)
3809 struct ibmvscsis_tport *tport = container_of(se_tpg,
3810 struct ibmvscsis_tport,
3813 tport->releasing = true;
3814 tport->enabled = false;
3817 * Release the virtual I_T Nexus for this ibmvscsis TPG
3819 ibmvscsis_drop_nexus(tport);
3821 * Deregister the se_tpg from TCM..
3823 core_tpg_deregister(se_tpg);
3826 static ssize_t ibmvscsis_wwn_version_show(struct config_item *item,
3829 return scnprintf(page, PAGE_SIZE, "%s\n", IBMVSCSIS_VERSION);
3831 CONFIGFS_ATTR_RO(ibmvscsis_wwn_, version);
3833 static struct configfs_attribute *ibmvscsis_wwn_attrs[] = {
3834 &ibmvscsis_wwn_attr_version,
3838 static ssize_t ibmvscsis_tpg_enable_show(struct config_item *item,
3841 struct se_portal_group *se_tpg = to_tpg(item);
3842 struct ibmvscsis_tport *tport = container_of(se_tpg,
3843 struct ibmvscsis_tport,
3846 return snprintf(page, PAGE_SIZE, "%d\n", (tport->enabled) ? 1 : 0);
3849 static ssize_t ibmvscsis_tpg_enable_store(struct config_item *item,
3850 const char *page, size_t count)
3852 struct se_portal_group *se_tpg = to_tpg(item);
3853 struct ibmvscsis_tport *tport = container_of(se_tpg,
3854 struct ibmvscsis_tport,
3856 struct scsi_info *vscsi = container_of(tport, struct scsi_info, tport);
3861 rc = kstrtoul(page, 0, &tmp);
3863 pr_err("Unable to extract srpt_tpg_store_enable\n");
3867 if ((tmp != 0) && (tmp != 1)) {
3868 pr_err("Illegal value for srpt_tpg_store_enable\n");
3873 spin_lock_bh(&vscsi->intr_lock);
3874 tport->enabled = true;
3875 lrc = ibmvscsis_enable_change_state(vscsi);
3877 pr_err("enable_change_state failed, rc %ld state %d\n",
3879 spin_unlock_bh(&vscsi->intr_lock);
3881 spin_lock_bh(&vscsi->intr_lock);
3882 tport->enabled = false;
3883 /* This simulates the server going down */
3884 ibmvscsis_post_disconnect(vscsi, ERR_DISCONNECT, 0);
3885 spin_unlock_bh(&vscsi->intr_lock);
3888 pr_debug("tpg_enable_store, tmp %ld, state %d\n", tmp, vscsi->state);
3892 CONFIGFS_ATTR(ibmvscsis_tpg_, enable);
3894 static struct configfs_attribute *ibmvscsis_tpg_attrs[] = {
3895 &ibmvscsis_tpg_attr_enable,
3899 static const struct target_core_fabric_ops ibmvscsis_ops = {
3900 .module = THIS_MODULE,
3901 .name = "ibmvscsis",
3902 .max_data_sg_nents = MAX_TXU / PAGE_SIZE,
3903 .get_fabric_name = ibmvscsis_get_fabric_name,
3904 .tpg_get_wwn = ibmvscsis_get_fabric_wwn,
3905 .tpg_get_tag = ibmvscsis_get_tag,
3906 .tpg_get_default_depth = ibmvscsis_get_default_depth,
3907 .tpg_check_demo_mode = ibmvscsis_check_true,
3908 .tpg_check_demo_mode_cache = ibmvscsis_check_true,
3909 .tpg_check_demo_mode_write_protect = ibmvscsis_check_false,
3910 .tpg_check_prod_mode_write_protect = ibmvscsis_check_false,
3911 .tpg_get_inst_index = ibmvscsis_tpg_get_inst_index,
3912 .check_stop_free = ibmvscsis_check_stop_free,
3913 .release_cmd = ibmvscsis_release_cmd,
3914 .sess_get_index = ibmvscsis_sess_get_index,
3915 .write_pending = ibmvscsis_write_pending,
3916 .write_pending_status = ibmvscsis_write_pending_status,
3917 .set_default_node_attributes = ibmvscsis_set_default_node_attrs,
3918 .get_cmd_state = ibmvscsis_get_cmd_state,
3919 .queue_data_in = ibmvscsis_queue_data_in,
3920 .queue_status = ibmvscsis_queue_status,
3921 .queue_tm_rsp = ibmvscsis_queue_tm_rsp,
3922 .aborted_task = ibmvscsis_aborted_task,
3924 * Setup function pointers for logic in target_core_fabric_configfs.c
3926 .fabric_make_wwn = ibmvscsis_make_tport,
3927 .fabric_drop_wwn = ibmvscsis_drop_tport,
3928 .fabric_make_tpg = ibmvscsis_make_tpg,
3929 .fabric_drop_tpg = ibmvscsis_drop_tpg,
3931 .tfc_wwn_attrs = ibmvscsis_wwn_attrs,
3932 .tfc_tpg_base_attrs = ibmvscsis_tpg_attrs,
3935 static void ibmvscsis_dev_release(struct device *dev) {};
3937 static struct class_attribute ibmvscsis_class_attrs[] = {
3941 static struct device_attribute dev_attr_system_id =
3942 __ATTR(system_id, S_IRUGO, system_id_show, NULL);
3944 static struct device_attribute dev_attr_partition_number =
3945 __ATTR(partition_number, S_IRUGO, partition_number_show, NULL);
3947 static struct device_attribute dev_attr_unit_address =
3948 __ATTR(unit_address, S_IRUGO, unit_address_show, NULL);
3950 static struct attribute *ibmvscsis_dev_attrs[] = {
3951 &dev_attr_system_id.attr,
3952 &dev_attr_partition_number.attr,
3953 &dev_attr_unit_address.attr,
3955 ATTRIBUTE_GROUPS(ibmvscsis_dev);
3957 static struct class ibmvscsis_class = {
3958 .name = "ibmvscsis",
3959 .dev_release = ibmvscsis_dev_release,
3960 .class_attrs = ibmvscsis_class_attrs,
3961 .dev_groups = ibmvscsis_dev_groups,
3964 static struct vio_device_id ibmvscsis_device_table[] = {
3965 { "v-scsi-host", "IBM,v-scsi-host" },
3968 MODULE_DEVICE_TABLE(vio, ibmvscsis_device_table);
3970 static struct vio_driver ibmvscsis_driver = {
3971 .name = "ibmvscsis",
3972 .id_table = ibmvscsis_device_table,
3973 .probe = ibmvscsis_probe,
3974 .remove = ibmvscsis_remove,
3978 * ibmvscsis_init() - Kernel Module initialization
3980 * Note: vio_register_driver() registers callback functions, and at least one
3981 * of those callback functions calls TCM - Linux IO Target Subsystem, thus
3982 * the SCSI Target template must be registered before vio_register_driver()
3985 static int __init ibmvscsis_init(void)
3989 rc = ibmvscsis_get_system_info();
3991 pr_err("rc %d from get_system_info\n", rc);
3995 rc = class_register(&ibmvscsis_class);
3997 pr_err("failed class register\n");
4001 rc = target_register_template(&ibmvscsis_ops);
4003 pr_err("rc %d from target_register_template\n", rc);
4004 goto unregister_class;
4007 rc = vio_register_driver(&ibmvscsis_driver);
4009 pr_err("rc %d from vio_register_driver\n", rc);
4010 goto unregister_target;
4016 target_unregister_template(&ibmvscsis_ops);
4018 class_unregister(&ibmvscsis_class);
4023 static void __exit ibmvscsis_exit(void)
4025 pr_info("Unregister IBM virtual SCSI host driver\n");
4026 vio_unregister_driver(&ibmvscsis_driver);
4027 target_unregister_template(&ibmvscsis_ops);
4028 class_unregister(&ibmvscsis_class);
4031 MODULE_DESCRIPTION("IBMVSCSIS fabric driver");
4032 MODULE_AUTHOR("Bryant G. Ly and Michael Cyr");
4033 MODULE_LICENSE("GPL");
4034 MODULE_VERSION(IBMVSCSIS_VERSION);
4035 module_init(ibmvscsis_init);
4036 module_exit(ibmvscsis_exit);