Matt Porter | 2b0c28d7f | 2005-11-07 01:00:19 -0800 | [diff] [blame] | 1 | /* |
Zhang Wei | d02443a | 2008-04-18 13:33:38 -0700 | [diff] [blame] | 2 | * Freescale MPC85xx/MPC86xx RapidIO support |
Matt Porter | 2b0c28d7f | 2005-11-07 01:00:19 -0800 | [diff] [blame] | 3 | * |
Zhang Wei | ad1e938 | 2008-04-18 13:33:41 -0700 | [diff] [blame] | 4 | * Copyright (C) 2007, 2008 Freescale Semiconductor, Inc. |
| 5 | * Zhang Wei <wei.zhang@freescale.com> |
| 6 | * |
Matt Porter | 2b0c28d7f | 2005-11-07 01:00:19 -0800 | [diff] [blame] | 7 | * Copyright 2005 MontaVista Software, Inc. |
| 8 | * Matt Porter <mporter@kernel.crashing.org> |
| 9 | * |
| 10 | * This program is free software; you can redistribute it and/or modify it |
| 11 | * under the terms of the GNU General Public License as published by the |
| 12 | * Free Software Foundation; either version 2 of the License, or (at your |
| 13 | * option) any later version. |
| 14 | */ |
| 15 | |
Matt Porter | 2b0c28d7f | 2005-11-07 01:00:19 -0800 | [diff] [blame] | 16 | #include <linux/init.h> |
| 17 | #include <linux/module.h> |
| 18 | #include <linux/types.h> |
| 19 | #include <linux/dma-mapping.h> |
| 20 | #include <linux/interrupt.h> |
| 21 | #include <linux/rio.h> |
| 22 | #include <linux/rio_drv.h> |
Zhang Wei | cc2bb69 | 2008-04-18 13:33:41 -0700 | [diff] [blame] | 23 | #include <linux/of_platform.h> |
Zhang Wei | 61b2691 | 2008-04-18 13:33:44 -0700 | [diff] [blame] | 24 | #include <linux/delay.h> |
Matt Porter | 2b0c28d7f | 2005-11-07 01:00:19 -0800 | [diff] [blame] | 25 | |
| 26 | #include <asm/io.h> |
| 27 | |
Zhang Wei | ad1e938 | 2008-04-18 13:33:41 -0700 | [diff] [blame] | 28 | /* RapidIO definition irq, which read from OF-tree */ |
| 29 | #define IRQ_RIO_BELL(m) (((struct rio_priv *)(m->priv))->bellirq) |
| 30 | #define IRQ_RIO_TX(m) (((struct rio_priv *)(m->priv))->txirq) |
| 31 | #define IRQ_RIO_RX(m) (((struct rio_priv *)(m->priv))->rxirq) |
| 32 | |
Matt Porter | 2b0c28d7f | 2005-11-07 01:00:19 -0800 | [diff] [blame] | 33 | #define RIO_ATMU_REGS_OFFSET 0x10c00 |
Zhang Wei | 61b2691 | 2008-04-18 13:33:44 -0700 | [diff] [blame] | 34 | #define RIO_P_MSG_REGS_OFFSET 0x11000 |
| 35 | #define RIO_S_MSG_REGS_OFFSET 0x13000 |
| 36 | #define RIO_ESCSR 0x158 |
| 37 | #define RIO_CCSR 0x15c |
| 38 | #define RIO_ISR_AACR 0x10120 |
| 39 | #define RIO_ISR_AACR_AA 0x1 /* Accept All ID */ |
Matt Porter | 2b0c28d7f | 2005-11-07 01:00:19 -0800 | [diff] [blame] | 40 | #define RIO_MAINT_WIN_SIZE 0x400000 |
| 41 | #define RIO_DBELL_WIN_SIZE 0x1000 |
| 42 | |
| 43 | #define RIO_MSG_OMR_MUI 0x00000002 |
| 44 | #define RIO_MSG_OSR_TE 0x00000080 |
| 45 | #define RIO_MSG_OSR_QOI 0x00000020 |
| 46 | #define RIO_MSG_OSR_QFI 0x00000010 |
| 47 | #define RIO_MSG_OSR_MUB 0x00000004 |
| 48 | #define RIO_MSG_OSR_EOMI 0x00000002 |
| 49 | #define RIO_MSG_OSR_QEI 0x00000001 |
| 50 | |
| 51 | #define RIO_MSG_IMR_MI 0x00000002 |
| 52 | #define RIO_MSG_ISR_TE 0x00000080 |
| 53 | #define RIO_MSG_ISR_QFI 0x00000010 |
| 54 | #define RIO_MSG_ISR_DIQI 0x00000001 |
| 55 | |
| 56 | #define RIO_MSG_DESC_SIZE 32 |
| 57 | #define RIO_MSG_BUFFER_SIZE 4096 |
| 58 | #define RIO_MIN_TX_RING_SIZE 2 |
| 59 | #define RIO_MAX_TX_RING_SIZE 2048 |
| 60 | #define RIO_MIN_RX_RING_SIZE 2 |
| 61 | #define RIO_MAX_RX_RING_SIZE 2048 |
| 62 | |
| 63 | #define DOORBELL_DMR_DI 0x00000002 |
| 64 | #define DOORBELL_DSR_TE 0x00000080 |
| 65 | #define DOORBELL_DSR_QFI 0x00000010 |
| 66 | #define DOORBELL_DSR_DIQI 0x00000001 |
Zhang Wei | 6c39103 | 2008-04-18 13:33:48 -0700 | [diff] [blame^] | 67 | #define DOORBELL_TID_OFFSET 0x02 |
| 68 | #define DOORBELL_SID_OFFSET 0x04 |
Matt Porter | 2b0c28d7f | 2005-11-07 01:00:19 -0800 | [diff] [blame] | 69 | #define DOORBELL_INFO_OFFSET 0x06 |
| 70 | |
| 71 | #define DOORBELL_MESSAGE_SIZE 0x08 |
Zhang Wei | 6c39103 | 2008-04-18 13:33:48 -0700 | [diff] [blame^] | 72 | #define DBELL_SID(x) (*(u16 *)(x + DOORBELL_SID_OFFSET)) |
| 73 | #define DBELL_TID(x) (*(u16 *)(x + DOORBELL_TID_OFFSET)) |
Matt Porter | 2b0c28d7f | 2005-11-07 01:00:19 -0800 | [diff] [blame] | 74 | #define DBELL_INF(x) (*(u16 *)(x + DOORBELL_INFO_OFFSET)) |
| 75 | |
Matt Porter | 2b0c28d7f | 2005-11-07 01:00:19 -0800 | [diff] [blame] | 76 | struct rio_atmu_regs { |
| 77 | u32 rowtar; |
Zhang Wei | 61b2691 | 2008-04-18 13:33:44 -0700 | [diff] [blame] | 78 | u32 rowtear; |
Matt Porter | 2b0c28d7f | 2005-11-07 01:00:19 -0800 | [diff] [blame] | 79 | u32 rowbar; |
| 80 | u32 pad2; |
| 81 | u32 rowar; |
| 82 | u32 pad3[3]; |
| 83 | }; |
| 84 | |
| 85 | struct rio_msg_regs { |
| 86 | u32 omr; |
| 87 | u32 osr; |
| 88 | u32 pad1; |
| 89 | u32 odqdpar; |
| 90 | u32 pad2; |
| 91 | u32 osar; |
| 92 | u32 odpr; |
| 93 | u32 odatr; |
| 94 | u32 odcr; |
| 95 | u32 pad3; |
| 96 | u32 odqepar; |
| 97 | u32 pad4[13]; |
| 98 | u32 imr; |
| 99 | u32 isr; |
| 100 | u32 pad5; |
| 101 | u32 ifqdpar; |
| 102 | u32 pad6; |
| 103 | u32 ifqepar; |
Zhang Wei | 61b2691 | 2008-04-18 13:33:44 -0700 | [diff] [blame] | 104 | u32 pad7[226]; |
| 105 | u32 odmr; |
| 106 | u32 odsr; |
| 107 | u32 res0[4]; |
| 108 | u32 oddpr; |
| 109 | u32 oddatr; |
| 110 | u32 res1[3]; |
| 111 | u32 odretcr; |
| 112 | u32 res2[12]; |
Matt Porter | 2b0c28d7f | 2005-11-07 01:00:19 -0800 | [diff] [blame] | 113 | u32 dmr; |
| 114 | u32 dsr; |
| 115 | u32 pad8; |
| 116 | u32 dqdpar; |
| 117 | u32 pad9; |
| 118 | u32 dqepar; |
| 119 | u32 pad10[26]; |
| 120 | u32 pwmr; |
| 121 | u32 pwsr; |
| 122 | u32 pad11; |
| 123 | u32 pwqbar; |
| 124 | }; |
| 125 | |
| 126 | struct rio_tx_desc { |
| 127 | u32 res1; |
| 128 | u32 saddr; |
| 129 | u32 dport; |
| 130 | u32 dattr; |
| 131 | u32 res2; |
| 132 | u32 res3; |
| 133 | u32 dwcnt; |
| 134 | u32 res4; |
| 135 | }; |
| 136 | |
Zhang Wei | ad1e938 | 2008-04-18 13:33:41 -0700 | [diff] [blame] | 137 | struct rio_dbell_ring { |
Matt Porter | 2b0c28d7f | 2005-11-07 01:00:19 -0800 | [diff] [blame] | 138 | void *virt; |
| 139 | dma_addr_t phys; |
Zhang Wei | ad1e938 | 2008-04-18 13:33:41 -0700 | [diff] [blame] | 140 | }; |
Matt Porter | 2b0c28d7f | 2005-11-07 01:00:19 -0800 | [diff] [blame] | 141 | |
Zhang Wei | ad1e938 | 2008-04-18 13:33:41 -0700 | [diff] [blame] | 142 | struct rio_msg_tx_ring { |
Matt Porter | 2b0c28d7f | 2005-11-07 01:00:19 -0800 | [diff] [blame] | 143 | void *virt; |
| 144 | dma_addr_t phys; |
| 145 | void *virt_buffer[RIO_MAX_TX_RING_SIZE]; |
| 146 | dma_addr_t phys_buffer[RIO_MAX_TX_RING_SIZE]; |
| 147 | int tx_slot; |
| 148 | int size; |
Matt Porter | 6978bbc | 2005-11-07 01:00:20 -0800 | [diff] [blame] | 149 | void *dev_id; |
Zhang Wei | ad1e938 | 2008-04-18 13:33:41 -0700 | [diff] [blame] | 150 | }; |
Matt Porter | 2b0c28d7f | 2005-11-07 01:00:19 -0800 | [diff] [blame] | 151 | |
Zhang Wei | ad1e938 | 2008-04-18 13:33:41 -0700 | [diff] [blame] | 152 | struct rio_msg_rx_ring { |
Matt Porter | 2b0c28d7f | 2005-11-07 01:00:19 -0800 | [diff] [blame] | 153 | void *virt; |
| 154 | dma_addr_t phys; |
| 155 | void *virt_buffer[RIO_MAX_RX_RING_SIZE]; |
| 156 | int rx_slot; |
| 157 | int size; |
Matt Porter | 6978bbc | 2005-11-07 01:00:20 -0800 | [diff] [blame] | 158 | void *dev_id; |
Zhang Wei | ad1e938 | 2008-04-18 13:33:41 -0700 | [diff] [blame] | 159 | }; |
| 160 | |
| 161 | struct rio_priv { |
| 162 | void __iomem *regs_win; |
| 163 | struct rio_atmu_regs __iomem *atmu_regs; |
| 164 | struct rio_atmu_regs __iomem *maint_atmu_regs; |
| 165 | struct rio_atmu_regs __iomem *dbell_atmu_regs; |
| 166 | void __iomem *dbell_win; |
| 167 | void __iomem *maint_win; |
| 168 | struct rio_msg_regs __iomem *msg_regs; |
| 169 | struct rio_dbell_ring dbell_ring; |
| 170 | struct rio_msg_tx_ring msg_tx_ring; |
| 171 | struct rio_msg_rx_ring msg_rx_ring; |
| 172 | int bellirq; |
| 173 | int txirq; |
| 174 | int rxirq; |
| 175 | }; |
Matt Porter | 2b0c28d7f | 2005-11-07 01:00:19 -0800 | [diff] [blame] | 176 | |
| 177 | /** |
Zhang Wei | d02443a | 2008-04-18 13:33:38 -0700 | [diff] [blame] | 178 | * fsl_rio_doorbell_send - Send a MPC85xx doorbell message |
Matt Porter | 2b0c28d7f | 2005-11-07 01:00:19 -0800 | [diff] [blame] | 179 | * @index: ID of RapidIO interface |
| 180 | * @destid: Destination ID of target device |
| 181 | * @data: 16-bit info field of RapidIO doorbell message |
| 182 | * |
| 183 | * Sends a MPC85xx doorbell message. Returns %0 on success or |
| 184 | * %-EINVAL on failure. |
| 185 | */ |
Zhang Wei | ad1e938 | 2008-04-18 13:33:41 -0700 | [diff] [blame] | 186 | static int fsl_rio_doorbell_send(struct rio_mport *mport, |
| 187 | int index, u16 destid, u16 data) |
Matt Porter | 2b0c28d7f | 2005-11-07 01:00:19 -0800 | [diff] [blame] | 188 | { |
Zhang Wei | ad1e938 | 2008-04-18 13:33:41 -0700 | [diff] [blame] | 189 | struct rio_priv *priv = mport->priv; |
Zhang Wei | d02443a | 2008-04-18 13:33:38 -0700 | [diff] [blame] | 190 | pr_debug("fsl_doorbell_send: index %d destid %4.4x data %4.4x\n", |
Matt Porter | 2b0c28d7f | 2005-11-07 01:00:19 -0800 | [diff] [blame] | 191 | index, destid, data); |
Zhang Wei | 61b2691 | 2008-04-18 13:33:44 -0700 | [diff] [blame] | 192 | switch (mport->phy_type) { |
| 193 | case RIO_PHY_PARALLEL: |
| 194 | out_be32(&priv->dbell_atmu_regs->rowtar, destid << 22); |
| 195 | out_be16(priv->dbell_win, data); |
| 196 | break; |
| 197 | case RIO_PHY_SERIAL: |
| 198 | /* In the serial version silicons, such as MPC8548, MPC8641, |
| 199 | * below operations is must be. |
| 200 | */ |
| 201 | out_be32(&priv->msg_regs->odmr, 0x00000000); |
| 202 | out_be32(&priv->msg_regs->odretcr, 0x00000004); |
| 203 | out_be32(&priv->msg_regs->oddpr, destid << 16); |
| 204 | out_be32(&priv->msg_regs->oddatr, data); |
| 205 | out_be32(&priv->msg_regs->odmr, 0x00000001); |
| 206 | break; |
| 207 | } |
Matt Porter | 2b0c28d7f | 2005-11-07 01:00:19 -0800 | [diff] [blame] | 208 | |
| 209 | return 0; |
| 210 | } |
| 211 | |
| 212 | /** |
Zhang Wei | d02443a | 2008-04-18 13:33:38 -0700 | [diff] [blame] | 213 | * fsl_local_config_read - Generate a MPC85xx local config space read |
Matt Porter | 2b0c28d7f | 2005-11-07 01:00:19 -0800 | [diff] [blame] | 214 | * @index: ID of RapdiIO interface |
| 215 | * @offset: Offset into configuration space |
| 216 | * @len: Length (in bytes) of the maintenance transaction |
| 217 | * @data: Value to be read into |
| 218 | * |
| 219 | * Generates a MPC85xx local configuration space read. Returns %0 on |
| 220 | * success or %-EINVAL on failure. |
| 221 | */ |
Zhang Wei | ad1e938 | 2008-04-18 13:33:41 -0700 | [diff] [blame] | 222 | static int fsl_local_config_read(struct rio_mport *mport, |
| 223 | int index, u32 offset, int len, u32 *data) |
Matt Porter | 2b0c28d7f | 2005-11-07 01:00:19 -0800 | [diff] [blame] | 224 | { |
Zhang Wei | ad1e938 | 2008-04-18 13:33:41 -0700 | [diff] [blame] | 225 | struct rio_priv *priv = mport->priv; |
Zhang Wei | d02443a | 2008-04-18 13:33:38 -0700 | [diff] [blame] | 226 | pr_debug("fsl_local_config_read: index %d offset %8.8x\n", index, |
Matt Porter | 2b0c28d7f | 2005-11-07 01:00:19 -0800 | [diff] [blame] | 227 | offset); |
Zhang Wei | ad1e938 | 2008-04-18 13:33:41 -0700 | [diff] [blame] | 228 | *data = in_be32(priv->regs_win + offset); |
Matt Porter | 2b0c28d7f | 2005-11-07 01:00:19 -0800 | [diff] [blame] | 229 | |
| 230 | return 0; |
| 231 | } |
| 232 | |
| 233 | /** |
Zhang Wei | d02443a | 2008-04-18 13:33:38 -0700 | [diff] [blame] | 234 | * fsl_local_config_write - Generate a MPC85xx local config space write |
Matt Porter | 2b0c28d7f | 2005-11-07 01:00:19 -0800 | [diff] [blame] | 235 | * @index: ID of RapdiIO interface |
| 236 | * @offset: Offset into configuration space |
| 237 | * @len: Length (in bytes) of the maintenance transaction |
| 238 | * @data: Value to be written |
| 239 | * |
| 240 | * Generates a MPC85xx local configuration space write. Returns %0 on |
| 241 | * success or %-EINVAL on failure. |
| 242 | */ |
Zhang Wei | ad1e938 | 2008-04-18 13:33:41 -0700 | [diff] [blame] | 243 | static int fsl_local_config_write(struct rio_mport *mport, |
| 244 | int index, u32 offset, int len, u32 data) |
Matt Porter | 2b0c28d7f | 2005-11-07 01:00:19 -0800 | [diff] [blame] | 245 | { |
Zhang Wei | ad1e938 | 2008-04-18 13:33:41 -0700 | [diff] [blame] | 246 | struct rio_priv *priv = mport->priv; |
Matt Porter | 2b0c28d7f | 2005-11-07 01:00:19 -0800 | [diff] [blame] | 247 | pr_debug |
Zhang Wei | d02443a | 2008-04-18 13:33:38 -0700 | [diff] [blame] | 248 | ("fsl_local_config_write: index %d offset %8.8x data %8.8x\n", |
Matt Porter | 2b0c28d7f | 2005-11-07 01:00:19 -0800 | [diff] [blame] | 249 | index, offset, data); |
Zhang Wei | ad1e938 | 2008-04-18 13:33:41 -0700 | [diff] [blame] | 250 | out_be32(priv->regs_win + offset, data); |
Matt Porter | 2b0c28d7f | 2005-11-07 01:00:19 -0800 | [diff] [blame] | 251 | |
| 252 | return 0; |
| 253 | } |
| 254 | |
| 255 | /** |
Zhang Wei | d02443a | 2008-04-18 13:33:38 -0700 | [diff] [blame] | 256 | * fsl_rio_config_read - Generate a MPC85xx read maintenance transaction |
Matt Porter | 2b0c28d7f | 2005-11-07 01:00:19 -0800 | [diff] [blame] | 257 | * @index: ID of RapdiIO interface |
| 258 | * @destid: Destination ID of transaction |
| 259 | * @hopcount: Number of hops to target device |
| 260 | * @offset: Offset into configuration space |
| 261 | * @len: Length (in bytes) of the maintenance transaction |
| 262 | * @val: Location to be read into |
| 263 | * |
| 264 | * Generates a MPC85xx read maintenance transaction. Returns %0 on |
| 265 | * success or %-EINVAL on failure. |
| 266 | */ |
| 267 | static int |
Zhang Wei | ad1e938 | 2008-04-18 13:33:41 -0700 | [diff] [blame] | 268 | fsl_rio_config_read(struct rio_mport *mport, int index, u16 destid, |
| 269 | u8 hopcount, u32 offset, int len, u32 *val) |
Matt Porter | 2b0c28d7f | 2005-11-07 01:00:19 -0800 | [diff] [blame] | 270 | { |
Zhang Wei | ad1e938 | 2008-04-18 13:33:41 -0700 | [diff] [blame] | 271 | struct rio_priv *priv = mport->priv; |
Matt Porter | 2b0c28d7f | 2005-11-07 01:00:19 -0800 | [diff] [blame] | 272 | u8 *data; |
| 273 | |
| 274 | pr_debug |
Zhang Wei | d02443a | 2008-04-18 13:33:38 -0700 | [diff] [blame] | 275 | ("fsl_rio_config_read: index %d destid %d hopcount %d offset %8.8x len %d\n", |
Matt Porter | 2b0c28d7f | 2005-11-07 01:00:19 -0800 | [diff] [blame] | 276 | index, destid, hopcount, offset, len); |
Zhang Wei | ad1e938 | 2008-04-18 13:33:41 -0700 | [diff] [blame] | 277 | out_be32(&priv->maint_atmu_regs->rowtar, |
Matt Porter | 2b0c28d7f | 2005-11-07 01:00:19 -0800 | [diff] [blame] | 278 | (destid << 22) | (hopcount << 12) | ((offset & ~0x3) >> 9)); |
| 279 | |
Zhang Wei | ad1e938 | 2008-04-18 13:33:41 -0700 | [diff] [blame] | 280 | data = (u8 *) priv->maint_win + offset; |
Matt Porter | 2b0c28d7f | 2005-11-07 01:00:19 -0800 | [diff] [blame] | 281 | switch (len) { |
| 282 | case 1: |
| 283 | *val = in_8((u8 *) data); |
| 284 | break; |
| 285 | case 2: |
| 286 | *val = in_be16((u16 *) data); |
| 287 | break; |
| 288 | default: |
| 289 | *val = in_be32((u32 *) data); |
| 290 | break; |
| 291 | } |
| 292 | |
| 293 | return 0; |
| 294 | } |
| 295 | |
| 296 | /** |
Zhang Wei | d02443a | 2008-04-18 13:33:38 -0700 | [diff] [blame] | 297 | * fsl_rio_config_write - Generate a MPC85xx write maintenance transaction |
Matt Porter | 2b0c28d7f | 2005-11-07 01:00:19 -0800 | [diff] [blame] | 298 | * @index: ID of RapdiIO interface |
| 299 | * @destid: Destination ID of transaction |
| 300 | * @hopcount: Number of hops to target device |
| 301 | * @offset: Offset into configuration space |
| 302 | * @len: Length (in bytes) of the maintenance transaction |
| 303 | * @val: Value to be written |
| 304 | * |
| 305 | * Generates an MPC85xx write maintenance transaction. Returns %0 on |
| 306 | * success or %-EINVAL on failure. |
| 307 | */ |
| 308 | static int |
Zhang Wei | ad1e938 | 2008-04-18 13:33:41 -0700 | [diff] [blame] | 309 | fsl_rio_config_write(struct rio_mport *mport, int index, u16 destid, |
| 310 | u8 hopcount, u32 offset, int len, u32 val) |
Matt Porter | 2b0c28d7f | 2005-11-07 01:00:19 -0800 | [diff] [blame] | 311 | { |
Zhang Wei | ad1e938 | 2008-04-18 13:33:41 -0700 | [diff] [blame] | 312 | struct rio_priv *priv = mport->priv; |
Matt Porter | 2b0c28d7f | 2005-11-07 01:00:19 -0800 | [diff] [blame] | 313 | u8 *data; |
| 314 | pr_debug |
Zhang Wei | d02443a | 2008-04-18 13:33:38 -0700 | [diff] [blame] | 315 | ("fsl_rio_config_write: index %d destid %d hopcount %d offset %8.8x len %d val %8.8x\n", |
Matt Porter | 2b0c28d7f | 2005-11-07 01:00:19 -0800 | [diff] [blame] | 316 | index, destid, hopcount, offset, len, val); |
Zhang Wei | ad1e938 | 2008-04-18 13:33:41 -0700 | [diff] [blame] | 317 | out_be32(&priv->maint_atmu_regs->rowtar, |
Matt Porter | 2b0c28d7f | 2005-11-07 01:00:19 -0800 | [diff] [blame] | 318 | (destid << 22) | (hopcount << 12) | ((offset & ~0x3) >> 9)); |
| 319 | |
Zhang Wei | ad1e938 | 2008-04-18 13:33:41 -0700 | [diff] [blame] | 320 | data = (u8 *) priv->maint_win + offset; |
Matt Porter | 2b0c28d7f | 2005-11-07 01:00:19 -0800 | [diff] [blame] | 321 | switch (len) { |
| 322 | case 1: |
| 323 | out_8((u8 *) data, val); |
| 324 | break; |
| 325 | case 2: |
| 326 | out_be16((u16 *) data, val); |
| 327 | break; |
| 328 | default: |
| 329 | out_be32((u32 *) data, val); |
| 330 | break; |
| 331 | } |
| 332 | |
| 333 | return 0; |
| 334 | } |
| 335 | |
| 336 | /** |
| 337 | * rio_hw_add_outb_message - Add message to the MPC85xx outbound message queue |
| 338 | * @mport: Master port with outbound message queue |
| 339 | * @rdev: Target of outbound message |
| 340 | * @mbox: Outbound mailbox |
| 341 | * @buffer: Message to add to outbound queue |
| 342 | * @len: Length of message |
| 343 | * |
| 344 | * Adds the @buffer message to the MPC85xx outbound message queue. Returns |
| 345 | * %0 on success or %-EINVAL on failure. |
| 346 | */ |
| 347 | int |
| 348 | rio_hw_add_outb_message(struct rio_mport *mport, struct rio_dev *rdev, int mbox, |
| 349 | void *buffer, size_t len) |
| 350 | { |
Zhang Wei | ad1e938 | 2008-04-18 13:33:41 -0700 | [diff] [blame] | 351 | struct rio_priv *priv = mport->priv; |
Matt Porter | 2b0c28d7f | 2005-11-07 01:00:19 -0800 | [diff] [blame] | 352 | u32 omr; |
Zhang Wei | ad1e938 | 2008-04-18 13:33:41 -0700 | [diff] [blame] | 353 | struct rio_tx_desc *desc = (struct rio_tx_desc *)priv->msg_tx_ring.virt |
| 354 | + priv->msg_tx_ring.tx_slot; |
Matt Porter | 2b0c28d7f | 2005-11-07 01:00:19 -0800 | [diff] [blame] | 355 | int ret = 0; |
| 356 | |
| 357 | pr_debug |
| 358 | ("RIO: rio_hw_add_outb_message(): destid %4.4x mbox %d buffer %8.8x len %8.8x\n", |
| 359 | rdev->destid, mbox, (int)buffer, len); |
| 360 | |
| 361 | if ((len < 8) || (len > RIO_MAX_MSG_SIZE)) { |
| 362 | ret = -EINVAL; |
| 363 | goto out; |
| 364 | } |
| 365 | |
| 366 | /* Copy and clear rest of buffer */ |
Zhang Wei | ad1e938 | 2008-04-18 13:33:41 -0700 | [diff] [blame] | 367 | memcpy(priv->msg_tx_ring.virt_buffer[priv->msg_tx_ring.tx_slot], buffer, |
| 368 | len); |
Matt Porter | 2b0c28d7f | 2005-11-07 01:00:19 -0800 | [diff] [blame] | 369 | if (len < (RIO_MAX_MSG_SIZE - 4)) |
Zhang Wei | ad1e938 | 2008-04-18 13:33:41 -0700 | [diff] [blame] | 370 | memset(priv->msg_tx_ring.virt_buffer[priv->msg_tx_ring.tx_slot] |
| 371 | + len, 0, RIO_MAX_MSG_SIZE - len); |
Matt Porter | 2b0c28d7f | 2005-11-07 01:00:19 -0800 | [diff] [blame] | 372 | |
Zhang Wei | 61b2691 | 2008-04-18 13:33:44 -0700 | [diff] [blame] | 373 | switch (mport->phy_type) { |
| 374 | case RIO_PHY_PARALLEL: |
| 375 | /* Set mbox field for message */ |
| 376 | desc->dport = mbox & 0x3; |
Matt Porter | 2b0c28d7f | 2005-11-07 01:00:19 -0800 | [diff] [blame] | 377 | |
Zhang Wei | 61b2691 | 2008-04-18 13:33:44 -0700 | [diff] [blame] | 378 | /* Enable EOMI interrupt, set priority, and set destid */ |
| 379 | desc->dattr = 0x28000000 | (rdev->destid << 2); |
| 380 | break; |
| 381 | case RIO_PHY_SERIAL: |
| 382 | /* Set mbox field for message, and set destid */ |
| 383 | desc->dport = (rdev->destid << 16) | (mbox & 0x3); |
| 384 | |
| 385 | /* Enable EOMI interrupt and priority */ |
| 386 | desc->dattr = 0x28000000; |
| 387 | break; |
| 388 | } |
Matt Porter | 2b0c28d7f | 2005-11-07 01:00:19 -0800 | [diff] [blame] | 389 | |
| 390 | /* Set transfer size aligned to next power of 2 (in double words) */ |
| 391 | desc->dwcnt = is_power_of_2(len) ? len : 1 << get_bitmask_order(len); |
| 392 | |
| 393 | /* Set snooping and source buffer address */ |
Zhang Wei | ad1e938 | 2008-04-18 13:33:41 -0700 | [diff] [blame] | 394 | desc->saddr = 0x00000004 |
| 395 | | priv->msg_tx_ring.phys_buffer[priv->msg_tx_ring.tx_slot]; |
Matt Porter | 2b0c28d7f | 2005-11-07 01:00:19 -0800 | [diff] [blame] | 396 | |
| 397 | /* Increment enqueue pointer */ |
Zhang Wei | ad1e938 | 2008-04-18 13:33:41 -0700 | [diff] [blame] | 398 | omr = in_be32(&priv->msg_regs->omr); |
| 399 | out_be32(&priv->msg_regs->omr, omr | RIO_MSG_OMR_MUI); |
Matt Porter | 2b0c28d7f | 2005-11-07 01:00:19 -0800 | [diff] [blame] | 400 | |
| 401 | /* Go to next descriptor */ |
Zhang Wei | ad1e938 | 2008-04-18 13:33:41 -0700 | [diff] [blame] | 402 | if (++priv->msg_tx_ring.tx_slot == priv->msg_tx_ring.size) |
| 403 | priv->msg_tx_ring.tx_slot = 0; |
Matt Porter | 2b0c28d7f | 2005-11-07 01:00:19 -0800 | [diff] [blame] | 404 | |
| 405 | out: |
| 406 | return ret; |
| 407 | } |
| 408 | |
| 409 | EXPORT_SYMBOL_GPL(rio_hw_add_outb_message); |
| 410 | |
| 411 | /** |
Zhang Wei | d02443a | 2008-04-18 13:33:38 -0700 | [diff] [blame] | 412 | * fsl_rio_tx_handler - MPC85xx outbound message interrupt handler |
Matt Porter | 2b0c28d7f | 2005-11-07 01:00:19 -0800 | [diff] [blame] | 413 | * @irq: Linux interrupt number |
| 414 | * @dev_instance: Pointer to interrupt-specific data |
Matt Porter | 2b0c28d7f | 2005-11-07 01:00:19 -0800 | [diff] [blame] | 415 | * |
| 416 | * Handles outbound message interrupts. Executes a register outbound |
Simon Arlott | a8de5ce | 2007-05-12 05:42:54 +1000 | [diff] [blame] | 417 | * mailbox event handler and acks the interrupt occurrence. |
Matt Porter | 2b0c28d7f | 2005-11-07 01:00:19 -0800 | [diff] [blame] | 418 | */ |
| 419 | static irqreturn_t |
Zhang Wei | d02443a | 2008-04-18 13:33:38 -0700 | [diff] [blame] | 420 | fsl_rio_tx_handler(int irq, void *dev_instance) |
Matt Porter | 2b0c28d7f | 2005-11-07 01:00:19 -0800 | [diff] [blame] | 421 | { |
| 422 | int osr; |
| 423 | struct rio_mport *port = (struct rio_mport *)dev_instance; |
Zhang Wei | ad1e938 | 2008-04-18 13:33:41 -0700 | [diff] [blame] | 424 | struct rio_priv *priv = port->priv; |
Matt Porter | 2b0c28d7f | 2005-11-07 01:00:19 -0800 | [diff] [blame] | 425 | |
Zhang Wei | ad1e938 | 2008-04-18 13:33:41 -0700 | [diff] [blame] | 426 | osr = in_be32(&priv->msg_regs->osr); |
Matt Porter | 2b0c28d7f | 2005-11-07 01:00:19 -0800 | [diff] [blame] | 427 | |
| 428 | if (osr & RIO_MSG_OSR_TE) { |
| 429 | pr_info("RIO: outbound message transmission error\n"); |
Zhang Wei | ad1e938 | 2008-04-18 13:33:41 -0700 | [diff] [blame] | 430 | out_be32(&priv->msg_regs->osr, RIO_MSG_OSR_TE); |
Matt Porter | 2b0c28d7f | 2005-11-07 01:00:19 -0800 | [diff] [blame] | 431 | goto out; |
| 432 | } |
| 433 | |
| 434 | if (osr & RIO_MSG_OSR_QOI) { |
| 435 | pr_info("RIO: outbound message queue overflow\n"); |
Zhang Wei | ad1e938 | 2008-04-18 13:33:41 -0700 | [diff] [blame] | 436 | out_be32(&priv->msg_regs->osr, RIO_MSG_OSR_QOI); |
Matt Porter | 2b0c28d7f | 2005-11-07 01:00:19 -0800 | [diff] [blame] | 437 | goto out; |
| 438 | } |
| 439 | |
| 440 | if (osr & RIO_MSG_OSR_EOMI) { |
Zhang Wei | ad1e938 | 2008-04-18 13:33:41 -0700 | [diff] [blame] | 441 | u32 dqp = in_be32(&priv->msg_regs->odqdpar); |
| 442 | int slot = (dqp - priv->msg_tx_ring.phys) >> 5; |
| 443 | port->outb_msg[0].mcback(port, priv->msg_tx_ring.dev_id, -1, |
| 444 | slot); |
Matt Porter | 2b0c28d7f | 2005-11-07 01:00:19 -0800 | [diff] [blame] | 445 | |
| 446 | /* Ack the end-of-message interrupt */ |
Zhang Wei | ad1e938 | 2008-04-18 13:33:41 -0700 | [diff] [blame] | 447 | out_be32(&priv->msg_regs->osr, RIO_MSG_OSR_EOMI); |
Matt Porter | 2b0c28d7f | 2005-11-07 01:00:19 -0800 | [diff] [blame] | 448 | } |
| 449 | |
| 450 | out: |
| 451 | return IRQ_HANDLED; |
| 452 | } |
| 453 | |
| 454 | /** |
| 455 | * rio_open_outb_mbox - Initialize MPC85xx outbound mailbox |
| 456 | * @mport: Master port implementing the outbound message unit |
Matt Porter | 6978bbc | 2005-11-07 01:00:20 -0800 | [diff] [blame] | 457 | * @dev_id: Device specific pointer to pass on event |
Matt Porter | 2b0c28d7f | 2005-11-07 01:00:19 -0800 | [diff] [blame] | 458 | * @mbox: Mailbox to open |
| 459 | * @entries: Number of entries in the outbound mailbox ring |
| 460 | * |
| 461 | * Initializes buffer ring, request the outbound message interrupt, |
| 462 | * and enables the outbound message unit. Returns %0 on success and |
| 463 | * %-EINVAL or %-ENOMEM on failure. |
| 464 | */ |
Matt Porter | 6978bbc | 2005-11-07 01:00:20 -0800 | [diff] [blame] | 465 | int rio_open_outb_mbox(struct rio_mport *mport, void *dev_id, int mbox, int entries) |
Matt Porter | 2b0c28d7f | 2005-11-07 01:00:19 -0800 | [diff] [blame] | 466 | { |
| 467 | int i, j, rc = 0; |
Zhang Wei | ad1e938 | 2008-04-18 13:33:41 -0700 | [diff] [blame] | 468 | struct rio_priv *priv = mport->priv; |
Matt Porter | 2b0c28d7f | 2005-11-07 01:00:19 -0800 | [diff] [blame] | 469 | |
| 470 | if ((entries < RIO_MIN_TX_RING_SIZE) || |
| 471 | (entries > RIO_MAX_TX_RING_SIZE) || (!is_power_of_2(entries))) { |
| 472 | rc = -EINVAL; |
| 473 | goto out; |
| 474 | } |
| 475 | |
| 476 | /* Initialize shadow copy ring */ |
Zhang Wei | ad1e938 | 2008-04-18 13:33:41 -0700 | [diff] [blame] | 477 | priv->msg_tx_ring.dev_id = dev_id; |
| 478 | priv->msg_tx_ring.size = entries; |
Matt Porter | 2b0c28d7f | 2005-11-07 01:00:19 -0800 | [diff] [blame] | 479 | |
Zhang Wei | ad1e938 | 2008-04-18 13:33:41 -0700 | [diff] [blame] | 480 | for (i = 0; i < priv->msg_tx_ring.size; i++) { |
| 481 | priv->msg_tx_ring.virt_buffer[i] = |
| 482 | dma_alloc_coherent(NULL, RIO_MSG_BUFFER_SIZE, |
| 483 | &priv->msg_tx_ring.phys_buffer[i], GFP_KERNEL); |
| 484 | if (!priv->msg_tx_ring.virt_buffer[i]) { |
Matt Porter | 2b0c28d7f | 2005-11-07 01:00:19 -0800 | [diff] [blame] | 485 | rc = -ENOMEM; |
Zhang Wei | ad1e938 | 2008-04-18 13:33:41 -0700 | [diff] [blame] | 486 | for (j = 0; j < priv->msg_tx_ring.size; j++) |
| 487 | if (priv->msg_tx_ring.virt_buffer[j]) |
Matt Porter | 2b0c28d7f | 2005-11-07 01:00:19 -0800 | [diff] [blame] | 488 | dma_free_coherent(NULL, |
Zhang Wei | ad1e938 | 2008-04-18 13:33:41 -0700 | [diff] [blame] | 489 | RIO_MSG_BUFFER_SIZE, |
| 490 | priv->msg_tx_ring. |
| 491 | virt_buffer[j], |
| 492 | priv->msg_tx_ring. |
| 493 | phys_buffer[j]); |
Matt Porter | 2b0c28d7f | 2005-11-07 01:00:19 -0800 | [diff] [blame] | 494 | goto out; |
| 495 | } |
| 496 | } |
| 497 | |
| 498 | /* Initialize outbound message descriptor ring */ |
Zhang Wei | ad1e938 | 2008-04-18 13:33:41 -0700 | [diff] [blame] | 499 | priv->msg_tx_ring.virt = dma_alloc_coherent(NULL, |
| 500 | priv->msg_tx_ring.size * RIO_MSG_DESC_SIZE, |
| 501 | &priv->msg_tx_ring.phys, GFP_KERNEL); |
| 502 | if (!priv->msg_tx_ring.virt) { |
Matt Porter | 2b0c28d7f | 2005-11-07 01:00:19 -0800 | [diff] [blame] | 503 | rc = -ENOMEM; |
| 504 | goto out_dma; |
| 505 | } |
Zhang Wei | ad1e938 | 2008-04-18 13:33:41 -0700 | [diff] [blame] | 506 | memset(priv->msg_tx_ring.virt, 0, |
| 507 | priv->msg_tx_ring.size * RIO_MSG_DESC_SIZE); |
| 508 | priv->msg_tx_ring.tx_slot = 0; |
Matt Porter | 2b0c28d7f | 2005-11-07 01:00:19 -0800 | [diff] [blame] | 509 | |
| 510 | /* Point dequeue/enqueue pointers at first entry in ring */ |
Zhang Wei | ad1e938 | 2008-04-18 13:33:41 -0700 | [diff] [blame] | 511 | out_be32(&priv->msg_regs->odqdpar, priv->msg_tx_ring.phys); |
| 512 | out_be32(&priv->msg_regs->odqepar, priv->msg_tx_ring.phys); |
Matt Porter | 2b0c28d7f | 2005-11-07 01:00:19 -0800 | [diff] [blame] | 513 | |
| 514 | /* Configure for snooping */ |
Zhang Wei | ad1e938 | 2008-04-18 13:33:41 -0700 | [diff] [blame] | 515 | out_be32(&priv->msg_regs->osar, 0x00000004); |
Matt Porter | 2b0c28d7f | 2005-11-07 01:00:19 -0800 | [diff] [blame] | 516 | |
| 517 | /* Clear interrupt status */ |
Zhang Wei | ad1e938 | 2008-04-18 13:33:41 -0700 | [diff] [blame] | 518 | out_be32(&priv->msg_regs->osr, 0x000000b3); |
Matt Porter | 2b0c28d7f | 2005-11-07 01:00:19 -0800 | [diff] [blame] | 519 | |
| 520 | /* Hook up outbound message handler */ |
Zhang Wei | ad1e938 | 2008-04-18 13:33:41 -0700 | [diff] [blame] | 521 | rc = request_irq(IRQ_RIO_TX(mport), fsl_rio_tx_handler, 0, |
| 522 | "msg_tx", (void *)mport); |
| 523 | if (rc < 0) |
Matt Porter | 2b0c28d7f | 2005-11-07 01:00:19 -0800 | [diff] [blame] | 524 | goto out_irq; |
| 525 | |
| 526 | /* |
| 527 | * Configure outbound message unit |
| 528 | * Snooping |
| 529 | * Interrupts (all enabled, except QEIE) |
| 530 | * Chaining mode |
| 531 | * Disable |
| 532 | */ |
Zhang Wei | ad1e938 | 2008-04-18 13:33:41 -0700 | [diff] [blame] | 533 | out_be32(&priv->msg_regs->omr, 0x00100220); |
Matt Porter | 2b0c28d7f | 2005-11-07 01:00:19 -0800 | [diff] [blame] | 534 | |
| 535 | /* Set number of entries */ |
Zhang Wei | ad1e938 | 2008-04-18 13:33:41 -0700 | [diff] [blame] | 536 | out_be32(&priv->msg_regs->omr, |
| 537 | in_be32(&priv->msg_regs->omr) | |
Matt Porter | 2b0c28d7f | 2005-11-07 01:00:19 -0800 | [diff] [blame] | 538 | ((get_bitmask_order(entries) - 2) << 12)); |
| 539 | |
| 540 | /* Now enable the unit */ |
Zhang Wei | ad1e938 | 2008-04-18 13:33:41 -0700 | [diff] [blame] | 541 | out_be32(&priv->msg_regs->omr, in_be32(&priv->msg_regs->omr) | 0x1); |
Matt Porter | 2b0c28d7f | 2005-11-07 01:00:19 -0800 | [diff] [blame] | 542 | |
| 543 | out: |
| 544 | return rc; |
| 545 | |
| 546 | out_irq: |
Zhang Wei | ad1e938 | 2008-04-18 13:33:41 -0700 | [diff] [blame] | 547 | dma_free_coherent(NULL, priv->msg_tx_ring.size * RIO_MSG_DESC_SIZE, |
| 548 | priv->msg_tx_ring.virt, priv->msg_tx_ring.phys); |
Matt Porter | 2b0c28d7f | 2005-11-07 01:00:19 -0800 | [diff] [blame] | 549 | |
| 550 | out_dma: |
Zhang Wei | ad1e938 | 2008-04-18 13:33:41 -0700 | [diff] [blame] | 551 | for (i = 0; i < priv->msg_tx_ring.size; i++) |
Matt Porter | 2b0c28d7f | 2005-11-07 01:00:19 -0800 | [diff] [blame] | 552 | dma_free_coherent(NULL, RIO_MSG_BUFFER_SIZE, |
Zhang Wei | ad1e938 | 2008-04-18 13:33:41 -0700 | [diff] [blame] | 553 | priv->msg_tx_ring.virt_buffer[i], |
| 554 | priv->msg_tx_ring.phys_buffer[i]); |
Matt Porter | 2b0c28d7f | 2005-11-07 01:00:19 -0800 | [diff] [blame] | 555 | |
| 556 | return rc; |
| 557 | } |
| 558 | |
| 559 | /** |
| 560 | * rio_close_outb_mbox - Shut down MPC85xx outbound mailbox |
| 561 | * @mport: Master port implementing the outbound message unit |
| 562 | * @mbox: Mailbox to close |
| 563 | * |
| 564 | * Disables the outbound message unit, free all buffers, and |
| 565 | * frees the outbound message interrupt. |
| 566 | */ |
| 567 | void rio_close_outb_mbox(struct rio_mport *mport, int mbox) |
| 568 | { |
Zhang Wei | ad1e938 | 2008-04-18 13:33:41 -0700 | [diff] [blame] | 569 | struct rio_priv *priv = mport->priv; |
Matt Porter | 2b0c28d7f | 2005-11-07 01:00:19 -0800 | [diff] [blame] | 570 | /* Disable inbound message unit */ |
Zhang Wei | ad1e938 | 2008-04-18 13:33:41 -0700 | [diff] [blame] | 571 | out_be32(&priv->msg_regs->omr, 0); |
Matt Porter | 2b0c28d7f | 2005-11-07 01:00:19 -0800 | [diff] [blame] | 572 | |
| 573 | /* Free ring */ |
Zhang Wei | ad1e938 | 2008-04-18 13:33:41 -0700 | [diff] [blame] | 574 | dma_free_coherent(NULL, priv->msg_tx_ring.size * RIO_MSG_DESC_SIZE, |
| 575 | priv->msg_tx_ring.virt, priv->msg_tx_ring.phys); |
Matt Porter | 2b0c28d7f | 2005-11-07 01:00:19 -0800 | [diff] [blame] | 576 | |
| 577 | /* Free interrupt */ |
Zhang Wei | ad1e938 | 2008-04-18 13:33:41 -0700 | [diff] [blame] | 578 | free_irq(IRQ_RIO_TX(mport), (void *)mport); |
Matt Porter | 2b0c28d7f | 2005-11-07 01:00:19 -0800 | [diff] [blame] | 579 | } |
| 580 | |
| 581 | /** |
Zhang Wei | d02443a | 2008-04-18 13:33:38 -0700 | [diff] [blame] | 582 | * fsl_rio_rx_handler - MPC85xx inbound message interrupt handler |
Matt Porter | 2b0c28d7f | 2005-11-07 01:00:19 -0800 | [diff] [blame] | 583 | * @irq: Linux interrupt number |
| 584 | * @dev_instance: Pointer to interrupt-specific data |
Matt Porter | 2b0c28d7f | 2005-11-07 01:00:19 -0800 | [diff] [blame] | 585 | * |
| 586 | * Handles inbound message interrupts. Executes a registered inbound |
Simon Arlott | a8de5ce | 2007-05-12 05:42:54 +1000 | [diff] [blame] | 587 | * mailbox event handler and acks the interrupt occurrence. |
Matt Porter | 2b0c28d7f | 2005-11-07 01:00:19 -0800 | [diff] [blame] | 588 | */ |
| 589 | static irqreturn_t |
Zhang Wei | d02443a | 2008-04-18 13:33:38 -0700 | [diff] [blame] | 590 | fsl_rio_rx_handler(int irq, void *dev_instance) |
Matt Porter | 2b0c28d7f | 2005-11-07 01:00:19 -0800 | [diff] [blame] | 591 | { |
| 592 | int isr; |
| 593 | struct rio_mport *port = (struct rio_mport *)dev_instance; |
Zhang Wei | ad1e938 | 2008-04-18 13:33:41 -0700 | [diff] [blame] | 594 | struct rio_priv *priv = port->priv; |
Matt Porter | 2b0c28d7f | 2005-11-07 01:00:19 -0800 | [diff] [blame] | 595 | |
Zhang Wei | ad1e938 | 2008-04-18 13:33:41 -0700 | [diff] [blame] | 596 | isr = in_be32(&priv->msg_regs->isr); |
Matt Porter | 2b0c28d7f | 2005-11-07 01:00:19 -0800 | [diff] [blame] | 597 | |
| 598 | if (isr & RIO_MSG_ISR_TE) { |
| 599 | pr_info("RIO: inbound message reception error\n"); |
Zhang Wei | ad1e938 | 2008-04-18 13:33:41 -0700 | [diff] [blame] | 600 | out_be32((void *)&priv->msg_regs->isr, RIO_MSG_ISR_TE); |
Matt Porter | 2b0c28d7f | 2005-11-07 01:00:19 -0800 | [diff] [blame] | 601 | goto out; |
| 602 | } |
| 603 | |
| 604 | /* XXX Need to check/dispatch until queue empty */ |
| 605 | if (isr & RIO_MSG_ISR_DIQI) { |
| 606 | /* |
| 607 | * We implement *only* mailbox 0, but can receive messages |
| 608 | * for any mailbox/letter to that mailbox destination. So, |
| 609 | * make the callback with an unknown/invalid mailbox number |
| 610 | * argument. |
| 611 | */ |
Zhang Wei | ad1e938 | 2008-04-18 13:33:41 -0700 | [diff] [blame] | 612 | port->inb_msg[0].mcback(port, priv->msg_rx_ring.dev_id, -1, -1); |
Matt Porter | 2b0c28d7f | 2005-11-07 01:00:19 -0800 | [diff] [blame] | 613 | |
| 614 | /* Ack the queueing interrupt */ |
Zhang Wei | ad1e938 | 2008-04-18 13:33:41 -0700 | [diff] [blame] | 615 | out_be32(&priv->msg_regs->isr, RIO_MSG_ISR_DIQI); |
Matt Porter | 2b0c28d7f | 2005-11-07 01:00:19 -0800 | [diff] [blame] | 616 | } |
| 617 | |
| 618 | out: |
| 619 | return IRQ_HANDLED; |
| 620 | } |
| 621 | |
| 622 | /** |
| 623 | * rio_open_inb_mbox - Initialize MPC85xx inbound mailbox |
| 624 | * @mport: Master port implementing the inbound message unit |
Matt Porter | 6978bbc | 2005-11-07 01:00:20 -0800 | [diff] [blame] | 625 | * @dev_id: Device specific pointer to pass on event |
Matt Porter | 2b0c28d7f | 2005-11-07 01:00:19 -0800 | [diff] [blame] | 626 | * @mbox: Mailbox to open |
| 627 | * @entries: Number of entries in the inbound mailbox ring |
| 628 | * |
| 629 | * Initializes buffer ring, request the inbound message interrupt, |
| 630 | * and enables the inbound message unit. Returns %0 on success |
| 631 | * and %-EINVAL or %-ENOMEM on failure. |
| 632 | */ |
Matt Porter | 6978bbc | 2005-11-07 01:00:20 -0800 | [diff] [blame] | 633 | int rio_open_inb_mbox(struct rio_mport *mport, void *dev_id, int mbox, int entries) |
Matt Porter | 2b0c28d7f | 2005-11-07 01:00:19 -0800 | [diff] [blame] | 634 | { |
| 635 | int i, rc = 0; |
Zhang Wei | ad1e938 | 2008-04-18 13:33:41 -0700 | [diff] [blame] | 636 | struct rio_priv *priv = mport->priv; |
Matt Porter | 2b0c28d7f | 2005-11-07 01:00:19 -0800 | [diff] [blame] | 637 | |
| 638 | if ((entries < RIO_MIN_RX_RING_SIZE) || |
| 639 | (entries > RIO_MAX_RX_RING_SIZE) || (!is_power_of_2(entries))) { |
| 640 | rc = -EINVAL; |
| 641 | goto out; |
| 642 | } |
| 643 | |
| 644 | /* Initialize client buffer ring */ |
Zhang Wei | ad1e938 | 2008-04-18 13:33:41 -0700 | [diff] [blame] | 645 | priv->msg_rx_ring.dev_id = dev_id; |
| 646 | priv->msg_rx_ring.size = entries; |
| 647 | priv->msg_rx_ring.rx_slot = 0; |
| 648 | for (i = 0; i < priv->msg_rx_ring.size; i++) |
| 649 | priv->msg_rx_ring.virt_buffer[i] = NULL; |
Matt Porter | 2b0c28d7f | 2005-11-07 01:00:19 -0800 | [diff] [blame] | 650 | |
| 651 | /* Initialize inbound message ring */ |
Zhang Wei | ad1e938 | 2008-04-18 13:33:41 -0700 | [diff] [blame] | 652 | priv->msg_rx_ring.virt = dma_alloc_coherent(NULL, |
| 653 | priv->msg_rx_ring.size * RIO_MAX_MSG_SIZE, |
| 654 | &priv->msg_rx_ring.phys, GFP_KERNEL); |
| 655 | if (!priv->msg_rx_ring.virt) { |
Matt Porter | 2b0c28d7f | 2005-11-07 01:00:19 -0800 | [diff] [blame] | 656 | rc = -ENOMEM; |
| 657 | goto out; |
| 658 | } |
| 659 | |
| 660 | /* Point dequeue/enqueue pointers at first entry in ring */ |
Zhang Wei | ad1e938 | 2008-04-18 13:33:41 -0700 | [diff] [blame] | 661 | out_be32(&priv->msg_regs->ifqdpar, (u32) priv->msg_rx_ring.phys); |
| 662 | out_be32(&priv->msg_regs->ifqepar, (u32) priv->msg_rx_ring.phys); |
Matt Porter | 2b0c28d7f | 2005-11-07 01:00:19 -0800 | [diff] [blame] | 663 | |
| 664 | /* Clear interrupt status */ |
Zhang Wei | ad1e938 | 2008-04-18 13:33:41 -0700 | [diff] [blame] | 665 | out_be32(&priv->msg_regs->isr, 0x00000091); |
Matt Porter | 2b0c28d7f | 2005-11-07 01:00:19 -0800 | [diff] [blame] | 666 | |
| 667 | /* Hook up inbound message handler */ |
Zhang Wei | ad1e938 | 2008-04-18 13:33:41 -0700 | [diff] [blame] | 668 | rc = request_irq(IRQ_RIO_RX(mport), fsl_rio_rx_handler, 0, |
| 669 | "msg_rx", (void *)mport); |
| 670 | if (rc < 0) { |
Matt Porter | 2b0c28d7f | 2005-11-07 01:00:19 -0800 | [diff] [blame] | 671 | dma_free_coherent(NULL, RIO_MSG_BUFFER_SIZE, |
Zhang Wei | ad1e938 | 2008-04-18 13:33:41 -0700 | [diff] [blame] | 672 | priv->msg_tx_ring.virt_buffer[i], |
| 673 | priv->msg_tx_ring.phys_buffer[i]); |
Matt Porter | 2b0c28d7f | 2005-11-07 01:00:19 -0800 | [diff] [blame] | 674 | goto out; |
| 675 | } |
| 676 | |
| 677 | /* |
| 678 | * Configure inbound message unit: |
| 679 | * Snooping |
| 680 | * 4KB max message size |
| 681 | * Unmask all interrupt sources |
| 682 | * Disable |
| 683 | */ |
Zhang Wei | ad1e938 | 2008-04-18 13:33:41 -0700 | [diff] [blame] | 684 | out_be32(&priv->msg_regs->imr, 0x001b0060); |
Matt Porter | 2b0c28d7f | 2005-11-07 01:00:19 -0800 | [diff] [blame] | 685 | |
| 686 | /* Set number of queue entries */ |
Zhang Wei | ad1e938 | 2008-04-18 13:33:41 -0700 | [diff] [blame] | 687 | setbits32(&priv->msg_regs->imr, (get_bitmask_order(entries) - 2) << 12); |
Matt Porter | 2b0c28d7f | 2005-11-07 01:00:19 -0800 | [diff] [blame] | 688 | |
| 689 | /* Now enable the unit */ |
Zhang Wei | ad1e938 | 2008-04-18 13:33:41 -0700 | [diff] [blame] | 690 | setbits32(&priv->msg_regs->imr, 0x1); |
Matt Porter | 2b0c28d7f | 2005-11-07 01:00:19 -0800 | [diff] [blame] | 691 | |
| 692 | out: |
| 693 | return rc; |
| 694 | } |
| 695 | |
| 696 | /** |
| 697 | * rio_close_inb_mbox - Shut down MPC85xx inbound mailbox |
| 698 | * @mport: Master port implementing the inbound message unit |
| 699 | * @mbox: Mailbox to close |
| 700 | * |
| 701 | * Disables the inbound message unit, free all buffers, and |
| 702 | * frees the inbound message interrupt. |
| 703 | */ |
| 704 | void rio_close_inb_mbox(struct rio_mport *mport, int mbox) |
| 705 | { |
Zhang Wei | ad1e938 | 2008-04-18 13:33:41 -0700 | [diff] [blame] | 706 | struct rio_priv *priv = mport->priv; |
Matt Porter | 2b0c28d7f | 2005-11-07 01:00:19 -0800 | [diff] [blame] | 707 | /* Disable inbound message unit */ |
Zhang Wei | ad1e938 | 2008-04-18 13:33:41 -0700 | [diff] [blame] | 708 | out_be32(&priv->msg_regs->imr, 0); |
Matt Porter | 2b0c28d7f | 2005-11-07 01:00:19 -0800 | [diff] [blame] | 709 | |
| 710 | /* Free ring */ |
Zhang Wei | ad1e938 | 2008-04-18 13:33:41 -0700 | [diff] [blame] | 711 | dma_free_coherent(NULL, priv->msg_rx_ring.size * RIO_MAX_MSG_SIZE, |
| 712 | priv->msg_rx_ring.virt, priv->msg_rx_ring.phys); |
Matt Porter | 2b0c28d7f | 2005-11-07 01:00:19 -0800 | [diff] [blame] | 713 | |
| 714 | /* Free interrupt */ |
Zhang Wei | ad1e938 | 2008-04-18 13:33:41 -0700 | [diff] [blame] | 715 | free_irq(IRQ_RIO_RX(mport), (void *)mport); |
Matt Porter | 2b0c28d7f | 2005-11-07 01:00:19 -0800 | [diff] [blame] | 716 | } |
| 717 | |
| 718 | /** |
| 719 | * rio_hw_add_inb_buffer - Add buffer to the MPC85xx inbound message queue |
| 720 | * @mport: Master port implementing the inbound message unit |
| 721 | * @mbox: Inbound mailbox number |
| 722 | * @buf: Buffer to add to inbound queue |
| 723 | * |
| 724 | * Adds the @buf buffer to the MPC85xx inbound message queue. Returns |
| 725 | * %0 on success or %-EINVAL on failure. |
| 726 | */ |
| 727 | int rio_hw_add_inb_buffer(struct rio_mport *mport, int mbox, void *buf) |
| 728 | { |
| 729 | int rc = 0; |
Zhang Wei | ad1e938 | 2008-04-18 13:33:41 -0700 | [diff] [blame] | 730 | struct rio_priv *priv = mport->priv; |
Matt Porter | 2b0c28d7f | 2005-11-07 01:00:19 -0800 | [diff] [blame] | 731 | |
| 732 | pr_debug("RIO: rio_hw_add_inb_buffer(), msg_rx_ring.rx_slot %d\n", |
Zhang Wei | ad1e938 | 2008-04-18 13:33:41 -0700 | [diff] [blame] | 733 | priv->msg_rx_ring.rx_slot); |
Matt Porter | 2b0c28d7f | 2005-11-07 01:00:19 -0800 | [diff] [blame] | 734 | |
Zhang Wei | ad1e938 | 2008-04-18 13:33:41 -0700 | [diff] [blame] | 735 | if (priv->msg_rx_ring.virt_buffer[priv->msg_rx_ring.rx_slot]) { |
Matt Porter | 2b0c28d7f | 2005-11-07 01:00:19 -0800 | [diff] [blame] | 736 | printk(KERN_ERR |
| 737 | "RIO: error adding inbound buffer %d, buffer exists\n", |
Zhang Wei | ad1e938 | 2008-04-18 13:33:41 -0700 | [diff] [blame] | 738 | priv->msg_rx_ring.rx_slot); |
Matt Porter | 2b0c28d7f | 2005-11-07 01:00:19 -0800 | [diff] [blame] | 739 | rc = -EINVAL; |
| 740 | goto out; |
| 741 | } |
| 742 | |
Zhang Wei | ad1e938 | 2008-04-18 13:33:41 -0700 | [diff] [blame] | 743 | priv->msg_rx_ring.virt_buffer[priv->msg_rx_ring.rx_slot] = buf; |
| 744 | if (++priv->msg_rx_ring.rx_slot == priv->msg_rx_ring.size) |
| 745 | priv->msg_rx_ring.rx_slot = 0; |
Matt Porter | 2b0c28d7f | 2005-11-07 01:00:19 -0800 | [diff] [blame] | 746 | |
| 747 | out: |
| 748 | return rc; |
| 749 | } |
| 750 | |
| 751 | EXPORT_SYMBOL_GPL(rio_hw_add_inb_buffer); |
| 752 | |
| 753 | /** |
| 754 | * rio_hw_get_inb_message - Fetch inbound message from the MPC85xx message unit |
| 755 | * @mport: Master port implementing the inbound message unit |
| 756 | * @mbox: Inbound mailbox number |
| 757 | * |
| 758 | * Gets the next available inbound message from the inbound message queue. |
| 759 | * A pointer to the message is returned on success or NULL on failure. |
| 760 | */ |
| 761 | void *rio_hw_get_inb_message(struct rio_mport *mport, int mbox) |
| 762 | { |
Zhang Wei | ad1e938 | 2008-04-18 13:33:41 -0700 | [diff] [blame] | 763 | struct rio_priv *priv = mport->priv; |
Matt Porter | 2b0c28d7f | 2005-11-07 01:00:19 -0800 | [diff] [blame] | 764 | u32 phys_buf, virt_buf; |
| 765 | void *buf = NULL; |
| 766 | int buf_idx; |
| 767 | |
Zhang Wei | ad1e938 | 2008-04-18 13:33:41 -0700 | [diff] [blame] | 768 | phys_buf = in_be32(&priv->msg_regs->ifqdpar); |
Matt Porter | 2b0c28d7f | 2005-11-07 01:00:19 -0800 | [diff] [blame] | 769 | |
| 770 | /* If no more messages, then bail out */ |
Zhang Wei | ad1e938 | 2008-04-18 13:33:41 -0700 | [diff] [blame] | 771 | if (phys_buf == in_be32(&priv->msg_regs->ifqepar)) |
Matt Porter | 2b0c28d7f | 2005-11-07 01:00:19 -0800 | [diff] [blame] | 772 | goto out2; |
| 773 | |
Zhang Wei | ad1e938 | 2008-04-18 13:33:41 -0700 | [diff] [blame] | 774 | virt_buf = (u32) priv->msg_rx_ring.virt + (phys_buf |
| 775 | - priv->msg_rx_ring.phys); |
| 776 | buf_idx = (phys_buf - priv->msg_rx_ring.phys) / RIO_MAX_MSG_SIZE; |
| 777 | buf = priv->msg_rx_ring.virt_buffer[buf_idx]; |
Matt Porter | 2b0c28d7f | 2005-11-07 01:00:19 -0800 | [diff] [blame] | 778 | |
| 779 | if (!buf) { |
| 780 | printk(KERN_ERR |
| 781 | "RIO: inbound message copy failed, no buffers\n"); |
| 782 | goto out1; |
| 783 | } |
| 784 | |
| 785 | /* Copy max message size, caller is expected to allocate that big */ |
| 786 | memcpy(buf, (void *)virt_buf, RIO_MAX_MSG_SIZE); |
| 787 | |
| 788 | /* Clear the available buffer */ |
Zhang Wei | ad1e938 | 2008-04-18 13:33:41 -0700 | [diff] [blame] | 789 | priv->msg_rx_ring.virt_buffer[buf_idx] = NULL; |
Matt Porter | 2b0c28d7f | 2005-11-07 01:00:19 -0800 | [diff] [blame] | 790 | |
| 791 | out1: |
Zhang Wei | ad1e938 | 2008-04-18 13:33:41 -0700 | [diff] [blame] | 792 | setbits32(&priv->msg_regs->imr, RIO_MSG_IMR_MI); |
Matt Porter | 2b0c28d7f | 2005-11-07 01:00:19 -0800 | [diff] [blame] | 793 | |
| 794 | out2: |
| 795 | return buf; |
| 796 | } |
| 797 | |
| 798 | EXPORT_SYMBOL_GPL(rio_hw_get_inb_message); |
| 799 | |
| 800 | /** |
Zhang Wei | d02443a | 2008-04-18 13:33:38 -0700 | [diff] [blame] | 801 | * fsl_rio_dbell_handler - MPC85xx doorbell interrupt handler |
Matt Porter | 2b0c28d7f | 2005-11-07 01:00:19 -0800 | [diff] [blame] | 802 | * @irq: Linux interrupt number |
| 803 | * @dev_instance: Pointer to interrupt-specific data |
Matt Porter | 2b0c28d7f | 2005-11-07 01:00:19 -0800 | [diff] [blame] | 804 | * |
| 805 | * Handles doorbell interrupts. Parses a list of registered |
| 806 | * doorbell event handlers and executes a matching event handler. |
| 807 | */ |
| 808 | static irqreturn_t |
Zhang Wei | d02443a | 2008-04-18 13:33:38 -0700 | [diff] [blame] | 809 | fsl_rio_dbell_handler(int irq, void *dev_instance) |
Matt Porter | 2b0c28d7f | 2005-11-07 01:00:19 -0800 | [diff] [blame] | 810 | { |
| 811 | int dsr; |
| 812 | struct rio_mport *port = (struct rio_mport *)dev_instance; |
Zhang Wei | ad1e938 | 2008-04-18 13:33:41 -0700 | [diff] [blame] | 813 | struct rio_priv *priv = port->priv; |
Matt Porter | 2b0c28d7f | 2005-11-07 01:00:19 -0800 | [diff] [blame] | 814 | |
Zhang Wei | ad1e938 | 2008-04-18 13:33:41 -0700 | [diff] [blame] | 815 | dsr = in_be32(&priv->msg_regs->dsr); |
Matt Porter | 2b0c28d7f | 2005-11-07 01:00:19 -0800 | [diff] [blame] | 816 | |
| 817 | if (dsr & DOORBELL_DSR_TE) { |
| 818 | pr_info("RIO: doorbell reception error\n"); |
Zhang Wei | ad1e938 | 2008-04-18 13:33:41 -0700 | [diff] [blame] | 819 | out_be32(&priv->msg_regs->dsr, DOORBELL_DSR_TE); |
Matt Porter | 2b0c28d7f | 2005-11-07 01:00:19 -0800 | [diff] [blame] | 820 | goto out; |
| 821 | } |
| 822 | |
| 823 | if (dsr & DOORBELL_DSR_QFI) { |
| 824 | pr_info("RIO: doorbell queue full\n"); |
Zhang Wei | ad1e938 | 2008-04-18 13:33:41 -0700 | [diff] [blame] | 825 | out_be32(&priv->msg_regs->dsr, DOORBELL_DSR_QFI); |
Matt Porter | 2b0c28d7f | 2005-11-07 01:00:19 -0800 | [diff] [blame] | 826 | goto out; |
| 827 | } |
| 828 | |
| 829 | /* XXX Need to check/dispatch until queue empty */ |
| 830 | if (dsr & DOORBELL_DSR_DIQI) { |
| 831 | u32 dmsg = |
Zhang Wei | ad1e938 | 2008-04-18 13:33:41 -0700 | [diff] [blame] | 832 | (u32) priv->dbell_ring.virt + |
| 833 | (in_be32(&priv->msg_regs->dqdpar) & 0xfff); |
Matt Porter | 2b0c28d7f | 2005-11-07 01:00:19 -0800 | [diff] [blame] | 834 | struct rio_dbell *dbell; |
| 835 | int found = 0; |
| 836 | |
| 837 | pr_debug |
| 838 | ("RIO: processing doorbell, sid %2.2x tid %2.2x info %4.4x\n", |
| 839 | DBELL_SID(dmsg), DBELL_TID(dmsg), DBELL_INF(dmsg)); |
| 840 | |
| 841 | list_for_each_entry(dbell, &port->dbells, node) { |
| 842 | if ((dbell->res->start <= DBELL_INF(dmsg)) && |
| 843 | (dbell->res->end >= DBELL_INF(dmsg))) { |
| 844 | found = 1; |
| 845 | break; |
| 846 | } |
| 847 | } |
| 848 | if (found) { |
Matt Porter | 6978bbc | 2005-11-07 01:00:20 -0800 | [diff] [blame] | 849 | dbell->dinb(port, dbell->dev_id, DBELL_SID(dmsg), DBELL_TID(dmsg), |
Matt Porter | 2b0c28d7f | 2005-11-07 01:00:19 -0800 | [diff] [blame] | 850 | DBELL_INF(dmsg)); |
| 851 | } else { |
| 852 | pr_debug |
| 853 | ("RIO: spurious doorbell, sid %2.2x tid %2.2x info %4.4x\n", |
| 854 | DBELL_SID(dmsg), DBELL_TID(dmsg), DBELL_INF(dmsg)); |
| 855 | } |
Zhang Wei | ad1e938 | 2008-04-18 13:33:41 -0700 | [diff] [blame] | 856 | setbits32(&priv->msg_regs->dmr, DOORBELL_DMR_DI); |
| 857 | out_be32(&priv->msg_regs->dsr, DOORBELL_DSR_DIQI); |
Matt Porter | 2b0c28d7f | 2005-11-07 01:00:19 -0800 | [diff] [blame] | 858 | } |
| 859 | |
| 860 | out: |
| 861 | return IRQ_HANDLED; |
| 862 | } |
| 863 | |
| 864 | /** |
Zhang Wei | d02443a | 2008-04-18 13:33:38 -0700 | [diff] [blame] | 865 | * fsl_rio_doorbell_init - MPC85xx doorbell interface init |
Matt Porter | 2b0c28d7f | 2005-11-07 01:00:19 -0800 | [diff] [blame] | 866 | * @mport: Master port implementing the inbound doorbell unit |
| 867 | * |
| 868 | * Initializes doorbell unit hardware and inbound DMA buffer |
Zhang Wei | d02443a | 2008-04-18 13:33:38 -0700 | [diff] [blame] | 869 | * ring. Called from fsl_rio_setup(). Returns %0 on success |
Matt Porter | 2b0c28d7f | 2005-11-07 01:00:19 -0800 | [diff] [blame] | 870 | * or %-ENOMEM on failure. |
| 871 | */ |
Zhang Wei | d02443a | 2008-04-18 13:33:38 -0700 | [diff] [blame] | 872 | static int fsl_rio_doorbell_init(struct rio_mport *mport) |
Matt Porter | 2b0c28d7f | 2005-11-07 01:00:19 -0800 | [diff] [blame] | 873 | { |
Zhang Wei | ad1e938 | 2008-04-18 13:33:41 -0700 | [diff] [blame] | 874 | struct rio_priv *priv = mport->priv; |
Matt Porter | 2b0c28d7f | 2005-11-07 01:00:19 -0800 | [diff] [blame] | 875 | int rc = 0; |
| 876 | |
| 877 | /* Map outbound doorbell window immediately after maintenance window */ |
Zhang Wei | ad1e938 | 2008-04-18 13:33:41 -0700 | [diff] [blame] | 878 | priv->dbell_win = ioremap(mport->iores.start + RIO_MAINT_WIN_SIZE, |
| 879 | RIO_DBELL_WIN_SIZE); |
| 880 | if (!priv->dbell_win) { |
Matt Porter | 2b0c28d7f | 2005-11-07 01:00:19 -0800 | [diff] [blame] | 881 | printk(KERN_ERR |
| 882 | "RIO: unable to map outbound doorbell window\n"); |
| 883 | rc = -ENOMEM; |
| 884 | goto out; |
| 885 | } |
| 886 | |
| 887 | /* Initialize inbound doorbells */ |
Zhang Wei | ad1e938 | 2008-04-18 13:33:41 -0700 | [diff] [blame] | 888 | priv->dbell_ring.virt = dma_alloc_coherent(NULL, 512 * |
| 889 | DOORBELL_MESSAGE_SIZE, &priv->dbell_ring.phys, GFP_KERNEL); |
| 890 | if (!priv->dbell_ring.virt) { |
Matt Porter | 2b0c28d7f | 2005-11-07 01:00:19 -0800 | [diff] [blame] | 891 | printk(KERN_ERR "RIO: unable allocate inbound doorbell ring\n"); |
| 892 | rc = -ENOMEM; |
Zhang Wei | ad1e938 | 2008-04-18 13:33:41 -0700 | [diff] [blame] | 893 | iounmap(priv->dbell_win); |
Matt Porter | 2b0c28d7f | 2005-11-07 01:00:19 -0800 | [diff] [blame] | 894 | goto out; |
| 895 | } |
| 896 | |
| 897 | /* Point dequeue/enqueue pointers at first entry in ring */ |
Zhang Wei | ad1e938 | 2008-04-18 13:33:41 -0700 | [diff] [blame] | 898 | out_be32(&priv->msg_regs->dqdpar, (u32) priv->dbell_ring.phys); |
| 899 | out_be32(&priv->msg_regs->dqepar, (u32) priv->dbell_ring.phys); |
Matt Porter | 2b0c28d7f | 2005-11-07 01:00:19 -0800 | [diff] [blame] | 900 | |
| 901 | /* Clear interrupt status */ |
Zhang Wei | ad1e938 | 2008-04-18 13:33:41 -0700 | [diff] [blame] | 902 | out_be32(&priv->msg_regs->dsr, 0x00000091); |
Matt Porter | 2b0c28d7f | 2005-11-07 01:00:19 -0800 | [diff] [blame] | 903 | |
| 904 | /* Hook up doorbell handler */ |
Zhang Wei | ad1e938 | 2008-04-18 13:33:41 -0700 | [diff] [blame] | 905 | rc = request_irq(IRQ_RIO_BELL(mport), fsl_rio_dbell_handler, 0, |
| 906 | "dbell_rx", (void *)mport); |
| 907 | if (rc < 0) { |
| 908 | iounmap(priv->dbell_win); |
Matt Porter | 2b0c28d7f | 2005-11-07 01:00:19 -0800 | [diff] [blame] | 909 | dma_free_coherent(NULL, 512 * DOORBELL_MESSAGE_SIZE, |
Zhang Wei | ad1e938 | 2008-04-18 13:33:41 -0700 | [diff] [blame] | 910 | priv->dbell_ring.virt, priv->dbell_ring.phys); |
Matt Porter | 2b0c28d7f | 2005-11-07 01:00:19 -0800 | [diff] [blame] | 911 | printk(KERN_ERR |
| 912 | "MPC85xx RIO: unable to request inbound doorbell irq"); |
| 913 | goto out; |
| 914 | } |
| 915 | |
| 916 | /* Configure doorbells for snooping, 512 entries, and enable */ |
Zhang Wei | ad1e938 | 2008-04-18 13:33:41 -0700 | [diff] [blame] | 917 | out_be32(&priv->msg_regs->dmr, 0x00108161); |
Matt Porter | 2b0c28d7f | 2005-11-07 01:00:19 -0800 | [diff] [blame] | 918 | |
| 919 | out: |
| 920 | return rc; |
| 921 | } |
| 922 | |
| 923 | static char *cmdline = NULL; |
| 924 | |
Zhang Wei | d02443a | 2008-04-18 13:33:38 -0700 | [diff] [blame] | 925 | static int fsl_rio_get_hdid(int index) |
Matt Porter | 2b0c28d7f | 2005-11-07 01:00:19 -0800 | [diff] [blame] | 926 | { |
| 927 | /* XXX Need to parse multiple entries in some format */ |
| 928 | if (!cmdline) |
| 929 | return -1; |
| 930 | |
| 931 | return simple_strtol(cmdline, NULL, 0); |
| 932 | } |
| 933 | |
Zhang Wei | d02443a | 2008-04-18 13:33:38 -0700 | [diff] [blame] | 934 | static int fsl_rio_get_cmdline(char *s) |
Matt Porter | 2b0c28d7f | 2005-11-07 01:00:19 -0800 | [diff] [blame] | 935 | { |
| 936 | if (!s) |
| 937 | return 0; |
| 938 | |
| 939 | cmdline = s; |
| 940 | return 1; |
| 941 | } |
| 942 | |
Zhang Wei | d02443a | 2008-04-18 13:33:38 -0700 | [diff] [blame] | 943 | __setup("riohdid=", fsl_rio_get_cmdline); |
Matt Porter | 2b0c28d7f | 2005-11-07 01:00:19 -0800 | [diff] [blame] | 944 | |
Zhang Wei | 7f620df | 2008-04-18 13:33:44 -0700 | [diff] [blame] | 945 | static inline void fsl_rio_info(struct device *dev, u32 ccsr) |
| 946 | { |
| 947 | const char *str; |
| 948 | if (ccsr & 1) { |
| 949 | /* Serial phy */ |
| 950 | switch (ccsr >> 30) { |
| 951 | case 0: |
| 952 | str = "1"; |
| 953 | break; |
| 954 | case 1: |
| 955 | str = "4"; |
| 956 | break; |
| 957 | default: |
| 958 | str = "Unknown"; |
| 959 | break;; |
| 960 | } |
| 961 | dev_info(dev, "Hardware port width: %s\n", str); |
| 962 | |
| 963 | switch ((ccsr >> 27) & 7) { |
| 964 | case 0: |
| 965 | str = "Single-lane 0"; |
| 966 | break; |
| 967 | case 1: |
| 968 | str = "Single-lane 2"; |
| 969 | break; |
| 970 | case 2: |
| 971 | str = "Four-lane"; |
| 972 | break; |
| 973 | default: |
| 974 | str = "Unknown"; |
| 975 | break; |
| 976 | } |
| 977 | dev_info(dev, "Training connection status: %s\n", str); |
| 978 | } else { |
| 979 | /* Parallel phy */ |
| 980 | if (!(ccsr & 0x80000000)) |
| 981 | dev_info(dev, "Output port operating in 8-bit mode\n"); |
| 982 | if (!(ccsr & 0x08000000)) |
| 983 | dev_info(dev, "Input port operating in 8-bit mode\n"); |
| 984 | } |
| 985 | } |
| 986 | |
Matt Porter | 2b0c28d7f | 2005-11-07 01:00:19 -0800 | [diff] [blame] | 987 | /** |
Zhang Wei | d02443a | 2008-04-18 13:33:38 -0700 | [diff] [blame] | 988 | * fsl_rio_setup - Setup MPC85xx RapidIO interface |
Zhang Wei | cc2bb69 | 2008-04-18 13:33:41 -0700 | [diff] [blame] | 989 | * @fsl_rio_setup - Setup Freescale PowerPC RapidIO interface |
Matt Porter | 2b0c28d7f | 2005-11-07 01:00:19 -0800 | [diff] [blame] | 990 | * |
| 991 | * Initializes MPC85xx RapidIO hardware interface, configures |
| 992 | * master port with system-specific info, and registers the |
| 993 | * master port with the RapidIO subsystem. |
| 994 | */ |
Zhang Wei | cc2bb69 | 2008-04-18 13:33:41 -0700 | [diff] [blame] | 995 | int fsl_rio_setup(struct of_device *dev) |
Matt Porter | 2b0c28d7f | 2005-11-07 01:00:19 -0800 | [diff] [blame] | 996 | { |
| 997 | struct rio_ops *ops; |
| 998 | struct rio_mport *port; |
Zhang Wei | cc2bb69 | 2008-04-18 13:33:41 -0700 | [diff] [blame] | 999 | struct rio_priv *priv; |
| 1000 | int rc = 0; |
| 1001 | const u32 *dt_range, *cell; |
| 1002 | struct resource regs; |
| 1003 | int rlen; |
Zhang Wei | 61b2691 | 2008-04-18 13:33:44 -0700 | [diff] [blame] | 1004 | u32 ccsr; |
Zhang Wei | cc2bb69 | 2008-04-18 13:33:41 -0700 | [diff] [blame] | 1005 | u64 law_start, law_size; |
| 1006 | int paw, aw, sw; |
| 1007 | |
| 1008 | if (!dev->node) { |
| 1009 | dev_err(&dev->dev, "Device OF-Node is NULL"); |
| 1010 | return -EFAULT; |
| 1011 | } |
| 1012 | |
| 1013 | rc = of_address_to_resource(dev->node, 0, ®s); |
| 1014 | if (rc) { |
| 1015 | dev_err(&dev->dev, "Can't get %s property 'reg'\n", |
| 1016 | dev->node->full_name); |
| 1017 | return -EFAULT; |
| 1018 | } |
| 1019 | dev_info(&dev->dev, "Of-device full name %s\n", dev->node->full_name); |
| 1020 | dev_info(&dev->dev, "Regs start 0x%08x size 0x%08x\n", regs.start, |
| 1021 | regs.end - regs.start + 1); |
| 1022 | |
| 1023 | dt_range = of_get_property(dev->node, "ranges", &rlen); |
| 1024 | if (!dt_range) { |
| 1025 | dev_err(&dev->dev, "Can't get %s property 'ranges'\n", |
| 1026 | dev->node->full_name); |
| 1027 | return -EFAULT; |
| 1028 | } |
| 1029 | |
| 1030 | /* Get node address wide */ |
| 1031 | cell = of_get_property(dev->node, "#address-cells", NULL); |
| 1032 | if (cell) |
| 1033 | aw = *cell; |
| 1034 | else |
| 1035 | aw = of_n_addr_cells(dev->node); |
| 1036 | /* Get node size wide */ |
| 1037 | cell = of_get_property(dev->node, "#size-cells", NULL); |
| 1038 | if (cell) |
| 1039 | sw = *cell; |
| 1040 | else |
| 1041 | sw = of_n_size_cells(dev->node); |
| 1042 | /* Get parent address wide wide */ |
| 1043 | paw = of_n_addr_cells(dev->node); |
| 1044 | |
| 1045 | law_start = of_read_number(dt_range + aw, paw); |
| 1046 | law_size = of_read_number(dt_range + aw + paw, sw); |
| 1047 | |
| 1048 | dev_info(&dev->dev, "LAW start 0x%016llx, size 0x%016llx.\n", |
| 1049 | law_start, law_size); |
Matt Porter | 2b0c28d7f | 2005-11-07 01:00:19 -0800 | [diff] [blame] | 1050 | |
| 1051 | ops = kmalloc(sizeof(struct rio_ops), GFP_KERNEL); |
Zhang Wei | d02443a | 2008-04-18 13:33:38 -0700 | [diff] [blame] | 1052 | ops->lcread = fsl_local_config_read; |
| 1053 | ops->lcwrite = fsl_local_config_write; |
| 1054 | ops->cread = fsl_rio_config_read; |
| 1055 | ops->cwrite = fsl_rio_config_write; |
| 1056 | ops->dsend = fsl_rio_doorbell_send; |
Matt Porter | 2b0c28d7f | 2005-11-07 01:00:19 -0800 | [diff] [blame] | 1057 | |
Zhang Wei | ad1e938 | 2008-04-18 13:33:41 -0700 | [diff] [blame] | 1058 | port = kzalloc(sizeof(struct rio_mport), GFP_KERNEL); |
Matt Porter | 2b0c28d7f | 2005-11-07 01:00:19 -0800 | [diff] [blame] | 1059 | port->id = 0; |
| 1060 | port->index = 0; |
Zhang Wei | ad1e938 | 2008-04-18 13:33:41 -0700 | [diff] [blame] | 1061 | |
| 1062 | priv = kzalloc(sizeof(struct rio_priv), GFP_KERNEL); |
| 1063 | if (!priv) { |
| 1064 | printk(KERN_ERR "Can't alloc memory for 'priv'\n"); |
| 1065 | rc = -ENOMEM; |
| 1066 | goto err; |
| 1067 | } |
| 1068 | |
Matt Porter | 2b0c28d7f | 2005-11-07 01:00:19 -0800 | [diff] [blame] | 1069 | INIT_LIST_HEAD(&port->dbells); |
| 1070 | port->iores.start = law_start; |
| 1071 | port->iores.end = law_start + law_size; |
| 1072 | port->iores.flags = IORESOURCE_MEM; |
| 1073 | |
Zhang Wei | cc2bb69 | 2008-04-18 13:33:41 -0700 | [diff] [blame] | 1074 | priv->bellirq = irq_of_parse_and_map(dev->node, 2); |
| 1075 | priv->txirq = irq_of_parse_and_map(dev->node, 3); |
| 1076 | priv->rxirq = irq_of_parse_and_map(dev->node, 4); |
| 1077 | dev_info(&dev->dev, "bellirq: %d, txirq: %d, rxirq %d\n", priv->bellirq, |
| 1078 | priv->txirq, priv->rxirq); |
| 1079 | |
Matt Porter | 2b0c28d7f | 2005-11-07 01:00:19 -0800 | [diff] [blame] | 1080 | rio_init_dbell_res(&port->riores[RIO_DOORBELL_RESOURCE], 0, 0xffff); |
| 1081 | rio_init_mbox_res(&port->riores[RIO_INB_MBOX_RESOURCE], 0, 0); |
| 1082 | rio_init_mbox_res(&port->riores[RIO_OUTB_MBOX_RESOURCE], 0, 0); |
| 1083 | strcpy(port->name, "RIO0 mport"); |
| 1084 | |
| 1085 | port->ops = ops; |
Zhang Wei | d02443a | 2008-04-18 13:33:38 -0700 | [diff] [blame] | 1086 | port->host_deviceid = fsl_rio_get_hdid(port->id); |
Matt Porter | 2b0c28d7f | 2005-11-07 01:00:19 -0800 | [diff] [blame] | 1087 | |
Zhang Wei | ad1e938 | 2008-04-18 13:33:41 -0700 | [diff] [blame] | 1088 | port->priv = priv; |
Matt Porter | 2b0c28d7f | 2005-11-07 01:00:19 -0800 | [diff] [blame] | 1089 | rio_register_mport(port); |
| 1090 | |
Zhang Wei | cc2bb69 | 2008-04-18 13:33:41 -0700 | [diff] [blame] | 1091 | priv->regs_win = ioremap(regs.start, regs.end - regs.start + 1); |
Zhang Wei | e042323 | 2008-04-18 13:33:42 -0700 | [diff] [blame] | 1092 | |
Zhang Wei | 61b2691 | 2008-04-18 13:33:44 -0700 | [diff] [blame] | 1093 | /* Probe the master port phy type */ |
| 1094 | ccsr = in_be32(priv->regs_win + RIO_CCSR); |
| 1095 | port->phy_type = (ccsr & 1) ? RIO_PHY_SERIAL : RIO_PHY_PARALLEL; |
| 1096 | dev_info(&dev->dev, "RapidIO PHY type: %s\n", |
| 1097 | (port->phy_type == RIO_PHY_PARALLEL) ? "parallel" : |
| 1098 | ((port->phy_type == RIO_PHY_SERIAL) ? "serial" : |
| 1099 | "unknown")); |
Zhang Wei | 7f620df | 2008-04-18 13:33:44 -0700 | [diff] [blame] | 1100 | /* Checking the port training status */ |
| 1101 | if (in_be32((priv->regs_win + RIO_ESCSR)) & 1) { |
| 1102 | dev_err(&dev->dev, "Port is not ready. " |
| 1103 | "Try to restart connection...\n"); |
| 1104 | switch (port->phy_type) { |
| 1105 | case RIO_PHY_SERIAL: |
| 1106 | /* Disable ports */ |
| 1107 | out_be32(priv->regs_win + RIO_CCSR, 0); |
| 1108 | /* Set 1x lane */ |
| 1109 | setbits32(priv->regs_win + RIO_CCSR, 0x02000000); |
| 1110 | /* Enable ports */ |
| 1111 | setbits32(priv->regs_win + RIO_CCSR, 0x00600000); |
| 1112 | break; |
| 1113 | case RIO_PHY_PARALLEL: |
| 1114 | /* Disable ports */ |
| 1115 | out_be32(priv->regs_win + RIO_CCSR, 0x22000000); |
| 1116 | /* Enable ports */ |
| 1117 | out_be32(priv->regs_win + RIO_CCSR, 0x44000000); |
| 1118 | break; |
| 1119 | } |
| 1120 | msleep(100); |
| 1121 | if (in_be32((priv->regs_win + RIO_ESCSR)) & 1) { |
| 1122 | dev_err(&dev->dev, "Port restart failed.\n"); |
| 1123 | rc = -ENOLINK; |
| 1124 | goto err; |
| 1125 | } |
| 1126 | dev_info(&dev->dev, "Port restart success!\n"); |
| 1127 | } |
| 1128 | fsl_rio_info(&dev->dev, ccsr); |
Zhang Wei | 61b2691 | 2008-04-18 13:33:44 -0700 | [diff] [blame] | 1129 | |
Zhang Wei | e042323 | 2008-04-18 13:33:42 -0700 | [diff] [blame] | 1130 | port->sys_size = (in_be32((priv->regs_win + RIO_PEF_CAR)) |
| 1131 | & RIO_PEF_CTLS) >> 4; |
| 1132 | dev_info(&dev->dev, "RapidIO Common Transport System size: %d\n", |
| 1133 | port->sys_size ? 65536 : 256); |
| 1134 | |
Zhang Wei | ad1e938 | 2008-04-18 13:33:41 -0700 | [diff] [blame] | 1135 | priv->atmu_regs = (struct rio_atmu_regs *)(priv->regs_win |
| 1136 | + RIO_ATMU_REGS_OFFSET); |
| 1137 | priv->maint_atmu_regs = priv->atmu_regs + 1; |
| 1138 | priv->dbell_atmu_regs = priv->atmu_regs + 2; |
Zhang Wei | 61b2691 | 2008-04-18 13:33:44 -0700 | [diff] [blame] | 1139 | priv->msg_regs = (struct rio_msg_regs *)(priv->regs_win + |
| 1140 | ((port->phy_type == RIO_PHY_SERIAL) ? |
| 1141 | RIO_S_MSG_REGS_OFFSET : RIO_P_MSG_REGS_OFFSET)); |
| 1142 | |
| 1143 | /* Set to receive any dist ID for serial RapidIO controller. */ |
| 1144 | if (port->phy_type == RIO_PHY_SERIAL) |
| 1145 | out_be32((priv->regs_win + RIO_ISR_AACR), RIO_ISR_AACR_AA); |
Matt Porter | 2b0c28d7f | 2005-11-07 01:00:19 -0800 | [diff] [blame] | 1146 | |
| 1147 | /* Configure maintenance transaction window */ |
Zhang Wei | ad1e938 | 2008-04-18 13:33:41 -0700 | [diff] [blame] | 1148 | out_be32(&priv->maint_atmu_regs->rowbar, 0x000c0000); |
| 1149 | out_be32(&priv->maint_atmu_regs->rowar, 0x80077015); |
Matt Porter | 2b0c28d7f | 2005-11-07 01:00:19 -0800 | [diff] [blame] | 1150 | |
Zhang Wei | ad1e938 | 2008-04-18 13:33:41 -0700 | [diff] [blame] | 1151 | priv->maint_win = ioremap(law_start, RIO_MAINT_WIN_SIZE); |
Matt Porter | 2b0c28d7f | 2005-11-07 01:00:19 -0800 | [diff] [blame] | 1152 | |
| 1153 | /* Configure outbound doorbell window */ |
Zhang Wei | ad1e938 | 2008-04-18 13:33:41 -0700 | [diff] [blame] | 1154 | out_be32(&priv->dbell_atmu_regs->rowbar, 0x000c0400); |
| 1155 | out_be32(&priv->dbell_atmu_regs->rowar, 0x8004200b); |
Zhang Wei | d02443a | 2008-04-18 13:33:38 -0700 | [diff] [blame] | 1156 | fsl_rio_doorbell_init(port); |
Zhang Wei | ad1e938 | 2008-04-18 13:33:41 -0700 | [diff] [blame] | 1157 | |
Zhang Wei | cc2bb69 | 2008-04-18 13:33:41 -0700 | [diff] [blame] | 1158 | return 0; |
Zhang Wei | ad1e938 | 2008-04-18 13:33:41 -0700 | [diff] [blame] | 1159 | err: |
| 1160 | if (priv) |
| 1161 | iounmap(priv->regs_win); |
Zhang Wei | cc2bb69 | 2008-04-18 13:33:41 -0700 | [diff] [blame] | 1162 | kfree(ops); |
Zhang Wei | ad1e938 | 2008-04-18 13:33:41 -0700 | [diff] [blame] | 1163 | kfree(priv); |
| 1164 | kfree(port); |
Zhang Wei | cc2bb69 | 2008-04-18 13:33:41 -0700 | [diff] [blame] | 1165 | return rc; |
Matt Porter | 2b0c28d7f | 2005-11-07 01:00:19 -0800 | [diff] [blame] | 1166 | } |
Zhang Wei | cc2bb69 | 2008-04-18 13:33:41 -0700 | [diff] [blame] | 1167 | |
| 1168 | /* The probe function for RapidIO peer-to-peer network. |
| 1169 | */ |
| 1170 | static int __devinit fsl_of_rio_rpn_probe(struct of_device *dev, |
| 1171 | const struct of_device_id *match) |
| 1172 | { |
| 1173 | int rc; |
| 1174 | printk(KERN_INFO "Setting up RapidIO peer-to-peer network %s\n", |
| 1175 | dev->node->full_name); |
| 1176 | |
| 1177 | rc = fsl_rio_setup(dev); |
| 1178 | if (rc) |
| 1179 | goto out; |
| 1180 | |
| 1181 | /* Enumerate all registered ports */ |
| 1182 | rc = rio_init_mports(); |
| 1183 | out: |
| 1184 | return rc; |
| 1185 | }; |
| 1186 | |
| 1187 | static const struct of_device_id fsl_of_rio_rpn_ids[] = { |
| 1188 | { |
| 1189 | .compatible = "fsl,rapidio-delta", |
| 1190 | }, |
| 1191 | {}, |
| 1192 | }; |
| 1193 | |
| 1194 | static struct of_platform_driver fsl_of_rio_rpn_driver = { |
| 1195 | .name = "fsl-of-rio", |
| 1196 | .match_table = fsl_of_rio_rpn_ids, |
| 1197 | .probe = fsl_of_rio_rpn_probe, |
| 1198 | }; |
| 1199 | |
| 1200 | static __init int fsl_of_rio_rpn_init(void) |
| 1201 | { |
| 1202 | return of_register_platform_driver(&fsl_of_rio_rpn_driver); |
| 1203 | } |
| 1204 | |
| 1205 | subsys_initcall(fsl_of_rio_rpn_init); |