| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* ------------------------------------------------------------ | 
|  | 2 | * iSeries_vscsi.c | 
|  | 3 | * (C) Copyright IBM Corporation 1994, 2003 | 
|  | 4 | * Authors: Colin DeVilbiss (devilbis@us.ibm.com) | 
|  | 5 | *          Santiago Leon (santil@us.ibm.com) | 
|  | 6 | *          Dave Boutcher (sleddog@us.ibm.com) | 
|  | 7 | * | 
|  | 8 | * This program is free software; you can redistribute it and/or modify | 
|  | 9 | * it under the terms of the GNU General Public License as published by | 
|  | 10 | * the Free Software Foundation; either version 2 of the License, or | 
|  | 11 | * (at your option) any later version. | 
|  | 12 | * | 
|  | 13 | * This program is distributed in the hope that it will be useful, | 
|  | 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | 
|  | 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
|  | 16 | * GNU General Public License for more details. | 
|  | 17 | * | 
|  | 18 | * You should have received a copy of the GNU General Public License | 
|  | 19 | * along with this program; if not, write to the Free Software | 
|  | 20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 | 
|  | 21 | * USA | 
|  | 22 | * | 
|  | 23 | * ------------------------------------------------------------ | 
|  | 24 | * iSeries-specific functions of the SCSI host adapter for Virtual I/O devices | 
|  | 25 | * | 
|  | 26 | * This driver allows the Linux SCSI peripheral drivers to directly | 
|  | 27 | * access devices in the hosting partition, either on an iSeries | 
|  | 28 | * hypervisor system or a converged hypervisor system. | 
|  | 29 | */ | 
|  | 30 |  | 
| Kelly Daly | b420677 | 2005-11-02 15:13:57 +1100 | [diff] [blame] | 31 | #include <asm/iseries/vio.h> | 
| Kelly Daly | e45423e | 2005-11-02 12:08:31 +1100 | [diff] [blame] | 32 | #include <asm/iseries/hv_lp_event.h> | 
| Kelly Daly | 1ec65d7 | 2005-11-02 13:46:07 +1100 | [diff] [blame] | 33 | #include <asm/iseries/hv_types.h> | 
| Kelly Daly | 15b1718 | 2005-11-02 11:55:28 +1100 | [diff] [blame] | 34 | #include <asm/iseries/hv_lp_config.h> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | #include <asm/vio.h> | 
|  | 36 | #include <linux/device.h> | 
|  | 37 | #include "ibmvscsi.h" | 
|  | 38 |  | 
|  | 39 | /* global variables */ | 
|  | 40 | static struct ibmvscsi_host_data *single_host_data; | 
|  | 41 |  | 
|  | 42 | /* ------------------------------------------------------------ | 
|  | 43 | * Routines for direct interpartition interaction | 
|  | 44 | */ | 
|  | 45 | struct srp_lp_event { | 
|  | 46 | struct HvLpEvent lpevt;	/* 0x00-0x17          */ | 
|  | 47 | u32 reserved1;		/* 0x18-0x1B; unused  */ | 
|  | 48 | u16 version;		/* 0x1C-0x1D; unused  */ | 
|  | 49 | u16 subtype_rc;		/* 0x1E-0x1F; unused  */ | 
|  | 50 | struct viosrp_crq crq;	/* 0x20-0x3F          */ | 
|  | 51 | }; | 
|  | 52 |  | 
|  | 53 | /** | 
|  | 54 | * standard interface for handling logical partition events. | 
|  | 55 | */ | 
| David Woodhouse | d3849d5 | 2007-09-22 08:29:36 +1000 | [diff] [blame] | 56 | static void iseriesvscsi_handle_event(struct HvLpEvent *lpevt) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | { | 
|  | 58 | struct srp_lp_event *evt = (struct srp_lp_event *)lpevt; | 
|  | 59 |  | 
|  | 60 | if (!evt) { | 
|  | 61 | printk(KERN_ERR "ibmvscsi: received null event\n"); | 
|  | 62 | return; | 
|  | 63 | } | 
|  | 64 |  | 
|  | 65 | if (single_host_data == NULL) { | 
|  | 66 | printk(KERN_ERR | 
|  | 67 | "ibmvscsi: received event, no adapter present\n"); | 
|  | 68 | return; | 
|  | 69 | } | 
|  | 70 |  | 
|  | 71 | ibmvscsi_handle_crq(&evt->crq, single_host_data); | 
|  | 72 | } | 
|  | 73 |  | 
|  | 74 | /* ------------------------------------------------------------ | 
|  | 75 | * Routines for driver initialization | 
|  | 76 | */ | 
| David Woodhouse | d3849d5 | 2007-09-22 08:29:36 +1000 | [diff] [blame] | 77 | static int iseriesvscsi_init_crq_queue(struct crq_queue *queue, | 
|  | 78 | struct ibmvscsi_host_data *hostdata, | 
|  | 79 | int max_requests) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | { | 
|  | 81 | int rc; | 
|  | 82 |  | 
|  | 83 | single_host_data = hostdata; | 
| Dave C Boutcher | 6c51fe1 | 2006-07-06 22:07:47 -0500 | [diff] [blame] | 84 | rc = viopath_open(viopath_hostLp, viomajorsubtype_scsi, max_requests); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | if (rc < 0) { | 
|  | 86 | printk("viopath_open failed with rc %d in open_event_path\n", | 
|  | 87 | rc); | 
|  | 88 | goto viopath_open_failed; | 
|  | 89 | } | 
|  | 90 |  | 
| David Woodhouse | d3849d5 | 2007-09-22 08:29:36 +1000 | [diff] [blame] | 91 | rc = vio_setHandler(viomajorsubtype_scsi, iseriesvscsi_handle_event); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 | if (rc < 0) { | 
|  | 93 | printk("vio_setHandler failed with rc %d in open_event_path\n", | 
|  | 94 | rc); | 
|  | 95 | goto vio_setHandler_failed; | 
|  | 96 | } | 
|  | 97 | return 0; | 
|  | 98 |  | 
|  | 99 | vio_setHandler_failed: | 
|  | 100 | viopath_close(viopath_hostLp, viomajorsubtype_scsi, max_requests); | 
|  | 101 | viopath_open_failed: | 
|  | 102 | return -1; | 
|  | 103 | } | 
|  | 104 |  | 
| David Woodhouse | d3849d5 | 2007-09-22 08:29:36 +1000 | [diff] [blame] | 105 | static void iseriesvscsi_release_crq_queue(struct crq_queue *queue, | 
|  | 106 | struct ibmvscsi_host_data *hostdata, | 
|  | 107 | int max_requests) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 108 | { | 
|  | 109 | vio_clearHandler(viomajorsubtype_scsi); | 
|  | 110 | viopath_close(viopath_hostLp, viomajorsubtype_scsi, max_requests); | 
|  | 111 | } | 
|  | 112 |  | 
|  | 113 | /** | 
|  | 114 | * reset_crq_queue: - resets a crq after a failure | 
|  | 115 | * @queue:	crq_queue to initialize and register | 
|  | 116 | * @hostdata:	ibmvscsi_host_data of host | 
|  | 117 | * | 
|  | 118 | * no-op for iSeries | 
|  | 119 | */ | 
| David Woodhouse | d3849d5 | 2007-09-22 08:29:36 +1000 | [diff] [blame] | 120 | static int iseriesvscsi_reset_crq_queue(struct crq_queue *queue, | 
|  | 121 | struct ibmvscsi_host_data *hostdata) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 122 | { | 
| Dave C Boutcher | bb58596 | 2005-11-15 09:53:00 -0600 | [diff] [blame] | 123 | return 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 124 | } | 
|  | 125 |  | 
|  | 126 | /** | 
| Dave C Boutcher | 2b541f8 | 2006-01-19 13:34:44 -0600 | [diff] [blame] | 127 | * reenable_crq_queue: - reenables a crq after a failure | 
|  | 128 | * @queue:	crq_queue to initialize and register | 
|  | 129 | * @hostdata:	ibmvscsi_host_data of host | 
|  | 130 | * | 
|  | 131 | * no-op for iSeries | 
|  | 132 | */ | 
| David Woodhouse | d3849d5 | 2007-09-22 08:29:36 +1000 | [diff] [blame] | 133 | static int iseriesvscsi_reenable_crq_queue(struct crq_queue *queue, | 
|  | 134 | struct ibmvscsi_host_data *hostdata) | 
| Dave C Boutcher | 2b541f8 | 2006-01-19 13:34:44 -0600 | [diff] [blame] | 135 | { | 
|  | 136 | return 0; | 
|  | 137 | } | 
|  | 138 |  | 
|  | 139 | /** | 
| David Woodhouse | d3849d5 | 2007-09-22 08:29:36 +1000 | [diff] [blame] | 140 | * iseriesvscsi_send_crq: - Send a CRQ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 141 | * @hostdata:	the adapter | 
|  | 142 | * @word1:	the first 64 bits of the data | 
|  | 143 | * @word2:	the second 64 bits of the data | 
|  | 144 | */ | 
| David Woodhouse | d3849d5 | 2007-09-22 08:29:36 +1000 | [diff] [blame] | 145 | static int iseriesvscsi_send_crq(struct ibmvscsi_host_data *hostdata, | 
|  | 146 | u64 word1, u64 word2) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 147 | { | 
|  | 148 | single_host_data = hostdata; | 
|  | 149 | return HvCallEvent_signalLpEventFast(viopath_hostLp, | 
|  | 150 | HvLpEvent_Type_VirtualIo, | 
|  | 151 | viomajorsubtype_scsi, | 
|  | 152 | HvLpEvent_AckInd_NoAck, | 
|  | 153 | HvLpEvent_AckType_ImmediateAck, | 
|  | 154 | viopath_sourceinst(viopath_hostLp), | 
|  | 155 | viopath_targetinst(viopath_hostLp), | 
|  | 156 | 0, | 
|  | 157 | VIOVERSION << 16, word1, word2, 0, | 
|  | 158 | 0); | 
|  | 159 | } | 
| David Woodhouse | d3849d5 | 2007-09-22 08:29:36 +1000 | [diff] [blame] | 160 |  | 
|  | 161 | struct ibmvscsi_ops iseriesvscsi_ops = { | 
|  | 162 | .init_crq_queue = iseriesvscsi_init_crq_queue, | 
|  | 163 | .release_crq_queue = iseriesvscsi_release_crq_queue, | 
|  | 164 | .reset_crq_queue = iseriesvscsi_reset_crq_queue, | 
|  | 165 | .reenable_crq_queue = iseriesvscsi_reenable_crq_queue, | 
|  | 166 | .send_crq = iseriesvscsi_send_crq, | 
|  | 167 | }; |