diff options
Diffstat (limited to 'drivers/message/fusion/mptctl.c')
| -rw-r--r-- | drivers/message/fusion/mptctl.c | 692 |
1 files changed, 379 insertions, 313 deletions
diff --git a/drivers/message/fusion/mptctl.c b/drivers/message/fusion/mptctl.c index c63817117c0a..9b2e2198aee9 100644 --- a/drivers/message/fusion/mptctl.c +++ b/drivers/message/fusion/mptctl.c | |||
| @@ -84,6 +84,7 @@ MODULE_VERSION(my_VERSION); | |||
| 84 | /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ | 84 | /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ |
| 85 | 85 | ||
| 86 | static u8 mptctl_id = MPT_MAX_PROTOCOL_DRIVERS; | 86 | static u8 mptctl_id = MPT_MAX_PROTOCOL_DRIVERS; |
| 87 | static u8 mptctl_taskmgmt_id = MPT_MAX_PROTOCOL_DRIVERS; | ||
| 87 | 88 | ||
| 88 | static DECLARE_WAIT_QUEUE_HEAD ( mptctl_wait ); | 89 | static DECLARE_WAIT_QUEUE_HEAD ( mptctl_wait ); |
| 89 | 90 | ||
| @@ -127,10 +128,7 @@ static MptSge_t *kbuf_alloc_2_sgl(int bytes, u32 dir, int sge_offset, int *frags | |||
| 127 | struct buflist **blp, dma_addr_t *sglbuf_dma, MPT_ADAPTER *ioc); | 128 | struct buflist **blp, dma_addr_t *sglbuf_dma, MPT_ADAPTER *ioc); |
| 128 | static void kfree_sgl(MptSge_t *sgl, dma_addr_t sgl_dma, | 129 | static void kfree_sgl(MptSge_t *sgl, dma_addr_t sgl_dma, |
| 129 | struct buflist *buflist, MPT_ADAPTER *ioc); | 130 | struct buflist *buflist, MPT_ADAPTER *ioc); |
| 130 | static void mptctl_timeout_expired (MPT_IOCTL *ioctl); | 131 | static int mptctl_bus_reset(MPT_ADAPTER *ioc, u8 function); |
| 131 | static int mptctl_bus_reset(MPT_IOCTL *ioctl); | ||
| 132 | static int mptctl_set_tm_flags(MPT_SCSI_HOST *hd); | ||
| 133 | static void mptctl_free_tm_flags(MPT_ADAPTER *ioc); | ||
| 134 | 132 | ||
| 135 | /* | 133 | /* |
| 136 | * Reset Handler cleanup function | 134 | * Reset Handler cleanup function |
| @@ -183,10 +181,10 @@ mptctl_syscall_down(MPT_ADAPTER *ioc, int nonblock) | |||
| 183 | int rc = 0; | 181 | int rc = 0; |
| 184 | 182 | ||
| 185 | if (nonblock) { | 183 | if (nonblock) { |
| 186 | if (!mutex_trylock(&ioc->ioctl->ioctl_mutex)) | 184 | if (!mutex_trylock(&ioc->ioctl_cmds.mutex)) |
| 187 | rc = -EAGAIN; | 185 | rc = -EAGAIN; |
| 188 | } else { | 186 | } else { |
| 189 | if (mutex_lock_interruptible(&ioc->ioctl->ioctl_mutex)) | 187 | if (mutex_lock_interruptible(&ioc->ioctl_cmds.mutex)) |
| 190 | rc = -ERESTARTSYS; | 188 | rc = -ERESTARTSYS; |
| 191 | } | 189 | } |
| 192 | return rc; | 190 | return rc; |
| @@ -202,99 +200,78 @@ mptctl_syscall_down(MPT_ADAPTER *ioc, int nonblock) | |||
| 202 | static int | 200 | static int |
| 203 | mptctl_reply(MPT_ADAPTER *ioc, MPT_FRAME_HDR *req, MPT_FRAME_HDR *reply) | 201 | mptctl_reply(MPT_ADAPTER *ioc, MPT_FRAME_HDR *req, MPT_FRAME_HDR *reply) |
| 204 | { | 202 | { |
| 205 | char *sense_data; | 203 | char *sense_data; |
| 206 | int sz, req_index; | 204 | int req_index; |
| 207 | u16 iocStatus; | 205 | int sz; |
| 208 | u8 cmd; | ||
| 209 | 206 | ||
| 210 | if (req) | 207 | if (!req) |
| 211 | cmd = req->u.hdr.Function; | 208 | return 0; |
| 212 | else | ||
| 213 | return 1; | ||
| 214 | dctlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "\tcompleting mpi function (0x%02X), req=%p, " | ||
| 215 | "reply=%p\n", ioc->name, req->u.hdr.Function, req, reply)); | ||
| 216 | |||
| 217 | if (ioc->ioctl) { | ||
| 218 | |||
| 219 | if (reply==NULL) { | ||
| 220 | |||
| 221 | dctlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "mptctl_reply() NULL Reply " | ||
| 222 | "Function=%x!\n", ioc->name, cmd)); | ||
| 223 | 209 | ||
| 224 | ioc->ioctl->status |= MPT_IOCTL_STATUS_COMMAND_GOOD; | 210 | dctlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "completing mpi function " |
| 225 | ioc->ioctl->reset &= ~MPTCTL_RESET_OK; | 211 | "(0x%02X), req=%p, reply=%p\n", ioc->name, req->u.hdr.Function, |
| 212 | req, reply)); | ||
| 226 | 213 | ||
| 227 | /* We are done, issue wake up | 214 | /* |
| 228 | */ | 215 | * Handling continuation of the same reply. Processing the first |
| 229 | ioc->ioctl->wait_done = 1; | 216 | * reply, and eating the other replys that come later. |
| 230 | wake_up (&mptctl_wait); | 217 | */ |
| 231 | return 1; | 218 | if (ioc->ioctl_cmds.msg_context != req->u.hdr.MsgContext) |
| 219 | goto out_continuation; | ||
| 232 | 220 | ||
| 233 | } | 221 | ioc->ioctl_cmds.status |= MPT_MGMT_STATUS_COMMAND_GOOD; |
| 234 | 222 | ||
| 235 | /* Copy the reply frame (which much exist | 223 | if (!reply) |
| 236 | * for non-SCSI I/O) to the IOC structure. | 224 | goto out; |
| 237 | */ | ||
| 238 | memcpy(ioc->ioctl->ReplyFrame, reply, | ||
| 239 | min(ioc->reply_sz, 4*reply->u.reply.MsgLength)); | ||
| 240 | ioc->ioctl->status |= MPT_IOCTL_STATUS_RF_VALID; | ||
| 241 | 225 | ||
| 242 | /* Set the command status to GOOD if IOC Status is GOOD | 226 | ioc->ioctl_cmds.status |= MPT_MGMT_STATUS_RF_VALID; |
| 243 | * OR if SCSI I/O cmd and data underrun or recovered error. | 227 | sz = min(ioc->reply_sz, 4*reply->u.reply.MsgLength); |
| 244 | */ | 228 | memcpy(ioc->ioctl_cmds.reply, reply, sz); |
| 245 | iocStatus = le16_to_cpu(reply->u.reply.IOCStatus) & MPI_IOCSTATUS_MASK; | ||
| 246 | if (iocStatus == MPI_IOCSTATUS_SUCCESS) | ||
| 247 | ioc->ioctl->status |= MPT_IOCTL_STATUS_COMMAND_GOOD; | ||
| 248 | |||
| 249 | if (iocStatus || reply->u.reply.IOCLogInfo) | ||
| 250 | dctlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "\tiocstatus (0x%04X), " | ||
| 251 | "loginfo (0x%08X)\n", ioc->name, | ||
| 252 | iocStatus, | ||
| 253 | le32_to_cpu(reply->u.reply.IOCLogInfo))); | ||
| 254 | |||
| 255 | if ((cmd == MPI_FUNCTION_SCSI_IO_REQUEST) || | ||
| 256 | (cmd == MPI_FUNCTION_RAID_SCSI_IO_PASSTHROUGH)) { | ||
| 257 | |||
| 258 | if (reply->u.sreply.SCSIStatus || reply->u.sreply.SCSIState) | ||
| 259 | dctlprintk(ioc, printk(MYIOC_s_DEBUG_FMT | ||
| 260 | "\tscsi_status (0x%02x), scsi_state (0x%02x), " | ||
| 261 | "tag = (0x%04x), transfer_count (0x%08x)\n", ioc->name, | ||
| 262 | reply->u.sreply.SCSIStatus, | ||
| 263 | reply->u.sreply.SCSIState, | ||
| 264 | le16_to_cpu(reply->u.sreply.TaskTag), | ||
| 265 | le32_to_cpu(reply->u.sreply.TransferCount))); | ||
| 266 | |||
| 267 | ioc->ioctl->reset &= ~MPTCTL_RESET_OK; | ||
| 268 | |||
| 269 | if ((iocStatus == MPI_IOCSTATUS_SCSI_DATA_UNDERRUN) || | ||
| 270 | (iocStatus == MPI_IOCSTATUS_SCSI_RECOVERED_ERROR)) { | ||
| 271 | ioc->ioctl->status |= MPT_IOCTL_STATUS_COMMAND_GOOD; | ||
| 272 | } | ||
| 273 | } | ||
| 274 | 229 | ||
| 275 | /* Copy the sense data - if present | 230 | if (reply->u.reply.IOCStatus || reply->u.reply.IOCLogInfo) |
| 276 | */ | 231 | dctlprintk(ioc, printk(MYIOC_s_DEBUG_FMT |
| 277 | if ((cmd == MPI_FUNCTION_SCSI_IO_REQUEST) && | 232 | "iocstatus (0x%04X), loginfo (0x%08X)\n", ioc->name, |
| 278 | (reply->u.sreply.SCSIState & | 233 | le16_to_cpu(reply->u.reply.IOCStatus), |
| 279 | MPI_SCSI_STATE_AUTOSENSE_VALID)){ | 234 | le32_to_cpu(reply->u.reply.IOCLogInfo))); |
| 235 | |||
| 236 | if ((req->u.hdr.Function == MPI_FUNCTION_SCSI_IO_REQUEST) || | ||
| 237 | (req->u.hdr.Function == | ||
| 238 | MPI_FUNCTION_RAID_SCSI_IO_PASSTHROUGH)) { | ||
| 239 | |||
| 240 | if (reply->u.sreply.SCSIStatus || reply->u.sreply.SCSIState) | ||
| 241 | dctlprintk(ioc, printk(MYIOC_s_DEBUG_FMT | ||
| 242 | "scsi_status (0x%02x), scsi_state (0x%02x), " | ||
| 243 | "tag = (0x%04x), transfer_count (0x%08x)\n", ioc->name, | ||
| 244 | reply->u.sreply.SCSIStatus, | ||
| 245 | reply->u.sreply.SCSIState, | ||
| 246 | le16_to_cpu(reply->u.sreply.TaskTag), | ||
| 247 | le32_to_cpu(reply->u.sreply.TransferCount))); | ||
| 248 | |||
| 249 | if (reply->u.sreply.SCSIState & | ||
| 250 | MPI_SCSI_STATE_AUTOSENSE_VALID) { | ||
| 280 | sz = req->u.scsireq.SenseBufferLength; | 251 | sz = req->u.scsireq.SenseBufferLength; |
| 281 | req_index = | 252 | req_index = |
| 282 | le16_to_cpu(req->u.frame.hwhdr.msgctxu.fld.req_idx); | 253 | le16_to_cpu(req->u.frame.hwhdr.msgctxu.fld.req_idx); |
| 283 | sense_data = | 254 | sense_data = ((u8 *)ioc->sense_buf_pool + |
| 284 | ((u8 *)ioc->sense_buf_pool + | ||
| 285 | (req_index * MPT_SENSE_BUFFER_ALLOC)); | 255 | (req_index * MPT_SENSE_BUFFER_ALLOC)); |
| 286 | memcpy(ioc->ioctl->sense, sense_data, sz); | 256 | memcpy(ioc->ioctl_cmds.sense, sense_data, sz); |
| 287 | ioc->ioctl->status |= MPT_IOCTL_STATUS_SENSE_VALID; | 257 | ioc->ioctl_cmds.status |= MPT_MGMT_STATUS_SENSE_VALID; |
| 288 | } | 258 | } |
| 259 | } | ||
| 289 | 260 | ||
| 290 | if (cmd == MPI_FUNCTION_SCSI_TASK_MGMT) | 261 | out: |
| 291 | mptctl_free_tm_flags(ioc); | 262 | /* We are done, issue wake up |
| 292 | 263 | */ | |
| 293 | /* We are done, issue wake up | 264 | if (ioc->ioctl_cmds.status & MPT_MGMT_STATUS_PENDING) { |
| 294 | */ | 265 | if (req->u.hdr.Function == MPI_FUNCTION_SCSI_TASK_MGMT) |
| 295 | ioc->ioctl->wait_done = 1; | 266 | mpt_clear_taskmgmt_in_progress_flag(ioc); |
| 296 | wake_up (&mptctl_wait); | 267 | ioc->ioctl_cmds.status &= ~MPT_MGMT_STATUS_PENDING; |
| 268 | complete(&ioc->ioctl_cmds.done); | ||
| 297 | } | 269 | } |
| 270 | |||
| 271 | out_continuation: | ||
| 272 | if (reply && (reply->u.reply.MsgFlags & | ||
| 273 | MPI_MSGFLAGS_CONTINUATION_REPLY)) | ||
| 274 | return 0; | ||
| 298 | return 1; | 275 | return 1; |
| 299 | } | 276 | } |
| 300 | 277 | ||
| @@ -304,30 +281,66 @@ mptctl_reply(MPT_ADAPTER *ioc, MPT_FRAME_HDR *req, MPT_FRAME_HDR *reply) | |||
| 304 | * Expecting an interrupt, however timed out. | 281 | * Expecting an interrupt, however timed out. |
| 305 | * | 282 | * |
| 306 | */ | 283 | */ |
| 307 | static void mptctl_timeout_expired (MPT_IOCTL *ioctl) | 284 | static void |
| 285 | mptctl_timeout_expired(MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf) | ||
| 308 | { | 286 | { |
| 309 | int rc = 1; | 287 | unsigned long flags; |
| 310 | 288 | ||
| 311 | if (ioctl == NULL) | 289 | dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT ": %s\n", |
| 312 | return; | 290 | ioc->name, __func__)); |
| 313 | dctlprintk(ioctl->ioc, | ||
| 314 | printk(MYIOC_s_DEBUG_FMT ": Timeout Expired! Host %d\n", | ||
| 315 | ioctl->ioc->name, ioctl->ioc->id)); | ||
| 316 | 291 | ||
| 317 | ioctl->wait_done = 0; | 292 | if (mpt_fwfault_debug) |
| 318 | if (ioctl->reset & MPTCTL_RESET_OK) | 293 | mpt_halt_firmware(ioc); |
| 319 | rc = mptctl_bus_reset(ioctl); | ||
| 320 | 294 | ||
| 321 | if (rc) { | 295 | spin_lock_irqsave(&ioc->taskmgmt_lock, flags); |
| 322 | /* Issue a reset for this device. | 296 | if (ioc->ioc_reset_in_progress) { |
| 323 | * The IOC is not responding. | 297 | spin_unlock_irqrestore(&ioc->taskmgmt_lock, flags); |
| 324 | */ | 298 | CLEAR_MGMT_PENDING_STATUS(ioc->ioctl_cmds.status) |
| 325 | dctlprintk(ioctl->ioc, printk(MYIOC_s_DEBUG_FMT "Calling HardReset! \n", | 299 | mpt_free_msg_frame(ioc, mf); |
| 326 | ioctl->ioc->name)); | 300 | return; |
| 327 | mpt_HardResetHandler(ioctl->ioc, CAN_SLEEP); | ||
| 328 | } | 301 | } |
| 329 | return; | 302 | spin_unlock_irqrestore(&ioc->taskmgmt_lock, flags); |
| 303 | |||
| 330 | 304 | ||
| 305 | if (!mptctl_bus_reset(ioc, mf->u.hdr.Function)) | ||
| 306 | return; | ||
| 307 | |||
| 308 | /* Issue a reset for this device. | ||
| 309 | * The IOC is not responding. | ||
| 310 | */ | ||
| 311 | dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Calling HardReset! \n", | ||
| 312 | ioc->name)); | ||
| 313 | CLEAR_MGMT_PENDING_STATUS(ioc->ioctl_cmds.status) | ||
| 314 | mpt_HardResetHandler(ioc, CAN_SLEEP); | ||
| 315 | mpt_free_msg_frame(ioc, mf); | ||
| 316 | } | ||
| 317 | |||
| 318 | static int | ||
| 319 | mptctl_taskmgmt_reply(MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf, MPT_FRAME_HDR *mr) | ||
| 320 | { | ||
| 321 | if (!mf) | ||
| 322 | return 0; | ||
| 323 | |||
| 324 | dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT | ||
| 325 | "TaskMgmt completed (mf=%p, mr=%p)\n", | ||
| 326 | ioc->name, mf, mr)); | ||
| 327 | |||
| 328 | ioc->taskmgmt_cmds.status |= MPT_MGMT_STATUS_COMMAND_GOOD; | ||
| 329 | |||
| 330 | if (!mr) | ||
| 331 | goto out; | ||
| 332 | |||
| 333 | ioc->taskmgmt_cmds.status |= MPT_MGMT_STATUS_RF_VALID; | ||
| 334 | memcpy(ioc->taskmgmt_cmds.reply, mr, | ||
| 335 | min(MPT_DEFAULT_FRAME_SIZE, 4 * mr->u.reply.MsgLength)); | ||
| 336 | out: | ||
| 337 | if (ioc->taskmgmt_cmds.status & MPT_MGMT_STATUS_PENDING) { | ||
| 338 | mpt_clear_taskmgmt_in_progress_flag(ioc); | ||
| 339 | ioc->taskmgmt_cmds.status &= ~MPT_MGMT_STATUS_PENDING; | ||
| 340 | complete(&ioc->taskmgmt_cmds.done); | ||
| 341 | return 1; | ||
| 342 | } | ||
| 343 | return 0; | ||
| 331 | } | 344 | } |
| 332 | 345 | ||
| 333 | /* mptctl_bus_reset | 346 | /* mptctl_bus_reset |
| @@ -335,133 +348,150 @@ static void mptctl_timeout_expired (MPT_IOCTL *ioctl) | |||
| 335 | * Bus reset code. | 348 | * Bus reset code. |
| 336 | * | 349 | * |
| 337 | */ | 350 | */ |
| 338 | static int mptctl_bus_reset(MPT_IOCTL *ioctl) | 351 | static int mptctl_bus_reset(MPT_ADAPTER *ioc, u8 function) |
| 339 | { | 352 | { |
| 340 | MPT_FRAME_HDR *mf; | 353 | MPT_FRAME_HDR *mf; |
| 341 | SCSITaskMgmt_t *pScsiTm; | 354 | SCSITaskMgmt_t *pScsiTm; |
| 342 | MPT_SCSI_HOST *hd; | 355 | SCSITaskMgmtReply_t *pScsiTmReply; |
| 343 | int ii; | 356 | int ii; |
| 344 | int retval=0; | 357 | int retval; |
| 345 | 358 | unsigned long timeout; | |
| 346 | 359 | unsigned long time_count; | |
| 347 | ioctl->reset &= ~MPTCTL_RESET_OK; | 360 | u16 iocstatus; |
| 348 | 361 | ||
| 349 | if (ioctl->ioc->sh == NULL) | 362 | /* bus reset is only good for SCSI IO, RAID PASSTHRU */ |
| 363 | if (!(function == MPI_FUNCTION_RAID_SCSI_IO_PASSTHROUGH) || | ||
| 364 | (function == MPI_FUNCTION_SCSI_IO_REQUEST)) { | ||
| 365 | dtmprintk(ioc, printk(MYIOC_s_WARN_FMT | ||
| 366 | "TaskMgmt, not SCSI_IO!!\n", ioc->name)); | ||
| 350 | return -EPERM; | 367 | return -EPERM; |
| 368 | } | ||
| 351 | 369 | ||
| 352 | hd = shost_priv(ioctl->ioc->sh); | 370 | mutex_lock(&ioc->taskmgmt_cmds.mutex); |
| 353 | if (hd == NULL) | 371 | if (mpt_set_taskmgmt_in_progress_flag(ioc) != 0) { |
| 372 | mutex_unlock(&ioc->taskmgmt_cmds.mutex); | ||
| 354 | return -EPERM; | 373 | return -EPERM; |
| 374 | } | ||
| 355 | 375 | ||
| 356 | /* Single threading .... | 376 | retval = 0; |
| 357 | */ | ||
| 358 | if (mptctl_set_tm_flags(hd) != 0) | ||
| 359 | return -EPERM; | ||
| 360 | 377 | ||
| 361 | /* Send request | 378 | /* Send request |
| 362 | */ | 379 | */ |
| 363 | if ((mf = mpt_get_msg_frame(mptctl_id, ioctl->ioc)) == NULL) { | 380 | mf = mpt_get_msg_frame(mptctl_taskmgmt_id, ioc); |
| 364 | dtmprintk(ioctl->ioc, printk(MYIOC_s_DEBUG_FMT "IssueTaskMgmt, no msg frames!!\n", | 381 | if (mf == NULL) { |
| 365 | ioctl->ioc->name)); | 382 | dtmprintk(ioc, printk(MYIOC_s_WARN_FMT |
| 366 | 383 | "TaskMgmt, no msg frames!!\n", ioc->name)); | |
| 367 | mptctl_free_tm_flags(ioctl->ioc); | 384 | mpt_clear_taskmgmt_in_progress_flag(ioc); |
| 368 | return -ENOMEM; | 385 | retval = -ENOMEM; |
| 386 | goto mptctl_bus_reset_done; | ||
| 369 | } | 387 | } |
| 370 | 388 | ||
| 371 | dtmprintk(ioctl->ioc, printk(MYIOC_s_DEBUG_FMT "IssueTaskMgmt request @ %p\n", | 389 | dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT "TaskMgmt request (mf=%p)\n", |
| 372 | ioctl->ioc->name, mf)); | 390 | ioc->name, mf)); |
| 373 | 391 | ||
| 374 | pScsiTm = (SCSITaskMgmt_t *) mf; | 392 | pScsiTm = (SCSITaskMgmt_t *) mf; |
| 375 | pScsiTm->TargetID = ioctl->id; | 393 | memset(pScsiTm, 0, sizeof(SCSITaskMgmt_t)); |
| 376 | pScsiTm->Bus = hd->port; /* 0 */ | ||
| 377 | pScsiTm->ChainOffset = 0; | ||
| 378 | pScsiTm->Function = MPI_FUNCTION_SCSI_TASK_MGMT; | 394 | pScsiTm->Function = MPI_FUNCTION_SCSI_TASK_MGMT; |
| 379 | pScsiTm->Reserved = 0; | ||
| 380 | pScsiTm->TaskType = MPI_SCSITASKMGMT_TASKTYPE_RESET_BUS; | 395 | pScsiTm->TaskType = MPI_SCSITASKMGMT_TASKTYPE_RESET_BUS; |
| 381 | pScsiTm->Reserved1 = 0; | ||
| 382 | pScsiTm->MsgFlags = MPI_SCSITASKMGMT_MSGFLAGS_LIPRESET_RESET_OPTION; | 396 | pScsiTm->MsgFlags = MPI_SCSITASKMGMT_MSGFLAGS_LIPRESET_RESET_OPTION; |
| 383 | 397 | pScsiTm->TargetID = 0; | |
| 398 | pScsiTm->Bus = 0; | ||
| 399 | pScsiTm->ChainOffset = 0; | ||
| 400 | pScsiTm->Reserved = 0; | ||
| 401 | pScsiTm->Reserved1 = 0; | ||
| 402 | pScsiTm->TaskMsgContext = 0; | ||
| 384 | for (ii= 0; ii < 8; ii++) | 403 | for (ii= 0; ii < 8; ii++) |
| 385 | pScsiTm->LUN[ii] = 0; | 404 | pScsiTm->LUN[ii] = 0; |
| 386 | |||
| 387 | for (ii=0; ii < 7; ii++) | 405 | for (ii=0; ii < 7; ii++) |
| 388 | pScsiTm->Reserved2[ii] = 0; | 406 | pScsiTm->Reserved2[ii] = 0; |
| 389 | 407 | ||
| 390 | pScsiTm->TaskMsgContext = 0; | 408 | switch (ioc->bus_type) { |
| 391 | dtmprintk(ioctl->ioc, printk(MYIOC_s_DEBUG_FMT | 409 | case FC: |
| 392 | "mptctl_bus_reset: issued.\n", ioctl->ioc->name)); | 410 | timeout = 40; |
| 393 | 411 | break; | |
| 394 | DBG_DUMP_TM_REQUEST_FRAME(ioctl->ioc, (u32 *)mf); | 412 | case SAS: |
| 413 | timeout = 30; | ||
| 414 | break; | ||
| 415 | case SPI: | ||
| 416 | default: | ||
| 417 | timeout = 2; | ||
| 418 | break; | ||
| 419 | } | ||
| 395 | 420 | ||
| 396 | ioctl->wait_done=0; | 421 | dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT |
| 422 | "TaskMgmt type=%d timeout=%ld\n", | ||
| 423 | ioc->name, MPI_SCSITASKMGMT_TASKTYPE_RESET_BUS, timeout)); | ||
| 397 | 424 | ||
| 398 | if ((ioctl->ioc->facts.IOCCapabilities & MPI_IOCFACTS_CAPABILITY_HIGH_PRI_Q) && | 425 | INITIALIZE_MGMT_STATUS(ioc->taskmgmt_cmds.status) |
| 399 | (ioctl->ioc->facts.MsgVersion >= MPI_VERSION_01_05)) | 426 | CLEAR_MGMT_STATUS(ioc->taskmgmt_cmds.status) |
| 400 | mpt_put_msg_frame_hi_pri(mptctl_id, ioctl->ioc, mf); | 427 | time_count = jiffies; |
| 428 | if ((ioc->facts.IOCCapabilities & MPI_IOCFACTS_CAPABILITY_HIGH_PRI_Q) && | ||
| 429 | (ioc->facts.MsgVersion >= MPI_VERSION_01_05)) | ||
| 430 | mpt_put_msg_frame_hi_pri(mptctl_taskmgmt_id, ioc, mf); | ||
| 401 | else { | 431 | else { |
| 402 | retval = mpt_send_handshake_request(mptctl_id, ioctl->ioc, | 432 | retval = mpt_send_handshake_request(mptctl_taskmgmt_id, ioc, |
| 403 | sizeof(SCSITaskMgmt_t), (u32*)pScsiTm, CAN_SLEEP); | 433 | sizeof(SCSITaskMgmt_t), (u32 *)pScsiTm, CAN_SLEEP); |
| 404 | if (retval != 0) { | 434 | if (retval != 0) { |
| 405 | dfailprintk(ioctl->ioc, printk(MYIOC_s_ERR_FMT "_send_handshake FAILED!" | 435 | dfailprintk(ioc, printk(MYIOC_s_ERR_FMT |
| 406 | " (hd %p, ioc %p, mf %p) \n", hd->ioc->name, hd, | 436 | "TaskMgmt send_handshake FAILED!" |
| 407 | hd->ioc, mf)); | 437 | " (ioc %p, mf %p, rc=%d) \n", ioc->name, |
| 438 | ioc, mf, retval)); | ||
| 439 | mpt_clear_taskmgmt_in_progress_flag(ioc); | ||
| 408 | goto mptctl_bus_reset_done; | 440 | goto mptctl_bus_reset_done; |
| 409 | } | 441 | } |
| 410 | } | 442 | } |
| 411 | 443 | ||
| 412 | /* Now wait for the command to complete */ | 444 | /* Now wait for the command to complete */ |
| 413 | ii = wait_event_timeout(mptctl_wait, | 445 | ii = wait_for_completion_timeout(&ioc->taskmgmt_cmds.done, timeout*HZ); |
| 414 | ioctl->wait_done == 1, | 446 | if (!(ioc->taskmgmt_cmds.status & MPT_MGMT_STATUS_COMMAND_GOOD)) { |
| 415 | HZ*5 /* 5 second timeout */); | 447 | dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT |
| 448 | "TaskMgmt failed\n", ioc->name)); | ||
| 449 | mpt_free_msg_frame(ioc, mf); | ||
| 450 | mpt_clear_taskmgmt_in_progress_flag(ioc); | ||
| 451 | if (ioc->taskmgmt_cmds.status & MPT_MGMT_STATUS_DID_IOCRESET) | ||
| 452 | retval = 0; | ||
| 453 | else | ||
| 454 | retval = -1; /* return failure */ | ||
| 455 | goto mptctl_bus_reset_done; | ||
| 456 | } | ||
| 416 | 457 | ||
| 417 | if(ii <=0 && (ioctl->wait_done != 1 )) { | 458 | if (!(ioc->taskmgmt_cmds.status & MPT_MGMT_STATUS_RF_VALID)) { |
| 418 | mpt_free_msg_frame(hd->ioc, mf); | 459 | dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT |
| 419 | ioctl->wait_done = 0; | 460 | "TaskMgmt failed\n", ioc->name)); |
| 461 | retval = -1; /* return failure */ | ||
| 462 | goto mptctl_bus_reset_done; | ||
| 463 | } | ||
| 464 | |||
| 465 | pScsiTmReply = (SCSITaskMgmtReply_t *) ioc->taskmgmt_cmds.reply; | ||
| 466 | dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT | ||
| 467 | "TaskMgmt fw_channel = %d, fw_id = %d, task_type=0x%02X, " | ||
| 468 | "iocstatus=0x%04X\n\tloginfo=0x%08X, response_code=0x%02X, " | ||
| 469 | "term_cmnds=%d\n", ioc->name, pScsiTmReply->Bus, | ||
| 470 | pScsiTmReply->TargetID, MPI_SCSITASKMGMT_TASKTYPE_RESET_BUS, | ||
| 471 | le16_to_cpu(pScsiTmReply->IOCStatus), | ||
| 472 | le32_to_cpu(pScsiTmReply->IOCLogInfo), | ||
| 473 | pScsiTmReply->ResponseCode, | ||
| 474 | le32_to_cpu(pScsiTmReply->TerminationCount))); | ||
| 475 | |||
| 476 | iocstatus = le16_to_cpu(pScsiTmReply->IOCStatus) & MPI_IOCSTATUS_MASK; | ||
| 477 | |||
| 478 | if (iocstatus == MPI_IOCSTATUS_SCSI_TASK_TERMINATED || | ||
| 479 | iocstatus == MPI_IOCSTATUS_SCSI_IOC_TERMINATED || | ||
| 480 | iocstatus == MPI_IOCSTATUS_SUCCESS) | ||
| 481 | retval = 0; | ||
| 482 | else { | ||
| 483 | dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT | ||
| 484 | "TaskMgmt failed\n", ioc->name)); | ||
| 420 | retval = -1; /* return failure */ | 485 | retval = -1; /* return failure */ |
| 421 | } | 486 | } |
| 422 | 487 | ||
| 423 | mptctl_bus_reset_done: | ||
| 424 | 488 | ||
| 425 | mptctl_free_tm_flags(ioctl->ioc); | 489 | mptctl_bus_reset_done: |
| 490 | mutex_unlock(&ioc->taskmgmt_cmds.mutex); | ||
| 491 | CLEAR_MGMT_STATUS(ioc->taskmgmt_cmds.status) | ||
| 426 | return retval; | 492 | return retval; |
| 427 | } | 493 | } |
| 428 | 494 | ||
| 429 | static int | ||
| 430 | mptctl_set_tm_flags(MPT_SCSI_HOST *hd) { | ||
| 431 | unsigned long flags; | ||
| 432 | |||
| 433 | spin_lock_irqsave(&hd->ioc->FreeQlock, flags); | ||
| 434 | |||
| 435 | if (hd->tmState == TM_STATE_NONE) { | ||
| 436 | hd->tmState = TM_STATE_IN_PROGRESS; | ||
| 437 | hd->tmPending = 1; | ||
| 438 | spin_unlock_irqrestore(&hd->ioc->FreeQlock, flags); | ||
| 439 | } else { | ||
| 440 | spin_unlock_irqrestore(&hd->ioc->FreeQlock, flags); | ||
| 441 | return -EBUSY; | ||
| 442 | } | ||
| 443 | |||
| 444 | return 0; | ||
| 445 | } | ||
| 446 | |||
| 447 | static void | ||
| 448 | mptctl_free_tm_flags(MPT_ADAPTER *ioc) | ||
| 449 | { | ||
| 450 | MPT_SCSI_HOST * hd; | ||
| 451 | unsigned long flags; | ||
| 452 | |||
| 453 | hd = shost_priv(ioc->sh); | ||
| 454 | if (hd == NULL) | ||
| 455 | return; | ||
| 456 | |||
| 457 | spin_lock_irqsave(&ioc->FreeQlock, flags); | ||
| 458 | |||
| 459 | hd->tmState = TM_STATE_NONE; | ||
| 460 | hd->tmPending = 0; | ||
| 461 | spin_unlock_irqrestore(&ioc->FreeQlock, flags); | ||
| 462 | |||
| 463 | return; | ||
| 464 | } | ||
| 465 | 495 | ||
| 466 | /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ | 496 | /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ |
| 467 | /* mptctl_ioc_reset | 497 | /* mptctl_ioc_reset |
| @@ -473,22 +503,23 @@ mptctl_free_tm_flags(MPT_ADAPTER *ioc) | |||
| 473 | static int | 503 | static int |
| 474 | mptctl_ioc_reset(MPT_ADAPTER *ioc, int reset_phase) | 504 | mptctl_ioc_reset(MPT_ADAPTER *ioc, int reset_phase) |
| 475 | { | 505 | { |
| 476 | MPT_IOCTL *ioctl = ioc->ioctl; | ||
| 477 | dctlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "IOC %s_reset routed to IOCTL driver!\n", ioc->name, | ||
| 478 | reset_phase==MPT_IOC_SETUP_RESET ? "setup" : ( | ||
| 479 | reset_phase==MPT_IOC_PRE_RESET ? "pre" : "post"))); | ||
| 480 | |||
| 481 | if(ioctl == NULL) | ||
| 482 | return 1; | ||
| 483 | |||
| 484 | switch(reset_phase) { | 506 | switch(reset_phase) { |
| 485 | case MPT_IOC_SETUP_RESET: | 507 | case MPT_IOC_SETUP_RESET: |
| 486 | ioctl->status |= MPT_IOCTL_STATUS_DID_IOCRESET; | 508 | dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT |
| 509 | "%s: MPT_IOC_SETUP_RESET\n", ioc->name, __func__)); | ||
| 510 | break; | ||
| 511 | case MPT_IOC_PRE_RESET: | ||
| 512 | dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT | ||
| 513 | "%s: MPT_IOC_PRE_RESET\n", ioc->name, __func__)); | ||
| 487 | break; | 514 | break; |
| 488 | case MPT_IOC_POST_RESET: | 515 | case MPT_IOC_POST_RESET: |
| 489 | ioctl->status &= ~MPT_IOCTL_STATUS_DID_IOCRESET; | 516 | dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT |
| 517 | "%s: MPT_IOC_POST_RESET\n", ioc->name, __func__)); | ||
| 518 | if (ioc->ioctl_cmds.status & MPT_MGMT_STATUS_PENDING) { | ||
| 519 | ioc->ioctl_cmds.status |= MPT_MGMT_STATUS_DID_IOCRESET; | ||
| 520 | complete(&ioc->ioctl_cmds.done); | ||
| 521 | } | ||
| 490 | break; | 522 | break; |
| 491 | case MPT_IOC_PRE_RESET: | ||
| 492 | default: | 523 | default: |
| 493 | break; | 524 | break; |
| 494 | } | 525 | } |
| @@ -642,7 +673,7 @@ __mptctl_ioctl(struct file *file, unsigned int cmd, unsigned long arg) | |||
| 642 | else | 673 | else |
| 643 | ret = -EINVAL; | 674 | ret = -EINVAL; |
| 644 | 675 | ||
| 645 | mutex_unlock(&iocp->ioctl->ioctl_mutex); | 676 | mutex_unlock(&iocp->ioctl_cmds.mutex); |
| 646 | 677 | ||
| 647 | return ret; | 678 | return ret; |
| 648 | } | 679 | } |
| @@ -758,6 +789,7 @@ mptctl_do_fw_download(int ioc, char __user *ufwbuf, size_t fwlen) | |||
| 758 | int sge_offset = 0; | 789 | int sge_offset = 0; |
| 759 | u16 iocstat; | 790 | u16 iocstat; |
| 760 | pFWDownloadReply_t ReplyMsg = NULL; | 791 | pFWDownloadReply_t ReplyMsg = NULL; |
| 792 | unsigned long timeleft; | ||
| 761 | 793 | ||
| 762 | if (mpt_verify_adapter(ioc, &iocp) < 0) { | 794 | if (mpt_verify_adapter(ioc, &iocp) < 0) { |
| 763 | printk(KERN_DEBUG MYNAM "ioctl_fwdl - ioc%d not found!\n", | 795 | printk(KERN_DEBUG MYNAM "ioctl_fwdl - ioc%d not found!\n", |
| @@ -841,8 +873,9 @@ mptctl_do_fw_download(int ioc, char __user *ufwbuf, size_t fwlen) | |||
| 841 | * 96 8 | 873 | * 96 8 |
| 842 | * 64 4 | 874 | * 64 4 |
| 843 | */ | 875 | */ |
| 844 | maxfrags = (iocp->req_sz - sizeof(MPIHeader_t) - sizeof(FWDownloadTCSGE_t)) | 876 | maxfrags = (iocp->req_sz - sizeof(MPIHeader_t) - |
| 845 | / (sizeof(dma_addr_t) + sizeof(u32)); | 877 | sizeof(FWDownloadTCSGE_t)) |
| 878 | / iocp->SGE_size; | ||
| 846 | if (numfrags > maxfrags) { | 879 | if (numfrags > maxfrags) { |
| 847 | ret = -EMLINK; | 880 | ret = -EMLINK; |
| 848 | goto fwdl_out; | 881 | goto fwdl_out; |
| @@ -870,7 +903,7 @@ mptctl_do_fw_download(int ioc, char __user *ufwbuf, size_t fwlen) | |||
| 870 | if (nib == 0 || nib == 3) { | 903 | if (nib == 0 || nib == 3) { |
| 871 | ; | 904 | ; |
| 872 | } else if (sgIn->Address) { | 905 | } else if (sgIn->Address) { |
| 873 | mpt_add_sge(sgOut, sgIn->FlagsLength, sgIn->Address); | 906 | iocp->add_sge(sgOut, sgIn->FlagsLength, sgIn->Address); |
| 874 | n++; | 907 | n++; |
| 875 | if (copy_from_user(bl->kptr, ufwbuf+fw_bytes_copied, bl->len)) { | 908 | if (copy_from_user(bl->kptr, ufwbuf+fw_bytes_copied, bl->len)) { |
| 876 | printk(MYIOC_s_ERR_FMT "%s@%d::_ioctl_fwdl - " | 909 | printk(MYIOC_s_ERR_FMT "%s@%d::_ioctl_fwdl - " |
| @@ -882,7 +915,7 @@ mptctl_do_fw_download(int ioc, char __user *ufwbuf, size_t fwlen) | |||
| 882 | } | 915 | } |
| 883 | sgIn++; | 916 | sgIn++; |
| 884 | bl++; | 917 | bl++; |
| 885 | sgOut += (sizeof(dma_addr_t) + sizeof(u32)); | 918 | sgOut += iocp->SGE_size; |
| 886 | } | 919 | } |
| 887 | 920 | ||
| 888 | DBG_DUMP_FW_DOWNLOAD(iocp, (u32 *)mf, numfrags); | 921 | DBG_DUMP_FW_DOWNLOAD(iocp, (u32 *)mf, numfrags); |
| @@ -891,16 +924,30 @@ mptctl_do_fw_download(int ioc, char __user *ufwbuf, size_t fwlen) | |||
| 891 | * Finally, perform firmware download. | 924 | * Finally, perform firmware download. |
| 892 | */ | 925 | */ |
| 893 | ReplyMsg = NULL; | 926 | ReplyMsg = NULL; |
| 927 | SET_MGMT_MSG_CONTEXT(iocp->ioctl_cmds.msg_context, dlmsg->MsgContext); | ||
| 928 | INITIALIZE_MGMT_STATUS(iocp->ioctl_cmds.status) | ||
| 894 | mpt_put_msg_frame(mptctl_id, iocp, mf); | 929 | mpt_put_msg_frame(mptctl_id, iocp, mf); |
| 895 | 930 | ||
| 896 | /* Now wait for the command to complete */ | 931 | /* Now wait for the command to complete */ |
| 897 | ret = wait_event_timeout(mptctl_wait, | 932 | retry_wait: |
| 898 | iocp->ioctl->wait_done == 1, | 933 | timeleft = wait_for_completion_timeout(&iocp->ioctl_cmds.done, HZ*60); |
| 899 | HZ*60); | 934 | if (!(iocp->ioctl_cmds.status & MPT_MGMT_STATUS_COMMAND_GOOD)) { |
| 935 | ret = -ETIME; | ||
| 936 | printk(MYIOC_s_WARN_FMT "%s: failed\n", iocp->name, __func__); | ||
| 937 | if (iocp->ioctl_cmds.status & MPT_MGMT_STATUS_DID_IOCRESET) { | ||
| 938 | mpt_free_msg_frame(iocp, mf); | ||
| 939 | goto fwdl_out; | ||
| 940 | } | ||
| 941 | if (!timeleft) | ||
| 942 | mptctl_timeout_expired(iocp, mf); | ||
| 943 | else | ||
| 944 | goto retry_wait; | ||
| 945 | goto fwdl_out; | ||
| 946 | } | ||
| 900 | 947 | ||
| 901 | if(ret <=0 && (iocp->ioctl->wait_done != 1 )) { | 948 | if (!(iocp->ioctl_cmds.status & MPT_MGMT_STATUS_RF_VALID)) { |
| 902 | /* Now we need to reset the board */ | 949 | printk(MYIOC_s_WARN_FMT "%s: failed\n", iocp->name, __func__); |
| 903 | mptctl_timeout_expired(iocp->ioctl); | 950 | mpt_free_msg_frame(iocp, mf); |
| 904 | ret = -ENODATA; | 951 | ret = -ENODATA; |
| 905 | goto fwdl_out; | 952 | goto fwdl_out; |
| 906 | } | 953 | } |
| @@ -908,7 +955,7 @@ mptctl_do_fw_download(int ioc, char __user *ufwbuf, size_t fwlen) | |||
| 908 | if (sgl) | 955 | if (sgl) |
| 909 | kfree_sgl(sgl, sgl_dma, buflist, iocp); | 956 | kfree_sgl(sgl, sgl_dma, buflist, iocp); |
| 910 | 957 | ||
| 911 | ReplyMsg = (pFWDownloadReply_t)iocp->ioctl->ReplyFrame; | 958 | ReplyMsg = (pFWDownloadReply_t)iocp->ioctl_cmds.reply; |
| 912 | iocstat = le16_to_cpu(ReplyMsg->IOCStatus) & MPI_IOCSTATUS_MASK; | 959 | iocstat = le16_to_cpu(ReplyMsg->IOCStatus) & MPI_IOCSTATUS_MASK; |
| 913 | if (iocstat == MPI_IOCSTATUS_SUCCESS) { | 960 | if (iocstat == MPI_IOCSTATUS_SUCCESS) { |
| 914 | printk(MYIOC_s_INFO_FMT "F/W update successfull!\n", iocp->name); | 961 | printk(MYIOC_s_INFO_FMT "F/W update successfull!\n", iocp->name); |
| @@ -932,6 +979,9 @@ mptctl_do_fw_download(int ioc, char __user *ufwbuf, size_t fwlen) | |||
| 932 | return 0; | 979 | return 0; |
| 933 | 980 | ||
| 934 | fwdl_out: | 981 | fwdl_out: |
| 982 | |||
| 983 | CLEAR_MGMT_STATUS(iocp->ioctl_cmds.status); | ||
| 984 | SET_MGMT_MSG_CONTEXT(iocp->ioctl_cmds.msg_context, 0); | ||
| 935 | kfree_sgl(sgl, sgl_dma, buflist, iocp); | 985 | kfree_sgl(sgl, sgl_dma, buflist, iocp); |
| 936 | return ret; | 986 | return ret; |
| 937 | } | 987 | } |
| @@ -1003,7 +1053,7 @@ kbuf_alloc_2_sgl(int bytes, u32 sgdir, int sge_offset, int *frags, | |||
| 1003 | * | 1053 | * |
| 1004 | */ | 1054 | */ |
| 1005 | sgl = sglbuf; | 1055 | sgl = sglbuf; |
| 1006 | sg_spill = ((ioc->req_sz - sge_offset)/(sizeof(dma_addr_t) + sizeof(u32))) - 1; | 1056 | sg_spill = ((ioc->req_sz - sge_offset)/ioc->SGE_size) - 1; |
| 1007 | while (bytes_allocd < bytes) { | 1057 | while (bytes_allocd < bytes) { |
| 1008 | this_alloc = min(alloc_sz, bytes-bytes_allocd); | 1058 | this_alloc = min(alloc_sz, bytes-bytes_allocd); |
| 1009 | buflist[buflist_ent].len = this_alloc; | 1059 | buflist[buflist_ent].len = this_alloc; |
| @@ -1024,8 +1074,9 @@ kbuf_alloc_2_sgl(int bytes, u32 sgdir, int sge_offset, int *frags, | |||
| 1024 | dma_addr_t dma_addr; | 1074 | dma_addr_t dma_addr; |
| 1025 | 1075 | ||
| 1026 | bytes_allocd += this_alloc; | 1076 | bytes_allocd += this_alloc; |
| 1027 | sgl->FlagsLength = (0x10000000|MPT_SGE_FLAGS_ADDRESSING|sgdir|this_alloc); | 1077 | sgl->FlagsLength = (0x10000000|sgdir|this_alloc); |
| 1028 | dma_addr = pci_map_single(ioc->pcidev, buflist[buflist_ent].kptr, this_alloc, dir); | 1078 | dma_addr = pci_map_single(ioc->pcidev, |
| 1079 | buflist[buflist_ent].kptr, this_alloc, dir); | ||
| 1029 | sgl->Address = dma_addr; | 1080 | sgl->Address = dma_addr; |
| 1030 | 1081 | ||
| 1031 | fragcnt++; | 1082 | fragcnt++; |
| @@ -1771,7 +1822,10 @@ mptctl_do_mpt_command (struct mpt_ioctl_command karg, void __user *mfPtr) | |||
| 1771 | int msgContext; | 1822 | int msgContext; |
| 1772 | u16 req_idx; | 1823 | u16 req_idx; |
| 1773 | ulong timeout; | 1824 | ulong timeout; |
| 1825 | unsigned long timeleft; | ||
| 1774 | struct scsi_device *sdev; | 1826 | struct scsi_device *sdev; |
| 1827 | unsigned long flags; | ||
| 1828 | u8 function; | ||
| 1775 | 1829 | ||
| 1776 | /* bufIn and bufOut are used for user to kernel space transfers | 1830 | /* bufIn and bufOut are used for user to kernel space transfers |
| 1777 | */ | 1831 | */ |
| @@ -1784,24 +1838,23 @@ mptctl_do_mpt_command (struct mpt_ioctl_command karg, void __user *mfPtr) | |||
| 1784 | __FILE__, __LINE__, iocnum); | 1838 | __FILE__, __LINE__, iocnum); |
| 1785 | return -ENODEV; | 1839 | return -ENODEV; |
| 1786 | } | 1840 | } |
| 1787 | if (!ioc->ioctl) { | 1841 | |
| 1788 | printk(KERN_ERR MYNAM "%s@%d::mptctl_do_mpt_command - " | 1842 | spin_lock_irqsave(&ioc->taskmgmt_lock, flags); |
| 1789 | "No memory available during driver init.\n", | 1843 | if (ioc->ioc_reset_in_progress) { |
| 1790 | __FILE__, __LINE__); | 1844 | spin_unlock_irqrestore(&ioc->taskmgmt_lock, flags); |
| 1791 | return -ENOMEM; | ||
| 1792 | } else if (ioc->ioctl->status & MPT_IOCTL_STATUS_DID_IOCRESET) { | ||
| 1793 | printk(KERN_ERR MYNAM "%s@%d::mptctl_do_mpt_command - " | 1845 | printk(KERN_ERR MYNAM "%s@%d::mptctl_do_mpt_command - " |
| 1794 | "Busy with IOC Reset \n", __FILE__, __LINE__); | 1846 | "Busy with diagnostic reset\n", __FILE__, __LINE__); |
| 1795 | return -EBUSY; | 1847 | return -EBUSY; |
| 1796 | } | 1848 | } |
| 1849 | spin_unlock_irqrestore(&ioc->taskmgmt_lock, flags); | ||
| 1797 | 1850 | ||
| 1798 | /* Verify that the final request frame will not be too large. | 1851 | /* Verify that the final request frame will not be too large. |
| 1799 | */ | 1852 | */ |
| 1800 | sz = karg.dataSgeOffset * 4; | 1853 | sz = karg.dataSgeOffset * 4; |
| 1801 | if (karg.dataInSize > 0) | 1854 | if (karg.dataInSize > 0) |
| 1802 | sz += sizeof(dma_addr_t) + sizeof(u32); | 1855 | sz += ioc->SGE_size; |
| 1803 | if (karg.dataOutSize > 0) | 1856 | if (karg.dataOutSize > 0) |
| 1804 | sz += sizeof(dma_addr_t) + sizeof(u32); | 1857 | sz += ioc->SGE_size; |
| 1805 | 1858 | ||
| 1806 | if (sz > ioc->req_sz) { | 1859 | if (sz > ioc->req_sz) { |
| 1807 | printk(MYIOC_s_ERR_FMT "%s@%d::mptctl_do_mpt_command - " | 1860 | printk(MYIOC_s_ERR_FMT "%s@%d::mptctl_do_mpt_command - " |
| @@ -1827,10 +1880,12 @@ mptctl_do_mpt_command (struct mpt_ioctl_command karg, void __user *mfPtr) | |||
| 1827 | printk(MYIOC_s_ERR_FMT "%s@%d::mptctl_do_mpt_command - " | 1880 | printk(MYIOC_s_ERR_FMT "%s@%d::mptctl_do_mpt_command - " |
| 1828 | "Unable to read MF from mpt_ioctl_command struct @ %p\n", | 1881 | "Unable to read MF from mpt_ioctl_command struct @ %p\n", |
| 1829 | ioc->name, __FILE__, __LINE__, mfPtr); | 1882 | ioc->name, __FILE__, __LINE__, mfPtr); |
| 1883 | function = -1; | ||
| 1830 | rc = -EFAULT; | 1884 | rc = -EFAULT; |
| 1831 | goto done_free_mem; | 1885 | goto done_free_mem; |
| 1832 | } | 1886 | } |
| 1833 | hdr->MsgContext = cpu_to_le32(msgContext); | 1887 | hdr->MsgContext = cpu_to_le32(msgContext); |
| 1888 | function = hdr->Function; | ||
| 1834 | 1889 | ||
| 1835 | 1890 | ||
| 1836 | /* Verify that this request is allowed. | 1891 | /* Verify that this request is allowed. |
| @@ -1838,7 +1893,7 @@ mptctl_do_mpt_command (struct mpt_ioctl_command karg, void __user *mfPtr) | |||
| 1838 | dctlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sending mpi function (0x%02X), req=%p\n", | 1893 | dctlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sending mpi function (0x%02X), req=%p\n", |
| 1839 | ioc->name, hdr->Function, mf)); | 1894 | ioc->name, hdr->Function, mf)); |
| 1840 | 1895 | ||
| 1841 | switch (hdr->Function) { | 1896 | switch (function) { |
| 1842 | case MPI_FUNCTION_IOC_FACTS: | 1897 | case MPI_FUNCTION_IOC_FACTS: |
| 1843 | case MPI_FUNCTION_PORT_FACTS: | 1898 | case MPI_FUNCTION_PORT_FACTS: |
| 1844 | karg.dataOutSize = karg.dataInSize = 0; | 1899 | karg.dataOutSize = karg.dataInSize = 0; |
| @@ -1893,7 +1948,7 @@ mptctl_do_mpt_command (struct mpt_ioctl_command karg, void __user *mfPtr) | |||
| 1893 | } | 1948 | } |
| 1894 | 1949 | ||
| 1895 | pScsiReq->MsgFlags &= ~MPI_SCSIIO_MSGFLGS_SENSE_WIDTH; | 1950 | pScsiReq->MsgFlags &= ~MPI_SCSIIO_MSGFLGS_SENSE_WIDTH; |
| 1896 | pScsiReq->MsgFlags |= mpt_msg_flags(); | 1951 | pScsiReq->MsgFlags |= mpt_msg_flags(ioc); |
| 1897 | 1952 | ||
| 1898 | 1953 | ||
| 1899 | /* verify that app has not requested | 1954 | /* verify that app has not requested |
| @@ -1935,8 +1990,6 @@ mptctl_do_mpt_command (struct mpt_ioctl_command karg, void __user *mfPtr) | |||
| 1935 | pScsiReq->Control = cpu_to_le32(scsidir | qtag); | 1990 | pScsiReq->Control = cpu_to_le32(scsidir | qtag); |
| 1936 | pScsiReq->DataLength = cpu_to_le32(dataSize); | 1991 | pScsiReq->DataLength = cpu_to_le32(dataSize); |
| 1937 | 1992 | ||
| 1938 | ioc->ioctl->reset = MPTCTL_RESET_OK; | ||
| 1939 | ioc->ioctl->id = pScsiReq->TargetID; | ||
| 1940 | 1993 | ||
| 1941 | } else { | 1994 | } else { |
| 1942 | printk(MYIOC_s_ERR_FMT "%s@%d::mptctl_do_mpt_command - " | 1995 | printk(MYIOC_s_ERR_FMT "%s@%d::mptctl_do_mpt_command - " |
| @@ -1979,7 +2032,7 @@ mptctl_do_mpt_command (struct mpt_ioctl_command karg, void __user *mfPtr) | |||
| 1979 | int dataSize; | 2032 | int dataSize; |
| 1980 | 2033 | ||
| 1981 | pScsiReq->MsgFlags &= ~MPI_SCSIIO_MSGFLGS_SENSE_WIDTH; | 2034 | pScsiReq->MsgFlags &= ~MPI_SCSIIO_MSGFLGS_SENSE_WIDTH; |
| 1982 | pScsiReq->MsgFlags |= mpt_msg_flags(); | 2035 | pScsiReq->MsgFlags |= mpt_msg_flags(ioc); |
| 1983 | 2036 | ||
| 1984 | 2037 | ||
| 1985 | /* verify that app has not requested | 2038 | /* verify that app has not requested |
| @@ -2014,8 +2067,6 @@ mptctl_do_mpt_command (struct mpt_ioctl_command karg, void __user *mfPtr) | |||
| 2014 | pScsiReq->Control = cpu_to_le32(scsidir | qtag); | 2067 | pScsiReq->Control = cpu_to_le32(scsidir | qtag); |
| 2015 | pScsiReq->DataLength = cpu_to_le32(dataSize); | 2068 | pScsiReq->DataLength = cpu_to_le32(dataSize); |
| 2016 | 2069 | ||
| 2017 | ioc->ioctl->reset = MPTCTL_RESET_OK; | ||
| 2018 | ioc->ioctl->id = pScsiReq->TargetID; | ||
| 2019 | } else { | 2070 | } else { |
| 2020 | printk(MYIOC_s_ERR_FMT "%s@%d::mptctl_do_mpt_command - " | 2071 | printk(MYIOC_s_ERR_FMT "%s@%d::mptctl_do_mpt_command - " |
| 2021 | "SCSI driver is not loaded. \n", | 2072 | "SCSI driver is not loaded. \n", |
| @@ -2026,20 +2077,17 @@ mptctl_do_mpt_command (struct mpt_ioctl_command karg, void __user *mfPtr) | |||
| 2026 | break; | 2077 | break; |
| 2027 | 2078 | ||
| 2028 | case MPI_FUNCTION_SCSI_TASK_MGMT: | 2079 | case MPI_FUNCTION_SCSI_TASK_MGMT: |
| 2029 | { | 2080 | { |
| 2030 | MPT_SCSI_HOST *hd = NULL; | 2081 | SCSITaskMgmt_t *pScsiTm; |
| 2031 | if ((ioc->sh == NULL) || ((hd = shost_priv(ioc->sh)) == NULL)) { | 2082 | pScsiTm = (SCSITaskMgmt_t *)mf; |
| 2032 | printk(MYIOC_s_ERR_FMT "%s@%d::mptctl_do_mpt_command - " | 2083 | dctlprintk(ioc, printk(MYIOC_s_DEBUG_FMT |
| 2033 | "SCSI driver not loaded or SCSI host not found. \n", | 2084 | "\tTaskType=0x%x MsgFlags=0x%x " |
| 2034 | ioc->name, __FILE__, __LINE__); | 2085 | "TaskMsgContext=0x%x id=%d channel=%d\n", |
| 2035 | rc = -EFAULT; | 2086 | ioc->name, pScsiTm->TaskType, le32_to_cpu |
| 2036 | goto done_free_mem; | 2087 | (pScsiTm->TaskMsgContext), pScsiTm->MsgFlags, |
| 2037 | } else if (mptctl_set_tm_flags(hd) != 0) { | 2088 | pScsiTm->TargetID, pScsiTm->Bus)); |
| 2038 | rc = -EPERM; | ||
| 2039 | goto done_free_mem; | ||
| 2040 | } | ||
| 2041 | } | ||
| 2042 | break; | 2089 | break; |
| 2090 | } | ||
| 2043 | 2091 | ||
| 2044 | case MPI_FUNCTION_IOC_INIT: | 2092 | case MPI_FUNCTION_IOC_INIT: |
| 2045 | { | 2093 | { |
| @@ -2123,8 +2171,7 @@ mptctl_do_mpt_command (struct mpt_ioctl_command karg, void __user *mfPtr) | |||
| 2123 | if (karg.dataInSize > 0) { | 2171 | if (karg.dataInSize > 0) { |
| 2124 | flagsLength = ( MPI_SGE_FLAGS_SIMPLE_ELEMENT | | 2172 | flagsLength = ( MPI_SGE_FLAGS_SIMPLE_ELEMENT | |
| 2125 | MPI_SGE_FLAGS_END_OF_BUFFER | | 2173 | MPI_SGE_FLAGS_END_OF_BUFFER | |
| 2126 | MPI_SGE_FLAGS_DIRECTION | | 2174 | MPI_SGE_FLAGS_DIRECTION) |
| 2127 | mpt_addr_size() ) | ||
| 2128 | << MPI_SGE_FLAGS_SHIFT; | 2175 | << MPI_SGE_FLAGS_SHIFT; |
| 2129 | } else { | 2176 | } else { |
| 2130 | flagsLength = MPT_SGE_FLAGS_SSIMPLE_WRITE; | 2177 | flagsLength = MPT_SGE_FLAGS_SSIMPLE_WRITE; |
| @@ -2141,8 +2188,8 @@ mptctl_do_mpt_command (struct mpt_ioctl_command karg, void __user *mfPtr) | |||
| 2141 | /* Set up this SGE. | 2188 | /* Set up this SGE. |
| 2142 | * Copy to MF and to sglbuf | 2189 | * Copy to MF and to sglbuf |
| 2143 | */ | 2190 | */ |
| 2144 | mpt_add_sge(psge, flagsLength, dma_addr_out); | 2191 | ioc->add_sge(psge, flagsLength, dma_addr_out); |
| 2145 | psge += (sizeof(u32) + sizeof(dma_addr_t)); | 2192 | psge += ioc->SGE_size; |
| 2146 | 2193 | ||
| 2147 | /* Copy user data to kernel space. | 2194 | /* Copy user data to kernel space. |
| 2148 | */ | 2195 | */ |
| @@ -2175,18 +2222,25 @@ mptctl_do_mpt_command (struct mpt_ioctl_command karg, void __user *mfPtr) | |||
| 2175 | /* Set up this SGE | 2222 | /* Set up this SGE |
| 2176 | * Copy to MF and to sglbuf | 2223 | * Copy to MF and to sglbuf |
| 2177 | */ | 2224 | */ |
| 2178 | mpt_add_sge(psge, flagsLength, dma_addr_in); | 2225 | ioc->add_sge(psge, flagsLength, dma_addr_in); |
| 2179 | } | 2226 | } |
| 2180 | } | 2227 | } |
| 2181 | } else { | 2228 | } else { |
| 2182 | /* Add a NULL SGE | 2229 | /* Add a NULL SGE |
| 2183 | */ | 2230 | */ |
| 2184 | mpt_add_sge(psge, flagsLength, (dma_addr_t) -1); | 2231 | ioc->add_sge(psge, flagsLength, (dma_addr_t) -1); |
| 2185 | } | 2232 | } |
| 2186 | 2233 | ||
| 2187 | ioc->ioctl->wait_done = 0; | 2234 | SET_MGMT_MSG_CONTEXT(ioc->ioctl_cmds.msg_context, hdr->MsgContext); |
| 2235 | INITIALIZE_MGMT_STATUS(ioc->ioctl_cmds.status) | ||
| 2188 | if (hdr->Function == MPI_FUNCTION_SCSI_TASK_MGMT) { | 2236 | if (hdr->Function == MPI_FUNCTION_SCSI_TASK_MGMT) { |
| 2189 | 2237 | ||
| 2238 | mutex_lock(&ioc->taskmgmt_cmds.mutex); | ||
| 2239 | if (mpt_set_taskmgmt_in_progress_flag(ioc) != 0) { | ||
| 2240 | mutex_unlock(&ioc->taskmgmt_cmds.mutex); | ||
| 2241 | goto done_free_mem; | ||
| 2242 | } | ||
| 2243 | |||
| 2190 | DBG_DUMP_TM_REQUEST_FRAME(ioc, (u32 *)mf); | 2244 | DBG_DUMP_TM_REQUEST_FRAME(ioc, (u32 *)mf); |
| 2191 | 2245 | ||
| 2192 | if ((ioc->facts.IOCCapabilities & MPI_IOCFACTS_CAPABILITY_HIGH_PRI_Q) && | 2246 | if ((ioc->facts.IOCCapabilities & MPI_IOCFACTS_CAPABILITY_HIGH_PRI_Q) && |
| @@ -2197,10 +2251,11 @@ mptctl_do_mpt_command (struct mpt_ioctl_command karg, void __user *mfPtr) | |||
| 2197 | sizeof(SCSITaskMgmt_t), (u32*)mf, CAN_SLEEP); | 2251 | sizeof(SCSITaskMgmt_t), (u32*)mf, CAN_SLEEP); |
| 2198 | if (rc != 0) { | 2252 | if (rc != 0) { |
| 2199 | dfailprintk(ioc, printk(MYIOC_s_ERR_FMT | 2253 | dfailprintk(ioc, printk(MYIOC_s_ERR_FMT |
| 2200 | "_send_handshake FAILED! (ioc %p, mf %p)\n", | 2254 | "send_handshake FAILED! (ioc %p, mf %p)\n", |
| 2201 | ioc->name, ioc, mf)); | 2255 | ioc->name, ioc, mf)); |
| 2202 | mptctl_free_tm_flags(ioc); | 2256 | mpt_clear_taskmgmt_in_progress_flag(ioc); |
| 2203 | rc = -ENODATA; | 2257 | rc = -ENODATA; |
| 2258 | mutex_unlock(&ioc->taskmgmt_cmds.mutex); | ||
| 2204 | goto done_free_mem; | 2259 | goto done_free_mem; |
| 2205 | } | 2260 | } |
| 2206 | } | 2261 | } |
| @@ -2210,36 +2265,47 @@ mptctl_do_mpt_command (struct mpt_ioctl_command karg, void __user *mfPtr) | |||
| 2210 | 2265 | ||
| 2211 | /* Now wait for the command to complete */ | 2266 | /* Now wait for the command to complete */ |
| 2212 | timeout = (karg.timeout > 0) ? karg.timeout : MPT_IOCTL_DEFAULT_TIMEOUT; | 2267 | timeout = (karg.timeout > 0) ? karg.timeout : MPT_IOCTL_DEFAULT_TIMEOUT; |
| 2213 | timeout = wait_event_timeout(mptctl_wait, | 2268 | retry_wait: |
| 2214 | ioc->ioctl->wait_done == 1, | 2269 | timeleft = wait_for_completion_timeout(&ioc->ioctl_cmds.done, |
| 2215 | HZ*timeout); | 2270 | HZ*timeout); |
| 2216 | 2271 | if (!(ioc->ioctl_cmds.status & MPT_MGMT_STATUS_COMMAND_GOOD)) { | |
| 2217 | if(timeout <=0 && (ioc->ioctl->wait_done != 1 )) { | 2272 | rc = -ETIME; |
| 2218 | /* Now we need to reset the board */ | 2273 | dfailprintk(ioc, printk(MYIOC_s_ERR_FMT "%s: TIMED OUT!\n", |
| 2219 | 2274 | ioc->name, __func__)); | |
| 2220 | if (hdr->Function == MPI_FUNCTION_SCSI_TASK_MGMT) | 2275 | if (ioc->ioctl_cmds.status & MPT_MGMT_STATUS_DID_IOCRESET) { |
| 2221 | mptctl_free_tm_flags(ioc); | 2276 | if (function == MPI_FUNCTION_SCSI_TASK_MGMT) |
| 2222 | 2277 | mutex_unlock(&ioc->taskmgmt_cmds.mutex); | |
| 2223 | mptctl_timeout_expired(ioc->ioctl); | 2278 | goto done_free_mem; |
| 2224 | rc = -ENODATA; | 2279 | } |
| 2280 | if (!timeleft) { | ||
| 2281 | if (function == MPI_FUNCTION_SCSI_TASK_MGMT) | ||
| 2282 | mutex_unlock(&ioc->taskmgmt_cmds.mutex); | ||
| 2283 | mptctl_timeout_expired(ioc, mf); | ||
| 2284 | mf = NULL; | ||
| 2285 | } else | ||
| 2286 | goto retry_wait; | ||
| 2225 | goto done_free_mem; | 2287 | goto done_free_mem; |
| 2226 | } | 2288 | } |
| 2227 | 2289 | ||
| 2290 | if (function == MPI_FUNCTION_SCSI_TASK_MGMT) | ||
| 2291 | mutex_unlock(&ioc->taskmgmt_cmds.mutex); | ||
| 2292 | |||
| 2293 | |||
| 2228 | mf = NULL; | 2294 | mf = NULL; |
| 2229 | 2295 | ||
| 2230 | /* If a valid reply frame, copy to the user. | 2296 | /* If a valid reply frame, copy to the user. |
| 2231 | * Offset 2: reply length in U32's | 2297 | * Offset 2: reply length in U32's |
| 2232 | */ | 2298 | */ |
| 2233 | if (ioc->ioctl->status & MPT_IOCTL_STATUS_RF_VALID) { | 2299 | if (ioc->ioctl_cmds.status & MPT_MGMT_STATUS_RF_VALID) { |
| 2234 | if (karg.maxReplyBytes < ioc->reply_sz) { | 2300 | if (karg.maxReplyBytes < ioc->reply_sz) { |
| 2235 | sz = min(karg.maxReplyBytes, 4*ioc->ioctl->ReplyFrame[2]); | 2301 | sz = min(karg.maxReplyBytes, |
| 2302 | 4*ioc->ioctl_cmds.reply[2]); | ||
| 2236 | } else { | 2303 | } else { |
| 2237 | sz = min(ioc->reply_sz, 4*ioc->ioctl->ReplyFrame[2]); | 2304 | sz = min(ioc->reply_sz, 4*ioc->ioctl_cmds.reply[2]); |
| 2238 | } | 2305 | } |
| 2239 | |||
| 2240 | if (sz > 0) { | 2306 | if (sz > 0) { |
| 2241 | if (copy_to_user(karg.replyFrameBufPtr, | 2307 | if (copy_to_user(karg.replyFrameBufPtr, |
| 2242 | &ioc->ioctl->ReplyFrame, sz)){ | 2308 | ioc->ioctl_cmds.reply, sz)){ |
| 2243 | printk(MYIOC_s_ERR_FMT | 2309 | printk(MYIOC_s_ERR_FMT |
| 2244 | "%s@%d::mptctl_do_mpt_command - " | 2310 | "%s@%d::mptctl_do_mpt_command - " |
| 2245 | "Unable to write out reply frame %p\n", | 2311 | "Unable to write out reply frame %p\n", |
| @@ -2252,10 +2318,11 @@ mptctl_do_mpt_command (struct mpt_ioctl_command karg, void __user *mfPtr) | |||
| 2252 | 2318 | ||
| 2253 | /* If valid sense data, copy to user. | 2319 | /* If valid sense data, copy to user. |
| 2254 | */ | 2320 | */ |
| 2255 | if (ioc->ioctl->status & MPT_IOCTL_STATUS_SENSE_VALID) { | 2321 | if (ioc->ioctl_cmds.status & MPT_MGMT_STATUS_SENSE_VALID) { |
| 2256 | sz = min(karg.maxSenseBytes, MPT_SENSE_BUFFER_SIZE); | 2322 | sz = min(karg.maxSenseBytes, MPT_SENSE_BUFFER_SIZE); |
| 2257 | if (sz > 0) { | 2323 | if (sz > 0) { |
| 2258 | if (copy_to_user(karg.senseDataPtr, ioc->ioctl->sense, sz)) { | 2324 | if (copy_to_user(karg.senseDataPtr, |
| 2325 | ioc->ioctl_cmds.sense, sz)) { | ||
| 2259 | printk(MYIOC_s_ERR_FMT "%s@%d::mptctl_do_mpt_command - " | 2326 | printk(MYIOC_s_ERR_FMT "%s@%d::mptctl_do_mpt_command - " |
| 2260 | "Unable to write sense data to user %p\n", | 2327 | "Unable to write sense data to user %p\n", |
| 2261 | ioc->name, __FILE__, __LINE__, | 2328 | ioc->name, __FILE__, __LINE__, |
| @@ -2269,7 +2336,7 @@ mptctl_do_mpt_command (struct mpt_ioctl_command karg, void __user *mfPtr) | |||
| 2269 | /* If the overall status is _GOOD and data in, copy data | 2336 | /* If the overall status is _GOOD and data in, copy data |
| 2270 | * to user. | 2337 | * to user. |
| 2271 | */ | 2338 | */ |
| 2272 | if ((ioc->ioctl->status & MPT_IOCTL_STATUS_COMMAND_GOOD) && | 2339 | if ((ioc->ioctl_cmds.status & MPT_MGMT_STATUS_COMMAND_GOOD) && |
| 2273 | (karg.dataInSize > 0) && (bufIn.kptr)) { | 2340 | (karg.dataInSize > 0) && (bufIn.kptr)) { |
| 2274 | 2341 | ||
| 2275 | if (copy_to_user(karg.dataInBufPtr, | 2342 | if (copy_to_user(karg.dataInBufPtr, |
| @@ -2284,9 +2351,8 @@ mptctl_do_mpt_command (struct mpt_ioctl_command karg, void __user *mfPtr) | |||
| 2284 | 2351 | ||
| 2285 | done_free_mem: | 2352 | done_free_mem: |
| 2286 | 2353 | ||
| 2287 | ioc->ioctl->status &= ~(MPT_IOCTL_STATUS_COMMAND_GOOD | | 2354 | CLEAR_MGMT_STATUS(ioc->ioctl_cmds.status) |
| 2288 | MPT_IOCTL_STATUS_SENSE_VALID | | 2355 | SET_MGMT_MSG_CONTEXT(ioc->ioctl_cmds.msg_context, 0); |
| 2289 | MPT_IOCTL_STATUS_RF_VALID ); | ||
| 2290 | 2356 | ||
| 2291 | /* Free the allocated memory. | 2357 | /* Free the allocated memory. |
| 2292 | */ | 2358 | */ |
| @@ -2336,6 +2402,8 @@ mptctl_hp_hostinfo(unsigned long arg, unsigned int data_size) | |||
| 2336 | ToolboxIstwiReadWriteRequest_t *IstwiRWRequest; | 2402 | ToolboxIstwiReadWriteRequest_t *IstwiRWRequest; |
| 2337 | MPT_FRAME_HDR *mf = NULL; | 2403 | MPT_FRAME_HDR *mf = NULL; |
| 2338 | MPIHeader_t *mpi_hdr; | 2404 | MPIHeader_t *mpi_hdr; |
| 2405 | unsigned long timeleft; | ||
| 2406 | int retval; | ||
| 2339 | 2407 | ||
| 2340 | /* Reset long to int. Should affect IA64 and SPARC only | 2408 | /* Reset long to int. Should affect IA64 and SPARC only |
| 2341 | */ | 2409 | */ |
| @@ -2466,9 +2534,9 @@ mptctl_hp_hostinfo(unsigned long arg, unsigned int data_size) | |||
| 2466 | MPT_SCSI_HOST *hd = shost_priv(ioc->sh); | 2534 | MPT_SCSI_HOST *hd = shost_priv(ioc->sh); |
| 2467 | 2535 | ||
| 2468 | if (hd && (cim_rev == 1)) { | 2536 | if (hd && (cim_rev == 1)) { |
| 2469 | karg.hard_resets = hd->hard_resets; | 2537 | karg.hard_resets = ioc->hard_resets; |
| 2470 | karg.soft_resets = hd->soft_resets; | 2538 | karg.soft_resets = ioc->soft_resets; |
| 2471 | karg.timeouts = hd->timeouts; | 2539 | karg.timeouts = ioc->timeouts; |
| 2472 | } | 2540 | } |
| 2473 | } | 2541 | } |
| 2474 | 2542 | ||
| @@ -2476,8 +2544,8 @@ mptctl_hp_hostinfo(unsigned long arg, unsigned int data_size) | |||
| 2476 | * Gather ISTWI(Industry Standard Two Wire Interface) Data | 2544 | * Gather ISTWI(Industry Standard Two Wire Interface) Data |
| 2477 | */ | 2545 | */ |
| 2478 | if ((mf = mpt_get_msg_frame(mptctl_id, ioc)) == NULL) { | 2546 | if ((mf = mpt_get_msg_frame(mptctl_id, ioc)) == NULL) { |
| 2479 | dfailprintk(ioc, printk(MYIOC_s_WARN_FMT "%s, no msg frames!!\n", | 2547 | dfailprintk(ioc, printk(MYIOC_s_WARN_FMT |
| 2480 | ioc->name,__func__)); | 2548 | "%s, no msg frames!!\n", ioc->name, __func__)); |
| 2481 | goto out; | 2549 | goto out; |
| 2482 | } | 2550 | } |
| 2483 | 2551 | ||
| @@ -2498,22 +2566,29 @@ mptctl_hp_hostinfo(unsigned long arg, unsigned int data_size) | |||
| 2498 | pbuf = pci_alloc_consistent(ioc->pcidev, 4, &buf_dma); | 2566 | pbuf = pci_alloc_consistent(ioc->pcidev, 4, &buf_dma); |
| 2499 | if (!pbuf) | 2567 | if (!pbuf) |
| 2500 | goto out; | 2568 | goto out; |
| 2501 | mpt_add_sge((char *)&IstwiRWRequest->SGL, | 2569 | ioc->add_sge((char *)&IstwiRWRequest->SGL, |
| 2502 | (MPT_SGE_FLAGS_SSIMPLE_READ|4), buf_dma); | 2570 | (MPT_SGE_FLAGS_SSIMPLE_READ|4), buf_dma); |
| 2503 | 2571 | ||
| 2504 | ioc->ioctl->wait_done = 0; | 2572 | retval = 0; |
| 2573 | SET_MGMT_MSG_CONTEXT(ioc->ioctl_cmds.msg_context, | ||
| 2574 | IstwiRWRequest->MsgContext); | ||
| 2575 | INITIALIZE_MGMT_STATUS(ioc->ioctl_cmds.status) | ||
| 2505 | mpt_put_msg_frame(mptctl_id, ioc, mf); | 2576 | mpt_put_msg_frame(mptctl_id, ioc, mf); |
| 2506 | 2577 | ||
| 2507 | rc = wait_event_timeout(mptctl_wait, | 2578 | retry_wait: |
| 2508 | ioc->ioctl->wait_done == 1, | 2579 | timeleft = wait_for_completion_timeout(&ioc->ioctl_cmds.done, |
| 2509 | HZ*MPT_IOCTL_DEFAULT_TIMEOUT /* 10 sec */); | 2580 | HZ*MPT_IOCTL_DEFAULT_TIMEOUT); |
| 2510 | 2581 | if (!(ioc->ioctl_cmds.status & MPT_MGMT_STATUS_COMMAND_GOOD)) { | |
| 2511 | if(rc <=0 && (ioc->ioctl->wait_done != 1 )) { | 2582 | retval = -ETIME; |
| 2512 | /* | 2583 | printk(MYIOC_s_WARN_FMT "%s: failed\n", ioc->name, __func__); |
| 2513 | * Now we need to reset the board | 2584 | if (ioc->ioctl_cmds.status & MPT_MGMT_STATUS_DID_IOCRESET) { |
| 2514 | */ | 2585 | mpt_free_msg_frame(ioc, mf); |
| 2515 | mpt_free_msg_frame(ioc, mf); | 2586 | goto out; |
| 2516 | mptctl_timeout_expired(ioc->ioctl); | 2587 | } |
| 2588 | if (!timeleft) | ||
| 2589 | mptctl_timeout_expired(ioc, mf); | ||
| 2590 | else | ||
| 2591 | goto retry_wait; | ||
| 2517 | goto out; | 2592 | goto out; |
| 2518 | } | 2593 | } |
| 2519 | 2594 | ||
| @@ -2526,10 +2601,13 @@ mptctl_hp_hostinfo(unsigned long arg, unsigned int data_size) | |||
| 2526 | * bays have drives in them | 2601 | * bays have drives in them |
| 2527 | * pbuf[3] = Checksum (0x100 = (byte0 + byte2 + byte3) | 2602 | * pbuf[3] = Checksum (0x100 = (byte0 + byte2 + byte3) |
| 2528 | */ | 2603 | */ |
| 2529 | if (ioc->ioctl->status & MPT_IOCTL_STATUS_RF_VALID) | 2604 | if (ioc->ioctl_cmds.status & MPT_MGMT_STATUS_RF_VALID) |
| 2530 | karg.rsvd = *(u32 *)pbuf; | 2605 | karg.rsvd = *(u32 *)pbuf; |
| 2531 | 2606 | ||
| 2532 | out: | 2607 | out: |
| 2608 | CLEAR_MGMT_STATUS(ioc->ioctl_cmds.status) | ||
| 2609 | SET_MGMT_MSG_CONTEXT(ioc->ioctl_cmds.msg_context, 0); | ||
| 2610 | |||
| 2533 | if (pbuf) | 2611 | if (pbuf) |
| 2534 | pci_free_consistent(ioc->pcidev, 4, pbuf, buf_dma); | 2612 | pci_free_consistent(ioc->pcidev, 4, pbuf, buf_dma); |
| 2535 | 2613 | ||
| @@ -2753,7 +2831,7 @@ compat_mptfwxfer_ioctl(struct file *filp, unsigned int cmd, | |||
| 2753 | 2831 | ||
| 2754 | ret = mptctl_do_fw_download(kfw.iocnum, kfw.bufp, kfw.fwlen); | 2832 | ret = mptctl_do_fw_download(kfw.iocnum, kfw.bufp, kfw.fwlen); |
| 2755 | 2833 | ||
| 2756 | mutex_unlock(&iocp->ioctl->ioctl_mutex); | 2834 | mutex_unlock(&iocp->ioctl_cmds.mutex); |
| 2757 | 2835 | ||
| 2758 | return ret; | 2836 | return ret; |
| 2759 | } | 2837 | } |
| @@ -2807,7 +2885,7 @@ compat_mpt_command(struct file *filp, unsigned int cmd, | |||
| 2807 | */ | 2885 | */ |
| 2808 | ret = mptctl_do_mpt_command (karg, &uarg->MF); | 2886 | ret = mptctl_do_mpt_command (karg, &uarg->MF); |
| 2809 | 2887 | ||
| 2810 | mutex_unlock(&iocp->ioctl->ioctl_mutex); | 2888 | mutex_unlock(&iocp->ioctl_cmds.mutex); |
| 2811 | 2889 | ||
| 2812 | return ret; | 2890 | return ret; |
| 2813 | } | 2891 | } |
| @@ -2859,21 +2937,10 @@ static long compat_mpctl_ioctl(struct file *f, unsigned int cmd, unsigned long a | |||
| 2859 | static int | 2937 | static int |
| 2860 | mptctl_probe(struct pci_dev *pdev, const struct pci_device_id *id) | 2938 | mptctl_probe(struct pci_dev *pdev, const struct pci_device_id *id) |
| 2861 | { | 2939 | { |
| 2862 | MPT_IOCTL *mem; | ||
| 2863 | MPT_ADAPTER *ioc = pci_get_drvdata(pdev); | 2940 | MPT_ADAPTER *ioc = pci_get_drvdata(pdev); |
| 2864 | 2941 | ||
| 2865 | /* | 2942 | mutex_init(&ioc->ioctl_cmds.mutex); |
| 2866 | * Allocate and inite a MPT_IOCTL structure | 2943 | init_completion(&ioc->ioctl_cmds.done); |
| 2867 | */ | ||
| 2868 | mem = kzalloc(sizeof(MPT_IOCTL), GFP_KERNEL); | ||
| 2869 | if (!mem) { | ||
| 2870 | mptctl_remove(pdev); | ||
| 2871 | return -ENOMEM; | ||
| 2872 | } | ||
| 2873 | |||
| 2874 | ioc->ioctl = mem; | ||
| 2875 | ioc->ioctl->ioc = ioc; | ||
| 2876 | mutex_init(&ioc->ioctl->ioctl_mutex); | ||
| 2877 | return 0; | 2944 | return 0; |
| 2878 | } | 2945 | } |
| 2879 | 2946 | ||
| @@ -2887,9 +2954,6 @@ mptctl_probe(struct pci_dev *pdev, const struct pci_device_id *id) | |||
| 2887 | static void | 2954 | static void |
| 2888 | mptctl_remove(struct pci_dev *pdev) | 2955 | mptctl_remove(struct pci_dev *pdev) |
| 2889 | { | 2956 | { |
| 2890 | MPT_ADAPTER *ioc = pci_get_drvdata(pdev); | ||
| 2891 | |||
| 2892 | kfree ( ioc->ioctl ); | ||
| 2893 | } | 2957 | } |
| 2894 | 2958 | ||
| 2895 | static struct mpt_pci_driver mptctl_driver = { | 2959 | static struct mpt_pci_driver mptctl_driver = { |
| @@ -2929,6 +2993,7 @@ static int __init mptctl_init(void) | |||
| 2929 | goto out_fail; | 2993 | goto out_fail; |
| 2930 | } | 2994 | } |
| 2931 | 2995 | ||
| 2996 | mptctl_taskmgmt_id = mpt_register(mptctl_taskmgmt_reply, MPTCTL_DRIVER); | ||
| 2932 | mpt_reset_register(mptctl_id, mptctl_ioc_reset); | 2997 | mpt_reset_register(mptctl_id, mptctl_ioc_reset); |
| 2933 | mpt_event_register(mptctl_id, mptctl_event_process); | 2998 | mpt_event_register(mptctl_id, mptctl_event_process); |
| 2934 | 2999 | ||
| @@ -2953,6 +3018,7 @@ static void mptctl_exit(void) | |||
| 2953 | 3018 | ||
| 2954 | /* De-register callback handler from base module */ | 3019 | /* De-register callback handler from base module */ |
| 2955 | mpt_deregister(mptctl_id); | 3020 | mpt_deregister(mptctl_id); |
| 3021 | mpt_reset_deregister(mptctl_taskmgmt_id); | ||
| 2956 | 3022 | ||
| 2957 | mpt_device_driver_deregister(MPTCTL_DRIVER); | 3023 | mpt_device_driver_deregister(MPTCTL_DRIVER); |
| 2958 | 3024 | ||
