Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * linux/drivers/message/fusion/mptctl.c |
Moore, Eric Dean | b6fe4dd | 2005-04-22 18:01:34 -0400 | [diff] [blame] | 3 | * mpt Ioctl driver. |
Prakash, Sathya | f36789e | 2007-08-14 16:22:54 +0530 | [diff] [blame] | 4 | * For use with LSI PCI chip/adapters |
| 5 | * running LSI Fusion MPT (Message Passing Technology) firmware. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6 | * |
Prakash, Sathya | cddc0ab | 2008-05-21 00:56:41 +0530 | [diff] [blame] | 7 | * Copyright (c) 1999-2008 LSI Corporation |
Eric Moore | 16d2010 | 2007-06-13 16:31:07 -0600 | [diff] [blame] | 8 | * (mailto:DL-MPTFusionLinux@lsi.com) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10 | */ |
| 11 | /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ |
| 12 | /* |
| 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; version 2 of the License. |
| 16 | |
| 17 | This program is distributed in the hope that it will be useful, |
| 18 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 19 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 20 | GNU General Public License for more details. |
| 21 | |
| 22 | NO WARRANTY |
| 23 | THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR |
| 24 | CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT |
| 25 | LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, |
| 26 | MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is |
| 27 | solely responsible for determining the appropriateness of using and |
| 28 | distributing the Program and assumes all risks associated with its |
| 29 | exercise of rights under this Agreement, including but not limited to |
| 30 | the risks and costs of program errors, damage to or loss of data, |
| 31 | programs or equipment, and unavailability or interruption of operations. |
| 32 | |
| 33 | DISCLAIMER OF LIABILITY |
| 34 | NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY |
| 35 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 36 | DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND |
| 37 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR |
| 38 | TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE |
| 39 | USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED |
| 40 | HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES |
| 41 | |
| 42 | You should have received a copy of the GNU General Public License |
| 43 | along with this program; if not, write to the Free Software |
| 44 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 45 | */ |
| 46 | /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ |
| 47 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | #include <linux/kernel.h> |
| 49 | #include <linux/module.h> |
| 50 | #include <linux/errno.h> |
| 51 | #include <linux/init.h> |
| 52 | #include <linux/slab.h> |
| 53 | #include <linux/types.h> |
| 54 | #include <linux/pci.h> |
| 55 | #include <linux/delay.h> /* for mdelay */ |
| 56 | #include <linux/miscdevice.h> |
| 57 | #include <linux/smp_lock.h> |
| 58 | #include <linux/compat.h> |
| 59 | |
| 60 | #include <asm/io.h> |
| 61 | #include <asm/uaccess.h> |
| 62 | |
| 63 | #include <scsi/scsi.h> |
| 64 | #include <scsi/scsi_cmnd.h> |
| 65 | #include <scsi/scsi_device.h> |
| 66 | #include <scsi/scsi_host.h> |
| 67 | #include <scsi/scsi_tcq.h> |
| 68 | |
Prakash, Sathya | cddc0ab | 2008-05-21 00:56:41 +0530 | [diff] [blame] | 69 | #define COPYRIGHT "Copyright (c) 1999-2008 LSI Corporation" |
Prakash, Sathya | f36789e | 2007-08-14 16:22:54 +0530 | [diff] [blame] | 70 | #define MODULEAUTHOR "LSI Corporation" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | #include "mptbase.h" |
| 72 | #include "mptctl.h" |
| 73 | |
| 74 | /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ |
| 75 | #define my_NAME "Fusion MPT misc device (ioctl) driver" |
| 76 | #define my_VERSION MPT_LINUX_VERSION_COMMON |
| 77 | #define MYNAM "mptctl" |
| 78 | |
| 79 | MODULE_AUTHOR(MODULEAUTHOR); |
| 80 | MODULE_DESCRIPTION(my_NAME); |
| 81 | MODULE_LICENSE("GPL"); |
Eric Moore | 9f4203b | 2007-01-04 20:47:47 -0700 | [diff] [blame] | 82 | MODULE_VERSION(my_VERSION); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 83 | |
| 84 | /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ |
| 85 | |
Prakash, Sathya | f606f57 | 2007-08-14 16:12:53 +0530 | [diff] [blame] | 86 | static u8 mptctl_id = MPT_MAX_PROTOCOL_DRIVERS; |
Kashyap, Desai | ea2a788 | 2009-05-29 16:46:50 +0530 | [diff] [blame] | 87 | static u8 mptctl_taskmgmt_id = MPT_MAX_PROTOCOL_DRIVERS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | |
| 89 | static DECLARE_WAIT_QUEUE_HEAD ( mptctl_wait ); |
| 90 | |
| 91 | /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ |
| 92 | |
| 93 | struct buflist { |
| 94 | u8 *kptr; |
| 95 | int len; |
| 96 | }; |
| 97 | |
| 98 | /* |
| 99 | * Function prototypes. Called from OS entry point mptctl_ioctl. |
| 100 | * arg contents specific to function. |
| 101 | */ |
| 102 | static int mptctl_fw_download(unsigned long arg); |
Moore, Eric Dean | d485eb8 | 2005-05-11 17:37:26 -0600 | [diff] [blame] | 103 | static int mptctl_getiocinfo(unsigned long arg, unsigned int cmd); |
| 104 | static int mptctl_gettargetinfo(unsigned long arg); |
| 105 | static int mptctl_readtest(unsigned long arg); |
| 106 | static int mptctl_mpt_command(unsigned long arg); |
| 107 | static int mptctl_eventquery(unsigned long arg); |
| 108 | static int mptctl_eventenable(unsigned long arg); |
| 109 | static int mptctl_eventreport(unsigned long arg); |
| 110 | static int mptctl_replace_fw(unsigned long arg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 111 | |
| 112 | static int mptctl_do_reset(unsigned long arg); |
| 113 | static int mptctl_hp_hostinfo(unsigned long arg, unsigned int cmd); |
| 114 | static int mptctl_hp_targetinfo(unsigned long arg); |
| 115 | |
| 116 | static int mptctl_probe(struct pci_dev *, const struct pci_device_id *); |
| 117 | static void mptctl_remove(struct pci_dev *); |
| 118 | |
| 119 | #ifdef CONFIG_COMPAT |
| 120 | static long compat_mpctl_ioctl(struct file *f, unsigned cmd, unsigned long arg); |
| 121 | #endif |
| 122 | /* |
| 123 | * Private function calls. |
| 124 | */ |
Moore, Eric Dean | d485eb8 | 2005-05-11 17:37:26 -0600 | [diff] [blame] | 125 | static int mptctl_do_mpt_command(struct mpt_ioctl_command karg, void __user *mfPtr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 126 | static int mptctl_do_fw_download(int ioc, char __user *ufwbuf, size_t fwlen); |
Moore, Eric Dean | d485eb8 | 2005-05-11 17:37:26 -0600 | [diff] [blame] | 127 | static MptSge_t *kbuf_alloc_2_sgl(int bytes, u32 dir, int sge_offset, int *frags, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 128 | struct buflist **blp, dma_addr_t *sglbuf_dma, MPT_ADAPTER *ioc); |
Moore, Eric Dean | d485eb8 | 2005-05-11 17:37:26 -0600 | [diff] [blame] | 129 | static void kfree_sgl(MptSge_t *sgl, dma_addr_t sgl_dma, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 130 | struct buflist *buflist, MPT_ADAPTER *ioc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 131 | |
| 132 | /* |
| 133 | * Reset Handler cleanup function |
| 134 | */ |
| 135 | static int mptctl_ioc_reset(MPT_ADAPTER *ioc, int reset_phase); |
| 136 | |
Moore, Eric | ea5a7a8 | 2006-02-02 17:20:01 -0700 | [diff] [blame] | 137 | /* |
| 138 | * Event Handler function |
| 139 | */ |
| 140 | static int mptctl_event_process(MPT_ADAPTER *ioc, EventNotificationReply_t *pEvReply); |
Moore, Eric | c972c70 | 2006-03-14 09:14:06 -0700 | [diff] [blame] | 141 | static struct fasync_struct *async_queue=NULL; |
Moore, Eric | ea5a7a8 | 2006-02-02 17:20:01 -0700 | [diff] [blame] | 142 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 143 | /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ |
| 144 | /* |
| 145 | * Scatter gather list (SGL) sizes and limits... |
| 146 | */ |
| 147 | //#define MAX_SCSI_FRAGS 9 |
| 148 | #define MAX_FRAGS_SPILL1 9 |
| 149 | #define MAX_FRAGS_SPILL2 15 |
| 150 | #define FRAGS_PER_BUCKET (MAX_FRAGS_SPILL2 + 1) |
| 151 | |
| 152 | //#define MAX_CHAIN_FRAGS 64 |
| 153 | //#define MAX_CHAIN_FRAGS (15+15+15+16) |
| 154 | #define MAX_CHAIN_FRAGS (4 * MAX_FRAGS_SPILL2 + 1) |
| 155 | |
| 156 | // Define max sg LIST bytes ( == (#frags + #chains) * 8 bytes each) |
| 157 | // Works out to: 592d bytes! (9+1)*8 + 4*(15+1)*8 |
| 158 | // ^----------------- 80 + 512 |
| 159 | #define MAX_SGL_BYTES ((MAX_FRAGS_SPILL1 + 1 + (4 * FRAGS_PER_BUCKET)) * 8) |
| 160 | |
| 161 | /* linux only seems to ever give 128kB MAX contiguous (GFP_USER) mem bytes */ |
| 162 | #define MAX_KMALLOC_SZ (128*1024) |
| 163 | |
| 164 | #define MPT_IOCTL_DEFAULT_TIMEOUT 10 /* Default timeout value (seconds) */ |
| 165 | |
| 166 | /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ |
| 167 | /** |
| 168 | * mptctl_syscall_down - Down the MPT adapter syscall semaphore. |
| 169 | * @ioc: Pointer to MPT adapter |
| 170 | * @nonblock: boolean, non-zero if O_NONBLOCK is set |
| 171 | * |
| 172 | * All of the ioctl commands can potentially sleep, which is illegal |
| 173 | * with a spinlock held, thus we perform mutual exclusion here. |
| 174 | * |
| 175 | * Returns negative errno on error, or zero for success. |
| 176 | */ |
| 177 | static inline int |
| 178 | mptctl_syscall_down(MPT_ADAPTER *ioc, int nonblock) |
| 179 | { |
| 180 | int rc = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 181 | |
| 182 | if (nonblock) { |
Kashyap, Desai | ea2a788 | 2009-05-29 16:46:50 +0530 | [diff] [blame] | 183 | if (!mutex_trylock(&ioc->ioctl_cmds.mutex)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 184 | rc = -EAGAIN; |
| 185 | } else { |
Kashyap, Desai | ea2a788 | 2009-05-29 16:46:50 +0530 | [diff] [blame] | 186 | if (mutex_lock_interruptible(&ioc->ioctl_cmds.mutex)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 187 | rc = -ERESTARTSYS; |
| 188 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 189 | return rc; |
| 190 | } |
| 191 | |
| 192 | /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ |
| 193 | /* |
| 194 | * This is the callback for any message we have posted. The message itself |
| 195 | * will be returned to the message pool when we return from the IRQ |
| 196 | * |
| 197 | * This runs in irq context so be short and sweet. |
| 198 | */ |
| 199 | static int |
| 200 | mptctl_reply(MPT_ADAPTER *ioc, MPT_FRAME_HDR *req, MPT_FRAME_HDR *reply) |
| 201 | { |
Kashyap, Desai | ea2a788 | 2009-05-29 16:46:50 +0530 | [diff] [blame] | 202 | char *sense_data; |
| 203 | int req_index; |
| 204 | int sz; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 205 | |
Kashyap, Desai | ea2a788 | 2009-05-29 16:46:50 +0530 | [diff] [blame] | 206 | if (!req) |
| 207 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 208 | |
Kashyap, Desai | ea2a788 | 2009-05-29 16:46:50 +0530 | [diff] [blame] | 209 | dctlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "completing mpi function " |
| 210 | "(0x%02X), req=%p, reply=%p\n", ioc->name, req->u.hdr.Function, |
| 211 | req, reply)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 212 | |
Kashyap, Desai | ea2a788 | 2009-05-29 16:46:50 +0530 | [diff] [blame] | 213 | /* |
| 214 | * Handling continuation of the same reply. Processing the first |
| 215 | * reply, and eating the other replys that come later. |
| 216 | */ |
| 217 | if (ioc->ioctl_cmds.msg_context != req->u.hdr.MsgContext) |
| 218 | goto out_continuation; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 219 | |
Kashyap, Desai | ea2a788 | 2009-05-29 16:46:50 +0530 | [diff] [blame] | 220 | ioc->ioctl_cmds.status |= MPT_MGMT_STATUS_COMMAND_GOOD; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 221 | |
Kashyap, Desai | ea2a788 | 2009-05-29 16:46:50 +0530 | [diff] [blame] | 222 | if (!reply) |
| 223 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 224 | |
Kashyap, Desai | ea2a788 | 2009-05-29 16:46:50 +0530 | [diff] [blame] | 225 | ioc->ioctl_cmds.status |= MPT_MGMT_STATUS_RF_VALID; |
| 226 | sz = min(ioc->reply_sz, 4*reply->u.reply.MsgLength); |
| 227 | memcpy(ioc->ioctl_cmds.reply, reply, sz); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 228 | |
Kashyap, Desai | ea2a788 | 2009-05-29 16:46:50 +0530 | [diff] [blame] | 229 | if (reply->u.reply.IOCStatus || reply->u.reply.IOCLogInfo) |
| 230 | dctlprintk(ioc, printk(MYIOC_s_DEBUG_FMT |
| 231 | "iocstatus (0x%04X), loginfo (0x%08X)\n", ioc->name, |
| 232 | le16_to_cpu(reply->u.reply.IOCStatus), |
| 233 | le32_to_cpu(reply->u.reply.IOCLogInfo))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 234 | |
Kashyap, Desai | ea2a788 | 2009-05-29 16:46:50 +0530 | [diff] [blame] | 235 | if ((req->u.hdr.Function == MPI_FUNCTION_SCSI_IO_REQUEST) || |
| 236 | (req->u.hdr.Function == |
| 237 | MPI_FUNCTION_RAID_SCSI_IO_PASSTHROUGH)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 238 | |
Kashyap, Desai | ea2a788 | 2009-05-29 16:46:50 +0530 | [diff] [blame] | 239 | if (reply->u.sreply.SCSIStatus || reply->u.sreply.SCSIState) |
| 240 | dctlprintk(ioc, printk(MYIOC_s_DEBUG_FMT |
| 241 | "scsi_status (0x%02x), scsi_state (0x%02x), " |
| 242 | "tag = (0x%04x), transfer_count (0x%08x)\n", ioc->name, |
| 243 | reply->u.sreply.SCSIStatus, |
| 244 | reply->u.sreply.SCSIState, |
| 245 | le16_to_cpu(reply->u.sreply.TaskTag), |
| 246 | le32_to_cpu(reply->u.sreply.TransferCount))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 247 | |
Kashyap, Desai | ea2a788 | 2009-05-29 16:46:50 +0530 | [diff] [blame] | 248 | if (reply->u.sreply.SCSIState & |
| 249 | MPI_SCSI_STATE_AUTOSENSE_VALID) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 250 | sz = req->u.scsireq.SenseBufferLength; |
| 251 | req_index = |
| 252 | le16_to_cpu(req->u.frame.hwhdr.msgctxu.fld.req_idx); |
Kashyap, Desai | ea2a788 | 2009-05-29 16:46:50 +0530 | [diff] [blame] | 253 | sense_data = ((u8 *)ioc->sense_buf_pool + |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 254 | (req_index * MPT_SENSE_BUFFER_ALLOC)); |
Kashyap, Desai | ea2a788 | 2009-05-29 16:46:50 +0530 | [diff] [blame] | 255 | memcpy(ioc->ioctl_cmds.sense, sense_data, sz); |
| 256 | ioc->ioctl_cmds.status |= MPT_MGMT_STATUS_SENSE_VALID; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 257 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 258 | } |
Kashyap, Desai | ea2a788 | 2009-05-29 16:46:50 +0530 | [diff] [blame] | 259 | |
| 260 | out: |
| 261 | /* We are done, issue wake up |
| 262 | */ |
| 263 | if (ioc->ioctl_cmds.status & MPT_MGMT_STATUS_PENDING) { |
| 264 | if (req->u.hdr.Function == MPI_FUNCTION_SCSI_TASK_MGMT) |
| 265 | mpt_clear_taskmgmt_in_progress_flag(ioc); |
| 266 | ioc->ioctl_cmds.status &= ~MPT_MGMT_STATUS_PENDING; |
| 267 | complete(&ioc->ioctl_cmds.done); |
| 268 | } |
| 269 | |
| 270 | out_continuation: |
| 271 | if (reply && (reply->u.reply.MsgFlags & |
| 272 | MPI_MSGFLAGS_CONTINUATION_REPLY)) |
| 273 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 274 | return 1; |
| 275 | } |
| 276 | |
Kashyap, Desai | ea2a788 | 2009-05-29 16:46:50 +0530 | [diff] [blame] | 277 | |
| 278 | static int |
| 279 | mptctl_taskmgmt_reply(MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf, MPT_FRAME_HDR *mr) |
| 280 | { |
| 281 | if (!mf) |
| 282 | return 0; |
| 283 | |
| 284 | dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT |
| 285 | "TaskMgmt completed (mf=%p, mr=%p)\n", |
| 286 | ioc->name, mf, mr)); |
| 287 | |
| 288 | ioc->taskmgmt_cmds.status |= MPT_MGMT_STATUS_COMMAND_GOOD; |
| 289 | |
| 290 | if (!mr) |
| 291 | goto out; |
| 292 | |
| 293 | ioc->taskmgmt_cmds.status |= MPT_MGMT_STATUS_RF_VALID; |
| 294 | memcpy(ioc->taskmgmt_cmds.reply, mr, |
| 295 | min(MPT_DEFAULT_FRAME_SIZE, 4 * mr->u.reply.MsgLength)); |
| 296 | out: |
| 297 | if (ioc->taskmgmt_cmds.status & MPT_MGMT_STATUS_PENDING) { |
| 298 | mpt_clear_taskmgmt_in_progress_flag(ioc); |
| 299 | ioc->taskmgmt_cmds.status &= ~MPT_MGMT_STATUS_PENDING; |
| 300 | complete(&ioc->taskmgmt_cmds.done); |
| 301 | return 1; |
| 302 | } |
| 303 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 304 | } |
| 305 | |
Kashyap, Desai | 7d757f1 | 2010-03-18 19:13:10 +0530 | [diff] [blame^] | 306 | static int |
| 307 | mptctl_do_taskmgmt(MPT_ADAPTER *ioc, u8 tm_type, u8 bus_id, u8 target_id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 308 | { |
| 309 | MPT_FRAME_HDR *mf; |
| 310 | SCSITaskMgmt_t *pScsiTm; |
Kashyap, Desai | ea2a788 | 2009-05-29 16:46:50 +0530 | [diff] [blame] | 311 | SCSITaskMgmtReply_t *pScsiTmReply; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 312 | int ii; |
Kashyap, Desai | ea2a788 | 2009-05-29 16:46:50 +0530 | [diff] [blame] | 313 | int retval; |
| 314 | unsigned long timeout; |
| 315 | unsigned long time_count; |
| 316 | u16 iocstatus; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 317 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 318 | |
Kashyap, Desai | ea2a788 | 2009-05-29 16:46:50 +0530 | [diff] [blame] | 319 | mutex_lock(&ioc->taskmgmt_cmds.mutex); |
| 320 | if (mpt_set_taskmgmt_in_progress_flag(ioc) != 0) { |
| 321 | mutex_unlock(&ioc->taskmgmt_cmds.mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 322 | return -EPERM; |
Kashyap, Desai | ea2a788 | 2009-05-29 16:46:50 +0530 | [diff] [blame] | 323 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 324 | |
Kashyap, Desai | ea2a788 | 2009-05-29 16:46:50 +0530 | [diff] [blame] | 325 | retval = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 326 | |
Kashyap, Desai | ea2a788 | 2009-05-29 16:46:50 +0530 | [diff] [blame] | 327 | mf = mpt_get_msg_frame(mptctl_taskmgmt_id, ioc); |
| 328 | if (mf == NULL) { |
Kashyap, Desai | 7d757f1 | 2010-03-18 19:13:10 +0530 | [diff] [blame^] | 329 | dtmprintk(ioc, |
| 330 | printk(MYIOC_s_WARN_FMT "TaskMgmt, no msg frames!!\n", |
| 331 | ioc->name)); |
Kashyap, Desai | ea2a788 | 2009-05-29 16:46:50 +0530 | [diff] [blame] | 332 | mpt_clear_taskmgmt_in_progress_flag(ioc); |
| 333 | retval = -ENOMEM; |
Kashyap, Desai | 7d757f1 | 2010-03-18 19:13:10 +0530 | [diff] [blame^] | 334 | goto tm_done; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 335 | } |
| 336 | |
Kashyap, Desai | ea2a788 | 2009-05-29 16:46:50 +0530 | [diff] [blame] | 337 | dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT "TaskMgmt request (mf=%p)\n", |
| 338 | ioc->name, mf)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 339 | |
| 340 | pScsiTm = (SCSITaskMgmt_t *) mf; |
Kashyap, Desai | ea2a788 | 2009-05-29 16:46:50 +0530 | [diff] [blame] | 341 | memset(pScsiTm, 0, sizeof(SCSITaskMgmt_t)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 342 | pScsiTm->Function = MPI_FUNCTION_SCSI_TASK_MGMT; |
Kashyap, Desai | 7d757f1 | 2010-03-18 19:13:10 +0530 | [diff] [blame^] | 343 | pScsiTm->TaskType = tm_type; |
| 344 | if ((tm_type == MPI_SCSITASKMGMT_TASKTYPE_RESET_BUS) && |
| 345 | (ioc->bus_type == FC)) |
| 346 | pScsiTm->MsgFlags = |
| 347 | MPI_SCSITASKMGMT_MSGFLAGS_LIPRESET_RESET_OPTION; |
| 348 | pScsiTm->TargetID = target_id; |
| 349 | pScsiTm->Bus = bus_id; |
Kashyap, Desai | ea2a788 | 2009-05-29 16:46:50 +0530 | [diff] [blame] | 350 | pScsiTm->ChainOffset = 0; |
| 351 | pScsiTm->Reserved = 0; |
| 352 | pScsiTm->Reserved1 = 0; |
| 353 | pScsiTm->TaskMsgContext = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 354 | for (ii= 0; ii < 8; ii++) |
| 355 | pScsiTm->LUN[ii] = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 356 | for (ii=0; ii < 7; ii++) |
| 357 | pScsiTm->Reserved2[ii] = 0; |
| 358 | |
Kashyap, Desai | ea2a788 | 2009-05-29 16:46:50 +0530 | [diff] [blame] | 359 | switch (ioc->bus_type) { |
| 360 | case FC: |
| 361 | timeout = 40; |
| 362 | break; |
| 363 | case SAS: |
| 364 | timeout = 30; |
| 365 | break; |
| 366 | case SPI: |
Kashyap, Desai | 7d757f1 | 2010-03-18 19:13:10 +0530 | [diff] [blame^] | 367 | default: |
| 368 | timeout = 10; |
Kashyap, Desai | ea2a788 | 2009-05-29 16:46:50 +0530 | [diff] [blame] | 369 | break; |
| 370 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 371 | |
Kashyap, Desai | 7d757f1 | 2010-03-18 19:13:10 +0530 | [diff] [blame^] | 372 | dtmprintk(ioc, |
| 373 | printk(MYIOC_s_DEBUG_FMT "TaskMgmt type=%d timeout=%ld\n", |
| 374 | ioc->name, tm_type, timeout)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 375 | |
Kashyap, Desai | ea2a788 | 2009-05-29 16:46:50 +0530 | [diff] [blame] | 376 | INITIALIZE_MGMT_STATUS(ioc->taskmgmt_cmds.status) |
Kashyap, Desai | ea2a788 | 2009-05-29 16:46:50 +0530 | [diff] [blame] | 377 | time_count = jiffies; |
| 378 | if ((ioc->facts.IOCCapabilities & MPI_IOCFACTS_CAPABILITY_HIGH_PRI_Q) && |
| 379 | (ioc->facts.MsgVersion >= MPI_VERSION_01_05)) |
| 380 | mpt_put_msg_frame_hi_pri(mptctl_taskmgmt_id, ioc, mf); |
Prakash, Sathya | 7a195f4 | 2007-08-14 16:08:40 +0530 | [diff] [blame] | 381 | else { |
Kashyap, Desai | ea2a788 | 2009-05-29 16:46:50 +0530 | [diff] [blame] | 382 | retval = mpt_send_handshake_request(mptctl_taskmgmt_id, ioc, |
| 383 | sizeof(SCSITaskMgmt_t), (u32 *)pScsiTm, CAN_SLEEP); |
Prakash, Sathya | 7a195f4 | 2007-08-14 16:08:40 +0530 | [diff] [blame] | 384 | if (retval != 0) { |
Kashyap, Desai | 7d757f1 | 2010-03-18 19:13:10 +0530 | [diff] [blame^] | 385 | dfailprintk(ioc, |
| 386 | printk(MYIOC_s_ERR_FMT |
Kashyap, Desai | ea2a788 | 2009-05-29 16:46:50 +0530 | [diff] [blame] | 387 | "TaskMgmt send_handshake FAILED!" |
| 388 | " (ioc %p, mf %p, rc=%d) \n", ioc->name, |
| 389 | ioc, mf, retval)); |
Kashyap, Desai | 7d757f1 | 2010-03-18 19:13:10 +0530 | [diff] [blame^] | 390 | mpt_free_msg_frame(ioc, mf); |
Kashyap, Desai | ea2a788 | 2009-05-29 16:46:50 +0530 | [diff] [blame] | 391 | mpt_clear_taskmgmt_in_progress_flag(ioc); |
Kashyap, Desai | 7d757f1 | 2010-03-18 19:13:10 +0530 | [diff] [blame^] | 392 | goto tm_done; |
Prakash, Sathya | 7a195f4 | 2007-08-14 16:08:40 +0530 | [diff] [blame] | 393 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 394 | } |
| 395 | |
| 396 | /* Now wait for the command to complete */ |
Kashyap, Desai | ea2a788 | 2009-05-29 16:46:50 +0530 | [diff] [blame] | 397 | ii = wait_for_completion_timeout(&ioc->taskmgmt_cmds.done, timeout*HZ); |
Kashyap, Desai | 7d757f1 | 2010-03-18 19:13:10 +0530 | [diff] [blame^] | 398 | |
Kashyap, Desai | ea2a788 | 2009-05-29 16:46:50 +0530 | [diff] [blame] | 399 | if (!(ioc->taskmgmt_cmds.status & MPT_MGMT_STATUS_COMMAND_GOOD)) { |
| 400 | dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT |
| 401 | "TaskMgmt failed\n", ioc->name)); |
| 402 | mpt_free_msg_frame(ioc, mf); |
| 403 | mpt_clear_taskmgmt_in_progress_flag(ioc); |
| 404 | if (ioc->taskmgmt_cmds.status & MPT_MGMT_STATUS_DID_IOCRESET) |
| 405 | retval = 0; |
| 406 | else |
| 407 | retval = -1; /* return failure */ |
Kashyap, Desai | 7d757f1 | 2010-03-18 19:13:10 +0530 | [diff] [blame^] | 408 | goto tm_done; |
Kashyap, Desai | ea2a788 | 2009-05-29 16:46:50 +0530 | [diff] [blame] | 409 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 410 | |
Kashyap, Desai | ea2a788 | 2009-05-29 16:46:50 +0530 | [diff] [blame] | 411 | if (!(ioc->taskmgmt_cmds.status & MPT_MGMT_STATUS_RF_VALID)) { |
| 412 | dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT |
| 413 | "TaskMgmt failed\n", ioc->name)); |
| 414 | retval = -1; /* return failure */ |
Kashyap, Desai | 7d757f1 | 2010-03-18 19:13:10 +0530 | [diff] [blame^] | 415 | goto tm_done; |
Kashyap, Desai | ea2a788 | 2009-05-29 16:46:50 +0530 | [diff] [blame] | 416 | } |
| 417 | |
| 418 | pScsiTmReply = (SCSITaskMgmtReply_t *) ioc->taskmgmt_cmds.reply; |
| 419 | dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT |
| 420 | "TaskMgmt fw_channel = %d, fw_id = %d, task_type=0x%02X, " |
| 421 | "iocstatus=0x%04X\n\tloginfo=0x%08X, response_code=0x%02X, " |
| 422 | "term_cmnds=%d\n", ioc->name, pScsiTmReply->Bus, |
Kashyap, Desai | 7d757f1 | 2010-03-18 19:13:10 +0530 | [diff] [blame^] | 423 | pScsiTmReply->TargetID, tm_type, |
Kashyap, Desai | ea2a788 | 2009-05-29 16:46:50 +0530 | [diff] [blame] | 424 | le16_to_cpu(pScsiTmReply->IOCStatus), |
| 425 | le32_to_cpu(pScsiTmReply->IOCLogInfo), |
| 426 | pScsiTmReply->ResponseCode, |
| 427 | le32_to_cpu(pScsiTmReply->TerminationCount))); |
| 428 | |
| 429 | iocstatus = le16_to_cpu(pScsiTmReply->IOCStatus) & MPI_IOCSTATUS_MASK; |
| 430 | |
| 431 | if (iocstatus == MPI_IOCSTATUS_SCSI_TASK_TERMINATED || |
| 432 | iocstatus == MPI_IOCSTATUS_SCSI_IOC_TERMINATED || |
| 433 | iocstatus == MPI_IOCSTATUS_SUCCESS) |
| 434 | retval = 0; |
| 435 | else { |
| 436 | dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT |
| 437 | "TaskMgmt failed\n", ioc->name)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 438 | retval = -1; /* return failure */ |
| 439 | } |
| 440 | |
Kashyap, Desai | 7d757f1 | 2010-03-18 19:13:10 +0530 | [diff] [blame^] | 441 | tm_done: |
Kashyap, Desai | ea2a788 | 2009-05-29 16:46:50 +0530 | [diff] [blame] | 442 | mutex_unlock(&ioc->taskmgmt_cmds.mutex); |
| 443 | CLEAR_MGMT_STATUS(ioc->taskmgmt_cmds.status) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 444 | return retval; |
| 445 | } |
| 446 | |
Kashyap, Desai | 7d757f1 | 2010-03-18 19:13:10 +0530 | [diff] [blame^] | 447 | /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ |
| 448 | /* mptctl_timeout_expired |
| 449 | * |
| 450 | * Expecting an interrupt, however timed out. |
| 451 | * |
| 452 | */ |
| 453 | static void |
| 454 | mptctl_timeout_expired(MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf) |
| 455 | { |
| 456 | unsigned long flags; |
| 457 | int ret_val = -1; |
| 458 | SCSIIORequest_t *scsi_req = (SCSIIORequest_t *) mf; |
| 459 | u8 function = mf->u.hdr.Function; |
| 460 | |
| 461 | dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT ": %s\n", |
| 462 | ioc->name, __func__)); |
| 463 | |
| 464 | if (mpt_fwfault_debug) |
| 465 | mpt_halt_firmware(ioc); |
| 466 | |
| 467 | spin_lock_irqsave(&ioc->taskmgmt_lock, flags); |
| 468 | if (ioc->ioc_reset_in_progress) { |
| 469 | spin_unlock_irqrestore(&ioc->taskmgmt_lock, flags); |
| 470 | CLEAR_MGMT_PENDING_STATUS(ioc->ioctl_cmds.status) |
| 471 | mpt_free_msg_frame(ioc, mf); |
| 472 | return; |
| 473 | } |
| 474 | spin_unlock_irqrestore(&ioc->taskmgmt_lock, flags); |
| 475 | |
| 476 | |
| 477 | CLEAR_MGMT_PENDING_STATUS(ioc->ioctl_cmds.status) |
| 478 | |
| 479 | if (ioc->bus_type == SAS) { |
| 480 | if (function == MPI_FUNCTION_SCSI_IO_REQUEST) |
| 481 | ret_val = mptctl_do_taskmgmt(ioc, |
| 482 | MPI_SCSITASKMGMT_TASKTYPE_TARGET_RESET, |
| 483 | scsi_req->Bus, scsi_req->TargetID); |
| 484 | else if (function == MPI_FUNCTION_RAID_SCSI_IO_PASSTHROUGH) |
| 485 | ret_val = mptctl_do_taskmgmt(ioc, |
| 486 | MPI_SCSITASKMGMT_TASKTYPE_RESET_BUS, |
| 487 | scsi_req->Bus, 0); |
| 488 | if (!ret_val) |
| 489 | return; |
| 490 | } else { |
| 491 | if ((function == MPI_FUNCTION_SCSI_IO_REQUEST) || |
| 492 | (function == MPI_FUNCTION_RAID_SCSI_IO_PASSTHROUGH)) |
| 493 | ret_val = mptctl_do_taskmgmt(ioc, |
| 494 | MPI_SCSITASKMGMT_TASKTYPE_RESET_BUS, |
| 495 | scsi_req->Bus, 0); |
| 496 | if (!ret_val) |
| 497 | return; |
| 498 | } |
| 499 | |
| 500 | dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Calling Reset! \n", |
| 501 | ioc->name)); |
| 502 | mpt_Soft_Hard_ResetHandler(ioc, CAN_SLEEP); |
| 503 | mpt_free_msg_frame(ioc, mf); |
| 504 | } |
| 505 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 506 | |
| 507 | /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ |
| 508 | /* mptctl_ioc_reset |
| 509 | * |
| 510 | * Clean-up functionality. Used only if there has been a |
| 511 | * reload of the FW due. |
| 512 | * |
| 513 | */ |
| 514 | static int |
| 515 | mptctl_ioc_reset(MPT_ADAPTER *ioc, int reset_phase) |
| 516 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 517 | switch(reset_phase) { |
| 518 | case MPT_IOC_SETUP_RESET: |
Kashyap, Desai | ea2a788 | 2009-05-29 16:46:50 +0530 | [diff] [blame] | 519 | dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT |
| 520 | "%s: MPT_IOC_SETUP_RESET\n", ioc->name, __func__)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 521 | break; |
| 522 | case MPT_IOC_PRE_RESET: |
Kashyap, Desai | ea2a788 | 2009-05-29 16:46:50 +0530 | [diff] [blame] | 523 | dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT |
| 524 | "%s: MPT_IOC_PRE_RESET\n", ioc->name, __func__)); |
| 525 | break; |
| 526 | case MPT_IOC_POST_RESET: |
| 527 | dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT |
| 528 | "%s: MPT_IOC_POST_RESET\n", ioc->name, __func__)); |
| 529 | if (ioc->ioctl_cmds.status & MPT_MGMT_STATUS_PENDING) { |
| 530 | ioc->ioctl_cmds.status |= MPT_MGMT_STATUS_DID_IOCRESET; |
| 531 | complete(&ioc->ioctl_cmds.done); |
| 532 | } |
| 533 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 534 | default: |
| 535 | break; |
| 536 | } |
| 537 | |
| 538 | return 1; |
| 539 | } |
| 540 | |
| 541 | /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ |
Moore, Eric | ea5a7a8 | 2006-02-02 17:20:01 -0700 | [diff] [blame] | 542 | /* ASYNC Event Notification Support */ |
| 543 | static int |
| 544 | mptctl_event_process(MPT_ADAPTER *ioc, EventNotificationReply_t *pEvReply) |
| 545 | { |
| 546 | u8 event; |
| 547 | |
| 548 | event = le32_to_cpu(pEvReply->Event) & 0xFF; |
| 549 | |
Prakash, Sathya | 09120a8 | 2007-07-24 15:49:05 +0530 | [diff] [blame] | 550 | dctlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "%s() called\n", |
Harvey Harrison | cadbd4a | 2008-07-03 23:47:27 -0700 | [diff] [blame] | 551 | ioc->name, __func__)); |
Moore, Eric | ea5a7a8 | 2006-02-02 17:20:01 -0700 | [diff] [blame] | 552 | if(async_queue == NULL) |
| 553 | return 1; |
| 554 | |
| 555 | /* Raise SIGIO for persistent events. |
| 556 | * TODO - this define is not in MPI spec yet, |
| 557 | * but they plan to set it to 0x21 |
| 558 | */ |
| 559 | if (event == 0x21 ) { |
| 560 | ioc->aen_event_read_flag=1; |
Prakash, Sathya | 09120a8 | 2007-07-24 15:49:05 +0530 | [diff] [blame] | 561 | dctlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Raised SIGIO to application\n", |
| 562 | ioc->name)); |
| 563 | devtverboseprintk(ioc, printk(MYIOC_s_DEBUG_FMT |
| 564 | "Raised SIGIO to application\n", ioc->name)); |
Moore, Eric | ea5a7a8 | 2006-02-02 17:20:01 -0700 | [diff] [blame] | 565 | kill_fasync(&async_queue, SIGIO, POLL_IN); |
| 566 | return 1; |
| 567 | } |
| 568 | |
| 569 | /* This flag is set after SIGIO was raised, and |
| 570 | * remains set until the application has read |
| 571 | * the event log via ioctl=MPTEVENTREPORT |
| 572 | */ |
| 573 | if(ioc->aen_event_read_flag) |
| 574 | return 1; |
| 575 | |
| 576 | /* Signal only for the events that are |
| 577 | * requested for by the application |
| 578 | */ |
| 579 | if (ioc->events && (ioc->eventTypes & ( 1 << event))) { |
| 580 | ioc->aen_event_read_flag=1; |
Prakash, Sathya | 09120a8 | 2007-07-24 15:49:05 +0530 | [diff] [blame] | 581 | dctlprintk(ioc, printk(MYIOC_s_DEBUG_FMT |
| 582 | "Raised SIGIO to application\n", ioc->name)); |
| 583 | devtverboseprintk(ioc, printk(MYIOC_s_DEBUG_FMT |
| 584 | "Raised SIGIO to application\n", ioc->name)); |
Moore, Eric | ea5a7a8 | 2006-02-02 17:20:01 -0700 | [diff] [blame] | 585 | kill_fasync(&async_queue, SIGIO, POLL_IN); |
| 586 | } |
| 587 | return 1; |
| 588 | } |
| 589 | |
| 590 | static int |
| 591 | mptctl_fasync(int fd, struct file *filep, int mode) |
| 592 | { |
| 593 | MPT_ADAPTER *ioc; |
Jonathan Corbet | b7e3e1f | 2008-06-19 15:41:11 -0600 | [diff] [blame] | 594 | int ret; |
Moore, Eric | ea5a7a8 | 2006-02-02 17:20:01 -0700 | [diff] [blame] | 595 | |
Jonathan Corbet | b7e3e1f | 2008-06-19 15:41:11 -0600 | [diff] [blame] | 596 | lock_kernel(); |
Moore, Eric | ea5a7a8 | 2006-02-02 17:20:01 -0700 | [diff] [blame] | 597 | list_for_each_entry(ioc, &ioc_list, list) |
| 598 | ioc->aen_event_read_flag=0; |
| 599 | |
Jonathan Corbet | b7e3e1f | 2008-06-19 15:41:11 -0600 | [diff] [blame] | 600 | ret = fasync_helper(fd, filep, mode, &async_queue); |
| 601 | unlock_kernel(); |
| 602 | return ret; |
Moore, Eric | ea5a7a8 | 2006-02-02 17:20:01 -0700 | [diff] [blame] | 603 | } |
| 604 | |
Moore, Eric | ea5a7a8 | 2006-02-02 17:20:01 -0700 | [diff] [blame] | 605 | /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 606 | /* |
| 607 | * MPT ioctl handler |
| 608 | * cmd - specify the particular IOCTL command to be issued |
| 609 | * arg - data specific to the command. Must not be null. |
| 610 | */ |
| 611 | static long |
| 612 | __mptctl_ioctl(struct file *file, unsigned int cmd, unsigned long arg) |
| 613 | { |
| 614 | mpt_ioctl_header __user *uhdr = (void __user *) arg; |
| 615 | mpt_ioctl_header khdr; |
| 616 | int iocnum; |
| 617 | unsigned iocnumX; |
| 618 | int nonblock = (file->f_flags & O_NONBLOCK); |
| 619 | int ret; |
| 620 | MPT_ADAPTER *iocp = NULL; |
| 621 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 622 | if (copy_from_user(&khdr, uhdr, sizeof(khdr))) { |
Eric Moore | 29dd360 | 2007-09-14 18:46:51 -0600 | [diff] [blame] | 623 | printk(KERN_ERR MYNAM "%s::mptctl_ioctl() @%d - " |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 624 | "Unable to copy mpt_ioctl_header data @ %p\n", |
| 625 | __FILE__, __LINE__, uhdr); |
| 626 | return -EFAULT; |
| 627 | } |
| 628 | ret = -ENXIO; /* (-6) No such device or address */ |
| 629 | |
| 630 | /* Verify intended MPT adapter - set iocnum and the adapter |
| 631 | * pointer (iocp) |
| 632 | */ |
| 633 | iocnumX = khdr.iocnum & 0xFF; |
| 634 | if (((iocnum = mpt_verify_adapter(iocnumX, &iocp)) < 0) || |
Kashyap, Desai | e39e145 | 2009-10-07 11:26:54 +0530 | [diff] [blame] | 635 | (iocp == NULL)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 636 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 637 | |
| 638 | if (!iocp->active) { |
Eric Moore | 29dd360 | 2007-09-14 18:46:51 -0600 | [diff] [blame] | 639 | printk(KERN_DEBUG MYNAM "%s::mptctl_ioctl() @%d - Controller disabled.\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 640 | __FILE__, __LINE__); |
| 641 | return -EFAULT; |
| 642 | } |
| 643 | |
| 644 | /* Handle those commands that are just returning |
| 645 | * information stored in the driver. |
| 646 | * These commands should never time out and are unaffected |
| 647 | * by TM and FW reloads. |
| 648 | */ |
| 649 | if ((cmd & ~IOCSIZE_MASK) == (MPTIOCINFO & ~IOCSIZE_MASK)) { |
| 650 | return mptctl_getiocinfo(arg, _IOC_SIZE(cmd)); |
| 651 | } else if (cmd == MPTTARGETINFO) { |
| 652 | return mptctl_gettargetinfo(arg); |
| 653 | } else if (cmd == MPTTEST) { |
| 654 | return mptctl_readtest(arg); |
| 655 | } else if (cmd == MPTEVENTQUERY) { |
| 656 | return mptctl_eventquery(arg); |
| 657 | } else if (cmd == MPTEVENTENABLE) { |
| 658 | return mptctl_eventenable(arg); |
| 659 | } else if (cmd == MPTEVENTREPORT) { |
| 660 | return mptctl_eventreport(arg); |
| 661 | } else if (cmd == MPTFWREPLACE) { |
| 662 | return mptctl_replace_fw(arg); |
| 663 | } |
| 664 | |
| 665 | /* All of these commands require an interrupt or |
| 666 | * are unknown/illegal. |
| 667 | */ |
| 668 | if ((ret = mptctl_syscall_down(iocp, nonblock)) != 0) |
| 669 | return ret; |
| 670 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 671 | if (cmd == MPTFWDOWNLOAD) |
| 672 | ret = mptctl_fw_download(arg); |
| 673 | else if (cmd == MPTCOMMAND) |
| 674 | ret = mptctl_mpt_command(arg); |
| 675 | else if (cmd == MPTHARDRESET) |
| 676 | ret = mptctl_do_reset(arg); |
| 677 | else if ((cmd & ~IOCSIZE_MASK) == (HP_GETHOSTINFO & ~IOCSIZE_MASK)) |
| 678 | ret = mptctl_hp_hostinfo(arg, _IOC_SIZE(cmd)); |
| 679 | else if (cmd == HP_GETTARGETINFO) |
| 680 | ret = mptctl_hp_targetinfo(arg); |
| 681 | else |
| 682 | ret = -EINVAL; |
| 683 | |
Kashyap, Desai | ea2a788 | 2009-05-29 16:46:50 +0530 | [diff] [blame] | 684 | mutex_unlock(&iocp->ioctl_cmds.mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 685 | |
| 686 | return ret; |
| 687 | } |
| 688 | |
| 689 | static long |
| 690 | mptctl_ioctl(struct file *file, unsigned int cmd, unsigned long arg) |
| 691 | { |
| 692 | long ret; |
| 693 | lock_kernel(); |
| 694 | ret = __mptctl_ioctl(file, cmd, arg); |
| 695 | unlock_kernel(); |
| 696 | return ret; |
| 697 | } |
| 698 | |
| 699 | static int mptctl_do_reset(unsigned long arg) |
| 700 | { |
| 701 | struct mpt_ioctl_diag_reset __user *urinfo = (void __user *) arg; |
| 702 | struct mpt_ioctl_diag_reset krinfo; |
| 703 | MPT_ADAPTER *iocp; |
| 704 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 705 | if (copy_from_user(&krinfo, urinfo, sizeof(struct mpt_ioctl_diag_reset))) { |
Eric Moore | 29dd360 | 2007-09-14 18:46:51 -0600 | [diff] [blame] | 706 | printk(KERN_ERR MYNAM "%s@%d::mptctl_do_reset - " |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 707 | "Unable to copy mpt_ioctl_diag_reset struct @ %p\n", |
| 708 | __FILE__, __LINE__, urinfo); |
| 709 | return -EFAULT; |
| 710 | } |
| 711 | |
| 712 | if (mpt_verify_adapter(krinfo.hdr.iocnum, &iocp) < 0) { |
Eric Moore | 29dd360 | 2007-09-14 18:46:51 -0600 | [diff] [blame] | 713 | printk(KERN_DEBUG MYNAM "%s@%d::mptctl_do_reset - ioc%d not found!\n", |
Prakash, Sathya | 09120a8 | 2007-07-24 15:49:05 +0530 | [diff] [blame] | 714 | __FILE__, __LINE__, krinfo.hdr.iocnum); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 715 | return -ENODEV; /* (-6) No such device or address */ |
| 716 | } |
| 717 | |
Prakash, Sathya | 09120a8 | 2007-07-24 15:49:05 +0530 | [diff] [blame] | 718 | dctlprintk(iocp, printk(MYIOC_s_DEBUG_FMT "mptctl_do_reset called.\n", |
| 719 | iocp->name)); |
| 720 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 721 | if (mpt_HardResetHandler(iocp, CAN_SLEEP) != 0) { |
Eric Moore | 29dd360 | 2007-09-14 18:46:51 -0600 | [diff] [blame] | 722 | printk (MYIOC_s_ERR_FMT "%s@%d::mptctl_do_reset - reset failed.\n", |
| 723 | iocp->name, __FILE__, __LINE__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 724 | return -1; |
| 725 | } |
| 726 | |
| 727 | return 0; |
| 728 | } |
| 729 | |
| 730 | /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ |
| 731 | /* |
| 732 | * MPT FW download function. Cast the arg into the mpt_fw_xfer structure. |
| 733 | * This structure contains: iocnum, firmware length (bytes), |
| 734 | * pointer to user space memory where the fw image is stored. |
| 735 | * |
| 736 | * Outputs: None. |
| 737 | * Return: 0 if successful |
| 738 | * -EFAULT if data unavailable |
| 739 | * -ENXIO if no such device |
| 740 | * -EAGAIN if resource problem |
| 741 | * -ENOMEM if no memory for SGE |
| 742 | * -EMLINK if too many chain buffers required |
| 743 | * -EBADRQC if adapter does not support FW download |
| 744 | * -EBUSY if adapter is busy |
| 745 | * -ENOMSG if FW upload returned bad status |
| 746 | */ |
| 747 | static int |
| 748 | mptctl_fw_download(unsigned long arg) |
| 749 | { |
| 750 | struct mpt_fw_xfer __user *ufwdl = (void __user *) arg; |
| 751 | struct mpt_fw_xfer kfwdl; |
| 752 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 753 | if (copy_from_user(&kfwdl, ufwdl, sizeof(struct mpt_fw_xfer))) { |
Eric Moore | 29dd360 | 2007-09-14 18:46:51 -0600 | [diff] [blame] | 754 | printk(KERN_ERR MYNAM "%s@%d::_ioctl_fwdl - " |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 755 | "Unable to copy mpt_fw_xfer struct @ %p\n", |
| 756 | __FILE__, __LINE__, ufwdl); |
| 757 | return -EFAULT; |
| 758 | } |
| 759 | |
| 760 | return mptctl_do_fw_download(kfwdl.iocnum, kfwdl.bufp, kfwdl.fwlen); |
| 761 | } |
| 762 | |
| 763 | /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ |
| 764 | /* |
| 765 | * FW Download engine. |
| 766 | * Outputs: None. |
| 767 | * Return: 0 if successful |
| 768 | * -EFAULT if data unavailable |
| 769 | * -ENXIO if no such device |
| 770 | * -EAGAIN if resource problem |
| 771 | * -ENOMEM if no memory for SGE |
| 772 | * -EMLINK if too many chain buffers required |
| 773 | * -EBADRQC if adapter does not support FW download |
| 774 | * -EBUSY if adapter is busy |
| 775 | * -ENOMSG if FW upload returned bad status |
| 776 | */ |
| 777 | static int |
| 778 | mptctl_do_fw_download(int ioc, char __user *ufwbuf, size_t fwlen) |
| 779 | { |
| 780 | FWDownload_t *dlmsg; |
| 781 | MPT_FRAME_HDR *mf; |
| 782 | MPT_ADAPTER *iocp; |
| 783 | FWDownloadTCSGE_t *ptsge; |
| 784 | MptSge_t *sgl, *sgIn; |
| 785 | char *sgOut; |
| 786 | struct buflist *buflist; |
| 787 | struct buflist *bl; |
| 788 | dma_addr_t sgl_dma; |
| 789 | int ret; |
| 790 | int numfrags = 0; |
| 791 | int maxfrags; |
| 792 | int n = 0; |
| 793 | u32 sgdir; |
| 794 | u32 nib; |
| 795 | int fw_bytes_copied = 0; |
| 796 | int i; |
| 797 | int sge_offset = 0; |
| 798 | u16 iocstat; |
| 799 | pFWDownloadReply_t ReplyMsg = NULL; |
Kashyap, Desai | ea2a788 | 2009-05-29 16:46:50 +0530 | [diff] [blame] | 800 | unsigned long timeleft; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 801 | |
Moore, Eric | 946cbf0 | 2006-02-02 17:19:50 -0700 | [diff] [blame] | 802 | if (mpt_verify_adapter(ioc, &iocp) < 0) { |
Eric Moore | 29dd360 | 2007-09-14 18:46:51 -0600 | [diff] [blame] | 803 | printk(KERN_DEBUG MYNAM "ioctl_fwdl - ioc%d not found!\n", |
| 804 | ioc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 805 | return -ENODEV; /* (-6) No such device or address */ |
Moore, Eric | 946cbf0 | 2006-02-02 17:19:50 -0700 | [diff] [blame] | 806 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 807 | |
Moore, Eric | 946cbf0 | 2006-02-02 17:19:50 -0700 | [diff] [blame] | 808 | /* Valid device. Get a message frame and construct the FW download message. |
| 809 | */ |
| 810 | if ((mf = mpt_get_msg_frame(mptctl_id, iocp)) == NULL) |
| 811 | return -EAGAIN; |
| 812 | } |
Prakash, Sathya | 09120a8 | 2007-07-24 15:49:05 +0530 | [diff] [blame] | 813 | |
| 814 | dctlprintk(iocp, printk(MYIOC_s_DEBUG_FMT |
| 815 | "mptctl_do_fwdl called. mptctl_id = %xh.\n", iocp->name, mptctl_id)); |
| 816 | dctlprintk(iocp, printk(MYIOC_s_DEBUG_FMT "DbG: kfwdl.bufp = %p\n", |
| 817 | iocp->name, ufwbuf)); |
| 818 | dctlprintk(iocp, printk(MYIOC_s_DEBUG_FMT "DbG: kfwdl.fwlen = %d\n", |
| 819 | iocp->name, (int)fwlen)); |
| 820 | dctlprintk(iocp, printk(MYIOC_s_DEBUG_FMT "DbG: kfwdl.ioc = %04xh\n", |
| 821 | iocp->name, ioc)); |
| 822 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 823 | dlmsg = (FWDownload_t*) mf; |
| 824 | ptsge = (FWDownloadTCSGE_t *) &dlmsg->SGL; |
| 825 | sgOut = (char *) (ptsge + 1); |
| 826 | |
| 827 | /* |
| 828 | * Construct f/w download request |
| 829 | */ |
| 830 | dlmsg->ImageType = MPI_FW_DOWNLOAD_ITYPE_FW; |
| 831 | dlmsg->Reserved = 0; |
| 832 | dlmsg->ChainOffset = 0; |
| 833 | dlmsg->Function = MPI_FUNCTION_FW_DOWNLOAD; |
| 834 | dlmsg->Reserved1[0] = dlmsg->Reserved1[1] = dlmsg->Reserved1[2] = 0; |
Moore, Eric | 946cbf0 | 2006-02-02 17:19:50 -0700 | [diff] [blame] | 835 | if (iocp->facts.MsgVersion >= MPI_VERSION_01_05) |
| 836 | dlmsg->MsgFlags = MPI_FW_DOWNLOAD_MSGFLGS_LAST_SEGMENT; |
| 837 | else |
| 838 | dlmsg->MsgFlags = 0; |
| 839 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 840 | |
| 841 | /* Set up the Transaction SGE. |
| 842 | */ |
| 843 | ptsge->Reserved = 0; |
| 844 | ptsge->ContextSize = 0; |
| 845 | ptsge->DetailsLength = 12; |
| 846 | ptsge->Flags = MPI_SGE_FLAGS_TRANSACTION_ELEMENT; |
| 847 | ptsge->Reserved_0100_Checksum = 0; |
| 848 | ptsge->ImageOffset = 0; |
| 849 | ptsge->ImageSize = cpu_to_le32(fwlen); |
| 850 | |
| 851 | /* Add the SGL |
| 852 | */ |
| 853 | |
| 854 | /* |
| 855 | * Need to kmalloc area(s) for holding firmware image bytes. |
| 856 | * But we need to do it piece meal, using a proper |
| 857 | * scatter gather list (with 128kB MAX hunks). |
| 858 | * |
| 859 | * A practical limit here might be # of sg hunks that fit into |
| 860 | * a single IOC request frame; 12 or 8 (see below), so: |
| 861 | * For FC9xx: 12 x 128kB == 1.5 mB (max) |
| 862 | * For C1030: 8 x 128kB == 1 mB (max) |
| 863 | * We could support chaining, but things get ugly(ier:) |
| 864 | * |
| 865 | * Set the sge_offset to the start of the sgl (bytes). |
| 866 | */ |
| 867 | sgdir = 0x04000000; /* IOC will READ from sys mem */ |
| 868 | sge_offset = sizeof(MPIHeader_t) + sizeof(FWDownloadTCSGE_t); |
| 869 | if ((sgl = kbuf_alloc_2_sgl(fwlen, sgdir, sge_offset, |
| 870 | &numfrags, &buflist, &sgl_dma, iocp)) == NULL) |
| 871 | return -ENOMEM; |
| 872 | |
| 873 | /* |
| 874 | * We should only need SGL with 2 simple_32bit entries (up to 256 kB) |
| 875 | * for FC9xx f/w image, but calculate max number of sge hunks |
| 876 | * we can fit into a request frame, and limit ourselves to that. |
| 877 | * (currently no chain support) |
| 878 | * maxfrags = (Request Size - FWdownload Size ) / Size of 32 bit SGE |
| 879 | * Request maxfrags |
| 880 | * 128 12 |
| 881 | * 96 8 |
| 882 | * 64 4 |
| 883 | */ |
Kashyap, Desai | 14d0f0b | 2009-05-29 16:37:04 +0530 | [diff] [blame] | 884 | maxfrags = (iocp->req_sz - sizeof(MPIHeader_t) - |
| 885 | sizeof(FWDownloadTCSGE_t)) |
| 886 | / iocp->SGE_size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 887 | if (numfrags > maxfrags) { |
| 888 | ret = -EMLINK; |
| 889 | goto fwdl_out; |
| 890 | } |
| 891 | |
Prakash, Sathya | 09120a8 | 2007-07-24 15:49:05 +0530 | [diff] [blame] | 892 | dctlprintk(iocp, printk(MYIOC_s_DEBUG_FMT "DbG: sgl buffer = %p, sgfrags = %d\n", |
| 893 | iocp->name, sgl, numfrags)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 894 | |
| 895 | /* |
| 896 | * Parse SG list, copying sgl itself, |
| 897 | * plus f/w image hunks from user space as we go... |
| 898 | */ |
| 899 | ret = -EFAULT; |
| 900 | sgIn = sgl; |
| 901 | bl = buflist; |
| 902 | for (i=0; i < numfrags; i++) { |
| 903 | |
| 904 | /* Get the SGE type: 0 - TCSGE, 3 - Chain, 1 - Simple SGE |
| 905 | * Skip everything but Simple. If simple, copy from |
| 906 | * user space into kernel space. |
| 907 | * Note: we should not have anything but Simple as |
| 908 | * Chain SGE are illegal. |
| 909 | */ |
| 910 | nib = (sgIn->FlagsLength & 0x30000000) >> 28; |
| 911 | if (nib == 0 || nib == 3) { |
| 912 | ; |
| 913 | } else if (sgIn->Address) { |
Kashyap, Desai | 14d0f0b | 2009-05-29 16:37:04 +0530 | [diff] [blame] | 914 | iocp->add_sge(sgOut, sgIn->FlagsLength, sgIn->Address); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 915 | n++; |
| 916 | if (copy_from_user(bl->kptr, ufwbuf+fw_bytes_copied, bl->len)) { |
Eric Moore | 29dd360 | 2007-09-14 18:46:51 -0600 | [diff] [blame] | 917 | printk(MYIOC_s_ERR_FMT "%s@%d::_ioctl_fwdl - " |
| 918 | "Unable to copy f/w buffer hunk#%d @ %p\n", |
| 919 | iocp->name, __FILE__, __LINE__, n, ufwbuf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 920 | goto fwdl_out; |
| 921 | } |
| 922 | fw_bytes_copied += bl->len; |
| 923 | } |
| 924 | sgIn++; |
| 925 | bl++; |
Kashyap, Desai | 14d0f0b | 2009-05-29 16:37:04 +0530 | [diff] [blame] | 926 | sgOut += iocp->SGE_size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 927 | } |
| 928 | |
Prakash, Sathya | 09120a8 | 2007-07-24 15:49:05 +0530 | [diff] [blame] | 929 | DBG_DUMP_FW_DOWNLOAD(iocp, (u32 *)mf, numfrags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 930 | |
| 931 | /* |
| 932 | * Finally, perform firmware download. |
| 933 | */ |
Moore, Eric | 946cbf0 | 2006-02-02 17:19:50 -0700 | [diff] [blame] | 934 | ReplyMsg = NULL; |
Kashyap, Desai | ea2a788 | 2009-05-29 16:46:50 +0530 | [diff] [blame] | 935 | SET_MGMT_MSG_CONTEXT(iocp->ioctl_cmds.msg_context, dlmsg->MsgContext); |
| 936 | INITIALIZE_MGMT_STATUS(iocp->ioctl_cmds.status) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 937 | mpt_put_msg_frame(mptctl_id, iocp, mf); |
| 938 | |
| 939 | /* Now wait for the command to complete */ |
Kashyap, Desai | ea2a788 | 2009-05-29 16:46:50 +0530 | [diff] [blame] | 940 | retry_wait: |
| 941 | timeleft = wait_for_completion_timeout(&iocp->ioctl_cmds.done, HZ*60); |
| 942 | if (!(iocp->ioctl_cmds.status & MPT_MGMT_STATUS_COMMAND_GOOD)) { |
| 943 | ret = -ETIME; |
| 944 | printk(MYIOC_s_WARN_FMT "%s: failed\n", iocp->name, __func__); |
| 945 | if (iocp->ioctl_cmds.status & MPT_MGMT_STATUS_DID_IOCRESET) { |
| 946 | mpt_free_msg_frame(iocp, mf); |
| 947 | goto fwdl_out; |
| 948 | } |
| 949 | if (!timeleft) |
| 950 | mptctl_timeout_expired(iocp, mf); |
| 951 | else |
| 952 | goto retry_wait; |
| 953 | goto fwdl_out; |
| 954 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 955 | |
Kashyap, Desai | ea2a788 | 2009-05-29 16:46:50 +0530 | [diff] [blame] | 956 | if (!(iocp->ioctl_cmds.status & MPT_MGMT_STATUS_RF_VALID)) { |
| 957 | printk(MYIOC_s_WARN_FMT "%s: failed\n", iocp->name, __func__); |
| 958 | mpt_free_msg_frame(iocp, mf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 959 | ret = -ENODATA; |
| 960 | goto fwdl_out; |
| 961 | } |
| 962 | |
| 963 | if (sgl) |
| 964 | kfree_sgl(sgl, sgl_dma, buflist, iocp); |
| 965 | |
Kashyap, Desai | ea2a788 | 2009-05-29 16:46:50 +0530 | [diff] [blame] | 966 | ReplyMsg = (pFWDownloadReply_t)iocp->ioctl_cmds.reply; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 967 | iocstat = le16_to_cpu(ReplyMsg->IOCStatus) & MPI_IOCSTATUS_MASK; |
| 968 | if (iocstat == MPI_IOCSTATUS_SUCCESS) { |
Eric Moore | 29dd360 | 2007-09-14 18:46:51 -0600 | [diff] [blame] | 969 | printk(MYIOC_s_INFO_FMT "F/W update successfull!\n", iocp->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 970 | return 0; |
| 971 | } else if (iocstat == MPI_IOCSTATUS_INVALID_FUNCTION) { |
Eric Moore | 29dd360 | 2007-09-14 18:46:51 -0600 | [diff] [blame] | 972 | printk(MYIOC_s_WARN_FMT "Hmmm... F/W download not supported!?!\n", |
| 973 | iocp->name); |
| 974 | printk(MYIOC_s_WARN_FMT "(time to go bang on somebodies door)\n", |
| 975 | iocp->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 976 | return -EBADRQC; |
| 977 | } else if (iocstat == MPI_IOCSTATUS_BUSY) { |
Eric Moore | 29dd360 | 2007-09-14 18:46:51 -0600 | [diff] [blame] | 978 | printk(MYIOC_s_WARN_FMT "IOC_BUSY!\n", iocp->name); |
| 979 | printk(MYIOC_s_WARN_FMT "(try again later?)\n", iocp->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 980 | return -EBUSY; |
| 981 | } else { |
Eric Moore | 29dd360 | 2007-09-14 18:46:51 -0600 | [diff] [blame] | 982 | printk(MYIOC_s_WARN_FMT "ioctl_fwdl() returned [bad] status = %04xh\n", |
| 983 | iocp->name, iocstat); |
| 984 | printk(MYIOC_s_WARN_FMT "(bad VooDoo)\n", iocp->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 985 | return -ENOMSG; |
| 986 | } |
| 987 | return 0; |
| 988 | |
| 989 | fwdl_out: |
Kashyap, Desai | ea2a788 | 2009-05-29 16:46:50 +0530 | [diff] [blame] | 990 | |
| 991 | CLEAR_MGMT_STATUS(iocp->ioctl_cmds.status); |
| 992 | SET_MGMT_MSG_CONTEXT(iocp->ioctl_cmds.msg_context, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 993 | kfree_sgl(sgl, sgl_dma, buflist, iocp); |
| 994 | return ret; |
| 995 | } |
| 996 | |
| 997 | /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ |
| 998 | /* |
| 999 | * SGE Allocation routine |
| 1000 | * |
| 1001 | * Inputs: bytes - number of bytes to be transferred |
| 1002 | * sgdir - data direction |
| 1003 | * sge_offset - offset (in bytes) from the start of the request |
| 1004 | * frame to the first SGE |
| 1005 | * ioc - pointer to the mptadapter |
| 1006 | * Outputs: frags - number of scatter gather elements |
| 1007 | * blp - point to the buflist pointer |
| 1008 | * sglbuf_dma - pointer to the (dma) sgl |
| 1009 | * Returns: Null if failes |
| 1010 | * pointer to the (virtual) sgl if successful. |
| 1011 | */ |
| 1012 | static MptSge_t * |
| 1013 | kbuf_alloc_2_sgl(int bytes, u32 sgdir, int sge_offset, int *frags, |
| 1014 | struct buflist **blp, dma_addr_t *sglbuf_dma, MPT_ADAPTER *ioc) |
| 1015 | { |
| 1016 | MptSge_t *sglbuf = NULL; /* pointer to array of SGE */ |
| 1017 | /* and chain buffers */ |
| 1018 | struct buflist *buflist = NULL; /* kernel routine */ |
| 1019 | MptSge_t *sgl; |
| 1020 | int numfrags = 0; |
| 1021 | int fragcnt = 0; |
| 1022 | int alloc_sz = min(bytes,MAX_KMALLOC_SZ); // avoid kernel warning msg! |
| 1023 | int bytes_allocd = 0; |
| 1024 | int this_alloc; |
| 1025 | dma_addr_t pa; // phys addr |
| 1026 | int i, buflist_ent; |
| 1027 | int sg_spill = MAX_FRAGS_SPILL1; |
| 1028 | int dir; |
| 1029 | /* initialization */ |
| 1030 | *frags = 0; |
| 1031 | *blp = NULL; |
| 1032 | |
| 1033 | /* Allocate and initialize an array of kernel |
| 1034 | * structures for the SG elements. |
| 1035 | */ |
| 1036 | i = MAX_SGL_BYTES / 8; |
Mariusz Kozlowski | d7383a2 | 2007-08-10 14:50:50 -0700 | [diff] [blame] | 1037 | buflist = kzalloc(i, GFP_USER); |
| 1038 | if (!buflist) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1039 | return NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1040 | buflist_ent = 0; |
| 1041 | |
| 1042 | /* Allocate a single block of memory to store the sg elements and |
| 1043 | * the chain buffers. The calling routine is responsible for |
| 1044 | * copying the data in this array into the correct place in the |
| 1045 | * request and chain buffers. |
| 1046 | */ |
| 1047 | sglbuf = pci_alloc_consistent(ioc->pcidev, MAX_SGL_BYTES, sglbuf_dma); |
| 1048 | if (sglbuf == NULL) |
| 1049 | goto free_and_fail; |
| 1050 | |
| 1051 | if (sgdir & 0x04000000) |
| 1052 | dir = PCI_DMA_TODEVICE; |
| 1053 | else |
| 1054 | dir = PCI_DMA_FROMDEVICE; |
| 1055 | |
| 1056 | /* At start: |
| 1057 | * sgl = sglbuf = point to beginning of sg buffer |
| 1058 | * buflist_ent = 0 = first kernel structure |
| 1059 | * sg_spill = number of SGE that can be written before the first |
| 1060 | * chain element. |
| 1061 | * |
| 1062 | */ |
| 1063 | sgl = sglbuf; |
Kashyap, Desai | 14d0f0b | 2009-05-29 16:37:04 +0530 | [diff] [blame] | 1064 | sg_spill = ((ioc->req_sz - sge_offset)/ioc->SGE_size) - 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1065 | while (bytes_allocd < bytes) { |
| 1066 | this_alloc = min(alloc_sz, bytes-bytes_allocd); |
| 1067 | buflist[buflist_ent].len = this_alloc; |
| 1068 | buflist[buflist_ent].kptr = pci_alloc_consistent(ioc->pcidev, |
| 1069 | this_alloc, |
| 1070 | &pa); |
| 1071 | if (buflist[buflist_ent].kptr == NULL) { |
| 1072 | alloc_sz = alloc_sz / 2; |
| 1073 | if (alloc_sz == 0) { |
Eric Moore | 29dd360 | 2007-09-14 18:46:51 -0600 | [diff] [blame] | 1074 | printk(MYIOC_s_WARN_FMT "-SG: No can do - " |
| 1075 | "not enough memory! :-(\n", ioc->name); |
| 1076 | printk(MYIOC_s_WARN_FMT "-SG: (freeing %d frags)\n", |
| 1077 | ioc->name, numfrags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1078 | goto free_and_fail; |
| 1079 | } |
| 1080 | continue; |
| 1081 | } else { |
| 1082 | dma_addr_t dma_addr; |
| 1083 | |
| 1084 | bytes_allocd += this_alloc; |
Kashyap, Desai | 14d0f0b | 2009-05-29 16:37:04 +0530 | [diff] [blame] | 1085 | sgl->FlagsLength = (0x10000000|sgdir|this_alloc); |
| 1086 | dma_addr = pci_map_single(ioc->pcidev, |
| 1087 | buflist[buflist_ent].kptr, this_alloc, dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1088 | sgl->Address = dma_addr; |
| 1089 | |
| 1090 | fragcnt++; |
| 1091 | numfrags++; |
| 1092 | sgl++; |
| 1093 | buflist_ent++; |
| 1094 | } |
| 1095 | |
| 1096 | if (bytes_allocd >= bytes) |
| 1097 | break; |
| 1098 | |
| 1099 | /* Need to chain? */ |
| 1100 | if (fragcnt == sg_spill) { |
Eric Moore | 29dd360 | 2007-09-14 18:46:51 -0600 | [diff] [blame] | 1101 | printk(MYIOC_s_WARN_FMT |
| 1102 | "-SG: No can do - " "Chain required! :-(\n", ioc->name); |
| 1103 | printk(MYIOC_s_WARN_FMT "(freeing %d frags)\n", ioc->name, numfrags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1104 | goto free_and_fail; |
| 1105 | } |
| 1106 | |
| 1107 | /* overflow check... */ |
| 1108 | if (numfrags*8 > MAX_SGL_BYTES){ |
| 1109 | /* GRRRRR... */ |
Eric Moore | 29dd360 | 2007-09-14 18:46:51 -0600 | [diff] [blame] | 1110 | printk(MYIOC_s_WARN_FMT "-SG: No can do - " |
| 1111 | "too many SG frags! :-(\n", ioc->name); |
| 1112 | printk(MYIOC_s_WARN_FMT "-SG: (freeing %d frags)\n", |
| 1113 | ioc->name, numfrags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1114 | goto free_and_fail; |
| 1115 | } |
| 1116 | } |
| 1117 | |
| 1118 | /* Last sge fixup: set LE+eol+eob bits */ |
| 1119 | sgl[-1].FlagsLength |= 0xC1000000; |
| 1120 | |
| 1121 | *frags = numfrags; |
| 1122 | *blp = buflist; |
| 1123 | |
Prakash, Sathya | 09120a8 | 2007-07-24 15:49:05 +0530 | [diff] [blame] | 1124 | dctlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "-SG: kbuf_alloc_2_sgl() - " |
| 1125 | "%d SG frags generated!\n", ioc->name, numfrags)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1126 | |
Prakash, Sathya | 09120a8 | 2007-07-24 15:49:05 +0530 | [diff] [blame] | 1127 | dctlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "-SG: kbuf_alloc_2_sgl() - " |
| 1128 | "last (big) alloc_sz=%d\n", ioc->name, alloc_sz)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1129 | |
| 1130 | return sglbuf; |
| 1131 | |
| 1132 | free_and_fail: |
| 1133 | if (sglbuf != NULL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1134 | for (i = 0; i < numfrags; i++) { |
| 1135 | dma_addr_t dma_addr; |
| 1136 | u8 *kptr; |
| 1137 | int len; |
| 1138 | |
| 1139 | if ((sglbuf[i].FlagsLength >> 24) == 0x30) |
| 1140 | continue; |
| 1141 | |
| 1142 | dma_addr = sglbuf[i].Address; |
| 1143 | kptr = buflist[i].kptr; |
| 1144 | len = buflist[i].len; |
| 1145 | |
| 1146 | pci_free_consistent(ioc->pcidev, len, kptr, dma_addr); |
| 1147 | } |
| 1148 | pci_free_consistent(ioc->pcidev, MAX_SGL_BYTES, sglbuf, *sglbuf_dma); |
| 1149 | } |
| 1150 | kfree(buflist); |
| 1151 | return NULL; |
| 1152 | } |
| 1153 | |
| 1154 | /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ |
| 1155 | /* |
| 1156 | * Routine to free the SGL elements. |
| 1157 | */ |
| 1158 | static void |
| 1159 | kfree_sgl(MptSge_t *sgl, dma_addr_t sgl_dma, struct buflist *buflist, MPT_ADAPTER *ioc) |
| 1160 | { |
| 1161 | MptSge_t *sg = sgl; |
| 1162 | struct buflist *bl = buflist; |
| 1163 | u32 nib; |
| 1164 | int dir; |
| 1165 | int n = 0; |
| 1166 | |
| 1167 | if (sg->FlagsLength & 0x04000000) |
| 1168 | dir = PCI_DMA_TODEVICE; |
| 1169 | else |
| 1170 | dir = PCI_DMA_FROMDEVICE; |
| 1171 | |
| 1172 | nib = (sg->FlagsLength & 0xF0000000) >> 28; |
| 1173 | while (! (nib & 0x4)) { /* eob */ |
| 1174 | /* skip ignore/chain. */ |
| 1175 | if (nib == 0 || nib == 3) { |
| 1176 | ; |
| 1177 | } else if (sg->Address) { |
| 1178 | dma_addr_t dma_addr; |
| 1179 | void *kptr; |
| 1180 | int len; |
| 1181 | |
| 1182 | dma_addr = sg->Address; |
| 1183 | kptr = bl->kptr; |
| 1184 | len = bl->len; |
| 1185 | pci_unmap_single(ioc->pcidev, dma_addr, len, dir); |
| 1186 | pci_free_consistent(ioc->pcidev, len, kptr, dma_addr); |
| 1187 | n++; |
| 1188 | } |
| 1189 | sg++; |
| 1190 | bl++; |
| 1191 | nib = (le32_to_cpu(sg->FlagsLength) & 0xF0000000) >> 28; |
| 1192 | } |
| 1193 | |
| 1194 | /* we're at eob! */ |
| 1195 | if (sg->Address) { |
| 1196 | dma_addr_t dma_addr; |
| 1197 | void *kptr; |
| 1198 | int len; |
| 1199 | |
| 1200 | dma_addr = sg->Address; |
| 1201 | kptr = bl->kptr; |
| 1202 | len = bl->len; |
| 1203 | pci_unmap_single(ioc->pcidev, dma_addr, len, dir); |
| 1204 | pci_free_consistent(ioc->pcidev, len, kptr, dma_addr); |
| 1205 | n++; |
| 1206 | } |
| 1207 | |
| 1208 | pci_free_consistent(ioc->pcidev, MAX_SGL_BYTES, sgl, sgl_dma); |
| 1209 | kfree(buflist); |
Prakash, Sathya | 09120a8 | 2007-07-24 15:49:05 +0530 | [diff] [blame] | 1210 | dctlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "-SG: Free'd 1 SGL buf + %d kbufs!\n", |
| 1211 | ioc->name, n)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1212 | } |
| 1213 | |
| 1214 | /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ |
| 1215 | /* |
| 1216 | * mptctl_getiocinfo - Query the host adapter for IOC information. |
| 1217 | * @arg: User space argument |
| 1218 | * |
| 1219 | * Outputs: None. |
| 1220 | * Return: 0 if successful |
| 1221 | * -EFAULT if data unavailable |
| 1222 | * -ENODEV if no such device/adapter |
| 1223 | */ |
| 1224 | static int |
| 1225 | mptctl_getiocinfo (unsigned long arg, unsigned int data_size) |
| 1226 | { |
| 1227 | struct mpt_ioctl_iocinfo __user *uarg = (void __user *) arg; |
| 1228 | struct mpt_ioctl_iocinfo *karg; |
| 1229 | MPT_ADAPTER *ioc; |
| 1230 | struct pci_dev *pdev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1231 | int iocnum; |
Moore, Eric Dean | b6fe4dd | 2005-04-22 18:01:34 -0400 | [diff] [blame] | 1232 | unsigned int port; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1233 | int cim_rev; |
| 1234 | u8 revision; |
Eric Moore | 793955f | 2007-01-29 09:42:20 -0700 | [diff] [blame] | 1235 | struct scsi_device *sdev; |
Eric Moore | a69de50 | 2007-09-14 18:48:19 -0600 | [diff] [blame] | 1236 | VirtDevice *vdevice; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1237 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1238 | /* Add of PCI INFO results in unaligned access for |
| 1239 | * IA64 and Sparc. Reset long to int. Return no PCI |
| 1240 | * data for obsolete format. |
| 1241 | */ |
| 1242 | if (data_size == sizeof(struct mpt_ioctl_iocinfo_rev0)) |
| 1243 | cim_rev = 0; |
| 1244 | else if (data_size == sizeof(struct mpt_ioctl_iocinfo_rev1)) |
| 1245 | cim_rev = 1; |
| 1246 | else if (data_size == sizeof(struct mpt_ioctl_iocinfo)) |
| 1247 | cim_rev = 2; |
| 1248 | else if (data_size == (sizeof(struct mpt_ioctl_iocinfo_rev0)+12)) |
| 1249 | cim_rev = 0; /* obsolete */ |
| 1250 | else |
| 1251 | return -EFAULT; |
| 1252 | |
| 1253 | karg = kmalloc(data_size, GFP_KERNEL); |
| 1254 | if (karg == NULL) { |
Eric Moore | 29dd360 | 2007-09-14 18:46:51 -0600 | [diff] [blame] | 1255 | printk(KERN_ERR MYNAM "%s::mpt_ioctl_iocinfo() @%d - no memory available!\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1256 | __FILE__, __LINE__); |
| 1257 | return -ENOMEM; |
| 1258 | } |
| 1259 | |
| 1260 | if (copy_from_user(karg, uarg, data_size)) { |
Eric Moore | 29dd360 | 2007-09-14 18:46:51 -0600 | [diff] [blame] | 1261 | printk(KERN_ERR MYNAM "%s@%d::mptctl_getiocinfo - " |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1262 | "Unable to read in mpt_ioctl_iocinfo struct @ %p\n", |
| 1263 | __FILE__, __LINE__, uarg); |
| 1264 | kfree(karg); |
| 1265 | return -EFAULT; |
| 1266 | } |
| 1267 | |
| 1268 | if (((iocnum = mpt_verify_adapter(karg->hdr.iocnum, &ioc)) < 0) || |
| 1269 | (ioc == NULL)) { |
Eric Moore | 29dd360 | 2007-09-14 18:46:51 -0600 | [diff] [blame] | 1270 | printk(KERN_DEBUG MYNAM "%s::mptctl_getiocinfo() @%d - ioc%d not found!\n", |
Prakash, Sathya | 09120a8 | 2007-07-24 15:49:05 +0530 | [diff] [blame] | 1271 | __FILE__, __LINE__, iocnum); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1272 | kfree(karg); |
| 1273 | return -ENODEV; |
| 1274 | } |
| 1275 | |
Moore, Eric Dean | b6fe4dd | 2005-04-22 18:01:34 -0400 | [diff] [blame] | 1276 | /* Verify the data transfer size is correct. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1277 | if (karg->hdr.maxDataSize != data_size) { |
Eric Moore | 29dd360 | 2007-09-14 18:46:51 -0600 | [diff] [blame] | 1278 | printk(MYIOC_s_ERR_FMT "%s@%d::mptctl_getiocinfo - " |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1279 | "Structure size mismatch. Command not completed.\n", |
Eric Moore | 29dd360 | 2007-09-14 18:46:51 -0600 | [diff] [blame] | 1280 | ioc->name, __FILE__, __LINE__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1281 | kfree(karg); |
| 1282 | return -EFAULT; |
| 1283 | } |
| 1284 | |
Prakash, Sathya | 09120a8 | 2007-07-24 15:49:05 +0530 | [diff] [blame] | 1285 | dctlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "mptctl_getiocinfo called.\n", |
| 1286 | ioc->name)); |
| 1287 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1288 | /* Fill in the data and return the structure to the calling |
| 1289 | * program |
| 1290 | */ |
Moore, Eric | 9cc1cfb | 2006-02-02 17:19:33 -0700 | [diff] [blame] | 1291 | if (ioc->bus_type == SAS) |
| 1292 | karg->adapterType = MPT_IOCTL_INTERFACE_SAS; |
| 1293 | else if (ioc->bus_type == FC) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1294 | karg->adapterType = MPT_IOCTL_INTERFACE_FC; |
| 1295 | else |
| 1296 | karg->adapterType = MPT_IOCTL_INTERFACE_SCSI; |
| 1297 | |
Moore, Eric Dean | b6fe4dd | 2005-04-22 18:01:34 -0400 | [diff] [blame] | 1298 | if (karg->hdr.port > 1) |
| 1299 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1300 | port = karg->hdr.port; |
| 1301 | |
| 1302 | karg->port = port; |
| 1303 | pdev = (struct pci_dev *) ioc->pcidev; |
| 1304 | |
| 1305 | karg->pciId = pdev->device; |
| 1306 | pci_read_config_byte(pdev, PCI_CLASS_REVISION, &revision); |
| 1307 | karg->hwRev = revision; |
| 1308 | karg->subSystemDevice = pdev->subsystem_device; |
| 1309 | karg->subSystemVendor = pdev->subsystem_vendor; |
| 1310 | |
| 1311 | if (cim_rev == 1) { |
| 1312 | /* Get the PCI bus, device, and function numbers for the IOC |
| 1313 | */ |
| 1314 | karg->pciInfo.u.bits.busNumber = pdev->bus->number; |
| 1315 | karg->pciInfo.u.bits.deviceNumber = PCI_SLOT( pdev->devfn ); |
| 1316 | karg->pciInfo.u.bits.functionNumber = PCI_FUNC( pdev->devfn ); |
| 1317 | } else if (cim_rev == 2) { |
Moore, Eric | 86a7dca | 2006-02-02 17:19:37 -0700 | [diff] [blame] | 1318 | /* Get the PCI bus, device, function and segment ID numbers |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1319 | for the IOC */ |
| 1320 | karg->pciInfo.u.bits.busNumber = pdev->bus->number; |
| 1321 | karg->pciInfo.u.bits.deviceNumber = PCI_SLOT( pdev->devfn ); |
| 1322 | karg->pciInfo.u.bits.functionNumber = PCI_FUNC( pdev->devfn ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1323 | karg->pciInfo.segmentID = pci_domain_nr(pdev->bus); |
| 1324 | } |
| 1325 | |
| 1326 | /* Get number of devices |
| 1327 | */ |
Eric Moore | 793955f | 2007-01-29 09:42:20 -0700 | [diff] [blame] | 1328 | karg->numDevices = 0; |
| 1329 | if (ioc->sh) { |
| 1330 | shost_for_each_device(sdev, ioc->sh) { |
Eric Moore | a69de50 | 2007-09-14 18:48:19 -0600 | [diff] [blame] | 1331 | vdevice = sdev->hostdata; |
| 1332 | if (vdevice->vtarget->tflags & |
Eric Moore | 793955f | 2007-01-29 09:42:20 -0700 | [diff] [blame] | 1333 | MPT_TARGET_FLAGS_RAID_COMPONENT) |
| 1334 | continue; |
| 1335 | karg->numDevices++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1336 | } |
| 1337 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1338 | |
| 1339 | /* Set the BIOS and FW Version |
| 1340 | */ |
| 1341 | karg->FWVersion = ioc->facts.FWVersion.Word; |
| 1342 | karg->BIOSVersion = ioc->biosVersion; |
| 1343 | |
| 1344 | /* Set the Version Strings. |
| 1345 | */ |
| 1346 | strncpy (karg->driverVersion, MPT_LINUX_PACKAGE_NAME, MPT_IOCTL_VERSION_LENGTH); |
| 1347 | karg->driverVersion[MPT_IOCTL_VERSION_LENGTH-1]='\0'; |
| 1348 | |
| 1349 | karg->busChangeEvent = 0; |
| 1350 | karg->hostId = ioc->pfacts[port].PortSCSIID; |
| 1351 | karg->rsvd[0] = karg->rsvd[1] = 0; |
| 1352 | |
| 1353 | /* Copy the data from kernel memory to user memory |
| 1354 | */ |
| 1355 | if (copy_to_user((char __user *)arg, karg, data_size)) { |
Eric Moore | 29dd360 | 2007-09-14 18:46:51 -0600 | [diff] [blame] | 1356 | printk(MYIOC_s_ERR_FMT "%s@%d::mptctl_getiocinfo - " |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1357 | "Unable to write out mpt_ioctl_iocinfo struct @ %p\n", |
Eric Moore | 29dd360 | 2007-09-14 18:46:51 -0600 | [diff] [blame] | 1358 | ioc->name, __FILE__, __LINE__, uarg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1359 | kfree(karg); |
| 1360 | return -EFAULT; |
| 1361 | } |
| 1362 | |
| 1363 | kfree(karg); |
| 1364 | return 0; |
| 1365 | } |
| 1366 | |
| 1367 | /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ |
| 1368 | /* |
| 1369 | * mptctl_gettargetinfo - Query the host adapter for target information. |
| 1370 | * @arg: User space argument |
| 1371 | * |
| 1372 | * Outputs: None. |
| 1373 | * Return: 0 if successful |
| 1374 | * -EFAULT if data unavailable |
| 1375 | * -ENODEV if no such device/adapter |
| 1376 | */ |
| 1377 | static int |
| 1378 | mptctl_gettargetinfo (unsigned long arg) |
| 1379 | { |
| 1380 | struct mpt_ioctl_targetinfo __user *uarg = (void __user *) arg; |
| 1381 | struct mpt_ioctl_targetinfo karg; |
| 1382 | MPT_ADAPTER *ioc; |
Eric Moore | a69de50 | 2007-09-14 18:48:19 -0600 | [diff] [blame] | 1383 | VirtDevice *vdevice; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1384 | char *pmem; |
| 1385 | int *pdata; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1386 | int iocnum; |
| 1387 | int numDevices = 0; |
Eric Moore | 793955f | 2007-01-29 09:42:20 -0700 | [diff] [blame] | 1388 | int lun; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1389 | int maxWordsLeft; |
| 1390 | int numBytes; |
Eric Moore | 793955f | 2007-01-29 09:42:20 -0700 | [diff] [blame] | 1391 | u8 port; |
| 1392 | struct scsi_device *sdev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1393 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1394 | if (copy_from_user(&karg, uarg, sizeof(struct mpt_ioctl_targetinfo))) { |
Eric Moore | 29dd360 | 2007-09-14 18:46:51 -0600 | [diff] [blame] | 1395 | printk(KERN_ERR MYNAM "%s@%d::mptctl_gettargetinfo - " |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1396 | "Unable to read in mpt_ioctl_targetinfo struct @ %p\n", |
| 1397 | __FILE__, __LINE__, uarg); |
| 1398 | return -EFAULT; |
| 1399 | } |
| 1400 | |
| 1401 | if (((iocnum = mpt_verify_adapter(karg.hdr.iocnum, &ioc)) < 0) || |
| 1402 | (ioc == NULL)) { |
Eric Moore | 29dd360 | 2007-09-14 18:46:51 -0600 | [diff] [blame] | 1403 | printk(KERN_DEBUG MYNAM "%s::mptctl_gettargetinfo() @%d - ioc%d not found!\n", |
Prakash, Sathya | 09120a8 | 2007-07-24 15:49:05 +0530 | [diff] [blame] | 1404 | __FILE__, __LINE__, iocnum); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1405 | return -ENODEV; |
| 1406 | } |
| 1407 | |
Prakash, Sathya | 09120a8 | 2007-07-24 15:49:05 +0530 | [diff] [blame] | 1408 | dctlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "mptctl_gettargetinfo called.\n", |
| 1409 | ioc->name)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1410 | /* Get the port number and set the maximum number of bytes |
| 1411 | * in the returned structure. |
| 1412 | * Ignore the port setting. |
| 1413 | */ |
| 1414 | numBytes = karg.hdr.maxDataSize - sizeof(mpt_ioctl_header); |
| 1415 | maxWordsLeft = numBytes/sizeof(int); |
| 1416 | port = karg.hdr.port; |
| 1417 | |
| 1418 | if (maxWordsLeft <= 0) { |
Eric Moore | 29dd360 | 2007-09-14 18:46:51 -0600 | [diff] [blame] | 1419 | printk(MYIOC_s_ERR_FMT "%s@%d::mptctl_gettargetinfo() - no memory available!\n", |
| 1420 | ioc->name, __FILE__, __LINE__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1421 | return -ENOMEM; |
| 1422 | } |
| 1423 | |
| 1424 | /* Fill in the data and return the structure to the calling |
| 1425 | * program |
| 1426 | */ |
| 1427 | |
| 1428 | /* struct mpt_ioctl_targetinfo does not contain sufficient space |
| 1429 | * for the target structures so when the IOCTL is called, there is |
| 1430 | * not sufficient stack space for the structure. Allocate memory, |
| 1431 | * populate the memory, copy back to the user, then free memory. |
| 1432 | * targetInfo format: |
| 1433 | * bits 31-24: reserved |
| 1434 | * 23-16: LUN |
| 1435 | * 15- 8: Bus Number |
| 1436 | * 7- 0: Target ID |
| 1437 | */ |
Mariusz Kozlowski | d7383a2 | 2007-08-10 14:50:50 -0700 | [diff] [blame] | 1438 | pmem = kzalloc(numBytes, GFP_KERNEL); |
| 1439 | if (!pmem) { |
Eric Moore | 29dd360 | 2007-09-14 18:46:51 -0600 | [diff] [blame] | 1440 | printk(MYIOC_s_ERR_FMT "%s@%d::mptctl_gettargetinfo() - no memory available!\n", |
| 1441 | ioc->name, __FILE__, __LINE__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1442 | return -ENOMEM; |
| 1443 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1444 | pdata = (int *) pmem; |
| 1445 | |
| 1446 | /* Get number of devices |
| 1447 | */ |
Eric Moore | 793955f | 2007-01-29 09:42:20 -0700 | [diff] [blame] | 1448 | if (ioc->sh){ |
| 1449 | shost_for_each_device(sdev, ioc->sh) { |
| 1450 | if (!maxWordsLeft) |
| 1451 | continue; |
Eric Moore | a69de50 | 2007-09-14 18:48:19 -0600 | [diff] [blame] | 1452 | vdevice = sdev->hostdata; |
| 1453 | if (vdevice->vtarget->tflags & |
Eric Moore | 793955f | 2007-01-29 09:42:20 -0700 | [diff] [blame] | 1454 | MPT_TARGET_FLAGS_RAID_COMPONENT) |
| 1455 | continue; |
Eric Moore | a69de50 | 2007-09-14 18:48:19 -0600 | [diff] [blame] | 1456 | lun = (vdevice->vtarget->raidVolume) ? 0x80 : vdevice->lun; |
| 1457 | *pdata = (((u8)lun << 16) + (vdevice->vtarget->channel << 8) + |
| 1458 | (vdevice->vtarget->id )); |
Eric Moore | 793955f | 2007-01-29 09:42:20 -0700 | [diff] [blame] | 1459 | pdata++; |
| 1460 | numDevices++; |
| 1461 | --maxWordsLeft; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1462 | } |
| 1463 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1464 | karg.numDevices = numDevices; |
| 1465 | |
| 1466 | /* Copy part of the data from kernel memory to user memory |
| 1467 | */ |
| 1468 | if (copy_to_user((char __user *)arg, &karg, |
| 1469 | sizeof(struct mpt_ioctl_targetinfo))) { |
Eric Moore | 29dd360 | 2007-09-14 18:46:51 -0600 | [diff] [blame] | 1470 | printk(MYIOC_s_ERR_FMT "%s@%d::mptctl_gettargetinfo - " |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1471 | "Unable to write out mpt_ioctl_targetinfo struct @ %p\n", |
Eric Moore | 29dd360 | 2007-09-14 18:46:51 -0600 | [diff] [blame] | 1472 | ioc->name, __FILE__, __LINE__, uarg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1473 | kfree(pmem); |
| 1474 | return -EFAULT; |
| 1475 | } |
| 1476 | |
| 1477 | /* Copy the remaining data from kernel memory to user memory |
| 1478 | */ |
| 1479 | if (copy_to_user(uarg->targetInfo, pmem, numBytes)) { |
Eric Moore | 29dd360 | 2007-09-14 18:46:51 -0600 | [diff] [blame] | 1480 | printk(MYIOC_s_ERR_FMT "%s@%d::mptctl_gettargetinfo - " |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1481 | "Unable to write out mpt_ioctl_targetinfo struct @ %p\n", |
Eric Moore | 29dd360 | 2007-09-14 18:46:51 -0600 | [diff] [blame] | 1482 | ioc->name, __FILE__, __LINE__, pdata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1483 | kfree(pmem); |
| 1484 | return -EFAULT; |
| 1485 | } |
| 1486 | |
| 1487 | kfree(pmem); |
| 1488 | |
| 1489 | return 0; |
| 1490 | } |
| 1491 | |
| 1492 | /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ |
| 1493 | /* MPT IOCTL Test function. |
| 1494 | * |
| 1495 | * Outputs: None. |
| 1496 | * Return: 0 if successful |
| 1497 | * -EFAULT if data unavailable |
| 1498 | * -ENODEV if no such device/adapter |
| 1499 | */ |
| 1500 | static int |
| 1501 | mptctl_readtest (unsigned long arg) |
| 1502 | { |
| 1503 | struct mpt_ioctl_test __user *uarg = (void __user *) arg; |
| 1504 | struct mpt_ioctl_test karg; |
| 1505 | MPT_ADAPTER *ioc; |
| 1506 | int iocnum; |
| 1507 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1508 | if (copy_from_user(&karg, uarg, sizeof(struct mpt_ioctl_test))) { |
Eric Moore | 29dd360 | 2007-09-14 18:46:51 -0600 | [diff] [blame] | 1509 | printk(KERN_ERR MYNAM "%s@%d::mptctl_readtest - " |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1510 | "Unable to read in mpt_ioctl_test struct @ %p\n", |
| 1511 | __FILE__, __LINE__, uarg); |
| 1512 | return -EFAULT; |
| 1513 | } |
| 1514 | |
| 1515 | if (((iocnum = mpt_verify_adapter(karg.hdr.iocnum, &ioc)) < 0) || |
| 1516 | (ioc == NULL)) { |
Eric Moore | 29dd360 | 2007-09-14 18:46:51 -0600 | [diff] [blame] | 1517 | printk(KERN_DEBUG MYNAM "%s::mptctl_readtest() @%d - ioc%d not found!\n", |
Prakash, Sathya | 09120a8 | 2007-07-24 15:49:05 +0530 | [diff] [blame] | 1518 | __FILE__, __LINE__, iocnum); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1519 | return -ENODEV; |
| 1520 | } |
| 1521 | |
Prakash, Sathya | 09120a8 | 2007-07-24 15:49:05 +0530 | [diff] [blame] | 1522 | dctlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "mptctl_readtest called.\n", |
| 1523 | ioc->name)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1524 | /* Fill in the data and return the structure to the calling |
| 1525 | * program |
| 1526 | */ |
| 1527 | |
| 1528 | #ifdef MFCNT |
| 1529 | karg.chip_type = ioc->mfcnt; |
| 1530 | #else |
| 1531 | karg.chip_type = ioc->pcidev->device; |
| 1532 | #endif |
| 1533 | strncpy (karg.name, ioc->name, MPT_MAX_NAME); |
| 1534 | karg.name[MPT_MAX_NAME-1]='\0'; |
| 1535 | strncpy (karg.product, ioc->prod_name, MPT_PRODUCT_LENGTH); |
| 1536 | karg.product[MPT_PRODUCT_LENGTH-1]='\0'; |
| 1537 | |
| 1538 | /* Copy the data from kernel memory to user memory |
| 1539 | */ |
| 1540 | if (copy_to_user((char __user *)arg, &karg, sizeof(struct mpt_ioctl_test))) { |
Eric Moore | 29dd360 | 2007-09-14 18:46:51 -0600 | [diff] [blame] | 1541 | printk(MYIOC_s_ERR_FMT "%s@%d::mptctl_readtest - " |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1542 | "Unable to write out mpt_ioctl_test struct @ %p\n", |
Eric Moore | 29dd360 | 2007-09-14 18:46:51 -0600 | [diff] [blame] | 1543 | ioc->name, __FILE__, __LINE__, uarg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1544 | return -EFAULT; |
| 1545 | } |
| 1546 | |
| 1547 | return 0; |
| 1548 | } |
| 1549 | |
| 1550 | /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ |
| 1551 | /* |
| 1552 | * mptctl_eventquery - Query the host adapter for the event types |
| 1553 | * that are being logged. |
| 1554 | * @arg: User space argument |
| 1555 | * |
| 1556 | * Outputs: None. |
| 1557 | * Return: 0 if successful |
| 1558 | * -EFAULT if data unavailable |
| 1559 | * -ENODEV if no such device/adapter |
| 1560 | */ |
| 1561 | static int |
| 1562 | mptctl_eventquery (unsigned long arg) |
| 1563 | { |
| 1564 | struct mpt_ioctl_eventquery __user *uarg = (void __user *) arg; |
| 1565 | struct mpt_ioctl_eventquery karg; |
| 1566 | MPT_ADAPTER *ioc; |
| 1567 | int iocnum; |
| 1568 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1569 | if (copy_from_user(&karg, uarg, sizeof(struct mpt_ioctl_eventquery))) { |
Eric Moore | 29dd360 | 2007-09-14 18:46:51 -0600 | [diff] [blame] | 1570 | printk(KERN_ERR MYNAM "%s@%d::mptctl_eventquery - " |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1571 | "Unable to read in mpt_ioctl_eventquery struct @ %p\n", |
| 1572 | __FILE__, __LINE__, uarg); |
| 1573 | return -EFAULT; |
| 1574 | } |
| 1575 | |
| 1576 | if (((iocnum = mpt_verify_adapter(karg.hdr.iocnum, &ioc)) < 0) || |
| 1577 | (ioc == NULL)) { |
Eric Moore | 29dd360 | 2007-09-14 18:46:51 -0600 | [diff] [blame] | 1578 | printk(KERN_DEBUG MYNAM "%s::mptctl_eventquery() @%d - ioc%d not found!\n", |
Prakash, Sathya | 09120a8 | 2007-07-24 15:49:05 +0530 | [diff] [blame] | 1579 | __FILE__, __LINE__, iocnum); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1580 | return -ENODEV; |
| 1581 | } |
| 1582 | |
Prakash, Sathya | 09120a8 | 2007-07-24 15:49:05 +0530 | [diff] [blame] | 1583 | dctlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "mptctl_eventquery called.\n", |
| 1584 | ioc->name)); |
Moore, Eric | 5b5ef4f | 2006-02-02 17:19:40 -0700 | [diff] [blame] | 1585 | karg.eventEntries = MPTCTL_EVENT_LOG_SIZE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1586 | karg.eventTypes = ioc->eventTypes; |
| 1587 | |
| 1588 | /* Copy the data from kernel memory to user memory |
| 1589 | */ |
| 1590 | if (copy_to_user((char __user *)arg, &karg, sizeof(struct mpt_ioctl_eventquery))) { |
Eric Moore | 29dd360 | 2007-09-14 18:46:51 -0600 | [diff] [blame] | 1591 | printk(MYIOC_s_ERR_FMT "%s@%d::mptctl_eventquery - " |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1592 | "Unable to write out mpt_ioctl_eventquery struct @ %p\n", |
Eric Moore | 29dd360 | 2007-09-14 18:46:51 -0600 | [diff] [blame] | 1593 | ioc->name, __FILE__, __LINE__, uarg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1594 | return -EFAULT; |
| 1595 | } |
| 1596 | return 0; |
| 1597 | } |
| 1598 | |
| 1599 | /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ |
| 1600 | static int |
| 1601 | mptctl_eventenable (unsigned long arg) |
| 1602 | { |
| 1603 | struct mpt_ioctl_eventenable __user *uarg = (void __user *) arg; |
| 1604 | struct mpt_ioctl_eventenable karg; |
| 1605 | MPT_ADAPTER *ioc; |
| 1606 | int iocnum; |
| 1607 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1608 | if (copy_from_user(&karg, uarg, sizeof(struct mpt_ioctl_eventenable))) { |
Eric Moore | 29dd360 | 2007-09-14 18:46:51 -0600 | [diff] [blame] | 1609 | printk(KERN_ERR MYNAM "%s@%d::mptctl_eventenable - " |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1610 | "Unable to read in mpt_ioctl_eventenable struct @ %p\n", |
| 1611 | __FILE__, __LINE__, uarg); |
| 1612 | return -EFAULT; |
| 1613 | } |
| 1614 | |
| 1615 | if (((iocnum = mpt_verify_adapter(karg.hdr.iocnum, &ioc)) < 0) || |
| 1616 | (ioc == NULL)) { |
Eric Moore | 29dd360 | 2007-09-14 18:46:51 -0600 | [diff] [blame] | 1617 | printk(KERN_DEBUG MYNAM "%s::mptctl_eventenable() @%d - ioc%d not found!\n", |
Prakash, Sathya | 09120a8 | 2007-07-24 15:49:05 +0530 | [diff] [blame] | 1618 | __FILE__, __LINE__, iocnum); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1619 | return -ENODEV; |
| 1620 | } |
| 1621 | |
Prakash, Sathya | 09120a8 | 2007-07-24 15:49:05 +0530 | [diff] [blame] | 1622 | dctlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "mptctl_eventenable called.\n", |
| 1623 | ioc->name)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1624 | if (ioc->events == NULL) { |
| 1625 | /* Have not yet allocated memory - do so now. |
| 1626 | */ |
| 1627 | int sz = MPTCTL_EVENT_LOG_SIZE * sizeof(MPT_IOCTL_EVENTS); |
Mariusz Kozlowski | d7383a2 | 2007-08-10 14:50:50 -0700 | [diff] [blame] | 1628 | ioc->events = kzalloc(sz, GFP_KERNEL); |
| 1629 | if (!ioc->events) { |
Eric Moore | 29dd360 | 2007-09-14 18:46:51 -0600 | [diff] [blame] | 1630 | printk(MYIOC_s_ERR_FMT |
| 1631 | ": ERROR - Insufficient memory to add adapter!\n", |
| 1632 | ioc->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1633 | return -ENOMEM; |
| 1634 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1635 | ioc->alloc_total += sz; |
| 1636 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1637 | ioc->eventContext = 0; |
| 1638 | } |
| 1639 | |
| 1640 | /* Update the IOC event logging flag. |
| 1641 | */ |
| 1642 | ioc->eventTypes = karg.eventTypes; |
| 1643 | |
| 1644 | return 0; |
| 1645 | } |
| 1646 | |
| 1647 | /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ |
| 1648 | static int |
| 1649 | mptctl_eventreport (unsigned long arg) |
| 1650 | { |
| 1651 | struct mpt_ioctl_eventreport __user *uarg = (void __user *) arg; |
| 1652 | struct mpt_ioctl_eventreport karg; |
| 1653 | MPT_ADAPTER *ioc; |
| 1654 | int iocnum; |
| 1655 | int numBytes, maxEvents, max; |
| 1656 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1657 | if (copy_from_user(&karg, uarg, sizeof(struct mpt_ioctl_eventreport))) { |
Eric Moore | 29dd360 | 2007-09-14 18:46:51 -0600 | [diff] [blame] | 1658 | printk(KERN_ERR MYNAM "%s@%d::mptctl_eventreport - " |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1659 | "Unable to read in mpt_ioctl_eventreport struct @ %p\n", |
| 1660 | __FILE__, __LINE__, uarg); |
| 1661 | return -EFAULT; |
| 1662 | } |
| 1663 | |
| 1664 | if (((iocnum = mpt_verify_adapter(karg.hdr.iocnum, &ioc)) < 0) || |
| 1665 | (ioc == NULL)) { |
Eric Moore | 29dd360 | 2007-09-14 18:46:51 -0600 | [diff] [blame] | 1666 | printk(KERN_DEBUG MYNAM "%s::mptctl_eventreport() @%d - ioc%d not found!\n", |
Prakash, Sathya | 09120a8 | 2007-07-24 15:49:05 +0530 | [diff] [blame] | 1667 | __FILE__, __LINE__, iocnum); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1668 | return -ENODEV; |
| 1669 | } |
Prakash, Sathya | 09120a8 | 2007-07-24 15:49:05 +0530 | [diff] [blame] | 1670 | dctlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "mptctl_eventreport called.\n", |
| 1671 | ioc->name)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1672 | |
| 1673 | numBytes = karg.hdr.maxDataSize - sizeof(mpt_ioctl_header); |
| 1674 | maxEvents = numBytes/sizeof(MPT_IOCTL_EVENTS); |
| 1675 | |
| 1676 | |
Moore, Eric | 5b5ef4f | 2006-02-02 17:19:40 -0700 | [diff] [blame] | 1677 | max = MPTCTL_EVENT_LOG_SIZE < maxEvents ? MPTCTL_EVENT_LOG_SIZE : maxEvents; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1678 | |
| 1679 | /* If fewer than 1 event is requested, there must have |
| 1680 | * been some type of error. |
| 1681 | */ |
| 1682 | if ((max < 1) || !ioc->events) |
| 1683 | return -ENODATA; |
| 1684 | |
Moore, Eric | ea5a7a8 | 2006-02-02 17:20:01 -0700 | [diff] [blame] | 1685 | /* reset this flag so SIGIO can restart */ |
| 1686 | ioc->aen_event_read_flag=0; |
| 1687 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1688 | /* Copy the data from kernel memory to user memory |
| 1689 | */ |
| 1690 | numBytes = max * sizeof(MPT_IOCTL_EVENTS); |
| 1691 | if (copy_to_user(uarg->eventData, ioc->events, numBytes)) { |
Eric Moore | 29dd360 | 2007-09-14 18:46:51 -0600 | [diff] [blame] | 1692 | printk(MYIOC_s_ERR_FMT "%s@%d::mptctl_eventreport - " |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1693 | "Unable to write out mpt_ioctl_eventreport struct @ %p\n", |
Eric Moore | 29dd360 | 2007-09-14 18:46:51 -0600 | [diff] [blame] | 1694 | ioc->name, __FILE__, __LINE__, ioc->events); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1695 | return -EFAULT; |
| 1696 | } |
| 1697 | |
| 1698 | return 0; |
| 1699 | } |
| 1700 | |
| 1701 | /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ |
| 1702 | static int |
| 1703 | mptctl_replace_fw (unsigned long arg) |
| 1704 | { |
| 1705 | struct mpt_ioctl_replace_fw __user *uarg = (void __user *) arg; |
| 1706 | struct mpt_ioctl_replace_fw karg; |
| 1707 | MPT_ADAPTER *ioc; |
| 1708 | int iocnum; |
| 1709 | int newFwSize; |
| 1710 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1711 | if (copy_from_user(&karg, uarg, sizeof(struct mpt_ioctl_replace_fw))) { |
Eric Moore | 29dd360 | 2007-09-14 18:46:51 -0600 | [diff] [blame] | 1712 | printk(KERN_ERR MYNAM "%s@%d::mptctl_replace_fw - " |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1713 | "Unable to read in mpt_ioctl_replace_fw struct @ %p\n", |
| 1714 | __FILE__, __LINE__, uarg); |
| 1715 | return -EFAULT; |
| 1716 | } |
| 1717 | |
| 1718 | if (((iocnum = mpt_verify_adapter(karg.hdr.iocnum, &ioc)) < 0) || |
| 1719 | (ioc == NULL)) { |
Eric Moore | 29dd360 | 2007-09-14 18:46:51 -0600 | [diff] [blame] | 1720 | printk(KERN_DEBUG MYNAM "%s::mptctl_replace_fw() @%d - ioc%d not found!\n", |
Prakash, Sathya | 09120a8 | 2007-07-24 15:49:05 +0530 | [diff] [blame] | 1721 | __FILE__, __LINE__, iocnum); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1722 | return -ENODEV; |
| 1723 | } |
| 1724 | |
Prakash, Sathya | 09120a8 | 2007-07-24 15:49:05 +0530 | [diff] [blame] | 1725 | dctlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "mptctl_replace_fw called.\n", |
| 1726 | ioc->name)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1727 | /* If caching FW, Free the old FW image |
| 1728 | */ |
| 1729 | if (ioc->cached_fw == NULL) |
| 1730 | return 0; |
| 1731 | |
| 1732 | mpt_free_fw_memory(ioc); |
| 1733 | |
| 1734 | /* Allocate memory for the new FW image |
| 1735 | */ |
| 1736 | newFwSize = karg.newImageSize; |
| 1737 | |
| 1738 | if (newFwSize & 0x01) |
| 1739 | newFwSize += 1; |
| 1740 | if (newFwSize & 0x02) |
| 1741 | newFwSize += 2; |
| 1742 | |
| 1743 | mpt_alloc_fw_memory(ioc, newFwSize); |
| 1744 | if (ioc->cached_fw == NULL) |
| 1745 | return -ENOMEM; |
| 1746 | |
| 1747 | /* Copy the data from user memory to kernel space |
| 1748 | */ |
| 1749 | if (copy_from_user(ioc->cached_fw, uarg->newImage, newFwSize)) { |
Eric Moore | 29dd360 | 2007-09-14 18:46:51 -0600 | [diff] [blame] | 1750 | printk(MYIOC_s_ERR_FMT "%s@%d::mptctl_replace_fw - " |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1751 | "Unable to read in mpt_ioctl_replace_fw image " |
Eric Moore | 29dd360 | 2007-09-14 18:46:51 -0600 | [diff] [blame] | 1752 | "@ %p\n", ioc->name, __FILE__, __LINE__, uarg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1753 | mpt_free_fw_memory(ioc); |
| 1754 | return -EFAULT; |
| 1755 | } |
| 1756 | |
| 1757 | /* Update IOCFactsReply |
| 1758 | */ |
| 1759 | ioc->facts.FWImageSize = newFwSize; |
| 1760 | return 0; |
| 1761 | } |
| 1762 | |
| 1763 | /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ |
| 1764 | /* MPT IOCTL MPTCOMMAND function. |
| 1765 | * Cast the arg into the mpt_ioctl_mpt_command structure. |
| 1766 | * |
| 1767 | * Outputs: None. |
| 1768 | * Return: 0 if successful |
Joe Perches | fc1323b | 2008-02-03 17:21:01 +0200 | [diff] [blame] | 1769 | * -EBUSY if previous command timeout and IOC reset is not complete. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1770 | * -EFAULT if data unavailable |
| 1771 | * -ENODEV if no such device/adapter |
| 1772 | * -ETIME if timer expires |
| 1773 | * -ENOMEM if memory allocation error |
| 1774 | */ |
| 1775 | static int |
| 1776 | mptctl_mpt_command (unsigned long arg) |
| 1777 | { |
| 1778 | struct mpt_ioctl_command __user *uarg = (void __user *) arg; |
| 1779 | struct mpt_ioctl_command karg; |
| 1780 | MPT_ADAPTER *ioc; |
| 1781 | int iocnum; |
| 1782 | int rc; |
| 1783 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1784 | |
| 1785 | if (copy_from_user(&karg, uarg, sizeof(struct mpt_ioctl_command))) { |
Eric Moore | 29dd360 | 2007-09-14 18:46:51 -0600 | [diff] [blame] | 1786 | printk(KERN_ERR MYNAM "%s@%d::mptctl_mpt_command - " |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1787 | "Unable to read in mpt_ioctl_command struct @ %p\n", |
| 1788 | __FILE__, __LINE__, uarg); |
| 1789 | return -EFAULT; |
| 1790 | } |
| 1791 | |
| 1792 | if (((iocnum = mpt_verify_adapter(karg.hdr.iocnum, &ioc)) < 0) || |
| 1793 | (ioc == NULL)) { |
Eric Moore | 29dd360 | 2007-09-14 18:46:51 -0600 | [diff] [blame] | 1794 | printk(KERN_DEBUG MYNAM "%s::mptctl_mpt_command() @%d - ioc%d not found!\n", |
Prakash, Sathya | 09120a8 | 2007-07-24 15:49:05 +0530 | [diff] [blame] | 1795 | __FILE__, __LINE__, iocnum); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1796 | return -ENODEV; |
| 1797 | } |
| 1798 | |
| 1799 | rc = mptctl_do_mpt_command (karg, &uarg->MF); |
| 1800 | |
| 1801 | return rc; |
| 1802 | } |
| 1803 | |
| 1804 | /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ |
| 1805 | /* Worker routine for the IOCTL MPTCOMMAND and MPTCOMMAND32 (sparc) commands. |
| 1806 | * |
| 1807 | * Outputs: None. |
| 1808 | * Return: 0 if successful |
Joe Perches | fc1323b | 2008-02-03 17:21:01 +0200 | [diff] [blame] | 1809 | * -EBUSY if previous command timeout and IOC reset is not complete. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1810 | * -EFAULT if data unavailable |
| 1811 | * -ENODEV if no such device/adapter |
| 1812 | * -ETIME if timer expires |
| 1813 | * -ENOMEM if memory allocation error |
| 1814 | * -EPERM if SCSI I/O and target is untagged |
| 1815 | */ |
| 1816 | static int |
| 1817 | mptctl_do_mpt_command (struct mpt_ioctl_command karg, void __user *mfPtr) |
| 1818 | { |
| 1819 | MPT_ADAPTER *ioc; |
| 1820 | MPT_FRAME_HDR *mf = NULL; |
| 1821 | MPIHeader_t *hdr; |
| 1822 | char *psge; |
| 1823 | struct buflist bufIn; /* data In buffer */ |
| 1824 | struct buflist bufOut; /* data Out buffer */ |
| 1825 | dma_addr_t dma_addr_in; |
| 1826 | dma_addr_t dma_addr_out; |
| 1827 | int sgSize = 0; /* Num SG elements */ |
| 1828 | int iocnum, flagsLength; |
| 1829 | int sz, rc = 0; |
| 1830 | int msgContext; |
| 1831 | u16 req_idx; |
| 1832 | ulong timeout; |
Kashyap, Desai | ea2a788 | 2009-05-29 16:46:50 +0530 | [diff] [blame] | 1833 | unsigned long timeleft; |
Eric Moore | 793955f | 2007-01-29 09:42:20 -0700 | [diff] [blame] | 1834 | struct scsi_device *sdev; |
Kashyap, Desai | ea2a788 | 2009-05-29 16:46:50 +0530 | [diff] [blame] | 1835 | unsigned long flags; |
| 1836 | u8 function; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1837 | |
Eric Moore | ab37128 | 2007-09-29 10:22:54 -0600 | [diff] [blame] | 1838 | /* bufIn and bufOut are used for user to kernel space transfers |
| 1839 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1840 | bufIn.kptr = bufOut.kptr = NULL; |
Eric Moore | ab37128 | 2007-09-29 10:22:54 -0600 | [diff] [blame] | 1841 | bufIn.len = bufOut.len = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1842 | |
| 1843 | if (((iocnum = mpt_verify_adapter(karg.hdr.iocnum, &ioc)) < 0) || |
| 1844 | (ioc == NULL)) { |
Eric Moore | 29dd360 | 2007-09-14 18:46:51 -0600 | [diff] [blame] | 1845 | printk(KERN_DEBUG MYNAM "%s::mptctl_do_mpt_command() @%d - ioc%d not found!\n", |
Prakash, Sathya | 09120a8 | 2007-07-24 15:49:05 +0530 | [diff] [blame] | 1846 | __FILE__, __LINE__, iocnum); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1847 | return -ENODEV; |
| 1848 | } |
Kashyap, Desai | ea2a788 | 2009-05-29 16:46:50 +0530 | [diff] [blame] | 1849 | |
| 1850 | spin_lock_irqsave(&ioc->taskmgmt_lock, flags); |
| 1851 | if (ioc->ioc_reset_in_progress) { |
| 1852 | spin_unlock_irqrestore(&ioc->taskmgmt_lock, flags); |
Eric Moore | 29dd360 | 2007-09-14 18:46:51 -0600 | [diff] [blame] | 1853 | printk(KERN_ERR MYNAM "%s@%d::mptctl_do_mpt_command - " |
Kashyap, Desai | ea2a788 | 2009-05-29 16:46:50 +0530 | [diff] [blame] | 1854 | "Busy with diagnostic reset\n", __FILE__, __LINE__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1855 | return -EBUSY; |
| 1856 | } |
Kashyap, Desai | ea2a788 | 2009-05-29 16:46:50 +0530 | [diff] [blame] | 1857 | spin_unlock_irqrestore(&ioc->taskmgmt_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1858 | |
| 1859 | /* Verify that the final request frame will not be too large. |
| 1860 | */ |
| 1861 | sz = karg.dataSgeOffset * 4; |
| 1862 | if (karg.dataInSize > 0) |
Kashyap, Desai | 14d0f0b | 2009-05-29 16:37:04 +0530 | [diff] [blame] | 1863 | sz += ioc->SGE_size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1864 | if (karg.dataOutSize > 0) |
Kashyap, Desai | 14d0f0b | 2009-05-29 16:37:04 +0530 | [diff] [blame] | 1865 | sz += ioc->SGE_size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1866 | |
| 1867 | if (sz > ioc->req_sz) { |
Eric Moore | 29dd360 | 2007-09-14 18:46:51 -0600 | [diff] [blame] | 1868 | printk(MYIOC_s_ERR_FMT "%s@%d::mptctl_do_mpt_command - " |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1869 | "Request frame too large (%d) maximum (%d)\n", |
Eric Moore | 29dd360 | 2007-09-14 18:46:51 -0600 | [diff] [blame] | 1870 | ioc->name, __FILE__, __LINE__, sz, ioc->req_sz); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1871 | return -EFAULT; |
| 1872 | } |
| 1873 | |
| 1874 | /* Get a free request frame and save the message context. |
| 1875 | */ |
| 1876 | if ((mf = mpt_get_msg_frame(mptctl_id, ioc)) == NULL) |
| 1877 | return -EAGAIN; |
| 1878 | |
| 1879 | hdr = (MPIHeader_t *) mf; |
| 1880 | msgContext = le32_to_cpu(hdr->MsgContext); |
| 1881 | req_idx = le16_to_cpu(mf->u.frame.hwhdr.msgctxu.fld.req_idx); |
| 1882 | |
| 1883 | /* Copy the request frame |
| 1884 | * Reset the saved message context. |
| 1885 | * Request frame in user space |
| 1886 | */ |
| 1887 | if (copy_from_user(mf, mfPtr, karg.dataSgeOffset * 4)) { |
Eric Moore | 29dd360 | 2007-09-14 18:46:51 -0600 | [diff] [blame] | 1888 | printk(MYIOC_s_ERR_FMT "%s@%d::mptctl_do_mpt_command - " |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1889 | "Unable to read MF from mpt_ioctl_command struct @ %p\n", |
Eric Moore | 29dd360 | 2007-09-14 18:46:51 -0600 | [diff] [blame] | 1890 | ioc->name, __FILE__, __LINE__, mfPtr); |
Kashyap, Desai | ea2a788 | 2009-05-29 16:46:50 +0530 | [diff] [blame] | 1891 | function = -1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1892 | rc = -EFAULT; |
| 1893 | goto done_free_mem; |
| 1894 | } |
| 1895 | hdr->MsgContext = cpu_to_le32(msgContext); |
Kashyap, Desai | ea2a788 | 2009-05-29 16:46:50 +0530 | [diff] [blame] | 1896 | function = hdr->Function; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1897 | |
| 1898 | |
| 1899 | /* Verify that this request is allowed. |
| 1900 | */ |
Prakash, Sathya | 09120a8 | 2007-07-24 15:49:05 +0530 | [diff] [blame] | 1901 | dctlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sending mpi function (0x%02X), req=%p\n", |
| 1902 | ioc->name, hdr->Function, mf)); |
| 1903 | |
Kashyap, Desai | ea2a788 | 2009-05-29 16:46:50 +0530 | [diff] [blame] | 1904 | switch (function) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1905 | case MPI_FUNCTION_IOC_FACTS: |
| 1906 | case MPI_FUNCTION_PORT_FACTS: |
| 1907 | karg.dataOutSize = karg.dataInSize = 0; |
| 1908 | break; |
| 1909 | |
| 1910 | case MPI_FUNCTION_CONFIG: |
Prakash, Sathya | 09120a8 | 2007-07-24 15:49:05 +0530 | [diff] [blame] | 1911 | { |
| 1912 | Config_t *config_frame; |
| 1913 | config_frame = (Config_t *)mf; |
| 1914 | dctlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "\ttype=0x%02x ext_type=0x%02x " |
| 1915 | "number=0x%02x action=0x%02x\n", ioc->name, |
| 1916 | config_frame->Header.PageType, |
| 1917 | config_frame->ExtPageType, |
| 1918 | config_frame->Header.PageNumber, |
| 1919 | config_frame->Action)); |
| 1920 | break; |
| 1921 | } |
| 1922 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1923 | case MPI_FUNCTION_FC_COMMON_TRANSPORT_SEND: |
| 1924 | case MPI_FUNCTION_FC_EX_LINK_SRVC_SEND: |
| 1925 | case MPI_FUNCTION_FW_UPLOAD: |
| 1926 | case MPI_FUNCTION_SCSI_ENCLOSURE_PROCESSOR: |
| 1927 | case MPI_FUNCTION_FW_DOWNLOAD: |
| 1928 | case MPI_FUNCTION_FC_PRIMITIVE_SEND: |
Moore, Eric | 096f7a2 | 2006-02-02 17:19:30 -0700 | [diff] [blame] | 1929 | case MPI_FUNCTION_TOOLBOX: |
| 1930 | case MPI_FUNCTION_SAS_IO_UNIT_CONTROL: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1931 | break; |
| 1932 | |
| 1933 | case MPI_FUNCTION_SCSI_IO_REQUEST: |
| 1934 | if (ioc->sh) { |
| 1935 | SCSIIORequest_t *pScsiReq = (SCSIIORequest_t *) mf; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1936 | int qtag = MPI_SCSIIO_CONTROL_UNTAGGED; |
| 1937 | int scsidir = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1938 | int dataSize; |
Eric Moore | 793955f | 2007-01-29 09:42:20 -0700 | [diff] [blame] | 1939 | u32 id; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1940 | |
Eric Moore | 793955f | 2007-01-29 09:42:20 -0700 | [diff] [blame] | 1941 | id = (ioc->devices_per_bus == 0) ? 256 : ioc->devices_per_bus; |
| 1942 | if (pScsiReq->TargetID > id) { |
Eric Moore | 29dd360 | 2007-09-14 18:46:51 -0600 | [diff] [blame] | 1943 | printk(MYIOC_s_ERR_FMT "%s@%d::mptctl_do_mpt_command - " |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1944 | "Target ID out of bounds. \n", |
Eric Moore | 29dd360 | 2007-09-14 18:46:51 -0600 | [diff] [blame] | 1945 | ioc->name, __FILE__, __LINE__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1946 | rc = -ENODEV; |
| 1947 | goto done_free_mem; |
| 1948 | } |
| 1949 | |
Eric Moore | 793955f | 2007-01-29 09:42:20 -0700 | [diff] [blame] | 1950 | if (pScsiReq->Bus >= ioc->number_of_buses) { |
Eric Moore | 29dd360 | 2007-09-14 18:46:51 -0600 | [diff] [blame] | 1951 | printk(MYIOC_s_ERR_FMT "%s@%d::mptctl_do_mpt_command - " |
Eric Moore | 793955f | 2007-01-29 09:42:20 -0700 | [diff] [blame] | 1952 | "Target Bus out of bounds. \n", |
Eric Moore | 29dd360 | 2007-09-14 18:46:51 -0600 | [diff] [blame] | 1953 | ioc->name, __FILE__, __LINE__); |
Eric Moore | 793955f | 2007-01-29 09:42:20 -0700 | [diff] [blame] | 1954 | rc = -ENODEV; |
| 1955 | goto done_free_mem; |
| 1956 | } |
| 1957 | |
Moore, Eric | 5f07e24 | 2006-02-02 17:19:44 -0700 | [diff] [blame] | 1958 | pScsiReq->MsgFlags &= ~MPI_SCSIIO_MSGFLGS_SENSE_WIDTH; |
Kashyap, Desai | 14d0f0b | 2009-05-29 16:37:04 +0530 | [diff] [blame] | 1959 | pScsiReq->MsgFlags |= mpt_msg_flags(ioc); |
Moore, Eric | 5f07e24 | 2006-02-02 17:19:44 -0700 | [diff] [blame] | 1960 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1961 | |
| 1962 | /* verify that app has not requested |
| 1963 | * more sense data than driver |
| 1964 | * can provide, if so, reset this parameter |
| 1965 | * set the sense buffer pointer low address |
| 1966 | * update the control field to specify Q type |
| 1967 | */ |
| 1968 | if (karg.maxSenseBytes > MPT_SENSE_BUFFER_SIZE) |
| 1969 | pScsiReq->SenseBufferLength = MPT_SENSE_BUFFER_SIZE; |
| 1970 | else |
| 1971 | pScsiReq->SenseBufferLength = karg.maxSenseBytes; |
| 1972 | |
| 1973 | pScsiReq->SenseBufferLowAddr = |
| 1974 | cpu_to_le32(ioc->sense_buf_low_dma |
| 1975 | + (req_idx * MPT_SENSE_BUFFER_ALLOC)); |
| 1976 | |
Eric Moore | 793955f | 2007-01-29 09:42:20 -0700 | [diff] [blame] | 1977 | shost_for_each_device(sdev, ioc->sh) { |
| 1978 | struct scsi_target *starget = scsi_target(sdev); |
| 1979 | VirtTarget *vtarget = starget->hostdata; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1980 | |
Eric Moore | 793955f | 2007-01-29 09:42:20 -0700 | [diff] [blame] | 1981 | if ((pScsiReq->TargetID == vtarget->id) && |
| 1982 | (pScsiReq->Bus == vtarget->channel) && |
| 1983 | (vtarget->tflags & MPT_TARGET_FLAGS_Q_YES)) |
| 1984 | qtag = MPI_SCSIIO_CONTROL_SIMPLEQ; |
| 1985 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1986 | |
| 1987 | /* Have the IOCTL driver set the direction based |
| 1988 | * on the dataOutSize (ordering issue with Sparc). |
| 1989 | */ |
| 1990 | if (karg.dataOutSize > 0) { |
| 1991 | scsidir = MPI_SCSIIO_CONTROL_WRITE; |
| 1992 | dataSize = karg.dataOutSize; |
| 1993 | } else { |
| 1994 | scsidir = MPI_SCSIIO_CONTROL_READ; |
| 1995 | dataSize = karg.dataInSize; |
| 1996 | } |
| 1997 | |
| 1998 | pScsiReq->Control = cpu_to_le32(scsidir | qtag); |
| 1999 | pScsiReq->DataLength = cpu_to_le32(dataSize); |
| 2000 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2001 | |
| 2002 | } else { |
Eric Moore | 29dd360 | 2007-09-14 18:46:51 -0600 | [diff] [blame] | 2003 | printk(MYIOC_s_ERR_FMT "%s@%d::mptctl_do_mpt_command - " |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2004 | "SCSI driver is not loaded. \n", |
Eric Moore | 29dd360 | 2007-09-14 18:46:51 -0600 | [diff] [blame] | 2005 | ioc->name, __FILE__, __LINE__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2006 | rc = -EFAULT; |
| 2007 | goto done_free_mem; |
| 2008 | } |
| 2009 | break; |
| 2010 | |
Moore, Eric | 096f7a2 | 2006-02-02 17:19:30 -0700 | [diff] [blame] | 2011 | case MPI_FUNCTION_SMP_PASSTHROUGH: |
| 2012 | /* Check mf->PassthruFlags to determine if |
| 2013 | * transfer is ImmediateMode or not. |
| 2014 | * Immediate mode returns data in the ReplyFrame. |
| 2015 | * Else, we are sending request and response data |
| 2016 | * in two SGLs at the end of the mf. |
| 2017 | */ |
| 2018 | break; |
| 2019 | |
| 2020 | case MPI_FUNCTION_SATA_PASSTHROUGH: |
| 2021 | if (!ioc->sh) { |
Eric Moore | 29dd360 | 2007-09-14 18:46:51 -0600 | [diff] [blame] | 2022 | printk(MYIOC_s_ERR_FMT "%s@%d::mptctl_do_mpt_command - " |
Moore, Eric | 096f7a2 | 2006-02-02 17:19:30 -0700 | [diff] [blame] | 2023 | "SCSI driver is not loaded. \n", |
Eric Moore | 29dd360 | 2007-09-14 18:46:51 -0600 | [diff] [blame] | 2024 | ioc->name, __FILE__, __LINE__); |
Moore, Eric | 096f7a2 | 2006-02-02 17:19:30 -0700 | [diff] [blame] | 2025 | rc = -EFAULT; |
| 2026 | goto done_free_mem; |
| 2027 | } |
| 2028 | break; |
| 2029 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2030 | case MPI_FUNCTION_RAID_ACTION: |
| 2031 | /* Just add a SGE |
| 2032 | */ |
| 2033 | break; |
| 2034 | |
| 2035 | case MPI_FUNCTION_RAID_SCSI_IO_PASSTHROUGH: |
| 2036 | if (ioc->sh) { |
| 2037 | SCSIIORequest_t *pScsiReq = (SCSIIORequest_t *) mf; |
| 2038 | int qtag = MPI_SCSIIO_CONTROL_SIMPLEQ; |
| 2039 | int scsidir = MPI_SCSIIO_CONTROL_READ; |
| 2040 | int dataSize; |
| 2041 | |
Moore, Eric | 5f07e24 | 2006-02-02 17:19:44 -0700 | [diff] [blame] | 2042 | pScsiReq->MsgFlags &= ~MPI_SCSIIO_MSGFLGS_SENSE_WIDTH; |
Kashyap, Desai | 14d0f0b | 2009-05-29 16:37:04 +0530 | [diff] [blame] | 2043 | pScsiReq->MsgFlags |= mpt_msg_flags(ioc); |
Moore, Eric | 5f07e24 | 2006-02-02 17:19:44 -0700 | [diff] [blame] | 2044 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2045 | |
| 2046 | /* verify that app has not requested |
| 2047 | * more sense data than driver |
| 2048 | * can provide, if so, reset this parameter |
| 2049 | * set the sense buffer pointer low address |
| 2050 | * update the control field to specify Q type |
| 2051 | */ |
| 2052 | if (karg.maxSenseBytes > MPT_SENSE_BUFFER_SIZE) |
| 2053 | pScsiReq->SenseBufferLength = MPT_SENSE_BUFFER_SIZE; |
| 2054 | else |
| 2055 | pScsiReq->SenseBufferLength = karg.maxSenseBytes; |
| 2056 | |
| 2057 | pScsiReq->SenseBufferLowAddr = |
| 2058 | cpu_to_le32(ioc->sense_buf_low_dma |
| 2059 | + (req_idx * MPT_SENSE_BUFFER_ALLOC)); |
| 2060 | |
| 2061 | /* All commands to physical devices are tagged |
| 2062 | */ |
| 2063 | |
| 2064 | /* Have the IOCTL driver set the direction based |
| 2065 | * on the dataOutSize (ordering issue with Sparc). |
| 2066 | */ |
| 2067 | if (karg.dataOutSize > 0) { |
| 2068 | scsidir = MPI_SCSIIO_CONTROL_WRITE; |
| 2069 | dataSize = karg.dataOutSize; |
| 2070 | } else { |
| 2071 | scsidir = MPI_SCSIIO_CONTROL_READ; |
| 2072 | dataSize = karg.dataInSize; |
| 2073 | } |
| 2074 | |
| 2075 | pScsiReq->Control = cpu_to_le32(scsidir | qtag); |
| 2076 | pScsiReq->DataLength = cpu_to_le32(dataSize); |
| 2077 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2078 | } else { |
Eric Moore | 29dd360 | 2007-09-14 18:46:51 -0600 | [diff] [blame] | 2079 | printk(MYIOC_s_ERR_FMT "%s@%d::mptctl_do_mpt_command - " |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2080 | "SCSI driver is not loaded. \n", |
Eric Moore | 29dd360 | 2007-09-14 18:46:51 -0600 | [diff] [blame] | 2081 | ioc->name, __FILE__, __LINE__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2082 | rc = -EFAULT; |
| 2083 | goto done_free_mem; |
| 2084 | } |
| 2085 | break; |
| 2086 | |
| 2087 | case MPI_FUNCTION_SCSI_TASK_MGMT: |
Kashyap, Desai | ea2a788 | 2009-05-29 16:46:50 +0530 | [diff] [blame] | 2088 | { |
| 2089 | SCSITaskMgmt_t *pScsiTm; |
| 2090 | pScsiTm = (SCSITaskMgmt_t *)mf; |
| 2091 | dctlprintk(ioc, printk(MYIOC_s_DEBUG_FMT |
| 2092 | "\tTaskType=0x%x MsgFlags=0x%x " |
| 2093 | "TaskMsgContext=0x%x id=%d channel=%d\n", |
| 2094 | ioc->name, pScsiTm->TaskType, le32_to_cpu |
| 2095 | (pScsiTm->TaskMsgContext), pScsiTm->MsgFlags, |
| 2096 | pScsiTm->TargetID, pScsiTm->Bus)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2097 | break; |
Kashyap, Desai | ea2a788 | 2009-05-29 16:46:50 +0530 | [diff] [blame] | 2098 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2099 | |
| 2100 | case MPI_FUNCTION_IOC_INIT: |
| 2101 | { |
| 2102 | IOCInit_t *pInit = (IOCInit_t *) mf; |
| 2103 | u32 high_addr, sense_high; |
| 2104 | |
| 2105 | /* Verify that all entries in the IOC INIT match |
| 2106 | * existing setup (and in LE format). |
| 2107 | */ |
| 2108 | if (sizeof(dma_addr_t) == sizeof(u64)) { |
| 2109 | high_addr = cpu_to_le32((u32)((u64)ioc->req_frames_dma >> 32)); |
| 2110 | sense_high= cpu_to_le32((u32)((u64)ioc->sense_buf_pool_dma >> 32)); |
| 2111 | } else { |
| 2112 | high_addr = 0; |
| 2113 | sense_high= 0; |
| 2114 | } |
| 2115 | |
| 2116 | if ((pInit->Flags != 0) || (pInit->MaxDevices != ioc->facts.MaxDevices) || |
| 2117 | (pInit->MaxBuses != ioc->facts.MaxBuses) || |
| 2118 | (pInit->ReplyFrameSize != cpu_to_le16(ioc->reply_sz)) || |
| 2119 | (pInit->HostMfaHighAddr != high_addr) || |
| 2120 | (pInit->SenseBufferHighAddr != sense_high)) { |
Eric Moore | 29dd360 | 2007-09-14 18:46:51 -0600 | [diff] [blame] | 2121 | printk(MYIOC_s_ERR_FMT "%s@%d::mptctl_do_mpt_command - " |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2122 | "IOC_INIT issued with 1 or more incorrect parameters. Rejected.\n", |
Eric Moore | 29dd360 | 2007-09-14 18:46:51 -0600 | [diff] [blame] | 2123 | ioc->name, __FILE__, __LINE__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2124 | rc = -EFAULT; |
| 2125 | goto done_free_mem; |
| 2126 | } |
| 2127 | } |
| 2128 | break; |
| 2129 | default: |
| 2130 | /* |
| 2131 | * MPI_FUNCTION_PORT_ENABLE |
| 2132 | * MPI_FUNCTION_TARGET_CMD_BUFFER_POST |
| 2133 | * MPI_FUNCTION_TARGET_ASSIST |
| 2134 | * MPI_FUNCTION_TARGET_STATUS_SEND |
| 2135 | * MPI_FUNCTION_TARGET_MODE_ABORT |
| 2136 | * MPI_FUNCTION_IOC_MESSAGE_UNIT_RESET |
| 2137 | * MPI_FUNCTION_IO_UNIT_RESET |
| 2138 | * MPI_FUNCTION_HANDSHAKE |
| 2139 | * MPI_FUNCTION_REPLY_FRAME_REMOVAL |
| 2140 | * MPI_FUNCTION_EVENT_NOTIFICATION |
| 2141 | * (driver handles event notification) |
| 2142 | * MPI_FUNCTION_EVENT_ACK |
| 2143 | */ |
| 2144 | |
| 2145 | /* What to do with these??? CHECK ME!!! |
| 2146 | MPI_FUNCTION_FC_LINK_SRVC_BUF_POST |
| 2147 | MPI_FUNCTION_FC_LINK_SRVC_RSP |
| 2148 | MPI_FUNCTION_FC_ABORT |
| 2149 | MPI_FUNCTION_LAN_SEND |
| 2150 | MPI_FUNCTION_LAN_RECEIVE |
| 2151 | MPI_FUNCTION_LAN_RESET |
| 2152 | */ |
| 2153 | |
Eric Moore | 29dd360 | 2007-09-14 18:46:51 -0600 | [diff] [blame] | 2154 | printk(MYIOC_s_ERR_FMT "%s@%d::mptctl_do_mpt_command - " |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2155 | "Illegal request (function 0x%x) \n", |
Eric Moore | 29dd360 | 2007-09-14 18:46:51 -0600 | [diff] [blame] | 2156 | ioc->name, __FILE__, __LINE__, hdr->Function); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2157 | rc = -EFAULT; |
| 2158 | goto done_free_mem; |
| 2159 | } |
| 2160 | |
| 2161 | /* Add the SGL ( at most one data in SGE and one data out SGE ) |
| 2162 | * In the case of two SGE's - the data out (write) will always |
| 2163 | * preceede the data in (read) SGE. psgList is used to free the |
| 2164 | * allocated memory. |
| 2165 | */ |
| 2166 | psge = (char *) (((int *) mf) + karg.dataSgeOffset); |
| 2167 | flagsLength = 0; |
| 2168 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2169 | if (karg.dataOutSize > 0) |
| 2170 | sgSize ++; |
| 2171 | |
| 2172 | if (karg.dataInSize > 0) |
| 2173 | sgSize ++; |
| 2174 | |
| 2175 | if (sgSize > 0) { |
| 2176 | |
| 2177 | /* Set up the dataOut memory allocation */ |
| 2178 | if (karg.dataOutSize > 0) { |
| 2179 | if (karg.dataInSize > 0) { |
| 2180 | flagsLength = ( MPI_SGE_FLAGS_SIMPLE_ELEMENT | |
| 2181 | MPI_SGE_FLAGS_END_OF_BUFFER | |
Kashyap, Desai | 14d0f0b | 2009-05-29 16:37:04 +0530 | [diff] [blame] | 2182 | MPI_SGE_FLAGS_DIRECTION) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2183 | << MPI_SGE_FLAGS_SHIFT; |
| 2184 | } else { |
| 2185 | flagsLength = MPT_SGE_FLAGS_SSIMPLE_WRITE; |
| 2186 | } |
| 2187 | flagsLength |= karg.dataOutSize; |
| 2188 | bufOut.len = karg.dataOutSize; |
| 2189 | bufOut.kptr = pci_alloc_consistent( |
| 2190 | ioc->pcidev, bufOut.len, &dma_addr_out); |
| 2191 | |
| 2192 | if (bufOut.kptr == NULL) { |
| 2193 | rc = -ENOMEM; |
| 2194 | goto done_free_mem; |
| 2195 | } else { |
| 2196 | /* Set up this SGE. |
| 2197 | * Copy to MF and to sglbuf |
| 2198 | */ |
Kashyap, Desai | 14d0f0b | 2009-05-29 16:37:04 +0530 | [diff] [blame] | 2199 | ioc->add_sge(psge, flagsLength, dma_addr_out); |
| 2200 | psge += ioc->SGE_size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2201 | |
| 2202 | /* Copy user data to kernel space. |
| 2203 | */ |
| 2204 | if (copy_from_user(bufOut.kptr, |
| 2205 | karg.dataOutBufPtr, |
| 2206 | bufOut.len)) { |
Eric Moore | 29dd360 | 2007-09-14 18:46:51 -0600 | [diff] [blame] | 2207 | printk(MYIOC_s_ERR_FMT |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2208 | "%s@%d::mptctl_do_mpt_command - Unable " |
| 2209 | "to read user data " |
| 2210 | "struct @ %p\n", |
Eric Moore | 29dd360 | 2007-09-14 18:46:51 -0600 | [diff] [blame] | 2211 | ioc->name, __FILE__, __LINE__,karg.dataOutBufPtr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2212 | rc = -EFAULT; |
| 2213 | goto done_free_mem; |
| 2214 | } |
| 2215 | } |
| 2216 | } |
| 2217 | |
| 2218 | if (karg.dataInSize > 0) { |
| 2219 | flagsLength = MPT_SGE_FLAGS_SSIMPLE_READ; |
| 2220 | flagsLength |= karg.dataInSize; |
| 2221 | |
| 2222 | bufIn.len = karg.dataInSize; |
| 2223 | bufIn.kptr = pci_alloc_consistent(ioc->pcidev, |
| 2224 | bufIn.len, &dma_addr_in); |
| 2225 | |
| 2226 | if (bufIn.kptr == NULL) { |
| 2227 | rc = -ENOMEM; |
| 2228 | goto done_free_mem; |
| 2229 | } else { |
| 2230 | /* Set up this SGE |
| 2231 | * Copy to MF and to sglbuf |
| 2232 | */ |
Kashyap, Desai | 14d0f0b | 2009-05-29 16:37:04 +0530 | [diff] [blame] | 2233 | ioc->add_sge(psge, flagsLength, dma_addr_in); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2234 | } |
| 2235 | } |
| 2236 | } else { |
| 2237 | /* Add a NULL SGE |
| 2238 | */ |
Kashyap, Desai | 14d0f0b | 2009-05-29 16:37:04 +0530 | [diff] [blame] | 2239 | ioc->add_sge(psge, flagsLength, (dma_addr_t) -1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2240 | } |
| 2241 | |
Kashyap, Desai | ea2a788 | 2009-05-29 16:46:50 +0530 | [diff] [blame] | 2242 | SET_MGMT_MSG_CONTEXT(ioc->ioctl_cmds.msg_context, hdr->MsgContext); |
| 2243 | INITIALIZE_MGMT_STATUS(ioc->ioctl_cmds.status) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2244 | if (hdr->Function == MPI_FUNCTION_SCSI_TASK_MGMT) { |
| 2245 | |
Kashyap, Desai | ea2a788 | 2009-05-29 16:46:50 +0530 | [diff] [blame] | 2246 | mutex_lock(&ioc->taskmgmt_cmds.mutex); |
| 2247 | if (mpt_set_taskmgmt_in_progress_flag(ioc) != 0) { |
| 2248 | mutex_unlock(&ioc->taskmgmt_cmds.mutex); |
| 2249 | goto done_free_mem; |
| 2250 | } |
| 2251 | |
Prakash, Sathya | 09120a8 | 2007-07-24 15:49:05 +0530 | [diff] [blame] | 2252 | DBG_DUMP_TM_REQUEST_FRAME(ioc, (u32 *)mf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2253 | |
Prakash, Sathya | 7a195f4 | 2007-08-14 16:08:40 +0530 | [diff] [blame] | 2254 | if ((ioc->facts.IOCCapabilities & MPI_IOCFACTS_CAPABILITY_HIGH_PRI_Q) && |
| 2255 | (ioc->facts.MsgVersion >= MPI_VERSION_01_05)) |
| 2256 | mpt_put_msg_frame_hi_pri(mptctl_id, ioc, mf); |
| 2257 | else { |
| 2258 | rc =mpt_send_handshake_request(mptctl_id, ioc, |
| 2259 | sizeof(SCSITaskMgmt_t), (u32*)mf, CAN_SLEEP); |
| 2260 | if (rc != 0) { |
| 2261 | dfailprintk(ioc, printk(MYIOC_s_ERR_FMT |
Kashyap, Desai | ea2a788 | 2009-05-29 16:46:50 +0530 | [diff] [blame] | 2262 | "send_handshake FAILED! (ioc %p, mf %p)\n", |
Prakash, Sathya | 7a195f4 | 2007-08-14 16:08:40 +0530 | [diff] [blame] | 2263 | ioc->name, ioc, mf)); |
Kashyap, Desai | ea2a788 | 2009-05-29 16:46:50 +0530 | [diff] [blame] | 2264 | mpt_clear_taskmgmt_in_progress_flag(ioc); |
Prakash, Sathya | 7a195f4 | 2007-08-14 16:08:40 +0530 | [diff] [blame] | 2265 | rc = -ENODATA; |
Kashyap, Desai | ea2a788 | 2009-05-29 16:46:50 +0530 | [diff] [blame] | 2266 | mutex_unlock(&ioc->taskmgmt_cmds.mutex); |
Prakash, Sathya | 7a195f4 | 2007-08-14 16:08:40 +0530 | [diff] [blame] | 2267 | goto done_free_mem; |
| 2268 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2269 | } |
| 2270 | |
| 2271 | } else |
| 2272 | mpt_put_msg_frame(mptctl_id, ioc, mf); |
| 2273 | |
| 2274 | /* Now wait for the command to complete */ |
| 2275 | timeout = (karg.timeout > 0) ? karg.timeout : MPT_IOCTL_DEFAULT_TIMEOUT; |
Kashyap, Desai | ea2a788 | 2009-05-29 16:46:50 +0530 | [diff] [blame] | 2276 | retry_wait: |
| 2277 | timeleft = wait_for_completion_timeout(&ioc->ioctl_cmds.done, |
| 2278 | HZ*timeout); |
| 2279 | if (!(ioc->ioctl_cmds.status & MPT_MGMT_STATUS_COMMAND_GOOD)) { |
| 2280 | rc = -ETIME; |
| 2281 | dfailprintk(ioc, printk(MYIOC_s_ERR_FMT "%s: TIMED OUT!\n", |
| 2282 | ioc->name, __func__)); |
| 2283 | if (ioc->ioctl_cmds.status & MPT_MGMT_STATUS_DID_IOCRESET) { |
| 2284 | if (function == MPI_FUNCTION_SCSI_TASK_MGMT) |
| 2285 | mutex_unlock(&ioc->taskmgmt_cmds.mutex); |
| 2286 | goto done_free_mem; |
| 2287 | } |
| 2288 | if (!timeleft) { |
| 2289 | if (function == MPI_FUNCTION_SCSI_TASK_MGMT) |
| 2290 | mutex_unlock(&ioc->taskmgmt_cmds.mutex); |
| 2291 | mptctl_timeout_expired(ioc, mf); |
| 2292 | mf = NULL; |
| 2293 | } else |
| 2294 | goto retry_wait; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2295 | goto done_free_mem; |
| 2296 | } |
| 2297 | |
Kashyap, Desai | ea2a788 | 2009-05-29 16:46:50 +0530 | [diff] [blame] | 2298 | if (function == MPI_FUNCTION_SCSI_TASK_MGMT) |
| 2299 | mutex_unlock(&ioc->taskmgmt_cmds.mutex); |
| 2300 | |
| 2301 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2302 | mf = NULL; |
| 2303 | |
| 2304 | /* If a valid reply frame, copy to the user. |
| 2305 | * Offset 2: reply length in U32's |
| 2306 | */ |
Kashyap, Desai | ea2a788 | 2009-05-29 16:46:50 +0530 | [diff] [blame] | 2307 | if (ioc->ioctl_cmds.status & MPT_MGMT_STATUS_RF_VALID) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2308 | if (karg.maxReplyBytes < ioc->reply_sz) { |
Kashyap, Desai | ea2a788 | 2009-05-29 16:46:50 +0530 | [diff] [blame] | 2309 | sz = min(karg.maxReplyBytes, |
| 2310 | 4*ioc->ioctl_cmds.reply[2]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2311 | } else { |
Kashyap, Desai | ea2a788 | 2009-05-29 16:46:50 +0530 | [diff] [blame] | 2312 | sz = min(ioc->reply_sz, 4*ioc->ioctl_cmds.reply[2]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2313 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2314 | if (sz > 0) { |
| 2315 | if (copy_to_user(karg.replyFrameBufPtr, |
Kashyap, Desai | ea2a788 | 2009-05-29 16:46:50 +0530 | [diff] [blame] | 2316 | ioc->ioctl_cmds.reply, sz)){ |
Eric Moore | 29dd360 | 2007-09-14 18:46:51 -0600 | [diff] [blame] | 2317 | printk(MYIOC_s_ERR_FMT |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2318 | "%s@%d::mptctl_do_mpt_command - " |
| 2319 | "Unable to write out reply frame %p\n", |
Eric Moore | 29dd360 | 2007-09-14 18:46:51 -0600 | [diff] [blame] | 2320 | ioc->name, __FILE__, __LINE__, karg.replyFrameBufPtr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2321 | rc = -ENODATA; |
| 2322 | goto done_free_mem; |
| 2323 | } |
| 2324 | } |
| 2325 | } |
| 2326 | |
| 2327 | /* If valid sense data, copy to user. |
| 2328 | */ |
Kashyap, Desai | ea2a788 | 2009-05-29 16:46:50 +0530 | [diff] [blame] | 2329 | if (ioc->ioctl_cmds.status & MPT_MGMT_STATUS_SENSE_VALID) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2330 | sz = min(karg.maxSenseBytes, MPT_SENSE_BUFFER_SIZE); |
| 2331 | if (sz > 0) { |
Kashyap, Desai | ea2a788 | 2009-05-29 16:46:50 +0530 | [diff] [blame] | 2332 | if (copy_to_user(karg.senseDataPtr, |
| 2333 | ioc->ioctl_cmds.sense, sz)) { |
Eric Moore | 29dd360 | 2007-09-14 18:46:51 -0600 | [diff] [blame] | 2334 | printk(MYIOC_s_ERR_FMT "%s@%d::mptctl_do_mpt_command - " |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2335 | "Unable to write sense data to user %p\n", |
Eric Moore | 29dd360 | 2007-09-14 18:46:51 -0600 | [diff] [blame] | 2336 | ioc->name, __FILE__, __LINE__, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2337 | karg.senseDataPtr); |
| 2338 | rc = -ENODATA; |
| 2339 | goto done_free_mem; |
| 2340 | } |
| 2341 | } |
| 2342 | } |
| 2343 | |
| 2344 | /* If the overall status is _GOOD and data in, copy data |
| 2345 | * to user. |
| 2346 | */ |
Kashyap, Desai | ea2a788 | 2009-05-29 16:46:50 +0530 | [diff] [blame] | 2347 | if ((ioc->ioctl_cmds.status & MPT_MGMT_STATUS_COMMAND_GOOD) && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2348 | (karg.dataInSize > 0) && (bufIn.kptr)) { |
| 2349 | |
| 2350 | if (copy_to_user(karg.dataInBufPtr, |
| 2351 | bufIn.kptr, karg.dataInSize)) { |
Eric Moore | 29dd360 | 2007-09-14 18:46:51 -0600 | [diff] [blame] | 2352 | printk(MYIOC_s_ERR_FMT "%s@%d::mptctl_do_mpt_command - " |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2353 | "Unable to write data to user %p\n", |
Eric Moore | 29dd360 | 2007-09-14 18:46:51 -0600 | [diff] [blame] | 2354 | ioc->name, __FILE__, __LINE__, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2355 | karg.dataInBufPtr); |
| 2356 | rc = -ENODATA; |
| 2357 | } |
| 2358 | } |
| 2359 | |
| 2360 | done_free_mem: |
| 2361 | |
Kashyap, Desai | ea2a788 | 2009-05-29 16:46:50 +0530 | [diff] [blame] | 2362 | CLEAR_MGMT_STATUS(ioc->ioctl_cmds.status) |
| 2363 | SET_MGMT_MSG_CONTEXT(ioc->ioctl_cmds.msg_context, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2364 | |
| 2365 | /* Free the allocated memory. |
| 2366 | */ |
| 2367 | if (bufOut.kptr != NULL) { |
| 2368 | pci_free_consistent(ioc->pcidev, |
| 2369 | bufOut.len, (void *) bufOut.kptr, dma_addr_out); |
| 2370 | } |
| 2371 | |
| 2372 | if (bufIn.kptr != NULL) { |
| 2373 | pci_free_consistent(ioc->pcidev, |
| 2374 | bufIn.len, (void *) bufIn.kptr, dma_addr_in); |
| 2375 | } |
| 2376 | |
| 2377 | /* mf is null if command issued successfully |
| 2378 | * otherwise, failure occured after mf acquired. |
| 2379 | */ |
| 2380 | if (mf) |
| 2381 | mpt_free_msg_frame(ioc, mf); |
| 2382 | |
| 2383 | return rc; |
| 2384 | } |
| 2385 | |
| 2386 | /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ |
Eric Moore | ba856d3 | 2006-07-11 17:34:01 -0600 | [diff] [blame] | 2387 | /* Prototype Routine for the HOST INFO command. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2388 | * |
| 2389 | * Outputs: None. |
| 2390 | * Return: 0 if successful |
| 2391 | * -EFAULT if data unavailable |
Joe Perches | fc1323b | 2008-02-03 17:21:01 +0200 | [diff] [blame] | 2392 | * -EBUSY if previous command timeout and IOC reset is not complete. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2393 | * -ENODEV if no such device/adapter |
| 2394 | * -ETIME if timer expires |
| 2395 | * -ENOMEM if memory allocation error |
| 2396 | */ |
| 2397 | static int |
| 2398 | mptctl_hp_hostinfo(unsigned long arg, unsigned int data_size) |
| 2399 | { |
| 2400 | hp_host_info_t __user *uarg = (void __user *) arg; |
| 2401 | MPT_ADAPTER *ioc; |
| 2402 | struct pci_dev *pdev; |
Moore, Eric | 592f9c2 | 2006-02-02 17:19:47 -0700 | [diff] [blame] | 2403 | char *pbuf=NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2404 | dma_addr_t buf_dma; |
| 2405 | hp_host_info_t karg; |
| 2406 | CONFIGPARMS cfg; |
| 2407 | ConfigPageHeader_t hdr; |
| 2408 | int iocnum; |
| 2409 | int rc, cim_rev; |
Moore, Eric | 592f9c2 | 2006-02-02 17:19:47 -0700 | [diff] [blame] | 2410 | ToolboxIstwiReadWriteRequest_t *IstwiRWRequest; |
| 2411 | MPT_FRAME_HDR *mf = NULL; |
| 2412 | MPIHeader_t *mpi_hdr; |
Kashyap, Desai | ea2a788 | 2009-05-29 16:46:50 +0530 | [diff] [blame] | 2413 | unsigned long timeleft; |
| 2414 | int retval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2415 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2416 | /* Reset long to int. Should affect IA64 and SPARC only |
| 2417 | */ |
| 2418 | if (data_size == sizeof(hp_host_info_t)) |
| 2419 | cim_rev = 1; |
| 2420 | else if (data_size == sizeof(hp_host_info_rev0_t)) |
| 2421 | cim_rev = 0; /* obsolete */ |
| 2422 | else |
| 2423 | return -EFAULT; |
| 2424 | |
| 2425 | if (copy_from_user(&karg, uarg, sizeof(hp_host_info_t))) { |
Eric Moore | 29dd360 | 2007-09-14 18:46:51 -0600 | [diff] [blame] | 2426 | printk(KERN_ERR MYNAM "%s@%d::mptctl_hp_host_info - " |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2427 | "Unable to read in hp_host_info struct @ %p\n", |
| 2428 | __FILE__, __LINE__, uarg); |
| 2429 | return -EFAULT; |
| 2430 | } |
| 2431 | |
| 2432 | if (((iocnum = mpt_verify_adapter(karg.hdr.iocnum, &ioc)) < 0) || |
| 2433 | (ioc == NULL)) { |
Eric Moore | 29dd360 | 2007-09-14 18:46:51 -0600 | [diff] [blame] | 2434 | printk(KERN_DEBUG MYNAM "%s::mptctl_hp_hostinfo() @%d - ioc%d not found!\n", |
Prakash, Sathya | 09120a8 | 2007-07-24 15:49:05 +0530 | [diff] [blame] | 2435 | __FILE__, __LINE__, iocnum); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2436 | return -ENODEV; |
| 2437 | } |
Prakash, Sathya | 09120a8 | 2007-07-24 15:49:05 +0530 | [diff] [blame] | 2438 | dctlprintk(ioc, printk(MYIOC_s_DEBUG_FMT ": mptctl_hp_hostinfo called.\n", |
| 2439 | ioc->name)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2440 | |
| 2441 | /* Fill in the data and return the structure to the calling |
| 2442 | * program |
| 2443 | */ |
| 2444 | pdev = (struct pci_dev *) ioc->pcidev; |
| 2445 | |
| 2446 | karg.vendor = pdev->vendor; |
| 2447 | karg.device = pdev->device; |
| 2448 | karg.subsystem_id = pdev->subsystem_device; |
| 2449 | karg.subsystem_vendor = pdev->subsystem_vendor; |
| 2450 | karg.devfn = pdev->devfn; |
| 2451 | karg.bus = pdev->bus->number; |
| 2452 | |
| 2453 | /* Save the SCSI host no. if |
| 2454 | * SCSI driver loaded |
| 2455 | */ |
| 2456 | if (ioc->sh != NULL) |
| 2457 | karg.host_no = ioc->sh->host_no; |
| 2458 | else |
| 2459 | karg.host_no = -1; |
| 2460 | |
| 2461 | /* Reformat the fw_version into a string |
| 2462 | */ |
| 2463 | karg.fw_version[0] = ioc->facts.FWVersion.Struct.Major >= 10 ? |
| 2464 | ((ioc->facts.FWVersion.Struct.Major / 10) + '0') : '0'; |
| 2465 | karg.fw_version[1] = (ioc->facts.FWVersion.Struct.Major % 10 ) + '0'; |
| 2466 | karg.fw_version[2] = '.'; |
| 2467 | karg.fw_version[3] = ioc->facts.FWVersion.Struct.Minor >= 10 ? |
| 2468 | ((ioc->facts.FWVersion.Struct.Minor / 10) + '0') : '0'; |
| 2469 | karg.fw_version[4] = (ioc->facts.FWVersion.Struct.Minor % 10 ) + '0'; |
| 2470 | karg.fw_version[5] = '.'; |
| 2471 | karg.fw_version[6] = ioc->facts.FWVersion.Struct.Unit >= 10 ? |
| 2472 | ((ioc->facts.FWVersion.Struct.Unit / 10) + '0') : '0'; |
| 2473 | karg.fw_version[7] = (ioc->facts.FWVersion.Struct.Unit % 10 ) + '0'; |
| 2474 | karg.fw_version[8] = '.'; |
| 2475 | karg.fw_version[9] = ioc->facts.FWVersion.Struct.Dev >= 10 ? |
| 2476 | ((ioc->facts.FWVersion.Struct.Dev / 10) + '0') : '0'; |
| 2477 | karg.fw_version[10] = (ioc->facts.FWVersion.Struct.Dev % 10 ) + '0'; |
| 2478 | karg.fw_version[11] = '\0'; |
| 2479 | |
| 2480 | /* Issue a config request to get the device serial number |
| 2481 | */ |
| 2482 | hdr.PageVersion = 0; |
| 2483 | hdr.PageLength = 0; |
| 2484 | hdr.PageNumber = 0; |
| 2485 | hdr.PageType = MPI_CONFIG_PAGETYPE_MANUFACTURING; |
Christoph Hellwig | 69218ee | 2005-08-18 16:26:15 +0200 | [diff] [blame] | 2486 | cfg.cfghdr.hdr = &hdr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2487 | cfg.physAddr = -1; |
| 2488 | cfg.pageAddr = 0; |
| 2489 | cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER; |
| 2490 | cfg.dir = 0; /* read */ |
| 2491 | cfg.timeout = 10; |
| 2492 | |
| 2493 | strncpy(karg.serial_number, " ", 24); |
| 2494 | if (mpt_config(ioc, &cfg) == 0) { |
Christoph Hellwig | 69218ee | 2005-08-18 16:26:15 +0200 | [diff] [blame] | 2495 | if (cfg.cfghdr.hdr->PageLength > 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2496 | /* Issue the second config page request */ |
| 2497 | cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT; |
| 2498 | |
| 2499 | pbuf = pci_alloc_consistent(ioc->pcidev, hdr.PageLength * 4, &buf_dma); |
| 2500 | if (pbuf) { |
| 2501 | cfg.physAddr = buf_dma; |
| 2502 | if (mpt_config(ioc, &cfg) == 0) { |
| 2503 | ManufacturingPage0_t *pdata = (ManufacturingPage0_t *) pbuf; |
| 2504 | if (strlen(pdata->BoardTracerNumber) > 1) { |
| 2505 | strncpy(karg.serial_number, pdata->BoardTracerNumber, 24); |
| 2506 | karg.serial_number[24-1]='\0'; |
| 2507 | } |
| 2508 | } |
| 2509 | pci_free_consistent(ioc->pcidev, hdr.PageLength * 4, pbuf, buf_dma); |
| 2510 | pbuf = NULL; |
| 2511 | } |
| 2512 | } |
| 2513 | } |
| 2514 | rc = mpt_GetIocState(ioc, 1); |
| 2515 | switch (rc) { |
| 2516 | case MPI_IOC_STATE_OPERATIONAL: |
| 2517 | karg.ioc_status = HP_STATUS_OK; |
| 2518 | break; |
| 2519 | |
| 2520 | case MPI_IOC_STATE_FAULT: |
| 2521 | karg.ioc_status = HP_STATUS_FAILED; |
| 2522 | break; |
| 2523 | |
| 2524 | case MPI_IOC_STATE_RESET: |
| 2525 | case MPI_IOC_STATE_READY: |
| 2526 | default: |
| 2527 | karg.ioc_status = HP_STATUS_OTHER; |
| 2528 | break; |
| 2529 | } |
| 2530 | |
| 2531 | karg.base_io_addr = pci_resource_start(pdev, 0); |
| 2532 | |
Moore, Eric | 9cc1cfb | 2006-02-02 17:19:33 -0700 | [diff] [blame] | 2533 | if ((ioc->bus_type == SAS) || (ioc->bus_type == FC)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2534 | karg.bus_phys_width = HP_BUS_WIDTH_UNK; |
| 2535 | else |
| 2536 | karg.bus_phys_width = HP_BUS_WIDTH_16; |
| 2537 | |
| 2538 | karg.hard_resets = 0; |
| 2539 | karg.soft_resets = 0; |
| 2540 | karg.timeouts = 0; |
| 2541 | if (ioc->sh != NULL) { |
Eric Moore | e7eae9f | 2007-09-29 10:15:59 -0600 | [diff] [blame] | 2542 | MPT_SCSI_HOST *hd = shost_priv(ioc->sh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2543 | |
| 2544 | if (hd && (cim_rev == 1)) { |
Kashyap, Desai | 2f18786 | 2009-05-29 16:52:37 +0530 | [diff] [blame] | 2545 | karg.hard_resets = ioc->hard_resets; |
| 2546 | karg.soft_resets = ioc->soft_resets; |
| 2547 | karg.timeouts = ioc->timeouts; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2548 | } |
| 2549 | } |
| 2550 | |
Moore, Eric | 592f9c2 | 2006-02-02 17:19:47 -0700 | [diff] [blame] | 2551 | /* |
| 2552 | * Gather ISTWI(Industry Standard Two Wire Interface) Data |
| 2553 | */ |
| 2554 | if ((mf = mpt_get_msg_frame(mptctl_id, ioc)) == NULL) { |
Kashyap, Desai | ea2a788 | 2009-05-29 16:46:50 +0530 | [diff] [blame] | 2555 | dfailprintk(ioc, printk(MYIOC_s_WARN_FMT |
| 2556 | "%s, no msg frames!!\n", ioc->name, __func__)); |
Moore, Eric | 592f9c2 | 2006-02-02 17:19:47 -0700 | [diff] [blame] | 2557 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2558 | } |
| 2559 | |
Moore, Eric | 592f9c2 | 2006-02-02 17:19:47 -0700 | [diff] [blame] | 2560 | IstwiRWRequest = (ToolboxIstwiReadWriteRequest_t *)mf; |
| 2561 | mpi_hdr = (MPIHeader_t *) mf; |
| 2562 | memset(IstwiRWRequest,0,sizeof(ToolboxIstwiReadWriteRequest_t)); |
| 2563 | IstwiRWRequest->Function = MPI_FUNCTION_TOOLBOX; |
| 2564 | IstwiRWRequest->Tool = MPI_TOOLBOX_ISTWI_READ_WRITE_TOOL; |
| 2565 | IstwiRWRequest->MsgContext = mpi_hdr->MsgContext; |
| 2566 | IstwiRWRequest->Flags = MPI_TB_ISTWI_FLAGS_READ; |
| 2567 | IstwiRWRequest->NumAddressBytes = 0x01; |
| 2568 | IstwiRWRequest->DataLength = cpu_to_le16(0x04); |
| 2569 | if (pdev->devfn & 1) |
| 2570 | IstwiRWRequest->DeviceAddr = 0xB2; |
| 2571 | else |
| 2572 | IstwiRWRequest->DeviceAddr = 0xB0; |
| 2573 | |
| 2574 | pbuf = pci_alloc_consistent(ioc->pcidev, 4, &buf_dma); |
| 2575 | if (!pbuf) |
| 2576 | goto out; |
Kashyap, Desai | 14d0f0b | 2009-05-29 16:37:04 +0530 | [diff] [blame] | 2577 | ioc->add_sge((char *)&IstwiRWRequest->SGL, |
Moore, Eric | 592f9c2 | 2006-02-02 17:19:47 -0700 | [diff] [blame] | 2578 | (MPT_SGE_FLAGS_SSIMPLE_READ|4), buf_dma); |
| 2579 | |
Kashyap, Desai | ea2a788 | 2009-05-29 16:46:50 +0530 | [diff] [blame] | 2580 | retval = 0; |
| 2581 | SET_MGMT_MSG_CONTEXT(ioc->ioctl_cmds.msg_context, |
| 2582 | IstwiRWRequest->MsgContext); |
| 2583 | INITIALIZE_MGMT_STATUS(ioc->ioctl_cmds.status) |
Moore, Eric | 592f9c2 | 2006-02-02 17:19:47 -0700 | [diff] [blame] | 2584 | mpt_put_msg_frame(mptctl_id, ioc, mf); |
| 2585 | |
Kashyap, Desai | ea2a788 | 2009-05-29 16:46:50 +0530 | [diff] [blame] | 2586 | retry_wait: |
| 2587 | timeleft = wait_for_completion_timeout(&ioc->ioctl_cmds.done, |
| 2588 | HZ*MPT_IOCTL_DEFAULT_TIMEOUT); |
| 2589 | if (!(ioc->ioctl_cmds.status & MPT_MGMT_STATUS_COMMAND_GOOD)) { |
| 2590 | retval = -ETIME; |
| 2591 | printk(MYIOC_s_WARN_FMT "%s: failed\n", ioc->name, __func__); |
| 2592 | if (ioc->ioctl_cmds.status & MPT_MGMT_STATUS_DID_IOCRESET) { |
| 2593 | mpt_free_msg_frame(ioc, mf); |
| 2594 | goto out; |
| 2595 | } |
| 2596 | if (!timeleft) |
| 2597 | mptctl_timeout_expired(ioc, mf); |
| 2598 | else |
| 2599 | goto retry_wait; |
Moore, Eric | 592f9c2 | 2006-02-02 17:19:47 -0700 | [diff] [blame] | 2600 | goto out; |
| 2601 | } |
| 2602 | |
Prakash, Sathya | 09120a8 | 2007-07-24 15:49:05 +0530 | [diff] [blame] | 2603 | /* |
Moore, Eric | 592f9c2 | 2006-02-02 17:19:47 -0700 | [diff] [blame] | 2604 | *ISTWI Data Definition |
| 2605 | * pbuf[0] = FW_VERSION = 0x4 |
| 2606 | * pbuf[1] = Bay Count = 6 or 4 or 2, depending on |
| 2607 | * the config, you should be seeing one out of these three values |
| 2608 | * pbuf[2] = Drive Installed Map = bit pattern depend on which |
| 2609 | * bays have drives in them |
| 2610 | * pbuf[3] = Checksum (0x100 = (byte0 + byte2 + byte3) |
| 2611 | */ |
Kashyap, Desai | ea2a788 | 2009-05-29 16:46:50 +0530 | [diff] [blame] | 2612 | if (ioc->ioctl_cmds.status & MPT_MGMT_STATUS_RF_VALID) |
Moore, Eric | 592f9c2 | 2006-02-02 17:19:47 -0700 | [diff] [blame] | 2613 | karg.rsvd = *(u32 *)pbuf; |
| 2614 | |
| 2615 | out: |
Kashyap, Desai | ea2a788 | 2009-05-29 16:46:50 +0530 | [diff] [blame] | 2616 | CLEAR_MGMT_STATUS(ioc->ioctl_cmds.status) |
| 2617 | SET_MGMT_MSG_CONTEXT(ioc->ioctl_cmds.msg_context, 0); |
| 2618 | |
Moore, Eric | 592f9c2 | 2006-02-02 17:19:47 -0700 | [diff] [blame] | 2619 | if (pbuf) |
| 2620 | pci_free_consistent(ioc->pcidev, 4, pbuf, buf_dma); |
| 2621 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2622 | /* Copy the data from kernel memory to user memory |
| 2623 | */ |
| 2624 | if (copy_to_user((char __user *)arg, &karg, sizeof(hp_host_info_t))) { |
Eric Moore | 29dd360 | 2007-09-14 18:46:51 -0600 | [diff] [blame] | 2625 | printk(MYIOC_s_ERR_FMT "%s@%d::mptctl_hpgethostinfo - " |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2626 | "Unable to write out hp_host_info @ %p\n", |
Eric Moore | 29dd360 | 2007-09-14 18:46:51 -0600 | [diff] [blame] | 2627 | ioc->name, __FILE__, __LINE__, uarg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2628 | return -EFAULT; |
| 2629 | } |
| 2630 | |
| 2631 | return 0; |
| 2632 | |
| 2633 | } |
| 2634 | |
| 2635 | /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ |
Eric Moore | ba856d3 | 2006-07-11 17:34:01 -0600 | [diff] [blame] | 2636 | /* Prototype Routine for the TARGET INFO command. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2637 | * |
| 2638 | * Outputs: None. |
| 2639 | * Return: 0 if successful |
| 2640 | * -EFAULT if data unavailable |
Joe Perches | fc1323b | 2008-02-03 17:21:01 +0200 | [diff] [blame] | 2641 | * -EBUSY if previous command timeout and IOC reset is not complete. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2642 | * -ENODEV if no such device/adapter |
| 2643 | * -ETIME if timer expires |
| 2644 | * -ENOMEM if memory allocation error |
| 2645 | */ |
| 2646 | static int |
| 2647 | mptctl_hp_targetinfo(unsigned long arg) |
| 2648 | { |
| 2649 | hp_target_info_t __user *uarg = (void __user *) arg; |
| 2650 | SCSIDevicePage0_t *pg0_alloc; |
| 2651 | SCSIDevicePage3_t *pg3_alloc; |
| 2652 | MPT_ADAPTER *ioc; |
| 2653 | MPT_SCSI_HOST *hd = NULL; |
| 2654 | hp_target_info_t karg; |
| 2655 | int iocnum; |
| 2656 | int data_sz; |
| 2657 | dma_addr_t page_dma; |
| 2658 | CONFIGPARMS cfg; |
| 2659 | ConfigPageHeader_t hdr; |
| 2660 | int tmp, np, rc = 0; |
| 2661 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2662 | if (copy_from_user(&karg, uarg, sizeof(hp_target_info_t))) { |
Eric Moore | 29dd360 | 2007-09-14 18:46:51 -0600 | [diff] [blame] | 2663 | printk(KERN_ERR MYNAM "%s@%d::mptctl_hp_targetinfo - " |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2664 | "Unable to read in hp_host_targetinfo struct @ %p\n", |
| 2665 | __FILE__, __LINE__, uarg); |
| 2666 | return -EFAULT; |
| 2667 | } |
| 2668 | |
| 2669 | if (((iocnum = mpt_verify_adapter(karg.hdr.iocnum, &ioc)) < 0) || |
| 2670 | (ioc == NULL)) { |
Eric Moore | 29dd360 | 2007-09-14 18:46:51 -0600 | [diff] [blame] | 2671 | printk(KERN_DEBUG MYNAM "%s::mptctl_hp_targetinfo() @%d - ioc%d not found!\n", |
Prakash, Sathya | 09120a8 | 2007-07-24 15:49:05 +0530 | [diff] [blame] | 2672 | __FILE__, __LINE__, iocnum); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2673 | return -ENODEV; |
| 2674 | } |
Eric Moore | 29dd360 | 2007-09-14 18:46:51 -0600 | [diff] [blame] | 2675 | dctlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "mptctl_hp_targetinfo called.\n", |
Prakash, Sathya | 09120a8 | 2007-07-24 15:49:05 +0530 | [diff] [blame] | 2676 | ioc->name)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2677 | |
| 2678 | /* There is nothing to do for FCP parts. |
| 2679 | */ |
Moore, Eric | 9cc1cfb | 2006-02-02 17:19:33 -0700 | [diff] [blame] | 2680 | if ((ioc->bus_type == SAS) || (ioc->bus_type == FC)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2681 | return 0; |
| 2682 | |
| 2683 | if ((ioc->spi_data.sdp0length == 0) || (ioc->sh == NULL)) |
| 2684 | return 0; |
| 2685 | |
| 2686 | if (ioc->sh->host_no != karg.hdr.host) |
| 2687 | return -ENODEV; |
| 2688 | |
| 2689 | /* Get the data transfer speeds |
| 2690 | */ |
| 2691 | data_sz = ioc->spi_data.sdp0length * 4; |
| 2692 | pg0_alloc = (SCSIDevicePage0_t *) pci_alloc_consistent(ioc->pcidev, data_sz, &page_dma); |
| 2693 | if (pg0_alloc) { |
| 2694 | hdr.PageVersion = ioc->spi_data.sdp0version; |
| 2695 | hdr.PageLength = data_sz; |
| 2696 | hdr.PageNumber = 0; |
| 2697 | hdr.PageType = MPI_CONFIG_PAGETYPE_SCSI_DEVICE; |
| 2698 | |
Christoph Hellwig | 69218ee | 2005-08-18 16:26:15 +0200 | [diff] [blame] | 2699 | cfg.cfghdr.hdr = &hdr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2700 | cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT; |
| 2701 | cfg.dir = 0; |
| 2702 | cfg.timeout = 0; |
| 2703 | cfg.physAddr = page_dma; |
| 2704 | |
| 2705 | cfg.pageAddr = (karg.hdr.channel << 8) | karg.hdr.id; |
| 2706 | |
| 2707 | if ((rc = mpt_config(ioc, &cfg)) == 0) { |
| 2708 | np = le32_to_cpu(pg0_alloc->NegotiatedParameters); |
| 2709 | karg.negotiated_width = np & MPI_SCSIDEVPAGE0_NP_WIDE ? |
| 2710 | HP_BUS_WIDTH_16 : HP_BUS_WIDTH_8; |
| 2711 | |
| 2712 | if (np & MPI_SCSIDEVPAGE0_NP_NEG_SYNC_OFFSET_MASK) { |
| 2713 | tmp = (np & MPI_SCSIDEVPAGE0_NP_NEG_SYNC_PERIOD_MASK) >> 8; |
| 2714 | if (tmp < 0x09) |
| 2715 | karg.negotiated_speed = HP_DEV_SPEED_ULTRA320; |
| 2716 | else if (tmp <= 0x09) |
| 2717 | karg.negotiated_speed = HP_DEV_SPEED_ULTRA160; |
| 2718 | else if (tmp <= 0x0A) |
| 2719 | karg.negotiated_speed = HP_DEV_SPEED_ULTRA2; |
| 2720 | else if (tmp <= 0x0C) |
| 2721 | karg.negotiated_speed = HP_DEV_SPEED_ULTRA; |
| 2722 | else if (tmp <= 0x25) |
| 2723 | karg.negotiated_speed = HP_DEV_SPEED_FAST; |
| 2724 | else |
| 2725 | karg.negotiated_speed = HP_DEV_SPEED_ASYNC; |
| 2726 | } else |
| 2727 | karg.negotiated_speed = HP_DEV_SPEED_ASYNC; |
| 2728 | } |
| 2729 | |
| 2730 | pci_free_consistent(ioc->pcidev, data_sz, (u8 *) pg0_alloc, page_dma); |
| 2731 | } |
| 2732 | |
| 2733 | /* Set defaults |
| 2734 | */ |
| 2735 | karg.message_rejects = -1; |
| 2736 | karg.phase_errors = -1; |
| 2737 | karg.parity_errors = -1; |
| 2738 | karg.select_timeouts = -1; |
| 2739 | |
| 2740 | /* Get the target error parameters |
| 2741 | */ |
| 2742 | hdr.PageVersion = 0; |
| 2743 | hdr.PageLength = 0; |
| 2744 | hdr.PageNumber = 3; |
| 2745 | hdr.PageType = MPI_CONFIG_PAGETYPE_SCSI_DEVICE; |
| 2746 | |
Christoph Hellwig | 69218ee | 2005-08-18 16:26:15 +0200 | [diff] [blame] | 2747 | cfg.cfghdr.hdr = &hdr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2748 | cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER; |
| 2749 | cfg.dir = 0; |
| 2750 | cfg.timeout = 0; |
| 2751 | cfg.physAddr = -1; |
Christoph Hellwig | 69218ee | 2005-08-18 16:26:15 +0200 | [diff] [blame] | 2752 | if ((mpt_config(ioc, &cfg) == 0) && (cfg.cfghdr.hdr->PageLength > 0)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2753 | /* Issue the second config page request */ |
| 2754 | cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT; |
Christoph Hellwig | 69218ee | 2005-08-18 16:26:15 +0200 | [diff] [blame] | 2755 | data_sz = (int) cfg.cfghdr.hdr->PageLength * 4; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2756 | pg3_alloc = (SCSIDevicePage3_t *) pci_alloc_consistent( |
| 2757 | ioc->pcidev, data_sz, &page_dma); |
| 2758 | if (pg3_alloc) { |
| 2759 | cfg.physAddr = page_dma; |
| 2760 | cfg.pageAddr = (karg.hdr.channel << 8) | karg.hdr.id; |
| 2761 | if ((rc = mpt_config(ioc, &cfg)) == 0) { |
| 2762 | karg.message_rejects = (u32) le16_to_cpu(pg3_alloc->MsgRejectCount); |
| 2763 | karg.phase_errors = (u32) le16_to_cpu(pg3_alloc->PhaseErrorCount); |
| 2764 | karg.parity_errors = (u32) le16_to_cpu(pg3_alloc->ParityErrorCount); |
| 2765 | } |
| 2766 | pci_free_consistent(ioc->pcidev, data_sz, (u8 *) pg3_alloc, page_dma); |
| 2767 | } |
| 2768 | } |
Eric Moore | e7eae9f | 2007-09-29 10:15:59 -0600 | [diff] [blame] | 2769 | hd = shost_priv(ioc->sh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2770 | if (hd != NULL) |
| 2771 | karg.select_timeouts = hd->sel_timeout[karg.hdr.id]; |
| 2772 | |
| 2773 | /* Copy the data from kernel memory to user memory |
| 2774 | */ |
| 2775 | if (copy_to_user((char __user *)arg, &karg, sizeof(hp_target_info_t))) { |
Eric Moore | 29dd360 | 2007-09-14 18:46:51 -0600 | [diff] [blame] | 2776 | printk(MYIOC_s_ERR_FMT "%s@%d::mptctl_hp_target_info - " |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2777 | "Unable to write out mpt_ioctl_targetinfo struct @ %p\n", |
Eric Moore | 29dd360 | 2007-09-14 18:46:51 -0600 | [diff] [blame] | 2778 | ioc->name, __FILE__, __LINE__, uarg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2779 | return -EFAULT; |
| 2780 | } |
| 2781 | |
| 2782 | return 0; |
| 2783 | } |
| 2784 | |
| 2785 | /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ |
| 2786 | |
Arjan van de Ven | fa027c2 | 2007-02-12 00:55:33 -0800 | [diff] [blame] | 2787 | static const struct file_operations mptctl_fops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2788 | .owner = THIS_MODULE, |
| 2789 | .llseek = no_llseek, |
Moore, Eric | ea5a7a8 | 2006-02-02 17:20:01 -0700 | [diff] [blame] | 2790 | .fasync = mptctl_fasync, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2791 | .unlocked_ioctl = mptctl_ioctl, |
| 2792 | #ifdef CONFIG_COMPAT |
| 2793 | .compat_ioctl = compat_mpctl_ioctl, |
| 2794 | #endif |
| 2795 | }; |
| 2796 | |
| 2797 | static struct miscdevice mptctl_miscdev = { |
| 2798 | MPT_MINOR, |
| 2799 | MYNAM, |
| 2800 | &mptctl_fops |
| 2801 | }; |
| 2802 | |
| 2803 | /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ |
| 2804 | |
| 2805 | #ifdef CONFIG_COMPAT |
| 2806 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2807 | static int |
| 2808 | compat_mptfwxfer_ioctl(struct file *filp, unsigned int cmd, |
| 2809 | unsigned long arg) |
| 2810 | { |
| 2811 | struct mpt_fw_xfer32 kfw32; |
| 2812 | struct mpt_fw_xfer kfw; |
| 2813 | MPT_ADAPTER *iocp = NULL; |
| 2814 | int iocnum, iocnumX; |
| 2815 | int nonblock = (filp->f_flags & O_NONBLOCK); |
| 2816 | int ret; |
| 2817 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2818 | |
| 2819 | if (copy_from_user(&kfw32, (char __user *)arg, sizeof(kfw32))) |
| 2820 | return -EFAULT; |
| 2821 | |
| 2822 | /* Verify intended MPT adapter */ |
| 2823 | iocnumX = kfw32.iocnum & 0xFF; |
| 2824 | if (((iocnum = mpt_verify_adapter(iocnumX, &iocp)) < 0) || |
| 2825 | (iocp == NULL)) { |
Prakash, Sathya | 09120a8 | 2007-07-24 15:49:05 +0530 | [diff] [blame] | 2826 | printk(KERN_DEBUG MYNAM "::compat_mptfwxfer_ioctl @%d - ioc%d not found!\n", |
Eric Moore | 29dd360 | 2007-09-14 18:46:51 -0600 | [diff] [blame] | 2827 | __LINE__, iocnumX); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2828 | return -ENODEV; |
| 2829 | } |
| 2830 | |
| 2831 | if ((ret = mptctl_syscall_down(iocp, nonblock)) != 0) |
| 2832 | return ret; |
| 2833 | |
Prakash, Sathya | 09120a8 | 2007-07-24 15:49:05 +0530 | [diff] [blame] | 2834 | dctlprintk(iocp, printk(MYIOC_s_DEBUG_FMT "compat_mptfwxfer_ioctl() called\n", |
| 2835 | iocp->name)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2836 | kfw.iocnum = iocnum; |
| 2837 | kfw.fwlen = kfw32.fwlen; |
| 2838 | kfw.bufp = compat_ptr(kfw32.bufp); |
| 2839 | |
| 2840 | ret = mptctl_do_fw_download(kfw.iocnum, kfw.bufp, kfw.fwlen); |
| 2841 | |
Kashyap, Desai | ea2a788 | 2009-05-29 16:46:50 +0530 | [diff] [blame] | 2842 | mutex_unlock(&iocp->ioctl_cmds.mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2843 | |
| 2844 | return ret; |
| 2845 | } |
| 2846 | |
| 2847 | static int |
| 2848 | compat_mpt_command(struct file *filp, unsigned int cmd, |
| 2849 | unsigned long arg) |
| 2850 | { |
| 2851 | struct mpt_ioctl_command32 karg32; |
| 2852 | struct mpt_ioctl_command32 __user *uarg = (struct mpt_ioctl_command32 __user *) arg; |
| 2853 | struct mpt_ioctl_command karg; |
| 2854 | MPT_ADAPTER *iocp = NULL; |
| 2855 | int iocnum, iocnumX; |
| 2856 | int nonblock = (filp->f_flags & O_NONBLOCK); |
| 2857 | int ret; |
| 2858 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2859 | if (copy_from_user(&karg32, (char __user *)arg, sizeof(karg32))) |
| 2860 | return -EFAULT; |
| 2861 | |
| 2862 | /* Verify intended MPT adapter */ |
| 2863 | iocnumX = karg32.hdr.iocnum & 0xFF; |
| 2864 | if (((iocnum = mpt_verify_adapter(iocnumX, &iocp)) < 0) || |
| 2865 | (iocp == NULL)) { |
Prakash, Sathya | 09120a8 | 2007-07-24 15:49:05 +0530 | [diff] [blame] | 2866 | printk(KERN_DEBUG MYNAM "::compat_mpt_command @%d - ioc%d not found!\n", |
Eric Moore | 29dd360 | 2007-09-14 18:46:51 -0600 | [diff] [blame] | 2867 | __LINE__, iocnumX); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2868 | return -ENODEV; |
| 2869 | } |
| 2870 | |
| 2871 | if ((ret = mptctl_syscall_down(iocp, nonblock)) != 0) |
| 2872 | return ret; |
| 2873 | |
Prakash, Sathya | 09120a8 | 2007-07-24 15:49:05 +0530 | [diff] [blame] | 2874 | dctlprintk(iocp, printk(MYIOC_s_DEBUG_FMT "compat_mpt_command() called\n", |
| 2875 | iocp->name)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2876 | /* Copy data to karg */ |
| 2877 | karg.hdr.iocnum = karg32.hdr.iocnum; |
| 2878 | karg.hdr.port = karg32.hdr.port; |
| 2879 | karg.timeout = karg32.timeout; |
| 2880 | karg.maxReplyBytes = karg32.maxReplyBytes; |
| 2881 | |
| 2882 | karg.dataInSize = karg32.dataInSize; |
| 2883 | karg.dataOutSize = karg32.dataOutSize; |
| 2884 | karg.maxSenseBytes = karg32.maxSenseBytes; |
| 2885 | karg.dataSgeOffset = karg32.dataSgeOffset; |
| 2886 | |
| 2887 | karg.replyFrameBufPtr = (char __user *)(unsigned long)karg32.replyFrameBufPtr; |
| 2888 | karg.dataInBufPtr = (char __user *)(unsigned long)karg32.dataInBufPtr; |
| 2889 | karg.dataOutBufPtr = (char __user *)(unsigned long)karg32.dataOutBufPtr; |
| 2890 | karg.senseDataPtr = (char __user *)(unsigned long)karg32.senseDataPtr; |
| 2891 | |
| 2892 | /* Pass new structure to do_mpt_command |
| 2893 | */ |
| 2894 | ret = mptctl_do_mpt_command (karg, &uarg->MF); |
| 2895 | |
Kashyap, Desai | ea2a788 | 2009-05-29 16:46:50 +0530 | [diff] [blame] | 2896 | mutex_unlock(&iocp->ioctl_cmds.mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2897 | |
| 2898 | return ret; |
| 2899 | } |
| 2900 | |
| 2901 | static long compat_mpctl_ioctl(struct file *f, unsigned int cmd, unsigned long arg) |
| 2902 | { |
| 2903 | long ret; |
| 2904 | lock_kernel(); |
| 2905 | switch (cmd) { |
| 2906 | case MPTIOCINFO: |
| 2907 | case MPTIOCINFO1: |
| 2908 | case MPTIOCINFO2: |
| 2909 | case MPTTARGETINFO: |
| 2910 | case MPTEVENTQUERY: |
| 2911 | case MPTEVENTENABLE: |
| 2912 | case MPTEVENTREPORT: |
| 2913 | case MPTHARDRESET: |
| 2914 | case HP_GETHOSTINFO: |
| 2915 | case HP_GETTARGETINFO: |
| 2916 | case MPTTEST: |
| 2917 | ret = __mptctl_ioctl(f, cmd, arg); |
| 2918 | break; |
| 2919 | case MPTCOMMAND32: |
| 2920 | ret = compat_mpt_command(f, cmd, arg); |
| 2921 | break; |
| 2922 | case MPTFWDOWNLOAD32: |
| 2923 | ret = compat_mptfwxfer_ioctl(f, cmd, arg); |
| 2924 | break; |
| 2925 | default: |
| 2926 | ret = -ENOIOCTLCMD; |
| 2927 | break; |
| 2928 | } |
| 2929 | unlock_kernel(); |
| 2930 | return ret; |
| 2931 | } |
| 2932 | |
| 2933 | #endif |
| 2934 | |
| 2935 | |
| 2936 | /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ |
| 2937 | /* |
| 2938 | * mptctl_probe - Installs ioctl devices per bus. |
| 2939 | * @pdev: Pointer to pci_dev structure |
| 2940 | * |
| 2941 | * Returns 0 for success, non-zero for failure. |
| 2942 | * |
| 2943 | */ |
| 2944 | |
| 2945 | static int |
| 2946 | mptctl_probe(struct pci_dev *pdev, const struct pci_device_id *id) |
| 2947 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2948 | MPT_ADAPTER *ioc = pci_get_drvdata(pdev); |
| 2949 | |
Kashyap, Desai | ea2a788 | 2009-05-29 16:46:50 +0530 | [diff] [blame] | 2950 | mutex_init(&ioc->ioctl_cmds.mutex); |
| 2951 | init_completion(&ioc->ioctl_cmds.done); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2952 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2953 | } |
| 2954 | |
| 2955 | /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ |
| 2956 | /* |
| 2957 | * mptctl_remove - Removed ioctl devices |
| 2958 | * @pdev: Pointer to pci_dev structure |
| 2959 | * |
| 2960 | * |
| 2961 | */ |
| 2962 | static void |
| 2963 | mptctl_remove(struct pci_dev *pdev) |
| 2964 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2965 | } |
| 2966 | |
| 2967 | static struct mpt_pci_driver mptctl_driver = { |
| 2968 | .probe = mptctl_probe, |
| 2969 | .remove = mptctl_remove, |
| 2970 | }; |
| 2971 | |
| 2972 | /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ |
| 2973 | static int __init mptctl_init(void) |
| 2974 | { |
| 2975 | int err; |
| 2976 | int where = 1; |
| 2977 | |
| 2978 | show_mptmod_ver(my_NAME, my_VERSION); |
| 2979 | |
Prakash, Sathya | 09120a8 | 2007-07-24 15:49:05 +0530 | [diff] [blame] | 2980 | mpt_device_driver_register(&mptctl_driver, MPTCTL_DRIVER); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2981 | |
| 2982 | /* Register this device */ |
| 2983 | err = misc_register(&mptctl_miscdev); |
| 2984 | if (err < 0) { |
| 2985 | printk(KERN_ERR MYNAM ": Can't register misc device [minor=%d].\n", MPT_MINOR); |
| 2986 | goto out_fail; |
| 2987 | } |
| 2988 | printk(KERN_INFO MYNAM ": Registered with Fusion MPT base driver\n"); |
| 2989 | printk(KERN_INFO MYNAM ": /dev/%s @ (major,minor=%d,%d)\n", |
| 2990 | mptctl_miscdev.name, MISC_MAJOR, mptctl_miscdev.minor); |
| 2991 | |
| 2992 | /* |
| 2993 | * Install our handler |
| 2994 | */ |
| 2995 | ++where; |
Prakash, Sathya | f606f57 | 2007-08-14 16:12:53 +0530 | [diff] [blame] | 2996 | mptctl_id = mpt_register(mptctl_reply, MPTCTL_DRIVER); |
| 2997 | if (!mptctl_id || mptctl_id >= MPT_MAX_PROTOCOL_DRIVERS) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2998 | printk(KERN_ERR MYNAM ": ERROR: Failed to register with Fusion MPT base driver\n"); |
| 2999 | misc_deregister(&mptctl_miscdev); |
| 3000 | err = -EBUSY; |
| 3001 | goto out_fail; |
| 3002 | } |
| 3003 | |
Kashyap, Desai | ea2a788 | 2009-05-29 16:46:50 +0530 | [diff] [blame] | 3004 | mptctl_taskmgmt_id = mpt_register(mptctl_taskmgmt_reply, MPTCTL_DRIVER); |
Kei Tokunaga | 65c054f | 2010-03-15 14:48:43 +0900 | [diff] [blame] | 3005 | if (!mptctl_taskmgmt_id || mptctl_taskmgmt_id >= MPT_MAX_PROTOCOL_DRIVERS) { |
| 3006 | printk(KERN_ERR MYNAM ": ERROR: Failed to register with Fusion MPT base driver\n"); |
| 3007 | mpt_deregister(mptctl_id); |
| 3008 | misc_deregister(&mptctl_miscdev); |
| 3009 | err = -EBUSY; |
| 3010 | goto out_fail; |
| 3011 | } |
| 3012 | |
Prakash, Sathya | 09120a8 | 2007-07-24 15:49:05 +0530 | [diff] [blame] | 3013 | mpt_reset_register(mptctl_id, mptctl_ioc_reset); |
| 3014 | mpt_event_register(mptctl_id, mptctl_event_process); |
Moore, Eric | ea5a7a8 | 2006-02-02 17:20:01 -0700 | [diff] [blame] | 3015 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3016 | return 0; |
| 3017 | |
| 3018 | out_fail: |
| 3019 | |
| 3020 | mpt_device_driver_deregister(MPTCTL_DRIVER); |
| 3021 | |
| 3022 | return err; |
| 3023 | } |
| 3024 | |
| 3025 | /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ |
| 3026 | static void mptctl_exit(void) |
| 3027 | { |
| 3028 | misc_deregister(&mptctl_miscdev); |
| 3029 | printk(KERN_INFO MYNAM ": Deregistered /dev/%s @ (major,minor=%d,%d)\n", |
| 3030 | mptctl_miscdev.name, MISC_MAJOR, mptctl_miscdev.minor); |
| 3031 | |
Kei Tokunaga | 65c054f | 2010-03-15 14:48:43 +0900 | [diff] [blame] | 3032 | /* De-register event handler from base module */ |
| 3033 | mpt_event_deregister(mptctl_id); |
| 3034 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3035 | /* De-register reset handler from base module */ |
| 3036 | mpt_reset_deregister(mptctl_id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3037 | |
| 3038 | /* De-register callback handler from base module */ |
Kei Tokunaga | 65c054f | 2010-03-15 14:48:43 +0900 | [diff] [blame] | 3039 | mpt_deregister(mptctl_taskmgmt_id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3040 | mpt_deregister(mptctl_id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3041 | |
| 3042 | mpt_device_driver_deregister(MPTCTL_DRIVER); |
| 3043 | |
| 3044 | } |
| 3045 | |
| 3046 | /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ |
| 3047 | |
| 3048 | module_init(mptctl_init); |
| 3049 | module_exit(mptctl_exit); |