blob: 99a332d76f51446fb047fd977ac5a9360f77a965 [file] [log] [blame]
Eric Moore635374e2009-03-09 01:21:12 -06001/*
2 * Management Module Support for MPT (Message Passing Technology) based
3 * controllers
4 *
5 * This code is based on drivers/scsi/mpt2sas/mpt2_ctl.c
Kashyap, Desai19d3ebe2009-09-14 11:01:36 +05306 * Copyright (C) 2007-2009 LSI Corporation
Eric Moore635374e2009-03-09 01:21:12 -06007 * (mailto:DL-MPTFusionLinux@lsi.com)
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version 2
12 * of the License, or (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * NO WARRANTY
20 * THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR
21 * CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT
22 * LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT,
23 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is
24 * solely responsible for determining the appropriateness of using and
25 * distributing the Program and assumes all risks associated with its
26 * exercise of rights under this Agreement, including but not limited to
27 * the risks and costs of program errors, damage to or loss of data,
28 * programs or equipment, and unavailability or interruption of operations.
29
30 * DISCLAIMER OF LIABILITY
31 * NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY
32 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
33 * DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND
34 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
35 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
36 * USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED
37 * HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES
38
39 * You should have received a copy of the GNU General Public License
40 * along with this program; if not, write to the Free Software
41 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
42 * USA.
43 */
44
45#include <linux/version.h>
46#include <linux/kernel.h>
47#include <linux/module.h>
48#include <linux/errno.h>
49#include <linux/init.h>
50#include <linux/slab.h>
51#include <linux/types.h>
52#include <linux/pci.h>
53#include <linux/delay.h>
54#include <linux/smp_lock.h>
55#include <linux/compat.h>
56#include <linux/poll.h>
57
58#include <linux/io.h>
59#include <linux/uaccess.h>
60
61#include "mpt2sas_base.h"
62#include "mpt2sas_ctl.h"
63
64static struct fasync_struct *async_queue;
65static DECLARE_WAIT_QUEUE_HEAD(ctl_poll_wait);
66
Eric Moore99bb2142009-04-21 15:42:13 -060067static int _ctl_send_release(struct MPT2SAS_ADAPTER *ioc, u8 buffer_type,
68 u8 *issue_reset);
69
Eric Moore635374e2009-03-09 01:21:12 -060070/**
71 * enum block_state - blocking state
72 * @NON_BLOCKING: non blocking
73 * @BLOCKING: blocking
74 *
75 * These states are for ioctls that need to wait for a response
76 * from firmware, so they probably require sleep.
77 */
78enum block_state {
79 NON_BLOCKING,
80 BLOCKING,
81};
82
83#ifdef CONFIG_SCSI_MPT2SAS_LOGGING
84/**
85 * _ctl_display_some_debug - debug routine
86 * @ioc: per adapter object
87 * @smid: system request message index
88 * @calling_function_name: string pass from calling function
89 * @mpi_reply: reply message frame
90 * Context: none.
91 *
92 * Function for displaying debug info helpfull when debugging issues
93 * in this module.
94 */
95static void
96_ctl_display_some_debug(struct MPT2SAS_ADAPTER *ioc, u16 smid,
97 char *calling_function_name, MPI2DefaultReply_t *mpi_reply)
98{
99 Mpi2ConfigRequest_t *mpi_request;
100 char *desc = NULL;
101
102 if (!(ioc->logging_level & MPT_DEBUG_IOCTL))
103 return;
104
105 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
106 switch (mpi_request->Function) {
107 case MPI2_FUNCTION_SCSI_IO_REQUEST:
108 {
109 Mpi2SCSIIORequest_t *scsi_request =
110 (Mpi2SCSIIORequest_t *)mpi_request;
111
112 snprintf(ioc->tmp_string, MPT_STRING_LENGTH,
113 "scsi_io, cmd(0x%02x), cdb_len(%d)",
114 scsi_request->CDB.CDB32[0],
115 le16_to_cpu(scsi_request->IoFlags) & 0xF);
116 desc = ioc->tmp_string;
117 break;
118 }
119 case MPI2_FUNCTION_SCSI_TASK_MGMT:
120 desc = "task_mgmt";
121 break;
122 case MPI2_FUNCTION_IOC_INIT:
123 desc = "ioc_init";
124 break;
125 case MPI2_FUNCTION_IOC_FACTS:
126 desc = "ioc_facts";
127 break;
128 case MPI2_FUNCTION_CONFIG:
129 {
130 Mpi2ConfigRequest_t *config_request =
131 (Mpi2ConfigRequest_t *)mpi_request;
132
133 snprintf(ioc->tmp_string, MPT_STRING_LENGTH,
134 "config, type(0x%02x), ext_type(0x%02x), number(%d)",
135 (config_request->Header.PageType &
136 MPI2_CONFIG_PAGETYPE_MASK), config_request->ExtPageType,
137 config_request->Header.PageNumber);
138 desc = ioc->tmp_string;
139 break;
140 }
141 case MPI2_FUNCTION_PORT_FACTS:
142 desc = "port_facts";
143 break;
144 case MPI2_FUNCTION_PORT_ENABLE:
145 desc = "port_enable";
146 break;
147 case MPI2_FUNCTION_EVENT_NOTIFICATION:
148 desc = "event_notification";
149 break;
150 case MPI2_FUNCTION_FW_DOWNLOAD:
151 desc = "fw_download";
152 break;
153 case MPI2_FUNCTION_FW_UPLOAD:
154 desc = "fw_upload";
155 break;
156 case MPI2_FUNCTION_RAID_ACTION:
157 desc = "raid_action";
158 break;
159 case MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH:
160 {
161 Mpi2SCSIIORequest_t *scsi_request =
162 (Mpi2SCSIIORequest_t *)mpi_request;
163
164 snprintf(ioc->tmp_string, MPT_STRING_LENGTH,
165 "raid_pass, cmd(0x%02x), cdb_len(%d)",
166 scsi_request->CDB.CDB32[0],
167 le16_to_cpu(scsi_request->IoFlags) & 0xF);
168 desc = ioc->tmp_string;
169 break;
170 }
171 case MPI2_FUNCTION_SAS_IO_UNIT_CONTROL:
172 desc = "sas_iounit_cntl";
173 break;
174 case MPI2_FUNCTION_SATA_PASSTHROUGH:
175 desc = "sata_pass";
176 break;
177 case MPI2_FUNCTION_DIAG_BUFFER_POST:
178 desc = "diag_buffer_post";
179 break;
180 case MPI2_FUNCTION_DIAG_RELEASE:
181 desc = "diag_release";
182 break;
183 case MPI2_FUNCTION_SMP_PASSTHROUGH:
184 desc = "smp_passthrough";
185 break;
186 }
187
188 if (!desc)
189 return;
190
191 printk(MPT2SAS_DEBUG_FMT "%s: %s, smid(%d)\n",
192 ioc->name, calling_function_name, desc, smid);
193
194 if (!mpi_reply)
195 return;
196
197 if (mpi_reply->IOCStatus || mpi_reply->IOCLogInfo)
198 printk(MPT2SAS_DEBUG_FMT
199 "\tiocstatus(0x%04x), loginfo(0x%08x)\n",
200 ioc->name, le16_to_cpu(mpi_reply->IOCStatus),
201 le32_to_cpu(mpi_reply->IOCLogInfo));
202
203 if (mpi_request->Function == MPI2_FUNCTION_SCSI_IO_REQUEST ||
204 mpi_request->Function ==
205 MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH) {
206 Mpi2SCSIIOReply_t *scsi_reply =
207 (Mpi2SCSIIOReply_t *)mpi_reply;
208 if (scsi_reply->SCSIState || scsi_reply->SCSIStatus)
209 printk(MPT2SAS_DEBUG_FMT
210 "\tscsi_state(0x%02x), scsi_status"
211 "(0x%02x)\n", ioc->name,
212 scsi_reply->SCSIState,
213 scsi_reply->SCSIStatus);
214 }
215}
216#endif
217
218/**
219 * mpt2sas_ctl_done - ctl module completion routine
220 * @ioc: per adapter object
221 * @smid: system request message index
Kashyap, Desai7b936b02009-09-25 11:44:41 +0530222 * @msix_index: MSIX table index supplied by the OS
Eric Moore635374e2009-03-09 01:21:12 -0600223 * @reply: reply message frame(lower 32bit addr)
224 * Context: none.
225 *
226 * The callback handler when using ioc->ctl_cb_idx.
227 *
Kashyap, Desai77e63ed2009-09-14 11:04:23 +0530228 * Return 1 meaning mf should be freed from _base_interrupt
229 * 0 means the mf is freed from this function.
Eric Moore635374e2009-03-09 01:21:12 -0600230 */
Kashyap, Desai77e63ed2009-09-14 11:04:23 +0530231u8
Kashyap, Desai7b936b02009-09-25 11:44:41 +0530232mpt2sas_ctl_done(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 msix_index,
233 u32 reply)
Eric Moore635374e2009-03-09 01:21:12 -0600234{
235 MPI2DefaultReply_t *mpi_reply;
236
237 if (ioc->ctl_cmds.status == MPT2_CMD_NOT_USED)
Kashyap, Desai77e63ed2009-09-14 11:04:23 +0530238 return 1;
Eric Moore635374e2009-03-09 01:21:12 -0600239 if (ioc->ctl_cmds.smid != smid)
Kashyap, Desai77e63ed2009-09-14 11:04:23 +0530240 return 1;
Eric Moore635374e2009-03-09 01:21:12 -0600241 ioc->ctl_cmds.status |= MPT2_CMD_COMPLETE;
242 mpi_reply = mpt2sas_base_get_reply_virt_addr(ioc, reply);
243 if (mpi_reply) {
244 memcpy(ioc->ctl_cmds.reply, mpi_reply, mpi_reply->MsgLength*4);
245 ioc->ctl_cmds.status |= MPT2_CMD_REPLY_VALID;
246 }
247#ifdef CONFIG_SCSI_MPT2SAS_LOGGING
248 _ctl_display_some_debug(ioc, smid, "ctl_done", mpi_reply);
249#endif
250 ioc->ctl_cmds.status &= ~MPT2_CMD_PENDING;
251 complete(&ioc->ctl_cmds.done);
Kashyap, Desai77e63ed2009-09-14 11:04:23 +0530252 return 1;
Eric Moore635374e2009-03-09 01:21:12 -0600253}
254
255/**
256 * _ctl_check_event_type - determines when an event needs logging
257 * @ioc: per adapter object
258 * @event: firmware event
259 *
260 * The bitmask in ioc->event_type[] indicates which events should be
261 * be saved in the driver event_log. This bitmask is set by application.
262 *
263 * Returns 1 when event should be captured, or zero means no match.
264 */
265static int
266_ctl_check_event_type(struct MPT2SAS_ADAPTER *ioc, u16 event)
267{
268 u16 i;
269 u32 desired_event;
270
271 if (event >= 128 || !event || !ioc->event_log)
272 return 0;
273
274 desired_event = (1 << (event % 32));
275 if (!desired_event)
276 desired_event = 1;
277 i = event / 32;
278 return desired_event & ioc->event_type[i];
279}
280
281/**
282 * mpt2sas_ctl_add_to_event_log - add event
283 * @ioc: per adapter object
284 * @mpi_reply: reply message frame
285 *
286 * Return nothing.
287 */
288void
289mpt2sas_ctl_add_to_event_log(struct MPT2SAS_ADAPTER *ioc,
290 Mpi2EventNotificationReply_t *mpi_reply)
291{
292 struct MPT2_IOCTL_EVENTS *event_log;
293 u16 event;
294 int i;
295 u32 sz, event_data_sz;
296 u8 send_aen = 0;
297
298 if (!ioc->event_log)
299 return;
300
301 event = le16_to_cpu(mpi_reply->Event);
302
303 if (_ctl_check_event_type(ioc, event)) {
304
305 /* insert entry into circular event_log */
306 i = ioc->event_context % MPT2SAS_CTL_EVENT_LOG_SIZE;
307 event_log = ioc->event_log;
308 event_log[i].event = event;
309 event_log[i].context = ioc->event_context++;
310
311 event_data_sz = le16_to_cpu(mpi_reply->EventDataLength)*4;
312 sz = min_t(u32, event_data_sz, MPT2_EVENT_DATA_SIZE);
313 memset(event_log[i].data, 0, MPT2_EVENT_DATA_SIZE);
314 memcpy(event_log[i].data, mpi_reply->EventData, sz);
315 send_aen = 1;
316 }
317
318 /* This aen_event_read_flag flag is set until the
319 * application has read the event log.
320 * For MPI2_EVENT_LOG_ENTRY_ADDED, we always notify.
321 */
322 if (event == MPI2_EVENT_LOG_ENTRY_ADDED ||
323 (send_aen && !ioc->aen_event_read_flag)) {
324 ioc->aen_event_read_flag = 1;
325 wake_up_interruptible(&ctl_poll_wait);
326 if (async_queue)
327 kill_fasync(&async_queue, SIGIO, POLL_IN);
328 }
329}
330
331/**
332 * mpt2sas_ctl_event_callback - firmware event handler (called at ISR time)
333 * @ioc: per adapter object
Kashyap, Desai7b936b02009-09-25 11:44:41 +0530334 * @msix_index: MSIX table index supplied by the OS
Eric Moore635374e2009-03-09 01:21:12 -0600335 * @reply: reply message frame(lower 32bit addr)
336 * Context: interrupt.
337 *
338 * This function merely adds a new work task into ioc->firmware_event_thread.
339 * The tasks are worked from _firmware_event_work in user context.
340 *
Kashyap, Desai77e63ed2009-09-14 11:04:23 +0530341 * Return 1 meaning mf should be freed from _base_interrupt
342 * 0 means the mf is freed from this function.
Eric Moore635374e2009-03-09 01:21:12 -0600343 */
Kashyap, Desai77e63ed2009-09-14 11:04:23 +0530344u8
Kashyap, Desai7b936b02009-09-25 11:44:41 +0530345mpt2sas_ctl_event_callback(struct MPT2SAS_ADAPTER *ioc, u8 msix_index,
346 u32 reply)
Eric Moore635374e2009-03-09 01:21:12 -0600347{
348 Mpi2EventNotificationReply_t *mpi_reply;
349
350 mpi_reply = mpt2sas_base_get_reply_virt_addr(ioc, reply);
351 mpt2sas_ctl_add_to_event_log(ioc, mpi_reply);
Kashyap, Desai77e63ed2009-09-14 11:04:23 +0530352 return 1;
Eric Moore635374e2009-03-09 01:21:12 -0600353}
354
355/**
356 * _ctl_verify_adapter - validates ioc_number passed from application
357 * @ioc: per adapter object
358 * @iocpp: The ioc pointer is returned in this.
359 *
360 * Return (-1) means error, else ioc_number.
361 */
362static int
363_ctl_verify_adapter(int ioc_number, struct MPT2SAS_ADAPTER **iocpp)
364{
365 struct MPT2SAS_ADAPTER *ioc;
366
Eric Mooreba33fad2009-03-15 21:37:18 -0600367 list_for_each_entry(ioc, &mpt2sas_ioc_list, list) {
Eric Moore635374e2009-03-09 01:21:12 -0600368 if (ioc->id != ioc_number)
369 continue;
370 *iocpp = ioc;
371 return ioc_number;
372 }
373 *iocpp = NULL;
374 return -1;
375}
376
377/**
378 * mpt2sas_ctl_reset_handler - reset callback handler (for ctl)
379 * @ioc: per adapter object
380 * @reset_phase: phase
381 *
382 * The handler for doing any required cleanup or initialization.
383 *
384 * The reset phase can be MPT2_IOC_PRE_RESET, MPT2_IOC_AFTER_RESET,
385 * MPT2_IOC_DONE_RESET
386 */
387void
388mpt2sas_ctl_reset_handler(struct MPT2SAS_ADAPTER *ioc, int reset_phase)
389{
Eric Moore99bb2142009-04-21 15:42:13 -0600390 int i;
391 u8 issue_reset;
392
Eric Moore635374e2009-03-09 01:21:12 -0600393 switch (reset_phase) {
394 case MPT2_IOC_PRE_RESET:
395 dtmprintk(ioc, printk(MPT2SAS_DEBUG_FMT "%s: "
396 "MPT2_IOC_PRE_RESET\n", ioc->name, __func__));
Eric Moore99bb2142009-04-21 15:42:13 -0600397 for (i = 0; i < MPI2_DIAG_BUF_TYPE_COUNT; i++) {
398 if (!(ioc->diag_buffer_status[i] &
399 MPT2_DIAG_BUFFER_IS_REGISTERED))
400 continue;
401 if ((ioc->diag_buffer_status[i] &
402 MPT2_DIAG_BUFFER_IS_RELEASED))
403 continue;
404 _ctl_send_release(ioc, i, &issue_reset);
405 }
Eric Moore635374e2009-03-09 01:21:12 -0600406 break;
407 case MPT2_IOC_AFTER_RESET:
408 dtmprintk(ioc, printk(MPT2SAS_DEBUG_FMT "%s: "
409 "MPT2_IOC_AFTER_RESET\n", ioc->name, __func__));
410 if (ioc->ctl_cmds.status & MPT2_CMD_PENDING) {
411 ioc->ctl_cmds.status |= MPT2_CMD_RESET;
412 mpt2sas_base_free_smid(ioc, ioc->ctl_cmds.smid);
413 complete(&ioc->ctl_cmds.done);
414 }
415 break;
416 case MPT2_IOC_DONE_RESET:
417 dtmprintk(ioc, printk(MPT2SAS_DEBUG_FMT "%s: "
418 "MPT2_IOC_DONE_RESET\n", ioc->name, __func__));
Eric Moore99bb2142009-04-21 15:42:13 -0600419
420 for (i = 0; i < MPI2_DIAG_BUF_TYPE_COUNT; i++) {
421 if (!(ioc->diag_buffer_status[i] &
422 MPT2_DIAG_BUFFER_IS_REGISTERED))
423 continue;
424 if ((ioc->diag_buffer_status[i] &
425 MPT2_DIAG_BUFFER_IS_RELEASED))
426 continue;
427 ioc->diag_buffer_status[i] |=
428 MPT2_DIAG_BUFFER_IS_DIAG_RESET;
429 }
Eric Moore635374e2009-03-09 01:21:12 -0600430 break;
431 }
432}
433
434/**
435 * _ctl_fasync -
436 * @fd -
437 * @filep -
438 * @mode -
439 *
440 * Called when application request fasyn callback handler.
441 */
442static int
443_ctl_fasync(int fd, struct file *filep, int mode)
444{
445 return fasync_helper(fd, filep, mode, &async_queue);
446}
447
448/**
449 * _ctl_release -
450 * @inode -
451 * @filep -
452 *
453 * Called when application releases the fasyn callback handler.
454 */
455static int
456_ctl_release(struct inode *inode, struct file *filep)
457{
458 return fasync_helper(-1, filep, 0, &async_queue);
459}
460
461/**
462 * _ctl_poll -
463 * @file -
464 * @wait -
465 *
466 */
467static unsigned int
468_ctl_poll(struct file *filep, poll_table *wait)
469{
470 struct MPT2SAS_ADAPTER *ioc;
471
472 poll_wait(filep, &ctl_poll_wait, wait);
473
Eric Mooreba33fad2009-03-15 21:37:18 -0600474 list_for_each_entry(ioc, &mpt2sas_ioc_list, list) {
Eric Moore635374e2009-03-09 01:21:12 -0600475 if (ioc->aen_event_read_flag)
476 return POLLIN | POLLRDNORM;
477 }
478 return 0;
479}
480
481/**
Eric Mooreddf59a32009-05-18 13:01:29 -0600482 * _ctl_set_task_mid - assign an active smid to tm request
Eric Moore635374e2009-03-09 01:21:12 -0600483 * @ioc: per adapter object
484 * @karg - (struct mpt2_ioctl_command)
485 * @tm_request - pointer to mf from user space
486 *
487 * Returns 0 when an smid if found, else fail.
488 * during failure, the reply frame is filled.
489 */
490static int
Eric Mooreddf59a32009-05-18 13:01:29 -0600491_ctl_set_task_mid(struct MPT2SAS_ADAPTER *ioc, struct mpt2_ioctl_command *karg,
Eric Moore635374e2009-03-09 01:21:12 -0600492 Mpi2SCSITaskManagementRequest_t *tm_request)
493{
494 u8 found = 0;
495 u16 i;
496 u16 handle;
497 struct scsi_cmnd *scmd;
498 struct MPT2SAS_DEVICE *priv_data;
499 unsigned long flags;
500 Mpi2SCSITaskManagementReply_t *tm_reply;
501 u32 sz;
502 u32 lun;
Eric Mooreddf59a32009-05-18 13:01:29 -0600503 char *desc = NULL;
504
505 if (tm_request->TaskType == MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK)
506 desc = "abort_task";
507 else if (tm_request->TaskType == MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK)
508 desc = "query_task";
509 else
510 return 0;
Eric Moore635374e2009-03-09 01:21:12 -0600511
512 lun = scsilun_to_int((struct scsi_lun *)tm_request->LUN);
513
514 handle = le16_to_cpu(tm_request->DevHandle);
515 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
Kashyap, Desai595bb0b2009-09-14 11:02:48 +0530516 for (i = ioc->scsiio_depth; i && !found; i--) {
Eric Moore635374e2009-03-09 01:21:12 -0600517 scmd = ioc->scsi_lookup[i - 1].scmd;
518 if (scmd == NULL || scmd->device == NULL ||
519 scmd->device->hostdata == NULL)
520 continue;
521 if (lun != scmd->device->lun)
522 continue;
523 priv_data = scmd->device->hostdata;
524 if (priv_data->sas_target == NULL)
525 continue;
526 if (priv_data->sas_target->handle != handle)
527 continue;
528 tm_request->TaskMID = cpu_to_le16(ioc->scsi_lookup[i - 1].smid);
529 found = 1;
530 }
531 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
532
533 if (!found) {
Eric Mooreddf59a32009-05-18 13:01:29 -0600534 dctlprintk(ioc, printk(MPT2SAS_DEBUG_FMT "%s: "
535 "handle(0x%04x), lun(%d), no active mid!!\n", ioc->name,
536 desc, tm_request->DevHandle, lun));
Eric Moore635374e2009-03-09 01:21:12 -0600537 tm_reply = ioc->ctl_cmds.reply;
538 tm_reply->DevHandle = tm_request->DevHandle;
539 tm_reply->Function = MPI2_FUNCTION_SCSI_TASK_MGMT;
Eric Mooreddf59a32009-05-18 13:01:29 -0600540 tm_reply->TaskType = tm_request->TaskType;
Eric Moore635374e2009-03-09 01:21:12 -0600541 tm_reply->MsgLength = sizeof(Mpi2SCSITaskManagementReply_t)/4;
542 tm_reply->VP_ID = tm_request->VP_ID;
543 tm_reply->VF_ID = tm_request->VF_ID;
544 sz = min_t(u32, karg->max_reply_bytes, ioc->reply_sz);
545 if (copy_to_user(karg->reply_frame_buf_ptr, ioc->ctl_cmds.reply,
546 sz))
547 printk(KERN_ERR "failure at %s:%d/%s()!\n", __FILE__,
548 __LINE__, __func__);
549 return 1;
550 }
551
Eric Mooreddf59a32009-05-18 13:01:29 -0600552 dctlprintk(ioc, printk(MPT2SAS_DEBUG_FMT "%s: "
553 "handle(0x%04x), lun(%d), task_mid(%d)\n", ioc->name,
554 desc, tm_request->DevHandle, lun, tm_request->TaskMID));
Eric Moore635374e2009-03-09 01:21:12 -0600555 return 0;
556}
557
558/**
559 * _ctl_do_mpt_command - main handler for MPT2COMMAND opcode
560 * @ioc: per adapter object
561 * @karg - (struct mpt2_ioctl_command)
562 * @mf - pointer to mf in user space
563 * @state - NON_BLOCKING or BLOCKING
564 */
565static long
566_ctl_do_mpt_command(struct MPT2SAS_ADAPTER *ioc,
567 struct mpt2_ioctl_command karg, void __user *mf, enum block_state state)
568{
569 MPI2RequestHeader_t *mpi_request;
570 MPI2DefaultReply_t *mpi_reply;
571 u32 ioc_state;
572 u16 ioc_status;
573 u16 smid;
574 unsigned long timeout, timeleft;
575 u8 issue_reset;
576 u32 sz;
577 void *psge;
578 void *priv_sense = NULL;
579 void *data_out = NULL;
580 dma_addr_t data_out_dma;
581 size_t data_out_sz = 0;
582 void *data_in = NULL;
583 dma_addr_t data_in_dma;
584 size_t data_in_sz = 0;
585 u32 sgl_flags;
586 long ret;
587 u16 wait_state_count;
588
589 issue_reset = 0;
590
591 if (state == NON_BLOCKING && !mutex_trylock(&ioc->ctl_cmds.mutex))
592 return -EAGAIN;
593 else if (mutex_lock_interruptible(&ioc->ctl_cmds.mutex))
594 return -ERESTARTSYS;
595
596 if (ioc->ctl_cmds.status != MPT2_CMD_NOT_USED) {
597 printk(MPT2SAS_ERR_FMT "%s: ctl_cmd in use\n",
598 ioc->name, __func__);
599 ret = -EAGAIN;
600 goto out;
601 }
602
603 wait_state_count = 0;
604 ioc_state = mpt2sas_base_get_iocstate(ioc, 1);
605 while (ioc_state != MPI2_IOC_STATE_OPERATIONAL) {
606 if (wait_state_count++ == 10) {
607 printk(MPT2SAS_ERR_FMT
608 "%s: failed due to ioc not operational\n",
609 ioc->name, __func__);
610 ret = -EFAULT;
611 goto out;
612 }
613 ssleep(1);
614 ioc_state = mpt2sas_base_get_iocstate(ioc, 1);
615 printk(MPT2SAS_INFO_FMT "%s: waiting for "
616 "operational state(count=%d)\n", ioc->name,
617 __func__, wait_state_count);
618 }
619 if (wait_state_count)
620 printk(MPT2SAS_INFO_FMT "%s: ioc is operational\n",
621 ioc->name, __func__);
622
Kashyap, Desai595bb0b2009-09-14 11:02:48 +0530623 smid = mpt2sas_base_get_smid_scsiio(ioc, ioc->ctl_cb_idx, NULL);
Eric Moore635374e2009-03-09 01:21:12 -0600624 if (!smid) {
625 printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n",
626 ioc->name, __func__);
627 ret = -EAGAIN;
628 goto out;
629 }
630
631 ret = 0;
632 ioc->ctl_cmds.status = MPT2_CMD_PENDING;
633 memset(ioc->ctl_cmds.reply, 0, ioc->reply_sz);
634 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
635 ioc->ctl_cmds.smid = smid;
636 data_out_sz = karg.data_out_size;
637 data_in_sz = karg.data_in_size;
638
639 /* copy in request message frame from user */
640 if (copy_from_user(mpi_request, mf, karg.data_sge_offset*4)) {
641 printk(KERN_ERR "failure at %s:%d/%s()!\n", __FILE__, __LINE__,
642 __func__);
643 ret = -EFAULT;
644 mpt2sas_base_free_smid(ioc, smid);
645 goto out;
646 }
647
648 if (mpi_request->Function == MPI2_FUNCTION_SCSI_IO_REQUEST ||
649 mpi_request->Function == MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH) {
650 if (!mpi_request->FunctionDependent1 ||
651 mpi_request->FunctionDependent1 >
652 cpu_to_le16(ioc->facts.MaxDevHandle)) {
653 ret = -EINVAL;
654 mpt2sas_base_free_smid(ioc, smid);
655 goto out;
656 }
657 }
658
659 /* obtain dma-able memory for data transfer */
660 if (data_out_sz) /* WRITE */ {
661 data_out = pci_alloc_consistent(ioc->pdev, data_out_sz,
662 &data_out_dma);
663 if (!data_out) {
664 printk(KERN_ERR "failure at %s:%d/%s()!\n", __FILE__,
665 __LINE__, __func__);
666 ret = -ENOMEM;
667 mpt2sas_base_free_smid(ioc, smid);
668 goto out;
669 }
670 if (copy_from_user(data_out, karg.data_out_buf_ptr,
671 data_out_sz)) {
672 printk(KERN_ERR "failure at %s:%d/%s()!\n", __FILE__,
673 __LINE__, __func__);
674 ret = -EFAULT;
675 mpt2sas_base_free_smid(ioc, smid);
676 goto out;
677 }
678 }
679
680 if (data_in_sz) /* READ */ {
681 data_in = pci_alloc_consistent(ioc->pdev, data_in_sz,
682 &data_in_dma);
683 if (!data_in) {
684 printk(KERN_ERR "failure at %s:%d/%s()!\n", __FILE__,
685 __LINE__, __func__);
686 ret = -ENOMEM;
687 mpt2sas_base_free_smid(ioc, smid);
688 goto out;
689 }
690 }
691
692 /* add scatter gather elements */
693 psge = (void *)mpi_request + (karg.data_sge_offset*4);
694
695 if (!data_out_sz && !data_in_sz) {
696 mpt2sas_base_build_zero_len_sge(ioc, psge);
697 } else if (data_out_sz && data_in_sz) {
698 /* WRITE sgel first */
699 sgl_flags = (MPI2_SGE_FLAGS_SIMPLE_ELEMENT |
700 MPI2_SGE_FLAGS_END_OF_BUFFER | MPI2_SGE_FLAGS_HOST_TO_IOC);
701 sgl_flags = sgl_flags << MPI2_SGE_FLAGS_SHIFT;
702 ioc->base_add_sg_single(psge, sgl_flags |
703 data_out_sz, data_out_dma);
704
705 /* incr sgel */
706 psge += ioc->sge_size;
707
708 /* READ sgel last */
709 sgl_flags = (MPI2_SGE_FLAGS_SIMPLE_ELEMENT |
710 MPI2_SGE_FLAGS_LAST_ELEMENT | MPI2_SGE_FLAGS_END_OF_BUFFER |
711 MPI2_SGE_FLAGS_END_OF_LIST);
712 sgl_flags = sgl_flags << MPI2_SGE_FLAGS_SHIFT;
713 ioc->base_add_sg_single(psge, sgl_flags |
714 data_in_sz, data_in_dma);
715 } else if (data_out_sz) /* WRITE */ {
716 sgl_flags = (MPI2_SGE_FLAGS_SIMPLE_ELEMENT |
717 MPI2_SGE_FLAGS_LAST_ELEMENT | MPI2_SGE_FLAGS_END_OF_BUFFER |
718 MPI2_SGE_FLAGS_END_OF_LIST | MPI2_SGE_FLAGS_HOST_TO_IOC);
719 sgl_flags = sgl_flags << MPI2_SGE_FLAGS_SHIFT;
720 ioc->base_add_sg_single(psge, sgl_flags |
721 data_out_sz, data_out_dma);
722 } else if (data_in_sz) /* READ */ {
723 sgl_flags = (MPI2_SGE_FLAGS_SIMPLE_ELEMENT |
724 MPI2_SGE_FLAGS_LAST_ELEMENT | MPI2_SGE_FLAGS_END_OF_BUFFER |
725 MPI2_SGE_FLAGS_END_OF_LIST);
726 sgl_flags = sgl_flags << MPI2_SGE_FLAGS_SHIFT;
727 ioc->base_add_sg_single(psge, sgl_flags |
728 data_in_sz, data_in_dma);
729 }
730
731 /* send command to firmware */
732#ifdef CONFIG_SCSI_MPT2SAS_LOGGING
733 _ctl_display_some_debug(ioc, smid, "ctl_request", NULL);
734#endif
735
736 switch (mpi_request->Function) {
737 case MPI2_FUNCTION_SCSI_IO_REQUEST:
738 case MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH:
739 {
740 Mpi2SCSIIORequest_t *scsiio_request =
741 (Mpi2SCSIIORequest_t *)mpi_request;
742 scsiio_request->SenseBufferLowAddress =
743 (u32)mpt2sas_base_get_sense_buffer_dma(ioc, smid);
744 priv_sense = mpt2sas_base_get_sense_buffer(ioc, smid);
745 memset(priv_sense, 0, SCSI_SENSE_BUFFERSIZE);
Kashyap, Desai7b936b02009-09-25 11:44:41 +0530746 mpt2sas_base_put_smid_scsi_io(ioc, smid,
Eric Moore635374e2009-03-09 01:21:12 -0600747 le16_to_cpu(mpi_request->FunctionDependent1));
748 break;
749 }
750 case MPI2_FUNCTION_SCSI_TASK_MGMT:
751 {
752 Mpi2SCSITaskManagementRequest_t *tm_request =
753 (Mpi2SCSITaskManagementRequest_t *)mpi_request;
754
755 if (tm_request->TaskType ==
Eric Mooreddf59a32009-05-18 13:01:29 -0600756 MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK ||
757 tm_request->TaskType ==
758 MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK) {
759 if (_ctl_set_task_mid(ioc, &karg, tm_request)) {
Eric Moore77bdd9e2009-04-21 15:39:24 -0600760 mpt2sas_base_free_smid(ioc, smid);
Eric Moore635374e2009-03-09 01:21:12 -0600761 goto out;
Eric Moore77bdd9e2009-04-21 15:39:24 -0600762 }
Eric Moore635374e2009-03-09 01:21:12 -0600763 }
764
765 mutex_lock(&ioc->tm_cmds.mutex);
766 mpt2sas_scsih_set_tm_flag(ioc, le16_to_cpu(
767 tm_request->DevHandle));
Kashyap, Desai7b936b02009-09-25 11:44:41 +0530768 mpt2sas_base_put_smid_hi_priority(ioc, smid);
Eric Moore635374e2009-03-09 01:21:12 -0600769 break;
770 }
771 case MPI2_FUNCTION_SMP_PASSTHROUGH:
772 {
773 Mpi2SmpPassthroughRequest_t *smp_request =
774 (Mpi2SmpPassthroughRequest_t *)mpi_request;
775 u8 *data;
776
777 /* ioc determines which port to use */
778 smp_request->PhysicalPort = 0xFF;
779 if (smp_request->PassthroughFlags &
780 MPI2_SMP_PT_REQ_PT_FLAGS_IMMEDIATE)
781 data = (u8 *)&smp_request->SGL;
782 else
783 data = data_out;
784
785 if (data[1] == 0x91 && (data[10] == 1 || data[10] == 2)) {
786 ioc->ioc_link_reset_in_progress = 1;
787 ioc->ignore_loginfos = 1;
788 }
Kashyap, Desai7b936b02009-09-25 11:44:41 +0530789 mpt2sas_base_put_smid_default(ioc, smid);
Eric Moore635374e2009-03-09 01:21:12 -0600790 break;
791 }
792 case MPI2_FUNCTION_SAS_IO_UNIT_CONTROL:
793 {
794 Mpi2SasIoUnitControlRequest_t *sasiounit_request =
795 (Mpi2SasIoUnitControlRequest_t *)mpi_request;
796
797 if (sasiounit_request->Operation == MPI2_SAS_OP_PHY_HARD_RESET
798 || sasiounit_request->Operation ==
799 MPI2_SAS_OP_PHY_LINK_RESET) {
800 ioc->ioc_link_reset_in_progress = 1;
801 ioc->ignore_loginfos = 1;
802 }
Kashyap, Desai7b936b02009-09-25 11:44:41 +0530803 mpt2sas_base_put_smid_default(ioc, smid);
Eric Moore635374e2009-03-09 01:21:12 -0600804 break;
805 }
806 default:
Kashyap, Desai7b936b02009-09-25 11:44:41 +0530807 mpt2sas_base_put_smid_default(ioc, smid);
Eric Moore635374e2009-03-09 01:21:12 -0600808 break;
809 }
810
811 if (karg.timeout < MPT2_IOCTL_DEFAULT_TIMEOUT)
812 timeout = MPT2_IOCTL_DEFAULT_TIMEOUT;
813 else
814 timeout = karg.timeout;
Kashyap, Desaibcfb6e62009-09-14 11:05:24 +0530815 init_completion(&ioc->ctl_cmds.done);
Eric Moore635374e2009-03-09 01:21:12 -0600816 timeleft = wait_for_completion_timeout(&ioc->ctl_cmds.done,
817 timeout*HZ);
818 if (mpi_request->Function == MPI2_FUNCTION_SCSI_TASK_MGMT) {
819 Mpi2SCSITaskManagementRequest_t *tm_request =
820 (Mpi2SCSITaskManagementRequest_t *)mpi_request;
821 mutex_unlock(&ioc->tm_cmds.mutex);
822 mpt2sas_scsih_clear_tm_flag(ioc, le16_to_cpu(
823 tm_request->DevHandle));
824 } else if ((mpi_request->Function == MPI2_FUNCTION_SMP_PASSTHROUGH ||
825 mpi_request->Function == MPI2_FUNCTION_SAS_IO_UNIT_CONTROL) &&
826 ioc->ioc_link_reset_in_progress) {
827 ioc->ioc_link_reset_in_progress = 0;
828 ioc->ignore_loginfos = 0;
829 }
830 if (!(ioc->ctl_cmds.status & MPT2_CMD_COMPLETE)) {
831 printk(MPT2SAS_ERR_FMT "%s: timeout\n", ioc->name,
832 __func__);
833 _debug_dump_mf(mpi_request, karg.data_sge_offset);
834 if (!(ioc->ctl_cmds.status & MPT2_CMD_RESET))
835 issue_reset = 1;
836 goto issue_host_reset;
837 }
838
839 mpi_reply = ioc->ctl_cmds.reply;
840 ioc_status = le16_to_cpu(mpi_reply->IOCStatus) & MPI2_IOCSTATUS_MASK;
841
842#ifdef CONFIG_SCSI_MPT2SAS_LOGGING
843 if (mpi_reply->Function == MPI2_FUNCTION_SCSI_TASK_MGMT &&
844 (ioc->logging_level & MPT_DEBUG_TM)) {
845 Mpi2SCSITaskManagementReply_t *tm_reply =
846 (Mpi2SCSITaskManagementReply_t *)mpi_reply;
847
848 printk(MPT2SAS_DEBUG_FMT "TASK_MGMT: "
849 "IOCStatus(0x%04x), IOCLogInfo(0x%08x), "
850 "TerminationCount(0x%08x)\n", ioc->name,
851 tm_reply->IOCStatus, tm_reply->IOCLogInfo,
852 tm_reply->TerminationCount);
853 }
854#endif
855 /* copy out xdata to user */
856 if (data_in_sz) {
857 if (copy_to_user(karg.data_in_buf_ptr, data_in,
858 data_in_sz)) {
859 printk(KERN_ERR "failure at %s:%d/%s()!\n", __FILE__,
860 __LINE__, __func__);
861 ret = -ENODATA;
862 goto out;
863 }
864 }
865
866 /* copy out reply message frame to user */
867 if (karg.max_reply_bytes) {
868 sz = min_t(u32, karg.max_reply_bytes, ioc->reply_sz);
869 if (copy_to_user(karg.reply_frame_buf_ptr, ioc->ctl_cmds.reply,
870 sz)) {
871 printk(KERN_ERR "failure at %s:%d/%s()!\n", __FILE__,
872 __LINE__, __func__);
873 ret = -ENODATA;
874 goto out;
875 }
876 }
877
878 /* copy out sense to user */
879 if (karg.max_sense_bytes && (mpi_request->Function ==
880 MPI2_FUNCTION_SCSI_IO_REQUEST || mpi_request->Function ==
881 MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH)) {
882 sz = min_t(u32, karg.max_sense_bytes, SCSI_SENSE_BUFFERSIZE);
883 if (copy_to_user(karg.sense_data_ptr, priv_sense, sz)) {
884 printk(KERN_ERR "failure at %s:%d/%s()!\n", __FILE__,
885 __LINE__, __func__);
886 ret = -ENODATA;
887 goto out;
888 }
889 }
890
891 issue_host_reset:
892 if (issue_reset) {
893 if ((mpi_request->Function == MPI2_FUNCTION_SCSI_IO_REQUEST ||
894 mpi_request->Function ==
895 MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH)) {
896 printk(MPT2SAS_INFO_FMT "issue target reset: handle "
897 "= (0x%04x)\n", ioc->name,
898 mpi_request->FunctionDependent1);
Kashyap, Desaifa7f3162009-09-23 17:26:58 +0530899 mpt2sas_halt_firmware(ioc);
Eric Moore635374e2009-03-09 01:21:12 -0600900 mutex_lock(&ioc->tm_cmds.mutex);
901 mpt2sas_scsih_issue_tm(ioc,
902 mpi_request->FunctionDependent1, 0,
903 MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET, 0, 10);
904 ioc->tm_cmds.status = MPT2_CMD_NOT_USED;
905 mutex_unlock(&ioc->tm_cmds.mutex);
906 } else
907 mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP,
908 FORCE_BIG_HAMMER);
909 }
910
911 out:
912
913 /* free memory associated with sg buffers */
914 if (data_in)
915 pci_free_consistent(ioc->pdev, data_in_sz, data_in,
916 data_in_dma);
917
918 if (data_out)
919 pci_free_consistent(ioc->pdev, data_out_sz, data_out,
920 data_out_dma);
921
922 ioc->ctl_cmds.status = MPT2_CMD_NOT_USED;
923 mutex_unlock(&ioc->ctl_cmds.mutex);
924 return ret;
925}
926
927/**
928 * _ctl_getiocinfo - main handler for MPT2IOCINFO opcode
929 * @arg - user space buffer containing ioctl content
930 */
931static long
932_ctl_getiocinfo(void __user *arg)
933{
934 struct mpt2_ioctl_iocinfo karg;
935 struct MPT2SAS_ADAPTER *ioc;
936 u8 revision;
937
938 if (copy_from_user(&karg, arg, sizeof(karg))) {
939 printk(KERN_ERR "failure at %s:%d/%s()!\n",
940 __FILE__, __LINE__, __func__);
941 return -EFAULT;
942 }
943 if (_ctl_verify_adapter(karg.hdr.ioc_number, &ioc) == -1 || !ioc)
944 return -ENODEV;
945
946 dctlprintk(ioc, printk(MPT2SAS_DEBUG_FMT "%s: enter\n", ioc->name,
947 __func__));
948
949 memset(&karg, 0 , sizeof(karg));
950 karg.adapter_type = MPT2_IOCTL_INTERFACE_SAS2;
951 if (ioc->pfacts)
952 karg.port_number = ioc->pfacts[0].PortNumber;
953 pci_read_config_byte(ioc->pdev, PCI_CLASS_REVISION, &revision);
954 karg.hw_rev = revision;
955 karg.pci_id = ioc->pdev->device;
956 karg.subsystem_device = ioc->pdev->subsystem_device;
957 karg.subsystem_vendor = ioc->pdev->subsystem_vendor;
958 karg.pci_information.u.bits.bus = ioc->pdev->bus->number;
959 karg.pci_information.u.bits.device = PCI_SLOT(ioc->pdev->devfn);
960 karg.pci_information.u.bits.function = PCI_FUNC(ioc->pdev->devfn);
961 karg.pci_information.segment_id = pci_domain_nr(ioc->pdev->bus);
962 karg.firmware_version = ioc->facts.FWVersion.Word;
Eric Mooree5f9bb12009-04-21 15:40:01 -0600963 strcpy(karg.driver_version, MPT2SAS_DRIVER_NAME);
964 strcat(karg.driver_version, "-");
965 strcat(karg.driver_version, MPT2SAS_DRIVER_VERSION);
Eric Moore635374e2009-03-09 01:21:12 -0600966 karg.bios_version = le32_to_cpu(ioc->bios_pg3.BiosVersion);
967
968 if (copy_to_user(arg, &karg, sizeof(karg))) {
969 printk(KERN_ERR "failure at %s:%d/%s()!\n",
970 __FILE__, __LINE__, __func__);
971 return -EFAULT;
972 }
973 return 0;
974}
975
976/**
977 * _ctl_eventquery - main handler for MPT2EVENTQUERY opcode
978 * @arg - user space buffer containing ioctl content
979 */
980static long
981_ctl_eventquery(void __user *arg)
982{
983 struct mpt2_ioctl_eventquery karg;
984 struct MPT2SAS_ADAPTER *ioc;
985
986 if (copy_from_user(&karg, arg, sizeof(karg))) {
987 printk(KERN_ERR "failure at %s:%d/%s()!\n",
988 __FILE__, __LINE__, __func__);
989 return -EFAULT;
990 }
991 if (_ctl_verify_adapter(karg.hdr.ioc_number, &ioc) == -1 || !ioc)
992 return -ENODEV;
993
994 dctlprintk(ioc, printk(MPT2SAS_DEBUG_FMT "%s: enter\n", ioc->name,
995 __func__));
996
997 karg.event_entries = MPT2SAS_CTL_EVENT_LOG_SIZE;
998 memcpy(karg.event_types, ioc->event_type,
999 MPI2_EVENT_NOTIFY_EVENTMASK_WORDS * sizeof(u32));
1000
1001 if (copy_to_user(arg, &karg, sizeof(karg))) {
1002 printk(KERN_ERR "failure at %s:%d/%s()!\n",
1003 __FILE__, __LINE__, __func__);
1004 return -EFAULT;
1005 }
1006 return 0;
1007}
1008
1009/**
1010 * _ctl_eventenable - main handler for MPT2EVENTENABLE opcode
1011 * @arg - user space buffer containing ioctl content
1012 */
1013static long
1014_ctl_eventenable(void __user *arg)
1015{
1016 struct mpt2_ioctl_eventenable karg;
1017 struct MPT2SAS_ADAPTER *ioc;
1018
1019 if (copy_from_user(&karg, arg, sizeof(karg))) {
1020 printk(KERN_ERR "failure at %s:%d/%s()!\n",
1021 __FILE__, __LINE__, __func__);
1022 return -EFAULT;
1023 }
1024 if (_ctl_verify_adapter(karg.hdr.ioc_number, &ioc) == -1 || !ioc)
1025 return -ENODEV;
1026
1027 dctlprintk(ioc, printk(MPT2SAS_DEBUG_FMT "%s: enter\n", ioc->name,
1028 __func__));
1029
1030 if (ioc->event_log)
1031 return 0;
1032 memcpy(ioc->event_type, karg.event_types,
1033 MPI2_EVENT_NOTIFY_EVENTMASK_WORDS * sizeof(u32));
1034 mpt2sas_base_validate_event_type(ioc, ioc->event_type);
1035
1036 /* initialize event_log */
1037 ioc->event_context = 0;
1038 ioc->aen_event_read_flag = 0;
1039 ioc->event_log = kcalloc(MPT2SAS_CTL_EVENT_LOG_SIZE,
1040 sizeof(struct MPT2_IOCTL_EVENTS), GFP_KERNEL);
1041 if (!ioc->event_log) {
1042 printk(KERN_ERR "failure at %s:%d/%s()!\n",
1043 __FILE__, __LINE__, __func__);
1044 return -ENOMEM;
1045 }
1046 return 0;
1047}
1048
1049/**
1050 * _ctl_eventreport - main handler for MPT2EVENTREPORT opcode
1051 * @arg - user space buffer containing ioctl content
1052 */
1053static long
1054_ctl_eventreport(void __user *arg)
1055{
1056 struct mpt2_ioctl_eventreport karg;
1057 struct MPT2SAS_ADAPTER *ioc;
1058 u32 number_bytes, max_events, max;
1059 struct mpt2_ioctl_eventreport __user *uarg = arg;
1060
1061 if (copy_from_user(&karg, arg, sizeof(karg))) {
1062 printk(KERN_ERR "failure at %s:%d/%s()!\n",
1063 __FILE__, __LINE__, __func__);
1064 return -EFAULT;
1065 }
1066 if (_ctl_verify_adapter(karg.hdr.ioc_number, &ioc) == -1 || !ioc)
1067 return -ENODEV;
1068
1069 dctlprintk(ioc, printk(MPT2SAS_DEBUG_FMT "%s: enter\n", ioc->name,
1070 __func__));
1071
1072 number_bytes = karg.hdr.max_data_size -
1073 sizeof(struct mpt2_ioctl_header);
1074 max_events = number_bytes/sizeof(struct MPT2_IOCTL_EVENTS);
1075 max = min_t(u32, MPT2SAS_CTL_EVENT_LOG_SIZE, max_events);
1076
1077 /* If fewer than 1 event is requested, there must have
1078 * been some type of error.
1079 */
1080 if (!max || !ioc->event_log)
1081 return -ENODATA;
1082
1083 number_bytes = max * sizeof(struct MPT2_IOCTL_EVENTS);
1084 if (copy_to_user(uarg->event_data, ioc->event_log, number_bytes)) {
1085 printk(KERN_ERR "failure at %s:%d/%s()!\n",
1086 __FILE__, __LINE__, __func__);
1087 return -EFAULT;
1088 }
1089
1090 /* reset flag so SIGIO can restart */
1091 ioc->aen_event_read_flag = 0;
1092 return 0;
1093}
1094
1095/**
1096 * _ctl_do_reset - main handler for MPT2HARDRESET opcode
1097 * @arg - user space buffer containing ioctl content
1098 */
1099static long
1100_ctl_do_reset(void __user *arg)
1101{
1102 struct mpt2_ioctl_diag_reset karg;
1103 struct MPT2SAS_ADAPTER *ioc;
1104 int retval;
1105
1106 if (copy_from_user(&karg, arg, sizeof(karg))) {
1107 printk(KERN_ERR "failure at %s:%d/%s()!\n",
1108 __FILE__, __LINE__, __func__);
1109 return -EFAULT;
1110 }
1111 if (_ctl_verify_adapter(karg.hdr.ioc_number, &ioc) == -1 || !ioc)
1112 return -ENODEV;
1113
1114 dctlprintk(ioc, printk(MPT2SAS_DEBUG_FMT "%s: enter\n", ioc->name,
1115 __func__));
1116
1117 retval = mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP,
1118 FORCE_BIG_HAMMER);
1119 printk(MPT2SAS_INFO_FMT "host reset: %s\n",
1120 ioc->name, ((!retval) ? "SUCCESS" : "FAILED"));
1121 return 0;
1122}
1123
1124/**
1125 * _ctl_btdh_search_sas_device - searching for sas device
1126 * @ioc: per adapter object
1127 * @btdh: btdh ioctl payload
1128 */
1129static int
1130_ctl_btdh_search_sas_device(struct MPT2SAS_ADAPTER *ioc,
1131 struct mpt2_ioctl_btdh_mapping *btdh)
1132{
1133 struct _sas_device *sas_device;
1134 unsigned long flags;
1135 int rc = 0;
1136
1137 if (list_empty(&ioc->sas_device_list))
1138 return rc;
1139
1140 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1141 list_for_each_entry(sas_device, &ioc->sas_device_list, list) {
1142 if (btdh->bus == 0xFFFFFFFF && btdh->id == 0xFFFFFFFF &&
1143 btdh->handle == sas_device->handle) {
1144 btdh->bus = sas_device->channel;
1145 btdh->id = sas_device->id;
1146 rc = 1;
1147 goto out;
1148 } else if (btdh->bus == sas_device->channel && btdh->id ==
1149 sas_device->id && btdh->handle == 0xFFFF) {
1150 btdh->handle = sas_device->handle;
1151 rc = 1;
1152 goto out;
1153 }
1154 }
1155 out:
1156 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1157 return rc;
1158}
1159
1160/**
1161 * _ctl_btdh_search_raid_device - searching for raid device
1162 * @ioc: per adapter object
1163 * @btdh: btdh ioctl payload
1164 */
1165static int
1166_ctl_btdh_search_raid_device(struct MPT2SAS_ADAPTER *ioc,
1167 struct mpt2_ioctl_btdh_mapping *btdh)
1168{
1169 struct _raid_device *raid_device;
1170 unsigned long flags;
1171 int rc = 0;
1172
1173 if (list_empty(&ioc->raid_device_list))
1174 return rc;
1175
1176 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1177 list_for_each_entry(raid_device, &ioc->raid_device_list, list) {
1178 if (btdh->bus == 0xFFFFFFFF && btdh->id == 0xFFFFFFFF &&
1179 btdh->handle == raid_device->handle) {
1180 btdh->bus = raid_device->channel;
1181 btdh->id = raid_device->id;
1182 rc = 1;
1183 goto out;
1184 } else if (btdh->bus == raid_device->channel && btdh->id ==
1185 raid_device->id && btdh->handle == 0xFFFF) {
1186 btdh->handle = raid_device->handle;
1187 rc = 1;
1188 goto out;
1189 }
1190 }
1191 out:
1192 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1193 return rc;
1194}
1195
1196/**
1197 * _ctl_btdh_mapping - main handler for MPT2BTDHMAPPING opcode
1198 * @arg - user space buffer containing ioctl content
1199 */
1200static long
1201_ctl_btdh_mapping(void __user *arg)
1202{
1203 struct mpt2_ioctl_btdh_mapping karg;
1204 struct MPT2SAS_ADAPTER *ioc;
1205 int rc;
1206
1207 if (copy_from_user(&karg, arg, sizeof(karg))) {
1208 printk(KERN_ERR "failure at %s:%d/%s()!\n",
1209 __FILE__, __LINE__, __func__);
1210 return -EFAULT;
1211 }
1212 if (_ctl_verify_adapter(karg.hdr.ioc_number, &ioc) == -1 || !ioc)
1213 return -ENODEV;
1214
1215 dctlprintk(ioc, printk(MPT2SAS_DEBUG_FMT "%s\n", ioc->name,
1216 __func__));
1217
1218 rc = _ctl_btdh_search_sas_device(ioc, &karg);
1219 if (!rc)
1220 _ctl_btdh_search_raid_device(ioc, &karg);
1221
1222 if (copy_to_user(arg, &karg, sizeof(karg))) {
1223 printk(KERN_ERR "failure at %s:%d/%s()!\n",
1224 __FILE__, __LINE__, __func__);
1225 return -EFAULT;
1226 }
1227 return 0;
1228}
1229
1230/**
1231 * _ctl_diag_capability - return diag buffer capability
1232 * @ioc: per adapter object
1233 * @buffer_type: specifies either TRACE or SNAPSHOT
1234 *
1235 * returns 1 when diag buffer support is enabled in firmware
1236 */
1237static u8
1238_ctl_diag_capability(struct MPT2SAS_ADAPTER *ioc, u8 buffer_type)
1239{
1240 u8 rc = 0;
1241
1242 switch (buffer_type) {
1243 case MPI2_DIAG_BUF_TYPE_TRACE:
1244 if (ioc->facts.IOCCapabilities &
1245 MPI2_IOCFACTS_CAPABILITY_DIAG_TRACE_BUFFER)
1246 rc = 1;
1247 break;
1248 case MPI2_DIAG_BUF_TYPE_SNAPSHOT:
1249 if (ioc->facts.IOCCapabilities &
1250 MPI2_IOCFACTS_CAPABILITY_SNAPSHOT_BUFFER)
1251 rc = 1;
1252 break;
1253 }
1254
1255 return rc;
1256}
1257
1258/**
Kashyap, Desai32e0eb52009-09-23 17:28:09 +05301259 * _ctl_diag_register_2 - wrapper for registering diag buffer support
1260 * @ioc: per adapter object
1261 * @diag_register: the diag_register struct passed in from user space
Eric Moore635374e2009-03-09 01:21:12 -06001262 *
Eric Moore635374e2009-03-09 01:21:12 -06001263 */
1264static long
Kashyap, Desai32e0eb52009-09-23 17:28:09 +05301265_ctl_diag_register_2(struct MPT2SAS_ADAPTER *ioc,
1266 struct mpt2_diag_register *diag_register)
Eric Moore635374e2009-03-09 01:21:12 -06001267{
Eric Moore635374e2009-03-09 01:21:12 -06001268 int rc, i;
1269 void *request_data = NULL;
1270 dma_addr_t request_data_dma;
1271 u32 request_data_sz = 0;
1272 Mpi2DiagBufferPostRequest_t *mpi_request;
1273 Mpi2DiagBufferPostReply_t *mpi_reply;
1274 u8 buffer_type;
1275 unsigned long timeleft;
1276 u16 smid;
1277 u16 ioc_status;
1278 u8 issue_reset = 0;
1279
Eric Moore635374e2009-03-09 01:21:12 -06001280 dctlprintk(ioc, printk(MPT2SAS_DEBUG_FMT "%s\n", ioc->name,
1281 __func__));
1282
Kashyap, Desai32e0eb52009-09-23 17:28:09 +05301283 if (ioc->ctl_cmds.status != MPT2_CMD_NOT_USED) {
1284 printk(MPT2SAS_ERR_FMT "%s: ctl_cmd in use\n",
1285 ioc->name, __func__);
1286 rc = -EAGAIN;
1287 goto out;
1288 }
1289
1290 buffer_type = diag_register->buffer_type;
Eric Moore635374e2009-03-09 01:21:12 -06001291 if (!_ctl_diag_capability(ioc, buffer_type)) {
1292 printk(MPT2SAS_ERR_FMT "%s: doesn't have capability for "
1293 "buffer_type(0x%02x)\n", ioc->name, __func__, buffer_type);
1294 return -EPERM;
1295 }
1296
1297 if (ioc->diag_buffer_status[buffer_type] &
1298 MPT2_DIAG_BUFFER_IS_REGISTERED) {
1299 printk(MPT2SAS_ERR_FMT "%s: already has a registered "
1300 "buffer for buffer_type(0x%02x)\n", ioc->name, __func__,
1301 buffer_type);
1302 return -EINVAL;
1303 }
1304
Kashyap, Desai32e0eb52009-09-23 17:28:09 +05301305 if (diag_register->requested_buffer_size % 4) {
Eric Moore635374e2009-03-09 01:21:12 -06001306 printk(MPT2SAS_ERR_FMT "%s: the requested_buffer_size "
1307 "is not 4 byte aligned\n", ioc->name, __func__);
1308 return -EINVAL;
1309 }
1310
Eric Moore635374e2009-03-09 01:21:12 -06001311 smid = mpt2sas_base_get_smid(ioc, ioc->ctl_cb_idx);
1312 if (!smid) {
1313 printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n",
1314 ioc->name, __func__);
1315 rc = -EAGAIN;
1316 goto out;
1317 }
1318
1319 rc = 0;
1320 ioc->ctl_cmds.status = MPT2_CMD_PENDING;
1321 memset(ioc->ctl_cmds.reply, 0, ioc->reply_sz);
1322 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
1323 ioc->ctl_cmds.smid = smid;
1324
1325 request_data = ioc->diag_buffer[buffer_type];
Kashyap, Desai32e0eb52009-09-23 17:28:09 +05301326 request_data_sz = diag_register->requested_buffer_size;
1327 ioc->unique_id[buffer_type] = diag_register->unique_id;
Eric Moore635374e2009-03-09 01:21:12 -06001328 ioc->diag_buffer_status[buffer_type] = 0;
Kashyap, Desai32e0eb52009-09-23 17:28:09 +05301329 memcpy(ioc->product_specific[buffer_type],
1330 diag_register->product_specific, MPT2_PRODUCT_SPECIFIC_DWORDS);
1331 ioc->diagnostic_flags[buffer_type] = diag_register->diagnostic_flags;
Eric Moore635374e2009-03-09 01:21:12 -06001332
1333 if (request_data) {
1334 request_data_dma = ioc->diag_buffer_dma[buffer_type];
1335 if (request_data_sz != ioc->diag_buffer_sz[buffer_type]) {
1336 pci_free_consistent(ioc->pdev,
1337 ioc->diag_buffer_sz[buffer_type],
1338 request_data, request_data_dma);
1339 request_data = NULL;
1340 }
1341 }
1342
1343 if (request_data == NULL) {
1344 ioc->diag_buffer_sz[buffer_type] = 0;
1345 ioc->diag_buffer_dma[buffer_type] = 0;
1346 request_data = pci_alloc_consistent(
1347 ioc->pdev, request_data_sz, &request_data_dma);
1348 if (request_data == NULL) {
1349 printk(MPT2SAS_ERR_FMT "%s: failed allocating memory"
1350 " for diag buffers, requested size(%d)\n",
1351 ioc->name, __func__, request_data_sz);
1352 mpt2sas_base_free_smid(ioc, smid);
1353 return -ENOMEM;
1354 }
1355 ioc->diag_buffer[buffer_type] = request_data;
1356 ioc->diag_buffer_sz[buffer_type] = request_data_sz;
1357 ioc->diag_buffer_dma[buffer_type] = request_data_dma;
1358 }
1359
1360 mpi_request->Function = MPI2_FUNCTION_DIAG_BUFFER_POST;
Kashyap, Desai32e0eb52009-09-23 17:28:09 +05301361 mpi_request->BufferType = diag_register->buffer_type;
1362 mpi_request->Flags = cpu_to_le32(diag_register->diagnostic_flags);
Eric Moore635374e2009-03-09 01:21:12 -06001363 mpi_request->BufferAddress = cpu_to_le64(request_data_dma);
1364 mpi_request->BufferLength = cpu_to_le32(request_data_sz);
Kashyap, Desai7b936b02009-09-25 11:44:41 +05301365 mpi_request->VF_ID = 0; /* TODO */
1366 mpi_request->VP_ID = 0;
Eric Moore635374e2009-03-09 01:21:12 -06001367
1368 dctlprintk(ioc, printk(MPT2SAS_DEBUG_FMT "%s: diag_buffer(0x%p), "
1369 "dma(0x%llx), sz(%d)\n", ioc->name, __func__, request_data,
1370 (unsigned long long)request_data_dma, mpi_request->BufferLength));
1371
1372 for (i = 0; i < MPT2_PRODUCT_SPECIFIC_DWORDS; i++)
1373 mpi_request->ProductSpecific[i] =
1374 cpu_to_le32(ioc->product_specific[buffer_type][i]);
1375
Kashyap, Desai7b936b02009-09-25 11:44:41 +05301376 mpt2sas_base_put_smid_default(ioc, smid);
Kashyap, Desaibcfb6e62009-09-14 11:05:24 +05301377 init_completion(&ioc->ctl_cmds.done);
Eric Moore635374e2009-03-09 01:21:12 -06001378 timeleft = wait_for_completion_timeout(&ioc->ctl_cmds.done,
1379 MPT2_IOCTL_DEFAULT_TIMEOUT*HZ);
1380
1381 if (!(ioc->ctl_cmds.status & MPT2_CMD_COMPLETE)) {
1382 printk(MPT2SAS_ERR_FMT "%s: timeout\n", ioc->name,
1383 __func__);
1384 _debug_dump_mf(mpi_request,
1385 sizeof(Mpi2DiagBufferPostRequest_t)/4);
1386 if (!(ioc->ctl_cmds.status & MPT2_CMD_RESET))
1387 issue_reset = 1;
1388 goto issue_host_reset;
1389 }
1390
1391 /* process the completed Reply Message Frame */
1392 if ((ioc->ctl_cmds.status & MPT2_CMD_REPLY_VALID) == 0) {
1393 printk(MPT2SAS_ERR_FMT "%s: no reply message\n",
1394 ioc->name, __func__);
1395 rc = -EFAULT;
1396 goto out;
1397 }
1398
1399 mpi_reply = ioc->ctl_cmds.reply;
1400 ioc_status = le16_to_cpu(mpi_reply->IOCStatus) & MPI2_IOCSTATUS_MASK;
1401
1402 if (ioc_status == MPI2_IOCSTATUS_SUCCESS) {
1403 ioc->diag_buffer_status[buffer_type] |=
1404 MPT2_DIAG_BUFFER_IS_REGISTERED;
1405 dctlprintk(ioc, printk(MPT2SAS_DEBUG_FMT "%s: success\n",
1406 ioc->name, __func__));
1407 } else {
1408 printk(MPT2SAS_DEBUG_FMT "%s: ioc_status(0x%04x) "
1409 "log_info(0x%08x)\n", ioc->name, __func__,
1410 ioc_status, mpi_reply->IOCLogInfo);
1411 rc = -EFAULT;
1412 }
1413
1414 issue_host_reset:
1415 if (issue_reset)
1416 mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP,
1417 FORCE_BIG_HAMMER);
1418
1419 out:
1420
1421 if (rc && request_data)
1422 pci_free_consistent(ioc->pdev, request_data_sz,
1423 request_data, request_data_dma);
1424
1425 ioc->ctl_cmds.status = MPT2_CMD_NOT_USED;
Kashyap, Desai32e0eb52009-09-23 17:28:09 +05301426 return rc;
1427}
1428
1429/**
1430 * mpt2sas_enable_diag_buffer - enabling diag_buffers support driver load time
1431 * @ioc: per adapter object
1432 * @bits_to_register: bitwise field where trace is bit 0, and snapshot is bit 1
1433 *
1434 * This is called when command line option diag_buffer_enable is enabled
1435 * at driver load time.
1436 */
1437void
1438mpt2sas_enable_diag_buffer(struct MPT2SAS_ADAPTER *ioc, u8 bits_to_register)
1439{
1440 struct mpt2_diag_register diag_register;
1441
1442 memset(&diag_register, 0, sizeof(struct mpt2_diag_register));
1443
1444 if (bits_to_register & 1) {
1445 printk(MPT2SAS_INFO_FMT "registering trace buffer support\n",
1446 ioc->name);
1447 diag_register.buffer_type = MPI2_DIAG_BUF_TYPE_TRACE;
1448 /* register for 1MB buffers */
1449 diag_register.requested_buffer_size = (1024 * 1024);
1450 diag_register.unique_id = 0x7075900;
1451 _ctl_diag_register_2(ioc, &diag_register);
1452 }
1453
1454 if (bits_to_register & 2) {
1455 printk(MPT2SAS_INFO_FMT "registering snapshot buffer support\n",
1456 ioc->name);
1457 diag_register.buffer_type = MPI2_DIAG_BUF_TYPE_SNAPSHOT;
1458 /* register for 2MB buffers */
1459 diag_register.requested_buffer_size = 2 * (1024 * 1024);
1460 diag_register.unique_id = 0x7075901;
1461 _ctl_diag_register_2(ioc, &diag_register);
1462 }
1463}
1464
1465/**
1466 * _ctl_diag_register - application register with driver
1467 * @arg - user space buffer containing ioctl content
1468 * @state - NON_BLOCKING or BLOCKING
1469 *
1470 * This will allow the driver to setup any required buffers that will be
1471 * needed by firmware to communicate with the driver.
1472 */
1473static long
1474_ctl_diag_register(void __user *arg, enum block_state state)
1475{
1476 struct mpt2_diag_register karg;
1477 struct MPT2SAS_ADAPTER *ioc;
1478 long rc;
1479
1480 if (copy_from_user(&karg, arg, sizeof(karg))) {
1481 printk(KERN_ERR "failure at %s:%d/%s()!\n",
1482 __FILE__, __LINE__, __func__);
1483 return -EFAULT;
1484 }
1485 if (_ctl_verify_adapter(karg.hdr.ioc_number, &ioc) == -1 || !ioc)
1486 return -ENODEV;
1487
1488 if (state == NON_BLOCKING && !mutex_trylock(&ioc->ctl_cmds.mutex))
1489 return -EAGAIN;
1490 else if (mutex_lock_interruptible(&ioc->ctl_cmds.mutex))
1491 return -ERESTARTSYS;
1492 rc = _ctl_diag_register_2(ioc, &karg);
Eric Moore635374e2009-03-09 01:21:12 -06001493 mutex_unlock(&ioc->ctl_cmds.mutex);
1494 return rc;
1495}
1496
1497/**
1498 * _ctl_diag_unregister - application unregister with driver
1499 * @arg - user space buffer containing ioctl content
1500 *
1501 * This will allow the driver to cleanup any memory allocated for diag
1502 * messages and to free up any resources.
1503 */
1504static long
1505_ctl_diag_unregister(void __user *arg)
1506{
1507 struct mpt2_diag_unregister karg;
1508 struct MPT2SAS_ADAPTER *ioc;
1509 void *request_data;
1510 dma_addr_t request_data_dma;
1511 u32 request_data_sz;
1512 u8 buffer_type;
1513
1514 if (copy_from_user(&karg, arg, sizeof(karg))) {
1515 printk(KERN_ERR "failure at %s:%d/%s()!\n",
1516 __FILE__, __LINE__, __func__);
1517 return -EFAULT;
1518 }
1519 if (_ctl_verify_adapter(karg.hdr.ioc_number, &ioc) == -1 || !ioc)
1520 return -ENODEV;
1521
1522 dctlprintk(ioc, printk(MPT2SAS_DEBUG_FMT "%s\n", ioc->name,
1523 __func__));
1524
1525 buffer_type = karg.unique_id & 0x000000ff;
1526 if (!_ctl_diag_capability(ioc, buffer_type)) {
1527 printk(MPT2SAS_ERR_FMT "%s: doesn't have capability for "
1528 "buffer_type(0x%02x)\n", ioc->name, __func__, buffer_type);
1529 return -EPERM;
1530 }
1531
1532 if ((ioc->diag_buffer_status[buffer_type] &
1533 MPT2_DIAG_BUFFER_IS_REGISTERED) == 0) {
1534 printk(MPT2SAS_ERR_FMT "%s: buffer_type(0x%02x) is not "
1535 "registered\n", ioc->name, __func__, buffer_type);
1536 return -EINVAL;
1537 }
1538 if ((ioc->diag_buffer_status[buffer_type] &
1539 MPT2_DIAG_BUFFER_IS_RELEASED) == 0) {
1540 printk(MPT2SAS_ERR_FMT "%s: buffer_type(0x%02x) has not been "
1541 "released\n", ioc->name, __func__, buffer_type);
1542 return -EINVAL;
1543 }
1544
1545 if (karg.unique_id != ioc->unique_id[buffer_type]) {
1546 printk(MPT2SAS_ERR_FMT "%s: unique_id(0x%08x) is not "
1547 "registered\n", ioc->name, __func__, karg.unique_id);
1548 return -EINVAL;
1549 }
1550
1551 request_data = ioc->diag_buffer[buffer_type];
1552 if (!request_data) {
1553 printk(MPT2SAS_ERR_FMT "%s: doesn't have memory allocated for "
1554 "buffer_type(0x%02x)\n", ioc->name, __func__, buffer_type);
1555 return -ENOMEM;
1556 }
1557
1558 request_data_sz = ioc->diag_buffer_sz[buffer_type];
1559 request_data_dma = ioc->diag_buffer_dma[buffer_type];
1560 pci_free_consistent(ioc->pdev, request_data_sz,
1561 request_data, request_data_dma);
1562 ioc->diag_buffer[buffer_type] = NULL;
1563 ioc->diag_buffer_status[buffer_type] = 0;
1564 return 0;
1565}
1566
1567/**
1568 * _ctl_diag_query - query relevant info associated with diag buffers
1569 * @arg - user space buffer containing ioctl content
1570 *
1571 * The application will send only buffer_type and unique_id. Driver will
1572 * inspect unique_id first, if valid, fill in all the info. If unique_id is
1573 * 0x00, the driver will return info specified by Buffer Type.
1574 */
1575static long
1576_ctl_diag_query(void __user *arg)
1577{
1578 struct mpt2_diag_query karg;
1579 struct MPT2SAS_ADAPTER *ioc;
1580 void *request_data;
1581 int i;
1582 u8 buffer_type;
1583
1584 if (copy_from_user(&karg, arg, sizeof(karg))) {
1585 printk(KERN_ERR "failure at %s:%d/%s()!\n",
1586 __FILE__, __LINE__, __func__);
1587 return -EFAULT;
1588 }
1589 if (_ctl_verify_adapter(karg.hdr.ioc_number, &ioc) == -1 || !ioc)
1590 return -ENODEV;
1591
1592 dctlprintk(ioc, printk(MPT2SAS_DEBUG_FMT "%s\n", ioc->name,
1593 __func__));
1594
1595 karg.application_flags = 0;
1596 buffer_type = karg.buffer_type;
1597
1598 if (!_ctl_diag_capability(ioc, buffer_type)) {
1599 printk(MPT2SAS_ERR_FMT "%s: doesn't have capability for "
1600 "buffer_type(0x%02x)\n", ioc->name, __func__, buffer_type);
1601 return -EPERM;
1602 }
1603
1604 if ((ioc->diag_buffer_status[buffer_type] &
1605 MPT2_DIAG_BUFFER_IS_REGISTERED) == 0) {
1606 printk(MPT2SAS_ERR_FMT "%s: buffer_type(0x%02x) is not "
1607 "registered\n", ioc->name, __func__, buffer_type);
1608 return -EINVAL;
1609 }
1610
1611 if (karg.unique_id & 0xffffff00) {
1612 if (karg.unique_id != ioc->unique_id[buffer_type]) {
1613 printk(MPT2SAS_ERR_FMT "%s: unique_id(0x%08x) is not "
1614 "registered\n", ioc->name, __func__,
1615 karg.unique_id);
1616 return -EINVAL;
1617 }
1618 }
1619
1620 request_data = ioc->diag_buffer[buffer_type];
1621 if (!request_data) {
1622 printk(MPT2SAS_ERR_FMT "%s: doesn't have buffer for "
1623 "buffer_type(0x%02x)\n", ioc->name, __func__, buffer_type);
1624 return -ENOMEM;
1625 }
1626
1627 if (ioc->diag_buffer_status[buffer_type] & MPT2_DIAG_BUFFER_IS_RELEASED)
1628 karg.application_flags = (MPT2_APP_FLAGS_APP_OWNED |
1629 MPT2_APP_FLAGS_BUFFER_VALID);
1630 else
1631 karg.application_flags = (MPT2_APP_FLAGS_APP_OWNED |
1632 MPT2_APP_FLAGS_BUFFER_VALID |
1633 MPT2_APP_FLAGS_FW_BUFFER_ACCESS);
1634
1635 for (i = 0; i < MPT2_PRODUCT_SPECIFIC_DWORDS; i++)
1636 karg.product_specific[i] =
1637 ioc->product_specific[buffer_type][i];
1638
1639 karg.total_buffer_size = ioc->diag_buffer_sz[buffer_type];
1640 karg.driver_added_buffer_size = 0;
1641 karg.unique_id = ioc->unique_id[buffer_type];
1642 karg.diagnostic_flags = ioc->diagnostic_flags[buffer_type];
1643
1644 if (copy_to_user(arg, &karg, sizeof(struct mpt2_diag_query))) {
1645 printk(MPT2SAS_ERR_FMT "%s: unable to write mpt2_diag_query "
1646 "data @ %p\n", ioc->name, __func__, arg);
1647 return -EFAULT;
1648 }
1649 return 0;
1650}
1651
1652/**
Eric Moore99bb2142009-04-21 15:42:13 -06001653 * _ctl_send_release - Diag Release Message
1654 * @ioc: per adapter object
1655 * @buffer_type - specifies either TRACE or SNAPSHOT
1656 * @issue_reset - specifies whether host reset is required.
1657 *
1658 */
1659static int
1660_ctl_send_release(struct MPT2SAS_ADAPTER *ioc, u8 buffer_type, u8 *issue_reset)
1661{
1662 Mpi2DiagReleaseRequest_t *mpi_request;
1663 Mpi2DiagReleaseReply_t *mpi_reply;
1664 u16 smid;
1665 u16 ioc_status;
1666 u32 ioc_state;
1667 int rc;
1668 unsigned long timeleft;
1669
1670 dctlprintk(ioc, printk(MPT2SAS_DEBUG_FMT "%s\n", ioc->name,
1671 __func__));
1672
1673 rc = 0;
1674 *issue_reset = 0;
1675
1676 ioc_state = mpt2sas_base_get_iocstate(ioc, 1);
1677 if (ioc_state != MPI2_IOC_STATE_OPERATIONAL) {
1678 dctlprintk(ioc, printk(MPT2SAS_DEBUG_FMT "%s: "
1679 "skipping due to FAULT state\n", ioc->name,
1680 __func__));
1681 rc = -EAGAIN;
1682 goto out;
1683 }
1684
1685 if (ioc->ctl_cmds.status != MPT2_CMD_NOT_USED) {
1686 printk(MPT2SAS_ERR_FMT "%s: ctl_cmd in use\n",
1687 ioc->name, __func__);
1688 rc = -EAGAIN;
1689 goto out;
1690 }
1691
1692 smid = mpt2sas_base_get_smid(ioc, ioc->ctl_cb_idx);
1693 if (!smid) {
1694 printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n",
1695 ioc->name, __func__);
1696 rc = -EAGAIN;
1697 goto out;
1698 }
1699
1700 ioc->ctl_cmds.status = MPT2_CMD_PENDING;
1701 memset(ioc->ctl_cmds.reply, 0, ioc->reply_sz);
1702 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
1703 ioc->ctl_cmds.smid = smid;
1704
1705 mpi_request->Function = MPI2_FUNCTION_DIAG_RELEASE;
1706 mpi_request->BufferType = buffer_type;
Kashyap, Desai7b936b02009-09-25 11:44:41 +05301707 mpi_request->VF_ID = 0; /* TODO */
1708 mpi_request->VP_ID = 0;
Eric Moore99bb2142009-04-21 15:42:13 -06001709
Kashyap, Desai7b936b02009-09-25 11:44:41 +05301710 mpt2sas_base_put_smid_default(ioc, smid);
Kashyap, Desaibcfb6e62009-09-14 11:05:24 +05301711 init_completion(&ioc->ctl_cmds.done);
Eric Moore99bb2142009-04-21 15:42:13 -06001712 timeleft = wait_for_completion_timeout(&ioc->ctl_cmds.done,
1713 MPT2_IOCTL_DEFAULT_TIMEOUT*HZ);
1714
1715 if (!(ioc->ctl_cmds.status & MPT2_CMD_COMPLETE)) {
1716 printk(MPT2SAS_ERR_FMT "%s: timeout\n", ioc->name,
1717 __func__);
1718 _debug_dump_mf(mpi_request,
1719 sizeof(Mpi2DiagReleaseRequest_t)/4);
1720 if (!(ioc->ctl_cmds.status & MPT2_CMD_RESET))
1721 *issue_reset = 1;
1722 rc = -EFAULT;
1723 goto out;
1724 }
1725
1726 /* process the completed Reply Message Frame */
1727 if ((ioc->ctl_cmds.status & MPT2_CMD_REPLY_VALID) == 0) {
1728 printk(MPT2SAS_ERR_FMT "%s: no reply message\n",
1729 ioc->name, __func__);
1730 rc = -EFAULT;
1731 goto out;
1732 }
1733
1734 mpi_reply = ioc->ctl_cmds.reply;
1735 ioc_status = le16_to_cpu(mpi_reply->IOCStatus) & MPI2_IOCSTATUS_MASK;
1736
1737 if (ioc_status == MPI2_IOCSTATUS_SUCCESS) {
1738 ioc->diag_buffer_status[buffer_type] |=
1739 MPT2_DIAG_BUFFER_IS_RELEASED;
1740 dctlprintk(ioc, printk(MPT2SAS_DEBUG_FMT "%s: success\n",
1741 ioc->name, __func__));
1742 } else {
1743 printk(MPT2SAS_DEBUG_FMT "%s: ioc_status(0x%04x) "
1744 "log_info(0x%08x)\n", ioc->name, __func__,
1745 ioc_status, mpi_reply->IOCLogInfo);
1746 rc = -EFAULT;
1747 }
1748
1749 out:
1750 ioc->ctl_cmds.status = MPT2_CMD_NOT_USED;
1751 return rc;
1752}
1753
1754/**
Eric Moore635374e2009-03-09 01:21:12 -06001755 * _ctl_diag_release - request to send Diag Release Message to firmware
1756 * @arg - user space buffer containing ioctl content
1757 * @state - NON_BLOCKING or BLOCKING
1758 *
1759 * This allows ownership of the specified buffer to returned to the driver,
1760 * allowing an application to read the buffer without fear that firmware is
1761 * overwritting information in the buffer.
1762 */
1763static long
1764_ctl_diag_release(void __user *arg, enum block_state state)
1765{
1766 struct mpt2_diag_release karg;
1767 struct MPT2SAS_ADAPTER *ioc;
1768 void *request_data;
1769 int rc;
Eric Moore635374e2009-03-09 01:21:12 -06001770 u8 buffer_type;
Eric Moore635374e2009-03-09 01:21:12 -06001771 u8 issue_reset = 0;
1772
1773 if (copy_from_user(&karg, arg, sizeof(karg))) {
1774 printk(KERN_ERR "failure at %s:%d/%s()!\n",
1775 __FILE__, __LINE__, __func__);
1776 return -EFAULT;
1777 }
1778 if (_ctl_verify_adapter(karg.hdr.ioc_number, &ioc) == -1 || !ioc)
1779 return -ENODEV;
1780
1781 dctlprintk(ioc, printk(MPT2SAS_DEBUG_FMT "%s\n", ioc->name,
1782 __func__));
1783
1784 buffer_type = karg.unique_id & 0x000000ff;
1785 if (!_ctl_diag_capability(ioc, buffer_type)) {
1786 printk(MPT2SAS_ERR_FMT "%s: doesn't have capability for "
1787 "buffer_type(0x%02x)\n", ioc->name, __func__, buffer_type);
1788 return -EPERM;
1789 }
1790
1791 if ((ioc->diag_buffer_status[buffer_type] &
1792 MPT2_DIAG_BUFFER_IS_REGISTERED) == 0) {
1793 printk(MPT2SAS_ERR_FMT "%s: buffer_type(0x%02x) is not "
1794 "registered\n", ioc->name, __func__, buffer_type);
1795 return -EINVAL;
1796 }
1797
1798 if (karg.unique_id != ioc->unique_id[buffer_type]) {
1799 printk(MPT2SAS_ERR_FMT "%s: unique_id(0x%08x) is not "
1800 "registered\n", ioc->name, __func__, karg.unique_id);
1801 return -EINVAL;
1802 }
1803
1804 if (ioc->diag_buffer_status[buffer_type] &
1805 MPT2_DIAG_BUFFER_IS_RELEASED) {
1806 printk(MPT2SAS_ERR_FMT "%s: buffer_type(0x%02x) "
1807 "is already released\n", ioc->name, __func__,
1808 buffer_type);
1809 return 0;
1810 }
1811
1812 request_data = ioc->diag_buffer[buffer_type];
1813
1814 if (!request_data) {
1815 printk(MPT2SAS_ERR_FMT "%s: doesn't have memory allocated for "
1816 "buffer_type(0x%02x)\n", ioc->name, __func__, buffer_type);
1817 return -ENOMEM;
1818 }
1819
Eric Moore99bb2142009-04-21 15:42:13 -06001820 /* buffers were released by due to host reset */
1821 if ((ioc->diag_buffer_status[buffer_type] &
1822 MPT2_DIAG_BUFFER_IS_DIAG_RESET)) {
1823 ioc->diag_buffer_status[buffer_type] |=
1824 MPT2_DIAG_BUFFER_IS_RELEASED;
1825 ioc->diag_buffer_status[buffer_type] &=
1826 ~MPT2_DIAG_BUFFER_IS_DIAG_RESET;
1827 printk(MPT2SAS_ERR_FMT "%s: buffer_type(0x%02x) "
1828 "was released due to host reset\n", ioc->name, __func__,
1829 buffer_type);
1830 return 0;
1831 }
1832
Eric Moore635374e2009-03-09 01:21:12 -06001833 if (state == NON_BLOCKING && !mutex_trylock(&ioc->ctl_cmds.mutex))
1834 return -EAGAIN;
1835 else if (mutex_lock_interruptible(&ioc->ctl_cmds.mutex))
1836 return -ERESTARTSYS;
1837
Eric Moore99bb2142009-04-21 15:42:13 -06001838 rc = _ctl_send_release(ioc, buffer_type, &issue_reset);
Eric Moore635374e2009-03-09 01:21:12 -06001839
Eric Moore635374e2009-03-09 01:21:12 -06001840 if (issue_reset)
1841 mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP,
1842 FORCE_BIG_HAMMER);
1843
Eric Moore635374e2009-03-09 01:21:12 -06001844 mutex_unlock(&ioc->ctl_cmds.mutex);
1845 return rc;
1846}
1847
1848/**
1849 * _ctl_diag_read_buffer - request for copy of the diag buffer
1850 * @arg - user space buffer containing ioctl content
1851 * @state - NON_BLOCKING or BLOCKING
1852 */
1853static long
1854_ctl_diag_read_buffer(void __user *arg, enum block_state state)
1855{
1856 struct mpt2_diag_read_buffer karg;
1857 struct mpt2_diag_read_buffer __user *uarg = arg;
1858 struct MPT2SAS_ADAPTER *ioc;
1859 void *request_data, *diag_data;
1860 Mpi2DiagBufferPostRequest_t *mpi_request;
1861 Mpi2DiagBufferPostReply_t *mpi_reply;
1862 int rc, i;
1863 u8 buffer_type;
1864 unsigned long timeleft;
1865 u16 smid;
1866 u16 ioc_status;
1867 u8 issue_reset = 0;
1868
1869 if (copy_from_user(&karg, arg, sizeof(karg))) {
1870 printk(KERN_ERR "failure at %s:%d/%s()!\n",
1871 __FILE__, __LINE__, __func__);
1872 return -EFAULT;
1873 }
1874 if (_ctl_verify_adapter(karg.hdr.ioc_number, &ioc) == -1 || !ioc)
1875 return -ENODEV;
1876
1877 dctlprintk(ioc, printk(MPT2SAS_DEBUG_FMT "%s\n", ioc->name,
1878 __func__));
1879
1880 buffer_type = karg.unique_id & 0x000000ff;
1881 if (!_ctl_diag_capability(ioc, buffer_type)) {
1882 printk(MPT2SAS_ERR_FMT "%s: doesn't have capability for "
1883 "buffer_type(0x%02x)\n", ioc->name, __func__, buffer_type);
1884 return -EPERM;
1885 }
1886
1887 if (karg.unique_id != ioc->unique_id[buffer_type]) {
1888 printk(MPT2SAS_ERR_FMT "%s: unique_id(0x%08x) is not "
1889 "registered\n", ioc->name, __func__, karg.unique_id);
1890 return -EINVAL;
1891 }
1892
1893 request_data = ioc->diag_buffer[buffer_type];
1894 if (!request_data) {
1895 printk(MPT2SAS_ERR_FMT "%s: doesn't have buffer for "
1896 "buffer_type(0x%02x)\n", ioc->name, __func__, buffer_type);
1897 return -ENOMEM;
1898 }
1899
1900 if ((karg.starting_offset % 4) || (karg.bytes_to_read % 4)) {
1901 printk(MPT2SAS_ERR_FMT "%s: either the starting_offset "
1902 "or bytes_to_read are not 4 byte aligned\n", ioc->name,
1903 __func__);
1904 return -EINVAL;
1905 }
1906
1907 diag_data = (void *)(request_data + karg.starting_offset);
1908 dctlprintk(ioc, printk(MPT2SAS_DEBUG_FMT "%s: diag_buffer(%p), "
1909 "offset(%d), sz(%d)\n", ioc->name, __func__,
1910 diag_data, karg.starting_offset, karg.bytes_to_read));
1911
1912 if (copy_to_user((void __user *)uarg->diagnostic_data,
1913 diag_data, karg.bytes_to_read)) {
1914 printk(MPT2SAS_ERR_FMT "%s: Unable to write "
1915 "mpt_diag_read_buffer_t data @ %p\n", ioc->name,
1916 __func__, diag_data);
1917 return -EFAULT;
1918 }
1919
1920 if ((karg.flags & MPT2_FLAGS_REREGISTER) == 0)
1921 return 0;
1922
1923 dctlprintk(ioc, printk(MPT2SAS_DEBUG_FMT "%s: Reregister "
1924 "buffer_type(0x%02x)\n", ioc->name, __func__, buffer_type));
1925 if ((ioc->diag_buffer_status[buffer_type] &
1926 MPT2_DIAG_BUFFER_IS_RELEASED) == 0) {
1927 dctlprintk(ioc, printk(MPT2SAS_DEBUG_FMT "%s: "
1928 "buffer_type(0x%02x) is still registered\n", ioc->name,
1929 __func__, buffer_type));
1930 return 0;
1931 }
1932 /* Get a free request frame and save the message context.
1933 */
1934 if (state == NON_BLOCKING && !mutex_trylock(&ioc->ctl_cmds.mutex))
1935 return -EAGAIN;
1936 else if (mutex_lock_interruptible(&ioc->ctl_cmds.mutex))
1937 return -ERESTARTSYS;
1938
1939 if (ioc->ctl_cmds.status != MPT2_CMD_NOT_USED) {
1940 printk(MPT2SAS_ERR_FMT "%s: ctl_cmd in use\n",
1941 ioc->name, __func__);
1942 rc = -EAGAIN;
1943 goto out;
1944 }
1945
1946 smid = mpt2sas_base_get_smid(ioc, ioc->ctl_cb_idx);
1947 if (!smid) {
1948 printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n",
1949 ioc->name, __func__);
1950 rc = -EAGAIN;
1951 goto out;
1952 }
1953
1954 rc = 0;
1955 ioc->ctl_cmds.status = MPT2_CMD_PENDING;
1956 memset(ioc->ctl_cmds.reply, 0, ioc->reply_sz);
1957 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
1958 ioc->ctl_cmds.smid = smid;
1959
1960 mpi_request->Function = MPI2_FUNCTION_DIAG_BUFFER_POST;
1961 mpi_request->BufferType = buffer_type;
1962 mpi_request->BufferLength =
1963 cpu_to_le32(ioc->diag_buffer_sz[buffer_type]);
1964 mpi_request->BufferAddress =
1965 cpu_to_le64(ioc->diag_buffer_dma[buffer_type]);
1966 for (i = 0; i < MPT2_PRODUCT_SPECIFIC_DWORDS; i++)
1967 mpi_request->ProductSpecific[i] =
1968 cpu_to_le32(ioc->product_specific[buffer_type][i]);
Kashyap, Desai7b936b02009-09-25 11:44:41 +05301969 mpi_request->VF_ID = 0; /* TODO */
1970 mpi_request->VP_ID = 0;
Eric Moore635374e2009-03-09 01:21:12 -06001971
Kashyap, Desai7b936b02009-09-25 11:44:41 +05301972 mpt2sas_base_put_smid_default(ioc, smid);
Kashyap, Desaibcfb6e62009-09-14 11:05:24 +05301973 init_completion(&ioc->ctl_cmds.done);
Eric Moore635374e2009-03-09 01:21:12 -06001974 timeleft = wait_for_completion_timeout(&ioc->ctl_cmds.done,
1975 MPT2_IOCTL_DEFAULT_TIMEOUT*HZ);
1976
1977 if (!(ioc->ctl_cmds.status & MPT2_CMD_COMPLETE)) {
1978 printk(MPT2SAS_ERR_FMT "%s: timeout\n", ioc->name,
1979 __func__);
1980 _debug_dump_mf(mpi_request,
1981 sizeof(Mpi2DiagBufferPostRequest_t)/4);
1982 if (!(ioc->ctl_cmds.status & MPT2_CMD_RESET))
1983 issue_reset = 1;
1984 goto issue_host_reset;
1985 }
1986
1987 /* process the completed Reply Message Frame */
1988 if ((ioc->ctl_cmds.status & MPT2_CMD_REPLY_VALID) == 0) {
1989 printk(MPT2SAS_ERR_FMT "%s: no reply message\n",
1990 ioc->name, __func__);
1991 rc = -EFAULT;
1992 goto out;
1993 }
1994
1995 mpi_reply = ioc->ctl_cmds.reply;
1996 ioc_status = le16_to_cpu(mpi_reply->IOCStatus) & MPI2_IOCSTATUS_MASK;
1997
1998 if (ioc_status == MPI2_IOCSTATUS_SUCCESS) {
1999 ioc->diag_buffer_status[buffer_type] |=
2000 MPT2_DIAG_BUFFER_IS_REGISTERED;
2001 dctlprintk(ioc, printk(MPT2SAS_DEBUG_FMT "%s: success\n",
2002 ioc->name, __func__));
2003 } else {
2004 printk(MPT2SAS_DEBUG_FMT "%s: ioc_status(0x%04x) "
2005 "log_info(0x%08x)\n", ioc->name, __func__,
2006 ioc_status, mpi_reply->IOCLogInfo);
2007 rc = -EFAULT;
2008 }
2009
2010 issue_host_reset:
2011 if (issue_reset)
2012 mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP,
2013 FORCE_BIG_HAMMER);
2014
2015 out:
2016
2017 ioc->ctl_cmds.status = MPT2_CMD_NOT_USED;
2018 mutex_unlock(&ioc->ctl_cmds.mutex);
2019 return rc;
2020}
2021
2022/**
2023 * _ctl_ioctl_main - main ioctl entry point
2024 * @file - (struct file)
2025 * @cmd - ioctl opcode
2026 * @arg -
2027 */
2028static long
2029_ctl_ioctl_main(struct file *file, unsigned int cmd, void __user *arg)
2030{
2031 enum block_state state;
2032 long ret = -EINVAL;
Eric Moore635374e2009-03-09 01:21:12 -06002033
2034 state = (file->f_flags & O_NONBLOCK) ? NON_BLOCKING :
2035 BLOCKING;
2036
2037 switch (cmd) {
2038 case MPT2IOCINFO:
2039 if (_IOC_SIZE(cmd) == sizeof(struct mpt2_ioctl_iocinfo))
2040 ret = _ctl_getiocinfo(arg);
2041 break;
2042 case MPT2COMMAND:
2043 {
2044 struct mpt2_ioctl_command karg;
2045 struct mpt2_ioctl_command __user *uarg;
2046 struct MPT2SAS_ADAPTER *ioc;
2047
2048 if (copy_from_user(&karg, arg, sizeof(karg))) {
2049 printk(KERN_ERR "failure at %s:%d/%s()!\n",
2050 __FILE__, __LINE__, __func__);
2051 return -EFAULT;
2052 }
2053
2054 if (_ctl_verify_adapter(karg.hdr.ioc_number, &ioc) == -1 ||
2055 !ioc)
2056 return -ENODEV;
2057
Kashyap, Desai155dd4c2009-08-20 13:22:00 +05302058 if (ioc->shost_recovery)
Eric Moore635374e2009-03-09 01:21:12 -06002059 return -EAGAIN;
Eric Moore635374e2009-03-09 01:21:12 -06002060
2061 if (_IOC_SIZE(cmd) == sizeof(struct mpt2_ioctl_command)) {
2062 uarg = arg;
2063 ret = _ctl_do_mpt_command(ioc, karg, &uarg->mf, state);
2064 }
2065 break;
2066 }
2067 case MPT2EVENTQUERY:
2068 if (_IOC_SIZE(cmd) == sizeof(struct mpt2_ioctl_eventquery))
2069 ret = _ctl_eventquery(arg);
2070 break;
2071 case MPT2EVENTENABLE:
2072 if (_IOC_SIZE(cmd) == sizeof(struct mpt2_ioctl_eventenable))
2073 ret = _ctl_eventenable(arg);
2074 break;
2075 case MPT2EVENTREPORT:
2076 ret = _ctl_eventreport(arg);
2077 break;
2078 case MPT2HARDRESET:
2079 if (_IOC_SIZE(cmd) == sizeof(struct mpt2_ioctl_diag_reset))
2080 ret = _ctl_do_reset(arg);
2081 break;
2082 case MPT2BTDHMAPPING:
2083 if (_IOC_SIZE(cmd) == sizeof(struct mpt2_ioctl_btdh_mapping))
2084 ret = _ctl_btdh_mapping(arg);
2085 break;
2086 case MPT2DIAGREGISTER:
2087 if (_IOC_SIZE(cmd) == sizeof(struct mpt2_diag_register))
2088 ret = _ctl_diag_register(arg, state);
2089 break;
2090 case MPT2DIAGUNREGISTER:
2091 if (_IOC_SIZE(cmd) == sizeof(struct mpt2_diag_unregister))
2092 ret = _ctl_diag_unregister(arg);
2093 break;
2094 case MPT2DIAGQUERY:
2095 if (_IOC_SIZE(cmd) == sizeof(struct mpt2_diag_query))
2096 ret = _ctl_diag_query(arg);
2097 break;
2098 case MPT2DIAGRELEASE:
2099 if (_IOC_SIZE(cmd) == sizeof(struct mpt2_diag_release))
2100 ret = _ctl_diag_release(arg, state);
2101 break;
2102 case MPT2DIAGREADBUFFER:
2103 if (_IOC_SIZE(cmd) == sizeof(struct mpt2_diag_read_buffer))
2104 ret = _ctl_diag_read_buffer(arg, state);
2105 break;
2106 default:
2107 {
2108 struct mpt2_ioctl_command karg;
2109 struct MPT2SAS_ADAPTER *ioc;
2110
2111 if (copy_from_user(&karg, arg, sizeof(karg))) {
2112 printk(KERN_ERR "failure at %s:%d/%s()!\n",
2113 __FILE__, __LINE__, __func__);
2114 return -EFAULT;
2115 }
2116
2117 if (_ctl_verify_adapter(karg.hdr.ioc_number, &ioc) == -1 ||
2118 !ioc)
2119 return -ENODEV;
2120
2121 dctlprintk(ioc, printk(MPT2SAS_DEBUG_FMT
2122 "unsupported ioctl opcode(0x%08x)\n", ioc->name, cmd));
2123 break;
2124 }
2125 }
2126 return ret;
2127}
2128
2129/**
2130 * _ctl_ioctl - main ioctl entry point (unlocked)
2131 * @file - (struct file)
2132 * @cmd - ioctl opcode
2133 * @arg -
2134 */
2135static long
2136_ctl_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
2137{
2138 long ret;
Kashyap, Desai7b936b02009-09-25 11:44:41 +05302139
Eric Moore635374e2009-03-09 01:21:12 -06002140 lock_kernel();
2141 ret = _ctl_ioctl_main(file, cmd, (void __user *)arg);
2142 unlock_kernel();
2143 return ret;
2144}
2145
2146#ifdef CONFIG_COMPAT
2147/**
2148 * _ctl_compat_mpt_command - convert 32bit pointers to 64bit.
2149 * @file - (struct file)
2150 * @cmd - ioctl opcode
2151 * @arg - (struct mpt2_ioctl_command32)
2152 *
2153 * MPT2COMMAND32 - Handle 32bit applications running on 64bit os.
2154 */
2155static long
2156_ctl_compat_mpt_command(struct file *file, unsigned cmd, unsigned long arg)
2157{
2158 struct mpt2_ioctl_command32 karg32;
2159 struct mpt2_ioctl_command32 __user *uarg;
2160 struct mpt2_ioctl_command karg;
2161 struct MPT2SAS_ADAPTER *ioc;
2162 enum block_state state;
Eric Moore635374e2009-03-09 01:21:12 -06002163
2164 if (_IOC_SIZE(cmd) != sizeof(struct mpt2_ioctl_command32))
2165 return -EINVAL;
2166
2167 uarg = (struct mpt2_ioctl_command32 __user *) arg;
2168
2169 if (copy_from_user(&karg32, (char __user *)arg, sizeof(karg32))) {
2170 printk(KERN_ERR "failure at %s:%d/%s()!\n",
2171 __FILE__, __LINE__, __func__);
2172 return -EFAULT;
2173 }
2174 if (_ctl_verify_adapter(karg32.hdr.ioc_number, &ioc) == -1 || !ioc)
2175 return -ENODEV;
2176
Kashyap, Desai155dd4c2009-08-20 13:22:00 +05302177 if (ioc->shost_recovery)
Eric Moore635374e2009-03-09 01:21:12 -06002178 return -EAGAIN;
Eric Moore635374e2009-03-09 01:21:12 -06002179
2180 memset(&karg, 0, sizeof(struct mpt2_ioctl_command));
2181 karg.hdr.ioc_number = karg32.hdr.ioc_number;
2182 karg.hdr.port_number = karg32.hdr.port_number;
2183 karg.hdr.max_data_size = karg32.hdr.max_data_size;
2184 karg.timeout = karg32.timeout;
2185 karg.max_reply_bytes = karg32.max_reply_bytes;
2186 karg.data_in_size = karg32.data_in_size;
2187 karg.data_out_size = karg32.data_out_size;
2188 karg.max_sense_bytes = karg32.max_sense_bytes;
2189 karg.data_sge_offset = karg32.data_sge_offset;
2190 memcpy(&karg.reply_frame_buf_ptr, &karg32.reply_frame_buf_ptr,
2191 sizeof(uint32_t));
2192 memcpy(&karg.data_in_buf_ptr, &karg32.data_in_buf_ptr,
2193 sizeof(uint32_t));
2194 memcpy(&karg.data_out_buf_ptr, &karg32.data_out_buf_ptr,
2195 sizeof(uint32_t));
2196 memcpy(&karg.sense_data_ptr, &karg32.sense_data_ptr,
2197 sizeof(uint32_t));
2198 state = (file->f_flags & O_NONBLOCK) ? NON_BLOCKING : BLOCKING;
2199 return _ctl_do_mpt_command(ioc, karg, &uarg->mf, state);
2200}
2201
2202/**
2203 * _ctl_ioctl_compat - main ioctl entry point (compat)
2204 * @file -
2205 * @cmd -
2206 * @arg -
2207 *
2208 * This routine handles 32 bit applications in 64bit os.
2209 */
2210static long
2211_ctl_ioctl_compat(struct file *file, unsigned cmd, unsigned long arg)
2212{
2213 long ret;
Kashyap, Desai7b936b02009-09-25 11:44:41 +05302214
Eric Moore635374e2009-03-09 01:21:12 -06002215 lock_kernel();
2216 if (cmd == MPT2COMMAND32)
2217 ret = _ctl_compat_mpt_command(file, cmd, arg);
2218 else
2219 ret = _ctl_ioctl_main(file, cmd, (void __user *)arg);
2220 unlock_kernel();
2221 return ret;
2222}
2223#endif
2224
2225/* scsi host attributes */
2226
2227/**
2228 * _ctl_version_fw_show - firmware version
2229 * @cdev - pointer to embedded class device
2230 * @buf - the buffer returned
2231 *
2232 * A sysfs 'read-only' shost attribute.
2233 */
2234static ssize_t
2235_ctl_version_fw_show(struct device *cdev, struct device_attribute *attr,
2236 char *buf)
2237{
2238 struct Scsi_Host *shost = class_to_shost(cdev);
2239 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
2240
2241 return snprintf(buf, PAGE_SIZE, "%02d.%02d.%02d.%02d\n",
2242 (ioc->facts.FWVersion.Word & 0xFF000000) >> 24,
2243 (ioc->facts.FWVersion.Word & 0x00FF0000) >> 16,
2244 (ioc->facts.FWVersion.Word & 0x0000FF00) >> 8,
2245 ioc->facts.FWVersion.Word & 0x000000FF);
2246}
2247static DEVICE_ATTR(version_fw, S_IRUGO, _ctl_version_fw_show, NULL);
2248
2249/**
2250 * _ctl_version_bios_show - bios version
2251 * @cdev - pointer to embedded class device
2252 * @buf - the buffer returned
2253 *
2254 * A sysfs 'read-only' shost attribute.
2255 */
2256static ssize_t
2257_ctl_version_bios_show(struct device *cdev, struct device_attribute *attr,
2258 char *buf)
2259{
2260 struct Scsi_Host *shost = class_to_shost(cdev);
2261 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
2262
2263 u32 version = le32_to_cpu(ioc->bios_pg3.BiosVersion);
2264
2265 return snprintf(buf, PAGE_SIZE, "%02d.%02d.%02d.%02d\n",
2266 (version & 0xFF000000) >> 24,
2267 (version & 0x00FF0000) >> 16,
2268 (version & 0x0000FF00) >> 8,
2269 version & 0x000000FF);
2270}
2271static DEVICE_ATTR(version_bios, S_IRUGO, _ctl_version_bios_show, NULL);
2272
2273/**
2274 * _ctl_version_mpi_show - MPI (message passing interface) version
2275 * @cdev - pointer to embedded class device
2276 * @buf - the buffer returned
2277 *
2278 * A sysfs 'read-only' shost attribute.
2279 */
2280static ssize_t
2281_ctl_version_mpi_show(struct device *cdev, struct device_attribute *attr,
2282 char *buf)
2283{
2284 struct Scsi_Host *shost = class_to_shost(cdev);
2285 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
2286
2287 return snprintf(buf, PAGE_SIZE, "%03x.%02x\n",
2288 ioc->facts.MsgVersion, ioc->facts.HeaderVersion >> 8);
2289}
2290static DEVICE_ATTR(version_mpi, S_IRUGO, _ctl_version_mpi_show, NULL);
2291
2292/**
2293 * _ctl_version_product_show - product name
2294 * @cdev - pointer to embedded class device
2295 * @buf - the buffer returned
2296 *
2297 * A sysfs 'read-only' shost attribute.
2298 */
2299static ssize_t
2300_ctl_version_product_show(struct device *cdev, struct device_attribute *attr,
2301 char *buf)
2302{
2303 struct Scsi_Host *shost = class_to_shost(cdev);
2304 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
2305
2306 return snprintf(buf, 16, "%s\n", ioc->manu_pg0.ChipName);
2307}
2308static DEVICE_ATTR(version_product, S_IRUGO,
2309 _ctl_version_product_show, NULL);
2310
2311/**
2312 * _ctl_version_nvdata_persistent_show - ndvata persistent version
2313 * @cdev - pointer to embedded class device
2314 * @buf - the buffer returned
2315 *
2316 * A sysfs 'read-only' shost attribute.
2317 */
2318static ssize_t
2319_ctl_version_nvdata_persistent_show(struct device *cdev,
2320 struct device_attribute *attr, char *buf)
2321{
2322 struct Scsi_Host *shost = class_to_shost(cdev);
2323 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
2324
2325 return snprintf(buf, PAGE_SIZE, "%02xh\n",
2326 le16_to_cpu(ioc->iounit_pg0.NvdataVersionPersistent.Word));
2327}
2328static DEVICE_ATTR(version_nvdata_persistent, S_IRUGO,
2329 _ctl_version_nvdata_persistent_show, NULL);
2330
2331/**
2332 * _ctl_version_nvdata_default_show - nvdata default version
2333 * @cdev - pointer to embedded class device
2334 * @buf - the buffer returned
2335 *
2336 * A sysfs 'read-only' shost attribute.
2337 */
2338static ssize_t
2339_ctl_version_nvdata_default_show(struct device *cdev,
2340 struct device_attribute *attr, char *buf)
2341{
2342 struct Scsi_Host *shost = class_to_shost(cdev);
2343 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
2344
2345 return snprintf(buf, PAGE_SIZE, "%02xh\n",
2346 le16_to_cpu(ioc->iounit_pg0.NvdataVersionDefault.Word));
2347}
2348static DEVICE_ATTR(version_nvdata_default, S_IRUGO,
2349 _ctl_version_nvdata_default_show, NULL);
2350
2351/**
2352 * _ctl_board_name_show - board name
2353 * @cdev - pointer to embedded class device
2354 * @buf - the buffer returned
2355 *
2356 * A sysfs 'read-only' shost attribute.
2357 */
2358static ssize_t
2359_ctl_board_name_show(struct device *cdev, struct device_attribute *attr,
2360 char *buf)
2361{
2362 struct Scsi_Host *shost = class_to_shost(cdev);
2363 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
2364
2365 return snprintf(buf, 16, "%s\n", ioc->manu_pg0.BoardName);
2366}
2367static DEVICE_ATTR(board_name, S_IRUGO, _ctl_board_name_show, NULL);
2368
2369/**
2370 * _ctl_board_assembly_show - board assembly name
2371 * @cdev - pointer to embedded class device
2372 * @buf - the buffer returned
2373 *
2374 * A sysfs 'read-only' shost attribute.
2375 */
2376static ssize_t
2377_ctl_board_assembly_show(struct device *cdev, struct device_attribute *attr,
2378 char *buf)
2379{
2380 struct Scsi_Host *shost = class_to_shost(cdev);
2381 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
2382
2383 return snprintf(buf, 16, "%s\n", ioc->manu_pg0.BoardAssembly);
2384}
2385static DEVICE_ATTR(board_assembly, S_IRUGO,
2386 _ctl_board_assembly_show, NULL);
2387
2388/**
2389 * _ctl_board_tracer_show - board tracer number
2390 * @cdev - pointer to embedded class device
2391 * @buf - the buffer returned
2392 *
2393 * A sysfs 'read-only' shost attribute.
2394 */
2395static ssize_t
2396_ctl_board_tracer_show(struct device *cdev, struct device_attribute *attr,
2397 char *buf)
2398{
2399 struct Scsi_Host *shost = class_to_shost(cdev);
2400 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
2401
2402 return snprintf(buf, 16, "%s\n", ioc->manu_pg0.BoardTracerNumber);
2403}
2404static DEVICE_ATTR(board_tracer, S_IRUGO,
2405 _ctl_board_tracer_show, NULL);
2406
2407/**
2408 * _ctl_io_delay_show - io missing delay
2409 * @cdev - pointer to embedded class device
2410 * @buf - the buffer returned
2411 *
2412 * This is for firmware implemention for deboucing device
2413 * removal events.
2414 *
2415 * A sysfs 'read-only' shost attribute.
2416 */
2417static ssize_t
2418_ctl_io_delay_show(struct device *cdev, struct device_attribute *attr,
2419 char *buf)
2420{
2421 struct Scsi_Host *shost = class_to_shost(cdev);
2422 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
2423
2424 return snprintf(buf, PAGE_SIZE, "%02d\n", ioc->io_missing_delay);
2425}
2426static DEVICE_ATTR(io_delay, S_IRUGO,
2427 _ctl_io_delay_show, NULL);
2428
2429/**
2430 * _ctl_device_delay_show - device missing delay
2431 * @cdev - pointer to embedded class device
2432 * @buf - the buffer returned
2433 *
2434 * This is for firmware implemention for deboucing device
2435 * removal events.
2436 *
2437 * A sysfs 'read-only' shost attribute.
2438 */
2439static ssize_t
2440_ctl_device_delay_show(struct device *cdev, struct device_attribute *attr,
2441 char *buf)
2442{
2443 struct Scsi_Host *shost = class_to_shost(cdev);
2444 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
2445
2446 return snprintf(buf, PAGE_SIZE, "%02d\n", ioc->device_missing_delay);
2447}
2448static DEVICE_ATTR(device_delay, S_IRUGO,
2449 _ctl_device_delay_show, NULL);
2450
2451/**
2452 * _ctl_fw_queue_depth_show - global credits
2453 * @cdev - pointer to embedded class device
2454 * @buf - the buffer returned
2455 *
2456 * This is firmware queue depth limit
2457 *
2458 * A sysfs 'read-only' shost attribute.
2459 */
2460static ssize_t
2461_ctl_fw_queue_depth_show(struct device *cdev, struct device_attribute *attr,
2462 char *buf)
2463{
2464 struct Scsi_Host *shost = class_to_shost(cdev);
2465 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
2466
2467 return snprintf(buf, PAGE_SIZE, "%02d\n", ioc->facts.RequestCredit);
2468}
2469static DEVICE_ATTR(fw_queue_depth, S_IRUGO,
2470 _ctl_fw_queue_depth_show, NULL);
2471
2472/**
2473 * _ctl_sas_address_show - sas address
2474 * @cdev - pointer to embedded class device
2475 * @buf - the buffer returned
2476 *
2477 * This is the controller sas address
2478 *
2479 * A sysfs 'read-only' shost attribute.
2480 */
2481static ssize_t
2482_ctl_host_sas_address_show(struct device *cdev, struct device_attribute *attr,
2483 char *buf)
2484{
2485 struct Scsi_Host *shost = class_to_shost(cdev);
2486 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
2487
2488 return snprintf(buf, PAGE_SIZE, "0x%016llx\n",
2489 (unsigned long long)ioc->sas_hba.sas_address);
2490}
2491static DEVICE_ATTR(host_sas_address, S_IRUGO,
2492 _ctl_host_sas_address_show, NULL);
2493
2494/**
2495 * _ctl_logging_level_show - logging level
2496 * @cdev - pointer to embedded class device
2497 * @buf - the buffer returned
2498 *
2499 * A sysfs 'read/write' shost attribute.
2500 */
2501static ssize_t
2502_ctl_logging_level_show(struct device *cdev, struct device_attribute *attr,
2503 char *buf)
2504{
2505 struct Scsi_Host *shost = class_to_shost(cdev);
2506 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
2507
2508 return snprintf(buf, PAGE_SIZE, "%08xh\n", ioc->logging_level);
2509}
2510static ssize_t
2511_ctl_logging_level_store(struct device *cdev, struct device_attribute *attr,
2512 const char *buf, size_t count)
2513{
2514 struct Scsi_Host *shost = class_to_shost(cdev);
2515 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
2516 int val = 0;
2517
2518 if (sscanf(buf, "%x", &val) != 1)
2519 return -EINVAL;
2520
2521 ioc->logging_level = val;
2522 printk(MPT2SAS_INFO_FMT "logging_level=%08xh\n", ioc->name,
2523 ioc->logging_level);
2524 return strlen(buf);
2525}
2526static DEVICE_ATTR(logging_level, S_IRUGO | S_IWUSR,
2527 _ctl_logging_level_show, _ctl_logging_level_store);
2528
Kashyap, Desaifa7f3162009-09-23 17:26:58 +05302529/* device attributes */
2530/*
2531 * _ctl_fwfault_debug_show - show/store fwfault_debug
2532 * @cdev - pointer to embedded class device
2533 * @buf - the buffer returned
2534 *
2535 * mpt2sas_fwfault_debug is command line option
2536 * A sysfs 'read/write' shost attribute.
2537 */
2538static ssize_t
2539_ctl_fwfault_debug_show(struct device *cdev,
2540 struct device_attribute *attr, char *buf)
2541{
2542 struct Scsi_Host *shost = class_to_shost(cdev);
2543 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
2544
2545 return snprintf(buf, PAGE_SIZE, "%d\n", ioc->fwfault_debug);
2546}
2547static ssize_t
2548_ctl_fwfault_debug_store(struct device *cdev,
2549 struct device_attribute *attr, const char *buf, size_t count)
2550{
2551 struct Scsi_Host *shost = class_to_shost(cdev);
2552 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
2553 int val = 0;
2554
2555 if (sscanf(buf, "%d", &val) != 1)
2556 return -EINVAL;
2557
2558 ioc->fwfault_debug = val;
2559 printk(MPT2SAS_INFO_FMT "fwfault_debug=%d\n", ioc->name,
2560 ioc->fwfault_debug);
2561 return strlen(buf);
2562}
2563static DEVICE_ATTR(fwfault_debug, S_IRUGO | S_IWUSR,
2564 _ctl_fwfault_debug_show, _ctl_fwfault_debug_store);
2565
Eric Moore635374e2009-03-09 01:21:12 -06002566struct device_attribute *mpt2sas_host_attrs[] = {
2567 &dev_attr_version_fw,
2568 &dev_attr_version_bios,
2569 &dev_attr_version_mpi,
2570 &dev_attr_version_product,
2571 &dev_attr_version_nvdata_persistent,
2572 &dev_attr_version_nvdata_default,
2573 &dev_attr_board_name,
2574 &dev_attr_board_assembly,
2575 &dev_attr_board_tracer,
2576 &dev_attr_io_delay,
2577 &dev_attr_device_delay,
2578 &dev_attr_logging_level,
Kashyap, Desaifa7f3162009-09-23 17:26:58 +05302579 &dev_attr_fwfault_debug,
Eric Moore635374e2009-03-09 01:21:12 -06002580 &dev_attr_fw_queue_depth,
2581 &dev_attr_host_sas_address,
2582 NULL,
2583};
2584
Eric Moore635374e2009-03-09 01:21:12 -06002585/**
2586 * _ctl_device_sas_address_show - sas address
2587 * @cdev - pointer to embedded class device
2588 * @buf - the buffer returned
2589 *
2590 * This is the sas address for the target
2591 *
2592 * A sysfs 'read-only' shost attribute.
2593 */
2594static ssize_t
2595_ctl_device_sas_address_show(struct device *dev, struct device_attribute *attr,
2596 char *buf)
2597{
2598 struct scsi_device *sdev = to_scsi_device(dev);
2599 struct MPT2SAS_DEVICE *sas_device_priv_data = sdev->hostdata;
2600
2601 return snprintf(buf, PAGE_SIZE, "0x%016llx\n",
2602 (unsigned long long)sas_device_priv_data->sas_target->sas_address);
2603}
2604static DEVICE_ATTR(sas_address, S_IRUGO, _ctl_device_sas_address_show, NULL);
2605
2606/**
2607 * _ctl_device_handle_show - device handle
2608 * @cdev - pointer to embedded class device
2609 * @buf - the buffer returned
2610 *
2611 * This is the firmware assigned device handle
2612 *
2613 * A sysfs 'read-only' shost attribute.
2614 */
2615static ssize_t
2616_ctl_device_handle_show(struct device *dev, struct device_attribute *attr,
2617 char *buf)
2618{
2619 struct scsi_device *sdev = to_scsi_device(dev);
2620 struct MPT2SAS_DEVICE *sas_device_priv_data = sdev->hostdata;
2621
2622 return snprintf(buf, PAGE_SIZE, "0x%04x\n",
2623 sas_device_priv_data->sas_target->handle);
2624}
2625static DEVICE_ATTR(sas_device_handle, S_IRUGO, _ctl_device_handle_show, NULL);
2626
2627struct device_attribute *mpt2sas_dev_attrs[] = {
2628 &dev_attr_sas_address,
2629 &dev_attr_sas_device_handle,
2630 NULL,
2631};
2632
2633static const struct file_operations ctl_fops = {
2634 .owner = THIS_MODULE,
2635 .unlocked_ioctl = _ctl_ioctl,
2636 .release = _ctl_release,
2637 .poll = _ctl_poll,
2638 .fasync = _ctl_fasync,
2639#ifdef CONFIG_COMPAT
2640 .compat_ioctl = _ctl_ioctl_compat,
2641#endif
2642};
2643
2644static struct miscdevice ctl_dev = {
2645 .minor = MPT2SAS_MINOR,
2646 .name = MPT2SAS_DEV_NAME,
2647 .fops = &ctl_fops,
2648};
2649
2650/**
2651 * mpt2sas_ctl_init - main entry point for ctl.
2652 *
2653 */
2654void
2655mpt2sas_ctl_init(void)
2656{
2657 async_queue = NULL;
2658 if (misc_register(&ctl_dev) < 0)
2659 printk(KERN_ERR "%s can't register misc device [minor=%d]\n",
2660 MPT2SAS_DRIVER_NAME, MPT2SAS_MINOR);
2661
2662 init_waitqueue_head(&ctl_poll_wait);
2663}
2664
2665/**
2666 * mpt2sas_ctl_exit - exit point for ctl
2667 *
2668 */
2669void
2670mpt2sas_ctl_exit(void)
2671{
2672 struct MPT2SAS_ADAPTER *ioc;
2673 int i;
2674
Eric Mooreba33fad2009-03-15 21:37:18 -06002675 list_for_each_entry(ioc, &mpt2sas_ioc_list, list) {
Eric Moore635374e2009-03-09 01:21:12 -06002676
2677 /* free memory associated to diag buffers */
2678 for (i = 0; i < MPI2_DIAG_BUF_TYPE_COUNT; i++) {
2679 if (!ioc->diag_buffer[i])
2680 continue;
2681 pci_free_consistent(ioc->pdev, ioc->diag_buffer_sz[i],
2682 ioc->diag_buffer[i], ioc->diag_buffer_dma[i]);
2683 ioc->diag_buffer[i] = NULL;
2684 ioc->diag_buffer_status[i] = 0;
2685 }
2686
2687 kfree(ioc->event_log);
2688 }
2689 misc_deregister(&ctl_dev);
2690}
2691