blob: 2661e4fe935dc1635e445286691d7fb20371c283 [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, Desai31b7f2e2010-03-17 16:28:04 +05306 * Copyright (C) 2007-2010 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>
Arnd Bergmannc45d15d2010-06-02 14:28:52 +020054#include <linux/mutex.h>
Eric Moore635374e2009-03-09 01:21:12 -060055#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
Arnd Bergmannc45d15d2010-06-02 14:28:52 +020064static DEFINE_MUTEX(_ctl_mutex);
Eric Moore635374e2009-03-09 01:21:12 -060065static struct fasync_struct *async_queue;
66static DECLARE_WAIT_QUEUE_HEAD(ctl_poll_wait);
67
Eric Moore99bb2142009-04-21 15:42:13 -060068static int _ctl_send_release(struct MPT2SAS_ADAPTER *ioc, u8 buffer_type,
69 u8 *issue_reset);
70
Eric Moore635374e2009-03-09 01:21:12 -060071/**
72 * enum block_state - blocking state
73 * @NON_BLOCKING: non blocking
74 * @BLOCKING: blocking
75 *
76 * These states are for ioctls that need to wait for a response
77 * from firmware, so they probably require sleep.
78 */
79enum block_state {
80 NON_BLOCKING,
81 BLOCKING,
82};
83
Kashyap, Desai363fa502010-11-13 04:29:20 +053084#ifdef CONFIG_SCSI_MPT2SAS_LOGGING
Kashyap, Desai7fbae672010-06-17 13:45:17 +053085/**
86 * _ctl_sas_device_find_by_handle - sas device search
87 * @ioc: per adapter object
88 * @handle: sas device handle (assigned by firmware)
89 * Context: Calling function should acquire ioc->sas_device_lock
90 *
91 * This searches for sas_device based on sas_address, then return sas_device
92 * object.
93 */
94static struct _sas_device *
95_ctl_sas_device_find_by_handle(struct MPT2SAS_ADAPTER *ioc, u16 handle)
96{
97 struct _sas_device *sas_device, *r;
98
99 r = NULL;
100 list_for_each_entry(sas_device, &ioc->sas_device_list, list) {
101 if (sas_device->handle != handle)
102 continue;
103 r = sas_device;
104 goto out;
105 }
106
107 out:
108 return r;
109}
110
Eric Moore635374e2009-03-09 01:21:12 -0600111/**
112 * _ctl_display_some_debug - debug routine
113 * @ioc: per adapter object
114 * @smid: system request message index
115 * @calling_function_name: string pass from calling function
116 * @mpi_reply: reply message frame
117 * Context: none.
118 *
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300119 * Function for displaying debug info helpful when debugging issues
Eric Moore635374e2009-03-09 01:21:12 -0600120 * in this module.
121 */
122static void
123_ctl_display_some_debug(struct MPT2SAS_ADAPTER *ioc, u16 smid,
124 char *calling_function_name, MPI2DefaultReply_t *mpi_reply)
125{
126 Mpi2ConfigRequest_t *mpi_request;
127 char *desc = NULL;
128
129 if (!(ioc->logging_level & MPT_DEBUG_IOCTL))
130 return;
131
132 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
133 switch (mpi_request->Function) {
134 case MPI2_FUNCTION_SCSI_IO_REQUEST:
135 {
136 Mpi2SCSIIORequest_t *scsi_request =
137 (Mpi2SCSIIORequest_t *)mpi_request;
138
139 snprintf(ioc->tmp_string, MPT_STRING_LENGTH,
140 "scsi_io, cmd(0x%02x), cdb_len(%d)",
141 scsi_request->CDB.CDB32[0],
142 le16_to_cpu(scsi_request->IoFlags) & 0xF);
143 desc = ioc->tmp_string;
144 break;
145 }
146 case MPI2_FUNCTION_SCSI_TASK_MGMT:
147 desc = "task_mgmt";
148 break;
149 case MPI2_FUNCTION_IOC_INIT:
150 desc = "ioc_init";
151 break;
152 case MPI2_FUNCTION_IOC_FACTS:
153 desc = "ioc_facts";
154 break;
155 case MPI2_FUNCTION_CONFIG:
156 {
157 Mpi2ConfigRequest_t *config_request =
158 (Mpi2ConfigRequest_t *)mpi_request;
159
160 snprintf(ioc->tmp_string, MPT_STRING_LENGTH,
161 "config, type(0x%02x), ext_type(0x%02x), number(%d)",
162 (config_request->Header.PageType &
163 MPI2_CONFIG_PAGETYPE_MASK), config_request->ExtPageType,
164 config_request->Header.PageNumber);
165 desc = ioc->tmp_string;
166 break;
167 }
168 case MPI2_FUNCTION_PORT_FACTS:
169 desc = "port_facts";
170 break;
171 case MPI2_FUNCTION_PORT_ENABLE:
172 desc = "port_enable";
173 break;
174 case MPI2_FUNCTION_EVENT_NOTIFICATION:
175 desc = "event_notification";
176 break;
177 case MPI2_FUNCTION_FW_DOWNLOAD:
178 desc = "fw_download";
179 break;
180 case MPI2_FUNCTION_FW_UPLOAD:
181 desc = "fw_upload";
182 break;
183 case MPI2_FUNCTION_RAID_ACTION:
184 desc = "raid_action";
185 break;
186 case MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH:
187 {
188 Mpi2SCSIIORequest_t *scsi_request =
189 (Mpi2SCSIIORequest_t *)mpi_request;
190
191 snprintf(ioc->tmp_string, MPT_STRING_LENGTH,
192 "raid_pass, cmd(0x%02x), cdb_len(%d)",
193 scsi_request->CDB.CDB32[0],
194 le16_to_cpu(scsi_request->IoFlags) & 0xF);
195 desc = ioc->tmp_string;
196 break;
197 }
198 case MPI2_FUNCTION_SAS_IO_UNIT_CONTROL:
199 desc = "sas_iounit_cntl";
200 break;
201 case MPI2_FUNCTION_SATA_PASSTHROUGH:
202 desc = "sata_pass";
203 break;
204 case MPI2_FUNCTION_DIAG_BUFFER_POST:
205 desc = "diag_buffer_post";
206 break;
207 case MPI2_FUNCTION_DIAG_RELEASE:
208 desc = "diag_release";
209 break;
210 case MPI2_FUNCTION_SMP_PASSTHROUGH:
211 desc = "smp_passthrough";
212 break;
213 }
214
215 if (!desc)
216 return;
217
Kashyap, Desaieabb08a2010-06-17 13:43:57 +0530218 printk(MPT2SAS_INFO_FMT "%s: %s, smid(%d)\n",
Eric Moore635374e2009-03-09 01:21:12 -0600219 ioc->name, calling_function_name, desc, smid);
220
221 if (!mpi_reply)
222 return;
223
224 if (mpi_reply->IOCStatus || mpi_reply->IOCLogInfo)
Kashyap, Desaieabb08a2010-06-17 13:43:57 +0530225 printk(MPT2SAS_INFO_FMT
Eric Moore635374e2009-03-09 01:21:12 -0600226 "\tiocstatus(0x%04x), loginfo(0x%08x)\n",
227 ioc->name, le16_to_cpu(mpi_reply->IOCStatus),
228 le32_to_cpu(mpi_reply->IOCLogInfo));
229
230 if (mpi_request->Function == MPI2_FUNCTION_SCSI_IO_REQUEST ||
231 mpi_request->Function ==
232 MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH) {
233 Mpi2SCSIIOReply_t *scsi_reply =
234 (Mpi2SCSIIOReply_t *)mpi_reply;
Kashyap, Desai7fbae672010-06-17 13:45:17 +0530235 struct _sas_device *sas_device = NULL;
236 unsigned long flags;
237
238 spin_lock_irqsave(&ioc->sas_device_lock, flags);
239 sas_device = _ctl_sas_device_find_by_handle(ioc,
240 le16_to_cpu(scsi_reply->DevHandle));
241 if (sas_device) {
242 printk(MPT2SAS_WARN_FMT "\tsas_address(0x%016llx), "
243 "phy(%d)\n", ioc->name, (unsigned long long)
244 sas_device->sas_address, sas_device->phy);
245 printk(MPT2SAS_WARN_FMT
246 "\tenclosure_logical_id(0x%016llx), slot(%d)\n",
247 ioc->name, sas_device->enclosure_logical_id,
248 sas_device->slot);
249 }
250 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
Eric Moore635374e2009-03-09 01:21:12 -0600251 if (scsi_reply->SCSIState || scsi_reply->SCSIStatus)
Kashyap, Desaieabb08a2010-06-17 13:43:57 +0530252 printk(MPT2SAS_INFO_FMT
Eric Moore635374e2009-03-09 01:21:12 -0600253 "\tscsi_state(0x%02x), scsi_status"
254 "(0x%02x)\n", ioc->name,
255 scsi_reply->SCSIState,
256 scsi_reply->SCSIStatus);
257 }
258}
259#endif
260
261/**
262 * mpt2sas_ctl_done - ctl module completion routine
263 * @ioc: per adapter object
264 * @smid: system request message index
Kashyap, Desai7b936b02009-09-25 11:44:41 +0530265 * @msix_index: MSIX table index supplied by the OS
Eric Moore635374e2009-03-09 01:21:12 -0600266 * @reply: reply message frame(lower 32bit addr)
267 * Context: none.
268 *
269 * The callback handler when using ioc->ctl_cb_idx.
270 *
Kashyap, Desai77e63ed2009-09-14 11:04:23 +0530271 * Return 1 meaning mf should be freed from _base_interrupt
272 * 0 means the mf is freed from this function.
Eric Moore635374e2009-03-09 01:21:12 -0600273 */
Kashyap, Desai77e63ed2009-09-14 11:04:23 +0530274u8
Kashyap, Desai7b936b02009-09-25 11:44:41 +0530275mpt2sas_ctl_done(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 msix_index,
276 u32 reply)
Eric Moore635374e2009-03-09 01:21:12 -0600277{
278 MPI2DefaultReply_t *mpi_reply;
Kashyap, Desai769578f2010-06-17 13:49:28 +0530279 Mpi2SCSIIOReply_t *scsiio_reply;
280 const void *sense_data;
281 u32 sz;
Eric Moore635374e2009-03-09 01:21:12 -0600282
283 if (ioc->ctl_cmds.status == MPT2_CMD_NOT_USED)
Kashyap, Desai77e63ed2009-09-14 11:04:23 +0530284 return 1;
Eric Moore635374e2009-03-09 01:21:12 -0600285 if (ioc->ctl_cmds.smid != smid)
Kashyap, Desai77e63ed2009-09-14 11:04:23 +0530286 return 1;
Eric Moore635374e2009-03-09 01:21:12 -0600287 ioc->ctl_cmds.status |= MPT2_CMD_COMPLETE;
288 mpi_reply = mpt2sas_base_get_reply_virt_addr(ioc, reply);
289 if (mpi_reply) {
290 memcpy(ioc->ctl_cmds.reply, mpi_reply, mpi_reply->MsgLength*4);
291 ioc->ctl_cmds.status |= MPT2_CMD_REPLY_VALID;
Kashyap, Desai769578f2010-06-17 13:49:28 +0530292 /* get sense data */
293 if (mpi_reply->Function == MPI2_FUNCTION_SCSI_IO_REQUEST ||
294 mpi_reply->Function ==
295 MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH) {
296 scsiio_reply = (Mpi2SCSIIOReply_t *)mpi_reply;
297 if (scsiio_reply->SCSIState &
298 MPI2_SCSI_STATE_AUTOSENSE_VALID) {
299 sz = min_t(u32, SCSI_SENSE_BUFFERSIZE,
300 le32_to_cpu(scsiio_reply->SenseCount));
301 sense_data = mpt2sas_base_get_sense_buffer(ioc,
302 smid);
303 memcpy(ioc->ctl_cmds.sense, sense_data, sz);
304 }
305 }
Eric Moore635374e2009-03-09 01:21:12 -0600306 }
307#ifdef CONFIG_SCSI_MPT2SAS_LOGGING
308 _ctl_display_some_debug(ioc, smid, "ctl_done", mpi_reply);
309#endif
310 ioc->ctl_cmds.status &= ~MPT2_CMD_PENDING;
311 complete(&ioc->ctl_cmds.done);
Kashyap, Desai77e63ed2009-09-14 11:04:23 +0530312 return 1;
Eric Moore635374e2009-03-09 01:21:12 -0600313}
314
315/**
316 * _ctl_check_event_type - determines when an event needs logging
317 * @ioc: per adapter object
318 * @event: firmware event
319 *
320 * The bitmask in ioc->event_type[] indicates which events should be
321 * be saved in the driver event_log. This bitmask is set by application.
322 *
323 * Returns 1 when event should be captured, or zero means no match.
324 */
325static int
326_ctl_check_event_type(struct MPT2SAS_ADAPTER *ioc, u16 event)
327{
328 u16 i;
329 u32 desired_event;
330
331 if (event >= 128 || !event || !ioc->event_log)
332 return 0;
333
334 desired_event = (1 << (event % 32));
335 if (!desired_event)
336 desired_event = 1;
337 i = event / 32;
338 return desired_event & ioc->event_type[i];
339}
340
341/**
342 * mpt2sas_ctl_add_to_event_log - add event
343 * @ioc: per adapter object
344 * @mpi_reply: reply message frame
345 *
346 * Return nothing.
347 */
348void
349mpt2sas_ctl_add_to_event_log(struct MPT2SAS_ADAPTER *ioc,
350 Mpi2EventNotificationReply_t *mpi_reply)
351{
352 struct MPT2_IOCTL_EVENTS *event_log;
353 u16 event;
354 int i;
355 u32 sz, event_data_sz;
356 u8 send_aen = 0;
357
358 if (!ioc->event_log)
359 return;
360
361 event = le16_to_cpu(mpi_reply->Event);
362
363 if (_ctl_check_event_type(ioc, event)) {
364
365 /* insert entry into circular event_log */
366 i = ioc->event_context % MPT2SAS_CTL_EVENT_LOG_SIZE;
367 event_log = ioc->event_log;
368 event_log[i].event = event;
369 event_log[i].context = ioc->event_context++;
370
371 event_data_sz = le16_to_cpu(mpi_reply->EventDataLength)*4;
372 sz = min_t(u32, event_data_sz, MPT2_EVENT_DATA_SIZE);
373 memset(event_log[i].data, 0, MPT2_EVENT_DATA_SIZE);
374 memcpy(event_log[i].data, mpi_reply->EventData, sz);
375 send_aen = 1;
376 }
377
378 /* This aen_event_read_flag flag is set until the
379 * application has read the event log.
380 * For MPI2_EVENT_LOG_ENTRY_ADDED, we always notify.
381 */
382 if (event == MPI2_EVENT_LOG_ENTRY_ADDED ||
383 (send_aen && !ioc->aen_event_read_flag)) {
384 ioc->aen_event_read_flag = 1;
385 wake_up_interruptible(&ctl_poll_wait);
386 if (async_queue)
387 kill_fasync(&async_queue, SIGIO, POLL_IN);
388 }
389}
390
391/**
392 * mpt2sas_ctl_event_callback - firmware event handler (called at ISR time)
393 * @ioc: per adapter object
Kashyap, Desai7b936b02009-09-25 11:44:41 +0530394 * @msix_index: MSIX table index supplied by the OS
Eric Moore635374e2009-03-09 01:21:12 -0600395 * @reply: reply message frame(lower 32bit addr)
396 * Context: interrupt.
397 *
398 * This function merely adds a new work task into ioc->firmware_event_thread.
399 * The tasks are worked from _firmware_event_work in user context.
400 *
Kashyap, Desai77e63ed2009-09-14 11:04:23 +0530401 * Return 1 meaning mf should be freed from _base_interrupt
402 * 0 means the mf is freed from this function.
Eric Moore635374e2009-03-09 01:21:12 -0600403 */
Kashyap, Desai77e63ed2009-09-14 11:04:23 +0530404u8
Kashyap, Desai7b936b02009-09-25 11:44:41 +0530405mpt2sas_ctl_event_callback(struct MPT2SAS_ADAPTER *ioc, u8 msix_index,
406 u32 reply)
Eric Moore635374e2009-03-09 01:21:12 -0600407{
408 Mpi2EventNotificationReply_t *mpi_reply;
409
410 mpi_reply = mpt2sas_base_get_reply_virt_addr(ioc, reply);
411 mpt2sas_ctl_add_to_event_log(ioc, mpi_reply);
Kashyap, Desai77e63ed2009-09-14 11:04:23 +0530412 return 1;
Eric Moore635374e2009-03-09 01:21:12 -0600413}
414
415/**
416 * _ctl_verify_adapter - validates ioc_number passed from application
417 * @ioc: per adapter object
418 * @iocpp: The ioc pointer is returned in this.
419 *
420 * Return (-1) means error, else ioc_number.
421 */
422static int
423_ctl_verify_adapter(int ioc_number, struct MPT2SAS_ADAPTER **iocpp)
424{
425 struct MPT2SAS_ADAPTER *ioc;
426
Eric Mooreba33fad2009-03-15 21:37:18 -0600427 list_for_each_entry(ioc, &mpt2sas_ioc_list, list) {
Eric Moore635374e2009-03-09 01:21:12 -0600428 if (ioc->id != ioc_number)
429 continue;
430 *iocpp = ioc;
431 return ioc_number;
432 }
433 *iocpp = NULL;
434 return -1;
435}
436
437/**
438 * mpt2sas_ctl_reset_handler - reset callback handler (for ctl)
439 * @ioc: per adapter object
440 * @reset_phase: phase
441 *
442 * The handler for doing any required cleanup or initialization.
443 *
444 * The reset phase can be MPT2_IOC_PRE_RESET, MPT2_IOC_AFTER_RESET,
445 * MPT2_IOC_DONE_RESET
446 */
447void
448mpt2sas_ctl_reset_handler(struct MPT2SAS_ADAPTER *ioc, int reset_phase)
449{
Eric Moore99bb2142009-04-21 15:42:13 -0600450 int i;
451 u8 issue_reset;
452
Eric Moore635374e2009-03-09 01:21:12 -0600453 switch (reset_phase) {
454 case MPT2_IOC_PRE_RESET:
Kashyap, Desaieabb08a2010-06-17 13:43:57 +0530455 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: "
Eric Moore635374e2009-03-09 01:21:12 -0600456 "MPT2_IOC_PRE_RESET\n", ioc->name, __func__));
Eric Moore99bb2142009-04-21 15:42:13 -0600457 for (i = 0; i < MPI2_DIAG_BUF_TYPE_COUNT; i++) {
458 if (!(ioc->diag_buffer_status[i] &
459 MPT2_DIAG_BUFFER_IS_REGISTERED))
460 continue;
461 if ((ioc->diag_buffer_status[i] &
462 MPT2_DIAG_BUFFER_IS_RELEASED))
463 continue;
464 _ctl_send_release(ioc, i, &issue_reset);
465 }
Eric Moore635374e2009-03-09 01:21:12 -0600466 break;
467 case MPT2_IOC_AFTER_RESET:
Kashyap, Desaieabb08a2010-06-17 13:43:57 +0530468 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: "
Eric Moore635374e2009-03-09 01:21:12 -0600469 "MPT2_IOC_AFTER_RESET\n", ioc->name, __func__));
470 if (ioc->ctl_cmds.status & MPT2_CMD_PENDING) {
471 ioc->ctl_cmds.status |= MPT2_CMD_RESET;
472 mpt2sas_base_free_smid(ioc, ioc->ctl_cmds.smid);
473 complete(&ioc->ctl_cmds.done);
474 }
475 break;
476 case MPT2_IOC_DONE_RESET:
Kashyap, Desaieabb08a2010-06-17 13:43:57 +0530477 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: "
Eric Moore635374e2009-03-09 01:21:12 -0600478 "MPT2_IOC_DONE_RESET\n", ioc->name, __func__));
Eric Moore99bb2142009-04-21 15:42:13 -0600479
480 for (i = 0; i < MPI2_DIAG_BUF_TYPE_COUNT; i++) {
481 if (!(ioc->diag_buffer_status[i] &
482 MPT2_DIAG_BUFFER_IS_REGISTERED))
483 continue;
484 if ((ioc->diag_buffer_status[i] &
485 MPT2_DIAG_BUFFER_IS_RELEASED))
486 continue;
487 ioc->diag_buffer_status[i] |=
488 MPT2_DIAG_BUFFER_IS_DIAG_RESET;
489 }
Eric Moore635374e2009-03-09 01:21:12 -0600490 break;
491 }
492}
493
494/**
495 * _ctl_fasync -
496 * @fd -
497 * @filep -
498 * @mode -
499 *
500 * Called when application request fasyn callback handler.
501 */
502static int
503_ctl_fasync(int fd, struct file *filep, int mode)
504{
505 return fasync_helper(fd, filep, mode, &async_queue);
506}
507
508/**
509 * _ctl_release -
510 * @inode -
511 * @filep -
512 *
513 * Called when application releases the fasyn callback handler.
514 */
515static int
516_ctl_release(struct inode *inode, struct file *filep)
517{
518 return fasync_helper(-1, filep, 0, &async_queue);
519}
520
521/**
522 * _ctl_poll -
523 * @file -
524 * @wait -
525 *
526 */
527static unsigned int
528_ctl_poll(struct file *filep, poll_table *wait)
529{
530 struct MPT2SAS_ADAPTER *ioc;
531
532 poll_wait(filep, &ctl_poll_wait, wait);
533
Eric Mooreba33fad2009-03-15 21:37:18 -0600534 list_for_each_entry(ioc, &mpt2sas_ioc_list, list) {
Eric Moore635374e2009-03-09 01:21:12 -0600535 if (ioc->aen_event_read_flag)
536 return POLLIN | POLLRDNORM;
537 }
538 return 0;
539}
540
541/**
Eric Mooreddf59a32009-05-18 13:01:29 -0600542 * _ctl_set_task_mid - assign an active smid to tm request
Eric Moore635374e2009-03-09 01:21:12 -0600543 * @ioc: per adapter object
544 * @karg - (struct mpt2_ioctl_command)
545 * @tm_request - pointer to mf from user space
546 *
547 * Returns 0 when an smid if found, else fail.
548 * during failure, the reply frame is filled.
549 */
550static int
Eric Mooreddf59a32009-05-18 13:01:29 -0600551_ctl_set_task_mid(struct MPT2SAS_ADAPTER *ioc, struct mpt2_ioctl_command *karg,
Eric Moore635374e2009-03-09 01:21:12 -0600552 Mpi2SCSITaskManagementRequest_t *tm_request)
553{
554 u8 found = 0;
555 u16 i;
556 u16 handle;
557 struct scsi_cmnd *scmd;
558 struct MPT2SAS_DEVICE *priv_data;
559 unsigned long flags;
560 Mpi2SCSITaskManagementReply_t *tm_reply;
561 u32 sz;
562 u32 lun;
Eric Mooreddf59a32009-05-18 13:01:29 -0600563 char *desc = NULL;
564
565 if (tm_request->TaskType == MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK)
566 desc = "abort_task";
567 else if (tm_request->TaskType == MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK)
568 desc = "query_task";
569 else
570 return 0;
Eric Moore635374e2009-03-09 01:21:12 -0600571
572 lun = scsilun_to_int((struct scsi_lun *)tm_request->LUN);
573
574 handle = le16_to_cpu(tm_request->DevHandle);
575 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
Kashyap, Desai595bb0b2009-09-14 11:02:48 +0530576 for (i = ioc->scsiio_depth; i && !found; i--) {
Eric Moore635374e2009-03-09 01:21:12 -0600577 scmd = ioc->scsi_lookup[i - 1].scmd;
578 if (scmd == NULL || scmd->device == NULL ||
579 scmd->device->hostdata == NULL)
580 continue;
581 if (lun != scmd->device->lun)
582 continue;
583 priv_data = scmd->device->hostdata;
584 if (priv_data->sas_target == NULL)
585 continue;
586 if (priv_data->sas_target->handle != handle)
587 continue;
588 tm_request->TaskMID = cpu_to_le16(ioc->scsi_lookup[i - 1].smid);
589 found = 1;
590 }
591 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
592
593 if (!found) {
Kashyap, Desaieabb08a2010-06-17 13:43:57 +0530594 dctlprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: "
Eric Mooreddf59a32009-05-18 13:01:29 -0600595 "handle(0x%04x), lun(%d), no active mid!!\n", ioc->name,
Kashyap, Desaie94f6742010-03-17 16:24:52 +0530596 desc, le16_to_cpu(tm_request->DevHandle), lun));
Eric Moore635374e2009-03-09 01:21:12 -0600597 tm_reply = ioc->ctl_cmds.reply;
598 tm_reply->DevHandle = tm_request->DevHandle;
599 tm_reply->Function = MPI2_FUNCTION_SCSI_TASK_MGMT;
Eric Mooreddf59a32009-05-18 13:01:29 -0600600 tm_reply->TaskType = tm_request->TaskType;
Eric Moore635374e2009-03-09 01:21:12 -0600601 tm_reply->MsgLength = sizeof(Mpi2SCSITaskManagementReply_t)/4;
602 tm_reply->VP_ID = tm_request->VP_ID;
603 tm_reply->VF_ID = tm_request->VF_ID;
604 sz = min_t(u32, karg->max_reply_bytes, ioc->reply_sz);
605 if (copy_to_user(karg->reply_frame_buf_ptr, ioc->ctl_cmds.reply,
606 sz))
607 printk(KERN_ERR "failure at %s:%d/%s()!\n", __FILE__,
608 __LINE__, __func__);
609 return 1;
610 }
611
Kashyap, Desaieabb08a2010-06-17 13:43:57 +0530612 dctlprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: "
Eric Mooreddf59a32009-05-18 13:01:29 -0600613 "handle(0x%04x), lun(%d), task_mid(%d)\n", ioc->name,
Kashyap, Desaie94f6742010-03-17 16:24:52 +0530614 desc, le16_to_cpu(tm_request->DevHandle), lun,
615 le16_to_cpu(tm_request->TaskMID)));
Eric Moore635374e2009-03-09 01:21:12 -0600616 return 0;
617}
618
619/**
620 * _ctl_do_mpt_command - main handler for MPT2COMMAND opcode
621 * @ioc: per adapter object
622 * @karg - (struct mpt2_ioctl_command)
623 * @mf - pointer to mf in user space
624 * @state - NON_BLOCKING or BLOCKING
625 */
626static long
627_ctl_do_mpt_command(struct MPT2SAS_ADAPTER *ioc,
628 struct mpt2_ioctl_command karg, void __user *mf, enum block_state state)
629{
Kashyap, Desai1bbfa372010-06-17 13:50:11 +0530630 MPI2RequestHeader_t *mpi_request = NULL, *request;
Eric Moore635374e2009-03-09 01:21:12 -0600631 MPI2DefaultReply_t *mpi_reply;
632 u32 ioc_state;
633 u16 ioc_status;
634 u16 smid;
635 unsigned long timeout, timeleft;
636 u8 issue_reset;
637 u32 sz;
638 void *psge;
Eric Moore635374e2009-03-09 01:21:12 -0600639 void *data_out = NULL;
640 dma_addr_t data_out_dma;
641 size_t data_out_sz = 0;
642 void *data_in = NULL;
643 dma_addr_t data_in_dma;
644 size_t data_in_sz = 0;
645 u32 sgl_flags;
646 long ret;
647 u16 wait_state_count;
648
649 issue_reset = 0;
650
651 if (state == NON_BLOCKING && !mutex_trylock(&ioc->ctl_cmds.mutex))
652 return -EAGAIN;
653 else if (mutex_lock_interruptible(&ioc->ctl_cmds.mutex))
654 return -ERESTARTSYS;
655
656 if (ioc->ctl_cmds.status != MPT2_CMD_NOT_USED) {
657 printk(MPT2SAS_ERR_FMT "%s: ctl_cmd in use\n",
658 ioc->name, __func__);
659 ret = -EAGAIN;
660 goto out;
661 }
662
663 wait_state_count = 0;
664 ioc_state = mpt2sas_base_get_iocstate(ioc, 1);
665 while (ioc_state != MPI2_IOC_STATE_OPERATIONAL) {
666 if (wait_state_count++ == 10) {
667 printk(MPT2SAS_ERR_FMT
668 "%s: failed due to ioc not operational\n",
669 ioc->name, __func__);
670 ret = -EFAULT;
671 goto out;
672 }
673 ssleep(1);
674 ioc_state = mpt2sas_base_get_iocstate(ioc, 1);
675 printk(MPT2SAS_INFO_FMT "%s: waiting for "
676 "operational state(count=%d)\n", ioc->name,
677 __func__, wait_state_count);
678 }
679 if (wait_state_count)
680 printk(MPT2SAS_INFO_FMT "%s: ioc is operational\n",
681 ioc->name, __func__);
682
Kashyap, Desai1bbfa372010-06-17 13:50:11 +0530683 mpi_request = kzalloc(ioc->request_sz, GFP_KERNEL);
684 if (!mpi_request) {
685 printk(MPT2SAS_ERR_FMT "%s: failed obtaining a memory for "
686 "mpi_request\n", ioc->name, __func__);
687 ret = -ENOMEM;
Eric Moore635374e2009-03-09 01:21:12 -0600688 goto out;
689 }
690
Eric Moore635374e2009-03-09 01:21:12 -0600691 /* copy in request message frame from user */
692 if (copy_from_user(mpi_request, mf, karg.data_sge_offset*4)) {
693 printk(KERN_ERR "failure at %s:%d/%s()!\n", __FILE__, __LINE__,
694 __func__);
695 ret = -EFAULT;
Eric Moore635374e2009-03-09 01:21:12 -0600696 goto out;
697 }
698
Kashyap, Desai1bbfa372010-06-17 13:50:11 +0530699 if (mpi_request->Function == MPI2_FUNCTION_SCSI_TASK_MGMT) {
700 smid = mpt2sas_base_get_smid_hpr(ioc, ioc->ctl_cb_idx);
701 if (!smid) {
702 printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n",
703 ioc->name, __func__);
704 ret = -EAGAIN;
705 goto out;
706 }
707 } else {
708
709 smid = mpt2sas_base_get_smid_scsiio(ioc, ioc->ctl_cb_idx, NULL);
710 if (!smid) {
711 printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n",
712 ioc->name, __func__);
713 ret = -EAGAIN;
714 goto out;
715 }
716 }
717
718 ret = 0;
719 ioc->ctl_cmds.status = MPT2_CMD_PENDING;
720 memset(ioc->ctl_cmds.reply, 0, ioc->reply_sz);
721 request = mpt2sas_base_get_msg_frame(ioc, smid);
722 memcpy(request, mpi_request, karg.data_sge_offset*4);
723 ioc->ctl_cmds.smid = smid;
724 data_out_sz = karg.data_out_size;
725 data_in_sz = karg.data_in_size;
726
Eric Moore635374e2009-03-09 01:21:12 -0600727 if (mpi_request->Function == MPI2_FUNCTION_SCSI_IO_REQUEST ||
728 mpi_request->Function == MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH) {
Kashyap, Desaie94f6742010-03-17 16:24:52 +0530729 if (!le16_to_cpu(mpi_request->FunctionDependent1) ||
730 le16_to_cpu(mpi_request->FunctionDependent1) >
731 ioc->facts.MaxDevHandle) {
Eric Moore635374e2009-03-09 01:21:12 -0600732 ret = -EINVAL;
733 mpt2sas_base_free_smid(ioc, smid);
734 goto out;
735 }
736 }
737
738 /* obtain dma-able memory for data transfer */
739 if (data_out_sz) /* WRITE */ {
740 data_out = pci_alloc_consistent(ioc->pdev, data_out_sz,
741 &data_out_dma);
742 if (!data_out) {
743 printk(KERN_ERR "failure at %s:%d/%s()!\n", __FILE__,
744 __LINE__, __func__);
745 ret = -ENOMEM;
746 mpt2sas_base_free_smid(ioc, smid);
747 goto out;
748 }
749 if (copy_from_user(data_out, karg.data_out_buf_ptr,
750 data_out_sz)) {
751 printk(KERN_ERR "failure at %s:%d/%s()!\n", __FILE__,
752 __LINE__, __func__);
753 ret = -EFAULT;
754 mpt2sas_base_free_smid(ioc, smid);
755 goto out;
756 }
757 }
758
759 if (data_in_sz) /* READ */ {
760 data_in = pci_alloc_consistent(ioc->pdev, data_in_sz,
761 &data_in_dma);
762 if (!data_in) {
763 printk(KERN_ERR "failure at %s:%d/%s()!\n", __FILE__,
764 __LINE__, __func__);
765 ret = -ENOMEM;
766 mpt2sas_base_free_smid(ioc, smid);
767 goto out;
768 }
769 }
770
771 /* add scatter gather elements */
Kashyap, Desai1bbfa372010-06-17 13:50:11 +0530772 psge = (void *)request + (karg.data_sge_offset*4);
Eric Moore635374e2009-03-09 01:21:12 -0600773
774 if (!data_out_sz && !data_in_sz) {
775 mpt2sas_base_build_zero_len_sge(ioc, psge);
776 } else if (data_out_sz && data_in_sz) {
777 /* WRITE sgel first */
778 sgl_flags = (MPI2_SGE_FLAGS_SIMPLE_ELEMENT |
779 MPI2_SGE_FLAGS_END_OF_BUFFER | MPI2_SGE_FLAGS_HOST_TO_IOC);
780 sgl_flags = sgl_flags << MPI2_SGE_FLAGS_SHIFT;
781 ioc->base_add_sg_single(psge, sgl_flags |
782 data_out_sz, data_out_dma);
783
784 /* incr sgel */
785 psge += ioc->sge_size;
786
787 /* READ sgel last */
788 sgl_flags = (MPI2_SGE_FLAGS_SIMPLE_ELEMENT |
789 MPI2_SGE_FLAGS_LAST_ELEMENT | MPI2_SGE_FLAGS_END_OF_BUFFER |
790 MPI2_SGE_FLAGS_END_OF_LIST);
791 sgl_flags = sgl_flags << MPI2_SGE_FLAGS_SHIFT;
792 ioc->base_add_sg_single(psge, sgl_flags |
793 data_in_sz, data_in_dma);
794 } else if (data_out_sz) /* WRITE */ {
795 sgl_flags = (MPI2_SGE_FLAGS_SIMPLE_ELEMENT |
796 MPI2_SGE_FLAGS_LAST_ELEMENT | MPI2_SGE_FLAGS_END_OF_BUFFER |
797 MPI2_SGE_FLAGS_END_OF_LIST | MPI2_SGE_FLAGS_HOST_TO_IOC);
798 sgl_flags = sgl_flags << MPI2_SGE_FLAGS_SHIFT;
799 ioc->base_add_sg_single(psge, sgl_flags |
800 data_out_sz, data_out_dma);
801 } else if (data_in_sz) /* READ */ {
802 sgl_flags = (MPI2_SGE_FLAGS_SIMPLE_ELEMENT |
803 MPI2_SGE_FLAGS_LAST_ELEMENT | MPI2_SGE_FLAGS_END_OF_BUFFER |
804 MPI2_SGE_FLAGS_END_OF_LIST);
805 sgl_flags = sgl_flags << MPI2_SGE_FLAGS_SHIFT;
806 ioc->base_add_sg_single(psge, sgl_flags |
807 data_in_sz, data_in_dma);
808 }
809
810 /* send command to firmware */
811#ifdef CONFIG_SCSI_MPT2SAS_LOGGING
812 _ctl_display_some_debug(ioc, smid, "ctl_request", NULL);
813#endif
814
815 switch (mpi_request->Function) {
816 case MPI2_FUNCTION_SCSI_IO_REQUEST:
817 case MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH:
818 {
819 Mpi2SCSIIORequest_t *scsiio_request =
Kashyap, Desai1bbfa372010-06-17 13:50:11 +0530820 (Mpi2SCSIIORequest_t *)request;
Kashyap, Desai769578f2010-06-17 13:49:28 +0530821 scsiio_request->SenseBufferLength = SCSI_SENSE_BUFFERSIZE;
Eric Moore635374e2009-03-09 01:21:12 -0600822 scsiio_request->SenseBufferLowAddress =
Kashyap, Desaiec9472c2009-09-23 17:34:13 +0530823 mpt2sas_base_get_sense_buffer_dma(ioc, smid);
Kashyap, Desai769578f2010-06-17 13:49:28 +0530824 memset(ioc->ctl_cmds.sense, 0, SCSI_SENSE_BUFFERSIZE);
Kashyap, Desaiebda4d32010-04-05 14:19:21 +0530825 if (mpi_request->Function == MPI2_FUNCTION_SCSI_IO_REQUEST)
826 mpt2sas_base_put_smid_scsi_io(ioc, smid,
827 le16_to_cpu(mpi_request->FunctionDependent1));
828 else
829 mpt2sas_base_put_smid_default(ioc, smid);
Eric Moore635374e2009-03-09 01:21:12 -0600830 break;
831 }
832 case MPI2_FUNCTION_SCSI_TASK_MGMT:
833 {
834 Mpi2SCSITaskManagementRequest_t *tm_request =
Kashyap, Desai1bbfa372010-06-17 13:50:11 +0530835 (Mpi2SCSITaskManagementRequest_t *)request;
Eric Moore635374e2009-03-09 01:21:12 -0600836
Kashyap, Desaieabb08a2010-06-17 13:43:57 +0530837 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "TASK_MGMT: "
Kashyap, Desai8ed9a032010-03-17 16:25:59 +0530838 "handle(0x%04x), task_type(0x%02x)\n", ioc->name,
839 le16_to_cpu(tm_request->DevHandle), tm_request->TaskType));
840
Eric Moore635374e2009-03-09 01:21:12 -0600841 if (tm_request->TaskType ==
Eric Mooreddf59a32009-05-18 13:01:29 -0600842 MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK ||
843 tm_request->TaskType ==
844 MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK) {
845 if (_ctl_set_task_mid(ioc, &karg, tm_request)) {
Eric Moore77bdd9e2009-04-21 15:39:24 -0600846 mpt2sas_base_free_smid(ioc, smid);
Eric Moore635374e2009-03-09 01:21:12 -0600847 goto out;
Eric Moore77bdd9e2009-04-21 15:39:24 -0600848 }
Eric Moore635374e2009-03-09 01:21:12 -0600849 }
850
Eric Moore635374e2009-03-09 01:21:12 -0600851 mpt2sas_scsih_set_tm_flag(ioc, le16_to_cpu(
852 tm_request->DevHandle));
Kashyap, Desai7b936b02009-09-25 11:44:41 +0530853 mpt2sas_base_put_smid_hi_priority(ioc, smid);
Eric Moore635374e2009-03-09 01:21:12 -0600854 break;
855 }
856 case MPI2_FUNCTION_SMP_PASSTHROUGH:
857 {
858 Mpi2SmpPassthroughRequest_t *smp_request =
859 (Mpi2SmpPassthroughRequest_t *)mpi_request;
860 u8 *data;
861
862 /* ioc determines which port to use */
863 smp_request->PhysicalPort = 0xFF;
864 if (smp_request->PassthroughFlags &
865 MPI2_SMP_PT_REQ_PT_FLAGS_IMMEDIATE)
866 data = (u8 *)&smp_request->SGL;
867 else
868 data = data_out;
869
870 if (data[1] == 0x91 && (data[10] == 1 || data[10] == 2)) {
871 ioc->ioc_link_reset_in_progress = 1;
872 ioc->ignore_loginfos = 1;
873 }
Kashyap, Desai7b936b02009-09-25 11:44:41 +0530874 mpt2sas_base_put_smid_default(ioc, smid);
Eric Moore635374e2009-03-09 01:21:12 -0600875 break;
876 }
877 case MPI2_FUNCTION_SAS_IO_UNIT_CONTROL:
878 {
879 Mpi2SasIoUnitControlRequest_t *sasiounit_request =
880 (Mpi2SasIoUnitControlRequest_t *)mpi_request;
881
882 if (sasiounit_request->Operation == MPI2_SAS_OP_PHY_HARD_RESET
883 || sasiounit_request->Operation ==
884 MPI2_SAS_OP_PHY_LINK_RESET) {
885 ioc->ioc_link_reset_in_progress = 1;
886 ioc->ignore_loginfos = 1;
887 }
Kashyap, Desai7b936b02009-09-25 11:44:41 +0530888 mpt2sas_base_put_smid_default(ioc, smid);
Eric Moore635374e2009-03-09 01:21:12 -0600889 break;
890 }
891 default:
Kashyap, Desai7b936b02009-09-25 11:44:41 +0530892 mpt2sas_base_put_smid_default(ioc, smid);
Eric Moore635374e2009-03-09 01:21:12 -0600893 break;
894 }
895
896 if (karg.timeout < MPT2_IOCTL_DEFAULT_TIMEOUT)
897 timeout = MPT2_IOCTL_DEFAULT_TIMEOUT;
898 else
899 timeout = karg.timeout;
Kashyap, Desaibcfb6e62009-09-14 11:05:24 +0530900 init_completion(&ioc->ctl_cmds.done);
Eric Moore635374e2009-03-09 01:21:12 -0600901 timeleft = wait_for_completion_timeout(&ioc->ctl_cmds.done,
902 timeout*HZ);
903 if (mpi_request->Function == MPI2_FUNCTION_SCSI_TASK_MGMT) {
904 Mpi2SCSITaskManagementRequest_t *tm_request =
905 (Mpi2SCSITaskManagementRequest_t *)mpi_request;
Eric Moore635374e2009-03-09 01:21:12 -0600906 mpt2sas_scsih_clear_tm_flag(ioc, le16_to_cpu(
907 tm_request->DevHandle));
908 } else if ((mpi_request->Function == MPI2_FUNCTION_SMP_PASSTHROUGH ||
909 mpi_request->Function == MPI2_FUNCTION_SAS_IO_UNIT_CONTROL) &&
910 ioc->ioc_link_reset_in_progress) {
911 ioc->ioc_link_reset_in_progress = 0;
912 ioc->ignore_loginfos = 0;
913 }
914 if (!(ioc->ctl_cmds.status & MPT2_CMD_COMPLETE)) {
915 printk(MPT2SAS_ERR_FMT "%s: timeout\n", ioc->name,
916 __func__);
917 _debug_dump_mf(mpi_request, karg.data_sge_offset);
918 if (!(ioc->ctl_cmds.status & MPT2_CMD_RESET))
919 issue_reset = 1;
920 goto issue_host_reset;
921 }
922
923 mpi_reply = ioc->ctl_cmds.reply;
924 ioc_status = le16_to_cpu(mpi_reply->IOCStatus) & MPI2_IOCSTATUS_MASK;
925
926#ifdef CONFIG_SCSI_MPT2SAS_LOGGING
927 if (mpi_reply->Function == MPI2_FUNCTION_SCSI_TASK_MGMT &&
928 (ioc->logging_level & MPT_DEBUG_TM)) {
929 Mpi2SCSITaskManagementReply_t *tm_reply =
930 (Mpi2SCSITaskManagementReply_t *)mpi_reply;
931
Kashyap, Desaieabb08a2010-06-17 13:43:57 +0530932 printk(MPT2SAS_INFO_FMT "TASK_MGMT: "
Eric Moore635374e2009-03-09 01:21:12 -0600933 "IOCStatus(0x%04x), IOCLogInfo(0x%08x), "
934 "TerminationCount(0x%08x)\n", ioc->name,
Kashyap, Desai463217b2009-10-05 15:53:06 +0530935 le16_to_cpu(tm_reply->IOCStatus),
936 le32_to_cpu(tm_reply->IOCLogInfo),
937 le32_to_cpu(tm_reply->TerminationCount));
Eric Moore635374e2009-03-09 01:21:12 -0600938 }
939#endif
940 /* copy out xdata to user */
941 if (data_in_sz) {
942 if (copy_to_user(karg.data_in_buf_ptr, data_in,
943 data_in_sz)) {
944 printk(KERN_ERR "failure at %s:%d/%s()!\n", __FILE__,
945 __LINE__, __func__);
946 ret = -ENODATA;
947 goto out;
948 }
949 }
950
951 /* copy out reply message frame to user */
952 if (karg.max_reply_bytes) {
953 sz = min_t(u32, karg.max_reply_bytes, ioc->reply_sz);
954 if (copy_to_user(karg.reply_frame_buf_ptr, ioc->ctl_cmds.reply,
955 sz)) {
956 printk(KERN_ERR "failure at %s:%d/%s()!\n", __FILE__,
957 __LINE__, __func__);
958 ret = -ENODATA;
959 goto out;
960 }
961 }
962
963 /* copy out sense to user */
964 if (karg.max_sense_bytes && (mpi_request->Function ==
965 MPI2_FUNCTION_SCSI_IO_REQUEST || mpi_request->Function ==
966 MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH)) {
967 sz = min_t(u32, karg.max_sense_bytes, SCSI_SENSE_BUFFERSIZE);
Kashyap, Desai769578f2010-06-17 13:49:28 +0530968 if (copy_to_user(karg.sense_data_ptr,
969 ioc->ctl_cmds.sense, sz)) {
Eric Moore635374e2009-03-09 01:21:12 -0600970 printk(KERN_ERR "failure at %s:%d/%s()!\n", __FILE__,
971 __LINE__, __func__);
972 ret = -ENODATA;
973 goto out;
974 }
975 }
976
977 issue_host_reset:
978 if (issue_reset) {
Kashyap, Desaib2ff36b2009-12-16 18:51:05 +0530979 ret = -ENODATA;
Eric Moore635374e2009-03-09 01:21:12 -0600980 if ((mpi_request->Function == MPI2_FUNCTION_SCSI_IO_REQUEST ||
981 mpi_request->Function ==
982 MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH)) {
983 printk(MPT2SAS_INFO_FMT "issue target reset: handle "
984 "= (0x%04x)\n", ioc->name,
Kashyap, Desaie94f6742010-03-17 16:24:52 +0530985 le16_to_cpu(mpi_request->FunctionDependent1));
Kashyap, Desaifa7f3162009-09-23 17:26:58 +0530986 mpt2sas_halt_firmware(ioc);
Eric Moore635374e2009-03-09 01:21:12 -0600987 mpt2sas_scsih_issue_tm(ioc,
Kashyap, Desai8ed9a032010-03-17 16:25:59 +0530988 le16_to_cpu(mpi_request->FunctionDependent1), 0, 0,
989 0, MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET, 0, 10,
990 NULL);
Eric Moore635374e2009-03-09 01:21:12 -0600991 ioc->tm_cmds.status = MPT2_CMD_NOT_USED;
Eric Moore635374e2009-03-09 01:21:12 -0600992 } else
993 mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP,
994 FORCE_BIG_HAMMER);
995 }
996
997 out:
998
999 /* free memory associated with sg buffers */
1000 if (data_in)
1001 pci_free_consistent(ioc->pdev, data_in_sz, data_in,
1002 data_in_dma);
1003
1004 if (data_out)
1005 pci_free_consistent(ioc->pdev, data_out_sz, data_out,
1006 data_out_dma);
1007
Kashyap, Desai1bbfa372010-06-17 13:50:11 +05301008 kfree(mpi_request);
Eric Moore635374e2009-03-09 01:21:12 -06001009 ioc->ctl_cmds.status = MPT2_CMD_NOT_USED;
1010 mutex_unlock(&ioc->ctl_cmds.mutex);
1011 return ret;
1012}
1013
1014/**
1015 * _ctl_getiocinfo - main handler for MPT2IOCINFO opcode
1016 * @arg - user space buffer containing ioctl content
1017 */
1018static long
1019_ctl_getiocinfo(void __user *arg)
1020{
1021 struct mpt2_ioctl_iocinfo karg;
1022 struct MPT2SAS_ADAPTER *ioc;
1023 u8 revision;
1024
1025 if (copy_from_user(&karg, arg, sizeof(karg))) {
1026 printk(KERN_ERR "failure at %s:%d/%s()!\n",
1027 __FILE__, __LINE__, __func__);
1028 return -EFAULT;
1029 }
1030 if (_ctl_verify_adapter(karg.hdr.ioc_number, &ioc) == -1 || !ioc)
1031 return -ENODEV;
1032
Kashyap, Desaieabb08a2010-06-17 13:43:57 +05301033 dctlprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: enter\n", ioc->name,
Eric Moore635374e2009-03-09 01:21:12 -06001034 __func__));
1035
1036 memset(&karg, 0 , sizeof(karg));
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05301037 if (ioc->is_warpdrive)
1038 karg.adapter_type = MPT2_IOCTL_INTERFACE_SAS2_SSS6200;
1039 else
1040 karg.adapter_type = MPT2_IOCTL_INTERFACE_SAS2;
Eric Moore635374e2009-03-09 01:21:12 -06001041 if (ioc->pfacts)
1042 karg.port_number = ioc->pfacts[0].PortNumber;
1043 pci_read_config_byte(ioc->pdev, PCI_CLASS_REVISION, &revision);
1044 karg.hw_rev = revision;
1045 karg.pci_id = ioc->pdev->device;
1046 karg.subsystem_device = ioc->pdev->subsystem_device;
1047 karg.subsystem_vendor = ioc->pdev->subsystem_vendor;
1048 karg.pci_information.u.bits.bus = ioc->pdev->bus->number;
1049 karg.pci_information.u.bits.device = PCI_SLOT(ioc->pdev->devfn);
1050 karg.pci_information.u.bits.function = PCI_FUNC(ioc->pdev->devfn);
1051 karg.pci_information.segment_id = pci_domain_nr(ioc->pdev->bus);
1052 karg.firmware_version = ioc->facts.FWVersion.Word;
Eric Mooree5f9bb12009-04-21 15:40:01 -06001053 strcpy(karg.driver_version, MPT2SAS_DRIVER_NAME);
1054 strcat(karg.driver_version, "-");
1055 strcat(karg.driver_version, MPT2SAS_DRIVER_VERSION);
Eric Moore635374e2009-03-09 01:21:12 -06001056 karg.bios_version = le32_to_cpu(ioc->bios_pg3.BiosVersion);
1057
1058 if (copy_to_user(arg, &karg, sizeof(karg))) {
1059 printk(KERN_ERR "failure at %s:%d/%s()!\n",
1060 __FILE__, __LINE__, __func__);
1061 return -EFAULT;
1062 }
1063 return 0;
1064}
1065
1066/**
1067 * _ctl_eventquery - main handler for MPT2EVENTQUERY opcode
1068 * @arg - user space buffer containing ioctl content
1069 */
1070static long
1071_ctl_eventquery(void __user *arg)
1072{
1073 struct mpt2_ioctl_eventquery karg;
1074 struct MPT2SAS_ADAPTER *ioc;
1075
1076 if (copy_from_user(&karg, arg, sizeof(karg))) {
1077 printk(KERN_ERR "failure at %s:%d/%s()!\n",
1078 __FILE__, __LINE__, __func__);
1079 return -EFAULT;
1080 }
1081 if (_ctl_verify_adapter(karg.hdr.ioc_number, &ioc) == -1 || !ioc)
1082 return -ENODEV;
1083
Kashyap, Desaieabb08a2010-06-17 13:43:57 +05301084 dctlprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: enter\n", ioc->name,
Eric Moore635374e2009-03-09 01:21:12 -06001085 __func__));
1086
1087 karg.event_entries = MPT2SAS_CTL_EVENT_LOG_SIZE;
1088 memcpy(karg.event_types, ioc->event_type,
1089 MPI2_EVENT_NOTIFY_EVENTMASK_WORDS * sizeof(u32));
1090
1091 if (copy_to_user(arg, &karg, sizeof(karg))) {
1092 printk(KERN_ERR "failure at %s:%d/%s()!\n",
1093 __FILE__, __LINE__, __func__);
1094 return -EFAULT;
1095 }
1096 return 0;
1097}
1098
1099/**
1100 * _ctl_eventenable - main handler for MPT2EVENTENABLE opcode
1101 * @arg - user space buffer containing ioctl content
1102 */
1103static long
1104_ctl_eventenable(void __user *arg)
1105{
1106 struct mpt2_ioctl_eventenable karg;
1107 struct MPT2SAS_ADAPTER *ioc;
1108
1109 if (copy_from_user(&karg, arg, sizeof(karg))) {
1110 printk(KERN_ERR "failure at %s:%d/%s()!\n",
1111 __FILE__, __LINE__, __func__);
1112 return -EFAULT;
1113 }
1114 if (_ctl_verify_adapter(karg.hdr.ioc_number, &ioc) == -1 || !ioc)
1115 return -ENODEV;
1116
Kashyap, Desaieabb08a2010-06-17 13:43:57 +05301117 dctlprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: enter\n", ioc->name,
Eric Moore635374e2009-03-09 01:21:12 -06001118 __func__));
1119
1120 if (ioc->event_log)
1121 return 0;
1122 memcpy(ioc->event_type, karg.event_types,
1123 MPI2_EVENT_NOTIFY_EVENTMASK_WORDS * sizeof(u32));
1124 mpt2sas_base_validate_event_type(ioc, ioc->event_type);
1125
1126 /* initialize event_log */
1127 ioc->event_context = 0;
1128 ioc->aen_event_read_flag = 0;
1129 ioc->event_log = kcalloc(MPT2SAS_CTL_EVENT_LOG_SIZE,
1130 sizeof(struct MPT2_IOCTL_EVENTS), GFP_KERNEL);
1131 if (!ioc->event_log) {
1132 printk(KERN_ERR "failure at %s:%d/%s()!\n",
1133 __FILE__, __LINE__, __func__);
1134 return -ENOMEM;
1135 }
1136 return 0;
1137}
1138
1139/**
1140 * _ctl_eventreport - main handler for MPT2EVENTREPORT opcode
1141 * @arg - user space buffer containing ioctl content
1142 */
1143static long
1144_ctl_eventreport(void __user *arg)
1145{
1146 struct mpt2_ioctl_eventreport karg;
1147 struct MPT2SAS_ADAPTER *ioc;
1148 u32 number_bytes, max_events, max;
1149 struct mpt2_ioctl_eventreport __user *uarg = arg;
1150
1151 if (copy_from_user(&karg, arg, sizeof(karg))) {
1152 printk(KERN_ERR "failure at %s:%d/%s()!\n",
1153 __FILE__, __LINE__, __func__);
1154 return -EFAULT;
1155 }
1156 if (_ctl_verify_adapter(karg.hdr.ioc_number, &ioc) == -1 || !ioc)
1157 return -ENODEV;
1158
Kashyap, Desaieabb08a2010-06-17 13:43:57 +05301159 dctlprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: enter\n", ioc->name,
Eric Moore635374e2009-03-09 01:21:12 -06001160 __func__));
1161
1162 number_bytes = karg.hdr.max_data_size -
1163 sizeof(struct mpt2_ioctl_header);
1164 max_events = number_bytes/sizeof(struct MPT2_IOCTL_EVENTS);
1165 max = min_t(u32, MPT2SAS_CTL_EVENT_LOG_SIZE, max_events);
1166
1167 /* If fewer than 1 event is requested, there must have
1168 * been some type of error.
1169 */
1170 if (!max || !ioc->event_log)
1171 return -ENODATA;
1172
1173 number_bytes = max * sizeof(struct MPT2_IOCTL_EVENTS);
1174 if (copy_to_user(uarg->event_data, ioc->event_log, number_bytes)) {
1175 printk(KERN_ERR "failure at %s:%d/%s()!\n",
1176 __FILE__, __LINE__, __func__);
1177 return -EFAULT;
1178 }
1179
1180 /* reset flag so SIGIO can restart */
1181 ioc->aen_event_read_flag = 0;
1182 return 0;
1183}
1184
1185/**
1186 * _ctl_do_reset - main handler for MPT2HARDRESET opcode
1187 * @arg - user space buffer containing ioctl content
1188 */
1189static long
1190_ctl_do_reset(void __user *arg)
1191{
1192 struct mpt2_ioctl_diag_reset karg;
1193 struct MPT2SAS_ADAPTER *ioc;
1194 int retval;
1195
1196 if (copy_from_user(&karg, arg, sizeof(karg))) {
1197 printk(KERN_ERR "failure at %s:%d/%s()!\n",
1198 __FILE__, __LINE__, __func__);
1199 return -EFAULT;
1200 }
1201 if (_ctl_verify_adapter(karg.hdr.ioc_number, &ioc) == -1 || !ioc)
1202 return -ENODEV;
1203
Kashyap, Desaieabb08a2010-06-17 13:43:57 +05301204 dctlprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: enter\n", ioc->name,
Eric Moore635374e2009-03-09 01:21:12 -06001205 __func__));
1206
1207 retval = mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP,
1208 FORCE_BIG_HAMMER);
1209 printk(MPT2SAS_INFO_FMT "host reset: %s\n",
1210 ioc->name, ((!retval) ? "SUCCESS" : "FAILED"));
1211 return 0;
1212}
1213
1214/**
1215 * _ctl_btdh_search_sas_device - searching for sas device
1216 * @ioc: per adapter object
1217 * @btdh: btdh ioctl payload
1218 */
1219static int
1220_ctl_btdh_search_sas_device(struct MPT2SAS_ADAPTER *ioc,
1221 struct mpt2_ioctl_btdh_mapping *btdh)
1222{
1223 struct _sas_device *sas_device;
1224 unsigned long flags;
1225 int rc = 0;
1226
1227 if (list_empty(&ioc->sas_device_list))
1228 return rc;
1229
1230 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1231 list_for_each_entry(sas_device, &ioc->sas_device_list, list) {
1232 if (btdh->bus == 0xFFFFFFFF && btdh->id == 0xFFFFFFFF &&
1233 btdh->handle == sas_device->handle) {
1234 btdh->bus = sas_device->channel;
1235 btdh->id = sas_device->id;
1236 rc = 1;
1237 goto out;
1238 } else if (btdh->bus == sas_device->channel && btdh->id ==
1239 sas_device->id && btdh->handle == 0xFFFF) {
1240 btdh->handle = sas_device->handle;
1241 rc = 1;
1242 goto out;
1243 }
1244 }
1245 out:
1246 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1247 return rc;
1248}
1249
1250/**
1251 * _ctl_btdh_search_raid_device - searching for raid device
1252 * @ioc: per adapter object
1253 * @btdh: btdh ioctl payload
1254 */
1255static int
1256_ctl_btdh_search_raid_device(struct MPT2SAS_ADAPTER *ioc,
1257 struct mpt2_ioctl_btdh_mapping *btdh)
1258{
1259 struct _raid_device *raid_device;
1260 unsigned long flags;
1261 int rc = 0;
1262
1263 if (list_empty(&ioc->raid_device_list))
1264 return rc;
1265
1266 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1267 list_for_each_entry(raid_device, &ioc->raid_device_list, list) {
1268 if (btdh->bus == 0xFFFFFFFF && btdh->id == 0xFFFFFFFF &&
1269 btdh->handle == raid_device->handle) {
1270 btdh->bus = raid_device->channel;
1271 btdh->id = raid_device->id;
1272 rc = 1;
1273 goto out;
1274 } else if (btdh->bus == raid_device->channel && btdh->id ==
1275 raid_device->id && btdh->handle == 0xFFFF) {
1276 btdh->handle = raid_device->handle;
1277 rc = 1;
1278 goto out;
1279 }
1280 }
1281 out:
1282 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1283 return rc;
1284}
1285
1286/**
1287 * _ctl_btdh_mapping - main handler for MPT2BTDHMAPPING opcode
1288 * @arg - user space buffer containing ioctl content
1289 */
1290static long
1291_ctl_btdh_mapping(void __user *arg)
1292{
1293 struct mpt2_ioctl_btdh_mapping karg;
1294 struct MPT2SAS_ADAPTER *ioc;
1295 int rc;
1296
1297 if (copy_from_user(&karg, arg, sizeof(karg))) {
1298 printk(KERN_ERR "failure at %s:%d/%s()!\n",
1299 __FILE__, __LINE__, __func__);
1300 return -EFAULT;
1301 }
1302 if (_ctl_verify_adapter(karg.hdr.ioc_number, &ioc) == -1 || !ioc)
1303 return -ENODEV;
1304
Kashyap, Desaieabb08a2010-06-17 13:43:57 +05301305 dctlprintk(ioc, printk(MPT2SAS_INFO_FMT "%s\n", ioc->name,
Eric Moore635374e2009-03-09 01:21:12 -06001306 __func__));
1307
1308 rc = _ctl_btdh_search_sas_device(ioc, &karg);
1309 if (!rc)
1310 _ctl_btdh_search_raid_device(ioc, &karg);
1311
1312 if (copy_to_user(arg, &karg, sizeof(karg))) {
1313 printk(KERN_ERR "failure at %s:%d/%s()!\n",
1314 __FILE__, __LINE__, __func__);
1315 return -EFAULT;
1316 }
1317 return 0;
1318}
1319
1320/**
1321 * _ctl_diag_capability - return diag buffer capability
1322 * @ioc: per adapter object
Kashyap, Desai1b01fe32009-09-23 17:28:59 +05301323 * @buffer_type: specifies either TRACE, SNAPSHOT, or EXTENDED
Eric Moore635374e2009-03-09 01:21:12 -06001324 *
1325 * returns 1 when diag buffer support is enabled in firmware
1326 */
1327static u8
1328_ctl_diag_capability(struct MPT2SAS_ADAPTER *ioc, u8 buffer_type)
1329{
1330 u8 rc = 0;
1331
1332 switch (buffer_type) {
1333 case MPI2_DIAG_BUF_TYPE_TRACE:
1334 if (ioc->facts.IOCCapabilities &
1335 MPI2_IOCFACTS_CAPABILITY_DIAG_TRACE_BUFFER)
1336 rc = 1;
1337 break;
1338 case MPI2_DIAG_BUF_TYPE_SNAPSHOT:
1339 if (ioc->facts.IOCCapabilities &
1340 MPI2_IOCFACTS_CAPABILITY_SNAPSHOT_BUFFER)
1341 rc = 1;
1342 break;
Kashyap, Desai1b01fe32009-09-23 17:28:59 +05301343 case MPI2_DIAG_BUF_TYPE_EXTENDED:
1344 if (ioc->facts.IOCCapabilities &
1345 MPI2_IOCFACTS_CAPABILITY_EXTENDED_BUFFER)
1346 rc = 1;
Eric Moore635374e2009-03-09 01:21:12 -06001347 }
1348
1349 return rc;
1350}
1351
1352/**
Kashyap, Desai32e0eb52009-09-23 17:28:09 +05301353 * _ctl_diag_register_2 - wrapper for registering diag buffer support
1354 * @ioc: per adapter object
1355 * @diag_register: the diag_register struct passed in from user space
Eric Moore635374e2009-03-09 01:21:12 -06001356 *
Eric Moore635374e2009-03-09 01:21:12 -06001357 */
1358static long
Kashyap, Desai32e0eb52009-09-23 17:28:09 +05301359_ctl_diag_register_2(struct MPT2SAS_ADAPTER *ioc,
1360 struct mpt2_diag_register *diag_register)
Eric Moore635374e2009-03-09 01:21:12 -06001361{
Eric Moore635374e2009-03-09 01:21:12 -06001362 int rc, i;
1363 void *request_data = NULL;
1364 dma_addr_t request_data_dma;
1365 u32 request_data_sz = 0;
1366 Mpi2DiagBufferPostRequest_t *mpi_request;
1367 Mpi2DiagBufferPostReply_t *mpi_reply;
1368 u8 buffer_type;
1369 unsigned long timeleft;
1370 u16 smid;
1371 u16 ioc_status;
1372 u8 issue_reset = 0;
1373
Kashyap, Desaieabb08a2010-06-17 13:43:57 +05301374 dctlprintk(ioc, printk(MPT2SAS_INFO_FMT "%s\n", ioc->name,
Eric Moore635374e2009-03-09 01:21:12 -06001375 __func__));
1376
Kashyap, Desai32e0eb52009-09-23 17:28:09 +05301377 if (ioc->ctl_cmds.status != MPT2_CMD_NOT_USED) {
1378 printk(MPT2SAS_ERR_FMT "%s: ctl_cmd in use\n",
1379 ioc->name, __func__);
1380 rc = -EAGAIN;
1381 goto out;
1382 }
1383
1384 buffer_type = diag_register->buffer_type;
Eric Moore635374e2009-03-09 01:21:12 -06001385 if (!_ctl_diag_capability(ioc, buffer_type)) {
1386 printk(MPT2SAS_ERR_FMT "%s: doesn't have capability for "
1387 "buffer_type(0x%02x)\n", ioc->name, __func__, buffer_type);
1388 return -EPERM;
1389 }
1390
1391 if (ioc->diag_buffer_status[buffer_type] &
1392 MPT2_DIAG_BUFFER_IS_REGISTERED) {
1393 printk(MPT2SAS_ERR_FMT "%s: already has a registered "
1394 "buffer for buffer_type(0x%02x)\n", ioc->name, __func__,
1395 buffer_type);
1396 return -EINVAL;
1397 }
1398
Kashyap, Desai32e0eb52009-09-23 17:28:09 +05301399 if (diag_register->requested_buffer_size % 4) {
Eric Moore635374e2009-03-09 01:21:12 -06001400 printk(MPT2SAS_ERR_FMT "%s: the requested_buffer_size "
1401 "is not 4 byte aligned\n", ioc->name, __func__);
1402 return -EINVAL;
1403 }
1404
Eric Moore635374e2009-03-09 01:21:12 -06001405 smid = mpt2sas_base_get_smid(ioc, ioc->ctl_cb_idx);
1406 if (!smid) {
1407 printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n",
1408 ioc->name, __func__);
1409 rc = -EAGAIN;
1410 goto out;
1411 }
1412
1413 rc = 0;
1414 ioc->ctl_cmds.status = MPT2_CMD_PENDING;
1415 memset(ioc->ctl_cmds.reply, 0, ioc->reply_sz);
1416 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
1417 ioc->ctl_cmds.smid = smid;
1418
1419 request_data = ioc->diag_buffer[buffer_type];
Kashyap, Desai32e0eb52009-09-23 17:28:09 +05301420 request_data_sz = diag_register->requested_buffer_size;
1421 ioc->unique_id[buffer_type] = diag_register->unique_id;
Eric Moore635374e2009-03-09 01:21:12 -06001422 ioc->diag_buffer_status[buffer_type] = 0;
Kashyap, Desai32e0eb52009-09-23 17:28:09 +05301423 memcpy(ioc->product_specific[buffer_type],
1424 diag_register->product_specific, MPT2_PRODUCT_SPECIFIC_DWORDS);
1425 ioc->diagnostic_flags[buffer_type] = diag_register->diagnostic_flags;
Eric Moore635374e2009-03-09 01:21:12 -06001426
1427 if (request_data) {
1428 request_data_dma = ioc->diag_buffer_dma[buffer_type];
1429 if (request_data_sz != ioc->diag_buffer_sz[buffer_type]) {
1430 pci_free_consistent(ioc->pdev,
1431 ioc->diag_buffer_sz[buffer_type],
1432 request_data, request_data_dma);
1433 request_data = NULL;
1434 }
1435 }
1436
1437 if (request_data == NULL) {
1438 ioc->diag_buffer_sz[buffer_type] = 0;
1439 ioc->diag_buffer_dma[buffer_type] = 0;
1440 request_data = pci_alloc_consistent(
1441 ioc->pdev, request_data_sz, &request_data_dma);
1442 if (request_data == NULL) {
1443 printk(MPT2SAS_ERR_FMT "%s: failed allocating memory"
1444 " for diag buffers, requested size(%d)\n",
1445 ioc->name, __func__, request_data_sz);
1446 mpt2sas_base_free_smid(ioc, smid);
1447 return -ENOMEM;
1448 }
1449 ioc->diag_buffer[buffer_type] = request_data;
1450 ioc->diag_buffer_sz[buffer_type] = request_data_sz;
1451 ioc->diag_buffer_dma[buffer_type] = request_data_dma;
1452 }
1453
1454 mpi_request->Function = MPI2_FUNCTION_DIAG_BUFFER_POST;
Kashyap, Desai32e0eb52009-09-23 17:28:09 +05301455 mpi_request->BufferType = diag_register->buffer_type;
1456 mpi_request->Flags = cpu_to_le32(diag_register->diagnostic_flags);
Eric Moore635374e2009-03-09 01:21:12 -06001457 mpi_request->BufferAddress = cpu_to_le64(request_data_dma);
1458 mpi_request->BufferLength = cpu_to_le32(request_data_sz);
Kashyap, Desai7b936b02009-09-25 11:44:41 +05301459 mpi_request->VF_ID = 0; /* TODO */
1460 mpi_request->VP_ID = 0;
Eric Moore635374e2009-03-09 01:21:12 -06001461
Kashyap, Desaieabb08a2010-06-17 13:43:57 +05301462 dctlprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: diag_buffer(0x%p), "
Eric Moore635374e2009-03-09 01:21:12 -06001463 "dma(0x%llx), sz(%d)\n", ioc->name, __func__, request_data,
Kashyap, Desaie94f6742010-03-17 16:24:52 +05301464 (unsigned long long)request_data_dma,
1465 le32_to_cpu(mpi_request->BufferLength)));
Eric Moore635374e2009-03-09 01:21:12 -06001466
1467 for (i = 0; i < MPT2_PRODUCT_SPECIFIC_DWORDS; i++)
1468 mpi_request->ProductSpecific[i] =
1469 cpu_to_le32(ioc->product_specific[buffer_type][i]);
1470
Kashyap, Desai7b936b02009-09-25 11:44:41 +05301471 mpt2sas_base_put_smid_default(ioc, smid);
Kashyap, Desaibcfb6e62009-09-14 11:05:24 +05301472 init_completion(&ioc->ctl_cmds.done);
Eric Moore635374e2009-03-09 01:21:12 -06001473 timeleft = wait_for_completion_timeout(&ioc->ctl_cmds.done,
1474 MPT2_IOCTL_DEFAULT_TIMEOUT*HZ);
1475
1476 if (!(ioc->ctl_cmds.status & MPT2_CMD_COMPLETE)) {
1477 printk(MPT2SAS_ERR_FMT "%s: timeout\n", ioc->name,
1478 __func__);
1479 _debug_dump_mf(mpi_request,
1480 sizeof(Mpi2DiagBufferPostRequest_t)/4);
1481 if (!(ioc->ctl_cmds.status & MPT2_CMD_RESET))
1482 issue_reset = 1;
1483 goto issue_host_reset;
1484 }
1485
1486 /* process the completed Reply Message Frame */
1487 if ((ioc->ctl_cmds.status & MPT2_CMD_REPLY_VALID) == 0) {
1488 printk(MPT2SAS_ERR_FMT "%s: no reply message\n",
1489 ioc->name, __func__);
1490 rc = -EFAULT;
1491 goto out;
1492 }
1493
1494 mpi_reply = ioc->ctl_cmds.reply;
1495 ioc_status = le16_to_cpu(mpi_reply->IOCStatus) & MPI2_IOCSTATUS_MASK;
1496
1497 if (ioc_status == MPI2_IOCSTATUS_SUCCESS) {
1498 ioc->diag_buffer_status[buffer_type] |=
1499 MPT2_DIAG_BUFFER_IS_REGISTERED;
Kashyap, Desaieabb08a2010-06-17 13:43:57 +05301500 dctlprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: success\n",
Eric Moore635374e2009-03-09 01:21:12 -06001501 ioc->name, __func__));
1502 } else {
Kashyap, Desaieabb08a2010-06-17 13:43:57 +05301503 printk(MPT2SAS_INFO_FMT "%s: ioc_status(0x%04x) "
Eric Moore635374e2009-03-09 01:21:12 -06001504 "log_info(0x%08x)\n", ioc->name, __func__,
Kashyap, Desai463217b2009-10-05 15:53:06 +05301505 ioc_status, le32_to_cpu(mpi_reply->IOCLogInfo));
Eric Moore635374e2009-03-09 01:21:12 -06001506 rc = -EFAULT;
1507 }
1508
1509 issue_host_reset:
1510 if (issue_reset)
1511 mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP,
1512 FORCE_BIG_HAMMER);
1513
1514 out:
1515
1516 if (rc && request_data)
1517 pci_free_consistent(ioc->pdev, request_data_sz,
1518 request_data, request_data_dma);
1519
1520 ioc->ctl_cmds.status = MPT2_CMD_NOT_USED;
Kashyap, Desai32e0eb52009-09-23 17:28:09 +05301521 return rc;
1522}
1523
1524/**
1525 * mpt2sas_enable_diag_buffer - enabling diag_buffers support driver load time
1526 * @ioc: per adapter object
1527 * @bits_to_register: bitwise field where trace is bit 0, and snapshot is bit 1
1528 *
1529 * This is called when command line option diag_buffer_enable is enabled
1530 * at driver load time.
1531 */
1532void
1533mpt2sas_enable_diag_buffer(struct MPT2SAS_ADAPTER *ioc, u8 bits_to_register)
1534{
1535 struct mpt2_diag_register diag_register;
1536
1537 memset(&diag_register, 0, sizeof(struct mpt2_diag_register));
1538
1539 if (bits_to_register & 1) {
1540 printk(MPT2SAS_INFO_FMT "registering trace buffer support\n",
1541 ioc->name);
1542 diag_register.buffer_type = MPI2_DIAG_BUF_TYPE_TRACE;
1543 /* register for 1MB buffers */
1544 diag_register.requested_buffer_size = (1024 * 1024);
1545 diag_register.unique_id = 0x7075900;
1546 _ctl_diag_register_2(ioc, &diag_register);
1547 }
1548
1549 if (bits_to_register & 2) {
1550 printk(MPT2SAS_INFO_FMT "registering snapshot buffer support\n",
1551 ioc->name);
1552 diag_register.buffer_type = MPI2_DIAG_BUF_TYPE_SNAPSHOT;
1553 /* register for 2MB buffers */
1554 diag_register.requested_buffer_size = 2 * (1024 * 1024);
1555 diag_register.unique_id = 0x7075901;
1556 _ctl_diag_register_2(ioc, &diag_register);
1557 }
Kashyap, Desai1b01fe32009-09-23 17:28:59 +05301558
1559 if (bits_to_register & 4) {
1560 printk(MPT2SAS_INFO_FMT "registering extended buffer support\n",
1561 ioc->name);
1562 diag_register.buffer_type = MPI2_DIAG_BUF_TYPE_EXTENDED;
1563 /* register for 2MB buffers */
1564 diag_register.requested_buffer_size = 2 * (1024 * 1024);
1565 diag_register.unique_id = 0x7075901;
1566 _ctl_diag_register_2(ioc, &diag_register);
1567 }
Kashyap, Desai32e0eb52009-09-23 17:28:09 +05301568}
1569
1570/**
1571 * _ctl_diag_register - application register with driver
1572 * @arg - user space buffer containing ioctl content
1573 * @state - NON_BLOCKING or BLOCKING
1574 *
1575 * This will allow the driver to setup any required buffers that will be
1576 * needed by firmware to communicate with the driver.
1577 */
1578static long
1579_ctl_diag_register(void __user *arg, enum block_state state)
1580{
1581 struct mpt2_diag_register karg;
1582 struct MPT2SAS_ADAPTER *ioc;
1583 long rc;
1584
1585 if (copy_from_user(&karg, arg, sizeof(karg))) {
1586 printk(KERN_ERR "failure at %s:%d/%s()!\n",
1587 __FILE__, __LINE__, __func__);
1588 return -EFAULT;
1589 }
1590 if (_ctl_verify_adapter(karg.hdr.ioc_number, &ioc) == -1 || !ioc)
1591 return -ENODEV;
1592
1593 if (state == NON_BLOCKING && !mutex_trylock(&ioc->ctl_cmds.mutex))
1594 return -EAGAIN;
1595 else if (mutex_lock_interruptible(&ioc->ctl_cmds.mutex))
1596 return -ERESTARTSYS;
1597 rc = _ctl_diag_register_2(ioc, &karg);
Eric Moore635374e2009-03-09 01:21:12 -06001598 mutex_unlock(&ioc->ctl_cmds.mutex);
1599 return rc;
1600}
1601
1602/**
1603 * _ctl_diag_unregister - application unregister with driver
1604 * @arg - user space buffer containing ioctl content
1605 *
1606 * This will allow the driver to cleanup any memory allocated for diag
1607 * messages and to free up any resources.
1608 */
1609static long
1610_ctl_diag_unregister(void __user *arg)
1611{
1612 struct mpt2_diag_unregister karg;
1613 struct MPT2SAS_ADAPTER *ioc;
1614 void *request_data;
1615 dma_addr_t request_data_dma;
1616 u32 request_data_sz;
1617 u8 buffer_type;
1618
1619 if (copy_from_user(&karg, arg, sizeof(karg))) {
1620 printk(KERN_ERR "failure at %s:%d/%s()!\n",
1621 __FILE__, __LINE__, __func__);
1622 return -EFAULT;
1623 }
1624 if (_ctl_verify_adapter(karg.hdr.ioc_number, &ioc) == -1 || !ioc)
1625 return -ENODEV;
1626
Kashyap, Desaieabb08a2010-06-17 13:43:57 +05301627 dctlprintk(ioc, printk(MPT2SAS_INFO_FMT "%s\n", ioc->name,
Eric Moore635374e2009-03-09 01:21:12 -06001628 __func__));
1629
1630 buffer_type = karg.unique_id & 0x000000ff;
1631 if (!_ctl_diag_capability(ioc, buffer_type)) {
1632 printk(MPT2SAS_ERR_FMT "%s: doesn't have capability for "
1633 "buffer_type(0x%02x)\n", ioc->name, __func__, buffer_type);
1634 return -EPERM;
1635 }
1636
1637 if ((ioc->diag_buffer_status[buffer_type] &
1638 MPT2_DIAG_BUFFER_IS_REGISTERED) == 0) {
1639 printk(MPT2SAS_ERR_FMT "%s: buffer_type(0x%02x) is not "
1640 "registered\n", ioc->name, __func__, buffer_type);
1641 return -EINVAL;
1642 }
1643 if ((ioc->diag_buffer_status[buffer_type] &
1644 MPT2_DIAG_BUFFER_IS_RELEASED) == 0) {
1645 printk(MPT2SAS_ERR_FMT "%s: buffer_type(0x%02x) has not been "
1646 "released\n", ioc->name, __func__, buffer_type);
1647 return -EINVAL;
1648 }
1649
1650 if (karg.unique_id != ioc->unique_id[buffer_type]) {
1651 printk(MPT2SAS_ERR_FMT "%s: unique_id(0x%08x) is not "
1652 "registered\n", ioc->name, __func__, karg.unique_id);
1653 return -EINVAL;
1654 }
1655
1656 request_data = ioc->diag_buffer[buffer_type];
1657 if (!request_data) {
1658 printk(MPT2SAS_ERR_FMT "%s: doesn't have memory allocated for "
1659 "buffer_type(0x%02x)\n", ioc->name, __func__, buffer_type);
1660 return -ENOMEM;
1661 }
1662
1663 request_data_sz = ioc->diag_buffer_sz[buffer_type];
1664 request_data_dma = ioc->diag_buffer_dma[buffer_type];
1665 pci_free_consistent(ioc->pdev, request_data_sz,
1666 request_data, request_data_dma);
1667 ioc->diag_buffer[buffer_type] = NULL;
1668 ioc->diag_buffer_status[buffer_type] = 0;
1669 return 0;
1670}
1671
1672/**
1673 * _ctl_diag_query - query relevant info associated with diag buffers
1674 * @arg - user space buffer containing ioctl content
1675 *
1676 * The application will send only buffer_type and unique_id. Driver will
1677 * inspect unique_id first, if valid, fill in all the info. If unique_id is
1678 * 0x00, the driver will return info specified by Buffer Type.
1679 */
1680static long
1681_ctl_diag_query(void __user *arg)
1682{
1683 struct mpt2_diag_query karg;
1684 struct MPT2SAS_ADAPTER *ioc;
1685 void *request_data;
1686 int i;
1687 u8 buffer_type;
1688
1689 if (copy_from_user(&karg, arg, sizeof(karg))) {
1690 printk(KERN_ERR "failure at %s:%d/%s()!\n",
1691 __FILE__, __LINE__, __func__);
1692 return -EFAULT;
1693 }
1694 if (_ctl_verify_adapter(karg.hdr.ioc_number, &ioc) == -1 || !ioc)
1695 return -ENODEV;
1696
Kashyap, Desaieabb08a2010-06-17 13:43:57 +05301697 dctlprintk(ioc, printk(MPT2SAS_INFO_FMT "%s\n", ioc->name,
Eric Moore635374e2009-03-09 01:21:12 -06001698 __func__));
1699
1700 karg.application_flags = 0;
1701 buffer_type = karg.buffer_type;
1702
1703 if (!_ctl_diag_capability(ioc, buffer_type)) {
1704 printk(MPT2SAS_ERR_FMT "%s: doesn't have capability for "
1705 "buffer_type(0x%02x)\n", ioc->name, __func__, buffer_type);
1706 return -EPERM;
1707 }
1708
1709 if ((ioc->diag_buffer_status[buffer_type] &
1710 MPT2_DIAG_BUFFER_IS_REGISTERED) == 0) {
1711 printk(MPT2SAS_ERR_FMT "%s: buffer_type(0x%02x) is not "
1712 "registered\n", ioc->name, __func__, buffer_type);
1713 return -EINVAL;
1714 }
1715
1716 if (karg.unique_id & 0xffffff00) {
1717 if (karg.unique_id != ioc->unique_id[buffer_type]) {
1718 printk(MPT2SAS_ERR_FMT "%s: unique_id(0x%08x) is not "
1719 "registered\n", ioc->name, __func__,
1720 karg.unique_id);
1721 return -EINVAL;
1722 }
1723 }
1724
1725 request_data = ioc->diag_buffer[buffer_type];
1726 if (!request_data) {
1727 printk(MPT2SAS_ERR_FMT "%s: doesn't have buffer for "
1728 "buffer_type(0x%02x)\n", ioc->name, __func__, buffer_type);
1729 return -ENOMEM;
1730 }
1731
1732 if (ioc->diag_buffer_status[buffer_type] & MPT2_DIAG_BUFFER_IS_RELEASED)
1733 karg.application_flags = (MPT2_APP_FLAGS_APP_OWNED |
1734 MPT2_APP_FLAGS_BUFFER_VALID);
1735 else
1736 karg.application_flags = (MPT2_APP_FLAGS_APP_OWNED |
1737 MPT2_APP_FLAGS_BUFFER_VALID |
1738 MPT2_APP_FLAGS_FW_BUFFER_ACCESS);
1739
1740 for (i = 0; i < MPT2_PRODUCT_SPECIFIC_DWORDS; i++)
1741 karg.product_specific[i] =
1742 ioc->product_specific[buffer_type][i];
1743
1744 karg.total_buffer_size = ioc->diag_buffer_sz[buffer_type];
1745 karg.driver_added_buffer_size = 0;
1746 karg.unique_id = ioc->unique_id[buffer_type];
1747 karg.diagnostic_flags = ioc->diagnostic_flags[buffer_type];
1748
1749 if (copy_to_user(arg, &karg, sizeof(struct mpt2_diag_query))) {
1750 printk(MPT2SAS_ERR_FMT "%s: unable to write mpt2_diag_query "
1751 "data @ %p\n", ioc->name, __func__, arg);
1752 return -EFAULT;
1753 }
1754 return 0;
1755}
1756
1757/**
Eric Moore99bb2142009-04-21 15:42:13 -06001758 * _ctl_send_release - Diag Release Message
1759 * @ioc: per adapter object
Kashyap, Desai1b01fe32009-09-23 17:28:59 +05301760 * @buffer_type - specifies either TRACE, SNAPSHOT, or EXTENDED
Eric Moore99bb2142009-04-21 15:42:13 -06001761 * @issue_reset - specifies whether host reset is required.
1762 *
1763 */
1764static int
1765_ctl_send_release(struct MPT2SAS_ADAPTER *ioc, u8 buffer_type, u8 *issue_reset)
1766{
1767 Mpi2DiagReleaseRequest_t *mpi_request;
1768 Mpi2DiagReleaseReply_t *mpi_reply;
1769 u16 smid;
1770 u16 ioc_status;
1771 u32 ioc_state;
1772 int rc;
1773 unsigned long timeleft;
1774
Kashyap, Desaieabb08a2010-06-17 13:43:57 +05301775 dctlprintk(ioc, printk(MPT2SAS_INFO_FMT "%s\n", ioc->name,
Eric Moore99bb2142009-04-21 15:42:13 -06001776 __func__));
1777
1778 rc = 0;
1779 *issue_reset = 0;
1780
1781 ioc_state = mpt2sas_base_get_iocstate(ioc, 1);
1782 if (ioc_state != MPI2_IOC_STATE_OPERATIONAL) {
Kashyap, Desaieabb08a2010-06-17 13:43:57 +05301783 dctlprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: "
Eric Moore99bb2142009-04-21 15:42:13 -06001784 "skipping due to FAULT state\n", ioc->name,
1785 __func__));
1786 rc = -EAGAIN;
1787 goto out;
1788 }
1789
1790 if (ioc->ctl_cmds.status != MPT2_CMD_NOT_USED) {
1791 printk(MPT2SAS_ERR_FMT "%s: ctl_cmd in use\n",
1792 ioc->name, __func__);
1793 rc = -EAGAIN;
1794 goto out;
1795 }
1796
1797 smid = mpt2sas_base_get_smid(ioc, ioc->ctl_cb_idx);
1798 if (!smid) {
1799 printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n",
1800 ioc->name, __func__);
1801 rc = -EAGAIN;
1802 goto out;
1803 }
1804
1805 ioc->ctl_cmds.status = MPT2_CMD_PENDING;
1806 memset(ioc->ctl_cmds.reply, 0, ioc->reply_sz);
1807 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
1808 ioc->ctl_cmds.smid = smid;
1809
1810 mpi_request->Function = MPI2_FUNCTION_DIAG_RELEASE;
1811 mpi_request->BufferType = buffer_type;
Kashyap, Desai7b936b02009-09-25 11:44:41 +05301812 mpi_request->VF_ID = 0; /* TODO */
1813 mpi_request->VP_ID = 0;
Eric Moore99bb2142009-04-21 15:42:13 -06001814
Kashyap, Desai7b936b02009-09-25 11:44:41 +05301815 mpt2sas_base_put_smid_default(ioc, smid);
Kashyap, Desaibcfb6e62009-09-14 11:05:24 +05301816 init_completion(&ioc->ctl_cmds.done);
Eric Moore99bb2142009-04-21 15:42:13 -06001817 timeleft = wait_for_completion_timeout(&ioc->ctl_cmds.done,
1818 MPT2_IOCTL_DEFAULT_TIMEOUT*HZ);
1819
1820 if (!(ioc->ctl_cmds.status & MPT2_CMD_COMPLETE)) {
1821 printk(MPT2SAS_ERR_FMT "%s: timeout\n", ioc->name,
1822 __func__);
1823 _debug_dump_mf(mpi_request,
1824 sizeof(Mpi2DiagReleaseRequest_t)/4);
1825 if (!(ioc->ctl_cmds.status & MPT2_CMD_RESET))
1826 *issue_reset = 1;
1827 rc = -EFAULT;
1828 goto out;
1829 }
1830
1831 /* process the completed Reply Message Frame */
1832 if ((ioc->ctl_cmds.status & MPT2_CMD_REPLY_VALID) == 0) {
1833 printk(MPT2SAS_ERR_FMT "%s: no reply message\n",
1834 ioc->name, __func__);
1835 rc = -EFAULT;
1836 goto out;
1837 }
1838
1839 mpi_reply = ioc->ctl_cmds.reply;
1840 ioc_status = le16_to_cpu(mpi_reply->IOCStatus) & MPI2_IOCSTATUS_MASK;
1841
1842 if (ioc_status == MPI2_IOCSTATUS_SUCCESS) {
1843 ioc->diag_buffer_status[buffer_type] |=
1844 MPT2_DIAG_BUFFER_IS_RELEASED;
Kashyap, Desaieabb08a2010-06-17 13:43:57 +05301845 dctlprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: success\n",
Eric Moore99bb2142009-04-21 15:42:13 -06001846 ioc->name, __func__));
1847 } else {
Kashyap, Desaieabb08a2010-06-17 13:43:57 +05301848 printk(MPT2SAS_INFO_FMT "%s: ioc_status(0x%04x) "
Eric Moore99bb2142009-04-21 15:42:13 -06001849 "log_info(0x%08x)\n", ioc->name, __func__,
Kashyap, Desai463217b2009-10-05 15:53:06 +05301850 ioc_status, le32_to_cpu(mpi_reply->IOCLogInfo));
Eric Moore99bb2142009-04-21 15:42:13 -06001851 rc = -EFAULT;
1852 }
1853
1854 out:
1855 ioc->ctl_cmds.status = MPT2_CMD_NOT_USED;
1856 return rc;
1857}
1858
1859/**
Eric Moore635374e2009-03-09 01:21:12 -06001860 * _ctl_diag_release - request to send Diag Release Message to firmware
1861 * @arg - user space buffer containing ioctl content
1862 * @state - NON_BLOCKING or BLOCKING
1863 *
1864 * This allows ownership of the specified buffer to returned to the driver,
1865 * allowing an application to read the buffer without fear that firmware is
1866 * overwritting information in the buffer.
1867 */
1868static long
1869_ctl_diag_release(void __user *arg, enum block_state state)
1870{
1871 struct mpt2_diag_release karg;
1872 struct MPT2SAS_ADAPTER *ioc;
1873 void *request_data;
1874 int rc;
Eric Moore635374e2009-03-09 01:21:12 -06001875 u8 buffer_type;
Eric Moore635374e2009-03-09 01:21:12 -06001876 u8 issue_reset = 0;
1877
1878 if (copy_from_user(&karg, arg, sizeof(karg))) {
1879 printk(KERN_ERR "failure at %s:%d/%s()!\n",
1880 __FILE__, __LINE__, __func__);
1881 return -EFAULT;
1882 }
1883 if (_ctl_verify_adapter(karg.hdr.ioc_number, &ioc) == -1 || !ioc)
1884 return -ENODEV;
1885
Kashyap, Desaieabb08a2010-06-17 13:43:57 +05301886 dctlprintk(ioc, printk(MPT2SAS_INFO_FMT "%s\n", ioc->name,
Eric Moore635374e2009-03-09 01:21:12 -06001887 __func__));
1888
1889 buffer_type = karg.unique_id & 0x000000ff;
1890 if (!_ctl_diag_capability(ioc, buffer_type)) {
1891 printk(MPT2SAS_ERR_FMT "%s: doesn't have capability for "
1892 "buffer_type(0x%02x)\n", ioc->name, __func__, buffer_type);
1893 return -EPERM;
1894 }
1895
1896 if ((ioc->diag_buffer_status[buffer_type] &
1897 MPT2_DIAG_BUFFER_IS_REGISTERED) == 0) {
1898 printk(MPT2SAS_ERR_FMT "%s: buffer_type(0x%02x) is not "
1899 "registered\n", ioc->name, __func__, buffer_type);
1900 return -EINVAL;
1901 }
1902
1903 if (karg.unique_id != ioc->unique_id[buffer_type]) {
1904 printk(MPT2SAS_ERR_FMT "%s: unique_id(0x%08x) is not "
1905 "registered\n", ioc->name, __func__, karg.unique_id);
1906 return -EINVAL;
1907 }
1908
1909 if (ioc->diag_buffer_status[buffer_type] &
1910 MPT2_DIAG_BUFFER_IS_RELEASED) {
1911 printk(MPT2SAS_ERR_FMT "%s: buffer_type(0x%02x) "
1912 "is already released\n", ioc->name, __func__,
1913 buffer_type);
1914 return 0;
1915 }
1916
1917 request_data = ioc->diag_buffer[buffer_type];
1918
1919 if (!request_data) {
1920 printk(MPT2SAS_ERR_FMT "%s: doesn't have memory allocated for "
1921 "buffer_type(0x%02x)\n", ioc->name, __func__, buffer_type);
1922 return -ENOMEM;
1923 }
1924
Eric Moore99bb2142009-04-21 15:42:13 -06001925 /* buffers were released by due to host reset */
1926 if ((ioc->diag_buffer_status[buffer_type] &
1927 MPT2_DIAG_BUFFER_IS_DIAG_RESET)) {
1928 ioc->diag_buffer_status[buffer_type] |=
1929 MPT2_DIAG_BUFFER_IS_RELEASED;
1930 ioc->diag_buffer_status[buffer_type] &=
1931 ~MPT2_DIAG_BUFFER_IS_DIAG_RESET;
1932 printk(MPT2SAS_ERR_FMT "%s: buffer_type(0x%02x) "
1933 "was released due to host reset\n", ioc->name, __func__,
1934 buffer_type);
1935 return 0;
1936 }
1937
Eric Moore635374e2009-03-09 01:21:12 -06001938 if (state == NON_BLOCKING && !mutex_trylock(&ioc->ctl_cmds.mutex))
1939 return -EAGAIN;
1940 else if (mutex_lock_interruptible(&ioc->ctl_cmds.mutex))
1941 return -ERESTARTSYS;
1942
Eric Moore99bb2142009-04-21 15:42:13 -06001943 rc = _ctl_send_release(ioc, buffer_type, &issue_reset);
Eric Moore635374e2009-03-09 01:21:12 -06001944
Eric Moore635374e2009-03-09 01:21:12 -06001945 if (issue_reset)
1946 mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP,
1947 FORCE_BIG_HAMMER);
1948
Eric Moore635374e2009-03-09 01:21:12 -06001949 mutex_unlock(&ioc->ctl_cmds.mutex);
1950 return rc;
1951}
1952
1953/**
1954 * _ctl_diag_read_buffer - request for copy of the diag buffer
1955 * @arg - user space buffer containing ioctl content
1956 * @state - NON_BLOCKING or BLOCKING
1957 */
1958static long
1959_ctl_diag_read_buffer(void __user *arg, enum block_state state)
1960{
1961 struct mpt2_diag_read_buffer karg;
1962 struct mpt2_diag_read_buffer __user *uarg = arg;
1963 struct MPT2SAS_ADAPTER *ioc;
1964 void *request_data, *diag_data;
1965 Mpi2DiagBufferPostRequest_t *mpi_request;
1966 Mpi2DiagBufferPostReply_t *mpi_reply;
1967 int rc, i;
1968 u8 buffer_type;
1969 unsigned long timeleft;
1970 u16 smid;
1971 u16 ioc_status;
1972 u8 issue_reset = 0;
1973
1974 if (copy_from_user(&karg, arg, sizeof(karg))) {
1975 printk(KERN_ERR "failure at %s:%d/%s()!\n",
1976 __FILE__, __LINE__, __func__);
1977 return -EFAULT;
1978 }
1979 if (_ctl_verify_adapter(karg.hdr.ioc_number, &ioc) == -1 || !ioc)
1980 return -ENODEV;
1981
Kashyap, Desaieabb08a2010-06-17 13:43:57 +05301982 dctlprintk(ioc, printk(MPT2SAS_INFO_FMT "%s\n", ioc->name,
Eric Moore635374e2009-03-09 01:21:12 -06001983 __func__));
1984
1985 buffer_type = karg.unique_id & 0x000000ff;
1986 if (!_ctl_diag_capability(ioc, buffer_type)) {
1987 printk(MPT2SAS_ERR_FMT "%s: doesn't have capability for "
1988 "buffer_type(0x%02x)\n", ioc->name, __func__, buffer_type);
1989 return -EPERM;
1990 }
1991
1992 if (karg.unique_id != ioc->unique_id[buffer_type]) {
1993 printk(MPT2SAS_ERR_FMT "%s: unique_id(0x%08x) is not "
1994 "registered\n", ioc->name, __func__, karg.unique_id);
1995 return -EINVAL;
1996 }
1997
1998 request_data = ioc->diag_buffer[buffer_type];
1999 if (!request_data) {
2000 printk(MPT2SAS_ERR_FMT "%s: doesn't have buffer for "
2001 "buffer_type(0x%02x)\n", ioc->name, __func__, buffer_type);
2002 return -ENOMEM;
2003 }
2004
2005 if ((karg.starting_offset % 4) || (karg.bytes_to_read % 4)) {
2006 printk(MPT2SAS_ERR_FMT "%s: either the starting_offset "
2007 "or bytes_to_read are not 4 byte aligned\n", ioc->name,
2008 __func__);
2009 return -EINVAL;
2010 }
2011
2012 diag_data = (void *)(request_data + karg.starting_offset);
Kashyap, Desaieabb08a2010-06-17 13:43:57 +05302013 dctlprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: diag_buffer(%p), "
Eric Moore635374e2009-03-09 01:21:12 -06002014 "offset(%d), sz(%d)\n", ioc->name, __func__,
2015 diag_data, karg.starting_offset, karg.bytes_to_read));
2016
2017 if (copy_to_user((void __user *)uarg->diagnostic_data,
2018 diag_data, karg.bytes_to_read)) {
2019 printk(MPT2SAS_ERR_FMT "%s: Unable to write "
2020 "mpt_diag_read_buffer_t data @ %p\n", ioc->name,
2021 __func__, diag_data);
2022 return -EFAULT;
2023 }
2024
2025 if ((karg.flags & MPT2_FLAGS_REREGISTER) == 0)
2026 return 0;
2027
Kashyap, Desaieabb08a2010-06-17 13:43:57 +05302028 dctlprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: Reregister "
Eric Moore635374e2009-03-09 01:21:12 -06002029 "buffer_type(0x%02x)\n", ioc->name, __func__, buffer_type));
2030 if ((ioc->diag_buffer_status[buffer_type] &
2031 MPT2_DIAG_BUFFER_IS_RELEASED) == 0) {
Kashyap, Desaieabb08a2010-06-17 13:43:57 +05302032 dctlprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: "
Eric Moore635374e2009-03-09 01:21:12 -06002033 "buffer_type(0x%02x) is still registered\n", ioc->name,
2034 __func__, buffer_type));
2035 return 0;
2036 }
2037 /* Get a free request frame and save the message context.
2038 */
2039 if (state == NON_BLOCKING && !mutex_trylock(&ioc->ctl_cmds.mutex))
2040 return -EAGAIN;
2041 else if (mutex_lock_interruptible(&ioc->ctl_cmds.mutex))
2042 return -ERESTARTSYS;
2043
2044 if (ioc->ctl_cmds.status != MPT2_CMD_NOT_USED) {
2045 printk(MPT2SAS_ERR_FMT "%s: ctl_cmd in use\n",
2046 ioc->name, __func__);
2047 rc = -EAGAIN;
2048 goto out;
2049 }
2050
2051 smid = mpt2sas_base_get_smid(ioc, ioc->ctl_cb_idx);
2052 if (!smid) {
2053 printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n",
2054 ioc->name, __func__);
2055 rc = -EAGAIN;
2056 goto out;
2057 }
2058
2059 rc = 0;
2060 ioc->ctl_cmds.status = MPT2_CMD_PENDING;
2061 memset(ioc->ctl_cmds.reply, 0, ioc->reply_sz);
2062 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
2063 ioc->ctl_cmds.smid = smid;
2064
2065 mpi_request->Function = MPI2_FUNCTION_DIAG_BUFFER_POST;
2066 mpi_request->BufferType = buffer_type;
2067 mpi_request->BufferLength =
2068 cpu_to_le32(ioc->diag_buffer_sz[buffer_type]);
2069 mpi_request->BufferAddress =
2070 cpu_to_le64(ioc->diag_buffer_dma[buffer_type]);
2071 for (i = 0; i < MPT2_PRODUCT_SPECIFIC_DWORDS; i++)
2072 mpi_request->ProductSpecific[i] =
2073 cpu_to_le32(ioc->product_specific[buffer_type][i]);
Kashyap, Desai7b936b02009-09-25 11:44:41 +05302074 mpi_request->VF_ID = 0; /* TODO */
2075 mpi_request->VP_ID = 0;
Eric Moore635374e2009-03-09 01:21:12 -06002076
Kashyap, Desai7b936b02009-09-25 11:44:41 +05302077 mpt2sas_base_put_smid_default(ioc, smid);
Kashyap, Desaibcfb6e62009-09-14 11:05:24 +05302078 init_completion(&ioc->ctl_cmds.done);
Eric Moore635374e2009-03-09 01:21:12 -06002079 timeleft = wait_for_completion_timeout(&ioc->ctl_cmds.done,
2080 MPT2_IOCTL_DEFAULT_TIMEOUT*HZ);
2081
2082 if (!(ioc->ctl_cmds.status & MPT2_CMD_COMPLETE)) {
2083 printk(MPT2SAS_ERR_FMT "%s: timeout\n", ioc->name,
2084 __func__);
2085 _debug_dump_mf(mpi_request,
2086 sizeof(Mpi2DiagBufferPostRequest_t)/4);
2087 if (!(ioc->ctl_cmds.status & MPT2_CMD_RESET))
2088 issue_reset = 1;
2089 goto issue_host_reset;
2090 }
2091
2092 /* process the completed Reply Message Frame */
2093 if ((ioc->ctl_cmds.status & MPT2_CMD_REPLY_VALID) == 0) {
2094 printk(MPT2SAS_ERR_FMT "%s: no reply message\n",
2095 ioc->name, __func__);
2096 rc = -EFAULT;
2097 goto out;
2098 }
2099
2100 mpi_reply = ioc->ctl_cmds.reply;
2101 ioc_status = le16_to_cpu(mpi_reply->IOCStatus) & MPI2_IOCSTATUS_MASK;
2102
2103 if (ioc_status == MPI2_IOCSTATUS_SUCCESS) {
2104 ioc->diag_buffer_status[buffer_type] |=
2105 MPT2_DIAG_BUFFER_IS_REGISTERED;
Kashyap, Desaieabb08a2010-06-17 13:43:57 +05302106 dctlprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: success\n",
Eric Moore635374e2009-03-09 01:21:12 -06002107 ioc->name, __func__));
2108 } else {
Kashyap, Desaieabb08a2010-06-17 13:43:57 +05302109 printk(MPT2SAS_INFO_FMT "%s: ioc_status(0x%04x) "
Eric Moore635374e2009-03-09 01:21:12 -06002110 "log_info(0x%08x)\n", ioc->name, __func__,
Kashyap, Desai463217b2009-10-05 15:53:06 +05302111 ioc_status, le32_to_cpu(mpi_reply->IOCLogInfo));
Eric Moore635374e2009-03-09 01:21:12 -06002112 rc = -EFAULT;
2113 }
2114
2115 issue_host_reset:
2116 if (issue_reset)
2117 mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP,
2118 FORCE_BIG_HAMMER);
2119
2120 out:
2121
2122 ioc->ctl_cmds.status = MPT2_CMD_NOT_USED;
2123 mutex_unlock(&ioc->ctl_cmds.mutex);
2124 return rc;
2125}
2126
2127/**
2128 * _ctl_ioctl_main - main ioctl entry point
2129 * @file - (struct file)
2130 * @cmd - ioctl opcode
2131 * @arg -
2132 */
2133static long
2134_ctl_ioctl_main(struct file *file, unsigned int cmd, void __user *arg)
2135{
2136 enum block_state state;
2137 long ret = -EINVAL;
Eric Moore635374e2009-03-09 01:21:12 -06002138
2139 state = (file->f_flags & O_NONBLOCK) ? NON_BLOCKING :
2140 BLOCKING;
2141
2142 switch (cmd) {
2143 case MPT2IOCINFO:
2144 if (_IOC_SIZE(cmd) == sizeof(struct mpt2_ioctl_iocinfo))
2145 ret = _ctl_getiocinfo(arg);
2146 break;
2147 case MPT2COMMAND:
2148 {
2149 struct mpt2_ioctl_command karg;
2150 struct mpt2_ioctl_command __user *uarg;
2151 struct MPT2SAS_ADAPTER *ioc;
2152
2153 if (copy_from_user(&karg, arg, sizeof(karg))) {
2154 printk(KERN_ERR "failure at %s:%d/%s()!\n",
2155 __FILE__, __LINE__, __func__);
2156 return -EFAULT;
2157 }
2158
2159 if (_ctl_verify_adapter(karg.hdr.ioc_number, &ioc) == -1 ||
2160 !ioc)
2161 return -ENODEV;
2162
Eric Moore3cb54692010-07-08 14:44:34 -06002163 if (ioc->shost_recovery || ioc->pci_error_recovery)
Eric Moore635374e2009-03-09 01:21:12 -06002164 return -EAGAIN;
Eric Moore635374e2009-03-09 01:21:12 -06002165
2166 if (_IOC_SIZE(cmd) == sizeof(struct mpt2_ioctl_command)) {
2167 uarg = arg;
2168 ret = _ctl_do_mpt_command(ioc, karg, &uarg->mf, state);
2169 }
2170 break;
2171 }
2172 case MPT2EVENTQUERY:
2173 if (_IOC_SIZE(cmd) == sizeof(struct mpt2_ioctl_eventquery))
2174 ret = _ctl_eventquery(arg);
2175 break;
2176 case MPT2EVENTENABLE:
2177 if (_IOC_SIZE(cmd) == sizeof(struct mpt2_ioctl_eventenable))
2178 ret = _ctl_eventenable(arg);
2179 break;
2180 case MPT2EVENTREPORT:
2181 ret = _ctl_eventreport(arg);
2182 break;
2183 case MPT2HARDRESET:
2184 if (_IOC_SIZE(cmd) == sizeof(struct mpt2_ioctl_diag_reset))
2185 ret = _ctl_do_reset(arg);
2186 break;
2187 case MPT2BTDHMAPPING:
2188 if (_IOC_SIZE(cmd) == sizeof(struct mpt2_ioctl_btdh_mapping))
2189 ret = _ctl_btdh_mapping(arg);
2190 break;
2191 case MPT2DIAGREGISTER:
2192 if (_IOC_SIZE(cmd) == sizeof(struct mpt2_diag_register))
2193 ret = _ctl_diag_register(arg, state);
2194 break;
2195 case MPT2DIAGUNREGISTER:
2196 if (_IOC_SIZE(cmd) == sizeof(struct mpt2_diag_unregister))
2197 ret = _ctl_diag_unregister(arg);
2198 break;
2199 case MPT2DIAGQUERY:
2200 if (_IOC_SIZE(cmd) == sizeof(struct mpt2_diag_query))
2201 ret = _ctl_diag_query(arg);
2202 break;
2203 case MPT2DIAGRELEASE:
2204 if (_IOC_SIZE(cmd) == sizeof(struct mpt2_diag_release))
2205 ret = _ctl_diag_release(arg, state);
2206 break;
2207 case MPT2DIAGREADBUFFER:
2208 if (_IOC_SIZE(cmd) == sizeof(struct mpt2_diag_read_buffer))
2209 ret = _ctl_diag_read_buffer(arg, state);
2210 break;
2211 default:
2212 {
2213 struct mpt2_ioctl_command karg;
2214 struct MPT2SAS_ADAPTER *ioc;
2215
2216 if (copy_from_user(&karg, arg, sizeof(karg))) {
2217 printk(KERN_ERR "failure at %s:%d/%s()!\n",
2218 __FILE__, __LINE__, __func__);
2219 return -EFAULT;
2220 }
2221
2222 if (_ctl_verify_adapter(karg.hdr.ioc_number, &ioc) == -1 ||
2223 !ioc)
2224 return -ENODEV;
2225
Kashyap, Desaieabb08a2010-06-17 13:43:57 +05302226 dctlprintk(ioc, printk(MPT2SAS_INFO_FMT
Eric Moore635374e2009-03-09 01:21:12 -06002227 "unsupported ioctl opcode(0x%08x)\n", ioc->name, cmd));
2228 break;
2229 }
2230 }
2231 return ret;
2232}
2233
2234/**
2235 * _ctl_ioctl - main ioctl entry point (unlocked)
2236 * @file - (struct file)
2237 * @cmd - ioctl opcode
2238 * @arg -
2239 */
2240static long
2241_ctl_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
2242{
2243 long ret;
Kashyap, Desai7b936b02009-09-25 11:44:41 +05302244
Arnd Bergmannc45d15d2010-06-02 14:28:52 +02002245 mutex_lock(&_ctl_mutex);
Eric Moore635374e2009-03-09 01:21:12 -06002246 ret = _ctl_ioctl_main(file, cmd, (void __user *)arg);
Arnd Bergmannc45d15d2010-06-02 14:28:52 +02002247 mutex_unlock(&_ctl_mutex);
Eric Moore635374e2009-03-09 01:21:12 -06002248 return ret;
2249}
2250
2251#ifdef CONFIG_COMPAT
2252/**
2253 * _ctl_compat_mpt_command - convert 32bit pointers to 64bit.
2254 * @file - (struct file)
2255 * @cmd - ioctl opcode
2256 * @arg - (struct mpt2_ioctl_command32)
2257 *
2258 * MPT2COMMAND32 - Handle 32bit applications running on 64bit os.
2259 */
2260static long
2261_ctl_compat_mpt_command(struct file *file, unsigned cmd, unsigned long arg)
2262{
2263 struct mpt2_ioctl_command32 karg32;
2264 struct mpt2_ioctl_command32 __user *uarg;
2265 struct mpt2_ioctl_command karg;
2266 struct MPT2SAS_ADAPTER *ioc;
2267 enum block_state state;
Eric Moore635374e2009-03-09 01:21:12 -06002268
2269 if (_IOC_SIZE(cmd) != sizeof(struct mpt2_ioctl_command32))
2270 return -EINVAL;
2271
2272 uarg = (struct mpt2_ioctl_command32 __user *) arg;
2273
2274 if (copy_from_user(&karg32, (char __user *)arg, sizeof(karg32))) {
2275 printk(KERN_ERR "failure at %s:%d/%s()!\n",
2276 __FILE__, __LINE__, __func__);
2277 return -EFAULT;
2278 }
2279 if (_ctl_verify_adapter(karg32.hdr.ioc_number, &ioc) == -1 || !ioc)
2280 return -ENODEV;
2281
Eric Moore3cb54692010-07-08 14:44:34 -06002282 if (ioc->shost_recovery || ioc->pci_error_recovery)
Eric Moore635374e2009-03-09 01:21:12 -06002283 return -EAGAIN;
Eric Moore635374e2009-03-09 01:21:12 -06002284
2285 memset(&karg, 0, sizeof(struct mpt2_ioctl_command));
2286 karg.hdr.ioc_number = karg32.hdr.ioc_number;
2287 karg.hdr.port_number = karg32.hdr.port_number;
2288 karg.hdr.max_data_size = karg32.hdr.max_data_size;
2289 karg.timeout = karg32.timeout;
2290 karg.max_reply_bytes = karg32.max_reply_bytes;
2291 karg.data_in_size = karg32.data_in_size;
2292 karg.data_out_size = karg32.data_out_size;
2293 karg.max_sense_bytes = karg32.max_sense_bytes;
2294 karg.data_sge_offset = karg32.data_sge_offset;
Kashyap, Desai22c88422009-12-16 18:53:04 +05302295 karg.reply_frame_buf_ptr = compat_ptr(karg32.reply_frame_buf_ptr);
2296 karg.data_in_buf_ptr = compat_ptr(karg32.data_in_buf_ptr);
2297 karg.data_out_buf_ptr = compat_ptr(karg32.data_out_buf_ptr);
2298 karg.sense_data_ptr = compat_ptr(karg32.sense_data_ptr);
Eric Moore635374e2009-03-09 01:21:12 -06002299 state = (file->f_flags & O_NONBLOCK) ? NON_BLOCKING : BLOCKING;
2300 return _ctl_do_mpt_command(ioc, karg, &uarg->mf, state);
2301}
2302
2303/**
2304 * _ctl_ioctl_compat - main ioctl entry point (compat)
2305 * @file -
2306 * @cmd -
2307 * @arg -
2308 *
2309 * This routine handles 32 bit applications in 64bit os.
2310 */
2311static long
2312_ctl_ioctl_compat(struct file *file, unsigned cmd, unsigned long arg)
2313{
2314 long ret;
Kashyap, Desai7b936b02009-09-25 11:44:41 +05302315
Arnd Bergmannc45d15d2010-06-02 14:28:52 +02002316 mutex_lock(&_ctl_mutex);
Eric Moore635374e2009-03-09 01:21:12 -06002317 if (cmd == MPT2COMMAND32)
2318 ret = _ctl_compat_mpt_command(file, cmd, arg);
2319 else
2320 ret = _ctl_ioctl_main(file, cmd, (void __user *)arg);
Arnd Bergmannc45d15d2010-06-02 14:28:52 +02002321 mutex_unlock(&_ctl_mutex);
Eric Moore635374e2009-03-09 01:21:12 -06002322 return ret;
2323}
2324#endif
2325
2326/* scsi host attributes */
2327
2328/**
2329 * _ctl_version_fw_show - firmware version
2330 * @cdev - pointer to embedded class device
2331 * @buf - the buffer returned
2332 *
2333 * A sysfs 'read-only' shost attribute.
2334 */
2335static ssize_t
2336_ctl_version_fw_show(struct device *cdev, struct device_attribute *attr,
2337 char *buf)
2338{
2339 struct Scsi_Host *shost = class_to_shost(cdev);
2340 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
2341
2342 return snprintf(buf, PAGE_SIZE, "%02d.%02d.%02d.%02d\n",
2343 (ioc->facts.FWVersion.Word & 0xFF000000) >> 24,
2344 (ioc->facts.FWVersion.Word & 0x00FF0000) >> 16,
2345 (ioc->facts.FWVersion.Word & 0x0000FF00) >> 8,
2346 ioc->facts.FWVersion.Word & 0x000000FF);
2347}
2348static DEVICE_ATTR(version_fw, S_IRUGO, _ctl_version_fw_show, NULL);
2349
2350/**
2351 * _ctl_version_bios_show - bios version
2352 * @cdev - pointer to embedded class device
2353 * @buf - the buffer returned
2354 *
2355 * A sysfs 'read-only' shost attribute.
2356 */
2357static ssize_t
2358_ctl_version_bios_show(struct device *cdev, struct device_attribute *attr,
2359 char *buf)
2360{
2361 struct Scsi_Host *shost = class_to_shost(cdev);
2362 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
2363
2364 u32 version = le32_to_cpu(ioc->bios_pg3.BiosVersion);
2365
2366 return snprintf(buf, PAGE_SIZE, "%02d.%02d.%02d.%02d\n",
2367 (version & 0xFF000000) >> 24,
2368 (version & 0x00FF0000) >> 16,
2369 (version & 0x0000FF00) >> 8,
2370 version & 0x000000FF);
2371}
2372static DEVICE_ATTR(version_bios, S_IRUGO, _ctl_version_bios_show, NULL);
2373
2374/**
2375 * _ctl_version_mpi_show - MPI (message passing interface) version
2376 * @cdev - pointer to embedded class device
2377 * @buf - the buffer returned
2378 *
2379 * A sysfs 'read-only' shost attribute.
2380 */
2381static ssize_t
2382_ctl_version_mpi_show(struct device *cdev, struct device_attribute *attr,
2383 char *buf)
2384{
2385 struct Scsi_Host *shost = class_to_shost(cdev);
2386 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
2387
2388 return snprintf(buf, PAGE_SIZE, "%03x.%02x\n",
2389 ioc->facts.MsgVersion, ioc->facts.HeaderVersion >> 8);
2390}
2391static DEVICE_ATTR(version_mpi, S_IRUGO, _ctl_version_mpi_show, NULL);
2392
2393/**
2394 * _ctl_version_product_show - product name
2395 * @cdev - pointer to embedded class device
2396 * @buf - the buffer returned
2397 *
2398 * A sysfs 'read-only' shost attribute.
2399 */
2400static ssize_t
2401_ctl_version_product_show(struct device *cdev, struct device_attribute *attr,
2402 char *buf)
2403{
2404 struct Scsi_Host *shost = class_to_shost(cdev);
2405 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
2406
2407 return snprintf(buf, 16, "%s\n", ioc->manu_pg0.ChipName);
2408}
2409static DEVICE_ATTR(version_product, S_IRUGO,
2410 _ctl_version_product_show, NULL);
2411
2412/**
2413 * _ctl_version_nvdata_persistent_show - ndvata persistent version
2414 * @cdev - pointer to embedded class device
2415 * @buf - the buffer returned
2416 *
2417 * A sysfs 'read-only' shost attribute.
2418 */
2419static ssize_t
2420_ctl_version_nvdata_persistent_show(struct device *cdev,
2421 struct device_attribute *attr, char *buf)
2422{
2423 struct Scsi_Host *shost = class_to_shost(cdev);
2424 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
2425
Kashyap, Desaie94f6742010-03-17 16:24:52 +05302426 return snprintf(buf, PAGE_SIZE, "%08xh\n",
2427 le32_to_cpu(ioc->iounit_pg0.NvdataVersionPersistent.Word));
Eric Moore635374e2009-03-09 01:21:12 -06002428}
2429static DEVICE_ATTR(version_nvdata_persistent, S_IRUGO,
2430 _ctl_version_nvdata_persistent_show, NULL);
2431
2432/**
2433 * _ctl_version_nvdata_default_show - nvdata default version
2434 * @cdev - pointer to embedded class device
2435 * @buf - the buffer returned
2436 *
2437 * A sysfs 'read-only' shost attribute.
2438 */
2439static ssize_t
2440_ctl_version_nvdata_default_show(struct device *cdev,
2441 struct device_attribute *attr, char *buf)
2442{
2443 struct Scsi_Host *shost = class_to_shost(cdev);
2444 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
2445
Kashyap, Desaie94f6742010-03-17 16:24:52 +05302446 return snprintf(buf, PAGE_SIZE, "%08xh\n",
2447 le32_to_cpu(ioc->iounit_pg0.NvdataVersionDefault.Word));
Eric Moore635374e2009-03-09 01:21:12 -06002448}
2449static DEVICE_ATTR(version_nvdata_default, S_IRUGO,
2450 _ctl_version_nvdata_default_show, NULL);
2451
2452/**
2453 * _ctl_board_name_show - board name
2454 * @cdev - pointer to embedded class device
2455 * @buf - the buffer returned
2456 *
2457 * A sysfs 'read-only' shost attribute.
2458 */
2459static ssize_t
2460_ctl_board_name_show(struct device *cdev, struct device_attribute *attr,
2461 char *buf)
2462{
2463 struct Scsi_Host *shost = class_to_shost(cdev);
2464 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
2465
2466 return snprintf(buf, 16, "%s\n", ioc->manu_pg0.BoardName);
2467}
2468static DEVICE_ATTR(board_name, S_IRUGO, _ctl_board_name_show, NULL);
2469
2470/**
2471 * _ctl_board_assembly_show - board assembly name
2472 * @cdev - pointer to embedded class device
2473 * @buf - the buffer returned
2474 *
2475 * A sysfs 'read-only' shost attribute.
2476 */
2477static ssize_t
2478_ctl_board_assembly_show(struct device *cdev, struct device_attribute *attr,
2479 char *buf)
2480{
2481 struct Scsi_Host *shost = class_to_shost(cdev);
2482 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
2483
2484 return snprintf(buf, 16, "%s\n", ioc->manu_pg0.BoardAssembly);
2485}
2486static DEVICE_ATTR(board_assembly, S_IRUGO,
2487 _ctl_board_assembly_show, NULL);
2488
2489/**
2490 * _ctl_board_tracer_show - board tracer number
2491 * @cdev - pointer to embedded class device
2492 * @buf - the buffer returned
2493 *
2494 * A sysfs 'read-only' shost attribute.
2495 */
2496static ssize_t
2497_ctl_board_tracer_show(struct device *cdev, struct device_attribute *attr,
2498 char *buf)
2499{
2500 struct Scsi_Host *shost = class_to_shost(cdev);
2501 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
2502
2503 return snprintf(buf, 16, "%s\n", ioc->manu_pg0.BoardTracerNumber);
2504}
2505static DEVICE_ATTR(board_tracer, S_IRUGO,
2506 _ctl_board_tracer_show, NULL);
2507
2508/**
2509 * _ctl_io_delay_show - io missing delay
2510 * @cdev - pointer to embedded class device
2511 * @buf - the buffer returned
2512 *
2513 * This is for firmware implemention for deboucing device
2514 * removal events.
2515 *
2516 * A sysfs 'read-only' shost attribute.
2517 */
2518static ssize_t
2519_ctl_io_delay_show(struct device *cdev, struct device_attribute *attr,
2520 char *buf)
2521{
2522 struct Scsi_Host *shost = class_to_shost(cdev);
2523 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
2524
2525 return snprintf(buf, PAGE_SIZE, "%02d\n", ioc->io_missing_delay);
2526}
2527static DEVICE_ATTR(io_delay, S_IRUGO,
2528 _ctl_io_delay_show, NULL);
2529
2530/**
2531 * _ctl_device_delay_show - device missing delay
2532 * @cdev - pointer to embedded class device
2533 * @buf - the buffer returned
2534 *
2535 * This is for firmware implemention for deboucing device
2536 * removal events.
2537 *
2538 * A sysfs 'read-only' shost attribute.
2539 */
2540static ssize_t
2541_ctl_device_delay_show(struct device *cdev, struct device_attribute *attr,
2542 char *buf)
2543{
2544 struct Scsi_Host *shost = class_to_shost(cdev);
2545 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
2546
2547 return snprintf(buf, PAGE_SIZE, "%02d\n", ioc->device_missing_delay);
2548}
2549static DEVICE_ATTR(device_delay, S_IRUGO,
2550 _ctl_device_delay_show, NULL);
2551
2552/**
2553 * _ctl_fw_queue_depth_show - global credits
2554 * @cdev - pointer to embedded class device
2555 * @buf - the buffer returned
2556 *
2557 * This is firmware queue depth limit
2558 *
2559 * A sysfs 'read-only' shost attribute.
2560 */
2561static ssize_t
2562_ctl_fw_queue_depth_show(struct device *cdev, struct device_attribute *attr,
2563 char *buf)
2564{
2565 struct Scsi_Host *shost = class_to_shost(cdev);
2566 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
2567
2568 return snprintf(buf, PAGE_SIZE, "%02d\n", ioc->facts.RequestCredit);
2569}
2570static DEVICE_ATTR(fw_queue_depth, S_IRUGO,
2571 _ctl_fw_queue_depth_show, NULL);
2572
2573/**
2574 * _ctl_sas_address_show - sas address
2575 * @cdev - pointer to embedded class device
2576 * @buf - the buffer returned
2577 *
2578 * This is the controller sas address
2579 *
2580 * A sysfs 'read-only' shost attribute.
2581 */
2582static ssize_t
2583_ctl_host_sas_address_show(struct device *cdev, struct device_attribute *attr,
2584 char *buf)
2585{
2586 struct Scsi_Host *shost = class_to_shost(cdev);
2587 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
2588
2589 return snprintf(buf, PAGE_SIZE, "0x%016llx\n",
2590 (unsigned long long)ioc->sas_hba.sas_address);
2591}
2592static DEVICE_ATTR(host_sas_address, S_IRUGO,
2593 _ctl_host_sas_address_show, NULL);
2594
2595/**
2596 * _ctl_logging_level_show - logging level
2597 * @cdev - pointer to embedded class device
2598 * @buf - the buffer returned
2599 *
2600 * A sysfs 'read/write' shost attribute.
2601 */
2602static ssize_t
2603_ctl_logging_level_show(struct device *cdev, struct device_attribute *attr,
2604 char *buf)
2605{
2606 struct Scsi_Host *shost = class_to_shost(cdev);
2607 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
2608
2609 return snprintf(buf, PAGE_SIZE, "%08xh\n", ioc->logging_level);
2610}
2611static ssize_t
2612_ctl_logging_level_store(struct device *cdev, struct device_attribute *attr,
2613 const char *buf, size_t count)
2614{
2615 struct Scsi_Host *shost = class_to_shost(cdev);
2616 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
2617 int val = 0;
2618
2619 if (sscanf(buf, "%x", &val) != 1)
2620 return -EINVAL;
2621
2622 ioc->logging_level = val;
2623 printk(MPT2SAS_INFO_FMT "logging_level=%08xh\n", ioc->name,
2624 ioc->logging_level);
2625 return strlen(buf);
2626}
2627static DEVICE_ATTR(logging_level, S_IRUGO | S_IWUSR,
2628 _ctl_logging_level_show, _ctl_logging_level_store);
2629
Kashyap, Desaifa7f3162009-09-23 17:26:58 +05302630/* device attributes */
2631/*
2632 * _ctl_fwfault_debug_show - show/store fwfault_debug
2633 * @cdev - pointer to embedded class device
2634 * @buf - the buffer returned
2635 *
2636 * mpt2sas_fwfault_debug is command line option
2637 * A sysfs 'read/write' shost attribute.
2638 */
2639static ssize_t
2640_ctl_fwfault_debug_show(struct device *cdev,
2641 struct device_attribute *attr, char *buf)
2642{
2643 struct Scsi_Host *shost = class_to_shost(cdev);
2644 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
2645
2646 return snprintf(buf, PAGE_SIZE, "%d\n", ioc->fwfault_debug);
2647}
2648static ssize_t
2649_ctl_fwfault_debug_store(struct device *cdev,
2650 struct device_attribute *attr, const char *buf, size_t count)
2651{
2652 struct Scsi_Host *shost = class_to_shost(cdev);
2653 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
2654 int val = 0;
2655
2656 if (sscanf(buf, "%d", &val) != 1)
2657 return -EINVAL;
2658
2659 ioc->fwfault_debug = val;
2660 printk(MPT2SAS_INFO_FMT "fwfault_debug=%d\n", ioc->name,
2661 ioc->fwfault_debug);
2662 return strlen(buf);
2663}
2664static DEVICE_ATTR(fwfault_debug, S_IRUGO | S_IWUSR,
2665 _ctl_fwfault_debug_show, _ctl_fwfault_debug_store);
2666
Kashyap, Desaid32a8c12010-06-17 13:36:53 +05302667
2668/**
2669 * _ctl_ioc_reset_count_show - ioc reset count
2670 * @cdev - pointer to embedded class device
2671 * @buf - the buffer returned
2672 *
2673 * This is firmware queue depth limit
2674 *
2675 * A sysfs 'read-only' shost attribute.
2676 */
2677static ssize_t
2678_ctl_ioc_reset_count_show(struct device *cdev, struct device_attribute *attr,
2679 char *buf)
2680{
2681 struct Scsi_Host *shost = class_to_shost(cdev);
2682 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
2683
2684 return snprintf(buf, PAGE_SIZE, "%08d\n", ioc->ioc_reset_count);
2685}
2686static DEVICE_ATTR(ioc_reset_count, S_IRUGO,
2687 _ctl_ioc_reset_count_show, NULL);
2688
Kashyap, Desai570c67a2010-06-17 13:43:17 +05302689struct DIAG_BUFFER_START {
2690 u32 Size;
2691 u32 DiagVersion;
2692 u8 BufferType;
2693 u8 Reserved[3];
2694 u32 Reserved1;
2695 u32 Reserved2;
2696 u32 Reserved3;
2697};
2698/**
2699 * _ctl_host_trace_buffer_size_show - host buffer size (trace only)
2700 * @cdev - pointer to embedded class device
2701 * @buf - the buffer returned
2702 *
2703 * A sysfs 'read-only' shost attribute.
2704 */
2705static ssize_t
2706_ctl_host_trace_buffer_size_show(struct device *cdev,
2707 struct device_attribute *attr, char *buf)
2708{
2709 struct Scsi_Host *shost = class_to_shost(cdev);
2710 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
2711 u32 size = 0;
2712 struct DIAG_BUFFER_START *request_data;
2713
2714 if (!ioc->diag_buffer[MPI2_DIAG_BUF_TYPE_TRACE]) {
2715 printk(MPT2SAS_ERR_FMT "%s: host_trace_buffer is not "
2716 "registered\n", ioc->name, __func__);
2717 return 0;
2718 }
2719
2720 if ((ioc->diag_buffer_status[MPI2_DIAG_BUF_TYPE_TRACE] &
2721 MPT2_DIAG_BUFFER_IS_REGISTERED) == 0) {
2722 printk(MPT2SAS_ERR_FMT "%s: host_trace_buffer is not "
2723 "registered\n", ioc->name, __func__);
2724 return 0;
2725 }
2726
2727 request_data = (struct DIAG_BUFFER_START *)
2728 ioc->diag_buffer[MPI2_DIAG_BUF_TYPE_TRACE];
2729 if ((le32_to_cpu(request_data->DiagVersion) == 0x00000000 ||
2730 le32_to_cpu(request_data->DiagVersion) == 0x01000000) &&
2731 le32_to_cpu(request_data->Reserved3) == 0x4742444c)
2732 size = le32_to_cpu(request_data->Size);
2733
2734 ioc->ring_buffer_sz = size;
2735 return snprintf(buf, PAGE_SIZE, "%d\n", size);
2736}
2737static DEVICE_ATTR(host_trace_buffer_size, S_IRUGO,
2738 _ctl_host_trace_buffer_size_show, NULL);
2739
2740/**
2741 * _ctl_host_trace_buffer_show - firmware ring buffer (trace only)
2742 * @cdev - pointer to embedded class device
2743 * @buf - the buffer returned
2744 *
2745 * A sysfs 'read/write' shost attribute.
2746 *
2747 * You will only be able to read 4k bytes of ring buffer at a time.
2748 * In order to read beyond 4k bytes, you will have to write out the
2749 * offset to the same attribute, it will move the pointer.
2750 */
2751static ssize_t
2752_ctl_host_trace_buffer_show(struct device *cdev, struct device_attribute *attr,
2753 char *buf)
2754{
2755 struct Scsi_Host *shost = class_to_shost(cdev);
2756 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
2757 void *request_data;
2758 u32 size;
2759
2760 if (!ioc->diag_buffer[MPI2_DIAG_BUF_TYPE_TRACE]) {
2761 printk(MPT2SAS_ERR_FMT "%s: host_trace_buffer is not "
2762 "registered\n", ioc->name, __func__);
2763 return 0;
2764 }
2765
2766 if ((ioc->diag_buffer_status[MPI2_DIAG_BUF_TYPE_TRACE] &
2767 MPT2_DIAG_BUFFER_IS_REGISTERED) == 0) {
2768 printk(MPT2SAS_ERR_FMT "%s: host_trace_buffer is not "
2769 "registered\n", ioc->name, __func__);
2770 return 0;
2771 }
2772
2773 if (ioc->ring_buffer_offset > ioc->ring_buffer_sz)
2774 return 0;
2775
2776 size = ioc->ring_buffer_sz - ioc->ring_buffer_offset;
2777 size = (size > PAGE_SIZE) ? PAGE_SIZE : size;
2778 request_data = ioc->diag_buffer[0] + ioc->ring_buffer_offset;
2779 memcpy(buf, request_data, size);
2780 return size;
2781}
2782
2783static ssize_t
2784_ctl_host_trace_buffer_store(struct device *cdev, struct device_attribute *attr,
2785 const char *buf, size_t count)
2786{
2787 struct Scsi_Host *shost = class_to_shost(cdev);
2788 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
2789 int val = 0;
2790
2791 if (sscanf(buf, "%d", &val) != 1)
2792 return -EINVAL;
2793
2794 ioc->ring_buffer_offset = val;
2795 return strlen(buf);
2796}
2797static DEVICE_ATTR(host_trace_buffer, S_IRUGO | S_IWUSR,
2798 _ctl_host_trace_buffer_show, _ctl_host_trace_buffer_store);
2799
2800/*****************************************/
2801
2802/**
2803 * _ctl_host_trace_buffer_enable_show - firmware ring buffer (trace only)
2804 * @cdev - pointer to embedded class device
2805 * @buf - the buffer returned
2806 *
2807 * A sysfs 'read/write' shost attribute.
2808 *
2809 * This is a mechnism to post/release host_trace_buffers
2810 */
2811static ssize_t
2812_ctl_host_trace_buffer_enable_show(struct device *cdev,
2813 struct device_attribute *attr, char *buf)
2814{
2815 struct Scsi_Host *shost = class_to_shost(cdev);
2816 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
2817
2818 if ((!ioc->diag_buffer[MPI2_DIAG_BUF_TYPE_TRACE]) ||
2819 ((ioc->diag_buffer_status[MPI2_DIAG_BUF_TYPE_TRACE] &
2820 MPT2_DIAG_BUFFER_IS_REGISTERED) == 0))
2821 return snprintf(buf, PAGE_SIZE, "off\n");
2822 else if ((ioc->diag_buffer_status[MPI2_DIAG_BUF_TYPE_TRACE] &
2823 MPT2_DIAG_BUFFER_IS_RELEASED))
2824 return snprintf(buf, PAGE_SIZE, "release\n");
2825 else
2826 return snprintf(buf, PAGE_SIZE, "post\n");
2827}
2828
2829static ssize_t
2830_ctl_host_trace_buffer_enable_store(struct device *cdev,
2831 struct device_attribute *attr, const char *buf, size_t count)
2832{
2833 struct Scsi_Host *shost = class_to_shost(cdev);
2834 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
2835 char str[10] = "";
2836 struct mpt2_diag_register diag_register;
2837 u8 issue_reset = 0;
2838
2839 if (sscanf(buf, "%s", str) != 1)
2840 return -EINVAL;
2841
2842 if (!strcmp(str, "post")) {
2843 /* exit out if host buffers are already posted */
2844 if ((ioc->diag_buffer[MPI2_DIAG_BUF_TYPE_TRACE]) &&
2845 (ioc->diag_buffer_status[MPI2_DIAG_BUF_TYPE_TRACE] &
2846 MPT2_DIAG_BUFFER_IS_REGISTERED) &&
2847 ((ioc->diag_buffer_status[MPI2_DIAG_BUF_TYPE_TRACE] &
2848 MPT2_DIAG_BUFFER_IS_RELEASED) == 0))
2849 goto out;
2850 memset(&diag_register, 0, sizeof(struct mpt2_diag_register));
2851 printk(MPT2SAS_INFO_FMT "posting host trace buffers\n",
2852 ioc->name);
2853 diag_register.buffer_type = MPI2_DIAG_BUF_TYPE_TRACE;
2854 diag_register.requested_buffer_size = (1024 * 1024);
2855 diag_register.unique_id = 0x7075900;
2856 ioc->diag_buffer_status[MPI2_DIAG_BUF_TYPE_TRACE] = 0;
2857 _ctl_diag_register_2(ioc, &diag_register);
2858 } else if (!strcmp(str, "release")) {
2859 /* exit out if host buffers are already released */
2860 if (!ioc->diag_buffer[MPI2_DIAG_BUF_TYPE_TRACE])
2861 goto out;
2862 if ((ioc->diag_buffer_status[MPI2_DIAG_BUF_TYPE_TRACE] &
2863 MPT2_DIAG_BUFFER_IS_REGISTERED) == 0)
2864 goto out;
2865 if ((ioc->diag_buffer_status[MPI2_DIAG_BUF_TYPE_TRACE] &
2866 MPT2_DIAG_BUFFER_IS_RELEASED))
2867 goto out;
2868 printk(MPT2SAS_INFO_FMT "releasing host trace buffer\n",
2869 ioc->name);
2870 _ctl_send_release(ioc, MPI2_DIAG_BUF_TYPE_TRACE, &issue_reset);
2871 }
2872
2873 out:
2874 return strlen(buf);
2875}
2876static DEVICE_ATTR(host_trace_buffer_enable, S_IRUGO | S_IWUSR,
2877 _ctl_host_trace_buffer_enable_show, _ctl_host_trace_buffer_enable_store);
Kashyap, Desaid32a8c12010-06-17 13:36:53 +05302878
Eric Moore635374e2009-03-09 01:21:12 -06002879struct device_attribute *mpt2sas_host_attrs[] = {
2880 &dev_attr_version_fw,
2881 &dev_attr_version_bios,
2882 &dev_attr_version_mpi,
2883 &dev_attr_version_product,
2884 &dev_attr_version_nvdata_persistent,
2885 &dev_attr_version_nvdata_default,
2886 &dev_attr_board_name,
2887 &dev_attr_board_assembly,
2888 &dev_attr_board_tracer,
2889 &dev_attr_io_delay,
2890 &dev_attr_device_delay,
2891 &dev_attr_logging_level,
Kashyap, Desaifa7f3162009-09-23 17:26:58 +05302892 &dev_attr_fwfault_debug,
Eric Moore635374e2009-03-09 01:21:12 -06002893 &dev_attr_fw_queue_depth,
2894 &dev_attr_host_sas_address,
Kashyap, Desaid32a8c12010-06-17 13:36:53 +05302895 &dev_attr_ioc_reset_count,
Kashyap, Desai570c67a2010-06-17 13:43:17 +05302896 &dev_attr_host_trace_buffer_size,
2897 &dev_attr_host_trace_buffer,
2898 &dev_attr_host_trace_buffer_enable,
Eric Moore635374e2009-03-09 01:21:12 -06002899 NULL,
2900};
2901
Eric Moore635374e2009-03-09 01:21:12 -06002902/**
2903 * _ctl_device_sas_address_show - sas address
2904 * @cdev - pointer to embedded class device
2905 * @buf - the buffer returned
2906 *
2907 * This is the sas address for the target
2908 *
2909 * A sysfs 'read-only' shost attribute.
2910 */
2911static ssize_t
2912_ctl_device_sas_address_show(struct device *dev, struct device_attribute *attr,
2913 char *buf)
2914{
2915 struct scsi_device *sdev = to_scsi_device(dev);
2916 struct MPT2SAS_DEVICE *sas_device_priv_data = sdev->hostdata;
2917
2918 return snprintf(buf, PAGE_SIZE, "0x%016llx\n",
2919 (unsigned long long)sas_device_priv_data->sas_target->sas_address);
2920}
2921static DEVICE_ATTR(sas_address, S_IRUGO, _ctl_device_sas_address_show, NULL);
2922
2923/**
2924 * _ctl_device_handle_show - device handle
2925 * @cdev - pointer to embedded class device
2926 * @buf - the buffer returned
2927 *
2928 * This is the firmware assigned device handle
2929 *
2930 * A sysfs 'read-only' shost attribute.
2931 */
2932static ssize_t
2933_ctl_device_handle_show(struct device *dev, struct device_attribute *attr,
2934 char *buf)
2935{
2936 struct scsi_device *sdev = to_scsi_device(dev);
2937 struct MPT2SAS_DEVICE *sas_device_priv_data = sdev->hostdata;
2938
2939 return snprintf(buf, PAGE_SIZE, "0x%04x\n",
2940 sas_device_priv_data->sas_target->handle);
2941}
2942static DEVICE_ATTR(sas_device_handle, S_IRUGO, _ctl_device_handle_show, NULL);
2943
2944struct device_attribute *mpt2sas_dev_attrs[] = {
2945 &dev_attr_sas_address,
2946 &dev_attr_sas_device_handle,
2947 NULL,
2948};
2949
2950static const struct file_operations ctl_fops = {
2951 .owner = THIS_MODULE,
2952 .unlocked_ioctl = _ctl_ioctl,
2953 .release = _ctl_release,
2954 .poll = _ctl_poll,
2955 .fasync = _ctl_fasync,
2956#ifdef CONFIG_COMPAT
2957 .compat_ioctl = _ctl_ioctl_compat,
2958#endif
Arnd Bergmann6038f372010-08-15 18:52:59 +02002959 .llseek = noop_llseek,
Eric Moore635374e2009-03-09 01:21:12 -06002960};
2961
2962static struct miscdevice ctl_dev = {
2963 .minor = MPT2SAS_MINOR,
2964 .name = MPT2SAS_DEV_NAME,
2965 .fops = &ctl_fops,
2966};
2967
2968/**
2969 * mpt2sas_ctl_init - main entry point for ctl.
2970 *
2971 */
2972void
2973mpt2sas_ctl_init(void)
2974{
2975 async_queue = NULL;
2976 if (misc_register(&ctl_dev) < 0)
2977 printk(KERN_ERR "%s can't register misc device [minor=%d]\n",
2978 MPT2SAS_DRIVER_NAME, MPT2SAS_MINOR);
2979
2980 init_waitqueue_head(&ctl_poll_wait);
2981}
2982
2983/**
2984 * mpt2sas_ctl_exit - exit point for ctl
2985 *
2986 */
2987void
2988mpt2sas_ctl_exit(void)
2989{
2990 struct MPT2SAS_ADAPTER *ioc;
2991 int i;
2992
Eric Mooreba33fad2009-03-15 21:37:18 -06002993 list_for_each_entry(ioc, &mpt2sas_ioc_list, list) {
Eric Moore635374e2009-03-09 01:21:12 -06002994
2995 /* free memory associated to diag buffers */
2996 for (i = 0; i < MPI2_DIAG_BUF_TYPE_COUNT; i++) {
2997 if (!ioc->diag_buffer[i])
2998 continue;
2999 pci_free_consistent(ioc->pdev, ioc->diag_buffer_sz[i],
3000 ioc->diag_buffer[i], ioc->diag_buffer_dma[i]);
3001 ioc->diag_buffer[i] = NULL;
3002 ioc->diag_buffer_status[i] = 0;
3003 }
3004
3005 kfree(ioc->event_log);
3006 }
3007 misc_deregister(&ctl_dev);
3008}
3009