Linux Audio

Check our new training course

Loading...
v3.1
 
   1/*
   2 * HighPoint RR3xxx/4xxx controller driver for Linux
   3 * Copyright (C) 2006-2009 HighPoint Technologies, Inc. All Rights Reserved.
   4 *
   5 * This program is free software; you can redistribute it and/or modify
   6 * it under the terms of the GNU General Public License as published by
   7 * the Free Software Foundation; version 2 of the License.
   8 *
   9 * This program is distributed in the hope that it will be useful,
  10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12 * GNU General Public License for more details.
  13 *
  14 * Please report bugs/comments/suggestions to linux@highpoint-tech.com
  15 *
  16 * For more information, visit http://www.highpoint-tech.com
  17 */
  18#include <linux/module.h>
  19#include <linux/types.h>
  20#include <linux/string.h>
  21#include <linux/kernel.h>
  22#include <linux/pci.h>
  23#include <linux/interrupt.h>
  24#include <linux/errno.h>
  25#include <linux/delay.h>
  26#include <linux/timer.h>
  27#include <linux/spinlock.h>
  28#include <linux/gfp.h>
  29#include <asm/uaccess.h>
  30#include <asm/io.h>
  31#include <asm/div64.h>
  32#include <scsi/scsi_cmnd.h>
  33#include <scsi/scsi_device.h>
  34#include <scsi/scsi.h>
  35#include <scsi/scsi_tcq.h>
  36#include <scsi/scsi_host.h>
  37
  38#include "hptiop.h"
  39
  40MODULE_AUTHOR("HighPoint Technologies, Inc.");
  41MODULE_DESCRIPTION("HighPoint RocketRAID 3xxx/4xxx Controller Driver");
  42
  43static char driver_name[] = "hptiop";
  44static const char driver_name_long[] = "RocketRAID 3xxx/4xxx Controller driver";
  45static const char driver_ver[] = "v1.6 (090910)";
  46
  47static int iop_send_sync_msg(struct hptiop_hba *hba, u32 msg, u32 millisec);
  48static void hptiop_finish_scsi_req(struct hptiop_hba *hba, u32 tag,
  49				struct hpt_iop_request_scsi_command *req);
  50static void hptiop_host_request_callback_itl(struct hptiop_hba *hba, u32 tag);
  51static void hptiop_iop_request_callback_itl(struct hptiop_hba *hba, u32 tag);
  52static void hptiop_message_callback(struct hptiop_hba *hba, u32 msg);
  53
  54static int iop_wait_ready_itl(struct hptiop_hba *hba, u32 millisec)
  55{
  56	u32 req = 0;
  57	int i;
  58
  59	for (i = 0; i < millisec; i++) {
  60		req = readl(&hba->u.itl.iop->inbound_queue);
  61		if (req != IOPMU_QUEUE_EMPTY)
  62			break;
  63		msleep(1);
  64	}
  65
  66	if (req != IOPMU_QUEUE_EMPTY) {
  67		writel(req, &hba->u.itl.iop->outbound_queue);
  68		readl(&hba->u.itl.iop->outbound_intstatus);
  69		return 0;
  70	}
  71
  72	return -1;
  73}
  74
  75static int iop_wait_ready_mv(struct hptiop_hba *hba, u32 millisec)
  76{
  77	return iop_send_sync_msg(hba, IOPMU_INBOUND_MSG0_NOP, millisec);
  78}
  79
 
 
 
 
 
  80static void hptiop_request_callback_itl(struct hptiop_hba *hba, u32 tag)
  81{
  82	if (tag & IOPMU_QUEUE_ADDR_HOST_BIT)
  83		hptiop_host_request_callback_itl(hba,
  84				tag & ~IOPMU_QUEUE_ADDR_HOST_BIT);
  85	else
  86		hptiop_iop_request_callback_itl(hba, tag);
  87}
  88
  89static void hptiop_drain_outbound_queue_itl(struct hptiop_hba *hba)
  90{
  91	u32 req;
  92
  93	while ((req = readl(&hba->u.itl.iop->outbound_queue)) !=
  94						IOPMU_QUEUE_EMPTY) {
  95
  96		if (req & IOPMU_QUEUE_MASK_HOST_BITS)
  97			hptiop_request_callback_itl(hba, req);
  98		else {
  99			struct hpt_iop_request_header __iomem * p;
 100
 101			p = (struct hpt_iop_request_header __iomem *)
 102				((char __iomem *)hba->u.itl.iop + req);
 103
 104			if (readl(&p->flags) & IOP_REQUEST_FLAG_SYNC_REQUEST) {
 105				if (readl(&p->context))
 106					hptiop_request_callback_itl(hba, req);
 107				else
 108					writel(1, &p->context);
 109			}
 110			else
 111				hptiop_request_callback_itl(hba, req);
 112		}
 113	}
 114}
 115
 116static int iop_intr_itl(struct hptiop_hba *hba)
 117{
 118	struct hpt_iopmu_itl __iomem *iop = hba->u.itl.iop;
 119	void __iomem *plx = hba->u.itl.plx;
 120	u32 status;
 121	int ret = 0;
 122
 123	if (plx && readl(plx + 0x11C5C) & 0xf)
 124		writel(1, plx + 0x11C60);
 125
 126	status = readl(&iop->outbound_intstatus);
 127
 128	if (status & IOPMU_OUTBOUND_INT_MSG0) {
 129		u32 msg = readl(&iop->outbound_msgaddr0);
 130
 131		dprintk("received outbound msg %x\n", msg);
 132		writel(IOPMU_OUTBOUND_INT_MSG0, &iop->outbound_intstatus);
 133		hptiop_message_callback(hba, msg);
 134		ret = 1;
 135	}
 136
 137	if (status & IOPMU_OUTBOUND_INT_POSTQUEUE) {
 138		hptiop_drain_outbound_queue_itl(hba);
 139		ret = 1;
 140	}
 141
 142	return ret;
 143}
 144
 145static u64 mv_outbound_read(struct hpt_iopmu_mv __iomem *mu)
 146{
 147	u32 outbound_tail = readl(&mu->outbound_tail);
 148	u32 outbound_head = readl(&mu->outbound_head);
 149
 150	if (outbound_tail != outbound_head) {
 151		u64 p;
 152
 153		memcpy_fromio(&p, &mu->outbound_q[mu->outbound_tail], 8);
 154		outbound_tail++;
 155
 156		if (outbound_tail == MVIOP_QUEUE_LEN)
 157			outbound_tail = 0;
 158		writel(outbound_tail, &mu->outbound_tail);
 159		return p;
 160	} else
 161		return 0;
 162}
 163
 164static void mv_inbound_write(u64 p, struct hptiop_hba *hba)
 165{
 166	u32 inbound_head = readl(&hba->u.mv.mu->inbound_head);
 167	u32 head = inbound_head + 1;
 168
 169	if (head == MVIOP_QUEUE_LEN)
 170		head = 0;
 171
 172	memcpy_toio(&hba->u.mv.mu->inbound_q[inbound_head], &p, 8);
 173	writel(head, &hba->u.mv.mu->inbound_head);
 174	writel(MVIOP_MU_INBOUND_INT_POSTQUEUE,
 175			&hba->u.mv.regs->inbound_doorbell);
 176}
 177
 178static void hptiop_request_callback_mv(struct hptiop_hba *hba, u64 tag)
 179{
 180	u32 req_type = (tag >> 5) & 0x7;
 181	struct hpt_iop_request_scsi_command *req;
 182
 183	dprintk("hptiop_request_callback_mv: tag=%llx\n", tag);
 184
 185	BUG_ON((tag & MVIOP_MU_QUEUE_REQUEST_RETURN_CONTEXT) == 0);
 186
 187	switch (req_type) {
 188	case IOP_REQUEST_TYPE_GET_CONFIG:
 189	case IOP_REQUEST_TYPE_SET_CONFIG:
 190		hba->msg_done = 1;
 191		break;
 192
 193	case IOP_REQUEST_TYPE_SCSI_COMMAND:
 194		req = hba->reqs[tag >> 8].req_virt;
 195		if (likely(tag & MVIOP_MU_QUEUE_REQUEST_RESULT_BIT))
 196			req->header.result = cpu_to_le32(IOP_RESULT_SUCCESS);
 197
 198		hptiop_finish_scsi_req(hba, tag>>8, req);
 199		break;
 200
 201	default:
 202		break;
 203	}
 204}
 205
 206static int iop_intr_mv(struct hptiop_hba *hba)
 207{
 208	u32 status;
 209	int ret = 0;
 210
 211	status = readl(&hba->u.mv.regs->outbound_doorbell);
 212	writel(~status, &hba->u.mv.regs->outbound_doorbell);
 213
 214	if (status & MVIOP_MU_OUTBOUND_INT_MSG) {
 215		u32 msg;
 216		msg = readl(&hba->u.mv.mu->outbound_msg);
 217		dprintk("received outbound msg %x\n", msg);
 218		hptiop_message_callback(hba, msg);
 219		ret = 1;
 220	}
 221
 222	if (status & MVIOP_MU_OUTBOUND_INT_POSTQUEUE) {
 223		u64 tag;
 224
 225		while ((tag = mv_outbound_read(hba->u.mv.mu)))
 226			hptiop_request_callback_mv(hba, tag);
 227		ret = 1;
 228	}
 229
 230	return ret;
 231}
 232
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 233static int iop_send_sync_request_itl(struct hptiop_hba *hba,
 234					void __iomem *_req, u32 millisec)
 235{
 236	struct hpt_iop_request_header __iomem *req = _req;
 237	u32 i;
 238
 239	writel(readl(&req->flags) | IOP_REQUEST_FLAG_SYNC_REQUEST, &req->flags);
 240	writel(0, &req->context);
 241	writel((unsigned long)req - (unsigned long)hba->u.itl.iop,
 242			&hba->u.itl.iop->inbound_queue);
 243	readl(&hba->u.itl.iop->outbound_intstatus);
 244
 245	for (i = 0; i < millisec; i++) {
 246		iop_intr_itl(hba);
 247		if (readl(&req->context))
 248			return 0;
 249		msleep(1);
 250	}
 251
 252	return -1;
 253}
 254
 255static int iop_send_sync_request_mv(struct hptiop_hba *hba,
 256					u32 size_bits, u32 millisec)
 257{
 258	struct hpt_iop_request_header *reqhdr = hba->u.mv.internal_req;
 259	u32 i;
 260
 261	hba->msg_done = 0;
 262	reqhdr->flags |= cpu_to_le32(IOP_REQUEST_FLAG_SYNC_REQUEST);
 263	mv_inbound_write(hba->u.mv.internal_req_phy |
 264			MVIOP_MU_QUEUE_ADDR_HOST_BIT | size_bits, hba);
 265
 266	for (i = 0; i < millisec; i++) {
 267		iop_intr_mv(hba);
 268		if (hba->msg_done)
 269			return 0;
 270		msleep(1);
 271	}
 272	return -1;
 273}
 274
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 275static void hptiop_post_msg_itl(struct hptiop_hba *hba, u32 msg)
 276{
 277	writel(msg, &hba->u.itl.iop->inbound_msgaddr0);
 278	readl(&hba->u.itl.iop->outbound_intstatus);
 279}
 280
 281static void hptiop_post_msg_mv(struct hptiop_hba *hba, u32 msg)
 282{
 283	writel(msg, &hba->u.mv.mu->inbound_msg);
 284	writel(MVIOP_MU_INBOUND_INT_MSG, &hba->u.mv.regs->inbound_doorbell);
 285	readl(&hba->u.mv.regs->inbound_doorbell);
 286}
 287
 
 
 
 
 
 
 288static int iop_send_sync_msg(struct hptiop_hba *hba, u32 msg, u32 millisec)
 289{
 290	u32 i;
 291
 292	hba->msg_done = 0;
 
 293	hba->ops->post_msg(hba, msg);
 294
 295	for (i = 0; i < millisec; i++) {
 296		spin_lock_irq(hba->host->host_lock);
 297		hba->ops->iop_intr(hba);
 298		spin_unlock_irq(hba->host->host_lock);
 299		if (hba->msg_done)
 300			break;
 301		msleep(1);
 302	}
 303
 
 304	return hba->msg_done? 0 : -1;
 305}
 306
 307static int iop_get_config_itl(struct hptiop_hba *hba,
 308				struct hpt_iop_request_get_config *config)
 309{
 310	u32 req32;
 311	struct hpt_iop_request_get_config __iomem *req;
 312
 313	req32 = readl(&hba->u.itl.iop->inbound_queue);
 314	if (req32 == IOPMU_QUEUE_EMPTY)
 315		return -1;
 316
 317	req = (struct hpt_iop_request_get_config __iomem *)
 318			((unsigned long)hba->u.itl.iop + req32);
 319
 320	writel(0, &req->header.flags);
 321	writel(IOP_REQUEST_TYPE_GET_CONFIG, &req->header.type);
 322	writel(sizeof(struct hpt_iop_request_get_config), &req->header.size);
 323	writel(IOP_RESULT_PENDING, &req->header.result);
 324
 325	if (iop_send_sync_request_itl(hba, req, 20000)) {
 326		dprintk("Get config send cmd failed\n");
 327		return -1;
 328	}
 329
 330	memcpy_fromio(config, req, sizeof(*config));
 331	writel(req32, &hba->u.itl.iop->outbound_queue);
 332	return 0;
 333}
 334
 335static int iop_get_config_mv(struct hptiop_hba *hba,
 336				struct hpt_iop_request_get_config *config)
 337{
 338	struct hpt_iop_request_get_config *req = hba->u.mv.internal_req;
 339
 340	req->header.flags = cpu_to_le32(IOP_REQUEST_FLAG_OUTPUT_CONTEXT);
 341	req->header.type = cpu_to_le32(IOP_REQUEST_TYPE_GET_CONFIG);
 342	req->header.size =
 343		cpu_to_le32(sizeof(struct hpt_iop_request_get_config));
 344	req->header.result = cpu_to_le32(IOP_RESULT_PENDING);
 345	req->header.context = cpu_to_le32(IOP_REQUEST_TYPE_GET_CONFIG<<5);
 346	req->header.context_hi32 = 0;
 347
 348	if (iop_send_sync_request_mv(hba, 0, 20000)) {
 349		dprintk("Get config send cmd failed\n");
 350		return -1;
 351	}
 352
 353	memcpy(config, req, sizeof(struct hpt_iop_request_get_config));
 354	return 0;
 355}
 356
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 357static int iop_set_config_itl(struct hptiop_hba *hba,
 358				struct hpt_iop_request_set_config *config)
 359{
 360	u32 req32;
 361	struct hpt_iop_request_set_config __iomem *req;
 362
 363	req32 = readl(&hba->u.itl.iop->inbound_queue);
 364	if (req32 == IOPMU_QUEUE_EMPTY)
 365		return -1;
 366
 367	req = (struct hpt_iop_request_set_config __iomem *)
 368			((unsigned long)hba->u.itl.iop + req32);
 369
 370	memcpy_toio((u8 __iomem *)req + sizeof(struct hpt_iop_request_header),
 371		(u8 *)config + sizeof(struct hpt_iop_request_header),
 372		sizeof(struct hpt_iop_request_set_config) -
 373			sizeof(struct hpt_iop_request_header));
 374
 375	writel(0, &req->header.flags);
 376	writel(IOP_REQUEST_TYPE_SET_CONFIG, &req->header.type);
 377	writel(sizeof(struct hpt_iop_request_set_config), &req->header.size);
 378	writel(IOP_RESULT_PENDING, &req->header.result);
 379
 380	if (iop_send_sync_request_itl(hba, req, 20000)) {
 381		dprintk("Set config send cmd failed\n");
 382		return -1;
 383	}
 384
 385	writel(req32, &hba->u.itl.iop->outbound_queue);
 386	return 0;
 387}
 388
 389static int iop_set_config_mv(struct hptiop_hba *hba,
 390				struct hpt_iop_request_set_config *config)
 391{
 392	struct hpt_iop_request_set_config *req = hba->u.mv.internal_req;
 393
 394	memcpy(req, config, sizeof(struct hpt_iop_request_set_config));
 395	req->header.flags = cpu_to_le32(IOP_REQUEST_FLAG_OUTPUT_CONTEXT);
 396	req->header.type = cpu_to_le32(IOP_REQUEST_TYPE_SET_CONFIG);
 397	req->header.size =
 398		cpu_to_le32(sizeof(struct hpt_iop_request_set_config));
 399	req->header.result = cpu_to_le32(IOP_RESULT_PENDING);
 400	req->header.context = cpu_to_le32(IOP_REQUEST_TYPE_SET_CONFIG<<5);
 401	req->header.context_hi32 = 0;
 402
 403	if (iop_send_sync_request_mv(hba, 0, 20000)) {
 404		dprintk("Set config send cmd failed\n");
 405		return -1;
 406	}
 407
 408	return 0;
 409}
 410
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 411static void hptiop_enable_intr_itl(struct hptiop_hba *hba)
 412{
 413	writel(~(IOPMU_OUTBOUND_INT_POSTQUEUE | IOPMU_OUTBOUND_INT_MSG0),
 414		&hba->u.itl.iop->outbound_intmask);
 415}
 416
 417static void hptiop_enable_intr_mv(struct hptiop_hba *hba)
 418{
 419	writel(MVIOP_MU_OUTBOUND_INT_POSTQUEUE | MVIOP_MU_OUTBOUND_INT_MSG,
 420		&hba->u.mv.regs->outbound_intmask);
 421}
 422
 
 
 
 
 
 
 
 423static int hptiop_initialize_iop(struct hptiop_hba *hba)
 424{
 425	/* enable interrupts */
 426	hba->ops->enable_intr(hba);
 427
 428	hba->initialized = 1;
 429
 430	/* start background tasks */
 431	if (iop_send_sync_msg(hba,
 432			IOPMU_INBOUND_MSG0_START_BACKGROUND_TASK, 5000)) {
 433		printk(KERN_ERR "scsi%d: fail to start background task\n",
 434			hba->host->host_no);
 435		return -1;
 436	}
 437	return 0;
 438}
 439
 440static void __iomem *hptiop_map_pci_bar(struct hptiop_hba *hba, int index)
 441{
 442	u32 mem_base_phy, length;
 443	void __iomem *mem_base_virt;
 444
 445	struct pci_dev *pcidev = hba->pcidev;
 446
 447
 448	if (!(pci_resource_flags(pcidev, index) & IORESOURCE_MEM)) {
 449		printk(KERN_ERR "scsi%d: pci resource invalid\n",
 450				hba->host->host_no);
 451		return NULL;
 452	}
 453
 454	mem_base_phy = pci_resource_start(pcidev, index);
 455	length = pci_resource_len(pcidev, index);
 456	mem_base_virt = ioremap(mem_base_phy, length);
 457
 458	if (!mem_base_virt) {
 459		printk(KERN_ERR "scsi%d: Fail to ioremap memory space\n",
 460				hba->host->host_no);
 461		return NULL;
 462	}
 463	return mem_base_virt;
 464}
 465
 466static int hptiop_map_pci_bar_itl(struct hptiop_hba *hba)
 467{
 468	struct pci_dev *pcidev = hba->pcidev;
 469	hba->u.itl.iop = hptiop_map_pci_bar(hba, 0);
 470	if (hba->u.itl.iop == NULL)
 471		return -1;
 472	if ((pcidev->device & 0xff00) == 0x4400) {
 473		hba->u.itl.plx = hba->u.itl.iop;
 474		hba->u.itl.iop = hptiop_map_pci_bar(hba, 2);
 475		if (hba->u.itl.iop == NULL) {
 476			iounmap(hba->u.itl.plx);
 477			return -1;
 478		}
 479	}
 480	return 0;
 481}
 482
 483static void hptiop_unmap_pci_bar_itl(struct hptiop_hba *hba)
 484{
 485	if (hba->u.itl.plx)
 486		iounmap(hba->u.itl.plx);
 487	iounmap(hba->u.itl.iop);
 488}
 489
 490static int hptiop_map_pci_bar_mv(struct hptiop_hba *hba)
 491{
 492	hba->u.mv.regs = hptiop_map_pci_bar(hba, 0);
 493	if (hba->u.mv.regs == NULL)
 494		return -1;
 495
 496	hba->u.mv.mu = hptiop_map_pci_bar(hba, 2);
 497	if (hba->u.mv.mu == NULL) {
 498		iounmap(hba->u.mv.regs);
 499		return -1;
 500	}
 501
 502	return 0;
 503}
 504
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 505static void hptiop_unmap_pci_bar_mv(struct hptiop_hba *hba)
 506{
 507	iounmap(hba->u.mv.regs);
 508	iounmap(hba->u.mv.mu);
 509}
 510
 
 
 
 
 
 
 511static void hptiop_message_callback(struct hptiop_hba *hba, u32 msg)
 512{
 513	dprintk("iop message 0x%x\n", msg);
 514
 515	if (msg == IOPMU_INBOUND_MSG0_NOP)
 
 516		hba->msg_done = 1;
 517
 518	if (!hba->initialized)
 519		return;
 520
 521	if (msg == IOPMU_INBOUND_MSG0_RESET) {
 522		atomic_set(&hba->resetting, 0);
 523		wake_up(&hba->reset_wq);
 524	}
 525	else if (msg <= IOPMU_INBOUND_MSG0_MAX)
 526		hba->msg_done = 1;
 527}
 528
 529static struct hptiop_request *get_req(struct hptiop_hba *hba)
 530{
 531	struct hptiop_request *ret;
 532
 533	dprintk("get_req : req=%p\n", hba->req_list);
 534
 535	ret = hba->req_list;
 536	if (ret)
 537		hba->req_list = ret->next;
 538
 539	return ret;
 540}
 541
 542static void free_req(struct hptiop_hba *hba, struct hptiop_request *req)
 543{
 544	dprintk("free_req(%d, %p)\n", req->index, req);
 545	req->next = hba->req_list;
 546	hba->req_list = req;
 547}
 548
 549static void hptiop_finish_scsi_req(struct hptiop_hba *hba, u32 tag,
 550				struct hpt_iop_request_scsi_command *req)
 551{
 552	struct scsi_cmnd *scp;
 553
 554	dprintk("hptiop_finish_scsi_req: req=%p, type=%d, "
 555			"result=%d, context=0x%x tag=%d\n",
 556			req, req->header.type, req->header.result,
 557			req->header.context, tag);
 558
 559	BUG_ON(!req->header.result);
 560	BUG_ON(req->header.type != cpu_to_le32(IOP_REQUEST_TYPE_SCSI_COMMAND));
 561
 562	scp = hba->reqs[tag].scp;
 563
 564	if (HPT_SCP(scp)->mapped)
 565		scsi_dma_unmap(scp);
 566
 567	switch (le32_to_cpu(req->header.result)) {
 568	case IOP_RESULT_SUCCESS:
 569		scsi_set_resid(scp,
 570			scsi_bufflen(scp) - le32_to_cpu(req->dataxfer_length));
 571		scp->result = (DID_OK<<16);
 572		break;
 573	case IOP_RESULT_BAD_TARGET:
 574		scp->result = (DID_BAD_TARGET<<16);
 575		break;
 576	case IOP_RESULT_BUSY:
 577		scp->result = (DID_BUS_BUSY<<16);
 578		break;
 579	case IOP_RESULT_RESET:
 580		scp->result = (DID_RESET<<16);
 581		break;
 582	case IOP_RESULT_FAIL:
 583		scp->result = (DID_ERROR<<16);
 584		break;
 585	case IOP_RESULT_INVALID_REQUEST:
 586		scp->result = (DID_ABORT<<16);
 587		break;
 588	case IOP_RESULT_CHECK_CONDITION:
 589		scsi_set_resid(scp,
 590			scsi_bufflen(scp) - le32_to_cpu(req->dataxfer_length));
 591		scp->result = SAM_STAT_CHECK_CONDITION;
 592		memcpy(scp->sense_buffer, &req->sg_list,
 593				min_t(size_t, SCSI_SENSE_BUFFERSIZE,
 594					le32_to_cpu(req->dataxfer_length)));
 595		break;
 596
 597	default:
 598		scp->result = DRIVER_INVALID << 24 | DID_ABORT << 16;
 599		break;
 600	}
 601
 
 
 
 
 602	dprintk("scsi_done(%p)\n", scp);
 603	scp->scsi_done(scp);
 604	free_req(hba, &hba->reqs[tag]);
 605}
 606
 607static void hptiop_host_request_callback_itl(struct hptiop_hba *hba, u32 _tag)
 608{
 609	struct hpt_iop_request_scsi_command *req;
 610	u32 tag;
 611
 612	if (hba->iopintf_v2) {
 613		tag = _tag & ~IOPMU_QUEUE_REQUEST_RESULT_BIT;
 614		req = hba->reqs[tag].req_virt;
 615		if (likely(_tag & IOPMU_QUEUE_REQUEST_RESULT_BIT))
 616			req->header.result = cpu_to_le32(IOP_RESULT_SUCCESS);
 617	} else {
 618		tag = _tag;
 619		req = hba->reqs[tag].req_virt;
 620	}
 621
 622	hptiop_finish_scsi_req(hba, tag, req);
 623}
 624
 625void hptiop_iop_request_callback_itl(struct hptiop_hba *hba, u32 tag)
 626{
 627	struct hpt_iop_request_header __iomem *req;
 628	struct hpt_iop_request_ioctl_command __iomem *p;
 629	struct hpt_ioctl_k *arg;
 630
 631	req = (struct hpt_iop_request_header __iomem *)
 632			((unsigned long)hba->u.itl.iop + tag);
 633	dprintk("hptiop_iop_request_callback_itl: req=%p, type=%d, "
 634			"result=%d, context=0x%x tag=%d\n",
 635			req, readl(&req->type), readl(&req->result),
 636			readl(&req->context), tag);
 637
 638	BUG_ON(!readl(&req->result));
 639	BUG_ON(readl(&req->type) != IOP_REQUEST_TYPE_IOCTL_COMMAND);
 640
 641	p = (struct hpt_iop_request_ioctl_command __iomem *)req;
 642	arg = (struct hpt_ioctl_k *)(unsigned long)
 643		(readl(&req->context) |
 644			((u64)readl(&req->context_hi32)<<32));
 645
 646	if (readl(&req->result) == IOP_RESULT_SUCCESS) {
 647		arg->result = HPT_IOCTL_RESULT_OK;
 648
 649		if (arg->outbuf_size)
 650			memcpy_fromio(arg->outbuf,
 651				&p->buf[(readl(&p->inbuf_size) + 3)& ~3],
 652				arg->outbuf_size);
 653
 654		if (arg->bytes_returned)
 655			*arg->bytes_returned = arg->outbuf_size;
 656	}
 657	else
 658		arg->result = HPT_IOCTL_RESULT_FAILED;
 659
 660	arg->done(arg);
 661	writel(tag, &hba->u.itl.iop->outbound_queue);
 662}
 663
 664static irqreturn_t hptiop_intr(int irq, void *dev_id)
 665{
 666	struct hptiop_hba  *hba = dev_id;
 667	int  handled;
 668	unsigned long flags;
 669
 670	spin_lock_irqsave(hba->host->host_lock, flags);
 671	handled = hba->ops->iop_intr(hba);
 672	spin_unlock_irqrestore(hba->host->host_lock, flags);
 673
 674	return handled;
 675}
 676
 677static int hptiop_buildsgl(struct scsi_cmnd *scp, struct hpt_iopsg *psg)
 678{
 679	struct Scsi_Host *host = scp->device->host;
 680	struct hptiop_hba *hba = (struct hptiop_hba *)host->hostdata;
 681	struct scatterlist *sg;
 682	int idx, nseg;
 683
 684	nseg = scsi_dma_map(scp);
 685	BUG_ON(nseg < 0);
 686	if (!nseg)
 687		return 0;
 688
 689	HPT_SCP(scp)->sgcnt = nseg;
 690	HPT_SCP(scp)->mapped = 1;
 691
 692	BUG_ON(HPT_SCP(scp)->sgcnt > hba->max_sg_descriptors);
 693
 694	scsi_for_each_sg(scp, sg, HPT_SCP(scp)->sgcnt, idx) {
 695		psg[idx].pci_address = cpu_to_le64(sg_dma_address(sg));
 
 696		psg[idx].size = cpu_to_le32(sg_dma_len(sg));
 697		psg[idx].eot = (idx == HPT_SCP(scp)->sgcnt - 1) ?
 698			cpu_to_le32(1) : 0;
 699	}
 700	return HPT_SCP(scp)->sgcnt;
 701}
 702
 703static void hptiop_post_req_itl(struct hptiop_hba *hba,
 704					struct hptiop_request *_req)
 705{
 706	struct hpt_iop_request_header *reqhdr = _req->req_virt;
 707
 708	reqhdr->context = cpu_to_le32(IOPMU_QUEUE_ADDR_HOST_BIT |
 709							(u32)_req->index);
 710	reqhdr->context_hi32 = 0;
 711
 712	if (hba->iopintf_v2) {
 713		u32 size, size_bits;
 714
 715		size = le32_to_cpu(reqhdr->size);
 716		if (size < 256)
 717			size_bits = IOPMU_QUEUE_REQUEST_SIZE_BIT;
 718		else if (size < 512)
 719			size_bits = IOPMU_QUEUE_ADDR_HOST_BIT;
 720		else
 721			size_bits = IOPMU_QUEUE_REQUEST_SIZE_BIT |
 722						IOPMU_QUEUE_ADDR_HOST_BIT;
 723		writel(_req->req_shifted_phy | size_bits,
 724			&hba->u.itl.iop->inbound_queue);
 725	} else
 726		writel(_req->req_shifted_phy | IOPMU_QUEUE_ADDR_HOST_BIT,
 727					&hba->u.itl.iop->inbound_queue);
 728}
 729
 730static void hptiop_post_req_mv(struct hptiop_hba *hba,
 731					struct hptiop_request *_req)
 732{
 733	struct hpt_iop_request_header *reqhdr = _req->req_virt;
 734	u32 size, size_bit;
 735
 736	reqhdr->context = cpu_to_le32(_req->index<<8 |
 737					IOP_REQUEST_TYPE_SCSI_COMMAND<<5);
 738	reqhdr->context_hi32 = 0;
 739	size = le32_to_cpu(reqhdr->size);
 740
 741	if (size <= 256)
 742		size_bit = 0;
 743	else if (size <= 256*2)
 744		size_bit = 1;
 745	else if (size <= 256*3)
 746		size_bit = 2;
 747	else
 748		size_bit = 3;
 749
 750	mv_inbound_write((_req->req_shifted_phy << 5) |
 751		MVIOP_MU_QUEUE_ADDR_HOST_BIT | size_bit, hba);
 752}
 753
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 754static int hptiop_queuecommand_lck(struct scsi_cmnd *scp,
 755				void (*done)(struct scsi_cmnd *))
 756{
 757	struct Scsi_Host *host = scp->device->host;
 758	struct hptiop_hba *hba = (struct hptiop_hba *)host->hostdata;
 759	struct hpt_iop_request_scsi_command *req;
 760	int sg_count = 0;
 761	struct hptiop_request *_req;
 762
 763	BUG_ON(!done);
 764	scp->scsi_done = done;
 765
 766	_req = get_req(hba);
 767	if (_req == NULL) {
 768		dprintk("hptiop_queuecmd : no free req\n");
 769		return SCSI_MLQUEUE_HOST_BUSY;
 770	}
 771
 772	_req->scp = scp;
 773
 774	dprintk("hptiop_queuecmd(scp=%p) %d/%d/%d/%d cdb=(%x-%x-%x) "
 775			"req_index=%d, req=%p\n",
 776			scp,
 777			host->host_no, scp->device->channel,
 778			scp->device->id, scp->device->lun,
 779			((u32 *)scp->cmnd)[0],
 780			((u32 *)scp->cmnd)[1],
 781			((u32 *)scp->cmnd)[2],
 
 782			_req->index, _req->req_virt);
 783
 784	scp->result = 0;
 785
 786	if (scp->device->channel || scp->device->lun ||
 787			scp->device->id > hba->max_devices) {
 
 788		scp->result = DID_BAD_TARGET << 16;
 789		free_req(hba, _req);
 790		goto cmd_done;
 791	}
 792
 793	req = _req->req_virt;
 794
 795	/* build S/G table */
 796	sg_count = hptiop_buildsgl(scp, req->sg_list);
 797	if (!sg_count)
 798		HPT_SCP(scp)->mapped = 0;
 799
 800	req->header.flags = cpu_to_le32(IOP_REQUEST_FLAG_OUTPUT_CONTEXT);
 801	req->header.type = cpu_to_le32(IOP_REQUEST_TYPE_SCSI_COMMAND);
 802	req->header.result = cpu_to_le32(IOP_RESULT_PENDING);
 803	req->dataxfer_length = cpu_to_le32(scsi_bufflen(scp));
 804	req->channel = scp->device->channel;
 805	req->target = scp->device->id;
 806	req->lun = scp->device->lun;
 807	req->header.size = cpu_to_le32(
 808				sizeof(struct hpt_iop_request_scsi_command)
 809				 - sizeof(struct hpt_iopsg)
 810				 + sg_count * sizeof(struct hpt_iopsg));
 811
 812	memcpy(req->cdb, scp->cmnd, sizeof(req->cdb));
 813	hba->ops->post_req(hba, _req);
 814	return 0;
 815
 816cmd_done:
 817	dprintk("scsi_done(scp=%p)\n", scp);
 818	scp->scsi_done(scp);
 819	return 0;
 820}
 821
 822static DEF_SCSI_QCMD(hptiop_queuecommand)
 823
 824static const char *hptiop_info(struct Scsi_Host *host)
 825{
 826	return driver_name_long;
 827}
 828
 829static int hptiop_reset_hba(struct hptiop_hba *hba)
 830{
 831	if (atomic_xchg(&hba->resetting, 1) == 0) {
 832		atomic_inc(&hba->reset_count);
 833		hba->ops->post_msg(hba, IOPMU_INBOUND_MSG0_RESET);
 834	}
 835
 836	wait_event_timeout(hba->reset_wq,
 837			atomic_read(&hba->resetting) == 0, 60 * HZ);
 838
 839	if (atomic_read(&hba->resetting)) {
 840		/* IOP is in unknown state, abort reset */
 841		printk(KERN_ERR "scsi%d: reset failed\n", hba->host->host_no);
 842		return -1;
 843	}
 844
 845	if (iop_send_sync_msg(hba,
 846		IOPMU_INBOUND_MSG0_START_BACKGROUND_TASK, 5000)) {
 847		dprintk("scsi%d: fail to start background task\n",
 848				hba->host->host_no);
 849	}
 850
 851	return 0;
 852}
 853
 854static int hptiop_reset(struct scsi_cmnd *scp)
 855{
 856	struct Scsi_Host * host = scp->device->host;
 857	struct hptiop_hba * hba = (struct hptiop_hba *)host->hostdata;
 858
 859	printk(KERN_WARNING "hptiop_reset(%d/%d/%d) scp=%p\n",
 860			scp->device->host->host_no, scp->device->channel,
 861			scp->device->id, scp);
 862
 863	return hptiop_reset_hba(hba)? FAILED : SUCCESS;
 864}
 865
 866static int hptiop_adjust_disk_queue_depth(struct scsi_device *sdev,
 867					  int queue_depth, int reason)
 868{
 869	struct hptiop_hba *hba = (struct hptiop_hba *)sdev->host->hostdata;
 870
 871	if (reason != SCSI_QDEPTH_DEFAULT)
 872		return -EOPNOTSUPP;
 873
 874	if (queue_depth > hba->max_requests)
 875		queue_depth = hba->max_requests;
 876	scsi_adjust_queue_depth(sdev, MSG_ORDERED_TAG, queue_depth);
 877	return queue_depth;
 878}
 879
 880static ssize_t hptiop_show_version(struct device *dev,
 881				   struct device_attribute *attr, char *buf)
 882{
 883	return snprintf(buf, PAGE_SIZE, "%s\n", driver_ver);
 884}
 885
 886static ssize_t hptiop_show_fw_version(struct device *dev,
 887				      struct device_attribute *attr, char *buf)
 888{
 889	struct Scsi_Host *host = class_to_shost(dev);
 890	struct hptiop_hba *hba = (struct hptiop_hba *)host->hostdata;
 891
 892	return snprintf(buf, PAGE_SIZE, "%d.%d.%d.%d\n",
 893				hba->firmware_version >> 24,
 894				(hba->firmware_version >> 16) & 0xff,
 895				(hba->firmware_version >> 8) & 0xff,
 896				hba->firmware_version & 0xff);
 897}
 898
 899static struct device_attribute hptiop_attr_version = {
 900	.attr = {
 901		.name = "driver-version",
 902		.mode = S_IRUGO,
 903	},
 904	.show = hptiop_show_version,
 905};
 906
 907static struct device_attribute hptiop_attr_fw_version = {
 908	.attr = {
 909		.name = "firmware-version",
 910		.mode = S_IRUGO,
 911	},
 912	.show = hptiop_show_fw_version,
 913};
 914
 915static struct device_attribute *hptiop_attrs[] = {
 916	&hptiop_attr_version,
 917	&hptiop_attr_fw_version,
 918	NULL
 919};
 920
 
 
 
 
 
 
 
 
 921static struct scsi_host_template driver_template = {
 922	.module                     = THIS_MODULE,
 923	.name                       = driver_name,
 924	.queuecommand               = hptiop_queuecommand,
 925	.eh_device_reset_handler    = hptiop_reset,
 926	.eh_bus_reset_handler       = hptiop_reset,
 927	.info                       = hptiop_info,
 928	.emulated                   = 0,
 929	.use_clustering             = ENABLE_CLUSTERING,
 930	.proc_name                  = driver_name,
 931	.shost_attrs                = hptiop_attrs,
 
 932	.this_id                    = -1,
 933	.change_queue_depth         = hptiop_adjust_disk_queue_depth,
 934};
 935
 
 
 
 
 
 936static int hptiop_internal_memalloc_mv(struct hptiop_hba *hba)
 937{
 938	hba->u.mv.internal_req = dma_alloc_coherent(&hba->pcidev->dev,
 939			0x800, &hba->u.mv.internal_req_phy, GFP_KERNEL);
 940	if (hba->u.mv.internal_req)
 941		return 0;
 942	else
 943		return -1;
 944}
 945
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 946static int hptiop_internal_memfree_mv(struct hptiop_hba *hba)
 947{
 948	if (hba->u.mv.internal_req) {
 949		dma_free_coherent(&hba->pcidev->dev, 0x800,
 950			hba->u.mv.internal_req, hba->u.mv.internal_req_phy);
 951		return 0;
 952	} else
 953		return -1;
 954}
 955
 956static int __devinit hptiop_probe(struct pci_dev *pcidev,
 957					const struct pci_device_id *id)
 
 
 
 
 
 
 
 
 
 
 
 
 958{
 959	struct Scsi_Host *host = NULL;
 960	struct hptiop_hba *hba;
 
 961	struct hpt_iop_request_get_config iop_config;
 962	struct hpt_iop_request_set_config set_config;
 963	dma_addr_t start_phy;
 964	void *start_virt;
 965	u32 offset, i, req_size;
 
 966
 967	dprintk("hptiop_probe(%p)\n", pcidev);
 968
 969	if (pci_enable_device(pcidev)) {
 970		printk(KERN_ERR "hptiop: fail to enable pci device\n");
 971		return -ENODEV;
 972	}
 973
 974	printk(KERN_INFO "adapter at PCI %d:%d:%d, IRQ %d\n",
 975		pcidev->bus->number, pcidev->devfn >> 3, pcidev->devfn & 7,
 976		pcidev->irq);
 977
 978	pci_set_master(pcidev);
 979
 980	/* Enable 64bit DMA if possible */
 981	if (pci_set_dma_mask(pcidev, DMA_BIT_MASK(64))) {
 982		if (pci_set_dma_mask(pcidev, DMA_BIT_MASK(32))) {
 983			printk(KERN_ERR "hptiop: fail to set dma_mask\n");
 984			goto disable_pci_device;
 985		}
 
 
 
 
 986	}
 987
 988	if (pci_request_regions(pcidev, driver_name)) {
 989		printk(KERN_ERR "hptiop: pci_request_regions failed\n");
 990		goto disable_pci_device;
 991	}
 992
 993	host = scsi_host_alloc(&driver_template, sizeof(struct hptiop_hba));
 994	if (!host) {
 995		printk(KERN_ERR "hptiop: fail to alloc scsi host\n");
 996		goto free_pci_regions;
 997	}
 998
 999	hba = (struct hptiop_hba *)host->hostdata;
 
1000
1001	hba->ops = (struct hptiop_adapter_ops *)id->driver_data;
1002	hba->pcidev = pcidev;
1003	hba->host = host;
1004	hba->initialized = 0;
1005	hba->iopintf_v2 = 0;
1006
1007	atomic_set(&hba->resetting, 0);
1008	atomic_set(&hba->reset_count, 0);
1009
1010	init_waitqueue_head(&hba->reset_wq);
1011	init_waitqueue_head(&hba->ioctl_wq);
1012
1013	host->max_lun = 1;
1014	host->max_channel = 0;
1015	host->io_port = 0;
1016	host->n_io_port = 0;
1017	host->irq = pcidev->irq;
1018
1019	if (hba->ops->map_pci_bar(hba))
1020		goto free_scsi_host;
1021
1022	if (hba->ops->iop_wait_ready(hba, 20000)) {
1023		printk(KERN_ERR "scsi%d: firmware not ready\n",
1024				hba->host->host_no);
1025		goto unmap_pci_bar;
1026	}
1027
1028	if (hba->ops->internal_memalloc) {
1029		if (hba->ops->internal_memalloc(hba)) {
1030			printk(KERN_ERR "scsi%d: internal_memalloc failed\n",
1031				hba->host->host_no);
1032			goto unmap_pci_bar;
1033		}
1034	}
1035
1036	if (hba->ops->get_config(hba, &iop_config)) {
1037		printk(KERN_ERR "scsi%d: get config failed\n",
1038				hba->host->host_no);
1039		goto unmap_pci_bar;
1040	}
1041
1042	hba->max_requests = min(le32_to_cpu(iop_config.max_requests),
1043				HPTIOP_MAX_REQUESTS);
1044	hba->max_devices = le32_to_cpu(iop_config.max_devices);
1045	hba->max_request_size = le32_to_cpu(iop_config.request_size);
1046	hba->max_sg_descriptors = le32_to_cpu(iop_config.max_sg_count);
1047	hba->firmware_version = le32_to_cpu(iop_config.firmware_version);
1048	hba->interface_version = le32_to_cpu(iop_config.interface_version);
1049	hba->sdram_size = le32_to_cpu(iop_config.sdram_size);
1050
 
 
 
 
 
 
 
 
 
 
 
 
 
1051	if (hba->firmware_version > 0x01020000 ||
1052			hba->interface_version > 0x01020000)
1053		hba->iopintf_v2 = 1;
1054
1055	host->max_sectors = le32_to_cpu(iop_config.data_transfer_length) >> 9;
1056	host->max_id = le32_to_cpu(iop_config.max_devices);
1057	host->sg_tablesize = le32_to_cpu(iop_config.max_sg_count);
1058	host->can_queue = le32_to_cpu(iop_config.max_requests);
1059	host->cmd_per_lun = le32_to_cpu(iop_config.max_requests);
1060	host->max_cmd_len = 16;
1061
1062	req_size = sizeof(struct hpt_iop_request_scsi_command)
1063		+ sizeof(struct hpt_iopsg) * (hba->max_sg_descriptors - 1);
1064	if ((req_size & 0x1f) != 0)
1065		req_size = (req_size + 0x1f) & ~0x1f;
1066
1067	memset(&set_config, 0, sizeof(struct hpt_iop_request_set_config));
1068	set_config.iop_id = cpu_to_le32(host->host_no);
1069	set_config.vbus_id = cpu_to_le16(host->host_no);
1070	set_config.max_host_request_size = cpu_to_le16(req_size);
1071
1072	if (hba->ops->set_config(hba, &set_config)) {
1073		printk(KERN_ERR "scsi%d: set config failed\n",
1074				hba->host->host_no);
1075		goto unmap_pci_bar;
1076	}
1077
1078	pci_set_drvdata(pcidev, host);
1079
1080	if (request_irq(pcidev->irq, hptiop_intr, IRQF_SHARED,
1081					driver_name, hba)) {
1082		printk(KERN_ERR "scsi%d: request irq %d failed\n",
1083					hba->host->host_no, pcidev->irq);
1084		goto unmap_pci_bar;
1085	}
1086
1087	/* Allocate request mem */
1088
1089	dprintk("req_size=%d, max_requests=%d\n", req_size, hba->max_requests);
1090
1091	hba->req_size = req_size;
1092	start_virt = dma_alloc_coherent(&pcidev->dev,
1093				hba->req_size*hba->max_requests + 0x20,
1094				&start_phy, GFP_KERNEL);
1095
1096	if (!start_virt) {
1097		printk(KERN_ERR "scsi%d: fail to alloc request mem\n",
1098					hba->host->host_no);
1099		goto free_request_irq;
1100	}
 
 
 
 
 
1101
1102	hba->dma_coherent = start_virt;
1103	hba->dma_coherent_handle = start_phy;
1104
1105	if ((start_phy & 0x1f) != 0)
1106	{
1107		offset = ((start_phy + 0x1f) & ~0x1f) - start_phy;
1108		start_phy += offset;
1109		start_virt += offset;
1110	}
1111
1112	hba->req_list = start_virt;
1113	for (i = 0; i < hba->max_requests; i++) {
1114		hba->reqs[i].next = NULL;
1115		hba->reqs[i].req_virt = start_virt;
1116		hba->reqs[i].req_shifted_phy = start_phy >> 5;
1117		hba->reqs[i].index = i;
1118		free_req(hba, &hba->reqs[i]);
1119		start_virt = (char *)start_virt + hba->req_size;
1120		start_phy = start_phy + hba->req_size;
1121	}
1122
1123	/* Enable Interrupt and start background task */
1124	if (hptiop_initialize_iop(hba))
1125		goto free_request_mem;
1126
1127	if (scsi_add_host(host, &pcidev->dev)) {
1128		printk(KERN_ERR "scsi%d: scsi_add_host failed\n",
1129					hba->host->host_no);
1130		goto free_request_mem;
1131	}
1132
1133
1134	scsi_scan_host(host);
1135
1136	dprintk("scsi%d: hptiop_probe successfully\n", hba->host->host_no);
1137	return 0;
1138
1139free_request_mem:
1140	dma_free_coherent(&hba->pcidev->dev,
1141			hba->req_size * hba->max_requests + 0x20,
1142			hba->dma_coherent, hba->dma_coherent_handle);
 
 
 
 
 
 
1143
1144free_request_irq:
1145	free_irq(hba->pcidev->irq, hba);
1146
1147unmap_pci_bar:
1148	if (hba->ops->internal_memfree)
1149		hba->ops->internal_memfree(hba);
1150
1151	hba->ops->unmap_pci_bar(hba);
1152
1153free_scsi_host:
1154	scsi_host_put(host);
1155
1156free_pci_regions:
1157	pci_release_regions(pcidev);
1158
1159disable_pci_device:
1160	pci_disable_device(pcidev);
1161
1162	dprintk("scsi%d: hptiop_probe fail\n", host ? host->host_no : 0);
1163	return -ENODEV;
1164}
1165
1166static void hptiop_shutdown(struct pci_dev *pcidev)
1167{
1168	struct Scsi_Host *host = pci_get_drvdata(pcidev);
1169	struct hptiop_hba *hba = (struct hptiop_hba *)host->hostdata;
1170
1171	dprintk("hptiop_shutdown(%p)\n", hba);
1172
1173	/* stop the iop */
1174	if (iop_send_sync_msg(hba, IOPMU_INBOUND_MSG0_SHUTDOWN, 60000))
1175		printk(KERN_ERR "scsi%d: shutdown the iop timeout\n",
1176					hba->host->host_no);
1177
1178	/* disable all outbound interrupts */
1179	hba->ops->disable_intr(hba);
1180}
1181
1182static void hptiop_disable_intr_itl(struct hptiop_hba *hba)
1183{
1184	u32 int_mask;
1185
1186	int_mask = readl(&hba->u.itl.iop->outbound_intmask);
1187	writel(int_mask |
1188		IOPMU_OUTBOUND_INT_MSG0 | IOPMU_OUTBOUND_INT_POSTQUEUE,
1189		&hba->u.itl.iop->outbound_intmask);
1190	readl(&hba->u.itl.iop->outbound_intmask);
1191}
1192
1193static void hptiop_disable_intr_mv(struct hptiop_hba *hba)
1194{
1195	writel(0, &hba->u.mv.regs->outbound_intmask);
1196	readl(&hba->u.mv.regs->outbound_intmask);
1197}
1198
 
 
 
 
 
 
 
 
 
 
1199static void hptiop_remove(struct pci_dev *pcidev)
1200{
1201	struct Scsi_Host *host = pci_get_drvdata(pcidev);
1202	struct hptiop_hba *hba = (struct hptiop_hba *)host->hostdata;
 
1203
1204	dprintk("scsi%d: hptiop_remove\n", hba->host->host_no);
1205
1206	scsi_remove_host(host);
1207
1208	hptiop_shutdown(pcidev);
1209
1210	free_irq(hba->pcidev->irq, hba);
1211
1212	dma_free_coherent(&hba->pcidev->dev,
1213			hba->req_size * hba->max_requests + 0x20,
1214			hba->dma_coherent,
1215			hba->dma_coherent_handle);
 
 
 
 
 
1216
1217	if (hba->ops->internal_memfree)
1218		hba->ops->internal_memfree(hba);
1219
1220	hba->ops->unmap_pci_bar(hba);
1221
1222	pci_release_regions(hba->pcidev);
1223	pci_set_drvdata(hba->pcidev, NULL);
1224	pci_disable_device(hba->pcidev);
1225
1226	scsi_host_put(host);
1227}
1228
1229static struct hptiop_adapter_ops hptiop_itl_ops = {
 
1230	.iop_wait_ready    = iop_wait_ready_itl,
1231	.internal_memalloc = NULL,
1232	.internal_memfree  = NULL,
1233	.map_pci_bar       = hptiop_map_pci_bar_itl,
1234	.unmap_pci_bar     = hptiop_unmap_pci_bar_itl,
1235	.enable_intr       = hptiop_enable_intr_itl,
1236	.disable_intr      = hptiop_disable_intr_itl,
1237	.get_config        = iop_get_config_itl,
1238	.set_config        = iop_set_config_itl,
1239	.iop_intr          = iop_intr_itl,
1240	.post_msg          = hptiop_post_msg_itl,
1241	.post_req          = hptiop_post_req_itl,
 
 
 
1242};
1243
1244static struct hptiop_adapter_ops hptiop_mv_ops = {
 
1245	.iop_wait_ready    = iop_wait_ready_mv,
1246	.internal_memalloc = hptiop_internal_memalloc_mv,
1247	.internal_memfree  = hptiop_internal_memfree_mv,
1248	.map_pci_bar       = hptiop_map_pci_bar_mv,
1249	.unmap_pci_bar     = hptiop_unmap_pci_bar_mv,
1250	.enable_intr       = hptiop_enable_intr_mv,
1251	.disable_intr      = hptiop_disable_intr_mv,
1252	.get_config        = iop_get_config_mv,
1253	.set_config        = iop_set_config_mv,
1254	.iop_intr          = iop_intr_mv,
1255	.post_msg          = hptiop_post_msg_mv,
1256	.post_req          = hptiop_post_req_mv,
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1257};
1258
1259static struct pci_device_id hptiop_id_table[] = {
1260	{ PCI_VDEVICE(TTI, 0x3220), (kernel_ulong_t)&hptiop_itl_ops },
1261	{ PCI_VDEVICE(TTI, 0x3320), (kernel_ulong_t)&hptiop_itl_ops },
1262	{ PCI_VDEVICE(TTI, 0x3410), (kernel_ulong_t)&hptiop_itl_ops },
1263	{ PCI_VDEVICE(TTI, 0x3510), (kernel_ulong_t)&hptiop_itl_ops },
1264	{ PCI_VDEVICE(TTI, 0x3511), (kernel_ulong_t)&hptiop_itl_ops },
1265	{ PCI_VDEVICE(TTI, 0x3520), (kernel_ulong_t)&hptiop_itl_ops },
1266	{ PCI_VDEVICE(TTI, 0x3521), (kernel_ulong_t)&hptiop_itl_ops },
1267	{ PCI_VDEVICE(TTI, 0x3522), (kernel_ulong_t)&hptiop_itl_ops },
1268	{ PCI_VDEVICE(TTI, 0x3530), (kernel_ulong_t)&hptiop_itl_ops },
1269	{ PCI_VDEVICE(TTI, 0x3540), (kernel_ulong_t)&hptiop_itl_ops },
1270	{ PCI_VDEVICE(TTI, 0x3560), (kernel_ulong_t)&hptiop_itl_ops },
1271	{ PCI_VDEVICE(TTI, 0x4210), (kernel_ulong_t)&hptiop_itl_ops },
1272	{ PCI_VDEVICE(TTI, 0x4211), (kernel_ulong_t)&hptiop_itl_ops },
1273	{ PCI_VDEVICE(TTI, 0x4310), (kernel_ulong_t)&hptiop_itl_ops },
1274	{ PCI_VDEVICE(TTI, 0x4311), (kernel_ulong_t)&hptiop_itl_ops },
1275	{ PCI_VDEVICE(TTI, 0x4320), (kernel_ulong_t)&hptiop_itl_ops },
1276	{ PCI_VDEVICE(TTI, 0x4321), (kernel_ulong_t)&hptiop_itl_ops },
1277	{ PCI_VDEVICE(TTI, 0x4322), (kernel_ulong_t)&hptiop_itl_ops },
1278	{ PCI_VDEVICE(TTI, 0x4400), (kernel_ulong_t)&hptiop_itl_ops },
1279	{ PCI_VDEVICE(TTI, 0x3120), (kernel_ulong_t)&hptiop_mv_ops },
1280	{ PCI_VDEVICE(TTI, 0x3122), (kernel_ulong_t)&hptiop_mv_ops },
1281	{ PCI_VDEVICE(TTI, 0x3020), (kernel_ulong_t)&hptiop_mv_ops },
 
 
 
 
 
 
 
 
 
 
1282	{},
1283};
1284
1285MODULE_DEVICE_TABLE(pci, hptiop_id_table);
1286
1287static struct pci_driver hptiop_pci_driver = {
1288	.name       = driver_name,
1289	.id_table   = hptiop_id_table,
1290	.probe      = hptiop_probe,
1291	.remove     = hptiop_remove,
1292	.shutdown   = hptiop_shutdown,
1293};
1294
1295static int __init hptiop_module_init(void)
1296{
1297	printk(KERN_INFO "%s %s\n", driver_name_long, driver_ver);
1298	return pci_register_driver(&hptiop_pci_driver);
1299}
1300
1301static void __exit hptiop_module_exit(void)
1302{
1303	pci_unregister_driver(&hptiop_pci_driver);
1304}
1305
1306
1307module_init(hptiop_module_init);
1308module_exit(hptiop_module_exit);
1309
1310MODULE_LICENSE("GPL");
1311
v5.9
   1// SPDX-License-Identifier: GPL-2.0-only
   2/*
   3 * HighPoint RR3xxx/4xxx controller driver for Linux
   4 * Copyright (C) 2006-2015 HighPoint Technologies, Inc. All Rights Reserved.
 
 
 
 
 
 
 
 
 
   5 *
   6 * Please report bugs/comments/suggestions to linux@highpoint-tech.com
   7 *
   8 * For more information, visit http://www.highpoint-tech.com
   9 */
  10#include <linux/module.h>
  11#include <linux/types.h>
  12#include <linux/string.h>
  13#include <linux/kernel.h>
  14#include <linux/pci.h>
  15#include <linux/interrupt.h>
  16#include <linux/errno.h>
  17#include <linux/delay.h>
  18#include <linux/timer.h>
  19#include <linux/spinlock.h>
  20#include <linux/gfp.h>
  21#include <linux/uaccess.h>
  22#include <asm/io.h>
  23#include <asm/div64.h>
  24#include <scsi/scsi_cmnd.h>
  25#include <scsi/scsi_device.h>
  26#include <scsi/scsi.h>
  27#include <scsi/scsi_tcq.h>
  28#include <scsi/scsi_host.h>
  29
  30#include "hptiop.h"
  31
  32MODULE_AUTHOR("HighPoint Technologies, Inc.");
  33MODULE_DESCRIPTION("HighPoint RocketRAID 3xxx/4xxx Controller Driver");
  34
  35static char driver_name[] = "hptiop";
  36static const char driver_name_long[] = "RocketRAID 3xxx/4xxx Controller driver";
  37static const char driver_ver[] = "v1.10.0";
  38
  39static int iop_send_sync_msg(struct hptiop_hba *hba, u32 msg, u32 millisec);
  40static void hptiop_finish_scsi_req(struct hptiop_hba *hba, u32 tag,
  41				struct hpt_iop_request_scsi_command *req);
  42static void hptiop_host_request_callback_itl(struct hptiop_hba *hba, u32 tag);
  43static void hptiop_iop_request_callback_itl(struct hptiop_hba *hba, u32 tag);
  44static void hptiop_message_callback(struct hptiop_hba *hba, u32 msg);
  45
  46static int iop_wait_ready_itl(struct hptiop_hba *hba, u32 millisec)
  47{
  48	u32 req = 0;
  49	int i;
  50
  51	for (i = 0; i < millisec; i++) {
  52		req = readl(&hba->u.itl.iop->inbound_queue);
  53		if (req != IOPMU_QUEUE_EMPTY)
  54			break;
  55		msleep(1);
  56	}
  57
  58	if (req != IOPMU_QUEUE_EMPTY) {
  59		writel(req, &hba->u.itl.iop->outbound_queue);
  60		readl(&hba->u.itl.iop->outbound_intstatus);
  61		return 0;
  62	}
  63
  64	return -1;
  65}
  66
  67static int iop_wait_ready_mv(struct hptiop_hba *hba, u32 millisec)
  68{
  69	return iop_send_sync_msg(hba, IOPMU_INBOUND_MSG0_NOP, millisec);
  70}
  71
  72static int iop_wait_ready_mvfrey(struct hptiop_hba *hba, u32 millisec)
  73{
  74	return iop_send_sync_msg(hba, IOPMU_INBOUND_MSG0_NOP, millisec);
  75}
  76
  77static void hptiop_request_callback_itl(struct hptiop_hba *hba, u32 tag)
  78{
  79	if (tag & IOPMU_QUEUE_ADDR_HOST_BIT)
  80		hptiop_host_request_callback_itl(hba,
  81				tag & ~IOPMU_QUEUE_ADDR_HOST_BIT);
  82	else
  83		hptiop_iop_request_callback_itl(hba, tag);
  84}
  85
  86static void hptiop_drain_outbound_queue_itl(struct hptiop_hba *hba)
  87{
  88	u32 req;
  89
  90	while ((req = readl(&hba->u.itl.iop->outbound_queue)) !=
  91						IOPMU_QUEUE_EMPTY) {
  92
  93		if (req & IOPMU_QUEUE_MASK_HOST_BITS)
  94			hptiop_request_callback_itl(hba, req);
  95		else {
  96			struct hpt_iop_request_header __iomem * p;
  97
  98			p = (struct hpt_iop_request_header __iomem *)
  99				((char __iomem *)hba->u.itl.iop + req);
 100
 101			if (readl(&p->flags) & IOP_REQUEST_FLAG_SYNC_REQUEST) {
 102				if (readl(&p->context))
 103					hptiop_request_callback_itl(hba, req);
 104				else
 105					writel(1, &p->context);
 106			}
 107			else
 108				hptiop_request_callback_itl(hba, req);
 109		}
 110	}
 111}
 112
 113static int iop_intr_itl(struct hptiop_hba *hba)
 114{
 115	struct hpt_iopmu_itl __iomem *iop = hba->u.itl.iop;
 116	void __iomem *plx = hba->u.itl.plx;
 117	u32 status;
 118	int ret = 0;
 119
 120	if (plx && readl(plx + 0x11C5C) & 0xf)
 121		writel(1, plx + 0x11C60);
 122
 123	status = readl(&iop->outbound_intstatus);
 124
 125	if (status & IOPMU_OUTBOUND_INT_MSG0) {
 126		u32 msg = readl(&iop->outbound_msgaddr0);
 127
 128		dprintk("received outbound msg %x\n", msg);
 129		writel(IOPMU_OUTBOUND_INT_MSG0, &iop->outbound_intstatus);
 130		hptiop_message_callback(hba, msg);
 131		ret = 1;
 132	}
 133
 134	if (status & IOPMU_OUTBOUND_INT_POSTQUEUE) {
 135		hptiop_drain_outbound_queue_itl(hba);
 136		ret = 1;
 137	}
 138
 139	return ret;
 140}
 141
 142static u64 mv_outbound_read(struct hpt_iopmu_mv __iomem *mu)
 143{
 144	u32 outbound_tail = readl(&mu->outbound_tail);
 145	u32 outbound_head = readl(&mu->outbound_head);
 146
 147	if (outbound_tail != outbound_head) {
 148		u64 p;
 149
 150		memcpy_fromio(&p, &mu->outbound_q[mu->outbound_tail], 8);
 151		outbound_tail++;
 152
 153		if (outbound_tail == MVIOP_QUEUE_LEN)
 154			outbound_tail = 0;
 155		writel(outbound_tail, &mu->outbound_tail);
 156		return p;
 157	} else
 158		return 0;
 159}
 160
 161static void mv_inbound_write(u64 p, struct hptiop_hba *hba)
 162{
 163	u32 inbound_head = readl(&hba->u.mv.mu->inbound_head);
 164	u32 head = inbound_head + 1;
 165
 166	if (head == MVIOP_QUEUE_LEN)
 167		head = 0;
 168
 169	memcpy_toio(&hba->u.mv.mu->inbound_q[inbound_head], &p, 8);
 170	writel(head, &hba->u.mv.mu->inbound_head);
 171	writel(MVIOP_MU_INBOUND_INT_POSTQUEUE,
 172			&hba->u.mv.regs->inbound_doorbell);
 173}
 174
 175static void hptiop_request_callback_mv(struct hptiop_hba *hba, u64 tag)
 176{
 177	u32 req_type = (tag >> 5) & 0x7;
 178	struct hpt_iop_request_scsi_command *req;
 179
 180	dprintk("hptiop_request_callback_mv: tag=%llx\n", tag);
 181
 182	BUG_ON((tag & MVIOP_MU_QUEUE_REQUEST_RETURN_CONTEXT) == 0);
 183
 184	switch (req_type) {
 185	case IOP_REQUEST_TYPE_GET_CONFIG:
 186	case IOP_REQUEST_TYPE_SET_CONFIG:
 187		hba->msg_done = 1;
 188		break;
 189
 190	case IOP_REQUEST_TYPE_SCSI_COMMAND:
 191		req = hba->reqs[tag >> 8].req_virt;
 192		if (likely(tag & MVIOP_MU_QUEUE_REQUEST_RESULT_BIT))
 193			req->header.result = cpu_to_le32(IOP_RESULT_SUCCESS);
 194
 195		hptiop_finish_scsi_req(hba, tag>>8, req);
 196		break;
 197
 198	default:
 199		break;
 200	}
 201}
 202
 203static int iop_intr_mv(struct hptiop_hba *hba)
 204{
 205	u32 status;
 206	int ret = 0;
 207
 208	status = readl(&hba->u.mv.regs->outbound_doorbell);
 209	writel(~status, &hba->u.mv.regs->outbound_doorbell);
 210
 211	if (status & MVIOP_MU_OUTBOUND_INT_MSG) {
 212		u32 msg;
 213		msg = readl(&hba->u.mv.mu->outbound_msg);
 214		dprintk("received outbound msg %x\n", msg);
 215		hptiop_message_callback(hba, msg);
 216		ret = 1;
 217	}
 218
 219	if (status & MVIOP_MU_OUTBOUND_INT_POSTQUEUE) {
 220		u64 tag;
 221
 222		while ((tag = mv_outbound_read(hba->u.mv.mu)))
 223			hptiop_request_callback_mv(hba, tag);
 224		ret = 1;
 225	}
 226
 227	return ret;
 228}
 229
 230static void hptiop_request_callback_mvfrey(struct hptiop_hba *hba, u32 _tag)
 231{
 232	u32 req_type = _tag & 0xf;
 233	struct hpt_iop_request_scsi_command *req;
 234
 235	switch (req_type) {
 236	case IOP_REQUEST_TYPE_GET_CONFIG:
 237	case IOP_REQUEST_TYPE_SET_CONFIG:
 238		hba->msg_done = 1;
 239		break;
 240
 241	case IOP_REQUEST_TYPE_SCSI_COMMAND:
 242		req = hba->reqs[(_tag >> 4) & 0xff].req_virt;
 243		if (likely(_tag & IOPMU_QUEUE_REQUEST_RESULT_BIT))
 244			req->header.result = IOP_RESULT_SUCCESS;
 245		hptiop_finish_scsi_req(hba, (_tag >> 4) & 0xff, req);
 246		break;
 247
 248	default:
 249		break;
 250	}
 251}
 252
 253static int iop_intr_mvfrey(struct hptiop_hba *hba)
 254{
 255	u32 _tag, status, cptr, cur_rptr;
 256	int ret = 0;
 257
 258	if (hba->initialized)
 259		writel(0, &(hba->u.mvfrey.mu->pcie_f0_int_enable));
 260
 261	status = readl(&(hba->u.mvfrey.mu->f0_doorbell));
 262	if (status) {
 263		writel(status, &(hba->u.mvfrey.mu->f0_doorbell));
 264		if (status & CPU_TO_F0_DRBL_MSG_BIT) {
 265			u32 msg = readl(&(hba->u.mvfrey.mu->cpu_to_f0_msg_a));
 266			dprintk("received outbound msg %x\n", msg);
 267			hptiop_message_callback(hba, msg);
 268		}
 269		ret = 1;
 270	}
 271
 272	status = readl(&(hba->u.mvfrey.mu->isr_cause));
 273	if (status) {
 274		writel(status, &(hba->u.mvfrey.mu->isr_cause));
 275		do {
 276			cptr = *hba->u.mvfrey.outlist_cptr & 0xff;
 277			cur_rptr = hba->u.mvfrey.outlist_rptr;
 278			while (cur_rptr != cptr) {
 279				cur_rptr++;
 280				if (cur_rptr ==	hba->u.mvfrey.list_count)
 281					cur_rptr = 0;
 282
 283				_tag = hba->u.mvfrey.outlist[cur_rptr].val;
 284				BUG_ON(!(_tag & IOPMU_QUEUE_MASK_HOST_BITS));
 285				hptiop_request_callback_mvfrey(hba, _tag);
 286				ret = 1;
 287			}
 288			hba->u.mvfrey.outlist_rptr = cur_rptr;
 289		} while (cptr != (*hba->u.mvfrey.outlist_cptr & 0xff));
 290	}
 291
 292	if (hba->initialized)
 293		writel(0x1010, &(hba->u.mvfrey.mu->pcie_f0_int_enable));
 294
 295	return ret;
 296}
 297
 298static int iop_send_sync_request_itl(struct hptiop_hba *hba,
 299					void __iomem *_req, u32 millisec)
 300{
 301	struct hpt_iop_request_header __iomem *req = _req;
 302	u32 i;
 303
 304	writel(readl(&req->flags) | IOP_REQUEST_FLAG_SYNC_REQUEST, &req->flags);
 305	writel(0, &req->context);
 306	writel((unsigned long)req - (unsigned long)hba->u.itl.iop,
 307			&hba->u.itl.iop->inbound_queue);
 308	readl(&hba->u.itl.iop->outbound_intstatus);
 309
 310	for (i = 0; i < millisec; i++) {
 311		iop_intr_itl(hba);
 312		if (readl(&req->context))
 313			return 0;
 314		msleep(1);
 315	}
 316
 317	return -1;
 318}
 319
 320static int iop_send_sync_request_mv(struct hptiop_hba *hba,
 321					u32 size_bits, u32 millisec)
 322{
 323	struct hpt_iop_request_header *reqhdr = hba->u.mv.internal_req;
 324	u32 i;
 325
 326	hba->msg_done = 0;
 327	reqhdr->flags |= cpu_to_le32(IOP_REQUEST_FLAG_SYNC_REQUEST);
 328	mv_inbound_write(hba->u.mv.internal_req_phy |
 329			MVIOP_MU_QUEUE_ADDR_HOST_BIT | size_bits, hba);
 330
 331	for (i = 0; i < millisec; i++) {
 332		iop_intr_mv(hba);
 333		if (hba->msg_done)
 334			return 0;
 335		msleep(1);
 336	}
 337	return -1;
 338}
 339
 340static int iop_send_sync_request_mvfrey(struct hptiop_hba *hba,
 341					u32 size_bits, u32 millisec)
 342{
 343	struct hpt_iop_request_header *reqhdr =
 344		hba->u.mvfrey.internal_req.req_virt;
 345	u32 i;
 346
 347	hba->msg_done = 0;
 348	reqhdr->flags |= cpu_to_le32(IOP_REQUEST_FLAG_SYNC_REQUEST);
 349	hba->ops->post_req(hba, &(hba->u.mvfrey.internal_req));
 350
 351	for (i = 0; i < millisec; i++) {
 352		iop_intr_mvfrey(hba);
 353		if (hba->msg_done)
 354			break;
 355		msleep(1);
 356	}
 357	return hba->msg_done ? 0 : -1;
 358}
 359
 360static void hptiop_post_msg_itl(struct hptiop_hba *hba, u32 msg)
 361{
 362	writel(msg, &hba->u.itl.iop->inbound_msgaddr0);
 363	readl(&hba->u.itl.iop->outbound_intstatus);
 364}
 365
 366static void hptiop_post_msg_mv(struct hptiop_hba *hba, u32 msg)
 367{
 368	writel(msg, &hba->u.mv.mu->inbound_msg);
 369	writel(MVIOP_MU_INBOUND_INT_MSG, &hba->u.mv.regs->inbound_doorbell);
 370	readl(&hba->u.mv.regs->inbound_doorbell);
 371}
 372
 373static void hptiop_post_msg_mvfrey(struct hptiop_hba *hba, u32 msg)
 374{
 375	writel(msg, &(hba->u.mvfrey.mu->f0_to_cpu_msg_a));
 376	readl(&(hba->u.mvfrey.mu->f0_to_cpu_msg_a));
 377}
 378
 379static int iop_send_sync_msg(struct hptiop_hba *hba, u32 msg, u32 millisec)
 380{
 381	u32 i;
 382
 383	hba->msg_done = 0;
 384	hba->ops->disable_intr(hba);
 385	hba->ops->post_msg(hba, msg);
 386
 387	for (i = 0; i < millisec; i++) {
 388		spin_lock_irq(hba->host->host_lock);
 389		hba->ops->iop_intr(hba);
 390		spin_unlock_irq(hba->host->host_lock);
 391		if (hba->msg_done)
 392			break;
 393		msleep(1);
 394	}
 395
 396	hba->ops->enable_intr(hba);
 397	return hba->msg_done? 0 : -1;
 398}
 399
 400static int iop_get_config_itl(struct hptiop_hba *hba,
 401				struct hpt_iop_request_get_config *config)
 402{
 403	u32 req32;
 404	struct hpt_iop_request_get_config __iomem *req;
 405
 406	req32 = readl(&hba->u.itl.iop->inbound_queue);
 407	if (req32 == IOPMU_QUEUE_EMPTY)
 408		return -1;
 409
 410	req = (struct hpt_iop_request_get_config __iomem *)
 411			((unsigned long)hba->u.itl.iop + req32);
 412
 413	writel(0, &req->header.flags);
 414	writel(IOP_REQUEST_TYPE_GET_CONFIG, &req->header.type);
 415	writel(sizeof(struct hpt_iop_request_get_config), &req->header.size);
 416	writel(IOP_RESULT_PENDING, &req->header.result);
 417
 418	if (iop_send_sync_request_itl(hba, req, 20000)) {
 419		dprintk("Get config send cmd failed\n");
 420		return -1;
 421	}
 422
 423	memcpy_fromio(config, req, sizeof(*config));
 424	writel(req32, &hba->u.itl.iop->outbound_queue);
 425	return 0;
 426}
 427
 428static int iop_get_config_mv(struct hptiop_hba *hba,
 429				struct hpt_iop_request_get_config *config)
 430{
 431	struct hpt_iop_request_get_config *req = hba->u.mv.internal_req;
 432
 433	req->header.flags = cpu_to_le32(IOP_REQUEST_FLAG_OUTPUT_CONTEXT);
 434	req->header.type = cpu_to_le32(IOP_REQUEST_TYPE_GET_CONFIG);
 435	req->header.size =
 436		cpu_to_le32(sizeof(struct hpt_iop_request_get_config));
 437	req->header.result = cpu_to_le32(IOP_RESULT_PENDING);
 438	req->header.context = cpu_to_le32(IOP_REQUEST_TYPE_GET_CONFIG<<5);
 439	req->header.context_hi32 = 0;
 440
 441	if (iop_send_sync_request_mv(hba, 0, 20000)) {
 442		dprintk("Get config send cmd failed\n");
 443		return -1;
 444	}
 445
 446	memcpy(config, req, sizeof(struct hpt_iop_request_get_config));
 447	return 0;
 448}
 449
 450static int iop_get_config_mvfrey(struct hptiop_hba *hba,
 451				struct hpt_iop_request_get_config *config)
 452{
 453	struct hpt_iop_request_get_config *info = hba->u.mvfrey.config;
 454
 455	if (info->header.size != sizeof(struct hpt_iop_request_get_config) ||
 456			info->header.type != IOP_REQUEST_TYPE_GET_CONFIG)
 457		return -1;
 458
 459	config->interface_version = info->interface_version;
 460	config->firmware_version = info->firmware_version;
 461	config->max_requests = info->max_requests;
 462	config->request_size = info->request_size;
 463	config->max_sg_count = info->max_sg_count;
 464	config->data_transfer_length = info->data_transfer_length;
 465	config->alignment_mask = info->alignment_mask;
 466	config->max_devices = info->max_devices;
 467	config->sdram_size = info->sdram_size;
 468
 469	return 0;
 470}
 471
 472static int iop_set_config_itl(struct hptiop_hba *hba,
 473				struct hpt_iop_request_set_config *config)
 474{
 475	u32 req32;
 476	struct hpt_iop_request_set_config __iomem *req;
 477
 478	req32 = readl(&hba->u.itl.iop->inbound_queue);
 479	if (req32 == IOPMU_QUEUE_EMPTY)
 480		return -1;
 481
 482	req = (struct hpt_iop_request_set_config __iomem *)
 483			((unsigned long)hba->u.itl.iop + req32);
 484
 485	memcpy_toio((u8 __iomem *)req + sizeof(struct hpt_iop_request_header),
 486		(u8 *)config + sizeof(struct hpt_iop_request_header),
 487		sizeof(struct hpt_iop_request_set_config) -
 488			sizeof(struct hpt_iop_request_header));
 489
 490	writel(0, &req->header.flags);
 491	writel(IOP_REQUEST_TYPE_SET_CONFIG, &req->header.type);
 492	writel(sizeof(struct hpt_iop_request_set_config), &req->header.size);
 493	writel(IOP_RESULT_PENDING, &req->header.result);
 494
 495	if (iop_send_sync_request_itl(hba, req, 20000)) {
 496		dprintk("Set config send cmd failed\n");
 497		return -1;
 498	}
 499
 500	writel(req32, &hba->u.itl.iop->outbound_queue);
 501	return 0;
 502}
 503
 504static int iop_set_config_mv(struct hptiop_hba *hba,
 505				struct hpt_iop_request_set_config *config)
 506{
 507	struct hpt_iop_request_set_config *req = hba->u.mv.internal_req;
 508
 509	memcpy(req, config, sizeof(struct hpt_iop_request_set_config));
 510	req->header.flags = cpu_to_le32(IOP_REQUEST_FLAG_OUTPUT_CONTEXT);
 511	req->header.type = cpu_to_le32(IOP_REQUEST_TYPE_SET_CONFIG);
 512	req->header.size =
 513		cpu_to_le32(sizeof(struct hpt_iop_request_set_config));
 514	req->header.result = cpu_to_le32(IOP_RESULT_PENDING);
 515	req->header.context = cpu_to_le32(IOP_REQUEST_TYPE_SET_CONFIG<<5);
 516	req->header.context_hi32 = 0;
 517
 518	if (iop_send_sync_request_mv(hba, 0, 20000)) {
 519		dprintk("Set config send cmd failed\n");
 520		return -1;
 521	}
 522
 523	return 0;
 524}
 525
 526static int iop_set_config_mvfrey(struct hptiop_hba *hba,
 527				struct hpt_iop_request_set_config *config)
 528{
 529	struct hpt_iop_request_set_config *req =
 530		hba->u.mvfrey.internal_req.req_virt;
 531
 532	memcpy(req, config, sizeof(struct hpt_iop_request_set_config));
 533	req->header.flags = cpu_to_le32(IOP_REQUEST_FLAG_OUTPUT_CONTEXT);
 534	req->header.type = cpu_to_le32(IOP_REQUEST_TYPE_SET_CONFIG);
 535	req->header.size =
 536		cpu_to_le32(sizeof(struct hpt_iop_request_set_config));
 537	req->header.result = cpu_to_le32(IOP_RESULT_PENDING);
 538	req->header.context = cpu_to_le32(IOP_REQUEST_TYPE_SET_CONFIG<<5);
 539	req->header.context_hi32 = 0;
 540
 541	if (iop_send_sync_request_mvfrey(hba, 0, 20000)) {
 542		dprintk("Set config send cmd failed\n");
 543		return -1;
 544	}
 545
 546	return 0;
 547}
 548
 549static void hptiop_enable_intr_itl(struct hptiop_hba *hba)
 550{
 551	writel(~(IOPMU_OUTBOUND_INT_POSTQUEUE | IOPMU_OUTBOUND_INT_MSG0),
 552		&hba->u.itl.iop->outbound_intmask);
 553}
 554
 555static void hptiop_enable_intr_mv(struct hptiop_hba *hba)
 556{
 557	writel(MVIOP_MU_OUTBOUND_INT_POSTQUEUE | MVIOP_MU_OUTBOUND_INT_MSG,
 558		&hba->u.mv.regs->outbound_intmask);
 559}
 560
 561static void hptiop_enable_intr_mvfrey(struct hptiop_hba *hba)
 562{
 563	writel(CPU_TO_F0_DRBL_MSG_BIT, &(hba->u.mvfrey.mu->f0_doorbell_enable));
 564	writel(0x1, &(hba->u.mvfrey.mu->isr_enable));
 565	writel(0x1010, &(hba->u.mvfrey.mu->pcie_f0_int_enable));
 566}
 567
 568static int hptiop_initialize_iop(struct hptiop_hba *hba)
 569{
 570	/* enable interrupts */
 571	hba->ops->enable_intr(hba);
 572
 573	hba->initialized = 1;
 574
 575	/* start background tasks */
 576	if (iop_send_sync_msg(hba,
 577			IOPMU_INBOUND_MSG0_START_BACKGROUND_TASK, 5000)) {
 578		printk(KERN_ERR "scsi%d: fail to start background task\n",
 579			hba->host->host_no);
 580		return -1;
 581	}
 582	return 0;
 583}
 584
 585static void __iomem *hptiop_map_pci_bar(struct hptiop_hba *hba, int index)
 586{
 587	u32 mem_base_phy, length;
 588	void __iomem *mem_base_virt;
 589
 590	struct pci_dev *pcidev = hba->pcidev;
 591
 592
 593	if (!(pci_resource_flags(pcidev, index) & IORESOURCE_MEM)) {
 594		printk(KERN_ERR "scsi%d: pci resource invalid\n",
 595				hba->host->host_no);
 596		return NULL;
 597	}
 598
 599	mem_base_phy = pci_resource_start(pcidev, index);
 600	length = pci_resource_len(pcidev, index);
 601	mem_base_virt = ioremap(mem_base_phy, length);
 602
 603	if (!mem_base_virt) {
 604		printk(KERN_ERR "scsi%d: Fail to ioremap memory space\n",
 605				hba->host->host_no);
 606		return NULL;
 607	}
 608	return mem_base_virt;
 609}
 610
 611static int hptiop_map_pci_bar_itl(struct hptiop_hba *hba)
 612{
 613	struct pci_dev *pcidev = hba->pcidev;
 614	hba->u.itl.iop = hptiop_map_pci_bar(hba, 0);
 615	if (hba->u.itl.iop == NULL)
 616		return -1;
 617	if ((pcidev->device & 0xff00) == 0x4400) {
 618		hba->u.itl.plx = hba->u.itl.iop;
 619		hba->u.itl.iop = hptiop_map_pci_bar(hba, 2);
 620		if (hba->u.itl.iop == NULL) {
 621			iounmap(hba->u.itl.plx);
 622			return -1;
 623		}
 624	}
 625	return 0;
 626}
 627
 628static void hptiop_unmap_pci_bar_itl(struct hptiop_hba *hba)
 629{
 630	if (hba->u.itl.plx)
 631		iounmap(hba->u.itl.plx);
 632	iounmap(hba->u.itl.iop);
 633}
 634
 635static int hptiop_map_pci_bar_mv(struct hptiop_hba *hba)
 636{
 637	hba->u.mv.regs = hptiop_map_pci_bar(hba, 0);
 638	if (hba->u.mv.regs == NULL)
 639		return -1;
 640
 641	hba->u.mv.mu = hptiop_map_pci_bar(hba, 2);
 642	if (hba->u.mv.mu == NULL) {
 643		iounmap(hba->u.mv.regs);
 644		return -1;
 645	}
 646
 647	return 0;
 648}
 649
 650static int hptiop_map_pci_bar_mvfrey(struct hptiop_hba *hba)
 651{
 652	hba->u.mvfrey.config = hptiop_map_pci_bar(hba, 0);
 653	if (hba->u.mvfrey.config == NULL)
 654		return -1;
 655
 656	hba->u.mvfrey.mu = hptiop_map_pci_bar(hba, 2);
 657	if (hba->u.mvfrey.mu == NULL) {
 658		iounmap(hba->u.mvfrey.config);
 659		return -1;
 660	}
 661
 662	return 0;
 663}
 664
 665static void hptiop_unmap_pci_bar_mv(struct hptiop_hba *hba)
 666{
 667	iounmap(hba->u.mv.regs);
 668	iounmap(hba->u.mv.mu);
 669}
 670
 671static void hptiop_unmap_pci_bar_mvfrey(struct hptiop_hba *hba)
 672{
 673	iounmap(hba->u.mvfrey.config);
 674	iounmap(hba->u.mvfrey.mu);
 675}
 676
 677static void hptiop_message_callback(struct hptiop_hba *hba, u32 msg)
 678{
 679	dprintk("iop message 0x%x\n", msg);
 680
 681	if (msg == IOPMU_INBOUND_MSG0_NOP ||
 682		msg == IOPMU_INBOUND_MSG0_RESET_COMM)
 683		hba->msg_done = 1;
 684
 685	if (!hba->initialized)
 686		return;
 687
 688	if (msg == IOPMU_INBOUND_MSG0_RESET) {
 689		atomic_set(&hba->resetting, 0);
 690		wake_up(&hba->reset_wq);
 691	}
 692	else if (msg <= IOPMU_INBOUND_MSG0_MAX)
 693		hba->msg_done = 1;
 694}
 695
 696static struct hptiop_request *get_req(struct hptiop_hba *hba)
 697{
 698	struct hptiop_request *ret;
 699
 700	dprintk("get_req : req=%p\n", hba->req_list);
 701
 702	ret = hba->req_list;
 703	if (ret)
 704		hba->req_list = ret->next;
 705
 706	return ret;
 707}
 708
 709static void free_req(struct hptiop_hba *hba, struct hptiop_request *req)
 710{
 711	dprintk("free_req(%d, %p)\n", req->index, req);
 712	req->next = hba->req_list;
 713	hba->req_list = req;
 714}
 715
 716static void hptiop_finish_scsi_req(struct hptiop_hba *hba, u32 tag,
 717				struct hpt_iop_request_scsi_command *req)
 718{
 719	struct scsi_cmnd *scp;
 720
 721	dprintk("hptiop_finish_scsi_req: req=%p, type=%d, "
 722			"result=%d, context=0x%x tag=%d\n",
 723			req, req->header.type, req->header.result,
 724			req->header.context, tag);
 725
 726	BUG_ON(!req->header.result);
 727	BUG_ON(req->header.type != cpu_to_le32(IOP_REQUEST_TYPE_SCSI_COMMAND));
 728
 729	scp = hba->reqs[tag].scp;
 730
 731	if (HPT_SCP(scp)->mapped)
 732		scsi_dma_unmap(scp);
 733
 734	switch (le32_to_cpu(req->header.result)) {
 735	case IOP_RESULT_SUCCESS:
 736		scsi_set_resid(scp,
 737			scsi_bufflen(scp) - le32_to_cpu(req->dataxfer_length));
 738		scp->result = (DID_OK<<16);
 739		break;
 740	case IOP_RESULT_BAD_TARGET:
 741		scp->result = (DID_BAD_TARGET<<16);
 742		break;
 743	case IOP_RESULT_BUSY:
 744		scp->result = (DID_BUS_BUSY<<16);
 745		break;
 746	case IOP_RESULT_RESET:
 747		scp->result = (DID_RESET<<16);
 748		break;
 749	case IOP_RESULT_FAIL:
 750		scp->result = (DID_ERROR<<16);
 751		break;
 752	case IOP_RESULT_INVALID_REQUEST:
 753		scp->result = (DID_ABORT<<16);
 754		break;
 755	case IOP_RESULT_CHECK_CONDITION:
 756		scsi_set_resid(scp,
 757			scsi_bufflen(scp) - le32_to_cpu(req->dataxfer_length));
 758		scp->result = SAM_STAT_CHECK_CONDITION;
 759		memcpy(scp->sense_buffer, &req->sg_list, SCSI_SENSE_BUFFERSIZE);
 760		goto skip_resid;
 
 761		break;
 762
 763	default:
 764		scp->result = DRIVER_INVALID << 24 | DID_ABORT << 16;
 765		break;
 766	}
 767
 768	scsi_set_resid(scp,
 769		scsi_bufflen(scp) - le32_to_cpu(req->dataxfer_length));
 770
 771skip_resid:
 772	dprintk("scsi_done(%p)\n", scp);
 773	scp->scsi_done(scp);
 774	free_req(hba, &hba->reqs[tag]);
 775}
 776
 777static void hptiop_host_request_callback_itl(struct hptiop_hba *hba, u32 _tag)
 778{
 779	struct hpt_iop_request_scsi_command *req;
 780	u32 tag;
 781
 782	if (hba->iopintf_v2) {
 783		tag = _tag & ~IOPMU_QUEUE_REQUEST_RESULT_BIT;
 784		req = hba->reqs[tag].req_virt;
 785		if (likely(_tag & IOPMU_QUEUE_REQUEST_RESULT_BIT))
 786			req->header.result = cpu_to_le32(IOP_RESULT_SUCCESS);
 787	} else {
 788		tag = _tag;
 789		req = hba->reqs[tag].req_virt;
 790	}
 791
 792	hptiop_finish_scsi_req(hba, tag, req);
 793}
 794
 795static void hptiop_iop_request_callback_itl(struct hptiop_hba *hba, u32 tag)
 796{
 797	struct hpt_iop_request_header __iomem *req;
 798	struct hpt_iop_request_ioctl_command __iomem *p;
 799	struct hpt_ioctl_k *arg;
 800
 801	req = (struct hpt_iop_request_header __iomem *)
 802			((unsigned long)hba->u.itl.iop + tag);
 803	dprintk("hptiop_iop_request_callback_itl: req=%p, type=%d, "
 804			"result=%d, context=0x%x tag=%d\n",
 805			req, readl(&req->type), readl(&req->result),
 806			readl(&req->context), tag);
 807
 808	BUG_ON(!readl(&req->result));
 809	BUG_ON(readl(&req->type) != IOP_REQUEST_TYPE_IOCTL_COMMAND);
 810
 811	p = (struct hpt_iop_request_ioctl_command __iomem *)req;
 812	arg = (struct hpt_ioctl_k *)(unsigned long)
 813		(readl(&req->context) |
 814			((u64)readl(&req->context_hi32)<<32));
 815
 816	if (readl(&req->result) == IOP_RESULT_SUCCESS) {
 817		arg->result = HPT_IOCTL_RESULT_OK;
 818
 819		if (arg->outbuf_size)
 820			memcpy_fromio(arg->outbuf,
 821				&p->buf[(readl(&p->inbuf_size) + 3)& ~3],
 822				arg->outbuf_size);
 823
 824		if (arg->bytes_returned)
 825			*arg->bytes_returned = arg->outbuf_size;
 826	}
 827	else
 828		arg->result = HPT_IOCTL_RESULT_FAILED;
 829
 830	arg->done(arg);
 831	writel(tag, &hba->u.itl.iop->outbound_queue);
 832}
 833
 834static irqreturn_t hptiop_intr(int irq, void *dev_id)
 835{
 836	struct hptiop_hba  *hba = dev_id;
 837	int  handled;
 838	unsigned long flags;
 839
 840	spin_lock_irqsave(hba->host->host_lock, flags);
 841	handled = hba->ops->iop_intr(hba);
 842	spin_unlock_irqrestore(hba->host->host_lock, flags);
 843
 844	return handled;
 845}
 846
 847static int hptiop_buildsgl(struct scsi_cmnd *scp, struct hpt_iopsg *psg)
 848{
 849	struct Scsi_Host *host = scp->device->host;
 850	struct hptiop_hba *hba = (struct hptiop_hba *)host->hostdata;
 851	struct scatterlist *sg;
 852	int idx, nseg;
 853
 854	nseg = scsi_dma_map(scp);
 855	BUG_ON(nseg < 0);
 856	if (!nseg)
 857		return 0;
 858
 859	HPT_SCP(scp)->sgcnt = nseg;
 860	HPT_SCP(scp)->mapped = 1;
 861
 862	BUG_ON(HPT_SCP(scp)->sgcnt > hba->max_sg_descriptors);
 863
 864	scsi_for_each_sg(scp, sg, HPT_SCP(scp)->sgcnt, idx) {
 865		psg[idx].pci_address = cpu_to_le64(sg_dma_address(sg)) |
 866			hba->ops->host_phy_flag;
 867		psg[idx].size = cpu_to_le32(sg_dma_len(sg));
 868		psg[idx].eot = (idx == HPT_SCP(scp)->sgcnt - 1) ?
 869			cpu_to_le32(1) : 0;
 870	}
 871	return HPT_SCP(scp)->sgcnt;
 872}
 873
 874static void hptiop_post_req_itl(struct hptiop_hba *hba,
 875					struct hptiop_request *_req)
 876{
 877	struct hpt_iop_request_header *reqhdr = _req->req_virt;
 878
 879	reqhdr->context = cpu_to_le32(IOPMU_QUEUE_ADDR_HOST_BIT |
 880							(u32)_req->index);
 881	reqhdr->context_hi32 = 0;
 882
 883	if (hba->iopintf_v2) {
 884		u32 size, size_bits;
 885
 886		size = le32_to_cpu(reqhdr->size);
 887		if (size < 256)
 888			size_bits = IOPMU_QUEUE_REQUEST_SIZE_BIT;
 889		else if (size < 512)
 890			size_bits = IOPMU_QUEUE_ADDR_HOST_BIT;
 891		else
 892			size_bits = IOPMU_QUEUE_REQUEST_SIZE_BIT |
 893						IOPMU_QUEUE_ADDR_HOST_BIT;
 894		writel(_req->req_shifted_phy | size_bits,
 895			&hba->u.itl.iop->inbound_queue);
 896	} else
 897		writel(_req->req_shifted_phy | IOPMU_QUEUE_ADDR_HOST_BIT,
 898					&hba->u.itl.iop->inbound_queue);
 899}
 900
 901static void hptiop_post_req_mv(struct hptiop_hba *hba,
 902					struct hptiop_request *_req)
 903{
 904	struct hpt_iop_request_header *reqhdr = _req->req_virt;
 905	u32 size, size_bit;
 906
 907	reqhdr->context = cpu_to_le32(_req->index<<8 |
 908					IOP_REQUEST_TYPE_SCSI_COMMAND<<5);
 909	reqhdr->context_hi32 = 0;
 910	size = le32_to_cpu(reqhdr->size);
 911
 912	if (size <= 256)
 913		size_bit = 0;
 914	else if (size <= 256*2)
 915		size_bit = 1;
 916	else if (size <= 256*3)
 917		size_bit = 2;
 918	else
 919		size_bit = 3;
 920
 921	mv_inbound_write((_req->req_shifted_phy << 5) |
 922		MVIOP_MU_QUEUE_ADDR_HOST_BIT | size_bit, hba);
 923}
 924
 925static void hptiop_post_req_mvfrey(struct hptiop_hba *hba,
 926					struct hptiop_request *_req)
 927{
 928	struct hpt_iop_request_header *reqhdr = _req->req_virt;
 929	u32 index;
 930
 931	reqhdr->flags |= cpu_to_le32(IOP_REQUEST_FLAG_OUTPUT_CONTEXT |
 932			IOP_REQUEST_FLAG_ADDR_BITS |
 933			((_req->req_shifted_phy >> 11) & 0xffff0000));
 934	reqhdr->context = cpu_to_le32(IOPMU_QUEUE_ADDR_HOST_BIT |
 935			(_req->index << 4) | reqhdr->type);
 936	reqhdr->context_hi32 = cpu_to_le32((_req->req_shifted_phy << 5) &
 937			0xffffffff);
 938
 939	hba->u.mvfrey.inlist_wptr++;
 940	index = hba->u.mvfrey.inlist_wptr & 0x3fff;
 941
 942	if (index == hba->u.mvfrey.list_count) {
 943		index = 0;
 944		hba->u.mvfrey.inlist_wptr &= ~0x3fff;
 945		hba->u.mvfrey.inlist_wptr ^= CL_POINTER_TOGGLE;
 946	}
 947
 948	hba->u.mvfrey.inlist[index].addr =
 949			(dma_addr_t)_req->req_shifted_phy << 5;
 950	hba->u.mvfrey.inlist[index].intrfc_len = (reqhdr->size + 3) / 4;
 951	writel(hba->u.mvfrey.inlist_wptr,
 952		&(hba->u.mvfrey.mu->inbound_write_ptr));
 953	readl(&(hba->u.mvfrey.mu->inbound_write_ptr));
 954}
 955
 956static int hptiop_reset_comm_itl(struct hptiop_hba *hba)
 957{
 958	return 0;
 959}
 960
 961static int hptiop_reset_comm_mv(struct hptiop_hba *hba)
 962{
 963	return 0;
 964}
 965
 966static int hptiop_reset_comm_mvfrey(struct hptiop_hba *hba)
 967{
 968	u32 list_count = hba->u.mvfrey.list_count;
 969
 970	if (iop_send_sync_msg(hba, IOPMU_INBOUND_MSG0_RESET_COMM, 3000))
 971		return -1;
 972
 973	/* wait 100ms for MCU ready */
 974	msleep(100);
 975
 976	writel(cpu_to_le32(hba->u.mvfrey.inlist_phy & 0xffffffff),
 977			&(hba->u.mvfrey.mu->inbound_base));
 978	writel(cpu_to_le32((hba->u.mvfrey.inlist_phy >> 16) >> 16),
 979			&(hba->u.mvfrey.mu->inbound_base_high));
 980
 981	writel(cpu_to_le32(hba->u.mvfrey.outlist_phy & 0xffffffff),
 982			&(hba->u.mvfrey.mu->outbound_base));
 983	writel(cpu_to_le32((hba->u.mvfrey.outlist_phy >> 16) >> 16),
 984			&(hba->u.mvfrey.mu->outbound_base_high));
 985
 986	writel(cpu_to_le32(hba->u.mvfrey.outlist_cptr_phy & 0xffffffff),
 987			&(hba->u.mvfrey.mu->outbound_shadow_base));
 988	writel(cpu_to_le32((hba->u.mvfrey.outlist_cptr_phy >> 16) >> 16),
 989			&(hba->u.mvfrey.mu->outbound_shadow_base_high));
 990
 991	hba->u.mvfrey.inlist_wptr = (list_count - 1) | CL_POINTER_TOGGLE;
 992	*hba->u.mvfrey.outlist_cptr = (list_count - 1) | CL_POINTER_TOGGLE;
 993	hba->u.mvfrey.outlist_rptr = list_count - 1;
 994	return 0;
 995}
 996
 997static int hptiop_queuecommand_lck(struct scsi_cmnd *scp,
 998				void (*done)(struct scsi_cmnd *))
 999{
1000	struct Scsi_Host *host = scp->device->host;
1001	struct hptiop_hba *hba = (struct hptiop_hba *)host->hostdata;
1002	struct hpt_iop_request_scsi_command *req;
1003	int sg_count = 0;
1004	struct hptiop_request *_req;
1005
1006	BUG_ON(!done);
1007	scp->scsi_done = done;
1008
1009	_req = get_req(hba);
1010	if (_req == NULL) {
1011		dprintk("hptiop_queuecmd : no free req\n");
1012		return SCSI_MLQUEUE_HOST_BUSY;
1013	}
1014
1015	_req->scp = scp;
1016
1017	dprintk("hptiop_queuecmd(scp=%p) %d/%d/%d/%llu cdb=(%08x-%08x-%08x-%08x) "
1018			"req_index=%d, req=%p\n",
1019			scp,
1020			host->host_no, scp->device->channel,
1021			scp->device->id, scp->device->lun,
1022			cpu_to_be32(((u32 *)scp->cmnd)[0]),
1023			cpu_to_be32(((u32 *)scp->cmnd)[1]),
1024			cpu_to_be32(((u32 *)scp->cmnd)[2]),
1025			cpu_to_be32(((u32 *)scp->cmnd)[3]),
1026			_req->index, _req->req_virt);
1027
1028	scp->result = 0;
1029
1030	if (scp->device->channel ||
1031			(scp->device->id > hba->max_devices) ||
1032			((scp->device->id == (hba->max_devices-1)) && scp->device->lun)) {
1033		scp->result = DID_BAD_TARGET << 16;
1034		free_req(hba, _req);
1035		goto cmd_done;
1036	}
1037
1038	req = _req->req_virt;
1039
1040	/* build S/G table */
1041	sg_count = hptiop_buildsgl(scp, req->sg_list);
1042	if (!sg_count)
1043		HPT_SCP(scp)->mapped = 0;
1044
1045	req->header.flags = cpu_to_le32(IOP_REQUEST_FLAG_OUTPUT_CONTEXT);
1046	req->header.type = cpu_to_le32(IOP_REQUEST_TYPE_SCSI_COMMAND);
1047	req->header.result = cpu_to_le32(IOP_RESULT_PENDING);
1048	req->dataxfer_length = cpu_to_le32(scsi_bufflen(scp));
1049	req->channel = scp->device->channel;
1050	req->target = scp->device->id;
1051	req->lun = scp->device->lun;
1052	req->header.size = cpu_to_le32(
1053				sizeof(struct hpt_iop_request_scsi_command)
1054				 - sizeof(struct hpt_iopsg)
1055				 + sg_count * sizeof(struct hpt_iopsg));
1056
1057	memcpy(req->cdb, scp->cmnd, sizeof(req->cdb));
1058	hba->ops->post_req(hba, _req);
1059	return 0;
1060
1061cmd_done:
1062	dprintk("scsi_done(scp=%p)\n", scp);
1063	scp->scsi_done(scp);
1064	return 0;
1065}
1066
1067static DEF_SCSI_QCMD(hptiop_queuecommand)
1068
1069static const char *hptiop_info(struct Scsi_Host *host)
1070{
1071	return driver_name_long;
1072}
1073
1074static int hptiop_reset_hba(struct hptiop_hba *hba)
1075{
1076	if (atomic_xchg(&hba->resetting, 1) == 0) {
1077		atomic_inc(&hba->reset_count);
1078		hba->ops->post_msg(hba, IOPMU_INBOUND_MSG0_RESET);
1079	}
1080
1081	wait_event_timeout(hba->reset_wq,
1082			atomic_read(&hba->resetting) == 0, 60 * HZ);
1083
1084	if (atomic_read(&hba->resetting)) {
1085		/* IOP is in unknown state, abort reset */
1086		printk(KERN_ERR "scsi%d: reset failed\n", hba->host->host_no);
1087		return -1;
1088	}
1089
1090	if (iop_send_sync_msg(hba,
1091		IOPMU_INBOUND_MSG0_START_BACKGROUND_TASK, 5000)) {
1092		dprintk("scsi%d: fail to start background task\n",
1093				hba->host->host_no);
1094	}
1095
1096	return 0;
1097}
1098
1099static int hptiop_reset(struct scsi_cmnd *scp)
1100{
1101	struct hptiop_hba * hba = (struct hptiop_hba *)scp->device->host->hostdata;
 
1102
1103	printk(KERN_WARNING "hptiop_reset(%d/%d/%d)\n",
1104	       scp->device->host->host_no, -1, -1);
 
1105
1106	return hptiop_reset_hba(hba)? FAILED : SUCCESS;
1107}
1108
1109static int hptiop_adjust_disk_queue_depth(struct scsi_device *sdev,
1110					  int queue_depth)
1111{
1112	struct hptiop_hba *hba = (struct hptiop_hba *)sdev->host->hostdata;
1113
 
 
 
1114	if (queue_depth > hba->max_requests)
1115		queue_depth = hba->max_requests;
1116	return scsi_change_queue_depth(sdev, queue_depth);
 
1117}
1118
1119static ssize_t hptiop_show_version(struct device *dev,
1120				   struct device_attribute *attr, char *buf)
1121{
1122	return snprintf(buf, PAGE_SIZE, "%s\n", driver_ver);
1123}
1124
1125static ssize_t hptiop_show_fw_version(struct device *dev,
1126				      struct device_attribute *attr, char *buf)
1127{
1128	struct Scsi_Host *host = class_to_shost(dev);
1129	struct hptiop_hba *hba = (struct hptiop_hba *)host->hostdata;
1130
1131	return snprintf(buf, PAGE_SIZE, "%d.%d.%d.%d\n",
1132				hba->firmware_version >> 24,
1133				(hba->firmware_version >> 16) & 0xff,
1134				(hba->firmware_version >> 8) & 0xff,
1135				hba->firmware_version & 0xff);
1136}
1137
1138static struct device_attribute hptiop_attr_version = {
1139	.attr = {
1140		.name = "driver-version",
1141		.mode = S_IRUGO,
1142	},
1143	.show = hptiop_show_version,
1144};
1145
1146static struct device_attribute hptiop_attr_fw_version = {
1147	.attr = {
1148		.name = "firmware-version",
1149		.mode = S_IRUGO,
1150	},
1151	.show = hptiop_show_fw_version,
1152};
1153
1154static struct device_attribute *hptiop_attrs[] = {
1155	&hptiop_attr_version,
1156	&hptiop_attr_fw_version,
1157	NULL
1158};
1159
1160static int hptiop_slave_config(struct scsi_device *sdev)
1161{
1162	if (sdev->type == TYPE_TAPE)
1163		blk_queue_max_hw_sectors(sdev->request_queue, 8192);
1164
1165	return 0;
1166}
1167
1168static struct scsi_host_template driver_template = {
1169	.module                     = THIS_MODULE,
1170	.name                       = driver_name,
1171	.queuecommand               = hptiop_queuecommand,
1172	.eh_host_reset_handler      = hptiop_reset,
 
1173	.info                       = hptiop_info,
1174	.emulated                   = 0,
 
1175	.proc_name                  = driver_name,
1176	.shost_attrs                = hptiop_attrs,
1177	.slave_configure            = hptiop_slave_config,
1178	.this_id                    = -1,
1179	.change_queue_depth         = hptiop_adjust_disk_queue_depth,
1180};
1181
1182static int hptiop_internal_memalloc_itl(struct hptiop_hba *hba)
1183{
1184	return 0;
1185}
1186
1187static int hptiop_internal_memalloc_mv(struct hptiop_hba *hba)
1188{
1189	hba->u.mv.internal_req = dma_alloc_coherent(&hba->pcidev->dev,
1190			0x800, &hba->u.mv.internal_req_phy, GFP_KERNEL);
1191	if (hba->u.mv.internal_req)
1192		return 0;
1193	else
1194		return -1;
1195}
1196
1197static int hptiop_internal_memalloc_mvfrey(struct hptiop_hba *hba)
1198{
1199	u32 list_count = readl(&hba->u.mvfrey.mu->inbound_conf_ctl);
1200	char *p;
1201	dma_addr_t phy;
1202
1203	BUG_ON(hba->max_request_size == 0);
1204
1205	if (list_count == 0) {
1206		BUG_ON(1);
1207		return -1;
1208	}
1209
1210	list_count >>= 16;
1211
1212	hba->u.mvfrey.list_count = list_count;
1213	hba->u.mvfrey.internal_mem_size = 0x800 +
1214			list_count * sizeof(struct mvfrey_inlist_entry) +
1215			list_count * sizeof(struct mvfrey_outlist_entry) +
1216			sizeof(int);
1217
1218	p = dma_alloc_coherent(&hba->pcidev->dev,
1219			hba->u.mvfrey.internal_mem_size, &phy, GFP_KERNEL);
1220	if (!p)
1221		return -1;
1222
1223	hba->u.mvfrey.internal_req.req_virt = p;
1224	hba->u.mvfrey.internal_req.req_shifted_phy = phy >> 5;
1225	hba->u.mvfrey.internal_req.scp = NULL;
1226	hba->u.mvfrey.internal_req.next = NULL;
1227
1228	p += 0x800;
1229	phy += 0x800;
1230
1231	hba->u.mvfrey.inlist = (struct mvfrey_inlist_entry *)p;
1232	hba->u.mvfrey.inlist_phy = phy;
1233
1234	p += list_count * sizeof(struct mvfrey_inlist_entry);
1235	phy += list_count * sizeof(struct mvfrey_inlist_entry);
1236
1237	hba->u.mvfrey.outlist = (struct mvfrey_outlist_entry *)p;
1238	hba->u.mvfrey.outlist_phy = phy;
1239
1240	p += list_count * sizeof(struct mvfrey_outlist_entry);
1241	phy += list_count * sizeof(struct mvfrey_outlist_entry);
1242
1243	hba->u.mvfrey.outlist_cptr = (__le32 *)p;
1244	hba->u.mvfrey.outlist_cptr_phy = phy;
1245
1246	return 0;
1247}
1248
1249static int hptiop_internal_memfree_itl(struct hptiop_hba *hba)
1250{
1251	return 0;
1252}
1253
1254static int hptiop_internal_memfree_mv(struct hptiop_hba *hba)
1255{
1256	if (hba->u.mv.internal_req) {
1257		dma_free_coherent(&hba->pcidev->dev, 0x800,
1258			hba->u.mv.internal_req, hba->u.mv.internal_req_phy);
1259		return 0;
1260	} else
1261		return -1;
1262}
1263
1264static int hptiop_internal_memfree_mvfrey(struct hptiop_hba *hba)
1265{
1266	if (hba->u.mvfrey.internal_req.req_virt) {
1267		dma_free_coherent(&hba->pcidev->dev,
1268			hba->u.mvfrey.internal_mem_size,
1269			hba->u.mvfrey.internal_req.req_virt,
1270			(dma_addr_t)
1271			hba->u.mvfrey.internal_req.req_shifted_phy << 5);
1272		return 0;
1273	} else
1274		return -1;
1275}
1276
1277static int hptiop_probe(struct pci_dev *pcidev, const struct pci_device_id *id)
1278{
1279	struct Scsi_Host *host = NULL;
1280	struct hptiop_hba *hba;
1281	struct hptiop_adapter_ops *iop_ops;
1282	struct hpt_iop_request_get_config iop_config;
1283	struct hpt_iop_request_set_config set_config;
1284	dma_addr_t start_phy;
1285	void *start_virt;
1286	u32 offset, i, req_size;
1287	int rc;
1288
1289	dprintk("hptiop_probe(%p)\n", pcidev);
1290
1291	if (pci_enable_device(pcidev)) {
1292		printk(KERN_ERR "hptiop: fail to enable pci device\n");
1293		return -ENODEV;
1294	}
1295
1296	printk(KERN_INFO "adapter at PCI %d:%d:%d, IRQ %d\n",
1297		pcidev->bus->number, pcidev->devfn >> 3, pcidev->devfn & 7,
1298		pcidev->irq);
1299
1300	pci_set_master(pcidev);
1301
1302	/* Enable 64bit DMA if possible */
1303	iop_ops = (struct hptiop_adapter_ops *)id->driver_data;
1304	rc = dma_set_mask(&pcidev->dev,
1305			  DMA_BIT_MASK(iop_ops->hw_dma_bit_mask));
1306	if (rc)
1307		rc = dma_set_mask(&pcidev->dev, DMA_BIT_MASK(32));
1308
1309	if (rc) {
1310		printk(KERN_ERR "hptiop: fail to set dma_mask\n");
1311		goto disable_pci_device;
1312	}
1313
1314	if (pci_request_regions(pcidev, driver_name)) {
1315		printk(KERN_ERR "hptiop: pci_request_regions failed\n");
1316		goto disable_pci_device;
1317	}
1318
1319	host = scsi_host_alloc(&driver_template, sizeof(struct hptiop_hba));
1320	if (!host) {
1321		printk(KERN_ERR "hptiop: fail to alloc scsi host\n");
1322		goto free_pci_regions;
1323	}
1324
1325	hba = (struct hptiop_hba *)host->hostdata;
1326	memset(hba, 0, sizeof(struct hptiop_hba));
1327
1328	hba->ops = iop_ops;
1329	hba->pcidev = pcidev;
1330	hba->host = host;
1331	hba->initialized = 0;
1332	hba->iopintf_v2 = 0;
1333
1334	atomic_set(&hba->resetting, 0);
1335	atomic_set(&hba->reset_count, 0);
1336
1337	init_waitqueue_head(&hba->reset_wq);
1338	init_waitqueue_head(&hba->ioctl_wq);
1339
1340	host->max_lun = 128;
1341	host->max_channel = 0;
1342	host->io_port = 0;
1343	host->n_io_port = 0;
1344	host->irq = pcidev->irq;
1345
1346	if (hba->ops->map_pci_bar(hba))
1347		goto free_scsi_host;
1348
1349	if (hba->ops->iop_wait_ready(hba, 20000)) {
1350		printk(KERN_ERR "scsi%d: firmware not ready\n",
1351				hba->host->host_no);
1352		goto unmap_pci_bar;
1353	}
1354
1355	if (hba->ops->family == MV_BASED_IOP) {
1356		if (hba->ops->internal_memalloc(hba)) {
1357			printk(KERN_ERR "scsi%d: internal_memalloc failed\n",
1358				hba->host->host_no);
1359			goto unmap_pci_bar;
1360		}
1361	}
1362
1363	if (hba->ops->get_config(hba, &iop_config)) {
1364		printk(KERN_ERR "scsi%d: get config failed\n",
1365				hba->host->host_no);
1366		goto unmap_pci_bar;
1367	}
1368
1369	hba->max_requests = min(le32_to_cpu(iop_config.max_requests),
1370				HPTIOP_MAX_REQUESTS);
1371	hba->max_devices = le32_to_cpu(iop_config.max_devices);
1372	hba->max_request_size = le32_to_cpu(iop_config.request_size);
1373	hba->max_sg_descriptors = le32_to_cpu(iop_config.max_sg_count);
1374	hba->firmware_version = le32_to_cpu(iop_config.firmware_version);
1375	hba->interface_version = le32_to_cpu(iop_config.interface_version);
1376	hba->sdram_size = le32_to_cpu(iop_config.sdram_size);
1377
1378	if (hba->ops->family == MVFREY_BASED_IOP) {
1379		if (hba->ops->internal_memalloc(hba)) {
1380			printk(KERN_ERR "scsi%d: internal_memalloc failed\n",
1381				hba->host->host_no);
1382			goto unmap_pci_bar;
1383		}
1384		if (hba->ops->reset_comm(hba)) {
1385			printk(KERN_ERR "scsi%d: reset comm failed\n",
1386					hba->host->host_no);
1387			goto unmap_pci_bar;
1388		}
1389	}
1390
1391	if (hba->firmware_version > 0x01020000 ||
1392			hba->interface_version > 0x01020000)
1393		hba->iopintf_v2 = 1;
1394
1395	host->max_sectors = le32_to_cpu(iop_config.data_transfer_length) >> 9;
1396	host->max_id = le32_to_cpu(iop_config.max_devices);
1397	host->sg_tablesize = le32_to_cpu(iop_config.max_sg_count);
1398	host->can_queue = le32_to_cpu(iop_config.max_requests);
1399	host->cmd_per_lun = le32_to_cpu(iop_config.max_requests);
1400	host->max_cmd_len = 16;
1401
1402	req_size = sizeof(struct hpt_iop_request_scsi_command)
1403		+ sizeof(struct hpt_iopsg) * (hba->max_sg_descriptors - 1);
1404	if ((req_size & 0x1f) != 0)
1405		req_size = (req_size + 0x1f) & ~0x1f;
1406
1407	memset(&set_config, 0, sizeof(struct hpt_iop_request_set_config));
1408	set_config.iop_id = cpu_to_le32(host->host_no);
1409	set_config.vbus_id = cpu_to_le16(host->host_no);
1410	set_config.max_host_request_size = cpu_to_le16(req_size);
1411
1412	if (hba->ops->set_config(hba, &set_config)) {
1413		printk(KERN_ERR "scsi%d: set config failed\n",
1414				hba->host->host_no);
1415		goto unmap_pci_bar;
1416	}
1417
1418	pci_set_drvdata(pcidev, host);
1419
1420	if (request_irq(pcidev->irq, hptiop_intr, IRQF_SHARED,
1421					driver_name, hba)) {
1422		printk(KERN_ERR "scsi%d: request irq %d failed\n",
1423					hba->host->host_no, pcidev->irq);
1424		goto unmap_pci_bar;
1425	}
1426
1427	/* Allocate request mem */
1428
1429	dprintk("req_size=%d, max_requests=%d\n", req_size, hba->max_requests);
1430
1431	hba->req_size = req_size;
1432	hba->req_list = NULL;
 
 
1433
1434	for (i = 0; i < hba->max_requests; i++) {
1435		start_virt = dma_alloc_coherent(&pcidev->dev,
1436					hba->req_size + 0x20,
1437					&start_phy, GFP_KERNEL);
1438
1439		if (!start_virt) {
1440			printk(KERN_ERR "scsi%d: fail to alloc request mem\n",
1441						hba->host->host_no);
1442			goto free_request_mem;
1443		}
1444
1445		hba->dma_coherent[i] = start_virt;
1446		hba->dma_coherent_handle[i] = start_phy;
1447
1448		if ((start_phy & 0x1f) != 0) {
1449			offset = ((start_phy + 0x1f) & ~0x1f) - start_phy;
1450			start_phy += offset;
1451			start_virt += offset;
1452		}
 
1453
 
 
1454		hba->reqs[i].next = NULL;
1455		hba->reqs[i].req_virt = start_virt;
1456		hba->reqs[i].req_shifted_phy = start_phy >> 5;
1457		hba->reqs[i].index = i;
1458		free_req(hba, &hba->reqs[i]);
 
 
1459	}
1460
1461	/* Enable Interrupt and start background task */
1462	if (hptiop_initialize_iop(hba))
1463		goto free_request_mem;
1464
1465	if (scsi_add_host(host, &pcidev->dev)) {
1466		printk(KERN_ERR "scsi%d: scsi_add_host failed\n",
1467					hba->host->host_no);
1468		goto free_request_mem;
1469	}
1470
 
1471	scsi_scan_host(host);
1472
1473	dprintk("scsi%d: hptiop_probe successfully\n", hba->host->host_no);
1474	return 0;
1475
1476free_request_mem:
1477	for (i = 0; i < hba->max_requests; i++) {
1478		if (hba->dma_coherent[i] && hba->dma_coherent_handle[i])
1479			dma_free_coherent(&hba->pcidev->dev,
1480					hba->req_size + 0x20,
1481					hba->dma_coherent[i],
1482					hba->dma_coherent_handle[i]);
1483		else
1484			break;
1485	}
1486
 
1487	free_irq(hba->pcidev->irq, hba);
1488
1489unmap_pci_bar:
1490	hba->ops->internal_memfree(hba);
 
1491
1492	hba->ops->unmap_pci_bar(hba);
1493
1494free_scsi_host:
1495	scsi_host_put(host);
1496
1497free_pci_regions:
1498	pci_release_regions(pcidev);
1499
1500disable_pci_device:
1501	pci_disable_device(pcidev);
1502
1503	dprintk("scsi%d: hptiop_probe fail\n", host ? host->host_no : 0);
1504	return -ENODEV;
1505}
1506
1507static void hptiop_shutdown(struct pci_dev *pcidev)
1508{
1509	struct Scsi_Host *host = pci_get_drvdata(pcidev);
1510	struct hptiop_hba *hba = (struct hptiop_hba *)host->hostdata;
1511
1512	dprintk("hptiop_shutdown(%p)\n", hba);
1513
1514	/* stop the iop */
1515	if (iop_send_sync_msg(hba, IOPMU_INBOUND_MSG0_SHUTDOWN, 60000))
1516		printk(KERN_ERR "scsi%d: shutdown the iop timeout\n",
1517					hba->host->host_no);
1518
1519	/* disable all outbound interrupts */
1520	hba->ops->disable_intr(hba);
1521}
1522
1523static void hptiop_disable_intr_itl(struct hptiop_hba *hba)
1524{
1525	u32 int_mask;
1526
1527	int_mask = readl(&hba->u.itl.iop->outbound_intmask);
1528	writel(int_mask |
1529		IOPMU_OUTBOUND_INT_MSG0 | IOPMU_OUTBOUND_INT_POSTQUEUE,
1530		&hba->u.itl.iop->outbound_intmask);
1531	readl(&hba->u.itl.iop->outbound_intmask);
1532}
1533
1534static void hptiop_disable_intr_mv(struct hptiop_hba *hba)
1535{
1536	writel(0, &hba->u.mv.regs->outbound_intmask);
1537	readl(&hba->u.mv.regs->outbound_intmask);
1538}
1539
1540static void hptiop_disable_intr_mvfrey(struct hptiop_hba *hba)
1541{
1542	writel(0, &(hba->u.mvfrey.mu->f0_doorbell_enable));
1543	readl(&(hba->u.mvfrey.mu->f0_doorbell_enable));
1544	writel(0, &(hba->u.mvfrey.mu->isr_enable));
1545	readl(&(hba->u.mvfrey.mu->isr_enable));
1546	writel(0, &(hba->u.mvfrey.mu->pcie_f0_int_enable));
1547	readl(&(hba->u.mvfrey.mu->pcie_f0_int_enable));
1548}
1549
1550static void hptiop_remove(struct pci_dev *pcidev)
1551{
1552	struct Scsi_Host *host = pci_get_drvdata(pcidev);
1553	struct hptiop_hba *hba = (struct hptiop_hba *)host->hostdata;
1554	u32 i;
1555
1556	dprintk("scsi%d: hptiop_remove\n", hba->host->host_no);
1557
1558	scsi_remove_host(host);
1559
1560	hptiop_shutdown(pcidev);
1561
1562	free_irq(hba->pcidev->irq, hba);
1563
1564	for (i = 0; i < hba->max_requests; i++) {
1565		if (hba->dma_coherent[i] && hba->dma_coherent_handle[i])
1566			dma_free_coherent(&hba->pcidev->dev,
1567					hba->req_size + 0x20,
1568					hba->dma_coherent[i],
1569					hba->dma_coherent_handle[i]);
1570		else
1571			break;
1572	}
1573
1574	hba->ops->internal_memfree(hba);
 
1575
1576	hba->ops->unmap_pci_bar(hba);
1577
1578	pci_release_regions(hba->pcidev);
1579	pci_set_drvdata(hba->pcidev, NULL);
1580	pci_disable_device(hba->pcidev);
1581
1582	scsi_host_put(host);
1583}
1584
1585static struct hptiop_adapter_ops hptiop_itl_ops = {
1586	.family            = INTEL_BASED_IOP,
1587	.iop_wait_ready    = iop_wait_ready_itl,
1588	.internal_memalloc = hptiop_internal_memalloc_itl,
1589	.internal_memfree  = hptiop_internal_memfree_itl,
1590	.map_pci_bar       = hptiop_map_pci_bar_itl,
1591	.unmap_pci_bar     = hptiop_unmap_pci_bar_itl,
1592	.enable_intr       = hptiop_enable_intr_itl,
1593	.disable_intr      = hptiop_disable_intr_itl,
1594	.get_config        = iop_get_config_itl,
1595	.set_config        = iop_set_config_itl,
1596	.iop_intr          = iop_intr_itl,
1597	.post_msg          = hptiop_post_msg_itl,
1598	.post_req          = hptiop_post_req_itl,
1599	.hw_dma_bit_mask   = 64,
1600	.reset_comm        = hptiop_reset_comm_itl,
1601	.host_phy_flag     = cpu_to_le64(0),
1602};
1603
1604static struct hptiop_adapter_ops hptiop_mv_ops = {
1605	.family            = MV_BASED_IOP,
1606	.iop_wait_ready    = iop_wait_ready_mv,
1607	.internal_memalloc = hptiop_internal_memalloc_mv,
1608	.internal_memfree  = hptiop_internal_memfree_mv,
1609	.map_pci_bar       = hptiop_map_pci_bar_mv,
1610	.unmap_pci_bar     = hptiop_unmap_pci_bar_mv,
1611	.enable_intr       = hptiop_enable_intr_mv,
1612	.disable_intr      = hptiop_disable_intr_mv,
1613	.get_config        = iop_get_config_mv,
1614	.set_config        = iop_set_config_mv,
1615	.iop_intr          = iop_intr_mv,
1616	.post_msg          = hptiop_post_msg_mv,
1617	.post_req          = hptiop_post_req_mv,
1618	.hw_dma_bit_mask   = 33,
1619	.reset_comm        = hptiop_reset_comm_mv,
1620	.host_phy_flag     = cpu_to_le64(0),
1621};
1622
1623static struct hptiop_adapter_ops hptiop_mvfrey_ops = {
1624	.family            = MVFREY_BASED_IOP,
1625	.iop_wait_ready    = iop_wait_ready_mvfrey,
1626	.internal_memalloc = hptiop_internal_memalloc_mvfrey,
1627	.internal_memfree  = hptiop_internal_memfree_mvfrey,
1628	.map_pci_bar       = hptiop_map_pci_bar_mvfrey,
1629	.unmap_pci_bar     = hptiop_unmap_pci_bar_mvfrey,
1630	.enable_intr       = hptiop_enable_intr_mvfrey,
1631	.disable_intr      = hptiop_disable_intr_mvfrey,
1632	.get_config        = iop_get_config_mvfrey,
1633	.set_config        = iop_set_config_mvfrey,
1634	.iop_intr          = iop_intr_mvfrey,
1635	.post_msg          = hptiop_post_msg_mvfrey,
1636	.post_req          = hptiop_post_req_mvfrey,
1637	.hw_dma_bit_mask   = 64,
1638	.reset_comm        = hptiop_reset_comm_mvfrey,
1639	.host_phy_flag     = cpu_to_le64(1),
1640};
1641
1642static struct pci_device_id hptiop_id_table[] = {
1643	{ PCI_VDEVICE(TTI, 0x3220), (kernel_ulong_t)&hptiop_itl_ops },
1644	{ PCI_VDEVICE(TTI, 0x3320), (kernel_ulong_t)&hptiop_itl_ops },
1645	{ PCI_VDEVICE(TTI, 0x3410), (kernel_ulong_t)&hptiop_itl_ops },
1646	{ PCI_VDEVICE(TTI, 0x3510), (kernel_ulong_t)&hptiop_itl_ops },
1647	{ PCI_VDEVICE(TTI, 0x3511), (kernel_ulong_t)&hptiop_itl_ops },
1648	{ PCI_VDEVICE(TTI, 0x3520), (kernel_ulong_t)&hptiop_itl_ops },
1649	{ PCI_VDEVICE(TTI, 0x3521), (kernel_ulong_t)&hptiop_itl_ops },
1650	{ PCI_VDEVICE(TTI, 0x3522), (kernel_ulong_t)&hptiop_itl_ops },
1651	{ PCI_VDEVICE(TTI, 0x3530), (kernel_ulong_t)&hptiop_itl_ops },
1652	{ PCI_VDEVICE(TTI, 0x3540), (kernel_ulong_t)&hptiop_itl_ops },
1653	{ PCI_VDEVICE(TTI, 0x3560), (kernel_ulong_t)&hptiop_itl_ops },
1654	{ PCI_VDEVICE(TTI, 0x4210), (kernel_ulong_t)&hptiop_itl_ops },
1655	{ PCI_VDEVICE(TTI, 0x4211), (kernel_ulong_t)&hptiop_itl_ops },
1656	{ PCI_VDEVICE(TTI, 0x4310), (kernel_ulong_t)&hptiop_itl_ops },
1657	{ PCI_VDEVICE(TTI, 0x4311), (kernel_ulong_t)&hptiop_itl_ops },
1658	{ PCI_VDEVICE(TTI, 0x4320), (kernel_ulong_t)&hptiop_itl_ops },
1659	{ PCI_VDEVICE(TTI, 0x4321), (kernel_ulong_t)&hptiop_itl_ops },
1660	{ PCI_VDEVICE(TTI, 0x4322), (kernel_ulong_t)&hptiop_itl_ops },
1661	{ PCI_VDEVICE(TTI, 0x4400), (kernel_ulong_t)&hptiop_itl_ops },
1662	{ PCI_VDEVICE(TTI, 0x3120), (kernel_ulong_t)&hptiop_mv_ops },
1663	{ PCI_VDEVICE(TTI, 0x3122), (kernel_ulong_t)&hptiop_mv_ops },
1664	{ PCI_VDEVICE(TTI, 0x3020), (kernel_ulong_t)&hptiop_mv_ops },
1665	{ PCI_VDEVICE(TTI, 0x4520), (kernel_ulong_t)&hptiop_mvfrey_ops },
1666	{ PCI_VDEVICE(TTI, 0x4522), (kernel_ulong_t)&hptiop_mvfrey_ops },
1667	{ PCI_VDEVICE(TTI, 0x3610), (kernel_ulong_t)&hptiop_mvfrey_ops },
1668	{ PCI_VDEVICE(TTI, 0x3611), (kernel_ulong_t)&hptiop_mvfrey_ops },
1669	{ PCI_VDEVICE(TTI, 0x3620), (kernel_ulong_t)&hptiop_mvfrey_ops },
1670	{ PCI_VDEVICE(TTI, 0x3622), (kernel_ulong_t)&hptiop_mvfrey_ops },
1671	{ PCI_VDEVICE(TTI, 0x3640), (kernel_ulong_t)&hptiop_mvfrey_ops },
1672	{ PCI_VDEVICE(TTI, 0x3660), (kernel_ulong_t)&hptiop_mvfrey_ops },
1673	{ PCI_VDEVICE(TTI, 0x3680), (kernel_ulong_t)&hptiop_mvfrey_ops },
1674	{ PCI_VDEVICE(TTI, 0x3690), (kernel_ulong_t)&hptiop_mvfrey_ops },
1675	{},
1676};
1677
1678MODULE_DEVICE_TABLE(pci, hptiop_id_table);
1679
1680static struct pci_driver hptiop_pci_driver = {
1681	.name       = driver_name,
1682	.id_table   = hptiop_id_table,
1683	.probe      = hptiop_probe,
1684	.remove     = hptiop_remove,
1685	.shutdown   = hptiop_shutdown,
1686};
1687
1688static int __init hptiop_module_init(void)
1689{
1690	printk(KERN_INFO "%s %s\n", driver_name_long, driver_ver);
1691	return pci_register_driver(&hptiop_pci_driver);
1692}
1693
1694static void __exit hptiop_module_exit(void)
1695{
1696	pci_unregister_driver(&hptiop_pci_driver);
1697}
1698
1699
1700module_init(hptiop_module_init);
1701module_exit(hptiop_module_exit);
1702
1703MODULE_LICENSE("GPL");
1704