195ea36275f3c9a1d3d04c217b4b576c657c4e70eIvo van Doorn/* 29c9a0d145fee73b5e821bb460732ac2a66c680b3Gertjan van Wingerde Copyright (C) 2004 - 2009 Ivo van Doorn <IvDoorn@gmail.com> 395ea36275f3c9a1d3d04c217b4b576c657c4e70eIvo van Doorn <http://rt2x00.serialmonkey.com> 495ea36275f3c9a1d3d04c217b4b576c657c4e70eIvo van Doorn 595ea36275f3c9a1d3d04c217b4b576c657c4e70eIvo van Doorn This program is free software; you can redistribute it and/or modify 695ea36275f3c9a1d3d04c217b4b576c657c4e70eIvo van Doorn it under the terms of the GNU General Public License as published by 795ea36275f3c9a1d3d04c217b4b576c657c4e70eIvo van Doorn the Free Software Foundation; either version 2 of the License, or 895ea36275f3c9a1d3d04c217b4b576c657c4e70eIvo van Doorn (at your option) any later version. 995ea36275f3c9a1d3d04c217b4b576c657c4e70eIvo van Doorn 1095ea36275f3c9a1d3d04c217b4b576c657c4e70eIvo van Doorn This program is distributed in the hope that it will be useful, 1195ea36275f3c9a1d3d04c217b4b576c657c4e70eIvo van Doorn but WITHOUT ANY WARRANTY; without even the implied warranty of 1295ea36275f3c9a1d3d04c217b4b576c657c4e70eIvo van Doorn MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1395ea36275f3c9a1d3d04c217b4b576c657c4e70eIvo van Doorn GNU General Public License for more details. 1495ea36275f3c9a1d3d04c217b4b576c657c4e70eIvo van Doorn 1595ea36275f3c9a1d3d04c217b4b576c657c4e70eIvo van Doorn You should have received a copy of the GNU General Public License 1695ea36275f3c9a1d3d04c217b4b576c657c4e70eIvo van Doorn along with this program; if not, write to the 1795ea36275f3c9a1d3d04c217b4b576c657c4e70eIvo van Doorn Free Software Foundation, Inc., 1895ea36275f3c9a1d3d04c217b4b576c657c4e70eIvo van Doorn 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 1995ea36275f3c9a1d3d04c217b4b576c657c4e70eIvo van Doorn */ 2095ea36275f3c9a1d3d04c217b4b576c657c4e70eIvo van Doorn 2195ea36275f3c9a1d3d04c217b4b576c657c4e70eIvo van Doorn/* 2295ea36275f3c9a1d3d04c217b4b576c657c4e70eIvo van Doorn Module: rt2x00pci 2395ea36275f3c9a1d3d04c217b4b576c657c4e70eIvo van Doorn Abstract: Data structures for the rt2x00pci module. 2495ea36275f3c9a1d3d04c217b4b576c657c4e70eIvo van Doorn */ 2595ea36275f3c9a1d3d04c217b4b576c657c4e70eIvo van Doorn 2695ea36275f3c9a1d3d04c217b4b576c657c4e70eIvo van Doorn#ifndef RT2X00PCI_H 2795ea36275f3c9a1d3d04c217b4b576c657c4e70eIvo van Doorn#define RT2X00PCI_H 2895ea36275f3c9a1d3d04c217b4b576c657c4e70eIvo van Doorn 2995ea36275f3c9a1d3d04c217b4b576c657c4e70eIvo van Doorn#include <linux/io.h> 30714fa6636331d33c6045efe394f36c964a6c14eeGertjan van Wingerde#include <linux/pci.h> 3195ea36275f3c9a1d3d04c217b4b576c657c4e70eIvo van Doorn 3295ea36275f3c9a1d3d04c217b4b576c657c4e70eIvo van Doorn/* 3395ea36275f3c9a1d3d04c217b4b576c657c4e70eIvo van Doorn * This variable should be used with the 3495ea36275f3c9a1d3d04c217b4b576c657c4e70eIvo van Doorn * pci_driver structure initialization. 3595ea36275f3c9a1d3d04c217b4b576c657c4e70eIvo van Doorn */ 3695ea36275f3c9a1d3d04c217b4b576c657c4e70eIvo van Doorn#define PCI_DEVICE_DATA(__ops) .driver_data = (kernel_ulong_t)(__ops) 3795ea36275f3c9a1d3d04c217b4b576c657c4e70eIvo van Doorn 3895ea36275f3c9a1d3d04c217b4b576c657c4e70eIvo van Doorn/* 3995ea36275f3c9a1d3d04c217b4b576c657c4e70eIvo van Doorn * Register access. 4095ea36275f3c9a1d3d04c217b4b576c657c4e70eIvo van Doorn */ 410e14f6d3e088473b411d35ff63737e46efb9e6dfAdam Bakerstatic inline void rt2x00pci_register_read(struct rt2x00_dev *rt2x00dev, 42743b97caf98036ec8ee4bfc6fc6f85ad94e04783Ivo van Doorn const unsigned int offset, 4395ea36275f3c9a1d3d04c217b4b576c657c4e70eIvo van Doorn u32 *value) 4495ea36275f3c9a1d3d04c217b4b576c657c4e70eIvo van Doorn{ 4521795094e2b71b4b11bfb468321046c1336cef69Ivo van Doorn *value = readl(rt2x00dev->csr.base + offset); 4695ea36275f3c9a1d3d04c217b4b576c657c4e70eIvo van Doorn} 4795ea36275f3c9a1d3d04c217b4b576c657c4e70eIvo van Doorn 48473196bd9935f0efd4c5f1cda28229e7dcff564cBartlomiej Zolnierkiewiczstatic inline void rt2x00pci_register_multiread(struct rt2x00_dev *rt2x00dev, 49473196bd9935f0efd4c5f1cda28229e7dcff564cBartlomiej Zolnierkiewicz const unsigned int offset, 50473196bd9935f0efd4c5f1cda28229e7dcff564cBartlomiej Zolnierkiewicz void *value, const u32 length) 5195ea36275f3c9a1d3d04c217b4b576c657c4e70eIvo van Doorn{ 5221795094e2b71b4b11bfb468321046c1336cef69Ivo van Doorn memcpy_fromio(value, rt2x00dev->csr.base + offset, length); 5395ea36275f3c9a1d3d04c217b4b576c657c4e70eIvo van Doorn} 5495ea36275f3c9a1d3d04c217b4b576c657c4e70eIvo van Doorn 550e14f6d3e088473b411d35ff63737e46efb9e6dfAdam Bakerstatic inline void rt2x00pci_register_write(struct rt2x00_dev *rt2x00dev, 56743b97caf98036ec8ee4bfc6fc6f85ad94e04783Ivo van Doorn const unsigned int offset, 5795ea36275f3c9a1d3d04c217b4b576c657c4e70eIvo van Doorn u32 value) 5895ea36275f3c9a1d3d04c217b4b576c657c4e70eIvo van Doorn{ 5921795094e2b71b4b11bfb468321046c1336cef69Ivo van Doorn writel(value, rt2x00dev->csr.base + offset); 6095ea36275f3c9a1d3d04c217b4b576c657c4e70eIvo van Doorn} 6195ea36275f3c9a1d3d04c217b4b576c657c4e70eIvo van Doorn 62473196bd9935f0efd4c5f1cda28229e7dcff564cBartlomiej Zolnierkiewiczstatic inline void rt2x00pci_register_multiwrite(struct rt2x00_dev *rt2x00dev, 63473196bd9935f0efd4c5f1cda28229e7dcff564cBartlomiej Zolnierkiewicz const unsigned int offset, 64473196bd9935f0efd4c5f1cda28229e7dcff564cBartlomiej Zolnierkiewicz const void *value, 65473196bd9935f0efd4c5f1cda28229e7dcff564cBartlomiej Zolnierkiewicz const u32 length) 6695ea36275f3c9a1d3d04c217b4b576c657c4e70eIvo van Doorn{ 67412b31334b831a8c2909afaca017c5a236ac2dd0Wolfgang Kufner __iowrite32_copy(rt2x00dev->csr.base + offset, value, length >> 2); 6895ea36275f3c9a1d3d04c217b4b576c657c4e70eIvo van Doorn} 6995ea36275f3c9a1d3d04c217b4b576c657c4e70eIvo van Doorn 706db3786aee36b32e5ed072ed67fad6d5341b0991Ivo van Doorn/** 71c9c3b1a5deac4297503145840fffcd122b253db5Ivo van Doorn * rt2x00pci_regbusy_read - Read from register with busy check 72c9c3b1a5deac4297503145840fffcd122b253db5Ivo van Doorn * @rt2x00dev: Device pointer, see &struct rt2x00_dev. 73c9c3b1a5deac4297503145840fffcd122b253db5Ivo van Doorn * @offset: Register offset 74c9c3b1a5deac4297503145840fffcd122b253db5Ivo van Doorn * @field: Field to check if register is busy 75c9c3b1a5deac4297503145840fffcd122b253db5Ivo van Doorn * @reg: Pointer to where register contents should be stored 76c9c3b1a5deac4297503145840fffcd122b253db5Ivo van Doorn * 77c9c3b1a5deac4297503145840fffcd122b253db5Ivo van Doorn * This function will read the given register, and checks if the 78c9c3b1a5deac4297503145840fffcd122b253db5Ivo van Doorn * register is busy. If it is, it will sleep for a couple of 79c9c3b1a5deac4297503145840fffcd122b253db5Ivo van Doorn * microseconds before reading the register again. If the register 80c9c3b1a5deac4297503145840fffcd122b253db5Ivo van Doorn * is not read after a certain timeout, this function will return 81c9c3b1a5deac4297503145840fffcd122b253db5Ivo van Doorn * FALSE. 82c9c3b1a5deac4297503145840fffcd122b253db5Ivo van Doorn */ 83c9c3b1a5deac4297503145840fffcd122b253db5Ivo van Doornint rt2x00pci_regbusy_read(struct rt2x00_dev *rt2x00dev, 84c9c3b1a5deac4297503145840fffcd122b253db5Ivo van Doorn const unsigned int offset, 85c9c3b1a5deac4297503145840fffcd122b253db5Ivo van Doorn const struct rt2x00_field32 field, 86c9c3b1a5deac4297503145840fffcd122b253db5Ivo van Doorn u32 *reg); 87c9c3b1a5deac4297503145840fffcd122b253db5Ivo van Doorn 88c9c3b1a5deac4297503145840fffcd122b253db5Ivo van Doorn/** 89b8be63ffa5dc44324e7f507997870fa3e4b17619Ivo van Doorn * struct queue_entry_priv_pci: Per entry PCI specific information 90181d6902b6bad978d157e69479c95cc0ff213a76Ivo van Doorn * 91181d6902b6bad978d157e69479c95cc0ff213a76Ivo van Doorn * @desc: Pointer to device descriptor 92b8be63ffa5dc44324e7f507997870fa3e4b17619Ivo van Doorn * @desc_dma: DMA pointer to &desc. 93181d6902b6bad978d157e69479c95cc0ff213a76Ivo van Doorn * @data: Pointer to device's entry memory. 949a46d44eda55ad87a727fe351b0ab27c23d4555cIvo van Doorn * @data_dma: DMA pointer to &data. 95181d6902b6bad978d157e69479c95cc0ff213a76Ivo van Doorn */ 96b8be63ffa5dc44324e7f507997870fa3e4b17619Ivo van Doornstruct queue_entry_priv_pci { 97181d6902b6bad978d157e69479c95cc0ff213a76Ivo van Doorn __le32 *desc; 9830b3a23c2594e122e7086f97b5252a87eaf8a817Ivo van Doorn dma_addr_t desc_dma; 99181d6902b6bad978d157e69479c95cc0ff213a76Ivo van Doorn}; 100181d6902b6bad978d157e69479c95cc0ff213a76Ivo van Doorn 101181d6902b6bad978d157e69479c95cc0ff213a76Ivo van Doorn/** 102181d6902b6bad978d157e69479c95cc0ff213a76Ivo van Doorn * rt2x00pci_rxdone - Handle RX done events 103181d6902b6bad978d157e69479c95cc0ff213a76Ivo van Doorn * @rt2x00dev: Device pointer, see &struct rt2x00_dev. 104166389375d5a3894aa00a9c2e490ac4b9af2a891Helmut Schaa * 105166389375d5a3894aa00a9c2e490ac4b9af2a891Helmut Schaa * Returns true if there are still rx frames pending and false if all 106166389375d5a3894aa00a9c2e490ac4b9af2a891Helmut Schaa * pending rx frames were processed. 10795ea36275f3c9a1d3d04c217b4b576c657c4e70eIvo van Doorn */ 108166389375d5a3894aa00a9c2e490ac4b9af2a891Helmut Schaabool rt2x00pci_rxdone(struct rt2x00_dev *rt2x00dev); 109181d6902b6bad978d157e69479c95cc0ff213a76Ivo van Doorn 110152a599274b15028604e24ae2d9c9d7f49853977Ivo van Doorn/** 111152a599274b15028604e24ae2d9c9d7f49853977Ivo van Doorn * rt2x00pci_flush_queue - Flush data queue 112152a599274b15028604e24ae2d9c9d7f49853977Ivo van Doorn * @queue: Data queue to stop 113152a599274b15028604e24ae2d9c9d7f49853977Ivo van Doorn * @drop: True to drop all pending frames. 114152a599274b15028604e24ae2d9c9d7f49853977Ivo van Doorn * 115152a599274b15028604e24ae2d9c9d7f49853977Ivo van Doorn * This will wait for a maximum of 100ms, waiting for the queues 116152a599274b15028604e24ae2d9c9d7f49853977Ivo van Doorn * to become empty. 117152a599274b15028604e24ae2d9c9d7f49853977Ivo van Doorn */ 118152a599274b15028604e24ae2d9c9d7f49853977Ivo van Doornvoid rt2x00pci_flush_queue(struct data_queue *queue, bool drop); 119152a599274b15028604e24ae2d9c9d7f49853977Ivo van Doorn 12095ea36275f3c9a1d3d04c217b4b576c657c4e70eIvo van Doorn/* 12195ea36275f3c9a1d3d04c217b4b576c657c4e70eIvo van Doorn * Device initialization handlers. 12295ea36275f3c9a1d3d04c217b4b576c657c4e70eIvo van Doorn */ 12395ea36275f3c9a1d3d04c217b4b576c657c4e70eIvo van Doornint rt2x00pci_initialize(struct rt2x00_dev *rt2x00dev); 12495ea36275f3c9a1d3d04c217b4b576c657c4e70eIvo van Doornvoid rt2x00pci_uninitialize(struct rt2x00_dev *rt2x00dev); 12595ea36275f3c9a1d3d04c217b4b576c657c4e70eIvo van Doorn 12695ea36275f3c9a1d3d04c217b4b576c657c4e70eIvo van Doorn/* 12795ea36275f3c9a1d3d04c217b4b576c657c4e70eIvo van Doorn * PCI driver handlers. 12895ea36275f3c9a1d3d04c217b4b576c657c4e70eIvo van Doorn */ 129e01ae27f8ce6bd3ee26ef33c704f62449ce8233bGertjan van Wingerdeint rt2x00pci_probe(struct pci_dev *pci_dev, const struct rt2x00_ops *ops); 13095ea36275f3c9a1d3d04c217b4b576c657c4e70eIvo van Doornvoid rt2x00pci_remove(struct pci_dev *pci_dev); 13195ea36275f3c9a1d3d04c217b4b576c657c4e70eIvo van Doorn#ifdef CONFIG_PM 13295ea36275f3c9a1d3d04c217b4b576c657c4e70eIvo van Doornint rt2x00pci_suspend(struct pci_dev *pci_dev, pm_message_t state); 13395ea36275f3c9a1d3d04c217b4b576c657c4e70eIvo van Doornint rt2x00pci_resume(struct pci_dev *pci_dev); 13495ea36275f3c9a1d3d04c217b4b576c657c4e70eIvo van Doorn#else 13595ea36275f3c9a1d3d04c217b4b576c657c4e70eIvo van Doorn#define rt2x00pci_suspend NULL 13695ea36275f3c9a1d3d04c217b4b576c657c4e70eIvo van Doorn#define rt2x00pci_resume NULL 13795ea36275f3c9a1d3d04c217b4b576c657c4e70eIvo van Doorn#endif /* CONFIG_PM */ 13895ea36275f3c9a1d3d04c217b4b576c657c4e70eIvo van Doorn 13995ea36275f3c9a1d3d04c217b4b576c657c4e70eIvo van Doorn#endif /* RT2X00PCI_H */ 140