2 * RapidIO mport driver for Tsi721 PCIExpress-to-SRIO bridge
4 * Copyright 2011 Integrated Device Technology, Inc.
5 * Alexandre Bounine <alexandre.bounine@idt.com>
6 * Chul Kim <chul.kim@idt.com>
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the Free
10 * Software Foundation; either version 2 of the License, or (at your option)
13 * This program is distributed in the hope that it will be useful, but WITHOUT
14 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
18 * You should have received a copy of the GNU General Public License along with
19 * this program; if not, write to the Free Software Foundation, Inc., 59
20 * Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24 #include <linux/errno.h>
25 #include <linux/init.h>
26 #include <linux/ioport.h>
27 #include <linux/kernel.h>
28 #include <linux/module.h>
29 #include <linux/pci.h>
30 #include <linux/rio.h>
31 #include <linux/rio_drv.h>
32 #include <linux/dma-mapping.h>
33 #include <linux/interrupt.h>
34 #include <linux/kfifo.h>
35 #include <linux/delay.h>
39 #define DEBUG_PW /* Inbound Port-Write debugging */
41 static void tsi721_omsg_handler(struct tsi721_device *priv, int ch);
42 static void tsi721_imsg_handler(struct tsi721_device *priv, int ch);
45 * tsi721_lcread - read from local SREP config space
46 * @mport: RapidIO master port info
47 * @index: ID of RapdiIO interface
48 * @offset: Offset into configuration space
49 * @len: Length (in bytes) of the maintenance transaction
50 * @data: Value to be read into
52 * Generates a local SREP space read. Returns %0 on
53 * success or %-EINVAL on failure.
55 static int tsi721_lcread(struct rio_mport *mport, int index, u32 offset,
58 struct tsi721_device *priv = mport->priv;
60 if (len != sizeof(u32))
61 return -EINVAL; /* only 32-bit access is supported */
63 *data = ioread32(priv->regs + offset);
69 * tsi721_lcwrite - write into local SREP config space
70 * @mport: RapidIO master port info
71 * @index: ID of RapdiIO interface
72 * @offset: Offset into configuration space
73 * @len: Length (in bytes) of the maintenance transaction
74 * @data: Value to be written
76 * Generates a local write into SREP configuration space. Returns %0 on
77 * success or %-EINVAL on failure.
79 static int tsi721_lcwrite(struct rio_mport *mport, int index, u32 offset,
82 struct tsi721_device *priv = mport->priv;
84 if (len != sizeof(u32))
85 return -EINVAL; /* only 32-bit access is supported */
87 iowrite32(data, priv->regs + offset);
93 * tsi721_maint_dma - Helper function to generate RapidIO maintenance
94 * transactions using designated Tsi721 DMA channel.
95 * @priv: pointer to tsi721 private data
96 * @sys_size: RapdiIO transport system size
97 * @destid: Destination ID of transaction
98 * @hopcount: Number of hops to target device
99 * @offset: Offset into configuration space
100 * @len: Length (in bytes) of the maintenance transaction
101 * @data: Location to be read from or write into
102 * @do_wr: Operation flag (1 == MAINT_WR)
104 * Generates a RapidIO maintenance transaction (Read or Write).
105 * Returns %0 on success and %-EINVAL or %-EFAULT on failure.
107 static int tsi721_maint_dma(struct tsi721_device *priv, u32 sys_size,
108 u16 destid, u8 hopcount, u32 offset, int len,
109 u32 *data, int do_wr)
111 void __iomem *regs = priv->regs + TSI721_DMAC_BASE(priv->mdma.ch_id);
112 struct tsi721_dma_desc *bd_ptr;
113 u32 rd_count, swr_ptr, ch_stat;
115 u32 op = do_wr ? MAINT_WR : MAINT_RD;
117 if (offset > (RIO_MAINT_SPACE_SZ - len) || (len != sizeof(u32)))
120 bd_ptr = priv->mdma.bd_base;
122 rd_count = ioread32(regs + TSI721_DMAC_DRDCNT);
124 /* Initialize DMA descriptor */
125 bd_ptr[0].type_id = cpu_to_le32((DTYPE2 << 29) | (op << 19) | destid);
126 bd_ptr[0].bcount = cpu_to_le32((sys_size << 26) | 0x04);
127 bd_ptr[0].raddr_lo = cpu_to_le32((hopcount << 24) | offset);
128 bd_ptr[0].raddr_hi = 0;
130 bd_ptr[0].data[0] = cpu_to_be32p(data);
132 bd_ptr[0].data[0] = 0xffffffff;
136 /* Start DMA operation */
137 iowrite32(rd_count + 2, regs + TSI721_DMAC_DWRCNT);
138 ioread32(regs + TSI721_DMAC_DWRCNT);
141 /* Wait until DMA transfer is finished */
142 while ((ch_stat = ioread32(regs + TSI721_DMAC_STS))
143 & TSI721_DMAC_STS_RUN) {
145 if (++i >= 5000000) {
146 dev_dbg(&priv->pdev->dev,
147 "%s : DMA[%d] read timeout ch_status=%x\n",
148 __func__, priv->mdma.ch_id, ch_stat);
156 if (ch_stat & TSI721_DMAC_STS_ABORT) {
157 /* If DMA operation aborted due to error,
158 * reinitialize DMA channel
160 dev_dbg(&priv->pdev->dev, "%s : DMA ABORT ch_stat=%x\n",
162 dev_dbg(&priv->pdev->dev, "OP=%d : destid=%x hc=%x off=%x\n",
163 do_wr ? MAINT_WR : MAINT_RD, destid, hopcount, offset);
164 iowrite32(TSI721_DMAC_INT_ALL, regs + TSI721_DMAC_INT);
165 iowrite32(TSI721_DMAC_CTL_INIT, regs + TSI721_DMAC_CTL);
167 iowrite32(0, regs + TSI721_DMAC_DWRCNT);
176 *data = be32_to_cpu(bd_ptr[0].data[0]);
179 * Update descriptor status FIFO RD pointer.
180 * NOTE: Skipping check and clear FIFO entries because we are waiting
181 * for transfer to be completed.
183 swr_ptr = ioread32(regs + TSI721_DMAC_DSWP);
184 iowrite32(swr_ptr, regs + TSI721_DMAC_DSRP);
191 * tsi721_cread_dma - Generate a RapidIO maintenance read transaction
192 * using Tsi721 BDMA engine.
193 * @mport: RapidIO master port control structure
194 * @index: ID of RapdiIO interface
195 * @destid: Destination ID of transaction
196 * @hopcount: Number of hops to target device
197 * @offset: Offset into configuration space
198 * @len: Length (in bytes) of the maintenance transaction
199 * @val: Location to be read into
201 * Generates a RapidIO maintenance read transaction.
202 * Returns %0 on success and %-EINVAL or %-EFAULT on failure.
204 static int tsi721_cread_dma(struct rio_mport *mport, int index, u16 destid,
205 u8 hopcount, u32 offset, int len, u32 *data)
207 struct tsi721_device *priv = mport->priv;
209 return tsi721_maint_dma(priv, mport->sys_size, destid, hopcount,
210 offset, len, data, 0);
214 * tsi721_cwrite_dma - Generate a RapidIO maintenance write transaction
215 * using Tsi721 BDMA engine
216 * @mport: RapidIO master port control structure
217 * @index: ID of RapdiIO interface
218 * @destid: Destination ID of transaction
219 * @hopcount: Number of hops to target device
220 * @offset: Offset into configuration space
221 * @len: Length (in bytes) of the maintenance transaction
222 * @val: Value to be written
224 * Generates a RapidIO maintenance write transaction.
225 * Returns %0 on success and %-EINVAL or %-EFAULT on failure.
227 static int tsi721_cwrite_dma(struct rio_mport *mport, int index, u16 destid,
228 u8 hopcount, u32 offset, int len, u32 data)
230 struct tsi721_device *priv = mport->priv;
233 return tsi721_maint_dma(priv, mport->sys_size, destid, hopcount,
234 offset, len, &temp, 1);
238 * tsi721_pw_handler - Tsi721 inbound port-write interrupt handler
239 * @priv: tsi721 device private structure
241 * Handles inbound port-write interrupts. Copies PW message from an internal
242 * buffer into PW message FIFO and schedules deferred routine to process
246 tsi721_pw_handler(struct tsi721_device *priv)
249 u32 pw_buf[TSI721_RIO_PW_MSG_SIZE/sizeof(u32)];
252 pw_stat = ioread32(priv->regs + TSI721_RIO_PW_RX_STAT);
254 if (pw_stat & TSI721_RIO_PW_RX_STAT_PW_VAL) {
255 pw_buf[0] = ioread32(priv->regs + TSI721_RIO_PW_RX_CAPT(0));
256 pw_buf[1] = ioread32(priv->regs + TSI721_RIO_PW_RX_CAPT(1));
257 pw_buf[2] = ioread32(priv->regs + TSI721_RIO_PW_RX_CAPT(2));
258 pw_buf[3] = ioread32(priv->regs + TSI721_RIO_PW_RX_CAPT(3));
260 /* Queue PW message (if there is room in FIFO),
261 * otherwise discard it.
263 spin_lock(&priv->pw_fifo_lock);
264 if (kfifo_avail(&priv->pw_fifo) >= TSI721_RIO_PW_MSG_SIZE)
265 kfifo_in(&priv->pw_fifo, pw_buf,
266 TSI721_RIO_PW_MSG_SIZE);
268 priv->pw_discard_count++;
269 spin_unlock(&priv->pw_fifo_lock);
272 /* Clear pending PW interrupts */
273 iowrite32(TSI721_RIO_PW_RX_STAT_PW_DISC | TSI721_RIO_PW_RX_STAT_PW_VAL,
274 priv->regs + TSI721_RIO_PW_RX_STAT);
276 schedule_work(&priv->pw_work);
281 static void tsi721_pw_dpc(struct work_struct *work)
283 struct tsi721_device *priv = container_of(work, struct tsi721_device,
285 u32 msg_buffer[RIO_PW_MSG_SIZE/sizeof(u32)]; /* Use full size PW message
286 buffer for RIO layer */
289 * Process port-write messages
291 while (kfifo_out_spinlocked(&priv->pw_fifo, (unsigned char *)msg_buffer,
292 TSI721_RIO_PW_MSG_SIZE, &priv->pw_fifo_lock)) {
293 /* Process one message */
297 pr_debug("%s : Port-Write Message:", __func__);
298 for (i = 0; i < RIO_PW_MSG_SIZE/sizeof(u32); ) {
299 pr_debug("0x%02x: %08x %08x %08x %08x", i*4,
300 msg_buffer[i], msg_buffer[i + 1],
301 msg_buffer[i + 2], msg_buffer[i + 3]);
307 /* Pass the port-write message to RIO core for processing */
308 rio_inb_pwrite_handler((union rio_pw_msg *)msg_buffer);
313 * tsi721_pw_enable - enable/disable port-write interface init
314 * @mport: Master port implementing the port write unit
315 * @enable: 1=enable; 0=disable port-write message handling
317 static int tsi721_pw_enable(struct rio_mport *mport, int enable)
319 struct tsi721_device *priv = mport->priv;
322 rval = ioread32(priv->regs + TSI721_RIO_EM_INT_ENABLE);
325 rval |= TSI721_RIO_EM_INT_ENABLE_PW_RX;
327 rval &= ~TSI721_RIO_EM_INT_ENABLE_PW_RX;
329 /* Clear pending PW interrupts */
330 iowrite32(TSI721_RIO_PW_RX_STAT_PW_DISC | TSI721_RIO_PW_RX_STAT_PW_VAL,
331 priv->regs + TSI721_RIO_PW_RX_STAT);
332 /* Update enable bits */
333 iowrite32(rval, priv->regs + TSI721_RIO_EM_INT_ENABLE);
339 * tsi721_dsend - Send a RapidIO doorbell
340 * @mport: RapidIO master port info
341 * @index: ID of RapidIO interface
342 * @destid: Destination ID of target device
343 * @data: 16-bit info field of RapidIO doorbell
345 * Sends a RapidIO doorbell message. Always returns %0.
347 static int tsi721_dsend(struct rio_mport *mport, int index,
348 u16 destid, u16 data)
350 struct tsi721_device *priv = mport->priv;
353 offset = (((mport->sys_size) ? RIO_TT_CODE_16 : RIO_TT_CODE_8) << 18) |
356 dev_dbg(&priv->pdev->dev,
357 "Send Doorbell 0x%04x to destID 0x%x\n", data, destid);
358 iowrite16be(data, priv->odb_base + offset);
364 * tsi721_dbell_handler - Tsi721 doorbell interrupt handler
365 * @priv: tsi721 device-specific data structure
367 * Handles inbound doorbell interrupts. Copies doorbell entry from an internal
368 * buffer into DB message FIFO and schedules deferred routine to process
372 tsi721_dbell_handler(struct tsi721_device *priv)
376 /* Disable IDB interrupts */
377 regval = ioread32(priv->regs + TSI721_SR_CHINTE(IDB_QUEUE));
378 regval &= ~TSI721_SR_CHINT_IDBQRCV;
380 priv->regs + TSI721_SR_CHINTE(IDB_QUEUE));
382 schedule_work(&priv->idb_work);
387 static void tsi721_db_dpc(struct work_struct *work)
389 struct tsi721_device *priv = container_of(work, struct tsi721_device,
391 struct rio_mport *mport;
392 struct rio_dbell *dbell;
403 * Process queued inbound doorbells
405 mport = &priv->mport;
407 wr_ptr = ioread32(priv->regs + TSI721_IDQ_WP(IDB_QUEUE)) % IDB_QSIZE;
408 rd_ptr = ioread32(priv->regs + TSI721_IDQ_RP(IDB_QUEUE)) % IDB_QSIZE;
410 while (wr_ptr != rd_ptr) {
411 idb_entry = (u64 *)(priv->idb_base +
412 (TSI721_IDB_ENTRY_SIZE * rd_ptr));
415 idb.msg = *idb_entry;
418 /* Process one doorbell */
419 list_for_each_entry(dbell, &mport->dbells, node) {
420 if ((dbell->res->start <= DBELL_INF(idb.bytes)) &&
421 (dbell->res->end >= DBELL_INF(idb.bytes))) {
428 dbell->dinb(mport, dbell->dev_id, DBELL_SID(idb.bytes),
429 DBELL_TID(idb.bytes), DBELL_INF(idb.bytes));
431 dev_dbg(&priv->pdev->dev,
432 "spurious inb doorbell, sid %2.2x tid %2.2x"
433 " info %4.4x\n", DBELL_SID(idb.bytes),
434 DBELL_TID(idb.bytes), DBELL_INF(idb.bytes));
437 wr_ptr = ioread32(priv->regs +
438 TSI721_IDQ_WP(IDB_QUEUE)) % IDB_QSIZE;
441 iowrite32(rd_ptr & (IDB_QSIZE - 1),
442 priv->regs + TSI721_IDQ_RP(IDB_QUEUE));
444 /* Re-enable IDB interrupts */
445 regval = ioread32(priv->regs + TSI721_SR_CHINTE(IDB_QUEUE));
446 regval |= TSI721_SR_CHINT_IDBQRCV;
448 priv->regs + TSI721_SR_CHINTE(IDB_QUEUE));
450 wr_ptr = ioread32(priv->regs + TSI721_IDQ_WP(IDB_QUEUE)) % IDB_QSIZE;
451 if (wr_ptr != rd_ptr)
452 schedule_work(&priv->idb_work);
456 * tsi721_irqhandler - Tsi721 interrupt handler
457 * @irq: Linux interrupt number
458 * @ptr: Pointer to interrupt-specific data (tsi721_device structure)
460 * Handles Tsi721 interrupts signaled using MSI and INTA. Checks reported
461 * interrupt events and calls an event-specific handler(s).
463 static irqreturn_t tsi721_irqhandler(int irq, void *ptr)
465 struct tsi721_device *priv = (struct tsi721_device *)ptr;
471 /* For MSI mode disable all device-level interrupts */
472 if (priv->flags & TSI721_USING_MSI)
473 iowrite32(0, priv->regs + TSI721_DEV_INTE);
475 dev_int = ioread32(priv->regs + TSI721_DEV_INT);
479 dev_ch_int = ioread32(priv->regs + TSI721_DEV_CHAN_INT);
481 if (dev_int & TSI721_DEV_INT_SR2PC_CH) {
482 /* Service SR2PC Channel interrupts */
483 if (dev_ch_int & TSI721_INT_SR2PC_CHAN(IDB_QUEUE)) {
484 /* Service Inbound Doorbell interrupt */
485 intval = ioread32(priv->regs +
486 TSI721_SR_CHINT(IDB_QUEUE));
487 if (intval & TSI721_SR_CHINT_IDBQRCV)
488 tsi721_dbell_handler(priv);
490 dev_info(&priv->pdev->dev,
491 "Unsupported SR_CH_INT %x\n", intval);
493 /* Clear interrupts */
495 priv->regs + TSI721_SR_CHINT(IDB_QUEUE));
496 ioread32(priv->regs + TSI721_SR_CHINT(IDB_QUEUE));
500 if (dev_int & TSI721_DEV_INT_SMSG_CH) {
504 * Service channel interrupts from Messaging Engine
507 if (dev_ch_int & TSI721_INT_IMSG_CHAN_M) { /* Inbound Msg */
508 /* Disable signaled OB MSG Channel interrupts */
509 ch_inte = ioread32(priv->regs + TSI721_DEV_CHAN_INTE);
510 ch_inte &= ~(dev_ch_int & TSI721_INT_IMSG_CHAN_M);
511 iowrite32(ch_inte, priv->regs + TSI721_DEV_CHAN_INTE);
514 * Process Inbound Message interrupt for each MBOX
516 for (ch = 4; ch < RIO_MAX_MBOX + 4; ch++) {
517 if (!(dev_ch_int & TSI721_INT_IMSG_CHAN(ch)))
519 tsi721_imsg_handler(priv, ch);
523 if (dev_ch_int & TSI721_INT_OMSG_CHAN_M) { /* Outbound Msg */
524 /* Disable signaled OB MSG Channel interrupts */
525 ch_inte = ioread32(priv->regs + TSI721_DEV_CHAN_INTE);
526 ch_inte &= ~(dev_ch_int & TSI721_INT_OMSG_CHAN_M);
527 iowrite32(ch_inte, priv->regs + TSI721_DEV_CHAN_INTE);
530 * Process Outbound Message interrupts for each MBOX
533 for (ch = 0; ch < RIO_MAX_MBOX; ch++) {
534 if (!(dev_ch_int & TSI721_INT_OMSG_CHAN(ch)))
536 tsi721_omsg_handler(priv, ch);
541 if (dev_int & TSI721_DEV_INT_SRIO) {
542 /* Service SRIO MAC interrupts */
543 intval = ioread32(priv->regs + TSI721_RIO_EM_INT_STAT);
544 if (intval & TSI721_RIO_EM_INT_STAT_PW_RX)
545 tsi721_pw_handler(priv);
548 #ifdef CONFIG_RAPIDIO_DMA_ENGINE
549 if (dev_int & TSI721_DEV_INT_BDMA_CH) {
552 if (dev_ch_int & TSI721_INT_BDMA_CHAN_M) {
553 dev_dbg(&priv->pdev->dev,
554 "IRQ from DMA channel 0x%08x\n", dev_ch_int);
556 for (ch = 0; ch < TSI721_DMA_MAXCH; ch++) {
557 if (!(dev_ch_int & TSI721_INT_BDMA_CHAN(ch)))
559 tsi721_bdma_handler(&priv->bdma[ch]);
565 /* For MSI mode re-enable device-level interrupts */
566 if (priv->flags & TSI721_USING_MSI) {
567 dev_int = TSI721_DEV_INT_SR2PC_CH | TSI721_DEV_INT_SRIO |
568 TSI721_DEV_INT_SMSG_CH | TSI721_DEV_INT_BDMA_CH;
569 iowrite32(dev_int, priv->regs + TSI721_DEV_INTE);
575 static void tsi721_interrupts_init(struct tsi721_device *priv)
579 /* Enable IDB interrupts */
580 iowrite32(TSI721_SR_CHINT_ALL,
581 priv->regs + TSI721_SR_CHINT(IDB_QUEUE));
582 iowrite32(TSI721_SR_CHINT_IDBQRCV,
583 priv->regs + TSI721_SR_CHINTE(IDB_QUEUE));
585 /* Enable SRIO MAC interrupts */
586 iowrite32(TSI721_RIO_EM_DEV_INT_EN_INT,
587 priv->regs + TSI721_RIO_EM_DEV_INT_EN);
589 /* Enable interrupts from channels in use */
590 #ifdef CONFIG_RAPIDIO_DMA_ENGINE
591 intr = TSI721_INT_SR2PC_CHAN(IDB_QUEUE) |
592 (TSI721_INT_BDMA_CHAN_M &
593 ~TSI721_INT_BDMA_CHAN(TSI721_DMACH_MAINT));
595 intr = TSI721_INT_SR2PC_CHAN(IDB_QUEUE);
597 iowrite32(intr, priv->regs + TSI721_DEV_CHAN_INTE);
599 if (priv->flags & TSI721_USING_MSIX)
600 intr = TSI721_DEV_INT_SRIO;
602 intr = TSI721_DEV_INT_SR2PC_CH | TSI721_DEV_INT_SRIO |
603 TSI721_DEV_INT_SMSG_CH | TSI721_DEV_INT_BDMA_CH;
605 iowrite32(intr, priv->regs + TSI721_DEV_INTE);
606 ioread32(priv->regs + TSI721_DEV_INTE);
609 #ifdef CONFIG_PCI_MSI
611 * tsi721_omsg_msix - MSI-X interrupt handler for outbound messaging
612 * @irq: Linux interrupt number
613 * @ptr: Pointer to interrupt-specific data (tsi721_device structure)
615 * Handles outbound messaging interrupts signaled using MSI-X.
617 static irqreturn_t tsi721_omsg_msix(int irq, void *ptr)
619 struct tsi721_device *priv = (struct tsi721_device *)ptr;
622 mbox = (irq - priv->msix[TSI721_VECT_OMB0_DONE].vector) % RIO_MAX_MBOX;
623 tsi721_omsg_handler(priv, mbox);
628 * tsi721_imsg_msix - MSI-X interrupt handler for inbound messaging
629 * @irq: Linux interrupt number
630 * @ptr: Pointer to interrupt-specific data (tsi721_device structure)
632 * Handles inbound messaging interrupts signaled using MSI-X.
634 static irqreturn_t tsi721_imsg_msix(int irq, void *ptr)
636 struct tsi721_device *priv = (struct tsi721_device *)ptr;
639 mbox = (irq - priv->msix[TSI721_VECT_IMB0_RCV].vector) % RIO_MAX_MBOX;
640 tsi721_imsg_handler(priv, mbox + 4);
645 * tsi721_srio_msix - Tsi721 MSI-X SRIO MAC interrupt handler
646 * @irq: Linux interrupt number
647 * @ptr: Pointer to interrupt-specific data (tsi721_device structure)
649 * Handles Tsi721 interrupts from SRIO MAC.
651 static irqreturn_t tsi721_srio_msix(int irq, void *ptr)
653 struct tsi721_device *priv = (struct tsi721_device *)ptr;
656 /* Service SRIO MAC interrupts */
657 srio_int = ioread32(priv->regs + TSI721_RIO_EM_INT_STAT);
658 if (srio_int & TSI721_RIO_EM_INT_STAT_PW_RX)
659 tsi721_pw_handler(priv);
665 * tsi721_sr2pc_ch_msix - Tsi721 MSI-X SR2PC Channel interrupt handler
666 * @irq: Linux interrupt number
667 * @ptr: Pointer to interrupt-specific data (tsi721_device structure)
669 * Handles Tsi721 interrupts from SR2PC Channel.
670 * NOTE: At this moment services only one SR2PC channel associated with inbound
673 static irqreturn_t tsi721_sr2pc_ch_msix(int irq, void *ptr)
675 struct tsi721_device *priv = (struct tsi721_device *)ptr;
678 /* Service Inbound DB interrupt from SR2PC channel */
679 sr_ch_int = ioread32(priv->regs + TSI721_SR_CHINT(IDB_QUEUE));
680 if (sr_ch_int & TSI721_SR_CHINT_IDBQRCV)
681 tsi721_dbell_handler(priv);
683 /* Clear interrupts */
684 iowrite32(sr_ch_int, priv->regs + TSI721_SR_CHINT(IDB_QUEUE));
685 /* Read back to ensure that interrupt was cleared */
686 sr_ch_int = ioread32(priv->regs + TSI721_SR_CHINT(IDB_QUEUE));
692 * tsi721_request_msix - register interrupt service for MSI-X mode.
693 * @priv: tsi721 device-specific data structure
695 * Registers MSI-X interrupt service routines for interrupts that are active
696 * immediately after mport initialization. Messaging interrupt service routines
697 * should be registered during corresponding open requests.
699 static int tsi721_request_msix(struct tsi721_device *priv)
703 err = request_irq(priv->msix[TSI721_VECT_IDB].vector,
704 tsi721_sr2pc_ch_msix, 0,
705 priv->msix[TSI721_VECT_IDB].irq_name, (void *)priv);
709 err = request_irq(priv->msix[TSI721_VECT_PWRX].vector,
711 priv->msix[TSI721_VECT_PWRX].irq_name, (void *)priv);
713 free_irq(priv->msix[TSI721_VECT_IDB].vector, (void *)priv);
721 * tsi721_enable_msix - Attempts to enable MSI-X support for Tsi721.
722 * @priv: pointer to tsi721 private data
724 * Configures MSI-X support for Tsi721. Supports only an exact number
725 * of requested vectors.
727 static int tsi721_enable_msix(struct tsi721_device *priv)
729 struct msix_entry entries[TSI721_VECT_MAX];
733 entries[TSI721_VECT_IDB].entry = TSI721_MSIX_SR2PC_IDBQ_RCV(IDB_QUEUE);
734 entries[TSI721_VECT_PWRX].entry = TSI721_MSIX_SRIO_MAC_INT;
737 * Initialize MSI-X entries for Messaging Engine:
738 * this driver supports four RIO mailboxes (inbound and outbound)
739 * NOTE: Inbound message MBOX 0...4 use IB channels 4...7. Therefore
740 * offset +4 is added to IB MBOX number.
742 for (i = 0; i < RIO_MAX_MBOX; i++) {
743 entries[TSI721_VECT_IMB0_RCV + i].entry =
744 TSI721_MSIX_IMSG_DQ_RCV(i + 4);
745 entries[TSI721_VECT_IMB0_INT + i].entry =
746 TSI721_MSIX_IMSG_INT(i + 4);
747 entries[TSI721_VECT_OMB0_DONE + i].entry =
748 TSI721_MSIX_OMSG_DONE(i);
749 entries[TSI721_VECT_OMB0_INT + i].entry =
750 TSI721_MSIX_OMSG_INT(i);
753 #ifdef CONFIG_RAPIDIO_DMA_ENGINE
755 * Initialize MSI-X entries for Block DMA Engine:
756 * this driver supports XXX DMA channels
757 * (one is reserved for SRIO maintenance transactions)
759 for (i = 0; i < TSI721_DMA_CHNUM; i++) {
760 entries[TSI721_VECT_DMA0_DONE + i].entry =
761 TSI721_MSIX_DMACH_DONE(i);
762 entries[TSI721_VECT_DMA0_INT + i].entry =
763 TSI721_MSIX_DMACH_INT(i);
765 #endif /* CONFIG_RAPIDIO_DMA_ENGINE */
767 err = pci_enable_msix_exact(priv->pdev, entries, ARRAY_SIZE(entries));
769 dev_err(&priv->pdev->dev,
770 "Failed to enable MSI-X (err=%d)\n", err);
775 * Copy MSI-X vector information into tsi721 private structure
777 priv->msix[TSI721_VECT_IDB].vector = entries[TSI721_VECT_IDB].vector;
778 snprintf(priv->msix[TSI721_VECT_IDB].irq_name, IRQ_DEVICE_NAME_MAX,
779 DRV_NAME "-idb@pci:%s", pci_name(priv->pdev));
780 priv->msix[TSI721_VECT_PWRX].vector = entries[TSI721_VECT_PWRX].vector;
781 snprintf(priv->msix[TSI721_VECT_PWRX].irq_name, IRQ_DEVICE_NAME_MAX,
782 DRV_NAME "-pwrx@pci:%s", pci_name(priv->pdev));
784 for (i = 0; i < RIO_MAX_MBOX; i++) {
785 priv->msix[TSI721_VECT_IMB0_RCV + i].vector =
786 entries[TSI721_VECT_IMB0_RCV + i].vector;
787 snprintf(priv->msix[TSI721_VECT_IMB0_RCV + i].irq_name,
788 IRQ_DEVICE_NAME_MAX, DRV_NAME "-imbr%d@pci:%s",
789 i, pci_name(priv->pdev));
791 priv->msix[TSI721_VECT_IMB0_INT + i].vector =
792 entries[TSI721_VECT_IMB0_INT + i].vector;
793 snprintf(priv->msix[TSI721_VECT_IMB0_INT + i].irq_name,
794 IRQ_DEVICE_NAME_MAX, DRV_NAME "-imbi%d@pci:%s",
795 i, pci_name(priv->pdev));
797 priv->msix[TSI721_VECT_OMB0_DONE + i].vector =
798 entries[TSI721_VECT_OMB0_DONE + i].vector;
799 snprintf(priv->msix[TSI721_VECT_OMB0_DONE + i].irq_name,
800 IRQ_DEVICE_NAME_MAX, DRV_NAME "-ombd%d@pci:%s",
801 i, pci_name(priv->pdev));
803 priv->msix[TSI721_VECT_OMB0_INT + i].vector =
804 entries[TSI721_VECT_OMB0_INT + i].vector;
805 snprintf(priv->msix[TSI721_VECT_OMB0_INT + i].irq_name,
806 IRQ_DEVICE_NAME_MAX, DRV_NAME "-ombi%d@pci:%s",
807 i, pci_name(priv->pdev));
810 #ifdef CONFIG_RAPIDIO_DMA_ENGINE
811 for (i = 0; i < TSI721_DMA_CHNUM; i++) {
812 priv->msix[TSI721_VECT_DMA0_DONE + i].vector =
813 entries[TSI721_VECT_DMA0_DONE + i].vector;
814 snprintf(priv->msix[TSI721_VECT_DMA0_DONE + i].irq_name,
815 IRQ_DEVICE_NAME_MAX, DRV_NAME "-dmad%d@pci:%s",
816 i, pci_name(priv->pdev));
818 priv->msix[TSI721_VECT_DMA0_INT + i].vector =
819 entries[TSI721_VECT_DMA0_INT + i].vector;
820 snprintf(priv->msix[TSI721_VECT_DMA0_INT + i].irq_name,
821 IRQ_DEVICE_NAME_MAX, DRV_NAME "-dmai%d@pci:%s",
822 i, pci_name(priv->pdev));
824 #endif /* CONFIG_RAPIDIO_DMA_ENGINE */
828 #endif /* CONFIG_PCI_MSI */
830 static int tsi721_request_irq(struct tsi721_device *priv)
834 #ifdef CONFIG_PCI_MSI
835 if (priv->flags & TSI721_USING_MSIX)
836 err = tsi721_request_msix(priv);
839 err = request_irq(priv->pdev->irq, tsi721_irqhandler,
840 (priv->flags & TSI721_USING_MSI) ? 0 : IRQF_SHARED,
841 DRV_NAME, (void *)priv);
844 dev_err(&priv->pdev->dev,
845 "Unable to allocate interrupt, Error: %d\n", err);
850 static void tsi721_free_irq(struct tsi721_device *priv)
852 #ifdef CONFIG_PCI_MSI
853 if (priv->flags & TSI721_USING_MSIX) {
854 free_irq(priv->msix[TSI721_VECT_IDB].vector, (void *)priv);
855 free_irq(priv->msix[TSI721_VECT_PWRX].vector, (void *)priv);
858 free_irq(priv->pdev->irq, (void *)priv);
862 * tsi721_init_pc2sr_mapping - initializes outbound (PCIe->SRIO)
863 * translation regions.
864 * @priv: pointer to tsi721 private data
866 * Disables SREP translation regions.
868 static void tsi721_init_pc2sr_mapping(struct tsi721_device *priv)
872 /* Disable all PC2SR translation windows */
873 for (i = 0; i < TSI721_OBWIN_NUM; i++)
874 iowrite32(0, priv->regs + TSI721_OBWINLB(i));
878 * tsi721_rio_map_inb_mem -- Mapping inbound memory region.
879 * @mport: RapidIO master port
880 * @lstart: Local memory space start address.
881 * @rstart: RapidIO space start address.
882 * @size: The mapping region size.
883 * @flags: Flags for mapping. 0 for using default flags.
885 * Return: 0 -- Success.
887 * This function will create the inbound mapping
888 * from rstart to lstart.
890 static int tsi721_rio_map_inb_mem(struct rio_mport *mport, dma_addr_t lstart,
891 u64 rstart, u32 size, u32 flags)
893 struct tsi721_device *priv = mport->priv;
896 struct tsi721_ib_win *ib_win;
897 bool direct = (lstart == rstart);
899 dma_addr_t loc_start;
901 struct tsi721_ib_win_mapping *map = NULL;
905 dev_dbg(&priv->pdev->dev,
906 "Direct (RIO_0x%llx -> PCIe_0x%pad), size=0x%x",
907 rstart, &lstart, size);
909 /* Calculate minimal acceptable window size and base address */
911 ibw_size = roundup_pow_of_two(size);
912 ibw_start = lstart & ~(ibw_size - 1);
914 while ((lstart + size) > (ibw_start + ibw_size)) {
916 ibw_start = lstart & ~(ibw_size - 1);
917 if (ibw_size > 0x80000000) { /* Limit max size to 2GB */
922 loc_start = ibw_start;
924 map = kzalloc(sizeof(struct tsi721_ib_win_mapping), GFP_ATOMIC);
929 dev_dbg(&priv->pdev->dev,
930 "Translated (RIO_0x%llx -> PCIe_0x%pad), size=0x%x",
931 rstart, &lstart, size);
933 if (!is_power_of_2(size) || size < 0x1000 ||
934 ((u64)lstart & (size - 1)) || (rstart & (size - 1)))
936 if (priv->ibwin_cnt == 0)
944 * Scan for overlapping with active regions and mark the first available
945 * IB window at the same time.
947 for (i = 0; i < TSI721_IBWIN_NUM; i++) {
948 ib_win = &priv->ib_win[i];
950 if (!ib_win->active) {
955 } else if (ibw_start < (ib_win->rstart + ib_win->size) &&
956 (ibw_start + ibw_size) > ib_win->rstart) {
957 /* Return error if address translation involved */
958 if (direct && ib_win->xlat) {
964 * Direct mappings usually are larger than originally
965 * requested fragments - check if this new request fits
968 if (rstart >= ib_win->rstart &&
969 (rstart + size) <= (ib_win->rstart +
971 /* We are in - no further mapping required */
972 map->lstart = lstart;
973 list_add_tail(&map->node, &ib_win->mappings);
986 /* Sanity check: available IB window must be disabled at this point */
987 regval = ioread32(priv->regs + TSI721_IBWIN_LB(i));
988 if (WARN_ON(regval & TSI721_IBWIN_LB_WEN)) {
993 ib_win = &priv->ib_win[i];
994 ib_win->active = true;
995 ib_win->rstart = ibw_start;
996 ib_win->lstart = loc_start;
997 ib_win->size = ibw_size;
998 ib_win->xlat = (lstart != rstart);
999 INIT_LIST_HEAD(&ib_win->mappings);
1002 * When using direct IBW mapping and have larger than requested IBW size
1003 * we can have multiple local memory blocks mapped through the same IBW
1004 * To handle this situation we maintain list of "clients" for such IBWs.
1007 map->lstart = lstart;
1008 list_add_tail(&map->node, &ib_win->mappings);
1011 iowrite32(TSI721_IBWIN_SIZE(ibw_size) << 8,
1012 priv->regs + TSI721_IBWIN_SZ(i));
1014 iowrite32(((u64)loc_start >> 32), priv->regs + TSI721_IBWIN_TUA(i));
1015 iowrite32(((u64)loc_start & TSI721_IBWIN_TLA_ADD),
1016 priv->regs + TSI721_IBWIN_TLA(i));
1018 iowrite32(ibw_start >> 32, priv->regs + TSI721_IBWIN_UB(i));
1019 iowrite32((ibw_start & TSI721_IBWIN_LB_BA) | TSI721_IBWIN_LB_WEN,
1020 priv->regs + TSI721_IBWIN_LB(i));
1024 dev_dbg(&priv->pdev->dev,
1025 "Configured IBWIN%d (RIO_0x%llx -> PCIe_0x%llx), size=0x%llx\n",
1026 i, ibw_start, (unsigned long long)loc_start, ibw_size);
1035 * tsi721_rio_unmap_inb_mem -- Unmapping inbound memory region.
1036 * @mport: RapidIO master port
1037 * @lstart: Local memory space start address.
1039 static void tsi721_rio_unmap_inb_mem(struct rio_mport *mport,
1042 struct tsi721_device *priv = mport->priv;
1043 struct tsi721_ib_win *ib_win;
1046 dev_dbg(&priv->pdev->dev,
1047 "Unmap IBW mapped to PCIe_0x%pad", &lstart);
1049 /* Search for matching active inbound translation window */
1050 for (i = 0; i < TSI721_IBWIN_NUM; i++) {
1051 ib_win = &priv->ib_win[i];
1053 /* Address translating IBWs must to be an exact march */
1054 if (!ib_win->active ||
1055 (ib_win->xlat && lstart != ib_win->lstart))
1058 if (lstart >= ib_win->lstart &&
1059 lstart < (ib_win->lstart + ib_win->size)) {
1061 if (!ib_win->xlat) {
1062 struct tsi721_ib_win_mapping *map;
1065 list_for_each_entry(map,
1066 &ib_win->mappings, node) {
1067 if (map->lstart == lstart) {
1068 list_del(&map->node);
1078 if (!list_empty(&ib_win->mappings))
1082 dev_dbg(&priv->pdev->dev, "Disable IBWIN_%d", i);
1083 iowrite32(0, priv->regs + TSI721_IBWIN_LB(i));
1084 ib_win->active = false;
1090 if (i == TSI721_IBWIN_NUM)
1091 dev_dbg(&priv->pdev->dev,
1092 "IB window mapped to %pad not found", &lstart);
1096 * tsi721_init_sr2pc_mapping - initializes inbound (SRIO->PCIe)
1097 * translation regions.
1098 * @priv: pointer to tsi721 private data
1100 * Disables inbound windows.
1102 static void tsi721_init_sr2pc_mapping(struct tsi721_device *priv)
1106 /* Disable all SR2PC inbound windows */
1107 for (i = 0; i < TSI721_IBWIN_NUM; i++)
1108 iowrite32(0, priv->regs + TSI721_IBWIN_LB(i));
1109 priv->ibwin_cnt = TSI721_IBWIN_NUM;
1113 * tsi721_close_sr2pc_mapping - closes all active inbound (SRIO->PCIe)
1114 * translation regions.
1115 * @priv: pointer to tsi721 device private data
1117 static void tsi721_close_sr2pc_mapping(struct tsi721_device *priv)
1119 struct tsi721_ib_win *ib_win;
1122 /* Disable all active SR2PC inbound windows */
1123 for (i = 0; i < TSI721_IBWIN_NUM; i++) {
1124 ib_win = &priv->ib_win[i];
1125 if (ib_win->active) {
1126 iowrite32(0, priv->regs + TSI721_IBWIN_LB(i));
1127 ib_win->active = false;
1133 * tsi721_port_write_init - Inbound port write interface init
1134 * @priv: pointer to tsi721 private data
1136 * Initializes inbound port write handler.
1137 * Returns %0 on success or %-ENOMEM on failure.
1139 static int tsi721_port_write_init(struct tsi721_device *priv)
1141 priv->pw_discard_count = 0;
1142 INIT_WORK(&priv->pw_work, tsi721_pw_dpc);
1143 spin_lock_init(&priv->pw_fifo_lock);
1144 if (kfifo_alloc(&priv->pw_fifo,
1145 TSI721_RIO_PW_MSG_SIZE * 32, GFP_KERNEL)) {
1146 dev_err(&priv->pdev->dev, "PW FIFO allocation failed\n");
1150 /* Use reliable port-write capture mode */
1151 iowrite32(TSI721_RIO_PW_CTL_PWC_REL, priv->regs + TSI721_RIO_PW_CTL);
1155 static void tsi721_port_write_free(struct tsi721_device *priv)
1157 kfifo_free(&priv->pw_fifo);
1160 static int tsi721_doorbell_init(struct tsi721_device *priv)
1162 /* Outbound Doorbells do not require any setup.
1163 * Tsi721 uses dedicated PCI BAR1 to generate doorbells.
1164 * That BAR1 was mapped during the probe routine.
1167 /* Initialize Inbound Doorbell processing DPC and queue */
1168 priv->db_discard_count = 0;
1169 INIT_WORK(&priv->idb_work, tsi721_db_dpc);
1171 /* Allocate buffer for inbound doorbells queue */
1172 priv->idb_base = dma_zalloc_coherent(&priv->pdev->dev,
1173 IDB_QSIZE * TSI721_IDB_ENTRY_SIZE,
1174 &priv->idb_dma, GFP_KERNEL);
1175 if (!priv->idb_base)
1178 dev_dbg(&priv->pdev->dev, "Allocated IDB buffer @ %p (phys = %llx)\n",
1179 priv->idb_base, (unsigned long long)priv->idb_dma);
1181 iowrite32(TSI721_IDQ_SIZE_VAL(IDB_QSIZE),
1182 priv->regs + TSI721_IDQ_SIZE(IDB_QUEUE));
1183 iowrite32(((u64)priv->idb_dma >> 32),
1184 priv->regs + TSI721_IDQ_BASEU(IDB_QUEUE));
1185 iowrite32(((u64)priv->idb_dma & TSI721_IDQ_BASEL_ADDR),
1186 priv->regs + TSI721_IDQ_BASEL(IDB_QUEUE));
1187 /* Enable accepting all inbound doorbells */
1188 iowrite32(0, priv->regs + TSI721_IDQ_MASK(IDB_QUEUE));
1190 iowrite32(TSI721_IDQ_INIT, priv->regs + TSI721_IDQ_CTL(IDB_QUEUE));
1192 iowrite32(0, priv->regs + TSI721_IDQ_RP(IDB_QUEUE));
1197 static void tsi721_doorbell_free(struct tsi721_device *priv)
1199 if (priv->idb_base == NULL)
1202 /* Free buffer allocated for inbound doorbell queue */
1203 dma_free_coherent(&priv->pdev->dev, IDB_QSIZE * TSI721_IDB_ENTRY_SIZE,
1204 priv->idb_base, priv->idb_dma);
1205 priv->idb_base = NULL;
1209 * tsi721_bdma_maint_init - Initialize maintenance request BDMA channel.
1210 * @priv: pointer to tsi721 private data
1212 * Initialize BDMA channel allocated for RapidIO maintenance read/write
1213 * request generation
1214 * Returns %0 on success or %-ENOMEM on failure.
1216 static int tsi721_bdma_maint_init(struct tsi721_device *priv)
1218 struct tsi721_dma_desc *bd_ptr;
1220 dma_addr_t bd_phys, sts_phys;
1225 dev_dbg(&priv->pdev->dev,
1226 "Init Block DMA Engine for Maintenance requests, CH%d\n",
1227 TSI721_DMACH_MAINT);
1230 * Initialize DMA channel for maintenance requests
1233 priv->mdma.ch_id = TSI721_DMACH_MAINT;
1234 regs = priv->regs + TSI721_DMAC_BASE(TSI721_DMACH_MAINT);
1236 /* Allocate space for DMA descriptors */
1237 bd_ptr = dma_zalloc_coherent(&priv->pdev->dev,
1238 bd_num * sizeof(struct tsi721_dma_desc),
1239 &bd_phys, GFP_KERNEL);
1243 priv->mdma.bd_num = bd_num;
1244 priv->mdma.bd_phys = bd_phys;
1245 priv->mdma.bd_base = bd_ptr;
1247 dev_dbg(&priv->pdev->dev, "DMA descriptors @ %p (phys = %llx)\n",
1248 bd_ptr, (unsigned long long)bd_phys);
1250 /* Allocate space for descriptor status FIFO */
1251 sts_size = (bd_num >= TSI721_DMA_MINSTSSZ) ?
1252 bd_num : TSI721_DMA_MINSTSSZ;
1253 sts_size = roundup_pow_of_two(sts_size);
1254 sts_ptr = dma_zalloc_coherent(&priv->pdev->dev,
1255 sts_size * sizeof(struct tsi721_dma_sts),
1256 &sts_phys, GFP_KERNEL);
1258 /* Free space allocated for DMA descriptors */
1259 dma_free_coherent(&priv->pdev->dev,
1260 bd_num * sizeof(struct tsi721_dma_desc),
1262 priv->mdma.bd_base = NULL;
1266 priv->mdma.sts_phys = sts_phys;
1267 priv->mdma.sts_base = sts_ptr;
1268 priv->mdma.sts_size = sts_size;
1270 dev_dbg(&priv->pdev->dev,
1271 "desc status FIFO @ %p (phys = %llx) size=0x%x\n",
1272 sts_ptr, (unsigned long long)sts_phys, sts_size);
1274 /* Initialize DMA descriptors ring */
1275 bd_ptr[bd_num - 1].type_id = cpu_to_le32(DTYPE3 << 29);
1276 bd_ptr[bd_num - 1].next_lo = cpu_to_le32((u64)bd_phys &
1277 TSI721_DMAC_DPTRL_MASK);
1278 bd_ptr[bd_num - 1].next_hi = cpu_to_le32((u64)bd_phys >> 32);
1280 /* Setup DMA descriptor pointers */
1281 iowrite32(((u64)bd_phys >> 32), regs + TSI721_DMAC_DPTRH);
1282 iowrite32(((u64)bd_phys & TSI721_DMAC_DPTRL_MASK),
1283 regs + TSI721_DMAC_DPTRL);
1285 /* Setup descriptor status FIFO */
1286 iowrite32(((u64)sts_phys >> 32), regs + TSI721_DMAC_DSBH);
1287 iowrite32(((u64)sts_phys & TSI721_DMAC_DSBL_MASK),
1288 regs + TSI721_DMAC_DSBL);
1289 iowrite32(TSI721_DMAC_DSSZ_SIZE(sts_size),
1290 regs + TSI721_DMAC_DSSZ);
1292 /* Clear interrupt bits */
1293 iowrite32(TSI721_DMAC_INT_ALL, regs + TSI721_DMAC_INT);
1295 ioread32(regs + TSI721_DMAC_INT);
1297 /* Toggle DMA channel initialization */
1298 iowrite32(TSI721_DMAC_CTL_INIT, regs + TSI721_DMAC_CTL);
1299 ioread32(regs + TSI721_DMAC_CTL);
1305 static int tsi721_bdma_maint_free(struct tsi721_device *priv)
1308 struct tsi721_bdma_maint *mdma = &priv->mdma;
1309 void __iomem *regs = priv->regs + TSI721_DMAC_BASE(mdma->ch_id);
1311 if (mdma->bd_base == NULL)
1314 /* Check if DMA channel still running */
1315 ch_stat = ioread32(regs + TSI721_DMAC_STS);
1316 if (ch_stat & TSI721_DMAC_STS_RUN)
1319 /* Put DMA channel into init state */
1320 iowrite32(TSI721_DMAC_CTL_INIT, regs + TSI721_DMAC_CTL);
1322 /* Free space allocated for DMA descriptors */
1323 dma_free_coherent(&priv->pdev->dev,
1324 mdma->bd_num * sizeof(struct tsi721_dma_desc),
1325 mdma->bd_base, mdma->bd_phys);
1326 mdma->bd_base = NULL;
1328 /* Free space allocated for status FIFO */
1329 dma_free_coherent(&priv->pdev->dev,
1330 mdma->sts_size * sizeof(struct tsi721_dma_sts),
1331 mdma->sts_base, mdma->sts_phys);
1332 mdma->sts_base = NULL;
1336 /* Enable Inbound Messaging Interrupts */
1338 tsi721_imsg_interrupt_enable(struct tsi721_device *priv, int ch,
1346 /* Clear pending Inbound Messaging interrupts */
1347 iowrite32(inte_mask, priv->regs + TSI721_IBDMAC_INT(ch));
1349 /* Enable Inbound Messaging interrupts */
1350 rval = ioread32(priv->regs + TSI721_IBDMAC_INTE(ch));
1351 iowrite32(rval | inte_mask, priv->regs + TSI721_IBDMAC_INTE(ch));
1353 if (priv->flags & TSI721_USING_MSIX)
1354 return; /* Finished if we are in MSI-X mode */
1357 * For MSI and INTA interrupt signalling we need to enable next levels
1360 /* Enable Device Channel Interrupt */
1361 rval = ioread32(priv->regs + TSI721_DEV_CHAN_INTE);
1362 iowrite32(rval | TSI721_INT_IMSG_CHAN(ch),
1363 priv->regs + TSI721_DEV_CHAN_INTE);
1366 /* Disable Inbound Messaging Interrupts */
1368 tsi721_imsg_interrupt_disable(struct tsi721_device *priv, int ch,
1376 /* Clear pending Inbound Messaging interrupts */
1377 iowrite32(inte_mask, priv->regs + TSI721_IBDMAC_INT(ch));
1379 /* Disable Inbound Messaging interrupts */
1380 rval = ioread32(priv->regs + TSI721_IBDMAC_INTE(ch));
1382 iowrite32(rval, priv->regs + TSI721_IBDMAC_INTE(ch));
1384 if (priv->flags & TSI721_USING_MSIX)
1385 return; /* Finished if we are in MSI-X mode */
1388 * For MSI and INTA interrupt signalling we need to disable next levels
1391 /* Disable Device Channel Interrupt */
1392 rval = ioread32(priv->regs + TSI721_DEV_CHAN_INTE);
1393 rval &= ~TSI721_INT_IMSG_CHAN(ch);
1394 iowrite32(rval, priv->regs + TSI721_DEV_CHAN_INTE);
1397 /* Enable Outbound Messaging interrupts */
1399 tsi721_omsg_interrupt_enable(struct tsi721_device *priv, int ch,
1407 /* Clear pending Outbound Messaging interrupts */
1408 iowrite32(inte_mask, priv->regs + TSI721_OBDMAC_INT(ch));
1410 /* Enable Outbound Messaging channel interrupts */
1411 rval = ioread32(priv->regs + TSI721_OBDMAC_INTE(ch));
1412 iowrite32(rval | inte_mask, priv->regs + TSI721_OBDMAC_INTE(ch));
1414 if (priv->flags & TSI721_USING_MSIX)
1415 return; /* Finished if we are in MSI-X mode */
1418 * For MSI and INTA interrupt signalling we need to enable next levels
1421 /* Enable Device Channel Interrupt */
1422 rval = ioread32(priv->regs + TSI721_DEV_CHAN_INTE);
1423 iowrite32(rval | TSI721_INT_OMSG_CHAN(ch),
1424 priv->regs + TSI721_DEV_CHAN_INTE);
1427 /* Disable Outbound Messaging interrupts */
1429 tsi721_omsg_interrupt_disable(struct tsi721_device *priv, int ch,
1437 /* Clear pending Outbound Messaging interrupts */
1438 iowrite32(inte_mask, priv->regs + TSI721_OBDMAC_INT(ch));
1440 /* Disable Outbound Messaging interrupts */
1441 rval = ioread32(priv->regs + TSI721_OBDMAC_INTE(ch));
1443 iowrite32(rval, priv->regs + TSI721_OBDMAC_INTE(ch));
1445 if (priv->flags & TSI721_USING_MSIX)
1446 return; /* Finished if we are in MSI-X mode */
1449 * For MSI and INTA interrupt signalling we need to disable next levels
1452 /* Disable Device Channel Interrupt */
1453 rval = ioread32(priv->regs + TSI721_DEV_CHAN_INTE);
1454 rval &= ~TSI721_INT_OMSG_CHAN(ch);
1455 iowrite32(rval, priv->regs + TSI721_DEV_CHAN_INTE);
1459 * tsi721_add_outb_message - Add message to the Tsi721 outbound message queue
1460 * @mport: Master port with outbound message queue
1461 * @rdev: Target of outbound message
1462 * @mbox: Outbound mailbox
1463 * @buffer: Message to add to outbound queue
1464 * @len: Length of message
1467 tsi721_add_outb_message(struct rio_mport *mport, struct rio_dev *rdev, int mbox,
1468 void *buffer, size_t len)
1470 struct tsi721_device *priv = mport->priv;
1471 struct tsi721_omsg_desc *desc;
1474 if (!priv->omsg_init[mbox] ||
1475 len > TSI721_MSG_MAX_SIZE || len < 8)
1478 tx_slot = priv->omsg_ring[mbox].tx_slot;
1480 /* Copy copy message into transfer buffer */
1481 memcpy(priv->omsg_ring[mbox].omq_base[tx_slot], buffer, len);
1486 /* Build descriptor associated with buffer */
1487 desc = priv->omsg_ring[mbox].omd_base;
1488 desc[tx_slot].type_id = cpu_to_le32((DTYPE4 << 29) | rdev->destid);
1489 if (tx_slot % 4 == 0)
1490 desc[tx_slot].type_id |= cpu_to_le32(TSI721_OMD_IOF);
1492 desc[tx_slot].msg_info =
1493 cpu_to_le32((mport->sys_size << 26) | (mbox << 22) |
1494 (0xe << 12) | (len & 0xff8));
1495 desc[tx_slot].bufptr_lo =
1496 cpu_to_le32((u64)priv->omsg_ring[mbox].omq_phys[tx_slot] &
1498 desc[tx_slot].bufptr_hi =
1499 cpu_to_le32((u64)priv->omsg_ring[mbox].omq_phys[tx_slot] >> 32);
1501 priv->omsg_ring[mbox].wr_count++;
1503 /* Go to next descriptor */
1504 if (++priv->omsg_ring[mbox].tx_slot == priv->omsg_ring[mbox].size) {
1505 priv->omsg_ring[mbox].tx_slot = 0;
1506 /* Move through the ring link descriptor at the end */
1507 priv->omsg_ring[mbox].wr_count++;
1512 /* Set new write count value */
1513 iowrite32(priv->omsg_ring[mbox].wr_count,
1514 priv->regs + TSI721_OBDMAC_DWRCNT(mbox));
1515 ioread32(priv->regs + TSI721_OBDMAC_DWRCNT(mbox));
1521 * tsi721_omsg_handler - Outbound Message Interrupt Handler
1522 * @priv: pointer to tsi721 private data
1523 * @ch: number of OB MSG channel to service
1525 * Services channel interrupts from outbound messaging engine.
1527 static void tsi721_omsg_handler(struct tsi721_device *priv, int ch)
1530 struct rio_mport *mport = &priv->mport;
1532 spin_lock(&priv->omsg_ring[ch].lock);
1534 omsg_int = ioread32(priv->regs + TSI721_OBDMAC_INT(ch));
1536 if (omsg_int & TSI721_OBDMAC_INT_ST_FULL)
1537 dev_info(&priv->pdev->dev,
1538 "OB MBOX%d: Status FIFO is full\n", ch);
1540 if (omsg_int & (TSI721_OBDMAC_INT_DONE | TSI721_OBDMAC_INT_IOF_DONE)) {
1542 u64 *sts_ptr, last_ptr = 0, prev_ptr = 0;
1547 * Find last successfully processed descriptor
1550 /* Check and clear descriptor status FIFO entries */
1551 srd_ptr = priv->omsg_ring[ch].sts_rdptr;
1552 sts_ptr = priv->omsg_ring[ch].sts_base;
1554 while (sts_ptr[j]) {
1555 for (i = 0; i < 8 && sts_ptr[j]; i++, j++) {
1556 prev_ptr = last_ptr;
1557 last_ptr = le64_to_cpu(sts_ptr[j]);
1562 srd_ptr %= priv->omsg_ring[ch].sts_size;
1569 priv->omsg_ring[ch].sts_rdptr = srd_ptr;
1570 iowrite32(srd_ptr, priv->regs + TSI721_OBDMAC_DSRP(ch));
1572 if (!mport->outb_msg[ch].mcback)
1575 /* Inform upper layer about transfer completion */
1577 tx_slot = (last_ptr - (u64)priv->omsg_ring[ch].omd_phys)/
1578 sizeof(struct tsi721_omsg_desc);
1581 * Check if this is a Link Descriptor (LD).
1582 * If yes, ignore LD and use descriptor processed
1585 if (tx_slot == priv->omsg_ring[ch].size) {
1587 tx_slot = (prev_ptr -
1588 (u64)priv->omsg_ring[ch].omd_phys)/
1589 sizeof(struct tsi721_omsg_desc);
1594 /* Move slot index to the next message to be sent */
1596 if (tx_slot == priv->omsg_ring[ch].size)
1598 BUG_ON(tx_slot >= priv->omsg_ring[ch].size);
1599 mport->outb_msg[ch].mcback(mport,
1600 priv->omsg_ring[ch].dev_id, ch,
1606 if (omsg_int & TSI721_OBDMAC_INT_ERROR) {
1608 * Outbound message operation aborted due to error,
1609 * reinitialize OB MSG channel
1612 dev_dbg(&priv->pdev->dev, "OB MSG ABORT ch_stat=%x\n",
1613 ioread32(priv->regs + TSI721_OBDMAC_STS(ch)));
1615 iowrite32(TSI721_OBDMAC_INT_ERROR,
1616 priv->regs + TSI721_OBDMAC_INT(ch));
1617 iowrite32(TSI721_OBDMAC_CTL_INIT,
1618 priv->regs + TSI721_OBDMAC_CTL(ch));
1619 ioread32(priv->regs + TSI721_OBDMAC_CTL(ch));
1621 /* Inform upper level to clear all pending tx slots */
1622 if (mport->outb_msg[ch].mcback)
1623 mport->outb_msg[ch].mcback(mport,
1624 priv->omsg_ring[ch].dev_id, ch,
1625 priv->omsg_ring[ch].tx_slot);
1626 /* Synch tx_slot tracking */
1627 iowrite32(priv->omsg_ring[ch].tx_slot,
1628 priv->regs + TSI721_OBDMAC_DRDCNT(ch));
1629 ioread32(priv->regs + TSI721_OBDMAC_DRDCNT(ch));
1630 priv->omsg_ring[ch].wr_count = priv->omsg_ring[ch].tx_slot;
1631 priv->omsg_ring[ch].sts_rdptr = 0;
1634 /* Clear channel interrupts */
1635 iowrite32(omsg_int, priv->regs + TSI721_OBDMAC_INT(ch));
1637 if (!(priv->flags & TSI721_USING_MSIX)) {
1640 /* Re-enable channel interrupts */
1641 ch_inte = ioread32(priv->regs + TSI721_DEV_CHAN_INTE);
1642 ch_inte |= TSI721_INT_OMSG_CHAN(ch);
1643 iowrite32(ch_inte, priv->regs + TSI721_DEV_CHAN_INTE);
1646 spin_unlock(&priv->omsg_ring[ch].lock);
1650 * tsi721_open_outb_mbox - Initialize Tsi721 outbound mailbox
1651 * @mport: Master port implementing Outbound Messaging Engine
1652 * @dev_id: Device specific pointer to pass on event
1653 * @mbox: Mailbox to open
1654 * @entries: Number of entries in the outbound mailbox ring
1656 static int tsi721_open_outb_mbox(struct rio_mport *mport, void *dev_id,
1657 int mbox, int entries)
1659 struct tsi721_device *priv = mport->priv;
1660 struct tsi721_omsg_desc *bd_ptr;
1663 if ((entries < TSI721_OMSGD_MIN_RING_SIZE) ||
1664 (entries > (TSI721_OMSGD_RING_SIZE)) ||
1665 (!is_power_of_2(entries)) || mbox >= RIO_MAX_MBOX) {
1670 priv->omsg_ring[mbox].dev_id = dev_id;
1671 priv->omsg_ring[mbox].size = entries;
1672 priv->omsg_ring[mbox].sts_rdptr = 0;
1673 spin_lock_init(&priv->omsg_ring[mbox].lock);
1675 /* Outbound Msg Buffer allocation based on
1676 the number of maximum descriptor entries */
1677 for (i = 0; i < entries; i++) {
1678 priv->omsg_ring[mbox].omq_base[i] =
1680 &priv->pdev->dev, TSI721_MSG_BUFFER_SIZE,
1681 &priv->omsg_ring[mbox].omq_phys[i],
1683 if (priv->omsg_ring[mbox].omq_base[i] == NULL) {
1684 dev_dbg(&priv->pdev->dev,
1685 "Unable to allocate OB MSG data buffer for"
1692 /* Outbound message descriptor allocation */
1693 priv->omsg_ring[mbox].omd_base = dma_alloc_coherent(
1695 (entries + 1) * sizeof(struct tsi721_omsg_desc),
1696 &priv->omsg_ring[mbox].omd_phys, GFP_KERNEL);
1697 if (priv->omsg_ring[mbox].omd_base == NULL) {
1698 dev_dbg(&priv->pdev->dev,
1699 "Unable to allocate OB MSG descriptor memory "
1700 "for MBOX%d\n", mbox);
1705 priv->omsg_ring[mbox].tx_slot = 0;
1707 /* Outbound message descriptor status FIFO allocation */
1708 priv->omsg_ring[mbox].sts_size = roundup_pow_of_two(entries + 1);
1709 priv->omsg_ring[mbox].sts_base = dma_zalloc_coherent(&priv->pdev->dev,
1710 priv->omsg_ring[mbox].sts_size *
1711 sizeof(struct tsi721_dma_sts),
1712 &priv->omsg_ring[mbox].sts_phys, GFP_KERNEL);
1713 if (priv->omsg_ring[mbox].sts_base == NULL) {
1714 dev_dbg(&priv->pdev->dev,
1715 "Unable to allocate OB MSG descriptor status FIFO "
1716 "for MBOX%d\n", mbox);
1722 * Configure Outbound Messaging Engine
1725 /* Setup Outbound Message descriptor pointer */
1726 iowrite32(((u64)priv->omsg_ring[mbox].omd_phys >> 32),
1727 priv->regs + TSI721_OBDMAC_DPTRH(mbox));
1728 iowrite32(((u64)priv->omsg_ring[mbox].omd_phys &
1729 TSI721_OBDMAC_DPTRL_MASK),
1730 priv->regs + TSI721_OBDMAC_DPTRL(mbox));
1732 /* Setup Outbound Message descriptor status FIFO */
1733 iowrite32(((u64)priv->omsg_ring[mbox].sts_phys >> 32),
1734 priv->regs + TSI721_OBDMAC_DSBH(mbox));
1735 iowrite32(((u64)priv->omsg_ring[mbox].sts_phys &
1736 TSI721_OBDMAC_DSBL_MASK),
1737 priv->regs + TSI721_OBDMAC_DSBL(mbox));
1738 iowrite32(TSI721_DMAC_DSSZ_SIZE(priv->omsg_ring[mbox].sts_size),
1739 priv->regs + (u32)TSI721_OBDMAC_DSSZ(mbox));
1741 /* Enable interrupts */
1743 #ifdef CONFIG_PCI_MSI
1744 if (priv->flags & TSI721_USING_MSIX) {
1745 int idx = TSI721_VECT_OMB0_DONE + mbox;
1747 /* Request interrupt service if we are in MSI-X mode */
1748 rc = request_irq(priv->msix[idx].vector, tsi721_omsg_msix, 0,
1749 priv->msix[idx].irq_name, (void *)priv);
1752 dev_dbg(&priv->pdev->dev,
1753 "Unable to allocate MSI-X interrupt for "
1754 "OBOX%d-DONE\n", mbox);
1758 idx = TSI721_VECT_OMB0_INT + mbox;
1759 rc = request_irq(priv->msix[idx].vector, tsi721_omsg_msix, 0,
1760 priv->msix[idx].irq_name, (void *)priv);
1763 dev_dbg(&priv->pdev->dev,
1764 "Unable to allocate MSI-X interrupt for "
1765 "MBOX%d-INT\n", mbox);
1766 idx = TSI721_VECT_OMB0_DONE + mbox;
1767 free_irq(priv->msix[idx].vector, (void *)priv);
1771 #endif /* CONFIG_PCI_MSI */
1773 tsi721_omsg_interrupt_enable(priv, mbox, TSI721_OBDMAC_INT_ALL);
1775 /* Initialize Outbound Message descriptors ring */
1776 bd_ptr = priv->omsg_ring[mbox].omd_base;
1777 bd_ptr[entries].type_id = cpu_to_le32(DTYPE5 << 29);
1778 bd_ptr[entries].msg_info = 0;
1779 bd_ptr[entries].next_lo =
1780 cpu_to_le32((u64)priv->omsg_ring[mbox].omd_phys &
1781 TSI721_OBDMAC_DPTRL_MASK);
1782 bd_ptr[entries].next_hi =
1783 cpu_to_le32((u64)priv->omsg_ring[mbox].omd_phys >> 32);
1784 priv->omsg_ring[mbox].wr_count = 0;
1787 /* Initialize Outbound Message engine */
1788 iowrite32(TSI721_OBDMAC_CTL_INIT, priv->regs + TSI721_OBDMAC_CTL(mbox));
1789 ioread32(priv->regs + TSI721_OBDMAC_DWRCNT(mbox));
1792 priv->omsg_init[mbox] = 1;
1796 #ifdef CONFIG_PCI_MSI
1798 dma_free_coherent(&priv->pdev->dev,
1799 priv->omsg_ring[mbox].sts_size * sizeof(struct tsi721_dma_sts),
1800 priv->omsg_ring[mbox].sts_base,
1801 priv->omsg_ring[mbox].sts_phys);
1803 priv->omsg_ring[mbox].sts_base = NULL;
1804 #endif /* CONFIG_PCI_MSI */
1807 dma_free_coherent(&priv->pdev->dev,
1808 (entries + 1) * sizeof(struct tsi721_omsg_desc),
1809 priv->omsg_ring[mbox].omd_base,
1810 priv->omsg_ring[mbox].omd_phys);
1812 priv->omsg_ring[mbox].omd_base = NULL;
1815 for (i = 0; i < priv->omsg_ring[mbox].size; i++) {
1816 if (priv->omsg_ring[mbox].omq_base[i]) {
1817 dma_free_coherent(&priv->pdev->dev,
1818 TSI721_MSG_BUFFER_SIZE,
1819 priv->omsg_ring[mbox].omq_base[i],
1820 priv->omsg_ring[mbox].omq_phys[i]);
1822 priv->omsg_ring[mbox].omq_base[i] = NULL;
1831 * tsi721_close_outb_mbox - Close Tsi721 outbound mailbox
1832 * @mport: Master port implementing the outbound message unit
1833 * @mbox: Mailbox to close
1835 static void tsi721_close_outb_mbox(struct rio_mport *mport, int mbox)
1837 struct tsi721_device *priv = mport->priv;
1840 if (!priv->omsg_init[mbox])
1842 priv->omsg_init[mbox] = 0;
1844 /* Disable Interrupts */
1846 tsi721_omsg_interrupt_disable(priv, mbox, TSI721_OBDMAC_INT_ALL);
1848 #ifdef CONFIG_PCI_MSI
1849 if (priv->flags & TSI721_USING_MSIX) {
1850 free_irq(priv->msix[TSI721_VECT_OMB0_DONE + mbox].vector,
1852 free_irq(priv->msix[TSI721_VECT_OMB0_INT + mbox].vector,
1855 #endif /* CONFIG_PCI_MSI */
1857 /* Free OMSG Descriptor Status FIFO */
1858 dma_free_coherent(&priv->pdev->dev,
1859 priv->omsg_ring[mbox].sts_size * sizeof(struct tsi721_dma_sts),
1860 priv->omsg_ring[mbox].sts_base,
1861 priv->omsg_ring[mbox].sts_phys);
1863 priv->omsg_ring[mbox].sts_base = NULL;
1865 /* Free OMSG descriptors */
1866 dma_free_coherent(&priv->pdev->dev,
1867 (priv->omsg_ring[mbox].size + 1) *
1868 sizeof(struct tsi721_omsg_desc),
1869 priv->omsg_ring[mbox].omd_base,
1870 priv->omsg_ring[mbox].omd_phys);
1872 priv->omsg_ring[mbox].omd_base = NULL;
1874 /* Free message buffers */
1875 for (i = 0; i < priv->omsg_ring[mbox].size; i++) {
1876 if (priv->omsg_ring[mbox].omq_base[i]) {
1877 dma_free_coherent(&priv->pdev->dev,
1878 TSI721_MSG_BUFFER_SIZE,
1879 priv->omsg_ring[mbox].omq_base[i],
1880 priv->omsg_ring[mbox].omq_phys[i]);
1882 priv->omsg_ring[mbox].omq_base[i] = NULL;
1888 * tsi721_imsg_handler - Inbound Message Interrupt Handler
1889 * @priv: pointer to tsi721 private data
1890 * @ch: inbound message channel number to service
1892 * Services channel interrupts from inbound messaging engine.
1894 static void tsi721_imsg_handler(struct tsi721_device *priv, int ch)
1898 struct rio_mport *mport = &priv->mport;
1900 spin_lock(&priv->imsg_ring[mbox].lock);
1902 imsg_int = ioread32(priv->regs + TSI721_IBDMAC_INT(ch));
1904 if (imsg_int & TSI721_IBDMAC_INT_SRTO)
1905 dev_info(&priv->pdev->dev, "IB MBOX%d SRIO timeout\n",
1908 if (imsg_int & TSI721_IBDMAC_INT_PC_ERROR)
1909 dev_info(&priv->pdev->dev, "IB MBOX%d PCIe error\n",
1912 if (imsg_int & TSI721_IBDMAC_INT_FQ_LOW)
1913 dev_info(&priv->pdev->dev,
1914 "IB MBOX%d IB free queue low\n", mbox);
1916 /* Clear IB channel interrupts */
1917 iowrite32(imsg_int, priv->regs + TSI721_IBDMAC_INT(ch));
1919 /* If an IB Msg is received notify the upper layer */
1920 if (imsg_int & TSI721_IBDMAC_INT_DQ_RCV &&
1921 mport->inb_msg[mbox].mcback)
1922 mport->inb_msg[mbox].mcback(mport,
1923 priv->imsg_ring[mbox].dev_id, mbox, -1);
1925 if (!(priv->flags & TSI721_USING_MSIX)) {
1928 /* Re-enable channel interrupts */
1929 ch_inte = ioread32(priv->regs + TSI721_DEV_CHAN_INTE);
1930 ch_inte |= TSI721_INT_IMSG_CHAN(ch);
1931 iowrite32(ch_inte, priv->regs + TSI721_DEV_CHAN_INTE);
1934 spin_unlock(&priv->imsg_ring[mbox].lock);
1938 * tsi721_open_inb_mbox - Initialize Tsi721 inbound mailbox
1939 * @mport: Master port implementing the Inbound Messaging Engine
1940 * @dev_id: Device specific pointer to pass on event
1941 * @mbox: Mailbox to open
1942 * @entries: Number of entries in the inbound mailbox ring
1944 static int tsi721_open_inb_mbox(struct rio_mport *mport, void *dev_id,
1945 int mbox, int entries)
1947 struct tsi721_device *priv = mport->priv;
1953 if ((entries < TSI721_IMSGD_MIN_RING_SIZE) ||
1954 (entries > TSI721_IMSGD_RING_SIZE) ||
1955 (!is_power_of_2(entries)) || mbox >= RIO_MAX_MBOX) {
1960 /* Initialize IB Messaging Ring */
1961 priv->imsg_ring[mbox].dev_id = dev_id;
1962 priv->imsg_ring[mbox].size = entries;
1963 priv->imsg_ring[mbox].rx_slot = 0;
1964 priv->imsg_ring[mbox].desc_rdptr = 0;
1965 priv->imsg_ring[mbox].fq_wrptr = 0;
1966 for (i = 0; i < priv->imsg_ring[mbox].size; i++)
1967 priv->imsg_ring[mbox].imq_base[i] = NULL;
1968 spin_lock_init(&priv->imsg_ring[mbox].lock);
1970 /* Allocate buffers for incoming messages */
1971 priv->imsg_ring[mbox].buf_base =
1972 dma_alloc_coherent(&priv->pdev->dev,
1973 entries * TSI721_MSG_BUFFER_SIZE,
1974 &priv->imsg_ring[mbox].buf_phys,
1977 if (priv->imsg_ring[mbox].buf_base == NULL) {
1978 dev_err(&priv->pdev->dev,
1979 "Failed to allocate buffers for IB MBOX%d\n", mbox);
1984 /* Allocate memory for circular free list */
1985 priv->imsg_ring[mbox].imfq_base =
1986 dma_alloc_coherent(&priv->pdev->dev,
1988 &priv->imsg_ring[mbox].imfq_phys,
1991 if (priv->imsg_ring[mbox].imfq_base == NULL) {
1992 dev_err(&priv->pdev->dev,
1993 "Failed to allocate free queue for IB MBOX%d\n", mbox);
1998 /* Allocate memory for Inbound message descriptors */
1999 priv->imsg_ring[mbox].imd_base =
2000 dma_alloc_coherent(&priv->pdev->dev,
2001 entries * sizeof(struct tsi721_imsg_desc),
2002 &priv->imsg_ring[mbox].imd_phys, GFP_KERNEL);
2004 if (priv->imsg_ring[mbox].imd_base == NULL) {
2005 dev_err(&priv->pdev->dev,
2006 "Failed to allocate descriptor memory for IB MBOX%d\n",
2012 /* Fill free buffer pointer list */
2013 free_ptr = priv->imsg_ring[mbox].imfq_base;
2014 for (i = 0; i < entries; i++)
2015 free_ptr[i] = cpu_to_le64(
2016 (u64)(priv->imsg_ring[mbox].buf_phys) +
2022 * For mapping of inbound SRIO Messages into appropriate queues we need
2023 * to set Inbound Device ID register in the messaging engine. We do it
2024 * once when first inbound mailbox is requested.
2026 if (!(priv->flags & TSI721_IMSGID_SET)) {
2027 iowrite32((u32)priv->mport.host_deviceid,
2028 priv->regs + TSI721_IB_DEVID);
2029 priv->flags |= TSI721_IMSGID_SET;
2033 * Configure Inbound Messaging channel (ch = mbox + 4)
2036 /* Setup Inbound Message free queue */
2037 iowrite32(((u64)priv->imsg_ring[mbox].imfq_phys >> 32),
2038 priv->regs + TSI721_IBDMAC_FQBH(ch));
2039 iowrite32(((u64)priv->imsg_ring[mbox].imfq_phys &
2040 TSI721_IBDMAC_FQBL_MASK),
2041 priv->regs+TSI721_IBDMAC_FQBL(ch));
2042 iowrite32(TSI721_DMAC_DSSZ_SIZE(entries),
2043 priv->regs + TSI721_IBDMAC_FQSZ(ch));
2045 /* Setup Inbound Message descriptor queue */
2046 iowrite32(((u64)priv->imsg_ring[mbox].imd_phys >> 32),
2047 priv->regs + TSI721_IBDMAC_DQBH(ch));
2048 iowrite32(((u32)priv->imsg_ring[mbox].imd_phys &
2049 (u32)TSI721_IBDMAC_DQBL_MASK),
2050 priv->regs+TSI721_IBDMAC_DQBL(ch));
2051 iowrite32(TSI721_DMAC_DSSZ_SIZE(entries),
2052 priv->regs + TSI721_IBDMAC_DQSZ(ch));
2054 /* Enable interrupts */
2056 #ifdef CONFIG_PCI_MSI
2057 if (priv->flags & TSI721_USING_MSIX) {
2058 int idx = TSI721_VECT_IMB0_RCV + mbox;
2060 /* Request interrupt service if we are in MSI-X mode */
2061 rc = request_irq(priv->msix[idx].vector, tsi721_imsg_msix, 0,
2062 priv->msix[idx].irq_name, (void *)priv);
2065 dev_dbg(&priv->pdev->dev,
2066 "Unable to allocate MSI-X interrupt for "
2067 "IBOX%d-DONE\n", mbox);
2071 idx = TSI721_VECT_IMB0_INT + mbox;
2072 rc = request_irq(priv->msix[idx].vector, tsi721_imsg_msix, 0,
2073 priv->msix[idx].irq_name, (void *)priv);
2076 dev_dbg(&priv->pdev->dev,
2077 "Unable to allocate MSI-X interrupt for "
2078 "IBOX%d-INT\n", mbox);
2080 priv->msix[TSI721_VECT_IMB0_RCV + mbox].vector,
2085 #endif /* CONFIG_PCI_MSI */
2087 tsi721_imsg_interrupt_enable(priv, ch, TSI721_IBDMAC_INT_ALL);
2089 /* Initialize Inbound Message Engine */
2090 iowrite32(TSI721_IBDMAC_CTL_INIT, priv->regs + TSI721_IBDMAC_CTL(ch));
2091 ioread32(priv->regs + TSI721_IBDMAC_CTL(ch));
2093 priv->imsg_ring[mbox].fq_wrptr = entries - 1;
2094 iowrite32(entries - 1, priv->regs + TSI721_IBDMAC_FQWP(ch));
2096 priv->imsg_init[mbox] = 1;
2099 #ifdef CONFIG_PCI_MSI
2101 dma_free_coherent(&priv->pdev->dev,
2102 priv->imsg_ring[mbox].size * sizeof(struct tsi721_imsg_desc),
2103 priv->imsg_ring[mbox].imd_base,
2104 priv->imsg_ring[mbox].imd_phys);
2106 priv->imsg_ring[mbox].imd_base = NULL;
2107 #endif /* CONFIG_PCI_MSI */
2110 dma_free_coherent(&priv->pdev->dev,
2111 priv->imsg_ring[mbox].size * 8,
2112 priv->imsg_ring[mbox].imfq_base,
2113 priv->imsg_ring[mbox].imfq_phys);
2115 priv->imsg_ring[mbox].imfq_base = NULL;
2118 dma_free_coherent(&priv->pdev->dev,
2119 priv->imsg_ring[mbox].size * TSI721_MSG_BUFFER_SIZE,
2120 priv->imsg_ring[mbox].buf_base,
2121 priv->imsg_ring[mbox].buf_phys);
2123 priv->imsg_ring[mbox].buf_base = NULL;
2130 * tsi721_close_inb_mbox - Shut down Tsi721 inbound mailbox
2131 * @mport: Master port implementing the Inbound Messaging Engine
2132 * @mbox: Mailbox to close
2134 static void tsi721_close_inb_mbox(struct rio_mport *mport, int mbox)
2136 struct tsi721_device *priv = mport->priv;
2140 if (!priv->imsg_init[mbox]) /* mbox isn't initialized yet */
2142 priv->imsg_init[mbox] = 0;
2144 /* Disable Inbound Messaging Engine */
2146 /* Disable Interrupts */
2147 tsi721_imsg_interrupt_disable(priv, ch, TSI721_OBDMAC_INT_MASK);
2149 #ifdef CONFIG_PCI_MSI
2150 if (priv->flags & TSI721_USING_MSIX) {
2151 free_irq(priv->msix[TSI721_VECT_IMB0_RCV + mbox].vector,
2153 free_irq(priv->msix[TSI721_VECT_IMB0_INT + mbox].vector,
2156 #endif /* CONFIG_PCI_MSI */
2158 /* Clear Inbound Buffer Queue */
2159 for (rx_slot = 0; rx_slot < priv->imsg_ring[mbox].size; rx_slot++)
2160 priv->imsg_ring[mbox].imq_base[rx_slot] = NULL;
2162 /* Free memory allocated for message buffers */
2163 dma_free_coherent(&priv->pdev->dev,
2164 priv->imsg_ring[mbox].size * TSI721_MSG_BUFFER_SIZE,
2165 priv->imsg_ring[mbox].buf_base,
2166 priv->imsg_ring[mbox].buf_phys);
2168 priv->imsg_ring[mbox].buf_base = NULL;
2170 /* Free memory allocated for free pointr list */
2171 dma_free_coherent(&priv->pdev->dev,
2172 priv->imsg_ring[mbox].size * 8,
2173 priv->imsg_ring[mbox].imfq_base,
2174 priv->imsg_ring[mbox].imfq_phys);
2176 priv->imsg_ring[mbox].imfq_base = NULL;
2178 /* Free memory allocated for RX descriptors */
2179 dma_free_coherent(&priv->pdev->dev,
2180 priv->imsg_ring[mbox].size * sizeof(struct tsi721_imsg_desc),
2181 priv->imsg_ring[mbox].imd_base,
2182 priv->imsg_ring[mbox].imd_phys);
2184 priv->imsg_ring[mbox].imd_base = NULL;
2188 * tsi721_add_inb_buffer - Add buffer to the Tsi721 inbound message queue
2189 * @mport: Master port implementing the Inbound Messaging Engine
2190 * @mbox: Inbound mailbox number
2191 * @buf: Buffer to add to inbound queue
2193 static int tsi721_add_inb_buffer(struct rio_mport *mport, int mbox, void *buf)
2195 struct tsi721_device *priv = mport->priv;
2199 rx_slot = priv->imsg_ring[mbox].rx_slot;
2200 if (priv->imsg_ring[mbox].imq_base[rx_slot]) {
2201 dev_err(&priv->pdev->dev,
2202 "Error adding inbound buffer %d, buffer exists\n",
2208 priv->imsg_ring[mbox].imq_base[rx_slot] = buf;
2210 if (++priv->imsg_ring[mbox].rx_slot == priv->imsg_ring[mbox].size)
2211 priv->imsg_ring[mbox].rx_slot = 0;
2218 * tsi721_get_inb_message - Fetch inbound message from the Tsi721 MSG Queue
2219 * @mport: Master port implementing the Inbound Messaging Engine
2220 * @mbox: Inbound mailbox number
2222 * Returns pointer to the message on success or NULL on failure.
2224 static void *tsi721_get_inb_message(struct rio_mport *mport, int mbox)
2226 struct tsi721_device *priv = mport->priv;
2227 struct tsi721_imsg_desc *desc;
2229 void *rx_virt = NULL;
2236 if (!priv->imsg_init[mbox])
2239 desc = priv->imsg_ring[mbox].imd_base;
2240 desc += priv->imsg_ring[mbox].desc_rdptr;
2242 if (!(le32_to_cpu(desc->msg_info) & TSI721_IMD_HO))
2245 rx_slot = priv->imsg_ring[mbox].rx_slot;
2246 while (priv->imsg_ring[mbox].imq_base[rx_slot] == NULL) {
2247 if (++rx_slot == priv->imsg_ring[mbox].size)
2251 rx_phys = ((u64)le32_to_cpu(desc->bufptr_hi) << 32) |
2252 le32_to_cpu(desc->bufptr_lo);
2254 rx_virt = priv->imsg_ring[mbox].buf_base +
2255 (rx_phys - (u64)priv->imsg_ring[mbox].buf_phys);
2257 buf = priv->imsg_ring[mbox].imq_base[rx_slot];
2258 msg_size = le32_to_cpu(desc->msg_info) & TSI721_IMD_BCOUNT;
2260 msg_size = RIO_MAX_MSG_SIZE;
2262 memcpy(buf, rx_virt, msg_size);
2263 priv->imsg_ring[mbox].imq_base[rx_slot] = NULL;
2265 desc->msg_info &= cpu_to_le32(~TSI721_IMD_HO);
2266 if (++priv->imsg_ring[mbox].desc_rdptr == priv->imsg_ring[mbox].size)
2267 priv->imsg_ring[mbox].desc_rdptr = 0;
2269 iowrite32(priv->imsg_ring[mbox].desc_rdptr,
2270 priv->regs + TSI721_IBDMAC_DQRP(ch));
2272 /* Return free buffer into the pointer list */
2273 free_ptr = priv->imsg_ring[mbox].imfq_base;
2274 free_ptr[priv->imsg_ring[mbox].fq_wrptr] = cpu_to_le64(rx_phys);
2276 if (++priv->imsg_ring[mbox].fq_wrptr == priv->imsg_ring[mbox].size)
2277 priv->imsg_ring[mbox].fq_wrptr = 0;
2279 iowrite32(priv->imsg_ring[mbox].fq_wrptr,
2280 priv->regs + TSI721_IBDMAC_FQWP(ch));
2286 * tsi721_messages_init - Initialization of Messaging Engine
2287 * @priv: pointer to tsi721 private data
2289 * Configures Tsi721 messaging engine.
2291 static int tsi721_messages_init(struct tsi721_device *priv)
2295 iowrite32(0, priv->regs + TSI721_SMSG_ECC_LOG);
2296 iowrite32(0, priv->regs + TSI721_RETRY_GEN_CNT);
2297 iowrite32(0, priv->regs + TSI721_RETRY_RX_CNT);
2299 /* Set SRIO Message Request/Response Timeout */
2300 iowrite32(TSI721_RQRPTO_VAL, priv->regs + TSI721_RQRPTO);
2302 /* Initialize Inbound Messaging Engine Registers */
2303 for (ch = 0; ch < TSI721_IMSG_CHNUM; ch++) {
2304 /* Clear interrupt bits */
2305 iowrite32(TSI721_IBDMAC_INT_MASK,
2306 priv->regs + TSI721_IBDMAC_INT(ch));
2308 iowrite32(0, priv->regs + TSI721_IBDMAC_STS(ch));
2310 iowrite32(TSI721_SMSG_ECC_COR_LOG_MASK,
2311 priv->regs + TSI721_SMSG_ECC_COR_LOG(ch));
2312 iowrite32(TSI721_SMSG_ECC_NCOR_MASK,
2313 priv->regs + TSI721_SMSG_ECC_NCOR(ch));
2320 * tsi721_query_mport - Fetch inbound message from the Tsi721 MSG Queue
2321 * @mport: Master port implementing the Inbound Messaging Engine
2322 * @mbox: Inbound mailbox number
2324 * Returns pointer to the message on success or NULL on failure.
2326 static int tsi721_query_mport(struct rio_mport *mport,
2327 struct rio_mport_attr *attr)
2329 struct tsi721_device *priv = mport->priv;
2332 rval = ioread32(priv->regs + (0x100 + RIO_PORT_N_ERR_STS_CSR(0)));
2333 if (rval & RIO_PORT_N_ERR_STS_PORT_OK) {
2334 rval = ioread32(priv->regs + (0x100 + RIO_PORT_N_CTL2_CSR(0)));
2335 attr->link_speed = (rval & RIO_PORT_N_CTL2_SEL_BAUD) >> 28;
2336 rval = ioread32(priv->regs + (0x100 + RIO_PORT_N_CTL_CSR(0)));
2337 attr->link_width = (rval & RIO_PORT_N_CTL_IPW) >> 27;
2339 attr->link_speed = RIO_LINK_DOWN;
2341 #ifdef CONFIG_RAPIDIO_DMA_ENGINE
2342 attr->flags = RIO_MPORT_DMA | RIO_MPORT_DMA_SG;
2343 attr->dma_max_sge = 0;
2344 attr->dma_max_size = TSI721_BDMA_MAX_BCOUNT;
2345 attr->dma_align = 0;
2353 * tsi721_disable_ints - disables all device interrupts
2354 * @priv: pointer to tsi721 private data
2356 static void tsi721_disable_ints(struct tsi721_device *priv)
2360 /* Disable all device level interrupts */
2361 iowrite32(0, priv->regs + TSI721_DEV_INTE);
2363 /* Disable all Device Channel interrupts */
2364 iowrite32(0, priv->regs + TSI721_DEV_CHAN_INTE);
2366 /* Disable all Inbound Msg Channel interrupts */
2367 for (ch = 0; ch < TSI721_IMSG_CHNUM; ch++)
2368 iowrite32(0, priv->regs + TSI721_IBDMAC_INTE(ch));
2370 /* Disable all Outbound Msg Channel interrupts */
2371 for (ch = 0; ch < TSI721_OMSG_CHNUM; ch++)
2372 iowrite32(0, priv->regs + TSI721_OBDMAC_INTE(ch));
2374 /* Disable all general messaging interrupts */
2375 iowrite32(0, priv->regs + TSI721_SMSG_INTE);
2377 /* Disable all BDMA Channel interrupts */
2378 for (ch = 0; ch < TSI721_DMA_MAXCH; ch++)
2380 priv->regs + TSI721_DMAC_BASE(ch) + TSI721_DMAC_INTE);
2382 /* Disable all general BDMA interrupts */
2383 iowrite32(0, priv->regs + TSI721_BDMA_INTE);
2385 /* Disable all SRIO Channel interrupts */
2386 for (ch = 0; ch < TSI721_SRIO_MAXCH; ch++)
2387 iowrite32(0, priv->regs + TSI721_SR_CHINTE(ch));
2389 /* Disable all general SR2PC interrupts */
2390 iowrite32(0, priv->regs + TSI721_SR2PC_GEN_INTE);
2392 /* Disable all PC2SR interrupts */
2393 iowrite32(0, priv->regs + TSI721_PC2SR_INTE);
2395 /* Disable all I2C interrupts */
2396 iowrite32(0, priv->regs + TSI721_I2C_INT_ENABLE);
2398 /* Disable SRIO MAC interrupts */
2399 iowrite32(0, priv->regs + TSI721_RIO_EM_INT_ENABLE);
2400 iowrite32(0, priv->regs + TSI721_RIO_EM_DEV_INT_EN);
2403 static struct rio_ops tsi721_rio_ops = {
2404 .lcread = tsi721_lcread,
2405 .lcwrite = tsi721_lcwrite,
2406 .cread = tsi721_cread_dma,
2407 .cwrite = tsi721_cwrite_dma,
2408 .dsend = tsi721_dsend,
2409 .open_inb_mbox = tsi721_open_inb_mbox,
2410 .close_inb_mbox = tsi721_close_inb_mbox,
2411 .open_outb_mbox = tsi721_open_outb_mbox,
2412 .close_outb_mbox = tsi721_close_outb_mbox,
2413 .add_outb_message = tsi721_add_outb_message,
2414 .add_inb_buffer = tsi721_add_inb_buffer,
2415 .get_inb_message = tsi721_get_inb_message,
2416 .map_inb = tsi721_rio_map_inb_mem,
2417 .unmap_inb = tsi721_rio_unmap_inb_mem,
2418 .pwenable = tsi721_pw_enable,
2419 .query_mport = tsi721_query_mport,
2422 static void tsi721_mport_release(struct device *dev)
2424 struct rio_mport *mport = to_rio_mport(dev);
2426 dev_dbg(dev, "RIO: %s %s id=%d\n", __func__, mport->name, mport->id);
2430 * tsi721_setup_mport - Setup Tsi721 as RapidIO subsystem master port
2431 * @priv: pointer to tsi721 private data
2433 * Configures Tsi721 as RapidIO master port.
2435 static int tsi721_setup_mport(struct tsi721_device *priv)
2437 struct pci_dev *pdev = priv->pdev;
2439 struct rio_mport *mport = &priv->mport;
2441 err = rio_mport_initialize(mport);
2445 mport->ops = &tsi721_rio_ops;
2447 mport->sys_size = 0; /* small system */
2448 mport->phy_type = RIO_PHY_SERIAL;
2449 mport->priv = (void *)priv;
2450 mport->phys_efptr = 0x100;
2451 mport->dev.parent = &pdev->dev;
2452 mport->dev.release = tsi721_mport_release;
2454 INIT_LIST_HEAD(&mport->dbells);
2456 rio_init_dbell_res(&mport->riores[RIO_DOORBELL_RESOURCE], 0, 0xffff);
2457 rio_init_mbox_res(&mport->riores[RIO_INB_MBOX_RESOURCE], 0, 3);
2458 rio_init_mbox_res(&mport->riores[RIO_OUTB_MBOX_RESOURCE], 0, 3);
2459 snprintf(mport->name, RIO_MAX_MPORT_NAME, "%s(%s)",
2460 dev_driver_string(&pdev->dev), dev_name(&pdev->dev));
2462 /* Hook up interrupt handler */
2464 #ifdef CONFIG_PCI_MSI
2465 if (!tsi721_enable_msix(priv))
2466 priv->flags |= TSI721_USING_MSIX;
2467 else if (!pci_enable_msi(pdev))
2468 priv->flags |= TSI721_USING_MSI;
2470 dev_info(&pdev->dev,
2471 "MSI/MSI-X is not available. Using legacy INTx.\n");
2472 #endif /* CONFIG_PCI_MSI */
2474 err = tsi721_request_irq(priv);
2477 dev_err(&pdev->dev, "Unable to get assigned PCI IRQ "
2478 "vector %02X err=0x%x\n", pdev->irq, err);
2482 #ifdef CONFIG_RAPIDIO_DMA_ENGINE
2483 err = tsi721_register_dma(priv);
2487 /* Enable SRIO link */
2488 iowrite32(ioread32(priv->regs + TSI721_DEVCTL) |
2489 TSI721_DEVCTL_SRBOOT_CMPL,
2490 priv->regs + TSI721_DEVCTL);
2492 if (mport->host_deviceid >= 0)
2493 iowrite32(RIO_PORT_GEN_HOST | RIO_PORT_GEN_MASTER |
2494 RIO_PORT_GEN_DISCOVERED,
2495 priv->regs + (0x100 + RIO_PORT_GEN_CTL_CSR));
2497 iowrite32(0, priv->regs + (0x100 + RIO_PORT_GEN_CTL_CSR));
2499 err = rio_register_mport(mport);
2501 tsi721_unregister_dma(priv);
2508 tsi721_free_irq(priv);
2512 static int tsi721_probe(struct pci_dev *pdev,
2513 const struct pci_device_id *id)
2515 struct tsi721_device *priv;
2518 priv = kzalloc(sizeof(struct tsi721_device), GFP_KERNEL);
2520 dev_err(&pdev->dev, "Failed to allocate memory for device\n");
2525 err = pci_enable_device(pdev);
2527 dev_err(&pdev->dev, "Failed to enable PCI device\n");
2536 for (i = 0; i <= PCI_STD_RESOURCE_END; i++) {
2537 dev_dbg(&pdev->dev, "res[%d] @ 0x%llx (0x%lx, 0x%lx)\n",
2538 i, (unsigned long long)pci_resource_start(pdev, i),
2539 (unsigned long)pci_resource_len(pdev, i),
2540 pci_resource_flags(pdev, i));
2545 * Verify BAR configuration
2548 /* BAR_0 (registers) must be 512KB+ in 32-bit address space */
2549 if (!(pci_resource_flags(pdev, BAR_0) & IORESOURCE_MEM) ||
2550 pci_resource_flags(pdev, BAR_0) & IORESOURCE_MEM_64 ||
2551 pci_resource_len(pdev, BAR_0) < TSI721_REG_SPACE_SIZE) {
2553 "Missing or misconfigured CSR BAR0, aborting.\n");
2555 goto err_disable_pdev;
2558 /* BAR_1 (outbound doorbells) must be 16MB+ in 32-bit address space */
2559 if (!(pci_resource_flags(pdev, BAR_1) & IORESOURCE_MEM) ||
2560 pci_resource_flags(pdev, BAR_1) & IORESOURCE_MEM_64 ||
2561 pci_resource_len(pdev, BAR_1) < TSI721_DB_WIN_SIZE) {
2563 "Missing or misconfigured Doorbell BAR1, aborting.\n");
2565 goto err_disable_pdev;
2569 * BAR_2 and BAR_4 (outbound translation) must be in 64-bit PCIe address
2571 * NOTE: BAR_2 and BAR_4 are not used by this version of driver.
2572 * It may be a good idea to keep them disabled using HW configuration
2573 * to save PCI memory space.
2575 if ((pci_resource_flags(pdev, BAR_2) & IORESOURCE_MEM) &&
2576 (pci_resource_flags(pdev, BAR_2) & IORESOURCE_MEM_64)) {
2577 dev_info(&pdev->dev, "Outbound BAR2 is not used but enabled.\n");
2580 if ((pci_resource_flags(pdev, BAR_4) & IORESOURCE_MEM) &&
2581 (pci_resource_flags(pdev, BAR_4) & IORESOURCE_MEM_64)) {
2582 dev_info(&pdev->dev, "Outbound BAR4 is not used but enabled.\n");
2585 err = pci_request_regions(pdev, DRV_NAME);
2587 dev_err(&pdev->dev, "Cannot obtain PCI resources, "
2589 goto err_disable_pdev;
2592 pci_set_master(pdev);
2594 priv->regs = pci_ioremap_bar(pdev, BAR_0);
2597 "Unable to map device registers space, aborting\n");
2602 priv->odb_base = pci_ioremap_bar(pdev, BAR_1);
2603 if (!priv->odb_base) {
2605 "Unable to map outbound doorbells space, aborting\n");
2607 goto err_unmap_bars;
2610 /* Configure DMA attributes. */
2611 if (pci_set_dma_mask(pdev, DMA_BIT_MASK(64))) {
2612 err = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
2614 dev_info(&pdev->dev, "Unable to set DMA mask\n");
2615 goto err_unmap_bars;
2618 if (pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32)))
2619 dev_info(&pdev->dev, "Unable to set consistent DMA mask\n");
2621 err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64));
2623 dev_info(&pdev->dev, "Unable to set consistent DMA mask\n");
2626 BUG_ON(!pci_is_pcie(pdev));
2628 /* Clear "no snoop" and "relaxed ordering" bits. */
2629 pcie_capability_clear_and_set_word(pdev, PCI_EXP_DEVCTL,
2630 PCI_EXP_DEVCTL_RELAX_EN | PCI_EXP_DEVCTL_NOSNOOP_EN, 0);
2632 /* Adjust PCIe completion timeout. */
2633 pcie_capability_clear_and_set_word(pdev, PCI_EXP_DEVCTL2, 0xf, 0x2);
2636 * FIXUP: correct offsets of MSI-X tables in the MSI-X Capability Block
2638 pci_write_config_dword(pdev, TSI721_PCIECFG_EPCTL, 0x01);
2639 pci_write_config_dword(pdev, TSI721_PCIECFG_MSIXTBL,
2640 TSI721_MSIXTBL_OFFSET);
2641 pci_write_config_dword(pdev, TSI721_PCIECFG_MSIXPBA,
2642 TSI721_MSIXPBA_OFFSET);
2643 pci_write_config_dword(pdev, TSI721_PCIECFG_EPCTL, 0);
2646 tsi721_disable_ints(priv);
2648 tsi721_init_pc2sr_mapping(priv);
2649 tsi721_init_sr2pc_mapping(priv);
2651 if (tsi721_bdma_maint_init(priv)) {
2652 dev_err(&pdev->dev, "BDMA initialization failed, aborting\n");
2654 goto err_unmap_bars;
2657 err = tsi721_doorbell_init(priv);
2661 tsi721_port_write_init(priv);
2663 err = tsi721_messages_init(priv);
2665 goto err_free_consistent;
2667 err = tsi721_setup_mport(priv);
2669 goto err_free_consistent;
2671 pci_set_drvdata(pdev, priv);
2672 tsi721_interrupts_init(priv);
2676 err_free_consistent:
2677 tsi721_port_write_free(priv);
2678 tsi721_doorbell_free(priv);
2680 tsi721_bdma_maint_free(priv);
2683 iounmap(priv->regs);
2685 iounmap(priv->odb_base);
2687 pci_release_regions(pdev);
2688 pci_clear_master(pdev);
2690 pci_disable_device(pdev);
2697 static void tsi721_remove(struct pci_dev *pdev)
2699 struct tsi721_device *priv = pci_get_drvdata(pdev);
2701 dev_dbg(&pdev->dev, "%s enter\n", __func__);
2703 tsi721_disable_ints(priv);
2704 tsi721_free_irq(priv);
2705 rio_unregister_mport(&priv->mport);
2707 tsi721_unregister_dma(priv);
2708 tsi721_bdma_maint_free(priv);
2709 tsi721_doorbell_free(priv);
2710 tsi721_port_write_free(priv);
2711 tsi721_close_sr2pc_mapping(priv);
2714 iounmap(priv->regs);
2716 iounmap(priv->odb_base);
2717 #ifdef CONFIG_PCI_MSI
2718 if (priv->flags & TSI721_USING_MSIX)
2719 pci_disable_msix(priv->pdev);
2720 else if (priv->flags & TSI721_USING_MSI)
2721 pci_disable_msi(priv->pdev);
2723 pci_release_regions(pdev);
2724 pci_clear_master(pdev);
2725 pci_disable_device(pdev);
2726 pci_set_drvdata(pdev, NULL);
2728 dev_dbg(&pdev->dev, "%s exit\n", __func__);
2731 static void tsi721_shutdown(struct pci_dev *pdev)
2733 struct tsi721_device *priv = pci_get_drvdata(pdev);
2735 dev_dbg(&pdev->dev, "RIO: %s\n", __func__);
2737 tsi721_disable_ints(priv);
2738 tsi721_dma_stop_all(priv);
2739 pci_clear_master(pdev);
2740 pci_disable_device(pdev);
2743 static const struct pci_device_id tsi721_pci_tbl[] = {
2744 { PCI_DEVICE(PCI_VENDOR_ID_IDT, PCI_DEVICE_ID_TSI721) },
2745 { 0, } /* terminate list */
2748 MODULE_DEVICE_TABLE(pci, tsi721_pci_tbl);
2750 static struct pci_driver tsi721_driver = {
2752 .id_table = tsi721_pci_tbl,
2753 .probe = tsi721_probe,
2754 .remove = tsi721_remove,
2755 .shutdown = tsi721_shutdown,
2758 module_pci_driver(tsi721_driver);
2760 MODULE_DESCRIPTION("IDT Tsi721 PCIExpress-to-SRIO bridge driver");
2761 MODULE_AUTHOR("Integrated Device Technology, Inc.");
2762 MODULE_LICENSE("GPL");