repo_name
string
path
string
copies
string
size
string
content
string
license
string
ishtob/qmk_firmware
keyboards/crkbd/keymaps/julian_turner/oled.c
13
2660
/* Copyright 2022 Julian Turner * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include QMK_KEYBOARD_H #include "layers.h" oled_rotation_t oled_init_user(oled_rotation_t rotation) { if (!is_keyboard_master()) { return OLED_ROTATION_180; // flips the display 180 degrees if offhand } return rotation; } void oled_render_layer_state(void) { oled_write_P(PSTR("layer: "), false); switch (get_highest_layer(layer_state | default_layer_state)) { case _QWERTZ: oled_write_ln_P(PSTR("QWERTZ"), false); break; case _SYMBOL: oled_write_ln_P(PSTR("SYMBOL"), false); break; case _NUMBER: oled_write_ln_P(PSTR("NUMBER"), false); break; default: oled_write_ln_P(PSTR("unknown"), false); break; } } void render_bootmagic_status(bool status) { /* Show Ctrl-Gui Swap options */ static const char PROGMEM logo[][2][3] = { {{0x97, 0x98, 0}, {0xb7, 0xb8, 0}}, {{0x95, 0x96, 0}, {0xb5, 0xb6, 0}}, }; if (status) { oled_write_ln_P(logo[0][0], false); oled_write_ln_P(logo[0][1], false); } else { oled_write_ln_P(logo[1][0], false); oled_write_ln_P(logo[1][1], false); } } void oled_render_logo(void) { static const char PROGMEM crkbd_logo[] = {0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f, 0x90, 0x91, 0x92, 0x93, 0x94, 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf, 0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf, 0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0}; oled_write_P(crkbd_logo, false); } bool oled_task_user(void) { if (is_keyboard_master()) { oled_render_layer_state(); oled_write_P(PSTR("WPM: "), false); oled_write(get_u8_str(get_current_wpm(), ' '), false); } else { oled_render_logo(); } return false; }
gpl-2.0
fabiocannizzo/linux
drivers/scsi/mpt3sas/mpt3sas_base.c
13
255077
/* * This is the Fusion MPT base driver providing common API layer interface * for access to MPT (Message Passing Technology) firmware. * * This code is based on drivers/scsi/mpt3sas/mpt3sas_base.c * Copyright (C) 2012-2014 LSI Corporation * Copyright (C) 2013-2014 Avago Technologies * (mailto: MPT-FusionLinux.pdl@avagotech.com) * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * NO WARRANTY * THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR * CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT * LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is * solely responsible for determining the appropriateness of using and * distributing the Program and assumes all risks associated with its * exercise of rights under this Agreement, including but not limited to * the risks and costs of program errors, damage to or loss of data, * programs or equipment, and unavailability or interruption of operations. * DISCLAIMER OF LIABILITY * NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE * USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED * HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. */ #include <linux/kernel.h> #include <linux/module.h> #include <linux/errno.h> #include <linux/init.h> #include <linux/slab.h> #include <linux/types.h> #include <linux/pci.h> #include <linux/kdev_t.h> #include <linux/blkdev.h> #include <linux/delay.h> #include <linux/interrupt.h> #include <linux/dma-mapping.h> #include <linux/io.h> #include <linux/time.h> #include <linux/ktime.h> #include <linux/kthread.h> #include <asm/page.h> /* To get host page size per arch */ #include <linux/aer.h> #include "mpt3sas_base.h" static MPT_CALLBACK mpt_callbacks[MPT_MAX_CALLBACKS]; #define FAULT_POLLING_INTERVAL 1000 /* in milliseconds */ /* maximum controller queue depth */ #define MAX_HBA_QUEUE_DEPTH 30000 #define MAX_CHAIN_DEPTH 100000 static int max_queue_depth = -1; module_param(max_queue_depth, int, 0444); MODULE_PARM_DESC(max_queue_depth, " max controller queue depth "); static int max_sgl_entries = -1; module_param(max_sgl_entries, int, 0444); MODULE_PARM_DESC(max_sgl_entries, " max sg entries "); static int msix_disable = -1; module_param(msix_disable, int, 0444); MODULE_PARM_DESC(msix_disable, " disable msix routed interrupts (default=0)"); static int smp_affinity_enable = 1; module_param(smp_affinity_enable, int, 0444); MODULE_PARM_DESC(smp_affinity_enable, "SMP affinity feature enable/disable Default: enable(1)"); static int max_msix_vectors = -1; module_param(max_msix_vectors, int, 0444); MODULE_PARM_DESC(max_msix_vectors, " max msix vectors"); static int irqpoll_weight = -1; module_param(irqpoll_weight, int, 0444); MODULE_PARM_DESC(irqpoll_weight, "irq poll weight (default= one fourth of HBA queue depth)"); static int mpt3sas_fwfault_debug; MODULE_PARM_DESC(mpt3sas_fwfault_debug, " enable detection of firmware fault and halt firmware - (default=0)"); static int perf_mode = -1; module_param(perf_mode, int, 0444); MODULE_PARM_DESC(perf_mode, "Performance mode (only for Aero/Sea Generation), options:\n\t\t" "0 - balanced: high iops mode is enabled &\n\t\t" "interrupt coalescing is enabled only on high iops queues,\n\t\t" "1 - iops: high iops mode is disabled &\n\t\t" "interrupt coalescing is enabled on all queues,\n\t\t" "2 - latency: high iops mode is disabled &\n\t\t" "interrupt coalescing is enabled on all queues with timeout value 0xA,\n" "\t\tdefault - default perf_mode is 'balanced'" ); static int poll_queues; module_param(poll_queues, int, 0444); MODULE_PARM_DESC(poll_queues, "Number of queues to be use for io_uring poll mode.\n\t\t" "This parameter is effective only if host_tagset_enable=1. &\n\t\t" "when poll_queues are enabled then &\n\t\t" "perf_mode is set to latency mode. &\n\t\t" ); enum mpt3sas_perf_mode { MPT_PERF_MODE_DEFAULT = -1, MPT_PERF_MODE_BALANCED = 0, MPT_PERF_MODE_IOPS = 1, MPT_PERF_MODE_LATENCY = 2, }; static int _base_wait_on_iocstate(struct MPT3SAS_ADAPTER *ioc, u32 ioc_state, int timeout); static int _base_get_ioc_facts(struct MPT3SAS_ADAPTER *ioc); static void _base_clear_outstanding_commands(struct MPT3SAS_ADAPTER *ioc); /** * mpt3sas_base_check_cmd_timeout - Function * to check timeout and command termination due * to Host reset. * * @ioc: per adapter object. * @status: Status of issued command. * @mpi_request:mf request pointer. * @sz: size of buffer. * * Return: 1/0 Reset to be done or Not */ u8 mpt3sas_base_check_cmd_timeout(struct MPT3SAS_ADAPTER *ioc, u8 status, void *mpi_request, int sz) { u8 issue_reset = 0; if (!(status & MPT3_CMD_RESET)) issue_reset = 1; ioc_err(ioc, "Command %s\n", issue_reset == 0 ? "terminated due to Host Reset" : "Timeout"); _debug_dump_mf(mpi_request, sz); return issue_reset; } /** * _scsih_set_fwfault_debug - global setting of ioc->fwfault_debug. * @val: ? * @kp: ? * * Return: ? */ static int _scsih_set_fwfault_debug(const char *val, const struct kernel_param *kp) { int ret = param_set_int(val, kp); struct MPT3SAS_ADAPTER *ioc; if (ret) return ret; /* global ioc spinlock to protect controller list on list operations */ pr_info("setting fwfault_debug(%d)\n", mpt3sas_fwfault_debug); spin_lock(&gioc_lock); list_for_each_entry(ioc, &mpt3sas_ioc_list, list) ioc->fwfault_debug = mpt3sas_fwfault_debug; spin_unlock(&gioc_lock); return 0; } module_param_call(mpt3sas_fwfault_debug, _scsih_set_fwfault_debug, param_get_int, &mpt3sas_fwfault_debug, 0644); /** * _base_readl_aero - retry readl for max three times. * @addr: MPT Fusion system interface register address * * Retry the readl() for max three times if it gets zero value * while reading the system interface register. */ static inline u32 _base_readl_aero(const volatile void __iomem *addr) { u32 i = 0, ret_val; do { ret_val = readl(addr); i++; } while (ret_val == 0 && i < 3); return ret_val; } static inline u32 _base_readl(const volatile void __iomem *addr) { return readl(addr); } /** * _base_clone_reply_to_sys_mem - copies reply to reply free iomem * in BAR0 space. * * @ioc: per adapter object * @reply: reply message frame(lower 32bit addr) * @index: System request message index. */ static void _base_clone_reply_to_sys_mem(struct MPT3SAS_ADAPTER *ioc, u32 reply, u32 index) { /* * 256 is offset within sys register. * 256 offset MPI frame starts. Max MPI frame supported is 32. * 32 * 128 = 4K. From here, Clone of reply free for mcpu starts */ u16 cmd_credit = ioc->facts.RequestCredit + 1; void __iomem *reply_free_iomem = (void __iomem *)ioc->chip + MPI_FRAME_START_OFFSET + (cmd_credit * ioc->request_sz) + (index * sizeof(u32)); writel(reply, reply_free_iomem); } /** * _base_clone_mpi_to_sys_mem - Writes/copies MPI frames * to system/BAR0 region. * * @dst_iomem: Pointer to the destination location in BAR0 space. * @src: Pointer to the Source data. * @size: Size of data to be copied. */ static void _base_clone_mpi_to_sys_mem(void *dst_iomem, void *src, u32 size) { int i; u32 *src_virt_mem = (u32 *)src; for (i = 0; i < size/4; i++) writel((u32)src_virt_mem[i], (void __iomem *)dst_iomem + (i * 4)); } /** * _base_clone_to_sys_mem - Writes/copies data to system/BAR0 region * * @dst_iomem: Pointer to the destination location in BAR0 space. * @src: Pointer to the Source data. * @size: Size of data to be copied. */ static void _base_clone_to_sys_mem(void __iomem *dst_iomem, void *src, u32 size) { int i; u32 *src_virt_mem = (u32 *)(src); for (i = 0; i < size/4; i++) writel((u32)src_virt_mem[i], (void __iomem *)dst_iomem + (i * 4)); } /** * _base_get_chain - Calculates and Returns virtual chain address * for the provided smid in BAR0 space. * * @ioc: per adapter object * @smid: system request message index * @sge_chain_count: Scatter gather chain count. * * Return: the chain address. */ static inline void __iomem* _base_get_chain(struct MPT3SAS_ADAPTER *ioc, u16 smid, u8 sge_chain_count) { void __iomem *base_chain, *chain_virt; u16 cmd_credit = ioc->facts.RequestCredit + 1; base_chain = (void __iomem *)ioc->chip + MPI_FRAME_START_OFFSET + (cmd_credit * ioc->request_sz) + REPLY_FREE_POOL_SIZE; chain_virt = base_chain + (smid * ioc->facts.MaxChainDepth * ioc->request_sz) + (sge_chain_count * ioc->request_sz); return chain_virt; } /** * _base_get_chain_phys - Calculates and Returns physical address * in BAR0 for scatter gather chains, for * the provided smid. * * @ioc: per adapter object * @smid: system request message index * @sge_chain_count: Scatter gather chain count. * * Return: Physical chain address. */ static inline phys_addr_t _base_get_chain_phys(struct MPT3SAS_ADAPTER *ioc, u16 smid, u8 sge_chain_count) { phys_addr_t base_chain_phys, chain_phys; u16 cmd_credit = ioc->facts.RequestCredit + 1; base_chain_phys = ioc->chip_phys + MPI_FRAME_START_OFFSET + (cmd_credit * ioc->request_sz) + REPLY_FREE_POOL_SIZE; chain_phys = base_chain_phys + (smid * ioc->facts.MaxChainDepth * ioc->request_sz) + (sge_chain_count * ioc->request_sz); return chain_phys; } /** * _base_get_buffer_bar0 - Calculates and Returns BAR0 mapped Host * buffer address for the provided smid. * (Each smid can have 64K starts from 17024) * * @ioc: per adapter object * @smid: system request message index * * Return: Pointer to buffer location in BAR0. */ static void __iomem * _base_get_buffer_bar0(struct MPT3SAS_ADAPTER *ioc, u16 smid) { u16 cmd_credit = ioc->facts.RequestCredit + 1; // Added extra 1 to reach end of chain. void __iomem *chain_end = _base_get_chain(ioc, cmd_credit + 1, ioc->facts.MaxChainDepth); return chain_end + (smid * 64 * 1024); } /** * _base_get_buffer_phys_bar0 - Calculates and Returns BAR0 mapped * Host buffer Physical address for the provided smid. * (Each smid can have 64K starts from 17024) * * @ioc: per adapter object * @smid: system request message index * * Return: Pointer to buffer location in BAR0. */ static phys_addr_t _base_get_buffer_phys_bar0(struct MPT3SAS_ADAPTER *ioc, u16 smid) { u16 cmd_credit = ioc->facts.RequestCredit + 1; phys_addr_t chain_end_phys = _base_get_chain_phys(ioc, cmd_credit + 1, ioc->facts.MaxChainDepth); return chain_end_phys + (smid * 64 * 1024); } /** * _base_get_chain_buffer_dma_to_chain_buffer - Iterates chain * lookup list and Provides chain_buffer * address for the matching dma address. * (Each smid can have 64K starts from 17024) * * @ioc: per adapter object * @chain_buffer_dma: Chain buffer dma address. * * Return: Pointer to chain buffer. Or Null on Failure. */ static void * _base_get_chain_buffer_dma_to_chain_buffer(struct MPT3SAS_ADAPTER *ioc, dma_addr_t chain_buffer_dma) { u16 index, j; struct chain_tracker *ct; for (index = 0; index < ioc->scsiio_depth; index++) { for (j = 0; j < ioc->chains_needed_per_io; j++) { ct = &ioc->chain_lookup[index].chains_per_smid[j]; if (ct && ct->chain_buffer_dma == chain_buffer_dma) return ct->chain_buffer; } } ioc_info(ioc, "Provided chain_buffer_dma address is not in the lookup list\n"); return NULL; } /** * _clone_sg_entries - MPI EP's scsiio and config requests * are handled here. Base function for * double buffering, before submitting * the requests. * * @ioc: per adapter object. * @mpi_request: mf request pointer. * @smid: system request message index. */ static void _clone_sg_entries(struct MPT3SAS_ADAPTER *ioc, void *mpi_request, u16 smid) { Mpi2SGESimple32_t *sgel, *sgel_next; u32 sgl_flags, sge_chain_count = 0; bool is_write = false; u16 i = 0; void __iomem *buffer_iomem; phys_addr_t buffer_iomem_phys; void __iomem *buff_ptr; phys_addr_t buff_ptr_phys; void __iomem *dst_chain_addr[MCPU_MAX_CHAINS_PER_IO]; void *src_chain_addr[MCPU_MAX_CHAINS_PER_IO]; phys_addr_t dst_addr_phys; MPI2RequestHeader_t *request_hdr; struct scsi_cmnd *scmd; struct scatterlist *sg_scmd = NULL; int is_scsiio_req = 0; request_hdr = (MPI2RequestHeader_t *) mpi_request; if (request_hdr->Function == MPI2_FUNCTION_SCSI_IO_REQUEST) { Mpi25SCSIIORequest_t *scsiio_request = (Mpi25SCSIIORequest_t *)mpi_request; sgel = (Mpi2SGESimple32_t *) &scsiio_request->SGL; is_scsiio_req = 1; } else if (request_hdr->Function == MPI2_FUNCTION_CONFIG) { Mpi2ConfigRequest_t *config_req = (Mpi2ConfigRequest_t *)mpi_request; sgel = (Mpi2SGESimple32_t *) &config_req->PageBufferSGE; } else return; /* From smid we can get scsi_cmd, once we have sg_scmd, * we just need to get sg_virt and sg_next to get virtual * address associated with sgel->Address. */ if (is_scsiio_req) { /* Get scsi_cmd using smid */ scmd = mpt3sas_scsih_scsi_lookup_get(ioc, smid); if (scmd == NULL) { ioc_err(ioc, "scmd is NULL\n"); return; } /* Get sg_scmd from scmd provided */ sg_scmd = scsi_sglist(scmd); } /* * 0 - 255 System register * 256 - 4352 MPI Frame. (This is based on maxCredit 32) * 4352 - 4864 Reply_free pool (512 byte is reserved * considering maxCredit 32. Reply need extra * room, for mCPU case kept four times of * maxCredit). * 4864 - 17152 SGE chain element. (32cmd * 3 chain of * 128 byte size = 12288) * 17152 - x Host buffer mapped with smid. * (Each smid can have 64K Max IO.) * BAR0+Last 1K MSIX Addr and Data * Total size in use 2113664 bytes of 4MB BAR0 */ buffer_iomem = _base_get_buffer_bar0(ioc, smid); buffer_iomem_phys = _base_get_buffer_phys_bar0(ioc, smid); buff_ptr = buffer_iomem; buff_ptr_phys = buffer_iomem_phys; WARN_ON(buff_ptr_phys > U32_MAX); if (le32_to_cpu(sgel->FlagsLength) & (MPI2_SGE_FLAGS_HOST_TO_IOC << MPI2_SGE_FLAGS_SHIFT)) is_write = true; for (i = 0; i < MPT_MIN_PHYS_SEGMENTS + ioc->facts.MaxChainDepth; i++) { sgl_flags = (le32_to_cpu(sgel->FlagsLength) >> MPI2_SGE_FLAGS_SHIFT); switch (sgl_flags & MPI2_SGE_FLAGS_ELEMENT_MASK) { case MPI2_SGE_FLAGS_CHAIN_ELEMENT: /* * Helper function which on passing * chain_buffer_dma returns chain_buffer. Get * the virtual address for sgel->Address */ sgel_next = _base_get_chain_buffer_dma_to_chain_buffer(ioc, le32_to_cpu(sgel->Address)); if (sgel_next == NULL) return; /* * This is coping 128 byte chain * frame (not a host buffer) */ dst_chain_addr[sge_chain_count] = _base_get_chain(ioc, smid, sge_chain_count); src_chain_addr[sge_chain_count] = (void *) sgel_next; dst_addr_phys = _base_get_chain_phys(ioc, smid, sge_chain_count); WARN_ON(dst_addr_phys > U32_MAX); sgel->Address = cpu_to_le32(lower_32_bits(dst_addr_phys)); sgel = sgel_next; sge_chain_count++; break; case MPI2_SGE_FLAGS_SIMPLE_ELEMENT: if (is_write) { if (is_scsiio_req) { _base_clone_to_sys_mem(buff_ptr, sg_virt(sg_scmd), (le32_to_cpu(sgel->FlagsLength) & 0x00ffffff)); /* * FIXME: this relies on a a zero * PCI mem_offset. */ sgel->Address = cpu_to_le32((u32)buff_ptr_phys); } else { _base_clone_to_sys_mem(buff_ptr, ioc->config_vaddr, (le32_to_cpu(sgel->FlagsLength) & 0x00ffffff)); sgel->Address = cpu_to_le32((u32)buff_ptr_phys); } } buff_ptr += (le32_to_cpu(sgel->FlagsLength) & 0x00ffffff); buff_ptr_phys += (le32_to_cpu(sgel->FlagsLength) & 0x00ffffff); if ((le32_to_cpu(sgel->FlagsLength) & (MPI2_SGE_FLAGS_END_OF_BUFFER << MPI2_SGE_FLAGS_SHIFT))) goto eob_clone_chain; else { /* * Every single element in MPT will have * associated sg_next. Better to sanity that * sg_next is not NULL, but it will be a bug * if it is null. */ if (is_scsiio_req) { sg_scmd = sg_next(sg_scmd); if (sg_scmd) sgel++; else goto eob_clone_chain; } } break; } } eob_clone_chain: for (i = 0; i < sge_chain_count; i++) { if (is_scsiio_req) _base_clone_to_sys_mem(dst_chain_addr[i], src_chain_addr[i], ioc->request_sz); } } /** * mpt3sas_remove_dead_ioc_func - kthread context to remove dead ioc * @arg: input argument, used to derive ioc * * Return: * 0 if controller is removed from pci subsystem. * -1 for other case. */ static int mpt3sas_remove_dead_ioc_func(void *arg) { struct MPT3SAS_ADAPTER *ioc = (struct MPT3SAS_ADAPTER *)arg; struct pci_dev *pdev; if (!ioc) return -1; pdev = ioc->pdev; if (!pdev) return -1; pci_stop_and_remove_bus_device_locked(pdev); return 0; } /** * _base_sync_drv_fw_timestamp - Sync Drive-Fw TimeStamp. * @ioc: Per Adapter Object * * Return: nothing. */ static void _base_sync_drv_fw_timestamp(struct MPT3SAS_ADAPTER *ioc) { Mpi26IoUnitControlRequest_t *mpi_request; Mpi26IoUnitControlReply_t *mpi_reply; u16 smid; ktime_t current_time; u64 TimeStamp = 0; u8 issue_reset = 0; mutex_lock(&ioc->scsih_cmds.mutex); if (ioc->scsih_cmds.status != MPT3_CMD_NOT_USED) { ioc_err(ioc, "scsih_cmd in use %s\n", __func__); goto out; } ioc->scsih_cmds.status = MPT3_CMD_PENDING; smid = mpt3sas_base_get_smid(ioc, ioc->scsih_cb_idx); if (!smid) { ioc_err(ioc, "Failed obtaining a smid %s\n", __func__); ioc->scsih_cmds.status = MPT3_CMD_NOT_USED; goto out; } mpi_request = mpt3sas_base_get_msg_frame(ioc, smid); ioc->scsih_cmds.smid = smid; memset(mpi_request, 0, sizeof(Mpi26IoUnitControlRequest_t)); mpi_request->Function = MPI2_FUNCTION_IO_UNIT_CONTROL; mpi_request->Operation = MPI26_CTRL_OP_SET_IOC_PARAMETER; mpi_request->IOCParameter = MPI26_SET_IOC_PARAMETER_SYNC_TIMESTAMP; current_time = ktime_get_real(); TimeStamp = ktime_to_ms(current_time); mpi_request->Reserved7 = cpu_to_le32(TimeStamp >> 32); mpi_request->IOCParameterValue = cpu_to_le32(TimeStamp & 0xFFFFFFFF); init_completion(&ioc->scsih_cmds.done); ioc->put_smid_default(ioc, smid); dinitprintk(ioc, ioc_info(ioc, "Io Unit Control Sync TimeStamp (sending), @time %lld ms\n", TimeStamp)); wait_for_completion_timeout(&ioc->scsih_cmds.done, MPT3SAS_TIMESYNC_TIMEOUT_SECONDS*HZ); if (!(ioc->scsih_cmds.status & MPT3_CMD_COMPLETE)) { mpt3sas_check_cmd_timeout(ioc, ioc->scsih_cmds.status, mpi_request, sizeof(Mpi2SasIoUnitControlRequest_t)/4, issue_reset); goto issue_host_reset; } if (ioc->scsih_cmds.status & MPT3_CMD_REPLY_VALID) { mpi_reply = ioc->scsih_cmds.reply; dinitprintk(ioc, ioc_info(ioc, "Io Unit Control sync timestamp (complete): ioc_status(0x%04x), loginfo(0x%08x)\n", le16_to_cpu(mpi_reply->IOCStatus), le32_to_cpu(mpi_reply->IOCLogInfo))); } issue_host_reset: if (issue_reset) mpt3sas_base_hard_reset_handler(ioc, FORCE_BIG_HAMMER); ioc->scsih_cmds.status = MPT3_CMD_NOT_USED; out: mutex_unlock(&ioc->scsih_cmds.mutex); } /** * _base_fault_reset_work - workq handling ioc fault conditions * @work: input argument, used to derive ioc * * Context: sleep. */ static void _base_fault_reset_work(struct work_struct *work) { struct MPT3SAS_ADAPTER *ioc = container_of(work, struct MPT3SAS_ADAPTER, fault_reset_work.work); unsigned long flags; u32 doorbell; int rc; struct task_struct *p; spin_lock_irqsave(&ioc->ioc_reset_in_progress_lock, flags); if ((ioc->shost_recovery && (ioc->ioc_coredump_loop == 0)) || ioc->pci_error_recovery) goto rearm_timer; spin_unlock_irqrestore(&ioc->ioc_reset_in_progress_lock, flags); doorbell = mpt3sas_base_get_iocstate(ioc, 0); if ((doorbell & MPI2_IOC_STATE_MASK) == MPI2_IOC_STATE_MASK) { ioc_err(ioc, "SAS host is non-operational !!!!\n"); /* It may be possible that EEH recovery can resolve some of * pci bus failure issues rather removing the dead ioc function * by considering controller is in a non-operational state. So * here priority is given to the EEH recovery. If it doesn't * not resolve this issue, mpt3sas driver will consider this * controller to non-operational state and remove the dead ioc * function. */ if (ioc->non_operational_loop++ < 5) { spin_lock_irqsave(&ioc->ioc_reset_in_progress_lock, flags); goto rearm_timer; } /* * Call _scsih_flush_pending_cmds callback so that we flush all * pending commands back to OS. This call is required to avoid * deadlock at block layer. Dead IOC will fail to do diag reset, * and this call is safe since dead ioc will never return any * command back from HW. */ mpt3sas_base_pause_mq_polling(ioc); ioc->schedule_dead_ioc_flush_running_cmds(ioc); /* * Set remove_host flag early since kernel thread will * take some time to execute. */ ioc->remove_host = 1; /*Remove the Dead Host */ p = kthread_run(mpt3sas_remove_dead_ioc_func, ioc, "%s_dead_ioc_%d", ioc->driver_name, ioc->id); if (IS_ERR(p)) ioc_err(ioc, "%s: Running mpt3sas_dead_ioc thread failed !!!!\n", __func__); else ioc_err(ioc, "%s: Running mpt3sas_dead_ioc thread success !!!!\n", __func__); return; /* don't rearm timer */ } if ((doorbell & MPI2_IOC_STATE_MASK) == MPI2_IOC_STATE_COREDUMP) { u8 timeout = (ioc->manu_pg11.CoreDumpTOSec) ? ioc->manu_pg11.CoreDumpTOSec : MPT3SAS_DEFAULT_COREDUMP_TIMEOUT_SECONDS; timeout /= (FAULT_POLLING_INTERVAL/1000); if (ioc->ioc_coredump_loop == 0) { mpt3sas_print_coredump_info(ioc, doorbell & MPI2_DOORBELL_DATA_MASK); /* do not accept any IOs and disable the interrupts */ spin_lock_irqsave( &ioc->ioc_reset_in_progress_lock, flags); ioc->shost_recovery = 1; spin_unlock_irqrestore( &ioc->ioc_reset_in_progress_lock, flags); mpt3sas_base_mask_interrupts(ioc); mpt3sas_base_pause_mq_polling(ioc); _base_clear_outstanding_commands(ioc); } ioc_info(ioc, "%s: CoreDump loop %d.", __func__, ioc->ioc_coredump_loop); /* Wait until CoreDump completes or times out */ if (ioc->ioc_coredump_loop++ < timeout) { spin_lock_irqsave( &ioc->ioc_reset_in_progress_lock, flags); goto rearm_timer; } } if (ioc->ioc_coredump_loop) { if ((doorbell & MPI2_IOC_STATE_MASK) != MPI2_IOC_STATE_COREDUMP) ioc_err(ioc, "%s: CoreDump completed. LoopCount: %d", __func__, ioc->ioc_coredump_loop); else ioc_err(ioc, "%s: CoreDump Timed out. LoopCount: %d", __func__, ioc->ioc_coredump_loop); ioc->ioc_coredump_loop = MPT3SAS_COREDUMP_LOOP_DONE; } ioc->non_operational_loop = 0; if ((doorbell & MPI2_IOC_STATE_MASK) != MPI2_IOC_STATE_OPERATIONAL) { rc = mpt3sas_base_hard_reset_handler(ioc, FORCE_BIG_HAMMER); ioc_warn(ioc, "%s: hard reset: %s\n", __func__, rc == 0 ? "success" : "failed"); doorbell = mpt3sas_base_get_iocstate(ioc, 0); if ((doorbell & MPI2_IOC_STATE_MASK) == MPI2_IOC_STATE_FAULT) { mpt3sas_print_fault_code(ioc, doorbell & MPI2_DOORBELL_DATA_MASK); } else if ((doorbell & MPI2_IOC_STATE_MASK) == MPI2_IOC_STATE_COREDUMP) mpt3sas_print_coredump_info(ioc, doorbell & MPI2_DOORBELL_DATA_MASK); if (rc && (doorbell & MPI2_IOC_STATE_MASK) != MPI2_IOC_STATE_OPERATIONAL) return; /* don't rearm timer */ } ioc->ioc_coredump_loop = 0; if (ioc->time_sync_interval && ++ioc->timestamp_update_count >= ioc->time_sync_interval) { ioc->timestamp_update_count = 0; _base_sync_drv_fw_timestamp(ioc); } spin_lock_irqsave(&ioc->ioc_reset_in_progress_lock, flags); rearm_timer: if (ioc->fault_reset_work_q) queue_delayed_work(ioc->fault_reset_work_q, &ioc->fault_reset_work, msecs_to_jiffies(FAULT_POLLING_INTERVAL)); spin_unlock_irqrestore(&ioc->ioc_reset_in_progress_lock, flags); } /** * mpt3sas_base_start_watchdog - start the fault_reset_work_q * @ioc: per adapter object * * Context: sleep. */ void mpt3sas_base_start_watchdog(struct MPT3SAS_ADAPTER *ioc) { unsigned long flags; if (ioc->fault_reset_work_q) return; ioc->timestamp_update_count = 0; /* initialize fault polling */ INIT_DELAYED_WORK(&ioc->fault_reset_work, _base_fault_reset_work); snprintf(ioc->fault_reset_work_q_name, sizeof(ioc->fault_reset_work_q_name), "poll_%s%d_status", ioc->driver_name, ioc->id); ioc->fault_reset_work_q = create_singlethread_workqueue(ioc->fault_reset_work_q_name); if (!ioc->fault_reset_work_q) { ioc_err(ioc, "%s: failed (line=%d)\n", __func__, __LINE__); return; } spin_lock_irqsave(&ioc->ioc_reset_in_progress_lock, flags); if (ioc->fault_reset_work_q) queue_delayed_work(ioc->fault_reset_work_q, &ioc->fault_reset_work, msecs_to_jiffies(FAULT_POLLING_INTERVAL)); spin_unlock_irqrestore(&ioc->ioc_reset_in_progress_lock, flags); } /** * mpt3sas_base_stop_watchdog - stop the fault_reset_work_q * @ioc: per adapter object * * Context: sleep. */ void mpt3sas_base_stop_watchdog(struct MPT3SAS_ADAPTER *ioc) { unsigned long flags; struct workqueue_struct *wq; spin_lock_irqsave(&ioc->ioc_reset_in_progress_lock, flags); wq = ioc->fault_reset_work_q; ioc->fault_reset_work_q = NULL; spin_unlock_irqrestore(&ioc->ioc_reset_in_progress_lock, flags); if (wq) { if (!cancel_delayed_work_sync(&ioc->fault_reset_work)) flush_workqueue(wq); destroy_workqueue(wq); } } /** * mpt3sas_base_fault_info - verbose translation of firmware FAULT code * @ioc: per adapter object * @fault_code: fault code */ void mpt3sas_base_fault_info(struct MPT3SAS_ADAPTER *ioc , u16 fault_code) { ioc_err(ioc, "fault_state(0x%04x)!\n", fault_code); } /** * mpt3sas_base_coredump_info - verbose translation of firmware CoreDump state * @ioc: per adapter object * @fault_code: fault code * * Return: nothing. */ void mpt3sas_base_coredump_info(struct MPT3SAS_ADAPTER *ioc, u16 fault_code) { ioc_err(ioc, "coredump_state(0x%04x)!\n", fault_code); } /** * mpt3sas_base_wait_for_coredump_completion - Wait until coredump * completes or times out * @ioc: per adapter object * @caller: caller function name * * Return: 0 for success, non-zero for failure. */ int mpt3sas_base_wait_for_coredump_completion(struct MPT3SAS_ADAPTER *ioc, const char *caller) { u8 timeout = (ioc->manu_pg11.CoreDumpTOSec) ? ioc->manu_pg11.CoreDumpTOSec : MPT3SAS_DEFAULT_COREDUMP_TIMEOUT_SECONDS; int ioc_state = _base_wait_on_iocstate(ioc, MPI2_IOC_STATE_FAULT, timeout); if (ioc_state) ioc_err(ioc, "%s: CoreDump timed out. (ioc_state=0x%x)\n", caller, ioc_state); else ioc_info(ioc, "%s: CoreDump completed. (ioc_state=0x%x)\n", caller, ioc_state); return ioc_state; } /** * mpt3sas_halt_firmware - halt's mpt controller firmware * @ioc: per adapter object * * For debugging timeout related issues. Writing 0xCOFFEE00 * to the doorbell register will halt controller firmware. With * the purpose to stop both driver and firmware, the enduser can * obtain a ring buffer from controller UART. */ void mpt3sas_halt_firmware(struct MPT3SAS_ADAPTER *ioc) { u32 doorbell; if (!ioc->fwfault_debug) return; dump_stack(); doorbell = ioc->base_readl(&ioc->chip->Doorbell); if ((doorbell & MPI2_IOC_STATE_MASK) == MPI2_IOC_STATE_FAULT) { mpt3sas_print_fault_code(ioc, doorbell & MPI2_DOORBELL_DATA_MASK); } else if ((doorbell & MPI2_IOC_STATE_MASK) == MPI2_IOC_STATE_COREDUMP) { mpt3sas_print_coredump_info(ioc, doorbell & MPI2_DOORBELL_DATA_MASK); } else { writel(0xC0FFEE00, &ioc->chip->Doorbell); ioc_err(ioc, "Firmware is halted due to command timeout\n"); } if (ioc->fwfault_debug == 2) for (;;) ; else panic("panic in %s\n", __func__); } /** * _base_sas_ioc_info - verbose translation of the ioc status * @ioc: per adapter object * @mpi_reply: reply mf payload returned from firmware * @request_hdr: request mf */ static void _base_sas_ioc_info(struct MPT3SAS_ADAPTER *ioc, MPI2DefaultReply_t *mpi_reply, MPI2RequestHeader_t *request_hdr) { u16 ioc_status = le16_to_cpu(mpi_reply->IOCStatus) & MPI2_IOCSTATUS_MASK; char *desc = NULL; u16 frame_sz; char *func_str = NULL; /* SCSI_IO, RAID_PASS are handled from _scsih_scsi_ioc_info */ if (request_hdr->Function == MPI2_FUNCTION_SCSI_IO_REQUEST || request_hdr->Function == MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH || request_hdr->Function == MPI2_FUNCTION_EVENT_NOTIFICATION) return; if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE) return; /* * Older Firmware version doesn't support driver trigger pages. * So, skip displaying 'config invalid type' type * of error message. */ if (request_hdr->Function == MPI2_FUNCTION_CONFIG) { Mpi2ConfigRequest_t *rqst = (Mpi2ConfigRequest_t *)request_hdr; if ((rqst->ExtPageType == MPI2_CONFIG_EXTPAGETYPE_DRIVER_PERSISTENT_TRIGGER) && !(ioc->logging_level & MPT_DEBUG_CONFIG)) { return; } } switch (ioc_status) { /**************************************************************************** * Common IOCStatus values for all replies ****************************************************************************/ case MPI2_IOCSTATUS_INVALID_FUNCTION: desc = "invalid function"; break; case MPI2_IOCSTATUS_BUSY: desc = "busy"; break; case MPI2_IOCSTATUS_INVALID_SGL: desc = "invalid sgl"; break; case MPI2_IOCSTATUS_INTERNAL_ERROR: desc = "internal error"; break; case MPI2_IOCSTATUS_INVALID_VPID: desc = "invalid vpid"; break; case MPI2_IOCSTATUS_INSUFFICIENT_RESOURCES: desc = "insufficient resources"; break; case MPI2_IOCSTATUS_INSUFFICIENT_POWER: desc = "insufficient power"; break; case MPI2_IOCSTATUS_INVALID_FIELD: desc = "invalid field"; break; case MPI2_IOCSTATUS_INVALID_STATE: desc = "invalid state"; break; case MPI2_IOCSTATUS_OP_STATE_NOT_SUPPORTED: desc = "op state not supported"; break; /**************************************************************************** * Config IOCStatus values ****************************************************************************/ case MPI2_IOCSTATUS_CONFIG_INVALID_ACTION: desc = "config invalid action"; break; case MPI2_IOCSTATUS_CONFIG_INVALID_TYPE: desc = "config invalid type"; break; case MPI2_IOCSTATUS_CONFIG_INVALID_PAGE: desc = "config invalid page"; break; case MPI2_IOCSTATUS_CONFIG_INVALID_DATA: desc = "config invalid data"; break; case MPI2_IOCSTATUS_CONFIG_NO_DEFAULTS: desc = "config no defaults"; break; case MPI2_IOCSTATUS_CONFIG_CANT_COMMIT: desc = "config cant commit"; break; /**************************************************************************** * SCSI IO Reply ****************************************************************************/ case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR: case MPI2_IOCSTATUS_SCSI_INVALID_DEVHANDLE: case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE: case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN: case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN: case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR: case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR: case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED: case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH: case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED: case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED: case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED: break; /**************************************************************************** * For use by SCSI Initiator and SCSI Target end-to-end data protection ****************************************************************************/ case MPI2_IOCSTATUS_EEDP_GUARD_ERROR: desc = "eedp guard error"; break; case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR: desc = "eedp ref tag error"; break; case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR: desc = "eedp app tag error"; break; /**************************************************************************** * SCSI Target values ****************************************************************************/ case MPI2_IOCSTATUS_TARGET_INVALID_IO_INDEX: desc = "target invalid io index"; break; case MPI2_IOCSTATUS_TARGET_ABORTED: desc = "target aborted"; break; case MPI2_IOCSTATUS_TARGET_NO_CONN_RETRYABLE: desc = "target no conn retryable"; break; case MPI2_IOCSTATUS_TARGET_NO_CONNECTION: desc = "target no connection"; break; case MPI2_IOCSTATUS_TARGET_XFER_COUNT_MISMATCH: desc = "target xfer count mismatch"; break; case MPI2_IOCSTATUS_TARGET_DATA_OFFSET_ERROR: desc = "target data offset error"; break; case MPI2_IOCSTATUS_TARGET_TOO_MUCH_WRITE_DATA: desc = "target too much write data"; break; case MPI2_IOCSTATUS_TARGET_IU_TOO_SHORT: desc = "target iu too short"; break; case MPI2_IOCSTATUS_TARGET_ACK_NAK_TIMEOUT: desc = "target ack nak timeout"; break; case MPI2_IOCSTATUS_TARGET_NAK_RECEIVED: desc = "target nak received"; break; /**************************************************************************** * Serial Attached SCSI values ****************************************************************************/ case MPI2_IOCSTATUS_SAS_SMP_REQUEST_FAILED: desc = "smp request failed"; break; case MPI2_IOCSTATUS_SAS_SMP_DATA_OVERRUN: desc = "smp data overrun"; break; /**************************************************************************** * Diagnostic Buffer Post / Diagnostic Release values ****************************************************************************/ case MPI2_IOCSTATUS_DIAGNOSTIC_RELEASED: desc = "diagnostic released"; break; default: break; } if (!desc) return; switch (request_hdr->Function) { case MPI2_FUNCTION_CONFIG: frame_sz = sizeof(Mpi2ConfigRequest_t) + ioc->sge_size; func_str = "config_page"; break; case MPI2_FUNCTION_SCSI_TASK_MGMT: frame_sz = sizeof(Mpi2SCSITaskManagementRequest_t); func_str = "task_mgmt"; break; case MPI2_FUNCTION_SAS_IO_UNIT_CONTROL: frame_sz = sizeof(Mpi2SasIoUnitControlRequest_t); func_str = "sas_iounit_ctl"; break; case MPI2_FUNCTION_SCSI_ENCLOSURE_PROCESSOR: frame_sz = sizeof(Mpi2SepRequest_t); func_str = "enclosure"; break; case MPI2_FUNCTION_IOC_INIT: frame_sz = sizeof(Mpi2IOCInitRequest_t); func_str = "ioc_init"; break; case MPI2_FUNCTION_PORT_ENABLE: frame_sz = sizeof(Mpi2PortEnableRequest_t); func_str = "port_enable"; break; case MPI2_FUNCTION_SMP_PASSTHROUGH: frame_sz = sizeof(Mpi2SmpPassthroughRequest_t) + ioc->sge_size; func_str = "smp_passthru"; break; case MPI2_FUNCTION_NVME_ENCAPSULATED: frame_sz = sizeof(Mpi26NVMeEncapsulatedRequest_t) + ioc->sge_size; func_str = "nvme_encapsulated"; break; default: frame_sz = 32; func_str = "unknown"; break; } ioc_warn(ioc, "ioc_status: %s(0x%04x), request(0x%p),(%s)\n", desc, ioc_status, request_hdr, func_str); _debug_dump_mf(request_hdr, frame_sz/4); } /** * _base_display_event_data - verbose translation of firmware asyn events * @ioc: per adapter object * @mpi_reply: reply mf payload returned from firmware */ static void _base_display_event_data(struct MPT3SAS_ADAPTER *ioc, Mpi2EventNotificationReply_t *mpi_reply) { char *desc = NULL; u16 event; if (!(ioc->logging_level & MPT_DEBUG_EVENTS)) return; event = le16_to_cpu(mpi_reply->Event); switch (event) { case MPI2_EVENT_LOG_DATA: desc = "Log Data"; break; case MPI2_EVENT_STATE_CHANGE: desc = "Status Change"; break; case MPI2_EVENT_HARD_RESET_RECEIVED: desc = "Hard Reset Received"; break; case MPI2_EVENT_EVENT_CHANGE: desc = "Event Change"; break; case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE: desc = "Device Status Change"; break; case MPI2_EVENT_IR_OPERATION_STATUS: if (!ioc->hide_ir_msg) desc = "IR Operation Status"; break; case MPI2_EVENT_SAS_DISCOVERY: { Mpi2EventDataSasDiscovery_t *event_data = (Mpi2EventDataSasDiscovery_t *)mpi_reply->EventData; ioc_info(ioc, "Discovery: (%s)", event_data->ReasonCode == MPI2_EVENT_SAS_DISC_RC_STARTED ? "start" : "stop"); if (event_data->DiscoveryStatus) pr_cont(" discovery_status(0x%08x)", le32_to_cpu(event_data->DiscoveryStatus)); pr_cont("\n"); return; } case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE: desc = "SAS Broadcast Primitive"; break; case MPI2_EVENT_SAS_INIT_DEVICE_STATUS_CHANGE: desc = "SAS Init Device Status Change"; break; case MPI2_EVENT_SAS_INIT_TABLE_OVERFLOW: desc = "SAS Init Table Overflow"; break; case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST: desc = "SAS Topology Change List"; break; case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE: desc = "SAS Enclosure Device Status Change"; break; case MPI2_EVENT_IR_VOLUME: if (!ioc->hide_ir_msg) desc = "IR Volume"; break; case MPI2_EVENT_IR_PHYSICAL_DISK: if (!ioc->hide_ir_msg) desc = "IR Physical Disk"; break; case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST: if (!ioc->hide_ir_msg) desc = "IR Configuration Change List"; break; case MPI2_EVENT_LOG_ENTRY_ADDED: if (!ioc->hide_ir_msg) desc = "Log Entry Added"; break; case MPI2_EVENT_TEMP_THRESHOLD: desc = "Temperature Threshold"; break; case MPI2_EVENT_ACTIVE_CABLE_EXCEPTION: desc = "Cable Event"; break; case MPI2_EVENT_SAS_DEVICE_DISCOVERY_ERROR: desc = "SAS Device Discovery Error"; break; case MPI2_EVENT_PCIE_DEVICE_STATUS_CHANGE: desc = "PCIE Device Status Change"; break; case MPI2_EVENT_PCIE_ENUMERATION: { Mpi26EventDataPCIeEnumeration_t *event_data = (Mpi26EventDataPCIeEnumeration_t *)mpi_reply->EventData; ioc_info(ioc, "PCIE Enumeration: (%s)", event_data->ReasonCode == MPI26_EVENT_PCIE_ENUM_RC_STARTED ? "start" : "stop"); if (event_data->EnumerationStatus) pr_cont("enumeration_status(0x%08x)", le32_to_cpu(event_data->EnumerationStatus)); pr_cont("\n"); return; } case MPI2_EVENT_PCIE_TOPOLOGY_CHANGE_LIST: desc = "PCIE Topology Change List"; break; } if (!desc) return; ioc_info(ioc, "%s\n", desc); } /** * _base_sas_log_info - verbose translation of firmware log info * @ioc: per adapter object * @log_info: log info */ static void _base_sas_log_info(struct MPT3SAS_ADAPTER *ioc , u32 log_info) { union loginfo_type { u32 loginfo; struct { u32 subcode:16; u32 code:8; u32 originator:4; u32 bus_type:4; } dw; }; union loginfo_type sas_loginfo; char *originator_str = NULL; sas_loginfo.loginfo = log_info; if (sas_loginfo.dw.bus_type != 3 /*SAS*/) return; /* each nexus loss loginfo */ if (log_info == 0x31170000) return; /* eat the loginfos associated with task aborts */ if (ioc->ignore_loginfos && (log_info == 0x30050000 || log_info == 0x31140000 || log_info == 0x31130000)) return; switch (sas_loginfo.dw.originator) { case 0: originator_str = "IOP"; break; case 1: originator_str = "PL"; break; case 2: if (!ioc->hide_ir_msg) originator_str = "IR"; else originator_str = "WarpDrive"; break; } ioc_warn(ioc, "log_info(0x%08x): originator(%s), code(0x%02x), sub_code(0x%04x)\n", log_info, originator_str, sas_loginfo.dw.code, sas_loginfo.dw.subcode); } /** * _base_display_reply_info - handle reply descriptors depending on IOC Status * @ioc: per adapter object * @smid: system request message index * @msix_index: MSIX table index supplied by the OS * @reply: reply message frame (lower 32bit addr) */ static void _base_display_reply_info(struct MPT3SAS_ADAPTER *ioc, u16 smid, u8 msix_index, u32 reply) { MPI2DefaultReply_t *mpi_reply; u16 ioc_status; u32 loginfo = 0; mpi_reply = mpt3sas_base_get_reply_virt_addr(ioc, reply); if (unlikely(!mpi_reply)) { ioc_err(ioc, "mpi_reply not valid at %s:%d/%s()!\n", __FILE__, __LINE__, __func__); return; } ioc_status = le16_to_cpu(mpi_reply->IOCStatus); if ((ioc_status & MPI2_IOCSTATUS_MASK) && (ioc->logging_level & MPT_DEBUG_REPLY)) { _base_sas_ioc_info(ioc , mpi_reply, mpt3sas_base_get_msg_frame(ioc, smid)); } if (ioc_status & MPI2_IOCSTATUS_FLAG_LOG_INFO_AVAILABLE) { loginfo = le32_to_cpu(mpi_reply->IOCLogInfo); _base_sas_log_info(ioc, loginfo); } if (ioc_status || loginfo) { ioc_status &= MPI2_IOCSTATUS_MASK; mpt3sas_trigger_mpi(ioc, ioc_status, loginfo); } } /** * mpt3sas_base_done - base internal command completion routine * @ioc: per adapter object * @smid: system request message index * @msix_index: MSIX table index supplied by the OS * @reply: reply message frame(lower 32bit addr) * * Return: * 1 meaning mf should be freed from _base_interrupt * 0 means the mf is freed from this function. */ u8 mpt3sas_base_done(struct MPT3SAS_ADAPTER *ioc, u16 smid, u8 msix_index, u32 reply) { MPI2DefaultReply_t *mpi_reply; mpi_reply = mpt3sas_base_get_reply_virt_addr(ioc, reply); if (mpi_reply && mpi_reply->Function == MPI2_FUNCTION_EVENT_ACK) return mpt3sas_check_for_pending_internal_cmds(ioc, smid); if (ioc->base_cmds.status == MPT3_CMD_NOT_USED) return 1; ioc->base_cmds.status |= MPT3_CMD_COMPLETE; if (mpi_reply) { ioc->base_cmds.status |= MPT3_CMD_REPLY_VALID; memcpy(ioc->base_cmds.reply, mpi_reply, mpi_reply->MsgLength*4); } ioc->base_cmds.status &= ~MPT3_CMD_PENDING; complete(&ioc->base_cmds.done); return 1; } /** * _base_async_event - main callback handler for firmware asyn events * @ioc: per adapter object * @msix_index: MSIX table index supplied by the OS * @reply: reply message frame(lower 32bit addr) * * Return: * 1 meaning mf should be freed from _base_interrupt * 0 means the mf is freed from this function. */ static u8 _base_async_event(struct MPT3SAS_ADAPTER *ioc, u8 msix_index, u32 reply) { Mpi2EventNotificationReply_t *mpi_reply; Mpi2EventAckRequest_t *ack_request; u16 smid; struct _event_ack_list *delayed_event_ack; mpi_reply = mpt3sas_base_get_reply_virt_addr(ioc, reply); if (!mpi_reply) return 1; if (mpi_reply->Function != MPI2_FUNCTION_EVENT_NOTIFICATION) return 1; _base_display_event_data(ioc, mpi_reply); if (!(mpi_reply->AckRequired & MPI2_EVENT_NOTIFICATION_ACK_REQUIRED)) goto out; smid = mpt3sas_base_get_smid(ioc, ioc->base_cb_idx); if (!smid) { delayed_event_ack = kzalloc(sizeof(*delayed_event_ack), GFP_ATOMIC); if (!delayed_event_ack) goto out; INIT_LIST_HEAD(&delayed_event_ack->list); delayed_event_ack->Event = mpi_reply->Event; delayed_event_ack->EventContext = mpi_reply->EventContext; list_add_tail(&delayed_event_ack->list, &ioc->delayed_event_ack_list); dewtprintk(ioc, ioc_info(ioc, "DELAYED: EVENT ACK: event (0x%04x)\n", le16_to_cpu(mpi_reply->Event))); goto out; } ack_request = mpt3sas_base_get_msg_frame(ioc, smid); memset(ack_request, 0, sizeof(Mpi2EventAckRequest_t)); ack_request->Function = MPI2_FUNCTION_EVENT_ACK; ack_request->Event = mpi_reply->Event; ack_request->EventContext = mpi_reply->EventContext; ack_request->VF_ID = 0; /* TODO */ ack_request->VP_ID = 0; ioc->put_smid_default(ioc, smid); out: /* scsih callback handler */ mpt3sas_scsih_event_callback(ioc, msix_index, reply); /* ctl callback handler */ mpt3sas_ctl_event_callback(ioc, msix_index, reply); return 1; } static struct scsiio_tracker * _get_st_from_smid(struct MPT3SAS_ADAPTER *ioc, u16 smid) { struct scsi_cmnd *cmd; if (WARN_ON(!smid) || WARN_ON(smid >= ioc->hi_priority_smid)) return NULL; cmd = mpt3sas_scsih_scsi_lookup_get(ioc, smid); if (cmd) return scsi_cmd_priv(cmd); return NULL; } /** * _base_get_cb_idx - obtain the callback index * @ioc: per adapter object * @smid: system request message index * * Return: callback index. */ static u8 _base_get_cb_idx(struct MPT3SAS_ADAPTER *ioc, u16 smid) { int i; u16 ctl_smid = ioc->scsiio_depth - INTERNAL_SCSIIO_CMDS_COUNT + 1; u8 cb_idx = 0xFF; if (smid < ioc->hi_priority_smid) { struct scsiio_tracker *st; if (smid < ctl_smid) { st = _get_st_from_smid(ioc, smid); if (st) cb_idx = st->cb_idx; } else if (smid == ctl_smid) cb_idx = ioc->ctl_cb_idx; } else if (smid < ioc->internal_smid) { i = smid - ioc->hi_priority_smid; cb_idx = ioc->hpr_lookup[i].cb_idx; } else if (smid <= ioc->hba_queue_depth) { i = smid - ioc->internal_smid; cb_idx = ioc->internal_lookup[i].cb_idx; } return cb_idx; } /** * mpt3sas_base_pause_mq_polling - pause polling on the mq poll queues * when driver is flushing out the IOs. * @ioc: per adapter object * * Pause polling on the mq poll (io uring) queues when driver is flushing * out the IOs. Otherwise we may see the race condition of completing the same * IO from two paths. * * Returns nothing. */ void mpt3sas_base_pause_mq_polling(struct MPT3SAS_ADAPTER *ioc) { int iopoll_q_count = ioc->reply_queue_count - ioc->iopoll_q_start_index; int qid; for (qid = 0; qid < iopoll_q_count; qid++) atomic_set(&ioc->io_uring_poll_queues[qid].pause, 1); /* * wait for current poll to complete. */ for (qid = 0; qid < iopoll_q_count; qid++) { while (atomic_read(&ioc->io_uring_poll_queues[qid].busy)) { cpu_relax(); udelay(500); } } } /** * mpt3sas_base_resume_mq_polling - Resume polling on mq poll queues. * @ioc: per adapter object * * Returns nothing. */ void mpt3sas_base_resume_mq_polling(struct MPT3SAS_ADAPTER *ioc) { int iopoll_q_count = ioc->reply_queue_count - ioc->iopoll_q_start_index; int qid; for (qid = 0; qid < iopoll_q_count; qid++) atomic_set(&ioc->io_uring_poll_queues[qid].pause, 0); } /** * mpt3sas_base_mask_interrupts - disable interrupts * @ioc: per adapter object * * Disabling ResetIRQ, Reply and Doorbell Interrupts */ void mpt3sas_base_mask_interrupts(struct MPT3SAS_ADAPTER *ioc) { u32 him_register; ioc->mask_interrupts = 1; him_register = ioc->base_readl(&ioc->chip->HostInterruptMask); him_register |= MPI2_HIM_DIM + MPI2_HIM_RIM + MPI2_HIM_RESET_IRQ_MASK; writel(him_register, &ioc->chip->HostInterruptMask); ioc->base_readl(&ioc->chip->HostInterruptMask); } /** * mpt3sas_base_unmask_interrupts - enable interrupts * @ioc: per adapter object * * Enabling only Reply Interrupts */ void mpt3sas_base_unmask_interrupts(struct MPT3SAS_ADAPTER *ioc) { u32 him_register; him_register = ioc->base_readl(&ioc->chip->HostInterruptMask); him_register &= ~MPI2_HIM_RIM; writel(him_register, &ioc->chip->HostInterruptMask); ioc->mask_interrupts = 0; } union reply_descriptor { u64 word; struct { u32 low; u32 high; } u; }; static u32 base_mod64(u64 dividend, u32 divisor) { u32 remainder; if (!divisor) pr_err("mpt3sas: DIVISOR is zero, in div fn\n"); remainder = do_div(dividend, divisor); return remainder; } /** * _base_process_reply_queue - Process reply descriptors from reply * descriptor post queue. * @reply_q: per IRQ's reply queue object. * * Return: number of reply descriptors processed from reply * descriptor queue. */ static int _base_process_reply_queue(struct adapter_reply_queue *reply_q) { union reply_descriptor rd; u64 completed_cmds; u8 request_descript_type; u16 smid; u8 cb_idx; u32 reply; u8 msix_index = reply_q->msix_index; struct MPT3SAS_ADAPTER *ioc = reply_q->ioc; Mpi2ReplyDescriptorsUnion_t *rpf; u8 rc; completed_cmds = 0; if (!atomic_add_unless(&reply_q->busy, 1, 1)) return completed_cmds; rpf = &reply_q->reply_post_free[reply_q->reply_post_host_index]; request_descript_type = rpf->Default.ReplyFlags & MPI2_RPY_DESCRIPT_FLAGS_TYPE_MASK; if (request_descript_type == MPI2_RPY_DESCRIPT_FLAGS_UNUSED) { atomic_dec(&reply_q->busy); return completed_cmds; } cb_idx = 0xFF; do { rd.word = le64_to_cpu(rpf->Words); if (rd.u.low == UINT_MAX || rd.u.high == UINT_MAX) goto out; reply = 0; smid = le16_to_cpu(rpf->Default.DescriptorTypeDependent1); if (request_descript_type == MPI25_RPY_DESCRIPT_FLAGS_FAST_PATH_SCSI_IO_SUCCESS || request_descript_type == MPI2_RPY_DESCRIPT_FLAGS_SCSI_IO_SUCCESS || request_descript_type == MPI26_RPY_DESCRIPT_FLAGS_PCIE_ENCAPSULATED_SUCCESS) { cb_idx = _base_get_cb_idx(ioc, smid); if ((likely(cb_idx < MPT_MAX_CALLBACKS)) && (likely(mpt_callbacks[cb_idx] != NULL))) { rc = mpt_callbacks[cb_idx](ioc, smid, msix_index, 0); if (rc) mpt3sas_base_free_smid(ioc, smid); } } else if (request_descript_type == MPI2_RPY_DESCRIPT_FLAGS_ADDRESS_REPLY) { reply = le32_to_cpu( rpf->AddressReply.ReplyFrameAddress); if (reply > ioc->reply_dma_max_address || reply < ioc->reply_dma_min_address) reply = 0; if (smid) { cb_idx = _base_get_cb_idx(ioc, smid); if ((likely(cb_idx < MPT_MAX_CALLBACKS)) && (likely(mpt_callbacks[cb_idx] != NULL))) { rc = mpt_callbacks[cb_idx](ioc, smid, msix_index, reply); if (reply) _base_display_reply_info(ioc, smid, msix_index, reply); if (rc) mpt3sas_base_free_smid(ioc, smid); } } else { _base_async_event(ioc, msix_index, reply); } /* reply free queue handling */ if (reply) { ioc->reply_free_host_index = (ioc->reply_free_host_index == (ioc->reply_free_queue_depth - 1)) ? 0 : ioc->reply_free_host_index + 1; ioc->reply_free[ioc->reply_free_host_index] = cpu_to_le32(reply); if (ioc->is_mcpu_endpoint) _base_clone_reply_to_sys_mem(ioc, reply, ioc->reply_free_host_index); writel(ioc->reply_free_host_index, &ioc->chip->ReplyFreeHostIndex); } } rpf->Words = cpu_to_le64(ULLONG_MAX); reply_q->reply_post_host_index = (reply_q->reply_post_host_index == (ioc->reply_post_queue_depth - 1)) ? 0 : reply_q->reply_post_host_index + 1; request_descript_type = reply_q->reply_post_free[reply_q->reply_post_host_index]. Default.ReplyFlags & MPI2_RPY_DESCRIPT_FLAGS_TYPE_MASK; completed_cmds++; /* Update the reply post host index after continuously * processing the threshold number of Reply Descriptors. * So that FW can find enough entries to post the Reply * Descriptors in the reply descriptor post queue. */ if (completed_cmds >= ioc->thresh_hold) { if (ioc->combined_reply_queue) { writel(reply_q->reply_post_host_index | ((msix_index & 7) << MPI2_RPHI_MSIX_INDEX_SHIFT), ioc->replyPostRegisterIndex[msix_index/8]); } else { writel(reply_q->reply_post_host_index | (msix_index << MPI2_RPHI_MSIX_INDEX_SHIFT), &ioc->chip->ReplyPostHostIndex); } if (!reply_q->is_iouring_poll_q && !reply_q->irq_poll_scheduled) { reply_q->irq_poll_scheduled = true; irq_poll_sched(&reply_q->irqpoll); } atomic_dec(&reply_q->busy); return completed_cmds; } if (request_descript_type == MPI2_RPY_DESCRIPT_FLAGS_UNUSED) goto out; if (!reply_q->reply_post_host_index) rpf = reply_q->reply_post_free; else rpf++; } while (1); out: if (!completed_cmds) { atomic_dec(&reply_q->busy); return completed_cmds; } if (ioc->is_warpdrive) { writel(reply_q->reply_post_host_index, ioc->reply_post_host_index[msix_index]); atomic_dec(&reply_q->busy); return completed_cmds; } /* Update Reply Post Host Index. * For those HBA's which support combined reply queue feature * 1. Get the correct Supplemental Reply Post Host Index Register. * i.e. (msix_index / 8)th entry from Supplemental Reply Post Host * Index Register address bank i.e replyPostRegisterIndex[], * 2. Then update this register with new reply host index value * in ReplyPostIndex field and the MSIxIndex field with * msix_index value reduced to a value between 0 and 7, * using a modulo 8 operation. Since each Supplemental Reply Post * Host Index Register supports 8 MSI-X vectors. * * For other HBA's just update the Reply Post Host Index register with * new reply host index value in ReplyPostIndex Field and msix_index * value in MSIxIndex field. */ if (ioc->combined_reply_queue) writel(reply_q->reply_post_host_index | ((msix_index & 7) << MPI2_RPHI_MSIX_INDEX_SHIFT), ioc->replyPostRegisterIndex[msix_index/8]); else writel(reply_q->reply_post_host_index | (msix_index << MPI2_RPHI_MSIX_INDEX_SHIFT), &ioc->chip->ReplyPostHostIndex); atomic_dec(&reply_q->busy); return completed_cmds; } /** * mpt3sas_blk_mq_poll - poll the blk mq poll queue * @shost: Scsi_Host object * @queue_num: hw ctx queue number * * Return number of entries that has been processed from poll queue. */ int mpt3sas_blk_mq_poll(struct Scsi_Host *shost, unsigned int queue_num) { struct MPT3SAS_ADAPTER *ioc = (struct MPT3SAS_ADAPTER *)shost->hostdata; struct adapter_reply_queue *reply_q; int num_entries = 0; int qid = queue_num - ioc->iopoll_q_start_index; if (atomic_read(&ioc->io_uring_poll_queues[qid].pause) || !atomic_add_unless(&ioc->io_uring_poll_queues[qid].busy, 1, 1)) return 0; reply_q = ioc->io_uring_poll_queues[qid].reply_q; num_entries = _base_process_reply_queue(reply_q); atomic_dec(&ioc->io_uring_poll_queues[qid].busy); return num_entries; } /** * _base_interrupt - MPT adapter (IOC) specific interrupt handler. * @irq: irq number (not used) * @bus_id: bus identifier cookie == pointer to MPT_ADAPTER structure * * Return: IRQ_HANDLED if processed, else IRQ_NONE. */ static irqreturn_t _base_interrupt(int irq, void *bus_id) { struct adapter_reply_queue *reply_q = bus_id; struct MPT3SAS_ADAPTER *ioc = reply_q->ioc; if (ioc->mask_interrupts) return IRQ_NONE; if (reply_q->irq_poll_scheduled) return IRQ_HANDLED; return ((_base_process_reply_queue(reply_q) > 0) ? IRQ_HANDLED : IRQ_NONE); } /** * _base_irqpoll - IRQ poll callback handler * @irqpoll: irq_poll object * @budget: irq poll weight * * Return: number of reply descriptors processed */ static int _base_irqpoll(struct irq_poll *irqpoll, int budget) { struct adapter_reply_queue *reply_q; int num_entries = 0; reply_q = container_of(irqpoll, struct adapter_reply_queue, irqpoll); if (reply_q->irq_line_enable) { disable_irq_nosync(reply_q->os_irq); reply_q->irq_line_enable = false; } num_entries = _base_process_reply_queue(reply_q); if (num_entries < budget) { irq_poll_complete(irqpoll); reply_q->irq_poll_scheduled = false; reply_q->irq_line_enable = true; enable_irq(reply_q->os_irq); /* * Go for one more round of processing the * reply descriptor post queue in case the HBA * Firmware has posted some reply descriptors * while reenabling the IRQ. */ _base_process_reply_queue(reply_q); } return num_entries; } /** * _base_init_irqpolls - initliaze IRQ polls * @ioc: per adapter object * * Return: nothing */ static void _base_init_irqpolls(struct MPT3SAS_ADAPTER *ioc) { struct adapter_reply_queue *reply_q, *next; if (list_empty(&ioc->reply_queue_list)) return; list_for_each_entry_safe(reply_q, next, &ioc->reply_queue_list, list) { if (reply_q->is_iouring_poll_q) continue; irq_poll_init(&reply_q->irqpoll, ioc->hba_queue_depth/4, _base_irqpoll); reply_q->irq_poll_scheduled = false; reply_q->irq_line_enable = true; reply_q->os_irq = pci_irq_vector(ioc->pdev, reply_q->msix_index); } } /** * _base_is_controller_msix_enabled - is controller support muli-reply queues * @ioc: per adapter object * * Return: Whether or not MSI/X is enabled. */ static inline int _base_is_controller_msix_enabled(struct MPT3SAS_ADAPTER *ioc) { return (ioc->facts.IOCCapabilities & MPI2_IOCFACTS_CAPABILITY_MSI_X_INDEX) && ioc->msix_enable; } /** * mpt3sas_base_sync_reply_irqs - flush pending MSIX interrupts * @ioc: per adapter object * @poll: poll over reply descriptor pools incase interrupt for * timed-out SCSI command got delayed * Context: non-ISR context * * Called when a Task Management request has completed. */ void mpt3sas_base_sync_reply_irqs(struct MPT3SAS_ADAPTER *ioc, u8 poll) { struct adapter_reply_queue *reply_q; /* If MSIX capability is turned off * then multi-queues are not enabled */ if (!_base_is_controller_msix_enabled(ioc)) return; list_for_each_entry(reply_q, &ioc->reply_queue_list, list) { if (ioc->shost_recovery || ioc->remove_host || ioc->pci_error_recovery) return; /* TMs are on msix_index == 0 */ if (reply_q->msix_index == 0) continue; if (reply_q->is_iouring_poll_q) { _base_process_reply_queue(reply_q); continue; } synchronize_irq(pci_irq_vector(ioc->pdev, reply_q->msix_index)); if (reply_q->irq_poll_scheduled) { /* Calling irq_poll_disable will wait for any pending * callbacks to have completed. */ irq_poll_disable(&reply_q->irqpoll); irq_poll_enable(&reply_q->irqpoll); /* check how the scheduled poll has ended, * clean up only if necessary */ if (reply_q->irq_poll_scheduled) { reply_q->irq_poll_scheduled = false; reply_q->irq_line_enable = true; enable_irq(reply_q->os_irq); } } } if (poll) _base_process_reply_queue(reply_q); } /** * mpt3sas_base_release_callback_handler - clear interrupt callback handler * @cb_idx: callback index */ void mpt3sas_base_release_callback_handler(u8 cb_idx) { mpt_callbacks[cb_idx] = NULL; } /** * mpt3sas_base_register_callback_handler - obtain index for the interrupt callback handler * @cb_func: callback function * * Return: Index of @cb_func. */ u8 mpt3sas_base_register_callback_handler(MPT_CALLBACK cb_func) { u8 cb_idx; for (cb_idx = MPT_MAX_CALLBACKS-1; cb_idx; cb_idx--) if (mpt_callbacks[cb_idx] == NULL) break; mpt_callbacks[cb_idx] = cb_func; return cb_idx; } /** * mpt3sas_base_initialize_callback_handler - initialize the interrupt callback handler */ void mpt3sas_base_initialize_callback_handler(void) { u8 cb_idx; for (cb_idx = 0; cb_idx < MPT_MAX_CALLBACKS; cb_idx++) mpt3sas_base_release_callback_handler(cb_idx); } /** * _base_build_zero_len_sge - build zero length sg entry * @ioc: per adapter object * @paddr: virtual address for SGE * * Create a zero length scatter gather entry to insure the IOCs hardware has * something to use if the target device goes brain dead and tries * to send data even when none is asked for. */ static void _base_build_zero_len_sge(struct MPT3SAS_ADAPTER *ioc, void *paddr) { u32 flags_length = (u32)((MPI2_SGE_FLAGS_LAST_ELEMENT | MPI2_SGE_FLAGS_END_OF_BUFFER | MPI2_SGE_FLAGS_END_OF_LIST | MPI2_SGE_FLAGS_SIMPLE_ELEMENT) << MPI2_SGE_FLAGS_SHIFT); ioc->base_add_sg_single(paddr, flags_length, -1); } /** * _base_add_sg_single_32 - Place a simple 32 bit SGE at address pAddr. * @paddr: virtual address for SGE * @flags_length: SGE flags and data transfer length * @dma_addr: Physical address */ static void _base_add_sg_single_32(void *paddr, u32 flags_length, dma_addr_t dma_addr) { Mpi2SGESimple32_t *sgel = paddr; flags_length |= (MPI2_SGE_FLAGS_32_BIT_ADDRESSING | MPI2_SGE_FLAGS_SYSTEM_ADDRESS) << MPI2_SGE_FLAGS_SHIFT; sgel->FlagsLength = cpu_to_le32(flags_length); sgel->Address = cpu_to_le32(dma_addr); } /** * _base_add_sg_single_64 - Place a simple 64 bit SGE at address pAddr. * @paddr: virtual address for SGE * @flags_length: SGE flags and data transfer length * @dma_addr: Physical address */ static void _base_add_sg_single_64(void *paddr, u32 flags_length, dma_addr_t dma_addr) { Mpi2SGESimple64_t *sgel = paddr; flags_length |= (MPI2_SGE_FLAGS_64_BIT_ADDRESSING | MPI2_SGE_FLAGS_SYSTEM_ADDRESS) << MPI2_SGE_FLAGS_SHIFT; sgel->FlagsLength = cpu_to_le32(flags_length); sgel->Address = cpu_to_le64(dma_addr); } /** * _base_get_chain_buffer_tracker - obtain chain tracker * @ioc: per adapter object * @scmd: SCSI commands of the IO request * * Return: chain tracker from chain_lookup table using key as * smid and smid's chain_offset. */ static struct chain_tracker * _base_get_chain_buffer_tracker(struct MPT3SAS_ADAPTER *ioc, struct scsi_cmnd *scmd) { struct chain_tracker *chain_req; struct scsiio_tracker *st = scsi_cmd_priv(scmd); u16 smid = st->smid; u8 chain_offset = atomic_read(&ioc->chain_lookup[smid - 1].chain_offset); if (chain_offset == ioc->chains_needed_per_io) return NULL; chain_req = &ioc->chain_lookup[smid - 1].chains_per_smid[chain_offset]; atomic_inc(&ioc->chain_lookup[smid - 1].chain_offset); return chain_req; } /** * _base_build_sg - build generic sg * @ioc: per adapter object * @psge: virtual address for SGE * @data_out_dma: physical address for WRITES * @data_out_sz: data xfer size for WRITES * @data_in_dma: physical address for READS * @data_in_sz: data xfer size for READS */ static void _base_build_sg(struct MPT3SAS_ADAPTER *ioc, void *psge, dma_addr_t data_out_dma, size_t data_out_sz, dma_addr_t data_in_dma, size_t data_in_sz) { u32 sgl_flags; if (!data_out_sz && !data_in_sz) { _base_build_zero_len_sge(ioc, psge); return; } if (data_out_sz && data_in_sz) { /* WRITE sgel first */ sgl_flags = (MPI2_SGE_FLAGS_SIMPLE_ELEMENT | MPI2_SGE_FLAGS_END_OF_BUFFER | MPI2_SGE_FLAGS_HOST_TO_IOC); sgl_flags = sgl_flags << MPI2_SGE_FLAGS_SHIFT; ioc->base_add_sg_single(psge, sgl_flags | data_out_sz, data_out_dma); /* incr sgel */ psge += ioc->sge_size; /* READ sgel last */ sgl_flags = (MPI2_SGE_FLAGS_SIMPLE_ELEMENT | MPI2_SGE_FLAGS_LAST_ELEMENT | MPI2_SGE_FLAGS_END_OF_BUFFER | MPI2_SGE_FLAGS_END_OF_LIST); sgl_flags = sgl_flags << MPI2_SGE_FLAGS_SHIFT; ioc->base_add_sg_single(psge, sgl_flags | data_in_sz, data_in_dma); } else if (data_out_sz) /* WRITE */ { sgl_flags = (MPI2_SGE_FLAGS_SIMPLE_ELEMENT | MPI2_SGE_FLAGS_LAST_ELEMENT | MPI2_SGE_FLAGS_END_OF_BUFFER | MPI2_SGE_FLAGS_END_OF_LIST | MPI2_SGE_FLAGS_HOST_TO_IOC); sgl_flags = sgl_flags << MPI2_SGE_FLAGS_SHIFT; ioc->base_add_sg_single(psge, sgl_flags | data_out_sz, data_out_dma); } else if (data_in_sz) /* READ */ { sgl_flags = (MPI2_SGE_FLAGS_SIMPLE_ELEMENT | MPI2_SGE_FLAGS_LAST_ELEMENT | MPI2_SGE_FLAGS_END_OF_BUFFER | MPI2_SGE_FLAGS_END_OF_LIST); sgl_flags = sgl_flags << MPI2_SGE_FLAGS_SHIFT; ioc->base_add_sg_single(psge, sgl_flags | data_in_sz, data_in_dma); } } /* IEEE format sgls */ /** * _base_build_nvme_prp - This function is called for NVMe end devices to build * a native SGL (NVMe PRP). * @ioc: per adapter object * @smid: system request message index for getting asscociated SGL * @nvme_encap_request: the NVMe request msg frame pointer * @data_out_dma: physical address for WRITES * @data_out_sz: data xfer size for WRITES * @data_in_dma: physical address for READS * @data_in_sz: data xfer size for READS * * The native SGL is built starting in the first PRP * entry of the NVMe message (PRP1). If the data buffer is small enough to be * described entirely using PRP1, then PRP2 is not used. If needed, PRP2 is * used to describe a larger data buffer. If the data buffer is too large to * describe using the two PRP entriess inside the NVMe message, then PRP1 * describes the first data memory segment, and PRP2 contains a pointer to a PRP * list located elsewhere in memory to describe the remaining data memory * segments. The PRP list will be contiguous. * * The native SGL for NVMe devices is a Physical Region Page (PRP). A PRP * consists of a list of PRP entries to describe a number of noncontigous * physical memory segments as a single memory buffer, just as a SGL does. Note * however, that this function is only used by the IOCTL call, so the memory * given will be guaranteed to be contiguous. There is no need to translate * non-contiguous SGL into a PRP in this case. All PRPs will describe * contiguous space that is one page size each. * * Each NVMe message contains two PRP entries. The first (PRP1) either contains * a PRP list pointer or a PRP element, depending upon the command. PRP2 * contains the second PRP element if the memory being described fits within 2 * PRP entries, or a PRP list pointer if the PRP spans more than two entries. * * A PRP list pointer contains the address of a PRP list, structured as a linear * array of PRP entries. Each PRP entry in this list describes a segment of * physical memory. * * Each 64-bit PRP entry comprises an address and an offset field. The address * always points at the beginning of a 4KB physical memory page, and the offset * describes where within that 4KB page the memory segment begins. Only the * first element in a PRP list may contain a non-zero offset, implying that all * memory segments following the first begin at the start of a 4KB page. * * Each PRP element normally describes 4KB of physical memory, with exceptions * for the first and last elements in the list. If the memory being described * by the list begins at a non-zero offset within the first 4KB page, then the * first PRP element will contain a non-zero offset indicating where the region * begins within the 4KB page. The last memory segment may end before the end * of the 4KB segment, depending upon the overall size of the memory being * described by the PRP list. * * Since PRP entries lack any indication of size, the overall data buffer length * is used to determine where the end of the data memory buffer is located, and * how many PRP entries are required to describe it. */ static void _base_build_nvme_prp(struct MPT3SAS_ADAPTER *ioc, u16 smid, Mpi26NVMeEncapsulatedRequest_t *nvme_encap_request, dma_addr_t data_out_dma, size_t data_out_sz, dma_addr_t data_in_dma, size_t data_in_sz) { int prp_size = NVME_PRP_SIZE; __le64 *prp_entry, *prp1_entry, *prp2_entry; __le64 *prp_page; dma_addr_t prp_entry_dma, prp_page_dma, dma_addr; u32 offset, entry_len; u32 page_mask_result, page_mask; size_t length; struct mpt3sas_nvme_cmd *nvme_cmd = (void *)nvme_encap_request->NVMe_Command; /* * Not all commands require a data transfer. If no data, just return * without constructing any PRP. */ if (!data_in_sz && !data_out_sz) return; prp1_entry = &nvme_cmd->prp1; prp2_entry = &nvme_cmd->prp2; prp_entry = prp1_entry; /* * For the PRP entries, use the specially allocated buffer of * contiguous memory. */ prp_page = (__le64 *)mpt3sas_base_get_pcie_sgl(ioc, smid); prp_page_dma = mpt3sas_base_get_pcie_sgl_dma(ioc, smid); /* * Check if we are within 1 entry of a page boundary we don't * want our first entry to be a PRP List entry. */ page_mask = ioc->page_size - 1; page_mask_result = (uintptr_t)((u8 *)prp_page + prp_size) & page_mask; if (!page_mask_result) { /* Bump up to next page boundary. */ prp_page = (__le64 *)((u8 *)prp_page + prp_size); prp_page_dma = prp_page_dma + prp_size; } /* * Set PRP physical pointer, which initially points to the current PRP * DMA memory page. */ prp_entry_dma = prp_page_dma; /* Get physical address and length of the data buffer. */ if (data_in_sz) { dma_addr = data_in_dma; length = data_in_sz; } else { dma_addr = data_out_dma; length = data_out_sz; } /* Loop while the length is not zero. */ while (length) { /* * Check if we need to put a list pointer here if we are at * page boundary - prp_size (8 bytes). */ page_mask_result = (prp_entry_dma + prp_size) & page_mask; if (!page_mask_result) { /* * This is the last entry in a PRP List, so we need to * put a PRP list pointer here. What this does is: * - bump the current memory pointer to the next * address, which will be the next full page. * - set the PRP Entry to point to that page. This * is now the PRP List pointer. * - bump the PRP Entry pointer the start of the * next page. Since all of this PRP memory is * contiguous, no need to get a new page - it's * just the next address. */ prp_entry_dma++; *prp_entry = cpu_to_le64(prp_entry_dma); prp_entry++; } /* Need to handle if entry will be part of a page. */ offset = dma_addr & page_mask; entry_len = ioc->page_size - offset; if (prp_entry == prp1_entry) { /* * Must fill in the first PRP pointer (PRP1) before * moving on. */ *prp1_entry = cpu_to_le64(dma_addr); /* * Now point to the second PRP entry within the * command (PRP2). */ prp_entry = prp2_entry; } else if (prp_entry == prp2_entry) { /* * Should the PRP2 entry be a PRP List pointer or just * a regular PRP pointer? If there is more than one * more page of data, must use a PRP List pointer. */ if (length > ioc->page_size) { /* * PRP2 will contain a PRP List pointer because * more PRP's are needed with this command. The * list will start at the beginning of the * contiguous buffer. */ *prp2_entry = cpu_to_le64(prp_entry_dma); /* * The next PRP Entry will be the start of the * first PRP List. */ prp_entry = prp_page; } else { /* * After this, the PRP Entries are complete. * This command uses 2 PRP's and no PRP list. */ *prp2_entry = cpu_to_le64(dma_addr); } } else { /* * Put entry in list and bump the addresses. * * After PRP1 and PRP2 are filled in, this will fill in * all remaining PRP entries in a PRP List, one per * each time through the loop. */ *prp_entry = cpu_to_le64(dma_addr); prp_entry++; prp_entry_dma++; } /* * Bump the phys address of the command's data buffer by the * entry_len. */ dma_addr += entry_len; /* Decrement length accounting for last partial page. */ if (entry_len > length) length = 0; else length -= entry_len; } } /** * base_make_prp_nvme - Prepare PRPs (Physical Region Page) - * SGLs specific to NVMe drives only * * @ioc: per adapter object * @scmd: SCSI command from the mid-layer * @mpi_request: mpi request * @smid: msg Index * @sge_count: scatter gather element count. * * Return: true: PRPs are built * false: IEEE SGLs needs to be built */ static void base_make_prp_nvme(struct MPT3SAS_ADAPTER *ioc, struct scsi_cmnd *scmd, Mpi25SCSIIORequest_t *mpi_request, u16 smid, int sge_count) { int sge_len, num_prp_in_chain = 0; Mpi25IeeeSgeChain64_t *main_chain_element, *ptr_first_sgl; __le64 *curr_buff; dma_addr_t msg_dma, sge_addr, offset; u32 page_mask, page_mask_result; struct scatterlist *sg_scmd; u32 first_prp_len; int data_len = scsi_bufflen(scmd); u32 nvme_pg_size; nvme_pg_size = max_t(u32, ioc->page_size, NVME_PRP_PAGE_SIZE); /* * Nvme has a very convoluted prp format. One prp is required * for each page or partial page. Driver need to split up OS sg_list * entries if it is longer than one page or cross a page * boundary. Driver also have to insert a PRP list pointer entry as * the last entry in each physical page of the PRP list. * * NOTE: The first PRP "entry" is actually placed in the first * SGL entry in the main message as IEEE 64 format. The 2nd * entry in the main message is the chain element, and the rest * of the PRP entries are built in the contiguous pcie buffer. */ page_mask = nvme_pg_size - 1; /* * Native SGL is needed. * Put a chain element in main message frame that points to the first * chain buffer. * * NOTE: The ChainOffset field must be 0 when using a chain pointer to * a native SGL. */ /* Set main message chain element pointer */ main_chain_element = (pMpi25IeeeSgeChain64_t)&mpi_request->SGL; /* * For NVMe the chain element needs to be the 2nd SG entry in the main * message. */ main_chain_element = (Mpi25IeeeSgeChain64_t *) ((u8 *)main_chain_element + sizeof(MPI25_IEEE_SGE_CHAIN64)); /* * For the PRP entries, use the specially allocated buffer of * contiguous memory. Normal chain buffers can't be used * because each chain buffer would need to be the size of an OS * page (4k). */ curr_buff = mpt3sas_base_get_pcie_sgl(ioc, smid); msg_dma = mpt3sas_base_get_pcie_sgl_dma(ioc, smid); main_chain_element->Address = cpu_to_le64(msg_dma); main_chain_element->NextChainOffset = 0; main_chain_element->Flags = MPI2_IEEE_SGE_FLAGS_CHAIN_ELEMENT | MPI2_IEEE_SGE_FLAGS_SYSTEM_ADDR | MPI26_IEEE_SGE_FLAGS_NSF_NVME_PRP; /* Build first prp, sge need not to be page aligned*/ ptr_first_sgl = (pMpi25IeeeSgeChain64_t)&mpi_request->SGL; sg_scmd = scsi_sglist(scmd); sge_addr = sg_dma_address(sg_scmd); sge_len = sg_dma_len(sg_scmd); offset = sge_addr & page_mask; first_prp_len = nvme_pg_size - offset; ptr_first_sgl->Address = cpu_to_le64(sge_addr); ptr_first_sgl->Length = cpu_to_le32(first_prp_len); data_len -= first_prp_len; if (sge_len > first_prp_len) { sge_addr += first_prp_len; sge_len -= first_prp_len; } else if (data_len && (sge_len == first_prp_len)) { sg_scmd = sg_next(sg_scmd); sge_addr = sg_dma_address(sg_scmd); sge_len = sg_dma_len(sg_scmd); } for (;;) { offset = sge_addr & page_mask; /* Put PRP pointer due to page boundary*/ page_mask_result = (uintptr_t)(curr_buff + 1) & page_mask; if (unlikely(!page_mask_result)) { scmd_printk(KERN_NOTICE, scmd, "page boundary curr_buff: 0x%p\n", curr_buff); msg_dma += 8; *curr_buff = cpu_to_le64(msg_dma); curr_buff++; num_prp_in_chain++; } *curr_buff = cpu_to_le64(sge_addr); curr_buff++; msg_dma += 8; num_prp_in_chain++; sge_addr += nvme_pg_size; sge_len -= nvme_pg_size; data_len -= nvme_pg_size; if (data_len <= 0) break; if (sge_len > 0) continue; sg_scmd = sg_next(sg_scmd); sge_addr = sg_dma_address(sg_scmd); sge_len = sg_dma_len(sg_scmd); } main_chain_element->Length = cpu_to_le32(num_prp_in_chain * sizeof(u64)); return; } static bool base_is_prp_possible(struct MPT3SAS_ADAPTER *ioc, struct _pcie_device *pcie_device, struct scsi_cmnd *scmd, int sge_count) { u32 data_length = 0; bool build_prp = true; data_length = scsi_bufflen(scmd); if (pcie_device && (mpt3sas_scsih_is_pcie_scsi_device(pcie_device->device_info))) { build_prp = false; return build_prp; } /* If Datalenth is <= 16K and number of SGE’s entries are <= 2 * we built IEEE SGL */ if ((data_length <= NVME_PRP_PAGE_SIZE*4) && (sge_count <= 2)) build_prp = false; return build_prp; } /** * _base_check_pcie_native_sgl - This function is called for PCIe end devices to * determine if the driver needs to build a native SGL. If so, that native * SGL is built in the special contiguous buffers allocated especially for * PCIe SGL creation. If the driver will not build a native SGL, return * TRUE and a normal IEEE SGL will be built. Currently this routine * supports NVMe. * @ioc: per adapter object * @mpi_request: mf request pointer * @smid: system request message index * @scmd: scsi command * @pcie_device: points to the PCIe device's info * * Return: 0 if native SGL was built, 1 if no SGL was built */ static int _base_check_pcie_native_sgl(struct MPT3SAS_ADAPTER *ioc, Mpi25SCSIIORequest_t *mpi_request, u16 smid, struct scsi_cmnd *scmd, struct _pcie_device *pcie_device) { int sges_left; /* Get the SG list pointer and info. */ sges_left = scsi_dma_map(scmd); if (sges_left < 0) { sdev_printk(KERN_ERR, scmd->device, "scsi_dma_map failed: request for %d bytes!\n", scsi_bufflen(scmd)); return 1; } /* Check if we need to build a native SG list. */ if (!base_is_prp_possible(ioc, pcie_device, scmd, sges_left)) { /* We built a native SG list, just return. */ goto out; } /* * Build native NVMe PRP. */ base_make_prp_nvme(ioc, scmd, mpi_request, smid, sges_left); return 0; out: scsi_dma_unmap(scmd); return 1; } /** * _base_add_sg_single_ieee - add sg element for IEEE format * @paddr: virtual address for SGE * @flags: SGE flags * @chain_offset: number of 128 byte elements from start of segment * @length: data transfer length * @dma_addr: Physical address */ static void _base_add_sg_single_ieee(void *paddr, u8 flags, u8 chain_offset, u32 length, dma_addr_t dma_addr) { Mpi25IeeeSgeChain64_t *sgel = paddr; sgel->Flags = flags; sgel->NextChainOffset = chain_offset; sgel->Length = cpu_to_le32(length); sgel->Address = cpu_to_le64(dma_addr); } /** * _base_build_zero_len_sge_ieee - build zero length sg entry for IEEE format * @ioc: per adapter object * @paddr: virtual address for SGE * * Create a zero length scatter gather entry to insure the IOCs hardware has * something to use if the target device goes brain dead and tries * to send data even when none is asked for. */ static void _base_build_zero_len_sge_ieee(struct MPT3SAS_ADAPTER *ioc, void *paddr) { u8 sgl_flags = (MPI2_IEEE_SGE_FLAGS_SIMPLE_ELEMENT | MPI2_IEEE_SGE_FLAGS_SYSTEM_ADDR | MPI25_IEEE_SGE_FLAGS_END_OF_LIST); _base_add_sg_single_ieee(paddr, sgl_flags, 0, 0, -1); } /** * _base_build_sg_scmd - main sg creation routine * pcie_device is unused here! * @ioc: per adapter object * @scmd: scsi command * @smid: system request message index * @unused: unused pcie_device pointer * Context: none. * * The main routine that builds scatter gather table from a given * scsi request sent via the .queuecommand main handler. * * Return: 0 success, anything else error */ static int _base_build_sg_scmd(struct MPT3SAS_ADAPTER *ioc, struct scsi_cmnd *scmd, u16 smid, struct _pcie_device *unused) { Mpi2SCSIIORequest_t *mpi_request; dma_addr_t chain_dma; struct scatterlist *sg_scmd; void *sg_local, *chain; u32 chain_offset; u32 chain_length; u32 chain_flags; int sges_left; u32 sges_in_segment; u32 sgl_flags; u32 sgl_flags_last_element; u32 sgl_flags_end_buffer; struct chain_tracker *chain_req; mpi_request = mpt3sas_base_get_msg_frame(ioc, smid); /* init scatter gather flags */ sgl_flags = MPI2_SGE_FLAGS_SIMPLE_ELEMENT; if (scmd->sc_data_direction == DMA_TO_DEVICE) sgl_flags |= MPI2_SGE_FLAGS_HOST_TO_IOC; sgl_flags_last_element = (sgl_flags | MPI2_SGE_FLAGS_LAST_ELEMENT) << MPI2_SGE_FLAGS_SHIFT; sgl_flags_end_buffer = (sgl_flags | MPI2_SGE_FLAGS_LAST_ELEMENT | MPI2_SGE_FLAGS_END_OF_BUFFER | MPI2_SGE_FLAGS_END_OF_LIST) << MPI2_SGE_FLAGS_SHIFT; sgl_flags = sgl_flags << MPI2_SGE_FLAGS_SHIFT; sg_scmd = scsi_sglist(scmd); sges_left = scsi_dma_map(scmd); if (sges_left < 0) { sdev_printk(KERN_ERR, scmd->device, "scsi_dma_map failed: request for %d bytes!\n", scsi_bufflen(scmd)); return -ENOMEM; } sg_local = &mpi_request->SGL; sges_in_segment = ioc->max_sges_in_main_message; if (sges_left <= sges_in_segment) goto fill_in_last_segment; mpi_request->ChainOffset = (offsetof(Mpi2SCSIIORequest_t, SGL) + (sges_in_segment * ioc->sge_size))/4; /* fill in main message segment when there is a chain following */ while (sges_in_segment) { if (sges_in_segment == 1) ioc->base_add_sg_single(sg_local, sgl_flags_last_element | sg_dma_len(sg_scmd), sg_dma_address(sg_scmd)); else ioc->base_add_sg_single(sg_local, sgl_flags | sg_dma_len(sg_scmd), sg_dma_address(sg_scmd)); sg_scmd = sg_next(sg_scmd); sg_local += ioc->sge_size; sges_left--; sges_in_segment--; } /* initializing the chain flags and pointers */ chain_flags = MPI2_SGE_FLAGS_CHAIN_ELEMENT << MPI2_SGE_FLAGS_SHIFT; chain_req = _base_get_chain_buffer_tracker(ioc, scmd); if (!chain_req) return -1; chain = chain_req->chain_buffer; chain_dma = chain_req->chain_buffer_dma; do { sges_in_segment = (sges_left <= ioc->max_sges_in_chain_message) ? sges_left : ioc->max_sges_in_chain_message; chain_offset = (sges_left == sges_in_segment) ? 0 : (sges_in_segment * ioc->sge_size)/4; chain_length = sges_in_segment * ioc->sge_size; if (chain_offset) { chain_offset = chain_offset << MPI2_SGE_CHAIN_OFFSET_SHIFT; chain_length += ioc->sge_size; } ioc->base_add_sg_single(sg_local, chain_flags | chain_offset | chain_length, chain_dma); sg_local = chain; if (!chain_offset) goto fill_in_last_segment; /* fill in chain segments */ while (sges_in_segment) { if (sges_in_segment == 1) ioc->base_add_sg_single(sg_local, sgl_flags_last_element | sg_dma_len(sg_scmd), sg_dma_address(sg_scmd)); else ioc->base_add_sg_single(sg_local, sgl_flags | sg_dma_len(sg_scmd), sg_dma_address(sg_scmd)); sg_scmd = sg_next(sg_scmd); sg_local += ioc->sge_size; sges_left--; sges_in_segment--; } chain_req = _base_get_chain_buffer_tracker(ioc, scmd); if (!chain_req) return -1; chain = chain_req->chain_buffer; chain_dma = chain_req->chain_buffer_dma; } while (1); fill_in_last_segment: /* fill the last segment */ while (sges_left) { if (sges_left == 1) ioc->base_add_sg_single(sg_local, sgl_flags_end_buffer | sg_dma_len(sg_scmd), sg_dma_address(sg_scmd)); else ioc->base_add_sg_single(sg_local, sgl_flags | sg_dma_len(sg_scmd), sg_dma_address(sg_scmd)); sg_scmd = sg_next(sg_scmd); sg_local += ioc->sge_size; sges_left--; } return 0; } /** * _base_build_sg_scmd_ieee - main sg creation routine for IEEE format * @ioc: per adapter object * @scmd: scsi command * @smid: system request message index * @pcie_device: Pointer to pcie_device. If set, the pcie native sgl will be * constructed on need. * Context: none. * * The main routine that builds scatter gather table from a given * scsi request sent via the .queuecommand main handler. * * Return: 0 success, anything else error */ static int _base_build_sg_scmd_ieee(struct MPT3SAS_ADAPTER *ioc, struct scsi_cmnd *scmd, u16 smid, struct _pcie_device *pcie_device) { Mpi25SCSIIORequest_t *mpi_request; dma_addr_t chain_dma; struct scatterlist *sg_scmd; void *sg_local, *chain; u32 chain_offset; u32 chain_length; int sges_left; u32 sges_in_segment; u8 simple_sgl_flags; u8 simple_sgl_flags_last; u8 chain_sgl_flags; struct chain_tracker *chain_req; mpi_request = mpt3sas_base_get_msg_frame(ioc, smid); /* init scatter gather flags */ simple_sgl_flags = MPI2_IEEE_SGE_FLAGS_SIMPLE_ELEMENT | MPI2_IEEE_SGE_FLAGS_SYSTEM_ADDR; simple_sgl_flags_last = simple_sgl_flags | MPI25_IEEE_SGE_FLAGS_END_OF_LIST; chain_sgl_flags = MPI2_IEEE_SGE_FLAGS_CHAIN_ELEMENT | MPI2_IEEE_SGE_FLAGS_SYSTEM_ADDR; /* Check if we need to build a native SG list. */ if ((pcie_device) && (_base_check_pcie_native_sgl(ioc, mpi_request, smid, scmd, pcie_device) == 0)) { /* We built a native SG list, just return. */ return 0; } sg_scmd = scsi_sglist(scmd); sges_left = scsi_dma_map(scmd); if (sges_left < 0) { sdev_printk(KERN_ERR, scmd->device, "scsi_dma_map failed: request for %d bytes!\n", scsi_bufflen(scmd)); return -ENOMEM; } sg_local = &mpi_request->SGL; sges_in_segment = (ioc->request_sz - offsetof(Mpi25SCSIIORequest_t, SGL))/ioc->sge_size_ieee; if (sges_left <= sges_in_segment) goto fill_in_last_segment; mpi_request->ChainOffset = (sges_in_segment - 1 /* chain element */) + (offsetof(Mpi25SCSIIORequest_t, SGL)/ioc->sge_size_ieee); /* fill in main message segment when there is a chain following */ while (sges_in_segment > 1) { _base_add_sg_single_ieee(sg_local, simple_sgl_flags, 0, sg_dma_len(sg_scmd), sg_dma_address(sg_scmd)); sg_scmd = sg_next(sg_scmd); sg_local += ioc->sge_size_ieee; sges_left--; sges_in_segment--; } /* initializing the pointers */ chain_req = _base_get_chain_buffer_tracker(ioc, scmd); if (!chain_req) return -1; chain = chain_req->chain_buffer; chain_dma = chain_req->chain_buffer_dma; do { sges_in_segment = (sges_left <= ioc->max_sges_in_chain_message) ? sges_left : ioc->max_sges_in_chain_message; chain_offset = (sges_left == sges_in_segment) ? 0 : sges_in_segment; chain_length = sges_in_segment * ioc->sge_size_ieee; if (chain_offset) chain_length += ioc->sge_size_ieee; _base_add_sg_single_ieee(sg_local, chain_sgl_flags, chain_offset, chain_length, chain_dma); sg_local = chain; if (!chain_offset) goto fill_in_last_segment; /* fill in chain segments */ while (sges_in_segment) { _base_add_sg_single_ieee(sg_local, simple_sgl_flags, 0, sg_dma_len(sg_scmd), sg_dma_address(sg_scmd)); sg_scmd = sg_next(sg_scmd); sg_local += ioc->sge_size_ieee; sges_left--; sges_in_segment--; } chain_req = _base_get_chain_buffer_tracker(ioc, scmd); if (!chain_req) return -1; chain = chain_req->chain_buffer; chain_dma = chain_req->chain_buffer_dma; } while (1); fill_in_last_segment: /* fill the last segment */ while (sges_left > 0) { if (sges_left == 1) _base_add_sg_single_ieee(sg_local, simple_sgl_flags_last, 0, sg_dma_len(sg_scmd), sg_dma_address(sg_scmd)); else _base_add_sg_single_ieee(sg_local, simple_sgl_flags, 0, sg_dma_len(sg_scmd), sg_dma_address(sg_scmd)); sg_scmd = sg_next(sg_scmd); sg_local += ioc->sge_size_ieee; sges_left--; } return 0; } /** * _base_build_sg_ieee - build generic sg for IEEE format * @ioc: per adapter object * @psge: virtual address for SGE * @data_out_dma: physical address for WRITES * @data_out_sz: data xfer size for WRITES * @data_in_dma: physical address for READS * @data_in_sz: data xfer size for READS */ static void _base_build_sg_ieee(struct MPT3SAS_ADAPTER *ioc, void *psge, dma_addr_t data_out_dma, size_t data_out_sz, dma_addr_t data_in_dma, size_t data_in_sz) { u8 sgl_flags; if (!data_out_sz && !data_in_sz) { _base_build_zero_len_sge_ieee(ioc, psge); return; } if (data_out_sz && data_in_sz) { /* WRITE sgel first */ sgl_flags = MPI2_IEEE_SGE_FLAGS_SIMPLE_ELEMENT | MPI2_IEEE_SGE_FLAGS_SYSTEM_ADDR; _base_add_sg_single_ieee(psge, sgl_flags, 0, data_out_sz, data_out_dma); /* incr sgel */ psge += ioc->sge_size_ieee; /* READ sgel last */ sgl_flags |= MPI25_IEEE_SGE_FLAGS_END_OF_LIST; _base_add_sg_single_ieee(psge, sgl_flags, 0, data_in_sz, data_in_dma); } else if (data_out_sz) /* WRITE */ { sgl_flags = MPI2_IEEE_SGE_FLAGS_SIMPLE_ELEMENT | MPI25_IEEE_SGE_FLAGS_END_OF_LIST | MPI2_IEEE_SGE_FLAGS_SYSTEM_ADDR; _base_add_sg_single_ieee(psge, sgl_flags, 0, data_out_sz, data_out_dma); } else if (data_in_sz) /* READ */ { sgl_flags = MPI2_IEEE_SGE_FLAGS_SIMPLE_ELEMENT | MPI25_IEEE_SGE_FLAGS_END_OF_LIST | MPI2_IEEE_SGE_FLAGS_SYSTEM_ADDR; _base_add_sg_single_ieee(psge, sgl_flags, 0, data_in_sz, data_in_dma); } } #define convert_to_kb(x) ((x) << (PAGE_SHIFT - 10)) /** * _base_config_dma_addressing - set dma addressing * @ioc: per adapter object * @pdev: PCI device struct * * Return: 0 for success, non-zero for failure. */ static int _base_config_dma_addressing(struct MPT3SAS_ADAPTER *ioc, struct pci_dev *pdev) { struct sysinfo s; if (ioc->is_mcpu_endpoint || sizeof(dma_addr_t) == 4 || ioc->use_32bit_dma || dma_get_required_mask(&pdev->dev) <= 32) ioc->dma_mask = 32; /* Set 63 bit DMA mask for all SAS3 and SAS35 controllers */ else if (ioc->hba_mpi_version_belonged > MPI2_VERSION) ioc->dma_mask = 63; else ioc->dma_mask = 64; if (dma_set_mask(&pdev->dev, DMA_BIT_MASK(ioc->dma_mask)) || dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(ioc->dma_mask))) return -ENODEV; if (ioc->dma_mask > 32) { ioc->base_add_sg_single = &_base_add_sg_single_64; ioc->sge_size = sizeof(Mpi2SGESimple64_t); } else { ioc->base_add_sg_single = &_base_add_sg_single_32; ioc->sge_size = sizeof(Mpi2SGESimple32_t); } si_meminfo(&s); ioc_info(ioc, "%d BIT PCI BUS DMA ADDRESSING SUPPORTED, total mem (%ld kB)\n", ioc->dma_mask, convert_to_kb(s.totalram)); return 0; } /** * _base_check_enable_msix - checks MSIX capabable. * @ioc: per adapter object * * Check to see if card is capable of MSIX, and set number * of available msix vectors */ static int _base_check_enable_msix(struct MPT3SAS_ADAPTER *ioc) { int base; u16 message_control; /* Check whether controller SAS2008 B0 controller, * if it is SAS2008 B0 controller use IO-APIC instead of MSIX */ if (ioc->pdev->device == MPI2_MFGPAGE_DEVID_SAS2008 && ioc->pdev->revision == SAS2_PCI_DEVICE_B0_REVISION) { return -EINVAL; } base = pci_find_capability(ioc->pdev, PCI_CAP_ID_MSIX); if (!base) { dfailprintk(ioc, ioc_info(ioc, "msix not supported\n")); return -EINVAL; } /* get msix vector count */ /* NUMA_IO not supported for older controllers */ if (ioc->pdev->device == MPI2_MFGPAGE_DEVID_SAS2004 || ioc->pdev->device == MPI2_MFGPAGE_DEVID_SAS2008 || ioc->pdev->device == MPI2_MFGPAGE_DEVID_SAS2108_1 || ioc->pdev->device == MPI2_MFGPAGE_DEVID_SAS2108_2 || ioc->pdev->device == MPI2_MFGPAGE_DEVID_SAS2108_3 || ioc->pdev->device == MPI2_MFGPAGE_DEVID_SAS2116_1 || ioc->pdev->device == MPI2_MFGPAGE_DEVID_SAS2116_2) ioc->msix_vector_count = 1; else { pci_read_config_word(ioc->pdev, base + 2, &message_control); ioc->msix_vector_count = (message_control & 0x3FF) + 1; } dinitprintk(ioc, ioc_info(ioc, "msix is supported, vector_count(%d)\n", ioc->msix_vector_count)); return 0; } /** * mpt3sas_base_free_irq - free irq * @ioc: per adapter object * * Freeing respective reply_queue from the list. */ void mpt3sas_base_free_irq(struct MPT3SAS_ADAPTER *ioc) { unsigned int irq; struct adapter_reply_queue *reply_q, *next; if (list_empty(&ioc->reply_queue_list)) return; list_for_each_entry_safe(reply_q, next, &ioc->reply_queue_list, list) { list_del(&reply_q->list); if (reply_q->is_iouring_poll_q) { kfree(reply_q); continue; } if (ioc->smp_affinity_enable) { irq = pci_irq_vector(ioc->pdev, reply_q->msix_index); irq_update_affinity_hint(irq, NULL); } free_irq(pci_irq_vector(ioc->pdev, reply_q->msix_index), reply_q); kfree(reply_q); } } /** * _base_request_irq - request irq * @ioc: per adapter object * @index: msix index into vector table * * Inserting respective reply_queue into the list. */ static int _base_request_irq(struct MPT3SAS_ADAPTER *ioc, u8 index) { struct pci_dev *pdev = ioc->pdev; struct adapter_reply_queue *reply_q; int r, qid; reply_q = kzalloc(sizeof(struct adapter_reply_queue), GFP_KERNEL); if (!reply_q) { ioc_err(ioc, "unable to allocate memory %zu!\n", sizeof(struct adapter_reply_queue)); return -ENOMEM; } reply_q->ioc = ioc; reply_q->msix_index = index; atomic_set(&reply_q->busy, 0); if (index >= ioc->iopoll_q_start_index) { qid = index - ioc->iopoll_q_start_index; snprintf(reply_q->name, MPT_NAME_LENGTH, "%s%d-mq-poll%d", ioc->driver_name, ioc->id, qid); reply_q->is_iouring_poll_q = 1; ioc->io_uring_poll_queues[qid].reply_q = reply_q; goto out; } if (ioc->msix_enable) snprintf(reply_q->name, MPT_NAME_LENGTH, "%s%d-msix%d", ioc->driver_name, ioc->id, index); else snprintf(reply_q->name, MPT_NAME_LENGTH, "%s%d", ioc->driver_name, ioc->id); r = request_irq(pci_irq_vector(pdev, index), _base_interrupt, IRQF_SHARED, reply_q->name, reply_q); if (r) { pr_err("%s: unable to allocate interrupt %d!\n", reply_q->name, pci_irq_vector(pdev, index)); kfree(reply_q); return -EBUSY; } out: INIT_LIST_HEAD(&reply_q->list); list_add_tail(&reply_q->list, &ioc->reply_queue_list); return 0; } /** * _base_assign_reply_queues - assigning msix index for each cpu * @ioc: per adapter object * * The enduser would need to set the affinity via /proc/irq/#/smp_affinity */ static void _base_assign_reply_queues(struct MPT3SAS_ADAPTER *ioc) { unsigned int cpu, nr_cpus, nr_msix, index = 0, irq; struct adapter_reply_queue *reply_q; int iopoll_q_count = ioc->reply_queue_count - ioc->iopoll_q_start_index; const struct cpumask *mask; if (!_base_is_controller_msix_enabled(ioc)) return; if (ioc->msix_load_balance) return; memset(ioc->cpu_msix_table, 0, ioc->cpu_msix_table_sz); nr_cpus = num_online_cpus(); nr_msix = ioc->reply_queue_count = min(ioc->reply_queue_count, ioc->facts.MaxMSIxVectors); if (!nr_msix) return; if (ioc->smp_affinity_enable) { /* * set irq affinity to local numa node for those irqs * corresponding to high iops queues. */ if (ioc->high_iops_queues) { mask = cpumask_of_node(dev_to_node(&ioc->pdev->dev)); for (index = 0; index < ioc->high_iops_queues; index++) { irq = pci_irq_vector(ioc->pdev, index); irq_set_affinity_and_hint(irq, mask); } } list_for_each_entry(reply_q, &ioc->reply_queue_list, list) { const cpumask_t *mask; if (reply_q->msix_index < ioc->high_iops_queues || reply_q->msix_index >= ioc->iopoll_q_start_index) continue; mask = pci_irq_get_affinity(ioc->pdev, reply_q->msix_index); if (!mask) { ioc_warn(ioc, "no affinity for msi %x\n", reply_q->msix_index); goto fall_back; } for_each_cpu_and(cpu, mask, cpu_online_mask) { if (cpu >= ioc->cpu_msix_table_sz) break; ioc->cpu_msix_table[cpu] = reply_q->msix_index; } } return; } fall_back: cpu = cpumask_first(cpu_online_mask); nr_msix -= (ioc->high_iops_queues - iopoll_q_count); index = 0; list_for_each_entry(reply_q, &ioc->reply_queue_list, list) { unsigned int i, group = nr_cpus / nr_msix; if (reply_q->msix_index < ioc->high_iops_queues || reply_q->msix_index >= ioc->iopoll_q_start_index) continue; if (cpu >= nr_cpus) break; if (index < nr_cpus % nr_msix) group++; for (i = 0 ; i < group ; i++) { ioc->cpu_msix_table[cpu] = reply_q->msix_index; cpu = cpumask_next(cpu, cpu_online_mask); } index++; } } /** * _base_check_and_enable_high_iops_queues - enable high iops mode * @ioc: per adapter object * @hba_msix_vector_count: msix vectors supported by HBA * * Enable high iops queues only if * - HBA is a SEA/AERO controller and * - MSI-Xs vector supported by the HBA is 128 and * - total CPU count in the system >=16 and * - loaded driver with default max_msix_vectors module parameter and * - system booted in non kdump mode * * Return: nothing. */ static void _base_check_and_enable_high_iops_queues(struct MPT3SAS_ADAPTER *ioc, int hba_msix_vector_count) { u16 lnksta, speed; /* * Disable high iops queues if io uring poll queues are enabled. */ if (perf_mode == MPT_PERF_MODE_IOPS || perf_mode == MPT_PERF_MODE_LATENCY || ioc->io_uring_poll_queues) { ioc->high_iops_queues = 0; return; } if (perf_mode == MPT_PERF_MODE_DEFAULT) { pcie_capability_read_word(ioc->pdev, PCI_EXP_LNKSTA, &lnksta); speed = lnksta & PCI_EXP_LNKSTA_CLS; if (speed < 0x4) { ioc->high_iops_queues = 0; return; } } if (!reset_devices && ioc->is_aero_ioc && hba_msix_vector_count == MPT3SAS_GEN35_MAX_MSIX_QUEUES && num_online_cpus() >= MPT3SAS_HIGH_IOPS_REPLY_QUEUES && max_msix_vectors == -1) ioc->high_iops_queues = MPT3SAS_HIGH_IOPS_REPLY_QUEUES; else ioc->high_iops_queues = 0; } /** * mpt3sas_base_disable_msix - disables msix * @ioc: per adapter object * */ void mpt3sas_base_disable_msix(struct MPT3SAS_ADAPTER *ioc) { if (!ioc->msix_enable) return; pci_free_irq_vectors(ioc->pdev); ioc->msix_enable = 0; kfree(ioc->io_uring_poll_queues); } /** * _base_alloc_irq_vectors - allocate msix vectors * @ioc: per adapter object * */ static int _base_alloc_irq_vectors(struct MPT3SAS_ADAPTER *ioc) { int i, irq_flags = PCI_IRQ_MSIX; struct irq_affinity desc = { .pre_vectors = ioc->high_iops_queues }; struct irq_affinity *descp = &desc; /* * Don't allocate msix vectors for poll_queues. * msix_vectors is always within a range of FW supported reply queue. */ int nr_msix_vectors = ioc->iopoll_q_start_index; if (ioc->smp_affinity_enable) irq_flags |= PCI_IRQ_AFFINITY | PCI_IRQ_ALL_TYPES; else descp = NULL; ioc_info(ioc, " %d %d %d\n", ioc->high_iops_queues, ioc->reply_queue_count, nr_msix_vectors); i = pci_alloc_irq_vectors_affinity(ioc->pdev, ioc->high_iops_queues, nr_msix_vectors, irq_flags, descp); return i; } /** * _base_enable_msix - enables msix, failback to io_apic * @ioc: per adapter object * */ static int _base_enable_msix(struct MPT3SAS_ADAPTER *ioc) { int r; int i, local_max_msix_vectors; u8 try_msix = 0; int iopoll_q_count = 0; ioc->msix_load_balance = false; if (msix_disable == -1 || msix_disable == 0) try_msix = 1; if (!try_msix) goto try_ioapic; if (_base_check_enable_msix(ioc) != 0) goto try_ioapic; ioc_info(ioc, "MSI-X vectors supported: %d\n", ioc->msix_vector_count); pr_info("\t no of cores: %d, max_msix_vectors: %d\n", ioc->cpu_count, max_msix_vectors); ioc->reply_queue_count = min_t(int, ioc->cpu_count, ioc->msix_vector_count); if (!ioc->rdpq_array_enable && max_msix_vectors == -1) local_max_msix_vectors = (reset_devices) ? 1 : 8; else local_max_msix_vectors = max_msix_vectors; if (local_max_msix_vectors == 0) goto try_ioapic; /* * Enable msix_load_balance only if combined reply queue mode is * disabled on SAS3 & above generation HBA devices. */ if (!ioc->combined_reply_queue && ioc->hba_mpi_version_belonged != MPI2_VERSION) { ioc_info(ioc, "combined ReplyQueue is off, Enabling msix load balance\n"); ioc->msix_load_balance = true; } /* * smp affinity setting is not need when msix load balance * is enabled. */ if (ioc->msix_load_balance) ioc->smp_affinity_enable = 0; if (!ioc->smp_affinity_enable || ioc->reply_queue_count <= 1) ioc->shost->host_tagset = 0; /* * Enable io uring poll queues only if host_tagset is enabled. */ if (ioc->shost->host_tagset) iopoll_q_count = poll_queues; if (iopoll_q_count) { ioc->io_uring_poll_queues = kcalloc(iopoll_q_count, sizeof(struct io_uring_poll_queue), GFP_KERNEL); if (!ioc->io_uring_poll_queues) iopoll_q_count = 0; } if (ioc->is_aero_ioc) _base_check_and_enable_high_iops_queues(ioc, ioc->msix_vector_count); /* * Add high iops queues count to reply queue count if high iops queues * are enabled. */ ioc->reply_queue_count = min_t(int, ioc->reply_queue_count + ioc->high_iops_queues, ioc->msix_vector_count); /* * Adjust the reply queue count incase reply queue count * exceeds the user provided MSIx vectors count. */ if (local_max_msix_vectors > 0) ioc->reply_queue_count = min_t(int, local_max_msix_vectors, ioc->reply_queue_count); /* * Add io uring poll queues count to reply queues count * if io uring is enabled in driver. */ if (iopoll_q_count) { if (ioc->reply_queue_count < (iopoll_q_count + MPT3_MIN_IRQS)) iopoll_q_count = 0; ioc->reply_queue_count = min_t(int, ioc->reply_queue_count + iopoll_q_count, ioc->msix_vector_count); } /* * Starting index of io uring poll queues in reply queue list. */ ioc->iopoll_q_start_index = ioc->reply_queue_count - iopoll_q_count; r = _base_alloc_irq_vectors(ioc); if (r < 0) { ioc_info(ioc, "pci_alloc_irq_vectors failed (r=%d) !!!\n", r); goto try_ioapic; } /* * Adjust the reply queue count if the allocated * MSIx vectors is less then the requested number * of MSIx vectors. */ if (r < ioc->iopoll_q_start_index) { ioc->reply_queue_count = r + iopoll_q_count; ioc->iopoll_q_start_index = ioc->reply_queue_count - iopoll_q_count; } ioc->msix_enable = 1; for (i = 0; i < ioc->reply_queue_count; i++) { r = _base_request_irq(ioc, i); if (r) { mpt3sas_base_free_irq(ioc); mpt3sas_base_disable_msix(ioc); goto try_ioapic; } } ioc_info(ioc, "High IOPs queues : %s\n", ioc->high_iops_queues ? "enabled" : "disabled"); return 0; /* failback to io_apic interrupt routing */ try_ioapic: ioc->high_iops_queues = 0; ioc_info(ioc, "High IOPs queues : disabled\n"); ioc->reply_queue_count = 1; ioc->iopoll_q_start_index = ioc->reply_queue_count - 0; r = pci_alloc_irq_vectors(ioc->pdev, 1, 1, PCI_IRQ_LEGACY); if (r < 0) { dfailprintk(ioc, ioc_info(ioc, "pci_alloc_irq_vector(legacy) failed (r=%d) !!!\n", r)); } else r = _base_request_irq(ioc, 0); return r; } /** * mpt3sas_base_unmap_resources - free controller resources * @ioc: per adapter object */ static void mpt3sas_base_unmap_resources(struct MPT3SAS_ADAPTER *ioc) { struct pci_dev *pdev = ioc->pdev; dexitprintk(ioc, ioc_info(ioc, "%s\n", __func__)); mpt3sas_base_free_irq(ioc); mpt3sas_base_disable_msix(ioc); kfree(ioc->replyPostRegisterIndex); ioc->replyPostRegisterIndex = NULL; if (ioc->chip_phys) { iounmap(ioc->chip); ioc->chip_phys = 0; } if (pci_is_enabled(pdev)) { pci_release_selected_regions(ioc->pdev, ioc->bars); pci_disable_pcie_error_reporting(pdev); pci_disable_device(pdev); } } static int _base_diag_reset(struct MPT3SAS_ADAPTER *ioc); /** * mpt3sas_base_check_for_fault_and_issue_reset - check if IOC is in fault state * and if it is in fault state then issue diag reset. * @ioc: per adapter object * * Return: 0 for success, non-zero for failure. */ int mpt3sas_base_check_for_fault_and_issue_reset(struct MPT3SAS_ADAPTER *ioc) { u32 ioc_state; int rc = -EFAULT; dinitprintk(ioc, pr_info("%s\n", __func__)); if (ioc->pci_error_recovery) return 0; ioc_state = mpt3sas_base_get_iocstate(ioc, 0); dhsprintk(ioc, pr_info("%s: ioc_state(0x%08x)\n", __func__, ioc_state)); if ((ioc_state & MPI2_IOC_STATE_MASK) == MPI2_IOC_STATE_FAULT) { mpt3sas_print_fault_code(ioc, ioc_state & MPI2_DOORBELL_DATA_MASK); mpt3sas_base_mask_interrupts(ioc); rc = _base_diag_reset(ioc); } else if ((ioc_state & MPI2_IOC_STATE_MASK) == MPI2_IOC_STATE_COREDUMP) { mpt3sas_print_coredump_info(ioc, ioc_state & MPI2_DOORBELL_DATA_MASK); mpt3sas_base_wait_for_coredump_completion(ioc, __func__); mpt3sas_base_mask_interrupts(ioc); rc = _base_diag_reset(ioc); } return rc; } /** * mpt3sas_base_map_resources - map in controller resources (io/irq/memap) * @ioc: per adapter object * * Return: 0 for success, non-zero for failure. */ int mpt3sas_base_map_resources(struct MPT3SAS_ADAPTER *ioc) { struct pci_dev *pdev = ioc->pdev; u32 memap_sz; u32 pio_sz; int i, r = 0, rc; u64 pio_chip = 0; phys_addr_t chip_phys = 0; struct adapter_reply_queue *reply_q; int iopoll_q_count = 0; dinitprintk(ioc, ioc_info(ioc, "%s\n", __func__)); ioc->bars = pci_select_bars(pdev, IORESOURCE_MEM); if (pci_enable_device_mem(pdev)) { ioc_warn(ioc, "pci_enable_device_mem: failed\n"); ioc->bars = 0; return -ENODEV; } if (pci_request_selected_regions(pdev, ioc->bars, ioc->driver_name)) { ioc_warn(ioc, "pci_request_selected_regions: failed\n"); ioc->bars = 0; r = -ENODEV; goto out_fail; } /* AER (Advanced Error Reporting) hooks */ pci_enable_pcie_error_reporting(pdev); pci_set_master(pdev); if (_base_config_dma_addressing(ioc, pdev) != 0) { ioc_warn(ioc, "no suitable DMA mask for %s\n", pci_name(pdev)); r = -ENODEV; goto out_fail; } for (i = 0, memap_sz = 0, pio_sz = 0; (i < DEVICE_COUNT_RESOURCE) && (!memap_sz || !pio_sz); i++) { if (pci_resource_flags(pdev, i) & IORESOURCE_IO) { if (pio_sz) continue; pio_chip = (u64)pci_resource_start(pdev, i); pio_sz = pci_resource_len(pdev, i); } else if (pci_resource_flags(pdev, i) & IORESOURCE_MEM) { if (memap_sz) continue; ioc->chip_phys = pci_resource_start(pdev, i); chip_phys = ioc->chip_phys; memap_sz = pci_resource_len(pdev, i); ioc->chip = ioremap(ioc->chip_phys, memap_sz); } } if (ioc->chip == NULL) { ioc_err(ioc, "unable to map adapter memory! or resource not found\n"); r = -EINVAL; goto out_fail; } mpt3sas_base_mask_interrupts(ioc); r = _base_get_ioc_facts(ioc); if (r) { rc = mpt3sas_base_check_for_fault_and_issue_reset(ioc); if (rc || (_base_get_ioc_facts(ioc))) goto out_fail; } if (!ioc->rdpq_array_enable_assigned) { ioc->rdpq_array_enable = ioc->rdpq_array_capable; ioc->rdpq_array_enable_assigned = 1; } r = _base_enable_msix(ioc); if (r) goto out_fail; iopoll_q_count = ioc->reply_queue_count - ioc->iopoll_q_start_index; for (i = 0; i < iopoll_q_count; i++) { atomic_set(&ioc->io_uring_poll_queues[i].busy, 0); atomic_set(&ioc->io_uring_poll_queues[i].pause, 0); } if (!ioc->is_driver_loading) _base_init_irqpolls(ioc); /* Use the Combined reply queue feature only for SAS3 C0 & higher * revision HBAs and also only when reply queue count is greater than 8 */ if (ioc->combined_reply_queue) { /* Determine the Supplemental Reply Post Host Index Registers * Addresse. Supplemental Reply Post Host Index Registers * starts at offset MPI25_SUP_REPLY_POST_HOST_INDEX_OFFSET and * each register is at offset bytes of * MPT3_SUP_REPLY_POST_HOST_INDEX_REG_OFFSET from previous one. */ ioc->replyPostRegisterIndex = kcalloc( ioc->combined_reply_index_count, sizeof(resource_size_t *), GFP_KERNEL); if (!ioc->replyPostRegisterIndex) { ioc_err(ioc, "allocation for replyPostRegisterIndex failed!\n"); r = -ENOMEM; goto out_fail; } for (i = 0; i < ioc->combined_reply_index_count; i++) { ioc->replyPostRegisterIndex[i] = (resource_size_t *) ((u8 __force *)&ioc->chip->Doorbell + MPI25_SUP_REPLY_POST_HOST_INDEX_OFFSET + (i * MPT3_SUP_REPLY_POST_HOST_INDEX_REG_OFFSET)); } } if (ioc->is_warpdrive) { ioc->reply_post_host_index[0] = (resource_size_t __iomem *) &ioc->chip->ReplyPostHostIndex; for (i = 1; i < ioc->cpu_msix_table_sz; i++) ioc->reply_post_host_index[i] = (resource_size_t __iomem *) ((u8 __iomem *)&ioc->chip->Doorbell + (0x4000 + ((i - 1) * 4))); } list_for_each_entry(reply_q, &ioc->reply_queue_list, list) { if (reply_q->msix_index >= ioc->iopoll_q_start_index) { pr_info("%s: enabled: index: %d\n", reply_q->name, reply_q->msix_index); continue; } pr_info("%s: %s enabled: IRQ %d\n", reply_q->name, ioc->msix_enable ? "PCI-MSI-X" : "IO-APIC", pci_irq_vector(ioc->pdev, reply_q->msix_index)); } ioc_info(ioc, "iomem(%pap), mapped(0x%p), size(%d)\n", &chip_phys, ioc->chip, memap_sz); ioc_info(ioc, "ioport(0x%016llx), size(%d)\n", (unsigned long long)pio_chip, pio_sz); /* Save PCI configuration state for recovery from PCI AER/EEH errors */ pci_save_state(pdev); return 0; out_fail: mpt3sas_base_unmap_resources(ioc); return r; } /** * mpt3sas_base_get_msg_frame - obtain request mf pointer * @ioc: per adapter object * @smid: system request message index(smid zero is invalid) * * Return: virt pointer to message frame. */ void * mpt3sas_base_get_msg_frame(struct MPT3SAS_ADAPTER *ioc, u16 smid) { return (void *)(ioc->request + (smid * ioc->request_sz)); } /** * mpt3sas_base_get_sense_buffer - obtain a sense buffer virt addr * @ioc: per adapter object * @smid: system request message index * * Return: virt pointer to sense buffer. */ void * mpt3sas_base_get_sense_buffer(struct MPT3SAS_ADAPTER *ioc, u16 smid) { return (void *)(ioc->sense + ((smid - 1) * SCSI_SENSE_BUFFERSIZE)); } /** * mpt3sas_base_get_sense_buffer_dma - obtain a sense buffer dma addr * @ioc: per adapter object * @smid: system request message index * * Return: phys pointer to the low 32bit address of the sense buffer. */ __le32 mpt3sas_base_get_sense_buffer_dma(struct MPT3SAS_ADAPTER *ioc, u16 smid) { return cpu_to_le32(ioc->sense_dma + ((smid - 1) * SCSI_SENSE_BUFFERSIZE)); } /** * mpt3sas_base_get_pcie_sgl - obtain a PCIe SGL virt addr * @ioc: per adapter object * @smid: system request message index * * Return: virt pointer to a PCIe SGL. */ void * mpt3sas_base_get_pcie_sgl(struct MPT3SAS_ADAPTER *ioc, u16 smid) { return (void *)(ioc->pcie_sg_lookup[smid - 1].pcie_sgl); } /** * mpt3sas_base_get_pcie_sgl_dma - obtain a PCIe SGL dma addr * @ioc: per adapter object * @smid: system request message index * * Return: phys pointer to the address of the PCIe buffer. */ dma_addr_t mpt3sas_base_get_pcie_sgl_dma(struct MPT3SAS_ADAPTER *ioc, u16 smid) { return ioc->pcie_sg_lookup[smid - 1].pcie_sgl_dma; } /** * mpt3sas_base_get_reply_virt_addr - obtain reply frames virt address * @ioc: per adapter object * @phys_addr: lower 32 physical addr of the reply * * Converts 32bit lower physical addr into a virt address. */ void * mpt3sas_base_get_reply_virt_addr(struct MPT3SAS_ADAPTER *ioc, u32 phys_addr) { if (!phys_addr) return NULL; return ioc->reply + (phys_addr - (u32)ioc->reply_dma); } /** * _base_get_msix_index - get the msix index * @ioc: per adapter object * @scmd: scsi_cmnd object * * Return: msix index of general reply queues, * i.e. reply queue on which IO request's reply * should be posted by the HBA firmware. */ static inline u8 _base_get_msix_index(struct MPT3SAS_ADAPTER *ioc, struct scsi_cmnd *scmd) { /* Enables reply_queue load balancing */ if (ioc->msix_load_balance) return ioc->reply_queue_count ? base_mod64(atomic64_add_return(1, &ioc->total_io_cnt), ioc->reply_queue_count) : 0; if (scmd && ioc->shost->nr_hw_queues > 1) { u32 tag = blk_mq_unique_tag(scsi_cmd_to_rq(scmd)); return blk_mq_unique_tag_to_hwq(tag) + ioc->high_iops_queues; } return ioc->cpu_msix_table[raw_smp_processor_id()]; } /** * _base_get_high_iops_msix_index - get the msix index of * high iops queues * @ioc: per adapter object * @scmd: scsi_cmnd object * * Return: msix index of high iops reply queues. * i.e. high iops reply queue on which IO request's * reply should be posted by the HBA firmware. */ static inline u8 _base_get_high_iops_msix_index(struct MPT3SAS_ADAPTER *ioc, struct scsi_cmnd *scmd) { /** * Round robin the IO interrupts among the high iops * reply queues in terms of batch count 16 when outstanding * IOs on the target device is >=8. */ if (scsi_device_busy(scmd->device) > MPT3SAS_DEVICE_HIGH_IOPS_DEPTH) return base_mod64(( atomic64_add_return(1, &ioc->high_iops_outstanding) / MPT3SAS_HIGH_IOPS_BATCH_COUNT), MPT3SAS_HIGH_IOPS_REPLY_QUEUES); return _base_get_msix_index(ioc, scmd); } /** * mpt3sas_base_get_smid - obtain a free smid from internal queue * @ioc: per adapter object * @cb_idx: callback index * * Return: smid (zero is invalid) */ u16 mpt3sas_base_get_smid(struct MPT3SAS_ADAPTER *ioc, u8 cb_idx) { unsigned long flags; struct request_tracker *request; u16 smid; spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); if (list_empty(&ioc->internal_free_list)) { spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags); ioc_err(ioc, "%s: smid not available\n", __func__); return 0; } request = list_entry(ioc->internal_free_list.next, struct request_tracker, tracker_list); request->cb_idx = cb_idx; smid = request->smid; list_del(&request->tracker_list); spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags); return smid; } /** * mpt3sas_base_get_smid_scsiio - obtain a free smid from scsiio queue * @ioc: per adapter object * @cb_idx: callback index * @scmd: pointer to scsi command object * * Return: smid (zero is invalid) */ u16 mpt3sas_base_get_smid_scsiio(struct MPT3SAS_ADAPTER *ioc, u8 cb_idx, struct scsi_cmnd *scmd) { struct scsiio_tracker *request = scsi_cmd_priv(scmd); u16 smid; u32 tag, unique_tag; unique_tag = blk_mq_unique_tag(scsi_cmd_to_rq(scmd)); tag = blk_mq_unique_tag_to_tag(unique_tag); /* * Store hw queue number corresponding to the tag. * This hw queue number is used later to determine * the unique_tag using the logic below. This unique_tag * is used to retrieve the scmd pointer corresponding * to tag using scsi_host_find_tag() API. * * tag = smid - 1; * unique_tag = ioc->io_queue_num[tag] << BLK_MQ_UNIQUE_TAG_BITS | tag; */ ioc->io_queue_num[tag] = blk_mq_unique_tag_to_hwq(unique_tag); smid = tag + 1; request->cb_idx = cb_idx; request->smid = smid; request->scmd = scmd; INIT_LIST_HEAD(&request->chain_list); return smid; } /** * mpt3sas_base_get_smid_hpr - obtain a free smid from hi-priority queue * @ioc: per adapter object * @cb_idx: callback index * * Return: smid (zero is invalid) */ u16 mpt3sas_base_get_smid_hpr(struct MPT3SAS_ADAPTER *ioc, u8 cb_idx) { unsigned long flags; struct request_tracker *request; u16 smid; spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); if (list_empty(&ioc->hpr_free_list)) { spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags); return 0; } request = list_entry(ioc->hpr_free_list.next, struct request_tracker, tracker_list); request->cb_idx = cb_idx; smid = request->smid; list_del(&request->tracker_list); spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags); return smid; } static void _base_recovery_check(struct MPT3SAS_ADAPTER *ioc) { /* * See _wait_for_commands_to_complete() call with regards to this code. */ if (ioc->shost_recovery && ioc->pending_io_count) { ioc->pending_io_count = scsi_host_busy(ioc->shost); if (ioc->pending_io_count == 0) wake_up(&ioc->reset_wq); } } void mpt3sas_base_clear_st(struct MPT3SAS_ADAPTER *ioc, struct scsiio_tracker *st) { if (WARN_ON(st->smid == 0)) return; st->cb_idx = 0xFF; st->direct_io = 0; st->scmd = NULL; atomic_set(&ioc->chain_lookup[st->smid - 1].chain_offset, 0); st->smid = 0; } /** * mpt3sas_base_free_smid - put smid back on free_list * @ioc: per adapter object * @smid: system request message index */ void mpt3sas_base_free_smid(struct MPT3SAS_ADAPTER *ioc, u16 smid) { unsigned long flags; int i; if (smid < ioc->hi_priority_smid) { struct scsiio_tracker *st; void *request; st = _get_st_from_smid(ioc, smid); if (!st) { _base_recovery_check(ioc); return; } /* Clear MPI request frame */ request = mpt3sas_base_get_msg_frame(ioc, smid); memset(request, 0, ioc->request_sz); mpt3sas_base_clear_st(ioc, st); _base_recovery_check(ioc); ioc->io_queue_num[smid - 1] = 0; return; } spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); if (smid < ioc->internal_smid) { /* hi-priority */ i = smid - ioc->hi_priority_smid; ioc->hpr_lookup[i].cb_idx = 0xFF; list_add(&ioc->hpr_lookup[i].tracker_list, &ioc->hpr_free_list); } else if (smid <= ioc->hba_queue_depth) { /* internal queue */ i = smid - ioc->internal_smid; ioc->internal_lookup[i].cb_idx = 0xFF; list_add(&ioc->internal_lookup[i].tracker_list, &ioc->internal_free_list); } spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags); } /** * _base_mpi_ep_writeq - 32 bit write to MMIO * @b: data payload * @addr: address in MMIO space * @writeq_lock: spin lock * * This special handling for MPI EP to take care of 32 bit * environment where its not quarenteed to send the entire word * in one transfer. */ static inline void _base_mpi_ep_writeq(__u64 b, volatile void __iomem *addr, spinlock_t *writeq_lock) { unsigned long flags; spin_lock_irqsave(writeq_lock, flags); __raw_writel((u32)(b), addr); __raw_writel((u32)(b >> 32), (addr + 4)); spin_unlock_irqrestore(writeq_lock, flags); } /** * _base_writeq - 64 bit write to MMIO * @b: data payload * @addr: address in MMIO space * @writeq_lock: spin lock * * Glue for handling an atomic 64 bit word to MMIO. This special handling takes * care of 32 bit environment where its not quarenteed to send the entire word * in one transfer. */ #if defined(writeq) && defined(CONFIG_64BIT) static inline void _base_writeq(__u64 b, volatile void __iomem *addr, spinlock_t *writeq_lock) { wmb(); __raw_writeq(b, addr); barrier(); } #else static inline void _base_writeq(__u64 b, volatile void __iomem *addr, spinlock_t *writeq_lock) { _base_mpi_ep_writeq(b, addr, writeq_lock); } #endif /** * _base_set_and_get_msix_index - get the msix index and assign to msix_io * variable of scsi tracker * @ioc: per adapter object * @smid: system request message index * * Return: msix index. */ static u8 _base_set_and_get_msix_index(struct MPT3SAS_ADAPTER *ioc, u16 smid) { struct scsiio_tracker *st = NULL; if (smid < ioc->hi_priority_smid) st = _get_st_from_smid(ioc, smid); if (st == NULL) return _base_get_msix_index(ioc, NULL); st->msix_io = ioc->get_msix_index_for_smlio(ioc, st->scmd); return st->msix_io; } /** * _base_put_smid_mpi_ep_scsi_io - send SCSI_IO request to firmware * @ioc: per adapter object * @smid: system request message index * @handle: device handle */ static void _base_put_smid_mpi_ep_scsi_io(struct MPT3SAS_ADAPTER *ioc, u16 smid, u16 handle) { Mpi2RequestDescriptorUnion_t descriptor; u64 *request = (u64 *)&descriptor; void *mpi_req_iomem; __le32 *mfp = (__le32 *)mpt3sas_base_get_msg_frame(ioc, smid); _clone_sg_entries(ioc, (void *) mfp, smid); mpi_req_iomem = (void __force *)ioc->chip + MPI_FRAME_START_OFFSET + (smid * ioc->request_sz); _base_clone_mpi_to_sys_mem(mpi_req_iomem, (void *)mfp, ioc->request_sz); descriptor.SCSIIO.RequestFlags = MPI2_REQ_DESCRIPT_FLAGS_SCSI_IO; descriptor.SCSIIO.MSIxIndex = _base_set_and_get_msix_index(ioc, smid); descriptor.SCSIIO.SMID = cpu_to_le16(smid); descriptor.SCSIIO.DevHandle = cpu_to_le16(handle); descriptor.SCSIIO.LMID = 0; _base_mpi_ep_writeq(*request, &ioc->chip->RequestDescriptorPostLow, &ioc->scsi_lookup_lock); } /** * _base_put_smid_scsi_io - send SCSI_IO request to firmware * @ioc: per adapter object * @smid: system request message index * @handle: device handle */ static void _base_put_smid_scsi_io(struct MPT3SAS_ADAPTER *ioc, u16 smid, u16 handle) { Mpi2RequestDescriptorUnion_t descriptor; u64 *request = (u64 *)&descriptor; descriptor.SCSIIO.RequestFlags = MPI2_REQ_DESCRIPT_FLAGS_SCSI_IO; descriptor.SCSIIO.MSIxIndex = _base_set_and_get_msix_index(ioc, smid); descriptor.SCSIIO.SMID = cpu_to_le16(smid); descriptor.SCSIIO.DevHandle = cpu_to_le16(handle); descriptor.SCSIIO.LMID = 0; _base_writeq(*request, &ioc->chip->RequestDescriptorPostLow, &ioc->scsi_lookup_lock); } /** * _base_put_smid_fast_path - send fast path request to firmware * @ioc: per adapter object * @smid: system request message index * @handle: device handle */ static void _base_put_smid_fast_path(struct MPT3SAS_ADAPTER *ioc, u16 smid, u16 handle) { Mpi2RequestDescriptorUnion_t descriptor; u64 *request = (u64 *)&descriptor; descriptor.SCSIIO.RequestFlags = MPI25_REQ_DESCRIPT_FLAGS_FAST_PATH_SCSI_IO; descriptor.SCSIIO.MSIxIndex = _base_set_and_get_msix_index(ioc, smid); descriptor.SCSIIO.SMID = cpu_to_le16(smid); descriptor.SCSIIO.DevHandle = cpu_to_le16(handle); descriptor.SCSIIO.LMID = 0; _base_writeq(*request, &ioc->chip->RequestDescriptorPostLow, &ioc->scsi_lookup_lock); } /** * _base_put_smid_hi_priority - send Task Management request to firmware * @ioc: per adapter object * @smid: system request message index * @msix_task: msix_task will be same as msix of IO in case of task abort else 0 */ static void _base_put_smid_hi_priority(struct MPT3SAS_ADAPTER *ioc, u16 smid, u16 msix_task) { Mpi2RequestDescriptorUnion_t descriptor; void *mpi_req_iomem; u64 *request; if (ioc->is_mcpu_endpoint) { __le32 *mfp = (__le32 *)mpt3sas_base_get_msg_frame(ioc, smid); /* TBD 256 is offset within sys register. */ mpi_req_iomem = (void __force *)ioc->chip + MPI_FRAME_START_OFFSET + (smid * ioc->request_sz); _base_clone_mpi_to_sys_mem(mpi_req_iomem, (void *)mfp, ioc->request_sz); } request = (u64 *)&descriptor; descriptor.HighPriority.RequestFlags = MPI2_REQ_DESCRIPT_FLAGS_HIGH_PRIORITY; descriptor.HighPriority.MSIxIndex = msix_task; descriptor.HighPriority.SMID = cpu_to_le16(smid); descriptor.HighPriority.LMID = 0; descriptor.HighPriority.Reserved1 = 0; if (ioc->is_mcpu_endpoint) _base_mpi_ep_writeq(*request, &ioc->chip->RequestDescriptorPostLow, &ioc->scsi_lookup_lock); else _base_writeq(*request, &ioc->chip->RequestDescriptorPostLow, &ioc->scsi_lookup_lock); } /** * mpt3sas_base_put_smid_nvme_encap - send NVMe encapsulated request to * firmware * @ioc: per adapter object * @smid: system request message index */ void mpt3sas_base_put_smid_nvme_encap(struct MPT3SAS_ADAPTER *ioc, u16 smid) { Mpi2RequestDescriptorUnion_t descriptor; u64 *request = (u64 *)&descriptor; descriptor.Default.RequestFlags = MPI26_REQ_DESCRIPT_FLAGS_PCIE_ENCAPSULATED; descriptor.Default.MSIxIndex = _base_set_and_get_msix_index(ioc, smid); descriptor.Default.SMID = cpu_to_le16(smid); descriptor.Default.LMID = 0; descriptor.Default.DescriptorTypeDependent = 0; _base_writeq(*request, &ioc->chip->RequestDescriptorPostLow, &ioc->scsi_lookup_lock); } /** * _base_put_smid_default - Default, primarily used for config pages * @ioc: per adapter object * @smid: system request message index */ static void _base_put_smid_default(struct MPT3SAS_ADAPTER *ioc, u16 smid) { Mpi2RequestDescriptorUnion_t descriptor; void *mpi_req_iomem; u64 *request; if (ioc->is_mcpu_endpoint) { __le32 *mfp = (__le32 *)mpt3sas_base_get_msg_frame(ioc, smid); _clone_sg_entries(ioc, (void *) mfp, smid); /* TBD 256 is offset within sys register */ mpi_req_iomem = (void __force *)ioc->chip + MPI_FRAME_START_OFFSET + (smid * ioc->request_sz); _base_clone_mpi_to_sys_mem(mpi_req_iomem, (void *)mfp, ioc->request_sz); } request = (u64 *)&descriptor; descriptor.Default.RequestFlags = MPI2_REQ_DESCRIPT_FLAGS_DEFAULT_TYPE; descriptor.Default.MSIxIndex = _base_set_and_get_msix_index(ioc, smid); descriptor.Default.SMID = cpu_to_le16(smid); descriptor.Default.LMID = 0; descriptor.Default.DescriptorTypeDependent = 0; if (ioc->is_mcpu_endpoint) _base_mpi_ep_writeq(*request, &ioc->chip->RequestDescriptorPostLow, &ioc->scsi_lookup_lock); else _base_writeq(*request, &ioc->chip->RequestDescriptorPostLow, &ioc->scsi_lookup_lock); } /** * _base_put_smid_scsi_io_atomic - send SCSI_IO request to firmware using * Atomic Request Descriptor * @ioc: per adapter object * @smid: system request message index * @handle: device handle, unused in this function, for function type match * * Return: nothing. */ static void _base_put_smid_scsi_io_atomic(struct MPT3SAS_ADAPTER *ioc, u16 smid, u16 handle) { Mpi26AtomicRequestDescriptor_t descriptor; u32 *request = (u32 *)&descriptor; descriptor.RequestFlags = MPI2_REQ_DESCRIPT_FLAGS_SCSI_IO; descriptor.MSIxIndex = _base_set_and_get_msix_index(ioc, smid); descriptor.SMID = cpu_to_le16(smid); writel(cpu_to_le32(*request), &ioc->chip->AtomicRequestDescriptorPost); } /** * _base_put_smid_fast_path_atomic - send fast path request to firmware * using Atomic Request Descriptor * @ioc: per adapter object * @smid: system request message index * @handle: device handle, unused in this function, for function type match * Return: nothing */ static void _base_put_smid_fast_path_atomic(struct MPT3SAS_ADAPTER *ioc, u16 smid, u16 handle) { Mpi26AtomicRequestDescriptor_t descriptor; u32 *request = (u32 *)&descriptor; descriptor.RequestFlags = MPI25_REQ_DESCRIPT_FLAGS_FAST_PATH_SCSI_IO; descriptor.MSIxIndex = _base_set_and_get_msix_index(ioc, smid); descriptor.SMID = cpu_to_le16(smid); writel(cpu_to_le32(*request), &ioc->chip->AtomicRequestDescriptorPost); } /** * _base_put_smid_hi_priority_atomic - send Task Management request to * firmware using Atomic Request Descriptor * @ioc: per adapter object * @smid: system request message index * @msix_task: msix_task will be same as msix of IO in case of task abort else 0 * * Return: nothing. */ static void _base_put_smid_hi_priority_atomic(struct MPT3SAS_ADAPTER *ioc, u16 smid, u16 msix_task) { Mpi26AtomicRequestDescriptor_t descriptor; u32 *request = (u32 *)&descriptor; descriptor.RequestFlags = MPI2_REQ_DESCRIPT_FLAGS_HIGH_PRIORITY; descriptor.MSIxIndex = msix_task; descriptor.SMID = cpu_to_le16(smid); writel(cpu_to_le32(*request), &ioc->chip->AtomicRequestDescriptorPost); } /** * _base_put_smid_default_atomic - Default, primarily used for config pages * use Atomic Request Descriptor * @ioc: per adapter object * @smid: system request message index * * Return: nothing. */ static void _base_put_smid_default_atomic(struct MPT3SAS_ADAPTER *ioc, u16 smid) { Mpi26AtomicRequestDescriptor_t descriptor; u32 *request = (u32 *)&descriptor; descriptor.RequestFlags = MPI2_REQ_DESCRIPT_FLAGS_DEFAULT_TYPE; descriptor.MSIxIndex = _base_set_and_get_msix_index(ioc, smid); descriptor.SMID = cpu_to_le16(smid); writel(cpu_to_le32(*request), &ioc->chip->AtomicRequestDescriptorPost); } /** * _base_display_OEMs_branding - Display branding string * @ioc: per adapter object */ static void _base_display_OEMs_branding(struct MPT3SAS_ADAPTER *ioc) { if (ioc->pdev->subsystem_vendor != PCI_VENDOR_ID_INTEL) return; switch (ioc->pdev->subsystem_vendor) { case PCI_VENDOR_ID_INTEL: switch (ioc->pdev->device) { case MPI2_MFGPAGE_DEVID_SAS2008: switch (ioc->pdev->subsystem_device) { case MPT2SAS_INTEL_RMS2LL080_SSDID: ioc_info(ioc, "%s\n", MPT2SAS_INTEL_RMS2LL080_BRANDING); break; case MPT2SAS_INTEL_RMS2LL040_SSDID: ioc_info(ioc, "%s\n", MPT2SAS_INTEL_RMS2LL040_BRANDING); break; case MPT2SAS_INTEL_SSD910_SSDID: ioc_info(ioc, "%s\n", MPT2SAS_INTEL_SSD910_BRANDING); break; default: ioc_info(ioc, "Intel(R) Controller: Subsystem ID: 0x%X\n", ioc->pdev->subsystem_device); break; } break; case MPI2_MFGPAGE_DEVID_SAS2308_2: switch (ioc->pdev->subsystem_device) { case MPT2SAS_INTEL_RS25GB008_SSDID: ioc_info(ioc, "%s\n", MPT2SAS_INTEL_RS25GB008_BRANDING); break; case MPT2SAS_INTEL_RMS25JB080_SSDID: ioc_info(ioc, "%s\n", MPT2SAS_INTEL_RMS25JB080_BRANDING); break; case MPT2SAS_INTEL_RMS25JB040_SSDID: ioc_info(ioc, "%s\n", MPT2SAS_INTEL_RMS25JB040_BRANDING); break; case MPT2SAS_INTEL_RMS25KB080_SSDID: ioc_info(ioc, "%s\n", MPT2SAS_INTEL_RMS25KB080_BRANDING); break; case MPT2SAS_INTEL_RMS25KB040_SSDID: ioc_info(ioc, "%s\n", MPT2SAS_INTEL_RMS25KB040_BRANDING); break; case MPT2SAS_INTEL_RMS25LB040_SSDID: ioc_info(ioc, "%s\n", MPT2SAS_INTEL_RMS25LB040_BRANDING); break; case MPT2SAS_INTEL_RMS25LB080_SSDID: ioc_info(ioc, "%s\n", MPT2SAS_INTEL_RMS25LB080_BRANDING); break; default: ioc_info(ioc, "Intel(R) Controller: Subsystem ID: 0x%X\n", ioc->pdev->subsystem_device); break; } break; case MPI25_MFGPAGE_DEVID_SAS3008: switch (ioc->pdev->subsystem_device) { case MPT3SAS_INTEL_RMS3JC080_SSDID: ioc_info(ioc, "%s\n", MPT3SAS_INTEL_RMS3JC080_BRANDING); break; case MPT3SAS_INTEL_RS3GC008_SSDID: ioc_info(ioc, "%s\n", MPT3SAS_INTEL_RS3GC008_BRANDING); break; case MPT3SAS_INTEL_RS3FC044_SSDID: ioc_info(ioc, "%s\n", MPT3SAS_INTEL_RS3FC044_BRANDING); break; case MPT3SAS_INTEL_RS3UC080_SSDID: ioc_info(ioc, "%s\n", MPT3SAS_INTEL_RS3UC080_BRANDING); break; default: ioc_info(ioc, "Intel(R) Controller: Subsystem ID: 0x%X\n", ioc->pdev->subsystem_device); break; } break; default: ioc_info(ioc, "Intel(R) Controller: Subsystem ID: 0x%X\n", ioc->pdev->subsystem_device); break; } break; case PCI_VENDOR_ID_DELL: switch (ioc->pdev->device) { case MPI2_MFGPAGE_DEVID_SAS2008: switch (ioc->pdev->subsystem_device) { case MPT2SAS_DELL_6GBPS_SAS_HBA_SSDID: ioc_info(ioc, "%s\n", MPT2SAS_DELL_6GBPS_SAS_HBA_BRANDING); break; case MPT2SAS_DELL_PERC_H200_ADAPTER_SSDID: ioc_info(ioc, "%s\n", MPT2SAS_DELL_PERC_H200_ADAPTER_BRANDING); break; case MPT2SAS_DELL_PERC_H200_INTEGRATED_SSDID: ioc_info(ioc, "%s\n", MPT2SAS_DELL_PERC_H200_INTEGRATED_BRANDING); break; case MPT2SAS_DELL_PERC_H200_MODULAR_SSDID: ioc_info(ioc, "%s\n", MPT2SAS_DELL_PERC_H200_MODULAR_BRANDING); break; case MPT2SAS_DELL_PERC_H200_EMBEDDED_SSDID: ioc_info(ioc, "%s\n", MPT2SAS_DELL_PERC_H200_EMBEDDED_BRANDING); break; case MPT2SAS_DELL_PERC_H200_SSDID: ioc_info(ioc, "%s\n", MPT2SAS_DELL_PERC_H200_BRANDING); break; case MPT2SAS_DELL_6GBPS_SAS_SSDID: ioc_info(ioc, "%s\n", MPT2SAS_DELL_6GBPS_SAS_BRANDING); break; default: ioc_info(ioc, "Dell 6Gbps HBA: Subsystem ID: 0x%X\n", ioc->pdev->subsystem_device); break; } break; case MPI25_MFGPAGE_DEVID_SAS3008: switch (ioc->pdev->subsystem_device) { case MPT3SAS_DELL_12G_HBA_SSDID: ioc_info(ioc, "%s\n", MPT3SAS_DELL_12G_HBA_BRANDING); break; default: ioc_info(ioc, "Dell 12Gbps HBA: Subsystem ID: 0x%X\n", ioc->pdev->subsystem_device); break; } break; default: ioc_info(ioc, "Dell HBA: Subsystem ID: 0x%X\n", ioc->pdev->subsystem_device); break; } break; case PCI_VENDOR_ID_CISCO: switch (ioc->pdev->device) { case MPI25_MFGPAGE_DEVID_SAS3008: switch (ioc->pdev->subsystem_device) { case MPT3SAS_CISCO_12G_8E_HBA_SSDID: ioc_info(ioc, "%s\n", MPT3SAS_CISCO_12G_8E_HBA_BRANDING); break; case MPT3SAS_CISCO_12G_8I_HBA_SSDID: ioc_info(ioc, "%s\n", MPT3SAS_CISCO_12G_8I_HBA_BRANDING); break; case MPT3SAS_CISCO_12G_AVILA_HBA_SSDID: ioc_info(ioc, "%s\n", MPT3SAS_CISCO_12G_AVILA_HBA_BRANDING); break; default: ioc_info(ioc, "Cisco 12Gbps SAS HBA: Subsystem ID: 0x%X\n", ioc->pdev->subsystem_device); break; } break; case MPI25_MFGPAGE_DEVID_SAS3108_1: switch (ioc->pdev->subsystem_device) { case MPT3SAS_CISCO_12G_AVILA_HBA_SSDID: ioc_info(ioc, "%s\n", MPT3SAS_CISCO_12G_AVILA_HBA_BRANDING); break; case MPT3SAS_CISCO_12G_COLUSA_MEZZANINE_HBA_SSDID: ioc_info(ioc, "%s\n", MPT3SAS_CISCO_12G_COLUSA_MEZZANINE_HBA_BRANDING); break; default: ioc_info(ioc, "Cisco 12Gbps SAS HBA: Subsystem ID: 0x%X\n", ioc->pdev->subsystem_device); break; } break; default: ioc_info(ioc, "Cisco SAS HBA: Subsystem ID: 0x%X\n", ioc->pdev->subsystem_device); break; } break; case MPT2SAS_HP_3PAR_SSVID: switch (ioc->pdev->device) { case MPI2_MFGPAGE_DEVID_SAS2004: switch (ioc->pdev->subsystem_device) { case MPT2SAS_HP_DAUGHTER_2_4_INTERNAL_SSDID: ioc_info(ioc, "%s\n", MPT2SAS_HP_DAUGHTER_2_4_INTERNAL_BRANDING); break; default: ioc_info(ioc, "HP 6Gbps SAS HBA: Subsystem ID: 0x%X\n", ioc->pdev->subsystem_device); break; } break; case MPI2_MFGPAGE_DEVID_SAS2308_2: switch (ioc->pdev->subsystem_device) { case MPT2SAS_HP_2_4_INTERNAL_SSDID: ioc_info(ioc, "%s\n", MPT2SAS_HP_2_4_INTERNAL_BRANDING); break; case MPT2SAS_HP_2_4_EXTERNAL_SSDID: ioc_info(ioc, "%s\n", MPT2SAS_HP_2_4_EXTERNAL_BRANDING); break; case MPT2SAS_HP_1_4_INTERNAL_1_4_EXTERNAL_SSDID: ioc_info(ioc, "%s\n", MPT2SAS_HP_1_4_INTERNAL_1_4_EXTERNAL_BRANDING); break; case MPT2SAS_HP_EMBEDDED_2_4_INTERNAL_SSDID: ioc_info(ioc, "%s\n", MPT2SAS_HP_EMBEDDED_2_4_INTERNAL_BRANDING); break; default: ioc_info(ioc, "HP 6Gbps SAS HBA: Subsystem ID: 0x%X\n", ioc->pdev->subsystem_device); break; } break; default: ioc_info(ioc, "HP SAS HBA: Subsystem ID: 0x%X\n", ioc->pdev->subsystem_device); break; } break; default: break; } } /** * _base_display_fwpkg_version - sends FWUpload request to pull FWPkg * version from FW Image Header. * @ioc: per adapter object * * Return: 0 for success, non-zero for failure. */ static int _base_display_fwpkg_version(struct MPT3SAS_ADAPTER *ioc) { Mpi2FWImageHeader_t *fw_img_hdr; Mpi26ComponentImageHeader_t *cmp_img_hdr; Mpi25FWUploadRequest_t *mpi_request; Mpi2FWUploadReply_t mpi_reply; int r = 0, issue_diag_reset = 0; u32 package_version = 0; void *fwpkg_data = NULL; dma_addr_t fwpkg_data_dma; u16 smid, ioc_status; size_t data_length; dinitprintk(ioc, ioc_info(ioc, "%s\n", __func__)); if (ioc->base_cmds.status & MPT3_CMD_PENDING) { ioc_err(ioc, "%s: internal command already in use\n", __func__); return -EAGAIN; } data_length = sizeof(Mpi2FWImageHeader_t); fwpkg_data = dma_alloc_coherent(&ioc->pdev->dev, data_length, &fwpkg_data_dma, GFP_KERNEL); if (!fwpkg_data) { ioc_err(ioc, "Memory allocation for fwpkg data failed at %s:%d/%s()!\n", __FILE__, __LINE__, __func__); return -ENOMEM; } smid = mpt3sas_base_get_smid(ioc, ioc->base_cb_idx); if (!smid) { ioc_err(ioc, "%s: failed obtaining a smid\n", __func__); r = -EAGAIN; goto out; } ioc->base_cmds.status = MPT3_CMD_PENDING; mpi_request = mpt3sas_base_get_msg_frame(ioc, smid); ioc->base_cmds.smid = smid; memset(mpi_request, 0, sizeof(Mpi25FWUploadRequest_t)); mpi_request->Function = MPI2_FUNCTION_FW_UPLOAD; mpi_request->ImageType = MPI2_FW_UPLOAD_ITYPE_FW_FLASH; mpi_request->ImageSize = cpu_to_le32(data_length); ioc->build_sg(ioc, &mpi_request->SGL, 0, 0, fwpkg_data_dma, data_length); init_completion(&ioc->base_cmds.done); ioc->put_smid_default(ioc, smid); /* Wait for 15 seconds */ wait_for_completion_timeout(&ioc->base_cmds.done, FW_IMG_HDR_READ_TIMEOUT*HZ); ioc_info(ioc, "%s: complete\n", __func__); if (!(ioc->base_cmds.status & MPT3_CMD_COMPLETE)) { ioc_err(ioc, "%s: timeout\n", __func__); _debug_dump_mf(mpi_request, sizeof(Mpi25FWUploadRequest_t)/4); issue_diag_reset = 1; } else { memset(&mpi_reply, 0, sizeof(Mpi2FWUploadReply_t)); if (ioc->base_cmds.status & MPT3_CMD_REPLY_VALID) { memcpy(&mpi_reply, ioc->base_cmds.reply, sizeof(Mpi2FWUploadReply_t)); ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK; if (ioc_status == MPI2_IOCSTATUS_SUCCESS) { fw_img_hdr = (Mpi2FWImageHeader_t *)fwpkg_data; if (le32_to_cpu(fw_img_hdr->Signature) == MPI26_IMAGE_HEADER_SIGNATURE0_MPI26) { cmp_img_hdr = (Mpi26ComponentImageHeader_t *) (fwpkg_data); package_version = le32_to_cpu( cmp_img_hdr->ApplicationSpecific); } else package_version = le32_to_cpu( fw_img_hdr->PackageVersion.Word); if (package_version) ioc_info(ioc, "FW Package Ver(%02d.%02d.%02d.%02d)\n", ((package_version) & 0xFF000000) >> 24, ((package_version) & 0x00FF0000) >> 16, ((package_version) & 0x0000FF00) >> 8, (package_version) & 0x000000FF); } else { _debug_dump_mf(&mpi_reply, sizeof(Mpi2FWUploadReply_t)/4); } } } ioc->base_cmds.status = MPT3_CMD_NOT_USED; out: if (fwpkg_data) dma_free_coherent(&ioc->pdev->dev, data_length, fwpkg_data, fwpkg_data_dma); if (issue_diag_reset) { if (ioc->drv_internal_flags & MPT_DRV_INTERNAL_FIRST_PE_ISSUED) return -EFAULT; if (mpt3sas_base_check_for_fault_and_issue_reset(ioc)) return -EFAULT; r = -EAGAIN; } return r; } /** * _base_display_ioc_capabilities - Display IOC's capabilities. * @ioc: per adapter object */ static void _base_display_ioc_capabilities(struct MPT3SAS_ADAPTER *ioc) { int i = 0; char desc[16]; u32 iounit_pg1_flags; u32 bios_version; bios_version = le32_to_cpu(ioc->bios_pg3.BiosVersion); strncpy(desc, ioc->manu_pg0.ChipName, 16); ioc_info(ioc, "%s: FWVersion(%02d.%02d.%02d.%02d), ChipRevision(0x%02x), BiosVersion(%02d.%02d.%02d.%02d)\n", desc, (ioc->facts.FWVersion.Word & 0xFF000000) >> 24, (ioc->facts.FWVersion.Word & 0x00FF0000) >> 16, (ioc->facts.FWVersion.Word & 0x0000FF00) >> 8, ioc->facts.FWVersion.Word & 0x000000FF, ioc->pdev->revision, (bios_version & 0xFF000000) >> 24, (bios_version & 0x00FF0000) >> 16, (bios_version & 0x0000FF00) >> 8, bios_version & 0x000000FF); _base_display_OEMs_branding(ioc); if (ioc->facts.ProtocolFlags & MPI2_IOCFACTS_PROTOCOL_NVME_DEVICES) { pr_info("%sNVMe", i ? "," : ""); i++; } ioc_info(ioc, "Protocol=("); if (ioc->facts.ProtocolFlags & MPI2_IOCFACTS_PROTOCOL_SCSI_INITIATOR) { pr_cont("Initiator"); i++; } if (ioc->facts.ProtocolFlags & MPI2_IOCFACTS_PROTOCOL_SCSI_TARGET) { pr_cont("%sTarget", i ? "," : ""); i++; } i = 0; pr_cont("), Capabilities=("); if (!ioc->hide_ir_msg) { if (ioc->facts.IOCCapabilities & MPI2_IOCFACTS_CAPABILITY_INTEGRATED_RAID) { pr_cont("Raid"); i++; } } if (ioc->facts.IOCCapabilities & MPI2_IOCFACTS_CAPABILITY_TLR) { pr_cont("%sTLR", i ? "," : ""); i++; } if (ioc->facts.IOCCapabilities & MPI2_IOCFACTS_CAPABILITY_MULTICAST) { pr_cont("%sMulticast", i ? "," : ""); i++; } if (ioc->facts.IOCCapabilities & MPI2_IOCFACTS_CAPABILITY_BIDIRECTIONAL_TARGET) { pr_cont("%sBIDI Target", i ? "," : ""); i++; } if (ioc->facts.IOCCapabilities & MPI2_IOCFACTS_CAPABILITY_EEDP) { pr_cont("%sEEDP", i ? "," : ""); i++; } if (ioc->facts.IOCCapabilities & MPI2_IOCFACTS_CAPABILITY_SNAPSHOT_BUFFER) { pr_cont("%sSnapshot Buffer", i ? "," : ""); i++; } if (ioc->facts.IOCCapabilities & MPI2_IOCFACTS_CAPABILITY_DIAG_TRACE_BUFFER) { pr_cont("%sDiag Trace Buffer", i ? "," : ""); i++; } if (ioc->facts.IOCCapabilities & MPI2_IOCFACTS_CAPABILITY_EXTENDED_BUFFER) { pr_cont("%sDiag Extended Buffer", i ? "," : ""); i++; } if (ioc->facts.IOCCapabilities & MPI2_IOCFACTS_CAPABILITY_TASK_SET_FULL_HANDLING) { pr_cont("%sTask Set Full", i ? "," : ""); i++; } iounit_pg1_flags = le32_to_cpu(ioc->iounit_pg1.Flags); if (!(iounit_pg1_flags & MPI2_IOUNITPAGE1_NATIVE_COMMAND_Q_DISABLE)) { pr_cont("%sNCQ", i ? "," : ""); i++; } pr_cont(")\n"); } /** * mpt3sas_base_update_missing_delay - change the missing delay timers * @ioc: per adapter object * @device_missing_delay: amount of time till device is reported missing * @io_missing_delay: interval IO is returned when there is a missing device * * Passed on the command line, this function will modify the device missing * delay, as well as the io missing delay. This should be called at driver * load time. */ void mpt3sas_base_update_missing_delay(struct MPT3SAS_ADAPTER *ioc, u16 device_missing_delay, u8 io_missing_delay) { u16 dmd, dmd_new, dmd_orignal; u8 io_missing_delay_original; u16 sz; Mpi2SasIOUnitPage1_t *sas_iounit_pg1 = NULL; Mpi2ConfigReply_t mpi_reply; u8 num_phys = 0; u16 ioc_status; mpt3sas_config_get_number_hba_phys(ioc, &num_phys); if (!num_phys) return; sz = offsetof(Mpi2SasIOUnitPage1_t, PhyData) + (num_phys * sizeof(Mpi2SasIOUnit1PhyData_t)); sas_iounit_pg1 = kzalloc(sz, GFP_KERNEL); if (!sas_iounit_pg1) { ioc_err(ioc, "failure at %s:%d/%s()!\n", __FILE__, __LINE__, __func__); goto out; } if ((mpt3sas_config_get_sas_iounit_pg1(ioc, &mpi_reply, sas_iounit_pg1, sz))) { ioc_err(ioc, "failure at %s:%d/%s()!\n", __FILE__, __LINE__, __func__); goto out; } ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK; if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { ioc_err(ioc, "failure at %s:%d/%s()!\n", __FILE__, __LINE__, __func__); goto out; } /* device missing delay */ dmd = sas_iounit_pg1->ReportDeviceMissingDelay; if (dmd & MPI2_SASIOUNIT1_REPORT_MISSING_UNIT_16) dmd = (dmd & MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK) * 16; else dmd = dmd & MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK; dmd_orignal = dmd; if (device_missing_delay > 0x7F) { dmd = (device_missing_delay > 0x7F0) ? 0x7F0 : device_missing_delay; dmd = dmd / 16; dmd |= MPI2_SASIOUNIT1_REPORT_MISSING_UNIT_16; } else dmd = device_missing_delay; sas_iounit_pg1->ReportDeviceMissingDelay = dmd; /* io missing delay */ io_missing_delay_original = sas_iounit_pg1->IODeviceMissingDelay; sas_iounit_pg1->IODeviceMissingDelay = io_missing_delay; if (!mpt3sas_config_set_sas_iounit_pg1(ioc, &mpi_reply, sas_iounit_pg1, sz)) { if (dmd & MPI2_SASIOUNIT1_REPORT_MISSING_UNIT_16) dmd_new = (dmd & MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK) * 16; else dmd_new = dmd & MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK; ioc_info(ioc, "device_missing_delay: old(%d), new(%d)\n", dmd_orignal, dmd_new); ioc_info(ioc, "ioc_missing_delay: old(%d), new(%d)\n", io_missing_delay_original, io_missing_delay); ioc->device_missing_delay = dmd_new; ioc->io_missing_delay = io_missing_delay; } out: kfree(sas_iounit_pg1); } /** * _base_update_ioc_page1_inlinewith_perf_mode - Update IOC Page1 fields * according to performance mode. * @ioc : per adapter object * * Return: zero on success; otherwise return EAGAIN error code asking the * caller to retry. */ static int _base_update_ioc_page1_inlinewith_perf_mode(struct MPT3SAS_ADAPTER *ioc) { Mpi2IOCPage1_t ioc_pg1; Mpi2ConfigReply_t mpi_reply; int rc; rc = mpt3sas_config_get_ioc_pg1(ioc, &mpi_reply, &ioc->ioc_pg1_copy); if (rc) return rc; memcpy(&ioc_pg1, &ioc->ioc_pg1_copy, sizeof(Mpi2IOCPage1_t)); switch (perf_mode) { case MPT_PERF_MODE_DEFAULT: case MPT_PERF_MODE_BALANCED: if (ioc->high_iops_queues) { ioc_info(ioc, "Enable interrupt coalescing only for first\t" "%d reply queues\n", MPT3SAS_HIGH_IOPS_REPLY_QUEUES); /* * If 31st bit is zero then interrupt coalescing is * enabled for all reply descriptor post queues. * If 31st bit is set to one then user can * enable/disable interrupt coalescing on per reply * descriptor post queue group(8) basis. So to enable * interrupt coalescing only on first reply descriptor * post queue group 31st bit and zero th bit is enabled. */ ioc_pg1.ProductSpecific = cpu_to_le32(0x80000000 | ((1 << MPT3SAS_HIGH_IOPS_REPLY_QUEUES/8) - 1)); rc = mpt3sas_config_set_ioc_pg1(ioc, &mpi_reply, &ioc_pg1); if (rc) return rc; ioc_info(ioc, "performance mode: balanced\n"); return 0; } fallthrough; case MPT_PERF_MODE_LATENCY: /* * Enable interrupt coalescing on all reply queues * with timeout value 0xA */ ioc_pg1.CoalescingTimeout = cpu_to_le32(0xa); ioc_pg1.Flags |= cpu_to_le32(MPI2_IOCPAGE1_REPLY_COALESCING); ioc_pg1.ProductSpecific = 0; rc = mpt3sas_config_set_ioc_pg1(ioc, &mpi_reply, &ioc_pg1); if (rc) return rc; ioc_info(ioc, "performance mode: latency\n"); break; case MPT_PERF_MODE_IOPS: /* * Enable interrupt coalescing on all reply queues. */ ioc_info(ioc, "performance mode: iops with coalescing timeout: 0x%x\n", le32_to_cpu(ioc_pg1.CoalescingTimeout)); ioc_pg1.Flags |= cpu_to_le32(MPI2_IOCPAGE1_REPLY_COALESCING); ioc_pg1.ProductSpecific = 0; rc = mpt3sas_config_set_ioc_pg1(ioc, &mpi_reply, &ioc_pg1); if (rc) return rc; break; } return 0; } /** * _base_get_event_diag_triggers - get event diag trigger values from * persistent pages * @ioc : per adapter object * * Return: nothing. */ static int _base_get_event_diag_triggers(struct MPT3SAS_ADAPTER *ioc) { Mpi26DriverTriggerPage2_t trigger_pg2; struct SL_WH_EVENT_TRIGGER_T *event_tg; MPI26_DRIVER_MPI_EVENT_TIGGER_ENTRY *mpi_event_tg; Mpi2ConfigReply_t mpi_reply; int r = 0, i = 0; u16 count = 0; u16 ioc_status; r = mpt3sas_config_get_driver_trigger_pg2(ioc, &mpi_reply, &trigger_pg2); if (r) return r; ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK; if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { dinitprintk(ioc, ioc_err(ioc, "%s: Failed to get trigger pg2, ioc_status(0x%04x)\n", __func__, ioc_status)); return 0; } if (le16_to_cpu(trigger_pg2.NumMPIEventTrigger)) { count = le16_to_cpu(trigger_pg2.NumMPIEventTrigger); count = min_t(u16, NUM_VALID_ENTRIES, count); ioc->diag_trigger_event.ValidEntries = count; event_tg = &ioc->diag_trigger_event.EventTriggerEntry[0]; mpi_event_tg = &trigger_pg2.MPIEventTriggers[0]; for (i = 0; i < count; i++) { event_tg->EventValue = le16_to_cpu( mpi_event_tg->MPIEventCode); event_tg->LogEntryQualifier = le16_to_cpu( mpi_event_tg->MPIEventCodeSpecific); event_tg++; mpi_event_tg++; } } return 0; } /** * _base_get_scsi_diag_triggers - get scsi diag trigger values from * persistent pages * @ioc : per adapter object * * Return: 0 on success; otherwise return failure status. */ static int _base_get_scsi_diag_triggers(struct MPT3SAS_ADAPTER *ioc) { Mpi26DriverTriggerPage3_t trigger_pg3; struct SL_WH_SCSI_TRIGGER_T *scsi_tg; MPI26_DRIVER_SCSI_SENSE_TIGGER_ENTRY *mpi_scsi_tg; Mpi2ConfigReply_t mpi_reply; int r = 0, i = 0; u16 count = 0; u16 ioc_status; r = mpt3sas_config_get_driver_trigger_pg3(ioc, &mpi_reply, &trigger_pg3); if (r) return r; ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK; if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { dinitprintk(ioc, ioc_err(ioc, "%s: Failed to get trigger pg3, ioc_status(0x%04x)\n", __func__, ioc_status)); return 0; } if (le16_to_cpu(trigger_pg3.NumSCSISenseTrigger)) { count = le16_to_cpu(trigger_pg3.NumSCSISenseTrigger); count = min_t(u16, NUM_VALID_ENTRIES, count); ioc->diag_trigger_scsi.ValidEntries = count; scsi_tg = &ioc->diag_trigger_scsi.SCSITriggerEntry[0]; mpi_scsi_tg = &trigger_pg3.SCSISenseTriggers[0]; for (i = 0; i < count; i++) { scsi_tg->ASCQ = mpi_scsi_tg->ASCQ; scsi_tg->ASC = mpi_scsi_tg->ASC; scsi_tg->SenseKey = mpi_scsi_tg->SenseKey; scsi_tg++; mpi_scsi_tg++; } } return 0; } /** * _base_get_mpi_diag_triggers - get mpi diag trigger values from * persistent pages * @ioc : per adapter object * * Return: 0 on success; otherwise return failure status. */ static int _base_get_mpi_diag_triggers(struct MPT3SAS_ADAPTER *ioc) { Mpi26DriverTriggerPage4_t trigger_pg4; struct SL_WH_MPI_TRIGGER_T *status_tg; MPI26_DRIVER_IOCSTATUS_LOGINFO_TIGGER_ENTRY *mpi_status_tg; Mpi2ConfigReply_t mpi_reply; int r = 0, i = 0; u16 count = 0; u16 ioc_status; r = mpt3sas_config_get_driver_trigger_pg4(ioc, &mpi_reply, &trigger_pg4); if (r) return r; ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK; if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { dinitprintk(ioc, ioc_err(ioc, "%s: Failed to get trigger pg4, ioc_status(0x%04x)\n", __func__, ioc_status)); return 0; } if (le16_to_cpu(trigger_pg4.NumIOCStatusLogInfoTrigger)) { count = le16_to_cpu(trigger_pg4.NumIOCStatusLogInfoTrigger); count = min_t(u16, NUM_VALID_ENTRIES, count); ioc->diag_trigger_mpi.ValidEntries = count; status_tg = &ioc->diag_trigger_mpi.MPITriggerEntry[0]; mpi_status_tg = &trigger_pg4.IOCStatusLoginfoTriggers[0]; for (i = 0; i < count; i++) { status_tg->IOCStatus = le16_to_cpu( mpi_status_tg->IOCStatus); status_tg->IocLogInfo = le32_to_cpu( mpi_status_tg->LogInfo); status_tg++; mpi_status_tg++; } } return 0; } /** * _base_get_master_diag_triggers - get master diag trigger values from * persistent pages * @ioc : per adapter object * * Return: nothing. */ static int _base_get_master_diag_triggers(struct MPT3SAS_ADAPTER *ioc) { Mpi26DriverTriggerPage1_t trigger_pg1; Mpi2ConfigReply_t mpi_reply; int r; u16 ioc_status; r = mpt3sas_config_get_driver_trigger_pg1(ioc, &mpi_reply, &trigger_pg1); if (r) return r; ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK; if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { dinitprintk(ioc, ioc_err(ioc, "%s: Failed to get trigger pg1, ioc_status(0x%04x)\n", __func__, ioc_status)); return 0; } if (le16_to_cpu(trigger_pg1.NumMasterTrigger)) ioc->diag_trigger_master.MasterData |= le32_to_cpu( trigger_pg1.MasterTriggers[0].MasterTriggerFlags); return 0; } /** * _base_check_for_trigger_pages_support - checks whether HBA FW supports * driver trigger pages or not * @ioc : per adapter object * @trigger_flags : address where trigger page0's TriggerFlags value is copied * * Return: trigger flags mask if HBA FW supports driver trigger pages; * otherwise returns %-EFAULT if driver trigger pages are not supported by FW or * return EAGAIN if diag reset occurred due to FW fault and asking the * caller to retry the command. * */ static int _base_check_for_trigger_pages_support(struct MPT3SAS_ADAPTER *ioc, u32 *trigger_flags) { Mpi26DriverTriggerPage0_t trigger_pg0; int r = 0; Mpi2ConfigReply_t mpi_reply; u16 ioc_status; r = mpt3sas_config_get_driver_trigger_pg0(ioc, &mpi_reply, &trigger_pg0); if (r) return r; ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK; if (ioc_status != MPI2_IOCSTATUS_SUCCESS) return -EFAULT; *trigger_flags = le16_to_cpu(trigger_pg0.TriggerFlags); return 0; } /** * _base_get_diag_triggers - Retrieve diag trigger values from * persistent pages. * @ioc : per adapter object * * Return: zero on success; otherwise return EAGAIN error codes * asking the caller to retry. */ static int _base_get_diag_triggers(struct MPT3SAS_ADAPTER *ioc) { int trigger_flags; int r; /* * Default setting of master trigger. */ ioc->diag_trigger_master.MasterData = (MASTER_TRIGGER_FW_FAULT + MASTER_TRIGGER_ADAPTER_RESET); r = _base_check_for_trigger_pages_support(ioc, &trigger_flags); if (r) { if (r == -EAGAIN) return r; /* * Don't go for error handling when FW doesn't support * driver trigger pages. */ return 0; } ioc->supports_trigger_pages = 1; /* * Retrieve master diag trigger values from driver trigger pg1 * if master trigger bit enabled in TriggerFlags. */ if ((u16)trigger_flags & MPI26_DRIVER_TRIGGER0_FLAG_MASTER_TRIGGER_VALID) { r = _base_get_master_diag_triggers(ioc); if (r) return r; } /* * Retrieve event diag trigger values from driver trigger pg2 * if event trigger bit enabled in TriggerFlags. */ if ((u16)trigger_flags & MPI26_DRIVER_TRIGGER0_FLAG_MPI_EVENT_TRIGGER_VALID) { r = _base_get_event_diag_triggers(ioc); if (r) return r; } /* * Retrieve scsi diag trigger values from driver trigger pg3 * if scsi trigger bit enabled in TriggerFlags. */ if ((u16)trigger_flags & MPI26_DRIVER_TRIGGER0_FLAG_SCSI_SENSE_TRIGGER_VALID) { r = _base_get_scsi_diag_triggers(ioc); if (r) return r; } /* * Retrieve mpi error diag trigger values from driver trigger pg4 * if loginfo trigger bit enabled in TriggerFlags. */ if ((u16)trigger_flags & MPI26_DRIVER_TRIGGER0_FLAG_LOGINFO_TRIGGER_VALID) { r = _base_get_mpi_diag_triggers(ioc); if (r) return r; } return 0; } /** * _base_update_diag_trigger_pages - Update the driver trigger pages after * online FW update, in case updated FW supports driver * trigger pages. * @ioc : per adapter object * * Return: nothing. */ static void _base_update_diag_trigger_pages(struct MPT3SAS_ADAPTER *ioc) { if (ioc->diag_trigger_master.MasterData) mpt3sas_config_update_driver_trigger_pg1(ioc, &ioc->diag_trigger_master, 1); if (ioc->diag_trigger_event.ValidEntries) mpt3sas_config_update_driver_trigger_pg2(ioc, &ioc->diag_trigger_event, 1); if (ioc->diag_trigger_scsi.ValidEntries) mpt3sas_config_update_driver_trigger_pg3(ioc, &ioc->diag_trigger_scsi, 1); if (ioc->diag_trigger_mpi.ValidEntries) mpt3sas_config_update_driver_trigger_pg4(ioc, &ioc->diag_trigger_mpi, 1); } /** * _base_assign_fw_reported_qd - Get FW reported QD for SAS/SATA devices. * - On failure set default QD values. * @ioc : per adapter object * * Returns 0 for success, non-zero for failure. * */ static int _base_assign_fw_reported_qd(struct MPT3SAS_ADAPTER *ioc) { Mpi2ConfigReply_t mpi_reply; Mpi2SasIOUnitPage1_t *sas_iounit_pg1 = NULL; Mpi26PCIeIOUnitPage1_t pcie_iounit_pg1; int sz; int rc = 0; ioc->max_wideport_qd = MPT3SAS_SAS_QUEUE_DEPTH; ioc->max_narrowport_qd = MPT3SAS_SAS_QUEUE_DEPTH; ioc->max_sata_qd = MPT3SAS_SATA_QUEUE_DEPTH; ioc->max_nvme_qd = MPT3SAS_NVME_QUEUE_DEPTH; if (!ioc->is_gen35_ioc) goto out; /* sas iounit page 1 */ sz = offsetof(Mpi2SasIOUnitPage1_t, PhyData); sas_iounit_pg1 = kzalloc(sz, GFP_KERNEL); if (!sas_iounit_pg1) { pr_err("%s: failure at %s:%d/%s()!\n", ioc->name, __FILE__, __LINE__, __func__); return rc; } rc = mpt3sas_config_get_sas_iounit_pg1(ioc, &mpi_reply, sas_iounit_pg1, sz); if (rc) { pr_err("%s: failure at %s:%d/%s()!\n", ioc->name, __FILE__, __LINE__, __func__); goto out; } ioc->max_wideport_qd = (le16_to_cpu(sas_iounit_pg1->SASWideMaxQueueDepth)) ? le16_to_cpu(sas_iounit_pg1->SASWideMaxQueueDepth) : MPT3SAS_SAS_QUEUE_DEPTH; ioc->max_narrowport_qd = (le16_to_cpu(sas_iounit_pg1->SASNarrowMaxQueueDepth)) ? le16_to_cpu(sas_iounit_pg1->SASNarrowMaxQueueDepth) : MPT3SAS_SAS_QUEUE_DEPTH; ioc->max_sata_qd = (sas_iounit_pg1->SATAMaxQDepth) ? sas_iounit_pg1->SATAMaxQDepth : MPT3SAS_SATA_QUEUE_DEPTH; /* pcie iounit page 1 */ rc = mpt3sas_config_get_pcie_iounit_pg1(ioc, &mpi_reply, &pcie_iounit_pg1, sizeof(Mpi26PCIeIOUnitPage1_t)); if (rc) { pr_err("%s: failure at %s:%d/%s()!\n", ioc->name, __FILE__, __LINE__, __func__); goto out; } ioc->max_nvme_qd = (le16_to_cpu(pcie_iounit_pg1.NVMeMaxQueueDepth)) ? (le16_to_cpu(pcie_iounit_pg1.NVMeMaxQueueDepth)) : MPT3SAS_NVME_QUEUE_DEPTH; out: dinitprintk(ioc, pr_err( "MaxWidePortQD: 0x%x MaxNarrowPortQD: 0x%x MaxSataQD: 0x%x MaxNvmeQD: 0x%x\n", ioc->max_wideport_qd, ioc->max_narrowport_qd, ioc->max_sata_qd, ioc->max_nvme_qd)); kfree(sas_iounit_pg1); return rc; } /** * _base_static_config_pages - static start of day config pages * @ioc: per adapter object */ static int _base_static_config_pages(struct MPT3SAS_ADAPTER *ioc) { Mpi2ConfigReply_t mpi_reply; u32 iounit_pg1_flags; int tg_flags = 0; int rc; ioc->nvme_abort_timeout = 30; rc = mpt3sas_config_get_manufacturing_pg0(ioc, &mpi_reply, &ioc->manu_pg0); if (rc) return rc; if (ioc->ir_firmware) { rc = mpt3sas_config_get_manufacturing_pg10(ioc, &mpi_reply, &ioc->manu_pg10); if (rc) return rc; } /* * Ensure correct T10 PI operation if vendor left EEDPTagMode * flag unset in NVDATA. */ rc = mpt3sas_config_get_manufacturing_pg11(ioc, &mpi_reply, &ioc->manu_pg11); if (rc) return rc; if (!ioc->is_gen35_ioc && ioc->manu_pg11.EEDPTagMode == 0) { pr_err("%s: overriding NVDATA EEDPTagMode setting\n", ioc->name); ioc->manu_pg11.EEDPTagMode &= ~0x3; ioc->manu_pg11.EEDPTagMode |= 0x1; mpt3sas_config_set_manufacturing_pg11(ioc, &mpi_reply, &ioc->manu_pg11); } if (ioc->manu_pg11.AddlFlags2 & NVME_TASK_MNGT_CUSTOM_MASK) ioc->tm_custom_handling = 1; else { ioc->tm_custom_handling = 0; if (ioc->manu_pg11.NVMeAbortTO < NVME_TASK_ABORT_MIN_TIMEOUT) ioc->nvme_abort_timeout = NVME_TASK_ABORT_MIN_TIMEOUT; else if (ioc->manu_pg11.NVMeAbortTO > NVME_TASK_ABORT_MAX_TIMEOUT) ioc->nvme_abort_timeout = NVME_TASK_ABORT_MAX_TIMEOUT; else ioc->nvme_abort_timeout = ioc->manu_pg11.NVMeAbortTO; } ioc->time_sync_interval = ioc->manu_pg11.TimeSyncInterval & MPT3SAS_TIMESYNC_MASK; if (ioc->time_sync_interval) { if (ioc->manu_pg11.TimeSyncInterval & MPT3SAS_TIMESYNC_UNIT_MASK) ioc->time_sync_interval = ioc->time_sync_interval * SECONDS_PER_HOUR; else ioc->time_sync_interval = ioc->time_sync_interval * SECONDS_PER_MIN; dinitprintk(ioc, ioc_info(ioc, "Driver-FW TimeSync interval is %d seconds. ManuPg11 TimeSync Unit is in %s\n", ioc->time_sync_interval, (ioc->manu_pg11.TimeSyncInterval & MPT3SAS_TIMESYNC_UNIT_MASK) ? "Hour" : "Minute")); } else { if (ioc->is_gen35_ioc) ioc_warn(ioc, "TimeSync Interval in Manuf page-11 is not enabled. Periodic Time-Sync will be disabled\n"); } rc = _base_assign_fw_reported_qd(ioc); if (rc) return rc; rc = mpt3sas_config_get_bios_pg2(ioc, &mpi_reply, &ioc->bios_pg2); if (rc) return rc; rc = mpt3sas_config_get_bios_pg3(ioc, &mpi_reply, &ioc->bios_pg3); if (rc) return rc; rc = mpt3sas_config_get_ioc_pg8(ioc, &mpi_reply, &ioc->ioc_pg8); if (rc) return rc; rc = mpt3sas_config_get_iounit_pg0(ioc, &mpi_reply, &ioc->iounit_pg0); if (rc) return rc; rc = mpt3sas_config_get_iounit_pg1(ioc, &mpi_reply, &ioc->iounit_pg1); if (rc) return rc; rc = mpt3sas_config_get_iounit_pg8(ioc, &mpi_reply, &ioc->iounit_pg8); if (rc) return rc; _base_display_ioc_capabilities(ioc); /* * Enable task_set_full handling in iounit_pg1 when the * facts capabilities indicate that its supported. */ iounit_pg1_flags = le32_to_cpu(ioc->iounit_pg1.Flags); if ((ioc->facts.IOCCapabilities & MPI2_IOCFACTS_CAPABILITY_TASK_SET_FULL_HANDLING)) iounit_pg1_flags &= ~MPI2_IOUNITPAGE1_DISABLE_TASK_SET_FULL_HANDLING; else iounit_pg1_flags |= MPI2_IOUNITPAGE1_DISABLE_TASK_SET_FULL_HANDLING; ioc->iounit_pg1.Flags = cpu_to_le32(iounit_pg1_flags); rc = mpt3sas_config_set_iounit_pg1(ioc, &mpi_reply, &ioc->iounit_pg1); if (rc) return rc; if (ioc->iounit_pg8.NumSensors) ioc->temp_sensors_count = ioc->iounit_pg8.NumSensors; if (ioc->is_aero_ioc) { rc = _base_update_ioc_page1_inlinewith_perf_mode(ioc); if (rc) return rc; } if (ioc->is_gen35_ioc) { if (ioc->is_driver_loading) { rc = _base_get_diag_triggers(ioc); if (rc) return rc; } else { /* * In case of online HBA FW update operation, * check whether updated FW supports the driver trigger * pages or not. * - If previous FW has not supported driver trigger * pages and newer FW supports them then update these * pages with current diag trigger values. * - If previous FW has supported driver trigger pages * and new FW doesn't support them then disable * support_trigger_pages flag. */ _base_check_for_trigger_pages_support(ioc, &tg_flags); if (!ioc->supports_trigger_pages && tg_flags != -EFAULT) _base_update_diag_trigger_pages(ioc); else if (ioc->supports_trigger_pages && tg_flags == -EFAULT) ioc->supports_trigger_pages = 0; } } return 0; } /** * mpt3sas_free_enclosure_list - release memory * @ioc: per adapter object * * Free memory allocated during enclosure add. */ void mpt3sas_free_enclosure_list(struct MPT3SAS_ADAPTER *ioc) { struct _enclosure_node *enclosure_dev, *enclosure_dev_next; /* Free enclosure list */ list_for_each_entry_safe(enclosure_dev, enclosure_dev_next, &ioc->enclosure_list, list) { list_del(&enclosure_dev->list); kfree(enclosure_dev); } } /** * _base_release_memory_pools - release memory * @ioc: per adapter object * * Free memory allocated from _base_allocate_memory_pools. */ static void _base_release_memory_pools(struct MPT3SAS_ADAPTER *ioc) { int i = 0; int j = 0; int dma_alloc_count = 0; struct chain_tracker *ct; int count = ioc->rdpq_array_enable ? ioc->reply_queue_count : 1; dexitprintk(ioc, ioc_info(ioc, "%s\n", __func__)); if (ioc->request) { dma_free_coherent(&ioc->pdev->dev, ioc->request_dma_sz, ioc->request, ioc->request_dma); dexitprintk(ioc, ioc_info(ioc, "request_pool(0x%p): free\n", ioc->request)); ioc->request = NULL; } if (ioc->sense) { dma_pool_free(ioc->sense_dma_pool, ioc->sense, ioc->sense_dma); dma_pool_destroy(ioc->sense_dma_pool); dexitprintk(ioc, ioc_info(ioc, "sense_pool(0x%p): free\n", ioc->sense)); ioc->sense = NULL; } if (ioc->reply) { dma_pool_free(ioc->reply_dma_pool, ioc->reply, ioc->reply_dma); dma_pool_destroy(ioc->reply_dma_pool); dexitprintk(ioc, ioc_info(ioc, "reply_pool(0x%p): free\n", ioc->reply)); ioc->reply = NULL; } if (ioc->reply_free) { dma_pool_free(ioc->reply_free_dma_pool, ioc->reply_free, ioc->reply_free_dma); dma_pool_destroy(ioc->reply_free_dma_pool); dexitprintk(ioc, ioc_info(ioc, "reply_free_pool(0x%p): free\n", ioc->reply_free)); ioc->reply_free = NULL; } if (ioc->reply_post) { dma_alloc_count = DIV_ROUND_UP(count, RDPQ_MAX_INDEX_IN_ONE_CHUNK); for (i = 0; i < count; i++) { if (i % RDPQ_MAX_INDEX_IN_ONE_CHUNK == 0 && dma_alloc_count) { if (ioc->reply_post[i].reply_post_free) { dma_pool_free( ioc->reply_post_free_dma_pool, ioc->reply_post[i].reply_post_free, ioc->reply_post[i].reply_post_free_dma); dexitprintk(ioc, ioc_info(ioc, "reply_post_free_pool(0x%p): free\n", ioc->reply_post[i].reply_post_free)); ioc->reply_post[i].reply_post_free = NULL; } --dma_alloc_count; } } dma_pool_destroy(ioc->reply_post_free_dma_pool); if (ioc->reply_post_free_array && ioc->rdpq_array_enable) { dma_pool_free(ioc->reply_post_free_array_dma_pool, ioc->reply_post_free_array, ioc->reply_post_free_array_dma); ioc->reply_post_free_array = NULL; } dma_pool_destroy(ioc->reply_post_free_array_dma_pool); kfree(ioc->reply_post); } if (ioc->pcie_sgl_dma_pool) { for (i = 0; i < ioc->scsiio_depth; i++) { dma_pool_free(ioc->pcie_sgl_dma_pool, ioc->pcie_sg_lookup[i].pcie_sgl, ioc->pcie_sg_lookup[i].pcie_sgl_dma); ioc->pcie_sg_lookup[i].pcie_sgl = NULL; } dma_pool_destroy(ioc->pcie_sgl_dma_pool); } if (ioc->config_page) { dexitprintk(ioc, ioc_info(ioc, "config_page(0x%p): free\n", ioc->config_page)); dma_free_coherent(&ioc->pdev->dev, ioc->config_page_sz, ioc->config_page, ioc->config_page_dma); } kfree(ioc->hpr_lookup); ioc->hpr_lookup = NULL; kfree(ioc->internal_lookup); ioc->internal_lookup = NULL; if (ioc->chain_lookup) { for (i = 0; i < ioc->scsiio_depth; i++) { for (j = ioc->chains_per_prp_buffer; j < ioc->chains_needed_per_io; j++) { ct = &ioc->chain_lookup[i].chains_per_smid[j]; if (ct && ct->chain_buffer) dma_pool_free(ioc->chain_dma_pool, ct->chain_buffer, ct->chain_buffer_dma); } kfree(ioc->chain_lookup[i].chains_per_smid); } dma_pool_destroy(ioc->chain_dma_pool); kfree(ioc->chain_lookup); ioc->chain_lookup = NULL; } kfree(ioc->io_queue_num); ioc->io_queue_num = NULL; } /** * mpt3sas_check_same_4gb_region - checks whether all reply queues in a set are * having same upper 32bits in their base memory address. * @reply_pool_start_address: Base address of a reply queue set * @pool_sz: Size of single Reply Descriptor Post Queues pool size * * Return: 1 if reply queues in a set have a same upper 32bits in their base * memory address, else 0. */ static int mpt3sas_check_same_4gb_region(long reply_pool_start_address, u32 pool_sz) { long reply_pool_end_address; reply_pool_end_address = reply_pool_start_address + pool_sz; if (upper_32_bits(reply_pool_start_address) == upper_32_bits(reply_pool_end_address)) return 1; else return 0; } /** * _base_reduce_hba_queue_depth- Retry with reduced queue depth * @ioc: Adapter object * * Return: 0 for success, non-zero for failure. **/ static inline int _base_reduce_hba_queue_depth(struct MPT3SAS_ADAPTER *ioc) { int reduce_sz = 64; if ((ioc->hba_queue_depth - reduce_sz) > (ioc->internal_depth + INTERNAL_SCSIIO_CMDS_COUNT)) { ioc->hba_queue_depth -= reduce_sz; return 0; } else return -ENOMEM; } /** * _base_allocate_pcie_sgl_pool - Allocating DMA'able memory * for pcie sgl pools. * @ioc: Adapter object * @sz: DMA Pool size * * Return: 0 for success, non-zero for failure. */ static int _base_allocate_pcie_sgl_pool(struct MPT3SAS_ADAPTER *ioc, u32 sz) { int i = 0, j = 0; struct chain_tracker *ct; ioc->pcie_sgl_dma_pool = dma_pool_create("PCIe SGL pool", &ioc->pdev->dev, sz, ioc->page_size, 0); if (!ioc->pcie_sgl_dma_pool) { ioc_err(ioc, "PCIe SGL pool: dma_pool_create failed\n"); return -ENOMEM; } ioc->chains_per_prp_buffer = sz/ioc->chain_segment_sz; ioc->chains_per_prp_buffer = min(ioc->chains_per_prp_buffer, ioc->chains_needed_per_io); for (i = 0; i < ioc->scsiio_depth; i++) { ioc->pcie_sg_lookup[i].pcie_sgl = dma_pool_alloc(ioc->pcie_sgl_dma_pool, GFP_KERNEL, &ioc->pcie_sg_lookup[i].pcie_sgl_dma); if (!ioc->pcie_sg_lookup[i].pcie_sgl) { ioc_err(ioc, "PCIe SGL pool: dma_pool_alloc failed\n"); return -EAGAIN; } if (!mpt3sas_check_same_4gb_region( (long)ioc->pcie_sg_lookup[i].pcie_sgl, sz)) { ioc_err(ioc, "PCIE SGLs are not in same 4G !! pcie sgl (0x%p) dma = (0x%llx)\n", ioc->pcie_sg_lookup[i].pcie_sgl, (unsigned long long) ioc->pcie_sg_lookup[i].pcie_sgl_dma); ioc->use_32bit_dma = true; return -EAGAIN; } for (j = 0; j < ioc->chains_per_prp_buffer; j++) { ct = &ioc->chain_lookup[i].chains_per_smid[j]; ct->chain_buffer = ioc->pcie_sg_lookup[i].pcie_sgl + (j * ioc->chain_segment_sz); ct->chain_buffer_dma = ioc->pcie_sg_lookup[i].pcie_sgl_dma + (j * ioc->chain_segment_sz); } } dinitprintk(ioc, ioc_info(ioc, "PCIe sgl pool depth(%d), element_size(%d), pool_size(%d kB)\n", ioc->scsiio_depth, sz, (sz * ioc->scsiio_depth)/1024)); dinitprintk(ioc, ioc_info(ioc, "Number of chains can fit in a PRP page(%d)\n", ioc->chains_per_prp_buffer)); return 0; } /** * _base_allocate_chain_dma_pool - Allocating DMA'able memory * for chain dma pool. * @ioc: Adapter object * @sz: DMA Pool size * * Return: 0 for success, non-zero for failure. */ static int _base_allocate_chain_dma_pool(struct MPT3SAS_ADAPTER *ioc, u32 sz) { int i = 0, j = 0; struct chain_tracker *ctr; ioc->chain_dma_pool = dma_pool_create("chain pool", &ioc->pdev->dev, ioc->chain_segment_sz, 16, 0); if (!ioc->chain_dma_pool) return -ENOMEM; for (i = 0; i < ioc->scsiio_depth; i++) { for (j = ioc->chains_per_prp_buffer; j < ioc->chains_needed_per_io; j++) { ctr = &ioc->chain_lookup[i].chains_per_smid[j]; ctr->chain_buffer = dma_pool_alloc(ioc->chain_dma_pool, GFP_KERNEL, &ctr->chain_buffer_dma); if (!ctr->chain_buffer) return -EAGAIN; if (!mpt3sas_check_same_4gb_region((long) ctr->chain_buffer, ioc->chain_segment_sz)) { ioc_err(ioc, "Chain buffers are not in same 4G !!! Chain buff (0x%p) dma = (0x%llx)\n", ctr->chain_buffer, (unsigned long long)ctr->chain_buffer_dma); ioc->use_32bit_dma = true; return -EAGAIN; } } } dinitprintk(ioc, ioc_info(ioc, "chain_lookup depth (%d), frame_size(%d), pool_size(%d kB)\n", ioc->scsiio_depth, ioc->chain_segment_sz, ((ioc->scsiio_depth * (ioc->chains_needed_per_io - ioc->chains_per_prp_buffer) * ioc->chain_segment_sz))/1024)); return 0; } /** * _base_allocate_sense_dma_pool - Allocating DMA'able memory * for sense dma pool. * @ioc: Adapter object * @sz: DMA Pool size * Return: 0 for success, non-zero for failure. */ static int _base_allocate_sense_dma_pool(struct MPT3SAS_ADAPTER *ioc, u32 sz) { ioc->sense_dma_pool = dma_pool_create("sense pool", &ioc->pdev->dev, sz, 4, 0); if (!ioc->sense_dma_pool) return -ENOMEM; ioc->sense = dma_pool_alloc(ioc->sense_dma_pool, GFP_KERNEL, &ioc->sense_dma); if (!ioc->sense) return -EAGAIN; if (!mpt3sas_check_same_4gb_region((long)ioc->sense, sz)) { dinitprintk(ioc, pr_err( "Bad Sense Pool! sense (0x%p) sense_dma = (0x%llx)\n", ioc->sense, (unsigned long long) ioc->sense_dma)); ioc->use_32bit_dma = true; return -EAGAIN; } ioc_info(ioc, "sense pool(0x%p) - dma(0x%llx): depth(%d), element_size(%d), pool_size (%d kB)\n", ioc->sense, (unsigned long long)ioc->sense_dma, ioc->scsiio_depth, SCSI_SENSE_BUFFERSIZE, sz/1024); return 0; } /** * _base_allocate_reply_pool - Allocating DMA'able memory * for reply pool. * @ioc: Adapter object * @sz: DMA Pool size * Return: 0 for success, non-zero for failure. */ static int _base_allocate_reply_pool(struct MPT3SAS_ADAPTER *ioc, u32 sz) { /* reply pool, 4 byte align */ ioc->reply_dma_pool = dma_pool_create("reply pool", &ioc->pdev->dev, sz, 4, 0); if (!ioc->reply_dma_pool) return -ENOMEM; ioc->reply = dma_pool_alloc(ioc->reply_dma_pool, GFP_KERNEL, &ioc->reply_dma); if (!ioc->reply) return -EAGAIN; if (!mpt3sas_check_same_4gb_region((long)ioc->reply_free, sz)) { dinitprintk(ioc, pr_err( "Bad Reply Pool! Reply (0x%p) Reply dma = (0x%llx)\n", ioc->reply, (unsigned long long) ioc->reply_dma)); ioc->use_32bit_dma = true; return -EAGAIN; } ioc->reply_dma_min_address = (u32)(ioc->reply_dma); ioc->reply_dma_max_address = (u32)(ioc->reply_dma) + sz; ioc_info(ioc, "reply pool(0x%p) - dma(0x%llx): depth(%d), frame_size(%d), pool_size(%d kB)\n", ioc->reply, (unsigned long long)ioc->reply_dma, ioc->reply_free_queue_depth, ioc->reply_sz, sz/1024); return 0; } /** * _base_allocate_reply_free_dma_pool - Allocating DMA'able memory * for reply free dma pool. * @ioc: Adapter object * @sz: DMA Pool size * Return: 0 for success, non-zero for failure. */ static int _base_allocate_reply_free_dma_pool(struct MPT3SAS_ADAPTER *ioc, u32 sz) { /* reply free queue, 16 byte align */ ioc->reply_free_dma_pool = dma_pool_create( "reply_free pool", &ioc->pdev->dev, sz, 16, 0); if (!ioc->reply_free_dma_pool) return -ENOMEM; ioc->reply_free = dma_pool_alloc(ioc->reply_free_dma_pool, GFP_KERNEL, &ioc->reply_free_dma); if (!ioc->reply_free) return -EAGAIN; if (!mpt3sas_check_same_4gb_region((long)ioc->reply_free, sz)) { dinitprintk(ioc, pr_err("Bad Reply Free Pool! Reply Free (0x%p) Reply Free dma = (0x%llx)\n", ioc->reply_free, (unsigned long long) ioc->reply_free_dma)); ioc->use_32bit_dma = true; return -EAGAIN; } memset(ioc->reply_free, 0, sz); dinitprintk(ioc, ioc_info(ioc, "reply_free pool(0x%p): depth(%d), element_size(%d), pool_size(%d kB)\n", ioc->reply_free, ioc->reply_free_queue_depth, 4, sz/1024)); dinitprintk(ioc, ioc_info(ioc, "reply_free_dma (0x%llx)\n", (unsigned long long)ioc->reply_free_dma)); return 0; } /** * _base_allocate_reply_post_free_array - Allocating DMA'able memory * for reply post free array. * @ioc: Adapter object * @reply_post_free_array_sz: DMA Pool size * Return: 0 for success, non-zero for failure. */ static int _base_allocate_reply_post_free_array(struct MPT3SAS_ADAPTER *ioc, u32 reply_post_free_array_sz) { ioc->reply_post_free_array_dma_pool = dma_pool_create("reply_post_free_array pool", &ioc->pdev->dev, reply_post_free_array_sz, 16, 0); if (!ioc->reply_post_free_array_dma_pool) return -ENOMEM; ioc->reply_post_free_array = dma_pool_alloc(ioc->reply_post_free_array_dma_pool, GFP_KERNEL, &ioc->reply_post_free_array_dma); if (!ioc->reply_post_free_array) return -EAGAIN; if (!mpt3sas_check_same_4gb_region((long)ioc->reply_post_free_array, reply_post_free_array_sz)) { dinitprintk(ioc, pr_err( "Bad Reply Free Pool! Reply Free (0x%p) Reply Free dma = (0x%llx)\n", ioc->reply_free, (unsigned long long) ioc->reply_free_dma)); ioc->use_32bit_dma = true; return -EAGAIN; } return 0; } /** * base_alloc_rdpq_dma_pool - Allocating DMA'able memory * for reply queues. * @ioc: per adapter object * @sz: DMA Pool size * Return: 0 for success, non-zero for failure. */ static int base_alloc_rdpq_dma_pool(struct MPT3SAS_ADAPTER *ioc, int sz) { int i = 0; u32 dma_alloc_count = 0; int reply_post_free_sz = ioc->reply_post_queue_depth * sizeof(Mpi2DefaultReplyDescriptor_t); int count = ioc->rdpq_array_enable ? ioc->reply_queue_count : 1; ioc->reply_post = kcalloc(count, sizeof(struct reply_post_struct), GFP_KERNEL); if (!ioc->reply_post) return -ENOMEM; /* * For INVADER_SERIES each set of 8 reply queues(0-7, 8-15, ..) and * VENTURA_SERIES each set of 16 reply queues(0-15, 16-31, ..) should * be within 4GB boundary i.e reply queues in a set must have same * upper 32-bits in their memory address. so here driver is allocating * the DMA'able memory for reply queues according. * Driver uses limitation of * VENTURA_SERIES to manage INVADER_SERIES as well. */ dma_alloc_count = DIV_ROUND_UP(count, RDPQ_MAX_INDEX_IN_ONE_CHUNK); ioc->reply_post_free_dma_pool = dma_pool_create("reply_post_free pool", &ioc->pdev->dev, sz, 16, 0); if (!ioc->reply_post_free_dma_pool) return -ENOMEM; for (i = 0; i < count; i++) { if ((i % RDPQ_MAX_INDEX_IN_ONE_CHUNK == 0) && dma_alloc_count) { ioc->reply_post[i].reply_post_free = dma_pool_zalloc(ioc->reply_post_free_dma_pool, GFP_KERNEL, &ioc->reply_post[i].reply_post_free_dma); if (!ioc->reply_post[i].reply_post_free) return -ENOMEM; /* * Each set of RDPQ pool must satisfy 4gb boundary * restriction. * 1) Check if allocated resources for RDPQ pool are in * the same 4GB range. * 2) If #1 is true, continue with 64 bit DMA. * 3) If #1 is false, return 1. which means free all the * resources and set DMA mask to 32 and allocate. */ if (!mpt3sas_check_same_4gb_region( (long)ioc->reply_post[i].reply_post_free, sz)) { dinitprintk(ioc, ioc_err(ioc, "bad Replypost free pool(0x%p)" "reply_post_free_dma = (0x%llx)\n", ioc->reply_post[i].reply_post_free, (unsigned long long) ioc->reply_post[i].reply_post_free_dma)); return -EAGAIN; } dma_alloc_count--; } else { ioc->reply_post[i].reply_post_free = (Mpi2ReplyDescriptorsUnion_t *) ((long)ioc->reply_post[i-1].reply_post_free + reply_post_free_sz); ioc->reply_post[i].reply_post_free_dma = (dma_addr_t) (ioc->reply_post[i-1].reply_post_free_dma + reply_post_free_sz); } } return 0; } /** * _base_allocate_memory_pools - allocate start of day memory pools * @ioc: per adapter object * * Return: 0 success, anything else error. */ static int _base_allocate_memory_pools(struct MPT3SAS_ADAPTER *ioc) { struct mpt3sas_facts *facts; u16 max_sge_elements; u16 chains_needed_per_io; u32 sz, total_sz, reply_post_free_sz, reply_post_free_array_sz; u32 retry_sz; u32 rdpq_sz = 0, sense_sz = 0; u16 max_request_credit, nvme_blocks_needed; unsigned short sg_tablesize; u16 sge_size; int i; int ret = 0, rc = 0; dinitprintk(ioc, ioc_info(ioc, "%s\n", __func__)); retry_sz = 0; facts = &ioc->facts; /* command line tunables for max sgl entries */ if (max_sgl_entries != -1) sg_tablesize = max_sgl_entries; else { if (ioc->hba_mpi_version_belonged == MPI2_VERSION) sg_tablesize = MPT2SAS_SG_DEPTH; else sg_tablesize = MPT3SAS_SG_DEPTH; } /* max sgl entries <= MPT_KDUMP_MIN_PHYS_SEGMENTS in KDUMP mode */ if (reset_devices) sg_tablesize = min_t(unsigned short, sg_tablesize, MPT_KDUMP_MIN_PHYS_SEGMENTS); if (ioc->is_mcpu_endpoint) ioc->shost->sg_tablesize = MPT_MIN_PHYS_SEGMENTS; else { if (sg_tablesize < MPT_MIN_PHYS_SEGMENTS) sg_tablesize = MPT_MIN_PHYS_SEGMENTS; else if (sg_tablesize > MPT_MAX_PHYS_SEGMENTS) { sg_tablesize = min_t(unsigned short, sg_tablesize, SG_MAX_SEGMENTS); ioc_warn(ioc, "sg_tablesize(%u) is bigger than kernel defined SG_CHUNK_SIZE(%u)\n", sg_tablesize, MPT_MAX_PHYS_SEGMENTS); } ioc->shost->sg_tablesize = sg_tablesize; } ioc->internal_depth = min_t(int, (facts->HighPriorityCredit + (5)), (facts->RequestCredit / 4)); if (ioc->internal_depth < INTERNAL_CMDS_COUNT) { if (facts->RequestCredit <= (INTERNAL_CMDS_COUNT + INTERNAL_SCSIIO_CMDS_COUNT)) { ioc_err(ioc, "IOC doesn't have enough Request Credits, it has just %d number of credits\n", facts->RequestCredit); return -ENOMEM; } ioc->internal_depth = 10; } ioc->hi_priority_depth = ioc->internal_depth - (5); /* command line tunables for max controller queue depth */ if (max_queue_depth != -1 && max_queue_depth != 0) { max_request_credit = min_t(u16, max_queue_depth + ioc->internal_depth, facts->RequestCredit); if (max_request_credit > MAX_HBA_QUEUE_DEPTH) max_request_credit = MAX_HBA_QUEUE_DEPTH; } else if (reset_devices) max_request_credit = min_t(u16, facts->RequestCredit, (MPT3SAS_KDUMP_SCSI_IO_DEPTH + ioc->internal_depth)); else max_request_credit = min_t(u16, facts->RequestCredit, MAX_HBA_QUEUE_DEPTH); /* Firmware maintains additional facts->HighPriorityCredit number of * credits for HiPriprity Request messages, so hba queue depth will be * sum of max_request_credit and high priority queue depth. */ ioc->hba_queue_depth = max_request_credit + ioc->hi_priority_depth; /* request frame size */ ioc->request_sz = facts->IOCRequestFrameSize * 4; /* reply frame size */ ioc->reply_sz = facts->ReplyFrameSize * 4; /* chain segment size */ if (ioc->hba_mpi_version_belonged != MPI2_VERSION) { if (facts->IOCMaxChainSegmentSize) ioc->chain_segment_sz = facts->IOCMaxChainSegmentSize * MAX_CHAIN_ELEMT_SZ; else /* set to 128 bytes size if IOCMaxChainSegmentSize is zero */ ioc->chain_segment_sz = DEFAULT_NUM_FWCHAIN_ELEMTS * MAX_CHAIN_ELEMT_SZ; } else ioc->chain_segment_sz = ioc->request_sz; /* calculate the max scatter element size */ sge_size = max_t(u16, ioc->sge_size, ioc->sge_size_ieee); retry_allocation: total_sz = 0; /* calculate number of sg elements left over in the 1st frame */ max_sge_elements = ioc->request_sz - ((sizeof(Mpi2SCSIIORequest_t) - sizeof(Mpi2SGEIOUnion_t)) + sge_size); ioc->max_sges_in_main_message = max_sge_elements/sge_size; /* now do the same for a chain buffer */ max_sge_elements = ioc->chain_segment_sz - sge_size; ioc->max_sges_in_chain_message = max_sge_elements/sge_size; /* * MPT3SAS_SG_DEPTH = CONFIG_FUSION_MAX_SGE */ chains_needed_per_io = ((ioc->shost->sg_tablesize - ioc->max_sges_in_main_message)/ioc->max_sges_in_chain_message) + 1; if (chains_needed_per_io > facts->MaxChainDepth) { chains_needed_per_io = facts->MaxChainDepth; ioc->shost->sg_tablesize = min_t(u16, ioc->max_sges_in_main_message + (ioc->max_sges_in_chain_message * chains_needed_per_io), ioc->shost->sg_tablesize); } ioc->chains_needed_per_io = chains_needed_per_io; /* reply free queue sizing - taking into account for 64 FW events */ ioc->reply_free_queue_depth = ioc->hba_queue_depth + 64; /* mCPU manage single counters for simplicity */ if (ioc->is_mcpu_endpoint) ioc->reply_post_queue_depth = ioc->reply_free_queue_depth; else { /* calculate reply descriptor post queue depth */ ioc->reply_post_queue_depth = ioc->hba_queue_depth + ioc->reply_free_queue_depth + 1; /* align the reply post queue on the next 16 count boundary */ if (ioc->reply_post_queue_depth % 16) ioc->reply_post_queue_depth += 16 - (ioc->reply_post_queue_depth % 16); } if (ioc->reply_post_queue_depth > facts->MaxReplyDescriptorPostQueueDepth) { ioc->reply_post_queue_depth = facts->MaxReplyDescriptorPostQueueDepth - (facts->MaxReplyDescriptorPostQueueDepth % 16); ioc->hba_queue_depth = ((ioc->reply_post_queue_depth - 64) / 2) - 1; ioc->reply_free_queue_depth = ioc->hba_queue_depth + 64; } ioc_info(ioc, "scatter gather: sge_in_main_msg(%d), sge_per_chain(%d), " "sge_per_io(%d), chains_per_io(%d)\n", ioc->max_sges_in_main_message, ioc->max_sges_in_chain_message, ioc->shost->sg_tablesize, ioc->chains_needed_per_io); /* reply post queue, 16 byte align */ reply_post_free_sz = ioc->reply_post_queue_depth * sizeof(Mpi2DefaultReplyDescriptor_t); rdpq_sz = reply_post_free_sz * RDPQ_MAX_INDEX_IN_ONE_CHUNK; if ((_base_is_controller_msix_enabled(ioc) && !ioc->rdpq_array_enable) || (ioc->reply_queue_count < RDPQ_MAX_INDEX_IN_ONE_CHUNK)) rdpq_sz = reply_post_free_sz * ioc->reply_queue_count; ret = base_alloc_rdpq_dma_pool(ioc, rdpq_sz); if (ret == -EAGAIN) { /* * Free allocated bad RDPQ memory pools. * Change dma coherent mask to 32 bit and reallocate RDPQ */ _base_release_memory_pools(ioc); ioc->use_32bit_dma = true; if (_base_config_dma_addressing(ioc, ioc->pdev) != 0) { ioc_err(ioc, "32 DMA mask failed %s\n", pci_name(ioc->pdev)); return -ENODEV; } if (base_alloc_rdpq_dma_pool(ioc, rdpq_sz)) return -ENOMEM; } else if (ret == -ENOMEM) return -ENOMEM; total_sz = rdpq_sz * (!ioc->rdpq_array_enable ? 1 : DIV_ROUND_UP(ioc->reply_queue_count, RDPQ_MAX_INDEX_IN_ONE_CHUNK)); ioc->scsiio_depth = ioc->hba_queue_depth - ioc->hi_priority_depth - ioc->internal_depth; /* set the scsi host can_queue depth * with some internal commands that could be outstanding */ ioc->shost->can_queue = ioc->scsiio_depth - INTERNAL_SCSIIO_CMDS_COUNT; dinitprintk(ioc, ioc_info(ioc, "scsi host: can_queue depth (%d)\n", ioc->shost->can_queue)); /* contiguous pool for request and chains, 16 byte align, one extra " * "frame for smid=0 */ ioc->chain_depth = ioc->chains_needed_per_io * ioc->scsiio_depth; sz = ((ioc->scsiio_depth + 1) * ioc->request_sz); /* hi-priority queue */ sz += (ioc->hi_priority_depth * ioc->request_sz); /* internal queue */ sz += (ioc->internal_depth * ioc->request_sz); ioc->request_dma_sz = sz; ioc->request = dma_alloc_coherent(&ioc->pdev->dev, sz, &ioc->request_dma, GFP_KERNEL); if (!ioc->request) { ioc_err(ioc, "request pool: dma_alloc_coherent failed: hba_depth(%d), chains_per_io(%d), frame_sz(%d), total(%d kB)\n", ioc->hba_queue_depth, ioc->chains_needed_per_io, ioc->request_sz, sz / 1024); if (ioc->scsiio_depth < MPT3SAS_SAS_QUEUE_DEPTH) goto out; retry_sz = 64; ioc->hba_queue_depth -= retry_sz; _base_release_memory_pools(ioc); goto retry_allocation; } if (retry_sz) ioc_err(ioc, "request pool: dma_alloc_coherent succeed: hba_depth(%d), chains_per_io(%d), frame_sz(%d), total(%d kb)\n", ioc->hba_queue_depth, ioc->chains_needed_per_io, ioc->request_sz, sz / 1024); /* hi-priority queue */ ioc->hi_priority = ioc->request + ((ioc->scsiio_depth + 1) * ioc->request_sz); ioc->hi_priority_dma = ioc->request_dma + ((ioc->scsiio_depth + 1) * ioc->request_sz); /* internal queue */ ioc->internal = ioc->hi_priority + (ioc->hi_priority_depth * ioc->request_sz); ioc->internal_dma = ioc->hi_priority_dma + (ioc->hi_priority_depth * ioc->request_sz); ioc_info(ioc, "request pool(0x%p) - dma(0x%llx): " "depth(%d), frame_size(%d), pool_size(%d kB)\n", ioc->request, (unsigned long long) ioc->request_dma, ioc->hba_queue_depth, ioc->request_sz, (ioc->hba_queue_depth * ioc->request_sz) / 1024); total_sz += sz; dinitprintk(ioc, ioc_info(ioc, "scsiio(0x%p): depth(%d)\n", ioc->request, ioc->scsiio_depth)); ioc->chain_depth = min_t(u32, ioc->chain_depth, MAX_CHAIN_DEPTH); sz = ioc->scsiio_depth * sizeof(struct chain_lookup); ioc->chain_lookup = kzalloc(sz, GFP_KERNEL); if (!ioc->chain_lookup) { ioc_err(ioc, "chain_lookup: __get_free_pages failed\n"); goto out; } sz = ioc->chains_needed_per_io * sizeof(struct chain_tracker); for (i = 0; i < ioc->scsiio_depth; i++) { ioc->chain_lookup[i].chains_per_smid = kzalloc(sz, GFP_KERNEL); if (!ioc->chain_lookup[i].chains_per_smid) { ioc_err(ioc, "chain_lookup: kzalloc failed\n"); goto out; } } /* initialize hi-priority queue smid's */ ioc->hpr_lookup = kcalloc(ioc->hi_priority_depth, sizeof(struct request_tracker), GFP_KERNEL); if (!ioc->hpr_lookup) { ioc_err(ioc, "hpr_lookup: kcalloc failed\n"); goto out; } ioc->hi_priority_smid = ioc->scsiio_depth + 1; dinitprintk(ioc, ioc_info(ioc, "hi_priority(0x%p): depth(%d), start smid(%d)\n", ioc->hi_priority, ioc->hi_priority_depth, ioc->hi_priority_smid)); /* initialize internal queue smid's */ ioc->internal_lookup = kcalloc(ioc->internal_depth, sizeof(struct request_tracker), GFP_KERNEL); if (!ioc->internal_lookup) { ioc_err(ioc, "internal_lookup: kcalloc failed\n"); goto out; } ioc->internal_smid = ioc->hi_priority_smid + ioc->hi_priority_depth; dinitprintk(ioc, ioc_info(ioc, "internal(0x%p): depth(%d), start smid(%d)\n", ioc->internal, ioc->internal_depth, ioc->internal_smid)); ioc->io_queue_num = kcalloc(ioc->scsiio_depth, sizeof(u16), GFP_KERNEL); if (!ioc->io_queue_num) goto out; /* * The number of NVMe page sized blocks needed is: * (((sg_tablesize * 8) - 1) / (page_size - 8)) + 1 * ((sg_tablesize * 8) - 1) is the max PRP's minus the first PRP entry * that is placed in the main message frame. 8 is the size of each PRP * entry or PRP list pointer entry. 8 is subtracted from page_size * because of the PRP list pointer entry at the end of a page, so this * is not counted as a PRP entry. The 1 added page is a round up. * * To avoid allocation failures due to the amount of memory that could * be required for NVMe PRP's, only each set of NVMe blocks will be * contiguous, so a new set is allocated for each possible I/O. */ ioc->chains_per_prp_buffer = 0; if (ioc->facts.ProtocolFlags & MPI2_IOCFACTS_PROTOCOL_NVME_DEVICES) { nvme_blocks_needed = (ioc->shost->sg_tablesize * NVME_PRP_SIZE) - 1; nvme_blocks_needed /= (ioc->page_size - NVME_PRP_SIZE); nvme_blocks_needed++; sz = sizeof(struct pcie_sg_list) * ioc->scsiio_depth; ioc->pcie_sg_lookup = kzalloc(sz, GFP_KERNEL); if (!ioc->pcie_sg_lookup) { ioc_info(ioc, "PCIe SGL lookup: kzalloc failed\n"); goto out; } sz = nvme_blocks_needed * ioc->page_size; rc = _base_allocate_pcie_sgl_pool(ioc, sz); if (rc == -ENOMEM) return -ENOMEM; else if (rc == -EAGAIN) goto try_32bit_dma; total_sz += sz * ioc->scsiio_depth; } rc = _base_allocate_chain_dma_pool(ioc, ioc->chain_segment_sz); if (rc == -ENOMEM) return -ENOMEM; else if (rc == -EAGAIN) goto try_32bit_dma; total_sz += ioc->chain_segment_sz * ((ioc->chains_needed_per_io - ioc->chains_per_prp_buffer) * ioc->scsiio_depth); dinitprintk(ioc, ioc_info(ioc, "chain pool depth(%d), frame_size(%d), pool_size(%d kB)\n", ioc->chain_depth, ioc->chain_segment_sz, (ioc->chain_depth * ioc->chain_segment_sz) / 1024)); /* sense buffers, 4 byte align */ sense_sz = ioc->scsiio_depth * SCSI_SENSE_BUFFERSIZE; rc = _base_allocate_sense_dma_pool(ioc, sense_sz); if (rc == -ENOMEM) return -ENOMEM; else if (rc == -EAGAIN) goto try_32bit_dma; total_sz += sense_sz; ioc_info(ioc, "sense pool(0x%p)- dma(0x%llx): depth(%d)," "element_size(%d), pool_size(%d kB)\n", ioc->sense, (unsigned long long)ioc->sense_dma, ioc->scsiio_depth, SCSI_SENSE_BUFFERSIZE, sz / 1024); /* reply pool, 4 byte align */ sz = ioc->reply_free_queue_depth * ioc->reply_sz; rc = _base_allocate_reply_pool(ioc, sz); if (rc == -ENOMEM) return -ENOMEM; else if (rc == -EAGAIN) goto try_32bit_dma; total_sz += sz; /* reply free queue, 16 byte align */ sz = ioc->reply_free_queue_depth * 4; rc = _base_allocate_reply_free_dma_pool(ioc, sz); if (rc == -ENOMEM) return -ENOMEM; else if (rc == -EAGAIN) goto try_32bit_dma; dinitprintk(ioc, ioc_info(ioc, "reply_free_dma (0x%llx)\n", (unsigned long long)ioc->reply_free_dma)); total_sz += sz; if (ioc->rdpq_array_enable) { reply_post_free_array_sz = ioc->reply_queue_count * sizeof(Mpi2IOCInitRDPQArrayEntry); rc = _base_allocate_reply_post_free_array(ioc, reply_post_free_array_sz); if (rc == -ENOMEM) return -ENOMEM; else if (rc == -EAGAIN) goto try_32bit_dma; } ioc->config_page_sz = 512; ioc->config_page = dma_alloc_coherent(&ioc->pdev->dev, ioc->config_page_sz, &ioc->config_page_dma, GFP_KERNEL); if (!ioc->config_page) { ioc_err(ioc, "config page: dma_pool_alloc failed\n"); goto out; } ioc_info(ioc, "config page(0x%p) - dma(0x%llx): size(%d)\n", ioc->config_page, (unsigned long long)ioc->config_page_dma, ioc->config_page_sz); total_sz += ioc->config_page_sz; ioc_info(ioc, "Allocated physical memory: size(%d kB)\n", total_sz / 1024); ioc_info(ioc, "Current Controller Queue Depth(%d),Max Controller Queue Depth(%d)\n", ioc->shost->can_queue, facts->RequestCredit); ioc_info(ioc, "Scatter Gather Elements per IO(%d)\n", ioc->shost->sg_tablesize); return 0; try_32bit_dma: _base_release_memory_pools(ioc); if (ioc->use_32bit_dma && (ioc->dma_mask > 32)) { /* Change dma coherent mask to 32 bit and reallocate */ if (_base_config_dma_addressing(ioc, ioc->pdev) != 0) { pr_err("Setting 32 bit coherent DMA mask Failed %s\n", pci_name(ioc->pdev)); return -ENODEV; } } else if (_base_reduce_hba_queue_depth(ioc) != 0) return -ENOMEM; goto retry_allocation; out: return -ENOMEM; } /** * mpt3sas_base_get_iocstate - Get the current state of a MPT adapter. * @ioc: Pointer to MPT_ADAPTER structure * @cooked: Request raw or cooked IOC state * * Return: all IOC Doorbell register bits if cooked==0, else just the * Doorbell bits in MPI_IOC_STATE_MASK. */ u32 mpt3sas_base_get_iocstate(struct MPT3SAS_ADAPTER *ioc, int cooked) { u32 s, sc; s = ioc->base_readl(&ioc->chip->Doorbell); sc = s & MPI2_IOC_STATE_MASK; return cooked ? sc : s; } /** * _base_wait_on_iocstate - waiting on a particular ioc state * @ioc: ? * @ioc_state: controller state { READY, OPERATIONAL, or RESET } * @timeout: timeout in second * * Return: 0 for success, non-zero for failure. */ static int _base_wait_on_iocstate(struct MPT3SAS_ADAPTER *ioc, u32 ioc_state, int timeout) { u32 count, cntdn; u32 current_state; count = 0; cntdn = 1000 * timeout; do { current_state = mpt3sas_base_get_iocstate(ioc, 1); if (current_state == ioc_state) return 0; if (count && current_state == MPI2_IOC_STATE_FAULT) break; if (count && current_state == MPI2_IOC_STATE_COREDUMP) break; usleep_range(1000, 1500); count++; } while (--cntdn); return current_state; } /** * _base_dump_reg_set - This function will print hexdump of register set. * @ioc: per adapter object * * Return: nothing. */ static inline void _base_dump_reg_set(struct MPT3SAS_ADAPTER *ioc) { unsigned int i, sz = 256; u32 __iomem *reg = (u32 __iomem *)ioc->chip; ioc_info(ioc, "System Register set:\n"); for (i = 0; i < (sz / sizeof(u32)); i++) pr_info("%08x: %08x\n", (i * 4), readl(&reg[i])); } /** * _base_wait_for_doorbell_int - waiting for controller interrupt(generated by * a write to the doorbell) * @ioc: per adapter object * @timeout: timeout in seconds * * Return: 0 for success, non-zero for failure. * * Notes: MPI2_HIS_IOC2SYS_DB_STATUS - set to one when IOC writes to doorbell. */ static int _base_wait_for_doorbell_int(struct MPT3SAS_ADAPTER *ioc, int timeout) { u32 cntdn, count; u32 int_status; count = 0; cntdn = 1000 * timeout; do { int_status = ioc->base_readl(&ioc->chip->HostInterruptStatus); if (int_status & MPI2_HIS_IOC2SYS_DB_STATUS) { dhsprintk(ioc, ioc_info(ioc, "%s: successful count(%d), timeout(%d)\n", __func__, count, timeout)); return 0; } usleep_range(1000, 1500); count++; } while (--cntdn); ioc_err(ioc, "%s: failed due to timeout count(%d), int_status(%x)!\n", __func__, count, int_status); return -EFAULT; } static int _base_spin_on_doorbell_int(struct MPT3SAS_ADAPTER *ioc, int timeout) { u32 cntdn, count; u32 int_status; count = 0; cntdn = 2000 * timeout; do { int_status = ioc->base_readl(&ioc->chip->HostInterruptStatus); if (int_status & MPI2_HIS_IOC2SYS_DB_STATUS) { dhsprintk(ioc, ioc_info(ioc, "%s: successful count(%d), timeout(%d)\n", __func__, count, timeout)); return 0; } udelay(500); count++; } while (--cntdn); ioc_err(ioc, "%s: failed due to timeout count(%d), int_status(%x)!\n", __func__, count, int_status); return -EFAULT; } /** * _base_wait_for_doorbell_ack - waiting for controller to read the doorbell. * @ioc: per adapter object * @timeout: timeout in second * * Return: 0 for success, non-zero for failure. * * Notes: MPI2_HIS_SYS2IOC_DB_STATUS - set to one when host writes to * doorbell. */ static int _base_wait_for_doorbell_ack(struct MPT3SAS_ADAPTER *ioc, int timeout) { u32 cntdn, count; u32 int_status; u32 doorbell; count = 0; cntdn = 1000 * timeout; do { int_status = ioc->base_readl(&ioc->chip->HostInterruptStatus); if (!(int_status & MPI2_HIS_SYS2IOC_DB_STATUS)) { dhsprintk(ioc, ioc_info(ioc, "%s: successful count(%d), timeout(%d)\n", __func__, count, timeout)); return 0; } else if (int_status & MPI2_HIS_IOC2SYS_DB_STATUS) { doorbell = ioc->base_readl(&ioc->chip->Doorbell); if ((doorbell & MPI2_IOC_STATE_MASK) == MPI2_IOC_STATE_FAULT) { mpt3sas_print_fault_code(ioc, doorbell); return -EFAULT; } if ((doorbell & MPI2_IOC_STATE_MASK) == MPI2_IOC_STATE_COREDUMP) { mpt3sas_print_coredump_info(ioc, doorbell); return -EFAULT; } } else if (int_status == 0xFFFFFFFF) goto out; usleep_range(1000, 1500); count++; } while (--cntdn); out: ioc_err(ioc, "%s: failed due to timeout count(%d), int_status(%x)!\n", __func__, count, int_status); return -EFAULT; } /** * _base_wait_for_doorbell_not_used - waiting for doorbell to not be in use * @ioc: per adapter object * @timeout: timeout in second * * Return: 0 for success, non-zero for failure. */ static int _base_wait_for_doorbell_not_used(struct MPT3SAS_ADAPTER *ioc, int timeout) { u32 cntdn, count; u32 doorbell_reg; count = 0; cntdn = 1000 * timeout; do { doorbell_reg = ioc->base_readl(&ioc->chip->Doorbell); if (!(doorbell_reg & MPI2_DOORBELL_USED)) { dhsprintk(ioc, ioc_info(ioc, "%s: successful count(%d), timeout(%d)\n", __func__, count, timeout)); return 0; } usleep_range(1000, 1500); count++; } while (--cntdn); ioc_err(ioc, "%s: failed due to timeout count(%d), doorbell_reg(%x)!\n", __func__, count, doorbell_reg); return -EFAULT; } /** * _base_send_ioc_reset - send doorbell reset * @ioc: per adapter object * @reset_type: currently only supports: MPI2_FUNCTION_IOC_MESSAGE_UNIT_RESET * @timeout: timeout in second * * Return: 0 for success, non-zero for failure. */ static int _base_send_ioc_reset(struct MPT3SAS_ADAPTER *ioc, u8 reset_type, int timeout) { u32 ioc_state; int r = 0; unsigned long flags; if (reset_type != MPI2_FUNCTION_IOC_MESSAGE_UNIT_RESET) { ioc_err(ioc, "%s: unknown reset_type\n", __func__); return -EFAULT; } if (!(ioc->facts.IOCCapabilities & MPI2_IOCFACTS_CAPABILITY_EVENT_REPLAY)) return -EFAULT; ioc_info(ioc, "sending message unit reset !!\n"); writel(reset_type << MPI2_DOORBELL_FUNCTION_SHIFT, &ioc->chip->Doorbell); if ((_base_wait_for_doorbell_ack(ioc, 15))) { r = -EFAULT; goto out; } ioc_state = _base_wait_on_iocstate(ioc, MPI2_IOC_STATE_READY, timeout); if (ioc_state) { ioc_err(ioc, "%s: failed going to ready state (ioc_state=0x%x)\n", __func__, ioc_state); r = -EFAULT; goto out; } out: if (r != 0) { ioc_state = mpt3sas_base_get_iocstate(ioc, 0); spin_lock_irqsave(&ioc->ioc_reset_in_progress_lock, flags); /* * Wait for IOC state CoreDump to clear only during * HBA initialization & release time. */ if ((ioc_state & MPI2_IOC_STATE_MASK) == MPI2_IOC_STATE_COREDUMP && (ioc->is_driver_loading == 1 || ioc->fault_reset_work_q == NULL)) { spin_unlock_irqrestore( &ioc->ioc_reset_in_progress_lock, flags); mpt3sas_print_coredump_info(ioc, ioc_state); mpt3sas_base_wait_for_coredump_completion(ioc, __func__); spin_lock_irqsave( &ioc->ioc_reset_in_progress_lock, flags); } spin_unlock_irqrestore(&ioc->ioc_reset_in_progress_lock, flags); } ioc_info(ioc, "message unit reset: %s\n", r == 0 ? "SUCCESS" : "FAILED"); return r; } /** * mpt3sas_wait_for_ioc - IOC's operational state is checked here. * @ioc: per adapter object * @timeout: timeout in seconds * * Return: Waits up to timeout seconds for the IOC to * become operational. Returns 0 if IOC is present * and operational; otherwise returns %-EFAULT. */ int mpt3sas_wait_for_ioc(struct MPT3SAS_ADAPTER *ioc, int timeout) { int wait_state_count = 0; u32 ioc_state; do { ioc_state = mpt3sas_base_get_iocstate(ioc, 1); if (ioc_state == MPI2_IOC_STATE_OPERATIONAL) break; /* * Watchdog thread will be started after IOC Initialization, so * no need to wait here for IOC state to become operational * when IOC Initialization is on. Instead the driver will * return ETIME status, so that calling function can issue * diag reset operation and retry the command. */ if (ioc->is_driver_loading) return -ETIME; ssleep(1); ioc_info(ioc, "%s: waiting for operational state(count=%d)\n", __func__, ++wait_state_count); } while (--timeout); if (!timeout) { ioc_err(ioc, "%s: failed due to ioc not operational\n", __func__); return -EFAULT; } if (wait_state_count) ioc_info(ioc, "ioc is operational\n"); return 0; } /** * _base_handshake_req_reply_wait - send request thru doorbell interface * @ioc: per adapter object * @request_bytes: request length * @request: pointer having request payload * @reply_bytes: reply length * @reply: pointer to reply payload * @timeout: timeout in second * * Return: 0 for success, non-zero for failure. */ static int _base_handshake_req_reply_wait(struct MPT3SAS_ADAPTER *ioc, int request_bytes, u32 *request, int reply_bytes, u16 *reply, int timeout) { MPI2DefaultReply_t *default_reply = (MPI2DefaultReply_t *)reply; int i; u8 failed; __le32 *mfp; /* make sure doorbell is not in use */ if ((ioc->base_readl(&ioc->chip->Doorbell) & MPI2_DOORBELL_USED)) { ioc_err(ioc, "doorbell is in use (line=%d)\n", __LINE__); return -EFAULT; } /* clear pending doorbell interrupts from previous state changes */ if (ioc->base_readl(&ioc->chip->HostInterruptStatus) & MPI2_HIS_IOC2SYS_DB_STATUS) writel(0, &ioc->chip->HostInterruptStatus); /* send message to ioc */ writel(((MPI2_FUNCTION_HANDSHAKE<<MPI2_DOORBELL_FUNCTION_SHIFT) | ((request_bytes/4)<<MPI2_DOORBELL_ADD_DWORDS_SHIFT)), &ioc->chip->Doorbell); if ((_base_spin_on_doorbell_int(ioc, 5))) { ioc_err(ioc, "doorbell handshake int failed (line=%d)\n", __LINE__); return -EFAULT; } writel(0, &ioc->chip->HostInterruptStatus); if ((_base_wait_for_doorbell_ack(ioc, 5))) { ioc_err(ioc, "doorbell handshake ack failed (line=%d)\n", __LINE__); return -EFAULT; } /* send message 32-bits at a time */ for (i = 0, failed = 0; i < request_bytes/4 && !failed; i++) { writel(cpu_to_le32(request[i]), &ioc->chip->Doorbell); if ((_base_wait_for_doorbell_ack(ioc, 5))) failed = 1; } if (failed) { ioc_err(ioc, "doorbell handshake sending request failed (line=%d)\n", __LINE__); return -EFAULT; } /* now wait for the reply */ if ((_base_wait_for_doorbell_int(ioc, timeout))) { ioc_err(ioc, "doorbell handshake int failed (line=%d)\n", __LINE__); return -EFAULT; } /* read the first two 16-bits, it gives the total length of the reply */ reply[0] = le16_to_cpu(ioc->base_readl(&ioc->chip->Doorbell) & MPI2_DOORBELL_DATA_MASK); writel(0, &ioc->chip->HostInterruptStatus); if ((_base_wait_for_doorbell_int(ioc, 5))) { ioc_err(ioc, "doorbell handshake int failed (line=%d)\n", __LINE__); return -EFAULT; } reply[1] = le16_to_cpu(ioc->base_readl(&ioc->chip->Doorbell) & MPI2_DOORBELL_DATA_MASK); writel(0, &ioc->chip->HostInterruptStatus); for (i = 2; i < default_reply->MsgLength * 2; i++) { if ((_base_wait_for_doorbell_int(ioc, 5))) { ioc_err(ioc, "doorbell handshake int failed (line=%d)\n", __LINE__); return -EFAULT; } if (i >= reply_bytes/2) /* overflow case */ ioc->base_readl(&ioc->chip->Doorbell); else reply[i] = le16_to_cpu( ioc->base_readl(&ioc->chip->Doorbell) & MPI2_DOORBELL_DATA_MASK); writel(0, &ioc->chip->HostInterruptStatus); } _base_wait_for_doorbell_int(ioc, 5); if (_base_wait_for_doorbell_not_used(ioc, 5) != 0) { dhsprintk(ioc, ioc_info(ioc, "doorbell is in use (line=%d)\n", __LINE__)); } writel(0, &ioc->chip->HostInterruptStatus); if (ioc->logging_level & MPT_DEBUG_INIT) { mfp = (__le32 *)reply; pr_info("\toffset:data\n"); for (i = 0; i < reply_bytes/4; i++) ioc_info(ioc, "\t[0x%02x]:%08x\n", i*4, le32_to_cpu(mfp[i])); } return 0; } /** * mpt3sas_base_sas_iounit_control - send sas iounit control to FW * @ioc: per adapter object * @mpi_reply: the reply payload from FW * @mpi_request: the request payload sent to FW * * The SAS IO Unit Control Request message allows the host to perform low-level * operations, such as resets on the PHYs of the IO Unit, also allows the host * to obtain the IOC assigned device handles for a device if it has other * identifying information about the device, in addition allows the host to * remove IOC resources associated with the device. * * Return: 0 for success, non-zero for failure. */ int mpt3sas_base_sas_iounit_control(struct MPT3SAS_ADAPTER *ioc, Mpi2SasIoUnitControlReply_t *mpi_reply, Mpi2SasIoUnitControlRequest_t *mpi_request) { u16 smid; u8 issue_reset = 0; int rc; void *request; dinitprintk(ioc, ioc_info(ioc, "%s\n", __func__)); mutex_lock(&ioc->base_cmds.mutex); if (ioc->base_cmds.status != MPT3_CMD_NOT_USED) { ioc_err(ioc, "%s: base_cmd in use\n", __func__); rc = -EAGAIN; goto out; } rc = mpt3sas_wait_for_ioc(ioc, IOC_OPERATIONAL_WAIT_COUNT); if (rc) goto out; smid = mpt3sas_base_get_smid(ioc, ioc->base_cb_idx); if (!smid) { ioc_err(ioc, "%s: failed obtaining a smid\n", __func__); rc = -EAGAIN; goto out; } rc = 0; ioc->base_cmds.status = MPT3_CMD_PENDING; request = mpt3sas_base_get_msg_frame(ioc, smid); ioc->base_cmds.smid = smid; memcpy(request, mpi_request, sizeof(Mpi2SasIoUnitControlRequest_t)); if (mpi_request->Operation == MPI2_SAS_OP_PHY_HARD_RESET || mpi_request->Operation == MPI2_SAS_OP_PHY_LINK_RESET) ioc->ioc_link_reset_in_progress = 1; init_completion(&ioc->base_cmds.done); ioc->put_smid_default(ioc, smid); wait_for_completion_timeout(&ioc->base_cmds.done, msecs_to_jiffies(10000)); if ((mpi_request->Operation == MPI2_SAS_OP_PHY_HARD_RESET || mpi_request->Operation == MPI2_SAS_OP_PHY_LINK_RESET) && ioc->ioc_link_reset_in_progress) ioc->ioc_link_reset_in_progress = 0; if (!(ioc->base_cmds.status & MPT3_CMD_COMPLETE)) { mpt3sas_check_cmd_timeout(ioc, ioc->base_cmds.status, mpi_request, sizeof(Mpi2SasIoUnitControlRequest_t)/4, issue_reset); goto issue_host_reset; } if (ioc->base_cmds.status & MPT3_CMD_REPLY_VALID) memcpy(mpi_reply, ioc->base_cmds.reply, sizeof(Mpi2SasIoUnitControlReply_t)); else memset(mpi_reply, 0, sizeof(Mpi2SasIoUnitControlReply_t)); ioc->base_cmds.status = MPT3_CMD_NOT_USED; goto out; issue_host_reset: if (issue_reset) mpt3sas_base_hard_reset_handler(ioc, FORCE_BIG_HAMMER); ioc->base_cmds.status = MPT3_CMD_NOT_USED; rc = -EFAULT; out: mutex_unlock(&ioc->base_cmds.mutex); return rc; } /** * mpt3sas_base_scsi_enclosure_processor - sending request to sep device * @ioc: per adapter object * @mpi_reply: the reply payload from FW * @mpi_request: the request payload sent to FW * * The SCSI Enclosure Processor request message causes the IOC to * communicate with SES devices to control LED status signals. * * Return: 0 for success, non-zero for failure. */ int mpt3sas_base_scsi_enclosure_processor(struct MPT3SAS_ADAPTER *ioc, Mpi2SepReply_t *mpi_reply, Mpi2SepRequest_t *mpi_request) { u16 smid; u8 issue_reset = 0; int rc; void *request; dinitprintk(ioc, ioc_info(ioc, "%s\n", __func__)); mutex_lock(&ioc->base_cmds.mutex); if (ioc->base_cmds.status != MPT3_CMD_NOT_USED) { ioc_err(ioc, "%s: base_cmd in use\n", __func__); rc = -EAGAIN; goto out; } rc = mpt3sas_wait_for_ioc(ioc, IOC_OPERATIONAL_WAIT_COUNT); if (rc) goto out; smid = mpt3sas_base_get_smid(ioc, ioc->base_cb_idx); if (!smid) { ioc_err(ioc, "%s: failed obtaining a smid\n", __func__); rc = -EAGAIN; goto out; } rc = 0; ioc->base_cmds.status = MPT3_CMD_PENDING; request = mpt3sas_base_get_msg_frame(ioc, smid); ioc->base_cmds.smid = smid; memset(request, 0, ioc->request_sz); memcpy(request, mpi_request, sizeof(Mpi2SepReply_t)); init_completion(&ioc->base_cmds.done); ioc->put_smid_default(ioc, smid); wait_for_completion_timeout(&ioc->base_cmds.done, msecs_to_jiffies(10000)); if (!(ioc->base_cmds.status & MPT3_CMD_COMPLETE)) { mpt3sas_check_cmd_timeout(ioc, ioc->base_cmds.status, mpi_request, sizeof(Mpi2SepRequest_t)/4, issue_reset); goto issue_host_reset; } if (ioc->base_cmds.status & MPT3_CMD_REPLY_VALID) memcpy(mpi_reply, ioc->base_cmds.reply, sizeof(Mpi2SepReply_t)); else memset(mpi_reply, 0, sizeof(Mpi2SepReply_t)); ioc->base_cmds.status = MPT3_CMD_NOT_USED; goto out; issue_host_reset: if (issue_reset) mpt3sas_base_hard_reset_handler(ioc, FORCE_BIG_HAMMER); ioc->base_cmds.status = MPT3_CMD_NOT_USED; rc = -EFAULT; out: mutex_unlock(&ioc->base_cmds.mutex); return rc; } /** * _base_get_port_facts - obtain port facts reply and save in ioc * @ioc: per adapter object * @port: ? * * Return: 0 for success, non-zero for failure. */ static int _base_get_port_facts(struct MPT3SAS_ADAPTER *ioc, int port) { Mpi2PortFactsRequest_t mpi_request; Mpi2PortFactsReply_t mpi_reply; struct mpt3sas_port_facts *pfacts; int mpi_reply_sz, mpi_request_sz, r; dinitprintk(ioc, ioc_info(ioc, "%s\n", __func__)); mpi_reply_sz = sizeof(Mpi2PortFactsReply_t); mpi_request_sz = sizeof(Mpi2PortFactsRequest_t); memset(&mpi_request, 0, mpi_request_sz); mpi_request.Function = MPI2_FUNCTION_PORT_FACTS; mpi_request.PortNumber = port; r = _base_handshake_req_reply_wait(ioc, mpi_request_sz, (u32 *)&mpi_request, mpi_reply_sz, (u16 *)&mpi_reply, 5); if (r != 0) { ioc_err(ioc, "%s: handshake failed (r=%d)\n", __func__, r); return r; } pfacts = &ioc->pfacts[port]; memset(pfacts, 0, sizeof(struct mpt3sas_port_facts)); pfacts->PortNumber = mpi_reply.PortNumber; pfacts->VP_ID = mpi_reply.VP_ID; pfacts->VF_ID = mpi_reply.VF_ID; pfacts->MaxPostedCmdBuffers = le16_to_cpu(mpi_reply.MaxPostedCmdBuffers); return 0; } /** * _base_wait_for_iocstate - Wait until the card is in READY or OPERATIONAL * @ioc: per adapter object * @timeout: * * Return: 0 for success, non-zero for failure. */ static int _base_wait_for_iocstate(struct MPT3SAS_ADAPTER *ioc, int timeout) { u32 ioc_state; int rc; dinitprintk(ioc, ioc_info(ioc, "%s\n", __func__)); if (ioc->pci_error_recovery) { dfailprintk(ioc, ioc_info(ioc, "%s: host in pci error recovery\n", __func__)); return -EFAULT; } ioc_state = mpt3sas_base_get_iocstate(ioc, 0); dhsprintk(ioc, ioc_info(ioc, "%s: ioc_state(0x%08x)\n", __func__, ioc_state)); if (((ioc_state & MPI2_IOC_STATE_MASK) == MPI2_IOC_STATE_READY) || (ioc_state & MPI2_IOC_STATE_MASK) == MPI2_IOC_STATE_OPERATIONAL) return 0; if (ioc_state & MPI2_DOORBELL_USED) { dhsprintk(ioc, ioc_info(ioc, "unexpected doorbell active!\n")); goto issue_diag_reset; } if ((ioc_state & MPI2_IOC_STATE_MASK) == MPI2_IOC_STATE_FAULT) { mpt3sas_print_fault_code(ioc, ioc_state & MPI2_DOORBELL_DATA_MASK); goto issue_diag_reset; } else if ((ioc_state & MPI2_IOC_STATE_MASK) == MPI2_IOC_STATE_COREDUMP) { ioc_info(ioc, "%s: Skipping the diag reset here. (ioc_state=0x%x)\n", __func__, ioc_state); return -EFAULT; } ioc_state = _base_wait_on_iocstate(ioc, MPI2_IOC_STATE_READY, timeout); if (ioc_state) { dfailprintk(ioc, ioc_info(ioc, "%s: failed going to ready state (ioc_state=0x%x)\n", __func__, ioc_state)); return -EFAULT; } issue_diag_reset: rc = _base_diag_reset(ioc); return rc; } /** * _base_get_ioc_facts - obtain ioc facts reply and save in ioc * @ioc: per adapter object * * Return: 0 for success, non-zero for failure. */ static int _base_get_ioc_facts(struct MPT3SAS_ADAPTER *ioc) { Mpi2IOCFactsRequest_t mpi_request; Mpi2IOCFactsReply_t mpi_reply; struct mpt3sas_facts *facts; int mpi_reply_sz, mpi_request_sz, r; dinitprintk(ioc, ioc_info(ioc, "%s\n", __func__)); r = _base_wait_for_iocstate(ioc, 10); if (r) { dfailprintk(ioc, ioc_info(ioc, "%s: failed getting to correct state\n", __func__)); return r; } mpi_reply_sz = sizeof(Mpi2IOCFactsReply_t); mpi_request_sz = sizeof(Mpi2IOCFactsRequest_t); memset(&mpi_request, 0, mpi_request_sz); mpi_request.Function = MPI2_FUNCTION_IOC_FACTS; r = _base_handshake_req_reply_wait(ioc, mpi_request_sz, (u32 *)&mpi_request, mpi_reply_sz, (u16 *)&mpi_reply, 5); if (r != 0) { ioc_err(ioc, "%s: handshake failed (r=%d)\n", __func__, r); return r; } facts = &ioc->facts; memset(facts, 0, sizeof(struct mpt3sas_facts)); facts->MsgVersion = le16_to_cpu(mpi_reply.MsgVersion); facts->HeaderVersion = le16_to_cpu(mpi_reply.HeaderVersion); facts->VP_ID = mpi_reply.VP_ID; facts->VF_ID = mpi_reply.VF_ID; facts->IOCExceptions = le16_to_cpu(mpi_reply.IOCExceptions); facts->MaxChainDepth = mpi_reply.MaxChainDepth; facts->WhoInit = mpi_reply.WhoInit; facts->NumberOfPorts = mpi_reply.NumberOfPorts; facts->MaxMSIxVectors = mpi_reply.MaxMSIxVectors; if (ioc->msix_enable && (facts->MaxMSIxVectors <= MAX_COMBINED_MSIX_VECTORS(ioc->is_gen35_ioc))) ioc->combined_reply_queue = 0; facts->RequestCredit = le16_to_cpu(mpi_reply.RequestCredit); facts->MaxReplyDescriptorPostQueueDepth = le16_to_cpu(mpi_reply.MaxReplyDescriptorPostQueueDepth); facts->ProductID = le16_to_cpu(mpi_reply.ProductID); facts->IOCCapabilities = le32_to_cpu(mpi_reply.IOCCapabilities); if ((facts->IOCCapabilities & MPI2_IOCFACTS_CAPABILITY_INTEGRATED_RAID)) ioc->ir_firmware = 1; if ((facts->IOCCapabilities & MPI2_IOCFACTS_CAPABILITY_RDPQ_ARRAY_CAPABLE) && (!reset_devices)) ioc->rdpq_array_capable = 1; if ((facts->IOCCapabilities & MPI26_IOCFACTS_CAPABILITY_ATOMIC_REQ) && ioc->is_aero_ioc) ioc->atomic_desc_capable = 1; facts->FWVersion.Word = le32_to_cpu(mpi_reply.FWVersion.Word); facts->IOCRequestFrameSize = le16_to_cpu(mpi_reply.IOCRequestFrameSize); if (ioc->hba_mpi_version_belonged != MPI2_VERSION) { facts->IOCMaxChainSegmentSize = le16_to_cpu(mpi_reply.IOCMaxChainSegmentSize); } facts->MaxInitiators = le16_to_cpu(mpi_reply.MaxInitiators); facts->MaxTargets = le16_to_cpu(mpi_reply.MaxTargets); ioc->shost->max_id = -1; facts->MaxSasExpanders = le16_to_cpu(mpi_reply.MaxSasExpanders); facts->MaxEnclosures = le16_to_cpu(mpi_reply.MaxEnclosures); facts->ProtocolFlags = le16_to_cpu(mpi_reply.ProtocolFlags); facts->HighPriorityCredit = le16_to_cpu(mpi_reply.HighPriorityCredit); facts->ReplyFrameSize = mpi_reply.ReplyFrameSize; facts->MaxDevHandle = le16_to_cpu(mpi_reply.MaxDevHandle); facts->CurrentHostPageSize = mpi_reply.CurrentHostPageSize; /* * Get the Page Size from IOC Facts. If it's 0, default to 4k. */ ioc->page_size = 1 << facts->CurrentHostPageSize; if (ioc->page_size == 1) { ioc_info(ioc, "CurrentHostPageSize is 0: Setting default host page size to 4k\n"); ioc->page_size = 1 << MPT3SAS_HOST_PAGE_SIZE_4K; } dinitprintk(ioc, ioc_info(ioc, "CurrentHostPageSize(%d)\n", facts->CurrentHostPageSize)); dinitprintk(ioc, ioc_info(ioc, "hba queue depth(%d), max chains per io(%d)\n", facts->RequestCredit, facts->MaxChainDepth)); dinitprintk(ioc, ioc_info(ioc, "request frame size(%d), reply frame size(%d)\n", facts->IOCRequestFrameSize * 4, facts->ReplyFrameSize * 4)); return 0; } /** * _base_send_ioc_init - send ioc_init to firmware * @ioc: per adapter object * * Return: 0 for success, non-zero for failure. */ static int _base_send_ioc_init(struct MPT3SAS_ADAPTER *ioc) { Mpi2IOCInitRequest_t mpi_request; Mpi2IOCInitReply_t mpi_reply; int i, r = 0; ktime_t current_time; u16 ioc_status; u32 reply_post_free_array_sz = 0; dinitprintk(ioc, ioc_info(ioc, "%s\n", __func__)); memset(&mpi_request, 0, sizeof(Mpi2IOCInitRequest_t)); mpi_request.Function = MPI2_FUNCTION_IOC_INIT; mpi_request.WhoInit = MPI2_WHOINIT_HOST_DRIVER; mpi_request.VF_ID = 0; /* TODO */ mpi_request.VP_ID = 0; mpi_request.MsgVersion = cpu_to_le16(ioc->hba_mpi_version_belonged); mpi_request.HeaderVersion = cpu_to_le16(MPI2_HEADER_VERSION); mpi_request.HostPageSize = MPT3SAS_HOST_PAGE_SIZE_4K; if (_base_is_controller_msix_enabled(ioc)) mpi_request.HostMSIxVectors = ioc->reply_queue_count; mpi_request.SystemRequestFrameSize = cpu_to_le16(ioc->request_sz/4); mpi_request.ReplyDescriptorPostQueueDepth = cpu_to_le16(ioc->reply_post_queue_depth); mpi_request.ReplyFreeQueueDepth = cpu_to_le16(ioc->reply_free_queue_depth); mpi_request.SenseBufferAddressHigh = cpu_to_le32((u64)ioc->sense_dma >> 32); mpi_request.SystemReplyAddressHigh = cpu_to_le32((u64)ioc->reply_dma >> 32); mpi_request.SystemRequestFrameBaseAddress = cpu_to_le64((u64)ioc->request_dma); mpi_request.ReplyFreeQueueAddress = cpu_to_le64((u64)ioc->reply_free_dma); if (ioc->rdpq_array_enable) { reply_post_free_array_sz = ioc->reply_queue_count * sizeof(Mpi2IOCInitRDPQArrayEntry); memset(ioc->reply_post_free_array, 0, reply_post_free_array_sz); for (i = 0; i < ioc->reply_queue_count; i++) ioc->reply_post_free_array[i].RDPQBaseAddress = cpu_to_le64( (u64)ioc->reply_post[i].reply_post_free_dma); mpi_request.MsgFlags = MPI2_IOCINIT_MSGFLAG_RDPQ_ARRAY_MODE; mpi_request.ReplyDescriptorPostQueueAddress = cpu_to_le64((u64)ioc->reply_post_free_array_dma); } else { mpi_request.ReplyDescriptorPostQueueAddress = cpu_to_le64((u64)ioc->reply_post[0].reply_post_free_dma); } /* * Set the flag to enable CoreDump state feature in IOC firmware. */ mpi_request.ConfigurationFlags |= cpu_to_le16(MPI26_IOCINIT_CFGFLAGS_COREDUMP_ENABLE); /* This time stamp specifies number of milliseconds * since epoch ~ midnight January 1, 1970. */ current_time = ktime_get_real(); mpi_request.TimeStamp = cpu_to_le64(ktime_to_ms(current_time)); if (ioc->logging_level & MPT_DEBUG_INIT) { __le32 *mfp; int i; mfp = (__le32 *)&mpi_request; ioc_info(ioc, "\toffset:data\n"); for (i = 0; i < sizeof(Mpi2IOCInitRequest_t)/4; i++) ioc_info(ioc, "\t[0x%02x]:%08x\n", i*4, le32_to_cpu(mfp[i])); } r = _base_handshake_req_reply_wait(ioc, sizeof(Mpi2IOCInitRequest_t), (u32 *)&mpi_request, sizeof(Mpi2IOCInitReply_t), (u16 *)&mpi_reply, 30); if (r != 0) { ioc_err(ioc, "%s: handshake failed (r=%d)\n", __func__, r); return r; } ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK; if (ioc_status != MPI2_IOCSTATUS_SUCCESS || mpi_reply.IOCLogInfo) { ioc_err(ioc, "%s: failed\n", __func__); r = -EIO; } /* Reset TimeSync Counter*/ ioc->timestamp_update_count = 0; return r; } /** * mpt3sas_port_enable_done - command completion routine for port enable * @ioc: per adapter object * @smid: system request message index * @msix_index: MSIX table index supplied by the OS * @reply: reply message frame(lower 32bit addr) * * Return: 1 meaning mf should be freed from _base_interrupt * 0 means the mf is freed from this function. */ u8 mpt3sas_port_enable_done(struct MPT3SAS_ADAPTER *ioc, u16 smid, u8 msix_index, u32 reply) { MPI2DefaultReply_t *mpi_reply; u16 ioc_status; if (ioc->port_enable_cmds.status == MPT3_CMD_NOT_USED) return 1; mpi_reply = mpt3sas_base_get_reply_virt_addr(ioc, reply); if (!mpi_reply) return 1; if (mpi_reply->Function != MPI2_FUNCTION_PORT_ENABLE) return 1; ioc->port_enable_cmds.status &= ~MPT3_CMD_PENDING; ioc->port_enable_cmds.status |= MPT3_CMD_COMPLETE; ioc->port_enable_cmds.status |= MPT3_CMD_REPLY_VALID; memcpy(ioc->port_enable_cmds.reply, mpi_reply, mpi_reply->MsgLength*4); ioc_status = le16_to_cpu(mpi_reply->IOCStatus) & MPI2_IOCSTATUS_MASK; if (ioc_status != MPI2_IOCSTATUS_SUCCESS) ioc->port_enable_failed = 1; if (ioc->port_enable_cmds.status & MPT3_CMD_COMPLETE_ASYNC) { ioc->port_enable_cmds.status &= ~MPT3_CMD_COMPLETE_ASYNC; if (ioc_status == MPI2_IOCSTATUS_SUCCESS) { mpt3sas_port_enable_complete(ioc); return 1; } else { ioc->start_scan_failed = ioc_status; ioc->start_scan = 0; return 1; } } complete(&ioc->port_enable_cmds.done); return 1; } /** * _base_send_port_enable - send port_enable(discovery stuff) to firmware * @ioc: per adapter object * * Return: 0 for success, non-zero for failure. */ static int _base_send_port_enable(struct MPT3SAS_ADAPTER *ioc) { Mpi2PortEnableRequest_t *mpi_request; Mpi2PortEnableReply_t *mpi_reply; int r = 0; u16 smid; u16 ioc_status; ioc_info(ioc, "sending port enable !!\n"); if (ioc->port_enable_cmds.status & MPT3_CMD_PENDING) { ioc_err(ioc, "%s: internal command already in use\n", __func__); return -EAGAIN; } smid = mpt3sas_base_get_smid(ioc, ioc->port_enable_cb_idx); if (!smid) { ioc_err(ioc, "%s: failed obtaining a smid\n", __func__); return -EAGAIN; } ioc->port_enable_cmds.status = MPT3_CMD_PENDING; mpi_request = mpt3sas_base_get_msg_frame(ioc, smid); ioc->port_enable_cmds.smid = smid; memset(mpi_request, 0, sizeof(Mpi2PortEnableRequest_t)); mpi_request->Function = MPI2_FUNCTION_PORT_ENABLE; init_completion(&ioc->port_enable_cmds.done); ioc->put_smid_default(ioc, smid); wait_for_completion_timeout(&ioc->port_enable_cmds.done, 300*HZ); if (!(ioc->port_enable_cmds.status & MPT3_CMD_COMPLETE)) { ioc_err(ioc, "%s: timeout\n", __func__); _debug_dump_mf(mpi_request, sizeof(Mpi2PortEnableRequest_t)/4); if (ioc->port_enable_cmds.status & MPT3_CMD_RESET) r = -EFAULT; else r = -ETIME; goto out; } mpi_reply = ioc->port_enable_cmds.reply; ioc_status = le16_to_cpu(mpi_reply->IOCStatus) & MPI2_IOCSTATUS_MASK; if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { ioc_err(ioc, "%s: failed with (ioc_status=0x%08x)\n", __func__, ioc_status); r = -EFAULT; goto out; } out: ioc->port_enable_cmds.status = MPT3_CMD_NOT_USED; ioc_info(ioc, "port enable: %s\n", r == 0 ? "SUCCESS" : "FAILED"); return r; } /** * mpt3sas_port_enable - initiate firmware discovery (don't wait for reply) * @ioc: per adapter object * * Return: 0 for success, non-zero for failure. */ int mpt3sas_port_enable(struct MPT3SAS_ADAPTER *ioc) { Mpi2PortEnableRequest_t *mpi_request; u16 smid; ioc_info(ioc, "sending port enable !!\n"); if (ioc->port_enable_cmds.status & MPT3_CMD_PENDING) { ioc_err(ioc, "%s: internal command already in use\n", __func__); return -EAGAIN; } smid = mpt3sas_base_get_smid(ioc, ioc->port_enable_cb_idx); if (!smid) { ioc_err(ioc, "%s: failed obtaining a smid\n", __func__); return -EAGAIN; } ioc->drv_internal_flags |= MPT_DRV_INTERNAL_FIRST_PE_ISSUED; ioc->port_enable_cmds.status = MPT3_CMD_PENDING; ioc->port_enable_cmds.status |= MPT3_CMD_COMPLETE_ASYNC; mpi_request = mpt3sas_base_get_msg_frame(ioc, smid); ioc->port_enable_cmds.smid = smid; memset(mpi_request, 0, sizeof(Mpi2PortEnableRequest_t)); mpi_request->Function = MPI2_FUNCTION_PORT_ENABLE; ioc->put_smid_default(ioc, smid); return 0; } /** * _base_determine_wait_on_discovery - desposition * @ioc: per adapter object * * Decide whether to wait on discovery to complete. Used to either * locate boot device, or report volumes ahead of physical devices. * * Return: 1 for wait, 0 for don't wait. */ static int _base_determine_wait_on_discovery(struct MPT3SAS_ADAPTER *ioc) { /* We wait for discovery to complete if IR firmware is loaded. * The sas topology events arrive before PD events, so we need time to * turn on the bit in ioc->pd_handles to indicate PD * Also, it maybe required to report Volumes ahead of physical * devices when MPI2_IOCPAGE8_IRFLAGS_LOW_VOLUME_MAPPING is set. */ if (ioc->ir_firmware) return 1; /* if no Bios, then we don't need to wait */ if (!ioc->bios_pg3.BiosVersion) return 0; /* Bios is present, then we drop down here. * * If there any entries in the Bios Page 2, then we wait * for discovery to complete. */ /* Current Boot Device */ if ((ioc->bios_pg2.CurrentBootDeviceForm & MPI2_BIOSPAGE2_FORM_MASK) == MPI2_BIOSPAGE2_FORM_NO_DEVICE_SPECIFIED && /* Request Boot Device */ (ioc->bios_pg2.ReqBootDeviceForm & MPI2_BIOSPAGE2_FORM_MASK) == MPI2_BIOSPAGE2_FORM_NO_DEVICE_SPECIFIED && /* Alternate Request Boot Device */ (ioc->bios_pg2.ReqAltBootDeviceForm & MPI2_BIOSPAGE2_FORM_MASK) == MPI2_BIOSPAGE2_FORM_NO_DEVICE_SPECIFIED) return 0; return 1; } /** * _base_unmask_events - turn on notification for this event * @ioc: per adapter object * @event: firmware event * * The mask is stored in ioc->event_masks. */ static void _base_unmask_events(struct MPT3SAS_ADAPTER *ioc, u16 event) { u32 desired_event; if (event >= 128) return; desired_event = (1 << (event % 32)); if (event < 32) ioc->event_masks[0] &= ~desired_event; else if (event < 64) ioc->event_masks[1] &= ~desired_event; else if (event < 96) ioc->event_masks[2] &= ~desired_event; else if (event < 128) ioc->event_masks[3] &= ~desired_event; } /** * _base_event_notification - send event notification * @ioc: per adapter object * * Return: 0 for success, non-zero for failure. */ static int _base_event_notification(struct MPT3SAS_ADAPTER *ioc) { Mpi2EventNotificationRequest_t *mpi_request; u16 smid; int r = 0; int i, issue_diag_reset = 0; dinitprintk(ioc, ioc_info(ioc, "%s\n", __func__)); if (ioc->base_cmds.status & MPT3_CMD_PENDING) { ioc_err(ioc, "%s: internal command already in use\n", __func__); return -EAGAIN; } smid = mpt3sas_base_get_smid(ioc, ioc->base_cb_idx); if (!smid) { ioc_err(ioc, "%s: failed obtaining a smid\n", __func__); return -EAGAIN; } ioc->base_cmds.status = MPT3_CMD_PENDING; mpi_request = mpt3sas_base_get_msg_frame(ioc, smid); ioc->base_cmds.smid = smid; memset(mpi_request, 0, sizeof(Mpi2EventNotificationRequest_t)); mpi_request->Function = MPI2_FUNCTION_EVENT_NOTIFICATION; mpi_request->VF_ID = 0; /* TODO */ mpi_request->VP_ID = 0; for (i = 0; i < MPI2_EVENT_NOTIFY_EVENTMASK_WORDS; i++) mpi_request->EventMasks[i] = cpu_to_le32(ioc->event_masks[i]); init_completion(&ioc->base_cmds.done); ioc->put_smid_default(ioc, smid); wait_for_completion_timeout(&ioc->base_cmds.done, 30*HZ); if (!(ioc->base_cmds.status & MPT3_CMD_COMPLETE)) { ioc_err(ioc, "%s: timeout\n", __func__); _debug_dump_mf(mpi_request, sizeof(Mpi2EventNotificationRequest_t)/4); if (ioc->base_cmds.status & MPT3_CMD_RESET) r = -EFAULT; else issue_diag_reset = 1; } else dinitprintk(ioc, ioc_info(ioc, "%s: complete\n", __func__)); ioc->base_cmds.status = MPT3_CMD_NOT_USED; if (issue_diag_reset) { if (ioc->drv_internal_flags & MPT_DRV_INTERNAL_FIRST_PE_ISSUED) return -EFAULT; if (mpt3sas_base_check_for_fault_and_issue_reset(ioc)) return -EFAULT; r = -EAGAIN; } return r; } /** * mpt3sas_base_validate_event_type - validating event types * @ioc: per adapter object * @event_type: firmware event * * This will turn on firmware event notification when application * ask for that event. We don't mask events that are already enabled. */ void mpt3sas_base_validate_event_type(struct MPT3SAS_ADAPTER *ioc, u32 *event_type) { int i, j; u32 event_mask, desired_event; u8 send_update_to_fw; for (i = 0, send_update_to_fw = 0; i < MPI2_EVENT_NOTIFY_EVENTMASK_WORDS; i++) { event_mask = ~event_type[i]; desired_event = 1; for (j = 0; j < 32; j++) { if (!(event_mask & desired_event) && (ioc->event_masks[i] & desired_event)) { ioc->event_masks[i] &= ~desired_event; send_update_to_fw = 1; } desired_event = (desired_event << 1); } } if (!send_update_to_fw) return; mutex_lock(&ioc->base_cmds.mutex); _base_event_notification(ioc); mutex_unlock(&ioc->base_cmds.mutex); } /** * _base_diag_reset - the "big hammer" start of day reset * @ioc: per adapter object * * Return: 0 for success, non-zero for failure. */ static int _base_diag_reset(struct MPT3SAS_ADAPTER *ioc) { u32 host_diagnostic; u32 ioc_state; u32 count; u32 hcb_size; ioc_info(ioc, "sending diag reset !!\n"); pci_cfg_access_lock(ioc->pdev); drsprintk(ioc, ioc_info(ioc, "clear interrupts\n")); count = 0; do { /* Write magic sequence to WriteSequence register * Loop until in diagnostic mode */ drsprintk(ioc, ioc_info(ioc, "write magic sequence\n")); writel(MPI2_WRSEQ_FLUSH_KEY_VALUE, &ioc->chip->WriteSequence); writel(MPI2_WRSEQ_1ST_KEY_VALUE, &ioc->chip->WriteSequence); writel(MPI2_WRSEQ_2ND_KEY_VALUE, &ioc->chip->WriteSequence); writel(MPI2_WRSEQ_3RD_KEY_VALUE, &ioc->chip->WriteSequence); writel(MPI2_WRSEQ_4TH_KEY_VALUE, &ioc->chip->WriteSequence); writel(MPI2_WRSEQ_5TH_KEY_VALUE, &ioc->chip->WriteSequence); writel(MPI2_WRSEQ_6TH_KEY_VALUE, &ioc->chip->WriteSequence); /* wait 100 msec */ msleep(100); if (count++ > 20) { ioc_info(ioc, "Stop writing magic sequence after 20 retries\n"); _base_dump_reg_set(ioc); goto out; } host_diagnostic = ioc->base_readl(&ioc->chip->HostDiagnostic); drsprintk(ioc, ioc_info(ioc, "wrote magic sequence: count(%d), host_diagnostic(0x%08x)\n", count, host_diagnostic)); } while ((host_diagnostic & MPI2_DIAG_DIAG_WRITE_ENABLE) == 0); hcb_size = ioc->base_readl(&ioc->chip->HCBSize); drsprintk(ioc, ioc_info(ioc, "diag reset: issued\n")); writel(host_diagnostic | MPI2_DIAG_RESET_ADAPTER, &ioc->chip->HostDiagnostic); /*This delay allows the chip PCIe hardware time to finish reset tasks*/ msleep(MPI2_HARD_RESET_PCIE_FIRST_READ_DELAY_MICRO_SEC/1000); /* Approximately 300 second max wait */ for (count = 0; count < (300000000 / MPI2_HARD_RESET_PCIE_SECOND_READ_DELAY_MICRO_SEC); count++) { host_diagnostic = ioc->base_readl(&ioc->chip->HostDiagnostic); if (host_diagnostic == 0xFFFFFFFF) { ioc_info(ioc, "Invalid host diagnostic register value\n"); _base_dump_reg_set(ioc); goto out; } if (!(host_diagnostic & MPI2_DIAG_RESET_ADAPTER)) break; msleep(MPI2_HARD_RESET_PCIE_SECOND_READ_DELAY_MICRO_SEC / 1000); } if (host_diagnostic & MPI2_DIAG_HCB_MODE) { drsprintk(ioc, ioc_info(ioc, "restart the adapter assuming the HCB Address points to good F/W\n")); host_diagnostic &= ~MPI2_DIAG_BOOT_DEVICE_SELECT_MASK; host_diagnostic |= MPI2_DIAG_BOOT_DEVICE_SELECT_HCDW; writel(host_diagnostic, &ioc->chip->HostDiagnostic); drsprintk(ioc, ioc_info(ioc, "re-enable the HCDW\n")); writel(hcb_size | MPI2_HCB_SIZE_HCB_ENABLE, &ioc->chip->HCBSize); } drsprintk(ioc, ioc_info(ioc, "restart the adapter\n")); writel(host_diagnostic & ~MPI2_DIAG_HOLD_IOC_RESET, &ioc->chip->HostDiagnostic); drsprintk(ioc, ioc_info(ioc, "disable writes to the diagnostic register\n")); writel(MPI2_WRSEQ_FLUSH_KEY_VALUE, &ioc->chip->WriteSequence); drsprintk(ioc, ioc_info(ioc, "Wait for FW to go to the READY state\n")); ioc_state = _base_wait_on_iocstate(ioc, MPI2_IOC_STATE_READY, 20); if (ioc_state) { ioc_err(ioc, "%s: failed going to ready state (ioc_state=0x%x)\n", __func__, ioc_state); _base_dump_reg_set(ioc); goto out; } pci_cfg_access_unlock(ioc->pdev); ioc_info(ioc, "diag reset: SUCCESS\n"); return 0; out: pci_cfg_access_unlock(ioc->pdev); ioc_err(ioc, "diag reset: FAILED\n"); return -EFAULT; } /** * mpt3sas_base_make_ioc_ready - put controller in READY state * @ioc: per adapter object * @type: FORCE_BIG_HAMMER or SOFT_RESET * * Return: 0 for success, non-zero for failure. */ int mpt3sas_base_make_ioc_ready(struct MPT3SAS_ADAPTER *ioc, enum reset_type type) { u32 ioc_state; int rc; int count; dinitprintk(ioc, ioc_info(ioc, "%s\n", __func__)); if (ioc->pci_error_recovery) return 0; ioc_state = mpt3sas_base_get_iocstate(ioc, 0); dhsprintk(ioc, ioc_info(ioc, "%s: ioc_state(0x%08x)\n", __func__, ioc_state)); /* if in RESET state, it should move to READY state shortly */ count = 0; if ((ioc_state & MPI2_IOC_STATE_MASK) == MPI2_IOC_STATE_RESET) { while ((ioc_state & MPI2_IOC_STATE_MASK) != MPI2_IOC_STATE_READY) { if (count++ == 10) { ioc_err(ioc, "%s: failed going to ready state (ioc_state=0x%x)\n", __func__, ioc_state); return -EFAULT; } ssleep(1); ioc_state = mpt3sas_base_get_iocstate(ioc, 0); } } if ((ioc_state & MPI2_IOC_STATE_MASK) == MPI2_IOC_STATE_READY) return 0; if (ioc_state & MPI2_DOORBELL_USED) { ioc_info(ioc, "unexpected doorbell active!\n"); goto issue_diag_reset; } if ((ioc_state & MPI2_IOC_STATE_MASK) == MPI2_IOC_STATE_FAULT) { mpt3sas_print_fault_code(ioc, ioc_state & MPI2_DOORBELL_DATA_MASK); goto issue_diag_reset; } if ((ioc_state & MPI2_IOC_STATE_MASK) == MPI2_IOC_STATE_COREDUMP) { /* * if host reset is invoked while watch dog thread is waiting * for IOC state to be changed to Fault state then driver has * to wait here for CoreDump state to clear otherwise reset * will be issued to the FW and FW move the IOC state to * reset state without copying the FW logs to coredump region. */ if (ioc->ioc_coredump_loop != MPT3SAS_COREDUMP_LOOP_DONE) { mpt3sas_print_coredump_info(ioc, ioc_state & MPI2_DOORBELL_DATA_MASK); mpt3sas_base_wait_for_coredump_completion(ioc, __func__); } goto issue_diag_reset; } if (type == FORCE_BIG_HAMMER) goto issue_diag_reset; if ((ioc_state & MPI2_IOC_STATE_MASK) == MPI2_IOC_STATE_OPERATIONAL) if (!(_base_send_ioc_reset(ioc, MPI2_FUNCTION_IOC_MESSAGE_UNIT_RESET, 15))) { return 0; } issue_diag_reset: rc = _base_diag_reset(ioc); return rc; } /** * _base_make_ioc_operational - put controller in OPERATIONAL state * @ioc: per adapter object * * Return: 0 for success, non-zero for failure. */ static int _base_make_ioc_operational(struct MPT3SAS_ADAPTER *ioc) { int r, i, index, rc; unsigned long flags; u32 reply_address; u16 smid; struct _tr_list *delayed_tr, *delayed_tr_next; struct _sc_list *delayed_sc, *delayed_sc_next; struct _event_ack_list *delayed_event_ack, *delayed_event_ack_next; u8 hide_flag; struct adapter_reply_queue *reply_q; Mpi2ReplyDescriptorsUnion_t *reply_post_free_contig; dinitprintk(ioc, ioc_info(ioc, "%s\n", __func__)); /* clean the delayed target reset list */ list_for_each_entry_safe(delayed_tr, delayed_tr_next, &ioc->delayed_tr_list, list) { list_del(&delayed_tr->list); kfree(delayed_tr); } list_for_each_entry_safe(delayed_tr, delayed_tr_next, &ioc->delayed_tr_volume_list, list) { list_del(&delayed_tr->list); kfree(delayed_tr); } list_for_each_entry_safe(delayed_sc, delayed_sc_next, &ioc->delayed_sc_list, list) { list_del(&delayed_sc->list); kfree(delayed_sc); } list_for_each_entry_safe(delayed_event_ack, delayed_event_ack_next, &ioc->delayed_event_ack_list, list) { list_del(&delayed_event_ack->list); kfree(delayed_event_ack); } spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); /* hi-priority queue */ INIT_LIST_HEAD(&ioc->hpr_free_list); smid = ioc->hi_priority_smid; for (i = 0; i < ioc->hi_priority_depth; i++, smid++) { ioc->hpr_lookup[i].cb_idx = 0xFF; ioc->hpr_lookup[i].smid = smid; list_add_tail(&ioc->hpr_lookup[i].tracker_list, &ioc->hpr_free_list); } /* internal queue */ INIT_LIST_HEAD(&ioc->internal_free_list); smid = ioc->internal_smid; for (i = 0; i < ioc->internal_depth; i++, smid++) { ioc->internal_lookup[i].cb_idx = 0xFF; ioc->internal_lookup[i].smid = smid; list_add_tail(&ioc->internal_lookup[i].tracker_list, &ioc->internal_free_list); } spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags); /* initialize Reply Free Queue */ for (i = 0, reply_address = (u32)ioc->reply_dma ; i < ioc->reply_free_queue_depth ; i++, reply_address += ioc->reply_sz) { ioc->reply_free[i] = cpu_to_le32(reply_address); if (ioc->is_mcpu_endpoint) _base_clone_reply_to_sys_mem(ioc, reply_address, i); } /* initialize reply queues */ if (ioc->is_driver_loading) _base_assign_reply_queues(ioc); /* initialize Reply Post Free Queue */ index = 0; reply_post_free_contig = ioc->reply_post[0].reply_post_free; list_for_each_entry(reply_q, &ioc->reply_queue_list, list) { /* * If RDPQ is enabled, switch to the next allocation. * Otherwise advance within the contiguous region. */ if (ioc->rdpq_array_enable) { reply_q->reply_post_free = ioc->reply_post[index++].reply_post_free; } else { reply_q->reply_post_free = reply_post_free_contig; reply_post_free_contig += ioc->reply_post_queue_depth; } reply_q->reply_post_host_index = 0; for (i = 0; i < ioc->reply_post_queue_depth; i++) reply_q->reply_post_free[i].Words = cpu_to_le64(ULLONG_MAX); if (!_base_is_controller_msix_enabled(ioc)) goto skip_init_reply_post_free_queue; } skip_init_reply_post_free_queue: r = _base_send_ioc_init(ioc); if (r) { /* * No need to check IOC state for fault state & issue * diag reset during host reset. This check is need * only during driver load time. */ if (!ioc->is_driver_loading) return r; rc = mpt3sas_base_check_for_fault_and_issue_reset(ioc); if (rc || (_base_send_ioc_init(ioc))) return r; } /* initialize reply free host index */ ioc->reply_free_host_index = ioc->reply_free_queue_depth - 1; writel(ioc->reply_free_host_index, &ioc->chip->ReplyFreeHostIndex); /* initialize reply post host index */ list_for_each_entry(reply_q, &ioc->reply_queue_list, list) { if (ioc->combined_reply_queue) writel((reply_q->msix_index & 7)<< MPI2_RPHI_MSIX_INDEX_SHIFT, ioc->replyPostRegisterIndex[reply_q->msix_index/8]); else writel(reply_q->msix_index << MPI2_RPHI_MSIX_INDEX_SHIFT, &ioc->chip->ReplyPostHostIndex); if (!_base_is_controller_msix_enabled(ioc)) goto skip_init_reply_post_host_index; } skip_init_reply_post_host_index: mpt3sas_base_unmask_interrupts(ioc); if (ioc->hba_mpi_version_belonged != MPI2_VERSION) { r = _base_display_fwpkg_version(ioc); if (r) return r; } r = _base_static_config_pages(ioc); if (r) return r; r = _base_event_notification(ioc); if (r) return r; if (!ioc->shost_recovery) { if (ioc->is_warpdrive && ioc->manu_pg10.OEMIdentifier == 0x80) { hide_flag = (u8) ( le32_to_cpu(ioc->manu_pg10.OEMSpecificFlags0) & MFG_PAGE10_HIDE_SSDS_MASK); if (hide_flag != MFG_PAGE10_HIDE_SSDS_MASK) ioc->mfg_pg10_hide_flag = hide_flag; } ioc->wait_for_discovery_to_complete = _base_determine_wait_on_discovery(ioc); return r; /* scan_start and scan_finished support */ } r = _base_send_port_enable(ioc); if (r) return r; return r; } /** * mpt3sas_base_free_resources - free resources controller resources * @ioc: per adapter object */ void mpt3sas_base_free_resources(struct MPT3SAS_ADAPTER *ioc) { dexitprintk(ioc, ioc_info(ioc, "%s\n", __func__)); /* synchronizing freeing resource with pci_access_mutex lock */ mutex_lock(&ioc->pci_access_mutex); if (ioc->chip_phys && ioc->chip) { mpt3sas_base_mask_interrupts(ioc); ioc->shost_recovery = 1; mpt3sas_base_make_ioc_ready(ioc, SOFT_RESET); ioc->shost_recovery = 0; } mpt3sas_base_unmap_resources(ioc); mutex_unlock(&ioc->pci_access_mutex); return; } /** * mpt3sas_base_attach - attach controller instance * @ioc: per adapter object * * Return: 0 for success, non-zero for failure. */ int mpt3sas_base_attach(struct MPT3SAS_ADAPTER *ioc) { int r, i, rc; int cpu_id, last_cpu_id = 0; dinitprintk(ioc, ioc_info(ioc, "%s\n", __func__)); /* setup cpu_msix_table */ ioc->cpu_count = num_online_cpus(); for_each_online_cpu(cpu_id) last_cpu_id = cpu_id; ioc->cpu_msix_table_sz = last_cpu_id + 1; ioc->cpu_msix_table = kzalloc(ioc->cpu_msix_table_sz, GFP_KERNEL); ioc->reply_queue_count = 1; if (!ioc->cpu_msix_table) { ioc_info(ioc, "Allocation for cpu_msix_table failed!!!\n"); r = -ENOMEM; goto out_free_resources; } if (ioc->is_warpdrive) { ioc->reply_post_host_index = kcalloc(ioc->cpu_msix_table_sz, sizeof(resource_size_t *), GFP_KERNEL); if (!ioc->reply_post_host_index) { ioc_info(ioc, "Allocation for reply_post_host_index failed!!!\n"); r = -ENOMEM; goto out_free_resources; } } ioc->smp_affinity_enable = smp_affinity_enable; ioc->rdpq_array_enable_assigned = 0; ioc->use_32bit_dma = false; ioc->dma_mask = 64; if (ioc->is_aero_ioc) ioc->base_readl = &_base_readl_aero; else ioc->base_readl = &_base_readl; r = mpt3sas_base_map_resources(ioc); if (r) goto out_free_resources; pci_set_drvdata(ioc->pdev, ioc->shost); r = _base_get_ioc_facts(ioc); if (r) { rc = mpt3sas_base_check_for_fault_and_issue_reset(ioc); if (rc || (_base_get_ioc_facts(ioc))) goto out_free_resources; } switch (ioc->hba_mpi_version_belonged) { case MPI2_VERSION: ioc->build_sg_scmd = &_base_build_sg_scmd; ioc->build_sg = &_base_build_sg; ioc->build_zero_len_sge = &_base_build_zero_len_sge; ioc->get_msix_index_for_smlio = &_base_get_msix_index; break; case MPI25_VERSION: case MPI26_VERSION: /* * In SAS3.0, * SCSI_IO, SMP_PASSTHRU, SATA_PASSTHRU, Target Assist, and * Target Status - all require the IEEE formatted scatter gather * elements. */ ioc->build_sg_scmd = &_base_build_sg_scmd_ieee; ioc->build_sg = &_base_build_sg_ieee; ioc->build_nvme_prp = &_base_build_nvme_prp; ioc->build_zero_len_sge = &_base_build_zero_len_sge_ieee; ioc->sge_size_ieee = sizeof(Mpi2IeeeSgeSimple64_t); if (ioc->high_iops_queues) ioc->get_msix_index_for_smlio = &_base_get_high_iops_msix_index; else ioc->get_msix_index_for_smlio = &_base_get_msix_index; break; } if (ioc->atomic_desc_capable) { ioc->put_smid_default = &_base_put_smid_default_atomic; ioc->put_smid_scsi_io = &_base_put_smid_scsi_io_atomic; ioc->put_smid_fast_path = &_base_put_smid_fast_path_atomic; ioc->put_smid_hi_priority = &_base_put_smid_hi_priority_atomic; } else { ioc->put_smid_default = &_base_put_smid_default; ioc->put_smid_fast_path = &_base_put_smid_fast_path; ioc->put_smid_hi_priority = &_base_put_smid_hi_priority; if (ioc->is_mcpu_endpoint) ioc->put_smid_scsi_io = &_base_put_smid_mpi_ep_scsi_io; else ioc->put_smid_scsi_io = &_base_put_smid_scsi_io; } /* * These function pointers for other requests that don't * the require IEEE scatter gather elements. * * For example Configuration Pages and SAS IOUNIT Control don't. */ ioc->build_sg_mpi = &_base_build_sg; ioc->build_zero_len_sge_mpi = &_base_build_zero_len_sge; r = mpt3sas_base_make_ioc_ready(ioc, SOFT_RESET); if (r) goto out_free_resources; ioc->pfacts = kcalloc(ioc->facts.NumberOfPorts, sizeof(struct mpt3sas_port_facts), GFP_KERNEL); if (!ioc->pfacts) { r = -ENOMEM; goto out_free_resources; } for (i = 0 ; i < ioc->facts.NumberOfPorts; i++) { r = _base_get_port_facts(ioc, i); if (r) { rc = mpt3sas_base_check_for_fault_and_issue_reset(ioc); if (rc || (_base_get_port_facts(ioc, i))) goto out_free_resources; } } r = _base_allocate_memory_pools(ioc); if (r) goto out_free_resources; if (irqpoll_weight > 0) ioc->thresh_hold = irqpoll_weight; else ioc->thresh_hold = ioc->hba_queue_depth/4; _base_init_irqpolls(ioc); init_waitqueue_head(&ioc->reset_wq); /* allocate memory pd handle bitmask list */ ioc->pd_handles_sz = (ioc->facts.MaxDevHandle / 8); if (ioc->facts.MaxDevHandle % 8) ioc->pd_handles_sz++; ioc->pd_handles = kzalloc(ioc->pd_handles_sz, GFP_KERNEL); if (!ioc->pd_handles) { r = -ENOMEM; goto out_free_resources; } ioc->blocking_handles = kzalloc(ioc->pd_handles_sz, GFP_KERNEL); if (!ioc->blocking_handles) { r = -ENOMEM; goto out_free_resources; } /* allocate memory for pending OS device add list */ ioc->pend_os_device_add_sz = (ioc->facts.MaxDevHandle / 8); if (ioc->facts.MaxDevHandle % 8) ioc->pend_os_device_add_sz++; ioc->pend_os_device_add = kzalloc(ioc->pend_os_device_add_sz, GFP_KERNEL); if (!ioc->pend_os_device_add) { r = -ENOMEM; goto out_free_resources; } ioc->device_remove_in_progress_sz = ioc->pend_os_device_add_sz; ioc->device_remove_in_progress = kzalloc(ioc->device_remove_in_progress_sz, GFP_KERNEL); if (!ioc->device_remove_in_progress) { r = -ENOMEM; goto out_free_resources; } ioc->fwfault_debug = mpt3sas_fwfault_debug; /* base internal command bits */ mutex_init(&ioc->base_cmds.mutex); ioc->base_cmds.reply = kzalloc(ioc->reply_sz, GFP_KERNEL); ioc->base_cmds.status = MPT3_CMD_NOT_USED; /* port_enable command bits */ ioc->port_enable_cmds.reply = kzalloc(ioc->reply_sz, GFP_KERNEL); ioc->port_enable_cmds.status = MPT3_CMD_NOT_USED; /* transport internal command bits */ ioc->transport_cmds.reply = kzalloc(ioc->reply_sz, GFP_KERNEL); ioc->transport_cmds.status = MPT3_CMD_NOT_USED; mutex_init(&ioc->transport_cmds.mutex); /* scsih internal command bits */ ioc->scsih_cmds.reply = kzalloc(ioc->reply_sz, GFP_KERNEL); ioc->scsih_cmds.status = MPT3_CMD_NOT_USED; mutex_init(&ioc->scsih_cmds.mutex); /* task management internal command bits */ ioc->tm_cmds.reply = kzalloc(ioc->reply_sz, GFP_KERNEL); ioc->tm_cmds.status = MPT3_CMD_NOT_USED; mutex_init(&ioc->tm_cmds.mutex); /* config page internal command bits */ ioc->config_cmds.reply = kzalloc(ioc->reply_sz, GFP_KERNEL); ioc->config_cmds.status = MPT3_CMD_NOT_USED; mutex_init(&ioc->config_cmds.mutex); /* ctl module internal command bits */ ioc->ctl_cmds.reply = kzalloc(ioc->reply_sz, GFP_KERNEL); ioc->ctl_cmds.sense = kzalloc(SCSI_SENSE_BUFFERSIZE, GFP_KERNEL); ioc->ctl_cmds.status = MPT3_CMD_NOT_USED; mutex_init(&ioc->ctl_cmds.mutex); if (!ioc->base_cmds.reply || !ioc->port_enable_cmds.reply || !ioc->transport_cmds.reply || !ioc->scsih_cmds.reply || !ioc->tm_cmds.reply || !ioc->config_cmds.reply || !ioc->ctl_cmds.reply || !ioc->ctl_cmds.sense) { r = -ENOMEM; goto out_free_resources; } for (i = 0; i < MPI2_EVENT_NOTIFY_EVENTMASK_WORDS; i++) ioc->event_masks[i] = -1; /* here we enable the events we care about */ _base_unmask_events(ioc, MPI2_EVENT_SAS_DISCOVERY); _base_unmask_events(ioc, MPI2_EVENT_SAS_BROADCAST_PRIMITIVE); _base_unmask_events(ioc, MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST); _base_unmask_events(ioc, MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE); _base_unmask_events(ioc, MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE); _base_unmask_events(ioc, MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST); _base_unmask_events(ioc, MPI2_EVENT_IR_VOLUME); _base_unmask_events(ioc, MPI2_EVENT_IR_PHYSICAL_DISK); _base_unmask_events(ioc, MPI2_EVENT_IR_OPERATION_STATUS); _base_unmask_events(ioc, MPI2_EVENT_LOG_ENTRY_ADDED); _base_unmask_events(ioc, MPI2_EVENT_TEMP_THRESHOLD); _base_unmask_events(ioc, MPI2_EVENT_ACTIVE_CABLE_EXCEPTION); _base_unmask_events(ioc, MPI2_EVENT_SAS_DEVICE_DISCOVERY_ERROR); if (ioc->hba_mpi_version_belonged == MPI26_VERSION) { if (ioc->is_gen35_ioc) { _base_unmask_events(ioc, MPI2_EVENT_PCIE_DEVICE_STATUS_CHANGE); _base_unmask_events(ioc, MPI2_EVENT_PCIE_ENUMERATION); _base_unmask_events(ioc, MPI2_EVENT_PCIE_TOPOLOGY_CHANGE_LIST); } } r = _base_make_ioc_operational(ioc); if (r == -EAGAIN) { r = _base_make_ioc_operational(ioc); if (r) goto out_free_resources; } /* * Copy current copy of IOCFacts in prev_fw_facts * and it will be used during online firmware upgrade. */ memcpy(&ioc->prev_fw_facts, &ioc->facts, sizeof(struct mpt3sas_facts)); ioc->non_operational_loop = 0; ioc->ioc_coredump_loop = 0; ioc->got_task_abort_from_ioctl = 0; return 0; out_free_resources: ioc->remove_host = 1; mpt3sas_base_free_resources(ioc); _base_release_memory_pools(ioc); pci_set_drvdata(ioc->pdev, NULL); kfree(ioc->cpu_msix_table); if (ioc->is_warpdrive) kfree(ioc->reply_post_host_index); kfree(ioc->pd_handles); kfree(ioc->blocking_handles); kfree(ioc->device_remove_in_progress); kfree(ioc->pend_os_device_add); kfree(ioc->tm_cmds.reply); kfree(ioc->transport_cmds.reply); kfree(ioc->scsih_cmds.reply); kfree(ioc->config_cmds.reply); kfree(ioc->base_cmds.reply); kfree(ioc->port_enable_cmds.reply); kfree(ioc->ctl_cmds.reply); kfree(ioc->ctl_cmds.sense); kfree(ioc->pfacts); ioc->ctl_cmds.reply = NULL; ioc->base_cmds.reply = NULL; ioc->tm_cmds.reply = NULL; ioc->scsih_cmds.reply = NULL; ioc->transport_cmds.reply = NULL; ioc->config_cmds.reply = NULL; ioc->pfacts = NULL; return r; } /** * mpt3sas_base_detach - remove controller instance * @ioc: per adapter object */ void mpt3sas_base_detach(struct MPT3SAS_ADAPTER *ioc) { dexitprintk(ioc, ioc_info(ioc, "%s\n", __func__)); mpt3sas_base_stop_watchdog(ioc); mpt3sas_base_free_resources(ioc); _base_release_memory_pools(ioc); mpt3sas_free_enclosure_list(ioc); pci_set_drvdata(ioc->pdev, NULL); kfree(ioc->cpu_msix_table); if (ioc->is_warpdrive) kfree(ioc->reply_post_host_index); kfree(ioc->pd_handles); kfree(ioc->blocking_handles); kfree(ioc->device_remove_in_progress); kfree(ioc->pend_os_device_add); kfree(ioc->pfacts); kfree(ioc->ctl_cmds.reply); kfree(ioc->ctl_cmds.sense); kfree(ioc->base_cmds.reply); kfree(ioc->port_enable_cmds.reply); kfree(ioc->tm_cmds.reply); kfree(ioc->transport_cmds.reply); kfree(ioc->scsih_cmds.reply); kfree(ioc->config_cmds.reply); } /** * _base_pre_reset_handler - pre reset handler * @ioc: per adapter object */ static void _base_pre_reset_handler(struct MPT3SAS_ADAPTER *ioc) { mpt3sas_scsih_pre_reset_handler(ioc); mpt3sas_ctl_pre_reset_handler(ioc); dtmprintk(ioc, ioc_info(ioc, "%s: MPT3_IOC_PRE_RESET\n", __func__)); } /** * _base_clear_outstanding_mpt_commands - clears outstanding mpt commands * @ioc: per adapter object */ static void _base_clear_outstanding_mpt_commands(struct MPT3SAS_ADAPTER *ioc) { dtmprintk(ioc, ioc_info(ioc, "%s: clear outstanding mpt cmds\n", __func__)); if (ioc->transport_cmds.status & MPT3_CMD_PENDING) { ioc->transport_cmds.status |= MPT3_CMD_RESET; mpt3sas_base_free_smid(ioc, ioc->transport_cmds.smid); complete(&ioc->transport_cmds.done); } if (ioc->base_cmds.status & MPT3_CMD_PENDING) { ioc->base_cmds.status |= MPT3_CMD_RESET; mpt3sas_base_free_smid(ioc, ioc->base_cmds.smid); complete(&ioc->base_cmds.done); } if (ioc->port_enable_cmds.status & MPT3_CMD_PENDING) { ioc->port_enable_failed = 1; ioc->port_enable_cmds.status |= MPT3_CMD_RESET; mpt3sas_base_free_smid(ioc, ioc->port_enable_cmds.smid); if (ioc->is_driver_loading) { ioc->start_scan_failed = MPI2_IOCSTATUS_INTERNAL_ERROR; ioc->start_scan = 0; } else { complete(&ioc->port_enable_cmds.done); } } if (ioc->config_cmds.status & MPT3_CMD_PENDING) { ioc->config_cmds.status |= MPT3_CMD_RESET; mpt3sas_base_free_smid(ioc, ioc->config_cmds.smid); ioc->config_cmds.smid = USHRT_MAX; complete(&ioc->config_cmds.done); } } /** * _base_clear_outstanding_commands - clear all outstanding commands * @ioc: per adapter object */ static void _base_clear_outstanding_commands(struct MPT3SAS_ADAPTER *ioc) { mpt3sas_scsih_clear_outstanding_scsi_tm_commands(ioc); mpt3sas_ctl_clear_outstanding_ioctls(ioc); _base_clear_outstanding_mpt_commands(ioc); } /** * _base_reset_done_handler - reset done handler * @ioc: per adapter object */ static void _base_reset_done_handler(struct MPT3SAS_ADAPTER *ioc) { mpt3sas_scsih_reset_done_handler(ioc); mpt3sas_ctl_reset_done_handler(ioc); dtmprintk(ioc, ioc_info(ioc, "%s: MPT3_IOC_DONE_RESET\n", __func__)); } /** * mpt3sas_wait_for_commands_to_complete - reset controller * @ioc: Pointer to MPT_ADAPTER structure * * This function is waiting 10s for all pending commands to complete * prior to putting controller in reset. */ void mpt3sas_wait_for_commands_to_complete(struct MPT3SAS_ADAPTER *ioc) { u32 ioc_state; ioc->pending_io_count = 0; ioc_state = mpt3sas_base_get_iocstate(ioc, 0); if ((ioc_state & MPI2_IOC_STATE_MASK) != MPI2_IOC_STATE_OPERATIONAL) return; /* pending command count */ ioc->pending_io_count = scsi_host_busy(ioc->shost); if (!ioc->pending_io_count) return; /* wait for pending commands to complete */ wait_event_timeout(ioc->reset_wq, ioc->pending_io_count == 0, 10 * HZ); } /** * _base_check_ioc_facts_changes - Look for increase/decrease of IOCFacts * attributes during online firmware upgrade and update the corresponding * IOC variables accordingly. * * @ioc: Pointer to MPT_ADAPTER structure */ static int _base_check_ioc_facts_changes(struct MPT3SAS_ADAPTER *ioc) { u16 pd_handles_sz; void *pd_handles = NULL, *blocking_handles = NULL; void *pend_os_device_add = NULL, *device_remove_in_progress = NULL; struct mpt3sas_facts *old_facts = &ioc->prev_fw_facts; if (ioc->facts.MaxDevHandle > old_facts->MaxDevHandle) { pd_handles_sz = (ioc->facts.MaxDevHandle / 8); if (ioc->facts.MaxDevHandle % 8) pd_handles_sz++; pd_handles = krealloc(ioc->pd_handles, pd_handles_sz, GFP_KERNEL); if (!pd_handles) { ioc_info(ioc, "Unable to allocate the memory for pd_handles of sz: %d\n", pd_handles_sz); return -ENOMEM; } memset(pd_handles + ioc->pd_handles_sz, 0, (pd_handles_sz - ioc->pd_handles_sz)); ioc->pd_handles = pd_handles; blocking_handles = krealloc(ioc->blocking_handles, pd_handles_sz, GFP_KERNEL); if (!blocking_handles) { ioc_info(ioc, "Unable to allocate the memory for " "blocking_handles of sz: %d\n", pd_handles_sz); return -ENOMEM; } memset(blocking_handles + ioc->pd_handles_sz, 0, (pd_handles_sz - ioc->pd_handles_sz)); ioc->blocking_handles = blocking_handles; ioc->pd_handles_sz = pd_handles_sz; pend_os_device_add = krealloc(ioc->pend_os_device_add, pd_handles_sz, GFP_KERNEL); if (!pend_os_device_add) { ioc_info(ioc, "Unable to allocate the memory for pend_os_device_add of sz: %d\n", pd_handles_sz); return -ENOMEM; } memset(pend_os_device_add + ioc->pend_os_device_add_sz, 0, (pd_handles_sz - ioc->pend_os_device_add_sz)); ioc->pend_os_device_add = pend_os_device_add; ioc->pend_os_device_add_sz = pd_handles_sz; device_remove_in_progress = krealloc( ioc->device_remove_in_progress, pd_handles_sz, GFP_KERNEL); if (!device_remove_in_progress) { ioc_info(ioc, "Unable to allocate the memory for " "device_remove_in_progress of sz: %d\n " , pd_handles_sz); return -ENOMEM; } memset(device_remove_in_progress + ioc->device_remove_in_progress_sz, 0, (pd_handles_sz - ioc->device_remove_in_progress_sz)); ioc->device_remove_in_progress = device_remove_in_progress; ioc->device_remove_in_progress_sz = pd_handles_sz; } memcpy(&ioc->prev_fw_facts, &ioc->facts, sizeof(struct mpt3sas_facts)); return 0; } /** * mpt3sas_base_hard_reset_handler - reset controller * @ioc: Pointer to MPT_ADAPTER structure * @type: FORCE_BIG_HAMMER or SOFT_RESET * * Return: 0 for success, non-zero for failure. */ int mpt3sas_base_hard_reset_handler(struct MPT3SAS_ADAPTER *ioc, enum reset_type type) { int r; unsigned long flags; u32 ioc_state; u8 is_fault = 0, is_trigger = 0; dtmprintk(ioc, ioc_info(ioc, "%s: enter\n", __func__)); if (ioc->pci_error_recovery) { ioc_err(ioc, "%s: pci error recovery reset\n", __func__); r = 0; goto out_unlocked; } if (mpt3sas_fwfault_debug) mpt3sas_halt_firmware(ioc); /* wait for an active reset in progress to complete */ mutex_lock(&ioc->reset_in_progress_mutex); spin_lock_irqsave(&ioc->ioc_reset_in_progress_lock, flags); ioc->shost_recovery = 1; spin_unlock_irqrestore(&ioc->ioc_reset_in_progress_lock, flags); if ((ioc->diag_buffer_status[MPI2_DIAG_BUF_TYPE_TRACE] & MPT3_DIAG_BUFFER_IS_REGISTERED) && (!(ioc->diag_buffer_status[MPI2_DIAG_BUF_TYPE_TRACE] & MPT3_DIAG_BUFFER_IS_RELEASED))) { is_trigger = 1; ioc_state = mpt3sas_base_get_iocstate(ioc, 0); if ((ioc_state & MPI2_IOC_STATE_MASK) == MPI2_IOC_STATE_FAULT || (ioc_state & MPI2_IOC_STATE_MASK) == MPI2_IOC_STATE_COREDUMP) { is_fault = 1; ioc->htb_rel.trigger_info_dwords[1] = (ioc_state & MPI2_DOORBELL_DATA_MASK); } } _base_pre_reset_handler(ioc); mpt3sas_wait_for_commands_to_complete(ioc); mpt3sas_base_mask_interrupts(ioc); mpt3sas_base_pause_mq_polling(ioc); r = mpt3sas_base_make_ioc_ready(ioc, type); if (r) goto out; _base_clear_outstanding_commands(ioc); /* If this hard reset is called while port enable is active, then * there is no reason to call make_ioc_operational */ if (ioc->is_driver_loading && ioc->port_enable_failed) { ioc->remove_host = 1; r = -EFAULT; goto out; } r = _base_get_ioc_facts(ioc); if (r) goto out; r = _base_check_ioc_facts_changes(ioc); if (r) { ioc_info(ioc, "Some of the parameters got changed in this new firmware" " image and it requires system reboot\n"); goto out; } if (ioc->rdpq_array_enable && !ioc->rdpq_array_capable) panic("%s: Issue occurred with flashing controller firmware." "Please reboot the system and ensure that the correct" " firmware version is running\n", ioc->name); r = _base_make_ioc_operational(ioc); if (!r) _base_reset_done_handler(ioc); out: ioc_info(ioc, "%s: %s\n", __func__, r == 0 ? "SUCCESS" : "FAILED"); spin_lock_irqsave(&ioc->ioc_reset_in_progress_lock, flags); ioc->shost_recovery = 0; spin_unlock_irqrestore(&ioc->ioc_reset_in_progress_lock, flags); ioc->ioc_reset_count++; mutex_unlock(&ioc->reset_in_progress_mutex); mpt3sas_base_resume_mq_polling(ioc); out_unlocked: if ((r == 0) && is_trigger) { if (is_fault) mpt3sas_trigger_master(ioc, MASTER_TRIGGER_FW_FAULT); else mpt3sas_trigger_master(ioc, MASTER_TRIGGER_ADAPTER_RESET); } dtmprintk(ioc, ioc_info(ioc, "%s: exit\n", __func__)); return r; }
gpl-2.0
fizista/Dorimanx-SG2-I9100-Kernel
arch/arm/mach-exynos/busfreq_opp_4x12.c
13
32948
/* linux/arch/arm/mach-exynos/busfreq_opp_4x12.c * * Copyright (c) 2011 Samsung Electronics Co., Ltd. * http://www.samsung.com/ * * EXYNOS4 - BUS clock frequency scaling support with OPP * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 as * published by the Free Software Foundation. */ #include <linux/init.h> #include <linux/interrupt.h> #include <linux/types.h> #include <linux/err.h> #include <linux/io.h> #include <linux/regulator/consumer.h> #include <linux/sysfs.h> #include <linux/platform_device.h> #include <linux/device.h> #include <linux/module.h> #include <linux/cpu.h> #include <linux/ktime.h> #include <linux/tick.h> #include <linux/kernel_stat.h> #include <linux/reboot.h> #include <linux/slab.h> #include <linux/opp.h> #include <linux/clk.h> #include <linux/cpufreq.h> #include <linux/pm_qos_params.h> #include <mach/busfreq_exynos4.h> #include <asm/mach-types.h> #include <mach/ppmu.h> #include <mach/map.h> #include <mach/regs-clock.h> #include <mach/gpio.h> #include <mach/regs-mem.h> #include <mach/dev.h> #include <mach/asv.h> #include <mach/smc.h> #include <plat/map-s5p.h> #include <plat/gpio-cfg.h> #include <plat/cpu.h> #define UP_THRESHOLD 30 #define IDLE_THRESHOLD 4 #define UP_CPU_THRESHOLD 11 #define MAX_CPU_THRESHOLD 20 #define CPU_SLOPE_SIZE 7 #define PPMU_THRESHOLD 5 unsigned int up_threshold = UP_THRESHOLD; unsigned int ppmu_threshold = PPMU_THRESHOLD; unsigned int idle_threshold = IDLE_THRESHOLD; unsigned int up_cpu_threshold = UP_CPU_THRESHOLD; unsigned int max_cpu_threshold = MAX_CPU_THRESHOLD; unsigned int cpu_slope_size = CPU_SLOPE_SIZE; unsigned int dmc_max_threshold; unsigned int load_history_size = LOAD_HISTORY_SIZE; static bool mif_locking; static bool int_locking; /* To save/restore DMC_PAUSE_CTRL register */ static unsigned int dmc_pause_ctrl; enum busfreq_level_idx { LV_0, LV_1, LV_2, LV_3, LV_4, LV_5, LV_6, LV_END }; struct busfreq_table *exynos4_busfreq_table; static struct busfreq_table exynos4_busfreq_table_orig[] = { {LV_0, 400266, 1100000, 0, 0, 0}, /* MIF : 400MHz INT : 200MHz */ {LV_1, 400200, 1100000, 0, 0, 0}, /* MIF : 400MHz INT : 200MHz */ {LV_2, 267200, 1000000, 0, 0, 0}, /* MIF : 267MHz INT : 200MHz */ {LV_3, 267160, 1000000, 0, 0, 0}, /* MIF : 267MHz INT : 160MHz */ {LV_4, 160160, 950000, 0, 0, 0}, /* MIF : 160MHz INT : 160MHz */ {LV_5, 133133, 950000, 0, 0, 0}, /* MIF : 133MHz INT : 133MHz */ {LV_6, 100100, 950000, 0, 0, 0}, /* MIF : 100MHz INT : 100MHz */ }; static struct busfreq_table exynos4_busfreq_table_rev2[] = { {LV_0, 440293, 1100000, 0, 0, 0}, /* MIF : 440MHz INT : 220MHz */ {LV_1, 440220, 1100000, 0, 0, 0}, /* MIF : 440MHz INT : 220MHz */ {LV_2, 293220, 1000000, 0, 0, 0}, /* MIF : 293MHz INT : 220MHz */ {LV_3, 293176, 1000000, 0, 0, 0}, /* MIF : 293MHz INT : 176MHz */ {LV_4, 176176, 950000, 0, 0, 0}, /* MIF : 176MHz INT : 176MHz */ {LV_5, 147147, 950000, 0, 0, 0}, /* MIF : 147MHz INT : 147MHz */ {LV_6, 110110, 950000, 0, 0, 0}, /* MIF : 110MHz INT : 110MHz */ }; enum busfreq_qos_target { BUS_QOS_0, BUS_QOS_1, BUS_QOS_MAX, }; static enum busfreq_qos_target busfreq_qos = BUS_QOS_0; static unsigned int (*exynos4_qos_value)[LV_END][4]; #if defined(CONFIG_BUSFREQ_QOS_1280X800) /* P4NOTE */ static unsigned int exynos4_qos_value_orig[BUS_QOS_MAX][LV_END][4] = { { {0x00, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x00, 0x00}, {0x06, 0x03, 0x06, 0x0e}, {0x06, 0x03, 0x06, 0x0e}, {0x03, 0x03, 0x03, 0x0e}, {0x03, 0x03, 0x03, 0x0e}, {0x02, 0x0B, 0x00, 0x00}, }, { {0x06, 0x0b, 0x06, 0x0f}, {0x06, 0x0b, 0x06, 0x0f}, {0x06, 0x0b, 0x06, 0x0f}, {0x06, 0x0b, 0x06, 0x0f}, {0x06, 0x03, 0x06, 0x0e}, {0x04, 0x03, 0x04, 0x0e}, {0x02, 0x0b, 0x00, 0x00}, }, }; static unsigned int exynos4_qos_value_rev2[BUS_QOS_MAX][LV_END][4] = { { {0x00, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x00, 0x00}, {0x06, 0x03, 0x06, 0x0e}, {0x06, 0x03, 0x06, 0x0e}, {0x03, 0x03, 0x03, 0x0e}, {0x03, 0x03, 0x03, 0x0e}, {0x02, 0x0B, 0x00, 0x00}, }, { {0x06, 0x0b, 0x06, 0x0f}, {0x06, 0x0b, 0x06, 0x0f}, {0x06, 0x0b, 0x06, 0x0f}, {0x06, 0x0b, 0x06, 0x0f}, {0x06, 0x03, 0x06, 0x0e}, {0x04, 0x03, 0x04, 0x0e}, {0x02, 0x0b, 0x00, 0x00}, }, }; #else static unsigned int exynos4_qos_value_orig[BUS_QOS_MAX][LV_END][4] = { { {0x00, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x00, 0x00}, {0x06, 0x03, 0x06, 0x0e}, {0x04, 0x03, 0x04, 0x0e}, {0x03, 0x0B, 0x00, 0x00}, }, { {0x06, 0x0b, 0x06, 0x0f}, {0x06, 0x0b, 0x06, 0x0f}, {0x06, 0x0b, 0x06, 0x0f}, {0x06, 0x0b, 0x06, 0x0f}, {0x06, 0x03, 0x06, 0x0e}, {0x04, 0x03, 0x04, 0x0e}, {0x03, 0x0b, 0x00, 0x00}, }, }; static unsigned int exynos4_qos_value_rev2[BUS_QOS_MAX][LV_END][4] = { { {0x00, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x00, 0x00}, {0x06, 0x03, 0x06, 0x0e}, {0x06, 0x03, 0x06, 0x0e}, {0x03, 0x03, 0x03, 0x0e}, {0x03, 0x03, 0x03, 0x0e}, {0x02, 0x03, 0x02, 0x0e}, }, { {0x06, 0x0b, 0x06, 0x0f}, {0x06, 0x0b, 0x06, 0x0f}, {0x06, 0x0b, 0x06, 0x0f}, {0x06, 0x0b, 0x06, 0x0f}, {0x06, 0x03, 0x06, 0x0e}, {0x04, 0x03, 0x04, 0x0e}, {0x03, 0x0b, 0x00, 0x00}, }, }; #endif #define ASV_GROUP 12 #define PRIME_ASV_GROUP 13 static unsigned int asv_group_index; static unsigned int (*exynos4_mif_volt)[LV_END]; static unsigned int (*exynos4_int_volt)[LV_END]; static unsigned int exynos4212_mif_volt[ASV_GROUP][LV_END] = { /* 400 400 267 267 160 133 100 */ {1012500, 1012500, 962500, 962500, 912500, 912500, 912500}, /* RESERVED */ {1000000, 1000000, 950000, 950000, 900000, 900000, 900000}, /* ASV1 */ {1000000, 1000000, 950000, 950000, 900000, 900000, 900000}, /* ASV2 */ {1000000, 1000000, 950000, 950000, 900000, 900000, 900000}, /* ASV3 */ {1050000, 1050000, 1000000, 1000000, 900000, 900000, 900000}, /* ASV4 */ {1000000, 1000000, 950000, 950000, 900000, 900000, 900000}, /* ASV5 */ {1000000, 1000000, 950000, 950000, 900000, 900000, 900000}, /* ASV6 */ {950000, 950000, 900000, 900000, 900000, 900000, 900000}, /* ASV7 */ {950000, 950000, 900000, 900000, 900000, 900000, 850000}, /* ASV8 */ {950000, 950000, 900000, 900000, 900000, 900000, 850000}, /* ASV9 */ {950000, 950000, 900000, 900000, 900000, 850000, 850000}, /* ASV10 */ {937500, 937500, 887500, 887500, 887500, 850000, 850000}, /* RESERVED */ }; static unsigned int exynos4212_int_volt[ASV_GROUP][LV_END] = { /* 266 200 200 160 160 133 100 */ {1300000, 1250000, 1250000, 950000, 950000, 912500, 887500}, /* RESERVED */ {1062500, 1012500, 1012500, 937500, 937500, 900000, 875000}, /* ASV1 */ {1050000, 1000000, 1000000, 925000, 925000, 887500, 875000}, /* ASV2 */ {1050000, 1000000, 1000000, 912500, 912500, 887500, 875000}, /* ASV3 */ {1062500, 1012500, 1012500, 925000, 925000, 900000, 875000}, /* ASV4 */ {1050000, 1000000, 1000000, 925000, 925000, 887500, 875000}, /* ASV5 */ {1050000, 1000000, 1000000, 912500, 912500, 887500, 875000}, /* ASV6 */ {1037500, 987500, 987500, 912500, 912500, 875000, 875000}, /* ASV7 */ {1037500, 987500, 987500, 900000, 900000, 875000, 875000}, /* ASV8 */ {1037500, 987500, 987500, 900000, 900000, 875000, 875000}, /* ASV9 */ {1037500, 987500, 987500, 900000, 900000, 862500, 850000}, /* ASV10 */ {1035000, 975000, 975000, 887500, 887500, 850000, 850000}, /* RESERVED */ }; static unsigned int exynos4412_mif_volt[ASV_GROUP][LV_END] = { /* 400 400 267 267 160 133 100 */ {1100000, 1100000, 1000000, 1000000, 950000, 950000, 950000}, /* RESERVED */ {1050000, 1050000, 950000, 950000, 900000, 900000, 900000}, /* RESERVED */ {1050000, 1050000, 950000, 950000, 900000, 900000, 900000}, /* ASV2 */ {1050000, 1050000, 950000, 950000, 900000, 900000, 900000}, /* ASV3 */ {1050000, 1050000, 950000, 950000, 900000, 900000, 900000}, /* ASV4 */ {1000000, 1000000, 950000, 950000, 900000, 900000, 900000}, /* ASV5 */ {1000000, 1000000, 950000, 950000, 900000, 900000, 900000}, /* ASV6 */ {1000000, 1000000, 950000, 950000, 900000, 900000, 900000}, /* ASV7 */ {1000000, 1000000, 950000, 950000, 900000, 900000, 900000}, /* ASV8 */ {1000000, 1000000, 950000, 950000, 900000, 900000, 850000}, /* ASV9 */ {1000000, 1000000, 900000, 900000, 900000, 900000, 850000}, /* ASV10 */ {1000000, 1000000, 900000, 900000, 900000, 900000, 850000}, /* RESERVED */ }; static unsigned int exynos4412_int_volt[ASV_GROUP][LV_END] = { /* GDR : 266 200 200 160 160 133 100 */ {1112500, 1062500, 1062500, 975000, 975000, 937500, 900000}, /* RESERVED */ {1100000, 1050000, 1050000, 962500, 962500, 925000, 887500}, /* RESERVED */ {1075000, 1025000, 1025000, 937500, 937500, 912500, 875000}, /* ASV2 */ {1062500, 1012500, 1012500, 937500, 937500, 900000, 862500}, /* ASV3 */ {1062500, 1012500, 1012500, 925000, 925000, 900000, 862500}, /* ASV4 */ {1050000, 1000000, 1000000, 925000, 925000, 887500, 850000}, /* ASV5 */ {1050000, 1000000, 1000000, 912500, 912500, 875000, 850000}, /* ASV6 */ {1037500, 987500, 987500, 912500, 912500, 862500, 850000}, /* ASV7 */ {1037500, 987500, 987500, 900000, 900000, 862500, 850000}, /* ASV8 */ {1037500, 987500, 987500, 900000, 900000, 862500, 850000}, /* ASV9 */ {1037500, 987500, 987500, 900000, 900000, 862500, 850000}, /* ASV10 */ {1025000, 975000, 975000, 887500, 887500, 850000, 850000}, /* RESERVED */ }; /* 20120822 DVFS table for pega prime */ /* Because buck1 of pmic can be set to 50mV step size, 50mV table is used */ static unsigned int exynos4412_mif_volt_rev2[PRIME_ASV_GROUP][LV_END] = { /* 440 440 293 293 176 147 110 */ {1100000, 1100000, 1000000, 1000000, 950000, 950000, 950000}, /* RESERVED */ {1100000, 1100000, 1000000, 1000000, 950000, 950000, 950000}, /* ASV1 */ {1100000, 1100000, 1000000, 1000000, 950000, 950000, 900000}, /* ASV2 */ {1100000, 1100000, 1000000, 1000000, 950000, 900000, 900000}, /* ASV3 */ {1050000, 1050000, 950000, 950000, 900000, 900000, 900000}, /* ASV4 */ {1050000, 1050000, 950000, 950000, 900000, 900000, 900000}, /* ASV5 */ {1050000, 1050000, 950000, 950000, 900000, 900000, 900000}, /* ASV6 */ {1050000, 1050000, 950000, 950000, 900000, 900000, 850000}, /* ASV7 */ {1050000, 1050000, 950000, 950000, 900000, 850000, 850000}, /* ASV8 */ {1000000, 1000000, 900000, 900000, 850000, 850000, 850000}, /* ASV9 */ {1000000, 1000000, 900000, 900000, 850000, 850000, 850000}, /* ASV10 */ {1000000, 1000000, 900000, 900000, 850000, 850000, 850000}, /* ASV11 */ { 950000, 950000, 850000, 850000, 850000, 850000, 850000}, /* ASV12 */ }; /* 20120822 DVFS table for pega prime */ static unsigned int exynos4412_int_volt_rev2[PRIME_ASV_GROUP][LV_END] = { /* GDR : 293 220 220 176 176 147 110 */ {1087500, 1062500, 1062500, 1000000, 1000000, 962500, 950000}, /* RESERVED */ {1075000, 1050000, 1050000, 987500, 987500, 950000, 937500}, /* ASV1 */ {1062500, 1037500, 1037500, 975000, 975000, 937500, 912500}, /* ASV2 */ {1050000, 1037500, 1037500, 975000, 975000, 937500, 900000}, /* ASV3 */ {1037500, 1025000, 1025000, 962500, 962500, 925000, 887500}, /* ASV4 */ {1025000, 1012500, 1012500, 950000, 950000, 912500, 887500}, /* ASV5 */ {1012500, 1000000, 1000000, 937500, 937500, 900000, 887500}, /* ASV6 */ {1000000, 987500, 987500, 925000, 925000, 887500, 875000}, /* ASV7 */ {1037500, 975000, 975000, 912500, 912500, 875000, 875000}, /* ASV8 */ {1025000, 962500, 962500, 900000, 900000, 875000, 875000}, /* ASV9 */ {1012500, 937500, 937500, 875000, 875000, 850000, 850000}, /* ASV10 */ {1000000, 925000, 925000, 862500, 862500, 850000, 850000}, /* ASV11 */ {1000000, 912500, 912500, 850000, 850000, 850000, 850000}, /* ASV12 */ }; static unsigned int exynos4412_1ghz_mif_volt[ASV_GROUP][LV_END] = { /* 400 400 267 267 160 133 100 */ {1100000, 1100000, 1000000, 1000000, 950000, 950000, 950000}, /* RESERVED */ {1050000, 1050000, 1000000, 1000000, 950000, 950000, 950000}, /* RESERVED */ {1050000, 1050000, 1000000, 1000000, 950000, 950000, 950000}, /* ASV2 */ {1050000, 1050000, 1000000, 1000000, 950000, 950000, 950000}, /* ASV3 */ {1050000, 1050000, 950000, 950000, 900000, 900000, 900000}, /* ASV4 */ {1050000, 1050000, 950000, 950000, 900000, 900000, 900000}, /* ASV5 */ {1050000, 1050000, 950000, 950000, 900000, 900000, 900000}, /* ASV6 */ {1000000, 1000000, 950000, 950000, 900000, 900000, 900000}, /* ASV7 */ {1000000, 1000000, 950000, 950000, 900000, 900000, 900000}, /* ASV8 */ {1000000, 1000000, 950000, 950000, 900000, 900000, 900000}, /* ASV9 */ {1000000, 1000000, 950000, 950000, 900000, 900000, 900000}, /* ASV10 */ {1025000, 1025000, 925000, 925000, 925000, 925000, 875000}, /* RESERVED */ }; static unsigned int exynos4412_1ghz_int_volt[ASV_GROUP][LV_END] = { /* GDR : 266 200 200 160 160 133 100 */ {0, 1087500, 1087500, 1000000, 1000000, 975000, 950000}, /* RESERVED */ {0, 1050000, 1050000, 1000000, 1000000, 975000, 950000}, /* RESERVED */ {0, 1050000, 1050000, 1000000, 1000000, 975000, 950000}, /* ASV2 */ {0, 1050000, 1050000, 1000000, 1000000, 975000, 950000}, /* ASV3 */ {0, 1037500, 1037500, 950000, 950000, 925000, 900000}, /* ASV4 */ {0, 1037500, 1037500, 950000, 950000, 925000, 900000}, /* ASV5 */ {0, 1037500, 1037500, 950000, 950000, 925000, 900000}, /* ASV6 */ {0, 1012500, 1012500, 937500, 937500, 887500, 875000}, /* ASV7 */ {0, 1012500, 1012500, 937500, 937500, 887500, 875000}, /* ASV8 */ {0, 1012500, 1012500, 937500, 937500, 887500, 875000}, /* ASV9 */ {0, 1012500, 1012500, 937500, 937500, 887500, 875000}, /* ASV10 */ {0, 1000000, 1000000, 912500, 912500, 875000, 875000}, /* RESERVED */ }; static unsigned int exynos4x12_timingrow[LV_END] = { 0x34498691, 0x34498691, 0x24488490, 0x24488490, 0x154882D0, 0x154882D0, 0x0D488210 }; static unsigned int clkdiv_dmc0[LV_END][6] = { /* * Clock divider value for following * { DIVACP, DIVACP_PCLK, DIVDPHY, DIVDMC, DIVDMCD * DIVDMCP} */ /* DMC L0: 400MHz */ {3, 1, 1, 1, 1, 1}, /* DMC L1: 400MHz */ {3, 1, 1, 1, 1, 1}, /* DMC L2: 266.7MHz */ {4, 1, 1, 2, 1, 1}, /* DMC L3: 266.7MHz */ {4, 1, 1, 2, 1, 1}, /* DMC L4: 160MHz */ {5, 1, 1, 4, 1, 1}, /* DMC L5: 133MHz */ {5, 1, 1, 5, 1, 1}, /* DMC L6: 100MHz */ {7, 1, 1, 7, 1, 1}, }; static unsigned int clkdiv_dmc1[LV_END][6] = { /* * Clock divider value for following * { G2DACP, DIVC2C, DIVC2C_ACLK } */ /* DMC L0: 400MHz */ {3, 1, 1}, /* DMC L1: 400MHz */ {3, 1, 1}, /* DMC L2: 266.7MHz */ {4, 2, 1}, /* DMC L3: 266.7MHz */ {4, 2, 1}, /* DMC L4: 160MHz */ {5, 4, 1}, /* DMC L5: 133MHz */ {5, 5, 1}, /* DMC L6: 100MHz */ {7, 7, 1}, }; static unsigned int clkdiv_top[LV_END][5] = { /* * Clock divider value for following * { DIVACLK266_GPS, DIVACLK100, DIVACLK160, DIVACLK133, DIVONENAND } */ /* ACLK_GDL/R L0: 266MHz */ {2, 7, 4, 5, 1}, /* ACLK_GDL/R L1: 200MHz */ {2, 7, 4, 5, 1}, /* ACLK_GDL/R L2: 200MHz */ {2, 7, 4, 5, 1}, /* ACLK_GDL/R L3: 160MHz */ {4, 7, 5, 7, 1}, /* ACLK_GDL/R L4: 160MHz */ {4, 7, 5, 7, 1}, /* ACLK_GDL/R L5: 133MHz */ {5, 7, 5, 7, 1}, /* ACLK_GDL/R L6: 100MHz */ {7, 7, 7, 7, 1}, }; static unsigned int clkdiv_l_bus[LV_END][2] = { /* * Clock divider value for following * { DIVGDL, DIVGPL } */ /* ACLK_GDL L0: 200MHz */ {3, 1}, /* ACLK_GDL L1: 200MHz */ {3, 1}, /* ACLK_GDL L2: 200MHz */ {3, 1}, /* ACLK_GDL L3: 160MHz */ {4, 1}, /* ACLK_GDL L4: 160MHz */ {4, 1}, /* ACLK_GDL L5: 133MHz */ {5, 1}, /* ACLK_GDL L6: 100MHz */ {7, 1}, }; static unsigned int clkdiv_r_bus[LV_END][2] = { /* * Clock divider value for following * { DIVGDR, DIVGPR } */ /* ACLK_GDR L0: 266MHz */ {2, 1}, /* ACLK_GDR L1: 200MHz */ {3, 1}, /* ACLK_GDR L2: 200MHz */ {3, 1}, /* ACLK_GDR L3: 160MHz */ {4, 1}, /* ACLK_GDR L4: 160MHz */ {4, 1}, /* ACLK_GDR L5: 133MHz */ {5, 1}, /* ACLK_GDR L6: 100MHz */ {7, 1}, }; static unsigned int clkdiv_sclkip[LV_END][3] = { /* * Clock divider value for following * { DIVMFC, DIVJPEG, DIVFIMC0~3} */ /* SCLK_MFC: 200MHz */ {3, 3, 4}, /* SCLK_MFC: 200MHz */ {3, 3, 4}, /* SCLK_MFC: 200MHz */ {3, 3, 4}, /* SCLK_MFC: 160MHz */ {4, 4, 5}, /* SCLK_MFC: 160MHz */ {4, 4, 5}, /* SCLK_MFC: 133MHz */ {5, 5, 5}, /* SCLK_MFC: 100MHz */ {7, 7, 7}, }; static void exynos4x12_set_bus_volt(void) { unsigned int i; asv_group_index = exynos_result_of_asv; if (asv_group_index == 0xff) asv_group_index = 0; if ((is_special_flag() >> MIF_LOCK_FLAG) & 0x1) mif_locking = true; if ((is_special_flag() >> INT_LOCK_FLAG) & 0x1) int_locking = true; printk(KERN_INFO "DVFS : VDD_INT Voltage table set with %d Group\n", asv_group_index); for (i = 0 ; i < LV_END ; i++) { exynos4_busfreq_table[i].volt = exynos4_mif_volt[asv_group_index][i]; if (mif_locking) exynos4_busfreq_table[i].volt += 50000; if (int_locking) exynos4_int_volt[asv_group_index][i] += 25000; } return; } void exynos4x12_target(int index) { unsigned int tmp; /* Change Divider - DMC0 */ tmp = exynos4_busfreq_table[index].clk_dmc0div; __raw_writel(tmp, EXYNOS4_CLKDIV_DMC0); do { tmp = __raw_readl(EXYNOS4_CLKDIV_STAT_DMC0); } while (tmp & 0x111111); /* Change Divider - DMC1 */ tmp = __raw_readl(EXYNOS4_CLKDIV_DMC1); tmp &= ~(EXYNOS4_CLKDIV_DMC1_G2D_ACP_MASK | EXYNOS4_CLKDIV_DMC1_C2C_MASK | EXYNOS4_CLKDIV_DMC1_C2CACLK_MASK); tmp |= ((clkdiv_dmc1[index][0] << EXYNOS4_CLKDIV_DMC1_G2D_ACP_SHIFT) | (clkdiv_dmc1[index][1] << EXYNOS4_CLKDIV_DMC1_C2C_SHIFT) | (clkdiv_dmc1[index][2] << EXYNOS4_CLKDIV_DMC1_C2CACLK_SHIFT)); __raw_writel(tmp, EXYNOS4_CLKDIV_DMC1); do { tmp = __raw_readl(EXYNOS4_CLKDIV_STAT_DMC1); } while (tmp & 0x1011); /* Change Divider - TOP */ tmp = __raw_readl(EXYNOS4_CLKDIV_TOP); tmp &= ~(EXYNOS4_CLKDIV_TOP_ACLK266_GPS_MASK | EXYNOS4_CLKDIV_TOP_ACLK100_MASK | EXYNOS4_CLKDIV_TOP_ACLK160_MASK | EXYNOS4_CLKDIV_TOP_ACLK133_MASK | EXYNOS4_CLKDIV_TOP_ONENAND_MASK); tmp |= ((clkdiv_top[index][0] << EXYNOS4_CLKDIV_TOP_ACLK266_GPS_SHIFT) | (clkdiv_top[index][1] << EXYNOS4_CLKDIV_TOP_ACLK100_SHIFT) | (clkdiv_top[index][2] << EXYNOS4_CLKDIV_TOP_ACLK160_SHIFT) | (clkdiv_top[index][3] << EXYNOS4_CLKDIV_TOP_ACLK133_SHIFT) | (clkdiv_top[index][4] << EXYNOS4_CLKDIV_TOP_ONENAND_SHIFT)); __raw_writel(tmp, EXYNOS4_CLKDIV_TOP); do { tmp = __raw_readl(EXYNOS4_CLKDIV_STAT_TOP); } while (tmp & 0x11111); /* Change Divider - LEFTBUS */ tmp = __raw_readl(EXYNOS4_CLKDIV_LEFTBUS); tmp &= ~(EXYNOS4_CLKDIV_BUS_GDLR_MASK | EXYNOS4_CLKDIV_BUS_GPLR_MASK); tmp |= ((clkdiv_l_bus[index][0] << EXYNOS4_CLKDIV_BUS_GDLR_SHIFT) | (clkdiv_l_bus[index][1] << EXYNOS4_CLKDIV_BUS_GPLR_SHIFT)); __raw_writel(tmp, EXYNOS4_CLKDIV_LEFTBUS); do { tmp = __raw_readl(EXYNOS4_CLKDIV_STAT_LEFTBUS); } while (tmp & 0x11); /* Change Divider - RIGHTBUS */ tmp = __raw_readl(EXYNOS4_CLKDIV_RIGHTBUS); tmp &= ~(EXYNOS4_CLKDIV_BUS_GDLR_MASK | EXYNOS4_CLKDIV_BUS_GPLR_MASK); tmp |= ((clkdiv_r_bus[index][0] << EXYNOS4_CLKDIV_BUS_GDLR_SHIFT) | (clkdiv_r_bus[index][1] << EXYNOS4_CLKDIV_BUS_GPLR_SHIFT)); __raw_writel(tmp, EXYNOS4_CLKDIV_RIGHTBUS); do { tmp = __raw_readl(EXYNOS4_CLKDIV_STAT_RIGHTBUS); } while (tmp & 0x11); /* Change Divider - MFC */ tmp = __raw_readl(EXYNOS4_CLKDIV_MFC); tmp &= ~(EXYNOS4_CLKDIV_MFC_MASK); tmp |= ((clkdiv_sclkip[index][0] << EXYNOS4_CLKDIV_MFC_SHIFT)); __raw_writel(tmp, EXYNOS4_CLKDIV_MFC); do { tmp = __raw_readl(EXYNOS4_CLKDIV_STAT_MFC); } while (tmp & 0x1); /* Change Divider - JPEG */ tmp = __raw_readl(EXYNOS4_CLKDIV_CAM1); tmp &= ~(EXYNOS4_CLKDIV_CAM1_JPEG_MASK); tmp |= ((clkdiv_sclkip[index][1] << EXYNOS4_CLKDIV_CAM1_JPEG_SHIFT)); __raw_writel(tmp, EXYNOS4_CLKDIV_CAM1); do { tmp = __raw_readl(EXYNOS4_CLKDIV_STAT_CAM1); } while (tmp & 0x1); /* Change Divider - FIMC0~3 */ tmp = __raw_readl(EXYNOS4_CLKDIV_CAM); tmp &= ~(EXYNOS4_CLKDIV_CAM_FIMC0_MASK | EXYNOS4_CLKDIV_CAM_FIMC1_MASK | EXYNOS4_CLKDIV_CAM_FIMC2_MASK | EXYNOS4_CLKDIV_CAM_FIMC3_MASK); tmp |= ((clkdiv_sclkip[index][2] << EXYNOS4_CLKDIV_CAM_FIMC0_SHIFT) | (clkdiv_sclkip[index][2] << EXYNOS4_CLKDIV_CAM_FIMC1_SHIFT) | (clkdiv_sclkip[index][2] << EXYNOS4_CLKDIV_CAM_FIMC2_SHIFT) | (clkdiv_sclkip[index][2] << EXYNOS4_CLKDIV_CAM_FIMC3_SHIFT)); __raw_writel(tmp, EXYNOS4_CLKDIV_CAM); do { tmp = __raw_readl(EXYNOS4_CLKDIV_STAT_CAM1); } while (tmp & 0x1111); /* if pega-prime, ABB value is not changed */ if (samsung_rev() >= EXYNOS4412_REV_2_0) return; /* ABB value is changed in below case */ if (soc_is_exynos4412() && (exynos_result_of_asv > 3)) { if (index == LV_6) { /* MIF:100 / INT:100 */ exynos4x12_set_abb_member(ABB_INT, ABB_MODE_100V); exynos4x12_set_abb_member(ABB_MIF, ABB_MODE_100V); } else { exynos4x12_set_abb_member(ABB_INT, ABB_MODE_130V); exynos4x12_set_abb_member(ABB_MIF, ABB_MODE_130V); } } } unsigned int exynos4x12_get_table_index(struct opp *opp) { unsigned int index; for (index = LV_0; index < LV_END; index++) if (opp_get_freq(opp) == exynos4_busfreq_table[index].mem_clk) break; return index; } void exynos4x12_prepare(unsigned int index) { unsigned int timing0 = 0; #ifdef CONFIG_ARM_TRUSTZONE exynos_smc_readsfr(EXYNOS4_PA_DMC0_4212 + TIMINGROW_OFFSET, &timing0); timing0 |= exynos4x12_timingrow[index]; exynos_smc(SMC_CMD_REG, SMC_REG_ID_SFR_W(EXYNOS4_PA_DMC0_4212 + TIMINGROW_OFFSET), timing0, 0); exynos_smc(SMC_CMD_REG, SMC_REG_ID_SFR_W(EXYNOS4_PA_DMC0_4212 + TIMINGROW_OFFSET), exynos4x12_timingrow[index], 0); exynos_smc(SMC_CMD_REG, SMC_REG_ID_SFR_W(EXYNOS4_PA_DMC1_4212 + TIMINGROW_OFFSET), timing0, 0); exynos_smc(SMC_CMD_REG, SMC_REG_ID_SFR_W(EXYNOS4_PA_DMC1_4212 + TIMINGROW_OFFSET), exynos4x12_timingrow[index], 0); #else timing0 = __raw_readl(S5P_VA_DMC0 + TIMINGROW_OFFSET); timing0 |= exynos4x12_timingrow[index]; __raw_writel(timing0, S5P_VA_DMC0 + TIMINGROW_OFFSET); __raw_writel(exynos4x12_timingrow[index], S5P_VA_DMC0 + TIMINGROW_OFFSET); __raw_writel(timing0, S5P_VA_DMC1 + TIMINGROW_OFFSET); __raw_writel(exynos4x12_timingrow[index], S5P_VA_DMC1 + TIMINGROW_OFFSET); #endif } void exynos4x12_post(unsigned int index) { unsigned int timing0 = 0; #ifdef CONFIG_ARM_TRUSTZONE exynos_smc_readsfr(EXYNOS4_PA_DMC0_4212 + TIMINGROW_OFFSET, &timing0); timing0 |= exynos4x12_timingrow[index]; exynos_smc(SMC_CMD_REG, SMC_REG_ID_SFR_W(EXYNOS4_PA_DMC0_4212 + TIMINGROW_OFFSET), timing0, 0); exynos_smc(SMC_CMD_REG, SMC_REG_ID_SFR_W(EXYNOS4_PA_DMC0_4212 + TIMINGROW_OFFSET), exynos4x12_timingrow[index], 0); exynos_smc(SMC_CMD_REG, SMC_REG_ID_SFR_W(EXYNOS4_PA_DMC1_4212 + TIMINGROW_OFFSET), timing0, 0); exynos_smc(SMC_CMD_REG, SMC_REG_ID_SFR_W(EXYNOS4_PA_DMC1_4212 + TIMINGROW_OFFSET), exynos4x12_timingrow[index], 0); #else timing0 = __raw_readl(S5P_VA_DMC0 + TIMINGROW_OFFSET); timing0 |= exynos4x12_timingrow[index]; __raw_writel(timing0, S5P_VA_DMC0 + TIMINGROW_OFFSET); __raw_writel(exynos4x12_timingrow[index], S5P_VA_DMC0 + TIMINGROW_OFFSET); __raw_writel(timing0, S5P_VA_DMC1 + TIMINGROW_OFFSET); __raw_writel(exynos4x12_timingrow[index], S5P_VA_DMC1 + TIMINGROW_OFFSET); #endif } void exynos4x12_set_qos(unsigned int index) { __raw_writel(exynos4_qos_value[busfreq_qos][index][0], S5P_VA_GDL + 0x400); __raw_writel(exynos4_qos_value[busfreq_qos][index][1], S5P_VA_GDL + 0x404); __raw_writel(exynos4_qos_value[busfreq_qos][index][2], S5P_VA_GDR + 0x400); __raw_writel(exynos4_qos_value[busfreq_qos][index][3], S5P_VA_GDR + 0x404); } void exynos4x12_suspend(void) { /* Nothing to do */ } void exynos4x12_resume(void) { __raw_writel(dmc_pause_ctrl, EXYNOS4_DMC_PAUSE_CTRL); } /** * exynos4x12_find_busfreq_by_volt - find busfreq by requested * voltage. * * This function finds the busfreq to set for voltage above req_volt * and return its value. */ int exynos4x12_find_busfreq_by_volt(unsigned int req_volt, unsigned int *freq) { unsigned int volt_cmp; int i; /* check if req_volt has value or not */ if (!req_volt) { pr_err("%s: req_volt has no value.\n", __func__); return -EINVAL; } /* find busfreq level in busfreq_table */ for (i = LV_END - 1; i >= 0; i--) { volt_cmp = min(exynos4_int_volt[asv_group_index][i], exynos4_mif_volt[asv_group_index][i]); if (volt_cmp >= req_volt) { *freq = exynos4_busfreq_table[i].mem_clk; return 0; } } pr_err("%s: %u volt can't support\n", __func__, req_volt); return -EINVAL; } EXPORT_SYMBOL_GPL(exynos4x12_find_busfreq_by_volt); unsigned int exynos4x12_get_int_volt(unsigned long index) { return exynos4_int_volt[asv_group_index][index]; } struct opp *exynos4x12_monitor(struct busfreq_data *data) { struct opp *opp = data->curr_opp; int i; unsigned int cpu_load_average = 0; unsigned int dmc0_load_average = 0; unsigned int dmc1_load_average = 0; unsigned int dmc_load_average; unsigned long cpufreq = 0; unsigned long lockfreq; unsigned long dmcfreq; unsigned long newfreq; unsigned long currfreq = opp_get_freq(data->curr_opp) / 1000; unsigned long maxfreq = opp_get_freq(data->max_opp) / 1000; unsigned long cpu_load; unsigned long dmc0_load; unsigned long dmc1_load; unsigned long dmc_load; int cpu_load_slope; ppmu_update(data->dev, 3); /* Convert from base xxx to base maxfreq */ cpu_load = ppmu_load[PPMU_CPU]; dmc0_load = div64_u64(ppmu_load[PPMU_DMC0] * currfreq, maxfreq); dmc1_load = div64_u64(ppmu_load[PPMU_DMC1] * currfreq, maxfreq); cpu_load_slope = cpu_load - data->load_history[PPMU_CPU] [data->index ? data->index - 1 : load_history_size - 1]; data->load_history[PPMU_CPU][data->index] = cpu_load; data->load_history[PPMU_DMC0][data->index] = dmc0_load; data->load_history[PPMU_DMC1][data->index++] = dmc1_load; if (data->index >= load_history_size) data->index = 0; for (i = 0; i < load_history_size; i++) { cpu_load_average += data->load_history[PPMU_CPU][i]; dmc0_load_average += data->load_history[PPMU_DMC0][i]; dmc1_load_average += data->load_history[PPMU_DMC1][i]; } /* Calculate average Load */ cpu_load_average /= load_history_size; dmc0_load_average /= load_history_size; dmc1_load_average /= load_history_size; if (dmc0_load >= dmc1_load) { dmc_load = dmc0_load; dmc_load_average = dmc0_load_average; } else { dmc_load = dmc1_load; dmc_load_average = dmc1_load_average; } if (cpu_load >= up_cpu_threshold) { cpufreq = opp_get_freq(data->max_opp); if (cpu_load < max_cpu_threshold) { opp = data->curr_opp; if (cpu_load_slope > cpu_slope_size) { cpufreq--; opp = opp_find_freq_floor(data->dev, &cpufreq); } cpufreq = opp_get_freq(opp); } } if (dmc_load >= dmc_max_threshold) { dmcfreq = opp_get_freq(data->max_opp); } else if (dmc_load < idle_threshold) { if (dmc_load_average < idle_threshold) opp = step_down(data, 1); else opp = data->curr_opp; dmcfreq = opp_get_freq(opp); } else { if (dmc_load < dmc_load_average) { dmc_load = dmc_load_average; if (dmc_load >= dmc_max_threshold) dmc_load = dmc_max_threshold; } dmcfreq = div64_u64(maxfreq * dmc_load * 1000, dmc_max_threshold); } lockfreq = dev_max_freq(data->dev); newfreq = max3(lockfreq, dmcfreq, cpufreq); if (samsung_rev() < EXYNOS4412_REV_1_0) newfreq = opp_get_freq(data->max_opp); pr_debug("curfreq %ld, newfreq %ld, dmc0_load %ld, dmc1_load %ld, cpu_load %ld\n", currfreq, newfreq, dmc0_load, dmc1_load, cpu_load); opp = opp_find_freq_ceil(data->dev, &newfreq); if (IS_ERR(opp)) opp = data->max_opp; return opp; } static int exynos4x12_bus_qos_notifiy(struct notifier_block *nb, unsigned long l, void *v) { struct busfreq_data *bus_data = container_of(nb, struct busfreq_data, exynos_busqos_notifier); busfreq_qos = (int)l; exynos4x12_set_qos(bus_data->get_table_index(bus_data->curr_opp)); return NOTIFY_OK; } static inline void exynos4x12_bus_qos_notifier_init(struct notifier_block *n) { pm_qos_add_notifier(PM_QOS_BUS_QOS, n); } #define ARM_INT_CORRECTION 160160 static int exynos4x12_busfreq_cpufreq_transition(struct notifier_block *nb, unsigned long val, void *data) { struct cpufreq_freqs *freqs = (struct cpufreq_freqs *)data; struct busfreq_data *bus_data = container_of(nb, struct busfreq_data, exynos_cpufreq_notifier); switch (val) { case CPUFREQ_PRECHANGE: if (freqs->new > 900000 && freqs->old < 1000000) dev_lock(bus_data->dev, bus_data->dev, ARM_INT_CORRECTION); break; case CPUFREQ_POSTCHANGE: if (freqs->old > 900000 && freqs->new < 1000000) dev_unlock(bus_data->dev, bus_data->dev); break; } return NOTIFY_DONE; } int exynos4x12_init(struct device *dev, struct busfreq_data *data) { unsigned int i; unsigned int tmp; unsigned long maxfreq = 400200; unsigned long minfreq = 0; unsigned long freq; struct clk *sclk_dmc; int ret; if (soc_is_exynos4412() && samsung_rev() >= EXYNOS4412_REV_2_0) { exynos4_busfreq_table = exynos4_busfreq_table_rev2; exynos4_qos_value = exynos4_qos_value_rev2; } else { exynos4_busfreq_table = exynos4_busfreq_table_orig; exynos4_qos_value = exynos4_qos_value_orig; } if (soc_is_exynos4212()) { exynos4_mif_volt = exynos4212_mif_volt; exynos4_int_volt = exynos4212_int_volt; dmc_max_threshold = EXYNOS4212_DMC_MAX_THRESHOLD; } else if (soc_is_exynos4412()) { #ifdef CONFIG_EXYNOS4X12_1000MHZ_SUPPORT exynos4_mif_volt = exynos4412_1ghz_mif_volt; exynos4_int_volt = exynos4412_1ghz_int_volt; #else if (samsung_rev() >= EXYNOS4412_REV_2_0) { exynos4_mif_volt = exynos4412_mif_volt_rev2; exynos4_int_volt = exynos4412_int_volt_rev2; dmc_max_threshold = PRIME_DMC_MAX_THRESHOLD; } else if (exynos_armclk_max == 1000000) { exynos4_mif_volt = exynos4412_1ghz_mif_volt; exynos4_int_volt = exynos4412_1ghz_int_volt; dmc_max_threshold = EXYNOS4412_DMC_MAX_THRESHOLD; } else { exynos4_mif_volt = exynos4412_mif_volt; exynos4_int_volt = exynos4412_int_volt; dmc_max_threshold = EXYNOS4412_DMC_MAX_THRESHOLD; } #endif } else { pr_err("Unsupported model.\n"); return -EINVAL; } /* Enable pause function for DREX2 DVFS */ dmc_pause_ctrl = __raw_readl(EXYNOS4_DMC_PAUSE_CTRL); dmc_pause_ctrl |= DMC_PAUSE_ENABLE; __raw_writel(dmc_pause_ctrl, EXYNOS4_DMC_PAUSE_CTRL); tmp = __raw_readl(EXYNOS4_CLKDIV_DMC0); for (i = 0; i < LV_END; i++) { tmp &= ~(EXYNOS4_CLKDIV_DMC0_ACP_MASK | EXYNOS4_CLKDIV_DMC0_ACPPCLK_MASK | EXYNOS4_CLKDIV_DMC0_DPHY_MASK | EXYNOS4_CLKDIV_DMC0_DMC_MASK | EXYNOS4_CLKDIV_DMC0_DMCD_MASK | EXYNOS4_CLKDIV_DMC0_DMCP_MASK); tmp |= ((clkdiv_dmc0[i][0] << EXYNOS4_CLKDIV_DMC0_ACP_SHIFT) | (clkdiv_dmc0[i][1] << EXYNOS4_CLKDIV_DMC0_ACPPCLK_SHIFT) | (clkdiv_dmc0[i][2] << EXYNOS4_CLKDIV_DMC0_DPHY_SHIFT) | (clkdiv_dmc0[i][3] << EXYNOS4_CLKDIV_DMC0_DMC_SHIFT) | (clkdiv_dmc0[i][4] << EXYNOS4_CLKDIV_DMC0_DMCD_SHIFT) | (clkdiv_dmc0[i][5] << EXYNOS4_CLKDIV_DMC0_DMCP_SHIFT)); exynos4_busfreq_table[i].clk_dmc0div = tmp; } exynos4x12_set_bus_volt(); for (i = 0; i < LV_END; i++) { ret = opp_add(dev, exynos4_busfreq_table[i].mem_clk, exynos4_busfreq_table[i].volt); if (ret) { dev_err(dev, "Fail to add opp entries.\n"); return ret; } } if (samsung_rev() >= EXYNOS4412_REV_2_0) { opp_disable(dev, 440293); maxfreq = 440220; } else { /* opp_disable(dev, 267200); */ } data->table = exynos4_busfreq_table; data->table_size = LV_END; /* Find max frequency */ data->max_opp = opp_find_freq_floor(dev, &maxfreq); data->min_opp = opp_find_freq_ceil(dev, &minfreq); sclk_dmc = clk_get(NULL, "sclk_dmc"); if (IS_ERR(sclk_dmc)) { pr_err("Failed to get sclk_dmc.!\n"); data->curr_opp = data->max_opp; } else { freq = clk_get_rate(sclk_dmc) / 1000; clk_put(sclk_dmc); data->curr_opp = opp_find_freq_ceil(dev, &freq); } data->vdd_int = regulator_get(NULL, "vdd_int"); if (IS_ERR(data->vdd_int)) { pr_err("failed to get resource %s\n", "vdd_int"); return -ENODEV; } data->vdd_mif = regulator_get(NULL, "vdd_mif"); if (IS_ERR(data->vdd_mif)) { pr_err("failed to get resource %s\n", "vdd_mif"); regulator_put(data->vdd_int); return -ENODEV; } data->exynos_cpufreq_notifier.notifier_call = exynos4x12_busfreq_cpufreq_transition; if (cpufreq_register_notifier(&data->exynos_cpufreq_notifier, CPUFREQ_TRANSITION_NOTIFIER)) pr_err("Falied to register cpufreq notifier\n"); data->exynos_busqos_notifier.notifier_call = exynos4x12_bus_qos_notifiy; exynos4x12_bus_qos_notifier_init(&data->exynos_busqos_notifier); return 0; }
gpl-2.0
kulv2012/linux-2.6.11
drivers/serial/crisv10.c
13
147780
/* $Id: serial.c,v 1.25 2004/09/29 10:33:49 starvik Exp $ * * Serial port driver for the ETRAX 100LX chip * * Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003 Axis Communications AB * * Many, many authors. Based once upon a time on serial.c for 16x50. * * $Log: serial.c,v $ * Revision 1.25 2004/09/29 10:33:49 starvik * Resolved a dealock when printing debug from kernel. * * Revision 1.24 2004/08/27 23:25:59 johana * rs_set_termios() must call change_speed() if c_iflag has changed or * automatic XOFF handling will be enabled and transmitter will stop * if 0x13 is received. * * Revision 1.23 2004/08/24 06:57:13 starvik * More whitespace cleanup * * Revision 1.22 2004/08/24 06:12:20 starvik * Whitespace cleanup * * Revision 1.20 2004/05/24 12:00:20 starvik * Big merge of stuff from Linux 2.4 (e.g. manual mode for the serial port). * * Revision 1.19 2004/05/17 13:12:15 starvik * Kernel console hook * Big merge from Linux 2.4 still pending. * * Revision 1.18 2003/10/28 07:18:30 starvik * Compiles with debug info * * Revision 1.17 2003/07/04 08:27:37 starvik * Merge of Linux 2.5.74 * * Revision 1.16 2003/06/13 10:05:19 johana * Help the user to avoid trouble by: * Forcing mixed mode for status/control lines if not all pins are used. * * Revision 1.15 2003/06/13 09:43:01 johana * Merged in the following changes from os/linux/arch/cris/drivers/serial.c * + some minor changes to reduce diff. * * Revision 1.49 2003/05/30 11:31:54 johana * Merged in change-branch--serial9bit that adds CMSPAR support for sticky * parity (mark/space) * * Revision 1.48 2003/05/30 11:03:57 johana * Implemented rs_send_xchar() by disabling the DMA and writing manually. * Added e100_disable_txdma_channel() and e100_enable_txdma_channel(). * Fixed rs_throttle() and rs_unthrottle() to properly call rs_send_xchar * instead of setting info->x_char and check the CRTSCTS flag before * controlling the rts pin. * * Revision 1.14 2003/04/09 08:12:44 pkj * Corrected typo changes made upstream. * * Revision 1.13 2003/04/09 05:20:47 starvik * Merge of Linux 2.5.67 * * Revision 1.11 2003/01/22 06:48:37 starvik * Fixed warnings issued by GCC 3.2.1 * * Revision 1.9 2002/12/13 09:07:47 starvik * Alert user that RX_TIMEOUT_TICKS==0 doesn't work * * Revision 1.8 2002/12/11 13:13:57 starvik * Added arch/ to v10 specific includes * Added fix from Linux 2.4 in serial.c (flush_to_flip_buffer) * * Revision 1.7 2002/12/06 07:13:57 starvik * Corrected work queue stuff * Removed CONFIG_ETRAX_SERIAL_FLUSH_DMA_FAST * * Revision 1.6 2002/11/21 07:17:46 starvik * Change static inline to extern inline where otherwise outlined with gcc-3.2 * * Revision 1.5 2002/11/14 15:59:49 starvik * Linux 2.5 port of the latest serial driver from 2.4. The work queue stuff * probably doesn't work yet. * * Revision 1.42 2002/11/05 09:08:47 johana * Better implementation of rs_stop() and rs_start() that uses the XOFF * register to start/stop transmission. * change_speed() also initilises XOFF register correctly so that * auto_xoff is enabled when IXON flag is set by user. * This gives fast XOFF response times. * * Revision 1.41 2002/11/04 18:40:57 johana * Implemented rs_stop() and rs_start(). * Simple tests using hwtestserial indicates that this should be enough * to make it work. * * Revision 1.40 2002/10/14 05:33:18 starvik * RS-485 uses fast timers even if SERIAL_FAST_TIMER is disabled * * Revision 1.39 2002/09/30 21:00:57 johana * Support for CONFIG_ETRAX_SERx_DTR_RI_DSR_CD_MIXED where the status and * control pins can be mixed between PA and PB. * If no serial port uses MIXED old solution is used * (saves a few bytes and cycles). * control_pins struct uses masks instead of bit numbers. * Corrected dummy values and polarity in line_info() so * /proc/tty/driver/serial is now correct. * (the E100_xxx_GET() macros is really active low - perhaps not obvious) * * Revision 1.38 2002/08/23 11:01:36 starvik * Check that serial port is enabled in all interrupt handlers to avoid * restarts of DMA channels not assigned to serial ports * * Revision 1.37 2002/08/13 13:02:37 bjornw * Removed some warnings because of unused code * * Revision 1.36 2002/08/08 12:50:01 starvik * Serial interrupt is shared with synchronous serial port driver * * Revision 1.35 2002/06/03 10:40:49 starvik * Increased RS-485 RTS toggle timer to 2 characters * * Revision 1.34 2002/05/28 18:59:36 johana * Whitespace and comment fixing to be more like etrax100ser.c 1.71. * * Revision 1.33 2002/05/28 17:55:43 johana * RS-485 uses FAST_TIMER if enabled, and starts a short (one char time) * timer from tranismit_chars (interrupt context). * The timer toggles RTS in interrupt context when expired giving minimum * latencies. * * Revision 1.32 2002/05/22 13:58:00 johana * Renamed rs_write() to raw_write() and made it inline. * New rs_write() handles RS-485 if configured and enabled * (moved code from e100_write_rs485()). * RS-485 ioctl's uses copy_from_user() instead of verify_area(). * * Revision 1.31 2002/04/22 11:20:03 johana * Updated copyright years. * * Revision 1.30 2002/04/22 09:39:12 johana * RS-485 support compiles. * * Revision 1.29 2002/01/14 16:10:01 pkj * Allocate the receive buffers dynamically. The static 4kB buffer was * too small for the peaks. This means that we can get rid of the extra * buffer and the copying to it. It also means we require less memory * under normal operations, but can use more when needed (there is a * cap at 64kB for safety reasons). If there is no memory available * we panic(), and die a horrible death... * * Revision 1.28 2001/12/18 15:04:53 johana * Cleaned up write_rs485() - now it works correctly without padding extra * char. * Added sane default initialisation of rs485. * Added #ifdef around dummy variables. * * Revision 1.27 2001/11/29 17:00:41 pkj * 2kB seems to be too small a buffer when using 921600 bps, * so increase it to 4kB (this was already done for the elinux * version of the serial driver). * * Revision 1.26 2001/11/19 14:20:41 pkj * Minor changes to comments and unused code. * * Revision 1.25 2001/11/12 20:03:43 pkj * Fixed compiler warnings. * * Revision 1.24 2001/11/12 15:10:05 pkj * Total redesign of the receiving part of the serial driver. * Uses eight chained descriptors to write to a 4kB buffer. * This data is then serialised into a 2kB buffer. From there it * is copied into the TTY's flip buffers when they become available. * A lot of copying, and the sizes of the buffers might need to be * tweaked, but all in all it should work better than the previous * version, without the need to modify the TTY code in any way. * Also note that erroneous bytes are now correctly marked in the * flag buffers (instead of always marking the first byte). * * Revision 1.23 2001/10/30 17:53:26 pkj * * Set info->uses_dma to 0 when a port is closed. * * Mark the timer1 interrupt as a fast one (SA_INTERRUPT). * * Call start_flush_timer() in start_receive() if * CONFIG_ETRAX_SERIAL_FLUSH_DMA_FAST is defined. * * Revision 1.22 2001/10/30 17:44:03 pkj * Use %lu for received and transmitted counters in line_info(). * * Revision 1.21 2001/10/30 17:40:34 pkj * Clean-up. The only change to functionality is that * CONFIG_ETRAX_SERIAL_RX_TIMEOUT_TICKS(=5) is used instead of * MAX_FLUSH_TIME(=8). * * Revision 1.20 2001/10/30 15:24:49 johana * Added char_time stuff from 2.0 driver. * * Revision 1.19 2001/10/30 15:23:03 johana * Merged with 1.13.2 branch + fixed indentation * and changed CONFIG_ETRAX100_XYS to CONFIG_ETRAX_XYZ * * Revision 1.18 2001/09/24 09:27:22 pkj * Completed ext_baud_table[] in cflag_to_baud() and cflag_to_etrax_baud(). * * Revision 1.17 2001/08/24 11:32:49 ronny * More fixes for the CONFIG_ETRAX_SERIAL_PORT0 define. * * Revision 1.16 2001/08/24 07:56:22 ronny * Added config ifdefs around ser0 irq requests. * * Revision 1.15 2001/08/16 09:10:31 bjarne * serial.c - corrected the initialization of rs_table, the wrong defines * where used. * Corrected a test in timed_flush_handler. * Changed configured to enabled. * serial.h - Changed configured to enabled. * * Revision 1.14 2001/08/15 07:31:23 bjarne * Introduced two new members to the e100_serial struct. * configured - Will be set to 1 if the port has been configured in .config * uses_dma - Should be set to 1 if the port uses DMA. Currently it is set * to 1 * when a port is opened. This is used to limit the DMA interrupt * routines to only manipulate DMA channels actually used by the * serial driver. * * Revision 1.13.2.2 2001/10/17 13:57:13 starvik * Receiver was broken by the break fixes * * Revision 1.13.2.1 2001/07/20 13:57:39 ronny * Merge with new stuff from etrax100ser.c. Works but haven't checked stuff * like break handling. * * Revision 1.13 2001/05/09 12:40:31 johana * Use DMA_NBR and IRQ_NBR defines from dma.h and irq.h * * Revision 1.12 2001/04/19 12:23:07 bjornw * CONFIG_RS485 -> CONFIG_ETRAX_RS485 * * Revision 1.11 2001/04/05 14:29:48 markusl * Updated according to review remarks i.e. * -Use correct types in port structure to avoid compiler warnings * -Try to use IO_* macros whenever possible * -Open should never return -EBUSY * * Revision 1.10 2001/03/05 13:14:07 bjornw * Another spelling fix * * Revision 1.9 2001/02/23 13:46:38 bjornw * Spellling check * * Revision 1.8 2001/01/23 14:56:35 markusl * Made use of ser1 optional * Needed by USB * * Revision 1.7 2001/01/19 16:14:48 perf * Added kernel options for serial ports 234. * Changed option names from CONFIG_ETRAX100_XYZ to CONFIG_ETRAX_XYZ. * * Revision 1.6 2000/11/22 16:36:09 bjornw * Please marketing by using the correct case when spelling Etrax. * * Revision 1.5 2000/11/21 16:43:37 bjornw * Fixed so it compiles under CONFIG_SVINTO_SIM * * Revision 1.4 2000/11/15 17:34:12 bjornw * Added a timeout timer for flushing input channels. The interrupt-based * fast flush system should be easy to merge with this later (works the same * way, only with an irq instead of a system timer_list) * * Revision 1.3 2000/11/13 17:19:57 bjornw * * Incredibly, this almost complete rewrite of serial.c worked (at least * for output) the first time. * * Items worth noticing: * * No Etrax100 port 1 workarounds (does only compile on 2.4 anyway now) * RS485 is not ported (why can't it be done in userspace as on x86 ?) * Statistics done through async_icount - if any more stats are needed, * that's the place to put them or in an arch-dep version of it. * timeout_interrupt and the other fast timeout stuff not ported yet * There be dragons in this 3k+ line driver * * Revision 1.2 2000/11/10 16:50:28 bjornw * First shot at a 2.4 port, does not compile totally yet * * Revision 1.1 2000/11/10 16:47:32 bjornw * Added verbatim copy of rev 1.49 etrax100ser.c from elinux * * Revision 1.49 2000/10/30 15:47:14 tobiasa * Changed version number. * * Revision 1.48 2000/10/25 11:02:43 johana * Changed %ul to %lu in printf's * * Revision 1.47 2000/10/18 15:06:53 pkj * Compile correctly with CONFIG_ETRAX_SERIAL_FLUSH_DMA_FAST and * CONFIG_ETRAX_SERIAL_PROC_ENTRY together. * Some clean-up of the /proc/serial file. * * Revision 1.46 2000/10/16 12:59:40 johana * Added CONFIG_ETRAX_SERIAL_PROC_ENTRY for statistics and debug info. * * Revision 1.45 2000/10/13 17:10:59 pkj * Do not flush DMAs while flipping TTY buffers. * * Revision 1.44 2000/10/13 16:34:29 pkj * Added a delay in ser_interrupt() for 2.3ms when an error is detected. * We do not know why this delay is required yet, but without it the * irmaflash program does not work (this was the program that needed * the ser_interrupt() to be needed in the first place). This should not * affect normal use of the serial ports. * * Revision 1.43 2000/10/13 16:30:44 pkj * New version of the fast flush of serial buffers code. This time * it is localized to the serial driver and uses a fast timer to * do the work. * * Revision 1.42 2000/10/13 14:54:26 bennyo * Fix for switching RTS when using rs485 * * Revision 1.41 2000/10/12 11:43:44 pkj * Cleaned up a number of comments. * * Revision 1.40 2000/10/10 11:58:39 johana * Made RS485 support generic for all ports. * Toggle rts in interrupt if no delay wanted. * WARNING: No true transmitter empty check?? * Set d_wait bit when sending data so interrupt is delayed until * fifo flushed. (Fix tcdrain() problem) * * Revision 1.39 2000/10/04 16:08:02 bjornw * * Use virt_to_phys etc. for DMA addresses * * Removed CONFIG_FLUSH_DMA_FAST hacks * * Indentation fix * * Revision 1.38 2000/10/02 12:27:10 mattias * * added variable used when using fast flush on serial dma. * (CONFIG_FLUSH_DMA_FAST) * * Revision 1.37 2000/09/27 09:44:24 pkj * Uncomment definition of SERIAL_HANDLE_EARLY_ERRORS. * * Revision 1.36 2000/09/20 13:12:52 johana * Support for CONFIG_ETRAX_SERIAL_RX_TIMEOUT_TICKS: * Number of timer ticks between flush of receive fifo (1 tick = 10ms). * Try 0-3 for low latency applications. Approx 5 for high load * applications (e.g. PPP). Maybe this should be more adaptive some day... * * Revision 1.35 2000/09/20 10:36:08 johana * Typo in get_lsr_info() * * Revision 1.34 2000/09/20 10:29:59 johana * Let rs_chars_in_buffer() check fifo content as well. * get_lsr_info() might work now (not tested). * Easier to change the port to debug. * * Revision 1.33 2000/09/13 07:52:11 torbjore * Support RS485 * * Revision 1.32 2000/08/31 14:45:37 bjornw * After sending a break we need to reset the transmit DMA channel * * Revision 1.31 2000/06/21 12:13:29 johana * Fixed wait for all chars sent when closing port. * (Used to always take 1 second!) * Added shadows for directions of status/ctrl signals. * * Revision 1.30 2000/05/29 16:27:55 bjornw * Simulator ifdef moved a bit * * Revision 1.29 2000/05/09 09:40:30 mattias * * Added description of dma registers used in timeout_interrupt * * Removed old code * * Revision 1.28 2000/05/08 16:38:58 mattias * * Bugfix for flushing fifo in timeout_interrupt * Problem occurs when bluetooth stack waits for a small number of bytes * containing an event acknowledging free buffers in bluetooth HW * As before, data was stuck in fifo until more data came on uart and * flushed it up to the stack. * * Revision 1.27 2000/05/02 09:52:28 jonasd * Added fix for peculiar etrax behaviour when eop is forced on an empty * fifo. This is used when flashing the IRMA chip. Disabled by default. * * Revision 1.26 2000/03/29 15:32:02 bjornw * 2.0.34 updates * * Revision 1.25 2000/02/16 16:59:36 bjornw * * Receive DMA directly into the flip-buffer, eliminating an intermediary * receive buffer and a memcpy. Will avoid some overruns. * * Error message on debug port if an overrun or flip buffer overrun occurs. * * Just use the first byte in the flag flip buffer for errors. * * Check for timeout on the serial ports only each 5/100 s, not 1/100. * * Revision 1.24 2000/02/09 18:02:28 bjornw * * Clear serial errors (overrun, framing, parity) correctly. Before, the * receiver would get stuck if an error occurred and we did not restart * the input DMA. * * Cosmetics (indentation, some code made into inlines) * * Some more debug options * * Actually shut down the serial port (DMA irq, DMA reset, receiver stop) * when the last open is closed. Corresponding fixes in startup(). * * rs_close() "tx FIFO wait" code moved into right place, bug & -> && fixed * and make a special case out of port 1 (R_DMA_CHx_STATUS is broken for that) * * e100_disable_rx/enable_rx just disables/enables the receiver, not RTS * * Revision 1.23 2000/01/24 17:46:19 johana * Wait for flush of DMA/FIFO when closing port. * * Revision 1.22 2000/01/20 18:10:23 johana * Added TIOCMGET ioctl to return modem status. * Implemented modem status/control that works with the extra signals * (DTR, DSR, RI,CD) as well. * 3 different modes supported: * ser0 on PB (Bundy), ser1 on PB (Lisa) and ser2 on PA (Bundy) * Fixed DEF_TX value that caused the serial transmitter pin (txd) to go to 0 when * closing the last filehandle, NASTY!. * Added break generation, not tested though! * Use SA_SHIRQ when request_irq() for ser2 and ser3 (shared with) par0 and par1. * You can't use them at the same time (yet..), but you can hopefully switch * between ser2/par0, ser3/par1 with the same kernel config. * Replaced some magic constants with defines * * */ static char *serial_version = "$Revision: 1.25 $"; #include <linux/config.h> #include <linux/version.h> #include <linux/types.h> #include <linux/errno.h> #include <linux/signal.h> #include <linux/sched.h> #include <linux/timer.h> #include <linux/interrupt.h> #include <linux/tty.h> #include <linux/tty_flip.h> #include <linux/major.h> #include <linux/string.h> #include <linux/fcntl.h> #include <linux/mm.h> #include <linux/slab.h> #include <linux/init.h> #include <asm/uaccess.h> #include <linux/kernel.h> #include <asm/io.h> #include <asm/irq.h> #include <asm/system.h> #include <asm/segment.h> #include <asm/bitops.h> #include <linux/delay.h> #include <asm/arch/svinto.h> /* non-arch dependent serial structures are in linux/serial.h */ #include <linux/serial.h> /* while we keep our own stuff (struct e100_serial) in a local .h file */ #include "serial.h" #include <asm/fasttimer.h> #ifdef CONFIG_ETRAX_SERIAL_FAST_TIMER #ifndef CONFIG_ETRAX_FAST_TIMER #error "Enable FAST_TIMER to use SERIAL_FAST_TIMER" #endif #endif #if defined(CONFIG_ETRAX_SERIAL_RX_TIMEOUT_TICKS) && \ (CONFIG_ETRAX_SERIAL_RX_TIMEOUT_TICKS == 0) #error "RX_TIMEOUT_TICKS == 0 not allowed, use 1" #endif #if defined(CONFIG_ETRAX_RS485_ON_PA) && defined(CONFIG_ETRAX_RS485_ON_PORT_G) #error "Disable either CONFIG_ETRAX_RS485_ON_PA or CONFIG_ETRAX_RS485_ON_PORT_G" #endif /* * All of the compatibilty code so we can compile serial.c against * older kernels is hidden in serial_compat.h */ #if defined(LOCAL_HEADERS) #include "serial_compat.h" #endif #define _INLINE_ inline struct tty_driver *serial_driver; /* serial subtype definitions */ #ifndef SERIAL_TYPE_NORMAL #define SERIAL_TYPE_NORMAL 1 #endif /* number of characters left in xmit buffer before we ask for more */ #define WAKEUP_CHARS 256 //#define SERIAL_DEBUG_INTR //#define SERIAL_DEBUG_OPEN //#define SERIAL_DEBUG_FLOW //#define SERIAL_DEBUG_DATA //#define SERIAL_DEBUG_THROTTLE //#define SERIAL_DEBUG_IO /* Debug for Extra control and status pins */ //#define SERIAL_DEBUG_LINE 0 /* What serport we want to debug */ /* Enable this to use serial interrupts to handle when you expect the first received event on the serial port to be an error, break or similar. Used to be able to flash IRMA from eLinux */ #define SERIAL_HANDLE_EARLY_ERRORS /* Defined and used in n_tty.c, but we need it here as well */ #define TTY_THRESHOLD_THROTTLE 128 /* Due to buffersizes and threshold values, our SERIAL_DESCR_BUF_SIZE * must not be to high or flow control won't work if we leave it to the tty * layer so we have our own throttling in flush_to_flip * TTY_FLIPBUF_SIZE=512, * TTY_THRESHOLD_THROTTLE/UNTHROTTLE=128 * BUF_SIZE can't be > 128 */ /* Currently 16 descriptors x 128 bytes = 2048 bytes */ #define SERIAL_DESCR_BUF_SIZE 256 #define SERIAL_PRESCALE_BASE 3125000 /* 3.125MHz */ #define DEF_BAUD_BASE SERIAL_PRESCALE_BASE /* We don't want to load the system with massive fast timer interrupt * on high baudrates so limit it to 250 us (4kHz) */ #define MIN_FLUSH_TIME_USEC 250 /* Add an x here to log a lot of timer stuff */ #define TIMERD(x) /* Debug details of interrupt handling */ #define DINTR1(x) /* irq on/off, errors */ #define DINTR2(x) /* tx and rx */ /* Debug flip buffer stuff */ #define DFLIP(x) /* Debug flow control and overview of data flow */ #define DFLOW(x) #define DBAUD(x) #define DLOG_INT_TRIG(x) //#define DEBUG_LOG_INCLUDED #ifndef DEBUG_LOG_INCLUDED #define DEBUG_LOG(line, string, value) #else struct debug_log_info { unsigned long time; unsigned long timer_data; // int line; const char *string; int value; }; #define DEBUG_LOG_SIZE 4096 struct debug_log_info debug_log[DEBUG_LOG_SIZE]; int debug_log_pos = 0; #define DEBUG_LOG(_line, _string, _value) do { \ if ((_line) == SERIAL_DEBUG_LINE) {\ debug_log_func(_line, _string, _value); \ }\ }while(0) void debug_log_func(int line, const char *string, int value) { if (debug_log_pos < DEBUG_LOG_SIZE) { debug_log[debug_log_pos].time = jiffies; debug_log[debug_log_pos].timer_data = *R_TIMER_DATA; // debug_log[debug_log_pos].line = line; debug_log[debug_log_pos].string = string; debug_log[debug_log_pos].value = value; debug_log_pos++; } /*printk(string, value);*/ } #endif #ifndef CONFIG_ETRAX_SERIAL_RX_TIMEOUT_TICKS /* Default number of timer ticks before flushing rx fifo * When using "little data, low latency applications: use 0 * When using "much data applications (PPP)" use ~5 */ #define CONFIG_ETRAX_SERIAL_RX_TIMEOUT_TICKS 5 #endif unsigned long timer_data_to_ns(unsigned long timer_data); static void change_speed(struct e100_serial *info); static void rs_throttle(struct tty_struct * tty); static void rs_wait_until_sent(struct tty_struct *tty, int timeout); static int rs_write(struct tty_struct * tty, int from_user, const unsigned char *buf, int count); extern _INLINE_ int rs_raw_write(struct tty_struct * tty, int from_user, const unsigned char *buf, int count); #ifdef CONFIG_ETRAX_RS485 static int e100_write_rs485(struct tty_struct * tty, int from_user, const unsigned char *buf, int count); #endif static int get_lsr_info(struct e100_serial * info, unsigned int *value); #define DEF_BAUD 115200 /* 115.2 kbit/s */ #define STD_FLAGS (ASYNC_BOOT_AUTOCONF | ASYNC_SKIP_TEST) #define DEF_RX 0x20 /* or SERIAL_CTRL_W >> 8 */ /* Default value of tx_ctrl register: has txd(bit 7)=1 (idle) as default */ #define DEF_TX 0x80 /* or SERIAL_CTRL_B */ /* offsets from R_SERIALx_CTRL */ #define REG_DATA 0 #define REG_DATA_STATUS32 0 /* this is the 32 bit register R_SERIALx_READ */ #define REG_TR_DATA 0 #define REG_STATUS 1 #define REG_TR_CTRL 1 #define REG_REC_CTRL 2 #define REG_BAUD 3 #define REG_XOFF 4 /* this is a 32 bit register */ /* The bitfields are the same for all serial ports */ #define SER_RXD_MASK IO_MASK(R_SERIAL0_STATUS, rxd) #define SER_DATA_AVAIL_MASK IO_MASK(R_SERIAL0_STATUS, data_avail) #define SER_FRAMING_ERR_MASK IO_MASK(R_SERIAL0_STATUS, framing_err) #define SER_PAR_ERR_MASK IO_MASK(R_SERIAL0_STATUS, par_err) #define SER_OVERRUN_MASK IO_MASK(R_SERIAL0_STATUS, overrun) #define SER_ERROR_MASK (SER_OVERRUN_MASK | SER_PAR_ERR_MASK | SER_FRAMING_ERR_MASK) /* Values for info->errorcode */ #define ERRCODE_SET_BREAK (TTY_BREAK) #define ERRCODE_INSERT 0x100 #define ERRCODE_INSERT_BREAK (ERRCODE_INSERT | TTY_BREAK) #define FORCE_EOP(info) *R_SET_EOP = 1U << info->iseteop; /* * General note regarding the use of IO_* macros in this file: * * We will use the bits defined for DMA channel 6 when using various * IO_* macros (e.g. IO_STATE, IO_MASK, IO_EXTRACT) and _assume_ they are * the same for all channels (which of course they are). * * We will also use the bits defined for serial port 0 when writing commands * to the different ports, as these bits too are the same for all ports. */ /* Mask for the irqs possibly enabled in R_IRQ_MASK1_RD etc. */ static const unsigned long e100_ser_int_mask = 0 #ifdef CONFIG_ETRAX_SERIAL_PORT0 | IO_MASK(R_IRQ_MASK1_RD, ser0_data) | IO_MASK(R_IRQ_MASK1_RD, ser0_ready) #endif #ifdef CONFIG_ETRAX_SERIAL_PORT1 | IO_MASK(R_IRQ_MASK1_RD, ser1_data) | IO_MASK(R_IRQ_MASK1_RD, ser1_ready) #endif #ifdef CONFIG_ETRAX_SERIAL_PORT2 | IO_MASK(R_IRQ_MASK1_RD, ser2_data) | IO_MASK(R_IRQ_MASK1_RD, ser2_ready) #endif #ifdef CONFIG_ETRAX_SERIAL_PORT3 | IO_MASK(R_IRQ_MASK1_RD, ser3_data) | IO_MASK(R_IRQ_MASK1_RD, ser3_ready) #endif ; unsigned long r_alt_ser_baudrate_shadow = 0; /* this is the data for the four serial ports in the etrax100 */ /* DMA2(ser2), DMA4(ser3), DMA6(ser0) or DMA8(ser1) */ /* R_DMA_CHx_CLR_INTR, R_DMA_CHx_FIRST, R_DMA_CHx_CMD */ static struct e100_serial rs_table[] = { { .baud = DEF_BAUD, .port = (unsigned char *)R_SERIAL0_CTRL, .irq = 1U << 12, /* uses DMA 6 and 7 */ .oclrintradr = R_DMA_CH6_CLR_INTR, .ofirstadr = R_DMA_CH6_FIRST, .ocmdadr = R_DMA_CH6_CMD, .ostatusadr = R_DMA_CH6_STATUS, .iclrintradr = R_DMA_CH7_CLR_INTR, .ifirstadr = R_DMA_CH7_FIRST, .icmdadr = R_DMA_CH7_CMD, .idescradr = R_DMA_CH7_DESCR, .flags = STD_FLAGS, .rx_ctrl = DEF_RX, .tx_ctrl = DEF_TX, .iseteop = 2, #ifdef CONFIG_ETRAX_SERIAL_PORT0 .enabled = 1, #ifdef CONFIG_ETRAX_SERIAL_PORT0_DMA6_OUT .dma_out_enabled = 1, #else .dma_out_enabled = 0, #endif #ifdef CONFIG_ETRAX_SERIAL_PORT0_DMA7_IN .dma_in_enabled = 1, #else .dma_in_enabled = 0 #endif #else .enabled = 0, .dma_out_enabled = 0, .dma_in_enabled = 0 #endif }, /* ttyS0 */ #ifndef CONFIG_SVINTO_SIM { .baud = DEF_BAUD, .port = (unsigned char *)R_SERIAL1_CTRL, .irq = 1U << 16, /* uses DMA 8 and 9 */ .oclrintradr = R_DMA_CH8_CLR_INTR, .ofirstadr = R_DMA_CH8_FIRST, .ocmdadr = R_DMA_CH8_CMD, .ostatusadr = R_DMA_CH8_STATUS, .iclrintradr = R_DMA_CH9_CLR_INTR, .ifirstadr = R_DMA_CH9_FIRST, .icmdadr = R_DMA_CH9_CMD, .idescradr = R_DMA_CH9_DESCR, .flags = STD_FLAGS, .rx_ctrl = DEF_RX, .tx_ctrl = DEF_TX, .iseteop = 3, #ifdef CONFIG_ETRAX_SERIAL_PORT1 .enabled = 1, #ifdef CONFIG_ETRAX_SERIAL_PORT1_DMA8_OUT .dma_out_enabled = 1, #else .dma_out_enabled = 0, #endif #ifdef CONFIG_ETRAX_SERIAL_PORT1_DMA9_IN .dma_in_enabled = 1, #else .dma_in_enabled = 0 #endif #else .enabled = 0, .dma_out_enabled = 0, .dma_in_enabled = 0 #endif }, /* ttyS1 */ { .baud = DEF_BAUD, .port = (unsigned char *)R_SERIAL2_CTRL, .irq = 1U << 4, /* uses DMA 2 and 3 */ .oclrintradr = R_DMA_CH2_CLR_INTR, .ofirstadr = R_DMA_CH2_FIRST, .ocmdadr = R_DMA_CH2_CMD, .ostatusadr = R_DMA_CH2_STATUS, .iclrintradr = R_DMA_CH3_CLR_INTR, .ifirstadr = R_DMA_CH3_FIRST, .icmdadr = R_DMA_CH3_CMD, .idescradr = R_DMA_CH3_DESCR, .flags = STD_FLAGS, .rx_ctrl = DEF_RX, .tx_ctrl = DEF_TX, .iseteop = 0, #ifdef CONFIG_ETRAX_SERIAL_PORT2 .enabled = 1, #ifdef CONFIG_ETRAX_SERIAL_PORT2_DMA2_OUT .dma_out_enabled = 1, #else .dma_out_enabled = 0, #endif #ifdef CONFIG_ETRAX_SERIAL_PORT2_DMA3_IN .dma_in_enabled = 1, #else .dma_in_enabled = 0 #endif #else .enabled = 0, .dma_out_enabled = 0, .dma_in_enabled = 0 #endif }, /* ttyS2 */ { .baud = DEF_BAUD, .port = (unsigned char *)R_SERIAL3_CTRL, .irq = 1U << 8, /* uses DMA 4 and 5 */ .oclrintradr = R_DMA_CH4_CLR_INTR, .ofirstadr = R_DMA_CH4_FIRST, .ocmdadr = R_DMA_CH4_CMD, .ostatusadr = R_DMA_CH4_STATUS, .iclrintradr = R_DMA_CH5_CLR_INTR, .ifirstadr = R_DMA_CH5_FIRST, .icmdadr = R_DMA_CH5_CMD, .idescradr = R_DMA_CH5_DESCR, .flags = STD_FLAGS, .rx_ctrl = DEF_RX, .tx_ctrl = DEF_TX, .iseteop = 1, #ifdef CONFIG_ETRAX_SERIAL_PORT3 .enabled = 1, #ifdef CONFIG_ETRAX_SERIAL_PORT3_DMA4_OUT .dma_out_enabled = 1, #else .dma_out_enabled = 0, #endif #ifdef CONFIG_ETRAX_SERIAL_PORT3_DMA5_IN .dma_in_enabled = 1, #else .dma_in_enabled = 0 #endif #else .enabled = 0, .dma_out_enabled = 0, .dma_in_enabled = 0 #endif } /* ttyS3 */ #endif }; #define NR_PORTS (sizeof(rs_table)/sizeof(struct e100_serial)) static struct termios *serial_termios[NR_PORTS]; static struct termios *serial_termios_locked[NR_PORTS]; #ifdef CONFIG_ETRAX_SERIAL_FAST_TIMER static struct fast_timer fast_timers[NR_PORTS]; #endif #ifdef CONFIG_ETRAX_SERIAL_PROC_ENTRY #define PROCSTAT(x) x struct ser_statistics_type { int overrun_cnt; int early_errors_cnt; int ser_ints_ok_cnt; int errors_cnt; unsigned long int processing_flip; unsigned long processing_flip_still_room; unsigned long int timeout_flush_cnt; int rx_dma_ints; int tx_dma_ints; int rx_tot; int tx_tot; }; static struct ser_statistics_type ser_stat[NR_PORTS]; #else #define PROCSTAT(x) #endif /* CONFIG_ETRAX_SERIAL_PROC_ENTRY */ /* RS-485 */ #if defined(CONFIG_ETRAX_RS485) #ifdef CONFIG_ETRAX_FAST_TIMER static struct fast_timer fast_timers_rs485[NR_PORTS]; #endif #if defined(CONFIG_ETRAX_RS485_ON_PA) static int rs485_pa_bit = CONFIG_ETRAX_RS485_ON_PA_BIT; #endif #if defined(CONFIG_ETRAX_RS485_ON_PORT_G) static int rs485_port_g_bit = CONFIG_ETRAX_RS485_ON_PORT_G_BIT; #endif #endif /* Info and macros needed for each ports extra control/status signals. */ #define E100_STRUCT_PORT(line, pinname) \ ((CONFIG_ETRAX_SER##line##_##pinname##_ON_PA_BIT >= 0)? \ (R_PORT_PA_DATA): ( \ (CONFIG_ETRAX_SER##line##_##pinname##_ON_PB_BIT >= 0)? \ (R_PORT_PB_DATA):&dummy_ser[line])) #define E100_STRUCT_SHADOW(line, pinname) \ ((CONFIG_ETRAX_SER##line##_##pinname##_ON_PA_BIT >= 0)? \ (&port_pa_data_shadow): ( \ (CONFIG_ETRAX_SER##line##_##pinname##_ON_PB_BIT >= 0)? \ (&port_pb_data_shadow):&dummy_ser[line])) #define E100_STRUCT_MASK(line, pinname) \ ((CONFIG_ETRAX_SER##line##_##pinname##_ON_PA_BIT >= 0)? \ (1<<CONFIG_ETRAX_SER##line##_##pinname##_ON_PA_BIT): ( \ (CONFIG_ETRAX_SER##line##_##pinname##_ON_PB_BIT >= 0)? \ (1<<CONFIG_ETRAX_SER##line##_##pinname##_ON_PB_BIT):DUMMY_##pinname##_MASK)) #define DUMMY_DTR_MASK 1 #define DUMMY_RI_MASK 2 #define DUMMY_DSR_MASK 4 #define DUMMY_CD_MASK 8 static unsigned char dummy_ser[NR_PORTS] = {0xFF, 0xFF, 0xFF,0xFF}; /* If not all status pins are used or disabled, use mixed mode */ #ifdef CONFIG_ETRAX_SERIAL_PORT0 #define SER0_PA_BITSUM (CONFIG_ETRAX_SER0_DTR_ON_PA_BIT+CONFIG_ETRAX_SER0_RI_ON_PA_BIT+CONFIG_ETRAX_SER0_DSR_ON_PA_BIT+CONFIG_ETRAX_SER0_CD_ON_PA_BIT) #if SER0_PA_BITSUM != -4 # if CONFIG_ETRAX_SER0_DTR_ON_PA_BIT == -1 # ifndef CONFIG_ETRAX_SER0_DTR_RI_DSR_CD_MIXED # define CONFIG_ETRAX_SER0_DTR_RI_DSR_CD_MIXED 1 # endif # endif # if CONFIG_ETRAX_SER0_RI_ON_PA_BIT == -1 # ifndef CONFIG_ETRAX_SER0_DTR_RI_DSR_CD_MIXED # define CONFIG_ETRAX_SER0_DTR_RI_DSR_CD_MIXED 1 # endif # endif # if CONFIG_ETRAX_SER0_DSR_ON_PA_BIT == -1 # ifndef CONFIG_ETRAX_SER0_DTR_RI_DSR_CD_MIXED # define CONFIG_ETRAX_SER0_DTR_RI_DSR_CD_MIXED 1 # endif # endif # if CONFIG_ETRAX_SER0_CD_ON_PA_BIT == -1 # ifndef CONFIG_ETRAX_SER0_DTR_RI_DSR_CD_MIXED # define CONFIG_ETRAX_SER0_DTR_RI_DSR_CD_MIXED 1 # endif # endif #endif #define SER0_PB_BITSUM (CONFIG_ETRAX_SER0_DTR_ON_PB_BIT+CONFIG_ETRAX_SER0_RI_ON_PB_BIT+CONFIG_ETRAX_SER0_DSR_ON_PB_BIT+CONFIG_ETRAX_SER0_CD_ON_PB_BIT) #if SER0_PB_BITSUM != -4 # if CONFIG_ETRAX_SER0_DTR_ON_PB_BIT == -1 # ifndef CONFIG_ETRAX_SER0_DTR_RI_DSR_CD_MIXED # define CONFIG_ETRAX_SER0_DTR_RI_DSR_CD_MIXED 1 # endif # endif # if CONFIG_ETRAX_SER0_RI_ON_PB_BIT == -1 # ifndef CONFIG_ETRAX_SER0_DTR_RI_DSR_CD_MIXED # define CONFIG_ETRAX_SER0_DTR_RI_DSR_CD_MIXED 1 # endif # endif # if CONFIG_ETRAX_SER0_DSR_ON_PB_BIT == -1 # ifndef CONFIG_ETRAX_SER0_DTR_RI_DSR_CD_MIXED # define CONFIG_ETRAX_SER0_DTR_RI_DSR_CD_MIXED 1 # endif # endif # if CONFIG_ETRAX_SER0_CD_ON_PB_BIT == -1 # ifndef CONFIG_ETRAX_SER0_DTR_RI_DSR_CD_MIXED # define CONFIG_ETRAX_SER0_DTR_RI_DSR_CD_MIXED 1 # endif # endif #endif #endif /* PORT0 */ #ifdef CONFIG_ETRAX_SERIAL_PORT1 #define SER1_PA_BITSUM (CONFIG_ETRAX_SER1_DTR_ON_PA_BIT+CONFIG_ETRAX_SER1_RI_ON_PA_BIT+CONFIG_ETRAX_SER1_DSR_ON_PA_BIT+CONFIG_ETRAX_SER1_CD_ON_PA_BIT) #if SER1_PA_BITSUM != -4 # if CONFIG_ETRAX_SER1_DTR_ON_PA_BIT == -1 # ifndef CONFIG_ETRAX_SER1_DTR_RI_DSR_CD_MIXED # define CONFIG_ETRAX_SER1_DTR_RI_DSR_CD_MIXED 1 # endif # endif # if CONFIG_ETRAX_SER1_RI_ON_PA_BIT == -1 # ifndef CONFIG_ETRAX_SER1_DTR_RI_DSR_CD_MIXED # define CONFIG_ETRAX_SER1_DTR_RI_DSR_CD_MIXED 1 # endif # endif # if CONFIG_ETRAX_SER1_DSR_ON_PA_BIT == -1 # ifndef CONFIG_ETRAX_SER1_DTR_RI_DSR_CD_MIXED # define CONFIG_ETRAX_SER1_DTR_RI_DSR_CD_MIXED 1 # endif # endif # if CONFIG_ETRAX_SER1_CD_ON_PA_BIT == -1 # ifndef CONFIG_ETRAX_SER1_DTR_RI_DSR_CD_MIXED # define CONFIG_ETRAX_SER1_DTR_RI_DSR_CD_MIXED 1 # endif # endif #endif #define SER1_PB_BITSUM (CONFIG_ETRAX_SER1_DTR_ON_PB_BIT+CONFIG_ETRAX_SER1_RI_ON_PB_BIT+CONFIG_ETRAX_SER1_DSR_ON_PB_BIT+CONFIG_ETRAX_SER1_CD_ON_PB_BIT) #if SER1_PB_BITSUM != -4 # if CONFIG_ETRAX_SER1_DTR_ON_PB_BIT == -1 # ifndef CONFIG_ETRAX_SER1_DTR_RI_DSR_CD_MIXED # define CONFIG_ETRAX_SER1_DTR_RI_DSR_CD_MIXED 1 # endif # endif # if CONFIG_ETRAX_SER1_RI_ON_PB_BIT == -1 # ifndef CONFIG_ETRAX_SER1_DTR_RI_DSR_CD_MIXED # define CONFIG_ETRAX_SER1_DTR_RI_DSR_CD_MIXED 1 # endif # endif # if CONFIG_ETRAX_SER1_DSR_ON_PB_BIT == -1 # ifndef CONFIG_ETRAX_SER1_DTR_RI_DSR_CD_MIXED # define CONFIG_ETRAX_SER1_DTR_RI_DSR_CD_MIXED 1 # endif # endif # if CONFIG_ETRAX_SER1_CD_ON_PB_BIT == -1 # ifndef CONFIG_ETRAX_SER1_DTR_RI_DSR_CD_MIXED # define CONFIG_ETRAX_SER1_DTR_RI_DSR_CD_MIXED 1 # endif # endif #endif #endif /* PORT1 */ #ifdef CONFIG_ETRAX_SERIAL_PORT2 #define SER2_PA_BITSUM (CONFIG_ETRAX_SER2_DTR_ON_PA_BIT+CONFIG_ETRAX_SER2_RI_ON_PA_BIT+CONFIG_ETRAX_SER2_DSR_ON_PA_BIT+CONFIG_ETRAX_SER2_CD_ON_PA_BIT) #if SER2_PA_BITSUM != -4 # if CONFIG_ETRAX_SER2_DTR_ON_PA_BIT == -1 # ifndef CONFIG_ETRAX_SER2_DTR_RI_DSR_CD_MIXED # define CONFIG_ETRAX_SER2_DTR_RI_DSR_CD_MIXED 1 # endif # endif # if CONFIG_ETRAX_SER2_RI_ON_PA_BIT == -1 # ifndef CONFIG_ETRAX_SER2_DTR_RI_DSR_CD_MIXED # define CONFIG_ETRAX_SER2_DTR_RI_DSR_CD_MIXED 1 # endif # endif # if CONFIG_ETRAX_SER2_DSR_ON_PA_BIT == -1 # ifndef CONFIG_ETRAX_SER2_DTR_RI_DSR_CD_MIXED # define CONFIG_ETRAX_SER2_DTR_RI_DSR_CD_MIXED 1 # endif # endif # if CONFIG_ETRAX_SER2_CD_ON_PA_BIT == -1 # ifndef CONFIG_ETRAX_SER2_DTR_RI_DSR_CD_MIXED # define CONFIG_ETRAX_SER2_DTR_RI_DSR_CD_MIXED 1 # endif # endif #endif #define SER2_PB_BITSUM (CONFIG_ETRAX_SER2_DTR_ON_PB_BIT+CONFIG_ETRAX_SER2_RI_ON_PB_BIT+CONFIG_ETRAX_SER2_DSR_ON_PB_BIT+CONFIG_ETRAX_SER2_CD_ON_PB_BIT) #if SER2_PB_BITSUM != -4 # if CONFIG_ETRAX_SER2_DTR_ON_PB_BIT == -1 # ifndef CONFIG_ETRAX_SER2_DTR_RI_DSR_CD_MIXED # define CONFIG_ETRAX_SER2_DTR_RI_DSR_CD_MIXED 1 # endif # endif # if CONFIG_ETRAX_SER2_RI_ON_PB_BIT == -1 # ifndef CONFIG_ETRAX_SER2_DTR_RI_DSR_CD_MIXED # define CONFIG_ETRAX_SER2_DTR_RI_DSR_CD_MIXED 1 # endif # endif # if CONFIG_ETRAX_SER2_DSR_ON_PB_BIT == -1 # ifndef CONFIG_ETRAX_SER2_DTR_RI_DSR_CD_MIXED # define CONFIG_ETRAX_SER2_DTR_RI_DSR_CD_MIXED 1 # endif # endif # if CONFIG_ETRAX_SER2_CD_ON_PB_BIT == -1 # ifndef CONFIG_ETRAX_SER2_DTR_RI_DSR_CD_MIXED # define CONFIG_ETRAX_SER2_DTR_RI_DSR_CD_MIXED 1 # endif # endif #endif #endif /* PORT2 */ #ifdef CONFIG_ETRAX_SERIAL_PORT3 #define SER3_PA_BITSUM (CONFIG_ETRAX_SER3_DTR_ON_PA_BIT+CONFIG_ETRAX_SER3_RI_ON_PA_BIT+CONFIG_ETRAX_SER3_DSR_ON_PA_BIT+CONFIG_ETRAX_SER3_CD_ON_PA_BIT) #if SER3_PA_BITSUM != -4 # if CONFIG_ETRAX_SER3_DTR_ON_PA_BIT == -1 # ifndef CONFIG_ETRAX_SER3_DTR_RI_DSR_CD_MIXED # define CONFIG_ETRAX_SER3_DTR_RI_DSR_CD_MIXED 1 # endif # endif # if CONFIG_ETRAX_SER3_RI_ON_PA_BIT == -1 # ifndef CONFIG_ETRAX_SER3_DTR_RI_DSR_CD_MIXED # define CONFIG_ETRAX_SER3_DTR_RI_DSR_CD_MIXED 1 # endif # endif # if CONFIG_ETRAX_SER3_DSR_ON_PA_BIT == -1 # ifndef CONFIG_ETRAX_SER3_DTR_RI_DSR_CD_MIXED # define CONFIG_ETRAX_SER3_DTR_RI_DSR_CD_MIXED 1 # endif # endif # if CONFIG_ETRAX_SER3_CD_ON_PA_BIT == -1 # ifndef CONFIG_ETRAX_SER3_DTR_RI_DSR_CD_MIXED # define CONFIG_ETRAX_SER3_DTR_RI_DSR_CD_MIXED 1 # endif # endif #endif #define SER3_PB_BITSUM (CONFIG_ETRAX_SER3_DTR_ON_PB_BIT+CONFIG_ETRAX_SER3_RI_ON_PB_BIT+CONFIG_ETRAX_SER3_DSR_ON_PB_BIT+CONFIG_ETRAX_SER3_CD_ON_PB_BIT) #if SER3_PB_BITSUM != -4 # if CONFIG_ETRAX_SER3_DTR_ON_PB_BIT == -1 # ifndef CONFIG_ETRAX_SER3_DTR_RI_DSR_CD_MIXED # define CONFIG_ETRAX_SER3_DTR_RI_DSR_CD_MIXED 1 # endif # endif # if CONFIG_ETRAX_SER3_RI_ON_PB_BIT == -1 # ifndef CONFIG_ETRAX_SER3_DTR_RI_DSR_CD_MIXED # define CONFIG_ETRAX_SER3_DTR_RI_DSR_CD_MIXED 1 # endif # endif # if CONFIG_ETRAX_SER3_DSR_ON_PB_BIT == -1 # ifndef CONFIG_ETRAX_SER3_DTR_RI_DSR_CD_MIXED # define CONFIG_ETRAX_SER3_DTR_RI_DSR_CD_MIXED 1 # endif # endif # if CONFIG_ETRAX_SER3_CD_ON_PB_BIT == -1 # ifndef CONFIG_ETRAX_SER3_DTR_RI_DSR_CD_MIXED # define CONFIG_ETRAX_SER3_DTR_RI_DSR_CD_MIXED 1 # endif # endif #endif #endif /* PORT3 */ #if defined(CONFIG_ETRAX_SER0_DTR_RI_DSR_CD_MIXED) || \ defined(CONFIG_ETRAX_SER1_DTR_RI_DSR_CD_MIXED) || \ defined(CONFIG_ETRAX_SER2_DTR_RI_DSR_CD_MIXED) || \ defined(CONFIG_ETRAX_SER3_DTR_RI_DSR_CD_MIXED) #define CONFIG_ETRAX_SERX_DTR_RI_DSR_CD_MIXED #endif #ifdef CONFIG_ETRAX_SERX_DTR_RI_DSR_CD_MIXED /* The pins can be mixed on PA and PB */ #define CONTROL_PINS_PORT_NOT_USED(line) \ &dummy_ser[line], &dummy_ser[line], \ &dummy_ser[line], &dummy_ser[line], \ &dummy_ser[line], &dummy_ser[line], \ &dummy_ser[line], &dummy_ser[line], \ DUMMY_DTR_MASK, DUMMY_RI_MASK, DUMMY_DSR_MASK, DUMMY_CD_MASK struct control_pins { volatile unsigned char *dtr_port; unsigned char *dtr_shadow; volatile unsigned char *ri_port; unsigned char *ri_shadow; volatile unsigned char *dsr_port; unsigned char *dsr_shadow; volatile unsigned char *cd_port; unsigned char *cd_shadow; unsigned char dtr_mask; unsigned char ri_mask; unsigned char dsr_mask; unsigned char cd_mask; }; static const struct control_pins e100_modem_pins[NR_PORTS] = { /* Ser 0 */ { #ifdef CONFIG_ETRAX_SERIAL_PORT0 E100_STRUCT_PORT(0,DTR), E100_STRUCT_SHADOW(0,DTR), E100_STRUCT_PORT(0,RI), E100_STRUCT_SHADOW(0,RI), E100_STRUCT_PORT(0,DSR), E100_STRUCT_SHADOW(0,DSR), E100_STRUCT_PORT(0,CD), E100_STRUCT_SHADOW(0,CD), E100_STRUCT_MASK(0,DTR), E100_STRUCT_MASK(0,RI), E100_STRUCT_MASK(0,DSR), E100_STRUCT_MASK(0,CD) #else CONTROL_PINS_PORT_NOT_USED(0) #endif }, /* Ser 1 */ { #ifdef CONFIG_ETRAX_SERIAL_PORT1 E100_STRUCT_PORT(1,DTR), E100_STRUCT_SHADOW(1,DTR), E100_STRUCT_PORT(1,RI), E100_STRUCT_SHADOW(1,RI), E100_STRUCT_PORT(1,DSR), E100_STRUCT_SHADOW(1,DSR), E100_STRUCT_PORT(1,CD), E100_STRUCT_SHADOW(1,CD), E100_STRUCT_MASK(1,DTR), E100_STRUCT_MASK(1,RI), E100_STRUCT_MASK(1,DSR), E100_STRUCT_MASK(1,CD) #else CONTROL_PINS_PORT_NOT_USED(1) #endif }, /* Ser 2 */ { #ifdef CONFIG_ETRAX_SERIAL_PORT2 E100_STRUCT_PORT(2,DTR), E100_STRUCT_SHADOW(2,DTR), E100_STRUCT_PORT(2,RI), E100_STRUCT_SHADOW(2,RI), E100_STRUCT_PORT(2,DSR), E100_STRUCT_SHADOW(2,DSR), E100_STRUCT_PORT(2,CD), E100_STRUCT_SHADOW(2,CD), E100_STRUCT_MASK(2,DTR), E100_STRUCT_MASK(2,RI), E100_STRUCT_MASK(2,DSR), E100_STRUCT_MASK(2,CD) #else CONTROL_PINS_PORT_NOT_USED(2) #endif }, /* Ser 3 */ { #ifdef CONFIG_ETRAX_SERIAL_PORT3 E100_STRUCT_PORT(3,DTR), E100_STRUCT_SHADOW(3,DTR), E100_STRUCT_PORT(3,RI), E100_STRUCT_SHADOW(3,RI), E100_STRUCT_PORT(3,DSR), E100_STRUCT_SHADOW(3,DSR), E100_STRUCT_PORT(3,CD), E100_STRUCT_SHADOW(3,CD), E100_STRUCT_MASK(3,DTR), E100_STRUCT_MASK(3,RI), E100_STRUCT_MASK(3,DSR), E100_STRUCT_MASK(3,CD) #else CONTROL_PINS_PORT_NOT_USED(3) #endif } }; #else /* CONFIG_ETRAX_SERX_DTR_RI_DSR_CD_MIXED */ /* All pins are on either PA or PB for each serial port */ #define CONTROL_PINS_PORT_NOT_USED(line) \ &dummy_ser[line], &dummy_ser[line], \ DUMMY_DTR_MASK, DUMMY_RI_MASK, DUMMY_DSR_MASK, DUMMY_CD_MASK struct control_pins { volatile unsigned char *port; unsigned char *shadow; unsigned char dtr_mask; unsigned char ri_mask; unsigned char dsr_mask; unsigned char cd_mask; }; #define dtr_port port #define dtr_shadow shadow #define ri_port port #define ri_shadow shadow #define dsr_port port #define dsr_shadow shadow #define cd_port port #define cd_shadow shadow static const struct control_pins e100_modem_pins[NR_PORTS] = { /* Ser 0 */ { #ifdef CONFIG_ETRAX_SERIAL_PORT0 E100_STRUCT_PORT(0,DTR), E100_STRUCT_SHADOW(0,DTR), E100_STRUCT_MASK(0,DTR), E100_STRUCT_MASK(0,RI), E100_STRUCT_MASK(0,DSR), E100_STRUCT_MASK(0,CD) #else CONTROL_PINS_PORT_NOT_USED(0) #endif }, /* Ser 1 */ { #ifdef CONFIG_ETRAX_SERIAL_PORT1 E100_STRUCT_PORT(1,DTR), E100_STRUCT_SHADOW(1,DTR), E100_STRUCT_MASK(1,DTR), E100_STRUCT_MASK(1,RI), E100_STRUCT_MASK(1,DSR), E100_STRUCT_MASK(1,CD) #else CONTROL_PINS_PORT_NOT_USED(1) #endif }, /* Ser 2 */ { #ifdef CONFIG_ETRAX_SERIAL_PORT2 E100_STRUCT_PORT(2,DTR), E100_STRUCT_SHADOW(2,DTR), E100_STRUCT_MASK(2,DTR), E100_STRUCT_MASK(2,RI), E100_STRUCT_MASK(2,DSR), E100_STRUCT_MASK(2,CD) #else CONTROL_PINS_PORT_NOT_USED(2) #endif }, /* Ser 3 */ { #ifdef CONFIG_ETRAX_SERIAL_PORT3 E100_STRUCT_PORT(3,DTR), E100_STRUCT_SHADOW(3,DTR), E100_STRUCT_MASK(3,DTR), E100_STRUCT_MASK(3,RI), E100_STRUCT_MASK(3,DSR), E100_STRUCT_MASK(3,CD) #else CONTROL_PINS_PORT_NOT_USED(3) #endif } }; #endif /* !CONFIG_ETRAX_SERX_DTR_RI_DSR_CD_MIXED */ #define E100_RTS_MASK 0x20 #define E100_CTS_MASK 0x40 /* All serial port signals are active low: * active = 0 -> 3.3V to RS-232 driver -> -12V on RS-232 level * inactive = 1 -> 0V to RS-232 driver -> +12V on RS-232 level * * These macros returns the pin value: 0=0V, >=1 = 3.3V on ETRAX chip */ /* Output */ #define E100_RTS_GET(info) ((info)->rx_ctrl & E100_RTS_MASK) /* Input */ #define E100_CTS_GET(info) ((info)->port[REG_STATUS] & E100_CTS_MASK) /* These are typically PA or PB and 0 means 0V, 1 means 3.3V */ /* Is an output */ #define E100_DTR_GET(info) ((*e100_modem_pins[(info)->line].dtr_shadow) & e100_modem_pins[(info)->line].dtr_mask) /* Normally inputs */ #define E100_RI_GET(info) ((*e100_modem_pins[(info)->line].ri_port) & e100_modem_pins[(info)->line].ri_mask) #define E100_CD_GET(info) ((*e100_modem_pins[(info)->line].cd_port) & e100_modem_pins[(info)->line].cd_mask) /* Input */ #define E100_DSR_GET(info) ((*e100_modem_pins[(info)->line].dsr_port) & e100_modem_pins[(info)->line].dsr_mask) /* * tmp_buf is used as a temporary buffer by serial_write. We need to * lock it in case the memcpy_fromfs blocks while swapping in a page, * and some other program tries to do a serial write at the same time. * Since the lock will only come under contention when the system is * swapping and available memory is low, it makes sense to share one * buffer across all the serial ports, since it significantly saves * memory if large numbers of serial ports are open. */ static unsigned char *tmp_buf; #ifdef DECLARE_MUTEX static DECLARE_MUTEX(tmp_buf_sem); #else static struct semaphore tmp_buf_sem = MUTEX; #endif /* Calculate the chartime depending on baudrate, numbor of bits etc. */ static void update_char_time(struct e100_serial * info) { tcflag_t cflags = info->tty->termios->c_cflag; int bits; /* calc. number of bits / data byte */ /* databits + startbit and 1 stopbit */ if ((cflags & CSIZE) == CS7) bits = 9; else bits = 10; if (cflags & CSTOPB) /* 2 stopbits ? */ bits++; if (cflags & PARENB) /* parity bit ? */ bits++; /* calc timeout */ info->char_time_usec = ((bits * 1000000) / info->baud) + 1; info->flush_time_usec = 4*info->char_time_usec; if (info->flush_time_usec < MIN_FLUSH_TIME_USEC) info->flush_time_usec = MIN_FLUSH_TIME_USEC; } /* * This function maps from the Bxxxx defines in asm/termbits.h into real * baud rates. */ static int cflag_to_baud(unsigned int cflag) { static int baud_table[] = { 0, 50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400, 4800, 9600, 19200, 38400 }; static int ext_baud_table[] = { 0, 57600, 115200, 230400, 460800, 921600, 1843200, 6250000, 0, 0, 0, 0, 0, 0, 0, 0 }; if (cflag & CBAUDEX) return ext_baud_table[(cflag & CBAUD) & ~CBAUDEX]; else return baud_table[cflag & CBAUD]; } /* and this maps to an etrax100 hardware baud constant */ static unsigned char cflag_to_etrax_baud(unsigned int cflag) { char retval; static char baud_table[] = { -1, -1, -1, -1, -1, -1, -1, 0, 1, 2, -1, 3, 4, 5, 6, 7 }; static char ext_baud_table[] = { -1, 8, 9, 10, 11, 12, 13, 14, -1, -1, -1, -1, -1, -1, -1, -1 }; if (cflag & CBAUDEX) retval = ext_baud_table[(cflag & CBAUD) & ~CBAUDEX]; else retval = baud_table[cflag & CBAUD]; if (retval < 0) { printk(KERN_WARNING "serdriver tried setting invalid baud rate, flags %x.\n", cflag); retval = 5; /* choose default 9600 instead */ } return retval | (retval << 4); /* choose same for both TX and RX */ } /* Various static support functions */ /* Functions to set or clear DTR/RTS on the requested line */ /* It is complicated by the fact that RTS is a serial port register, while * DTR might not be implemented in the HW at all, and if it is, it can be on * any general port. */ static inline void e100_dtr(struct e100_serial *info, int set) { #ifndef CONFIG_SVINTO_SIM unsigned char mask = e100_modem_pins[info->line].dtr_mask; #ifdef SERIAL_DEBUG_IO printk("ser%i dtr %i mask: 0x%02X\n", info->line, set, mask); printk("ser%i shadow before 0x%02X get: %i\n", info->line, *e100_modem_pins[info->line].dtr_shadow, E100_DTR_GET(info)); #endif /* DTR is active low */ { unsigned long flags; save_flags(flags); cli(); *e100_modem_pins[info->line].dtr_shadow &= ~mask; *e100_modem_pins[info->line].dtr_shadow |= (set ? 0 : mask); *e100_modem_pins[info->line].dtr_port = *e100_modem_pins[info->line].dtr_shadow; restore_flags(flags); } #ifdef SERIAL_DEBUG_IO printk("ser%i shadow after 0x%02X get: %i\n", info->line, *e100_modem_pins[info->line].dtr_shadow, E100_DTR_GET(info)); #endif #endif } /* set = 0 means 3.3V on the pin, bitvalue: 0=active, 1=inactive * 0=0V , 1=3.3V */ static inline void e100_rts(struct e100_serial *info, int set) { #ifndef CONFIG_SVINTO_SIM unsigned long flags; save_flags(flags); cli(); info->rx_ctrl &= ~E100_RTS_MASK; info->rx_ctrl |= (set ? 0 : E100_RTS_MASK); /* RTS is active low */ info->port[REG_REC_CTRL] = info->rx_ctrl; restore_flags(flags); #ifdef SERIAL_DEBUG_IO printk("ser%i rts %i\n", info->line, set); #endif #endif } /* If this behaves as a modem, RI and CD is an output */ static inline void e100_ri_out(struct e100_serial *info, int set) { #ifndef CONFIG_SVINTO_SIM /* RI is active low */ { unsigned char mask = e100_modem_pins[info->line].ri_mask; unsigned long flags; save_flags(flags); cli(); *e100_modem_pins[info->line].ri_shadow &= ~mask; *e100_modem_pins[info->line].ri_shadow |= (set ? 0 : mask); *e100_modem_pins[info->line].ri_port = *e100_modem_pins[info->line].ri_shadow; restore_flags(flags); } #endif } static inline void e100_cd_out(struct e100_serial *info, int set) { #ifndef CONFIG_SVINTO_SIM /* CD is active low */ { unsigned char mask = e100_modem_pins[info->line].cd_mask; unsigned long flags; save_flags(flags); cli(); *e100_modem_pins[info->line].cd_shadow &= ~mask; *e100_modem_pins[info->line].cd_shadow |= (set ? 0 : mask); *e100_modem_pins[info->line].cd_port = *e100_modem_pins[info->line].cd_shadow; restore_flags(flags); } #endif } static inline void e100_disable_rx(struct e100_serial *info) { #ifndef CONFIG_SVINTO_SIM /* disable the receiver */ info->port[REG_REC_CTRL] = (info->rx_ctrl &= ~IO_MASK(R_SERIAL0_REC_CTRL, rec_enable)); #endif } static inline void e100_enable_rx(struct e100_serial *info) { #ifndef CONFIG_SVINTO_SIM /* enable the receiver */ info->port[REG_REC_CTRL] = (info->rx_ctrl |= IO_MASK(R_SERIAL0_REC_CTRL, rec_enable)); #endif } /* the rx DMA uses both the dma_descr and the dma_eop interrupts */ static inline void e100_disable_rxdma_irq(struct e100_serial *info) { #ifdef SERIAL_DEBUG_INTR printk("rxdma_irq(%d): 0\n",info->line); #endif DINTR1(DEBUG_LOG(info->line,"IRQ disable_rxdma_irq %i\n", info->line)); *R_IRQ_MASK2_CLR = (info->irq << 2) | (info->irq << 3); } static inline void e100_enable_rxdma_irq(struct e100_serial *info) { #ifdef SERIAL_DEBUG_INTR printk("rxdma_irq(%d): 1\n",info->line); #endif DINTR1(DEBUG_LOG(info->line,"IRQ enable_rxdma_irq %i\n", info->line)); *R_IRQ_MASK2_SET = (info->irq << 2) | (info->irq << 3); } /* the tx DMA uses only dma_descr interrupt */ static _INLINE_ void e100_disable_txdma_irq(struct e100_serial *info) { #ifdef SERIAL_DEBUG_INTR printk("txdma_irq(%d): 0\n",info->line); #endif DINTR1(DEBUG_LOG(info->line,"IRQ disable_txdma_irq %i\n", info->line)); *R_IRQ_MASK2_CLR = info->irq; } static _INLINE_ void e100_enable_txdma_irq(struct e100_serial *info) { #ifdef SERIAL_DEBUG_INTR printk("txdma_irq(%d): 1\n",info->line); #endif DINTR1(DEBUG_LOG(info->line,"IRQ enable_txdma_irq %i\n", info->line)); *R_IRQ_MASK2_SET = info->irq; } static _INLINE_ void e100_disable_txdma_channel(struct e100_serial *info) { unsigned long flags; /* Disable output DMA channel for the serial port in question * ( set to something other then serialX) */ save_flags(flags); cli(); DFLOW(DEBUG_LOG(info->line, "disable_txdma_channel %i\n", info->line)); if (info->line == 0) { if ((genconfig_shadow & IO_MASK(R_GEN_CONFIG, dma6)) == IO_STATE(R_GEN_CONFIG, dma6, serial0)) { genconfig_shadow &= ~IO_MASK(R_GEN_CONFIG, dma6); genconfig_shadow |= IO_STATE(R_GEN_CONFIG, dma6, unused); } } else if (info->line == 1) { if ((genconfig_shadow & IO_MASK(R_GEN_CONFIG, dma8)) == IO_STATE(R_GEN_CONFIG, dma8, serial1)) { genconfig_shadow &= ~IO_MASK(R_GEN_CONFIG, dma8); genconfig_shadow |= IO_STATE(R_GEN_CONFIG, dma8, usb); } } else if (info->line == 2) { if ((genconfig_shadow & IO_MASK(R_GEN_CONFIG, dma2)) == IO_STATE(R_GEN_CONFIG, dma2, serial2)) { genconfig_shadow &= ~IO_MASK(R_GEN_CONFIG, dma2); genconfig_shadow |= IO_STATE(R_GEN_CONFIG, dma2, par0); } } else if (info->line == 3) { if ((genconfig_shadow & IO_MASK(R_GEN_CONFIG, dma4)) == IO_STATE(R_GEN_CONFIG, dma4, serial3)) { genconfig_shadow &= ~IO_MASK(R_GEN_CONFIG, dma4); genconfig_shadow |= IO_STATE(R_GEN_CONFIG, dma4, par1); } } *R_GEN_CONFIG = genconfig_shadow; restore_flags(flags); } static _INLINE_ void e100_enable_txdma_channel(struct e100_serial *info) { unsigned long flags; save_flags(flags); cli(); DFLOW(DEBUG_LOG(info->line, "enable_txdma_channel %i\n", info->line)); /* Enable output DMA channel for the serial port in question */ if (info->line == 0) { genconfig_shadow &= ~IO_MASK(R_GEN_CONFIG, dma6); genconfig_shadow |= IO_STATE(R_GEN_CONFIG, dma6, serial0); } else if (info->line == 1) { genconfig_shadow &= ~IO_MASK(R_GEN_CONFIG, dma8); genconfig_shadow |= IO_STATE(R_GEN_CONFIG, dma8, serial1); } else if (info->line == 2) { genconfig_shadow &= ~IO_MASK(R_GEN_CONFIG, dma2); genconfig_shadow |= IO_STATE(R_GEN_CONFIG, dma2, serial2); } else if (info->line == 3) { genconfig_shadow &= ~IO_MASK(R_GEN_CONFIG, dma4); genconfig_shadow |= IO_STATE(R_GEN_CONFIG, dma4, serial3); } *R_GEN_CONFIG = genconfig_shadow; restore_flags(flags); } static _INLINE_ void e100_disable_rxdma_channel(struct e100_serial *info) { unsigned long flags; /* Disable input DMA channel for the serial port in question * ( set to something other then serialX) */ save_flags(flags); cli(); if (info->line == 0) { if ((genconfig_shadow & IO_MASK(R_GEN_CONFIG, dma7)) == IO_STATE(R_GEN_CONFIG, dma7, serial0)) { genconfig_shadow &= ~IO_MASK(R_GEN_CONFIG, dma7); genconfig_shadow |= IO_STATE(R_GEN_CONFIG, dma7, unused); } } else if (info->line == 1) { if ((genconfig_shadow & IO_MASK(R_GEN_CONFIG, dma9)) == IO_STATE(R_GEN_CONFIG, dma9, serial1)) { genconfig_shadow &= ~IO_MASK(R_GEN_CONFIG, dma9); genconfig_shadow |= IO_STATE(R_GEN_CONFIG, dma9, usb); } } else if (info->line == 2) { if ((genconfig_shadow & IO_MASK(R_GEN_CONFIG, dma3)) == IO_STATE(R_GEN_CONFIG, dma3, serial2)) { genconfig_shadow &= ~IO_MASK(R_GEN_CONFIG, dma3); genconfig_shadow |= IO_STATE(R_GEN_CONFIG, dma3, par0); } } else if (info->line == 3) { if ((genconfig_shadow & IO_MASK(R_GEN_CONFIG, dma5)) == IO_STATE(R_GEN_CONFIG, dma5, serial3)) { genconfig_shadow &= ~IO_MASK(R_GEN_CONFIG, dma5); genconfig_shadow |= IO_STATE(R_GEN_CONFIG, dma5, par1); } } *R_GEN_CONFIG = genconfig_shadow; restore_flags(flags); } static _INLINE_ void e100_enable_rxdma_channel(struct e100_serial *info) { unsigned long flags; save_flags(flags); cli(); /* Enable input DMA channel for the serial port in question */ if (info->line == 0) { genconfig_shadow &= ~IO_MASK(R_GEN_CONFIG, dma7); genconfig_shadow |= IO_STATE(R_GEN_CONFIG, dma7, serial0); } else if (info->line == 1) { genconfig_shadow &= ~IO_MASK(R_GEN_CONFIG, dma9); genconfig_shadow |= IO_STATE(R_GEN_CONFIG, dma9, serial1); } else if (info->line == 2) { genconfig_shadow &= ~IO_MASK(R_GEN_CONFIG, dma3); genconfig_shadow |= IO_STATE(R_GEN_CONFIG, dma3, serial2); } else if (info->line == 3) { genconfig_shadow &= ~IO_MASK(R_GEN_CONFIG, dma5); genconfig_shadow |= IO_STATE(R_GEN_CONFIG, dma5, serial3); } *R_GEN_CONFIG = genconfig_shadow; restore_flags(flags); } #ifdef SERIAL_HANDLE_EARLY_ERRORS /* in order to detect and fix errors on the first byte we have to use the serial interrupts as well. */ static inline void e100_disable_serial_data_irq(struct e100_serial *info) { #ifdef SERIAL_DEBUG_INTR printk("ser_irq(%d): 0\n",info->line); #endif DINTR1(DEBUG_LOG(info->line,"IRQ disable data_irq %i\n", info->line)); *R_IRQ_MASK1_CLR = (1U << (8+2*info->line)); } static inline void e100_enable_serial_data_irq(struct e100_serial *info) { #ifdef SERIAL_DEBUG_INTR printk("ser_irq(%d): 1\n",info->line); printk("**** %d = %d\n", (8+2*info->line), (1U << (8+2*info->line))); #endif DINTR1(DEBUG_LOG(info->line,"IRQ enable data_irq %i\n", info->line)); *R_IRQ_MASK1_SET = (1U << (8+2*info->line)); } #endif static inline void e100_disable_serial_tx_ready_irq(struct e100_serial *info) { #ifdef SERIAL_DEBUG_INTR printk("ser_tx_irq(%d): 0\n",info->line); #endif DINTR1(DEBUG_LOG(info->line,"IRQ disable ready_irq %i\n", info->line)); *R_IRQ_MASK1_CLR = (1U << (8+1+2*info->line)); } static inline void e100_enable_serial_tx_ready_irq(struct e100_serial *info) { #ifdef SERIAL_DEBUG_INTR printk("ser_tx_irq(%d): 1\n",info->line); printk("**** %d = %d\n", (8+1+2*info->line), (1U << (8+1+2*info->line))); #endif DINTR2(DEBUG_LOG(info->line,"IRQ enable ready_irq %i\n", info->line)); *R_IRQ_MASK1_SET = (1U << (8+1+2*info->line)); } static inline void e100_enable_rx_irq(struct e100_serial *info) { if (info->uses_dma_in) e100_enable_rxdma_irq(info); else e100_enable_serial_data_irq(info); } static inline void e100_disable_rx_irq(struct e100_serial *info) { if (info->uses_dma_in) e100_disable_rxdma_irq(info); else e100_disable_serial_data_irq(info); } #if defined(CONFIG_ETRAX_RS485) /* Enable RS-485 mode on selected port. This is UGLY. */ static int e100_enable_rs485(struct tty_struct *tty,struct rs485_control *r) { struct e100_serial * info = (struct e100_serial *)tty->driver_data; #if defined(CONFIG_ETRAX_RS485_ON_PA) *R_PORT_PA_DATA = port_pa_data_shadow |= (1 << rs485_pa_bit); #endif #if defined(CONFIG_ETRAX_RS485_ON_PORT_G) REG_SHADOW_SET(R_PORT_G_DATA, port_g_data_shadow, rs485_port_g_bit, 1); #endif #if defined(CONFIG_ETRAX_RS485_LTC1387) REG_SHADOW_SET(R_PORT_G_DATA, port_g_data_shadow, CONFIG_ETRAX_RS485_LTC1387_DXEN_PORT_G_BIT, 1); REG_SHADOW_SET(R_PORT_G_DATA, port_g_data_shadow, CONFIG_ETRAX_RS485_LTC1387_RXEN_PORT_G_BIT, 1); #endif info->rs485.rts_on_send = 0x01 & r->rts_on_send; info->rs485.rts_after_sent = 0x01 & r->rts_after_sent; if (r->delay_rts_before_send >= 1000) info->rs485.delay_rts_before_send = 1000; else info->rs485.delay_rts_before_send = r->delay_rts_before_send; info->rs485.enabled = r->enabled; /* printk("rts: on send = %i, after = %i, enabled = %i", info->rs485.rts_on_send, info->rs485.rts_after_sent, info->rs485.enabled ); */ return 0; } static int e100_write_rs485(struct tty_struct *tty, int from_user, const unsigned char *buf, int count) { struct e100_serial * info = (struct e100_serial *)tty->driver_data; int old_enabled = info->rs485.enabled; /* rs485 is always implicitly enabled if we're using the ioctl() * but it doesn't have to be set in the rs485_control * (to be backward compatible with old apps) * So we store, set and restore it. */ info->rs485.enabled = 1; /* rs_write now deals with RS485 if enabled */ count = rs_write(tty, from_user, buf, count); info->rs485.enabled = old_enabled; return count; } #ifdef CONFIG_ETRAX_FAST_TIMER /* Timer function to toggle RTS when using FAST_TIMER */ static void rs485_toggle_rts_timer_function(unsigned long data) { struct e100_serial *info = (struct e100_serial *)data; fast_timers_rs485[info->line].function = NULL; e100_rts(info, info->rs485.rts_after_sent); #if defined(CONFIG_ETRAX_RS485_DISABLE_RECEIVER) e100_enable_rx(info); e100_enable_rx_irq(info); #endif } #endif #endif /* CONFIG_ETRAX_RS485 */ /* * ------------------------------------------------------------ * rs_stop() and rs_start() * * This routines are called before setting or resetting tty->stopped. * They enable or disable transmitter using the XOFF registers, as necessary. * ------------------------------------------------------------ */ static void rs_stop(struct tty_struct *tty) { struct e100_serial *info = (struct e100_serial *)tty->driver_data; if (info) { unsigned long flags; unsigned long xoff; save_flags(flags); cli(); DFLOW(DEBUG_LOG(info->line, "XOFF rs_stop xmit %i\n", CIRC_CNT(info->xmit.head, info->xmit.tail,SERIAL_XMIT_SIZE))); xoff = IO_FIELD(R_SERIAL0_XOFF, xoff_char, STOP_CHAR(info->tty)); xoff |= IO_STATE(R_SERIAL0_XOFF, tx_stop, stop); if (tty->termios->c_iflag & IXON ) { xoff |= IO_STATE(R_SERIAL0_XOFF, auto_xoff, enable); } *((unsigned long *)&info->port[REG_XOFF]) = xoff; restore_flags(flags); } } static void rs_start(struct tty_struct *tty) { struct e100_serial *info = (struct e100_serial *)tty->driver_data; if (info) { unsigned long flags; unsigned long xoff; save_flags(flags); cli(); DFLOW(DEBUG_LOG(info->line, "XOFF rs_start xmit %i\n", CIRC_CNT(info->xmit.head, info->xmit.tail,SERIAL_XMIT_SIZE))); xoff = IO_FIELD(R_SERIAL0_XOFF, xoff_char, STOP_CHAR(tty)); xoff |= IO_STATE(R_SERIAL0_XOFF, tx_stop, enable); if (tty->termios->c_iflag & IXON ) { xoff |= IO_STATE(R_SERIAL0_XOFF, auto_xoff, enable); } *((unsigned long *)&info->port[REG_XOFF]) = xoff; if (!info->uses_dma_out && info->xmit.head != info->xmit.tail && info->xmit.buf) e100_enable_serial_tx_ready_irq(info); restore_flags(flags); } } /* * ---------------------------------------------------------------------- * * Here starts the interrupt handling routines. All of the following * subroutines are declared as inline and are folded into * rs_interrupt(). They were separated out for readability's sake. * * Note: rs_interrupt() is a "fast" interrupt, which means that it * runs with interrupts turned off. People who may want to modify * rs_interrupt() should try to keep the interrupt handler as fast as * possible. After you are done making modifications, it is not a bad * idea to do: * * gcc -S -DKERNEL -Wall -Wstrict-prototypes -O6 -fomit-frame-pointer serial.c * * and look at the resulting assemble code in serial.s. * * - Ted Ts'o (tytso@mit.edu), 7-Mar-93 * ----------------------------------------------------------------------- */ /* * This routine is used by the interrupt handler to schedule * processing in the software interrupt portion of the driver. */ static _INLINE_ void rs_sched_event(struct e100_serial *info, int event) { if (info->event & (1 << event)) return; info->event |= 1 << event; schedule_work(&info->work); } /* The output DMA channel is free - use it to send as many chars as possible * NOTES: * We don't pay attention to info->x_char, which means if the TTY wants to * use XON/XOFF it will set info->x_char but we won't send any X char! * * To implement this, we'd just start a DMA send of 1 byte pointing at a * buffer containing the X char, and skip updating xmit. We'd also have to * check if the last sent char was the X char when we enter this function * the next time, to avoid updating xmit with the sent X value. */ static void transmit_chars_dma(struct e100_serial *info) { unsigned int c, sentl; struct etrax_dma_descr *descr; #ifdef CONFIG_SVINTO_SIM /* This will output too little if tail is not 0 always since * we don't reloop to send the other part. Anyway this SHOULD be a * no-op - transmit_chars_dma would never really be called during sim * since rs_write does not write into the xmit buffer then. */ if (info->xmit.tail) printk("Error in serial.c:transmit_chars-dma(), tail!=0\n"); if (info->xmit.head != info->xmit.tail) { SIMCOUT(info->xmit.buf + info->xmit.tail, CIRC_CNT(info->xmit.head, info->xmit.tail, SERIAL_XMIT_SIZE)); info->xmit.head = info->xmit.tail; /* move back head */ info->tr_running = 0; } return; #endif /* acknowledge both dma_descr and dma_eop irq in R_DMA_CHx_CLR_INTR */ *info->oclrintradr = IO_STATE(R_DMA_CH6_CLR_INTR, clr_descr, do) | IO_STATE(R_DMA_CH6_CLR_INTR, clr_eop, do); #ifdef SERIAL_DEBUG_INTR if (info->line == SERIAL_DEBUG_LINE) printk("tc\n"); #endif if (!info->tr_running) { /* weirdo... we shouldn't get here! */ printk(KERN_WARNING "Achtung: transmit_chars_dma with !tr_running\n"); return; } descr = &info->tr_descr; /* first get the amount of bytes sent during the last DMA transfer, and update xmit accordingly */ /* if the stop bit was not set, all data has been sent */ if (!(descr->status & d_stop)) { sentl = descr->sw_len; } else /* otherwise we find the amount of data sent here */ sentl = descr->hw_len; DFLOW(DEBUG_LOG(info->line, "TX %i done\n", sentl)); /* update stats */ info->icount.tx += sentl; /* update xmit buffer */ info->xmit.tail = (info->xmit.tail + sentl) & (SERIAL_XMIT_SIZE - 1); /* if there is only a few chars left in the buf, wake up the blocked write if any */ if (CIRC_CNT(info->xmit.head, info->xmit.tail, SERIAL_XMIT_SIZE) < WAKEUP_CHARS) rs_sched_event(info, RS_EVENT_WRITE_WAKEUP); /* find out the largest amount of consecutive bytes we want to send now */ c = CIRC_CNT_TO_END(info->xmit.head, info->xmit.tail, SERIAL_XMIT_SIZE); /* Don't send all in one DMA transfer - divide it so we wake up * application before all is sent */ if (c >= 4*WAKEUP_CHARS) c = c/2; if (c <= 0) { /* our job here is done, don't schedule any new DMA transfer */ info->tr_running = 0; #if defined(CONFIG_ETRAX_RS485) && defined(CONFIG_ETRAX_FAST_TIMER) if (info->rs485.enabled) { /* Set a short timer to toggle RTS */ start_one_shot_timer(&fast_timers_rs485[info->line], rs485_toggle_rts_timer_function, (unsigned long)info, info->char_time_usec*2, "RS-485"); } #endif /* RS485 */ return; } /* ok we can schedule a dma send of c chars starting at info->xmit.tail */ /* set up the descriptor correctly for output */ DFLOW(DEBUG_LOG(info->line, "TX %i\n", c)); descr->ctrl = d_int | d_eol | d_wait; /* Wait needed for tty_wait_until_sent() */ descr->sw_len = c; descr->buf = virt_to_phys(info->xmit.buf + info->xmit.tail); descr->status = 0; *info->ofirstadr = virt_to_phys(descr); /* write to R_DMAx_FIRST */ *info->ocmdadr = IO_STATE(R_DMA_CH6_CMD, cmd, start); /* DMA is now running (hopefully) */ } /* transmit_chars_dma */ static void start_transmit(struct e100_serial *info) { #if 0 if (info->line == SERIAL_DEBUG_LINE) printk("x\n"); #endif info->tr_descr.sw_len = 0; info->tr_descr.hw_len = 0; info->tr_descr.status = 0; info->tr_running = 1; if (info->uses_dma_out) transmit_chars_dma(info); else e100_enable_serial_tx_ready_irq(info); } /* start_transmit */ #ifdef CONFIG_ETRAX_SERIAL_FAST_TIMER static int serial_fast_timer_started = 0; static int serial_fast_timer_expired = 0; static void flush_timeout_function(unsigned long data); #define START_FLUSH_FAST_TIMER_TIME(info, string, usec) {\ unsigned long timer_flags; \ save_flags(timer_flags); \ cli(); \ if (fast_timers[info->line].function == NULL) { \ serial_fast_timer_started++; \ TIMERD(DEBUG_LOG(info->line, "start_timer %i ", info->line)); \ TIMERD(DEBUG_LOG(info->line, "num started: %i\n", serial_fast_timer_started)); \ start_one_shot_timer(&fast_timers[info->line], \ flush_timeout_function, \ (unsigned long)info, \ (usec), \ string); \ } \ else { \ TIMERD(DEBUG_LOG(info->line, "timer %i already running\n", info->line)); \ } \ restore_flags(timer_flags); \ } #define START_FLUSH_FAST_TIMER(info, string) START_FLUSH_FAST_TIMER_TIME(info, string, info->flush_time_usec) #else #define START_FLUSH_FAST_TIMER_TIME(info, string, usec) #define START_FLUSH_FAST_TIMER(info, string) #endif static struct etrax_recv_buffer * alloc_recv_buffer(unsigned int size) { struct etrax_recv_buffer *buffer; if (!(buffer = kmalloc(sizeof *buffer + size, GFP_ATOMIC))) return NULL; buffer->next = NULL; buffer->length = 0; buffer->error = TTY_NORMAL; return buffer; } static void append_recv_buffer(struct e100_serial *info, struct etrax_recv_buffer *buffer) { unsigned long flags; save_flags(flags); cli(); if (!info->first_recv_buffer) info->first_recv_buffer = buffer; else info->last_recv_buffer->next = buffer; info->last_recv_buffer = buffer; info->recv_cnt += buffer->length; if (info->recv_cnt > info->max_recv_cnt) info->max_recv_cnt = info->recv_cnt; restore_flags(flags); } static int add_char_and_flag(struct e100_serial *info, unsigned char data, unsigned char flag) { struct etrax_recv_buffer *buffer; if (info->uses_dma_in) { if (!(buffer = alloc_recv_buffer(4))) return 0; buffer->length = 1; buffer->error = flag; buffer->buffer[0] = data; append_recv_buffer(info, buffer); info->icount.rx++; } else { struct tty_struct *tty = info->tty; *tty->flip.char_buf_ptr = data; *tty->flip.flag_buf_ptr = flag; tty->flip.flag_buf_ptr++; tty->flip.char_buf_ptr++; tty->flip.count++; info->icount.rx++; } return 1; } extern _INLINE_ unsigned int handle_descr_data(struct e100_serial *info, struct etrax_dma_descr *descr, unsigned int recvl) { struct etrax_recv_buffer *buffer = phys_to_virt(descr->buf) - sizeof *buffer; if (info->recv_cnt + recvl > 65536) { printk(KERN_CRIT "%s: Too much pending incoming serial data! Dropping %u bytes.\n", __FUNCTION__, recvl); return 0; } buffer->length = recvl; if (info->errorcode == ERRCODE_SET_BREAK) buffer->error = TTY_BREAK; info->errorcode = 0; append_recv_buffer(info, buffer); if (!(buffer = alloc_recv_buffer(SERIAL_DESCR_BUF_SIZE))) panic("%s: Failed to allocate memory for receive buffer!\n", __FUNCTION__); descr->buf = virt_to_phys(buffer->buffer); return recvl; } static _INLINE_ unsigned int handle_all_descr_data(struct e100_serial *info) { struct etrax_dma_descr *descr; unsigned int recvl; unsigned int ret = 0; while (1) { descr = &info->rec_descr[info->cur_rec_descr]; if (descr == phys_to_virt(*info->idescradr)) break; if (++info->cur_rec_descr == SERIAL_RECV_DESCRIPTORS) info->cur_rec_descr = 0; /* find out how many bytes were read */ /* if the eop bit was not set, all data has been received */ if (!(descr->status & d_eop)) { recvl = descr->sw_len; } else { /* otherwise we find the amount of data received here */ recvl = descr->hw_len; } /* Reset the status information */ descr->status = 0; DFLOW( DEBUG_LOG(info->line, "RX %lu\n", recvl); if (info->tty->stopped) { unsigned char *buf = phys_to_virt(descr->buf); DEBUG_LOG(info->line, "rx 0x%02X\n", buf[0]); DEBUG_LOG(info->line, "rx 0x%02X\n", buf[1]); DEBUG_LOG(info->line, "rx 0x%02X\n", buf[2]); } ); /* update stats */ info->icount.rx += recvl; ret += handle_descr_data(info, descr, recvl); } return ret; } static _INLINE_ void receive_chars_dma(struct e100_serial *info) { struct tty_struct *tty; unsigned char rstat; #ifdef CONFIG_SVINTO_SIM /* No receive in the simulator. Will probably be when the rest of * the serial interface works, and this piece will just be removed. */ return; #endif /* Acknowledge both dma_descr and dma_eop irq in R_DMA_CHx_CLR_INTR */ *info->iclrintradr = IO_STATE(R_DMA_CH6_CLR_INTR, clr_descr, do) | IO_STATE(R_DMA_CH6_CLR_INTR, clr_eop, do); tty = info->tty; if (!tty) /* Something wrong... */ return; #ifdef SERIAL_HANDLE_EARLY_ERRORS if (info->uses_dma_in) e100_enable_serial_data_irq(info); #endif if (info->errorcode == ERRCODE_INSERT_BREAK) add_char_and_flag(info, '\0', TTY_BREAK); handle_all_descr_data(info); /* Read the status register to detect errors */ rstat = info->port[REG_STATUS]; if (rstat & IO_MASK(R_SERIAL0_STATUS, xoff_detect) ) { DFLOW(DEBUG_LOG(info->line, "XOFF detect stat %x\n", rstat)); } if (rstat & SER_ERROR_MASK) { /* If we got an error, we must reset it by reading the * data_in field */ unsigned char data = info->port[REG_DATA]; PROCSTAT(ser_stat[info->line].errors_cnt++); DEBUG_LOG(info->line, "#dERR: s d 0x%04X\n", ((rstat & SER_ERROR_MASK) << 8) | data); if (rstat & SER_PAR_ERR_MASK) add_char_and_flag(info, data, TTY_PARITY); else if (rstat & SER_OVERRUN_MASK) add_char_and_flag(info, data, TTY_OVERRUN); else if (rstat & SER_FRAMING_ERR_MASK) add_char_and_flag(info, data, TTY_FRAME); } START_FLUSH_FAST_TIMER(info, "receive_chars"); /* Restart the receiving DMA */ *info->icmdadr = IO_STATE(R_DMA_CH6_CMD, cmd, restart); } static _INLINE_ int start_recv_dma(struct e100_serial *info) { struct etrax_dma_descr *descr = info->rec_descr; struct etrax_recv_buffer *buffer; int i; /* Set up the receiving descriptors */ for (i = 0; i < SERIAL_RECV_DESCRIPTORS; i++) { if (!(buffer = alloc_recv_buffer(SERIAL_DESCR_BUF_SIZE))) panic("%s: Failed to allocate memory for receive buffer!\n", __FUNCTION__); descr[i].ctrl = d_int; descr[i].buf = virt_to_phys(buffer->buffer); descr[i].sw_len = SERIAL_DESCR_BUF_SIZE; descr[i].hw_len = 0; descr[i].status = 0; descr[i].next = virt_to_phys(&descr[i+1]); } /* Link the last descriptor to the first */ descr[i-1].next = virt_to_phys(&descr[0]); /* Start with the first descriptor in the list */ info->cur_rec_descr = 0; /* Start the DMA */ *info->ifirstadr = virt_to_phys(&descr[info->cur_rec_descr]); *info->icmdadr = IO_STATE(R_DMA_CH6_CMD, cmd, start); /* Input DMA should be running now */ return 1; } static void start_receive(struct e100_serial *info) { #ifdef CONFIG_SVINTO_SIM /* No receive in the simulator. Will probably be when the rest of * the serial interface works, and this piece will just be removed. */ return; #endif info->tty->flip.count = 0; if (info->uses_dma_in) { /* reset the input dma channel to be sure it works */ *info->icmdadr = IO_STATE(R_DMA_CH6_CMD, cmd, reset); while (IO_EXTRACT(R_DMA_CH6_CMD, cmd, *info->icmdadr) == IO_STATE_VALUE(R_DMA_CH6_CMD, cmd, reset)); start_recv_dma(info); } } static _INLINE_ void status_handle(struct e100_serial *info, unsigned short status) { } /* the bits in the MASK2 register are laid out like this: DMAI_EOP DMAI_DESCR DMAO_EOP DMAO_DESCR where I is the input channel and O is the output channel for the port. info->irq is the bit number for the DMAO_DESCR so to check the others we shift info->irq to the left. */ /* dma output channel interrupt handler this interrupt is called from DMA2(ser2), DMA4(ser3), DMA6(ser0) or DMA8(ser1) when they have finished a descriptor with the intr flag set. */ static irqreturn_t tr_interrupt(int irq, void *dev_id, struct pt_regs * regs) { struct e100_serial *info; unsigned long ireg; int i; int handled = 0; #ifdef CONFIG_SVINTO_SIM /* No receive in the simulator. Will probably be when the rest of * the serial interface works, and this piece will just be removed. */ { const char *s = "What? tr_interrupt in simulator??\n"; SIMCOUT(s,strlen(s)); } return IRQ_HANDLED; #endif /* find out the line that caused this irq and get it from rs_table */ ireg = *R_IRQ_MASK2_RD; /* get the active irq bits for the dma channels */ for (i = 0; i < NR_PORTS; i++) { info = rs_table + i; if (!info->enabled || !info->uses_dma_out) continue; /* check for dma_descr (don't need to check for dma_eop in output dma for serial */ if (ireg & info->irq) { handled = 1; /* we can send a new dma bunch. make it so. */ DINTR2(DEBUG_LOG(info->line, "tr_interrupt %i\n", i)); /* Read jiffies_usec first, * we want this time to be as late as possible */ PROCSTAT(ser_stat[info->line].tx_dma_ints++); info->last_tx_active_usec = GET_JIFFIES_USEC(); info->last_tx_active = jiffies; transmit_chars_dma(info); } /* FIXME: here we should really check for a change in the status lines and if so call status_handle(info) */ } return IRQ_RETVAL(handled); } /* tr_interrupt */ /* dma input channel interrupt handler */ static irqreturn_t rec_interrupt(int irq, void *dev_id, struct pt_regs * regs) { struct e100_serial *info; unsigned long ireg; int i; int handled = 0; #ifdef CONFIG_SVINTO_SIM /* No receive in the simulator. Will probably be when the rest of * the serial interface works, and this piece will just be removed. */ { const char *s = "What? rec_interrupt in simulator??\n"; SIMCOUT(s,strlen(s)); } return IRQ_HANDLED; #endif /* find out the line that caused this irq and get it from rs_table */ ireg = *R_IRQ_MASK2_RD; /* get the active irq bits for the dma channels */ for (i = 0; i < NR_PORTS; i++) { info = rs_table + i; if (!info->enabled || !info->uses_dma_in) continue; /* check for both dma_eop and dma_descr for the input dma channel */ if (ireg & ((info->irq << 2) | (info->irq << 3))) { handled = 1; /* we have received something */ receive_chars_dma(info); } /* FIXME: here we should really check for a change in the status lines and if so call status_handle(info) */ } return IRQ_RETVAL(handled); } /* rec_interrupt */ static _INLINE_ int force_eop_if_needed(struct e100_serial *info) { /* We check data_avail bit to determine if data has * arrived since last time */ unsigned char rstat = info->port[REG_STATUS]; /* error or datavail? */ if (rstat & SER_ERROR_MASK) { /* Some error has occurred. If there has been valid data, an * EOP interrupt will be made automatically. If no data, the * normal ser_interrupt should be enabled and handle it. * So do nothing! */ DEBUG_LOG(info->line, "timeout err: rstat 0x%03X\n", rstat | (info->line << 8)); return 0; } if (rstat & SER_DATA_AVAIL_MASK) { /* Ok data, no error, count it */ TIMERD(DEBUG_LOG(info->line, "timeout: rstat 0x%03X\n", rstat | (info->line << 8))); /* Read data to clear status flags */ (void)info->port[REG_DATA]; info->forced_eop = 0; START_FLUSH_FAST_TIMER(info, "magic"); return 0; } /* hit the timeout, force an EOP for the input * dma channel if we haven't already */ if (!info->forced_eop) { info->forced_eop = 1; PROCSTAT(ser_stat[info->line].timeout_flush_cnt++); TIMERD(DEBUG_LOG(info->line, "timeout EOP %i\n", info->line)); FORCE_EOP(info); } return 1; } extern _INLINE_ void flush_to_flip_buffer(struct e100_serial *info) { struct tty_struct *tty; struct etrax_recv_buffer *buffer; unsigned int length; unsigned long flags; int max_flip_size; if (!info->first_recv_buffer) return; save_flags(flags); cli(); if (!(tty = info->tty)) { restore_flags(flags); return; } length = tty->flip.count; /* Don't flip more than the ldisc has room for. * The return value from ldisc.receive_room(tty) - might not be up to * date, the previous flip of up to TTY_FLIPBUF_SIZE might be on the * processed and not accounted for yet. * Since we use DMA, 1 SERIAL_DESCR_BUF_SIZE could be on the way. * Lets buffer data here and let flow control take care of it. * Since we normally flip large chunks, the ldisc don't react * with throttle until too late if we flip to much. */ max_flip_size = tty->ldisc.receive_room(tty); if (max_flip_size < 0) max_flip_size = 0; if (max_flip_size <= (TTY_FLIPBUF_SIZE + /* Maybe not accounted for */ length + info->recv_cnt + /* We have this queued */ 2*SERIAL_DESCR_BUF_SIZE + /* This could be on the way */ TTY_THRESHOLD_THROTTLE)) { /* Some slack */ /* check TTY_THROTTLED first so it indicates our state */ if (!test_and_set_bit(TTY_THROTTLED, &tty->flags)) { DFLOW(DEBUG_LOG(info->line,"flush_to_flip throttles room %lu\n", max_flip_size)); rs_throttle(tty); } #if 0 else if (max_flip_size <= (TTY_FLIPBUF_SIZE + /* Maybe not accounted for */ length + info->recv_cnt + /* We have this queued */ SERIAL_DESCR_BUF_SIZE + /* This could be on the way */ TTY_THRESHOLD_THROTTLE)) { /* Some slack */ DFLOW(DEBUG_LOG(info->line,"flush_to_flip throttles again! %lu\n", max_flip_size)); rs_throttle(tty); } #endif } if (max_flip_size > TTY_FLIPBUF_SIZE) max_flip_size = TTY_FLIPBUF_SIZE; while ((buffer = info->first_recv_buffer) && length < max_flip_size) { unsigned int count = buffer->length; if (length + count > max_flip_size) count = max_flip_size - length; memcpy(tty->flip.char_buf_ptr + length, buffer->buffer, count); memset(tty->flip.flag_buf_ptr + length, TTY_NORMAL, count); tty->flip.flag_buf_ptr[length] = buffer->error; length += count; info->recv_cnt -= count; DFLIP(DEBUG_LOG(info->line,"flip: %i\n", length)); if (count == buffer->length) { info->first_recv_buffer = buffer->next; kfree(buffer); } else { buffer->length -= count; memmove(buffer->buffer, buffer->buffer + count, buffer->length); buffer->error = TTY_NORMAL; } } if (!info->first_recv_buffer) info->last_recv_buffer = NULL; tty->flip.count = length; DFLIP(if (tty->ldisc.chars_in_buffer(tty) > 3500) { DEBUG_LOG(info->line, "ldisc %lu\n", tty->ldisc.chars_in_buffer(tty)); DEBUG_LOG(info->line, "flip.count %lu\n", tty->flip.count); } ); restore_flags(flags); DFLIP( if (1) { if (test_bit(TTY_DONT_FLIP, &tty->flags)) { DEBUG_LOG(info->line, "*** TTY_DONT_FLIP set flip.count %i ***\n", tty->flip.count); DEBUG_LOG(info->line, "*** recv_cnt %i\n", info->recv_cnt); } else { } DEBUG_LOG(info->line, "*** rxtot %i\n", info->icount.rx); DEBUG_LOG(info->line, "ldisc %lu\n", tty->ldisc.chars_in_buffer(tty)); DEBUG_LOG(info->line, "room %lu\n", tty->ldisc.receive_room(tty)); } ); /* this includes a check for low-latency */ tty_flip_buffer_push(tty); } static _INLINE_ void check_flush_timeout(struct e100_serial *info) { /* Flip what we've got (if we can) */ flush_to_flip_buffer(info); /* We might need to flip later, but not to fast * since the system is busy processing input... */ if (info->first_recv_buffer) START_FLUSH_FAST_TIMER_TIME(info, "flip", 2000); /* Force eop last, since data might have come while we're processing * and if we started the slow timer above, we won't start a fast * below. */ force_eop_if_needed(info); } #ifdef CONFIG_ETRAX_SERIAL_FAST_TIMER static void flush_timeout_function(unsigned long data) { struct e100_serial *info = (struct e100_serial *)data; fast_timers[info->line].function = NULL; serial_fast_timer_expired++; TIMERD(DEBUG_LOG(info->line, "flush_timout %i ", info->line)); TIMERD(DEBUG_LOG(info->line, "num expired: %i\n", serial_fast_timer_expired)); check_flush_timeout(info); } #else /* dma fifo/buffer timeout handler forces an end-of-packet for the dma input channel if no chars have been received for CONFIG_ETRAX_SERIAL_RX_TIMEOUT_TICKS/100 s. */ static struct timer_list flush_timer; static void timed_flush_handler(unsigned long ptr) { struct e100_serial *info; int i; #ifdef CONFIG_SVINTO_SIM return; #endif for (i = 0; i < NR_PORTS; i++) { info = rs_table + i; if (info->uses_dma_in) check_flush_timeout(info); } /* restart flush timer */ mod_timer(&flush_timer, jiffies + CONFIG_ETRAX_SERIAL_RX_TIMEOUT_TICKS); } #endif #ifdef SERIAL_HANDLE_EARLY_ERRORS /* If there is an error (ie break) when the DMA is running and * there are no bytes in the fifo the DMA is stopped and we get no * eop interrupt. Thus we have to monitor the first bytes on a DMA * transfer, and if it is without error we can turn the serial * interrupts off. */ /* BREAK handling on ETRAX 100: ETRAX will generate interrupt although there is no stop bit between the characters. Depending on how long the break sequence is, the end of the breaksequence will look differently: | indicates start/end of a character. B= Break character (0x00) with framing error. E= Error byte with parity error received after B characters. F= "Faked" valid byte received immediately after B characters. V= Valid byte 1. B BL ___________________________ V .._|__________|__________| |valid data | Multiple frame errors with data == 0x00 (B), the timing matches up "perfectly" so no extra ending char is detected. The RXD pin is 1 in the last interrupt, in that case we set info->errorcode = ERRCODE_INSERT_BREAK, but we can't really know if another byte will come and this really is case 2. below (e.g F=0xFF or 0xFE) If RXD pin is 0 we can expect another character (see 2. below). 2. B B E or F__________________..__ V .._|__________|__________|______ | |valid data "valid" or parity error Multiple frame errors with data == 0x00 (B), but the part of the break trigs is interpreted as a start bit (and possibly some 0 bits followed by a number of 1 bits and a stop bit). Depending on parity settings etc. this last character can be either a fake "valid" char (F) or have a parity error (E). If the character is valid it will be put in the buffer, we set info->errorcode = ERRCODE_SET_BREAK so the receive interrupt will set the flags so the tty will handle it, if it's an error byte it will not be put in the buffer and we set info->errorcode = ERRCODE_INSERT_BREAK. To distinguish a V byte in 1. from an F byte in 2. we keep a timestamp of the last faulty char (B) and compares it with the current time: If the time elapsed time is less then 2*char_time_usec we will assume it's a faked F char and not a Valid char and set info->errorcode = ERRCODE_SET_BREAK. Flaws in the above solution: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ We use the timer to distinguish a F character from a V character, if a V character is to close after the break we might make the wrong decision. TODO: The break will be delayed until an F or V character is received. */ extern _INLINE_ struct e100_serial * handle_ser_rx_interrupt_no_dma(struct e100_serial *info) { unsigned long data_read; struct tty_struct *tty = info->tty; if (!tty) { printk("!NO TTY!\n"); return info; } if (tty->flip.count >= TTY_FLIPBUF_SIZE - TTY_THRESHOLD_THROTTLE) { /* check TTY_THROTTLED first so it indicates our state */ if (!test_and_set_bit(TTY_THROTTLED, &tty->flags)) { DFLOW(DEBUG_LOG(info->line, "rs_throttle flip.count: %i\n", tty->flip.count)); rs_throttle(tty); } } if (tty->flip.count >= TTY_FLIPBUF_SIZE) { DEBUG_LOG(info->line, "force FLIP! %i\n", tty->flip.count); tty->flip.work.func((void *) tty); if (tty->flip.count >= TTY_FLIPBUF_SIZE) { DEBUG_LOG(info->line, "FLIP FULL! %i\n", tty->flip.count); return info; /* if TTY_DONT_FLIP is set */ } } /* Read data and status at the same time */ data_read = *((unsigned long *)&info->port[REG_DATA_STATUS32]); more_data: if (data_read & IO_MASK(R_SERIAL0_READ, xoff_detect) ) { DFLOW(DEBUG_LOG(info->line, "XOFF detect\n", 0)); } DINTR2(DEBUG_LOG(info->line, "ser_rx %c\n", IO_EXTRACT(R_SERIAL0_READ, data_in, data_read))); if (data_read & ( IO_MASK(R_SERIAL0_READ, framing_err) | IO_MASK(R_SERIAL0_READ, par_err) | IO_MASK(R_SERIAL0_READ, overrun) )) { /* An error */ info->last_rx_active_usec = GET_JIFFIES_USEC(); info->last_rx_active = jiffies; DINTR1(DEBUG_LOG(info->line, "ser_rx err stat_data %04X\n", data_read)); DLOG_INT_TRIG( if (!log_int_trig1_pos) { log_int_trig1_pos = log_int_pos; log_int(rdpc(), 0, 0); } ); if ( ((data_read & IO_MASK(R_SERIAL0_READ, data_in)) == 0) && (data_read & IO_MASK(R_SERIAL0_READ, framing_err)) ) { /* Most likely a break, but we get interrupts over and * over again. */ if (!info->break_detected_cnt) { DEBUG_LOG(info->line, "#BRK start\n", 0); } if (data_read & IO_MASK(R_SERIAL0_READ, rxd)) { /* The RX pin is high now, so the break * must be over, but.... * we can't really know if we will get another * last byte ending the break or not. * And we don't know if the byte (if any) will * have an error or look valid. */ DEBUG_LOG(info->line, "# BL BRK\n", 0); info->errorcode = ERRCODE_INSERT_BREAK; } info->break_detected_cnt++; } else { /* The error does not look like a break, but could be * the end of one */ if (info->break_detected_cnt) { DEBUG_LOG(info->line, "EBRK %i\n", info->break_detected_cnt); info->errorcode = ERRCODE_INSERT_BREAK; } else { if (info->errorcode == ERRCODE_INSERT_BREAK) { info->icount.brk++; *tty->flip.char_buf_ptr = 0; *tty->flip.flag_buf_ptr = TTY_BREAK; tty->flip.flag_buf_ptr++; tty->flip.char_buf_ptr++; tty->flip.count++; info->icount.rx++; } *tty->flip.char_buf_ptr = IO_EXTRACT(R_SERIAL0_READ, data_in, data_read); if (data_read & IO_MASK(R_SERIAL0_READ, par_err)) { info->icount.parity++; *tty->flip.flag_buf_ptr = TTY_PARITY; } else if (data_read & IO_MASK(R_SERIAL0_READ, overrun)) { info->icount.overrun++; *tty->flip.flag_buf_ptr = TTY_OVERRUN; } else if (data_read & IO_MASK(R_SERIAL0_READ, framing_err)) { info->icount.frame++; *tty->flip.flag_buf_ptr = TTY_FRAME; } info->errorcode = 0; } info->break_detected_cnt = 0; } } else if (data_read & IO_MASK(R_SERIAL0_READ, data_avail)) { /* No error */ DLOG_INT_TRIG( if (!log_int_trig1_pos) { if (log_int_pos >= log_int_size) { log_int_pos = 0; } log_int_trig0_pos = log_int_pos; log_int(rdpc(), 0, 0); } ); *tty->flip.char_buf_ptr = IO_EXTRACT(R_SERIAL0_READ, data_in, data_read); *tty->flip.flag_buf_ptr = 0; } else { DEBUG_LOG(info->line, "ser_rx int but no data_avail %08lX\n", data_read); } tty->flip.flag_buf_ptr++; tty->flip.char_buf_ptr++; tty->flip.count++; info->icount.rx++; data_read = *((unsigned long *)&info->port[REG_DATA_STATUS32]); if (data_read & IO_MASK(R_SERIAL0_READ, data_avail)) { DEBUG_LOG(info->line, "ser_rx %c in loop\n", IO_EXTRACT(R_SERIAL0_READ, data_in, data_read)); goto more_data; } tty_flip_buffer_push(info->tty); return info; } extern _INLINE_ struct e100_serial* handle_ser_rx_interrupt(struct e100_serial *info) { unsigned char rstat; #ifdef SERIAL_DEBUG_INTR printk("Interrupt from serport %d\n", i); #endif /* DEBUG_LOG(info->line, "ser_interrupt stat %03X\n", rstat | (i << 8)); */ if (!info->uses_dma_in) { return handle_ser_rx_interrupt_no_dma(info); } /* DMA is used */ rstat = info->port[REG_STATUS]; if (rstat & IO_MASK(R_SERIAL0_STATUS, xoff_detect) ) { DFLOW(DEBUG_LOG(info->line, "XOFF detect\n", 0)); } if (rstat & SER_ERROR_MASK) { unsigned char data; info->last_rx_active_usec = GET_JIFFIES_USEC(); info->last_rx_active = jiffies; /* If we got an error, we must reset it by reading the * data_in field */ data = info->port[REG_DATA]; DINTR1(DEBUG_LOG(info->line, "ser_rx! %c\n", data)); DINTR1(DEBUG_LOG(info->line, "ser_rx err stat %02X\n", rstat)); if (!data && (rstat & SER_FRAMING_ERR_MASK)) { /* Most likely a break, but we get interrupts over and * over again. */ if (!info->break_detected_cnt) { DEBUG_LOG(info->line, "#BRK start\n", 0); } if (rstat & SER_RXD_MASK) { /* The RX pin is high now, so the break * must be over, but.... * we can't really know if we will get another * last byte ending the break or not. * And we don't know if the byte (if any) will * have an error or look valid. */ DEBUG_LOG(info->line, "# BL BRK\n", 0); info->errorcode = ERRCODE_INSERT_BREAK; } info->break_detected_cnt++; } else { /* The error does not look like a break, but could be * the end of one */ if (info->break_detected_cnt) { DEBUG_LOG(info->line, "EBRK %i\n", info->break_detected_cnt); info->errorcode = ERRCODE_INSERT_BREAK; } else { if (info->errorcode == ERRCODE_INSERT_BREAK) { info->icount.brk++; add_char_and_flag(info, '\0', TTY_BREAK); } if (rstat & SER_PAR_ERR_MASK) { info->icount.parity++; add_char_and_flag(info, data, TTY_PARITY); } else if (rstat & SER_OVERRUN_MASK) { info->icount.overrun++; add_char_and_flag(info, data, TTY_OVERRUN); } else if (rstat & SER_FRAMING_ERR_MASK) { info->icount.frame++; add_char_and_flag(info, data, TTY_FRAME); } info->errorcode = 0; } info->break_detected_cnt = 0; DEBUG_LOG(info->line, "#iERR s d %04X\n", ((rstat & SER_ERROR_MASK) << 8) | data); } PROCSTAT(ser_stat[info->line].early_errors_cnt++); } else { /* It was a valid byte, now let the DMA do the rest */ unsigned long curr_time_u = GET_JIFFIES_USEC(); unsigned long curr_time = jiffies; if (info->break_detected_cnt) { /* Detect if this character is a new valid char or the * last char in a break sequence: If LSBits are 0 and * MSBits are high AND the time is close to the * previous interrupt we should discard it. */ long elapsed_usec = (curr_time - info->last_rx_active) * (1000000/HZ) + curr_time_u - info->last_rx_active_usec; if (elapsed_usec < 2*info->char_time_usec) { DEBUG_LOG(info->line, "FBRK %i\n", info->line); /* Report as BREAK (error) and let * receive_chars_dma() handle it */ info->errorcode = ERRCODE_SET_BREAK; } else { DEBUG_LOG(info->line, "Not end of BRK (V)%i\n", info->line); } DEBUG_LOG(info->line, "num brk %i\n", info->break_detected_cnt); } #ifdef SERIAL_DEBUG_INTR printk("** OK, disabling ser_interrupts\n"); #endif e100_disable_serial_data_irq(info); DINTR2(DEBUG_LOG(info->line, "ser_rx OK %d\n", info->line)); info->break_detected_cnt = 0; PROCSTAT(ser_stat[info->line].ser_ints_ok_cnt++); } /* Restarting the DMA never hurts */ *info->icmdadr = IO_STATE(R_DMA_CH6_CMD, cmd, restart); START_FLUSH_FAST_TIMER(info, "ser_int"); return info; } /* handle_ser_rx_interrupt */ extern _INLINE_ void handle_ser_tx_interrupt(struct e100_serial *info) { unsigned long flags; if (info->x_char) { unsigned char rstat; DFLOW(DEBUG_LOG(info->line, "tx_int: xchar 0x%02X\n", info->x_char)); save_flags(flags); cli(); rstat = info->port[REG_STATUS]; DFLOW(DEBUG_LOG(info->line, "stat %x\n", rstat)); info->port[REG_TR_DATA] = info->x_char; info->icount.tx++; info->x_char = 0; /* We must enable since it is disabled in ser_interrupt */ e100_enable_serial_tx_ready_irq(info); restore_flags(flags); return; } if (info->uses_dma_out) { unsigned char rstat; int i; /* We only use normal tx interrupt when sending x_char */ DFLOW(DEBUG_LOG(info->line, "tx_int: xchar sent\n", 0)); save_flags(flags); cli(); rstat = info->port[REG_STATUS]; DFLOW(DEBUG_LOG(info->line, "stat %x\n", rstat)); e100_disable_serial_tx_ready_irq(info); if (info->tty->stopped) rs_stop(info->tty); /* Enable the DMA channel and tell it to continue */ e100_enable_txdma_channel(info); /* Wait 12 cycles before doing the DMA command */ for(i = 6; i > 0; i--) nop(); *info->ocmdadr = IO_STATE(R_DMA_CH6_CMD, cmd, continue); restore_flags(flags); return; } /* Normal char-by-char interrupt */ if (info->xmit.head == info->xmit.tail || info->tty->stopped || info->tty->hw_stopped) { DFLOW(DEBUG_LOG(info->line, "tx_int: stopped %i\n", info->tty->stopped)); e100_disable_serial_tx_ready_irq(info); info->tr_running = 0; return; } DINTR2(DEBUG_LOG(info->line, "tx_int %c\n", info->xmit.buf[info->xmit.tail])); /* Send a byte, rs485 timing is critical so turn of ints */ save_flags(flags); cli(); info->port[REG_TR_DATA] = info->xmit.buf[info->xmit.tail]; info->xmit.tail = (info->xmit.tail + 1) & (SERIAL_XMIT_SIZE-1); info->icount.tx++; if (info->xmit.head == info->xmit.tail) { #if defined(CONFIG_ETRAX_RS485) && defined(CONFIG_ETRAX_FAST_TIMER) if (info->rs485.enabled) { /* Set a short timer to toggle RTS */ start_one_shot_timer(&fast_timers_rs485[info->line], rs485_toggle_rts_timer_function, (unsigned long)info, info->char_time_usec*2, "RS-485"); } #endif /* RS485 */ info->last_tx_active_usec = GET_JIFFIES_USEC(); info->last_tx_active = jiffies; e100_disable_serial_tx_ready_irq(info); info->tr_running = 0; DFLOW(DEBUG_LOG(info->line, "tx_int: stop2\n", 0)); } else { /* We must enable since it is disabled in ser_interrupt */ e100_enable_serial_tx_ready_irq(info); } restore_flags(flags); if (CIRC_CNT(info->xmit.head, info->xmit.tail, SERIAL_XMIT_SIZE) < WAKEUP_CHARS) rs_sched_event(info, RS_EVENT_WRITE_WAKEUP); } /* handle_ser_tx_interrupt */ /* result of time measurements: * RX duration 54-60 us when doing something, otherwise 6-9 us * ser_int duration: just sending: 8-15 us normally, up to 73 us */ static irqreturn_t ser_interrupt(int irq, void *dev_id, struct pt_regs *regs) { static volatile int tx_started = 0; struct e100_serial *info; int i; unsigned long flags; unsigned long irq_mask1_rd; unsigned long data_mask = (1 << (8+2*0)); /* ser0 data_avail */ int handled = 0; static volatile unsigned long reentered_ready_mask = 0; save_flags(flags); cli(); irq_mask1_rd = *R_IRQ_MASK1_RD; /* First handle all rx interrupts with ints disabled */ info = rs_table; irq_mask1_rd &= e100_ser_int_mask; for (i = 0; i < NR_PORTS; i++) { /* Which line caused the data irq? */ if (irq_mask1_rd & data_mask) { handled = 1; handle_ser_rx_interrupt(info); } info += 1; data_mask <<= 2; } /* Handle tx interrupts with interrupts enabled so we * can take care of new data interrupts while transmitting * We protect the tx part with the tx_started flag. * We disable the tr_ready interrupts we are about to handle and * unblock the serial interrupt so new serial interrupts may come. * * If we get a new interrupt: * - it migth be due to synchronous serial ports. * - serial irq will be blocked by general irq handler. * - async data will be handled above (sync will be ignored). * - tx_started flag will prevent us from trying to send again and * we will exit fast - no need to unblock serial irq. * - Next (sync) serial interrupt handler will be runned with * disabled interrupt due to restore_flags() at end of function, * so sync handler will not be preempted or reentered. */ if (!tx_started) { unsigned long ready_mask; unsigned long tx_started = 1; /* Only the tr_ready interrupts left */ irq_mask1_rd &= (IO_MASK(R_IRQ_MASK1_RD, ser0_ready) | IO_MASK(R_IRQ_MASK1_RD, ser1_ready) | IO_MASK(R_IRQ_MASK1_RD, ser2_ready) | IO_MASK(R_IRQ_MASK1_RD, ser3_ready)); while (irq_mask1_rd) { /* Disable those we are about to handle */ *R_IRQ_MASK1_CLR = irq_mask1_rd; /* Unblock the serial interrupt */ *R_VECT_MASK_SET = IO_STATE(R_VECT_MASK_SET, serial, set); sti(); ready_mask = (1 << (8+1+2*0)); /* ser0 tr_ready */ info = rs_table; for (i = 0; i < NR_PORTS; i++) { /* Which line caused the ready irq? */ if (irq_mask1_rd & ready_mask) { handled = 1; handle_ser_tx_interrupt(info); } info += 1; ready_mask <<= 2; } /* handle_ser_tx_interrupt enables tr_ready interrupts */ cli(); /* Handle reentered TX interrupt */ irq_mask1_rd = reentered_ready_mask; } cli(); tx_started = 0; } else { unsigned long ready_mask; ready_mask = irq_mask1_rd & (IO_MASK(R_IRQ_MASK1_RD, ser0_ready) | IO_MASK(R_IRQ_MASK1_RD, ser1_ready) | IO_MASK(R_IRQ_MASK1_RD, ser2_ready) | IO_MASK(R_IRQ_MASK1_RD, ser3_ready)); if (ready_mask) { reentered_ready_mask |= ready_mask; /* Disable those we are about to handle */ *R_IRQ_MASK1_CLR = ready_mask; DFLOW(DEBUG_LOG(SERIAL_DEBUG_LINE, "ser_int reentered with TX %X\n", ready_mask)); } } restore_flags(flags); return IRQ_RETVAL(handled); } /* ser_interrupt */ #endif /* * ------------------------------------------------------------------- * Here ends the serial interrupt routines. * ------------------------------------------------------------------- */ /* * This routine is used to handle the "bottom half" processing for the * serial driver, known also the "software interrupt" processing. * This processing is done at the kernel interrupt level, after the * rs_interrupt() has returned, BUT WITH INTERRUPTS TURNED ON. This * is where time-consuming activities which can not be done in the * interrupt driver proper are done; the interrupt driver schedules * them using rs_sched_event(), and they get done here. */ static void do_softint(void *private_) { struct e100_serial *info = (struct e100_serial *) private_; struct tty_struct *tty; tty = info->tty; if (!tty) return; if (test_and_clear_bit(RS_EVENT_WRITE_WAKEUP, &info->event)) { if ((tty->flags & (1 << TTY_DO_WRITE_WAKEUP)) && tty->ldisc.write_wakeup) (tty->ldisc.write_wakeup)(tty); wake_up_interruptible(&tty->write_wait); } } static int startup(struct e100_serial * info) { unsigned long flags; unsigned long xmit_page; int i; xmit_page = get_zeroed_page(GFP_KERNEL); if (!xmit_page) return -ENOMEM; save_flags(flags); cli(); /* if it was already initialized, skip this */ if (info->flags & ASYNC_INITIALIZED) { restore_flags(flags); free_page(xmit_page); return 0; } if (info->xmit.buf) free_page(xmit_page); else info->xmit.buf = (unsigned char *) xmit_page; #ifdef SERIAL_DEBUG_OPEN printk("starting up ttyS%d (xmit_buf 0x%p)...\n", info->line, info->xmit.buf); #endif #ifdef CONFIG_SVINTO_SIM /* Bits and pieces collected from below. Better to have them in one ifdef:ed clause than to mix in a lot of ifdefs, right? */ if (info->tty) clear_bit(TTY_IO_ERROR, &info->tty->flags); info->xmit.head = info->xmit.tail = 0; info->first_recv_buffer = info->last_recv_buffer = NULL; info->recv_cnt = info->max_recv_cnt = 0; for (i = 0; i < SERIAL_RECV_DESCRIPTORS; i++) info->rec_descr[i].buf = NULL; /* No real action in the simulator, but may set info important to ioctl. */ change_speed(info); #else /* * Clear the FIFO buffers and disable them * (they will be reenabled in change_speed()) */ /* * Reset the DMA channels and make sure their interrupts are cleared */ if (info->dma_in_enabled) { info->uses_dma_in = 1; e100_enable_rxdma_channel(info); *info->icmdadr = IO_STATE(R_DMA_CH6_CMD, cmd, reset); /* Wait until reset cycle is complete */ while (IO_EXTRACT(R_DMA_CH6_CMD, cmd, *info->icmdadr) == IO_STATE_VALUE(R_DMA_CH6_CMD, cmd, reset)); /* Make sure the irqs are cleared */ *info->iclrintradr = IO_STATE(R_DMA_CH6_CLR_INTR, clr_descr, do) | IO_STATE(R_DMA_CH6_CLR_INTR, clr_eop, do); } else { e100_disable_rxdma_channel(info); } if (info->dma_out_enabled) { info->uses_dma_out = 1; e100_enable_txdma_channel(info); *info->ocmdadr = IO_STATE(R_DMA_CH6_CMD, cmd, reset); while (IO_EXTRACT(R_DMA_CH6_CMD, cmd, *info->ocmdadr) == IO_STATE_VALUE(R_DMA_CH6_CMD, cmd, reset)); /* Make sure the irqs are cleared */ *info->oclrintradr = IO_STATE(R_DMA_CH6_CLR_INTR, clr_descr, do) | IO_STATE(R_DMA_CH6_CLR_INTR, clr_eop, do); } else { e100_disable_txdma_channel(info); } if (info->tty) clear_bit(TTY_IO_ERROR, &info->tty->flags); info->xmit.head = info->xmit.tail = 0; info->first_recv_buffer = info->last_recv_buffer = NULL; info->recv_cnt = info->max_recv_cnt = 0; for (i = 0; i < SERIAL_RECV_DESCRIPTORS; i++) info->rec_descr[i].buf = 0; /* * and set the speed and other flags of the serial port * this will start the rx/tx as well */ #ifdef SERIAL_HANDLE_EARLY_ERRORS e100_enable_serial_data_irq(info); #endif change_speed(info); /* dummy read to reset any serial errors */ (void)info->port[REG_DATA]; /* enable the interrupts */ if (info->uses_dma_out) e100_enable_txdma_irq(info); e100_enable_rx_irq(info); info->tr_running = 0; /* to be sure we don't lock up the transmitter */ /* setup the dma input descriptor and start dma */ start_receive(info); /* for safety, make sure the descriptors last result is 0 bytes written */ info->tr_descr.sw_len = 0; info->tr_descr.hw_len = 0; info->tr_descr.status = 0; /* enable RTS/DTR last */ e100_rts(info, 1); e100_dtr(info, 1); #endif /* CONFIG_SVINTO_SIM */ info->flags |= ASYNC_INITIALIZED; restore_flags(flags); return 0; } /* * This routine will shutdown a serial port; interrupts are disabled, and * DTR is dropped if the hangup on close termio flag is on. */ static void shutdown(struct e100_serial * info) { unsigned long flags; struct etrax_dma_descr *descr = info->rec_descr; struct etrax_recv_buffer *buffer; int i; #ifndef CONFIG_SVINTO_SIM /* shut down the transmitter and receiver */ DFLOW(DEBUG_LOG(info->line, "shutdown %i\n", info->line)); e100_disable_rx(info); info->port[REG_TR_CTRL] = (info->tx_ctrl &= ~0x40); /* disable interrupts, reset dma channels */ if (info->uses_dma_in) { e100_disable_rxdma_irq(info); *info->icmdadr = IO_STATE(R_DMA_CH6_CMD, cmd, reset); info->uses_dma_in = 0; } else { e100_disable_serial_data_irq(info); } if (info->uses_dma_out) { e100_disable_txdma_irq(info); info->tr_running = 0; *info->ocmdadr = IO_STATE(R_DMA_CH6_CMD, cmd, reset); info->uses_dma_out = 0; } else { e100_disable_serial_tx_ready_irq(info); info->tr_running = 0; } #endif /* CONFIG_SVINTO_SIM */ if (!(info->flags & ASYNC_INITIALIZED)) return; #ifdef SERIAL_DEBUG_OPEN printk("Shutting down serial port %d (irq %d)....\n", info->line, info->irq); #endif save_flags(flags); cli(); /* Disable interrupts */ if (info->xmit.buf) { free_page((unsigned long)info->xmit.buf); info->xmit.buf = NULL; } for (i = 0; i < SERIAL_RECV_DESCRIPTORS; i++) if (descr[i].buf) { buffer = phys_to_virt(descr[i].buf) - sizeof *buffer; kfree(buffer); descr[i].buf = 0; } if (!info->tty || (info->tty->termios->c_cflag & HUPCL)) { /* hang up DTR and RTS if HUPCL is enabled */ e100_dtr(info, 0); e100_rts(info, 0); /* could check CRTSCTS before doing this */ } if (info->tty) set_bit(TTY_IO_ERROR, &info->tty->flags); info->flags &= ~ASYNC_INITIALIZED; restore_flags(flags); } /* change baud rate and other assorted parameters */ static void change_speed(struct e100_serial *info) { unsigned int cflag; unsigned long xoff; unsigned long flags; /* first some safety checks */ if (!info->tty || !info->tty->termios) return; if (!info->port) return; cflag = info->tty->termios->c_cflag; /* possibly, the tx/rx should be disabled first to do this safely */ /* change baud-rate and write it to the hardware */ if ((info->flags & ASYNC_SPD_MASK) == ASYNC_SPD_CUST) { /* Special baudrate */ u32 mask = 0xFF << (info->line*8); /* Each port has 8 bits */ unsigned long alt_source = IO_STATE(R_ALT_SER_BAUDRATE, ser0_rec, normal) | IO_STATE(R_ALT_SER_BAUDRATE, ser0_tr, normal); /* R_ALT_SER_BAUDRATE selects the source */ DBAUD(printk("Custom baudrate: baud_base/divisor %lu/%i\n", (unsigned long)info->baud_base, info->custom_divisor)); if (info->baud_base == SERIAL_PRESCALE_BASE) { /* 0, 2-65535 (0=65536) */ u16 divisor = info->custom_divisor; /* R_SERIAL_PRESCALE (upper 16 bits of R_CLOCK_PRESCALE) */ /* baudrate is 3.125MHz/custom_divisor */ alt_source = IO_STATE(R_ALT_SER_BAUDRATE, ser0_rec, prescale) | IO_STATE(R_ALT_SER_BAUDRATE, ser0_tr, prescale); alt_source = 0x11; DBAUD(printk("Writing SERIAL_PRESCALE: divisor %i\n", divisor)); *R_SERIAL_PRESCALE = divisor; info->baud = SERIAL_PRESCALE_BASE/divisor; } #ifdef CONFIG_ETRAX_EXTERN_PB6CLK_ENABLED else if ((info->baud_base==CONFIG_ETRAX_EXTERN_PB6CLK_FREQ/8 && info->custom_divisor == 1) || (info->baud_base==CONFIG_ETRAX_EXTERN_PB6CLK_FREQ && info->custom_divisor == 8)) { /* ext_clk selected */ alt_source = IO_STATE(R_ALT_SER_BAUDRATE, ser0_rec, extern) | IO_STATE(R_ALT_SER_BAUDRATE, ser0_tr, extern); DBAUD(printk("using external baudrate: %lu\n", CONFIG_ETRAX_EXTERN_PB6CLK_FREQ/8)); info->baud = CONFIG_ETRAX_EXTERN_PB6CLK_FREQ/8; } } #endif else { /* Bad baudbase, we don't support using timer0 * for baudrate. */ printk(KERN_WARNING "Bad baud_base/custom_divisor: %lu/%i\n", (unsigned long)info->baud_base, info->custom_divisor); } r_alt_ser_baudrate_shadow &= ~mask; r_alt_ser_baudrate_shadow |= (alt_source << (info->line*8)); *R_ALT_SER_BAUDRATE = r_alt_ser_baudrate_shadow; } else { /* Normal baudrate */ /* Make sure we use normal baudrate */ u32 mask = 0xFF << (info->line*8); /* Each port has 8 bits */ unsigned long alt_source = IO_STATE(R_ALT_SER_BAUDRATE, ser0_rec, normal) | IO_STATE(R_ALT_SER_BAUDRATE, ser0_tr, normal); r_alt_ser_baudrate_shadow &= ~mask; r_alt_ser_baudrate_shadow |= (alt_source << (info->line*8)); #ifndef CONFIG_SVINTO_SIM *R_ALT_SER_BAUDRATE = r_alt_ser_baudrate_shadow; #endif /* CONFIG_SVINTO_SIM */ info->baud = cflag_to_baud(cflag); #ifndef CONFIG_SVINTO_SIM info->port[REG_BAUD] = cflag_to_etrax_baud(cflag); #endif /* CONFIG_SVINTO_SIM */ } #ifndef CONFIG_SVINTO_SIM /* start with default settings and then fill in changes */ save_flags(flags); cli(); /* 8 bit, no/even parity */ info->rx_ctrl &= ~(IO_MASK(R_SERIAL0_REC_CTRL, rec_bitnr) | IO_MASK(R_SERIAL0_REC_CTRL, rec_par_en) | IO_MASK(R_SERIAL0_REC_CTRL, rec_par)); /* 8 bit, no/even parity, 1 stop bit, no cts */ info->tx_ctrl &= ~(IO_MASK(R_SERIAL0_TR_CTRL, tr_bitnr) | IO_MASK(R_SERIAL0_TR_CTRL, tr_par_en) | IO_MASK(R_SERIAL0_TR_CTRL, tr_par) | IO_MASK(R_SERIAL0_TR_CTRL, stop_bits) | IO_MASK(R_SERIAL0_TR_CTRL, auto_cts)); if ((cflag & CSIZE) == CS7) { /* set 7 bit mode */ info->tx_ctrl |= IO_STATE(R_SERIAL0_TR_CTRL, tr_bitnr, tr_7bit); info->rx_ctrl |= IO_STATE(R_SERIAL0_REC_CTRL, rec_bitnr, rec_7bit); } if (cflag & CSTOPB) { /* set 2 stop bit mode */ info->tx_ctrl |= IO_STATE(R_SERIAL0_TR_CTRL, stop_bits, two_bits); } if (cflag & PARENB) { /* enable parity */ info->tx_ctrl |= IO_STATE(R_SERIAL0_TR_CTRL, tr_par_en, enable); info->rx_ctrl |= IO_STATE(R_SERIAL0_REC_CTRL, rec_par_en, enable); } if (cflag & CMSPAR) { /* enable stick parity, PARODD mean Mark which matches ETRAX */ info->tx_ctrl |= IO_STATE(R_SERIAL0_TR_CTRL, tr_stick_par, stick); info->rx_ctrl |= IO_STATE(R_SERIAL0_REC_CTRL, rec_stick_par, stick); } if (cflag & PARODD) { /* set odd parity (or Mark if CMSPAR) */ info->tx_ctrl |= IO_STATE(R_SERIAL0_TR_CTRL, tr_par, odd); info->rx_ctrl |= IO_STATE(R_SERIAL0_REC_CTRL, rec_par, odd); } if (cflag & CRTSCTS) { /* enable automatic CTS handling */ DFLOW(DEBUG_LOG(info->line, "FLOW auto_cts enabled\n", 0)); info->tx_ctrl |= IO_STATE(R_SERIAL0_TR_CTRL, auto_cts, active); } /* make sure the tx and rx are enabled */ info->tx_ctrl |= IO_STATE(R_SERIAL0_TR_CTRL, tr_enable, enable); info->rx_ctrl |= IO_STATE(R_SERIAL0_REC_CTRL, rec_enable, enable); /* actually write the control regs to the hardware */ info->port[REG_TR_CTRL] = info->tx_ctrl; info->port[REG_REC_CTRL] = info->rx_ctrl; xoff = IO_FIELD(R_SERIAL0_XOFF, xoff_char, STOP_CHAR(info->tty)); xoff |= IO_STATE(R_SERIAL0_XOFF, tx_stop, enable); if (info->tty->termios->c_iflag & IXON ) { DFLOW(DEBUG_LOG(info->line, "FLOW XOFF enabled 0x%02X\n", STOP_CHAR(info->tty))); xoff |= IO_STATE(R_SERIAL0_XOFF, auto_xoff, enable); } *((unsigned long *)&info->port[REG_XOFF]) = xoff; restore_flags(flags); #endif /* !CONFIG_SVINTO_SIM */ update_char_time(info); } /* change_speed */ /* start transmitting chars NOW */ static void rs_flush_chars(struct tty_struct *tty) { struct e100_serial *info = (struct e100_serial *)tty->driver_data; unsigned long flags; if (info->tr_running || info->xmit.head == info->xmit.tail || tty->stopped || tty->hw_stopped || !info->xmit.buf) return; #ifdef SERIAL_DEBUG_FLOW printk("rs_flush_chars\n"); #endif /* this protection might not exactly be necessary here */ save_flags(flags); cli(); start_transmit(info); restore_flags(flags); } extern _INLINE_ int rs_raw_write(struct tty_struct * tty, int from_user, const unsigned char *buf, int count) { int c, ret = 0; struct e100_serial *info = (struct e100_serial *)tty->driver_data; unsigned long flags; /* first some sanity checks */ if (!tty || !info->xmit.buf || !tmp_buf) return 0; #ifdef SERIAL_DEBUG_DATA if (info->line == SERIAL_DEBUG_LINE) printk("rs_raw_write (%d), status %d\n", count, info->port[REG_STATUS]); #endif #ifdef CONFIG_SVINTO_SIM /* Really simple. The output is here and now. */ SIMCOUT(buf, count); return count; #endif save_flags(flags); DFLOW(DEBUG_LOG(info->line, "write count %i ", count)); DFLOW(DEBUG_LOG(info->line, "ldisc %i\n", tty->ldisc.chars_in_buffer(tty))); /* the cli/restore_flags pairs below are needed because the * DMA interrupt handler moves the info->xmit values. the memcpy * needs to be in the critical region unfortunately, because we * need to read xmit values, memcpy, write xmit values in one * atomic operation... this could perhaps be avoided by more clever * design. */ if (from_user) { down(&tmp_buf_sem); while (1) { int c1; c = CIRC_SPACE_TO_END(info->xmit.head, info->xmit.tail, SERIAL_XMIT_SIZE); if (count < c) c = count; if (c <= 0) break; c -= copy_from_user(tmp_buf, buf, c); if (!c) { if (!ret) ret = -EFAULT; break; } cli(); c1 = CIRC_SPACE_TO_END(info->xmit.head, info->xmit.tail, SERIAL_XMIT_SIZE); if (c1 < c) c = c1; memcpy(info->xmit.buf + info->xmit.head, tmp_buf, c); info->xmit.head = ((info->xmit.head + c) & (SERIAL_XMIT_SIZE-1)); restore_flags(flags); buf += c; count -= c; ret += c; } up(&tmp_buf_sem); } else { cli(); while (count) { c = CIRC_SPACE_TO_END(info->xmit.head, info->xmit.tail, SERIAL_XMIT_SIZE); if (count < c) c = count; if (c <= 0) break; memcpy(info->xmit.buf + info->xmit.head, buf, c); info->xmit.head = (info->xmit.head + c) & (SERIAL_XMIT_SIZE-1); buf += c; count -= c; ret += c; } restore_flags(flags); } /* enable transmitter if not running, unless the tty is stopped * this does not need IRQ protection since if tr_running == 0 * the IRQ's are not running anyway for this port. */ DFLOW(DEBUG_LOG(info->line, "write ret %i\n", ret)); if (info->xmit.head != info->xmit.tail && !tty->stopped && !tty->hw_stopped && !info->tr_running) { start_transmit(info); } return ret; } /* raw_raw_write() */ static int rs_write(struct tty_struct * tty, int from_user, const unsigned char *buf, int count) { #if defined(CONFIG_ETRAX_RS485) struct e100_serial *info = (struct e100_serial *)tty->driver_data; if (info->rs485.enabled) { /* If we are in RS-485 mode, we need to toggle RTS and disable * the receiver before initiating a DMA transfer */ #ifdef CONFIG_ETRAX_FAST_TIMER /* Abort any started timer */ fast_timers_rs485[info->line].function = NULL; del_fast_timer(&fast_timers_rs485[info->line]); #endif e100_rts(info, info->rs485.rts_on_send); #if defined(CONFIG_ETRAX_RS485_DISABLE_RECEIVER) e100_disable_rx(info); e100_enable_rx_irq(info); #endif if (info->rs485.delay_rts_before_send > 0) { set_current_state(TASK_INTERRUPTIBLE); schedule_timeout((info->rs485.delay_rts_before_send * HZ)/1000); } } #endif /* CONFIG_ETRAX_RS485 */ count = rs_raw_write(tty, from_user, buf, count); #if defined(CONFIG_ETRAX_RS485) if (info->rs485.enabled) { unsigned int val; /* If we are in RS-485 mode the following has to be done: * wait until DMA is ready * wait on transmit shift register * toggle RTS * enable the receiver */ /* Sleep until all sent */ tty_wait_until_sent(tty, 0); #ifdef CONFIG_ETRAX_FAST_TIMER /* Now sleep a little more so that shift register is empty */ schedule_usleep(info->char_time_usec * 2); #endif /* wait on transmit shift register */ do{ get_lsr_info(info, &val); }while (!(val & TIOCSER_TEMT)); e100_rts(info, info->rs485.rts_after_sent); #if defined(CONFIG_ETRAX_RS485_DISABLE_RECEIVER) e100_enable_rx(info); e100_enable_rxdma_irq(info); #endif } #endif /* CONFIG_ETRAX_RS485 */ return count; } /* rs_write */ /* how much space is available in the xmit buffer? */ static int rs_write_room(struct tty_struct *tty) { struct e100_serial *info = (struct e100_serial *)tty->driver_data; return CIRC_SPACE(info->xmit.head, info->xmit.tail, SERIAL_XMIT_SIZE); } /* How many chars are in the xmit buffer? * This does not include any chars in the transmitter FIFO. * Use wait_until_sent for waiting for FIFO drain. */ static int rs_chars_in_buffer(struct tty_struct *tty) { struct e100_serial *info = (struct e100_serial *)tty->driver_data; return CIRC_CNT(info->xmit.head, info->xmit.tail, SERIAL_XMIT_SIZE); } /* discard everything in the xmit buffer */ static void rs_flush_buffer(struct tty_struct *tty) { struct e100_serial *info = (struct e100_serial *)tty->driver_data; unsigned long flags; save_flags(flags); cli(); info->xmit.head = info->xmit.tail = 0; restore_flags(flags); wake_up_interruptible(&tty->write_wait); if ((tty->flags & (1 << TTY_DO_WRITE_WAKEUP)) && tty->ldisc.write_wakeup) (tty->ldisc.write_wakeup)(tty); } /* * This function is used to send a high-priority XON/XOFF character to * the device * * Since we use DMA we don't check for info->x_char in transmit_chars_dma(), * but we do it in handle_ser_tx_interrupt(). * We disable DMA channel and enable tx ready interrupt and write the * character when possible. */ static void rs_send_xchar(struct tty_struct *tty, char ch) { struct e100_serial *info = (struct e100_serial *)tty->driver_data; unsigned long flags; save_flags(flags); cli(); if (info->uses_dma_out) { /* Put the DMA on hold and disable the channel */ *info->ocmdadr = IO_STATE(R_DMA_CH6_CMD, cmd, hold); while (IO_EXTRACT(R_DMA_CH6_CMD, cmd, *info->ocmdadr) != IO_STATE_VALUE(R_DMA_CH6_CMD, cmd, hold)); e100_disable_txdma_channel(info); } /* Must make sure transmitter is not stopped before we can transmit */ if (tty->stopped) rs_start(tty); /* Enable manual transmit interrupt and send from there */ DFLOW(DEBUG_LOG(info->line, "rs_send_xchar 0x%02X\n", ch)); info->x_char = ch; e100_enable_serial_tx_ready_irq(info); restore_flags(flags); } /* * ------------------------------------------------------------ * rs_throttle() * * This routine is called by the upper-layer tty layer to signal that * incoming characters should be throttled. * ------------------------------------------------------------ */ static void rs_throttle(struct tty_struct * tty) { struct e100_serial *info = (struct e100_serial *)tty->driver_data; #ifdef SERIAL_DEBUG_THROTTLE char buf[64]; printk("throttle %s: %lu....\n", tty_name(tty, buf), (unsigned long)tty->ldisc.chars_in_buffer(tty)); #endif DFLOW(DEBUG_LOG(info->line,"rs_throttle %lu\n", tty->ldisc.chars_in_buffer(tty))); /* Do RTS before XOFF since XOFF might take some time */ if (tty->termios->c_cflag & CRTSCTS) { /* Turn off RTS line */ e100_rts(info, 0); } if (I_IXOFF(tty)) rs_send_xchar(tty, STOP_CHAR(tty)); } static void rs_unthrottle(struct tty_struct * tty) { struct e100_serial *info = (struct e100_serial *)tty->driver_data; #ifdef SERIAL_DEBUG_THROTTLE char buf[64]; printk("unthrottle %s: %lu....\n", tty_name(tty, buf), (unsigned long)tty->ldisc.chars_in_buffer(tty)); #endif DFLOW(DEBUG_LOG(info->line,"rs_unthrottle ldisc %d\n", tty->ldisc.chars_in_buffer(tty))); DFLOW(DEBUG_LOG(info->line,"rs_unthrottle flip.count: %i\n", tty->flip.count)); /* Do RTS before XOFF since XOFF might take some time */ if (tty->termios->c_cflag & CRTSCTS) { /* Assert RTS line */ e100_rts(info, 1); } if (I_IXOFF(tty)) { if (info->x_char) info->x_char = 0; else rs_send_xchar(tty, START_CHAR(tty)); } } /* * ------------------------------------------------------------ * rs_ioctl() and friends * ------------------------------------------------------------ */ static int get_serial_info(struct e100_serial * info, struct serial_struct * retinfo) { struct serial_struct tmp; /* this is all probably wrong, there are a lot of fields * here that we don't have in e100_serial and maybe we * should set them to something else than 0. */ if (!retinfo) return -EFAULT; memset(&tmp, 0, sizeof(tmp)); tmp.type = info->type; tmp.line = info->line; tmp.port = (int)info->port; tmp.irq = info->irq; tmp.flags = info->flags; tmp.baud_base = info->baud_base; tmp.close_delay = info->close_delay; tmp.closing_wait = info->closing_wait; tmp.custom_divisor = info->custom_divisor; if (copy_to_user(retinfo, &tmp, sizeof(*retinfo))) return -EFAULT; return 0; } static int set_serial_info(struct e100_serial *info, struct serial_struct *new_info) { struct serial_struct new_serial; struct e100_serial old_info; int retval = 0; if (copy_from_user(&new_serial, new_info, sizeof(new_serial))) return -EFAULT; old_info = *info; if (!capable(CAP_SYS_ADMIN)) { if ((new_serial.type != info->type) || (new_serial.close_delay != info->close_delay) || ((new_serial.flags & ~ASYNC_USR_MASK) != (info->flags & ~ASYNC_USR_MASK))) return -EPERM; info->flags = ((info->flags & ~ASYNC_USR_MASK) | (new_serial.flags & ASYNC_USR_MASK)); goto check_and_exit; } if (info->count > 1) return -EBUSY; /* * OK, past this point, all the error checking has been done. * At this point, we start making changes..... */ info->baud_base = new_serial.baud_base; info->flags = ((info->flags & ~ASYNC_FLAGS) | (new_serial.flags & ASYNC_FLAGS)); info->custom_divisor = new_serial.custom_divisor; info->type = new_serial.type; info->close_delay = new_serial.close_delay; info->closing_wait = new_serial.closing_wait; info->tty->low_latency = (info->flags & ASYNC_LOW_LATENCY) ? 1 : 0; check_and_exit: if (info->flags & ASYNC_INITIALIZED) { change_speed(info); } else retval = startup(info); return retval; } /* * get_lsr_info - get line status register info * * Purpose: Let user call ioctl() to get info when the UART physically * is emptied. On bus types like RS485, the transmitter must * release the bus after transmitting. This must be done when * the transmit shift register is empty, not be done when the * transmit holding register is empty. This functionality * allows an RS485 driver to be written in user space. */ static int get_lsr_info(struct e100_serial * info, unsigned int *value) { unsigned int result = TIOCSER_TEMT; #ifndef CONFIG_SVINTO_SIM unsigned long curr_time = jiffies; unsigned long curr_time_usec = GET_JIFFIES_USEC(); unsigned long elapsed_usec = (curr_time - info->last_tx_active) * 1000000/HZ + curr_time_usec - info->last_tx_active_usec; if (info->xmit.head != info->xmit.tail || elapsed_usec < 2*info->char_time_usec) { result = 0; } #endif if (copy_to_user(value, &result, sizeof(int))) return -EFAULT; return 0; } #ifdef SERIAL_DEBUG_IO struct state_str { int state; const char *str; }; const struct state_str control_state_str[] = { {TIOCM_DTR, "DTR" }, {TIOCM_RTS, "RTS"}, {TIOCM_ST, "ST?" }, {TIOCM_SR, "SR?" }, {TIOCM_CTS, "CTS" }, {TIOCM_CD, "CD" }, {TIOCM_RI, "RI" }, {TIOCM_DSR, "DSR" }, {0, NULL } }; char *get_control_state_str(int MLines, char *s) { int i = 0; s[0]='\0'; while (control_state_str[i].str != NULL) { if (MLines & control_state_str[i].state) { if (s[0] != '\0') { strcat(s, ", "); } strcat(s, control_state_str[i].str); } i++; } return s; } #endif static int get_modem_info(struct e100_serial * info, unsigned int *value) { unsigned int result; /* Polarity isn't verified */ #if 0 /*def SERIAL_DEBUG_IO */ printk("get_modem_info: RTS: %i DTR: %i CD: %i RI: %i DSR: %i CTS: %i\n", E100_RTS_GET(info), E100_DTR_GET(info), E100_CD_GET(info), E100_RI_GET(info), E100_DSR_GET(info), E100_CTS_GET(info)); #endif result = (!E100_RTS_GET(info) ? TIOCM_RTS : 0) | (!E100_DTR_GET(info) ? TIOCM_DTR : 0) | (!E100_RI_GET(info) ? TIOCM_RNG : 0) | (!E100_DSR_GET(info) ? TIOCM_DSR : 0) | (!E100_CD_GET(info) ? TIOCM_CAR : 0) | (!E100_CTS_GET(info) ? TIOCM_CTS : 0); #ifdef SERIAL_DEBUG_IO printk("e100ser: modem state: %i 0x%08X\n", result, result); { char s[100]; get_control_state_str(result, s); printk("state: %s\n", s); } #endif if (copy_to_user(value, &result, sizeof(int))) return -EFAULT; return 0; } static int set_modem_info(struct e100_serial * info, unsigned int cmd, unsigned int *value) { unsigned int arg; if (copy_from_user(&arg, value, sizeof(int))) return -EFAULT; switch (cmd) { case TIOCMBIS: if (arg & TIOCM_RTS) { e100_rts(info, 1); } if (arg & TIOCM_DTR) { e100_dtr(info, 1); } /* Handle FEMALE behaviour */ if (arg & TIOCM_RI) { e100_ri_out(info, 1); } if (arg & TIOCM_CD) { e100_cd_out(info, 1); } break; case TIOCMBIC: if (arg & TIOCM_RTS) { e100_rts(info, 0); } if (arg & TIOCM_DTR) { e100_dtr(info, 0); } /* Handle FEMALE behaviour */ if (arg & TIOCM_RI) { e100_ri_out(info, 0); } if (arg & TIOCM_CD) { e100_cd_out(info, 0); } break; case TIOCMSET: e100_rts(info, arg & TIOCM_RTS); e100_dtr(info, arg & TIOCM_DTR); /* Handle FEMALE behaviour */ e100_ri_out(info, arg & TIOCM_RI); e100_cd_out(info, arg & TIOCM_CD); break; default: return -EINVAL; } return 0; } static void rs_break(struct tty_struct *tty, int break_state) { struct e100_serial * info = (struct e100_serial *)tty->driver_data; unsigned long flags; if (!info->port) return; save_flags(flags); cli(); if (break_state == -1) { /* Go to manual mode and set the txd pin to 0 */ info->tx_ctrl &= 0x3F; /* Clear bit 7 (txd) and 6 (tr_enable) */ } else { info->tx_ctrl |= (0x80 | 0x40); /* Set bit 7 (txd) and 6 (tr_enable) */ } info->port[REG_TR_CTRL] = info->tx_ctrl; restore_flags(flags); } static int rs_ioctl(struct tty_struct *tty, struct file * file, unsigned int cmd, unsigned long arg) { struct e100_serial * info = (struct e100_serial *)tty->driver_data; if ((cmd != TIOCGSERIAL) && (cmd != TIOCSSERIAL) && (cmd != TIOCSERCONFIG) && (cmd != TIOCSERGWILD) && (cmd != TIOCSERSWILD) && (cmd != TIOCSERGSTRUCT)) { if (tty->flags & (1 << TTY_IO_ERROR)) return -EIO; } switch (cmd) { case TIOCMGET: return get_modem_info(info, (unsigned int *) arg); case TIOCMBIS: case TIOCMBIC: case TIOCMSET: return set_modem_info(info, cmd, (unsigned int *) arg); case TIOCGSERIAL: return get_serial_info(info, (struct serial_struct *) arg); case TIOCSSERIAL: return set_serial_info(info, (struct serial_struct *) arg); case TIOCSERGETLSR: /* Get line status register */ return get_lsr_info(info, (unsigned int *) arg); case TIOCSERGSTRUCT: if (copy_to_user((struct e100_serial *) arg, info, sizeof(struct e100_serial))) return -EFAULT; return 0; #if defined(CONFIG_ETRAX_RS485) case TIOCSERSETRS485: { struct rs485_control rs485ctrl; if (copy_from_user(&rs485ctrl, (struct rs485_control*)arg, sizeof(rs485ctrl))) return -EFAULT; return e100_enable_rs485(tty, &rs485ctrl); } case TIOCSERWRRS485: { struct rs485_write rs485wr; if (copy_from_user(&rs485wr, (struct rs485_write*)arg, sizeof(rs485wr))) return -EFAULT; return e100_write_rs485(tty, 1, rs485wr.outc, rs485wr.outc_size); } #endif default: return -ENOIOCTLCMD; } return 0; } static void rs_set_termios(struct tty_struct *tty, struct termios *old_termios) { struct e100_serial *info = (struct e100_serial *)tty->driver_data; if (tty->termios->c_cflag == old_termios->c_cflag && tty->termios->c_iflag == old_termios->c_iflag) return; change_speed(info); /* Handle turning off CRTSCTS */ if ((old_termios->c_cflag & CRTSCTS) && !(tty->termios->c_cflag & CRTSCTS)) { tty->hw_stopped = 0; rs_start(tty); } } /* In debugport.c - register a console write function that uses the normal * serial driver */ typedef int (*debugport_write_function)(int i, const char *buf, unsigned int len); extern debugport_write_function debug_write_function; static int rs_debug_write_function(int i, const char *buf, unsigned int len) { int cnt; int written = 0; struct tty_struct *tty; static int recurse_cnt = 0; tty = rs_table[i].tty; if (tty) { unsigned long flags; if (recurse_cnt > 5) /* We skip this debug output */ return 1; local_irq_save(flags); recurse_cnt++; local_irq_restore(flags); do { cnt = rs_write(tty, 0, buf + written, len); if (cnt >= 0) { written += cnt; buf += cnt; len -= cnt; } else len = cnt; } while(len > 0); local_irq_save(flags); recurse_cnt--; local_irq_restore(flags); return 1; } return 0; } /* * ------------------------------------------------------------ * rs_close() * * This routine is called when the serial port gets closed. First, we * wait for the last remaining data to be sent. Then, we unlink its * S structure from the interrupt chain if necessary, and we free * that IRQ if nothing is left in the chain. * ------------------------------------------------------------ */ static void rs_close(struct tty_struct *tty, struct file * filp) { struct e100_serial * info = (struct e100_serial *)tty->driver_data; unsigned long flags; if (!info) return; /* interrupts are disabled for this entire function */ save_flags(flags); cli(); if (tty_hung_up_p(filp)) { restore_flags(flags); return; } #ifdef SERIAL_DEBUG_OPEN printk("[%d] rs_close ttyS%d, count = %d\n", current->pid, info->line, info->count); #endif if ((tty->count == 1) && (info->count != 1)) { /* * Uh, oh. tty->count is 1, which means that the tty * structure will be freed. Info->count should always * be one in these conditions. If it's greater than * one, we've got real problems, since it means the * serial port won't be shutdown. */ printk(KERN_CRIT "rs_close: bad serial port count; tty->count is 1, " "info->count is %d\n", info->count); info->count = 1; } if (--info->count < 0) { printk(KERN_CRIT "rs_close: bad serial port count for ttyS%d: %d\n", info->line, info->count); info->count = 0; } if (info->count) { restore_flags(flags); return; } info->flags |= ASYNC_CLOSING; /* * Save the termios structure, since this port may have * separate termios for callout and dialin. */ if (info->flags & ASYNC_NORMAL_ACTIVE) info->normal_termios = *tty->termios; /* * Now we wait for the transmit buffer to clear; and we notify * the line discipline to only process XON/XOFF characters. */ tty->closing = 1; if (info->closing_wait != ASYNC_CLOSING_WAIT_NONE) tty_wait_until_sent(tty, info->closing_wait); /* * At this point we stop accepting input. To do this, we * disable the serial receiver and the DMA receive interrupt. */ #ifdef SERIAL_HANDLE_EARLY_ERRORS e100_disable_serial_data_irq(info); #endif #ifndef CONFIG_SVINTO_SIM e100_disable_rx(info); e100_disable_rx_irq(info); if (info->flags & ASYNC_INITIALIZED) { /* * Before we drop DTR, make sure the UART transmitter * has completely drained; this is especially * important as we have a transmit FIFO! */ rs_wait_until_sent(tty, HZ); } #endif shutdown(info); if (tty->driver->flush_buffer) tty->driver->flush_buffer(tty); if (tty->ldisc.flush_buffer) tty->ldisc.flush_buffer(tty); tty->closing = 0; info->event = 0; info->tty = 0; if (info->blocked_open) { if (info->close_delay) { set_current_state(TASK_INTERRUPTIBLE); schedule_timeout(info->close_delay); } wake_up_interruptible(&info->open_wait); } info->flags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CLOSING); wake_up_interruptible(&info->close_wait); restore_flags(flags); /* port closed */ #if defined(CONFIG_ETRAX_RS485) if (info->rs485.enabled) { info->rs485.enabled = 0; #if defined(CONFIG_ETRAX_RS485_ON_PA) *R_PORT_PA_DATA = port_pa_data_shadow &= ~(1 << rs485_pa_bit); #endif #if defined(CONFIG_ETRAX_RS485_ON_PORT_G) REG_SHADOW_SET(R_PORT_G_DATA, port_g_data_shadow, rs485_port_g_bit, 0); #endif #if defined(CONFIG_ETRAX_RS485_LTC1387) REG_SHADOW_SET(R_PORT_G_DATA, port_g_data_shadow, CONFIG_ETRAX_RS485_LTC1387_DXEN_PORT_G_BIT, 0); REG_SHADOW_SET(R_PORT_G_DATA, port_g_data_shadow, CONFIG_ETRAX_RS485_LTC1387_RXEN_PORT_G_BIT, 0); #endif } #endif } /* * rs_wait_until_sent() --- wait until the transmitter is empty */ static void rs_wait_until_sent(struct tty_struct *tty, int timeout) { unsigned long orig_jiffies; struct e100_serial *info = (struct e100_serial *)tty->driver_data; unsigned long curr_time = jiffies; unsigned long curr_time_usec = GET_JIFFIES_USEC(); long elapsed_usec = (curr_time - info->last_tx_active) * (1000000/HZ) + curr_time_usec - info->last_tx_active_usec; /* * Check R_DMA_CHx_STATUS bit 0-6=number of available bytes in FIFO * R_DMA_CHx_HWSW bit 31-16=nbr of bytes left in DMA buffer (0=64k) */ orig_jiffies = jiffies; while (info->xmit.head != info->xmit.tail || /* More in send queue */ (*info->ostatusadr & 0x007f) || /* more in FIFO */ (elapsed_usec < 2*info->char_time_usec)) { set_current_state(TASK_INTERRUPTIBLE); schedule_timeout(1); if (signal_pending(current)) break; if (timeout && time_after(jiffies, orig_jiffies + timeout)) break; curr_time = jiffies; curr_time_usec = GET_JIFFIES_USEC(); elapsed_usec = (curr_time - info->last_tx_active) * (1000000/HZ) + curr_time_usec - info->last_tx_active_usec; } set_current_state(TASK_RUNNING); } /* * rs_hangup() --- called by tty_hangup() when a hangup is signaled. */ void rs_hangup(struct tty_struct *tty) { struct e100_serial * info = (struct e100_serial *)tty->driver_data; rs_flush_buffer(tty); shutdown(info); info->event = 0; info->count = 0; info->flags &= ~ASYNC_NORMAL_ACTIVE; info->tty = 0; wake_up_interruptible(&info->open_wait); } /* * ------------------------------------------------------------ * rs_open() and friends * ------------------------------------------------------------ */ static int block_til_ready(struct tty_struct *tty, struct file * filp, struct e100_serial *info) { DECLARE_WAITQUEUE(wait, current); unsigned long flags; int retval; int do_clocal = 0, extra_count = 0; /* * If the device is in the middle of being closed, then block * until it's done, and then try again. */ if (tty_hung_up_p(filp) || (info->flags & ASYNC_CLOSING)) { if (info->flags & ASYNC_CLOSING) interruptible_sleep_on(&info->close_wait); #ifdef SERIAL_DO_RESTART if (info->flags & ASYNC_HUP_NOTIFY) return -EAGAIN; else return -ERESTARTSYS; #else return -EAGAIN; #endif } /* * If non-blocking mode is set, or the port is not enabled, * then make the check up front and then exit. */ if ((filp->f_flags & O_NONBLOCK) || (tty->flags & (1 << TTY_IO_ERROR))) { info->flags |= ASYNC_NORMAL_ACTIVE; return 0; } if (tty->termios->c_cflag & CLOCAL) { do_clocal = 1; } /* * Block waiting for the carrier detect and the line to become * free (i.e., not in use by the callout). While we are in * this loop, info->count is dropped by one, so that * rs_close() knows when to free things. We restore it upon * exit, either normal or abnormal. */ retval = 0; add_wait_queue(&info->open_wait, &wait); #ifdef SERIAL_DEBUG_OPEN printk("block_til_ready before block: ttyS%d, count = %d\n", info->line, info->count); #endif save_flags(flags); cli(); if (!tty_hung_up_p(filp)) { extra_count++; info->count--; } restore_flags(flags); info->blocked_open++; while (1) { save_flags(flags); cli(); /* assert RTS and DTR */ e100_rts(info, 1); e100_dtr(info, 1); restore_flags(flags); set_current_state(TASK_INTERRUPTIBLE); if (tty_hung_up_p(filp) || !(info->flags & ASYNC_INITIALIZED)) { #ifdef SERIAL_DO_RESTART if (info->flags & ASYNC_HUP_NOTIFY) retval = -EAGAIN; else retval = -ERESTARTSYS; #else retval = -EAGAIN; #endif break; } if (!(info->flags & ASYNC_CLOSING) && do_clocal) /* && (do_clocal || DCD_IS_ASSERTED) */ break; if (signal_pending(current)) { retval = -ERESTARTSYS; break; } #ifdef SERIAL_DEBUG_OPEN printk("block_til_ready blocking: ttyS%d, count = %d\n", info->line, info->count); #endif schedule(); } set_current_state(TASK_RUNNING); remove_wait_queue(&info->open_wait, &wait); if (extra_count) info->count++; info->blocked_open--; #ifdef SERIAL_DEBUG_OPEN printk("block_til_ready after blocking: ttyS%d, count = %d\n", info->line, info->count); #endif if (retval) return retval; info->flags |= ASYNC_NORMAL_ACTIVE; return 0; } /* * This routine is called whenever a serial port is opened. * It performs the serial-specific initialization for the tty structure. */ static int rs_open(struct tty_struct *tty, struct file * filp) { struct e100_serial *info; int retval, line; unsigned long page; /* find which port we want to open */ line = tty->index; if (line < 0 || line >= NR_PORTS) return -ENODEV; /* find the corresponding e100_serial struct in the table */ info = rs_table + line; /* don't allow the opening of ports that are not enabled in the HW config */ if (!info->enabled) return -ENODEV; #ifdef SERIAL_DEBUG_OPEN printk("[%d] rs_open %s, count = %d\n", current->pid, tty->name, info->count); #endif info->count++; tty->driver_data = info; info->tty = tty; info->tty->low_latency = (info->flags & ASYNC_LOW_LATENCY) ? 1 : 0; if (!tmp_buf) { page = get_zeroed_page(GFP_KERNEL); if (!page) { return -ENOMEM; } if (tmp_buf) free_page(page); else tmp_buf = (unsigned char *) page; } /* * If the port is in the middle of closing, bail out now */ if (tty_hung_up_p(filp) || (info->flags & ASYNC_CLOSING)) { if (info->flags & ASYNC_CLOSING) interruptible_sleep_on(&info->close_wait); #ifdef SERIAL_DO_RESTART return ((info->flags & ASYNC_HUP_NOTIFY) ? -EAGAIN : -ERESTARTSYS); #else return -EAGAIN; #endif } /* * Start up the serial port */ retval = startup(info); if (retval) return retval; retval = block_til_ready(tty, filp, info); if (retval) { #ifdef SERIAL_DEBUG_OPEN printk("rs_open returning after block_til_ready with %d\n", retval); #endif return retval; } if ((info->count == 1) && (info->flags & ASYNC_SPLIT_TERMIOS)) { *tty->termios = info->normal_termios; change_speed(info); } #ifdef SERIAL_DEBUG_OPEN printk("rs_open ttyS%d successful...\n", info->line); #endif DLOG_INT_TRIG( log_int_pos = 0); DFLIP( if (info->line == SERIAL_DEBUG_LINE) { info->icount.rx = 0; } ); return 0; } /* * /proc fs routines.... */ extern _INLINE_ int line_info(char *buf, struct e100_serial *info) { char stat_buf[30]; int ret; unsigned long tmp; ret = sprintf(buf, "%d: uart:E100 port:%lX irq:%d", info->line, (unsigned long)info->port, info->irq); if (!info->port || (info->type == PORT_UNKNOWN)) { ret += sprintf(buf+ret, "\n"); return ret; } stat_buf[0] = 0; stat_buf[1] = 0; if (!E100_RTS_GET(info)) strcat(stat_buf, "|RTS"); if (!E100_CTS_GET(info)) strcat(stat_buf, "|CTS"); if (!E100_DTR_GET(info)) strcat(stat_buf, "|DTR"); if (!E100_DSR_GET(info)) strcat(stat_buf, "|DSR"); if (!E100_CD_GET(info)) strcat(stat_buf, "|CD"); if (!E100_RI_GET(info)) strcat(stat_buf, "|RI"); ret += sprintf(buf+ret, " baud:%d", info->baud); ret += sprintf(buf+ret, " tx:%lu rx:%lu", (unsigned long)info->icount.tx, (unsigned long)info->icount.rx); tmp = CIRC_CNT(info->xmit.head, info->xmit.tail, SERIAL_XMIT_SIZE); if (tmp) { ret += sprintf(buf+ret, " tx_pend:%lu/%lu", (unsigned long)tmp, (unsigned long)SERIAL_XMIT_SIZE); } ret += sprintf(buf+ret, " rx_pend:%lu/%lu", (unsigned long)info->recv_cnt, (unsigned long)info->max_recv_cnt); #if 1 if (info->tty) { if (info->tty->stopped) ret += sprintf(buf+ret, " stopped:%i", (int)info->tty->stopped); if (info->tty->hw_stopped) ret += sprintf(buf+ret, " hw_stopped:%i", (int)info->tty->hw_stopped); } { unsigned char rstat = info->port[REG_STATUS]; if (rstat & IO_MASK(R_SERIAL0_STATUS, xoff_detect) ) ret += sprintf(buf+ret, " xoff_detect:1"); } #endif if (info->icount.frame) ret += sprintf(buf+ret, " fe:%lu", (unsigned long)info->icount.frame); if (info->icount.parity) ret += sprintf(buf+ret, " pe:%lu", (unsigned long)info->icount.parity); if (info->icount.brk) ret += sprintf(buf+ret, " brk:%lu", (unsigned long)info->icount.brk); if (info->icount.overrun) ret += sprintf(buf+ret, " oe:%lu", (unsigned long)info->icount.overrun); /* * Last thing is the RS-232 status lines */ ret += sprintf(buf+ret, " %s\n", stat_buf+1); return ret; } int rs_read_proc(char *page, char **start, off_t off, int count, int *eof, void *data) { int i, len = 0, l; off_t begin = 0; len += sprintf(page, "serinfo:1.0 driver:%s\n", serial_version); for (i = 0; i < NR_PORTS && len < 4000; i++) { if (!rs_table[i].enabled) continue; l = line_info(page + len, &rs_table[i]); len += l; if (len+begin > off+count) goto done; if (len+begin < off) { begin += len; len = 0; } } #ifdef DEBUG_LOG_INCLUDED for (i = 0; i < debug_log_pos; i++) { len += sprintf(page + len, "%-4i %lu.%lu ", i, debug_log[i].time, timer_data_to_ns(debug_log[i].timer_data)); len += sprintf(page + len, debug_log[i].string, debug_log[i].value); if (len+begin > off+count) goto done; if (len+begin < off) { begin += len; len = 0; } } len += sprintf(page + len, "debug_log %i/%i %li bytes\n", i, DEBUG_LOG_SIZE, begin+len); debug_log_pos = 0; #endif *eof = 1; done: if (off >= len+begin) return 0; *start = page + (off-begin); return ((count < begin+len-off) ? count : begin+len-off); } /* Finally, routines used to initialize the serial driver. */ static void show_serial_version(void) { printk(KERN_INFO "ETRAX 100LX serial-driver %s, (c) 2000-2004 Axis Communications AB\r\n", &serial_version[11]); /* "$Revision: x.yy" */ } /* rs_init inits the driver at boot (using the module_init chain) */ static struct tty_operations rs_ops = { .open = rs_open, .close = rs_close, .write = rs_write, .flush_chars = rs_flush_chars, .write_room = rs_write_room, .chars_in_buffer = rs_chars_in_buffer, .flush_buffer = rs_flush_buffer, .ioctl = rs_ioctl, .throttle = rs_throttle, .unthrottle = rs_unthrottle, .set_termios = rs_set_termios, .stop = rs_stop, .start = rs_start, .hangup = rs_hangup, .break_ctl = rs_break, .send_xchar = rs_send_xchar, .wait_until_sent = rs_wait_until_sent, .read_proc = rs_read_proc, }; static int __init rs_init(void) { int i; struct e100_serial *info; struct tty_driver *driver = alloc_tty_driver(NR_PORTS); if (!driver) return -ENOMEM; show_serial_version(); /* Setup the timed flush handler system */ #if !defined(CONFIG_ETRAX_SERIAL_FAST_TIMER) init_timer(&flush_timer); flush_timer.function = timed_flush_handler; mod_timer(&flush_timer, jiffies + CONFIG_ETRAX_SERIAL_RX_TIMEOUT_TICKS); #endif /* Initialize the tty_driver structure */ driver->driver_name = "serial"; driver->name = "ttyS"; driver->major = TTY_MAJOR; driver->minor_start = 64; driver->type = TTY_DRIVER_TYPE_SERIAL; driver->subtype = SERIAL_TYPE_NORMAL; driver->init_termios = tty_std_termios; driver->init_termios.c_cflag = B115200 | CS8 | CREAD | HUPCL | CLOCAL; /* is normally B9600 default... */ driver->flags = TTY_DRIVER_REAL_RAW | TTY_DRIVER_NO_DEVFS; driver->termios = serial_termios; driver->termios_locked = serial_termios_locked; tty_set_operations(driver, &rs_ops); serial_driver = driver; if (tty_register_driver(driver)) panic("Couldn't register serial driver\n"); /* do some initializing for the separate ports */ for (i = 0, info = rs_table; i < NR_PORTS; i++,info++) { info->uses_dma_in = 0; info->uses_dma_out = 0; info->line = i; info->tty = 0; info->type = PORT_ETRAX; info->tr_running = 0; info->forced_eop = 0; info->baud_base = DEF_BAUD_BASE; info->custom_divisor = 0; info->flags = 0; info->close_delay = 5*HZ/10; info->closing_wait = 30*HZ; info->x_char = 0; info->event = 0; info->count = 0; info->blocked_open = 0; info->normal_termios = driver->init_termios; init_waitqueue_head(&info->open_wait); init_waitqueue_head(&info->close_wait); info->xmit.buf = NULL; info->xmit.tail = info->xmit.head = 0; info->first_recv_buffer = info->last_recv_buffer = NULL; info->recv_cnt = info->max_recv_cnt = 0; info->last_tx_active_usec = 0; info->last_tx_active = 0; #if defined(CONFIG_ETRAX_RS485) /* Set sane defaults */ info->rs485.rts_on_send = 0; info->rs485.rts_after_sent = 1; info->rs485.delay_rts_before_send = 0; info->rs485.enabled = 0; #endif INIT_WORK(&info->work, do_softint, info); if (info->enabled) { printk(KERN_INFO "%s%d at 0x%x is a builtin UART with DMA\n", serial_driver->name, info->line, (unsigned int)info->port); } } #ifdef CONFIG_ETRAX_FAST_TIMER #ifdef CONFIG_ETRAX_SERIAL_FAST_TIMER memset(fast_timers, 0, sizeof(fast_timers)); #endif #ifdef CONFIG_ETRAX_RS485 memset(fast_timers_rs485, 0, sizeof(fast_timers_rs485)); #endif fast_timer_init(); #endif #ifndef CONFIG_SVINTO_SIM /* Not needed in simulator. May only complicate stuff. */ /* hook the irq's for DMA channel 6 and 7, serial output and input, and some more... */ if (request_irq(SERIAL_IRQ_NBR, ser_interrupt, SA_SHIRQ | SA_INTERRUPT, "serial ", NULL)) panic("irq8"); #ifdef CONFIG_ETRAX_SERIAL_PORT0 #ifdef CONFIG_ETRAX_SERIAL_PORT0_DMA6_OUT if (request_irq(SER0_DMA_TX_IRQ_NBR, tr_interrupt, SA_INTERRUPT, "serial 0 dma tr", NULL)) panic("irq22"); #endif #ifdef CONFIG_ETRAX_SERIAL_PORT0_DMA7_IN if (request_irq(SER0_DMA_RX_IRQ_NBR, rec_interrupt, SA_INTERRUPT, "serial 0 dma rec", NULL)) panic("irq23"); #endif #endif #ifdef CONFIG_ETRAX_SERIAL_PORT1 #ifdef CONFIG_ETRAX_SERIAL_PORT1_DMA8_OUT if (request_irq(SER1_DMA_TX_IRQ_NBR, tr_interrupt, SA_INTERRUPT, "serial 1 dma tr", NULL)) panic("irq24"); #endif #ifdef CONFIG_ETRAX_SERIAL_PORT1_DMA9_IN if (request_irq(SER1_DMA_RX_IRQ_NBR, rec_interrupt, SA_INTERRUPT, "serial 1 dma rec", NULL)) panic("irq25"); #endif #endif #ifdef CONFIG_ETRAX_SERIAL_PORT2 /* DMA Shared with par0 (and SCSI0 and ATA) */ #ifdef CONFIG_ETRAX_SERIAL_PORT2_DMA2_OUT if (request_irq(SER2_DMA_TX_IRQ_NBR, tr_interrupt, SA_SHIRQ | SA_INTERRUPT, "serial 2 dma tr", NULL)) panic("irq18"); #endif #ifdef CONFIG_ETRAX_SERIAL_PORT2_DMA3_IN if (request_irq(SER2_DMA_RX_IRQ_NBR, rec_interrupt, SA_SHIRQ | SA_INTERRUPT, "serial 2 dma rec", NULL)) panic("irq19"); #endif #endif #ifdef CONFIG_ETRAX_SERIAL_PORT3 /* DMA Shared with par1 (and SCSI1 and Extern DMA 0) */ #ifdef CONFIG_ETRAX_SERIAL_PORT3_DMA4_OUT if (request_irq(SER3_DMA_TX_IRQ_NBR, tr_interrupt, SA_SHIRQ | SA_INTERRUPT, "serial 3 dma tr", NULL)) panic("irq20"); #endif #ifdef CONFIG_ETRAX_SERIAL_PORT3_DMA5_IN if (request_irq(SER3_DMA_RX_IRQ_NBR, rec_interrupt, SA_SHIRQ | SA_INTERRUPT, "serial 3 dma rec", NULL)) panic("irq21"); #endif #endif #ifdef CONFIG_ETRAX_SERIAL_FLUSH_DMA_FAST if (request_irq(TIMER1_IRQ_NBR, timeout_interrupt, SA_SHIRQ | SA_INTERRUPT, "fast serial dma timeout", NULL)) { printk(KERN_CRIT "err: timer1 irq\n"); } #endif #endif /* CONFIG_SVINTO_SIM */ debug_write_function = rs_debug_write_function; return 0; } /* this makes sure that rs_init is called during kernel boot */ module_init(rs_init); /* * register_serial and unregister_serial allows for serial ports to be * configured at run-time, to support PCMCIA modems. */ int register_serial(struct serial_struct *req) { return -1; } void unregister_serial(int line) { }
gpl-2.0
erikvdk/qemu-hypercall
util/cutils.c
13
12994
/* * Simple C functions to supplement the C library * * Copyright (c) 2006 Fabrice Bellard * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ #include "qemu-common.h" #include "qemu/host-utils.h" #include <math.h> #include "qemu/sockets.h" #include "qemu/iov.h" #include "net/net.h" void strpadcpy(char *buf, int buf_size, const char *str, char pad) { int len = qemu_strnlen(str, buf_size); memcpy(buf, str, len); memset(buf + len, pad, buf_size - len); } void pstrcpy(char *buf, int buf_size, const char *str) { int c; char *q = buf; if (buf_size <= 0) return; for(;;) { c = *str++; if (c == 0 || q >= buf + buf_size - 1) break; *q++ = c; } *q = '\0'; } /* strcat and truncate. */ char *pstrcat(char *buf, int buf_size, const char *s) { int len; len = strlen(buf); if (len < buf_size) pstrcpy(buf + len, buf_size - len, s); return buf; } int strstart(const char *str, const char *val, const char **ptr) { const char *p, *q; p = str; q = val; while (*q != '\0') { if (*p != *q) return 0; p++; q++; } if (ptr) *ptr = p; return 1; } int stristart(const char *str, const char *val, const char **ptr) { const char *p, *q; p = str; q = val; while (*q != '\0') { if (qemu_toupper(*p) != qemu_toupper(*q)) return 0; p++; q++; } if (ptr) *ptr = p; return 1; } /* XXX: use host strnlen if available ? */ int qemu_strnlen(const char *s, int max_len) { int i; for(i = 0; i < max_len; i++) { if (s[i] == '\0') { break; } } return i; } char *qemu_strsep(char **input, const char *delim) { char *result = *input; if (result != NULL) { char *p; for (p = result; *p != '\0'; p++) { if (strchr(delim, *p)) { break; } } if (*p == '\0') { *input = NULL; } else { *p = '\0'; *input = p + 1; } } return result; } time_t mktimegm(struct tm *tm) { time_t t; int y = tm->tm_year + 1900, m = tm->tm_mon + 1, d = tm->tm_mday; if (m < 3) { m += 12; y--; } t = 86400ULL * (d + (153 * m - 457) / 5 + 365 * y + y / 4 - y / 100 + y / 400 - 719469); t += 3600 * tm->tm_hour + 60 * tm->tm_min + tm->tm_sec; return t; } int qemu_fls(int i) { return 32 - clz32(i); } /* * Make sure data goes on disk, but if possible do not bother to * write out the inode just for timestamp updates. * * Unfortunately even in 2009 many operating systems do not support * fdatasync and have to fall back to fsync. */ int qemu_fdatasync(int fd) { #ifdef CONFIG_FDATASYNC return fdatasync(fd); #else return fsync(fd); #endif } /* * Searches for an area with non-zero content in a buffer * * Attention! The len must be a multiple of * BUFFER_FIND_NONZERO_OFFSET_UNROLL_FACTOR * sizeof(VECTYPE) * and addr must be a multiple of sizeof(VECTYPE) due to * restriction of optimizations in this function. * * can_use_buffer_find_nonzero_offset() can be used to check * these requirements. * * The return value is the offset of the non-zero area rounded * down to a multiple of sizeof(VECTYPE) for the first * BUFFER_FIND_NONZERO_OFFSET_UNROLL_FACTOR chunks and down to * BUFFER_FIND_NONZERO_OFFSET_UNROLL_FACTOR * sizeof(VECTYPE) * afterwards. * * If the buffer is all zero the return value is equal to len. */ size_t buffer_find_nonzero_offset(const void *buf, size_t len) { const VECTYPE *p = buf; const VECTYPE zero = (VECTYPE){0}; size_t i; assert(can_use_buffer_find_nonzero_offset(buf, len)); if (!len) { return 0; } for (i = 0; i < BUFFER_FIND_NONZERO_OFFSET_UNROLL_FACTOR; i++) { if (!ALL_EQ(p[i], zero)) { return i * sizeof(VECTYPE); } } for (i = BUFFER_FIND_NONZERO_OFFSET_UNROLL_FACTOR; i < len / sizeof(VECTYPE); i += BUFFER_FIND_NONZERO_OFFSET_UNROLL_FACTOR) { VECTYPE tmp0 = p[i + 0] | p[i + 1]; VECTYPE tmp1 = p[i + 2] | p[i + 3]; VECTYPE tmp2 = p[i + 4] | p[i + 5]; VECTYPE tmp3 = p[i + 6] | p[i + 7]; VECTYPE tmp01 = tmp0 | tmp1; VECTYPE tmp23 = tmp2 | tmp3; if (!ALL_EQ(tmp01 | tmp23, zero)) { break; } } return i * sizeof(VECTYPE); } /* * Checks if a buffer is all zeroes * * Attention! The len must be a multiple of 4 * sizeof(long) due to * restriction of optimizations in this function. */ bool buffer_is_zero(const void *buf, size_t len) { /* * Use long as the biggest available internal data type that fits into the * CPU register and unroll the loop to smooth out the effect of memory * latency. */ size_t i; long d0, d1, d2, d3; const long * const data = buf; /* use vector optimized zero check if possible */ if (can_use_buffer_find_nonzero_offset(buf, len)) { return buffer_find_nonzero_offset(buf, len) == len; } assert(len % (4 * sizeof(long)) == 0); len /= sizeof(long); for (i = 0; i < len; i += 4) { d0 = data[i + 0]; d1 = data[i + 1]; d2 = data[i + 2]; d3 = data[i + 3]; if (d0 || d1 || d2 || d3) { return false; } } return true; } #ifndef _WIN32 /* Sets a specific flag */ int fcntl_setfl(int fd, int flag) { int flags; flags = fcntl(fd, F_GETFL); if (flags == -1) return -errno; if (fcntl(fd, F_SETFL, flags | flag) == -1) return -errno; return 0; } #endif static int64_t suffix_mul(char suffix, int64_t unit) { switch (qemu_toupper(suffix)) { case STRTOSZ_DEFSUFFIX_B: return 1; case STRTOSZ_DEFSUFFIX_KB: return unit; case STRTOSZ_DEFSUFFIX_MB: return unit * unit; case STRTOSZ_DEFSUFFIX_GB: return unit * unit * unit; case STRTOSZ_DEFSUFFIX_TB: return unit * unit * unit * unit; case STRTOSZ_DEFSUFFIX_PB: return unit * unit * unit * unit * unit; case STRTOSZ_DEFSUFFIX_EB: return unit * unit * unit * unit * unit * unit; } return -1; } /* * Convert string to bytes, allowing either B/b for bytes, K/k for KB, * M/m for MB, G/g for GB or T/t for TB. End pointer will be returned * in *end, if not NULL. Return -ERANGE on overflow, Return -EINVAL on * other error. */ int64_t strtosz_suffix_unit(const char *nptr, char **end, const char default_suffix, int64_t unit) { int64_t retval = -EINVAL; char *endptr; unsigned char c; int mul_required = 0; double val, mul, integral, fraction; errno = 0; val = strtod(nptr, &endptr); if (isnan(val) || endptr == nptr || errno != 0) { goto fail; } fraction = modf(val, &integral); if (fraction != 0) { mul_required = 1; } c = *endptr; mul = suffix_mul(c, unit); if (mul >= 0) { endptr++; } else { mul = suffix_mul(default_suffix, unit); assert(mul >= 0); } if (mul == 1 && mul_required) { goto fail; } if ((val * mul >= INT64_MAX) || val < 0) { retval = -ERANGE; goto fail; } retval = val * mul; fail: if (end) { *end = endptr; } return retval; } int64_t strtosz_suffix(const char *nptr, char **end, const char default_suffix) { return strtosz_suffix_unit(nptr, end, default_suffix, 1024); } int64_t strtosz(const char *nptr, char **end) { return strtosz_suffix(nptr, end, STRTOSZ_DEFSUFFIX_MB); } /** * parse_uint: * * @s: String to parse * @value: Destination for parsed integer value * @endptr: Destination for pointer to first character not consumed * @base: integer base, between 2 and 36 inclusive, or 0 * * Parse unsigned integer * * Parsed syntax is like strtoull()'s: arbitrary whitespace, a single optional * '+' or '-', an optional "0x" if @base is 0 or 16, one or more digits. * * If @s is null, or @base is invalid, or @s doesn't start with an * integer in the syntax above, set *@value to 0, *@endptr to @s, and * return -EINVAL. * * Set *@endptr to point right beyond the parsed integer (even if the integer * overflows or is negative, all digits will be parsed and *@endptr will * point right beyond them). * * If the integer is negative, set *@value to 0, and return -ERANGE. * * If the integer overflows unsigned long long, set *@value to * ULLONG_MAX, and return -ERANGE. * * Else, set *@value to the parsed integer, and return 0. */ int parse_uint(const char *s, unsigned long long *value, char **endptr, int base) { int r = 0; char *endp = (char *)s; unsigned long long val = 0; if (!s) { r = -EINVAL; goto out; } errno = 0; val = strtoull(s, &endp, base); if (errno) { r = -errno; goto out; } if (endp == s) { r = -EINVAL; goto out; } /* make sure we reject negative numbers: */ while (isspace((unsigned char)*s)) { s++; } if (*s == '-') { val = 0; r = -ERANGE; goto out; } out: *value = val; *endptr = endp; return r; } /** * parse_uint_full: * * @s: String to parse * @value: Destination for parsed integer value * @base: integer base, between 2 and 36 inclusive, or 0 * * Parse unsigned integer from entire string * * Have the same behavior of parse_uint(), but with an additional check * for additional data after the parsed number. If extra characters are present * after the parsed number, the function will return -EINVAL, and *@v will * be set to 0. */ int parse_uint_full(const char *s, unsigned long long *value, int base) { char *endp; int r; r = parse_uint(s, value, &endp, base); if (r < 0) { return r; } if (*endp) { *value = 0; return -EINVAL; } return 0; } int qemu_parse_fd(const char *param) { int fd; char *endptr = NULL; fd = strtol(param, &endptr, 10); if (*endptr || (fd == 0 && param == endptr)) { return -1; } return fd; } /* round down to the nearest power of 2*/ int64_t pow2floor(int64_t value) { if (!is_power_of_2(value)) { value = 0x8000000000000000ULL >> clz64(value); } return value; } /* * Implementation of ULEB128 (http://en.wikipedia.org/wiki/LEB128) * Input is limited to 14-bit numbers */ int uleb128_encode_small(uint8_t *out, uint32_t n) { g_assert(n <= 0x3fff); if (n < 0x80) { *out++ = n; return 1; } else { *out++ = (n & 0x7f) | 0x80; *out++ = n >> 7; return 2; } } int uleb128_decode_small(const uint8_t *in, uint32_t *n) { if (!(*in & 0x80)) { *n = *in++; return 1; } else { *n = *in++ & 0x7f; /* we exceed 14 bit number */ if (*in & 0x80) { return -1; } *n |= *in++ << 7; return 2; } } /* * helper to parse debug environment variables */ int parse_debug_env(const char *name, int max, int initial) { char *debug_env = getenv(name); char *inv = NULL; int debug; if (!debug_env) { return initial; } debug = strtol(debug_env, &inv, 10); if (inv == debug_env) { return initial; } if (debug < 0 || debug > max) { fprintf(stderr, "warning: %s not in [0, %d]", name, max); return initial; } return debug; } /* * Helper to print ethernet mac address */ const char *qemu_ether_ntoa(const MACAddr *mac) { static char ret[18]; snprintf(ret, sizeof(ret), "%02x:%02x:%02x:%02x:%02x:%02x", mac->a[0], mac->a[1], mac->a[2], mac->a[3], mac->a[4], mac->a[5]); return ret; }
gpl-2.0
The-DarkBeast/android_kernel_oneplus_msm8994
drivers/net/ethernet/msm/ecm_ipa.c
13
50540
/* Copyright (c) 2013-2015, The Linux Foundation. All rights reserved. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 and * only version 2 as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. */ #include <linux/debugfs.h> #include <linux/errno.h> #include <linux/etherdevice.h> #include <linux/fs.h> #include <linux/module.h> #include <linux/netdevice.h> #include <linux/skbuff.h> #include <linux/sched.h> #include <linux/atomic.h> #include <linux/ecm_ipa.h> #define DRIVER_NAME "ecm_ipa" #define ECM_IPA_IPV4_HDR_NAME "ecm_eth_ipv4" #define ECM_IPA_IPV6_HDR_NAME "ecm_eth_ipv6" #define INACTIVITY_MSEC_DELAY 100 #define DEFAULT_OUTSTANDING_HIGH 64 #define DEFAULT_OUTSTANDING_LOW 32 #define DEBUGFS_TEMP_BUF_SIZE 4 #define TX_TIMEOUT (5 * HZ) #define ECM_IPA_DEBUG(fmt, args...) \ pr_debug("ctx:%s: "\ fmt, current->comm, ## args) #define ECM_IPA_INFO(fmt, args...) \ pr_err(DRIVER_NAME "@%s@%d@ctx:%s: "\ fmt, __func__, __LINE__, current->comm, ## args) #define ECM_IPA_ERROR(fmt, args...) \ pr_err(DRIVER_NAME "@%s@%d@ctx:%s: "\ fmt, __func__, __LINE__, current->comm, ## args) #define NULL_CHECK(ptr) \ do { \ if (!(ptr)) { \ ECM_IPA_ERROR("null pointer #ptr\n"); \ return -EINVAL; \ } \ } \ while (0) #define ECM_IPA_LOG_ENTRY() ECM_IPA_DEBUG("begin\n") #define ECM_IPA_LOG_EXIT() ECM_IPA_DEBUG("end\n") /** * enum ecm_ipa_state - specify the current driver internal state * which is guarded by a state machine. * * The driver internal state changes due to its external API usage. * The driver saves its internal state to guard from caller illegal * call sequence. * states: * UNLOADED is the first state which is the default one and is also the state * after the driver gets unloaded(cleanup). * INITIALIZED is the driver state once it finished registering * the network device and all internal data struct were initialized * CONNECTED is the driver state once the USB pipes were connected to IPA * UP is the driver state after the interface mode was set to UP but the * pipes are not connected yet - this state is meta-stable state. * CONNECTED_AND_UP is the driver state when the pipe were connected and * the interface got UP request from the network stack. this is the driver * idle operation state which allows it to transmit/receive data. * INVALID is a state which is not allowed. */ enum ecm_ipa_state { ECM_IPA_UNLOADED = 0, ECM_IPA_INITIALIZED, ECM_IPA_CONNECTED, ECM_IPA_UP, ECM_IPA_CONNECTED_AND_UP, ECM_IPA_INVALID, }; /** * enum ecm_ipa_operation - enumerations used to descibe the API operation * * Those enums are used as input for the driver state machine. */ enum ecm_ipa_operation { ECM_IPA_INITIALIZE, ECM_IPA_CONNECT, ECM_IPA_OPEN, ECM_IPA_STOP, ECM_IPA_DISCONNECT, ECM_IPA_CLEANUP, }; #define ECM_IPA_STATE_DEBUG(ecm_ipa_ctx) \ ECM_IPA_DEBUG("Driver state - %s\n",\ ecm_ipa_state_string(ecm_ipa_ctx->state)); /** * struct ecm_ipa_dev - main driver context parameters * @net: network interface struct implemented by this driver * @directory: debugfs directory for various debuging switches * @tx_enable: flag that enable/disable Tx path to continue to IPA * @rx_enable: flag that enable/disable Rx path to continue to IPA * @rm_enable: flag that enable/disable Resource manager request prior to Tx * @dma_enable: flag that allow on-the-fly DMA mode for IPA * @eth_ipv4_hdr_hdl: saved handle for ipv4 header-insertion table * @eth_ipv6_hdr_hdl: saved handle for ipv6 header-insertion table * @usb_to_ipa_hdl: save handle for IPA pipe operations * @ipa_to_usb_hdl: save handle for IPA pipe operations * @outstanding_pkts: number of packets sent to IPA without TX complete ACKed * @outstanding_high: number of outstanding packets allowed * @outstanding_low: number of outstanding packets which shall cause * to netdev queue start (after stopped due to outstanding_high reached) * @state: current state of ecm_ipa driver * @device_ready_notify: callback supplied by USB core driver * This callback shall be called by the Netdev once the Netdev internal * state is changed to RNDIS_IPA_CONNECTED_AND_UP * @ipa_to_usb_client: consumer client * @usb_to_ipa_client: producer client * @ipa_rm_resource_name_prod: IPA resource manager producer resource * @ipa_rm_resource_name_cons: IPA resource manager consumer resource */ struct ecm_ipa_dev { struct net_device *net; u32 tx_enable; u32 rx_enable; u32 rm_enable; bool dma_enable; struct dentry *directory; uint32_t eth_ipv4_hdr_hdl; uint32_t eth_ipv6_hdr_hdl; u32 usb_to_ipa_hdl; u32 ipa_to_usb_hdl; atomic_t outstanding_pkts; u8 outstanding_high; u8 outstanding_low; enum ecm_ipa_state state; void (*device_ready_notify)(void); enum ipa_client_type ipa_to_usb_client; enum ipa_client_type usb_to_ipa_client; enum ipa_rm_resource_name ipa_rm_resource_name_prod; enum ipa_rm_resource_name ipa_rm_resource_name_cons; }; static int ecm_ipa_open(struct net_device *net); static void ecm_ipa_packet_receive_notify(void *priv, enum ipa_dp_evt_type evt, unsigned long data); static void ecm_ipa_tx_complete_notify(void *priv, enum ipa_dp_evt_type evt, unsigned long data); static void ecm_ipa_tx_timeout(struct net_device *net); static int ecm_ipa_stop(struct net_device *net); static void ecm_ipa_enable_data_path(struct ecm_ipa_dev *ecm_ipa_ctx); static int ecm_ipa_rules_cfg(struct ecm_ipa_dev *ecm_ipa_ctx, const void *dst_mac, const void *src_mac); static void ecm_ipa_rules_destroy(struct ecm_ipa_dev *ecm_ipa_ctx); static int ecm_ipa_register_properties(struct ecm_ipa_dev *ecm_ipa_ctx); static void ecm_ipa_deregister_properties(void); static void ecm_ipa_rm_notify(void *user_data, enum ipa_rm_event event, unsigned long data); static struct net_device_stats *ecm_ipa_get_stats(struct net_device *net); static int ecm_ipa_create_rm_resource(struct ecm_ipa_dev *ecm_ipa_ctx); static void ecm_ipa_destory_rm_resource(struct ecm_ipa_dev *ecm_ipa_ctx); static bool rx_filter(struct sk_buff *skb); static bool tx_filter(struct sk_buff *skb); static bool rm_enabled(struct ecm_ipa_dev *ecm_ipa_ctx); static int resource_request(struct ecm_ipa_dev *ecm_ipa_ctx); static void resource_release(struct ecm_ipa_dev *ecm_ipa_ctx); static netdev_tx_t ecm_ipa_start_xmit(struct sk_buff *skb, struct net_device *net); static int ecm_ipa_debugfs_stall_open(struct inode *inode, struct file *file); static ssize_t ecm_ipa_debugfs_stall_write(struct file *file, const char __user *buf, size_t count, loff_t *ppos); static int ecm_ipa_debugfs_atomic_open(struct inode *inode, struct file *file); static ssize_t ecm_ipa_debugfs_enable_write_dma(struct file *file, const char __user *buf, size_t count, loff_t *ppos); static int ecm_ipa_debugfs_dma_open(struct inode *inode, struct file *file); static ssize_t ecm_ipa_debugfs_enable_write(struct file *file, const char __user *buf, size_t count, loff_t *ppos); static ssize_t ecm_ipa_debugfs_enable_read(struct file *file, char __user *ubuf, size_t count, loff_t *ppos); static ssize_t ecm_ipa_debugfs_atomic_read(struct file *file, char __user *ubuf, size_t count, loff_t *ppos); static int ecm_ipa_debugfs_init(struct ecm_ipa_dev *ecm_ipa_ctx); static void ecm_ipa_debugfs_destroy(struct ecm_ipa_dev *ecm_ipa_ctx); static int ecm_ipa_ep_registers_cfg(u32 usb_to_ipa_hdl, u32 ipa_to_usb_hdl); static int ecm_ipa_ep_registers_dma_cfg(u32 usb_to_ipa_hdl, enum ipa_client_type prod_client); static int ecm_ipa_set_device_ethernet_addr(u8 *dev_ethaddr, u8 device_ethaddr[]); static enum ecm_ipa_state ecm_ipa_next_state(enum ecm_ipa_state current_state, enum ecm_ipa_operation operation); static const char *ecm_ipa_state_string(enum ecm_ipa_state state); static int ecm_ipa_init_module(void); static void ecm_ipa_cleanup_module(void); static const struct net_device_ops ecm_ipa_netdev_ops = { .ndo_open = ecm_ipa_open, .ndo_stop = ecm_ipa_stop, .ndo_start_xmit = ecm_ipa_start_xmit, .ndo_set_mac_address = eth_mac_addr, .ndo_tx_timeout = ecm_ipa_tx_timeout, .ndo_get_stats = ecm_ipa_get_stats, }; const struct file_operations ecm_ipa_debugfs_dma_ops = { .open = ecm_ipa_debugfs_dma_open, .read = ecm_ipa_debugfs_enable_read, .write = ecm_ipa_debugfs_enable_write_dma, }; const struct file_operations ecm_ipa_debugfs_atomic_ops = { .open = ecm_ipa_debugfs_atomic_open, .read = ecm_ipa_debugfs_atomic_read, }; const struct file_operations ecm_ipa_debugfs_stall_ops = { .open = ecm_ipa_debugfs_stall_open, .write = ecm_ipa_debugfs_stall_write, }; static void ecm_ipa_msg_free_cb(void *buff, u32 len, u32 type) { kfree(buff); } /** * ecm_ipa_init() - create network device and initializes internal * data structures * @params: in/out parameters required for ecm_ipa initialization * * Shall be called prior to pipe connection. * The out parameters (the callbacks) shall be supplied to ipa_connect. * Detailed description: * - allocate the network device * - set default values for driver internals * - create debugfs folder and files * - create IPA resource manager client * - add header insertion rules for IPA driver (based on host/device * Ethernet addresses given in input params) * - register tx/rx properties to IPA driver (will be later used * by IPA configuration manager to configure reset of the IPA rules) * - set the carrier state to "off" (until ecm_ipa_connect is called) * - register the network device * - set the out parameters * * Returns negative errno, or zero on success */ int ecm_ipa_init(struct ecm_ipa_params *params) { int result = 0; struct net_device *net; struct ecm_ipa_dev *ecm_ipa_ctx; ECM_IPA_LOG_ENTRY(); ECM_IPA_DEBUG("%s initializing\n", DRIVER_NAME); NULL_CHECK(params); ECM_IPA_DEBUG("host_ethaddr=%pM, device_ethaddr=%pM\n", params->host_ethaddr, params->device_ethaddr); net = alloc_etherdev(sizeof(struct ecm_ipa_dev)); if (!net) { result = -ENOMEM; ECM_IPA_ERROR("fail to allocate etherdev\n"); goto fail_alloc_etherdev; } ECM_IPA_DEBUG("network device was successfully allocated\n"); ecm_ipa_ctx = netdev_priv(net); if (!ecm_ipa_ctx) { ECM_IPA_ERROR("fail to extract netdev priv\n"); result = -ENOMEM; goto fail_netdev_priv; } memset(ecm_ipa_ctx, 0, sizeof(*ecm_ipa_ctx)); ECM_IPA_DEBUG("ecm_ipa_ctx (private) = %p\n", ecm_ipa_ctx); ecm_ipa_ctx->net = net; ecm_ipa_ctx->tx_enable = true; ecm_ipa_ctx->rx_enable = true; ecm_ipa_ctx->rm_enable = true; ecm_ipa_ctx->outstanding_high = DEFAULT_OUTSTANDING_HIGH; ecm_ipa_ctx->outstanding_low = DEFAULT_OUTSTANDING_LOW; atomic_set(&ecm_ipa_ctx->outstanding_pkts, 0); snprintf(net->name, sizeof(net->name), "%s%%d", "ecm"); net->netdev_ops = &ecm_ipa_netdev_ops; net->watchdog_timeo = TX_TIMEOUT; ECM_IPA_DEBUG("internal data structures were intialized\n"); if (!params->device_ready_notify) ECM_IPA_DEBUG("device_ready_notify() was not supplied"); ecm_ipa_ctx->device_ready_notify = params->device_ready_notify; result = ecm_ipa_debugfs_init(ecm_ipa_ctx); if (result) goto fail_debugfs; ECM_IPA_DEBUG("debugfs entries were created\n"); result = ecm_ipa_set_device_ethernet_addr(net->dev_addr, params->device_ethaddr); if (result) { ECM_IPA_ERROR("set device MAC failed\n"); goto fail_set_device_ethernet; } ECM_IPA_DEBUG("Device Ethernet address set %pM\n", net->dev_addr); result = ecm_ipa_rules_cfg(ecm_ipa_ctx, params->host_ethaddr, params->device_ethaddr); if (result) { ECM_IPA_ERROR("fail on ipa rules set\n"); goto fail_rules_cfg; } ECM_IPA_DEBUG("Ethernet header insertion set\n"); netif_carrier_off(net); ECM_IPA_DEBUG("netif_carrier_off() was called\n"); netif_stop_queue(ecm_ipa_ctx->net); ECM_IPA_DEBUG("netif_stop_queue() was called"); result = register_netdev(net); if (result) { ECM_IPA_ERROR("register_netdev failed: %d\n", result); goto fail_register_netdev; } ECM_IPA_DEBUG("register_netdev succeeded\n"); params->ecm_ipa_rx_dp_notify = ecm_ipa_packet_receive_notify; params->ecm_ipa_tx_dp_notify = ecm_ipa_tx_complete_notify; params->private = (void *)ecm_ipa_ctx; params->skip_ep_cfg = false; ecm_ipa_ctx->state = ECM_IPA_INITIALIZED; ECM_IPA_STATE_DEBUG(ecm_ipa_ctx); ECM_IPA_INFO("ECM_IPA was initialized successfully\n"); ECM_IPA_LOG_EXIT(); return 0; fail_register_netdev: ecm_ipa_rules_destroy(ecm_ipa_ctx); fail_set_device_ethernet: fail_rules_cfg: ecm_ipa_debugfs_destroy(ecm_ipa_ctx); fail_debugfs: fail_netdev_priv: free_netdev(net); fail_alloc_etherdev: return result; } EXPORT_SYMBOL(ecm_ipa_init); /** * ecm_ipa_connect() - notify ecm_ipa for IPA<->USB pipes connection * @usb_to_ipa_hdl: handle of IPA driver client for USB->IPA * @ipa_to_usb_hdl: handle of IPA driver client for IPA->USB * @priv: same value that was set by ecm_ipa_init(), this * parameter holds the network device pointer. * * Once USB driver finishes the pipe connection between IPA core * and USB core this method shall be called in order to * allow ecm_ipa complete the data path configurations. * Caller should make sure that it is calling this function * from a context that allows it to handle device_ready_notify(). * Detailed description: * - configure the IPA end-points register * - notify the Linux kernel for "carrier_on" * After this function is done the driver state changes to "Connected". * This API is expected to be called after ecm_ipa_init() or * after a call to ecm_ipa_disconnect. */ int ecm_ipa_connect(u32 usb_to_ipa_hdl, u32 ipa_to_usb_hdl, void *priv) { struct ecm_ipa_dev *ecm_ipa_ctx = priv; int next_state; struct ipa_ecm_msg *ecm_msg; struct ipa_msg_meta msg_meta; int retval; ECM_IPA_LOG_ENTRY(); NULL_CHECK(priv); ECM_IPA_DEBUG("usb_to_ipa_hdl = %d, ipa_to_usb_hdl = %d, priv=0x%p\n", usb_to_ipa_hdl, ipa_to_usb_hdl, priv); next_state = ecm_ipa_next_state(ecm_ipa_ctx->state, ECM_IPA_CONNECT); if (next_state == ECM_IPA_INVALID) { ECM_IPA_ERROR("can't call connect before calling initialize\n"); return -EPERM; } ecm_ipa_ctx->state = next_state; ECM_IPA_STATE_DEBUG(ecm_ipa_ctx); if (!ipa_is_client_handle_valid(usb_to_ipa_hdl)) { ECM_IPA_ERROR("usb_to_ipa_hdl(%d) is not a valid ipa handle\n", usb_to_ipa_hdl); return -EINVAL; } if (!ipa_is_client_handle_valid(ipa_to_usb_hdl)) { ECM_IPA_ERROR("ipa_to_usb_hdl(%d) is not a valid ipa handle\n", ipa_to_usb_hdl); return -EINVAL; } ecm_ipa_ctx->ipa_to_usb_hdl = ipa_to_usb_hdl; ecm_ipa_ctx->usb_to_ipa_hdl = usb_to_ipa_hdl; ecm_ipa_ctx->ipa_to_usb_client = ipa_get_client_mapping(ipa_to_usb_hdl); if (ecm_ipa_ctx->ipa_to_usb_client < 0) { ECM_IPA_ERROR( "Error getting IPA->USB client from handle %d\n", ecm_ipa_ctx->ipa_to_usb_client); return -EINVAL; } ECM_IPA_DEBUG("ipa_to_usb_client = %d\n", ecm_ipa_ctx->ipa_to_usb_client); ecm_ipa_ctx->usb_to_ipa_client = ipa_get_client_mapping(usb_to_ipa_hdl); if (ecm_ipa_ctx->usb_to_ipa_client < 0) { ECM_IPA_ERROR( "Error getting USB->IPA client from handle %d\n", ecm_ipa_ctx->usb_to_ipa_client); return -EINVAL; } ECM_IPA_DEBUG("usb_to_ipa_client = %d\n", ecm_ipa_ctx->usb_to_ipa_client); ecm_ipa_ctx->ipa_rm_resource_name_cons = ipa_get_rm_resource_from_ep(ipa_to_usb_hdl); if (ecm_ipa_ctx->ipa_rm_resource_name_cons < 0) { ECM_IPA_ERROR("Error getting CONS RM resource from handle %d\n", ecm_ipa_ctx->ipa_rm_resource_name_cons); return -EINVAL; } ECM_IPA_DEBUG("ipa_rm_resource_name_cons = %d\n", ecm_ipa_ctx->ipa_rm_resource_name_cons); ecm_ipa_ctx->ipa_rm_resource_name_prod = ipa_get_rm_resource_from_ep(usb_to_ipa_hdl); if (ecm_ipa_ctx->ipa_rm_resource_name_prod < 0) { ECM_IPA_ERROR("Error getting PROD RM resource from handle %d\n", ecm_ipa_ctx->ipa_rm_resource_name_prod); return -EINVAL; } ECM_IPA_DEBUG("ipa_rm_resource_name_prod = %d\n", ecm_ipa_ctx->ipa_rm_resource_name_prod); retval = ecm_ipa_create_rm_resource(ecm_ipa_ctx); if (retval) { ECM_IPA_ERROR("fail on RM create\n"); goto fail_create_rm; } ECM_IPA_DEBUG("RM resource was created\n"); retval = ecm_ipa_register_properties(ecm_ipa_ctx); if (retval) { ECM_IPA_ERROR("fail on properties set\n"); goto fail_create_rm; } ECM_IPA_DEBUG("ecm_ipa 2 Tx and 2 Rx properties were registered\n"); retval = ecm_ipa_ep_registers_cfg(usb_to_ipa_hdl, ipa_to_usb_hdl); if (retval) { ECM_IPA_ERROR("fail on ep cfg\n"); goto fail; } ECM_IPA_DEBUG("end-point configured\n"); netif_carrier_on(ecm_ipa_ctx->net); ecm_msg = kzalloc(sizeof(struct ipa_ecm_msg), GFP_KERNEL); if (!ecm_msg) { ECM_IPA_ERROR("can't alloc msg mem\n"); retval = -ENOMEM; goto fail; } memset(&msg_meta, 0, sizeof(struct ipa_msg_meta)); msg_meta.msg_type = ECM_CONNECT; msg_meta.msg_len = sizeof(struct ipa_ecm_msg); strlcpy(ecm_msg->name, ecm_ipa_ctx->net->name, IPA_RESOURCE_NAME_MAX); ecm_msg->ifindex = ecm_ipa_ctx->net->ifindex; retval = ipa_send_msg(&msg_meta, ecm_msg, ecm_ipa_msg_free_cb); if (retval) { ECM_IPA_ERROR("fail to send ECM_CONNECT message\n"); kfree(ecm_msg); goto fail; } if (!netif_carrier_ok(ecm_ipa_ctx->net)) { ECM_IPA_ERROR("netif_carrier_ok error\n"); retval = -EBUSY; goto fail; } ECM_IPA_DEBUG("carrier_on notified\n"); if (ecm_ipa_ctx->state == ECM_IPA_CONNECTED_AND_UP) ecm_ipa_enable_data_path(ecm_ipa_ctx); else ECM_IPA_DEBUG("data path was not enabled yet\n"); ECM_IPA_INFO("ECM_IPA was connected successfully\n"); ECM_IPA_LOG_EXIT(); return 0; fail: ecm_ipa_deregister_properties(); fail_create_rm: ecm_ipa_destory_rm_resource(ecm_ipa_ctx); return retval; } EXPORT_SYMBOL(ecm_ipa_connect); /** * ecm_ipa_open() - notify Linux network stack to start sending packets * @net: the network interface supplied by the network stack * * Linux uses this API to notify the driver that the network interface * transitions to the up state. * The driver will instruct the Linux network stack to start * delivering data packets. */ static int ecm_ipa_open(struct net_device *net) { struct ecm_ipa_dev *ecm_ipa_ctx; int next_state; ECM_IPA_LOG_ENTRY(); ecm_ipa_ctx = netdev_priv(net); next_state = ecm_ipa_next_state(ecm_ipa_ctx->state, ECM_IPA_OPEN); if (next_state == ECM_IPA_INVALID) { ECM_IPA_ERROR("can't bring driver up before initialize\n"); return -EPERM; } ecm_ipa_ctx->state = next_state; ECM_IPA_STATE_DEBUG(ecm_ipa_ctx); if (ecm_ipa_ctx->state == ECM_IPA_CONNECTED_AND_UP) ecm_ipa_enable_data_path(ecm_ipa_ctx); else ECM_IPA_DEBUG("data path was not enabled yet\n"); ECM_IPA_LOG_EXIT(); return 0; } /** * ecm_ipa_start_xmit() - send data from APPs to USB core via IPA core * @skb: packet received from Linux network stack * @net: the network device being used to send this packet * * Several conditions needed in order to send the packet to IPA: * - Transmit queue for the network driver is currently * in "send" state * - The driver internal state is in "UP" state. * - Filter Tx switch is turned off * - The IPA resource manager state for the driver producer client * is "Granted" which implies that all the resources in the dependency * graph are valid for data flow. * - outstanding high boundary did not reach. * * In case all of the above conditions are met, the network driver will * send the packet by using the IPA API for Tx. * In case the outstanding packet high boundary is reached, the driver will * stop the send queue until enough packet were proceeded by the IPA core. */ static netdev_tx_t ecm_ipa_start_xmit(struct sk_buff *skb, struct net_device *net) { int ret; netdev_tx_t status = NETDEV_TX_BUSY; struct ecm_ipa_dev *ecm_ipa_ctx = netdev_priv(net); net->trans_start = jiffies; ECM_IPA_DEBUG("Tx, len=%d, skb->protocol=%d, outstanding=%d\n", skb->len, skb->protocol, atomic_read(&ecm_ipa_ctx->outstanding_pkts)); if (unlikely(netif_queue_stopped(net))) { ECM_IPA_ERROR("interface queue is stopped\n"); goto out; } if (unlikely(ecm_ipa_ctx->state != ECM_IPA_CONNECTED_AND_UP)) { ECM_IPA_ERROR("Missing pipe connected and/or iface up\n"); return NETDEV_TX_BUSY; } if (unlikely(tx_filter(skb))) { dev_kfree_skb_any(skb); ECM_IPA_DEBUG("packet got filtered out on Tx path\n"); status = NETDEV_TX_OK; goto out; } ret = resource_request(ecm_ipa_ctx); if (ret) { ECM_IPA_DEBUG("Waiting to resource\n"); netif_stop_queue(net); goto resource_busy; } if (atomic_read(&ecm_ipa_ctx->outstanding_pkts) >= ecm_ipa_ctx->outstanding_high) { ECM_IPA_DEBUG("outstanding high (%d)- stopping\n", ecm_ipa_ctx->outstanding_high); netif_stop_queue(net); status = NETDEV_TX_BUSY; goto out; } ret = ipa_tx_dp(ecm_ipa_ctx->ipa_to_usb_client, skb, NULL); if (ret) { ECM_IPA_ERROR("ipa transmit failed (%d)\n", ret); goto fail_tx_packet; } atomic_inc(&ecm_ipa_ctx->outstanding_pkts); status = NETDEV_TX_OK; goto out; fail_tx_packet: out: resource_release(ecm_ipa_ctx); resource_busy: return status; } /** * ecm_ipa_packet_receive_notify() - Rx notify * * @priv: ecm driver context * @evt: event type * @data: data provided with event * * IPA will pass a packet to the Linux network stack with skb->data pointing * to Ethernet packet frame. */ static void ecm_ipa_packet_receive_notify(void *priv, enum ipa_dp_evt_type evt, unsigned long data) { struct sk_buff *skb = (struct sk_buff *)data; struct ecm_ipa_dev *ecm_ipa_ctx = priv; int result; unsigned int packet_len = skb->len; if (!skb) { ECM_IPA_ERROR("Bad SKB received from IPA driver\n"); return; } ECM_IPA_DEBUG("packet RX, len=%d\n", skb->len); if (unlikely(ecm_ipa_ctx->state != ECM_IPA_CONNECTED_AND_UP)) { ECM_IPA_DEBUG("Missing pipe connected and/or iface up\n"); return; } if (evt != IPA_RECEIVE) { ECM_IPA_ERROR("A none IPA_RECEIVE event in ecm_ipa_receive\n"); return; } skb->dev = ecm_ipa_ctx->net; skb->protocol = eth_type_trans(skb, ecm_ipa_ctx->net); if (rx_filter(skb)) { ECM_IPA_DEBUG("packet got filtered out on Rx path\n"); dev_kfree_skb_any(skb); return; } result = netif_rx_ni(skb); if (result) ECM_IPA_ERROR("fail on netif_rx_ni\n"); ecm_ipa_ctx->net->stats.rx_packets++; ecm_ipa_ctx->net->stats.rx_bytes += packet_len; return; } /** ecm_ipa_stop() - called when network device transitions to the down * state. * @net: the network device being stopped. * * This API is used by Linux network stack to notify the network driver that * its state was changed to "down" * The driver will stop the "send" queue and change its internal * state to "Connected". */ static int ecm_ipa_stop(struct net_device *net) { struct ecm_ipa_dev *ecm_ipa_ctx = netdev_priv(net); int next_state; ECM_IPA_LOG_ENTRY(); next_state = ecm_ipa_next_state(ecm_ipa_ctx->state, ECM_IPA_STOP); if (next_state == ECM_IPA_INVALID) { ECM_IPA_ERROR("can't do network interface down without up\n"); return -EPERM; } ecm_ipa_ctx->state = next_state; ECM_IPA_STATE_DEBUG(ecm_ipa_ctx); netif_stop_queue(net); ECM_IPA_DEBUG("network device stopped\n"); ECM_IPA_LOG_EXIT(); return 0; } /** ecm_ipa_disconnect() - called when the USB cable is unplugged. * @priv: same value that was set by ecm_ipa_init(), this * parameter holds the network device pointer. * * Once the USB cable is unplugged the USB driver will notify the network * interface driver. * The internal driver state will returned to its initialized state and * Linux network stack will be informed for carrier off and the send queue * will be stopped. */ int ecm_ipa_disconnect(void *priv) { struct ecm_ipa_dev *ecm_ipa_ctx = priv; int next_state; struct ipa_ecm_msg *ecm_msg; struct ipa_msg_meta msg_meta; int retval; int outstanding_dropped_pkts; ECM_IPA_LOG_ENTRY(); NULL_CHECK(ecm_ipa_ctx); ECM_IPA_DEBUG("priv=0x%p\n", priv); next_state = ecm_ipa_next_state(ecm_ipa_ctx->state, ECM_IPA_DISCONNECT); if (next_state == ECM_IPA_INVALID) { ECM_IPA_ERROR("can't disconnect before connect\n"); return -EPERM; } ecm_ipa_ctx->state = next_state; ECM_IPA_STATE_DEBUG(ecm_ipa_ctx); netif_carrier_off(ecm_ipa_ctx->net); ECM_IPA_DEBUG("carrier_off notifcation was sent\n"); ecm_msg = kzalloc(sizeof(struct ipa_ecm_msg), GFP_KERNEL); if (!ecm_msg) { ECM_IPA_ERROR("can't alloc msg mem\n"); return -ENOMEM; } memset(&msg_meta, 0, sizeof(struct ipa_msg_meta)); msg_meta.msg_type = ECM_DISCONNECT; msg_meta.msg_len = sizeof(struct ipa_ecm_msg); strlcpy(ecm_msg->name, ecm_ipa_ctx->net->name, IPA_RESOURCE_NAME_MAX); ecm_msg->ifindex = ecm_ipa_ctx->net->ifindex; retval = ipa_send_msg(&msg_meta, ecm_msg, ecm_ipa_msg_free_cb); if (retval) { ECM_IPA_ERROR("fail to send ECM_DISCONNECT message\n"); kfree(ecm_msg); return -EPERM; } netif_stop_queue(ecm_ipa_ctx->net); ECM_IPA_DEBUG("queue stopped\n"); ecm_ipa_destory_rm_resource(ecm_ipa_ctx); outstanding_dropped_pkts = atomic_read(&ecm_ipa_ctx->outstanding_pkts); ecm_ipa_ctx->net->stats.tx_errors += outstanding_dropped_pkts; atomic_set(&ecm_ipa_ctx->outstanding_pkts, 0); ECM_IPA_INFO("ECM_IPA was disconnected successfully\n"); ECM_IPA_LOG_EXIT(); return 0; } EXPORT_SYMBOL(ecm_ipa_disconnect); /** * ecm_ipa_cleanup() - unregister the network interface driver and free * internal data structs. * @priv: same value that was set by ecm_ipa_init(), this * parameter holds the network device pointer. * * This function shall be called once the network interface is not * needed anymore, e.g: when the USB composition does not support ECM. * This function shall be called after the pipes were disconnected. * Detailed description: * - delete the driver dependency defined for IPA resource manager and * destroy the producer resource. * - remove the debugfs entries * - deregister the network interface from Linux network stack * - free all internal data structs */ void ecm_ipa_cleanup(void *priv) { struct ecm_ipa_dev *ecm_ipa_ctx = priv; int next_state; ECM_IPA_LOG_ENTRY(); ECM_IPA_DEBUG("priv=0x%p\n", priv); if (!ecm_ipa_ctx) { ECM_IPA_ERROR("ecm_ipa_ctx NULL pointer\n"); return; } next_state = ecm_ipa_next_state(ecm_ipa_ctx->state, ECM_IPA_CLEANUP); if (next_state == ECM_IPA_INVALID) { ECM_IPA_ERROR("can't clean driver without cable disconnect\n"); return; } ecm_ipa_ctx->state = next_state; ECM_IPA_STATE_DEBUG(ecm_ipa_ctx); ecm_ipa_rules_destroy(ecm_ipa_ctx); ecm_ipa_debugfs_destroy(ecm_ipa_ctx); unregister_netdev(ecm_ipa_ctx->net); free_netdev(ecm_ipa_ctx->net); ECM_IPA_INFO("ECM_IPA was destroyed successfully\n"); ECM_IPA_LOG_EXIT(); return; } EXPORT_SYMBOL(ecm_ipa_cleanup); static void ecm_ipa_enable_data_path(struct ecm_ipa_dev *ecm_ipa_ctx) { if (ecm_ipa_ctx->device_ready_notify) { ecm_ipa_ctx->device_ready_notify(); ECM_IPA_DEBUG("USB device_ready_notify() was called\n"); } else { ECM_IPA_DEBUG("device_ready_notify() not supplied\n"); } netif_start_queue(ecm_ipa_ctx->net); ECM_IPA_DEBUG("queue started\n"); } /** * ecm_ipa_rules_cfg() - set header insertion and register Tx/Rx properties * Headers will be commited to HW * @ecm_ipa_ctx: main driver context parameters * @dst_mac: destination MAC address * @src_mac: source MAC address * * Returns negative errno, or zero on success */ static int ecm_ipa_rules_cfg(struct ecm_ipa_dev *ecm_ipa_ctx, const void *dst_mac, const void *src_mac) { struct ipa_ioc_add_hdr *hdrs; struct ipa_hdr_add *ipv4_hdr; struct ipa_hdr_add *ipv6_hdr; struct ethhdr *eth_ipv4; struct ethhdr *eth_ipv6; int result = 0; ECM_IPA_LOG_ENTRY(); hdrs = kzalloc(sizeof(*hdrs) + sizeof(*ipv4_hdr) + sizeof(*ipv6_hdr), GFP_KERNEL); if (!hdrs) { result = -ENOMEM; goto out; } ipv4_hdr = &hdrs->hdr[0]; eth_ipv4 = (struct ethhdr *)ipv4_hdr->hdr; ipv6_hdr = &hdrs->hdr[1]; eth_ipv6 = (struct ethhdr *)ipv6_hdr->hdr; strlcpy(ipv4_hdr->name, ECM_IPA_IPV4_HDR_NAME, IPA_RESOURCE_NAME_MAX); memcpy(eth_ipv4->h_dest, dst_mac, ETH_ALEN); memcpy(eth_ipv4->h_source, src_mac, ETH_ALEN); eth_ipv4->h_proto = htons(ETH_P_IP); ipv4_hdr->hdr_len = ETH_HLEN; ipv4_hdr->is_partial = 0; ipv4_hdr->is_eth2_ofst_valid = true; ipv4_hdr->eth2_ofst = 0; ipv4_hdr->type = IPA_HDR_L2_ETHERNET_II; strlcpy(ipv6_hdr->name, ECM_IPA_IPV6_HDR_NAME, IPA_RESOURCE_NAME_MAX); memcpy(eth_ipv6->h_dest, dst_mac, ETH_ALEN); memcpy(eth_ipv6->h_source, src_mac, ETH_ALEN); eth_ipv6->h_proto = htons(ETH_P_IPV6); ipv6_hdr->hdr_len = ETH_HLEN; ipv6_hdr->is_partial = 0; ipv6_hdr->is_eth2_ofst_valid = true; ipv6_hdr->eth2_ofst = 0; ipv6_hdr->type = IPA_HDR_L2_ETHERNET_II; hdrs->commit = 1; hdrs->num_hdrs = 2; result = ipa_add_hdr(hdrs); if (result) { ECM_IPA_ERROR("Fail on Header-Insertion(%d)\n", result); goto out_free_mem; } if (ipv4_hdr->status) { ECM_IPA_ERROR("Fail on Header-Insertion ipv4(%d)\n", ipv4_hdr->status); result = ipv4_hdr->status; goto out_free_mem; } if (ipv6_hdr->status) { ECM_IPA_ERROR("Fail on Header-Insertion ipv6(%d)\n", ipv6_hdr->status); result = ipv6_hdr->status; goto out_free_mem; } ecm_ipa_ctx->eth_ipv4_hdr_hdl = ipv4_hdr->hdr_hdl; ecm_ipa_ctx->eth_ipv6_hdr_hdl = ipv6_hdr->hdr_hdl; ECM_IPA_LOG_EXIT(); out_free_mem: kfree(hdrs); out: return result; } /** * ecm_ipa_rules_destroy() - remove the IPA core configuration done for * the driver data path. * @ecm_ipa_ctx: the driver context * * Revert the work done on ecm_ipa_rules_cfg. */ static void ecm_ipa_rules_destroy(struct ecm_ipa_dev *ecm_ipa_ctx) { struct ipa_ioc_del_hdr *del_hdr; struct ipa_hdr_del *ipv4; struct ipa_hdr_del *ipv6; int result; del_hdr = kzalloc(sizeof(*del_hdr) + sizeof(*ipv4) + sizeof(*ipv6), GFP_KERNEL); if (!del_hdr) return; del_hdr->commit = 1; del_hdr->num_hdls = 2; ipv4 = &del_hdr->hdl[0]; ipv4->hdl = ecm_ipa_ctx->eth_ipv4_hdr_hdl; ipv6 = &del_hdr->hdl[1]; ipv6->hdl = ecm_ipa_ctx->eth_ipv6_hdr_hdl; result = ipa_del_hdr(del_hdr); if (result || ipv4->status || ipv6->status) ECM_IPA_ERROR("ipa_del_hdr failed\n"); kfree(del_hdr); } /* ecm_ipa_register_properties() - set Tx/Rx properties for ipacm * * Register ecm0 interface with 2 Tx properties and 2 Rx properties: * The 2 Tx properties are for data flowing from IPA to USB, they * have Header-Insertion properties both for Ipv4 and Ipv6 Ethernet framing. * The 2 Rx properties are for data flowing from USB to IPA, they have * simple rule which always "hit". * */ static int ecm_ipa_register_properties(struct ecm_ipa_dev *ecm_ipa_ctx) { struct ipa_tx_intf tx_properties = {0}; struct ipa_ioc_tx_intf_prop properties[2] = { {0}, {0} }; struct ipa_ioc_tx_intf_prop *ipv4_property; struct ipa_ioc_tx_intf_prop *ipv6_property; struct ipa_ioc_rx_intf_prop rx_ioc_properties[2] = { {0}, {0} }; struct ipa_rx_intf rx_properties = {0}; struct ipa_ioc_rx_intf_prop *rx_ipv4_property; struct ipa_ioc_rx_intf_prop *rx_ipv6_property; int result = 0; ECM_IPA_LOG_ENTRY(); tx_properties.prop = properties; ipv4_property = &tx_properties.prop[0]; ipv4_property->ip = IPA_IP_v4; ipv4_property->dst_pipe = ecm_ipa_ctx->ipa_to_usb_client; strlcpy(ipv4_property->hdr_name, ECM_IPA_IPV4_HDR_NAME, IPA_RESOURCE_NAME_MAX); ipv4_property->hdr_l2_type = IPA_HDR_L2_ETHERNET_II; ipv6_property = &tx_properties.prop[1]; ipv6_property->ip = IPA_IP_v6; ipv6_property->dst_pipe = ecm_ipa_ctx->ipa_to_usb_client; ipv6_property->hdr_l2_type = IPA_HDR_L2_ETHERNET_II; strlcpy(ipv6_property->hdr_name, ECM_IPA_IPV6_HDR_NAME, IPA_RESOURCE_NAME_MAX); tx_properties.num_props = 2; rx_properties.prop = rx_ioc_properties; rx_ipv4_property = &rx_properties.prop[0]; rx_ipv4_property->ip = IPA_IP_v4; rx_ipv4_property->attrib.attrib_mask = 0; rx_ipv4_property->src_pipe = ecm_ipa_ctx->usb_to_ipa_client; rx_ipv4_property->hdr_l2_type = IPA_HDR_L2_ETHERNET_II; rx_ipv6_property = &rx_properties.prop[1]; rx_ipv6_property->ip = IPA_IP_v6; rx_ipv6_property->attrib.attrib_mask = 0; rx_ipv6_property->src_pipe = ecm_ipa_ctx->usb_to_ipa_client; rx_ipv6_property->hdr_l2_type = IPA_HDR_L2_ETHERNET_II; rx_properties.num_props = 2; result = ipa_register_intf("ecm0", &tx_properties, &rx_properties); if (result) ECM_IPA_ERROR("fail on Tx/Rx properties registration\n"); ECM_IPA_LOG_EXIT(); return result; } static void ecm_ipa_deregister_properties(void) { int result; ECM_IPA_LOG_ENTRY(); result = ipa_deregister_intf("ecm0"); if (result) ECM_IPA_DEBUG("Fail on Tx prop deregister\n"); ECM_IPA_LOG_EXIT(); return; } /** * ecm_ipa_configure() - make IPA core end-point specific configuration * @usb_to_ipa_hdl: handle of usb_to_ipa end-point for IPA driver * @ipa_to_usb_hdl: handle of ipa_to_usb end-point for IPA driver * @host_ethaddr: host Ethernet address in network order * @device_ethaddr: device Ethernet address in network order * * Configure the usb_to_ipa and ipa_to_usb end-point registers * - USB->IPA end-point: disable de-aggregation, enable link layer * header removal (Ethernet removal), source NATing and default routing. * - IPA->USB end-point: disable aggregation, add link layer header (Ethernet) * - allocate Ethernet device * - register to Linux network stack * * Returns negative errno, or zero on success */ static void ecm_ipa_rm_notify(void *user_data, enum ipa_rm_event event, unsigned long data) { struct ecm_ipa_dev *ecm_ipa_ctx = user_data; ECM_IPA_LOG_ENTRY(); if (event == IPA_RM_RESOURCE_GRANTED && netif_queue_stopped(ecm_ipa_ctx->net)) { ECM_IPA_DEBUG("Resource Granted - starting queue\n"); netif_start_queue(ecm_ipa_ctx->net); } else { ECM_IPA_DEBUG("Resource released\n"); } ECM_IPA_LOG_EXIT(); } static struct net_device_stats *ecm_ipa_get_stats(struct net_device *net) { return &net->stats; } static int ecm_ipa_create_rm_resource(struct ecm_ipa_dev *ecm_ipa_ctx) { struct ipa_rm_create_params create_params = {0}; struct ipa_rm_perf_profile profile; int result; ECM_IPA_LOG_ENTRY(); create_params.name = IPA_RM_RESOURCE_STD_ECM_PROD; create_params.reg_params.user_data = ecm_ipa_ctx; create_params.reg_params.notify_cb = ecm_ipa_rm_notify; result = ipa_rm_create_resource(&create_params); if (result) { ECM_IPA_ERROR("Fail on ipa_rm_create_resource\n"); goto fail_rm_create; } ECM_IPA_DEBUG("rm client was created"); profile.max_supported_bandwidth_mbps = IPA_APPS_MAX_BW_IN_MBPS; ipa_rm_set_perf_profile(IPA_RM_RESOURCE_STD_ECM_PROD, &profile); result = ipa_rm_inactivity_timer_init(IPA_RM_RESOURCE_STD_ECM_PROD, INACTIVITY_MSEC_DELAY); if (result) { ECM_IPA_ERROR("Fail on ipa_rm_inactivity_timer_init\n"); goto fail_it; } ECM_IPA_DEBUG("rm_it client was created"); result = ipa_rm_add_dependency(IPA_RM_RESOURCE_STD_ECM_PROD, ecm_ipa_ctx->ipa_rm_resource_name_cons); if (result && result != -EINPROGRESS) ECM_IPA_ERROR("unable to add ECM/USB dependency (%d)\n", result); result = ipa_rm_add_dependency(ecm_ipa_ctx->ipa_rm_resource_name_prod, IPA_RM_RESOURCE_APPS_CONS); if (result && result != -EINPROGRESS) ECM_IPA_ERROR("unable to add USB/APPS dependency (%d)\n", result); ECM_IPA_DEBUG("rm dependency was set\n"); ECM_IPA_LOG_EXIT(); return 0; fail_it: fail_rm_create: return result; } static void ecm_ipa_destory_rm_resource(struct ecm_ipa_dev *ecm_ipa_ctx) { int result; ECM_IPA_LOG_ENTRY(); ipa_rm_delete_dependency(IPA_RM_RESOURCE_STD_ECM_PROD, ecm_ipa_ctx->ipa_rm_resource_name_cons); ipa_rm_delete_dependency(ecm_ipa_ctx->ipa_rm_resource_name_prod, IPA_RM_RESOURCE_APPS_CONS); ipa_rm_inactivity_timer_destroy(IPA_RM_RESOURCE_STD_ECM_PROD); result = ipa_rm_delete_resource(IPA_RM_RESOURCE_STD_ECM_PROD); if (result) ECM_IPA_ERROR("resource deletion failed\n"); ECM_IPA_LOG_EXIT(); } static bool rx_filter(struct sk_buff *skb) { struct ecm_ipa_dev *ecm_ipa_ctx = netdev_priv(skb->dev); return !ecm_ipa_ctx->rx_enable; } static bool tx_filter(struct sk_buff *skb) { struct ecm_ipa_dev *ecm_ipa_ctx = netdev_priv(skb->dev); return !ecm_ipa_ctx->tx_enable; } static bool rm_enabled(struct ecm_ipa_dev *ecm_ipa_ctx) { return ecm_ipa_ctx->rm_enable; } static int resource_request(struct ecm_ipa_dev *ecm_ipa_ctx) { int result = 0; if (!rm_enabled(ecm_ipa_ctx)) goto out; result = ipa_rm_inactivity_timer_request_resource( IPA_RM_RESOURCE_STD_ECM_PROD); out: return result; } static void resource_release(struct ecm_ipa_dev *ecm_ipa_ctx) { if (!rm_enabled(ecm_ipa_ctx)) goto out; ipa_rm_inactivity_timer_release_resource(IPA_RM_RESOURCE_STD_ECM_PROD); out: return; } /** * ecm_ipa_tx_complete_notify() - Rx notify * * @priv: ecm driver context * @evt: event type * @data: data provided with event * * Check that the packet is the one we sent and release it * This function will be called in defered context in IPA wq. */ static void ecm_ipa_tx_complete_notify(void *priv, enum ipa_dp_evt_type evt, unsigned long data) { struct sk_buff *skb = (struct sk_buff *)data; struct ecm_ipa_dev *ecm_ipa_ctx = priv; if (!skb) { ECM_IPA_ERROR("Bad SKB received from IPA driver\n"); return; } if (!ecm_ipa_ctx) { ECM_IPA_ERROR("ecm_ipa_ctx is NULL pointer\n"); return; } ECM_IPA_DEBUG("Tx-complete, len=%d, skb->prot=%d, outstanding=%d\n", skb->len, skb->protocol, atomic_read(&ecm_ipa_ctx->outstanding_pkts)); if (evt != IPA_WRITE_DONE) { ECM_IPA_ERROR("unsupported event on Tx callback\n"); return; } if (unlikely(ecm_ipa_ctx->state != ECM_IPA_CONNECTED_AND_UP)) { ECM_IPA_DEBUG("dropping Tx-complete pkt, state=%s", ecm_ipa_state_string(ecm_ipa_ctx->state)); goto out; } ecm_ipa_ctx->net->stats.tx_packets++; ecm_ipa_ctx->net->stats.tx_bytes += skb->len; atomic_dec(&ecm_ipa_ctx->outstanding_pkts); if (netif_queue_stopped(ecm_ipa_ctx->net) && netif_carrier_ok(ecm_ipa_ctx->net) && atomic_read(&ecm_ipa_ctx->outstanding_pkts) < (ecm_ipa_ctx->outstanding_low)) { ECM_IPA_DEBUG("outstanding low (%d) - waking up queue\n", ecm_ipa_ctx->outstanding_low); netif_wake_queue(ecm_ipa_ctx->net); } out: dev_kfree_skb_any(skb); return; } static void ecm_ipa_tx_timeout(struct net_device *net) { struct ecm_ipa_dev *ecm_ipa_ctx = netdev_priv(net); ECM_IPA_ERROR("possible IPA stall was detected, %d outstanding", atomic_read(&ecm_ipa_ctx->outstanding_pkts)); net->stats.tx_errors++; } static int ecm_ipa_debugfs_stall_open(struct inode *inode, struct file *file) { ECM_IPA_LOG_ENTRY(); ECM_IPA_LOG_EXIT(); return 0; } static ssize_t ecm_ipa_debugfs_stall_write(struct file *file, const char __user *buf, size_t count, loff_t *ppos) { u32 cmdq_cfg_mmio_phy = 0xFD4E3038; void *cmdq_cfg_mmio_virt; int result; bool val = 0; ECM_IPA_LOG_ENTRY(); file->private_data = &val; result = ecm_ipa_debugfs_enable_write(file, buf, count, ppos); cmdq_cfg_mmio_virt = ioremap(cmdq_cfg_mmio_phy, sizeof(u32)); if (!cmdq_cfg_mmio_virt) { ECM_IPA_ERROR("fail on mmio for cmdq_cfg_mmio_phy=0x%x", cmdq_cfg_mmio_phy); return result; } iowrite32(val, cmdq_cfg_mmio_virt); ECM_IPA_DEBUG("Value %d was written to cfgq", val); ECM_IPA_LOG_EXIT(); return result; } static int ecm_ipa_debugfs_atomic_open(struct inode *inode, struct file *file) { struct ecm_ipa_dev *ecm_ipa_ctx = inode->i_private; ECM_IPA_LOG_ENTRY(); file->private_data = &(ecm_ipa_ctx->outstanding_pkts); ECM_IPA_LOG_EXIT(); return 0; } static ssize_t ecm_ipa_debugfs_enable_write_dma(struct file *file, const char __user *buf, size_t count, loff_t *ppos) { struct ecm_ipa_dev *ecm_ipa_ctx = file->private_data; int result; ECM_IPA_LOG_ENTRY(); file->private_data = &ecm_ipa_ctx->dma_enable; result = ecm_ipa_debugfs_enable_write(file, buf, count, ppos); if (ecm_ipa_ctx->dma_enable) ecm_ipa_ep_registers_dma_cfg(ecm_ipa_ctx->usb_to_ipa_hdl, ecm_ipa_ctx->ipa_to_usb_client); else ecm_ipa_ep_registers_cfg(ecm_ipa_ctx->usb_to_ipa_hdl, ecm_ipa_ctx->usb_to_ipa_hdl); ECM_IPA_LOG_EXIT(); return result; } static int ecm_ipa_debugfs_dma_open(struct inode *inode, struct file *file) { struct ecm_ipa_dev *ecm_ipa_ctx = inode->i_private; ECM_IPA_LOG_ENTRY(); file->private_data = ecm_ipa_ctx; ECM_IPA_LOG_EXIT(); return 0; } static ssize_t ecm_ipa_debugfs_enable_write(struct file *file, const char __user *buf, size_t count, loff_t *ppos) { unsigned long missing; char input; bool *enable = file->private_data; if (count != sizeof(input) + 1) { ECM_IPA_ERROR("wrong input length(%zd)\n", count); return -EINVAL; } if (!buf) { ECM_IPA_ERROR("Bad argument\n"); return -EINVAL; } missing = copy_from_user(&input, buf, 1); if (missing) return -EFAULT; ECM_IPA_DEBUG("input received %c\n", input); *enable = input - '0'; ECM_IPA_DEBUG("value was set to %d\n", *enable); return count; } static ssize_t ecm_ipa_debugfs_enable_read(struct file *file, char __user *ubuf, size_t count, loff_t *ppos) { int nbytes; int size = 0; int ret; loff_t pos; u8 enable_str[sizeof(char)*3] = {0}; bool *enable = file->private_data; pos = *ppos; nbytes = scnprintf(enable_str, sizeof(enable_str), "%d\n", *enable); ret = simple_read_from_buffer(ubuf, count, ppos, enable_str, nbytes); if (ret < 0) { ECM_IPA_ERROR("simple_read_from_buffer problem\n"); return ret; } size += ret; count -= nbytes; *ppos = pos + size; return size; } static ssize_t ecm_ipa_debugfs_atomic_read(struct file *file, char __user *ubuf, size_t count, loff_t *ppos) { int nbytes; u8 atomic_str[DEBUGFS_TEMP_BUF_SIZE] = {0}; atomic_t *atomic_var = file->private_data; nbytes = scnprintf(atomic_str, sizeof(atomic_str), "%d\n", atomic_read(atomic_var)); return simple_read_from_buffer(ubuf, count, ppos, atomic_str, nbytes); } static int ecm_ipa_debugfs_init(struct ecm_ipa_dev *ecm_ipa_ctx) { const mode_t flags_read_write = S_IRUGO | S_IWUGO; const mode_t flags_read_only = S_IRUGO; const mode_t flags_write_only = S_IWUGO; struct dentry *file; ECM_IPA_LOG_ENTRY(); if (!ecm_ipa_ctx) return -EINVAL; ecm_ipa_ctx->directory = debugfs_create_dir("ecm_ipa", NULL); if (!ecm_ipa_ctx->directory) { ECM_IPA_ERROR("could not create debugfs directory entry\n"); goto fail_directory; } file = debugfs_create_bool("tx_enable", flags_read_write, ecm_ipa_ctx->directory, &ecm_ipa_ctx->tx_enable); if (!file) { ECM_IPA_ERROR("could not create debugfs tx file\n"); goto fail_file; } file = debugfs_create_bool("rx_enable", flags_read_write, ecm_ipa_ctx->directory, &ecm_ipa_ctx->rx_enable); if (!file) { ECM_IPA_ERROR("could not create debugfs rx file\n"); goto fail_file; } file = debugfs_create_bool("rm_enable", flags_read_write, ecm_ipa_ctx->directory, &ecm_ipa_ctx->rm_enable); if (!file) { ECM_IPA_ERROR("could not create debugfs rm file\n"); goto fail_file; } file = debugfs_create_u8("outstanding_high", flags_read_write, ecm_ipa_ctx->directory, &ecm_ipa_ctx->outstanding_high); if (!file) { ECM_IPA_ERROR("could not create outstanding_high file\n"); goto fail_file; } file = debugfs_create_u8("outstanding_low", flags_read_write, ecm_ipa_ctx->directory, &ecm_ipa_ctx->outstanding_low); if (!file) { ECM_IPA_ERROR("could not create outstanding_low file\n"); goto fail_file; } file = debugfs_create_file("dma_enable", flags_read_write, ecm_ipa_ctx->directory, ecm_ipa_ctx, &ecm_ipa_debugfs_dma_ops); if (!file) { ECM_IPA_ERROR("could not create debugfs dma file\n"); goto fail_file; } file = debugfs_create_file("outstanding", flags_read_only, ecm_ipa_ctx->directory, ecm_ipa_ctx, &ecm_ipa_debugfs_atomic_ops); if (!file) { ECM_IPA_ERROR("could not create outstanding file\n"); goto fail_file; } file = debugfs_create_file("stall_ipa_rx_proc", flags_write_only, ecm_ipa_ctx->directory, ecm_ipa_ctx, &ecm_ipa_debugfs_stall_ops); if (!file) { ECM_IPA_ERROR("could not create stall_ipa_rx_proc file\n"); goto fail_file; } ECM_IPA_LOG_EXIT(); return 0; fail_file: debugfs_remove_recursive(ecm_ipa_ctx->directory); fail_directory: return -EFAULT; } static void ecm_ipa_debugfs_destroy(struct ecm_ipa_dev *ecm_ipa_ctx) { debugfs_remove_recursive(ecm_ipa_ctx->directory); } /** * ecm_ipa_ep_cfg() - configure the USB endpoints for ECM * *usb_to_ipa_hdl: handle received from ipa_connect *ipa_to_usb_hdl: handle received from ipa_connect * * USB to IPA pipe: * - No de-aggregation * - Remove Ethernet header * - SRC NAT * - Default routing(0) * IPA to USB Pipe: * - No aggregation * - Add Ethernet header */ static int ecm_ipa_ep_registers_cfg(u32 usb_to_ipa_hdl, u32 ipa_to_usb_hdl) { int result = 0; struct ipa_ep_cfg usb_to_ipa_ep_cfg; struct ipa_ep_cfg ipa_to_usb_ep_cfg; ECM_IPA_LOG_ENTRY(); memset(&usb_to_ipa_ep_cfg, 0 , sizeof(struct ipa_ep_cfg)); usb_to_ipa_ep_cfg.aggr.aggr_en = IPA_BYPASS_AGGR; usb_to_ipa_ep_cfg.hdr.hdr_len = ETH_HLEN; usb_to_ipa_ep_cfg.nat.nat_en = IPA_SRC_NAT; usb_to_ipa_ep_cfg.route.rt_tbl_hdl = 0; usb_to_ipa_ep_cfg.mode.dst = IPA_CLIENT_A5_LAN_WAN_CONS; usb_to_ipa_ep_cfg.mode.mode = IPA_BASIC; result = ipa_cfg_ep(usb_to_ipa_hdl, &usb_to_ipa_ep_cfg); if (result) { ECM_IPA_ERROR("failed to configure USB to IPA point\n"); goto out; } memset(&ipa_to_usb_ep_cfg, 0 , sizeof(struct ipa_ep_cfg)); ipa_to_usb_ep_cfg.aggr.aggr_en = IPA_BYPASS_AGGR; ipa_to_usb_ep_cfg.hdr.hdr_len = ETH_HLEN; ipa_to_usb_ep_cfg.nat.nat_en = IPA_BYPASS_NAT; result = ipa_cfg_ep(ipa_to_usb_hdl, &ipa_to_usb_ep_cfg); if (result) { ECM_IPA_ERROR("failed to configure IPA to USB end-point\n"); goto out; } ECM_IPA_DEBUG("end-point registers successfully configured\n"); out: ECM_IPA_LOG_EXIT(); return result; } /** * ecm_ipa_ep_registers_dma_cfg() - configure the USB endpoints for ECM * DMA * @usb_to_ipa_hdl: handle received from ipa_connect * * This function will override the previous configuration * which is needed for cores that does not support blocks logic * Note that client handles are the actual pipe index */ static int ecm_ipa_ep_registers_dma_cfg(u32 usb_to_ipa_hdl, enum ipa_client_type prod_client) { int result = 0; struct ipa_ep_cfg_mode cfg_mode; u32 apps_to_ipa_hdl = 2; ECM_IPA_LOG_ENTRY(); memset(&cfg_mode, 0 , sizeof(cfg_mode)); cfg_mode.mode = IPA_DMA; cfg_mode.dst = prod_client; result = ipa_cfg_ep_mode(apps_to_ipa_hdl, &cfg_mode); if (result) { ECM_IPA_ERROR("failed to configure Apps to IPA\n"); goto out; } memset(&cfg_mode, 0 , sizeof(cfg_mode)); cfg_mode.mode = IPA_DMA; cfg_mode.dst = IPA_CLIENT_A5_LAN_WAN_CONS; result = ipa_cfg_ep_mode(usb_to_ipa_hdl, &cfg_mode); if (result) { ECM_IPA_ERROR("failed to configure USB to IPA\n"); goto out; } ECM_IPA_DEBUG("end-point registers successfully configured\n"); out: ECM_IPA_LOG_EXIT(); return result; } /** * ecm_ipa_set_device_ethernet_addr() - set device etherenet address * @dev_ethaddr: device etherenet address * * Returns 0 for success, negative otherwise */ static int ecm_ipa_set_device_ethernet_addr(u8 *dev_ethaddr, u8 device_ethaddr[]) { if (!is_valid_ether_addr(device_ethaddr)) return -EINVAL; memcpy(dev_ethaddr, device_ethaddr, ETH_ALEN); ECM_IPA_DEBUG("device ethernet address: %pM\n", dev_ethaddr); return 0; } /** ecm_ipa_next_state - return the next state of the driver * @current_state: the current state of the driver * @operation: an enum which represent the operation being made on the driver * by its API. * * This function implements the driver internal state machine. * Its decisions are based on the driver current state and the operation * being made. * In case the operation is invalid this state machine will return * the value ECM_IPA_INVALID to inform the caller for a forbidden sequence. */ static enum ecm_ipa_state ecm_ipa_next_state(enum ecm_ipa_state current_state, enum ecm_ipa_operation operation) { int next_state = ECM_IPA_INVALID; switch (current_state) { case ECM_IPA_UNLOADED: if (operation == ECM_IPA_INITIALIZE) next_state = ECM_IPA_INITIALIZED; break; case ECM_IPA_INITIALIZED: if (operation == ECM_IPA_CONNECT) next_state = ECM_IPA_CONNECTED; else if (operation == ECM_IPA_OPEN) next_state = ECM_IPA_UP; else if (operation == ECM_IPA_CLEANUP) next_state = ECM_IPA_UNLOADED; break; case ECM_IPA_CONNECTED: if (operation == ECM_IPA_DISCONNECT) next_state = ECM_IPA_INITIALIZED; else if (operation == ECM_IPA_OPEN) next_state = ECM_IPA_CONNECTED_AND_UP; break; case ECM_IPA_UP: if (operation == ECM_IPA_STOP) next_state = ECM_IPA_INITIALIZED; else if (operation == ECM_IPA_CONNECT) next_state = ECM_IPA_CONNECTED_AND_UP; else if (operation == ECM_IPA_CLEANUP) next_state = ECM_IPA_UNLOADED; break; case ECM_IPA_CONNECTED_AND_UP: if (operation == ECM_IPA_STOP) next_state = ECM_IPA_CONNECTED; else if (operation == ECM_IPA_DISCONNECT) next_state = ECM_IPA_UP; break; default: ECM_IPA_ERROR("State is not supported\n"); break; } ECM_IPA_DEBUG("state transition ( %s -> %s )- %s\n", ecm_ipa_state_string(current_state), ecm_ipa_state_string(next_state) , next_state == ECM_IPA_INVALID ? "Forbidden" : "Allowed"); return next_state; } /** * ecm_ipa_state_string - return the state string representation * @state: enum which describe the state */ static const char *ecm_ipa_state_string(enum ecm_ipa_state state) { switch (state) { case ECM_IPA_UNLOADED: return "ECM_IPA_UNLOADED"; case ECM_IPA_INITIALIZED: return "ECM_IPA_INITIALIZED"; case ECM_IPA_CONNECTED: return "ECM_IPA_CONNECTED"; case ECM_IPA_UP: return "ECM_IPA_UP"; case ECM_IPA_CONNECTED_AND_UP: return "ECM_IPA_CONNECTED_AND_UP"; default: return "Not supported"; } } /** * ecm_ipa_init_module() - module initialization * */ static int ecm_ipa_init_module(void) { ECM_IPA_LOG_ENTRY(); ECM_IPA_LOG_EXIT(); return 0; } /** * ecm_ipa_cleanup_module() - module cleanup * */ static void ecm_ipa_cleanup_module(void) { ECM_IPA_LOG_ENTRY(); ECM_IPA_LOG_EXIT(); return; } MODULE_LICENSE("GPL v2"); MODULE_DESCRIPTION("ECM IPA network interface"); late_initcall(ecm_ipa_init_module); module_exit(ecm_ipa_cleanup_module);
gpl-2.0
inyourface09/android_kernel_lge_fx3
arch/arm/mach-msm/board-8930-display.c
13
20754
/* Copyright (c) 2011-2012, Code Aurora Forum. All rights reserved. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 and * only version 2 as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * */ #include <linux/init.h> #include <linux/ioport.h> #include <linux/platform_device.h> #include <linux/bootmem.h> #include <linux/gpio.h> #include <asm/mach-types.h> #include <mach/msm_bus_board.h> #include <mach/msm_memtypes.h> #include <mach/board.h> #include <mach/gpiomux.h> #include <mach/socinfo.h> #include <linux/ion.h> #include <mach/ion.h> #include "devices.h" #include "board-8930.h" #ifdef CONFIG_FB_MSM_TRIPLE_BUFFER #define MSM_FB_PRIM_BUF_SIZE \ (roundup((1920 * 1088 * 4), 4096) * 3) /* 4 bpp x 3 pages */ #else #define MSM_FB_PRIM_BUF_SIZE \ (roundup((1920 * 1088 * 4), 4096) * 2) /* 4 bpp x 2 pages */ #endif /* Note: must be multiple of 4096 */ #define MSM_FB_SIZE roundup(MSM_FB_PRIM_BUF_SIZE, 4096) #ifdef CONFIG_FB_MSM_OVERLAY0_WRITEBACK #define MSM_FB_OVERLAY0_WRITEBACK_SIZE roundup((1376 * 768 * 3 * 2), 4096) #else #define MSM_FB_OVERLAY0_WRITEBACK_SIZE (0) #endif /* CONFIG_FB_MSM_OVERLAY0_WRITEBACK */ #ifdef CONFIG_FB_MSM_OVERLAY1_WRITEBACK #define MSM_FB_OVERLAY1_WRITEBACK_SIZE roundup((1920 * 1088 * 3 * 2), 4096) #else #define MSM_FB_OVERLAY1_WRITEBACK_SIZE (0) #endif /* CONFIG_FB_MSM_OVERLAY1_WRITEBACK */ #define MDP_VSYNC_GPIO 0 #define MIPI_CMD_NOVATEK_QHD_PANEL_NAME "mipi_cmd_novatek_qhd" #define MIPI_VIDEO_NOVATEK_QHD_PANEL_NAME "mipi_video_novatek_qhd" #define MIPI_VIDEO_TOSHIBA_WSVGA_PANEL_NAME "mipi_video_toshiba_wsvga" #define MIPI_VIDEO_CHIMEI_WXGA_PANEL_NAME "mipi_video_chimei_wxga" #define MIPI_VIDEO_SIMULATOR_VGA_PANEL_NAME "mipi_video_simulator_vga" #define MIPI_CMD_RENESAS_FWVGA_PANEL_NAME "mipi_cmd_renesas_fwvga" #define HDMI_PANEL_NAME "hdmi_msm" #define MHL_PANEL_NAME "hdmi_msm,mhl_8334" #define TVOUT_PANEL_NAME "tvout_msm" static unsigned char mhl_display_enabled; unsigned char msm8930_mhl_display_enabled(void) { return mhl_display_enabled; } static struct resource msm_fb_resources[] = { { .flags = IORESOURCE_DMA, } }; static int msm_fb_detect_panel(const char *name) { if (!strncmp(name, MIPI_CMD_NOVATEK_QHD_PANEL_NAME, strnlen(MIPI_CMD_NOVATEK_QHD_PANEL_NAME, PANEL_NAME_MAX_LEN))) return 0; #if !defined(CONFIG_FB_MSM_LVDS_MIPI_PANEL_DETECT) && \ !defined(CONFIG_FB_MSM_MIPI_PANEL_DETECT) if (!strncmp(name, MIPI_VIDEO_NOVATEK_QHD_PANEL_NAME, strnlen(MIPI_VIDEO_NOVATEK_QHD_PANEL_NAME, PANEL_NAME_MAX_LEN))) return 0; if (!strncmp(name, MIPI_VIDEO_TOSHIBA_WSVGA_PANEL_NAME, strnlen(MIPI_VIDEO_TOSHIBA_WSVGA_PANEL_NAME, PANEL_NAME_MAX_LEN))) return 0; if (!strncmp(name, MIPI_VIDEO_SIMULATOR_VGA_PANEL_NAME, strnlen(MIPI_VIDEO_SIMULATOR_VGA_PANEL_NAME, PANEL_NAME_MAX_LEN))) return 0; if (!strncmp(name, MIPI_CMD_RENESAS_FWVGA_PANEL_NAME, strnlen(MIPI_CMD_RENESAS_FWVGA_PANEL_NAME, PANEL_NAME_MAX_LEN))) return 0; #endif if (!strncmp(name, HDMI_PANEL_NAME, strnlen(HDMI_PANEL_NAME, PANEL_NAME_MAX_LEN))) return 0; if (!strncmp(name, TVOUT_PANEL_NAME, strnlen(TVOUT_PANEL_NAME, PANEL_NAME_MAX_LEN))) return 0; pr_warning("%s: not supported '%s'", __func__, name); return -ENODEV; } static struct msm_fb_platform_data msm_fb_pdata = { .detect_client = msm_fb_detect_panel, }; static struct platform_device msm_fb_device = { .name = "msm_fb", .id = 0, .num_resources = ARRAY_SIZE(msm_fb_resources), .resource = msm_fb_resources, .dev.platform_data = &msm_fb_pdata, }; static bool dsi_power_on; static struct mipi_dsi_panel_platform_data novatek_pdata; static void pm8917_gpio_set_backlight(int bl_level) { int gpio24 = PM8917_GPIO_PM_TO_SYS(24); if (bl_level > 0) gpio_set_value_cansleep(gpio24, 1); else gpio_set_value_cansleep(gpio24, 0); } /* * TODO: When physical 8930/PM8038 hardware becomes * available, replace mipi_dsi_cdp_panel_power with * appropriate function. */ #define DISP_RST_GPIO 58 #define DISP_3D_2D_MODE 1 static int mipi_dsi_cdp_panel_power(int on) { static struct regulator *reg_l8, *reg_l23, *reg_l2; /* Control backlight GPIO (24) directly when using PM8917 */ int gpio24 = PM8917_GPIO_PM_TO_SYS(24); int rc; pr_debug("%s: state : %d\n", __func__, on); if (!dsi_power_on) { reg_l8 = regulator_get(&msm_mipi_dsi1_device.dev, "dsi_vdc"); if (IS_ERR(reg_l8)) { pr_err("could not get 8038_l8, rc = %ld\n", PTR_ERR(reg_l8)); return -ENODEV; } reg_l23 = regulator_get(&msm_mipi_dsi1_device.dev, "dsi_vddio"); if (IS_ERR(reg_l23)) { pr_err("could not get 8038_l23, rc = %ld\n", PTR_ERR(reg_l23)); return -ENODEV; } reg_l2 = regulator_get(&msm_mipi_dsi1_device.dev, "dsi_vdda"); if (IS_ERR(reg_l2)) { pr_err("could not get 8038_l2, rc = %ld\n", PTR_ERR(reg_l2)); return -ENODEV; } rc = regulator_set_voltage(reg_l8, 2800000, 3000000); if (rc) { pr_err("set_voltage l8 failed, rc=%d\n", rc); return -EINVAL; } rc = regulator_set_voltage(reg_l23, 1800000, 1800000); if (rc) { pr_err("set_voltage l23 failed, rc=%d\n", rc); return -EINVAL; } rc = regulator_set_voltage(reg_l2, 1200000, 1200000); if (rc) { pr_err("set_voltage l2 failed, rc=%d\n", rc); return -EINVAL; } rc = gpio_request(DISP_RST_GPIO, "disp_rst_n"); if (rc) { pr_err("request gpio DISP_RST_GPIO failed, rc=%d\n", rc); gpio_free(DISP_RST_GPIO); return -ENODEV; } rc = gpio_request(DISP_3D_2D_MODE, "disp_3d_2d"); if (rc) { pr_err("request gpio DISP_3D_2D_MODE failed, rc=%d\n", rc); gpio_free(DISP_3D_2D_MODE); return -ENODEV; } rc = gpio_direction_output(DISP_3D_2D_MODE, 0); if (rc) { pr_err("gpio_direction_output failed for %d gpio rc=%d\n", DISP_3D_2D_MODE, rc); return -ENODEV; } if (socinfo_get_pmic_model() == PMIC_MODEL_PM8917) { rc = gpio_request(gpio24, "disp_bl"); if (rc) { pr_err("request for gpio 24 failed, rc=%d\n", rc); return -ENODEV; } gpio_set_value_cansleep(gpio24, 0); novatek_pdata.gpio_set_backlight = pm8917_gpio_set_backlight; } dsi_power_on = true; } if (on) { rc = regulator_set_optimum_mode(reg_l8, 100000); if (rc < 0) { pr_err("set_optimum_mode l8 failed, rc=%d\n", rc); return -EINVAL; } rc = regulator_set_optimum_mode(reg_l23, 100000); if (rc < 0) { pr_err("set_optimum_mode l23 failed, rc=%d\n", rc); return -EINVAL; } rc = regulator_set_optimum_mode(reg_l2, 100000); if (rc < 0) { pr_err("set_optimum_mode l2 failed, rc=%d\n", rc); return -EINVAL; } rc = regulator_enable(reg_l8); if (rc) { pr_err("enable l8 failed, rc=%d\n", rc); return -ENODEV; } rc = regulator_enable(reg_l23); if (rc) { pr_err("enable l8 failed, rc=%d\n", rc); return -ENODEV; } rc = regulator_enable(reg_l2); if (rc) { pr_err("enable l2 failed, rc=%d\n", rc); return -ENODEV; } usleep(10000); gpio_set_value(DISP_RST_GPIO, 1); usleep(10); gpio_set_value(DISP_RST_GPIO, 0); usleep(20); gpio_set_value(DISP_RST_GPIO, 1); gpio_set_value(DISP_3D_2D_MODE, 1); usleep(20); } else { gpio_set_value(DISP_RST_GPIO, 0); rc = regulator_disable(reg_l2); if (rc) { pr_err("disable reg_l2 failed, rc=%d\n", rc); return -ENODEV; } rc = regulator_disable(reg_l8); if (rc) { pr_err("disable reg_l8 failed, rc=%d\n", rc); return -ENODEV; } rc = regulator_disable(reg_l23); if (rc) { pr_err("disable reg_l23 failed, rc=%d\n", rc); return -ENODEV; } rc = regulator_set_optimum_mode(reg_l8, 100); if (rc < 0) { pr_err("set_optimum_mode l8 failed, rc=%d\n", rc); return -EINVAL; } rc = regulator_set_optimum_mode(reg_l23, 100); if (rc < 0) { pr_err("set_optimum_mode l23 failed, rc=%d\n", rc); return -EINVAL; } rc = regulator_set_optimum_mode(reg_l2, 100); if (rc < 0) { pr_err("set_optimum_mode l2 failed, rc=%d\n", rc); return -EINVAL; } gpio_set_value(DISP_3D_2D_MODE, 0); usleep(20); } return 0; } static int mipi_dsi_panel_power(int on) { pr_debug("%s: on=%d\n", __func__, on); return mipi_dsi_cdp_panel_power(on); } static struct mipi_dsi_platform_data mipi_dsi_pdata = { .vsync_gpio = MDP_VSYNC_GPIO, .dsi_power_save = mipi_dsi_panel_power, }; #ifdef CONFIG_MSM_BUS_SCALING static struct msm_bus_vectors mdp_init_vectors[] = { { .src = MSM_BUS_MASTER_MDP_PORT0, .dst = MSM_BUS_SLAVE_EBI_CH0, .ab = 0, .ib = 0, }, }; #ifdef CONFIG_FB_MSM_HDMI_AS_PRIMARY static struct msm_bus_vectors hdmi_as_primary_vectors[] = { /* If HDMI is used as primary */ { .src = MSM_BUS_MASTER_MDP_PORT0, .dst = MSM_BUS_SLAVE_EBI_CH0, .ab = 2000000000, .ib = 2000000000, }, }; static struct msm_bus_paths mdp_bus_scale_usecases[] = { { ARRAY_SIZE(mdp_init_vectors), mdp_init_vectors, }, { ARRAY_SIZE(hdmi_as_primary_vectors), hdmi_as_primary_vectors, }, { ARRAY_SIZE(hdmi_as_primary_vectors), hdmi_as_primary_vectors, }, { ARRAY_SIZE(hdmi_as_primary_vectors), hdmi_as_primary_vectors, }, { ARRAY_SIZE(hdmi_as_primary_vectors), hdmi_as_primary_vectors, }, { ARRAY_SIZE(hdmi_as_primary_vectors), hdmi_as_primary_vectors, }, }; #else static struct msm_bus_vectors mdp_ui_vectors[] = { { .src = MSM_BUS_MASTER_MDP_PORT0, .dst = MSM_BUS_SLAVE_EBI_CH0, .ab = 216000000 * 2, .ib = 270000000 * 2, }, }; static struct msm_bus_vectors mdp_vga_vectors[] = { /* VGA and less video */ { .src = MSM_BUS_MASTER_MDP_PORT0, .dst = MSM_BUS_SLAVE_EBI_CH0, .ab = 216000000 * 2, .ib = 270000000 * 2, }, }; static struct msm_bus_vectors mdp_720p_vectors[] = { /* 720p and less video */ { .src = MSM_BUS_MASTER_MDP_PORT0, .dst = MSM_BUS_SLAVE_EBI_CH0, .ab = 230400000 * 2, .ib = 288000000 * 2, }, }; static struct msm_bus_vectors mdp_1080p_vectors[] = { /* 1080p and less video */ { .src = MSM_BUS_MASTER_MDP_PORT0, .dst = MSM_BUS_SLAVE_EBI_CH0, .ab = 334080000 * 2, .ib = 417600000 * 2, }, }; static struct msm_bus_paths mdp_bus_scale_usecases[] = { { ARRAY_SIZE(mdp_init_vectors), mdp_init_vectors, }, { ARRAY_SIZE(mdp_ui_vectors), mdp_ui_vectors, }, { ARRAY_SIZE(mdp_ui_vectors), mdp_ui_vectors, }, { ARRAY_SIZE(mdp_vga_vectors), mdp_vga_vectors, }, { ARRAY_SIZE(mdp_720p_vectors), mdp_720p_vectors, }, { ARRAY_SIZE(mdp_1080p_vectors), mdp_1080p_vectors, }, }; #endif static struct msm_bus_scale_pdata mdp_bus_scale_pdata = { mdp_bus_scale_usecases, ARRAY_SIZE(mdp_bus_scale_usecases), .name = "mdp", }; #endif static struct msm_panel_common_pdata mdp_pdata = { .gpio = MDP_VSYNC_GPIO, .mdp_max_clk = 200000000, #ifdef CONFIG_MSM_BUS_SCALING .mdp_bus_scale_table = &mdp_bus_scale_pdata, #endif .mdp_rev = MDP_REV_43, #ifdef CONFIG_MSM_MULTIMEDIA_USE_ION .mem_hid = BIT(ION_CP_MM_HEAP_ID), #else .mem_hid = MEMTYPE_EBI1, #endif .mdp_iommu_split_domain = 0, }; void __init msm8930_mdp_writeback(struct memtype_reserve* reserve_table) { mdp_pdata.ov0_wb_size = MSM_FB_OVERLAY0_WRITEBACK_SIZE; mdp_pdata.ov1_wb_size = MSM_FB_OVERLAY1_WRITEBACK_SIZE; #if defined(CONFIG_ANDROID_PMEM) && !defined(CONFIG_MSM_MULTIMEDIA_USE_ION) reserve_table[mdp_pdata.mem_hid].size += mdp_pdata.ov0_wb_size; reserve_table[mdp_pdata.mem_hid].size += mdp_pdata.ov1_wb_size; #endif } #define LPM_CHANNEL0 0 static int toshiba_gpio[] = {LPM_CHANNEL0}; static struct mipi_dsi_panel_platform_data toshiba_pdata = { .gpio = toshiba_gpio, }; static struct platform_device mipi_dsi_toshiba_panel_device = { .name = "mipi_toshiba", .id = 0, .dev = { .platform_data = &toshiba_pdata, } }; #define FPGA_3D_GPIO_CONFIG_ADDR 0xB5 static struct mipi_dsi_phy_ctrl dsi_novatek_cmd_mode_phy_db = { /* DSI_BIT_CLK at 500MHz, 2 lane, RGB888 */ {0x09, 0x08, 0x05, 0x00, 0x20}, /* regulator */ /* timing */ {0xab, 0x8a, 0x18, 0x00, 0x92, 0x97, 0x1b, 0x8c, 0x0c, 0x03, 0x04, 0xa0}, {0x5f, 0x00, 0x00, 0x10}, /* phy ctrl */ {0xff, 0x00, 0x06, 0x00}, /* strength */ /* pll control */ {0x0, 0xe, 0x30, 0xda, 0x00, 0x10, 0x0f, 0x61, 0x40, 0x07, 0x03, 0x00, 0x1a, 0x00, 0x00, 0x02, 0x00, 0x20, 0x00, 0x02}, }; static struct mipi_dsi_panel_platform_data novatek_pdata = { .fpga_3d_config_addr = FPGA_3D_GPIO_CONFIG_ADDR, .fpga_ctrl_mode = FPGA_SPI_INTF, .phy_ctrl_settings = &dsi_novatek_cmd_mode_phy_db, .dlane_swap = 0x1, .enable_wled_bl_ctrl = 0x1, }; static struct platform_device mipi_dsi_novatek_panel_device = { .name = "mipi_novatek", .id = 0, .dev = { .platform_data = &novatek_pdata, } }; #ifdef CONFIG_FB_MSM_HDMI_MSM_PANEL static struct resource hdmi_msm_resources[] = { { .name = "hdmi_msm_qfprom_addr", .start = 0x00700000, .end = 0x007060FF, .flags = IORESOURCE_MEM, }, { .name = "hdmi_msm_hdmi_addr", .start = 0x04A00000, .end = 0x04A00FFF, .flags = IORESOURCE_MEM, }, { .name = "hdmi_msm_irq", .start = HDMI_IRQ, .end = HDMI_IRQ, .flags = IORESOURCE_IRQ, }, }; static int hdmi_enable_5v(int on); static int hdmi_core_power(int on, int show); static int hdmi_cec_power(int on); static int hdmi_gpio_config(int on); static int hdmi_panel_power(int on); static struct msm_hdmi_platform_data hdmi_msm_data = { .irq = HDMI_IRQ, .enable_5v = hdmi_enable_5v, .core_power = hdmi_core_power, .cec_power = hdmi_cec_power, .panel_power = hdmi_panel_power, .gpio_config = hdmi_gpio_config, }; static struct platform_device hdmi_msm_device = { .name = "hdmi_msm", .id = 0, .num_resources = ARRAY_SIZE(hdmi_msm_resources), .resource = hdmi_msm_resources, .dev.platform_data = &hdmi_msm_data, }; #endif /* CONFIG_FB_MSM_HDMI_MSM_PANEL */ #ifdef CONFIG_FB_MSM_WRITEBACK_MSM_PANEL static struct platform_device wfd_panel_device = { .name = "wfd_panel", .id = 0, .dev.platform_data = NULL, }; static struct platform_device wfd_device = { .name = "msm_wfd", .id = -1, }; #endif #ifdef CONFIG_MSM_BUS_SCALING static struct msm_bus_vectors dtv_bus_init_vectors[] = { { .src = MSM_BUS_MASTER_MDP_PORT0, .dst = MSM_BUS_SLAVE_EBI_CH0, .ab = 0, .ib = 0, }, }; #ifdef CONFIG_FB_MSM_HDMI_AS_PRIMARY static struct msm_bus_vectors dtv_bus_def_vectors[] = { { .src = MSM_BUS_MASTER_MDP_PORT0, .dst = MSM_BUS_SLAVE_EBI_CH0, .ab = 2000000000, .ib = 2000000000, }, }; #else static struct msm_bus_vectors dtv_bus_def_vectors[] = { { .src = MSM_BUS_MASTER_MDP_PORT0, .dst = MSM_BUS_SLAVE_EBI_CH0, .ab = 566092800 * 2, .ib = 707616000 * 2, }, }; #endif static struct msm_bus_paths dtv_bus_scale_usecases[] = { { ARRAY_SIZE(dtv_bus_init_vectors), dtv_bus_init_vectors, }, { ARRAY_SIZE(dtv_bus_def_vectors), dtv_bus_def_vectors, }, }; static struct msm_bus_scale_pdata dtv_bus_scale_pdata = { dtv_bus_scale_usecases, ARRAY_SIZE(dtv_bus_scale_usecases), .name = "dtv", }; static struct lcdc_platform_data dtv_pdata = { .bus_scale_table = &dtv_bus_scale_pdata, .lcdc_power_save = hdmi_panel_power, }; static int hdmi_panel_power(int on) { int rc; pr_debug("%s: HDMI Core: %s\n", __func__, (on ? "ON" : "OFF")); rc = hdmi_core_power(on, 1); if (rc) rc = hdmi_cec_power(on); pr_debug("%s: HDMI Core: %s Success\n", __func__, (on ? "ON" : "OFF")); return rc; } #endif #ifdef CONFIG_FB_MSM_HDMI_MSM_PANEL static int hdmi_enable_5v(int on) { static struct regulator *reg_ext_5v; /* HDMI_5V */ static int prev_on; int rc; if (on == prev_on) return 0; if (!reg_ext_5v) { reg_ext_5v = regulator_get(&hdmi_msm_device.dev, "hdmi_mvs"); if (IS_ERR(reg_ext_5v)) { pr_err("'%s' regulator not found, rc=%ld\n", "hdmi_mvs", IS_ERR(reg_ext_5v)); reg_ext_5v = NULL; return -ENODEV; } } if (on) { rc = regulator_enable(reg_ext_5v); if (rc) { pr_err("'%s' regulator enable failed, rc=%d\n", "reg_ext_5v", rc); return rc; } pr_debug("%s(on): success\n", __func__); } else { rc = regulator_disable(reg_ext_5v); if (rc) pr_warning("'%s' regulator disable failed, rc=%d\n", "reg_ext_5v", rc); pr_debug("%s(off): success\n", __func__); } prev_on = on; return 0; } static int hdmi_core_power(int on, int show) { /* Both HDMI "avdd" and "vcc" are powered by 8038_l23 regulator */ static struct regulator *reg_8038_l23; static int prev_on; int rc; if (on == prev_on) return 0; if (!reg_8038_l23) { reg_8038_l23 = regulator_get(&hdmi_msm_device.dev, "hdmi_avdd"); if (IS_ERR(reg_8038_l23)) { pr_err("could not get reg_8038_l23, rc = %ld\n", PTR_ERR(reg_8038_l23)); return -ENODEV; } rc = regulator_set_voltage(reg_8038_l23, 1800000, 1800000); if (rc) { pr_err("set_voltage failed for 8921_l23, rc=%d\n", rc); return -EINVAL; } } if (on) { rc = regulator_set_optimum_mode(reg_8038_l23, 100000); if (rc < 0) { pr_err("set_optimum_mode l23 failed, rc=%d\n", rc); return -EINVAL; } rc = regulator_enable(reg_8038_l23); if (rc) { pr_err("'%s' regulator enable failed, rc=%d\n", "hdmi_avdd", rc); return rc; } pr_debug("%s(on): success\n", __func__); } else { rc = regulator_disable(reg_8038_l23); if (rc) { pr_err("disable reg_8038_l23 failed, rc=%d\n", rc); return -ENODEV; } rc = regulator_set_optimum_mode(reg_8038_l23, 100); if (rc < 0) { pr_err("set_optimum_mode l23 failed, rc=%d\n", rc); return -EINVAL; } pr_debug("%s(off): success\n", __func__); } prev_on = on; return 0; } static int hdmi_gpio_config(int on) { int rc = 0; static int prev_on; if (on == prev_on) return 0; if (on) { rc = gpio_request(100, "HDMI_DDC_CLK"); if (rc) { pr_err("'%s'(%d) gpio_request failed, rc=%d\n", "HDMI_DDC_CLK", 100, rc); return rc; } rc = gpio_request(101, "HDMI_DDC_DATA"); if (rc) { pr_err("'%s'(%d) gpio_request failed, rc=%d\n", "HDMI_DDC_DATA", 101, rc); goto error1; } rc = gpio_request(102, "HDMI_HPD"); if (rc) { pr_err("'%s'(%d) gpio_request failed, rc=%d\n", "HDMI_HPD", 102, rc); goto error2; } pr_debug("%s(on): success\n", __func__); } else { gpio_free(100); gpio_free(101); gpio_free(102); pr_debug("%s(off): success\n", __func__); } prev_on = on; return 0; error2: gpio_free(101); error1: gpio_free(100); return rc; } static int hdmi_cec_power(int on) { static int prev_on; int rc; if (on == prev_on) return 0; if (on) { rc = gpio_request(99, "HDMI_CEC_VAR"); if (rc) { pr_err("'%s'(%d) gpio_request failed, rc=%d\n", "HDMI_CEC_VAR", 99, rc); goto error; } pr_debug("%s(on): success\n", __func__); } else { gpio_free(99); pr_debug("%s(off): success\n", __func__); } prev_on = on; return 0; error: return rc; } #endif /* CONFIG_FB_MSM_HDMI_MSM_PANEL */ void __init msm8930_init_fb(void) { platform_device_register(&msm_fb_device); #ifdef CONFIG_FB_MSM_WRITEBACK_MSM_PANEL platform_device_register(&wfd_panel_device); platform_device_register(&wfd_device); #endif platform_device_register(&mipi_dsi_novatek_panel_device); #ifdef CONFIG_FB_MSM_HDMI_MSM_PANEL platform_device_register(&hdmi_msm_device); #endif platform_device_register(&mipi_dsi_toshiba_panel_device); msm_fb_register_device("mdp", &mdp_pdata); msm_fb_register_device("mipi_dsi", &mipi_dsi_pdata); #ifdef CONFIG_MSM_BUS_SCALING msm_fb_register_device("dtv", &dtv_pdata); #endif } void __init msm8930_allocate_fb_region(void) { void *addr; unsigned long size; size = MSM_FB_SIZE; addr = alloc_bootmem_align(size, 0x1000); msm_fb_resources[0].start = __pa(addr); msm_fb_resources[0].end = msm_fb_resources[0].start + size - 1; pr_info("allocating %lu bytes at %p (%lx physical) for fb\n", size, addr, __pa(addr)); } void __init msm8930_set_display_params(char *prim_panel, char *ext_panel) { if (strnlen(prim_panel, PANEL_NAME_MAX_LEN)) { strlcpy(msm_fb_pdata.prim_panel_name, prim_panel, PANEL_NAME_MAX_LEN); pr_debug("msm_fb_pdata.prim_panel_name %s\n", msm_fb_pdata.prim_panel_name); } if (strnlen(ext_panel, PANEL_NAME_MAX_LEN)) { strlcpy(msm_fb_pdata.ext_panel_name, ext_panel, PANEL_NAME_MAX_LEN); pr_debug("msm_fb_pdata.ext_panel_name %s\n", msm_fb_pdata.ext_panel_name); if (!strncmp((char *)msm_fb_pdata.ext_panel_name, MHL_PANEL_NAME, strnlen(MHL_PANEL_NAME, PANEL_NAME_MAX_LEN))) { pr_debug("MHL is external display by boot parameter\n"); mhl_display_enabled = 1; } } hdmi_msm_data.is_mhl_enabled = mhl_display_enabled; }
gpl-2.0
xobs/novena-linux.aqs
arch/powerpc/platforms/pasemi/gpio_mdio.c
525
6982
/* * Copyright (C) 2006-2007 PA Semi, Inc * * Author: Olof Johansson, PA Semi * * Maintained by: Olof Johansson <olof@lixom.net> * * Based on drivers/net/fs_enet/mii-bitbang.c. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 as * published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include <linux/io.h> #include <linux/module.h> #include <linux/types.h> #include <linux/slab.h> #include <linux/sched.h> #include <linux/errno.h> #include <linux/ioport.h> #include <linux/interrupt.h> #include <linux/phy.h> #include <linux/of_address.h> #include <linux/of_mdio.h> #include <linux/of_platform.h> #define DELAY 1 static void __iomem *gpio_regs; struct gpio_priv { int mdc_pin; int mdio_pin; int mdio_irqs[PHY_MAX_ADDR]; }; #define MDC_PIN(bus) (((struct gpio_priv *)bus->priv)->mdc_pin) #define MDIO_PIN(bus) (((struct gpio_priv *)bus->priv)->mdio_pin) static inline void mdio_lo(struct mii_bus *bus) { out_le32(gpio_regs+0x10, 1 << MDIO_PIN(bus)); } static inline void mdio_hi(struct mii_bus *bus) { out_le32(gpio_regs, 1 << MDIO_PIN(bus)); } static inline void mdc_lo(struct mii_bus *bus) { out_le32(gpio_regs+0x10, 1 << MDC_PIN(bus)); } static inline void mdc_hi(struct mii_bus *bus) { out_le32(gpio_regs, 1 << MDC_PIN(bus)); } static inline void mdio_active(struct mii_bus *bus) { out_le32(gpio_regs+0x20, (1 << MDC_PIN(bus)) | (1 << MDIO_PIN(bus))); } static inline void mdio_tristate(struct mii_bus *bus) { out_le32(gpio_regs+0x30, (1 << MDIO_PIN(bus))); } static inline int mdio_read(struct mii_bus *bus) { return !!(in_le32(gpio_regs+0x40) & (1 << MDIO_PIN(bus))); } static void clock_out(struct mii_bus *bus, int bit) { if (bit) mdio_hi(bus); else mdio_lo(bus); udelay(DELAY); mdc_hi(bus); udelay(DELAY); mdc_lo(bus); } /* Utility to send the preamble, address, and register (common to read and write). */ static void bitbang_pre(struct mii_bus *bus, int read, u8 addr, u8 reg) { int i; /* CFE uses a really long preamble (40 bits). We'll do the same. */ mdio_active(bus); for (i = 0; i < 40; i++) { clock_out(bus, 1); } /* send the start bit (01) and the read opcode (10) or write (10) */ clock_out(bus, 0); clock_out(bus, 1); clock_out(bus, read); clock_out(bus, !read); /* send the PHY address */ for (i = 0; i < 5; i++) { clock_out(bus, (addr & 0x10) != 0); addr <<= 1; } /* send the register address */ for (i = 0; i < 5; i++) { clock_out(bus, (reg & 0x10) != 0); reg <<= 1; } } static int gpio_mdio_read(struct mii_bus *bus, int phy_id, int location) { u16 rdreg; int ret, i; u8 addr = phy_id & 0xff; u8 reg = location & 0xff; bitbang_pre(bus, 1, addr, reg); /* tri-state our MDIO I/O pin so we can read */ mdio_tristate(bus); udelay(DELAY); mdc_hi(bus); udelay(DELAY); mdc_lo(bus); /* read 16 bits of register data, MSB first */ rdreg = 0; for (i = 0; i < 16; i++) { mdc_lo(bus); udelay(DELAY); mdc_hi(bus); udelay(DELAY); mdc_lo(bus); udelay(DELAY); rdreg <<= 1; rdreg |= mdio_read(bus); } mdc_hi(bus); udelay(DELAY); mdc_lo(bus); udelay(DELAY); ret = rdreg; return ret; } static int gpio_mdio_write(struct mii_bus *bus, int phy_id, int location, u16 val) { int i; u8 addr = phy_id & 0xff; u8 reg = location & 0xff; u16 value = val & 0xffff; bitbang_pre(bus, 0, addr, reg); /* send the turnaround (10) */ mdc_lo(bus); mdio_hi(bus); udelay(DELAY); mdc_hi(bus); udelay(DELAY); mdc_lo(bus); mdio_lo(bus); udelay(DELAY); mdc_hi(bus); udelay(DELAY); /* write 16 bits of register data, MSB first */ for (i = 0; i < 16; i++) { mdc_lo(bus); if (value & 0x8000) mdio_hi(bus); else mdio_lo(bus); udelay(DELAY); mdc_hi(bus); udelay(DELAY); value <<= 1; } /* * Tri-state the MDIO line. */ mdio_tristate(bus); mdc_lo(bus); udelay(DELAY); mdc_hi(bus); udelay(DELAY); return 0; } static int gpio_mdio_reset(struct mii_bus *bus) { /*nothing here - dunno how to reset it*/ return 0; } static int gpio_mdio_probe(struct platform_device *ofdev) { struct device *dev = &ofdev->dev; struct device_node *np = ofdev->dev.of_node; struct mii_bus *new_bus; struct gpio_priv *priv; const unsigned int *prop; int err; err = -ENOMEM; priv = kzalloc(sizeof(struct gpio_priv), GFP_KERNEL); if (!priv) goto out; new_bus = mdiobus_alloc(); if (!new_bus) goto out_free_priv; new_bus->name = "pasemi gpio mdio bus"; new_bus->read = &gpio_mdio_read; new_bus->write = &gpio_mdio_write; new_bus->reset = &gpio_mdio_reset; prop = of_get_property(np, "reg", NULL); snprintf(new_bus->id, MII_BUS_ID_SIZE, "%x", *prop); new_bus->priv = priv; new_bus->irq = priv->mdio_irqs; prop = of_get_property(np, "mdc-pin", NULL); priv->mdc_pin = *prop; prop = of_get_property(np, "mdio-pin", NULL); priv->mdio_pin = *prop; new_bus->parent = dev; dev_set_drvdata(dev, new_bus); err = of_mdiobus_register(new_bus, np); if (err != 0) { printk(KERN_ERR "%s: Cannot register as MDIO bus, err %d\n", new_bus->name, err); goto out_free_irq; } return 0; out_free_irq: kfree(new_bus); out_free_priv: kfree(priv); out: return err; } static int gpio_mdio_remove(struct platform_device *dev) { struct mii_bus *bus = dev_get_drvdata(&dev->dev); mdiobus_unregister(bus); dev_set_drvdata(&dev->dev, NULL); kfree(bus->priv); bus->priv = NULL; mdiobus_free(bus); return 0; } static struct of_device_id gpio_mdio_match[] = { { .compatible = "gpio-mdio", }, {}, }; MODULE_DEVICE_TABLE(of, gpio_mdio_match); static struct platform_driver gpio_mdio_driver = { .probe = gpio_mdio_probe, .remove = gpio_mdio_remove, .driver = { .name = "gpio-mdio-bitbang", .owner = THIS_MODULE, .of_match_table = gpio_mdio_match, }, }; int gpio_mdio_init(void) { struct device_node *np; np = of_find_compatible_node(NULL, NULL, "1682m-gpio"); if (!np) np = of_find_compatible_node(NULL, NULL, "pasemi,pwrficient-gpio"); if (!np) return -ENODEV; gpio_regs = of_iomap(np, 0); of_node_put(np); if (!gpio_regs) return -ENODEV; return platform_driver_register(&gpio_mdio_driver); } module_init(gpio_mdio_init); void gpio_mdio_exit(void) { platform_driver_unregister(&gpio_mdio_driver); if (gpio_regs) iounmap(gpio_regs); } module_exit(gpio_mdio_exit); MODULE_LICENSE("GPL"); MODULE_AUTHOR("Olof Johansson <olof@lixom.net>"); MODULE_DESCRIPTION("Driver for MDIO over GPIO on PA Semi PWRficient-based boards");
gpl-2.0
JoeyJiao/huawei_kernel_2.6.32_9
arch/cris/arch-v32/mach-fs/arbiter.c
781
11549
/* * Memory arbiter functions. Allocates bandwidth through the * arbiter and sets up arbiter breakpoints. * * The algorithm first assigns slots to the clients that has specified * bandwidth (e.g. ethernet) and then the remaining slots are divided * on all the active clients. * * Copyright (c) 2004-2007 Axis Communications AB. */ #include <hwregs/reg_map.h> #include <hwregs/reg_rdwr.h> #include <hwregs/marb_defs.h> #include <arbiter.h> #include <hwregs/intr_vect.h> #include <linux/interrupt.h> #include <linux/signal.h> #include <linux/errno.h> #include <linux/spinlock.h> #include <asm/io.h> #include <asm/irq_regs.h> struct crisv32_watch_entry { unsigned long instance; watch_callback *cb; unsigned long start; unsigned long end; int used; }; #define NUMBER_OF_BP 4 #define NBR_OF_CLIENTS 14 #define NBR_OF_SLOTS 64 #define SDRAM_BANDWIDTH 100000000 /* Some kind of expected value */ #define INTMEM_BANDWIDTH 400000000 #define NBR_OF_REGIONS 2 static struct crisv32_watch_entry watches[NUMBER_OF_BP] = { {regi_marb_bp0}, {regi_marb_bp1}, {regi_marb_bp2}, {regi_marb_bp3} }; static u8 requested_slots[NBR_OF_REGIONS][NBR_OF_CLIENTS]; static u8 active_clients[NBR_OF_REGIONS][NBR_OF_CLIENTS]; static int max_bandwidth[NBR_OF_REGIONS] = { SDRAM_BANDWIDTH, INTMEM_BANDWIDTH }; DEFINE_SPINLOCK(arbiter_lock); static irqreturn_t crisv32_arbiter_irq(int irq, void *dev_id); /* * "I'm the arbiter, I know the score. * From square one I'll be watching all 64." * (memory arbiter slots, that is) * * Or in other words: * Program the memory arbiter slots for "region" according to what's * in requested_slots[] and active_clients[], while minimizing * latency. A caller may pass a non-zero positive amount for * "unused_slots", which must then be the unallocated, remaining * number of slots, free to hand out to any client. */ static void crisv32_arbiter_config(int region, int unused_slots) { int slot; int client; int interval = 0; /* * This vector corresponds to the hardware arbiter slots (see * the hardware documentation for semantics). We initialize * each slot with a suitable sentinel value outside the valid * range {0 .. NBR_OF_CLIENTS - 1} and replace them with * client indexes. Then it's fed to the hardware. */ s8 val[NBR_OF_SLOTS]; for (slot = 0; slot < NBR_OF_SLOTS; slot++) val[slot] = -1; for (client = 0; client < NBR_OF_CLIENTS; client++) { int pos; /* Allocate the requested non-zero number of slots, but * also give clients with zero-requests one slot each * while stocks last. We do the latter here, in client * order. This makes sure zero-request clients are the * first to get to any spare slots, else those slots * could, when bandwidth is allocated close to the limit, * all be allocated to low-index non-zero-request clients * in the default-fill loop below. Another positive but * secondary effect is a somewhat better spread of the * zero-bandwidth clients in the vector, avoiding some of * the latency that could otherwise be caused by the * partitioning of non-zero-bandwidth clients at low * indexes and zero-bandwidth clients at high * indexes. (Note that this spreading can only affect the * unallocated bandwidth.) All the above only matters for * memory-intensive situations, of course. */ if (!requested_slots[region][client]) { /* * Skip inactive clients. Also skip zero-slot * allocations in this pass when there are no known * free slots. */ if (!active_clients[region][client] || unused_slots <= 0) continue; unused_slots--; /* Only allocate one slot for this client. */ interval = NBR_OF_SLOTS; } else interval = NBR_OF_SLOTS / requested_slots[region][client]; pos = 0; while (pos < NBR_OF_SLOTS) { if (val[pos] >= 0) pos++; else { val[pos] = client; pos += interval; } } } client = 0; for (slot = 0; slot < NBR_OF_SLOTS; slot++) { /* * Allocate remaining slots in round-robin * client-number order for active clients. For this * pass, we ignore requested bandwidth and previous * allocations. */ if (val[slot] < 0) { int first = client; while (!active_clients[region][client]) { client = (client + 1) % NBR_OF_CLIENTS; if (client == first) break; } val[slot] = client; client = (client + 1) % NBR_OF_CLIENTS; } if (region == EXT_REGION) REG_WR_INT_VECT(marb, regi_marb, rw_ext_slots, slot, val[slot]); else if (region == INT_REGION) REG_WR_INT_VECT(marb, regi_marb, rw_int_slots, slot, val[slot]); } } extern char _stext, _etext; static void crisv32_arbiter_init(void) { static int initialized; if (initialized) return; initialized = 1; /* * CPU caches are always set to active, but with zero * bandwidth allocated. It should be ok to allocate zero * bandwidth for the caches, because DMA for other channels * will supposedly finish, once their programmed amount is * done, and then the caches will get access according to the * "fixed scheme" for unclaimed slots. Though, if for some * use-case somewhere, there's a maximum CPU latency for * e.g. some interrupt, we have to start allocating specific * bandwidth for the CPU caches too. */ active_clients[EXT_REGION][10] = active_clients[EXT_REGION][11] = 1; crisv32_arbiter_config(EXT_REGION, 0); crisv32_arbiter_config(INT_REGION, 0); if (request_irq(MEMARB_INTR_VECT, crisv32_arbiter_irq, IRQF_DISABLED, "arbiter", NULL)) printk(KERN_ERR "Couldn't allocate arbiter IRQ\n"); #ifndef CONFIG_ETRAX_KGDB /* Global watch for writes to kernel text segment. */ crisv32_arbiter_watch(virt_to_phys(&_stext), &_etext - &_stext, arbiter_all_clients, arbiter_all_write, NULL); #endif } /* Main entry for bandwidth allocation. */ int crisv32_arbiter_allocate_bandwidth(int client, int region, unsigned long bandwidth) { int i; int total_assigned = 0; int total_clients = 0; int req; crisv32_arbiter_init(); for (i = 0; i < NBR_OF_CLIENTS; i++) { total_assigned += requested_slots[region][i]; total_clients += active_clients[region][i]; } /* Avoid division by 0 for 0-bandwidth requests. */ req = bandwidth == 0 ? 0 : NBR_OF_SLOTS / (max_bandwidth[region] / bandwidth); /* * We make sure that there are enough slots only for non-zero * requests. Requesting 0 bandwidth *may* allocate slots, * though if all bandwidth is allocated, such a client won't * get any and will have to rely on getting memory access * according to the fixed scheme that's the default when one * of the slot-allocated clients doesn't claim their slot. */ if (total_assigned + req > NBR_OF_SLOTS) return -ENOMEM; active_clients[region][client] = 1; requested_slots[region][client] = req; crisv32_arbiter_config(region, NBR_OF_SLOTS - total_assigned); return 0; } /* * Main entry for bandwidth deallocation. * * Strictly speaking, for a somewhat constant set of clients where * each client gets a constant bandwidth and is just enabled or * disabled (somewhat dynamically), no action is necessary here to * avoid starvation for non-zero-allocation clients, as the allocated * slots will just be unused. However, handing out those unused slots * to active clients avoids needless latency if the "fixed scheme" * would give unclaimed slots to an eager low-index client. */ void crisv32_arbiter_deallocate_bandwidth(int client, int region) { int i; int total_assigned = 0; requested_slots[region][client] = 0; active_clients[region][client] = 0; for (i = 0; i < NBR_OF_CLIENTS; i++) total_assigned += requested_slots[region][i]; crisv32_arbiter_config(region, NBR_OF_SLOTS - total_assigned); } int crisv32_arbiter_watch(unsigned long start, unsigned long size, unsigned long clients, unsigned long accesses, watch_callback *cb) { int i; crisv32_arbiter_init(); if (start > 0x80000000) { printk(KERN_ERR "Arbiter: %lX doesn't look like a " "physical address", start); return -EFAULT; } spin_lock(&arbiter_lock); for (i = 0; i < NUMBER_OF_BP; i++) { if (!watches[i].used) { reg_marb_rw_intr_mask intr_mask = REG_RD(marb, regi_marb, rw_intr_mask); watches[i].used = 1; watches[i].start = start; watches[i].end = start + size; watches[i].cb = cb; REG_WR_INT(marb_bp, watches[i].instance, rw_first_addr, watches[i].start); REG_WR_INT(marb_bp, watches[i].instance, rw_last_addr, watches[i].end); REG_WR_INT(marb_bp, watches[i].instance, rw_op, accesses); REG_WR_INT(marb_bp, watches[i].instance, rw_clients, clients); if (i == 0) intr_mask.bp0 = regk_marb_yes; else if (i == 1) intr_mask.bp1 = regk_marb_yes; else if (i == 2) intr_mask.bp2 = regk_marb_yes; else if (i == 3) intr_mask.bp3 = regk_marb_yes; REG_WR(marb, regi_marb, rw_intr_mask, intr_mask); spin_unlock(&arbiter_lock); return i; } } spin_unlock(&arbiter_lock); return -ENOMEM; } int crisv32_arbiter_unwatch(int id) { reg_marb_rw_intr_mask intr_mask = REG_RD(marb, regi_marb, rw_intr_mask); crisv32_arbiter_init(); spin_lock(&arbiter_lock); if ((id < 0) || (id >= NUMBER_OF_BP) || (!watches[id].used)) { spin_unlock(&arbiter_lock); return -EINVAL; } memset(&watches[id], 0, sizeof(struct crisv32_watch_entry)); if (id == 0) intr_mask.bp0 = regk_marb_no; else if (id == 1) intr_mask.bp2 = regk_marb_no; else if (id == 2) intr_mask.bp2 = regk_marb_no; else if (id == 3) intr_mask.bp3 = regk_marb_no; REG_WR(marb, regi_marb, rw_intr_mask, intr_mask); spin_unlock(&arbiter_lock); return 0; } extern void show_registers(struct pt_regs *regs); static irqreturn_t crisv32_arbiter_irq(int irq, void *dev_id) { reg_marb_r_masked_intr masked_intr = REG_RD(marb, regi_marb, r_masked_intr); reg_marb_bp_r_brk_clients r_clients; reg_marb_bp_r_brk_addr r_addr; reg_marb_bp_r_brk_op r_op; reg_marb_bp_r_brk_first_client r_first; reg_marb_bp_r_brk_size r_size; reg_marb_bp_rw_ack ack = { 0 }; reg_marb_rw_ack_intr ack_intr = { .bp0 = 1, .bp1 = 1, .bp2 = 1, .bp3 = 1 }; struct crisv32_watch_entry *watch; if (masked_intr.bp0) { watch = &watches[0]; ack_intr.bp0 = regk_marb_yes; } else if (masked_intr.bp1) { watch = &watches[1]; ack_intr.bp1 = regk_marb_yes; } else if (masked_intr.bp2) { watch = &watches[2]; ack_intr.bp2 = regk_marb_yes; } else if (masked_intr.bp3) { watch = &watches[3]; ack_intr.bp3 = regk_marb_yes; } else { return IRQ_NONE; } /* Retrieve all useful information and print it. */ r_clients = REG_RD(marb_bp, watch->instance, r_brk_clients); r_addr = REG_RD(marb_bp, watch->instance, r_brk_addr); r_op = REG_RD(marb_bp, watch->instance, r_brk_op); r_first = REG_RD(marb_bp, watch->instance, r_brk_first_client); r_size = REG_RD(marb_bp, watch->instance, r_brk_size); printk(KERN_INFO "Arbiter IRQ\n"); printk(KERN_INFO "Clients %X addr %X op %X first %X size %X\n", REG_TYPE_CONV(int, reg_marb_bp_r_brk_clients, r_clients), REG_TYPE_CONV(int, reg_marb_bp_r_brk_addr, r_addr), REG_TYPE_CONV(int, reg_marb_bp_r_brk_op, r_op), REG_TYPE_CONV(int, reg_marb_bp_r_brk_first_client, r_first), REG_TYPE_CONV(int, reg_marb_bp_r_brk_size, r_size)); REG_WR(marb_bp, watch->instance, rw_ack, ack); REG_WR(marb, regi_marb, rw_ack_intr, ack_intr); printk(KERN_INFO "IRQ occured at %lX\n", get_irq_regs()->erp); if (watch->cb) watch->cb(); return IRQ_HANDLED; }
gpl-2.0
pro4tlzz/P9000-Kernel
fs/nfs/objlayout/objlayout.c
1549
18735
/* * pNFS Objects layout driver high level definitions * * Copyright (C) 2007 Panasas Inc. [year of first publication] * All rights reserved. * * Benny Halevy <bhalevy@panasas.com> * Boaz Harrosh <ooo@electrozaur.com> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 * See the file COPYING included with this distribution for more details. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. Neither the name of the Panasas company nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include <linux/kmod.h> #include <linux/moduleparam.h> #include <linux/ratelimit.h> #include <scsi/osd_initiator.h> #include "objlayout.h" #define NFSDBG_FACILITY NFSDBG_PNFS_LD /* * Create a objlayout layout structure for the given inode and return it. */ struct pnfs_layout_hdr * objlayout_alloc_layout_hdr(struct inode *inode, gfp_t gfp_flags) { struct objlayout *objlay; objlay = kzalloc(sizeof(struct objlayout), gfp_flags); if (!objlay) return NULL; spin_lock_init(&objlay->lock); INIT_LIST_HEAD(&objlay->err_list); dprintk("%s: Return %p\n", __func__, objlay); return &objlay->pnfs_layout; } /* * Free an objlayout layout structure */ void objlayout_free_layout_hdr(struct pnfs_layout_hdr *lo) { struct objlayout *objlay = OBJLAYOUT(lo); dprintk("%s: objlay %p\n", __func__, objlay); WARN_ON(!list_empty(&objlay->err_list)); kfree(objlay); } /* * Unmarshall layout and store it in pnfslay. */ struct pnfs_layout_segment * objlayout_alloc_lseg(struct pnfs_layout_hdr *pnfslay, struct nfs4_layoutget_res *lgr, gfp_t gfp_flags) { int status = -ENOMEM; struct xdr_stream stream; struct xdr_buf buf = { .pages = lgr->layoutp->pages, .page_len = lgr->layoutp->len, .buflen = lgr->layoutp->len, .len = lgr->layoutp->len, }; struct page *scratch; struct pnfs_layout_segment *lseg; dprintk("%s: Begin pnfslay %p\n", __func__, pnfslay); scratch = alloc_page(gfp_flags); if (!scratch) goto err_nofree; xdr_init_decode(&stream, &buf, NULL); xdr_set_scratch_buffer(&stream, page_address(scratch), PAGE_SIZE); status = objio_alloc_lseg(&lseg, pnfslay, &lgr->range, &stream, gfp_flags); if (unlikely(status)) { dprintk("%s: objio_alloc_lseg Return err %d\n", __func__, status); goto err; } __free_page(scratch); dprintk("%s: Return %p\n", __func__, lseg); return lseg; err: __free_page(scratch); err_nofree: dprintk("%s: Err Return=>%d\n", __func__, status); return ERR_PTR(status); } /* * Free a layout segement */ void objlayout_free_lseg(struct pnfs_layout_segment *lseg) { dprintk("%s: freeing layout segment %p\n", __func__, lseg); if (unlikely(!lseg)) return; objio_free_lseg(lseg); } /* * I/O Operations */ static inline u64 end_offset(u64 start, u64 len) { u64 end; end = start + len; return end >= start ? end : NFS4_MAX_UINT64; } static void _fix_verify_io_params(struct pnfs_layout_segment *lseg, struct page ***p_pages, unsigned *p_pgbase, u64 offset, unsigned long count) { u64 lseg_end_offset; BUG_ON(offset < lseg->pls_range.offset); lseg_end_offset = end_offset(lseg->pls_range.offset, lseg->pls_range.length); BUG_ON(offset >= lseg_end_offset); WARN_ON(offset + count > lseg_end_offset); if (*p_pgbase > PAGE_SIZE) { dprintk("%s: pgbase(0x%x) > PAGE_SIZE\n", __func__, *p_pgbase); *p_pages += *p_pgbase >> PAGE_SHIFT; *p_pgbase &= ~PAGE_MASK; } } /* * I/O done common code */ static void objlayout_iodone(struct objlayout_io_res *oir) { if (likely(oir->status >= 0)) { objio_free_result(oir); } else { struct objlayout *objlay = oir->objlay; spin_lock(&objlay->lock); objlay->delta_space_valid = OBJ_DSU_INVALID; list_add(&objlay->err_list, &oir->err_list); spin_unlock(&objlay->lock); } } /* * objlayout_io_set_result - Set an osd_error code on a specific osd comp. * * The @index component IO failed (error returned from target). Register * the error for later reporting at layout-return. */ void objlayout_io_set_result(struct objlayout_io_res *oir, unsigned index, struct pnfs_osd_objid *pooid, int osd_error, u64 offset, u64 length, bool is_write) { struct pnfs_osd_ioerr *ioerr = &oir->ioerrs[index]; BUG_ON(index >= oir->num_comps); if (osd_error) { ioerr->oer_component = *pooid; ioerr->oer_comp_offset = offset; ioerr->oer_comp_length = length; ioerr->oer_iswrite = is_write; ioerr->oer_errno = osd_error; dprintk("%s: err[%d]: errno=%d is_write=%d dev(%llx:%llx) " "par=0x%llx obj=0x%llx offset=0x%llx length=0x%llx\n", __func__, index, ioerr->oer_errno, ioerr->oer_iswrite, _DEVID_LO(&ioerr->oer_component.oid_device_id), _DEVID_HI(&ioerr->oer_component.oid_device_id), ioerr->oer_component.oid_partition_id, ioerr->oer_component.oid_object_id, ioerr->oer_comp_offset, ioerr->oer_comp_length); } else { /* User need not call if no error is reported */ ioerr->oer_errno = 0; } } /* Function scheduled on rpc workqueue to call ->nfs_readlist_complete(). * This is because the osd completion is called with ints-off from * the block layer */ static void _rpc_read_complete(struct work_struct *work) { struct rpc_task *task; struct nfs_pgio_header *hdr; dprintk("%s enter\n", __func__); task = container_of(work, struct rpc_task, u.tk_work); hdr = container_of(task, struct nfs_pgio_header, task); pnfs_ld_read_done(hdr); } void objlayout_read_done(struct objlayout_io_res *oir, ssize_t status, bool sync) { struct nfs_pgio_header *hdr = oir->rpcdata; oir->status = hdr->task.tk_status = status; if (status >= 0) hdr->res.count = status; else hdr->pnfs_error = status; objlayout_iodone(oir); /* must not use oir after this point */ dprintk("%s: Return status=%zd eof=%d sync=%d\n", __func__, status, hdr->res.eof, sync); if (sync) pnfs_ld_read_done(hdr); else { INIT_WORK(&hdr->task.u.tk_work, _rpc_read_complete); schedule_work(&hdr->task.u.tk_work); } } /* * Perform sync or async reads. */ enum pnfs_try_status objlayout_read_pagelist(struct nfs_pgio_header *hdr) { struct inode *inode = hdr->inode; loff_t offset = hdr->args.offset; size_t count = hdr->args.count; int err; loff_t eof; eof = i_size_read(inode); if (unlikely(offset + count > eof)) { if (offset >= eof) { err = 0; hdr->res.count = 0; hdr->res.eof = 1; /*FIXME: do we need to call pnfs_ld_read_done() */ goto out; } count = eof - offset; } hdr->res.eof = (offset + count) >= eof; _fix_verify_io_params(hdr->lseg, &hdr->args.pages, &hdr->args.pgbase, hdr->args.offset, hdr->args.count); dprintk("%s: inode(%lx) offset 0x%llx count 0x%Zx eof=%d\n", __func__, inode->i_ino, offset, count, hdr->res.eof); err = objio_read_pagelist(hdr); out: if (unlikely(err)) { hdr->pnfs_error = err; dprintk("%s: Returned Error %d\n", __func__, err); return PNFS_NOT_ATTEMPTED; } return PNFS_ATTEMPTED; } /* Function scheduled on rpc workqueue to call ->nfs_writelist_complete(). * This is because the osd completion is called with ints-off from * the block layer */ static void _rpc_write_complete(struct work_struct *work) { struct rpc_task *task; struct nfs_pgio_header *hdr; dprintk("%s enter\n", __func__); task = container_of(work, struct rpc_task, u.tk_work); hdr = container_of(task, struct nfs_pgio_header, task); pnfs_ld_write_done(hdr); } void objlayout_write_done(struct objlayout_io_res *oir, ssize_t status, bool sync) { struct nfs_pgio_header *hdr = oir->rpcdata; oir->status = hdr->task.tk_status = status; if (status >= 0) { hdr->res.count = status; hdr->verf.committed = oir->committed; } else { hdr->pnfs_error = status; } objlayout_iodone(oir); /* must not use oir after this point */ dprintk("%s: Return status %zd committed %d sync=%d\n", __func__, status, hdr->verf.committed, sync); if (sync) pnfs_ld_write_done(hdr); else { INIT_WORK(&hdr->task.u.tk_work, _rpc_write_complete); schedule_work(&hdr->task.u.tk_work); } } /* * Perform sync or async writes. */ enum pnfs_try_status objlayout_write_pagelist(struct nfs_pgio_header *hdr, int how) { int err; _fix_verify_io_params(hdr->lseg, &hdr->args.pages, &hdr->args.pgbase, hdr->args.offset, hdr->args.count); err = objio_write_pagelist(hdr, how); if (unlikely(err)) { hdr->pnfs_error = err; dprintk("%s: Returned Error %d\n", __func__, err); return PNFS_NOT_ATTEMPTED; } return PNFS_ATTEMPTED; } void objlayout_encode_layoutcommit(struct pnfs_layout_hdr *pnfslay, struct xdr_stream *xdr, const struct nfs4_layoutcommit_args *args) { struct objlayout *objlay = OBJLAYOUT(pnfslay); struct pnfs_osd_layoutupdate lou; __be32 *start; dprintk("%s: Begin\n", __func__); spin_lock(&objlay->lock); lou.dsu_valid = (objlay->delta_space_valid == OBJ_DSU_VALID); lou.dsu_delta = objlay->delta_space_used; objlay->delta_space_used = 0; objlay->delta_space_valid = OBJ_DSU_INIT; lou.olu_ioerr_flag = !list_empty(&objlay->err_list); spin_unlock(&objlay->lock); start = xdr_reserve_space(xdr, 4); BUG_ON(pnfs_osd_xdr_encode_layoutupdate(xdr, &lou)); *start = cpu_to_be32((xdr->p - start - 1) * 4); dprintk("%s: Return delta_space_used %lld err %d\n", __func__, lou.dsu_delta, lou.olu_ioerr_flag); } static int err_prio(u32 oer_errno) { switch (oer_errno) { case 0: return 0; case PNFS_OSD_ERR_RESOURCE: return OSD_ERR_PRI_RESOURCE; case PNFS_OSD_ERR_BAD_CRED: return OSD_ERR_PRI_BAD_CRED; case PNFS_OSD_ERR_NO_ACCESS: return OSD_ERR_PRI_NO_ACCESS; case PNFS_OSD_ERR_UNREACHABLE: return OSD_ERR_PRI_UNREACHABLE; case PNFS_OSD_ERR_NOT_FOUND: return OSD_ERR_PRI_NOT_FOUND; case PNFS_OSD_ERR_NO_SPACE: return OSD_ERR_PRI_NO_SPACE; default: WARN_ON(1); /* fallthrough */ case PNFS_OSD_ERR_EIO: return OSD_ERR_PRI_EIO; } } static void merge_ioerr(struct pnfs_osd_ioerr *dest_err, const struct pnfs_osd_ioerr *src_err) { u64 dest_end, src_end; if (!dest_err->oer_errno) { *dest_err = *src_err; /* accumulated device must be blank */ memset(&dest_err->oer_component.oid_device_id, 0, sizeof(dest_err->oer_component.oid_device_id)); return; } if (dest_err->oer_component.oid_partition_id != src_err->oer_component.oid_partition_id) dest_err->oer_component.oid_partition_id = 0; if (dest_err->oer_component.oid_object_id != src_err->oer_component.oid_object_id) dest_err->oer_component.oid_object_id = 0; if (dest_err->oer_comp_offset > src_err->oer_comp_offset) dest_err->oer_comp_offset = src_err->oer_comp_offset; dest_end = end_offset(dest_err->oer_comp_offset, dest_err->oer_comp_length); src_end = end_offset(src_err->oer_comp_offset, src_err->oer_comp_length); if (dest_end < src_end) dest_end = src_end; dest_err->oer_comp_length = dest_end - dest_err->oer_comp_offset; if ((src_err->oer_iswrite == dest_err->oer_iswrite) && (err_prio(src_err->oer_errno) > err_prio(dest_err->oer_errno))) { dest_err->oer_errno = src_err->oer_errno; } else if (src_err->oer_iswrite) { dest_err->oer_iswrite = true; dest_err->oer_errno = src_err->oer_errno; } } static void encode_accumulated_error(struct objlayout *objlay, __be32 *p) { struct objlayout_io_res *oir, *tmp; struct pnfs_osd_ioerr accumulated_err = {.oer_errno = 0}; list_for_each_entry_safe(oir, tmp, &objlay->err_list, err_list) { unsigned i; for (i = 0; i < oir->num_comps; i++) { struct pnfs_osd_ioerr *ioerr = &oir->ioerrs[i]; if (!ioerr->oer_errno) continue; printk(KERN_ERR "NFS: %s: err[%d]: errno=%d " "is_write=%d dev(%llx:%llx) par=0x%llx " "obj=0x%llx offset=0x%llx length=0x%llx\n", __func__, i, ioerr->oer_errno, ioerr->oer_iswrite, _DEVID_LO(&ioerr->oer_component.oid_device_id), _DEVID_HI(&ioerr->oer_component.oid_device_id), ioerr->oer_component.oid_partition_id, ioerr->oer_component.oid_object_id, ioerr->oer_comp_offset, ioerr->oer_comp_length); merge_ioerr(&accumulated_err, ioerr); } list_del(&oir->err_list); objio_free_result(oir); } pnfs_osd_xdr_encode_ioerr(p, &accumulated_err); } void objlayout_encode_layoutreturn(struct pnfs_layout_hdr *pnfslay, struct xdr_stream *xdr, const struct nfs4_layoutreturn_args *args) { struct objlayout *objlay = OBJLAYOUT(pnfslay); struct objlayout_io_res *oir, *tmp; __be32 *start; dprintk("%s: Begin\n", __func__); start = xdr_reserve_space(xdr, 4); BUG_ON(!start); spin_lock(&objlay->lock); list_for_each_entry_safe(oir, tmp, &objlay->err_list, err_list) { __be32 *last_xdr = NULL, *p; unsigned i; int res = 0; for (i = 0; i < oir->num_comps; i++) { struct pnfs_osd_ioerr *ioerr = &oir->ioerrs[i]; if (!ioerr->oer_errno) continue; dprintk("%s: err[%d]: errno=%d is_write=%d " "dev(%llx:%llx) par=0x%llx obj=0x%llx " "offset=0x%llx length=0x%llx\n", __func__, i, ioerr->oer_errno, ioerr->oer_iswrite, _DEVID_LO(&ioerr->oer_component.oid_device_id), _DEVID_HI(&ioerr->oer_component.oid_device_id), ioerr->oer_component.oid_partition_id, ioerr->oer_component.oid_object_id, ioerr->oer_comp_offset, ioerr->oer_comp_length); p = pnfs_osd_xdr_ioerr_reserve_space(xdr); if (unlikely(!p)) { res = -E2BIG; break; /* accumulated_error */ } last_xdr = p; pnfs_osd_xdr_encode_ioerr(p, &oir->ioerrs[i]); } /* TODO: use xdr_write_pages */ if (unlikely(res)) { /* no space for even one error descriptor */ BUG_ON(!last_xdr); /* we've encountered a situation with lots and lots of * errors and no space to encode them all. Use the last * available slot to report the union of all the * remaining errors. */ encode_accumulated_error(objlay, last_xdr); goto loop_done; } list_del(&oir->err_list); objio_free_result(oir); } loop_done: spin_unlock(&objlay->lock); *start = cpu_to_be32((xdr->p - start - 1) * 4); dprintk("%s: Return\n", __func__); } enum { OBJLAYOUT_MAX_URI_LEN = 256, OBJLAYOUT_MAX_OSDNAME_LEN = 64, OBJLAYOUT_MAX_SYSID_HEX_LEN = OSD_SYSTEMID_LEN * 2 + 1, OSD_LOGIN_UPCALL_PATHLEN = 256 }; static char osd_login_prog[OSD_LOGIN_UPCALL_PATHLEN] = "/sbin/osd_login"; module_param_string(osd_login_prog, osd_login_prog, sizeof(osd_login_prog), 0600); MODULE_PARM_DESC(osd_login_prog, "Path to the osd_login upcall program"); struct __auto_login { char uri[OBJLAYOUT_MAX_URI_LEN]; char osdname[OBJLAYOUT_MAX_OSDNAME_LEN]; char systemid_hex[OBJLAYOUT_MAX_SYSID_HEX_LEN]; }; static int __objlayout_upcall(struct __auto_login *login) { static char *envp[] = { "HOME=/", "TERM=linux", "PATH=/sbin:/usr/sbin:/bin:/usr/bin", NULL }; char *argv[8]; int ret; if (unlikely(!osd_login_prog[0])) { dprintk("%s: osd_login_prog is disabled\n", __func__); return -EACCES; } dprintk("%s uri: %s\n", __func__, login->uri); dprintk("%s osdname %s\n", __func__, login->osdname); dprintk("%s systemid_hex %s\n", __func__, login->systemid_hex); argv[0] = (char *)osd_login_prog; argv[1] = "-u"; argv[2] = login->uri; argv[3] = "-o"; argv[4] = login->osdname; argv[5] = "-s"; argv[6] = login->systemid_hex; argv[7] = NULL; ret = call_usermodehelper(argv[0], argv, envp, UMH_WAIT_PROC); /* * Disable the upcall mechanism if we're getting an ENOENT or * EACCES error. The admin can re-enable it on the fly by using * sysfs to set the objlayoutdriver.osd_login_prog module parameter once * the problem has been fixed. */ if (ret == -ENOENT || ret == -EACCES) { printk(KERN_ERR "PNFS-OBJ: %s was not found please set " "objlayoutdriver.osd_login_prog kernel parameter!\n", osd_login_prog); osd_login_prog[0] = '\0'; } dprintk("%s %s return value: %d\n", __func__, osd_login_prog, ret); return ret; } /* Assume dest is all zeros */ static void __copy_nfsS_and_zero_terminate(struct nfs4_string s, char *dest, int max_len, const char *var_name) { if (!s.len) return; if (s.len >= max_len) { pr_warn_ratelimited( "objlayout_autologin: %s: s.len(%d) >= max_len(%d)", var_name, s.len, max_len); s.len = max_len - 1; /* space for null terminator */ } memcpy(dest, s.data, s.len); } /* Assume sysid is all zeros */ static void _sysid_2_hex(struct nfs4_string s, char sysid[OBJLAYOUT_MAX_SYSID_HEX_LEN]) { int i; char *cur; if (!s.len) return; if (s.len != OSD_SYSTEMID_LEN) { pr_warn_ratelimited( "objlayout_autologin: systemid_len(%d) != OSD_SYSTEMID_LEN", s.len); if (s.len > OSD_SYSTEMID_LEN) s.len = OSD_SYSTEMID_LEN; } cur = sysid; for (i = 0; i < s.len; i++) cur = hex_byte_pack(cur, s.data[i]); } int objlayout_autologin(struct pnfs_osd_deviceaddr *deviceaddr) { int rc; struct __auto_login login; if (!deviceaddr->oda_targetaddr.ota_netaddr.r_addr.len) return -ENODEV; memset(&login, 0, sizeof(login)); __copy_nfsS_and_zero_terminate( deviceaddr->oda_targetaddr.ota_netaddr.r_addr, login.uri, sizeof(login.uri), "URI"); __copy_nfsS_and_zero_terminate( deviceaddr->oda_osdname, login.osdname, sizeof(login.osdname), "OSDNAME"); _sysid_2_hex(deviceaddr->oda_systemid, login.systemid_hex); rc = __objlayout_upcall(&login); if (rc > 0) /* script returns positive values */ rc = -ENODEV; return rc; }
gpl-2.0
CyanogenMod/android_kernel_huawei_msm8916
sound/usb/clock.c
2061
11908
/* * Clock domain and sample rate management functions * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ #include <linux/bitops.h> #include <linux/init.h> #include <linux/string.h> #include <linux/usb.h> #include <linux/usb/audio.h> #include <linux/usb/audio-v2.h> #include <sound/core.h> #include <sound/info.h> #include <sound/pcm.h> #include "usbaudio.h" #include "card.h" #include "helper.h" #include "clock.h" #include "quirks.h" static struct uac_clock_source_descriptor * snd_usb_find_clock_source(struct usb_host_interface *ctrl_iface, int clock_id) { struct uac_clock_source_descriptor *cs = NULL; while ((cs = snd_usb_find_csint_desc(ctrl_iface->extra, ctrl_iface->extralen, cs, UAC2_CLOCK_SOURCE))) { if (cs->bClockID == clock_id) return cs; } return NULL; } static struct uac_clock_selector_descriptor * snd_usb_find_clock_selector(struct usb_host_interface *ctrl_iface, int clock_id) { struct uac_clock_selector_descriptor *cs = NULL; while ((cs = snd_usb_find_csint_desc(ctrl_iface->extra, ctrl_iface->extralen, cs, UAC2_CLOCK_SELECTOR))) { if (cs->bClockID == clock_id) return cs; } return NULL; } static struct uac_clock_multiplier_descriptor * snd_usb_find_clock_multiplier(struct usb_host_interface *ctrl_iface, int clock_id) { struct uac_clock_multiplier_descriptor *cs = NULL; while ((cs = snd_usb_find_csint_desc(ctrl_iface->extra, ctrl_iface->extralen, cs, UAC2_CLOCK_MULTIPLIER))) { if (cs->bClockID == clock_id) return cs; } return NULL; } static int uac_clock_selector_get_val(struct snd_usb_audio *chip, int selector_id) { unsigned char buf; int ret; ret = snd_usb_ctl_msg(chip->dev, usb_rcvctrlpipe(chip->dev, 0), UAC2_CS_CUR, USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_IN, UAC2_CX_CLOCK_SELECTOR << 8, snd_usb_ctrl_intf(chip) | (selector_id << 8), &buf, sizeof(buf)); if (ret < 0) return ret; return buf; } static int uac_clock_selector_set_val(struct snd_usb_audio *chip, int selector_id, unsigned char pin) { int ret; ret = snd_usb_ctl_msg(chip->dev, usb_sndctrlpipe(chip->dev, 0), UAC2_CS_CUR, USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_OUT, UAC2_CX_CLOCK_SELECTOR << 8, snd_usb_ctrl_intf(chip) | (selector_id << 8), &pin, sizeof(pin)); if (ret < 0) return ret; if (ret != sizeof(pin)) { snd_printk(KERN_ERR "usb-audio:%d: setting selector (id %d) unexpected length %d\n", chip->dev->devnum, selector_id, ret); return -EINVAL; } ret = uac_clock_selector_get_val(chip, selector_id); if (ret < 0) return ret; if (ret != pin) { snd_printk(KERN_ERR "usb-audio:%d: setting selector (id %d) to %x failed (current: %d)\n", chip->dev->devnum, selector_id, pin, ret); return -EINVAL; } return ret; } static bool uac_clock_source_is_valid(struct snd_usb_audio *chip, int source_id) { int err; unsigned char data; struct usb_device *dev = chip->dev; struct uac_clock_source_descriptor *cs_desc = snd_usb_find_clock_source(chip->ctrl_intf, source_id); if (!cs_desc) return 0; /* If a clock source can't tell us whether it's valid, we assume it is */ if (!uac2_control_is_readable(cs_desc->bmControls, UAC2_CS_CONTROL_CLOCK_VALID - 1)) return 1; err = snd_usb_ctl_msg(dev, usb_rcvctrlpipe(dev, 0), UAC2_CS_CUR, USB_TYPE_CLASS | USB_RECIP_INTERFACE | USB_DIR_IN, UAC2_CS_CONTROL_CLOCK_VALID << 8, snd_usb_ctrl_intf(chip) | (source_id << 8), &data, sizeof(data)); if (err < 0) { snd_printk(KERN_WARNING "%s(): cannot get clock validity for id %d\n", __func__, source_id); return 0; } return !!data; } static int __uac_clock_find_source(struct snd_usb_audio *chip, int entity_id, unsigned long *visited, bool validate) { struct uac_clock_source_descriptor *source; struct uac_clock_selector_descriptor *selector; struct uac_clock_multiplier_descriptor *multiplier; entity_id &= 0xff; if (test_and_set_bit(entity_id, visited)) { snd_printk(KERN_WARNING "%s(): recursive clock topology detected, id %d.\n", __func__, entity_id); return -EINVAL; } /* first, see if the ID we're looking for is a clock source already */ source = snd_usb_find_clock_source(chip->ctrl_intf, entity_id); if (source) { entity_id = source->bClockID; if (validate && !uac_clock_source_is_valid(chip, entity_id)) { snd_printk(KERN_ERR "usb-audio:%d: clock source %d is not valid, cannot use\n", chip->dev->devnum, entity_id); return -ENXIO; } return entity_id; } selector = snd_usb_find_clock_selector(chip->ctrl_intf, entity_id); if (selector) { int ret, i, cur; /* the entity ID we are looking for is a selector. * find out what it currently selects */ ret = uac_clock_selector_get_val(chip, selector->bClockID); if (ret < 0) return ret; /* Selector values are one-based */ if (ret > selector->bNrInPins || ret < 1) { snd_printk(KERN_ERR "%s(): selector reported illegal value, id %d, ret %d\n", __func__, selector->bClockID, ret); return -EINVAL; } cur = ret; ret = __uac_clock_find_source(chip, selector->baCSourceID[ret - 1], visited, validate); if (!validate || ret > 0 || !chip->autoclock) return ret; /* The current clock source is invalid, try others. */ for (i = 1; i <= selector->bNrInPins; i++) { int err; if (i == cur) continue; ret = __uac_clock_find_source(chip, selector->baCSourceID[i - 1], visited, true); if (ret < 0) continue; err = uac_clock_selector_set_val(chip, entity_id, i); if (err < 0) continue; snd_printk(KERN_INFO "usb-audio:%d: found and selected valid clock source %d\n", chip->dev->devnum, ret); return ret; } return -ENXIO; } /* FIXME: multipliers only act as pass-thru element for now */ multiplier = snd_usb_find_clock_multiplier(chip->ctrl_intf, entity_id); if (multiplier) return __uac_clock_find_source(chip, multiplier->bCSourceID, visited, validate); return -EINVAL; } /* * For all kinds of sample rate settings and other device queries, * the clock source (end-leaf) must be used. However, clock selectors, * clock multipliers and sample rate converters may be specified as * clock source input to terminal. This functions walks the clock path * to its end and tries to find the source. * * The 'visited' bitfield is used internally to detect recursive loops. * * Returns the clock source UnitID (>=0) on success, or an error. */ int snd_usb_clock_find_source(struct snd_usb_audio *chip, int entity_id, bool validate) { DECLARE_BITMAP(visited, 256); memset(visited, 0, sizeof(visited)); return __uac_clock_find_source(chip, entity_id, visited, validate); } static int set_sample_rate_v1(struct snd_usb_audio *chip, int iface, struct usb_host_interface *alts, struct audioformat *fmt, int rate) { struct usb_device *dev = chip->dev; unsigned int ep; unsigned char data[3]; int err, crate; ep = get_endpoint(alts, 0)->bEndpointAddress; /* if endpoint doesn't have sampling rate control, bail out */ if (!(fmt->attributes & UAC_EP_CS_ATTR_SAMPLE_RATE)) return 0; data[0] = rate; data[1] = rate >> 8; data[2] = rate >> 16; if ((err = snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0), UAC_SET_CUR, USB_TYPE_CLASS | USB_RECIP_ENDPOINT | USB_DIR_OUT, UAC_EP_CS_ATTR_SAMPLE_RATE << 8, ep, data, sizeof(data))) < 0) { snd_printk(KERN_ERR "%d:%d:%d: cannot set freq %d to ep %#x\n", dev->devnum, iface, fmt->altsetting, rate, ep); return err; } if ((err = snd_usb_ctl_msg(dev, usb_rcvctrlpipe(dev, 0), UAC_GET_CUR, USB_TYPE_CLASS | USB_RECIP_ENDPOINT | USB_DIR_IN, UAC_EP_CS_ATTR_SAMPLE_RATE << 8, ep, data, sizeof(data))) < 0) { snd_printk(KERN_WARNING "%d:%d:%d: cannot get freq at ep %#x\n", dev->devnum, iface, fmt->altsetting, ep); return 0; /* some devices don't support reading */ } crate = data[0] | (data[1] << 8) | (data[2] << 16); if (crate != rate) { snd_printd(KERN_WARNING "current rate %d is different from the runtime rate %d\n", crate, rate); // runtime->rate = crate; } return 0; } static int get_sample_rate_v2(struct snd_usb_audio *chip, int iface, int altsetting, int clock) { struct usb_device *dev = chip->dev; __le32 data; int err; err = snd_usb_ctl_msg(dev, usb_rcvctrlpipe(dev, 0), UAC2_CS_CUR, USB_TYPE_CLASS | USB_RECIP_INTERFACE | USB_DIR_IN, UAC2_CS_CONTROL_SAM_FREQ << 8, snd_usb_ctrl_intf(chip) | (clock << 8), &data, sizeof(data)); if (err < 0) { snd_printk(KERN_WARNING "%d:%d:%d: cannot get freq (v2): err %d\n", dev->devnum, iface, altsetting, err); return 0; } return le32_to_cpu(data); } static int set_sample_rate_v2(struct snd_usb_audio *chip, int iface, struct usb_host_interface *alts, struct audioformat *fmt, int rate) { struct usb_device *dev = chip->dev; __le32 data; int err, cur_rate, prev_rate; int clock; bool writeable; struct uac_clock_source_descriptor *cs_desc; clock = snd_usb_clock_find_source(chip, fmt->clock, true); if (clock < 0) return clock; prev_rate = get_sample_rate_v2(chip, iface, fmt->altsetting, clock); if (prev_rate == rate) return 0; cs_desc = snd_usb_find_clock_source(chip->ctrl_intf, clock); writeable = uac2_control_is_writeable(cs_desc->bmControls, UAC2_CS_CONTROL_SAM_FREQ - 1); if (writeable) { data = cpu_to_le32(rate); err = snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0), UAC2_CS_CUR, USB_TYPE_CLASS | USB_RECIP_INTERFACE | USB_DIR_OUT, UAC2_CS_CONTROL_SAM_FREQ << 8, snd_usb_ctrl_intf(chip) | (clock << 8), &data, sizeof(data)); if (err < 0) { snd_printk(KERN_ERR "%d:%d:%d: cannot set freq %d (v2): err %d\n", dev->devnum, iface, fmt->altsetting, rate, err); return err; } cur_rate = get_sample_rate_v2(chip, iface, fmt->altsetting, clock); } else { cur_rate = prev_rate; } if (cur_rate != rate) { if (!writeable) { snd_printk(KERN_WARNING "%d:%d:%d: freq mismatch (RO clock): req %d, clock runs @%d\n", dev->devnum, iface, fmt->altsetting, rate, cur_rate); return -ENXIO; } snd_printd(KERN_WARNING "current rate %d is different from the runtime rate %d\n", cur_rate, rate); } /* Some devices doesn't respond to sample rate changes while the * interface is active. */ if (rate != prev_rate) { usb_set_interface(dev, iface, 0); snd_usb_set_interface_quirk(dev); usb_set_interface(dev, iface, fmt->altsetting); snd_usb_set_interface_quirk(dev); } return 0; } int snd_usb_init_sample_rate(struct snd_usb_audio *chip, int iface, struct usb_host_interface *alts, struct audioformat *fmt, int rate) { struct usb_interface_descriptor *altsd = get_iface_desc(alts); switch (altsd->bInterfaceProtocol) { case UAC_VERSION_1: default: return set_sample_rate_v1(chip, iface, alts, fmt, rate); case UAC_VERSION_2: return set_sample_rate_v2(chip, iface, alts, fmt, rate); } }
gpl-2.0
nDroidProject/nDroid-kernel
drivers/xen/dbgp.c
2317
1152
#include <linux/pci.h> #include <linux/usb.h> #include <linux/usb/ehci_def.h> #include <linux/usb/hcd.h> #include <asm/xen/hypercall.h> #include <xen/interface/physdev.h> #include <xen/xen.h> static int xen_dbgp_op(struct usb_hcd *hcd, int op) { #ifdef CONFIG_PCI const struct device *ctrlr = hcd_to_bus(hcd)->controller; #endif struct physdev_dbgp_op dbgp; if (!xen_initial_domain()) return 0; dbgp.op = op; #ifdef CONFIG_PCI if (dev_is_pci(ctrlr)) { const struct pci_dev *pdev = to_pci_dev(ctrlr); dbgp.u.pci.seg = pci_domain_nr(pdev->bus); dbgp.u.pci.bus = pdev->bus->number; dbgp.u.pci.devfn = pdev->devfn; dbgp.bus = PHYSDEVOP_DBGP_BUS_PCI; } else #endif dbgp.bus = PHYSDEVOP_DBGP_BUS_UNKNOWN; return HYPERVISOR_physdev_op(PHYSDEVOP_dbgp_op, &dbgp); } int xen_dbgp_reset_prep(struct usb_hcd *hcd) { return xen_dbgp_op(hcd, PHYSDEVOP_DBGP_RESET_PREPARE); } int xen_dbgp_external_startup(struct usb_hcd *hcd) { return xen_dbgp_op(hcd, PHYSDEVOP_DBGP_RESET_DONE); } #ifndef CONFIG_EARLY_PRINTK_DBGP #include <linux/export.h> EXPORT_SYMBOL_GPL(xen_dbgp_reset_prep); EXPORT_SYMBOL_GPL(xen_dbgp_external_startup); #endif
gpl-2.0
MoKee/android_kernel_htc_villec2
drivers/isdn/i4l/isdn_audio.c
3341
20313
/* $Id: isdn_audio.c,v 1.1.2.2 2004/01/12 22:37:18 keil Exp $ * * Linux ISDN subsystem, audio conversion and compression (linklevel). * * Copyright 1994-1999 by Fritz Elfert (fritz@isdn4linux.de) * DTMF code (c) 1996 by Christian Mock (cm@kukuruz.ping.at) * Silence detection (c) 1998 by Armin Schindler (mac@gismo.telekom.de) * * This software may be used and distributed according to the terms * of the GNU General Public License, incorporated herein by reference. * */ #include <linux/isdn.h> #include <linux/slab.h> #include "isdn_audio.h" #include "isdn_common.h" char *isdn_audio_revision = "$Revision: 1.1.2.2 $"; /* * Misc. lookup-tables. */ /* ulaw -> signed 16-bit */ static short isdn_audio_ulaw_to_s16[] = { 0x8284, 0x8684, 0x8a84, 0x8e84, 0x9284, 0x9684, 0x9a84, 0x9e84, 0xa284, 0xa684, 0xaa84, 0xae84, 0xb284, 0xb684, 0xba84, 0xbe84, 0xc184, 0xc384, 0xc584, 0xc784, 0xc984, 0xcb84, 0xcd84, 0xcf84, 0xd184, 0xd384, 0xd584, 0xd784, 0xd984, 0xdb84, 0xdd84, 0xdf84, 0xe104, 0xe204, 0xe304, 0xe404, 0xe504, 0xe604, 0xe704, 0xe804, 0xe904, 0xea04, 0xeb04, 0xec04, 0xed04, 0xee04, 0xef04, 0xf004, 0xf0c4, 0xf144, 0xf1c4, 0xf244, 0xf2c4, 0xf344, 0xf3c4, 0xf444, 0xf4c4, 0xf544, 0xf5c4, 0xf644, 0xf6c4, 0xf744, 0xf7c4, 0xf844, 0xf8a4, 0xf8e4, 0xf924, 0xf964, 0xf9a4, 0xf9e4, 0xfa24, 0xfa64, 0xfaa4, 0xfae4, 0xfb24, 0xfb64, 0xfba4, 0xfbe4, 0xfc24, 0xfc64, 0xfc94, 0xfcb4, 0xfcd4, 0xfcf4, 0xfd14, 0xfd34, 0xfd54, 0xfd74, 0xfd94, 0xfdb4, 0xfdd4, 0xfdf4, 0xfe14, 0xfe34, 0xfe54, 0xfe74, 0xfe8c, 0xfe9c, 0xfeac, 0xfebc, 0xfecc, 0xfedc, 0xfeec, 0xfefc, 0xff0c, 0xff1c, 0xff2c, 0xff3c, 0xff4c, 0xff5c, 0xff6c, 0xff7c, 0xff88, 0xff90, 0xff98, 0xffa0, 0xffa8, 0xffb0, 0xffb8, 0xffc0, 0xffc8, 0xffd0, 0xffd8, 0xffe0, 0xffe8, 0xfff0, 0xfff8, 0x0000, 0x7d7c, 0x797c, 0x757c, 0x717c, 0x6d7c, 0x697c, 0x657c, 0x617c, 0x5d7c, 0x597c, 0x557c, 0x517c, 0x4d7c, 0x497c, 0x457c, 0x417c, 0x3e7c, 0x3c7c, 0x3a7c, 0x387c, 0x367c, 0x347c, 0x327c, 0x307c, 0x2e7c, 0x2c7c, 0x2a7c, 0x287c, 0x267c, 0x247c, 0x227c, 0x207c, 0x1efc, 0x1dfc, 0x1cfc, 0x1bfc, 0x1afc, 0x19fc, 0x18fc, 0x17fc, 0x16fc, 0x15fc, 0x14fc, 0x13fc, 0x12fc, 0x11fc, 0x10fc, 0x0ffc, 0x0f3c, 0x0ebc, 0x0e3c, 0x0dbc, 0x0d3c, 0x0cbc, 0x0c3c, 0x0bbc, 0x0b3c, 0x0abc, 0x0a3c, 0x09bc, 0x093c, 0x08bc, 0x083c, 0x07bc, 0x075c, 0x071c, 0x06dc, 0x069c, 0x065c, 0x061c, 0x05dc, 0x059c, 0x055c, 0x051c, 0x04dc, 0x049c, 0x045c, 0x041c, 0x03dc, 0x039c, 0x036c, 0x034c, 0x032c, 0x030c, 0x02ec, 0x02cc, 0x02ac, 0x028c, 0x026c, 0x024c, 0x022c, 0x020c, 0x01ec, 0x01cc, 0x01ac, 0x018c, 0x0174, 0x0164, 0x0154, 0x0144, 0x0134, 0x0124, 0x0114, 0x0104, 0x00f4, 0x00e4, 0x00d4, 0x00c4, 0x00b4, 0x00a4, 0x0094, 0x0084, 0x0078, 0x0070, 0x0068, 0x0060, 0x0058, 0x0050, 0x0048, 0x0040, 0x0038, 0x0030, 0x0028, 0x0020, 0x0018, 0x0010, 0x0008, 0x0000 }; /* alaw -> signed 16-bit */ static short isdn_audio_alaw_to_s16[] = { 0x13fc, 0xec04, 0x0144, 0xfebc, 0x517c, 0xae84, 0x051c, 0xfae4, 0x0a3c, 0xf5c4, 0x0048, 0xffb8, 0x287c, 0xd784, 0x028c, 0xfd74, 0x1bfc, 0xe404, 0x01cc, 0xfe34, 0x717c, 0x8e84, 0x071c, 0xf8e4, 0x0e3c, 0xf1c4, 0x00c4, 0xff3c, 0x387c, 0xc784, 0x039c, 0xfc64, 0x0ffc, 0xf004, 0x0104, 0xfefc, 0x417c, 0xbe84, 0x041c, 0xfbe4, 0x083c, 0xf7c4, 0x0008, 0xfff8, 0x207c, 0xdf84, 0x020c, 0xfdf4, 0x17fc, 0xe804, 0x018c, 0xfe74, 0x617c, 0x9e84, 0x061c, 0xf9e4, 0x0c3c, 0xf3c4, 0x0084, 0xff7c, 0x307c, 0xcf84, 0x030c, 0xfcf4, 0x15fc, 0xea04, 0x0164, 0xfe9c, 0x597c, 0xa684, 0x059c, 0xfa64, 0x0b3c, 0xf4c4, 0x0068, 0xff98, 0x2c7c, 0xd384, 0x02cc, 0xfd34, 0x1dfc, 0xe204, 0x01ec, 0xfe14, 0x797c, 0x8684, 0x07bc, 0xf844, 0x0f3c, 0xf0c4, 0x00e4, 0xff1c, 0x3c7c, 0xc384, 0x03dc, 0xfc24, 0x11fc, 0xee04, 0x0124, 0xfedc, 0x497c, 0xb684, 0x049c, 0xfb64, 0x093c, 0xf6c4, 0x0028, 0xffd8, 0x247c, 0xdb84, 0x024c, 0xfdb4, 0x19fc, 0xe604, 0x01ac, 0xfe54, 0x697c, 0x9684, 0x069c, 0xf964, 0x0d3c, 0xf2c4, 0x00a4, 0xff5c, 0x347c, 0xcb84, 0x034c, 0xfcb4, 0x12fc, 0xed04, 0x0134, 0xfecc, 0x4d7c, 0xb284, 0x04dc, 0xfb24, 0x09bc, 0xf644, 0x0038, 0xffc8, 0x267c, 0xd984, 0x026c, 0xfd94, 0x1afc, 0xe504, 0x01ac, 0xfe54, 0x6d7c, 0x9284, 0x06dc, 0xf924, 0x0dbc, 0xf244, 0x00b4, 0xff4c, 0x367c, 0xc984, 0x036c, 0xfc94, 0x0f3c, 0xf0c4, 0x00f4, 0xff0c, 0x3e7c, 0xc184, 0x03dc, 0xfc24, 0x07bc, 0xf844, 0x0008, 0xfff8, 0x1efc, 0xe104, 0x01ec, 0xfe14, 0x16fc, 0xe904, 0x0174, 0xfe8c, 0x5d7c, 0xa284, 0x05dc, 0xfa24, 0x0bbc, 0xf444, 0x0078, 0xff88, 0x2e7c, 0xd184, 0x02ec, 0xfd14, 0x14fc, 0xeb04, 0x0154, 0xfeac, 0x557c, 0xaa84, 0x055c, 0xfaa4, 0x0abc, 0xf544, 0x0058, 0xffa8, 0x2a7c, 0xd584, 0x02ac, 0xfd54, 0x1cfc, 0xe304, 0x01cc, 0xfe34, 0x757c, 0x8a84, 0x075c, 0xf8a4, 0x0ebc, 0xf144, 0x00d4, 0xff2c, 0x3a7c, 0xc584, 0x039c, 0xfc64, 0x10fc, 0xef04, 0x0114, 0xfeec, 0x457c, 0xba84, 0x045c, 0xfba4, 0x08bc, 0xf744, 0x0018, 0xffe8, 0x227c, 0xdd84, 0x022c, 0xfdd4, 0x18fc, 0xe704, 0x018c, 0xfe74, 0x657c, 0x9a84, 0x065c, 0xf9a4, 0x0cbc, 0xf344, 0x0094, 0xff6c, 0x327c, 0xcd84, 0x032c, 0xfcd4 }; /* alaw -> ulaw */ static char isdn_audio_alaw_to_ulaw[] = { 0xab, 0x2b, 0xe3, 0x63, 0x8b, 0x0b, 0xc9, 0x49, 0xba, 0x3a, 0xf6, 0x76, 0x9b, 0x1b, 0xd7, 0x57, 0xa3, 0x23, 0xdd, 0x5d, 0x83, 0x03, 0xc1, 0x41, 0xb2, 0x32, 0xeb, 0x6b, 0x93, 0x13, 0xcf, 0x4f, 0xaf, 0x2f, 0xe7, 0x67, 0x8f, 0x0f, 0xcd, 0x4d, 0xbe, 0x3e, 0xfe, 0x7e, 0x9f, 0x1f, 0xdb, 0x5b, 0xa7, 0x27, 0xdf, 0x5f, 0x87, 0x07, 0xc5, 0x45, 0xb6, 0x36, 0xef, 0x6f, 0x97, 0x17, 0xd3, 0x53, 0xa9, 0x29, 0xe1, 0x61, 0x89, 0x09, 0xc7, 0x47, 0xb8, 0x38, 0xf2, 0x72, 0x99, 0x19, 0xd5, 0x55, 0xa1, 0x21, 0xdc, 0x5c, 0x81, 0x01, 0xbf, 0x3f, 0xb0, 0x30, 0xe9, 0x69, 0x91, 0x11, 0xce, 0x4e, 0xad, 0x2d, 0xe5, 0x65, 0x8d, 0x0d, 0xcb, 0x4b, 0xbc, 0x3c, 0xfa, 0x7a, 0x9d, 0x1d, 0xd9, 0x59, 0xa5, 0x25, 0xde, 0x5e, 0x85, 0x05, 0xc3, 0x43, 0xb4, 0x34, 0xed, 0x6d, 0x95, 0x15, 0xd1, 0x51, 0xac, 0x2c, 0xe4, 0x64, 0x8c, 0x0c, 0xca, 0x4a, 0xbb, 0x3b, 0xf8, 0x78, 0x9c, 0x1c, 0xd8, 0x58, 0xa4, 0x24, 0xde, 0x5e, 0x84, 0x04, 0xc2, 0x42, 0xb3, 0x33, 0xec, 0x6c, 0x94, 0x14, 0xd0, 0x50, 0xb0, 0x30, 0xe8, 0x68, 0x90, 0x10, 0xce, 0x4e, 0xbf, 0x3f, 0xfe, 0x7e, 0xa0, 0x20, 0xdc, 0x5c, 0xa8, 0x28, 0xe0, 0x60, 0x88, 0x08, 0xc6, 0x46, 0xb7, 0x37, 0xf0, 0x70, 0x98, 0x18, 0xd4, 0x54, 0xaa, 0x2a, 0xe2, 0x62, 0x8a, 0x0a, 0xc8, 0x48, 0xb9, 0x39, 0xf4, 0x74, 0x9a, 0x1a, 0xd6, 0x56, 0xa2, 0x22, 0xdd, 0x5d, 0x82, 0x02, 0xc0, 0x40, 0xb1, 0x31, 0xea, 0x6a, 0x92, 0x12, 0xcf, 0x4f, 0xae, 0x2e, 0xe6, 0x66, 0x8e, 0x0e, 0xcc, 0x4c, 0xbd, 0x3d, 0xfc, 0x7c, 0x9e, 0x1e, 0xda, 0x5a, 0xa6, 0x26, 0xdf, 0x5f, 0x86, 0x06, 0xc4, 0x44, 0xb5, 0x35, 0xee, 0x6e, 0x96, 0x16, 0xd2, 0x52 }; /* ulaw -> alaw */ static char isdn_audio_ulaw_to_alaw[] = { 0xab, 0x55, 0xd5, 0x15, 0x95, 0x75, 0xf5, 0x35, 0xb5, 0x45, 0xc5, 0x05, 0x85, 0x65, 0xe5, 0x25, 0xa5, 0x5d, 0xdd, 0x1d, 0x9d, 0x7d, 0xfd, 0x3d, 0xbd, 0x4d, 0xcd, 0x0d, 0x8d, 0x6d, 0xed, 0x2d, 0xad, 0x51, 0xd1, 0x11, 0x91, 0x71, 0xf1, 0x31, 0xb1, 0x41, 0xc1, 0x01, 0x81, 0x61, 0xe1, 0x21, 0x59, 0xd9, 0x19, 0x99, 0x79, 0xf9, 0x39, 0xb9, 0x49, 0xc9, 0x09, 0x89, 0x69, 0xe9, 0x29, 0xa9, 0xd7, 0x17, 0x97, 0x77, 0xf7, 0x37, 0xb7, 0x47, 0xc7, 0x07, 0x87, 0x67, 0xe7, 0x27, 0xa7, 0xdf, 0x9f, 0x7f, 0xff, 0x3f, 0xbf, 0x4f, 0xcf, 0x0f, 0x8f, 0x6f, 0xef, 0x2f, 0x53, 0x13, 0x73, 0x33, 0xb3, 0x43, 0xc3, 0x03, 0x83, 0x63, 0xe3, 0x23, 0xa3, 0x5b, 0xdb, 0x1b, 0x9b, 0x7b, 0xfb, 0x3b, 0xbb, 0xbb, 0x4b, 0x4b, 0xcb, 0xcb, 0x0b, 0x0b, 0x8b, 0x8b, 0x6b, 0x6b, 0xeb, 0xeb, 0x2b, 0x2b, 0xab, 0x54, 0xd4, 0x14, 0x94, 0x74, 0xf4, 0x34, 0xb4, 0x44, 0xc4, 0x04, 0x84, 0x64, 0xe4, 0x24, 0xa4, 0x5c, 0xdc, 0x1c, 0x9c, 0x7c, 0xfc, 0x3c, 0xbc, 0x4c, 0xcc, 0x0c, 0x8c, 0x6c, 0xec, 0x2c, 0xac, 0x50, 0xd0, 0x10, 0x90, 0x70, 0xf0, 0x30, 0xb0, 0x40, 0xc0, 0x00, 0x80, 0x60, 0xe0, 0x20, 0x58, 0xd8, 0x18, 0x98, 0x78, 0xf8, 0x38, 0xb8, 0x48, 0xc8, 0x08, 0x88, 0x68, 0xe8, 0x28, 0xa8, 0xd6, 0x16, 0x96, 0x76, 0xf6, 0x36, 0xb6, 0x46, 0xc6, 0x06, 0x86, 0x66, 0xe6, 0x26, 0xa6, 0xde, 0x9e, 0x7e, 0xfe, 0x3e, 0xbe, 0x4e, 0xce, 0x0e, 0x8e, 0x6e, 0xee, 0x2e, 0x52, 0x12, 0x72, 0x32, 0xb2, 0x42, 0xc2, 0x02, 0x82, 0x62, 0xe2, 0x22, 0xa2, 0x5a, 0xda, 0x1a, 0x9a, 0x7a, 0xfa, 0x3a, 0xba, 0xba, 0x4a, 0x4a, 0xca, 0xca, 0x0a, 0x0a, 0x8a, 0x8a, 0x6a, 0x6a, 0xea, 0xea, 0x2a, 0x2a }; #define NCOEFF 8 /* number of frequencies to be analyzed */ #define DTMF_TRESH 4000 /* above this is dtmf */ #define SILENCE_TRESH 200 /* below this is silence */ #define AMP_BITS 9 /* bits per sample, reduced to avoid overflow */ #define LOGRP 0 #define HIGRP 1 /* For DTMF recognition: * 2 * cos(2 * PI * k / N) precalculated for all k */ static int cos2pik[NCOEFF] = { 55813, 53604, 51193, 48591, 38114, 33057, 25889, 18332 }; static char dtmf_matrix[4][4] = { {'1', '2', '3', 'A'}, {'4', '5', '6', 'B'}, {'7', '8', '9', 'C'}, {'*', '0', '#', 'D'} }; static inline void isdn_audio_tlookup(const u_char *table, u_char *buff, unsigned long n) { #ifdef __i386__ unsigned long d0, d1, d2, d3; __asm__ __volatile__( "cld\n" "1:\tlodsb\n\t" "xlatb\n\t" "stosb\n\t" "loop 1b\n\t" : "=&b"(d0), "=&c"(d1), "=&D"(d2), "=&S"(d3) : "0"((long) table), "1"(n), "2"((long) buff), "3"((long) buff) : "memory", "ax"); #else while (n--) *buff = table[*(unsigned char *)buff], buff++; #endif } void isdn_audio_ulaw2alaw(unsigned char *buff, unsigned long len) { isdn_audio_tlookup(isdn_audio_ulaw_to_alaw, buff, len); } void isdn_audio_alaw2ulaw(unsigned char *buff, unsigned long len) { isdn_audio_tlookup(isdn_audio_alaw_to_ulaw, buff, len); } /* * linear <-> adpcm conversion stuff * Most parts from the mgetty-package. * (C) by Gert Doering and Klaus Weidner * Used by permission of Gert Doering */ #define ZEROTRAP /* turn on the trap as per the MIL-STD */ #undef ZEROTRAP #define BIAS 0x84 /* define the add-in bias for 16 bit samples */ #define CLIP 32635 static unsigned char isdn_audio_linear2ulaw(int sample) { static int exp_lut[256] = { 0, 0, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7 }; int sign, exponent, mantissa; unsigned char ulawbyte; /* Get the sample into sign-magnitude. */ sign = (sample >> 8) & 0x80; /* set aside the sign */ if (sign != 0) sample = -sample; /* get magnitude */ if (sample > CLIP) sample = CLIP; /* clip the magnitude */ /* Convert from 16 bit linear to ulaw. */ sample = sample + BIAS; exponent = exp_lut[(sample >> 7) & 0xFF]; mantissa = (sample >> (exponent + 3)) & 0x0F; ulawbyte = ~(sign | (exponent << 4) | mantissa); #ifdef ZEROTRAP /* optional CCITT trap */ if (ulawbyte == 0) ulawbyte = 0x02; #endif return (ulawbyte); } static int Mx[3][8] = { {0x3800, 0x5600, 0, 0, 0, 0, 0, 0}, {0x399a, 0x3a9f, 0x4d14, 0x6607, 0, 0, 0, 0}, {0x3556, 0x3556, 0x399A, 0x3A9F, 0x4200, 0x4D14, 0x6607, 0x6607}, }; static int bitmask[9] = { 0, 0x01, 0x03, 0x07, 0x0f, 0x1f, 0x3f, 0x7f, 0xff }; static int isdn_audio_get_bits(adpcm_state * s, unsigned char **in, int *len) { while (s->nleft < s->nbits) { int d = *((*in)++); (*len)--; s->word = (s->word << 8) | d; s->nleft += 8; } s->nleft -= s->nbits; return (s->word >> s->nleft) & bitmask[s->nbits]; } static void isdn_audio_put_bits(int data, int nbits, adpcm_state * s, unsigned char **out, int *len) { s->word = (s->word << nbits) | (data & bitmask[nbits]); s->nleft += nbits; while (s->nleft >= 8) { int d = (s->word >> (s->nleft - 8)); *(out[0]++) = d & 255; (*len)++; s->nleft -= 8; } } adpcm_state * isdn_audio_adpcm_init(adpcm_state * s, int nbits) { if (!s) s = kmalloc(sizeof(adpcm_state), GFP_ATOMIC); if (s) { s->a = 0; s->d = 5; s->word = 0; s->nleft = 0; s->nbits = nbits; } return s; } dtmf_state * isdn_audio_dtmf_init(dtmf_state * s) { if (!s) s = kmalloc(sizeof(dtmf_state), GFP_ATOMIC); if (s) { s->idx = 0; s->last = ' '; } return s; } /* * Decompression of adpcm data to a/u-law * */ int isdn_audio_adpcm2xlaw(adpcm_state * s, int fmt, unsigned char *in, unsigned char *out, int len) { int a = s->a; int d = s->d; int nbits = s->nbits; int olen = 0; while (len) { int e = isdn_audio_get_bits(s, &in, &len); int sign; if (nbits == 4 && e == 0) d = 4; sign = (e >> (nbits - 1)) ? -1 : 1; e &= bitmask[nbits - 1]; a += sign * ((e << 1) + 1) * d >> 1; if (d & 1) a++; if (fmt) *out++ = isdn_audio_ulaw_to_alaw[ isdn_audio_linear2ulaw(a << 2)]; else *out++ = isdn_audio_linear2ulaw(a << 2); olen++; d = (d * Mx[nbits - 2][e] + 0x2000) >> 14; if (d < 5) d = 5; } s->a = a; s->d = d; return olen; } int isdn_audio_xlaw2adpcm(adpcm_state * s, int fmt, unsigned char *in, unsigned char *out, int len) { int a = s->a; int d = s->d; int nbits = s->nbits; int olen = 0; while (len--) { int e = 0, nmax = 1 << (nbits - 1); int sign, delta; if (fmt) delta = (isdn_audio_alaw_to_s16[*in++] >> 2) - a; else delta = (isdn_audio_ulaw_to_s16[*in++] >> 2) - a; if (delta < 0) { e = nmax; delta = -delta; } while (--nmax && delta > d) { delta -= d; e++; } if (nbits == 4 && ((e & 0x0f) == 0)) e = 8; isdn_audio_put_bits(e, nbits, s, &out, &olen); sign = (e >> (nbits - 1)) ? -1 : 1; e &= bitmask[nbits - 1]; a += sign * ((e << 1) + 1) * d >> 1; if (d & 1) a++; d = (d * Mx[nbits - 2][e] + 0x2000) >> 14; if (d < 5) d = 5; } s->a = a; s->d = d; return olen; } /* * Goertzel algorithm. * See http://ptolemy.eecs.berkeley.edu/papers/96/dtmf_ict/ * for more info. * Result is stored into an sk_buff and queued up for later * evaluation. */ static void isdn_audio_goertzel(int *sample, modem_info * info) { int sk, sk1, sk2; int k, n; struct sk_buff *skb; int *result; skb = dev_alloc_skb(sizeof(int) * NCOEFF); if (!skb) { printk(KERN_WARNING "isdn_audio: Could not alloc DTMF result for ttyI%d\n", info->line); return; } result = (int *) skb_put(skb, sizeof(int) * NCOEFF); for (k = 0; k < NCOEFF; k++) { sk = sk1 = sk2 = 0; for (n = 0; n < DTMF_NPOINTS; n++) { sk = sample[n] + ((cos2pik[k] * sk1) >> 15) - sk2; sk2 = sk1; sk1 = sk; } /* Avoid overflows */ sk >>= 1; sk2 >>= 1; /* compute |X(k)|**2 */ /* report overflows. This should not happen. */ /* Comment this out if desired */ if (sk < -32768 || sk > 32767) printk(KERN_DEBUG "isdn_audio: dtmf goertzel overflow, sk=%d\n", sk); if (sk2 < -32768 || sk2 > 32767) printk(KERN_DEBUG "isdn_audio: dtmf goertzel overflow, sk2=%d\n", sk2); result[k] = ((sk * sk) >> AMP_BITS) - ((((cos2pik[k] * sk) >> 15) * sk2) >> AMP_BITS) + ((sk2 * sk2) >> AMP_BITS); } skb_queue_tail(&info->dtmf_queue, skb); isdn_timer_ctrl(ISDN_TIMER_MODEMREAD, 1); } void isdn_audio_eval_dtmf(modem_info * info) { struct sk_buff *skb; int *result; dtmf_state *s; int silence; int i; int di; int ch; int grp[2]; char what; char *p; int thresh; while ((skb = skb_dequeue(&info->dtmf_queue))) { result = (int *) skb->data; s = info->dtmf_state; grp[LOGRP] = grp[HIGRP] = -1; silence = 0; thresh = 0; for (i = 0; i < NCOEFF; i++) { if (result[i] > DTMF_TRESH) { if (result[i] > thresh) thresh = result[i]; } else if (result[i] < SILENCE_TRESH) silence++; } if (silence == NCOEFF) what = ' '; else { if (thresh > 0) { thresh = thresh >> 4; /* touchtones must match within 12 dB */ for (i = 0; i < NCOEFF; i++) { if (result[i] < thresh) continue; /* ignore */ /* good level found. This is allowed only one time per group */ if (i < NCOEFF / 2) { /* lowgroup*/ if (grp[LOGRP] >= 0) { // Bad. Another tone found. */ grp[LOGRP] = -1; break; } else grp[LOGRP] = i; } else { /* higroup */ if (grp[HIGRP] >= 0) { // Bad. Another tone found. */ grp[HIGRP] = -1; break; } else grp[HIGRP] = i - NCOEFF/2; } } if ((grp[LOGRP] >= 0) && (grp[HIGRP] >= 0)) { what = dtmf_matrix[grp[LOGRP]][grp[HIGRP]]; if (s->last != ' ' && s->last != '.') s->last = what; /* min. 1 non-DTMF between DTMF */ } else what = '.'; } else what = '.'; } if ((what != s->last) && (what != ' ') && (what != '.')) { printk(KERN_DEBUG "dtmf: tt='%c'\n", what); p = skb->data; *p++ = 0x10; *p = what; skb_trim(skb, 2); ISDN_AUDIO_SKB_DLECOUNT(skb) = 0; ISDN_AUDIO_SKB_LOCK(skb) = 0; di = info->isdn_driver; ch = info->isdn_channel; __skb_queue_tail(&dev->drv[di]->rpqueue[ch], skb); dev->drv[di]->rcvcount[ch] += 2; /* Schedule dequeuing */ if ((dev->modempoll) && (info->rcvsched)) isdn_timer_ctrl(ISDN_TIMER_MODEMREAD, 1); wake_up_interruptible(&dev->drv[di]->rcv_waitq[ch]); } else kfree_skb(skb); s->last = what; } } /* * Decode DTMF tones, queue result in separate sk_buf for * later examination. * Parameters: * s = pointer to state-struct. * buf = input audio data * len = size of audio data. * fmt = audio data format (0 = ulaw, 1 = alaw) */ void isdn_audio_calc_dtmf(modem_info * info, unsigned char *buf, int len, int fmt) { dtmf_state *s = info->dtmf_state; int i; int c; while (len) { c = DTMF_NPOINTS - s->idx; if (c > len) c = len; if (c <= 0) break; for (i = 0; i < c; i++) { if (fmt) s->buf[s->idx++] = isdn_audio_alaw_to_s16[*buf++] >> (15 - AMP_BITS); else s->buf[s->idx++] = isdn_audio_ulaw_to_s16[*buf++] >> (15 - AMP_BITS); } if (s->idx == DTMF_NPOINTS) { isdn_audio_goertzel(s->buf, info); s->idx = 0; } len -= c; } } silence_state * isdn_audio_silence_init(silence_state * s) { if (!s) s = kmalloc(sizeof(silence_state), GFP_ATOMIC); if (s) { s->idx = 0; s->state = 0; } return s; } void isdn_audio_calc_silence(modem_info * info, unsigned char *buf, int len, int fmt) { silence_state *s = info->silence_state; int i; signed char c; if (!info->emu.vpar[1]) return; for (i = 0; i < len; i++) { if (fmt) c = isdn_audio_alaw_to_ulaw[*buf++]; else c = *buf++; if (c > 0) c -= 128; c = abs(c); if (c > (info->emu.vpar[1] * 4)) { s->idx = 0; s->state = 1; } else { if (s->idx < 210000) s->idx++; } } } void isdn_audio_put_dle_code(modem_info * info, u_char code) { struct sk_buff *skb; int di; int ch; char *p; skb = dev_alloc_skb(2); if (!skb) { printk(KERN_WARNING "isdn_audio: Could not alloc skb for ttyI%d\n", info->line); return; } p = (char *) skb_put(skb, 2); p[0] = 0x10; p[1] = code; ISDN_AUDIO_SKB_DLECOUNT(skb) = 0; ISDN_AUDIO_SKB_LOCK(skb) = 0; di = info->isdn_driver; ch = info->isdn_channel; __skb_queue_tail(&dev->drv[di]->rpqueue[ch], skb); dev->drv[di]->rcvcount[ch] += 2; /* Schedule dequeuing */ if ((dev->modempoll) && (info->rcvsched)) isdn_timer_ctrl(ISDN_TIMER_MODEMREAD, 1); wake_up_interruptible(&dev->drv[di]->rcv_waitq[ch]); } void isdn_audio_eval_silence(modem_info * info) { silence_state *s = info->silence_state; char what; what = ' '; if (s->idx > (info->emu.vpar[2] * 800)) { s->idx = 0; if (!s->state) { /* silence from beginning of rec */ what = 's'; } else { what = 'q'; } } if ((what == 's') || (what == 'q')) { printk(KERN_DEBUG "ttyI%d: %s\n", info->line, (what=='s') ? "silence":"quiet"); isdn_audio_put_dle_code(info, what); } }
gpl-2.0
EuphoriaOS/android_kernel_samsung_exynos5410
arch/arm/mach-imx/mach-qong.c
4877
6763
/* * Copyright (C) 2009 Ilya Yanok, Emcraft Systems Ltd, <yanok@emcraft.com> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. */ #include <linux/types.h> #include <linux/init.h> #include <linux/kernel.h> #include <linux/memory.h> #include <linux/platform_device.h> #include <linux/mtd/physmap.h> #include <linux/mtd/nand.h> #include <linux/gpio.h> #include <mach/hardware.h> #include <mach/irqs.h> #include <asm/mach-types.h> #include <asm/mach/arch.h> #include <asm/mach/time.h> #include <asm/mach/map.h> #include <mach/common.h> #include <asm/page.h> #include <asm/setup.h> #include <mach/iomux-mx3.h> #include "devices-imx31.h" /* FPGA defines */ #define QONG_FPGA_VERSION(major, minor, rev) \ (((major & 0xF) << 12) | ((minor & 0xF) << 8) | (rev & 0xFF)) #define QONG_FPGA_BASEADDR MX31_CS1_BASE_ADDR #define QONG_FPGA_PERIPH_SIZE (1 << 24) #define QONG_FPGA_CTRL_BASEADDR QONG_FPGA_BASEADDR #define QONG_FPGA_CTRL_SIZE 0x10 /* FPGA control registers */ #define QONG_FPGA_CTRL_VERSION 0x00 #define QONG_DNET_ID 1 #define QONG_DNET_BASEADDR \ (QONG_FPGA_BASEADDR + QONG_DNET_ID * QONG_FPGA_PERIPH_SIZE) #define QONG_DNET_SIZE 0x00001000 #define QONG_FPGA_IRQ IOMUX_TO_IRQ(MX31_PIN_DTR_DCE1) static const struct imxuart_platform_data uart_pdata __initconst = { .flags = IMXUART_HAVE_RTSCTS, }; static int uart_pins[] = { MX31_PIN_CTS1__CTS1, MX31_PIN_RTS1__RTS1, MX31_PIN_TXD1__TXD1, MX31_PIN_RXD1__RXD1 }; static inline void __init mxc_init_imx_uart(void) { mxc_iomux_setup_multiple_pins(uart_pins, ARRAY_SIZE(uart_pins), "uart-0"); imx31_add_imx_uart0(&uart_pdata); } static struct resource dnet_resources[] = { { .name = "dnet-memory", .start = QONG_DNET_BASEADDR, .end = QONG_DNET_BASEADDR + QONG_DNET_SIZE - 1, .flags = IORESOURCE_MEM, }, { .start = QONG_FPGA_IRQ, .end = QONG_FPGA_IRQ, .flags = IORESOURCE_IRQ, }, }; static struct platform_device dnet_device = { .name = "dnet", .id = -1, .num_resources = ARRAY_SIZE(dnet_resources), .resource = dnet_resources, }; static int __init qong_init_dnet(void) { int ret; ret = platform_device_register(&dnet_device); return ret; } /* MTD NOR flash */ static struct physmap_flash_data qong_flash_data = { .width = 2, }; static struct resource qong_flash_resource = { .start = MX31_CS0_BASE_ADDR, .end = MX31_CS0_BASE_ADDR + SZ_128M - 1, .flags = IORESOURCE_MEM, }; static struct platform_device qong_nor_mtd_device = { .name = "physmap-flash", .id = 0, .dev = { .platform_data = &qong_flash_data, }, .resource = &qong_flash_resource, .num_resources = 1, }; static void qong_init_nor_mtd(void) { (void)platform_device_register(&qong_nor_mtd_device); } /* * Hardware specific access to control-lines */ static void qong_nand_cmd_ctrl(struct mtd_info *mtd, int cmd, unsigned int ctrl) { struct nand_chip *nand_chip = mtd->priv; if (cmd == NAND_CMD_NONE) return; if (ctrl & NAND_CLE) writeb(cmd, nand_chip->IO_ADDR_W + (1 << 24)); else writeb(cmd, nand_chip->IO_ADDR_W + (1 << 23)); } /* * Read the Device Ready pin. */ static int qong_nand_device_ready(struct mtd_info *mtd) { return gpio_get_value(IOMUX_TO_GPIO(MX31_PIN_NFRB)); } static void qong_nand_select_chip(struct mtd_info *mtd, int chip) { if (chip >= 0) gpio_set_value(IOMUX_TO_GPIO(MX31_PIN_NFCE_B), 0); else gpio_set_value(IOMUX_TO_GPIO(MX31_PIN_NFCE_B), 1); } static struct platform_nand_data qong_nand_data = { .chip = { .nr_chips = 1, .chip_delay = 20, .options = 0, }, .ctrl = { .cmd_ctrl = qong_nand_cmd_ctrl, .dev_ready = qong_nand_device_ready, .select_chip = qong_nand_select_chip, } }; static struct resource qong_nand_resource = { .start = MX31_CS3_BASE_ADDR, .end = MX31_CS3_BASE_ADDR + SZ_32M - 1, .flags = IORESOURCE_MEM, }; static struct platform_device qong_nand_device = { .name = "gen_nand", .id = -1, .dev = { .platform_data = &qong_nand_data, }, .num_resources = 1, .resource = &qong_nand_resource, }; static void __init qong_init_nand_mtd(void) { /* init CS */ __raw_writel(0x00004f00, MX31_IO_ADDRESS(MX31_WEIM_CSCRxU(3))); __raw_writel(0x20013b31, MX31_IO_ADDRESS(MX31_WEIM_CSCRxL(3))); __raw_writel(0x00020800, MX31_IO_ADDRESS(MX31_WEIM_CSCRxA(3))); mxc_iomux_set_gpr(MUX_SDCTL_CSD1_SEL, true); /* enable pin */ mxc_iomux_mode(IOMUX_MODE(MX31_PIN_NFCE_B, IOMUX_CONFIG_GPIO)); if (!gpio_request(IOMUX_TO_GPIO(MX31_PIN_NFCE_B), "nand_enable")) gpio_direction_output(IOMUX_TO_GPIO(MX31_PIN_NFCE_B), 0); /* ready/busy pin */ mxc_iomux_mode(IOMUX_MODE(MX31_PIN_NFRB, IOMUX_CONFIG_GPIO)); if (!gpio_request(IOMUX_TO_GPIO(MX31_PIN_NFRB), "nand_rdy")) gpio_direction_input(IOMUX_TO_GPIO(MX31_PIN_NFRB)); /* write protect pin */ mxc_iomux_mode(IOMUX_MODE(MX31_PIN_NFWP_B, IOMUX_CONFIG_GPIO)); if (!gpio_request(IOMUX_TO_GPIO(MX31_PIN_NFWP_B), "nand_wp")) gpio_direction_input(IOMUX_TO_GPIO(MX31_PIN_NFWP_B)); platform_device_register(&qong_nand_device); } static void __init qong_init_fpga(void) { void __iomem *regs; u32 fpga_ver; regs = ioremap(QONG_FPGA_CTRL_BASEADDR, QONG_FPGA_CTRL_SIZE); if (!regs) { printk(KERN_ERR "%s: failed to map registers, aborting.\n", __func__); return; } fpga_ver = readl(regs + QONG_FPGA_CTRL_VERSION); iounmap(regs); printk(KERN_INFO "Qong FPGA version %d.%d.%d\n", (fpga_ver & 0xF000) >> 12, (fpga_ver & 0x0F00) >> 8, fpga_ver & 0x00FF); if (fpga_ver < QONG_FPGA_VERSION(0, 8, 7)) { printk(KERN_ERR "qong: Unexpected FPGA version, FPGA-based " "devices won't be registered!\n"); return; } /* register FPGA-based devices */ qong_init_nand_mtd(); qong_init_dnet(); } /* * Board specific initialization. */ static void __init qong_init(void) { imx31_soc_init(); mxc_init_imx_uart(); qong_init_nor_mtd(); qong_init_fpga(); imx31_add_imx2_wdt(NULL); } static void __init qong_timer_init(void) { mx31_clocks_init(26000000); } static struct sys_timer qong_timer = { .init = qong_timer_init, }; MACHINE_START(QONG, "Dave/DENX QongEVB-LITE") /* Maintainer: DENX Software Engineering GmbH */ .atag_offset = 0x100, .map_io = mx31_map_io, .init_early = imx31_init_early, .init_irq = mx31_init_irq, .handle_irq = imx31_handle_irq, .timer = &qong_timer, .init_machine = qong_init, .restart = mxc_restart, MACHINE_END
gpl-2.0
ignacio28/android_kernel_lge_msm8610
arch/arm/mach-imx/mach-qong.c
4877
6763
/* * Copyright (C) 2009 Ilya Yanok, Emcraft Systems Ltd, <yanok@emcraft.com> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. */ #include <linux/types.h> #include <linux/init.h> #include <linux/kernel.h> #include <linux/memory.h> #include <linux/platform_device.h> #include <linux/mtd/physmap.h> #include <linux/mtd/nand.h> #include <linux/gpio.h> #include <mach/hardware.h> #include <mach/irqs.h> #include <asm/mach-types.h> #include <asm/mach/arch.h> #include <asm/mach/time.h> #include <asm/mach/map.h> #include <mach/common.h> #include <asm/page.h> #include <asm/setup.h> #include <mach/iomux-mx3.h> #include "devices-imx31.h" /* FPGA defines */ #define QONG_FPGA_VERSION(major, minor, rev) \ (((major & 0xF) << 12) | ((minor & 0xF) << 8) | (rev & 0xFF)) #define QONG_FPGA_BASEADDR MX31_CS1_BASE_ADDR #define QONG_FPGA_PERIPH_SIZE (1 << 24) #define QONG_FPGA_CTRL_BASEADDR QONG_FPGA_BASEADDR #define QONG_FPGA_CTRL_SIZE 0x10 /* FPGA control registers */ #define QONG_FPGA_CTRL_VERSION 0x00 #define QONG_DNET_ID 1 #define QONG_DNET_BASEADDR \ (QONG_FPGA_BASEADDR + QONG_DNET_ID * QONG_FPGA_PERIPH_SIZE) #define QONG_DNET_SIZE 0x00001000 #define QONG_FPGA_IRQ IOMUX_TO_IRQ(MX31_PIN_DTR_DCE1) static const struct imxuart_platform_data uart_pdata __initconst = { .flags = IMXUART_HAVE_RTSCTS, }; static int uart_pins[] = { MX31_PIN_CTS1__CTS1, MX31_PIN_RTS1__RTS1, MX31_PIN_TXD1__TXD1, MX31_PIN_RXD1__RXD1 }; static inline void __init mxc_init_imx_uart(void) { mxc_iomux_setup_multiple_pins(uart_pins, ARRAY_SIZE(uart_pins), "uart-0"); imx31_add_imx_uart0(&uart_pdata); } static struct resource dnet_resources[] = { { .name = "dnet-memory", .start = QONG_DNET_BASEADDR, .end = QONG_DNET_BASEADDR + QONG_DNET_SIZE - 1, .flags = IORESOURCE_MEM, }, { .start = QONG_FPGA_IRQ, .end = QONG_FPGA_IRQ, .flags = IORESOURCE_IRQ, }, }; static struct platform_device dnet_device = { .name = "dnet", .id = -1, .num_resources = ARRAY_SIZE(dnet_resources), .resource = dnet_resources, }; static int __init qong_init_dnet(void) { int ret; ret = platform_device_register(&dnet_device); return ret; } /* MTD NOR flash */ static struct physmap_flash_data qong_flash_data = { .width = 2, }; static struct resource qong_flash_resource = { .start = MX31_CS0_BASE_ADDR, .end = MX31_CS0_BASE_ADDR + SZ_128M - 1, .flags = IORESOURCE_MEM, }; static struct platform_device qong_nor_mtd_device = { .name = "physmap-flash", .id = 0, .dev = { .platform_data = &qong_flash_data, }, .resource = &qong_flash_resource, .num_resources = 1, }; static void qong_init_nor_mtd(void) { (void)platform_device_register(&qong_nor_mtd_device); } /* * Hardware specific access to control-lines */ static void qong_nand_cmd_ctrl(struct mtd_info *mtd, int cmd, unsigned int ctrl) { struct nand_chip *nand_chip = mtd->priv; if (cmd == NAND_CMD_NONE) return; if (ctrl & NAND_CLE) writeb(cmd, nand_chip->IO_ADDR_W + (1 << 24)); else writeb(cmd, nand_chip->IO_ADDR_W + (1 << 23)); } /* * Read the Device Ready pin. */ static int qong_nand_device_ready(struct mtd_info *mtd) { return gpio_get_value(IOMUX_TO_GPIO(MX31_PIN_NFRB)); } static void qong_nand_select_chip(struct mtd_info *mtd, int chip) { if (chip >= 0) gpio_set_value(IOMUX_TO_GPIO(MX31_PIN_NFCE_B), 0); else gpio_set_value(IOMUX_TO_GPIO(MX31_PIN_NFCE_B), 1); } static struct platform_nand_data qong_nand_data = { .chip = { .nr_chips = 1, .chip_delay = 20, .options = 0, }, .ctrl = { .cmd_ctrl = qong_nand_cmd_ctrl, .dev_ready = qong_nand_device_ready, .select_chip = qong_nand_select_chip, } }; static struct resource qong_nand_resource = { .start = MX31_CS3_BASE_ADDR, .end = MX31_CS3_BASE_ADDR + SZ_32M - 1, .flags = IORESOURCE_MEM, }; static struct platform_device qong_nand_device = { .name = "gen_nand", .id = -1, .dev = { .platform_data = &qong_nand_data, }, .num_resources = 1, .resource = &qong_nand_resource, }; static void __init qong_init_nand_mtd(void) { /* init CS */ __raw_writel(0x00004f00, MX31_IO_ADDRESS(MX31_WEIM_CSCRxU(3))); __raw_writel(0x20013b31, MX31_IO_ADDRESS(MX31_WEIM_CSCRxL(3))); __raw_writel(0x00020800, MX31_IO_ADDRESS(MX31_WEIM_CSCRxA(3))); mxc_iomux_set_gpr(MUX_SDCTL_CSD1_SEL, true); /* enable pin */ mxc_iomux_mode(IOMUX_MODE(MX31_PIN_NFCE_B, IOMUX_CONFIG_GPIO)); if (!gpio_request(IOMUX_TO_GPIO(MX31_PIN_NFCE_B), "nand_enable")) gpio_direction_output(IOMUX_TO_GPIO(MX31_PIN_NFCE_B), 0); /* ready/busy pin */ mxc_iomux_mode(IOMUX_MODE(MX31_PIN_NFRB, IOMUX_CONFIG_GPIO)); if (!gpio_request(IOMUX_TO_GPIO(MX31_PIN_NFRB), "nand_rdy")) gpio_direction_input(IOMUX_TO_GPIO(MX31_PIN_NFRB)); /* write protect pin */ mxc_iomux_mode(IOMUX_MODE(MX31_PIN_NFWP_B, IOMUX_CONFIG_GPIO)); if (!gpio_request(IOMUX_TO_GPIO(MX31_PIN_NFWP_B), "nand_wp")) gpio_direction_input(IOMUX_TO_GPIO(MX31_PIN_NFWP_B)); platform_device_register(&qong_nand_device); } static void __init qong_init_fpga(void) { void __iomem *regs; u32 fpga_ver; regs = ioremap(QONG_FPGA_CTRL_BASEADDR, QONG_FPGA_CTRL_SIZE); if (!regs) { printk(KERN_ERR "%s: failed to map registers, aborting.\n", __func__); return; } fpga_ver = readl(regs + QONG_FPGA_CTRL_VERSION); iounmap(regs); printk(KERN_INFO "Qong FPGA version %d.%d.%d\n", (fpga_ver & 0xF000) >> 12, (fpga_ver & 0x0F00) >> 8, fpga_ver & 0x00FF); if (fpga_ver < QONG_FPGA_VERSION(0, 8, 7)) { printk(KERN_ERR "qong: Unexpected FPGA version, FPGA-based " "devices won't be registered!\n"); return; } /* register FPGA-based devices */ qong_init_nand_mtd(); qong_init_dnet(); } /* * Board specific initialization. */ static void __init qong_init(void) { imx31_soc_init(); mxc_init_imx_uart(); qong_init_nor_mtd(); qong_init_fpga(); imx31_add_imx2_wdt(NULL); } static void __init qong_timer_init(void) { mx31_clocks_init(26000000); } static struct sys_timer qong_timer = { .init = qong_timer_init, }; MACHINE_START(QONG, "Dave/DENX QongEVB-LITE") /* Maintainer: DENX Software Engineering GmbH */ .atag_offset = 0x100, .map_io = mx31_map_io, .init_early = imx31_init_early, .init_irq = mx31_init_irq, .handle_irq = imx31_handle_irq, .timer = &qong_timer, .init_machine = qong_init, .restart = mxc_restart, MACHINE_END
gpl-2.0
sicknemesis/expectus_kernel_hammerhead
arch/arm/plat-spear/clock.c
5389
23857
/* * arch/arm/plat-spear/clock.c * * Clock framework for SPEAr platform * * Copyright (C) 2009 ST Microelectronics * Viresh Kumar<viresh.kumar@st.com> * * This file is licensed under the terms of the GNU General Public * License version 2. This program is licensed "as is" without any * warranty of any kind, whether express or implied. */ #include <linux/bug.h> #include <linux/clk.h> #include <linux/debugfs.h> #include <linux/err.h> #include <linux/io.h> #include <linux/list.h> #include <linux/module.h> #include <linux/spinlock.h> #include <plat/clock.h> static DEFINE_SPINLOCK(clocks_lock); static LIST_HEAD(root_clks); #ifdef CONFIG_DEBUG_FS static LIST_HEAD(clocks); #endif static void propagate_rate(struct clk *, int on_init); #ifdef CONFIG_DEBUG_FS static int clk_debugfs_reparent(struct clk *); #endif static int generic_clk_enable(struct clk *clk) { unsigned int val; if (!clk->en_reg) return -EFAULT; val = readl(clk->en_reg); if (unlikely(clk->flags & RESET_TO_ENABLE)) val &= ~(1 << clk->en_reg_bit); else val |= 1 << clk->en_reg_bit; writel(val, clk->en_reg); return 0; } static void generic_clk_disable(struct clk *clk) { unsigned int val; if (!clk->en_reg) return; val = readl(clk->en_reg); if (unlikely(clk->flags & RESET_TO_ENABLE)) val |= 1 << clk->en_reg_bit; else val &= ~(1 << clk->en_reg_bit); writel(val, clk->en_reg); } /* generic clk ops */ static struct clkops generic_clkops = { .enable = generic_clk_enable, .disable = generic_clk_disable, }; /* returns current programmed clocks clock info structure */ static struct pclk_info *pclk_info_get(struct clk *clk) { unsigned int val, i; struct pclk_info *info = NULL; val = (readl(clk->pclk_sel->pclk_sel_reg) >> clk->pclk_sel_shift) & clk->pclk_sel->pclk_sel_mask; for (i = 0; i < clk->pclk_sel->pclk_count; i++) { if (clk->pclk_sel->pclk_info[i].pclk_val == val) info = &clk->pclk_sel->pclk_info[i]; } return info; } /* * Set Update pclk, and pclk_info of clk and add clock sibling node to current * parents children list */ static void clk_reparent(struct clk *clk, struct pclk_info *pclk_info) { unsigned long flags; spin_lock_irqsave(&clocks_lock, flags); list_del(&clk->sibling); list_add(&clk->sibling, &pclk_info->pclk->children); clk->pclk = pclk_info->pclk; spin_unlock_irqrestore(&clocks_lock, flags); #ifdef CONFIG_DEBUG_FS clk_debugfs_reparent(clk); #endif } static void do_clk_disable(struct clk *clk) { if (!clk) return; if (!clk->usage_count) { WARN_ON(1); return; } clk->usage_count--; if (clk->usage_count == 0) { /* * Surely, there are no active childrens or direct users * of this clock */ if (clk->pclk) do_clk_disable(clk->pclk); if (clk->ops && clk->ops->disable) clk->ops->disable(clk); } } static int do_clk_enable(struct clk *clk) { int ret = 0; if (!clk) return -EFAULT; if (clk->usage_count == 0) { if (clk->pclk) { ret = do_clk_enable(clk->pclk); if (ret) goto err; } if (clk->ops && clk->ops->enable) { ret = clk->ops->enable(clk); if (ret) { if (clk->pclk) do_clk_disable(clk->pclk); goto err; } } /* * Since the clock is going to be used for the first * time please reclac */ if (clk->recalc) { ret = clk->recalc(clk); if (ret) goto err; } } clk->usage_count++; err: return ret; } /* * clk_enable - inform the system when the clock source should be running. * @clk: clock source * * If the clock can not be enabled/disabled, this should return success. * * Returns success (0) or negative errno. */ int clk_enable(struct clk *clk) { unsigned long flags; int ret = 0; spin_lock_irqsave(&clocks_lock, flags); ret = do_clk_enable(clk); spin_unlock_irqrestore(&clocks_lock, flags); return ret; } EXPORT_SYMBOL(clk_enable); /* * clk_disable - inform the system when the clock source is no longer required. * @clk: clock source * * Inform the system that a clock source is no longer required by * a driver and may be shut down. * * Implementation detail: if the clock source is shared between * multiple drivers, clk_enable() calls must be balanced by the * same number of clk_disable() calls for the clock source to be * disabled. */ void clk_disable(struct clk *clk) { unsigned long flags; spin_lock_irqsave(&clocks_lock, flags); do_clk_disable(clk); spin_unlock_irqrestore(&clocks_lock, flags); } EXPORT_SYMBOL(clk_disable); /** * clk_get_rate - obtain the current clock rate (in Hz) for a clock source. * This is only valid once the clock source has been enabled. * @clk: clock source */ unsigned long clk_get_rate(struct clk *clk) { unsigned long flags, rate; spin_lock_irqsave(&clocks_lock, flags); rate = clk->rate; spin_unlock_irqrestore(&clocks_lock, flags); return rate; } EXPORT_SYMBOL(clk_get_rate); /** * clk_set_parent - set the parent clock source for this clock * @clk: clock source * @parent: parent clock source * * Returns success (0) or negative errno. */ int clk_set_parent(struct clk *clk, struct clk *parent) { int i, found = 0, val = 0; unsigned long flags; if (!clk || !parent) return -EFAULT; if (clk->pclk == parent) return 0; if (!clk->pclk_sel) return -EPERM; /* check if requested parent is in clk parent list */ for (i = 0; i < clk->pclk_sel->pclk_count; i++) { if (clk->pclk_sel->pclk_info[i].pclk == parent) { found = 1; break; } } if (!found) return -EINVAL; spin_lock_irqsave(&clocks_lock, flags); /* reflect parent change in hardware */ val = readl(clk->pclk_sel->pclk_sel_reg); val &= ~(clk->pclk_sel->pclk_sel_mask << clk->pclk_sel_shift); val |= clk->pclk_sel->pclk_info[i].pclk_val << clk->pclk_sel_shift; writel(val, clk->pclk_sel->pclk_sel_reg); spin_unlock_irqrestore(&clocks_lock, flags); /* reflect parent change in software */ clk_reparent(clk, &clk->pclk_sel->pclk_info[i]); propagate_rate(clk, 0); return 0; } EXPORT_SYMBOL(clk_set_parent); /** * clk_set_rate - set the clock rate for a clock source * @clk: clock source * @rate: desired clock rate in Hz * * Returns success (0) or negative errno. */ int clk_set_rate(struct clk *clk, unsigned long rate) { unsigned long flags; int ret = -EINVAL; if (!clk || !rate) return -EFAULT; if (clk->set_rate) { spin_lock_irqsave(&clocks_lock, flags); ret = clk->set_rate(clk, rate); if (!ret) /* if successful -> propagate */ propagate_rate(clk, 0); spin_unlock_irqrestore(&clocks_lock, flags); } else if (clk->pclk) { u32 mult = clk->div_factor ? clk->div_factor : 1; ret = clk_set_rate(clk->pclk, mult * rate); } return ret; } EXPORT_SYMBOL(clk_set_rate); /* registers clock in platform clock framework */ void clk_register(struct clk_lookup *cl) { struct clk *clk; unsigned long flags; if (!cl || !cl->clk) return; clk = cl->clk; spin_lock_irqsave(&clocks_lock, flags); INIT_LIST_HEAD(&clk->children); if (clk->flags & ALWAYS_ENABLED) clk->ops = NULL; else if (!clk->ops) clk->ops = &generic_clkops; /* root clock don't have any parents */ if (!clk->pclk && !clk->pclk_sel) { list_add(&clk->sibling, &root_clks); } else if (clk->pclk && !clk->pclk_sel) { /* add clocks with only one parent to parent's children list */ list_add(&clk->sibling, &clk->pclk->children); } else { /* clocks with more than one parent */ struct pclk_info *pclk_info; pclk_info = pclk_info_get(clk); if (!pclk_info) { pr_err("CLKDEV: invalid pclk info of clk with" " %s dev_id and %s con_id\n", cl->dev_id, cl->con_id); } else { clk->pclk = pclk_info->pclk; list_add(&clk->sibling, &pclk_info->pclk->children); } } spin_unlock_irqrestore(&clocks_lock, flags); /* debugfs specific */ #ifdef CONFIG_DEBUG_FS list_add(&clk->node, &clocks); clk->cl = cl; #endif /* add clock to arm clockdev framework */ clkdev_add(cl); } /** * propagate_rate - recalculate and propagate all clocks to children * @pclk: parent clock required to be propogated * @on_init: flag for enabling clocks which are ENABLED_ON_INIT. * * Recalculates all children clocks */ void propagate_rate(struct clk *pclk, int on_init) { struct clk *clk, *_temp; int ret = 0; list_for_each_entry_safe(clk, _temp, &pclk->children, sibling) { if (clk->recalc) { ret = clk->recalc(clk); /* * recalc will return error if clk out is not programmed * In this case configure default rate. */ if (ret && clk->set_rate) clk->set_rate(clk, 0); } propagate_rate(clk, on_init); if (!on_init) continue; /* Enable clks enabled on init, in software view */ if (clk->flags & ENABLED_ON_INIT) do_clk_enable(clk); } } /** * round_rate_index - return closest programmable rate index in rate_config tbl * @clk: ptr to clock structure * @drate: desired rate * @rate: final rate will be returned in this variable only. * * Finds index in rate_config for highest clk rate which is less than * requested rate. If there is no clk rate lesser than requested rate then * -EINVAL is returned. This routine assumes that rate_config is written * in incrementing order of clk rates. * If drate passed is zero then default rate is programmed. */ static int round_rate_index(struct clk *clk, unsigned long drate, unsigned long *rate) { unsigned long tmp = 0, prev_rate = 0; int index; if (!clk->calc_rate) return -EFAULT; if (!drate) return -EINVAL; /* * This loops ends on two conditions: * - as soon as clk is found with rate greater than requested rate. * - if all clks in rate_config are smaller than requested rate. */ for (index = 0; index < clk->rate_config.count; index++) { prev_rate = tmp; tmp = clk->calc_rate(clk, index); if (drate < tmp) { index--; break; } } /* return if can't find suitable clock */ if (index < 0) { index = -EINVAL; *rate = 0; } else if (index == clk->rate_config.count) { /* program with highest clk rate possible */ index = clk->rate_config.count - 1; *rate = tmp; } else *rate = prev_rate; return index; } /** * clk_round_rate - adjust a rate to the exact rate a clock can provide * @clk: clock source * @rate: desired clock rate in Hz * * Returns rounded clock rate in Hz, or negative errno. */ long clk_round_rate(struct clk *clk, unsigned long drate) { long rate = 0; int index; /* * propagate call to parent who supports calc_rate. Similar approach is * used in clk_set_rate. */ if (!clk->calc_rate) { u32 mult; if (!clk->pclk) return clk->rate; mult = clk->div_factor ? clk->div_factor : 1; return clk_round_rate(clk->pclk, mult * drate) / mult; } index = round_rate_index(clk, drate, &rate); if (index >= 0) return rate; else return index; } EXPORT_SYMBOL(clk_round_rate); /*All below functions are called with lock held */ /* * Calculates pll clk rate for specific value of mode, m, n and p * * In normal mode * rate = (2 * M[15:8] * Fin)/(N * 2^P) * * In Dithered mode * rate = (2 * M[15:0] * Fin)/(256 * N * 2^P) */ unsigned long pll_calc_rate(struct clk *clk, int index) { unsigned long rate = clk->pclk->rate; struct pll_rate_tbl *tbls = clk->rate_config.tbls; unsigned int mode; mode = tbls[index].mode ? 256 : 1; return (((2 * rate / 10000) * tbls[index].m) / (mode * tbls[index].n * (1 << tbls[index].p))) * 10000; } /* * calculates current programmed rate of pll1 * * In normal mode * rate = (2 * M[15:8] * Fin)/(N * 2^P) * * In Dithered mode * rate = (2 * M[15:0] * Fin)/(256 * N * 2^P) */ int pll_clk_recalc(struct clk *clk) { struct pll_clk_config *config = clk->private_data; unsigned int num = 2, den = 0, val, mode = 0; mode = (readl(config->mode_reg) >> config->masks->mode_shift) & config->masks->mode_mask; val = readl(config->cfg_reg); /* calculate denominator */ den = (val >> config->masks->div_p_shift) & config->masks->div_p_mask; den = 1 << den; den *= (val >> config->masks->div_n_shift) & config->masks->div_n_mask; /* calculate numerator & denominator */ if (!mode) { /* Normal mode */ num *= (val >> config->masks->norm_fdbk_m_shift) & config->masks->norm_fdbk_m_mask; } else { /* Dithered mode */ num *= (val >> config->masks->dith_fdbk_m_shift) & config->masks->dith_fdbk_m_mask; den *= 256; } if (!den) return -EINVAL; clk->rate = (((clk->pclk->rate/10000) * num) / den) * 10000; return 0; } /* * Configures new clock rate of pll */ int pll_clk_set_rate(struct clk *clk, unsigned long desired_rate) { struct pll_rate_tbl *tbls = clk->rate_config.tbls; struct pll_clk_config *config = clk->private_data; unsigned long val, rate; int i; i = round_rate_index(clk, desired_rate, &rate); if (i < 0) return i; val = readl(config->mode_reg) & ~(config->masks->mode_mask << config->masks->mode_shift); val |= (tbls[i].mode & config->masks->mode_mask) << config->masks->mode_shift; writel(val, config->mode_reg); val = readl(config->cfg_reg) & ~(config->masks->div_p_mask << config->masks->div_p_shift); val |= (tbls[i].p & config->masks->div_p_mask) << config->masks->div_p_shift; val &= ~(config->masks->div_n_mask << config->masks->div_n_shift); val |= (tbls[i].n & config->masks->div_n_mask) << config->masks->div_n_shift; val &= ~(config->masks->dith_fdbk_m_mask << config->masks->dith_fdbk_m_shift); if (tbls[i].mode) val |= (tbls[i].m & config->masks->dith_fdbk_m_mask) << config->masks->dith_fdbk_m_shift; else val |= (tbls[i].m & config->masks->norm_fdbk_m_mask) << config->masks->norm_fdbk_m_shift; writel(val, config->cfg_reg); clk->rate = rate; return 0; } /* * Calculates ahb, apb clk rate for specific value of div */ unsigned long bus_calc_rate(struct clk *clk, int index) { unsigned long rate = clk->pclk->rate; struct bus_rate_tbl *tbls = clk->rate_config.tbls; return rate / (tbls[index].div + 1); } /* calculates current programmed rate of ahb or apb bus */ int bus_clk_recalc(struct clk *clk) { struct bus_clk_config *config = clk->private_data; unsigned int div; div = ((readl(config->reg) >> config->masks->shift) & config->masks->mask) + 1; if (!div) return -EINVAL; clk->rate = (unsigned long)clk->pclk->rate / div; return 0; } /* Configures new clock rate of AHB OR APB bus */ int bus_clk_set_rate(struct clk *clk, unsigned long desired_rate) { struct bus_rate_tbl *tbls = clk->rate_config.tbls; struct bus_clk_config *config = clk->private_data; unsigned long val, rate; int i; i = round_rate_index(clk, desired_rate, &rate); if (i < 0) return i; val = readl(config->reg) & ~(config->masks->mask << config->masks->shift); val |= (tbls[i].div & config->masks->mask) << config->masks->shift; writel(val, config->reg); clk->rate = rate; return 0; } /* * gives rate for different values of eq, x and y * * Fout from synthesizer can be given from two equations: * Fout1 = (Fin * X/Y)/2 EQ1 * Fout2 = Fin * X/Y EQ2 */ unsigned long aux_calc_rate(struct clk *clk, int index) { unsigned long rate = clk->pclk->rate; struct aux_rate_tbl *tbls = clk->rate_config.tbls; u8 eq = tbls[index].eq ? 1 : 2; return (((rate/10000) * tbls[index].xscale) / (tbls[index].yscale * eq)) * 10000; } /* * calculates current programmed rate of auxiliary synthesizers * used by: UART, FIRDA * * Fout from synthesizer can be given from two equations: * Fout1 = (Fin * X/Y)/2 * Fout2 = Fin * X/Y * * Selection of eqn 1 or 2 is programmed in register */ int aux_clk_recalc(struct clk *clk) { struct aux_clk_config *config = clk->private_data; unsigned int num = 1, den = 1, val, eqn; val = readl(config->synth_reg); eqn = (val >> config->masks->eq_sel_shift) & config->masks->eq_sel_mask; if (eqn == config->masks->eq1_mask) den *= 2; /* calculate numerator */ num = (val >> config->masks->xscale_sel_shift) & config->masks->xscale_sel_mask; /* calculate denominator */ den *= (val >> config->masks->yscale_sel_shift) & config->masks->yscale_sel_mask; if (!den) return -EINVAL; clk->rate = (((clk->pclk->rate/10000) * num) / den) * 10000; return 0; } /* Configures new clock rate of auxiliary synthesizers used by: UART, FIRDA*/ int aux_clk_set_rate(struct clk *clk, unsigned long desired_rate) { struct aux_rate_tbl *tbls = clk->rate_config.tbls; struct aux_clk_config *config = clk->private_data; unsigned long val, rate; int i; i = round_rate_index(clk, desired_rate, &rate); if (i < 0) return i; val = readl(config->synth_reg) & ~(config->masks->eq_sel_mask << config->masks->eq_sel_shift); val |= (tbls[i].eq & config->masks->eq_sel_mask) << config->masks->eq_sel_shift; val &= ~(config->masks->xscale_sel_mask << config->masks->xscale_sel_shift); val |= (tbls[i].xscale & config->masks->xscale_sel_mask) << config->masks->xscale_sel_shift; val &= ~(config->masks->yscale_sel_mask << config->masks->yscale_sel_shift); val |= (tbls[i].yscale & config->masks->yscale_sel_mask) << config->masks->yscale_sel_shift; writel(val, config->synth_reg); clk->rate = rate; return 0; } /* * Calculates gpt clk rate for different values of mscale and nscale * * Fout= Fin/((2 ^ (N+1)) * (M+1)) */ unsigned long gpt_calc_rate(struct clk *clk, int index) { unsigned long rate = clk->pclk->rate; struct gpt_rate_tbl *tbls = clk->rate_config.tbls; return rate / ((1 << (tbls[index].nscale + 1)) * (tbls[index].mscale + 1)); } /* * calculates current programmed rate of gpt synthesizers * Fout from synthesizer can be given from below equations: * Fout= Fin/((2 ^ (N+1)) * (M+1)) */ int gpt_clk_recalc(struct clk *clk) { struct gpt_clk_config *config = clk->private_data; unsigned int div = 1, val; val = readl(config->synth_reg); div += (val >> config->masks->mscale_sel_shift) & config->masks->mscale_sel_mask; div *= 1 << (((val >> config->masks->nscale_sel_shift) & config->masks->nscale_sel_mask) + 1); if (!div) return -EINVAL; clk->rate = (unsigned long)clk->pclk->rate / div; return 0; } /* Configures new clock rate of gptiliary synthesizers used by: UART, FIRDA*/ int gpt_clk_set_rate(struct clk *clk, unsigned long desired_rate) { struct gpt_rate_tbl *tbls = clk->rate_config.tbls; struct gpt_clk_config *config = clk->private_data; unsigned long val, rate; int i; i = round_rate_index(clk, desired_rate, &rate); if (i < 0) return i; val = readl(config->synth_reg) & ~(config->masks->mscale_sel_mask << config->masks->mscale_sel_shift); val |= (tbls[i].mscale & config->masks->mscale_sel_mask) << config->masks->mscale_sel_shift; val &= ~(config->masks->nscale_sel_mask << config->masks->nscale_sel_shift); val |= (tbls[i].nscale & config->masks->nscale_sel_mask) << config->masks->nscale_sel_shift; writel(val, config->synth_reg); clk->rate = rate; return 0; } /* * Calculates clcd clk rate for different values of div * * Fout from synthesizer can be given from below equation: * Fout= Fin/2*div (division factor) * div is 17 bits:- * 0-13 (fractional part) * 14-16 (integer part) * To calculate Fout we left shift val by 14 bits and divide Fin by * complete div (including fractional part) and then right shift the * result by 14 places. */ unsigned long clcd_calc_rate(struct clk *clk, int index) { unsigned long rate = clk->pclk->rate; struct clcd_rate_tbl *tbls = clk->rate_config.tbls; rate /= 1000; rate <<= 12; rate /= (2 * tbls[index].div); rate >>= 12; rate *= 1000; return rate; } /* * calculates current programmed rate of clcd synthesizer * Fout from synthesizer can be given from below equation: * Fout= Fin/2*div (division factor) * div is 17 bits:- * 0-13 (fractional part) * 14-16 (integer part) * To calculate Fout we left shift val by 14 bits and divide Fin by * complete div (including fractional part) and then right shift the * result by 14 places. */ int clcd_clk_recalc(struct clk *clk) { struct clcd_clk_config *config = clk->private_data; unsigned int div = 1; unsigned long prate; unsigned int val; val = readl(config->synth_reg); div = (val >> config->masks->div_factor_shift) & config->masks->div_factor_mask; if (!div) return -EINVAL; prate = clk->pclk->rate / 1000; /* first level division, make it KHz */ clk->rate = (((unsigned long)prate << 12) / (2 * div)) >> 12; clk->rate *= 1000; return 0; } /* Configures new clock rate of auxiliary synthesizers used by: UART, FIRDA*/ int clcd_clk_set_rate(struct clk *clk, unsigned long desired_rate) { struct clcd_rate_tbl *tbls = clk->rate_config.tbls; struct clcd_clk_config *config = clk->private_data; unsigned long val, rate; int i; i = round_rate_index(clk, desired_rate, &rate); if (i < 0) return i; val = readl(config->synth_reg) & ~(config->masks->div_factor_mask << config->masks->div_factor_shift); val |= (tbls[i].div & config->masks->div_factor_mask) << config->masks->div_factor_shift; writel(val, config->synth_reg); clk->rate = rate; return 0; } /* * Used for clocks that always have value as the parent clock divided by a * fixed divisor */ int follow_parent(struct clk *clk) { unsigned int div_factor = (clk->div_factor < 1) ? 1 : clk->div_factor; clk->rate = clk->pclk->rate/div_factor; return 0; } /** * recalc_root_clocks - recalculate and propagate all root clocks * * Recalculates all root clocks (clocks with no parent), which if the * clock's .recalc is set correctly, should also propagate their rates. */ void recalc_root_clocks(void) { struct clk *pclk; unsigned long flags; int ret = 0; spin_lock_irqsave(&clocks_lock, flags); list_for_each_entry(pclk, &root_clks, sibling) { if (pclk->recalc) { ret = pclk->recalc(pclk); /* * recalc will return error if clk out is not programmed * In this case configure default clock. */ if (ret && pclk->set_rate) pclk->set_rate(pclk, 0); } propagate_rate(pclk, 1); /* Enable clks enabled on init, in software view */ if (pclk->flags & ENABLED_ON_INIT) do_clk_enable(pclk); } spin_unlock_irqrestore(&clocks_lock, flags); } void __init clk_init(void) { recalc_root_clocks(); } #ifdef CONFIG_DEBUG_FS /* * debugfs support to trace clock tree hierarchy and attributes */ static struct dentry *clk_debugfs_root; static int clk_debugfs_register_one(struct clk *c) { int err; struct dentry *d; struct clk *pa = c->pclk; char s[255]; char *p = s; if (c) { if (c->cl->con_id) p += sprintf(p, "%s", c->cl->con_id); if (c->cl->dev_id) p += sprintf(p, "%s", c->cl->dev_id); } d = debugfs_create_dir(s, pa ? pa->dent : clk_debugfs_root); if (!d) return -ENOMEM; c->dent = d; d = debugfs_create_u32("usage_count", S_IRUGO, c->dent, (u32 *)&c->usage_count); if (!d) { err = -ENOMEM; goto err_out; } d = debugfs_create_u32("rate", S_IRUGO, c->dent, (u32 *)&c->rate); if (!d) { err = -ENOMEM; goto err_out; } d = debugfs_create_x32("flags", S_IRUGO, c->dent, (u32 *)&c->flags); if (!d) { err = -ENOMEM; goto err_out; } return 0; err_out: debugfs_remove_recursive(c->dent); return err; } static int clk_debugfs_register(struct clk *c) { int err; struct clk *pa = c->pclk; if (pa && !pa->dent) { err = clk_debugfs_register(pa); if (err) return err; } if (!c->dent) { err = clk_debugfs_register_one(c); if (err) return err; } return 0; } static int __init clk_debugfs_init(void) { struct clk *c; struct dentry *d; int err; d = debugfs_create_dir("clock", NULL); if (!d) return -ENOMEM; clk_debugfs_root = d; list_for_each_entry(c, &clocks, node) { err = clk_debugfs_register(c); if (err) goto err_out; } return 0; err_out: debugfs_remove_recursive(clk_debugfs_root); return err; } late_initcall(clk_debugfs_init); static int clk_debugfs_reparent(struct clk *c) { debugfs_remove(c->dent); return clk_debugfs_register_one(c); } #endif /* CONFIG_DEBUG_FS */
gpl-2.0
Pafcholini/emotion_tw_caf_kernel
drivers/isdn/hardware/eicon/debuglib.c
9741
4506
/* * Copyright (c) Eicon Networks, 2002. * This source file is supplied for the use with Eicon Networks range of DIVA Server Adapters. * Eicon File Revision : 2.1 * This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY OF ANY KIND WHATSOEVER INCLUDING ANY implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. * You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * */ #include "debuglib.h" #ifdef DIVA_NO_DEBUGLIB static DIVA_DI_PRINTF dprintf; #else /* DIVA_NO_DEBUGLIB */ _DbgHandle_ myDriverDebugHandle = { 0 /*!Registered*/, DBG_HANDLE_VERSION }; DIVA_DI_PRINTF dprintf = no_printf; /*****************************************************************************/ #define DBG_FUNC(name) \ void \ myDbgPrint_##name(char *format, ...) \ { va_list ap; \ if (myDriverDebugHandle.dbg_prt) \ { va_start(ap, format); \ (myDriverDebugHandle.dbg_prt) \ (myDriverDebugHandle.id, DLI_##name, format, ap); \ va_end(ap); \ } } DBG_FUNC(LOG) DBG_FUNC(FTL) DBG_FUNC(ERR) DBG_FUNC(TRC) DBG_FUNC(MXLOG) DBG_FUNC(FTL_MXLOG) void myDbgPrint_EVL(long msgID, ...) { va_list ap; if (myDriverDebugHandle.dbg_ev) { va_start(ap, msgID); (myDriverDebugHandle.dbg_ev) (myDriverDebugHandle.id, (unsigned long)msgID, ap); va_end(ap); } } DBG_FUNC(REG) DBG_FUNC(MEM) DBG_FUNC(SPL) DBG_FUNC(IRP) DBG_FUNC(TIM) DBG_FUNC(BLK) DBG_FUNC(TAPI) DBG_FUNC(NDIS) DBG_FUNC(CONN) DBG_FUNC(STAT) DBG_FUNC(SEND) DBG_FUNC(RECV) DBG_FUNC(PRV0) DBG_FUNC(PRV1) DBG_FUNC(PRV2) DBG_FUNC(PRV3) /*****************************************************************************/ int DbgRegister(char *drvName, char *drvTag, unsigned long dbgMask) { int len; /* * deregister (if already registered) and zero out myDriverDebugHandle */ DbgDeregister(); /* * initialize the debug handle */ myDriverDebugHandle.Version = DBG_HANDLE_VERSION; myDriverDebugHandle.id = -1; myDriverDebugHandle.dbgMask = dbgMask | (DL_EVL | DL_FTL | DL_LOG); len = strlen(drvName); memcpy(myDriverDebugHandle.drvName, drvName, (len < sizeof(myDriverDebugHandle.drvName)) ? len : sizeof(myDriverDebugHandle.drvName) - 1); len = strlen(drvTag); memcpy(myDriverDebugHandle.drvTag, drvTag, (len < sizeof(myDriverDebugHandle.drvTag)) ? len : sizeof(myDriverDebugHandle.drvTag) - 1); /* * Try to register debugging via old (and only) interface */ dprintf("\000\377", &myDriverDebugHandle); if (myDriverDebugHandle.dbg_prt) { return (1); } /* * Check if we registered with an old maint driver (see debuglib.h) */ if (myDriverDebugHandle.dbg_end != NULL /* location of 'dbg_prt' in _OldDbgHandle_ struct */ && (myDriverDebugHandle.regTime.LowPart || myDriverDebugHandle.regTime.HighPart)) /* same location as in _OldDbgHandle_ struct */ { dprintf("%s: Cannot log to old maint driver !", drvName); myDriverDebugHandle.dbg_end = ((_OldDbgHandle_ *)&myDriverDebugHandle)->dbg_end; DbgDeregister(); } return (0); } /*****************************************************************************/ void DbgSetLevel(unsigned long dbgMask) { myDriverDebugHandle.dbgMask = dbgMask | (DL_EVL | DL_FTL | DL_LOG); } /*****************************************************************************/ void DbgDeregister(void) { if (myDriverDebugHandle.dbg_end) { (myDriverDebugHandle.dbg_end)(&myDriverDebugHandle); } memset(&myDriverDebugHandle, 0, sizeof(myDriverDebugHandle)); } void xdi_dbg_xlog(char *x, ...) { va_list ap; va_start(ap, x); if (myDriverDebugHandle.dbg_end && (myDriverDebugHandle.dbg_irq || myDriverDebugHandle.dbg_old) && (myDriverDebugHandle.dbgMask & DL_STAT)) { if (myDriverDebugHandle.dbg_irq) { (*(myDriverDebugHandle.dbg_irq))(myDriverDebugHandle.id, (x[0] != 0) ? DLI_TRC : DLI_XLOG, x, ap); } else { (*(myDriverDebugHandle.dbg_old))(myDriverDebugHandle.id, x, ap); } } va_end(ap); } /*****************************************************************************/ #endif /* DIVA_NO_DEBUGLIB */
gpl-2.0
yajnab/android_kernel_sony_taoshan
arch/powerpc/oprofile/backtrace.c
10509
2953
/** * Copyright (C) 2005 Brian Rogan <bcr6@cornell.edu>, IBM * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version * 2 of the License, or (at your option) any later version. **/ #include <linux/oprofile.h> #include <linux/sched.h> #include <asm/processor.h> #include <asm/uaccess.h> #include <asm/compat.h> #define STACK_SP(STACK) *(STACK) #define STACK_LR64(STACK) *((unsigned long *)(STACK) + 2) #define STACK_LR32(STACK) *((unsigned int *)(STACK) + 1) #ifdef CONFIG_PPC64 #define STACK_LR(STACK) STACK_LR64(STACK) #else #define STACK_LR(STACK) STACK_LR32(STACK) #endif static unsigned int user_getsp32(unsigned int sp, int is_first) { unsigned int stack_frame[2]; void __user *p = compat_ptr(sp); if (!access_ok(VERIFY_READ, p, sizeof(stack_frame))) return 0; /* * The most likely reason for this is that we returned -EFAULT, * which means that we've done all that we can do from * interrupt context. */ if (__copy_from_user_inatomic(stack_frame, p, sizeof(stack_frame))) return 0; if (!is_first) oprofile_add_trace(STACK_LR32(stack_frame)); /* * We do not enforce increasing stack addresses here because * we may transition to a different stack, eg a signal handler. */ return STACK_SP(stack_frame); } #ifdef CONFIG_PPC64 static unsigned long user_getsp64(unsigned long sp, int is_first) { unsigned long stack_frame[3]; if (!access_ok(VERIFY_READ, (void __user *)sp, sizeof(stack_frame))) return 0; if (__copy_from_user_inatomic(stack_frame, (void __user *)sp, sizeof(stack_frame))) return 0; if (!is_first) oprofile_add_trace(STACK_LR64(stack_frame)); return STACK_SP(stack_frame); } #endif static unsigned long kernel_getsp(unsigned long sp, int is_first) { unsigned long *stack_frame = (unsigned long *)sp; if (!validate_sp(sp, current, STACK_FRAME_OVERHEAD)) return 0; if (!is_first) oprofile_add_trace(STACK_LR(stack_frame)); /* * We do not enforce increasing stack addresses here because * we might be transitioning from an interrupt stack to a kernel * stack. validate_sp() is designed to understand this, so just * use it. */ return STACK_SP(stack_frame); } void op_powerpc_backtrace(struct pt_regs * const regs, unsigned int depth) { unsigned long sp = regs->gpr[1]; int first_frame = 1; /* We ditch the top stackframe so need to loop through an extra time */ depth += 1; if (!user_mode(regs)) { while (depth--) { sp = kernel_getsp(sp, first_frame); if (!sp) break; first_frame = 0; } } else { #ifdef CONFIG_PPC64 if (!is_32bit_task()) { while (depth--) { sp = user_getsp64(sp, first_frame); if (!sp) break; first_frame = 0; } return; } #endif while (depth--) { sp = user_getsp32(sp, first_frame); if (!sp) break; first_frame = 0; } } }
gpl-2.0
gromaudio/linux-imx6
drivers/media/video/mxc/capture/csi_v4l2_capture.c
14
35774
/* * Copyright 2009-2011 Freescale Semiconductor, Inc. All Rights Reserved. */ /* * The code contained herein is licensed under the GNU General Public * License. You may obtain a copy of the GNU General Public License * Version 2 or later at the following locations: * * http://www.opensource.org/licenses/gpl-license.html * http://www.gnu.org/copyleft/gpl.html */ /*! * @file drivers/media/video/mxc/capture/csi_v4l2_capture.c * This file is derived from mxc_v4l2_capture.c * * @brief MX25 Video For Linux 2 driver * * @ingroup MXC_V4L2_CAPTURE */ #include <linux/version.h> #include <linux/module.h> #include <linux/init.h> #include <linux/platform_device.h> #include <linux/fs.h> #include <linux/slab.h> #include <linux/ctype.h> #include <linux/io.h> #include <linux/semaphore.h> #include <linux/pagemap.h> #include <linux/vmalloc.h> #include <linux/types.h> #include <linux/fb.h> #include <linux/dma-mapping.h> #include <media/v4l2-ioctl.h> #include <media/v4l2-int-device.h> #include <linux/mxcfb.h> #include "mxc_v4l2_capture.h" #include "fsl_csi.h" static int video_nr = -1; static cam_data *g_cam; static int csi_v4l2_master_attach(struct v4l2_int_device *slave); static void csi_v4l2_master_detach(struct v4l2_int_device *slave); static u8 camera_power(cam_data *cam, bool cameraOn); /*! Information about this driver. */ static struct v4l2_int_master csi_v4l2_master = { .attach = csi_v4l2_master_attach, .detach = csi_v4l2_master_detach, }; static struct v4l2_int_device csi_v4l2_int_device = { .module = THIS_MODULE, .name = "csi_v4l2_cap", .type = v4l2_int_type_master, .u = { .master = &csi_v4l2_master, }, }; /*! * Camera V4l2 callback function. * * @param mask u32 * @param dev void device structure * * @return none */ static void camera_callback(u32 mask, void *dev) { struct mxc_v4l_frame *done_frame; struct mxc_v4l_frame *ready_frame; cam_data *cam; cam = (cam_data *) dev; if (cam == NULL) return; if (list_empty(&cam->working_q)) { pr_err("ERROR: v4l2 capture: %s: " "working queue empty\n", __func__); return; } done_frame = list_entry(cam->working_q.next, struct mxc_v4l_frame, queue); if (done_frame->buffer.flags & V4L2_BUF_FLAG_QUEUED) { done_frame->buffer.flags |= V4L2_BUF_FLAG_DONE; done_frame->buffer.flags &= ~V4L2_BUF_FLAG_QUEUED; if (list_empty(&cam->ready_q)) { cam->skip_frame++; } else { ready_frame = list_entry(cam->ready_q.next, struct mxc_v4l_frame, queue); list_del(cam->ready_q.next); list_add_tail(&ready_frame->queue, &cam->working_q); if (cam->ping_pong_csi == 1) { __raw_writel(cam->frame[ready_frame->index]. paddress, CSI_CSIDMASA_FB1); } else { __raw_writel(cam->frame[ready_frame->index]. paddress, CSI_CSIDMASA_FB2); } } /* Added to the done queue */ list_del(cam->working_q.next); list_add_tail(&done_frame->queue, &cam->done_q); cam->enc_counter++; wake_up_interruptible(&cam->enc_queue); } else { pr_err("ERROR: v4l2 capture: %s: " "buffer not queued\n", __func__); } return; } /*! * Make csi ready for capture image. * * @param cam structure cam_data * * * @return status 0 success */ static int csi_cap_image(cam_data *cam) { unsigned int value; value = __raw_readl(CSI_CSICR3); __raw_writel(value | BIT_DMA_REFLASH_RFF | BIT_FRMCNT_RST, CSI_CSICR3); value = __raw_readl(CSI_CSISR); __raw_writel(value, CSI_CSISR); return 0; } /*************************************************************************** * Functions for handling Frame buffers. **************************************************************************/ /*! * Free frame buffers * * @param cam Structure cam_data * * * @return status 0 success. */ static int csi_free_frame_buf(cam_data *cam) { int i; pr_debug("MVC: In %s\n", __func__); for (i = 0; i < FRAME_NUM; i++) { if (cam->frame[i].vaddress != 0) { dma_free_coherent(0, cam->frame[i].buffer.length, cam->frame[i].vaddress, cam->frame[i].paddress); cam->frame[i].vaddress = 0; } } return 0; } /*! * Allocate frame buffers * * @param cam Structure cam_data * * @param count int number of buffer need to allocated * * @return status -0 Successfully allocated a buffer, -ENOBUFS failed. */ static int csi_allocate_frame_buf(cam_data *cam, int count) { int i; pr_debug("In MVC:%s- size=%d\n", __func__, cam->v2f.fmt.pix.sizeimage); for (i = 0; i < count; i++) { cam->frame[i].vaddress = dma_alloc_coherent(0, PAGE_ALIGN (cam->v2f.fmt. pix.sizeimage), &cam->frame[i]. paddress, GFP_DMA | GFP_KERNEL); if (cam->frame[i].vaddress == 0) { pr_err("ERROR: v4l2 capture: " "%s failed.\n", __func__); csi_free_frame_buf(cam); return -ENOBUFS; } cam->frame[i].buffer.index = i; cam->frame[i].buffer.flags = V4L2_BUF_FLAG_MAPPED; cam->frame[i].buffer.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; cam->frame[i].buffer.length = PAGE_ALIGN(cam->v2f.fmt. pix.sizeimage); cam->frame[i].buffer.memory = V4L2_MEMORY_MMAP; cam->frame[i].buffer.m.offset = cam->frame[i].paddress; cam->frame[i].index = i; } return 0; } /*! * Free frame buffers status * * @param cam Structure cam_data * * * @return none */ static void csi_free_frames(cam_data *cam) { int i; pr_debug("In MVC: %s\n", __func__); for (i = 0; i < FRAME_NUM; i++) cam->frame[i].buffer.flags = V4L2_BUF_FLAG_MAPPED; cam->skip_frame = 0; INIT_LIST_HEAD(&cam->ready_q); INIT_LIST_HEAD(&cam->working_q); INIT_LIST_HEAD(&cam->done_q); return; } /*! * Return the buffer status * * @param cam Structure cam_data * * @param buf Structure v4l2_buffer * * * @return status 0 success, EINVAL failed. */ static int csi_v4l2_buffer_status(cam_data *cam, struct v4l2_buffer *buf) { pr_debug("In MVC: %s\n", __func__); if (buf->index < 0 || buf->index >= FRAME_NUM) { pr_err("ERROR: v4l2 capture: %s buffers " "not allocated\n", __func__); return -EINVAL; } memcpy(buf, &(cam->frame[buf->index].buffer), sizeof(*buf)); return 0; } /*! * Indicates whether the palette is supported. * * @param palette V4L2_PIX_FMT_RGB565, V4L2_PIX_FMT_UYVY or V4L2_PIX_FMT_YUV420 * * @return 0 if failed */ static inline int valid_mode(u32 palette) { return (palette == V4L2_PIX_FMT_RGB565) || (palette == V4L2_PIX_FMT_UYVY) || (palette == V4L2_PIX_FMT_YUV420); } /*! * Start stream I/O * * @param cam structure cam_data * * * @return status 0 Success */ static int csi_streamon(cam_data *cam) { struct mxc_v4l_frame *frame; pr_debug("In MVC: %s\n", __func__); if (NULL == cam) { pr_err("ERROR: v4l2 capture: %s cam parameter is NULL\n", __func__); return -1; } /* move the frame from readyq to workingq */ if (list_empty(&cam->ready_q)) { pr_err("ERROR: v4l2 capture: %s: " "ready_q queue empty\n", __func__); return -1; } frame = list_entry(cam->ready_q.next, struct mxc_v4l_frame, queue); list_del(cam->ready_q.next); list_add_tail(&frame->queue, &cam->working_q); __raw_writel(cam->frame[frame->index].paddress, CSI_CSIDMASA_FB1); if (list_empty(&cam->ready_q)) { pr_err("ERROR: v4l2 capture: %s: " "ready_q queue empty\n", __func__); return -1; } frame = list_entry(cam->ready_q.next, struct mxc_v4l_frame, queue); list_del(cam->ready_q.next); list_add_tail(&frame->queue, &cam->working_q); __raw_writel(cam->frame[frame->index].paddress, CSI_CSIDMASA_FB2); cam->capture_pid = current->pid; cam->capture_on = true; csi_cap_image(cam); csi_enable_int(1); return 0; } /*! * Stop stream I/O * * @param cam structure cam_data * * * @return status 0 Success */ static int csi_streamoff(cam_data *cam) { unsigned int cr3; pr_debug("In MVC: %s\n", __func__); if (cam->capture_on == false) return 0; csi_disable_int(); cam->capture_on = false; /* set CSI_CSIDMASA_FB1 and CSI_CSIDMASA_FB2 to default value */ __raw_writel(0, CSI_CSIDMASA_FB1); __raw_writel(0, CSI_CSIDMASA_FB2); cr3 = __raw_readl(CSI_CSICR3); __raw_writel(cr3 | BIT_DMA_REFLASH_RFF, CSI_CSICR3); csi_free_frames(cam); csi_free_frame_buf(cam); return 0; } /*! * start the viewfinder job * * @param cam structure cam_data * * * @return status 0 Success */ static int start_preview(cam_data *cam) { unsigned long fb_addr = (unsigned long)cam->v4l2_fb.base; __raw_writel(fb_addr, CSI_CSIDMASA_FB1); __raw_writel(fb_addr, CSI_CSIDMASA_FB2); __raw_writel(__raw_readl(CSI_CSICR3) | BIT_DMA_REFLASH_RFF, CSI_CSICR3); csi_enable_int(0); return 0; } /*! * shut down the viewfinder job * * @param cam structure cam_data * * * @return status 0 Success */ static int stop_preview(cam_data *cam) { csi_disable_int(); /* set CSI_CSIDMASA_FB1 and CSI_CSIDMASA_FB2 to default value */ __raw_writel(0, CSI_CSIDMASA_FB1); __raw_writel(0, CSI_CSIDMASA_FB2); __raw_writel(__raw_readl(CSI_CSICR3) | BIT_DMA_REFLASH_RFF, CSI_CSICR3); return 0; } /*************************************************************************** * VIDIOC Functions. **************************************************************************/ /*! * * @param cam structure cam_data * * * @param f structure v4l2_format * * * @return status 0 success, EINVAL failed */ static int csi_v4l2_g_fmt(cam_data *cam, struct v4l2_format *f) { int retval = 0; switch (f->type) { case V4L2_BUF_TYPE_VIDEO_CAPTURE: pr_debug(" type is V4L2_BUF_TYPE_VIDEO_CAPTURE\n"); f->fmt.pix = cam->v2f.fmt.pix; break; case V4L2_BUF_TYPE_VIDEO_OVERLAY: pr_debug(" type is V4L2_BUF_TYPE_VIDEO_OVERLAY\n"); f->fmt.win = cam->win; break; default: pr_debug(" type is invalid\n"); retval = -EINVAL; } pr_debug("End of %s: v2f pix widthxheight %d x %d\n", __func__, cam->v2f.fmt.pix.width, cam->v2f.fmt.pix.height); return retval; } /*! * V4L2 - csi_v4l2_s_fmt function * * @param cam structure cam_data * * * @param f structure v4l2_format * * * @return status 0 success, EINVAL failed */ static int csi_v4l2_s_fmt(cam_data *cam, struct v4l2_format *f) { int retval = 0; int size = 0; int bytesperline = 0; int *width, *height; pr_debug("In MVC: %s\n", __func__); switch (f->type) { case V4L2_BUF_TYPE_VIDEO_CAPTURE: pr_debug(" type=V4L2_BUF_TYPE_VIDEO_CAPTURE\n"); if (!valid_mode(f->fmt.pix.pixelformat)) { pr_err("ERROR: v4l2 capture: %s: format " "not supported\n", __func__); return -EINVAL; } /* Handle case where size requested is larger than cuurent * camera setting. */ if ((f->fmt.pix.width > cam->crop_bounds.width) || (f->fmt.pix.height > cam->crop_bounds.height)) { /* Need the logic here, calling vidioc_s_param if * camera can change. */ pr_debug("csi_v4l2_s_fmt size changed\n"); } if (cam->rotation >= IPU_ROTATE_90_RIGHT) { height = &f->fmt.pix.width; width = &f->fmt.pix.height; } else { width = &f->fmt.pix.width; height = &f->fmt.pix.height; } if ((cam->crop_bounds.width / *width > 8) || ((cam->crop_bounds.width / *width == 8) && (cam->crop_bounds.width % *width))) { *width = cam->crop_bounds.width / 8; if (*width % 8) *width += 8 - *width % 8; pr_err("ERROR: v4l2 capture: width exceeds limit " "resize to %d.\n", *width); } if ((cam->crop_bounds.height / *height > 8) || ((cam->crop_bounds.height / *height == 8) && (cam->crop_bounds.height % *height))) { *height = cam->crop_bounds.height / 8; if (*height % 8) *height += 8 - *height % 8; pr_err("ERROR: v4l2 capture: height exceeds limit " "resize to %d.\n", *height); } switch (f->fmt.pix.pixelformat) { case V4L2_PIX_FMT_RGB565: size = f->fmt.pix.width * f->fmt.pix.height * 2; csi_set_16bit_imagpara(f->fmt.pix.width, f->fmt.pix.height); bytesperline = f->fmt.pix.width * 2; break; case V4L2_PIX_FMT_UYVY: size = f->fmt.pix.width * f->fmt.pix.height * 2; csi_set_16bit_imagpara(f->fmt.pix.width, f->fmt.pix.height); bytesperline = f->fmt.pix.width * 2; break; case V4L2_PIX_FMT_YUV420: size = f->fmt.pix.width * f->fmt.pix.height * 3 / 2; csi_set_12bit_imagpara(f->fmt.pix.width, f->fmt.pix.height); bytesperline = f->fmt.pix.width; break; case V4L2_PIX_FMT_YUV422P: case V4L2_PIX_FMT_RGB24: case V4L2_PIX_FMT_BGR24: case V4L2_PIX_FMT_BGR32: case V4L2_PIX_FMT_RGB32: case V4L2_PIX_FMT_NV12: default: pr_debug(" case not supported\n"); break; } if (f->fmt.pix.bytesperline < bytesperline) f->fmt.pix.bytesperline = bytesperline; else bytesperline = f->fmt.pix.bytesperline; if (f->fmt.pix.sizeimage < size) f->fmt.pix.sizeimage = size; else size = f->fmt.pix.sizeimage; cam->v2f.fmt.pix = f->fmt.pix; if (cam->v2f.fmt.pix.priv != 0) { if (copy_from_user(&cam->offset, (void *)cam->v2f.fmt.pix.priv, sizeof(cam->offset))) { retval = -EFAULT; break; } } break; case V4L2_BUF_TYPE_VIDEO_OVERLAY: pr_debug(" type=V4L2_BUF_TYPE_VIDEO_OVERLAY\n"); cam->win = f->fmt.win; break; default: retval = -EINVAL; } pr_debug("End of %s: v2f pix widthxheight %d x %d\n", __func__, cam->v2f.fmt.pix.width, cam->v2f.fmt.pix.height); return retval; } /*! * V4L2 - csi_v4l2_s_param function * Allows setting of capturemode and frame rate. * * @param cam structure cam_data * * @param parm structure v4l2_streamparm * * * @return status 0 success, EINVAL failed */ static int csi_v4l2_s_param(cam_data *cam, struct v4l2_streamparm *parm) { struct v4l2_ifparm ifparm; struct v4l2_format cam_fmt; struct v4l2_streamparm currentparm; int err = 0; pr_debug("In %s\n", __func__); if (parm->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) { pr_err(KERN_ERR "%s invalid type\n", __func__); return -EINVAL; } /* Stop the viewfinder */ if (cam->overlay_on == true) stop_preview(cam); currentparm.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; /* First check that this device can support the changes requested. */ err = vidioc_int_g_parm(cam->sensor, &currentparm); if (err) { pr_err("%s: vidioc_int_g_parm returned an error %d\n", __func__, err); goto exit; } pr_debug(" Current capabilities are %x\n", currentparm.parm.capture.capability); pr_debug(" Current capturemode is %d change to %d\n", currentparm.parm.capture.capturemode, parm->parm.capture.capturemode); pr_debug(" Current framerate is %d change to %d\n", currentparm.parm.capture.timeperframe.denominator, parm->parm.capture.timeperframe.denominator); err = vidioc_int_s_parm(cam->sensor, parm); if (err) { pr_err("%s: vidioc_int_s_parm returned an error %d\n", __func__, err); goto exit; } vidioc_int_g_ifparm(cam->sensor, &ifparm); cam_fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; pr_debug(" g_fmt_cap returns widthxheight of input as %d x %d\n", cam_fmt.fmt.pix.width, cam_fmt.fmt.pix.height); exit: return err; } /*! * Dequeue one V4L capture buffer * * @param cam structure cam_data * * @param buf structure v4l2_buffer * * * @return status 0 success, EINVAL invalid frame number * ETIME timeout, ERESTARTSYS interrupted by user */ static int csi_v4l_dqueue(cam_data *cam, struct v4l2_buffer *buf) { int retval = 0; struct mxc_v4l_frame *frame; unsigned long lock_flags; if (!wait_event_interruptible_timeout(cam->enc_queue, cam->enc_counter != 0, 10 * HZ)) { pr_err("ERROR: v4l2 capture: mxc_v4l_dqueue timeout " "enc_counter %x\n", cam->enc_counter); return -ETIME; } else if (signal_pending(current)) { pr_err("ERROR: v4l2 capture: mxc_v4l_dqueue() " "interrupt received\n"); return -ERESTARTSYS; } spin_lock_irqsave(&cam->dqueue_int_lock, lock_flags); cam->enc_counter--; frame = list_entry(cam->done_q.next, struct mxc_v4l_frame, queue); list_del(cam->done_q.next); if (frame->buffer.flags & V4L2_BUF_FLAG_DONE) { frame->buffer.flags &= ~V4L2_BUF_FLAG_DONE; } else if (frame->buffer.flags & V4L2_BUF_FLAG_QUEUED) { pr_err("ERROR: v4l2 capture: VIDIOC_DQBUF: " "Buffer not filled.\n"); frame->buffer.flags &= ~V4L2_BUF_FLAG_QUEUED; retval = -EINVAL; } else if ((frame->buffer.flags & 0x7) == V4L2_BUF_FLAG_MAPPED) { pr_err("ERROR: v4l2 capture: VIDIOC_DQBUF: " "Buffer not queued.\n"); retval = -EINVAL; } spin_unlock_irqrestore(&cam->dqueue_int_lock, lock_flags); buf->bytesused = cam->v2f.fmt.pix.sizeimage; buf->index = frame->index; buf->flags = frame->buffer.flags; buf->m = cam->frame[frame->index].buffer.m; return retval; } /*! * V4L interface - open function * * @param file structure file * * * @return status 0 success, ENODEV invalid device instance, * ENODEV timeout, ERESTARTSYS interrupted by user */ static int csi_v4l_open(struct file *file) { struct v4l2_ifparm ifparm; struct v4l2_format cam_fmt; struct video_device *dev = video_devdata(file); cam_data *cam = video_get_drvdata(dev); int err = 0; pr_debug(" device name is %s\n", dev->name); if (!cam) { pr_err("ERROR: v4l2 capture: Internal error, " "cam_data not found!\n"); return -EBADF; } down(&cam->busy_lock); err = 0; if (signal_pending(current)) goto oops; if (cam->open_count++ == 0) { wait_event_interruptible(cam->power_queue, cam->low_power == false); cam->enc_counter = 0; cam->skip_frame = 0; INIT_LIST_HEAD(&cam->ready_q); INIT_LIST_HEAD(&cam->working_q); INIT_LIST_HEAD(&cam->done_q); vidioc_int_g_ifparm(cam->sensor, &ifparm); cam_fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; csi_enable_mclk(CSI_MCLK_I2C, true, true); vidioc_int_init(cam->sensor); } file->private_data = dev; oops: up(&cam->busy_lock); return err; } /*! * V4L interface - close function * * @param file struct file * * * @return 0 success */ static int csi_v4l_close(struct file *file) { struct video_device *dev = video_devdata(file); int err = 0; cam_data *cam = video_get_drvdata(dev); pr_debug("In MVC:%s\n", __func__); if (!cam) { pr_err("ERROR: v4l2 capture: Internal error, " "cam_data not found!\n"); return -EBADF; } /* for the case somebody hit the ctrl C */ if (cam->overlay_pid == current->pid) { err = stop_preview(cam); cam->overlay_on = false; } if (--cam->open_count == 0) { wait_event_interruptible(cam->power_queue, cam->low_power == false); file->private_data = NULL; csi_enable_mclk(CSI_MCLK_I2C, false, false); } return err; } /* * V4L interface - read function * * @param file struct file * * @param read buf char * * @param count size_t * @param ppos structure loff_t * * * @return bytes read */ static ssize_t csi_v4l_read(struct file *file, char *buf, size_t count, loff_t *ppos) { int err = 0; struct video_device *dev = video_devdata(file); cam_data *cam = video_get_drvdata(dev); if (down_interruptible(&cam->busy_lock)) return -EINTR; /* Stop the viewfinder */ if (cam->overlay_on == true) stop_preview(cam); if (cam->still_buf_vaddr == NULL) { cam->still_buf_vaddr = dma_alloc_coherent(0, PAGE_ALIGN (cam->v2f.fmt. pix.sizeimage), &cam-> still_buf[0], GFP_DMA | GFP_KERNEL); if (cam->still_buf_vaddr == NULL) { pr_err("alloc dma memory failed\n"); return -ENOMEM; } cam->still_counter = 0; __raw_writel(cam->still_buf[0], CSI_CSIDMASA_FB2); __raw_writel(cam->still_buf[0], CSI_CSIDMASA_FB1); __raw_writel(__raw_readl(CSI_CSICR3) | BIT_DMA_REFLASH_RFF, CSI_CSICR3); __raw_writel(__raw_readl(CSI_CSISR), CSI_CSISR); __raw_writel(__raw_readl(CSI_CSICR3) | BIT_FRMCNT_RST, CSI_CSICR3); csi_enable_int(1); } wait_event_interruptible(cam->still_queue, cam->still_counter); csi_disable_int(); err = copy_to_user(buf, cam->still_buf_vaddr, cam->v2f.fmt.pix.sizeimage); if (cam->still_buf_vaddr != NULL) { dma_free_coherent(0, PAGE_ALIGN(cam->v2f.fmt.pix.sizeimage), cam->still_buf_vaddr, cam->still_buf[0]); cam->still_buf[0] = 0; cam->still_buf_vaddr = NULL; } if (cam->overlay_on == true) start_preview(cam); up(&cam->busy_lock); if (err < 0) return err; return cam->v2f.fmt.pix.sizeimage - err; } /*! * V4L interface - ioctl function * * @param file struct file* * * @param ioctlnr unsigned int * * @param arg void* * * @return 0 success, ENODEV for invalid device instance, * -1 for other errors. */ static long csi_v4l_do_ioctl(struct file *file, unsigned int ioctlnr, void *arg) { struct video_device *dev = video_devdata(file); cam_data *cam = video_get_drvdata(dev); int retval = 0; unsigned long lock_flags; pr_debug("In MVC: %s, %x\n", __func__, ioctlnr); wait_event_interruptible(cam->power_queue, cam->low_power == false); /* make this _really_ smp-safe */ if (down_interruptible(&cam->busy_lock)) return -EBUSY; switch (ioctlnr) { /*! * V4l2 VIDIOC_G_FMT ioctl */ case VIDIOC_G_FMT:{ struct v4l2_format *gf = arg; pr_debug(" case VIDIOC_G_FMT\n"); retval = csi_v4l2_g_fmt(cam, gf); break; } /*! * V4l2 VIDIOC_S_FMT ioctl */ case VIDIOC_S_FMT:{ struct v4l2_format *sf = arg; pr_debug(" case VIDIOC_S_FMT\n"); retval = csi_v4l2_s_fmt(cam, sf); vidioc_int_s_fmt_cap(cam->sensor, sf); break; } /*! * V4l2 VIDIOC_OVERLAY ioctl */ case VIDIOC_OVERLAY:{ int *on = arg; pr_debug(" case VIDIOC_OVERLAY\n"); if (*on) { cam->overlay_on = true; cam->overlay_pid = current->pid; start_preview(cam); } if (!*on) { stop_preview(cam); cam->overlay_on = false; } break; } /*! * V4l2 VIDIOC_G_FBUF ioctl */ case VIDIOC_G_FBUF:{ struct v4l2_framebuffer *fb = arg; *fb = cam->v4l2_fb; fb->capability = V4L2_FBUF_CAP_EXTERNOVERLAY; break; } /*! * V4l2 VIDIOC_S_FBUF ioctl */ case VIDIOC_S_FBUF:{ struct v4l2_framebuffer *fb = arg; cam->v4l2_fb = *fb; break; } case VIDIOC_G_PARM:{ struct v4l2_streamparm *parm = arg; pr_debug(" case VIDIOC_G_PARM\n"); vidioc_int_g_parm(cam->sensor, parm); break; } case VIDIOC_S_PARM:{ struct v4l2_streamparm *parm = arg; pr_debug(" case VIDIOC_S_PARM\n"); retval = csi_v4l2_s_param(cam, parm); break; } case VIDIOC_QUERYCAP:{ struct v4l2_capability *cap = arg; pr_debug(" case VIDIOC_QUERYCAP\n"); strcpy(cap->driver, "csi_v4l2"); cap->version = KERNEL_VERSION(0, 1, 11); cap->capabilities = V4L2_CAP_VIDEO_OVERLAY | V4L2_CAP_VIDEO_OUTPUT_OVERLAY | V4L2_CAP_READWRITE; cap->card[0] = '\0'; cap->bus_info[0] = '\0'; break; } case VIDIOC_S_CROP: pr_debug(" case not supported\n"); break; case VIDIOC_REQBUFS: { struct v4l2_requestbuffers *req = arg; pr_debug(" case VIDIOC_REQBUFS\n"); if (req->count > FRAME_NUM) { pr_err("ERROR: v4l2 capture: VIDIOC_REQBUFS: " "not enough buffers\n"); req->count = FRAME_NUM; } if ((req->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) || (req->memory != V4L2_MEMORY_MMAP)) { pr_err("ERROR: v4l2 capture: VIDIOC_REQBUFS: " "wrong buffer type\n"); retval = -EINVAL; break; } csi_streamoff(cam); csi_free_frame_buf(cam); cam->skip_frame = 0; INIT_LIST_HEAD(&cam->ready_q); INIT_LIST_HEAD(&cam->working_q); INIT_LIST_HEAD(&cam->done_q); retval = csi_allocate_frame_buf(cam, req->count); break; } case VIDIOC_QUERYBUF: { struct v4l2_buffer *buf = arg; int index = buf->index; pr_debug(" case VIDIOC_QUERYBUF\n"); if (buf->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) { retval = -EINVAL; break; } memset(buf, 0, sizeof(buf)); buf->index = index; retval = csi_v4l2_buffer_status(cam, buf); break; } case VIDIOC_QBUF: { struct v4l2_buffer *buf = arg; int index = buf->index; pr_debug(" case VIDIOC_QBUF\n"); spin_lock_irqsave(&cam->queue_int_lock, lock_flags); cam->frame[index].buffer.m.offset = buf->m.offset; if ((cam->frame[index].buffer.flags & 0x7) == V4L2_BUF_FLAG_MAPPED) { cam->frame[index].buffer.flags |= V4L2_BUF_FLAG_QUEUED; if (cam->skip_frame > 0) { list_add_tail(&cam->frame[index].queue, &cam->working_q); cam->skip_frame = 0; if (cam->ping_pong_csi == 1) { __raw_writel(cam->frame[index].paddress, CSI_CSIDMASA_FB1); } else { __raw_writel(cam->frame[index].paddress, CSI_CSIDMASA_FB2); } } else { list_add_tail(&cam->frame[index].queue, &cam->ready_q); } } else if (cam->frame[index].buffer.flags & V4L2_BUF_FLAG_QUEUED) { pr_err("ERROR: v4l2 capture: VIDIOC_QBUF: " "buffer already queued\n"); retval = -EINVAL; } else if (cam->frame[index].buffer. flags & V4L2_BUF_FLAG_DONE) { pr_err("ERROR: v4l2 capture: VIDIOC_QBUF: " "overwrite done buffer.\n"); cam->frame[index].buffer.flags &= ~V4L2_BUF_FLAG_DONE; cam->frame[index].buffer.flags |= V4L2_BUF_FLAG_QUEUED; retval = -EINVAL; } buf->flags = cam->frame[index].buffer.flags; spin_unlock_irqrestore(&cam->queue_int_lock, lock_flags); break; } case VIDIOC_DQBUF: { struct v4l2_buffer *buf = arg; pr_debug(" case VIDIOC_DQBUF\n"); retval = csi_v4l_dqueue(cam, buf); break; } case VIDIOC_STREAMON: { pr_debug(" case VIDIOC_STREAMON\n"); retval = csi_streamon(cam); break; } case VIDIOC_STREAMOFF: { pr_debug(" case VIDIOC_STREAMOFF\n"); retval = csi_streamoff(cam); break; } case VIDIOC_S_CTRL: case VIDIOC_G_STD: case VIDIOC_G_OUTPUT: case VIDIOC_S_OUTPUT: case VIDIOC_ENUMSTD: case VIDIOC_G_CROP: case VIDIOC_CROPCAP: case VIDIOC_S_STD: case VIDIOC_G_CTRL: case VIDIOC_ENUM_FMT: case VIDIOC_TRY_FMT: case VIDIOC_QUERYCTRL: case VIDIOC_ENUMINPUT: case VIDIOC_G_INPUT: case VIDIOC_S_INPUT: case VIDIOC_G_TUNER: case VIDIOC_S_TUNER: case VIDIOC_G_FREQUENCY: case VIDIOC_S_FREQUENCY: case VIDIOC_ENUMOUTPUT: default: pr_debug(" case not supported\n"); retval = -EINVAL; break; } up(&cam->busy_lock); return retval; } /* * V4L interface - ioctl function * * @return None */ static long csi_v4l_ioctl(struct file *file, unsigned int cmd, unsigned long arg) { return video_usercopy(file, cmd, arg, csi_v4l_do_ioctl); } /*! * V4L interface - mmap function * * @param file structure file * * * @param vma structure vm_area_struct * * * @return status 0 Success, EINTR busy lock error, ENOBUFS remap_page error */ static int csi_mmap(struct file *file, struct vm_area_struct *vma) { struct video_device *dev = video_devdata(file); unsigned long size; int res = 0; cam_data *cam = video_get_drvdata(dev); pr_debug("%s\n", __func__); pr_debug("\npgoff=0x%lx, start=0x%lx, end=0x%lx\n", vma->vm_pgoff, vma->vm_start, vma->vm_end); /* make this _really_ smp-safe */ if (down_interruptible(&cam->busy_lock)) return -EINTR; size = vma->vm_end - vma->vm_start; vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot); if (remap_pfn_range(vma, vma->vm_start, vma->vm_pgoff, size, vma->vm_page_prot)) { pr_err("ERROR: v4l2 capture: %s : " "remap_pfn_range failed\n", __func__); res = -ENOBUFS; goto csi_mmap_exit; } vma->vm_flags &= ~VM_IO; /* using shared anonymous pages */ csi_mmap_exit: up(&cam->busy_lock); return res; } /*! * This structure defines the functions to be called in this driver. */ static struct v4l2_file_operations csi_v4l_fops = { .owner = THIS_MODULE, .open = csi_v4l_open, .release = csi_v4l_close, .read = csi_v4l_read, .ioctl = csi_v4l_ioctl, .mmap = csi_mmap, }; static struct video_device csi_v4l_template = { .name = "Mx25 Camera", .fops = &csi_v4l_fops, .release = video_device_release, }; /*! * This function can be used to release any platform data on closing. */ static void camera_platform_release(struct device *device) { } /*! Device Definition for csi v4l2 device */ static struct platform_device csi_v4l2_devices = { .name = "csi_v4l2", .dev = { .release = camera_platform_release, }, .id = 0, }; /*! * initialize cam_data structure * * @param cam structure cam_data * * * @return status 0 Success */ static void init_camera_struct(cam_data *cam) { pr_debug("In MVC: %s\n", __func__); /* Default everything to 0 */ memset(cam, 0, sizeof(cam_data)); init_MUTEX(&cam->param_lock); init_MUTEX(&cam->busy_lock); cam->video_dev = video_device_alloc(); if (cam->video_dev == NULL) return; *(cam->video_dev) = csi_v4l_template; video_set_drvdata(cam->video_dev, cam); dev_set_drvdata(&csi_v4l2_devices.dev, (void *)cam); cam->video_dev->minor = -1; init_waitqueue_head(&cam->enc_queue); init_waitqueue_head(&cam->still_queue); cam->streamparm.parm.capture.capturemode = 0; cam->standard.index = 0; cam->standard.id = V4L2_STD_UNKNOWN; cam->standard.frameperiod.denominator = 30; cam->standard.frameperiod.numerator = 1; cam->standard.framelines = 480; cam->standard_autodetect = true; cam->streamparm.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; cam->streamparm.parm.capture.timeperframe = cam->standard.frameperiod; cam->streamparm.parm.capture.capability = V4L2_CAP_TIMEPERFRAME; cam->overlay_on = false; cam->capture_on = false; cam->skip_frame = 0; cam->v4l2_fb.flags = V4L2_FBUF_FLAG_OVERLAY; cam->v2f.fmt.pix.sizeimage = 480 * 640 * 2; cam->v2f.fmt.pix.bytesperline = 640 * 2; cam->v2f.fmt.pix.width = 640; cam->v2f.fmt.pix.height = 480; cam->v2f.fmt.pix.pixelformat = V4L2_PIX_FMT_UYVY; cam->win.w.width = 160; cam->win.w.height = 160; cam->win.w.left = 0; cam->win.w.top = 0; cam->still_counter = 0; cam->enc_callback = camera_callback; csi_start_callback(cam); init_waitqueue_head(&cam->power_queue); spin_lock_init(&cam->queue_int_lock); spin_lock_init(&cam->dqueue_int_lock); } /*! * camera_power function * Turns Sensor power On/Off * * @param cam cam data struct * @param cameraOn true to turn camera on, false to turn off power. * * @return status */ static u8 camera_power(cam_data *cam, bool cameraOn) { pr_debug("In MVC: %s on=%d\n", __func__, cameraOn); if (cameraOn == true) { csi_enable_mclk(CSI_MCLK_I2C, true, true); vidioc_int_s_power(cam->sensor, 1); } else { csi_enable_mclk(CSI_MCLK_I2C, false, false); vidioc_int_s_power(cam->sensor, 0); } return 0; } /*! * This function is called to put the sensor in a low power state. * Refer to the document driver-model/driver.txt in the kernel source tree * for more information. * * @param pdev the device structure used to give information on which I2C * to suspend * @param state the power state the device is entering * * @return The function returns 0 on success and -1 on failure. */ static int csi_v4l2_suspend(struct platform_device *pdev, pm_message_t state) { cam_data *cam = platform_get_drvdata(pdev); pr_debug("In MVC: %s\n", __func__); if (cam == NULL) return -1; cam->low_power = true; if (cam->overlay_on == true) stop_preview(cam); camera_power(cam, false); return 0; } /*! * This function is called to bring the sensor back from a low power state. * Refer to the document driver-model/driver.txt in the kernel source tree * for more information. * * @param pdev the device structure * * @return The function returns 0 on success and -1 on failure */ static int csi_v4l2_resume(struct platform_device *pdev) { cam_data *cam = platform_get_drvdata(pdev); pr_debug("In MVC: %s\n", __func__); if (cam == NULL) return -1; cam->low_power = false; wake_up_interruptible(&cam->power_queue); camera_power(cam, true); if (cam->overlay_on == true) start_preview(cam); return 0; } /*! * This structure contains pointers to the power management callback functions. */ static struct platform_driver csi_v4l2_driver = { .driver = { .name = "csi_v4l2", }, .probe = NULL, .remove = NULL, #ifdef CONFIG_PM .suspend = csi_v4l2_suspend, .resume = csi_v4l2_resume, #endif .shutdown = NULL, }; /*! * Initializes the camera driver. */ static int csi_v4l2_master_attach(struct v4l2_int_device *slave) { cam_data *cam = slave->u.slave->master->priv; struct v4l2_format cam_fmt; pr_debug("In MVC: %s\n", __func__); pr_debug(" slave.name = %s\n", slave->name); pr_debug(" master.name = %s\n", slave->u.slave->master->name); cam->sensor = slave; if (slave == NULL) { pr_err("ERROR: v4l2 capture: slave parameter not valid.\n"); return -1; } csi_enable_mclk(CSI_MCLK_I2C, true, true); vidioc_int_dev_init(slave); csi_enable_mclk(CSI_MCLK_I2C, false, false); cam_fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; /* Used to detect TV in (type 1) vs. camera (type 0) */ cam->device_type = cam_fmt.fmt.pix.priv; pr_debug("End of %s: v2f pix widthxheight %d x %d\n", __func__, cam->v2f.fmt.pix.width, cam->v2f.fmt.pix.height); return 0; } /*! * Disconnects the camera driver. */ static void csi_v4l2_master_detach(struct v4l2_int_device *slave) { pr_debug("In MVC: %s\n", __func__); vidioc_int_dev_exit(slave); } /*! * Entry point for the V4L2 * * @return Error code indicating success or failure */ static __init int camera_init(void) { u8 err = 0; /* Register the device driver structure. */ err = platform_driver_register(&csi_v4l2_driver); if (err != 0) { pr_err("ERROR: v4l2 capture:camera_init: " "platform_driver_register failed.\n"); return err; } /* Create g_cam and initialize it. */ g_cam = kmalloc(sizeof(cam_data), GFP_KERNEL); if (g_cam == NULL) { pr_err("ERROR: v4l2 capture: failed to register camera\n"); platform_driver_unregister(&csi_v4l2_driver); return -1; } init_camera_struct(g_cam); /* Set up the v4l2 device and register it */ csi_v4l2_int_device.priv = g_cam; /* This function contains a bug that won't let this be rmmod'd. */ v4l2_int_device_register(&csi_v4l2_int_device); /* Register the platform device */ err = platform_device_register(&csi_v4l2_devices); if (err != 0) { pr_err("ERROR: v4l2 capture: camera_init: " "platform_device_register failed.\n"); platform_driver_unregister(&csi_v4l2_driver); kfree(g_cam); g_cam = NULL; return err; } /* register v4l video device */ if (video_register_device(g_cam->video_dev, VFL_TYPE_GRABBER, video_nr) == -1) { platform_device_unregister(&csi_v4l2_devices); platform_driver_unregister(&csi_v4l2_driver); kfree(g_cam); g_cam = NULL; pr_err("ERROR: v4l2 capture: video_register_device failed\n"); return -1; } pr_debug(" Video device registered: %s #%d\n", g_cam->video_dev->name, g_cam->video_dev->minor); return err; } /*! * Exit and cleanup for the V4L2 */ static void __exit camera_exit(void) { pr_debug("In MVC: %s\n", __func__); if (g_cam->open_count) { pr_err("ERROR: v4l2 capture:camera open " "-- setting ops to NULL\n"); } else { pr_info("V4L2 freeing image input device\n"); v4l2_int_device_unregister(&csi_v4l2_int_device); csi_stop_callback(g_cam); video_unregister_device(g_cam->video_dev); platform_driver_unregister(&csi_v4l2_driver); platform_device_unregister(&csi_v4l2_devices); kfree(g_cam); g_cam = NULL; } } module_init(camera_init); module_exit(camera_exit); module_param(video_nr, int, 0444); MODULE_AUTHOR("Freescale Semiconductor, Inc."); MODULE_DESCRIPTION("V4L2 capture driver for Mx25 based cameras"); MODULE_LICENSE("GPL"); MODULE_SUPPORTED_DEVICE("video");
gpl-2.0
updownlife/RoboRobert
mjpg_streamer/plugins/input_file/input_file.c
14
12875
/******************************************************************************* # # # MJPG-streamer allows to stream JPG frames from an input-plugin # # to several output plugins # # # # Copyright (C) 2007 Tom Stöveken # # # # This program is free software; you can redistribute it and/or modify # # it under the terms of the GNU General Public License as published by # # the Free Software Foundation; version 2 of the License. # # # # This program is distributed in the hope that it will be useful, # # but WITHOUT ANY WARRANTY; without even the implied warranty of # # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # # GNU General Public License for more details. # # # # You should have received a copy of the GNU General Public License # # along with this program; if not, write to the Free Software # # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # # # *******************************************************************************/ #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <string.h> #include <getopt.h> #include <pthread.h> #include <syslog.h> #include <sys/types.h> #include <sys/inotify.h> #include <dirent.h> #include <sys/stat.h> #include <fcntl.h> #include "../../mjpg_streamer.h" #include "../../utils.h" #define INPUT_PLUGIN_NAME "FILE input plugin" typedef enum _read_mode { NewFilesOnly, ExistingFiles } read_mode; /* private functions and variables to this plugin */ static pthread_t worker; static globals *pglobal; void *worker_thread(void *); void worker_cleanup(void *); void help(void); static int delay = 1; static char *folder = NULL; static char *filename = NULL; static int rm = 0; static int plugin_number; static read_mode mode = NewFilesOnly; /* global variables for this plugin */ static int fd, rc, wd, size; static struct inotify_event *ev; /*** plugin interface functions ***/ int input_init(input_parameter *param, int id) { int i; plugin_number = id; param->argv[0] = INPUT_PLUGIN_NAME; /* show all parameters for DBG purposes */ for(i = 0; i < param->argc; i++) { DBG("argv[%d]=%s\n", i, param->argv[i]); } reset_getopt(); while(1) { int option_index = 0, c = 0; static struct option long_options[] = { {"h", no_argument, 0, 0 }, {"help", no_argument, 0, 0}, {"d", required_argument, 0, 0}, {"delay", required_argument, 0, 0}, {"f", required_argument, 0, 0}, {"folder", required_argument, 0, 0}, {"r", no_argument, 0, 0}, {"remove", no_argument, 0, 0}, {"n", required_argument, 0, 0}, {"name", required_argument, 0, 0}, {"e", no_argument, 0, 0}, {"existing", no_argument, 0, 0}, {0, 0, 0, 0} }; c = getopt_long_only(param->argc, param->argv, "", long_options, &option_index); /* no more options to parse */ if(c == -1) break; /* unrecognized option */ if(c == '?') { help(); return 1; } switch(option_index) { /* h, help */ case 0: case 1: DBG("case 0,1\n"); help(); return 1; break; /* d, delay */ case 2: case 3: DBG("case 2,3\n"); delay = atoi(optarg); break; /* f, folder */ case 4: case 5: DBG("case 4,5\n"); folder = malloc(strlen(optarg) + 2); strcpy(folder, optarg); if(optarg[strlen(optarg)-1] != '/') strcat(folder, "/"); break; /* r, remove */ case 6: case 7: DBG("case 6,7\n"); rm = 1; break; /* n, name */ case 8: case 9: DBG("case 8,9\n"); filename = malloc(strlen(optarg) + 1); strcpy(filename, optarg); break; /* e, existing */ case 10: case 11: DBG("case 10,11\n"); mode = ExistingFiles; break; default: DBG("default case\n"); help(); return 1; } } pglobal = param->global; /* check for required parameters */ if(folder == NULL) { IPRINT("ERROR: no folder specified\n"); return 1; } IPRINT("folder to watch...: %s\n", folder); IPRINT("forced delay......: %i\n", delay); IPRINT("delete file.......: %s\n", (rm) ? "yes, delete" : "no, do not delete"); IPRINT("filename must be..: %s\n", (filename == NULL) ? "-no filter for certain filename set-" : filename); param->global->in[id].name = malloc((strlen(INPUT_PLUGIN_NAME) + 1) * sizeof(char)); sprintf(param->global->in[id].name, INPUT_PLUGIN_NAME); return 0; } int input_stop(int id) { DBG("will cancel input thread\n"); pthread_cancel(worker); return 0; } int input_run(int id) { pglobal->in[id].buf = NULL; if (mode == NewFilesOnly) { rc = fd = inotify_init(); if(rc == -1) { perror("could not initilialize inotify"); return 1; } rc = wd = inotify_add_watch(fd, folder, IN_CLOSE_WRITE | IN_MOVED_TO | IN_ONLYDIR); if(rc == -1) { perror("could not add watch"); return 1; } size = sizeof(struct inotify_event) + (1 << 16); ev = malloc(size); if(ev == NULL) { perror("not enough memory"); return 1; } } if(pthread_create(&worker, 0, worker_thread, NULL) != 0) { free(pglobal->in[id].buf); fprintf(stderr, "could not start worker thread\n"); exit(EXIT_FAILURE); } pthread_detach(worker); return 0; } /*** private functions for this plugin below ***/ void help(void) { fprintf(stderr, " ---------------------------------------------------------------\n" \ " Help for input plugin..: "INPUT_PLUGIN_NAME"\n" \ " ---------------------------------------------------------------\n" \ " The following parameters can be passed to this plugin:\n\n" \ " [-d | --delay ]........: delay to pause between frames\n" \ " [-f | --folder ].......: folder to watch for new JPEG files\n" \ " [-r | --remove ].......: remove/delete JPEG file after reading\n" \ " [-n | --name ].........: ignore changes unless filename matches\n" \ " [-e | --existing ].....: serve the existing *.jpg files from the specified directory\n" \ " ---------------------------------------------------------------\n"); } /* the single writer thread */ void *worker_thread(void *arg) { char buffer[1<<16]; int file; size_t filesize = 0; struct stat stats; struct dirent **fileList; int fileCount = 0; int currentFileNumber = 0; char hasJpgFile = 0; struct timeval timestamp; if (mode == ExistingFiles) { fileCount = scandir(folder, &fileList, 0, alphasort); if (fileCount < 0) { perror("error during scandir\n"); return NULL; } } /* set cleanup handler to cleanup allocated ressources */ pthread_cleanup_push(worker_cleanup, NULL); while(!pglobal->stop) { if (mode == NewFilesOnly) { /* wait for new frame, read will block until something happens */ rc = read(fd, ev, size); if(rc == -1) { perror("reading inotify events failed\n"); break; } /* sanity check */ if(wd != ev->wd) { fprintf(stderr, "This event is not for the watched directory (%d != %d)\n", wd, ev->wd); continue; } if(ev->mask & (IN_IGNORED | IN_Q_OVERFLOW | IN_UNMOUNT)) { fprintf(stderr, "event mask suggests to stop\n"); break; } /* prepare filename */ snprintf(buffer, sizeof(buffer), "%s%s", folder, ev->name); /* check if the filename matches specified parameter (if given) */ if((filename != NULL) && (strcmp(filename, ev->name) != 0)) { DBG("ignoring this change (specified filename does not match)\n"); continue; } DBG("new file detected: %s\n", buffer); } else { if ((strstr(fileList[currentFileNumber]->d_name, ".jpg") != NULL) || (strstr(fileList[currentFileNumber]->d_name, ".JPG") != NULL)) { hasJpgFile = 1; DBG("serving file: %s\n", fileList[currentFileNumber]->d_name); snprintf(buffer, sizeof(buffer), "%s%s", folder, fileList[currentFileNumber]->d_name); currentFileNumber++; if (currentFileNumber == fileCount) currentFileNumber = 0; } else { currentFileNumber++; if ((currentFileNumber == fileCount) && (hasJpgFile == 0)) { perror("No files with jpg/JPG extension in the folder\n"); goto thread_quit; } continue; } } /* open file for reading */ rc = file = open(buffer, O_RDONLY); if(rc == -1) { perror("could not open file for reading"); break; } /* approximate size of file */ rc = fstat(file, &stats); if(rc == -1) { perror("could not read statistics of file"); close(file); break; } filesize = stats.st_size; /* copy frame from file to global buffer */ pthread_mutex_lock(&pglobal->in[plugin_number].db); /* allocate memory for frame */ if(pglobal->in[plugin_number].buf != NULL) free(pglobal->in[plugin_number].buf); pglobal->in[plugin_number].buf = malloc(filesize + (1 << 16)); if(pglobal->in[plugin_number].buf == NULL) { fprintf(stderr, "could not allocate memory\n"); break; } if((pglobal->in[plugin_number].size = read(file, pglobal->in[plugin_number].buf, filesize)) == -1) { perror("could not read from file"); free(pglobal->in[plugin_number].buf); pglobal->in[plugin_number].buf = NULL; pglobal->in[plugin_number].size = 0; pthread_mutex_unlock(&pglobal->in[plugin_number].db); close(file); break; } gettimeofday(&timestamp, NULL); pglobal->in[plugin_number].timestamp = timestamp; DBG("new frame copied (size: %d)\n", pglobal->in[plugin_number].size); /* signal fresh_frame */ pthread_cond_broadcast(&pglobal->in[plugin_number].db_update); pthread_mutex_unlock(&pglobal->in[plugin_number].db); close(file); /* delete file if necessary */ if(rm) { rc = unlink(buffer); if(rc == -1) { perror("could not remove/delete file"); } } if(delay != 0) usleep(1000 * 1000 * delay); } thread_quit: while (fileCount--) { free(fileList[fileCount]); } free(fileList); DBG("leaving input thread, calling cleanup function now\n"); /* call cleanup handler, signal with the parameter */ pthread_cleanup_pop(1); return NULL; } void worker_cleanup(void *arg) { static unsigned char first_run = 1; if(!first_run) { DBG("already cleaned up ressources\n"); return; } first_run = 0; DBG("cleaning up ressources allocated by input thread\n"); if(pglobal->in[plugin_number].buf != NULL) free(pglobal->in[plugin_number].buf); free(ev); if (mode == NewFilesOnly) { rc = inotify_rm_watch(fd, wd); if(rc == -1) { perror("could not close watch descriptor"); } rc = close(fd); if(rc == -1) { perror("could not close filedescriptor"); } } }
gpl-2.0
xerpi/linux
drivers/ata/ahci.c
14
58255
/* * ahci.c - AHCI SATA support * * Maintained by: Tejun Heo <tj@kernel.org> * Please ALWAYS copy linux-ide@vger.kernel.org * on emails. * * Copyright 2004-2005 Red Hat, Inc. * * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2, or (at your option) * any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; see the file COPYING. If not, write to * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. * * * libata documentation is available via 'make {ps|pdf}docs', * as Documentation/DocBook/libata.* * * AHCI hardware documentation: * http://www.intel.com/technology/serialata/pdf/rev1_0.pdf * http://www.intel.com/technology/serialata/pdf/rev1_1.pdf * */ #include <linux/kernel.h> #include <linux/module.h> #include <linux/pci.h> #include <linux/blkdev.h> #include <linux/delay.h> #include <linux/interrupt.h> #include <linux/dma-mapping.h> #include <linux/device.h> #include <linux/dmi.h> #include <linux/gfp.h> #include <linux/msi.h> #include <scsi/scsi_host.h> #include <scsi/scsi_cmnd.h> #include <linux/libata.h> #include <linux/ahci-remap.h> #include <linux/io-64-nonatomic-lo-hi.h> #include "ahci.h" #define DRV_NAME "ahci" #define DRV_VERSION "3.0" enum { AHCI_PCI_BAR_STA2X11 = 0, AHCI_PCI_BAR_CAVIUM = 0, AHCI_PCI_BAR_ENMOTUS = 2, AHCI_PCI_BAR_STANDARD = 5, }; enum board_ids { /* board IDs by feature in alphabetical order */ board_ahci, board_ahci_ign_iferr, board_ahci_nomsi, board_ahci_noncq, board_ahci_nosntf, board_ahci_yes_fbs, /* board IDs for specific chipsets in alphabetical order */ board_ahci_avn, board_ahci_mcp65, board_ahci_mcp77, board_ahci_mcp89, board_ahci_mv, board_ahci_sb600, board_ahci_sb700, /* for SB700 and SB800 */ board_ahci_vt8251, /* aliases */ board_ahci_mcp_linux = board_ahci_mcp65, board_ahci_mcp67 = board_ahci_mcp65, board_ahci_mcp73 = board_ahci_mcp65, board_ahci_mcp79 = board_ahci_mcp77, }; static int ahci_init_one(struct pci_dev *pdev, const struct pci_device_id *ent); static void ahci_remove_one(struct pci_dev *dev); static int ahci_vt8251_hardreset(struct ata_link *link, unsigned int *class, unsigned long deadline); static int ahci_avn_hardreset(struct ata_link *link, unsigned int *class, unsigned long deadline); static void ahci_mcp89_apple_enable(struct pci_dev *pdev); static bool is_mcp89_apple(struct pci_dev *pdev); static int ahci_p5wdh_hardreset(struct ata_link *link, unsigned int *class, unsigned long deadline); #ifdef CONFIG_PM static int ahci_pci_device_runtime_suspend(struct device *dev); static int ahci_pci_device_runtime_resume(struct device *dev); #ifdef CONFIG_PM_SLEEP static int ahci_pci_device_suspend(struct device *dev); static int ahci_pci_device_resume(struct device *dev); #endif #endif /* CONFIG_PM */ static struct scsi_host_template ahci_sht = { AHCI_SHT("ahci"), }; static struct ata_port_operations ahci_vt8251_ops = { .inherits = &ahci_ops, .hardreset = ahci_vt8251_hardreset, }; static struct ata_port_operations ahci_p5wdh_ops = { .inherits = &ahci_ops, .hardreset = ahci_p5wdh_hardreset, }; static struct ata_port_operations ahci_avn_ops = { .inherits = &ahci_ops, .hardreset = ahci_avn_hardreset, }; static const struct ata_port_info ahci_port_info[] = { /* by features */ [board_ahci] = { .flags = AHCI_FLAG_COMMON, .pio_mask = ATA_PIO4, .udma_mask = ATA_UDMA6, .port_ops = &ahci_ops, }, [board_ahci_ign_iferr] = { AHCI_HFLAGS (AHCI_HFLAG_IGN_IRQ_IF_ERR), .flags = AHCI_FLAG_COMMON, .pio_mask = ATA_PIO4, .udma_mask = ATA_UDMA6, .port_ops = &ahci_ops, }, [board_ahci_nomsi] = { AHCI_HFLAGS (AHCI_HFLAG_NO_MSI), .flags = AHCI_FLAG_COMMON, .pio_mask = ATA_PIO4, .udma_mask = ATA_UDMA6, .port_ops = &ahci_ops, }, [board_ahci_noncq] = { AHCI_HFLAGS (AHCI_HFLAG_NO_NCQ), .flags = AHCI_FLAG_COMMON, .pio_mask = ATA_PIO4, .udma_mask = ATA_UDMA6, .port_ops = &ahci_ops, }, [board_ahci_nosntf] = { AHCI_HFLAGS (AHCI_HFLAG_NO_SNTF), .flags = AHCI_FLAG_COMMON, .pio_mask = ATA_PIO4, .udma_mask = ATA_UDMA6, .port_ops = &ahci_ops, }, [board_ahci_yes_fbs] = { AHCI_HFLAGS (AHCI_HFLAG_YES_FBS), .flags = AHCI_FLAG_COMMON, .pio_mask = ATA_PIO4, .udma_mask = ATA_UDMA6, .port_ops = &ahci_ops, }, /* by chipsets */ [board_ahci_avn] = { .flags = AHCI_FLAG_COMMON, .pio_mask = ATA_PIO4, .udma_mask = ATA_UDMA6, .port_ops = &ahci_avn_ops, }, [board_ahci_mcp65] = { AHCI_HFLAGS (AHCI_HFLAG_NO_FPDMA_AA | AHCI_HFLAG_NO_PMP | AHCI_HFLAG_YES_NCQ), .flags = AHCI_FLAG_COMMON | ATA_FLAG_NO_DIPM, .pio_mask = ATA_PIO4, .udma_mask = ATA_UDMA6, .port_ops = &ahci_ops, }, [board_ahci_mcp77] = { AHCI_HFLAGS (AHCI_HFLAG_NO_FPDMA_AA | AHCI_HFLAG_NO_PMP), .flags = AHCI_FLAG_COMMON, .pio_mask = ATA_PIO4, .udma_mask = ATA_UDMA6, .port_ops = &ahci_ops, }, [board_ahci_mcp89] = { AHCI_HFLAGS (AHCI_HFLAG_NO_FPDMA_AA), .flags = AHCI_FLAG_COMMON, .pio_mask = ATA_PIO4, .udma_mask = ATA_UDMA6, .port_ops = &ahci_ops, }, [board_ahci_mv] = { AHCI_HFLAGS (AHCI_HFLAG_NO_NCQ | AHCI_HFLAG_NO_MSI | AHCI_HFLAG_MV_PATA | AHCI_HFLAG_NO_PMP), .flags = ATA_FLAG_SATA | ATA_FLAG_PIO_DMA, .pio_mask = ATA_PIO4, .udma_mask = ATA_UDMA6, .port_ops = &ahci_ops, }, [board_ahci_sb600] = { AHCI_HFLAGS (AHCI_HFLAG_IGN_SERR_INTERNAL | AHCI_HFLAG_NO_MSI | AHCI_HFLAG_SECT255 | AHCI_HFLAG_32BIT_ONLY), .flags = AHCI_FLAG_COMMON, .pio_mask = ATA_PIO4, .udma_mask = ATA_UDMA6, .port_ops = &ahci_pmp_retry_srst_ops, }, [board_ahci_sb700] = { /* for SB700 and SB800 */ AHCI_HFLAGS (AHCI_HFLAG_IGN_SERR_INTERNAL), .flags = AHCI_FLAG_COMMON, .pio_mask = ATA_PIO4, .udma_mask = ATA_UDMA6, .port_ops = &ahci_pmp_retry_srst_ops, }, [board_ahci_vt8251] = { AHCI_HFLAGS (AHCI_HFLAG_NO_NCQ | AHCI_HFLAG_NO_PMP), .flags = AHCI_FLAG_COMMON, .pio_mask = ATA_PIO4, .udma_mask = ATA_UDMA6, .port_ops = &ahci_vt8251_ops, }, }; static const struct pci_device_id ahci_pci_tbl[] = { /* Intel */ { PCI_VDEVICE(INTEL, 0x2652), board_ahci }, /* ICH6 */ { PCI_VDEVICE(INTEL, 0x2653), board_ahci }, /* ICH6M */ { PCI_VDEVICE(INTEL, 0x27c1), board_ahci }, /* ICH7 */ { PCI_VDEVICE(INTEL, 0x27c5), board_ahci }, /* ICH7M */ { PCI_VDEVICE(INTEL, 0x27c3), board_ahci }, /* ICH7R */ { PCI_VDEVICE(AL, 0x5288), board_ahci_ign_iferr }, /* ULi M5288 */ { PCI_VDEVICE(INTEL, 0x2681), board_ahci }, /* ESB2 */ { PCI_VDEVICE(INTEL, 0x2682), board_ahci }, /* ESB2 */ { PCI_VDEVICE(INTEL, 0x2683), board_ahci }, /* ESB2 */ { PCI_VDEVICE(INTEL, 0x27c6), board_ahci }, /* ICH7-M DH */ { PCI_VDEVICE(INTEL, 0x2821), board_ahci }, /* ICH8 */ { PCI_VDEVICE(INTEL, 0x2822), board_ahci_nosntf }, /* ICH8 */ { PCI_VDEVICE(INTEL, 0x2824), board_ahci }, /* ICH8 */ { PCI_VDEVICE(INTEL, 0x2829), board_ahci }, /* ICH8M */ { PCI_VDEVICE(INTEL, 0x282a), board_ahci }, /* ICH8M */ { PCI_VDEVICE(INTEL, 0x2922), board_ahci }, /* ICH9 */ { PCI_VDEVICE(INTEL, 0x2923), board_ahci }, /* ICH9 */ { PCI_VDEVICE(INTEL, 0x2924), board_ahci }, /* ICH9 */ { PCI_VDEVICE(INTEL, 0x2925), board_ahci }, /* ICH9 */ { PCI_VDEVICE(INTEL, 0x2927), board_ahci }, /* ICH9 */ { PCI_VDEVICE(INTEL, 0x2929), board_ahci }, /* ICH9M */ { PCI_VDEVICE(INTEL, 0x292a), board_ahci }, /* ICH9M */ { PCI_VDEVICE(INTEL, 0x292b), board_ahci }, /* ICH9M */ { PCI_VDEVICE(INTEL, 0x292c), board_ahci }, /* ICH9M */ { PCI_VDEVICE(INTEL, 0x292f), board_ahci }, /* ICH9M */ { PCI_VDEVICE(INTEL, 0x294d), board_ahci }, /* ICH9 */ { PCI_VDEVICE(INTEL, 0x294e), board_ahci }, /* ICH9M */ { PCI_VDEVICE(INTEL, 0x502a), board_ahci }, /* Tolapai */ { PCI_VDEVICE(INTEL, 0x502b), board_ahci }, /* Tolapai */ { PCI_VDEVICE(INTEL, 0x3a05), board_ahci }, /* ICH10 */ { PCI_VDEVICE(INTEL, 0x3a22), board_ahci }, /* ICH10 */ { PCI_VDEVICE(INTEL, 0x3a25), board_ahci }, /* ICH10 */ { PCI_VDEVICE(INTEL, 0x3b22), board_ahci }, /* PCH AHCI */ { PCI_VDEVICE(INTEL, 0x3b23), board_ahci }, /* PCH AHCI */ { PCI_VDEVICE(INTEL, 0x3b24), board_ahci }, /* PCH RAID */ { PCI_VDEVICE(INTEL, 0x3b25), board_ahci }, /* PCH RAID */ { PCI_VDEVICE(INTEL, 0x3b29), board_ahci }, /* PCH AHCI */ { PCI_VDEVICE(INTEL, 0x3b2b), board_ahci }, /* PCH RAID */ { PCI_VDEVICE(INTEL, 0x3b2c), board_ahci }, /* PCH RAID */ { PCI_VDEVICE(INTEL, 0x3b2f), board_ahci }, /* PCH AHCI */ { PCI_VDEVICE(INTEL, 0x19b0), board_ahci }, /* DNV AHCI */ { PCI_VDEVICE(INTEL, 0x19b1), board_ahci }, /* DNV AHCI */ { PCI_VDEVICE(INTEL, 0x19b2), board_ahci }, /* DNV AHCI */ { PCI_VDEVICE(INTEL, 0x19b3), board_ahci }, /* DNV AHCI */ { PCI_VDEVICE(INTEL, 0x19b4), board_ahci }, /* DNV AHCI */ { PCI_VDEVICE(INTEL, 0x19b5), board_ahci }, /* DNV AHCI */ { PCI_VDEVICE(INTEL, 0x19b6), board_ahci }, /* DNV AHCI */ { PCI_VDEVICE(INTEL, 0x19b7), board_ahci }, /* DNV AHCI */ { PCI_VDEVICE(INTEL, 0x19bE), board_ahci }, /* DNV AHCI */ { PCI_VDEVICE(INTEL, 0x19bF), board_ahci }, /* DNV AHCI */ { PCI_VDEVICE(INTEL, 0x19c0), board_ahci }, /* DNV AHCI */ { PCI_VDEVICE(INTEL, 0x19c1), board_ahci }, /* DNV AHCI */ { PCI_VDEVICE(INTEL, 0x19c2), board_ahci }, /* DNV AHCI */ { PCI_VDEVICE(INTEL, 0x19c3), board_ahci }, /* DNV AHCI */ { PCI_VDEVICE(INTEL, 0x19c4), board_ahci }, /* DNV AHCI */ { PCI_VDEVICE(INTEL, 0x19c5), board_ahci }, /* DNV AHCI */ { PCI_VDEVICE(INTEL, 0x19c6), board_ahci }, /* DNV AHCI */ { PCI_VDEVICE(INTEL, 0x19c7), board_ahci }, /* DNV AHCI */ { PCI_VDEVICE(INTEL, 0x19cE), board_ahci }, /* DNV AHCI */ { PCI_VDEVICE(INTEL, 0x19cF), board_ahci }, /* DNV AHCI */ { PCI_VDEVICE(INTEL, 0x1c02), board_ahci }, /* CPT AHCI */ { PCI_VDEVICE(INTEL, 0x1c03), board_ahci }, /* CPT AHCI */ { PCI_VDEVICE(INTEL, 0x1c04), board_ahci }, /* CPT RAID */ { PCI_VDEVICE(INTEL, 0x1c05), board_ahci }, /* CPT RAID */ { PCI_VDEVICE(INTEL, 0x1c06), board_ahci }, /* CPT RAID */ { PCI_VDEVICE(INTEL, 0x1c07), board_ahci }, /* CPT RAID */ { PCI_VDEVICE(INTEL, 0x1d02), board_ahci }, /* PBG AHCI */ { PCI_VDEVICE(INTEL, 0x1d04), board_ahci }, /* PBG RAID */ { PCI_VDEVICE(INTEL, 0x1d06), board_ahci }, /* PBG RAID */ { PCI_VDEVICE(INTEL, 0x2826), board_ahci }, /* PBG RAID */ { PCI_VDEVICE(INTEL, 0x2323), board_ahci }, /* DH89xxCC AHCI */ { PCI_VDEVICE(INTEL, 0x1e02), board_ahci }, /* Panther Point AHCI */ { PCI_VDEVICE(INTEL, 0x1e03), board_ahci }, /* Panther Point AHCI */ { PCI_VDEVICE(INTEL, 0x1e04), board_ahci }, /* Panther Point RAID */ { PCI_VDEVICE(INTEL, 0x1e05), board_ahci }, /* Panther Point RAID */ { PCI_VDEVICE(INTEL, 0x1e06), board_ahci }, /* Panther Point RAID */ { PCI_VDEVICE(INTEL, 0x1e07), board_ahci }, /* Panther Point RAID */ { PCI_VDEVICE(INTEL, 0x1e0e), board_ahci }, /* Panther Point RAID */ { PCI_VDEVICE(INTEL, 0x8c02), board_ahci }, /* Lynx Point AHCI */ { PCI_VDEVICE(INTEL, 0x8c03), board_ahci }, /* Lynx Point AHCI */ { PCI_VDEVICE(INTEL, 0x8c04), board_ahci }, /* Lynx Point RAID */ { PCI_VDEVICE(INTEL, 0x8c05), board_ahci }, /* Lynx Point RAID */ { PCI_VDEVICE(INTEL, 0x8c06), board_ahci }, /* Lynx Point RAID */ { PCI_VDEVICE(INTEL, 0x8c07), board_ahci }, /* Lynx Point RAID */ { PCI_VDEVICE(INTEL, 0x8c0e), board_ahci }, /* Lynx Point RAID */ { PCI_VDEVICE(INTEL, 0x8c0f), board_ahci }, /* Lynx Point RAID */ { PCI_VDEVICE(INTEL, 0x9c02), board_ahci }, /* Lynx Point-LP AHCI */ { PCI_VDEVICE(INTEL, 0x9c03), board_ahci }, /* Lynx Point-LP AHCI */ { PCI_VDEVICE(INTEL, 0x9c04), board_ahci }, /* Lynx Point-LP RAID */ { PCI_VDEVICE(INTEL, 0x9c05), board_ahci }, /* Lynx Point-LP RAID */ { PCI_VDEVICE(INTEL, 0x9c06), board_ahci }, /* Lynx Point-LP RAID */ { PCI_VDEVICE(INTEL, 0x9c07), board_ahci }, /* Lynx Point-LP RAID */ { PCI_VDEVICE(INTEL, 0x9c0e), board_ahci }, /* Lynx Point-LP RAID */ { PCI_VDEVICE(INTEL, 0x9c0f), board_ahci }, /* Lynx Point-LP RAID */ { PCI_VDEVICE(INTEL, 0x1f22), board_ahci }, /* Avoton AHCI */ { PCI_VDEVICE(INTEL, 0x1f23), board_ahci }, /* Avoton AHCI */ { PCI_VDEVICE(INTEL, 0x1f24), board_ahci }, /* Avoton RAID */ { PCI_VDEVICE(INTEL, 0x1f25), board_ahci }, /* Avoton RAID */ { PCI_VDEVICE(INTEL, 0x1f26), board_ahci }, /* Avoton RAID */ { PCI_VDEVICE(INTEL, 0x1f27), board_ahci }, /* Avoton RAID */ { PCI_VDEVICE(INTEL, 0x1f2e), board_ahci }, /* Avoton RAID */ { PCI_VDEVICE(INTEL, 0x1f2f), board_ahci }, /* Avoton RAID */ { PCI_VDEVICE(INTEL, 0x1f32), board_ahci_avn }, /* Avoton AHCI */ { PCI_VDEVICE(INTEL, 0x1f33), board_ahci_avn }, /* Avoton AHCI */ { PCI_VDEVICE(INTEL, 0x1f34), board_ahci_avn }, /* Avoton RAID */ { PCI_VDEVICE(INTEL, 0x1f35), board_ahci_avn }, /* Avoton RAID */ { PCI_VDEVICE(INTEL, 0x1f36), board_ahci_avn }, /* Avoton RAID */ { PCI_VDEVICE(INTEL, 0x1f37), board_ahci_avn }, /* Avoton RAID */ { PCI_VDEVICE(INTEL, 0x1f3e), board_ahci_avn }, /* Avoton RAID */ { PCI_VDEVICE(INTEL, 0x1f3f), board_ahci_avn }, /* Avoton RAID */ { PCI_VDEVICE(INTEL, 0x2823), board_ahci }, /* Wellsburg RAID */ { PCI_VDEVICE(INTEL, 0x2827), board_ahci }, /* Wellsburg RAID */ { PCI_VDEVICE(INTEL, 0x8d02), board_ahci }, /* Wellsburg AHCI */ { PCI_VDEVICE(INTEL, 0x8d04), board_ahci }, /* Wellsburg RAID */ { PCI_VDEVICE(INTEL, 0x8d06), board_ahci }, /* Wellsburg RAID */ { PCI_VDEVICE(INTEL, 0x8d0e), board_ahci }, /* Wellsburg RAID */ { PCI_VDEVICE(INTEL, 0x8d62), board_ahci }, /* Wellsburg AHCI */ { PCI_VDEVICE(INTEL, 0x8d64), board_ahci }, /* Wellsburg RAID */ { PCI_VDEVICE(INTEL, 0x8d66), board_ahci }, /* Wellsburg RAID */ { PCI_VDEVICE(INTEL, 0x8d6e), board_ahci }, /* Wellsburg RAID */ { PCI_VDEVICE(INTEL, 0x23a3), board_ahci }, /* Coleto Creek AHCI */ { PCI_VDEVICE(INTEL, 0x9c83), board_ahci }, /* Wildcat Point-LP AHCI */ { PCI_VDEVICE(INTEL, 0x9c85), board_ahci }, /* Wildcat Point-LP RAID */ { PCI_VDEVICE(INTEL, 0x9c87), board_ahci }, /* Wildcat Point-LP RAID */ { PCI_VDEVICE(INTEL, 0x9c8f), board_ahci }, /* Wildcat Point-LP RAID */ { PCI_VDEVICE(INTEL, 0x8c82), board_ahci }, /* 9 Series AHCI */ { PCI_VDEVICE(INTEL, 0x8c83), board_ahci }, /* 9 Series AHCI */ { PCI_VDEVICE(INTEL, 0x8c84), board_ahci }, /* 9 Series RAID */ { PCI_VDEVICE(INTEL, 0x8c85), board_ahci }, /* 9 Series RAID */ { PCI_VDEVICE(INTEL, 0x8c86), board_ahci }, /* 9 Series RAID */ { PCI_VDEVICE(INTEL, 0x8c87), board_ahci }, /* 9 Series RAID */ { PCI_VDEVICE(INTEL, 0x8c8e), board_ahci }, /* 9 Series RAID */ { PCI_VDEVICE(INTEL, 0x8c8f), board_ahci }, /* 9 Series RAID */ { PCI_VDEVICE(INTEL, 0x9d03), board_ahci }, /* Sunrise Point-LP AHCI */ { PCI_VDEVICE(INTEL, 0x9d05), board_ahci }, /* Sunrise Point-LP RAID */ { PCI_VDEVICE(INTEL, 0x9d07), board_ahci }, /* Sunrise Point-LP RAID */ { PCI_VDEVICE(INTEL, 0xa102), board_ahci }, /* Sunrise Point-H AHCI */ { PCI_VDEVICE(INTEL, 0xa103), board_ahci }, /* Sunrise Point-H AHCI */ { PCI_VDEVICE(INTEL, 0xa105), board_ahci }, /* Sunrise Point-H RAID */ { PCI_VDEVICE(INTEL, 0xa106), board_ahci }, /* Sunrise Point-H RAID */ { PCI_VDEVICE(INTEL, 0xa107), board_ahci }, /* Sunrise Point-H RAID */ { PCI_VDEVICE(INTEL, 0xa10f), board_ahci }, /* Sunrise Point-H RAID */ { PCI_VDEVICE(INTEL, 0x2822), board_ahci }, /* Lewisburg RAID*/ { PCI_VDEVICE(INTEL, 0x2823), board_ahci }, /* Lewisburg AHCI*/ { PCI_VDEVICE(INTEL, 0x2826), board_ahci }, /* Lewisburg RAID*/ { PCI_VDEVICE(INTEL, 0x2827), board_ahci }, /* Lewisburg RAID*/ { PCI_VDEVICE(INTEL, 0xa182), board_ahci }, /* Lewisburg AHCI*/ { PCI_VDEVICE(INTEL, 0xa186), board_ahci }, /* Lewisburg RAID*/ { PCI_VDEVICE(INTEL, 0xa1d2), board_ahci }, /* Lewisburg RAID*/ { PCI_VDEVICE(INTEL, 0xa1d6), board_ahci }, /* Lewisburg RAID*/ { PCI_VDEVICE(INTEL, 0xa202), board_ahci }, /* Lewisburg AHCI*/ { PCI_VDEVICE(INTEL, 0xa206), board_ahci }, /* Lewisburg RAID*/ { PCI_VDEVICE(INTEL, 0xa252), board_ahci }, /* Lewisburg RAID*/ { PCI_VDEVICE(INTEL, 0xa256), board_ahci }, /* Lewisburg RAID*/ /* JMicron 360/1/3/5/6, match class to avoid IDE function */ { PCI_VENDOR_ID_JMICRON, PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_STORAGE_SATA_AHCI, 0xffffff, board_ahci_ign_iferr }, /* JMicron 362B and 362C have an AHCI function with IDE class code */ { PCI_VDEVICE(JMICRON, 0x2362), board_ahci_ign_iferr }, { PCI_VDEVICE(JMICRON, 0x236f), board_ahci_ign_iferr }, /* May need to update quirk_jmicron_async_suspend() for additions */ /* ATI */ { PCI_VDEVICE(ATI, 0x4380), board_ahci_sb600 }, /* ATI SB600 */ { PCI_VDEVICE(ATI, 0x4390), board_ahci_sb700 }, /* ATI SB700/800 */ { PCI_VDEVICE(ATI, 0x4391), board_ahci_sb700 }, /* ATI SB700/800 */ { PCI_VDEVICE(ATI, 0x4392), board_ahci_sb700 }, /* ATI SB700/800 */ { PCI_VDEVICE(ATI, 0x4393), board_ahci_sb700 }, /* ATI SB700/800 */ { PCI_VDEVICE(ATI, 0x4394), board_ahci_sb700 }, /* ATI SB700/800 */ { PCI_VDEVICE(ATI, 0x4395), board_ahci_sb700 }, /* ATI SB700/800 */ /* AMD */ { PCI_VDEVICE(AMD, 0x7800), board_ahci }, /* AMD Hudson-2 */ { PCI_VDEVICE(AMD, 0x7900), board_ahci }, /* AMD CZ */ /* AMD is using RAID class only for ahci controllers */ { PCI_VENDOR_ID_AMD, PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_STORAGE_RAID << 8, 0xffffff, board_ahci }, /* VIA */ { PCI_VDEVICE(VIA, 0x3349), board_ahci_vt8251 }, /* VIA VT8251 */ { PCI_VDEVICE(VIA, 0x6287), board_ahci_vt8251 }, /* VIA VT8251 */ /* NVIDIA */ { PCI_VDEVICE(NVIDIA, 0x044c), board_ahci_mcp65 }, /* MCP65 */ { PCI_VDEVICE(NVIDIA, 0x044d), board_ahci_mcp65 }, /* MCP65 */ { PCI_VDEVICE(NVIDIA, 0x044e), board_ahci_mcp65 }, /* MCP65 */ { PCI_VDEVICE(NVIDIA, 0x044f), board_ahci_mcp65 }, /* MCP65 */ { PCI_VDEVICE(NVIDIA, 0x045c), board_ahci_mcp65 }, /* MCP65 */ { PCI_VDEVICE(NVIDIA, 0x045d), board_ahci_mcp65 }, /* MCP65 */ { PCI_VDEVICE(NVIDIA, 0x045e), board_ahci_mcp65 }, /* MCP65 */ { PCI_VDEVICE(NVIDIA, 0x045f), board_ahci_mcp65 }, /* MCP65 */ { PCI_VDEVICE(NVIDIA, 0x0550), board_ahci_mcp67 }, /* MCP67 */ { PCI_VDEVICE(NVIDIA, 0x0551), board_ahci_mcp67 }, /* MCP67 */ { PCI_VDEVICE(NVIDIA, 0x0552), board_ahci_mcp67 }, /* MCP67 */ { PCI_VDEVICE(NVIDIA, 0x0553), board_ahci_mcp67 }, /* MCP67 */ { PCI_VDEVICE(NVIDIA, 0x0554), board_ahci_mcp67 }, /* MCP67 */ { PCI_VDEVICE(NVIDIA, 0x0555), board_ahci_mcp67 }, /* MCP67 */ { PCI_VDEVICE(NVIDIA, 0x0556), board_ahci_mcp67 }, /* MCP67 */ { PCI_VDEVICE(NVIDIA, 0x0557), board_ahci_mcp67 }, /* MCP67 */ { PCI_VDEVICE(NVIDIA, 0x0558), board_ahci_mcp67 }, /* MCP67 */ { PCI_VDEVICE(NVIDIA, 0x0559), board_ahci_mcp67 }, /* MCP67 */ { PCI_VDEVICE(NVIDIA, 0x055a), board_ahci_mcp67 }, /* MCP67 */ { PCI_VDEVICE(NVIDIA, 0x055b), board_ahci_mcp67 }, /* MCP67 */ { PCI_VDEVICE(NVIDIA, 0x0580), board_ahci_mcp_linux }, /* Linux ID */ { PCI_VDEVICE(NVIDIA, 0x0581), board_ahci_mcp_linux }, /* Linux ID */ { PCI_VDEVICE(NVIDIA, 0x0582), board_ahci_mcp_linux }, /* Linux ID */ { PCI_VDEVICE(NVIDIA, 0x0583), board_ahci_mcp_linux }, /* Linux ID */ { PCI_VDEVICE(NVIDIA, 0x0584), board_ahci_mcp_linux }, /* Linux ID */ { PCI_VDEVICE(NVIDIA, 0x0585), board_ahci_mcp_linux }, /* Linux ID */ { PCI_VDEVICE(NVIDIA, 0x0586), board_ahci_mcp_linux }, /* Linux ID */ { PCI_VDEVICE(NVIDIA, 0x0587), board_ahci_mcp_linux }, /* Linux ID */ { PCI_VDEVICE(NVIDIA, 0x0588), board_ahci_mcp_linux }, /* Linux ID */ { PCI_VDEVICE(NVIDIA, 0x0589), board_ahci_mcp_linux }, /* Linux ID */ { PCI_VDEVICE(NVIDIA, 0x058a), board_ahci_mcp_linux }, /* Linux ID */ { PCI_VDEVICE(NVIDIA, 0x058b), board_ahci_mcp_linux }, /* Linux ID */ { PCI_VDEVICE(NVIDIA, 0x058c), board_ahci_mcp_linux }, /* Linux ID */ { PCI_VDEVICE(NVIDIA, 0x058d), board_ahci_mcp_linux }, /* Linux ID */ { PCI_VDEVICE(NVIDIA, 0x058e), board_ahci_mcp_linux }, /* Linux ID */ { PCI_VDEVICE(NVIDIA, 0x058f), board_ahci_mcp_linux }, /* Linux ID */ { PCI_VDEVICE(NVIDIA, 0x07f0), board_ahci_mcp73 }, /* MCP73 */ { PCI_VDEVICE(NVIDIA, 0x07f1), board_ahci_mcp73 }, /* MCP73 */ { PCI_VDEVICE(NVIDIA, 0x07f2), board_ahci_mcp73 }, /* MCP73 */ { PCI_VDEVICE(NVIDIA, 0x07f3), board_ahci_mcp73 }, /* MCP73 */ { PCI_VDEVICE(NVIDIA, 0x07f4), board_ahci_mcp73 }, /* MCP73 */ { PCI_VDEVICE(NVIDIA, 0x07f5), board_ahci_mcp73 }, /* MCP73 */ { PCI_VDEVICE(NVIDIA, 0x07f6), board_ahci_mcp73 }, /* MCP73 */ { PCI_VDEVICE(NVIDIA, 0x07f7), board_ahci_mcp73 }, /* MCP73 */ { PCI_VDEVICE(NVIDIA, 0x07f8), board_ahci_mcp73 }, /* MCP73 */ { PCI_VDEVICE(NVIDIA, 0x07f9), board_ahci_mcp73 }, /* MCP73 */ { PCI_VDEVICE(NVIDIA, 0x07fa), board_ahci_mcp73 }, /* MCP73 */ { PCI_VDEVICE(NVIDIA, 0x07fb), board_ahci_mcp73 }, /* MCP73 */ { PCI_VDEVICE(NVIDIA, 0x0ad0), board_ahci_mcp77 }, /* MCP77 */ { PCI_VDEVICE(NVIDIA, 0x0ad1), board_ahci_mcp77 }, /* MCP77 */ { PCI_VDEVICE(NVIDIA, 0x0ad2), board_ahci_mcp77 }, /* MCP77 */ { PCI_VDEVICE(NVIDIA, 0x0ad3), board_ahci_mcp77 }, /* MCP77 */ { PCI_VDEVICE(NVIDIA, 0x0ad4), board_ahci_mcp77 }, /* MCP77 */ { PCI_VDEVICE(NVIDIA, 0x0ad5), board_ahci_mcp77 }, /* MCP77 */ { PCI_VDEVICE(NVIDIA, 0x0ad6), board_ahci_mcp77 }, /* MCP77 */ { PCI_VDEVICE(NVIDIA, 0x0ad7), board_ahci_mcp77 }, /* MCP77 */ { PCI_VDEVICE(NVIDIA, 0x0ad8), board_ahci_mcp77 }, /* MCP77 */ { PCI_VDEVICE(NVIDIA, 0x0ad9), board_ahci_mcp77 }, /* MCP77 */ { PCI_VDEVICE(NVIDIA, 0x0ada), board_ahci_mcp77 }, /* MCP77 */ { PCI_VDEVICE(NVIDIA, 0x0adb), board_ahci_mcp77 }, /* MCP77 */ { PCI_VDEVICE(NVIDIA, 0x0ab4), board_ahci_mcp79 }, /* MCP79 */ { PCI_VDEVICE(NVIDIA, 0x0ab5), board_ahci_mcp79 }, /* MCP79 */ { PCI_VDEVICE(NVIDIA, 0x0ab6), board_ahci_mcp79 }, /* MCP79 */ { PCI_VDEVICE(NVIDIA, 0x0ab7), board_ahci_mcp79 }, /* MCP79 */ { PCI_VDEVICE(NVIDIA, 0x0ab8), board_ahci_mcp79 }, /* MCP79 */ { PCI_VDEVICE(NVIDIA, 0x0ab9), board_ahci_mcp79 }, /* MCP79 */ { PCI_VDEVICE(NVIDIA, 0x0aba), board_ahci_mcp79 }, /* MCP79 */ { PCI_VDEVICE(NVIDIA, 0x0abb), board_ahci_mcp79 }, /* MCP79 */ { PCI_VDEVICE(NVIDIA, 0x0abc), board_ahci_mcp79 }, /* MCP79 */ { PCI_VDEVICE(NVIDIA, 0x0abd), board_ahci_mcp79 }, /* MCP79 */ { PCI_VDEVICE(NVIDIA, 0x0abe), board_ahci_mcp79 }, /* MCP79 */ { PCI_VDEVICE(NVIDIA, 0x0abf), board_ahci_mcp79 }, /* MCP79 */ { PCI_VDEVICE(NVIDIA, 0x0d84), board_ahci_mcp89 }, /* MCP89 */ { PCI_VDEVICE(NVIDIA, 0x0d85), board_ahci_mcp89 }, /* MCP89 */ { PCI_VDEVICE(NVIDIA, 0x0d86), board_ahci_mcp89 }, /* MCP89 */ { PCI_VDEVICE(NVIDIA, 0x0d87), board_ahci_mcp89 }, /* MCP89 */ { PCI_VDEVICE(NVIDIA, 0x0d88), board_ahci_mcp89 }, /* MCP89 */ { PCI_VDEVICE(NVIDIA, 0x0d89), board_ahci_mcp89 }, /* MCP89 */ { PCI_VDEVICE(NVIDIA, 0x0d8a), board_ahci_mcp89 }, /* MCP89 */ { PCI_VDEVICE(NVIDIA, 0x0d8b), board_ahci_mcp89 }, /* MCP89 */ { PCI_VDEVICE(NVIDIA, 0x0d8c), board_ahci_mcp89 }, /* MCP89 */ { PCI_VDEVICE(NVIDIA, 0x0d8d), board_ahci_mcp89 }, /* MCP89 */ { PCI_VDEVICE(NVIDIA, 0x0d8e), board_ahci_mcp89 }, /* MCP89 */ { PCI_VDEVICE(NVIDIA, 0x0d8f), board_ahci_mcp89 }, /* MCP89 */ /* SiS */ { PCI_VDEVICE(SI, 0x1184), board_ahci }, /* SiS 966 */ { PCI_VDEVICE(SI, 0x1185), board_ahci }, /* SiS 968 */ { PCI_VDEVICE(SI, 0x0186), board_ahci }, /* SiS 968 */ /* ST Microelectronics */ { PCI_VDEVICE(STMICRO, 0xCC06), board_ahci }, /* ST ConneXt */ /* Marvell */ { PCI_VDEVICE(MARVELL, 0x6145), board_ahci_mv }, /* 6145 */ { PCI_VDEVICE(MARVELL, 0x6121), board_ahci_mv }, /* 6121 */ { PCI_DEVICE(PCI_VENDOR_ID_MARVELL_EXT, 0x9123), .class = PCI_CLASS_STORAGE_SATA_AHCI, .class_mask = 0xffffff, .driver_data = board_ahci_yes_fbs }, /* 88se9128 */ { PCI_DEVICE(PCI_VENDOR_ID_MARVELL_EXT, 0x9125), .driver_data = board_ahci_yes_fbs }, /* 88se9125 */ { PCI_DEVICE_SUB(PCI_VENDOR_ID_MARVELL_EXT, 0x9178, PCI_VENDOR_ID_MARVELL_EXT, 0x9170), .driver_data = board_ahci_yes_fbs }, /* 88se9170 */ { PCI_DEVICE(PCI_VENDOR_ID_MARVELL_EXT, 0x917a), .driver_data = board_ahci_yes_fbs }, /* 88se9172 */ { PCI_DEVICE(PCI_VENDOR_ID_MARVELL_EXT, 0x9172), .driver_data = board_ahci_yes_fbs }, /* 88se9182 */ { PCI_DEVICE(PCI_VENDOR_ID_MARVELL_EXT, 0x9182), .driver_data = board_ahci_yes_fbs }, /* 88se9172 */ { PCI_DEVICE(PCI_VENDOR_ID_MARVELL_EXT, 0x9192), .driver_data = board_ahci_yes_fbs }, /* 88se9172 on some Gigabyte */ { PCI_DEVICE(PCI_VENDOR_ID_MARVELL_EXT, 0x91a0), .driver_data = board_ahci_yes_fbs }, { PCI_DEVICE(PCI_VENDOR_ID_MARVELL_EXT, 0x91a2), /* 88se91a2 */ .driver_data = board_ahci_yes_fbs }, { PCI_DEVICE(PCI_VENDOR_ID_MARVELL_EXT, 0x91a3), .driver_data = board_ahci_yes_fbs }, { PCI_DEVICE(PCI_VENDOR_ID_MARVELL_EXT, 0x9230), .driver_data = board_ahci_yes_fbs }, { PCI_DEVICE(PCI_VENDOR_ID_TTI, 0x0642), .driver_data = board_ahci_yes_fbs }, /* Promise */ { PCI_VDEVICE(PROMISE, 0x3f20), board_ahci }, /* PDC42819 */ { PCI_VDEVICE(PROMISE, 0x3781), board_ahci }, /* FastTrak TX8660 ahci-mode */ /* Asmedia */ { PCI_VDEVICE(ASMEDIA, 0x0601), board_ahci }, /* ASM1060 */ { PCI_VDEVICE(ASMEDIA, 0x0602), board_ahci }, /* ASM1060 */ { PCI_VDEVICE(ASMEDIA, 0x0611), board_ahci }, /* ASM1061 */ { PCI_VDEVICE(ASMEDIA, 0x0612), board_ahci }, /* ASM1062 */ /* * Samsung SSDs found on some macbooks. NCQ times out if MSI is * enabled. https://bugzilla.kernel.org/show_bug.cgi?id=60731 */ { PCI_VDEVICE(SAMSUNG, 0x1600), board_ahci_nomsi }, { PCI_VDEVICE(SAMSUNG, 0xa800), board_ahci_nomsi }, /* Enmotus */ { PCI_DEVICE(0x1c44, 0x8000), board_ahci }, /* Generic, PCI class code for AHCI */ { PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_STORAGE_SATA_AHCI, 0xffffff, board_ahci }, { } /* terminate list */ }; static const struct dev_pm_ops ahci_pci_pm_ops = { SET_SYSTEM_SLEEP_PM_OPS(ahci_pci_device_suspend, ahci_pci_device_resume) SET_RUNTIME_PM_OPS(ahci_pci_device_runtime_suspend, ahci_pci_device_runtime_resume, NULL) }; static struct pci_driver ahci_pci_driver = { .name = DRV_NAME, .id_table = ahci_pci_tbl, .probe = ahci_init_one, .remove = ahci_remove_one, .driver = { .pm = &ahci_pci_pm_ops, }, }; #if IS_ENABLED(CONFIG_PATA_MARVELL) static int marvell_enable; #else static int marvell_enable = 1; #endif module_param(marvell_enable, int, 0644); MODULE_PARM_DESC(marvell_enable, "Marvell SATA via AHCI (1 = enabled)"); static void ahci_pci_save_initial_config(struct pci_dev *pdev, struct ahci_host_priv *hpriv) { if (pdev->vendor == PCI_VENDOR_ID_JMICRON && pdev->device == 0x2361) { dev_info(&pdev->dev, "JMB361 has only one port\n"); hpriv->force_port_map = 1; } /* * Temporary Marvell 6145 hack: PATA port presence * is asserted through the standard AHCI port * presence register, as bit 4 (counting from 0) */ if (hpriv->flags & AHCI_HFLAG_MV_PATA) { if (pdev->device == 0x6121) hpriv->mask_port_map = 0x3; else hpriv->mask_port_map = 0xf; dev_info(&pdev->dev, "Disabling your PATA port. Use the boot option 'ahci.marvell_enable=0' to avoid this.\n"); } ahci_save_initial_config(&pdev->dev, hpriv); } static int ahci_pci_reset_controller(struct ata_host *host) { struct pci_dev *pdev = to_pci_dev(host->dev); ahci_reset_controller(host); if (pdev->vendor == PCI_VENDOR_ID_INTEL) { struct ahci_host_priv *hpriv = host->private_data; u16 tmp16; /* configure PCS */ pci_read_config_word(pdev, 0x92, &tmp16); if ((tmp16 & hpriv->port_map) != hpriv->port_map) { tmp16 |= hpriv->port_map; pci_write_config_word(pdev, 0x92, tmp16); } } return 0; } static void ahci_pci_init_controller(struct ata_host *host) { struct ahci_host_priv *hpriv = host->private_data; struct pci_dev *pdev = to_pci_dev(host->dev); void __iomem *port_mmio; u32 tmp; int mv; if (hpriv->flags & AHCI_HFLAG_MV_PATA) { if (pdev->device == 0x6121) mv = 2; else mv = 4; port_mmio = __ahci_port_base(host, mv); writel(0, port_mmio + PORT_IRQ_MASK); /* clear port IRQ */ tmp = readl(port_mmio + PORT_IRQ_STAT); VPRINTK("PORT_IRQ_STAT 0x%x\n", tmp); if (tmp) writel(tmp, port_mmio + PORT_IRQ_STAT); } ahci_init_controller(host); } static int ahci_vt8251_hardreset(struct ata_link *link, unsigned int *class, unsigned long deadline) { struct ata_port *ap = link->ap; struct ahci_host_priv *hpriv = ap->host->private_data; bool online; int rc; DPRINTK("ENTER\n"); ahci_stop_engine(ap); rc = sata_link_hardreset(link, sata_ehc_deb_timing(&link->eh_context), deadline, &online, NULL); hpriv->start_engine(ap); DPRINTK("EXIT, rc=%d, class=%u\n", rc, *class); /* vt8251 doesn't clear BSY on signature FIS reception, * request follow-up softreset. */ return online ? -EAGAIN : rc; } static int ahci_p5wdh_hardreset(struct ata_link *link, unsigned int *class, unsigned long deadline) { struct ata_port *ap = link->ap; struct ahci_port_priv *pp = ap->private_data; struct ahci_host_priv *hpriv = ap->host->private_data; u8 *d2h_fis = pp->rx_fis + RX_FIS_D2H_REG; struct ata_taskfile tf; bool online; int rc; ahci_stop_engine(ap); /* clear D2H reception area to properly wait for D2H FIS */ ata_tf_init(link->device, &tf); tf.command = ATA_BUSY; ata_tf_to_fis(&tf, 0, 0, d2h_fis); rc = sata_link_hardreset(link, sata_ehc_deb_timing(&link->eh_context), deadline, &online, NULL); hpriv->start_engine(ap); /* The pseudo configuration device on SIMG4726 attached to * ASUS P5W-DH Deluxe doesn't send signature FIS after * hardreset if no device is attached to the first downstream * port && the pseudo device locks up on SRST w/ PMP==0. To * work around this, wait for !BSY only briefly. If BSY isn't * cleared, perform CLO and proceed to IDENTIFY (achieved by * ATA_LFLAG_NO_SRST and ATA_LFLAG_ASSUME_ATA). * * Wait for two seconds. Devices attached to downstream port * which can't process the following IDENTIFY after this will * have to be reset again. For most cases, this should * suffice while making probing snappish enough. */ if (online) { rc = ata_wait_after_reset(link, jiffies + 2 * HZ, ahci_check_ready); if (rc) ahci_kick_engine(ap); } return rc; } /* * ahci_avn_hardreset - attempt more aggressive recovery of Avoton ports. * * It has been observed with some SSDs that the timing of events in the * link synchronization phase can leave the port in a state that can not * be recovered by a SATA-hard-reset alone. The failing signature is * SStatus.DET stuck at 1 ("Device presence detected but Phy * communication not established"). It was found that unloading and * reloading the driver when this problem occurs allows the drive * connection to be recovered (DET advanced to 0x3). The critical * component of reloading the driver is that the port state machines are * reset by bouncing "port enable" in the AHCI PCS configuration * register. So, reproduce that effect by bouncing a port whenever we * see DET==1 after a reset. */ static int ahci_avn_hardreset(struct ata_link *link, unsigned int *class, unsigned long deadline) { const unsigned long *timing = sata_ehc_deb_timing(&link->eh_context); struct ata_port *ap = link->ap; struct ahci_port_priv *pp = ap->private_data; struct ahci_host_priv *hpriv = ap->host->private_data; u8 *d2h_fis = pp->rx_fis + RX_FIS_D2H_REG; unsigned long tmo = deadline - jiffies; struct ata_taskfile tf; bool online; int rc, i; DPRINTK("ENTER\n"); ahci_stop_engine(ap); for (i = 0; i < 2; i++) { u16 val; u32 sstatus; int port = ap->port_no; struct ata_host *host = ap->host; struct pci_dev *pdev = to_pci_dev(host->dev); /* clear D2H reception area to properly wait for D2H FIS */ ata_tf_init(link->device, &tf); tf.command = ATA_BUSY; ata_tf_to_fis(&tf, 0, 0, d2h_fis); rc = sata_link_hardreset(link, timing, deadline, &online, ahci_check_ready); if (sata_scr_read(link, SCR_STATUS, &sstatus) != 0 || (sstatus & 0xf) != 1) break; ata_link_printk(link, KERN_INFO, "avn bounce port%d\n", port); pci_read_config_word(pdev, 0x92, &val); val &= ~(1 << port); pci_write_config_word(pdev, 0x92, val); ata_msleep(ap, 1000); val |= 1 << port; pci_write_config_word(pdev, 0x92, val); deadline += tmo; } hpriv->start_engine(ap); if (online) *class = ahci_dev_classify(ap); DPRINTK("EXIT, rc=%d, class=%u\n", rc, *class); return rc; } #ifdef CONFIG_PM static void ahci_pci_disable_interrupts(struct ata_host *host) { struct ahci_host_priv *hpriv = host->private_data; void __iomem *mmio = hpriv->mmio; u32 ctl; /* AHCI spec rev1.1 section 8.3.3: * Software must disable interrupts prior to requesting a * transition of the HBA to D3 state. */ ctl = readl(mmio + HOST_CTL); ctl &= ~HOST_IRQ_EN; writel(ctl, mmio + HOST_CTL); readl(mmio + HOST_CTL); /* flush */ } static int ahci_pci_device_runtime_suspend(struct device *dev) { struct pci_dev *pdev = to_pci_dev(dev); struct ata_host *host = pci_get_drvdata(pdev); ahci_pci_disable_interrupts(host); return 0; } static int ahci_pci_device_runtime_resume(struct device *dev) { struct pci_dev *pdev = to_pci_dev(dev); struct ata_host *host = pci_get_drvdata(pdev); int rc; rc = ahci_pci_reset_controller(host); if (rc) return rc; ahci_pci_init_controller(host); return 0; } #ifdef CONFIG_PM_SLEEP static int ahci_pci_device_suspend(struct device *dev) { struct pci_dev *pdev = to_pci_dev(dev); struct ata_host *host = pci_get_drvdata(pdev); struct ahci_host_priv *hpriv = host->private_data; if (hpriv->flags & AHCI_HFLAG_NO_SUSPEND) { dev_err(&pdev->dev, "BIOS update required for suspend/resume\n"); return -EIO; } ahci_pci_disable_interrupts(host); return ata_host_suspend(host, PMSG_SUSPEND); } static int ahci_pci_device_resume(struct device *dev) { struct pci_dev *pdev = to_pci_dev(dev); struct ata_host *host = pci_get_drvdata(pdev); int rc; /* Apple BIOS helpfully mangles the registers on resume */ if (is_mcp89_apple(pdev)) ahci_mcp89_apple_enable(pdev); if (pdev->dev.power.power_state.event == PM_EVENT_SUSPEND) { rc = ahci_pci_reset_controller(host); if (rc) return rc; ahci_pci_init_controller(host); } ata_host_resume(host); return 0; } #endif #endif /* CONFIG_PM */ static int ahci_configure_dma_masks(struct pci_dev *pdev, int using_dac) { int rc; /* * If the device fixup already set the dma_mask to some non-standard * value, don't extend it here. This happens on STA2X11, for example. */ if (pdev->dma_mask && pdev->dma_mask < DMA_BIT_MASK(32)) return 0; if (using_dac && !dma_set_mask(&pdev->dev, DMA_BIT_MASK(64))) { rc = dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(64)); if (rc) { rc = dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(32)); if (rc) { dev_err(&pdev->dev, "64-bit DMA enable failed\n"); return rc; } } } else { rc = dma_set_mask(&pdev->dev, DMA_BIT_MASK(32)); if (rc) { dev_err(&pdev->dev, "32-bit DMA enable failed\n"); return rc; } rc = dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(32)); if (rc) { dev_err(&pdev->dev, "32-bit consistent DMA enable failed\n"); return rc; } } return 0; } static void ahci_pci_print_info(struct ata_host *host) { struct pci_dev *pdev = to_pci_dev(host->dev); u16 cc; const char *scc_s; pci_read_config_word(pdev, 0x0a, &cc); if (cc == PCI_CLASS_STORAGE_IDE) scc_s = "IDE"; else if (cc == PCI_CLASS_STORAGE_SATA) scc_s = "SATA"; else if (cc == PCI_CLASS_STORAGE_RAID) scc_s = "RAID"; else scc_s = "unknown"; ahci_print_info(host, scc_s); } /* On ASUS P5W DH Deluxe, the second port of PCI device 00:1f.2 is * hardwired to on-board SIMG 4726. The chipset is ICH8 and doesn't * support PMP and the 4726 either directly exports the device * attached to the first downstream port or acts as a hardware storage * controller and emulate a single ATA device (can be RAID 0/1 or some * other configuration). * * When there's no device attached to the first downstream port of the * 4726, "Config Disk" appears, which is a pseudo ATA device to * configure the 4726. However, ATA emulation of the device is very * lame. It doesn't send signature D2H Reg FIS after the initial * hardreset, pukes on SRST w/ PMP==0 and has bunch of other issues. * * The following function works around the problem by always using * hardreset on the port and not depending on receiving signature FIS * afterward. If signature FIS isn't received soon, ATA class is * assumed without follow-up softreset. */ static void ahci_p5wdh_workaround(struct ata_host *host) { static const struct dmi_system_id sysids[] = { { .ident = "P5W DH Deluxe", .matches = { DMI_MATCH(DMI_SYS_VENDOR, "ASUSTEK COMPUTER INC"), DMI_MATCH(DMI_PRODUCT_NAME, "P5W DH Deluxe"), }, }, { } }; struct pci_dev *pdev = to_pci_dev(host->dev); if (pdev->bus->number == 0 && pdev->devfn == PCI_DEVFN(0x1f, 2) && dmi_check_system(sysids)) { struct ata_port *ap = host->ports[1]; dev_info(&pdev->dev, "enabling ASUS P5W DH Deluxe on-board SIMG4726 workaround\n"); ap->ops = &ahci_p5wdh_ops; ap->link.flags |= ATA_LFLAG_NO_SRST | ATA_LFLAG_ASSUME_ATA; } } /* * Macbook7,1 firmware forcibly disables MCP89 AHCI and changes PCI ID when * booting in BIOS compatibility mode. We restore the registers but not ID. */ static void ahci_mcp89_apple_enable(struct pci_dev *pdev) { u32 val; printk(KERN_INFO "ahci: enabling MCP89 AHCI mode\n"); pci_read_config_dword(pdev, 0xf8, &val); val |= 1 << 0x1b; /* the following changes the device ID, but appears not to affect function */ /* val = (val & ~0xf0000000) | 0x80000000; */ pci_write_config_dword(pdev, 0xf8, val); pci_read_config_dword(pdev, 0x54c, &val); val |= 1 << 0xc; pci_write_config_dword(pdev, 0x54c, val); pci_read_config_dword(pdev, 0x4a4, &val); val &= 0xff; val |= 0x01060100; pci_write_config_dword(pdev, 0x4a4, val); pci_read_config_dword(pdev, 0x54c, &val); val &= ~(1 << 0xc); pci_write_config_dword(pdev, 0x54c, val); pci_read_config_dword(pdev, 0xf8, &val); val &= ~(1 << 0x1b); pci_write_config_dword(pdev, 0xf8, val); } static bool is_mcp89_apple(struct pci_dev *pdev) { return pdev->vendor == PCI_VENDOR_ID_NVIDIA && pdev->device == PCI_DEVICE_ID_NVIDIA_NFORCE_MCP89_SATA && pdev->subsystem_vendor == PCI_VENDOR_ID_APPLE && pdev->subsystem_device == 0xcb89; } /* only some SB600 ahci controllers can do 64bit DMA */ static bool ahci_sb600_enable_64bit(struct pci_dev *pdev) { static const struct dmi_system_id sysids[] = { /* * The oldest version known to be broken is 0901 and * working is 1501 which was released on 2007-10-26. * Enable 64bit DMA on 1501 and anything newer. * * Please read bko#9412 for more info. */ { .ident = "ASUS M2A-VM", .matches = { DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTeK Computer INC."), DMI_MATCH(DMI_BOARD_NAME, "M2A-VM"), }, .driver_data = "20071026", /* yyyymmdd */ }, /* * All BIOS versions for the MSI K9A2 Platinum (MS-7376) * support 64bit DMA. * * BIOS versions earlier than 1.5 had the Manufacturer DMI * fields as "MICRO-STAR INTERANTIONAL CO.,LTD". * This spelling mistake was fixed in BIOS version 1.5, so * 1.5 and later have the Manufacturer as * "MICRO-STAR INTERNATIONAL CO.,LTD". * So try to match on DMI_BOARD_VENDOR of "MICRO-STAR INTER". * * BIOS versions earlier than 1.9 had a Board Product Name * DMI field of "MS-7376". This was changed to be * "K9A2 Platinum (MS-7376)" in version 1.9, but we can still * match on DMI_BOARD_NAME of "MS-7376". */ { .ident = "MSI K9A2 Platinum", .matches = { DMI_MATCH(DMI_BOARD_VENDOR, "MICRO-STAR INTER"), DMI_MATCH(DMI_BOARD_NAME, "MS-7376"), }, }, /* * All BIOS versions for the MSI K9AGM2 (MS-7327) support * 64bit DMA. * * This board also had the typo mentioned above in the * Manufacturer DMI field (fixed in BIOS version 1.5), so * match on DMI_BOARD_VENDOR of "MICRO-STAR INTER" again. */ { .ident = "MSI K9AGM2", .matches = { DMI_MATCH(DMI_BOARD_VENDOR, "MICRO-STAR INTER"), DMI_MATCH(DMI_BOARD_NAME, "MS-7327"), }, }, /* * All BIOS versions for the Asus M3A support 64bit DMA. * (all release versions from 0301 to 1206 were tested) */ { .ident = "ASUS M3A", .matches = { DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTeK Computer INC."), DMI_MATCH(DMI_BOARD_NAME, "M3A"), }, }, { } }; const struct dmi_system_id *match; int year, month, date; char buf[9]; match = dmi_first_match(sysids); if (pdev->bus->number != 0 || pdev->devfn != PCI_DEVFN(0x12, 0) || !match) return false; if (!match->driver_data) goto enable_64bit; dmi_get_date(DMI_BIOS_DATE, &year, &month, &date); snprintf(buf, sizeof(buf), "%04d%02d%02d", year, month, date); if (strcmp(buf, match->driver_data) >= 0) goto enable_64bit; else { dev_warn(&pdev->dev, "%s: BIOS too old, forcing 32bit DMA, update BIOS\n", match->ident); return false; } enable_64bit: dev_warn(&pdev->dev, "%s: enabling 64bit DMA\n", match->ident); return true; } static bool ahci_broken_system_poweroff(struct pci_dev *pdev) { static const struct dmi_system_id broken_systems[] = { { .ident = "HP Compaq nx6310", .matches = { DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"), DMI_MATCH(DMI_PRODUCT_NAME, "HP Compaq nx6310"), }, /* PCI slot number of the controller */ .driver_data = (void *)0x1FUL, }, { .ident = "HP Compaq 6720s", .matches = { DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"), DMI_MATCH(DMI_PRODUCT_NAME, "HP Compaq 6720s"), }, /* PCI slot number of the controller */ .driver_data = (void *)0x1FUL, }, { } /* terminate list */ }; const struct dmi_system_id *dmi = dmi_first_match(broken_systems); if (dmi) { unsigned long slot = (unsigned long)dmi->driver_data; /* apply the quirk only to on-board controllers */ return slot == PCI_SLOT(pdev->devfn); } return false; } static bool ahci_broken_suspend(struct pci_dev *pdev) { static const struct dmi_system_id sysids[] = { /* * On HP dv[4-6] and HDX18 with earlier BIOSen, link * to the harddisk doesn't become online after * resuming from STR. Warn and fail suspend. * * http://bugzilla.kernel.org/show_bug.cgi?id=12276 * * Use dates instead of versions to match as HP is * apparently recycling both product and version * strings. * * http://bugzilla.kernel.org/show_bug.cgi?id=15462 */ { .ident = "dv4", .matches = { DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"), DMI_MATCH(DMI_PRODUCT_NAME, "HP Pavilion dv4 Notebook PC"), }, .driver_data = "20090105", /* F.30 */ }, { .ident = "dv5", .matches = { DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"), DMI_MATCH(DMI_PRODUCT_NAME, "HP Pavilion dv5 Notebook PC"), }, .driver_data = "20090506", /* F.16 */ }, { .ident = "dv6", .matches = { DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"), DMI_MATCH(DMI_PRODUCT_NAME, "HP Pavilion dv6 Notebook PC"), }, .driver_data = "20090423", /* F.21 */ }, { .ident = "HDX18", .matches = { DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"), DMI_MATCH(DMI_PRODUCT_NAME, "HP HDX18 Notebook PC"), }, .driver_data = "20090430", /* F.23 */ }, /* * Acer eMachines G725 has the same problem. BIOS * V1.03 is known to be broken. V3.04 is known to * work. Between, there are V1.06, V2.06 and V3.03 * that we don't have much idea about. For now, * blacklist anything older than V3.04. * * http://bugzilla.kernel.org/show_bug.cgi?id=15104 */ { .ident = "G725", .matches = { DMI_MATCH(DMI_SYS_VENDOR, "eMachines"), DMI_MATCH(DMI_PRODUCT_NAME, "eMachines G725"), }, .driver_data = "20091216", /* V3.04 */ }, { } /* terminate list */ }; const struct dmi_system_id *dmi = dmi_first_match(sysids); int year, month, date; char buf[9]; if (!dmi || pdev->bus->number || pdev->devfn != PCI_DEVFN(0x1f, 2)) return false; dmi_get_date(DMI_BIOS_DATE, &year, &month, &date); snprintf(buf, sizeof(buf), "%04d%02d%02d", year, month, date); return strcmp(buf, dmi->driver_data) < 0; } static bool ahci_broken_online(struct pci_dev *pdev) { #define ENCODE_BUSDEVFN(bus, slot, func) \ (void *)(unsigned long)(((bus) << 8) | PCI_DEVFN((slot), (func))) static const struct dmi_system_id sysids[] = { /* * There are several gigabyte boards which use * SIMG5723s configured as hardware RAID. Certain * 5723 firmware revisions shipped there keep the link * online but fail to answer properly to SRST or * IDENTIFY when no device is attached downstream * causing libata to retry quite a few times leading * to excessive detection delay. * * As these firmwares respond to the second reset try * with invalid device signature, considering unknown * sig as offline works around the problem acceptably. */ { .ident = "EP45-DQ6", .matches = { DMI_MATCH(DMI_BOARD_VENDOR, "Gigabyte Technology Co., Ltd."), DMI_MATCH(DMI_BOARD_NAME, "EP45-DQ6"), }, .driver_data = ENCODE_BUSDEVFN(0x0a, 0x00, 0), }, { .ident = "EP45-DS5", .matches = { DMI_MATCH(DMI_BOARD_VENDOR, "Gigabyte Technology Co., Ltd."), DMI_MATCH(DMI_BOARD_NAME, "EP45-DS5"), }, .driver_data = ENCODE_BUSDEVFN(0x03, 0x00, 0), }, { } /* terminate list */ }; #undef ENCODE_BUSDEVFN const struct dmi_system_id *dmi = dmi_first_match(sysids); unsigned int val; if (!dmi) return false; val = (unsigned long)dmi->driver_data; return pdev->bus->number == (val >> 8) && pdev->devfn == (val & 0xff); } static bool ahci_broken_devslp(struct pci_dev *pdev) { /* device with broken DEVSLP but still showing SDS capability */ static const struct pci_device_id ids[] = { { PCI_VDEVICE(INTEL, 0x0f23)}, /* Valleyview SoC */ {} }; return pci_match_id(ids, pdev); } #ifdef CONFIG_ATA_ACPI static void ahci_gtf_filter_workaround(struct ata_host *host) { static const struct dmi_system_id sysids[] = { /* * Aspire 3810T issues a bunch of SATA enable commands * via _GTF including an invalid one and one which is * rejected by the device. Among the successful ones * is FPDMA non-zero offset enable which when enabled * only on the drive side leads to NCQ command * failures. Filter it out. */ { .ident = "Aspire 3810T", .matches = { DMI_MATCH(DMI_SYS_VENDOR, "Acer"), DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 3810T"), }, .driver_data = (void *)ATA_ACPI_FILTER_FPDMA_OFFSET, }, { } }; const struct dmi_system_id *dmi = dmi_first_match(sysids); unsigned int filter; int i; if (!dmi) return; filter = (unsigned long)dmi->driver_data; dev_info(host->dev, "applying extra ACPI _GTF filter 0x%x for %s\n", filter, dmi->ident); for (i = 0; i < host->n_ports; i++) { struct ata_port *ap = host->ports[i]; struct ata_link *link; struct ata_device *dev; ata_for_each_link(link, ap, EDGE) ata_for_each_dev(dev, link, ALL) dev->gtf_filter |= filter; } } #else static inline void ahci_gtf_filter_workaround(struct ata_host *host) {} #endif /* * On the Acer Aspire Switch Alpha 12, sometimes all SATA ports are detected * as DUMMY, or detected but eventually get a "link down" and never get up * again. When this happens, CAP.NP may hold a value of 0x00 or 0x01, and the * port_map may hold a value of 0x00. * * Overriding CAP.NP to 0x02 and the port_map to 0x7 will reveal all 3 ports * and can significantly reduce the occurrence of the problem. * * https://bugzilla.kernel.org/show_bug.cgi?id=189471 */ static void acer_sa5_271_workaround(struct ahci_host_priv *hpriv, struct pci_dev *pdev) { static const struct dmi_system_id sysids[] = { { .ident = "Acer Switch Alpha 12", .matches = { DMI_MATCH(DMI_SYS_VENDOR, "Acer"), DMI_MATCH(DMI_PRODUCT_NAME, "Switch SA5-271") }, }, { } }; if (dmi_check_system(sysids)) { dev_info(&pdev->dev, "enabling Acer Switch Alpha 12 workaround\n"); if ((hpriv->saved_cap & 0xC734FF00) == 0xC734FF00) { hpriv->port_map = 0x7; hpriv->cap = 0xC734FF02; } } } #ifdef CONFIG_ARM64 /* * Due to ERRATA#22536, ThunderX needs to handle HOST_IRQ_STAT differently. * Workaround is to make sure all pending IRQs are served before leaving * handler. */ static irqreturn_t ahci_thunderx_irq_handler(int irq, void *dev_instance) { struct ata_host *host = dev_instance; struct ahci_host_priv *hpriv; unsigned int rc = 0; void __iomem *mmio; u32 irq_stat, irq_masked; unsigned int handled = 1; VPRINTK("ENTER\n"); hpriv = host->private_data; mmio = hpriv->mmio; irq_stat = readl(mmio + HOST_IRQ_STAT); if (!irq_stat) return IRQ_NONE; do { irq_masked = irq_stat & hpriv->port_map; spin_lock(&host->lock); rc = ahci_handle_port_intr(host, irq_masked); if (!rc) handled = 0; writel(irq_stat, mmio + HOST_IRQ_STAT); irq_stat = readl(mmio + HOST_IRQ_STAT); spin_unlock(&host->lock); } while (irq_stat); VPRINTK("EXIT\n"); return IRQ_RETVAL(handled); } #endif static void ahci_remap_check(struct pci_dev *pdev, int bar, struct ahci_host_priv *hpriv) { int i, count = 0; u32 cap; /* * Check if this device might have remapped nvme devices. */ if (pdev->vendor != PCI_VENDOR_ID_INTEL || pci_resource_len(pdev, bar) < SZ_512K || bar != AHCI_PCI_BAR_STANDARD || !(readl(hpriv->mmio + AHCI_VSCAP) & 1)) return; cap = readq(hpriv->mmio + AHCI_REMAP_CAP); for (i = 0; i < AHCI_MAX_REMAP; i++) { if ((cap & (1 << i)) == 0) continue; if (readl(hpriv->mmio + ahci_remap_dcc(i)) != PCI_CLASS_STORAGE_EXPRESS) continue; /* We've found a remapped device */ count++; } if (!count) return; dev_warn(&pdev->dev, "Found %d remapped NVMe devices.\n", count); dev_warn(&pdev->dev, "Switch your BIOS from RAID to AHCI mode to use them.\n"); } static int ahci_get_irq_vector(struct ata_host *host, int port) { return pci_irq_vector(to_pci_dev(host->dev), port); } static int ahci_init_msi(struct pci_dev *pdev, unsigned int n_ports, struct ahci_host_priv *hpriv) { int nvec; if (hpriv->flags & AHCI_HFLAG_NO_MSI) return -ENODEV; /* * If number of MSIs is less than number of ports then Sharing Last * Message mode could be enforced. In this case assume that advantage * of multipe MSIs is negated and use single MSI mode instead. */ if (n_ports > 1) { nvec = pci_alloc_irq_vectors(pdev, n_ports, INT_MAX, PCI_IRQ_MSIX | PCI_IRQ_MSI); if (nvec > 0) { if (!(readl(hpriv->mmio + HOST_CTL) & HOST_MRSM)) { hpriv->get_irq_vector = ahci_get_irq_vector; hpriv->flags |= AHCI_HFLAG_MULTI_MSI; return nvec; } /* * Fallback to single MSI mode if the controller * enforced MRSM mode. */ printk(KERN_INFO "ahci: MRSM is on, fallback to single MSI\n"); pci_free_irq_vectors(pdev); } } /* * If the host is not capable of supporting per-port vectors, fall * back to single MSI before finally attempting single MSI-X. */ nvec = pci_alloc_irq_vectors(pdev, 1, 1, PCI_IRQ_MSI); if (nvec == 1) return nvec; return pci_alloc_irq_vectors(pdev, 1, 1, PCI_IRQ_MSIX); } static int ahci_init_one(struct pci_dev *pdev, const struct pci_device_id *ent) { unsigned int board_id = ent->driver_data; struct ata_port_info pi = ahci_port_info[board_id]; const struct ata_port_info *ppi[] = { &pi, NULL }; struct device *dev = &pdev->dev; struct ahci_host_priv *hpriv; struct ata_host *host; int n_ports, i, rc; int ahci_pci_bar = AHCI_PCI_BAR_STANDARD; VPRINTK("ENTER\n"); WARN_ON((int)ATA_MAX_QUEUE > AHCI_MAX_CMDS); ata_print_version_once(&pdev->dev, DRV_VERSION); /* The AHCI driver can only drive the SATA ports, the PATA driver can drive them all so if both drivers are selected make sure AHCI stays out of the way */ if (pdev->vendor == PCI_VENDOR_ID_MARVELL && !marvell_enable) return -ENODEV; /* Apple BIOS on MCP89 prevents us using AHCI */ if (is_mcp89_apple(pdev)) ahci_mcp89_apple_enable(pdev); /* Promise's PDC42819 is a SAS/SATA controller that has an AHCI mode. * At the moment, we can only use the AHCI mode. Let the users know * that for SAS drives they're out of luck. */ if (pdev->vendor == PCI_VENDOR_ID_PROMISE) dev_info(&pdev->dev, "PDC42819 can only drive SATA devices with this driver\n"); /* Some devices use non-standard BARs */ if (pdev->vendor == PCI_VENDOR_ID_STMICRO && pdev->device == 0xCC06) ahci_pci_bar = AHCI_PCI_BAR_STA2X11; else if (pdev->vendor == 0x1c44 && pdev->device == 0x8000) ahci_pci_bar = AHCI_PCI_BAR_ENMOTUS; else if (pdev->vendor == 0x177d && pdev->device == 0xa01c) ahci_pci_bar = AHCI_PCI_BAR_CAVIUM; /* acquire resources */ rc = pcim_enable_device(pdev); if (rc) return rc; if (pdev->vendor == PCI_VENDOR_ID_INTEL && (pdev->device == 0x2652 || pdev->device == 0x2653)) { u8 map; /* ICH6s share the same PCI ID for both piix and ahci * modes. Enabling ahci mode while MAP indicates * combined mode is a bad idea. Yield to ata_piix. */ pci_read_config_byte(pdev, ICH_MAP, &map); if (map & 0x3) { dev_info(&pdev->dev, "controller is in combined mode, can't enable AHCI mode\n"); return -ENODEV; } } /* AHCI controllers often implement SFF compatible interface. * Grab all PCI BARs just in case. */ rc = pcim_iomap_regions_request_all(pdev, 1 << ahci_pci_bar, DRV_NAME); if (rc == -EBUSY) pcim_pin_device(pdev); if (rc) return rc; hpriv = devm_kzalloc(dev, sizeof(*hpriv), GFP_KERNEL); if (!hpriv) return -ENOMEM; hpriv->flags |= (unsigned long)pi.private_data; /* MCP65 revision A1 and A2 can't do MSI */ if (board_id == board_ahci_mcp65 && (pdev->revision == 0xa1 || pdev->revision == 0xa2)) hpriv->flags |= AHCI_HFLAG_NO_MSI; /* SB800 does NOT need the workaround to ignore SERR_INTERNAL */ if (board_id == board_ahci_sb700 && pdev->revision >= 0x40) hpriv->flags &= ~AHCI_HFLAG_IGN_SERR_INTERNAL; /* only some SB600s can do 64bit DMA */ if (ahci_sb600_enable_64bit(pdev)) hpriv->flags &= ~AHCI_HFLAG_32BIT_ONLY; hpriv->mmio = pcim_iomap_table(pdev)[ahci_pci_bar]; /* detect remapped nvme devices */ ahci_remap_check(pdev, ahci_pci_bar, hpriv); /* must set flag prior to save config in order to take effect */ if (ahci_broken_devslp(pdev)) hpriv->flags |= AHCI_HFLAG_NO_DEVSLP; #ifdef CONFIG_ARM64 if (pdev->vendor == 0x177d && pdev->device == 0xa01c) hpriv->irq_handler = ahci_thunderx_irq_handler; #endif /* save initial config */ ahci_pci_save_initial_config(pdev, hpriv); /* prepare host */ if (hpriv->cap & HOST_CAP_NCQ) { pi.flags |= ATA_FLAG_NCQ; /* * Auto-activate optimization is supposed to be * supported on all AHCI controllers indicating NCQ * capability, but it seems to be broken on some * chipsets including NVIDIAs. */ if (!(hpriv->flags & AHCI_HFLAG_NO_FPDMA_AA)) pi.flags |= ATA_FLAG_FPDMA_AA; /* * All AHCI controllers should be forward-compatible * with the new auxiliary field. This code should be * conditionalized if any buggy AHCI controllers are * encountered. */ pi.flags |= ATA_FLAG_FPDMA_AUX; } if (hpriv->cap & HOST_CAP_PMP) pi.flags |= ATA_FLAG_PMP; ahci_set_em_messages(hpriv, &pi); if (ahci_broken_system_poweroff(pdev)) { pi.flags |= ATA_FLAG_NO_POWEROFF_SPINDOWN; dev_info(&pdev->dev, "quirky BIOS, skipping spindown on poweroff\n"); } if (ahci_broken_suspend(pdev)) { hpriv->flags |= AHCI_HFLAG_NO_SUSPEND; dev_warn(&pdev->dev, "BIOS update required for suspend/resume\n"); } if (ahci_broken_online(pdev)) { hpriv->flags |= AHCI_HFLAG_SRST_TOUT_IS_OFFLINE; dev_info(&pdev->dev, "online status unreliable, applying workaround\n"); } /* Acer SA5-271 workaround modifies private_data */ acer_sa5_271_workaround(hpriv, pdev); /* CAP.NP sometimes indicate the index of the last enabled * port, at other times, that of the last possible port, so * determining the maximum port number requires looking at * both CAP.NP and port_map. */ n_ports = max(ahci_nr_ports(hpriv->cap), fls(hpriv->port_map)); host = ata_host_alloc_pinfo(&pdev->dev, ppi, n_ports); if (!host) return -ENOMEM; host->private_data = hpriv; if (ahci_init_msi(pdev, n_ports, hpriv) < 0) { /* legacy intx interrupts */ pci_intx(pdev, 1); } hpriv->irq = pci_irq_vector(pdev, 0); if (!(hpriv->cap & HOST_CAP_SSS) || ahci_ignore_sss) host->flags |= ATA_HOST_PARALLEL_SCAN; else dev_info(&pdev->dev, "SSS flag set, parallel bus scan disabled\n"); if (pi.flags & ATA_FLAG_EM) ahci_reset_em(host); for (i = 0; i < host->n_ports; i++) { struct ata_port *ap = host->ports[i]; ata_port_pbar_desc(ap, ahci_pci_bar, -1, "abar"); ata_port_pbar_desc(ap, ahci_pci_bar, 0x100 + ap->port_no * 0x80, "port"); /* set enclosure management message type */ if (ap->flags & ATA_FLAG_EM) ap->em_message_type = hpriv->em_msg_type; /* disabled/not-implemented port */ if (!(hpriv->port_map & (1 << i))) ap->ops = &ata_dummy_port_ops; } /* apply workaround for ASUS P5W DH Deluxe mainboard */ ahci_p5wdh_workaround(host); /* apply gtf filter quirk */ ahci_gtf_filter_workaround(host); /* initialize adapter */ rc = ahci_configure_dma_masks(pdev, hpriv->cap & HOST_CAP_64); if (rc) return rc; rc = ahci_pci_reset_controller(host); if (rc) return rc; ahci_pci_init_controller(host); ahci_pci_print_info(host); pci_set_master(pdev); rc = ahci_host_activate(host, &ahci_sht); if (rc) return rc; pm_runtime_put_noidle(&pdev->dev); return 0; } static void ahci_remove_one(struct pci_dev *pdev) { pm_runtime_get_noresume(&pdev->dev); ata_pci_remove_one(pdev); } module_pci_driver(ahci_pci_driver); MODULE_AUTHOR("Jeff Garzik"); MODULE_DESCRIPTION("AHCI SATA low-level driver"); MODULE_LICENSE("GPL"); MODULE_DEVICE_TABLE(pci, ahci_pci_tbl); MODULE_VERSION(DRV_VERSION);
gpl-2.0
pravsalam/clamav-antivirus
win32/clamav-for-windows/sigui/wxWidgets-2.9.1/src/tiff/port/lfind.c
14
2234
/* $Id$ */ /* * Copyright (c) 1989, 1993 * The Regents of the University of California. All rights reserved. * * This code is derived from software contributed to Berkeley by * Roger L. Snyder. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #if 0 static char sccsid[] = "@(#)lsearch.c 8.1 (Berkeley) 6/4/93"; __RCSID("$NetBSD: lsearch.c,v 1.2 2005/07/06 15:47:15 drochner Exp $"); #endif #include <sys/types.h> #ifndef NULL # define NULL 0 #endif void * lfind(const void *key, const void *base, size_t *nmemb, size_t size, int(*compar)(const void *, const void *)) { char *element, *end; end = (char *)base + *nmemb * size; for (element = (char *)base; element < end; element += size) if (!compar(element, key)) /* key found */ return element; return NULL; }
gpl-2.0
Nold360/GC-Linux-Kernel-2.6.32
drivers/net/wireless/hostap/hostap_info.c
526
14576
/* Host AP driver Info Frame processing (part of hostap.o module) */ #include <linux/if_arp.h> #include <linux/sched.h> #include "hostap_wlan.h" #include "hostap.h" #include "hostap_ap.h" /* Called only as a tasklet (software IRQ) */ static void prism2_info_commtallies16(local_info_t *local, unsigned char *buf, int left) { struct hfa384x_comm_tallies *tallies; if (left < sizeof(struct hfa384x_comm_tallies)) { printk(KERN_DEBUG "%s: too short (len=%d) commtallies " "info frame\n", local->dev->name, left); return; } tallies = (struct hfa384x_comm_tallies *) buf; #define ADD_COMM_TALLIES(name) \ local->comm_tallies.name += le16_to_cpu(tallies->name) ADD_COMM_TALLIES(tx_unicast_frames); ADD_COMM_TALLIES(tx_multicast_frames); ADD_COMM_TALLIES(tx_fragments); ADD_COMM_TALLIES(tx_unicast_octets); ADD_COMM_TALLIES(tx_multicast_octets); ADD_COMM_TALLIES(tx_deferred_transmissions); ADD_COMM_TALLIES(tx_single_retry_frames); ADD_COMM_TALLIES(tx_multiple_retry_frames); ADD_COMM_TALLIES(tx_retry_limit_exceeded); ADD_COMM_TALLIES(tx_discards); ADD_COMM_TALLIES(rx_unicast_frames); ADD_COMM_TALLIES(rx_multicast_frames); ADD_COMM_TALLIES(rx_fragments); ADD_COMM_TALLIES(rx_unicast_octets); ADD_COMM_TALLIES(rx_multicast_octets); ADD_COMM_TALLIES(rx_fcs_errors); ADD_COMM_TALLIES(rx_discards_no_buffer); ADD_COMM_TALLIES(tx_discards_wrong_sa); ADD_COMM_TALLIES(rx_discards_wep_undecryptable); ADD_COMM_TALLIES(rx_message_in_msg_fragments); ADD_COMM_TALLIES(rx_message_in_bad_msg_fragments); #undef ADD_COMM_TALLIES } /* Called only as a tasklet (software IRQ) */ static void prism2_info_commtallies32(local_info_t *local, unsigned char *buf, int left) { struct hfa384x_comm_tallies32 *tallies; if (left < sizeof(struct hfa384x_comm_tallies32)) { printk(KERN_DEBUG "%s: too short (len=%d) commtallies32 " "info frame\n", local->dev->name, left); return; } tallies = (struct hfa384x_comm_tallies32 *) buf; #define ADD_COMM_TALLIES(name) \ local->comm_tallies.name += le32_to_cpu(tallies->name) ADD_COMM_TALLIES(tx_unicast_frames); ADD_COMM_TALLIES(tx_multicast_frames); ADD_COMM_TALLIES(tx_fragments); ADD_COMM_TALLIES(tx_unicast_octets); ADD_COMM_TALLIES(tx_multicast_octets); ADD_COMM_TALLIES(tx_deferred_transmissions); ADD_COMM_TALLIES(tx_single_retry_frames); ADD_COMM_TALLIES(tx_multiple_retry_frames); ADD_COMM_TALLIES(tx_retry_limit_exceeded); ADD_COMM_TALLIES(tx_discards); ADD_COMM_TALLIES(rx_unicast_frames); ADD_COMM_TALLIES(rx_multicast_frames); ADD_COMM_TALLIES(rx_fragments); ADD_COMM_TALLIES(rx_unicast_octets); ADD_COMM_TALLIES(rx_multicast_octets); ADD_COMM_TALLIES(rx_fcs_errors); ADD_COMM_TALLIES(rx_discards_no_buffer); ADD_COMM_TALLIES(tx_discards_wrong_sa); ADD_COMM_TALLIES(rx_discards_wep_undecryptable); ADD_COMM_TALLIES(rx_message_in_msg_fragments); ADD_COMM_TALLIES(rx_message_in_bad_msg_fragments); #undef ADD_COMM_TALLIES } /* Called only as a tasklet (software IRQ) */ static void prism2_info_commtallies(local_info_t *local, unsigned char *buf, int left) { if (local->tallies32) prism2_info_commtallies32(local, buf, left); else prism2_info_commtallies16(local, buf, left); } #ifndef PRISM2_NO_STATION_MODES #ifndef PRISM2_NO_DEBUG static const char* hfa384x_linkstatus_str(u16 linkstatus) { switch (linkstatus) { case HFA384X_LINKSTATUS_CONNECTED: return "Connected"; case HFA384X_LINKSTATUS_DISCONNECTED: return "Disconnected"; case HFA384X_LINKSTATUS_AP_CHANGE: return "Access point change"; case HFA384X_LINKSTATUS_AP_OUT_OF_RANGE: return "Access point out of range"; case HFA384X_LINKSTATUS_AP_IN_RANGE: return "Access point in range"; case HFA384X_LINKSTATUS_ASSOC_FAILED: return "Association failed"; default: return "Unknown"; } } #endif /* PRISM2_NO_DEBUG */ /* Called only as a tasklet (software IRQ) */ static void prism2_info_linkstatus(local_info_t *local, unsigned char *buf, int left) { u16 val; int non_sta_mode; /* Alloc new JoinRequests to occur since LinkStatus for the previous * has been received */ local->last_join_time = 0; if (left != 2) { printk(KERN_DEBUG "%s: invalid linkstatus info frame " "length %d\n", local->dev->name, left); return; } non_sta_mode = local->iw_mode == IW_MODE_MASTER || local->iw_mode == IW_MODE_REPEAT || local->iw_mode == IW_MODE_MONITOR; val = buf[0] | (buf[1] << 8); if (!non_sta_mode || val != HFA384X_LINKSTATUS_DISCONNECTED) { PDEBUG(DEBUG_EXTRA, "%s: LinkStatus=%d (%s)\n", local->dev->name, val, hfa384x_linkstatus_str(val)); } if (non_sta_mode) { netif_carrier_on(local->dev); netif_carrier_on(local->ddev); return; } /* Get current BSSID later in scheduled task */ set_bit(PRISM2_INFO_PENDING_LINKSTATUS, &local->pending_info); local->prev_link_status = val; schedule_work(&local->info_queue); } static void prism2_host_roaming(local_info_t *local) { struct hfa384x_join_request req; struct net_device *dev = local->dev; struct hfa384x_hostscan_result *selected, *entry; int i; unsigned long flags; if (local->last_join_time && time_before(jiffies, local->last_join_time + 10 * HZ)) { PDEBUG(DEBUG_EXTRA, "%s: last join request has not yet been " "completed - waiting for it before issuing new one\n", dev->name); return; } /* ScanResults are sorted: first ESS results in decreasing signal * quality then IBSS results in similar order. * Trivial roaming policy: just select the first entry. * This could probably be improved by adding hysteresis to limit * number of handoffs, etc. * * Could do periodic RID_SCANREQUEST or Inquire F101 to get new * ScanResults */ spin_lock_irqsave(&local->lock, flags); if (local->last_scan_results == NULL || local->last_scan_results_count == 0) { spin_unlock_irqrestore(&local->lock, flags); PDEBUG(DEBUG_EXTRA, "%s: no scan results for host roaming\n", dev->name); return; } selected = &local->last_scan_results[0]; if (local->preferred_ap[0] || local->preferred_ap[1] || local->preferred_ap[2] || local->preferred_ap[3] || local->preferred_ap[4] || local->preferred_ap[5]) { /* Try to find preferred AP */ PDEBUG(DEBUG_EXTRA, "%s: Preferred AP BSSID %pM\n", dev->name, local->preferred_ap); for (i = 0; i < local->last_scan_results_count; i++) { entry = &local->last_scan_results[i]; if (memcmp(local->preferred_ap, entry->bssid, 6) == 0) { PDEBUG(DEBUG_EXTRA, "%s: using preferred AP " "selection\n", dev->name); selected = entry; break; } } } memcpy(req.bssid, selected->bssid, 6); req.channel = selected->chid; spin_unlock_irqrestore(&local->lock, flags); PDEBUG(DEBUG_EXTRA, "%s: JoinRequest: BSSID=%pM" " channel=%d\n", dev->name, req.bssid, le16_to_cpu(req.channel)); if (local->func->set_rid(dev, HFA384X_RID_JOINREQUEST, &req, sizeof(req))) { printk(KERN_DEBUG "%s: JoinRequest failed\n", dev->name); } local->last_join_time = jiffies; } static void hostap_report_scan_complete(local_info_t *local) { union iwreq_data wrqu; /* Inform user space about new scan results (just empty event, * SIOCGIWSCAN can be used to fetch data */ wrqu.data.length = 0; wrqu.data.flags = 0; wireless_send_event(local->dev, SIOCGIWSCAN, &wrqu, NULL); /* Allow SIOCGIWSCAN handling to occur since we have received * scanning result */ local->scan_timestamp = 0; } /* Called only as a tasklet (software IRQ) */ static void prism2_info_scanresults(local_info_t *local, unsigned char *buf, int left) { u16 *pos; int new_count, i; unsigned long flags; struct hfa384x_scan_result *res; struct hfa384x_hostscan_result *results, *prev; if (left < 4) { printk(KERN_DEBUG "%s: invalid scanresult info frame " "length %d\n", local->dev->name, left); return; } pos = (u16 *) buf; pos++; pos++; left -= 4; new_count = left / sizeof(struct hfa384x_scan_result); results = kmalloc(new_count * sizeof(struct hfa384x_hostscan_result), GFP_ATOMIC); if (results == NULL) return; /* Convert to hostscan result format. */ res = (struct hfa384x_scan_result *) pos; for (i = 0; i < new_count; i++) { memcpy(&results[i], &res[i], sizeof(struct hfa384x_scan_result)); results[i].atim = 0; } spin_lock_irqsave(&local->lock, flags); local->last_scan_type = PRISM2_SCAN; prev = local->last_scan_results; local->last_scan_results = results; local->last_scan_results_count = new_count; spin_unlock_irqrestore(&local->lock, flags); kfree(prev); hostap_report_scan_complete(local); /* Perform rest of ScanResults handling later in scheduled task */ set_bit(PRISM2_INFO_PENDING_SCANRESULTS, &local->pending_info); schedule_work(&local->info_queue); } /* Called only as a tasklet (software IRQ) */ static void prism2_info_hostscanresults(local_info_t *local, unsigned char *buf, int left) { int i, result_size, copy_len, new_count; struct hfa384x_hostscan_result *results, *prev; unsigned long flags; __le16 *pos; u8 *ptr; wake_up_interruptible(&local->hostscan_wq); if (left < 4) { printk(KERN_DEBUG "%s: invalid hostscanresult info frame " "length %d\n", local->dev->name, left); return; } pos = (__le16 *) buf; copy_len = result_size = le16_to_cpu(*pos); if (result_size == 0) { printk(KERN_DEBUG "%s: invalid result_size (0) in " "hostscanresults\n", local->dev->name); return; } if (copy_len > sizeof(struct hfa384x_hostscan_result)) copy_len = sizeof(struct hfa384x_hostscan_result); pos++; pos++; left -= 4; ptr = (u8 *) pos; new_count = left / result_size; results = kcalloc(new_count, sizeof(struct hfa384x_hostscan_result), GFP_ATOMIC); if (results == NULL) return; for (i = 0; i < new_count; i++) { memcpy(&results[i], ptr, copy_len); ptr += result_size; left -= result_size; } if (left) { printk(KERN_DEBUG "%s: short HostScan result entry (%d/%d)\n", local->dev->name, left, result_size); } spin_lock_irqsave(&local->lock, flags); local->last_scan_type = PRISM2_HOSTSCAN; prev = local->last_scan_results; local->last_scan_results = results; local->last_scan_results_count = new_count; spin_unlock_irqrestore(&local->lock, flags); kfree(prev); hostap_report_scan_complete(local); } #endif /* PRISM2_NO_STATION_MODES */ /* Called only as a tasklet (software IRQ) */ void hostap_info_process(local_info_t *local, struct sk_buff *skb) { struct hfa384x_info_frame *info; unsigned char *buf; int left; #ifndef PRISM2_NO_DEBUG int i; #endif /* PRISM2_NO_DEBUG */ info = (struct hfa384x_info_frame *) skb->data; buf = skb->data + sizeof(*info); left = skb->len - sizeof(*info); switch (le16_to_cpu(info->type)) { case HFA384X_INFO_COMMTALLIES: prism2_info_commtallies(local, buf, left); break; #ifndef PRISM2_NO_STATION_MODES case HFA384X_INFO_LINKSTATUS: prism2_info_linkstatus(local, buf, left); break; case HFA384X_INFO_SCANRESULTS: prism2_info_scanresults(local, buf, left); break; case HFA384X_INFO_HOSTSCANRESULTS: prism2_info_hostscanresults(local, buf, left); break; #endif /* PRISM2_NO_STATION_MODES */ #ifndef PRISM2_NO_DEBUG default: PDEBUG(DEBUG_EXTRA, "%s: INFO - len=%d type=0x%04x\n", local->dev->name, le16_to_cpu(info->len), le16_to_cpu(info->type)); PDEBUG(DEBUG_EXTRA, "Unknown info frame:"); for (i = 0; i < (left < 100 ? left : 100); i++) PDEBUG2(DEBUG_EXTRA, " %02x", buf[i]); PDEBUG2(DEBUG_EXTRA, "\n"); break; #endif /* PRISM2_NO_DEBUG */ } } #ifndef PRISM2_NO_STATION_MODES static void handle_info_queue_linkstatus(local_info_t *local) { int val = local->prev_link_status; int connected; union iwreq_data wrqu; connected = val == HFA384X_LINKSTATUS_CONNECTED || val == HFA384X_LINKSTATUS_AP_CHANGE || val == HFA384X_LINKSTATUS_AP_IN_RANGE; if (local->func->get_rid(local->dev, HFA384X_RID_CURRENTBSSID, local->bssid, ETH_ALEN, 1) < 0) { printk(KERN_DEBUG "%s: could not read CURRENTBSSID after " "LinkStatus event\n", local->dev->name); } else { PDEBUG(DEBUG_EXTRA, "%s: LinkStatus: BSSID=%pM\n", local->dev->name, (unsigned char *) local->bssid); if (local->wds_type & HOSTAP_WDS_AP_CLIENT) hostap_add_sta(local->ap, local->bssid); } /* Get BSSID if we have a valid AP address */ if (connected) { netif_carrier_on(local->dev); netif_carrier_on(local->ddev); memcpy(wrqu.ap_addr.sa_data, local->bssid, ETH_ALEN); } else { netif_carrier_off(local->dev); netif_carrier_off(local->ddev); memset(wrqu.ap_addr.sa_data, 0, ETH_ALEN); } wrqu.ap_addr.sa_family = ARPHRD_ETHER; /* * Filter out sequential disconnect events in order not to cause a * flood of SIOCGIWAP events that have a race condition with EAPOL * frames and can confuse wpa_supplicant about the current association * status. */ if (connected || local->prev_linkstatus_connected) wireless_send_event(local->dev, SIOCGIWAP, &wrqu, NULL); local->prev_linkstatus_connected = connected; } static void handle_info_queue_scanresults(local_info_t *local) { if (local->host_roaming == 1 && local->iw_mode == IW_MODE_INFRA) prism2_host_roaming(local); if (local->host_roaming == 2 && local->iw_mode == IW_MODE_INFRA && memcmp(local->preferred_ap, "\x00\x00\x00\x00\x00\x00", ETH_ALEN) != 0) { /* * Firmware seems to be getting into odd state in host_roaming * mode 2 when hostscan is used without join command, so try * to fix this by re-joining the current AP. This does not * actually trigger a new association if the current AP is * still in the scan results. */ prism2_host_roaming(local); } } /* Called only as scheduled task after receiving info frames (used to avoid * pending too much time in HW IRQ handler). */ static void handle_info_queue(struct work_struct *work) { local_info_t *local = container_of(work, local_info_t, info_queue); if (test_and_clear_bit(PRISM2_INFO_PENDING_LINKSTATUS, &local->pending_info)) handle_info_queue_linkstatus(local); if (test_and_clear_bit(PRISM2_INFO_PENDING_SCANRESULTS, &local->pending_info)) handle_info_queue_scanresults(local); } #endif /* PRISM2_NO_STATION_MODES */ void hostap_info_init(local_info_t *local) { skb_queue_head_init(&local->info_list); #ifndef PRISM2_NO_STATION_MODES INIT_WORK(&local->info_queue, handle_info_queue); #endif /* PRISM2_NO_STATION_MODES */ } EXPORT_SYMBOL(hostap_info_init); EXPORT_SYMBOL(hostap_info_process);
gpl-2.0
bantu/linux
arch/arm/mach-omap2/board-generic.c
526
8623
/* * Copyright (C) 2005 Nokia Corporation * Author: Paul Mundt <paul.mundt@nokia.com> * * Copyright (C) 2011 Texas Instruments Incorporated - http://www.ti.com/ * * Modified from the original mach-omap/omap2/board-generic.c did by Paul * to support the OMAP2+ device tree boards with an unique board file. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 as * published by the Free Software Foundation. */ #include <linux/io.h> #include <linux/of_irq.h> #include <linux/of_platform.h> #include <linux/irqdomain.h> #include <asm/mach/arch.h> #include "common.h" #if !(defined(CONFIG_ARCH_OMAP2) || defined(CONFIG_ARCH_OMAP3)) #define intc_of_init NULL #endif #ifndef CONFIG_ARCH_OMAP4 #define gic_of_init NULL #endif static const struct of_device_id omap_dt_match_table[] __initconst = { { .compatible = "simple-bus", }, { .compatible = "ti,omap-infra", }, { } }; static void __init omap_generic_init(void) { omapdss_early_init_of(); pdata_quirks_init(omap_dt_match_table); omapdss_init_of(); } #ifdef CONFIG_SOC_OMAP2420 static const char *const omap242x_boards_compat[] __initconst = { "ti,omap2420", NULL, }; DT_MACHINE_START(OMAP242X_DT, "Generic OMAP2420 (Flattened Device Tree)") .reserve = omap_reserve, .map_io = omap242x_map_io, .init_early = omap2420_init_early, .init_machine = omap_generic_init, .init_time = omap2_sync32k_timer_init, .dt_compat = omap242x_boards_compat, .restart = omap2xxx_restart, MACHINE_END #endif #ifdef CONFIG_SOC_OMAP2430 static const char *const omap243x_boards_compat[] __initconst = { "ti,omap2430", NULL, }; DT_MACHINE_START(OMAP243X_DT, "Generic OMAP2430 (Flattened Device Tree)") .reserve = omap_reserve, .map_io = omap243x_map_io, .init_early = omap2430_init_early, .init_machine = omap_generic_init, .init_time = omap2_sync32k_timer_init, .dt_compat = omap243x_boards_compat, .restart = omap2xxx_restart, MACHINE_END #endif #ifdef CONFIG_ARCH_OMAP3 /* Some boards need board name for legacy userspace in /proc/cpuinfo */ static const char *const n900_boards_compat[] __initconst = { "nokia,omap3-n900", NULL, }; DT_MACHINE_START(OMAP3_N900_DT, "Nokia RX-51 board") .reserve = omap_reserve, .map_io = omap3_map_io, .init_early = omap3430_init_early, .init_machine = omap_generic_init, .init_late = omap3_init_late, .init_time = omap3_sync32k_timer_init, .dt_compat = n900_boards_compat, .restart = omap3xxx_restart, MACHINE_END /* Generic omap3 boards, most boards can use these */ static const char *const omap3_boards_compat[] __initconst = { "ti,omap3430", "ti,omap3", NULL, }; DT_MACHINE_START(OMAP3_DT, "Generic OMAP3 (Flattened Device Tree)") .reserve = omap_reserve, .map_io = omap3_map_io, .init_early = omap3430_init_early, .init_machine = omap_generic_init, .init_late = omap3_init_late, .init_time = omap3_sync32k_timer_init, .dt_compat = omap3_boards_compat, .restart = omap3xxx_restart, MACHINE_END static const char *const omap36xx_boards_compat[] __initconst = { "ti,omap36xx", NULL, }; DT_MACHINE_START(OMAP36XX_DT, "Generic OMAP36xx (Flattened Device Tree)") .reserve = omap_reserve, .map_io = omap3_map_io, .init_early = omap3630_init_early, .init_machine = omap_generic_init, .init_late = omap3_init_late, .init_time = omap3_sync32k_timer_init, .dt_compat = omap36xx_boards_compat, .restart = omap3xxx_restart, MACHINE_END static const char *const omap3_gp_boards_compat[] __initconst = { "ti,omap3-beagle", "timll,omap3-devkit8000", NULL, }; DT_MACHINE_START(OMAP3_GP_DT, "Generic OMAP3-GP (Flattened Device Tree)") .reserve = omap_reserve, .map_io = omap3_map_io, .init_early = omap3430_init_early, .init_machine = omap_generic_init, .init_late = omap3_init_late, .init_time = omap3_secure_sync32k_timer_init, .dt_compat = omap3_gp_boards_compat, .restart = omap3xxx_restart, MACHINE_END static const char *const am3517_boards_compat[] __initconst = { "ti,am3517", NULL, }; DT_MACHINE_START(AM3517_DT, "Generic AM3517 (Flattened Device Tree)") .reserve = omap_reserve, .map_io = omap3_map_io, .init_early = am35xx_init_early, .init_machine = omap_generic_init, .init_late = omap3_init_late, .init_time = omap3_gptimer_timer_init, .dt_compat = am3517_boards_compat, .restart = omap3xxx_restart, MACHINE_END #endif #ifdef CONFIG_SOC_TI81XX static const char *const ti814x_boards_compat[] __initconst = { "ti,dm8148", "ti,dm814", NULL, }; DT_MACHINE_START(TI81XX_DT, "Generic ti814x (Flattened Device Tree)") .reserve = omap_reserve, .map_io = ti81xx_map_io, .init_early = ti814x_init_early, .init_machine = omap_generic_init, .init_late = ti81xx_init_late, .init_time = omap3_gptimer_timer_init, .dt_compat = ti814x_boards_compat, .restart = ti81xx_restart, MACHINE_END static const char *const ti816x_boards_compat[] __initconst = { "ti,dm8168", "ti,dm816", NULL, }; DT_MACHINE_START(TI816X_DT, "Generic ti816x (Flattened Device Tree)") .reserve = omap_reserve, .map_io = ti81xx_map_io, .init_early = ti816x_init_early, .init_machine = omap_generic_init, .init_late = ti81xx_init_late, .init_time = omap3_gptimer_timer_init, .dt_compat = ti816x_boards_compat, .restart = ti81xx_restart, MACHINE_END #endif #ifdef CONFIG_SOC_AM33XX static const char *const am33xx_boards_compat[] __initconst = { "ti,am33xx", NULL, }; DT_MACHINE_START(AM33XX_DT, "Generic AM33XX (Flattened Device Tree)") .reserve = omap_reserve, .map_io = am33xx_map_io, .init_early = am33xx_init_early, .init_machine = omap_generic_init, .init_late = am33xx_init_late, .init_time = omap3_gptimer_timer_init, .dt_compat = am33xx_boards_compat, .restart = am33xx_restart, MACHINE_END #endif #ifdef CONFIG_ARCH_OMAP4 static const char *const omap4_boards_compat[] __initconst = { "ti,omap4460", "ti,omap4430", "ti,omap4", NULL, }; DT_MACHINE_START(OMAP4_DT, "Generic OMAP4 (Flattened Device Tree)") .l2c_aux_val = OMAP_L2C_AUX_CTRL, .l2c_aux_mask = 0xcf9fffff, .l2c_write_sec = omap4_l2c310_write_sec, .reserve = omap_reserve, .smp = smp_ops(omap4_smp_ops), .map_io = omap4_map_io, .init_early = omap4430_init_early, .init_irq = omap_gic_of_init, .init_machine = omap_generic_init, .init_late = omap4430_init_late, .init_time = omap4_local_timer_init, .dt_compat = omap4_boards_compat, .restart = omap44xx_restart, MACHINE_END #endif #ifdef CONFIG_SOC_OMAP5 static const char *const omap5_boards_compat[] __initconst = { "ti,omap5432", "ti,omap5430", "ti,omap5", NULL, }; DT_MACHINE_START(OMAP5_DT, "Generic OMAP5 (Flattened Device Tree)") .reserve = omap_reserve, .smp = smp_ops(omap4_smp_ops), .map_io = omap5_map_io, .init_early = omap5_init_early, .init_irq = omap_gic_of_init, .init_machine = omap_generic_init, .init_late = omap5_init_late, .init_time = omap5_realtime_timer_init, .dt_compat = omap5_boards_compat, .restart = omap44xx_restart, MACHINE_END #endif #ifdef CONFIG_SOC_AM43XX static const char *const am43_boards_compat[] __initconst = { "ti,am4372", "ti,am43", NULL, }; DT_MACHINE_START(AM43_DT, "Generic AM43 (Flattened Device Tree)") .l2c_aux_val = OMAP_L2C_AUX_CTRL, .l2c_aux_mask = 0xcf9fffff, .l2c_write_sec = omap4_l2c310_write_sec, .map_io = am33xx_map_io, .init_early = am43xx_init_early, .init_late = am43xx_init_late, .init_irq = omap_gic_of_init, .init_machine = omap_generic_init, .init_time = omap3_gptimer_timer_init, .dt_compat = am43_boards_compat, .restart = omap44xx_restart, MACHINE_END #endif #ifdef CONFIG_SOC_DRA7XX static const char *const dra74x_boards_compat[] __initconst = { "ti,am5728", "ti,am5726", "ti,dra742", "ti,dra7", NULL, }; DT_MACHINE_START(DRA74X_DT, "Generic DRA74X (Flattened Device Tree)") .reserve = omap_reserve, .smp = smp_ops(omap4_smp_ops), .map_io = omap5_map_io, .init_early = dra7xx_init_early, .init_late = dra7xx_init_late, .init_irq = omap_gic_of_init, .init_machine = omap_generic_init, .init_time = omap5_realtime_timer_init, .dt_compat = dra74x_boards_compat, .restart = omap44xx_restart, MACHINE_END static const char *const dra72x_boards_compat[] __initconst = { "ti,am5718", "ti,am5716", "ti,dra722", NULL, }; DT_MACHINE_START(DRA72X_DT, "Generic DRA72X (Flattened Device Tree)") .reserve = omap_reserve, .map_io = omap5_map_io, .init_early = dra7xx_init_early, .init_late = dra7xx_init_late, .init_irq = omap_gic_of_init, .init_machine = omap_generic_init, .init_time = omap5_realtime_timer_init, .dt_compat = dra72x_boards_compat, .restart = omap44xx_restart, MACHINE_END #endif
gpl-2.0
JTdevAndroid/XKernel
arch/powerpc/kernel/time.c
1294
27194
/* * Common time routines among all ppc machines. * * Written by Cort Dougan (cort@cs.nmt.edu) to merge * Paul Mackerras' version and mine for PReP and Pmac. * MPC8xx/MBX changes by Dan Malek (dmalek@jlc.net). * Converted for 64-bit by Mike Corrigan (mikejc@us.ibm.com) * * First round of bugfixes by Gabriel Paubert (paubert@iram.es) * to make clock more stable (2.4.0-test5). The only thing * that this code assumes is that the timebases have been synchronized * by firmware on SMP and are never stopped (never do sleep * on SMP then, nap and doze are OK). * * Speeded up do_gettimeofday by getting rid of references to * xtime (which required locks for consistency). (mikejc@us.ibm.com) * * TODO (not necessarily in this file): * - improve precision and reproducibility of timebase frequency * measurement at boot time. * - for astronomical applications: add a new function to get * non ambiguous timestamps even around leap seconds. This needs * a new timestamp format and a good name. * * 1997-09-10 Updated NTP code according to technical memorandum Jan '96 * "A Kernel Model for Precision Timekeeping" by Dave Mills * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version * 2 of the License, or (at your option) any later version. */ #include <linux/errno.h> #include <linux/export.h> #include <linux/sched.h> #include <linux/kernel.h> #include <linux/param.h> #include <linux/string.h> #include <linux/mm.h> #include <linux/interrupt.h> #include <linux/timex.h> #include <linux/kernel_stat.h> #include <linux/time.h> #include <linux/init.h> #include <linux/profile.h> #include <linux/cpu.h> #include <linux/security.h> #include <linux/percpu.h> #include <linux/rtc.h> #include <linux/jiffies.h> #include <linux/posix-timers.h> #include <linux/irq.h> #include <linux/delay.h> #include <linux/irq_work.h> #include <asm/trace.h> #include <asm/io.h> #include <asm/processor.h> #include <asm/nvram.h> #include <asm/cache.h> #include <asm/machdep.h> #include <asm/uaccess.h> #include <asm/time.h> #include <asm/prom.h> #include <asm/irq.h> #include <asm/div64.h> #include <asm/smp.h> #include <asm/vdso_datapage.h> #include <asm/firmware.h> #include <asm/cputime.h> /* powerpc clocksource/clockevent code */ #include <linux/clockchips.h> #include <linux/timekeeper_internal.h> static cycle_t rtc_read(struct clocksource *); static struct clocksource clocksource_rtc = { .name = "rtc", .rating = 400, .flags = CLOCK_SOURCE_IS_CONTINUOUS, .mask = CLOCKSOURCE_MASK(64), .read = rtc_read, }; static cycle_t timebase_read(struct clocksource *); static struct clocksource clocksource_timebase = { .name = "timebase", .rating = 400, .flags = CLOCK_SOURCE_IS_CONTINUOUS, .mask = CLOCKSOURCE_MASK(64), .read = timebase_read, }; #define DECREMENTER_MAX 0x7fffffff static int decrementer_set_next_event(unsigned long evt, struct clock_event_device *dev); static void decrementer_set_mode(enum clock_event_mode mode, struct clock_event_device *dev); struct clock_event_device decrementer_clockevent = { .name = "decrementer", .rating = 200, .irq = 0, .set_next_event = decrementer_set_next_event, .set_mode = decrementer_set_mode, .features = CLOCK_EVT_FEAT_ONESHOT, }; EXPORT_SYMBOL(decrementer_clockevent); DEFINE_PER_CPU(u64, decrementers_next_tb); static DEFINE_PER_CPU(struct clock_event_device, decrementers); #define XSEC_PER_SEC (1024*1024) #ifdef CONFIG_PPC64 #define SCALE_XSEC(xsec, max) (((xsec) * max) / XSEC_PER_SEC) #else /* compute ((xsec << 12) * max) >> 32 */ #define SCALE_XSEC(xsec, max) mulhwu((xsec) << 12, max) #endif unsigned long tb_ticks_per_jiffy; unsigned long tb_ticks_per_usec = 100; /* sane default */ EXPORT_SYMBOL(tb_ticks_per_usec); unsigned long tb_ticks_per_sec; EXPORT_SYMBOL(tb_ticks_per_sec); /* for cputime_t conversions */ DEFINE_SPINLOCK(rtc_lock); EXPORT_SYMBOL_GPL(rtc_lock); static u64 tb_to_ns_scale __read_mostly; static unsigned tb_to_ns_shift __read_mostly; static u64 boot_tb __read_mostly; extern struct timezone sys_tz; static long timezone_offset; unsigned long ppc_proc_freq; EXPORT_SYMBOL_GPL(ppc_proc_freq); unsigned long ppc_tb_freq; EXPORT_SYMBOL_GPL(ppc_tb_freq); #ifdef CONFIG_VIRT_CPU_ACCOUNTING_NATIVE /* * Factors for converting from cputime_t (timebase ticks) to * jiffies, microseconds, seconds, and clock_t (1/USER_HZ seconds). * These are all stored as 0.64 fixed-point binary fractions. */ u64 __cputime_jiffies_factor; EXPORT_SYMBOL(__cputime_jiffies_factor); u64 __cputime_usec_factor; EXPORT_SYMBOL(__cputime_usec_factor); u64 __cputime_sec_factor; EXPORT_SYMBOL(__cputime_sec_factor); u64 __cputime_clockt_factor; EXPORT_SYMBOL(__cputime_clockt_factor); DEFINE_PER_CPU(unsigned long, cputime_last_delta); DEFINE_PER_CPU(unsigned long, cputime_scaled_last_delta); cputime_t cputime_one_jiffy; void (*dtl_consumer)(struct dtl_entry *, u64); static void calc_cputime_factors(void) { struct div_result res; div128_by_32(HZ, 0, tb_ticks_per_sec, &res); __cputime_jiffies_factor = res.result_low; div128_by_32(1000000, 0, tb_ticks_per_sec, &res); __cputime_usec_factor = res.result_low; div128_by_32(1, 0, tb_ticks_per_sec, &res); __cputime_sec_factor = res.result_low; div128_by_32(USER_HZ, 0, tb_ticks_per_sec, &res); __cputime_clockt_factor = res.result_low; } /* * Read the SPURR on systems that have it, otherwise the PURR, * or if that doesn't exist return the timebase value passed in. */ static u64 read_spurr(u64 tb) { if (cpu_has_feature(CPU_FTR_SPURR)) return mfspr(SPRN_SPURR); if (cpu_has_feature(CPU_FTR_PURR)) return mfspr(SPRN_PURR); return tb; } #ifdef CONFIG_PPC_SPLPAR /* * Scan the dispatch trace log and count up the stolen time. * Should be called with interrupts disabled. */ static u64 scan_dispatch_log(u64 stop_tb) { u64 i = local_paca->dtl_ridx; struct dtl_entry *dtl = local_paca->dtl_curr; struct dtl_entry *dtl_end = local_paca->dispatch_log_end; struct lppaca *vpa = local_paca->lppaca_ptr; u64 tb_delta; u64 stolen = 0; u64 dtb; if (!dtl) return 0; if (i == vpa->dtl_idx) return 0; while (i < vpa->dtl_idx) { if (dtl_consumer) dtl_consumer(dtl, i); dtb = dtl->timebase; tb_delta = dtl->enqueue_to_dispatch_time + dtl->ready_to_enqueue_time; barrier(); if (i + N_DISPATCH_LOG < vpa->dtl_idx) { /* buffer has overflowed */ i = vpa->dtl_idx - N_DISPATCH_LOG; dtl = local_paca->dispatch_log + (i % N_DISPATCH_LOG); continue; } if (dtb > stop_tb) break; stolen += tb_delta; ++i; ++dtl; if (dtl == dtl_end) dtl = local_paca->dispatch_log; } local_paca->dtl_ridx = i; local_paca->dtl_curr = dtl; return stolen; } /* * Accumulate stolen time by scanning the dispatch trace log. * Called on entry from user mode. */ void accumulate_stolen_time(void) { u64 sst, ust; u8 save_soft_enabled = local_paca->soft_enabled; /* We are called early in the exception entry, before * soft/hard_enabled are sync'ed to the expected state * for the exception. We are hard disabled but the PACA * needs to reflect that so various debug stuff doesn't * complain */ local_paca->soft_enabled = 0; sst = scan_dispatch_log(local_paca->starttime_user); ust = scan_dispatch_log(local_paca->starttime); local_paca->system_time -= sst; local_paca->user_time -= ust; local_paca->stolen_time += ust + sst; local_paca->soft_enabled = save_soft_enabled; } static inline u64 calculate_stolen_time(u64 stop_tb) { u64 stolen = 0; if (get_paca()->dtl_ridx != get_paca()->lppaca_ptr->dtl_idx) { stolen = scan_dispatch_log(stop_tb); get_paca()->system_time -= stolen; } stolen += get_paca()->stolen_time; get_paca()->stolen_time = 0; return stolen; } #else /* CONFIG_PPC_SPLPAR */ static inline u64 calculate_stolen_time(u64 stop_tb) { return 0; } #endif /* CONFIG_PPC_SPLPAR */ /* * Account time for a transition between system, hard irq * or soft irq state. */ static u64 vtime_delta(struct task_struct *tsk, u64 *sys_scaled, u64 *stolen) { u64 now, nowscaled, deltascaled; u64 udelta, delta, user_scaled; WARN_ON_ONCE(!irqs_disabled()); now = mftb(); nowscaled = read_spurr(now); get_paca()->system_time += now - get_paca()->starttime; get_paca()->starttime = now; deltascaled = nowscaled - get_paca()->startspurr; get_paca()->startspurr = nowscaled; *stolen = calculate_stolen_time(now); delta = get_paca()->system_time; get_paca()->system_time = 0; udelta = get_paca()->user_time - get_paca()->utime_sspurr; get_paca()->utime_sspurr = get_paca()->user_time; /* * Because we don't read the SPURR on every kernel entry/exit, * deltascaled includes both user and system SPURR ticks. * Apportion these ticks to system SPURR ticks and user * SPURR ticks in the same ratio as the system time (delta) * and user time (udelta) values obtained from the timebase * over the same interval. The system ticks get accounted here; * the user ticks get saved up in paca->user_time_scaled to be * used by account_process_tick. */ *sys_scaled = delta; user_scaled = udelta; if (deltascaled != delta + udelta) { if (udelta) { *sys_scaled = deltascaled * delta / (delta + udelta); user_scaled = deltascaled - *sys_scaled; } else { *sys_scaled = deltascaled; } } get_paca()->user_time_scaled += user_scaled; return delta; } void vtime_account_system(struct task_struct *tsk) { u64 delta, sys_scaled, stolen; delta = vtime_delta(tsk, &sys_scaled, &stolen); account_system_time(tsk, 0, delta, sys_scaled); if (stolen) account_steal_time(stolen); } EXPORT_SYMBOL_GPL(vtime_account_system); void vtime_account_idle(struct task_struct *tsk) { u64 delta, sys_scaled, stolen; delta = vtime_delta(tsk, &sys_scaled, &stolen); account_idle_time(delta + stolen); } /* * Transfer the user time accumulated in the paca * by the exception entry and exit code to the generic * process user time records. * Must be called with interrupts disabled. * Assumes that vtime_account_system/idle() has been called * recently (i.e. since the last entry from usermode) so that * get_paca()->user_time_scaled is up to date. */ void vtime_account_user(struct task_struct *tsk) { cputime_t utime, utimescaled; utime = get_paca()->user_time; utimescaled = get_paca()->user_time_scaled; get_paca()->user_time = 0; get_paca()->user_time_scaled = 0; get_paca()->utime_sspurr = 0; account_user_time(tsk, utime, utimescaled); } #else /* ! CONFIG_VIRT_CPU_ACCOUNTING_NATIVE */ #define calc_cputime_factors() #endif void __delay(unsigned long loops) { unsigned long start; int diff; if (__USE_RTC()) { start = get_rtcl(); do { /* the RTCL register wraps at 1000000000 */ diff = get_rtcl() - start; if (diff < 0) diff += 1000000000; } while (diff < loops); } else { start = get_tbl(); while (get_tbl() - start < loops) HMT_low(); HMT_medium(); } } EXPORT_SYMBOL(__delay); void udelay(unsigned long usecs) { __delay(tb_ticks_per_usec * usecs); } EXPORT_SYMBOL(udelay); #ifdef CONFIG_SMP unsigned long profile_pc(struct pt_regs *regs) { unsigned long pc = instruction_pointer(regs); if (in_lock_functions(pc)) return regs->link; return pc; } EXPORT_SYMBOL(profile_pc); #endif #ifdef CONFIG_IRQ_WORK /* * 64-bit uses a byte in the PACA, 32-bit uses a per-cpu variable... */ #ifdef CONFIG_PPC64 static inline unsigned long test_irq_work_pending(void) { unsigned long x; asm volatile("lbz %0,%1(13)" : "=r" (x) : "i" (offsetof(struct paca_struct, irq_work_pending))); return x; } static inline void set_irq_work_pending_flag(void) { asm volatile("stb %0,%1(13)" : : "r" (1), "i" (offsetof(struct paca_struct, irq_work_pending))); } static inline void clear_irq_work_pending(void) { asm volatile("stb %0,%1(13)" : : "r" (0), "i" (offsetof(struct paca_struct, irq_work_pending))); } #else /* 32-bit */ DEFINE_PER_CPU(u8, irq_work_pending); #define set_irq_work_pending_flag() __get_cpu_var(irq_work_pending) = 1 #define test_irq_work_pending() __get_cpu_var(irq_work_pending) #define clear_irq_work_pending() __get_cpu_var(irq_work_pending) = 0 #endif /* 32 vs 64 bit */ void arch_irq_work_raise(void) { preempt_disable(); set_irq_work_pending_flag(); set_dec(1); preempt_enable(); } #else /* CONFIG_IRQ_WORK */ #define test_irq_work_pending() 0 #define clear_irq_work_pending() #endif /* CONFIG_IRQ_WORK */ /* * timer_interrupt - gets called when the decrementer overflows, * with interrupts disabled. */ void timer_interrupt(struct pt_regs * regs) { struct pt_regs *old_regs; u64 *next_tb = &__get_cpu_var(decrementers_next_tb); struct clock_event_device *evt = &__get_cpu_var(decrementers); u64 now; /* Ensure a positive value is written to the decrementer, or else * some CPUs will continue to take decrementer exceptions. */ set_dec(DECREMENTER_MAX); /* Some implementations of hotplug will get timer interrupts while * offline, just ignore these and we also need to set * decrementers_next_tb as MAX to make sure __check_irq_replay * don't replay timer interrupt when return, otherwise we'll trap * here infinitely :( */ if (!cpu_online(smp_processor_id())) { *next_tb = ~(u64)0; return; } /* Conditionally hard-enable interrupts now that the DEC has been * bumped to its maximum value */ may_hard_irq_enable(); __get_cpu_var(irq_stat).timer_irqs++; #if defined(CONFIG_PPC32) && defined(CONFIG_PPC_PMAC) if (atomic_read(&ppc_n_lost_interrupts) != 0) do_IRQ(regs); #endif old_regs = set_irq_regs(regs); irq_enter(); trace_timer_interrupt_entry(regs); if (test_irq_work_pending()) { clear_irq_work_pending(); irq_work_run(); } now = get_tb_or_rtc(); if (now >= *next_tb) { *next_tb = ~(u64)0; if (evt->event_handler) evt->event_handler(evt); } else { now = *next_tb - now; if (now <= DECREMENTER_MAX) set_dec((int)now); } #ifdef CONFIG_PPC64 /* collect purr register values often, for accurate calculations */ if (firmware_has_feature(FW_FEATURE_SPLPAR)) { struct cpu_usage *cu = &__get_cpu_var(cpu_usage_array); cu->current_tb = mfspr(SPRN_PURR); } #endif trace_timer_interrupt_exit(regs); irq_exit(); set_irq_regs(old_regs); } /* * Hypervisor decrementer interrupts shouldn't occur but are sometimes * left pending on exit from a KVM guest. We don't need to do anything * to clear them, as they are edge-triggered. */ void hdec_interrupt(struct pt_regs *regs) { } #ifdef CONFIG_SUSPEND static void generic_suspend_disable_irqs(void) { /* Disable the decrementer, so that it doesn't interfere * with suspending. */ set_dec(DECREMENTER_MAX); local_irq_disable(); set_dec(DECREMENTER_MAX); } static void generic_suspend_enable_irqs(void) { local_irq_enable(); } /* Overrides the weak version in kernel/power/main.c */ void arch_suspend_disable_irqs(void) { if (ppc_md.suspend_disable_irqs) ppc_md.suspend_disable_irqs(); generic_suspend_disable_irqs(); } /* Overrides the weak version in kernel/power/main.c */ void arch_suspend_enable_irqs(void) { generic_suspend_enable_irqs(); if (ppc_md.suspend_enable_irqs) ppc_md.suspend_enable_irqs(); } #endif /* * Scheduler clock - returns current time in nanosec units. * * Note: mulhdu(a, b) (multiply high double unsigned) returns * the high 64 bits of a * b, i.e. (a * b) >> 64, where a and b * are 64-bit unsigned numbers. */ unsigned long long sched_clock(void) { if (__USE_RTC()) return get_rtc(); return mulhdu(get_tb() - boot_tb, tb_to_ns_scale) << tb_to_ns_shift; } static int __init get_freq(char *name, int cells, unsigned long *val) { struct device_node *cpu; const unsigned int *fp; int found = 0; /* The cpu node should have timebase and clock frequency properties */ cpu = of_find_node_by_type(NULL, "cpu"); if (cpu) { fp = of_get_property(cpu, name, NULL); if (fp) { found = 1; *val = of_read_ulong(fp, cells); } of_node_put(cpu); } return found; } /* should become __cpuinit when secondary_cpu_time_init also is */ void start_cpu_decrementer(void) { #if defined(CONFIG_BOOKE) || defined(CONFIG_40x) /* Clear any pending timer interrupts */ mtspr(SPRN_TSR, TSR_ENW | TSR_WIS | TSR_DIS | TSR_FIS); /* Enable decrementer interrupt */ mtspr(SPRN_TCR, TCR_DIE); #endif /* defined(CONFIG_BOOKE) || defined(CONFIG_40x) */ } void __init generic_calibrate_decr(void) { ppc_tb_freq = DEFAULT_TB_FREQ; /* hardcoded default */ if (!get_freq("ibm,extended-timebase-frequency", 2, &ppc_tb_freq) && !get_freq("timebase-frequency", 1, &ppc_tb_freq)) { printk(KERN_ERR "WARNING: Estimating decrementer frequency " "(not found)\n"); } ppc_proc_freq = DEFAULT_PROC_FREQ; /* hardcoded default */ if (!get_freq("ibm,extended-clock-frequency", 2, &ppc_proc_freq) && !get_freq("clock-frequency", 1, &ppc_proc_freq)) { printk(KERN_ERR "WARNING: Estimating processor frequency " "(not found)\n"); } } int update_persistent_clock(struct timespec now) { struct rtc_time tm; if (!ppc_md.set_rtc_time) return -ENODEV; to_tm(now.tv_sec + 1 + timezone_offset, &tm); tm.tm_year -= 1900; tm.tm_mon -= 1; return ppc_md.set_rtc_time(&tm); } static void __read_persistent_clock(struct timespec *ts) { struct rtc_time tm; static int first = 1; ts->tv_nsec = 0; /* XXX this is a litle fragile but will work okay in the short term */ if (first) { first = 0; if (ppc_md.time_init) timezone_offset = ppc_md.time_init(); /* get_boot_time() isn't guaranteed to be safe to call late */ if (ppc_md.get_boot_time) { ts->tv_sec = ppc_md.get_boot_time() - timezone_offset; return; } } if (!ppc_md.get_rtc_time) { ts->tv_sec = 0; return; } ppc_md.get_rtc_time(&tm); ts->tv_sec = mktime(tm.tm_year+1900, tm.tm_mon+1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec); } void read_persistent_clock(struct timespec *ts) { __read_persistent_clock(ts); /* Sanitize it in case real time clock is set below EPOCH */ if (ts->tv_sec < 0) { ts->tv_sec = 0; ts->tv_nsec = 0; } } /* clocksource code */ static cycle_t rtc_read(struct clocksource *cs) { return (cycle_t)get_rtc(); } static cycle_t timebase_read(struct clocksource *cs) { return (cycle_t)get_tb(); } void update_vsyscall_old(struct timespec *wall_time, struct timespec *wtm, struct clocksource *clock, u32 mult) { u64 new_tb_to_xs, new_stamp_xsec; u32 frac_sec; if (clock != &clocksource_timebase) return; /* Make userspace gettimeofday spin until we're done. */ ++vdso_data->tb_update_count; smp_mb(); /* 19342813113834067 ~= 2^(20+64) / 1e9 */ new_tb_to_xs = (u64) mult * (19342813113834067ULL >> clock->shift); new_stamp_xsec = (u64) wall_time->tv_nsec * XSEC_PER_SEC; do_div(new_stamp_xsec, 1000000000); new_stamp_xsec += (u64) wall_time->tv_sec * XSEC_PER_SEC; BUG_ON(wall_time->tv_nsec >= NSEC_PER_SEC); /* this is tv_nsec / 1e9 as a 0.32 fraction */ frac_sec = ((u64) wall_time->tv_nsec * 18446744073ULL) >> 32; /* * tb_update_count is used to allow the userspace gettimeofday code * to assure itself that it sees a consistent view of the tb_to_xs and * stamp_xsec variables. It reads the tb_update_count, then reads * tb_to_xs and stamp_xsec and then reads tb_update_count again. If * the two values of tb_update_count match and are even then the * tb_to_xs and stamp_xsec values are consistent. If not, then it * loops back and reads them again until this criteria is met. * We expect the caller to have done the first increment of * vdso_data->tb_update_count already. */ vdso_data->tb_orig_stamp = clock->cycle_last; vdso_data->stamp_xsec = new_stamp_xsec; vdso_data->tb_to_xs = new_tb_to_xs; vdso_data->wtom_clock_sec = wtm->tv_sec; vdso_data->wtom_clock_nsec = wtm->tv_nsec; vdso_data->stamp_xtime = *wall_time; vdso_data->stamp_sec_fraction = frac_sec; smp_wmb(); ++(vdso_data->tb_update_count); } void update_vsyscall_tz(void) { vdso_data->tz_minuteswest = sys_tz.tz_minuteswest; vdso_data->tz_dsttime = sys_tz.tz_dsttime; } static void __init clocksource_init(void) { struct clocksource *clock; if (__USE_RTC()) clock = &clocksource_rtc; else clock = &clocksource_timebase; if (clocksource_register_hz(clock, tb_ticks_per_sec)) { printk(KERN_ERR "clocksource: %s is already registered\n", clock->name); return; } printk(KERN_INFO "clocksource: %s mult[%x] shift[%d] registered\n", clock->name, clock->mult, clock->shift); } static int decrementer_set_next_event(unsigned long evt, struct clock_event_device *dev) { __get_cpu_var(decrementers_next_tb) = get_tb_or_rtc() + evt; set_dec(evt); return 0; } static void decrementer_set_mode(enum clock_event_mode mode, struct clock_event_device *dev) { if (mode != CLOCK_EVT_MODE_ONESHOT) decrementer_set_next_event(DECREMENTER_MAX, dev); } static void register_decrementer_clockevent(int cpu) { struct clock_event_device *dec = &per_cpu(decrementers, cpu); *dec = decrementer_clockevent; dec->cpumask = cpumask_of(cpu); printk_once(KERN_DEBUG "clockevent: %s mult[%x] shift[%d] cpu[%d]\n", dec->name, dec->mult, dec->shift, cpu); clockevents_register_device(dec); } static void __init init_decrementer_clockevent(void) { int cpu = smp_processor_id(); clockevents_calc_mult_shift(&decrementer_clockevent, ppc_tb_freq, 4); decrementer_clockevent.max_delta_ns = clockevent_delta2ns(DECREMENTER_MAX, &decrementer_clockevent); decrementer_clockevent.min_delta_ns = clockevent_delta2ns(2, &decrementer_clockevent); register_decrementer_clockevent(cpu); } void secondary_cpu_time_init(void) { /* Start the decrementer on CPUs that have manual control * such as BookE */ start_cpu_decrementer(); /* FIME: Should make unrelatred change to move snapshot_timebase * call here ! */ register_decrementer_clockevent(smp_processor_id()); } /* This function is only called on the boot processor */ void __init time_init(void) { struct div_result res; u64 scale; unsigned shift; if (__USE_RTC()) { /* 601 processor: dec counts down by 128 every 128ns */ ppc_tb_freq = 1000000000; } else { /* Normal PowerPC with timebase register */ ppc_md.calibrate_decr(); printk(KERN_DEBUG "time_init: decrementer frequency = %lu.%.6lu MHz\n", ppc_tb_freq / 1000000, ppc_tb_freq % 1000000); printk(KERN_DEBUG "time_init: processor frequency = %lu.%.6lu MHz\n", ppc_proc_freq / 1000000, ppc_proc_freq % 1000000); } tb_ticks_per_jiffy = ppc_tb_freq / HZ; tb_ticks_per_sec = ppc_tb_freq; tb_ticks_per_usec = ppc_tb_freq / 1000000; calc_cputime_factors(); setup_cputime_one_jiffy(); /* * Compute scale factor for sched_clock. * The calibrate_decr() function has set tb_ticks_per_sec, * which is the timebase frequency. * We compute 1e9 * 2^64 / tb_ticks_per_sec and interpret * the 128-bit result as a 64.64 fixed-point number. * We then shift that number right until it is less than 1.0, * giving us the scale factor and shift count to use in * sched_clock(). */ div128_by_32(1000000000, 0, tb_ticks_per_sec, &res); scale = res.result_low; for (shift = 0; res.result_high != 0; ++shift) { scale = (scale >> 1) | (res.result_high << 63); res.result_high >>= 1; } tb_to_ns_scale = scale; tb_to_ns_shift = shift; /* Save the current timebase to pretty up CONFIG_PRINTK_TIME */ boot_tb = get_tb_or_rtc(); /* If platform provided a timezone (pmac), we correct the time */ if (timezone_offset) { sys_tz.tz_minuteswest = -timezone_offset / 60; sys_tz.tz_dsttime = 0; } vdso_data->tb_update_count = 0; vdso_data->tb_ticks_per_sec = tb_ticks_per_sec; /* Start the decrementer on CPUs that have manual control * such as BookE */ start_cpu_decrementer(); /* Register the clocksource */ clocksource_init(); init_decrementer_clockevent(); } #define FEBRUARY 2 #define STARTOFTIME 1970 #define SECDAY 86400L #define SECYR (SECDAY * 365) #define leapyear(year) ((year) % 4 == 0 && \ ((year) % 100 != 0 || (year) % 400 == 0)) #define days_in_year(a) (leapyear(a) ? 366 : 365) #define days_in_month(a) (month_days[(a) - 1]) static int month_days[12] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; /* * This only works for the Gregorian calendar - i.e. after 1752 (in the UK) */ void GregorianDay(struct rtc_time * tm) { int leapsToDate; int lastYear; int day; int MonthOffset[] = { 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334 }; lastYear = tm->tm_year - 1; /* * Number of leap corrections to apply up to end of last year */ leapsToDate = lastYear / 4 - lastYear / 100 + lastYear / 400; /* * This year is a leap year if it is divisible by 4 except when it is * divisible by 100 unless it is divisible by 400 * * e.g. 1904 was a leap year, 1900 was not, 1996 is, and 2000 was */ day = tm->tm_mon > 2 && leapyear(tm->tm_year); day += lastYear*365 + leapsToDate + MonthOffset[tm->tm_mon-1] + tm->tm_mday; tm->tm_wday = day % 7; } void to_tm(int tim, struct rtc_time * tm) { register int i; register long hms, day; day = tim / SECDAY; hms = tim % SECDAY; /* Hours, minutes, seconds are easy */ tm->tm_hour = hms / 3600; tm->tm_min = (hms % 3600) / 60; tm->tm_sec = (hms % 3600) % 60; /* Number of years in days */ for (i = STARTOFTIME; day >= days_in_year(i); i++) day -= days_in_year(i); tm->tm_year = i; /* Number of months in days left */ if (leapyear(tm->tm_year)) days_in_month(FEBRUARY) = 29; for (i = 1; day >= days_in_month(i); i++) day -= days_in_month(i); days_in_month(FEBRUARY) = 28; tm->tm_mon = i; /* Days are what is left over (+1) from all that. */ tm->tm_mday = day + 1; /* * Determine the day of week */ GregorianDay(tm); } /* * Divide a 128-bit dividend by a 32-bit divisor, leaving a 128 bit * result. */ void div128_by_32(u64 dividend_high, u64 dividend_low, unsigned divisor, struct div_result *dr) { unsigned long a, b, c, d; unsigned long w, x, y, z; u64 ra, rb, rc; a = dividend_high >> 32; b = dividend_high & 0xffffffff; c = dividend_low >> 32; d = dividend_low & 0xffffffff; w = a / divisor; ra = ((u64)(a - (w * divisor)) << 32) + b; rb = ((u64) do_div(ra, divisor) << 32) + c; x = ra; rc = ((u64) do_div(rb, divisor) << 32) + d; y = rb; do_div(rc, divisor); z = rc; dr->result_high = ((u64)w << 32) + x; dr->result_low = ((u64)y << 32) + z; } /* We don't need to calibrate delay, we use the CPU timebase for that */ void calibrate_delay(void) { /* Some generic code (such as spinlock debug) use loops_per_jiffy * as the number of __delay(1) in a jiffy, so make it so */ loops_per_jiffy = tb_ticks_per_jiffy; } static int __init rtc_init(void) { struct platform_device *pdev; if (!ppc_md.get_rtc_time) return -ENODEV; pdev = platform_device_register_simple("rtc-generic", -1, NULL, 0); return PTR_RET(pdev); } module_init(rtc_init);
gpl-2.0
mirsys/linux-3.4.y
drivers/watchdog/hpwdt.c
1550
21923
/* * HP WatchDog Driver * based on * * SoftDog 0.05: A Software Watchdog Device * * (c) Copyright 2007 Hewlett-Packard Development Company, L.P. * Thomas Mingarelli <thomas.mingarelli@hp.com> * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * version 2 as published by the Free Software Foundation * */ #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt #include <linux/device.h> #include <linux/fs.h> #include <linux/init.h> #include <linux/io.h> #include <linux/bitops.h> #include <linux/kernel.h> #include <linux/miscdevice.h> #include <linux/module.h> #include <linux/moduleparam.h> #include <linux/pci.h> #include <linux/pci_ids.h> #include <linux/types.h> #include <linux/uaccess.h> #include <linux/watchdog.h> #ifdef CONFIG_HPWDT_NMI_DECODING #include <linux/dmi.h> #include <linux/spinlock.h> #include <linux/nmi.h> #include <linux/kdebug.h> #include <linux/notifier.h> #include <asm/cacheflush.h> #endif /* CONFIG_HPWDT_NMI_DECODING */ #include <asm/nmi.h> #define HPWDT_VERSION "1.3.0" #define SECS_TO_TICKS(secs) ((secs) * 1000 / 128) #define TICKS_TO_SECS(ticks) ((ticks) * 128 / 1000) #define HPWDT_MAX_TIMER TICKS_TO_SECS(65535) #define DEFAULT_MARGIN 30 static unsigned int soft_margin = DEFAULT_MARGIN; /* in seconds */ static unsigned int reload; /* the computed soft_margin */ static bool nowayout = WATCHDOG_NOWAYOUT; static char expect_release; static unsigned long hpwdt_is_open; static void __iomem *pci_mem_addr; /* the PCI-memory address */ static unsigned long __iomem *hpwdt_timer_reg; static unsigned long __iomem *hpwdt_timer_con; static DEFINE_PCI_DEVICE_TABLE(hpwdt_devices) = { { PCI_DEVICE(PCI_VENDOR_ID_COMPAQ, 0xB203) }, /* iLO2 */ { PCI_DEVICE(PCI_VENDOR_ID_HP, 0x3306) }, /* iLO3 */ {0}, /* terminate list */ }; MODULE_DEVICE_TABLE(pci, hpwdt_devices); #ifdef CONFIG_HPWDT_NMI_DECODING #define PCI_BIOS32_SD_VALUE 0x5F32335F /* "_32_" */ #define CRU_BIOS_SIGNATURE_VALUE 0x55524324 #define PCI_BIOS32_PARAGRAPH_LEN 16 #define PCI_ROM_BASE1 0x000F0000 #define ROM_SIZE 0x10000 struct bios32_service_dir { u32 signature; u32 entry_point; u8 revision; u8 length; u8 checksum; u8 reserved[5]; }; /* type 212 */ struct smbios_cru64_info { u8 type; u8 byte_length; u16 handle; u32 signature; u64 physical_address; u32 double_length; u32 double_offset; }; #define SMBIOS_CRU64_INFORMATION 212 /* type 219 */ struct smbios_proliant_info { u8 type; u8 byte_length; u16 handle; u32 power_features; u32 omega_features; u32 reserved; u32 misc_features; }; #define SMBIOS_ICRU_INFORMATION 219 struct cmn_registers { union { struct { u8 ral; u8 rah; u16 rea2; }; u32 reax; } u1; union { struct { u8 rbl; u8 rbh; u8 reb2l; u8 reb2h; }; u32 rebx; } u2; union { struct { u8 rcl; u8 rch; u16 rec2; }; u32 recx; } u3; union { struct { u8 rdl; u8 rdh; u16 red2; }; u32 redx; } u4; u32 resi; u32 redi; u16 rds; u16 res; u32 reflags; } __attribute__((packed)); static unsigned int hpwdt_nmi_decoding; static unsigned int allow_kdump; static unsigned int priority; /* hpwdt at end of die_notify list */ static unsigned int is_icru; static DEFINE_SPINLOCK(rom_lock); static void *cru_rom_addr; static struct cmn_registers cmn_regs; extern asmlinkage void asminline_call(struct cmn_registers *pi86Regs, unsigned long *pRomEntry); #ifdef CONFIG_X86_32 /* --32 Bit Bios------------------------------------------------------------ */ #define HPWDT_ARCH 32 asm(".text \n\t" ".align 4 \n" "asminline_call: \n\t" "pushl %ebp \n\t" "movl %esp, %ebp \n\t" "pusha \n\t" "pushf \n\t" "push %es \n\t" "push %ds \n\t" "pop %es \n\t" "movl 8(%ebp),%eax \n\t" "movl 4(%eax),%ebx \n\t" "movl 8(%eax),%ecx \n\t" "movl 12(%eax),%edx \n\t" "movl 16(%eax),%esi \n\t" "movl 20(%eax),%edi \n\t" "movl (%eax),%eax \n\t" "push %cs \n\t" "call *12(%ebp) \n\t" "pushf \n\t" "pushl %eax \n\t" "movl 8(%ebp),%eax \n\t" "movl %ebx,4(%eax) \n\t" "movl %ecx,8(%eax) \n\t" "movl %edx,12(%eax) \n\t" "movl %esi,16(%eax) \n\t" "movl %edi,20(%eax) \n\t" "movw %ds,24(%eax) \n\t" "movw %es,26(%eax) \n\t" "popl %ebx \n\t" "movl %ebx,(%eax) \n\t" "popl %ebx \n\t" "movl %ebx,28(%eax) \n\t" "pop %es \n\t" "popf \n\t" "popa \n\t" "leave \n\t" "ret \n\t" ".previous"); /* * cru_detect * * Routine Description: * This function uses the 32-bit BIOS Service Directory record to * search for a $CRU record. * * Return Value: * 0 : SUCCESS * <0 : FAILURE */ static int __devinit cru_detect(unsigned long map_entry, unsigned long map_offset) { void *bios32_map; unsigned long *bios32_entrypoint; unsigned long cru_physical_address; unsigned long cru_length; unsigned long physical_bios_base = 0; unsigned long physical_bios_offset = 0; int retval = -ENODEV; bios32_map = ioremap(map_entry, (2 * PAGE_SIZE)); if (bios32_map == NULL) return -ENODEV; bios32_entrypoint = bios32_map + map_offset; cmn_regs.u1.reax = CRU_BIOS_SIGNATURE_VALUE; set_memory_x((unsigned long)bios32_map, 2); asminline_call(&cmn_regs, bios32_entrypoint); if (cmn_regs.u1.ral != 0) { pr_warn("Call succeeded but with an error: 0x%x\n", cmn_regs.u1.ral); } else { physical_bios_base = cmn_regs.u2.rebx; physical_bios_offset = cmn_regs.u4.redx; cru_length = cmn_regs.u3.recx; cru_physical_address = physical_bios_base + physical_bios_offset; /* If the values look OK, then map it in. */ if ((physical_bios_base + physical_bios_offset)) { cru_rom_addr = ioremap(cru_physical_address, cru_length); if (cru_rom_addr) { set_memory_x((unsigned long)cru_rom_addr & PAGE_MASK, (cru_length + PAGE_SIZE - 1) >> PAGE_SHIFT); retval = 0; } } pr_debug("CRU Base Address: 0x%lx\n", physical_bios_base); pr_debug("CRU Offset Address: 0x%lx\n", physical_bios_offset); pr_debug("CRU Length: 0x%lx\n", cru_length); pr_debug("CRU Mapped Address: %p\n", &cru_rom_addr); } iounmap(bios32_map); return retval; } /* * bios_checksum */ static int __devinit bios_checksum(const char __iomem *ptr, int len) { char sum = 0; int i; /* * calculate checksum of size bytes. This should add up * to zero if we have a valid header. */ for (i = 0; i < len; i++) sum += ptr[i]; return ((sum == 0) && (len > 0)); } /* * bios32_present * * Routine Description: * This function finds the 32-bit BIOS Service Directory * * Return Value: * 0 : SUCCESS * <0 : FAILURE */ static int __devinit bios32_present(const char __iomem *p) { struct bios32_service_dir *bios_32_ptr; int length; unsigned long map_entry, map_offset; bios_32_ptr = (struct bios32_service_dir *) p; /* * Search for signature by checking equal to the swizzled value * instead of calling another routine to perform a strcmp. */ if (bios_32_ptr->signature == PCI_BIOS32_SD_VALUE) { length = bios_32_ptr->length * PCI_BIOS32_PARAGRAPH_LEN; if (bios_checksum(p, length)) { /* * According to the spec, we're looking for the * first 4KB-aligned address below the entrypoint * listed in the header. The Service Directory code * is guaranteed to occupy no more than 2 4KB pages. */ map_entry = bios_32_ptr->entry_point & ~(PAGE_SIZE - 1); map_offset = bios_32_ptr->entry_point - map_entry; return cru_detect(map_entry, map_offset); } } return -ENODEV; } static int __devinit detect_cru_service(void) { char __iomem *p, *q; int rc = -1; /* * Search from 0x0f0000 through 0x0fffff, inclusive. */ p = ioremap(PCI_ROM_BASE1, ROM_SIZE); if (p == NULL) return -ENOMEM; for (q = p; q < p + ROM_SIZE; q += 16) { rc = bios32_present(q); if (!rc) break; } iounmap(p); return rc; } /* ------------------------------------------------------------------------- */ #endif /* CONFIG_X86_32 */ #ifdef CONFIG_X86_64 /* --64 Bit Bios------------------------------------------------------------ */ #define HPWDT_ARCH 64 asm(".text \n\t" ".align 4 \n" "asminline_call: \n\t" "pushq %rbp \n\t" "movq %rsp, %rbp \n\t" "pushq %rax \n\t" "pushq %rbx \n\t" "pushq %rdx \n\t" "pushq %r12 \n\t" "pushq %r9 \n\t" "movq %rsi, %r12 \n\t" "movq %rdi, %r9 \n\t" "movl 4(%r9),%ebx \n\t" "movl 8(%r9),%ecx \n\t" "movl 12(%r9),%edx \n\t" "movl 16(%r9),%esi \n\t" "movl 20(%r9),%edi \n\t" "movl (%r9),%eax \n\t" "call *%r12 \n\t" "pushfq \n\t" "popq %r12 \n\t" "movl %eax, (%r9) \n\t" "movl %ebx, 4(%r9) \n\t" "movl %ecx, 8(%r9) \n\t" "movl %edx, 12(%r9) \n\t" "movl %esi, 16(%r9) \n\t" "movl %edi, 20(%r9) \n\t" "movq %r12, %rax \n\t" "movl %eax, 28(%r9) \n\t" "popq %r9 \n\t" "popq %r12 \n\t" "popq %rdx \n\t" "popq %rbx \n\t" "popq %rax \n\t" "leave \n\t" "ret \n\t" ".previous"); /* * dmi_find_cru * * Routine Description: * This function checks whether or not a SMBIOS/DMI record is * the 64bit CRU info or not */ static void __devinit dmi_find_cru(const struct dmi_header *dm, void *dummy) { struct smbios_cru64_info *smbios_cru64_ptr; unsigned long cru_physical_address; if (dm->type == SMBIOS_CRU64_INFORMATION) { smbios_cru64_ptr = (struct smbios_cru64_info *) dm; if (smbios_cru64_ptr->signature == CRU_BIOS_SIGNATURE_VALUE) { cru_physical_address = smbios_cru64_ptr->physical_address + smbios_cru64_ptr->double_offset; cru_rom_addr = ioremap(cru_physical_address, smbios_cru64_ptr->double_length); set_memory_x((unsigned long)cru_rom_addr & PAGE_MASK, smbios_cru64_ptr->double_length >> PAGE_SHIFT); } } } static int __devinit detect_cru_service(void) { cru_rom_addr = NULL; dmi_walk(dmi_find_cru, NULL); /* if cru_rom_addr has been set then we found a CRU service */ return ((cru_rom_addr != NULL) ? 0 : -ENODEV); } /* ------------------------------------------------------------------------- */ #endif /* CONFIG_X86_64 */ #endif /* CONFIG_HPWDT_NMI_DECODING */ /* * Watchdog operations */ static void hpwdt_start(void) { reload = SECS_TO_TICKS(soft_margin); iowrite16(reload, hpwdt_timer_reg); iowrite8(0x85, hpwdt_timer_con); } static void hpwdt_stop(void) { unsigned long data; data = ioread8(hpwdt_timer_con); data &= 0xFE; iowrite8(data, hpwdt_timer_con); } static void hpwdt_ping(void) { iowrite16(reload, hpwdt_timer_reg); } static int hpwdt_change_timer(int new_margin) { if (new_margin < 1 || new_margin > HPWDT_MAX_TIMER) { pr_warn("New value passed in is invalid: %d seconds\n", new_margin); return -EINVAL; } soft_margin = new_margin; pr_debug("New timer passed in is %d seconds\n", new_margin); reload = SECS_TO_TICKS(soft_margin); return 0; } static int hpwdt_time_left(void) { return TICKS_TO_SECS(ioread16(hpwdt_timer_reg)); } #ifdef CONFIG_HPWDT_NMI_DECODING /* * NMI Handler */ static int hpwdt_pretimeout(unsigned int ulReason, struct pt_regs *regs) { unsigned long rom_pl; static int die_nmi_called; if (!hpwdt_nmi_decoding) goto out; spin_lock_irqsave(&rom_lock, rom_pl); if (!die_nmi_called && !is_icru) asminline_call(&cmn_regs, cru_rom_addr); die_nmi_called = 1; spin_unlock_irqrestore(&rom_lock, rom_pl); if (allow_kdump) hpwdt_stop(); if (!is_icru) { if (cmn_regs.u1.ral == 0) { panic("An NMI occurred, " "but unable to determine source.\n"); } } panic("An NMI occurred, please see the Integrated " "Management Log for details.\n"); out: return NMI_DONE; } #endif /* CONFIG_HPWDT_NMI_DECODING */ /* * /dev/watchdog handling */ static int hpwdt_open(struct inode *inode, struct file *file) { /* /dev/watchdog can only be opened once */ if (test_and_set_bit(0, &hpwdt_is_open)) return -EBUSY; /* Start the watchdog */ hpwdt_start(); hpwdt_ping(); return nonseekable_open(inode, file); } static int hpwdt_release(struct inode *inode, struct file *file) { /* Stop the watchdog */ if (expect_release == 42) { hpwdt_stop(); } else { pr_crit("Unexpected close, not stopping watchdog!\n"); hpwdt_ping(); } expect_release = 0; /* /dev/watchdog is being closed, make sure it can be re-opened */ clear_bit(0, &hpwdt_is_open); return 0; } static ssize_t hpwdt_write(struct file *file, const char __user *data, size_t len, loff_t *ppos) { /* See if we got the magic character 'V' and reload the timer */ if (len) { if (!nowayout) { size_t i; /* note: just in case someone wrote the magic character * five months ago... */ expect_release = 0; /* scan to see whether or not we got the magic char. */ for (i = 0; i != len; i++) { char c; if (get_user(c, data + i)) return -EFAULT; if (c == 'V') expect_release = 42; } } /* someone wrote to us, we should reload the timer */ hpwdt_ping(); } return len; } static const struct watchdog_info ident = { .options = WDIOF_SETTIMEOUT | WDIOF_KEEPALIVEPING | WDIOF_MAGICCLOSE, .identity = "HP iLO2+ HW Watchdog Timer", }; static long hpwdt_ioctl(struct file *file, unsigned int cmd, unsigned long arg) { void __user *argp = (void __user *)arg; int __user *p = argp; int new_margin; int ret = -ENOTTY; switch (cmd) { case WDIOC_GETSUPPORT: ret = 0; if (copy_to_user(argp, &ident, sizeof(ident))) ret = -EFAULT; break; case WDIOC_GETSTATUS: case WDIOC_GETBOOTSTATUS: ret = put_user(0, p); break; case WDIOC_KEEPALIVE: hpwdt_ping(); ret = 0; break; case WDIOC_SETTIMEOUT: ret = get_user(new_margin, p); if (ret) break; ret = hpwdt_change_timer(new_margin); if (ret) break; hpwdt_ping(); /* Fall */ case WDIOC_GETTIMEOUT: ret = put_user(soft_margin, p); break; case WDIOC_GETTIMELEFT: ret = put_user(hpwdt_time_left(), p); break; } return ret; } /* * Kernel interfaces */ static const struct file_operations hpwdt_fops = { .owner = THIS_MODULE, .llseek = no_llseek, .write = hpwdt_write, .unlocked_ioctl = hpwdt_ioctl, .open = hpwdt_open, .release = hpwdt_release, }; static struct miscdevice hpwdt_miscdev = { .minor = WATCHDOG_MINOR, .name = "watchdog", .fops = &hpwdt_fops, }; /* * Init & Exit */ #ifdef CONFIG_HPWDT_NMI_DECODING #ifdef CONFIG_X86_LOCAL_APIC static void __devinit hpwdt_check_nmi_decoding(struct pci_dev *dev) { /* * If nmi_watchdog is turned off then we can turn on * our nmi decoding capability. */ hpwdt_nmi_decoding = 1; } #else static void __devinit hpwdt_check_nmi_decoding(struct pci_dev *dev) { dev_warn(&dev->dev, "NMI decoding is disabled. " "Your kernel does not support a NMI Watchdog.\n"); } #endif /* CONFIG_X86_LOCAL_APIC */ /* * dmi_find_icru * * Routine Description: * This function checks whether or not we are on an iCRU-based server. * This check is independent of architecture and needs to be made for * any ProLiant system. */ static void __devinit dmi_find_icru(const struct dmi_header *dm, void *dummy) { struct smbios_proliant_info *smbios_proliant_ptr; if (dm->type == SMBIOS_ICRU_INFORMATION) { smbios_proliant_ptr = (struct smbios_proliant_info *) dm; if (smbios_proliant_ptr->misc_features & 0x01) is_icru = 1; } } static int __devinit hpwdt_init_nmi_decoding(struct pci_dev *dev) { int retval; /* * On typical CRU-based systems we need to map that service in * the BIOS. For 32 bit Operating Systems we need to go through * the 32 Bit BIOS Service Directory. For 64 bit Operating * Systems we get that service through SMBIOS. * * On systems that support the new iCRU service all we need to * do is call dmi_walk to get the supported flag value and skip * the old cru detect code. */ dmi_walk(dmi_find_icru, NULL); if (!is_icru) { /* * We need to map the ROM to get the CRU service. * For 32 bit Operating Systems we need to go through the 32 Bit * BIOS Service Directory * For 64 bit Operating Systems we get that service through SMBIOS. */ retval = detect_cru_service(); if (retval < 0) { dev_warn(&dev->dev, "Unable to detect the %d Bit CRU Service.\n", HPWDT_ARCH); return retval; } /* * We know this is the only CRU call we need to make so lets keep as * few instructions as possible once the NMI comes in. */ cmn_regs.u1.rah = 0x0D; cmn_regs.u1.ral = 0x02; } /* * If the priority is set to 1, then we will be put first on the * die notify list to handle a critical NMI. The default is to * be last so other users of the NMI signal can function. */ retval = register_nmi_handler(NMI_UNKNOWN, hpwdt_pretimeout, (priority) ? NMI_FLAG_FIRST : 0, "hpwdt"); if (retval != 0) { dev_warn(&dev->dev, "Unable to register a die notifier (err=%d).\n", retval); if (cru_rom_addr) iounmap(cru_rom_addr); } dev_info(&dev->dev, "HP Watchdog Timer Driver: NMI decoding initialized" ", allow kernel dump: %s (default = 0/OFF)" ", priority: %s (default = 0/LAST).\n", (allow_kdump == 0) ? "OFF" : "ON", (priority == 0) ? "LAST" : "FIRST"); return 0; } static void hpwdt_exit_nmi_decoding(void) { unregister_nmi_handler(NMI_UNKNOWN, "hpwdt"); if (cru_rom_addr) iounmap(cru_rom_addr); } #else /* !CONFIG_HPWDT_NMI_DECODING */ static void __devinit hpwdt_check_nmi_decoding(struct pci_dev *dev) { } static int __devinit hpwdt_init_nmi_decoding(struct pci_dev *dev) { return 0; } static void hpwdt_exit_nmi_decoding(void) { } #endif /* CONFIG_HPWDT_NMI_DECODING */ static int __devinit hpwdt_init_one(struct pci_dev *dev, const struct pci_device_id *ent) { int retval; /* * Check if we can do NMI decoding or not */ hpwdt_check_nmi_decoding(dev); /* * First let's find out if we are on an iLO2+ server. We will * not run on a legacy ASM box. * So we only support the G5 ProLiant servers and higher. */ if (dev->subsystem_vendor != PCI_VENDOR_ID_HP) { dev_warn(&dev->dev, "This server does not have an iLO2+ ASIC.\n"); return -ENODEV; } if (pci_enable_device(dev)) { dev_warn(&dev->dev, "Not possible to enable PCI Device: 0x%x:0x%x.\n", ent->vendor, ent->device); return -ENODEV; } pci_mem_addr = pci_iomap(dev, 1, 0x80); if (!pci_mem_addr) { dev_warn(&dev->dev, "Unable to detect the iLO2+ server memory.\n"); retval = -ENOMEM; goto error_pci_iomap; } hpwdt_timer_reg = pci_mem_addr + 0x70; hpwdt_timer_con = pci_mem_addr + 0x72; /* Make sure that timer is disabled until /dev/watchdog is opened */ hpwdt_stop(); /* Make sure that we have a valid soft_margin */ if (hpwdt_change_timer(soft_margin)) hpwdt_change_timer(DEFAULT_MARGIN); /* Initialize NMI Decoding functionality */ retval = hpwdt_init_nmi_decoding(dev); if (retval != 0) goto error_init_nmi_decoding; retval = misc_register(&hpwdt_miscdev); if (retval < 0) { dev_warn(&dev->dev, "Unable to register miscdev on minor=%d (err=%d).\n", WATCHDOG_MINOR, retval); goto error_misc_register; } dev_info(&dev->dev, "HP Watchdog Timer Driver: %s" ", timer margin: %d seconds (nowayout=%d).\n", HPWDT_VERSION, soft_margin, nowayout); return 0; error_misc_register: hpwdt_exit_nmi_decoding(); error_init_nmi_decoding: pci_iounmap(dev, pci_mem_addr); error_pci_iomap: pci_disable_device(dev); return retval; } static void __devexit hpwdt_exit(struct pci_dev *dev) { if (!nowayout) hpwdt_stop(); misc_deregister(&hpwdt_miscdev); hpwdt_exit_nmi_decoding(); pci_iounmap(dev, pci_mem_addr); pci_disable_device(dev); } static struct pci_driver hpwdt_driver = { .name = "hpwdt", .id_table = hpwdt_devices, .probe = hpwdt_init_one, .remove = __devexit_p(hpwdt_exit), }; static void __exit hpwdt_cleanup(void) { pci_unregister_driver(&hpwdt_driver); } static int __init hpwdt_init(void) { return pci_register_driver(&hpwdt_driver); } MODULE_AUTHOR("Tom Mingarelli"); MODULE_DESCRIPTION("hp watchdog driver"); MODULE_LICENSE("GPL"); MODULE_VERSION(HPWDT_VERSION); MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR); module_param(soft_margin, int, 0); MODULE_PARM_DESC(soft_margin, "Watchdog timeout in seconds"); module_param(nowayout, bool, 0); MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default=" __MODULE_STRING(WATCHDOG_NOWAYOUT) ")"); #ifdef CONFIG_HPWDT_NMI_DECODING module_param(allow_kdump, int, 0); MODULE_PARM_DESC(allow_kdump, "Start a kernel dump after NMI occurs"); module_param(priority, int, 0); MODULE_PARM_DESC(priority, "The hpwdt driver handles NMIs first or last" " (default = 0/Last)\n"); #endif /* !CONFIG_HPWDT_NMI_DECODING */ module_init(hpwdt_init); module_exit(hpwdt_cleanup);
gpl-2.0
CandyDevices/kernel_htc_msm8994
drivers/staging/vt6655/datarate.c
2318
11468
/* * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc. * All rights reserved. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * File: datarate.c * * Purpose: Handles the auto fallback & data rates functions * * Author: Lyndon Chen * * Date: July 17, 2002 * * Functions: * RATEvParseMaxRate - Parsing the highest basic & support rate in rate field of frame * RATEvTxRateFallBack - Rate fallback Algorithm Implementaion * RATEuSetIE- Set rate IE field. * * Revision History: * */ #include "ttype.h" #include "tmacro.h" #include "mac.h" #include "80211mgr.h" #include "bssdb.h" #include "datarate.h" #include "card.h" #include "baseband.h" #include "srom.h" /*--------------------- Static Definitions -------------------------*/ /*--------------------- Static Classes ----------------------------*/ extern unsigned short TxRate_iwconfig; //2008-5-8 <add> by chester /*--------------------- Static Variables --------------------------*/ //static int msglevel =MSG_LEVEL_DEBUG; static int msglevel = MSG_LEVEL_INFO; const unsigned char acbyIERate[MAX_RATE] = {0x02, 0x04, 0x0B, 0x16, 0x0C, 0x12, 0x18, 0x24, 0x30, 0x48, 0x60, 0x6C}; #define AUTORATE_TXOK_CNT 0x0400 #define AUTORATE_TXFAIL_CNT 0x0064 #define AUTORATE_TIMEOUT 10 /*--------------------- Static Functions --------------------------*/ void s_vResetCounter( PKnownNodeDB psNodeDBTable ); void s_vResetCounter( PKnownNodeDB psNodeDBTable ) { unsigned char ii; // clear statistic counter for auto_rate for (ii = 0; ii <= MAX_RATE; ii++) { psNodeDBTable->uTxOk[ii] = 0; psNodeDBTable->uTxFail[ii] = 0; } } /*--------------------- Export Variables --------------------------*/ /*--------------------- Export Functions --------------------------*/ /*+ * * Description: * Get RateIdx from the value in SuppRates IE or ExtSuppRates IE * * Parameters: * In: * unsigned char - Rate value in SuppRates IE or ExtSuppRates IE * Out: * none * * Return Value: RateIdx * -*/ unsigned char DATARATEbyGetRateIdx( unsigned char byRate ) { unsigned char ii; //Erase basicRate flag. byRate = byRate & 0x7F;//0111 1111 for (ii = 0; ii < MAX_RATE; ii++) { if (acbyIERate[ii] == byRate) return ii; } return 0; } /*+ * * Routine Description: * Rate fallback Algorithm Implementation * * Parameters: * In: * pDevice - Pointer to the adapter * psNodeDBTable - Pointer to Node Data Base * Out: * none * * Return Value: none * -*/ #define AUTORATE_TXCNT_THRESHOLD 20 #define AUTORATE_INC_THRESHOLD 30 /*+ * * Description: * Get RateIdx from the value in SuppRates IE or ExtSuppRates IE * * Parameters: * In: * unsigned char - Rate value in SuppRates IE or ExtSuppRates IE * Out: * none * * Return Value: RateIdx * -*/ unsigned short wGetRateIdx( unsigned char byRate ) { unsigned short ii; //Erase basicRate flag. byRate = byRate & 0x7F;//0111 1111 for (ii = 0; ii < MAX_RATE; ii++) { if (acbyIERate[ii] == byRate) return ii; } return 0; } /*+ * * Description: * Parsing the highest basic & support rate in rate field of frame. * * Parameters: * In: * pDevice - Pointer to the adapter * pItemRates - Pointer to Rate field defined in 802.11 spec. * pItemExtRates - Pointer to Extended Rate field defined in 802.11 spec. * Out: * pwMaxBasicRate - Maximum Basic Rate * pwMaxSuppRate - Maximum Supported Rate * pbyTopCCKRate - Maximum Basic Rate in CCK mode * pbyTopOFDMRate - Maximum Basic Rate in OFDM mode * * Return Value: none * -*/ void RATEvParseMaxRate( void *pDeviceHandler, PWLAN_IE_SUPP_RATES pItemRates, PWLAN_IE_SUPP_RATES pItemExtRates, bool bUpdateBasicRate, unsigned short *pwMaxBasicRate, unsigned short *pwMaxSuppRate, unsigned short *pwSuppRate, unsigned char *pbyTopCCKRate, unsigned char *pbyTopOFDMRate ) { PSDevice pDevice = (PSDevice) pDeviceHandler; unsigned int ii; unsigned char byHighSuppRate = 0; unsigned char byRate = 0; unsigned short wOldBasicRate = pDevice->wBasicRate; unsigned int uRateLen; if (pItemRates == NULL) return; *pwSuppRate = 0; uRateLen = pItemRates->len; DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "ParseMaxRate Len: %d\n", uRateLen); if (pDevice->eCurrentPHYType != PHY_TYPE_11B) { if (uRateLen > WLAN_RATES_MAXLEN) uRateLen = WLAN_RATES_MAXLEN; } else { if (uRateLen > WLAN_RATES_MAXLEN_11B) uRateLen = WLAN_RATES_MAXLEN_11B; } for (ii = 0; ii < uRateLen; ii++) { byRate = (unsigned char)(pItemRates->abyRates[ii]); if (WLAN_MGMT_IS_BASICRATE(byRate) && (bUpdateBasicRate == true)) { // Add to basic rate set, update pDevice->byTopCCKBasicRate and pDevice->byTopOFDMBasicRate CARDbAddBasicRate((void *)pDevice, wGetRateIdx(byRate)); DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "ParseMaxRate AddBasicRate: %d\n", wGetRateIdx(byRate)); } byRate = (unsigned char)(pItemRates->abyRates[ii]&0x7F); if (byHighSuppRate == 0) byHighSuppRate = byRate; if (byRate > byHighSuppRate) byHighSuppRate = byRate; *pwSuppRate |= (1<<wGetRateIdx(byRate)); } if ((pItemExtRates != NULL) && (pItemExtRates->byElementID == WLAN_EID_EXTSUPP_RATES) && (pDevice->eCurrentPHYType != PHY_TYPE_11B)) { unsigned int uExtRateLen = pItemExtRates->len; if (uExtRateLen > WLAN_RATES_MAXLEN) uExtRateLen = WLAN_RATES_MAXLEN; for (ii = 0; ii < uExtRateLen; ii++) { byRate = (unsigned char)(pItemExtRates->abyRates[ii]); // select highest basic rate if (WLAN_MGMT_IS_BASICRATE(pItemExtRates->abyRates[ii])) { // Add to basic rate set, update pDevice->byTopCCKBasicRate and pDevice->byTopOFDMBasicRate CARDbAddBasicRate((void *)pDevice, wGetRateIdx(byRate)); DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "ParseMaxRate AddBasicRate: %d\n", wGetRateIdx(byRate)); } byRate = (unsigned char)(pItemExtRates->abyRates[ii]&0x7F); if (byHighSuppRate == 0) byHighSuppRate = byRate; if (byRate > byHighSuppRate) byHighSuppRate = byRate; *pwSuppRate |= (1<<wGetRateIdx(byRate)); //DBG_PRN_GRP09(("ParseMaxRate : HighSuppRate: %d, %X\n", wGetRateIdx(byRate), byRate)); } } //if (pItemExtRates != NULL) if ((pDevice->byPacketType == PK_TYPE_11GB) && CARDbIsOFDMinBasicRate((void *)pDevice)) { pDevice->byPacketType = PK_TYPE_11GA; } *pbyTopCCKRate = pDevice->byTopCCKBasicRate; *pbyTopOFDMRate = pDevice->byTopOFDMBasicRate; *pwMaxSuppRate = wGetRateIdx(byHighSuppRate); if ((pDevice->byPacketType == PK_TYPE_11B) || (pDevice->byPacketType == PK_TYPE_11GB)) *pwMaxBasicRate = pDevice->byTopCCKBasicRate; else *pwMaxBasicRate = pDevice->byTopOFDMBasicRate; if (wOldBasicRate != pDevice->wBasicRate) CARDvSetRSPINF((void *)pDevice, pDevice->eCurrentPHYType); DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Exit ParseMaxRate\n"); } /*+ * * Routine Description: * Rate fallback Algorithm Implementaion * * Parameters: * In: * pDevice - Pointer to the adapter * psNodeDBTable - Pointer to Node Data Base * Out: * none * * Return Value: none * -*/ #define AUTORATE_TXCNT_THRESHOLD 20 #define AUTORATE_INC_THRESHOLD 30 void RATEvTxRateFallBack( void *pDeviceHandler, PKnownNodeDB psNodeDBTable ) { PSDevice pDevice = (PSDevice) pDeviceHandler; unsigned short wIdxDownRate = 0; unsigned int ii; //unsigned long dwRateTable[MAX_RATE] = {1, 2, 5, 11, 6, 9, 12, 18, 24, 36, 48, 54}; bool bAutoRate[MAX_RATE] = {true, true, true, true, false, false, true, true, true, true, true, true}; unsigned long dwThroughputTbl[MAX_RATE] = {10, 20, 55, 110, 60, 90, 120, 180, 240, 360, 480, 540}; unsigned long dwThroughput = 0; unsigned short wIdxUpRate = 0; unsigned long dwTxDiff = 0; if (pDevice->pMgmt->eScanState != WMAC_NO_SCANNING) { // Don't do Fallback when scanning Channel return; } psNodeDBTable->uTimeCount++; if (psNodeDBTable->uTxFail[MAX_RATE] > psNodeDBTable->uTxOk[MAX_RATE]) dwTxDiff = psNodeDBTable->uTxFail[MAX_RATE] - psNodeDBTable->uTxOk[MAX_RATE]; if ((psNodeDBTable->uTxOk[MAX_RATE] < AUTORATE_TXOK_CNT) && (dwTxDiff < AUTORATE_TXFAIL_CNT) && (psNodeDBTable->uTimeCount < AUTORATE_TIMEOUT)) { return; } if (psNodeDBTable->uTimeCount >= AUTORATE_TIMEOUT) { psNodeDBTable->uTimeCount = 0; } for (ii = 0; ii < MAX_RATE; ii++) { if (psNodeDBTable->wSuppRate & (0x0001<<ii)) { if (bAutoRate[ii] == true) { wIdxUpRate = (unsigned short) ii; } } else { bAutoRate[ii] = false; } } for (ii = 0; ii <= psNodeDBTable->wTxDataRate; ii++) { if ((psNodeDBTable->uTxOk[ii] != 0) || (psNodeDBTable->uTxFail[ii] != 0)) { dwThroughputTbl[ii] *= psNodeDBTable->uTxOk[ii]; if (ii < RATE_11M) { psNodeDBTable->uTxFail[ii] *= 4; } dwThroughputTbl[ii] /= (psNodeDBTable->uTxOk[ii] + psNodeDBTable->uTxFail[ii]); } // DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Rate %d,Ok: %d, Fail:%d, Throughput:%d\n", // ii, psNodeDBTable->uTxOk[ii], psNodeDBTable->uTxFail[ii], dwThroughputTbl[ii]); } dwThroughput = dwThroughputTbl[psNodeDBTable->wTxDataRate]; wIdxDownRate = psNodeDBTable->wTxDataRate; for (ii = psNodeDBTable->wTxDataRate; ii > 0;) { ii--; if ((dwThroughputTbl[ii] > dwThroughput) && (bAutoRate[ii] == true)) { dwThroughput = dwThroughputTbl[ii]; wIdxDownRate = (unsigned short) ii; } } psNodeDBTable->wTxDataRate = wIdxDownRate; if (psNodeDBTable->uTxOk[MAX_RATE]) { if (psNodeDBTable->uTxOk[MAX_RATE] > (psNodeDBTable->uTxFail[MAX_RATE] * 4)) { psNodeDBTable->wTxDataRate = wIdxUpRate; } } else { // adhoc, if uTxOk =0 & uTxFail = 0 if (psNodeDBTable->uTxFail[MAX_RATE] == 0) psNodeDBTable->wTxDataRate = wIdxUpRate; } //2008-5-8 <add> by chester TxRate_iwconfig = psNodeDBTable->wTxDataRate; s_vResetCounter(psNodeDBTable); // DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Rate: %d, U:%d, D:%d\n", psNodeDBTable->wTxDataRate, wIdxUpRate, wIdxDownRate); return; } /*+ * * Description: * This routine is used to assemble available Rate IE. * * Parameters: * In: * pDevice * Out: * * Return Value: None * -*/ unsigned char RATEuSetIE( PWLAN_IE_SUPP_RATES pSrcRates, PWLAN_IE_SUPP_RATES pDstRates, unsigned int uRateLen ) { unsigned int ii, uu, uRateCnt = 0; if ((pSrcRates == NULL) || (pDstRates == NULL)) return 0; if (pSrcRates->len == 0) return 0; for (ii = 0; ii < uRateLen; ii++) { for (uu = 0; uu < pSrcRates->len; uu++) { if ((pSrcRates->abyRates[uu] & 0x7F) == acbyIERate[ii]) { pDstRates->abyRates[uRateCnt++] = pSrcRates->abyRates[uu]; break; } } } return (unsigned char)uRateCnt; }
gpl-2.0
SM-G920P-MM/G920P-MM
drivers/usb/misc/yurex.c
2318
13510
/* * Driver for Meywa-Denki & KAYAC YUREX * * Copyright (C) 2010 Tomoki Sekiyama (tomoki.sekiyama@gmail.com) * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation, version 2. * */ #include <linux/kernel.h> #include <linux/errno.h> #include <linux/init.h> #include <linux/slab.h> #include <linux/module.h> #include <linux/kref.h> #include <linux/mutex.h> #include <linux/uaccess.h> #include <linux/usb.h> #include <linux/hid.h> #define DRIVER_AUTHOR "Tomoki Sekiyama" #define DRIVER_DESC "Driver for Meywa-Denki & KAYAC YUREX" #define YUREX_VENDOR_ID 0x0c45 #define YUREX_PRODUCT_ID 0x1010 #define CMD_ACK '!' #define CMD_ANIMATE 'A' #define CMD_COUNT 'C' #define CMD_LED 'L' #define CMD_READ 'R' #define CMD_SET 'S' #define CMD_VERSION 'V' #define CMD_EOF 0x0d #define CMD_PADDING 0xff #define YUREX_BUF_SIZE 8 #define YUREX_WRITE_TIMEOUT (HZ*2) /* table of devices that work with this driver */ static struct usb_device_id yurex_table[] = { { USB_DEVICE(YUREX_VENDOR_ID, YUREX_PRODUCT_ID) }, { } /* Terminating entry */ }; MODULE_DEVICE_TABLE(usb, yurex_table); #ifdef CONFIG_USB_DYNAMIC_MINORS #define YUREX_MINOR_BASE 0 #else #define YUREX_MINOR_BASE 192 #endif /* Structure to hold all of our device specific stuff */ struct usb_yurex { struct usb_device *udev; struct usb_interface *interface; __u8 int_in_endpointAddr; struct urb *urb; /* URB for interrupt in */ unsigned char *int_buffer; /* buffer for intterupt in */ struct urb *cntl_urb; /* URB for control msg */ struct usb_ctrlrequest *cntl_req; /* req for control msg */ unsigned char *cntl_buffer; /* buffer for control msg */ struct kref kref; struct mutex io_mutex; struct fasync_struct *async_queue; wait_queue_head_t waitq; spinlock_t lock; __s64 bbu; /* BBU from device */ }; #define to_yurex_dev(d) container_of(d, struct usb_yurex, kref) static struct usb_driver yurex_driver; static const struct file_operations yurex_fops; static void yurex_control_callback(struct urb *urb) { struct usb_yurex *dev = urb->context; int status = urb->status; if (status) { dev_err(&urb->dev->dev, "%s - control failed: %d\n", __func__, status); wake_up_interruptible(&dev->waitq); return; } /* on success, sender woken up by CMD_ACK int in, or timeout */ } static void yurex_delete(struct kref *kref) { struct usb_yurex *dev = to_yurex_dev(kref); dev_dbg(&dev->interface->dev, "%s\n", __func__); usb_put_dev(dev->udev); if (dev->cntl_urb) { usb_kill_urb(dev->cntl_urb); kfree(dev->cntl_req); if (dev->cntl_buffer) usb_free_coherent(dev->udev, YUREX_BUF_SIZE, dev->cntl_buffer, dev->cntl_urb->transfer_dma); usb_free_urb(dev->cntl_urb); } if (dev->urb) { usb_kill_urb(dev->urb); if (dev->int_buffer) usb_free_coherent(dev->udev, YUREX_BUF_SIZE, dev->int_buffer, dev->urb->transfer_dma); usb_free_urb(dev->urb); } kfree(dev); } /* * usb class driver info in order to get a minor number from the usb core, * and to have the device registered with the driver core */ static struct usb_class_driver yurex_class = { .name = "yurex%d", .fops = &yurex_fops, .minor_base = YUREX_MINOR_BASE, }; static void yurex_interrupt(struct urb *urb) { struct usb_yurex *dev = urb->context; unsigned char *buf = dev->int_buffer; int status = urb->status; unsigned long flags; int retval, i; switch (status) { case 0: /*success*/ break; case -EOVERFLOW: dev_err(&dev->interface->dev, "%s - overflow with length %d, actual length is %d\n", __func__, YUREX_BUF_SIZE, dev->urb->actual_length); case -ECONNRESET: case -ENOENT: case -ESHUTDOWN: case -EILSEQ: /* The device is terminated, clean up */ return; default: dev_err(&dev->interface->dev, "%s - unknown status received: %d\n", __func__, status); goto exit; } /* handle received message */ switch (buf[0]) { case CMD_COUNT: case CMD_READ: if (buf[6] == CMD_EOF) { spin_lock_irqsave(&dev->lock, flags); dev->bbu = 0; for (i = 1; i < 6; i++) { dev->bbu += buf[i]; if (i != 5) dev->bbu <<= 8; } dev_dbg(&dev->interface->dev, "%s count: %lld\n", __func__, dev->bbu); spin_unlock_irqrestore(&dev->lock, flags); kill_fasync(&dev->async_queue, SIGIO, POLL_IN); } else dev_dbg(&dev->interface->dev, "data format error - no EOF\n"); break; case CMD_ACK: dev_dbg(&dev->interface->dev, "%s ack: %c\n", __func__, buf[1]); wake_up_interruptible(&dev->waitq); break; } exit: retval = usb_submit_urb(dev->urb, GFP_ATOMIC); if (retval) { dev_err(&dev->interface->dev, "%s - usb_submit_urb failed: %d\n", __func__, retval); } } static int yurex_probe(struct usb_interface *interface, const struct usb_device_id *id) { struct usb_yurex *dev; struct usb_host_interface *iface_desc; struct usb_endpoint_descriptor *endpoint; int retval = -ENOMEM; int i; DEFINE_WAIT(wait); /* allocate memory for our device state and initialize it */ dev = kzalloc(sizeof(*dev), GFP_KERNEL); if (!dev) { dev_err(&interface->dev, "Out of memory\n"); goto error; } kref_init(&dev->kref); mutex_init(&dev->io_mutex); spin_lock_init(&dev->lock); init_waitqueue_head(&dev->waitq); dev->udev = usb_get_dev(interface_to_usbdev(interface)); dev->interface = interface; /* set up the endpoint information */ iface_desc = interface->cur_altsetting; for (i = 0; i < iface_desc->desc.bNumEndpoints; i++) { endpoint = &iface_desc->endpoint[i].desc; if (usb_endpoint_is_int_in(endpoint)) { dev->int_in_endpointAddr = endpoint->bEndpointAddress; break; } } if (!dev->int_in_endpointAddr) { retval = -ENODEV; dev_err(&interface->dev, "Could not find endpoints\n"); goto error; } /* allocate control URB */ dev->cntl_urb = usb_alloc_urb(0, GFP_KERNEL); if (!dev->cntl_urb) { dev_err(&interface->dev, "Could not allocate control URB\n"); goto error; } /* allocate buffer for control req */ dev->cntl_req = kmalloc(YUREX_BUF_SIZE, GFP_KERNEL); if (!dev->cntl_req) { dev_err(&interface->dev, "Could not allocate cntl_req\n"); goto error; } /* allocate buffer for control msg */ dev->cntl_buffer = usb_alloc_coherent(dev->udev, YUREX_BUF_SIZE, GFP_KERNEL, &dev->cntl_urb->transfer_dma); if (!dev->cntl_buffer) { dev_err(&interface->dev, "Could not allocate cntl_buffer\n"); goto error; } /* configure control URB */ dev->cntl_req->bRequestType = USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE; dev->cntl_req->bRequest = HID_REQ_SET_REPORT; dev->cntl_req->wValue = cpu_to_le16((HID_OUTPUT_REPORT + 1) << 8); dev->cntl_req->wIndex = cpu_to_le16(iface_desc->desc.bInterfaceNumber); dev->cntl_req->wLength = cpu_to_le16(YUREX_BUF_SIZE); usb_fill_control_urb(dev->cntl_urb, dev->udev, usb_sndctrlpipe(dev->udev, 0), (void *)dev->cntl_req, dev->cntl_buffer, YUREX_BUF_SIZE, yurex_control_callback, dev); dev->cntl_urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; /* allocate interrupt URB */ dev->urb = usb_alloc_urb(0, GFP_KERNEL); if (!dev->urb) { dev_err(&interface->dev, "Could not allocate URB\n"); goto error; } /* allocate buffer for interrupt in */ dev->int_buffer = usb_alloc_coherent(dev->udev, YUREX_BUF_SIZE, GFP_KERNEL, &dev->urb->transfer_dma); if (!dev->int_buffer) { dev_err(&interface->dev, "Could not allocate int_buffer\n"); goto error; } /* configure interrupt URB */ usb_fill_int_urb(dev->urb, dev->udev, usb_rcvintpipe(dev->udev, dev->int_in_endpointAddr), dev->int_buffer, YUREX_BUF_SIZE, yurex_interrupt, dev, 1); dev->urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; if (usb_submit_urb(dev->urb, GFP_KERNEL)) { retval = -EIO; dev_err(&interface->dev, "Could not submitting URB\n"); goto error; } /* save our data pointer in this interface device */ usb_set_intfdata(interface, dev); /* we can register the device now, as it is ready */ retval = usb_register_dev(interface, &yurex_class); if (retval) { dev_err(&interface->dev, "Not able to get a minor for this device.\n"); usb_set_intfdata(interface, NULL); goto error; } dev->bbu = -1; dev_info(&interface->dev, "USB YUREX device now attached to Yurex #%d\n", interface->minor); return 0; error: if (dev) /* this frees allocated memory */ kref_put(&dev->kref, yurex_delete); return retval; } static void yurex_disconnect(struct usb_interface *interface) { struct usb_yurex *dev; int minor = interface->minor; dev = usb_get_intfdata(interface); usb_set_intfdata(interface, NULL); /* give back our minor */ usb_deregister_dev(interface, &yurex_class); /* prevent more I/O from starting */ mutex_lock(&dev->io_mutex); dev->interface = NULL; mutex_unlock(&dev->io_mutex); /* wakeup waiters */ kill_fasync(&dev->async_queue, SIGIO, POLL_IN); wake_up_interruptible(&dev->waitq); /* decrement our usage count */ kref_put(&dev->kref, yurex_delete); dev_info(&interface->dev, "USB YUREX #%d now disconnected\n", minor); } static struct usb_driver yurex_driver = { .name = "yurex", .probe = yurex_probe, .disconnect = yurex_disconnect, .id_table = yurex_table, }; static int yurex_fasync(int fd, struct file *file, int on) { struct usb_yurex *dev; dev = (struct usb_yurex *)file->private_data; return fasync_helper(fd, file, on, &dev->async_queue); } static int yurex_open(struct inode *inode, struct file *file) { struct usb_yurex *dev; struct usb_interface *interface; int subminor; int retval = 0; subminor = iminor(inode); interface = usb_find_interface(&yurex_driver, subminor); if (!interface) { printk(KERN_ERR "%s - error, can't find device for minor %d", __func__, subminor); retval = -ENODEV; goto exit; } dev = usb_get_intfdata(interface); if (!dev) { retval = -ENODEV; goto exit; } /* increment our usage count for the device */ kref_get(&dev->kref); /* save our object in the file's private structure */ mutex_lock(&dev->io_mutex); file->private_data = dev; mutex_unlock(&dev->io_mutex); exit: return retval; } static int yurex_release(struct inode *inode, struct file *file) { struct usb_yurex *dev; dev = (struct usb_yurex *)file->private_data; if (dev == NULL) return -ENODEV; /* decrement the count on our device */ kref_put(&dev->kref, yurex_delete); return 0; } static ssize_t yurex_read(struct file *file, char *buffer, size_t count, loff_t *ppos) { struct usb_yurex *dev; int retval = 0; int bytes_read = 0; char in_buffer[20]; unsigned long flags; dev = (struct usb_yurex *)file->private_data; mutex_lock(&dev->io_mutex); if (!dev->interface) { /* already disconnected */ retval = -ENODEV; goto exit; } spin_lock_irqsave(&dev->lock, flags); bytes_read = snprintf(in_buffer, 20, "%lld\n", dev->bbu); spin_unlock_irqrestore(&dev->lock, flags); if (*ppos < bytes_read) { if (copy_to_user(buffer, in_buffer + *ppos, bytes_read - *ppos)) retval = -EFAULT; else { retval = bytes_read - *ppos; *ppos += bytes_read; } } exit: mutex_unlock(&dev->io_mutex); return retval; } static ssize_t yurex_write(struct file *file, const char *user_buffer, size_t count, loff_t *ppos) { struct usb_yurex *dev; int i, set = 0, retval = 0; char buffer[16]; char *data = buffer; unsigned long long c, c2 = 0; signed long timeout = 0; DEFINE_WAIT(wait); count = min(sizeof(buffer), count); dev = (struct usb_yurex *)file->private_data; /* verify that we actually have some data to write */ if (count == 0) goto error; mutex_lock(&dev->io_mutex); if (!dev->interface) { /* alreaday disconnected */ mutex_unlock(&dev->io_mutex); retval = -ENODEV; goto error; } if (copy_from_user(buffer, user_buffer, count)) { mutex_unlock(&dev->io_mutex); retval = -EFAULT; goto error; } memset(dev->cntl_buffer, CMD_PADDING, YUREX_BUF_SIZE); switch (buffer[0]) { case CMD_ANIMATE: case CMD_LED: dev->cntl_buffer[0] = buffer[0]; dev->cntl_buffer[1] = buffer[1]; dev->cntl_buffer[2] = CMD_EOF; break; case CMD_READ: case CMD_VERSION: dev->cntl_buffer[0] = buffer[0]; dev->cntl_buffer[1] = 0x00; dev->cntl_buffer[2] = CMD_EOF; break; case CMD_SET: data++; /* FALL THROUGH */ case '0' ... '9': set = 1; c = c2 = simple_strtoull(data, NULL, 0); dev->cntl_buffer[0] = CMD_SET; for (i = 1; i < 6; i++) { dev->cntl_buffer[i] = (c>>32) & 0xff; c <<= 8; } buffer[6] = CMD_EOF; break; default: mutex_unlock(&dev->io_mutex); return -EINVAL; } /* send the data as the control msg */ prepare_to_wait(&dev->waitq, &wait, TASK_INTERRUPTIBLE); dev_dbg(&dev->interface->dev, "%s - submit %c\n", __func__, dev->cntl_buffer[0]); retval = usb_submit_urb(dev->cntl_urb, GFP_KERNEL); if (retval >= 0) timeout = schedule_timeout(YUREX_WRITE_TIMEOUT); finish_wait(&dev->waitq, &wait); mutex_unlock(&dev->io_mutex); if (retval < 0) { dev_err(&dev->interface->dev, "%s - failed to send bulk msg, error %d\n", __func__, retval); goto error; } if (set && timeout) dev->bbu = c2; return timeout ? count : -EIO; error: return retval; } static const struct file_operations yurex_fops = { .owner = THIS_MODULE, .read = yurex_read, .write = yurex_write, .open = yurex_open, .release = yurex_release, .fasync = yurex_fasync, .llseek = default_llseek, }; module_usb_driver(yurex_driver); MODULE_LICENSE("GPL");
gpl-2.0
MoKee/android_kernel_samsung_crespo
drivers/pci/hotplug/pciehp_acpi.c
3086
4210
/* * ACPI related functions for PCI Express Hot Plug driver. * * Copyright (C) 2008 Kenji Kaneshige * Copyright (C) 2008 Fujitsu Limited. * * All rights reserved. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or (at * your option) any later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or * NON INFRINGEMENT. See the GNU General Public License for more * details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * */ #include <linux/acpi.h> #include <linux/pci.h> #include <linux/pci_hotplug.h> #include <linux/slab.h> #include "pciehp.h" #define PCIEHP_DETECT_PCIE (0) #define PCIEHP_DETECT_ACPI (1) #define PCIEHP_DETECT_AUTO (2) #define PCIEHP_DETECT_DEFAULT PCIEHP_DETECT_AUTO struct dummy_slot { u32 number; struct list_head list; }; static int slot_detection_mode; static char *pciehp_detect_mode; module_param(pciehp_detect_mode, charp, 0444); MODULE_PARM_DESC(pciehp_detect_mode, "Slot detection mode: pcie, acpi, auto\n" " pcie - Use PCIe based slot detection\n" " acpi - Use ACPI for slot detection\n" " auto(default) - Auto select mode. Use acpi option if duplicate\n" " slot ids are found. Otherwise, use pcie option\n"); int pciehp_acpi_slot_detection_check(struct pci_dev *dev) { if (slot_detection_mode != PCIEHP_DETECT_ACPI) return 0; if (acpi_pci_detect_ejectable(DEVICE_ACPI_HANDLE(&dev->dev))) return 0; return -ENODEV; } static int __init parse_detect_mode(void) { if (!pciehp_detect_mode) return PCIEHP_DETECT_DEFAULT; if (!strcmp(pciehp_detect_mode, "pcie")) return PCIEHP_DETECT_PCIE; if (!strcmp(pciehp_detect_mode, "acpi")) return PCIEHP_DETECT_ACPI; if (!strcmp(pciehp_detect_mode, "auto")) return PCIEHP_DETECT_AUTO; warn("bad specifier '%s' for pciehp_detect_mode. Use default\n", pciehp_detect_mode); return PCIEHP_DETECT_DEFAULT; } static int __initdata dup_slot_id; static int __initdata acpi_slot_detected; static struct list_head __initdata dummy_slots = LIST_HEAD_INIT(dummy_slots); /* Dummy driver for dumplicate name detection */ static int __init dummy_probe(struct pcie_device *dev) { int pos; u32 slot_cap; acpi_handle handle; struct dummy_slot *slot, *tmp; struct pci_dev *pdev = dev->port; pos = pci_pcie_cap(pdev); if (!pos) return -ENODEV; pci_read_config_dword(pdev, pos + PCI_EXP_SLTCAP, &slot_cap); slot = kzalloc(sizeof(*slot), GFP_KERNEL); if (!slot) return -ENOMEM; slot->number = slot_cap >> 19; list_for_each_entry(tmp, &dummy_slots, list) { if (tmp->number == slot->number) dup_slot_id++; } list_add_tail(&slot->list, &dummy_slots); handle = DEVICE_ACPI_HANDLE(&pdev->dev); if (!acpi_slot_detected && acpi_pci_detect_ejectable(handle)) acpi_slot_detected = 1; return -ENODEV; /* dummy driver always returns error */ } static struct pcie_port_service_driver __initdata dummy_driver = { .name = "pciehp_dummy", .port_type = PCIE_ANY_PORT, .service = PCIE_PORT_SERVICE_HP, .probe = dummy_probe, }; static int __init select_detection_mode(void) { struct dummy_slot *slot, *tmp; if (pcie_port_service_register(&dummy_driver)) return PCIEHP_DETECT_ACPI; pcie_port_service_unregister(&dummy_driver); list_for_each_entry_safe(slot, tmp, &dummy_slots, list) { list_del(&slot->list); kfree(slot); } if (acpi_slot_detected && dup_slot_id) return PCIEHP_DETECT_ACPI; return PCIEHP_DETECT_PCIE; } void __init pciehp_acpi_slot_detection_init(void) { slot_detection_mode = parse_detect_mode(); if (slot_detection_mode != PCIEHP_DETECT_AUTO) goto out; slot_detection_mode = select_detection_mode(); out: if (slot_detection_mode == PCIEHP_DETECT_ACPI) info("Using ACPI for slot detection.\n"); }
gpl-2.0
davem330/net
drivers/staging/sbe-2t3e3/intr.c
3342
18876
/* * SBE 2T3E3 synchronous serial card driver for Linux * * Copyright (C) 2009-2010 Krzysztof Halasa <khc@pm.waw.pl> * * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License * as published by the Free Software Foundation. * * This code is based on a driver written by SBE Inc. */ #include <linux/hdlc.h> #include <linux/interrupt.h> #include <linux/netdevice.h> #include "2t3e3.h" irqreturn_t t3e3_intr(int irq, void *dev_instance) { struct channel *sc = dev_to_priv(dev_instance); u32 val; irqreturn_t ret = IRQ_NONE; sc->interrupt_active = 1; val = cpld_read(sc, SBE_2T3E3_CPLD_REG_PICSR); if (val & SBE_2T3E3_CPLD_VAL_RECEIVE_LOSS_OF_SIGNAL_CHANGE) { dev_dbg(&sc->pdev->dev, "Rx LOS Chng Int r=%02x (LOS|OOF=%02x)\n", val, (sc->s.LOS << 4) | sc->s.OOF); cpld_LOS_update(sc); ret = IRQ_HANDLED; } if (val & SBE_2T3E3_CPLD_VAL_INTERRUPT_FROM_ETHERNET_ASSERTED) { dc_intr(sc); ret = IRQ_HANDLED; } if (val & SBE_2T3E3_CPLD_VAL_INTERRUPT_FROM_FRAMER_ASSERTED) { exar7250_intr(sc); ret = IRQ_HANDLED; } /* we don't care about other interrupt sources (DMO, LOS, LCV) because they are handled by Framer too */ sc->interrupt_active = 0; return ret; } void dc_intr(struct channel *sc) { u32 val; /* disable ethernet interrupts */ /* grrr this clears interrupt summary bits !!! */ dc_write(sc->addr, SBE_2T3E3_21143_REG_INTERRUPT_ENABLE, 0); while ((val = dc_read(sc->addr, SBE_2T3E3_21143_REG_STATUS)) & (SBE_2T3E3_21143_VAL_RECEIVE_PROCESS_STOPPED | SBE_2T3E3_21143_VAL_RECEIVE_BUFFER_UNAVAILABLE | SBE_2T3E3_21143_VAL_RECEIVE_INTERRUPT | SBE_2T3E3_21143_VAL_TRANSMIT_UNDERFLOW | SBE_2T3E3_21143_VAL_TRANSMIT_BUFFER_UNAVAILABLE | SBE_2T3E3_21143_VAL_TRANSMIT_PROCESS_STOPPED | SBE_2T3E3_21143_VAL_TRANSMIT_INTERRUPT)) { dc_write(sc->addr, SBE_2T3E3_21143_REG_STATUS, val); dev_dbg(&sc->pdev->dev, "SBE 2T3E3: Ethernet controller interrupt! (CSR5 = %08X)\n", val); if (val & (SBE_2T3E3_21143_VAL_RECEIVE_INTERRUPT | SBE_2T3E3_21143_VAL_RECEIVE_BUFFER_UNAVAILABLE | SBE_2T3E3_21143_VAL_RECEIVE_PROCESS_STOPPED)) { if (val & SBE_2T3E3_21143_VAL_RECEIVE_INTERRUPT) dev_dbg(&sc->pdev->dev, "Receive interrupt (LOS=%d, OOF=%d)\n", sc->s.LOS, sc->s.OOF); if (val & SBE_2T3E3_21143_VAL_RECEIVE_BUFFER_UNAVAILABLE) dev_dbg(&sc->pdev->dev, "Receive buffer unavailable\n"); if (val & SBE_2T3E3_21143_VAL_RECEIVE_PROCESS_STOPPED) dev_dbg(&sc->pdev->dev, "Receive process stopped\n"); dc_intr_rx(sc); } if (val & SBE_2T3E3_21143_VAL_TRANSMIT_UNDERFLOW) { dev_dbg(&sc->pdev->dev, "Transmit underflow\n"); dc_intr_tx_underflow(sc); } if (val & (SBE_2T3E3_21143_VAL_TRANSMIT_BUFFER_UNAVAILABLE | SBE_2T3E3_21143_VAL_TRANSMIT_INTERRUPT | SBE_2T3E3_21143_VAL_TRANSMIT_PROCESS_STOPPED)) { if (val & SBE_2T3E3_21143_VAL_TRANSMIT_INTERRUPT) dev_dbg(&sc->pdev->dev, "Transmit interrupt\n"); if (val & SBE_2T3E3_21143_VAL_TRANSMIT_BUFFER_UNAVAILABLE) dev_dbg(&sc->pdev->dev, "Transmit buffer unavailable\n"); if (val & SBE_2T3E3_21143_VAL_TRANSMIT_PROCESS_STOPPED) dev_dbg(&sc->pdev->dev, "Transmit process stopped\n"); dc_intr_tx(sc); } } /* enable ethernet interrupts */ dc_write(sc->addr, SBE_2T3E3_21143_REG_INTERRUPT_ENABLE, sc->ether.interrupt_enable_mask); } void dc_intr_rx(struct channel *sc) { u32 current_read; u32 error_mask, error; t3e3_rx_desc_t *current_desc; struct sk_buff *m, *m2; unsigned rcv_len; sc->rcv_count++; /* for the activity LED */ current_read = sc->ether.rx_ring_current_read; dev_dbg(&sc->pdev->dev, "intr_rx current_read = %d\n", current_read); /* when ethernet loopback is set, ignore framer signals */ if ((sc->p.loopback != SBE_2T3E3_LOOPBACK_ETHERNET) && sc->s.OOF) { while (!(sc->ether.rx_ring[current_read].rdes0 & SBE_2T3E3_RX_DESC_21143_OWN)) { current_desc = &sc->ether.rx_ring[current_read]; current_desc->rdes1 &= SBE_2T3E3_RX_DESC_END_OF_RING | SBE_2T3E3_RX_DESC_SECOND_ADDRESS_CHAINED; current_desc->rdes1 |= SBE_2T3E3_MTU; current_desc->rdes0 = SBE_2T3E3_RX_DESC_21143_OWN; current_read = (current_read + 1) % SBE_2T3E3_RX_DESC_RING_SIZE; } sc->ether.rx_ring_current_read = current_read; return; } while (!(sc->ether.rx_ring[current_read].rdes0 & SBE_2T3E3_RX_DESC_21143_OWN)) { current_desc = &sc->ether.rx_ring[current_read]; dev_dbg(&sc->pdev->dev, "rdes0: %08X rdes1: %08X\n", current_desc->rdes0, current_desc->rdes1); m = sc->ether.rx_data[current_read]; rcv_len = (current_desc->rdes0 & SBE_2T3E3_RX_DESC_FRAME_LENGTH) >> SBE_2T3E3_RX_DESC_FRAME_LENGTH_SHIFT; dev_dbg(&sc->pdev->dev, "mbuf was received (mbuf len = %d)\n", rcv_len); switch (sc->p.crc) { case SBE_2T3E3_CRC_16: rcv_len -= SBE_2T3E3_CRC16_LENGTH; break; case SBE_2T3E3_CRC_32: rcv_len -= SBE_2T3E3_CRC32_LENGTH; break; default: break; } if (current_desc->rdes0 & SBE_2T3E3_RX_DESC_LAST_DESC) { /* TODO: is collision possible? */ error_mask = SBE_2T3E3_RX_DESC_DESC_ERROR | SBE_2T3E3_RX_DESC_COLLISION_SEEN | SBE_2T3E3_RX_DESC_DRIBBLING_BIT; switch (sc->p.frame_mode) { case SBE_2T3E3_FRAME_MODE_HDLC: error_mask |= SBE_2T3E3_RX_DESC_MII_ERROR; if (sc->p.crc == SBE_2T3E3_CRC_32) error_mask |= SBE_2T3E3_RX_DESC_CRC_ERROR; break; case SBE_2T3E3_FRAME_MODE_TRANSPARENT: case SBE_2T3E3_FRAME_MODE_RAW: break; default: error_mask = 0; } if (sc->s.LOS) { error_mask &= ~(SBE_2T3E3_RX_DESC_DRIBBLING_BIT || SBE_2T3E3_RX_DESC_MII_ERROR); } error = current_desc->rdes0 & error_mask; if (error) { sc->s.in_errors++; dev_dbg(&sc->pdev->dev, "error interrupt: NO_ERROR_MESSAGE = %d\n", sc->r.flags & SBE_2T3E3_FLAG_NO_ERROR_MESSAGES ? 1 : 0); current_desc->rdes1 &= SBE_2T3E3_RX_DESC_END_OF_RING | SBE_2T3E3_RX_DESC_SECOND_ADDRESS_CHAINED; current_desc->rdes1 |= SBE_2T3E3_MTU; current_desc->rdes0 = SBE_2T3E3_RX_DESC_21143_OWN; if (error & SBE_2T3E3_RX_DESC_DESC_ERROR) { if (!(sc->r.flags & SBE_2T3E3_FLAG_NO_ERROR_MESSAGES)) dev_err(&sc->pdev->dev, "SBE 2T3E3: descriptor error\n"); sc->s.in_error_desc++; } if (error & SBE_2T3E3_RX_DESC_COLLISION_SEEN) { if (!(sc->r.flags & SBE_2T3E3_FLAG_NO_ERROR_MESSAGES)) dev_err(&sc->pdev->dev, "SBE 2T3E3: collision seen\n"); sc->s.in_error_coll++; } else { if (error & SBE_2T3E3_RX_DESC_DRIBBLING_BIT) { if (!(sc->r.flags & SBE_2T3E3_FLAG_NO_ERROR_MESSAGES)) dev_err(&sc->pdev->dev, "SBE 2T3E3: dribbling bits error\n"); sc->s.in_error_drib++; } if (error & SBE_2T3E3_RX_DESC_CRC_ERROR) { if (!(sc->r.flags & SBE_2T3E3_FLAG_NO_ERROR_MESSAGES)) dev_err(&sc->pdev->dev, "SBE 2T3E3: crc error\n"); sc->s.in_error_crc++; } } if (error & SBE_2T3E3_RX_DESC_MII_ERROR) { if (!(sc->r.flags & SBE_2T3E3_FLAG_NO_ERROR_MESSAGES)) dev_err(&sc->pdev->dev, "SBE 2T3E3: mii error\n"); sc->s.in_error_mii++; } current_read = (current_read + 1) % SBE_2T3E3_RX_DESC_RING_SIZE; sc->r.flags |= SBE_2T3E3_FLAG_NO_ERROR_MESSAGES; continue; } } current_desc->rdes1 &= SBE_2T3E3_RX_DESC_END_OF_RING | SBE_2T3E3_RX_DESC_SECOND_ADDRESS_CHAINED; current_desc->rdes1 |= SBE_2T3E3_MTU; if (rcv_len > 1600) { sc->s.in_errors++; sc->s.in_dropped++; if (!(sc->r.flags & SBE_2T3E3_FLAG_NO_ERROR_MESSAGES)) dev_err(&sc->pdev->dev, "SBE 2T3E3: oversized rx: rdes0 = %08X\n", current_desc->rdes0); } else { m2 = dev_alloc_skb(MCLBYTES); if (m2 != NULL) { current_desc->rdes2 = virt_to_phys(m2->data); sc->ether.rx_data[current_read] = m2; sc->s.in_packets++; sc->s.in_bytes += rcv_len; m->dev = sc->dev; skb_put(m, rcv_len); skb_reset_mac_header(m); m->protocol = hdlc_type_trans(m, m->dev); netif_rx(m); /* good packet was received so we will show error messages again... */ if (sc->r.flags & SBE_2T3E3_FLAG_NO_ERROR_MESSAGES) { dev_dbg(&sc->pdev->dev, "setting ERROR_MESSAGES->0\n"); sc->r.flags &= ~SBE_2T3E3_FLAG_NO_ERROR_MESSAGES; } } else { sc->s.in_errors++; sc->s.in_dropped++; } } current_desc->rdes0 = SBE_2T3E3_RX_DESC_21143_OWN; current_read = (current_read + 1) % SBE_2T3E3_RX_DESC_RING_SIZE; } sc->ether.rx_ring_current_read = current_read; dc_write(sc->addr, SBE_2T3E3_21143_REG_RECEIVE_POLL_DEMAND, 0xFFFFFFFF); } void dc_intr_tx(struct channel *sc) { u32 current_read, current_write; u32 last_segment, error; t3e3_tx_desc_t *current_desc; spin_lock(&sc->ether.tx_lock); current_read = sc->ether.tx_ring_current_read; current_write = sc->ether.tx_ring_current_write; while (current_read != current_write) { current_desc = &sc->ether.tx_ring[current_read]; if (current_desc->tdes0 & SBE_2T3E3_RX_DESC_21143_OWN) break; dev_dbg(&sc->pdev->dev, "txeof: tdes0 = %08X tdes1 = %08X\n", current_desc->tdes0, current_desc->tdes1); error = current_desc->tdes0 & (SBE_2T3E3_TX_DESC_ERROR_SUMMARY | SBE_2T3E3_TX_DESC_TRANSMIT_JABBER_TIMEOUT | SBE_2T3E3_TX_DESC_LOSS_OF_CARRIER | SBE_2T3E3_TX_DESC_NO_CARRIER | SBE_2T3E3_TX_DESC_LINK_FAIL_REPORT | SBE_2T3E3_TX_DESC_UNDERFLOW_ERROR | SBE_2T3E3_TX_DESC_DEFFERED); last_segment = current_desc->tdes1 & SBE_2T3E3_TX_DESC_LAST_SEGMENT; current_desc->tdes0 = 0; current_desc->tdes1 &= SBE_2T3E3_TX_DESC_END_OF_RING | SBE_2T3E3_TX_DESC_SECOND_ADDRESS_CHAINED; current_desc->tdes2 = 0; sc->ether.tx_free_cnt++; if (last_segment != SBE_2T3E3_TX_DESC_LAST_SEGMENT) { current_read = (current_read + 1) % SBE_2T3E3_TX_DESC_RING_SIZE; continue; } if (sc->ether.tx_data[current_read]) { sc->s.out_packets++; sc->s.out_bytes += sc->ether.tx_data[current_read]->len; dev_kfree_skb_any(sc->ether.tx_data[current_read]); sc->ether.tx_data[current_read] = NULL; } if (error > 0) { sc->s.out_errors++; if (error & SBE_2T3E3_TX_DESC_TRANSMIT_JABBER_TIMEOUT) { dev_err(&sc->pdev->dev, "SBE 2T3E3: transmit jabber timeout\n"); sc->s.out_error_jab++; } if (sc->p.loopback != SBE_2T3E3_LOOPBACK_ETHERNET) { if (error & SBE_2T3E3_TX_DESC_LOSS_OF_CARRIER) { dev_err(&sc->pdev->dev, "SBE 2T3E3: loss of carrier\n"); sc->s.out_error_lost_carr++; } if (error & SBE_2T3E3_TX_DESC_NO_CARRIER) { dev_err(&sc->pdev->dev, "SBE 2T3E3: no carrier\n"); sc->s.out_error_no_carr++; } } if (error & SBE_2T3E3_TX_DESC_LINK_FAIL_REPORT) { dev_err(&sc->pdev->dev, "SBE 2T3E3: link fail report\n"); sc->s.out_error_link_fail++; } if (error & SBE_2T3E3_TX_DESC_UNDERFLOW_ERROR) { dev_err(&sc->pdev->dev, "SBE 2T3E3:" " transmission underflow error\n"); sc->s.out_error_underflow++; spin_unlock(&sc->ether.tx_lock); dc_restart(sc); return; } if (error & SBE_2T3E3_TX_DESC_DEFFERED) { dev_err(&sc->pdev->dev, "SBE 2T3E3: transmission deferred\n"); sc->s.out_error_dereferred++; } } current_read = (current_read + 1) % SBE_2T3E3_TX_DESC_RING_SIZE; } sc->ether.tx_ring_current_read = current_read; /* Relieve flow control when the TX queue is drained at least half way */ if (sc->ether.tx_full && (sc->ether.tx_free_cnt >= (SBE_2T3E3_TX_DESC_RING_SIZE / 2))) { sc->ether.tx_full = 0; netif_wake_queue(sc->dev); } spin_unlock(&sc->ether.tx_lock); } void dc_intr_tx_underflow(struct channel *sc) { u32 val; dc_transmitter_onoff(sc, SBE_2T3E3_OFF); val = dc_read(sc->addr, SBE_2T3E3_21143_REG_OPERATION_MODE); dc_clear_bits(sc->addr, SBE_2T3E3_21143_REG_OPERATION_MODE, SBE_2T3E3_21143_VAL_THRESHOLD_CONTROL_BITS); switch (val & SBE_2T3E3_21143_VAL_THRESHOLD_CONTROL_BITS) { case SBE_2T3E3_21143_VAL_THRESHOLD_CONTROL_BITS_1: dc_set_bits(sc->addr, SBE_2T3E3_21143_REG_OPERATION_MODE, SBE_2T3E3_21143_VAL_THRESHOLD_CONTROL_BITS_2); break; case SBE_2T3E3_21143_VAL_THRESHOLD_CONTROL_BITS_2: dc_set_bits(sc->addr, SBE_2T3E3_21143_REG_OPERATION_MODE, SBE_2T3E3_21143_VAL_THRESHOLD_CONTROL_BITS_3); break; case SBE_2T3E3_21143_VAL_THRESHOLD_CONTROL_BITS_3: dc_set_bits(sc->addr, SBE_2T3E3_21143_REG_OPERATION_MODE, SBE_2T3E3_21143_VAL_THRESHOLD_CONTROL_BITS_4); break; case SBE_2T3E3_21143_VAL_THRESHOLD_CONTROL_BITS_4: default: dc_set_bits(sc->addr, SBE_2T3E3_21143_REG_OPERATION_MODE, SBE_2T3E3_21143_VAL_STORE_AND_FORWARD); break; } dc_transmitter_onoff(sc, SBE_2T3E3_ON); } void exar7250_intr(struct channel *sc) { u32 status, old_OOF; #if 0 /* disable interrupts */ exar7250_write(sc, SBE_2T3E3_FRAMER_REG_BLOCK_INTERRUPT_ENABLE, 0); #endif old_OOF = sc->s.OOF; status = exar7250_read(sc, SBE_2T3E3_FRAMER_REG_BLOCK_INTERRUPT_STATUS); dev_dbg(&sc->pdev->dev, "SBE 2T3E3: Framer interrupt! (REG[0x05] = %02X)\n", status); switch (sc->p.frame_type) { case SBE_2T3E3_FRAME_TYPE_E3_G751: case SBE_2T3E3_FRAME_TYPE_E3_G832: exar7250_E3_intr(sc, status); break; case SBE_2T3E3_FRAME_TYPE_T3_CBIT: case SBE_2T3E3_FRAME_TYPE_T3_M13: exar7250_T3_intr(sc, status); break; default: break; } if (sc->s.OOF != old_OOF) { if (sc->s.OOF) { if (sc->p.loopback == SBE_2T3E3_LOOPBACK_NONE) { dev_dbg(&sc->pdev->dev, "SBE 2T3E3: Disabling eth interrupts\n"); /* turn off ethernet interrupts */ dc_stop_intr(sc); } } else if (sc->r.flags & SBE_2T3E3_FLAG_NETWORK_UP) { dev_dbg(&sc->pdev->dev, "SBE 2T3E3: Enabling eth interrupts\n"); /* start interrupts */ sc->s.OOF = 1; dc_intr_rx(sc); sc->s.OOF = 0; if (sc->p.receiver_on) { dc_receiver_onoff(sc, SBE_2T3E3_OFF); dc_receiver_onoff(sc, SBE_2T3E3_ON); } dc_start_intr(sc); } } #if 0 /* reenable interrupts */ exar7250_write(sc, SBE_2T3E3_FRAMER_REG_BLOCK_INTERRUPT_ENABLE, SBE_2T3E3_FRAMER_VAL_RX_INTERRUPT_ENABLE | SBE_2T3E3_FRAMER_VAL_TX_INTERRUPT_ENABLE ); #endif } void exar7250_T3_intr(struct channel *sc, u32 block_status) { u32 status, result; if (block_status & SBE_2T3E3_FRAMER_VAL_RX_INTERRUPT_STATUS) { status = exar7250_read(sc, SBE_2T3E3_FRAMER_REG_T3_RX_INTERRUPT_STATUS); if (status) { dev_dbg(&sc->pdev->dev, "Framer interrupt T3 RX (REG[0x13] = %02X)\n", status); result = exar7250_read(sc, SBE_2T3E3_FRAMER_REG_T3_RX_CONFIGURATION_STATUS); #if 0 if (status & SBE_2T3E3_FRAMER_VAL_T3_RX_LOS_INTERRUPT_STATUS) { dev_dbg(&sc->pdev->dev, "Framer interrupt T3: LOS\n"); sc->s.LOS = result & SBE_2T3E3_FRAMER_VAL_T3_RX_LOS ? 1 : 0; } #else cpld_LOS_update(sc); #endif if (status & SBE_2T3E3_FRAMER_VAL_T3_RX_OOF_INTERRUPT_STATUS) { sc->s.OOF = result & SBE_2T3E3_FRAMER_VAL_T3_RX_OOF ? 1 : 0; dev_dbg(&sc->pdev->dev, "Framer interrupt T3: OOF (%d)\n", sc->s.OOF); } exar7250_write(sc, SBE_2T3E3_FRAMER_REG_T3_RX_INTERRUPT_ENABLE, SBE_2T3E3_FRAMER_VAL_T3_RX_LOS_INTERRUPT_ENABLE | SBE_2T3E3_FRAMER_VAL_T3_RX_OOF_INTERRUPT_ENABLE); #if 0 SBE_2T3E3_FRAMER_VAL_T3_RX_CP_BIT_ERROR_INTERRUPT_ENABLE | SBE_2T3E3_FRAMER_VAL_T3_RX_LOS_INTERRUPT_ENABLE | SBE_2T3E3_FRAMER_VAL_T3_RX_AIS_INTERRUPT_ENABLE | SBE_2T3E3_FRAMER_VAL_T3_RX_IDLE_INTERRUPT_ENABLE | SBE_2T3E3_FRAMER_VAL_T3_RX_FERF_INTERRUPT_ENABLE | SBE_2T3E3_FRAMER_VAL_T3_RX_AIC_INTERRUPT_ENABLE | SBE_2T3E3_FRAMER_VAL_T3_RX_OOF_INTERRUPT_ENABLE | SBE_2T3E3_FRAMER_VAL_T3_RX_P_BIT_INTERRUPT_ENABLE #endif } status = exar7250_read(sc, SBE_2T3E3_FRAMER_REG_T3_RX_FEAC_INTERRUPT_ENABLE_STATUS); if (status) { dev_dbg(&sc->pdev->dev, "Framer interrupt T3 RX (REG[0x17] = %02X)\n", status); #if 0 exar7250_write(sc, SBE_2T3E3_FRAMER_REG_T3_RX_FEAC_INTERRUPT_ENABLE_STATUS, SBE_2T3E3_FRAMER_VAL_T3_RX_FEAC_REMOVE_INTERRUPT_ENABLE | SBE_2T3E3_FRAMER_VAL_T3_RX_FEAC_VALID_INTERRUPT_ENABLE ); #endif } status = exar7250_read(sc, SBE_2T3E3_FRAMER_REG_T3_RX_LAPD_CONTROL); if (status) dev_dbg(&sc->pdev->dev, "Framer interrupt T3 RX (REG[0x18] = %02X)\n", status); } if (block_status & SBE_2T3E3_FRAMER_VAL_TX_INTERRUPT_STATUS) { status = exar7250_read(sc, SBE_2T3E3_FRAMER_REG_T3_TX_FEAC_CONFIGURATION_STATUS); dev_dbg(&sc->pdev->dev, "SBE 2T3E3: Framer interrupt T3 TX (REG[0x31] = %02X)\n", status); status = exar7250_read(sc, SBE_2T3E3_FRAMER_REG_T3_TX_LAPD_STATUS); dev_dbg(&sc->pdev->dev, "SBE 2T3E3: Framer interrupt T3 TX (REG[0x34] = %02X)\n", status); } } void exar7250_E3_intr(struct channel *sc, u32 block_status) { u32 status, result; if (block_status & SBE_2T3E3_FRAMER_VAL_RX_INTERRUPT_STATUS) { status = exar7250_read(sc, SBE_2T3E3_FRAMER_REG_E3_RX_INTERRUPT_STATUS_1); if (status) { dev_dbg(&sc->pdev->dev, "Framer interrupt E3 RX (REG[0x14] = %02X)\n", status); result = exar7250_read(sc, SBE_2T3E3_FRAMER_REG_E3_RX_CONFIGURATION_STATUS_2); #if 0 if (status & SBE_2T3E3_FRAMER_VAL_E3_RX_LOS_INTERRUPT_STATUS) { dev_dbg(&sc->pdev->dev, "Framer interrupt E3: LOS\n"); sc->s.LOS = result & SBE_2T3E3_FRAMER_VAL_E3_RX_LOS ? 1 : 0; } #else cpld_LOS_update(sc); #endif if (status & SBE_2T3E3_FRAMER_VAL_E3_RX_OOF_INTERRUPT_STATUS) { sc->s.OOF = result & SBE_2T3E3_FRAMER_VAL_E3_RX_OOF ? 1 : 0; dev_dbg(&sc->pdev->dev, "Framer interrupt E3: OOF (%d)\n", sc->s.OOF); } exar7250_write(sc, SBE_2T3E3_FRAMER_REG_E3_RX_INTERRUPT_ENABLE_1, SBE_2T3E3_FRAMER_VAL_E3_RX_OOF_INTERRUPT_ENABLE | SBE_2T3E3_FRAMER_VAL_E3_RX_LOS_INTERRUPT_ENABLE ); #if 0 SBE_2T3E3_FRAMER_VAL_E3_RX_COFA_INTERRUPT_ENABLE | SBE_2T3E3_FRAMER_VAL_E3_RX_OOF_INTERRUPT_ENABLE | SBE_2T3E3_FRAMER_VAL_E3_RX_LOF_INTERRUPT_ENABLE | SBE_2T3E3_FRAMER_VAL_E3_RX_LOS_INTERRUPT_ENABLE | SBE_2T3E3_FRAMER_VAL_E3_RX_AIS_INTERRUPT_ENABLE #endif } status = exar7250_read(sc, SBE_2T3E3_FRAMER_REG_E3_RX_INTERRUPT_STATUS_2); if (status) { dev_dbg(&sc->pdev->dev, "Framer interrupt E3 RX (REG[0x15] = %02X)\n", status); #if 0 exar7250_write(sc, SBE_2T3E3_FRAMER_REG_E3_RX_INTERRUPT_ENABLE_2, SBE_2T3E3_FRAMER_VAL_E3_RX_FEBE_INTERRUPT_ENABLE | SBE_2T3E3_FRAMER_VAL_E3_RX_FERF_INTERRUPT_ENABLE | SBE_2T3E3_FRAMER_VAL_E3_RX_FRAMING_BYTE_ERROR_INTERRUPT_ENABLE); #endif } } if (block_status & SBE_2T3E3_FRAMER_VAL_TX_INTERRUPT_STATUS) { status = exar7250_read(sc, SBE_2T3E3_FRAMER_REG_E3_TX_LAPD_STATUS); dev_dbg(&sc->pdev->dev, "SBE 2T3E3: Framer interrupt E3 TX (REG[0x34] = %02X)\n", status); } }
gpl-2.0
de-wolff/caf_device_kernel_msm
fs/ntfs/super.c
4622
102464
/* * super.c - NTFS kernel super block handling. Part of the Linux-NTFS project. * * Copyright (c) 2001-2012 Anton Altaparmakov and Tuxera Inc. * Copyright (c) 2001,2002 Richard Russon * * This program/include file is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as published * by the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program/include file is distributed in the hope that it will be * useful, but WITHOUT ANY WARRANTY; without even the implied warranty * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program (in the main directory of the Linux-NTFS * distribution in the file COPYING); if not, write to the Free Software * Foundation,Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include <linux/stddef.h> #include <linux/init.h> #include <linux/slab.h> #include <linux/string.h> #include <linux/spinlock.h> #include <linux/blkdev.h> /* For bdev_logical_block_size(). */ #include <linux/backing-dev.h> #include <linux/buffer_head.h> #include <linux/vfs.h> #include <linux/moduleparam.h> #include <linux/bitmap.h> #include "sysctl.h" #include "logfile.h" #include "quota.h" #include "usnjrnl.h" #include "dir.h" #include "debug.h" #include "index.h" #include "inode.h" #include "aops.h" #include "layout.h" #include "malloc.h" #include "ntfs.h" /* Number of mounted filesystems which have compression enabled. */ static unsigned long ntfs_nr_compression_users; /* A global default upcase table and a corresponding reference count. */ static ntfschar *default_upcase = NULL; static unsigned long ntfs_nr_upcase_users = 0; /* Error constants/strings used in inode.c::ntfs_show_options(). */ typedef enum { /* One of these must be present, default is ON_ERRORS_CONTINUE. */ ON_ERRORS_PANIC = 0x01, ON_ERRORS_REMOUNT_RO = 0x02, ON_ERRORS_CONTINUE = 0x04, /* Optional, can be combined with any of the above. */ ON_ERRORS_RECOVER = 0x10, } ON_ERRORS_ACTIONS; const option_t on_errors_arr[] = { { ON_ERRORS_PANIC, "panic" }, { ON_ERRORS_REMOUNT_RO, "remount-ro", }, { ON_ERRORS_CONTINUE, "continue", }, { ON_ERRORS_RECOVER, "recover" }, { 0, NULL } }; /** * simple_getbool - * * Copied from old ntfs driver (which copied from vfat driver). */ static int simple_getbool(char *s, bool *setval) { if (s) { if (!strcmp(s, "1") || !strcmp(s, "yes") || !strcmp(s, "true")) *setval = true; else if (!strcmp(s, "0") || !strcmp(s, "no") || !strcmp(s, "false")) *setval = false; else return 0; } else *setval = true; return 1; } /** * parse_options - parse the (re)mount options * @vol: ntfs volume * @opt: string containing the (re)mount options * * Parse the recognized options in @opt for the ntfs volume described by @vol. */ static bool parse_options(ntfs_volume *vol, char *opt) { char *p, *v, *ov; static char *utf8 = "utf8"; int errors = 0, sloppy = 0; uid_t uid = (uid_t)-1; gid_t gid = (gid_t)-1; umode_t fmask = (umode_t)-1, dmask = (umode_t)-1; int mft_zone_multiplier = -1, on_errors = -1; int show_sys_files = -1, case_sensitive = -1, disable_sparse = -1; struct nls_table *nls_map = NULL, *old_nls; /* I am lazy... (-8 */ #define NTFS_GETOPT_WITH_DEFAULT(option, variable, default_value) \ if (!strcmp(p, option)) { \ if (!v || !*v) \ variable = default_value; \ else { \ variable = simple_strtoul(ov = v, &v, 0); \ if (*v) \ goto needs_val; \ } \ } #define NTFS_GETOPT(option, variable) \ if (!strcmp(p, option)) { \ if (!v || !*v) \ goto needs_arg; \ variable = simple_strtoul(ov = v, &v, 0); \ if (*v) \ goto needs_val; \ } #define NTFS_GETOPT_OCTAL(option, variable) \ if (!strcmp(p, option)) { \ if (!v || !*v) \ goto needs_arg; \ variable = simple_strtoul(ov = v, &v, 8); \ if (*v) \ goto needs_val; \ } #define NTFS_GETOPT_BOOL(option, variable) \ if (!strcmp(p, option)) { \ bool val; \ if (!simple_getbool(v, &val)) \ goto needs_bool; \ variable = val; \ } #define NTFS_GETOPT_OPTIONS_ARRAY(option, variable, opt_array) \ if (!strcmp(p, option)) { \ int _i; \ if (!v || !*v) \ goto needs_arg; \ ov = v; \ if (variable == -1) \ variable = 0; \ for (_i = 0; opt_array[_i].str && *opt_array[_i].str; _i++) \ if (!strcmp(opt_array[_i].str, v)) { \ variable |= opt_array[_i].val; \ break; \ } \ if (!opt_array[_i].str || !*opt_array[_i].str) \ goto needs_val; \ } if (!opt || !*opt) goto no_mount_options; ntfs_debug("Entering with mount options string: %s", opt); while ((p = strsep(&opt, ","))) { if ((v = strchr(p, '='))) *v++ = 0; NTFS_GETOPT("uid", uid) else NTFS_GETOPT("gid", gid) else NTFS_GETOPT_OCTAL("umask", fmask = dmask) else NTFS_GETOPT_OCTAL("fmask", fmask) else NTFS_GETOPT_OCTAL("dmask", dmask) else NTFS_GETOPT("mft_zone_multiplier", mft_zone_multiplier) else NTFS_GETOPT_WITH_DEFAULT("sloppy", sloppy, true) else NTFS_GETOPT_BOOL("show_sys_files", show_sys_files) else NTFS_GETOPT_BOOL("case_sensitive", case_sensitive) else NTFS_GETOPT_BOOL("disable_sparse", disable_sparse) else NTFS_GETOPT_OPTIONS_ARRAY("errors", on_errors, on_errors_arr) else if (!strcmp(p, "posix") || !strcmp(p, "show_inodes")) ntfs_warning(vol->sb, "Ignoring obsolete option %s.", p); else if (!strcmp(p, "nls") || !strcmp(p, "iocharset")) { if (!strcmp(p, "iocharset")) ntfs_warning(vol->sb, "Option iocharset is " "deprecated. Please use " "option nls=<charsetname> in " "the future."); if (!v || !*v) goto needs_arg; use_utf8: old_nls = nls_map; nls_map = load_nls(v); if (!nls_map) { if (!old_nls) { ntfs_error(vol->sb, "NLS character set " "%s not found.", v); return false; } ntfs_error(vol->sb, "NLS character set %s not " "found. Using previous one %s.", v, old_nls->charset); nls_map = old_nls; } else /* nls_map */ { unload_nls(old_nls); } } else if (!strcmp(p, "utf8")) { bool val = false; ntfs_warning(vol->sb, "Option utf8 is no longer " "supported, using option nls=utf8. Please " "use option nls=utf8 in the future and " "make sure utf8 is compiled either as a " "module or into the kernel."); if (!v || !*v) val = true; else if (!simple_getbool(v, &val)) goto needs_bool; if (val) { v = utf8; goto use_utf8; } } else { ntfs_error(vol->sb, "Unrecognized mount option %s.", p); if (errors < INT_MAX) errors++; } #undef NTFS_GETOPT_OPTIONS_ARRAY #undef NTFS_GETOPT_BOOL #undef NTFS_GETOPT #undef NTFS_GETOPT_WITH_DEFAULT } no_mount_options: if (errors && !sloppy) return false; if (sloppy) ntfs_warning(vol->sb, "Sloppy option given. Ignoring " "unrecognized mount option(s) and continuing."); /* Keep this first! */ if (on_errors != -1) { if (!on_errors) { ntfs_error(vol->sb, "Invalid errors option argument " "or bug in options parser."); return false; } } if (nls_map) { if (vol->nls_map && vol->nls_map != nls_map) { ntfs_error(vol->sb, "Cannot change NLS character set " "on remount."); return false; } /* else (!vol->nls_map) */ ntfs_debug("Using NLS character set %s.", nls_map->charset); vol->nls_map = nls_map; } else /* (!nls_map) */ { if (!vol->nls_map) { vol->nls_map = load_nls_default(); if (!vol->nls_map) { ntfs_error(vol->sb, "Failed to load default " "NLS character set."); return false; } ntfs_debug("Using default NLS character set (%s).", vol->nls_map->charset); } } if (mft_zone_multiplier != -1) { if (vol->mft_zone_multiplier && vol->mft_zone_multiplier != mft_zone_multiplier) { ntfs_error(vol->sb, "Cannot change mft_zone_multiplier " "on remount."); return false; } if (mft_zone_multiplier < 1 || mft_zone_multiplier > 4) { ntfs_error(vol->sb, "Invalid mft_zone_multiplier. " "Using default value, i.e. 1."); mft_zone_multiplier = 1; } vol->mft_zone_multiplier = mft_zone_multiplier; } if (!vol->mft_zone_multiplier) vol->mft_zone_multiplier = 1; if (on_errors != -1) vol->on_errors = on_errors; if (!vol->on_errors || vol->on_errors == ON_ERRORS_RECOVER) vol->on_errors |= ON_ERRORS_CONTINUE; if (uid != (uid_t)-1) vol->uid = uid; if (gid != (gid_t)-1) vol->gid = gid; if (fmask != (umode_t)-1) vol->fmask = fmask; if (dmask != (umode_t)-1) vol->dmask = dmask; if (show_sys_files != -1) { if (show_sys_files) NVolSetShowSystemFiles(vol); else NVolClearShowSystemFiles(vol); } if (case_sensitive != -1) { if (case_sensitive) NVolSetCaseSensitive(vol); else NVolClearCaseSensitive(vol); } if (disable_sparse != -1) { if (disable_sparse) NVolClearSparseEnabled(vol); else { if (!NVolSparseEnabled(vol) && vol->major_ver && vol->major_ver < 3) ntfs_warning(vol->sb, "Not enabling sparse " "support due to NTFS volume " "version %i.%i (need at least " "version 3.0).", vol->major_ver, vol->minor_ver); else NVolSetSparseEnabled(vol); } } return true; needs_arg: ntfs_error(vol->sb, "The %s option requires an argument.", p); return false; needs_bool: ntfs_error(vol->sb, "The %s option requires a boolean argument.", p); return false; needs_val: ntfs_error(vol->sb, "Invalid %s option argument: %s", p, ov); return false; } #ifdef NTFS_RW /** * ntfs_write_volume_flags - write new flags to the volume information flags * @vol: ntfs volume on which to modify the flags * @flags: new flags value for the volume information flags * * Internal function. You probably want to use ntfs_{set,clear}_volume_flags() * instead (see below). * * Replace the volume information flags on the volume @vol with the value * supplied in @flags. Note, this overwrites the volume information flags, so * make sure to combine the flags you want to modify with the old flags and use * the result when calling ntfs_write_volume_flags(). * * Return 0 on success and -errno on error. */ static int ntfs_write_volume_flags(ntfs_volume *vol, const VOLUME_FLAGS flags) { ntfs_inode *ni = NTFS_I(vol->vol_ino); MFT_RECORD *m; VOLUME_INFORMATION *vi; ntfs_attr_search_ctx *ctx; int err; ntfs_debug("Entering, old flags = 0x%x, new flags = 0x%x.", le16_to_cpu(vol->vol_flags), le16_to_cpu(flags)); if (vol->vol_flags == flags) goto done; BUG_ON(!ni); m = map_mft_record(ni); if (IS_ERR(m)) { err = PTR_ERR(m); goto err_out; } ctx = ntfs_attr_get_search_ctx(ni, m); if (!ctx) { err = -ENOMEM; goto put_unm_err_out; } err = ntfs_attr_lookup(AT_VOLUME_INFORMATION, NULL, 0, 0, 0, NULL, 0, ctx); if (err) goto put_unm_err_out; vi = (VOLUME_INFORMATION*)((u8*)ctx->attr + le16_to_cpu(ctx->attr->data.resident.value_offset)); vol->vol_flags = vi->flags = flags; flush_dcache_mft_record_page(ctx->ntfs_ino); mark_mft_record_dirty(ctx->ntfs_ino); ntfs_attr_put_search_ctx(ctx); unmap_mft_record(ni); done: ntfs_debug("Done."); return 0; put_unm_err_out: if (ctx) ntfs_attr_put_search_ctx(ctx); unmap_mft_record(ni); err_out: ntfs_error(vol->sb, "Failed with error code %i.", -err); return err; } /** * ntfs_set_volume_flags - set bits in the volume information flags * @vol: ntfs volume on which to modify the flags * @flags: flags to set on the volume * * Set the bits in @flags in the volume information flags on the volume @vol. * * Return 0 on success and -errno on error. */ static inline int ntfs_set_volume_flags(ntfs_volume *vol, VOLUME_FLAGS flags) { flags &= VOLUME_FLAGS_MASK; return ntfs_write_volume_flags(vol, vol->vol_flags | flags); } /** * ntfs_clear_volume_flags - clear bits in the volume information flags * @vol: ntfs volume on which to modify the flags * @flags: flags to clear on the volume * * Clear the bits in @flags in the volume information flags on the volume @vol. * * Return 0 on success and -errno on error. */ static inline int ntfs_clear_volume_flags(ntfs_volume *vol, VOLUME_FLAGS flags) { flags &= VOLUME_FLAGS_MASK; flags = vol->vol_flags & cpu_to_le16(~le16_to_cpu(flags)); return ntfs_write_volume_flags(vol, flags); } #endif /* NTFS_RW */ /** * ntfs_remount - change the mount options of a mounted ntfs filesystem * @sb: superblock of mounted ntfs filesystem * @flags: remount flags * @opt: remount options string * * Change the mount options of an already mounted ntfs filesystem. * * NOTE: The VFS sets the @sb->s_flags remount flags to @flags after * ntfs_remount() returns successfully (i.e. returns 0). Otherwise, * @sb->s_flags are not changed. */ static int ntfs_remount(struct super_block *sb, int *flags, char *opt) { ntfs_volume *vol = NTFS_SB(sb); ntfs_debug("Entering with remount options string: %s", opt); #ifndef NTFS_RW /* For read-only compiled driver, enforce read-only flag. */ *flags |= MS_RDONLY; #else /* NTFS_RW */ /* * For the read-write compiled driver, if we are remounting read-write, * make sure there are no volume errors and that no unsupported volume * flags are set. Also, empty the logfile journal as it would become * stale as soon as something is written to the volume and mark the * volume dirty so that chkdsk is run if the volume is not umounted * cleanly. Finally, mark the quotas out of date so Windows rescans * the volume on boot and updates them. * * When remounting read-only, mark the volume clean if no volume errors * have occurred. */ if ((sb->s_flags & MS_RDONLY) && !(*flags & MS_RDONLY)) { static const char *es = ". Cannot remount read-write."; /* Remounting read-write. */ if (NVolErrors(vol)) { ntfs_error(sb, "Volume has errors and is read-only%s", es); return -EROFS; } if (vol->vol_flags & VOLUME_IS_DIRTY) { ntfs_error(sb, "Volume is dirty and read-only%s", es); return -EROFS; } if (vol->vol_flags & VOLUME_MODIFIED_BY_CHKDSK) { ntfs_error(sb, "Volume has been modified by chkdsk " "and is read-only%s", es); return -EROFS; } if (vol->vol_flags & VOLUME_MUST_MOUNT_RO_MASK) { ntfs_error(sb, "Volume has unsupported flags set " "(0x%x) and is read-only%s", (unsigned)le16_to_cpu(vol->vol_flags), es); return -EROFS; } if (ntfs_set_volume_flags(vol, VOLUME_IS_DIRTY)) { ntfs_error(sb, "Failed to set dirty bit in volume " "information flags%s", es); return -EROFS; } #if 0 // TODO: Enable this code once we start modifying anything that // is different between NTFS 1.2 and 3.x... /* Set NT4 compatibility flag on newer NTFS version volumes. */ if ((vol->major_ver > 1)) { if (ntfs_set_volume_flags(vol, VOLUME_MOUNTED_ON_NT4)) { ntfs_error(sb, "Failed to set NT4 " "compatibility flag%s", es); NVolSetErrors(vol); return -EROFS; } } #endif if (!ntfs_empty_logfile(vol->logfile_ino)) { ntfs_error(sb, "Failed to empty journal $LogFile%s", es); NVolSetErrors(vol); return -EROFS; } if (!ntfs_mark_quotas_out_of_date(vol)) { ntfs_error(sb, "Failed to mark quotas out of date%s", es); NVolSetErrors(vol); return -EROFS; } if (!ntfs_stamp_usnjrnl(vol)) { ntfs_error(sb, "Failed to stamp transation log " "($UsnJrnl)%s", es); NVolSetErrors(vol); return -EROFS; } } else if (!(sb->s_flags & MS_RDONLY) && (*flags & MS_RDONLY)) { /* Remounting read-only. */ if (!NVolErrors(vol)) { if (ntfs_clear_volume_flags(vol, VOLUME_IS_DIRTY)) ntfs_warning(sb, "Failed to clear dirty bit " "in volume information " "flags. Run chkdsk."); } } #endif /* NTFS_RW */ // TODO: Deal with *flags. if (!parse_options(vol, opt)) return -EINVAL; ntfs_debug("Done."); return 0; } /** * is_boot_sector_ntfs - check whether a boot sector is a valid NTFS boot sector * @sb: Super block of the device to which @b belongs. * @b: Boot sector of device @sb to check. * @silent: If 'true', all output will be silenced. * * is_boot_sector_ntfs() checks whether the boot sector @b is a valid NTFS boot * sector. Returns 'true' if it is valid and 'false' if not. * * @sb is only needed for warning/error output, i.e. it can be NULL when silent * is 'true'. */ static bool is_boot_sector_ntfs(const struct super_block *sb, const NTFS_BOOT_SECTOR *b, const bool silent) { /* * Check that checksum == sum of u32 values from b to the checksum * field. If checksum is zero, no checking is done. We will work when * the checksum test fails, since some utilities update the boot sector * ignoring the checksum which leaves the checksum out-of-date. We * report a warning if this is the case. */ if ((void*)b < (void*)&b->checksum && b->checksum && !silent) { le32 *u; u32 i; for (i = 0, u = (le32*)b; u < (le32*)(&b->checksum); ++u) i += le32_to_cpup(u); if (le32_to_cpu(b->checksum) != i) ntfs_warning(sb, "Invalid boot sector checksum."); } /* Check OEMidentifier is "NTFS " */ if (b->oem_id != magicNTFS) goto not_ntfs; /* Check bytes per sector value is between 256 and 4096. */ if (le16_to_cpu(b->bpb.bytes_per_sector) < 0x100 || le16_to_cpu(b->bpb.bytes_per_sector) > 0x1000) goto not_ntfs; /* Check sectors per cluster value is valid. */ switch (b->bpb.sectors_per_cluster) { case 1: case 2: case 4: case 8: case 16: case 32: case 64: case 128: break; default: goto not_ntfs; } /* Check the cluster size is not above the maximum (64kiB). */ if ((u32)le16_to_cpu(b->bpb.bytes_per_sector) * b->bpb.sectors_per_cluster > NTFS_MAX_CLUSTER_SIZE) goto not_ntfs; /* Check reserved/unused fields are really zero. */ if (le16_to_cpu(b->bpb.reserved_sectors) || le16_to_cpu(b->bpb.root_entries) || le16_to_cpu(b->bpb.sectors) || le16_to_cpu(b->bpb.sectors_per_fat) || le32_to_cpu(b->bpb.large_sectors) || b->bpb.fats) goto not_ntfs; /* Check clusters per file mft record value is valid. */ if ((u8)b->clusters_per_mft_record < 0xe1 || (u8)b->clusters_per_mft_record > 0xf7) switch (b->clusters_per_mft_record) { case 1: case 2: case 4: case 8: case 16: case 32: case 64: break; default: goto not_ntfs; } /* Check clusters per index block value is valid. */ if ((u8)b->clusters_per_index_record < 0xe1 || (u8)b->clusters_per_index_record > 0xf7) switch (b->clusters_per_index_record) { case 1: case 2: case 4: case 8: case 16: case 32: case 64: break; default: goto not_ntfs; } /* * Check for valid end of sector marker. We will work without it, but * many BIOSes will refuse to boot from a bootsector if the magic is * incorrect, so we emit a warning. */ if (!silent && b->end_of_sector_marker != cpu_to_le16(0xaa55)) ntfs_warning(sb, "Invalid end of sector marker."); return true; not_ntfs: return false; } /** * read_ntfs_boot_sector - read the NTFS boot sector of a device * @sb: super block of device to read the boot sector from * @silent: if true, suppress all output * * Reads the boot sector from the device and validates it. If that fails, tries * to read the backup boot sector, first from the end of the device a-la NT4 and * later and then from the middle of the device a-la NT3.51 and before. * * If a valid boot sector is found but it is not the primary boot sector, we * repair the primary boot sector silently (unless the device is read-only or * the primary boot sector is not accessible). * * NOTE: To call this function, @sb must have the fields s_dev, the ntfs super * block (u.ntfs_sb), nr_blocks and the device flags (s_flags) initialized * to their respective values. * * Return the unlocked buffer head containing the boot sector or NULL on error. */ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb, const int silent) { const char *read_err_str = "Unable to read %s boot sector."; struct buffer_head *bh_primary, *bh_backup; sector_t nr_blocks = NTFS_SB(sb)->nr_blocks; /* Try to read primary boot sector. */ if ((bh_primary = sb_bread(sb, 0))) { if (is_boot_sector_ntfs(sb, (NTFS_BOOT_SECTOR*) bh_primary->b_data, silent)) return bh_primary; if (!silent) ntfs_error(sb, "Primary boot sector is invalid."); } else if (!silent) ntfs_error(sb, read_err_str, "primary"); if (!(NTFS_SB(sb)->on_errors & ON_ERRORS_RECOVER)) { if (bh_primary) brelse(bh_primary); if (!silent) ntfs_error(sb, "Mount option errors=recover not used. " "Aborting without trying to recover."); return NULL; } /* Try to read NT4+ backup boot sector. */ if ((bh_backup = sb_bread(sb, nr_blocks - 1))) { if (is_boot_sector_ntfs(sb, (NTFS_BOOT_SECTOR*) bh_backup->b_data, silent)) goto hotfix_primary_boot_sector; brelse(bh_backup); } else if (!silent) ntfs_error(sb, read_err_str, "backup"); /* Try to read NT3.51- backup boot sector. */ if ((bh_backup = sb_bread(sb, nr_blocks >> 1))) { if (is_boot_sector_ntfs(sb, (NTFS_BOOT_SECTOR*) bh_backup->b_data, silent)) goto hotfix_primary_boot_sector; if (!silent) ntfs_error(sb, "Could not find a valid backup boot " "sector."); brelse(bh_backup); } else if (!silent) ntfs_error(sb, read_err_str, "backup"); /* We failed. Cleanup and return. */ if (bh_primary) brelse(bh_primary); return NULL; hotfix_primary_boot_sector: if (bh_primary) { /* * If we managed to read sector zero and the volume is not * read-only, copy the found, valid backup boot sector to the * primary boot sector. Note we only copy the actual boot * sector structure, not the actual whole device sector as that * may be bigger and would potentially damage the $Boot system * file (FIXME: Would be nice to know if the backup boot sector * on a large sector device contains the whole boot loader or * just the first 512 bytes). */ if (!(sb->s_flags & MS_RDONLY)) { ntfs_warning(sb, "Hot-fix: Recovering invalid primary " "boot sector from backup copy."); memcpy(bh_primary->b_data, bh_backup->b_data, NTFS_BLOCK_SIZE); mark_buffer_dirty(bh_primary); sync_dirty_buffer(bh_primary); if (buffer_uptodate(bh_primary)) { brelse(bh_backup); return bh_primary; } ntfs_error(sb, "Hot-fix: Device write error while " "recovering primary boot sector."); } else { ntfs_warning(sb, "Hot-fix: Recovery of primary boot " "sector failed: Read-only mount."); } brelse(bh_primary); } ntfs_warning(sb, "Using backup boot sector."); return bh_backup; } /** * parse_ntfs_boot_sector - parse the boot sector and store the data in @vol * @vol: volume structure to initialise with data from boot sector * @b: boot sector to parse * * Parse the ntfs boot sector @b and store all imporant information therein in * the ntfs super block @vol. Return 'true' on success and 'false' on error. */ static bool parse_ntfs_boot_sector(ntfs_volume *vol, const NTFS_BOOT_SECTOR *b) { unsigned int sectors_per_cluster_bits, nr_hidden_sects; int clusters_per_mft_record, clusters_per_index_record; s64 ll; vol->sector_size = le16_to_cpu(b->bpb.bytes_per_sector); vol->sector_size_bits = ffs(vol->sector_size) - 1; ntfs_debug("vol->sector_size = %i (0x%x)", vol->sector_size, vol->sector_size); ntfs_debug("vol->sector_size_bits = %i (0x%x)", vol->sector_size_bits, vol->sector_size_bits); if (vol->sector_size < vol->sb->s_blocksize) { ntfs_error(vol->sb, "Sector size (%i) is smaller than the " "device block size (%lu). This is not " "supported. Sorry.", vol->sector_size, vol->sb->s_blocksize); return false; } ntfs_debug("sectors_per_cluster = 0x%x", b->bpb.sectors_per_cluster); sectors_per_cluster_bits = ffs(b->bpb.sectors_per_cluster) - 1; ntfs_debug("sectors_per_cluster_bits = 0x%x", sectors_per_cluster_bits); nr_hidden_sects = le32_to_cpu(b->bpb.hidden_sectors); ntfs_debug("number of hidden sectors = 0x%x", nr_hidden_sects); vol->cluster_size = vol->sector_size << sectors_per_cluster_bits; vol->cluster_size_mask = vol->cluster_size - 1; vol->cluster_size_bits = ffs(vol->cluster_size) - 1; ntfs_debug("vol->cluster_size = %i (0x%x)", vol->cluster_size, vol->cluster_size); ntfs_debug("vol->cluster_size_mask = 0x%x", vol->cluster_size_mask); ntfs_debug("vol->cluster_size_bits = %i", vol->cluster_size_bits); if (vol->cluster_size < vol->sector_size) { ntfs_error(vol->sb, "Cluster size (%i) is smaller than the " "sector size (%i). This is not supported. " "Sorry.", vol->cluster_size, vol->sector_size); return false; } clusters_per_mft_record = b->clusters_per_mft_record; ntfs_debug("clusters_per_mft_record = %i (0x%x)", clusters_per_mft_record, clusters_per_mft_record); if (clusters_per_mft_record > 0) vol->mft_record_size = vol->cluster_size << (ffs(clusters_per_mft_record) - 1); else /* * When mft_record_size < cluster_size, clusters_per_mft_record * = -log2(mft_record_size) bytes. mft_record_size normaly is * 1024 bytes, which is encoded as 0xF6 (-10 in decimal). */ vol->mft_record_size = 1 << -clusters_per_mft_record; vol->mft_record_size_mask = vol->mft_record_size - 1; vol->mft_record_size_bits = ffs(vol->mft_record_size) - 1; ntfs_debug("vol->mft_record_size = %i (0x%x)", vol->mft_record_size, vol->mft_record_size); ntfs_debug("vol->mft_record_size_mask = 0x%x", vol->mft_record_size_mask); ntfs_debug("vol->mft_record_size_bits = %i (0x%x)", vol->mft_record_size_bits, vol->mft_record_size_bits); /* * We cannot support mft record sizes above the PAGE_CACHE_SIZE since * we store $MFT/$DATA, the table of mft records in the page cache. */ if (vol->mft_record_size > PAGE_CACHE_SIZE) { ntfs_error(vol->sb, "Mft record size (%i) exceeds the " "PAGE_CACHE_SIZE on your system (%lu). " "This is not supported. Sorry.", vol->mft_record_size, PAGE_CACHE_SIZE); return false; } /* We cannot support mft record sizes below the sector size. */ if (vol->mft_record_size < vol->sector_size) { ntfs_error(vol->sb, "Mft record size (%i) is smaller than the " "sector size (%i). This is not supported. " "Sorry.", vol->mft_record_size, vol->sector_size); return false; } clusters_per_index_record = b->clusters_per_index_record; ntfs_debug("clusters_per_index_record = %i (0x%x)", clusters_per_index_record, clusters_per_index_record); if (clusters_per_index_record > 0) vol->index_record_size = vol->cluster_size << (ffs(clusters_per_index_record) - 1); else /* * When index_record_size < cluster_size, * clusters_per_index_record = -log2(index_record_size) bytes. * index_record_size normaly equals 4096 bytes, which is * encoded as 0xF4 (-12 in decimal). */ vol->index_record_size = 1 << -clusters_per_index_record; vol->index_record_size_mask = vol->index_record_size - 1; vol->index_record_size_bits = ffs(vol->index_record_size) - 1; ntfs_debug("vol->index_record_size = %i (0x%x)", vol->index_record_size, vol->index_record_size); ntfs_debug("vol->index_record_size_mask = 0x%x", vol->index_record_size_mask); ntfs_debug("vol->index_record_size_bits = %i (0x%x)", vol->index_record_size_bits, vol->index_record_size_bits); /* We cannot support index record sizes below the sector size. */ if (vol->index_record_size < vol->sector_size) { ntfs_error(vol->sb, "Index record size (%i) is smaller than " "the sector size (%i). This is not " "supported. Sorry.", vol->index_record_size, vol->sector_size); return false; } /* * Get the size of the volume in clusters and check for 64-bit-ness. * Windows currently only uses 32 bits to save the clusters so we do * the same as it is much faster on 32-bit CPUs. */ ll = sle64_to_cpu(b->number_of_sectors) >> sectors_per_cluster_bits; if ((u64)ll >= 1ULL << 32) { ntfs_error(vol->sb, "Cannot handle 64-bit clusters. Sorry."); return false; } vol->nr_clusters = ll; ntfs_debug("vol->nr_clusters = 0x%llx", (long long)vol->nr_clusters); /* * On an architecture where unsigned long is 32-bits, we restrict the * volume size to 2TiB (2^41). On a 64-bit architecture, the compiler * will hopefully optimize the whole check away. */ if (sizeof(unsigned long) < 8) { if ((ll << vol->cluster_size_bits) >= (1ULL << 41)) { ntfs_error(vol->sb, "Volume size (%lluTiB) is too " "large for this architecture. " "Maximum supported is 2TiB. Sorry.", (unsigned long long)ll >> (40 - vol->cluster_size_bits)); return false; } } ll = sle64_to_cpu(b->mft_lcn); if (ll >= vol->nr_clusters) { ntfs_error(vol->sb, "MFT LCN (%lli, 0x%llx) is beyond end of " "volume. Weird.", (unsigned long long)ll, (unsigned long long)ll); return false; } vol->mft_lcn = ll; ntfs_debug("vol->mft_lcn = 0x%llx", (long long)vol->mft_lcn); ll = sle64_to_cpu(b->mftmirr_lcn); if (ll >= vol->nr_clusters) { ntfs_error(vol->sb, "MFTMirr LCN (%lli, 0x%llx) is beyond end " "of volume. Weird.", (unsigned long long)ll, (unsigned long long)ll); return false; } vol->mftmirr_lcn = ll; ntfs_debug("vol->mftmirr_lcn = 0x%llx", (long long)vol->mftmirr_lcn); #ifdef NTFS_RW /* * Work out the size of the mft mirror in number of mft records. If the * cluster size is less than or equal to the size taken by four mft * records, the mft mirror stores the first four mft records. If the * cluster size is bigger than the size taken by four mft records, the * mft mirror contains as many mft records as will fit into one * cluster. */ if (vol->cluster_size <= (4 << vol->mft_record_size_bits)) vol->mftmirr_size = 4; else vol->mftmirr_size = vol->cluster_size >> vol->mft_record_size_bits; ntfs_debug("vol->mftmirr_size = %i", vol->mftmirr_size); #endif /* NTFS_RW */ vol->serial_no = le64_to_cpu(b->volume_serial_number); ntfs_debug("vol->serial_no = 0x%llx", (unsigned long long)vol->serial_no); return true; } /** * ntfs_setup_allocators - initialize the cluster and mft allocators * @vol: volume structure for which to setup the allocators * * Setup the cluster (lcn) and mft allocators to the starting values. */ static void ntfs_setup_allocators(ntfs_volume *vol) { #ifdef NTFS_RW LCN mft_zone_size, mft_lcn; #endif /* NTFS_RW */ ntfs_debug("vol->mft_zone_multiplier = 0x%x", vol->mft_zone_multiplier); #ifdef NTFS_RW /* Determine the size of the MFT zone. */ mft_zone_size = vol->nr_clusters; switch (vol->mft_zone_multiplier) { /* % of volume size in clusters */ case 4: mft_zone_size >>= 1; /* 50% */ break; case 3: mft_zone_size = (mft_zone_size + (mft_zone_size >> 1)) >> 2; /* 37.5% */ break; case 2: mft_zone_size >>= 2; /* 25% */ break; /* case 1: */ default: mft_zone_size >>= 3; /* 12.5% */ break; } /* Setup the mft zone. */ vol->mft_zone_start = vol->mft_zone_pos = vol->mft_lcn; ntfs_debug("vol->mft_zone_pos = 0x%llx", (unsigned long long)vol->mft_zone_pos); /* * Calculate the mft_lcn for an unmodified NTFS volume (see mkntfs * source) and if the actual mft_lcn is in the expected place or even * further to the front of the volume, extend the mft_zone to cover the * beginning of the volume as well. This is in order to protect the * area reserved for the mft bitmap as well within the mft_zone itself. * On non-standard volumes we do not protect it as the overhead would * be higher than the speed increase we would get by doing it. */ mft_lcn = (8192 + 2 * vol->cluster_size - 1) / vol->cluster_size; if (mft_lcn * vol->cluster_size < 16 * 1024) mft_lcn = (16 * 1024 + vol->cluster_size - 1) / vol->cluster_size; if (vol->mft_zone_start <= mft_lcn) vol->mft_zone_start = 0; ntfs_debug("vol->mft_zone_start = 0x%llx", (unsigned long long)vol->mft_zone_start); /* * Need to cap the mft zone on non-standard volumes so that it does * not point outside the boundaries of the volume. We do this by * halving the zone size until we are inside the volume. */ vol->mft_zone_end = vol->mft_lcn + mft_zone_size; while (vol->mft_zone_end >= vol->nr_clusters) { mft_zone_size >>= 1; vol->mft_zone_end = vol->mft_lcn + mft_zone_size; } ntfs_debug("vol->mft_zone_end = 0x%llx", (unsigned long long)vol->mft_zone_end); /* * Set the current position within each data zone to the start of the * respective zone. */ vol->data1_zone_pos = vol->mft_zone_end; ntfs_debug("vol->data1_zone_pos = 0x%llx", (unsigned long long)vol->data1_zone_pos); vol->data2_zone_pos = 0; ntfs_debug("vol->data2_zone_pos = 0x%llx", (unsigned long long)vol->data2_zone_pos); /* Set the mft data allocation position to mft record 24. */ vol->mft_data_pos = 24; ntfs_debug("vol->mft_data_pos = 0x%llx", (unsigned long long)vol->mft_data_pos); #endif /* NTFS_RW */ } #ifdef NTFS_RW /** * load_and_init_mft_mirror - load and setup the mft mirror inode for a volume * @vol: ntfs super block describing device whose mft mirror to load * * Return 'true' on success or 'false' on error. */ static bool load_and_init_mft_mirror(ntfs_volume *vol) { struct inode *tmp_ino; ntfs_inode *tmp_ni; ntfs_debug("Entering."); /* Get mft mirror inode. */ tmp_ino = ntfs_iget(vol->sb, FILE_MFTMirr); if (IS_ERR(tmp_ino) || is_bad_inode(tmp_ino)) { if (!IS_ERR(tmp_ino)) iput(tmp_ino); /* Caller will display error message. */ return false; } /* * Re-initialize some specifics about $MFTMirr's inode as * ntfs_read_inode() will have set up the default ones. */ /* Set uid and gid to root. */ tmp_ino->i_uid = tmp_ino->i_gid = 0; /* Regular file. No access for anyone. */ tmp_ino->i_mode = S_IFREG; /* No VFS initiated operations allowed for $MFTMirr. */ tmp_ino->i_op = &ntfs_empty_inode_ops; tmp_ino->i_fop = &ntfs_empty_file_ops; /* Put in our special address space operations. */ tmp_ino->i_mapping->a_ops = &ntfs_mst_aops; tmp_ni = NTFS_I(tmp_ino); /* The $MFTMirr, like the $MFT is multi sector transfer protected. */ NInoSetMstProtected(tmp_ni); NInoSetSparseDisabled(tmp_ni); /* * Set up our little cheat allowing us to reuse the async read io * completion handler for directories. */ tmp_ni->itype.index.block_size = vol->mft_record_size; tmp_ni->itype.index.block_size_bits = vol->mft_record_size_bits; vol->mftmirr_ino = tmp_ino; ntfs_debug("Done."); return true; } /** * check_mft_mirror - compare contents of the mft mirror with the mft * @vol: ntfs super block describing device whose mft mirror to check * * Return 'true' on success or 'false' on error. * * Note, this function also results in the mft mirror runlist being completely * mapped into memory. The mft mirror write code requires this and will BUG() * should it find an unmapped runlist element. */ static bool check_mft_mirror(ntfs_volume *vol) { struct super_block *sb = vol->sb; ntfs_inode *mirr_ni; struct page *mft_page, *mirr_page; u8 *kmft, *kmirr; runlist_element *rl, rl2[2]; pgoff_t index; int mrecs_per_page, i; ntfs_debug("Entering."); /* Compare contents of $MFT and $MFTMirr. */ mrecs_per_page = PAGE_CACHE_SIZE / vol->mft_record_size; BUG_ON(!mrecs_per_page); BUG_ON(!vol->mftmirr_size); mft_page = mirr_page = NULL; kmft = kmirr = NULL; index = i = 0; do { u32 bytes; /* Switch pages if necessary. */ if (!(i % mrecs_per_page)) { if (index) { ntfs_unmap_page(mft_page); ntfs_unmap_page(mirr_page); } /* Get the $MFT page. */ mft_page = ntfs_map_page(vol->mft_ino->i_mapping, index); if (IS_ERR(mft_page)) { ntfs_error(sb, "Failed to read $MFT."); return false; } kmft = page_address(mft_page); /* Get the $MFTMirr page. */ mirr_page = ntfs_map_page(vol->mftmirr_ino->i_mapping, index); if (IS_ERR(mirr_page)) { ntfs_error(sb, "Failed to read $MFTMirr."); goto mft_unmap_out; } kmirr = page_address(mirr_page); ++index; } /* Do not check the record if it is not in use. */ if (((MFT_RECORD*)kmft)->flags & MFT_RECORD_IN_USE) { /* Make sure the record is ok. */ if (ntfs_is_baad_recordp((le32*)kmft)) { ntfs_error(sb, "Incomplete multi sector " "transfer detected in mft " "record %i.", i); mm_unmap_out: ntfs_unmap_page(mirr_page); mft_unmap_out: ntfs_unmap_page(mft_page); return false; } } /* Do not check the mirror record if it is not in use. */ if (((MFT_RECORD*)kmirr)->flags & MFT_RECORD_IN_USE) { if (ntfs_is_baad_recordp((le32*)kmirr)) { ntfs_error(sb, "Incomplete multi sector " "transfer detected in mft " "mirror record %i.", i); goto mm_unmap_out; } } /* Get the amount of data in the current record. */ bytes = le32_to_cpu(((MFT_RECORD*)kmft)->bytes_in_use); if (bytes < sizeof(MFT_RECORD_OLD) || bytes > vol->mft_record_size || ntfs_is_baad_recordp((le32*)kmft)) { bytes = le32_to_cpu(((MFT_RECORD*)kmirr)->bytes_in_use); if (bytes < sizeof(MFT_RECORD_OLD) || bytes > vol->mft_record_size || ntfs_is_baad_recordp((le32*)kmirr)) bytes = vol->mft_record_size; } /* Compare the two records. */ if (memcmp(kmft, kmirr, bytes)) { ntfs_error(sb, "$MFT and $MFTMirr (record %i) do not " "match. Run ntfsfix or chkdsk.", i); goto mm_unmap_out; } kmft += vol->mft_record_size; kmirr += vol->mft_record_size; } while (++i < vol->mftmirr_size); /* Release the last pages. */ ntfs_unmap_page(mft_page); ntfs_unmap_page(mirr_page); /* Construct the mft mirror runlist by hand. */ rl2[0].vcn = 0; rl2[0].lcn = vol->mftmirr_lcn; rl2[0].length = (vol->mftmirr_size * vol->mft_record_size + vol->cluster_size - 1) / vol->cluster_size; rl2[1].vcn = rl2[0].length; rl2[1].lcn = LCN_ENOENT; rl2[1].length = 0; /* * Because we have just read all of the mft mirror, we know we have * mapped the full runlist for it. */ mirr_ni = NTFS_I(vol->mftmirr_ino); down_read(&mirr_ni->runlist.lock); rl = mirr_ni->runlist.rl; /* Compare the two runlists. They must be identical. */ i = 0; do { if (rl2[i].vcn != rl[i].vcn || rl2[i].lcn != rl[i].lcn || rl2[i].length != rl[i].length) { ntfs_error(sb, "$MFTMirr location mismatch. " "Run chkdsk."); up_read(&mirr_ni->runlist.lock); return false; } } while (rl2[i++].length); up_read(&mirr_ni->runlist.lock); ntfs_debug("Done."); return true; } /** * load_and_check_logfile - load and check the logfile inode for a volume * @vol: ntfs super block describing device whose logfile to load * * Return 'true' on success or 'false' on error. */ static bool load_and_check_logfile(ntfs_volume *vol, RESTART_PAGE_HEADER **rp) { struct inode *tmp_ino; ntfs_debug("Entering."); tmp_ino = ntfs_iget(vol->sb, FILE_LogFile); if (IS_ERR(tmp_ino) || is_bad_inode(tmp_ino)) { if (!IS_ERR(tmp_ino)) iput(tmp_ino); /* Caller will display error message. */ return false; } if (!ntfs_check_logfile(tmp_ino, rp)) { iput(tmp_ino); /* ntfs_check_logfile() will have displayed error output. */ return false; } NInoSetSparseDisabled(NTFS_I(tmp_ino)); vol->logfile_ino = tmp_ino; ntfs_debug("Done."); return true; } #define NTFS_HIBERFIL_HEADER_SIZE 4096 /** * check_windows_hibernation_status - check if Windows is suspended on a volume * @vol: ntfs super block of device to check * * Check if Windows is hibernated on the ntfs volume @vol. This is done by * looking for the file hiberfil.sys in the root directory of the volume. If * the file is not present Windows is definitely not suspended. * * If hiberfil.sys exists and is less than 4kiB in size it means Windows is * definitely suspended (this volume is not the system volume). Caveat: on a * system with many volumes it is possible that the < 4kiB check is bogus but * for now this should do fine. * * If hiberfil.sys exists and is larger than 4kiB in size, we need to read the * hiberfil header (which is the first 4kiB). If this begins with "hibr", * Windows is definitely suspended. If it is completely full of zeroes, * Windows is definitely not hibernated. Any other case is treated as if * Windows is suspended. This caters for the above mentioned caveat of a * system with many volumes where no "hibr" magic would be present and there is * no zero header. * * Return 0 if Windows is not hibernated on the volume, >0 if Windows is * hibernated on the volume, and -errno on error. */ static int check_windows_hibernation_status(ntfs_volume *vol) { MFT_REF mref; struct inode *vi; struct page *page; u32 *kaddr, *kend; ntfs_name *name = NULL; int ret = 1; static const ntfschar hiberfil[13] = { cpu_to_le16('h'), cpu_to_le16('i'), cpu_to_le16('b'), cpu_to_le16('e'), cpu_to_le16('r'), cpu_to_le16('f'), cpu_to_le16('i'), cpu_to_le16('l'), cpu_to_le16('.'), cpu_to_le16('s'), cpu_to_le16('y'), cpu_to_le16('s'), 0 }; ntfs_debug("Entering."); /* * Find the inode number for the hibernation file by looking up the * filename hiberfil.sys in the root directory. */ mutex_lock(&vol->root_ino->i_mutex); mref = ntfs_lookup_inode_by_name(NTFS_I(vol->root_ino), hiberfil, 12, &name); mutex_unlock(&vol->root_ino->i_mutex); if (IS_ERR_MREF(mref)) { ret = MREF_ERR(mref); /* If the file does not exist, Windows is not hibernated. */ if (ret == -ENOENT) { ntfs_debug("hiberfil.sys not present. Windows is not " "hibernated on the volume."); return 0; } /* A real error occurred. */ ntfs_error(vol->sb, "Failed to find inode number for " "hiberfil.sys."); return ret; } /* We do not care for the type of match that was found. */ kfree(name); /* Get the inode. */ vi = ntfs_iget(vol->sb, MREF(mref)); if (IS_ERR(vi) || is_bad_inode(vi)) { if (!IS_ERR(vi)) iput(vi); ntfs_error(vol->sb, "Failed to load hiberfil.sys."); return IS_ERR(vi) ? PTR_ERR(vi) : -EIO; } if (unlikely(i_size_read(vi) < NTFS_HIBERFIL_HEADER_SIZE)) { ntfs_debug("hiberfil.sys is smaller than 4kiB (0x%llx). " "Windows is hibernated on the volume. This " "is not the system volume.", i_size_read(vi)); goto iput_out; } page = ntfs_map_page(vi->i_mapping, 0); if (IS_ERR(page)) { ntfs_error(vol->sb, "Failed to read from hiberfil.sys."); ret = PTR_ERR(page); goto iput_out; } kaddr = (u32*)page_address(page); if (*(le32*)kaddr == cpu_to_le32(0x72626968)/*'hibr'*/) { ntfs_debug("Magic \"hibr\" found in hiberfil.sys. Windows is " "hibernated on the volume. This is the " "system volume."); goto unm_iput_out; } kend = kaddr + NTFS_HIBERFIL_HEADER_SIZE/sizeof(*kaddr); do { if (unlikely(*kaddr)) { ntfs_debug("hiberfil.sys is larger than 4kiB " "(0x%llx), does not contain the " "\"hibr\" magic, and does not have a " "zero header. Windows is hibernated " "on the volume. This is not the " "system volume.", i_size_read(vi)); goto unm_iput_out; } } while (++kaddr < kend); ntfs_debug("hiberfil.sys contains a zero header. Windows is not " "hibernated on the volume. This is the system " "volume."); ret = 0; unm_iput_out: ntfs_unmap_page(page); iput_out: iput(vi); return ret; } /** * load_and_init_quota - load and setup the quota file for a volume if present * @vol: ntfs super block describing device whose quota file to load * * Return 'true' on success or 'false' on error. If $Quota is not present, we * leave vol->quota_ino as NULL and return success. */ static bool load_and_init_quota(ntfs_volume *vol) { MFT_REF mref; struct inode *tmp_ino; ntfs_name *name = NULL; static const ntfschar Quota[7] = { cpu_to_le16('$'), cpu_to_le16('Q'), cpu_to_le16('u'), cpu_to_le16('o'), cpu_to_le16('t'), cpu_to_le16('a'), 0 }; static ntfschar Q[3] = { cpu_to_le16('$'), cpu_to_le16('Q'), 0 }; ntfs_debug("Entering."); /* * Find the inode number for the quota file by looking up the filename * $Quota in the extended system files directory $Extend. */ mutex_lock(&vol->extend_ino->i_mutex); mref = ntfs_lookup_inode_by_name(NTFS_I(vol->extend_ino), Quota, 6, &name); mutex_unlock(&vol->extend_ino->i_mutex); if (IS_ERR_MREF(mref)) { /* * If the file does not exist, quotas are disabled and have * never been enabled on this volume, just return success. */ if (MREF_ERR(mref) == -ENOENT) { ntfs_debug("$Quota not present. Volume does not have " "quotas enabled."); /* * No need to try to set quotas out of date if they are * not enabled. */ NVolSetQuotaOutOfDate(vol); return true; } /* A real error occurred. */ ntfs_error(vol->sb, "Failed to find inode number for $Quota."); return false; } /* We do not care for the type of match that was found. */ kfree(name); /* Get the inode. */ tmp_ino = ntfs_iget(vol->sb, MREF(mref)); if (IS_ERR(tmp_ino) || is_bad_inode(tmp_ino)) { if (!IS_ERR(tmp_ino)) iput(tmp_ino); ntfs_error(vol->sb, "Failed to load $Quota."); return false; } vol->quota_ino = tmp_ino; /* Get the $Q index allocation attribute. */ tmp_ino = ntfs_index_iget(vol->quota_ino, Q, 2); if (IS_ERR(tmp_ino)) { ntfs_error(vol->sb, "Failed to load $Quota/$Q index."); return false; } vol->quota_q_ino = tmp_ino; ntfs_debug("Done."); return true; } /** * load_and_init_usnjrnl - load and setup the transaction log if present * @vol: ntfs super block describing device whose usnjrnl file to load * * Return 'true' on success or 'false' on error. * * If $UsnJrnl is not present or in the process of being disabled, we set * NVolUsnJrnlStamped() and return success. * * If the $UsnJrnl $DATA/$J attribute has a size equal to the lowest valid usn, * i.e. transaction logging has only just been enabled or the journal has been * stamped and nothing has been logged since, we also set NVolUsnJrnlStamped() * and return success. */ static bool load_and_init_usnjrnl(ntfs_volume *vol) { MFT_REF mref; struct inode *tmp_ino; ntfs_inode *tmp_ni; struct page *page; ntfs_name *name = NULL; USN_HEADER *uh; static const ntfschar UsnJrnl[9] = { cpu_to_le16('$'), cpu_to_le16('U'), cpu_to_le16('s'), cpu_to_le16('n'), cpu_to_le16('J'), cpu_to_le16('r'), cpu_to_le16('n'), cpu_to_le16('l'), 0 }; static ntfschar Max[5] = { cpu_to_le16('$'), cpu_to_le16('M'), cpu_to_le16('a'), cpu_to_le16('x'), 0 }; static ntfschar J[3] = { cpu_to_le16('$'), cpu_to_le16('J'), 0 }; ntfs_debug("Entering."); /* * Find the inode number for the transaction log file by looking up the * filename $UsnJrnl in the extended system files directory $Extend. */ mutex_lock(&vol->extend_ino->i_mutex); mref = ntfs_lookup_inode_by_name(NTFS_I(vol->extend_ino), UsnJrnl, 8, &name); mutex_unlock(&vol->extend_ino->i_mutex); if (IS_ERR_MREF(mref)) { /* * If the file does not exist, transaction logging is disabled, * just return success. */ if (MREF_ERR(mref) == -ENOENT) { ntfs_debug("$UsnJrnl not present. Volume does not " "have transaction logging enabled."); not_enabled: /* * No need to try to stamp the transaction log if * transaction logging is not enabled. */ NVolSetUsnJrnlStamped(vol); return true; } /* A real error occurred. */ ntfs_error(vol->sb, "Failed to find inode number for " "$UsnJrnl."); return false; } /* We do not care for the type of match that was found. */ kfree(name); /* Get the inode. */ tmp_ino = ntfs_iget(vol->sb, MREF(mref)); if (unlikely(IS_ERR(tmp_ino) || is_bad_inode(tmp_ino))) { if (!IS_ERR(tmp_ino)) iput(tmp_ino); ntfs_error(vol->sb, "Failed to load $UsnJrnl."); return false; } vol->usnjrnl_ino = tmp_ino; /* * If the transaction log is in the process of being deleted, we can * ignore it. */ if (unlikely(vol->vol_flags & VOLUME_DELETE_USN_UNDERWAY)) { ntfs_debug("$UsnJrnl in the process of being disabled. " "Volume does not have transaction logging " "enabled."); goto not_enabled; } /* Get the $DATA/$Max attribute. */ tmp_ino = ntfs_attr_iget(vol->usnjrnl_ino, AT_DATA, Max, 4); if (IS_ERR(tmp_ino)) { ntfs_error(vol->sb, "Failed to load $UsnJrnl/$DATA/$Max " "attribute."); return false; } vol->usnjrnl_max_ino = tmp_ino; if (unlikely(i_size_read(tmp_ino) < sizeof(USN_HEADER))) { ntfs_error(vol->sb, "Found corrupt $UsnJrnl/$DATA/$Max " "attribute (size is 0x%llx but should be at " "least 0x%zx bytes).", i_size_read(tmp_ino), sizeof(USN_HEADER)); return false; } /* Get the $DATA/$J attribute. */ tmp_ino = ntfs_attr_iget(vol->usnjrnl_ino, AT_DATA, J, 2); if (IS_ERR(tmp_ino)) { ntfs_error(vol->sb, "Failed to load $UsnJrnl/$DATA/$J " "attribute."); return false; } vol->usnjrnl_j_ino = tmp_ino; /* Verify $J is non-resident and sparse. */ tmp_ni = NTFS_I(vol->usnjrnl_j_ino); if (unlikely(!NInoNonResident(tmp_ni) || !NInoSparse(tmp_ni))) { ntfs_error(vol->sb, "$UsnJrnl/$DATA/$J attribute is resident " "and/or not sparse."); return false; } /* Read the USN_HEADER from $DATA/$Max. */ page = ntfs_map_page(vol->usnjrnl_max_ino->i_mapping, 0); if (IS_ERR(page)) { ntfs_error(vol->sb, "Failed to read from $UsnJrnl/$DATA/$Max " "attribute."); return false; } uh = (USN_HEADER*)page_address(page); /* Sanity check the $Max. */ if (unlikely(sle64_to_cpu(uh->allocation_delta) > sle64_to_cpu(uh->maximum_size))) { ntfs_error(vol->sb, "Allocation delta (0x%llx) exceeds " "maximum size (0x%llx). $UsnJrnl is corrupt.", (long long)sle64_to_cpu(uh->allocation_delta), (long long)sle64_to_cpu(uh->maximum_size)); ntfs_unmap_page(page); return false; } /* * If the transaction log has been stamped and nothing has been written * to it since, we do not need to stamp it. */ if (unlikely(sle64_to_cpu(uh->lowest_valid_usn) >= i_size_read(vol->usnjrnl_j_ino))) { if (likely(sle64_to_cpu(uh->lowest_valid_usn) == i_size_read(vol->usnjrnl_j_ino))) { ntfs_unmap_page(page); ntfs_debug("$UsnJrnl is enabled but nothing has been " "logged since it was last stamped. " "Treating this as if the volume does " "not have transaction logging " "enabled."); goto not_enabled; } ntfs_error(vol->sb, "$UsnJrnl has lowest valid usn (0x%llx) " "which is out of bounds (0x%llx). $UsnJrnl " "is corrupt.", (long long)sle64_to_cpu(uh->lowest_valid_usn), i_size_read(vol->usnjrnl_j_ino)); ntfs_unmap_page(page); return false; } ntfs_unmap_page(page); ntfs_debug("Done."); return true; } /** * load_and_init_attrdef - load the attribute definitions table for a volume * @vol: ntfs super block describing device whose attrdef to load * * Return 'true' on success or 'false' on error. */ static bool load_and_init_attrdef(ntfs_volume *vol) { loff_t i_size; struct super_block *sb = vol->sb; struct inode *ino; struct page *page; pgoff_t index, max_index; unsigned int size; ntfs_debug("Entering."); /* Read attrdef table and setup vol->attrdef and vol->attrdef_size. */ ino = ntfs_iget(sb, FILE_AttrDef); if (IS_ERR(ino) || is_bad_inode(ino)) { if (!IS_ERR(ino)) iput(ino); goto failed; } NInoSetSparseDisabled(NTFS_I(ino)); /* The size of FILE_AttrDef must be above 0 and fit inside 31 bits. */ i_size = i_size_read(ino); if (i_size <= 0 || i_size > 0x7fffffff) goto iput_failed; vol->attrdef = (ATTR_DEF*)ntfs_malloc_nofs(i_size); if (!vol->attrdef) goto iput_failed; index = 0; max_index = i_size >> PAGE_CACHE_SHIFT; size = PAGE_CACHE_SIZE; while (index < max_index) { /* Read the attrdef table and copy it into the linear buffer. */ read_partial_attrdef_page: page = ntfs_map_page(ino->i_mapping, index); if (IS_ERR(page)) goto free_iput_failed; memcpy((u8*)vol->attrdef + (index++ << PAGE_CACHE_SHIFT), page_address(page), size); ntfs_unmap_page(page); }; if (size == PAGE_CACHE_SIZE) { size = i_size & ~PAGE_CACHE_MASK; if (size) goto read_partial_attrdef_page; } vol->attrdef_size = i_size; ntfs_debug("Read %llu bytes from $AttrDef.", i_size); iput(ino); return true; free_iput_failed: ntfs_free(vol->attrdef); vol->attrdef = NULL; iput_failed: iput(ino); failed: ntfs_error(sb, "Failed to initialize attribute definition table."); return false; } #endif /* NTFS_RW */ /** * load_and_init_upcase - load the upcase table for an ntfs volume * @vol: ntfs super block describing device whose upcase to load * * Return 'true' on success or 'false' on error. */ static bool load_and_init_upcase(ntfs_volume *vol) { loff_t i_size; struct super_block *sb = vol->sb; struct inode *ino; struct page *page; pgoff_t index, max_index; unsigned int size; int i, max; ntfs_debug("Entering."); /* Read upcase table and setup vol->upcase and vol->upcase_len. */ ino = ntfs_iget(sb, FILE_UpCase); if (IS_ERR(ino) || is_bad_inode(ino)) { if (!IS_ERR(ino)) iput(ino); goto upcase_failed; } /* * The upcase size must not be above 64k Unicode characters, must not * be zero and must be a multiple of sizeof(ntfschar). */ i_size = i_size_read(ino); if (!i_size || i_size & (sizeof(ntfschar) - 1) || i_size > 64ULL * 1024 * sizeof(ntfschar)) goto iput_upcase_failed; vol->upcase = (ntfschar*)ntfs_malloc_nofs(i_size); if (!vol->upcase) goto iput_upcase_failed; index = 0; max_index = i_size >> PAGE_CACHE_SHIFT; size = PAGE_CACHE_SIZE; while (index < max_index) { /* Read the upcase table and copy it into the linear buffer. */ read_partial_upcase_page: page = ntfs_map_page(ino->i_mapping, index); if (IS_ERR(page)) goto iput_upcase_failed; memcpy((char*)vol->upcase + (index++ << PAGE_CACHE_SHIFT), page_address(page), size); ntfs_unmap_page(page); }; if (size == PAGE_CACHE_SIZE) { size = i_size & ~PAGE_CACHE_MASK; if (size) goto read_partial_upcase_page; } vol->upcase_len = i_size >> UCHAR_T_SIZE_BITS; ntfs_debug("Read %llu bytes from $UpCase (expected %zu bytes).", i_size, 64 * 1024 * sizeof(ntfschar)); iput(ino); mutex_lock(&ntfs_lock); if (!default_upcase) { ntfs_debug("Using volume specified $UpCase since default is " "not present."); mutex_unlock(&ntfs_lock); return true; } max = default_upcase_len; if (max > vol->upcase_len) max = vol->upcase_len; for (i = 0; i < max; i++) if (vol->upcase[i] != default_upcase[i]) break; if (i == max) { ntfs_free(vol->upcase); vol->upcase = default_upcase; vol->upcase_len = max; ntfs_nr_upcase_users++; mutex_unlock(&ntfs_lock); ntfs_debug("Volume specified $UpCase matches default. Using " "default."); return true; } mutex_unlock(&ntfs_lock); ntfs_debug("Using volume specified $UpCase since it does not match " "the default."); return true; iput_upcase_failed: iput(ino); ntfs_free(vol->upcase); vol->upcase = NULL; upcase_failed: mutex_lock(&ntfs_lock); if (default_upcase) { vol->upcase = default_upcase; vol->upcase_len = default_upcase_len; ntfs_nr_upcase_users++; mutex_unlock(&ntfs_lock); ntfs_error(sb, "Failed to load $UpCase from the volume. Using " "default."); return true; } mutex_unlock(&ntfs_lock); ntfs_error(sb, "Failed to initialize upcase table."); return false; } /* * The lcn and mft bitmap inodes are NTFS-internal inodes with * their own special locking rules: */ static struct lock_class_key lcnbmp_runlist_lock_key, lcnbmp_mrec_lock_key, mftbmp_runlist_lock_key, mftbmp_mrec_lock_key; /** * load_system_files - open the system files using normal functions * @vol: ntfs super block describing device whose system files to load * * Open the system files with normal access functions and complete setting up * the ntfs super block @vol. * * Return 'true' on success or 'false' on error. */ static bool load_system_files(ntfs_volume *vol) { struct super_block *sb = vol->sb; MFT_RECORD *m; VOLUME_INFORMATION *vi; ntfs_attr_search_ctx *ctx; #ifdef NTFS_RW RESTART_PAGE_HEADER *rp; int err; #endif /* NTFS_RW */ ntfs_debug("Entering."); #ifdef NTFS_RW /* Get mft mirror inode compare the contents of $MFT and $MFTMirr. */ if (!load_and_init_mft_mirror(vol) || !check_mft_mirror(vol)) { static const char *es1 = "Failed to load $MFTMirr"; static const char *es2 = "$MFTMirr does not match $MFT"; static const char *es3 = ". Run ntfsfix and/or chkdsk."; /* If a read-write mount, convert it to a read-only mount. */ if (!(sb->s_flags & MS_RDONLY)) { if (!(vol->on_errors & (ON_ERRORS_REMOUNT_RO | ON_ERRORS_CONTINUE))) { ntfs_error(sb, "%s and neither on_errors=" "continue nor on_errors=" "remount-ro was specified%s", !vol->mftmirr_ino ? es1 : es2, es3); goto iput_mirr_err_out; } sb->s_flags |= MS_RDONLY; ntfs_error(sb, "%s. Mounting read-only%s", !vol->mftmirr_ino ? es1 : es2, es3); } else ntfs_warning(sb, "%s. Will not be able to remount " "read-write%s", !vol->mftmirr_ino ? es1 : es2, es3); /* This will prevent a read-write remount. */ NVolSetErrors(vol); } #endif /* NTFS_RW */ /* Get mft bitmap attribute inode. */ vol->mftbmp_ino = ntfs_attr_iget(vol->mft_ino, AT_BITMAP, NULL, 0); if (IS_ERR(vol->mftbmp_ino)) { ntfs_error(sb, "Failed to load $MFT/$BITMAP attribute."); goto iput_mirr_err_out; } lockdep_set_class(&NTFS_I(vol->mftbmp_ino)->runlist.lock, &mftbmp_runlist_lock_key); lockdep_set_class(&NTFS_I(vol->mftbmp_ino)->mrec_lock, &mftbmp_mrec_lock_key); /* Read upcase table and setup @vol->upcase and @vol->upcase_len. */ if (!load_and_init_upcase(vol)) goto iput_mftbmp_err_out; #ifdef NTFS_RW /* * Read attribute definitions table and setup @vol->attrdef and * @vol->attrdef_size. */ if (!load_and_init_attrdef(vol)) goto iput_upcase_err_out; #endif /* NTFS_RW */ /* * Get the cluster allocation bitmap inode and verify the size, no * need for any locking at this stage as we are already running * exclusively as we are mount in progress task. */ vol->lcnbmp_ino = ntfs_iget(sb, FILE_Bitmap); if (IS_ERR(vol->lcnbmp_ino) || is_bad_inode(vol->lcnbmp_ino)) { if (!IS_ERR(vol->lcnbmp_ino)) iput(vol->lcnbmp_ino); goto bitmap_failed; } lockdep_set_class(&NTFS_I(vol->lcnbmp_ino)->runlist.lock, &lcnbmp_runlist_lock_key); lockdep_set_class(&NTFS_I(vol->lcnbmp_ino)->mrec_lock, &lcnbmp_mrec_lock_key); NInoSetSparseDisabled(NTFS_I(vol->lcnbmp_ino)); if ((vol->nr_clusters + 7) >> 3 > i_size_read(vol->lcnbmp_ino)) { iput(vol->lcnbmp_ino); bitmap_failed: ntfs_error(sb, "Failed to load $Bitmap."); goto iput_attrdef_err_out; } /* * Get the volume inode and setup our cache of the volume flags and * version. */ vol->vol_ino = ntfs_iget(sb, FILE_Volume); if (IS_ERR(vol->vol_ino) || is_bad_inode(vol->vol_ino)) { if (!IS_ERR(vol->vol_ino)) iput(vol->vol_ino); volume_failed: ntfs_error(sb, "Failed to load $Volume."); goto iput_lcnbmp_err_out; } m = map_mft_record(NTFS_I(vol->vol_ino)); if (IS_ERR(m)) { iput_volume_failed: iput(vol->vol_ino); goto volume_failed; } if (!(ctx = ntfs_attr_get_search_ctx(NTFS_I(vol->vol_ino), m))) { ntfs_error(sb, "Failed to get attribute search context."); goto get_ctx_vol_failed; } if (ntfs_attr_lookup(AT_VOLUME_INFORMATION, NULL, 0, 0, 0, NULL, 0, ctx) || ctx->attr->non_resident || ctx->attr->flags) { err_put_vol: ntfs_attr_put_search_ctx(ctx); get_ctx_vol_failed: unmap_mft_record(NTFS_I(vol->vol_ino)); goto iput_volume_failed; } vi = (VOLUME_INFORMATION*)((char*)ctx->attr + le16_to_cpu(ctx->attr->data.resident.value_offset)); /* Some bounds checks. */ if ((u8*)vi < (u8*)ctx->attr || (u8*)vi + le32_to_cpu(ctx->attr->data.resident.value_length) > (u8*)ctx->attr + le32_to_cpu(ctx->attr->length)) goto err_put_vol; /* Copy the volume flags and version to the ntfs_volume structure. */ vol->vol_flags = vi->flags; vol->major_ver = vi->major_ver; vol->minor_ver = vi->minor_ver; ntfs_attr_put_search_ctx(ctx); unmap_mft_record(NTFS_I(vol->vol_ino)); printk(KERN_INFO "NTFS volume version %i.%i.\n", vol->major_ver, vol->minor_ver); if (vol->major_ver < 3 && NVolSparseEnabled(vol)) { ntfs_warning(vol->sb, "Disabling sparse support due to NTFS " "volume version %i.%i (need at least version " "3.0).", vol->major_ver, vol->minor_ver); NVolClearSparseEnabled(vol); } #ifdef NTFS_RW /* Make sure that no unsupported volume flags are set. */ if (vol->vol_flags & VOLUME_MUST_MOUNT_RO_MASK) { static const char *es1a = "Volume is dirty"; static const char *es1b = "Volume has been modified by chkdsk"; static const char *es1c = "Volume has unsupported flags set"; static const char *es2a = ". Run chkdsk and mount in Windows."; static const char *es2b = ". Mount in Windows."; const char *es1, *es2; es2 = es2a; if (vol->vol_flags & VOLUME_IS_DIRTY) es1 = es1a; else if (vol->vol_flags & VOLUME_MODIFIED_BY_CHKDSK) { es1 = es1b; es2 = es2b; } else { es1 = es1c; ntfs_warning(sb, "Unsupported volume flags 0x%x " "encountered.", (unsigned)le16_to_cpu(vol->vol_flags)); } /* If a read-write mount, convert it to a read-only mount. */ if (!(sb->s_flags & MS_RDONLY)) { if (!(vol->on_errors & (ON_ERRORS_REMOUNT_RO | ON_ERRORS_CONTINUE))) { ntfs_error(sb, "%s and neither on_errors=" "continue nor on_errors=" "remount-ro was specified%s", es1, es2); goto iput_vol_err_out; } sb->s_flags |= MS_RDONLY; ntfs_error(sb, "%s. Mounting read-only%s", es1, es2); } else ntfs_warning(sb, "%s. Will not be able to remount " "read-write%s", es1, es2); /* * Do not set NVolErrors() because ntfs_remount() re-checks the * flags which we need to do in case any flags have changed. */ } /* * Get the inode for the logfile, check it and determine if the volume * was shutdown cleanly. */ rp = NULL; if (!load_and_check_logfile(vol, &rp) || !ntfs_is_logfile_clean(vol->logfile_ino, rp)) { static const char *es1a = "Failed to load $LogFile"; static const char *es1b = "$LogFile is not clean"; static const char *es2 = ". Mount in Windows."; const char *es1; es1 = !vol->logfile_ino ? es1a : es1b; /* If a read-write mount, convert it to a read-only mount. */ if (!(sb->s_flags & MS_RDONLY)) { if (!(vol->on_errors & (ON_ERRORS_REMOUNT_RO | ON_ERRORS_CONTINUE))) { ntfs_error(sb, "%s and neither on_errors=" "continue nor on_errors=" "remount-ro was specified%s", es1, es2); if (vol->logfile_ino) { BUG_ON(!rp); ntfs_free(rp); } goto iput_logfile_err_out; } sb->s_flags |= MS_RDONLY; ntfs_error(sb, "%s. Mounting read-only%s", es1, es2); } else ntfs_warning(sb, "%s. Will not be able to remount " "read-write%s", es1, es2); /* This will prevent a read-write remount. */ NVolSetErrors(vol); } ntfs_free(rp); #endif /* NTFS_RW */ /* Get the root directory inode so we can do path lookups. */ vol->root_ino = ntfs_iget(sb, FILE_root); if (IS_ERR(vol->root_ino) || is_bad_inode(vol->root_ino)) { if (!IS_ERR(vol->root_ino)) iput(vol->root_ino); ntfs_error(sb, "Failed to load root directory."); goto iput_logfile_err_out; } #ifdef NTFS_RW /* * Check if Windows is suspended to disk on the target volume. If it * is hibernated, we must not write *anything* to the disk so set * NVolErrors() without setting the dirty volume flag and mount * read-only. This will prevent read-write remounting and it will also * prevent all writes. */ err = check_windows_hibernation_status(vol); if (unlikely(err)) { static const char *es1a = "Failed to determine if Windows is " "hibernated"; static const char *es1b = "Windows is hibernated"; static const char *es2 = ". Run chkdsk."; const char *es1; es1 = err < 0 ? es1a : es1b; /* If a read-write mount, convert it to a read-only mount. */ if (!(sb->s_flags & MS_RDONLY)) { if (!(vol->on_errors & (ON_ERRORS_REMOUNT_RO | ON_ERRORS_CONTINUE))) { ntfs_error(sb, "%s and neither on_errors=" "continue nor on_errors=" "remount-ro was specified%s", es1, es2); goto iput_root_err_out; } sb->s_flags |= MS_RDONLY; ntfs_error(sb, "%s. Mounting read-only%s", es1, es2); } else ntfs_warning(sb, "%s. Will not be able to remount " "read-write%s", es1, es2); /* This will prevent a read-write remount. */ NVolSetErrors(vol); } /* If (still) a read-write mount, mark the volume dirty. */ if (!(sb->s_flags & MS_RDONLY) && ntfs_set_volume_flags(vol, VOLUME_IS_DIRTY)) { static const char *es1 = "Failed to set dirty bit in volume " "information flags"; static const char *es2 = ". Run chkdsk."; /* Convert to a read-only mount. */ if (!(vol->on_errors & (ON_ERRORS_REMOUNT_RO | ON_ERRORS_CONTINUE))) { ntfs_error(sb, "%s and neither on_errors=continue nor " "on_errors=remount-ro was specified%s", es1, es2); goto iput_root_err_out; } ntfs_error(sb, "%s. Mounting read-only%s", es1, es2); sb->s_flags |= MS_RDONLY; /* * Do not set NVolErrors() because ntfs_remount() might manage * to set the dirty flag in which case all would be well. */ } #if 0 // TODO: Enable this code once we start modifying anything that is // different between NTFS 1.2 and 3.x... /* * If (still) a read-write mount, set the NT4 compatibility flag on * newer NTFS version volumes. */ if (!(sb->s_flags & MS_RDONLY) && (vol->major_ver > 1) && ntfs_set_volume_flags(vol, VOLUME_MOUNTED_ON_NT4)) { static const char *es1 = "Failed to set NT4 compatibility flag"; static const char *es2 = ". Run chkdsk."; /* Convert to a read-only mount. */ if (!(vol->on_errors & (ON_ERRORS_REMOUNT_RO | ON_ERRORS_CONTINUE))) { ntfs_error(sb, "%s and neither on_errors=continue nor " "on_errors=remount-ro was specified%s", es1, es2); goto iput_root_err_out; } ntfs_error(sb, "%s. Mounting read-only%s", es1, es2); sb->s_flags |= MS_RDONLY; NVolSetErrors(vol); } #endif /* If (still) a read-write mount, empty the logfile. */ if (!(sb->s_flags & MS_RDONLY) && !ntfs_empty_logfile(vol->logfile_ino)) { static const char *es1 = "Failed to empty $LogFile"; static const char *es2 = ". Mount in Windows."; /* Convert to a read-only mount. */ if (!(vol->on_errors & (ON_ERRORS_REMOUNT_RO | ON_ERRORS_CONTINUE))) { ntfs_error(sb, "%s and neither on_errors=continue nor " "on_errors=remount-ro was specified%s", es1, es2); goto iput_root_err_out; } ntfs_error(sb, "%s. Mounting read-only%s", es1, es2); sb->s_flags |= MS_RDONLY; NVolSetErrors(vol); } #endif /* NTFS_RW */ /* If on NTFS versions before 3.0, we are done. */ if (unlikely(vol->major_ver < 3)) return true; /* NTFS 3.0+ specific initialization. */ /* Get the security descriptors inode. */ vol->secure_ino = ntfs_iget(sb, FILE_Secure); if (IS_ERR(vol->secure_ino) || is_bad_inode(vol->secure_ino)) { if (!IS_ERR(vol->secure_ino)) iput(vol->secure_ino); ntfs_error(sb, "Failed to load $Secure."); goto iput_root_err_out; } // TODO: Initialize security. /* Get the extended system files' directory inode. */ vol->extend_ino = ntfs_iget(sb, FILE_Extend); if (IS_ERR(vol->extend_ino) || is_bad_inode(vol->extend_ino)) { if (!IS_ERR(vol->extend_ino)) iput(vol->extend_ino); ntfs_error(sb, "Failed to load $Extend."); goto iput_sec_err_out; } #ifdef NTFS_RW /* Find the quota file, load it if present, and set it up. */ if (!load_and_init_quota(vol)) { static const char *es1 = "Failed to load $Quota"; static const char *es2 = ". Run chkdsk."; /* If a read-write mount, convert it to a read-only mount. */ if (!(sb->s_flags & MS_RDONLY)) { if (!(vol->on_errors & (ON_ERRORS_REMOUNT_RO | ON_ERRORS_CONTINUE))) { ntfs_error(sb, "%s and neither on_errors=" "continue nor on_errors=" "remount-ro was specified%s", es1, es2); goto iput_quota_err_out; } sb->s_flags |= MS_RDONLY; ntfs_error(sb, "%s. Mounting read-only%s", es1, es2); } else ntfs_warning(sb, "%s. Will not be able to remount " "read-write%s", es1, es2); /* This will prevent a read-write remount. */ NVolSetErrors(vol); } /* If (still) a read-write mount, mark the quotas out of date. */ if (!(sb->s_flags & MS_RDONLY) && !ntfs_mark_quotas_out_of_date(vol)) { static const char *es1 = "Failed to mark quotas out of date"; static const char *es2 = ". Run chkdsk."; /* Convert to a read-only mount. */ if (!(vol->on_errors & (ON_ERRORS_REMOUNT_RO | ON_ERRORS_CONTINUE))) { ntfs_error(sb, "%s and neither on_errors=continue nor " "on_errors=remount-ro was specified%s", es1, es2); goto iput_quota_err_out; } ntfs_error(sb, "%s. Mounting read-only%s", es1, es2); sb->s_flags |= MS_RDONLY; NVolSetErrors(vol); } /* * Find the transaction log file ($UsnJrnl), load it if present, check * it, and set it up. */ if (!load_and_init_usnjrnl(vol)) { static const char *es1 = "Failed to load $UsnJrnl"; static const char *es2 = ". Run chkdsk."; /* If a read-write mount, convert it to a read-only mount. */ if (!(sb->s_flags & MS_RDONLY)) { if (!(vol->on_errors & (ON_ERRORS_REMOUNT_RO | ON_ERRORS_CONTINUE))) { ntfs_error(sb, "%s and neither on_errors=" "continue nor on_errors=" "remount-ro was specified%s", es1, es2); goto iput_usnjrnl_err_out; } sb->s_flags |= MS_RDONLY; ntfs_error(sb, "%s. Mounting read-only%s", es1, es2); } else ntfs_warning(sb, "%s. Will not be able to remount " "read-write%s", es1, es2); /* This will prevent a read-write remount. */ NVolSetErrors(vol); } /* If (still) a read-write mount, stamp the transaction log. */ if (!(sb->s_flags & MS_RDONLY) && !ntfs_stamp_usnjrnl(vol)) { static const char *es1 = "Failed to stamp transaction log " "($UsnJrnl)"; static const char *es2 = ". Run chkdsk."; /* Convert to a read-only mount. */ if (!(vol->on_errors & (ON_ERRORS_REMOUNT_RO | ON_ERRORS_CONTINUE))) { ntfs_error(sb, "%s and neither on_errors=continue nor " "on_errors=remount-ro was specified%s", es1, es2); goto iput_usnjrnl_err_out; } ntfs_error(sb, "%s. Mounting read-only%s", es1, es2); sb->s_flags |= MS_RDONLY; NVolSetErrors(vol); } #endif /* NTFS_RW */ return true; #ifdef NTFS_RW iput_usnjrnl_err_out: if (vol->usnjrnl_j_ino) iput(vol->usnjrnl_j_ino); if (vol->usnjrnl_max_ino) iput(vol->usnjrnl_max_ino); if (vol->usnjrnl_ino) iput(vol->usnjrnl_ino); iput_quota_err_out: if (vol->quota_q_ino) iput(vol->quota_q_ino); if (vol->quota_ino) iput(vol->quota_ino); iput(vol->extend_ino); #endif /* NTFS_RW */ iput_sec_err_out: iput(vol->secure_ino); iput_root_err_out: iput(vol->root_ino); iput_logfile_err_out: #ifdef NTFS_RW if (vol->logfile_ino) iput(vol->logfile_ino); iput_vol_err_out: #endif /* NTFS_RW */ iput(vol->vol_ino); iput_lcnbmp_err_out: iput(vol->lcnbmp_ino); iput_attrdef_err_out: vol->attrdef_size = 0; if (vol->attrdef) { ntfs_free(vol->attrdef); vol->attrdef = NULL; } #ifdef NTFS_RW iput_upcase_err_out: #endif /* NTFS_RW */ vol->upcase_len = 0; mutex_lock(&ntfs_lock); if (vol->upcase == default_upcase) { ntfs_nr_upcase_users--; vol->upcase = NULL; } mutex_unlock(&ntfs_lock); if (vol->upcase) { ntfs_free(vol->upcase); vol->upcase = NULL; } iput_mftbmp_err_out: iput(vol->mftbmp_ino); iput_mirr_err_out: #ifdef NTFS_RW if (vol->mftmirr_ino) iput(vol->mftmirr_ino); #endif /* NTFS_RW */ return false; } /** * ntfs_put_super - called by the vfs to unmount a volume * @sb: vfs superblock of volume to unmount * * ntfs_put_super() is called by the VFS (from fs/super.c::do_umount()) when * the volume is being unmounted (umount system call has been invoked) and it * releases all inodes and memory belonging to the NTFS specific part of the * super block. */ static void ntfs_put_super(struct super_block *sb) { ntfs_volume *vol = NTFS_SB(sb); ntfs_debug("Entering."); #ifdef NTFS_RW /* * Commit all inodes while they are still open in case some of them * cause others to be dirtied. */ ntfs_commit_inode(vol->vol_ino); /* NTFS 3.0+ specific. */ if (vol->major_ver >= 3) { if (vol->usnjrnl_j_ino) ntfs_commit_inode(vol->usnjrnl_j_ino); if (vol->usnjrnl_max_ino) ntfs_commit_inode(vol->usnjrnl_max_ino); if (vol->usnjrnl_ino) ntfs_commit_inode(vol->usnjrnl_ino); if (vol->quota_q_ino) ntfs_commit_inode(vol->quota_q_ino); if (vol->quota_ino) ntfs_commit_inode(vol->quota_ino); if (vol->extend_ino) ntfs_commit_inode(vol->extend_ino); if (vol->secure_ino) ntfs_commit_inode(vol->secure_ino); } ntfs_commit_inode(vol->root_ino); down_write(&vol->lcnbmp_lock); ntfs_commit_inode(vol->lcnbmp_ino); up_write(&vol->lcnbmp_lock); down_write(&vol->mftbmp_lock); ntfs_commit_inode(vol->mftbmp_ino); up_write(&vol->mftbmp_lock); if (vol->logfile_ino) ntfs_commit_inode(vol->logfile_ino); if (vol->mftmirr_ino) ntfs_commit_inode(vol->mftmirr_ino); ntfs_commit_inode(vol->mft_ino); /* * If a read-write mount and no volume errors have occurred, mark the * volume clean. Also, re-commit all affected inodes. */ if (!(sb->s_flags & MS_RDONLY)) { if (!NVolErrors(vol)) { if (ntfs_clear_volume_flags(vol, VOLUME_IS_DIRTY)) ntfs_warning(sb, "Failed to clear dirty bit " "in volume information " "flags. Run chkdsk."); ntfs_commit_inode(vol->vol_ino); ntfs_commit_inode(vol->root_ino); if (vol->mftmirr_ino) ntfs_commit_inode(vol->mftmirr_ino); ntfs_commit_inode(vol->mft_ino); } else { ntfs_warning(sb, "Volume has errors. Leaving volume " "marked dirty. Run chkdsk."); } } #endif /* NTFS_RW */ iput(vol->vol_ino); vol->vol_ino = NULL; /* NTFS 3.0+ specific clean up. */ if (vol->major_ver >= 3) { #ifdef NTFS_RW if (vol->usnjrnl_j_ino) { iput(vol->usnjrnl_j_ino); vol->usnjrnl_j_ino = NULL; } if (vol->usnjrnl_max_ino) { iput(vol->usnjrnl_max_ino); vol->usnjrnl_max_ino = NULL; } if (vol->usnjrnl_ino) { iput(vol->usnjrnl_ino); vol->usnjrnl_ino = NULL; } if (vol->quota_q_ino) { iput(vol->quota_q_ino); vol->quota_q_ino = NULL; } if (vol->quota_ino) { iput(vol->quota_ino); vol->quota_ino = NULL; } #endif /* NTFS_RW */ if (vol->extend_ino) { iput(vol->extend_ino); vol->extend_ino = NULL; } if (vol->secure_ino) { iput(vol->secure_ino); vol->secure_ino = NULL; } } iput(vol->root_ino); vol->root_ino = NULL; down_write(&vol->lcnbmp_lock); iput(vol->lcnbmp_ino); vol->lcnbmp_ino = NULL; up_write(&vol->lcnbmp_lock); down_write(&vol->mftbmp_lock); iput(vol->mftbmp_ino); vol->mftbmp_ino = NULL; up_write(&vol->mftbmp_lock); #ifdef NTFS_RW if (vol->logfile_ino) { iput(vol->logfile_ino); vol->logfile_ino = NULL; } if (vol->mftmirr_ino) { /* Re-commit the mft mirror and mft just in case. */ ntfs_commit_inode(vol->mftmirr_ino); ntfs_commit_inode(vol->mft_ino); iput(vol->mftmirr_ino); vol->mftmirr_ino = NULL; } /* * We should have no dirty inodes left, due to * mft.c::ntfs_mft_writepage() cleaning all the dirty pages as * the underlying mft records are written out and cleaned. */ ntfs_commit_inode(vol->mft_ino); write_inode_now(vol->mft_ino, 1); #endif /* NTFS_RW */ iput(vol->mft_ino); vol->mft_ino = NULL; /* Throw away the table of attribute definitions. */ vol->attrdef_size = 0; if (vol->attrdef) { ntfs_free(vol->attrdef); vol->attrdef = NULL; } vol->upcase_len = 0; /* * Destroy the global default upcase table if necessary. Also decrease * the number of upcase users if we are a user. */ mutex_lock(&ntfs_lock); if (vol->upcase == default_upcase) { ntfs_nr_upcase_users--; vol->upcase = NULL; } if (!ntfs_nr_upcase_users && default_upcase) { ntfs_free(default_upcase); default_upcase = NULL; } if (vol->cluster_size <= 4096 && !--ntfs_nr_compression_users) free_compression_buffers(); mutex_unlock(&ntfs_lock); if (vol->upcase) { ntfs_free(vol->upcase); vol->upcase = NULL; } unload_nls(vol->nls_map); sb->s_fs_info = NULL; kfree(vol); } /** * get_nr_free_clusters - return the number of free clusters on a volume * @vol: ntfs volume for which to obtain free cluster count * * Calculate the number of free clusters on the mounted NTFS volume @vol. We * actually calculate the number of clusters in use instead because this * allows us to not care about partial pages as these will be just zero filled * and hence not be counted as allocated clusters. * * The only particularity is that clusters beyond the end of the logical ntfs * volume will be marked as allocated to prevent errors which means we have to * discount those at the end. This is important as the cluster bitmap always * has a size in multiples of 8 bytes, i.e. up to 63 clusters could be outside * the logical volume and marked in use when they are not as they do not exist. * * If any pages cannot be read we assume all clusters in the erroring pages are * in use. This means we return an underestimate on errors which is better than * an overestimate. */ static s64 get_nr_free_clusters(ntfs_volume *vol) { s64 nr_free = vol->nr_clusters; struct address_space *mapping = vol->lcnbmp_ino->i_mapping; struct page *page; pgoff_t index, max_index; ntfs_debug("Entering."); /* Serialize accesses to the cluster bitmap. */ down_read(&vol->lcnbmp_lock); /* * Convert the number of bits into bytes rounded up, then convert into * multiples of PAGE_CACHE_SIZE, rounding up so that if we have one * full and one partial page max_index = 2. */ max_index = (((vol->nr_clusters + 7) >> 3) + PAGE_CACHE_SIZE - 1) >> PAGE_CACHE_SHIFT; /* Use multiples of 4 bytes, thus max_size is PAGE_CACHE_SIZE / 4. */ ntfs_debug("Reading $Bitmap, max_index = 0x%lx, max_size = 0x%lx.", max_index, PAGE_CACHE_SIZE / 4); for (index = 0; index < max_index; index++) { unsigned long *kaddr; /* * Read the page from page cache, getting it from backing store * if necessary, and increment the use count. */ page = read_mapping_page(mapping, index, NULL); /* Ignore pages which errored synchronously. */ if (IS_ERR(page)) { ntfs_debug("read_mapping_page() error. Skipping " "page (index 0x%lx).", index); nr_free -= PAGE_CACHE_SIZE * 8; continue; } kaddr = kmap_atomic(page); /* * Subtract the number of set bits. If this * is the last page and it is partial we don't really care as * it just means we do a little extra work but it won't affect * the result as all out of range bytes are set to zero by * ntfs_readpage(). */ nr_free -= bitmap_weight(kaddr, PAGE_CACHE_SIZE * BITS_PER_BYTE); kunmap_atomic(kaddr); page_cache_release(page); } ntfs_debug("Finished reading $Bitmap, last index = 0x%lx.", index - 1); /* * Fixup for eventual bits outside logical ntfs volume (see function * description above). */ if (vol->nr_clusters & 63) nr_free += 64 - (vol->nr_clusters & 63); up_read(&vol->lcnbmp_lock); /* If errors occurred we may well have gone below zero, fix this. */ if (nr_free < 0) nr_free = 0; ntfs_debug("Exiting."); return nr_free; } /** * __get_nr_free_mft_records - return the number of free inodes on a volume * @vol: ntfs volume for which to obtain free inode count * @nr_free: number of mft records in filesystem * @max_index: maximum number of pages containing set bits * * Calculate the number of free mft records (inodes) on the mounted NTFS * volume @vol. We actually calculate the number of mft records in use instead * because this allows us to not care about partial pages as these will be just * zero filled and hence not be counted as allocated mft record. * * If any pages cannot be read we assume all mft records in the erroring pages * are in use. This means we return an underestimate on errors which is better * than an overestimate. * * NOTE: Caller must hold mftbmp_lock rw_semaphore for reading or writing. */ static unsigned long __get_nr_free_mft_records(ntfs_volume *vol, s64 nr_free, const pgoff_t max_index) { struct address_space *mapping = vol->mftbmp_ino->i_mapping; struct page *page; pgoff_t index; ntfs_debug("Entering."); /* Use multiples of 4 bytes, thus max_size is PAGE_CACHE_SIZE / 4. */ ntfs_debug("Reading $MFT/$BITMAP, max_index = 0x%lx, max_size = " "0x%lx.", max_index, PAGE_CACHE_SIZE / 4); for (index = 0; index < max_index; index++) { unsigned long *kaddr; /* * Read the page from page cache, getting it from backing store * if necessary, and increment the use count. */ page = read_mapping_page(mapping, index, NULL); /* Ignore pages which errored synchronously. */ if (IS_ERR(page)) { ntfs_debug("read_mapping_page() error. Skipping " "page (index 0x%lx).", index); nr_free -= PAGE_CACHE_SIZE * 8; continue; } kaddr = kmap_atomic(page); /* * Subtract the number of set bits. If this * is the last page and it is partial we don't really care as * it just means we do a little extra work but it won't affect * the result as all out of range bytes are set to zero by * ntfs_readpage(). */ nr_free -= bitmap_weight(kaddr, PAGE_CACHE_SIZE * BITS_PER_BYTE); kunmap_atomic(kaddr); page_cache_release(page); } ntfs_debug("Finished reading $MFT/$BITMAP, last index = 0x%lx.", index - 1); /* If errors occurred we may well have gone below zero, fix this. */ if (nr_free < 0) nr_free = 0; ntfs_debug("Exiting."); return nr_free; } /** * ntfs_statfs - return information about mounted NTFS volume * @dentry: dentry from mounted volume * @sfs: statfs structure in which to return the information * * Return information about the mounted NTFS volume @dentry in the statfs structure * pointed to by @sfs (this is initialized with zeros before ntfs_statfs is * called). We interpret the values to be correct of the moment in time at * which we are called. Most values are variable otherwise and this isn't just * the free values but the totals as well. For example we can increase the * total number of file nodes if we run out and we can keep doing this until * there is no more space on the volume left at all. * * Called from vfs_statfs which is used to handle the statfs, fstatfs, and * ustat system calls. * * Return 0 on success or -errno on error. */ static int ntfs_statfs(struct dentry *dentry, struct kstatfs *sfs) { struct super_block *sb = dentry->d_sb; s64 size; ntfs_volume *vol = NTFS_SB(sb); ntfs_inode *mft_ni = NTFS_I(vol->mft_ino); pgoff_t max_index; unsigned long flags; ntfs_debug("Entering."); /* Type of filesystem. */ sfs->f_type = NTFS_SB_MAGIC; /* Optimal transfer block size. */ sfs->f_bsize = PAGE_CACHE_SIZE; /* * Total data blocks in filesystem in units of f_bsize and since * inodes are also stored in data blocs ($MFT is a file) this is just * the total clusters. */ sfs->f_blocks = vol->nr_clusters << vol->cluster_size_bits >> PAGE_CACHE_SHIFT; /* Free data blocks in filesystem in units of f_bsize. */ size = get_nr_free_clusters(vol) << vol->cluster_size_bits >> PAGE_CACHE_SHIFT; if (size < 0LL) size = 0LL; /* Free blocks avail to non-superuser, same as above on NTFS. */ sfs->f_bavail = sfs->f_bfree = size; /* Serialize accesses to the inode bitmap. */ down_read(&vol->mftbmp_lock); read_lock_irqsave(&mft_ni->size_lock, flags); size = i_size_read(vol->mft_ino) >> vol->mft_record_size_bits; /* * Convert the maximum number of set bits into bytes rounded up, then * convert into multiples of PAGE_CACHE_SIZE, rounding up so that if we * have one full and one partial page max_index = 2. */ max_index = ((((mft_ni->initialized_size >> vol->mft_record_size_bits) + 7) >> 3) + PAGE_CACHE_SIZE - 1) >> PAGE_CACHE_SHIFT; read_unlock_irqrestore(&mft_ni->size_lock, flags); /* Number of inodes in filesystem (at this point in time). */ sfs->f_files = size; /* Free inodes in fs (based on current total count). */ sfs->f_ffree = __get_nr_free_mft_records(vol, size, max_index); up_read(&vol->mftbmp_lock); /* * File system id. This is extremely *nix flavour dependent and even * within Linux itself all fs do their own thing. I interpret this to * mean a unique id associated with the mounted fs and not the id * associated with the filesystem driver, the latter is already given * by the filesystem type in sfs->f_type. Thus we use the 64-bit * volume serial number splitting it into two 32-bit parts. We enter * the least significant 32-bits in f_fsid[0] and the most significant * 32-bits in f_fsid[1]. */ sfs->f_fsid.val[0] = vol->serial_no & 0xffffffff; sfs->f_fsid.val[1] = (vol->serial_no >> 32) & 0xffffffff; /* Maximum length of filenames. */ sfs->f_namelen = NTFS_MAX_NAME_LEN; return 0; } #ifdef NTFS_RW static int ntfs_write_inode(struct inode *vi, struct writeback_control *wbc) { return __ntfs_write_inode(vi, wbc->sync_mode == WB_SYNC_ALL); } #endif /** * The complete super operations. */ static const struct super_operations ntfs_sops = { .alloc_inode = ntfs_alloc_big_inode, /* VFS: Allocate new inode. */ .destroy_inode = ntfs_destroy_big_inode, /* VFS: Deallocate inode. */ #ifdef NTFS_RW //.dirty_inode = NULL, /* VFS: Called from // __mark_inode_dirty(). */ .write_inode = ntfs_write_inode, /* VFS: Write dirty inode to disk. */ //.drop_inode = NULL, /* VFS: Called just after the // inode reference count has // been decreased to zero. // NOTE: The inode lock is // held. See fs/inode.c:: // generic_drop_inode(). */ //.delete_inode = NULL, /* VFS: Delete inode from disk. // Called when i_count becomes // 0 and i_nlink is also 0. */ //.write_super = NULL, /* Flush dirty super block to // disk. */ //.sync_fs = NULL, /* ? */ //.write_super_lockfs = NULL, /* ? */ //.unlockfs = NULL, /* ? */ #endif /* NTFS_RW */ .put_super = ntfs_put_super, /* Syscall: umount. */ .statfs = ntfs_statfs, /* Syscall: statfs */ .remount_fs = ntfs_remount, /* Syscall: mount -o remount. */ .evict_inode = ntfs_evict_big_inode, /* VFS: Called when an inode is removed from memory. */ //.umount_begin = NULL, /* Forced umount. */ .show_options = ntfs_show_options, /* Show mount options in proc. */ }; /** * ntfs_fill_super - mount an ntfs filesystem * @sb: super block of ntfs filesystem to mount * @opt: string containing the mount options * @silent: silence error output * * ntfs_fill_super() is called by the VFS to mount the device described by @sb * with the mount otions in @data with the NTFS filesystem. * * If @silent is true, remain silent even if errors are detected. This is used * during bootup, when the kernel tries to mount the root filesystem with all * registered filesystems one after the other until one succeeds. This implies * that all filesystems except the correct one will quite correctly and * expectedly return an error, but nobody wants to see error messages when in * fact this is what is supposed to happen. * * NOTE: @sb->s_flags contains the mount options flags. */ static int ntfs_fill_super(struct super_block *sb, void *opt, const int silent) { ntfs_volume *vol; struct buffer_head *bh; struct inode *tmp_ino; int blocksize, result; /* * We do a pretty difficult piece of bootstrap by reading the * MFT (and other metadata) from disk into memory. We'll only * release this metadata during umount, so the locking patterns * observed during bootstrap do not count. So turn off the * observation of locking patterns (strictly for this context * only) while mounting NTFS. [The validator is still active * otherwise, even for this context: it will for example record * lock class registrations.] */ lockdep_off(); ntfs_debug("Entering."); #ifndef NTFS_RW sb->s_flags |= MS_RDONLY; #endif /* ! NTFS_RW */ /* Allocate a new ntfs_volume and place it in sb->s_fs_info. */ sb->s_fs_info = kmalloc(sizeof(ntfs_volume), GFP_NOFS); vol = NTFS_SB(sb); if (!vol) { if (!silent) ntfs_error(sb, "Allocation of NTFS volume structure " "failed. Aborting mount..."); lockdep_on(); return -ENOMEM; } /* Initialize ntfs_volume structure. */ *vol = (ntfs_volume) { .sb = sb, /* * Default is group and other don't have any access to files or * directories while owner has full access. Further, files by * default are not executable but directories are of course * browseable. */ .fmask = 0177, .dmask = 0077, }; init_rwsem(&vol->mftbmp_lock); init_rwsem(&vol->lcnbmp_lock); /* By default, enable sparse support. */ NVolSetSparseEnabled(vol); /* Important to get the mount options dealt with now. */ if (!parse_options(vol, (char*)opt)) goto err_out_now; /* We support sector sizes up to the PAGE_CACHE_SIZE. */ if (bdev_logical_block_size(sb->s_bdev) > PAGE_CACHE_SIZE) { if (!silent) ntfs_error(sb, "Device has unsupported sector size " "(%i). The maximum supported sector " "size on this architecture is %lu " "bytes.", bdev_logical_block_size(sb->s_bdev), PAGE_CACHE_SIZE); goto err_out_now; } /* * Setup the device access block size to NTFS_BLOCK_SIZE or the hard * sector size, whichever is bigger. */ blocksize = sb_min_blocksize(sb, NTFS_BLOCK_SIZE); if (blocksize < NTFS_BLOCK_SIZE) { if (!silent) ntfs_error(sb, "Unable to set device block size."); goto err_out_now; } BUG_ON(blocksize != sb->s_blocksize); ntfs_debug("Set device block size to %i bytes (block size bits %i).", blocksize, sb->s_blocksize_bits); /* Determine the size of the device in units of block_size bytes. */ if (!i_size_read(sb->s_bdev->bd_inode)) { if (!silent) ntfs_error(sb, "Unable to determine device size."); goto err_out_now; } vol->nr_blocks = i_size_read(sb->s_bdev->bd_inode) >> sb->s_blocksize_bits; /* Read the boot sector and return unlocked buffer head to it. */ if (!(bh = read_ntfs_boot_sector(sb, silent))) { if (!silent) ntfs_error(sb, "Not an NTFS volume."); goto err_out_now; } /* * Extract the data from the boot sector and setup the ntfs volume * using it. */ result = parse_ntfs_boot_sector(vol, (NTFS_BOOT_SECTOR*)bh->b_data); brelse(bh); if (!result) { if (!silent) ntfs_error(sb, "Unsupported NTFS filesystem."); goto err_out_now; } /* * If the boot sector indicates a sector size bigger than the current * device block size, switch the device block size to the sector size. * TODO: It may be possible to support this case even when the set * below fails, we would just be breaking up the i/o for each sector * into multiple blocks for i/o purposes but otherwise it should just * work. However it is safer to leave disabled until someone hits this * error message and then we can get them to try it without the setting * so we know for sure that it works. */ if (vol->sector_size > blocksize) { blocksize = sb_set_blocksize(sb, vol->sector_size); if (blocksize != vol->sector_size) { if (!silent) ntfs_error(sb, "Unable to set device block " "size to sector size (%i).", vol->sector_size); goto err_out_now; } BUG_ON(blocksize != sb->s_blocksize); vol->nr_blocks = i_size_read(sb->s_bdev->bd_inode) >> sb->s_blocksize_bits; ntfs_debug("Changed device block size to %i bytes (block size " "bits %i) to match volume sector size.", blocksize, sb->s_blocksize_bits); } /* Initialize the cluster and mft allocators. */ ntfs_setup_allocators(vol); /* Setup remaining fields in the super block. */ sb->s_magic = NTFS_SB_MAGIC; /* * Ntfs allows 63 bits for the file size, i.e. correct would be: * sb->s_maxbytes = ~0ULL >> 1; * But the kernel uses a long as the page cache page index which on * 32-bit architectures is only 32-bits. MAX_LFS_FILESIZE is kernel * defined to the maximum the page cache page index can cope with * without overflowing the index or to 2^63 - 1, whichever is smaller. */ sb->s_maxbytes = MAX_LFS_FILESIZE; /* Ntfs measures time in 100ns intervals. */ sb->s_time_gran = 100; /* * Now load the metadata required for the page cache and our address * space operations to function. We do this by setting up a specialised * read_inode method and then just calling the normal iget() to obtain * the inode for $MFT which is sufficient to allow our normal inode * operations and associated address space operations to function. */ sb->s_op = &ntfs_sops; tmp_ino = new_inode(sb); if (!tmp_ino) { if (!silent) ntfs_error(sb, "Failed to load essential metadata."); goto err_out_now; } tmp_ino->i_ino = FILE_MFT; insert_inode_hash(tmp_ino); if (ntfs_read_inode_mount(tmp_ino) < 0) { if (!silent) ntfs_error(sb, "Failed to load essential metadata."); goto iput_tmp_ino_err_out_now; } mutex_lock(&ntfs_lock); /* * The current mount is a compression user if the cluster size is * less than or equal 4kiB. */ if (vol->cluster_size <= 4096 && !ntfs_nr_compression_users++) { result = allocate_compression_buffers(); if (result) { ntfs_error(NULL, "Failed to allocate buffers " "for compression engine."); ntfs_nr_compression_users--; mutex_unlock(&ntfs_lock); goto iput_tmp_ino_err_out_now; } } /* * Generate the global default upcase table if necessary. Also * temporarily increment the number of upcase users to avoid race * conditions with concurrent (u)mounts. */ if (!default_upcase) default_upcase = generate_default_upcase(); ntfs_nr_upcase_users++; mutex_unlock(&ntfs_lock); /* * From now on, ignore @silent parameter. If we fail below this line, * it will be due to a corrupt fs or a system error, so we report it. */ /* * Open the system files with normal access functions and complete * setting up the ntfs super block. */ if (!load_system_files(vol)) { ntfs_error(sb, "Failed to load system files."); goto unl_upcase_iput_tmp_ino_err_out_now; } /* We grab a reference, simulating an ntfs_iget(). */ ihold(vol->root_ino); if ((sb->s_root = d_make_root(vol->root_ino))) { ntfs_debug("Exiting, status successful."); /* Release the default upcase if it has no users. */ mutex_lock(&ntfs_lock); if (!--ntfs_nr_upcase_users && default_upcase) { ntfs_free(default_upcase); default_upcase = NULL; } mutex_unlock(&ntfs_lock); sb->s_export_op = &ntfs_export_ops; lockdep_on(); return 0; } ntfs_error(sb, "Failed to allocate root directory."); /* Clean up after the successful load_system_files() call from above. */ // TODO: Use ntfs_put_super() instead of repeating all this code... // FIXME: Should mark the volume clean as the error is most likely // -ENOMEM. iput(vol->vol_ino); vol->vol_ino = NULL; /* NTFS 3.0+ specific clean up. */ if (vol->major_ver >= 3) { #ifdef NTFS_RW if (vol->usnjrnl_j_ino) { iput(vol->usnjrnl_j_ino); vol->usnjrnl_j_ino = NULL; } if (vol->usnjrnl_max_ino) { iput(vol->usnjrnl_max_ino); vol->usnjrnl_max_ino = NULL; } if (vol->usnjrnl_ino) { iput(vol->usnjrnl_ino); vol->usnjrnl_ino = NULL; } if (vol->quota_q_ino) { iput(vol->quota_q_ino); vol->quota_q_ino = NULL; } if (vol->quota_ino) { iput(vol->quota_ino); vol->quota_ino = NULL; } #endif /* NTFS_RW */ if (vol->extend_ino) { iput(vol->extend_ino); vol->extend_ino = NULL; } if (vol->secure_ino) { iput(vol->secure_ino); vol->secure_ino = NULL; } } iput(vol->root_ino); vol->root_ino = NULL; iput(vol->lcnbmp_ino); vol->lcnbmp_ino = NULL; iput(vol->mftbmp_ino); vol->mftbmp_ino = NULL; #ifdef NTFS_RW if (vol->logfile_ino) { iput(vol->logfile_ino); vol->logfile_ino = NULL; } if (vol->mftmirr_ino) { iput(vol->mftmirr_ino); vol->mftmirr_ino = NULL; } #endif /* NTFS_RW */ /* Throw away the table of attribute definitions. */ vol->attrdef_size = 0; if (vol->attrdef) { ntfs_free(vol->attrdef); vol->attrdef = NULL; } vol->upcase_len = 0; mutex_lock(&ntfs_lock); if (vol->upcase == default_upcase) { ntfs_nr_upcase_users--; vol->upcase = NULL; } mutex_unlock(&ntfs_lock); if (vol->upcase) { ntfs_free(vol->upcase); vol->upcase = NULL; } if (vol->nls_map) { unload_nls(vol->nls_map); vol->nls_map = NULL; } /* Error exit code path. */ unl_upcase_iput_tmp_ino_err_out_now: /* * Decrease the number of upcase users and destroy the global default * upcase table if necessary. */ mutex_lock(&ntfs_lock); if (!--ntfs_nr_upcase_users && default_upcase) { ntfs_free(default_upcase); default_upcase = NULL; } if (vol->cluster_size <= 4096 && !--ntfs_nr_compression_users) free_compression_buffers(); mutex_unlock(&ntfs_lock); iput_tmp_ino_err_out_now: iput(tmp_ino); if (vol->mft_ino && vol->mft_ino != tmp_ino) iput(vol->mft_ino); vol->mft_ino = NULL; /* Errors at this stage are irrelevant. */ err_out_now: sb->s_fs_info = NULL; kfree(vol); ntfs_debug("Failed, returning -EINVAL."); lockdep_on(); return -EINVAL; } /* * This is a slab cache to optimize allocations and deallocations of Unicode * strings of the maximum length allowed by NTFS, which is NTFS_MAX_NAME_LEN * (255) Unicode characters + a terminating NULL Unicode character. */ struct kmem_cache *ntfs_name_cache; /* Slab caches for efficient allocation/deallocation of inodes. */ struct kmem_cache *ntfs_inode_cache; struct kmem_cache *ntfs_big_inode_cache; /* Init once constructor for the inode slab cache. */ static void ntfs_big_inode_init_once(void *foo) { ntfs_inode *ni = (ntfs_inode *)foo; inode_init_once(VFS_I(ni)); } /* * Slab caches to optimize allocations and deallocations of attribute search * contexts and index contexts, respectively. */ struct kmem_cache *ntfs_attr_ctx_cache; struct kmem_cache *ntfs_index_ctx_cache; /* Driver wide mutex. */ DEFINE_MUTEX(ntfs_lock); static struct dentry *ntfs_mount(struct file_system_type *fs_type, int flags, const char *dev_name, void *data) { return mount_bdev(fs_type, flags, dev_name, data, ntfs_fill_super); } static struct file_system_type ntfs_fs_type = { .owner = THIS_MODULE, .name = "ntfs", .mount = ntfs_mount, .kill_sb = kill_block_super, .fs_flags = FS_REQUIRES_DEV, }; /* Stable names for the slab caches. */ static const char ntfs_index_ctx_cache_name[] = "ntfs_index_ctx_cache"; static const char ntfs_attr_ctx_cache_name[] = "ntfs_attr_ctx_cache"; static const char ntfs_name_cache_name[] = "ntfs_name_cache"; static const char ntfs_inode_cache_name[] = "ntfs_inode_cache"; static const char ntfs_big_inode_cache_name[] = "ntfs_big_inode_cache"; static int __init init_ntfs_fs(void) { int err = 0; /* This may be ugly but it results in pretty output so who cares. (-8 */ printk(KERN_INFO "NTFS driver " NTFS_VERSION " [Flags: R/" #ifdef NTFS_RW "W" #else "O" #endif #ifdef DEBUG " DEBUG" #endif #ifdef MODULE " MODULE" #endif "].\n"); ntfs_debug("Debug messages are enabled."); ntfs_index_ctx_cache = kmem_cache_create(ntfs_index_ctx_cache_name, sizeof(ntfs_index_context), 0 /* offset */, SLAB_HWCACHE_ALIGN, NULL /* ctor */); if (!ntfs_index_ctx_cache) { printk(KERN_CRIT "NTFS: Failed to create %s!\n", ntfs_index_ctx_cache_name); goto ictx_err_out; } ntfs_attr_ctx_cache = kmem_cache_create(ntfs_attr_ctx_cache_name, sizeof(ntfs_attr_search_ctx), 0 /* offset */, SLAB_HWCACHE_ALIGN, NULL /* ctor */); if (!ntfs_attr_ctx_cache) { printk(KERN_CRIT "NTFS: Failed to create %s!\n", ntfs_attr_ctx_cache_name); goto actx_err_out; } ntfs_name_cache = kmem_cache_create(ntfs_name_cache_name, (NTFS_MAX_NAME_LEN+1) * sizeof(ntfschar), 0, SLAB_HWCACHE_ALIGN, NULL); if (!ntfs_name_cache) { printk(KERN_CRIT "NTFS: Failed to create %s!\n", ntfs_name_cache_name); goto name_err_out; } ntfs_inode_cache = kmem_cache_create(ntfs_inode_cache_name, sizeof(ntfs_inode), 0, SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD, NULL); if (!ntfs_inode_cache) { printk(KERN_CRIT "NTFS: Failed to create %s!\n", ntfs_inode_cache_name); goto inode_err_out; } ntfs_big_inode_cache = kmem_cache_create(ntfs_big_inode_cache_name, sizeof(big_ntfs_inode), 0, SLAB_HWCACHE_ALIGN|SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD, ntfs_big_inode_init_once); if (!ntfs_big_inode_cache) { printk(KERN_CRIT "NTFS: Failed to create %s!\n", ntfs_big_inode_cache_name); goto big_inode_err_out; } /* Register the ntfs sysctls. */ err = ntfs_sysctl(1); if (err) { printk(KERN_CRIT "NTFS: Failed to register NTFS sysctls!\n"); goto sysctl_err_out; } err = register_filesystem(&ntfs_fs_type); if (!err) { ntfs_debug("NTFS driver registered successfully."); return 0; /* Success! */ } printk(KERN_CRIT "NTFS: Failed to register NTFS filesystem driver!\n"); /* Unregister the ntfs sysctls. */ ntfs_sysctl(0); sysctl_err_out: kmem_cache_destroy(ntfs_big_inode_cache); big_inode_err_out: kmem_cache_destroy(ntfs_inode_cache); inode_err_out: kmem_cache_destroy(ntfs_name_cache); name_err_out: kmem_cache_destroy(ntfs_attr_ctx_cache); actx_err_out: kmem_cache_destroy(ntfs_index_ctx_cache); ictx_err_out: if (!err) { printk(KERN_CRIT "NTFS: Aborting NTFS filesystem driver " "registration...\n"); err = -ENOMEM; } return err; } static void __exit exit_ntfs_fs(void) { ntfs_debug("Unregistering NTFS driver."); unregister_filesystem(&ntfs_fs_type); kmem_cache_destroy(ntfs_big_inode_cache); kmem_cache_destroy(ntfs_inode_cache); kmem_cache_destroy(ntfs_name_cache); kmem_cache_destroy(ntfs_attr_ctx_cache); kmem_cache_destroy(ntfs_index_ctx_cache); /* Unregister the ntfs sysctls. */ ntfs_sysctl(0); } MODULE_AUTHOR("Anton Altaparmakov <anton@tuxera.com>"); MODULE_DESCRIPTION("NTFS 1.2/3.x driver - Copyright (c) 2001-2011 Anton Altaparmakov and Tuxera Inc."); MODULE_VERSION(NTFS_VERSION); MODULE_LICENSE("GPL"); #ifdef DEBUG module_param(debug_msgs, bint, 0); MODULE_PARM_DESC(debug_msgs, "Enable debug messages."); #endif module_init(init_ntfs_fs) module_exit(exit_ntfs_fs)
gpl-2.0
KainXS/android_kernel_huawei_y301a2
drivers/staging/iio/dac/ad5764.c
4878
9050
/* * Analog devices AD5764, AD5764R, AD5744, AD5744R quad-channel * Digital to Analog Converters driver * * Copyright 2011 Analog Devices Inc. * * Licensed under the GPL-2. */ #include <linux/device.h> #include <linux/err.h> #include <linux/module.h> #include <linux/kernel.h> #include <linux/spi/spi.h> #include <linux/slab.h> #include <linux/sysfs.h> #include <linux/regulator/consumer.h> #include "../iio.h" #include "../sysfs.h" #include "dac.h" #define AD5764_REG_SF_NOP 0x0 #define AD5764_REG_SF_CONFIG 0x1 #define AD5764_REG_SF_CLEAR 0x4 #define AD5764_REG_SF_LOAD 0x5 #define AD5764_REG_DATA(x) ((2 << 3) | (x)) #define AD5764_REG_COARSE_GAIN(x) ((3 << 3) | (x)) #define AD5764_REG_FINE_GAIN(x) ((4 << 3) | (x)) #define AD5764_REG_OFFSET(x) ((5 << 3) | (x)) #define AD5764_NUM_CHANNELS 4 /** * struct ad5764_chip_info - chip specific information * @int_vref: Value of the internal reference voltage in uV - 0 if external * reference voltage is used * @channel channel specification */ struct ad5764_chip_info { unsigned long int_vref; const struct iio_chan_spec *channels; }; /** * struct ad5764_state - driver instance specific data * @spi: spi_device * @chip_info: chip info * @vref_reg: vref supply regulators * @data: spi transfer buffers */ struct ad5764_state { struct spi_device *spi; const struct ad5764_chip_info *chip_info; struct regulator_bulk_data vref_reg[2]; /* * DMA (thus cache coherency maintenance) requires the * transfer buffers to live in their own cache lines. */ union { __be32 d32; u8 d8[4]; } data[2] ____cacheline_aligned; }; enum ad5764_type { ID_AD5744, ID_AD5744R, ID_AD5764, ID_AD5764R, }; #define AD5764_CHANNEL(_chan, _bits) { \ .type = IIO_VOLTAGE, \ .indexed = 1, \ .output = 1, \ .channel = (_chan), \ .address = (_chan), \ .info_mask = IIO_CHAN_INFO_OFFSET_SHARED_BIT | \ IIO_CHAN_INFO_SCALE_SEPARATE_BIT | \ IIO_CHAN_INFO_CALIBSCALE_SEPARATE_BIT | \ IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT, \ .scan_type = IIO_ST('u', (_bits), 16, 16 - (_bits)) \ } #define DECLARE_AD5764_CHANNELS(_name, _bits) \ const struct iio_chan_spec _name##_channels[] = { \ AD5764_CHANNEL(0, (_bits)), \ AD5764_CHANNEL(1, (_bits)), \ AD5764_CHANNEL(2, (_bits)), \ AD5764_CHANNEL(3, (_bits)), \ }; static DECLARE_AD5764_CHANNELS(ad5764, 16); static DECLARE_AD5764_CHANNELS(ad5744, 14); static const struct ad5764_chip_info ad5764_chip_infos[] = { [ID_AD5744] = { .int_vref = 0, .channels = ad5744_channels, }, [ID_AD5744R] = { .int_vref = 5000000, .channels = ad5744_channels, }, [ID_AD5764] = { .int_vref = 0, .channels = ad5764_channels, }, [ID_AD5764R] = { .int_vref = 5000000, .channels = ad5764_channels, }, }; static int ad5764_write(struct iio_dev *indio_dev, unsigned int reg, unsigned int val) { struct ad5764_state *st = iio_priv(indio_dev); int ret; mutex_lock(&indio_dev->mlock); st->data[0].d32 = cpu_to_be32((reg << 16) | val); ret = spi_write(st->spi, &st->data[0].d8[1], 3); mutex_unlock(&indio_dev->mlock); return ret; } static int ad5764_read(struct iio_dev *indio_dev, unsigned int reg, unsigned int *val) { struct ad5764_state *st = iio_priv(indio_dev); struct spi_message m; int ret; struct spi_transfer t[] = { { .tx_buf = &st->data[0].d8[1], .len = 3, .cs_change = 1, }, { .rx_buf = &st->data[1].d8[1], .len = 3, }, }; spi_message_init(&m); spi_message_add_tail(&t[0], &m); spi_message_add_tail(&t[1], &m); mutex_lock(&indio_dev->mlock); st->data[0].d32 = cpu_to_be32((1 << 23) | (reg << 16)); ret = spi_sync(st->spi, &m); if (ret >= 0) *val = be32_to_cpu(st->data[1].d32) & 0xffff; mutex_unlock(&indio_dev->mlock); return ret; } static int ad5764_chan_info_to_reg(struct iio_chan_spec const *chan, long info) { switch (info) { case 0: return AD5764_REG_DATA(chan->address); case IIO_CHAN_INFO_CALIBBIAS: return AD5764_REG_OFFSET(chan->address); case IIO_CHAN_INFO_CALIBSCALE: return AD5764_REG_FINE_GAIN(chan->address); default: break; } return 0; } static int ad5764_write_raw(struct iio_dev *indio_dev, struct iio_chan_spec const *chan, int val, int val2, long info) { const int max_val = (1 << chan->scan_type.realbits); unsigned int reg; switch (info) { case 0: if (val >= max_val || val < 0) return -EINVAL; val <<= chan->scan_type.shift; break; case IIO_CHAN_INFO_CALIBBIAS: if (val >= 128 || val < -128) return -EINVAL; break; case IIO_CHAN_INFO_CALIBSCALE: if (val >= 32 || val < -32) return -EINVAL; break; default: return -EINVAL; } reg = ad5764_chan_info_to_reg(chan, info); return ad5764_write(indio_dev, reg, (u16)val); } static int ad5764_get_channel_vref(struct ad5764_state *st, unsigned int channel) { if (st->chip_info->int_vref) return st->chip_info->int_vref; else return regulator_get_voltage(st->vref_reg[channel / 2].consumer); } static int ad5764_read_raw(struct iio_dev *indio_dev, struct iio_chan_spec const *chan, int *val, int *val2, long info) { struct ad5764_state *st = iio_priv(indio_dev); unsigned long scale_uv; unsigned int reg; int vref; int ret; switch (info) { case 0: reg = AD5764_REG_DATA(chan->address); ret = ad5764_read(indio_dev, reg, val); if (ret < 0) return ret; *val >>= chan->scan_type.shift; return IIO_VAL_INT; case IIO_CHAN_INFO_CALIBBIAS: reg = AD5764_REG_OFFSET(chan->address); ret = ad5764_read(indio_dev, reg, val); if (ret < 0) return ret; *val = sign_extend32(*val, 7); return IIO_VAL_INT; case IIO_CHAN_INFO_CALIBSCALE: reg = AD5764_REG_FINE_GAIN(chan->address); ret = ad5764_read(indio_dev, reg, val); if (ret < 0) return ret; *val = sign_extend32(*val, 5); return IIO_VAL_INT; case IIO_CHAN_INFO_SCALE: /* vout = 4 * vref + ((dac_code / 65535) - 0.5) */ vref = ad5764_get_channel_vref(st, chan->channel); if (vref < 0) return vref; scale_uv = (vref * 4 * 100) >> chan->scan_type.realbits; *val = scale_uv / 100000; *val2 = (scale_uv % 100000) * 10; return IIO_VAL_INT_PLUS_MICRO; case IIO_CHAN_INFO_OFFSET: *val = -(1 << chan->scan_type.realbits) / 2; return IIO_VAL_INT; } return -EINVAL; } static const struct iio_info ad5764_info = { .read_raw = ad5764_read_raw, .write_raw = ad5764_write_raw, .driver_module = THIS_MODULE, }; static int __devinit ad5764_probe(struct spi_device *spi) { enum ad5764_type type = spi_get_device_id(spi)->driver_data; struct iio_dev *indio_dev; struct ad5764_state *st; int ret; indio_dev = iio_allocate_device(sizeof(*st)); if (indio_dev == NULL) { dev_err(&spi->dev, "Failed to allocate iio device\n"); return -ENOMEM; } st = iio_priv(indio_dev); spi_set_drvdata(spi, indio_dev); st->spi = spi; st->chip_info = &ad5764_chip_infos[type]; indio_dev->dev.parent = &spi->dev; indio_dev->name = spi_get_device_id(spi)->name; indio_dev->info = &ad5764_info; indio_dev->modes = INDIO_DIRECT_MODE; indio_dev->num_channels = AD5764_NUM_CHANNELS; indio_dev->channels = st->chip_info->channels; if (st->chip_info->int_vref == 0) { st->vref_reg[0].supply = "vrefAB"; st->vref_reg[1].supply = "vrefCD"; ret = regulator_bulk_get(&st->spi->dev, ARRAY_SIZE(st->vref_reg), st->vref_reg); if (ret) { dev_err(&spi->dev, "Failed to request vref regulators: %d\n", ret); goto error_free; } ret = regulator_bulk_enable(ARRAY_SIZE(st->vref_reg), st->vref_reg); if (ret) { dev_err(&spi->dev, "Failed to enable vref regulators: %d\n", ret); goto error_free_reg; } } ret = iio_device_register(indio_dev); if (ret) { dev_err(&spi->dev, "Failed to register iio device: %d\n", ret); goto error_disable_reg; } return 0; error_disable_reg: if (st->chip_info->int_vref == 0) regulator_bulk_disable(ARRAY_SIZE(st->vref_reg), st->vref_reg); error_free_reg: if (st->chip_info->int_vref == 0) regulator_bulk_free(ARRAY_SIZE(st->vref_reg), st->vref_reg); error_free: iio_free_device(indio_dev); return ret; } static int __devexit ad5764_remove(struct spi_device *spi) { struct iio_dev *indio_dev = spi_get_drvdata(spi); struct ad5764_state *st = iio_priv(indio_dev); iio_device_unregister(indio_dev); if (st->chip_info->int_vref == 0) { regulator_bulk_disable(ARRAY_SIZE(st->vref_reg), st->vref_reg); regulator_bulk_free(ARRAY_SIZE(st->vref_reg), st->vref_reg); } iio_free_device(indio_dev); return 0; } static const struct spi_device_id ad5764_ids[] = { { "ad5744", ID_AD5744 }, { "ad5744r", ID_AD5744R }, { "ad5764", ID_AD5764 }, { "ad5764r", ID_AD5764R }, { } }; MODULE_DEVICE_TABLE(spi, ad5764_ids); static struct spi_driver ad5764_driver = { .driver = { .name = "ad5764", .owner = THIS_MODULE, }, .probe = ad5764_probe, .remove = __devexit_p(ad5764_remove), .id_table = ad5764_ids, }; module_spi_driver(ad5764_driver); MODULE_AUTHOR("Lars-Peter Clausen <lars@metafoo.de>"); MODULE_DESCRIPTION("Analog Devices AD5744/AD5744R/AD5764/AD5764R DAC"); MODULE_LICENSE("GPL v2");
gpl-2.0
Evervolv/android_kernel_oppo_apq8064
drivers/scsi/aic7xxx/aic7xxx_osm.c
5134
73156
/* * Adaptec AIC7xxx device driver for Linux. * * $Id: //depot/aic7xxx/linux/drivers/scsi/aic7xxx/aic7xxx_osm.c#235 $ * * Copyright (c) 1994 John Aycock * The University of Calgary Department of Computer Science. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2, or (at your option) * any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; see the file COPYING. If not, write to * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. * * Sources include the Adaptec 1740 driver (aha1740.c), the Ultrastor 24F * driver (ultrastor.c), various Linux kernel source, the Adaptec EISA * config file (!adp7771.cfg), the Adaptec AHA-2740A Series User's Guide, * the Linux Kernel Hacker's Guide, Writing a SCSI Device Driver for Linux, * the Adaptec 1542 driver (aha1542.c), the Adaptec EISA overlay file * (adp7770.ovl), the Adaptec AHA-2740 Series Technical Reference Manual, * the Adaptec AIC-7770 Data Book, the ANSI SCSI specification, the * ANSI SCSI-2 specification (draft 10c), ... * * -------------------------------------------------------------------------- * * Modifications by Daniel M. Eischen (deischen@iworks.InterWorks.org): * * Substantially modified to include support for wide and twin bus * adapters, DMAing of SCBs, tagged queueing, IRQ sharing, bug fixes, * SCB paging, and other rework of the code. * * -------------------------------------------------------------------------- * Copyright (c) 1994-2000 Justin T. Gibbs. * Copyright (c) 2000-2001 Adaptec Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions, and the following disclaimer, * without modification. * 2. Redistributions in binary form must reproduce at minimum a disclaimer * substantially similar to the "NO WARRANTY" disclaimer below * ("Disclaimer") and any redistribution must be conditioned upon * including a substantially similar Disclaimer requirement for further * binary redistribution. * 3. Neither the names of the above-listed copyright holders nor the names * of any contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * Alternatively, this software may be distributed under the terms of the * GNU General Public License ("GPL") version 2 as published by the Free * Software Foundation. * * NO WARRANTY * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGES. * *--------------------------------------------------------------------------- * * Thanks also go to (in alphabetical order) the following: * * Rory Bolt - Sequencer bug fixes * Jay Estabrook - Initial DEC Alpha support * Doug Ledford - Much needed abort/reset bug fixes * Kai Makisara - DMAing of SCBs * * A Boot time option was also added for not resetting the scsi bus. * * Form: aic7xxx=extended * aic7xxx=no_reset * aic7xxx=verbose * * Daniel M. Eischen, deischen@iworks.InterWorks.org, 1/23/97 * * Id: aic7xxx.c,v 4.1 1997/06/12 08:23:42 deang Exp */ /* * Further driver modifications made by Doug Ledford <dledford@redhat.com> * * Copyright (c) 1997-1999 Doug Ledford * * These changes are released under the same licensing terms as the FreeBSD * driver written by Justin Gibbs. Please see his Copyright notice above * for the exact terms and conditions covering my changes as well as the * warranty statement. * * Modifications made to the aic7xxx.c,v 4.1 driver from Dan Eischen include * but are not limited to: * * 1: Import of the latest FreeBSD sequencer code for this driver * 2: Modification of kernel code to accommodate different sequencer semantics * 3: Extensive changes throughout kernel portion of driver to improve * abort/reset processing and error hanndling * 4: Other work contributed by various people on the Internet * 5: Changes to printk information and verbosity selection code * 6: General reliability related changes, especially in IRQ management * 7: Modifications to the default probe/attach order for supported cards * 8: SMP friendliness has been improved * */ #include "aic7xxx_osm.h" #include "aic7xxx_inline.h" #include <scsi/scsicam.h> static struct scsi_transport_template *ahc_linux_transport_template = NULL; #include <linux/init.h> /* __setup */ #include <linux/mm.h> /* For fetching system memory size */ #include <linux/blkdev.h> /* For block_size() */ #include <linux/delay.h> /* For ssleep/msleep */ #include <linux/slab.h> /* * Set this to the delay in seconds after SCSI bus reset. * Note, we honor this only for the initial bus reset. * The scsi error recovery code performs its own bus settle * delay handling for error recovery actions. */ #ifdef CONFIG_AIC7XXX_RESET_DELAY_MS #define AIC7XXX_RESET_DELAY CONFIG_AIC7XXX_RESET_DELAY_MS #else #define AIC7XXX_RESET_DELAY 5000 #endif /* * Control collection of SCSI transfer statistics for the /proc filesystem. * * NOTE: Do NOT enable this when running on kernels version 1.2.x and below. * NOTE: This does affect performance since it has to maintain statistics. */ #ifdef CONFIG_AIC7XXX_PROC_STATS #define AIC7XXX_PROC_STATS #endif /* * To change the default number of tagged transactions allowed per-device, * add a line to the lilo.conf file like: * append="aic7xxx=verbose,tag_info:{{32,32,32,32},{32,32,32,32}}" * which will result in the first four devices on the first two * controllers being set to a tagged queue depth of 32. * * The tag_commands is an array of 16 to allow for wide and twin adapters. * Twin adapters will use indexes 0-7 for channel 0, and indexes 8-15 * for channel 1. */ typedef struct { uint8_t tag_commands[16]; /* Allow for wide/twin adapters. */ } adapter_tag_info_t; /* * Modify this as you see fit for your system. * * 0 tagged queuing disabled * 1 <= n <= 253 n == max tags ever dispatched. * * The driver will throttle the number of commands dispatched to a * device if it returns queue full. For devices with a fixed maximum * queue depth, the driver will eventually determine this depth and * lock it in (a console message is printed to indicate that a lock * has occurred). On some devices, queue full is returned for a temporary * resource shortage. These devices will return queue full at varying * depths. The driver will throttle back when the queue fulls occur and * attempt to slowly increase the depth over time as the device recovers * from the resource shortage. * * In this example, the first line will disable tagged queueing for all * the devices on the first probed aic7xxx adapter. * * The second line enables tagged queueing with 4 commands/LUN for IDs * (0, 2-11, 13-15), disables tagged queueing for ID 12, and tells the * driver to attempt to use up to 64 tags for ID 1. * * The third line is the same as the first line. * * The fourth line disables tagged queueing for devices 0 and 3. It * enables tagged queueing for the other IDs, with 16 commands/LUN * for IDs 1 and 4, 127 commands/LUN for ID 8, and 4 commands/LUN for * IDs 2, 5-7, and 9-15. */ /* * NOTE: The below structure is for reference only, the actual structure * to modify in order to change things is just below this comment block. adapter_tag_info_t aic7xxx_tag_info[] = { {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}}, {{4, 64, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 0, 4, 4, 4}}, {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}}, {{0, 16, 4, 0, 16, 4, 4, 4, 127, 4, 4, 4, 4, 4, 4, 4}} }; */ #ifdef CONFIG_AIC7XXX_CMDS_PER_DEVICE #define AIC7XXX_CMDS_PER_DEVICE CONFIG_AIC7XXX_CMDS_PER_DEVICE #else #define AIC7XXX_CMDS_PER_DEVICE AHC_MAX_QUEUE #endif #define AIC7XXX_CONFIGED_TAG_COMMANDS { \ AIC7XXX_CMDS_PER_DEVICE, AIC7XXX_CMDS_PER_DEVICE, \ AIC7XXX_CMDS_PER_DEVICE, AIC7XXX_CMDS_PER_DEVICE, \ AIC7XXX_CMDS_PER_DEVICE, AIC7XXX_CMDS_PER_DEVICE, \ AIC7XXX_CMDS_PER_DEVICE, AIC7XXX_CMDS_PER_DEVICE, \ AIC7XXX_CMDS_PER_DEVICE, AIC7XXX_CMDS_PER_DEVICE, \ AIC7XXX_CMDS_PER_DEVICE, AIC7XXX_CMDS_PER_DEVICE, \ AIC7XXX_CMDS_PER_DEVICE, AIC7XXX_CMDS_PER_DEVICE, \ AIC7XXX_CMDS_PER_DEVICE, AIC7XXX_CMDS_PER_DEVICE \ } /* * By default, use the number of commands specified by * the users kernel configuration. */ static adapter_tag_info_t aic7xxx_tag_info[] = { {AIC7XXX_CONFIGED_TAG_COMMANDS}, {AIC7XXX_CONFIGED_TAG_COMMANDS}, {AIC7XXX_CONFIGED_TAG_COMMANDS}, {AIC7XXX_CONFIGED_TAG_COMMANDS}, {AIC7XXX_CONFIGED_TAG_COMMANDS}, {AIC7XXX_CONFIGED_TAG_COMMANDS}, {AIC7XXX_CONFIGED_TAG_COMMANDS}, {AIC7XXX_CONFIGED_TAG_COMMANDS}, {AIC7XXX_CONFIGED_TAG_COMMANDS}, {AIC7XXX_CONFIGED_TAG_COMMANDS}, {AIC7XXX_CONFIGED_TAG_COMMANDS}, {AIC7XXX_CONFIGED_TAG_COMMANDS}, {AIC7XXX_CONFIGED_TAG_COMMANDS}, {AIC7XXX_CONFIGED_TAG_COMMANDS}, {AIC7XXX_CONFIGED_TAG_COMMANDS}, {AIC7XXX_CONFIGED_TAG_COMMANDS} }; /* * There should be a specific return value for this in scsi.h, but * it seems that most drivers ignore it. */ #define DID_UNDERFLOW DID_ERROR void ahc_print_path(struct ahc_softc *ahc, struct scb *scb) { printk("(scsi%d:%c:%d:%d): ", ahc->platform_data->host->host_no, scb != NULL ? SCB_GET_CHANNEL(ahc, scb) : 'X', scb != NULL ? SCB_GET_TARGET(ahc, scb) : -1, scb != NULL ? SCB_GET_LUN(scb) : -1); } /* * XXX - these options apply unilaterally to _all_ 274x/284x/294x * cards in the system. This should be fixed. Exceptions to this * rule are noted in the comments. */ /* * Skip the scsi bus reset. Non 0 make us skip the reset at startup. This * has no effect on any later resets that might occur due to things like * SCSI bus timeouts. */ static uint32_t aic7xxx_no_reset; /* * Should we force EXTENDED translation on a controller. * 0 == Use whatever is in the SEEPROM or default to off * 1 == Use whatever is in the SEEPROM or default to on */ static uint32_t aic7xxx_extended; /* * PCI bus parity checking of the Adaptec controllers. This is somewhat * dubious at best. To my knowledge, this option has never actually * solved a PCI parity problem, but on certain machines with broken PCI * chipset configurations where stray PCI transactions with bad parity are * the norm rather than the exception, the error messages can be overwhelming. * It's included in the driver for completeness. * 0 = Shut off PCI parity check * non-0 = reverse polarity pci parity checking */ static uint32_t aic7xxx_pci_parity = ~0; /* * There are lots of broken chipsets in the world. Some of them will * violate the PCI spec when we issue byte sized memory writes to our * controller. I/O mapped register access, if allowed by the given * platform, will work in almost all cases. */ uint32_t aic7xxx_allow_memio = ~0; /* * So that we can set how long each device is given as a selection timeout. * The table of values goes like this: * 0 - 256ms * 1 - 128ms * 2 - 64ms * 3 - 32ms * We default to 256ms because some older devices need a longer time * to respond to initial selection. */ static uint32_t aic7xxx_seltime; /* * Certain devices do not perform any aging on commands. Should the * device be saturated by commands in one portion of the disk, it is * possible for transactions on far away sectors to never be serviced. * To handle these devices, we can periodically send an ordered tag to * force all outstanding transactions to be serviced prior to a new * transaction. */ static uint32_t aic7xxx_periodic_otag; /* * Module information and settable options. */ static char *aic7xxx = NULL; MODULE_AUTHOR("Maintainer: Hannes Reinecke <hare@suse.de>"); MODULE_DESCRIPTION("Adaptec AIC77XX/78XX SCSI Host Bus Adapter driver"); MODULE_LICENSE("Dual BSD/GPL"); MODULE_VERSION(AIC7XXX_DRIVER_VERSION); module_param(aic7xxx, charp, 0444); MODULE_PARM_DESC(aic7xxx, "period-delimited options string:\n" " verbose Enable verbose/diagnostic logging\n" " allow_memio Allow device registers to be memory mapped\n" " debug Bitmask of debug values to enable\n" " no_probe Toggle EISA/VLB controller probing\n" " probe_eisa_vl Toggle EISA/VLB controller probing\n" " no_reset Suppress initial bus resets\n" " extended Enable extended geometry on all controllers\n" " periodic_otag Send an ordered tagged transaction\n" " periodically to prevent tag starvation.\n" " This may be required by some older disk\n" " drives or RAID arrays.\n" " tag_info:<tag_str> Set per-target tag depth\n" " global_tag_depth:<int> Global tag depth for every target\n" " on every bus\n" " seltime:<int> Selection Timeout\n" " (0/256ms,1/128ms,2/64ms,3/32ms)\n" "\n" " Sample modprobe configuration file:\n" " # Toggle EISA/VLB probing\n" " # Set tag depth on Controller 1/Target 1 to 10 tags\n" " # Shorten the selection timeout to 128ms\n" "\n" " options aic7xxx 'aic7xxx=probe_eisa_vl.tag_info:{{}.{.10}}.seltime:1'\n" ); static void ahc_linux_handle_scsi_status(struct ahc_softc *, struct scsi_device *, struct scb *); static void ahc_linux_queue_cmd_complete(struct ahc_softc *ahc, struct scsi_cmnd *cmd); static void ahc_linux_freeze_simq(struct ahc_softc *ahc); static void ahc_linux_release_simq(struct ahc_softc *ahc); static int ahc_linux_queue_recovery_cmd(struct scsi_cmnd *cmd, scb_flag flag); static void ahc_linux_initialize_scsi_bus(struct ahc_softc *ahc); static u_int ahc_linux_user_tagdepth(struct ahc_softc *ahc, struct ahc_devinfo *devinfo); static void ahc_linux_device_queue_depth(struct scsi_device *); static int ahc_linux_run_command(struct ahc_softc*, struct ahc_linux_device *, struct scsi_cmnd *); static void ahc_linux_setup_tag_info_global(char *p); static int aic7xxx_setup(char *s); static int ahc_linux_unit; /************************** OS Utility Wrappers *******************************/ void ahc_delay(long usec) { /* * udelay on Linux can have problems for * multi-millisecond waits. Wait at most * 1024us per call. */ while (usec > 0) { udelay(usec % 1024); usec -= 1024; } } /***************************** Low Level I/O **********************************/ uint8_t ahc_inb(struct ahc_softc * ahc, long port) { uint8_t x; if (ahc->tag == BUS_SPACE_MEMIO) { x = readb(ahc->bsh.maddr + port); } else { x = inb(ahc->bsh.ioport + port); } mb(); return (x); } void ahc_outb(struct ahc_softc * ahc, long port, uint8_t val) { if (ahc->tag == BUS_SPACE_MEMIO) { writeb(val, ahc->bsh.maddr + port); } else { outb(val, ahc->bsh.ioport + port); } mb(); } void ahc_outsb(struct ahc_softc * ahc, long port, uint8_t *array, int count) { int i; /* * There is probably a more efficient way to do this on Linux * but we don't use this for anything speed critical and this * should work. */ for (i = 0; i < count; i++) ahc_outb(ahc, port, *array++); } void ahc_insb(struct ahc_softc * ahc, long port, uint8_t *array, int count) { int i; /* * There is probably a more efficient way to do this on Linux * but we don't use this for anything speed critical and this * should work. */ for (i = 0; i < count; i++) *array++ = ahc_inb(ahc, port); } /********************************* Inlines ************************************/ static void ahc_linux_unmap_scb(struct ahc_softc*, struct scb*); static int ahc_linux_map_seg(struct ahc_softc *ahc, struct scb *scb, struct ahc_dma_seg *sg, dma_addr_t addr, bus_size_t len); static void ahc_linux_unmap_scb(struct ahc_softc *ahc, struct scb *scb) { struct scsi_cmnd *cmd; cmd = scb->io_ctx; ahc_sync_sglist(ahc, scb, BUS_DMASYNC_POSTWRITE); scsi_dma_unmap(cmd); } static int ahc_linux_map_seg(struct ahc_softc *ahc, struct scb *scb, struct ahc_dma_seg *sg, dma_addr_t addr, bus_size_t len) { int consumed; if ((scb->sg_count + 1) > AHC_NSEG) panic("Too few segs for dma mapping. " "Increase AHC_NSEG\n"); consumed = 1; sg->addr = ahc_htole32(addr & 0xFFFFFFFF); scb->platform_data->xfer_len += len; if (sizeof(dma_addr_t) > 4 && (ahc->flags & AHC_39BIT_ADDRESSING) != 0) len |= (addr >> 8) & AHC_SG_HIGH_ADDR_MASK; sg->len = ahc_htole32(len); return (consumed); } /* * Return a string describing the driver. */ static const char * ahc_linux_info(struct Scsi_Host *host) { static char buffer[512]; char ahc_info[256]; char *bp; struct ahc_softc *ahc; bp = &buffer[0]; ahc = *(struct ahc_softc **)host->hostdata; memset(bp, 0, sizeof(buffer)); strcpy(bp, "Adaptec AIC7XXX EISA/VLB/PCI SCSI HBA DRIVER, Rev " AIC7XXX_DRIVER_VERSION "\n" " <"); strcat(bp, ahc->description); strcat(bp, ">\n" " "); ahc_controller_info(ahc, ahc_info); strcat(bp, ahc_info); strcat(bp, "\n"); return (bp); } /* * Queue an SCB to the controller. */ static int ahc_linux_queue_lck(struct scsi_cmnd * cmd, void (*scsi_done) (struct scsi_cmnd *)) { struct ahc_softc *ahc; struct ahc_linux_device *dev = scsi_transport_device_data(cmd->device); int rtn = SCSI_MLQUEUE_HOST_BUSY; unsigned long flags; ahc = *(struct ahc_softc **)cmd->device->host->hostdata; ahc_lock(ahc, &flags); if (ahc->platform_data->qfrozen == 0) { cmd->scsi_done = scsi_done; cmd->result = CAM_REQ_INPROG << 16; rtn = ahc_linux_run_command(ahc, dev, cmd); } ahc_unlock(ahc, &flags); return rtn; } static DEF_SCSI_QCMD(ahc_linux_queue) static inline struct scsi_target ** ahc_linux_target_in_softc(struct scsi_target *starget) { struct ahc_softc *ahc = *((struct ahc_softc **)dev_to_shost(&starget->dev)->hostdata); unsigned int target_offset; target_offset = starget->id; if (starget->channel != 0) target_offset += 8; return &ahc->platform_data->starget[target_offset]; } static int ahc_linux_target_alloc(struct scsi_target *starget) { struct ahc_softc *ahc = *((struct ahc_softc **)dev_to_shost(&starget->dev)->hostdata); struct seeprom_config *sc = ahc->seep_config; unsigned long flags; struct scsi_target **ahc_targp = ahc_linux_target_in_softc(starget); unsigned short scsirate; struct ahc_devinfo devinfo; struct ahc_initiator_tinfo *tinfo; struct ahc_tmode_tstate *tstate; char channel = starget->channel + 'A'; unsigned int our_id = ahc->our_id; unsigned int target_offset; target_offset = starget->id; if (starget->channel != 0) target_offset += 8; if (starget->channel) our_id = ahc->our_id_b; ahc_lock(ahc, &flags); BUG_ON(*ahc_targp != NULL); *ahc_targp = starget; if (sc) { int maxsync = AHC_SYNCRATE_DT; int ultra = 0; int flags = sc->device_flags[target_offset]; if (ahc->flags & AHC_NEWEEPROM_FMT) { if (flags & CFSYNCHISULTRA) ultra = 1; } else if (flags & CFULTRAEN) ultra = 1; /* AIC nutcase; 10MHz appears as ultra = 1, CFXFER = 0x04 * change it to ultra=0, CFXFER = 0 */ if(ultra && (flags & CFXFER) == 0x04) { ultra = 0; flags &= ~CFXFER; } if ((ahc->features & AHC_ULTRA2) != 0) { scsirate = (flags & CFXFER) | (ultra ? 0x8 : 0); } else { scsirate = (flags & CFXFER) << 4; maxsync = ultra ? AHC_SYNCRATE_ULTRA : AHC_SYNCRATE_FAST; } spi_max_width(starget) = (flags & CFWIDEB) ? 1 : 0; if (!(flags & CFSYNCH)) spi_max_offset(starget) = 0; spi_min_period(starget) = ahc_find_period(ahc, scsirate, maxsync); tinfo = ahc_fetch_transinfo(ahc, channel, ahc->our_id, starget->id, &tstate); } ahc_compile_devinfo(&devinfo, our_id, starget->id, CAM_LUN_WILDCARD, channel, ROLE_INITIATOR); ahc_set_syncrate(ahc, &devinfo, NULL, 0, 0, 0, AHC_TRANS_GOAL, /*paused*/FALSE); ahc_set_width(ahc, &devinfo, MSG_EXT_WDTR_BUS_8_BIT, AHC_TRANS_GOAL, /*paused*/FALSE); ahc_unlock(ahc, &flags); return 0; } static void ahc_linux_target_destroy(struct scsi_target *starget) { struct scsi_target **ahc_targp = ahc_linux_target_in_softc(starget); *ahc_targp = NULL; } static int ahc_linux_slave_alloc(struct scsi_device *sdev) { struct ahc_softc *ahc = *((struct ahc_softc **)sdev->host->hostdata); struct scsi_target *starget = sdev->sdev_target; struct ahc_linux_device *dev; if (bootverbose) printk("%s: Slave Alloc %d\n", ahc_name(ahc), sdev->id); dev = scsi_transport_device_data(sdev); memset(dev, 0, sizeof(*dev)); /* * We start out life using untagged * transactions of which we allow one. */ dev->openings = 1; /* * Set maxtags to 0. This will be changed if we * later determine that we are dealing with * a tagged queuing capable device. */ dev->maxtags = 0; spi_period(starget) = 0; return 0; } static int ahc_linux_slave_configure(struct scsi_device *sdev) { struct ahc_softc *ahc; ahc = *((struct ahc_softc **)sdev->host->hostdata); if (bootverbose) sdev_printk(KERN_INFO, sdev, "Slave Configure\n"); ahc_linux_device_queue_depth(sdev); /* Initial Domain Validation */ if (!spi_initial_dv(sdev->sdev_target)) spi_dv_device(sdev); return 0; } #if defined(__i386__) /* * Return the disk geometry for the given SCSI device. */ static int ahc_linux_biosparam(struct scsi_device *sdev, struct block_device *bdev, sector_t capacity, int geom[]) { uint8_t *bh; int heads; int sectors; int cylinders; int ret; int extended; struct ahc_softc *ahc; u_int channel; ahc = *((struct ahc_softc **)sdev->host->hostdata); channel = sdev_channel(sdev); bh = scsi_bios_ptable(bdev); if (bh) { ret = scsi_partsize(bh, capacity, &geom[2], &geom[0], &geom[1]); kfree(bh); if (ret != -1) return (ret); } heads = 64; sectors = 32; cylinders = aic_sector_div(capacity, heads, sectors); if (aic7xxx_extended != 0) extended = 1; else if (channel == 0) extended = (ahc->flags & AHC_EXTENDED_TRANS_A) != 0; else extended = (ahc->flags & AHC_EXTENDED_TRANS_B) != 0; if (extended && cylinders >= 1024) { heads = 255; sectors = 63; cylinders = aic_sector_div(capacity, heads, sectors); } geom[0] = heads; geom[1] = sectors; geom[2] = cylinders; return (0); } #endif /* * Abort the current SCSI command(s). */ static int ahc_linux_abort(struct scsi_cmnd *cmd) { int error; error = ahc_linux_queue_recovery_cmd(cmd, SCB_ABORT); if (error != 0) printk("aic7xxx_abort returns 0x%x\n", error); return (error); } /* * Attempt to send a target reset message to the device that timed out. */ static int ahc_linux_dev_reset(struct scsi_cmnd *cmd) { int error; error = ahc_linux_queue_recovery_cmd(cmd, SCB_DEVICE_RESET); if (error != 0) printk("aic7xxx_dev_reset returns 0x%x\n", error); return (error); } /* * Reset the SCSI bus. */ static int ahc_linux_bus_reset(struct scsi_cmnd *cmd) { struct ahc_softc *ahc; int found; unsigned long flags; ahc = *(struct ahc_softc **)cmd->device->host->hostdata; ahc_lock(ahc, &flags); found = ahc_reset_channel(ahc, scmd_channel(cmd) + 'A', /*initiate reset*/TRUE); ahc_unlock(ahc, &flags); if (bootverbose) printk("%s: SCSI bus reset delivered. " "%d SCBs aborted.\n", ahc_name(ahc), found); return SUCCESS; } struct scsi_host_template aic7xxx_driver_template = { .module = THIS_MODULE, .name = "aic7xxx", .proc_name = "aic7xxx", .proc_info = ahc_linux_proc_info, .info = ahc_linux_info, .queuecommand = ahc_linux_queue, .eh_abort_handler = ahc_linux_abort, .eh_device_reset_handler = ahc_linux_dev_reset, .eh_bus_reset_handler = ahc_linux_bus_reset, #if defined(__i386__) .bios_param = ahc_linux_biosparam, #endif .can_queue = AHC_MAX_QUEUE, .this_id = -1, .max_sectors = 8192, .cmd_per_lun = 2, .use_clustering = ENABLE_CLUSTERING, .slave_alloc = ahc_linux_slave_alloc, .slave_configure = ahc_linux_slave_configure, .target_alloc = ahc_linux_target_alloc, .target_destroy = ahc_linux_target_destroy, }; /**************************** Tasklet Handler *********************************/ /******************************** Macros **************************************/ #define BUILD_SCSIID(ahc, cmd) \ ((((cmd)->device->id << TID_SHIFT) & TID) \ | (((cmd)->device->channel == 0) ? (ahc)->our_id : (ahc)->our_id_b) \ | (((cmd)->device->channel == 0) ? 0 : TWIN_CHNLB)) /******************************** Bus DMA *************************************/ int ahc_dma_tag_create(struct ahc_softc *ahc, bus_dma_tag_t parent, bus_size_t alignment, bus_size_t boundary, dma_addr_t lowaddr, dma_addr_t highaddr, bus_dma_filter_t *filter, void *filterarg, bus_size_t maxsize, int nsegments, bus_size_t maxsegsz, int flags, bus_dma_tag_t *ret_tag) { bus_dma_tag_t dmat; dmat = kmalloc(sizeof(*dmat), GFP_ATOMIC); if (dmat == NULL) return (ENOMEM); /* * Linux is very simplistic about DMA memory. For now don't * maintain all specification information. Once Linux supplies * better facilities for doing these operations, or the * needs of this particular driver change, we might need to do * more here. */ dmat->alignment = alignment; dmat->boundary = boundary; dmat->maxsize = maxsize; *ret_tag = dmat; return (0); } void ahc_dma_tag_destroy(struct ahc_softc *ahc, bus_dma_tag_t dmat) { kfree(dmat); } int ahc_dmamem_alloc(struct ahc_softc *ahc, bus_dma_tag_t dmat, void** vaddr, int flags, bus_dmamap_t *mapp) { *vaddr = pci_alloc_consistent(ahc->dev_softc, dmat->maxsize, mapp); if (*vaddr == NULL) return ENOMEM; return 0; } void ahc_dmamem_free(struct ahc_softc *ahc, bus_dma_tag_t dmat, void* vaddr, bus_dmamap_t map) { pci_free_consistent(ahc->dev_softc, dmat->maxsize, vaddr, map); } int ahc_dmamap_load(struct ahc_softc *ahc, bus_dma_tag_t dmat, bus_dmamap_t map, void *buf, bus_size_t buflen, bus_dmamap_callback_t *cb, void *cb_arg, int flags) { /* * Assume for now that this will only be used during * initialization and not for per-transaction buffer mapping. */ bus_dma_segment_t stack_sg; stack_sg.ds_addr = map; stack_sg.ds_len = dmat->maxsize; cb(cb_arg, &stack_sg, /*nseg*/1, /*error*/0); return (0); } void ahc_dmamap_destroy(struct ahc_softc *ahc, bus_dma_tag_t dmat, bus_dmamap_t map) { } int ahc_dmamap_unload(struct ahc_softc *ahc, bus_dma_tag_t dmat, bus_dmamap_t map) { /* Nothing to do */ return (0); } static void ahc_linux_setup_tag_info_global(char *p) { int tags, i, j; tags = simple_strtoul(p + 1, NULL, 0) & 0xff; printk("Setting Global Tags= %d\n", tags); for (i = 0; i < ARRAY_SIZE(aic7xxx_tag_info); i++) { for (j = 0; j < AHC_NUM_TARGETS; j++) { aic7xxx_tag_info[i].tag_commands[j] = tags; } } } static void ahc_linux_setup_tag_info(u_long arg, int instance, int targ, int32_t value) { if ((instance >= 0) && (targ >= 0) && (instance < ARRAY_SIZE(aic7xxx_tag_info)) && (targ < AHC_NUM_TARGETS)) { aic7xxx_tag_info[instance].tag_commands[targ] = value & 0xff; if (bootverbose) printk("tag_info[%d:%d] = %d\n", instance, targ, value); } } static char * ahc_parse_brace_option(char *opt_name, char *opt_arg, char *end, int depth, void (*callback)(u_long, int, int, int32_t), u_long callback_arg) { char *tok_end; char *tok_end2; int i; int instance; int targ; int done; char tok_list[] = {'.', ',', '{', '}', '\0'}; /* All options use a ':' name/arg separator */ if (*opt_arg != ':') return (opt_arg); opt_arg++; instance = -1; targ = -1; done = FALSE; /* * Restore separator that may be in * the middle of our option argument. */ tok_end = strchr(opt_arg, '\0'); if (tok_end < end) *tok_end = ','; while (!done) { switch (*opt_arg) { case '{': if (instance == -1) { instance = 0; } else { if (depth > 1) { if (targ == -1) targ = 0; } else { printk("Malformed Option %s\n", opt_name); done = TRUE; } } opt_arg++; break; case '}': if (targ != -1) targ = -1; else if (instance != -1) instance = -1; opt_arg++; break; case ',': case '.': if (instance == -1) done = TRUE; else if (targ >= 0) targ++; else if (instance >= 0) instance++; opt_arg++; break; case '\0': done = TRUE; break; default: tok_end = end; for (i = 0; tok_list[i]; i++) { tok_end2 = strchr(opt_arg, tok_list[i]); if ((tok_end2) && (tok_end2 < tok_end)) tok_end = tok_end2; } callback(callback_arg, instance, targ, simple_strtol(opt_arg, NULL, 0)); opt_arg = tok_end; break; } } return (opt_arg); } /* * Handle Linux boot parameters. This routine allows for assigning a value * to a parameter with a ':' between the parameter and the value. * ie. aic7xxx=stpwlev:1,extended */ static int aic7xxx_setup(char *s) { int i, n; char *p; char *end; static const struct { const char *name; uint32_t *flag; } options[] = { { "extended", &aic7xxx_extended }, { "no_reset", &aic7xxx_no_reset }, { "verbose", &aic7xxx_verbose }, { "allow_memio", &aic7xxx_allow_memio}, #ifdef AHC_DEBUG { "debug", &ahc_debug }, #endif { "periodic_otag", &aic7xxx_periodic_otag }, { "pci_parity", &aic7xxx_pci_parity }, { "seltime", &aic7xxx_seltime }, { "tag_info", NULL }, { "global_tag_depth", NULL }, { "dv", NULL } }; end = strchr(s, '\0'); /* * XXX ia64 gcc isn't smart enough to know that ARRAY_SIZE * will never be 0 in this case. */ n = 0; while ((p = strsep(&s, ",.")) != NULL) { if (*p == '\0') continue; for (i = 0; i < ARRAY_SIZE(options); i++) { n = strlen(options[i].name); if (strncmp(options[i].name, p, n) == 0) break; } if (i == ARRAY_SIZE(options)) continue; if (strncmp(p, "global_tag_depth", n) == 0) { ahc_linux_setup_tag_info_global(p + n); } else if (strncmp(p, "tag_info", n) == 0) { s = ahc_parse_brace_option("tag_info", p + n, end, 2, ahc_linux_setup_tag_info, 0); } else if (p[n] == ':') { *(options[i].flag) = simple_strtoul(p + n + 1, NULL, 0); } else if (strncmp(p, "verbose", n) == 0) { *(options[i].flag) = 1; } else { *(options[i].flag) ^= 0xFFFFFFFF; } } return 1; } __setup("aic7xxx=", aic7xxx_setup); uint32_t aic7xxx_verbose; int ahc_linux_register_host(struct ahc_softc *ahc, struct scsi_host_template *template) { char buf[80]; struct Scsi_Host *host; char *new_name; u_long s; int retval; template->name = ahc->description; host = scsi_host_alloc(template, sizeof(struct ahc_softc *)); if (host == NULL) return (ENOMEM); *((struct ahc_softc **)host->hostdata) = ahc; ahc->platform_data->host = host; host->can_queue = AHC_MAX_QUEUE; host->cmd_per_lun = 2; /* XXX No way to communicate the ID for multiple channels */ host->this_id = ahc->our_id; host->irq = ahc->platform_data->irq; host->max_id = (ahc->features & AHC_WIDE) ? 16 : 8; host->max_lun = AHC_NUM_LUNS; host->max_channel = (ahc->features & AHC_TWIN) ? 1 : 0; host->sg_tablesize = AHC_NSEG; ahc_lock(ahc, &s); ahc_set_unit(ahc, ahc_linux_unit++); ahc_unlock(ahc, &s); sprintf(buf, "scsi%d", host->host_no); new_name = kmalloc(strlen(buf) + 1, GFP_ATOMIC); if (new_name != NULL) { strcpy(new_name, buf); ahc_set_name(ahc, new_name); } host->unique_id = ahc->unit; ahc_linux_initialize_scsi_bus(ahc); ahc_intr_enable(ahc, TRUE); host->transportt = ahc_linux_transport_template; retval = scsi_add_host(host, (ahc->dev_softc ? &ahc->dev_softc->dev : NULL)); if (retval) { printk(KERN_WARNING "aic7xxx: scsi_add_host failed\n"); scsi_host_put(host); return retval; } scsi_scan_host(host); return 0; } /* * Place the SCSI bus into a known state by either resetting it, * or forcing transfer negotiations on the next command to any * target. */ void ahc_linux_initialize_scsi_bus(struct ahc_softc *ahc) { int i; int numtarg; unsigned long s; i = 0; numtarg = 0; ahc_lock(ahc, &s); if (aic7xxx_no_reset != 0) ahc->flags &= ~(AHC_RESET_BUS_A|AHC_RESET_BUS_B); if ((ahc->flags & AHC_RESET_BUS_A) != 0) ahc_reset_channel(ahc, 'A', /*initiate_reset*/TRUE); else numtarg = (ahc->features & AHC_WIDE) ? 16 : 8; if ((ahc->features & AHC_TWIN) != 0) { if ((ahc->flags & AHC_RESET_BUS_B) != 0) { ahc_reset_channel(ahc, 'B', /*initiate_reset*/TRUE); } else { if (numtarg == 0) i = 8; numtarg += 8; } } /* * Force negotiation to async for all targets that * will not see an initial bus reset. */ for (; i < numtarg; i++) { struct ahc_devinfo devinfo; struct ahc_initiator_tinfo *tinfo; struct ahc_tmode_tstate *tstate; u_int our_id; u_int target_id; char channel; channel = 'A'; our_id = ahc->our_id; target_id = i; if (i > 7 && (ahc->features & AHC_TWIN) != 0) { channel = 'B'; our_id = ahc->our_id_b; target_id = i % 8; } tinfo = ahc_fetch_transinfo(ahc, channel, our_id, target_id, &tstate); ahc_compile_devinfo(&devinfo, our_id, target_id, CAM_LUN_WILDCARD, channel, ROLE_INITIATOR); ahc_update_neg_request(ahc, &devinfo, tstate, tinfo, AHC_NEG_ALWAYS); } ahc_unlock(ahc, &s); /* Give the bus some time to recover */ if ((ahc->flags & (AHC_RESET_BUS_A|AHC_RESET_BUS_B)) != 0) { ahc_linux_freeze_simq(ahc); msleep(AIC7XXX_RESET_DELAY); ahc_linux_release_simq(ahc); } } int ahc_platform_alloc(struct ahc_softc *ahc, void *platform_arg) { ahc->platform_data = kmalloc(sizeof(struct ahc_platform_data), GFP_ATOMIC); if (ahc->platform_data == NULL) return (ENOMEM); memset(ahc->platform_data, 0, sizeof(struct ahc_platform_data)); ahc->platform_data->irq = AHC_LINUX_NOIRQ; ahc_lockinit(ahc); ahc->seltime = (aic7xxx_seltime & 0x3) << 4; ahc->seltime_b = (aic7xxx_seltime & 0x3) << 4; if (aic7xxx_pci_parity == 0) ahc->flags |= AHC_DISABLE_PCI_PERR; return (0); } void ahc_platform_free(struct ahc_softc *ahc) { struct scsi_target *starget; int i; if (ahc->platform_data != NULL) { /* destroy all of the device and target objects */ for (i = 0; i < AHC_NUM_TARGETS; i++) { starget = ahc->platform_data->starget[i]; if (starget != NULL) { ahc->platform_data->starget[i] = NULL; } } if (ahc->platform_data->irq != AHC_LINUX_NOIRQ) free_irq(ahc->platform_data->irq, ahc); if (ahc->tag == BUS_SPACE_PIO && ahc->bsh.ioport != 0) release_region(ahc->bsh.ioport, 256); if (ahc->tag == BUS_SPACE_MEMIO && ahc->bsh.maddr != NULL) { iounmap(ahc->bsh.maddr); release_mem_region(ahc->platform_data->mem_busaddr, 0x1000); } if (ahc->platform_data->host) scsi_host_put(ahc->platform_data->host); kfree(ahc->platform_data); } } void ahc_platform_freeze_devq(struct ahc_softc *ahc, struct scb *scb) { ahc_platform_abort_scbs(ahc, SCB_GET_TARGET(ahc, scb), SCB_GET_CHANNEL(ahc, scb), SCB_GET_LUN(scb), SCB_LIST_NULL, ROLE_UNKNOWN, CAM_REQUEUE_REQ); } void ahc_platform_set_tags(struct ahc_softc *ahc, struct scsi_device *sdev, struct ahc_devinfo *devinfo, ahc_queue_alg alg) { struct ahc_linux_device *dev; int was_queuing; int now_queuing; if (sdev == NULL) return; dev = scsi_transport_device_data(sdev); was_queuing = dev->flags & (AHC_DEV_Q_BASIC|AHC_DEV_Q_TAGGED); switch (alg) { default: case AHC_QUEUE_NONE: now_queuing = 0; break; case AHC_QUEUE_BASIC: now_queuing = AHC_DEV_Q_BASIC; break; case AHC_QUEUE_TAGGED: now_queuing = AHC_DEV_Q_TAGGED; break; } if ((dev->flags & AHC_DEV_FREEZE_TIL_EMPTY) == 0 && (was_queuing != now_queuing) && (dev->active != 0)) { dev->flags |= AHC_DEV_FREEZE_TIL_EMPTY; dev->qfrozen++; } dev->flags &= ~(AHC_DEV_Q_BASIC|AHC_DEV_Q_TAGGED|AHC_DEV_PERIODIC_OTAG); if (now_queuing) { u_int usertags; usertags = ahc_linux_user_tagdepth(ahc, devinfo); if (!was_queuing) { /* * Start out aggressively and allow our * dynamic queue depth algorithm to take * care of the rest. */ dev->maxtags = usertags; dev->openings = dev->maxtags - dev->active; } if (dev->maxtags == 0) { /* * Queueing is disabled by the user. */ dev->openings = 1; } else if (alg == AHC_QUEUE_TAGGED) { dev->flags |= AHC_DEV_Q_TAGGED; if (aic7xxx_periodic_otag != 0) dev->flags |= AHC_DEV_PERIODIC_OTAG; } else dev->flags |= AHC_DEV_Q_BASIC; } else { /* We can only have one opening. */ dev->maxtags = 0; dev->openings = 1 - dev->active; } switch ((dev->flags & (AHC_DEV_Q_BASIC|AHC_DEV_Q_TAGGED))) { case AHC_DEV_Q_BASIC: scsi_set_tag_type(sdev, MSG_SIMPLE_TAG); scsi_activate_tcq(sdev, dev->openings + dev->active); break; case AHC_DEV_Q_TAGGED: scsi_set_tag_type(sdev, MSG_ORDERED_TAG); scsi_activate_tcq(sdev, dev->openings + dev->active); break; default: /* * We allow the OS to queue 2 untagged transactions to * us at any time even though we can only execute them * serially on the controller/device. This should * remove some latency. */ scsi_deactivate_tcq(sdev, 2); break; } } int ahc_platform_abort_scbs(struct ahc_softc *ahc, int target, char channel, int lun, u_int tag, role_t role, uint32_t status) { return 0; } static u_int ahc_linux_user_tagdepth(struct ahc_softc *ahc, struct ahc_devinfo *devinfo) { static int warned_user; u_int tags; tags = 0; if ((ahc->user_discenable & devinfo->target_mask) != 0) { if (ahc->unit >= ARRAY_SIZE(aic7xxx_tag_info)) { if (warned_user == 0) { printk(KERN_WARNING "aic7xxx: WARNING: Insufficient tag_info instances\n" "aic7xxx: for installed controllers. Using defaults\n" "aic7xxx: Please update the aic7xxx_tag_info array in\n" "aic7xxx: the aic7xxx_osm..c source file.\n"); warned_user++; } tags = AHC_MAX_QUEUE; } else { adapter_tag_info_t *tag_info; tag_info = &aic7xxx_tag_info[ahc->unit]; tags = tag_info->tag_commands[devinfo->target_offset]; if (tags > AHC_MAX_QUEUE) tags = AHC_MAX_QUEUE; } } return (tags); } /* * Determines the queue depth for a given device. */ static void ahc_linux_device_queue_depth(struct scsi_device *sdev) { struct ahc_devinfo devinfo; u_int tags; struct ahc_softc *ahc = *((struct ahc_softc **)sdev->host->hostdata); ahc_compile_devinfo(&devinfo, sdev->sdev_target->channel == 0 ? ahc->our_id : ahc->our_id_b, sdev->sdev_target->id, sdev->lun, sdev->sdev_target->channel == 0 ? 'A' : 'B', ROLE_INITIATOR); tags = ahc_linux_user_tagdepth(ahc, &devinfo); if (tags != 0 && sdev->tagged_supported != 0) { ahc_platform_set_tags(ahc, sdev, &devinfo, AHC_QUEUE_TAGGED); ahc_send_async(ahc, devinfo.channel, devinfo.target, devinfo.lun, AC_TRANSFER_NEG); ahc_print_devinfo(ahc, &devinfo); printk("Tagged Queuing enabled. Depth %d\n", tags); } else { ahc_platform_set_tags(ahc, sdev, &devinfo, AHC_QUEUE_NONE); ahc_send_async(ahc, devinfo.channel, devinfo.target, devinfo.lun, AC_TRANSFER_NEG); } } static int ahc_linux_run_command(struct ahc_softc *ahc, struct ahc_linux_device *dev, struct scsi_cmnd *cmd) { struct scb *scb; struct hardware_scb *hscb; struct ahc_initiator_tinfo *tinfo; struct ahc_tmode_tstate *tstate; uint16_t mask; struct scb_tailq *untagged_q = NULL; int nseg; /* * Schedule us to run later. The only reason we are not * running is because the whole controller Q is frozen. */ if (ahc->platform_data->qfrozen != 0) return SCSI_MLQUEUE_HOST_BUSY; /* * We only allow one untagged transaction * per target in the initiator role unless * we are storing a full busy target *lun* * table in SCB space. */ if (!blk_rq_tagged(cmd->request) && (ahc->features & AHC_SCB_BTT) == 0) { int target_offset; target_offset = cmd->device->id + cmd->device->channel * 8; untagged_q = &(ahc->untagged_queues[target_offset]); if (!TAILQ_EMPTY(untagged_q)) /* if we're already executing an untagged command * we're busy to another */ return SCSI_MLQUEUE_DEVICE_BUSY; } nseg = scsi_dma_map(cmd); if (nseg < 0) return SCSI_MLQUEUE_HOST_BUSY; /* * Get an scb to use. */ scb = ahc_get_scb(ahc); if (!scb) { scsi_dma_unmap(cmd); return SCSI_MLQUEUE_HOST_BUSY; } scb->io_ctx = cmd; scb->platform_data->dev = dev; hscb = scb->hscb; cmd->host_scribble = (char *)scb; /* * Fill out basics of the HSCB. */ hscb->control = 0; hscb->scsiid = BUILD_SCSIID(ahc, cmd); hscb->lun = cmd->device->lun; mask = SCB_GET_TARGET_MASK(ahc, scb); tinfo = ahc_fetch_transinfo(ahc, SCB_GET_CHANNEL(ahc, scb), SCB_GET_OUR_ID(scb), SCB_GET_TARGET(ahc, scb), &tstate); hscb->scsirate = tinfo->scsirate; hscb->scsioffset = tinfo->curr.offset; if ((tstate->ultraenb & mask) != 0) hscb->control |= ULTRAENB; if ((ahc->user_discenable & mask) != 0) hscb->control |= DISCENB; if ((tstate->auto_negotiate & mask) != 0) { scb->flags |= SCB_AUTO_NEGOTIATE; scb->hscb->control |= MK_MESSAGE; } if ((dev->flags & (AHC_DEV_Q_TAGGED|AHC_DEV_Q_BASIC)) != 0) { int msg_bytes; uint8_t tag_msgs[2]; msg_bytes = scsi_populate_tag_msg(cmd, tag_msgs); if (msg_bytes && tag_msgs[0] != MSG_SIMPLE_TASK) { hscb->control |= tag_msgs[0]; if (tag_msgs[0] == MSG_ORDERED_TASK) dev->commands_since_idle_or_otag = 0; } else if (dev->commands_since_idle_or_otag == AHC_OTAG_THRESH && (dev->flags & AHC_DEV_Q_TAGGED) != 0) { hscb->control |= MSG_ORDERED_TASK; dev->commands_since_idle_or_otag = 0; } else { hscb->control |= MSG_SIMPLE_TASK; } } hscb->cdb_len = cmd->cmd_len; if (hscb->cdb_len <= 12) { memcpy(hscb->shared_data.cdb, cmd->cmnd, hscb->cdb_len); } else { memcpy(hscb->cdb32, cmd->cmnd, hscb->cdb_len); scb->flags |= SCB_CDB32_PTR; } scb->platform_data->xfer_len = 0; ahc_set_residual(scb, 0); ahc_set_sense_residual(scb, 0); scb->sg_count = 0; if (nseg > 0) { struct ahc_dma_seg *sg; struct scatterlist *cur_seg; int i; /* Copy the segments into the SG list. */ sg = scb->sg_list; /* * The sg_count may be larger than nseg if * a transfer crosses a 32bit page. */ scsi_for_each_sg(cmd, cur_seg, nseg, i) { dma_addr_t addr; bus_size_t len; int consumed; addr = sg_dma_address(cur_seg); len = sg_dma_len(cur_seg); consumed = ahc_linux_map_seg(ahc, scb, sg, addr, len); sg += consumed; scb->sg_count += consumed; } sg--; sg->len |= ahc_htole32(AHC_DMA_LAST_SEG); /* * Reset the sg list pointer. */ scb->hscb->sgptr = ahc_htole32(scb->sg_list_phys | SG_FULL_RESID); /* * Copy the first SG into the "current" * data pointer area. */ scb->hscb->dataptr = scb->sg_list->addr; scb->hscb->datacnt = scb->sg_list->len; } else { scb->hscb->sgptr = ahc_htole32(SG_LIST_NULL); scb->hscb->dataptr = 0; scb->hscb->datacnt = 0; scb->sg_count = 0; } LIST_INSERT_HEAD(&ahc->pending_scbs, scb, pending_links); dev->openings--; dev->active++; dev->commands_issued++; if ((dev->flags & AHC_DEV_PERIODIC_OTAG) != 0) dev->commands_since_idle_or_otag++; scb->flags |= SCB_ACTIVE; if (untagged_q) { TAILQ_INSERT_TAIL(untagged_q, scb, links.tqe); scb->flags |= SCB_UNTAGGEDQ; } ahc_queue_scb(ahc, scb); return 0; } /* * SCSI controller interrupt handler. */ irqreturn_t ahc_linux_isr(int irq, void *dev_id) { struct ahc_softc *ahc; u_long flags; int ours; ahc = (struct ahc_softc *) dev_id; ahc_lock(ahc, &flags); ours = ahc_intr(ahc); ahc_unlock(ahc, &flags); return IRQ_RETVAL(ours); } void ahc_platform_flushwork(struct ahc_softc *ahc) { } void ahc_send_async(struct ahc_softc *ahc, char channel, u_int target, u_int lun, ac_code code) { switch (code) { case AC_TRANSFER_NEG: { char buf[80]; struct scsi_target *starget; struct ahc_linux_target *targ; struct info_str info; struct ahc_initiator_tinfo *tinfo; struct ahc_tmode_tstate *tstate; int target_offset; unsigned int target_ppr_options; BUG_ON(target == CAM_TARGET_WILDCARD); info.buffer = buf; info.length = sizeof(buf); info.offset = 0; info.pos = 0; tinfo = ahc_fetch_transinfo(ahc, channel, channel == 'A' ? ahc->our_id : ahc->our_id_b, target, &tstate); /* * Don't bother reporting results while * negotiations are still pending. */ if (tinfo->curr.period != tinfo->goal.period || tinfo->curr.width != tinfo->goal.width || tinfo->curr.offset != tinfo->goal.offset || tinfo->curr.ppr_options != tinfo->goal.ppr_options) if (bootverbose == 0) break; /* * Don't bother reporting results that * are identical to those last reported. */ target_offset = target; if (channel == 'B') target_offset += 8; starget = ahc->platform_data->starget[target_offset]; if (starget == NULL) break; targ = scsi_transport_target_data(starget); target_ppr_options = (spi_dt(starget) ? MSG_EXT_PPR_DT_REQ : 0) + (spi_qas(starget) ? MSG_EXT_PPR_QAS_REQ : 0) + (spi_iu(starget) ? MSG_EXT_PPR_IU_REQ : 0); if (tinfo->curr.period == spi_period(starget) && tinfo->curr.width == spi_width(starget) && tinfo->curr.offset == spi_offset(starget) && tinfo->curr.ppr_options == target_ppr_options) if (bootverbose == 0) break; spi_period(starget) = tinfo->curr.period; spi_width(starget) = tinfo->curr.width; spi_offset(starget) = tinfo->curr.offset; spi_dt(starget) = tinfo->curr.ppr_options & MSG_EXT_PPR_DT_REQ ? 1 : 0; spi_qas(starget) = tinfo->curr.ppr_options & MSG_EXT_PPR_QAS_REQ ? 1 : 0; spi_iu(starget) = tinfo->curr.ppr_options & MSG_EXT_PPR_IU_REQ ? 1 : 0; spi_display_xfer_agreement(starget); break; } case AC_SENT_BDR: { WARN_ON(lun != CAM_LUN_WILDCARD); scsi_report_device_reset(ahc->platform_data->host, channel - 'A', target); break; } case AC_BUS_RESET: if (ahc->platform_data->host != NULL) { scsi_report_bus_reset(ahc->platform_data->host, channel - 'A'); } break; default: panic("ahc_send_async: Unexpected async event"); } } /* * Calls the higher level scsi done function and frees the scb. */ void ahc_done(struct ahc_softc *ahc, struct scb *scb) { struct scsi_cmnd *cmd; struct ahc_linux_device *dev; LIST_REMOVE(scb, pending_links); if ((scb->flags & SCB_UNTAGGEDQ) != 0) { struct scb_tailq *untagged_q; int target_offset; target_offset = SCB_GET_TARGET_OFFSET(ahc, scb); untagged_q = &(ahc->untagged_queues[target_offset]); TAILQ_REMOVE(untagged_q, scb, links.tqe); BUG_ON(!TAILQ_EMPTY(untagged_q)); } else if ((scb->flags & SCB_ACTIVE) == 0) { /* * Transactions aborted from the untagged queue may * not have been dispatched to the controller, so * only check the SCB_ACTIVE flag for tagged transactions. */ printk("SCB %d done'd twice\n", scb->hscb->tag); ahc_dump_card_state(ahc); panic("Stopping for safety"); } cmd = scb->io_ctx; dev = scb->platform_data->dev; dev->active--; dev->openings++; if ((cmd->result & (CAM_DEV_QFRZN << 16)) != 0) { cmd->result &= ~(CAM_DEV_QFRZN << 16); dev->qfrozen--; } ahc_linux_unmap_scb(ahc, scb); /* * Guard against stale sense data. * The Linux mid-layer assumes that sense * was retrieved anytime the first byte of * the sense buffer looks "sane". */ cmd->sense_buffer[0] = 0; if (ahc_get_transaction_status(scb) == CAM_REQ_INPROG) { uint32_t amount_xferred; amount_xferred = ahc_get_transfer_length(scb) - ahc_get_residual(scb); if ((scb->flags & SCB_TRANSMISSION_ERROR) != 0) { #ifdef AHC_DEBUG if ((ahc_debug & AHC_SHOW_MISC) != 0) { ahc_print_path(ahc, scb); printk("Set CAM_UNCOR_PARITY\n"); } #endif ahc_set_transaction_status(scb, CAM_UNCOR_PARITY); #ifdef AHC_REPORT_UNDERFLOWS /* * This code is disabled by default as some * clients of the SCSI system do not properly * initialize the underflow parameter. This * results in spurious termination of commands * that complete as expected (e.g. underflow is * allowed as command can return variable amounts * of data. */ } else if (amount_xferred < scb->io_ctx->underflow) { u_int i; ahc_print_path(ahc, scb); printk("CDB:"); for (i = 0; i < scb->io_ctx->cmd_len; i++) printk(" 0x%x", scb->io_ctx->cmnd[i]); printk("\n"); ahc_print_path(ahc, scb); printk("Saw underflow (%ld of %ld bytes). " "Treated as error\n", ahc_get_residual(scb), ahc_get_transfer_length(scb)); ahc_set_transaction_status(scb, CAM_DATA_RUN_ERR); #endif } else { ahc_set_transaction_status(scb, CAM_REQ_CMP); } } else if (ahc_get_transaction_status(scb) == CAM_SCSI_STATUS_ERROR) { ahc_linux_handle_scsi_status(ahc, cmd->device, scb); } if (dev->openings == 1 && ahc_get_transaction_status(scb) == CAM_REQ_CMP && ahc_get_scsi_status(scb) != SCSI_STATUS_QUEUE_FULL) dev->tag_success_count++; /* * Some devices deal with temporary internal resource * shortages by returning queue full. When the queue * full occurrs, we throttle back. Slowly try to get * back to our previous queue depth. */ if ((dev->openings + dev->active) < dev->maxtags && dev->tag_success_count > AHC_TAG_SUCCESS_INTERVAL) { dev->tag_success_count = 0; dev->openings++; } if (dev->active == 0) dev->commands_since_idle_or_otag = 0; if ((scb->flags & SCB_RECOVERY_SCB) != 0) { printk("Recovery SCB completes\n"); if (ahc_get_transaction_status(scb) == CAM_BDR_SENT || ahc_get_transaction_status(scb) == CAM_REQ_ABORTED) ahc_set_transaction_status(scb, CAM_CMD_TIMEOUT); if (ahc->platform_data->eh_done) complete(ahc->platform_data->eh_done); } ahc_free_scb(ahc, scb); ahc_linux_queue_cmd_complete(ahc, cmd); } static void ahc_linux_handle_scsi_status(struct ahc_softc *ahc, struct scsi_device *sdev, struct scb *scb) { struct ahc_devinfo devinfo; struct ahc_linux_device *dev = scsi_transport_device_data(sdev); ahc_compile_devinfo(&devinfo, ahc->our_id, sdev->sdev_target->id, sdev->lun, sdev->sdev_target->channel == 0 ? 'A' : 'B', ROLE_INITIATOR); /* * We don't currently trust the mid-layer to * properly deal with queue full or busy. So, * when one occurs, we tell the mid-layer to * unconditionally requeue the command to us * so that we can retry it ourselves. We also * implement our own throttling mechanism so * we don't clobber the device with too many * commands. */ switch (ahc_get_scsi_status(scb)) { default: break; case SCSI_STATUS_CHECK_COND: case SCSI_STATUS_CMD_TERMINATED: { struct scsi_cmnd *cmd; /* * Copy sense information to the OS's cmd * structure if it is available. */ cmd = scb->io_ctx; if (scb->flags & SCB_SENSE) { u_int sense_size; sense_size = min(sizeof(struct scsi_sense_data) - ahc_get_sense_residual(scb), (u_long)SCSI_SENSE_BUFFERSIZE); memcpy(cmd->sense_buffer, ahc_get_sense_buf(ahc, scb), sense_size); if (sense_size < SCSI_SENSE_BUFFERSIZE) memset(&cmd->sense_buffer[sense_size], 0, SCSI_SENSE_BUFFERSIZE - sense_size); cmd->result |= (DRIVER_SENSE << 24); #ifdef AHC_DEBUG if (ahc_debug & AHC_SHOW_SENSE) { int i; printk("Copied %d bytes of sense data:", sense_size); for (i = 0; i < sense_size; i++) { if ((i & 0xF) == 0) printk("\n"); printk("0x%x ", cmd->sense_buffer[i]); } printk("\n"); } #endif } break; } case SCSI_STATUS_QUEUE_FULL: { /* * By the time the core driver has returned this * command, all other commands that were queued * to us but not the device have been returned. * This ensures that dev->active is equal to * the number of commands actually queued to * the device. */ dev->tag_success_count = 0; if (dev->active != 0) { /* * Drop our opening count to the number * of commands currently outstanding. */ dev->openings = 0; /* ahc_print_path(ahc, scb); printk("Dropping tag count to %d\n", dev->active); */ if (dev->active == dev->tags_on_last_queuefull) { dev->last_queuefull_same_count++; /* * If we repeatedly see a queue full * at the same queue depth, this * device has a fixed number of tag * slots. Lock in this tag depth * so we stop seeing queue fulls from * this device. */ if (dev->last_queuefull_same_count == AHC_LOCK_TAGS_COUNT) { dev->maxtags = dev->active; ahc_print_path(ahc, scb); printk("Locking max tag count at %d\n", dev->active); } } else { dev->tags_on_last_queuefull = dev->active; dev->last_queuefull_same_count = 0; } ahc_set_transaction_status(scb, CAM_REQUEUE_REQ); ahc_set_scsi_status(scb, SCSI_STATUS_OK); ahc_platform_set_tags(ahc, sdev, &devinfo, (dev->flags & AHC_DEV_Q_BASIC) ? AHC_QUEUE_BASIC : AHC_QUEUE_TAGGED); break; } /* * Drop down to a single opening, and treat this * as if the target returned BUSY SCSI status. */ dev->openings = 1; ahc_set_scsi_status(scb, SCSI_STATUS_BUSY); ahc_platform_set_tags(ahc, sdev, &devinfo, (dev->flags & AHC_DEV_Q_BASIC) ? AHC_QUEUE_BASIC : AHC_QUEUE_TAGGED); break; } } } static void ahc_linux_queue_cmd_complete(struct ahc_softc *ahc, struct scsi_cmnd *cmd) { /* * Map CAM error codes into Linux Error codes. We * avoid the conversion so that the DV code has the * full error information available when making * state change decisions. */ { u_int new_status; switch (ahc_cmd_get_transaction_status(cmd)) { case CAM_REQ_INPROG: case CAM_REQ_CMP: case CAM_SCSI_STATUS_ERROR: new_status = DID_OK; break; case CAM_REQ_ABORTED: new_status = DID_ABORT; break; case CAM_BUSY: new_status = DID_BUS_BUSY; break; case CAM_REQ_INVALID: case CAM_PATH_INVALID: new_status = DID_BAD_TARGET; break; case CAM_SEL_TIMEOUT: new_status = DID_NO_CONNECT; break; case CAM_SCSI_BUS_RESET: case CAM_BDR_SENT: new_status = DID_RESET; break; case CAM_UNCOR_PARITY: new_status = DID_PARITY; break; case CAM_CMD_TIMEOUT: new_status = DID_TIME_OUT; break; case CAM_UA_ABORT: case CAM_REQ_CMP_ERR: case CAM_AUTOSENSE_FAIL: case CAM_NO_HBA: case CAM_DATA_RUN_ERR: case CAM_UNEXP_BUSFREE: case CAM_SEQUENCE_FAIL: case CAM_CCB_LEN_ERR: case CAM_PROVIDE_FAIL: case CAM_REQ_TERMIO: case CAM_UNREC_HBA_ERROR: case CAM_REQ_TOO_BIG: new_status = DID_ERROR; break; case CAM_REQUEUE_REQ: new_status = DID_REQUEUE; break; default: /* We should never get here */ new_status = DID_ERROR; break; } ahc_cmd_set_transaction_status(cmd, new_status); } cmd->scsi_done(cmd); } static void ahc_linux_freeze_simq(struct ahc_softc *ahc) { unsigned long s; ahc_lock(ahc, &s); ahc->platform_data->qfrozen++; if (ahc->platform_data->qfrozen == 1) { scsi_block_requests(ahc->platform_data->host); /* XXX What about Twin channels? */ ahc_platform_abort_scbs(ahc, CAM_TARGET_WILDCARD, ALL_CHANNELS, CAM_LUN_WILDCARD, SCB_LIST_NULL, ROLE_INITIATOR, CAM_REQUEUE_REQ); } ahc_unlock(ahc, &s); } static void ahc_linux_release_simq(struct ahc_softc *ahc) { u_long s; int unblock_reqs; unblock_reqs = 0; ahc_lock(ahc, &s); if (ahc->platform_data->qfrozen > 0) ahc->platform_data->qfrozen--; if (ahc->platform_data->qfrozen == 0) unblock_reqs = 1; ahc_unlock(ahc, &s); /* * There is still a race here. The mid-layer * should keep its own freeze count and use * a bottom half handler to run the queues * so we can unblock with our own lock held. */ if (unblock_reqs) scsi_unblock_requests(ahc->platform_data->host); } static int ahc_linux_queue_recovery_cmd(struct scsi_cmnd *cmd, scb_flag flag) { struct ahc_softc *ahc; struct ahc_linux_device *dev; struct scb *pending_scb; u_int saved_scbptr; u_int active_scb_index; u_int last_phase; u_int saved_scsiid; u_int cdb_byte; int retval; int was_paused; int paused; int wait; int disconnected; unsigned long flags; pending_scb = NULL; paused = FALSE; wait = FALSE; ahc = *(struct ahc_softc **)cmd->device->host->hostdata; scmd_printk(KERN_INFO, cmd, "Attempting to queue a%s message\n", flag == SCB_ABORT ? "n ABORT" : " TARGET RESET"); printk("CDB:"); for (cdb_byte = 0; cdb_byte < cmd->cmd_len; cdb_byte++) printk(" 0x%x", cmd->cmnd[cdb_byte]); printk("\n"); ahc_lock(ahc, &flags); /* * First determine if we currently own this command. * Start by searching the device queue. If not found * there, check the pending_scb list. If not found * at all, and the system wanted us to just abort the * command, return success. */ dev = scsi_transport_device_data(cmd->device); if (dev == NULL) { /* * No target device for this command exists, * so we must not still own the command. */ printk("%s:%d:%d:%d: Is not an active device\n", ahc_name(ahc), cmd->device->channel, cmd->device->id, cmd->device->lun); retval = SUCCESS; goto no_cmd; } if ((dev->flags & (AHC_DEV_Q_BASIC|AHC_DEV_Q_TAGGED)) == 0 && ahc_search_untagged_queues(ahc, cmd, cmd->device->id, cmd->device->channel + 'A', cmd->device->lun, CAM_REQ_ABORTED, SEARCH_COMPLETE) != 0) { printk("%s:%d:%d:%d: Command found on untagged queue\n", ahc_name(ahc), cmd->device->channel, cmd->device->id, cmd->device->lun); retval = SUCCESS; goto done; } /* * See if we can find a matching cmd in the pending list. */ LIST_FOREACH(pending_scb, &ahc->pending_scbs, pending_links) { if (pending_scb->io_ctx == cmd) break; } if (pending_scb == NULL && flag == SCB_DEVICE_RESET) { /* Any SCB for this device will do for a target reset */ LIST_FOREACH(pending_scb, &ahc->pending_scbs, pending_links) { if (ahc_match_scb(ahc, pending_scb, scmd_id(cmd), scmd_channel(cmd) + 'A', CAM_LUN_WILDCARD, SCB_LIST_NULL, ROLE_INITIATOR)) break; } } if (pending_scb == NULL) { scmd_printk(KERN_INFO, cmd, "Command not found\n"); goto no_cmd; } if ((pending_scb->flags & SCB_RECOVERY_SCB) != 0) { /* * We can't queue two recovery actions using the same SCB */ retval = FAILED; goto done; } /* * Ensure that the card doesn't do anything * behind our back and that we didn't "just" miss * an interrupt that would affect this cmd. */ was_paused = ahc_is_paused(ahc); ahc_pause_and_flushwork(ahc); paused = TRUE; if ((pending_scb->flags & SCB_ACTIVE) == 0) { scmd_printk(KERN_INFO, cmd, "Command already completed\n"); goto no_cmd; } printk("%s: At time of recovery, card was %spaused\n", ahc_name(ahc), was_paused ? "" : "not "); ahc_dump_card_state(ahc); disconnected = TRUE; if (flag == SCB_ABORT) { if (ahc_search_qinfifo(ahc, cmd->device->id, cmd->device->channel + 'A', cmd->device->lun, pending_scb->hscb->tag, ROLE_INITIATOR, CAM_REQ_ABORTED, SEARCH_COMPLETE) > 0) { printk("%s:%d:%d:%d: Cmd aborted from QINFIFO\n", ahc_name(ahc), cmd->device->channel, cmd->device->id, cmd->device->lun); retval = SUCCESS; goto done; } } else if (ahc_search_qinfifo(ahc, cmd->device->id, cmd->device->channel + 'A', cmd->device->lun, pending_scb->hscb->tag, ROLE_INITIATOR, /*status*/0, SEARCH_COUNT) > 0) { disconnected = FALSE; } if (disconnected && (ahc_inb(ahc, SEQ_FLAGS) & NOT_IDENTIFIED) == 0) { struct scb *bus_scb; bus_scb = ahc_lookup_scb(ahc, ahc_inb(ahc, SCB_TAG)); if (bus_scb == pending_scb) disconnected = FALSE; else if (flag != SCB_ABORT && ahc_inb(ahc, SAVED_SCSIID) == pending_scb->hscb->scsiid && ahc_inb(ahc, SAVED_LUN) == SCB_GET_LUN(pending_scb)) disconnected = FALSE; } /* * At this point, pending_scb is the scb associated with the * passed in command. That command is currently active on the * bus, is in the disconnected state, or we're hoping to find * a command for the same target active on the bus to abuse to * send a BDR. Queue the appropriate message based on which of * these states we are in. */ last_phase = ahc_inb(ahc, LASTPHASE); saved_scbptr = ahc_inb(ahc, SCBPTR); active_scb_index = ahc_inb(ahc, SCB_TAG); saved_scsiid = ahc_inb(ahc, SAVED_SCSIID); if (last_phase != P_BUSFREE && (pending_scb->hscb->tag == active_scb_index || (flag == SCB_DEVICE_RESET && SCSIID_TARGET(ahc, saved_scsiid) == scmd_id(cmd)))) { /* * We're active on the bus, so assert ATN * and hope that the target responds. */ pending_scb = ahc_lookup_scb(ahc, active_scb_index); pending_scb->flags |= SCB_RECOVERY_SCB|flag; ahc_outb(ahc, MSG_OUT, HOST_MSG); ahc_outb(ahc, SCSISIGO, last_phase|ATNO); scmd_printk(KERN_INFO, cmd, "Device is active, asserting ATN\n"); wait = TRUE; } else if (disconnected) { /* * Actually re-queue this SCB in an attempt * to select the device before it reconnects. * In either case (selection or reselection), * we will now issue the approprate message * to the timed-out device. * * Set the MK_MESSAGE control bit indicating * that we desire to send a message. We * also set the disconnected flag since * in the paging case there is no guarantee * that our SCB control byte matches the * version on the card. We don't want the * sequencer to abort the command thinking * an unsolicited reselection occurred. */ pending_scb->hscb->control |= MK_MESSAGE|DISCONNECTED; pending_scb->flags |= SCB_RECOVERY_SCB|flag; /* * Remove any cached copy of this SCB in the * disconnected list in preparation for the * queuing of our abort SCB. We use the * same element in the SCB, SCB_NEXT, for * both the qinfifo and the disconnected list. */ ahc_search_disc_list(ahc, cmd->device->id, cmd->device->channel + 'A', cmd->device->lun, pending_scb->hscb->tag, /*stop_on_first*/TRUE, /*remove*/TRUE, /*save_state*/FALSE); /* * In the non-paging case, the sequencer will * never re-reference the in-core SCB. * To make sure we are notified during * reselection, set the MK_MESSAGE flag in * the card's copy of the SCB. */ if ((ahc->flags & AHC_PAGESCBS) == 0) { ahc_outb(ahc, SCBPTR, pending_scb->hscb->tag); ahc_outb(ahc, SCB_CONTROL, ahc_inb(ahc, SCB_CONTROL)|MK_MESSAGE); } /* * Clear out any entries in the QINFIFO first * so we are the next SCB for this target * to run. */ ahc_search_qinfifo(ahc, cmd->device->id, cmd->device->channel + 'A', cmd->device->lun, SCB_LIST_NULL, ROLE_INITIATOR, CAM_REQUEUE_REQ, SEARCH_COMPLETE); ahc_qinfifo_requeue_tail(ahc, pending_scb); ahc_outb(ahc, SCBPTR, saved_scbptr); ahc_print_path(ahc, pending_scb); printk("Device is disconnected, re-queuing SCB\n"); wait = TRUE; } else { scmd_printk(KERN_INFO, cmd, "Unable to deliver message\n"); retval = FAILED; goto done; } no_cmd: /* * Our assumption is that if we don't have the command, no * recovery action was required, so we return success. Again, * the semantics of the mid-layer recovery engine are not * well defined, so this may change in time. */ retval = SUCCESS; done: if (paused) ahc_unpause(ahc); if (wait) { DECLARE_COMPLETION_ONSTACK(done); ahc->platform_data->eh_done = &done; ahc_unlock(ahc, &flags); printk("Recovery code sleeping\n"); if (!wait_for_completion_timeout(&done, 5 * HZ)) { ahc_lock(ahc, &flags); ahc->platform_data->eh_done = NULL; ahc_unlock(ahc, &flags); printk("Timer Expired\n"); retval = FAILED; } printk("Recovery code awake\n"); } else ahc_unlock(ahc, &flags); return (retval); } void ahc_platform_dump_card_state(struct ahc_softc *ahc) { } static void ahc_linux_set_width(struct scsi_target *starget, int width) { struct Scsi_Host *shost = dev_to_shost(starget->dev.parent); struct ahc_softc *ahc = *((struct ahc_softc **)shost->hostdata); struct ahc_devinfo devinfo; unsigned long flags; ahc_compile_devinfo(&devinfo, shost->this_id, starget->id, 0, starget->channel + 'A', ROLE_INITIATOR); ahc_lock(ahc, &flags); ahc_set_width(ahc, &devinfo, width, AHC_TRANS_GOAL, FALSE); ahc_unlock(ahc, &flags); } static void ahc_linux_set_period(struct scsi_target *starget, int period) { struct Scsi_Host *shost = dev_to_shost(starget->dev.parent); struct ahc_softc *ahc = *((struct ahc_softc **)shost->hostdata); struct ahc_tmode_tstate *tstate; struct ahc_initiator_tinfo *tinfo = ahc_fetch_transinfo(ahc, starget->channel + 'A', shost->this_id, starget->id, &tstate); struct ahc_devinfo devinfo; unsigned int ppr_options = tinfo->goal.ppr_options; unsigned long flags; unsigned long offset = tinfo->goal.offset; const struct ahc_syncrate *syncrate; if (offset == 0) offset = MAX_OFFSET; if (period < 9) period = 9; /* 12.5ns is our minimum */ if (period == 9) { if (spi_max_width(starget)) ppr_options |= MSG_EXT_PPR_DT_REQ; else /* need wide for DT and need DT for 12.5 ns */ period = 10; } ahc_compile_devinfo(&devinfo, shost->this_id, starget->id, 0, starget->channel + 'A', ROLE_INITIATOR); /* all PPR requests apart from QAS require wide transfers */ if (ppr_options & ~MSG_EXT_PPR_QAS_REQ) { if (spi_width(starget) == 0) ppr_options &= MSG_EXT_PPR_QAS_REQ; } syncrate = ahc_find_syncrate(ahc, &period, &ppr_options, AHC_SYNCRATE_DT); ahc_lock(ahc, &flags); ahc_set_syncrate(ahc, &devinfo, syncrate, period, offset, ppr_options, AHC_TRANS_GOAL, FALSE); ahc_unlock(ahc, &flags); } static void ahc_linux_set_offset(struct scsi_target *starget, int offset) { struct Scsi_Host *shost = dev_to_shost(starget->dev.parent); struct ahc_softc *ahc = *((struct ahc_softc **)shost->hostdata); struct ahc_tmode_tstate *tstate; struct ahc_initiator_tinfo *tinfo = ahc_fetch_transinfo(ahc, starget->channel + 'A', shost->this_id, starget->id, &tstate); struct ahc_devinfo devinfo; unsigned int ppr_options = 0; unsigned int period = 0; unsigned long flags; const struct ahc_syncrate *syncrate = NULL; ahc_compile_devinfo(&devinfo, shost->this_id, starget->id, 0, starget->channel + 'A', ROLE_INITIATOR); if (offset != 0) { syncrate = ahc_find_syncrate(ahc, &period, &ppr_options, AHC_SYNCRATE_DT); period = tinfo->goal.period; ppr_options = tinfo->goal.ppr_options; } ahc_lock(ahc, &flags); ahc_set_syncrate(ahc, &devinfo, syncrate, period, offset, ppr_options, AHC_TRANS_GOAL, FALSE); ahc_unlock(ahc, &flags); } static void ahc_linux_set_dt(struct scsi_target *starget, int dt) { struct Scsi_Host *shost = dev_to_shost(starget->dev.parent); struct ahc_softc *ahc = *((struct ahc_softc **)shost->hostdata); struct ahc_tmode_tstate *tstate; struct ahc_initiator_tinfo *tinfo = ahc_fetch_transinfo(ahc, starget->channel + 'A', shost->this_id, starget->id, &tstate); struct ahc_devinfo devinfo; unsigned int ppr_options = tinfo->goal.ppr_options & ~MSG_EXT_PPR_DT_REQ; unsigned int period = tinfo->goal.period; unsigned int width = tinfo->goal.width; unsigned long flags; const struct ahc_syncrate *syncrate; if (dt && spi_max_width(starget)) { ppr_options |= MSG_EXT_PPR_DT_REQ; if (!width) ahc_linux_set_width(starget, 1); } else if (period == 9) period = 10; /* if resetting DT, period must be >= 25ns */ ahc_compile_devinfo(&devinfo, shost->this_id, starget->id, 0, starget->channel + 'A', ROLE_INITIATOR); syncrate = ahc_find_syncrate(ahc, &period, &ppr_options,AHC_SYNCRATE_DT); ahc_lock(ahc, &flags); ahc_set_syncrate(ahc, &devinfo, syncrate, period, tinfo->goal.offset, ppr_options, AHC_TRANS_GOAL, FALSE); ahc_unlock(ahc, &flags); } #if 0 /* FIXME: This code claims to support IU and QAS. However, the actual * sequencer code and aic7xxx_core have no support for these parameters and * will get into a bad state if they're negotiated. Do not enable this * unless you know what you're doing */ static void ahc_linux_set_qas(struct scsi_target *starget, int qas) { struct Scsi_Host *shost = dev_to_shost(starget->dev.parent); struct ahc_softc *ahc = *((struct ahc_softc **)shost->hostdata); struct ahc_tmode_tstate *tstate; struct ahc_initiator_tinfo *tinfo = ahc_fetch_transinfo(ahc, starget->channel + 'A', shost->this_id, starget->id, &tstate); struct ahc_devinfo devinfo; unsigned int ppr_options = tinfo->goal.ppr_options & ~MSG_EXT_PPR_QAS_REQ; unsigned int period = tinfo->goal.period; unsigned long flags; struct ahc_syncrate *syncrate; if (qas) ppr_options |= MSG_EXT_PPR_QAS_REQ; ahc_compile_devinfo(&devinfo, shost->this_id, starget->id, 0, starget->channel + 'A', ROLE_INITIATOR); syncrate = ahc_find_syncrate(ahc, &period, &ppr_options, AHC_SYNCRATE_DT); ahc_lock(ahc, &flags); ahc_set_syncrate(ahc, &devinfo, syncrate, period, tinfo->goal.offset, ppr_options, AHC_TRANS_GOAL, FALSE); ahc_unlock(ahc, &flags); } static void ahc_linux_set_iu(struct scsi_target *starget, int iu) { struct Scsi_Host *shost = dev_to_shost(starget->dev.parent); struct ahc_softc *ahc = *((struct ahc_softc **)shost->hostdata); struct ahc_tmode_tstate *tstate; struct ahc_initiator_tinfo *tinfo = ahc_fetch_transinfo(ahc, starget->channel + 'A', shost->this_id, starget->id, &tstate); struct ahc_devinfo devinfo; unsigned int ppr_options = tinfo->goal.ppr_options & ~MSG_EXT_PPR_IU_REQ; unsigned int period = tinfo->goal.period; unsigned long flags; struct ahc_syncrate *syncrate; if (iu) ppr_options |= MSG_EXT_PPR_IU_REQ; ahc_compile_devinfo(&devinfo, shost->this_id, starget->id, 0, starget->channel + 'A', ROLE_INITIATOR); syncrate = ahc_find_syncrate(ahc, &period, &ppr_options, AHC_SYNCRATE_DT); ahc_lock(ahc, &flags); ahc_set_syncrate(ahc, &devinfo, syncrate, period, tinfo->goal.offset, ppr_options, AHC_TRANS_GOAL, FALSE); ahc_unlock(ahc, &flags); } #endif static void ahc_linux_get_signalling(struct Scsi_Host *shost) { struct ahc_softc *ahc = *(struct ahc_softc **)shost->hostdata; unsigned long flags; u8 mode; if (!(ahc->features & AHC_ULTRA2)) { /* non-LVD chipset, may not have SBLKCTL reg */ spi_signalling(shost) = ahc->features & AHC_HVD ? SPI_SIGNAL_HVD : SPI_SIGNAL_SE; return; } ahc_lock(ahc, &flags); ahc_pause(ahc); mode = ahc_inb(ahc, SBLKCTL); ahc_unpause(ahc); ahc_unlock(ahc, &flags); if (mode & ENAB40) spi_signalling(shost) = SPI_SIGNAL_LVD; else if (mode & ENAB20) spi_signalling(shost) = SPI_SIGNAL_SE; else spi_signalling(shost) = SPI_SIGNAL_UNKNOWN; } static struct spi_function_template ahc_linux_transport_functions = { .set_offset = ahc_linux_set_offset, .show_offset = 1, .set_period = ahc_linux_set_period, .show_period = 1, .set_width = ahc_linux_set_width, .show_width = 1, .set_dt = ahc_linux_set_dt, .show_dt = 1, #if 0 .set_iu = ahc_linux_set_iu, .show_iu = 1, .set_qas = ahc_linux_set_qas, .show_qas = 1, #endif .get_signalling = ahc_linux_get_signalling, }; static int __init ahc_linux_init(void) { /* * If we've been passed any parameters, process them now. */ if (aic7xxx) aic7xxx_setup(aic7xxx); ahc_linux_transport_template = spi_attach_transport(&ahc_linux_transport_functions); if (!ahc_linux_transport_template) return -ENODEV; scsi_transport_reserve_device(ahc_linux_transport_template, sizeof(struct ahc_linux_device)); ahc_linux_pci_init(); ahc_linux_eisa_init(); return 0; } static void ahc_linux_exit(void) { ahc_linux_pci_exit(); ahc_linux_eisa_exit(); spi_release_transport(ahc_linux_transport_template); } module_init(ahc_linux_init); module_exit(ahc_linux_exit);
gpl-2.0
BlackBox-Kernel/blackbox_sprout_kk
drivers/video/backlight/hp680_bl.c
8206
4190
/* * Backlight Driver for HP Jornada 680 * * Copyright (c) 2005 Andriy Skulysh * * Based on Sharp's Corgi Backlight Driver * * This file is subject to the terms and conditions of the GNU General Public * License. See the file "COPYING" in the main directory of this archive * for more details. */ #include <linux/module.h> #include <linux/kernel.h> #include <linux/init.h> #include <linux/platform_device.h> #include <linux/spinlock.h> #include <linux/fb.h> #include <linux/backlight.h> #include <cpu/dac.h> #include <mach/hp6xx.h> #include <asm/hd64461.h> #define HP680_MAX_INTENSITY 255 #define HP680_DEFAULT_INTENSITY 10 static int hp680bl_suspended; static int current_intensity = 0; static DEFINE_SPINLOCK(bl_lock); static void hp680bl_send_intensity(struct backlight_device *bd) { unsigned long flags; u16 v; int intensity = bd->props.brightness; if (bd->props.power != FB_BLANK_UNBLANK) intensity = 0; if (bd->props.fb_blank != FB_BLANK_UNBLANK) intensity = 0; if (hp680bl_suspended) intensity = 0; spin_lock_irqsave(&bl_lock, flags); if (intensity && current_intensity == 0) { sh_dac_enable(DAC_LCD_BRIGHTNESS); v = inw(HD64461_GPBDR); v &= ~HD64461_GPBDR_LCDOFF; outw(v, HD64461_GPBDR); sh_dac_output(255-(u8)intensity, DAC_LCD_BRIGHTNESS); } else if (intensity == 0 && current_intensity != 0) { sh_dac_output(255-(u8)intensity, DAC_LCD_BRIGHTNESS); sh_dac_disable(DAC_LCD_BRIGHTNESS); v = inw(HD64461_GPBDR); v |= HD64461_GPBDR_LCDOFF; outw(v, HD64461_GPBDR); } else if (intensity) { sh_dac_output(255-(u8)intensity, DAC_LCD_BRIGHTNESS); } spin_unlock_irqrestore(&bl_lock, flags); current_intensity = intensity; } #ifdef CONFIG_PM static int hp680bl_suspend(struct platform_device *pdev, pm_message_t state) { struct backlight_device *bd = platform_get_drvdata(pdev); hp680bl_suspended = 1; hp680bl_send_intensity(bd); return 0; } static int hp680bl_resume(struct platform_device *pdev) { struct backlight_device *bd = platform_get_drvdata(pdev); hp680bl_suspended = 0; hp680bl_send_intensity(bd); return 0; } #else #define hp680bl_suspend NULL #define hp680bl_resume NULL #endif static int hp680bl_set_intensity(struct backlight_device *bd) { hp680bl_send_intensity(bd); return 0; } static int hp680bl_get_intensity(struct backlight_device *bd) { return current_intensity; } static const struct backlight_ops hp680bl_ops = { .get_brightness = hp680bl_get_intensity, .update_status = hp680bl_set_intensity, }; static int __devinit hp680bl_probe(struct platform_device *pdev) { struct backlight_properties props; struct backlight_device *bd; memset(&props, 0, sizeof(struct backlight_properties)); props.type = BACKLIGHT_RAW; props.max_brightness = HP680_MAX_INTENSITY; bd = backlight_device_register("hp680-bl", &pdev->dev, NULL, &hp680bl_ops, &props); if (IS_ERR(bd)) return PTR_ERR(bd); platform_set_drvdata(pdev, bd); bd->props.brightness = HP680_DEFAULT_INTENSITY; hp680bl_send_intensity(bd); return 0; } static int hp680bl_remove(struct platform_device *pdev) { struct backlight_device *bd = platform_get_drvdata(pdev); bd->props.brightness = 0; bd->props.power = 0; hp680bl_send_intensity(bd); backlight_device_unregister(bd); return 0; } static struct platform_driver hp680bl_driver = { .probe = hp680bl_probe, .remove = hp680bl_remove, .suspend = hp680bl_suspend, .resume = hp680bl_resume, .driver = { .name = "hp680-bl", }, }; static struct platform_device *hp680bl_device; static int __init hp680bl_init(void) { int ret; ret = platform_driver_register(&hp680bl_driver); if (ret) return ret; hp680bl_device = platform_device_register_simple("hp680-bl", -1, NULL, 0); if (IS_ERR(hp680bl_device)) { platform_driver_unregister(&hp680bl_driver); return PTR_ERR(hp680bl_device); } return 0; } static void __exit hp680bl_exit(void) { platform_device_unregister(hp680bl_device); platform_driver_unregister(&hp680bl_driver); } module_init(hp680bl_init); module_exit(hp680bl_exit); MODULE_AUTHOR("Andriy Skulysh <askulysh@gmail.com>"); MODULE_DESCRIPTION("HP Jornada 680 Backlight Driver"); MODULE_LICENSE("GPL");
gpl-2.0
denggww123/IMX6_DB_Kernel_3.10.53
drivers/pcmcia/pxa2xx_mainstone.c
9742
4364
/* * linux/drivers/pcmcia/pxa2xx_mainstone.c * * Mainstone PCMCIA specific routines. * * Created: May 12, 2004 * Author: Nicolas Pitre * Copyright: MontaVista Software Inc. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 as * published by the Free Software Foundation. */ #include <linux/module.h> #include <linux/init.h> #include <linux/kernel.h> #include <linux/errno.h> #include <linux/interrupt.h> #include <linux/platform_device.h> #include <pcmcia/ss.h> #include <asm/mach-types.h> #include <asm/irq.h> #include <mach/pxa2xx-regs.h> #include <mach/mainstone.h> #include "soc_common.h" static int mst_pcmcia_hw_init(struct soc_pcmcia_socket *skt) { /* * Setup default state of GPIO outputs * before we enable them as outputs. */ if (skt->nr == 0) { skt->socket.pci_irq = MAINSTONE_S0_IRQ; skt->stat[SOC_STAT_CD].irq = MAINSTONE_S0_CD_IRQ; skt->stat[SOC_STAT_CD].name = "PCMCIA0 CD"; skt->stat[SOC_STAT_BVD1].irq = MAINSTONE_S0_STSCHG_IRQ; skt->stat[SOC_STAT_BVD1].name = "PCMCIA0 STSCHG"; } else { skt->socket.pci_irq = MAINSTONE_S1_IRQ; skt->stat[SOC_STAT_CD].irq = MAINSTONE_S1_CD_IRQ; skt->stat[SOC_STAT_CD].name = "PCMCIA1 CD"; skt->stat[SOC_STAT_BVD1].irq = MAINSTONE_S1_STSCHG_IRQ; skt->stat[SOC_STAT_BVD1].name = "PCMCIA1 STSCHG"; } return 0; } static unsigned long mst_pcmcia_status[2]; static void mst_pcmcia_socket_state(struct soc_pcmcia_socket *skt, struct pcmcia_state *state) { unsigned long status, flip; status = (skt->nr == 0) ? MST_PCMCIA0 : MST_PCMCIA1; flip = (status ^ mst_pcmcia_status[skt->nr]) & MST_PCMCIA_nSTSCHG_BVD1; /* * Workaround for STSCHG which can't be deasserted: * We therefore disable/enable corresponding IRQs * as needed to avoid IRQ locks. */ if (flip) { mst_pcmcia_status[skt->nr] = status; if (status & MST_PCMCIA_nSTSCHG_BVD1) enable_irq( (skt->nr == 0) ? MAINSTONE_S0_STSCHG_IRQ : MAINSTONE_S1_STSCHG_IRQ ); else disable_irq( (skt->nr == 0) ? MAINSTONE_S0_STSCHG_IRQ : MAINSTONE_S1_STSCHG_IRQ ); } state->detect = (status & MST_PCMCIA_nCD) ? 0 : 1; state->ready = (status & MST_PCMCIA_nIRQ) ? 1 : 0; state->bvd1 = (status & MST_PCMCIA_nSTSCHG_BVD1) ? 1 : 0; state->bvd2 = (status & MST_PCMCIA_nSPKR_BVD2) ? 1 : 0; state->vs_3v = (status & MST_PCMCIA_nVS1) ? 0 : 1; state->vs_Xv = (status & MST_PCMCIA_nVS2) ? 0 : 1; } static int mst_pcmcia_configure_socket(struct soc_pcmcia_socket *skt, const socket_state_t *state) { unsigned long power = 0; int ret = 0; switch (state->Vcc) { case 0: power |= MST_PCMCIA_PWR_VCC_0; break; case 33: power |= MST_PCMCIA_PWR_VCC_33; break; case 50: power |= MST_PCMCIA_PWR_VCC_50; break; default: printk(KERN_ERR "%s(): bad Vcc %u\n", __func__, state->Vcc); ret = -1; } switch (state->Vpp) { case 0: power |= MST_PCMCIA_PWR_VPP_0; break; case 120: power |= MST_PCMCIA_PWR_VPP_120; break; default: if(state->Vpp == state->Vcc) { power |= MST_PCMCIA_PWR_VPP_VCC; } else { printk(KERN_ERR "%s(): bad Vpp %u\n", __func__, state->Vpp); ret = -1; } } if (state->flags & SS_RESET) power |= MST_PCMCIA_RESET; switch (skt->nr) { case 0: MST_PCMCIA0 = power; break; case 1: MST_PCMCIA1 = power; break; default: ret = -1; } return ret; } static struct pcmcia_low_level mst_pcmcia_ops __initdata = { .owner = THIS_MODULE, .hw_init = mst_pcmcia_hw_init, .socket_state = mst_pcmcia_socket_state, .configure_socket = mst_pcmcia_configure_socket, .nr = 2, }; static struct platform_device *mst_pcmcia_device; static int __init mst_pcmcia_init(void) { int ret; if (!machine_is_mainstone()) return -ENODEV; mst_pcmcia_device = platform_device_alloc("pxa2xx-pcmcia", -1); if (!mst_pcmcia_device) return -ENOMEM; ret = platform_device_add_data(mst_pcmcia_device, &mst_pcmcia_ops, sizeof(mst_pcmcia_ops)); if (ret == 0) ret = platform_device_add(mst_pcmcia_device); if (ret) platform_device_put(mst_pcmcia_device); return ret; } static void __exit mst_pcmcia_exit(void) { platform_device_unregister(mst_pcmcia_device); } fs_initcall(mst_pcmcia_init); module_exit(mst_pcmcia_exit); MODULE_LICENSE("GPL"); MODULE_ALIAS("platform:pxa2xx-pcmcia");
gpl-2.0
Honor8Dev/android_kernel_huawei_FRD-L04
drivers/net/wireless/libertas/ethtool.c
9742
3371
#include <linux/hardirq.h> #include <linux/netdevice.h> #include <linux/ethtool.h> #include <linux/delay.h> #include "decl.h" #include "cmd.h" #include "mesh.h" static void lbs_ethtool_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info) { struct lbs_private *priv = dev->ml_priv; snprintf(info->fw_version, sizeof(info->fw_version), "%u.%u.%u.p%u", priv->fwrelease >> 24 & 0xff, priv->fwrelease >> 16 & 0xff, priv->fwrelease >> 8 & 0xff, priv->fwrelease & 0xff); strlcpy(info->driver, "libertas", sizeof(info->driver)); strlcpy(info->version, lbs_driver_version, sizeof(info->version)); } /* * All 8388 parts have 16KiB EEPROM size at the time of writing. * In case that changes this needs fixing. */ #define LBS_EEPROM_LEN 16384 static int lbs_ethtool_get_eeprom_len(struct net_device *dev) { return LBS_EEPROM_LEN; } static int lbs_ethtool_get_eeprom(struct net_device *dev, struct ethtool_eeprom *eeprom, u8 * bytes) { struct lbs_private *priv = dev->ml_priv; struct cmd_ds_802_11_eeprom_access cmd; int ret; lbs_deb_enter(LBS_DEB_ETHTOOL); if (eeprom->offset + eeprom->len > LBS_EEPROM_LEN || eeprom->len > LBS_EEPROM_READ_LEN) { ret = -EINVAL; goto out; } cmd.hdr.size = cpu_to_le16(sizeof(struct cmd_ds_802_11_eeprom_access) - LBS_EEPROM_READ_LEN + eeprom->len); cmd.action = cpu_to_le16(CMD_ACT_GET); cmd.offset = cpu_to_le16(eeprom->offset); cmd.len = cpu_to_le16(eeprom->len); ret = lbs_cmd_with_response(priv, CMD_802_11_EEPROM_ACCESS, &cmd); if (!ret) memcpy(bytes, cmd.value, eeprom->len); out: lbs_deb_leave_args(LBS_DEB_ETHTOOL, "ret %d", ret); return ret; } static void lbs_ethtool_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol) { struct lbs_private *priv = dev->ml_priv; wol->supported = WAKE_UCAST|WAKE_MCAST|WAKE_BCAST|WAKE_PHY; if (priv->wol_criteria == EHS_REMOVE_WAKEUP) return; if (priv->wol_criteria & EHS_WAKE_ON_UNICAST_DATA) wol->wolopts |= WAKE_UCAST; if (priv->wol_criteria & EHS_WAKE_ON_MULTICAST_DATA) wol->wolopts |= WAKE_MCAST; if (priv->wol_criteria & EHS_WAKE_ON_BROADCAST_DATA) wol->wolopts |= WAKE_BCAST; if (priv->wol_criteria & EHS_WAKE_ON_MAC_EVENT) wol->wolopts |= WAKE_PHY; } static int lbs_ethtool_set_wol(struct net_device *dev, struct ethtool_wolinfo *wol) { struct lbs_private *priv = dev->ml_priv; if (wol->wolopts & ~(WAKE_UCAST|WAKE_MCAST|WAKE_BCAST|WAKE_PHY)) return -EOPNOTSUPP; priv->wol_criteria = 0; if (wol->wolopts & WAKE_UCAST) priv->wol_criteria |= EHS_WAKE_ON_UNICAST_DATA; if (wol->wolopts & WAKE_MCAST) priv->wol_criteria |= EHS_WAKE_ON_MULTICAST_DATA; if (wol->wolopts & WAKE_BCAST) priv->wol_criteria |= EHS_WAKE_ON_BROADCAST_DATA; if (wol->wolopts & WAKE_PHY) priv->wol_criteria |= EHS_WAKE_ON_MAC_EVENT; if (wol->wolopts == 0) priv->wol_criteria |= EHS_REMOVE_WAKEUP; return 0; } const struct ethtool_ops lbs_ethtool_ops = { .get_drvinfo = lbs_ethtool_get_drvinfo, .get_eeprom = lbs_ethtool_get_eeprom, .get_eeprom_len = lbs_ethtool_get_eeprom_len, #ifdef CONFIG_LIBERTAS_MESH .get_sset_count = lbs_mesh_ethtool_get_sset_count, .get_ethtool_stats = lbs_mesh_ethtool_get_stats, .get_strings = lbs_mesh_ethtool_get_strings, #endif .get_wol = lbs_ethtool_get_wol, .set_wol = lbs_ethtool_set_wol, };
gpl-2.0
alecuba16/android_kernel_iuni_msm8974
drivers/net/wireless/libertas/ethtool.c
9742
3371
#include <linux/hardirq.h> #include <linux/netdevice.h> #include <linux/ethtool.h> #include <linux/delay.h> #include "decl.h" #include "cmd.h" #include "mesh.h" static void lbs_ethtool_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info) { struct lbs_private *priv = dev->ml_priv; snprintf(info->fw_version, sizeof(info->fw_version), "%u.%u.%u.p%u", priv->fwrelease >> 24 & 0xff, priv->fwrelease >> 16 & 0xff, priv->fwrelease >> 8 & 0xff, priv->fwrelease & 0xff); strlcpy(info->driver, "libertas", sizeof(info->driver)); strlcpy(info->version, lbs_driver_version, sizeof(info->version)); } /* * All 8388 parts have 16KiB EEPROM size at the time of writing. * In case that changes this needs fixing. */ #define LBS_EEPROM_LEN 16384 static int lbs_ethtool_get_eeprom_len(struct net_device *dev) { return LBS_EEPROM_LEN; } static int lbs_ethtool_get_eeprom(struct net_device *dev, struct ethtool_eeprom *eeprom, u8 * bytes) { struct lbs_private *priv = dev->ml_priv; struct cmd_ds_802_11_eeprom_access cmd; int ret; lbs_deb_enter(LBS_DEB_ETHTOOL); if (eeprom->offset + eeprom->len > LBS_EEPROM_LEN || eeprom->len > LBS_EEPROM_READ_LEN) { ret = -EINVAL; goto out; } cmd.hdr.size = cpu_to_le16(sizeof(struct cmd_ds_802_11_eeprom_access) - LBS_EEPROM_READ_LEN + eeprom->len); cmd.action = cpu_to_le16(CMD_ACT_GET); cmd.offset = cpu_to_le16(eeprom->offset); cmd.len = cpu_to_le16(eeprom->len); ret = lbs_cmd_with_response(priv, CMD_802_11_EEPROM_ACCESS, &cmd); if (!ret) memcpy(bytes, cmd.value, eeprom->len); out: lbs_deb_leave_args(LBS_DEB_ETHTOOL, "ret %d", ret); return ret; } static void lbs_ethtool_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol) { struct lbs_private *priv = dev->ml_priv; wol->supported = WAKE_UCAST|WAKE_MCAST|WAKE_BCAST|WAKE_PHY; if (priv->wol_criteria == EHS_REMOVE_WAKEUP) return; if (priv->wol_criteria & EHS_WAKE_ON_UNICAST_DATA) wol->wolopts |= WAKE_UCAST; if (priv->wol_criteria & EHS_WAKE_ON_MULTICAST_DATA) wol->wolopts |= WAKE_MCAST; if (priv->wol_criteria & EHS_WAKE_ON_BROADCAST_DATA) wol->wolopts |= WAKE_BCAST; if (priv->wol_criteria & EHS_WAKE_ON_MAC_EVENT) wol->wolopts |= WAKE_PHY; } static int lbs_ethtool_set_wol(struct net_device *dev, struct ethtool_wolinfo *wol) { struct lbs_private *priv = dev->ml_priv; if (wol->wolopts & ~(WAKE_UCAST|WAKE_MCAST|WAKE_BCAST|WAKE_PHY)) return -EOPNOTSUPP; priv->wol_criteria = 0; if (wol->wolopts & WAKE_UCAST) priv->wol_criteria |= EHS_WAKE_ON_UNICAST_DATA; if (wol->wolopts & WAKE_MCAST) priv->wol_criteria |= EHS_WAKE_ON_MULTICAST_DATA; if (wol->wolopts & WAKE_BCAST) priv->wol_criteria |= EHS_WAKE_ON_BROADCAST_DATA; if (wol->wolopts & WAKE_PHY) priv->wol_criteria |= EHS_WAKE_ON_MAC_EVENT; if (wol->wolopts == 0) priv->wol_criteria |= EHS_REMOVE_WAKEUP; return 0; } const struct ethtool_ops lbs_ethtool_ops = { .get_drvinfo = lbs_ethtool_get_drvinfo, .get_eeprom = lbs_ethtool_get_eeprom, .get_eeprom_len = lbs_ethtool_get_eeprom_len, #ifdef CONFIG_LIBERTAS_MESH .get_sset_count = lbs_mesh_ethtool_get_sset_count, .get_ethtool_stats = lbs_mesh_ethtool_get_stats, .get_strings = lbs_mesh_ethtool_get_strings, #endif .get_wol = lbs_ethtool_get_wol, .set_wol = lbs_ethtool_set_wol, };
gpl-2.0
alexfeinman/nv-tegra-h2c
sound/core/seq/seq_prioq.c
12558
10997
/* * ALSA sequencer Priority Queue * Copyright (c) 1998-1999 by Frank van de Pol <fvdpol@coil.demon.nl> * * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ #include <linux/time.h> #include <linux/slab.h> #include <sound/core.h> #include "seq_timer.h" #include "seq_prioq.h" /* Implementation is a simple linked list for now... This priority queue orders the events on timestamp. For events with an equeal timestamp the queue behaves as a FIFO. * * +-------+ * Head --> | first | * +-------+ * |next * +-----v-+ * | | * +-------+ * | * +-----v-+ * | | * +-------+ * | * +-----v-+ * Tail --> | last | * +-------+ * */ /* create new prioq (constructor) */ struct snd_seq_prioq *snd_seq_prioq_new(void) { struct snd_seq_prioq *f; f = kzalloc(sizeof(*f), GFP_KERNEL); if (f == NULL) { snd_printd("oops: malloc failed for snd_seq_prioq_new()\n"); return NULL; } spin_lock_init(&f->lock); f->head = NULL; f->tail = NULL; f->cells = 0; return f; } /* delete prioq (destructor) */ void snd_seq_prioq_delete(struct snd_seq_prioq **fifo) { struct snd_seq_prioq *f = *fifo; *fifo = NULL; if (f == NULL) { snd_printd("oops: snd_seq_prioq_delete() called with NULL prioq\n"); return; } /* release resources...*/ /*....................*/ if (f->cells > 0) { /* drain prioQ */ while (f->cells > 0) snd_seq_cell_free(snd_seq_prioq_cell_out(f)); } kfree(f); } /* compare timestamp between events */ /* return 1 if a >= b; 0 */ static inline int compare_timestamp(struct snd_seq_event *a, struct snd_seq_event *b) { if ((a->flags & SNDRV_SEQ_TIME_STAMP_MASK) == SNDRV_SEQ_TIME_STAMP_TICK) { /* compare ticks */ return (snd_seq_compare_tick_time(&a->time.tick, &b->time.tick)); } else { /* compare real time */ return (snd_seq_compare_real_time(&a->time.time, &b->time.time)); } } /* compare timestamp between events */ /* return negative if a < b; * zero if a = b; * positive if a > b; */ static inline int compare_timestamp_rel(struct snd_seq_event *a, struct snd_seq_event *b) { if ((a->flags & SNDRV_SEQ_TIME_STAMP_MASK) == SNDRV_SEQ_TIME_STAMP_TICK) { /* compare ticks */ if (a->time.tick > b->time.tick) return 1; else if (a->time.tick == b->time.tick) return 0; else return -1; } else { /* compare real time */ if (a->time.time.tv_sec > b->time.time.tv_sec) return 1; else if (a->time.time.tv_sec == b->time.time.tv_sec) { if (a->time.time.tv_nsec > b->time.time.tv_nsec) return 1; else if (a->time.time.tv_nsec == b->time.time.tv_nsec) return 0; else return -1; } else return -1; } } /* enqueue cell to prioq */ int snd_seq_prioq_cell_in(struct snd_seq_prioq * f, struct snd_seq_event_cell * cell) { struct snd_seq_event_cell *cur, *prev; unsigned long flags; int count; int prior; if (snd_BUG_ON(!f || !cell)) return -EINVAL; /* check flags */ prior = (cell->event.flags & SNDRV_SEQ_PRIORITY_MASK); spin_lock_irqsave(&f->lock, flags); /* check if this element needs to inserted at the end (ie. ordered data is inserted) This will be very likeley if a sequencer application or midi file player is feeding us (sequential) data */ if (f->tail && !prior) { if (compare_timestamp(&cell->event, &f->tail->event)) { /* add new cell to tail of the fifo */ f->tail->next = cell; f->tail = cell; cell->next = NULL; f->cells++; spin_unlock_irqrestore(&f->lock, flags); return 0; } } /* traverse list of elements to find the place where the new cell is to be inserted... Note that this is a order n process ! */ prev = NULL; /* previous cell */ cur = f->head; /* cursor */ count = 10000; /* FIXME: enough big, isn't it? */ while (cur != NULL) { /* compare timestamps */ int rel = compare_timestamp_rel(&cell->event, &cur->event); if (rel < 0) /* new cell has earlier schedule time, */ break; else if (rel == 0 && prior) /* equal schedule time and prior to others */ break; /* new cell has equal or larger schedule time, */ /* move cursor to next cell */ prev = cur; cur = cur->next; if (! --count) { spin_unlock_irqrestore(&f->lock, flags); snd_printk(KERN_ERR "cannot find a pointer.. infinite loop?\n"); return -EINVAL; } } /* insert it before cursor */ if (prev != NULL) prev->next = cell; cell->next = cur; if (f->head == cur) /* this is the first cell, set head to it */ f->head = cell; if (cur == NULL) /* reached end of the list */ f->tail = cell; f->cells++; spin_unlock_irqrestore(&f->lock, flags); return 0; } /* dequeue cell from prioq */ struct snd_seq_event_cell *snd_seq_prioq_cell_out(struct snd_seq_prioq *f) { struct snd_seq_event_cell *cell; unsigned long flags; if (f == NULL) { snd_printd("oops: snd_seq_prioq_cell_in() called with NULL prioq\n"); return NULL; } spin_lock_irqsave(&f->lock, flags); cell = f->head; if (cell) { f->head = cell->next; /* reset tail if this was the last element */ if (f->tail == cell) f->tail = NULL; cell->next = NULL; f->cells--; } spin_unlock_irqrestore(&f->lock, flags); return cell; } /* return number of events available in prioq */ int snd_seq_prioq_avail(struct snd_seq_prioq * f) { if (f == NULL) { snd_printd("oops: snd_seq_prioq_cell_in() called with NULL prioq\n"); return 0; } return f->cells; } /* peek at cell at the head of the prioq */ struct snd_seq_event_cell *snd_seq_prioq_cell_peek(struct snd_seq_prioq * f) { if (f == NULL) { snd_printd("oops: snd_seq_prioq_cell_in() called with NULL prioq\n"); return NULL; } return f->head; } static inline int prioq_match(struct snd_seq_event_cell *cell, int client, int timestamp) { if (cell->event.source.client == client || cell->event.dest.client == client) return 1; if (!timestamp) return 0; switch (cell->event.flags & SNDRV_SEQ_TIME_STAMP_MASK) { case SNDRV_SEQ_TIME_STAMP_TICK: if (cell->event.time.tick) return 1; break; case SNDRV_SEQ_TIME_STAMP_REAL: if (cell->event.time.time.tv_sec || cell->event.time.time.tv_nsec) return 1; break; } return 0; } /* remove cells for left client */ void snd_seq_prioq_leave(struct snd_seq_prioq * f, int client, int timestamp) { register struct snd_seq_event_cell *cell, *next; unsigned long flags; struct snd_seq_event_cell *prev = NULL; struct snd_seq_event_cell *freefirst = NULL, *freeprev = NULL, *freenext; /* collect all removed cells */ spin_lock_irqsave(&f->lock, flags); cell = f->head; while (cell) { next = cell->next; if (prioq_match(cell, client, timestamp)) { /* remove cell from prioq */ if (cell == f->head) { f->head = cell->next; } else { prev->next = cell->next; } if (cell == f->tail) f->tail = cell->next; f->cells--; /* add cell to free list */ cell->next = NULL; if (freefirst == NULL) { freefirst = cell; } else { freeprev->next = cell; } freeprev = cell; } else { #if 0 printk(KERN_DEBUG "type = %i, source = %i, dest = %i, " "client = %i\n", cell->event.type, cell->event.source.client, cell->event.dest.client, client); #endif prev = cell; } cell = next; } spin_unlock_irqrestore(&f->lock, flags); /* remove selected cells */ while (freefirst) { freenext = freefirst->next; snd_seq_cell_free(freefirst); freefirst = freenext; } } static int prioq_remove_match(struct snd_seq_remove_events *info, struct snd_seq_event *ev) { int res; if (info->remove_mode & SNDRV_SEQ_REMOVE_DEST) { if (ev->dest.client != info->dest.client || ev->dest.port != info->dest.port) return 0; } if (info->remove_mode & SNDRV_SEQ_REMOVE_DEST_CHANNEL) { if (! snd_seq_ev_is_channel_type(ev)) return 0; /* data.note.channel and data.control.channel are identical */ if (ev->data.note.channel != info->channel) return 0; } if (info->remove_mode & SNDRV_SEQ_REMOVE_TIME_AFTER) { if (info->remove_mode & SNDRV_SEQ_REMOVE_TIME_TICK) res = snd_seq_compare_tick_time(&ev->time.tick, &info->time.tick); else res = snd_seq_compare_real_time(&ev->time.time, &info->time.time); if (!res) return 0; } if (info->remove_mode & SNDRV_SEQ_REMOVE_TIME_BEFORE) { if (info->remove_mode & SNDRV_SEQ_REMOVE_TIME_TICK) res = snd_seq_compare_tick_time(&ev->time.tick, &info->time.tick); else res = snd_seq_compare_real_time(&ev->time.time, &info->time.time); if (res) return 0; } if (info->remove_mode & SNDRV_SEQ_REMOVE_EVENT_TYPE) { if (ev->type != info->type) return 0; } if (info->remove_mode & SNDRV_SEQ_REMOVE_IGNORE_OFF) { /* Do not remove off events */ switch (ev->type) { case SNDRV_SEQ_EVENT_NOTEOFF: /* case SNDRV_SEQ_EVENT_SAMPLE_STOP: */ return 0; default: break; } } if (info->remove_mode & SNDRV_SEQ_REMOVE_TAG_MATCH) { if (info->tag != ev->tag) return 0; } return 1; } /* remove cells matching remove criteria */ void snd_seq_prioq_remove_events(struct snd_seq_prioq * f, int client, struct snd_seq_remove_events *info) { struct snd_seq_event_cell *cell, *next; unsigned long flags; struct snd_seq_event_cell *prev = NULL; struct snd_seq_event_cell *freefirst = NULL, *freeprev = NULL, *freenext; /* collect all removed cells */ spin_lock_irqsave(&f->lock, flags); cell = f->head; while (cell) { next = cell->next; if (cell->event.source.client == client && prioq_remove_match(info, &cell->event)) { /* remove cell from prioq */ if (cell == f->head) { f->head = cell->next; } else { prev->next = cell->next; } if (cell == f->tail) f->tail = cell->next; f->cells--; /* add cell to free list */ cell->next = NULL; if (freefirst == NULL) { freefirst = cell; } else { freeprev->next = cell; } freeprev = cell; } else { prev = cell; } cell = next; } spin_unlock_irqrestore(&f->lock, flags); /* remove selected cells */ while (freefirst) { freenext = freefirst->next; snd_seq_cell_free(freefirst); freefirst = freenext; } }
gpl-2.0
javelinanddart/android_kernel_caf_ville
net/bridge/netfilter/ebt_arp.c
13582
3671
/* * ebt_arp * * Authors: * Bart De Schuymer <bdschuym@pandora.be> * Tim Gardner <timg@tpi.com> * * April, 2002 * */ #include <linux/if_arp.h> #include <linux/if_ether.h> #include <linux/module.h> #include <linux/netfilter/x_tables.h> #include <linux/netfilter_bridge/ebtables.h> #include <linux/netfilter_bridge/ebt_arp.h> static bool ebt_arp_mt(const struct sk_buff *skb, struct xt_action_param *par) { const struct ebt_arp_info *info = par->matchinfo; const struct arphdr *ah; struct arphdr _arph; ah = skb_header_pointer(skb, 0, sizeof(_arph), &_arph); if (ah == NULL) return false; if (info->bitmask & EBT_ARP_OPCODE && FWINV(info->opcode != ah->ar_op, EBT_ARP_OPCODE)) return false; if (info->bitmask & EBT_ARP_HTYPE && FWINV(info->htype != ah->ar_hrd, EBT_ARP_HTYPE)) return false; if (info->bitmask & EBT_ARP_PTYPE && FWINV(info->ptype != ah->ar_pro, EBT_ARP_PTYPE)) return false; if (info->bitmask & (EBT_ARP_SRC_IP | EBT_ARP_DST_IP | EBT_ARP_GRAT)) { const __be32 *sap, *dap; __be32 saddr, daddr; if (ah->ar_pln != sizeof(__be32) || ah->ar_pro != htons(ETH_P_IP)) return false; sap = skb_header_pointer(skb, sizeof(struct arphdr) + ah->ar_hln, sizeof(saddr), &saddr); if (sap == NULL) return false; dap = skb_header_pointer(skb, sizeof(struct arphdr) + 2*ah->ar_hln+sizeof(saddr), sizeof(daddr), &daddr); if (dap == NULL) return false; if (info->bitmask & EBT_ARP_SRC_IP && FWINV(info->saddr != (*sap & info->smsk), EBT_ARP_SRC_IP)) return false; if (info->bitmask & EBT_ARP_DST_IP && FWINV(info->daddr != (*dap & info->dmsk), EBT_ARP_DST_IP)) return false; if (info->bitmask & EBT_ARP_GRAT && FWINV(*dap != *sap, EBT_ARP_GRAT)) return false; } if (info->bitmask & (EBT_ARP_SRC_MAC | EBT_ARP_DST_MAC)) { const unsigned char *mp; unsigned char _mac[ETH_ALEN]; uint8_t verdict, i; if (ah->ar_hln != ETH_ALEN || ah->ar_hrd != htons(ARPHRD_ETHER)) return false; if (info->bitmask & EBT_ARP_SRC_MAC) { mp = skb_header_pointer(skb, sizeof(struct arphdr), sizeof(_mac), &_mac); if (mp == NULL) return false; verdict = 0; for (i = 0; i < 6; i++) verdict |= (mp[i] ^ info->smaddr[i]) & info->smmsk[i]; if (FWINV(verdict != 0, EBT_ARP_SRC_MAC)) return false; } if (info->bitmask & EBT_ARP_DST_MAC) { mp = skb_header_pointer(skb, sizeof(struct arphdr) + ah->ar_hln + ah->ar_pln, sizeof(_mac), &_mac); if (mp == NULL) return false; verdict = 0; for (i = 0; i < 6; i++) verdict |= (mp[i] ^ info->dmaddr[i]) & info->dmmsk[i]; if (FWINV(verdict != 0, EBT_ARP_DST_MAC)) return false; } } return true; } static int ebt_arp_mt_check(const struct xt_mtchk_param *par) { const struct ebt_arp_info *info = par->matchinfo; const struct ebt_entry *e = par->entryinfo; if ((e->ethproto != htons(ETH_P_ARP) && e->ethproto != htons(ETH_P_RARP)) || e->invflags & EBT_IPROTO) return -EINVAL; if (info->bitmask & ~EBT_ARP_MASK || info->invflags & ~EBT_ARP_MASK) return -EINVAL; return 0; } static struct xt_match ebt_arp_mt_reg __read_mostly = { .name = "arp", .revision = 0, .family = NFPROTO_BRIDGE, .match = ebt_arp_mt, .checkentry = ebt_arp_mt_check, .matchsize = sizeof(struct ebt_arp_info), .me = THIS_MODULE, }; static int __init ebt_arp_init(void) { return xt_register_match(&ebt_arp_mt_reg); } static void __exit ebt_arp_fini(void) { xt_unregister_match(&ebt_arp_mt_reg); } module_init(ebt_arp_init); module_exit(ebt_arp_fini); MODULE_DESCRIPTION("Ebtables: ARP protocol packet match"); MODULE_LICENSE("GPL");
gpl-2.0
androidarmv6/android_kernel_samsung_bcm21553-common
drivers/staging/bcm21553/drivers/sound/brcm/alsa/brcm_alsa_pcm.c
15
34613
/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ /******************************************************************************************* Copyright 2010 Broadcom Corporation. All rights reserved. Unless you and Broadcom execute a separate written software license agreement governing use of this software, this software is licensed to you under the terms of the GNU General Public License version 2, available at http://www.gnu.org/copyleft/gpl.html (the "GPL"). Notwithstanding the above, under no circumstances may you combine this software in any way with any other Broadcom software provided under a license other than the GPL, without Broadcom's express prior written consent. *******************************************************************************************/ #include <linux/platform_device.h> #include <linux/init.h> #include <linux/jiffies.h> #include <linux/slab.h> #include <linux/time.h> #include <linux/wait.h> #include <linux/delay.h> #include <linux/moduleparam.h> #include <linux/sched.h> #include <sound/core.h> #include <sound/control.h> #include <sound/pcm_params.h> #include <sound/pcm.h> #include <sound/rawmidi.h> #include <sound/initval.h> #include <linux/broadcom/hw_cfg.h> #include "brcm_alsa.h" #include "audvoc_drv.h" #include "audvoc_consts.h" #include "audio_ipc_consts.h" #include "hal_audio.h" #include "hal_audio_access.h" #include <mach/reg_sys.h> #include "vpu.h" //int DbgLogRegs(); int audvoc_data_transfer(struct snd_pcm_substream * substream); long GetCtrlValue(int ctrlIndex); extern int SwitchCallingRate(void); typedef struct _TIDChanOfPlaybackDev { AudioClientID_en_t clientID; AUDIO_CHANNEL_t channel; BRCM_CTRL_ENU volctrl; UInt16 volume; }TIDChanOfPlaybackDev; #define SPECIAL_SPK_HEADSET_VOL 0xFFFF static TIDChanOfPlaybackDev sgTableIDChannelOfDev[] = { {AUDIO_ID_FOR_PCM, AUDIO_CHNL_SPEAKER, BRCM_CTL_Speaker_Playback_Volume},//spk normal {AUDIO_ID_FOR_PCM, AUDIO_CHNL_SPEAKER, BRCM_CTL_Speaker_Playback_Volume},//spk ringtone {AUDIO_ID_CALL, AUDIO_CHNL_SPEAKER, BRCM_CTL_Speaker_Playback_Volume}, //spk incall {AUDIO_ID_FOR_PCM, AUDIO_CHNL_EARPIECE, BRCM_CTL_Speaker_Playback_Volume},//earpiece normal {AUDIO_ID_FOR_PCM, AUDIO_CHNL_EARPIECE, BRCM_CTL_Speaker_Playback_Volume},//earpiece ringtone {AUDIO_ID_CALL, AUDIO_CHNL_EARPIECE, BRCM_CTL_Speaker_Playback_Volume}, //earpiece incall {AUDIO_ID_FOR_PCM, AUDIO_CHNL_HEADPHONE, BRCM_CTL_Speaker_Playback_Volume},//headset normal {AUDIO_ID_FOR_PCM, AUDIO_CHNL_HEADPHONE, BRCM_CTL_Speaker_Playback_Volume},//headset ringtone {AUDIO_ID_CALL, AUDIO_CHNL_HEADPHONE, BRCM_CTL_Speaker_Playback_Volume}, //headset incall {AUDIO_CHNL_BT_MONO, AUDIO_CHNL_BT_MONO, BRCM_CTL_BTHeadset_Volume},//bt headset normal {AUDIO_CHNL_BT_MONO, AUDIO_CHNL_BT_MONO, BRCM_CTL_BTHeadset_Ringtone_Volume},//bt headset ringtone {AUDIO_ID_CALL, AUDIO_CHNL_BT_MONO, BRCM_CTL_BTHeadset_Incall_Volume}, //bt headset incall {AUDIO_ID_FOR_PCM, AUDIO_CHNL_HEADPHONE, BRCM_CTL_Speaker_Playback_Volume, SPECIAL_SPK_HEADSET_VOL},//spk-headset normal {AUDIO_ID_FOR_PCM, AUDIO_CHNL_HEADPHONE, BRCM_CTL_Speaker_Playback_Volume, SPECIAL_SPK_HEADSET_VOL}//spk-headset ringtone }; #define NUM_PLAYBACK_SUBDEVICE (sizeof(sgTableIDChannelOfDev)/sizeof(sgTableIDChannelOfDev[0])) #define NUM_CAPTURE_SUBDEVICE 3 #define PCM_MAX__PLAYBACK_BUF_BYTES (60*1024) #define PCM_MIN_PERIOD_BYTES (12*1024) #define VPU_PCM_DATA_BLK_LENTH (320*2) #define PERIOD_CAPTURE_MAX_BYTES (VPU_PCM_DATA_BLK_LENTH*4) #define PCM_MAX_CAPTURE_BUF_BYTES (6*1024) //(8*1024) // = (8000*2) // one second data #define PCM_TOTAL_BUF_BYTES (PCM_MAX_CAPTURE_BUF_BYTES+PCM_MAX__PLAYBACK_BUF_BYTES) /* hardware definition */ static struct snd_pcm_hardware brcm_playback_hw = { .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED | SNDRV_PCM_INFO_BLOCK_TRANSFER | SNDRV_PCM_INFO_MMAP_VALID|SNDRV_PCM_INFO_PAUSE), .formats = SNDRV_PCM_FMTBIT_S16_LE, .rates = SNDRV_PCM_RATE_8000_48000, .rate_min = 8000, .rate_max = 48000, .channels_min = 1, .channels_max = 2, .buffer_bytes_max = PCM_MAX__PLAYBACK_BUF_BYTES, //shared memory buffer .period_bytes_min = PCM_MIN_PERIOD_BYTES, .period_bytes_max = PCM_MIN_PERIOD_BYTES, //half shared memory buffer .periods_min = 2, .periods_max = PCM_MAX__PLAYBACK_BUF_BYTES/PCM_MIN_PERIOD_BYTES, }; static struct snd_pcm_hardware brcm_capture_hw = { .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED | SNDRV_PCM_INFO_BLOCK_TRANSFER | SNDRV_PCM_INFO_MMAP_VALID), .formats = SNDRV_PCM_FMTBIT_S16_LE, .rates = SNDRV_PCM_RATE_8000, .rate_min = 8000, .rate_max = 8000, .channels_min = 1, .channels_max = 1, .buffer_bytes_max = PCM_MAX_CAPTURE_BUF_BYTES, // one second data .period_bytes_min = VPU_PCM_DATA_BLK_LENTH, // one AMR brocks (each is 4 AMR frames) for pingpong, each blocks is 80 ms, 8000*0.020*2=320 .period_bytes_max = PERIOD_CAPTURE_MAX_BYTES, //half buffer .periods_min = 2, .periods_max = PCM_MAX_CAPTURE_BUF_BYTES/VPU_PCM_DATA_BLK_LENTH, }; //++++++++++++++++++++++++++++++++++++++++++++++++++++++ //Function name: AudioHalInit //Description: // Init audio HAL // //------------------------------------------------------------- int AudioHalInit(void) { HAL_AUDIO_Init(NULL); return 0; } //++++++++++++++++++++++++++++++++++++++ //EnableVoiceCall4Dev // Enable voice path for the sub device // Return negative if error, zero otherwise //------------------------------------------- int EnableVoiceCall4Dev(int subdevice) { HAL_AUDIO_Control_Params_un_t audioControlParam; if(subdevice<0 || subdevice>=NUM_PLAYBACK_SUBDEVICE) { DEBUG("Invalid subdevice # %d\n", subdevice); return -1; } audioControlParam.param_pathCfg.outputChnl = sgTableIDChannelOfDev[subdevice].channel; audioControlParam.param_pathCfg.audioID = sgTableIDChannelOfDev[subdevice].clientID; audioControlParam.param_pathCfg.volumeLevel = GetCtrlValue(BRCM_CTL_EAR_Playback_Volume); if(AUDIO_ID_CALL == audioControlParam.param_pathCfg.audioID) { HAL_AUDIO_Ctrl( ACTION_AUD_EnablePath, &audioControlParam, NULL); if(0==SwitchCallingRate()) return 0; if(0==GetCtrlValue(BRCM_CTL_Mic_Capture_Mute)) HAL_AUDIO_Ctrl(ACTION_AUD_UnmuteMic, NULL, NULL); else HAL_AUDIO_Ctrl(ACTION_AUD_MuteMic, NULL, NULL); return 0; } return -2; } //++++++++++++++++++++++++++++++++++++++ //DisableVoiceCall4Dev // Disable voice path for the sub device // Return negative if error, zero otherwise //------------------------------------------- int DisableVoiceCall4Dev(int subdevice) { HAL_AUDIO_Control_Params_un_t audioControlParam; if(subdevice<0 || subdevice>=NUM_PLAYBACK_SUBDEVICE) { DEBUG("Invalid subdevice # %d\n", subdevice); return -1; } audioControlParam.param_pathCfg.outputChnl = sgTableIDChannelOfDev[subdevice].channel; audioControlParam.param_pathCfg.audioID = sgTableIDChannelOfDev[subdevice].clientID; if(AUDIO_ID_CALL == audioControlParam.param_pathCfg.audioID) { // DEBUG("DisableVoiceCall4Dev id %d channel %d\n", audioControlParam.param_pathCfg.audioID, audioControlParam.param_pathCfg.outputChnl); HAL_AUDIO_Ctrl( ACTION_AUD_DisablePath, &audioControlParam, NULL); return 0; } return -2; } //++++++++++++++++++++++++++++++++++++++ //EnableAudioPath4Dev // Enable audio path for the sub device // Return negative if error, zero otherwise //------------------------------------------- int EnableAudioPath4Dev(int subdevice) { HAL_AUDIO_Control_Params_un_t audioControlParam; if(subdevice<0 || subdevice>=NUM_PLAYBACK_SUBDEVICE) { DEBUG("Invalid subdevice # %d\n", subdevice); return -1; } audioControlParam.param_pathCfg.outputChnl = sgTableIDChannelOfDev[subdevice].channel; audioControlParam.param_pathCfg.audioID = sgTableIDChannelOfDev[subdevice].clientID; audioControlParam.param_pathCfg.volumeLevel = GetCtrlValue(sgTableIDChannelOfDev[subdevice].volctrl); if(AUDIO_ID_CALL == audioControlParam.param_pathCfg.audioID) audioControlParam.param_pathCfg.audioID = AUDIO_ID_FOR_PCM; //hal needs to distinguish mono and stereo for AUDIO_ID_WAVETONE_POLY to config chan correctly if(audioControlParam.param_pathCfg.audioID == AUDIO_ID_WAVETONE_POLY) { HAL_AUDIO_Param_CodecCfg_t codecCfg; codecCfg.audioID = AUDIO_ID_WAVETONE_POLY; codecCfg.monoStereo = TYPE_STEREO; HAL_AUDIO_Ctrl( ACTION_AUD_ConfigCodecParam, &codecCfg, NULL ); } DEBUG("EnableAudioPath4Dev channel=%d id=%d vol=%d\n", audioControlParam.param_pathCfg.outputChnl, audioControlParam.param_pathCfg.audioID, audioControlParam.param_pathCfg.volumeLevel); HAL_AUDIO_Ctrl( ACTION_AUD_EnablePath, &audioControlParam, NULL); if(SPECIAL_SPK_HEADSET_VOL == sgTableIDChannelOfDev[subdevice].volume) { audioControlParam.param_pathCfg.audioID = AUDIO_ID_USER_EXT_AMP; audioControlParam.param_pathCfg.outputChnl = AUDIO_CHNL_RESERVE; HAL_AUDIO_Ctrl( ACTION_AUD_SetVolumeWithPath, &audioControlParam, NULL); } return 0; } //++++++++++++++++++++++++++++++++++++++ //DisableAudioPath4Dev // Disable audio path for the sub device // Return negative if error, zero otherwise //------------------------------------------- int DisableAudioPath4Dev(int subdevice) { HAL_AUDIO_Control_Params_un_t audioControlParam; if(subdevice<0 || subdevice>=NUM_PLAYBACK_SUBDEVICE) { DEBUG("Invalid subdevice # %d\n", subdevice); return -1; } audioControlParam.param_pathCfg.outputChnl = sgTableIDChannelOfDev[subdevice].channel; audioControlParam.param_pathCfg.audioID = sgTableIDChannelOfDev[subdevice].clientID; // DEBUG("DisableAudioPath4Dev channel=%d id=%d vol=%d\n", audioControlParam.param_pathCfg.outputChnl, audioControlParam.param_pathCfg.audioID, audioControlParam.param_pathCfg.volumeLevel); if(AUDIO_ID_CALL == audioControlParam.param_pathCfg.audioID) audioControlParam.param_pathCfg.audioID = AUDIO_ID_FOR_PCM; HAL_AUDIO_Ctrl( ACTION_AUD_DisablePath, &audioControlParam, NULL); return 0; } //+++++++++++++++++++++++++++++++++++++++++++++++++++++ // // Function Name: PcmHwParams // // Description: Set hardware parameters // //------------------------------------------------------------ static int PcmHwParams( struct snd_pcm_substream * substream, struct snd_pcm_hw_params * hw_params ) { // DEBUG("\n %lx:hw_params %d\n",jiffies,(int)substream->stream); DEBUG("\t params_access=%d params_format=%d params_subformat=%d params_channels=%d params_rate=%d, buffer bytes=%d\n", params_access(hw_params), params_format(hw_params), params_subformat(hw_params), params_channels(hw_params), params_rate(hw_params), params_buffer_bytes(hw_params)); return snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params)); } //+++++++++++++++++++++++++++++++++++++++++++++++++++++ // // Function Name: PcmHwFree // // Description: Release hardware resource // //------------------------------------------------------------ static int PcmHwFree( struct snd_pcm_substream * substream ) { int res; brcm_alsa_chip_t *chip = snd_pcm_substream_chip(substream); DEBUG("\n %lx:hw_free - stream=%x\n",jiffies, substream); flush_workqueue(chip->pWorkqueue_PCM); snd_pcm_stream_lock_irq(substream); res = snd_pcm_lib_free_pages(substream); snd_pcm_stream_unlock_irq(substream); return res; } //+++++++++++++++++++++++++++++++++++++++++++++++++++++ // // Function Name: PcmPlaybackOpen // // Description: Open PCM playback device // //------------------------------------------------------------ static int PcmPlaybackOpen( struct snd_pcm_substream * substream ) { P_DEVICE_CHANNEL dev; brcm_alsa_chip_t *chip = snd_pcm_substream_chip(substream); struct snd_pcm_runtime *runtime = substream->runtime; int err=0; runtime->hw = brcm_playback_hw; chip->substream[0] = substream; // open low level device dev = audvoc_open (0, 0, 0); substream->runtime->private_data = dev; DEBUG("\n %lx:playback_open subdevice=%d PCM_TOTAL_BUF_BYTES=%d\n",jiffies, substream->number, PCM_TOTAL_BUF_BYTES); return err; } //+++++++++++++++++++++++++++++++++++++++++++++++++++++ // // Function Name: PcmPlaybackClose // // Description: Close PCM playback device // //------------------------------------------------------------ static int PcmPlaybackClose(struct snd_pcm_substream * substream) { brcm_alsa_chip_t *chip = snd_pcm_substream_chip(substream); DEBUG("\n %lx:playback_close subdevice=%d\n",jiffies, substream->number); DisableVoiceCall4Dev(substream->number); // close low level device snd_pcm_stream_lock_irq(substream); audvoc_close(substream); substream->runtime->private_data = NULL; snd_pcm_stream_unlock_irq(substream); chip->substream[0] = NULL; return 0; } //+++++++++++++++++++++++++++++++++++++++++++++++++++++ // // Function Name: PcmPlaybackPrepare // // Description: Prepare PCM playback device, next call is Trigger or Close // //------------------------------------------------------------ static int PcmPlaybackPrepare( struct snd_pcm_substream * substream ) { struct snd_pcm_runtime *runtime = substream->runtime; brcm_alsa_chip_t *chip = snd_pcm_substream_chip(substream); AUDVOC_CFG_INFO p_cfg; P_DEVICE_CHANNEL p_dev_channel = (P_DEVICE_CHANNEL) runtime->private_data; // DEBUG("\n%lx:playback_prepare rate=%d, format=%d, channels=%d subdevice=%d\n",jiffies, runtime->rate, runtime->format, runtime->channels, substream->number); DEBUG("\nplayback_prepare period=%d period_size=%d bufsize=%d threshold=%d\n", runtime->periods, frames_to_bytes(runtime, runtime->period_size), frames_to_bytes(runtime, runtime->buffer_size), runtime->stop_threshold); chip->rate[0] = runtime->rate; chip->buffer_bytes[0] = runtime->dma_bytes; chip->period_bytes[0] = frames_to_bytes(runtime, runtime->period_size); chip->pcm_ptr[0] = 0; chip->pcm_write_ptr[0] = 0; chip->pcm_read_ptr[0] = 0; chip->last_pcm_rdptr[0] = 0; p_cfg.channel = runtime->channels; p_cfg.sample_rate = runtime->rate; audvoc_configure_audio_controller(p_dev_channel,&p_cfg); audvoc_configure_channel(p_dev_channel); EnableVoiceCall4Dev(substream->number); // DEBUG("\n%lx:playback_prepare period bytes=%d, periods =%d, buffersize=%d\n",jiffies, g_brcm_alsa_chip->period_bytes[0], runtime->periods, runtime->dma_bytes); return 0; } #define INIT_PCM_WORDS (4*1024) //+++++++++++++++++++++++++++++++++++++++++++++++++++++ // // Function Name: InitPlayBackSharedmem // // Description: Setup shared memory address with playback channel structure // //------------------------------------------------------------ static int InitPlayBackSharedmem(struct snd_pcm_substream *substream) { struct snd_pcm_runtime *runtime = substream->runtime; P_DEVICE_CHANNEL p_dev_channel = (P_DEVICE_CHANNEL) runtime->private_data; memset(p_dev_channel->sink.dst, 0, 24*1024); *p_dev_channel->sink.head = INIT_PCM_WORDS; g_brcm_alsa_chip->pcm_ptr[0] += bytes_to_frames(runtime,INIT_PCM_WORDS*2); return *p_dev_channel->sink.head; } static int InsertZeroPlayBackSharedmem(struct snd_pcm_substream *substream, int words) { struct snd_pcm_runtime *runtime = substream->runtime; brcm_alsa_chip_t *pChip = snd_pcm_substream_chip(substream); UInt16 head; P_DEVICE_CHANNEL p_dev_channel = (P_DEVICE_CHANNEL) runtime->private_data; memset(p_dev_channel->sink.dst, 0, words*2); *p_dev_channel->sink.tail = 0; *p_dev_channel->sink.head = words; pChip->pcm_read_ptr[0] += bytes_to_frames(runtime, words*2); if(pChip->pcm_read_ptr[0]>runtime->boundary) pChip->pcm_read_ptr[0] -= runtime->boundary; DEBUG("InsertZeroPlayBackSharedmem words=%d\n", words); return *p_dev_channel->sink.head; } //+++++++++++++++++++++++++++++++++++++++++++++++++++++ // // Function Name: PcmPlaybackTrigger // // Description: Command handling function // //------------------------------------------------------------ static int PcmPlaybackTrigger( struct snd_pcm_substream * substream, int cmd ) { int ret = 0; brcm_alsa_chip_t *chip = snd_pcm_substream_chip(substream); // DEBUG("\n ALSA : PcmPlaybackTrigger \n"); DEBUG("\n %lx:playback_trigger cmd=%d untime->boundary=%d\n",jiffies,cmd, (int)substream->runtime->boundary ); switch (cmd) { case SNDRV_PCM_TRIGGER_START: /* do something to start the PCM engine */ { struct snd_pcm_runtime *runtime = substream->runtime; P_DEVICE_CHANNEL p_dev_channel = (P_DEVICE_CHANNEL) runtime->private_data; int words; InitPlayBackSharedmem(substream); words = audvoc_data_transfer(substream); DEBUG("\n %lx:words transfered%d\n",jiffies,words ); if(words==0) DEBUG("\n %lx:silence words transfered%d\n",jiffies,words ); //do not turn on audio path until it is started. enable audio path here EnableAudioPath4Dev(substream->number); if(*p_dev_channel->sink.head==*p_dev_channel->sink.tail) *p_dev_channel->sink.head = (*p_dev_channel->sink.head -1)%p_dev_channel->AUDIO_BUF_SIZE; ret = audvoc_start_player(substream, (12*1024 - frames_to_bytes(runtime, runtime->period_size)/2)); } break; case SNDRV_PCM_TRIGGER_STOP: /* do something to stop the PCM engine */ ret = audvoc_stop_player(substream); DisableAudioPath4Dev(substream->number); break; case SNDRV_PCM_TRIGGER_PAUSE_PUSH: DisableAudioPath4Dev(substream->number); break; case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: EnableAudioPath4Dev(substream->number); break; default: return -EINVAL; } return ret; } //+++++++++++++++++++++++++++++++++++++++++++++++++++++ // // Function Name: PcmPlaybackPointer // // Description: Get playback pointer in frames // //------------------------------------------------------------ static snd_pcm_uframes_t PcmPlaybackPointer(struct snd_pcm_substream * substream) { struct snd_pcm_runtime *runtime = substream->runtime; P_DEVICE_CHANNEL p_dev_channel = (P_DEVICE_CHANNEL) runtime->private_data; snd_pcm_uframes_t pos; int datasize = -*p_dev_channel->sink.tail + *p_dev_channel->sink.head + 1; if(datasize==1) DEBUG("\n %lx:Warning playback_pointer head==tail=%d\n",jiffies,(int)*p_dev_channel->sink.tail ); if(datasize < 0) datasize += p_dev_channel->AUDIO_BUF_SIZE; // pos = g_brcm_alsa_chip->pcm_read_ptr[0] + g_brcm_alsa_chip->pcm_ptr[0] - bytes_to_frames(runtime, datasize*2); pos = g_brcm_alsa_chip->pcm_read_ptr[0];// + g_brcm_alsa_chip->pcm_ptr[0]; // DEBUG("\n pos=%d(%d- %d) pcm_read_ptr=%d datasize=%d\n", pos, (pos % runtime->buffer_size), (pos-bytes_to_frames(runtime, datasize*2))%runtime->buffer_size, g_brcm_alsa_chip->pcm_read_ptr[0], bytes_to_frames(runtime, datasize*2)); if(pos<0) { //DEBUG("\n %lx:Error playback_pointer %d\n",jiffies,(int)wordPos); pos += runtime->buffer_size; } pos %= runtime->buffer_size; // DEBUG("PcmPlaybackPointer: hw_ptr=%d pcm_read_ptr=%d words appl_ptr=%d validPcmSize=%d buffersize=%d\n", runtime->status->hw_ptr, g_brcm_alsa_chip->pcm_read_ptr[0], (int)runtime->control->appl_ptr, // runtime->control->appl_ptr-g_brcm_alsa_chip->pcm_read_ptr[0], runtime->buffer_size); return pos; } //+++++++++++++++++++++++++++++++++++++++++++++++++++++ // // Function Name: GetPlaybackRenderPosition // // Description: // Get playback position. // Position = DataCopiedToSharedMem - DataRemainInSharedMem // //------------------------------------------------------------ snd_pcm_uframes_t GetPlaybackRenderPosition(struct snd_pcm_substream * substream) { struct snd_pcm_runtime *runtime; P_DEVICE_CHANNEL p_dev_channel; long pos =0; int datasize; if (!substream) return pos; if (!substream->runtime) return pos; snd_pcm_stream_lock_irq(substream); runtime = substream->runtime; if(runtime->status->state == SNDRV_PCM_STATE_RUNNING) { p_dev_channel = (P_DEVICE_CHANNEL) runtime->private_data; if(p_dev_channel) { datasize = -*p_dev_channel->sink.tail + *p_dev_channel->sink.head + 1; if(datasize < 0) datasize += p_dev_channel->AUDIO_BUF_SIZE; pos = g_brcm_alsa_chip->pcm_read_ptr[0] - bytes_to_frames(runtime, datasize*2); //+ g_brcm_alsa_chip->pcm_ptr[0] if(pos<0) pos = 0; } } snd_pcm_stream_unlock_irq(substream); // DEBUG("GetPlaybackRenderPosition %d\n", pos); return pos; } static unsigned int sgpcm_capture_period_bytes[]={VPU_PCM_DATA_BLK_LENTH, VPU_PCM_DATA_BLK_LENTH*2, VPU_PCM_DATA_BLK_LENTH*3, VPU_PCM_DATA_BLK_LENTH*4}; //bytes static struct snd_pcm_hw_constraint_list sgpcm_capture_period_bytes_constraints_list = { .count = ARRAY_SIZE(sgpcm_capture_period_bytes), .list = sgpcm_capture_period_bytes, .mask = 0, }; //+++++++++++++++++++++++++++++++++++++++++++++++++++++ // // Function Name: PcmCaptureOpen // // Description: Open PCM capure device // //------------------------------------------------------------ static int PcmCaptureOpen(struct snd_pcm_substream * substream) { brcm_alsa_chip_t *chip = snd_pcm_substream_chip(substream); struct snd_pcm_runtime *runtime = substream->runtime; int err=0; // DEBUG("\n ALSA : PcmCaptureOpen \n"); runtime->hw = brcm_capture_hw; chip->substream[1] = substream; err = snd_pcm_hw_constraint_list(runtime,0,SNDRV_PCM_HW_PARAM_PERIOD_BYTES, &sgpcm_capture_period_bytes_constraints_list); if (err<0) return err; DEBUG("\n %lx:capture_open subdevice=%d\n",jiffies, substream->number); return 0; } //+++++++++++++++++++++++++++++++++++++++++++++++++++++ // // Function Name: PcmCaptureClose // // Description: Close PCM capure device // //------------------------------------------------------------ static int PcmCaptureClose(struct snd_pcm_substream * substream) { brcm_alsa_chip_t *chip = snd_pcm_substream_chip(substream); chip->substream[1] = NULL; DEBUG("\n %lx:capture_close subdevice=%d\n",jiffies, substream->number); return 0; } //+++++++++++++++++++++++++++++++++++++++++++++++++++++ // // Function Name: PcmCapturePrepare // // Description: Prepare hardware to capture // //------------------------------------------------------------ static int PcmCapturePrepare(struct snd_pcm_substream * substream) { struct snd_pcm_runtime *runtime = substream->runtime; DEBUG("\n %lx:capture_prepare: subdevice=%d rate =%d format =%d channel=%d dma_area=0x%x dma_bytes=%d period_bytes=%d avail_min=%d periods=%d buffer_size=%d\n", jiffies, substream->number, runtime->rate, runtime->format, runtime->channels, (unsigned int)runtime->dma_area, runtime->dma_bytes, frames_to_bytes(runtime, runtime->period_size), frames_to_bytes(runtime, runtime->control->avail_min), runtime->periods, runtime->buffer_size); g_brcm_alsa_chip->rate[1] = runtime->rate; g_brcm_alsa_chip->buffer_bytes[1] = runtime->dma_bytes; g_brcm_alsa_chip->period_bytes[1] = frames_to_bytes(runtime, runtime->period_size); g_brcm_alsa_chip->pcm_read_ptr[1] = 0; g_brcm_alsa_chip->last_pcm_rdptr[1] = 0; return 0; } //+++++++++++++++++++++++++++++++++++++++++++++++++++++ // // Function Name: CBDumpFrames // // Description: Call back function to dump recrding frames // //------------------------------------------------------------ static Boolean CBDumpFrames( UInt8* pSrc, UInt32 nFrames ) { int dstIdx, elapsed; ssize_t bytes; unsigned char * pDstBuf; struct snd_pcm_substream *substream = g_brcm_alsa_chip->substream[1]; struct snd_pcm_runtime *runtime = substream->runtime; int split, bufSizeInbytes; int endSize = 0; if(substream==NULL) { DEBUG("\n %lx:Error CBDumpFrames called when sunstream is NULL\n",jiffies); return FALSE; } bytes = nFrames*320; //copy data dstIdx = g_brcm_alsa_chip->pcm_read_ptr[1]; dstIdx = frames_to_bytes(runtime, dstIdx%runtime->buffer_size); //in bytes pDstBuf = substream->runtime->dma_area; // DEBUG("\n %lx:CBDumpFrames appl_ptr=%d pSrc=0x%x, nFrames=%d pre_dstIdx=%d\n",jiffies, runtime->control->appl_ptr, (unsigned int)pSrc, (int)nFrames,dstIdx); bufSizeInbytes = frames_to_bytes(runtime, runtime->buffer_size); split = (dstIdx+bytes) - bufSizeInbytes; if( split > 0) { // DEBUG("\n Error:CBDumpFrames dstIdx+bytes>=buffer_size: %d+%d>=%d\n",dstIdx, bytes, frames_to_bytes(runtime, runtime->buffer_size)); // return FALSE; endSize = bufSizeInbytes - dstIdx; memcpy(pDstBuf+dstIdx, pSrc, endSize); dstIdx = 0; pSrc += endSize; } memcpy(pDstBuf+dstIdx, pSrc, bytes-endSize); g_brcm_alsa_chip->pcm_read_ptr[1] += bytes_to_frames(runtime, bytes); if(g_brcm_alsa_chip->pcm_read_ptr[1]>runtime->boundary) g_brcm_alsa_chip->pcm_read_ptr[1] -= runtime->boundary; elapsed = g_brcm_alsa_chip->pcm_read_ptr[1] - g_brcm_alsa_chip->last_pcm_rdptr[1]; if (elapsed <0) { elapsed += runtime->buffer_size; DEBUG("\n CBDumpFrames boundary met:ptr=%d, previous=%d\n",g_brcm_alsa_chip->pcm_read_ptr[1] , g_brcm_alsa_chip->last_pcm_rdptr[1]); } if( elapsed>= substream->runtime->period_size) { snd_pcm_period_elapsed(substream); g_brcm_alsa_chip->last_pcm_rdptr[1] = g_brcm_alsa_chip->pcm_read_ptr[1]; } // else // DEBUG("\n less than 1 period is transfered %d < %d\n", (int)(g_brcm_alsa_chip->pcm_read_ptr[1] - g_brcm_alsa_chip->last_pcm_rdptr[1]),(int)substream->runtime->period_size); return TRUE; } //+++++++++++++++++++++++++++++++++++++++++++++++++++++ // // Function Name: VPMCaptureStart // // Description: Start VPU capture // //----------------------------------------------------- int VPMCaptureStart(struct snd_pcm_substream * substream) { UInt32 ret; UInt8 vpuLink = 3;// 1 - Near, 2 - Far, 3 - Both VP_Speech_Mode_t vpuSpeechMode = VP_SPEECH_MODE_LINEAR_PCM; UInt32 nParam = 0; brcm_alsa_chip_t *chip = snd_pcm_substream_chip(substream); //Enable path for recording: AUDIO_MODE_RECORD { HAL_AUDIO_Control_Params_un_t audioControlParam; HAL_AUDIO_Get_Param_t getParam; //get presernt Audio channel and volume levels from HAL getParam.paramType = GET_AUDIO_CHNL; HAL_AUDIO_Ctrl( ACTION_AUD_GetParam, &getParam, NULL); audioControlParam.param_pathCfg.outputChnl= (AUDIO_CHANNEL_t) *(getParam.paramPtr); getParam.paramType = GET_AUDIO_VOLUMELEVEL; HAL_AUDIO_Ctrl( ACTION_AUD_GetParam, &getParam, NULL); audioControlParam.param_pathCfg.volumeLevel = (UInt16)*(getParam.paramPtr); //audioControlParam.param_pathCfg.volumeLevel = 40; //audioControlParam.param_pathCfg.outputChnl = AUDIO_CHNL_EARPIECE; if(substream->number == 2) //AUX, wired headset audioControlParam.param_pathCfg.outputChnl = AUDIO_CHNL_HEADPHONE; audioControlParam.param_pathCfg.audioID = AUDIO_ID_VPU_RECORD; HAL_AUDIO_Ctrl( ACTION_AUD_EnablePath, &audioControlParam, NULL); DEBUG("\n %lx:Enable path outputChnl=%d vol=%d \n",jiffies, audioControlParam.param_pathCfg.outputChnl, audioControlParam.param_pathCfg.volumeLevel ); } mdelay(100); // Sleep 100ms to make sure VPU stopped ret = VPU_StartRecordingMemo(CBDumpFrames, vpuSpeechMode, vpuLink, nParam); DEBUG("\n %lx:VPMCaptureStart\n",jiffies); return 0; } //+++++++++++++++++++++++++++++++++++++++++++++++++++++ // // Function Name: VPMCaptureStop // // Description: Start VPU capture // //------------------------------------------------------------ int VPMCaptureStop(struct snd_pcm_substream * substream) { brcm_alsa_chip_t *chip = snd_pcm_substream_chip(substream); VPU_StopMemo(); DEBUG("\n %lx:VPMCaptureStop: VPU_StopMemo\n",jiffies); //Disable path for recording { HAL_AUDIO_Control_Params_un_t audioControlParam; HAL_AUDIO_Get_Param_t getParam; //get presernt Audio channel and volume levels from HAL getParam.paramType = GET_AUDIO_CHNL; HAL_AUDIO_Ctrl( ACTION_AUD_GetParam, &getParam, NULL); audioControlParam.param_pathCfg.outputChnl= (AUDIO_CHANNEL_t) *(getParam.paramPtr); getParam.paramType = GET_AUDIO_VOLUMELEVEL; HAL_AUDIO_Ctrl( ACTION_AUD_GetParam, &getParam, NULL); audioControlParam.param_pathCfg.volumeLevel = (UInt16)*(getParam.paramPtr); //audioControlParam.param_pathCfg.volumeLevel = 30; //audioControlParam.param_pathCfg.outputChnl = AUDIO_CHNL_EARPIECE; if(substream->number == 2) //AUX, wired headset audioControlParam.param_pathCfg.outputChnl = AUDIO_CHNL_HEADPHONE; audioControlParam.param_pathCfg.audioID = AUDIO_ID_VPU_RECORD; HAL_AUDIO_Ctrl( ACTION_AUD_DisablePath, &audioControlParam, NULL); } DEBUG("\n %lx:VPMCaptureStop: ACTION_AUD_DisablePath\n",jiffies); return 0; } //+++++++++++++++++++++++++++++++++++++++++++++++++++++ // // Function Name: PcmCaptureTrigger // // Description: Command handling function // //------------------------------------------------------------ static int PcmCaptureTrigger( struct snd_pcm_substream * substream, //substream int cmd //commands to handle ) { DEBUG("\n %lx:capture_trigger subdevice=%d cmd=%d\n",jiffies,substream->number, cmd); switch (cmd) { case SNDRV_PCM_TRIGGER_START: /* do something to start the PCM engine */ VPMCaptureStart(substream); break; case SNDRV_PCM_TRIGGER_STOP: /* do something to stop the PCM engine */ VPMCaptureStop(substream); default: return -EINVAL; } return 0; } //+++++++++++++++++++++++++++++++++++++++++++++++++++++ // // Function Name: PcmCapturePointer // // Description: Get capture pointer // //------------------------------------------------------------ static snd_pcm_uframes_t PcmCapturePointer(struct snd_pcm_substream * substream) { struct snd_pcm_runtime *runtime = substream->runtime; snd_pcm_uframes_t pos; pos = (g_brcm_alsa_chip->pcm_read_ptr[1]% runtime->buffer_size); // DEBUG("\n %lx:PcmCapturePointer pos=%d\n",jiffies,pos); return pos; } int PcmPlaybackAck(struct snd_pcm_substream *substream) { P_DEVICE_CHANNEL pDev; pDev = (P_DEVICE_CHANNEL)substream->runtime->private_data; if(pDev->devStatus & 2) { brcm_alsa_chip_t *chip = snd_pcm_substream_chip(substream); queue_work(chip->pWorkqueue_PCM, &chip->work); DEBUG("\nschedule additional job\n"); } return 0; } //Playback device operator static struct snd_pcm_ops brcm_alsa_omx_pcm_playback_ops = { .open = PcmPlaybackOpen, .close = PcmPlaybackClose, .ioctl = snd_pcm_lib_ioctl, .hw_params = PcmHwParams, .hw_free = PcmHwFree, .prepare = PcmPlaybackPrepare, .trigger = PcmPlaybackTrigger, .pointer = PcmPlaybackPointer, .ack = PcmPlaybackAck, }; //Capture device operator static struct snd_pcm_ops brcm_alsa_omx_pcm_capture_ops = { .open = PcmCaptureOpen, .close = PcmCaptureClose, .ioctl = snd_pcm_lib_ioctl, .hw_params = PcmHwParams, .hw_free = PcmHwFree, .prepare = PcmCapturePrepare, .trigger = PcmCaptureTrigger, .pointer = PcmCapturePointer, }; //+++++++++++++++++++++++++++++++++++++++++++++++++++++ // // Function Name: worker_pcm // // Description: Playback worker thread to copy data // //------------------------------------------------------------ static void worker_pcm(struct work_struct *work) { brcm_alsa_chip_t *pChip = container_of(work, brcm_alsa_chip_t, work); struct snd_pcm_substream * substream; int words; P_DEVICE_CHANNEL pDev; int err = 0; if(pChip==NULL) { DEBUG("worker_pcm:unlikely to happen pChip==NULL \n"); return ; } substream = pChip->substream[0]; // If the DSP INT arrives when we have excuted PcmHWFree but yet to execute PcmPlaybackClose we will not have valid dma_area pointer. if(substream==NULL || substream->runtime->dma_area == NULL ) return ; snd_pcm_stream_lock_irq(substream); if (PCM_RUNTIME_CHECK(substream)) err = -1; //error sub stream else { pDev = (P_DEVICE_CHANNEL)substream->runtime->private_data; words = audvoc_data_transfer(substream); } snd_pcm_stream_unlock_irq(substream); if(err) return; // if((words>0) && (pDev->devStatus & 2)) if((pDev->devStatus & 2)) { if(words<=0) { int wlength=256; InsertZeroPlayBackSharedmem(substream, wlength); //insert silence to keep it running // g_brcm_alsa_chip->pcm_ptr[0] += wlength; } pDev->devStatus &= ~2; post_msg(COMMAND_AUDIO_TASK_START_REQUEST,0,0,0); // DEBUG("COMMAND_AUDIO_TASK_START_REQUEST\n"); } if( (pChip->pcm_read_ptr[0] - pChip->last_pcm_rdptr[0])>= substream->runtime->period_size) { snd_pcm_period_elapsed(substream); pChip->last_pcm_rdptr[0] = pChip->pcm_read_ptr[0]; pDev->devStatus &= ~3; } else { if(pDev->devStatus & 1) //underrun snd_pcm_period_elapsed(substream); pDev->devStatus |= 1; // DEBUG("\n less than 1 period is transfered %d < %d\n", (int)(pChip->pcm_read_ptr[0] - pChip->last_pcm_rdptr[0]),(int)substream->runtime->period_size); } } //+++++++++++++++++++++++++++++++++++++++++++++++++++++ // // Function Name: PcmDeviceNew // // Description: Create PCM playback and capture device // //------------------------------------------------------------ int __devinit PcmDeviceNew(struct snd_card *card) { struct snd_pcm *pcm; int err = 0; brcm_alsa_chip_t *pChip; err = snd_pcm_new(card, "Broadcom ALSA PCM", 0, NUM_PLAYBACK_SUBDEVICE, NUM_CAPTURE_SUBDEVICE, &pcm); if (err<0) return err; pcm->private_data = card->private_data; strcpy(pcm->name, "Broadcom ALSA PCM"); snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &brcm_alsa_omx_pcm_playback_ops); snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &brcm_alsa_omx_pcm_capture_ops); pcm->info_flags = 0; err=snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_CONTINUOUS, snd_dma_continuous_data(GFP_KERNEL), PCM_TOTAL_BUF_BYTES, PCM_TOTAL_BUF_BYTES); pChip = (brcm_alsa_chip_t *)card->private_data; INIT_WORK(&pChip->work, worker_pcm); if(err) DEBUG("\n Error : PcmDeviceNew err=%d\n",err); pChip->pWorkqueue_PCM = create_workqueue("BrcmPcmWq"); if(!pChip->pWorkqueue_PCM) DEBUG("\n Error : Can not create work queue:BrcmPcmWq\n"); DEBUG("\n PcmDeviceNew : PcmDeviceNew err=%d\n",err); return err; }
gpl-2.0
munjeni/stock_jb_kexec_kernel_for_locked_bootloader
drivers/mmc/core/mmc.c
15
39790
/* * linux/drivers/mmc/core/mmc.c * * Copyright (C) 2003-2004 Russell King, All Rights Reserved. * Copyright (C) 2005-2007 Pierre Ossman, All Rights Reserved. * MMCv4 support Copyright (C) 2006 Philip Langdale, All Rights Reserved. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 as * published by the Free Software Foundation. */ #include <linux/err.h> #include <linux/slab.h> #include <linux/mmc/host.h> #include <linux/mmc/card.h> #include <linux/mmc/mmc.h> #include "core.h" #include "bus.h" #include "mmc_ops.h" #include "sd_ops.h" static const unsigned int tran_exp[] = { 10000, 100000, 1000000, 10000000, 0, 0, 0, 0 }; static const unsigned char tran_mant[] = { 0, 10, 12, 13, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 70, 80, }; static const unsigned int tacc_exp[] = { 1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, }; static const unsigned int tacc_mant[] = { 0, 10, 12, 13, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 70, 80, }; #define UNSTUFF_BITS(resp,start,size) \ ({ \ const int __size = size; \ const u32 __mask = (__size < 32 ? 1 << __size : 0) - 1; \ const int __off = 3 - ((start) / 32); \ const int __shft = (start) & 31; \ u32 __res; \ \ __res = resp[__off] >> __shft; \ if (__size + __shft > 32) \ __res |= resp[__off-1] << ((32 - __shft) % 32); \ __res & __mask; \ }) /* * Given the decoded CSD structure, decode the raw CID to our CID structure. */ static int mmc_decode_cid(struct mmc_card *card) { u32 *resp = card->raw_cid; /* * The selection of the format here is based upon published * specs from sandisk and from what people have reported. */ switch (card->csd.mmca_vsn) { case 0: /* MMC v1.0 - v1.2 */ case 1: /* MMC v1.4 */ card->cid.manfid = UNSTUFF_BITS(resp, 104, 24); card->cid.prod_name[0] = UNSTUFF_BITS(resp, 96, 8); card->cid.prod_name[1] = UNSTUFF_BITS(resp, 88, 8); card->cid.prod_name[2] = UNSTUFF_BITS(resp, 80, 8); card->cid.prod_name[3] = UNSTUFF_BITS(resp, 72, 8); card->cid.prod_name[4] = UNSTUFF_BITS(resp, 64, 8); card->cid.prod_name[5] = UNSTUFF_BITS(resp, 56, 8); card->cid.prod_name[6] = UNSTUFF_BITS(resp, 48, 8); card->cid.hwrev = UNSTUFF_BITS(resp, 44, 4); card->cid.fwrev = UNSTUFF_BITS(resp, 40, 4); card->cid.serial = UNSTUFF_BITS(resp, 16, 24); card->cid.month = UNSTUFF_BITS(resp, 12, 4); card->cid.year = UNSTUFF_BITS(resp, 8, 4) + 1997; break; case 2: /* MMC v2.0 - v2.2 */ case 3: /* MMC v3.1 - v3.3 */ case 4: /* MMC v4 */ card->cid.manfid = UNSTUFF_BITS(resp, 120, 8); card->cid.oemid = UNSTUFF_BITS(resp, 104, 16); card->cid.prod_name[0] = UNSTUFF_BITS(resp, 96, 8); card->cid.prod_name[1] = UNSTUFF_BITS(resp, 88, 8); card->cid.prod_name[2] = UNSTUFF_BITS(resp, 80, 8); card->cid.prod_name[3] = UNSTUFF_BITS(resp, 72, 8); card->cid.prod_name[4] = UNSTUFF_BITS(resp, 64, 8); card->cid.prod_name[5] = UNSTUFF_BITS(resp, 56, 8); card->cid.serial = UNSTUFF_BITS(resp, 16, 32); card->cid.month = UNSTUFF_BITS(resp, 12, 4); card->cid.year = UNSTUFF_BITS(resp, 8, 4) + 1997; break; default: pr_err("%s: card has unknown MMCA version %d\n", mmc_hostname(card->host), card->csd.mmca_vsn); return -EINVAL; } return 0; } static void mmc_set_erase_size(struct mmc_card *card) { if (card->ext_csd.erase_group_def & 1) card->erase_size = card->ext_csd.hc_erase_size; else card->erase_size = card->csd.erase_size; mmc_init_erase(card); } /* * Given a 128-bit response, decode to our card CSD structure. */ static int mmc_decode_csd(struct mmc_card *card) { struct mmc_csd *csd = &card->csd; unsigned int e, m, a, b; u32 *resp = card->raw_csd; /* * We only understand CSD structure v1.1 and v1.2. * v1.2 has extra information in bits 15, 11 and 10. * We also support eMMC v4.4 & v4.41. */ csd->structure = UNSTUFF_BITS(resp, 126, 2); if (csd->structure == 0) { pr_err("%s: unrecognised CSD structure version %d\n", mmc_hostname(card->host), csd->structure); return -EINVAL; } csd->mmca_vsn = UNSTUFF_BITS(resp, 122, 4); m = UNSTUFF_BITS(resp, 115, 4); e = UNSTUFF_BITS(resp, 112, 3); csd->tacc_ns = (tacc_exp[e] * tacc_mant[m] + 9) / 10; csd->tacc_clks = UNSTUFF_BITS(resp, 104, 8) * 100; m = UNSTUFF_BITS(resp, 99, 4); e = UNSTUFF_BITS(resp, 96, 3); csd->max_dtr = tran_exp[e] * tran_mant[m]; csd->cmdclass = UNSTUFF_BITS(resp, 84, 12); e = UNSTUFF_BITS(resp, 47, 3); m = UNSTUFF_BITS(resp, 62, 12); csd->capacity = (1 + m) << (e + 2); csd->read_blkbits = UNSTUFF_BITS(resp, 80, 4); csd->read_partial = UNSTUFF_BITS(resp, 79, 1); csd->write_misalign = UNSTUFF_BITS(resp, 78, 1); csd->read_misalign = UNSTUFF_BITS(resp, 77, 1); csd->r2w_factor = UNSTUFF_BITS(resp, 26, 3); csd->write_blkbits = UNSTUFF_BITS(resp, 22, 4); csd->write_partial = UNSTUFF_BITS(resp, 21, 1); if (csd->write_blkbits >= 9) { a = UNSTUFF_BITS(resp, 42, 5); b = UNSTUFF_BITS(resp, 37, 5); csd->erase_size = (a + 1) * (b + 1); csd->erase_size <<= csd->write_blkbits - 9; } return 0; } /* * Read extended CSD. */ static int mmc_get_ext_csd(struct mmc_card *card, u8 **new_ext_csd) { int err; u8 *ext_csd; BUG_ON(!card); BUG_ON(!new_ext_csd); *new_ext_csd = NULL; if (card->csd.mmca_vsn < CSD_SPEC_VER_4) return 0; /* * As the ext_csd is so large and mostly unused, we don't store the * raw block in mmc_card. */ ext_csd = kmalloc(512, GFP_KERNEL); if (!ext_csd) { pr_err("%s: could not allocate a buffer to " "receive the ext_csd.\n", mmc_hostname(card->host)); return -ENOMEM; } err = mmc_send_ext_csd(card, ext_csd); if (err) { kfree(ext_csd); *new_ext_csd = NULL; /* If the host or the card can't do the switch, * fail more gracefully. */ if ((err != -EINVAL) && (err != -ENOSYS) && (err != -EFAULT)) return err; /* * High capacity cards should have this "magic" size * stored in their CSD. */ if (card->csd.capacity == (4096 * 512)) { pr_err("%s: unable to read EXT_CSD " "on a possible high capacity card. " "Card will be ignored.\n", mmc_hostname(card->host)); } else { pr_warning("%s: unable to read " "EXT_CSD, performance might " "suffer.\n", mmc_hostname(card->host)); err = 0; } } else *new_ext_csd = ext_csd; return err; } /* * Decode extended CSD. */ static int mmc_read_ext_csd(struct mmc_card *card, u8 *ext_csd) { int err = 0, idx; unsigned int part_size; u8 hc_erase_grp_sz = 0, hc_wp_grp_sz = 0; BUG_ON(!card); if (!ext_csd) return 0; /* Version is coded in the CSD_STRUCTURE byte in the EXT_CSD register */ card->ext_csd.raw_ext_csd_structure = ext_csd[EXT_CSD_STRUCTURE]; if (card->csd.structure == 3) { if (card->ext_csd.raw_ext_csd_structure > 2) { pr_err("%s: unrecognised EXT_CSD structure " "version %d\n", mmc_hostname(card->host), card->ext_csd.raw_ext_csd_structure); err = -EINVAL; goto out; } } card->ext_csd.rev = ext_csd[EXT_CSD_REV]; if (card->ext_csd.rev > 6) { pr_err("%s: unrecognised EXT_CSD revision %d\n", mmc_hostname(card->host), card->ext_csd.rev); err = -EINVAL; goto out; } card->ext_csd.raw_sectors[0] = ext_csd[EXT_CSD_SEC_CNT + 0]; card->ext_csd.raw_sectors[1] = ext_csd[EXT_CSD_SEC_CNT + 1]; card->ext_csd.raw_sectors[2] = ext_csd[EXT_CSD_SEC_CNT + 2]; card->ext_csd.raw_sectors[3] = ext_csd[EXT_CSD_SEC_CNT + 3]; if (card->ext_csd.rev >= 2) { card->ext_csd.sectors = ext_csd[EXT_CSD_SEC_CNT + 0] << 0 | ext_csd[EXT_CSD_SEC_CNT + 1] << 8 | ext_csd[EXT_CSD_SEC_CNT + 2] << 16 | ext_csd[EXT_CSD_SEC_CNT + 3] << 24; /* Cards with density > 2GiB are sector addressed */ if (card->ext_csd.sectors > (2u * 1024 * 1024 * 1024) / 512) mmc_card_set_blockaddr(card); } card->ext_csd.raw_card_type = ext_csd[EXT_CSD_CARD_TYPE]; switch (ext_csd[EXT_CSD_CARD_TYPE] & EXT_CSD_CARD_TYPE_MASK) { case EXT_CSD_CARD_TYPE_SDR_ALL: case EXT_CSD_CARD_TYPE_SDR_ALL_DDR_1_8V: case EXT_CSD_CARD_TYPE_SDR_ALL_DDR_1_2V: case EXT_CSD_CARD_TYPE_SDR_ALL_DDR_52: card->ext_csd.hs_max_dtr = 200000000; card->ext_csd.card_type = EXT_CSD_CARD_TYPE_SDR_200; break; case EXT_CSD_CARD_TYPE_SDR_1_2V_ALL: case EXT_CSD_CARD_TYPE_SDR_1_2V_DDR_1_8V: case EXT_CSD_CARD_TYPE_SDR_1_2V_DDR_1_2V: case EXT_CSD_CARD_TYPE_SDR_1_2V_DDR_52: card->ext_csd.hs_max_dtr = 200000000; card->ext_csd.card_type = EXT_CSD_CARD_TYPE_SDR_1_2V; break; case EXT_CSD_CARD_TYPE_SDR_1_8V_ALL: case EXT_CSD_CARD_TYPE_SDR_1_8V_DDR_1_8V: case EXT_CSD_CARD_TYPE_SDR_1_8V_DDR_1_2V: case EXT_CSD_CARD_TYPE_SDR_1_8V_DDR_52: card->ext_csd.hs_max_dtr = 200000000; card->ext_csd.card_type = EXT_CSD_CARD_TYPE_SDR_1_8V; break; case EXT_CSD_CARD_TYPE_DDR_52 | EXT_CSD_CARD_TYPE_52 | EXT_CSD_CARD_TYPE_26: card->ext_csd.hs_max_dtr = 52000000; card->ext_csd.card_type = EXT_CSD_CARD_TYPE_DDR_52; break; case EXT_CSD_CARD_TYPE_DDR_1_2V | EXT_CSD_CARD_TYPE_52 | EXT_CSD_CARD_TYPE_26: card->ext_csd.hs_max_dtr = 52000000; card->ext_csd.card_type = EXT_CSD_CARD_TYPE_DDR_1_2V; break; case EXT_CSD_CARD_TYPE_DDR_1_8V | EXT_CSD_CARD_TYPE_52 | EXT_CSD_CARD_TYPE_26: card->ext_csd.hs_max_dtr = 52000000; card->ext_csd.card_type = EXT_CSD_CARD_TYPE_DDR_1_8V; break; case EXT_CSD_CARD_TYPE_52 | EXT_CSD_CARD_TYPE_26: card->ext_csd.hs_max_dtr = 52000000; break; case EXT_CSD_CARD_TYPE_26: card->ext_csd.hs_max_dtr = 26000000; break; default: /* MMC v4 spec says this cannot happen */ pr_warning("%s: card is mmc v4 but doesn't " "support any high-speed modes.\n", mmc_hostname(card->host)); } card->ext_csd.raw_s_a_timeout = ext_csd[EXT_CSD_S_A_TIMEOUT]; card->ext_csd.raw_erase_timeout_mult = ext_csd[EXT_CSD_ERASE_TIMEOUT_MULT]; card->ext_csd.raw_hc_erase_grp_size = ext_csd[EXT_CSD_HC_ERASE_GRP_SIZE]; if (card->ext_csd.rev >= 3) { u8 sa_shift = ext_csd[EXT_CSD_S_A_TIMEOUT]; card->ext_csd.part_config = ext_csd[EXT_CSD_PART_CONFIG]; /* EXT_CSD value is in units of 10ms, but we store in ms */ card->ext_csd.part_time = 10 * ext_csd[EXT_CSD_PART_SWITCH_TIME]; /* Sleep / awake timeout in 100ns units */ if (sa_shift > 0 && sa_shift <= 0x17) card->ext_csd.sa_timeout = 1 << ext_csd[EXT_CSD_S_A_TIMEOUT]; card->ext_csd.erase_group_def = ext_csd[EXT_CSD_ERASE_GROUP_DEF]; card->ext_csd.hc_erase_timeout = 300 * ext_csd[EXT_CSD_ERASE_TIMEOUT_MULT]; card->ext_csd.hc_erase_size = ext_csd[EXT_CSD_HC_ERASE_GRP_SIZE] << 10; card->ext_csd.rel_sectors = ext_csd[EXT_CSD_REL_WR_SEC_C]; /* * There are two boot regions of equal size, defined in * multiples of 128K. */ if (ext_csd[EXT_CSD_BOOT_MULT] && mmc_boot_partition_access(card->host)) { for (idx = 0; idx < MMC_NUM_BOOT_PARTITION; idx++) { part_size = ext_csd[EXT_CSD_BOOT_MULT] << 17; mmc_part_add(card, part_size, EXT_CSD_PART_CONFIG_ACC_BOOT0 + idx, "boot%d", idx, true, MMC_BLK_DATA_AREA_BOOT); } } } card->ext_csd.raw_hc_erase_gap_size = ext_csd[EXT_CSD_HC_WP_GRP_SIZE]; card->ext_csd.raw_sec_trim_mult = ext_csd[EXT_CSD_SEC_TRIM_MULT]; card->ext_csd.raw_sec_erase_mult = ext_csd[EXT_CSD_SEC_ERASE_MULT]; card->ext_csd.raw_sec_feature_support = ext_csd[EXT_CSD_SEC_FEATURE_SUPPORT]; card->ext_csd.raw_trim_mult = ext_csd[EXT_CSD_TRIM_MULT]; if (card->ext_csd.rev >= 4) { /* * Enhanced area feature support -- check whether the eMMC * card has the Enhanced area enabled. If so, export enhanced * area offset and size to user by adding sysfs interface. */ card->ext_csd.raw_partition_support = ext_csd[EXT_CSD_PARTITION_SUPPORT]; if ((ext_csd[EXT_CSD_PARTITION_SUPPORT] & 0x2) && (ext_csd[EXT_CSD_PARTITION_ATTRIBUTE] & 0x1)) { hc_erase_grp_sz = ext_csd[EXT_CSD_HC_ERASE_GRP_SIZE]; hc_wp_grp_sz = ext_csd[EXT_CSD_HC_WP_GRP_SIZE]; card->ext_csd.enhanced_area_en = 1; /* * calculate the enhanced data area offset, in bytes */ card->ext_csd.enhanced_area_offset = (ext_csd[139] << 24) + (ext_csd[138] << 16) + (ext_csd[137] << 8) + ext_csd[136]; if (mmc_card_blockaddr(card)) card->ext_csd.enhanced_area_offset <<= 9; /* * calculate the enhanced data area size, in kilobytes */ card->ext_csd.enhanced_area_size = (ext_csd[142] << 16) + (ext_csd[141] << 8) + ext_csd[140]; card->ext_csd.enhanced_area_size *= (size_t)(hc_erase_grp_sz * hc_wp_grp_sz); card->ext_csd.enhanced_area_size <<= 9; } else { /* * If the enhanced area is not enabled, disable these * device attributes. */ card->ext_csd.enhanced_area_offset = -EINVAL; card->ext_csd.enhanced_area_size = -EINVAL; } /* * General purpose partition feature support -- * If ext_csd has the size of general purpose partitions, * set size, part_cfg, partition name in mmc_part. */ if (ext_csd[EXT_CSD_PARTITION_SUPPORT] & EXT_CSD_PART_SUPPORT_PART_EN) { if (card->ext_csd.enhanced_area_en != 1) { hc_erase_grp_sz = ext_csd[EXT_CSD_HC_ERASE_GRP_SIZE]; hc_wp_grp_sz = ext_csd[EXT_CSD_HC_WP_GRP_SIZE]; card->ext_csd.enhanced_area_en = 1; } for (idx = 0; idx < MMC_NUM_GP_PARTITION; idx++) { if (!ext_csd[EXT_CSD_GP_SIZE_MULT + idx * 3] && !ext_csd[EXT_CSD_GP_SIZE_MULT + idx * 3 + 1] && !ext_csd[EXT_CSD_GP_SIZE_MULT + idx * 3 + 2]) continue; part_size = (ext_csd[EXT_CSD_GP_SIZE_MULT + idx * 3 + 2] << 16) + (ext_csd[EXT_CSD_GP_SIZE_MULT + idx * 3 + 1] << 8) + ext_csd[EXT_CSD_GP_SIZE_MULT + idx * 3]; part_size *= (size_t)(hc_erase_grp_sz * hc_wp_grp_sz); mmc_part_add(card, part_size << 19, EXT_CSD_PART_CONFIG_ACC_GP0 + idx, "gp%d", idx, false, MMC_BLK_DATA_AREA_GP); } } card->ext_csd.sec_trim_mult = ext_csd[EXT_CSD_SEC_TRIM_MULT]; card->ext_csd.sec_erase_mult = ext_csd[EXT_CSD_SEC_ERASE_MULT]; card->ext_csd.sec_feature_support = ext_csd[EXT_CSD_SEC_FEATURE_SUPPORT]; card->ext_csd.trim_timeout = 300 * ext_csd[EXT_CSD_TRIM_MULT]; /* * Note that the call to mmc_part_add above defaults to read * only. If this default assumption is changed, the call must * take into account the value of boot_locked below. */ card->ext_csd.boot_ro_lock = ext_csd[EXT_CSD_BOOT_WP]; card->ext_csd.boot_ro_lockable = true; } if (card->ext_csd.rev >= 5) { /* check whether the eMMC card supports HPI */ if (ext_csd[EXT_CSD_HPI_FEATURES] & 0x1) { card->ext_csd.hpi = 1; if (ext_csd[EXT_CSD_HPI_FEATURES] & 0x2) card->ext_csd.hpi_cmd = MMC_STOP_TRANSMISSION; else card->ext_csd.hpi_cmd = MMC_SEND_STATUS; /* * Indicate the maximum timeout to close * a command interrupted by HPI */ card->ext_csd.out_of_int_time = ext_csd[EXT_CSD_OUT_OF_INTERRUPT_TIME] * 10; } card->ext_csd.rel_param = ext_csd[EXT_CSD_WR_REL_PARAM]; card->ext_csd.rst_n_function = ext_csd[EXT_CSD_RST_N_FUNCTION]; } card->ext_csd.raw_erased_mem_count = ext_csd[EXT_CSD_ERASED_MEM_CONT]; if (ext_csd[EXT_CSD_ERASED_MEM_CONT]) card->erased_byte = 0xFF; else card->erased_byte = 0x0; /* eMMC v4.5 or later */ if (card->ext_csd.rev >= 6) { card->ext_csd.feature_support |= MMC_DISCARD_FEATURE; card->ext_csd.generic_cmd6_time = 10 * ext_csd[EXT_CSD_GENERIC_CMD6_TIME]; card->ext_csd.power_off_longtime = 10 * ext_csd[EXT_CSD_POWER_OFF_LONG_TIME]; card->ext_csd.cache_size = ext_csd[EXT_CSD_CACHE_SIZE + 0] << 0 | ext_csd[EXT_CSD_CACHE_SIZE + 1] << 8 | ext_csd[EXT_CSD_CACHE_SIZE + 2] << 16 | ext_csd[EXT_CSD_CACHE_SIZE + 3] << 24; if (ext_csd[EXT_CSD_DATA_SECTOR_SIZE] == 1) card->ext_csd.data_sector_size = 4096; else card->ext_csd.data_sector_size = 512; if ((ext_csd[EXT_CSD_DATA_TAG_SUPPORT] & 1) && (ext_csd[EXT_CSD_TAG_UNIT_SIZE] <= 8)) { card->ext_csd.data_tag_unit_size = ((unsigned int) 1 << ext_csd[EXT_CSD_TAG_UNIT_SIZE]) * (card->ext_csd.data_sector_size); } else { card->ext_csd.data_tag_unit_size = 0; } } out: return err; } static inline void mmc_free_ext_csd(u8 *ext_csd) { kfree(ext_csd); } static int mmc_compare_ext_csds(struct mmc_card *card, unsigned bus_width) { u8 *bw_ext_csd; int err; if (bus_width == MMC_BUS_WIDTH_1) return 0; err = mmc_get_ext_csd(card, &bw_ext_csd); if (err || bw_ext_csd == NULL) { if (bus_width != MMC_BUS_WIDTH_1) err = -EINVAL; goto out; } if (bus_width == MMC_BUS_WIDTH_1) goto out; /* only compare read only fields */ err = !((card->ext_csd.raw_partition_support == bw_ext_csd[EXT_CSD_PARTITION_SUPPORT]) && (card->ext_csd.raw_erased_mem_count == bw_ext_csd[EXT_CSD_ERASED_MEM_CONT]) && (card->ext_csd.rev == bw_ext_csd[EXT_CSD_REV]) && (card->ext_csd.raw_ext_csd_structure == bw_ext_csd[EXT_CSD_STRUCTURE]) && (card->ext_csd.raw_card_type == bw_ext_csd[EXT_CSD_CARD_TYPE]) && (card->ext_csd.raw_s_a_timeout == bw_ext_csd[EXT_CSD_S_A_TIMEOUT]) && (card->ext_csd.raw_hc_erase_gap_size == bw_ext_csd[EXT_CSD_HC_WP_GRP_SIZE]) && (card->ext_csd.raw_erase_timeout_mult == bw_ext_csd[EXT_CSD_ERASE_TIMEOUT_MULT]) && (card->ext_csd.raw_hc_erase_grp_size == bw_ext_csd[EXT_CSD_HC_ERASE_GRP_SIZE]) && (card->ext_csd.raw_sec_trim_mult == bw_ext_csd[EXT_CSD_SEC_TRIM_MULT]) && (card->ext_csd.raw_sec_erase_mult == bw_ext_csd[EXT_CSD_SEC_ERASE_MULT]) && (card->ext_csd.raw_sec_feature_support == bw_ext_csd[EXT_CSD_SEC_FEATURE_SUPPORT]) && (card->ext_csd.raw_trim_mult == bw_ext_csd[EXT_CSD_TRIM_MULT]) && (card->ext_csd.raw_sectors[0] == bw_ext_csd[EXT_CSD_SEC_CNT + 0]) && (card->ext_csd.raw_sectors[1] == bw_ext_csd[EXT_CSD_SEC_CNT + 1]) && (card->ext_csd.raw_sectors[2] == bw_ext_csd[EXT_CSD_SEC_CNT + 2]) && (card->ext_csd.raw_sectors[3] == bw_ext_csd[EXT_CSD_SEC_CNT + 3])); if (err) err = -EINVAL; out: mmc_free_ext_csd(bw_ext_csd); return err; } MMC_DEV_ATTR(cid, "%08x%08x%08x%08x\n", card->raw_cid[0], card->raw_cid[1], card->raw_cid[2], card->raw_cid[3]); MMC_DEV_ATTR(csd, "%08x%08x%08x%08x\n", card->raw_csd[0], card->raw_csd[1], card->raw_csd[2], card->raw_csd[3]); MMC_DEV_ATTR(date, "%02d/%04d\n", card->cid.month, card->cid.year); MMC_DEV_ATTR(erase_size, "%u\n", card->erase_size << 9); MMC_DEV_ATTR(preferred_erase_size, "%u\n", card->pref_erase << 9); MMC_DEV_ATTR(fwrev, "0x%x\n", card->cid.fwrev); MMC_DEV_ATTR(hwrev, "0x%x\n", card->cid.hwrev); MMC_DEV_ATTR(manfid, "0x%06x\n", card->cid.manfid); MMC_DEV_ATTR(name, "%s\n", card->cid.prod_name); MMC_DEV_ATTR(oemid, "0x%04x\n", card->cid.oemid); MMC_DEV_ATTR(serial, "0x%08x\n", card->cid.serial); MMC_DEV_ATTR(enhanced_area_offset, "%llu\n", card->ext_csd.enhanced_area_offset); MMC_DEV_ATTR(enhanced_area_size, "%u\n", card->ext_csd.enhanced_area_size); static struct attribute *mmc_std_attrs[] = { &dev_attr_cid.attr, &dev_attr_csd.attr, &dev_attr_date.attr, &dev_attr_erase_size.attr, &dev_attr_preferred_erase_size.attr, &dev_attr_fwrev.attr, &dev_attr_hwrev.attr, &dev_attr_manfid.attr, &dev_attr_name.attr, &dev_attr_oemid.attr, &dev_attr_serial.attr, &dev_attr_enhanced_area_offset.attr, &dev_attr_enhanced_area_size.attr, NULL, }; static struct attribute_group mmc_std_attr_group = { .attrs = mmc_std_attrs, }; static const struct attribute_group *mmc_attr_groups[] = { &mmc_std_attr_group, NULL, }; static struct device_type mmc_type = { .groups = mmc_attr_groups, }; /* * Select the PowerClass for the current bus width * If power class is defined for 4/8 bit bus in the * extended CSD register, select it by executing the * mmc_switch command. */ static int mmc_select_powerclass(struct mmc_card *card, unsigned int bus_width, u8 *ext_csd) { int err = 0; unsigned int pwrclass_val; unsigned int index = 0; struct mmc_host *host; BUG_ON(!card); host = card->host; BUG_ON(!host); if (ext_csd == NULL) return 0; /* Power class selection is supported for versions >= 4.0 */ if (card->csd.mmca_vsn < CSD_SPEC_VER_4) return 0; /* Power class values are defined only for 4/8 bit bus */ if (bus_width == EXT_CSD_BUS_WIDTH_1) return 0; switch (1 << host->ios.vdd) { case MMC_VDD_165_195: if (host->ios.clock <= 26000000) index = EXT_CSD_PWR_CL_26_195; else if (host->ios.clock <= 52000000) index = (bus_width <= EXT_CSD_BUS_WIDTH_8) ? EXT_CSD_PWR_CL_52_195 : EXT_CSD_PWR_CL_DDR_52_195; else if (host->ios.clock <= 200000000) index = EXT_CSD_PWR_CL_200_195; break; case MMC_VDD_32_33: case MMC_VDD_33_34: case MMC_VDD_34_35: case MMC_VDD_35_36: if (host->ios.clock <= 26000000) index = EXT_CSD_PWR_CL_26_360; else if (host->ios.clock <= 52000000) index = (bus_width <= EXT_CSD_BUS_WIDTH_8) ? EXT_CSD_PWR_CL_52_360 : EXT_CSD_PWR_CL_DDR_52_360; else if (host->ios.clock <= 200000000) index = EXT_CSD_PWR_CL_200_360; break; default: pr_warning("%s: Voltage range not supported " "for power class.\n", mmc_hostname(host)); return -EINVAL; } pwrclass_val = ext_csd[index]; if (bus_width & (EXT_CSD_BUS_WIDTH_8 | EXT_CSD_DDR_BUS_WIDTH_8)) pwrclass_val = (pwrclass_val & EXT_CSD_PWR_CL_8BIT_MASK) >> EXT_CSD_PWR_CL_8BIT_SHIFT; else pwrclass_val = (pwrclass_val & EXT_CSD_PWR_CL_4BIT_MASK) >> EXT_CSD_PWR_CL_4BIT_SHIFT; /* If the power class is different from the default value */ if (pwrclass_val > 0) { err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, EXT_CSD_POWER_CLASS, pwrclass_val, card->ext_csd.generic_cmd6_time); } return err; } /* * Selects the desired buswidth and switch to the HS200 mode * if bus width set without error */ static int mmc_select_hs200(struct mmc_card *card) { int idx, err = 0; struct mmc_host *host; static unsigned ext_csd_bits[] = { EXT_CSD_BUS_WIDTH_4, EXT_CSD_BUS_WIDTH_8, }; static unsigned bus_widths[] = { MMC_BUS_WIDTH_4, MMC_BUS_WIDTH_8, }; BUG_ON(!card); host = card->host; if (card->ext_csd.card_type & EXT_CSD_CARD_TYPE_SDR_1_2V && host->caps2 & MMC_CAP2_HS200_1_2V_SDR) if (mmc_set_signal_voltage(host, MMC_SIGNAL_VOLTAGE_120, 0)) err = mmc_set_signal_voltage(host, MMC_SIGNAL_VOLTAGE_180, 0); /* If fails try again during next card power cycle */ if (err) goto err; idx = (host->caps & MMC_CAP_8_BIT_DATA) ? 1 : 0; /* * Unlike SD, MMC cards dont have a configuration register to notify * supported bus width. So bus test command should be run to identify * the supported bus width or compare the ext csd values of current * bus width and ext csd values of 1 bit mode read earlier. */ for (; idx >= 0; idx--) { /* * Host is capable of 8bit transfer, then switch * the device to work in 8bit transfer mode. If the * mmc switch command returns error then switch to * 4bit transfer mode. On success set the corresponding * bus width on the host. */ err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, EXT_CSD_BUS_WIDTH, ext_csd_bits[idx], card->ext_csd.generic_cmd6_time); if (err) continue; mmc_set_bus_width(card->host, bus_widths[idx]); if (!(host->caps & MMC_CAP_BUS_WIDTH_TEST)) err = mmc_compare_ext_csds(card, bus_widths[idx]); else err = mmc_bus_test(card, bus_widths[idx]); if (!err) break; } /* switch to HS200 mode if bus width set successfully */ if (!err) err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, EXT_CSD_HS_TIMING, 2, 0); err: return err; } /* * Handle the detection and initialisation of a card. * * In the case of a resume, "oldcard" will contain the card * we're trying to reinitialise. */ static int mmc_init_card(struct mmc_host *host, u32 ocr, struct mmc_card *oldcard) { struct mmc_card *card; int err, ddr = 0; u32 cid[4]; unsigned int max_dtr; u32 rocr; u8 *ext_csd = NULL; BUG_ON(!host); WARN_ON(!host->claimed); /* Set correct bus mode for MMC before attempting init */ if (!mmc_host_is_spi(host)) mmc_set_bus_mode(host, MMC_BUSMODE_OPENDRAIN); /* Initialization should be done at 3.3 V I/O voltage. */ mmc_set_signal_voltage(host, MMC_SIGNAL_VOLTAGE_330, 0); /* * Since we're changing the OCR value, we seem to * need to tell some cards to go back to the idle * state. We wait 1ms to give cards time to * respond. * mmc_go_idle is needed for eMMC that are asleep */ err = mmc_go_idle(host); if (err) goto err; /* The extra bit indicates that we support high capacity */ err = mmc_send_op_cond(host, ocr | (1 << 30), &rocr); if (err) goto err; /* * For SPI, enable CRC as appropriate. */ if (mmc_host_is_spi(host)) { err = mmc_spi_set_crc(host, use_spi_crc); if (err) goto err; } /* * Fetch CID from card. */ if (mmc_host_is_spi(host)) err = mmc_send_cid(host, cid); else err = mmc_all_send_cid(host, cid); if (err) goto err; if (oldcard) { if (memcmp(cid, oldcard->raw_cid, sizeof(cid)) != 0) { err = -ENOENT; goto err; } card = oldcard; } else { /* * Allocate card structure. */ card = mmc_alloc_card(host, &mmc_type); if (IS_ERR(card)) { err = PTR_ERR(card); goto err; } card->type = MMC_TYPE_MMC; card->rca = 1; memcpy(card->raw_cid, cid, sizeof(card->raw_cid)); } /* * For native busses: set card RCA and quit open drain mode. */ if (!mmc_host_is_spi(host)) { err = mmc_set_relative_addr(card); if (err) goto free_card; mmc_set_bus_mode(host, MMC_BUSMODE_PUSHPULL); } if (!oldcard) { /* * Fetch CSD from card. */ err = mmc_send_csd(card, card->raw_csd); if (err) goto free_card; err = mmc_decode_csd(card); if (err) goto free_card; err = mmc_decode_cid(card); if (err) goto free_card; } /* * Select card, as all following commands rely on that. */ if (!mmc_host_is_spi(host)) { err = mmc_select_card(card); if (err) goto free_card; } if (!oldcard) { /* * Fetch and process extended CSD. */ err = mmc_get_ext_csd(card, &ext_csd); if (err) goto free_card; err = mmc_read_ext_csd(card, ext_csd); if (err) goto free_card; /* If doing byte addressing, check if required to do sector * addressing. Handle the case of <2GB cards needing sector * addressing. See section 8.1 JEDEC Standard JED84-A441; * ocr register has bit 30 set for sector addressing. */ if (!(mmc_card_blockaddr(card)) && (rocr & (1<<30))) mmc_card_set_blockaddr(card); /* Erase size depends on CSD and Extended CSD */ mmc_set_erase_size(card); } /* * If enhanced_area_en is TRUE, host needs to enable ERASE_GRP_DEF * bit. This bit will be lost every time after a reset or power off. */ if (card->ext_csd.enhanced_area_en || (card->ext_csd.rev >= 3 && (host->caps2 & MMC_CAP2_HC_ERASE_SZ))) { err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, EXT_CSD_ERASE_GROUP_DEF, 1, card->ext_csd.generic_cmd6_time); if (err && err != -EBADMSG) goto free_card; if (err) { err = 0; /* * Just disable enhanced area off & sz * will try to enable ERASE_GROUP_DEF * during next time reinit */ card->ext_csd.enhanced_area_offset = -EINVAL; card->ext_csd.enhanced_area_size = -EINVAL; } else { card->ext_csd.erase_group_def = 1; /* * enable ERASE_GRP_DEF successfully. * This will affect the erase size, so * here need to reset erase size */ mmc_set_erase_size(card); } } /* * Ensure eMMC user default partition is enabled */ if (card->ext_csd.part_config & EXT_CSD_PART_CONFIG_ACC_MASK) { card->ext_csd.part_config &= ~EXT_CSD_PART_CONFIG_ACC_MASK; err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, EXT_CSD_PART_CONFIG, card->ext_csd.part_config, card->ext_csd.part_time); if (err && err != -EBADMSG) goto free_card; } /* * If the host supports the power_off_notify capability then * set the notification byte in the ext_csd register of device */ if ((host->caps2 & MMC_CAP2_POWEROFF_NOTIFY) && (card->ext_csd.rev >= 6)) { err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, EXT_CSD_POWER_OFF_NOTIFICATION, EXT_CSD_POWER_ON, card->ext_csd.generic_cmd6_time); if (err && err != -EBADMSG) goto free_card; /* * The err can be -EBADMSG or 0, * so check for success and update the flag */ if (!err) card->poweroff_notify_state = MMC_POWERED_ON; } /* * Activate high speed (if supported) */ if (card->ext_csd.hs_max_dtr != 0) { err = 0; if (card->ext_csd.hs_max_dtr > 52000000 && host->caps2 & MMC_CAP2_HS200) err = mmc_select_hs200(card); else if (host->caps & MMC_CAP_MMC_HIGHSPEED) err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, EXT_CSD_HS_TIMING, 1, card->ext_csd.generic_cmd6_time); if (err && err != -EBADMSG) goto free_card; if (err) { pr_warning("%s: switch to highspeed failed\n", mmc_hostname(card->host)); err = 0; } else { if (card->ext_csd.hs_max_dtr > 52000000 && host->caps2 & MMC_CAP2_HS200) { mmc_card_set_hs200(card); mmc_set_timing(card->host, MMC_TIMING_MMC_HS200); } else { mmc_card_set_highspeed(card); mmc_set_timing(card->host, MMC_TIMING_MMC_HS); } } } /* * Compute bus speed. */ max_dtr = (unsigned int)-1; if (mmc_card_highspeed(card) || mmc_card_hs200(card)) { if (max_dtr > card->ext_csd.hs_max_dtr) max_dtr = card->ext_csd.hs_max_dtr; } else if (max_dtr > card->csd.max_dtr) { max_dtr = card->csd.max_dtr; } mmc_set_clock(host, max_dtr); /* * Indicate DDR mode (if supported). */ if (mmc_card_highspeed(card)) { if ((card->ext_csd.card_type & EXT_CSD_CARD_TYPE_DDR_1_8V) && ((host->caps & (MMC_CAP_1_8V_DDR | MMC_CAP_UHS_DDR50)) == (MMC_CAP_1_8V_DDR | MMC_CAP_UHS_DDR50))) ddr = MMC_1_8V_DDR_MODE; else if ((card->ext_csd.card_type & EXT_CSD_CARD_TYPE_DDR_1_2V) && ((host->caps & (MMC_CAP_1_2V_DDR | MMC_CAP_UHS_DDR50)) == (MMC_CAP_1_2V_DDR | MMC_CAP_UHS_DDR50))) ddr = MMC_1_2V_DDR_MODE; } /* * Indicate HS200 SDR mode (if supported). */ if (mmc_card_hs200(card)) { u32 ext_csd_bits; u32 bus_width = card->host->ios.bus_width; /* * For devices supporting HS200 mode, the bus width has * to be set before executing the tuning function. If * set before tuning, then device will respond with CRC * errors for responses on CMD line. So for HS200 the * sequence will be * 1. set bus width 4bit / 8 bit (1 bit not supported) * 2. switch to HS200 mode * 3. set the clock to > 52Mhz <=200MHz and * 4. execute tuning for HS200 */ if ((host->caps2 & MMC_CAP2_HS200) && card->host->ops->execute_tuning) { mmc_host_clk_hold(card->host); err = card->host->ops->execute_tuning(card->host, MMC_SEND_TUNING_BLOCK_HS200); mmc_host_clk_release(card->host); } if (err) { pr_warning("%s: tuning execution failed\n", mmc_hostname(card->host)); goto err; } ext_csd_bits = (bus_width == MMC_BUS_WIDTH_8) ? EXT_CSD_BUS_WIDTH_8 : EXT_CSD_BUS_WIDTH_4; err = mmc_select_powerclass(card, ext_csd_bits, ext_csd); if (err) { pr_err("%s: power class selection to bus width %d failed\n", mmc_hostname(card->host), 1 << bus_width); goto err; } } /* * Activate wide bus and DDR (if supported). */ if (!mmc_card_hs200(card) && (card->csd.mmca_vsn >= CSD_SPEC_VER_4) && (host->caps & (MMC_CAP_4_BIT_DATA | MMC_CAP_8_BIT_DATA))) { static unsigned ext_csd_bits[][2] = { { EXT_CSD_BUS_WIDTH_8, EXT_CSD_DDR_BUS_WIDTH_8 }, { EXT_CSD_BUS_WIDTH_4, EXT_CSD_DDR_BUS_WIDTH_4 }, { EXT_CSD_BUS_WIDTH_1, EXT_CSD_BUS_WIDTH_1 }, }; static unsigned bus_widths[] = { MMC_BUS_WIDTH_8, MMC_BUS_WIDTH_4, MMC_BUS_WIDTH_1 }; unsigned idx, bus_width = 0; if (host->caps & MMC_CAP_8_BIT_DATA) idx = 0; else idx = 1; for (; idx < ARRAY_SIZE(bus_widths); idx++) { bus_width = bus_widths[idx]; if (bus_width == MMC_BUS_WIDTH_1) ddr = 0; /* no DDR for 1-bit width */ err = mmc_select_powerclass(card, ext_csd_bits[idx][0], ext_csd); if (err) pr_err("%s: power class selection to " "bus width %d failed\n", mmc_hostname(card->host), 1 << bus_width); err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, EXT_CSD_BUS_WIDTH, ext_csd_bits[idx][0], card->ext_csd.generic_cmd6_time); if (!err) { mmc_set_bus_width(card->host, bus_width); /* * If controller can't handle bus width test, * compare ext_csd previously read in 1 bit mode * against ext_csd at new bus width */ if (!(host->caps & MMC_CAP_BUS_WIDTH_TEST)) err = mmc_compare_ext_csds(card, bus_width); else err = mmc_bus_test(card, bus_width); if (!err) break; } } if (!err && ddr) { err = mmc_select_powerclass(card, ext_csd_bits[idx][1], ext_csd); if (err) pr_err("%s: power class selection to " "bus width %d ddr %d failed\n", mmc_hostname(card->host), 1 << bus_width, ddr); err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, EXT_CSD_BUS_WIDTH, ext_csd_bits[idx][1], card->ext_csd.generic_cmd6_time); } if (err) { pr_warning("%s: switch to bus width %d ddr %d " "failed\n", mmc_hostname(card->host), 1 << bus_width, ddr); goto free_card; } else if (ddr) { /* * eMMC cards can support 3.3V to 1.2V i/o (vccq) * signaling. * * EXT_CSD_CARD_TYPE_DDR_1_8V means 3.3V or 1.8V vccq. * * 1.8V vccq at 3.3V core voltage (vcc) is not required * in the JEDEC spec for DDR. * * Do not force change in vccq since we are obviously * working and no change to vccq is needed. * * WARNING: eMMC rules are NOT the same as SD DDR */ if (ddr == MMC_1_2V_DDR_MODE) { err = mmc_set_signal_voltage(host, MMC_SIGNAL_VOLTAGE_120, 0); if (err) goto err; } mmc_card_set_ddr_mode(card); mmc_set_timing(card->host, MMC_TIMING_UHS_DDR50); mmc_set_bus_width(card->host, bus_width); } } /* * Enable HPI feature (if supported) */ if (card->ext_csd.hpi) { err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, EXT_CSD_HPI_MGMT, 1, card->ext_csd.generic_cmd6_time); if (err && err != -EBADMSG) goto free_card; if (err) { pr_warning("%s: Enabling HPI failed\n", mmc_hostname(card->host)); err = 0; } else card->ext_csd.hpi_en = 1; } /* * If cache size is higher than 0, this indicates * the existence of cache and it can be turned on. */ if ((host->caps2 & MMC_CAP2_CACHE_CTRL) && card->ext_csd.cache_size > 0) { err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, EXT_CSD_CACHE_CTRL, 1, card->ext_csd.generic_cmd6_time); if (err && err != -EBADMSG) goto free_card; /* * Only if no error, cache is turned on successfully. */ if (err) { pr_warning("%s: Cache is supported, but failed to turn on (%d)\n", mmc_hostname(card->host), err); err = 0; } else { card->ext_csd.cache_ctrl = 1; } } if (!oldcard) host->card = card; mmc_free_ext_csd(ext_csd); return 0; free_card: if (!oldcard) mmc_remove_card(card); err: mmc_free_ext_csd(ext_csd); return err; } /* * Host is being removed. Free up the current card. */ static void mmc_remove(struct mmc_host *host) { BUG_ON(!host); BUG_ON(!host->card); mmc_remove_card(host->card); host->card = NULL; } /* * Card detection - card is alive. */ static int mmc_alive(struct mmc_host *host) { return mmc_send_status(host->card, NULL); } /* * Card detection callback from host. */ static void mmc_detect(struct mmc_host *host) { int err; BUG_ON(!host); BUG_ON(!host->card); mmc_claim_host(host); /* * Just check if our card has been removed. */ err = _mmc_detect_card_removed(host); mmc_release_host(host); if (err) { mmc_remove(host); mmc_claim_host(host); mmc_detach_bus(host); mmc_power_off(host); mmc_release_host(host); } } /* * Suspend callback from host. */ static int mmc_suspend(struct mmc_host *host) { int err = 0; BUG_ON(!host); BUG_ON(!host->card); mmc_claim_host(host); if (mmc_card_can_sleep(host)) err = mmc_card_sleep(host); else if (!mmc_host_is_spi(host)) mmc_deselect_cards(host); host->card->state &= ~MMC_STATE_HIGHSPEED; mmc_release_host(host); return err; } /* * Resume callback from host. * * This function tries to determine if the same card is still present * and, if so, restore all state to it. */ static int mmc_resume(struct mmc_host *host) { int err; BUG_ON(!host); BUG_ON(!host->card); mmc_claim_host(host); err = mmc_init_card(host, host->ocr, host->card); mmc_release_host(host); return err; } static int mmc_power_restore(struct mmc_host *host) { int ret; host->card->state &= ~MMC_STATE_HIGHSPEED; mmc_claim_host(host); ret = mmc_init_card(host, host->ocr, host->card); mmc_release_host(host); return ret; } static int mmc_sleep(struct mmc_host *host) { struct mmc_card *card = host->card; int err = -ENOSYS; if (card && card->ext_csd.rev >= 3) { err = mmc_card_sleepawake(host, 1); if (err < 0) pr_debug("%s: Error %d while putting card into sleep", mmc_hostname(host), err); } return err; } static int mmc_awake(struct mmc_host *host) { struct mmc_card *card = host->card; int err = -ENOSYS; if (card && card->ext_csd.rev >= 3) { err = mmc_card_sleepawake(host, 0); if (err < 0) pr_debug("%s: Error %d while awaking sleeping card", mmc_hostname(host), err); } return err; } static const struct mmc_bus_ops mmc_ops = { .awake = mmc_awake, .sleep = mmc_sleep, .remove = mmc_remove, .detect = mmc_detect, .suspend = NULL, .resume = NULL, .power_restore = mmc_power_restore, .alive = mmc_alive, }; static const struct mmc_bus_ops mmc_ops_unsafe = { .awake = mmc_awake, .sleep = mmc_sleep, .remove = mmc_remove, .detect = mmc_detect, .suspend = mmc_suspend, .resume = mmc_resume, .power_restore = mmc_power_restore, .alive = mmc_alive, }; static void mmc_attach_bus_ops(struct mmc_host *host) { const struct mmc_bus_ops *bus_ops; if (!mmc_card_is_removable(host)) bus_ops = &mmc_ops_unsafe; else bus_ops = &mmc_ops; mmc_attach_bus(host, bus_ops); } /* * Starting point for MMC card init. */ int mmc_attach_mmc(struct mmc_host *host) { int err; u32 ocr; BUG_ON(!host); WARN_ON(!host->claimed); /* Set correct bus mode for MMC before attempting attach */ if (!mmc_host_is_spi(host)) mmc_set_bus_mode(host, MMC_BUSMODE_OPENDRAIN); err = mmc_send_op_cond(host, 0, &ocr); if (err) return err; mmc_attach_bus_ops(host); if (host->ocr_avail_mmc) host->ocr_avail = host->ocr_avail_mmc; /* * We need to get OCR a different way for SPI. */ if (mmc_host_is_spi(host)) { err = mmc_spi_read_ocr(host, 1, &ocr); if (err) goto err; } /* * Sanity check the voltages that the card claims to * support. */ if (ocr & 0x7F) { pr_warning("%s: card claims to support voltages " "below the defined range. These will be ignored.\n", mmc_hostname(host)); ocr &= ~0x7F; } host->ocr = mmc_select_voltage(host, ocr); /* * Can we support the voltage of the card? */ if (!host->ocr) { err = -EINVAL; goto err; } /* * Detect and init the card. */ err = mmc_init_card(host, host->ocr, NULL); if (err) goto err; mmc_release_host(host); err = mmc_add_card(host->card); mmc_claim_host(host); if (err) goto remove_card; return 0; remove_card: mmc_release_host(host); mmc_remove_card(host->card); mmc_claim_host(host); host->card = NULL; err: mmc_detach_bus(host); pr_err("%s: error %d whilst initialising MMC card\n", mmc_hostname(host), err); return err; }
gpl-2.0
rharshit/android_kernel_mediatek_sprout
drivers/mmc/core/mmc.c
15
40956
/* * linux/drivers/mmc/core/mmc.c * * Copyright (C) 2003-2004 Russell King, All Rights Reserved. * Copyright (C) 2005-2007 Pierre Ossman, All Rights Reserved. * MMCv4 support Copyright (C) 2006 Philip Langdale, All Rights Reserved. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 as * published by the Free Software Foundation. */ #include <linux/err.h> #include <linux/slab.h> #include <linux/stat.h> #include <linux/mmc/host.h> #include <linux/mmc/card.h> #include <linux/mmc/mmc.h> #include "core.h" #include "bus.h" #include "mmc_ops.h" #include "sd_ops.h" #ifdef CONFIG_MTK_EMMC_SUPPORT extern int init_pmt(void); #endif static const unsigned int tran_exp[] = { 10000, 100000, 1000000, 10000000, 0, 0, 0, 0 }; static const unsigned char tran_mant[] = { 0, 10, 12, 13, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 70, 80, }; static const unsigned int tacc_exp[] = { 1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, }; static const unsigned int tacc_mant[] = { 0, 10, 12, 13, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 70, 80, }; #define UNSTUFF_BITS(resp,start,size) \ ({ \ const int __size = size; \ const u32 __mask = (__size < 32 ? 1 << __size : 0) - 1; \ const int __off = 3 - ((start) / 32); \ const int __shft = (start) & 31; \ u32 __res; \ \ __res = resp[__off] >> __shft; \ if (__size + __shft > 32) \ __res |= resp[__off-1] << ((32 - __shft) % 32); \ __res & __mask; \ }) /* * Given the decoded CSD structure, decode the raw CID to our CID structure. */ static int mmc_decode_cid(struct mmc_card *card) { u32 *resp = card->raw_cid; /* * The selection of the format here is based upon published * specs from sandisk and from what people have reported. */ switch (card->csd.mmca_vsn) { case 0: /* MMC v1.0 - v1.2 */ case 1: /* MMC v1.4 */ card->cid.manfid = UNSTUFF_BITS(resp, 104, 24); card->cid.prod_name[0] = UNSTUFF_BITS(resp, 96, 8); card->cid.prod_name[1] = UNSTUFF_BITS(resp, 88, 8); card->cid.prod_name[2] = UNSTUFF_BITS(resp, 80, 8); card->cid.prod_name[3] = UNSTUFF_BITS(resp, 72, 8); card->cid.prod_name[4] = UNSTUFF_BITS(resp, 64, 8); card->cid.prod_name[5] = UNSTUFF_BITS(resp, 56, 8); card->cid.prod_name[6] = UNSTUFF_BITS(resp, 48, 8); card->cid.hwrev = UNSTUFF_BITS(resp, 44, 4); card->cid.fwrev = UNSTUFF_BITS(resp, 40, 4); card->cid.serial = UNSTUFF_BITS(resp, 16, 24); card->cid.month = UNSTUFF_BITS(resp, 12, 4); card->cid.year = UNSTUFF_BITS(resp, 8, 4) + 1997; break; case 2: /* MMC v2.0 - v2.2 */ case 3: /* MMC v3.1 - v3.3 */ case 4: /* MMC v4 */ card->cid.manfid = UNSTUFF_BITS(resp, 120, 8); card->cid.oemid = UNSTUFF_BITS(resp, 104, 16); card->cid.prod_name[0] = UNSTUFF_BITS(resp, 96, 8); card->cid.prod_name[1] = UNSTUFF_BITS(resp, 88, 8); card->cid.prod_name[2] = UNSTUFF_BITS(resp, 80, 8); card->cid.prod_name[3] = UNSTUFF_BITS(resp, 72, 8); card->cid.prod_name[4] = UNSTUFF_BITS(resp, 64, 8); card->cid.prod_name[5] = UNSTUFF_BITS(resp, 56, 8); card->cid.serial = UNSTUFF_BITS(resp, 16, 32); card->cid.month = UNSTUFF_BITS(resp, 12, 4); card->cid.year = UNSTUFF_BITS(resp, 8, 4) + 1997; break; default: pr_err("%s: card has unknown MMCA version %d\n", mmc_hostname(card->host), card->csd.mmca_vsn); return -EINVAL; } return 0; } static void mmc_set_erase_size(struct mmc_card *card) { if (card->ext_csd.erase_group_def & 1) card->erase_size = card->ext_csd.hc_erase_size; else card->erase_size = card->csd.erase_size; mmc_init_erase(card); } /* * Given a 128-bit response, decode to our card CSD structure. */ static int mmc_decode_csd(struct mmc_card *card) { struct mmc_csd *csd = &card->csd; unsigned int e, m, a, b; u32 *resp = card->raw_csd; /* * We only understand CSD structure v1.1 and v1.2. * v1.2 has extra information in bits 15, 11 and 10. * We also support eMMC v4.4 & v4.41. */ csd->structure = UNSTUFF_BITS(resp, 126, 2); if (csd->structure == 0) { pr_err("%s: unrecognised CSD structure version %d\n", mmc_hostname(card->host), csd->structure); return -EINVAL; } csd->mmca_vsn = UNSTUFF_BITS(resp, 122, 4); m = UNSTUFF_BITS(resp, 115, 4); e = UNSTUFF_BITS(resp, 112, 3); csd->tacc_ns = (tacc_exp[e] * tacc_mant[m] + 9) / 10; csd->tacc_clks = UNSTUFF_BITS(resp, 104, 8) * 100; m = UNSTUFF_BITS(resp, 99, 4); e = UNSTUFF_BITS(resp, 96, 3); csd->max_dtr = tran_exp[e] * tran_mant[m]; csd->cmdclass = UNSTUFF_BITS(resp, 84, 12); e = UNSTUFF_BITS(resp, 47, 3); m = UNSTUFF_BITS(resp, 62, 12); csd->capacity = (1 + m) << (e + 2); csd->read_blkbits = UNSTUFF_BITS(resp, 80, 4); csd->read_partial = UNSTUFF_BITS(resp, 79, 1); csd->write_misalign = UNSTUFF_BITS(resp, 78, 1); csd->read_misalign = UNSTUFF_BITS(resp, 77, 1); csd->r2w_factor = UNSTUFF_BITS(resp, 26, 3); csd->write_blkbits = UNSTUFF_BITS(resp, 22, 4); csd->write_partial = UNSTUFF_BITS(resp, 21, 1); if (csd->write_blkbits >= 9) { a = UNSTUFF_BITS(resp, 42, 5); b = UNSTUFF_BITS(resp, 37, 5); csd->erase_size = (a + 1) * (b + 1); csd->erase_size <<= csd->write_blkbits - 9; } return 0; } /* * Read extended CSD. */ static int mmc_get_ext_csd(struct mmc_card *card, u8 **new_ext_csd) { int err; u8 *ext_csd; BUG_ON(!card); BUG_ON(!new_ext_csd); *new_ext_csd = NULL; if (card->csd.mmca_vsn < CSD_SPEC_VER_4) return 0; /* * As the ext_csd is so large and mostly unused, we don't store the * raw block in mmc_card. */ ext_csd = kmalloc(512, GFP_KERNEL); if (!ext_csd) { pr_err("%s: could not allocate a buffer to " "receive the ext_csd.\n", mmc_hostname(card->host)); return -ENOMEM; } err = mmc_send_ext_csd(card, ext_csd); if (err) { kfree(ext_csd); *new_ext_csd = NULL; /* If the host or the card can't do the switch, * fail more gracefully. */ if ((err != -EINVAL) && (err != -ENOSYS) && (err != -EFAULT)) return err; /* * High capacity cards should have this "magic" size * stored in their CSD. */ if (card->csd.capacity == (4096 * 512)) { pr_err("%s: unable to read EXT_CSD " "on a possible high capacity card. " "Card will be ignored.\n", mmc_hostname(card->host)); } else { pr_warning("%s: unable to read " "EXT_CSD, performance might " "suffer.\n", mmc_hostname(card->host)); err = 0; } } else *new_ext_csd = ext_csd; return err; } /* * Decode extended CSD. */ #define VENDOR_SAMSUNG (0x15) static int mmc_read_ext_csd(struct mmc_card *card, u8 *ext_csd) { int err = 0, idx; unsigned int part_size; u8 hc_erase_grp_sz = 0, hc_wp_grp_sz = 0; BUG_ON(!card); if (!ext_csd) return 0; /* Version is coded in the CSD_STRUCTURE byte in the EXT_CSD register */ card->ext_csd.raw_ext_csd_structure = ext_csd[EXT_CSD_STRUCTURE]; if (card->csd.structure == 3) { if (card->ext_csd.raw_ext_csd_structure > 2) { pr_err("%s: unrecognised EXT_CSD structure " "version %d\n", mmc_hostname(card->host), card->ext_csd.raw_ext_csd_structure); err = -EINVAL; goto out; } } card->ext_csd.rev = ext_csd[EXT_CSD_REV]; if (card->ext_csd.rev > 7) { pr_err("%s: unrecognised EXT_CSD revision %d\n", mmc_hostname(card->host), card->ext_csd.rev); err = -EINVAL; goto out; } card->ext_csd.raw_sectors[0] = ext_csd[EXT_CSD_SEC_CNT + 0]; card->ext_csd.raw_sectors[1] = ext_csd[EXT_CSD_SEC_CNT + 1]; card->ext_csd.raw_sectors[2] = ext_csd[EXT_CSD_SEC_CNT + 2]; card->ext_csd.raw_sectors[3] = ext_csd[EXT_CSD_SEC_CNT + 3]; if (card->ext_csd.rev >= 2) { card->ext_csd.sectors = ext_csd[EXT_CSD_SEC_CNT + 0] << 0 | ext_csd[EXT_CSD_SEC_CNT + 1] << 8 | ext_csd[EXT_CSD_SEC_CNT + 2] << 16 | ext_csd[EXT_CSD_SEC_CNT + 3] << 24; /* Cards with density > 2GiB are sector addressed */ if (card->ext_csd.sectors > (2u * 1024 * 1024 * 1024) / 512) mmc_card_set_blockaddr(card); } card->ext_csd.raw_card_type = ext_csd[EXT_CSD_CARD_TYPE]; switch (ext_csd[EXT_CSD_CARD_TYPE] & EXT_CSD_CARD_TYPE_MASK) { case EXT_CSD_CARD_TYPE_SDR_ALL: case EXT_CSD_CARD_TYPE_SDR_ALL_DDR_1_8V: case EXT_CSD_CARD_TYPE_SDR_ALL_DDR_1_2V: case EXT_CSD_CARD_TYPE_SDR_ALL_DDR_52: card->ext_csd.hs_max_dtr = 200000000; card->ext_csd.card_type = EXT_CSD_CARD_TYPE_SDR_200; break; case EXT_CSD_CARD_TYPE_SDR_1_2V_ALL: case EXT_CSD_CARD_TYPE_SDR_1_2V_DDR_1_8V: case EXT_CSD_CARD_TYPE_SDR_1_2V_DDR_1_2V: case EXT_CSD_CARD_TYPE_SDR_1_2V_DDR_52: card->ext_csd.hs_max_dtr = 200000000; card->ext_csd.card_type = EXT_CSD_CARD_TYPE_SDR_1_2V; break; case EXT_CSD_CARD_TYPE_SDR_1_8V_ALL: case EXT_CSD_CARD_TYPE_SDR_1_8V_DDR_1_8V: case EXT_CSD_CARD_TYPE_SDR_1_8V_DDR_1_2V: case EXT_CSD_CARD_TYPE_SDR_1_8V_DDR_52: card->ext_csd.hs_max_dtr = 200000000; card->ext_csd.card_type = EXT_CSD_CARD_TYPE_SDR_1_8V; break; case EXT_CSD_CARD_TYPE_DDR_52 | EXT_CSD_CARD_TYPE_52 | EXT_CSD_CARD_TYPE_26: card->ext_csd.hs_max_dtr = 52000000; card->ext_csd.card_type = EXT_CSD_CARD_TYPE_DDR_52; break; case EXT_CSD_CARD_TYPE_DDR_1_2V | EXT_CSD_CARD_TYPE_52 | EXT_CSD_CARD_TYPE_26: card->ext_csd.hs_max_dtr = 52000000; card->ext_csd.card_type = EXT_CSD_CARD_TYPE_DDR_1_2V; break; case EXT_CSD_CARD_TYPE_DDR_1_8V | EXT_CSD_CARD_TYPE_52 | EXT_CSD_CARD_TYPE_26: card->ext_csd.hs_max_dtr = 52000000; card->ext_csd.card_type = EXT_CSD_CARD_TYPE_DDR_1_8V; break; case EXT_CSD_CARD_TYPE_52 | EXT_CSD_CARD_TYPE_26: card->ext_csd.hs_max_dtr = 52000000; break; case EXT_CSD_CARD_TYPE_26: card->ext_csd.hs_max_dtr = 26000000; break; default: /* MMC v4 spec says this cannot happen */ pr_warning("%s: card is mmc v4 but doesn't " "support any high-speed modes.\n", mmc_hostname(card->host)); } card->ext_csd.raw_s_a_timeout = ext_csd[EXT_CSD_S_A_TIMEOUT]; card->ext_csd.raw_erase_timeout_mult = ext_csd[EXT_CSD_ERASE_TIMEOUT_MULT]; card->ext_csd.raw_hc_erase_grp_size = ext_csd[EXT_CSD_HC_ERASE_GRP_SIZE]; if (card->ext_csd.rev >= 3) { u8 sa_shift = ext_csd[EXT_CSD_S_A_TIMEOUT]; card->ext_csd.part_config = ext_csd[EXT_CSD_PART_CONFIG]; /* EXT_CSD value is in units of 10ms, but we store in ms */ card->ext_csd.part_time = 10 * ext_csd[EXT_CSD_PART_SWITCH_TIME]; /* Sleep / awake timeout in 100ns units */ if (sa_shift > 0 && sa_shift <= 0x17) card->ext_csd.sa_timeout = 1 << ext_csd[EXT_CSD_S_A_TIMEOUT]; card->ext_csd.erase_group_def = ext_csd[EXT_CSD_ERASE_GROUP_DEF]; card->ext_csd.hc_erase_timeout = 300 * ext_csd[EXT_CSD_ERASE_TIMEOUT_MULT]; card->ext_csd.hc_erase_size = ext_csd[EXT_CSD_HC_ERASE_GRP_SIZE] << 10; card->ext_csd.rel_sectors = ext_csd[EXT_CSD_REL_WR_SEC_C]; /* * There are two boot regions of equal size, defined in * multiples of 128K. */ if (ext_csd[EXT_CSD_BOOT_MULT] && mmc_boot_partition_access(card->host)) { for (idx = 0; idx < MMC_NUM_BOOT_PARTITION; idx++) { part_size = ext_csd[EXT_CSD_BOOT_MULT] << 17; mmc_part_add(card, part_size, EXT_CSD_PART_CONFIG_ACC_BOOT0 + idx, "boot%d", idx, true, MMC_BLK_DATA_AREA_BOOT); } } } card->ext_csd.raw_hc_erase_gap_size = ext_csd[EXT_CSD_HC_WP_GRP_SIZE]; card->ext_csd.raw_sec_trim_mult = ext_csd[EXT_CSD_SEC_TRIM_MULT]; card->ext_csd.raw_sec_erase_mult = ext_csd[EXT_CSD_SEC_ERASE_MULT]; card->ext_csd.raw_sec_feature_support = ext_csd[EXT_CSD_SEC_FEATURE_SUPPORT]; card->ext_csd.raw_trim_mult = ext_csd[EXT_CSD_TRIM_MULT]; card->ext_csd.raw_partition_support = ext_csd[EXT_CSD_PARTITION_SUPPORT]; if (card->ext_csd.rev >= 4) { /* * Enhanced area feature support -- check whether the eMMC * card has the Enhanced area enabled. If so, export enhanced * area offset and size to user by adding sysfs interface. */ if ((ext_csd[EXT_CSD_PARTITION_SUPPORT] & 0x2) && (ext_csd[EXT_CSD_PARTITION_ATTRIBUTE] & 0x1)) { hc_erase_grp_sz = ext_csd[EXT_CSD_HC_ERASE_GRP_SIZE]; hc_wp_grp_sz = ext_csd[EXT_CSD_HC_WP_GRP_SIZE]; card->ext_csd.enhanced_area_en = 1; /* * calculate the enhanced data area offset, in bytes */ card->ext_csd.enhanced_area_offset = (ext_csd[139] << 24) + (ext_csd[138] << 16) + (ext_csd[137] << 8) + ext_csd[136]; if (mmc_card_blockaddr(card)) card->ext_csd.enhanced_area_offset <<= 9; /* * calculate the enhanced data area size, in kilobytes */ card->ext_csd.enhanced_area_size = (ext_csd[142] << 16) + (ext_csd[141] << 8) + ext_csd[140]; card->ext_csd.enhanced_area_size *= (size_t)(hc_erase_grp_sz * hc_wp_grp_sz); card->ext_csd.enhanced_area_size <<= 9; } else { /* * If the enhanced area is not enabled, disable these * device attributes. */ card->ext_csd.enhanced_area_offset = -EINVAL; card->ext_csd.enhanced_area_size = -EINVAL; } /* * General purpose partition feature support -- * If ext_csd has the size of general purpose partitions, * set size, part_cfg, partition name in mmc_part. */ if (ext_csd[EXT_CSD_PARTITION_SUPPORT] & EXT_CSD_PART_SUPPORT_PART_EN) { if (card->ext_csd.enhanced_area_en != 1) { hc_erase_grp_sz = ext_csd[EXT_CSD_HC_ERASE_GRP_SIZE]; hc_wp_grp_sz = ext_csd[EXT_CSD_HC_WP_GRP_SIZE]; card->ext_csd.enhanced_area_en = 1; } for (idx = 0; idx < MMC_NUM_GP_PARTITION; idx++) { if (!ext_csd[EXT_CSD_GP_SIZE_MULT + idx * 3] && !ext_csd[EXT_CSD_GP_SIZE_MULT + idx * 3 + 1] && !ext_csd[EXT_CSD_GP_SIZE_MULT + idx * 3 + 2]) continue; part_size = (ext_csd[EXT_CSD_GP_SIZE_MULT + idx * 3 + 2] << 16) + (ext_csd[EXT_CSD_GP_SIZE_MULT + idx * 3 + 1] << 8) + ext_csd[EXT_CSD_GP_SIZE_MULT + idx * 3]; part_size *= (size_t)(hc_erase_grp_sz * hc_wp_grp_sz); mmc_part_add(card, part_size << 19, EXT_CSD_PART_CONFIG_ACC_GP0 + idx, "gp%d", idx, false, MMC_BLK_DATA_AREA_GP); } } card->ext_csd.sec_trim_mult = ext_csd[EXT_CSD_SEC_TRIM_MULT]; card->ext_csd.sec_erase_mult = ext_csd[EXT_CSD_SEC_ERASE_MULT]; card->ext_csd.sec_feature_support = ext_csd[EXT_CSD_SEC_FEATURE_SUPPORT]; card->ext_csd.trim_timeout = 300 * ext_csd[EXT_CSD_TRIM_MULT]; /* * Note that the call to mmc_part_add above defaults to read * only. If this default assumption is changed, the call must * take into account the value of boot_locked below. */ card->ext_csd.boot_ro_lock = ext_csd[EXT_CSD_BOOT_WP]; card->ext_csd.boot_ro_lockable = true; } if (card->ext_csd.rev >= 5) { /* check whether the eMMC card supports HPI */ if (ext_csd[EXT_CSD_HPI_FEATURES] & 0x1) { card->ext_csd.hpi = 1; if (ext_csd[EXT_CSD_HPI_FEATURES] & 0x2) card->ext_csd.hpi_cmd = MMC_STOP_TRANSMISSION; else card->ext_csd.hpi_cmd = MMC_SEND_STATUS; /* * Indicate the maximum timeout to close * a command interrupted by HPI */ card->ext_csd.out_of_int_time = ext_csd[EXT_CSD_OUT_OF_INTERRUPT_TIME] * 10; } card->ext_csd.rel_param = ext_csd[EXT_CSD_WR_REL_PARAM]; card->ext_csd.rst_n_function = ext_csd[EXT_CSD_RST_N_FUNCTION]; } card->ext_csd.raw_erased_mem_count = ext_csd[EXT_CSD_ERASED_MEM_CONT]; if (ext_csd[EXT_CSD_ERASED_MEM_CONT]) card->erased_byte = 0xFF; else card->erased_byte = 0x0; /* for samsung emmc4.41 plus spec */ if ((card->cid.manfid == VENDOR_SAMSUNG) && (card->ext_csd.rev == 5) && (1 == (0x1 & ext_csd[EXT_CSD_SAMSUNG_FEATURE]))){ printk("set to support discard\n"); card->ext_csd.feature_support |= MMC_DISCARD_FEATURE; } /* eMMC v4.5 or later */ if (card->ext_csd.rev >= 6) { card->ext_csd.feature_support |= MMC_DISCARD_FEATURE; card->ext_csd.generic_cmd6_time = 10 * ext_csd[EXT_CSD_GENERIC_CMD6_TIME]; card->ext_csd.power_off_longtime = 10 * ext_csd[EXT_CSD_POWER_OFF_LONG_TIME]; card->ext_csd.cache_size = ext_csd[EXT_CSD_CACHE_SIZE + 0] << 0 | ext_csd[EXT_CSD_CACHE_SIZE + 1] << 8 | ext_csd[EXT_CSD_CACHE_SIZE + 2] << 16 | ext_csd[EXT_CSD_CACHE_SIZE + 3] << 24; if (ext_csd[EXT_CSD_DATA_SECTOR_SIZE] == 1) card->ext_csd.data_sector_size = 4096; else card->ext_csd.data_sector_size = 512; if ((ext_csd[EXT_CSD_DATA_TAG_SUPPORT] & 1) && (ext_csd[EXT_CSD_TAG_UNIT_SIZE] <= 8)) { card->ext_csd.data_tag_unit_size = ((unsigned int) 1 << ext_csd[EXT_CSD_TAG_UNIT_SIZE]) * (card->ext_csd.data_sector_size); } else { card->ext_csd.data_tag_unit_size = 0; } } out: return err; } static inline void mmc_free_ext_csd(u8 *ext_csd) { kfree(ext_csd); } static int mmc_compare_ext_csds(struct mmc_card *card, unsigned bus_width) { u8 *bw_ext_csd; int err; if (bus_width == MMC_BUS_WIDTH_1) return 0; err = mmc_get_ext_csd(card, &bw_ext_csd); if (err || bw_ext_csd == NULL) { if (bus_width != MMC_BUS_WIDTH_1) err = -EINVAL; goto out; } if (bus_width == MMC_BUS_WIDTH_1) goto out; /* only compare read only fields */ err = !((card->ext_csd.raw_partition_support == bw_ext_csd[EXT_CSD_PARTITION_SUPPORT]) && (card->ext_csd.raw_erased_mem_count == bw_ext_csd[EXT_CSD_ERASED_MEM_CONT]) && (card->ext_csd.rev == bw_ext_csd[EXT_CSD_REV]) && (card->ext_csd.raw_ext_csd_structure == bw_ext_csd[EXT_CSD_STRUCTURE]) && (card->ext_csd.raw_card_type == bw_ext_csd[EXT_CSD_CARD_TYPE]) && (card->ext_csd.raw_s_a_timeout == bw_ext_csd[EXT_CSD_S_A_TIMEOUT]) && (card->ext_csd.raw_hc_erase_gap_size == bw_ext_csd[EXT_CSD_HC_WP_GRP_SIZE]) && (card->ext_csd.raw_erase_timeout_mult == bw_ext_csd[EXT_CSD_ERASE_TIMEOUT_MULT]) && (card->ext_csd.raw_hc_erase_grp_size == bw_ext_csd[EXT_CSD_HC_ERASE_GRP_SIZE]) && (card->ext_csd.raw_sec_trim_mult == bw_ext_csd[EXT_CSD_SEC_TRIM_MULT]) && (card->ext_csd.raw_sec_erase_mult == bw_ext_csd[EXT_CSD_SEC_ERASE_MULT]) && (card->ext_csd.raw_sec_feature_support == bw_ext_csd[EXT_CSD_SEC_FEATURE_SUPPORT]) && (card->ext_csd.raw_trim_mult == bw_ext_csd[EXT_CSD_TRIM_MULT]) && (card->ext_csd.raw_sectors[0] == bw_ext_csd[EXT_CSD_SEC_CNT + 0]) && (card->ext_csd.raw_sectors[1] == bw_ext_csd[EXT_CSD_SEC_CNT + 1]) && (card->ext_csd.raw_sectors[2] == bw_ext_csd[EXT_CSD_SEC_CNT + 2]) && (card->ext_csd.raw_sectors[3] == bw_ext_csd[EXT_CSD_SEC_CNT + 3])); if (err) err = -EINVAL; out: mmc_free_ext_csd(bw_ext_csd); return err; } MMC_DEV_ATTR(cid, "%08x%08x%08x%08x\n", card->raw_cid[0], card->raw_cid[1], card->raw_cid[2], card->raw_cid[3]); MMC_DEV_ATTR(csd, "%08x%08x%08x%08x\n", card->raw_csd[0], card->raw_csd[1], card->raw_csd[2], card->raw_csd[3]); MMC_DEV_ATTR(date, "%02d/%04d\n", card->cid.month, card->cid.year); MMC_DEV_ATTR(erase_size, "%u\n", card->erase_size << 9); MMC_DEV_ATTR(preferred_erase_size, "%u\n", card->pref_erase << 9); MMC_DEV_ATTR(fwrev, "0x%x\n", card->cid.fwrev); MMC_DEV_ATTR(hwrev, "0x%x\n", card->cid.hwrev); MMC_DEV_ATTR(manfid, "0x%06x\n", card->cid.manfid); MMC_DEV_ATTR(name, "%s\n", card->cid.prod_name); MMC_DEV_ATTR(oemid, "0x%04x\n", card->cid.oemid); MMC_DEV_ATTR(serial, "0x%08x\n", card->cid.serial); MMC_DEV_ATTR(enhanced_area_offset, "%llu\n", card->ext_csd.enhanced_area_offset); MMC_DEV_ATTR(enhanced_area_size, "%u\n", card->ext_csd.enhanced_area_size); static struct attribute *mmc_std_attrs[] = { &dev_attr_cid.attr, &dev_attr_csd.attr, &dev_attr_date.attr, &dev_attr_erase_size.attr, &dev_attr_preferred_erase_size.attr, &dev_attr_fwrev.attr, &dev_attr_hwrev.attr, &dev_attr_manfid.attr, &dev_attr_name.attr, &dev_attr_oemid.attr, &dev_attr_serial.attr, &dev_attr_enhanced_area_offset.attr, &dev_attr_enhanced_area_size.attr, NULL, }; static struct attribute_group mmc_std_attr_group = { .attrs = mmc_std_attrs, }; static const struct attribute_group *mmc_attr_groups[] = { &mmc_std_attr_group, NULL, }; static struct device_type mmc_type = { .groups = mmc_attr_groups, }; /* * Select the PowerClass for the current bus width * If power class is defined for 4/8 bit bus in the * extended CSD register, select it by executing the * mmc_switch command. */ static int mmc_select_powerclass(struct mmc_card *card, unsigned int bus_width, u8 *ext_csd) { int err = 0; unsigned int pwrclass_val; unsigned int index = 0; struct mmc_host *host; BUG_ON(!card); host = card->host; BUG_ON(!host); if (ext_csd == NULL) return 0; /* Power class selection is supported for versions >= 4.0 */ if (card->csd.mmca_vsn < CSD_SPEC_VER_4) return 0; /* Power class values are defined only for 4/8 bit bus */ if (bus_width == EXT_CSD_BUS_WIDTH_1) return 0; switch (1 << host->ios.vdd) { case MMC_VDD_165_195: if (host->ios.clock <= 26000000) index = EXT_CSD_PWR_CL_26_195; else if (host->ios.clock <= 52000000) index = (bus_width <= EXT_CSD_BUS_WIDTH_8) ? EXT_CSD_PWR_CL_52_195 : EXT_CSD_PWR_CL_DDR_52_195; else if (host->ios.clock <= 200000000) index = EXT_CSD_PWR_CL_200_195; break; case MMC_VDD_27_28: case MMC_VDD_28_29: case MMC_VDD_29_30: case MMC_VDD_30_31: case MMC_VDD_31_32: case MMC_VDD_32_33: case MMC_VDD_33_34: case MMC_VDD_34_35: case MMC_VDD_35_36: if (host->ios.clock <= 26000000) index = EXT_CSD_PWR_CL_26_360; else if (host->ios.clock <= 52000000) index = (bus_width <= EXT_CSD_BUS_WIDTH_8) ? EXT_CSD_PWR_CL_52_360 : EXT_CSD_PWR_CL_DDR_52_360; else if (host->ios.clock <= 200000000) index = EXT_CSD_PWR_CL_200_360; break; default: pr_warning("%s: Voltage range not supported " "for power class.\n", mmc_hostname(host)); return -EINVAL; } pwrclass_val = ext_csd[index]; if (bus_width & (EXT_CSD_BUS_WIDTH_8 | EXT_CSD_DDR_BUS_WIDTH_8)) pwrclass_val = (pwrclass_val & EXT_CSD_PWR_CL_8BIT_MASK) >> EXT_CSD_PWR_CL_8BIT_SHIFT; else pwrclass_val = (pwrclass_val & EXT_CSD_PWR_CL_4BIT_MASK) >> EXT_CSD_PWR_CL_4BIT_SHIFT; /* If the power class is different from the default value */ if (pwrclass_val > 0) { err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, EXT_CSD_POWER_CLASS, pwrclass_val, card->ext_csd.generic_cmd6_time); } return err; } /* * Selects the desired buswidth and switch to the HS200 mode * if bus width set without error */ static int mmc_select_hs200(struct mmc_card *card) { int idx, err = 0; struct mmc_host *host; static unsigned ext_csd_bits[] = { EXT_CSD_BUS_WIDTH_4, EXT_CSD_BUS_WIDTH_8, }; static unsigned bus_widths[] = { MMC_BUS_WIDTH_4, MMC_BUS_WIDTH_8, }; BUG_ON(!card); host = card->host; if (card->ext_csd.card_type & EXT_CSD_CARD_TYPE_SDR_1_2V && host->caps2 & MMC_CAP2_HS200_1_2V_SDR) if (mmc_set_signal_voltage(host, MMC_SIGNAL_VOLTAGE_120, 0)) err = mmc_set_signal_voltage(host, MMC_SIGNAL_VOLTAGE_180, 0); /* If fails try again during next card power cycle */ if (err) goto err; idx = (host->caps & MMC_CAP_8_BIT_DATA) ? 1 : 0; /* * Unlike SD, MMC cards dont have a configuration register to notify * supported bus width. So bus test command should be run to identify * the supported bus width or compare the ext csd values of current * bus width and ext csd values of 1 bit mode read earlier. */ for (; idx >= 0; idx--) { /* * Host is capable of 8bit transfer, then switch * the device to work in 8bit transfer mode. If the * mmc switch command returns error then switch to * 4bit transfer mode. On success set the corresponding * bus width on the host. */ err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, EXT_CSD_BUS_WIDTH, ext_csd_bits[idx], card->ext_csd.generic_cmd6_time); if (err) continue; mmc_set_bus_width(card->host, bus_widths[idx]); if (!(host->caps & MMC_CAP_BUS_WIDTH_TEST)) err = mmc_compare_ext_csds(card, bus_widths[idx]); else err = mmc_bus_test(card, bus_widths[idx]); if (!err) break; } /* switch to HS200 mode if bus width set successfully */ if (!err) err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, EXT_CSD_HS_TIMING, 2, 0); err: return err; } /* * Handle the detection and initialisation of a card. * * In the case of a resume, "oldcard" will contain the card * we're trying to reinitialise. */ static int mmc_init_card(struct mmc_host *host, u32 ocr, struct mmc_card *oldcard) { struct mmc_card *card; int err, ddr = 0; u32 cid[4]; unsigned int max_dtr; u32 rocr; u8 *ext_csd = NULL; BUG_ON(!host); WARN_ON(!host->claimed); /* Set correct bus mode for MMC before attempting init */ if (!mmc_host_is_spi(host)) mmc_set_bus_mode(host, MMC_BUSMODE_OPENDRAIN); /* Initialization should be done at 3.3 V I/O voltage. */ mmc_set_signal_voltage(host, MMC_SIGNAL_VOLTAGE_330, 0); /* * Since we're changing the OCR value, we seem to * need to tell some cards to go back to the idle * state. We wait 1ms to give cards time to * respond. * mmc_go_idle is needed for eMMC that are asleep */ mmc_go_idle(host); /* The extra bit indicates that we support high capacity */ err = mmc_send_op_cond(host, ocr | (1 << 30), &rocr); if (err) goto err; /* * For SPI, enable CRC as appropriate. */ if (mmc_host_is_spi(host)) { err = mmc_spi_set_crc(host, use_spi_crc); if (err) goto err; } /* * Fetch CID from card. */ if (mmc_host_is_spi(host)) err = mmc_send_cid(host, cid); else err = mmc_all_send_cid(host, cid); if (err) goto err; if (oldcard) { if (memcmp(cid, oldcard->raw_cid, sizeof(cid)) != 0) { err = -ENOENT; goto err; } card = oldcard; } else { /* * Allocate card structure. */ card = mmc_alloc_card(host, &mmc_type); if (IS_ERR(card)) { err = PTR_ERR(card); goto err; } card->type = MMC_TYPE_MMC; card->rca = 1; memcpy(card->raw_cid, cid, sizeof(card->raw_cid)); } /* * For native busses: set card RCA and quit open drain mode. */ if (!mmc_host_is_spi(host)) { err = mmc_set_relative_addr(card); if (err) goto free_card; mmc_set_bus_mode(host, MMC_BUSMODE_PUSHPULL); } if (!oldcard) { /* * Fetch CSD from card. */ err = mmc_send_csd(card, card->raw_csd); if (err) goto free_card; err = mmc_decode_csd(card); if (err) goto free_card; err = mmc_decode_cid(card); if (err) goto free_card; } /* * Select card, as all following commands rely on that. */ if (!mmc_host_is_spi(host)) { err = mmc_select_card(card); if (err) goto free_card; } if (!oldcard) { /* * Fetch and process extended CSD. */ err = mmc_get_ext_csd(card, &ext_csd); if (err) goto free_card; err = mmc_read_ext_csd(card, ext_csd); if (err) goto free_card; /* If doing byte addressing, check if required to do sector * addressing. Handle the case of <2GB cards needing sector * addressing. See section 8.1 JEDEC Standard JED84-A441; * ocr register has bit 30 set for sector addressing. */ if (!(mmc_card_blockaddr(card)) && (rocr & (1<<30))) mmc_card_set_blockaddr(card); /* Erase size depends on CSD and Extended CSD */ mmc_set_erase_size(card); } /* * If enhanced_area_en is TRUE, host needs to enable ERASE_GRP_DEF * bit. This bit will be lost every time after a reset or power off. */ if (card->ext_csd.enhanced_area_en || (card->ext_csd.rev >= 3 && (host->caps2 & MMC_CAP2_HC_ERASE_SZ))) { err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, EXT_CSD_ERASE_GROUP_DEF, 1, card->ext_csd.generic_cmd6_time); if (err && err != -EBADMSG) goto free_card; if (err) { err = 0; /* * Just disable enhanced area off & sz * will try to enable ERASE_GROUP_DEF * during next time reinit */ card->ext_csd.enhanced_area_offset = -EINVAL; card->ext_csd.enhanced_area_size = -EINVAL; } else { card->ext_csd.erase_group_def = 1; /* * enable ERASE_GRP_DEF successfully. * This will affect the erase size, so * here need to reset erase size */ mmc_set_erase_size(card); } } /* * Ensure eMMC user default partition is enabled */ if (card->ext_csd.part_config & EXT_CSD_PART_CONFIG_ACC_MASK) { card->ext_csd.part_config &= ~EXT_CSD_PART_CONFIG_ACC_MASK; err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, EXT_CSD_PART_CONFIG, card->ext_csd.part_config, card->ext_csd.part_time); if (err && err != -EBADMSG) goto free_card; } /* * If the host supports the power_off_notify capability then * set the notification byte in the ext_csd register of device */ if ((host->caps2 & MMC_CAP2_POWEROFF_NOTIFY) && (card->ext_csd.rev >= 6)) { err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, EXT_CSD_POWER_OFF_NOTIFICATION, EXT_CSD_POWER_ON, card->ext_csd.generic_cmd6_time); if (err && err != -EBADMSG) goto free_card; /* * The err can be -EBADMSG or 0, * so check for success and update the flag */ if (!err) card->poweroff_notify_state = MMC_POWERED_ON; } /* * Activate high speed (if supported) */ if (card->ext_csd.hs_max_dtr != 0) { err = 0; if (card->ext_csd.hs_max_dtr > 52000000 && host->caps2 & MMC_CAP2_HS200) err = mmc_select_hs200(card); else if (host->caps & MMC_CAP_MMC_HIGHSPEED) err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, EXT_CSD_HS_TIMING, 1, card->ext_csd.generic_cmd6_time); if (err && err != -EBADMSG) goto free_card; if (err) { pr_warning("%s: switch to highspeed failed\n", mmc_hostname(card->host)); err = 0; } else { if (card->ext_csd.hs_max_dtr > 52000000 && host->caps2 & MMC_CAP2_HS200) { mmc_card_set_hs200(card); mmc_set_timing(card->host, MMC_TIMING_MMC_HS200); } else { mmc_card_set_highspeed(card); mmc_set_timing(card->host, MMC_TIMING_MMC_HS); } } } /* * Compute bus speed. */ max_dtr = (unsigned int)-1; if (mmc_card_highspeed(card) || mmc_card_hs200(card)) { if (max_dtr > card->ext_csd.hs_max_dtr) max_dtr = card->ext_csd.hs_max_dtr; } else if (max_dtr > card->csd.max_dtr) { max_dtr = card->csd.max_dtr; } mmc_set_clock(host, max_dtr); /* * Indicate DDR mode (if supported). */ if (mmc_card_highspeed(card)) { if ((card->ext_csd.card_type & EXT_CSD_CARD_TYPE_DDR_1_8V) && ((host->caps & (MMC_CAP_1_8V_DDR | MMC_CAP_UHS_DDR50)) == (MMC_CAP_1_8V_DDR | MMC_CAP_UHS_DDR50))) ddr = MMC_1_8V_DDR_MODE; else if ((card->ext_csd.card_type & EXT_CSD_CARD_TYPE_DDR_1_2V) && ((host->caps & (MMC_CAP_1_2V_DDR | MMC_CAP_UHS_DDR50)) == (MMC_CAP_1_2V_DDR | MMC_CAP_UHS_DDR50))) ddr = MMC_1_2V_DDR_MODE; } /* * Indicate HS200 SDR mode (if supported). */ if (mmc_card_hs200(card)) { u32 ext_csd_bits; u32 bus_width = card->host->ios.bus_width; /* * For devices supporting HS200 mode, the bus width has * to be set before executing the tuning function. If * set before tuning, then device will respond with CRC * errors for responses on CMD line. So for HS200 the * sequence will be * 1. set bus width 4bit / 8 bit (1 bit not supported) * 2. switch to HS200 mode * 3. set the clock to > 52Mhz <=200MHz and * 4. execute tuning for HS200 */ if ((host->caps2 & MMC_CAP2_HS200) && card->host->ops->execute_tuning) { mmc_host_clk_hold(card->host); err = card->host->ops->execute_tuning(card->host, MMC_SEND_TUNING_BLOCK_HS200); mmc_host_clk_release(card->host); } if (err) { pr_warning("%s: tuning execution failed\n", mmc_hostname(card->host)); goto err; } ext_csd_bits = (bus_width == MMC_BUS_WIDTH_8) ? EXT_CSD_BUS_WIDTH_8 : EXT_CSD_BUS_WIDTH_4; err = mmc_select_powerclass(card, ext_csd_bits, ext_csd); if (err) pr_warning("%s: power class selection to bus width %d" " failed\n", mmc_hostname(card->host), 1 << bus_width); } /* * Activate wide bus and DDR (if supported). */ if (!mmc_card_hs200(card) && (card->csd.mmca_vsn >= CSD_SPEC_VER_4) && (host->caps & (MMC_CAP_4_BIT_DATA | MMC_CAP_8_BIT_DATA))) { static unsigned ext_csd_bits[][2] = { { EXT_CSD_BUS_WIDTH_8, EXT_CSD_DDR_BUS_WIDTH_8 }, { EXT_CSD_BUS_WIDTH_4, EXT_CSD_DDR_BUS_WIDTH_4 }, { EXT_CSD_BUS_WIDTH_1, EXT_CSD_BUS_WIDTH_1 }, }; static unsigned bus_widths[] = { MMC_BUS_WIDTH_8, MMC_BUS_WIDTH_4, MMC_BUS_WIDTH_1 }; unsigned idx, bus_width = 0; if (host->caps & MMC_CAP_8_BIT_DATA) idx = 0; else idx = 1; for (; idx < ARRAY_SIZE(bus_widths); idx++) { bus_width = bus_widths[idx]; if (bus_width == MMC_BUS_WIDTH_1) ddr = 0; /* no DDR for 1-bit width */ err = mmc_select_powerclass(card, ext_csd_bits[idx][0], ext_csd); if (err) pr_warning("%s: power class selection to " "bus width %d failed\n", mmc_hostname(card->host), 1 << bus_width); err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, EXT_CSD_BUS_WIDTH, ext_csd_bits[idx][0], card->ext_csd.generic_cmd6_time); if (!err) { mmc_set_bus_width(card->host, bus_width); /* * If controller can't handle bus width test, * compare ext_csd previously read in 1 bit mode * against ext_csd at new bus width */ if (!(host->caps & MMC_CAP_BUS_WIDTH_TEST)) err = mmc_compare_ext_csds(card, bus_width); else err = mmc_bus_test(card, bus_width); if (!err) break; } } if (!err && ddr) { err = mmc_select_powerclass(card, ext_csd_bits[idx][1], ext_csd); if (err) pr_warning("%s: power class selection to " "bus width %d ddr %d failed\n", mmc_hostname(card->host), 1 << bus_width, ddr); err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, EXT_CSD_BUS_WIDTH, ext_csd_bits[idx][1], card->ext_csd.generic_cmd6_time); } if (err) { pr_warning("%s: switch to bus width %d ddr %d " "failed\n", mmc_hostname(card->host), 1 << bus_width, ddr); goto free_card; } else if (ddr) { /* * eMMC cards can support 3.3V to 1.2V i/o (vccq) * signaling. * * EXT_CSD_CARD_TYPE_DDR_1_8V means 3.3V or 1.8V vccq. * * 1.8V vccq at 3.3V core voltage (vcc) is not required * in the JEDEC spec for DDR. * * Do not force change in vccq since we are obviously * working and no change to vccq is needed. * * WARNING: eMMC rules are NOT the same as SD DDR */ if (ddr == MMC_1_2V_DDR_MODE) { err = mmc_set_signal_voltage(host, MMC_SIGNAL_VOLTAGE_120, 0); if (err) goto err; } mmc_card_set_ddr_mode(card); mmc_set_timing(card->host, MMC_TIMING_UHS_DDR50); mmc_set_bus_width(card->host, bus_width); } } /* * Enable HPI feature (if supported) */ if (card->ext_csd.hpi) { err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, EXT_CSD_HPI_MGMT, 1, card->ext_csd.generic_cmd6_time); if (err && err != -EBADMSG) goto free_card; if (err) { pr_warning("%s: Enabling HPI failed\n", mmc_hostname(card->host)); err = 0; } else card->ext_csd.hpi_en = 1; } /* * If cache size is higher than 0, this indicates * the existence of cache and it can be turned on. */ if ((host->caps2 & MMC_CAP2_CACHE_CTRL) && card->ext_csd.cache_size > 0) { err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, EXT_CSD_CACHE_CTRL, 1, card->ext_csd.generic_cmd6_time); if (err && err != -EBADMSG) goto free_card; /* * Only if no error, cache is turned on successfully. */ if (err) { pr_warning("%s: Cache is supported, " "but failed to turn on (%d)\n", mmc_hostname(card->host), err); card->ext_csd.cache_ctrl = 0; err = 0; } else { card->ext_csd.cache_ctrl = 1; } } if (!oldcard) host->card = card; #ifdef CONFIG_MTK_EMMC_SUPPORT_OTP /* enable hc erase grp size */ printk("switch to hc erase grp size\n"); err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, EXT_CSD_ERASE_GROUP_DEF, 1, 0); card->ext_csd.erase_group_def = 1; #endif mmc_free_ext_csd(ext_csd); return 0; free_card: if (!oldcard) mmc_remove_card(card); err: mmc_free_ext_csd(ext_csd); return err; } /* * Host is being removed. Free up the current card. */ static void mmc_remove(struct mmc_host *host) { BUG_ON(!host); BUG_ON(!host->card); mmc_remove_card(host->card); host->card = NULL; } /* * Card detection - card is alive. */ static int mmc_alive(struct mmc_host *host) { return mmc_send_status(host->card, NULL); } /* * Card detection callback from host. */ static void mmc_detect(struct mmc_host *host) { int err; BUG_ON(!host); BUG_ON(!host->card); mmc_claim_host(host); /* * Just check if our card has been removed. */ err = _mmc_detect_card_removed(host); mmc_release_host(host); if (err) { mmc_remove(host); mmc_claim_host(host); mmc_detach_bus(host); mmc_power_off(host); mmc_release_host(host); } } /* * Suspend callback from host. */ static int mmc_suspend(struct mmc_host *host) { int err = 0; BUG_ON(!host); BUG_ON(!host->card); mmc_claim_host(host); if (mmc_card_can_sleep(host)) { err = mmc_card_sleep(host); if (!err) mmc_card_set_sleep(host->card); } else if (!mmc_host_is_spi(host)) mmc_deselect_cards(host); host->card->state &= ~(MMC_STATE_HIGHSPEED | MMC_STATE_HIGHSPEED_200); mmc_release_host(host); return err; } /* * Resume callback from host. * * This function tries to determine if the same card is still present * and, if so, restore all state to it. */ static int mmc_resume(struct mmc_host *host) { int err; BUG_ON(!host); BUG_ON(!host->card); mmc_claim_host(host); if (mmc_card_is_sleep(host->card)) { err = mmc_card_awake(host); mmc_card_clr_sleep(host->card); } else err = mmc_init_card(host, host->ocr, host->card); mmc_release_host(host); return err; } static int mmc_power_restore(struct mmc_host *host) { int ret; host->card->state &= ~(MMC_STATE_HIGHSPEED | MMC_STATE_HIGHSPEED_200); mmc_card_clr_sleep(host->card); mmc_claim_host(host); ret = mmc_init_card(host, host->ocr, host->card); mmc_release_host(host); return ret; } static int mmc_sleep(struct mmc_host *host) { struct mmc_card *card = host->card; int err = -ENOSYS; if (card && card->ext_csd.rev >= 3) { err = mmc_card_sleepawake(host, 1); if (err < 0) pr_debug("%s: Error %d while putting card into sleep", mmc_hostname(host), err); } return err; } static int mmc_awake(struct mmc_host *host) { struct mmc_card *card = host->card; int err = -ENOSYS; if (card && card->ext_csd.rev >= 3) { err = mmc_card_sleepawake(host, 0); if (err < 0) pr_debug("%s: Error %d while awaking sleeping card", mmc_hostname(host), err); } return err; } static const struct mmc_bus_ops mmc_ops = { .awake = mmc_awake, .sleep = mmc_sleep, .remove = mmc_remove, .detect = mmc_detect, .suspend = NULL, .resume = NULL, .power_restore = mmc_power_restore, .alive = mmc_alive, }; static const struct mmc_bus_ops mmc_ops_unsafe = { .awake = mmc_awake, .sleep = mmc_sleep, .remove = mmc_remove, .detect = mmc_detect, .suspend = mmc_suspend, .resume = mmc_resume, .power_restore = mmc_power_restore, .alive = mmc_alive, }; static void mmc_attach_bus_ops(struct mmc_host *host) { const struct mmc_bus_ops *bus_ops; if (!mmc_card_is_removable(host)) bus_ops = &mmc_ops_unsafe; else bus_ops = &mmc_ops; mmc_attach_bus(host, bus_ops); } /* * Starting point for MMC card init. */ int mmc_attach_mmc(struct mmc_host *host) { int err; u32 ocr; BUG_ON(!host); WARN_ON(!host->claimed); /* Set correct bus mode for MMC before attempting attach */ if (!mmc_host_is_spi(host)) mmc_set_bus_mode(host, MMC_BUSMODE_OPENDRAIN); err = mmc_send_op_cond(host, 0, &ocr); if (err) return err; mmc_attach_bus_ops(host); if (host->ocr_avail_mmc) host->ocr_avail = host->ocr_avail_mmc; /* * We need to get OCR a different way for SPI. */ if (mmc_host_is_spi(host)) { err = mmc_spi_read_ocr(host, 1, &ocr); if (err) goto err; } /* * Sanity check the voltages that the card claims to * support. */ if (ocr & 0x7F) { pr_warning("%s: card claims to support voltages " "below the defined range. These will be ignored.\n", mmc_hostname(host)); ocr &= ~0x7F; } host->ocr = mmc_select_voltage(host, ocr); /* * Can we support the voltage of the card? */ if (!host->ocr) { err = -EINVAL; goto err; } /* * Detect and init the card. */ err = mmc_init_card(host, host->ocr, NULL); if (err) goto err; mmc_release_host(host); err = mmc_add_card(host->card); #ifdef CONFIG_MTK_EMMC_SUPPORT //err = init_pmt(); host->card_init_complete(host); #endif mmc_claim_host(host); if (err) goto remove_card; return 0; remove_card: mmc_release_host(host); mmc_remove_card(host->card); mmc_claim_host(host); host->card = NULL; err: mmc_detach_bus(host); pr_err("%s: error %d whilst initialising MMC card\n", mmc_hostname(host), err); return err; }
gpl-2.0
chillwater/linux-3.4
drivers/rtc/rtc-ds1511.c
527
14040
/* * An rtc driver for the Dallas DS1511 * * Copyright (C) 2006 Atsushi Nemoto <anemo@mba.ocn.ne.jp> * Copyright (C) 2007 Andrew Sharp <andy.sharp@lsi.com> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 as * published by the Free Software Foundation. * * Real time clock driver for the Dallas 1511 chip, which also * contains a watchdog timer. There is a tiny amount of code that * platform code could use to mess with the watchdog device a little * bit, but not a full watchdog driver. */ #include <linux/bcd.h> #include <linux/init.h> #include <linux/kernel.h> #include <linux/gfp.h> #include <linux/delay.h> #include <linux/interrupt.h> #include <linux/rtc.h> #include <linux/platform_device.h> #include <linux/io.h> #include <linux/module.h> #define DRV_VERSION "0.6" enum ds1511reg { DS1511_SEC = 0x0, DS1511_MIN = 0x1, DS1511_HOUR = 0x2, DS1511_DOW = 0x3, DS1511_DOM = 0x4, DS1511_MONTH = 0x5, DS1511_YEAR = 0x6, DS1511_CENTURY = 0x7, DS1511_AM1_SEC = 0x8, DS1511_AM2_MIN = 0x9, DS1511_AM3_HOUR = 0xa, DS1511_AM4_DATE = 0xb, DS1511_WD_MSEC = 0xc, DS1511_WD_SEC = 0xd, DS1511_CONTROL_A = 0xe, DS1511_CONTROL_B = 0xf, DS1511_RAMADDR_LSB = 0x10, DS1511_RAMDATA = 0x13 }; #define DS1511_BLF1 0x80 #define DS1511_BLF2 0x40 #define DS1511_PRS 0x20 #define DS1511_PAB 0x10 #define DS1511_TDF 0x08 #define DS1511_KSF 0x04 #define DS1511_WDF 0x02 #define DS1511_IRQF 0x01 #define DS1511_TE 0x80 #define DS1511_CS 0x40 #define DS1511_BME 0x20 #define DS1511_TPE 0x10 #define DS1511_TIE 0x08 #define DS1511_KIE 0x04 #define DS1511_WDE 0x02 #define DS1511_WDS 0x01 #define DS1511_RAM_MAX 0xff #define RTC_CMD DS1511_CONTROL_B #define RTC_CMD1 DS1511_CONTROL_A #define RTC_ALARM_SEC DS1511_AM1_SEC #define RTC_ALARM_MIN DS1511_AM2_MIN #define RTC_ALARM_HOUR DS1511_AM3_HOUR #define RTC_ALARM_DATE DS1511_AM4_DATE #define RTC_SEC DS1511_SEC #define RTC_MIN DS1511_MIN #define RTC_HOUR DS1511_HOUR #define RTC_DOW DS1511_DOW #define RTC_DOM DS1511_DOM #define RTC_MON DS1511_MONTH #define RTC_YEAR DS1511_YEAR #define RTC_CENTURY DS1511_CENTURY #define RTC_TIE DS1511_TIE #define RTC_TE DS1511_TE struct rtc_plat_data { struct rtc_device *rtc; void __iomem *ioaddr; /* virtual base address */ int irq; unsigned int irqen; int alrm_sec; int alrm_min; int alrm_hour; int alrm_mday; spinlock_t lock; }; static DEFINE_SPINLOCK(ds1511_lock); static __iomem char *ds1511_base; static u32 reg_spacing = 1; static noinline void rtc_write(uint8_t val, uint32_t reg) { writeb(val, ds1511_base + (reg * reg_spacing)); } static inline void rtc_write_alarm(uint8_t val, enum ds1511reg reg) { rtc_write((val | 0x80), reg); } static noinline uint8_t rtc_read(enum ds1511reg reg) { return readb(ds1511_base + (reg * reg_spacing)); } static inline void rtc_disable_update(void) { rtc_write((rtc_read(RTC_CMD) & ~RTC_TE), RTC_CMD); } static void rtc_enable_update(void) { rtc_write((rtc_read(RTC_CMD) | RTC_TE), RTC_CMD); } /* * #define DS1511_WDOG_RESET_SUPPORT * * Uncomment this if you want to use these routines in * some platform code. */ #ifdef DS1511_WDOG_RESET_SUPPORT /* * just enough code to set the watchdog timer so that it * will reboot the system */ void ds1511_wdog_set(unsigned long deciseconds) { /* * the wdog timer can take 99.99 seconds */ deciseconds %= 10000; /* * set the wdog values in the wdog registers */ rtc_write(bin2bcd(deciseconds % 100), DS1511_WD_MSEC); rtc_write(bin2bcd(deciseconds / 100), DS1511_WD_SEC); /* * set wdog enable and wdog 'steering' bit to issue a reset */ rtc_write(DS1511_WDE | DS1511_WDS, RTC_CMD); } void ds1511_wdog_disable(void) { /* * clear wdog enable and wdog 'steering' bits */ rtc_write(rtc_read(RTC_CMD) & ~(DS1511_WDE | DS1511_WDS), RTC_CMD); /* * clear the wdog counter */ rtc_write(0, DS1511_WD_MSEC); rtc_write(0, DS1511_WD_SEC); } #endif /* * set the rtc chip's idea of the time. * stupidly, some callers call with year unmolested; * and some call with year = year - 1900. thanks. */ static int ds1511_rtc_set_time(struct device *dev, struct rtc_time *rtc_tm) { u8 mon, day, dow, hrs, min, sec, yrs, cen; unsigned long flags; /* * won't have to change this for a while */ if (rtc_tm->tm_year < 1900) rtc_tm->tm_year += 1900; if (rtc_tm->tm_year < 1970) return -EINVAL; yrs = rtc_tm->tm_year % 100; cen = rtc_tm->tm_year / 100; mon = rtc_tm->tm_mon + 1; /* tm_mon starts at zero */ day = rtc_tm->tm_mday; dow = rtc_tm->tm_wday & 0x7; /* automatic BCD */ hrs = rtc_tm->tm_hour; min = rtc_tm->tm_min; sec = rtc_tm->tm_sec; if ((mon > 12) || (day == 0)) return -EINVAL; if (day > rtc_month_days(rtc_tm->tm_mon, rtc_tm->tm_year)) return -EINVAL; if ((hrs >= 24) || (min >= 60) || (sec >= 60)) return -EINVAL; /* * each register is a different number of valid bits */ sec = bin2bcd(sec) & 0x7f; min = bin2bcd(min) & 0x7f; hrs = bin2bcd(hrs) & 0x3f; day = bin2bcd(day) & 0x3f; mon = bin2bcd(mon) & 0x1f; yrs = bin2bcd(yrs) & 0xff; cen = bin2bcd(cen) & 0xff; spin_lock_irqsave(&ds1511_lock, flags); rtc_disable_update(); rtc_write(cen, RTC_CENTURY); rtc_write(yrs, RTC_YEAR); rtc_write((rtc_read(RTC_MON) & 0xe0) | mon, RTC_MON); rtc_write(day, RTC_DOM); rtc_write(hrs, RTC_HOUR); rtc_write(min, RTC_MIN); rtc_write(sec, RTC_SEC); rtc_write(dow, RTC_DOW); rtc_enable_update(); spin_unlock_irqrestore(&ds1511_lock, flags); return 0; } static int ds1511_rtc_read_time(struct device *dev, struct rtc_time *rtc_tm) { unsigned int century; unsigned long flags; spin_lock_irqsave(&ds1511_lock, flags); rtc_disable_update(); rtc_tm->tm_sec = rtc_read(RTC_SEC) & 0x7f; rtc_tm->tm_min = rtc_read(RTC_MIN) & 0x7f; rtc_tm->tm_hour = rtc_read(RTC_HOUR) & 0x3f; rtc_tm->tm_mday = rtc_read(RTC_DOM) & 0x3f; rtc_tm->tm_wday = rtc_read(RTC_DOW) & 0x7; rtc_tm->tm_mon = rtc_read(RTC_MON) & 0x1f; rtc_tm->tm_year = rtc_read(RTC_YEAR) & 0x7f; century = rtc_read(RTC_CENTURY); rtc_enable_update(); spin_unlock_irqrestore(&ds1511_lock, flags); rtc_tm->tm_sec = bcd2bin(rtc_tm->tm_sec); rtc_tm->tm_min = bcd2bin(rtc_tm->tm_min); rtc_tm->tm_hour = bcd2bin(rtc_tm->tm_hour); rtc_tm->tm_mday = bcd2bin(rtc_tm->tm_mday); rtc_tm->tm_wday = bcd2bin(rtc_tm->tm_wday); rtc_tm->tm_mon = bcd2bin(rtc_tm->tm_mon); rtc_tm->tm_year = bcd2bin(rtc_tm->tm_year); century = bcd2bin(century) * 100; /* * Account for differences between how the RTC uses the values * and how they are defined in a struct rtc_time; */ century += rtc_tm->tm_year; rtc_tm->tm_year = century - 1900; rtc_tm->tm_mon--; if (rtc_valid_tm(rtc_tm) < 0) { dev_err(dev, "retrieved date/time is not valid.\n"); rtc_time_to_tm(0, rtc_tm); } return 0; } /* * write the alarm register settings * * we only have the use to interrupt every second, otherwise * known as the update interrupt, or the interrupt if the whole * date/hours/mins/secs matches. the ds1511 has many more * permutations, but the kernel doesn't. */ static void ds1511_rtc_update_alarm(struct rtc_plat_data *pdata) { unsigned long flags; spin_lock_irqsave(&pdata->lock, flags); rtc_write(pdata->alrm_mday < 0 || (pdata->irqen & RTC_UF) ? 0x80 : bin2bcd(pdata->alrm_mday) & 0x3f, RTC_ALARM_DATE); rtc_write(pdata->alrm_hour < 0 || (pdata->irqen & RTC_UF) ? 0x80 : bin2bcd(pdata->alrm_hour) & 0x3f, RTC_ALARM_HOUR); rtc_write(pdata->alrm_min < 0 || (pdata->irqen & RTC_UF) ? 0x80 : bin2bcd(pdata->alrm_min) & 0x7f, RTC_ALARM_MIN); rtc_write(pdata->alrm_sec < 0 || (pdata->irqen & RTC_UF) ? 0x80 : bin2bcd(pdata->alrm_sec) & 0x7f, RTC_ALARM_SEC); rtc_write(rtc_read(RTC_CMD) | (pdata->irqen ? RTC_TIE : 0), RTC_CMD); rtc_read(RTC_CMD1); /* clear interrupts */ spin_unlock_irqrestore(&pdata->lock, flags); } static int ds1511_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm) { struct platform_device *pdev = to_platform_device(dev); struct rtc_plat_data *pdata = platform_get_drvdata(pdev); if (pdata->irq <= 0) return -EINVAL; pdata->alrm_mday = alrm->time.tm_mday; pdata->alrm_hour = alrm->time.tm_hour; pdata->alrm_min = alrm->time.tm_min; pdata->alrm_sec = alrm->time.tm_sec; if (alrm->enabled) pdata->irqen |= RTC_AF; ds1511_rtc_update_alarm(pdata); return 0; } static int ds1511_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm) { struct platform_device *pdev = to_platform_device(dev); struct rtc_plat_data *pdata = platform_get_drvdata(pdev); if (pdata->irq <= 0) return -EINVAL; alrm->time.tm_mday = pdata->alrm_mday < 0 ? 0 : pdata->alrm_mday; alrm->time.tm_hour = pdata->alrm_hour < 0 ? 0 : pdata->alrm_hour; alrm->time.tm_min = pdata->alrm_min < 0 ? 0 : pdata->alrm_min; alrm->time.tm_sec = pdata->alrm_sec < 0 ? 0 : pdata->alrm_sec; alrm->enabled = (pdata->irqen & RTC_AF) ? 1 : 0; return 0; } static irqreturn_t ds1511_interrupt(int irq, void *dev_id) { struct platform_device *pdev = dev_id; struct rtc_plat_data *pdata = platform_get_drvdata(pdev); unsigned long events = 0; spin_lock(&pdata->lock); /* * read and clear interrupt */ if (rtc_read(RTC_CMD1) & DS1511_IRQF) { events = RTC_IRQF; if (rtc_read(RTC_ALARM_SEC) & 0x80) events |= RTC_UF; else events |= RTC_AF; rtc_update_irq(pdata->rtc, 1, events); } spin_unlock(&pdata->lock); return events ? IRQ_HANDLED : IRQ_NONE; } static int ds1511_rtc_alarm_irq_enable(struct device *dev, unsigned int enabled) { struct platform_device *pdev = to_platform_device(dev); struct rtc_plat_data *pdata = platform_get_drvdata(pdev); if (pdata->irq <= 0) return -EINVAL; if (enabled) pdata->irqen |= RTC_AF; else pdata->irqen &= ~RTC_AF; ds1511_rtc_update_alarm(pdata); return 0; } static const struct rtc_class_ops ds1511_rtc_ops = { .read_time = ds1511_rtc_read_time, .set_time = ds1511_rtc_set_time, .read_alarm = ds1511_rtc_read_alarm, .set_alarm = ds1511_rtc_set_alarm, .alarm_irq_enable = ds1511_rtc_alarm_irq_enable, }; static ssize_t ds1511_nvram_read(struct file *filp, struct kobject *kobj, struct bin_attribute *ba, char *buf, loff_t pos, size_t size) { ssize_t count; /* * if count is more than one, turn on "burst" mode * turn it off when you're done */ if (size > 1) rtc_write((rtc_read(RTC_CMD) | DS1511_BME), RTC_CMD); if (pos > DS1511_RAM_MAX) pos = DS1511_RAM_MAX; if (size + pos > DS1511_RAM_MAX + 1) size = DS1511_RAM_MAX - pos + 1; rtc_write(pos, DS1511_RAMADDR_LSB); for (count = 0; size > 0; count++, size--) *buf++ = rtc_read(DS1511_RAMDATA); if (count > 1) rtc_write((rtc_read(RTC_CMD) & ~DS1511_BME), RTC_CMD); return count; } static ssize_t ds1511_nvram_write(struct file *filp, struct kobject *kobj, struct bin_attribute *bin_attr, char *buf, loff_t pos, size_t size) { ssize_t count; /* * if count is more than one, turn on "burst" mode * turn it off when you're done */ if (size > 1) rtc_write((rtc_read(RTC_CMD) | DS1511_BME), RTC_CMD); if (pos > DS1511_RAM_MAX) pos = DS1511_RAM_MAX; if (size + pos > DS1511_RAM_MAX + 1) size = DS1511_RAM_MAX - pos + 1; rtc_write(pos, DS1511_RAMADDR_LSB); for (count = 0; size > 0; count++, size--) rtc_write(*buf++, DS1511_RAMDATA); if (count > 1) rtc_write((rtc_read(RTC_CMD) & ~DS1511_BME), RTC_CMD); return count; } static struct bin_attribute ds1511_nvram_attr = { .attr = { .name = "nvram", .mode = S_IRUGO | S_IWUSR, }, .size = DS1511_RAM_MAX, .read = ds1511_nvram_read, .write = ds1511_nvram_write, }; static int ds1511_rtc_probe(struct platform_device *pdev) { struct resource *res; struct rtc_plat_data *pdata; int ret = 0; pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL); if (!pdata) return -ENOMEM; res = platform_get_resource(pdev, IORESOURCE_MEM, 0); ds1511_base = devm_ioremap_resource(&pdev->dev, res); if (IS_ERR(ds1511_base)) return PTR_ERR(ds1511_base); pdata->ioaddr = ds1511_base; pdata->irq = platform_get_irq(pdev, 0); /* * turn on the clock and the crystal, etc. */ rtc_write(0, RTC_CMD); rtc_write(0, RTC_CMD1); /* * clear the wdog counter */ rtc_write(0, DS1511_WD_MSEC); rtc_write(0, DS1511_WD_SEC); /* * start the clock */ rtc_enable_update(); /* * check for a dying bat-tree */ if (rtc_read(RTC_CMD1) & DS1511_BLF1) dev_warn(&pdev->dev, "voltage-low detected.\n"); spin_lock_init(&pdata->lock); platform_set_drvdata(pdev, pdata); pdata->rtc = devm_rtc_device_register(&pdev->dev, pdev->name, &ds1511_rtc_ops, THIS_MODULE); if (IS_ERR(pdata->rtc)) return PTR_ERR(pdata->rtc); /* * if the platform has an interrupt in mind for this device, * then by all means, set it */ if (pdata->irq > 0) { rtc_read(RTC_CMD1); if (devm_request_irq(&pdev->dev, pdata->irq, ds1511_interrupt, IRQF_SHARED, pdev->name, pdev) < 0) { dev_warn(&pdev->dev, "interrupt not available.\n"); pdata->irq = 0; } } ret = sysfs_create_bin_file(&pdev->dev.kobj, &ds1511_nvram_attr); if (ret) dev_err(&pdev->dev, "Unable to create sysfs entry: %s\n", ds1511_nvram_attr.attr.name); return 0; } static int ds1511_rtc_remove(struct platform_device *pdev) { struct rtc_plat_data *pdata = platform_get_drvdata(pdev); sysfs_remove_bin_file(&pdev->dev.kobj, &ds1511_nvram_attr); if (pdata->irq > 0) { /* * disable the alarm interrupt */ rtc_write(rtc_read(RTC_CMD) & ~RTC_TIE, RTC_CMD); rtc_read(RTC_CMD1); } return 0; } /* work with hotplug and coldplug */ MODULE_ALIAS("platform:ds1511"); static struct platform_driver ds1511_rtc_driver = { .probe = ds1511_rtc_probe, .remove = ds1511_rtc_remove, .driver = { .name = "ds1511", .owner = THIS_MODULE, }, }; module_platform_driver(ds1511_rtc_driver); MODULE_AUTHOR("Andrew Sharp <andy.sharp@lsi.com>"); MODULE_DESCRIPTION("Dallas DS1511 RTC driver"); MODULE_LICENSE("GPL"); MODULE_VERSION(DRV_VERSION);
gpl-2.0
webbhorn/netgroups
drivers/staging/rtl8192u/ieee80211/ieee80211_crypt_ccmp.c
527
11403
/* * Host AP crypt: host-based CCMP encryption implementation for Host AP driver * * Copyright (c) 2003-2004, Jouni Malinen <jkmaline@cc.hut.fi> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 as * published by the Free Software Foundation. See README and COPYING for * more details. */ //#include <linux/config.h> #include <linux/module.h> #include <linux/init.h> #include <linux/slab.h> #include <linux/random.h> #include <linux/skbuff.h> #include <linux/netdevice.h> #include <linux/if_ether.h> #include <linux/if_arp.h> #include <asm/string.h> #include <linux/wireless.h> #include "ieee80211.h" #include <linux/crypto.h> #include <linux/scatterlist.h> MODULE_AUTHOR("Jouni Malinen"); MODULE_DESCRIPTION("Host AP crypt: CCMP"); MODULE_LICENSE("GPL"); #define AES_BLOCK_LEN 16 #define CCMP_HDR_LEN 8 #define CCMP_MIC_LEN 8 #define CCMP_TK_LEN 16 #define CCMP_PN_LEN 6 struct ieee80211_ccmp_data { u8 key[CCMP_TK_LEN]; int key_set; u8 tx_pn[CCMP_PN_LEN]; u8 rx_pn[CCMP_PN_LEN]; u32 dot11RSNAStatsCCMPFormatErrors; u32 dot11RSNAStatsCCMPReplays; u32 dot11RSNAStatsCCMPDecryptErrors; int key_idx; struct crypto_tfm *tfm; /* scratch buffers for virt_to_page() (crypto API) */ u8 tx_b0[AES_BLOCK_LEN], tx_b[AES_BLOCK_LEN], tx_e[AES_BLOCK_LEN], tx_s0[AES_BLOCK_LEN]; u8 rx_b0[AES_BLOCK_LEN], rx_b[AES_BLOCK_LEN], rx_a[AES_BLOCK_LEN]; }; void ieee80211_ccmp_aes_encrypt(struct crypto_tfm *tfm, const u8 pt[16], u8 ct[16]) { crypto_cipher_encrypt_one((void *)tfm, ct, pt); } static void *ieee80211_ccmp_init(int key_idx) { struct ieee80211_ccmp_data *priv; priv = kzalloc(sizeof(*priv), GFP_ATOMIC); if (priv == NULL) goto fail; priv->key_idx = key_idx; priv->tfm = (void *)crypto_alloc_cipher("aes", 0, CRYPTO_ALG_ASYNC); if (IS_ERR(priv->tfm)) { printk(KERN_DEBUG "ieee80211_crypt_ccmp: could not allocate " "crypto API aes\n"); priv->tfm = NULL; goto fail; } return priv; fail: if (priv) { if (priv->tfm) crypto_free_cipher((void *)priv->tfm); kfree(priv); } return NULL; } static void ieee80211_ccmp_deinit(void *priv) { struct ieee80211_ccmp_data *_priv = priv; if (_priv && _priv->tfm) crypto_free_cipher((void *)_priv->tfm); kfree(priv); } static inline void xor_block(u8 *b, u8 *a, size_t len) { int i; for (i = 0; i < len; i++) b[i] ^= a[i]; } static void ccmp_init_blocks(struct crypto_tfm *tfm, struct ieee80211_hdr_4addr *hdr, u8 *pn, size_t dlen, u8 *b0, u8 *auth, u8 *s0) { u8 *pos, qc = 0; size_t aad_len; u16 fc; int a4_included, qc_included; u8 aad[2 * AES_BLOCK_LEN]; fc = le16_to_cpu(hdr->frame_ctl); a4_included = ((fc & (IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS)) == (IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS)); /* qc_included = ((WLAN_FC_GET_TYPE(fc) == IEEE80211_FTYPE_DATA) && (WLAN_FC_GET_STYPE(fc) & 0x08)); */ // fixed by David :2006.9.6 qc_included = ((WLAN_FC_GET_TYPE(fc) == IEEE80211_FTYPE_DATA) && (WLAN_FC_GET_STYPE(fc) & 0x80)); aad_len = 22; if (a4_included) aad_len += 6; if (qc_included) { pos = (u8 *) &hdr->addr4; if (a4_included) pos += 6; qc = *pos & 0x0f; aad_len += 2; } /* CCM Initial Block: * Flag (Include authentication header, M=3 (8-octet MIC), * L=1 (2-octet Dlen)) * Nonce: 0x00 | A2 | PN * Dlen */ b0[0] = 0x59; b0[1] = qc; memcpy(b0 + 2, hdr->addr2, ETH_ALEN); memcpy(b0 + 8, pn, CCMP_PN_LEN); b0[14] = (dlen >> 8) & 0xff; b0[15] = dlen & 0xff; /* AAD: * FC with bits 4..6 and 11..13 masked to zero; 14 is always one * A1 | A2 | A3 * SC with bits 4..15 (seq#) masked to zero * A4 (if present) * QC (if present) */ pos = (u8 *) hdr; aad[0] = 0; /* aad_len >> 8 */ aad[1] = aad_len & 0xff; aad[2] = pos[0] & 0x8f; aad[3] = pos[1] & 0xc7; memcpy(aad + 4, hdr->addr1, 3 * ETH_ALEN); pos = (u8 *) &hdr->seq_ctl; aad[22] = pos[0] & 0x0f; aad[23] = 0; /* all bits masked */ memset(aad + 24, 0, 8); if (a4_included) memcpy(aad + 24, hdr->addr4, ETH_ALEN); if (qc_included) { aad[a4_included ? 30 : 24] = qc; /* rest of QC masked */ } /* Start with the first block and AAD */ ieee80211_ccmp_aes_encrypt(tfm, b0, auth); xor_block(auth, aad, AES_BLOCK_LEN); ieee80211_ccmp_aes_encrypt(tfm, auth, auth); xor_block(auth, &aad[AES_BLOCK_LEN], AES_BLOCK_LEN); ieee80211_ccmp_aes_encrypt(tfm, auth, auth); b0[0] &= 0x07; b0[14] = b0[15] = 0; ieee80211_ccmp_aes_encrypt(tfm, b0, s0); } static int ieee80211_ccmp_encrypt(struct sk_buff *skb, int hdr_len, void *priv) { struct ieee80211_ccmp_data *key = priv; int data_len, i; u8 *pos; struct ieee80211_hdr_4addr *hdr; cb_desc *tcb_desc = (cb_desc *)(skb->cb + MAX_DEV_ADDR_SIZE); if (skb_headroom(skb) < CCMP_HDR_LEN || skb_tailroom(skb) < CCMP_MIC_LEN || skb->len < hdr_len) return -1; data_len = skb->len - hdr_len; pos = skb_push(skb, CCMP_HDR_LEN); memmove(pos, pos + CCMP_HDR_LEN, hdr_len); pos += hdr_len; // mic = skb_put(skb, CCMP_MIC_LEN); i = CCMP_PN_LEN - 1; while (i >= 0) { key->tx_pn[i]++; if (key->tx_pn[i] != 0) break; i--; } *pos++ = key->tx_pn[5]; *pos++ = key->tx_pn[4]; *pos++ = 0; *pos++ = (key->key_idx << 6) | (1 << 5) /* Ext IV included */; *pos++ = key->tx_pn[3]; *pos++ = key->tx_pn[2]; *pos++ = key->tx_pn[1]; *pos++ = key->tx_pn[0]; hdr = (struct ieee80211_hdr_4addr *) skb->data; if (!tcb_desc->bHwSec) { int blocks, last, len; u8 *mic; u8 *b0 = key->tx_b0; u8 *b = key->tx_b; u8 *e = key->tx_e; u8 *s0 = key->tx_s0; //mic is moved to here by john mic = skb_put(skb, CCMP_MIC_LEN); ccmp_init_blocks(key->tfm, hdr, key->tx_pn, data_len, b0, b, s0); blocks = (data_len + AES_BLOCK_LEN - 1) / AES_BLOCK_LEN; last = data_len % AES_BLOCK_LEN; for (i = 1; i <= blocks; i++) { len = (i == blocks && last) ? last : AES_BLOCK_LEN; /* Authentication */ xor_block(b, pos, len); ieee80211_ccmp_aes_encrypt(key->tfm, b, b); /* Encryption, with counter */ b0[14] = (i >> 8) & 0xff; b0[15] = i & 0xff; ieee80211_ccmp_aes_encrypt(key->tfm, b0, e); xor_block(pos, e, len); pos += len; } for (i = 0; i < CCMP_MIC_LEN; i++) mic[i] = b[i] ^ s0[i]; } return 0; } static int ieee80211_ccmp_decrypt(struct sk_buff *skb, int hdr_len, void *priv) { struct ieee80211_ccmp_data *key = priv; u8 keyidx, *pos; struct ieee80211_hdr_4addr *hdr; cb_desc *tcb_desc = (cb_desc *)(skb->cb + MAX_DEV_ADDR_SIZE); u8 pn[6]; if (skb->len < hdr_len + CCMP_HDR_LEN + CCMP_MIC_LEN) { key->dot11RSNAStatsCCMPFormatErrors++; return -1; } hdr = (struct ieee80211_hdr_4addr *) skb->data; pos = skb->data + hdr_len; keyidx = pos[3]; if (!(keyidx & (1 << 5))) { if (net_ratelimit()) { printk(KERN_DEBUG "CCMP: received packet without ExtIV" " flag from %pM\n", hdr->addr2); } key->dot11RSNAStatsCCMPFormatErrors++; return -2; } keyidx >>= 6; if (key->key_idx != keyidx) { printk(KERN_DEBUG "CCMP: RX tkey->key_idx=%d frame " "keyidx=%d priv=%p\n", key->key_idx, keyidx, priv); return -6; } if (!key->key_set) { if (net_ratelimit()) { printk(KERN_DEBUG "CCMP: received packet from %pM" " with keyid=%d that does not have a configured" " key\n", hdr->addr2, keyidx); } return -3; } pn[0] = pos[7]; pn[1] = pos[6]; pn[2] = pos[5]; pn[3] = pos[4]; pn[4] = pos[1]; pn[5] = pos[0]; pos += 8; if (memcmp(pn, key->rx_pn, CCMP_PN_LEN) <= 0) { if (net_ratelimit()) { printk(KERN_DEBUG "CCMP: replay detected: STA=%pM" " previous PN %pm received PN %pm\n", hdr->addr2, key->rx_pn, pn); } key->dot11RSNAStatsCCMPReplays++; return -4; } if (!tcb_desc->bHwSec) { size_t data_len = skb->len - hdr_len - CCMP_HDR_LEN - CCMP_MIC_LEN; u8 *mic = skb->data + skb->len - CCMP_MIC_LEN; u8 *b0 = key->rx_b0; u8 *b = key->rx_b; u8 *a = key->rx_a; int i, blocks, last, len; ccmp_init_blocks(key->tfm, hdr, pn, data_len, b0, a, b); xor_block(mic, b, CCMP_MIC_LEN); blocks = (data_len + AES_BLOCK_LEN - 1) / AES_BLOCK_LEN; last = data_len % AES_BLOCK_LEN; for (i = 1; i <= blocks; i++) { len = (i == blocks && last) ? last : AES_BLOCK_LEN; /* Decrypt, with counter */ b0[14] = (i >> 8) & 0xff; b0[15] = i & 0xff; ieee80211_ccmp_aes_encrypt(key->tfm, b0, b); xor_block(pos, b, len); /* Authentication */ xor_block(a, pos, len); ieee80211_ccmp_aes_encrypt(key->tfm, a, a); pos += len; } if (memcmp(mic, a, CCMP_MIC_LEN) != 0) { if (net_ratelimit()) { printk(KERN_DEBUG "CCMP: decrypt failed: STA=" "%pM\n", hdr->addr2); } key->dot11RSNAStatsCCMPDecryptErrors++; return -5; } memcpy(key->rx_pn, pn, CCMP_PN_LEN); } /* Remove hdr and MIC */ memmove(skb->data + CCMP_HDR_LEN, skb->data, hdr_len); skb_pull(skb, CCMP_HDR_LEN); skb_trim(skb, skb->len - CCMP_MIC_LEN); return keyidx; } static int ieee80211_ccmp_set_key(void *key, int len, u8 *seq, void *priv) { struct ieee80211_ccmp_data *data = priv; int keyidx; struct crypto_tfm *tfm = data->tfm; keyidx = data->key_idx; memset(data, 0, sizeof(*data)); data->key_idx = keyidx; data->tfm = tfm; if (len == CCMP_TK_LEN) { memcpy(data->key, key, CCMP_TK_LEN); data->key_set = 1; if (seq) { data->rx_pn[0] = seq[5]; data->rx_pn[1] = seq[4]; data->rx_pn[2] = seq[3]; data->rx_pn[3] = seq[2]; data->rx_pn[4] = seq[1]; data->rx_pn[5] = seq[0]; } crypto_cipher_setkey((void *)data->tfm, data->key, CCMP_TK_LEN); } else if (len == 0) data->key_set = 0; else return -1; return 0; } static int ieee80211_ccmp_get_key(void *key, int len, u8 *seq, void *priv) { struct ieee80211_ccmp_data *data = priv; if (len < CCMP_TK_LEN) return -1; if (!data->key_set) return 0; memcpy(key, data->key, CCMP_TK_LEN); if (seq) { seq[0] = data->tx_pn[5]; seq[1] = data->tx_pn[4]; seq[2] = data->tx_pn[3]; seq[3] = data->tx_pn[2]; seq[4] = data->tx_pn[1]; seq[5] = data->tx_pn[0]; } return CCMP_TK_LEN; } static char *ieee80211_ccmp_print_stats(char *p, void *priv) { struct ieee80211_ccmp_data *ccmp = priv; p += sprintf(p, "key[%d] alg=CCMP key_set=%d " "tx_pn=%pm rx_pn=%pm " "format_errors=%d replays=%d decrypt_errors=%d\n", ccmp->key_idx, ccmp->key_set, ccmp->tx_pn, ccmp->rx_pn, ccmp->dot11RSNAStatsCCMPFormatErrors, ccmp->dot11RSNAStatsCCMPReplays, ccmp->dot11RSNAStatsCCMPDecryptErrors); return p; } void ieee80211_ccmp_null(void) { // printk("============>%s()\n", __FUNCTION__); return; } static struct ieee80211_crypto_ops ieee80211_crypt_ccmp = { .name = "CCMP", .init = ieee80211_ccmp_init, .deinit = ieee80211_ccmp_deinit, .encrypt_mpdu = ieee80211_ccmp_encrypt, .decrypt_mpdu = ieee80211_ccmp_decrypt, .encrypt_msdu = NULL, .decrypt_msdu = NULL, .set_key = ieee80211_ccmp_set_key, .get_key = ieee80211_ccmp_get_key, .print_stats = ieee80211_ccmp_print_stats, .extra_prefix_len = CCMP_HDR_LEN, .extra_postfix_len = CCMP_MIC_LEN, .owner = THIS_MODULE, }; int __init ieee80211_crypto_ccmp_init(void) { return ieee80211_register_crypto_ops(&ieee80211_crypt_ccmp); } void __exit ieee80211_crypto_ccmp_exit(void) { ieee80211_unregister_crypto_ops(&ieee80211_crypt_ccmp); }
gpl-2.0
barakinflorida/samsung-kernel-aries
drivers/staging/hv/StorVsc.c
527
23585
/* * Copyright (c) 2009, Microsoft Corporation. * * This program is free software; you can redistribute it and/or modify it * under the terms and conditions of the GNU General Public License, * version 2, as published by the Free Software Foundation. * * This program is distributed in the hope it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * more details. * * You should have received a copy of the GNU General Public License along with * this program; if not, write to the Free Software Foundation, Inc., 59 Temple * Place - Suite 330, Boston, MA 02111-1307 USA. * * Authors: * Haiyang Zhang <haiyangz@microsoft.com> * Hank Janssen <hjanssen@microsoft.com> */ #include <linux/kernel.h> #include <linux/string.h> #include <linux/mm.h> #include <linux/delay.h> #include "osd.h" #include "logging.h" #include "StorVscApi.h" #include "VmbusPacketFormat.h" #include "vstorage.h" struct storvsc_request_extension { /* LIST_ENTRY ListEntry; */ struct hv_storvsc_request *Request; struct hv_device *Device; /* Synchronize the request/response if needed */ struct osd_waitevent *WaitEvent; struct vstor_packet VStorPacket; }; /* A storvsc device is a device object that contains a vmbus channel */ struct storvsc_device { struct hv_device *Device; /* 0 indicates the device is being destroyed */ atomic_t RefCount; atomic_t NumOutstandingRequests; /* * Each unique Port/Path/Target represents 1 channel ie scsi * controller. In reality, the pathid, targetid is always 0 * and the port is set by us */ unsigned int PortNumber; unsigned char PathId; unsigned char TargetId; /* LIST_ENTRY OutstandingRequestList; */ /* HANDLE OutstandingRequestLock; */ /* Used for vsc/vsp channel reset process */ struct storvsc_request_extension InitRequest; struct storvsc_request_extension ResetRequest; }; static const char *gDriverName = "storvsc"; /* {ba6163d9-04a1-4d29-b605-72e2ffb1dc7f} */ static const struct hv_guid gStorVscDeviceType = { .data = { 0xd9, 0x63, 0x61, 0xba, 0xa1, 0x04, 0x29, 0x4d, 0xb6, 0x05, 0x72, 0xe2, 0xff, 0xb1, 0xdc, 0x7f } }; static inline struct storvsc_device *AllocStorDevice(struct hv_device *Device) { struct storvsc_device *storDevice; storDevice = kzalloc(sizeof(struct storvsc_device), GFP_KERNEL); if (!storDevice) return NULL; /* Set to 2 to allow both inbound and outbound traffics */ /* (ie GetStorDevice() and MustGetStorDevice()) to proceed. */ atomic_cmpxchg(&storDevice->RefCount, 0, 2); storDevice->Device = Device; Device->Extension = storDevice; return storDevice; } static inline void FreeStorDevice(struct storvsc_device *Device) { ASSERT(atomic_read(&Device->RefCount) == 0); kfree(Device); } /* Get the stordevice object iff exists and its refcount > 1 */ static inline struct storvsc_device *GetStorDevice(struct hv_device *Device) { struct storvsc_device *storDevice; storDevice = (struct storvsc_device *)Device->Extension; if (storDevice && atomic_read(&storDevice->RefCount) > 1) atomic_inc(&storDevice->RefCount); else storDevice = NULL; return storDevice; } /* Get the stordevice object iff exists and its refcount > 0 */ static inline struct storvsc_device *MustGetStorDevice(struct hv_device *Device) { struct storvsc_device *storDevice; storDevice = (struct storvsc_device *)Device->Extension; if (storDevice && atomic_read(&storDevice->RefCount)) atomic_inc(&storDevice->RefCount); else storDevice = NULL; return storDevice; } static inline void PutStorDevice(struct hv_device *Device) { struct storvsc_device *storDevice; storDevice = (struct storvsc_device *)Device->Extension; ASSERT(storDevice); atomic_dec(&storDevice->RefCount); ASSERT(atomic_read(&storDevice->RefCount)); } /* Drop ref count to 1 to effectively disable GetStorDevice() */ static inline struct storvsc_device *ReleaseStorDevice(struct hv_device *Device) { struct storvsc_device *storDevice; storDevice = (struct storvsc_device *)Device->Extension; ASSERT(storDevice); /* Busy wait until the ref drop to 2, then set it to 1 */ while (atomic_cmpxchg(&storDevice->RefCount, 2, 1) != 2) udelay(100); return storDevice; } /* Drop ref count to 0. No one can use StorDevice object. */ static inline struct storvsc_device *FinalReleaseStorDevice( struct hv_device *Device) { struct storvsc_device *storDevice; storDevice = (struct storvsc_device *)Device->Extension; ASSERT(storDevice); /* Busy wait until the ref drop to 1, then set it to 0 */ while (atomic_cmpxchg(&storDevice->RefCount, 1, 0) != 1) udelay(100); Device->Extension = NULL; return storDevice; } static int StorVscChannelInit(struct hv_device *Device) { struct storvsc_device *storDevice; struct storvsc_request_extension *request; struct vstor_packet *vstorPacket; int ret; storDevice = GetStorDevice(Device); if (!storDevice) { DPRINT_ERR(STORVSC, "unable to get stor device..." "device being destroyed?"); DPRINT_EXIT(STORVSC); return -1; } request = &storDevice->InitRequest; vstorPacket = &request->VStorPacket; /* * Now, initiate the vsc/vsp initialization protocol on the open * channel */ memset(request, 0, sizeof(struct storvsc_request_extension)); request->WaitEvent = osd_WaitEventCreate(); vstorPacket->Operation = VStorOperationBeginInitialization; vstorPacket->Flags = REQUEST_COMPLETION_FLAG; /*SpinlockAcquire(gDriverExt.packetListLock); INSERT_TAIL_LIST(&gDriverExt.packetList, &packet->listEntry.entry); SpinlockRelease(gDriverExt.packetListLock);*/ DPRINT_INFO(STORVSC, "BEGIN_INITIALIZATION_OPERATION..."); ret = Device->Driver->VmbusChannelInterface.SendPacket(Device, vstorPacket, sizeof(struct vstor_packet), (unsigned long)request, VmbusPacketTypeDataInBand, VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED); if (ret != 0) { DPRINT_ERR(STORVSC, "unable to send BEGIN_INITIALIZATION_OPERATION"); goto Cleanup; } osd_WaitEventWait(request->WaitEvent); if (vstorPacket->Operation != VStorOperationCompleteIo || vstorPacket->Status != 0) { DPRINT_ERR(STORVSC, "BEGIN_INITIALIZATION_OPERATION failed " "(op %d status 0x%x)", vstorPacket->Operation, vstorPacket->Status); goto Cleanup; } DPRINT_INFO(STORVSC, "QUERY_PROTOCOL_VERSION_OPERATION..."); /* reuse the packet for version range supported */ memset(vstorPacket, 0, sizeof(struct vstor_packet)); vstorPacket->Operation = VStorOperationQueryProtocolVersion; vstorPacket->Flags = REQUEST_COMPLETION_FLAG; vstorPacket->Version.MajorMinor = VMSTOR_PROTOCOL_VERSION_CURRENT; FILL_VMSTOR_REVISION(vstorPacket->Version.Revision); ret = Device->Driver->VmbusChannelInterface.SendPacket(Device, vstorPacket, sizeof(struct vstor_packet), (unsigned long)request, VmbusPacketTypeDataInBand, VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED); if (ret != 0) { DPRINT_ERR(STORVSC, "unable to send BEGIN_INITIALIZATION_OPERATION"); goto Cleanup; } osd_WaitEventWait(request->WaitEvent); /* TODO: Check returned version */ if (vstorPacket->Operation != VStorOperationCompleteIo || vstorPacket->Status != 0) { DPRINT_ERR(STORVSC, "QUERY_PROTOCOL_VERSION_OPERATION failed " "(op %d status 0x%x)", vstorPacket->Operation, vstorPacket->Status); goto Cleanup; } /* Query channel properties */ DPRINT_INFO(STORVSC, "QUERY_PROPERTIES_OPERATION..."); memset(vstorPacket, 0, sizeof(struct vstor_packet)); vstorPacket->Operation = VStorOperationQueryProperties; vstorPacket->Flags = REQUEST_COMPLETION_FLAG; vstorPacket->StorageChannelProperties.PortNumber = storDevice->PortNumber; ret = Device->Driver->VmbusChannelInterface.SendPacket(Device, vstorPacket, sizeof(struct vstor_packet), (unsigned long)request, VmbusPacketTypeDataInBand, VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED); if (ret != 0) { DPRINT_ERR(STORVSC, "unable to send QUERY_PROPERTIES_OPERATION"); goto Cleanup; } osd_WaitEventWait(request->WaitEvent); /* TODO: Check returned version */ if (vstorPacket->Operation != VStorOperationCompleteIo || vstorPacket->Status != 0) { DPRINT_ERR(STORVSC, "QUERY_PROPERTIES_OPERATION failed " "(op %d status 0x%x)", vstorPacket->Operation, vstorPacket->Status); goto Cleanup; } storDevice->PathId = vstorPacket->StorageChannelProperties.PathId; storDevice->TargetId = vstorPacket->StorageChannelProperties.TargetId; DPRINT_DBG(STORVSC, "channel flag 0x%x, max xfer len 0x%x", vstorPacket->StorageChannelProperties.Flags, vstorPacket->StorageChannelProperties.MaxTransferBytes); DPRINT_INFO(STORVSC, "END_INITIALIZATION_OPERATION..."); memset(vstorPacket, 0, sizeof(struct vstor_packet)); vstorPacket->Operation = VStorOperationEndInitialization; vstorPacket->Flags = REQUEST_COMPLETION_FLAG; ret = Device->Driver->VmbusChannelInterface.SendPacket(Device, vstorPacket, sizeof(struct vstor_packet), (unsigned long)request, VmbusPacketTypeDataInBand, VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED); if (ret != 0) { DPRINT_ERR(STORVSC, "unable to send END_INITIALIZATION_OPERATION"); goto Cleanup; } osd_WaitEventWait(request->WaitEvent); if (vstorPacket->Operation != VStorOperationCompleteIo || vstorPacket->Status != 0) { DPRINT_ERR(STORVSC, "END_INITIALIZATION_OPERATION failed " "(op %d status 0x%x)", vstorPacket->Operation, vstorPacket->Status); goto Cleanup; } DPRINT_INFO(STORVSC, "**** storage channel up and running!! ****"); Cleanup: kfree(request->WaitEvent); request->WaitEvent = NULL; PutStorDevice(Device); DPRINT_EXIT(STORVSC); return ret; } static void StorVscOnIOCompletion(struct hv_device *Device, struct vstor_packet *VStorPacket, struct storvsc_request_extension *RequestExt) { struct hv_storvsc_request *request; struct storvsc_device *storDevice; DPRINT_ENTER(STORVSC); storDevice = MustGetStorDevice(Device); if (!storDevice) { DPRINT_ERR(STORVSC, "unable to get stor device..." "device being destroyed?"); DPRINT_EXIT(STORVSC); return; } DPRINT_DBG(STORVSC, "IO_COMPLETE_OPERATION - request extension %p " "completed bytes xfer %u", RequestExt, VStorPacket->VmSrb.DataTransferLength); ASSERT(RequestExt != NULL); ASSERT(RequestExt->Request != NULL); request = RequestExt->Request; ASSERT(request->OnIOCompletion != NULL); /* Copy over the status...etc */ request->Status = VStorPacket->VmSrb.ScsiStatus; if (request->Status != 0 || VStorPacket->VmSrb.SrbStatus != 1) { DPRINT_WARN(STORVSC, "cmd 0x%x scsi status 0x%x srb status 0x%x\n", request->Cdb[0], VStorPacket->VmSrb.ScsiStatus, VStorPacket->VmSrb.SrbStatus); } if ((request->Status & 0xFF) == 0x02) { /* CHECK_CONDITION */ if (VStorPacket->VmSrb.SrbStatus & 0x80) { /* autosense data available */ DPRINT_WARN(STORVSC, "storvsc pkt %p autosense data " "valid - len %d\n", RequestExt, VStorPacket->VmSrb.SenseInfoLength); ASSERT(VStorPacket->VmSrb.SenseInfoLength <= request->SenseBufferSize); memcpy(request->SenseBuffer, VStorPacket->VmSrb.SenseData, VStorPacket->VmSrb.SenseInfoLength); request->SenseBufferSize = VStorPacket->VmSrb.SenseInfoLength; } } /* TODO: */ request->BytesXfer = VStorPacket->VmSrb.DataTransferLength; request->OnIOCompletion(request); atomic_dec(&storDevice->NumOutstandingRequests); PutStorDevice(Device); DPRINT_EXIT(STORVSC); } static void StorVscOnReceive(struct hv_device *Device, struct vstor_packet *VStorPacket, struct storvsc_request_extension *RequestExt) { switch (VStorPacket->Operation) { case VStorOperationCompleteIo: DPRINT_DBG(STORVSC, "IO_COMPLETE_OPERATION"); StorVscOnIOCompletion(Device, VStorPacket, RequestExt); break; case VStorOperationRemoveDevice: DPRINT_INFO(STORVSC, "REMOVE_DEVICE_OPERATION"); /* TODO: */ break; default: DPRINT_INFO(STORVSC, "Unknown operation received - %d", VStorPacket->Operation); break; } } static void StorVscOnChannelCallback(void *context) { struct hv_device *device = (struct hv_device *)context; struct storvsc_device *storDevice; u32 bytesRecvd; u64 requestId; unsigned char packet[ALIGN_UP(sizeof(struct vstor_packet), 8)]; struct storvsc_request_extension *request; int ret; DPRINT_ENTER(STORVSC); ASSERT(device); storDevice = MustGetStorDevice(device); if (!storDevice) { DPRINT_ERR(STORVSC, "unable to get stor device..." "device being destroyed?"); DPRINT_EXIT(STORVSC); return; } do { ret = device->Driver->VmbusChannelInterface.RecvPacket(device, packet, ALIGN_UP(sizeof(struct vstor_packet), 8), &bytesRecvd, &requestId); if (ret == 0 && bytesRecvd > 0) { DPRINT_DBG(STORVSC, "receive %d bytes - tid %llx", bytesRecvd, requestId); /* ASSERT(bytesRecvd == sizeof(struct vstor_packet)); */ request = (struct storvsc_request_extension *) (unsigned long)requestId; ASSERT(request); /* if (vstorPacket.Flags & SYNTHETIC_FLAG) */ if ((request == &storDevice->InitRequest) || (request == &storDevice->ResetRequest)) { /* DPRINT_INFO(STORVSC, * "reset completion - operation " * "%u status %u", * vstorPacket.Operation, * vstorPacket.Status); */ memcpy(&request->VStorPacket, packet, sizeof(struct vstor_packet)); osd_WaitEventSet(request->WaitEvent); } else { StorVscOnReceive(device, (struct vstor_packet *)packet, request); } } else { /* DPRINT_DBG(STORVSC, "nothing else to read..."); */ break; } } while (1); PutStorDevice(device); DPRINT_EXIT(STORVSC); return; } static int StorVscConnectToVsp(struct hv_device *Device) { struct vmstorage_channel_properties props; struct storvsc_driver_object *storDriver; int ret; storDriver = (struct storvsc_driver_object *)Device->Driver; memset(&props, 0, sizeof(struct vmstorage_channel_properties)); /* Open the channel */ ret = Device->Driver->VmbusChannelInterface.Open(Device, storDriver->RingBufferSize, storDriver->RingBufferSize, (void *)&props, sizeof(struct vmstorage_channel_properties), StorVscOnChannelCallback, Device); DPRINT_DBG(STORVSC, "storage props: path id %d, tgt id %d, max xfer %d", props.PathId, props.TargetId, props.MaxTransferBytes); if (ret != 0) { DPRINT_ERR(STORVSC, "unable to open channel: %d", ret); return -1; } ret = StorVscChannelInit(Device); return ret; } /** * StorVscOnDeviceAdd - Callback when the device belonging to this driver is added */ static int StorVscOnDeviceAdd(struct hv_device *Device, void *AdditionalInfo) { struct storvsc_device *storDevice; /* struct vmstorage_channel_properties *props; */ struct storvsc_device_info *deviceInfo; int ret = 0; DPRINT_ENTER(STORVSC); deviceInfo = (struct storvsc_device_info *)AdditionalInfo; storDevice = AllocStorDevice(Device); if (!storDevice) { ret = -1; goto Cleanup; } /* Save the channel properties to our storvsc channel */ /* props = (struct vmstorage_channel_properties *) * channel->offerMsg.Offer.u.Standard.UserDefined; */ /* FIXME: */ /* * If we support more than 1 scsi channel, we need to set the * port number here to the scsi channel but how do we get the * scsi channel prior to the bus scan */ /* storChannel->PortNumber = 0; storChannel->PathId = props->PathId; storChannel->TargetId = props->TargetId; */ storDevice->PortNumber = deviceInfo->PortNumber; /* Send it back up */ ret = StorVscConnectToVsp(Device); /* deviceInfo->PortNumber = storDevice->PortNumber; */ deviceInfo->PathId = storDevice->PathId; deviceInfo->TargetId = storDevice->TargetId; DPRINT_DBG(STORVSC, "assigned port %u, path %u target %u\n", storDevice->PortNumber, storDevice->PathId, storDevice->TargetId); Cleanup: DPRINT_EXIT(STORVSC); return ret; } /** * StorVscOnDeviceRemove - Callback when the our device is being removed */ static int StorVscOnDeviceRemove(struct hv_device *Device) { struct storvsc_device *storDevice; DPRINT_ENTER(STORVSC); DPRINT_INFO(STORVSC, "disabling storage device (%p)...", Device->Extension); storDevice = ReleaseStorDevice(Device); /* * At this point, all outbound traffic should be disable. We * only allow inbound traffic (responses) to proceed so that * outstanding requests can be completed. */ while (atomic_read(&storDevice->NumOutstandingRequests)) { DPRINT_INFO(STORVSC, "waiting for %d requests to complete...", atomic_read(&storDevice->NumOutstandingRequests)); udelay(100); } DPRINT_INFO(STORVSC, "removing storage device (%p)...", Device->Extension); storDevice = FinalReleaseStorDevice(Device); DPRINT_INFO(STORVSC, "storage device (%p) safe to remove", storDevice); /* Close the channel */ Device->Driver->VmbusChannelInterface.Close(Device); FreeStorDevice(storDevice); DPRINT_EXIT(STORVSC); return 0; } static int StorVscOnHostReset(struct hv_device *Device) { struct storvsc_device *storDevice; struct storvsc_request_extension *request; struct vstor_packet *vstorPacket; int ret; DPRINT_ENTER(STORVSC); DPRINT_INFO(STORVSC, "resetting host adapter..."); storDevice = GetStorDevice(Device); if (!storDevice) { DPRINT_ERR(STORVSC, "unable to get stor device..." "device being destroyed?"); DPRINT_EXIT(STORVSC); return -1; } request = &storDevice->ResetRequest; vstorPacket = &request->VStorPacket; request->WaitEvent = osd_WaitEventCreate(); vstorPacket->Operation = VStorOperationResetBus; vstorPacket->Flags = REQUEST_COMPLETION_FLAG; vstorPacket->VmSrb.PathId = storDevice->PathId; ret = Device->Driver->VmbusChannelInterface.SendPacket(Device, vstorPacket, sizeof(struct vstor_packet), (unsigned long)&storDevice->ResetRequest, VmbusPacketTypeDataInBand, VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED); if (ret != 0) { DPRINT_ERR(STORVSC, "Unable to send reset packet %p ret %d", vstorPacket, ret); goto Cleanup; } /* FIXME: Add a timeout */ osd_WaitEventWait(request->WaitEvent); kfree(request->WaitEvent); DPRINT_INFO(STORVSC, "host adapter reset completed"); /* * At this point, all outstanding requests in the adapter * should have been flushed out and return to us */ Cleanup: PutStorDevice(Device); DPRINT_EXIT(STORVSC); return ret; } /** * StorVscOnIORequest - Callback to initiate an I/O request */ static int StorVscOnIORequest(struct hv_device *Device, struct hv_storvsc_request *Request) { struct storvsc_device *storDevice; struct storvsc_request_extension *requestExtension; struct vstor_packet *vstorPacket; int ret = 0; DPRINT_ENTER(STORVSC); requestExtension = (struct storvsc_request_extension *)Request->Extension; vstorPacket = &requestExtension->VStorPacket; storDevice = GetStorDevice(Device); DPRINT_DBG(STORVSC, "enter - Device %p, DeviceExt %p, Request %p, " "Extension %p", Device, storDevice, Request, requestExtension); DPRINT_DBG(STORVSC, "req %p len %d bus %d, target %d, lun %d cdblen %d", Request, Request->DataBuffer.Length, Request->Bus, Request->TargetId, Request->LunId, Request->CdbLen); if (!storDevice) { DPRINT_ERR(STORVSC, "unable to get stor device..." "device being destroyed?"); DPRINT_EXIT(STORVSC); return -2; } /* print_hex_dump_bytes("", DUMP_PREFIX_NONE, Request->Cdb, * Request->CdbLen); */ requestExtension->Request = Request; requestExtension->Device = Device; memset(vstorPacket, 0 , sizeof(struct vstor_packet)); vstorPacket->Flags |= REQUEST_COMPLETION_FLAG; vstorPacket->VmSrb.Length = sizeof(struct vmscsi_request); vstorPacket->VmSrb.PortNumber = Request->Host; vstorPacket->VmSrb.PathId = Request->Bus; vstorPacket->VmSrb.TargetId = Request->TargetId; vstorPacket->VmSrb.Lun = Request->LunId; vstorPacket->VmSrb.SenseInfoLength = SENSE_BUFFER_SIZE; /* Copy over the scsi command descriptor block */ vstorPacket->VmSrb.CdbLength = Request->CdbLen; memcpy(&vstorPacket->VmSrb.Cdb, Request->Cdb, Request->CdbLen); vstorPacket->VmSrb.DataIn = Request->Type; vstorPacket->VmSrb.DataTransferLength = Request->DataBuffer.Length; vstorPacket->Operation = VStorOperationExecuteSRB; DPRINT_DBG(STORVSC, "srb - len %d port %d, path %d, target %d, " "lun %d senselen %d cdblen %d", vstorPacket->VmSrb.Length, vstorPacket->VmSrb.PortNumber, vstorPacket->VmSrb.PathId, vstorPacket->VmSrb.TargetId, vstorPacket->VmSrb.Lun, vstorPacket->VmSrb.SenseInfoLength, vstorPacket->VmSrb.CdbLength); if (requestExtension->Request->DataBuffer.Length) { ret = Device->Driver->VmbusChannelInterface. SendPacketMultiPageBuffer(Device, &requestExtension->Request->DataBuffer, vstorPacket, sizeof(struct vstor_packet), (unsigned long)requestExtension); } else { ret = Device->Driver->VmbusChannelInterface.SendPacket(Device, vstorPacket, sizeof(struct vstor_packet), (unsigned long)requestExtension, VmbusPacketTypeDataInBand, VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED); } if (ret != 0) { DPRINT_DBG(STORVSC, "Unable to send packet %p ret %d", vstorPacket, ret); } atomic_inc(&storDevice->NumOutstandingRequests); PutStorDevice(Device); DPRINT_EXIT(STORVSC); return ret; } /** * StorVscOnCleanup - Perform any cleanup when the driver is removed */ static void StorVscOnCleanup(struct hv_driver *Driver) { DPRINT_ENTER(STORVSC); DPRINT_EXIT(STORVSC); } /** * StorVscInitialize - Main entry point */ int StorVscInitialize(struct hv_driver *Driver) { struct storvsc_driver_object *storDriver; DPRINT_ENTER(STORVSC); storDriver = (struct storvsc_driver_object *)Driver; DPRINT_DBG(STORVSC, "sizeof(STORVSC_REQUEST)=%zd " "sizeof(struct storvsc_request_extension)=%zd " "sizeof(struct vstor_packet)=%zd, " "sizeof(struct vmscsi_request)=%zd", sizeof(struct hv_storvsc_request), sizeof(struct storvsc_request_extension), sizeof(struct vstor_packet), sizeof(struct vmscsi_request)); /* Make sure we are at least 2 pages since 1 page is used for control */ ASSERT(storDriver->RingBufferSize >= (PAGE_SIZE << 1)); Driver->name = gDriverName; memcpy(&Driver->deviceType, &gStorVscDeviceType, sizeof(struct hv_guid)); storDriver->RequestExtSize = sizeof(struct storvsc_request_extension); /* * Divide the ring buffer data size (which is 1 page less * than the ring buffer size since that page is reserved for * the ring buffer indices) by the max request size (which is * VMBUS_CHANNEL_PACKET_MULITPAGE_BUFFER + struct vstor_packet + u64) */ storDriver->MaxOutstandingRequestsPerChannel = ((storDriver->RingBufferSize - PAGE_SIZE) / ALIGN_UP(MAX_MULTIPAGE_BUFFER_PACKET + sizeof(struct vstor_packet) + sizeof(u64), sizeof(u64))); DPRINT_INFO(STORVSC, "max io %u, currently %u\n", storDriver->MaxOutstandingRequestsPerChannel, STORVSC_MAX_IO_REQUESTS); /* Setup the dispatch table */ storDriver->Base.OnDeviceAdd = StorVscOnDeviceAdd; storDriver->Base.OnDeviceRemove = StorVscOnDeviceRemove; storDriver->Base.OnCleanup = StorVscOnCleanup; storDriver->OnIORequest = StorVscOnIORequest; storDriver->OnHostReset = StorVscOnHostReset; DPRINT_EXIT(STORVSC); return 0; }
gpl-2.0
kbc-developers/padfone2_kernel
drivers/thermal/pm8xxx-tm.c
783
17731
/* * Copyright (c) 2011, Code Aurora Forum. All rights reserved. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 and * only version 2 as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. */ /* * Qualcomm PMIC PM8xxx Thermal Manager driver */ #define pr_fmt(fmt) "%s: " fmt, __func__ #include <linux/module.h> #include <linux/err.h> #include <linux/string.h> #include <linux/kernel.h> #include <linux/slab.h> #include <linux/mutex.h> #include <linux/thermal.h> #include <linux/interrupt.h> #include <linux/platform_device.h> #include <linux/mfd/pm8xxx/core.h> #include <linux/mfd/pm8xxx/tm.h> #include <linux/completion.h> #include <linux/mfd/pm8xxx/pm8xxx-adc.h> #include <linux/msm_adc.h> /* Register TEMP_ALARM_CTRL bits */ #define TEMP_ALARM_CTRL_ST3_SD 0x80 #define TEMP_ALARM_CTRL_ST2_SD 0x40 #define TEMP_ALARM_CTRL_STATUS_MASK 0x30 #define TEMP_ALARM_CTRL_STATUS_SHIFT 4 #define TEMP_ALARM_CTRL_THRESH_MASK 0x0C #define TEMP_ALARM_CTRL_THRESH_SHIFT 2 #define TEMP_ALARM_CTRL_OVRD_ST3 0x02 #define TEMP_ALARM_CTRL_OVRD_ST2 0x01 #define TEMP_ALARM_CTRL_OVRD_MASK 0x03 #define TEMP_STAGE_STEP 20000 /* Stage step: 20.000 C */ #define TEMP_STAGE_HYSTERESIS 2000 #define TEMP_THRESH_MIN 105000 /* Threshold Min: 105 C */ #define TEMP_THRESH_STEP 5000 /* Threshold step: 5 C */ /* Register TEMP_ALARM_PWM bits */ #define TEMP_ALARM_PWM_EN_MASK 0xC0 #define TEMP_ALARM_PWM_EN_SHIFT 6 #define TEMP_ALARM_PWM_PER_PRE_MASK 0x38 #define TEMP_ALARM_PWM_PER_PRE_SHIFT 3 #define TEMP_ALARM_PWM_PER_DIV_MASK 0x07 #define TEMP_ALARM_PWM_PER_DIV_SHIFT 0 /* Trips: from critical to less critical */ #define TRIP_STAGE3 0 #define TRIP_STAGE2 1 #define TRIP_STAGE1 2 #define TRIP_NUM 3 struct pm8xxx_tm_chip { struct pm8xxx_tm_core_data cdata; struct work_struct irq_work; struct device *dev; struct thermal_zone_device *tz_dev; unsigned long temp; enum thermal_device_mode mode; unsigned int thresh; unsigned int stage; unsigned int tempstat_irq; unsigned int overtemp_irq; void *adc_handle; }; enum pmic_thermal_override_mode { SOFTWARE_OVERRIDE_DISABLED = 0, SOFTWARE_OVERRIDE_ENABLED, }; static inline int pm8xxx_tm_read_ctrl(struct pm8xxx_tm_chip *chip, u8 *reg) { int rc; rc = pm8xxx_readb(chip->dev->parent, chip->cdata.reg_addr_temp_alarm_ctrl, reg); if (rc) pr_err("%s: pm8xxx_readb(0x%03X) failed, rc=%d\n", chip->cdata.tm_name, chip->cdata.reg_addr_temp_alarm_ctrl, rc); return rc; } static inline int pm8xxx_tm_write_ctrl(struct pm8xxx_tm_chip *chip, u8 reg) { int rc; rc = pm8xxx_writeb(chip->dev->parent, chip->cdata.reg_addr_temp_alarm_ctrl, reg); if (rc) pr_err("%s: pm8xxx_writeb(0x%03X)=0x%02X failed, rc=%d\n", chip->cdata.tm_name, chip->cdata.reg_addr_temp_alarm_ctrl, reg, rc); return rc; } static inline int pm8xxx_tm_write_pwm(struct pm8xxx_tm_chip *chip, u8 reg) { int rc; rc = pm8xxx_writeb(chip->dev->parent, chip->cdata.reg_addr_temp_alarm_pwm, reg); if (rc) pr_err("%s: pm8xxx_writeb(0x%03X)=0x%02X failed, rc=%d\n", chip->cdata.tm_name, chip->cdata.reg_addr_temp_alarm_pwm, reg, rc); return rc; } static inline int pm8xxx_tm_shutdown_override(struct pm8xxx_tm_chip *chip, enum pmic_thermal_override_mode mode) { int rc; u8 reg; rc = pm8xxx_tm_read_ctrl(chip, &reg); if (rc < 0) return rc; reg &= ~(TEMP_ALARM_CTRL_OVRD_MASK | TEMP_ALARM_CTRL_STATUS_MASK); if (mode == SOFTWARE_OVERRIDE_ENABLED) reg |= (TEMP_ALARM_CTRL_OVRD_ST3 | TEMP_ALARM_CTRL_OVRD_ST2) & TEMP_ALARM_CTRL_OVRD_MASK; rc = pm8xxx_tm_write_ctrl(chip, reg); return rc; } /* * This function initializes the internal temperature value based on only the * current thermal stage and threshold. */ static int pm8xxx_tm_init_temp_no_adc(struct pm8xxx_tm_chip *chip) { int rc; u8 reg; rc = pm8xxx_tm_read_ctrl(chip, &reg); if (rc < 0) return rc; chip->stage = (reg & TEMP_ALARM_CTRL_STATUS_MASK) >> TEMP_ALARM_CTRL_STATUS_SHIFT; chip->thresh = (reg & TEMP_ALARM_CTRL_THRESH_MASK) >> TEMP_ALARM_CTRL_THRESH_SHIFT; if (chip->stage) chip->temp = chip->thresh * TEMP_THRESH_MIN + (chip->stage - 1) * TEMP_STAGE_STEP + TEMP_THRESH_MIN; else chip->temp = chip->cdata.default_no_adc_temp; return 0; } /* * This function updates the internal temperature value based on the * current thermal stage and threshold as well as the previous stage */ static int pm8xxx_tm_update_temp_no_adc(struct pm8xxx_tm_chip *chip) { unsigned int stage; int rc; u8 reg; rc = pm8xxx_tm_read_ctrl(chip, &reg); if (rc < 0) return rc; stage = (reg & TEMP_ALARM_CTRL_STATUS_MASK) >> TEMP_ALARM_CTRL_STATUS_SHIFT; chip->thresh = (reg & TEMP_ALARM_CTRL_THRESH_MASK) >> TEMP_ALARM_CTRL_THRESH_SHIFT; if (stage > chip->stage) { /* increasing stage, use lower bound */ chip->temp = (stage - 1) * TEMP_STAGE_STEP + chip->thresh * TEMP_THRESH_STEP + TEMP_STAGE_HYSTERESIS + TEMP_THRESH_MIN; } else if (stage < chip->stage) { /* decreasing stage, use upper bound */ chip->temp = stage * TEMP_STAGE_STEP + chip->thresh * TEMP_THRESH_STEP - TEMP_STAGE_HYSTERESIS + TEMP_THRESH_MIN; } chip->stage = stage; return 0; } static int pm8xxx_tz_get_temp_no_adc(struct thermal_zone_device *thermal, unsigned long *temp) { struct pm8xxx_tm_chip *chip = thermal->devdata; int rc; if (!chip || !temp) return -EINVAL; rc = pm8xxx_tm_update_temp_no_adc(chip); if (rc < 0) return rc; *temp = chip->temp; return 0; } static int pm8xxx_tz_get_temp_pm8058_adc(struct thermal_zone_device *thermal, unsigned long *temp) { struct pm8xxx_tm_chip *chip = thermal->devdata; DECLARE_COMPLETION_ONSTACK(wait); struct adc_chan_result adc_result = { .physical = 0lu, }; int rc; if (!chip || !temp) return -EINVAL; *temp = chip->temp; rc = adc_channel_request_conv(chip->adc_handle, &wait); if (rc < 0) { pr_err("%s: adc_channel_request_conv() failed, rc = %d\n", __func__, rc); return rc; } wait_for_completion(&wait); rc = adc_channel_read_result(chip->adc_handle, &adc_result); if (rc < 0) { pr_err("%s: adc_channel_read_result() failed, rc = %d\n", __func__, rc); return rc; } *temp = adc_result.physical; chip->temp = adc_result.physical; return 0; } static int pm8xxx_tz_get_temp_pm8xxx_adc(struct thermal_zone_device *thermal, unsigned long *temp) { struct pm8xxx_tm_chip *chip = thermal->devdata; struct pm8xxx_adc_chan_result result = { .physical = 0lu, }; int rc; if (!chip || !temp) return -EINVAL; *temp = chip->temp; rc = pm8xxx_adc_read(chip->cdata.adc_channel, &result); if (rc < 0) { pr_err("%s: adc_channel_read_result() failed, rc = %d\n", chip->cdata.tm_name, rc); return rc; } *temp = result.physical; chip->temp = result.physical; return 0; } static int pm8xxx_tz_get_mode(struct thermal_zone_device *thermal, enum thermal_device_mode *mode) { struct pm8xxx_tm_chip *chip = thermal->devdata; if (!chip || !mode) return -EINVAL; *mode = chip->mode; return 0; } static int pm8xxx_tz_set_mode(struct thermal_zone_device *thermal, enum thermal_device_mode mode) { struct pm8xxx_tm_chip *chip = thermal->devdata; if (!chip) return -EINVAL; if (mode != chip->mode) { if (mode == THERMAL_DEVICE_ENABLED) pm8xxx_tm_shutdown_override(chip, SOFTWARE_OVERRIDE_ENABLED); else pm8xxx_tm_shutdown_override(chip, SOFTWARE_OVERRIDE_DISABLED); } chip->mode = mode; return 0; } static int pm8xxx_tz_get_trip_type(struct thermal_zone_device *thermal, int trip, enum thermal_trip_type *type) { if (trip < 0 || !type) return -EINVAL; switch (trip) { case TRIP_STAGE3: *type = THERMAL_TRIP_CRITICAL; break; case TRIP_STAGE2: *type = THERMAL_TRIP_HOT; break; case TRIP_STAGE1: *type = THERMAL_TRIP_HOT; break; default: return -EINVAL; } return 0; } static int pm8xxx_tz_get_trip_temp(struct thermal_zone_device *thermal, int trip, unsigned long *temp) { struct pm8xxx_tm_chip *chip = thermal->devdata; int thresh_temp; if (!chip || trip < 0 || !temp) return -EINVAL; thresh_temp = chip->thresh * TEMP_THRESH_STEP + TEMP_THRESH_MIN; switch (trip) { case TRIP_STAGE3: thresh_temp += 2 * TEMP_STAGE_STEP; break; case TRIP_STAGE2: thresh_temp += TEMP_STAGE_STEP; break; case TRIP_STAGE1: break; default: return -EINVAL; } *temp = thresh_temp; return 0; } static int pm8xxx_tz_get_crit_temp(struct thermal_zone_device *thermal, unsigned long *temp) { struct pm8xxx_tm_chip *chip = thermal->devdata; if (!chip || !temp) return -EINVAL; *temp = chip->thresh * TEMP_THRESH_STEP + TEMP_THRESH_MIN + 2 * TEMP_STAGE_STEP; return 0; } static struct thermal_zone_device_ops pm8xxx_thermal_zone_ops_no_adc = { .get_temp = pm8xxx_tz_get_temp_no_adc, .get_mode = pm8xxx_tz_get_mode, .set_mode = pm8xxx_tz_set_mode, .get_trip_type = pm8xxx_tz_get_trip_type, .get_trip_temp = pm8xxx_tz_get_trip_temp, .get_crit_temp = pm8xxx_tz_get_crit_temp, }; static struct thermal_zone_device_ops pm8xxx_thermal_zone_ops_pm8xxx_adc = { .get_temp = pm8xxx_tz_get_temp_pm8xxx_adc, .get_mode = pm8xxx_tz_get_mode, .set_mode = pm8xxx_tz_set_mode, .get_trip_type = pm8xxx_tz_get_trip_type, .get_trip_temp = pm8xxx_tz_get_trip_temp, .get_crit_temp = pm8xxx_tz_get_crit_temp, }; static struct thermal_zone_device_ops pm8xxx_thermal_zone_ops_pm8058_adc = { .get_temp = pm8xxx_tz_get_temp_pm8058_adc, .get_mode = pm8xxx_tz_get_mode, .set_mode = pm8xxx_tz_set_mode, .get_trip_type = pm8xxx_tz_get_trip_type, .get_trip_temp = pm8xxx_tz_get_trip_temp, .get_crit_temp = pm8xxx_tz_get_crit_temp, }; static void pm8xxx_tm_work(struct work_struct *work) { struct pm8xxx_tm_chip *chip = container_of(work, struct pm8xxx_tm_chip, irq_work); int rc; u8 reg; rc = pm8xxx_tm_read_ctrl(chip, &reg); if (rc < 0) goto bail; if (chip->cdata.adc_type == PM8XXX_TM_ADC_NONE) { rc = pm8xxx_tm_update_temp_no_adc(chip); if (rc < 0) goto bail; pr_info("%s: Temp Alarm - stage=%u, threshold=%u, " "temp=%lu mC\n", chip->cdata.tm_name, chip->stage, chip->thresh, chip->temp); } else { chip->stage = (reg & TEMP_ALARM_CTRL_STATUS_MASK) >> TEMP_ALARM_CTRL_STATUS_SHIFT; chip->thresh = (reg & TEMP_ALARM_CTRL_THRESH_MASK) >> TEMP_ALARM_CTRL_THRESH_SHIFT; pr_info("%s: Temp Alarm - stage=%u, threshold=%u\n", chip->cdata.tm_name, chip->stage, chip->thresh); } /* Clear status bits. */ if (reg & (TEMP_ALARM_CTRL_ST2_SD | TEMP_ALARM_CTRL_ST3_SD)) { reg &= ~(TEMP_ALARM_CTRL_ST2_SD | TEMP_ALARM_CTRL_ST3_SD | TEMP_ALARM_CTRL_STATUS_MASK); pm8xxx_tm_write_ctrl(chip, reg); } thermal_zone_device_update(chip->tz_dev); /* Notify user space */ if (chip->mode == THERMAL_DEVICE_ENABLED) kobject_uevent(&chip->tz_dev->device.kobj, KOBJ_CHANGE); bail: enable_irq(chip->tempstat_irq); enable_irq(chip->overtemp_irq); } static irqreturn_t pm8xxx_tm_isr(int irq, void *data) { struct pm8xxx_tm_chip *chip = data; disable_irq_nosync(chip->tempstat_irq); disable_irq_nosync(chip->overtemp_irq); schedule_work(&chip->irq_work); return IRQ_HANDLED; } static int pm8xxx_tm_init_reg(struct pm8xxx_tm_chip *chip) { int rc; u8 reg; rc = pm8xxx_tm_read_ctrl(chip, &reg); if (rc < 0) return rc; chip->stage = (reg & TEMP_ALARM_CTRL_STATUS_MASK) >> TEMP_ALARM_CTRL_STATUS_SHIFT; chip->temp = 0; /* Use temperature threshold set 0: (105, 125, 145) */ chip->thresh = 0; reg = (chip->thresh << TEMP_ALARM_CTRL_THRESH_SHIFT) & TEMP_ALARM_CTRL_THRESH_MASK; rc = pm8xxx_tm_write_ctrl(chip, reg); if (rc < 0) return rc; /* * Set the PMIC alarm module PWM to have a frequency of 8 Hz. This * helps cut down on the number of unnecessary interrupts fired when * changing between thermal stages. Also, Enable the over temperature * PWM whenever the PMIC is enabled. */ reg = (1 << TEMP_ALARM_PWM_EN_SHIFT) | (3 << TEMP_ALARM_PWM_PER_PRE_SHIFT) | (3 << TEMP_ALARM_PWM_PER_DIV_SHIFT); rc = pm8xxx_tm_write_pwm(chip, reg); return rc; } static int pm8xxx_init_adc(struct pm8xxx_tm_chip *chip, bool enable) { int rc = 0; if (chip->cdata.adc_type == PM8XXX_TM_ADC_PM8058_ADC) { if (enable) { rc = adc_channel_open(chip->cdata.adc_channel, &(chip->adc_handle)); if (rc < 0) pr_err("adc_channel_open() failed.\n"); } else { adc_channel_close(chip->adc_handle); } } return rc; } static int __devinit pm8xxx_tm_probe(struct platform_device *pdev) { const struct pm8xxx_tm_core_data *cdata = pdev->dev.platform_data; struct thermal_zone_device_ops *tz_ops; struct pm8xxx_tm_chip *chip; struct resource *res; int rc = 0; if (!cdata) { pr_err("missing core data\n"); return -EINVAL; } chip = kzalloc(sizeof(struct pm8xxx_tm_chip), GFP_KERNEL); if (chip == NULL) { pr_err("kzalloc() failed.\n"); return -ENOMEM; } chip->dev = &pdev->dev; memcpy(&(chip->cdata), cdata, sizeof(struct pm8xxx_tm_core_data)); res = platform_get_resource_byname(pdev, IORESOURCE_IRQ, chip->cdata.irq_name_temp_stat); if (res) { chip->tempstat_irq = res->start; } else { pr_err("temp stat IRQ not specified\n"); goto err_free_chip; } res = platform_get_resource_byname(pdev, IORESOURCE_IRQ, chip->cdata.irq_name_over_temp); if (res) { chip->overtemp_irq = res->start; } else { pr_err("over temp IRQ not specified\n"); goto err_free_chip; } rc = pm8xxx_init_adc(chip, true); if (rc < 0) { pr_err("Unable to initialize adc\n"); goto err_free_chip; } /* Select proper thermal zone ops functions based on ADC type. */ if (chip->cdata.adc_type == PM8XXX_TM_ADC_PM8XXX_ADC) tz_ops = &pm8xxx_thermal_zone_ops_pm8xxx_adc; else if (chip->cdata.adc_type == PM8XXX_TM_ADC_PM8058_ADC) tz_ops = &pm8xxx_thermal_zone_ops_pm8058_adc; else tz_ops = &pm8xxx_thermal_zone_ops_no_adc; chip->tz_dev = thermal_zone_device_register(chip->cdata.tm_name, TRIP_NUM, chip, tz_ops, 0, 0, 0, 0); if (chip->tz_dev == NULL) { pr_err("thermal_zone_device_register() failed.\n"); rc = -ENODEV; goto err_fail_adc; } rc = pm8xxx_tm_init_reg(chip); if (rc < 0) goto err_free_tz; rc = pm8xxx_tm_shutdown_override(chip, SOFTWARE_OVERRIDE_DISABLED); if (rc < 0) goto err_free_tz; if (chip->cdata.adc_type == PM8XXX_TM_ADC_NONE) { rc = pm8xxx_tm_init_temp_no_adc(chip); if (rc < 0) goto err_free_tz; } /* Start in HW control; switch to SW control when user changes mode. */ chip->mode = THERMAL_DEVICE_DISABLED; thermal_zone_device_update(chip->tz_dev); INIT_WORK(&chip->irq_work, pm8xxx_tm_work); rc = request_irq(chip->tempstat_irq, pm8xxx_tm_isr, IRQF_TRIGGER_RISING, chip->cdata.irq_name_temp_stat, chip); if (rc < 0) { pr_err("request_irq(%d) failed: %d\n", chip->tempstat_irq, rc); goto err_cancel_work; } rc = request_irq(chip->overtemp_irq, pm8xxx_tm_isr, IRQF_TRIGGER_RISING, chip->cdata.irq_name_over_temp, chip); if (rc < 0) { pr_err("request_irq(%d) failed: %d\n", chip->overtemp_irq, rc); goto err_free_irq_tempstat; } platform_set_drvdata(pdev, chip); pr_info("OK\n"); return 0; err_free_irq_tempstat: free_irq(chip->tempstat_irq, chip); err_cancel_work: cancel_work_sync(&chip->irq_work); err_free_tz: thermal_zone_device_unregister(chip->tz_dev); err_fail_adc: pm8xxx_init_adc(chip, false); err_free_chip: kfree(chip); return rc; } static int __devexit pm8xxx_tm_remove(struct platform_device *pdev) { struct pm8xxx_tm_chip *chip = platform_get_drvdata(pdev); if (chip) { platform_set_drvdata(pdev, NULL); cancel_work_sync(&chip->irq_work); free_irq(chip->overtemp_irq, chip); free_irq(chip->tempstat_irq, chip); pm8xxx_tm_shutdown_override(chip, SOFTWARE_OVERRIDE_DISABLED); pm8xxx_init_adc(chip, false); thermal_zone_device_unregister(chip->tz_dev); kfree(chip); } return 0; } #ifdef CONFIG_PM static int pm8xxx_tm_suspend(struct device *dev) { struct platform_device *pdev = to_platform_device(dev); struct pm8xxx_tm_chip *chip = platform_get_drvdata(pdev); /* Clear override bits in suspend to allow hardware control */ pm8xxx_tm_shutdown_override(chip, SOFTWARE_OVERRIDE_DISABLED); return 0; } static int pm8xxx_tm_resume(struct device *dev) { struct platform_device *pdev = to_platform_device(dev); struct pm8xxx_tm_chip *chip = platform_get_drvdata(pdev); /* Override hardware actions so software can control */ if (chip->mode == THERMAL_DEVICE_ENABLED) pm8xxx_tm_shutdown_override(chip, SOFTWARE_OVERRIDE_ENABLED); return 0; } static const struct dev_pm_ops pm8xxx_tm_pm_ops = { .suspend = pm8xxx_tm_suspend, .resume = pm8xxx_tm_resume, }; #define PM8XXX_TM_PM_OPS (&pm8xxx_tm_pm_ops) #else #define PM8XXX_TM_PM_OPS NULL #endif static struct platform_driver pm8xxx_tm_driver = { .probe = pm8xxx_tm_probe, .remove = __devexit_p(pm8xxx_tm_remove), .driver = { .name = PM8XXX_TM_DEV_NAME, .owner = THIS_MODULE, .pm = PM8XXX_TM_PM_OPS, }, }; static int __init pm8xxx_tm_init(void) { return platform_driver_register(&pm8xxx_tm_driver); } static void __exit pm8xxx_tm_exit(void) { platform_driver_unregister(&pm8xxx_tm_driver); } module_init(pm8xxx_tm_init); module_exit(pm8xxx_tm_exit); MODULE_LICENSE("GPL v2"); MODULE_DESCRIPTION("PM8xxx Thermal Manager driver"); MODULE_VERSION("1.0"); MODULE_ALIAS("platform:" PM8XXX_TM_DEV_NAME);
gpl-2.0
altcrauer/linux
arch/sparc/mm/fault_32.c
783
10932
/* * fault.c: Page fault handlers for the Sparc. * * Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu) * Copyright (C) 1996 Eddie C. Dost (ecd@skynet.be) * Copyright (C) 1997 Jakub Jelinek (jj@sunsite.mff.cuni.cz) */ #include <asm/head.h> #include <linux/string.h> #include <linux/types.h> #include <linux/sched.h> #include <linux/ptrace.h> #include <linux/mman.h> #include <linux/threads.h> #include <linux/kernel.h> #include <linux/signal.h> #include <linux/mm.h> #include <linux/smp.h> #include <linux/perf_event.h> #include <linux/interrupt.h> #include <linux/kdebug.h> #include <asm/page.h> #include <asm/pgtable.h> #include <asm/openprom.h> #include <asm/oplib.h> #include <asm/smp.h> #include <asm/traps.h> #include <asm/uaccess.h> int show_unhandled_signals = 1; static void unhandled_fault(unsigned long, struct task_struct *, struct pt_regs *) __attribute__ ((noreturn)); static void __noreturn unhandled_fault(unsigned long address, struct task_struct *tsk, struct pt_regs *regs) { if ((unsigned long) address < PAGE_SIZE) { printk(KERN_ALERT "Unable to handle kernel NULL pointer dereference\n"); } else { printk(KERN_ALERT "Unable to handle kernel paging request at virtual address %08lx\n", address); } printk(KERN_ALERT "tsk->{mm,active_mm}->context = %08lx\n", (tsk->mm ? tsk->mm->context : tsk->active_mm->context)); printk(KERN_ALERT "tsk->{mm,active_mm}->pgd = %08lx\n", (tsk->mm ? (unsigned long) tsk->mm->pgd : (unsigned long) tsk->active_mm->pgd)); die_if_kernel("Oops", regs); } asmlinkage int lookup_fault(unsigned long pc, unsigned long ret_pc, unsigned long address) { struct pt_regs regs; unsigned long g2; unsigned int insn; int i; i = search_extables_range(ret_pc, &g2); switch (i) { case 3: /* load & store will be handled by fixup */ return 3; case 1: /* store will be handled by fixup, load will bump out */ /* for _to_ macros */ insn = *((unsigned int *) pc); if ((insn >> 21) & 1) return 1; break; case 2: /* load will be handled by fixup, store will bump out */ /* for _from_ macros */ insn = *((unsigned int *) pc); if (!((insn >> 21) & 1) || ((insn>>19)&0x3f) == 15) return 2; break; default: break; } memset(&regs, 0, sizeof(regs)); regs.pc = pc; regs.npc = pc + 4; __asm__ __volatile__( "rd %%psr, %0\n\t" "nop\n\t" "nop\n\t" "nop\n" : "=r" (regs.psr)); unhandled_fault(address, current, &regs); /* Not reached */ return 0; } static inline void show_signal_msg(struct pt_regs *regs, int sig, int code, unsigned long address, struct task_struct *tsk) { if (!unhandled_signal(tsk, sig)) return; if (!printk_ratelimit()) return; printk("%s%s[%d]: segfault at %lx ip %p (rpc %p) sp %p error %x", task_pid_nr(tsk) > 1 ? KERN_INFO : KERN_EMERG, tsk->comm, task_pid_nr(tsk), address, (void *)regs->pc, (void *)regs->u_regs[UREG_I7], (void *)regs->u_regs[UREG_FP], code); print_vma_addr(KERN_CONT " in ", regs->pc); printk(KERN_CONT "\n"); } static void __do_fault_siginfo(int code, int sig, struct pt_regs *regs, unsigned long addr) { siginfo_t info; info.si_signo = sig; info.si_code = code; info.si_errno = 0; info.si_addr = (void __user *) addr; info.si_trapno = 0; if (unlikely(show_unhandled_signals)) show_signal_msg(regs, sig, info.si_code, addr, current); force_sig_info (sig, &info, current); } extern unsigned long safe_compute_effective_address(struct pt_regs *, unsigned int); static unsigned long compute_si_addr(struct pt_regs *regs, int text_fault) { unsigned int insn; if (text_fault) return regs->pc; if (regs->psr & PSR_PS) insn = *(unsigned int *) regs->pc; else __get_user(insn, (unsigned int *) regs->pc); return safe_compute_effective_address(regs, insn); } static noinline void do_fault_siginfo(int code, int sig, struct pt_regs *regs, int text_fault) { unsigned long addr = compute_si_addr(regs, text_fault); __do_fault_siginfo(code, sig, regs, addr); } asmlinkage void do_sparc_fault(struct pt_regs *regs, int text_fault, int write, unsigned long address) { struct vm_area_struct *vma; struct task_struct *tsk = current; struct mm_struct *mm = tsk->mm; unsigned int fixup; unsigned long g2; int from_user = !(regs->psr & PSR_PS); int fault, code; unsigned int flags = (FAULT_FLAG_ALLOW_RETRY | FAULT_FLAG_KILLABLE | (write ? FAULT_FLAG_WRITE : 0)); if (text_fault) address = regs->pc; /* * We fault-in kernel-space virtual memory on-demand. The * 'reference' page table is init_mm.pgd. * * NOTE! We MUST NOT take any locks for this case. We may * be in an interrupt or a critical region, and should * only copy the information from the master page table, * nothing more. */ code = SEGV_MAPERR; if (address >= TASK_SIZE) goto vmalloc_fault; /* * If we're in an interrupt or have no user * context, we must not take the fault.. */ if (in_atomic() || !mm) goto no_context; perf_sw_event(PERF_COUNT_SW_PAGE_FAULTS, 1, regs, address); retry: down_read(&mm->mmap_sem); if (!from_user && address >= PAGE_OFFSET) goto bad_area; vma = find_vma(mm, address); if (!vma) goto bad_area; if (vma->vm_start <= address) goto good_area; if (!(vma->vm_flags & VM_GROWSDOWN)) goto bad_area; if (expand_stack(vma, address)) goto bad_area; /* * Ok, we have a good vm_area for this memory access, so * we can handle it.. */ good_area: code = SEGV_ACCERR; if (write) { if (!(vma->vm_flags & VM_WRITE)) goto bad_area; } else { /* Allow reads even for write-only mappings */ if (!(vma->vm_flags & (VM_READ | VM_EXEC))) goto bad_area; } /* * If for any reason at all we couldn't handle the fault, * make sure we exit gracefully rather than endlessly redo * the fault. */ fault = handle_mm_fault(mm, vma, address, flags); if ((fault & VM_FAULT_RETRY) && fatal_signal_pending(current)) return; if (unlikely(fault & VM_FAULT_ERROR)) { if (fault & VM_FAULT_OOM) goto out_of_memory; else if (fault & VM_FAULT_SIGBUS) goto do_sigbus; BUG(); } if (flags & FAULT_FLAG_ALLOW_RETRY) { if (fault & VM_FAULT_MAJOR) { current->maj_flt++; perf_sw_event(PERF_COUNT_SW_PAGE_FAULTS_MAJ, 1, regs, address); } else { current->min_flt++; perf_sw_event(PERF_COUNT_SW_PAGE_FAULTS_MIN, 1, regs, address); } if (fault & VM_FAULT_RETRY) { flags &= ~FAULT_FLAG_ALLOW_RETRY; flags |= FAULT_FLAG_TRIED; /* No need to up_read(&mm->mmap_sem) as we would * have already released it in __lock_page_or_retry * in mm/filemap.c. */ goto retry; } } up_read(&mm->mmap_sem); return; /* * Something tried to access memory that isn't in our memory map.. * Fix it, but check if it's kernel or user first.. */ bad_area: up_read(&mm->mmap_sem); bad_area_nosemaphore: /* User mode accesses just cause a SIGSEGV */ if (from_user) { do_fault_siginfo(code, SIGSEGV, regs, text_fault); return; } /* Is this in ex_table? */ no_context: g2 = regs->u_regs[UREG_G2]; if (!from_user) { fixup = search_extables_range(regs->pc, &g2); /* Values below 10 are reserved for other things */ if (fixup > 10) { extern const unsigned __memset_start[]; extern const unsigned __memset_end[]; extern const unsigned __csum_partial_copy_start[]; extern const unsigned __csum_partial_copy_end[]; #ifdef DEBUG_EXCEPTIONS printk("Exception: PC<%08lx> faddr<%08lx>\n", regs->pc, address); printk("EX_TABLE: insn<%08lx> fixup<%08x> g2<%08lx>\n", regs->pc, fixup, g2); #endif if ((regs->pc >= (unsigned long)__memset_start && regs->pc < (unsigned long)__memset_end) || (regs->pc >= (unsigned long)__csum_partial_copy_start && regs->pc < (unsigned long)__csum_partial_copy_end)) { regs->u_regs[UREG_I4] = address; regs->u_regs[UREG_I5] = regs->pc; } regs->u_regs[UREG_G2] = g2; regs->pc = fixup; regs->npc = regs->pc + 4; return; } } unhandled_fault(address, tsk, regs); do_exit(SIGKILL); /* * We ran out of memory, or some other thing happened to us that made * us unable to handle the page fault gracefully. */ out_of_memory: up_read(&mm->mmap_sem); if (from_user) { pagefault_out_of_memory(); return; } goto no_context; do_sigbus: up_read(&mm->mmap_sem); do_fault_siginfo(BUS_ADRERR, SIGBUS, regs, text_fault); if (!from_user) goto no_context; vmalloc_fault: { /* * Synchronize this task's top level page-table * with the 'reference' page table. */ int offset = pgd_index(address); pgd_t *pgd, *pgd_k; pmd_t *pmd, *pmd_k; pgd = tsk->active_mm->pgd + offset; pgd_k = init_mm.pgd + offset; if (!pgd_present(*pgd)) { if (!pgd_present(*pgd_k)) goto bad_area_nosemaphore; pgd_val(*pgd) = pgd_val(*pgd_k); return; } pmd = pmd_offset(pgd, address); pmd_k = pmd_offset(pgd_k, address); if (pmd_present(*pmd) || !pmd_present(*pmd_k)) goto bad_area_nosemaphore; *pmd = *pmd_k; return; } } /* This always deals with user addresses. */ static void force_user_fault(unsigned long address, int write) { struct vm_area_struct *vma; struct task_struct *tsk = current; struct mm_struct *mm = tsk->mm; int code; code = SEGV_MAPERR; down_read(&mm->mmap_sem); vma = find_vma(mm, address); if (!vma) goto bad_area; if (vma->vm_start <= address) goto good_area; if (!(vma->vm_flags & VM_GROWSDOWN)) goto bad_area; if (expand_stack(vma, address)) goto bad_area; good_area: code = SEGV_ACCERR; if (write) { if (!(vma->vm_flags & VM_WRITE)) goto bad_area; } else { if (!(vma->vm_flags & (VM_READ | VM_EXEC))) goto bad_area; } switch (handle_mm_fault(mm, vma, address, write ? FAULT_FLAG_WRITE : 0)) { case VM_FAULT_SIGBUS: case VM_FAULT_OOM: goto do_sigbus; } up_read(&mm->mmap_sem); return; bad_area: up_read(&mm->mmap_sem); __do_fault_siginfo(code, SIGSEGV, tsk->thread.kregs, address); return; do_sigbus: up_read(&mm->mmap_sem); __do_fault_siginfo(BUS_ADRERR, SIGBUS, tsk->thread.kregs, address); } static void check_stack_aligned(unsigned long sp) { if (sp & 0x7UL) force_sig(SIGILL, current); } void window_overflow_fault(void) { unsigned long sp; sp = current_thread_info()->rwbuf_stkptrs[0]; if (((sp + 0x38) & PAGE_MASK) != (sp & PAGE_MASK)) force_user_fault(sp + 0x38, 1); force_user_fault(sp, 1); check_stack_aligned(sp); } void window_underflow_fault(unsigned long sp) { if (((sp + 0x38) & PAGE_MASK) != (sp & PAGE_MASK)) force_user_fault(sp + 0x38, 0); force_user_fault(sp, 0); check_stack_aligned(sp); } void window_ret_fault(struct pt_regs *regs) { unsigned long sp; sp = regs->u_regs[UREG_FP]; if (((sp + 0x38) & PAGE_MASK) != (sp & PAGE_MASK)) force_user_fault(sp + 0x38, 0); force_user_fault(sp, 0); check_stack_aligned(sp); }
gpl-2.0
sndnvaps/linux-1
lib/digsig.c
1295
5606
/* * Copyright (C) 2011 Nokia Corporation * Copyright (C) 2011 Intel Corporation * * Author: * Dmitry Kasatkin <dmitry.kasatkin@nokia.com> * <dmitry.kasatkin@intel.com> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, version 2 of the License. * * File: sign.c * implements signature (RSA) verification * pkcs decoding is based on LibTomCrypt code */ #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt #include <linux/err.h> #include <linux/module.h> #include <linux/slab.h> #include <linux/key.h> #include <linux/crypto.h> #include <crypto/hash.h> #include <crypto/sha.h> #include <keys/user-type.h> #include <linux/mpi.h> #include <linux/digsig.h> static struct crypto_shash *shash; static const char *pkcs_1_v1_5_decode_emsa(const unsigned char *msg, unsigned long msglen, unsigned long modulus_bitlen, unsigned long *outlen) { unsigned long modulus_len, ps_len, i; modulus_len = (modulus_bitlen >> 3) + (modulus_bitlen & 7 ? 1 : 0); /* test message size */ if ((msglen > modulus_len) || (modulus_len < 11)) return NULL; /* separate encoded message */ if (msg[0] != 0x00 || msg[1] != 0x01) return NULL; for (i = 2; i < modulus_len - 1; i++) if (msg[i] != 0xFF) break; /* separator check */ if (msg[i] != 0) /* There was no octet with hexadecimal value 0x00 to separate ps from m. */ return NULL; ps_len = i - 2; *outlen = (msglen - (2 + ps_len + 1)); return msg + 2 + ps_len + 1; } /* * RSA Signature verification with public key */ static int digsig_verify_rsa(struct key *key, const char *sig, int siglen, const char *h, int hlen) { int err = -EINVAL; unsigned long len; unsigned long mlen, mblen; unsigned nret, l; int head, i; unsigned char *out1 = NULL; const char *m; MPI in = NULL, res = NULL, pkey[2]; uint8_t *p, *datap, *endp; struct user_key_payload *ukp; struct pubkey_hdr *pkh; down_read(&key->sem); ukp = key->payload.data; if (ukp->datalen < sizeof(*pkh)) goto err1; pkh = (struct pubkey_hdr *)ukp->data; if (pkh->version != 1) goto err1; if (pkh->algo != PUBKEY_ALGO_RSA) goto err1; if (pkh->nmpi != 2) goto err1; datap = pkh->mpi; endp = ukp->data + ukp->datalen; err = -ENOMEM; for (i = 0; i < pkh->nmpi; i++) { unsigned int remaining = endp - datap; pkey[i] = mpi_read_from_buffer(datap, &remaining); if (!pkey[i]) goto err; datap += remaining; } mblen = mpi_get_nbits(pkey[0]); mlen = DIV_ROUND_UP(mblen, 8); if (mlen == 0) goto err; out1 = kzalloc(mlen, GFP_KERNEL); if (!out1) goto err; nret = siglen; in = mpi_read_from_buffer(sig, &nret); if (!in) goto err; res = mpi_alloc(mpi_get_nlimbs(in) * 2); if (!res) goto err; err = mpi_powm(res, in, pkey[1], pkey[0]); if (err) goto err; if (mpi_get_nlimbs(res) * BYTES_PER_MPI_LIMB > mlen) { err = -EINVAL; goto err; } p = mpi_get_buffer(res, &l, NULL); if (!p) { err = -EINVAL; goto err; } len = mlen; head = len - l; memset(out1, 0, head); memcpy(out1 + head, p, l); kfree(p); m = pkcs_1_v1_5_decode_emsa(out1, len, mblen, &len); if (!m || len != hlen || memcmp(m, h, hlen)) err = -EINVAL; err: mpi_free(in); mpi_free(res); kfree(out1); while (--i >= 0) mpi_free(pkey[i]); err1: up_read(&key->sem); return err; } /** * digsig_verify() - digital signature verification with public key * @keyring: keyring to search key in * @sig: digital signature * @siglen: length of the signature * @data: data * @datalen: length of the data * * Returns 0 on success, -EINVAL otherwise * * Verifies data integrity against digital signature. * Currently only RSA is supported. * Normally hash of the content is used as a data for this function. * */ int digsig_verify(struct key *keyring, const char *sig, int siglen, const char *data, int datalen) { int err = -ENOMEM; struct signature_hdr *sh = (struct signature_hdr *)sig; struct shash_desc *desc = NULL; unsigned char hash[SHA1_DIGEST_SIZE]; struct key *key; char name[20]; if (siglen < sizeof(*sh) + 2) return -EINVAL; if (sh->algo != PUBKEY_ALGO_RSA) return -ENOTSUPP; sprintf(name, "%llX", __be64_to_cpup((uint64_t *)sh->keyid)); if (keyring) { /* search in specific keyring */ key_ref_t kref; kref = keyring_search(make_key_ref(keyring, 1UL), &key_type_user, name); if (IS_ERR(kref)) key = ERR_CAST(kref); else key = key_ref_to_ptr(kref); } else { key = request_key(&key_type_user, name, NULL); } if (IS_ERR(key)) { pr_err("key not found, id: %s\n", name); return PTR_ERR(key); } desc = kzalloc(sizeof(*desc) + crypto_shash_descsize(shash), GFP_KERNEL); if (!desc) goto err; desc->tfm = shash; desc->flags = CRYPTO_TFM_REQ_MAY_SLEEP; crypto_shash_init(desc); crypto_shash_update(desc, data, datalen); crypto_shash_update(desc, sig, sizeof(*sh)); crypto_shash_final(desc, hash); kfree(desc); /* pass signature mpis address */ err = digsig_verify_rsa(key, sig + sizeof(*sh), siglen - sizeof(*sh), hash, sizeof(hash)); err: key_put(key); return err ? -EINVAL : 0; } EXPORT_SYMBOL_GPL(digsig_verify); static int __init digsig_init(void) { shash = crypto_alloc_shash("sha1", 0, 0); if (IS_ERR(shash)) { pr_err("shash allocation failed\n"); return PTR_ERR(shash); } return 0; } static void __exit digsig_cleanup(void) { crypto_free_shash(shash); } module_init(digsig_init); module_exit(digsig_cleanup); MODULE_LICENSE("GPL");
gpl-2.0
joisonwk/linux
drivers/pcmcia/bcm63xx_pcmcia.c
1807
13664
/* * This file is subject to the terms and conditions of the GNU General Public * License. See the file "COPYING" in the main directory of this archive * for more details. * * Copyright (C) 2008 Maxime Bizon <mbizon@freebox.fr> */ #include <linux/kernel.h> #include <linux/module.h> #include <linux/ioport.h> #include <linux/timer.h> #include <linux/platform_device.h> #include <linux/slab.h> #include <linux/delay.h> #include <linux/pci.h> #include <linux/gpio.h> #include <bcm63xx_regs.h> #include <bcm63xx_io.h> #include "bcm63xx_pcmcia.h" #define PFX "bcm63xx_pcmcia: " #ifdef CONFIG_CARDBUS /* if cardbus is used, platform device needs reference to actual pci * device */ static struct pci_dev *bcm63xx_cb_dev; #endif /* * read/write helper for pcmcia regs */ static inline u32 pcmcia_readl(struct bcm63xx_pcmcia_socket *skt, u32 off) { return bcm_readl(skt->base + off); } static inline void pcmcia_writel(struct bcm63xx_pcmcia_socket *skt, u32 val, u32 off) { bcm_writel(val, skt->base + off); } /* * This callback should (re-)initialise the socket, turn on status * interrupts and PCMCIA bus, and wait for power to stabilise so that * the card status signals report correctly. * * Hardware cannot do that. */ static int bcm63xx_pcmcia_sock_init(struct pcmcia_socket *sock) { return 0; } /* * This callback should remove power on the socket, disable IRQs from * the card, turn off status interrupts, and disable the PCMCIA bus. * * Hardware cannot do that. */ static int bcm63xx_pcmcia_suspend(struct pcmcia_socket *sock) { return 0; } /* * Implements the set_socket() operation for the in-kernel PCMCIA * service (formerly SS_SetSocket in Card Services). We more or * less punt all of this work and let the kernel handle the details * of power configuration, reset, &c. We also record the value of * `state' in order to regurgitate it to the PCMCIA core later. */ static int bcm63xx_pcmcia_set_socket(struct pcmcia_socket *sock, socket_state_t *state) { struct bcm63xx_pcmcia_socket *skt; unsigned long flags; u32 val; skt = sock->driver_data; spin_lock_irqsave(&skt->lock, flags); /* note: hardware cannot control socket power, so we will * always report SS_POWERON */ /* apply socket reset */ val = pcmcia_readl(skt, PCMCIA_C1_REG); if (state->flags & SS_RESET) val |= PCMCIA_C1_RESET_MASK; else val &= ~PCMCIA_C1_RESET_MASK; /* reverse reset logic for cardbus card */ if (skt->card_detected && (skt->card_type & CARD_CARDBUS)) val ^= PCMCIA_C1_RESET_MASK; pcmcia_writel(skt, val, PCMCIA_C1_REG); /* keep requested state for event reporting */ skt->requested_state = *state; spin_unlock_irqrestore(&skt->lock, flags); return 0; } /* * identity cardtype from VS[12] input, CD[12] input while only VS2 is * floating, and CD[12] input while only VS1 is floating */ enum { IN_VS1 = (1 << 0), IN_VS2 = (1 << 1), IN_CD1_VS2H = (1 << 2), IN_CD2_VS2H = (1 << 3), IN_CD1_VS1H = (1 << 4), IN_CD2_VS1H = (1 << 5), }; static const u8 vscd_to_cardtype[] = { /* VS1 float, VS2 float */ [IN_VS1 | IN_VS2] = (CARD_PCCARD | CARD_5V), /* VS1 grounded, VS2 float */ [IN_VS2] = (CARD_PCCARD | CARD_5V | CARD_3V), /* VS1 grounded, VS2 grounded */ [0] = (CARD_PCCARD | CARD_5V | CARD_3V | CARD_XV), /* VS1 tied to CD1, VS2 float */ [IN_VS1 | IN_VS2 | IN_CD1_VS1H] = (CARD_CARDBUS | CARD_3V), /* VS1 grounded, VS2 tied to CD2 */ [IN_VS2 | IN_CD2_VS2H] = (CARD_CARDBUS | CARD_3V | CARD_XV), /* VS1 tied to CD2, VS2 grounded */ [IN_VS1 | IN_CD2_VS1H] = (CARD_CARDBUS | CARD_3V | CARD_XV | CARD_YV), /* VS1 float, VS2 grounded */ [IN_VS1] = (CARD_PCCARD | CARD_XV), /* VS1 float, VS2 tied to CD2 */ [IN_VS1 | IN_VS2 | IN_CD2_VS2H] = (CARD_CARDBUS | CARD_3V), /* VS1 float, VS2 tied to CD1 */ [IN_VS1 | IN_VS2 | IN_CD1_VS2H] = (CARD_CARDBUS | CARD_XV | CARD_YV), /* VS1 tied to CD2, VS2 float */ [IN_VS1 | IN_VS2 | IN_CD2_VS1H] = (CARD_CARDBUS | CARD_YV), /* VS2 grounded, VS1 is tied to CD1, CD2 is grounded */ [IN_VS1 | IN_CD1_VS1H] = 0, /* ignore cardbay */ }; /* * poll hardware to check card insertion status */ static unsigned int __get_socket_status(struct bcm63xx_pcmcia_socket *skt) { unsigned int stat; u32 val; stat = 0; /* check CD for card presence */ val = pcmcia_readl(skt, PCMCIA_C1_REG); if (!(val & PCMCIA_C1_CD1_MASK) && !(val & PCMCIA_C1_CD2_MASK)) stat |= SS_DETECT; /* if new insertion, detect cardtype */ if ((stat & SS_DETECT) && !skt->card_detected) { unsigned int stat = 0; /* float VS1, float VS2 */ val |= PCMCIA_C1_VS1OE_MASK; val |= PCMCIA_C1_VS2OE_MASK; pcmcia_writel(skt, val, PCMCIA_C1_REG); /* wait for output to stabilize and read VS[12] */ udelay(10); val = pcmcia_readl(skt, PCMCIA_C1_REG); stat |= (val & PCMCIA_C1_VS1_MASK) ? IN_VS1 : 0; stat |= (val & PCMCIA_C1_VS2_MASK) ? IN_VS2 : 0; /* drive VS1 low, float VS2 */ val &= ~PCMCIA_C1_VS1OE_MASK; val |= PCMCIA_C1_VS2OE_MASK; pcmcia_writel(skt, val, PCMCIA_C1_REG); /* wait for output to stabilize and read CD[12] */ udelay(10); val = pcmcia_readl(skt, PCMCIA_C1_REG); stat |= (val & PCMCIA_C1_CD1_MASK) ? IN_CD1_VS2H : 0; stat |= (val & PCMCIA_C1_CD2_MASK) ? IN_CD2_VS2H : 0; /* float VS1, drive VS2 low */ val |= PCMCIA_C1_VS1OE_MASK; val &= ~PCMCIA_C1_VS2OE_MASK; pcmcia_writel(skt, val, PCMCIA_C1_REG); /* wait for output to stabilize and read CD[12] */ udelay(10); val = pcmcia_readl(skt, PCMCIA_C1_REG); stat |= (val & PCMCIA_C1_CD1_MASK) ? IN_CD1_VS1H : 0; stat |= (val & PCMCIA_C1_CD2_MASK) ? IN_CD2_VS1H : 0; /* guess cardtype from all this */ skt->card_type = vscd_to_cardtype[stat]; if (!skt->card_type) dev_err(&skt->socket.dev, "unsupported card type\n"); /* drive both VS pin to 0 again */ val &= ~(PCMCIA_C1_VS1OE_MASK | PCMCIA_C1_VS2OE_MASK); /* enable correct logic */ val &= ~(PCMCIA_C1_EN_PCMCIA_MASK | PCMCIA_C1_EN_CARDBUS_MASK); if (skt->card_type & CARD_PCCARD) val |= PCMCIA_C1_EN_PCMCIA_MASK; else val |= PCMCIA_C1_EN_CARDBUS_MASK; pcmcia_writel(skt, val, PCMCIA_C1_REG); } skt->card_detected = (stat & SS_DETECT) ? 1 : 0; /* report card type/voltage */ if (skt->card_type & CARD_CARDBUS) stat |= SS_CARDBUS; if (skt->card_type & CARD_3V) stat |= SS_3VCARD; if (skt->card_type & CARD_XV) stat |= SS_XVCARD; stat |= SS_POWERON; if (gpio_get_value(skt->pd->ready_gpio)) stat |= SS_READY; return stat; } /* * core request to get current socket status */ static int bcm63xx_pcmcia_get_status(struct pcmcia_socket *sock, unsigned int *status) { struct bcm63xx_pcmcia_socket *skt; skt = sock->driver_data; spin_lock_bh(&skt->lock); *status = __get_socket_status(skt); spin_unlock_bh(&skt->lock); return 0; } /* * socket polling timer callback */ static void bcm63xx_pcmcia_poll(unsigned long data) { struct bcm63xx_pcmcia_socket *skt; unsigned int stat, events; skt = (struct bcm63xx_pcmcia_socket *)data; spin_lock_bh(&skt->lock); stat = __get_socket_status(skt); /* keep only changed bits, and mask with required one from the * core */ events = (stat ^ skt->old_status) & skt->requested_state.csc_mask; skt->old_status = stat; spin_unlock_bh(&skt->lock); if (events) pcmcia_parse_events(&skt->socket, events); mod_timer(&skt->timer, jiffies + msecs_to_jiffies(BCM63XX_PCMCIA_POLL_RATE)); } static int bcm63xx_pcmcia_set_io_map(struct pcmcia_socket *sock, struct pccard_io_map *map) { /* this doesn't seem to be called by pcmcia layer if static * mapping is used */ return 0; } static int bcm63xx_pcmcia_set_mem_map(struct pcmcia_socket *sock, struct pccard_mem_map *map) { struct bcm63xx_pcmcia_socket *skt; struct resource *res; skt = sock->driver_data; if (map->flags & MAP_ATTRIB) res = skt->attr_res; else res = skt->common_res; map->static_start = res->start + map->card_start; return 0; } static struct pccard_operations bcm63xx_pcmcia_operations = { .init = bcm63xx_pcmcia_sock_init, .suspend = bcm63xx_pcmcia_suspend, .get_status = bcm63xx_pcmcia_get_status, .set_socket = bcm63xx_pcmcia_set_socket, .set_io_map = bcm63xx_pcmcia_set_io_map, .set_mem_map = bcm63xx_pcmcia_set_mem_map, }; /* * register pcmcia socket to core */ static int bcm63xx_drv_pcmcia_probe(struct platform_device *pdev) { struct bcm63xx_pcmcia_socket *skt; struct pcmcia_socket *sock; struct resource *res, *irq_res; unsigned int regmem_size = 0, iomem_size = 0; u32 val; int ret; skt = kzalloc(sizeof(*skt), GFP_KERNEL); if (!skt) return -ENOMEM; spin_lock_init(&skt->lock); sock = &skt->socket; sock->driver_data = skt; /* make sure we have all resources we need */ skt->common_res = platform_get_resource(pdev, IORESOURCE_MEM, 1); skt->attr_res = platform_get_resource(pdev, IORESOURCE_MEM, 2); irq_res = platform_get_resource(pdev, IORESOURCE_IRQ, 0); skt->pd = pdev->dev.platform_data; if (!skt->common_res || !skt->attr_res || !irq_res || !skt->pd) { ret = -EINVAL; goto err; } /* remap pcmcia registers */ res = platform_get_resource(pdev, IORESOURCE_MEM, 0); regmem_size = resource_size(res); if (!request_mem_region(res->start, regmem_size, "bcm63xx_pcmcia")) { ret = -EINVAL; goto err; } skt->reg_res = res; skt->base = ioremap(res->start, regmem_size); if (!skt->base) { ret = -ENOMEM; goto err; } /* remap io registers */ res = platform_get_resource(pdev, IORESOURCE_MEM, 3); iomem_size = resource_size(res); skt->io_base = ioremap(res->start, iomem_size); if (!skt->io_base) { ret = -ENOMEM; goto err; } /* resources are static */ sock->resource_ops = &pccard_static_ops; sock->ops = &bcm63xx_pcmcia_operations; sock->owner = THIS_MODULE; sock->dev.parent = &pdev->dev; sock->features = SS_CAP_STATIC_MAP | SS_CAP_PCCARD; sock->io_offset = (unsigned long)skt->io_base; sock->pci_irq = irq_res->start; #ifdef CONFIG_CARDBUS sock->cb_dev = bcm63xx_cb_dev; if (bcm63xx_cb_dev) sock->features |= SS_CAP_CARDBUS; #endif /* assume common & attribute memory have the same size */ sock->map_size = resource_size(skt->common_res); /* initialize polling timer */ setup_timer(&skt->timer, bcm63xx_pcmcia_poll, (unsigned long)skt); /* initialize pcmcia control register, drive VS[12] to 0, * leave CB IDSEL to the old value since it is set by the PCI * layer */ val = pcmcia_readl(skt, PCMCIA_C1_REG); val &= PCMCIA_C1_CBIDSEL_MASK; val |= PCMCIA_C1_EN_PCMCIA_GPIO_MASK; pcmcia_writel(skt, val, PCMCIA_C1_REG); /* * Hardware has only one set of timings registers, not one for * each memory access type, so we configure them for the * slowest one: attribute memory. */ val = PCMCIA_C2_DATA16_MASK; val |= 10 << PCMCIA_C2_RWCOUNT_SHIFT; val |= 6 << PCMCIA_C2_INACTIVE_SHIFT; val |= 3 << PCMCIA_C2_SETUP_SHIFT; val |= 3 << PCMCIA_C2_HOLD_SHIFT; pcmcia_writel(skt, val, PCMCIA_C2_REG); ret = pcmcia_register_socket(sock); if (ret) goto err; /* start polling socket */ mod_timer(&skt->timer, jiffies + msecs_to_jiffies(BCM63XX_PCMCIA_POLL_RATE)); platform_set_drvdata(pdev, skt); return 0; err: if (skt->io_base) iounmap(skt->io_base); if (skt->base) iounmap(skt->base); if (skt->reg_res) release_mem_region(skt->reg_res->start, regmem_size); kfree(skt); return ret; } static int bcm63xx_drv_pcmcia_remove(struct platform_device *pdev) { struct bcm63xx_pcmcia_socket *skt; struct resource *res; skt = platform_get_drvdata(pdev); del_timer_sync(&skt->timer); iounmap(skt->base); iounmap(skt->io_base); res = skt->reg_res; release_mem_region(res->start, resource_size(res)); kfree(skt); return 0; } struct platform_driver bcm63xx_pcmcia_driver = { .probe = bcm63xx_drv_pcmcia_probe, .remove = bcm63xx_drv_pcmcia_remove, .driver = { .name = "bcm63xx_pcmcia", .owner = THIS_MODULE, }, }; #ifdef CONFIG_CARDBUS static int bcm63xx_cb_probe(struct pci_dev *dev, const struct pci_device_id *id) { /* keep pci device */ bcm63xx_cb_dev = dev; return platform_driver_register(&bcm63xx_pcmcia_driver); } static void bcm63xx_cb_exit(struct pci_dev *dev) { platform_driver_unregister(&bcm63xx_pcmcia_driver); bcm63xx_cb_dev = NULL; } static const struct pci_device_id bcm63xx_cb_table[] = { { .vendor = PCI_VENDOR_ID_BROADCOM, .device = BCM6348_CPU_ID, .subvendor = PCI_VENDOR_ID_BROADCOM, .subdevice = PCI_ANY_ID, .class = PCI_CLASS_BRIDGE_CARDBUS << 8, .class_mask = ~0, }, { .vendor = PCI_VENDOR_ID_BROADCOM, .device = BCM6358_CPU_ID, .subvendor = PCI_VENDOR_ID_BROADCOM, .subdevice = PCI_ANY_ID, .class = PCI_CLASS_BRIDGE_CARDBUS << 8, .class_mask = ~0, }, { }, }; MODULE_DEVICE_TABLE(pci, bcm63xx_cb_table); static struct pci_driver bcm63xx_cardbus_driver = { .name = "bcm63xx_cardbus", .id_table = bcm63xx_cb_table, .probe = bcm63xx_cb_probe, .remove = bcm63xx_cb_exit, }; #endif /* * if cardbus support is enabled, register our platform device after * our fake cardbus bridge has been registered */ static int __init bcm63xx_pcmcia_init(void) { #ifdef CONFIG_CARDBUS return pci_register_driver(&bcm63xx_cardbus_driver); #else return platform_driver_register(&bcm63xx_pcmcia_driver); #endif } static void __exit bcm63xx_pcmcia_exit(void) { #ifdef CONFIG_CARDBUS return pci_unregister_driver(&bcm63xx_cardbus_driver); #else platform_driver_unregister(&bcm63xx_pcmcia_driver); #endif } module_init(bcm63xx_pcmcia_init); module_exit(bcm63xx_pcmcia_exit); MODULE_LICENSE("GPL"); MODULE_AUTHOR("Maxime Bizon <mbizon@freebox.fr>"); MODULE_DESCRIPTION("Linux PCMCIA Card Services: bcm63xx Socket Controller");
gpl-2.0
cfriedt/bluetooth-next
drivers/net/wireless/broadcom/b43/radio_2056.c
2063
521650
/* Broadcom B43 wireless driver IEEE 802.11n 2056 radio device data tables Copyright (c) 2010 Rafał Miłecki <zajec5@gmail.com> This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Steet, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "b43.h" #include "radio_2056.h" #include "phy_common.h" struct b2056_inittab_entry { /* Value to write if we use the 5GHz band. */ u16 ghz5; /* Value to write if we use the 2.4GHz band. */ u16 ghz2; /* Flags */ u8 flags; }; #define B2056_INITTAB_ENTRY_OK 0x01 #define B2056_INITTAB_UPLOAD 0x02 #define UPLOAD .flags = B2056_INITTAB_ENTRY_OK | B2056_INITTAB_UPLOAD #define NOUPLOAD .flags = B2056_INITTAB_ENTRY_OK struct b2056_inittabs_pts { const struct b2056_inittab_entry *syn; unsigned int syn_length; const struct b2056_inittab_entry *tx; unsigned int tx_length; const struct b2056_inittab_entry *rx; unsigned int rx_length; }; static const struct b2056_inittab_entry b2056_inittab_phy_rev3_syn[] = { [B2056_SYN_RESERVED_ADDR2] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_RESERVED_ADDR3] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_RESERVED_ADDR4] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_RESERVED_ADDR5] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_RESERVED_ADDR6] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_RESERVED_ADDR7] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_COM_CTRL] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_COM_PU] = { .ghz5 = 0x0001, .ghz2 = 0x0001, NOUPLOAD, }, [B2056_SYN_COM_OVR] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_COM_RESET] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_COM_RCAL] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_COM_RC_RXLPF] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_COM_RC_TXLPF] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_COM_RC_RXHPF] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_RESERVED_ADDR16] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_RESERVED_ADDR17] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_RESERVED_ADDR18] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_RESERVED_ADDR19] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_RESERVED_ADDR20] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_RESERVED_ADDR21] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_RESERVED_ADDR22] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_RESERVED_ADDR23] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_RESERVED_ADDR24] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_RESERVED_ADDR25] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_RESERVED_ADDR26] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_RESERVED_ADDR27] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_RESERVED_ADDR28] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_RESERVED_ADDR29] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_RESERVED_ADDR30] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_RESERVED_ADDR31] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_GPIO_MASTER1] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_GPIO_MASTER2] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_TOPBIAS_MASTER] = { .ghz5 = 0x0060, .ghz2 = 0x0060, NOUPLOAD, }, [B2056_SYN_TOPBIAS_RCAL] = { .ghz5 = 0x0006, .ghz2 = 0x0006, NOUPLOAD, }, [B2056_SYN_AFEREG] = { .ghz5 = 0x000c, .ghz2 = 0x000c, NOUPLOAD, }, [B2056_SYN_TEMPPROCSENSE] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_TEMPPROCSENSEIDAC] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_TEMPPROCSENSERCAL] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LPO] = { .ghz5 = 0x0001, .ghz2 = 0x0001, NOUPLOAD, }, [B2056_SYN_VDDCAL_MASTER] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_VDDCAL_IDAC] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_VDDCAL_STATUS] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_RCAL_MASTER] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_RCAL_CODE_OUT] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_RCCAL_CTRL0] = { .ghz5 = 0x000d, .ghz2 = 0x000d, NOUPLOAD, }, [B2056_SYN_RCCAL_CTRL1] = { .ghz5 = 0x001f, .ghz2 = 0x001f, NOUPLOAD, }, [B2056_SYN_RCCAL_CTRL2] = { .ghz5 = 0x0015, .ghz2 = 0x0015, NOUPLOAD, }, [B2056_SYN_RCCAL_CTRL3] = { .ghz5 = 0x000f, .ghz2 = 0x000f, NOUPLOAD, }, [B2056_SYN_RCCAL_CTRL4] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_RCCAL_CTRL5] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_RCCAL_CTRL6] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_RCCAL_CTRL7] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_RCCAL_CTRL8] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_RCCAL_CTRL9] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_RCCAL_CTRL10] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_RCCAL_CTRL11] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_ZCAL_SPARE1] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_ZCAL_SPARE2] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_PLL_MAST1] = { .ghz5 = 0x0013, .ghz2 = 0x0013, NOUPLOAD, }, [B2056_SYN_PLL_MAST2] = { .ghz5 = 0x000f, .ghz2 = 0x000f, NOUPLOAD, }, [B2056_SYN_PLL_MAST3] = { .ghz5 = 0x0018, .ghz2 = 0x0018, NOUPLOAD, }, [B2056_SYN_PLL_BIAS_RESET] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_PLL_XTAL0] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_PLL_XTAL1] = { .ghz5 = 0x0020, .ghz2 = 0x0020, NOUPLOAD, }, [B2056_SYN_PLL_XTAL3] = { .ghz5 = 0x0020, .ghz2 = 0x0020, NOUPLOAD, }, [B2056_SYN_PLL_XTAL4] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_PLL_XTAL5] = { .ghz5 = 0x0077, .ghz2 = 0x0077, NOUPLOAD, }, [B2056_SYN_PLL_XTAL6] = { .ghz5 = 0x0007, .ghz2 = 0x0007, NOUPLOAD, }, [B2056_SYN_PLL_REFDIV] = { .ghz5 = 0x0001, .ghz2 = 0x0001, NOUPLOAD, }, [B2056_SYN_PLL_PFD] = { .ghz5 = 0x0004, .ghz2 = 0x0004, NOUPLOAD, }, [B2056_SYN_PLL_CP1] = { .ghz5 = 0x000f, .ghz2 = 0x000f, NOUPLOAD, }, [B2056_SYN_PLL_CP2] = { .ghz5 = 0x0030, .ghz2 = 0x0030, NOUPLOAD, }, [B2056_SYN_PLL_CP3] = { .ghz5 = 0x0032, .ghz2 = 0x0032, NOUPLOAD, }, [B2056_SYN_PLL_LOOPFILTER1] = { .ghz5 = 0x000d, .ghz2 = 0x000d, NOUPLOAD, }, [B2056_SYN_PLL_LOOPFILTER2] = { .ghz5 = 0x000d, .ghz2 = 0x000d, NOUPLOAD, }, [B2056_SYN_PLL_LOOPFILTER3] = { .ghz5 = 0x0004, .ghz2 = 0x0004, NOUPLOAD, }, [B2056_SYN_PLL_LOOPFILTER4] = { .ghz5 = 0x0006, .ghz2 = 0x0006, NOUPLOAD, }, [B2056_SYN_PLL_LOOPFILTER5] = { .ghz5 = 0x0001, .ghz2 = 0x0001, NOUPLOAD, }, [B2056_SYN_PLL_MMD1] = { .ghz5 = 0x001c, .ghz2 = 0x001c, NOUPLOAD, }, [B2056_SYN_PLL_MMD2] = { .ghz5 = 0x0002, .ghz2 = 0x0002, NOUPLOAD, }, [B2056_SYN_PLL_VCO1] = { .ghz5 = 0x0002, .ghz2 = 0x0002, NOUPLOAD, }, [B2056_SYN_PLL_VCO2] = { .ghz5 = 0x00f7, .ghz2 = 0x00f7, UPLOAD, }, [B2056_SYN_PLL_MONITOR1] = { .ghz5 = 0x00b4, .ghz2 = 0x00b4, NOUPLOAD, }, [B2056_SYN_PLL_MONITOR2] = { .ghz5 = 0x00d2, .ghz2 = 0x00d2, NOUPLOAD, }, [B2056_SYN_PLL_VCOCAL1] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_PLL_VCOCAL2] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_PLL_VCOCAL4] = { .ghz5 = 0x0004, .ghz2 = 0x0004, NOUPLOAD, }, [B2056_SYN_PLL_VCOCAL5] = { .ghz5 = 0x0096, .ghz2 = 0x0096, NOUPLOAD, }, [B2056_SYN_PLL_VCOCAL6] = { .ghz5 = 0x003e, .ghz2 = 0x003e, NOUPLOAD, }, [B2056_SYN_PLL_VCOCAL7] = { .ghz5 = 0x003e, .ghz2 = 0x003e, NOUPLOAD, }, [B2056_SYN_PLL_VCOCAL8] = { .ghz5 = 0x0013, .ghz2 = 0x0013, NOUPLOAD, }, [B2056_SYN_PLL_VCOCAL9] = { .ghz5 = 0x0002, .ghz2 = 0x0002, NOUPLOAD, }, [B2056_SYN_PLL_VCOCAL10] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_PLL_VCOCAL11] = { .ghz5 = 0x0007, .ghz2 = 0x0007, NOUPLOAD, }, [B2056_SYN_PLL_VCOCAL12] = { .ghz5 = 0x0007, .ghz2 = 0x0007, UPLOAD, }, [B2056_SYN_PLL_VCOCAL13] = { .ghz5 = 0x0008, .ghz2 = 0x0008, NOUPLOAD, }, [B2056_SYN_PLL_VREG] = { .ghz5 = 0x0003, .ghz2 = 0x0003, NOUPLOAD, }, [B2056_SYN_PLL_STATUS1] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_PLL_STATUS2] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_PLL_STATUS3] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_PU0] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_PU1] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_PU2] = { .ghz5 = 0x0040, .ghz2 = 0x0040, NOUPLOAD, }, [B2056_SYN_LOGEN_PU3] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_PU5] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_PU6] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_PU7] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_PU8] = { .ghz5 = 0x0001, .ghz2 = 0x0001, NOUPLOAD, }, [B2056_SYN_LOGEN_BIAS_RESET] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_RCCR1] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_VCOBUF1] = { .ghz5 = 0x0060, .ghz2 = 0x0060, NOUPLOAD, }, [B2056_SYN_LOGEN_MIXER1] = { .ghz5 = 0x0066, .ghz2 = 0x0066, NOUPLOAD, }, [B2056_SYN_LOGEN_MIXER2] = { .ghz5 = 0x000c, .ghz2 = 0x000c, NOUPLOAD, }, [B2056_SYN_LOGEN_BUF1] = { .ghz5 = 0x0066, .ghz2 = 0x0066, NOUPLOAD, }, [B2056_SYN_LOGENBUF2] = { .ghz5 = 0x008f, .ghz2 = 0x008f, UPLOAD, }, [B2056_SYN_LOGEN_BUF3] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_BUF4] = { .ghz5 = 0x00cc, .ghz2 = 0x00cc, NOUPLOAD, }, [B2056_SYN_LOGEN_DIV1] = { .ghz5 = 0x0001, .ghz2 = 0x0001, NOUPLOAD, }, [B2056_SYN_LOGEN_DIV2] = { .ghz5 = 0x0066, .ghz2 = 0x0066, NOUPLOAD, }, [B2056_SYN_LOGEN_DIV3] = { .ghz5 = 0x0066, .ghz2 = 0x0066, NOUPLOAD, }, [B2056_SYN_LOGEN_ACL1] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_ACL2] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_ACL3] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_ACL4] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_ACL5] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_ACL6] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_ACLOUT] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_ACLCAL1] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_ACLCAL2] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_ACLCAL3] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_CALEN] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_PEAKDET1] = { .ghz5 = 0x00ff, .ghz2 = 0x00ff, NOUPLOAD, }, [B2056_SYN_LOGEN_CORE_ACL_OVR] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_RX_DIFF_ACL_OVR] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_TX_DIFF_ACL_OVR] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_RX_CMOS_ACL_OVR] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_TX_CMOS_ACL_OVR] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_VCOBUF2] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_MIXER3] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_BUF5] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_BUF6] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_CBUFRX1] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_CBUFRX2] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_CBUFRX3] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_CBUFRX4] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_CBUFTX1] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_CBUFTX2] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_CBUFTX3] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_CBUFTX4] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_CMOSRX1] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_CMOSRX2] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_CMOSRX3] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_CMOSRX4] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_CMOSTX1] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_CMOSTX2] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_CMOSTX3] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_CMOSTX4] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_VCOBUF2_OVRVAL]= { .ghz5 = 0x0006, .ghz2 = 0x0006, NOUPLOAD, }, [B2056_SYN_LOGEN_MIXER3_OVRVAL] = { .ghz5 = 0x0066, .ghz2 = 0x0066, NOUPLOAD, }, [B2056_SYN_LOGEN_BUF5_OVRVAL] = { .ghz5 = 0x0066, .ghz2 = 0x0066, NOUPLOAD, }, [B2056_SYN_LOGEN_BUF6_OVRVAL] = { .ghz5 = 0x0066, .ghz2 = 0x0066, NOUPLOAD, }, [B2056_SYN_LOGEN_CBUFRX1_OVRVAL]= { .ghz5 = 0x0066, .ghz2 = 0x0066, NOUPLOAD, }, [B2056_SYN_LOGEN_CBUFRX2_OVRVAL]= { .ghz5 = 0x0066, .ghz2 = 0x0066, NOUPLOAD, }, [B2056_SYN_LOGEN_CBUFRX3_OVRVAL]= { .ghz5 = 0x0066, .ghz2 = 0x0066, NOUPLOAD, }, [B2056_SYN_LOGEN_CBUFRX4_OVRVAL]= { .ghz5 = 0x0066, .ghz2 = 0x0066, NOUPLOAD, }, [B2056_SYN_LOGEN_CBUFTX1_OVRVAL]= { .ghz5 = 0x0066, .ghz2 = 0x0066, NOUPLOAD, }, [B2056_SYN_LOGEN_CBUFTX2_OVRVAL]= { .ghz5 = 0x0066, .ghz2 = 0x0066, NOUPLOAD, }, [B2056_SYN_LOGEN_CBUFTX3_OVRVAL]= { .ghz5 = 0x0066, .ghz2 = 0x0066, NOUPLOAD, }, [B2056_SYN_LOGEN_CBUFTX4_OVRVAL]= { .ghz5 = 0x0066, .ghz2 = 0x0066, NOUPLOAD, }, [B2056_SYN_LOGEN_CMOSRX1_OVRVAL]= { .ghz5 = 0x0066, .ghz2 = 0x0066, NOUPLOAD, }, [B2056_SYN_LOGEN_CMOSRX2_OVRVAL]= { .ghz5 = 0x0066, .ghz2 = 0x0066, NOUPLOAD, }, [B2056_SYN_LOGEN_CMOSRX3_OVRVAL]= { .ghz5 = 0x0066, .ghz2 = 0x0066, NOUPLOAD, }, [B2056_SYN_LOGEN_CMOSRX4_OVRVAL]= { .ghz5 = 0x0066, .ghz2 = 0x0066, NOUPLOAD, }, [B2056_SYN_LOGEN_CMOSTX1_OVRVAL]= { .ghz5 = 0x0066, .ghz2 = 0x0066, NOUPLOAD, }, [B2056_SYN_LOGEN_CMOSTX2_OVRVAL]= { .ghz5 = 0x0066, .ghz2 = 0x0066, NOUPLOAD, }, [B2056_SYN_LOGEN_CMOSTX3_OVRVAL]= { .ghz5 = 0x0066, .ghz2 = 0x0066, NOUPLOAD, }, [B2056_SYN_LOGEN_CMOSTX4_OVRVAL]= { .ghz5 = 0x0066, .ghz2 = 0x0066, NOUPLOAD, }, [B2056_SYN_LOGEN_ACL_WAITCNT] = { .ghz5 = 0x000a, .ghz2 = 0x000a, NOUPLOAD, }, [B2056_SYN_LOGEN_CORE_CALVALID] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_RX_CMOS_CALVALID] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_TX_CMOS_VALID] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, }; static const struct b2056_inittab_entry b2056_inittab_phy_rev3_tx[] = { [B2056_TX_RESERVED_ADDR2] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_RESERVED_ADDR3] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_RESERVED_ADDR4] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_RESERVED_ADDR5] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_RESERVED_ADDR6] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_RESERVED_ADDR7] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_COM_CTRL] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_COM_PU] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_COM_OVR] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_COM_RESET] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_COM_RCAL] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_COM_RC_RXLPF] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_COM_RC_TXLPF] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_COM_RC_RXHPF] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_RESERVED_ADDR16] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_RESERVED_ADDR17] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_RESERVED_ADDR18] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_RESERVED_ADDR19] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_RESERVED_ADDR20] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_RESERVED_ADDR21] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_RESERVED_ADDR22] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_RESERVED_ADDR23] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_RESERVED_ADDR24] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_RESERVED_ADDR25] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_RESERVED_ADDR26] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_RESERVED_ADDR27] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_RESERVED_ADDR28] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_RESERVED_ADDR29] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_RESERVED_ADDR30] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_RESERVED_ADDR31] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_IQCAL_GAIN_BW] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_LOFT_FINE_I] = { .ghz5 = 0x0088, .ghz2 = 0x0088, NOUPLOAD, }, [B2056_TX_LOFT_FINE_Q] = { .ghz5 = 0x0088, .ghz2 = 0x0088, NOUPLOAD, }, [B2056_TX_LOFT_COARSE_I] = { .ghz5 = 0x0088, .ghz2 = 0x0088, NOUPLOAD, }, [B2056_TX_LOFT_COARSE_Q] = { .ghz5 = 0x0088, .ghz2 = 0x0088, NOUPLOAD, }, [B2056_TX_TX_COM_MASTER1] = { .ghz5 = 0x000c, .ghz2 = 0x000c, NOUPLOAD, }, [B2056_TX_TX_COM_MASTER2] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_RXIQCAL_TXMUX] = { .ghz5 = 0x0003, .ghz2 = 0x0003, NOUPLOAD, }, [B2056_TX_TX_SSI_MASTER] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_IQCAL_VCM_HG] = { .ghz5 = 0x0003, .ghz2 = 0x0003, NOUPLOAD, }, [B2056_TX_IQCAL_IDAC] = { .ghz5 = 0x0037, .ghz2 = 0x0037, NOUPLOAD, }, [B2056_TX_TSSI_VCM] = { .ghz5 = 0x0003, .ghz2 = 0x0003, NOUPLOAD, }, [B2056_TX_TX_AMP_DET] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_TX_SSI_MUX] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_TSSIA] = { .ghz5 = 0x0001, .ghz2 = 0x0001, NOUPLOAD, }, [B2056_TX_TSSIG] = { .ghz5 = 0x0001, .ghz2 = 0x0001, NOUPLOAD, }, [B2056_TX_TSSI_MISC1] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_TSSI_MISC2] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_TSSI_MISC3] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_PA_SPARE1] = { .ghz5 = 0x0011, .ghz2 = 0x0011, NOUPLOAD, }, [B2056_TX_PA_SPARE2] = { .ghz5 = 0x0011, .ghz2 = 0x0011, NOUPLOAD, }, [B2056_TX_INTPAA_MASTER] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_INTPAA_GAIN] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_INTPAA_BOOST_TUNE] = { .ghz5 = 0x0003, .ghz2 = 0x0003, NOUPLOAD, }, [B2056_TX_INTPAA_IAUX_STAT] = { .ghz5 = 0x000f, .ghz2 = 0x000f, NOUPLOAD, }, [B2056_TX_INTPAA_IAUX_DYN] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_INTPAA_IMAIN_STAT] = { .ghz5 = 0x002d, .ghz2 = 0x002d, NOUPLOAD, }, [B2056_TX_INTPAA_IMAIN_DYN] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_INTPAA_CASCBIAS] = { .ghz5 = 0x006e, .ghz2 = 0x006e, NOUPLOAD, }, [B2056_TX_INTPAA_PASLOPE] = { .ghz5 = 0x00f0, .ghz2 = 0x00f0, UPLOAD, }, [B2056_TX_INTPAA_PA_MISC] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_INTPAG_MASTER] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_INTPAG_GAIN] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_INTPAG_BOOST_TUNE] = { .ghz5 = 0x0003, .ghz2 = 0x0003, NOUPLOAD, }, [B2056_TX_INTPAG_IAUX_STAT] = { .ghz5 = 0x0003, .ghz2 = 0x0003, NOUPLOAD, }, [B2056_TX_INTPAG_IAUX_DYN] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_INTPAG_IMAIN_STAT] = { .ghz5 = 0x001e, .ghz2 = 0x001e, NOUPLOAD, }, [B2056_TX_INTPAG_IMAIN_DYN] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_INTPAG_CASCBIAS] = { .ghz5 = 0x006e, .ghz2 = 0x006e, NOUPLOAD, }, [B2056_TX_INTPAG_PASLOPE] = { .ghz5 = 0x00f0, .ghz2 = 0x00f0, UPLOAD, }, [B2056_TX_INTPAG_PA_MISC] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_PADA_MASTER] = { .ghz5 = 0x0002, .ghz2 = 0x0002, NOUPLOAD, }, [B2056_TX_PADA_IDAC] = { .ghz5 = 0x00ff, .ghz2 = 0x00ff, UPLOAD, }, [B2056_TX_PADA_CASCBIAS] = { .ghz5 = 0x000c, .ghz2 = 0x000c, NOUPLOAD, }, [B2056_TX_PADA_GAIN] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_PADA_BOOST_TUNE] = { .ghz5 = 0x0038, .ghz2 = 0x0038, NOUPLOAD, }, [B2056_TX_PADA_SLOPE] = { .ghz5 = 0x0070, .ghz2 = 0x0070, UPLOAD, }, [B2056_TX_PADG_MASTER] = { .ghz5 = 0x0002, .ghz2 = 0x0002, NOUPLOAD, }, [B2056_TX_PADG_IDAC] = { .ghz5 = 0x0088, .ghz2 = 0x0088, NOUPLOAD, }, [B2056_TX_PADG_CASCBIAS] = { .ghz5 = 0x000c, .ghz2 = 0x000c, NOUPLOAD, }, [B2056_TX_PADG_GAIN] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_PADG_BOOST_TUNE] = { .ghz5 = 0x0008, .ghz2 = 0x0008, NOUPLOAD, }, [B2056_TX_PADG_SLOPE] = { .ghz5 = 0x0070, .ghz2 = 0x0070, UPLOAD, }, [B2056_TX_PGAA_MASTER] = { .ghz5 = 0x0002, .ghz2 = 0x0002, NOUPLOAD, }, [B2056_TX_PGAA_IDAC] = { .ghz5 = 0x00ff, .ghz2 = 0x00ff, UPLOAD, }, [B2056_TX_PGAA_GAIN] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_PGAA_BOOST_TUNE] = { .ghz5 = 0x0083, .ghz2 = 0x0083, NOUPLOAD, }, [B2056_TX_PGAA_SLOPE] = { .ghz5 = 0x0077, .ghz2 = 0x0077, UPLOAD, }, [B2056_TX_PGAA_MISC] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_PGAG_MASTER] = { .ghz5 = 0x0002, .ghz2 = 0x0002, NOUPLOAD, }, [B2056_TX_PGAG_IDAC] = { .ghz5 = 0x0088, .ghz2 = 0x0088, NOUPLOAD, }, [B2056_TX_PGAG_GAIN] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_PGAG_BOOST_TUNE] = { .ghz5 = 0x0008, .ghz2 = 0x0008, NOUPLOAD, }, [B2056_TX_PGAG_SLOPE] = { .ghz5 = 0x0077, .ghz2 = 0x0077, UPLOAD, }, [B2056_TX_PGAG_MISC] = { .ghz5 = 0x0001, .ghz2 = 0x0001, NOUPLOAD, }, [B2056_TX_MIXA_MASTER] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_MIXA_BOOST_TUNE] = { .ghz5 = 0x0007, .ghz2 = 0x0007, NOUPLOAD, }, [B2056_TX_MIXG] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_MIXG_BOOST_TUNE] = { .ghz5 = 0x0007, .ghz2 = 0x0007, NOUPLOAD, }, [B2056_TX_BB_GM_MASTER] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_GMBB_GM] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_GMBB_IDAC] = { .ghz5 = 0x0074, .ghz2 = 0x0074, UPLOAD, }, [B2056_TX_TXLPF_MASTER] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_TXLPF_RCCAL] = { .ghz5 = 0x000a, .ghz2 = 0x000a, NOUPLOAD, }, [B2056_TX_TXLPF_RCCAL_OFF0] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_TXLPF_RCCAL_OFF1] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_TXLPF_RCCAL_OFF2] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_TXLPF_RCCAL_OFF3] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_TXLPF_RCCAL_OFF4] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_TXLPF_RCCAL_OFF5] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_TXLPF_RCCAL_OFF6] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_TXLPF_BW] = { .ghz5 = 0x0002, .ghz2 = 0x0002, NOUPLOAD, }, [B2056_TX_TXLPF_GAIN] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_TXLPF_IDAC] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_TXLPF_IDAC_0] = { .ghz5 = 0x000e, .ghz2 = 0x000e, NOUPLOAD, }, [B2056_TX_TXLPF_IDAC_1] = { .ghz5 = 0x000e, .ghz2 = 0x000e, NOUPLOAD, }, [B2056_TX_TXLPF_IDAC_2] = { .ghz5 = 0x000e, .ghz2 = 0x000e, NOUPLOAD, }, [B2056_TX_TXLPF_IDAC_3] = { .ghz5 = 0x0013, .ghz2 = 0x0013, NOUPLOAD, }, [B2056_TX_TXLPF_IDAC_4] = { .ghz5 = 0x0013, .ghz2 = 0x0013, NOUPLOAD, }, [B2056_TX_TXLPF_IDAC_5] = { .ghz5 = 0x001b, .ghz2 = 0x001b, NOUPLOAD, }, [B2056_TX_TXLPF_IDAC_6] = { .ghz5 = 0x001b, .ghz2 = 0x001b, NOUPLOAD, }, [B2056_TX_TXLPF_OPAMP_IDAC] = { .ghz5 = 0x0055, .ghz2 = 0x0055, NOUPLOAD, }, [B2056_TX_TXLPF_MISC] = { .ghz5 = 0x005b, .ghz2 = 0x005b, NOUPLOAD, }, [B2056_TX_TXSPARE1] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_TXSPARE2] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_TXSPARE3] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_TXSPARE4] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_TXSPARE5] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_TXSPARE6] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_TXSPARE7] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_TXSPARE8] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_TXSPARE9] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_TXSPARE10] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_TXSPARE11] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_TXSPARE12] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_TXSPARE13] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_TXSPARE14] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_TXSPARE15] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_TXSPARE16] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_STATUS_INTPA_GAIN] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_STATUS_PAD_GAIN] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_STATUS_PGA_GAIN] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_STATUS_GM_TXLPF_GAIN] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_STATUS_TXLPF_BW] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_STATUS_TXLPF_RC] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, }; static const struct b2056_inittab_entry b2056_inittab_phy_rev3_rx[] = { [B2056_RX_RESERVED_ADDR2] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RESERVED_ADDR3] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RESERVED_ADDR4] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RESERVED_ADDR5] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RESERVED_ADDR6] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RESERVED_ADDR7] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_COM_CTRL] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_COM_PU] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_COM_OVR] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_COM_RESET] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_COM_RCAL] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_COM_RC_RXLPF] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_COM_RC_TXLPF] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_COM_RC_RXHPF] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RESERVED_ADDR16] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RESERVED_ADDR17] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RESERVED_ADDR18] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RESERVED_ADDR19] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RESERVED_ADDR20] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RESERVED_ADDR21] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RESERVED_ADDR22] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RESERVED_ADDR23] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RESERVED_ADDR24] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RESERVED_ADDR25] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RESERVED_ADDR26] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RESERVED_ADDR27] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RESERVED_ADDR28] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RESERVED_ADDR29] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RESERVED_ADDR30] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RESERVED_ADDR31] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RXIQCAL_RXMUX] = { .ghz5 = 0x0003, .ghz2 = 0x0003, NOUPLOAD, }, [B2056_RX_RSSI_PU] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RSSI_SEL] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RSSI_GAIN] = { .ghz5 = 0x0090, .ghz2 = 0x0090, NOUPLOAD, }, [B2056_RX_RSSI_NB_IDAC] = { .ghz5 = 0x0055, .ghz2 = 0x0055, NOUPLOAD, }, [B2056_RX_RSSI_WB2I_IDAC_1] = { .ghz5 = 0x0015, .ghz2 = 0x0015, NOUPLOAD, }, [B2056_RX_RSSI_WB2I_IDAC_2] = { .ghz5 = 0x0005, .ghz2 = 0x0005, NOUPLOAD, }, [B2056_RX_RSSI_WB2Q_IDAC_1] = { .ghz5 = 0x0015, .ghz2 = 0x0015, NOUPLOAD, }, [B2056_RX_RSSI_WB2Q_IDAC_2] = { .ghz5 = 0x0005, .ghz2 = 0x0005, NOUPLOAD, }, [B2056_RX_RSSI_POLE] = { .ghz5 = 0x0020, .ghz2 = 0x0020, NOUPLOAD, }, [B2056_RX_RSSI_WB1_IDAC] = { .ghz5 = 0x0011, .ghz2 = 0x0011, NOUPLOAD, }, [B2056_RX_RSSI_MISC] = { .ghz5 = 0x0090, .ghz2 = 0x0090, NOUPLOAD, }, [B2056_RX_LNAA_MASTER] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_LNAA_TUNE] = { .ghz5 = 0x0088, .ghz2 = 0x0088, NOUPLOAD, }, [B2056_RX_LNAA_GAIN] = { .ghz5 = 0x0032, .ghz2 = 0x0032, NOUPLOAD, }, [B2056_RX_LNA_A_SLOPE] = { .ghz5 = 0x0077, .ghz2 = 0x0077, NOUPLOAD, }, [B2056_RX_BIASPOLE_LNAA1_IDAC] = { .ghz5 = 0x0017, .ghz2 = 0x0017, UPLOAD, }, [B2056_RX_LNAA2_IDAC] = { .ghz5 = 0x00ff, .ghz2 = 0x00ff, UPLOAD, }, [B2056_RX_LNA1A_MISC] = { .ghz5 = 0x0020, .ghz2 = 0x0020, NOUPLOAD, }, [B2056_RX_LNAG_MASTER] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_LNAG_TUNE] = { .ghz5 = 0x0088, .ghz2 = 0x0088, NOUPLOAD, }, [B2056_RX_LNAG_GAIN] = { .ghz5 = 0x0032, .ghz2 = 0x0032, NOUPLOAD, }, [B2056_RX_LNA_G_SLOPE] = { .ghz5 = 0x0077, .ghz2 = 0x0077, NOUPLOAD, }, [B2056_RX_BIASPOLE_LNAG1_IDAC] = { .ghz5 = 0x0017, .ghz2 = 0x0017, UPLOAD, }, [B2056_RX_LNAG2_IDAC] = { .ghz5 = 0x00f0, .ghz2 = 0x00f0, UPLOAD, }, [B2056_RX_LNA1G_MISC] = { .ghz5 = 0x0020, .ghz2 = 0x0020, NOUPLOAD, }, [B2056_RX_MIXA_MASTER] = { .ghz5 = 0x0008, .ghz2 = 0x0008, NOUPLOAD, }, [B2056_RX_MIXA_VCM] = { .ghz5 = 0x0099, .ghz2 = 0x0099, NOUPLOAD, }, [B2056_RX_MIXA_CTRLPTAT] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_MIXA_LOB_BIAS] = { .ghz5 = 0x0044, .ghz2 = 0x0044, UPLOAD, }, [B2056_RX_MIXA_CORE_IDAC] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_MIXA_CMFB_IDAC] = { .ghz5 = 0x0044, .ghz2 = 0x0044, NOUPLOAD, }, [B2056_RX_MIXA_BIAS_AUX] = { .ghz5 = 0x000f, .ghz2 = 0x000f, UPLOAD, }, [B2056_RX_MIXA_BIAS_MAIN] = { .ghz5 = 0x0006, .ghz2 = 0x0006, NOUPLOAD, }, [B2056_RX_MIXA_BIAS_MISC] = { .ghz5 = 0x0004, .ghz2 = 0x0004, NOUPLOAD, }, [B2056_RX_MIXA_MAST_BIAS] = { .ghz5 = 0x0050, .ghz2 = 0x0050, UPLOAD, }, [B2056_RX_MIXG_MASTER] = { .ghz5 = 0x0008, .ghz2 = 0x0008, NOUPLOAD, }, [B2056_RX_MIXG_VCM] = { .ghz5 = 0x0099, .ghz2 = 0x0099, NOUPLOAD, }, [B2056_RX_MIXG_CTRLPTAT] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_MIXG_LOB_BIAS] = { .ghz5 = 0x0011, .ghz2 = 0x0011, NOUPLOAD, }, [B2056_RX_MIXG_CORE_IDAC] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_MIXG_CMFB_IDAC] = { .ghz5 = 0x0044, .ghz2 = 0x0044, NOUPLOAD, }, [B2056_RX_MIXG_BIAS_AUX] = { .ghz5 = 0x0007, .ghz2 = 0x0007, NOUPLOAD, }, [B2056_RX_MIXG_BIAS_MAIN] = { .ghz5 = 0x0006, .ghz2 = 0x0006, NOUPLOAD, }, [B2056_RX_MIXG_BIAS_MISC] = { .ghz5 = 0x0004, .ghz2 = 0x0004, NOUPLOAD, }, [B2056_RX_MIXG_MAST_BIAS] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_TIA_MASTER] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_TIA_IOPAMP] = { .ghz5 = 0x0066, .ghz2 = 0x0066, NOUPLOAD, }, [B2056_RX_TIA_QOPAMP] = { .ghz5 = 0x0066, .ghz2 = 0x0066, NOUPLOAD, }, [B2056_RX_TIA_IMISC] = { .ghz5 = 0x0057, .ghz2 = 0x0057, NOUPLOAD, }, [B2056_RX_TIA_QMISC] = { .ghz5 = 0x0057, .ghz2 = 0x0057, NOUPLOAD, }, [B2056_RX_TIA_GAIN] = { .ghz5 = 0x0044, .ghz2 = 0x0044, NOUPLOAD, }, [B2056_RX_TIA_SPARE1] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_TIA_SPARE2] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_BB_LPF_MASTER] = { .ghz5 = 0x0008, .ghz2 = 0x0008, NOUPLOAD, }, [B2056_RX_AACI_MASTER] = { .ghz5 = 0x0008, .ghz2 = 0x0008, NOUPLOAD, }, [B2056_RX_RXLPF_IDAC] = { .ghz5 = 0x0007, .ghz2 = 0x0007, NOUPLOAD, }, [B2056_RX_RXLPF_OPAMPBIAS_LOWQ] = { .ghz5 = 0x0022, .ghz2 = 0x0022, NOUPLOAD, }, [B2056_RX_RXLPF_OPAMPBIAS_HIGHQ]= { .ghz5 = 0x0022, .ghz2 = 0x0022, NOUPLOAD, }, [B2056_RX_RXLPF_BIAS_DCCANCEL] = { .ghz5 = 0x0002, .ghz2 = 0x0002, NOUPLOAD, }, [B2056_RX_RXLPF_OUTVCM] = { .ghz5 = 0x0023, .ghz2 = 0x0023, NOUPLOAD, }, [B2056_RX_RXLPF_INVCM_BODY] = { .ghz5 = 0x0007, .ghz2 = 0x0007, NOUPLOAD, }, [B2056_RX_RXLPF_CC_OP] = { .ghz5 = 0x0055, .ghz2 = 0x0055, NOUPLOAD, }, [B2056_RX_RXLPF_GAIN] = { .ghz5 = 0x0023, .ghz2 = 0x0023, NOUPLOAD, }, [B2056_RX_RXLPF_Q_BW] = { .ghz5 = 0x0041, .ghz2 = 0x0041, NOUPLOAD, }, [B2056_RX_RXLPF_HP_CORNER_BW] = { .ghz5 = 0x0001, .ghz2 = 0x0001, NOUPLOAD, }, [B2056_RX_RXLPF_RCCAL_HPC] = { .ghz5 = 0x000a, .ghz2 = 0x000a, NOUPLOAD, }, [B2056_RX_RXHPF_OFF0] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RXHPF_OFF1] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RXHPF_OFF2] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RXHPF_OFF3] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RXHPF_OFF4] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RXHPF_OFF5] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RXHPF_OFF6] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RXHPF_OFF7] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RXLPF_RCCAL_LPC] = { .ghz5 = 0x000c, .ghz2 = 0x000c, NOUPLOAD, }, [B2056_RX_RXLPF_OFF_0] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RXLPF_OFF_1] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RXLPF_OFF_2] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RXLPF_OFF_3] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RXLPF_OFF_4] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_UNUSED] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_VGA_MASTER] = { .ghz5 = 0x0022, .ghz2 = 0x0022, NOUPLOAD, }, [B2056_RX_VGA_BIAS] = { .ghz5 = 0x0022, .ghz2 = 0x0022, NOUPLOAD, }, [B2056_RX_VGA_BIAS_DCCANCEL] = { .ghz5 = 0x0002, .ghz2 = 0x0002, NOUPLOAD, }, [B2056_RX_VGA_GAIN] = { .ghz5 = 0x000a, .ghz2 = 0x000a, NOUPLOAD, }, [B2056_RX_VGA_HP_CORNER_BW] = { .ghz5 = 0x0001, .ghz2 = 0x0001, NOUPLOAD, }, [B2056_RX_VGABUF_BIAS] = { .ghz5 = 0x0022, .ghz2 = 0x0022, NOUPLOAD, }, [B2056_RX_VGABUF_GAIN_BW] = { .ghz5 = 0x0030, .ghz2 = 0x0030, NOUPLOAD, }, [B2056_RX_TXFBMIX_A] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_TXFBMIX_G] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RXSPARE1] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RXSPARE2] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RXSPARE3] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RXSPARE4] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RXSPARE5] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RXSPARE6] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RXSPARE7] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RXSPARE8] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RXSPARE9] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RXSPARE10] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RXSPARE11] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RXSPARE12] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RXSPARE13] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RXSPARE14] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RXSPARE15] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RXSPARE16] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_STATUS_LNAA_GAIN] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_STATUS_LNAG_GAIN] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_STATUS_MIXTIA_GAIN] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_STATUS_RXLPF_GAIN] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_STATUS_VGA_BUF_GAIN] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_STATUS_RXLPF_Q] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_STATUS_RXLPF_BUF_BW] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_STATUS_RXLPF_VGA_HPC] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_STATUS_RXLPF_RC] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_STATUS_HPC_RC] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, }; static const struct b2056_inittab_entry b2056_inittab_phy_rev4_syn[] = { [B2056_SYN_RESERVED_ADDR2] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_RESERVED_ADDR3] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_RESERVED_ADDR4] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_RESERVED_ADDR5] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_RESERVED_ADDR6] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_RESERVED_ADDR7] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_COM_CTRL] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_COM_PU] = { .ghz5 = 0x0001, .ghz2 = 0x0001, NOUPLOAD, }, [B2056_SYN_COM_OVR] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_COM_RESET] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_COM_RCAL] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_COM_RC_RXLPF] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_COM_RC_TXLPF] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_COM_RC_RXHPF] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_RESERVED_ADDR16] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_RESERVED_ADDR17] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_RESERVED_ADDR18] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_RESERVED_ADDR19] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_RESERVED_ADDR20] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_RESERVED_ADDR21] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_RESERVED_ADDR22] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_RESERVED_ADDR23] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_RESERVED_ADDR24] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_RESERVED_ADDR25] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_RESERVED_ADDR26] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_RESERVED_ADDR27] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_RESERVED_ADDR28] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_RESERVED_ADDR29] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_RESERVED_ADDR30] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_RESERVED_ADDR31] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_GPIO_MASTER1] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_GPIO_MASTER2] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_TOPBIAS_MASTER] = { .ghz5 = 0x0060, .ghz2 = 0x0060, NOUPLOAD, }, [B2056_SYN_TOPBIAS_RCAL] = { .ghz5 = 0x0006, .ghz2 = 0x0006, NOUPLOAD, }, [B2056_SYN_AFEREG] = { .ghz5 = 0x000c, .ghz2 = 0x000c, NOUPLOAD, }, [B2056_SYN_TEMPPROCSENSE] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_TEMPPROCSENSEIDAC] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_TEMPPROCSENSERCAL] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LPO] = { .ghz5 = 0x0001, .ghz2 = 0x0001, NOUPLOAD, }, [B2056_SYN_VDDCAL_MASTER] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_VDDCAL_IDAC] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_VDDCAL_STATUS] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_RCAL_MASTER] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_RCAL_CODE_OUT] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_RCCAL_CTRL0] = { .ghz5 = 0x000d, .ghz2 = 0x000d, NOUPLOAD, }, [B2056_SYN_RCCAL_CTRL1] = { .ghz5 = 0x001f, .ghz2 = 0x001f, NOUPLOAD, }, [B2056_SYN_RCCAL_CTRL2] = { .ghz5 = 0x0015, .ghz2 = 0x0015, NOUPLOAD, }, [B2056_SYN_RCCAL_CTRL3] = { .ghz5 = 0x000f, .ghz2 = 0x000f, NOUPLOAD, }, [B2056_SYN_RCCAL_CTRL4] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_RCCAL_CTRL5] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_RCCAL_CTRL6] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_RCCAL_CTRL7] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_RCCAL_CTRL8] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_RCCAL_CTRL9] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_RCCAL_CTRL10] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_RCCAL_CTRL11] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_ZCAL_SPARE1] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_ZCAL_SPARE2] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_PLL_MAST1] = { .ghz5 = 0x0013, .ghz2 = 0x0013, NOUPLOAD, }, [B2056_SYN_PLL_MAST2] = { .ghz5 = 0x000f, .ghz2 = 0x000f, NOUPLOAD, }, [B2056_SYN_PLL_MAST3] = { .ghz5 = 0x0018, .ghz2 = 0x0018, NOUPLOAD, }, [B2056_SYN_PLL_BIAS_RESET] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_PLL_XTAL0] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_PLL_XTAL1] = { .ghz5 = 0x0020, .ghz2 = 0x0020, NOUPLOAD, }, [B2056_SYN_PLL_XTAL3] = { .ghz5 = 0x0020, .ghz2 = 0x0020, NOUPLOAD, }, [B2056_SYN_PLL_XTAL4] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_PLL_XTAL5] = { .ghz5 = 0x0077, .ghz2 = 0x0077, NOUPLOAD, }, [B2056_SYN_PLL_XTAL6] = { .ghz5 = 0x0007, .ghz2 = 0x0007, NOUPLOAD, }, [B2056_SYN_PLL_REFDIV] = { .ghz5 = 0x0001, .ghz2 = 0x0001, NOUPLOAD, }, [B2056_SYN_PLL_PFD] = { .ghz5 = 0x0004, .ghz2 = 0x0004, NOUPLOAD, }, [B2056_SYN_PLL_CP1] = { .ghz5 = 0x000f, .ghz2 = 0x000f, NOUPLOAD, }, [B2056_SYN_PLL_CP2] = { .ghz5 = 0x0030, .ghz2 = 0x0030, NOUPLOAD, }, [B2056_SYN_PLL_CP3] = { .ghz5 = 0x0032, .ghz2 = 0x0032, NOUPLOAD, }, [B2056_SYN_PLL_LOOPFILTER1] = { .ghz5 = 0x000d, .ghz2 = 0x000d, NOUPLOAD, }, [B2056_SYN_PLL_LOOPFILTER2] = { .ghz5 = 0x000d, .ghz2 = 0x000d, NOUPLOAD, }, [B2056_SYN_PLL_LOOPFILTER3] = { .ghz5 = 0x0004, .ghz2 = 0x0004, NOUPLOAD, }, [B2056_SYN_PLL_LOOPFILTER4] = { .ghz5 = 0x0006, .ghz2 = 0x0006, NOUPLOAD, }, [B2056_SYN_PLL_LOOPFILTER5] = { .ghz5 = 0x0001, .ghz2 = 0x0001, NOUPLOAD, }, [B2056_SYN_PLL_MMD1] = { .ghz5 = 0x001c, .ghz2 = 0x001c, NOUPLOAD, }, [B2056_SYN_PLL_MMD2] = { .ghz5 = 0x0002, .ghz2 = 0x0002, NOUPLOAD, }, [B2056_SYN_PLL_VCO1] = { .ghz5 = 0x0002, .ghz2 = 0x0002, NOUPLOAD, }, [B2056_SYN_PLL_VCO2] = { .ghz5 = 0x00f7, .ghz2 = 0x00f7, UPLOAD, }, [B2056_SYN_PLL_MONITOR1] = { .ghz5 = 0x00b4, .ghz2 = 0x00b4, NOUPLOAD, }, [B2056_SYN_PLL_MONITOR2] = { .ghz5 = 0x00d2, .ghz2 = 0x00d2, NOUPLOAD, }, [B2056_SYN_PLL_VCOCAL1] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_PLL_VCOCAL2] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_PLL_VCOCAL4] = { .ghz5 = 0x0004, .ghz2 = 0x0004, NOUPLOAD, }, [B2056_SYN_PLL_VCOCAL5] = { .ghz5 = 0x0096, .ghz2 = 0x0096, NOUPLOAD, }, [B2056_SYN_PLL_VCOCAL6] = { .ghz5 = 0x003e, .ghz2 = 0x003e, NOUPLOAD, }, [B2056_SYN_PLL_VCOCAL7] = { .ghz5 = 0x003e, .ghz2 = 0x003e, NOUPLOAD, }, [B2056_SYN_PLL_VCOCAL8] = { .ghz5 = 0x0013, .ghz2 = 0x0013, NOUPLOAD, }, [B2056_SYN_PLL_VCOCAL9] = { .ghz5 = 0x0002, .ghz2 = 0x0002, NOUPLOAD, }, [B2056_SYN_PLL_VCOCAL10] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_PLL_VCOCAL11] = { .ghz5 = 0x0007, .ghz2 = 0x0007, NOUPLOAD, }, [B2056_SYN_PLL_VCOCAL12] = { .ghz5 = 0x0007, .ghz2 = 0x0007, UPLOAD, }, [B2056_SYN_PLL_VCOCAL13] = { .ghz5 = 0x0008, .ghz2 = 0x0008, NOUPLOAD, }, [B2056_SYN_PLL_VREG] = { .ghz5 = 0x0003, .ghz2 = 0x0003, NOUPLOAD, }, [B2056_SYN_PLL_STATUS1] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_PLL_STATUS2] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_PLL_STATUS3] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_PU0] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_PU1] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_PU2] = { .ghz5 = 0x0040, .ghz2 = 0x0040, NOUPLOAD, }, [B2056_SYN_LOGEN_PU3] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_PU5] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_PU6] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_PU7] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_PU8] = { .ghz5 = 0x0001, .ghz2 = 0x0001, NOUPLOAD, }, [B2056_SYN_LOGEN_BIAS_RESET] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_RCCR1] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_VCOBUF1] = { .ghz5 = 0x0060, .ghz2 = 0x0060, NOUPLOAD, }, [B2056_SYN_LOGEN_MIXER1] = { .ghz5 = 0x0066, .ghz2 = 0x0066, NOUPLOAD, }, [B2056_SYN_LOGEN_MIXER2] = { .ghz5 = 0x000c, .ghz2 = 0x000c, NOUPLOAD, }, [B2056_SYN_LOGEN_BUF1] = { .ghz5 = 0x0066, .ghz2 = 0x0066, NOUPLOAD, }, [B2056_SYN_LOGENBUF2] = { .ghz5 = 0x008f, .ghz2 = 0x008f, UPLOAD, }, [B2056_SYN_LOGEN_BUF3] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_BUF4] = { .ghz5 = 0x00cc, .ghz2 = 0x00cc, NOUPLOAD, }, [B2056_SYN_LOGEN_DIV1] = { .ghz5 = 0x0001, .ghz2 = 0x0001, NOUPLOAD, }, [B2056_SYN_LOGEN_DIV2] = { .ghz5 = 0x0066, .ghz2 = 0x0066, NOUPLOAD, }, [B2056_SYN_LOGEN_DIV3] = { .ghz5 = 0x0066, .ghz2 = 0x0066, NOUPLOAD, }, [B2056_SYN_LOGEN_ACL1] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_ACL2] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_ACL3] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_ACL4] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_ACL5] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_ACL6] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_ACLOUT] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_ACLCAL1] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_ACLCAL2] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_ACLCAL3] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_CALEN] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_PEAKDET1] = { .ghz5 = 0x00ff, .ghz2 = 0x00ff, NOUPLOAD, }, [B2056_SYN_LOGEN_CORE_ACL_OVR] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_RX_DIFF_ACL_OVR] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_TX_DIFF_ACL_OVR] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_RX_CMOS_ACL_OVR] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_TX_CMOS_ACL_OVR] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_VCOBUF2] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_MIXER3] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_BUF5] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_BUF6] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_CBUFRX1] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_CBUFRX2] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_CBUFRX3] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_CBUFRX4] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_CBUFTX1] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_CBUFTX2] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_CBUFTX3] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_CBUFTX4] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_CMOSRX1] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_CMOSRX2] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_CMOSRX3] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_CMOSRX4] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_CMOSTX1] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_CMOSTX2] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_CMOSTX3] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_CMOSTX4] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_VCOBUF2_OVRVAL]= { .ghz5 = 0x0006, .ghz2 = 0x0006, NOUPLOAD, }, [B2056_SYN_LOGEN_MIXER3_OVRVAL] = { .ghz5 = 0x0066, .ghz2 = 0x0066, NOUPLOAD, }, [B2056_SYN_LOGEN_BUF5_OVRVAL] = { .ghz5 = 0x0066, .ghz2 = 0x0066, NOUPLOAD, }, [B2056_SYN_LOGEN_BUF6_OVRVAL] = { .ghz5 = 0x0066, .ghz2 = 0x0066, NOUPLOAD, }, [B2056_SYN_LOGEN_CBUFRX1_OVRVAL]= { .ghz5 = 0x0066, .ghz2 = 0x0066, NOUPLOAD, }, [B2056_SYN_LOGEN_CBUFRX2_OVRVAL]= { .ghz5 = 0x0066, .ghz2 = 0x0066, NOUPLOAD, }, [B2056_SYN_LOGEN_CBUFRX3_OVRVAL]= { .ghz5 = 0x0066, .ghz2 = 0x0066, NOUPLOAD, }, [B2056_SYN_LOGEN_CBUFRX4_OVRVAL]= { .ghz5 = 0x0066, .ghz2 = 0x0066, NOUPLOAD, }, [B2056_SYN_LOGEN_CBUFTX1_OVRVAL]= { .ghz5 = 0x0066, .ghz2 = 0x0066, NOUPLOAD, }, [B2056_SYN_LOGEN_CBUFTX2_OVRVAL]= { .ghz5 = 0x0066, .ghz2 = 0x0066, NOUPLOAD, }, [B2056_SYN_LOGEN_CBUFTX3_OVRVAL]= { .ghz5 = 0x0066, .ghz2 = 0x0066, NOUPLOAD, }, [B2056_SYN_LOGEN_CBUFTX4_OVRVAL]= { .ghz5 = 0x0066, .ghz2 = 0x0066, NOUPLOAD, }, [B2056_SYN_LOGEN_CMOSRX1_OVRVAL]= { .ghz5 = 0x0066, .ghz2 = 0x0066, NOUPLOAD, }, [B2056_SYN_LOGEN_CMOSRX2_OVRVAL]= { .ghz5 = 0x0066, .ghz2 = 0x0066, NOUPLOAD, }, [B2056_SYN_LOGEN_CMOSRX3_OVRVAL]= { .ghz5 = 0x0066, .ghz2 = 0x0066, NOUPLOAD, }, [B2056_SYN_LOGEN_CMOSRX4_OVRVAL]= { .ghz5 = 0x0066, .ghz2 = 0x0066, NOUPLOAD, }, [B2056_SYN_LOGEN_CMOSTX1_OVRVAL]= { .ghz5 = 0x0066, .ghz2 = 0x0066, NOUPLOAD, }, [B2056_SYN_LOGEN_CMOSTX2_OVRVAL]= { .ghz5 = 0x0066, .ghz2 = 0x0066, NOUPLOAD, }, [B2056_SYN_LOGEN_CMOSTX3_OVRVAL]= { .ghz5 = 0x0066, .ghz2 = 0x0066, NOUPLOAD, }, [B2056_SYN_LOGEN_CMOSTX4_OVRVAL]= { .ghz5 = 0x0066, .ghz2 = 0x0066, NOUPLOAD, }, [B2056_SYN_LOGEN_ACL_WAITCNT] = { .ghz5 = 0x000a, .ghz2 = 0x000a, NOUPLOAD, }, [B2056_SYN_LOGEN_CORE_CALVALID] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_RX_CMOS_CALVALID] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_TX_CMOS_VALID] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, }; static const struct b2056_inittab_entry b2056_inittab_phy_rev4_tx[] = { [B2056_TX_RESERVED_ADDR2] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_RESERVED_ADDR3] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_RESERVED_ADDR4] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_RESERVED_ADDR5] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_RESERVED_ADDR6] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_RESERVED_ADDR7] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_COM_CTRL] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_COM_PU] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_COM_OVR] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_COM_RESET] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_COM_RCAL] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_COM_RC_RXLPF] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_COM_RC_TXLPF] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_COM_RC_RXHPF] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_RESERVED_ADDR16] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_RESERVED_ADDR17] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_RESERVED_ADDR18] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_RESERVED_ADDR19] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_RESERVED_ADDR20] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_RESERVED_ADDR21] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_RESERVED_ADDR22] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_RESERVED_ADDR23] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_RESERVED_ADDR24] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_RESERVED_ADDR25] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_RESERVED_ADDR26] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_RESERVED_ADDR27] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_RESERVED_ADDR28] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_RESERVED_ADDR29] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_RESERVED_ADDR30] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_RESERVED_ADDR31] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_IQCAL_GAIN_BW] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_LOFT_FINE_I] = { .ghz5 = 0x0088, .ghz2 = 0x0088, NOUPLOAD, }, [B2056_TX_LOFT_FINE_Q] = { .ghz5 = 0x0088, .ghz2 = 0x0088, NOUPLOAD, }, [B2056_TX_LOFT_COARSE_I] = { .ghz5 = 0x0088, .ghz2 = 0x0088, NOUPLOAD, }, [B2056_TX_LOFT_COARSE_Q] = { .ghz5 = 0x0088, .ghz2 = 0x0088, NOUPLOAD, }, [B2056_TX_TX_COM_MASTER1] = { .ghz5 = 0x000c, .ghz2 = 0x000c, NOUPLOAD, }, [B2056_TX_TX_COM_MASTER2] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_RXIQCAL_TXMUX] = { .ghz5 = 0x0003, .ghz2 = 0x0003, NOUPLOAD, }, [B2056_TX_TX_SSI_MASTER] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_IQCAL_VCM_HG] = { .ghz5 = 0x0003, .ghz2 = 0x0003, NOUPLOAD, }, [B2056_TX_IQCAL_IDAC] = { .ghz5 = 0x0037, .ghz2 = 0x0037, NOUPLOAD, }, [B2056_TX_TSSI_VCM] = { .ghz5 = 0x0003, .ghz2 = 0x0003, NOUPLOAD, }, [B2056_TX_TX_AMP_DET] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_TX_SSI_MUX] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_TSSIA] = { .ghz5 = 0x0001, .ghz2 = 0x0001, NOUPLOAD, }, [B2056_TX_TSSIG] = { .ghz5 = 0x0001, .ghz2 = 0x0001, NOUPLOAD, }, [B2056_TX_TSSI_MISC1] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_TSSI_MISC2] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_TSSI_MISC3] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_PA_SPARE1] = { .ghz5 = 0x0011, .ghz2 = 0x0011, NOUPLOAD, }, [B2056_TX_PA_SPARE2] = { .ghz5 = 0x0011, .ghz2 = 0x0011, NOUPLOAD, }, [B2056_TX_INTPAA_MASTER] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_INTPAA_GAIN] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_INTPAA_BOOST_TUNE] = { .ghz5 = 0x0003, .ghz2 = 0x0003, NOUPLOAD, }, [B2056_TX_INTPAA_IAUX_STAT] = { .ghz5 = 0x000f, .ghz2 = 0x000f, NOUPLOAD, }, [B2056_TX_INTPAA_IAUX_DYN] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_INTPAA_IMAIN_STAT] = { .ghz5 = 0x002d, .ghz2 = 0x002d, NOUPLOAD, }, [B2056_TX_INTPAA_IMAIN_DYN] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_INTPAA_CASCBIAS] = { .ghz5 = 0x006e, .ghz2 = 0x006e, NOUPLOAD, }, [B2056_TX_INTPAA_PASLOPE] = { .ghz5 = 0x00f0, .ghz2 = 0x00f0, UPLOAD, }, [B2056_TX_INTPAA_PA_MISC] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_INTPAG_MASTER] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_INTPAG_GAIN] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_INTPAG_BOOST_TUNE] = { .ghz5 = 0x0003, .ghz2 = 0x0003, NOUPLOAD, }, [B2056_TX_INTPAG_IAUX_STAT] = { .ghz5 = 0x0003, .ghz2 = 0x0003, NOUPLOAD, }, [B2056_TX_INTPAG_IAUX_DYN] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_INTPAG_IMAIN_STAT] = { .ghz5 = 0x001e, .ghz2 = 0x001e, NOUPLOAD, }, [B2056_TX_INTPAG_IMAIN_DYN] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_INTPAG_CASCBIAS] = { .ghz5 = 0x006e, .ghz2 = 0x006e, NOUPLOAD, }, [B2056_TX_INTPAG_PASLOPE] = { .ghz5 = 0x00f0, .ghz2 = 0x00f0, UPLOAD, }, [B2056_TX_INTPAG_PA_MISC] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_PADA_MASTER] = { .ghz5 = 0x0002, .ghz2 = 0x0002, NOUPLOAD, }, [B2056_TX_PADA_IDAC] = { .ghz5 = 0x00ff, .ghz2 = 0x00ff, UPLOAD, }, [B2056_TX_PADA_CASCBIAS] = { .ghz5 = 0x000c, .ghz2 = 0x000c, NOUPLOAD, }, [B2056_TX_PADA_GAIN] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_PADA_BOOST_TUNE] = { .ghz5 = 0x0038, .ghz2 = 0x0038, NOUPLOAD, }, [B2056_TX_PADA_SLOPE] = { .ghz5 = 0x0070, .ghz2 = 0x0070, UPLOAD, }, [B2056_TX_PADG_MASTER] = { .ghz5 = 0x0002, .ghz2 = 0x0002, NOUPLOAD, }, [B2056_TX_PADG_IDAC] = { .ghz5 = 0x0088, .ghz2 = 0x0088, NOUPLOAD, }, [B2056_TX_PADG_CASCBIAS] = { .ghz5 = 0x000c, .ghz2 = 0x000c, NOUPLOAD, }, [B2056_TX_PADG_GAIN] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_PADG_BOOST_TUNE] = { .ghz5 = 0x0008, .ghz2 = 0x0008, NOUPLOAD, }, [B2056_TX_PADG_SLOPE] = { .ghz5 = 0x0070, .ghz2 = 0x0070, UPLOAD, }, [B2056_TX_PGAA_MASTER] = { .ghz5 = 0x0002, .ghz2 = 0x0002, NOUPLOAD, }, [B2056_TX_PGAA_IDAC] = { .ghz5 = 0x00ff, .ghz2 = 0x00ff, UPLOAD, }, [B2056_TX_PGAA_GAIN] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_PGAA_BOOST_TUNE] = { .ghz5 = 0x0083, .ghz2 = 0x0083, NOUPLOAD, }, [B2056_TX_PGAA_SLOPE] = { .ghz5 = 0x0077, .ghz2 = 0x0077, UPLOAD, }, [B2056_TX_PGAA_MISC] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_PGAG_MASTER] = { .ghz5 = 0x0002, .ghz2 = 0x0002, NOUPLOAD, }, [B2056_TX_PGAG_IDAC] = { .ghz5 = 0x0088, .ghz2 = 0x0088, NOUPLOAD, }, [B2056_TX_PGAG_GAIN] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_PGAG_BOOST_TUNE] = { .ghz5 = 0x0008, .ghz2 = 0x0008, NOUPLOAD, }, [B2056_TX_PGAG_SLOPE] = { .ghz5 = 0x0077, .ghz2 = 0x0077, UPLOAD, }, [B2056_TX_PGAG_MISC] = { .ghz5 = 0x0001, .ghz2 = 0x0001, NOUPLOAD, }, [B2056_TX_MIXA_MASTER] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_MIXA_BOOST_TUNE] = { .ghz5 = 0x0007, .ghz2 = 0x0007, NOUPLOAD, }, [B2056_TX_MIXG] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_MIXG_BOOST_TUNE] = { .ghz5 = 0x0007, .ghz2 = 0x0007, NOUPLOAD, }, [B2056_TX_BB_GM_MASTER] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_GMBB_GM] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_GMBB_IDAC] = { .ghz5 = 0x0072, .ghz2 = 0x0072, UPLOAD, }, [B2056_TX_TXLPF_MASTER] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_TXLPF_RCCAL] = { .ghz5 = 0x000a, .ghz2 = 0x000a, NOUPLOAD, }, [B2056_TX_TXLPF_RCCAL_OFF0] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_TXLPF_RCCAL_OFF1] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_TXLPF_RCCAL_OFF2] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_TXLPF_RCCAL_OFF3] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_TXLPF_RCCAL_OFF4] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_TXLPF_RCCAL_OFF5] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_TXLPF_RCCAL_OFF6] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_TXLPF_BW] = { .ghz5 = 0x0002, .ghz2 = 0x0002, NOUPLOAD, }, [B2056_TX_TXLPF_GAIN] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_TXLPF_IDAC] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_TXLPF_IDAC_0] = { .ghz5 = 0x000e, .ghz2 = 0x000e, NOUPLOAD, }, [B2056_TX_TXLPF_IDAC_1] = { .ghz5 = 0x000e, .ghz2 = 0x000e, NOUPLOAD, }, [B2056_TX_TXLPF_IDAC_2] = { .ghz5 = 0x000e, .ghz2 = 0x000e, NOUPLOAD, }, [B2056_TX_TXLPF_IDAC_3] = { .ghz5 = 0x0013, .ghz2 = 0x0013, NOUPLOAD, }, [B2056_TX_TXLPF_IDAC_4] = { .ghz5 = 0x0013, .ghz2 = 0x0013, NOUPLOAD, }, [B2056_TX_TXLPF_IDAC_5] = { .ghz5 = 0x001b, .ghz2 = 0x001b, NOUPLOAD, }, [B2056_TX_TXLPF_IDAC_6] = { .ghz5 = 0x001b, .ghz2 = 0x001b, NOUPLOAD, }, [B2056_TX_TXLPF_OPAMP_IDAC] = { .ghz5 = 0x0055, .ghz2 = 0x0055, NOUPLOAD, }, [B2056_TX_TXLPF_MISC] = { .ghz5 = 0x005b, .ghz2 = 0x005b, NOUPLOAD, }, [B2056_TX_TXSPARE1] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_TXSPARE2] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_TXSPARE3] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_TXSPARE4] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_TXSPARE5] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_TXSPARE6] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_TXSPARE7] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_TXSPARE8] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_TXSPARE9] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_TXSPARE10] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_TXSPARE11] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_TXSPARE12] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_TXSPARE13] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_TXSPARE14] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_TXSPARE15] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_TXSPARE16] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_STATUS_INTPA_GAIN] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_STATUS_PAD_GAIN] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_STATUS_PGA_GAIN] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_STATUS_GM_TXLPF_GAIN] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_STATUS_TXLPF_BW] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_STATUS_TXLPF_RC] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, }; static const struct b2056_inittab_entry b2056_inittab_phy_rev4_rx[] = { [B2056_RX_RESERVED_ADDR2] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RESERVED_ADDR3] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RESERVED_ADDR4] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RESERVED_ADDR5] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RESERVED_ADDR6] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RESERVED_ADDR7] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_COM_CTRL] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_COM_PU] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_COM_OVR] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_COM_RESET] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_COM_RCAL] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_COM_RC_RXLPF] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_COM_RC_TXLPF] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_COM_RC_RXHPF] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RESERVED_ADDR16] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RESERVED_ADDR17] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RESERVED_ADDR18] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RESERVED_ADDR19] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RESERVED_ADDR20] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RESERVED_ADDR21] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RESERVED_ADDR22] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RESERVED_ADDR23] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RESERVED_ADDR24] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RESERVED_ADDR25] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RESERVED_ADDR26] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RESERVED_ADDR27] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RESERVED_ADDR28] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RESERVED_ADDR29] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RESERVED_ADDR30] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RESERVED_ADDR31] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RXIQCAL_RXMUX] = { .ghz5 = 0x0003, .ghz2 = 0x0003, NOUPLOAD, }, [B2056_RX_RSSI_PU] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RSSI_SEL] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RSSI_GAIN] = { .ghz5 = 0x0090, .ghz2 = 0x0090, NOUPLOAD, }, [B2056_RX_RSSI_NB_IDAC] = { .ghz5 = 0x0055, .ghz2 = 0x0055, NOUPLOAD, }, [B2056_RX_RSSI_WB2I_IDAC_1] = { .ghz5 = 0x0015, .ghz2 = 0x0015, NOUPLOAD, }, [B2056_RX_RSSI_WB2I_IDAC_2] = { .ghz5 = 0x0005, .ghz2 = 0x0005, NOUPLOAD, }, [B2056_RX_RSSI_WB2Q_IDAC_1] = { .ghz5 = 0x0015, .ghz2 = 0x0015, NOUPLOAD, }, [B2056_RX_RSSI_WB2Q_IDAC_2] = { .ghz5 = 0x0005, .ghz2 = 0x0005, NOUPLOAD, }, [B2056_RX_RSSI_POLE] = { .ghz5 = 0x0020, .ghz2 = 0x0020, NOUPLOAD, }, [B2056_RX_RSSI_WB1_IDAC] = { .ghz5 = 0x0011, .ghz2 = 0x0011, NOUPLOAD, }, [B2056_RX_RSSI_MISC] = { .ghz5 = 0x0090, .ghz2 = 0x0090, NOUPLOAD, }, [B2056_RX_LNAA_MASTER] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_LNAA_TUNE] = { .ghz5 = 0x0088, .ghz2 = 0x0088, NOUPLOAD, }, [B2056_RX_LNAA_GAIN] = { .ghz5 = 0x0032, .ghz2 = 0x0032, NOUPLOAD, }, [B2056_RX_LNA_A_SLOPE] = { .ghz5 = 0x0077, .ghz2 = 0x0077, NOUPLOAD, }, [B2056_RX_BIASPOLE_LNAA1_IDAC] = { .ghz5 = 0x0017, .ghz2 = 0x0017, UPLOAD, }, [B2056_RX_LNAA2_IDAC] = { .ghz5 = 0x00ff, .ghz2 = 0x00ff, UPLOAD, }, [B2056_RX_LNA1A_MISC] = { .ghz5 = 0x0020, .ghz2 = 0x0020, NOUPLOAD, }, [B2056_RX_LNAG_MASTER] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_LNAG_TUNE] = { .ghz5 = 0x0088, .ghz2 = 0x0088, NOUPLOAD, }, [B2056_RX_LNAG_GAIN] = { .ghz5 = 0x0032, .ghz2 = 0x0032, NOUPLOAD, }, [B2056_RX_LNA_G_SLOPE] = { .ghz5 = 0x0077, .ghz2 = 0x0077, NOUPLOAD, }, [B2056_RX_BIASPOLE_LNAG1_IDAC] = { .ghz5 = 0x0017, .ghz2 = 0x0017, UPLOAD, }, [B2056_RX_LNAG2_IDAC] = { .ghz5 = 0x00f0, .ghz2 = 0x00f0, UPLOAD, }, [B2056_RX_LNA1G_MISC] = { .ghz5 = 0x0020, .ghz2 = 0x0020, NOUPLOAD, }, [B2056_RX_MIXA_MASTER] = { .ghz5 = 0x0008, .ghz2 = 0x0008, NOUPLOAD, }, [B2056_RX_MIXA_VCM] = { .ghz5 = 0x0055, .ghz2 = 0x0055, UPLOAD, }, [B2056_RX_MIXA_CTRLPTAT] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_MIXA_LOB_BIAS] = { .ghz5 = 0x0044, .ghz2 = 0x0044, UPLOAD, }, [B2056_RX_MIXA_CORE_IDAC] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_MIXA_CMFB_IDAC] = { .ghz5 = 0x0044, .ghz2 = 0x0044, NOUPLOAD, }, [B2056_RX_MIXA_BIAS_AUX] = { .ghz5 = 0x000f, .ghz2 = 0x000f, UPLOAD, }, [B2056_RX_MIXA_BIAS_MAIN] = { .ghz5 = 0x0006, .ghz2 = 0x0006, NOUPLOAD, }, [B2056_RX_MIXA_BIAS_MISC] = { .ghz5 = 0x0004, .ghz2 = 0x0004, NOUPLOAD, }, [B2056_RX_MIXA_MAST_BIAS] = { .ghz5 = 0x0050, .ghz2 = 0x0050, UPLOAD, }, [B2056_RX_MIXG_MASTER] = { .ghz5 = 0x0008, .ghz2 = 0x0008, NOUPLOAD, }, [B2056_RX_MIXG_VCM] = { .ghz5 = 0x0055, .ghz2 = 0x0055, UPLOAD, }, [B2056_RX_MIXG_CTRLPTAT] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_MIXG_LOB_BIAS] = { .ghz5 = 0x0011, .ghz2 = 0x0011, NOUPLOAD, }, [B2056_RX_MIXG_CORE_IDAC] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_MIXG_CMFB_IDAC] = { .ghz5 = 0x0044, .ghz2 = 0x0044, NOUPLOAD, }, [B2056_RX_MIXG_BIAS_AUX] = { .ghz5 = 0x0007, .ghz2 = 0x0007, NOUPLOAD, }, [B2056_RX_MIXG_BIAS_MAIN] = { .ghz5 = 0x0006, .ghz2 = 0x0006, NOUPLOAD, }, [B2056_RX_MIXG_BIAS_MISC] = { .ghz5 = 0x0004, .ghz2 = 0x0004, NOUPLOAD, }, [B2056_RX_MIXG_MAST_BIAS] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_TIA_MASTER] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_TIA_IOPAMP] = { .ghz5 = 0x0026, .ghz2 = 0x0026, UPLOAD, }, [B2056_RX_TIA_QOPAMP] = { .ghz5 = 0x0026, .ghz2 = 0x0026, UPLOAD, }, [B2056_RX_TIA_IMISC] = { .ghz5 = 0x000f, .ghz2 = 0x000f, UPLOAD, }, [B2056_RX_TIA_QMISC] = { .ghz5 = 0x000f, .ghz2 = 0x000f, UPLOAD, }, [B2056_RX_TIA_GAIN] = { .ghz5 = 0x0044, .ghz2 = 0x0044, NOUPLOAD, }, [B2056_RX_TIA_SPARE1] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_TIA_SPARE2] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_BB_LPF_MASTER] = { .ghz5 = 0x0008, .ghz2 = 0x0008, NOUPLOAD, }, [B2056_RX_AACI_MASTER] = { .ghz5 = 0x0008, .ghz2 = 0x0008, NOUPLOAD, }, [B2056_RX_RXLPF_IDAC] = { .ghz5 = 0x0007, .ghz2 = 0x0007, NOUPLOAD, }, [B2056_RX_RXLPF_OPAMPBIAS_LOWQ] = { .ghz5 = 0x0022, .ghz2 = 0x0022, NOUPLOAD, }, [B2056_RX_RXLPF_OPAMPBIAS_HIGHQ]= { .ghz5 = 0x0022, .ghz2 = 0x0022, NOUPLOAD, }, [B2056_RX_RXLPF_BIAS_DCCANCEL] = { .ghz5 = 0x0002, .ghz2 = 0x0002, NOUPLOAD, }, [B2056_RX_RXLPF_OUTVCM] = { .ghz5 = 0x002f, .ghz2 = 0x002f, UPLOAD, }, [B2056_RX_RXLPF_INVCM_BODY] = { .ghz5 = 0x0007, .ghz2 = 0x0007, NOUPLOAD, }, [B2056_RX_RXLPF_CC_OP] = { .ghz5 = 0x0055, .ghz2 = 0x0055, NOUPLOAD, }, [B2056_RX_RXLPF_GAIN] = { .ghz5 = 0x0023, .ghz2 = 0x0023, NOUPLOAD, }, [B2056_RX_RXLPF_Q_BW] = { .ghz5 = 0x0041, .ghz2 = 0x0041, NOUPLOAD, }, [B2056_RX_RXLPF_HP_CORNER_BW] = { .ghz5 = 0x0001, .ghz2 = 0x0001, NOUPLOAD, }, [B2056_RX_RXLPF_RCCAL_HPC] = { .ghz5 = 0x000a, .ghz2 = 0x000a, NOUPLOAD, }, [B2056_RX_RXHPF_OFF0] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RXHPF_OFF1] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RXHPF_OFF2] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RXHPF_OFF3] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RXHPF_OFF4] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RXHPF_OFF5] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RXHPF_OFF6] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RXHPF_OFF7] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RXLPF_RCCAL_LPC] = { .ghz5 = 0x000c, .ghz2 = 0x000c, NOUPLOAD, }, [B2056_RX_RXLPF_OFF_0] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RXLPF_OFF_1] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RXLPF_OFF_2] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RXLPF_OFF_3] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RXLPF_OFF_4] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_UNUSED] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_VGA_MASTER] = { .ghz5 = 0x0022, .ghz2 = 0x0022, NOUPLOAD, }, [B2056_RX_VGA_BIAS] = { .ghz5 = 0x0022, .ghz2 = 0x0022, NOUPLOAD, }, [B2056_RX_VGA_BIAS_DCCANCEL] = { .ghz5 = 0x0000, .ghz2 = 0x0000, UPLOAD, }, [B2056_RX_VGA_GAIN] = { .ghz5 = 0x000a, .ghz2 = 0x000a, NOUPLOAD, }, [B2056_RX_VGA_HP_CORNER_BW] = { .ghz5 = 0x0001, .ghz2 = 0x0001, NOUPLOAD, }, [B2056_RX_VGABUF_BIAS] = { .ghz5 = 0x0022, .ghz2 = 0x0022, NOUPLOAD, }, [B2056_RX_VGABUF_GAIN_BW] = { .ghz5 = 0x0030, .ghz2 = 0x0030, NOUPLOAD, }, [B2056_RX_TXFBMIX_A] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_TXFBMIX_G] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RXSPARE1] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RXSPARE2] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RXSPARE3] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RXSPARE4] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RXSPARE5] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RXSPARE6] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RXSPARE7] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RXSPARE8] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RXSPARE9] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RXSPARE10] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RXSPARE11] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RXSPARE12] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RXSPARE13] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RXSPARE14] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RXSPARE15] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RXSPARE16] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_STATUS_LNAA_GAIN] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_STATUS_LNAG_GAIN] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_STATUS_MIXTIA_GAIN] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_STATUS_RXLPF_GAIN] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_STATUS_VGA_BUF_GAIN] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_STATUS_RXLPF_Q] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_STATUS_RXLPF_BUF_BW] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_STATUS_RXLPF_VGA_HPC] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_STATUS_RXLPF_RC] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_STATUS_HPC_RC] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, }; static const struct b2056_inittab_entry b2056_inittab_radio_rev5_syn[] = { [B2056_SYN_RESERVED_ADDR2] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_RESERVED_ADDR3] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_RESERVED_ADDR4] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_RESERVED_ADDR5] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_RESERVED_ADDR6] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_RESERVED_ADDR7] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_COM_CTRL] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_COM_PU] = { .ghz5 = 0x0001, .ghz2 = 0x0001, NOUPLOAD, }, [B2056_SYN_COM_OVR] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_COM_RESET] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_COM_RCAL] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_COM_RC_RXLPF] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_COM_RC_TXLPF] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_COM_RC_RXHPF] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_RESERVED_ADDR16] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_RESERVED_ADDR17] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_RESERVED_ADDR18] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_RESERVED_ADDR19] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_RESERVED_ADDR20] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_RESERVED_ADDR21] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_RESERVED_ADDR22] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_RESERVED_ADDR23] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_RESERVED_ADDR24] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_RESERVED_ADDR25] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_RESERVED_ADDR26] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_RESERVED_ADDR27] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_RESERVED_ADDR28] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_RESERVED_ADDR29] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_RESERVED_ADDR30] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_RESERVED_ADDR31] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_GPIO_MASTER1] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_GPIO_MASTER2] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_TOPBIAS_MASTER] = { .ghz5 = 0x0060, .ghz2 = 0x0060, NOUPLOAD, }, [B2056_SYN_TOPBIAS_RCAL] = { .ghz5 = 0x0006, .ghz2 = 0x0006, NOUPLOAD, }, [B2056_SYN_AFEREG] = { .ghz5 = 0x000c, .ghz2 = 0x000c, NOUPLOAD, }, [B2056_SYN_TEMPPROCSENSE] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_TEMPPROCSENSEIDAC] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_TEMPPROCSENSERCAL] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LPO] = { .ghz5 = 0x0001, .ghz2 = 0x0001, NOUPLOAD, }, [B2056_SYN_VDDCAL_MASTER] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_VDDCAL_IDAC] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_VDDCAL_STATUS] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_RCAL_MASTER] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_RCAL_CODE_OUT] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_RCCAL_CTRL0] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_RCCAL_CTRL1] = { .ghz5 = 0x001f, .ghz2 = 0x001f, NOUPLOAD, }, [B2056_SYN_RCCAL_CTRL2] = { .ghz5 = 0x0015, .ghz2 = 0x0015, NOUPLOAD, }, [B2056_SYN_RCCAL_CTRL3] = { .ghz5 = 0x000f, .ghz2 = 0x000f, NOUPLOAD, }, [B2056_SYN_RCCAL_CTRL4] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_RCCAL_CTRL5] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_RCCAL_CTRL6] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_RCCAL_CTRL7] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_RCCAL_CTRL8] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_RCCAL_CTRL9] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_RCCAL_CTRL10] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_RCCAL_CTRL11] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_ZCAL_SPARE1] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_ZCAL_SPARE2] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_PLL_MAST1] = { .ghz5 = 0x0013, .ghz2 = 0x0013, NOUPLOAD, }, [B2056_SYN_PLL_MAST2] = { .ghz5 = 0x000f, .ghz2 = 0x000f, NOUPLOAD, }, [B2056_SYN_PLL_MAST3] = { .ghz5 = 0x0018, .ghz2 = 0x0018, NOUPLOAD, }, [B2056_SYN_PLL_BIAS_RESET] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_PLL_XTAL0] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_PLL_XTAL1] = { .ghz5 = 0x0020, .ghz2 = 0x0020, NOUPLOAD, }, [B2056_SYN_PLL_XTAL3] = { .ghz5 = 0x0020, .ghz2 = 0x0020, NOUPLOAD, }, [B2056_SYN_PLL_XTAL4] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_PLL_XTAL5] = { .ghz5 = 0x0077, .ghz2 = 0x0077, NOUPLOAD, }, [B2056_SYN_PLL_XTAL6] = { .ghz5 = 0x0007, .ghz2 = 0x0007, NOUPLOAD, }, [B2056_SYN_PLL_REFDIV] = { .ghz5 = 0x0001, .ghz2 = 0x0001, NOUPLOAD, }, [B2056_SYN_PLL_PFD] = { .ghz5 = 0x0004, .ghz2 = 0x0004, NOUPLOAD, }, [B2056_SYN_PLL_CP1] = { .ghz5 = 0x000f, .ghz2 = 0x000f, NOUPLOAD, }, [B2056_SYN_PLL_CP2] = { .ghz5 = 0x0030, .ghz2 = 0x0030, NOUPLOAD, }, [B2056_SYN_PLL_CP3] = { .ghz5 = 0x0032, .ghz2 = 0x0032, NOUPLOAD, }, [B2056_SYN_PLL_LOOPFILTER1] = { .ghz5 = 0x000d, .ghz2 = 0x000d, NOUPLOAD, }, [B2056_SYN_PLL_LOOPFILTER2] = { .ghz5 = 0x000d, .ghz2 = 0x000d, NOUPLOAD, }, [B2056_SYN_PLL_LOOPFILTER3] = { .ghz5 = 0x0004, .ghz2 = 0x0004, NOUPLOAD, }, [B2056_SYN_PLL_LOOPFILTER4] = { .ghz5 = 0x0006, .ghz2 = 0x0006, NOUPLOAD, }, [B2056_SYN_PLL_LOOPFILTER5] = { .ghz5 = 0x0001, .ghz2 = 0x0001, NOUPLOAD, }, [B2056_SYN_PLL_MMD1] = { .ghz5 = 0x001c, .ghz2 = 0x001c, NOUPLOAD, }, [B2056_SYN_PLL_MMD2] = { .ghz5 = 0x0002, .ghz2 = 0x0002, NOUPLOAD, }, [B2056_SYN_PLL_VCO1] = { .ghz5 = 0x0002, .ghz2 = 0x0002, NOUPLOAD, }, [B2056_SYN_PLL_VCO2] = { .ghz5 = 0x00f7, .ghz2 = 0x00f7, UPLOAD, }, [B2056_SYN_PLL_MONITOR1] = { .ghz5 = 0x00b4, .ghz2 = 0x00b4, NOUPLOAD, }, [B2056_SYN_PLL_MONITOR2] = { .ghz5 = 0x00d2, .ghz2 = 0x00d2, NOUPLOAD, }, [B2056_SYN_PLL_VCOCAL1] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_PLL_VCOCAL2] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_PLL_VCOCAL4] = { .ghz5 = 0x0004, .ghz2 = 0x0004, NOUPLOAD, }, [B2056_SYN_PLL_VCOCAL5] = { .ghz5 = 0x0096, .ghz2 = 0x0096, NOUPLOAD, }, [B2056_SYN_PLL_VCOCAL6] = { .ghz5 = 0x003e, .ghz2 = 0x003e, NOUPLOAD, }, [B2056_SYN_PLL_VCOCAL7] = { .ghz5 = 0x003e, .ghz2 = 0x003e, NOUPLOAD, }, [B2056_SYN_PLL_VCOCAL8] = { .ghz5 = 0x0013, .ghz2 = 0x0013, NOUPLOAD, }, [B2056_SYN_PLL_VCOCAL9] = { .ghz5 = 0x0002, .ghz2 = 0x0002, NOUPLOAD, }, [B2056_SYN_PLL_VCOCAL10] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_PLL_VCOCAL11] = { .ghz5 = 0x0007, .ghz2 = 0x0007, NOUPLOAD, }, [B2056_SYN_PLL_VCOCAL12] = { .ghz5 = 0x0007, .ghz2 = 0x0007, UPLOAD, }, [B2056_SYN_PLL_VCOCAL13] = { .ghz5 = 0x0008, .ghz2 = 0x0008, NOUPLOAD, }, [B2056_SYN_PLL_VREG] = { .ghz5 = 0x0003, .ghz2 = 0x0003, NOUPLOAD, }, [B2056_SYN_PLL_STATUS1] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_PLL_STATUS2] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_PLL_STATUS3] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_PU0] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_PU1] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_PU2] = { .ghz5 = 0x0040, .ghz2 = 0x0040, NOUPLOAD, }, [B2056_SYN_LOGEN_PU3] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_PU5] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_PU6] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_PU7] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_PU8] = { .ghz5 = 0x0001, .ghz2 = 0x0001, NOUPLOAD, }, [B2056_SYN_LOGEN_BIAS_RESET] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_RCCR1] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_VCOBUF1] = { .ghz5 = 0x0060, .ghz2 = 0x0060, NOUPLOAD, }, [B2056_SYN_LOGEN_MIXER1] = { .ghz5 = 0x0066, .ghz2 = 0x0066, NOUPLOAD, }, [B2056_SYN_LOGEN_MIXER2] = { .ghz5 = 0x000c, .ghz2 = 0x000c, NOUPLOAD, }, [B2056_SYN_LOGEN_BUF1] = { .ghz5 = 0x0066, .ghz2 = 0x0066, NOUPLOAD, }, [B2056_SYN_LOGENBUF2] = { .ghz5 = 0x008f, .ghz2 = 0x008f, UPLOAD, }, [B2056_SYN_LOGEN_BUF3] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_BUF4] = { .ghz5 = 0x00cc, .ghz2 = 0x00cc, NOUPLOAD, }, [B2056_SYN_LOGEN_DIV1] = { .ghz5 = 0x0001, .ghz2 = 0x0001, NOUPLOAD, }, [B2056_SYN_LOGEN_DIV2] = { .ghz5 = 0x0066, .ghz2 = 0x0066, NOUPLOAD, }, [B2056_SYN_LOGEN_DIV3] = { .ghz5 = 0x0066, .ghz2 = 0x0066, NOUPLOAD, }, [B2056_SYN_LOGEN_ACL1] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_ACL2] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_ACL3] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_ACL4] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_ACL5] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_ACL6] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_ACLOUT] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_ACLCAL1] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_ACLCAL2] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_ACLCAL3] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_CALEN] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_PEAKDET1] = { .ghz5 = 0x00ff, .ghz2 = 0x00ff, NOUPLOAD, }, [B2056_SYN_LOGEN_CORE_ACL_OVR] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_RX_DIFF_ACL_OVR] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_TX_DIFF_ACL_OVR] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_RX_CMOS_ACL_OVR] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_TX_CMOS_ACL_OVR] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_VCOBUF2] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_MIXER3] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_BUF5] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_BUF6] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_CBUFRX1] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_CBUFRX2] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_CBUFRX3] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_CBUFRX4] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_CBUFTX1] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_CBUFTX2] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_CBUFTX3] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_CBUFTX4] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_CMOSRX1] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_CMOSRX2] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_CMOSRX3] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_CMOSRX4] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_CMOSTX1] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_CMOSTX2] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_CMOSTX3] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_CMOSTX4] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_VCOBUF2_OVRVAL]= { .ghz5 = 0x0006, .ghz2 = 0x0006, NOUPLOAD, }, [B2056_SYN_LOGEN_MIXER3_OVRVAL] = { .ghz5 = 0x0066, .ghz2 = 0x0066, NOUPLOAD, }, [B2056_SYN_LOGEN_BUF5_OVRVAL] = { .ghz5 = 0x0066, .ghz2 = 0x0066, NOUPLOAD, }, [B2056_SYN_LOGEN_BUF6_OVRVAL] = { .ghz5 = 0x0066, .ghz2 = 0x0066, NOUPLOAD, }, [B2056_SYN_LOGEN_CBUFRX1_OVRVAL]= { .ghz5 = 0x0066, .ghz2 = 0x0066, NOUPLOAD, }, [B2056_SYN_LOGEN_CBUFRX2_OVRVAL]= { .ghz5 = 0x0066, .ghz2 = 0x0066, NOUPLOAD, }, [B2056_SYN_LOGEN_CBUFRX3_OVRVAL]= { .ghz5 = 0x0066, .ghz2 = 0x0066, NOUPLOAD, }, [B2056_SYN_LOGEN_CBUFRX4_OVRVAL]= { .ghz5 = 0x0066, .ghz2 = 0x0066, NOUPLOAD, }, [B2056_SYN_LOGEN_CBUFTX1_OVRVAL]= { .ghz5 = 0x0066, .ghz2 = 0x0066, NOUPLOAD, }, [B2056_SYN_LOGEN_CBUFTX2_OVRVAL]= { .ghz5 = 0x0066, .ghz2 = 0x0066, NOUPLOAD, }, [B2056_SYN_LOGEN_CBUFTX3_OVRVAL]= { .ghz5 = 0x0066, .ghz2 = 0x0066, NOUPLOAD, }, [B2056_SYN_LOGEN_CBUFTX4_OVRVAL]= { .ghz5 = 0x0066, .ghz2 = 0x0066, NOUPLOAD, }, [B2056_SYN_LOGEN_CMOSRX1_OVRVAL]= { .ghz5 = 0x0066, .ghz2 = 0x0066, NOUPLOAD, }, [B2056_SYN_LOGEN_CMOSRX2_OVRVAL]= { .ghz5 = 0x0066, .ghz2 = 0x0066, NOUPLOAD, }, [B2056_SYN_LOGEN_CMOSRX3_OVRVAL]= { .ghz5 = 0x0066, .ghz2 = 0x0066, NOUPLOAD, }, [B2056_SYN_LOGEN_CMOSRX4_OVRVAL]= { .ghz5 = 0x0066, .ghz2 = 0x0066, NOUPLOAD, }, [B2056_SYN_LOGEN_CMOSTX1_OVRVAL]= { .ghz5 = 0x0066, .ghz2 = 0x0066, NOUPLOAD, }, [B2056_SYN_LOGEN_CMOSTX2_OVRVAL]= { .ghz5 = 0x0066, .ghz2 = 0x0066, NOUPLOAD, }, [B2056_SYN_LOGEN_CMOSTX3_OVRVAL]= { .ghz5 = 0x0066, .ghz2 = 0x0066, NOUPLOAD, }, [B2056_SYN_LOGEN_CMOSTX4_OVRVAL]= { .ghz5 = 0x0066, .ghz2 = 0x0066, NOUPLOAD, }, [B2056_SYN_LOGEN_ACL_WAITCNT] = { .ghz5 = 0x000a, .ghz2 = 0x000a, NOUPLOAD, }, [B2056_SYN_LOGEN_CORE_CALVALID] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_RX_CMOS_CALVALID] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_TX_CMOS_VALID] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, }; static const struct b2056_inittab_entry b2056_inittab_radio_rev5_tx[] = { [B2056_TX_RESERVED_ADDR2] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_RESERVED_ADDR3] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_RESERVED_ADDR4] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_RESERVED_ADDR5] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_RESERVED_ADDR6] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_RESERVED_ADDR7] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_COM_CTRL] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_COM_PU] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_COM_OVR] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_COM_RESET] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_COM_RCAL] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_COM_RC_RXLPF] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_COM_RC_TXLPF] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_COM_RC_RXHPF] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_RESERVED_ADDR16] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_RESERVED_ADDR17] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_RESERVED_ADDR18] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_RESERVED_ADDR19] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_RESERVED_ADDR20] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_RESERVED_ADDR21] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_RESERVED_ADDR22] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_RESERVED_ADDR23] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_RESERVED_ADDR24] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_RESERVED_ADDR25] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_RESERVED_ADDR26] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_RESERVED_ADDR27] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_RESERVED_ADDR28] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_RESERVED_ADDR29] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_RESERVED_ADDR30] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_RESERVED_ADDR31] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_IQCAL_GAIN_BW] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_LOFT_FINE_I] = { .ghz5 = 0x0088, .ghz2 = 0x0088, NOUPLOAD, }, [B2056_TX_LOFT_FINE_Q] = { .ghz5 = 0x0088, .ghz2 = 0x0088, NOUPLOAD, }, [B2056_TX_LOFT_COARSE_I] = { .ghz5 = 0x0088, .ghz2 = 0x0088, NOUPLOAD, }, [B2056_TX_LOFT_COARSE_Q] = { .ghz5 = 0x0088, .ghz2 = 0x0088, NOUPLOAD, }, [B2056_TX_TX_COM_MASTER1] = { .ghz5 = 0x000c, .ghz2 = 0x000c, NOUPLOAD, }, [B2056_TX_TX_COM_MASTER2] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_RXIQCAL_TXMUX] = { .ghz5 = 0x0003, .ghz2 = 0x0003, NOUPLOAD, }, [B2056_TX_TX_SSI_MASTER] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_IQCAL_VCM_HG] = { .ghz5 = 0x0003, .ghz2 = 0x0003, NOUPLOAD, }, [B2056_TX_IQCAL_IDAC] = { .ghz5 = 0x0037, .ghz2 = 0x0037, NOUPLOAD, }, [B2056_TX_TSSI_VCM] = { .ghz5 = 0x0003, .ghz2 = 0x0003, NOUPLOAD, }, [B2056_TX_TX_AMP_DET] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_TX_SSI_MUX] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_TSSIA] = { .ghz5 = 0x0001, .ghz2 = 0x0001, NOUPLOAD, }, [B2056_TX_TSSIG] = { .ghz5 = 0x0001, .ghz2 = 0x0001, NOUPLOAD, }, [B2056_TX_TSSI_MISC1] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_TSSI_MISC2] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_TSSI_MISC3] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_PA_SPARE1] = { .ghz5 = 0x0011, .ghz2 = 0x0011, NOUPLOAD, }, [B2056_TX_PA_SPARE2] = { .ghz5 = 0x0011, .ghz2 = 0x0011, NOUPLOAD, }, [B2056_TX_INTPAA_MASTER] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_INTPAA_GAIN] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_INTPAA_BOOST_TUNE] = { .ghz5 = 0x0003, .ghz2 = 0x0003, NOUPLOAD, }, [B2056_TX_INTPAA_IAUX_STAT] = { .ghz5 = 0x000f, .ghz2 = 0x000f, NOUPLOAD, }, [B2056_TX_INTPAA_IAUX_DYN] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_INTPAA_IMAIN_STAT] = { .ghz5 = 0x002d, .ghz2 = 0x002d, NOUPLOAD, }, [B2056_TX_INTPAA_IMAIN_DYN] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_INTPAA_CASCBIAS] = { .ghz5 = 0x006e, .ghz2 = 0x006e, NOUPLOAD, }, [B2056_TX_INTPAA_PASLOPE] = { .ghz5 = 0x00f0, .ghz2 = 0x00f0, UPLOAD, }, [B2056_TX_INTPAA_PA_MISC] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_INTPAG_MASTER] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_INTPAG_GAIN] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_INTPAG_BOOST_TUNE] = { .ghz5 = 0x0003, .ghz2 = 0x0003, NOUPLOAD, }, [B2056_TX_INTPAG_IAUX_STAT] = { .ghz5 = 0x0003, .ghz2 = 0x0003, NOUPLOAD, }, [B2056_TX_INTPAG_IAUX_DYN] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_INTPAG_IMAIN_STAT] = { .ghz5 = 0x001e, .ghz2 = 0x001e, NOUPLOAD, }, [B2056_TX_INTPAG_IMAIN_DYN] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_INTPAG_CASCBIAS] = { .ghz5 = 0x006e, .ghz2 = 0x006e, NOUPLOAD, }, [B2056_TX_INTPAG_PASLOPE] = { .ghz5 = 0x00f0, .ghz2 = 0x00f0, UPLOAD, }, [B2056_TX_INTPAG_PA_MISC] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_PADA_MASTER] = { .ghz5 = 0x0002, .ghz2 = 0x0002, NOUPLOAD, }, [B2056_TX_PADA_IDAC] = { .ghz5 = 0x00ff, .ghz2 = 0x00ff, UPLOAD, }, [B2056_TX_PADA_CASCBIAS] = { .ghz5 = 0x000c, .ghz2 = 0x000c, NOUPLOAD, }, [B2056_TX_PADA_GAIN] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_PADA_BOOST_TUNE] = { .ghz5 = 0x0038, .ghz2 = 0x0038, NOUPLOAD, }, [B2056_TX_PADA_SLOPE] = { .ghz5 = 0x0070, .ghz2 = 0x0070, UPLOAD, }, [B2056_TX_PADG_MASTER] = { .ghz5 = 0x0002, .ghz2 = 0x0002, NOUPLOAD, }, [B2056_TX_PADG_IDAC] = { .ghz5 = 0x0088, .ghz2 = 0x0088, NOUPLOAD, }, [B2056_TX_PADG_CASCBIAS] = { .ghz5 = 0x000c, .ghz2 = 0x000c, NOUPLOAD, }, [B2056_TX_PADG_GAIN] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_PADG_BOOST_TUNE] = { .ghz5 = 0x0008, .ghz2 = 0x0008, NOUPLOAD, }, [B2056_TX_PADG_SLOPE] = { .ghz5 = 0x0070, .ghz2 = 0x0070, UPLOAD, }, [B2056_TX_PGAA_MASTER] = { .ghz5 = 0x0002, .ghz2 = 0x0002, NOUPLOAD, }, [B2056_TX_PGAA_IDAC] = { .ghz5 = 0x00ff, .ghz2 = 0x00ff, UPLOAD, }, [B2056_TX_PGAA_GAIN] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_PGAA_BOOST_TUNE] = { .ghz5 = 0x0083, .ghz2 = 0x0083, NOUPLOAD, }, [B2056_TX_PGAA_SLOPE] = { .ghz5 = 0x0077, .ghz2 = 0x0077, UPLOAD, }, [B2056_TX_PGAA_MISC] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_PGAG_MASTER] = { .ghz5 = 0x0002, .ghz2 = 0x0002, NOUPLOAD, }, [B2056_TX_PGAG_IDAC] = { .ghz5 = 0x0088, .ghz2 = 0x0088, NOUPLOAD, }, [B2056_TX_PGAG_GAIN] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_PGAG_BOOST_TUNE] = { .ghz5 = 0x0008, .ghz2 = 0x0008, NOUPLOAD, }, [B2056_TX_PGAG_SLOPE] = { .ghz5 = 0x0077, .ghz2 = 0x0077, UPLOAD, }, [B2056_TX_PGAG_MISC] = { .ghz5 = 0x0001, .ghz2 = 0x0001, NOUPLOAD, }, [B2056_TX_MIXA_MASTER] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_MIXA_BOOST_TUNE] = { .ghz5 = 0x0007, .ghz2 = 0x0007, NOUPLOAD, }, [B2056_TX_MIXG] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_MIXG_BOOST_TUNE] = { .ghz5 = 0x0007, .ghz2 = 0x0007, NOUPLOAD, }, [B2056_TX_BB_GM_MASTER] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_GMBB_GM] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_GMBB_IDAC] = { .ghz5 = 0x0000, .ghz2 = 0x0000, UPLOAD, }, [B2056_TX_TXLPF_MASTER] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_TXLPF_RCCAL] = { .ghz5 = 0x000a, .ghz2 = 0x000a, NOUPLOAD, }, [B2056_TX_TXLPF_RCCAL_OFF0] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_TXLPF_RCCAL_OFF1] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_TXLPF_RCCAL_OFF2] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_TXLPF_RCCAL_OFF3] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_TXLPF_RCCAL_OFF4] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_TXLPF_RCCAL_OFF5] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_TXLPF_RCCAL_OFF6] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_TXLPF_BW] = { .ghz5 = 0x0002, .ghz2 = 0x0002, NOUPLOAD, }, [B2056_TX_TXLPF_GAIN] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_TXLPF_IDAC] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_TXLPF_IDAC_0] = { .ghz5 = 0x000e, .ghz2 = 0x000e, NOUPLOAD, }, [B2056_TX_TXLPF_IDAC_1] = { .ghz5 = 0x000e, .ghz2 = 0x000e, NOUPLOAD, }, [B2056_TX_TXLPF_IDAC_2] = { .ghz5 = 0x000e, .ghz2 = 0x000e, NOUPLOAD, }, [B2056_TX_TXLPF_IDAC_3] = { .ghz5 = 0x0013, .ghz2 = 0x0013, NOUPLOAD, }, [B2056_TX_TXLPF_IDAC_4] = { .ghz5 = 0x0013, .ghz2 = 0x0013, NOUPLOAD, }, [B2056_TX_TXLPF_IDAC_5] = { .ghz5 = 0x001b, .ghz2 = 0x001b, NOUPLOAD, }, [B2056_TX_TXLPF_IDAC_6] = { .ghz5 = 0x001b, .ghz2 = 0x001b, NOUPLOAD, }, [B2056_TX_TXLPF_OPAMP_IDAC] = { .ghz5 = 0x0055, .ghz2 = 0x0055, NOUPLOAD, }, [B2056_TX_TXLPF_MISC] = { .ghz5 = 0x005b, .ghz2 = 0x005b, NOUPLOAD, }, [B2056_TX_TXSPARE1] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_TXSPARE2] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_TXSPARE3] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_TXSPARE4] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_TXSPARE5] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_TXSPARE6] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_TXSPARE7] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_TXSPARE8] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_TXSPARE9] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_TXSPARE10] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_TXSPARE11] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_TXSPARE12] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_TXSPARE13] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_TXSPARE14] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_TXSPARE15] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_TXSPARE16] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_STATUS_INTPA_GAIN] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_STATUS_PAD_GAIN] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_STATUS_PGA_GAIN] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_STATUS_GM_TXLPF_GAIN] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_STATUS_TXLPF_BW] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_STATUS_TXLPF_RC] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_GMBB_IDAC0] = { .ghz5 = 0x0070, .ghz2 = 0x0070, NOUPLOAD, }, [B2056_TX_GMBB_IDAC1] = { .ghz5 = 0x0070, .ghz2 = 0x0070, NOUPLOAD, }, [B2056_TX_GMBB_IDAC2] = { .ghz5 = 0x0071, .ghz2 = 0x0071, UPLOAD, }, [B2056_TX_GMBB_IDAC3] = { .ghz5 = 0x0071, .ghz2 = 0x0071, UPLOAD, }, [B2056_TX_GMBB_IDAC4] = { .ghz5 = 0x0072, .ghz2 = 0x0072, UPLOAD, }, [B2056_TX_GMBB_IDAC5] = { .ghz5 = 0x0073, .ghz2 = 0x0073, UPLOAD, }, [B2056_TX_GMBB_IDAC6] = { .ghz5 = 0x0074, .ghz2 = 0x0074, UPLOAD, }, [B2056_TX_GMBB_IDAC7] = { .ghz5 = 0x0075, .ghz2 = 0x0075, UPLOAD, }, }; static const struct b2056_inittab_entry b2056_inittab_radio_rev5_rx[] = { [B2056_RX_RESERVED_ADDR2] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RESERVED_ADDR3] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RESERVED_ADDR4] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RESERVED_ADDR5] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RESERVED_ADDR6] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RESERVED_ADDR7] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_COM_CTRL] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_COM_PU] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_COM_OVR] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_COM_RESET] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_COM_RCAL] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_COM_RC_RXLPF] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_COM_RC_TXLPF] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_COM_RC_RXHPF] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RESERVED_ADDR16] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RESERVED_ADDR17] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RESERVED_ADDR18] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RESERVED_ADDR19] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RESERVED_ADDR20] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RESERVED_ADDR21] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RESERVED_ADDR22] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RESERVED_ADDR23] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RESERVED_ADDR24] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RESERVED_ADDR25] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RESERVED_ADDR26] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RESERVED_ADDR27] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RESERVED_ADDR28] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RESERVED_ADDR29] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RESERVED_ADDR30] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RESERVED_ADDR31] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RXIQCAL_RXMUX] = { .ghz5 = 0x0003, .ghz2 = 0x0003, NOUPLOAD, }, [B2056_RX_RSSI_PU] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RSSI_SEL] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RSSI_GAIN] = { .ghz5 = 0x0090, .ghz2 = 0x0090, NOUPLOAD, }, [B2056_RX_RSSI_NB_IDAC] = { .ghz5 = 0x0055, .ghz2 = 0x0055, NOUPLOAD, }, [B2056_RX_RSSI_WB2I_IDAC_1] = { .ghz5 = 0x0015, .ghz2 = 0x0015, NOUPLOAD, }, [B2056_RX_RSSI_WB2I_IDAC_2] = { .ghz5 = 0x0005, .ghz2 = 0x0005, NOUPLOAD, }, [B2056_RX_RSSI_WB2Q_IDAC_1] = { .ghz5 = 0x0015, .ghz2 = 0x0015, NOUPLOAD, }, [B2056_RX_RSSI_WB2Q_IDAC_2] = { .ghz5 = 0x0005, .ghz2 = 0x0005, NOUPLOAD, }, [B2056_RX_RSSI_POLE] = { .ghz5 = 0x0020, .ghz2 = 0x0020, NOUPLOAD, }, [B2056_RX_RSSI_WB1_IDAC] = { .ghz5 = 0x0011, .ghz2 = 0x0011, NOUPLOAD, }, [B2056_RX_RSSI_MISC] = { .ghz5 = 0x0090, .ghz2 = 0x0090, NOUPLOAD, }, [B2056_RX_LNAA_MASTER] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_LNAA_TUNE] = { .ghz5 = 0x0088, .ghz2 = 0x0088, NOUPLOAD, }, [B2056_RX_LNAA_GAIN] = { .ghz5 = 0x0032, .ghz2 = 0x0032, NOUPLOAD, }, [B2056_RX_LNA_A_SLOPE] = { .ghz5 = 0x0077, .ghz2 = 0x0077, NOUPLOAD, }, [B2056_RX_BIASPOLE_LNAA1_IDAC] = { .ghz5 = 0x0017, .ghz2 = 0x0017, UPLOAD, }, [B2056_RX_LNAA2_IDAC] = { .ghz5 = 0x00ff, .ghz2 = 0x00ff, UPLOAD, }, [B2056_RX_LNA1A_MISC] = { .ghz5 = 0x0020, .ghz2 = 0x0020, NOUPLOAD, }, [B2056_RX_LNAG_MASTER] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_LNAG_TUNE] = { .ghz5 = 0x0088, .ghz2 = 0x0088, NOUPLOAD, }, [B2056_RX_LNAG_GAIN] = { .ghz5 = 0x0032, .ghz2 = 0x0032, NOUPLOAD, }, [B2056_RX_LNA_G_SLOPE] = { .ghz5 = 0x0077, .ghz2 = 0x0077, NOUPLOAD, }, [B2056_RX_BIASPOLE_LNAG1_IDAC] = { .ghz5 = 0x0017, .ghz2 = 0x0017, UPLOAD, }, [B2056_RX_LNAG2_IDAC] = { .ghz5 = 0x00f0, .ghz2 = 0x00f0, UPLOAD, }, [B2056_RX_LNA1G_MISC] = { .ghz5 = 0x0020, .ghz2 = 0x0020, NOUPLOAD, }, [B2056_RX_MIXA_MASTER] = { .ghz5 = 0x0008, .ghz2 = 0x0008, NOUPLOAD, }, [B2056_RX_MIXA_VCM] = { .ghz5 = 0x0055, .ghz2 = 0x0055, UPLOAD, }, [B2056_RX_MIXA_CTRLPTAT] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_MIXA_LOB_BIAS] = { .ghz5 = 0x0088, .ghz2 = 0x0088, UPLOAD, }, [B2056_RX_MIXA_CORE_IDAC] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_MIXA_CMFB_IDAC] = { .ghz5 = 0x0000, .ghz2 = 0x0000, UPLOAD, }, [B2056_RX_MIXA_BIAS_AUX] = { .ghz5 = 0x0007, .ghz2 = 0x0007, UPLOAD, }, [B2056_RX_MIXA_BIAS_MAIN] = { .ghz5 = 0x0006, .ghz2 = 0x0006, NOUPLOAD, }, [B2056_RX_MIXA_BIAS_MISC] = { .ghz5 = 0x0004, .ghz2 = 0x0004, NOUPLOAD, }, [B2056_RX_MIXA_MAST_BIAS] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_MIXG_MASTER] = { .ghz5 = 0x0008, .ghz2 = 0x0008, NOUPLOAD, }, [B2056_RX_MIXG_VCM] = { .ghz5 = 0x0055, .ghz2 = 0x0055, UPLOAD, }, [B2056_RX_MIXG_CTRLPTAT] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_MIXG_LOB_BIAS] = { .ghz5 = 0x0011, .ghz2 = 0x0011, NOUPLOAD, }, [B2056_RX_MIXG_CORE_IDAC] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_MIXG_CMFB_IDAC] = { .ghz5 = 0x0000, .ghz2 = 0x0000, UPLOAD, }, [B2056_RX_MIXG_BIAS_AUX] = { .ghz5 = 0x0007, .ghz2 = 0x0007, NOUPLOAD, }, [B2056_RX_MIXG_BIAS_MAIN] = { .ghz5 = 0x0006, .ghz2 = 0x0006, NOUPLOAD, }, [B2056_RX_MIXG_BIAS_MISC] = { .ghz5 = 0x0004, .ghz2 = 0x0004, NOUPLOAD, }, [B2056_RX_MIXG_MAST_BIAS] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_TIA_MASTER] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_TIA_IOPAMP] = { .ghz5 = 0x0026, .ghz2 = 0x0026, UPLOAD, }, [B2056_RX_TIA_QOPAMP] = { .ghz5 = 0x0026, .ghz2 = 0x0026, UPLOAD, }, [B2056_RX_TIA_IMISC] = { .ghz5 = 0x000f, .ghz2 = 0x000f, UPLOAD, }, [B2056_RX_TIA_QMISC] = { .ghz5 = 0x000f, .ghz2 = 0x000f, UPLOAD, }, [B2056_RX_TIA_GAIN] = { .ghz5 = 0x0044, .ghz2 = 0x0044, NOUPLOAD, }, [B2056_RX_TIA_SPARE1] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_TIA_SPARE2] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_BB_LPF_MASTER] = { .ghz5 = 0x0008, .ghz2 = 0x0008, NOUPLOAD, }, [B2056_RX_AACI_MASTER] = { .ghz5 = 0x0008, .ghz2 = 0x0008, NOUPLOAD, }, [B2056_RX_RXLPF_IDAC] = { .ghz5 = 0x0007, .ghz2 = 0x0007, NOUPLOAD, }, [B2056_RX_RXLPF_OPAMPBIAS_LOWQ] = { .ghz5 = 0x0022, .ghz2 = 0x0022, NOUPLOAD, }, [B2056_RX_RXLPF_OPAMPBIAS_HIGHQ]= { .ghz5 = 0x0022, .ghz2 = 0x0022, NOUPLOAD, }, [B2056_RX_RXLPF_BIAS_DCCANCEL] = { .ghz5 = 0x0002, .ghz2 = 0x0002, NOUPLOAD, }, [B2056_RX_RXLPF_OUTVCM] = { .ghz5 = 0x0004, .ghz2 = 0x0004, UPLOAD, }, [B2056_RX_RXLPF_INVCM_BODY] = { .ghz5 = 0x0007, .ghz2 = 0x0007, NOUPLOAD, }, [B2056_RX_RXLPF_CC_OP] = { .ghz5 = 0x0055, .ghz2 = 0x0055, NOUPLOAD, }, [B2056_RX_RXLPF_GAIN] = { .ghz5 = 0x0023, .ghz2 = 0x0023, NOUPLOAD, }, [B2056_RX_RXLPF_Q_BW] = { .ghz5 = 0x0041, .ghz2 = 0x0041, NOUPLOAD, }, [B2056_RX_RXLPF_HP_CORNER_BW] = { .ghz5 = 0x0001, .ghz2 = 0x0001, NOUPLOAD, }, [B2056_RX_RXLPF_RCCAL_HPC] = { .ghz5 = 0x000a, .ghz2 = 0x000a, NOUPLOAD, }, [B2056_RX_RXHPF_OFF0] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RXHPF_OFF1] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RXHPF_OFF2] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RXHPF_OFF3] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RXHPF_OFF4] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RXHPF_OFF5] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RXHPF_OFF6] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RXHPF_OFF7] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RXLPF_RCCAL_LPC] = { .ghz5 = 0x000c, .ghz2 = 0x000c, NOUPLOAD, }, [B2056_RX_RXLPF_OFF_0] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RXLPF_OFF_1] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RXLPF_OFF_2] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RXLPF_OFF_3] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RXLPF_OFF_4] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_UNUSED] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_VGA_MASTER] = { .ghz5 = 0x0022, .ghz2 = 0x0022, NOUPLOAD, }, [B2056_RX_VGA_BIAS] = { .ghz5 = 0x0022, .ghz2 = 0x0022, NOUPLOAD, }, [B2056_RX_VGA_BIAS_DCCANCEL] = { .ghz5 = 0x0000, .ghz2 = 0x0000, UPLOAD, }, [B2056_RX_VGA_GAIN] = { .ghz5 = 0x000a, .ghz2 = 0x000a, NOUPLOAD, }, [B2056_RX_VGA_HP_CORNER_BW] = { .ghz5 = 0x0001, .ghz2 = 0x0001, NOUPLOAD, }, [B2056_RX_VGABUF_BIAS] = { .ghz5 = 0x0022, .ghz2 = 0x0022, NOUPLOAD, }, [B2056_RX_VGABUF_GAIN_BW] = { .ghz5 = 0x0030, .ghz2 = 0x0030, NOUPLOAD, }, [B2056_RX_TXFBMIX_A] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_TXFBMIX_G] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RXSPARE1] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RXSPARE2] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RXSPARE3] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RXSPARE4] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RXSPARE5] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RXSPARE6] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RXSPARE7] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RXSPARE8] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RXSPARE9] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RXSPARE10] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RXSPARE11] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RXSPARE12] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RXSPARE13] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RXSPARE14] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RXSPARE15] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RXSPARE16] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_STATUS_LNAA_GAIN] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_STATUS_LNAG_GAIN] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_STATUS_MIXTIA_GAIN] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_STATUS_RXLPF_GAIN] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_STATUS_VGA_BUF_GAIN] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_STATUS_RXLPF_Q] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_STATUS_RXLPF_BUF_BW] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_STATUS_RXLPF_VGA_HPC] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_STATUS_RXLPF_RC] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_STATUS_HPC_RC] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, }; static const struct b2056_inittab_entry b2056_inittab_radio_rev6_syn[] = { [B2056_SYN_RESERVED_ADDR2] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_RESERVED_ADDR3] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_RESERVED_ADDR4] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_RESERVED_ADDR5] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_RESERVED_ADDR6] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_RESERVED_ADDR7] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_COM_CTRL] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_COM_PU] = { .ghz5 = 0x0001, .ghz2 = 0x0001, NOUPLOAD, }, [B2056_SYN_COM_OVR] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_COM_RESET] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_COM_RCAL] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_COM_RC_RXLPF] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_COM_RC_TXLPF] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_COM_RC_RXHPF] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_RESERVED_ADDR16] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_RESERVED_ADDR17] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_RESERVED_ADDR18] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_RESERVED_ADDR19] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_RESERVED_ADDR20] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_RESERVED_ADDR21] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_RESERVED_ADDR22] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_RESERVED_ADDR23] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_RESERVED_ADDR24] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_RESERVED_ADDR25] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_RESERVED_ADDR26] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_RESERVED_ADDR27] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_RESERVED_ADDR28] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_RESERVED_ADDR29] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_RESERVED_ADDR30] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_RESERVED_ADDR31] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_GPIO_MASTER1] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_GPIO_MASTER2] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_TOPBIAS_MASTER] = { .ghz5 = 0x0060, .ghz2 = 0x0060, NOUPLOAD, }, [B2056_SYN_TOPBIAS_RCAL] = { .ghz5 = 0x0006, .ghz2 = 0x0006, NOUPLOAD, }, [B2056_SYN_AFEREG] = { .ghz5 = 0x000c, .ghz2 = 0x000c, NOUPLOAD, }, [B2056_SYN_TEMPPROCSENSE] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_TEMPPROCSENSEIDAC] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_TEMPPROCSENSERCAL] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LPO] = { .ghz5 = 0x0001, .ghz2 = 0x0001, NOUPLOAD, }, [B2056_SYN_VDDCAL_MASTER] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_VDDCAL_IDAC] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_VDDCAL_STATUS] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_RCAL_MASTER] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_RCAL_CODE_OUT] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_RCCAL_CTRL0] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_RCCAL_CTRL1] = { .ghz5 = 0x001f, .ghz2 = 0x001f, NOUPLOAD, }, [B2056_SYN_RCCAL_CTRL2] = { .ghz5 = 0x0015, .ghz2 = 0x0015, NOUPLOAD, }, [B2056_SYN_RCCAL_CTRL3] = { .ghz5 = 0x000f, .ghz2 = 0x000f, NOUPLOAD, }, [B2056_SYN_RCCAL_CTRL4] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_RCCAL_CTRL5] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_RCCAL_CTRL6] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_RCCAL_CTRL7] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_RCCAL_CTRL8] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_RCCAL_CTRL9] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_RCCAL_CTRL10] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_RCCAL_CTRL11] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_ZCAL_SPARE1] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_ZCAL_SPARE2] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_PLL_MAST1] = { .ghz5 = 0x0013, .ghz2 = 0x0013, NOUPLOAD, }, [B2056_SYN_PLL_MAST2] = { .ghz5 = 0x000f, .ghz2 = 0x000f, NOUPLOAD, }, [B2056_SYN_PLL_MAST3] = { .ghz5 = 0x0018, .ghz2 = 0x0018, NOUPLOAD, }, [B2056_SYN_PLL_BIAS_RESET] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_PLL_XTAL0] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_PLL_XTAL1] = { .ghz5 = 0x0020, .ghz2 = 0x0020, NOUPLOAD, }, [B2056_SYN_PLL_XTAL3] = { .ghz5 = 0x0020, .ghz2 = 0x0020, NOUPLOAD, }, [B2056_SYN_PLL_XTAL4] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_PLL_XTAL5] = { .ghz5 = 0x0077, .ghz2 = 0x0077, NOUPLOAD, }, [B2056_SYN_PLL_XTAL6] = { .ghz5 = 0x0007, .ghz2 = 0x0007, NOUPLOAD, }, [B2056_SYN_PLL_REFDIV] = { .ghz5 = 0x0001, .ghz2 = 0x0001, NOUPLOAD, }, [B2056_SYN_PLL_PFD] = { .ghz5 = 0x0006, .ghz2 = 0x0006, UPLOAD, }, [B2056_SYN_PLL_CP1] = { .ghz5 = 0x000f, .ghz2 = 0x000f, NOUPLOAD, }, [B2056_SYN_PLL_CP2] = { .ghz5 = 0x003f, .ghz2 = 0x003f, UPLOAD, }, [B2056_SYN_PLL_CP3] = { .ghz5 = 0x0032, .ghz2 = 0x0032, NOUPLOAD, }, [B2056_SYN_PLL_LOOPFILTER1] = { .ghz5 = 0x0006, .ghz2 = 0x0006, UPLOAD, }, [B2056_SYN_PLL_LOOPFILTER2] = { .ghz5 = 0x0006, .ghz2 = 0x0006, UPLOAD, }, [B2056_SYN_PLL_LOOPFILTER3] = { .ghz5 = 0x0004, .ghz2 = 0x0004, NOUPLOAD, }, [B2056_SYN_PLL_LOOPFILTER4] = { .ghz5 = 0x002b, .ghz2 = 0x002b, UPLOAD, }, [B2056_SYN_PLL_LOOPFILTER5] = { .ghz5 = 0x0001, .ghz2 = 0x0001, NOUPLOAD, }, [B2056_SYN_PLL_MMD1] = { .ghz5 = 0x001c, .ghz2 = 0x001c, NOUPLOAD, }, [B2056_SYN_PLL_MMD2] = { .ghz5 = 0x0002, .ghz2 = 0x0002, NOUPLOAD, }, [B2056_SYN_PLL_VCO1] = { .ghz5 = 0x0002, .ghz2 = 0x0002, NOUPLOAD, }, [B2056_SYN_PLL_VCO2] = { .ghz5 = 0x00f7, .ghz2 = 0x00f7, UPLOAD, }, [B2056_SYN_PLL_MONITOR1] = { .ghz5 = 0x00b4, .ghz2 = 0x00b4, NOUPLOAD, }, [B2056_SYN_PLL_MONITOR2] = { .ghz5 = 0x00d2, .ghz2 = 0x00d2, NOUPLOAD, }, [B2056_SYN_PLL_VCOCAL1] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_PLL_VCOCAL2] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_PLL_VCOCAL4] = { .ghz5 = 0x0004, .ghz2 = 0x0004, NOUPLOAD, }, [B2056_SYN_PLL_VCOCAL5] = { .ghz5 = 0x0096, .ghz2 = 0x0096, NOUPLOAD, }, [B2056_SYN_PLL_VCOCAL6] = { .ghz5 = 0x003e, .ghz2 = 0x003e, NOUPLOAD, }, [B2056_SYN_PLL_VCOCAL7] = { .ghz5 = 0x003e, .ghz2 = 0x003e, NOUPLOAD, }, [B2056_SYN_PLL_VCOCAL8] = { .ghz5 = 0x0013, .ghz2 = 0x0013, NOUPLOAD, }, [B2056_SYN_PLL_VCOCAL9] = { .ghz5 = 0x0002, .ghz2 = 0x0002, NOUPLOAD, }, [B2056_SYN_PLL_VCOCAL10] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_PLL_VCOCAL11] = { .ghz5 = 0x0007, .ghz2 = 0x0007, NOUPLOAD, }, [B2056_SYN_PLL_VCOCAL12] = { .ghz5 = 0x0007, .ghz2 = 0x0007, UPLOAD, }, [B2056_SYN_PLL_VCOCAL13] = { .ghz5 = 0x0008, .ghz2 = 0x0008, NOUPLOAD, }, [B2056_SYN_PLL_VREG] = { .ghz5 = 0x0003, .ghz2 = 0x0003, NOUPLOAD, }, [B2056_SYN_PLL_STATUS1] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_PLL_STATUS2] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_PLL_STATUS3] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_PU0] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_PU1] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_PU2] = { .ghz5 = 0x0040, .ghz2 = 0x0040, NOUPLOAD, }, [B2056_SYN_LOGEN_PU3] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_PU5] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_PU6] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_PU7] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_PU8] = { .ghz5 = 0x0001, .ghz2 = 0x0001, NOUPLOAD, }, [B2056_SYN_LOGEN_BIAS_RESET] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_RCCR1] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_VCOBUF1] = { .ghz5 = 0x0060, .ghz2 = 0x0060, NOUPLOAD, }, [B2056_SYN_LOGEN_MIXER1] = { .ghz5 = 0x0066, .ghz2 = 0x0066, NOUPLOAD, }, [B2056_SYN_LOGEN_MIXER2] = { .ghz5 = 0x000c, .ghz2 = 0x000c, NOUPLOAD, }, [B2056_SYN_LOGEN_BUF1] = { .ghz5 = 0x0066, .ghz2 = 0x0066, NOUPLOAD, }, [B2056_SYN_LOGENBUF2] = { .ghz5 = 0x008f, .ghz2 = 0x008f, UPLOAD, }, [B2056_SYN_LOGEN_BUF3] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_BUF4] = { .ghz5 = 0x00cc, .ghz2 = 0x00cc, NOUPLOAD, }, [B2056_SYN_LOGEN_DIV1] = { .ghz5 = 0x0001, .ghz2 = 0x0001, NOUPLOAD, }, [B2056_SYN_LOGEN_DIV2] = { .ghz5 = 0x0066, .ghz2 = 0x0066, NOUPLOAD, }, [B2056_SYN_LOGEN_DIV3] = { .ghz5 = 0x0066, .ghz2 = 0x0066, NOUPLOAD, }, [B2056_SYN_LOGEN_ACL1] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_ACL2] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_ACL3] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_ACL4] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_ACL5] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_ACL6] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_ACLOUT] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_ACLCAL1] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_ACLCAL2] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_ACLCAL3] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_CALEN] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_PEAKDET1] = { .ghz5 = 0x00ff, .ghz2 = 0x00ff, NOUPLOAD, }, [B2056_SYN_LOGEN_CORE_ACL_OVR] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_RX_DIFF_ACL_OVR] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_TX_DIFF_ACL_OVR] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_RX_CMOS_ACL_OVR] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_TX_CMOS_ACL_OVR] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_VCOBUF2] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_MIXER3] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_BUF5] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_BUF6] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_CBUFRX1] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_CBUFRX2] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_CBUFRX3] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_CBUFRX4] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_CBUFTX1] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_CBUFTX2] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_CBUFTX3] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_CBUFTX4] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_CMOSRX1] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_CMOSRX2] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_CMOSRX3] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_CMOSRX4] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_CMOSTX1] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_CMOSTX2] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_CMOSTX3] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_CMOSTX4] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_VCOBUF2_OVRVAL]= { .ghz5 = 0x0006, .ghz2 = 0x0006, NOUPLOAD, }, [B2056_SYN_LOGEN_MIXER3_OVRVAL] = { .ghz5 = 0x0066, .ghz2 = 0x0066, NOUPLOAD, }, [B2056_SYN_LOGEN_BUF5_OVRVAL] = { .ghz5 = 0x0066, .ghz2 = 0x0066, NOUPLOAD, }, [B2056_SYN_LOGEN_BUF6_OVRVAL] = { .ghz5 = 0x0066, .ghz2 = 0x0066, NOUPLOAD, }, [B2056_SYN_LOGEN_CBUFRX1_OVRVAL]= { .ghz5 = 0x0066, .ghz2 = 0x0066, NOUPLOAD, }, [B2056_SYN_LOGEN_CBUFRX2_OVRVAL]= { .ghz5 = 0x0066, .ghz2 = 0x0066, NOUPLOAD, }, [B2056_SYN_LOGEN_CBUFRX3_OVRVAL]= { .ghz5 = 0x0066, .ghz2 = 0x0066, NOUPLOAD, }, [B2056_SYN_LOGEN_CBUFRX4_OVRVAL]= { .ghz5 = 0x0066, .ghz2 = 0x0066, NOUPLOAD, }, [B2056_SYN_LOGEN_CBUFTX1_OVRVAL]= { .ghz5 = 0x0066, .ghz2 = 0x0066, NOUPLOAD, }, [B2056_SYN_LOGEN_CBUFTX2_OVRVAL]= { .ghz5 = 0x0066, .ghz2 = 0x0066, NOUPLOAD, }, [B2056_SYN_LOGEN_CBUFTX3_OVRVAL]= { .ghz5 = 0x0066, .ghz2 = 0x0066, NOUPLOAD, }, [B2056_SYN_LOGEN_CBUFTX4_OVRVAL]= { .ghz5 = 0x0066, .ghz2 = 0x0066, NOUPLOAD, }, [B2056_SYN_LOGEN_CMOSRX1_OVRVAL]= { .ghz5 = 0x0066, .ghz2 = 0x0066, NOUPLOAD, }, [B2056_SYN_LOGEN_CMOSRX2_OVRVAL]= { .ghz5 = 0x0066, .ghz2 = 0x0066, NOUPLOAD, }, [B2056_SYN_LOGEN_CMOSRX3_OVRVAL]= { .ghz5 = 0x0066, .ghz2 = 0x0066, NOUPLOAD, }, [B2056_SYN_LOGEN_CMOSRX4_OVRVAL]= { .ghz5 = 0x0066, .ghz2 = 0x0066, NOUPLOAD, }, [B2056_SYN_LOGEN_CMOSTX1_OVRVAL]= { .ghz5 = 0x0066, .ghz2 = 0x0066, NOUPLOAD, }, [B2056_SYN_LOGEN_CMOSTX2_OVRVAL]= { .ghz5 = 0x0066, .ghz2 = 0x0066, NOUPLOAD, }, [B2056_SYN_LOGEN_CMOSTX3_OVRVAL]= { .ghz5 = 0x0066, .ghz2 = 0x0066, NOUPLOAD, }, [B2056_SYN_LOGEN_CMOSTX4_OVRVAL]= { .ghz5 = 0x0066, .ghz2 = 0x0066, NOUPLOAD, }, [B2056_SYN_LOGEN_ACL_WAITCNT] = { .ghz5 = 0x000a, .ghz2 = 0x000a, NOUPLOAD, }, [B2056_SYN_LOGEN_CORE_CALVALID] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_RX_CMOS_CALVALID] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_TX_CMOS_VALID] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, }; static const struct b2056_inittab_entry b2056_inittab_radio_rev6_tx[] = { [B2056_TX_RESERVED_ADDR2] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_RESERVED_ADDR3] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_RESERVED_ADDR4] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_RESERVED_ADDR5] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_RESERVED_ADDR6] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_RESERVED_ADDR7] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_COM_CTRL] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_COM_PU] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_COM_OVR] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_COM_RESET] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_COM_RCAL] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_COM_RC_RXLPF] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_COM_RC_TXLPF] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_COM_RC_RXHPF] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_RESERVED_ADDR16] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_RESERVED_ADDR17] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_RESERVED_ADDR18] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_RESERVED_ADDR19] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_RESERVED_ADDR20] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_RESERVED_ADDR21] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_RESERVED_ADDR22] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_RESERVED_ADDR23] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_RESERVED_ADDR24] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_RESERVED_ADDR25] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_RESERVED_ADDR26] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_RESERVED_ADDR27] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_RESERVED_ADDR28] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_RESERVED_ADDR29] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_RESERVED_ADDR30] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_RESERVED_ADDR31] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_IQCAL_GAIN_BW] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_LOFT_FINE_I] = { .ghz5 = 0x0088, .ghz2 = 0x0088, NOUPLOAD, }, [B2056_TX_LOFT_FINE_Q] = { .ghz5 = 0x0088, .ghz2 = 0x0088, NOUPLOAD, }, [B2056_TX_LOFT_COARSE_I] = { .ghz5 = 0x0088, .ghz2 = 0x0088, NOUPLOAD, }, [B2056_TX_LOFT_COARSE_Q] = { .ghz5 = 0x0088, .ghz2 = 0x0088, NOUPLOAD, }, [B2056_TX_TX_COM_MASTER1] = { .ghz5 = 0x000c, .ghz2 = 0x000c, NOUPLOAD, }, [B2056_TX_TX_COM_MASTER2] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_RXIQCAL_TXMUX] = { .ghz5 = 0x0003, .ghz2 = 0x0003, NOUPLOAD, }, [B2056_TX_TX_SSI_MASTER] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_IQCAL_VCM_HG] = { .ghz5 = 0x0003, .ghz2 = 0x0003, NOUPLOAD, }, [B2056_TX_IQCAL_IDAC] = { .ghz5 = 0x0037, .ghz2 = 0x0037, NOUPLOAD, }, [B2056_TX_TSSI_VCM] = { .ghz5 = 0x0003, .ghz2 = 0x0003, NOUPLOAD, }, [B2056_TX_TX_AMP_DET] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_TX_SSI_MUX] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_TSSIA] = { .ghz5 = 0x0001, .ghz2 = 0x0001, NOUPLOAD, }, [B2056_TX_TSSIG] = { .ghz5 = 0x0001, .ghz2 = 0x0001, NOUPLOAD, }, [B2056_TX_TSSI_MISC1] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_TSSI_MISC2] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_TSSI_MISC3] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_PA_SPARE1] = { .ghz5 = 0x0011, .ghz2 = 0x0011, NOUPLOAD, }, [B2056_TX_PA_SPARE2] = { .ghz5 = 0x00ee, .ghz2 = 0x00ee, UPLOAD, }, [B2056_TX_INTPAA_MASTER] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_INTPAA_GAIN] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_INTPAA_BOOST_TUNE] = { .ghz5 = 0x0003, .ghz2 = 0x0003, NOUPLOAD, }, [B2056_TX_INTPAA_IAUX_STAT] = { .ghz5 = 0x0050, .ghz2 = 0x0050, UPLOAD, }, [B2056_TX_INTPAA_IAUX_DYN] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_INTPAA_IMAIN_STAT] = { .ghz5 = 0x0050, .ghz2 = 0x0050, UPLOAD, }, [B2056_TX_INTPAA_IMAIN_DYN] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_INTPAA_CASCBIAS] = { .ghz5 = 0x006e, .ghz2 = 0x006e, NOUPLOAD, }, [B2056_TX_INTPAA_PASLOPE] = { .ghz5 = 0x00f0, .ghz2 = 0x00f0, UPLOAD, }, [B2056_TX_INTPAA_PA_MISC] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_INTPAG_MASTER] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_INTPAG_GAIN] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_INTPAG_BOOST_TUNE] = { .ghz5 = 0x0003, .ghz2 = 0x0003, NOUPLOAD, }, [B2056_TX_INTPAG_IAUX_STAT] = { .ghz5 = 0x0003, .ghz2 = 0x0003, NOUPLOAD, }, [B2056_TX_INTPAG_IAUX_DYN] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_INTPAG_IMAIN_STAT] = { .ghz5 = 0x001e, .ghz2 = 0x001e, NOUPLOAD, }, [B2056_TX_INTPAG_IMAIN_DYN] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_INTPAG_CASCBIAS] = { .ghz5 = 0x006e, .ghz2 = 0x006e, NOUPLOAD, }, [B2056_TX_INTPAG_PASLOPE] = { .ghz5 = 0x00f0, .ghz2 = 0x00f0, UPLOAD, }, [B2056_TX_INTPAG_PA_MISC] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_PADA_MASTER] = { .ghz5 = 0x0002, .ghz2 = 0x0002, NOUPLOAD, }, [B2056_TX_PADA_IDAC] = { .ghz5 = 0x00ff, .ghz2 = 0x00ff, UPLOAD, }, [B2056_TX_PADA_CASCBIAS] = { .ghz5 = 0x000c, .ghz2 = 0x000c, NOUPLOAD, }, [B2056_TX_PADA_GAIN] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_PADA_BOOST_TUNE] = { .ghz5 = 0x0038, .ghz2 = 0x0038, NOUPLOAD, }, [B2056_TX_PADA_SLOPE] = { .ghz5 = 0x0070, .ghz2 = 0x0070, UPLOAD, }, [B2056_TX_PADG_MASTER] = { .ghz5 = 0x0002, .ghz2 = 0x0002, NOUPLOAD, }, [B2056_TX_PADG_IDAC] = { .ghz5 = 0x0088, .ghz2 = 0x0088, NOUPLOAD, }, [B2056_TX_PADG_CASCBIAS] = { .ghz5 = 0x000c, .ghz2 = 0x000c, NOUPLOAD, }, [B2056_TX_PADG_GAIN] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_PADG_BOOST_TUNE] = { .ghz5 = 0x0008, .ghz2 = 0x0008, NOUPLOAD, }, [B2056_TX_PADG_SLOPE] = { .ghz5 = 0x0070, .ghz2 = 0x0070, UPLOAD, }, [B2056_TX_PGAA_MASTER] = { .ghz5 = 0x0002, .ghz2 = 0x0002, NOUPLOAD, }, [B2056_TX_PGAA_IDAC] = { .ghz5 = 0x00ff, .ghz2 = 0x00ff, UPLOAD, }, [B2056_TX_PGAA_GAIN] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_PGAA_BOOST_TUNE] = { .ghz5 = 0x0083, .ghz2 = 0x0083, NOUPLOAD, }, [B2056_TX_PGAA_SLOPE] = { .ghz5 = 0x0077, .ghz2 = 0x0077, UPLOAD, }, [B2056_TX_PGAA_MISC] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_PGAG_MASTER] = { .ghz5 = 0x0002, .ghz2 = 0x0002, NOUPLOAD, }, [B2056_TX_PGAG_IDAC] = { .ghz5 = 0x0088, .ghz2 = 0x0088, NOUPLOAD, }, [B2056_TX_PGAG_GAIN] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_PGAG_BOOST_TUNE] = { .ghz5 = 0x0008, .ghz2 = 0x0008, NOUPLOAD, }, [B2056_TX_PGAG_SLOPE] = { .ghz5 = 0x0077, .ghz2 = 0x0077, UPLOAD, }, [B2056_TX_PGAG_MISC] = { .ghz5 = 0x0001, .ghz2 = 0x0001, NOUPLOAD, }, [B2056_TX_MIXA_MASTER] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_MIXA_BOOST_TUNE] = { .ghz5 = 0x0007, .ghz2 = 0x0007, NOUPLOAD, }, [B2056_TX_MIXG] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_MIXG_BOOST_TUNE] = { .ghz5 = 0x0007, .ghz2 = 0x0007, NOUPLOAD, }, [B2056_TX_BB_GM_MASTER] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_GMBB_GM] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_GMBB_IDAC] = { .ghz5 = 0x0000, .ghz2 = 0x0000, UPLOAD, }, [B2056_TX_TXLPF_MASTER] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_TXLPF_RCCAL] = { .ghz5 = 0x000a, .ghz2 = 0x000a, NOUPLOAD, }, [B2056_TX_TXLPF_RCCAL_OFF0] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_TXLPF_RCCAL_OFF1] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_TXLPF_RCCAL_OFF2] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_TXLPF_RCCAL_OFF3] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_TXLPF_RCCAL_OFF4] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_TXLPF_RCCAL_OFF5] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_TXLPF_RCCAL_OFF6] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_TXLPF_BW] = { .ghz5 = 0x0002, .ghz2 = 0x0002, NOUPLOAD, }, [B2056_TX_TXLPF_GAIN] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_TXLPF_IDAC] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_TXLPF_IDAC_0] = { .ghz5 = 0x000e, .ghz2 = 0x000e, NOUPLOAD, }, [B2056_TX_TXLPF_IDAC_1] = { .ghz5 = 0x000e, .ghz2 = 0x000e, NOUPLOAD, }, [B2056_TX_TXLPF_IDAC_2] = { .ghz5 = 0x000e, .ghz2 = 0x000e, NOUPLOAD, }, [B2056_TX_TXLPF_IDAC_3] = { .ghz5 = 0x0013, .ghz2 = 0x0013, NOUPLOAD, }, [B2056_TX_TXLPF_IDAC_4] = { .ghz5 = 0x0013, .ghz2 = 0x0013, NOUPLOAD, }, [B2056_TX_TXLPF_IDAC_5] = { .ghz5 = 0x001b, .ghz2 = 0x001b, NOUPLOAD, }, [B2056_TX_TXLPF_IDAC_6] = { .ghz5 = 0x001b, .ghz2 = 0x001b, NOUPLOAD, }, [B2056_TX_TXLPF_OPAMP_IDAC] = { .ghz5 = 0x0055, .ghz2 = 0x0055, NOUPLOAD, }, [B2056_TX_TXLPF_MISC] = { .ghz5 = 0x005b, .ghz2 = 0x005b, NOUPLOAD, }, [B2056_TX_TXSPARE1] = { .ghz5 = 0x0030, .ghz2 = 0x0030, UPLOAD, }, [B2056_TX_TXSPARE2] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_TXSPARE3] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_TXSPARE4] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_TXSPARE5] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_TXSPARE6] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_TXSPARE7] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_TXSPARE8] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_TXSPARE9] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_TXSPARE10] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_TXSPARE11] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_TXSPARE12] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_TXSPARE13] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_TXSPARE14] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_TXSPARE15] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_TXSPARE16] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_STATUS_INTPA_GAIN] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_STATUS_PAD_GAIN] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_STATUS_PGA_GAIN] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_STATUS_GM_TXLPF_GAIN] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_STATUS_TXLPF_BW] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_STATUS_TXLPF_RC] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_GMBB_IDAC0] = { .ghz5 = 0x0070, .ghz2 = 0x0070, NOUPLOAD, }, [B2056_TX_GMBB_IDAC1] = { .ghz5 = 0x0070, .ghz2 = 0x0070, NOUPLOAD, }, [B2056_TX_GMBB_IDAC2] = { .ghz5 = 0x0070, .ghz2 = 0x0070, NOUPLOAD, }, [B2056_TX_GMBB_IDAC3] = { .ghz5 = 0x0070, .ghz2 = 0x0070, NOUPLOAD, }, [B2056_TX_GMBB_IDAC4] = { .ghz5 = 0x0070, .ghz2 = 0x0070, NOUPLOAD, }, [B2056_TX_GMBB_IDAC5] = { .ghz5 = 0x0070, .ghz2 = 0x0070, NOUPLOAD, }, [B2056_TX_GMBB_IDAC6] = { .ghz5 = 0x0070, .ghz2 = 0x0070, NOUPLOAD, }, [B2056_TX_GMBB_IDAC7] = { .ghz5 = 0x0070, .ghz2 = 0x0070, NOUPLOAD, }, }; static const struct b2056_inittab_entry b2056_inittab_radio_rev6_rx[] = { [B2056_RX_RESERVED_ADDR2] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RESERVED_ADDR3] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RESERVED_ADDR4] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RESERVED_ADDR5] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RESERVED_ADDR6] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RESERVED_ADDR7] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_COM_CTRL] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_COM_PU] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_COM_OVR] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_COM_RESET] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_COM_RCAL] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_COM_RC_RXLPF] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_COM_RC_TXLPF] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_COM_RC_RXHPF] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RESERVED_ADDR16] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RESERVED_ADDR17] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RESERVED_ADDR18] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RESERVED_ADDR19] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RESERVED_ADDR20] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RESERVED_ADDR21] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RESERVED_ADDR22] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RESERVED_ADDR23] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RESERVED_ADDR24] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RESERVED_ADDR25] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RESERVED_ADDR26] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RESERVED_ADDR27] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RESERVED_ADDR28] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RESERVED_ADDR29] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RESERVED_ADDR30] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RESERVED_ADDR31] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RXIQCAL_RXMUX] = { .ghz5 = 0x0003, .ghz2 = 0x0003, NOUPLOAD, }, [B2056_RX_RSSI_PU] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RSSI_SEL] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RSSI_GAIN] = { .ghz5 = 0x0090, .ghz2 = 0x0090, NOUPLOAD, }, [B2056_RX_RSSI_NB_IDAC] = { .ghz5 = 0x0055, .ghz2 = 0x0055, NOUPLOAD, }, [B2056_RX_RSSI_WB2I_IDAC_1] = { .ghz5 = 0x0015, .ghz2 = 0x0015, NOUPLOAD, }, [B2056_RX_RSSI_WB2I_IDAC_2] = { .ghz5 = 0x0005, .ghz2 = 0x0005, NOUPLOAD, }, [B2056_RX_RSSI_WB2Q_IDAC_1] = { .ghz5 = 0x0015, .ghz2 = 0x0015, NOUPLOAD, }, [B2056_RX_RSSI_WB2Q_IDAC_2] = { .ghz5 = 0x0005, .ghz2 = 0x0005, NOUPLOAD, }, [B2056_RX_RSSI_POLE] = { .ghz5 = 0x0020, .ghz2 = 0x0020, NOUPLOAD, }, [B2056_RX_RSSI_WB1_IDAC] = { .ghz5 = 0x0011, .ghz2 = 0x0011, NOUPLOAD, }, [B2056_RX_RSSI_MISC] = { .ghz5 = 0x0090, .ghz2 = 0x0090, NOUPLOAD, }, [B2056_RX_LNAA_MASTER] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_LNAA_TUNE] = { .ghz5 = 0x0088, .ghz2 = 0x0088, NOUPLOAD, }, [B2056_RX_LNAA_GAIN] = { .ghz5 = 0x0032, .ghz2 = 0x0032, NOUPLOAD, }, [B2056_RX_LNA_A_SLOPE] = { .ghz5 = 0x0077, .ghz2 = 0x0077, NOUPLOAD, }, [B2056_RX_BIASPOLE_LNAA1_IDAC] = { .ghz5 = 0x0017, .ghz2 = 0x0017, UPLOAD, }, [B2056_RX_LNAA2_IDAC] = { .ghz5 = 0x00ff, .ghz2 = 0x00ff, UPLOAD, }, [B2056_RX_LNA1A_MISC] = { .ghz5 = 0x0020, .ghz2 = 0x0020, NOUPLOAD, }, [B2056_RX_LNAG_MASTER] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_LNAG_TUNE] = { .ghz5 = 0x0088, .ghz2 = 0x0088, NOUPLOAD, }, [B2056_RX_LNAG_GAIN] = { .ghz5 = 0x0032, .ghz2 = 0x0032, NOUPLOAD, }, [B2056_RX_LNA_G_SLOPE] = { .ghz5 = 0x0077, .ghz2 = 0x0077, NOUPLOAD, }, [B2056_RX_BIASPOLE_LNAG1_IDAC] = { .ghz5 = 0x0017, .ghz2 = 0x0017, UPLOAD, }, [B2056_RX_LNAG2_IDAC] = { .ghz5 = 0x00f0, .ghz2 = 0x00f0, UPLOAD, }, [B2056_RX_LNA1G_MISC] = { .ghz5 = 0x0020, .ghz2 = 0x0020, NOUPLOAD, }, [B2056_RX_MIXA_MASTER] = { .ghz5 = 0x0008, .ghz2 = 0x0008, NOUPLOAD, }, [B2056_RX_MIXA_VCM] = { .ghz5 = 0x0055, .ghz2 = 0x0055, UPLOAD, }, [B2056_RX_MIXA_CTRLPTAT] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_MIXA_LOB_BIAS] = { .ghz5 = 0x0088, .ghz2 = 0x0088, UPLOAD, }, [B2056_RX_MIXA_CORE_IDAC] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_MIXA_CMFB_IDAC] = { .ghz5 = 0x0044, .ghz2 = 0x0044, NOUPLOAD, }, [B2056_RX_MIXA_BIAS_AUX] = { .ghz5 = 0x0007, .ghz2 = 0x0007, UPLOAD, }, [B2056_RX_MIXA_BIAS_MAIN] = { .ghz5 = 0x0006, .ghz2 = 0x0006, NOUPLOAD, }, [B2056_RX_MIXA_BIAS_MISC] = { .ghz5 = 0x0004, .ghz2 = 0x0004, NOUPLOAD, }, [B2056_RX_MIXA_MAST_BIAS] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_MIXG_MASTER] = { .ghz5 = 0x0008, .ghz2 = 0x0008, NOUPLOAD, }, [B2056_RX_MIXG_VCM] = { .ghz5 = 0x0055, .ghz2 = 0x0055, UPLOAD, }, [B2056_RX_MIXG_CTRLPTAT] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_MIXG_LOB_BIAS] = { .ghz5 = 0x0011, .ghz2 = 0x0011, NOUPLOAD, }, [B2056_RX_MIXG_CORE_IDAC] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_MIXG_CMFB_IDAC] = { .ghz5 = 0x0044, .ghz2 = 0x0044, NOUPLOAD, }, [B2056_RX_MIXG_BIAS_AUX] = { .ghz5 = 0x0007, .ghz2 = 0x0007, NOUPLOAD, }, [B2056_RX_MIXG_BIAS_MAIN] = { .ghz5 = 0x0006, .ghz2 = 0x0006, NOUPLOAD, }, [B2056_RX_MIXG_BIAS_MISC] = { .ghz5 = 0x0004, .ghz2 = 0x0004, NOUPLOAD, }, [B2056_RX_MIXG_MAST_BIAS] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_TIA_MASTER] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_TIA_IOPAMP] = { .ghz5 = 0x0026, .ghz2 = 0x0026, UPLOAD, }, [B2056_RX_TIA_QOPAMP] = { .ghz5 = 0x0026, .ghz2 = 0x0026, UPLOAD, }, [B2056_RX_TIA_IMISC] = { .ghz5 = 0x000f, .ghz2 = 0x000f, UPLOAD, }, [B2056_RX_TIA_QMISC] = { .ghz5 = 0x000f, .ghz2 = 0x000f, UPLOAD, }, [B2056_RX_TIA_GAIN] = { .ghz5 = 0x0044, .ghz2 = 0x0044, NOUPLOAD, }, [B2056_RX_TIA_SPARE1] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_TIA_SPARE2] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_BB_LPF_MASTER] = { .ghz5 = 0x0008, .ghz2 = 0x0008, NOUPLOAD, }, [B2056_RX_AACI_MASTER] = { .ghz5 = 0x0008, .ghz2 = 0x0008, NOUPLOAD, }, [B2056_RX_RXLPF_IDAC] = { .ghz5 = 0x0007, .ghz2 = 0x0007, NOUPLOAD, }, [B2056_RX_RXLPF_OPAMPBIAS_LOWQ] = { .ghz5 = 0x0022, .ghz2 = 0x0022, NOUPLOAD, }, [B2056_RX_RXLPF_OPAMPBIAS_HIGHQ]= { .ghz5 = 0x0022, .ghz2 = 0x0022, NOUPLOAD, }, [B2056_RX_RXLPF_BIAS_DCCANCEL] = { .ghz5 = 0x0002, .ghz2 = 0x0002, NOUPLOAD, }, [B2056_RX_RXLPF_OUTVCM] = { .ghz5 = 0x0004, .ghz2 = 0x0004, UPLOAD, }, [B2056_RX_RXLPF_INVCM_BODY] = { .ghz5 = 0x0007, .ghz2 = 0x0007, NOUPLOAD, }, [B2056_RX_RXLPF_CC_OP] = { .ghz5 = 0x0055, .ghz2 = 0x0055, NOUPLOAD, }, [B2056_RX_RXLPF_GAIN] = { .ghz5 = 0x0023, .ghz2 = 0x0023, NOUPLOAD, }, [B2056_RX_RXLPF_Q_BW] = { .ghz5 = 0x0041, .ghz2 = 0x0041, NOUPLOAD, }, [B2056_RX_RXLPF_HP_CORNER_BW] = { .ghz5 = 0x0001, .ghz2 = 0x0001, NOUPLOAD, }, [B2056_RX_RXLPF_RCCAL_HPC] = { .ghz5 = 0x000a, .ghz2 = 0x000a, NOUPLOAD, }, [B2056_RX_RXHPF_OFF0] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RXHPF_OFF1] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RXHPF_OFF2] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RXHPF_OFF3] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RXHPF_OFF4] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RXHPF_OFF5] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RXHPF_OFF6] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RXHPF_OFF7] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RXLPF_RCCAL_LPC] = { .ghz5 = 0x000c, .ghz2 = 0x000c, NOUPLOAD, }, [B2056_RX_RXLPF_OFF_0] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RXLPF_OFF_1] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RXLPF_OFF_2] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RXLPF_OFF_3] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RXLPF_OFF_4] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_UNUSED] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_VGA_MASTER] = { .ghz5 = 0x0022, .ghz2 = 0x0022, NOUPLOAD, }, [B2056_RX_VGA_BIAS] = { .ghz5 = 0x0022, .ghz2 = 0x0022, NOUPLOAD, }, [B2056_RX_VGA_BIAS_DCCANCEL] = { .ghz5 = 0x0000, .ghz2 = 0x0000, UPLOAD, }, [B2056_RX_VGA_GAIN] = { .ghz5 = 0x000a, .ghz2 = 0x000a, NOUPLOAD, }, [B2056_RX_VGA_HP_CORNER_BW] = { .ghz5 = 0x0001, .ghz2 = 0x0001, NOUPLOAD, }, [B2056_RX_VGABUF_BIAS] = { .ghz5 = 0x0022, .ghz2 = 0x0022, NOUPLOAD, }, [B2056_RX_VGABUF_GAIN_BW] = { .ghz5 = 0x0030, .ghz2 = 0x0030, NOUPLOAD, }, [B2056_RX_TXFBMIX_A] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_TXFBMIX_G] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RXSPARE1] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RXSPARE2] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RXSPARE3] = { .ghz5 = 0x0005, .ghz2 = 0x0005, UPLOAD, }, [B2056_RX_RXSPARE4] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RXSPARE5] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RXSPARE6] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RXSPARE7] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RXSPARE8] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RXSPARE9] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RXSPARE10] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RXSPARE11] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RXSPARE12] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RXSPARE13] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RXSPARE14] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RXSPARE15] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RXSPARE16] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_STATUS_LNAA_GAIN] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_STATUS_LNAG_GAIN] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_STATUS_MIXTIA_GAIN] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_STATUS_RXLPF_GAIN] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_STATUS_VGA_BUF_GAIN] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_STATUS_RXLPF_Q] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_STATUS_RXLPF_BUF_BW] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_STATUS_RXLPF_VGA_HPC] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_STATUS_RXLPF_RC] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_STATUS_HPC_RC] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, }; static const struct b2056_inittab_entry b2056_inittab_radio_rev7_9_syn[] = { [B2056_SYN_RESERVED_ADDR2] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_RESERVED_ADDR3] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_RESERVED_ADDR4] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_RESERVED_ADDR5] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_RESERVED_ADDR6] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_RESERVED_ADDR7] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_COM_CTRL] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_COM_PU] = { .ghz5 = 0x0001, .ghz2 = 0x0001, NOUPLOAD, }, [B2056_SYN_COM_OVR] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_COM_RESET] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_COM_RCAL] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_COM_RC_RXLPF] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_COM_RC_TXLPF] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_COM_RC_RXHPF] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_RESERVED_ADDR16] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_RESERVED_ADDR17] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_RESERVED_ADDR18] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_RESERVED_ADDR19] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_RESERVED_ADDR20] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_RESERVED_ADDR21] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_RESERVED_ADDR22] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_RESERVED_ADDR23] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_RESERVED_ADDR24] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_RESERVED_ADDR25] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_RESERVED_ADDR26] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_RESERVED_ADDR27] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_RESERVED_ADDR28] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_RESERVED_ADDR29] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_RESERVED_ADDR30] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_RESERVED_ADDR31] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_GPIO_MASTER1] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_GPIO_MASTER2] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_TOPBIAS_MASTER] = { .ghz5 = 0x0060, .ghz2 = 0x0060, NOUPLOAD, }, [B2056_SYN_TOPBIAS_RCAL] = { .ghz5 = 0x0006, .ghz2 = 0x0006, NOUPLOAD, }, [B2056_SYN_AFEREG] = { .ghz5 = 0x000c, .ghz2 = 0x000c, NOUPLOAD, }, [B2056_SYN_TEMPPROCSENSE] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_TEMPPROCSENSEIDAC] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_TEMPPROCSENSERCAL] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LPO] = { .ghz5 = 0x0001, .ghz2 = 0x0001, NOUPLOAD, }, [B2056_SYN_VDDCAL_MASTER] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_VDDCAL_IDAC] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_VDDCAL_STATUS] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_RCAL_MASTER] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_RCAL_CODE_OUT] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_RCCAL_CTRL0] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_RCCAL_CTRL1] = { .ghz5 = 0x001f, .ghz2 = 0x001f, NOUPLOAD, }, [B2056_SYN_RCCAL_CTRL2] = { .ghz5 = 0x0015, .ghz2 = 0x0015, NOUPLOAD, }, [B2056_SYN_RCCAL_CTRL3] = { .ghz5 = 0x000f, .ghz2 = 0x000f, NOUPLOAD, }, [B2056_SYN_RCCAL_CTRL4] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_RCCAL_CTRL5] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_RCCAL_CTRL6] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_RCCAL_CTRL7] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_RCCAL_CTRL8] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_RCCAL_CTRL9] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_RCCAL_CTRL10] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_RCCAL_CTRL11] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_ZCAL_SPARE1] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_ZCAL_SPARE2] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_PLL_MAST1] = { .ghz5 = 0x0013, .ghz2 = 0x0013, NOUPLOAD, }, [B2056_SYN_PLL_MAST2] = { .ghz5 = 0x000f, .ghz2 = 0x000f, NOUPLOAD, }, [B2056_SYN_PLL_MAST3] = { .ghz5 = 0x0018, .ghz2 = 0x0018, NOUPLOAD, }, [B2056_SYN_PLL_BIAS_RESET] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_PLL_XTAL0] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_PLL_XTAL1] = { .ghz5 = 0x0020, .ghz2 = 0x0020, NOUPLOAD, }, [B2056_SYN_PLL_XTAL3] = { .ghz5 = 0x0020, .ghz2 = 0x0020, NOUPLOAD, }, [B2056_SYN_PLL_XTAL4] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_PLL_XTAL5] = { .ghz5 = 0x0077, .ghz2 = 0x0077, NOUPLOAD, }, [B2056_SYN_PLL_XTAL6] = { .ghz5 = 0x0007, .ghz2 = 0x0007, NOUPLOAD, }, [B2056_SYN_PLL_REFDIV] = { .ghz5 = 0x0001, .ghz2 = 0x0001, NOUPLOAD, }, [B2056_SYN_PLL_PFD] = { .ghz5 = 0x0004, .ghz2 = 0x0004, NOUPLOAD, }, [B2056_SYN_PLL_CP1] = { .ghz5 = 0x000f, .ghz2 = 0x000f, NOUPLOAD, }, [B2056_SYN_PLL_CP2] = { .ghz5 = 0x0030, .ghz2 = 0x0030, NOUPLOAD, }, [B2056_SYN_PLL_CP3] = { .ghz5 = 0x0032, .ghz2 = 0x0032, NOUPLOAD, }, [B2056_SYN_PLL_LOOPFILTER1] = { .ghz5 = 0x000d, .ghz2 = 0x000d, NOUPLOAD, }, [B2056_SYN_PLL_LOOPFILTER2] = { .ghz5 = 0x000d, .ghz2 = 0x000d, NOUPLOAD, }, [B2056_SYN_PLL_LOOPFILTER3] = { .ghz5 = 0x0004, .ghz2 = 0x0004, NOUPLOAD, }, [B2056_SYN_PLL_LOOPFILTER4] = { .ghz5 = 0x0006, .ghz2 = 0x0006, NOUPLOAD, }, [B2056_SYN_PLL_LOOPFILTER5] = { .ghz5 = 0x0001, .ghz2 = 0x0001, NOUPLOAD, }, [B2056_SYN_PLL_MMD1] = { .ghz5 = 0x001c, .ghz2 = 0x001c, NOUPLOAD, }, [B2056_SYN_PLL_MMD2] = { .ghz5 = 0x0002, .ghz2 = 0x0002, NOUPLOAD, }, [B2056_SYN_PLL_VCO1] = { .ghz5 = 0x0002, .ghz2 = 0x0002, NOUPLOAD, }, [B2056_SYN_PLL_VCO2] = { .ghz5 = 0x00f7, .ghz2 = 0x00f7, UPLOAD, }, [B2056_SYN_PLL_MONITOR1] = { .ghz5 = 0x00b4, .ghz2 = 0x00b4, NOUPLOAD, }, [B2056_SYN_PLL_MONITOR2] = { .ghz5 = 0x00d2, .ghz2 = 0x00d2, NOUPLOAD, }, [B2056_SYN_PLL_VCOCAL1] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_PLL_VCOCAL2] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_PLL_VCOCAL4] = { .ghz5 = 0x0004, .ghz2 = 0x0004, NOUPLOAD, }, [B2056_SYN_PLL_VCOCAL5] = { .ghz5 = 0x0096, .ghz2 = 0x0096, NOUPLOAD, }, [B2056_SYN_PLL_VCOCAL6] = { .ghz5 = 0x003e, .ghz2 = 0x003e, NOUPLOAD, }, [B2056_SYN_PLL_VCOCAL7] = { .ghz5 = 0x003e, .ghz2 = 0x003e, NOUPLOAD, }, [B2056_SYN_PLL_VCOCAL8] = { .ghz5 = 0x0013, .ghz2 = 0x0013, NOUPLOAD, }, [B2056_SYN_PLL_VCOCAL9] = { .ghz5 = 0x0002, .ghz2 = 0x0002, NOUPLOAD, }, [B2056_SYN_PLL_VCOCAL10] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_PLL_VCOCAL11] = { .ghz5 = 0x0007, .ghz2 = 0x0007, NOUPLOAD, }, [B2056_SYN_PLL_VCOCAL12] = { .ghz5 = 0x0007, .ghz2 = 0x0007, UPLOAD, }, [B2056_SYN_PLL_VCOCAL13] = { .ghz5 = 0x0008, .ghz2 = 0x0008, NOUPLOAD, }, [B2056_SYN_PLL_VREG] = { .ghz5 = 0x0003, .ghz2 = 0x0003, NOUPLOAD, }, [B2056_SYN_PLL_STATUS1] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_PLL_STATUS2] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_PLL_STATUS3] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_PU0] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_PU1] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_PU2] = { .ghz5 = 0x0040, .ghz2 = 0x0040, NOUPLOAD, }, [B2056_SYN_LOGEN_PU3] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_PU5] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_PU6] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_PU7] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_PU8] = { .ghz5 = 0x0001, .ghz2 = 0x0001, NOUPLOAD, }, [B2056_SYN_LOGEN_BIAS_RESET] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_RCCR1] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_VCOBUF1] = { .ghz5 = 0x0060, .ghz2 = 0x0060, NOUPLOAD, }, [B2056_SYN_LOGEN_MIXER1] = { .ghz5 = 0x0066, .ghz2 = 0x0066, NOUPLOAD, }, [B2056_SYN_LOGEN_MIXER2] = { .ghz5 = 0x000c, .ghz2 = 0x000c, NOUPLOAD, }, [B2056_SYN_LOGEN_BUF1] = { .ghz5 = 0x0066, .ghz2 = 0x0066, NOUPLOAD, }, [B2056_SYN_LOGENBUF2] = { .ghz5 = 0x008f, .ghz2 = 0x008f, UPLOAD, }, [B2056_SYN_LOGEN_BUF3] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_BUF4] = { .ghz5 = 0x00cc, .ghz2 = 0x00cc, NOUPLOAD, }, [B2056_SYN_LOGEN_DIV1] = { .ghz5 = 0x0001, .ghz2 = 0x0001, NOUPLOAD, }, [B2056_SYN_LOGEN_DIV2] = { .ghz5 = 0x0066, .ghz2 = 0x0066, NOUPLOAD, }, [B2056_SYN_LOGEN_DIV3] = { .ghz5 = 0x0066, .ghz2 = 0x0066, NOUPLOAD, }, [B2056_SYN_LOGEN_ACL1] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_ACL2] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_ACL3] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_ACL4] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_ACL5] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_ACL6] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_ACLOUT] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_ACLCAL1] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_ACLCAL2] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_ACLCAL3] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_CALEN] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_PEAKDET1] = { .ghz5 = 0x00ff, .ghz2 = 0x00ff, NOUPLOAD, }, [B2056_SYN_LOGEN_CORE_ACL_OVR] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_RX_DIFF_ACL_OVR] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_TX_DIFF_ACL_OVR] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_RX_CMOS_ACL_OVR] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_TX_CMOS_ACL_OVR] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_VCOBUF2] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_MIXER3] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_BUF5] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_BUF6] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_CBUFRX1] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_CBUFRX2] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_CBUFRX3] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_CBUFRX4] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_CBUFTX1] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_CBUFTX2] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_CBUFTX3] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_CBUFTX4] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_CMOSRX1] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_CMOSRX2] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_CMOSRX3] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_CMOSRX4] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_CMOSTX1] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_CMOSTX2] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_CMOSTX3] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_CMOSTX4] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_VCOBUF2_OVRVAL]= { .ghz5 = 0x0006, .ghz2 = 0x0006, NOUPLOAD, }, [B2056_SYN_LOGEN_MIXER3_OVRVAL] = { .ghz5 = 0x0066, .ghz2 = 0x0066, NOUPLOAD, }, [B2056_SYN_LOGEN_BUF5_OVRVAL] = { .ghz5 = 0x0066, .ghz2 = 0x0066, NOUPLOAD, }, [B2056_SYN_LOGEN_BUF6_OVRVAL] = { .ghz5 = 0x0066, .ghz2 = 0x0066, NOUPLOAD, }, [B2056_SYN_LOGEN_CBUFRX1_OVRVAL]= { .ghz5 = 0x0066, .ghz2 = 0x0066, NOUPLOAD, }, [B2056_SYN_LOGEN_CBUFRX2_OVRVAL]= { .ghz5 = 0x0066, .ghz2 = 0x0066, NOUPLOAD, }, [B2056_SYN_LOGEN_CBUFRX3_OVRVAL]= { .ghz5 = 0x0066, .ghz2 = 0x0066, NOUPLOAD, }, [B2056_SYN_LOGEN_CBUFRX4_OVRVAL]= { .ghz5 = 0x0066, .ghz2 = 0x0066, NOUPLOAD, }, [B2056_SYN_LOGEN_CBUFTX1_OVRVAL]= { .ghz5 = 0x0066, .ghz2 = 0x0066, NOUPLOAD, }, [B2056_SYN_LOGEN_CBUFTX2_OVRVAL]= { .ghz5 = 0x0066, .ghz2 = 0x0066, NOUPLOAD, }, [B2056_SYN_LOGEN_CBUFTX3_OVRVAL]= { .ghz5 = 0x0066, .ghz2 = 0x0066, NOUPLOAD, }, [B2056_SYN_LOGEN_CBUFTX4_OVRVAL]= { .ghz5 = 0x0066, .ghz2 = 0x0066, NOUPLOAD, }, [B2056_SYN_LOGEN_CMOSRX1_OVRVAL]= { .ghz5 = 0x0066, .ghz2 = 0x0066, NOUPLOAD, }, [B2056_SYN_LOGEN_CMOSRX2_OVRVAL]= { .ghz5 = 0x0066, .ghz2 = 0x0066, NOUPLOAD, }, [B2056_SYN_LOGEN_CMOSRX3_OVRVAL]= { .ghz5 = 0x0066, .ghz2 = 0x0066, NOUPLOAD, }, [B2056_SYN_LOGEN_CMOSRX4_OVRVAL]= { .ghz5 = 0x0066, .ghz2 = 0x0066, NOUPLOAD, }, [B2056_SYN_LOGEN_CMOSTX1_OVRVAL]= { .ghz5 = 0x0066, .ghz2 = 0x0066, NOUPLOAD, }, [B2056_SYN_LOGEN_CMOSTX2_OVRVAL]= { .ghz5 = 0x0066, .ghz2 = 0x0066, NOUPLOAD, }, [B2056_SYN_LOGEN_CMOSTX3_OVRVAL]= { .ghz5 = 0x0066, .ghz2 = 0x0066, NOUPLOAD, }, [B2056_SYN_LOGEN_CMOSTX4_OVRVAL]= { .ghz5 = 0x0066, .ghz2 = 0x0066, NOUPLOAD, }, [B2056_SYN_LOGEN_ACL_WAITCNT] = { .ghz5 = 0x000a, .ghz2 = 0x000a, NOUPLOAD, }, [B2056_SYN_LOGEN_CORE_CALVALID] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_RX_CMOS_CALVALID] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_TX_CMOS_VALID] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, }; static const struct b2056_inittab_entry b2056_inittab_radio_rev7_9_tx[] = { [B2056_TX_RESERVED_ADDR2] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_RESERVED_ADDR3] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_RESERVED_ADDR4] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_RESERVED_ADDR5] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_RESERVED_ADDR6] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_RESERVED_ADDR7] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_COM_CTRL] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_COM_PU] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_COM_OVR] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_COM_RESET] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_COM_RCAL] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_COM_RC_RXLPF] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_COM_RC_TXLPF] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_COM_RC_RXHPF] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_RESERVED_ADDR16] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_RESERVED_ADDR17] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_RESERVED_ADDR18] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_RESERVED_ADDR19] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_RESERVED_ADDR20] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_RESERVED_ADDR21] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_RESERVED_ADDR22] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_RESERVED_ADDR23] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_RESERVED_ADDR24] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_RESERVED_ADDR25] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_RESERVED_ADDR26] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_RESERVED_ADDR27] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_RESERVED_ADDR28] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_RESERVED_ADDR29] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_RESERVED_ADDR30] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_RESERVED_ADDR31] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_IQCAL_GAIN_BW] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_LOFT_FINE_I] = { .ghz5 = 0x0088, .ghz2 = 0x0088, NOUPLOAD, }, [B2056_TX_LOFT_FINE_Q] = { .ghz5 = 0x0088, .ghz2 = 0x0088, NOUPLOAD, }, [B2056_TX_LOFT_COARSE_I] = { .ghz5 = 0x0088, .ghz2 = 0x0088, NOUPLOAD, }, [B2056_TX_LOFT_COARSE_Q] = { .ghz5 = 0x0088, .ghz2 = 0x0088, NOUPLOAD, }, [B2056_TX_TX_COM_MASTER1] = { .ghz5 = 0x000c, .ghz2 = 0x000c, NOUPLOAD, }, [B2056_TX_TX_COM_MASTER2] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_RXIQCAL_TXMUX] = { .ghz5 = 0x0003, .ghz2 = 0x0003, NOUPLOAD, }, [B2056_TX_TX_SSI_MASTER] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_IQCAL_VCM_HG] = { .ghz5 = 0x0003, .ghz2 = 0x0003, NOUPLOAD, }, [B2056_TX_IQCAL_IDAC] = { .ghz5 = 0x0037, .ghz2 = 0x0037, NOUPLOAD, }, [B2056_TX_TSSI_VCM] = { .ghz5 = 0x0003, .ghz2 = 0x0003, NOUPLOAD, }, [B2056_TX_TX_AMP_DET] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_TX_SSI_MUX] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_TSSIA] = { .ghz5 = 0x0001, .ghz2 = 0x0001, NOUPLOAD, }, [B2056_TX_TSSIG] = { .ghz5 = 0x0001, .ghz2 = 0x0001, NOUPLOAD, }, [B2056_TX_TSSI_MISC1] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_TSSI_MISC2] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_TSSI_MISC3] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_PA_SPARE1] = { .ghz5 = 0x0011, .ghz2 = 0x0011, NOUPLOAD, }, [B2056_TX_PA_SPARE2] = { .ghz5 = 0x00ee, .ghz2 = 0x00ee, UPLOAD, }, [B2056_TX_INTPAA_MASTER] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_INTPAA_GAIN] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_INTPAA_BOOST_TUNE] = { .ghz5 = 0x0003, .ghz2 = 0x0003, NOUPLOAD, }, [B2056_TX_INTPAA_IAUX_STAT] = { .ghz5 = 0x0050, .ghz2 = 0x0050, UPLOAD, }, [B2056_TX_INTPAA_IAUX_DYN] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_INTPAA_IMAIN_STAT] = { .ghz5 = 0x0050, .ghz2 = 0x0050, UPLOAD, }, [B2056_TX_INTPAA_IMAIN_DYN] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_INTPAA_CASCBIAS] = { .ghz5 = 0x006e, .ghz2 = 0x006e, NOUPLOAD, }, [B2056_TX_INTPAA_PASLOPE] = { .ghz5 = 0x00f0, .ghz2 = 0x00f0, UPLOAD, }, [B2056_TX_INTPAA_PA_MISC] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_INTPAG_MASTER] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_INTPAG_GAIN] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_INTPAG_BOOST_TUNE] = { .ghz5 = 0x0003, .ghz2 = 0x0003, NOUPLOAD, }, [B2056_TX_INTPAG_IAUX_STAT] = { .ghz5 = 0x0003, .ghz2 = 0x0003, NOUPLOAD, }, [B2056_TX_INTPAG_IAUX_DYN] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_INTPAG_IMAIN_STAT] = { .ghz5 = 0x001e, .ghz2 = 0x001e, NOUPLOAD, }, [B2056_TX_INTPAG_IMAIN_DYN] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_INTPAG_CASCBIAS] = { .ghz5 = 0x006e, .ghz2 = 0x006e, NOUPLOAD, }, [B2056_TX_INTPAG_PASLOPE] = { .ghz5 = 0x00f0, .ghz2 = 0x00f0, UPLOAD, }, [B2056_TX_INTPAG_PA_MISC] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_PADA_MASTER] = { .ghz5 = 0x0002, .ghz2 = 0x0002, NOUPLOAD, }, [B2056_TX_PADA_IDAC] = { .ghz5 = 0x00ff, .ghz2 = 0x00ff, UPLOAD, }, [B2056_TX_PADA_CASCBIAS] = { .ghz5 = 0x000c, .ghz2 = 0x000c, NOUPLOAD, }, [B2056_TX_PADA_GAIN] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_PADA_BOOST_TUNE] = { .ghz5 = 0x0038, .ghz2 = 0x0038, NOUPLOAD, }, [B2056_TX_PADA_SLOPE] = { .ghz5 = 0x0070, .ghz2 = 0x0070, UPLOAD, }, [B2056_TX_PADG_MASTER] = { .ghz5 = 0x0002, .ghz2 = 0x0002, NOUPLOAD, }, [B2056_TX_PADG_IDAC] = { .ghz5 = 0x0088, .ghz2 = 0x0088, NOUPLOAD, }, [B2056_TX_PADG_CASCBIAS] = { .ghz5 = 0x000c, .ghz2 = 0x000c, NOUPLOAD, }, [B2056_TX_PADG_GAIN] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_PADG_BOOST_TUNE] = { .ghz5 = 0x0008, .ghz2 = 0x0008, NOUPLOAD, }, [B2056_TX_PADG_SLOPE] = { .ghz5 = 0x0070, .ghz2 = 0x0070, UPLOAD, }, [B2056_TX_PGAA_MASTER] = { .ghz5 = 0x0002, .ghz2 = 0x0002, NOUPLOAD, }, [B2056_TX_PGAA_IDAC] = { .ghz5 = 0x00ff, .ghz2 = 0x00ff, UPLOAD, }, [B2056_TX_PGAA_GAIN] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_PGAA_BOOST_TUNE] = { .ghz5 = 0x0083, .ghz2 = 0x0083, NOUPLOAD, }, [B2056_TX_PGAA_SLOPE] = { .ghz5 = 0x0077, .ghz2 = 0x0077, UPLOAD, }, [B2056_TX_PGAA_MISC] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_PGAG_MASTER] = { .ghz5 = 0x0002, .ghz2 = 0x0002, NOUPLOAD, }, [B2056_TX_PGAG_IDAC] = { .ghz5 = 0x0088, .ghz2 = 0x0088, NOUPLOAD, }, [B2056_TX_PGAG_GAIN] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_PGAG_BOOST_TUNE] = { .ghz5 = 0x0008, .ghz2 = 0x0008, NOUPLOAD, }, [B2056_TX_PGAG_SLOPE] = { .ghz5 = 0x0077, .ghz2 = 0x0077, UPLOAD, }, [B2056_TX_PGAG_MISC] = { .ghz5 = 0x0001, .ghz2 = 0x0001, NOUPLOAD, }, [B2056_TX_MIXA_MASTER] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_MIXA_BOOST_TUNE] = { .ghz5 = 0x0007, .ghz2 = 0x0007, NOUPLOAD, }, [B2056_TX_MIXG] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_MIXG_BOOST_TUNE] = { .ghz5 = 0x0007, .ghz2 = 0x0007, NOUPLOAD, }, [B2056_TX_BB_GM_MASTER] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_GMBB_GM] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_GMBB_IDAC] = { .ghz5 = 0x0000, .ghz2 = 0x0000, UPLOAD, }, [B2056_TX_TXLPF_MASTER] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_TXLPF_RCCAL] = { .ghz5 = 0x000a, .ghz2 = 0x000a, NOUPLOAD, }, [B2056_TX_TXLPF_RCCAL_OFF0] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_TXLPF_RCCAL_OFF1] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_TXLPF_RCCAL_OFF2] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_TXLPF_RCCAL_OFF3] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_TXLPF_RCCAL_OFF4] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_TXLPF_RCCAL_OFF5] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_TXLPF_RCCAL_OFF6] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_TXLPF_BW] = { .ghz5 = 0x0002, .ghz2 = 0x0002, NOUPLOAD, }, [B2056_TX_TXLPF_GAIN] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_TXLPF_IDAC] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_TXLPF_IDAC_0] = { .ghz5 = 0x000e, .ghz2 = 0x000e, NOUPLOAD, }, [B2056_TX_TXLPF_IDAC_1] = { .ghz5 = 0x000e, .ghz2 = 0x000e, NOUPLOAD, }, [B2056_TX_TXLPF_IDAC_2] = { .ghz5 = 0x000e, .ghz2 = 0x000e, NOUPLOAD, }, [B2056_TX_TXLPF_IDAC_3] = { .ghz5 = 0x0013, .ghz2 = 0x0013, NOUPLOAD, }, [B2056_TX_TXLPF_IDAC_4] = { .ghz5 = 0x0013, .ghz2 = 0x0013, NOUPLOAD, }, [B2056_TX_TXLPF_IDAC_5] = { .ghz5 = 0x001b, .ghz2 = 0x001b, NOUPLOAD, }, [B2056_TX_TXLPF_IDAC_6] = { .ghz5 = 0x001b, .ghz2 = 0x001b, NOUPLOAD, }, [B2056_TX_TXLPF_OPAMP_IDAC] = { .ghz5 = 0x0055, .ghz2 = 0x0055, NOUPLOAD, }, [B2056_TX_TXLPF_MISC] = { .ghz5 = 0x005b, .ghz2 = 0x005b, NOUPLOAD, }, [B2056_TX_TXSPARE1] = { .ghz5 = 0x0030, .ghz2 = 0x0030, UPLOAD, }, [B2056_TX_TXSPARE2] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_TXSPARE3] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_TXSPARE4] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_TXSPARE5] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_TXSPARE6] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_TXSPARE7] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_TXSPARE8] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_TXSPARE9] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_TXSPARE10] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_TXSPARE11] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_TXSPARE12] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_TXSPARE13] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_TXSPARE14] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_TXSPARE15] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_TXSPARE16] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_STATUS_INTPA_GAIN] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_STATUS_PAD_GAIN] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_STATUS_PGA_GAIN] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_STATUS_GM_TXLPF_GAIN] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_STATUS_TXLPF_BW] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_STATUS_TXLPF_RC] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_GMBB_IDAC0] = { .ghz5 = 0x0070, .ghz2 = 0x0070, NOUPLOAD, }, [B2056_TX_GMBB_IDAC1] = { .ghz5 = 0x0070, .ghz2 = 0x0070, NOUPLOAD, }, [B2056_TX_GMBB_IDAC2] = { .ghz5 = 0x0071, .ghz2 = 0x0071, UPLOAD, }, [B2056_TX_GMBB_IDAC3] = { .ghz5 = 0x0071, .ghz2 = 0x0071, UPLOAD, }, [B2056_TX_GMBB_IDAC4] = { .ghz5 = 0x0072, .ghz2 = 0x0072, UPLOAD, }, [B2056_TX_GMBB_IDAC5] = { .ghz5 = 0x0073, .ghz2 = 0x0073, UPLOAD, }, [B2056_TX_GMBB_IDAC6] = { .ghz5 = 0x0074, .ghz2 = 0x0074, UPLOAD, }, [B2056_TX_GMBB_IDAC7] = { .ghz5 = 0x0075, .ghz2 = 0x0075, UPLOAD, }, }; static const struct b2056_inittab_entry b2056_inittab_radio_rev7_9_rx[] = { [B2056_RX_RESERVED_ADDR2] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RESERVED_ADDR3] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RESERVED_ADDR4] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RESERVED_ADDR5] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RESERVED_ADDR6] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RESERVED_ADDR7] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_COM_CTRL] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_COM_PU] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_COM_OVR] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_COM_RESET] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_COM_RCAL] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_COM_RC_RXLPF] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_COM_RC_TXLPF] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_COM_RC_RXHPF] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RESERVED_ADDR16] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RESERVED_ADDR17] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RESERVED_ADDR18] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RESERVED_ADDR19] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RESERVED_ADDR20] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RESERVED_ADDR21] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RESERVED_ADDR22] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RESERVED_ADDR23] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RESERVED_ADDR24] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RESERVED_ADDR25] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RESERVED_ADDR26] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RESERVED_ADDR27] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RESERVED_ADDR28] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RESERVED_ADDR29] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RESERVED_ADDR30] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RESERVED_ADDR31] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RXIQCAL_RXMUX] = { .ghz5 = 0x0003, .ghz2 = 0x0003, NOUPLOAD, }, [B2056_RX_RSSI_PU] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RSSI_SEL] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RSSI_GAIN] = { .ghz5 = 0x0090, .ghz2 = 0x0090, NOUPLOAD, }, [B2056_RX_RSSI_NB_IDAC] = { .ghz5 = 0x0055, .ghz2 = 0x0055, NOUPLOAD, }, [B2056_RX_RSSI_WB2I_IDAC_1] = { .ghz5 = 0x0015, .ghz2 = 0x0015, NOUPLOAD, }, [B2056_RX_RSSI_WB2I_IDAC_2] = { .ghz5 = 0x0005, .ghz2 = 0x0005, NOUPLOAD, }, [B2056_RX_RSSI_WB2Q_IDAC_1] = { .ghz5 = 0x0015, .ghz2 = 0x0015, NOUPLOAD, }, [B2056_RX_RSSI_WB2Q_IDAC_2] = { .ghz5 = 0x0005, .ghz2 = 0x0005, NOUPLOAD, }, [B2056_RX_RSSI_POLE] = { .ghz5 = 0x0020, .ghz2 = 0x0020, NOUPLOAD, }, [B2056_RX_RSSI_WB1_IDAC] = { .ghz5 = 0x0011, .ghz2 = 0x0011, NOUPLOAD, }, [B2056_RX_RSSI_MISC] = { .ghz5 = 0x0090, .ghz2 = 0x0090, NOUPLOAD, }, [B2056_RX_LNAA_MASTER] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_LNAA_TUNE] = { .ghz5 = 0x0088, .ghz2 = 0x0088, NOUPLOAD, }, [B2056_RX_LNAA_GAIN] = { .ghz5 = 0x0032, .ghz2 = 0x0032, NOUPLOAD, }, [B2056_RX_LNA_A_SLOPE] = { .ghz5 = 0x0077, .ghz2 = 0x0077, NOUPLOAD, }, [B2056_RX_BIASPOLE_LNAA1_IDAC] = { .ghz5 = 0x0017, .ghz2 = 0x0017, UPLOAD, }, [B2056_RX_LNAA2_IDAC] = { .ghz5 = 0x00ff, .ghz2 = 0x00ff, UPLOAD, }, [B2056_RX_LNA1A_MISC] = { .ghz5 = 0x0020, .ghz2 = 0x0020, NOUPLOAD, }, [B2056_RX_LNAG_MASTER] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_LNAG_TUNE] = { .ghz5 = 0x0088, .ghz2 = 0x0088, NOUPLOAD, }, [B2056_RX_LNAG_GAIN] = { .ghz5 = 0x0032, .ghz2 = 0x0032, NOUPLOAD, }, [B2056_RX_LNA_G_SLOPE] = { .ghz5 = 0x0077, .ghz2 = 0x0077, NOUPLOAD, }, [B2056_RX_BIASPOLE_LNAG1_IDAC] = { .ghz5 = 0x0017, .ghz2 = 0x0017, UPLOAD, }, [B2056_RX_LNAG2_IDAC] = { .ghz5 = 0x00f0, .ghz2 = 0x00f0, UPLOAD, }, [B2056_RX_LNA1G_MISC] = { .ghz5 = 0x0020, .ghz2 = 0x0020, NOUPLOAD, }, [B2056_RX_MIXA_MASTER] = { .ghz5 = 0x0008, .ghz2 = 0x0008, NOUPLOAD, }, [B2056_RX_MIXA_VCM] = { .ghz5 = 0x0055, .ghz2 = 0x0055, UPLOAD, }, [B2056_RX_MIXA_CTRLPTAT] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_MIXA_LOB_BIAS] = { .ghz5 = 0x0088, .ghz2 = 0x0088, UPLOAD, }, [B2056_RX_MIXA_CORE_IDAC] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_MIXA_CMFB_IDAC] = { .ghz5 = 0x0000, .ghz2 = 0x0000, UPLOAD, }, [B2056_RX_MIXA_BIAS_AUX] = { .ghz5 = 0x0007, .ghz2 = 0x0007, UPLOAD, }, [B2056_RX_MIXA_BIAS_MAIN] = { .ghz5 = 0x0006, .ghz2 = 0x0006, NOUPLOAD, }, [B2056_RX_MIXA_BIAS_MISC] = { .ghz5 = 0x0004, .ghz2 = 0x0004, NOUPLOAD, }, [B2056_RX_MIXA_MAST_BIAS] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_MIXG_MASTER] = { .ghz5 = 0x0008, .ghz2 = 0x0008, NOUPLOAD, }, [B2056_RX_MIXG_VCM] = { .ghz5 = 0x0055, .ghz2 = 0x0055, UPLOAD, }, [B2056_RX_MIXG_CTRLPTAT] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_MIXG_LOB_BIAS] = { .ghz5 = 0x0011, .ghz2 = 0x0011, NOUPLOAD, }, [B2056_RX_MIXG_CORE_IDAC] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_MIXG_CMFB_IDAC] = { .ghz5 = 0x0000, .ghz2 = 0x0000, UPLOAD, }, [B2056_RX_MIXG_BIAS_AUX] = { .ghz5 = 0x0007, .ghz2 = 0x0007, NOUPLOAD, }, [B2056_RX_MIXG_BIAS_MAIN] = { .ghz5 = 0x0006, .ghz2 = 0x0006, NOUPLOAD, }, [B2056_RX_MIXG_BIAS_MISC] = { .ghz5 = 0x0004, .ghz2 = 0x0004, NOUPLOAD, }, [B2056_RX_MIXG_MAST_BIAS] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_TIA_MASTER] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_TIA_IOPAMP] = { .ghz5 = 0x0026, .ghz2 = 0x0026, UPLOAD, }, [B2056_RX_TIA_QOPAMP] = { .ghz5 = 0x0026, .ghz2 = 0x0026, UPLOAD, }, [B2056_RX_TIA_IMISC] = { .ghz5 = 0x000f, .ghz2 = 0x000f, UPLOAD, }, [B2056_RX_TIA_QMISC] = { .ghz5 = 0x000f, .ghz2 = 0x000f, UPLOAD, }, [B2056_RX_TIA_GAIN] = { .ghz5 = 0x0044, .ghz2 = 0x0044, NOUPLOAD, }, [B2056_RX_TIA_SPARE1] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_TIA_SPARE2] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_BB_LPF_MASTER] = { .ghz5 = 0x0008, .ghz2 = 0x0008, NOUPLOAD, }, [B2056_RX_AACI_MASTER] = { .ghz5 = 0x0008, .ghz2 = 0x0008, NOUPLOAD, }, [B2056_RX_RXLPF_IDAC] = { .ghz5 = 0x0007, .ghz2 = 0x0007, NOUPLOAD, }, [B2056_RX_RXLPF_OPAMPBIAS_LOWQ] = { .ghz5 = 0x0022, .ghz2 = 0x0022, NOUPLOAD, }, [B2056_RX_RXLPF_OPAMPBIAS_HIGHQ]= { .ghz5 = 0x0022, .ghz2 = 0x0022, NOUPLOAD, }, [B2056_RX_RXLPF_BIAS_DCCANCEL] = { .ghz5 = 0x0002, .ghz2 = 0x0002, NOUPLOAD, }, [B2056_RX_RXLPF_OUTVCM] = { .ghz5 = 0x0004, .ghz2 = 0x0004, UPLOAD, }, [B2056_RX_RXLPF_INVCM_BODY] = { .ghz5 = 0x0007, .ghz2 = 0x0007, NOUPLOAD, }, [B2056_RX_RXLPF_CC_OP] = { .ghz5 = 0x0055, .ghz2 = 0x0055, NOUPLOAD, }, [B2056_RX_RXLPF_GAIN] = { .ghz5 = 0x0023, .ghz2 = 0x0023, NOUPLOAD, }, [B2056_RX_RXLPF_Q_BW] = { .ghz5 = 0x0041, .ghz2 = 0x0041, NOUPLOAD, }, [B2056_RX_RXLPF_HP_CORNER_BW] = { .ghz5 = 0x0001, .ghz2 = 0x0001, NOUPLOAD, }, [B2056_RX_RXLPF_RCCAL_HPC] = { .ghz5 = 0x000a, .ghz2 = 0x000a, NOUPLOAD, }, [B2056_RX_RXHPF_OFF0] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RXHPF_OFF1] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RXHPF_OFF2] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RXHPF_OFF3] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RXHPF_OFF4] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RXHPF_OFF5] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RXHPF_OFF6] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RXHPF_OFF7] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RXLPF_RCCAL_LPC] = { .ghz5 = 0x000c, .ghz2 = 0x000c, NOUPLOAD, }, [B2056_RX_RXLPF_OFF_0] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RXLPF_OFF_1] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RXLPF_OFF_2] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RXLPF_OFF_3] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RXLPF_OFF_4] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_UNUSED] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_VGA_MASTER] = { .ghz5 = 0x0022, .ghz2 = 0x0022, NOUPLOAD, }, [B2056_RX_VGA_BIAS] = { .ghz5 = 0x0022, .ghz2 = 0x0022, NOUPLOAD, }, [B2056_RX_VGA_BIAS_DCCANCEL] = { .ghz5 = 0x0000, .ghz2 = 0x0000, UPLOAD, }, [B2056_RX_VGA_GAIN] = { .ghz5 = 0x000a, .ghz2 = 0x000a, NOUPLOAD, }, [B2056_RX_VGA_HP_CORNER_BW] = { .ghz5 = 0x0001, .ghz2 = 0x0001, NOUPLOAD, }, [B2056_RX_VGABUF_BIAS] = { .ghz5 = 0x0022, .ghz2 = 0x0022, NOUPLOAD, }, [B2056_RX_VGABUF_GAIN_BW] = { .ghz5 = 0x0030, .ghz2 = 0x0030, NOUPLOAD, }, [B2056_RX_TXFBMIX_A] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_TXFBMIX_G] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RXSPARE1] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RXSPARE2] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RXSPARE3] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RXSPARE4] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RXSPARE5] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RXSPARE6] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RXSPARE7] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RXSPARE8] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RXSPARE9] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RXSPARE10] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RXSPARE11] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RXSPARE12] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RXSPARE13] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RXSPARE14] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RXSPARE15] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RXSPARE16] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_STATUS_LNAA_GAIN] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_STATUS_LNAG_GAIN] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_STATUS_MIXTIA_GAIN] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_STATUS_RXLPF_GAIN] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_STATUS_VGA_BUF_GAIN] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_STATUS_RXLPF_Q] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_STATUS_RXLPF_BUF_BW] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_STATUS_RXLPF_VGA_HPC] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_STATUS_RXLPF_RC] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_STATUS_HPC_RC] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, }; static const struct b2056_inittab_entry b2056_inittab_radio_rev8_syn[] = { [B2056_SYN_RESERVED_ADDR2] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_RESERVED_ADDR3] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_RESERVED_ADDR4] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_RESERVED_ADDR5] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_RESERVED_ADDR6] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_RESERVED_ADDR7] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_COM_CTRL] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_COM_PU] = { .ghz5 = 0x0001, .ghz2 = 0x0001, NOUPLOAD, }, [B2056_SYN_COM_OVR] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_COM_RESET] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_COM_RCAL] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_COM_RC_RXLPF] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_COM_RC_TXLPF] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_COM_RC_RXHPF] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_RESERVED_ADDR16] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_RESERVED_ADDR17] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_RESERVED_ADDR18] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_RESERVED_ADDR19] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_RESERVED_ADDR20] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_RESERVED_ADDR21] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_RESERVED_ADDR22] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_RESERVED_ADDR23] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_RESERVED_ADDR24] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_RESERVED_ADDR25] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_RESERVED_ADDR26] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_RESERVED_ADDR27] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_RESERVED_ADDR28] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_RESERVED_ADDR29] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_RESERVED_ADDR30] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_RESERVED_ADDR31] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_GPIO_MASTER1] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_GPIO_MASTER2] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_TOPBIAS_MASTER] = { .ghz5 = 0x0060, .ghz2 = 0x0060, NOUPLOAD, }, [B2056_SYN_TOPBIAS_RCAL] = { .ghz5 = 0x0006, .ghz2 = 0x0006, NOUPLOAD, }, [B2056_SYN_AFEREG] = { .ghz5 = 0x000c, .ghz2 = 0x000c, NOUPLOAD, }, [B2056_SYN_TEMPPROCSENSE] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_TEMPPROCSENSEIDAC] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_TEMPPROCSENSERCAL] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LPO] = { .ghz5 = 0x0001, .ghz2 = 0x0001, NOUPLOAD, }, [B2056_SYN_VDDCAL_MASTER] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_VDDCAL_IDAC] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_VDDCAL_STATUS] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_RCAL_MASTER] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_RCAL_CODE_OUT] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_RCCAL_CTRL0] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_RCCAL_CTRL1] = { .ghz5 = 0x001f, .ghz2 = 0x001f, NOUPLOAD, }, [B2056_SYN_RCCAL_CTRL2] = { .ghz5 = 0x0015, .ghz2 = 0x0015, NOUPLOAD, }, [B2056_SYN_RCCAL_CTRL3] = { .ghz5 = 0x000f, .ghz2 = 0x000f, NOUPLOAD, }, [B2056_SYN_RCCAL_CTRL4] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_RCCAL_CTRL5] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_RCCAL_CTRL6] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_RCCAL_CTRL7] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_RCCAL_CTRL8] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_RCCAL_CTRL9] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_RCCAL_CTRL10] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_RCCAL_CTRL11] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_ZCAL_SPARE1] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_ZCAL_SPARE2] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_PLL_MAST1] = { .ghz5 = 0x0013, .ghz2 = 0x0013, NOUPLOAD, }, [B2056_SYN_PLL_MAST2] = { .ghz5 = 0x000f, .ghz2 = 0x000f, NOUPLOAD, }, [B2056_SYN_PLL_MAST3] = { .ghz5 = 0x0018, .ghz2 = 0x0018, NOUPLOAD, }, [B2056_SYN_PLL_BIAS_RESET] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_PLL_XTAL0] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_PLL_XTAL1] = { .ghz5 = 0x0020, .ghz2 = 0x0020, NOUPLOAD, }, [B2056_SYN_PLL_XTAL3] = { .ghz5 = 0x0020, .ghz2 = 0x0020, NOUPLOAD, }, [B2056_SYN_PLL_XTAL4] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_PLL_XTAL5] = { .ghz5 = 0x0077, .ghz2 = 0x0077, NOUPLOAD, }, [B2056_SYN_PLL_XTAL6] = { .ghz5 = 0x0007, .ghz2 = 0x0007, NOUPLOAD, }, [B2056_SYN_PLL_REFDIV] = { .ghz5 = 0x0001, .ghz2 = 0x0001, NOUPLOAD, }, [B2056_SYN_PLL_PFD] = { .ghz5 = 0x0004, .ghz2 = 0x0004, NOUPLOAD, }, [B2056_SYN_PLL_CP1] = { .ghz5 = 0x000f, .ghz2 = 0x000f, NOUPLOAD, }, [B2056_SYN_PLL_CP2] = { .ghz5 = 0x0030, .ghz2 = 0x0030, NOUPLOAD, }, [B2056_SYN_PLL_CP3] = { .ghz5 = 0x0032, .ghz2 = 0x0032, NOUPLOAD, }, [B2056_SYN_PLL_LOOPFILTER1] = { .ghz5 = 0x000d, .ghz2 = 0x000d, NOUPLOAD, }, [B2056_SYN_PLL_LOOPFILTER2] = { .ghz5 = 0x000d, .ghz2 = 0x000d, NOUPLOAD, }, [B2056_SYN_PLL_LOOPFILTER3] = { .ghz5 = 0x0004, .ghz2 = 0x0004, NOUPLOAD, }, [B2056_SYN_PLL_LOOPFILTER4] = { .ghz5 = 0x0006, .ghz2 = 0x0006, NOUPLOAD, }, [B2056_SYN_PLL_LOOPFILTER5] = { .ghz5 = 0x0001, .ghz2 = 0x0001, NOUPLOAD, }, [B2056_SYN_PLL_MMD1] = { .ghz5 = 0x001c, .ghz2 = 0x001c, NOUPLOAD, }, [B2056_SYN_PLL_MMD2] = { .ghz5 = 0x0002, .ghz2 = 0x0002, NOUPLOAD, }, [B2056_SYN_PLL_VCO1] = { .ghz5 = 0x0002, .ghz2 = 0x0002, NOUPLOAD, }, [B2056_SYN_PLL_VCO2] = { .ghz5 = 0x00f7, .ghz2 = 0x00f7, UPLOAD, }, [B2056_SYN_PLL_MONITOR1] = { .ghz5 = 0x00b4, .ghz2 = 0x00b4, NOUPLOAD, }, [B2056_SYN_PLL_MONITOR2] = { .ghz5 = 0x00d2, .ghz2 = 0x00d2, NOUPLOAD, }, [B2056_SYN_PLL_VCOCAL1] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_PLL_VCOCAL2] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_PLL_VCOCAL4] = { .ghz5 = 0x0004, .ghz2 = 0x0004, NOUPLOAD, }, [B2056_SYN_PLL_VCOCAL5] = { .ghz5 = 0x0096, .ghz2 = 0x0096, NOUPLOAD, }, [B2056_SYN_PLL_VCOCAL6] = { .ghz5 = 0x003e, .ghz2 = 0x003e, NOUPLOAD, }, [B2056_SYN_PLL_VCOCAL7] = { .ghz5 = 0x003e, .ghz2 = 0x003e, NOUPLOAD, }, [B2056_SYN_PLL_VCOCAL8] = { .ghz5 = 0x0013, .ghz2 = 0x0013, NOUPLOAD, }, [B2056_SYN_PLL_VCOCAL9] = { .ghz5 = 0x0002, .ghz2 = 0x0002, NOUPLOAD, }, [B2056_SYN_PLL_VCOCAL10] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_PLL_VCOCAL11] = { .ghz5 = 0x0007, .ghz2 = 0x0007, NOUPLOAD, }, [B2056_SYN_PLL_VCOCAL12] = { .ghz5 = 0x0007, .ghz2 = 0x0007, UPLOAD, }, [B2056_SYN_PLL_VCOCAL13] = { .ghz5 = 0x0008, .ghz2 = 0x0008, NOUPLOAD, }, [B2056_SYN_PLL_VREG] = { .ghz5 = 0x0003, .ghz2 = 0x0003, NOUPLOAD, }, [B2056_SYN_PLL_STATUS1] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_PLL_STATUS2] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_PLL_STATUS3] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_PU0] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_PU1] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_PU2] = { .ghz5 = 0x0040, .ghz2 = 0x0040, NOUPLOAD, }, [B2056_SYN_LOGEN_PU3] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_PU5] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_PU6] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_PU7] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_PU8] = { .ghz5 = 0x0001, .ghz2 = 0x0001, NOUPLOAD, }, [B2056_SYN_LOGEN_BIAS_RESET] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_RCCR1] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_VCOBUF1] = { .ghz5 = 0x0060, .ghz2 = 0x0060, NOUPLOAD, }, [B2056_SYN_LOGEN_MIXER1] = { .ghz5 = 0x0066, .ghz2 = 0x0066, NOUPLOAD, }, [B2056_SYN_LOGEN_MIXER2] = { .ghz5 = 0x000c, .ghz2 = 0x000c, NOUPLOAD, }, [B2056_SYN_LOGEN_BUF1] = { .ghz5 = 0x0066, .ghz2 = 0x0066, NOUPLOAD, }, [B2056_SYN_LOGENBUF2] = { .ghz5 = 0x008f, .ghz2 = 0x008f, UPLOAD, }, [B2056_SYN_LOGEN_BUF3] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_BUF4] = { .ghz5 = 0x00cc, .ghz2 = 0x00cc, NOUPLOAD, }, [B2056_SYN_LOGEN_DIV1] = { .ghz5 = 0x0001, .ghz2 = 0x0001, NOUPLOAD, }, [B2056_SYN_LOGEN_DIV2] = { .ghz5 = 0x0066, .ghz2 = 0x0066, NOUPLOAD, }, [B2056_SYN_LOGEN_DIV3] = { .ghz5 = 0x0066, .ghz2 = 0x0066, NOUPLOAD, }, [B2056_SYN_LOGEN_ACL1] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_ACL2] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_ACL3] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_ACL4] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_ACL5] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_ACL6] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_ACLOUT] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_ACLCAL1] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_ACLCAL2] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_ACLCAL3] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_CALEN] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_PEAKDET1] = { .ghz5 = 0x00ff, .ghz2 = 0x00ff, NOUPLOAD, }, [B2056_SYN_LOGEN_CORE_ACL_OVR] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_RX_DIFF_ACL_OVR] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_TX_DIFF_ACL_OVR] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_RX_CMOS_ACL_OVR] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_TX_CMOS_ACL_OVR] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_VCOBUF2] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_MIXER3] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_BUF5] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_BUF6] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_CBUFRX1] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_CBUFRX2] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_CBUFRX3] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_CBUFRX4] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_CBUFTX1] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_CBUFTX2] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_CBUFTX3] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_CBUFTX4] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_CMOSRX1] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_CMOSRX2] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_CMOSRX3] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_CMOSRX4] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_CMOSTX1] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_CMOSTX2] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_CMOSTX3] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_CMOSTX4] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_VCOBUF2_OVRVAL]= { .ghz5 = 0x0006, .ghz2 = 0x0006, NOUPLOAD, }, [B2056_SYN_LOGEN_MIXER3_OVRVAL] = { .ghz5 = 0x0066, .ghz2 = 0x0066, NOUPLOAD, }, [B2056_SYN_LOGEN_BUF5_OVRVAL] = { .ghz5 = 0x0066, .ghz2 = 0x0066, NOUPLOAD, }, [B2056_SYN_LOGEN_BUF6_OVRVAL] = { .ghz5 = 0x0066, .ghz2 = 0x0066, NOUPLOAD, }, [B2056_SYN_LOGEN_CBUFRX1_OVRVAL]= { .ghz5 = 0x0066, .ghz2 = 0x0066, NOUPLOAD, }, [B2056_SYN_LOGEN_CBUFRX2_OVRVAL]= { .ghz5 = 0x0066, .ghz2 = 0x0066, NOUPLOAD, }, [B2056_SYN_LOGEN_CBUFRX3_OVRVAL]= { .ghz5 = 0x0066, .ghz2 = 0x0066, NOUPLOAD, }, [B2056_SYN_LOGEN_CBUFRX4_OVRVAL]= { .ghz5 = 0x0066, .ghz2 = 0x0066, NOUPLOAD, }, [B2056_SYN_LOGEN_CBUFTX1_OVRVAL]= { .ghz5 = 0x0066, .ghz2 = 0x0066, NOUPLOAD, }, [B2056_SYN_LOGEN_CBUFTX2_OVRVAL]= { .ghz5 = 0x0066, .ghz2 = 0x0066, NOUPLOAD, }, [B2056_SYN_LOGEN_CBUFTX3_OVRVAL]= { .ghz5 = 0x0066, .ghz2 = 0x0066, NOUPLOAD, }, [B2056_SYN_LOGEN_CBUFTX4_OVRVAL]= { .ghz5 = 0x0066, .ghz2 = 0x0066, NOUPLOAD, }, [B2056_SYN_LOGEN_CMOSRX1_OVRVAL]= { .ghz5 = 0x0066, .ghz2 = 0x0066, NOUPLOAD, }, [B2056_SYN_LOGEN_CMOSRX2_OVRVAL]= { .ghz5 = 0x0066, .ghz2 = 0x0066, NOUPLOAD, }, [B2056_SYN_LOGEN_CMOSRX3_OVRVAL]= { .ghz5 = 0x0066, .ghz2 = 0x0066, NOUPLOAD, }, [B2056_SYN_LOGEN_CMOSRX4_OVRVAL]= { .ghz5 = 0x0066, .ghz2 = 0x0066, NOUPLOAD, }, [B2056_SYN_LOGEN_CMOSTX1_OVRVAL]= { .ghz5 = 0x0066, .ghz2 = 0x0066, NOUPLOAD, }, [B2056_SYN_LOGEN_CMOSTX2_OVRVAL]= { .ghz5 = 0x0066, .ghz2 = 0x0066, NOUPLOAD, }, [B2056_SYN_LOGEN_CMOSTX3_OVRVAL]= { .ghz5 = 0x0066, .ghz2 = 0x0066, NOUPLOAD, }, [B2056_SYN_LOGEN_CMOSTX4_OVRVAL]= { .ghz5 = 0x0066, .ghz2 = 0x0066, NOUPLOAD, }, [B2056_SYN_LOGEN_ACL_WAITCNT] = { .ghz5 = 0x000a, .ghz2 = 0x000a, NOUPLOAD, }, [B2056_SYN_LOGEN_CORE_CALVALID] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_RX_CMOS_CALVALID] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_SYN_LOGEN_TX_CMOS_VALID] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, }; static const struct b2056_inittab_entry b2056_inittab_radio_rev8_tx[] = { [B2056_TX_RESERVED_ADDR2] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_RESERVED_ADDR3] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_RESERVED_ADDR4] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_RESERVED_ADDR5] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_RESERVED_ADDR6] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_RESERVED_ADDR7] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_COM_CTRL] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_COM_PU] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_COM_OVR] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_COM_RESET] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_COM_RCAL] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_COM_RC_RXLPF] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_COM_RC_TXLPF] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_COM_RC_RXHPF] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_RESERVED_ADDR16] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_RESERVED_ADDR17] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_RESERVED_ADDR18] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_RESERVED_ADDR19] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_RESERVED_ADDR20] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_RESERVED_ADDR21] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_RESERVED_ADDR22] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_RESERVED_ADDR23] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_RESERVED_ADDR24] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_RESERVED_ADDR25] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_RESERVED_ADDR26] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_RESERVED_ADDR27] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_RESERVED_ADDR28] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_RESERVED_ADDR29] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_RESERVED_ADDR30] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_RESERVED_ADDR31] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_IQCAL_GAIN_BW] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_LOFT_FINE_I] = { .ghz5 = 0x0088, .ghz2 = 0x0088, NOUPLOAD, }, [B2056_TX_LOFT_FINE_Q] = { .ghz5 = 0x0088, .ghz2 = 0x0088, NOUPLOAD, }, [B2056_TX_LOFT_COARSE_I] = { .ghz5 = 0x0088, .ghz2 = 0x0088, NOUPLOAD, }, [B2056_TX_LOFT_COARSE_Q] = { .ghz5 = 0x0088, .ghz2 = 0x0088, NOUPLOAD, }, [B2056_TX_TX_COM_MASTER1] = { .ghz5 = 0x000c, .ghz2 = 0x000c, NOUPLOAD, }, [B2056_TX_TX_COM_MASTER2] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_RXIQCAL_TXMUX] = { .ghz5 = 0x0003, .ghz2 = 0x0003, NOUPLOAD, }, [B2056_TX_TX_SSI_MASTER] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_IQCAL_VCM_HG] = { .ghz5 = 0x0003, .ghz2 = 0x0003, NOUPLOAD, }, [B2056_TX_IQCAL_IDAC] = { .ghz5 = 0x0037, .ghz2 = 0x0037, NOUPLOAD, }, [B2056_TX_TSSI_VCM] = { .ghz5 = 0x0003, .ghz2 = 0x0003, NOUPLOAD, }, [B2056_TX_TX_AMP_DET] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_TX_SSI_MUX] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_TSSIA] = { .ghz5 = 0x0001, .ghz2 = 0x0001, NOUPLOAD, }, [B2056_TX_TSSIG] = { .ghz5 = 0x0001, .ghz2 = 0x0001, NOUPLOAD, }, [B2056_TX_TSSI_MISC1] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_TSSI_MISC2] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_TSSI_MISC3] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_PA_SPARE1] = { .ghz5 = 0x0011, .ghz2 = 0x0011, NOUPLOAD, }, [B2056_TX_PA_SPARE2] = { .ghz5 = 0x00ee, .ghz2 = 0x00ee, UPLOAD, }, [B2056_TX_INTPAA_MASTER] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_INTPAA_GAIN] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_INTPAA_BOOST_TUNE] = { .ghz5 = 0x0003, .ghz2 = 0x0003, NOUPLOAD, }, [B2056_TX_INTPAA_IAUX_STAT] = { .ghz5 = 0x0050, .ghz2 = 0x0050, UPLOAD, }, [B2056_TX_INTPAA_IAUX_DYN] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_INTPAA_IMAIN_STAT] = { .ghz5 = 0x0050, .ghz2 = 0x0050, UPLOAD, }, [B2056_TX_INTPAA_IMAIN_DYN] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_INTPAA_CASCBIAS] = { .ghz5 = 0x006e, .ghz2 = 0x006e, NOUPLOAD, }, [B2056_TX_INTPAA_PASLOPE] = { .ghz5 = 0x00f0, .ghz2 = 0x00f0, UPLOAD, }, [B2056_TX_INTPAA_PA_MISC] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_INTPAG_MASTER] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_INTPAG_GAIN] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_INTPAG_BOOST_TUNE] = { .ghz5 = 0x0003, .ghz2 = 0x0003, NOUPLOAD, }, [B2056_TX_INTPAG_IAUX_STAT] = { .ghz5 = 0x0003, .ghz2 = 0x0003, NOUPLOAD, }, [B2056_TX_INTPAG_IAUX_DYN] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_INTPAG_IMAIN_STAT] = { .ghz5 = 0x001e, .ghz2 = 0x001e, NOUPLOAD, }, [B2056_TX_INTPAG_IMAIN_DYN] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_INTPAG_CASCBIAS] = { .ghz5 = 0x006e, .ghz2 = 0x006e, NOUPLOAD, }, [B2056_TX_INTPAG_PASLOPE] = { .ghz5 = 0x00f0, .ghz2 = 0x00f0, UPLOAD, }, [B2056_TX_INTPAG_PA_MISC] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_PADA_MASTER] = { .ghz5 = 0x0002, .ghz2 = 0x0002, NOUPLOAD, }, [B2056_TX_PADA_IDAC] = { .ghz5 = 0x00ff, .ghz2 = 0x00ff, UPLOAD, }, [B2056_TX_PADA_CASCBIAS] = { .ghz5 = 0x000c, .ghz2 = 0x000c, NOUPLOAD, }, [B2056_TX_PADA_GAIN] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_PADA_BOOST_TUNE] = { .ghz5 = 0x0038, .ghz2 = 0x0038, NOUPLOAD, }, [B2056_TX_PADA_SLOPE] = { .ghz5 = 0x0070, .ghz2 = 0x0070, UPLOAD, }, [B2056_TX_PADG_MASTER] = { .ghz5 = 0x0002, .ghz2 = 0x0002, NOUPLOAD, }, [B2056_TX_PADG_IDAC] = { .ghz5 = 0x0088, .ghz2 = 0x0088, NOUPLOAD, }, [B2056_TX_PADG_CASCBIAS] = { .ghz5 = 0x000c, .ghz2 = 0x000c, NOUPLOAD, }, [B2056_TX_PADG_GAIN] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_PADG_BOOST_TUNE] = { .ghz5 = 0x0008, .ghz2 = 0x0008, NOUPLOAD, }, [B2056_TX_PADG_SLOPE] = { .ghz5 = 0x0070, .ghz2 = 0x0070, UPLOAD, }, [B2056_TX_PGAA_MASTER] = { .ghz5 = 0x0002, .ghz2 = 0x0002, NOUPLOAD, }, [B2056_TX_PGAA_IDAC] = { .ghz5 = 0x00ff, .ghz2 = 0x00ff, UPLOAD, }, [B2056_TX_PGAA_GAIN] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_PGAA_BOOST_TUNE] = { .ghz5 = 0x0083, .ghz2 = 0x0083, NOUPLOAD, }, [B2056_TX_PGAA_SLOPE] = { .ghz5 = 0x0077, .ghz2 = 0x0077, UPLOAD, }, [B2056_TX_PGAA_MISC] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_PGAG_MASTER] = { .ghz5 = 0x0002, .ghz2 = 0x0002, NOUPLOAD, }, [B2056_TX_PGAG_IDAC] = { .ghz5 = 0x0088, .ghz2 = 0x0088, NOUPLOAD, }, [B2056_TX_PGAG_GAIN] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_PGAG_BOOST_TUNE] = { .ghz5 = 0x0008, .ghz2 = 0x0008, NOUPLOAD, }, [B2056_TX_PGAG_SLOPE] = { .ghz5 = 0x0077, .ghz2 = 0x0077, UPLOAD, }, [B2056_TX_PGAG_MISC] = { .ghz5 = 0x0001, .ghz2 = 0x0001, NOUPLOAD, }, [B2056_TX_MIXA_MASTER] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_MIXA_BOOST_TUNE] = { .ghz5 = 0x0007, .ghz2 = 0x0007, NOUPLOAD, }, [B2056_TX_MIXG] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_MIXG_BOOST_TUNE] = { .ghz5 = 0x0007, .ghz2 = 0x0007, NOUPLOAD, }, [B2056_TX_BB_GM_MASTER] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_GMBB_GM] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_GMBB_IDAC] = { .ghz5 = 0x0000, .ghz2 = 0x0000, UPLOAD, }, [B2056_TX_TXLPF_MASTER] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_TXLPF_RCCAL] = { .ghz5 = 0x000a, .ghz2 = 0x000a, NOUPLOAD, }, [B2056_TX_TXLPF_RCCAL_OFF0] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_TXLPF_RCCAL_OFF1] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_TXLPF_RCCAL_OFF2] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_TXLPF_RCCAL_OFF3] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_TXLPF_RCCAL_OFF4] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_TXLPF_RCCAL_OFF5] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_TXLPF_RCCAL_OFF6] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_TXLPF_BW] = { .ghz5 = 0x0002, .ghz2 = 0x0002, NOUPLOAD, }, [B2056_TX_TXLPF_GAIN] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_TXLPF_IDAC] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_TXLPF_IDAC_0] = { .ghz5 = 0x000e, .ghz2 = 0x000e, NOUPLOAD, }, [B2056_TX_TXLPF_IDAC_1] = { .ghz5 = 0x000e, .ghz2 = 0x000e, NOUPLOAD, }, [B2056_TX_TXLPF_IDAC_2] = { .ghz5 = 0x000e, .ghz2 = 0x000e, NOUPLOAD, }, [B2056_TX_TXLPF_IDAC_3] = { .ghz5 = 0x0013, .ghz2 = 0x0013, NOUPLOAD, }, [B2056_TX_TXLPF_IDAC_4] = { .ghz5 = 0x0013, .ghz2 = 0x0013, NOUPLOAD, }, [B2056_TX_TXLPF_IDAC_5] = { .ghz5 = 0x001b, .ghz2 = 0x001b, NOUPLOAD, }, [B2056_TX_TXLPF_IDAC_6] = { .ghz5 = 0x001b, .ghz2 = 0x001b, NOUPLOAD, }, [B2056_TX_TXLPF_OPAMP_IDAC] = { .ghz5 = 0x0055, .ghz2 = 0x0055, NOUPLOAD, }, [B2056_TX_TXLPF_MISC] = { .ghz5 = 0x005b, .ghz2 = 0x005b, NOUPLOAD, }, [B2056_TX_TXSPARE1] = { .ghz5 = 0x0030, .ghz2 = 0x0030, UPLOAD, }, [B2056_TX_TXSPARE2] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_TXSPARE3] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_TXSPARE4] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_TXSPARE5] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_TXSPARE6] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_TXSPARE7] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_TXSPARE8] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_TXSPARE9] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_TXSPARE10] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_TXSPARE11] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_TXSPARE12] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_TXSPARE13] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_TXSPARE14] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_TXSPARE15] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_TXSPARE16] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_STATUS_INTPA_GAIN] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_STATUS_PAD_GAIN] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_STATUS_PGA_GAIN] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_STATUS_GM_TXLPF_GAIN] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_STATUS_TXLPF_BW] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_STATUS_TXLPF_RC] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_TX_GMBB_IDAC0] = { .ghz5 = 0x0070, .ghz2 = 0x0070, NOUPLOAD, }, [B2056_TX_GMBB_IDAC1] = { .ghz5 = 0x0070, .ghz2 = 0x0070, NOUPLOAD, }, [B2056_TX_GMBB_IDAC2] = { .ghz5 = 0x0070, .ghz2 = 0x0070, NOUPLOAD, }, [B2056_TX_GMBB_IDAC3] = { .ghz5 = 0x0070, .ghz2 = 0x0070, NOUPLOAD, }, [B2056_TX_GMBB_IDAC4] = { .ghz5 = 0x0070, .ghz2 = 0x0070, NOUPLOAD, }, [B2056_TX_GMBB_IDAC5] = { .ghz5 = 0x0070, .ghz2 = 0x0070, NOUPLOAD, }, [B2056_TX_GMBB_IDAC6] = { .ghz5 = 0x0070, .ghz2 = 0x0070, NOUPLOAD, }, [B2056_TX_GMBB_IDAC7] = { .ghz5 = 0x0070, .ghz2 = 0x0070, NOUPLOAD, }, }; static const struct b2056_inittab_entry b2056_inittab_radio_rev8_rx[] = { [B2056_RX_RESERVED_ADDR2] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RESERVED_ADDR3] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RESERVED_ADDR4] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RESERVED_ADDR5] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RESERVED_ADDR6] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RESERVED_ADDR7] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_COM_CTRL] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_COM_PU] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_COM_OVR] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_COM_RESET] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_COM_RCAL] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_COM_RC_RXLPF] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_COM_RC_TXLPF] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_COM_RC_RXHPF] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RESERVED_ADDR16] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RESERVED_ADDR17] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RESERVED_ADDR18] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RESERVED_ADDR19] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RESERVED_ADDR20] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RESERVED_ADDR21] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RESERVED_ADDR22] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RESERVED_ADDR23] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RESERVED_ADDR24] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RESERVED_ADDR25] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RESERVED_ADDR26] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RESERVED_ADDR27] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RESERVED_ADDR28] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RESERVED_ADDR29] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RESERVED_ADDR30] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RESERVED_ADDR31] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RXIQCAL_RXMUX] = { .ghz5 = 0x0003, .ghz2 = 0x0003, NOUPLOAD, }, [B2056_RX_RSSI_PU] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RSSI_SEL] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RSSI_GAIN] = { .ghz5 = 0x0090, .ghz2 = 0x0090, NOUPLOAD, }, [B2056_RX_RSSI_NB_IDAC] = { .ghz5 = 0x0055, .ghz2 = 0x0055, NOUPLOAD, }, [B2056_RX_RSSI_WB2I_IDAC_1] = { .ghz5 = 0x0015, .ghz2 = 0x0015, NOUPLOAD, }, [B2056_RX_RSSI_WB2I_IDAC_2] = { .ghz5 = 0x0005, .ghz2 = 0x0005, NOUPLOAD, }, [B2056_RX_RSSI_WB2Q_IDAC_1] = { .ghz5 = 0x0015, .ghz2 = 0x0015, NOUPLOAD, }, [B2056_RX_RSSI_WB2Q_IDAC_2] = { .ghz5 = 0x0005, .ghz2 = 0x0005, NOUPLOAD, }, [B2056_RX_RSSI_POLE] = { .ghz5 = 0x0020, .ghz2 = 0x0020, NOUPLOAD, }, [B2056_RX_RSSI_WB1_IDAC] = { .ghz5 = 0x0011, .ghz2 = 0x0011, NOUPLOAD, }, [B2056_RX_RSSI_MISC] = { .ghz5 = 0x0090, .ghz2 = 0x0090, NOUPLOAD, }, [B2056_RX_LNAA_MASTER] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_LNAA_TUNE] = { .ghz5 = 0x0088, .ghz2 = 0x0088, NOUPLOAD, }, [B2056_RX_LNAA_GAIN] = { .ghz5 = 0x0032, .ghz2 = 0x0032, NOUPLOAD, }, [B2056_RX_LNA_A_SLOPE] = { .ghz5 = 0x0077, .ghz2 = 0x0077, NOUPLOAD, }, [B2056_RX_BIASPOLE_LNAA1_IDAC] = { .ghz5 = 0x0017, .ghz2 = 0x0017, UPLOAD, }, [B2056_RX_LNAA2_IDAC] = { .ghz5 = 0x00ff, .ghz2 = 0x00ff, UPLOAD, }, [B2056_RX_LNA1A_MISC] = { .ghz5 = 0x0020, .ghz2 = 0x0020, NOUPLOAD, }, [B2056_RX_LNAG_MASTER] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_LNAG_TUNE] = { .ghz5 = 0x0088, .ghz2 = 0x0088, NOUPLOAD, }, [B2056_RX_LNAG_GAIN] = { .ghz5 = 0x0032, .ghz2 = 0x0032, NOUPLOAD, }, [B2056_RX_LNA_G_SLOPE] = { .ghz5 = 0x0077, .ghz2 = 0x0077, NOUPLOAD, }, [B2056_RX_BIASPOLE_LNAG1_IDAC] = { .ghz5 = 0x0017, .ghz2 = 0x0017, UPLOAD, }, [B2056_RX_LNAG2_IDAC] = { .ghz5 = 0x00f0, .ghz2 = 0x00f0, UPLOAD, }, [B2056_RX_LNA1G_MISC] = { .ghz5 = 0x0020, .ghz2 = 0x0020, NOUPLOAD, }, [B2056_RX_MIXA_MASTER] = { .ghz5 = 0x0008, .ghz2 = 0x0008, NOUPLOAD, }, [B2056_RX_MIXA_VCM] = { .ghz5 = 0x0055, .ghz2 = 0x0055, UPLOAD, }, [B2056_RX_MIXA_CTRLPTAT] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_MIXA_LOB_BIAS] = { .ghz5 = 0x0088, .ghz2 = 0x0088, UPLOAD, }, [B2056_RX_MIXA_CORE_IDAC] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_MIXA_CMFB_IDAC] = { .ghz5 = 0x0044, .ghz2 = 0x0044, NOUPLOAD, }, [B2056_RX_MIXA_BIAS_AUX] = { .ghz5 = 0x0007, .ghz2 = 0x0007, UPLOAD, }, [B2056_RX_MIXA_BIAS_MAIN] = { .ghz5 = 0x0006, .ghz2 = 0x0006, NOUPLOAD, }, [B2056_RX_MIXA_BIAS_MISC] = { .ghz5 = 0x0004, .ghz2 = 0x0004, NOUPLOAD, }, [B2056_RX_MIXA_MAST_BIAS] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_MIXG_MASTER] = { .ghz5 = 0x0008, .ghz2 = 0x0008, NOUPLOAD, }, [B2056_RX_MIXG_VCM] = { .ghz5 = 0x0055, .ghz2 = 0x0055, UPLOAD, }, [B2056_RX_MIXG_CTRLPTAT] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_MIXG_LOB_BIAS] = { .ghz5 = 0x0011, .ghz2 = 0x0011, NOUPLOAD, }, [B2056_RX_MIXG_CORE_IDAC] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_MIXG_CMFB_IDAC] = { .ghz5 = 0x0044, .ghz2 = 0x0044, NOUPLOAD, }, [B2056_RX_MIXG_BIAS_AUX] = { .ghz5 = 0x0007, .ghz2 = 0x0007, NOUPLOAD, }, [B2056_RX_MIXG_BIAS_MAIN] = { .ghz5 = 0x0006, .ghz2 = 0x0006, NOUPLOAD, }, [B2056_RX_MIXG_BIAS_MISC] = { .ghz5 = 0x0004, .ghz2 = 0x0004, NOUPLOAD, }, [B2056_RX_MIXG_MAST_BIAS] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_TIA_MASTER] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_TIA_IOPAMP] = { .ghz5 = 0x0026, .ghz2 = 0x0026, UPLOAD, }, [B2056_RX_TIA_QOPAMP] = { .ghz5 = 0x0026, .ghz2 = 0x0026, UPLOAD, }, [B2056_RX_TIA_IMISC] = { .ghz5 = 0x000f, .ghz2 = 0x000f, UPLOAD, }, [B2056_RX_TIA_QMISC] = { .ghz5 = 0x000f, .ghz2 = 0x000f, UPLOAD, }, [B2056_RX_TIA_GAIN] = { .ghz5 = 0x0044, .ghz2 = 0x0044, NOUPLOAD, }, [B2056_RX_TIA_SPARE1] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_TIA_SPARE2] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_BB_LPF_MASTER] = { .ghz5 = 0x0008, .ghz2 = 0x0008, NOUPLOAD, }, [B2056_RX_AACI_MASTER] = { .ghz5 = 0x0008, .ghz2 = 0x0008, NOUPLOAD, }, [B2056_RX_RXLPF_IDAC] = { .ghz5 = 0x0007, .ghz2 = 0x0007, NOUPLOAD, }, [B2056_RX_RXLPF_OPAMPBIAS_LOWQ] = { .ghz5 = 0x0022, .ghz2 = 0x0022, NOUPLOAD, }, [B2056_RX_RXLPF_OPAMPBIAS_HIGHQ]= { .ghz5 = 0x0022, .ghz2 = 0x0022, NOUPLOAD, }, [B2056_RX_RXLPF_BIAS_DCCANCEL] = { .ghz5 = 0x0002, .ghz2 = 0x0002, NOUPLOAD, }, [B2056_RX_RXLPF_OUTVCM] = { .ghz5 = 0x0004, .ghz2 = 0x0004, UPLOAD, }, [B2056_RX_RXLPF_INVCM_BODY] = { .ghz5 = 0x0007, .ghz2 = 0x0007, NOUPLOAD, }, [B2056_RX_RXLPF_CC_OP] = { .ghz5 = 0x0055, .ghz2 = 0x0055, NOUPLOAD, }, [B2056_RX_RXLPF_GAIN] = { .ghz5 = 0x0023, .ghz2 = 0x0023, NOUPLOAD, }, [B2056_RX_RXLPF_Q_BW] = { .ghz5 = 0x0041, .ghz2 = 0x0041, NOUPLOAD, }, [B2056_RX_RXLPF_HP_CORNER_BW] = { .ghz5 = 0x0001, .ghz2 = 0x0001, NOUPLOAD, }, [B2056_RX_RXLPF_RCCAL_HPC] = { .ghz5 = 0x000a, .ghz2 = 0x000a, NOUPLOAD, }, [B2056_RX_RXHPF_OFF0] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RXHPF_OFF1] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RXHPF_OFF2] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RXHPF_OFF3] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RXHPF_OFF4] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RXHPF_OFF5] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RXHPF_OFF6] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RXHPF_OFF7] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RXLPF_RCCAL_LPC] = { .ghz5 = 0x000c, .ghz2 = 0x000c, NOUPLOAD, }, [B2056_RX_RXLPF_OFF_0] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RXLPF_OFF_1] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RXLPF_OFF_2] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RXLPF_OFF_3] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RXLPF_OFF_4] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_UNUSED] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_VGA_MASTER] = { .ghz5 = 0x0022, .ghz2 = 0x0022, NOUPLOAD, }, [B2056_RX_VGA_BIAS] = { .ghz5 = 0x0022, .ghz2 = 0x0022, NOUPLOAD, }, [B2056_RX_VGA_BIAS_DCCANCEL] = { .ghz5 = 0x0000, .ghz2 = 0x0000, UPLOAD, }, [B2056_RX_VGA_GAIN] = { .ghz5 = 0x000a, .ghz2 = 0x000a, NOUPLOAD, }, [B2056_RX_VGA_HP_CORNER_BW] = { .ghz5 = 0x0001, .ghz2 = 0x0001, NOUPLOAD, }, [B2056_RX_VGABUF_BIAS] = { .ghz5 = 0x0022, .ghz2 = 0x0022, NOUPLOAD, }, [B2056_RX_VGABUF_GAIN_BW] = { .ghz5 = 0x0030, .ghz2 = 0x0030, NOUPLOAD, }, [B2056_RX_TXFBMIX_A] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_TXFBMIX_G] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RXSPARE1] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RXSPARE2] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RXSPARE3] = { .ghz5 = 0x0005, .ghz2 = 0x0005, UPLOAD, }, [B2056_RX_RXSPARE4] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RXSPARE5] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RXSPARE6] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RXSPARE7] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RXSPARE8] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RXSPARE9] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RXSPARE10] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RXSPARE11] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RXSPARE12] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RXSPARE13] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RXSPARE14] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RXSPARE15] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_RXSPARE16] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_STATUS_LNAA_GAIN] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_STATUS_LNAG_GAIN] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_STATUS_MIXTIA_GAIN] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_STATUS_RXLPF_GAIN] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_STATUS_VGA_BUF_GAIN] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_STATUS_RXLPF_Q] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_STATUS_RXLPF_BUF_BW] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_STATUS_RXLPF_VGA_HPC] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_STATUS_RXLPF_RC] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, [B2056_RX_STATUS_HPC_RC] = { .ghz5 = 0x0000, .ghz2 = 0x0000, NOUPLOAD, }, }; static const struct b2056_inittab_entry b2056_inittab_radio_rev11_syn[] = { [B2056_SYN_PLL_PFD] = { .ghz5 = 0x0006, .ghz2 = 0x0006, UPLOAD, }, [B2056_SYN_PLL_CP2] = { .ghz5 = 0x003f, .ghz2 = 0x003f, UPLOAD, }, [B2056_SYN_PLL_LOOPFILTER1] = { .ghz5 = 0x0006, .ghz2 = 0x0006, UPLOAD, }, [B2056_SYN_PLL_LOOPFILTER2] = { .ghz5 = 0x0006, .ghz2 = 0x0006, UPLOAD, }, [B2056_SYN_PLL_LOOPFILTER4] = { .ghz5 = 0x002b, .ghz2 = 0x002b, UPLOAD, }, [B2056_SYN_PLL_VCO2] = { .ghz5 = 0x00f7, .ghz2 = 0x00f7, UPLOAD, }, [B2056_SYN_PLL_VCOCAL12] = { .ghz5 = 0x0007, .ghz2 = 0x0007, UPLOAD, }, [B2056_SYN_LOGENBUF2] = { .ghz5 = 0x008f, .ghz2 = 0x008f, UPLOAD, }, }; static const struct b2056_inittab_entry b2056_inittab_radio_rev11_tx[] = { [B2056_TX_PA_SPARE2] = { .ghz5 = 0x00ee, .ghz2 = 0x00ee, UPLOAD, }, [B2056_TX_INTPAA_IAUX_STAT] = { .ghz5 = 0x0050, .ghz2 = 0x0050, UPLOAD, }, [B2056_TX_INTPAA_IMAIN_STAT] = { .ghz5 = 0x0050, .ghz2 = 0x0050, UPLOAD, }, [B2056_TX_INTPAA_PASLOPE] = { .ghz5 = 0x00f0, .ghz2 = 0x00f0, UPLOAD, }, [B2056_TX_INTPAG_PASLOPE] = { .ghz5 = 0x00f0, .ghz2 = 0x00f0, UPLOAD, }, [B2056_TX_PADA_IDAC] = { .ghz5 = 0x00ff, .ghz2 = 0x00ff, UPLOAD, }, [B2056_TX_PADA_SLOPE] = { .ghz5 = 0x0070, .ghz2 = 0x0070, UPLOAD, }, [B2056_TX_PADG_SLOPE] = { .ghz5 = 0x0070, .ghz2 = 0x0070, UPLOAD, }, [B2056_TX_PGAA_IDAC] = { .ghz5 = 0x00ff, .ghz2 = 0x00ff, UPLOAD, }, [B2056_TX_PGAA_SLOPE] = { .ghz5 = 0x0077, .ghz2 = 0x0077, UPLOAD, }, [B2056_TX_PGAG_SLOPE] = { .ghz5 = 0x0077, .ghz2 = 0x0077, UPLOAD, }, [B2056_TX_GMBB_IDAC] = { .ghz5 = 0x0000, .ghz2 = 0x0000, UPLOAD, }, [B2056_TX_TXSPARE1] = { .ghz5 = 0x0030, .ghz2 = 0x0030, UPLOAD, }, }; static const struct b2056_inittab_entry b2056_inittab_radio_rev11_rx[] = { [B2056_RX_BIASPOLE_LNAA1_IDAC] = { .ghz5 = 0x0017, .ghz2 = 0x0017, UPLOAD, }, [B2056_RX_LNAA2_IDAC] = { .ghz5 = 0x00ff, .ghz2 = 0x00ff, UPLOAD, }, [B2056_RX_BIASPOLE_LNAG1_IDAC] = { .ghz5 = 0x0017, .ghz2 = 0x0017, UPLOAD, }, [B2056_RX_LNAG2_IDAC] = { .ghz5 = 0x00f0, .ghz2 = 0x00f0, UPLOAD, }, [B2056_RX_MIXA_VCM] = { .ghz5 = 0x0055, .ghz2 = 0x0055, UPLOAD, }, [B2056_RX_MIXA_LOB_BIAS] = { .ghz5 = 0x0088, .ghz2 = 0x0088, UPLOAD, }, [B2056_RX_MIXA_BIAS_AUX] = { .ghz5 = 0x0007, .ghz2 = 0x0007, UPLOAD, }, [B2056_RX_MIXG_VCM] = { .ghz5 = 0x0055, .ghz2 = 0x0055, UPLOAD, }, [B2056_RX_TIA_IOPAMP] = { .ghz5 = 0x0026, .ghz2 = 0x0026, UPLOAD, }, [B2056_RX_TIA_QOPAMP] = { .ghz5 = 0x0026, .ghz2 = 0x0026, UPLOAD, }, [B2056_RX_TIA_IMISC] = { .ghz5 = 0x000f, .ghz2 = 0x000f, UPLOAD, }, [B2056_RX_TIA_QMISC] = { .ghz5 = 0x000f, .ghz2 = 0x000f, UPLOAD, }, [B2056_RX_RXLPF_OUTVCM] = { .ghz5 = 0x0004, .ghz2 = 0x0004, UPLOAD, }, [B2056_RX_VGA_BIAS_DCCANCEL] = { .ghz5 = 0x0000, .ghz2 = 0x0000, UPLOAD, }, [B2056_RX_RXSPARE3] = { .ghz5 = 0x0005, .ghz2 = 0x0005, UPLOAD, }, }; #define INITTABSPTS(prefix) \ static const struct b2056_inittabs_pts prefix = { \ .syn = prefix##_syn, \ .syn_length = ARRAY_SIZE(prefix##_syn), \ .tx = prefix##_tx, \ .tx_length = ARRAY_SIZE(prefix##_tx), \ .rx = prefix##_rx, \ .rx_length = ARRAY_SIZE(prefix##_rx), \ } INITTABSPTS(b2056_inittab_phy_rev3); INITTABSPTS(b2056_inittab_phy_rev4); INITTABSPTS(b2056_inittab_radio_rev5); INITTABSPTS(b2056_inittab_radio_rev6); INITTABSPTS(b2056_inittab_radio_rev7_9); INITTABSPTS(b2056_inittab_radio_rev8); INITTABSPTS(b2056_inittab_radio_rev11); #define RADIOREGS3(r00, r01, r02, r03, r04, r05, r06, r07, r08, r09, \ r10, r11, r12, r13, r14, r15, r16, r17, r18, r19, \ r20, r21, r22, r23, r24, r25, r26, r27, r28, r29, \ r30, r31, r32, r33, r34, r35, r36) \ .radio_syn_pll_vcocal1 = r00, \ .radio_syn_pll_vcocal2 = r01, \ .radio_syn_pll_refdiv = r02, \ .radio_syn_pll_mmd2 = r03, \ .radio_syn_pll_mmd1 = r04, \ .radio_syn_pll_loopfilter1 = r05, \ .radio_syn_pll_loopfilter2 = r06, \ .radio_syn_pll_loopfilter3 = r07, \ .radio_syn_pll_loopfilter4 = r08, \ .radio_syn_pll_loopfilter5 = r09, \ .radio_syn_reserved_addr27 = r10, \ .radio_syn_reserved_addr28 = r11, \ .radio_syn_reserved_addr29 = r12, \ .radio_syn_logen_vcobuf1 = r13, \ .radio_syn_logen_mixer2 = r14, \ .radio_syn_logen_buf3 = r15, \ .radio_syn_logen_buf4 = r16, \ .radio_rx0_lnaa_tune = r17, \ .radio_rx0_lnag_tune = r18, \ .radio_tx0_intpaa_boost_tune = r19, \ .radio_tx0_intpag_boost_tune = r20, \ .radio_tx0_pada_boost_tune = r21, \ .radio_tx0_padg_boost_tune = r22, \ .radio_tx0_pgaa_boost_tune = r23, \ .radio_tx0_pgag_boost_tune = r24, \ .radio_tx0_mixa_boost_tune = r25, \ .radio_tx0_mixg_boost_tune = r26, \ .radio_rx1_lnaa_tune = r27, \ .radio_rx1_lnag_tune = r28, \ .radio_tx1_intpaa_boost_tune = r29, \ .radio_tx1_intpag_boost_tune = r30, \ .radio_tx1_pada_boost_tune = r31, \ .radio_tx1_padg_boost_tune = r32, \ .radio_tx1_pgaa_boost_tune = r33, \ .radio_tx1_pgag_boost_tune = r34, \ .radio_tx1_mixa_boost_tune = r35, \ .radio_tx1_mixg_boost_tune = r36 #define PHYREGS(r0, r1, r2, r3, r4, r5) \ .phy_regs.phy_bw1a = r0, \ .phy_regs.phy_bw2 = r1, \ .phy_regs.phy_bw3 = r2, \ .phy_regs.phy_bw4 = r3, \ .phy_regs.phy_bw5 = r4, \ .phy_regs.phy_bw6 = r5 /* http://bcm-v4.sipsolutions.net/802.11/Radio/2056/ChannelTable */ static const struct b43_nphy_channeltab_entry_rev3 b43_nphy_channeltab_phy_rev3[] = { { .freq = 4920, RADIOREGS3(0xff, 0x01, 0x01, 0x01, 0xec, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x00, 0x00, 0x00, 0x8f, 0x0f, 0x00, 0xff, 0xff, 0x00, 0x08, 0x00, 0x7f, 0x00, 0x0b, 0x00, 0xff, 0x00, 0xff, 0x00, 0x08, 0x00, 0x7f, 0x00, 0x0b, 0x00, 0xff, 0x00), PHYREGS(0x07b4, 0x07b0, 0x07ac, 0x0214, 0x0215, 0x0216), }, { .freq = 4930, RADIOREGS3(0xff, 0x01, 0x01, 0x01, 0xed, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x00, 0x00, 0x00, 0x8f, 0x0f, 0x00, 0xff, 0xff, 0x00, 0x08, 0x00, 0x7f, 0x00, 0x0b, 0x00, 0xff, 0x00, 0xff, 0x00, 0x08, 0x00, 0x7f, 0x00, 0x0b, 0x00, 0xff, 0x00), PHYREGS(0x07b8, 0x07b4, 0x07b0, 0x0213, 0x0214, 0x0215), }, { .freq = 4940, RADIOREGS3(0xff, 0x01, 0x01, 0x01, 0xee, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x00, 0x00, 0x00, 0x8f, 0x0f, 0x00, 0xff, 0xff, 0x00, 0x08, 0x00, 0x7f, 0x00, 0x0b, 0x00, 0xff, 0x00, 0xff, 0x00, 0x08, 0x00, 0x7f, 0x00, 0x0b, 0x00, 0xff, 0x00), PHYREGS(0x07bc, 0x07b8, 0x07b4, 0x0212, 0x0213, 0x0214), }, { .freq = 4950, RADIOREGS3(0xff, 0x01, 0x01, 0x01, 0xef, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x00, 0x00, 0x00, 0x8f, 0x0f, 0x00, 0xff, 0xff, 0x00, 0x08, 0x00, 0x7f, 0x00, 0x0b, 0x00, 0xff, 0x00, 0xff, 0x00, 0x08, 0x00, 0x7f, 0x00, 0x0b, 0x00, 0xff, 0x00), PHYREGS(0x07c0, 0x07bc, 0x07b8, 0x0211, 0x0212, 0x0213), }, { .freq = 4960, RADIOREGS3(0xff, 0x01, 0x01, 0x01, 0xf0, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x01, 0x01, 0x01, 0x8f, 0x0f, 0x00, 0xff, 0xff, 0x00, 0x08, 0x00, 0x7f, 0x00, 0x0b, 0x00, 0xff, 0x00, 0xff, 0x00, 0x08, 0x00, 0x7f, 0x00, 0x0b, 0x00, 0xff, 0x00), PHYREGS(0x07c4, 0x07c0, 0x07bc, 0x020f, 0x0211, 0x0212), }, { .freq = 4970, RADIOREGS3(0xff, 0x01, 0x01, 0x01, 0xf1, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x01, 0x01, 0x01, 0x8f, 0x0f, 0x00, 0xff, 0xff, 0x00, 0x08, 0x00, 0x7f, 0x00, 0x0b, 0x00, 0xff, 0x00, 0xff, 0x00, 0x08, 0x00, 0x7f, 0x00, 0x0b, 0x00, 0xff, 0x00), PHYREGS(0x07c8, 0x07c4, 0x07c0, 0x020e, 0x020f, 0x0211), }, { .freq = 4980, RADIOREGS3(0xff, 0x01, 0x01, 0x01, 0xf2, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x01, 0x01, 0x01, 0x8f, 0x0f, 0x00, 0xff, 0xff, 0x00, 0x08, 0x00, 0x7f, 0x00, 0x0b, 0x00, 0xff, 0x00, 0xff, 0x00, 0x08, 0x00, 0x7f, 0x00, 0x0b, 0x00, 0xff, 0x00), PHYREGS(0x07cc, 0x07c8, 0x07c4, 0x020d, 0x020e, 0x020f), }, { .freq = 4990, RADIOREGS3(0xff, 0x01, 0x01, 0x01, 0xf3, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x01, 0x01, 0x01, 0x8f, 0x0f, 0x00, 0xff, 0xff, 0x00, 0x08, 0x00, 0x7f, 0x00, 0x0b, 0x00, 0xff, 0x00, 0xff, 0x00, 0x08, 0x00, 0x7f, 0x00, 0x0b, 0x00, 0xff, 0x00), PHYREGS(0x07d0, 0x07cc, 0x07c8, 0x020c, 0x020d, 0x020e), }, { .freq = 5000, RADIOREGS3(0xff, 0x01, 0x01, 0x01, 0xf4, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x01, 0x01, 0x01, 0x8f, 0x0f, 0x00, 0xff, 0xff, 0x00, 0x07, 0x00, 0x7f, 0x00, 0x0b, 0x00, 0xff, 0x00, 0xff, 0x00, 0x07, 0x00, 0x7f, 0x00, 0x0b, 0x00, 0xff, 0x00), PHYREGS(0x07d4, 0x07d0, 0x07cc, 0x020b, 0x020c, 0x020d), }, { .freq = 5010, RADIOREGS3(0xff, 0x01, 0x01, 0x01, 0xf5, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x01, 0x01, 0x01, 0x8f, 0x0f, 0x00, 0xff, 0xff, 0x00, 0x07, 0x00, 0x7f, 0x00, 0x0b, 0x00, 0xff, 0x00, 0xff, 0x00, 0x07, 0x00, 0x7f, 0x00, 0x0b, 0x00, 0xff, 0x00), PHYREGS(0x07d8, 0x07d4, 0x07d0, 0x020a, 0x020b, 0x020c), }, { .freq = 5020, RADIOREGS3(0xf7, 0x01, 0x01, 0x01, 0xf6, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x01, 0x01, 0x01, 0x8f, 0x0f, 0x00, 0xff, 0xff, 0x00, 0x07, 0x00, 0x7f, 0x00, 0x0b, 0x00, 0xff, 0x00, 0xff, 0x00, 0x07, 0x00, 0x7f, 0x00, 0x0b, 0x00, 0xff, 0x00), PHYREGS(0x07dc, 0x07d8, 0x07d4, 0x0209, 0x020a, 0x020b), }, { .freq = 5030, RADIOREGS3(0xf7, 0x01, 0x01, 0x01, 0xf7, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x01, 0x01, 0x01, 0x8f, 0x0f, 0x00, 0xff, 0xff, 0x00, 0x07, 0x00, 0x7f, 0x00, 0x0b, 0x00, 0xff, 0x00, 0xff, 0x00, 0x07, 0x00, 0x7f, 0x00, 0x0b, 0x00, 0xff, 0x00), PHYREGS(0x07e0, 0x07dc, 0x07d8, 0x0208, 0x0209, 0x020a), }, { .freq = 5040, RADIOREGS3(0xef, 0x01, 0x01, 0x01, 0xf8, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x01, 0x01, 0x01, 0x8f, 0x0f, 0x00, 0xff, 0xff, 0x00, 0x07, 0x00, 0x7f, 0x00, 0x0b, 0x00, 0xff, 0x00, 0xff, 0x00, 0x07, 0x00, 0x7f, 0x00, 0x0b, 0x00, 0xff, 0x00), PHYREGS(0x07e4, 0x07e0, 0x07dc, 0x0207, 0x0208, 0x0209), }, { .freq = 5050, RADIOREGS3(0xef, 0x01, 0x01, 0x01, 0xf9, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x01, 0x01, 0x01, 0x8f, 0x0f, 0x00, 0xff, 0xff, 0x00, 0x07, 0x00, 0x7f, 0x00, 0x0b, 0x00, 0xff, 0x00, 0xff, 0x00, 0x07, 0x00, 0x7f, 0x00, 0x0b, 0x00, 0xff, 0x00), PHYREGS(0x07e8, 0x07e4, 0x07e0, 0x0206, 0x0207, 0x0208), }, { .freq = 5060, RADIOREGS3(0xe6, 0x01, 0x01, 0x01, 0xfa, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x01, 0x01, 0x01, 0x8f, 0x0f, 0x00, 0xff, 0xff, 0x00, 0x07, 0x00, 0x7f, 0x00, 0x0b, 0x00, 0xff, 0x00, 0xff, 0x00, 0x07, 0x00, 0x7f, 0x00, 0x0b, 0x00, 0xff, 0x00), PHYREGS(0x07ec, 0x07e8, 0x07e4, 0x0205, 0x0206, 0x0207), }, { .freq = 5070, RADIOREGS3(0xe6, 0x01, 0x01, 0x01, 0xfb, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x01, 0x01, 0x01, 0x8f, 0x0f, 0x00, 0xff, 0xff, 0x00, 0x07, 0x00, 0x7f, 0x00, 0x0b, 0x00, 0xff, 0x00, 0xff, 0x00, 0x07, 0x00, 0x7f, 0x00, 0x0b, 0x00, 0xff, 0x00), PHYREGS(0x07f0, 0x07ec, 0x07e8, 0x0204, 0x0205, 0x0206), }, { .freq = 5080, RADIOREGS3(0xde, 0x01, 0x01, 0x01, 0xfc, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x01, 0x01, 0x01, 0x8f, 0x0f, 0x00, 0xff, 0xff, 0x00, 0x07, 0x00, 0x7f, 0x00, 0x0b, 0x00, 0xff, 0x00, 0xff, 0x00, 0x07, 0x00, 0x7f, 0x00, 0x0b, 0x00, 0xff, 0x00), PHYREGS(0x07f4, 0x07f0, 0x07ec, 0x0203, 0x0204, 0x0205), }, { .freq = 5090, RADIOREGS3(0xde, 0x01, 0x01, 0x01, 0xfd, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x01, 0x01, 0x01, 0x8f, 0x0f, 0x00, 0xff, 0xff, 0x00, 0x07, 0x00, 0x7f, 0x00, 0x0b, 0x00, 0xff, 0x00, 0xff, 0x00, 0x07, 0x00, 0x7f, 0x00, 0x0b, 0x00, 0xff, 0x00), PHYREGS(0x07f8, 0x07f4, 0x07f0, 0x0202, 0x0203, 0x0204), }, { .freq = 5100, RADIOREGS3(0xd6, 0x01, 0x01, 0x01, 0xfe, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x02, 0x02, 0x02, 0x8f, 0x0f, 0x00, 0xff, 0xff, 0x00, 0x07, 0x00, 0x7f, 0x00, 0x0b, 0x00, 0xff, 0x00, 0xff, 0x00, 0x07, 0x00, 0x7f, 0x00, 0x0b, 0x00, 0xff, 0x00), PHYREGS(0x07fc, 0x07f8, 0x07f4, 0x0201, 0x0202, 0x0203), }, { .freq = 5110, RADIOREGS3(0xd6, 0x01, 0x01, 0x01, 0xff, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x02, 0x02, 0x02, 0x8f, 0x0f, 0x00, 0xff, 0xff, 0x00, 0x07, 0x00, 0x7f, 0x00, 0x0b, 0x00, 0xfc, 0x00, 0xff, 0x00, 0x07, 0x00, 0x7f, 0x00, 0x0b, 0x00, 0xfc, 0x00), PHYREGS(0x0800, 0x07fc, 0x07f8, 0x0200, 0x0201, 0x0202), }, { .freq = 5120, RADIOREGS3(0xce, 0x01, 0x01, 0x02, 0x00, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x02, 0x02, 0x02, 0x8f, 0x0f, 0x00, 0xff, 0xff, 0x00, 0x07, 0x00, 0x7f, 0x00, 0x0b, 0x00, 0xfc, 0x00, 0xff, 0x00, 0x07, 0x00, 0x7f, 0x00, 0x0b, 0x00, 0xfc, 0x00), PHYREGS(0x0804, 0x0800, 0x07fc, 0x01ff, 0x0200, 0x0201), }, { .freq = 5130, RADIOREGS3(0xce, 0x01, 0x01, 0x02, 0x01, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x02, 0x02, 0x02, 0x8f, 0x0f, 0x00, 0xff, 0xff, 0x00, 0x07, 0x00, 0x7f, 0x00, 0x0b, 0x00, 0xfc, 0x00, 0xff, 0x00, 0x07, 0x00, 0x7f, 0x00, 0x0b, 0x00, 0xfc, 0x00), PHYREGS(0x0808, 0x0804, 0x0800, 0x01fe, 0x01ff, 0x0200), }, { .freq = 5140, RADIOREGS3(0xc6, 0x01, 0x01, 0x02, 0x02, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x02, 0x02, 0x02, 0x8f, 0x0f, 0x00, 0xff, 0xff, 0x00, 0x07, 0x00, 0x7f, 0x00, 0x0b, 0x00, 0xfc, 0x00, 0xff, 0x00, 0x07, 0x00, 0x7f, 0x00, 0x0b, 0x00, 0xfc, 0x00), PHYREGS(0x080c, 0x0808, 0x0804, 0x01fd, 0x01fe, 0x01ff), }, { .freq = 5160, RADIOREGS3(0xbe, 0x01, 0x01, 0x02, 0x04, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x02, 0x02, 0x02, 0x8f, 0x0f, 0x00, 0xff, 0xff, 0x00, 0x07, 0x00, 0x7f, 0x00, 0x0b, 0x00, 0xfc, 0x00, 0xff, 0x00, 0x07, 0x00, 0x7f, 0x00, 0x0b, 0x00, 0xfc, 0x00), PHYREGS(0x0814, 0x0810, 0x080c, 0x01fb, 0x01fc, 0x01fd), }, { .freq = 5170, RADIOREGS3(0xbe, 0x01, 0x01, 0x02, 0x05, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x02, 0x02, 0x02, 0x8f, 0x0f, 0x00, 0xff, 0xff, 0x00, 0x07, 0x00, 0x7f, 0x00, 0x0b, 0x00, 0xfc, 0x00, 0xff, 0x00, 0x07, 0x00, 0x7f, 0x00, 0x0b, 0x00, 0xfc, 0x00), PHYREGS(0x0818, 0x0814, 0x0810, 0x01fa, 0x01fb, 0x01fc), }, { .freq = 5180, RADIOREGS3(0xb6, 0x01, 0x01, 0x02, 0x06, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x02, 0x02, 0x02, 0x8f, 0x0f, 0x00, 0xff, 0xef, 0x00, 0x07, 0x00, 0x7f, 0x00, 0x0b, 0x00, 0xfc, 0x00, 0xef, 0x00, 0x07, 0x00, 0x7f, 0x00, 0x0b, 0x00, 0xfc, 0x00), PHYREGS(0x081c, 0x0818, 0x0814, 0x01f9, 0x01fa, 0x01fb), }, { .freq = 5190, RADIOREGS3(0xb6, 0x01, 0x01, 0x02, 0x07, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x02, 0x02, 0x02, 0x8f, 0x0f, 0x00, 0xff, 0xef, 0x00, 0x07, 0x00, 0x7f, 0x00, 0x0b, 0x00, 0xfc, 0x00, 0xef, 0x00, 0x07, 0x00, 0x7f, 0x00, 0x0b, 0x00, 0xfc, 0x00), PHYREGS(0x0820, 0x081c, 0x0818, 0x01f8, 0x01f9, 0x01fa), }, { .freq = 5200, RADIOREGS3(0xaf, 0x01, 0x01, 0x02, 0x08, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x02, 0x02, 0x02, 0x8f, 0x0f, 0x00, 0xff, 0xef, 0x00, 0x06, 0x00, 0x7f, 0x00, 0x0a, 0x00, 0xfc, 0x00, 0xef, 0x00, 0x06, 0x00, 0x7f, 0x00, 0x0a, 0x00, 0xfc, 0x00), PHYREGS(0x0824, 0x0820, 0x081c, 0x01f7, 0x01f8, 0x01f9), }, { .freq = 5210, RADIOREGS3(0xaf, 0x01, 0x01, 0x02, 0x09, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x02, 0x02, 0x02, 0x8f, 0x0f, 0x00, 0xff, 0xdf, 0x00, 0x06, 0x00, 0x7f, 0x00, 0x0a, 0x00, 0xfc, 0x00, 0xdf, 0x00, 0x06, 0x00, 0x7f, 0x00, 0x0a, 0x00, 0xfc, 0x00), PHYREGS(0x0828, 0x0824, 0x0820, 0x01f6, 0x01f7, 0x01f8), }, { .freq = 5220, RADIOREGS3(0xa7, 0x01, 0x01, 0x02, 0x0a, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x02, 0x02, 0x02, 0x8f, 0x0f, 0x00, 0xff, 0xdf, 0x00, 0x06, 0x00, 0x7f, 0x00, 0x0a, 0x00, 0xfc, 0x00, 0xdf, 0x00, 0x06, 0x00, 0x7f, 0x00, 0x0a, 0x00, 0xfc, 0x00), PHYREGS(0x082c, 0x0828, 0x0824, 0x01f5, 0x01f6, 0x01f7), }, { .freq = 5230, RADIOREGS3(0xa7, 0x01, 0x01, 0x02, 0x0b, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x02, 0x02, 0x02, 0x8f, 0x0f, 0x00, 0xff, 0xdf, 0x00, 0x06, 0x00, 0x7f, 0x00, 0x0a, 0x00, 0xfc, 0x00, 0xdf, 0x00, 0x06, 0x00, 0x7f, 0x00, 0x0a, 0x00, 0xfc, 0x00), PHYREGS(0x0830, 0x082c, 0x0828, 0x01f4, 0x01f5, 0x01f6), }, { .freq = 5240, RADIOREGS3(0xa0, 0x01, 0x01, 0x02, 0x0c, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x02, 0x02, 0x02, 0x8f, 0x0f, 0x00, 0xff, 0xcf, 0x00, 0x06, 0x00, 0x7f, 0x00, 0x0a, 0x00, 0xfc, 0x00, 0xcf, 0x00, 0x06, 0x00, 0x7f, 0x00, 0x0a, 0x00, 0xfc, 0x00), PHYREGS(0x0834, 0x0830, 0x082c, 0x01f3, 0x01f4, 0x01f5), }, { .freq = 5250, RADIOREGS3(0xa0, 0x01, 0x01, 0x02, 0x0d, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x02, 0x02, 0x02, 0x8f, 0x0f, 0x00, 0xff, 0xcf, 0x00, 0x06, 0x00, 0x7f, 0x00, 0x0a, 0x00, 0xfc, 0x00, 0xcf, 0x00, 0x06, 0x00, 0x7f, 0x00, 0x0a, 0x00, 0xfc, 0x00), PHYREGS(0x0838, 0x0834, 0x0830, 0x01f2, 0x01f3, 0x01f4), }, { .freq = 5260, RADIOREGS3(0x98, 0x01, 0x01, 0x02, 0x0e, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x02, 0x02, 0x02, 0x8f, 0x0f, 0x00, 0xff, 0xcf, 0x00, 0x06, 0x00, 0x7f, 0x00, 0x0a, 0x00, 0xfc, 0x00, 0xcf, 0x00, 0x06, 0x00, 0x7f, 0x00, 0x0a, 0x00, 0xfc, 0x00), PHYREGS(0x083c, 0x0838, 0x0834, 0x01f1, 0x01f2, 0x01f3), }, { .freq = 5270, RADIOREGS3(0x98, 0x01, 0x01, 0x02, 0x0f, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x03, 0x03, 0x03, 0x8f, 0x0f, 0x00, 0xff, 0xcf, 0x00, 0x06, 0x00, 0x7f, 0x00, 0x0a, 0x00, 0xfc, 0x00, 0xcf, 0x00, 0x06, 0x00, 0x7f, 0x00, 0x0a, 0x00, 0xfc, 0x00), PHYREGS(0x0840, 0x083c, 0x0838, 0x01f0, 0x01f1, 0x01f2), }, { .freq = 5280, RADIOREGS3(0x91, 0x01, 0x01, 0x02, 0x10, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x03, 0x03, 0x03, 0x8f, 0x0f, 0x00, 0xff, 0xbf, 0x00, 0x06, 0x00, 0x7f, 0x00, 0x0a, 0x00, 0xfc, 0x00, 0xbf, 0x00, 0x06, 0x00, 0x7f, 0x00, 0x0a, 0x00, 0xfc, 0x00), PHYREGS(0x0844, 0x0840, 0x083c, 0x01f0, 0x01f0, 0x01f1), }, { .freq = 5290, RADIOREGS3(0x91, 0x01, 0x01, 0x02, 0x11, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x03, 0x03, 0x03, 0x8f, 0x0f, 0x00, 0xff, 0xbf, 0x00, 0x06, 0x00, 0x7f, 0x00, 0x0a, 0x00, 0xfc, 0x00, 0xbf, 0x00, 0x06, 0x00, 0x7f, 0x00, 0x0a, 0x00, 0xfc, 0x00), PHYREGS(0x0848, 0x0844, 0x0840, 0x01ef, 0x01f0, 0x01f0), }, { .freq = 5300, RADIOREGS3(0x8a, 0x01, 0x01, 0x02, 0x12, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x03, 0x03, 0x03, 0x8f, 0x0e, 0x00, 0xff, 0xbf, 0x00, 0x05, 0x00, 0x7f, 0x00, 0x09, 0x00, 0xfc, 0x00, 0xbf, 0x00, 0x05, 0x00, 0x7f, 0x00, 0x09, 0x00, 0xfc, 0x00), PHYREGS(0x084c, 0x0848, 0x0844, 0x01ee, 0x01ef, 0x01f0), }, { .freq = 5310, RADIOREGS3(0x8a, 0x01, 0x01, 0x02, 0x13, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x03, 0x03, 0x03, 0x8f, 0x0e, 0x00, 0xff, 0xbf, 0x00, 0x05, 0x00, 0x7f, 0x00, 0x09, 0x00, 0xfa, 0x00, 0xbf, 0x00, 0x05, 0x00, 0x7f, 0x00, 0x09, 0x00, 0xfa, 0x00), PHYREGS(0x0850, 0x084c, 0x0848, 0x01ed, 0x01ee, 0x01ef), }, { .freq = 5320, RADIOREGS3(0x83, 0x01, 0x01, 0x02, 0x14, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x03, 0x03, 0x03, 0x8f, 0x0e, 0x00, 0xff, 0xbf, 0x00, 0x05, 0x00, 0x7f, 0x00, 0x09, 0x00, 0xfa, 0x00, 0xbf, 0x00, 0x05, 0x00, 0x7f, 0x00, 0x09, 0x00, 0xfa, 0x00), PHYREGS(0x0854, 0x0850, 0x084c, 0x01ec, 0x01ed, 0x01ee), }, { .freq = 5330, RADIOREGS3(0x83, 0x01, 0x01, 0x02, 0x15, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x03, 0x03, 0x03, 0x8f, 0x0e, 0x00, 0xff, 0xaf, 0x00, 0x05, 0x00, 0x7f, 0x00, 0x09, 0x00, 0xfa, 0x00, 0xaf, 0x00, 0x05, 0x00, 0x7f, 0x00, 0x09, 0x00, 0xfa, 0x00), PHYREGS(0x0858, 0x0854, 0x0850, 0x01eb, 0x01ec, 0x01ed), }, { .freq = 5340, RADIOREGS3(0x7c, 0x01, 0x01, 0x02, 0x16, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x03, 0x03, 0x03, 0x8f, 0x0e, 0x00, 0xff, 0xaf, 0x00, 0x05, 0x00, 0x7f, 0x00, 0x09, 0x00, 0xfa, 0x00, 0xaf, 0x00, 0x05, 0x00, 0x7f, 0x00, 0x09, 0x00, 0xfa, 0x00), PHYREGS(0x085c, 0x0858, 0x0854, 0x01ea, 0x01eb, 0x01ec), }, { .freq = 5350, RADIOREGS3(0x7c, 0x01, 0x01, 0x02, 0x17, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x03, 0x03, 0x03, 0x8f, 0x0e, 0x00, 0xff, 0x9f, 0x00, 0x05, 0x00, 0x7f, 0x00, 0x09, 0x00, 0xfa, 0x00, 0x9f, 0x00, 0x05, 0x00, 0x7f, 0x00, 0x09, 0x00, 0xfa, 0x00), PHYREGS(0x0860, 0x085c, 0x0858, 0x01e9, 0x01ea, 0x01eb), }, { .freq = 5360, RADIOREGS3(0x75, 0x01, 0x01, 0x02, 0x18, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x03, 0x03, 0x03, 0x8f, 0x0e, 0x00, 0xff, 0x9f, 0x00, 0x05, 0x00, 0x7f, 0x00, 0x09, 0x00, 0xfa, 0x00, 0x9f, 0x00, 0x05, 0x00, 0x7f, 0x00, 0x09, 0x00, 0xfa, 0x00), PHYREGS(0x0864, 0x0860, 0x085c, 0x01e8, 0x01e9, 0x01ea), }, { .freq = 5370, RADIOREGS3(0x75, 0x01, 0x01, 0x02, 0x19, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x03, 0x03, 0x03, 0x8f, 0x0e, 0x00, 0xff, 0x9f, 0x00, 0x05, 0x00, 0x7f, 0x00, 0x09, 0x00, 0xfa, 0x00, 0x9f, 0x00, 0x05, 0x00, 0x7f, 0x00, 0x09, 0x00, 0xfa, 0x00), PHYREGS(0x0868, 0x0864, 0x0860, 0x01e7, 0x01e8, 0x01e9), }, { .freq = 5380, RADIOREGS3(0x6e, 0x01, 0x01, 0x02, 0x1a, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x03, 0x03, 0x03, 0x8f, 0x0e, 0x00, 0xff, 0x9f, 0x00, 0x05, 0x00, 0x7f, 0x00, 0x09, 0x00, 0xfa, 0x00, 0x9f, 0x00, 0x05, 0x00, 0x7f, 0x00, 0x09, 0x00, 0xfa, 0x00), PHYREGS(0x086c, 0x0868, 0x0864, 0x01e6, 0x01e7, 0x01e8), }, { .freq = 5390, RADIOREGS3(0x6e, 0x01, 0x01, 0x02, 0x1b, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x03, 0x03, 0x03, 0x8f, 0x0e, 0x00, 0xff, 0x8f, 0x00, 0x05, 0x00, 0x7f, 0x00, 0x09, 0x00, 0xfa, 0x00, 0x8f, 0x00, 0x05, 0x00, 0x7f, 0x00, 0x09, 0x00, 0xfa, 0x00), PHYREGS(0x0870, 0x086c, 0x0868, 0x01e5, 0x01e6, 0x01e7), }, { .freq = 5400, RADIOREGS3(0x67, 0x01, 0x01, 0x02, 0x1c, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x03, 0x03, 0x03, 0x8d, 0x0d, 0x00, 0xc8, 0x8f, 0x00, 0x04, 0x00, 0x7f, 0x00, 0x08, 0x00, 0xfa, 0x00, 0x8f, 0x00, 0x04, 0x00, 0x7f, 0x00, 0x08, 0x00, 0xfa, 0x00), PHYREGS(0x0874, 0x0870, 0x086c, 0x01e5, 0x01e5, 0x01e6), }, { .freq = 5410, RADIOREGS3(0x67, 0x01, 0x01, 0x02, 0x1d, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x03, 0x03, 0x03, 0x8d, 0x0d, 0x00, 0xc8, 0x8f, 0x00, 0x04, 0x00, 0x7f, 0x00, 0x08, 0x00, 0xfa, 0x00, 0x8f, 0x00, 0x04, 0x00, 0x7f, 0x00, 0x08, 0x00, 0xfa, 0x00), PHYREGS(0x0878, 0x0874, 0x0870, 0x01e4, 0x01e5, 0x01e5), }, { .freq = 5420, RADIOREGS3(0x61, 0x01, 0x01, 0x02, 0x1e, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x03, 0x03, 0x03, 0x8d, 0x0d, 0x00, 0xc8, 0x8e, 0x00, 0x04, 0x00, 0x7f, 0x00, 0x08, 0x00, 0xfa, 0x00, 0x8e, 0x00, 0x04, 0x00, 0x7f, 0x00, 0x08, 0x00, 0xfa, 0x00), PHYREGS(0x087c, 0x0878, 0x0874, 0x01e3, 0x01e4, 0x01e5), }, { .freq = 5430, RADIOREGS3(0x61, 0x01, 0x01, 0x02, 0x1f, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x03, 0x03, 0x03, 0x8d, 0x0d, 0x00, 0xc8, 0x8e, 0x00, 0x04, 0x00, 0x7f, 0x00, 0x08, 0x00, 0xfa, 0x00, 0x8e, 0x00, 0x04, 0x00, 0x7f, 0x00, 0x08, 0x00, 0xfa, 0x00), PHYREGS(0x0880, 0x087c, 0x0878, 0x01e2, 0x01e3, 0x01e4), }, { .freq = 5440, RADIOREGS3(0x5a, 0x01, 0x01, 0x02, 0x20, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x04, 0x04, 0x04, 0x8d, 0x0d, 0x00, 0xc8, 0x7e, 0x00, 0x04, 0x00, 0x7f, 0x00, 0x08, 0x00, 0xfa, 0x00, 0x7e, 0x00, 0x04, 0x00, 0x7f, 0x00, 0x08, 0x00, 0xfa, 0x00), PHYREGS(0x0884, 0x0880, 0x087c, 0x01e1, 0x01e2, 0x01e3), }, { .freq = 5450, RADIOREGS3(0x5a, 0x01, 0x01, 0x02, 0x21, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x04, 0x04, 0x04, 0x8d, 0x0d, 0x00, 0xc8, 0x7d, 0x00, 0x04, 0x00, 0x7f, 0x00, 0x08, 0x00, 0xfa, 0x00, 0x7d, 0x00, 0x04, 0x00, 0x7f, 0x00, 0x08, 0x00, 0xfa, 0x00), PHYREGS(0x0888, 0x0884, 0x0880, 0x01e0, 0x01e1, 0x01e2), }, { .freq = 5460, RADIOREGS3(0x53, 0x01, 0x01, 0x02, 0x22, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x04, 0x04, 0x04, 0x8d, 0x0d, 0x00, 0xc8, 0x6d, 0x00, 0x04, 0x00, 0x7f, 0x00, 0x08, 0x00, 0xf8, 0x00, 0x6d, 0x00, 0x04, 0x00, 0x7f, 0x00, 0x08, 0x00, 0xf8, 0x00), PHYREGS(0x088c, 0x0888, 0x0884, 0x01df, 0x01e0, 0x01e1), }, { .freq = 5470, RADIOREGS3(0x53, 0x01, 0x01, 0x02, 0x23, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x04, 0x04, 0x04, 0x8d, 0x0d, 0x00, 0xc8, 0x6d, 0x00, 0x04, 0x00, 0x7f, 0x00, 0x08, 0x00, 0xf8, 0x00, 0x6d, 0x00, 0x04, 0x00, 0x7f, 0x00, 0x08, 0x00, 0xf8, 0x00), PHYREGS(0x0890, 0x088c, 0x0888, 0x01de, 0x01df, 0x01e0), }, { .freq = 5480, RADIOREGS3(0x4d, 0x01, 0x01, 0x02, 0x24, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x04, 0x04, 0x04, 0x8d, 0x0d, 0x00, 0xc8, 0x5d, 0x00, 0x04, 0x00, 0x7f, 0x00, 0x08, 0x00, 0xf8, 0x00, 0x5d, 0x00, 0x04, 0x00, 0x7f, 0x00, 0x08, 0x00, 0xf8, 0x00), PHYREGS(0x0894, 0x0890, 0x088c, 0x01dd, 0x01de, 0x01df), }, { .freq = 5490, RADIOREGS3(0x4d, 0x01, 0x01, 0x02, 0x25, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x04, 0x04, 0x04, 0x8d, 0x0d, 0x00, 0xc8, 0x5c, 0x00, 0x04, 0x00, 0x7f, 0x00, 0x08, 0x00, 0xf8, 0x00, 0x5c, 0x00, 0x04, 0x00, 0x7f, 0x00, 0x08, 0x00, 0xf8, 0x00), PHYREGS(0x0898, 0x0894, 0x0890, 0x01dd, 0x01dd, 0x01de), }, { .freq = 5500, RADIOREGS3(0x47, 0x01, 0x01, 0x02, 0x26, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x04, 0x04, 0x04, 0x8d, 0x0b, 0x00, 0x84, 0x5c, 0x00, 0x03, 0x00, 0x7f, 0x00, 0x07, 0x00, 0xf8, 0x00, 0x5c, 0x00, 0x03, 0x00, 0x7f, 0x00, 0x07, 0x00, 0xf8, 0x00), PHYREGS(0x089c, 0x0898, 0x0894, 0x01dc, 0x01dd, 0x01dd), }, { .freq = 5510, RADIOREGS3(0x47, 0x01, 0x01, 0x02, 0x27, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x04, 0x04, 0x04, 0x8d, 0x0b, 0x00, 0x84, 0x4c, 0x00, 0x03, 0x00, 0x7f, 0x00, 0x07, 0x00, 0xf8, 0x00, 0x4c, 0x00, 0x03, 0x00, 0x7f, 0x00, 0x07, 0x00, 0xf8, 0x00), PHYREGS(0x08a0, 0x089c, 0x0898, 0x01db, 0x01dc, 0x01dd), }, { .freq = 5520, RADIOREGS3(0x40, 0x01, 0x01, 0x02, 0x28, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x04, 0x04, 0x04, 0x8d, 0x0b, 0x00, 0x84, 0x4c, 0x00, 0x03, 0x00, 0x7f, 0x00, 0x07, 0x00, 0xf8, 0x00, 0x4c, 0x00, 0x03, 0x00, 0x7f, 0x00, 0x07, 0x00, 0xf8, 0x00), PHYREGS(0x08a4, 0x08a0, 0x089c, 0x01da, 0x01db, 0x01dc), }, { .freq = 5530, RADIOREGS3(0x40, 0x01, 0x01, 0x02, 0x29, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x04, 0x04, 0x04, 0x8d, 0x0b, 0x00, 0x84, 0x3b, 0x00, 0x03, 0x00, 0x7f, 0x00, 0x07, 0x00, 0xf8, 0x00, 0x3b, 0x00, 0x03, 0x00, 0x7f, 0x00, 0x07, 0x00, 0xf8, 0x00), PHYREGS(0x08a8, 0x08a4, 0x08a0, 0x01d9, 0x01da, 0x01db), }, { .freq = 5540, RADIOREGS3(0x3a, 0x01, 0x01, 0x02, 0x2a, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x04, 0x04, 0x04, 0x8d, 0x0b, 0x00, 0x84, 0x3b, 0x00, 0x03, 0x00, 0x7f, 0x00, 0x07, 0x00, 0xf8, 0x00, 0x3b, 0x00, 0x03, 0x00, 0x7f, 0x00, 0x07, 0x00, 0xf8, 0x00), PHYREGS(0x08ac, 0x08a8, 0x08a4, 0x01d8, 0x01d9, 0x01da), }, { .freq = 5550, RADIOREGS3(0x3a, 0x01, 0x01, 0x02, 0x2b, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x04, 0x04, 0x04, 0x8d, 0x0b, 0x00, 0x84, 0x3b, 0x00, 0x03, 0x00, 0x7f, 0x00, 0x07, 0x00, 0xf8, 0x00, 0x3b, 0x00, 0x03, 0x00, 0x7f, 0x00, 0x07, 0x00, 0xf8, 0x00), PHYREGS(0x08b0, 0x08ac, 0x08a8, 0x01d7, 0x01d8, 0x01d9), }, { .freq = 5560, RADIOREGS3(0x34, 0x01, 0x01, 0x02, 0x2c, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x04, 0x04, 0x04, 0x8d, 0x0b, 0x00, 0x84, 0x2b, 0x00, 0x03, 0x00, 0x7f, 0x00, 0x07, 0x00, 0xf8, 0x00, 0x2b, 0x00, 0x03, 0x00, 0x7f, 0x00, 0x07, 0x00, 0xf8, 0x00), PHYREGS(0x08b4, 0x08b0, 0x08ac, 0x01d7, 0x01d7, 0x01d8), }, { .freq = 5570, RADIOREGS3(0x34, 0x01, 0x01, 0x02, 0x2d, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x04, 0x04, 0x04, 0x8d, 0x0b, 0x00, 0x84, 0x2a, 0x00, 0x03, 0x00, 0x7f, 0x00, 0x07, 0x00, 0xf8, 0x00, 0x2a, 0x00, 0x03, 0x00, 0x7f, 0x00, 0x07, 0x00, 0xf8, 0x00), PHYREGS(0x08b8, 0x08b4, 0x08b0, 0x01d6, 0x01d7, 0x01d7), }, { .freq = 5580, RADIOREGS3(0x2e, 0x01, 0x01, 0x02, 0x2e, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x04, 0x04, 0x04, 0x8d, 0x0b, 0x00, 0x84, 0x1a, 0x00, 0x03, 0x00, 0x7f, 0x00, 0x07, 0x00, 0xf8, 0x00, 0x1a, 0x00, 0x03, 0x00, 0x7f, 0x00, 0x07, 0x00, 0xf8, 0x00), PHYREGS(0x08bc, 0x08b8, 0x08b4, 0x01d5, 0x01d6, 0x01d7), }, { .freq = 5590, RADIOREGS3(0x2e, 0x01, 0x01, 0x02, 0x2f, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x04, 0x04, 0x04, 0x8d, 0x0b, 0x00, 0x84, 0x1a, 0x00, 0x03, 0x00, 0x7f, 0x00, 0x07, 0x00, 0xf8, 0x00, 0x1a, 0x00, 0x03, 0x00, 0x7f, 0x00, 0x07, 0x00, 0xf8, 0x00), PHYREGS(0x08c0, 0x08bc, 0x08b8, 0x01d4, 0x01d5, 0x01d6), }, { .freq = 5600, RADIOREGS3(0x28, 0x01, 0x01, 0x02, 0x30, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x05, 0x05, 0x05, 0x8b, 0x09, 0x00, 0x70, 0x1a, 0x00, 0x03, 0x00, 0x7f, 0x00, 0x07, 0x00, 0xf8, 0x00, 0x1a, 0x00, 0x03, 0x00, 0x7f, 0x00, 0x07, 0x00, 0xf8, 0x00), PHYREGS(0x08c4, 0x08c0, 0x08bc, 0x01d3, 0x01d4, 0x01d5), }, { .freq = 5610, RADIOREGS3(0x28, 0x01, 0x01, 0x02, 0x31, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x05, 0x05, 0x05, 0x8b, 0x09, 0x00, 0x70, 0x19, 0x00, 0x03, 0x00, 0x7f, 0x00, 0x07, 0x00, 0xf8, 0x00, 0x19, 0x00, 0x03, 0x00, 0x7f, 0x00, 0x07, 0x00, 0xf8, 0x00), PHYREGS(0x08c8, 0x08c4, 0x08c0, 0x01d2, 0x01d3, 0x01d4), }, { .freq = 5620, RADIOREGS3(0x21, 0x01, 0x01, 0x02, 0x32, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x05, 0x05, 0x05, 0x8b, 0x09, 0x00, 0x70, 0x19, 0x00, 0x03, 0x00, 0x7f, 0x00, 0x07, 0x00, 0xf8, 0x00, 0x19, 0x00, 0x03, 0x00, 0x7f, 0x00, 0x07, 0x00, 0xf8, 0x00), PHYREGS(0x08cc, 0x08c8, 0x08c4, 0x01d2, 0x01d2, 0x01d3), }, { .freq = 5630, RADIOREGS3(0x21, 0x01, 0x01, 0x02, 0x33, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x05, 0x05, 0x05, 0x8b, 0x09, 0x00, 0x70, 0x09, 0x00, 0x03, 0x00, 0x7f, 0x00, 0x07, 0x00, 0xf8, 0x00, 0x09, 0x00, 0x03, 0x00, 0x7f, 0x00, 0x07, 0x00, 0xf8, 0x00), PHYREGS(0x08d0, 0x08cc, 0x08c8, 0x01d1, 0x01d2, 0x01d2), }, { .freq = 5640, RADIOREGS3(0x1c, 0x01, 0x01, 0x02, 0x34, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x05, 0x05, 0x05, 0x8b, 0x09, 0x00, 0x70, 0x09, 0x00, 0x03, 0x00, 0x7f, 0x00, 0x07, 0x00, 0xf8, 0x00, 0x09, 0x00, 0x03, 0x00, 0x7f, 0x00, 0x07, 0x00, 0xf8, 0x00), PHYREGS(0x08d4, 0x08d0, 0x08cc, 0x01d0, 0x01d1, 0x01d2), }, { .freq = 5650, RADIOREGS3(0x1c, 0x01, 0x01, 0x02, 0x35, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x05, 0x05, 0x05, 0x8b, 0x09, 0x00, 0x70, 0x08, 0x00, 0x03, 0x00, 0x7f, 0x00, 0x07, 0x00, 0xf8, 0x00, 0x08, 0x00, 0x03, 0x00, 0x7f, 0x00, 0x07, 0x00, 0xf8, 0x00), PHYREGS(0x08d8, 0x08d4, 0x08d0, 0x01cf, 0x01d0, 0x01d1), }, { .freq = 5660, RADIOREGS3(0x16, 0x01, 0x01, 0x02, 0x36, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x05, 0x05, 0x05, 0x8b, 0x09, 0x00, 0x70, 0x08, 0x00, 0x03, 0x00, 0x7f, 0x00, 0x07, 0x00, 0xf6, 0x00, 0x08, 0x00, 0x03, 0x00, 0x7f, 0x00, 0x07, 0x00, 0xf6, 0x00), PHYREGS(0x08dc, 0x08d8, 0x08d4, 0x01ce, 0x01cf, 0x01d0), }, { .freq = 5670, RADIOREGS3(0x16, 0x01, 0x01, 0x02, 0x37, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x05, 0x05, 0x05, 0x8b, 0x09, 0x00, 0x70, 0x08, 0x00, 0x03, 0x00, 0x7f, 0x00, 0x07, 0x00, 0xf6, 0x00, 0x08, 0x00, 0x03, 0x00, 0x7f, 0x00, 0x07, 0x00, 0xf6, 0x00), PHYREGS(0x08e0, 0x08dc, 0x08d8, 0x01ce, 0x01ce, 0x01cf), }, { .freq = 5680, RADIOREGS3(0x10, 0x01, 0x01, 0x02, 0x38, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x05, 0x05, 0x05, 0x8b, 0x09, 0x00, 0x70, 0x08, 0x00, 0x03, 0x00, 0x7f, 0x00, 0x07, 0x00, 0xf6, 0x00, 0x08, 0x00, 0x03, 0x00, 0x7f, 0x00, 0x07, 0x00, 0xf6, 0x00), PHYREGS(0x08e4, 0x08e0, 0x08dc, 0x01cd, 0x01ce, 0x01ce), }, { .freq = 5690, RADIOREGS3(0x10, 0x01, 0x01, 0x02, 0x39, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x05, 0x05, 0x05, 0x8b, 0x09, 0x00, 0x70, 0x07, 0x00, 0x03, 0x00, 0x7f, 0x00, 0x07, 0x00, 0xf6, 0x00, 0x07, 0x00, 0x03, 0x00, 0x7f, 0x00, 0x07, 0x00, 0xf6, 0x00), PHYREGS(0x08e8, 0x08e4, 0x08e0, 0x01cc, 0x01cd, 0x01ce), }, { .freq = 5700, RADIOREGS3(0x0a, 0x01, 0x01, 0x02, 0x3a, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x05, 0x05, 0x05, 0x8a, 0x06, 0x00, 0x40, 0x07, 0x00, 0x02, 0x00, 0x7f, 0x00, 0x06, 0x00, 0xf6, 0x00, 0x07, 0x00, 0x02, 0x00, 0x7f, 0x00, 0x06, 0x00, 0xf6, 0x00), PHYREGS(0x08ec, 0x08e8, 0x08e4, 0x01cb, 0x01cc, 0x01cd), }, { .freq = 5710, RADIOREGS3(0x0a, 0x01, 0x01, 0x02, 0x3b, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x05, 0x05, 0x05, 0x8a, 0x06, 0x00, 0x40, 0x07, 0x00, 0x02, 0x00, 0x7f, 0x00, 0x06, 0x00, 0xf4, 0x00, 0x07, 0x00, 0x02, 0x00, 0x7f, 0x00, 0x06, 0x00, 0xf4, 0x00), PHYREGS(0x08f0, 0x08ec, 0x08e8, 0x01ca, 0x01cb, 0x01cc), }, { .freq = 5720, RADIOREGS3(0x0a, 0x01, 0x01, 0x02, 0x3c, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x05, 0x05, 0x05, 0x8a, 0x06, 0x00, 0x40, 0x07, 0x00, 0x02, 0x00, 0x7f, 0x00, 0x06, 0x00, 0xf4, 0x00, 0x07, 0x00, 0x02, 0x00, 0x7f, 0x00, 0x06, 0x00, 0xf4, 0x00), PHYREGS(0x08f4, 0x08f0, 0x08ec, 0x01c9, 0x01ca, 0x01cb), }, { .freq = 5725, RADIOREGS3(0x03, 0x01, 0x02, 0x04, 0x79, 0x07, 0x07, 0x04, 0x10, 0x01, 0x05, 0x05, 0x05, 0x8a, 0x06, 0x00, 0x40, 0x06, 0x00, 0x02, 0x00, 0x7f, 0x00, 0x06, 0x00, 0xf4, 0x00, 0x06, 0x00, 0x02, 0x00, 0x7f, 0x00, 0x06, 0x00, 0xf4, 0x00), PHYREGS(0x08f6, 0x08f2, 0x08ee, 0x01c9, 0x01ca, 0x01cb), }, { .freq = 5730, RADIOREGS3(0x0a, 0x01, 0x01, 0x02, 0x3d, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x05, 0x05, 0x05, 0x8a, 0x06, 0x00, 0x40, 0x06, 0x00, 0x02, 0x00, 0x7f, 0x00, 0x06, 0x00, 0xf4, 0x00, 0x06, 0x00, 0x02, 0x00, 0x7f, 0x00, 0x06, 0x00, 0xf4, 0x00), PHYREGS(0x08f8, 0x08f4, 0x08f0, 0x01c9, 0x01c9, 0x01ca), }, { .freq = 5735, RADIOREGS3(0x03, 0x01, 0x02, 0x04, 0x7b, 0x07, 0x07, 0x04, 0x10, 0x01, 0x05, 0x05, 0x05, 0x8a, 0x06, 0x00, 0x40, 0x06, 0x00, 0x02, 0x00, 0x7f, 0x00, 0x06, 0x00, 0xf4, 0x00, 0x06, 0x00, 0x02, 0x00, 0x7f, 0x00, 0x06, 0x00, 0xf4, 0x00), PHYREGS(0x08fa, 0x08f6, 0x08f2, 0x01c8, 0x01c9, 0x01ca), }, { .freq = 5740, RADIOREGS3(0x0a, 0x01, 0x01, 0x02, 0x3e, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x05, 0x05, 0x05, 0x8a, 0x06, 0x00, 0x40, 0x06, 0x00, 0x02, 0x00, 0x7f, 0x00, 0x06, 0x00, 0xf4, 0x00, 0x06, 0x00, 0x02, 0x00, 0x7f, 0x00, 0x06, 0x00, 0xf4, 0x00), PHYREGS(0x08fc, 0x08f8, 0x08f4, 0x01c8, 0x01c9, 0x01c9), }, { .freq = 5745, RADIOREGS3(0xfe, 0x00, 0x02, 0x04, 0x7d, 0x07, 0x07, 0x04, 0x10, 0x01, 0x05, 0x05, 0x05, 0x8a, 0x06, 0x00, 0x40, 0x06, 0x00, 0x02, 0x00, 0x7f, 0x00, 0x06, 0x00, 0xf4, 0x00, 0x06, 0x00, 0x02, 0x00, 0x7f, 0x00, 0x06, 0x00, 0xf4, 0x00), PHYREGS(0x08fe, 0x08fa, 0x08f6, 0x01c8, 0x01c8, 0x01c9), }, { .freq = 5750, RADIOREGS3(0x0a, 0x01, 0x01, 0x02, 0x3f, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x05, 0x05, 0x05, 0x8a, 0x06, 0x00, 0x40, 0x06, 0x00, 0x02, 0x00, 0x7f, 0x00, 0x06, 0x00, 0xf4, 0x00, 0x06, 0x00, 0x02, 0x00, 0x7f, 0x00, 0x06, 0x00, 0xf4, 0x00), PHYREGS(0x0900, 0x08fc, 0x08f8, 0x01c7, 0x01c8, 0x01c9), }, { .freq = 5755, RADIOREGS3(0xfe, 0x00, 0x02, 0x04, 0x7f, 0x07, 0x07, 0x04, 0x10, 0x01, 0x05, 0x05, 0x05, 0x8a, 0x06, 0x00, 0x40, 0x05, 0x00, 0x02, 0x00, 0x7f, 0x00, 0x06, 0x00, 0xf4, 0x00, 0x05, 0x00, 0x02, 0x00, 0x7f, 0x00, 0x06, 0x00, 0xf4, 0x00), PHYREGS(0x0902, 0x08fe, 0x08fa, 0x01c7, 0x01c8, 0x01c8), }, { .freq = 5760, RADIOREGS3(0x0a, 0x01, 0x01, 0x02, 0x40, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x05, 0x05, 0x05, 0x8a, 0x06, 0x00, 0x40, 0x05, 0x00, 0x02, 0x00, 0x7f, 0x00, 0x06, 0x00, 0xf4, 0x00, 0x05, 0x00, 0x02, 0x00, 0x7f, 0x00, 0x06, 0x00, 0xf4, 0x00), PHYREGS(0x0904, 0x0900, 0x08fc, 0x01c6, 0x01c7, 0x01c8), }, { .freq = 5765, RADIOREGS3(0xf8, 0x00, 0x02, 0x04, 0x81, 0x07, 0x07, 0x04, 0x10, 0x01, 0x05, 0x05, 0x05, 0x8a, 0x06, 0x00, 0x40, 0x05, 0x00, 0x02, 0x00, 0x7f, 0x00, 0x06, 0x00, 0xf4, 0x00, 0x05, 0x00, 0x02, 0x00, 0x7f, 0x00, 0x06, 0x00, 0xf4, 0x00), PHYREGS(0x0906, 0x0902, 0x08fe, 0x01c6, 0x01c7, 0x01c8), }, { .freq = 5770, RADIOREGS3(0x0a, 0x01, 0x01, 0x02, 0x41, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x05, 0x05, 0x05, 0x8a, 0x06, 0x00, 0x40, 0x05, 0x00, 0x02, 0x00, 0x7f, 0x00, 0x06, 0x00, 0xf4, 0x00, 0x05, 0x00, 0x02, 0x00, 0x7f, 0x00, 0x06, 0x00, 0xf4, 0x00), PHYREGS(0x0908, 0x0904, 0x0900, 0x01c6, 0x01c6, 0x01c7), }, { .freq = 5775, RADIOREGS3(0xf8, 0x00, 0x02, 0x04, 0x83, 0x07, 0x07, 0x04, 0x10, 0x01, 0x05, 0x05, 0x05, 0x8a, 0x06, 0x00, 0x40, 0x05, 0x00, 0x02, 0x00, 0x7f, 0x00, 0x06, 0x00, 0xf4, 0x00, 0x05, 0x00, 0x02, 0x00, 0x7f, 0x00, 0x06, 0x00, 0xf4, 0x00), PHYREGS(0x090a, 0x0906, 0x0902, 0x01c5, 0x01c6, 0x01c7), }, { .freq = 5780, RADIOREGS3(0x0a, 0x01, 0x01, 0x02, 0x42, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x05, 0x05, 0x05, 0x8a, 0x06, 0x00, 0x40, 0x05, 0x00, 0x02, 0x00, 0x7f, 0x00, 0x06, 0x00, 0xf4, 0x00, 0x05, 0x00, 0x02, 0x00, 0x7f, 0x00, 0x06, 0x00, 0xf4, 0x00), PHYREGS(0x090c, 0x0908, 0x0904, 0x01c5, 0x01c6, 0x01c6), }, { .freq = 5785, RADIOREGS3(0xf2, 0x00, 0x02, 0x04, 0x85, 0x07, 0x07, 0x04, 0x10, 0x01, 0x06, 0x06, 0x06, 0x8a, 0x06, 0x00, 0x40, 0x04, 0x00, 0x02, 0x00, 0x7f, 0x00, 0x06, 0x00, 0xf4, 0x00, 0x04, 0x00, 0x02, 0x00, 0x7f, 0x00, 0x06, 0x00, 0xf4, 0x00), PHYREGS(0x090e, 0x090a, 0x0906, 0x01c4, 0x01c5, 0x01c6), }, { .freq = 5790, RADIOREGS3(0x0a, 0x01, 0x01, 0x02, 0x43, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x06, 0x06, 0x06, 0x8a, 0x06, 0x00, 0x40, 0x04, 0x00, 0x02, 0x00, 0x7f, 0x00, 0x06, 0x00, 0xf4, 0x00, 0x04, 0x00, 0x02, 0x00, 0x7f, 0x00, 0x06, 0x00, 0xf4, 0x00), PHYREGS(0x0910, 0x090c, 0x0908, 0x01c4, 0x01c5, 0x01c6), }, { .freq = 5795, RADIOREGS3(0xf2, 0x00, 0x02, 0x04, 0x87, 0x07, 0x07, 0x04, 0x10, 0x01, 0x06, 0x06, 0x06, 0x8a, 0x06, 0x00, 0x40, 0x04, 0x00, 0x02, 0x00, 0x7f, 0x00, 0x06, 0x00, 0xf4, 0x00, 0x04, 0x00, 0x02, 0x00, 0x7f, 0x00, 0x06, 0x00, 0xf4, 0x00), PHYREGS(0x0912, 0x090e, 0x090a, 0x01c4, 0x01c4, 0x01c5), }, { .freq = 5800, RADIOREGS3(0x0a, 0x01, 0x01, 0x02, 0x44, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x06, 0x06, 0x06, 0x88, 0x04, 0x00, 0x20, 0x04, 0x00, 0x00, 0x00, 0x7f, 0x00, 0x06, 0x00, 0xf4, 0x00, 0x04, 0x00, 0x00, 0x00, 0x7f, 0x00, 0x06, 0x00, 0xf4, 0x00), PHYREGS(0x0914, 0x0910, 0x090c, 0x01c3, 0x01c4, 0x01c5), }, { .freq = 5805, RADIOREGS3(0xed, 0x00, 0x02, 0x04, 0x89, 0x07, 0x07, 0x04, 0x10, 0x01, 0x06, 0x06, 0x06, 0x88, 0x04, 0x00, 0x20, 0x04, 0x00, 0x00, 0x00, 0x7f, 0x00, 0x06, 0x00, 0xf4, 0x00, 0x04, 0x00, 0x00, 0x00, 0x7f, 0x00, 0x06, 0x00, 0xf4, 0x00), PHYREGS(0x0916, 0x0912, 0x090e, 0x01c3, 0x01c4, 0x01c4), }, { .freq = 5810, RADIOREGS3(0x0a, 0x01, 0x01, 0x02, 0x45, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x06, 0x06, 0x06, 0x88, 0x04, 0x00, 0x20, 0x04, 0x00, 0x00, 0x00, 0x7f, 0x00, 0x06, 0x00, 0xf4, 0x00, 0x04, 0x00, 0x00, 0x00, 0x7f, 0x00, 0x06, 0x00, 0xf4, 0x00), PHYREGS(0x0918, 0x0914, 0x0910, 0x01c2, 0x01c3, 0x01c4), }, { .freq = 5815, RADIOREGS3(0xed, 0x00, 0x02, 0x04, 0x8b, 0x07, 0x07, 0x04, 0x10, 0x01, 0x06, 0x06, 0x06, 0x88, 0x04, 0x00, 0x20, 0x04, 0x00, 0x00, 0x00, 0x7f, 0x00, 0x06, 0x00, 0xf4, 0x00, 0x04, 0x00, 0x00, 0x00, 0x7f, 0x00, 0x06, 0x00, 0xf4, 0x00), PHYREGS(0x091a, 0x0916, 0x0912, 0x01c2, 0x01c3, 0x01c4), }, { .freq = 5820, RADIOREGS3(0x0a, 0x01, 0x01, 0x02, 0x46, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x06, 0x06, 0x06, 0x88, 0x04, 0x00, 0x20, 0x03, 0x00, 0x00, 0x00, 0x7f, 0x00, 0x06, 0x00, 0xf4, 0x00, 0x03, 0x00, 0x00, 0x00, 0x7f, 0x00, 0x06, 0x00, 0xf4, 0x00), PHYREGS(0x091c, 0x0918, 0x0914, 0x01c2, 0x01c2, 0x01c3), }, { .freq = 5825, RADIOREGS3(0xed, 0x00, 0x02, 0x04, 0x8d, 0x07, 0x07, 0x04, 0x10, 0x01, 0x06, 0x06, 0x06, 0x88, 0x04, 0x00, 0x20, 0x03, 0x00, 0x00, 0x00, 0x7f, 0x00, 0x06, 0x00, 0xf4, 0x00, 0x03, 0x00, 0x00, 0x00, 0x7f, 0x00, 0x06, 0x00, 0xf4, 0x00), PHYREGS(0x091e, 0x091a, 0x0916, 0x01c1, 0x01c2, 0x01c3), }, { .freq = 5830, RADIOREGS3(0x0a, 0x01, 0x01, 0x02, 0x47, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x06, 0x06, 0x06, 0x88, 0x04, 0x00, 0x20, 0x03, 0x00, 0x00, 0x00, 0x7f, 0x00, 0x06, 0x00, 0xf4, 0x00, 0x03, 0x00, 0x00, 0x00, 0x7f, 0x00, 0x06, 0x00, 0xf4, 0x00), PHYREGS(0x0920, 0x091c, 0x0918, 0x01c1, 0x01c2, 0x01c2), }, { .freq = 5840, RADIOREGS3(0x0a, 0x01, 0x01, 0x02, 0x48, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x06, 0x06, 0x06, 0x88, 0x04, 0x00, 0x20, 0x03, 0x00, 0x00, 0x00, 0x7f, 0x00, 0x06, 0x00, 0xf4, 0x00, 0x03, 0x00, 0x00, 0x00, 0x7f, 0x00, 0x06, 0x00, 0xf4, 0x00), PHYREGS(0x0924, 0x0920, 0x091c, 0x01c0, 0x01c1, 0x01c2), }, { .freq = 5850, RADIOREGS3(0xe0, 0x00, 0x01, 0x02, 0x49, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x06, 0x06, 0x06, 0x88, 0x04, 0x00, 0x20, 0x03, 0x00, 0x00, 0x00, 0x7f, 0x00, 0x06, 0x00, 0xf4, 0x00, 0x03, 0x00, 0x00, 0x00, 0x7f, 0x00, 0x06, 0x00, 0xf4, 0x00), PHYREGS(0x0928, 0x0924, 0x0920, 0x01bf, 0x01c0, 0x01c1), }, { .freq = 5860, RADIOREGS3(0xde, 0x00, 0x01, 0x02, 0x4a, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x06, 0x06, 0x06, 0x88, 0x04, 0x00, 0x20, 0x03, 0x00, 0x00, 0x00, 0x7f, 0x00, 0x06, 0x00, 0xf2, 0x00, 0x03, 0x00, 0x00, 0x00, 0x7f, 0x00, 0x06, 0x00, 0xf2, 0x00), PHYREGS(0x092c, 0x0928, 0x0924, 0x01bf, 0x01bf, 0x01c0), }, { .freq = 5870, RADIOREGS3(0xdb, 0x00, 0x01, 0x02, 0x4b, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x06, 0x06, 0x06, 0x88, 0x04, 0x00, 0x20, 0x02, 0x00, 0x00, 0x00, 0x7f, 0x00, 0x06, 0x00, 0xf2, 0x00, 0x02, 0x00, 0x00, 0x00, 0x7f, 0x00, 0x06, 0x00, 0xf2, 0x00), PHYREGS(0x0930, 0x092c, 0x0928, 0x01be, 0x01bf, 0x01bf), }, { .freq = 5880, RADIOREGS3(0xd8, 0x00, 0x01, 0x02, 0x4c, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x06, 0x06, 0x06, 0x88, 0x04, 0x00, 0x20, 0x02, 0x00, 0x00, 0x00, 0x7f, 0x00, 0x06, 0x00, 0xf2, 0x00, 0x02, 0x00, 0x00, 0x00, 0x7f, 0x00, 0x06, 0x00, 0xf2, 0x00), PHYREGS(0x0934, 0x0930, 0x092c, 0x01bd, 0x01be, 0x01bf), }, { .freq = 5890, RADIOREGS3(0xd6, 0x00, 0x01, 0x02, 0x4d, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x06, 0x06, 0x06, 0x88, 0x04, 0x00, 0x20, 0x02, 0x00, 0x00, 0x00, 0x7f, 0x00, 0x06, 0x00, 0xf2, 0x00, 0x02, 0x00, 0x00, 0x00, 0x7f, 0x00, 0x06, 0x00, 0xf2, 0x00), PHYREGS(0x0938, 0x0934, 0x0930, 0x01bc, 0x01bd, 0x01be), }, { .freq = 5900, RADIOREGS3(0xd3, 0x00, 0x01, 0x02, 0x4e, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x06, 0x06, 0x06, 0x87, 0x03, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x7f, 0x00, 0x05, 0x00, 0xf2, 0x00, 0x02, 0x00, 0x00, 0x00, 0x7f, 0x00, 0x05, 0x00, 0xf2, 0x00), PHYREGS(0x093c, 0x0938, 0x0934, 0x01bc, 0x01bc, 0x01bd), }, { .freq = 5910, RADIOREGS3(0xd6, 0x00, 0x01, 0x02, 0x4f, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x06, 0x06, 0x06, 0x87, 0x03, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x7f, 0x00, 0x05, 0x00, 0xf2, 0x00, 0x01, 0x00, 0x00, 0x00, 0x7f, 0x00, 0x05, 0x00, 0xf2, 0x00), PHYREGS(0x0940, 0x093c, 0x0938, 0x01bb, 0x01bc, 0x01bc), }, { .freq = 2412, RADIOREGS3(0x00, 0x01, 0x03, 0x09, 0x6c, 0x08, 0x08, 0x04, 0x16, 0x01, 0x04, 0x04, 0x04, 0x8f, 0x30, 0x00, 0x00, 0x00, 0xff, 0x00, 0x05, 0x00, 0x70, 0x00, 0x0f, 0x00, 0x0f, 0x00, 0xff, 0x00, 0x05, 0x00, 0x70, 0x00, 0x0f, 0x00, 0x0f), PHYREGS(0x03c9, 0x03c5, 0x03c1, 0x043a, 0x043f, 0x0443), }, { .freq = 2417, RADIOREGS3(0x00, 0x01, 0x03, 0x09, 0x71, 0x08, 0x08, 0x04, 0x16, 0x01, 0x05, 0x05, 0x05, 0x8f, 0x30, 0x00, 0x00, 0x00, 0xff, 0x00, 0x05, 0x00, 0x70, 0x00, 0x0f, 0x00, 0x0f, 0x00, 0xff, 0x00, 0x05, 0x00, 0x70, 0x00, 0x0f, 0x00, 0x0f), PHYREGS(0x03cb, 0x03c7, 0x03c3, 0x0438, 0x043d, 0x0441), }, { .freq = 2422, RADIOREGS3(0x00, 0x01, 0x03, 0x09, 0x76, 0x08, 0x08, 0x04, 0x16, 0x01, 0x05, 0x05, 0x05, 0x8f, 0x30, 0x00, 0x00, 0x00, 0xff, 0x00, 0x05, 0x00, 0x70, 0x00, 0x0f, 0x00, 0x0f, 0x00, 0xff, 0x00, 0x05, 0x00, 0x70, 0x00, 0x0f, 0x00, 0x0f), PHYREGS(0x03cd, 0x03c9, 0x03c5, 0x0436, 0x043a, 0x043f), }, { .freq = 2427, RADIOREGS3(0x00, 0x01, 0x03, 0x09, 0x7b, 0x08, 0x08, 0x04, 0x16, 0x01, 0x05, 0x05, 0x05, 0x8f, 0x30, 0x00, 0x00, 0x00, 0xfd, 0x00, 0x05, 0x00, 0x70, 0x00, 0x0f, 0x00, 0x0f, 0x00, 0xfd, 0x00, 0x05, 0x00, 0x70, 0x00, 0x0f, 0x00, 0x0f), PHYREGS(0x03cf, 0x03cb, 0x03c7, 0x0434, 0x0438, 0x043d), }, { .freq = 2432, RADIOREGS3(0x00, 0x01, 0x03, 0x09, 0x80, 0x08, 0x08, 0x04, 0x16, 0x01, 0x05, 0x05, 0x05, 0x8f, 0x30, 0x00, 0x00, 0x00, 0xfb, 0x00, 0x05, 0x00, 0x70, 0x00, 0x0f, 0x00, 0x0f, 0x00, 0xfb, 0x00, 0x05, 0x00, 0x70, 0x00, 0x0f, 0x00, 0x0f), PHYREGS(0x03d1, 0x03cd, 0x03c9, 0x0431, 0x0436, 0x043a), }, { .freq = 2437, RADIOREGS3(0x00, 0x01, 0x03, 0x09, 0x85, 0x08, 0x08, 0x04, 0x16, 0x01, 0x05, 0x05, 0x05, 0x8f, 0x30, 0x00, 0x00, 0x00, 0xfa, 0x00, 0x05, 0x00, 0x70, 0x00, 0x0f, 0x00, 0x0f, 0x00, 0xfa, 0x00, 0x05, 0x00, 0x70, 0x00, 0x0f, 0x00, 0x0f), PHYREGS(0x03d3, 0x03cf, 0x03cb, 0x042f, 0x0434, 0x0438), }, { .freq = 2442, RADIOREGS3(0x00, 0x01, 0x03, 0x09, 0x8a, 0x08, 0x08, 0x04, 0x16, 0x01, 0x05, 0x05, 0x05, 0x8f, 0x30, 0x00, 0x00, 0x00, 0xf8, 0x00, 0x05, 0x00, 0x70, 0x00, 0x0f, 0x00, 0x0f, 0x00, 0xf8, 0x00, 0x05, 0x00, 0x70, 0x00, 0x0f, 0x00, 0x0f), PHYREGS(0x03d5, 0x03d1, 0x03cd, 0x042d, 0x0431, 0x0436), }, { .freq = 2447, RADIOREGS3(0x00, 0x01, 0x03, 0x09, 0x8f, 0x08, 0x08, 0x04, 0x16, 0x01, 0x06, 0x06, 0x06, 0x8f, 0x30, 0x00, 0x00, 0x00, 0xf7, 0x00, 0x05, 0x00, 0x70, 0x00, 0x0f, 0x00, 0x0f, 0x00, 0xf7, 0x00, 0x05, 0x00, 0x70, 0x00, 0x0f, 0x00, 0x0f), PHYREGS(0x03d7, 0x03d3, 0x03cf, 0x042b, 0x042f, 0x0434), }, { .freq = 2452, RADIOREGS3(0x00, 0x01, 0x03, 0x09, 0x94, 0x08, 0x08, 0x04, 0x16, 0x01, 0x06, 0x06, 0x06, 0x8f, 0x30, 0x00, 0x00, 0x00, 0xf6, 0x00, 0x05, 0x00, 0x70, 0x00, 0x0f, 0x00, 0x0f, 0x00, 0xf6, 0x00, 0x05, 0x00, 0x70, 0x00, 0x0f, 0x00, 0x0f), PHYREGS(0x03d9, 0x03d5, 0x03d1, 0x0429, 0x042d, 0x0431), }, { .freq = 2457, RADIOREGS3(0x00, 0x01, 0x03, 0x09, 0x99, 0x08, 0x08, 0x04, 0x16, 0x01, 0x06, 0x06, 0x06, 0x8f, 0x30, 0x00, 0x00, 0x00, 0xf5, 0x00, 0x05, 0x00, 0x70, 0x00, 0x0f, 0x00, 0x0d, 0x00, 0xf5, 0x00, 0x05, 0x00, 0x70, 0x00, 0x0f, 0x00, 0x0d), PHYREGS(0x03db, 0x03d7, 0x03d3, 0x0427, 0x042b, 0x042f), }, { .freq = 2462, RADIOREGS3(0x00, 0x01, 0x03, 0x09, 0x9e, 0x08, 0x08, 0x04, 0x16, 0x01, 0x06, 0x06, 0x06, 0x8f, 0x30, 0x00, 0x00, 0x00, 0xf4, 0x00, 0x05, 0x00, 0x70, 0x00, 0x0f, 0x00, 0x0d, 0x00, 0xf4, 0x00, 0x05, 0x00, 0x70, 0x00, 0x0f, 0x00, 0x0d), PHYREGS(0x03dd, 0x03d9, 0x03d5, 0x0424, 0x0429, 0x042d), }, { .freq = 2467, RADIOREGS3(0x00, 0x01, 0x03, 0x09, 0xa3, 0x08, 0x08, 0x04, 0x16, 0x01, 0x06, 0x06, 0x06, 0x8f, 0x30, 0x00, 0x00, 0x00, 0xf3, 0x00, 0x05, 0x00, 0x70, 0x00, 0x0f, 0x00, 0x0d, 0x00, 0xf3, 0x00, 0x05, 0x00, 0x70, 0x00, 0x0f, 0x00, 0x0d), PHYREGS(0x03df, 0x03db, 0x03d7, 0x0422, 0x0427, 0x042b), }, { .freq = 2472, RADIOREGS3(0x00, 0x01, 0x03, 0x09, 0xa8, 0x08, 0x08, 0x04, 0x16, 0x01, 0x07, 0x07, 0x07, 0x8f, 0x30, 0x00, 0x00, 0x00, 0xf2, 0x00, 0x05, 0x00, 0x70, 0x00, 0x0f, 0x00, 0x0d, 0x00, 0xf2, 0x00, 0x05, 0x00, 0x70, 0x00, 0x0f, 0x00, 0x0d), PHYREGS(0x03e1, 0x03dd, 0x03d9, 0x0420, 0x0424, 0x0429), }, { .freq = 2484, RADIOREGS3(0xff, 0x01, 0x03, 0x09, 0xb4, 0x08, 0x08, 0x04, 0x16, 0x01, 0x07, 0x07, 0x07, 0x8f, 0x30, 0x00, 0x00, 0x00, 0xf0, 0x00, 0x05, 0x00, 0x70, 0x00, 0x0f, 0x00, 0x0d, 0x00, 0xf0, 0x00, 0x05, 0x00, 0x70, 0x00, 0x0f, 0x00, 0x0d), PHYREGS(0x03e6, 0x03e2, 0x03de, 0x041b, 0x041f, 0x0424), }, }; static const struct b43_nphy_channeltab_entry_rev3 b43_nphy_channeltab_phy_rev4[] = { { .freq = 4920, RADIOREGS3(0xff, 0x01, 0x01, 0x01, 0xec, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x00, 0x00, 0x00, 0x8f, 0x0f, 0x00, 0xff, 0xff, 0x00, 0x0e, 0x00, 0x7f, 0x00, 0x0f, 0x00, 0xff, 0x00, 0xff, 0x00, 0x0e, 0x00, 0x7f, 0x00, 0x0f, 0x00, 0xff, 0x00), PHYREGS(0x07b4, 0x07b0, 0x07ac, 0x0214, 0x0215, 0x0216), }, { .freq = 4930, RADIOREGS3(0xff, 0x01, 0x01, 0x01, 0xed, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x00, 0x00, 0x00, 0x8f, 0x0f, 0x00, 0xff, 0xff, 0x00, 0x0e, 0x00, 0x7f, 0x00, 0x0f, 0x00, 0xff, 0x00, 0xff, 0x00, 0x0e, 0x00, 0x7f, 0x00, 0x0f, 0x00, 0xff, 0x00), PHYREGS(0x07b8, 0x07b4, 0x07b0, 0x0213, 0x0214, 0x0215), }, { .freq = 4940, RADIOREGS3(0xff, 0x01, 0x01, 0x01, 0xee, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x00, 0x00, 0x00, 0x8f, 0x0f, 0x00, 0xff, 0xff, 0x00, 0x0e, 0x00, 0x7f, 0x00, 0x0f, 0x00, 0xff, 0x00, 0xff, 0x00, 0x0e, 0x00, 0x7f, 0x00, 0x0f, 0x00, 0xff, 0x00), PHYREGS(0x07bc, 0x07b8, 0x07b4, 0x0212, 0x0213, 0x0214), }, { .freq = 4950, RADIOREGS3(0xff, 0x01, 0x01, 0x01, 0xef, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x00, 0x00, 0x00, 0x8f, 0x0f, 0x00, 0xff, 0xff, 0x00, 0x0e, 0x00, 0x7f, 0x00, 0x0f, 0x00, 0xff, 0x00, 0xff, 0x00, 0x0e, 0x00, 0x7f, 0x00, 0x0f, 0x00, 0xff, 0x00), PHYREGS(0x07c0, 0x07bc, 0x07b8, 0x0211, 0x0212, 0x0213), }, { .freq = 4960, RADIOREGS3(0xff, 0x01, 0x01, 0x01, 0xf0, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x01, 0x01, 0x01, 0x8f, 0x0f, 0x00, 0xff, 0xff, 0x00, 0x0e, 0x00, 0x7f, 0x00, 0x0f, 0x00, 0xff, 0x00, 0xff, 0x00, 0x0e, 0x00, 0x7f, 0x00, 0x0f, 0x00, 0xff, 0x00), PHYREGS(0x07c4, 0x07c0, 0x07bc, 0x020f, 0x0211, 0x0212), }, { .freq = 4970, RADIOREGS3(0xff, 0x01, 0x01, 0x01, 0xf1, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x01, 0x01, 0x01, 0x8f, 0x0f, 0x00, 0xff, 0xff, 0x00, 0x0e, 0x00, 0x7f, 0x00, 0x0f, 0x00, 0xff, 0x00, 0xff, 0x00, 0x0e, 0x00, 0x7f, 0x00, 0x0f, 0x00, 0xff, 0x00), PHYREGS(0x07c8, 0x07c4, 0x07c0, 0x020e, 0x020f, 0x0211), }, { .freq = 4980, RADIOREGS3(0xff, 0x01, 0x01, 0x01, 0xf2, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x01, 0x01, 0x01, 0x8f, 0x0f, 0x00, 0xff, 0xff, 0x00, 0x0e, 0x00, 0x7f, 0x00, 0x0f, 0x00, 0xff, 0x00, 0xff, 0x00, 0x0e, 0x00, 0x7f, 0x00, 0x0f, 0x00, 0xff, 0x00), PHYREGS(0x07cc, 0x07c8, 0x07c4, 0x020d, 0x020e, 0x020f), }, { .freq = 4990, RADIOREGS3(0xff, 0x01, 0x01, 0x01, 0xf3, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x01, 0x01, 0x01, 0x8f, 0x0f, 0x00, 0xff, 0xff, 0x00, 0x0e, 0x00, 0x7f, 0x00, 0x0f, 0x00, 0xff, 0x00, 0xff, 0x00, 0x0e, 0x00, 0x7f, 0x00, 0x0f, 0x00, 0xff, 0x00), PHYREGS(0x07d0, 0x07cc, 0x07c8, 0x020c, 0x020d, 0x020e), }, { .freq = 5000, RADIOREGS3(0xff, 0x01, 0x01, 0x01, 0xf4, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x01, 0x01, 0x01, 0x8f, 0x0f, 0x00, 0xff, 0xff, 0x00, 0x0d, 0x00, 0x7f, 0x00, 0x0f, 0x00, 0xff, 0x00, 0xff, 0x00, 0x0d, 0x00, 0x7f, 0x00, 0x0f, 0x00, 0xff, 0x00), PHYREGS(0x07d4, 0x07d0, 0x07cc, 0x020b, 0x020c, 0x020d), }, { .freq = 5010, RADIOREGS3(0xff, 0x01, 0x01, 0x01, 0xf5, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x01, 0x01, 0x01, 0x8f, 0x0f, 0x00, 0xff, 0xff, 0x00, 0x0d, 0x00, 0x7f, 0x00, 0x0f, 0x00, 0xff, 0x00, 0xff, 0x00, 0x0d, 0x00, 0x7f, 0x00, 0x0f, 0x00, 0xff, 0x00), PHYREGS(0x07d8, 0x07d4, 0x07d0, 0x020a, 0x020b, 0x020c), }, { .freq = 5020, RADIOREGS3(0xf7, 0x01, 0x01, 0x01, 0xf6, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x01, 0x01, 0x01, 0x8f, 0x0f, 0x00, 0xff, 0xff, 0x00, 0x0d, 0x00, 0x7f, 0x00, 0x0f, 0x00, 0xff, 0x00, 0xff, 0x00, 0x0d, 0x00, 0x7f, 0x00, 0x0f, 0x00, 0xff, 0x00), PHYREGS(0x07dc, 0x07d8, 0x07d4, 0x0209, 0x020a, 0x020b), }, { .freq = 5030, RADIOREGS3(0xf7, 0x01, 0x01, 0x01, 0xf7, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x01, 0x01, 0x01, 0x8f, 0x0f, 0x00, 0xff, 0xff, 0x00, 0x0d, 0x00, 0x7f, 0x00, 0x0f, 0x00, 0xff, 0x00, 0xff, 0x00, 0x0d, 0x00, 0x7f, 0x00, 0x0f, 0x00, 0xff, 0x00), PHYREGS(0x07e0, 0x07dc, 0x07d8, 0x0208, 0x0209, 0x020a), }, { .freq = 5040, RADIOREGS3(0xef, 0x01, 0x01, 0x01, 0xf8, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x01, 0x01, 0x01, 0x8f, 0x0f, 0x00, 0xff, 0xff, 0x00, 0x0d, 0x00, 0x7f, 0x00, 0x0f, 0x00, 0xff, 0x00, 0xff, 0x00, 0x0d, 0x00, 0x7f, 0x00, 0x0f, 0x00, 0xff, 0x00), PHYREGS(0x07e4, 0x07e0, 0x07dc, 0x0207, 0x0208, 0x0209), }, { .freq = 5050, RADIOREGS3(0xef, 0x01, 0x01, 0x01, 0xf9, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x01, 0x01, 0x01, 0x8f, 0x0f, 0x00, 0xff, 0xff, 0x00, 0x0d, 0x00, 0x7f, 0x00, 0x0f, 0x00, 0xff, 0x00, 0xff, 0x00, 0x0d, 0x00, 0x7f, 0x00, 0x0f, 0x00, 0xff, 0x00), PHYREGS(0x07e8, 0x07e4, 0x07e0, 0x0206, 0x0207, 0x0208), }, { .freq = 5060, RADIOREGS3(0xe6, 0x01, 0x01, 0x01, 0xfa, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x01, 0x01, 0x01, 0x8f, 0x0f, 0x00, 0xff, 0xff, 0x00, 0x0d, 0x00, 0x7f, 0x00, 0x0f, 0x00, 0xff, 0x00, 0xff, 0x00, 0x0d, 0x00, 0x7f, 0x00, 0x0f, 0x00, 0xff, 0x00), PHYREGS(0x07ec, 0x07e8, 0x07e4, 0x0205, 0x0206, 0x0207), }, { .freq = 5070, RADIOREGS3(0xe6, 0x01, 0x01, 0x01, 0xfb, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x01, 0x01, 0x01, 0x8f, 0x0f, 0x00, 0xff, 0xff, 0x00, 0x0d, 0x00, 0x7f, 0x00, 0x0f, 0x00, 0xff, 0x00, 0xff, 0x00, 0x0d, 0x00, 0x7f, 0x00, 0x0f, 0x00, 0xff, 0x00), PHYREGS(0x07f0, 0x07ec, 0x07e8, 0x0204, 0x0205, 0x0206), }, { .freq = 5080, RADIOREGS3(0xde, 0x01, 0x01, 0x01, 0xfc, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x01, 0x01, 0x01, 0x8f, 0x0f, 0x00, 0xff, 0xff, 0x00, 0x0d, 0x00, 0x7f, 0x00, 0x0f, 0x00, 0xff, 0x00, 0xff, 0x00, 0x0d, 0x00, 0x7f, 0x00, 0x0f, 0x00, 0xff, 0x00), PHYREGS(0x07f4, 0x07f0, 0x07ec, 0x0203, 0x0204, 0x0205), }, { .freq = 5090, RADIOREGS3(0xde, 0x01, 0x01, 0x01, 0xfd, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x01, 0x01, 0x01, 0x8f, 0x0f, 0x00, 0xff, 0xff, 0x00, 0x0d, 0x00, 0x7f, 0x00, 0x0f, 0x00, 0xff, 0x00, 0xff, 0x00, 0x0d, 0x00, 0x7f, 0x00, 0x0f, 0x00, 0xff, 0x00), PHYREGS(0x07f8, 0x07f4, 0x07f0, 0x0202, 0x0203, 0x0204), }, { .freq = 5100, RADIOREGS3(0xd6, 0x01, 0x01, 0x01, 0xfe, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x02, 0x02, 0x02, 0x8f, 0x0f, 0x00, 0xff, 0xff, 0x00, 0x0c, 0x00, 0x7f, 0x00, 0x0f, 0x00, 0xfe, 0x00, 0xff, 0x00, 0x0c, 0x00, 0x7f, 0x00, 0x0f, 0x00, 0xfe, 0x00), PHYREGS(0x07fc, 0x07f8, 0x07f4, 0x0201, 0x0202, 0x0203), }, { .freq = 5110, RADIOREGS3(0xd6, 0x01, 0x01, 0x01, 0xff, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x02, 0x02, 0x02, 0x8f, 0x0f, 0x00, 0xff, 0xff, 0x00, 0x0c, 0x00, 0x7f, 0x00, 0x0f, 0x00, 0xfe, 0x00, 0xff, 0x00, 0x0c, 0x00, 0x7f, 0x00, 0x0f, 0x00, 0xfe, 0x00), PHYREGS(0x0800, 0x07fc, 0x07f8, 0x0200, 0x0201, 0x0202), }, { .freq = 5120, RADIOREGS3(0xce, 0x01, 0x01, 0x02, 0x00, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x02, 0x02, 0x02, 0x8f, 0x0f, 0x00, 0xff, 0xff, 0x00, 0x0c, 0x00, 0x7f, 0x00, 0x0f, 0x00, 0xfe, 0x00, 0xff, 0x00, 0x0c, 0x00, 0x7f, 0x00, 0x0f, 0x00, 0xfe, 0x00), PHYREGS(0x0804, 0x0800, 0x07fc, 0x01ff, 0x0200, 0x0201), }, { .freq = 5130, RADIOREGS3(0xce, 0x01, 0x01, 0x02, 0x01, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x02, 0x02, 0x02, 0x8f, 0x0f, 0x00, 0xff, 0xff, 0x00, 0x0c, 0x00, 0x7f, 0x00, 0x0f, 0x00, 0xfe, 0x00, 0xff, 0x00, 0x0c, 0x00, 0x7f, 0x00, 0x0f, 0x00, 0xfe, 0x00), PHYREGS(0x0808, 0x0804, 0x0800, 0x01fe, 0x01ff, 0x0200), }, { .freq = 5140, RADIOREGS3(0xc6, 0x01, 0x01, 0x02, 0x02, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x02, 0x02, 0x02, 0x8f, 0x0f, 0x00, 0xff, 0xff, 0x00, 0x0c, 0x00, 0x7f, 0x00, 0x0f, 0x00, 0xfe, 0x00, 0xff, 0x00, 0x0c, 0x00, 0x7f, 0x00, 0x0f, 0x00, 0xfe, 0x00), PHYREGS(0x080c, 0x0808, 0x0804, 0x01fd, 0x01fe, 0x01ff), }, { .freq = 5160, RADIOREGS3(0xbe, 0x01, 0x01, 0x02, 0x04, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x02, 0x02, 0x02, 0x8f, 0x0f, 0x00, 0xff, 0xff, 0x00, 0x0c, 0x00, 0x7f, 0x00, 0x0f, 0x00, 0xfe, 0x00, 0xff, 0x00, 0x0c, 0x00, 0x7f, 0x00, 0x0f, 0x00, 0xfe, 0x00), PHYREGS(0x0814, 0x0810, 0x080c, 0x01fb, 0x01fc, 0x01fd), }, { .freq = 5170, RADIOREGS3(0xbe, 0x01, 0x01, 0x02, 0x05, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x02, 0x02, 0x02, 0x8f, 0x0f, 0x00, 0xff, 0xff, 0x00, 0x0c, 0x00, 0x7f, 0x00, 0x0f, 0x00, 0xfe, 0x00, 0xff, 0x00, 0x0c, 0x00, 0x7f, 0x00, 0x0f, 0x00, 0xfe, 0x00), PHYREGS(0x0818, 0x0814, 0x0810, 0x01fa, 0x01fb, 0x01fc), }, { .freq = 5180, RADIOREGS3(0xb6, 0x01, 0x01, 0x02, 0x06, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x02, 0x02, 0x02, 0x8f, 0x0f, 0x00, 0xff, 0xef, 0x00, 0x0c, 0x00, 0x7f, 0x00, 0x0f, 0x00, 0xfe, 0x00, 0xef, 0x00, 0x0c, 0x00, 0x7f, 0x00, 0x0f, 0x00, 0xfe, 0x00), PHYREGS(0x081c, 0x0818, 0x0814, 0x01f9, 0x01fa, 0x01fb), }, { .freq = 5190, RADIOREGS3(0xb6, 0x01, 0x01, 0x02, 0x07, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x02, 0x02, 0x02, 0x8f, 0x0f, 0x00, 0xff, 0xef, 0x00, 0x0c, 0x00, 0x7f, 0x00, 0x0f, 0x00, 0xfe, 0x00, 0xef, 0x00, 0x0c, 0x00, 0x7f, 0x00, 0x0f, 0x00, 0xfe, 0x00), PHYREGS(0x0820, 0x081c, 0x0818, 0x01f8, 0x01f9, 0x01fa), }, { .freq = 5200, RADIOREGS3(0xaf, 0x01, 0x01, 0x02, 0x08, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x02, 0x02, 0x02, 0x8f, 0x0f, 0x00, 0xff, 0xef, 0x00, 0x0a, 0x00, 0x7f, 0x00, 0x0f, 0x00, 0xfc, 0x00, 0xef, 0x00, 0x0a, 0x00, 0x7f, 0x00, 0x0f, 0x00, 0xfc, 0x00), PHYREGS(0x0824, 0x0820, 0x081c, 0x01f7, 0x01f8, 0x01f9), }, { .freq = 5210, RADIOREGS3(0xaf, 0x01, 0x01, 0x02, 0x09, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x02, 0x02, 0x02, 0x8f, 0x0f, 0x00, 0xff, 0xdf, 0x00, 0x0a, 0x00, 0x7f, 0x00, 0x0f, 0x00, 0xfc, 0x00, 0xdf, 0x00, 0x0a, 0x00, 0x7f, 0x00, 0x0f, 0x00, 0xfc, 0x00), PHYREGS(0x0828, 0x0824, 0x0820, 0x01f6, 0x01f7, 0x01f8), }, { .freq = 5220, RADIOREGS3(0xa7, 0x01, 0x01, 0x02, 0x0a, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x02, 0x02, 0x02, 0x8f, 0x0f, 0x00, 0xff, 0xdf, 0x00, 0x0a, 0x00, 0x7f, 0x00, 0x0f, 0x00, 0xfc, 0x00, 0xdf, 0x00, 0x0a, 0x00, 0x7f, 0x00, 0x0f, 0x00, 0xfc, 0x00), PHYREGS(0x082c, 0x0828, 0x0824, 0x01f5, 0x01f6, 0x01f7), }, { .freq = 5230, RADIOREGS3(0xa7, 0x01, 0x01, 0x02, 0x0b, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x02, 0x02, 0x02, 0x8f, 0x0f, 0x00, 0xff, 0xdf, 0x00, 0x0a, 0x00, 0x7f, 0x00, 0x0f, 0x00, 0xfc, 0x00, 0xdf, 0x00, 0x0a, 0x00, 0x7f, 0x00, 0x0f, 0x00, 0xfc, 0x00), PHYREGS(0x0830, 0x082c, 0x0828, 0x01f4, 0x01f5, 0x01f6), }, { .freq = 5240, RADIOREGS3(0xa0, 0x01, 0x01, 0x02, 0x0c, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x02, 0x02, 0x02, 0x8f, 0x0f, 0x00, 0xff, 0xcf, 0x00, 0x0a, 0x00, 0x7f, 0x00, 0x0f, 0x00, 0xfc, 0x00, 0xcf, 0x00, 0x0a, 0x00, 0x7f, 0x00, 0x0f, 0x00, 0xfc, 0x00), PHYREGS(0x0834, 0x0830, 0x082c, 0x01f3, 0x01f4, 0x01f5), }, { .freq = 5250, RADIOREGS3(0xa0, 0x01, 0x01, 0x02, 0x0d, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x02, 0x02, 0x02, 0x8f, 0x0f, 0x00, 0xff, 0xcf, 0x00, 0x0a, 0x00, 0x7f, 0x00, 0x0f, 0x00, 0xfc, 0x00, 0xcf, 0x00, 0x0a, 0x00, 0x7f, 0x00, 0x0f, 0x00, 0xfc, 0x00), PHYREGS(0x0838, 0x0834, 0x0830, 0x01f2, 0x01f3, 0x01f4), }, { .freq = 5260, RADIOREGS3(0x98, 0x01, 0x01, 0x02, 0x0e, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x02, 0x02, 0x02, 0x8f, 0x0f, 0x00, 0xff, 0xcf, 0x00, 0x0a, 0x00, 0x7f, 0x00, 0x0f, 0x00, 0xfc, 0x00, 0xcf, 0x00, 0x0a, 0x00, 0x7f, 0x00, 0x0f, 0x00, 0xfc, 0x00), PHYREGS(0x083c, 0x0838, 0x0834, 0x01f1, 0x01f2, 0x01f3), }, { .freq = 5270, RADIOREGS3(0x98, 0x01, 0x01, 0x02, 0x0f, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x03, 0x03, 0x03, 0x8f, 0x0f, 0x00, 0xff, 0xcf, 0x00, 0x0a, 0x00, 0x7f, 0x00, 0x0f, 0x00, 0xfc, 0x00, 0xcf, 0x00, 0x0a, 0x00, 0x7f, 0x00, 0x0f, 0x00, 0xfc, 0x00), PHYREGS(0x0840, 0x083c, 0x0838, 0x01f0, 0x01f1, 0x01f2), }, { .freq = 5280, RADIOREGS3(0x91, 0x01, 0x01, 0x02, 0x10, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x03, 0x03, 0x03, 0x8f, 0x0f, 0x00, 0xff, 0xbf, 0x00, 0x0a, 0x00, 0x7f, 0x00, 0x0f, 0x00, 0xfc, 0x00, 0xbf, 0x00, 0x0a, 0x00, 0x7f, 0x00, 0x0f, 0x00, 0xfc, 0x00), PHYREGS(0x0844, 0x0840, 0x083c, 0x01f0, 0x01f0, 0x01f1), }, { .freq = 5290, RADIOREGS3(0x91, 0x01, 0x01, 0x02, 0x11, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x03, 0x03, 0x03, 0x8f, 0x0f, 0x00, 0xff, 0xbf, 0x00, 0x0a, 0x00, 0x7f, 0x00, 0x0f, 0x00, 0xfc, 0x00, 0xbf, 0x00, 0x0a, 0x00, 0x7f, 0x00, 0x0f, 0x00, 0xfc, 0x00), PHYREGS(0x0848, 0x0844, 0x0840, 0x01ef, 0x01f0, 0x01f0), }, { .freq = 5300, RADIOREGS3(0x8a, 0x01, 0x01, 0x02, 0x12, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x03, 0x03, 0x03, 0x8f, 0x0e, 0x00, 0xff, 0xbf, 0x00, 0x08, 0x00, 0x7f, 0x00, 0x0f, 0x00, 0xfa, 0x00, 0xbf, 0x00, 0x08, 0x00, 0x7f, 0x00, 0x0f, 0x00, 0xfa, 0x00), PHYREGS(0x084c, 0x0848, 0x0844, 0x01ee, 0x01ef, 0x01f0), }, { .freq = 5310, RADIOREGS3(0x8a, 0x01, 0x01, 0x02, 0x13, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x03, 0x03, 0x03, 0x8f, 0x0e, 0x00, 0xff, 0xbf, 0x00, 0x08, 0x00, 0x7f, 0x00, 0x0f, 0x00, 0xfa, 0x00, 0xbf, 0x00, 0x08, 0x00, 0x7f, 0x00, 0x0f, 0x00, 0xfa, 0x00), PHYREGS(0x0850, 0x084c, 0x0848, 0x01ed, 0x01ee, 0x01ef), }, { .freq = 5320, RADIOREGS3(0x83, 0x01, 0x01, 0x02, 0x14, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x03, 0x03, 0x03, 0x8f, 0x0e, 0x00, 0xff, 0xbf, 0x00, 0x08, 0x00, 0x7f, 0x00, 0x0f, 0x00, 0xfa, 0x00, 0xbf, 0x00, 0x08, 0x00, 0x7f, 0x00, 0x0f, 0x00, 0xfa, 0x00), PHYREGS(0x0854, 0x0850, 0x084c, 0x01ec, 0x01ed, 0x01ee), }, { .freq = 5330, RADIOREGS3(0x83, 0x01, 0x01, 0x02, 0x15, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x03, 0x03, 0x03, 0x8f, 0x0e, 0x00, 0xff, 0xaf, 0x00, 0x08, 0x00, 0x7f, 0x00, 0x0f, 0x00, 0xfa, 0x00, 0xaf, 0x00, 0x08, 0x00, 0x7f, 0x00, 0x0f, 0x00, 0xfa, 0x00), PHYREGS(0x0858, 0x0854, 0x0850, 0x01eb, 0x01ec, 0x01ed), }, { .freq = 5340, RADIOREGS3(0x7c, 0x01, 0x01, 0x02, 0x16, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x03, 0x03, 0x03, 0x8f, 0x0e, 0x00, 0xff, 0xaf, 0x00, 0x08, 0x00, 0x7f, 0x00, 0x0f, 0x00, 0xfa, 0x00, 0xaf, 0x00, 0x08, 0x00, 0x7f, 0x00, 0x0f, 0x00, 0xfa, 0x00), PHYREGS(0x085c, 0x0858, 0x0854, 0x01ea, 0x01eb, 0x01ec), }, { .freq = 5350, RADIOREGS3(0x7c, 0x01, 0x01, 0x02, 0x17, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x03, 0x03, 0x03, 0x8f, 0x0e, 0x00, 0xff, 0x9f, 0x00, 0x08, 0x00, 0x7f, 0x00, 0x0f, 0x00, 0xfa, 0x00, 0x9f, 0x00, 0x08, 0x00, 0x7f, 0x00, 0x0f, 0x00, 0xfa, 0x00), PHYREGS(0x0860, 0x085c, 0x0858, 0x01e9, 0x01ea, 0x01eb), }, { .freq = 5360, RADIOREGS3(0x75, 0x01, 0x01, 0x02, 0x18, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x03, 0x03, 0x03, 0x8f, 0x0e, 0x00, 0xff, 0x9f, 0x00, 0x08, 0x00, 0x7f, 0x00, 0x0f, 0x00, 0xfa, 0x00, 0x9f, 0x00, 0x08, 0x00, 0x7f, 0x00, 0x0f, 0x00, 0xfa, 0x00), PHYREGS(0x0864, 0x0860, 0x085c, 0x01e8, 0x01e9, 0x01ea), }, { .freq = 5370, RADIOREGS3(0x75, 0x01, 0x01, 0x02, 0x19, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x03, 0x03, 0x03, 0x8f, 0x0e, 0x00, 0xff, 0x9f, 0x00, 0x08, 0x00, 0x7f, 0x00, 0x0f, 0x00, 0xfa, 0x00, 0x9f, 0x00, 0x08, 0x00, 0x7f, 0x00, 0x0f, 0x00, 0xfa, 0x00), PHYREGS(0x0868, 0x0864, 0x0860, 0x01e7, 0x01e8, 0x01e9), }, { .freq = 5380, RADIOREGS3(0x6e, 0x01, 0x01, 0x02, 0x1a, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x03, 0x03, 0x03, 0x8f, 0x0e, 0x00, 0xff, 0x9f, 0x00, 0x08, 0x00, 0x7f, 0x00, 0x0f, 0x00, 0xfa, 0x00, 0x9f, 0x00, 0x08, 0x00, 0x7f, 0x00, 0x0f, 0x00, 0xfa, 0x00), PHYREGS(0x086c, 0x0868, 0x0864, 0x01e6, 0x01e7, 0x01e8), }, { .freq = 5390, RADIOREGS3(0x6e, 0x01, 0x01, 0x02, 0x1b, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x03, 0x03, 0x03, 0x8f, 0x0e, 0x00, 0xff, 0x8f, 0x00, 0x08, 0x00, 0x7f, 0x00, 0x0f, 0x00, 0xfa, 0x00, 0x8f, 0x00, 0x08, 0x00, 0x7f, 0x00, 0x0f, 0x00, 0xfa, 0x00), PHYREGS(0x0870, 0x086c, 0x0868, 0x01e5, 0x01e6, 0x01e7), }, { .freq = 5400, RADIOREGS3(0x67, 0x01, 0x01, 0x02, 0x1c, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x03, 0x03, 0x03, 0x8d, 0x0d, 0x00, 0xc8, 0x8f, 0x00, 0x07, 0x00, 0x7f, 0x00, 0x0f, 0x00, 0xf8, 0x00, 0x8f, 0x00, 0x07, 0x00, 0x7f, 0x00, 0x0f, 0x00, 0xf8, 0x00), PHYREGS(0x0874, 0x0870, 0x086c, 0x01e5, 0x01e5, 0x01e6), }, { .freq = 5410, RADIOREGS3(0x67, 0x01, 0x01, 0x02, 0x1d, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x03, 0x03, 0x03, 0x8d, 0x0d, 0x00, 0xc8, 0x8f, 0x00, 0x07, 0x00, 0x7f, 0x00, 0x0f, 0x00, 0xf8, 0x00, 0x8f, 0x00, 0x07, 0x00, 0x7f, 0x00, 0x0f, 0x00, 0xf8, 0x00), PHYREGS(0x0878, 0x0874, 0x0870, 0x01e4, 0x01e5, 0x01e5), }, { .freq = 5420, RADIOREGS3(0x61, 0x01, 0x01, 0x02, 0x1e, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x03, 0x03, 0x03, 0x8d, 0x0d, 0x00, 0xc8, 0x8e, 0x00, 0x07, 0x00, 0x7f, 0x00, 0x0f, 0x00, 0xf8, 0x00, 0x8e, 0x00, 0x07, 0x00, 0x7f, 0x00, 0x0f, 0x00, 0xf8, 0x00), PHYREGS(0x087c, 0x0878, 0x0874, 0x01e3, 0x01e4, 0x01e5), }, { .freq = 5430, RADIOREGS3(0x61, 0x01, 0x01, 0x02, 0x1f, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x03, 0x03, 0x03, 0x8d, 0x0d, 0x00, 0xc8, 0x8e, 0x00, 0x07, 0x00, 0x7f, 0x00, 0x0f, 0x00, 0xf8, 0x00, 0x8e, 0x00, 0x07, 0x00, 0x7f, 0x00, 0x0f, 0x00, 0xf8, 0x00), PHYREGS(0x0880, 0x087c, 0x0878, 0x01e2, 0x01e3, 0x01e4), }, { .freq = 5440, RADIOREGS3(0x5a, 0x01, 0x01, 0x02, 0x20, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x04, 0x04, 0x04, 0x8d, 0x0d, 0x00, 0xc8, 0x7e, 0x00, 0x07, 0x00, 0x7f, 0x00, 0x0f, 0x00, 0xf8, 0x00, 0x7e, 0x00, 0x07, 0x00, 0x7f, 0x00, 0x0f, 0x00, 0xf8, 0x00), PHYREGS(0x0884, 0x0880, 0x087c, 0x01e1, 0x01e2, 0x01e3), }, { .freq = 5450, RADIOREGS3(0x5a, 0x01, 0x01, 0x02, 0x21, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x04, 0x04, 0x04, 0x8d, 0x0d, 0x00, 0xc8, 0x7d, 0x00, 0x07, 0x00, 0x7f, 0x00, 0x0f, 0x00, 0xf8, 0x00, 0x7d, 0x00, 0x07, 0x00, 0x7f, 0x00, 0x0f, 0x00, 0xf8, 0x00), PHYREGS(0x0888, 0x0884, 0x0880, 0x01e0, 0x01e1, 0x01e2), }, { .freq = 5460, RADIOREGS3(0x53, 0x01, 0x01, 0x02, 0x22, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x04, 0x04, 0x04, 0x8d, 0x0d, 0x00, 0xc8, 0x6d, 0x00, 0x07, 0x00, 0x7f, 0x00, 0x0f, 0x00, 0xf8, 0x00, 0x6d, 0x00, 0x07, 0x00, 0x7f, 0x00, 0x0f, 0x00, 0xf8, 0x00), PHYREGS(0x088c, 0x0888, 0x0884, 0x01df, 0x01e0, 0x01e1), }, { .freq = 5470, RADIOREGS3(0x53, 0x01, 0x01, 0x02, 0x23, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x04, 0x04, 0x04, 0x8d, 0x0d, 0x00, 0xc8, 0x6d, 0x00, 0x07, 0x00, 0x7f, 0x00, 0x0f, 0x00, 0xf8, 0x00, 0x6d, 0x00, 0x07, 0x00, 0x7f, 0x00, 0x0f, 0x00, 0xf8, 0x00), PHYREGS(0x0890, 0x088c, 0x0888, 0x01de, 0x01df, 0x01e0), }, { .freq = 5480, RADIOREGS3(0x4d, 0x01, 0x01, 0x02, 0x24, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x04, 0x04, 0x04, 0x8d, 0x0d, 0x00, 0xc8, 0x5d, 0x00, 0x07, 0x00, 0x7f, 0x00, 0x0f, 0x00, 0xf8, 0x00, 0x5d, 0x00, 0x07, 0x00, 0x7f, 0x00, 0x0f, 0x00, 0xf8, 0x00), PHYREGS(0x0894, 0x0890, 0x088c, 0x01dd, 0x01de, 0x01df), }, { .freq = 5490, RADIOREGS3(0x4d, 0x01, 0x01, 0x02, 0x25, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x04, 0x04, 0x04, 0x8d, 0x0d, 0x00, 0xc8, 0x5c, 0x00, 0x07, 0x00, 0x7f, 0x00, 0x0f, 0x00, 0xf8, 0x00, 0x5c, 0x00, 0x07, 0x00, 0x7f, 0x00, 0x0f, 0x00, 0xf8, 0x00), PHYREGS(0x0898, 0x0894, 0x0890, 0x01dd, 0x01dd, 0x01de), }, { .freq = 5500, RADIOREGS3(0x47, 0x01, 0x01, 0x02, 0x26, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x04, 0x04, 0x04, 0x8d, 0x0b, 0x00, 0x84, 0x5c, 0x00, 0x06, 0x00, 0x7f, 0x00, 0x0d, 0x00, 0xf6, 0x00, 0x5c, 0x00, 0x06, 0x00, 0x7f, 0x00, 0x0d, 0x00, 0xf6, 0x00), PHYREGS(0x089c, 0x0898, 0x0894, 0x01dc, 0x01dd, 0x01dd), }, { .freq = 5510, RADIOREGS3(0x47, 0x01, 0x01, 0x02, 0x27, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x04, 0x04, 0x04, 0x8d, 0x0b, 0x00, 0x84, 0x4c, 0x00, 0x06, 0x00, 0x7f, 0x00, 0x0d, 0x00, 0xf6, 0x00, 0x4c, 0x00, 0x06, 0x00, 0x7f, 0x00, 0x0d, 0x00, 0xf6, 0x00), PHYREGS(0x08a0, 0x089c, 0x0898, 0x01db, 0x01dc, 0x01dd), }, { .freq = 5520, RADIOREGS3(0x40, 0x01, 0x01, 0x02, 0x28, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x04, 0x04, 0x04, 0x8d, 0x0b, 0x00, 0x84, 0x4c, 0x00, 0x06, 0x00, 0x7f, 0x00, 0x0d, 0x00, 0xf6, 0x00, 0x4c, 0x00, 0x06, 0x00, 0x7f, 0x00, 0x0d, 0x00, 0xf6, 0x00), PHYREGS(0x08a4, 0x08a0, 0x089c, 0x01da, 0x01db, 0x01dc), }, { .freq = 5530, RADIOREGS3(0x40, 0x01, 0x01, 0x02, 0x29, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x04, 0x04, 0x04, 0x8d, 0x0b, 0x00, 0x84, 0x3b, 0x00, 0x06, 0x00, 0x7f, 0x00, 0x0d, 0x00, 0xf6, 0x00, 0x3b, 0x00, 0x06, 0x00, 0x7f, 0x00, 0x0d, 0x00, 0xf6, 0x00), PHYREGS(0x08a8, 0x08a4, 0x08a0, 0x01d9, 0x01da, 0x01db), }, { .freq = 5540, RADIOREGS3(0x3a, 0x01, 0x01, 0x02, 0x2a, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x04, 0x04, 0x04, 0x8d, 0x0b, 0x00, 0x84, 0x3b, 0x00, 0x06, 0x00, 0x7f, 0x00, 0x0d, 0x00, 0xf6, 0x00, 0x3b, 0x00, 0x06, 0x00, 0x7f, 0x00, 0x0d, 0x00, 0xf6, 0x00), PHYREGS(0x08ac, 0x08a8, 0x08a4, 0x01d8, 0x01d9, 0x01da), }, { .freq = 5550, RADIOREGS3(0x3a, 0x01, 0x01, 0x02, 0x2b, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x04, 0x04, 0x04, 0x8d, 0x0b, 0x00, 0x84, 0x3b, 0x00, 0x06, 0x00, 0x7f, 0x00, 0x0d, 0x00, 0xf6, 0x00, 0x3b, 0x00, 0x06, 0x00, 0x7f, 0x00, 0x0d, 0x00, 0xf6, 0x00), PHYREGS(0x08b0, 0x08ac, 0x08a8, 0x01d7, 0x01d8, 0x01d9), }, { .freq = 5560, RADIOREGS3(0x34, 0x01, 0x01, 0x02, 0x2c, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x04, 0x04, 0x04, 0x8d, 0x0b, 0x00, 0x84, 0x2b, 0x00, 0x06, 0x00, 0x7f, 0x00, 0x0d, 0x00, 0xf6, 0x00, 0x2b, 0x00, 0x06, 0x00, 0x7f, 0x00, 0x0d, 0x00, 0xf6, 0x00), PHYREGS(0x08b4, 0x08b0, 0x08ac, 0x01d7, 0x01d7, 0x01d8), }, { .freq = 5570, RADIOREGS3(0x34, 0x01, 0x01, 0x02, 0x2d, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x04, 0x04, 0x04, 0x8d, 0x0b, 0x00, 0x84, 0x2a, 0x00, 0x06, 0x00, 0x7f, 0x00, 0x0d, 0x00, 0xf6, 0x00, 0x2a, 0x00, 0x06, 0x00, 0x7f, 0x00, 0x0d, 0x00, 0xf6, 0x00), PHYREGS(0x08b8, 0x08b4, 0x08b0, 0x01d6, 0x01d7, 0x01d7), }, { .freq = 5580, RADIOREGS3(0x2e, 0x01, 0x01, 0x02, 0x2e, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x04, 0x04, 0x04, 0x8d, 0x0b, 0x00, 0x84, 0x1a, 0x00, 0x06, 0x00, 0x7f, 0x00, 0x0d, 0x00, 0xf6, 0x00, 0x1a, 0x00, 0x06, 0x00, 0x7f, 0x00, 0x0d, 0x00, 0xf6, 0x00), PHYREGS(0x08bc, 0x08b8, 0x08b4, 0x01d5, 0x01d6, 0x01d7), }, { .freq = 5590, RADIOREGS3(0x2e, 0x01, 0x01, 0x02, 0x2f, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x04, 0x04, 0x04, 0x8d, 0x0b, 0x00, 0x84, 0x1a, 0x00, 0x06, 0x00, 0x7f, 0x00, 0x0d, 0x00, 0xf6, 0x00, 0x1a, 0x00, 0x06, 0x00, 0x7f, 0x00, 0x0d, 0x00, 0xf6, 0x00), PHYREGS(0x08c0, 0x08bc, 0x08b8, 0x01d4, 0x01d5, 0x01d6), }, { .freq = 5600, RADIOREGS3(0x28, 0x01, 0x01, 0x02, 0x30, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x05, 0x05, 0x05, 0x8b, 0x09, 0x00, 0x70, 0x1a, 0x00, 0x04, 0x00, 0x7f, 0x00, 0x0b, 0x00, 0xf4, 0x00, 0x1a, 0x00, 0x04, 0x00, 0x7f, 0x00, 0x0b, 0x00, 0xf4, 0x00), PHYREGS(0x08c4, 0x08c0, 0x08bc, 0x01d3, 0x01d4, 0x01d5), }, { .freq = 5610, RADIOREGS3(0x28, 0x01, 0x01, 0x02, 0x31, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x05, 0x05, 0x05, 0x8b, 0x09, 0x00, 0x70, 0x19, 0x00, 0x04, 0x00, 0x7f, 0x00, 0x0b, 0x00, 0xf4, 0x00, 0x19, 0x00, 0x04, 0x00, 0x7f, 0x00, 0x0b, 0x00, 0xf4, 0x00), PHYREGS(0x08c8, 0x08c4, 0x08c0, 0x01d2, 0x01d3, 0x01d4), }, { .freq = 5620, RADIOREGS3(0x21, 0x01, 0x01, 0x02, 0x32, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x05, 0x05, 0x05, 0x8b, 0x09, 0x00, 0x70, 0x19, 0x00, 0x04, 0x00, 0x7f, 0x00, 0x0b, 0x00, 0xf4, 0x00, 0x19, 0x00, 0x04, 0x00, 0x7f, 0x00, 0x0b, 0x00, 0xf4, 0x00), PHYREGS(0x08cc, 0x08c8, 0x08c4, 0x01d2, 0x01d2, 0x01d3), }, { .freq = 5630, RADIOREGS3(0x21, 0x01, 0x01, 0x02, 0x33, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x05, 0x05, 0x05, 0x8b, 0x09, 0x00, 0x70, 0x09, 0x00, 0x04, 0x00, 0x7f, 0x00, 0x0b, 0x00, 0xf4, 0x00, 0x09, 0x00, 0x04, 0x00, 0x7f, 0x00, 0x0b, 0x00, 0xf4, 0x00), PHYREGS(0x08d0, 0x08cc, 0x08c8, 0x01d1, 0x01d2, 0x01d2), }, { .freq = 5640, RADIOREGS3(0x1c, 0x01, 0x01, 0x02, 0x34, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x05, 0x05, 0x05, 0x8b, 0x09, 0x00, 0x70, 0x09, 0x00, 0x04, 0x00, 0x7f, 0x00, 0x0b, 0x00, 0xf4, 0x00, 0x09, 0x00, 0x04, 0x00, 0x7f, 0x00, 0x0b, 0x00, 0xf4, 0x00), PHYREGS(0x08d4, 0x08d0, 0x08cc, 0x01d0, 0x01d1, 0x01d2), }, { .freq = 5650, RADIOREGS3(0x1c, 0x01, 0x01, 0x02, 0x35, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x05, 0x05, 0x05, 0x8b, 0x09, 0x00, 0x70, 0x08, 0x00, 0x04, 0x00, 0x7f, 0x00, 0x0b, 0x00, 0xf4, 0x00, 0x08, 0x00, 0x04, 0x00, 0x7f, 0x00, 0x0b, 0x00, 0xf4, 0x00), PHYREGS(0x08d8, 0x08d4, 0x08d0, 0x01cf, 0x01d0, 0x01d1), }, { .freq = 5660, RADIOREGS3(0x16, 0x01, 0x01, 0x02, 0x36, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x05, 0x05, 0x05, 0x8b, 0x09, 0x00, 0x70, 0x08, 0x00, 0x04, 0x00, 0x7f, 0x00, 0x0b, 0x00, 0xf4, 0x00, 0x08, 0x00, 0x04, 0x00, 0x7f, 0x00, 0x0b, 0x00, 0xf4, 0x00), PHYREGS(0x08dc, 0x08d8, 0x08d4, 0x01ce, 0x01cf, 0x01d0), }, { .freq = 5670, RADIOREGS3(0x16, 0x01, 0x01, 0x02, 0x37, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x05, 0x05, 0x05, 0x8b, 0x09, 0x00, 0x70, 0x08, 0x00, 0x04, 0x00, 0x7f, 0x00, 0x0b, 0x00, 0xf4, 0x00, 0x08, 0x00, 0x04, 0x00, 0x7f, 0x00, 0x0b, 0x00, 0xf4, 0x00), PHYREGS(0x08e0, 0x08dc, 0x08d8, 0x01ce, 0x01ce, 0x01cf), }, { .freq = 5680, RADIOREGS3(0x10, 0x01, 0x01, 0x02, 0x38, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x05, 0x05, 0x05, 0x8b, 0x09, 0x00, 0x70, 0x08, 0x00, 0x04, 0x00, 0x7f, 0x00, 0x0b, 0x00, 0xf4, 0x00, 0x08, 0x00, 0x04, 0x00, 0x7f, 0x00, 0x0b, 0x00, 0xf4, 0x00), PHYREGS(0x08e4, 0x08e0, 0x08dc, 0x01cd, 0x01ce, 0x01ce), }, { .freq = 5690, RADIOREGS3(0x10, 0x01, 0x01, 0x02, 0x39, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x05, 0x05, 0x05, 0x8b, 0x09, 0x00, 0x70, 0x07, 0x00, 0x04, 0x00, 0x7f, 0x00, 0x0b, 0x00, 0xf4, 0x00, 0x07, 0x00, 0x04, 0x00, 0x7f, 0x00, 0x0b, 0x00, 0xf4, 0x00), PHYREGS(0x08e8, 0x08e4, 0x08e0, 0x01cc, 0x01cd, 0x01ce), }, { .freq = 5700, RADIOREGS3(0x0a, 0x01, 0x01, 0x02, 0x3a, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x05, 0x05, 0x05, 0x8a, 0x06, 0x00, 0x40, 0x07, 0x00, 0x03, 0x00, 0x7f, 0x00, 0x0a, 0x00, 0xf2, 0x00, 0x07, 0x00, 0x03, 0x00, 0x7f, 0x00, 0x0a, 0x00, 0xf2, 0x00), PHYREGS(0x08ec, 0x08e8, 0x08e4, 0x01cb, 0x01cc, 0x01cd), }, { .freq = 5710, RADIOREGS3(0x0a, 0x01, 0x01, 0x02, 0x3b, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x05, 0x05, 0x05, 0x8a, 0x06, 0x00, 0x40, 0x07, 0x00, 0x03, 0x00, 0x7f, 0x00, 0x0a, 0x00, 0xf2, 0x00, 0x07, 0x00, 0x03, 0x00, 0x7f, 0x00, 0x0a, 0x00, 0xf2, 0x00), PHYREGS(0x08f0, 0x08ec, 0x08e8, 0x01ca, 0x01cb, 0x01cc), }, { .freq = 5720, RADIOREGS3(0x0a, 0x01, 0x01, 0x02, 0x3c, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x05, 0x05, 0x05, 0x8a, 0x06, 0x00, 0x40, 0x07, 0x00, 0x03, 0x00, 0x7f, 0x00, 0x0a, 0x00, 0xf2, 0x00, 0x07, 0x00, 0x03, 0x00, 0x7f, 0x00, 0x0a, 0x00, 0xf2, 0x00), PHYREGS(0x08f4, 0x08f0, 0x08ec, 0x01c9, 0x01ca, 0x01cb), }, { .freq = 5725, RADIOREGS3(0x03, 0x01, 0x02, 0x04, 0x79, 0x07, 0x07, 0x04, 0x10, 0x01, 0x05, 0x05, 0x05, 0x8a, 0x06, 0x00, 0x40, 0x06, 0x00, 0x03, 0x00, 0x7f, 0x00, 0x0a, 0x00, 0xf2, 0x00, 0x06, 0x00, 0x03, 0x00, 0x7f, 0x00, 0x0a, 0x00, 0xf2, 0x00), PHYREGS(0x08f6, 0x08f2, 0x08ee, 0x01c9, 0x01ca, 0x01cb), }, { .freq = 5730, RADIOREGS3(0x0a, 0x01, 0x01, 0x02, 0x3d, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x05, 0x05, 0x05, 0x8a, 0x06, 0x00, 0x40, 0x06, 0x00, 0x03, 0x00, 0x7f, 0x00, 0x0a, 0x00, 0xf2, 0x00, 0x06, 0x00, 0x03, 0x00, 0x7f, 0x00, 0x0a, 0x00, 0xf2, 0x00), PHYREGS(0x08f8, 0x08f4, 0x08f0, 0x01c9, 0x01c9, 0x01ca), }, { .freq = 5735, RADIOREGS3(0x03, 0x01, 0x02, 0x04, 0x7b, 0x07, 0x07, 0x04, 0x10, 0x01, 0x05, 0x05, 0x05, 0x8a, 0x06, 0x00, 0x40, 0x06, 0x00, 0x03, 0x00, 0x7f, 0x00, 0x0a, 0x00, 0xf2, 0x00, 0x06, 0x00, 0x03, 0x00, 0x7f, 0x00, 0x0a, 0x00, 0xf2, 0x00), PHYREGS(0x08fa, 0x08f6, 0x08f2, 0x01c8, 0x01c9, 0x01ca), }, { .freq = 5740, RADIOREGS3(0x0a, 0x01, 0x01, 0x02, 0x3e, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x05, 0x05, 0x05, 0x8a, 0x06, 0x00, 0x40, 0x06, 0x00, 0x03, 0x00, 0x7f, 0x00, 0x0a, 0x00, 0xf2, 0x00, 0x06, 0x00, 0x03, 0x00, 0x7f, 0x00, 0x0a, 0x00, 0xf2, 0x00), PHYREGS(0x08fc, 0x08f8, 0x08f4, 0x01c8, 0x01c9, 0x01c9), }, { .freq = 5745, RADIOREGS3(0xfe, 0x00, 0x02, 0x04, 0x7d, 0x07, 0x07, 0x04, 0x10, 0x01, 0x05, 0x05, 0x05, 0x8a, 0x06, 0x00, 0x40, 0x06, 0x00, 0x03, 0x00, 0x7f, 0x00, 0x0a, 0x00, 0xf2, 0x00, 0x06, 0x00, 0x03, 0x00, 0x7f, 0x00, 0x0a, 0x00, 0xf2, 0x00), PHYREGS(0x08fe, 0x08fa, 0x08f6, 0x01c8, 0x01c8, 0x01c9), }, { .freq = 5750, RADIOREGS3(0x0a, 0x01, 0x01, 0x02, 0x3f, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x05, 0x05, 0x05, 0x8a, 0x06, 0x00, 0x40, 0x06, 0x00, 0x03, 0x00, 0x7f, 0x00, 0x0a, 0x00, 0xf2, 0x00, 0x06, 0x00, 0x03, 0x00, 0x7f, 0x00, 0x0a, 0x00, 0xf2, 0x00), PHYREGS(0x0900, 0x08fc, 0x08f8, 0x01c7, 0x01c8, 0x01c9), }, { .freq = 5755, RADIOREGS3(0xfe, 0x00, 0x02, 0x04, 0x7f, 0x07, 0x07, 0x04, 0x10, 0x01, 0x05, 0x05, 0x05, 0x8a, 0x06, 0x00, 0x40, 0x05, 0x00, 0x03, 0x00, 0x7f, 0x00, 0x0a, 0x00, 0xf2, 0x00, 0x05, 0x00, 0x03, 0x00, 0x7f, 0x00, 0x0a, 0x00, 0xf2, 0x00), PHYREGS(0x0902, 0x08fe, 0x08fa, 0x01c7, 0x01c8, 0x01c8), }, { .freq = 5760, RADIOREGS3(0x0a, 0x01, 0x01, 0x02, 0x40, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x05, 0x05, 0x05, 0x8a, 0x06, 0x00, 0x40, 0x05, 0x00, 0x03, 0x00, 0x7f, 0x00, 0x0a, 0x00, 0xf2, 0x00, 0x05, 0x00, 0x03, 0x00, 0x7f, 0x00, 0x0a, 0x00, 0xf2, 0x00), PHYREGS(0x0904, 0x0900, 0x08fc, 0x01c6, 0x01c7, 0x01c8), }, { .freq = 5765, RADIOREGS3(0xf8, 0x00, 0x02, 0x04, 0x81, 0x07, 0x07, 0x04, 0x10, 0x01, 0x05, 0x05, 0x05, 0x8a, 0x06, 0x00, 0x40, 0x05, 0x00, 0x03, 0x00, 0x7f, 0x00, 0x0a, 0x00, 0xf2, 0x00, 0x05, 0x00, 0x03, 0x00, 0x7f, 0x00, 0x0a, 0x00, 0xf2, 0x00), PHYREGS(0x0906, 0x0902, 0x08fe, 0x01c6, 0x01c7, 0x01c8), }, { .freq = 5770, RADIOREGS3(0x0a, 0x01, 0x01, 0x02, 0x41, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x05, 0x05, 0x05, 0x8a, 0x06, 0x00, 0x40, 0x05, 0x00, 0x03, 0x00, 0x7f, 0x00, 0x0a, 0x00, 0xf2, 0x00, 0x05, 0x00, 0x03, 0x00, 0x7f, 0x00, 0x0a, 0x00, 0xf2, 0x00), PHYREGS(0x0908, 0x0904, 0x0900, 0x01c6, 0x01c6, 0x01c7), }, { .freq = 5775, RADIOREGS3(0xf8, 0x00, 0x02, 0x04, 0x83, 0x07, 0x07, 0x04, 0x10, 0x01, 0x05, 0x05, 0x05, 0x8a, 0x06, 0x00, 0x40, 0x05, 0x00, 0x03, 0x00, 0x7f, 0x00, 0x0a, 0x00, 0xf2, 0x00, 0x05, 0x00, 0x03, 0x00, 0x7f, 0x00, 0x0a, 0x00, 0xf2, 0x00), PHYREGS(0x090a, 0x0906, 0x0902, 0x01c5, 0x01c6, 0x01c7), }, { .freq = 5780, RADIOREGS3(0x0a, 0x01, 0x01, 0x02, 0x42, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x05, 0x05, 0x05, 0x8a, 0x06, 0x00, 0x40, 0x05, 0x00, 0x03, 0x00, 0x7f, 0x00, 0x0a, 0x00, 0xf2, 0x00, 0x05, 0x00, 0x03, 0x00, 0x7f, 0x00, 0x0a, 0x00, 0xf2, 0x00), PHYREGS(0x090c, 0x0908, 0x0904, 0x01c5, 0x01c6, 0x01c6), }, { .freq = 5785, RADIOREGS3(0xf2, 0x00, 0x02, 0x04, 0x85, 0x07, 0x07, 0x04, 0x10, 0x01, 0x06, 0x06, 0x06, 0x8a, 0x06, 0x00, 0x40, 0x04, 0x00, 0x03, 0x00, 0x7f, 0x00, 0x0a, 0x00, 0xf2, 0x00, 0x04, 0x00, 0x03, 0x00, 0x7f, 0x00, 0x0a, 0x00, 0xf2, 0x00), PHYREGS(0x090e, 0x090a, 0x0906, 0x01c4, 0x01c5, 0x01c6), }, { .freq = 5790, RADIOREGS3(0x0a, 0x01, 0x01, 0x02, 0x43, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x06, 0x06, 0x06, 0x8a, 0x06, 0x00, 0x40, 0x04, 0x00, 0x03, 0x00, 0x7f, 0x00, 0x0a, 0x00, 0xf2, 0x00, 0x04, 0x00, 0x03, 0x00, 0x7f, 0x00, 0x0a, 0x00, 0xf2, 0x00), PHYREGS(0x0910, 0x090c, 0x0908, 0x01c4, 0x01c5, 0x01c6), }, { .freq = 5795, RADIOREGS3(0xf2, 0x00, 0x02, 0x04, 0x87, 0x07, 0x07, 0x04, 0x10, 0x01, 0x06, 0x06, 0x06, 0x8a, 0x06, 0x00, 0x40, 0x04, 0x00, 0x03, 0x00, 0x7f, 0x00, 0x0a, 0x00, 0xf2, 0x00, 0x04, 0x00, 0x03, 0x00, 0x7f, 0x00, 0x0a, 0x00, 0xf2, 0x00), PHYREGS(0x0912, 0x090e, 0x090a, 0x01c4, 0x01c4, 0x01c5), }, { .freq = 5800, RADIOREGS3(0x0a, 0x01, 0x01, 0x02, 0x44, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x06, 0x06, 0x06, 0x88, 0x04, 0x00, 0x20, 0x04, 0x00, 0x02, 0x00, 0x7f, 0x00, 0x09, 0x00, 0xf0, 0x00, 0x04, 0x00, 0x02, 0x00, 0x7f, 0x00, 0x09, 0x00, 0xf0, 0x00), PHYREGS(0x0914, 0x0910, 0x090c, 0x01c3, 0x01c4, 0x01c5), }, { .freq = 5805, RADIOREGS3(0xed, 0x00, 0x02, 0x04, 0x89, 0x07, 0x07, 0x04, 0x10, 0x01, 0x06, 0x06, 0x06, 0x88, 0x04, 0x00, 0x20, 0x04, 0x00, 0x02, 0x00, 0x7f, 0x00, 0x09, 0x00, 0xf0, 0x00, 0x04, 0x00, 0x02, 0x00, 0x7f, 0x00, 0x09, 0x00, 0xf0, 0x00), PHYREGS(0x0916, 0x0912, 0x090e, 0x01c3, 0x01c4, 0x01c4), }, { .freq = 5810, RADIOREGS3(0x0a, 0x01, 0x01, 0x02, 0x45, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x06, 0x06, 0x06, 0x88, 0x04, 0x00, 0x20, 0x04, 0x00, 0x02, 0x00, 0x7f, 0x00, 0x09, 0x00, 0xf0, 0x00, 0x04, 0x00, 0x02, 0x00, 0x7f, 0x00, 0x09, 0x00, 0xf0, 0x00), PHYREGS(0x0918, 0x0914, 0x0910, 0x01c2, 0x01c3, 0x01c4), }, { .freq = 5815, RADIOREGS3(0xed, 0x00, 0x02, 0x04, 0x8b, 0x07, 0x07, 0x04, 0x10, 0x01, 0x06, 0x06, 0x06, 0x88, 0x04, 0x00, 0x20, 0x04, 0x00, 0x02, 0x00, 0x7f, 0x00, 0x09, 0x00, 0xf0, 0x00, 0x04, 0x00, 0x02, 0x00, 0x7f, 0x00, 0x09, 0x00, 0xf0, 0x00), PHYREGS(0x091a, 0x0916, 0x0912, 0x01c2, 0x01c3, 0x01c4), }, { .freq = 5820, RADIOREGS3(0x0a, 0x01, 0x01, 0x02, 0x46, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x06, 0x06, 0x06, 0x88, 0x04, 0x00, 0x20, 0x03, 0x00, 0x02, 0x00, 0x7f, 0x00, 0x09, 0x00, 0xf0, 0x00, 0x03, 0x00, 0x02, 0x00, 0x7f, 0x00, 0x09, 0x00, 0xf0, 0x00), PHYREGS(0x091c, 0x0918, 0x0914, 0x01c2, 0x01c2, 0x01c3), }, { .freq = 5825, RADIOREGS3(0xed, 0x00, 0x02, 0x04, 0x8d, 0x07, 0x07, 0x04, 0x10, 0x01, 0x06, 0x06, 0x06, 0x88, 0x04, 0x00, 0x20, 0x03, 0x00, 0x02, 0x00, 0x7f, 0x00, 0x09, 0x00, 0xf0, 0x00, 0x03, 0x00, 0x02, 0x00, 0x7f, 0x00, 0x09, 0x00, 0xf0, 0x00), PHYREGS(0x091e, 0x091a, 0x0916, 0x01c1, 0x01c2, 0x01c3), }, { .freq = 5830, RADIOREGS3(0x0a, 0x01, 0x01, 0x02, 0x47, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x06, 0x06, 0x06, 0x88, 0x04, 0x00, 0x20, 0x03, 0x00, 0x02, 0x00, 0x7f, 0x00, 0x09, 0x00, 0xf0, 0x00, 0x03, 0x00, 0x02, 0x00, 0x7f, 0x00, 0x09, 0x00, 0xf0, 0x00), PHYREGS(0x0920, 0x091c, 0x0918, 0x01c1, 0x01c2, 0x01c2), }, { .freq = 5840, RADIOREGS3(0x0a, 0x01, 0x01, 0x02, 0x48, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x06, 0x06, 0x06, 0x88, 0x04, 0x00, 0x20, 0x03, 0x00, 0x02, 0x00, 0x7f, 0x00, 0x09, 0x00, 0xf0, 0x00, 0x03, 0x00, 0x02, 0x00, 0x7f, 0x00, 0x09, 0x00, 0xf0, 0x00), PHYREGS(0x0924, 0x0920, 0x091c, 0x01c0, 0x01c1, 0x01c2), }, { .freq = 5850, RADIOREGS3(0xe0, 0x00, 0x01, 0x02, 0x49, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x06, 0x06, 0x06, 0x88, 0x04, 0x00, 0x20, 0x03, 0x00, 0x02, 0x00, 0x7f, 0x00, 0x09, 0x00, 0xf0, 0x00, 0x03, 0x00, 0x02, 0x00, 0x7f, 0x00, 0x09, 0x00, 0xf0, 0x00), PHYREGS(0x0928, 0x0924, 0x0920, 0x01bf, 0x01c0, 0x01c1), }, { .freq = 5860, RADIOREGS3(0xde, 0x00, 0x01, 0x02, 0x4a, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x06, 0x06, 0x06, 0x88, 0x04, 0x00, 0x20, 0x03, 0x00, 0x02, 0x00, 0x7f, 0x00, 0x09, 0x00, 0xf0, 0x00, 0x03, 0x00, 0x02, 0x00, 0x7f, 0x00, 0x09, 0x00, 0xf0, 0x00), PHYREGS(0x092c, 0x0928, 0x0924, 0x01bf, 0x01bf, 0x01c0), }, { .freq = 5870, RADIOREGS3(0xdb, 0x00, 0x01, 0x02, 0x4b, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x06, 0x06, 0x06, 0x88, 0x04, 0x00, 0x20, 0x02, 0x00, 0x02, 0x00, 0x7f, 0x00, 0x09, 0x00, 0xf0, 0x00, 0x02, 0x00, 0x02, 0x00, 0x7f, 0x00, 0x09, 0x00, 0xf0, 0x00), PHYREGS(0x0930, 0x092c, 0x0928, 0x01be, 0x01bf, 0x01bf), }, { .freq = 5880, RADIOREGS3(0xd8, 0x00, 0x01, 0x02, 0x4c, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x06, 0x06, 0x06, 0x88, 0x04, 0x00, 0x20, 0x02, 0x00, 0x02, 0x00, 0x7f, 0x00, 0x09, 0x00, 0xf0, 0x00, 0x02, 0x00, 0x02, 0x00, 0x7f, 0x00, 0x09, 0x00, 0xf0, 0x00), PHYREGS(0x0934, 0x0930, 0x092c, 0x01bd, 0x01be, 0x01bf), }, { .freq = 5890, RADIOREGS3(0xd6, 0x00, 0x01, 0x02, 0x4d, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x06, 0x06, 0x06, 0x88, 0x04, 0x00, 0x20, 0x02, 0x00, 0x02, 0x00, 0x7f, 0x00, 0x09, 0x00, 0xf0, 0x00, 0x02, 0x00, 0x02, 0x00, 0x7f, 0x00, 0x09, 0x00, 0xf0, 0x00), PHYREGS(0x0938, 0x0934, 0x0930, 0x01bc, 0x01bd, 0x01be), }, { .freq = 5900, RADIOREGS3(0xd3, 0x00, 0x01, 0x02, 0x4e, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x06, 0x06, 0x06, 0x87, 0x03, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x7f, 0x00, 0x07, 0x00, 0xf0, 0x00, 0x02, 0x00, 0x00, 0x00, 0x7f, 0x00, 0x07, 0x00, 0xf0, 0x00), PHYREGS(0x093c, 0x0938, 0x0934, 0x01bc, 0x01bc, 0x01bd), }, { .freq = 5910, RADIOREGS3(0xd6, 0x00, 0x01, 0x02, 0x4f, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x06, 0x06, 0x06, 0x87, 0x03, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x7f, 0x00, 0x07, 0x00, 0xf0, 0x00, 0x01, 0x00, 0x00, 0x00, 0x7f, 0x00, 0x07, 0x00, 0xf0, 0x00), PHYREGS(0x0940, 0x093c, 0x0938, 0x01bb, 0x01bc, 0x01bc), }, { .freq = 2412, RADIOREGS3(0x00, 0x01, 0x03, 0x09, 0x6c, 0x08, 0x08, 0x04, 0x16, 0x01, 0x04, 0x04, 0x04, 0x8f, 0x30, 0x00, 0x00, 0x00, 0xff, 0x00, 0x04, 0x00, 0x70, 0x00, 0x0f, 0x00, 0x0e, 0x00, 0xff, 0x00, 0x04, 0x00, 0x70, 0x00, 0x0f, 0x00, 0x0e), PHYREGS(0x03c9, 0x03c5, 0x03c1, 0x043a, 0x043f, 0x0443), }, { .freq = 2417, RADIOREGS3(0x00, 0x01, 0x03, 0x09, 0x71, 0x08, 0x08, 0x04, 0x16, 0x01, 0x05, 0x05, 0x05, 0x8f, 0x30, 0x00, 0x00, 0x00, 0xff, 0x00, 0x04, 0x00, 0x70, 0x00, 0x0f, 0x00, 0x0e, 0x00, 0xff, 0x00, 0x04, 0x00, 0x70, 0x00, 0x0f, 0x00, 0x0e), PHYREGS(0x03cb, 0x03c7, 0x03c3, 0x0438, 0x043d, 0x0441), }, { .freq = 2422, RADIOREGS3(0x00, 0x01, 0x03, 0x09, 0x76, 0x08, 0x08, 0x04, 0x16, 0x01, 0x05, 0x05, 0x05, 0x8f, 0x30, 0x00, 0x00, 0x00, 0xff, 0x00, 0x04, 0x00, 0x70, 0x00, 0x0f, 0x00, 0x0e, 0x00, 0xff, 0x00, 0x04, 0x00, 0x70, 0x00, 0x0f, 0x00, 0x0e), PHYREGS(0x03cd, 0x03c9, 0x03c5, 0x0436, 0x043a, 0x043f), }, { .freq = 2427, RADIOREGS3(0x00, 0x01, 0x03, 0x09, 0x7b, 0x08, 0x08, 0x04, 0x16, 0x01, 0x05, 0x05, 0x05, 0x8f, 0x30, 0x00, 0x00, 0x00, 0xfd, 0x00, 0x04, 0x00, 0x70, 0x00, 0x0f, 0x00, 0x0e, 0x00, 0xfd, 0x00, 0x04, 0x00, 0x70, 0x00, 0x0f, 0x00, 0x0e), PHYREGS(0x03cf, 0x03cb, 0x03c7, 0x0434, 0x0438, 0x043d), }, { .freq = 2432, RADIOREGS3(0x00, 0x01, 0x03, 0x09, 0x80, 0x08, 0x08, 0x04, 0x16, 0x01, 0x05, 0x05, 0x05, 0x8f, 0x30, 0x00, 0x00, 0x00, 0xfb, 0x00, 0x04, 0x00, 0x70, 0x00, 0x0f, 0x00, 0x0e, 0x00, 0xfb, 0x00, 0x04, 0x00, 0x70, 0x00, 0x0f, 0x00, 0x0e), PHYREGS(0x03d1, 0x03cd, 0x03c9, 0x0431, 0x0436, 0x043a), }, { .freq = 2437, RADIOREGS3(0x00, 0x01, 0x03, 0x09, 0x85, 0x08, 0x08, 0x04, 0x16, 0x01, 0x05, 0x05, 0x05, 0x8f, 0x30, 0x00, 0x00, 0x00, 0xfa, 0x00, 0x04, 0x00, 0x70, 0x00, 0x0f, 0x00, 0x0e, 0x00, 0xfa, 0x00, 0x04, 0x00, 0x70, 0x00, 0x0f, 0x00, 0x0e), PHYREGS(0x03d3, 0x03cf, 0x03cb, 0x042f, 0x0434, 0x0438), }, { .freq = 2442, RADIOREGS3(0x00, 0x01, 0x03, 0x09, 0x8a, 0x08, 0x08, 0x04, 0x16, 0x01, 0x05, 0x05, 0x05, 0x8f, 0x30, 0x00, 0x00, 0x00, 0xf8, 0x00, 0x04, 0x00, 0x70, 0x00, 0x0f, 0x00, 0x0e, 0x00, 0xf8, 0x00, 0x04, 0x00, 0x70, 0x00, 0x0f, 0x00, 0x0e), PHYREGS(0x03d5, 0x03d1, 0x03cd, 0x042d, 0x0431, 0x0436), }, { .freq = 2447, RADIOREGS3(0x00, 0x01, 0x03, 0x09, 0x8f, 0x08, 0x08, 0x04, 0x16, 0x01, 0x06, 0x06, 0x06, 0x8f, 0x30, 0x00, 0x00, 0x00, 0xf7, 0x00, 0x04, 0x00, 0x70, 0x00, 0x0f, 0x00, 0x0e, 0x00, 0xf7, 0x00, 0x04, 0x00, 0x70, 0x00, 0x0f, 0x00, 0x0e), PHYREGS(0x03d7, 0x03d3, 0x03cf, 0x042b, 0x042f, 0x0434), }, { .freq = 2452, RADIOREGS3(0x00, 0x01, 0x03, 0x09, 0x94, 0x08, 0x08, 0x04, 0x16, 0x01, 0x06, 0x06, 0x06, 0x8f, 0x30, 0x00, 0x00, 0x00, 0xf6, 0x00, 0x04, 0x00, 0x70, 0x00, 0x0f, 0x00, 0x0e, 0x00, 0xf6, 0x00, 0x04, 0x00, 0x70, 0x00, 0x0f, 0x00, 0x0e), PHYREGS(0x03d9, 0x03d5, 0x03d1, 0x0429, 0x042d, 0x0431), }, { .freq = 2457, RADIOREGS3(0x00, 0x01, 0x03, 0x09, 0x99, 0x08, 0x08, 0x04, 0x16, 0x01, 0x06, 0x06, 0x06, 0x8f, 0x30, 0x00, 0x00, 0x00, 0xf5, 0x00, 0x04, 0x00, 0x70, 0x00, 0x0f, 0x00, 0x0e, 0x00, 0xf5, 0x00, 0x04, 0x00, 0x70, 0x00, 0x0f, 0x00, 0x0e), PHYREGS(0x03db, 0x03d7, 0x03d3, 0x0427, 0x042b, 0x042f), }, { .freq = 2462, RADIOREGS3(0x00, 0x01, 0x03, 0x09, 0x9e, 0x08, 0x08, 0x04, 0x16, 0x01, 0x06, 0x06, 0x06, 0x8f, 0x30, 0x00, 0x00, 0x00, 0xf4, 0x00, 0x04, 0x00, 0x70, 0x00, 0x0f, 0x00, 0x0e, 0x00, 0xf4, 0x00, 0x04, 0x00, 0x70, 0x00, 0x0f, 0x00, 0x0e), PHYREGS(0x03dd, 0x03d9, 0x03d5, 0x0424, 0x0429, 0x042d), }, { .freq = 2467, RADIOREGS3(0x00, 0x01, 0x03, 0x09, 0xa3, 0x08, 0x08, 0x04, 0x16, 0x01, 0x06, 0x06, 0x06, 0x8f, 0x30, 0x00, 0x00, 0x00, 0xf3, 0x00, 0x04, 0x00, 0x70, 0x00, 0x0f, 0x00, 0x0e, 0x00, 0xf3, 0x00, 0x04, 0x00, 0x70, 0x00, 0x0f, 0x00, 0x0e), PHYREGS(0x03df, 0x03db, 0x03d7, 0x0422, 0x0427, 0x042b), }, { .freq = 2472, RADIOREGS3(0x00, 0x01, 0x03, 0x09, 0xa8, 0x08, 0x08, 0x04, 0x16, 0x01, 0x07, 0x07, 0x07, 0x8f, 0x30, 0x00, 0x00, 0x00, 0xf2, 0x00, 0x04, 0x00, 0x70, 0x00, 0x0f, 0x00, 0x0e, 0x00, 0xf2, 0x00, 0x04, 0x00, 0x70, 0x00, 0x0f, 0x00, 0x0e), PHYREGS(0x03e1, 0x03dd, 0x03d9, 0x0420, 0x0424, 0x0429), }, { .freq = 2484, RADIOREGS3(0xff, 0x01, 0x03, 0x09, 0xb4, 0x08, 0x08, 0x04, 0x16, 0x01, 0x07, 0x07, 0x07, 0x8f, 0x30, 0x00, 0x00, 0x00, 0xf0, 0x00, 0x04, 0x00, 0x70, 0x00, 0x0f, 0x00, 0x0e, 0x00, 0xf0, 0x00, 0x04, 0x00, 0x70, 0x00, 0x0f, 0x00, 0x0e), PHYREGS(0x03e6, 0x03e2, 0x03de, 0x041b, 0x041f, 0x0424), }, }; static const struct b43_nphy_channeltab_entry_rev3 b43_nphy_channeltab_radio_rev5[] = { { .freq = 4920, RADIOREGS3(0xff, 0x01, 0x01, 0x01, 0xec, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x00, 0x00, 0x00, 0x8f, 0x0f, 0x00, 0xff, 0xff, 0x00, 0x0b, 0x00, 0x70, 0x00, 0x0f, 0x00, 0x9f, 0x00, 0xff, 0x00, 0x0b, 0x00, 0x70, 0x00, 0x0f, 0x00, 0x6f, 0x00), PHYREGS(0x07b4, 0x07b0, 0x07ac, 0x0214, 0x0215, 0x0216), }, { .freq = 4930, RADIOREGS3(0xff, 0x01, 0x01, 0x01, 0xed, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x00, 0x00, 0x00, 0x8f, 0x0f, 0x00, 0xff, 0xff, 0x00, 0x0b, 0x00, 0x70, 0x00, 0x0e, 0x00, 0x9f, 0x00, 0xff, 0x00, 0x0b, 0x00, 0x70, 0x00, 0x0e, 0x00, 0x6f, 0x00), PHYREGS(0x07b8, 0x07b4, 0x07b0, 0x0213, 0x0214, 0x0215), }, { .freq = 4940, RADIOREGS3(0xff, 0x01, 0x01, 0x01, 0xee, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x00, 0x00, 0x00, 0x8f, 0x0f, 0x00, 0xff, 0xff, 0x00, 0x0b, 0x00, 0x70, 0x00, 0x0e, 0x00, 0x9f, 0x00, 0xff, 0x00, 0x0b, 0x00, 0x70, 0x00, 0x0e, 0x00, 0x6f, 0x00), PHYREGS(0x07bc, 0x07b8, 0x07b4, 0x0212, 0x0213, 0x0214), }, { .freq = 4950, RADIOREGS3(0xff, 0x01, 0x01, 0x01, 0xef, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x00, 0x00, 0x00, 0x8f, 0x0f, 0x00, 0xff, 0xff, 0x00, 0x0b, 0x00, 0x70, 0x00, 0x0e, 0x00, 0x9f, 0x00, 0xff, 0x00, 0x0b, 0x00, 0x70, 0x00, 0x0e, 0x00, 0x6f, 0x00), PHYREGS(0x07c0, 0x07bc, 0x07b8, 0x0211, 0x0212, 0x0213), }, { .freq = 4960, RADIOREGS3(0xff, 0x01, 0x01, 0x01, 0xf0, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x01, 0x01, 0x01, 0x8f, 0x0f, 0x00, 0xff, 0xff, 0x00, 0x0a, 0x00, 0x70, 0x00, 0x0e, 0x00, 0x9f, 0x00, 0xff, 0x00, 0x0a, 0x00, 0x70, 0x00, 0x0e, 0x00, 0x6f, 0x00), PHYREGS(0x07c4, 0x07c0, 0x07bc, 0x020f, 0x0211, 0x0212), }, { .freq = 4970, RADIOREGS3(0xff, 0x01, 0x01, 0x01, 0xf1, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x01, 0x01, 0x01, 0x8f, 0x0f, 0x00, 0xff, 0xff, 0x00, 0x0a, 0x00, 0x70, 0x00, 0x0d, 0x00, 0x9f, 0x00, 0xff, 0x00, 0x0a, 0x00, 0x70, 0x00, 0x0d, 0x00, 0x6f, 0x00), PHYREGS(0x07c8, 0x07c4, 0x07c0, 0x020e, 0x020f, 0x0211), }, { .freq = 4980, RADIOREGS3(0xff, 0x01, 0x01, 0x01, 0xf2, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x01, 0x01, 0x01, 0x8f, 0x0f, 0x00, 0xff, 0xff, 0x00, 0x0a, 0x00, 0x70, 0x00, 0x0d, 0x00, 0x9f, 0x00, 0xff, 0x00, 0x0a, 0x00, 0x70, 0x00, 0x0d, 0x00, 0x6f, 0x00), PHYREGS(0x07cc, 0x07c8, 0x07c4, 0x020d, 0x020e, 0x020f), }, { .freq = 4990, RADIOREGS3(0xff, 0x01, 0x01, 0x01, 0xf3, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x01, 0x01, 0x01, 0x8f, 0x0f, 0x00, 0xff, 0xff, 0x00, 0x0a, 0x00, 0x70, 0x00, 0x0d, 0x00, 0x9f, 0x00, 0xff, 0x00, 0x0a, 0x00, 0x70, 0x00, 0x0d, 0x00, 0x6f, 0x00), PHYREGS(0x07d0, 0x07cc, 0x07c8, 0x020c, 0x020d, 0x020e), }, { .freq = 5000, RADIOREGS3(0xff, 0x01, 0x01, 0x01, 0xf4, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x01, 0x01, 0x01, 0x8f, 0x0f, 0x00, 0xff, 0xff, 0x00, 0x0a, 0x00, 0x70, 0x00, 0x0d, 0x00, 0x9f, 0x00, 0xff, 0x00, 0x0a, 0x00, 0x70, 0x00, 0x0d, 0x00, 0x6f, 0x00), PHYREGS(0x07d4, 0x07d0, 0x07cc, 0x020b, 0x020c, 0x020d), }, { .freq = 5010, RADIOREGS3(0xff, 0x01, 0x01, 0x01, 0xf5, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x01, 0x01, 0x01, 0x8f, 0x0f, 0x00, 0xff, 0xff, 0x00, 0x0a, 0x00, 0x70, 0x00, 0x0d, 0x00, 0x9f, 0x00, 0xff, 0x00, 0x0a, 0x00, 0x70, 0x00, 0x0d, 0x00, 0x6f, 0x00), PHYREGS(0x07d8, 0x07d4, 0x07d0, 0x020a, 0x020b, 0x020c), }, { .freq = 5020, RADIOREGS3(0xf7, 0x01, 0x01, 0x01, 0xf6, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x01, 0x01, 0x01, 0x8f, 0x0f, 0x00, 0xff, 0xff, 0x00, 0x09, 0x00, 0x70, 0x00, 0x0d, 0x00, 0x9f, 0x00, 0xff, 0x00, 0x09, 0x00, 0x70, 0x00, 0x0d, 0x00, 0x6f, 0x00), PHYREGS(0x07dc, 0x07d8, 0x07d4, 0x0209, 0x020a, 0x020b), }, { .freq = 5030, RADIOREGS3(0xf7, 0x01, 0x01, 0x01, 0xf7, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x01, 0x01, 0x01, 0x8f, 0x0f, 0x00, 0xff, 0xff, 0x00, 0x09, 0x00, 0x70, 0x00, 0x0c, 0x00, 0x9f, 0x00, 0xff, 0x00, 0x09, 0x00, 0x70, 0x00, 0x0c, 0x00, 0x6f, 0x00), PHYREGS(0x07e0, 0x07dc, 0x07d8, 0x0208, 0x0209, 0x020a), }, { .freq = 5040, RADIOREGS3(0xef, 0x01, 0x01, 0x01, 0xf8, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x01, 0x01, 0x01, 0x8f, 0x0f, 0x00, 0xff, 0xfe, 0x00, 0x09, 0x00, 0x70, 0x00, 0x0c, 0x00, 0x9f, 0x00, 0xfe, 0x00, 0x09, 0x00, 0x70, 0x00, 0x0c, 0x00, 0x6f, 0x00), PHYREGS(0x07e4, 0x07e0, 0x07dc, 0x0207, 0x0208, 0x0209), }, { .freq = 5050, RADIOREGS3(0xef, 0x01, 0x01, 0x01, 0xf9, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x01, 0x01, 0x01, 0x8f, 0x0f, 0x00, 0xff, 0xfe, 0x00, 0x09, 0x00, 0x70, 0x00, 0x0c, 0x00, 0x9f, 0x00, 0xfe, 0x00, 0x09, 0x00, 0x70, 0x00, 0x0c, 0x00, 0x6f, 0x00), PHYREGS(0x07e8, 0x07e4, 0x07e0, 0x0206, 0x0207, 0x0208), }, { .freq = 5060, RADIOREGS3(0xe6, 0x01, 0x01, 0x01, 0xfa, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x01, 0x01, 0x01, 0x8f, 0x0f, 0x00, 0xff, 0xfd, 0x00, 0x09, 0x00, 0x70, 0x00, 0x0c, 0x00, 0x9f, 0x00, 0xfd, 0x00, 0x09, 0x00, 0x70, 0x00, 0x0c, 0x00, 0x6f, 0x00), PHYREGS(0x07ec, 0x07e8, 0x07e4, 0x0205, 0x0206, 0x0207), }, { .freq = 5070, RADIOREGS3(0xe6, 0x01, 0x01, 0x01, 0xfb, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x01, 0x01, 0x01, 0x8f, 0x0f, 0x00, 0xff, 0xfd, 0x00, 0x08, 0x00, 0x70, 0x00, 0x0b, 0x00, 0x9f, 0x00, 0xfd, 0x00, 0x08, 0x00, 0x70, 0x00, 0x0b, 0x00, 0x6f, 0x00), PHYREGS(0x07f0, 0x07ec, 0x07e8, 0x0204, 0x0205, 0x0206), }, { .freq = 5080, RADIOREGS3(0xde, 0x01, 0x01, 0x01, 0xfc, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x01, 0x01, 0x01, 0x8f, 0x0f, 0x00, 0xff, 0xfc, 0x00, 0x08, 0x00, 0x70, 0x00, 0x0b, 0x00, 0x9f, 0x00, 0xfc, 0x00, 0x08, 0x00, 0x70, 0x00, 0x0b, 0x00, 0x6f, 0x00), PHYREGS(0x07f4, 0x07f0, 0x07ec, 0x0203, 0x0204, 0x0205), }, { .freq = 5090, RADIOREGS3(0xde, 0x01, 0x01, 0x01, 0xfd, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x01, 0x01, 0x01, 0x8f, 0x0f, 0x00, 0xff, 0xfc, 0x00, 0x08, 0x00, 0x70, 0x00, 0x0b, 0x00, 0x9f, 0x00, 0xfc, 0x00, 0x08, 0x00, 0x70, 0x00, 0x0b, 0x00, 0x6f, 0x00), PHYREGS(0x07f8, 0x07f4, 0x07f0, 0x0202, 0x0203, 0x0204), }, { .freq = 5100, RADIOREGS3(0xd6, 0x01, 0x01, 0x01, 0xfe, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x02, 0x02, 0x02, 0x8f, 0x0f, 0x00, 0xff, 0xfc, 0x00, 0x08, 0x00, 0x70, 0x00, 0x0b, 0x00, 0x9f, 0x00, 0xfc, 0x00, 0x08, 0x00, 0x70, 0x00, 0x0b, 0x00, 0x6f, 0x00), PHYREGS(0x07fc, 0x07f8, 0x07f4, 0x0201, 0x0202, 0x0203), }, { .freq = 5110, RADIOREGS3(0xd6, 0x01, 0x01, 0x01, 0xff, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x02, 0x02, 0x02, 0x8f, 0x0f, 0x00, 0xff, 0xfc, 0x00, 0x08, 0x00, 0x70, 0x00, 0x0b, 0x00, 0x9f, 0x00, 0xfc, 0x00, 0x08, 0x00, 0x70, 0x00, 0x0b, 0x00, 0x6f, 0x00), PHYREGS(0x0800, 0x07fc, 0x07f8, 0x0200, 0x0201, 0x0202), }, { .freq = 5120, RADIOREGS3(0xce, 0x01, 0x01, 0x02, 0x00, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x02, 0x02, 0x02, 0x8f, 0x0f, 0x00, 0xff, 0xfc, 0x00, 0x08, 0x00, 0x70, 0x00, 0x0b, 0x00, 0x9f, 0x00, 0xfc, 0x00, 0x08, 0x00, 0x70, 0x00, 0x0b, 0x00, 0x6f, 0x00), PHYREGS(0x0804, 0x0800, 0x07fc, 0x01ff, 0x0200, 0x0201), }, { .freq = 5130, RADIOREGS3(0xce, 0x01, 0x01, 0x02, 0x01, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x02, 0x02, 0x02, 0x8f, 0x0f, 0x00, 0xff, 0xfb, 0x00, 0x08, 0x00, 0x70, 0x00, 0x0a, 0x00, 0x9f, 0x00, 0xfb, 0x00, 0x08, 0x00, 0x70, 0x00, 0x0a, 0x00, 0x6f, 0x00), PHYREGS(0x0808, 0x0804, 0x0800, 0x01fe, 0x01ff, 0x0200), }, { .freq = 5140, RADIOREGS3(0xc6, 0x01, 0x01, 0x02, 0x02, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x02, 0x02, 0x02, 0x8f, 0x0f, 0x00, 0xff, 0xfb, 0x00, 0x07, 0x00, 0x70, 0x00, 0x0a, 0x00, 0x9f, 0x00, 0xfb, 0x00, 0x07, 0x00, 0x70, 0x00, 0x0a, 0x00, 0x6f, 0x00), PHYREGS(0x080c, 0x0808, 0x0804, 0x01fd, 0x01fe, 0x01ff), }, { .freq = 5160, RADIOREGS3(0xbe, 0x01, 0x01, 0x02, 0x04, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x02, 0x02, 0x02, 0x8f, 0x0f, 0x00, 0xff, 0xfb, 0x00, 0x07, 0x00, 0x70, 0x00, 0x09, 0x00, 0x9e, 0x00, 0xfb, 0x00, 0x07, 0x00, 0x70, 0x00, 0x09, 0x00, 0x6e, 0x00), PHYREGS(0x0814, 0x0810, 0x080c, 0x01fb, 0x01fc, 0x01fd), }, { .freq = 5170, RADIOREGS3(0xbe, 0x01, 0x01, 0x02, 0x05, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x02, 0x02, 0x02, 0x8f, 0x0f, 0x00, 0xff, 0xfb, 0x00, 0x06, 0x00, 0x70, 0x00, 0x09, 0x00, 0x9e, 0x00, 0xfb, 0x00, 0x06, 0x00, 0x70, 0x00, 0x09, 0x00, 0x6e, 0x00), PHYREGS(0x0818, 0x0814, 0x0810, 0x01fa, 0x01fb, 0x01fc), }, { .freq = 5180, RADIOREGS3(0xb6, 0x01, 0x01, 0x02, 0x06, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x02, 0x02, 0x02, 0x8f, 0x0f, 0x00, 0xff, 0xfa, 0x00, 0x06, 0x00, 0x70, 0x00, 0x09, 0x00, 0x9e, 0x00, 0xfa, 0x00, 0x06, 0x00, 0x70, 0x00, 0x09, 0x00, 0x6e, 0x00), PHYREGS(0x081c, 0x0818, 0x0814, 0x01f9, 0x01fa, 0x01fb), }, { .freq = 5190, RADIOREGS3(0xb6, 0x01, 0x01, 0x02, 0x07, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x02, 0x02, 0x02, 0x8f, 0x0f, 0x00, 0xff, 0xfa, 0x00, 0x06, 0x00, 0x70, 0x00, 0x09, 0x00, 0x9e, 0x00, 0xfa, 0x00, 0x06, 0x00, 0x70, 0x00, 0x09, 0x00, 0x6e, 0x00), PHYREGS(0x0820, 0x081c, 0x0818, 0x01f8, 0x01f9, 0x01fa), }, { .freq = 5200, RADIOREGS3(0xaf, 0x01, 0x01, 0x02, 0x08, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x02, 0x02, 0x02, 0x8f, 0x0f, 0x00, 0xff, 0xfa, 0x00, 0x06, 0x00, 0x70, 0x00, 0x09, 0x00, 0x9e, 0x00, 0xfa, 0x00, 0x06, 0x00, 0x70, 0x00, 0x09, 0x00, 0x6e, 0x00), PHYREGS(0x0824, 0x0820, 0x081c, 0x01f7, 0x01f8, 0x01f9), }, { .freq = 5210, RADIOREGS3(0xaf, 0x01, 0x01, 0x02, 0x09, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x02, 0x02, 0x02, 0x8f, 0x0f, 0x00, 0xff, 0xfa, 0x00, 0x06, 0x00, 0x70, 0x00, 0x09, 0x00, 0x9e, 0x00, 0xfa, 0x00, 0x06, 0x00, 0x70, 0x00, 0x09, 0x00, 0x6e, 0x00), PHYREGS(0x0828, 0x0824, 0x0820, 0x01f6, 0x01f7, 0x01f8), }, { .freq = 5220, RADIOREGS3(0xa7, 0x01, 0x01, 0x02, 0x0a, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x02, 0x02, 0x02, 0x8f, 0x0f, 0x00, 0xff, 0xfa, 0x00, 0x06, 0x00, 0x70, 0x00, 0x09, 0x00, 0x9e, 0x00, 0xfa, 0x00, 0x06, 0x00, 0x70, 0x00, 0x09, 0x00, 0x6e, 0x00), PHYREGS(0x082c, 0x0828, 0x0824, 0x01f5, 0x01f6, 0x01f7), }, { .freq = 5230, RADIOREGS3(0xa7, 0x01, 0x01, 0x02, 0x0b, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x02, 0x02, 0x02, 0x8f, 0x0f, 0x00, 0xff, 0xea, 0x00, 0x06, 0x00, 0x70, 0x00, 0x08, 0x00, 0x9e, 0x00, 0xea, 0x00, 0x06, 0x00, 0x70, 0x00, 0x08, 0x00, 0x6e, 0x00), PHYREGS(0x0830, 0x082c, 0x0828, 0x01f4, 0x01f5, 0x01f6), }, { .freq = 5240, RADIOREGS3(0xa0, 0x01, 0x01, 0x02, 0x0c, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x02, 0x02, 0x02, 0x8f, 0x0f, 0x00, 0xff, 0xe9, 0x00, 0x05, 0x00, 0x70, 0x00, 0x08, 0x00, 0x9d, 0x00, 0xe9, 0x00, 0x05, 0x00, 0x70, 0x00, 0x08, 0x00, 0x6d, 0x00), PHYREGS(0x0834, 0x0830, 0x082c, 0x01f3, 0x01f4, 0x01f5), }, { .freq = 5250, RADIOREGS3(0xa0, 0x01, 0x01, 0x02, 0x0d, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x02, 0x02, 0x02, 0x8f, 0x0f, 0x00, 0xff, 0xe9, 0x00, 0x05, 0x00, 0x70, 0x00, 0x08, 0x00, 0x9d, 0x00, 0xe9, 0x00, 0x05, 0x00, 0x70, 0x00, 0x08, 0x00, 0x6d, 0x00), PHYREGS(0x0838, 0x0834, 0x0830, 0x01f2, 0x01f3, 0x01f4), }, { .freq = 5260, RADIOREGS3(0x98, 0x01, 0x01, 0x02, 0x0e, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x02, 0x02, 0x02, 0x8f, 0x0f, 0x00, 0xff, 0xd9, 0x00, 0x05, 0x00, 0x70, 0x00, 0x08, 0x00, 0x9d, 0x00, 0xd9, 0x00, 0x05, 0x00, 0x70, 0x00, 0x08, 0x00, 0x6d, 0x00), PHYREGS(0x083c, 0x0838, 0x0834, 0x01f1, 0x01f2, 0x01f3), }, { .freq = 5270, RADIOREGS3(0x98, 0x01, 0x01, 0x02, 0x0f, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x03, 0x03, 0x03, 0x8f, 0x0f, 0x00, 0xff, 0xd8, 0x00, 0x04, 0x00, 0x70, 0x00, 0x07, 0x00, 0x9c, 0x00, 0xd8, 0x00, 0x04, 0x00, 0x70, 0x00, 0x07, 0x00, 0x6c, 0x00), PHYREGS(0x0840, 0x083c, 0x0838, 0x01f0, 0x01f1, 0x01f2), }, { .freq = 5280, RADIOREGS3(0x91, 0x01, 0x01, 0x02, 0x10, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x03, 0x03, 0x03, 0x8f, 0x0f, 0x00, 0xff, 0xc8, 0x00, 0x04, 0x00, 0x70, 0x00, 0x07, 0x00, 0x9c, 0x00, 0xc8, 0x00, 0x04, 0x00, 0x70, 0x00, 0x07, 0x00, 0x6c, 0x00), PHYREGS(0x0844, 0x0840, 0x083c, 0x01f0, 0x01f0, 0x01f1), }, { .freq = 5290, RADIOREGS3(0x91, 0x01, 0x01, 0x02, 0x11, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x03, 0x03, 0x03, 0x8f, 0x0f, 0x00, 0xff, 0xc8, 0x00, 0x04, 0x00, 0x70, 0x00, 0x07, 0x00, 0x9c, 0x00, 0xc8, 0x00, 0x04, 0x00, 0x70, 0x00, 0x07, 0x00, 0x6c, 0x00), PHYREGS(0x0848, 0x0844, 0x0840, 0x01ef, 0x01f0, 0x01f0), }, { .freq = 5300, RADIOREGS3(0x8a, 0x01, 0x01, 0x02, 0x12, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x03, 0x03, 0x03, 0x8f, 0x0e, 0x00, 0xff, 0xc8, 0x00, 0x04, 0x00, 0x70, 0x00, 0x07, 0x00, 0x9c, 0x00, 0xc8, 0x00, 0x04, 0x00, 0x70, 0x00, 0x07, 0x00, 0x6c, 0x00), PHYREGS(0x084c, 0x0848, 0x0844, 0x01ee, 0x01ef, 0x01f0), }, { .freq = 5310, RADIOREGS3(0x8a, 0x01, 0x01, 0x02, 0x13, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x03, 0x03, 0x03, 0x8f, 0x0e, 0x00, 0xff, 0xc8, 0x00, 0x04, 0x00, 0x70, 0x00, 0x07, 0x00, 0x9c, 0x00, 0xc8, 0x00, 0x04, 0x00, 0x70, 0x00, 0x07, 0x00, 0x6c, 0x00), PHYREGS(0x0850, 0x084c, 0x0848, 0x01ed, 0x01ee, 0x01ef), }, { .freq = 5320, RADIOREGS3(0x83, 0x01, 0x01, 0x02, 0x14, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x03, 0x03, 0x03, 0x8f, 0x0e, 0x00, 0xff, 0xb8, 0x00, 0x04, 0x00, 0x70, 0x00, 0x07, 0x00, 0x9c, 0x00, 0xb8, 0x00, 0x04, 0x00, 0x70, 0x00, 0x07, 0x00, 0x6c, 0x00), PHYREGS(0x0854, 0x0850, 0x084c, 0x01ec, 0x01ed, 0x01ee), }, { .freq = 5330, RADIOREGS3(0x83, 0x01, 0x01, 0x02, 0x15, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x03, 0x03, 0x03, 0x8f, 0x0e, 0x00, 0xff, 0xb7, 0x00, 0x04, 0x00, 0x70, 0x00, 0x07, 0x00, 0x9b, 0x00, 0xb7, 0x00, 0x04, 0x00, 0x70, 0x00, 0x07, 0x00, 0x6b, 0x00), PHYREGS(0x0858, 0x0854, 0x0850, 0x01eb, 0x01ec, 0x01ed), }, { .freq = 5340, RADIOREGS3(0x7c, 0x01, 0x01, 0x02, 0x16, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x03, 0x03, 0x03, 0x8f, 0x0e, 0x00, 0xff, 0xb7, 0x00, 0x03, 0x00, 0x70, 0x00, 0x07, 0x00, 0x9b, 0x00, 0xb7, 0x00, 0x03, 0x00, 0x70, 0x00, 0x07, 0x00, 0x6b, 0x00), PHYREGS(0x085c, 0x0858, 0x0854, 0x01ea, 0x01eb, 0x01ec), }, { .freq = 5350, RADIOREGS3(0x7c, 0x01, 0x01, 0x02, 0x17, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x03, 0x03, 0x03, 0x8f, 0x0e, 0x00, 0xff, 0xa7, 0x00, 0x03, 0x00, 0x70, 0x00, 0x06, 0x00, 0x9b, 0x00, 0xa7, 0x00, 0x03, 0x00, 0x70, 0x00, 0x06, 0x00, 0x6b, 0x00), PHYREGS(0x0860, 0x085c, 0x0858, 0x01e9, 0x01ea, 0x01eb), }, { .freq = 5360, RADIOREGS3(0x75, 0x01, 0x01, 0x02, 0x18, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x03, 0x03, 0x03, 0x8f, 0x0e, 0x00, 0xff, 0xa6, 0x00, 0x03, 0x00, 0x70, 0x00, 0x06, 0x00, 0x9b, 0x00, 0xa6, 0x00, 0x03, 0x00, 0x70, 0x00, 0x06, 0x00, 0x6b, 0x00), PHYREGS(0x0864, 0x0860, 0x085c, 0x01e8, 0x01e9, 0x01ea), }, { .freq = 5370, RADIOREGS3(0x75, 0x01, 0x01, 0x02, 0x19, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x03, 0x03, 0x03, 0x8f, 0x0e, 0x00, 0xff, 0xa6, 0x00, 0x03, 0x00, 0x70, 0x00, 0x06, 0x00, 0x9b, 0x00, 0xa6, 0x00, 0x03, 0x00, 0x70, 0x00, 0x06, 0x00, 0x5b, 0x00), PHYREGS(0x0868, 0x0864, 0x0860, 0x01e7, 0x01e8, 0x01e9), }, { .freq = 5380, RADIOREGS3(0x6e, 0x01, 0x01, 0x02, 0x1a, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x03, 0x03, 0x03, 0x8f, 0x0e, 0x00, 0xff, 0x96, 0x00, 0x03, 0x00, 0x70, 0x00, 0x06, 0x00, 0x9a, 0x00, 0x96, 0x00, 0x03, 0x00, 0x70, 0x00, 0x06, 0x00, 0x5a, 0x00), PHYREGS(0x086c, 0x0868, 0x0864, 0x01e6, 0x01e7, 0x01e8), }, { .freq = 5390, RADIOREGS3(0x6e, 0x01, 0x01, 0x02, 0x1b, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x03, 0x03, 0x03, 0x8f, 0x0e, 0x00, 0xff, 0x95, 0x00, 0x03, 0x00, 0x70, 0x00, 0x06, 0x00, 0x9a, 0x00, 0x95, 0x00, 0x03, 0x00, 0x70, 0x00, 0x06, 0x00, 0x5a, 0x00), PHYREGS(0x0870, 0x086c, 0x0868, 0x01e5, 0x01e6, 0x01e7), }, { .freq = 5400, RADIOREGS3(0x67, 0x01, 0x01, 0x02, 0x1c, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x03, 0x03, 0x03, 0x8d, 0x0d, 0x00, 0xc8, 0x95, 0x00, 0x03, 0x00, 0x70, 0x00, 0x06, 0x00, 0x9a, 0x00, 0x95, 0x00, 0x03, 0x00, 0x70, 0x00, 0x06, 0x00, 0x5a, 0x00), PHYREGS(0x0874, 0x0870, 0x086c, 0x01e5, 0x01e5, 0x01e6), }, { .freq = 5410, RADIOREGS3(0x67, 0x01, 0x01, 0x02, 0x1d, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x03, 0x03, 0x03, 0x8d, 0x0d, 0x00, 0xc8, 0x95, 0x00, 0x03, 0x00, 0x70, 0x00, 0x05, 0x00, 0x9a, 0x00, 0x95, 0x00, 0x03, 0x00, 0x70, 0x00, 0x05, 0x00, 0x5a, 0x00), PHYREGS(0x0878, 0x0874, 0x0870, 0x01e4, 0x01e5, 0x01e5), }, { .freq = 5420, RADIOREGS3(0x61, 0x01, 0x01, 0x02, 0x1e, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x03, 0x03, 0x03, 0x8d, 0x0d, 0x00, 0xc8, 0x95, 0x00, 0x03, 0x00, 0x70, 0x00, 0x05, 0x00, 0x9a, 0x00, 0x95, 0x00, 0x03, 0x00, 0x70, 0x00, 0x05, 0x00, 0x5a, 0x00), PHYREGS(0x087c, 0x0878, 0x0874, 0x01e3, 0x01e4, 0x01e5), }, { .freq = 5430, RADIOREGS3(0x61, 0x01, 0x01, 0x02, 0x1f, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x03, 0x03, 0x03, 0x8d, 0x0d, 0x00, 0xc8, 0x85, 0x00, 0x02, 0x00, 0x70, 0x00, 0x05, 0x00, 0x99, 0x00, 0x85, 0x00, 0x02, 0x00, 0x70, 0x00, 0x05, 0x00, 0x59, 0x00), PHYREGS(0x0880, 0x087c, 0x0878, 0x01e2, 0x01e3, 0x01e4), }, { .freq = 5440, RADIOREGS3(0x5a, 0x01, 0x01, 0x02, 0x20, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x04, 0x04, 0x04, 0x8d, 0x0d, 0x00, 0xc8, 0x84, 0x00, 0x02, 0x00, 0x70, 0x00, 0x05, 0x00, 0x99, 0x00, 0x84, 0x00, 0x02, 0x00, 0x70, 0x00, 0x05, 0x00, 0x59, 0x00), PHYREGS(0x0884, 0x0880, 0x087c, 0x01e1, 0x01e2, 0x01e3), }, { .freq = 5450, RADIOREGS3(0x5a, 0x01, 0x01, 0x02, 0x21, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x04, 0x04, 0x04, 0x8d, 0x0d, 0x00, 0xc8, 0x84, 0x00, 0x02, 0x00, 0x70, 0x00, 0x05, 0x00, 0x99, 0x00, 0x84, 0x00, 0x02, 0x00, 0x70, 0x00, 0x05, 0x00, 0x59, 0x00), PHYREGS(0x0888, 0x0884, 0x0880, 0x01e0, 0x01e1, 0x01e2), }, { .freq = 5460, RADIOREGS3(0x53, 0x01, 0x01, 0x02, 0x22, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x04, 0x04, 0x04, 0x8d, 0x0d, 0x00, 0xc8, 0x84, 0x00, 0x02, 0x00, 0x70, 0x00, 0x04, 0x00, 0x99, 0x00, 0x84, 0x00, 0x02, 0x00, 0x70, 0x00, 0x04, 0x00, 0x69, 0x00), PHYREGS(0x088c, 0x0888, 0x0884, 0x01df, 0x01e0, 0x01e1), }, { .freq = 5470, RADIOREGS3(0x53, 0x01, 0x01, 0x02, 0x23, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x04, 0x04, 0x04, 0x8d, 0x0d, 0x00, 0xc8, 0x74, 0x00, 0x01, 0x00, 0x70, 0x00, 0x04, 0x00, 0x99, 0x00, 0x74, 0x00, 0x01, 0x00, 0x70, 0x00, 0x04, 0x00, 0x69, 0x00), PHYREGS(0x0890, 0x088c, 0x0888, 0x01de, 0x01df, 0x01e0), }, { .freq = 5480, RADIOREGS3(0x4d, 0x01, 0x01, 0x02, 0x24, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x04, 0x04, 0x04, 0x8d, 0x0d, 0x00, 0xc8, 0x73, 0x00, 0x01, 0x00, 0x70, 0x00, 0x04, 0x00, 0x98, 0x00, 0x73, 0x00, 0x01, 0x00, 0x70, 0x00, 0x04, 0x00, 0x68, 0x00), PHYREGS(0x0894, 0x0890, 0x088c, 0x01dd, 0x01de, 0x01df), }, { .freq = 5490, RADIOREGS3(0x4d, 0x01, 0x01, 0x02, 0x25, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x04, 0x04, 0x04, 0x8d, 0x0d, 0x00, 0xc8, 0x73, 0x00, 0x01, 0x00, 0x70, 0x00, 0x04, 0x00, 0x98, 0x00, 0x73, 0x00, 0x01, 0x00, 0x70, 0x00, 0x04, 0x00, 0x68, 0x00), PHYREGS(0x0898, 0x0894, 0x0890, 0x01dd, 0x01dd, 0x01de), }, { .freq = 5500, RADIOREGS3(0x47, 0x01, 0x01, 0x02, 0x26, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x04, 0x04, 0x04, 0x8d, 0x0b, 0x00, 0x84, 0x73, 0x00, 0x01, 0x00, 0x70, 0x00, 0x04, 0x00, 0x98, 0x00, 0x73, 0x00, 0x01, 0x00, 0x70, 0x00, 0x04, 0x00, 0x78, 0x00), PHYREGS(0x089c, 0x0898, 0x0894, 0x01dc, 0x01dd, 0x01dd), }, { .freq = 5510, RADIOREGS3(0x47, 0x01, 0x01, 0x02, 0x27, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x04, 0x04, 0x04, 0x8d, 0x0b, 0x00, 0x84, 0x73, 0x00, 0x01, 0x00, 0x70, 0x00, 0x04, 0x00, 0x98, 0x00, 0x73, 0x00, 0x01, 0x00, 0x70, 0x00, 0x04, 0x00, 0x78, 0x00), PHYREGS(0x08a0, 0x089c, 0x0898, 0x01db, 0x01dc, 0x01dd), }, { .freq = 5520, RADIOREGS3(0x40, 0x01, 0x01, 0x02, 0x28, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x04, 0x04, 0x04, 0x8d, 0x0b, 0x00, 0x84, 0x73, 0x00, 0x01, 0x00, 0x70, 0x00, 0x04, 0x00, 0x98, 0x00, 0x73, 0x00, 0x01, 0x00, 0x70, 0x00, 0x04, 0x00, 0x78, 0x00), PHYREGS(0x08a4, 0x08a0, 0x089c, 0x01da, 0x01db, 0x01dc), }, { .freq = 5530, RADIOREGS3(0x40, 0x01, 0x01, 0x02, 0x29, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x04, 0x04, 0x04, 0x8d, 0x0b, 0x00, 0x84, 0x63, 0x00, 0x01, 0x00, 0x70, 0x00, 0x03, 0x00, 0x98, 0x00, 0x63, 0x00, 0x01, 0x00, 0x70, 0x00, 0x03, 0x00, 0x78, 0x00), PHYREGS(0x08a8, 0x08a4, 0x08a0, 0x01d9, 0x01da, 0x01db), }, { .freq = 5540, RADIOREGS3(0x3a, 0x01, 0x01, 0x02, 0x2a, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x04, 0x04, 0x04, 0x8d, 0x0b, 0x00, 0x84, 0x62, 0x00, 0x00, 0x00, 0x70, 0x00, 0x03, 0x00, 0x97, 0x00, 0x62, 0x00, 0x00, 0x00, 0x70, 0x00, 0x03, 0x00, 0x77, 0x00), PHYREGS(0x08ac, 0x08a8, 0x08a4, 0x01d8, 0x01d9, 0x01da), }, { .freq = 5550, RADIOREGS3(0x3a, 0x01, 0x01, 0x02, 0x2b, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x04, 0x04, 0x04, 0x8d, 0x0b, 0x00, 0x84, 0x62, 0x00, 0x00, 0x00, 0x70, 0x00, 0x03, 0x00, 0x97, 0x00, 0x62, 0x00, 0x00, 0x00, 0x70, 0x00, 0x03, 0x00, 0x77, 0x00), PHYREGS(0x08b0, 0x08ac, 0x08a8, 0x01d7, 0x01d8, 0x01d9), }, { .freq = 5560, RADIOREGS3(0x34, 0x01, 0x01, 0x02, 0x2c, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x04, 0x04, 0x04, 0x8d, 0x0b, 0x00, 0x84, 0x62, 0x00, 0x00, 0x00, 0x70, 0x00, 0x03, 0x00, 0x97, 0x00, 0x62, 0x00, 0x00, 0x00, 0x70, 0x00, 0x03, 0x00, 0x77, 0x00), PHYREGS(0x08b4, 0x08b0, 0x08ac, 0x01d7, 0x01d7, 0x01d8), }, { .freq = 5570, RADIOREGS3(0x34, 0x01, 0x01, 0x02, 0x2d, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x04, 0x04, 0x04, 0x8d, 0x0b, 0x00, 0x84, 0x52, 0x00, 0x00, 0x00, 0x70, 0x00, 0x02, 0x00, 0x96, 0x00, 0x52, 0x00, 0x00, 0x00, 0x70, 0x00, 0x02, 0x00, 0x76, 0x00), PHYREGS(0x08b8, 0x08b4, 0x08b0, 0x01d6, 0x01d7, 0x01d7), }, { .freq = 5580, RADIOREGS3(0x2e, 0x01, 0x01, 0x02, 0x2e, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x04, 0x04, 0x04, 0x8d, 0x0b, 0x00, 0x84, 0x52, 0x00, 0x00, 0x00, 0x70, 0x00, 0x02, 0x00, 0x96, 0x00, 0x52, 0x00, 0x00, 0x00, 0x70, 0x00, 0x02, 0x00, 0x76, 0x00), PHYREGS(0x08bc, 0x08b8, 0x08b4, 0x01d5, 0x01d6, 0x01d7), }, { .freq = 5590, RADIOREGS3(0x2e, 0x01, 0x01, 0x02, 0x2f, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x04, 0x04, 0x04, 0x8d, 0x0b, 0x00, 0x84, 0x51, 0x00, 0x00, 0x00, 0x70, 0x00, 0x02, 0x00, 0x96, 0x00, 0x51, 0x00, 0x00, 0x00, 0x70, 0x00, 0x02, 0x00, 0x76, 0x00), PHYREGS(0x08c0, 0x08bc, 0x08b8, 0x01d4, 0x01d5, 0x01d6), }, { .freq = 5600, RADIOREGS3(0x28, 0x01, 0x01, 0x02, 0x30, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x05, 0x05, 0x05, 0x8b, 0x09, 0x00, 0x70, 0x51, 0x00, 0x00, 0x00, 0x70, 0x00, 0x02, 0x00, 0x96, 0x00, 0x51, 0x00, 0x00, 0x00, 0x70, 0x00, 0x02, 0x00, 0x76, 0x00), PHYREGS(0x08c4, 0x08c0, 0x08bc, 0x01d3, 0x01d4, 0x01d5), }, { .freq = 5610, RADIOREGS3(0x28, 0x01, 0x01, 0x02, 0x31, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x05, 0x05, 0x05, 0x8b, 0x09, 0x00, 0x70, 0x51, 0x00, 0x00, 0x00, 0x70, 0x00, 0x02, 0x00, 0x96, 0x00, 0x51, 0x00, 0x00, 0x00, 0x70, 0x00, 0x02, 0x00, 0x76, 0x00), PHYREGS(0x08c8, 0x08c4, 0x08c0, 0x01d2, 0x01d3, 0x01d4), }, { .freq = 5620, RADIOREGS3(0x21, 0x01, 0x01, 0x02, 0x32, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x05, 0x05, 0x05, 0x8b, 0x09, 0x00, 0x70, 0x51, 0x00, 0x00, 0x00, 0x70, 0x00, 0x02, 0x00, 0x96, 0x00, 0x51, 0x00, 0x00, 0x00, 0x70, 0x00, 0x02, 0x00, 0x76, 0x00), PHYREGS(0x08cc, 0x08c8, 0x08c4, 0x01d2, 0x01d2, 0x01d3), }, { .freq = 5630, RADIOREGS3(0x21, 0x01, 0x01, 0x02, 0x33, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x05, 0x05, 0x05, 0x8b, 0x09, 0x00, 0x70, 0x51, 0x00, 0x00, 0x00, 0x70, 0x00, 0x02, 0x00, 0x96, 0x00, 0x51, 0x00, 0x00, 0x00, 0x70, 0x00, 0x02, 0x00, 0x76, 0x00), PHYREGS(0x08d0, 0x08cc, 0x08c8, 0x01d1, 0x01d2, 0x01d2), }, { .freq = 5640, RADIOREGS3(0x1c, 0x01, 0x01, 0x02, 0x34, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x05, 0x05, 0x05, 0x8b, 0x09, 0x00, 0x70, 0x51, 0x00, 0x00, 0x00, 0x70, 0x00, 0x02, 0x00, 0x95, 0x00, 0x51, 0x00, 0x00, 0x00, 0x70, 0x00, 0x02, 0x00, 0x75, 0x00), PHYREGS(0x08d4, 0x08d0, 0x08cc, 0x01d0, 0x01d1, 0x01d2), }, { .freq = 5650, RADIOREGS3(0x1c, 0x01, 0x01, 0x02, 0x35, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x05, 0x05, 0x05, 0x8b, 0x09, 0x00, 0x70, 0x50, 0x00, 0x00, 0x00, 0x70, 0x00, 0x01, 0x00, 0x95, 0x00, 0x50, 0x00, 0x00, 0x00, 0x70, 0x00, 0x01, 0x00, 0x75, 0x00), PHYREGS(0x08d8, 0x08d4, 0x08d0, 0x01cf, 0x01d0, 0x01d1), }, { .freq = 5660, RADIOREGS3(0x16, 0x01, 0x01, 0x02, 0x36, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x05, 0x05, 0x05, 0x8b, 0x09, 0x00, 0x70, 0x50, 0x00, 0x00, 0x00, 0x70, 0x00, 0x01, 0x00, 0x95, 0x00, 0x50, 0x00, 0x00, 0x00, 0x70, 0x00, 0x01, 0x00, 0x75, 0x00), PHYREGS(0x08dc, 0x08d8, 0x08d4, 0x01ce, 0x01cf, 0x01d0), }, { .freq = 5670, RADIOREGS3(0x16, 0x01, 0x01, 0x02, 0x37, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x05, 0x05, 0x05, 0x8b, 0x09, 0x00, 0x70, 0x40, 0x00, 0x00, 0x00, 0x70, 0x00, 0x01, 0x00, 0x94, 0x00, 0x40, 0x00, 0x00, 0x00, 0x70, 0x00, 0x01, 0x00, 0x74, 0x00), PHYREGS(0x08e0, 0x08dc, 0x08d8, 0x01ce, 0x01ce, 0x01cf), }, { .freq = 5680, RADIOREGS3(0x10, 0x01, 0x01, 0x02, 0x38, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x05, 0x05, 0x05, 0x8b, 0x09, 0x00, 0x70, 0x40, 0x00, 0x00, 0x00, 0x70, 0x00, 0x01, 0x00, 0x94, 0x00, 0x40, 0x00, 0x00, 0x00, 0x70, 0x00, 0x01, 0x00, 0x74, 0x00), PHYREGS(0x08e4, 0x08e0, 0x08dc, 0x01cd, 0x01ce, 0x01ce), }, { .freq = 5690, RADIOREGS3(0x10, 0x01, 0x01, 0x02, 0x39, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x05, 0x05, 0x05, 0x8b, 0x09, 0x00, 0x70, 0x40, 0x00, 0x00, 0x00, 0x70, 0x00, 0x01, 0x00, 0x94, 0x00, 0x40, 0x00, 0x00, 0x00, 0x70, 0x00, 0x01, 0x00, 0x74, 0x00), PHYREGS(0x08e8, 0x08e4, 0x08e0, 0x01cc, 0x01cd, 0x01ce), }, { .freq = 5700, RADIOREGS3(0x0a, 0x01, 0x01, 0x02, 0x3a, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x05, 0x05, 0x05, 0x8a, 0x06, 0x00, 0x40, 0x40, 0x00, 0x00, 0x00, 0x70, 0x00, 0x01, 0x00, 0x94, 0x00, 0x40, 0x00, 0x00, 0x00, 0x70, 0x00, 0x01, 0x00, 0x74, 0x00), PHYREGS(0x08ec, 0x08e8, 0x08e4, 0x01cb, 0x01cc, 0x01cd), }, { .freq = 5710, RADIOREGS3(0x0a, 0x01, 0x01, 0x02, 0x3b, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x05, 0x05, 0x05, 0x8a, 0x06, 0x00, 0x40, 0x40, 0x00, 0x00, 0x00, 0x70, 0x00, 0x01, 0x00, 0x94, 0x00, 0x40, 0x00, 0x00, 0x00, 0x70, 0x00, 0x01, 0x00, 0x74, 0x00), PHYREGS(0x08f0, 0x08ec, 0x08e8, 0x01ca, 0x01cb, 0x01cc), }, { .freq = 5720, RADIOREGS3(0x0a, 0x01, 0x01, 0x02, 0x3c, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x05, 0x05, 0x05, 0x8a, 0x06, 0x00, 0x40, 0x40, 0x00, 0x00, 0x00, 0x70, 0x00, 0x01, 0x00, 0x94, 0x00, 0x40, 0x00, 0x00, 0x00, 0x70, 0x00, 0x01, 0x00, 0x74, 0x00), PHYREGS(0x08f4, 0x08f0, 0x08ec, 0x01c9, 0x01ca, 0x01cb), }, { .freq = 5725, RADIOREGS3(0x03, 0x01, 0x02, 0x04, 0x79, 0x07, 0x07, 0x04, 0x10, 0x01, 0x05, 0x05, 0x05, 0x8a, 0x06, 0x00, 0x40, 0x40, 0x00, 0x00, 0x00, 0x70, 0x00, 0x01, 0x00, 0x94, 0x00, 0x40, 0x00, 0x00, 0x00, 0x70, 0x00, 0x01, 0x00, 0x74, 0x00), PHYREGS(0x08f6, 0x08f2, 0x08ee, 0x01c9, 0x01ca, 0x01cb), }, { .freq = 5730, RADIOREGS3(0x0a, 0x01, 0x01, 0x02, 0x3d, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x05, 0x05, 0x05, 0x8a, 0x06, 0x00, 0x40, 0x30, 0x00, 0x00, 0x00, 0x70, 0x00, 0x01, 0x00, 0x94, 0x00, 0x30, 0x00, 0x00, 0x00, 0x70, 0x00, 0x01, 0x00, 0x84, 0x00), PHYREGS(0x08f8, 0x08f4, 0x08f0, 0x01c9, 0x01c9, 0x01ca), }, { .freq = 5735, RADIOREGS3(0x03, 0x01, 0x02, 0x04, 0x7b, 0x07, 0x07, 0x04, 0x10, 0x01, 0x05, 0x05, 0x05, 0x8a, 0x06, 0x00, 0x40, 0x30, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x93, 0x00, 0x30, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x83, 0x00), PHYREGS(0x08fa, 0x08f6, 0x08f2, 0x01c8, 0x01c9, 0x01ca), }, { .freq = 5740, RADIOREGS3(0x0a, 0x01, 0x01, 0x02, 0x3e, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x05, 0x05, 0x05, 0x8a, 0x06, 0x00, 0x40, 0x30, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x93, 0x00, 0x30, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x83, 0x00), PHYREGS(0x08fc, 0x08f8, 0x08f4, 0x01c8, 0x01c9, 0x01c9), }, { .freq = 5745, RADIOREGS3(0xfe, 0x00, 0x02, 0x04, 0x7d, 0x07, 0x07, 0x04, 0x10, 0x01, 0x05, 0x05, 0x05, 0x8a, 0x06, 0x00, 0x40, 0x30, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x93, 0x00, 0x30, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x83, 0x00), PHYREGS(0x08fe, 0x08fa, 0x08f6, 0x01c8, 0x01c8, 0x01c9), }, { .freq = 5750, RADIOREGS3(0x0a, 0x01, 0x01, 0x02, 0x3f, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x05, 0x05, 0x05, 0x8a, 0x06, 0x00, 0x40, 0x30, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x93, 0x00, 0x30, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x83, 0x00), PHYREGS(0x0900, 0x08fc, 0x08f8, 0x01c7, 0x01c8, 0x01c9), }, { .freq = 5755, RADIOREGS3(0xfe, 0x00, 0x02, 0x04, 0x7f, 0x07, 0x07, 0x04, 0x10, 0x01, 0x05, 0x05, 0x05, 0x8a, 0x06, 0x00, 0x40, 0x30, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x93, 0x00, 0x30, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x83, 0x00), PHYREGS(0x0902, 0x08fe, 0x08fa, 0x01c7, 0x01c8, 0x01c8), }, { .freq = 5760, RADIOREGS3(0x0a, 0x01, 0x01, 0x02, 0x40, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x05, 0x05, 0x05, 0x8a, 0x06, 0x00, 0x40, 0x20, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x93, 0x00, 0x20, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x83, 0x00), PHYREGS(0x0904, 0x0900, 0x08fc, 0x01c6, 0x01c7, 0x01c8), }, { .freq = 5765, RADIOREGS3(0xf8, 0x00, 0x02, 0x04, 0x81, 0x07, 0x07, 0x04, 0x10, 0x01, 0x05, 0x05, 0x05, 0x8a, 0x06, 0x00, 0x40, 0x20, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x92, 0x00, 0x20, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x82, 0x00), PHYREGS(0x0906, 0x0902, 0x08fe, 0x01c6, 0x01c7, 0x01c8), }, { .freq = 5770, RADIOREGS3(0x0a, 0x01, 0x01, 0x02, 0x41, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x05, 0x05, 0x05, 0x8a, 0x06, 0x00, 0x40, 0x20, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x92, 0x00, 0x20, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x82, 0x00), PHYREGS(0x0908, 0x0904, 0x0900, 0x01c6, 0x01c6, 0x01c7), }, { .freq = 5775, RADIOREGS3(0xf8, 0x00, 0x02, 0x04, 0x83, 0x07, 0x07, 0x04, 0x10, 0x01, 0x05, 0x05, 0x05, 0x8a, 0x06, 0x00, 0x40, 0x20, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x92, 0x00, 0x20, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x82, 0x00), PHYREGS(0x090a, 0x0906, 0x0902, 0x01c5, 0x01c6, 0x01c7), }, { .freq = 5780, RADIOREGS3(0x0a, 0x01, 0x01, 0x02, 0x42, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x05, 0x05, 0x05, 0x8a, 0x06, 0x00, 0x40, 0x10, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x92, 0x00, 0x10, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x82, 0x00), PHYREGS(0x090c, 0x0908, 0x0904, 0x01c5, 0x01c6, 0x01c6), }, { .freq = 5785, RADIOREGS3(0xf2, 0x00, 0x02, 0x04, 0x85, 0x07, 0x07, 0x04, 0x10, 0x01, 0x06, 0x06, 0x06, 0x8a, 0x06, 0x00, 0x40, 0x10, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x92, 0x00, 0x10, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x82, 0x00), PHYREGS(0x090e, 0x090a, 0x0906, 0x01c4, 0x01c5, 0x01c6), }, { .freq = 5790, RADIOREGS3(0x0a, 0x01, 0x01, 0x02, 0x43, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x06, 0x06, 0x06, 0x8a, 0x06, 0x00, 0x40, 0x10, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x92, 0x00, 0x10, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x82, 0x00), PHYREGS(0x0910, 0x090c, 0x0908, 0x01c4, 0x01c5, 0x01c6), }, { .freq = 5795, RADIOREGS3(0xf2, 0x00, 0x02, 0x04, 0x87, 0x07, 0x07, 0x04, 0x10, 0x01, 0x06, 0x06, 0x06, 0x8a, 0x06, 0x00, 0x40, 0x10, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x92, 0x00, 0x10, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x82, 0x00), PHYREGS(0x0912, 0x090e, 0x090a, 0x01c4, 0x01c4, 0x01c5), }, { .freq = 5800, RADIOREGS3(0x0a, 0x01, 0x01, 0x02, 0x44, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x06, 0x06, 0x06, 0x88, 0x04, 0x00, 0x20, 0x10, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x92, 0x00, 0x10, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x82, 0x00), PHYREGS(0x0914, 0x0910, 0x090c, 0x01c3, 0x01c4, 0x01c5), }, { .freq = 5805, RADIOREGS3(0xed, 0x00, 0x02, 0x04, 0x89, 0x07, 0x07, 0x04, 0x10, 0x01, 0x06, 0x06, 0x06, 0x88, 0x04, 0x00, 0x20, 0x10, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x92, 0x00, 0x10, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x82, 0x00), PHYREGS(0x0916, 0x0912, 0x090e, 0x01c3, 0x01c4, 0x01c4), }, { .freq = 5810, RADIOREGS3(0x0a, 0x01, 0x01, 0x02, 0x45, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x06, 0x06, 0x06, 0x88, 0x04, 0x00, 0x20, 0x10, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x92, 0x00, 0x10, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x82, 0x00), PHYREGS(0x0918, 0x0914, 0x0910, 0x01c2, 0x01c3, 0x01c4), }, { .freq = 5815, RADIOREGS3(0xed, 0x00, 0x02, 0x04, 0x8b, 0x07, 0x07, 0x04, 0x10, 0x01, 0x06, 0x06, 0x06, 0x88, 0x04, 0x00, 0x20, 0x10, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x92, 0x00, 0x10, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x82, 0x00), PHYREGS(0x091a, 0x0916, 0x0912, 0x01c2, 0x01c3, 0x01c4), }, { .freq = 5820, RADIOREGS3(0x0a, 0x01, 0x01, 0x02, 0x46, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x06, 0x06, 0x06, 0x88, 0x04, 0x00, 0x20, 0x10, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x92, 0x00, 0x10, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x82, 0x00), PHYREGS(0x091c, 0x0918, 0x0914, 0x01c2, 0x01c2, 0x01c3), }, { .freq = 5825, RADIOREGS3(0xed, 0x00, 0x02, 0x04, 0x8d, 0x07, 0x07, 0x04, 0x10, 0x01, 0x06, 0x06, 0x06, 0x88, 0x04, 0x00, 0x20, 0x10, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x92, 0x00, 0x10, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x82, 0x00), PHYREGS(0x091e, 0x091a, 0x0916, 0x01c1, 0x01c2, 0x01c3), }, { .freq = 5830, RADIOREGS3(0x0a, 0x01, 0x01, 0x02, 0x47, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x06, 0x06, 0x06, 0x88, 0x04, 0x00, 0x20, 0x10, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x92, 0x00, 0x10, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x72, 0x00), PHYREGS(0x0920, 0x091c, 0x0918, 0x01c1, 0x01c2, 0x01c2), }, { .freq = 5840, RADIOREGS3(0x0a, 0x01, 0x01, 0x02, 0x48, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x06, 0x06, 0x06, 0x88, 0x04, 0x00, 0x20, 0x10, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x92, 0x00, 0x10, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x72, 0x00), PHYREGS(0x0924, 0x0920, 0x091c, 0x01c0, 0x01c1, 0x01c2), }, { .freq = 5850, RADIOREGS3(0xe0, 0x00, 0x01, 0x02, 0x49, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x06, 0x06, 0x06, 0x88, 0x04, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x92, 0x00, 0x00, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x72, 0x00), PHYREGS(0x0928, 0x0924, 0x0920, 0x01bf, 0x01c0, 0x01c1), }, { .freq = 5860, RADIOREGS3(0xde, 0x00, 0x01, 0x02, 0x4a, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x06, 0x06, 0x06, 0x88, 0x04, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x92, 0x00, 0x00, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x72, 0x00), PHYREGS(0x092c, 0x0928, 0x0924, 0x01bf, 0x01bf, 0x01c0), }, { .freq = 5870, RADIOREGS3(0xdb, 0x00, 0x01, 0x02, 0x4b, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x06, 0x06, 0x06, 0x88, 0x04, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x91, 0x00, 0x00, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x71, 0x00), PHYREGS(0x0930, 0x092c, 0x0928, 0x01be, 0x01bf, 0x01bf), }, { .freq = 5880, RADIOREGS3(0xd8, 0x00, 0x01, 0x02, 0x4c, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x06, 0x06, 0x06, 0x88, 0x04, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x91, 0x00, 0x00, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x71, 0x00), PHYREGS(0x0934, 0x0930, 0x092c, 0x01bd, 0x01be, 0x01bf), }, { .freq = 5890, RADIOREGS3(0xd6, 0x00, 0x01, 0x02, 0x4d, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x06, 0x06, 0x06, 0x88, 0x04, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x91, 0x00, 0x00, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x71, 0x00), PHYREGS(0x0938, 0x0934, 0x0930, 0x01bc, 0x01bd, 0x01be), }, { .freq = 5900, RADIOREGS3(0xd3, 0x00, 0x01, 0x02, 0x4e, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x06, 0x06, 0x06, 0x87, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x91, 0x00, 0x00, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x71, 0x00), PHYREGS(0x093c, 0x0938, 0x0934, 0x01bc, 0x01bc, 0x01bd), }, { .freq = 5910, RADIOREGS3(0xd6, 0x00, 0x01, 0x02, 0x4f, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x06, 0x06, 0x06, 0x87, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x91, 0x00, 0x00, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x71, 0x00), PHYREGS(0x0940, 0x093c, 0x0938, 0x01bb, 0x01bc, 0x01bc), }, { .freq = 2412, RADIOREGS3(0x00, 0x01, 0x03, 0x09, 0x6c, 0x08, 0x08, 0x04, 0x16, 0x01, 0x04, 0x04, 0x04, 0x8f, 0x30, 0x00, 0x00, 0x00, 0x1f, 0x00, 0x03, 0x00, 0x70, 0x00, 0x0f, 0x00, 0x0b, 0x00, 0x1f, 0x00, 0x03, 0x00, 0x70, 0x00, 0x0f, 0x00, 0x0b), PHYREGS(0x03c9, 0x03c5, 0x03c1, 0x043a, 0x043f, 0x0443), }, { .freq = 2417, RADIOREGS3(0x00, 0x01, 0x03, 0x09, 0x71, 0x08, 0x08, 0x04, 0x16, 0x01, 0x05, 0x05, 0x05, 0x8f, 0x30, 0x00, 0x00, 0x00, 0x1f, 0x00, 0x03, 0x00, 0x70, 0x00, 0x0f, 0x00, 0x0a, 0x00, 0x1f, 0x00, 0x03, 0x00, 0x70, 0x00, 0x0f, 0x00, 0x0a), PHYREGS(0x03cb, 0x03c7, 0x03c3, 0x0438, 0x043d, 0x0441), }, { .freq = 2422, RADIOREGS3(0x00, 0x01, 0x03, 0x09, 0x76, 0x08, 0x08, 0x04, 0x16, 0x01, 0x05, 0x05, 0x05, 0x8f, 0x30, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x03, 0x00, 0x70, 0x00, 0x0f, 0x00, 0x0a, 0x00, 0x0e, 0x00, 0x03, 0x00, 0x70, 0x00, 0x0f, 0x00, 0x0a), PHYREGS(0x03cd, 0x03c9, 0x03c5, 0x0436, 0x043a, 0x043f), }, { .freq = 2427, RADIOREGS3(0x00, 0x01, 0x03, 0x09, 0x7b, 0x08, 0x08, 0x04, 0x16, 0x01, 0x05, 0x05, 0x05, 0x8f, 0x30, 0x00, 0x00, 0x00, 0x0d, 0x00, 0x03, 0x00, 0x70, 0x00, 0x0e, 0x00, 0x0a, 0x00, 0x0d, 0x00, 0x03, 0x00, 0x70, 0x00, 0x0e, 0x00, 0x0a), PHYREGS(0x03cf, 0x03cb, 0x03c7, 0x0434, 0x0438, 0x043d), }, { .freq = 2432, RADIOREGS3(0x00, 0x01, 0x03, 0x09, 0x80, 0x08, 0x08, 0x04, 0x16, 0x01, 0x05, 0x05, 0x05, 0x8f, 0x30, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x03, 0x00, 0x70, 0x00, 0x0e, 0x00, 0x0a, 0x00, 0x0c, 0x00, 0x03, 0x00, 0x70, 0x00, 0x0e, 0x00, 0x0a), PHYREGS(0x03d1, 0x03cd, 0x03c9, 0x0431, 0x0436, 0x043a), }, { .freq = 2437, RADIOREGS3(0x00, 0x01, 0x03, 0x09, 0x85, 0x08, 0x08, 0x04, 0x16, 0x01, 0x05, 0x05, 0x05, 0x8f, 0x30, 0x00, 0x00, 0x00, 0x0b, 0x00, 0x03, 0x00, 0x70, 0x00, 0x0e, 0x00, 0x0a, 0x00, 0x0b, 0x00, 0x03, 0x00, 0x70, 0x00, 0x0e, 0x00, 0x0a), PHYREGS(0x03d3, 0x03cf, 0x03cb, 0x042f, 0x0434, 0x0438), }, { .freq = 2442, RADIOREGS3(0x00, 0x01, 0x03, 0x09, 0x8a, 0x08, 0x08, 0x04, 0x16, 0x01, 0x05, 0x05, 0x05, 0x8f, 0x30, 0x00, 0x00, 0x00, 0x09, 0x00, 0x03, 0x00, 0x70, 0x00, 0x0e, 0x00, 0x0a, 0x00, 0x09, 0x00, 0x03, 0x00, 0x70, 0x00, 0x0e, 0x00, 0x0a), PHYREGS(0x03d5, 0x03d1, 0x03cd, 0x042d, 0x0431, 0x0436), }, { .freq = 2447, RADIOREGS3(0x00, 0x01, 0x03, 0x09, 0x8f, 0x08, 0x08, 0x04, 0x16, 0x01, 0x06, 0x06, 0x06, 0x8f, 0x30, 0x00, 0x00, 0x00, 0x08, 0x00, 0x02, 0x00, 0x70, 0x00, 0x0e, 0x00, 0x09, 0x00, 0x08, 0x00, 0x02, 0x00, 0x70, 0x00, 0x0e, 0x00, 0x09), PHYREGS(0x03d7, 0x03d3, 0x03cf, 0x042b, 0x042f, 0x0434), }, { .freq = 2452, RADIOREGS3(0x00, 0x01, 0x03, 0x09, 0x94, 0x08, 0x08, 0x04, 0x16, 0x01, 0x06, 0x06, 0x06, 0x8f, 0x30, 0x00, 0x00, 0x00, 0x07, 0x00, 0x02, 0x00, 0x70, 0x00, 0x0e, 0x00, 0x09, 0x00, 0x07, 0x00, 0x02, 0x00, 0x70, 0x00, 0x0e, 0x00, 0x09), PHYREGS(0x03d9, 0x03d5, 0x03d1, 0x0429, 0x042d, 0x0431), }, { .freq = 2457, RADIOREGS3(0x00, 0x01, 0x03, 0x09, 0x99, 0x08, 0x08, 0x04, 0x16, 0x01, 0x06, 0x06, 0x06, 0x8f, 0x30, 0x00, 0x00, 0x00, 0x06, 0x00, 0x02, 0x00, 0x70, 0x00, 0x0d, 0x00, 0x09, 0x00, 0x06, 0x00, 0x02, 0x00, 0x70, 0x00, 0x0d, 0x00, 0x09), PHYREGS(0x03db, 0x03d7, 0x03d3, 0x0427, 0x042b, 0x042f), }, { .freq = 2462, RADIOREGS3(0x00, 0x01, 0x03, 0x09, 0x9e, 0x08, 0x08, 0x04, 0x16, 0x01, 0x06, 0x06, 0x06, 0x8f, 0x30, 0x00, 0x00, 0x00, 0x05, 0x00, 0x02, 0x00, 0x70, 0x00, 0x0d, 0x00, 0x09, 0x00, 0x05, 0x00, 0x02, 0x00, 0x70, 0x00, 0x0d, 0x00, 0x09), PHYREGS(0x03dd, 0x03d9, 0x03d5, 0x0424, 0x0429, 0x042d), }, { .freq = 2467, RADIOREGS3(0x00, 0x01, 0x03, 0x09, 0xa3, 0x08, 0x08, 0x04, 0x16, 0x01, 0x06, 0x06, 0x06, 0x8f, 0x30, 0x00, 0x00, 0x00, 0x04, 0x00, 0x02, 0x00, 0x70, 0x00, 0x0d, 0x00, 0x08, 0x00, 0x04, 0x00, 0x02, 0x00, 0x70, 0x00, 0x0d, 0x00, 0x08), PHYREGS(0x03df, 0x03db, 0x03d7, 0x0422, 0x0427, 0x042b), }, { .freq = 2472, RADIOREGS3(0x00, 0x01, 0x03, 0x09, 0xa8, 0x08, 0x08, 0x04, 0x16, 0x01, 0x07, 0x07, 0x07, 0x8f, 0x30, 0x00, 0x00, 0x00, 0x03, 0x00, 0x02, 0x00, 0x70, 0x00, 0x0d, 0x00, 0x08, 0x00, 0x03, 0x00, 0x02, 0x00, 0x70, 0x00, 0x0d, 0x00, 0x08), PHYREGS(0x03e1, 0x03dd, 0x03d9, 0x0420, 0x0424, 0x0429), }, { .freq = 2484, RADIOREGS3(0xff, 0x01, 0x03, 0x09, 0xb4, 0x08, 0x08, 0x04, 0x16, 0x01, 0x07, 0x07, 0x07, 0x8f, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x70, 0x00, 0x0d, 0x00, 0x08, 0x00, 0x00, 0x00, 0x02, 0x00, 0x70, 0x00, 0x0d, 0x00, 0x08), PHYREGS(0x03e6, 0x03e2, 0x03de, 0x041b, 0x041f, 0x0424), }, }; static const struct b43_nphy_channeltab_entry_rev3 b43_nphy_channeltab_radio_rev6[] = { { .freq = 4920, RADIOREGS3(0xff, 0x01, 0x01, 0x01, 0xec, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x00, 0x00, 0x00, 0x8f, 0x0f, 0x00, 0xff, 0xfe, 0x00, 0x09, 0x00, 0x77, 0x00, 0x0f, 0x00, 0x6f, 0x00, 0xfe, 0x00, 0x09, 0x00, 0x77, 0x00, 0x0f, 0x00, 0x6f, 0x00), PHYREGS(0x07b4, 0x07b0, 0x07ac, 0x0214, 0x0215, 0x0216), }, { .freq = 4930, RADIOREGS3(0xff, 0x01, 0x01, 0x01, 0xed, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x00, 0x00, 0x00, 0x8f, 0x0f, 0x00, 0xff, 0xfe, 0x00, 0x09, 0x00, 0x77, 0x00, 0x0f, 0x00, 0x6f, 0x00, 0xfe, 0x00, 0x09, 0x00, 0x77, 0x00, 0x0f, 0x00, 0x6f, 0x00), PHYREGS(0x07b8, 0x07b4, 0x07b0, 0x0213, 0x0214, 0x0215), }, { .freq = 4940, RADIOREGS3(0xff, 0x01, 0x01, 0x01, 0xee, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x00, 0x00, 0x00, 0x8f, 0x0f, 0x00, 0xff, 0xfe, 0x00, 0x09, 0x00, 0x77, 0x00, 0x0f, 0x00, 0x6f, 0x00, 0xfe, 0x00, 0x09, 0x00, 0x77, 0x00, 0x0f, 0x00, 0x6f, 0x00), PHYREGS(0x07bc, 0x07b8, 0x07b4, 0x0212, 0x0213, 0x0214), }, { .freq = 4950, RADIOREGS3(0xff, 0x01, 0x01, 0x01, 0xef, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x00, 0x00, 0x00, 0x8f, 0x0f, 0x00, 0xff, 0xfe, 0x00, 0x09, 0x00, 0x77, 0x00, 0x0f, 0x00, 0x6f, 0x00, 0xfe, 0x00, 0x09, 0x00, 0x77, 0x00, 0x0f, 0x00, 0x6f, 0x00), PHYREGS(0x07c0, 0x07bc, 0x07b8, 0x0211, 0x0212, 0x0213), }, { .freq = 4960, RADIOREGS3(0xff, 0x01, 0x01, 0x01, 0xf0, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x01, 0x01, 0x01, 0x8f, 0x0f, 0x00, 0xff, 0xfe, 0x00, 0x09, 0x00, 0x77, 0x00, 0x0f, 0x00, 0x6f, 0x00, 0xfe, 0x00, 0x09, 0x00, 0x77, 0x00, 0x0f, 0x00, 0x6f, 0x00), PHYREGS(0x07c4, 0x07c0, 0x07bc, 0x020f, 0x0211, 0x0212), }, { .freq = 4970, RADIOREGS3(0xff, 0x01, 0x01, 0x01, 0xf1, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x01, 0x01, 0x01, 0x8f, 0x0f, 0x00, 0xff, 0xfe, 0x00, 0x09, 0x00, 0x77, 0x00, 0x0f, 0x00, 0x6f, 0x00, 0xfe, 0x00, 0x09, 0x00, 0x77, 0x00, 0x0f, 0x00, 0x6f, 0x00), PHYREGS(0x07c8, 0x07c4, 0x07c0, 0x020e, 0x020f, 0x0211), }, { .freq = 4980, RADIOREGS3(0xff, 0x01, 0x01, 0x01, 0xf2, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x01, 0x01, 0x01, 0x8f, 0x0f, 0x00, 0xff, 0xfe, 0x00, 0x09, 0x00, 0x77, 0x00, 0x0f, 0x00, 0x6f, 0x00, 0xfe, 0x00, 0x09, 0x00, 0x77, 0x00, 0x0f, 0x00, 0x6f, 0x00), PHYREGS(0x07cc, 0x07c8, 0x07c4, 0x020d, 0x020e, 0x020f), }, { .freq = 4990, RADIOREGS3(0xff, 0x01, 0x01, 0x01, 0xf3, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x01, 0x01, 0x01, 0x8f, 0x0f, 0x00, 0xff, 0xfe, 0x00, 0x09, 0x00, 0x77, 0x00, 0x0f, 0x00, 0x6f, 0x00, 0xfe, 0x00, 0x09, 0x00, 0x77, 0x00, 0x0f, 0x00, 0x6f, 0x00), PHYREGS(0x07d0, 0x07cc, 0x07c8, 0x020c, 0x020d, 0x020e), }, { .freq = 5000, RADIOREGS3(0xff, 0x01, 0x01, 0x01, 0xf4, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x01, 0x01, 0x01, 0x8f, 0x0f, 0x00, 0xff, 0xfe, 0x00, 0x09, 0x00, 0x77, 0x00, 0x0f, 0x00, 0x6f, 0x00, 0xfe, 0x00, 0x09, 0x00, 0x77, 0x00, 0x0f, 0x00, 0x6f, 0x00), PHYREGS(0x07d4, 0x07d0, 0x07cc, 0x020b, 0x020c, 0x020d), }, { .freq = 5010, RADIOREGS3(0xff, 0x01, 0x01, 0x01, 0xf5, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x01, 0x01, 0x01, 0x8f, 0x0f, 0x00, 0xff, 0xfe, 0x00, 0x09, 0x00, 0x77, 0x00, 0x0f, 0x00, 0x6f, 0x00, 0xfe, 0x00, 0x09, 0x00, 0x77, 0x00, 0x0f, 0x00, 0x6f, 0x00), PHYREGS(0x07d8, 0x07d4, 0x07d0, 0x020a, 0x020b, 0x020c), }, { .freq = 5020, RADIOREGS3(0xf7, 0x01, 0x01, 0x01, 0xf6, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x01, 0x01, 0x01, 0x8f, 0x0f, 0x00, 0xff, 0xfe, 0x00, 0x09, 0x00, 0x77, 0x00, 0x0f, 0x00, 0x6f, 0x00, 0xfe, 0x00, 0x09, 0x00, 0x77, 0x00, 0x0f, 0x00, 0x6f, 0x00), PHYREGS(0x07dc, 0x07d8, 0x07d4, 0x0209, 0x020a, 0x020b), }, { .freq = 5030, RADIOREGS3(0xf7, 0x01, 0x01, 0x01, 0xf7, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x01, 0x01, 0x01, 0x8f, 0x0f, 0x00, 0xff, 0xfe, 0x00, 0x09, 0x00, 0x77, 0x00, 0x0f, 0x00, 0x6f, 0x00, 0xfe, 0x00, 0x09, 0x00, 0x77, 0x00, 0x0f, 0x00, 0x6f, 0x00), PHYREGS(0x07e0, 0x07dc, 0x07d8, 0x0208, 0x0209, 0x020a), }, { .freq = 5040, RADIOREGS3(0xef, 0x01, 0x01, 0x01, 0xf8, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x01, 0x01, 0x01, 0x8f, 0x0f, 0x00, 0xff, 0xfe, 0x00, 0x09, 0x00, 0x77, 0x00, 0x0f, 0x00, 0x6f, 0x00, 0xfe, 0x00, 0x09, 0x00, 0x77, 0x00, 0x0f, 0x00, 0x6f, 0x00), PHYREGS(0x07e4, 0x07e0, 0x07dc, 0x0207, 0x0208, 0x0209), }, { .freq = 5050, RADIOREGS3(0xef, 0x01, 0x01, 0x01, 0xf9, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x01, 0x01, 0x01, 0x8f, 0x0f, 0x00, 0xff, 0xfe, 0x00, 0x09, 0x00, 0x77, 0x00, 0x0f, 0x00, 0x6f, 0x00, 0xfe, 0x00, 0x09, 0x00, 0x77, 0x00, 0x0f, 0x00, 0x6f, 0x00), PHYREGS(0x07e8, 0x07e4, 0x07e0, 0x0206, 0x0207, 0x0208), }, { .freq = 5060, RADIOREGS3(0xe6, 0x01, 0x01, 0x01, 0xfa, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x01, 0x01, 0x01, 0x8f, 0x0f, 0x00, 0xff, 0xfe, 0x00, 0x09, 0x00, 0x77, 0x00, 0x0f, 0x00, 0x6f, 0x00, 0xfe, 0x00, 0x09, 0x00, 0x77, 0x00, 0x0f, 0x00, 0x6f, 0x00), PHYREGS(0x07ec, 0x07e8, 0x07e4, 0x0205, 0x0206, 0x0207), }, { .freq = 5070, RADIOREGS3(0xe6, 0x01, 0x01, 0x01, 0xfb, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x01, 0x01, 0x01, 0x8f, 0x0f, 0x00, 0xff, 0xfd, 0x00, 0x09, 0x00, 0x77, 0x00, 0x0f, 0x00, 0x6f, 0x00, 0xfd, 0x00, 0x09, 0x00, 0x77, 0x00, 0x0f, 0x00, 0x6f, 0x00), PHYREGS(0x07f0, 0x07ec, 0x07e8, 0x0204, 0x0205, 0x0206), }, { .freq = 5080, RADIOREGS3(0xde, 0x01, 0x01, 0x01, 0xfc, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x01, 0x01, 0x01, 0x8f, 0x0f, 0x00, 0xff, 0xfd, 0x00, 0x09, 0x00, 0x77, 0x00, 0x0f, 0x00, 0x6f, 0x00, 0xfd, 0x00, 0x09, 0x00, 0x77, 0x00, 0x0f, 0x00, 0x6f, 0x00), PHYREGS(0x07f4, 0x07f0, 0x07ec, 0x0203, 0x0204, 0x0205), }, { .freq = 5090, RADIOREGS3(0xde, 0x01, 0x01, 0x01, 0xfd, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x01, 0x01, 0x01, 0x8f, 0x0f, 0x00, 0xff, 0xfd, 0x00, 0x09, 0x00, 0x77, 0x00, 0x0f, 0x00, 0x6f, 0x00, 0xfd, 0x00, 0x09, 0x00, 0x77, 0x00, 0x0f, 0x00, 0x6f, 0x00), PHYREGS(0x07f8, 0x07f4, 0x07f0, 0x0202, 0x0203, 0x0204), }, { .freq = 5100, RADIOREGS3(0xd6, 0x01, 0x01, 0x01, 0xfe, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x02, 0x02, 0x02, 0x8f, 0x0f, 0x00, 0xff, 0xfd, 0x00, 0x08, 0x00, 0x77, 0x00, 0x0f, 0x00, 0x6f, 0x00, 0xfd, 0x00, 0x08, 0x00, 0x77, 0x00, 0x0f, 0x00, 0x6f, 0x00), PHYREGS(0x07fc, 0x07f8, 0x07f4, 0x0201, 0x0202, 0x0203), }, { .freq = 5110, RADIOREGS3(0xd6, 0x01, 0x01, 0x01, 0xff, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x02, 0x02, 0x02, 0x8f, 0x0f, 0x00, 0xff, 0xfc, 0x00, 0x08, 0x00, 0x77, 0x00, 0x0f, 0x00, 0x6f, 0x00, 0xfc, 0x00, 0x08, 0x00, 0x77, 0x00, 0x0f, 0x00, 0x6f, 0x00), PHYREGS(0x0800, 0x07fc, 0x07f8, 0x0200, 0x0201, 0x0202), }, { .freq = 5120, RADIOREGS3(0xce, 0x01, 0x01, 0x02, 0x00, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x02, 0x02, 0x02, 0x8f, 0x0f, 0x00, 0xff, 0xfc, 0x00, 0x08, 0x00, 0x77, 0x00, 0x0f, 0x00, 0x6f, 0x00, 0xfc, 0x00, 0x08, 0x00, 0x77, 0x00, 0x0f, 0x00, 0x6f, 0x00), PHYREGS(0x0804, 0x0800, 0x07fc, 0x01ff, 0x0200, 0x0201), }, { .freq = 5130, RADIOREGS3(0xce, 0x01, 0x01, 0x02, 0x01, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x02, 0x02, 0x02, 0x8f, 0x0f, 0x00, 0xff, 0xfc, 0x00, 0x08, 0x00, 0x77, 0x00, 0x0f, 0x00, 0x6f, 0x00, 0xfc, 0x00, 0x08, 0x00, 0x77, 0x00, 0x0f, 0x00, 0x6f, 0x00), PHYREGS(0x0808, 0x0804, 0x0800, 0x01fe, 0x01ff, 0x0200), }, { .freq = 5140, RADIOREGS3(0xc6, 0x01, 0x01, 0x02, 0x02, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x02, 0x02, 0x02, 0x8f, 0x0f, 0x00, 0xff, 0xfb, 0x00, 0x08, 0x00, 0x77, 0x00, 0x0f, 0x00, 0x6f, 0x00, 0xfb, 0x00, 0x08, 0x00, 0x77, 0x00, 0x0f, 0x00, 0x6f, 0x00), PHYREGS(0x080c, 0x0808, 0x0804, 0x01fd, 0x01fe, 0x01ff), }, { .freq = 5160, RADIOREGS3(0xbe, 0x01, 0x01, 0x02, 0x04, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x02, 0x02, 0x02, 0x8f, 0x0f, 0x00, 0xff, 0xfa, 0x00, 0x07, 0x00, 0x77, 0x00, 0x0e, 0x00, 0x6f, 0x00, 0xfa, 0x00, 0x07, 0x00, 0x77, 0x00, 0x0e, 0x00, 0x6f, 0x00), PHYREGS(0x0814, 0x0810, 0x080c, 0x01fb, 0x01fc, 0x01fd), }, { .freq = 5170, RADIOREGS3(0xbe, 0x01, 0x01, 0x02, 0x05, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x02, 0x02, 0x02, 0x8f, 0x0f, 0x00, 0xff, 0xfa, 0x00, 0x07, 0x00, 0x77, 0x00, 0x0e, 0x00, 0x6f, 0x00, 0xfa, 0x00, 0x07, 0x00, 0x77, 0x00, 0x0e, 0x00, 0x6f, 0x00), PHYREGS(0x0818, 0x0814, 0x0810, 0x01fa, 0x01fb, 0x01fc), }, { .freq = 5180, RADIOREGS3(0xb6, 0x01, 0x01, 0x02, 0x06, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x02, 0x02, 0x02, 0x8f, 0x0f, 0x00, 0xff, 0xf9, 0x00, 0x06, 0x00, 0x77, 0x00, 0x0e, 0x00, 0x6f, 0x00, 0xf9, 0x00, 0x06, 0x00, 0x77, 0x00, 0x0e, 0x00, 0x6f, 0x00), PHYREGS(0x081c, 0x0818, 0x0814, 0x01f9, 0x01fa, 0x01fb), }, { .freq = 5190, RADIOREGS3(0xb6, 0x01, 0x01, 0x02, 0x07, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x02, 0x02, 0x02, 0x8f, 0x0f, 0x00, 0xff, 0xf9, 0x00, 0x06, 0x00, 0x77, 0x00, 0x0d, 0x00, 0x6f, 0x00, 0xf9, 0x00, 0x06, 0x00, 0x77, 0x00, 0x0d, 0x00, 0x6f, 0x00), PHYREGS(0x0820, 0x081c, 0x0818, 0x01f8, 0x01f9, 0x01fa), }, { .freq = 5200, RADIOREGS3(0xaf, 0x01, 0x01, 0x02, 0x08, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x02, 0x02, 0x02, 0x8f, 0x0f, 0x00, 0xff, 0xf9, 0x00, 0x05, 0x00, 0x77, 0x00, 0x0d, 0x00, 0x6f, 0x00, 0xf9, 0x00, 0x05, 0x00, 0x77, 0x00, 0x0d, 0x00, 0x6f, 0x00), PHYREGS(0x0824, 0x0820, 0x081c, 0x01f7, 0x01f8, 0x01f9), }, { .freq = 5210, RADIOREGS3(0xaf, 0x01, 0x01, 0x02, 0x09, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x02, 0x02, 0x02, 0x8f, 0x0f, 0x00, 0xff, 0xf9, 0x00, 0x05, 0x00, 0x77, 0x00, 0x0d, 0x00, 0x6f, 0x00, 0xf9, 0x00, 0x05, 0x00, 0x77, 0x00, 0x0d, 0x00, 0x6f, 0x00), PHYREGS(0x0828, 0x0824, 0x0820, 0x01f6, 0x01f7, 0x01f8), }, { .freq = 5220, RADIOREGS3(0xa7, 0x01, 0x01, 0x02, 0x0a, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x02, 0x02, 0x02, 0x8e, 0x0f, 0x00, 0xfe, 0xd8, 0x00, 0x05, 0x00, 0x77, 0x00, 0x0d, 0x00, 0x6f, 0x00, 0xd8, 0x00, 0x05, 0x00, 0x77, 0x00, 0x0d, 0x00, 0x6f, 0x00), PHYREGS(0x082c, 0x0828, 0x0824, 0x01f5, 0x01f6, 0x01f7), }, { .freq = 5230, RADIOREGS3(0xa7, 0x01, 0x01, 0x02, 0x0b, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x02, 0x02, 0x02, 0x8e, 0x0f, 0x00, 0xee, 0xd8, 0x00, 0x05, 0x00, 0x77, 0x00, 0x0d, 0x00, 0x6f, 0x00, 0xd8, 0x00, 0x05, 0x00, 0x77, 0x00, 0x0d, 0x00, 0x6f, 0x00), PHYREGS(0x0830, 0x082c, 0x0828, 0x01f4, 0x01f5, 0x01f6), }, { .freq = 5240, RADIOREGS3(0xa0, 0x01, 0x01, 0x02, 0x0c, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x02, 0x02, 0x02, 0x8e, 0x0f, 0x00, 0xee, 0xc8, 0x00, 0x05, 0x00, 0x77, 0x00, 0x0d, 0x00, 0x6f, 0x00, 0xc8, 0x00, 0x05, 0x00, 0x77, 0x00, 0x0d, 0x00, 0x6f, 0x00), PHYREGS(0x0834, 0x0830, 0x082c, 0x01f3, 0x01f4, 0x01f5), }, { .freq = 5250, RADIOREGS3(0xa0, 0x01, 0x01, 0x02, 0x0d, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x02, 0x02, 0x02, 0x8e, 0x0f, 0x00, 0xed, 0xc7, 0x00, 0x05, 0x00, 0x77, 0x00, 0x0d, 0x00, 0x6f, 0x00, 0xc7, 0x00, 0x05, 0x00, 0x77, 0x00, 0x0d, 0x00, 0x6f, 0x00), PHYREGS(0x0838, 0x0834, 0x0830, 0x01f2, 0x01f3, 0x01f4), }, { .freq = 5260, RADIOREGS3(0x98, 0x01, 0x01, 0x02, 0x0e, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x02, 0x02, 0x02, 0x8e, 0x0e, 0x00, 0xed, 0xc7, 0x00, 0x04, 0x00, 0x77, 0x00, 0x0d, 0x00, 0x6f, 0x00, 0xc7, 0x00, 0x04, 0x00, 0x77, 0x00, 0x0d, 0x00, 0x6f, 0x00), PHYREGS(0x083c, 0x0838, 0x0834, 0x01f1, 0x01f2, 0x01f3), }, { .freq = 5270, RADIOREGS3(0x98, 0x01, 0x01, 0x02, 0x0f, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x03, 0x03, 0x03, 0x8e, 0x0e, 0x00, 0xed, 0xc7, 0x00, 0x04, 0x00, 0x77, 0x00, 0x0c, 0x00, 0x6f, 0x00, 0xc7, 0x00, 0x04, 0x00, 0x77, 0x00, 0x0c, 0x00, 0x6f, 0x00), PHYREGS(0x0840, 0x083c, 0x0838, 0x01f0, 0x01f1, 0x01f2), }, { .freq = 5280, RADIOREGS3(0x91, 0x01, 0x01, 0x02, 0x10, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x03, 0x03, 0x03, 0x8d, 0x0e, 0x00, 0xdc, 0xb7, 0x00, 0x03, 0x00, 0x77, 0x00, 0x0c, 0x00, 0x6f, 0x00, 0xb7, 0x00, 0x03, 0x00, 0x77, 0x00, 0x0c, 0x00, 0x6f, 0x00), PHYREGS(0x0844, 0x0840, 0x083c, 0x01f0, 0x01f0, 0x01f1), }, { .freq = 5290, RADIOREGS3(0x91, 0x01, 0x01, 0x02, 0x11, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x03, 0x03, 0x03, 0x8d, 0x0e, 0x00, 0xdc, 0xb7, 0x00, 0x03, 0x00, 0x77, 0x00, 0x0c, 0x00, 0x6f, 0x00, 0xb7, 0x00, 0x03, 0x00, 0x77, 0x00, 0x0c, 0x00, 0x6f, 0x00), PHYREGS(0x0848, 0x0844, 0x0840, 0x01ef, 0x01f0, 0x01f0), }, { .freq = 5300, RADIOREGS3(0x8a, 0x01, 0x01, 0x02, 0x12, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x03, 0x03, 0x03, 0x8d, 0x0e, 0x00, 0xdc, 0xb7, 0x00, 0x03, 0x00, 0x77, 0x00, 0x0c, 0x00, 0x6f, 0x00, 0xb7, 0x00, 0x03, 0x00, 0x77, 0x00, 0x0c, 0x00, 0x6f, 0x00), PHYREGS(0x084c, 0x0848, 0x0844, 0x01ee, 0x01ef, 0x01f0), }, { .freq = 5310, RADIOREGS3(0x8a, 0x01, 0x01, 0x02, 0x13, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x03, 0x03, 0x03, 0x8d, 0x0e, 0x00, 0xdc, 0xb7, 0x00, 0x03, 0x00, 0x77, 0x00, 0x0c, 0x00, 0x6f, 0x00, 0xb7, 0x00, 0x03, 0x00, 0x77, 0x00, 0x0c, 0x00, 0x6f, 0x00), PHYREGS(0x0850, 0x084c, 0x0848, 0x01ed, 0x01ee, 0x01ef), }, { .freq = 5320, RADIOREGS3(0x83, 0x01, 0x01, 0x02, 0x14, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x03, 0x03, 0x03, 0x8d, 0x0e, 0x00, 0xdb, 0xb7, 0x00, 0x03, 0x00, 0x77, 0x00, 0x0c, 0x00, 0x6f, 0x00, 0xb7, 0x00, 0x03, 0x00, 0x77, 0x00, 0x0c, 0x00, 0x6f, 0x00), PHYREGS(0x0854, 0x0850, 0x084c, 0x01ec, 0x01ed, 0x01ee), }, { .freq = 5330, RADIOREGS3(0x83, 0x01, 0x01, 0x02, 0x15, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x03, 0x03, 0x03, 0x8d, 0x0d, 0x00, 0xcb, 0xa6, 0x00, 0x03, 0x00, 0x77, 0x00, 0x0b, 0x00, 0x6f, 0x00, 0xa6, 0x00, 0x03, 0x00, 0x77, 0x00, 0x0b, 0x00, 0x6f, 0x00), PHYREGS(0x0858, 0x0854, 0x0850, 0x01eb, 0x01ec, 0x01ed), }, { .freq = 5340, RADIOREGS3(0x7c, 0x01, 0x01, 0x02, 0x16, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x03, 0x03, 0x03, 0x8d, 0x0d, 0x00, 0xca, 0xa6, 0x00, 0x03, 0x00, 0x77, 0x00, 0x0b, 0x00, 0x6f, 0x00, 0xa6, 0x00, 0x03, 0x00, 0x77, 0x00, 0x0b, 0x00, 0x6f, 0x00), PHYREGS(0x085c, 0x0858, 0x0854, 0x01ea, 0x01eb, 0x01ec), }, { .freq = 5350, RADIOREGS3(0x7c, 0x01, 0x01, 0x02, 0x17, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x03, 0x03, 0x03, 0x8c, 0x0d, 0x00, 0xca, 0xa6, 0x00, 0x03, 0x00, 0x77, 0x00, 0x0b, 0x00, 0x6f, 0x00, 0xa6, 0x00, 0x03, 0x00, 0x77, 0x00, 0x0b, 0x00, 0x6f, 0x00), PHYREGS(0x0860, 0x085c, 0x0858, 0x01e9, 0x01ea, 0x01eb), }, { .freq = 5360, RADIOREGS3(0x75, 0x01, 0x01, 0x02, 0x18, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x03, 0x03, 0x03, 0x8c, 0x0d, 0x00, 0xc9, 0x95, 0x00, 0x03, 0x00, 0x77, 0x00, 0x0a, 0x00, 0x6f, 0x00, 0x95, 0x00, 0x03, 0x00, 0x77, 0x00, 0x0a, 0x00, 0x6f, 0x00), PHYREGS(0x0864, 0x0860, 0x085c, 0x01e8, 0x01e9, 0x01ea), }, { .freq = 5370, RADIOREGS3(0x75, 0x01, 0x01, 0x02, 0x19, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x03, 0x03, 0x03, 0x8c, 0x0d, 0x00, 0xc9, 0x95, 0x00, 0x03, 0x00, 0x77, 0x00, 0x0a, 0x00, 0x6f, 0x00, 0x95, 0x00, 0x03, 0x00, 0x77, 0x00, 0x0a, 0x00, 0x6f, 0x00), PHYREGS(0x0868, 0x0864, 0x0860, 0x01e7, 0x01e8, 0x01e9), }, { .freq = 5380, RADIOREGS3(0x6e, 0x01, 0x01, 0x02, 0x1a, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x03, 0x03, 0x03, 0x8c, 0x0c, 0x00, 0xb8, 0x95, 0x00, 0x03, 0x00, 0x77, 0x00, 0x0a, 0x00, 0x6f, 0x00, 0x95, 0x00, 0x03, 0x00, 0x77, 0x00, 0x0a, 0x00, 0x6f, 0x00), PHYREGS(0x086c, 0x0868, 0x0864, 0x01e6, 0x01e7, 0x01e8), }, { .freq = 5390, RADIOREGS3(0x6e, 0x01, 0x01, 0x02, 0x1b, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x03, 0x03, 0x03, 0x8c, 0x0c, 0x00, 0xb8, 0x84, 0x00, 0x03, 0x00, 0x77, 0x00, 0x0a, 0x00, 0x6f, 0x00, 0x84, 0x00, 0x03, 0x00, 0x77, 0x00, 0x0a, 0x00, 0x6f, 0x00), PHYREGS(0x0870, 0x086c, 0x0868, 0x01e5, 0x01e6, 0x01e7), }, { .freq = 5400, RADIOREGS3(0x67, 0x01, 0x01, 0x02, 0x1c, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x03, 0x03, 0x03, 0x8c, 0x0c, 0x00, 0xb8, 0x84, 0x00, 0x03, 0x00, 0x77, 0x00, 0x0a, 0x00, 0x6f, 0x00, 0x84, 0x00, 0x03, 0x00, 0x77, 0x00, 0x0a, 0x00, 0x6f, 0x00), PHYREGS(0x0874, 0x0870, 0x086c, 0x01e5, 0x01e5, 0x01e6), }, { .freq = 5410, RADIOREGS3(0x67, 0x01, 0x01, 0x02, 0x1d, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x03, 0x03, 0x03, 0x8c, 0x0c, 0x00, 0xb7, 0x84, 0x00, 0x02, 0x00, 0x77, 0x00, 0x0a, 0x00, 0x6f, 0x00, 0x84, 0x00, 0x02, 0x00, 0x77, 0x00, 0x0a, 0x00, 0x6f, 0x00), PHYREGS(0x0878, 0x0874, 0x0870, 0x01e4, 0x01e5, 0x01e5), }, { .freq = 5420, RADIOREGS3(0x61, 0x01, 0x01, 0x02, 0x1e, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x03, 0x03, 0x03, 0x8c, 0x0c, 0x00, 0xa7, 0x84, 0x00, 0x02, 0x00, 0x77, 0x00, 0x0a, 0x00, 0x6f, 0x00, 0x84, 0x00, 0x02, 0x00, 0x77, 0x00, 0x0a, 0x00, 0x6f, 0x00), PHYREGS(0x087c, 0x0878, 0x0874, 0x01e3, 0x01e4, 0x01e5), }, { .freq = 5430, RADIOREGS3(0x61, 0x01, 0x01, 0x02, 0x1f, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x03, 0x03, 0x03, 0x8c, 0x0b, 0x00, 0xa6, 0x84, 0x00, 0x02, 0x00, 0x77, 0x00, 0x0a, 0x00, 0x6f, 0x00, 0x84, 0x00, 0x02, 0x00, 0x77, 0x00, 0x0a, 0x00, 0x6f, 0x00), PHYREGS(0x0880, 0x087c, 0x0878, 0x01e2, 0x01e3, 0x01e4), }, { .freq = 5440, RADIOREGS3(0x5a, 0x01, 0x01, 0x02, 0x20, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x04, 0x04, 0x04, 0x8b, 0x0b, 0x00, 0xa6, 0x84, 0x00, 0x02, 0x00, 0x77, 0x00, 0x09, 0x00, 0x6f, 0x00, 0x84, 0x00, 0x02, 0x00, 0x77, 0x00, 0x09, 0x00, 0x6f, 0x00), PHYREGS(0x0884, 0x0880, 0x087c, 0x01e1, 0x01e2, 0x01e3), }, { .freq = 5450, RADIOREGS3(0x5a, 0x01, 0x01, 0x02, 0x21, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x04, 0x04, 0x04, 0x8b, 0x0b, 0x00, 0x95, 0x84, 0x00, 0x01, 0x00, 0x77, 0x00, 0x09, 0x00, 0x6f, 0x00, 0x84, 0x00, 0x01, 0x00, 0x77, 0x00, 0x09, 0x00, 0x6f, 0x00), PHYREGS(0x0888, 0x0884, 0x0880, 0x01e0, 0x01e1, 0x01e2), }, { .freq = 5460, RADIOREGS3(0x53, 0x01, 0x01, 0x02, 0x22, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x04, 0x04, 0x04, 0x8b, 0x0b, 0x00, 0x95, 0x84, 0x00, 0x01, 0x00, 0x77, 0x00, 0x09, 0x00, 0x6f, 0x00, 0x84, 0x00, 0x01, 0x00, 0x77, 0x00, 0x09, 0x00, 0x6f, 0x00), PHYREGS(0x088c, 0x0888, 0x0884, 0x01df, 0x01e0, 0x01e1), }, { .freq = 5470, RADIOREGS3(0x53, 0x01, 0x01, 0x02, 0x23, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x04, 0x04, 0x04, 0x8b, 0x0b, 0x00, 0x94, 0x73, 0x00, 0x01, 0x00, 0x77, 0x00, 0x09, 0x00, 0x6f, 0x00, 0x73, 0x00, 0x01, 0x00, 0x77, 0x00, 0x09, 0x00, 0x6f, 0x00), PHYREGS(0x0890, 0x088c, 0x0888, 0x01de, 0x01df, 0x01e0), }, { .freq = 5480, RADIOREGS3(0x4d, 0x01, 0x01, 0x02, 0x24, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x04, 0x04, 0x04, 0x8a, 0x0a, 0x00, 0x84, 0x73, 0x00, 0x00, 0x00, 0x77, 0x00, 0x09, 0x00, 0x6f, 0x00, 0x73, 0x00, 0x00, 0x00, 0x77, 0x00, 0x09, 0x00, 0x6f, 0x00), PHYREGS(0x0894, 0x0890, 0x088c, 0x01dd, 0x01de, 0x01df), }, { .freq = 5490, RADIOREGS3(0x4d, 0x01, 0x01, 0x02, 0x25, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x04, 0x04, 0x04, 0x8a, 0x0a, 0x00, 0x83, 0x73, 0x00, 0x00, 0x00, 0x77, 0x00, 0x09, 0x00, 0x6f, 0x00, 0x73, 0x00, 0x00, 0x00, 0x77, 0x00, 0x09, 0x00, 0x6f, 0x00), PHYREGS(0x0898, 0x0894, 0x0890, 0x01dd, 0x01dd, 0x01de), }, { .freq = 5500, RADIOREGS3(0x47, 0x01, 0x01, 0x02, 0x26, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x04, 0x04, 0x04, 0x8a, 0x0a, 0x00, 0x82, 0x73, 0x00, 0x00, 0x00, 0x77, 0x00, 0x09, 0x00, 0x6f, 0x00, 0x73, 0x00, 0x00, 0x00, 0x77, 0x00, 0x09, 0x00, 0x6f, 0x00), PHYREGS(0x089c, 0x0898, 0x0894, 0x01dc, 0x01dd, 0x01dd), }, { .freq = 5510, RADIOREGS3(0x47, 0x01, 0x01, 0x02, 0x27, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x04, 0x04, 0x04, 0x8a, 0x0a, 0x00, 0x82, 0x73, 0x00, 0x00, 0x00, 0x77, 0x00, 0x09, 0x00, 0x6f, 0x00, 0x73, 0x00, 0x00, 0x00, 0x77, 0x00, 0x09, 0x00, 0x6f, 0x00), PHYREGS(0x08a0, 0x089c, 0x0898, 0x01db, 0x01dc, 0x01dd), }, { .freq = 5520, RADIOREGS3(0x40, 0x01, 0x01, 0x02, 0x28, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x04, 0x04, 0x04, 0x8a, 0x0a, 0x00, 0x72, 0x73, 0x00, 0x00, 0x00, 0x77, 0x00, 0x09, 0x00, 0x6f, 0x00, 0x73, 0x00, 0x00, 0x00, 0x77, 0x00, 0x09, 0x00, 0x6f, 0x00), PHYREGS(0x08a4, 0x08a0, 0x089c, 0x01da, 0x01db, 0x01dc), }, { .freq = 5530, RADIOREGS3(0x40, 0x01, 0x01, 0x02, 0x29, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x04, 0x04, 0x04, 0x8a, 0x09, 0x00, 0x72, 0x73, 0x00, 0x00, 0x00, 0x77, 0x00, 0x09, 0x00, 0x6f, 0x00, 0x73, 0x00, 0x00, 0x00, 0x77, 0x00, 0x09, 0x00, 0x6f, 0x00), PHYREGS(0x08a8, 0x08a4, 0x08a0, 0x01d9, 0x01da, 0x01db), }, { .freq = 5540, RADIOREGS3(0x3a, 0x01, 0x01, 0x02, 0x2a, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x04, 0x04, 0x04, 0x8a, 0x09, 0x00, 0x71, 0x73, 0x00, 0x00, 0x00, 0x77, 0x00, 0x09, 0x00, 0x6f, 0x00, 0x73, 0x00, 0x00, 0x00, 0x77, 0x00, 0x09, 0x00, 0x6f, 0x00), PHYREGS(0x08ac, 0x08a8, 0x08a4, 0x01d8, 0x01d9, 0x01da), }, { .freq = 5550, RADIOREGS3(0x3a, 0x01, 0x01, 0x02, 0x2b, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x04, 0x04, 0x04, 0x89, 0x09, 0x00, 0x61, 0x73, 0x00, 0x00, 0x00, 0x77, 0x00, 0x09, 0x00, 0x6f, 0x00, 0x73, 0x00, 0x00, 0x00, 0x77, 0x00, 0x09, 0x00, 0x6f, 0x00), PHYREGS(0x08b0, 0x08ac, 0x08a8, 0x01d7, 0x01d8, 0x01d9), }, { .freq = 5560, RADIOREGS3(0x34, 0x01, 0x01, 0x02, 0x2c, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x04, 0x04, 0x04, 0x89, 0x09, 0x00, 0x61, 0x73, 0x00, 0x00, 0x00, 0x77, 0x00, 0x09, 0x00, 0x6f, 0x00, 0x73, 0x00, 0x00, 0x00, 0x77, 0x00, 0x09, 0x00, 0x6f, 0x00), PHYREGS(0x08b4, 0x08b0, 0x08ac, 0x01d7, 0x01d7, 0x01d8), }, { .freq = 5570, RADIOREGS3(0x34, 0x01, 0x01, 0x02, 0x2d, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x04, 0x04, 0x04, 0x89, 0x09, 0x00, 0x61, 0x62, 0x00, 0x00, 0x00, 0x77, 0x00, 0x09, 0x00, 0x6f, 0x00, 0x62, 0x00, 0x00, 0x00, 0x77, 0x00, 0x09, 0x00, 0x6f, 0x00), PHYREGS(0x08b8, 0x08b4, 0x08b0, 0x01d6, 0x01d7, 0x01d7), }, { .freq = 5580, RADIOREGS3(0x2e, 0x01, 0x01, 0x02, 0x2e, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x04, 0x04, 0x04, 0x89, 0x08, 0x00, 0x60, 0x62, 0x00, 0x00, 0x00, 0x77, 0x00, 0x08, 0x00, 0x6f, 0x00, 0x62, 0x00, 0x00, 0x00, 0x77, 0x00, 0x08, 0x00, 0x6f, 0x00), PHYREGS(0x08bc, 0x08b8, 0x08b4, 0x01d5, 0x01d6, 0x01d7), }, { .freq = 5590, RADIOREGS3(0x2e, 0x01, 0x01, 0x02, 0x2f, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x04, 0x04, 0x04, 0x89, 0x08, 0x00, 0x50, 0x61, 0x00, 0x00, 0x00, 0x77, 0x00, 0x08, 0x00, 0x6f, 0x00, 0x61, 0x00, 0x00, 0x00, 0x77, 0x00, 0x08, 0x00, 0x6f, 0x00), PHYREGS(0x08c0, 0x08bc, 0x08b8, 0x01d4, 0x01d5, 0x01d6), }, { .freq = 5600, RADIOREGS3(0x28, 0x01, 0x01, 0x02, 0x30, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x05, 0x05, 0x05, 0x89, 0x08, 0x00, 0x50, 0x51, 0x00, 0x00, 0x00, 0x77, 0x00, 0x08, 0x00, 0x6f, 0x00, 0x51, 0x00, 0x00, 0x00, 0x77, 0x00, 0x08, 0x00, 0x6f, 0x00), PHYREGS(0x08c4, 0x08c0, 0x08bc, 0x01d3, 0x01d4, 0x01d5), }, { .freq = 5610, RADIOREGS3(0x28, 0x01, 0x01, 0x02, 0x31, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x05, 0x05, 0x05, 0x89, 0x08, 0x00, 0x50, 0x51, 0x00, 0x00, 0x00, 0x77, 0x00, 0x08, 0x00, 0x6f, 0x00, 0x51, 0x00, 0x00, 0x00, 0x77, 0x00, 0x08, 0x00, 0x6f, 0x00), PHYREGS(0x08c8, 0x08c4, 0x08c0, 0x01d2, 0x01d3, 0x01d4), }, { .freq = 5620, RADIOREGS3(0x21, 0x01, 0x01, 0x02, 0x32, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x05, 0x05, 0x05, 0x89, 0x08, 0x00, 0x50, 0x50, 0x00, 0x00, 0x00, 0x77, 0x00, 0x07, 0x00, 0x6f, 0x00, 0x50, 0x00, 0x00, 0x00, 0x77, 0x00, 0x07, 0x00, 0x6f, 0x00), PHYREGS(0x08cc, 0x08c8, 0x08c4, 0x01d2, 0x01d2, 0x01d3), }, { .freq = 5630, RADIOREGS3(0x21, 0x01, 0x01, 0x02, 0x33, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x05, 0x05, 0x05, 0x88, 0x07, 0x00, 0x50, 0x50, 0x00, 0x00, 0x00, 0x77, 0x00, 0x07, 0x00, 0x6f, 0x00, 0x50, 0x00, 0x00, 0x00, 0x77, 0x00, 0x07, 0x00, 0x6f, 0x00), PHYREGS(0x08d0, 0x08cc, 0x08c8, 0x01d1, 0x01d2, 0x01d2), }, { .freq = 5640, RADIOREGS3(0x1c, 0x01, 0x01, 0x02, 0x34, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x05, 0x05, 0x05, 0x88, 0x07, 0x00, 0x40, 0x50, 0x00, 0x00, 0x00, 0x77, 0x00, 0x07, 0x00, 0x6f, 0x00, 0x50, 0x00, 0x00, 0x00, 0x77, 0x00, 0x07, 0x00, 0x6f, 0x00), PHYREGS(0x08d4, 0x08d0, 0x08cc, 0x01d0, 0x01d1, 0x01d2), }, { .freq = 5650, RADIOREGS3(0x1c, 0x01, 0x01, 0x02, 0x35, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x05, 0x05, 0x05, 0x88, 0x07, 0x00, 0x40, 0x40, 0x00, 0x00, 0x00, 0x77, 0x00, 0x07, 0x00, 0x6f, 0x00, 0x40, 0x00, 0x00, 0x00, 0x77, 0x00, 0x07, 0x00, 0x6f, 0x00), PHYREGS(0x08d8, 0x08d4, 0x08d0, 0x01cf, 0x01d0, 0x01d1), }, { .freq = 5660, RADIOREGS3(0x16, 0x01, 0x01, 0x02, 0x36, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x05, 0x05, 0x05, 0x88, 0x07, 0x00, 0x40, 0x40, 0x00, 0x00, 0x00, 0x77, 0x00, 0x06, 0x00, 0x6f, 0x00, 0x40, 0x00, 0x00, 0x00, 0x77, 0x00, 0x06, 0x00, 0x6f, 0x00), PHYREGS(0x08dc, 0x08d8, 0x08d4, 0x01ce, 0x01cf, 0x01d0), }, { .freq = 5670, RADIOREGS3(0x16, 0x01, 0x01, 0x02, 0x37, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x05, 0x05, 0x05, 0x88, 0x07, 0x00, 0x40, 0x30, 0x00, 0x00, 0x00, 0x77, 0x00, 0x06, 0x00, 0x6f, 0x00, 0x30, 0x00, 0x00, 0x00, 0x77, 0x00, 0x06, 0x00, 0x6f, 0x00), PHYREGS(0x08e0, 0x08dc, 0x08d8, 0x01ce, 0x01ce, 0x01cf), }, { .freq = 5680, RADIOREGS3(0x10, 0x01, 0x01, 0x02, 0x38, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x05, 0x05, 0x05, 0x87, 0x06, 0x00, 0x30, 0x30, 0x00, 0x00, 0x00, 0x77, 0x00, 0x06, 0x00, 0x6f, 0x00, 0x30, 0x00, 0x00, 0x00, 0x77, 0x00, 0x06, 0x00, 0x6f, 0x00), PHYREGS(0x08e4, 0x08e0, 0x08dc, 0x01cd, 0x01ce, 0x01ce), }, { .freq = 5690, RADIOREGS3(0x10, 0x01, 0x01, 0x02, 0x39, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x05, 0x05, 0x05, 0x87, 0x06, 0x00, 0x30, 0x30, 0x00, 0x00, 0x00, 0x77, 0x00, 0x06, 0x00, 0x6f, 0x00, 0x30, 0x00, 0x00, 0x00, 0x77, 0x00, 0x06, 0x00, 0x6f, 0x00), PHYREGS(0x08e8, 0x08e4, 0x08e0, 0x01cc, 0x01cd, 0x01ce), }, { .freq = 5700, RADIOREGS3(0x0a, 0x01, 0x01, 0x02, 0x3a, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x05, 0x05, 0x05, 0x87, 0x06, 0x00, 0x30, 0x30, 0x00, 0x00, 0x00, 0x77, 0x00, 0x06, 0x00, 0x6e, 0x00, 0x30, 0x00, 0x00, 0x00, 0x77, 0x00, 0x06, 0x00, 0x6e, 0x00), PHYREGS(0x08ec, 0x08e8, 0x08e4, 0x01cb, 0x01cc, 0x01cd), }, { .freq = 5710, RADIOREGS3(0x0a, 0x01, 0x01, 0x02, 0x3b, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x05, 0x05, 0x05, 0x87, 0x06, 0x00, 0x30, 0x30, 0x00, 0x00, 0x00, 0x77, 0x00, 0x06, 0x00, 0x6e, 0x00, 0x30, 0x00, 0x00, 0x00, 0x77, 0x00, 0x06, 0x00, 0x6e, 0x00), PHYREGS(0x08f0, 0x08ec, 0x08e8, 0x01ca, 0x01cb, 0x01cc), }, { .freq = 5720, RADIOREGS3(0x0a, 0x01, 0x01, 0x02, 0x3c, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x05, 0x05, 0x05, 0x87, 0x06, 0x00, 0x30, 0x30, 0x00, 0x00, 0x00, 0x77, 0x00, 0x06, 0x00, 0x6e, 0x00, 0x30, 0x00, 0x00, 0x00, 0x77, 0x00, 0x06, 0x00, 0x6e, 0x00), PHYREGS(0x08f4, 0x08f0, 0x08ec, 0x01c9, 0x01ca, 0x01cb), }, { .freq = 5725, RADIOREGS3(0x03, 0x01, 0x02, 0x04, 0x79, 0x07, 0x07, 0x04, 0x10, 0x01, 0x05, 0x05, 0x05, 0x87, 0x06, 0x00, 0x30, 0x30, 0x00, 0x00, 0x00, 0x77, 0x00, 0x06, 0x00, 0x6e, 0x00, 0x30, 0x00, 0x00, 0x00, 0x77, 0x00, 0x06, 0x00, 0x6e, 0x00), PHYREGS(0x08f6, 0x08f2, 0x08ee, 0x01c9, 0x01ca, 0x01cb), }, { .freq = 5730, RADIOREGS3(0x0a, 0x01, 0x01, 0x02, 0x3d, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x05, 0x05, 0x05, 0x87, 0x05, 0x00, 0x20, 0x30, 0x00, 0x00, 0x00, 0x77, 0x00, 0x06, 0x00, 0x6e, 0x00, 0x30, 0x00, 0x00, 0x00, 0x77, 0x00, 0x06, 0x00, 0x6e, 0x00), PHYREGS(0x08f8, 0x08f4, 0x08f0, 0x01c9, 0x01c9, 0x01ca), }, { .freq = 5735, RADIOREGS3(0x03, 0x01, 0x02, 0x04, 0x7b, 0x07, 0x07, 0x04, 0x10, 0x01, 0x05, 0x05, 0x05, 0x87, 0x05, 0x00, 0x20, 0x30, 0x00, 0x00, 0x00, 0x77, 0x00, 0x06, 0x00, 0x6d, 0x00, 0x30, 0x00, 0x00, 0x00, 0x77, 0x00, 0x06, 0x00, 0x6d, 0x00), PHYREGS(0x08fa, 0x08f6, 0x08f2, 0x01c8, 0x01c9, 0x01ca), }, { .freq = 5740, RADIOREGS3(0x0a, 0x01, 0x01, 0x02, 0x3e, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x05, 0x05, 0x05, 0x87, 0x05, 0x00, 0x20, 0x30, 0x00, 0x00, 0x00, 0x77, 0x00, 0x06, 0x00, 0x6d, 0x00, 0x30, 0x00, 0x00, 0x00, 0x77, 0x00, 0x06, 0x00, 0x6d, 0x00), PHYREGS(0x08fc, 0x08f8, 0x08f4, 0x01c8, 0x01c9, 0x01c9), }, { .freq = 5745, RADIOREGS3(0xfe, 0x00, 0x02, 0x04, 0x7d, 0x07, 0x07, 0x04, 0x10, 0x01, 0x05, 0x05, 0x05, 0x87, 0x05, 0x00, 0x20, 0x30, 0x00, 0x00, 0x00, 0x77, 0x00, 0x06, 0x00, 0x6d, 0x00, 0x30, 0x00, 0x00, 0x00, 0x77, 0x00, 0x06, 0x00, 0x6d, 0x00), PHYREGS(0x08fe, 0x08fa, 0x08f6, 0x01c8, 0x01c8, 0x01c9), }, { .freq = 5750, RADIOREGS3(0x0a, 0x01, 0x01, 0x02, 0x3f, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x05, 0x05, 0x05, 0x87, 0x05, 0x00, 0x20, 0x20, 0x00, 0x00, 0x00, 0x77, 0x00, 0x05, 0x00, 0x6d, 0x00, 0x20, 0x00, 0x00, 0x00, 0x77, 0x00, 0x05, 0x00, 0x6d, 0x00), PHYREGS(0x0900, 0x08fc, 0x08f8, 0x01c7, 0x01c8, 0x01c9), }, { .freq = 5755, RADIOREGS3(0xfe, 0x00, 0x02, 0x04, 0x7f, 0x07, 0x07, 0x04, 0x10, 0x01, 0x05, 0x05, 0x05, 0x87, 0x05, 0x00, 0x10, 0x20, 0x00, 0x00, 0x00, 0x77, 0x00, 0x05, 0x00, 0x6c, 0x00, 0x20, 0x00, 0x00, 0x00, 0x77, 0x00, 0x05, 0x00, 0x6c, 0x00), PHYREGS(0x0902, 0x08fe, 0x08fa, 0x01c7, 0x01c8, 0x01c8), }, { .freq = 5760, RADIOREGS3(0x0a, 0x01, 0x01, 0x02, 0x40, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x05, 0x05, 0x05, 0x86, 0x05, 0x00, 0x10, 0x20, 0x00, 0x00, 0x00, 0x77, 0x00, 0x05, 0x00, 0x6c, 0x00, 0x20, 0x00, 0x00, 0x00, 0x77, 0x00, 0x05, 0x00, 0x6c, 0x00), PHYREGS(0x0904, 0x0900, 0x08fc, 0x01c6, 0x01c7, 0x01c8), }, { .freq = 5765, RADIOREGS3(0xf8, 0x00, 0x02, 0x04, 0x81, 0x07, 0x07, 0x04, 0x10, 0x01, 0x05, 0x05, 0x05, 0x86, 0x05, 0x00, 0x10, 0x10, 0x00, 0x00, 0x00, 0x77, 0x00, 0x05, 0x00, 0x6c, 0x00, 0x10, 0x00, 0x00, 0x00, 0x77, 0x00, 0x05, 0x00, 0x6c, 0x00), PHYREGS(0x0906, 0x0902, 0x08fe, 0x01c6, 0x01c7, 0x01c8), }, { .freq = 5770, RADIOREGS3(0x0a, 0x01, 0x01, 0x02, 0x41, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x05, 0x05, 0x05, 0x86, 0x04, 0x00, 0x10, 0x10, 0x00, 0x00, 0x00, 0x77, 0x00, 0x05, 0x00, 0x6b, 0x00, 0x10, 0x00, 0x00, 0x00, 0x77, 0x00, 0x05, 0x00, 0x6b, 0x00), PHYREGS(0x0908, 0x0904, 0x0900, 0x01c6, 0x01c6, 0x01c7), }, { .freq = 5775, RADIOREGS3(0xf8, 0x00, 0x02, 0x04, 0x83, 0x07, 0x07, 0x04, 0x10, 0x01, 0x05, 0x05, 0x05, 0x86, 0x04, 0x00, 0x10, 0x10, 0x00, 0x00, 0x00, 0x77, 0x00, 0x05, 0x00, 0x6b, 0x00, 0x10, 0x00, 0x00, 0x00, 0x77, 0x00, 0x05, 0x00, 0x6b, 0x00), PHYREGS(0x090a, 0x0906, 0x0902, 0x01c5, 0x01c6, 0x01c7), }, { .freq = 5780, RADIOREGS3(0x0a, 0x01, 0x01, 0x02, 0x42, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x05, 0x05, 0x05, 0x86, 0x04, 0x00, 0x10, 0x10, 0x00, 0x00, 0x00, 0x77, 0x00, 0x05, 0x00, 0x6b, 0x00, 0x10, 0x00, 0x00, 0x00, 0x77, 0x00, 0x05, 0x00, 0x6b, 0x00), PHYREGS(0x090c, 0x0908, 0x0904, 0x01c5, 0x01c6, 0x01c6), }, { .freq = 5785, RADIOREGS3(0xf2, 0x00, 0x02, 0x04, 0x85, 0x07, 0x07, 0x04, 0x10, 0x01, 0x06, 0x06, 0x06, 0x86, 0x04, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x77, 0x00, 0x05, 0x00, 0x6b, 0x00, 0x10, 0x00, 0x00, 0x00, 0x77, 0x00, 0x05, 0x00, 0x6b, 0x00), PHYREGS(0x090e, 0x090a, 0x0906, 0x01c4, 0x01c5, 0x01c6), }, { .freq = 5790, RADIOREGS3(0x0a, 0x01, 0x01, 0x02, 0x43, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x06, 0x06, 0x06, 0x86, 0x04, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x77, 0x00, 0x05, 0x00, 0x6b, 0x00, 0x10, 0x00, 0x00, 0x00, 0x77, 0x00, 0x05, 0x00, 0x6b, 0x00), PHYREGS(0x0910, 0x090c, 0x0908, 0x01c4, 0x01c5, 0x01c6), }, { .freq = 5795, RADIOREGS3(0xf2, 0x00, 0x02, 0x04, 0x87, 0x07, 0x07, 0x04, 0x10, 0x01, 0x06, 0x06, 0x06, 0x86, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x77, 0x00, 0x05, 0x00, 0x6b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x77, 0x00, 0x05, 0x00, 0x6b, 0x00), PHYREGS(0x0912, 0x090e, 0x090a, 0x01c4, 0x01c4, 0x01c5), }, { .freq = 5800, RADIOREGS3(0x0a, 0x01, 0x01, 0x02, 0x44, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x06, 0x06, 0x06, 0x86, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x77, 0x00, 0x05, 0x00, 0x6b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x77, 0x00, 0x05, 0x00, 0x6b, 0x00), PHYREGS(0x0914, 0x0910, 0x090c, 0x01c3, 0x01c4, 0x01c5), }, { .freq = 5805, RADIOREGS3(0xed, 0x00, 0x02, 0x04, 0x89, 0x07, 0x07, 0x04, 0x10, 0x01, 0x06, 0x06, 0x06, 0x86, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x77, 0x00, 0x05, 0x00, 0x6a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x77, 0x00, 0x05, 0x00, 0x6a, 0x00), PHYREGS(0x0916, 0x0912, 0x090e, 0x01c3, 0x01c4, 0x01c4), }, { .freq = 5810, RADIOREGS3(0x0a, 0x01, 0x01, 0x02, 0x45, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x06, 0x06, 0x06, 0x86, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x77, 0x00, 0x05, 0x00, 0x6a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x77, 0x00, 0x05, 0x00, 0x6a, 0x00), PHYREGS(0x0918, 0x0914, 0x0910, 0x01c2, 0x01c3, 0x01c4), }, { .freq = 5815, RADIOREGS3(0xed, 0x00, 0x02, 0x04, 0x8b, 0x07, 0x07, 0x04, 0x10, 0x01, 0x06, 0x06, 0x06, 0x86, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x77, 0x00, 0x05, 0x00, 0x6a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x77, 0x00, 0x05, 0x00, 0x6a, 0x00), PHYREGS(0x091a, 0x0916, 0x0912, 0x01c2, 0x01c3, 0x01c4), }, { .freq = 5820, RADIOREGS3(0x0a, 0x01, 0x01, 0x02, 0x46, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x06, 0x06, 0x06, 0x86, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x77, 0x00, 0x05, 0x00, 0x6a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x77, 0x00, 0x05, 0x00, 0x6a, 0x00), PHYREGS(0x091c, 0x0918, 0x0914, 0x01c2, 0x01c2, 0x01c3), }, { .freq = 5825, RADIOREGS3(0xed, 0x00, 0x02, 0x04, 0x8d, 0x07, 0x07, 0x04, 0x10, 0x01, 0x06, 0x06, 0x06, 0x86, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x77, 0x00, 0x05, 0x00, 0x69, 0x00, 0x00, 0x00, 0x00, 0x00, 0x77, 0x00, 0x05, 0x00, 0x69, 0x00), PHYREGS(0x091e, 0x091a, 0x0916, 0x01c1, 0x01c2, 0x01c3), }, { .freq = 5830, RADIOREGS3(0x0a, 0x01, 0x01, 0x02, 0x47, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x06, 0x06, 0x06, 0x86, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x77, 0x00, 0x05, 0x00, 0x69, 0x00, 0x00, 0x00, 0x00, 0x00, 0x77, 0x00, 0x05, 0x00, 0x69, 0x00), PHYREGS(0x0920, 0x091c, 0x0918, 0x01c1, 0x01c2, 0x01c2), }, { .freq = 5840, RADIOREGS3(0x0a, 0x01, 0x01, 0x02, 0x48, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x06, 0x06, 0x06, 0x86, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x77, 0x00, 0x04, 0x00, 0x69, 0x00, 0x00, 0x00, 0x00, 0x00, 0x77, 0x00, 0x04, 0x00, 0x69, 0x00), PHYREGS(0x0924, 0x0920, 0x091c, 0x01c0, 0x01c1, 0x01c2), }, { .freq = 5850, RADIOREGS3(0xe0, 0x00, 0x01, 0x02, 0x49, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x06, 0x06, 0x06, 0x85, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x77, 0x00, 0x04, 0x00, 0x69, 0x00, 0x00, 0x00, 0x00, 0x00, 0x77, 0x00, 0x04, 0x00, 0x69, 0x00), PHYREGS(0x0928, 0x0924, 0x0920, 0x01bf, 0x01c0, 0x01c1), }, { .freq = 5860, RADIOREGS3(0xde, 0x00, 0x01, 0x02, 0x4a, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x06, 0x06, 0x06, 0x85, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x77, 0x00, 0x04, 0x00, 0x69, 0x00, 0x00, 0x00, 0x00, 0x00, 0x77, 0x00, 0x04, 0x00, 0x69, 0x00), PHYREGS(0x092c, 0x0928, 0x0924, 0x01bf, 0x01bf, 0x01c0), }, { .freq = 5870, RADIOREGS3(0xdb, 0x00, 0x01, 0x02, 0x4b, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x06, 0x06, 0x06, 0x85, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x77, 0x00, 0x04, 0x00, 0x68, 0x00, 0x00, 0x00, 0x00, 0x00, 0x77, 0x00, 0x04, 0x00, 0x68, 0x00), PHYREGS(0x0930, 0x092c, 0x0928, 0x01be, 0x01bf, 0x01bf), }, { .freq = 5880, RADIOREGS3(0xd8, 0x00, 0x01, 0x02, 0x4c, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x06, 0x06, 0x06, 0x85, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x77, 0x00, 0x04, 0x00, 0x68, 0x00, 0x00, 0x00, 0x00, 0x00, 0x77, 0x00, 0x04, 0x00, 0x68, 0x00), PHYREGS(0x0934, 0x0930, 0x092c, 0x01bd, 0x01be, 0x01bf), }, { .freq = 5890, RADIOREGS3(0xd6, 0x00, 0x01, 0x02, 0x4d, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x06, 0x06, 0x06, 0x85, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x77, 0x00, 0x04, 0x00, 0x68, 0x00, 0x00, 0x00, 0x00, 0x00, 0x77, 0x00, 0x04, 0x00, 0x68, 0x00), PHYREGS(0x0938, 0x0934, 0x0930, 0x01bc, 0x01bd, 0x01be), }, { .freq = 5900, RADIOREGS3(0xd3, 0x00, 0x01, 0x02, 0x4e, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x06, 0x06, 0x06, 0x85, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x77, 0x00, 0x04, 0x00, 0x68, 0x00, 0x00, 0x00, 0x00, 0x00, 0x77, 0x00, 0x04, 0x00, 0x68, 0x00), PHYREGS(0x093c, 0x0938, 0x0934, 0x01bc, 0x01bc, 0x01bd), }, { .freq = 5910, RADIOREGS3(0xd6, 0x00, 0x01, 0x02, 0x4f, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x06, 0x06, 0x06, 0x85, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x77, 0x00, 0x04, 0x00, 0x68, 0x00, 0x00, 0x00, 0x00, 0x00, 0x77, 0x00, 0x04, 0x00, 0x68, 0x00), PHYREGS(0x0940, 0x093c, 0x0938, 0x01bb, 0x01bc, 0x01bc), }, { .freq = 2412, RADIOREGS3(0x00, 0x01, 0x03, 0x09, 0x6c, 0x08, 0x08, 0x04, 0x16, 0x01, 0x04, 0x04, 0x04, 0x8f, 0x30, 0x00, 0x00, 0x00, 0x78, 0x00, 0x03, 0x00, 0x70, 0x00, 0x0b, 0x00, 0x0a, 0x00, 0x78, 0x00, 0x03, 0x00, 0x70, 0x00, 0x0b, 0x00, 0x0a), PHYREGS(0x03c9, 0x03c5, 0x03c1, 0x043a, 0x043f, 0x0443), }, { .freq = 2417, RADIOREGS3(0x00, 0x01, 0x03, 0x09, 0x71, 0x08, 0x08, 0x04, 0x16, 0x01, 0x05, 0x05, 0x05, 0x8f, 0x30, 0x00, 0x00, 0x00, 0x78, 0x00, 0x03, 0x00, 0x70, 0x00, 0x0b, 0x00, 0x0a, 0x00, 0x78, 0x00, 0x03, 0x00, 0x70, 0x00, 0x0b, 0x00, 0x0a), PHYREGS(0x03cb, 0x03c7, 0x03c3, 0x0438, 0x043d, 0x0441), }, { .freq = 2422, RADIOREGS3(0x00, 0x01, 0x03, 0x09, 0x76, 0x08, 0x08, 0x04, 0x16, 0x01, 0x05, 0x05, 0x05, 0x8f, 0x30, 0x00, 0x00, 0x00, 0x67, 0x00, 0x03, 0x00, 0x70, 0x00, 0x0b, 0x00, 0x0a, 0x00, 0x67, 0x00, 0x03, 0x00, 0x70, 0x00, 0x0b, 0x00, 0x0a), PHYREGS(0x03cd, 0x03c9, 0x03c5, 0x0436, 0x043a, 0x043f), }, { .freq = 2427, RADIOREGS3(0x00, 0x01, 0x03, 0x09, 0x7b, 0x08, 0x08, 0x04, 0x16, 0x01, 0x05, 0x05, 0x05, 0x8f, 0x30, 0x00, 0x00, 0x00, 0x57, 0x00, 0x03, 0x00, 0x70, 0x00, 0x0a, 0x00, 0x0a, 0x00, 0x57, 0x00, 0x03, 0x00, 0x70, 0x00, 0x0a, 0x00, 0x0a), PHYREGS(0x03cf, 0x03cb, 0x03c7, 0x0434, 0x0438, 0x043d), }, { .freq = 2432, RADIOREGS3(0x00, 0x01, 0x03, 0x09, 0x80, 0x08, 0x08, 0x04, 0x16, 0x01, 0x05, 0x05, 0x05, 0x8f, 0x30, 0x00, 0x00, 0x00, 0x56, 0x00, 0x03, 0x00, 0x70, 0x00, 0x0a, 0x00, 0x0a, 0x00, 0x56, 0x00, 0x03, 0x00, 0x70, 0x00, 0x0a, 0x00, 0x0a), PHYREGS(0x03d1, 0x03cd, 0x03c9, 0x0431, 0x0436, 0x043a), }, { .freq = 2437, RADIOREGS3(0x00, 0x01, 0x03, 0x09, 0x85, 0x08, 0x08, 0x04, 0x16, 0x01, 0x05, 0x05, 0x05, 0x8f, 0x30, 0x00, 0x00, 0x00, 0x46, 0x00, 0x03, 0x00, 0x70, 0x00, 0x0a, 0x00, 0x0a, 0x00, 0x46, 0x00, 0x03, 0x00, 0x70, 0x00, 0x0a, 0x00, 0x0a), PHYREGS(0x03d3, 0x03cf, 0x03cb, 0x042f, 0x0434, 0x0438), }, { .freq = 2442, RADIOREGS3(0x00, 0x01, 0x03, 0x09, 0x8a, 0x08, 0x08, 0x04, 0x16, 0x01, 0x05, 0x05, 0x05, 0x8f, 0x30, 0x00, 0x00, 0x00, 0x45, 0x00, 0x02, 0x00, 0x70, 0x00, 0x0a, 0x00, 0x0a, 0x00, 0x45, 0x00, 0x02, 0x00, 0x70, 0x00, 0x0a, 0x00, 0x0a), PHYREGS(0x03d5, 0x03d1, 0x03cd, 0x042d, 0x0431, 0x0436), }, { .freq = 2447, RADIOREGS3(0x00, 0x01, 0x03, 0x09, 0x8f, 0x08, 0x08, 0x04, 0x16, 0x01, 0x06, 0x06, 0x06, 0x8f, 0x30, 0x00, 0x00, 0x00, 0x34, 0x00, 0x02, 0x00, 0x70, 0x00, 0x0a, 0x00, 0x09, 0x00, 0x34, 0x00, 0x02, 0x00, 0x70, 0x00, 0x0a, 0x00, 0x09), PHYREGS(0x03d7, 0x03d3, 0x03cf, 0x042b, 0x042f, 0x0434), }, { .freq = 2452, RADIOREGS3(0x00, 0x01, 0x03, 0x09, 0x94, 0x08, 0x08, 0x04, 0x16, 0x01, 0x06, 0x06, 0x06, 0x8f, 0x30, 0x00, 0x00, 0x00, 0x23, 0x00, 0x02, 0x00, 0x70, 0x00, 0x0a, 0x00, 0x09, 0x00, 0x23, 0x00, 0x02, 0x00, 0x70, 0x00, 0x0a, 0x00, 0x09), PHYREGS(0x03d9, 0x03d5, 0x03d1, 0x0429, 0x042d, 0x0431), }, { .freq = 2457, RADIOREGS3(0x00, 0x01, 0x03, 0x09, 0x99, 0x08, 0x08, 0x04, 0x16, 0x01, 0x06, 0x06, 0x06, 0x8f, 0x30, 0x00, 0x00, 0x00, 0x12, 0x00, 0x02, 0x00, 0x70, 0x00, 0x0a, 0x00, 0x09, 0x00, 0x12, 0x00, 0x02, 0x00, 0x70, 0x00, 0x0a, 0x00, 0x09), PHYREGS(0x03db, 0x03d7, 0x03d3, 0x0427, 0x042b, 0x042f), }, { .freq = 2462, RADIOREGS3(0x00, 0x01, 0x03, 0x09, 0x9e, 0x08, 0x08, 0x04, 0x16, 0x01, 0x06, 0x06, 0x06, 0x8f, 0x30, 0x00, 0x00, 0x00, 0x02, 0x00, 0x02, 0x00, 0x70, 0x00, 0x09, 0x00, 0x09, 0x00, 0x02, 0x00, 0x02, 0x00, 0x70, 0x00, 0x09, 0x00, 0x09), PHYREGS(0x03dd, 0x03d9, 0x03d5, 0x0424, 0x0429, 0x042d), }, { .freq = 2467, RADIOREGS3(0x00, 0x01, 0x03, 0x09, 0xa3, 0x08, 0x08, 0x04, 0x16, 0x01, 0x06, 0x06, 0x06, 0x8f, 0x30, 0x00, 0x00, 0x00, 0x01, 0x00, 0x02, 0x00, 0x70, 0x00, 0x09, 0x00, 0x09, 0x00, 0x01, 0x00, 0x02, 0x00, 0x70, 0x00, 0x09, 0x00, 0x09), PHYREGS(0x03df, 0x03db, 0x03d7, 0x0422, 0x0427, 0x042b), }, { .freq = 2472, RADIOREGS3(0x00, 0x01, 0x03, 0x09, 0xa8, 0x08, 0x08, 0x04, 0x16, 0x01, 0x07, 0x07, 0x07, 0x8f, 0x30, 0x00, 0x00, 0x00, 0x01, 0x00, 0x02, 0x00, 0x70, 0x00, 0x09, 0x00, 0x09, 0x00, 0x01, 0x00, 0x02, 0x00, 0x70, 0x00, 0x09, 0x00, 0x09), PHYREGS(0x03e1, 0x03dd, 0x03d9, 0x0420, 0x0424, 0x0429), }, { .freq = 2484, RADIOREGS3(0xff, 0x01, 0x03, 0x09, 0xb4, 0x08, 0x08, 0x04, 0x16, 0x01, 0x07, 0x07, 0x07, 0x8f, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x70, 0x00, 0x09, 0x00, 0x09, 0x00, 0x00, 0x00, 0x02, 0x00, 0x70, 0x00, 0x09, 0x00, 0x09), PHYREGS(0x03e6, 0x03e2, 0x03de, 0x041b, 0x041f, 0x0424), }, }; static const struct b43_nphy_channeltab_entry_rev3 b43_nphy_channeltab_radio_rev7_9[] = { { .freq = 4920, RADIOREGS3(0xff, 0x01, 0x01, 0x01, 0xec, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x00, 0x00, 0x00, 0x8f, 0x0f, 0x00, 0xff, 0xff, 0x00, 0x0b, 0x00, 0x70, 0x00, 0x0f, 0x00, 0x9f, 0x00, 0xff, 0x00, 0x0b, 0x00, 0x70, 0x00, 0x0f, 0x00, 0x6f, 0x00), PHYREGS(0x07b4, 0x07b0, 0x07ac, 0x0214, 0x0215, 0x0216), }, { .freq = 4930, RADIOREGS3(0xff, 0x01, 0x01, 0x01, 0xed, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x00, 0x00, 0x00, 0x8f, 0x0f, 0x00, 0xff, 0xff, 0x00, 0x0b, 0x00, 0x70, 0x00, 0x0e, 0x00, 0x9f, 0x00, 0xff, 0x00, 0x0b, 0x00, 0x70, 0x00, 0x0e, 0x00, 0x6f, 0x00), PHYREGS(0x07b8, 0x07b4, 0x07b0, 0x0213, 0x0214, 0x0215), }, { .freq = 4940, RADIOREGS3(0xff, 0x01, 0x01, 0x01, 0xee, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x00, 0x00, 0x00, 0x8f, 0x0f, 0x00, 0xff, 0xff, 0x00, 0x0b, 0x00, 0x70, 0x00, 0x0e, 0x00, 0x9f, 0x00, 0xff, 0x00, 0x0b, 0x00, 0x70, 0x00, 0x0e, 0x00, 0x6f, 0x00), PHYREGS(0x07bc, 0x07b8, 0x07b4, 0x0212, 0x0213, 0x0214), }, { .freq = 4950, RADIOREGS3(0xff, 0x01, 0x01, 0x01, 0xef, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x00, 0x00, 0x00, 0x8f, 0x0f, 0x00, 0xff, 0xff, 0x00, 0x0b, 0x00, 0x70, 0x00, 0x0e, 0x00, 0x9f, 0x00, 0xff, 0x00, 0x0b, 0x00, 0x70, 0x00, 0x0e, 0x00, 0x6f, 0x00), PHYREGS(0x07c0, 0x07bc, 0x07b8, 0x0211, 0x0212, 0x0213), }, { .freq = 4960, RADIOREGS3(0xff, 0x01, 0x01, 0x01, 0xf0, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x01, 0x01, 0x01, 0x8f, 0x0f, 0x00, 0xff, 0xff, 0x00, 0x0a, 0x00, 0x70, 0x00, 0x0e, 0x00, 0x9f, 0x00, 0xff, 0x00, 0x0a, 0x00, 0x70, 0x00, 0x0e, 0x00, 0x6f, 0x00), PHYREGS(0x07c4, 0x07c0, 0x07bc, 0x020f, 0x0211, 0x0212), }, { .freq = 4970, RADIOREGS3(0xff, 0x01, 0x01, 0x01, 0xf1, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x01, 0x01, 0x01, 0x8f, 0x0f, 0x00, 0xff, 0xff, 0x00, 0x0a, 0x00, 0x70, 0x00, 0x0d, 0x00, 0x9f, 0x00, 0xff, 0x00, 0x0a, 0x00, 0x70, 0x00, 0x0d, 0x00, 0x6f, 0x00), PHYREGS(0x07c8, 0x07c4, 0x07c0, 0x020e, 0x020f, 0x0211), }, { .freq = 4980, RADIOREGS3(0xff, 0x01, 0x01, 0x01, 0xf2, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x01, 0x01, 0x01, 0x8f, 0x0f, 0x00, 0xff, 0xff, 0x00, 0x0a, 0x00, 0x70, 0x00, 0x0d, 0x00, 0x9f, 0x00, 0xff, 0x00, 0x0a, 0x00, 0x70, 0x00, 0x0d, 0x00, 0x6f, 0x00), PHYREGS(0x07cc, 0x07c8, 0x07c4, 0x020d, 0x020e, 0x020f), }, { .freq = 4990, RADIOREGS3(0xff, 0x01, 0x01, 0x01, 0xf3, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x01, 0x01, 0x01, 0x8f, 0x0f, 0x00, 0xff, 0xff, 0x00, 0x0a, 0x00, 0x70, 0x00, 0x0d, 0x00, 0x9f, 0x00, 0xff, 0x00, 0x0a, 0x00, 0x70, 0x00, 0x0d, 0x00, 0x6f, 0x00), PHYREGS(0x07d0, 0x07cc, 0x07c8, 0x020c, 0x020d, 0x020e), }, { .freq = 5000, RADIOREGS3(0xff, 0x01, 0x01, 0x01, 0xf4, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x01, 0x01, 0x01, 0x8f, 0x0f, 0x00, 0xff, 0xff, 0x00, 0x0a, 0x00, 0x70, 0x00, 0x0d, 0x00, 0x9f, 0x00, 0xff, 0x00, 0x0a, 0x00, 0x70, 0x00, 0x0d, 0x00, 0x6f, 0x00), PHYREGS(0x07d4, 0x07d0, 0x07cc, 0x020b, 0x020c, 0x020d), }, { .freq = 5010, RADIOREGS3(0xff, 0x01, 0x01, 0x01, 0xf5, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x01, 0x01, 0x01, 0x8f, 0x0f, 0x00, 0xff, 0xff, 0x00, 0x0a, 0x00, 0x70, 0x00, 0x0d, 0x00, 0x9f, 0x00, 0xff, 0x00, 0x0a, 0x00, 0x70, 0x00, 0x0d, 0x00, 0x6f, 0x00), PHYREGS(0x07d8, 0x07d4, 0x07d0, 0x020a, 0x020b, 0x020c), }, { .freq = 5020, RADIOREGS3(0xf7, 0x01, 0x01, 0x01, 0xf6, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x01, 0x01, 0x01, 0x8f, 0x0f, 0x00, 0xff, 0xff, 0x00, 0x09, 0x00, 0x70, 0x00, 0x0d, 0x00, 0x9f, 0x00, 0xff, 0x00, 0x09, 0x00, 0x70, 0x00, 0x0d, 0x00, 0x6f, 0x00), PHYREGS(0x07dc, 0x07d8, 0x07d4, 0x0209, 0x020a, 0x020b), }, { .freq = 5030, RADIOREGS3(0xf7, 0x01, 0x01, 0x01, 0xf7, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x01, 0x01, 0x01, 0x8f, 0x0f, 0x00, 0xff, 0xff, 0x00, 0x09, 0x00, 0x70, 0x00, 0x0c, 0x00, 0x9f, 0x00, 0xff, 0x00, 0x09, 0x00, 0x70, 0x00, 0x0c, 0x00, 0x6f, 0x00), PHYREGS(0x07e0, 0x07dc, 0x07d8, 0x0208, 0x0209, 0x020a), }, { .freq = 5040, RADIOREGS3(0xef, 0x01, 0x01, 0x01, 0xf8, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x01, 0x01, 0x01, 0x8f, 0x0f, 0x00, 0xff, 0xfe, 0x00, 0x09, 0x00, 0x70, 0x00, 0x0c, 0x00, 0x9f, 0x00, 0xfe, 0x00, 0x09, 0x00, 0x70, 0x00, 0x0c, 0x00, 0x6f, 0x00), PHYREGS(0x07e4, 0x07e0, 0x07dc, 0x0207, 0x0208, 0x0209), }, { .freq = 5050, RADIOREGS3(0xef, 0x01, 0x01, 0x01, 0xf9, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x01, 0x01, 0x01, 0x8f, 0x0f, 0x00, 0xff, 0xfe, 0x00, 0x09, 0x00, 0x70, 0x00, 0x0c, 0x00, 0x9f, 0x00, 0xfe, 0x00, 0x09, 0x00, 0x70, 0x00, 0x0c, 0x00, 0x6f, 0x00), PHYREGS(0x07e8, 0x07e4, 0x07e0, 0x0206, 0x0207, 0x0208), }, { .freq = 5060, RADIOREGS3(0xe6, 0x01, 0x01, 0x01, 0xfa, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x01, 0x01, 0x01, 0x8f, 0x0f, 0x00, 0xff, 0xfd, 0x00, 0x09, 0x00, 0x70, 0x00, 0x0c, 0x00, 0x9f, 0x00, 0xfd, 0x00, 0x09, 0x00, 0x70, 0x00, 0x0c, 0x00, 0x6f, 0x00), PHYREGS(0x07ec, 0x07e8, 0x07e4, 0x0205, 0x0206, 0x0207), }, { .freq = 5070, RADIOREGS3(0xe6, 0x01, 0x01, 0x01, 0xfb, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x01, 0x01, 0x01, 0x8f, 0x0f, 0x00, 0xff, 0xfd, 0x00, 0x08, 0x00, 0x70, 0x00, 0x0b, 0x00, 0x9f, 0x00, 0xfd, 0x00, 0x08, 0x00, 0x70, 0x00, 0x0b, 0x00, 0x6f, 0x00), PHYREGS(0x07f0, 0x07ec, 0x07e8, 0x0204, 0x0205, 0x0206), }, { .freq = 5080, RADIOREGS3(0xde, 0x01, 0x01, 0x01, 0xfc, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x01, 0x01, 0x01, 0x8f, 0x0f, 0x00, 0xff, 0xfc, 0x00, 0x08, 0x00, 0x70, 0x00, 0x0b, 0x00, 0x9f, 0x00, 0xfc, 0x00, 0x08, 0x00, 0x70, 0x00, 0x0b, 0x00, 0x6f, 0x00), PHYREGS(0x07f4, 0x07f0, 0x07ec, 0x0203, 0x0204, 0x0205), }, { .freq = 5090, RADIOREGS3(0xde, 0x01, 0x01, 0x01, 0xfd, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x01, 0x01, 0x01, 0x8f, 0x0f, 0x00, 0xff, 0xfc, 0x00, 0x08, 0x00, 0x70, 0x00, 0x0b, 0x00, 0x9f, 0x00, 0xfc, 0x00, 0x08, 0x00, 0x70, 0x00, 0x0b, 0x00, 0x6f, 0x00), PHYREGS(0x07f8, 0x07f4, 0x07f0, 0x0202, 0x0203, 0x0204), }, { .freq = 5100, RADIOREGS3(0xd6, 0x01, 0x01, 0x01, 0xfe, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x02, 0x02, 0x02, 0x8f, 0x0f, 0x00, 0xff, 0xfc, 0x00, 0x08, 0x00, 0x70, 0x00, 0x0b, 0x00, 0x9f, 0x00, 0xfc, 0x00, 0x08, 0x00, 0x70, 0x00, 0x0b, 0x00, 0x6f, 0x00), PHYREGS(0x07fc, 0x07f8, 0x07f4, 0x0201, 0x0202, 0x0203), }, { .freq = 5110, RADIOREGS3(0xd6, 0x01, 0x01, 0x01, 0xff, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x02, 0x02, 0x02, 0x8f, 0x0f, 0x00, 0xff, 0xfc, 0x00, 0x08, 0x00, 0x70, 0x00, 0x0b, 0x00, 0x9f, 0x00, 0xfc, 0x00, 0x08, 0x00, 0x70, 0x00, 0x0b, 0x00, 0x6f, 0x00), PHYREGS(0x0800, 0x07fc, 0x07f8, 0x0200, 0x0201, 0x0202), }, { .freq = 5120, RADIOREGS3(0xce, 0x01, 0x01, 0x02, 0x00, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x02, 0x02, 0x02, 0x8f, 0x0f, 0x00, 0xff, 0xfc, 0x00, 0x08, 0x00, 0x70, 0x00, 0x0b, 0x00, 0x9f, 0x00, 0xfc, 0x00, 0x08, 0x00, 0x70, 0x00, 0x0b, 0x00, 0x6f, 0x00), PHYREGS(0x0804, 0x0800, 0x07fc, 0x01ff, 0x0200, 0x0201), }, { .freq = 5130, RADIOREGS3(0xce, 0x01, 0x01, 0x02, 0x01, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x02, 0x02, 0x02, 0x8f, 0x0f, 0x00, 0xff, 0xfb, 0x00, 0x08, 0x00, 0x70, 0x00, 0x0a, 0x00, 0x9f, 0x00, 0xfb, 0x00, 0x08, 0x00, 0x70, 0x00, 0x0a, 0x00, 0x6f, 0x00), PHYREGS(0x0808, 0x0804, 0x0800, 0x01fe, 0x01ff, 0x0200), }, { .freq = 5140, RADIOREGS3(0xc6, 0x01, 0x01, 0x02, 0x02, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x02, 0x02, 0x02, 0x8f, 0x0f, 0x00, 0xff, 0xfb, 0x00, 0x07, 0x00, 0x70, 0x00, 0x0a, 0x00, 0x9f, 0x00, 0xfb, 0x00, 0x07, 0x00, 0x70, 0x00, 0x0a, 0x00, 0x6f, 0x00), PHYREGS(0x080c, 0x0808, 0x0804, 0x01fd, 0x01fe, 0x01ff), }, { .freq = 5160, RADIOREGS3(0xbe, 0x01, 0x01, 0x02, 0x04, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x02, 0x02, 0x02, 0x8f, 0x0f, 0x00, 0xff, 0xfb, 0x00, 0x07, 0x00, 0x70, 0x00, 0x09, 0x00, 0x9e, 0x00, 0xfb, 0x00, 0x07, 0x00, 0x70, 0x00, 0x09, 0x00, 0x6e, 0x00), PHYREGS(0x0814, 0x0810, 0x080c, 0x01fb, 0x01fc, 0x01fd), }, { .freq = 5170, RADIOREGS3(0xbe, 0x01, 0x01, 0x02, 0x05, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x02, 0x02, 0x02, 0x8f, 0x0f, 0x00, 0xff, 0xfb, 0x00, 0x06, 0x00, 0x70, 0x00, 0x09, 0x00, 0x9e, 0x00, 0xfb, 0x00, 0x06, 0x00, 0x70, 0x00, 0x09, 0x00, 0x6e, 0x00), PHYREGS(0x0818, 0x0814, 0x0810, 0x01fa, 0x01fb, 0x01fc), }, { .freq = 5180, RADIOREGS3(0xb6, 0x01, 0x01, 0x02, 0x06, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x02, 0x02, 0x02, 0x8f, 0x0f, 0x00, 0xff, 0xfa, 0x00, 0x06, 0x00, 0x70, 0x00, 0x09, 0x00, 0x9e, 0x00, 0xfa, 0x00, 0x06, 0x00, 0x70, 0x00, 0x09, 0x00, 0x6e, 0x00), PHYREGS(0x081c, 0x0818, 0x0814, 0x01f9, 0x01fa, 0x01fb), }, { .freq = 5190, RADIOREGS3(0xb6, 0x01, 0x01, 0x02, 0x07, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x02, 0x02, 0x02, 0x8f, 0x0f, 0x00, 0xff, 0xfa, 0x00, 0x06, 0x00, 0x70, 0x00, 0x09, 0x00, 0x9e, 0x00, 0xfa, 0x00, 0x06, 0x00, 0x70, 0x00, 0x09, 0x00, 0x6e, 0x00), PHYREGS(0x0820, 0x081c, 0x0818, 0x01f8, 0x01f9, 0x01fa), }, { .freq = 5200, RADIOREGS3(0xaf, 0x01, 0x01, 0x02, 0x08, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x02, 0x02, 0x02, 0x8f, 0x0f, 0x00, 0xff, 0xfa, 0x00, 0x06, 0x00, 0x70, 0x00, 0x09, 0x00, 0x9e, 0x00, 0xfa, 0x00, 0x06, 0x00, 0x70, 0x00, 0x09, 0x00, 0x6e, 0x00), PHYREGS(0x0824, 0x0820, 0x081c, 0x01f7, 0x01f8, 0x01f9), }, { .freq = 5210, RADIOREGS3(0xaf, 0x01, 0x01, 0x02, 0x09, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x02, 0x02, 0x02, 0x8f, 0x0f, 0x00, 0xff, 0xfa, 0x00, 0x06, 0x00, 0x70, 0x00, 0x09, 0x00, 0x9e, 0x00, 0xfa, 0x00, 0x06, 0x00, 0x70, 0x00, 0x09, 0x00, 0x6e, 0x00), PHYREGS(0x0828, 0x0824, 0x0820, 0x01f6, 0x01f7, 0x01f8), }, { .freq = 5220, RADIOREGS3(0xa7, 0x01, 0x01, 0x02, 0x0a, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x02, 0x02, 0x02, 0x8e, 0x0f, 0x00, 0xfe, 0xfa, 0x00, 0x06, 0x00, 0x70, 0x00, 0x09, 0x00, 0x9e, 0x00, 0xfa, 0x00, 0x06, 0x00, 0x70, 0x00, 0x09, 0x00, 0x6e, 0x00), PHYREGS(0x082c, 0x0828, 0x0824, 0x01f5, 0x01f6, 0x01f7), }, { .freq = 5230, RADIOREGS3(0xa7, 0x01, 0x01, 0x02, 0x0b, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x02, 0x02, 0x02, 0x8e, 0x0f, 0x00, 0xee, 0xea, 0x00, 0x06, 0x00, 0x70, 0x00, 0x08, 0x00, 0x9e, 0x00, 0xea, 0x00, 0x06, 0x00, 0x70, 0x00, 0x08, 0x00, 0x6e, 0x00), PHYREGS(0x0830, 0x082c, 0x0828, 0x01f4, 0x01f5, 0x01f6), }, { .freq = 5240, RADIOREGS3(0xa0, 0x01, 0x01, 0x02, 0x0c, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x02, 0x02, 0x02, 0x8e, 0x0f, 0x00, 0xee, 0xe9, 0x00, 0x05, 0x00, 0x70, 0x00, 0x08, 0x00, 0x9d, 0x00, 0xe9, 0x00, 0x05, 0x00, 0x70, 0x00, 0x08, 0x00, 0x6d, 0x00), PHYREGS(0x0834, 0x0830, 0x082c, 0x01f3, 0x01f4, 0x01f5), }, { .freq = 5250, RADIOREGS3(0xa0, 0x01, 0x01, 0x02, 0x0d, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x02, 0x02, 0x02, 0x8e, 0x0f, 0x00, 0xed, 0xe9, 0x00, 0x05, 0x00, 0x70, 0x00, 0x08, 0x00, 0x9d, 0x00, 0xe9, 0x00, 0x05, 0x00, 0x70, 0x00, 0x08, 0x00, 0x6d, 0x00), PHYREGS(0x0838, 0x0834, 0x0830, 0x01f2, 0x01f3, 0x01f4), }, { .freq = 5260, RADIOREGS3(0x98, 0x01, 0x01, 0x02, 0x0e, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x02, 0x02, 0x02, 0x8e, 0x0e, 0x00, 0xed, 0xd9, 0x00, 0x05, 0x00, 0x70, 0x00, 0x08, 0x00, 0x9d, 0x00, 0xd9, 0x00, 0x05, 0x00, 0x70, 0x00, 0x08, 0x00, 0x6d, 0x00), PHYREGS(0x083c, 0x0838, 0x0834, 0x01f1, 0x01f2, 0x01f3), }, { .freq = 5270, RADIOREGS3(0x98, 0x01, 0x01, 0x02, 0x0f, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x03, 0x03, 0x03, 0x8e, 0x0e, 0x00, 0xed, 0xd8, 0x00, 0x04, 0x00, 0x70, 0x00, 0x07, 0x00, 0x9c, 0x00, 0xd8, 0x00, 0x04, 0x00, 0x70, 0x00, 0x07, 0x00, 0x6c, 0x00), PHYREGS(0x0840, 0x083c, 0x0838, 0x01f0, 0x01f1, 0x01f2), }, { .freq = 5280, RADIOREGS3(0x91, 0x01, 0x01, 0x02, 0x10, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x03, 0x03, 0x03, 0x8d, 0x0e, 0x00, 0xdc, 0xc8, 0x00, 0x04, 0x00, 0x70, 0x00, 0x07, 0x00, 0x9c, 0x00, 0xc8, 0x00, 0x04, 0x00, 0x70, 0x00, 0x07, 0x00, 0x6c, 0x00), PHYREGS(0x0844, 0x0840, 0x083c, 0x01f0, 0x01f0, 0x01f1), }, { .freq = 5290, RADIOREGS3(0x91, 0x01, 0x01, 0x02, 0x11, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x03, 0x03, 0x03, 0x8d, 0x0e, 0x00, 0xdc, 0xc8, 0x00, 0x04, 0x00, 0x70, 0x00, 0x07, 0x00, 0x9c, 0x00, 0xc8, 0x00, 0x04, 0x00, 0x70, 0x00, 0x07, 0x00, 0x6c, 0x00), PHYREGS(0x0848, 0x0844, 0x0840, 0x01ef, 0x01f0, 0x01f0), }, { .freq = 5300, RADIOREGS3(0x8a, 0x01, 0x01, 0x02, 0x12, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x03, 0x03, 0x03, 0x8d, 0x0e, 0x00, 0xdc, 0xc8, 0x00, 0x04, 0x00, 0x70, 0x00, 0x07, 0x00, 0x9c, 0x00, 0xc8, 0x00, 0x04, 0x00, 0x70, 0x00, 0x07, 0x00, 0x6c, 0x00), PHYREGS(0x084c, 0x0848, 0x0844, 0x01ee, 0x01ef, 0x01f0), }, { .freq = 5310, RADIOREGS3(0x8a, 0x01, 0x01, 0x02, 0x13, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x03, 0x03, 0x03, 0x8d, 0x0e, 0x00, 0xdc, 0xc8, 0x00, 0x04, 0x00, 0x70, 0x00, 0x07, 0x00, 0x9c, 0x00, 0xc8, 0x00, 0x04, 0x00, 0x70, 0x00, 0x07, 0x00, 0x6c, 0x00), PHYREGS(0x0850, 0x084c, 0x0848, 0x01ed, 0x01ee, 0x01ef), }, { .freq = 5320, RADIOREGS3(0x83, 0x01, 0x01, 0x02, 0x14, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x03, 0x03, 0x03, 0x8d, 0x0e, 0x00, 0xdb, 0xb8, 0x00, 0x04, 0x00, 0x70, 0x00, 0x07, 0x00, 0x9c, 0x00, 0xb8, 0x00, 0x04, 0x00, 0x70, 0x00, 0x07, 0x00, 0x6c, 0x00), PHYREGS(0x0854, 0x0850, 0x084c, 0x01ec, 0x01ed, 0x01ee), }, { .freq = 5330, RADIOREGS3(0x83, 0x01, 0x01, 0x02, 0x15, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x03, 0x03, 0x03, 0x8d, 0x0d, 0x00, 0xcb, 0xb7, 0x00, 0x04, 0x00, 0x70, 0x00, 0x07, 0x00, 0x9b, 0x00, 0xb7, 0x00, 0x04, 0x00, 0x70, 0x00, 0x07, 0x00, 0x6b, 0x00), PHYREGS(0x0858, 0x0854, 0x0850, 0x01eb, 0x01ec, 0x01ed), }, { .freq = 5340, RADIOREGS3(0x7c, 0x01, 0x01, 0x02, 0x16, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x03, 0x03, 0x03, 0x8d, 0x0d, 0x00, 0xca, 0xb7, 0x00, 0x03, 0x00, 0x70, 0x00, 0x07, 0x00, 0x9b, 0x00, 0xb7, 0x00, 0x03, 0x00, 0x70, 0x00, 0x07, 0x00, 0x6b, 0x00), PHYREGS(0x085c, 0x0858, 0x0854, 0x01ea, 0x01eb, 0x01ec), }, { .freq = 5350, RADIOREGS3(0x7c, 0x01, 0x01, 0x02, 0x17, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x03, 0x03, 0x03, 0x8c, 0x0d, 0x00, 0xca, 0xa7, 0x00, 0x03, 0x00, 0x70, 0x00, 0x06, 0x00, 0x9b, 0x00, 0xa7, 0x00, 0x03, 0x00, 0x70, 0x00, 0x06, 0x00, 0x6b, 0x00), PHYREGS(0x0860, 0x085c, 0x0858, 0x01e9, 0x01ea, 0x01eb), }, { .freq = 5360, RADIOREGS3(0x75, 0x01, 0x01, 0x02, 0x18, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x03, 0x03, 0x03, 0x8c, 0x0d, 0x00, 0xc9, 0xa6, 0x00, 0x03, 0x00, 0x70, 0x00, 0x06, 0x00, 0x9b, 0x00, 0xa6, 0x00, 0x03, 0x00, 0x70, 0x00, 0x06, 0x00, 0x6b, 0x00), PHYREGS(0x0864, 0x0860, 0x085c, 0x01e8, 0x01e9, 0x01ea), }, { .freq = 5370, RADIOREGS3(0x75, 0x01, 0x01, 0x02, 0x19, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x03, 0x03, 0x03, 0x8c, 0x0d, 0x00, 0xc9, 0xa6, 0x00, 0x03, 0x00, 0x70, 0x00, 0x06, 0x00, 0x9b, 0x00, 0xa6, 0x00, 0x03, 0x00, 0x70, 0x00, 0x06, 0x00, 0x7b, 0x00), PHYREGS(0x0868, 0x0864, 0x0860, 0x01e7, 0x01e8, 0x01e9), }, { .freq = 5380, RADIOREGS3(0x6e, 0x01, 0x01, 0x02, 0x1a, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x03, 0x03, 0x03, 0x8c, 0x0c, 0x00, 0xb8, 0x96, 0x00, 0x03, 0x00, 0x70, 0x00, 0x06, 0x00, 0x9a, 0x00, 0x96, 0x00, 0x03, 0x00, 0x70, 0x00, 0x06, 0x00, 0x7a, 0x00), PHYREGS(0x086c, 0x0868, 0x0864, 0x01e6, 0x01e7, 0x01e8), }, { .freq = 5390, RADIOREGS3(0x6e, 0x01, 0x01, 0x02, 0x1b, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x03, 0x03, 0x03, 0x8c, 0x0c, 0x00, 0xb8, 0x95, 0x00, 0x03, 0x00, 0x70, 0x00, 0x06, 0x00, 0x9a, 0x00, 0x95, 0x00, 0x03, 0x00, 0x70, 0x00, 0x06, 0x00, 0x7a, 0x00), PHYREGS(0x0870, 0x086c, 0x0868, 0x01e5, 0x01e6, 0x01e7), }, { .freq = 5400, RADIOREGS3(0x67, 0x01, 0x01, 0x02, 0x1c, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x03, 0x03, 0x03, 0x8c, 0x0c, 0x00, 0xb8, 0x95, 0x00, 0x03, 0x00, 0x70, 0x00, 0x06, 0x00, 0x9a, 0x00, 0x95, 0x00, 0x03, 0x00, 0x70, 0x00, 0x06, 0x00, 0x7a, 0x00), PHYREGS(0x0874, 0x0870, 0x086c, 0x01e5, 0x01e5, 0x01e6), }, { .freq = 5410, RADIOREGS3(0x67, 0x01, 0x01, 0x02, 0x1d, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x03, 0x03, 0x03, 0x8c, 0x0c, 0x00, 0xb7, 0x95, 0x00, 0x03, 0x00, 0x70, 0x00, 0x05, 0x00, 0x9a, 0x00, 0x95, 0x00, 0x03, 0x00, 0x70, 0x00, 0x05, 0x00, 0x7a, 0x00), PHYREGS(0x0878, 0x0874, 0x0870, 0x01e4, 0x01e5, 0x01e5), }, { .freq = 5420, RADIOREGS3(0x61, 0x01, 0x01, 0x02, 0x1e, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x03, 0x03, 0x03, 0x8c, 0x0c, 0x00, 0xa7, 0x95, 0x00, 0x03, 0x00, 0x70, 0x00, 0x05, 0x00, 0x9a, 0x00, 0x95, 0x00, 0x03, 0x00, 0x70, 0x00, 0x05, 0x00, 0x7a, 0x00), PHYREGS(0x087c, 0x0878, 0x0874, 0x01e3, 0x01e4, 0x01e5), }, { .freq = 5430, RADIOREGS3(0x61, 0x01, 0x01, 0x02, 0x1f, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x03, 0x03, 0x03, 0x8c, 0x0b, 0x00, 0xa6, 0x85, 0x00, 0x02, 0x00, 0x70, 0x00, 0x05, 0x00, 0x99, 0x00, 0x85, 0x00, 0x02, 0x00, 0x70, 0x00, 0x05, 0x00, 0x79, 0x00), PHYREGS(0x0880, 0x087c, 0x0878, 0x01e2, 0x01e3, 0x01e4), }, { .freq = 5440, RADIOREGS3(0x5a, 0x01, 0x01, 0x02, 0x20, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x04, 0x04, 0x04, 0x8b, 0x0b, 0x00, 0xa6, 0x84, 0x00, 0x02, 0x00, 0x70, 0x00, 0x05, 0x00, 0x99, 0x00, 0x84, 0x00, 0x02, 0x00, 0x70, 0x00, 0x05, 0x00, 0x79, 0x00), PHYREGS(0x0884, 0x0880, 0x087c, 0x01e1, 0x01e2, 0x01e3), }, { .freq = 5450, RADIOREGS3(0x5a, 0x01, 0x01, 0x02, 0x21, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x04, 0x04, 0x04, 0x8b, 0x0b, 0x00, 0x95, 0x84, 0x00, 0x02, 0x00, 0x70, 0x00, 0x05, 0x00, 0x99, 0x00, 0x84, 0x00, 0x02, 0x00, 0x70, 0x00, 0x05, 0x00, 0x79, 0x00), PHYREGS(0x0888, 0x0884, 0x0880, 0x01e0, 0x01e1, 0x01e2), }, { .freq = 5460, RADIOREGS3(0x53, 0x01, 0x01, 0x02, 0x22, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x04, 0x04, 0x04, 0x8b, 0x0b, 0x00, 0x95, 0x84, 0x00, 0x02, 0x00, 0x70, 0x00, 0x04, 0x00, 0x99, 0x00, 0x84, 0x00, 0x02, 0x00, 0x70, 0x00, 0x04, 0x00, 0x79, 0x00), PHYREGS(0x088c, 0x0888, 0x0884, 0x01df, 0x01e0, 0x01e1), }, { .freq = 5470, RADIOREGS3(0x53, 0x01, 0x01, 0x02, 0x23, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x04, 0x04, 0x04, 0x8b, 0x0b, 0x00, 0x94, 0x74, 0x00, 0x01, 0x00, 0x70, 0x00, 0x04, 0x00, 0x99, 0x00, 0x74, 0x00, 0x01, 0x00, 0x70, 0x00, 0x04, 0x00, 0x79, 0x00), PHYREGS(0x0890, 0x088c, 0x0888, 0x01de, 0x01df, 0x01e0), }, { .freq = 5480, RADIOREGS3(0x4d, 0x01, 0x01, 0x02, 0x24, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x04, 0x04, 0x04, 0x8a, 0x0a, 0x00, 0x84, 0x73, 0x00, 0x01, 0x00, 0x70, 0x00, 0x04, 0x00, 0x98, 0x00, 0x73, 0x00, 0x01, 0x00, 0x70, 0x00, 0x04, 0x00, 0x78, 0x00), PHYREGS(0x0894, 0x0890, 0x088c, 0x01dd, 0x01de, 0x01df), }, { .freq = 5490, RADIOREGS3(0x4d, 0x01, 0x01, 0x02, 0x25, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x04, 0x04, 0x04, 0x8a, 0x0a, 0x00, 0x83, 0x73, 0x00, 0x01, 0x00, 0x70, 0x00, 0x04, 0x00, 0x98, 0x00, 0x73, 0x00, 0x01, 0x00, 0x70, 0x00, 0x04, 0x00, 0x78, 0x00), PHYREGS(0x0898, 0x0894, 0x0890, 0x01dd, 0x01dd, 0x01de), }, { .freq = 5500, RADIOREGS3(0x47, 0x01, 0x01, 0x02, 0x26, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x04, 0x04, 0x04, 0x8a, 0x0a, 0x00, 0x82, 0x73, 0x00, 0x01, 0x00, 0x70, 0x00, 0x04, 0x00, 0x98, 0x00, 0x73, 0x00, 0x01, 0x00, 0x70, 0x00, 0x04, 0x00, 0x78, 0x00), PHYREGS(0x089c, 0x0898, 0x0894, 0x01dc, 0x01dd, 0x01dd), }, { .freq = 5510, RADIOREGS3(0x47, 0x01, 0x01, 0x02, 0x27, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x04, 0x04, 0x04, 0x8a, 0x0a, 0x00, 0x82, 0x73, 0x00, 0x01, 0x00, 0x70, 0x00, 0x04, 0x00, 0x98, 0x00, 0x73, 0x00, 0x01, 0x00, 0x70, 0x00, 0x04, 0x00, 0x78, 0x00), PHYREGS(0x08a0, 0x089c, 0x0898, 0x01db, 0x01dc, 0x01dd), }, { .freq = 5520, RADIOREGS3(0x40, 0x01, 0x01, 0x02, 0x28, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x04, 0x04, 0x04, 0x8a, 0x0a, 0x00, 0x72, 0x73, 0x00, 0x01, 0x00, 0x70, 0x00, 0x04, 0x00, 0x98, 0x00, 0x73, 0x00, 0x01, 0x00, 0x70, 0x00, 0x04, 0x00, 0x78, 0x00), PHYREGS(0x08a4, 0x08a0, 0x089c, 0x01da, 0x01db, 0x01dc), }, { .freq = 5530, RADIOREGS3(0x40, 0x01, 0x01, 0x02, 0x29, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x04, 0x04, 0x04, 0x8a, 0x09, 0x00, 0x72, 0x63, 0x00, 0x01, 0x00, 0x70, 0x00, 0x03, 0x00, 0x98, 0x00, 0x63, 0x00, 0x01, 0x00, 0x70, 0x00, 0x03, 0x00, 0x78, 0x00), PHYREGS(0x08a8, 0x08a4, 0x08a0, 0x01d9, 0x01da, 0x01db), }, { .freq = 5540, RADIOREGS3(0x3a, 0x01, 0x01, 0x02, 0x2a, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x04, 0x04, 0x04, 0x8a, 0x09, 0x00, 0x71, 0x62, 0x00, 0x00, 0x00, 0x70, 0x00, 0x03, 0x00, 0x97, 0x00, 0x62, 0x00, 0x00, 0x00, 0x70, 0x00, 0x03, 0x00, 0x77, 0x00), PHYREGS(0x08ac, 0x08a8, 0x08a4, 0x01d8, 0x01d9, 0x01da), }, { .freq = 5550, RADIOREGS3(0x3a, 0x01, 0x01, 0x02, 0x2b, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x04, 0x04, 0x04, 0x89, 0x09, 0x00, 0x61, 0x62, 0x00, 0x00, 0x00, 0x70, 0x00, 0x03, 0x00, 0x97, 0x00, 0x62, 0x00, 0x00, 0x00, 0x70, 0x00, 0x03, 0x00, 0x77, 0x00), PHYREGS(0x08b0, 0x08ac, 0x08a8, 0x01d7, 0x01d8, 0x01d9), }, { .freq = 5560, RADIOREGS3(0x34, 0x01, 0x01, 0x02, 0x2c, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x04, 0x04, 0x04, 0x89, 0x09, 0x00, 0x61, 0x62, 0x00, 0x00, 0x00, 0x70, 0x00, 0x03, 0x00, 0x97, 0x00, 0x62, 0x00, 0x00, 0x00, 0x70, 0x00, 0x03, 0x00, 0x77, 0x00), PHYREGS(0x08b4, 0x08b0, 0x08ac, 0x01d7, 0x01d7, 0x01d8), }, { .freq = 5570, RADIOREGS3(0x34, 0x01, 0x01, 0x02, 0x2d, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x04, 0x04, 0x04, 0x89, 0x09, 0x00, 0x61, 0x52, 0x00, 0x00, 0x00, 0x70, 0x00, 0x02, 0x00, 0x96, 0x00, 0x52, 0x00, 0x00, 0x00, 0x70, 0x00, 0x02, 0x00, 0x76, 0x00), PHYREGS(0x08b8, 0x08b4, 0x08b0, 0x01d6, 0x01d7, 0x01d7), }, { .freq = 5580, RADIOREGS3(0x2e, 0x01, 0x01, 0x02, 0x2e, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x04, 0x04, 0x04, 0x89, 0x08, 0x00, 0x60, 0x52, 0x00, 0x00, 0x00, 0x70, 0x00, 0x02, 0x00, 0x96, 0x00, 0x52, 0x00, 0x00, 0x00, 0x70, 0x00, 0x02, 0x00, 0x86, 0x00), PHYREGS(0x08bc, 0x08b8, 0x08b4, 0x01d5, 0x01d6, 0x01d7), }, { .freq = 5590, RADIOREGS3(0x2e, 0x01, 0x01, 0x02, 0x2f, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x04, 0x04, 0x04, 0x89, 0x08, 0x00, 0x50, 0x51, 0x00, 0x00, 0x00, 0x70, 0x00, 0x02, 0x00, 0x96, 0x00, 0x51, 0x00, 0x00, 0x00, 0x70, 0x00, 0x02, 0x00, 0x86, 0x00), PHYREGS(0x08c0, 0x08bc, 0x08b8, 0x01d4, 0x01d5, 0x01d6), }, { .freq = 5600, RADIOREGS3(0x28, 0x01, 0x01, 0x02, 0x30, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x05, 0x05, 0x05, 0x89, 0x08, 0x00, 0x50, 0x51, 0x00, 0x00, 0x00, 0x70, 0x00, 0x02, 0x00, 0x96, 0x00, 0x51, 0x00, 0x00, 0x00, 0x70, 0x00, 0x02, 0x00, 0x86, 0x00), PHYREGS(0x08c4, 0x08c0, 0x08bc, 0x01d3, 0x01d4, 0x01d5), }, { .freq = 5610, RADIOREGS3(0x28, 0x01, 0x01, 0x02, 0x31, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x05, 0x05, 0x05, 0x89, 0x08, 0x00, 0x50, 0x51, 0x00, 0x00, 0x00, 0x70, 0x00, 0x02, 0x00, 0x96, 0x00, 0x51, 0x00, 0x00, 0x00, 0x70, 0x00, 0x02, 0x00, 0x86, 0x00), PHYREGS(0x08c8, 0x08c4, 0x08c0, 0x01d2, 0x01d3, 0x01d4), }, { .freq = 5620, RADIOREGS3(0x21, 0x01, 0x01, 0x02, 0x32, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x05, 0x05, 0x05, 0x89, 0x08, 0x00, 0x50, 0x51, 0x00, 0x00, 0x00, 0x70, 0x00, 0x02, 0x00, 0x96, 0x00, 0x51, 0x00, 0x00, 0x00, 0x70, 0x00, 0x02, 0x00, 0x86, 0x00), PHYREGS(0x08cc, 0x08c8, 0x08c4, 0x01d2, 0x01d2, 0x01d3), }, { .freq = 5630, RADIOREGS3(0x21, 0x01, 0x01, 0x02, 0x33, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x05, 0x05, 0x05, 0x88, 0x07, 0x00, 0x50, 0x51, 0x00, 0x00, 0x00, 0x70, 0x00, 0x02, 0x00, 0x96, 0x00, 0x51, 0x00, 0x00, 0x00, 0x70, 0x00, 0x02, 0x00, 0x86, 0x00), PHYREGS(0x08d0, 0x08cc, 0x08c8, 0x01d1, 0x01d2, 0x01d2), }, { .freq = 5640, RADIOREGS3(0x1c, 0x01, 0x01, 0x02, 0x34, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x05, 0x05, 0x05, 0x88, 0x07, 0x00, 0x40, 0x51, 0x00, 0x00, 0x00, 0x70, 0x00, 0x02, 0x00, 0x95, 0x00, 0x51, 0x00, 0x00, 0x00, 0x70, 0x00, 0x02, 0x00, 0x85, 0x00), PHYREGS(0x08d4, 0x08d0, 0x08cc, 0x01d0, 0x01d1, 0x01d2), }, { .freq = 5650, RADIOREGS3(0x1c, 0x01, 0x01, 0x02, 0x35, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x05, 0x05, 0x05, 0x88, 0x07, 0x00, 0x40, 0x50, 0x00, 0x00, 0x00, 0x70, 0x00, 0x01, 0x00, 0x95, 0x00, 0x50, 0x00, 0x00, 0x00, 0x70, 0x00, 0x01, 0x00, 0x85, 0x00), PHYREGS(0x08d8, 0x08d4, 0x08d0, 0x01cf, 0x01d0, 0x01d1), }, { .freq = 5660, RADIOREGS3(0x16, 0x01, 0x01, 0x02, 0x36, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x05, 0x05, 0x05, 0x88, 0x07, 0x00, 0x40, 0x50, 0x00, 0x00, 0x00, 0x70, 0x00, 0x01, 0x00, 0x95, 0x00, 0x50, 0x00, 0x00, 0x00, 0x70, 0x00, 0x01, 0x00, 0x85, 0x00), PHYREGS(0x08dc, 0x08d8, 0x08d4, 0x01ce, 0x01cf, 0x01d0), }, { .freq = 5670, RADIOREGS3(0x16, 0x01, 0x01, 0x02, 0x37, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x05, 0x05, 0x05, 0x88, 0x07, 0x00, 0x40, 0x40, 0x00, 0x00, 0x00, 0x70, 0x00, 0x01, 0x00, 0x94, 0x00, 0x40, 0x00, 0x00, 0x00, 0x70, 0x00, 0x01, 0x00, 0x84, 0x00), PHYREGS(0x08e0, 0x08dc, 0x08d8, 0x01ce, 0x01ce, 0x01cf), }, { .freq = 5680, RADIOREGS3(0x10, 0x01, 0x01, 0x02, 0x38, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x05, 0x05, 0x05, 0x87, 0x06, 0x00, 0x30, 0x40, 0x00, 0x00, 0x00, 0x70, 0x00, 0x01, 0x00, 0x94, 0x00, 0x40, 0x00, 0x00, 0x00, 0x70, 0x00, 0x01, 0x00, 0x84, 0x00), PHYREGS(0x08e4, 0x08e0, 0x08dc, 0x01cd, 0x01ce, 0x01ce), }, { .freq = 5690, RADIOREGS3(0x10, 0x01, 0x01, 0x02, 0x39, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x05, 0x05, 0x05, 0x87, 0x06, 0x00, 0x30, 0x40, 0x00, 0x00, 0x00, 0x70, 0x00, 0x01, 0x00, 0x94, 0x00, 0x40, 0x00, 0x00, 0x00, 0x70, 0x00, 0x01, 0x00, 0x94, 0x00), PHYREGS(0x08e8, 0x08e4, 0x08e0, 0x01cc, 0x01cd, 0x01ce), }, { .freq = 5700, RADIOREGS3(0x0a, 0x01, 0x01, 0x02, 0x3a, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x05, 0x05, 0x05, 0x87, 0x06, 0x00, 0x30, 0x40, 0x00, 0x00, 0x00, 0x70, 0x00, 0x01, 0x00, 0x94, 0x00, 0x40, 0x00, 0x00, 0x00, 0x70, 0x00, 0x01, 0x00, 0x94, 0x00), PHYREGS(0x08ec, 0x08e8, 0x08e4, 0x01cb, 0x01cc, 0x01cd), }, { .freq = 5710, RADIOREGS3(0x0a, 0x01, 0x01, 0x02, 0x3b, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x05, 0x05, 0x05, 0x87, 0x06, 0x00, 0x30, 0x40, 0x00, 0x00, 0x00, 0x70, 0x00, 0x01, 0x00, 0x94, 0x00, 0x40, 0x00, 0x00, 0x00, 0x70, 0x00, 0x01, 0x00, 0x94, 0x00), PHYREGS(0x08f0, 0x08ec, 0x08e8, 0x01ca, 0x01cb, 0x01cc), }, { .freq = 5720, RADIOREGS3(0x0a, 0x01, 0x01, 0x02, 0x3c, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x05, 0x05, 0x05, 0x87, 0x06, 0x00, 0x30, 0x40, 0x00, 0x00, 0x00, 0x70, 0x00, 0x01, 0x00, 0x94, 0x00, 0x40, 0x00, 0x00, 0x00, 0x70, 0x00, 0x01, 0x00, 0x94, 0x00), PHYREGS(0x08f4, 0x08f0, 0x08ec, 0x01c9, 0x01ca, 0x01cb), }, { .freq = 5725, RADIOREGS3(0x03, 0x01, 0x02, 0x04, 0x79, 0x07, 0x07, 0x04, 0x10, 0x01, 0x05, 0x05, 0x05, 0x87, 0x06, 0x00, 0x30, 0x40, 0x00, 0x00, 0x00, 0x70, 0x00, 0x01, 0x00, 0x94, 0x00, 0x40, 0x00, 0x00, 0x00, 0x70, 0x00, 0x01, 0x00, 0x94, 0x00), PHYREGS(0x08f6, 0x08f2, 0x08ee, 0x01c9, 0x01ca, 0x01cb), }, { .freq = 5730, RADIOREGS3(0x0a, 0x01, 0x01, 0x02, 0x3d, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x05, 0x05, 0x05, 0x87, 0x05, 0x00, 0x20, 0x30, 0x00, 0x00, 0x00, 0x70, 0x00, 0x01, 0x00, 0x94, 0x00, 0x30, 0x00, 0x00, 0x00, 0x70, 0x00, 0x01, 0x00, 0x94, 0x00), PHYREGS(0x08f8, 0x08f4, 0x08f0, 0x01c9, 0x01c9, 0x01ca), }, { .freq = 5735, RADIOREGS3(0x03, 0x01, 0x02, 0x04, 0x7b, 0x07, 0x07, 0x04, 0x10, 0x01, 0x05, 0x05, 0x05, 0x87, 0x05, 0x00, 0x20, 0x30, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x93, 0x00, 0x30, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x93, 0x00), PHYREGS(0x08fa, 0x08f6, 0x08f2, 0x01c8, 0x01c9, 0x01ca), }, { .freq = 5740, RADIOREGS3(0x0a, 0x01, 0x01, 0x02, 0x3e, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x05, 0x05, 0x05, 0x87, 0x05, 0x00, 0x20, 0x30, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x93, 0x00, 0x30, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x93, 0x00), PHYREGS(0x08fc, 0x08f8, 0x08f4, 0x01c8, 0x01c9, 0x01c9), }, { .freq = 5745, RADIOREGS3(0xfe, 0x00, 0x02, 0x04, 0x7d, 0x07, 0x07, 0x04, 0x10, 0x01, 0x05, 0x05, 0x05, 0x87, 0x05, 0x00, 0x20, 0x30, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x93, 0x00, 0x30, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x93, 0x00), PHYREGS(0x08fe, 0x08fa, 0x08f6, 0x01c8, 0x01c8, 0x01c9), }, { .freq = 5750, RADIOREGS3(0x0a, 0x01, 0x01, 0x02, 0x3f, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x05, 0x05, 0x05, 0x87, 0x05, 0x00, 0x20, 0x30, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x93, 0x00, 0x30, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x93, 0x00), PHYREGS(0x0900, 0x08fc, 0x08f8, 0x01c7, 0x01c8, 0x01c9), }, { .freq = 5755, RADIOREGS3(0xfe, 0x00, 0x02, 0x04, 0x7f, 0x07, 0x07, 0x04, 0x10, 0x01, 0x05, 0x05, 0x05, 0x87, 0x05, 0x00, 0x10, 0x30, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x93, 0x00, 0x30, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x93, 0x00), PHYREGS(0x0902, 0x08fe, 0x08fa, 0x01c7, 0x01c8, 0x01c8), }, { .freq = 5760, RADIOREGS3(0x0a, 0x01, 0x01, 0x02, 0x40, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x05, 0x05, 0x05, 0x86, 0x05, 0x00, 0x10, 0x20, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x93, 0x00, 0x20, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x93, 0x00), PHYREGS(0x0904, 0x0900, 0x08fc, 0x01c6, 0x01c7, 0x01c8), }, { .freq = 5765, RADIOREGS3(0xf8, 0x00, 0x02, 0x04, 0x81, 0x07, 0x07, 0x04, 0x10, 0x01, 0x05, 0x05, 0x05, 0x86, 0x05, 0x00, 0x10, 0x20, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x92, 0x00, 0x20, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x92, 0x00), PHYREGS(0x0906, 0x0902, 0x08fe, 0x01c6, 0x01c7, 0x01c8), }, { .freq = 5770, RADIOREGS3(0x0a, 0x01, 0x01, 0x02, 0x41, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x05, 0x05, 0x05, 0x86, 0x04, 0x00, 0x10, 0x20, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x92, 0x00, 0x20, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x92, 0x00), PHYREGS(0x0908, 0x0904, 0x0900, 0x01c6, 0x01c6, 0x01c7), }, { .freq = 5775, RADIOREGS3(0xf8, 0x00, 0x02, 0x04, 0x83, 0x07, 0x07, 0x04, 0x10, 0x01, 0x05, 0x05, 0x05, 0x86, 0x04, 0x00, 0x10, 0x20, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x92, 0x00, 0x20, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x92, 0x00), PHYREGS(0x090a, 0x0906, 0x0902, 0x01c5, 0x01c6, 0x01c7), }, { .freq = 5780, RADIOREGS3(0x0a, 0x01, 0x01, 0x02, 0x42, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x05, 0x05, 0x05, 0x86, 0x04, 0x00, 0x10, 0x10, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x92, 0x00, 0x10, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x92, 0x00), PHYREGS(0x090c, 0x0908, 0x0904, 0x01c5, 0x01c6, 0x01c6), }, { .freq = 5785, RADIOREGS3(0xf2, 0x00, 0x02, 0x04, 0x85, 0x07, 0x07, 0x04, 0x10, 0x01, 0x06, 0x06, 0x06, 0x86, 0x04, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x92, 0x00, 0x10, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x92, 0x00), PHYREGS(0x090e, 0x090a, 0x0906, 0x01c4, 0x01c5, 0x01c6), }, { .freq = 5790, RADIOREGS3(0x0a, 0x01, 0x01, 0x02, 0x43, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x06, 0x06, 0x06, 0x86, 0x04, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x92, 0x00, 0x10, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x92, 0x00), PHYREGS(0x0910, 0x090c, 0x0908, 0x01c4, 0x01c5, 0x01c6), }, { .freq = 5795, RADIOREGS3(0xf2, 0x00, 0x02, 0x04, 0x87, 0x07, 0x07, 0x04, 0x10, 0x01, 0x06, 0x06, 0x06, 0x86, 0x04, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x92, 0x00, 0x10, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x92, 0x00), PHYREGS(0x0912, 0x090e, 0x090a, 0x01c4, 0x01c4, 0x01c5), }, { .freq = 5800, RADIOREGS3(0x0a, 0x01, 0x01, 0x02, 0x44, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x06, 0x06, 0x06, 0x86, 0x04, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x92, 0x00, 0x10, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x92, 0x00), PHYREGS(0x0914, 0x0910, 0x090c, 0x01c3, 0x01c4, 0x01c5), }, { .freq = 5805, RADIOREGS3(0xed, 0x00, 0x02, 0x04, 0x89, 0x07, 0x07, 0x04, 0x10, 0x01, 0x06, 0x06, 0x06, 0x86, 0x04, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x92, 0x00, 0x10, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x92, 0x00), PHYREGS(0x0916, 0x0912, 0x090e, 0x01c3, 0x01c4, 0x01c4), }, { .freq = 5810, RADIOREGS3(0x0a, 0x01, 0x01, 0x02, 0x45, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x06, 0x06, 0x06, 0x86, 0x04, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x92, 0x00, 0x10, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x92, 0x00), PHYREGS(0x0918, 0x0914, 0x0910, 0x01c2, 0x01c3, 0x01c4), }, { .freq = 5815, RADIOREGS3(0xed, 0x00, 0x02, 0x04, 0x8b, 0x07, 0x07, 0x04, 0x10, 0x01, 0x06, 0x06, 0x06, 0x86, 0x04, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x92, 0x00, 0x10, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x92, 0x00), PHYREGS(0x091a, 0x0916, 0x0912, 0x01c2, 0x01c3, 0x01c4), }, { .freq = 5820, RADIOREGS3(0x0a, 0x01, 0x01, 0x02, 0x46, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x06, 0x06, 0x06, 0x86, 0x04, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x92, 0x00, 0x10, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x92, 0x00), PHYREGS(0x091c, 0x0918, 0x0914, 0x01c2, 0x01c2, 0x01c3), }, { .freq = 5825, RADIOREGS3(0xed, 0x00, 0x02, 0x04, 0x8d, 0x07, 0x07, 0x04, 0x10, 0x01, 0x06, 0x06, 0x06, 0x86, 0x04, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x92, 0x00, 0x10, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x92, 0x00), PHYREGS(0x091e, 0x091a, 0x0916, 0x01c1, 0x01c2, 0x01c3), }, { .freq = 5830, RADIOREGS3(0x0a, 0x01, 0x01, 0x02, 0x47, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x06, 0x06, 0x06, 0x86, 0x04, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x92, 0x00, 0x10, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x92, 0x00), PHYREGS(0x0920, 0x091c, 0x0918, 0x01c1, 0x01c2, 0x01c2), }, { .freq = 5840, RADIOREGS3(0x0a, 0x01, 0x01, 0x02, 0x48, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x06, 0x06, 0x06, 0x86, 0x04, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x92, 0x00, 0x10, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x92, 0x00), PHYREGS(0x0924, 0x0920, 0x091c, 0x01c0, 0x01c1, 0x01c2), }, { .freq = 5850, RADIOREGS3(0xe0, 0x00, 0x01, 0x02, 0x49, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x06, 0x06, 0x06, 0x85, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x92, 0x00, 0x00, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x92, 0x00), PHYREGS(0x0928, 0x0924, 0x0920, 0x01bf, 0x01c0, 0x01c1), }, { .freq = 5860, RADIOREGS3(0xde, 0x00, 0x01, 0x02, 0x4a, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x06, 0x06, 0x06, 0x85, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x92, 0x00, 0x00, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x92, 0x00), PHYREGS(0x092c, 0x0928, 0x0924, 0x01bf, 0x01bf, 0x01c0), }, { .freq = 5870, RADIOREGS3(0xdb, 0x00, 0x01, 0x02, 0x4b, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x06, 0x06, 0x06, 0x85, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x91, 0x00, 0x00, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x91, 0x00), PHYREGS(0x0930, 0x092c, 0x0928, 0x01be, 0x01bf, 0x01bf), }, { .freq = 5880, RADIOREGS3(0xd8, 0x00, 0x01, 0x02, 0x4c, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x06, 0x06, 0x06, 0x85, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x91, 0x00, 0x00, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x91, 0x00), PHYREGS(0x0934, 0x0930, 0x092c, 0x01bd, 0x01be, 0x01bf), }, { .freq = 5890, RADIOREGS3(0xd6, 0x00, 0x01, 0x02, 0x4d, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x06, 0x06, 0x06, 0x85, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x91, 0x00, 0x00, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x91, 0x00), PHYREGS(0x0938, 0x0934, 0x0930, 0x01bc, 0x01bd, 0x01be), }, { .freq = 5900, RADIOREGS3(0xd3, 0x00, 0x01, 0x02, 0x4e, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x06, 0x06, 0x06, 0x85, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x91, 0x00, 0x00, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x91, 0x00), PHYREGS(0x093c, 0x0938, 0x0934, 0x01bc, 0x01bc, 0x01bd), }, { .freq = 5910, RADIOREGS3(0xd6, 0x00, 0x01, 0x02, 0x4f, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x06, 0x06, 0x06, 0x85, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x91, 0x00, 0x00, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x91, 0x00), PHYREGS(0x0940, 0x093c, 0x0938, 0x01bb, 0x01bc, 0x01bc), }, { .freq = 2412, RADIOREGS3(0x00, 0x01, 0x03, 0x09, 0x6c, 0x08, 0x08, 0x04, 0x16, 0x01, 0x04, 0x04, 0x04, 0x8f, 0x30, 0x00, 0x00, 0x00, 0x89, 0x00, 0x03, 0x00, 0x70, 0x00, 0x0f, 0x00, 0x0b, 0x00, 0x89, 0x00, 0x03, 0x00, 0x70, 0x00, 0x0f, 0x00, 0x0b), PHYREGS(0x03c9, 0x03c5, 0x03c1, 0x043a, 0x043f, 0x0443), }, { .freq = 2417, RADIOREGS3(0x00, 0x01, 0x03, 0x09, 0x71, 0x08, 0x08, 0x04, 0x16, 0x01, 0x05, 0x05, 0x05, 0x8f, 0x30, 0x00, 0x00, 0x00, 0x89, 0x00, 0x03, 0x00, 0x70, 0x00, 0x0f, 0x00, 0x0a, 0x00, 0x89, 0x00, 0x03, 0x00, 0x70, 0x00, 0x0f, 0x00, 0x0a), PHYREGS(0x03cb, 0x03c7, 0x03c3, 0x0438, 0x043d, 0x0441), }, { .freq = 2422, RADIOREGS3(0x00, 0x01, 0x03, 0x09, 0x76, 0x08, 0x08, 0x04, 0x16, 0x01, 0x05, 0x05, 0x05, 0x8f, 0x30, 0x00, 0x00, 0x00, 0x89, 0x00, 0x03, 0x00, 0x70, 0x00, 0x0f, 0x00, 0x0a, 0x00, 0x89, 0x00, 0x03, 0x00, 0x70, 0x00, 0x0f, 0x00, 0x0a), PHYREGS(0x03cd, 0x03c9, 0x03c5, 0x0436, 0x043a, 0x043f), }, { .freq = 2427, RADIOREGS3(0x00, 0x01, 0x03, 0x09, 0x7b, 0x08, 0x08, 0x04, 0x16, 0x01, 0x05, 0x05, 0x05, 0x8f, 0x30, 0x00, 0x00, 0x00, 0x78, 0x00, 0x03, 0x00, 0x70, 0x00, 0x0e, 0x00, 0x0a, 0x00, 0x78, 0x00, 0x03, 0x00, 0x70, 0x00, 0x0e, 0x00, 0x0a), PHYREGS(0x03cf, 0x03cb, 0x03c7, 0x0434, 0x0438, 0x043d), }, { .freq = 2432, RADIOREGS3(0x00, 0x01, 0x03, 0x09, 0x80, 0x08, 0x08, 0x04, 0x16, 0x01, 0x05, 0x05, 0x05, 0x8f, 0x30, 0x00, 0x00, 0x00, 0x77, 0x00, 0x03, 0x00, 0x70, 0x00, 0x0e, 0x00, 0x0a, 0x00, 0x77, 0x00, 0x03, 0x00, 0x70, 0x00, 0x0e, 0x00, 0x0a), PHYREGS(0x03d1, 0x03cd, 0x03c9, 0x0431, 0x0436, 0x043a), }, { .freq = 2437, RADIOREGS3(0x00, 0x01, 0x03, 0x09, 0x85, 0x08, 0x08, 0x04, 0x16, 0x01, 0x05, 0x05, 0x05, 0x8f, 0x30, 0x00, 0x00, 0x00, 0x76, 0x00, 0x03, 0x00, 0x70, 0x00, 0x0e, 0x00, 0x0a, 0x00, 0x76, 0x00, 0x03, 0x00, 0x70, 0x00, 0x0e, 0x00, 0x0a), PHYREGS(0x03d3, 0x03cf, 0x03cb, 0x042f, 0x0434, 0x0438), }, { .freq = 2442, RADIOREGS3(0x00, 0x01, 0x03, 0x09, 0x8a, 0x08, 0x08, 0x04, 0x16, 0x01, 0x05, 0x05, 0x05, 0x8f, 0x30, 0x00, 0x00, 0x00, 0x66, 0x00, 0x03, 0x00, 0x70, 0x00, 0x0e, 0x00, 0x0a, 0x00, 0x66, 0x00, 0x03, 0x00, 0x70, 0x00, 0x0e, 0x00, 0x0a), PHYREGS(0x03d5, 0x03d1, 0x03cd, 0x042d, 0x0431, 0x0436), }, { .freq = 2447, RADIOREGS3(0x00, 0x01, 0x03, 0x09, 0x8f, 0x08, 0x08, 0x04, 0x16, 0x01, 0x06, 0x06, 0x06, 0x8f, 0x30, 0x00, 0x00, 0x00, 0x55, 0x00, 0x02, 0x00, 0x70, 0x00, 0x0e, 0x00, 0x09, 0x00, 0x55, 0x00, 0x02, 0x00, 0x70, 0x00, 0x0e, 0x00, 0x09), PHYREGS(0x03d7, 0x03d3, 0x03cf, 0x042b, 0x042f, 0x0434), }, { .freq = 2452, RADIOREGS3(0x00, 0x01, 0x03, 0x09, 0x94, 0x08, 0x08, 0x04, 0x16, 0x01, 0x06, 0x06, 0x06, 0x8f, 0x30, 0x00, 0x00, 0x00, 0x45, 0x00, 0x02, 0x00, 0x70, 0x00, 0x0e, 0x00, 0x09, 0x00, 0x45, 0x00, 0x02, 0x00, 0x70, 0x00, 0x0e, 0x00, 0x09), PHYREGS(0x03d9, 0x03d5, 0x03d1, 0x0429, 0x042d, 0x0431), }, { .freq = 2457, RADIOREGS3(0x00, 0x01, 0x03, 0x09, 0x99, 0x08, 0x08, 0x04, 0x16, 0x01, 0x06, 0x06, 0x06, 0x8f, 0x30, 0x00, 0x00, 0x00, 0x34, 0x00, 0x02, 0x00, 0x70, 0x00, 0x0d, 0x00, 0x09, 0x00, 0x34, 0x00, 0x02, 0x00, 0x70, 0x00, 0x0d, 0x00, 0x09), PHYREGS(0x03db, 0x03d7, 0x03d3, 0x0427, 0x042b, 0x042f), }, { .freq = 2462, RADIOREGS3(0x00, 0x01, 0x03, 0x09, 0x9e, 0x08, 0x08, 0x04, 0x16, 0x01, 0x06, 0x06, 0x06, 0x8f, 0x30, 0x00, 0x00, 0x00, 0x33, 0x00, 0x02, 0x00, 0x70, 0x00, 0x0d, 0x00, 0x09, 0x00, 0x33, 0x00, 0x02, 0x00, 0x70, 0x00, 0x0d, 0x00, 0x09), PHYREGS(0x03dd, 0x03d9, 0x03d5, 0x0424, 0x0429, 0x042d), }, { .freq = 2467, RADIOREGS3(0x00, 0x01, 0x03, 0x09, 0xa3, 0x08, 0x08, 0x04, 0x16, 0x01, 0x06, 0x06, 0x06, 0x8f, 0x30, 0x00, 0x00, 0x00, 0x22, 0x00, 0x02, 0x00, 0x70, 0x00, 0x0d, 0x00, 0x08, 0x00, 0x22, 0x00, 0x02, 0x00, 0x70, 0x00, 0x0d, 0x00, 0x08), PHYREGS(0x03df, 0x03db, 0x03d7, 0x0422, 0x0427, 0x042b), }, { .freq = 2472, RADIOREGS3(0x00, 0x01, 0x03, 0x09, 0xa8, 0x08, 0x08, 0x04, 0x16, 0x01, 0x07, 0x07, 0x07, 0x8f, 0x30, 0x00, 0x00, 0x00, 0x11, 0x00, 0x02, 0x00, 0x70, 0x00, 0x0d, 0x00, 0x08, 0x00, 0x11, 0x00, 0x02, 0x00, 0x70, 0x00, 0x0d, 0x00, 0x08), PHYREGS(0x03e1, 0x03dd, 0x03d9, 0x0420, 0x0424, 0x0429), }, { .freq = 2484, RADIOREGS3(0xff, 0x01, 0x03, 0x09, 0xb4, 0x08, 0x08, 0x04, 0x16, 0x01, 0x07, 0x07, 0x07, 0x8f, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x70, 0x00, 0x0d, 0x00, 0x08, 0x00, 0x00, 0x00, 0x02, 0x00, 0x70, 0x00, 0x0d, 0x00, 0x08), PHYREGS(0x03e6, 0x03e2, 0x03de, 0x041b, 0x041f, 0x0424), }, }; static const struct b43_nphy_channeltab_entry_rev3 b43_nphy_channeltab_radio_rev8[] = { { .freq = 4920, RADIOREGS3(0xff, 0x01, 0x01, 0x01, 0xec, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x00, 0x00, 0x00, 0x8f, 0x0f, 0x00, 0xff, 0xfe, 0x00, 0x09, 0x00, 0x77, 0x00, 0x0f, 0x00, 0x6f, 0x00, 0xfe, 0x00, 0x09, 0x00, 0x77, 0x00, 0x0f, 0x00, 0x6f, 0x00), PHYREGS(0x07b4, 0x07b0, 0x07ac, 0x0214, 0x0215, 0x0216), }, { .freq = 4930, RADIOREGS3(0xff, 0x01, 0x01, 0x01, 0xed, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x00, 0x00, 0x00, 0x8f, 0x0f, 0x00, 0xff, 0xfe, 0x00, 0x09, 0x00, 0x77, 0x00, 0x0f, 0x00, 0x6f, 0x00, 0xfe, 0x00, 0x09, 0x00, 0x77, 0x00, 0x0f, 0x00, 0x6f, 0x00), PHYREGS(0x07b8, 0x07b4, 0x07b0, 0x0213, 0x0214, 0x0215), }, { .freq = 4940, RADIOREGS3(0xff, 0x01, 0x01, 0x01, 0xee, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x00, 0x00, 0x00, 0x8f, 0x0f, 0x00, 0xff, 0xfe, 0x00, 0x09, 0x00, 0x77, 0x00, 0x0f, 0x00, 0x6f, 0x00, 0xfe, 0x00, 0x09, 0x00, 0x77, 0x00, 0x0f, 0x00, 0x6f, 0x00), PHYREGS(0x07bc, 0x07b8, 0x07b4, 0x0212, 0x0213, 0x0214), }, { .freq = 4950, RADIOREGS3(0xff, 0x01, 0x01, 0x01, 0xef, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x00, 0x00, 0x00, 0x8f, 0x0f, 0x00, 0xff, 0xfe, 0x00, 0x09, 0x00, 0x77, 0x00, 0x0f, 0x00, 0x6f, 0x00, 0xfe, 0x00, 0x09, 0x00, 0x77, 0x00, 0x0f, 0x00, 0x6f, 0x00), PHYREGS(0x07c0, 0x07bc, 0x07b8, 0x0211, 0x0212, 0x0213), }, { .freq = 4960, RADIOREGS3(0xff, 0x01, 0x01, 0x01, 0xf0, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x01, 0x01, 0x01, 0x8f, 0x0f, 0x00, 0xff, 0xfe, 0x00, 0x09, 0x00, 0x77, 0x00, 0x0f, 0x00, 0x6f, 0x00, 0xfe, 0x00, 0x09, 0x00, 0x77, 0x00, 0x0f, 0x00, 0x6f, 0x00), PHYREGS(0x07c4, 0x07c0, 0x07bc, 0x020f, 0x0211, 0x0212), }, { .freq = 4970, RADIOREGS3(0xff, 0x01, 0x01, 0x01, 0xf1, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x01, 0x01, 0x01, 0x8f, 0x0f, 0x00, 0xff, 0xfe, 0x00, 0x09, 0x00, 0x77, 0x00, 0x0f, 0x00, 0x6f, 0x00, 0xfe, 0x00, 0x09, 0x00, 0x77, 0x00, 0x0f, 0x00, 0x6f, 0x00), PHYREGS(0x07c8, 0x07c4, 0x07c0, 0x020e, 0x020f, 0x0211), }, { .freq = 4980, RADIOREGS3(0xff, 0x01, 0x01, 0x01, 0xf2, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x01, 0x01, 0x01, 0x8f, 0x0f, 0x00, 0xff, 0xfe, 0x00, 0x09, 0x00, 0x77, 0x00, 0x0f, 0x00, 0x6f, 0x00, 0xfe, 0x00, 0x09, 0x00, 0x77, 0x00, 0x0f, 0x00, 0x6f, 0x00), PHYREGS(0x07cc, 0x07c8, 0x07c4, 0x020d, 0x020e, 0x020f), }, { .freq = 4990, RADIOREGS3(0xff, 0x01, 0x01, 0x01, 0xf3, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x01, 0x01, 0x01, 0x8f, 0x0f, 0x00, 0xff, 0xfe, 0x00, 0x09, 0x00, 0x77, 0x00, 0x0f, 0x00, 0x6f, 0x00, 0xfe, 0x00, 0x09, 0x00, 0x77, 0x00, 0x0f, 0x00, 0x6f, 0x00), PHYREGS(0x07d0, 0x07cc, 0x07c8, 0x020c, 0x020d, 0x020e), }, { .freq = 5000, RADIOREGS3(0xff, 0x01, 0x01, 0x01, 0xf4, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x01, 0x01, 0x01, 0x8f, 0x0f, 0x00, 0xff, 0xfe, 0x00, 0x09, 0x00, 0x77, 0x00, 0x0f, 0x00, 0x6f, 0x00, 0xfe, 0x00, 0x09, 0x00, 0x77, 0x00, 0x0f, 0x00, 0x6f, 0x00), PHYREGS(0x07d4, 0x07d0, 0x07cc, 0x020b, 0x020c, 0x020d), }, { .freq = 5010, RADIOREGS3(0xff, 0x01, 0x01, 0x01, 0xf5, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x01, 0x01, 0x01, 0x8f, 0x0f, 0x00, 0xff, 0xfe, 0x00, 0x09, 0x00, 0x77, 0x00, 0x0f, 0x00, 0x6f, 0x00, 0xfe, 0x00, 0x09, 0x00, 0x77, 0x00, 0x0f, 0x00, 0x6f, 0x00), PHYREGS(0x07d8, 0x07d4, 0x07d0, 0x020a, 0x020b, 0x020c), }, { .freq = 5020, RADIOREGS3(0xf7, 0x01, 0x01, 0x01, 0xf6, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x01, 0x01, 0x01, 0x8f, 0x0f, 0x00, 0xff, 0xfe, 0x00, 0x09, 0x00, 0x77, 0x00, 0x0f, 0x00, 0x6f, 0x00, 0xfe, 0x00, 0x09, 0x00, 0x77, 0x00, 0x0f, 0x00, 0x6f, 0x00), PHYREGS(0x07dc, 0x07d8, 0x07d4, 0x0209, 0x020a, 0x020b), }, { .freq = 5030, RADIOREGS3(0xf7, 0x01, 0x01, 0x01, 0xf7, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x01, 0x01, 0x01, 0x8f, 0x0f, 0x00, 0xff, 0xfe, 0x00, 0x09, 0x00, 0x77, 0x00, 0x0f, 0x00, 0x6f, 0x00, 0xfe, 0x00, 0x09, 0x00, 0x77, 0x00, 0x0f, 0x00, 0x6f, 0x00), PHYREGS(0x07e0, 0x07dc, 0x07d8, 0x0208, 0x0209, 0x020a), }, { .freq = 5040, RADIOREGS3(0xef, 0x01, 0x01, 0x01, 0xf8, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x01, 0x01, 0x01, 0x8f, 0x0f, 0x00, 0xff, 0xfe, 0x00, 0x09, 0x00, 0x77, 0x00, 0x0f, 0x00, 0x6f, 0x00, 0xfe, 0x00, 0x09, 0x00, 0x77, 0x00, 0x0f, 0x00, 0x6f, 0x00), PHYREGS(0x07e4, 0x07e0, 0x07dc, 0x0207, 0x0208, 0x0209), }, { .freq = 5050, RADIOREGS3(0xef, 0x01, 0x01, 0x01, 0xf9, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x01, 0x01, 0x01, 0x8f, 0x0f, 0x00, 0xff, 0xfe, 0x00, 0x09, 0x00, 0x77, 0x00, 0x0f, 0x00, 0x6f, 0x00, 0xfe, 0x00, 0x09, 0x00, 0x77, 0x00, 0x0f, 0x00, 0x6f, 0x00), PHYREGS(0x07e8, 0x07e4, 0x07e0, 0x0206, 0x0207, 0x0208), }, { .freq = 5060, RADIOREGS3(0xe6, 0x01, 0x01, 0x01, 0xfa, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x01, 0x01, 0x01, 0x8f, 0x0f, 0x00, 0xff, 0xfe, 0x00, 0x09, 0x00, 0x77, 0x00, 0x0f, 0x00, 0x6f, 0x00, 0xfe, 0x00, 0x09, 0x00, 0x77, 0x00, 0x0f, 0x00, 0x6f, 0x00), PHYREGS(0x07ec, 0x07e8, 0x07e4, 0x0205, 0x0206, 0x0207), }, { .freq = 5070, RADIOREGS3(0xe6, 0x01, 0x01, 0x01, 0xfb, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x01, 0x01, 0x01, 0x8f, 0x0f, 0x00, 0xff, 0xfd, 0x00, 0x09, 0x00, 0x77, 0x00, 0x0f, 0x00, 0x6f, 0x00, 0xfd, 0x00, 0x09, 0x00, 0x77, 0x00, 0x0f, 0x00, 0x6f, 0x00), PHYREGS(0x07f0, 0x07ec, 0x07e8, 0x0204, 0x0205, 0x0206), }, { .freq = 5080, RADIOREGS3(0xde, 0x01, 0x01, 0x01, 0xfc, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x01, 0x01, 0x01, 0x8f, 0x0f, 0x00, 0xff, 0xfd, 0x00, 0x09, 0x00, 0x77, 0x00, 0x0f, 0x00, 0x6f, 0x00, 0xfd, 0x00, 0x09, 0x00, 0x77, 0x00, 0x0f, 0x00, 0x6f, 0x00), PHYREGS(0x07f4, 0x07f0, 0x07ec, 0x0203, 0x0204, 0x0205), }, { .freq = 5090, RADIOREGS3(0xde, 0x01, 0x01, 0x01, 0xfd, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x01, 0x01, 0x01, 0x8f, 0x0f, 0x00, 0xff, 0xfd, 0x00, 0x09, 0x00, 0x77, 0x00, 0x0f, 0x00, 0x6f, 0x00, 0xfd, 0x00, 0x09, 0x00, 0x77, 0x00, 0x0f, 0x00, 0x6f, 0x00), PHYREGS(0x07f8, 0x07f4, 0x07f0, 0x0202, 0x0203, 0x0204), }, { .freq = 5100, RADIOREGS3(0xd6, 0x01, 0x01, 0x01, 0xfe, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x02, 0x02, 0x02, 0x8f, 0x0f, 0x00, 0xff, 0xfd, 0x00, 0x08, 0x00, 0x77, 0x00, 0x0f, 0x00, 0x6f, 0x00, 0xfd, 0x00, 0x08, 0x00, 0x77, 0x00, 0x0f, 0x00, 0x6f, 0x00), PHYREGS(0x07fc, 0x07f8, 0x07f4, 0x0201, 0x0202, 0x0203), }, { .freq = 5110, RADIOREGS3(0xd6, 0x01, 0x01, 0x01, 0xff, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x02, 0x02, 0x02, 0x8f, 0x0f, 0x00, 0xff, 0xfc, 0x00, 0x08, 0x00, 0x77, 0x00, 0x0f, 0x00, 0x6f, 0x00, 0xfc, 0x00, 0x08, 0x00, 0x77, 0x00, 0x0f, 0x00, 0x6f, 0x00), PHYREGS(0x0800, 0x07fc, 0x07f8, 0x0200, 0x0201, 0x0202), }, { .freq = 5120, RADIOREGS3(0xce, 0x01, 0x01, 0x02, 0x00, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x02, 0x02, 0x02, 0x8f, 0x0f, 0x00, 0xff, 0xfc, 0x00, 0x08, 0x00, 0x77, 0x00, 0x0f, 0x00, 0x6f, 0x00, 0xfc, 0x00, 0x08, 0x00, 0x77, 0x00, 0x0f, 0x00, 0x6f, 0x00), PHYREGS(0x0804, 0x0800, 0x07fc, 0x01ff, 0x0200, 0x0201), }, { .freq = 5130, RADIOREGS3(0xce, 0x01, 0x01, 0x02, 0x01, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x02, 0x02, 0x02, 0x8f, 0x0f, 0x00, 0xff, 0xfc, 0x00, 0x08, 0x00, 0x77, 0x00, 0x0f, 0x00, 0x6f, 0x00, 0xfc, 0x00, 0x08, 0x00, 0x77, 0x00, 0x0f, 0x00, 0x6f, 0x00), PHYREGS(0x0808, 0x0804, 0x0800, 0x01fe, 0x01ff, 0x0200), }, { .freq = 5140, RADIOREGS3(0xc6, 0x01, 0x01, 0x02, 0x02, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x02, 0x02, 0x02, 0x8f, 0x0f, 0x00, 0xff, 0xfb, 0x00, 0x08, 0x00, 0x77, 0x00, 0x0f, 0x00, 0x6f, 0x00, 0xfb, 0x00, 0x08, 0x00, 0x77, 0x00, 0x0f, 0x00, 0x6f, 0x00), PHYREGS(0x080c, 0x0808, 0x0804, 0x01fd, 0x01fe, 0x01ff), }, { .freq = 5160, RADIOREGS3(0xbe, 0x01, 0x01, 0x02, 0x04, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x02, 0x02, 0x02, 0x8f, 0x0f, 0x00, 0xff, 0xfa, 0x00, 0x07, 0x00, 0x77, 0x00, 0x0e, 0x00, 0x6f, 0x00, 0xfa, 0x00, 0x07, 0x00, 0x77, 0x00, 0x0e, 0x00, 0x6f, 0x00), PHYREGS(0x0814, 0x0810, 0x080c, 0x01fb, 0x01fc, 0x01fd), }, { .freq = 5170, RADIOREGS3(0xbe, 0x01, 0x01, 0x02, 0x05, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x02, 0x02, 0x02, 0x8f, 0x0f, 0x00, 0xff, 0xfa, 0x00, 0x07, 0x00, 0x77, 0x00, 0x0e, 0x00, 0x6f, 0x00, 0xfa, 0x00, 0x07, 0x00, 0x77, 0x00, 0x0e, 0x00, 0x6f, 0x00), PHYREGS(0x0818, 0x0814, 0x0810, 0x01fa, 0x01fb, 0x01fc), }, { .freq = 5180, RADIOREGS3(0xb6, 0x01, 0x01, 0x02, 0x06, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x02, 0x02, 0x02, 0x8f, 0x0f, 0x00, 0xff, 0xf9, 0x00, 0x06, 0x00, 0x77, 0x00, 0x0e, 0x00, 0x6f, 0x00, 0xf9, 0x00, 0x06, 0x00, 0x77, 0x00, 0x0e, 0x00, 0x6f, 0x00), PHYREGS(0x081c, 0x0818, 0x0814, 0x01f9, 0x01fa, 0x01fb), }, { .freq = 5190, RADIOREGS3(0xb6, 0x01, 0x01, 0x02, 0x07, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x02, 0x02, 0x02, 0x8f, 0x0f, 0x00, 0xff, 0xf9, 0x00, 0x06, 0x00, 0x77, 0x00, 0x0d, 0x00, 0x6f, 0x00, 0xf9, 0x00, 0x06, 0x00, 0x77, 0x00, 0x0d, 0x00, 0x6f, 0x00), PHYREGS(0x0820, 0x081c, 0x0818, 0x01f8, 0x01f9, 0x01fa), }, { .freq = 5200, RADIOREGS3(0xaf, 0x01, 0x01, 0x02, 0x08, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x02, 0x02, 0x02, 0x8f, 0x0f, 0x00, 0xff, 0xf9, 0x00, 0x05, 0x00, 0x77, 0x00, 0x0d, 0x00, 0x6f, 0x00, 0xf9, 0x00, 0x05, 0x00, 0x77, 0x00, 0x0d, 0x00, 0x6f, 0x00), PHYREGS(0x0824, 0x0820, 0x081c, 0x01f7, 0x01f8, 0x01f9), }, { .freq = 5210, RADIOREGS3(0xaf, 0x01, 0x01, 0x02, 0x09, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x02, 0x02, 0x02, 0x8f, 0x0f, 0x00, 0xff, 0xf9, 0x00, 0x05, 0x00, 0x77, 0x00, 0x0d, 0x00, 0x6f, 0x00, 0xf9, 0x00, 0x05, 0x00, 0x77, 0x00, 0x0d, 0x00, 0x6f, 0x00), PHYREGS(0x0828, 0x0824, 0x0820, 0x01f6, 0x01f7, 0x01f8), }, { .freq = 5220, RADIOREGS3(0xa7, 0x01, 0x01, 0x02, 0x0a, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x02, 0x02, 0x02, 0x8e, 0x0f, 0x00, 0xfe, 0xd8, 0x00, 0x05, 0x00, 0x77, 0x00, 0x0d, 0x00, 0x6f, 0x00, 0xd8, 0x00, 0x05, 0x00, 0x77, 0x00, 0x0d, 0x00, 0x6f, 0x00), PHYREGS(0x082c, 0x0828, 0x0824, 0x01f5, 0x01f6, 0x01f7), }, { .freq = 5230, RADIOREGS3(0xa7, 0x01, 0x01, 0x02, 0x0b, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x02, 0x02, 0x02, 0x8e, 0x0f, 0x00, 0xee, 0xd8, 0x00, 0x05, 0x00, 0x77, 0x00, 0x0d, 0x00, 0x6f, 0x00, 0xd8, 0x00, 0x05, 0x00, 0x77, 0x00, 0x0d, 0x00, 0x6f, 0x00), PHYREGS(0x0830, 0x082c, 0x0828, 0x01f4, 0x01f5, 0x01f6), }, { .freq = 5240, RADIOREGS3(0xa0, 0x01, 0x01, 0x02, 0x0c, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x02, 0x02, 0x02, 0x8e, 0x0f, 0x00, 0xee, 0xc8, 0x00, 0x05, 0x00, 0x77, 0x00, 0x0d, 0x00, 0x6f, 0x00, 0xc8, 0x00, 0x05, 0x00, 0x77, 0x00, 0x0d, 0x00, 0x6f, 0x00), PHYREGS(0x0834, 0x0830, 0x082c, 0x01f3, 0x01f4, 0x01f5), }, { .freq = 5250, RADIOREGS3(0xa0, 0x01, 0x01, 0x02, 0x0d, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x02, 0x02, 0x02, 0x8e, 0x0f, 0x00, 0xed, 0xc7, 0x00, 0x05, 0x00, 0x77, 0x00, 0x0d, 0x00, 0x6f, 0x00, 0xc7, 0x00, 0x05, 0x00, 0x77, 0x00, 0x0d, 0x00, 0x6f, 0x00), PHYREGS(0x0838, 0x0834, 0x0830, 0x01f2, 0x01f3, 0x01f4), }, { .freq = 5260, RADIOREGS3(0x98, 0x01, 0x01, 0x02, 0x0e, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x02, 0x02, 0x02, 0x8e, 0x0e, 0x00, 0xed, 0xc7, 0x00, 0x04, 0x00, 0x77, 0x00, 0x0d, 0x00, 0x6f, 0x00, 0xc7, 0x00, 0x04, 0x00, 0x77, 0x00, 0x0d, 0x00, 0x6f, 0x00), PHYREGS(0x083c, 0x0838, 0x0834, 0x01f1, 0x01f2, 0x01f3), }, { .freq = 5270, RADIOREGS3(0x98, 0x01, 0x01, 0x02, 0x0f, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x03, 0x03, 0x03, 0x8e, 0x0e, 0x00, 0xed, 0xc7, 0x00, 0x04, 0x00, 0x77, 0x00, 0x0c, 0x00, 0x6f, 0x00, 0xc7, 0x00, 0x04, 0x00, 0x77, 0x00, 0x0c, 0x00, 0x6f, 0x00), PHYREGS(0x0840, 0x083c, 0x0838, 0x01f0, 0x01f1, 0x01f2), }, { .freq = 5280, RADIOREGS3(0x91, 0x01, 0x01, 0x02, 0x10, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x03, 0x03, 0x03, 0x8d, 0x0e, 0x00, 0xdc, 0xb7, 0x00, 0x03, 0x00, 0x77, 0x00, 0x0c, 0x00, 0x6f, 0x00, 0xb7, 0x00, 0x03, 0x00, 0x77, 0x00, 0x0c, 0x00, 0x6f, 0x00), PHYREGS(0x0844, 0x0840, 0x083c, 0x01f0, 0x01f0, 0x01f1), }, { .freq = 5290, RADIOREGS3(0x91, 0x01, 0x01, 0x02, 0x11, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x03, 0x03, 0x03, 0x8d, 0x0e, 0x00, 0xdc, 0xb7, 0x00, 0x03, 0x00, 0x77, 0x00, 0x0c, 0x00, 0x6f, 0x00, 0xb7, 0x00, 0x03, 0x00, 0x77, 0x00, 0x0c, 0x00, 0x6f, 0x00), PHYREGS(0x0848, 0x0844, 0x0840, 0x01ef, 0x01f0, 0x01f0), }, { .freq = 5300, RADIOREGS3(0x8a, 0x01, 0x01, 0x02, 0x12, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x03, 0x03, 0x03, 0x8d, 0x0e, 0x00, 0xdc, 0xb7, 0x00, 0x03, 0x00, 0x77, 0x00, 0x0c, 0x00, 0x6f, 0x00, 0xb7, 0x00, 0x03, 0x00, 0x77, 0x00, 0x0c, 0x00, 0x6f, 0x00), PHYREGS(0x084c, 0x0848, 0x0844, 0x01ee, 0x01ef, 0x01f0), }, { .freq = 5310, RADIOREGS3(0x8a, 0x01, 0x01, 0x02, 0x13, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x03, 0x03, 0x03, 0x8d, 0x0e, 0x00, 0xdc, 0xb7, 0x00, 0x03, 0x00, 0x77, 0x00, 0x0c, 0x00, 0x6f, 0x00, 0xb7, 0x00, 0x03, 0x00, 0x77, 0x00, 0x0c, 0x00, 0x6f, 0x00), PHYREGS(0x0850, 0x084c, 0x0848, 0x01ed, 0x01ee, 0x01ef), }, { .freq = 5320, RADIOREGS3(0x83, 0x01, 0x01, 0x02, 0x14, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x03, 0x03, 0x03, 0x8d, 0x0e, 0x00, 0xdb, 0xb7, 0x00, 0x03, 0x00, 0x77, 0x00, 0x0c, 0x00, 0x6f, 0x00, 0xb7, 0x00, 0x03, 0x00, 0x77, 0x00, 0x0c, 0x00, 0x6f, 0x00), PHYREGS(0x0854, 0x0850, 0x084c, 0x01ec, 0x01ed, 0x01ee), }, { .freq = 5330, RADIOREGS3(0x83, 0x01, 0x01, 0x02, 0x15, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x03, 0x03, 0x03, 0x8d, 0x0d, 0x00, 0xcb, 0xa6, 0x00, 0x03, 0x00, 0x77, 0x00, 0x0b, 0x00, 0x6f, 0x00, 0xa6, 0x00, 0x03, 0x00, 0x77, 0x00, 0x0b, 0x00, 0x6f, 0x00), PHYREGS(0x0858, 0x0854, 0x0850, 0x01eb, 0x01ec, 0x01ed), }, { .freq = 5340, RADIOREGS3(0x7c, 0x01, 0x01, 0x02, 0x16, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x03, 0x03, 0x03, 0x8d, 0x0d, 0x00, 0xca, 0xa6, 0x00, 0x03, 0x00, 0x77, 0x00, 0x0b, 0x00, 0x6f, 0x00, 0xa6, 0x00, 0x03, 0x00, 0x77, 0x00, 0x0b, 0x00, 0x6f, 0x00), PHYREGS(0x085c, 0x0858, 0x0854, 0x01ea, 0x01eb, 0x01ec), }, { .freq = 5350, RADIOREGS3(0x7c, 0x01, 0x01, 0x02, 0x17, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x03, 0x03, 0x03, 0x8c, 0x0d, 0x00, 0xca, 0xa6, 0x00, 0x03, 0x00, 0x77, 0x00, 0x0b, 0x00, 0x6f, 0x00, 0xa6, 0x00, 0x03, 0x00, 0x77, 0x00, 0x0b, 0x00, 0x6f, 0x00), PHYREGS(0x0860, 0x085c, 0x0858, 0x01e9, 0x01ea, 0x01eb), }, { .freq = 5360, RADIOREGS3(0x75, 0x01, 0x01, 0x02, 0x18, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x03, 0x03, 0x03, 0x8c, 0x0d, 0x00, 0xc9, 0x95, 0x00, 0x03, 0x00, 0x77, 0x00, 0x0a, 0x00, 0x6f, 0x00, 0x95, 0x00, 0x03, 0x00, 0x77, 0x00, 0x0a, 0x00, 0x6f, 0x00), PHYREGS(0x0864, 0x0860, 0x085c, 0x01e8, 0x01e9, 0x01ea), }, { .freq = 5370, RADIOREGS3(0x75, 0x01, 0x01, 0x02, 0x19, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x03, 0x03, 0x03, 0x8c, 0x0d, 0x00, 0xc9, 0x95, 0x00, 0x03, 0x00, 0x77, 0x00, 0x0a, 0x00, 0x6f, 0x00, 0x95, 0x00, 0x03, 0x00, 0x77, 0x00, 0x0a, 0x00, 0x6f, 0x00), PHYREGS(0x0868, 0x0864, 0x0860, 0x01e7, 0x01e8, 0x01e9), }, { .freq = 5380, RADIOREGS3(0x6e, 0x01, 0x01, 0x02, 0x1a, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x03, 0x03, 0x03, 0x8c, 0x0c, 0x00, 0xb8, 0x95, 0x00, 0x03, 0x00, 0x77, 0x00, 0x0a, 0x00, 0x6f, 0x00, 0x95, 0x00, 0x03, 0x00, 0x77, 0x00, 0x0a, 0x00, 0x6f, 0x00), PHYREGS(0x086c, 0x0868, 0x0864, 0x01e6, 0x01e7, 0x01e8), }, { .freq = 5390, RADIOREGS3(0x6e, 0x01, 0x01, 0x02, 0x1b, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x03, 0x03, 0x03, 0x8c, 0x0c, 0x00, 0xb8, 0x84, 0x00, 0x03, 0x00, 0x77, 0x00, 0x0a, 0x00, 0x6f, 0x00, 0x84, 0x00, 0x03, 0x00, 0x77, 0x00, 0x0a, 0x00, 0x6f, 0x00), PHYREGS(0x0870, 0x086c, 0x0868, 0x01e5, 0x01e6, 0x01e7), }, { .freq = 5400, RADIOREGS3(0x67, 0x01, 0x01, 0x02, 0x1c, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x03, 0x03, 0x03, 0x8c, 0x0c, 0x00, 0xb8, 0x84, 0x00, 0x03, 0x00, 0x77, 0x00, 0x0a, 0x00, 0x6f, 0x00, 0x84, 0x00, 0x03, 0x00, 0x77, 0x00, 0x0a, 0x00, 0x6f, 0x00), PHYREGS(0x0874, 0x0870, 0x086c, 0x01e5, 0x01e5, 0x01e6), }, { .freq = 5410, RADIOREGS3(0x67, 0x01, 0x01, 0x02, 0x1d, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x03, 0x03, 0x03, 0x8c, 0x0c, 0x00, 0xb7, 0x84, 0x00, 0x02, 0x00, 0x77, 0x00, 0x0a, 0x00, 0x6f, 0x00, 0x84, 0x00, 0x02, 0x00, 0x77, 0x00, 0x0a, 0x00, 0x6f, 0x00), PHYREGS(0x0878, 0x0874, 0x0870, 0x01e4, 0x01e5, 0x01e5), }, { .freq = 5420, RADIOREGS3(0x61, 0x01, 0x01, 0x02, 0x1e, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x03, 0x03, 0x03, 0x8c, 0x0c, 0x00, 0xa7, 0x84, 0x00, 0x02, 0x00, 0x77, 0x00, 0x0a, 0x00, 0x6f, 0x00, 0x84, 0x00, 0x02, 0x00, 0x77, 0x00, 0x0a, 0x00, 0x6f, 0x00), PHYREGS(0x087c, 0x0878, 0x0874, 0x01e3, 0x01e4, 0x01e5), }, { .freq = 5430, RADIOREGS3(0x61, 0x01, 0x01, 0x02, 0x1f, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x03, 0x03, 0x03, 0x8c, 0x0b, 0x00, 0xa6, 0x84, 0x00, 0x02, 0x00, 0x77, 0x00, 0x0a, 0x00, 0x6f, 0x00, 0x84, 0x00, 0x02, 0x00, 0x77, 0x00, 0x0a, 0x00, 0x6f, 0x00), PHYREGS(0x0880, 0x087c, 0x0878, 0x01e2, 0x01e3, 0x01e4), }, { .freq = 5440, RADIOREGS3(0x5a, 0x01, 0x01, 0x02, 0x20, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x04, 0x04, 0x04, 0x8b, 0x0b, 0x00, 0xa6, 0x84, 0x00, 0x02, 0x00, 0x77, 0x00, 0x09, 0x00, 0x6f, 0x00, 0x84, 0x00, 0x02, 0x00, 0x77, 0x00, 0x09, 0x00, 0x6f, 0x00), PHYREGS(0x0884, 0x0880, 0x087c, 0x01e1, 0x01e2, 0x01e3), }, { .freq = 5450, RADIOREGS3(0x5a, 0x01, 0x01, 0x02, 0x21, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x04, 0x04, 0x04, 0x8b, 0x0b, 0x00, 0x95, 0x84, 0x00, 0x01, 0x00, 0x77, 0x00, 0x09, 0x00, 0x6f, 0x00, 0x84, 0x00, 0x01, 0x00, 0x77, 0x00, 0x09, 0x00, 0x6f, 0x00), PHYREGS(0x0888, 0x0884, 0x0880, 0x01e0, 0x01e1, 0x01e2), }, { .freq = 5460, RADIOREGS3(0x53, 0x01, 0x01, 0x02, 0x22, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x04, 0x04, 0x04, 0x8b, 0x0b, 0x00, 0x95, 0x84, 0x00, 0x01, 0x00, 0x77, 0x00, 0x09, 0x00, 0x6f, 0x00, 0x84, 0x00, 0x01, 0x00, 0x77, 0x00, 0x09, 0x00, 0x6f, 0x00), PHYREGS(0x088c, 0x0888, 0x0884, 0x01df, 0x01e0, 0x01e1), }, { .freq = 5470, RADIOREGS3(0x53, 0x01, 0x01, 0x02, 0x23, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x04, 0x04, 0x04, 0x8b, 0x0b, 0x00, 0x94, 0x73, 0x00, 0x01, 0x00, 0x77, 0x00, 0x09, 0x00, 0x6f, 0x00, 0x73, 0x00, 0x01, 0x00, 0x77, 0x00, 0x09, 0x00, 0x6f, 0x00), PHYREGS(0x0890, 0x088c, 0x0888, 0x01de, 0x01df, 0x01e0), }, { .freq = 5480, RADIOREGS3(0x4d, 0x01, 0x01, 0x02, 0x24, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x04, 0x04, 0x04, 0x8a, 0x0a, 0x00, 0x84, 0x73, 0x00, 0x00, 0x00, 0x77, 0x00, 0x09, 0x00, 0x6f, 0x00, 0x73, 0x00, 0x00, 0x00, 0x77, 0x00, 0x09, 0x00, 0x6f, 0x00), PHYREGS(0x0894, 0x0890, 0x088c, 0x01dd, 0x01de, 0x01df), }, { .freq = 5490, RADIOREGS3(0x4d, 0x01, 0x01, 0x02, 0x25, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x04, 0x04, 0x04, 0x8a, 0x0a, 0x00, 0x83, 0x73, 0x00, 0x00, 0x00, 0x77, 0x00, 0x09, 0x00, 0x6f, 0x00, 0x73, 0x00, 0x00, 0x00, 0x77, 0x00, 0x09, 0x00, 0x6f, 0x00), PHYREGS(0x0898, 0x0894, 0x0890, 0x01dd, 0x01dd, 0x01de), }, { .freq = 5500, RADIOREGS3(0x47, 0x01, 0x01, 0x02, 0x26, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x04, 0x04, 0x04, 0x8a, 0x0a, 0x00, 0x82, 0x73, 0x00, 0x00, 0x00, 0x77, 0x00, 0x09, 0x00, 0x6f, 0x00, 0x73, 0x00, 0x00, 0x00, 0x77, 0x00, 0x09, 0x00, 0x6f, 0x00), PHYREGS(0x089c, 0x0898, 0x0894, 0x01dc, 0x01dd, 0x01dd), }, { .freq = 5510, RADIOREGS3(0x47, 0x01, 0x01, 0x02, 0x27, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x04, 0x04, 0x04, 0x8a, 0x0a, 0x00, 0x82, 0x73, 0x00, 0x00, 0x00, 0x77, 0x00, 0x09, 0x00, 0x6f, 0x00, 0x73, 0x00, 0x00, 0x00, 0x77, 0x00, 0x09, 0x00, 0x6f, 0x00), PHYREGS(0x08a0, 0x089c, 0x0898, 0x01db, 0x01dc, 0x01dd), }, { .freq = 5520, RADIOREGS3(0x40, 0x01, 0x01, 0x02, 0x28, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x04, 0x04, 0x04, 0x8a, 0x0a, 0x00, 0x72, 0x73, 0x00, 0x00, 0x00, 0x77, 0x00, 0x09, 0x00, 0x6f, 0x00, 0x73, 0x00, 0x00, 0x00, 0x77, 0x00, 0x09, 0x00, 0x6f, 0x00), PHYREGS(0x08a4, 0x08a0, 0x089c, 0x01da, 0x01db, 0x01dc), }, { .freq = 5530, RADIOREGS3(0x40, 0x01, 0x01, 0x02, 0x29, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x04, 0x04, 0x04, 0x8a, 0x09, 0x00, 0x72, 0x73, 0x00, 0x00, 0x00, 0x77, 0x00, 0x09, 0x00, 0x6f, 0x00, 0x73, 0x00, 0x00, 0x00, 0x77, 0x00, 0x09, 0x00, 0x6f, 0x00), PHYREGS(0x08a8, 0x08a4, 0x08a0, 0x01d9, 0x01da, 0x01db), }, { .freq = 5540, RADIOREGS3(0x3a, 0x01, 0x01, 0x02, 0x2a, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x04, 0x04, 0x04, 0x8a, 0x09, 0x00, 0x71, 0x73, 0x00, 0x00, 0x00, 0x77, 0x00, 0x09, 0x00, 0x6f, 0x00, 0x73, 0x00, 0x00, 0x00, 0x77, 0x00, 0x09, 0x00, 0x6f, 0x00), PHYREGS(0x08ac, 0x08a8, 0x08a4, 0x01d8, 0x01d9, 0x01da), }, { .freq = 5550, RADIOREGS3(0x3a, 0x01, 0x01, 0x02, 0x2b, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x04, 0x04, 0x04, 0x89, 0x09, 0x00, 0x61, 0x73, 0x00, 0x00, 0x00, 0x77, 0x00, 0x09, 0x00, 0x6f, 0x00, 0x73, 0x00, 0x00, 0x00, 0x77, 0x00, 0x09, 0x00, 0x6f, 0x00), PHYREGS(0x08b0, 0x08ac, 0x08a8, 0x01d7, 0x01d8, 0x01d9), }, { .freq = 5560, RADIOREGS3(0x34, 0x01, 0x01, 0x02, 0x2c, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x04, 0x04, 0x04, 0x89, 0x09, 0x00, 0x61, 0x73, 0x00, 0x00, 0x00, 0x77, 0x00, 0x09, 0x00, 0x6f, 0x00, 0x73, 0x00, 0x00, 0x00, 0x77, 0x00, 0x09, 0x00, 0x6f, 0x00), PHYREGS(0x08b4, 0x08b0, 0x08ac, 0x01d7, 0x01d7, 0x01d8), }, { .freq = 5570, RADIOREGS3(0x34, 0x01, 0x01, 0x02, 0x2d, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x04, 0x04, 0x04, 0x89, 0x09, 0x00, 0x61, 0x62, 0x00, 0x00, 0x00, 0x77, 0x00, 0x09, 0x00, 0x6f, 0x00, 0x62, 0x00, 0x00, 0x00, 0x77, 0x00, 0x09, 0x00, 0x6f, 0x00), PHYREGS(0x08b8, 0x08b4, 0x08b0, 0x01d6, 0x01d7, 0x01d7), }, { .freq = 5580, RADIOREGS3(0x2e, 0x01, 0x01, 0x02, 0x2e, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x04, 0x04, 0x04, 0x89, 0x08, 0x00, 0x60, 0x62, 0x00, 0x00, 0x00, 0x77, 0x00, 0x08, 0x00, 0x6f, 0x00, 0x62, 0x00, 0x00, 0x00, 0x77, 0x00, 0x08, 0x00, 0x6f, 0x00), PHYREGS(0x08bc, 0x08b8, 0x08b4, 0x01d5, 0x01d6, 0x01d7), }, { .freq = 5590, RADIOREGS3(0x2e, 0x01, 0x01, 0x02, 0x2f, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x04, 0x04, 0x04, 0x89, 0x08, 0x00, 0x50, 0x61, 0x00, 0x00, 0x00, 0x77, 0x00, 0x08, 0x00, 0x6f, 0x00, 0x61, 0x00, 0x00, 0x00, 0x77, 0x00, 0x08, 0x00, 0x6f, 0x00), PHYREGS(0x08c0, 0x08bc, 0x08b8, 0x01d4, 0x01d5, 0x01d6), }, { .freq = 5600, RADIOREGS3(0x28, 0x01, 0x01, 0x02, 0x30, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x05, 0x05, 0x05, 0x89, 0x08, 0x00, 0x50, 0x51, 0x00, 0x00, 0x00, 0x77, 0x00, 0x08, 0x00, 0x6f, 0x00, 0x51, 0x00, 0x00, 0x00, 0x77, 0x00, 0x08, 0x00, 0x6f, 0x00), PHYREGS(0x08c4, 0x08c0, 0x08bc, 0x01d3, 0x01d4, 0x01d5), }, { .freq = 5610, RADIOREGS3(0x28, 0x01, 0x01, 0x02, 0x31, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x05, 0x05, 0x05, 0x89, 0x08, 0x00, 0x50, 0x51, 0x00, 0x00, 0x00, 0x77, 0x00, 0x08, 0x00, 0x6f, 0x00, 0x51, 0x00, 0x00, 0x00, 0x77, 0x00, 0x08, 0x00, 0x6f, 0x00), PHYREGS(0x08c8, 0x08c4, 0x08c0, 0x01d2, 0x01d3, 0x01d4), }, { .freq = 5620, RADIOREGS3(0x21, 0x01, 0x01, 0x02, 0x32, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x05, 0x05, 0x05, 0x89, 0x08, 0x00, 0x50, 0x50, 0x00, 0x00, 0x00, 0x77, 0x00, 0x07, 0x00, 0x6f, 0x00, 0x50, 0x00, 0x00, 0x00, 0x77, 0x00, 0x07, 0x00, 0x6f, 0x00), PHYREGS(0x08cc, 0x08c8, 0x08c4, 0x01d2, 0x01d2, 0x01d3), }, { .freq = 5630, RADIOREGS3(0x21, 0x01, 0x01, 0x02, 0x33, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x05, 0x05, 0x05, 0x88, 0x07, 0x00, 0x50, 0x50, 0x00, 0x00, 0x00, 0x77, 0x00, 0x07, 0x00, 0x6f, 0x00, 0x50, 0x00, 0x00, 0x00, 0x77, 0x00, 0x07, 0x00, 0x6f, 0x00), PHYREGS(0x08d0, 0x08cc, 0x08c8, 0x01d1, 0x01d2, 0x01d2), }, { .freq = 5640, RADIOREGS3(0x1c, 0x01, 0x01, 0x02, 0x34, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x05, 0x05, 0x05, 0x88, 0x07, 0x00, 0x40, 0x50, 0x00, 0x00, 0x00, 0x77, 0x00, 0x07, 0x00, 0x6f, 0x00, 0x50, 0x00, 0x00, 0x00, 0x77, 0x00, 0x07, 0x00, 0x6f, 0x00), PHYREGS(0x08d4, 0x08d0, 0x08cc, 0x01d0, 0x01d1, 0x01d2), }, { .freq = 5650, RADIOREGS3(0x1c, 0x01, 0x01, 0x02, 0x35, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x05, 0x05, 0x05, 0x88, 0x07, 0x00, 0x40, 0x40, 0x00, 0x00, 0x00, 0x77, 0x00, 0x07, 0x00, 0x6f, 0x00, 0x40, 0x00, 0x00, 0x00, 0x77, 0x00, 0x07, 0x00, 0x6f, 0x00), PHYREGS(0x08d8, 0x08d4, 0x08d0, 0x01cf, 0x01d0, 0x01d1), }, { .freq = 5660, RADIOREGS3(0x16, 0x01, 0x01, 0x02, 0x36, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x05, 0x05, 0x05, 0x88, 0x07, 0x00, 0x40, 0x40, 0x00, 0x00, 0x00, 0x77, 0x00, 0x06, 0x00, 0x6f, 0x00, 0x40, 0x00, 0x00, 0x00, 0x77, 0x00, 0x06, 0x00, 0x6f, 0x00), PHYREGS(0x08dc, 0x08d8, 0x08d4, 0x01ce, 0x01cf, 0x01d0), }, { .freq = 5670, RADIOREGS3(0x16, 0x01, 0x01, 0x02, 0x37, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x05, 0x05, 0x05, 0x88, 0x07, 0x00, 0x40, 0x30, 0x00, 0x00, 0x00, 0x77, 0x00, 0x06, 0x00, 0x6f, 0x00, 0x30, 0x00, 0x00, 0x00, 0x77, 0x00, 0x06, 0x00, 0x6f, 0x00), PHYREGS(0x08e0, 0x08dc, 0x08d8, 0x01ce, 0x01ce, 0x01cf), }, { .freq = 5680, RADIOREGS3(0x10, 0x01, 0x01, 0x02, 0x38, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x05, 0x05, 0x05, 0x87, 0x06, 0x00, 0x30, 0x30, 0x00, 0x00, 0x00, 0x77, 0x00, 0x06, 0x00, 0x6f, 0x00, 0x30, 0x00, 0x00, 0x00, 0x77, 0x00, 0x06, 0x00, 0x6f, 0x00), PHYREGS(0x08e4, 0x08e0, 0x08dc, 0x01cd, 0x01ce, 0x01ce), }, { .freq = 5690, RADIOREGS3(0x10, 0x01, 0x01, 0x02, 0x39, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x05, 0x05, 0x05, 0x87, 0x06, 0x00, 0x30, 0x30, 0x00, 0x00, 0x00, 0x77, 0x00, 0x06, 0x00, 0x6f, 0x00, 0x30, 0x00, 0x00, 0x00, 0x77, 0x00, 0x06, 0x00, 0x6f, 0x00), PHYREGS(0x08e8, 0x08e4, 0x08e0, 0x01cc, 0x01cd, 0x01ce), }, { .freq = 5700, RADIOREGS3(0x0a, 0x01, 0x01, 0x02, 0x3a, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x05, 0x05, 0x05, 0x87, 0x06, 0x00, 0x30, 0x30, 0x00, 0x00, 0x00, 0x77, 0x00, 0x06, 0x00, 0x6e, 0x00, 0x30, 0x00, 0x00, 0x00, 0x77, 0x00, 0x06, 0x00, 0x6e, 0x00), PHYREGS(0x08ec, 0x08e8, 0x08e4, 0x01cb, 0x01cc, 0x01cd), }, { .freq = 5710, RADIOREGS3(0x0a, 0x01, 0x01, 0x02, 0x3b, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x05, 0x05, 0x05, 0x87, 0x06, 0x00, 0x30, 0x30, 0x00, 0x00, 0x00, 0x77, 0x00, 0x06, 0x00, 0x6e, 0x00, 0x30, 0x00, 0x00, 0x00, 0x77, 0x00, 0x06, 0x00, 0x6e, 0x00), PHYREGS(0x08f0, 0x08ec, 0x08e8, 0x01ca, 0x01cb, 0x01cc), }, { .freq = 5720, RADIOREGS3(0x0a, 0x01, 0x01, 0x02, 0x3c, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x05, 0x05, 0x05, 0x87, 0x06, 0x00, 0x30, 0x30, 0x00, 0x00, 0x00, 0x77, 0x00, 0x06, 0x00, 0x6e, 0x00, 0x30, 0x00, 0x00, 0x00, 0x77, 0x00, 0x06, 0x00, 0x6e, 0x00), PHYREGS(0x08f4, 0x08f0, 0x08ec, 0x01c9, 0x01ca, 0x01cb), }, { .freq = 5725, RADIOREGS3(0x03, 0x01, 0x02, 0x04, 0x79, 0x07, 0x07, 0x04, 0x10, 0x01, 0x05, 0x05, 0x05, 0x87, 0x06, 0x00, 0x30, 0x30, 0x00, 0x00, 0x00, 0x77, 0x00, 0x06, 0x00, 0x6e, 0x00, 0x30, 0x00, 0x00, 0x00, 0x77, 0x00, 0x06, 0x00, 0x6e, 0x00), PHYREGS(0x08f6, 0x08f2, 0x08ee, 0x01c9, 0x01ca, 0x01cb), }, { .freq = 5730, RADIOREGS3(0x0a, 0x01, 0x01, 0x02, 0x3d, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x05, 0x05, 0x05, 0x87, 0x05, 0x00, 0x20, 0x30, 0x00, 0x00, 0x00, 0x77, 0x00, 0x06, 0x00, 0x6e, 0x00, 0x30, 0x00, 0x00, 0x00, 0x77, 0x00, 0x06, 0x00, 0x6e, 0x00), PHYREGS(0x08f8, 0x08f4, 0x08f0, 0x01c9, 0x01c9, 0x01ca), }, { .freq = 5735, RADIOREGS3(0x03, 0x01, 0x02, 0x04, 0x7b, 0x07, 0x07, 0x04, 0x10, 0x01, 0x05, 0x05, 0x05, 0x87, 0x05, 0x00, 0x20, 0x30, 0x00, 0x00, 0x00, 0x77, 0x00, 0x06, 0x00, 0x6d, 0x00, 0x30, 0x00, 0x00, 0x00, 0x77, 0x00, 0x06, 0x00, 0x6d, 0x00), PHYREGS(0x08fa, 0x08f6, 0x08f2, 0x01c8, 0x01c9, 0x01ca), }, { .freq = 5740, RADIOREGS3(0x0a, 0x01, 0x01, 0x02, 0x3e, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x05, 0x05, 0x05, 0x87, 0x05, 0x00, 0x20, 0x30, 0x00, 0x00, 0x00, 0x77, 0x00, 0x06, 0x00, 0x6d, 0x00, 0x30, 0x00, 0x00, 0x00, 0x77, 0x00, 0x06, 0x00, 0x6d, 0x00), PHYREGS(0x08fc, 0x08f8, 0x08f4, 0x01c8, 0x01c9, 0x01c9), }, { .freq = 5745, RADIOREGS3(0xfe, 0x00, 0x02, 0x04, 0x7d, 0x07, 0x07, 0x04, 0x10, 0x01, 0x05, 0x05, 0x05, 0x87, 0x05, 0x00, 0x20, 0x30, 0x00, 0x00, 0x00, 0x77, 0x00, 0x06, 0x00, 0x6d, 0x00, 0x30, 0x00, 0x00, 0x00, 0x77, 0x00, 0x06, 0x00, 0x6d, 0x00), PHYREGS(0x08fe, 0x08fa, 0x08f6, 0x01c8, 0x01c8, 0x01c9), }, { .freq = 5750, RADIOREGS3(0x0a, 0x01, 0x01, 0x02, 0x3f, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x05, 0x05, 0x05, 0x87, 0x05, 0x00, 0x20, 0x20, 0x00, 0x00, 0x00, 0x77, 0x00, 0x05, 0x00, 0x6d, 0x00, 0x20, 0x00, 0x00, 0x00, 0x77, 0x00, 0x05, 0x00, 0x6d, 0x00), PHYREGS(0x0900, 0x08fc, 0x08f8, 0x01c7, 0x01c8, 0x01c9), }, { .freq = 5755, RADIOREGS3(0xfe, 0x00, 0x02, 0x04, 0x7f, 0x07, 0x07, 0x04, 0x10, 0x01, 0x05, 0x05, 0x05, 0x87, 0x05, 0x00, 0x10, 0x20, 0x00, 0x00, 0x00, 0x77, 0x00, 0x05, 0x00, 0x6c, 0x00, 0x20, 0x00, 0x00, 0x00, 0x77, 0x00, 0x05, 0x00, 0x6c, 0x00), PHYREGS(0x0902, 0x08fe, 0x08fa, 0x01c7, 0x01c8, 0x01c8), }, { .freq = 5760, RADIOREGS3(0x0a, 0x01, 0x01, 0x02, 0x40, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x05, 0x05, 0x05, 0x86, 0x05, 0x00, 0x10, 0x20, 0x00, 0x00, 0x00, 0x77, 0x00, 0x05, 0x00, 0x6c, 0x00, 0x20, 0x00, 0x00, 0x00, 0x77, 0x00, 0x05, 0x00, 0x6c, 0x00), PHYREGS(0x0904, 0x0900, 0x08fc, 0x01c6, 0x01c7, 0x01c8), }, { .freq = 5765, RADIOREGS3(0xf8, 0x00, 0x02, 0x04, 0x81, 0x07, 0x07, 0x04, 0x10, 0x01, 0x05, 0x05, 0x05, 0x86, 0x05, 0x00, 0x10, 0x10, 0x00, 0x00, 0x00, 0x77, 0x00, 0x05, 0x00, 0x6c, 0x00, 0x10, 0x00, 0x00, 0x00, 0x77, 0x00, 0x05, 0x00, 0x6c, 0x00), PHYREGS(0x0906, 0x0902, 0x08fe, 0x01c6, 0x01c7, 0x01c8), }, { .freq = 5770, RADIOREGS3(0x0a, 0x01, 0x01, 0x02, 0x41, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x05, 0x05, 0x05, 0x86, 0x04, 0x00, 0x10, 0x10, 0x00, 0x00, 0x00, 0x77, 0x00, 0x05, 0x00, 0x6b, 0x00, 0x10, 0x00, 0x00, 0x00, 0x77, 0x00, 0x05, 0x00, 0x6b, 0x00), PHYREGS(0x0908, 0x0904, 0x0900, 0x01c6, 0x01c6, 0x01c7), }, { .freq = 5775, RADIOREGS3(0xf8, 0x00, 0x02, 0x04, 0x83, 0x07, 0x07, 0x04, 0x10, 0x01, 0x05, 0x05, 0x05, 0x86, 0x04, 0x00, 0x10, 0x10, 0x00, 0x00, 0x00, 0x77, 0x00, 0x05, 0x00, 0x6b, 0x00, 0x10, 0x00, 0x00, 0x00, 0x77, 0x00, 0x05, 0x00, 0x6b, 0x00), PHYREGS(0x090a, 0x0906, 0x0902, 0x01c5, 0x01c6, 0x01c7), }, { .freq = 5780, RADIOREGS3(0x0a, 0x01, 0x01, 0x02, 0x42, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x05, 0x05, 0x05, 0x86, 0x04, 0x00, 0x10, 0x10, 0x00, 0x00, 0x00, 0x77, 0x00, 0x05, 0x00, 0x6b, 0x00, 0x10, 0x00, 0x00, 0x00, 0x77, 0x00, 0x05, 0x00, 0x6b, 0x00), PHYREGS(0x090c, 0x0908, 0x0904, 0x01c5, 0x01c6, 0x01c6), }, { .freq = 5785, RADIOREGS3(0xf2, 0x00, 0x02, 0x04, 0x85, 0x07, 0x07, 0x04, 0x10, 0x01, 0x06, 0x06, 0x06, 0x86, 0x04, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x77, 0x00, 0x05, 0x00, 0x6b, 0x00, 0x10, 0x00, 0x00, 0x00, 0x77, 0x00, 0x05, 0x00, 0x6b, 0x00), PHYREGS(0x090e, 0x090a, 0x0906, 0x01c4, 0x01c5, 0x01c6), }, { .freq = 5790, RADIOREGS3(0x0a, 0x01, 0x01, 0x02, 0x43, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x06, 0x06, 0x06, 0x86, 0x04, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x77, 0x00, 0x05, 0x00, 0x6b, 0x00, 0x10, 0x00, 0x00, 0x00, 0x77, 0x00, 0x05, 0x00, 0x6b, 0x00), PHYREGS(0x0910, 0x090c, 0x0908, 0x01c4, 0x01c5, 0x01c6), }, { .freq = 5795, RADIOREGS3(0xf2, 0x00, 0x02, 0x04, 0x87, 0x07, 0x07, 0x04, 0x10, 0x01, 0x06, 0x06, 0x06, 0x86, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x77, 0x00, 0x05, 0x00, 0x6b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x77, 0x00, 0x05, 0x00, 0x6b, 0x00), PHYREGS(0x0912, 0x090e, 0x090a, 0x01c4, 0x01c4, 0x01c5), }, { .freq = 5800, RADIOREGS3(0x0a, 0x01, 0x01, 0x02, 0x44, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x06, 0x06, 0x06, 0x86, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x77, 0x00, 0x05, 0x00, 0x6b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x77, 0x00, 0x05, 0x00, 0x6b, 0x00), PHYREGS(0x0914, 0x0910, 0x090c, 0x01c3, 0x01c4, 0x01c5), }, { .freq = 5805, RADIOREGS3(0xed, 0x00, 0x02, 0x04, 0x89, 0x07, 0x07, 0x04, 0x10, 0x01, 0x06, 0x06, 0x06, 0x86, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x77, 0x00, 0x05, 0x00, 0x6a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x77, 0x00, 0x05, 0x00, 0x6a, 0x00), PHYREGS(0x0916, 0x0912, 0x090e, 0x01c3, 0x01c4, 0x01c4), }, { .freq = 5810, RADIOREGS3(0x0a, 0x01, 0x01, 0x02, 0x45, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x06, 0x06, 0x06, 0x86, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x77, 0x00, 0x05, 0x00, 0x6a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x77, 0x00, 0x05, 0x00, 0x6a, 0x00), PHYREGS(0x0918, 0x0914, 0x0910, 0x01c2, 0x01c3, 0x01c4), }, { .freq = 5815, RADIOREGS3(0xed, 0x00, 0x02, 0x04, 0x8b, 0x07, 0x07, 0x04, 0x10, 0x01, 0x06, 0x06, 0x06, 0x86, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x77, 0x00, 0x05, 0x00, 0x6a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x77, 0x00, 0x05, 0x00, 0x6a, 0x00), PHYREGS(0x091a, 0x0916, 0x0912, 0x01c2, 0x01c3, 0x01c4), }, { .freq = 5820, RADIOREGS3(0x0a, 0x01, 0x01, 0x02, 0x46, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x06, 0x06, 0x06, 0x86, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x77, 0x00, 0x05, 0x00, 0x6a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x77, 0x00, 0x05, 0x00, 0x6a, 0x00), PHYREGS(0x091c, 0x0918, 0x0914, 0x01c2, 0x01c2, 0x01c3), }, { .freq = 5825, RADIOREGS3(0xed, 0x00, 0x02, 0x04, 0x8d, 0x07, 0x07, 0x04, 0x10, 0x01, 0x06, 0x06, 0x06, 0x86, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x77, 0x00, 0x05, 0x00, 0x69, 0x00, 0x00, 0x00, 0x00, 0x00, 0x77, 0x00, 0x05, 0x00, 0x69, 0x00), PHYREGS(0x091e, 0x091a, 0x0916, 0x01c1, 0x01c2, 0x01c3), }, { .freq = 5830, RADIOREGS3(0x0a, 0x01, 0x01, 0x02, 0x47, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x06, 0x06, 0x06, 0x86, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x77, 0x00, 0x05, 0x00, 0x69, 0x00, 0x00, 0x00, 0x00, 0x00, 0x77, 0x00, 0x05, 0x00, 0x69, 0x00), PHYREGS(0x0920, 0x091c, 0x0918, 0x01c1, 0x01c2, 0x01c2), }, { .freq = 5840, RADIOREGS3(0x0a, 0x01, 0x01, 0x02, 0x48, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x06, 0x06, 0x06, 0x86, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x77, 0x00, 0x04, 0x00, 0x69, 0x00, 0x00, 0x00, 0x00, 0x00, 0x77, 0x00, 0x04, 0x00, 0x69, 0x00), PHYREGS(0x0924, 0x0920, 0x091c, 0x01c0, 0x01c1, 0x01c2), }, { .freq = 5850, RADIOREGS3(0xe0, 0x00, 0x01, 0x02, 0x49, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x06, 0x06, 0x06, 0x85, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x77, 0x00, 0x04, 0x00, 0x69, 0x00, 0x00, 0x00, 0x00, 0x00, 0x77, 0x00, 0x04, 0x00, 0x69, 0x00), PHYREGS(0x0928, 0x0924, 0x0920, 0x01bf, 0x01c0, 0x01c1), }, { .freq = 5860, RADIOREGS3(0xde, 0x00, 0x01, 0x02, 0x4a, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x06, 0x06, 0x06, 0x85, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x77, 0x00, 0x04, 0x00, 0x69, 0x00, 0x00, 0x00, 0x00, 0x00, 0x77, 0x00, 0x04, 0x00, 0x69, 0x00), PHYREGS(0x092c, 0x0928, 0x0924, 0x01bf, 0x01bf, 0x01c0), }, { .freq = 5870, RADIOREGS3(0xdb, 0x00, 0x01, 0x02, 0x4b, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x06, 0x06, 0x06, 0x85, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x77, 0x00, 0x04, 0x00, 0x68, 0x00, 0x00, 0x00, 0x00, 0x00, 0x77, 0x00, 0x04, 0x00, 0x68, 0x00), PHYREGS(0x0930, 0x092c, 0x0928, 0x01be, 0x01bf, 0x01bf), }, { .freq = 5880, RADIOREGS3(0xd8, 0x00, 0x01, 0x02, 0x4c, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x06, 0x06, 0x06, 0x85, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x77, 0x00, 0x04, 0x00, 0x68, 0x00, 0x00, 0x00, 0x00, 0x00, 0x77, 0x00, 0x04, 0x00, 0x68, 0x00), PHYREGS(0x0934, 0x0930, 0x092c, 0x01bd, 0x01be, 0x01bf), }, { .freq = 5890, RADIOREGS3(0xd6, 0x00, 0x01, 0x02, 0x4d, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x06, 0x06, 0x06, 0x85, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x77, 0x00, 0x04, 0x00, 0x68, 0x00, 0x00, 0x00, 0x00, 0x00, 0x77, 0x00, 0x04, 0x00, 0x68, 0x00), PHYREGS(0x0938, 0x0934, 0x0930, 0x01bc, 0x01bd, 0x01be), }, { .freq = 5900, RADIOREGS3(0xd3, 0x00, 0x01, 0x02, 0x4e, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x06, 0x06, 0x06, 0x85, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x77, 0x00, 0x04, 0x00, 0x68, 0x00, 0x00, 0x00, 0x00, 0x00, 0x77, 0x00, 0x04, 0x00, 0x68, 0x00), PHYREGS(0x093c, 0x0938, 0x0934, 0x01bc, 0x01bc, 0x01bd), }, { .freq = 5910, RADIOREGS3(0xd6, 0x00, 0x01, 0x02, 0x4f, 0x05, 0x05, 0x04, 0x0c, 0x01, 0x06, 0x06, 0x06, 0x85, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x77, 0x00, 0x04, 0x00, 0x68, 0x00, 0x00, 0x00, 0x00, 0x00, 0x77, 0x00, 0x04, 0x00, 0x68, 0x00), PHYREGS(0x0940, 0x093c, 0x0938, 0x01bb, 0x01bc, 0x01bc), }, { .freq = 2412, RADIOREGS3(0x00, 0x01, 0x03, 0x09, 0x6c, 0x08, 0x08, 0x04, 0x16, 0x01, 0x04, 0x04, 0x04, 0x8f, 0x30, 0x00, 0x00, 0x00, 0x78, 0x00, 0x03, 0x00, 0x70, 0x00, 0x0b, 0x00, 0x0a, 0x00, 0x89, 0x00, 0x03, 0x00, 0x70, 0x00, 0x0b, 0x00, 0x0a), PHYREGS(0x03c9, 0x03c5, 0x03c1, 0x043a, 0x043f, 0x0443), }, { .freq = 2417, RADIOREGS3(0x00, 0x01, 0x03, 0x09, 0x71, 0x08, 0x08, 0x04, 0x16, 0x01, 0x05, 0x05, 0x05, 0x8f, 0x30, 0x00, 0x00, 0x00, 0x78, 0x00, 0x03, 0x00, 0x70, 0x00, 0x0b, 0x00, 0x0a, 0x00, 0x89, 0x00, 0x03, 0x00, 0x70, 0x00, 0x0b, 0x00, 0x0a), PHYREGS(0x03cb, 0x03c7, 0x03c3, 0x0438, 0x043d, 0x0441), }, { .freq = 2422, RADIOREGS3(0x00, 0x01, 0x03, 0x09, 0x76, 0x08, 0x08, 0x04, 0x16, 0x01, 0x05, 0x05, 0x05, 0x8f, 0x30, 0x00, 0x00, 0x00, 0x67, 0x00, 0x03, 0x00, 0x70, 0x00, 0x0b, 0x00, 0x0a, 0x00, 0x89, 0x00, 0x03, 0x00, 0x70, 0x00, 0x0b, 0x00, 0x0a), PHYREGS(0x03cd, 0x03c9, 0x03c5, 0x0436, 0x043a, 0x043f), }, { .freq = 2427, RADIOREGS3(0x00, 0x01, 0x03, 0x09, 0x7b, 0x08, 0x08, 0x04, 0x16, 0x01, 0x05, 0x05, 0x05, 0x8f, 0x30, 0x00, 0x00, 0x00, 0x57, 0x00, 0x03, 0x00, 0x70, 0x00, 0x0a, 0x00, 0x0a, 0x00, 0x78, 0x00, 0x03, 0x00, 0x70, 0x00, 0x0a, 0x00, 0x0a), PHYREGS(0x03cf, 0x03cb, 0x03c7, 0x0434, 0x0438, 0x043d), }, { .freq = 2432, RADIOREGS3(0x00, 0x01, 0x03, 0x09, 0x80, 0x08, 0x08, 0x04, 0x16, 0x01, 0x05, 0x05, 0x05, 0x8f, 0x30, 0x00, 0x00, 0x00, 0x56, 0x00, 0x03, 0x00, 0x70, 0x00, 0x0a, 0x00, 0x0a, 0x00, 0x77, 0x00, 0x03, 0x00, 0x70, 0x00, 0x0a, 0x00, 0x0a), PHYREGS(0x03d1, 0x03cd, 0x03c9, 0x0431, 0x0436, 0x043a), }, { .freq = 2437, RADIOREGS3(0x00, 0x01, 0x03, 0x09, 0x85, 0x08, 0x08, 0x04, 0x16, 0x01, 0x05, 0x05, 0x05, 0x8f, 0x30, 0x00, 0x00, 0x00, 0x46, 0x00, 0x03, 0x00, 0x70, 0x00, 0x0a, 0x00, 0x0a, 0x00, 0x76, 0x00, 0x03, 0x00, 0x70, 0x00, 0x0a, 0x00, 0x0a), PHYREGS(0x03d3, 0x03cf, 0x03cb, 0x042f, 0x0434, 0x0438), }, { .freq = 2442, RADIOREGS3(0x00, 0x01, 0x03, 0x09, 0x8a, 0x08, 0x08, 0x04, 0x16, 0x01, 0x05, 0x05, 0x05, 0x8f, 0x30, 0x00, 0x00, 0x00, 0x45, 0x00, 0x02, 0x00, 0x70, 0x00, 0x0a, 0x00, 0x0a, 0x00, 0x66, 0x00, 0x02, 0x00, 0x70, 0x00, 0x0a, 0x00, 0x0a), PHYREGS(0x03d5, 0x03d1, 0x03cd, 0x042d, 0x0431, 0x0436), }, { .freq = 2447, RADIOREGS3(0x00, 0x01, 0x03, 0x09, 0x8f, 0x08, 0x08, 0x04, 0x16, 0x01, 0x06, 0x06, 0x06, 0x8f, 0x30, 0x00, 0x00, 0x00, 0x34, 0x00, 0x02, 0x00, 0x70, 0x00, 0x0a, 0x00, 0x09, 0x00, 0x55, 0x00, 0x02, 0x00, 0x70, 0x00, 0x0a, 0x00, 0x09), PHYREGS(0x03d7, 0x03d3, 0x03cf, 0x042b, 0x042f, 0x0434), }, { .freq = 2452, RADIOREGS3(0x00, 0x01, 0x03, 0x09, 0x94, 0x08, 0x08, 0x04, 0x16, 0x01, 0x06, 0x06, 0x06, 0x8f, 0x30, 0x00, 0x00, 0x00, 0x23, 0x00, 0x02, 0x00, 0x70, 0x00, 0x0a, 0x00, 0x09, 0x00, 0x45, 0x00, 0x02, 0x00, 0x70, 0x00, 0x0a, 0x00, 0x09), PHYREGS(0x03d9, 0x03d5, 0x03d1, 0x0429, 0x042d, 0x0431), }, { .freq = 2457, RADIOREGS3(0x00, 0x01, 0x03, 0x09, 0x99, 0x08, 0x08, 0x04, 0x16, 0x01, 0x06, 0x06, 0x06, 0x8f, 0x30, 0x00, 0x00, 0x00, 0x12, 0x00, 0x02, 0x00, 0x70, 0x00, 0x0a, 0x00, 0x09, 0x00, 0x34, 0x00, 0x02, 0x00, 0x70, 0x00, 0x0a, 0x00, 0x09), PHYREGS(0x03db, 0x03d7, 0x03d3, 0x0427, 0x042b, 0x042f), }, { .freq = 2462, RADIOREGS3(0x00, 0x01, 0x03, 0x09, 0x9e, 0x08, 0x08, 0x04, 0x16, 0x01, 0x06, 0x06, 0x06, 0x8f, 0x30, 0x00, 0x00, 0x00, 0x02, 0x00, 0x02, 0x00, 0x70, 0x00, 0x09, 0x00, 0x09, 0x00, 0x33, 0x00, 0x02, 0x00, 0x70, 0x00, 0x09, 0x00, 0x09), PHYREGS(0x03dd, 0x03d9, 0x03d5, 0x0424, 0x0429, 0x042d), }, { .freq = 2467, RADIOREGS3(0x00, 0x01, 0x03, 0x09, 0xa3, 0x08, 0x08, 0x04, 0x16, 0x01, 0x06, 0x06, 0x06, 0x8f, 0x30, 0x00, 0x00, 0x00, 0x01, 0x00, 0x02, 0x00, 0x70, 0x00, 0x09, 0x00, 0x09, 0x00, 0x22, 0x00, 0x02, 0x00, 0x70, 0x00, 0x09, 0x00, 0x09), PHYREGS(0x03df, 0x03db, 0x03d7, 0x0422, 0x0427, 0x042b), }, { .freq = 2472, RADIOREGS3(0x00, 0x01, 0x03, 0x09, 0xa8, 0x08, 0x08, 0x04, 0x16, 0x01, 0x07, 0x07, 0x07, 0x8f, 0x30, 0x00, 0x00, 0x00, 0x01, 0x00, 0x02, 0x00, 0x70, 0x00, 0x09, 0x00, 0x09, 0x00, 0x11, 0x00, 0x02, 0x00, 0x70, 0x00, 0x09, 0x00, 0x09), PHYREGS(0x03e1, 0x03dd, 0x03d9, 0x0420, 0x0424, 0x0429), }, { .freq = 2484, RADIOREGS3(0xff, 0x01, 0x03, 0x09, 0xb4, 0x08, 0x08, 0x04, 0x16, 0x01, 0x07, 0x07, 0x07, 0x8f, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x70, 0x00, 0x09, 0x00, 0x09, 0x00, 0x00, 0x00, 0x02, 0x00, 0x70, 0x00, 0x09, 0x00, 0x09), PHYREGS(0x03e6, 0x03e2, 0x03de, 0x041b, 0x041f, 0x0424), }, }; static const struct b43_nphy_channeltab_entry_rev3 b43_nphy_channeltab_radio_rev11[] = { { .freq = 4920, RADIOREGS3(0xff, 0x01, 0x01, 0x01, 0xec, 0x05, 0x05, 0x02, 0x0c, 0x01, 0x00, 0x00, 0x00, 0x8f, 0x0f, 0x00, 0xff, 0xfe, 0x00, 0x09, 0x00, 0x77, 0x00, 0x0f, 0x00, 0x6f, 0x00, 0xfe, 0x00, 0x09, 0x00, 0x77, 0x00, 0x0f, 0x00, 0x6f, 0x00), PHYREGS(0x07b4, 0x07b0, 0x07ac, 0x0214, 0x0215, 0x0216), }, { .freq = 4930, RADIOREGS3(0xff, 0x01, 0x01, 0x01, 0xed, 0x05, 0x05, 0x02, 0x0c, 0x01, 0x00, 0x00, 0x00, 0x8f, 0x0f, 0x00, 0xff, 0xfe, 0x00, 0x09, 0x00, 0x77, 0x00, 0x0f, 0x00, 0x6f, 0x00, 0xfe, 0x00, 0x09, 0x00, 0x77, 0x00, 0x0f, 0x00, 0x6f, 0x00), PHYREGS(0x07b8, 0x07b4, 0x07b0, 0x0213, 0x0214, 0x0215), }, { .freq = 4940, RADIOREGS3(0xff, 0x01, 0x01, 0x01, 0xee, 0x05, 0x05, 0x02, 0x0c, 0x01, 0x00, 0x00, 0x00, 0x8f, 0x0f, 0x00, 0xff, 0xfe, 0x00, 0x09, 0x00, 0x77, 0x00, 0x0f, 0x00, 0x6f, 0x00, 0xfe, 0x00, 0x09, 0x00, 0x77, 0x00, 0x0f, 0x00, 0x6f, 0x00), PHYREGS(0x07bc, 0x07b8, 0x07b4, 0x0212, 0x0213, 0x0214), }, { .freq = 4950, RADIOREGS3(0xff, 0x01, 0x01, 0x01, 0xef, 0x05, 0x05, 0x02, 0x0c, 0x01, 0x00, 0x00, 0x00, 0x8f, 0x0f, 0x00, 0xff, 0xfe, 0x00, 0x09, 0x00, 0x77, 0x00, 0x0f, 0x00, 0x6f, 0x00, 0xfe, 0x00, 0x09, 0x00, 0x77, 0x00, 0x0f, 0x00, 0x6f, 0x00), PHYREGS(0x07c0, 0x07bc, 0x07b8, 0x0211, 0x0212, 0x0213), }, { .freq = 4960, RADIOREGS3(0xff, 0x01, 0x01, 0x01, 0xf0, 0x05, 0x05, 0x02, 0x0c, 0x01, 0x01, 0x01, 0x01, 0x8f, 0x0f, 0x00, 0xff, 0xfe, 0x00, 0x09, 0x00, 0x77, 0x00, 0x0f, 0x00, 0x6f, 0x00, 0xfe, 0x00, 0x09, 0x00, 0x77, 0x00, 0x0f, 0x00, 0x6f, 0x00), PHYREGS(0x07c4, 0x07c0, 0x07bc, 0x020f, 0x0211, 0x0212), }, { .freq = 4970, RADIOREGS3(0xff, 0x01, 0x01, 0x01, 0xf1, 0x05, 0x05, 0x02, 0x0c, 0x01, 0x01, 0x01, 0x01, 0x8f, 0x0f, 0x00, 0xff, 0xfe, 0x00, 0x09, 0x00, 0x77, 0x00, 0x0f, 0x00, 0x6f, 0x00, 0xfe, 0x00, 0x09, 0x00, 0x77, 0x00, 0x0f, 0x00, 0x6f, 0x00), PHYREGS(0x07c8, 0x07c4, 0x07c0, 0x020e, 0x020f, 0x0211), }, { .freq = 4980, RADIOREGS3(0xff, 0x01, 0x01, 0x01, 0xf2, 0x05, 0x05, 0x02, 0x0c, 0x01, 0x01, 0x01, 0x01, 0x8f, 0x0f, 0x00, 0xff, 0xfe, 0x00, 0x09, 0x00, 0x77, 0x00, 0x0f, 0x00, 0x6f, 0x00, 0xfe, 0x00, 0x09, 0x00, 0x77, 0x00, 0x0f, 0x00, 0x6f, 0x00), PHYREGS(0x07cc, 0x07c8, 0x07c4, 0x020d, 0x020e, 0x020f), }, { .freq = 4990, RADIOREGS3(0xff, 0x01, 0x01, 0x01, 0xf3, 0x05, 0x05, 0x02, 0x0c, 0x01, 0x01, 0x01, 0x01, 0x8f, 0x0f, 0x00, 0xff, 0xfe, 0x00, 0x09, 0x00, 0x77, 0x00, 0x0f, 0x00, 0x6f, 0x00, 0xfe, 0x00, 0x09, 0x00, 0x77, 0x00, 0x0f, 0x00, 0x6f, 0x00), PHYREGS(0x07d0, 0x07cc, 0x07c8, 0x020c, 0x020d, 0x020e), }, { .freq = 5000, RADIOREGS3(0xff, 0x01, 0x01, 0x01, 0xf4, 0x05, 0x05, 0x02, 0x0c, 0x01, 0x01, 0x01, 0x01, 0x8f, 0x0f, 0x00, 0xff, 0xfe, 0x00, 0x09, 0x00, 0x77, 0x00, 0x0f, 0x00, 0x6f, 0x00, 0xfe, 0x00, 0x09, 0x00, 0x77, 0x00, 0x0f, 0x00, 0x6f, 0x00), PHYREGS(0x07d4, 0x07d0, 0x07cc, 0x020b, 0x020c, 0x020d), }, { .freq = 5010, RADIOREGS3(0xff, 0x01, 0x01, 0x01, 0xf5, 0x05, 0x05, 0x02, 0x0c, 0x01, 0x01, 0x01, 0x01, 0x8f, 0x0f, 0x00, 0xff, 0xfe, 0x00, 0x09, 0x00, 0x77, 0x00, 0x0f, 0x00, 0x6f, 0x00, 0xfe, 0x00, 0x09, 0x00, 0x77, 0x00, 0x0f, 0x00, 0x6f, 0x00), PHYREGS(0x07d8, 0x07d4, 0x07d0, 0x020a, 0x020b, 0x020c), }, { .freq = 5020, RADIOREGS3(0xf7, 0x01, 0x01, 0x01, 0xf6, 0x05, 0x05, 0x02, 0x0c, 0x01, 0x01, 0x01, 0x01, 0x8f, 0x0f, 0x00, 0xff, 0xfe, 0x00, 0x09, 0x00, 0x77, 0x00, 0x0f, 0x00, 0x6f, 0x00, 0xfe, 0x00, 0x09, 0x00, 0x77, 0x00, 0x0f, 0x00, 0x6f, 0x00), PHYREGS(0x07dc, 0x07d8, 0x07d4, 0x0209, 0x020a, 0x020b), }, { .freq = 5030, RADIOREGS3(0xf7, 0x01, 0x01, 0x01, 0xf7, 0x05, 0x05, 0x02, 0x0c, 0x01, 0x01, 0x01, 0x01, 0x8f, 0x0f, 0x00, 0xff, 0xfe, 0x00, 0x09, 0x00, 0x77, 0x00, 0x0f, 0x00, 0x6f, 0x00, 0xfe, 0x00, 0x09, 0x00, 0x77, 0x00, 0x0f, 0x00, 0x6f, 0x00), PHYREGS(0x07e0, 0x07dc, 0x07d8, 0x0208, 0x0209, 0x020a), }, { .freq = 5040, RADIOREGS3(0xef, 0x01, 0x01, 0x01, 0xf8, 0x05, 0x05, 0x02, 0x0c, 0x01, 0x01, 0x01, 0x01, 0x8f, 0x0f, 0x00, 0xff, 0xfe, 0x00, 0x09, 0x00, 0x77, 0x00, 0x0f, 0x00, 0x6f, 0x00, 0xfe, 0x00, 0x09, 0x00, 0x77, 0x00, 0x0f, 0x00, 0x6f, 0x00), PHYREGS(0x07e4, 0x07e0, 0x07dc, 0x0207, 0x0208, 0x0209), }, { .freq = 5050, RADIOREGS3(0xef, 0x01, 0x01, 0x01, 0xf9, 0x05, 0x05, 0x02, 0x0c, 0x01, 0x01, 0x01, 0x01, 0x8f, 0x0f, 0x00, 0xff, 0xfe, 0x00, 0x09, 0x00, 0x77, 0x00, 0x0f, 0x00, 0x6f, 0x00, 0xfe, 0x00, 0x09, 0x00, 0x77, 0x00, 0x0f, 0x00, 0x6f, 0x00), PHYREGS(0x07e8, 0x07e4, 0x07e0, 0x0206, 0x0207, 0x0208), }, { .freq = 5060, RADIOREGS3(0xe6, 0x01, 0x01, 0x01, 0xfa, 0x05, 0x05, 0x02, 0x0c, 0x01, 0x01, 0x01, 0x01, 0x8f, 0x0f, 0x00, 0xff, 0xfe, 0x00, 0x09, 0x00, 0x77, 0x00, 0x0f, 0x00, 0x6f, 0x00, 0xfe, 0x00, 0x09, 0x00, 0x77, 0x00, 0x0f, 0x00, 0x6f, 0x00), PHYREGS(0x07ec, 0x07e8, 0x07e4, 0x0205, 0x0206, 0x0207), }, { .freq = 5070, RADIOREGS3(0xe6, 0x01, 0x01, 0x01, 0xfb, 0x05, 0x05, 0x02, 0x0c, 0x01, 0x01, 0x01, 0x01, 0x8f, 0x0f, 0x00, 0xff, 0xfd, 0x00, 0x09, 0x00, 0x77, 0x00, 0x0f, 0x00, 0x6f, 0x00, 0xfd, 0x00, 0x09, 0x00, 0x77, 0x00, 0x0f, 0x00, 0x6f, 0x00), PHYREGS(0x07f0, 0x07ec, 0x07e8, 0x0204, 0x0205, 0x0206), }, { .freq = 5080, RADIOREGS3(0xde, 0x01, 0x01, 0x01, 0xfc, 0x05, 0x05, 0x02, 0x0c, 0x01, 0x01, 0x01, 0x01, 0x8f, 0x0f, 0x00, 0xff, 0xfd, 0x00, 0x09, 0x00, 0x77, 0x00, 0x0f, 0x00, 0x6f, 0x00, 0xfd, 0x00, 0x09, 0x00, 0x77, 0x00, 0x0f, 0x00, 0x6f, 0x00), PHYREGS(0x07f4, 0x07f0, 0x07ec, 0x0203, 0x0204, 0x0205), }, { .freq = 5090, RADIOREGS3(0xde, 0x01, 0x01, 0x01, 0xfd, 0x05, 0x05, 0x02, 0x0c, 0x01, 0x01, 0x01, 0x01, 0x8f, 0x0f, 0x00, 0xff, 0xfd, 0x00, 0x09, 0x00, 0x77, 0x00, 0x0f, 0x00, 0x6f, 0x00, 0xfd, 0x00, 0x09, 0x00, 0x77, 0x00, 0x0f, 0x00, 0x6f, 0x00), PHYREGS(0x07f8, 0x07f4, 0x07f0, 0x0202, 0x0203, 0x0204), }, { .freq = 5100, RADIOREGS3(0xd6, 0x01, 0x01, 0x01, 0xfe, 0x05, 0x05, 0x02, 0x0c, 0x01, 0x02, 0x02, 0x02, 0x8f, 0x0f, 0x00, 0xff, 0xfd, 0x00, 0x08, 0x00, 0x77, 0x00, 0x0f, 0x00, 0x6f, 0x00, 0xfd, 0x00, 0x08, 0x00, 0x77, 0x00, 0x0f, 0x00, 0x6f, 0x00), PHYREGS(0x07fc, 0x07f8, 0x07f4, 0x0201, 0x0202, 0x0203), }, { .freq = 5110, RADIOREGS3(0xd6, 0x01, 0x01, 0x01, 0xff, 0x05, 0x05, 0x02, 0x0c, 0x01, 0x02, 0x02, 0x02, 0x8f, 0x0f, 0x00, 0xff, 0xfc, 0x00, 0x08, 0x00, 0x77, 0x00, 0x0f, 0x00, 0x6f, 0x00, 0xfc, 0x00, 0x08, 0x00, 0x77, 0x00, 0x0f, 0x00, 0x6f, 0x00), PHYREGS(0x0800, 0x07fc, 0x07f8, 0x0200, 0x0201, 0x0202), }, { .freq = 5120, RADIOREGS3(0xce, 0x01, 0x01, 0x02, 0x00, 0x05, 0x05, 0x02, 0x0c, 0x01, 0x02, 0x02, 0x02, 0x8f, 0x0f, 0x00, 0xff, 0xfc, 0x00, 0x08, 0x00, 0x77, 0x00, 0x0f, 0x00, 0x6f, 0x00, 0xfc, 0x00, 0x08, 0x00, 0x77, 0x00, 0x0f, 0x00, 0x6f, 0x00), PHYREGS(0x0804, 0x0800, 0x07fc, 0x01ff, 0x0200, 0x0201), }, { .freq = 5130, RADIOREGS3(0xce, 0x01, 0x01, 0x02, 0x01, 0x05, 0x05, 0x02, 0x0c, 0x01, 0x02, 0x02, 0x02, 0x8f, 0x0f, 0x00, 0xff, 0xfc, 0x00, 0x08, 0x00, 0x77, 0x00, 0x0f, 0x00, 0x6f, 0x00, 0xfc, 0x00, 0x08, 0x00, 0x77, 0x00, 0x0f, 0x00, 0x6f, 0x00), PHYREGS(0x0808, 0x0804, 0x0800, 0x01fe, 0x01ff, 0x0200), }, { .freq = 5140, RADIOREGS3(0xc6, 0x01, 0x01, 0x02, 0x02, 0x05, 0x05, 0x02, 0x0c, 0x01, 0x02, 0x02, 0x02, 0x8f, 0x0f, 0x00, 0xff, 0xfb, 0x00, 0x08, 0x00, 0x77, 0x00, 0x0f, 0x00, 0x6f, 0x00, 0xfb, 0x00, 0x08, 0x00, 0x77, 0x00, 0x0f, 0x00, 0x6f, 0x00), PHYREGS(0x080c, 0x0808, 0x0804, 0x01fd, 0x01fe, 0x01ff), }, { .freq = 5160, RADIOREGS3(0xbe, 0x01, 0x01, 0x02, 0x04, 0x05, 0x05, 0x02, 0x0c, 0x01, 0x02, 0x02, 0x02, 0x8f, 0x0f, 0x00, 0xff, 0xfa, 0x00, 0x07, 0x00, 0x77, 0x00, 0x0e, 0x00, 0x6f, 0x00, 0xfa, 0x00, 0x07, 0x00, 0x77, 0x00, 0x0e, 0x00, 0x6f, 0x00), PHYREGS(0x0814, 0x0810, 0x080c, 0x01fb, 0x01fc, 0x01fd), }, { .freq = 5170, RADIOREGS3(0xbe, 0x01, 0x01, 0x02, 0x05, 0x05, 0x05, 0x02, 0x0c, 0x01, 0x02, 0x02, 0x02, 0x8f, 0x0f, 0x00, 0xff, 0xfa, 0x00, 0x07, 0x00, 0x77, 0x00, 0x0e, 0x00, 0x6f, 0x00, 0xfa, 0x00, 0x07, 0x00, 0x77, 0x00, 0x0e, 0x00, 0x6f, 0x00), PHYREGS(0x0818, 0x0814, 0x0810, 0x01fa, 0x01fb, 0x01fc), }, { .freq = 5180, RADIOREGS3(0xb6, 0x01, 0x01, 0x02, 0x06, 0x05, 0x05, 0x02, 0x0c, 0x01, 0x02, 0x02, 0x02, 0x8f, 0x0f, 0x00, 0xff, 0xf9, 0x00, 0x06, 0x00, 0x77, 0x00, 0x0e, 0x00, 0x6f, 0x00, 0xf9, 0x00, 0x06, 0x00, 0x77, 0x00, 0x0e, 0x00, 0x6f, 0x00), PHYREGS(0x081c, 0x0818, 0x0814, 0x01f9, 0x01fa, 0x01fb), }, { .freq = 5190, RADIOREGS3(0xb6, 0x01, 0x01, 0x02, 0x07, 0x05, 0x05, 0x02, 0x0c, 0x01, 0x02, 0x02, 0x02, 0x8f, 0x0f, 0x00, 0xff, 0xf9, 0x00, 0x06, 0x00, 0x77, 0x00, 0x0d, 0x00, 0x6f, 0x00, 0xf9, 0x00, 0x06, 0x00, 0x77, 0x00, 0x0d, 0x00, 0x6f, 0x00), PHYREGS(0x0820, 0x081c, 0x0818, 0x01f8, 0x01f9, 0x01fa), }, { .freq = 5200, RADIOREGS3(0xaf, 0x01, 0x01, 0x02, 0x08, 0x05, 0x05, 0x02, 0x0c, 0x01, 0x02, 0x02, 0x02, 0x8f, 0x0f, 0x00, 0xff, 0xf9, 0x00, 0x05, 0x00, 0x77, 0x00, 0x0d, 0x00, 0x6f, 0x00, 0xf9, 0x00, 0x05, 0x00, 0x77, 0x00, 0x0d, 0x00, 0x6f, 0x00), PHYREGS(0x0824, 0x0820, 0x081c, 0x01f7, 0x01f8, 0x01f9), }, { .freq = 5210, RADIOREGS3(0xaf, 0x01, 0x01, 0x02, 0x09, 0x05, 0x05, 0x02, 0x0c, 0x01, 0x02, 0x02, 0x02, 0x8f, 0x0f, 0x00, 0xff, 0xf9, 0x00, 0x05, 0x00, 0x77, 0x00, 0x0d, 0x00, 0x6f, 0x00, 0xf9, 0x00, 0x05, 0x00, 0x77, 0x00, 0x0d, 0x00, 0x6f, 0x00), PHYREGS(0x0828, 0x0824, 0x0820, 0x01f6, 0x01f7, 0x01f8), }, { .freq = 5220, RADIOREGS3(0xa7, 0x01, 0x01, 0x02, 0x0a, 0x05, 0x05, 0x02, 0x0c, 0x01, 0x02, 0x02, 0x02, 0x8e, 0x0f, 0x00, 0xfe, 0xd8, 0x00, 0x05, 0x00, 0x77, 0x00, 0x0d, 0x00, 0x6f, 0x00, 0xd8, 0x00, 0x05, 0x00, 0x77, 0x00, 0x0d, 0x00, 0x6f, 0x00), PHYREGS(0x082c, 0x0828, 0x0824, 0x01f5, 0x01f6, 0x01f7), }, { .freq = 5230, RADIOREGS3(0xa7, 0x01, 0x01, 0x02, 0x0b, 0x05, 0x05, 0x02, 0x0c, 0x01, 0x02, 0x02, 0x02, 0x8e, 0x0f, 0x00, 0xee, 0xd8, 0x00, 0x05, 0x00, 0x77, 0x00, 0x0d, 0x00, 0x6f, 0x00, 0xd8, 0x00, 0x05, 0x00, 0x77, 0x00, 0x0d, 0x00, 0x6f, 0x00), PHYREGS(0x0830, 0x082c, 0x0828, 0x01f4, 0x01f5, 0x01f6), }, { .freq = 5240, RADIOREGS3(0xa0, 0x01, 0x01, 0x02, 0x0c, 0x05, 0x05, 0x02, 0x0c, 0x01, 0x02, 0x02, 0x02, 0x8e, 0x0f, 0x00, 0xee, 0xc8, 0x00, 0x05, 0x00, 0x77, 0x00, 0x0d, 0x00, 0x6f, 0x00, 0xc8, 0x00, 0x05, 0x00, 0x77, 0x00, 0x0d, 0x00, 0x6f, 0x00), PHYREGS(0x0834, 0x0830, 0x082c, 0x01f3, 0x01f4, 0x01f5), }, { .freq = 5250, RADIOREGS3(0xa0, 0x01, 0x01, 0x02, 0x0d, 0x05, 0x05, 0x02, 0x0c, 0x01, 0x02, 0x02, 0x02, 0x8e, 0x0f, 0x00, 0xed, 0xc7, 0x00, 0x05, 0x00, 0x77, 0x00, 0x0d, 0x00, 0x6f, 0x00, 0xc7, 0x00, 0x05, 0x00, 0x77, 0x00, 0x0d, 0x00, 0x6f, 0x00), PHYREGS(0x0838, 0x0834, 0x0830, 0x01f2, 0x01f3, 0x01f4), }, { .freq = 5260, RADIOREGS3(0x98, 0x01, 0x01, 0x02, 0x0e, 0x05, 0x05, 0x02, 0x0c, 0x01, 0x02, 0x02, 0x02, 0x8e, 0x0e, 0x00, 0xed, 0xc7, 0x00, 0x04, 0x00, 0x77, 0x00, 0x0d, 0x00, 0x6f, 0x00, 0xc7, 0x00, 0x04, 0x00, 0x77, 0x00, 0x0d, 0x00, 0x6f, 0x00), PHYREGS(0x083c, 0x0838, 0x0834, 0x01f1, 0x01f2, 0x01f3), }, { .freq = 5270, RADIOREGS3(0x98, 0x01, 0x01, 0x02, 0x0f, 0x05, 0x05, 0x02, 0x0c, 0x01, 0x03, 0x03, 0x03, 0x8e, 0x0e, 0x00, 0xed, 0xc7, 0x00, 0x04, 0x00, 0x77, 0x00, 0x0c, 0x00, 0x6f, 0x00, 0xc7, 0x00, 0x04, 0x00, 0x77, 0x00, 0x0c, 0x00, 0x6f, 0x00), PHYREGS(0x0840, 0x083c, 0x0838, 0x01f0, 0x01f1, 0x01f2), }, { .freq = 5280, RADIOREGS3(0x91, 0x01, 0x01, 0x02, 0x10, 0x05, 0x05, 0x02, 0x0c, 0x01, 0x03, 0x03, 0x03, 0x8d, 0x0e, 0x00, 0xdc, 0xb7, 0x00, 0x03, 0x00, 0x77, 0x00, 0x0c, 0x00, 0x6f, 0x00, 0xb7, 0x00, 0x03, 0x00, 0x77, 0x00, 0x0c, 0x00, 0x6f, 0x00), PHYREGS(0x0844, 0x0840, 0x083c, 0x01f0, 0x01f0, 0x01f1), }, { .freq = 5290, RADIOREGS3(0x91, 0x01, 0x01, 0x02, 0x11, 0x05, 0x05, 0x02, 0x0c, 0x01, 0x03, 0x03, 0x03, 0x8d, 0x0e, 0x00, 0xdc, 0xb7, 0x00, 0x03, 0x00, 0x77, 0x00, 0x0c, 0x00, 0x6f, 0x00, 0xb7, 0x00, 0x03, 0x00, 0x77, 0x00, 0x0c, 0x00, 0x6f, 0x00), PHYREGS(0x0848, 0x0844, 0x0840, 0x01ef, 0x01f0, 0x01f0), }, { .freq = 5300, RADIOREGS3(0x8a, 0x01, 0x01, 0x02, 0x12, 0x05, 0x05, 0x02, 0x0c, 0x01, 0x03, 0x03, 0x03, 0x8d, 0x0e, 0x00, 0xdc, 0xb7, 0x00, 0x03, 0x00, 0x77, 0x00, 0x0c, 0x00, 0x6f, 0x00, 0xb7, 0x00, 0x03, 0x00, 0x77, 0x00, 0x0c, 0x00, 0x6f, 0x00), PHYREGS(0x084c, 0x0848, 0x0844, 0x01ee, 0x01ef, 0x01f0), }, { .freq = 5310, RADIOREGS3(0x8a, 0x01, 0x01, 0x02, 0x13, 0x05, 0x05, 0x02, 0x0c, 0x01, 0x03, 0x03, 0x03, 0x8d, 0x0e, 0x00, 0xdc, 0xb7, 0x00, 0x03, 0x00, 0x77, 0x00, 0x0c, 0x00, 0x6f, 0x00, 0xb7, 0x00, 0x03, 0x00, 0x77, 0x00, 0x0c, 0x00, 0x6f, 0x00), PHYREGS(0x0850, 0x084c, 0x0848, 0x01ed, 0x01ee, 0x01ef), }, { .freq = 5320, RADIOREGS3(0x83, 0x01, 0x01, 0x02, 0x14, 0x05, 0x05, 0x02, 0x0c, 0x01, 0x03, 0x03, 0x03, 0x8d, 0x0e, 0x00, 0xdb, 0xb7, 0x00, 0x03, 0x00, 0x77, 0x00, 0x0c, 0x00, 0x6f, 0x00, 0xb7, 0x00, 0x03, 0x00, 0x77, 0x00, 0x0c, 0x00, 0x6f, 0x00), PHYREGS(0x0854, 0x0850, 0x084c, 0x01ec, 0x01ed, 0x01ee), }, { .freq = 5330, RADIOREGS3(0x83, 0x01, 0x01, 0x02, 0x15, 0x05, 0x05, 0x02, 0x0c, 0x01, 0x03, 0x03, 0x03, 0x8d, 0x0d, 0x00, 0xcb, 0xa6, 0x00, 0x03, 0x00, 0x77, 0x00, 0x0b, 0x00, 0x6f, 0x00, 0xa6, 0x00, 0x03, 0x00, 0x77, 0x00, 0x0b, 0x00, 0x6f, 0x00), PHYREGS(0x0858, 0x0854, 0x0850, 0x01eb, 0x01ec, 0x01ed), }, { .freq = 5340, RADIOREGS3(0x7c, 0x01, 0x01, 0x02, 0x16, 0x05, 0x05, 0x02, 0x0c, 0x01, 0x03, 0x03, 0x03, 0x8d, 0x0d, 0x00, 0xca, 0xa6, 0x00, 0x03, 0x00, 0x77, 0x00, 0x0b, 0x00, 0x6f, 0x00, 0xa6, 0x00, 0x03, 0x00, 0x77, 0x00, 0x0b, 0x00, 0x6f, 0x00), PHYREGS(0x085c, 0x0858, 0x0854, 0x01ea, 0x01eb, 0x01ec), }, { .freq = 5350, RADIOREGS3(0x7c, 0x01, 0x01, 0x02, 0x17, 0x05, 0x05, 0x02, 0x0c, 0x01, 0x03, 0x03, 0x03, 0x8c, 0x0d, 0x00, 0xca, 0xa6, 0x00, 0x03, 0x00, 0x77, 0x00, 0x0b, 0x00, 0x6f, 0x00, 0xa6, 0x00, 0x03, 0x00, 0x77, 0x00, 0x0b, 0x00, 0x6f, 0x00), PHYREGS(0x0860, 0x085c, 0x0858, 0x01e9, 0x01ea, 0x01eb), }, { .freq = 5360, RADIOREGS3(0x75, 0x01, 0x01, 0x02, 0x18, 0x05, 0x05, 0x02, 0x0c, 0x01, 0x03, 0x03, 0x03, 0x8c, 0x0d, 0x00, 0xc9, 0x95, 0x00, 0x03, 0x00, 0x77, 0x00, 0x0a, 0x00, 0x6f, 0x00, 0x95, 0x00, 0x03, 0x00, 0x77, 0x00, 0x0a, 0x00, 0x6f, 0x00), PHYREGS(0x0864, 0x0860, 0x085c, 0x01e8, 0x01e9, 0x01ea), }, { .freq = 5370, RADIOREGS3(0x75, 0x01, 0x01, 0x02, 0x19, 0x05, 0x05, 0x02, 0x0c, 0x01, 0x03, 0x03, 0x03, 0x8c, 0x0d, 0x00, 0xc9, 0x95, 0x00, 0x03, 0x00, 0x77, 0x00, 0x0a, 0x00, 0x6f, 0x00, 0x95, 0x00, 0x03, 0x00, 0x77, 0x00, 0x0a, 0x00, 0x6f, 0x00), PHYREGS(0x0868, 0x0864, 0x0860, 0x01e7, 0x01e8, 0x01e9), }, { .freq = 5380, RADIOREGS3(0x6e, 0x01, 0x01, 0x02, 0x1a, 0x05, 0x05, 0x02, 0x0c, 0x01, 0x03, 0x03, 0x03, 0x8c, 0x0c, 0x00, 0xb8, 0x95, 0x00, 0x03, 0x00, 0x77, 0x00, 0x0a, 0x00, 0x6f, 0x00, 0x95, 0x00, 0x03, 0x00, 0x77, 0x00, 0x0a, 0x00, 0x6f, 0x00), PHYREGS(0x086c, 0x0868, 0x0864, 0x01e6, 0x01e7, 0x01e8), }, { .freq = 5390, RADIOREGS3(0x6e, 0x01, 0x01, 0x02, 0x1b, 0x05, 0x05, 0x02, 0x0c, 0x01, 0x03, 0x03, 0x03, 0x8c, 0x0c, 0x00, 0xb8, 0x84, 0x00, 0x03, 0x00, 0x77, 0x00, 0x0a, 0x00, 0x6f, 0x00, 0x84, 0x00, 0x03, 0x00, 0x77, 0x00, 0x0a, 0x00, 0x6f, 0x00), PHYREGS(0x0870, 0x086c, 0x0868, 0x01e5, 0x01e6, 0x01e7), }, { .freq = 5400, RADIOREGS3(0x67, 0x01, 0x01, 0x02, 0x1c, 0x05, 0x05, 0x02, 0x0c, 0x01, 0x03, 0x03, 0x03, 0x8c, 0x0c, 0x00, 0xb8, 0x84, 0x00, 0x03, 0x00, 0x77, 0x00, 0x0a, 0x00, 0x6f, 0x00, 0x84, 0x00, 0x03, 0x00, 0x77, 0x00, 0x0a, 0x00, 0x6f, 0x00), PHYREGS(0x0874, 0x0870, 0x086c, 0x01e5, 0x01e5, 0x01e6), }, { .freq = 5410, RADIOREGS3(0x67, 0x01, 0x01, 0x02, 0x1d, 0x05, 0x05, 0x02, 0x0c, 0x01, 0x03, 0x03, 0x03, 0x8c, 0x0c, 0x00, 0xb7, 0x84, 0x00, 0x02, 0x00, 0x77, 0x00, 0x0a, 0x00, 0x6f, 0x00, 0x84, 0x00, 0x02, 0x00, 0x77, 0x00, 0x0a, 0x00, 0x6f, 0x00), PHYREGS(0x0878, 0x0874, 0x0870, 0x01e4, 0x01e5, 0x01e5), }, { .freq = 5420, RADIOREGS3(0x61, 0x01, 0x01, 0x02, 0x1e, 0x05, 0x05, 0x02, 0x0c, 0x01, 0x03, 0x03, 0x03, 0x8c, 0x0c, 0x00, 0xa7, 0x84, 0x00, 0x02, 0x00, 0x77, 0x00, 0x0a, 0x00, 0x6f, 0x00, 0x84, 0x00, 0x02, 0x00, 0x77, 0x00, 0x0a, 0x00, 0x6f, 0x00), PHYREGS(0x087c, 0x0878, 0x0874, 0x01e3, 0x01e4, 0x01e5), }, { .freq = 5430, RADIOREGS3(0x61, 0x01, 0x01, 0x02, 0x1f, 0x05, 0x05, 0x02, 0x0c, 0x01, 0x03, 0x03, 0x03, 0x8c, 0x0b, 0x00, 0xa6, 0x84, 0x00, 0x02, 0x00, 0x77, 0x00, 0x0a, 0x00, 0x6f, 0x00, 0x84, 0x00, 0x02, 0x00, 0x77, 0x00, 0x0a, 0x00, 0x6f, 0x00), PHYREGS(0x0880, 0x087c, 0x0878, 0x01e2, 0x01e3, 0x01e4), }, { .freq = 5440, RADIOREGS3(0x5a, 0x01, 0x01, 0x02, 0x20, 0x05, 0x05, 0x02, 0x0c, 0x01, 0x04, 0x04, 0x04, 0x8b, 0x0b, 0x00, 0xa6, 0x84, 0x00, 0x02, 0x00, 0x77, 0x00, 0x09, 0x00, 0x6f, 0x00, 0x84, 0x00, 0x02, 0x00, 0x77, 0x00, 0x09, 0x00, 0x6f, 0x00), PHYREGS(0x0884, 0x0880, 0x087c, 0x01e1, 0x01e2, 0x01e3), }, { .freq = 5450, RADIOREGS3(0x5a, 0x01, 0x01, 0x02, 0x21, 0x05, 0x05, 0x02, 0x0c, 0x01, 0x04, 0x04, 0x04, 0x8b, 0x0b, 0x00, 0x95, 0x84, 0x00, 0x01, 0x00, 0x77, 0x00, 0x09, 0x00, 0x6f, 0x00, 0x84, 0x00, 0x01, 0x00, 0x77, 0x00, 0x09, 0x00, 0x6f, 0x00), PHYREGS(0x0888, 0x0884, 0x0880, 0x01e0, 0x01e1, 0x01e2), }, { .freq = 5460, RADIOREGS3(0x53, 0x01, 0x01, 0x02, 0x22, 0x05, 0x05, 0x02, 0x0c, 0x01, 0x04, 0x04, 0x04, 0x8b, 0x0b, 0x00, 0x95, 0x84, 0x00, 0x01, 0x00, 0x77, 0x00, 0x09, 0x00, 0x6f, 0x00, 0x84, 0x00, 0x01, 0x00, 0x77, 0x00, 0x09, 0x00, 0x6f, 0x00), PHYREGS(0x088c, 0x0888, 0x0884, 0x01df, 0x01e0, 0x01e1), }, { .freq = 5470, RADIOREGS3(0x53, 0x01, 0x01, 0x02, 0x23, 0x05, 0x05, 0x02, 0x0c, 0x01, 0x04, 0x04, 0x04, 0x8b, 0x0b, 0x00, 0x94, 0x73, 0x00, 0x01, 0x00, 0x77, 0x00, 0x09, 0x00, 0x6f, 0x00, 0x73, 0x00, 0x01, 0x00, 0x77, 0x00, 0x09, 0x00, 0x6f, 0x00), PHYREGS(0x0890, 0x088c, 0x0888, 0x01de, 0x01df, 0x01e0), }, { .freq = 5480, RADIOREGS3(0x4d, 0x01, 0x01, 0x02, 0x24, 0x05, 0x05, 0x02, 0x0c, 0x01, 0x04, 0x04, 0x04, 0x8a, 0x0a, 0x00, 0x84, 0x73, 0x00, 0x00, 0x00, 0x77, 0x00, 0x09, 0x00, 0x6f, 0x00, 0x73, 0x00, 0x00, 0x00, 0x77, 0x00, 0x09, 0x00, 0x6f, 0x00), PHYREGS(0x0894, 0x0890, 0x088c, 0x01dd, 0x01de, 0x01df), }, { .freq = 5490, RADIOREGS3(0x4d, 0x01, 0x01, 0x02, 0x25, 0x05, 0x05, 0x02, 0x0c, 0x01, 0x04, 0x04, 0x04, 0x8a, 0x0a, 0x00, 0x83, 0x73, 0x00, 0x00, 0x00, 0x77, 0x00, 0x09, 0x00, 0x6f, 0x00, 0x73, 0x00, 0x00, 0x00, 0x77, 0x00, 0x09, 0x00, 0x6f, 0x00), PHYREGS(0x0898, 0x0894, 0x0890, 0x01dd, 0x01dd, 0x01de), }, { .freq = 5500, RADIOREGS3(0x47, 0x01, 0x01, 0x02, 0x26, 0x05, 0x05, 0x02, 0x0c, 0x01, 0x04, 0x04, 0x04, 0x8a, 0x0a, 0x00, 0x82, 0x73, 0x00, 0x00, 0x00, 0x77, 0x00, 0x09, 0x00, 0x6f, 0x00, 0x73, 0x00, 0x00, 0x00, 0x77, 0x00, 0x09, 0x00, 0x6f, 0x00), PHYREGS(0x089c, 0x0898, 0x0894, 0x01dc, 0x01dd, 0x01dd), }, { .freq = 5510, RADIOREGS3(0x47, 0x01, 0x01, 0x02, 0x27, 0x05, 0x05, 0x02, 0x0c, 0x01, 0x04, 0x04, 0x04, 0x8a, 0x0a, 0x00, 0x82, 0x73, 0x00, 0x00, 0x00, 0x77, 0x00, 0x09, 0x00, 0x6f, 0x00, 0x73, 0x00, 0x00, 0x00, 0x77, 0x00, 0x09, 0x00, 0x6f, 0x00), PHYREGS(0x08a0, 0x089c, 0x0898, 0x01db, 0x01dc, 0x01dd), }, { .freq = 5520, RADIOREGS3(0x40, 0x01, 0x01, 0x02, 0x28, 0x05, 0x05, 0x02, 0x0c, 0x01, 0x04, 0x04, 0x04, 0x8a, 0x0a, 0x00, 0x72, 0x73, 0x00, 0x00, 0x00, 0x77, 0x00, 0x09, 0x00, 0x6f, 0x00, 0x73, 0x00, 0x00, 0x00, 0x77, 0x00, 0x09, 0x00, 0x6f, 0x00), PHYREGS(0x08a4, 0x08a0, 0x089c, 0x01da, 0x01db, 0x01dc), }, { .freq = 5530, RADIOREGS3(0x40, 0x01, 0x01, 0x02, 0x29, 0x05, 0x05, 0x02, 0x0c, 0x01, 0x04, 0x04, 0x04, 0x8a, 0x09, 0x00, 0x72, 0x73, 0x00, 0x00, 0x00, 0x77, 0x00, 0x09, 0x00, 0x6f, 0x00, 0x73, 0x00, 0x00, 0x00, 0x77, 0x00, 0x09, 0x00, 0x6f, 0x00), PHYREGS(0x08a8, 0x08a4, 0x08a0, 0x01d9, 0x01da, 0x01db), }, { .freq = 5540, RADIOREGS3(0x3a, 0x01, 0x01, 0x02, 0x2a, 0x05, 0x05, 0x02, 0x0c, 0x01, 0x04, 0x04, 0x04, 0x8a, 0x09, 0x00, 0x71, 0x73, 0x00, 0x00, 0x00, 0x77, 0x00, 0x09, 0x00, 0x6f, 0x00, 0x73, 0x00, 0x00, 0x00, 0x77, 0x00, 0x09, 0x00, 0x6f, 0x00), PHYREGS(0x08ac, 0x08a8, 0x08a4, 0x01d8, 0x01d9, 0x01da), }, { .freq = 5550, RADIOREGS3(0x3a, 0x01, 0x01, 0x02, 0x2b, 0x05, 0x05, 0x02, 0x0c, 0x01, 0x04, 0x04, 0x04, 0x89, 0x09, 0x00, 0x61, 0x73, 0x00, 0x00, 0x00, 0x77, 0x00, 0x09, 0x00, 0x6f, 0x00, 0x73, 0x00, 0x00, 0x00, 0x77, 0x00, 0x09, 0x00, 0x6f, 0x00), PHYREGS(0x08b0, 0x08ac, 0x08a8, 0x01d7, 0x01d8, 0x01d9), }, { .freq = 5560, RADIOREGS3(0x34, 0x01, 0x01, 0x02, 0x2c, 0x05, 0x05, 0x02, 0x0c, 0x01, 0x04, 0x04, 0x04, 0x89, 0x09, 0x00, 0x61, 0x73, 0x00, 0x00, 0x00, 0x77, 0x00, 0x09, 0x00, 0x6f, 0x00, 0x73, 0x00, 0x00, 0x00, 0x77, 0x00, 0x09, 0x00, 0x6f, 0x00), PHYREGS(0x08b4, 0x08b0, 0x08ac, 0x01d7, 0x01d7, 0x01d8), }, { .freq = 5570, RADIOREGS3(0x34, 0x01, 0x01, 0x02, 0x2d, 0x05, 0x05, 0x02, 0x0c, 0x01, 0x04, 0x04, 0x04, 0x89, 0x09, 0x00, 0x61, 0x62, 0x00, 0x00, 0x00, 0x77, 0x00, 0x09, 0x00, 0x6f, 0x00, 0x62, 0x00, 0x00, 0x00, 0x77, 0x00, 0x09, 0x00, 0x6f, 0x00), PHYREGS(0x08b8, 0x08b4, 0x08b0, 0x01d6, 0x01d7, 0x01d7), }, { .freq = 5580, RADIOREGS3(0x2e, 0x01, 0x01, 0x02, 0x2e, 0x05, 0x05, 0x02, 0x0c, 0x01, 0x04, 0x04, 0x04, 0x89, 0x08, 0x00, 0x60, 0x62, 0x00, 0x00, 0x00, 0x77, 0x00, 0x08, 0x00, 0x6f, 0x00, 0x62, 0x00, 0x00, 0x00, 0x77, 0x00, 0x08, 0x00, 0x6f, 0x00), PHYREGS(0x08bc, 0x08b8, 0x08b4, 0x01d5, 0x01d6, 0x01d7), }, { .freq = 5590, RADIOREGS3(0x2e, 0x01, 0x01, 0x02, 0x2f, 0x05, 0x05, 0x02, 0x0c, 0x01, 0x04, 0x04, 0x04, 0x89, 0x08, 0x00, 0x50, 0x61, 0x00, 0x00, 0x00, 0x77, 0x00, 0x08, 0x00, 0x6f, 0x00, 0x61, 0x00, 0x00, 0x00, 0x77, 0x00, 0x08, 0x00, 0x6f, 0x00), PHYREGS(0x08c0, 0x08bc, 0x08b8, 0x01d4, 0x01d5, 0x01d6), }, { .freq = 5600, RADIOREGS3(0x28, 0x01, 0x01, 0x02, 0x30, 0x05, 0x05, 0x02, 0x0c, 0x01, 0x05, 0x05, 0x05, 0x89, 0x08, 0x00, 0x50, 0x51, 0x00, 0x00, 0x00, 0x77, 0x00, 0x08, 0x00, 0x6f, 0x00, 0x51, 0x00, 0x00, 0x00, 0x77, 0x00, 0x08, 0x00, 0x6f, 0x00), PHYREGS(0x08c4, 0x08c0, 0x08bc, 0x01d3, 0x01d4, 0x01d5), }, { .freq = 5610, RADIOREGS3(0x28, 0x01, 0x01, 0x02, 0x31, 0x05, 0x05, 0x02, 0x0c, 0x01, 0x05, 0x05, 0x05, 0x89, 0x08, 0x00, 0x50, 0x51, 0x00, 0x00, 0x00, 0x77, 0x00, 0x08, 0x00, 0x6f, 0x00, 0x51, 0x00, 0x00, 0x00, 0x77, 0x00, 0x08, 0x00, 0x6f, 0x00), PHYREGS(0x08c8, 0x08c4, 0x08c0, 0x01d2, 0x01d3, 0x01d4), }, { .freq = 5620, RADIOREGS3(0x21, 0x01, 0x01, 0x02, 0x32, 0x05, 0x05, 0x02, 0x0c, 0x01, 0x05, 0x05, 0x05, 0x89, 0x08, 0x00, 0x50, 0x50, 0x00, 0x00, 0x00, 0x77, 0x00, 0x07, 0x00, 0x6f, 0x00, 0x50, 0x00, 0x00, 0x00, 0x77, 0x00, 0x07, 0x00, 0x6f, 0x00), PHYREGS(0x08cc, 0x08c8, 0x08c4, 0x01d2, 0x01d2, 0x01d3), }, { .freq = 5630, RADIOREGS3(0x21, 0x01, 0x01, 0x02, 0x33, 0x05, 0x05, 0x02, 0x0c, 0x01, 0x05, 0x05, 0x05, 0x88, 0x07, 0x00, 0x50, 0x50, 0x00, 0x00, 0x00, 0x77, 0x00, 0x07, 0x00, 0x6f, 0x00, 0x50, 0x00, 0x00, 0x00, 0x77, 0x00, 0x07, 0x00, 0x6f, 0x00), PHYREGS(0x08d0, 0x08cc, 0x08c8, 0x01d1, 0x01d2, 0x01d2), }, { .freq = 5640, RADIOREGS3(0x1c, 0x01, 0x01, 0x02, 0x34, 0x05, 0x05, 0x02, 0x0c, 0x01, 0x05, 0x05, 0x05, 0x88, 0x07, 0x00, 0x40, 0x50, 0x00, 0x00, 0x00, 0x77, 0x00, 0x07, 0x00, 0x6f, 0x00, 0x50, 0x00, 0x00, 0x00, 0x77, 0x00, 0x07, 0x00, 0x6f, 0x00), PHYREGS(0x08d4, 0x08d0, 0x08cc, 0x01d0, 0x01d1, 0x01d2), }, { .freq = 5650, RADIOREGS3(0x1c, 0x01, 0x01, 0x02, 0x35, 0x05, 0x05, 0x02, 0x0c, 0x01, 0x05, 0x05, 0x05, 0x88, 0x07, 0x00, 0x40, 0x40, 0x00, 0x00, 0x00, 0x77, 0x00, 0x07, 0x00, 0x6f, 0x00, 0x40, 0x00, 0x00, 0x00, 0x77, 0x00, 0x07, 0x00, 0x6f, 0x00), PHYREGS(0x08d8, 0x08d4, 0x08d0, 0x01cf, 0x01d0, 0x01d1), }, { .freq = 5660, RADIOREGS3(0x16, 0x01, 0x01, 0x02, 0x36, 0x05, 0x05, 0x02, 0x0c, 0x01, 0x05, 0x05, 0x05, 0x88, 0x07, 0x00, 0x40, 0x40, 0x00, 0x00, 0x00, 0x77, 0x00, 0x06, 0x00, 0x6f, 0x00, 0x40, 0x00, 0x00, 0x00, 0x77, 0x00, 0x06, 0x00, 0x6f, 0x00), PHYREGS(0x08dc, 0x08d8, 0x08d4, 0x01ce, 0x01cf, 0x01d0), }, { .freq = 5670, RADIOREGS3(0x16, 0x01, 0x01, 0x02, 0x37, 0x05, 0x05, 0x02, 0x0c, 0x01, 0x05, 0x05, 0x05, 0x88, 0x07, 0x00, 0x40, 0x30, 0x00, 0x00, 0x00, 0x77, 0x00, 0x06, 0x00, 0x6f, 0x00, 0x30, 0x00, 0x00, 0x00, 0x77, 0x00, 0x06, 0x00, 0x6f, 0x00), PHYREGS(0x08e0, 0x08dc, 0x08d8, 0x01ce, 0x01ce, 0x01cf), }, { .freq = 5680, RADIOREGS3(0x10, 0x01, 0x01, 0x02, 0x38, 0x05, 0x05, 0x02, 0x0c, 0x01, 0x05, 0x05, 0x05, 0x87, 0x06, 0x00, 0x30, 0x30, 0x00, 0x00, 0x00, 0x77, 0x00, 0x06, 0x00, 0x6f, 0x00, 0x30, 0x00, 0x00, 0x00, 0x77, 0x00, 0x06, 0x00, 0x6f, 0x00), PHYREGS(0x08e4, 0x08e0, 0x08dc, 0x01cd, 0x01ce, 0x01ce), }, { .freq = 5690, RADIOREGS3(0x10, 0x01, 0x01, 0x02, 0x39, 0x05, 0x05, 0x02, 0x0c, 0x01, 0x05, 0x05, 0x05, 0x87, 0x06, 0x00, 0x30, 0x30, 0x00, 0x00, 0x00, 0x77, 0x00, 0x06, 0x00, 0x6f, 0x00, 0x30, 0x00, 0x00, 0x00, 0x77, 0x00, 0x06, 0x00, 0x6f, 0x00), PHYREGS(0x08e8, 0x08e4, 0x08e0, 0x01cc, 0x01cd, 0x01ce), }, { .freq = 5700, RADIOREGS3(0x0a, 0x01, 0x01, 0x02, 0x3a, 0x05, 0x05, 0x02, 0x0c, 0x01, 0x05, 0x05, 0x05, 0x87, 0x06, 0x00, 0x30, 0x30, 0x00, 0x00, 0x00, 0x77, 0x00, 0x06, 0x00, 0x6e, 0x00, 0x30, 0x00, 0x00, 0x00, 0x77, 0x00, 0x06, 0x00, 0x6e, 0x00), PHYREGS(0x08ec, 0x08e8, 0x08e4, 0x01cb, 0x01cc, 0x01cd), }, { .freq = 5710, RADIOREGS3(0x0a, 0x01, 0x01, 0x02, 0x3b, 0x05, 0x05, 0x02, 0x0c, 0x01, 0x05, 0x05, 0x05, 0x87, 0x06, 0x00, 0x30, 0x30, 0x00, 0x00, 0x00, 0x77, 0x00, 0x06, 0x00, 0x6e, 0x00, 0x30, 0x00, 0x00, 0x00, 0x77, 0x00, 0x06, 0x00, 0x6e, 0x00), PHYREGS(0x08f0, 0x08ec, 0x08e8, 0x01ca, 0x01cb, 0x01cc), }, { .freq = 5720, RADIOREGS3(0x0a, 0x01, 0x01, 0x02, 0x3c, 0x05, 0x05, 0x02, 0x0c, 0x01, 0x05, 0x05, 0x05, 0x87, 0x06, 0x00, 0x30, 0x30, 0x00, 0x00, 0x00, 0x77, 0x00, 0x06, 0x00, 0x6e, 0x00, 0x30, 0x00, 0x00, 0x00, 0x77, 0x00, 0x06, 0x00, 0x6e, 0x00), PHYREGS(0x08f4, 0x08f0, 0x08ec, 0x01c9, 0x01ca, 0x01cb), }, { .freq = 5725, RADIOREGS3(0x03, 0x01, 0x02, 0x04, 0x79, 0x05, 0x05, 0x02, 0x15, 0x01, 0x05, 0x05, 0x05, 0x87, 0x06, 0x00, 0x30, 0x30, 0x00, 0x00, 0x00, 0x77, 0x00, 0x06, 0x00, 0x6e, 0x00, 0x30, 0x00, 0x00, 0x00, 0x77, 0x00, 0x06, 0x00, 0x6e, 0x00), PHYREGS(0x08f6, 0x08f2, 0x08ee, 0x01c9, 0x01ca, 0x01cb), }, { .freq = 5730, RADIOREGS3(0x0a, 0x01, 0x01, 0x02, 0x3d, 0x05, 0x05, 0x02, 0x0c, 0x01, 0x05, 0x05, 0x05, 0x87, 0x05, 0x00, 0x20, 0x30, 0x00, 0x00, 0x00, 0x77, 0x00, 0x06, 0x00, 0x6e, 0x00, 0x30, 0x00, 0x00, 0x00, 0x77, 0x00, 0x06, 0x00, 0x6e, 0x00), PHYREGS(0x08f8, 0x08f4, 0x08f0, 0x01c9, 0x01c9, 0x01ca), }, { .freq = 5735, RADIOREGS3(0x03, 0x01, 0x02, 0x04, 0x7b, 0x05, 0x05, 0x02, 0x15, 0x01, 0x05, 0x05, 0x05, 0x87, 0x05, 0x00, 0x20, 0x30, 0x00, 0x00, 0x00, 0x77, 0x00, 0x06, 0x00, 0x6d, 0x00, 0x30, 0x00, 0x00, 0x00, 0x77, 0x00, 0x06, 0x00, 0x6d, 0x00), PHYREGS(0x08fa, 0x08f6, 0x08f2, 0x01c8, 0x01c9, 0x01ca), }, { .freq = 5740, RADIOREGS3(0x0a, 0x01, 0x01, 0x02, 0x3e, 0x05, 0x05, 0x02, 0x0c, 0x01, 0x05, 0x05, 0x05, 0x87, 0x05, 0x00, 0x20, 0x30, 0x00, 0x00, 0x00, 0x77, 0x00, 0x06, 0x00, 0x6d, 0x00, 0x30, 0x00, 0x00, 0x00, 0x77, 0x00, 0x06, 0x00, 0x6d, 0x00), PHYREGS(0x08fc, 0x08f8, 0x08f4, 0x01c8, 0x01c9, 0x01c9), }, { .freq = 5745, RADIOREGS3(0xfe, 0x00, 0x02, 0x04, 0x7d, 0x05, 0x05, 0x02, 0x15, 0x01, 0x05, 0x05, 0x05, 0x87, 0x05, 0x00, 0x20, 0x30, 0x00, 0x00, 0x00, 0x77, 0x00, 0x06, 0x00, 0x6d, 0x00, 0x30, 0x00, 0x00, 0x00, 0x77, 0x00, 0x06, 0x00, 0x6d, 0x00), PHYREGS(0x08fe, 0x08fa, 0x08f6, 0x01c8, 0x01c8, 0x01c9), }, { .freq = 5750, RADIOREGS3(0x0a, 0x01, 0x01, 0x02, 0x3f, 0x05, 0x05, 0x02, 0x0c, 0x01, 0x05, 0x05, 0x05, 0x87, 0x05, 0x00, 0x20, 0x20, 0x00, 0x00, 0x00, 0x77, 0x00, 0x05, 0x00, 0x6d, 0x00, 0x20, 0x00, 0x00, 0x00, 0x77, 0x00, 0x05, 0x00, 0x6d, 0x00), PHYREGS(0x0900, 0x08fc, 0x08f8, 0x01c7, 0x01c8, 0x01c9), }, { .freq = 5755, RADIOREGS3(0xfe, 0x00, 0x02, 0x04, 0x7f, 0x05, 0x05, 0x02, 0x15, 0x01, 0x05, 0x05, 0x05, 0x87, 0x05, 0x00, 0x10, 0x20, 0x00, 0x00, 0x00, 0x77, 0x00, 0x05, 0x00, 0x6c, 0x00, 0x20, 0x00, 0x00, 0x00, 0x77, 0x00, 0x05, 0x00, 0x6c, 0x00), PHYREGS(0x0902, 0x08fe, 0x08fa, 0x01c7, 0x01c8, 0x01c8), }, { .freq = 5760, RADIOREGS3(0x0a, 0x01, 0x01, 0x02, 0x40, 0x05, 0x05, 0x02, 0x0c, 0x01, 0x05, 0x05, 0x05, 0x86, 0x05, 0x00, 0x10, 0x20, 0x00, 0x00, 0x00, 0x77, 0x00, 0x05, 0x00, 0x6c, 0x00, 0x20, 0x00, 0x00, 0x00, 0x77, 0x00, 0x05, 0x00, 0x6c, 0x00), PHYREGS(0x0904, 0x0900, 0x08fc, 0x01c6, 0x01c7, 0x01c8), }, { .freq = 5765, RADIOREGS3(0xf8, 0x00, 0x02, 0x04, 0x81, 0x05, 0x05, 0x02, 0x15, 0x01, 0x05, 0x05, 0x05, 0x86, 0x05, 0x00, 0x10, 0x10, 0x00, 0x00, 0x00, 0x77, 0x00, 0x05, 0x00, 0x6c, 0x00, 0x10, 0x00, 0x00, 0x00, 0x77, 0x00, 0x05, 0x00, 0x6c, 0x00), PHYREGS(0x0906, 0x0902, 0x08fe, 0x01c6, 0x01c7, 0x01c8), }, { .freq = 5770, RADIOREGS3(0x0a, 0x01, 0x01, 0x02, 0x41, 0x05, 0x05, 0x02, 0x0c, 0x01, 0x05, 0x05, 0x05, 0x86, 0x04, 0x00, 0x10, 0x10, 0x00, 0x00, 0x00, 0x77, 0x00, 0x05, 0x00, 0x6b, 0x00, 0x10, 0x00, 0x00, 0x00, 0x77, 0x00, 0x05, 0x00, 0x6b, 0x00), PHYREGS(0x0908, 0x0904, 0x0900, 0x01c6, 0x01c6, 0x01c7), }, { .freq = 5775, RADIOREGS3(0xf8, 0x00, 0x02, 0x04, 0x83, 0x05, 0x05, 0x02, 0x15, 0x01, 0x05, 0x05, 0x05, 0x86, 0x04, 0x00, 0x10, 0x10, 0x00, 0x00, 0x00, 0x77, 0x00, 0x05, 0x00, 0x6b, 0x00, 0x10, 0x00, 0x00, 0x00, 0x77, 0x00, 0x05, 0x00, 0x6b, 0x00), PHYREGS(0x090a, 0x0906, 0x0902, 0x01c5, 0x01c6, 0x01c7), }, { .freq = 5780, RADIOREGS3(0x0a, 0x01, 0x01, 0x02, 0x42, 0x05, 0x05, 0x02, 0x0c, 0x01, 0x05, 0x05, 0x05, 0x86, 0x04, 0x00, 0x10, 0x10, 0x00, 0x00, 0x00, 0x77, 0x00, 0x05, 0x00, 0x6b, 0x00, 0x10, 0x00, 0x00, 0x00, 0x77, 0x00, 0x05, 0x00, 0x6b, 0x00), PHYREGS(0x090c, 0x0908, 0x0904, 0x01c5, 0x01c6, 0x01c6), }, { .freq = 5785, RADIOREGS3(0xf2, 0x00, 0x02, 0x04, 0x85, 0x05, 0x05, 0x02, 0x15, 0x01, 0x06, 0x06, 0x06, 0x86, 0x04, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x77, 0x00, 0x05, 0x00, 0x6b, 0x00, 0x10, 0x00, 0x00, 0x00, 0x77, 0x00, 0x05, 0x00, 0x6b, 0x00), PHYREGS(0x090e, 0x090a, 0x0906, 0x01c4, 0x01c5, 0x01c6), }, { .freq = 5790, RADIOREGS3(0x0a, 0x01, 0x01, 0x02, 0x43, 0x05, 0x05, 0x02, 0x0c, 0x01, 0x06, 0x06, 0x06, 0x86, 0x04, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x77, 0x00, 0x05, 0x00, 0x6b, 0x00, 0x10, 0x00, 0x00, 0x00, 0x77, 0x00, 0x05, 0x00, 0x6b, 0x00), PHYREGS(0x0910, 0x090c, 0x0908, 0x01c4, 0x01c5, 0x01c6), }, { .freq = 5795, RADIOREGS3(0xf2, 0x00, 0x02, 0x04, 0x87, 0x05, 0x05, 0x02, 0x15, 0x01, 0x06, 0x06, 0x06, 0x86, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x77, 0x00, 0x05, 0x00, 0x6b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x77, 0x00, 0x05, 0x00, 0x6b, 0x00), PHYREGS(0x0912, 0x090e, 0x090a, 0x01c4, 0x01c4, 0x01c5), }, { .freq = 5800, RADIOREGS3(0x0a, 0x01, 0x01, 0x02, 0x44, 0x05, 0x05, 0x02, 0x0c, 0x01, 0x06, 0x06, 0x06, 0x86, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x77, 0x00, 0x05, 0x00, 0x6b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x77, 0x00, 0x05, 0x00, 0x6b, 0x00), PHYREGS(0x0914, 0x0910, 0x090c, 0x01c3, 0x01c4, 0x01c5), }, { .freq = 5805, RADIOREGS3(0xed, 0x00, 0x02, 0x04, 0x89, 0x05, 0x05, 0x02, 0x15, 0x01, 0x06, 0x06, 0x06, 0x86, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x77, 0x00, 0x05, 0x00, 0x6a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x77, 0x00, 0x05, 0x00, 0x6a, 0x00), PHYREGS(0x0916, 0x0912, 0x090e, 0x01c3, 0x01c4, 0x01c4), }, { .freq = 5810, RADIOREGS3(0x0a, 0x01, 0x01, 0x02, 0x45, 0x05, 0x05, 0x02, 0x0c, 0x01, 0x06, 0x06, 0x06, 0x86, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x77, 0x00, 0x05, 0x00, 0x6a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x77, 0x00, 0x05, 0x00, 0x6a, 0x00), PHYREGS(0x0918, 0x0914, 0x0910, 0x01c2, 0x01c3, 0x01c4), }, { .freq = 5815, RADIOREGS3(0xed, 0x00, 0x02, 0x04, 0x8b, 0x05, 0x05, 0x02, 0x15, 0x01, 0x06, 0x06, 0x06, 0x86, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x77, 0x00, 0x05, 0x00, 0x6a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x77, 0x00, 0x05, 0x00, 0x6a, 0x00), PHYREGS(0x091a, 0x0916, 0x0912, 0x01c2, 0x01c3, 0x01c4), }, { .freq = 5820, RADIOREGS3(0x0a, 0x01, 0x01, 0x02, 0x46, 0x05, 0x05, 0x02, 0x0c, 0x01, 0x06, 0x06, 0x06, 0x86, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x77, 0x00, 0x05, 0x00, 0x6a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x77, 0x00, 0x05, 0x00, 0x6a, 0x00), PHYREGS(0x091c, 0x0918, 0x0914, 0x01c2, 0x01c2, 0x01c3), }, { .freq = 5825, RADIOREGS3(0xed, 0x00, 0x02, 0x04, 0x8d, 0x05, 0x05, 0x02, 0x15, 0x01, 0x06, 0x06, 0x06, 0x86, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x77, 0x00, 0x05, 0x00, 0x69, 0x00, 0x00, 0x00, 0x00, 0x00, 0x77, 0x00, 0x05, 0x00, 0x69, 0x00), PHYREGS(0x091e, 0x091a, 0x0916, 0x01c1, 0x01c2, 0x01c3), }, { .freq = 5830, RADIOREGS3(0x0a, 0x01, 0x01, 0x02, 0x47, 0x05, 0x05, 0x02, 0x0c, 0x01, 0x06, 0x06, 0x06, 0x86, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x77, 0x00, 0x05, 0x00, 0x69, 0x00, 0x00, 0x00, 0x00, 0x00, 0x77, 0x00, 0x05, 0x00, 0x69, 0x00), PHYREGS(0x0920, 0x091c, 0x0918, 0x01c1, 0x01c2, 0x01c2), }, { .freq = 5840, RADIOREGS3(0x0a, 0x01, 0x01, 0x02, 0x48, 0x05, 0x05, 0x02, 0x0c, 0x01, 0x06, 0x06, 0x06, 0x86, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x77, 0x00, 0x04, 0x00, 0x69, 0x00, 0x00, 0x00, 0x00, 0x00, 0x77, 0x00, 0x04, 0x00, 0x69, 0x00), PHYREGS(0x0924, 0x0920, 0x091c, 0x01c0, 0x01c1, 0x01c2), }, { .freq = 5850, RADIOREGS3(0xe0, 0x00, 0x01, 0x02, 0x49, 0x05, 0x05, 0x02, 0x0c, 0x01, 0x06, 0x06, 0x06, 0x85, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x77, 0x00, 0x04, 0x00, 0x69, 0x00, 0x00, 0x00, 0x00, 0x00, 0x77, 0x00, 0x04, 0x00, 0x69, 0x00), PHYREGS(0x0928, 0x0924, 0x0920, 0x01bf, 0x01c0, 0x01c1), }, { .freq = 5860, RADIOREGS3(0xde, 0x00, 0x01, 0x02, 0x4a, 0x05, 0x05, 0x02, 0x0c, 0x01, 0x06, 0x06, 0x06, 0x85, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x77, 0x00, 0x04, 0x00, 0x69, 0x00, 0x00, 0x00, 0x00, 0x00, 0x77, 0x00, 0x04, 0x00, 0x69, 0x00), PHYREGS(0x092c, 0x0928, 0x0924, 0x01bf, 0x01bf, 0x01c0), }, { .freq = 5870, RADIOREGS3(0xdb, 0x00, 0x01, 0x02, 0x4b, 0x05, 0x05, 0x02, 0x0c, 0x01, 0x06, 0x06, 0x06, 0x85, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x77, 0x00, 0x04, 0x00, 0x68, 0x00, 0x00, 0x00, 0x00, 0x00, 0x77, 0x00, 0x04, 0x00, 0x68, 0x00), PHYREGS(0x0930, 0x092c, 0x0928, 0x01be, 0x01bf, 0x01bf), }, { .freq = 5880, RADIOREGS3(0xd8, 0x00, 0x01, 0x02, 0x4c, 0x05, 0x05, 0x02, 0x0c, 0x01, 0x06, 0x06, 0x06, 0x85, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x77, 0x00, 0x04, 0x00, 0x68, 0x00, 0x00, 0x00, 0x00, 0x00, 0x77, 0x00, 0x04, 0x00, 0x68, 0x00), PHYREGS(0x0934, 0x0930, 0x092c, 0x01bd, 0x01be, 0x01bf), }, { .freq = 5890, RADIOREGS3(0xd6, 0x00, 0x01, 0x02, 0x4d, 0x05, 0x05, 0x02, 0x0c, 0x01, 0x06, 0x06, 0x06, 0x85, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x77, 0x00, 0x04, 0x00, 0x68, 0x00, 0x00, 0x00, 0x00, 0x00, 0x77, 0x00, 0x04, 0x00, 0x68, 0x00), PHYREGS(0x0938, 0x0934, 0x0930, 0x01bc, 0x01bd, 0x01be), }, { .freq = 5900, RADIOREGS3(0xd3, 0x00, 0x01, 0x02, 0x4e, 0x05, 0x05, 0x02, 0x0c, 0x01, 0x06, 0x06, 0x06, 0x85, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x77, 0x00, 0x04, 0x00, 0x68, 0x00, 0x00, 0x00, 0x00, 0x00, 0x77, 0x00, 0x04, 0x00, 0x68, 0x00), PHYREGS(0x093c, 0x0938, 0x0934, 0x01bc, 0x01bc, 0x01bd), }, { .freq = 5910, RADIOREGS3(0xd6, 0x00, 0x01, 0x02, 0x4f, 0x05, 0x05, 0x02, 0x0c, 0x01, 0x06, 0x06, 0x06, 0x85, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x77, 0x00, 0x04, 0x00, 0x68, 0x00, 0x00, 0x00, 0x00, 0x00, 0x77, 0x00, 0x04, 0x00, 0x68, 0x00), PHYREGS(0x0940, 0x093c, 0x0938, 0x01bb, 0x01bc, 0x01bc), }, { .freq = 2412, RADIOREGS3(0x00, 0x01, 0x03, 0x09, 0x6c, 0x06, 0x06, 0x04, 0x2b, 0x01, 0x04, 0x04, 0x04, 0x8f, 0x30, 0x00, 0x00, 0x00, 0x78, 0x00, 0x03, 0x00, 0x70, 0x00, 0x0b, 0x00, 0x0a, 0x00, 0x89, 0x00, 0x03, 0x00, 0x70, 0x00, 0x0b, 0x00, 0x0a), PHYREGS(0x03c9, 0x03c5, 0x03c1, 0x043a, 0x043f, 0x0443), }, { .freq = 2417, RADIOREGS3(0x00, 0x01, 0x03, 0x09, 0x71, 0x06, 0x06, 0x04, 0x2b, 0x01, 0x05, 0x05, 0x05, 0x8f, 0x30, 0x00, 0x00, 0x00, 0x78, 0x00, 0x03, 0x00, 0x70, 0x00, 0x0b, 0x00, 0x0a, 0x00, 0x89, 0x00, 0x03, 0x00, 0x70, 0x00, 0x0b, 0x00, 0x0a), PHYREGS(0x03cb, 0x03c7, 0x03c3, 0x0438, 0x043d, 0x0441), }, { .freq = 2422, RADIOREGS3(0x00, 0x01, 0x03, 0x09, 0x76, 0x06, 0x06, 0x04, 0x2b, 0x01, 0x05, 0x05, 0x05, 0x8f, 0x30, 0x00, 0x00, 0x00, 0x67, 0x00, 0x03, 0x00, 0x70, 0x00, 0x0b, 0x00, 0x0a, 0x00, 0x89, 0x00, 0x03, 0x00, 0x70, 0x00, 0x0b, 0x00, 0x0a), PHYREGS(0x03cd, 0x03c9, 0x03c5, 0x0436, 0x043a, 0x043f), }, { .freq = 2427, RADIOREGS3(0x00, 0x01, 0x03, 0x09, 0x7b, 0x06, 0x06, 0x04, 0x2b, 0x01, 0x05, 0x05, 0x05, 0x8f, 0x30, 0x00, 0x00, 0x00, 0x57, 0x00, 0x03, 0x00, 0x70, 0x00, 0x0a, 0x00, 0x0a, 0x00, 0x78, 0x00, 0x03, 0x00, 0x70, 0x00, 0x0a, 0x00, 0x0a), PHYREGS(0x03cf, 0x03cb, 0x03c7, 0x0434, 0x0438, 0x043d), }, { .freq = 2432, RADIOREGS3(0x00, 0x01, 0x03, 0x09, 0x80, 0x06, 0x06, 0x04, 0x2b, 0x01, 0x05, 0x05, 0x05, 0x8f, 0x30, 0x00, 0x00, 0x00, 0x56, 0x00, 0x03, 0x00, 0x70, 0x00, 0x0a, 0x00, 0x0a, 0x00, 0x77, 0x00, 0x03, 0x00, 0x70, 0x00, 0x0a, 0x00, 0x0a), PHYREGS(0x03d1, 0x03cd, 0x03c9, 0x0431, 0x0436, 0x043a), }, { .freq = 2437, RADIOREGS3(0x00, 0x01, 0x03, 0x09, 0x85, 0x06, 0x06, 0x04, 0x2b, 0x01, 0x05, 0x05, 0x05, 0x8f, 0x30, 0x00, 0x00, 0x00, 0x46, 0x00, 0x03, 0x00, 0x70, 0x00, 0x0a, 0x00, 0x0a, 0x00, 0x76, 0x00, 0x03, 0x00, 0x70, 0x00, 0x0a, 0x00, 0x0a), PHYREGS(0x03d3, 0x03cf, 0x03cb, 0x042f, 0x0434, 0x0438), }, { .freq = 2442, RADIOREGS3(0x00, 0x01, 0x03, 0x09, 0x8a, 0x06, 0x06, 0x04, 0x2b, 0x01, 0x05, 0x05, 0x05, 0x8f, 0x30, 0x00, 0x00, 0x00, 0x45, 0x00, 0x02, 0x00, 0x70, 0x00, 0x0a, 0x00, 0x0a, 0x00, 0x66, 0x00, 0x02, 0x00, 0x70, 0x00, 0x0a, 0x00, 0x0a), PHYREGS(0x03d5, 0x03d1, 0x03cd, 0x042d, 0x0431, 0x0436), }, { .freq = 2447, RADIOREGS3(0x00, 0x01, 0x03, 0x09, 0x8f, 0x06, 0x06, 0x04, 0x2b, 0x01, 0x06, 0x06, 0x06, 0x8f, 0x30, 0x00, 0x00, 0x00, 0x34, 0x00, 0x02, 0x00, 0x70, 0x00, 0x0a, 0x00, 0x09, 0x00, 0x55, 0x00, 0x02, 0x00, 0x70, 0x00, 0x0a, 0x00, 0x09), PHYREGS(0x03d7, 0x03d3, 0x03cf, 0x042b, 0x042f, 0x0434), }, { .freq = 2452, RADIOREGS3(0x00, 0x01, 0x03, 0x09, 0x94, 0x06, 0x06, 0x04, 0x2b, 0x01, 0x06, 0x06, 0x06, 0x8f, 0x30, 0x00, 0x00, 0x00, 0x23, 0x00, 0x02, 0x00, 0x70, 0x00, 0x0a, 0x00, 0x09, 0x00, 0x45, 0x00, 0x02, 0x00, 0x70, 0x00, 0x0a, 0x00, 0x09), PHYREGS(0x03d9, 0x03d5, 0x03d1, 0x0429, 0x042d, 0x0431), }, { .freq = 2457, RADIOREGS3(0x00, 0x01, 0x03, 0x09, 0x99, 0x06, 0x06, 0x04, 0x2b, 0x01, 0x06, 0x06, 0x06, 0x8f, 0x30, 0x00, 0x00, 0x00, 0x12, 0x00, 0x02, 0x00, 0x70, 0x00, 0x0a, 0x00, 0x09, 0x00, 0x34, 0x00, 0x02, 0x00, 0x70, 0x00, 0x0a, 0x00, 0x09), PHYREGS(0x03db, 0x03d7, 0x03d3, 0x0427, 0x042b, 0x042f), }, { .freq = 2462, RADIOREGS3(0x00, 0x01, 0x03, 0x09, 0x9e, 0x06, 0x06, 0x04, 0x2b, 0x01, 0x06, 0x06, 0x06, 0x8f, 0x30, 0x00, 0x00, 0x00, 0x02, 0x00, 0x02, 0x00, 0x70, 0x00, 0x09, 0x00, 0x09, 0x00, 0x33, 0x00, 0x02, 0x00, 0x70, 0x00, 0x09, 0x00, 0x09), PHYREGS(0x03dd, 0x03d9, 0x03d5, 0x0424, 0x0429, 0x042d), }, { .freq = 2467, RADIOREGS3(0x00, 0x01, 0x03, 0x09, 0xa3, 0x06, 0x06, 0x04, 0x2b, 0x01, 0x06, 0x06, 0x06, 0x8f, 0x30, 0x00, 0x00, 0x00, 0x01, 0x00, 0x02, 0x00, 0x70, 0x00, 0x09, 0x00, 0x09, 0x00, 0x22, 0x00, 0x02, 0x00, 0x70, 0x00, 0x09, 0x00, 0x09), PHYREGS(0x03df, 0x03db, 0x03d7, 0x0422, 0x0427, 0x042b), }, { .freq = 2472, RADIOREGS3(0x00, 0x01, 0x03, 0x09, 0xa8, 0x06, 0x06, 0x04, 0x2b, 0x01, 0x07, 0x07, 0x07, 0x8f, 0x30, 0x00, 0x00, 0x00, 0x01, 0x00, 0x02, 0x00, 0x70, 0x00, 0x09, 0x00, 0x09, 0x00, 0x11, 0x00, 0x02, 0x00, 0x70, 0x00, 0x09, 0x00, 0x09), PHYREGS(0x03e1, 0x03dd, 0x03d9, 0x0420, 0x0424, 0x0429), }, { .freq = 2484, RADIOREGS3(0xff, 0x01, 0x03, 0x09, 0xb4, 0x06, 0x06, 0x04, 0x2b, 0x01, 0x07, 0x07, 0x07, 0x8f, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x70, 0x00, 0x09, 0x00, 0x09, 0x00, 0x00, 0x00, 0x02, 0x00, 0x70, 0x00, 0x09, 0x00, 0x09), PHYREGS(0x03e6, 0x03e2, 0x03de, 0x041b, 0x041f, 0x0424), }, }; static const struct b2056_inittabs_pts *b43_nphy_get_inittabs_rev3(struct b43_wldev *dev) { struct b43_phy *phy = &dev->phy; switch (dev->phy.rev) { case 3: return &b2056_inittab_phy_rev3; case 4: return &b2056_inittab_phy_rev4; default: switch (phy->radio_rev) { case 5: return &b2056_inittab_radio_rev5; case 6: return &b2056_inittab_radio_rev6; case 7: case 9: return &b2056_inittab_radio_rev7_9; case 8: return &b2056_inittab_radio_rev8; case 11: return &b2056_inittab_radio_rev11; } } return NULL; } static void b2056_upload_inittab(struct b43_wldev *dev, bool ghz5, bool ignore_uploadflag, u16 routing, const struct b2056_inittab_entry *e, unsigned int length) { unsigned int i; u16 value; for (i = 0; i < length; i++, e++) { if (!(e->flags & B2056_INITTAB_ENTRY_OK)) continue; if ((e->flags & B2056_INITTAB_UPLOAD) || ignore_uploadflag) { if (ghz5) value = e->ghz5; else value = e->ghz2; b43_radio_write(dev, routing | i, value); } } } void b2056_upload_inittabs(struct b43_wldev *dev, bool ghz5, bool ignore_uploadflag) { const struct b2056_inittabs_pts *pts; pts = b43_nphy_get_inittabs_rev3(dev); if (!pts) { B43_WARN_ON(1); return; } b2056_upload_inittab(dev, ghz5, ignore_uploadflag, B2056_SYN, pts->syn, pts->syn_length); b2056_upload_inittab(dev, ghz5, ignore_uploadflag, B2056_TX0, pts->tx, pts->tx_length); b2056_upload_inittab(dev, ghz5, ignore_uploadflag, B2056_TX1, pts->tx, pts->tx_length); b2056_upload_inittab(dev, ghz5, ignore_uploadflag, B2056_RX0, pts->rx, pts->rx_length); b2056_upload_inittab(dev, ghz5, ignore_uploadflag, B2056_RX1, pts->rx, pts->rx_length); } void b2056_upload_syn_pll_cp2(struct b43_wldev *dev, bool ghz5) { const struct b2056_inittabs_pts *pts; const struct b2056_inittab_entry *e; pts = b43_nphy_get_inittabs_rev3(dev); if (!pts) { B43_WARN_ON(1); return; } e = &pts->syn[B2056_SYN_PLL_CP2]; b43_radio_write(dev, B2056_SYN_PLL_CP2, ghz5 ? e->ghz5 : e->ghz2); } const struct b43_nphy_channeltab_entry_rev3 * b43_nphy_get_chantabent_rev3(struct b43_wldev *dev, u16 freq) { struct b43_phy *phy = &dev->phy; const struct b43_nphy_channeltab_entry_rev3 *e; unsigned int length, i; switch (phy->rev) { case 3: e = b43_nphy_channeltab_phy_rev3; length = ARRAY_SIZE(b43_nphy_channeltab_phy_rev3); break; case 4: e = b43_nphy_channeltab_phy_rev4; length = ARRAY_SIZE(b43_nphy_channeltab_phy_rev4); break; default: switch (phy->radio_rev) { case 5: e = b43_nphy_channeltab_radio_rev5; length = ARRAY_SIZE(b43_nphy_channeltab_radio_rev5); break; case 6: e = b43_nphy_channeltab_radio_rev6; length = ARRAY_SIZE(b43_nphy_channeltab_radio_rev6); break; case 7: case 9: e = b43_nphy_channeltab_radio_rev7_9; length = ARRAY_SIZE(b43_nphy_channeltab_radio_rev7_9); break; case 8: e = b43_nphy_channeltab_radio_rev8; length = ARRAY_SIZE(b43_nphy_channeltab_radio_rev8); break; case 11: e = b43_nphy_channeltab_radio_rev11; length = ARRAY_SIZE(b43_nphy_channeltab_radio_rev11); break; default: B43_WARN_ON(1); return NULL; } } for (i = 0; i < length; i++, e++) { if (e->freq == freq) return e; } return NULL; }
gpl-2.0
surdupetru/android_kernel_huawei_msm8916-caf
drivers/gpu/drm/i915/intel_overlay.c
2063
40047
/* * Copyright © 2009 * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. * * Authors: * Daniel Vetter <daniel@ffwll.ch> * * Derived from Xorg ddx, xf86-video-intel, src/i830_video.c */ #include <drm/drmP.h> #include <drm/i915_drm.h> #include "i915_drv.h" #include "i915_reg.h" #include "intel_drv.h" /* Limits for overlay size. According to intel doc, the real limits are: * Y width: 4095, UV width (planar): 2047, Y height: 2047, * UV width (planar): * 1023. But the xorg thinks 2048 for height and width. Use * the mininum of both. */ #define IMAGE_MAX_WIDTH 2048 #define IMAGE_MAX_HEIGHT 2046 /* 2 * 1023 */ /* on 830 and 845 these large limits result in the card hanging */ #define IMAGE_MAX_WIDTH_LEGACY 1024 #define IMAGE_MAX_HEIGHT_LEGACY 1088 /* overlay register definitions */ /* OCMD register */ #define OCMD_TILED_SURFACE (0x1<<19) #define OCMD_MIRROR_MASK (0x3<<17) #define OCMD_MIRROR_MODE (0x3<<17) #define OCMD_MIRROR_HORIZONTAL (0x1<<17) #define OCMD_MIRROR_VERTICAL (0x2<<17) #define OCMD_MIRROR_BOTH (0x3<<17) #define OCMD_BYTEORDER_MASK (0x3<<14) /* zero for YUYV or FOURCC YUY2 */ #define OCMD_UV_SWAP (0x1<<14) /* YVYU */ #define OCMD_Y_SWAP (0x2<<14) /* UYVY or FOURCC UYVY */ #define OCMD_Y_AND_UV_SWAP (0x3<<14) /* VYUY */ #define OCMD_SOURCE_FORMAT_MASK (0xf<<10) #define OCMD_RGB_888 (0x1<<10) /* not in i965 Intel docs */ #define OCMD_RGB_555 (0x2<<10) /* not in i965 Intel docs */ #define OCMD_RGB_565 (0x3<<10) /* not in i965 Intel docs */ #define OCMD_YUV_422_PACKED (0x8<<10) #define OCMD_YUV_411_PACKED (0x9<<10) /* not in i965 Intel docs */ #define OCMD_YUV_420_PLANAR (0xc<<10) #define OCMD_YUV_422_PLANAR (0xd<<10) #define OCMD_YUV_410_PLANAR (0xe<<10) /* also 411 */ #define OCMD_TVSYNCFLIP_PARITY (0x1<<9) #define OCMD_TVSYNCFLIP_ENABLE (0x1<<7) #define OCMD_BUF_TYPE_MASK (0x1<<5) #define OCMD_BUF_TYPE_FRAME (0x0<<5) #define OCMD_BUF_TYPE_FIELD (0x1<<5) #define OCMD_TEST_MODE (0x1<<4) #define OCMD_BUFFER_SELECT (0x3<<2) #define OCMD_BUFFER0 (0x0<<2) #define OCMD_BUFFER1 (0x1<<2) #define OCMD_FIELD_SELECT (0x1<<2) #define OCMD_FIELD0 (0x0<<1) #define OCMD_FIELD1 (0x1<<1) #define OCMD_ENABLE (0x1<<0) /* OCONFIG register */ #define OCONF_PIPE_MASK (0x1<<18) #define OCONF_PIPE_A (0x0<<18) #define OCONF_PIPE_B (0x1<<18) #define OCONF_GAMMA2_ENABLE (0x1<<16) #define OCONF_CSC_MODE_BT601 (0x0<<5) #define OCONF_CSC_MODE_BT709 (0x1<<5) #define OCONF_CSC_BYPASS (0x1<<4) #define OCONF_CC_OUT_8BIT (0x1<<3) #define OCONF_TEST_MODE (0x1<<2) #define OCONF_THREE_LINE_BUFFER (0x1<<0) #define OCONF_TWO_LINE_BUFFER (0x0<<0) /* DCLRKM (dst-key) register */ #define DST_KEY_ENABLE (0x1<<31) #define CLK_RGB24_MASK 0x0 #define CLK_RGB16_MASK 0x070307 #define CLK_RGB15_MASK 0x070707 #define CLK_RGB8I_MASK 0xffffff #define RGB16_TO_COLORKEY(c) \ (((c & 0xF800) << 8) | ((c & 0x07E0) << 5) | ((c & 0x001F) << 3)) #define RGB15_TO_COLORKEY(c) \ (((c & 0x7c00) << 9) | ((c & 0x03E0) << 6) | ((c & 0x001F) << 3)) /* overlay flip addr flag */ #define OFC_UPDATE 0x1 /* polyphase filter coefficients */ #define N_HORIZ_Y_TAPS 5 #define N_VERT_Y_TAPS 3 #define N_HORIZ_UV_TAPS 3 #define N_VERT_UV_TAPS 3 #define N_PHASES 17 #define MAX_TAPS 5 /* memory bufferd overlay registers */ struct overlay_registers { u32 OBUF_0Y; u32 OBUF_1Y; u32 OBUF_0U; u32 OBUF_0V; u32 OBUF_1U; u32 OBUF_1V; u32 OSTRIDE; u32 YRGB_VPH; u32 UV_VPH; u32 HORZ_PH; u32 INIT_PHS; u32 DWINPOS; u32 DWINSZ; u32 SWIDTH; u32 SWIDTHSW; u32 SHEIGHT; u32 YRGBSCALE; u32 UVSCALE; u32 OCLRC0; u32 OCLRC1; u32 DCLRKV; u32 DCLRKM; u32 SCLRKVH; u32 SCLRKVL; u32 SCLRKEN; u32 OCONFIG; u32 OCMD; u32 RESERVED1; /* 0x6C */ u32 OSTART_0Y; u32 OSTART_1Y; u32 OSTART_0U; u32 OSTART_0V; u32 OSTART_1U; u32 OSTART_1V; u32 OTILEOFF_0Y; u32 OTILEOFF_1Y; u32 OTILEOFF_0U; u32 OTILEOFF_0V; u32 OTILEOFF_1U; u32 OTILEOFF_1V; u32 FASTHSCALE; /* 0xA0 */ u32 UVSCALEV; /* 0xA4 */ u32 RESERVEDC[(0x200 - 0xA8) / 4]; /* 0xA8 - 0x1FC */ u16 Y_VCOEFS[N_VERT_Y_TAPS * N_PHASES]; /* 0x200 */ u16 RESERVEDD[0x100 / 2 - N_VERT_Y_TAPS * N_PHASES]; u16 Y_HCOEFS[N_HORIZ_Y_TAPS * N_PHASES]; /* 0x300 */ u16 RESERVEDE[0x200 / 2 - N_HORIZ_Y_TAPS * N_PHASES]; u16 UV_VCOEFS[N_VERT_UV_TAPS * N_PHASES]; /* 0x500 */ u16 RESERVEDF[0x100 / 2 - N_VERT_UV_TAPS * N_PHASES]; u16 UV_HCOEFS[N_HORIZ_UV_TAPS * N_PHASES]; /* 0x600 */ u16 RESERVEDG[0x100 / 2 - N_HORIZ_UV_TAPS * N_PHASES]; }; struct intel_overlay { struct drm_device *dev; struct intel_crtc *crtc; struct drm_i915_gem_object *vid_bo; struct drm_i915_gem_object *old_vid_bo; int active; int pfit_active; u32 pfit_vscale_ratio; /* shifted-point number, (1<<12) == 1.0 */ u32 color_key; u32 brightness, contrast, saturation; u32 old_xscale, old_yscale; /* register access */ u32 flip_addr; struct drm_i915_gem_object *reg_bo; /* flip handling */ uint32_t last_flip_req; void (*flip_tail)(struct intel_overlay *); }; static struct overlay_registers __iomem * intel_overlay_map_regs(struct intel_overlay *overlay) { drm_i915_private_t *dev_priv = overlay->dev->dev_private; struct overlay_registers __iomem *regs; if (OVERLAY_NEEDS_PHYSICAL(overlay->dev)) regs = (struct overlay_registers __iomem *)overlay->reg_bo->phys_obj->handle->vaddr; else regs = io_mapping_map_wc(dev_priv->gtt.mappable, overlay->reg_bo->gtt_offset); return regs; } static void intel_overlay_unmap_regs(struct intel_overlay *overlay, struct overlay_registers __iomem *regs) { if (!OVERLAY_NEEDS_PHYSICAL(overlay->dev)) io_mapping_unmap(regs); } static int intel_overlay_do_wait_request(struct intel_overlay *overlay, void (*tail)(struct intel_overlay *)) { struct drm_device *dev = overlay->dev; drm_i915_private_t *dev_priv = dev->dev_private; struct intel_ring_buffer *ring = &dev_priv->ring[RCS]; int ret; BUG_ON(overlay->last_flip_req); ret = i915_add_request(ring, NULL, &overlay->last_flip_req); if (ret) return ret; overlay->flip_tail = tail; ret = i915_wait_seqno(ring, overlay->last_flip_req); if (ret) return ret; i915_gem_retire_requests(dev); overlay->last_flip_req = 0; return 0; } /* overlay needs to be disable in OCMD reg */ static int intel_overlay_on(struct intel_overlay *overlay) { struct drm_device *dev = overlay->dev; struct drm_i915_private *dev_priv = dev->dev_private; struct intel_ring_buffer *ring = &dev_priv->ring[RCS]; int ret; BUG_ON(overlay->active); overlay->active = 1; WARN_ON(IS_I830(dev) && !(dev_priv->quirks & QUIRK_PIPEA_FORCE)); ret = intel_ring_begin(ring, 4); if (ret) return ret; intel_ring_emit(ring, MI_OVERLAY_FLIP | MI_OVERLAY_ON); intel_ring_emit(ring, overlay->flip_addr | OFC_UPDATE); intel_ring_emit(ring, MI_WAIT_FOR_EVENT | MI_WAIT_FOR_OVERLAY_FLIP); intel_ring_emit(ring, MI_NOOP); intel_ring_advance(ring); return intel_overlay_do_wait_request(overlay, NULL); } /* overlay needs to be enabled in OCMD reg */ static int intel_overlay_continue(struct intel_overlay *overlay, bool load_polyphase_filter) { struct drm_device *dev = overlay->dev; drm_i915_private_t *dev_priv = dev->dev_private; struct intel_ring_buffer *ring = &dev_priv->ring[RCS]; u32 flip_addr = overlay->flip_addr; u32 tmp; int ret; BUG_ON(!overlay->active); if (load_polyphase_filter) flip_addr |= OFC_UPDATE; /* check for underruns */ tmp = I915_READ(DOVSTA); if (tmp & (1 << 17)) DRM_DEBUG("overlay underrun, DOVSTA: %x\n", tmp); ret = intel_ring_begin(ring, 2); if (ret) return ret; intel_ring_emit(ring, MI_OVERLAY_FLIP | MI_OVERLAY_CONTINUE); intel_ring_emit(ring, flip_addr); intel_ring_advance(ring); return i915_add_request(ring, NULL, &overlay->last_flip_req); } static void intel_overlay_release_old_vid_tail(struct intel_overlay *overlay) { struct drm_i915_gem_object *obj = overlay->old_vid_bo; i915_gem_object_unpin(obj); drm_gem_object_unreference(&obj->base); overlay->old_vid_bo = NULL; } static void intel_overlay_off_tail(struct intel_overlay *overlay) { struct drm_i915_gem_object *obj = overlay->vid_bo; /* never have the overlay hw on without showing a frame */ BUG_ON(!overlay->vid_bo); i915_gem_object_unpin(obj); drm_gem_object_unreference(&obj->base); overlay->vid_bo = NULL; overlay->crtc->overlay = NULL; overlay->crtc = NULL; overlay->active = 0; } /* overlay needs to be disabled in OCMD reg */ static int intel_overlay_off(struct intel_overlay *overlay) { struct drm_device *dev = overlay->dev; struct drm_i915_private *dev_priv = dev->dev_private; struct intel_ring_buffer *ring = &dev_priv->ring[RCS]; u32 flip_addr = overlay->flip_addr; int ret; BUG_ON(!overlay->active); /* According to intel docs the overlay hw may hang (when switching * off) without loading the filter coeffs. It is however unclear whether * this applies to the disabling of the overlay or to the switching off * of the hw. Do it in both cases */ flip_addr |= OFC_UPDATE; ret = intel_ring_begin(ring, 6); if (ret) return ret; /* wait for overlay to go idle */ intel_ring_emit(ring, MI_OVERLAY_FLIP | MI_OVERLAY_CONTINUE); intel_ring_emit(ring, flip_addr); intel_ring_emit(ring, MI_WAIT_FOR_EVENT | MI_WAIT_FOR_OVERLAY_FLIP); /* turn overlay off */ if (IS_I830(dev)) { /* Workaround: Don't disable the overlay fully, since otherwise * it dies on the next OVERLAY_ON cmd. */ intel_ring_emit(ring, MI_NOOP); intel_ring_emit(ring, MI_NOOP); intel_ring_emit(ring, MI_NOOP); } else { intel_ring_emit(ring, MI_OVERLAY_FLIP | MI_OVERLAY_OFF); intel_ring_emit(ring, flip_addr); intel_ring_emit(ring, MI_WAIT_FOR_EVENT | MI_WAIT_FOR_OVERLAY_FLIP); } intel_ring_advance(ring); return intel_overlay_do_wait_request(overlay, intel_overlay_off_tail); } /* recover from an interruption due to a signal * We have to be careful not to repeat work forever an make forward progess. */ static int intel_overlay_recover_from_interrupt(struct intel_overlay *overlay) { struct drm_device *dev = overlay->dev; drm_i915_private_t *dev_priv = dev->dev_private; struct intel_ring_buffer *ring = &dev_priv->ring[RCS]; int ret; if (overlay->last_flip_req == 0) return 0; ret = i915_wait_seqno(ring, overlay->last_flip_req); if (ret) return ret; i915_gem_retire_requests(dev); if (overlay->flip_tail) overlay->flip_tail(overlay); overlay->last_flip_req = 0; return 0; } /* Wait for pending overlay flip and release old frame. * Needs to be called before the overlay register are changed * via intel_overlay_(un)map_regs */ static int intel_overlay_release_old_vid(struct intel_overlay *overlay) { struct drm_device *dev = overlay->dev; drm_i915_private_t *dev_priv = dev->dev_private; struct intel_ring_buffer *ring = &dev_priv->ring[RCS]; int ret; /* Only wait if there is actually an old frame to release to * guarantee forward progress. */ if (!overlay->old_vid_bo) return 0; if (I915_READ(ISR) & I915_OVERLAY_PLANE_FLIP_PENDING_INTERRUPT) { /* synchronous slowpath */ ret = intel_ring_begin(ring, 2); if (ret) return ret; intel_ring_emit(ring, MI_WAIT_FOR_EVENT | MI_WAIT_FOR_OVERLAY_FLIP); intel_ring_emit(ring, MI_NOOP); intel_ring_advance(ring); ret = intel_overlay_do_wait_request(overlay, intel_overlay_release_old_vid_tail); if (ret) return ret; } intel_overlay_release_old_vid_tail(overlay); return 0; } struct put_image_params { int format; short dst_x; short dst_y; short dst_w; short dst_h; short src_w; short src_scan_h; short src_scan_w; short src_h; short stride_Y; short stride_UV; int offset_Y; int offset_U; int offset_V; }; static int packed_depth_bytes(u32 format) { switch (format & I915_OVERLAY_DEPTH_MASK) { case I915_OVERLAY_YUV422: return 4; case I915_OVERLAY_YUV411: /* return 6; not implemented */ default: return -EINVAL; } } static int packed_width_bytes(u32 format, short width) { switch (format & I915_OVERLAY_DEPTH_MASK) { case I915_OVERLAY_YUV422: return width << 1; default: return -EINVAL; } } static int uv_hsubsampling(u32 format) { switch (format & I915_OVERLAY_DEPTH_MASK) { case I915_OVERLAY_YUV422: case I915_OVERLAY_YUV420: return 2; case I915_OVERLAY_YUV411: case I915_OVERLAY_YUV410: return 4; default: return -EINVAL; } } static int uv_vsubsampling(u32 format) { switch (format & I915_OVERLAY_DEPTH_MASK) { case I915_OVERLAY_YUV420: case I915_OVERLAY_YUV410: return 2; case I915_OVERLAY_YUV422: case I915_OVERLAY_YUV411: return 1; default: return -EINVAL; } } static u32 calc_swidthsw(struct drm_device *dev, u32 offset, u32 width) { u32 mask, shift, ret; if (IS_GEN2(dev)) { mask = 0x1f; shift = 5; } else { mask = 0x3f; shift = 6; } ret = ((offset + width + mask) >> shift) - (offset >> shift); if (!IS_GEN2(dev)) ret <<= 1; ret -= 1; return ret << 2; } static const u16 y_static_hcoeffs[N_HORIZ_Y_TAPS * N_PHASES] = { 0x3000, 0xb4a0, 0x1930, 0x1920, 0xb4a0, 0x3000, 0xb500, 0x19d0, 0x1880, 0xb440, 0x3000, 0xb540, 0x1a88, 0x2f80, 0xb3e0, 0x3000, 0xb580, 0x1b30, 0x2e20, 0xb380, 0x3000, 0xb5c0, 0x1bd8, 0x2cc0, 0xb320, 0x3020, 0xb5e0, 0x1c60, 0x2b80, 0xb2c0, 0x3020, 0xb5e0, 0x1cf8, 0x2a20, 0xb260, 0x3020, 0xb5e0, 0x1d80, 0x28e0, 0xb200, 0x3020, 0xb5c0, 0x1e08, 0x3f40, 0xb1c0, 0x3020, 0xb580, 0x1e78, 0x3ce0, 0xb160, 0x3040, 0xb520, 0x1ed8, 0x3aa0, 0xb120, 0x3040, 0xb4a0, 0x1f30, 0x3880, 0xb0e0, 0x3040, 0xb400, 0x1f78, 0x3680, 0xb0a0, 0x3020, 0xb340, 0x1fb8, 0x34a0, 0xb060, 0x3020, 0xb240, 0x1fe0, 0x32e0, 0xb040, 0x3020, 0xb140, 0x1ff8, 0x3160, 0xb020, 0xb000, 0x3000, 0x0800, 0x3000, 0xb000 }; static const u16 uv_static_hcoeffs[N_HORIZ_UV_TAPS * N_PHASES] = { 0x3000, 0x1800, 0x1800, 0xb000, 0x18d0, 0x2e60, 0xb000, 0x1990, 0x2ce0, 0xb020, 0x1a68, 0x2b40, 0xb040, 0x1b20, 0x29e0, 0xb060, 0x1bd8, 0x2880, 0xb080, 0x1c88, 0x3e60, 0xb0a0, 0x1d28, 0x3c00, 0xb0c0, 0x1db8, 0x39e0, 0xb0e0, 0x1e40, 0x37e0, 0xb100, 0x1eb8, 0x3620, 0xb100, 0x1f18, 0x34a0, 0xb100, 0x1f68, 0x3360, 0xb0e0, 0x1fa8, 0x3240, 0xb0c0, 0x1fe0, 0x3140, 0xb060, 0x1ff0, 0x30a0, 0x3000, 0x0800, 0x3000 }; static void update_polyphase_filter(struct overlay_registers __iomem *regs) { memcpy_toio(regs->Y_HCOEFS, y_static_hcoeffs, sizeof(y_static_hcoeffs)); memcpy_toio(regs->UV_HCOEFS, uv_static_hcoeffs, sizeof(uv_static_hcoeffs)); } static bool update_scaling_factors(struct intel_overlay *overlay, struct overlay_registers __iomem *regs, struct put_image_params *params) { /* fixed point with a 12 bit shift */ u32 xscale, yscale, xscale_UV, yscale_UV; #define FP_SHIFT 12 #define FRACT_MASK 0xfff bool scale_changed = false; int uv_hscale = uv_hsubsampling(params->format); int uv_vscale = uv_vsubsampling(params->format); if (params->dst_w > 1) xscale = ((params->src_scan_w - 1) << FP_SHIFT) /(params->dst_w); else xscale = 1 << FP_SHIFT; if (params->dst_h > 1) yscale = ((params->src_scan_h - 1) << FP_SHIFT) /(params->dst_h); else yscale = 1 << FP_SHIFT; /*if (params->format & I915_OVERLAY_YUV_PLANAR) {*/ xscale_UV = xscale/uv_hscale; yscale_UV = yscale/uv_vscale; /* make the Y scale to UV scale ratio an exact multiply */ xscale = xscale_UV * uv_hscale; yscale = yscale_UV * uv_vscale; /*} else { xscale_UV = 0; yscale_UV = 0; }*/ if (xscale != overlay->old_xscale || yscale != overlay->old_yscale) scale_changed = true; overlay->old_xscale = xscale; overlay->old_yscale = yscale; iowrite32(((yscale & FRACT_MASK) << 20) | ((xscale >> FP_SHIFT) << 16) | ((xscale & FRACT_MASK) << 3), &regs->YRGBSCALE); iowrite32(((yscale_UV & FRACT_MASK) << 20) | ((xscale_UV >> FP_SHIFT) << 16) | ((xscale_UV & FRACT_MASK) << 3), &regs->UVSCALE); iowrite32((((yscale >> FP_SHIFT) << 16) | ((yscale_UV >> FP_SHIFT) << 0)), &regs->UVSCALEV); if (scale_changed) update_polyphase_filter(regs); return scale_changed; } static void update_colorkey(struct intel_overlay *overlay, struct overlay_registers __iomem *regs) { u32 key = overlay->color_key; switch (overlay->crtc->base.fb->bits_per_pixel) { case 8: iowrite32(0, &regs->DCLRKV); iowrite32(CLK_RGB8I_MASK | DST_KEY_ENABLE, &regs->DCLRKM); break; case 16: if (overlay->crtc->base.fb->depth == 15) { iowrite32(RGB15_TO_COLORKEY(key), &regs->DCLRKV); iowrite32(CLK_RGB15_MASK | DST_KEY_ENABLE, &regs->DCLRKM); } else { iowrite32(RGB16_TO_COLORKEY(key), &regs->DCLRKV); iowrite32(CLK_RGB16_MASK | DST_KEY_ENABLE, &regs->DCLRKM); } break; case 24: case 32: iowrite32(key, &regs->DCLRKV); iowrite32(CLK_RGB24_MASK | DST_KEY_ENABLE, &regs->DCLRKM); break; } } static u32 overlay_cmd_reg(struct put_image_params *params) { u32 cmd = OCMD_ENABLE | OCMD_BUF_TYPE_FRAME | OCMD_BUFFER0; if (params->format & I915_OVERLAY_YUV_PLANAR) { switch (params->format & I915_OVERLAY_DEPTH_MASK) { case I915_OVERLAY_YUV422: cmd |= OCMD_YUV_422_PLANAR; break; case I915_OVERLAY_YUV420: cmd |= OCMD_YUV_420_PLANAR; break; case I915_OVERLAY_YUV411: case I915_OVERLAY_YUV410: cmd |= OCMD_YUV_410_PLANAR; break; } } else { /* YUV packed */ switch (params->format & I915_OVERLAY_DEPTH_MASK) { case I915_OVERLAY_YUV422: cmd |= OCMD_YUV_422_PACKED; break; case I915_OVERLAY_YUV411: cmd |= OCMD_YUV_411_PACKED; break; } switch (params->format & I915_OVERLAY_SWAP_MASK) { case I915_OVERLAY_NO_SWAP: break; case I915_OVERLAY_UV_SWAP: cmd |= OCMD_UV_SWAP; break; case I915_OVERLAY_Y_SWAP: cmd |= OCMD_Y_SWAP; break; case I915_OVERLAY_Y_AND_UV_SWAP: cmd |= OCMD_Y_AND_UV_SWAP; break; } } return cmd; } static int intel_overlay_do_put_image(struct intel_overlay *overlay, struct drm_i915_gem_object *new_bo, struct put_image_params *params) { int ret, tmp_width; struct overlay_registers __iomem *regs; bool scale_changed = false; struct drm_device *dev = overlay->dev; u32 swidth, swidthsw, sheight, ostride; BUG_ON(!mutex_is_locked(&dev->struct_mutex)); BUG_ON(!mutex_is_locked(&dev->mode_config.mutex)); BUG_ON(!overlay); ret = intel_overlay_release_old_vid(overlay); if (ret != 0) return ret; ret = i915_gem_object_pin_to_display_plane(new_bo, 0, NULL); if (ret != 0) return ret; ret = i915_gem_object_put_fence(new_bo); if (ret) goto out_unpin; if (!overlay->active) { u32 oconfig; regs = intel_overlay_map_regs(overlay); if (!regs) { ret = -ENOMEM; goto out_unpin; } oconfig = OCONF_CC_OUT_8BIT; if (IS_GEN4(overlay->dev)) oconfig |= OCONF_CSC_MODE_BT709; oconfig |= overlay->crtc->pipe == 0 ? OCONF_PIPE_A : OCONF_PIPE_B; iowrite32(oconfig, &regs->OCONFIG); intel_overlay_unmap_regs(overlay, regs); ret = intel_overlay_on(overlay); if (ret != 0) goto out_unpin; } regs = intel_overlay_map_regs(overlay); if (!regs) { ret = -ENOMEM; goto out_unpin; } iowrite32((params->dst_y << 16) | params->dst_x, &regs->DWINPOS); iowrite32((params->dst_h << 16) | params->dst_w, &regs->DWINSZ); if (params->format & I915_OVERLAY_YUV_PACKED) tmp_width = packed_width_bytes(params->format, params->src_w); else tmp_width = params->src_w; swidth = params->src_w; swidthsw = calc_swidthsw(overlay->dev, params->offset_Y, tmp_width); sheight = params->src_h; iowrite32(new_bo->gtt_offset + params->offset_Y, &regs->OBUF_0Y); ostride = params->stride_Y; if (params->format & I915_OVERLAY_YUV_PLANAR) { int uv_hscale = uv_hsubsampling(params->format); int uv_vscale = uv_vsubsampling(params->format); u32 tmp_U, tmp_V; swidth |= (params->src_w/uv_hscale) << 16; tmp_U = calc_swidthsw(overlay->dev, params->offset_U, params->src_w/uv_hscale); tmp_V = calc_swidthsw(overlay->dev, params->offset_V, params->src_w/uv_hscale); swidthsw |= max_t(u32, tmp_U, tmp_V) << 16; sheight |= (params->src_h/uv_vscale) << 16; iowrite32(new_bo->gtt_offset + params->offset_U, &regs->OBUF_0U); iowrite32(new_bo->gtt_offset + params->offset_V, &regs->OBUF_0V); ostride |= params->stride_UV << 16; } iowrite32(swidth, &regs->SWIDTH); iowrite32(swidthsw, &regs->SWIDTHSW); iowrite32(sheight, &regs->SHEIGHT); iowrite32(ostride, &regs->OSTRIDE); scale_changed = update_scaling_factors(overlay, regs, params); update_colorkey(overlay, regs); iowrite32(overlay_cmd_reg(params), &regs->OCMD); intel_overlay_unmap_regs(overlay, regs); ret = intel_overlay_continue(overlay, scale_changed); if (ret) goto out_unpin; overlay->old_vid_bo = overlay->vid_bo; overlay->vid_bo = new_bo; return 0; out_unpin: i915_gem_object_unpin(new_bo); return ret; } int intel_overlay_switch_off(struct intel_overlay *overlay) { struct overlay_registers __iomem *regs; struct drm_device *dev = overlay->dev; int ret; BUG_ON(!mutex_is_locked(&dev->struct_mutex)); BUG_ON(!mutex_is_locked(&dev->mode_config.mutex)); ret = intel_overlay_recover_from_interrupt(overlay); if (ret != 0) return ret; if (!overlay->active) return 0; ret = intel_overlay_release_old_vid(overlay); if (ret != 0) return ret; regs = intel_overlay_map_regs(overlay); iowrite32(0, &regs->OCMD); intel_overlay_unmap_regs(overlay, regs); ret = intel_overlay_off(overlay); if (ret != 0) return ret; intel_overlay_off_tail(overlay); return 0; } static int check_overlay_possible_on_crtc(struct intel_overlay *overlay, struct intel_crtc *crtc) { drm_i915_private_t *dev_priv = overlay->dev->dev_private; if (!crtc->active) return -EINVAL; /* can't use the overlay with double wide pipe */ if (INTEL_INFO(overlay->dev)->gen < 4 && (I915_READ(PIPECONF(crtc->pipe)) & (PIPECONF_DOUBLE_WIDE | PIPECONF_ENABLE)) != PIPECONF_ENABLE) return -EINVAL; return 0; } static void update_pfit_vscale_ratio(struct intel_overlay *overlay) { struct drm_device *dev = overlay->dev; drm_i915_private_t *dev_priv = dev->dev_private; u32 pfit_control = I915_READ(PFIT_CONTROL); u32 ratio; /* XXX: This is not the same logic as in the xorg driver, but more in * line with the intel documentation for the i965 */ if (INTEL_INFO(dev)->gen >= 4) { /* on i965 use the PGM reg to read out the autoscaler values */ ratio = I915_READ(PFIT_PGM_RATIOS) >> PFIT_VERT_SCALE_SHIFT_965; } else { if (pfit_control & VERT_AUTO_SCALE) ratio = I915_READ(PFIT_AUTO_RATIOS); else ratio = I915_READ(PFIT_PGM_RATIOS); ratio >>= PFIT_VERT_SCALE_SHIFT; } overlay->pfit_vscale_ratio = ratio; } static int check_overlay_dst(struct intel_overlay *overlay, struct drm_intel_overlay_put_image *rec) { struct drm_display_mode *mode = &overlay->crtc->base.mode; if (rec->dst_x < mode->hdisplay && rec->dst_x + rec->dst_width <= mode->hdisplay && rec->dst_y < mode->vdisplay && rec->dst_y + rec->dst_height <= mode->vdisplay) return 0; else return -EINVAL; } static int check_overlay_scaling(struct put_image_params *rec) { u32 tmp; /* downscaling limit is 8.0 */ tmp = ((rec->src_scan_h << 16) / rec->dst_h) >> 16; if (tmp > 7) return -EINVAL; tmp = ((rec->src_scan_w << 16) / rec->dst_w) >> 16; if (tmp > 7) return -EINVAL; return 0; } static int check_overlay_src(struct drm_device *dev, struct drm_intel_overlay_put_image *rec, struct drm_i915_gem_object *new_bo) { int uv_hscale = uv_hsubsampling(rec->flags); int uv_vscale = uv_vsubsampling(rec->flags); u32 stride_mask; int depth; u32 tmp; /* check src dimensions */ if (IS_845G(dev) || IS_I830(dev)) { if (rec->src_height > IMAGE_MAX_HEIGHT_LEGACY || rec->src_width > IMAGE_MAX_WIDTH_LEGACY) return -EINVAL; } else { if (rec->src_height > IMAGE_MAX_HEIGHT || rec->src_width > IMAGE_MAX_WIDTH) return -EINVAL; } /* better safe than sorry, use 4 as the maximal subsampling ratio */ if (rec->src_height < N_VERT_Y_TAPS*4 || rec->src_width < N_HORIZ_Y_TAPS*4) return -EINVAL; /* check alignment constraints */ switch (rec->flags & I915_OVERLAY_TYPE_MASK) { case I915_OVERLAY_RGB: /* not implemented */ return -EINVAL; case I915_OVERLAY_YUV_PACKED: if (uv_vscale != 1) return -EINVAL; depth = packed_depth_bytes(rec->flags); if (depth < 0) return depth; /* ignore UV planes */ rec->stride_UV = 0; rec->offset_U = 0; rec->offset_V = 0; /* check pixel alignment */ if (rec->offset_Y % depth) return -EINVAL; break; case I915_OVERLAY_YUV_PLANAR: if (uv_vscale < 0 || uv_hscale < 0) return -EINVAL; /* no offset restrictions for planar formats */ break; default: return -EINVAL; } if (rec->src_width % uv_hscale) return -EINVAL; /* stride checking */ if (IS_I830(dev) || IS_845G(dev)) stride_mask = 255; else stride_mask = 63; if (rec->stride_Y & stride_mask || rec->stride_UV & stride_mask) return -EINVAL; if (IS_GEN4(dev) && rec->stride_Y < 512) return -EINVAL; tmp = (rec->flags & I915_OVERLAY_TYPE_MASK) == I915_OVERLAY_YUV_PLANAR ? 4096 : 8192; if (rec->stride_Y > tmp || rec->stride_UV > 2*1024) return -EINVAL; /* check buffer dimensions */ switch (rec->flags & I915_OVERLAY_TYPE_MASK) { case I915_OVERLAY_RGB: case I915_OVERLAY_YUV_PACKED: /* always 4 Y values per depth pixels */ if (packed_width_bytes(rec->flags, rec->src_width) > rec->stride_Y) return -EINVAL; tmp = rec->stride_Y*rec->src_height; if (rec->offset_Y + tmp > new_bo->base.size) return -EINVAL; break; case I915_OVERLAY_YUV_PLANAR: if (rec->src_width > rec->stride_Y) return -EINVAL; if (rec->src_width/uv_hscale > rec->stride_UV) return -EINVAL; tmp = rec->stride_Y * rec->src_height; if (rec->offset_Y + tmp > new_bo->base.size) return -EINVAL; tmp = rec->stride_UV * (rec->src_height / uv_vscale); if (rec->offset_U + tmp > new_bo->base.size || rec->offset_V + tmp > new_bo->base.size) return -EINVAL; break; } return 0; } /** * Return the pipe currently connected to the panel fitter, * or -1 if the panel fitter is not present or not in use */ static int intel_panel_fitter_pipe(struct drm_device *dev) { struct drm_i915_private *dev_priv = dev->dev_private; u32 pfit_control; /* i830 doesn't have a panel fitter */ if (IS_I830(dev)) return -1; pfit_control = I915_READ(PFIT_CONTROL); /* See if the panel fitter is in use */ if ((pfit_control & PFIT_ENABLE) == 0) return -1; /* 965 can place panel fitter on either pipe */ if (IS_GEN4(dev)) return (pfit_control >> 29) & 0x3; /* older chips can only use pipe 1 */ return 1; } int intel_overlay_put_image(struct drm_device *dev, void *data, struct drm_file *file_priv) { struct drm_intel_overlay_put_image *put_image_rec = data; drm_i915_private_t *dev_priv = dev->dev_private; struct intel_overlay *overlay; struct drm_mode_object *drmmode_obj; struct intel_crtc *crtc; struct drm_i915_gem_object *new_bo; struct put_image_params *params; int ret; /* No need to check for DRIVER_MODESET - we don't set it up then. */ overlay = dev_priv->overlay; if (!overlay) { DRM_DEBUG("userspace bug: no overlay\n"); return -ENODEV; } if (!(put_image_rec->flags & I915_OVERLAY_ENABLE)) { drm_modeset_lock_all(dev); mutex_lock(&dev->struct_mutex); ret = intel_overlay_switch_off(overlay); mutex_unlock(&dev->struct_mutex); drm_modeset_unlock_all(dev); return ret; } params = kmalloc(sizeof(struct put_image_params), GFP_KERNEL); if (!params) return -ENOMEM; drmmode_obj = drm_mode_object_find(dev, put_image_rec->crtc_id, DRM_MODE_OBJECT_CRTC); if (!drmmode_obj) { ret = -ENOENT; goto out_free; } crtc = to_intel_crtc(obj_to_crtc(drmmode_obj)); new_bo = to_intel_bo(drm_gem_object_lookup(dev, file_priv, put_image_rec->bo_handle)); if (&new_bo->base == NULL) { ret = -ENOENT; goto out_free; } drm_modeset_lock_all(dev); mutex_lock(&dev->struct_mutex); if (new_bo->tiling_mode) { DRM_ERROR("buffer used for overlay image can not be tiled\n"); ret = -EINVAL; goto out_unlock; } ret = intel_overlay_recover_from_interrupt(overlay); if (ret != 0) goto out_unlock; if (overlay->crtc != crtc) { struct drm_display_mode *mode = &crtc->base.mode; ret = intel_overlay_switch_off(overlay); if (ret != 0) goto out_unlock; ret = check_overlay_possible_on_crtc(overlay, crtc); if (ret != 0) goto out_unlock; overlay->crtc = crtc; crtc->overlay = overlay; /* line too wide, i.e. one-line-mode */ if (mode->hdisplay > 1024 && intel_panel_fitter_pipe(dev) == crtc->pipe) { overlay->pfit_active = 1; update_pfit_vscale_ratio(overlay); } else overlay->pfit_active = 0; } ret = check_overlay_dst(overlay, put_image_rec); if (ret != 0) goto out_unlock; if (overlay->pfit_active) { params->dst_y = ((((u32)put_image_rec->dst_y) << 12) / overlay->pfit_vscale_ratio); /* shifting right rounds downwards, so add 1 */ params->dst_h = ((((u32)put_image_rec->dst_height) << 12) / overlay->pfit_vscale_ratio) + 1; } else { params->dst_y = put_image_rec->dst_y; params->dst_h = put_image_rec->dst_height; } params->dst_x = put_image_rec->dst_x; params->dst_w = put_image_rec->dst_width; params->src_w = put_image_rec->src_width; params->src_h = put_image_rec->src_height; params->src_scan_w = put_image_rec->src_scan_width; params->src_scan_h = put_image_rec->src_scan_height; if (params->src_scan_h > params->src_h || params->src_scan_w > params->src_w) { ret = -EINVAL; goto out_unlock; } ret = check_overlay_src(dev, put_image_rec, new_bo); if (ret != 0) goto out_unlock; params->format = put_image_rec->flags & ~I915_OVERLAY_FLAGS_MASK; params->stride_Y = put_image_rec->stride_Y; params->stride_UV = put_image_rec->stride_UV; params->offset_Y = put_image_rec->offset_Y; params->offset_U = put_image_rec->offset_U; params->offset_V = put_image_rec->offset_V; /* Check scaling after src size to prevent a divide-by-zero. */ ret = check_overlay_scaling(params); if (ret != 0) goto out_unlock; ret = intel_overlay_do_put_image(overlay, new_bo, params); if (ret != 0) goto out_unlock; mutex_unlock(&dev->struct_mutex); drm_modeset_unlock_all(dev); kfree(params); return 0; out_unlock: mutex_unlock(&dev->struct_mutex); drm_modeset_unlock_all(dev); drm_gem_object_unreference_unlocked(&new_bo->base); out_free: kfree(params); return ret; } static void update_reg_attrs(struct intel_overlay *overlay, struct overlay_registers __iomem *regs) { iowrite32((overlay->contrast << 18) | (overlay->brightness & 0xff), &regs->OCLRC0); iowrite32(overlay->saturation, &regs->OCLRC1); } static bool check_gamma_bounds(u32 gamma1, u32 gamma2) { int i; if (gamma1 & 0xff000000 || gamma2 & 0xff000000) return false; for (i = 0; i < 3; i++) { if (((gamma1 >> i*8) & 0xff) >= ((gamma2 >> i*8) & 0xff)) return false; } return true; } static bool check_gamma5_errata(u32 gamma5) { int i; for (i = 0; i < 3; i++) { if (((gamma5 >> i*8) & 0xff) == 0x80) return false; } return true; } static int check_gamma(struct drm_intel_overlay_attrs *attrs) { if (!check_gamma_bounds(0, attrs->gamma0) || !check_gamma_bounds(attrs->gamma0, attrs->gamma1) || !check_gamma_bounds(attrs->gamma1, attrs->gamma2) || !check_gamma_bounds(attrs->gamma2, attrs->gamma3) || !check_gamma_bounds(attrs->gamma3, attrs->gamma4) || !check_gamma_bounds(attrs->gamma4, attrs->gamma5) || !check_gamma_bounds(attrs->gamma5, 0x00ffffff)) return -EINVAL; if (!check_gamma5_errata(attrs->gamma5)) return -EINVAL; return 0; } int intel_overlay_attrs(struct drm_device *dev, void *data, struct drm_file *file_priv) { struct drm_intel_overlay_attrs *attrs = data; drm_i915_private_t *dev_priv = dev->dev_private; struct intel_overlay *overlay; struct overlay_registers __iomem *regs; int ret; /* No need to check for DRIVER_MODESET - we don't set it up then. */ overlay = dev_priv->overlay; if (!overlay) { DRM_DEBUG("userspace bug: no overlay\n"); return -ENODEV; } drm_modeset_lock_all(dev); mutex_lock(&dev->struct_mutex); ret = -EINVAL; if (!(attrs->flags & I915_OVERLAY_UPDATE_ATTRS)) { attrs->color_key = overlay->color_key; attrs->brightness = overlay->brightness; attrs->contrast = overlay->contrast; attrs->saturation = overlay->saturation; if (!IS_GEN2(dev)) { attrs->gamma0 = I915_READ(OGAMC0); attrs->gamma1 = I915_READ(OGAMC1); attrs->gamma2 = I915_READ(OGAMC2); attrs->gamma3 = I915_READ(OGAMC3); attrs->gamma4 = I915_READ(OGAMC4); attrs->gamma5 = I915_READ(OGAMC5); } } else { if (attrs->brightness < -128 || attrs->brightness > 127) goto out_unlock; if (attrs->contrast > 255) goto out_unlock; if (attrs->saturation > 1023) goto out_unlock; overlay->color_key = attrs->color_key; overlay->brightness = attrs->brightness; overlay->contrast = attrs->contrast; overlay->saturation = attrs->saturation; regs = intel_overlay_map_regs(overlay); if (!regs) { ret = -ENOMEM; goto out_unlock; } update_reg_attrs(overlay, regs); intel_overlay_unmap_regs(overlay, regs); if (attrs->flags & I915_OVERLAY_UPDATE_GAMMA) { if (IS_GEN2(dev)) goto out_unlock; if (overlay->active) { ret = -EBUSY; goto out_unlock; } ret = check_gamma(attrs); if (ret) goto out_unlock; I915_WRITE(OGAMC0, attrs->gamma0); I915_WRITE(OGAMC1, attrs->gamma1); I915_WRITE(OGAMC2, attrs->gamma2); I915_WRITE(OGAMC3, attrs->gamma3); I915_WRITE(OGAMC4, attrs->gamma4); I915_WRITE(OGAMC5, attrs->gamma5); } } ret = 0; out_unlock: mutex_unlock(&dev->struct_mutex); drm_modeset_unlock_all(dev); return ret; } void intel_setup_overlay(struct drm_device *dev) { drm_i915_private_t *dev_priv = dev->dev_private; struct intel_overlay *overlay; struct drm_i915_gem_object *reg_bo; struct overlay_registers __iomem *regs; int ret; if (!HAS_OVERLAY(dev)) return; overlay = kzalloc(sizeof(struct intel_overlay), GFP_KERNEL); if (!overlay) return; mutex_lock(&dev->struct_mutex); if (WARN_ON(dev_priv->overlay)) goto out_free; overlay->dev = dev; reg_bo = i915_gem_object_create_stolen(dev, PAGE_SIZE); if (reg_bo == NULL) reg_bo = i915_gem_alloc_object(dev, PAGE_SIZE); if (reg_bo == NULL) goto out_free; overlay->reg_bo = reg_bo; if (OVERLAY_NEEDS_PHYSICAL(dev)) { ret = i915_gem_attach_phys_object(dev, reg_bo, I915_GEM_PHYS_OVERLAY_REGS, PAGE_SIZE); if (ret) { DRM_ERROR("failed to attach phys overlay regs\n"); goto out_free_bo; } overlay->flip_addr = reg_bo->phys_obj->handle->busaddr; } else { ret = i915_gem_object_pin(reg_bo, PAGE_SIZE, true, false); if (ret) { DRM_ERROR("failed to pin overlay register bo\n"); goto out_free_bo; } overlay->flip_addr = reg_bo->gtt_offset; ret = i915_gem_object_set_to_gtt_domain(reg_bo, true); if (ret) { DRM_ERROR("failed to move overlay register bo into the GTT\n"); goto out_unpin_bo; } } /* init all values */ overlay->color_key = 0x0101fe; overlay->brightness = -19; overlay->contrast = 75; overlay->saturation = 146; regs = intel_overlay_map_regs(overlay); if (!regs) goto out_unpin_bo; memset_io(regs, 0, sizeof(struct overlay_registers)); update_polyphase_filter(regs); update_reg_attrs(overlay, regs); intel_overlay_unmap_regs(overlay, regs); dev_priv->overlay = overlay; mutex_unlock(&dev->struct_mutex); DRM_INFO("initialized overlay support\n"); return; out_unpin_bo: if (!OVERLAY_NEEDS_PHYSICAL(dev)) i915_gem_object_unpin(reg_bo); out_free_bo: drm_gem_object_unreference(&reg_bo->base); out_free: mutex_unlock(&dev->struct_mutex); kfree(overlay); return; } void intel_cleanup_overlay(struct drm_device *dev) { drm_i915_private_t *dev_priv = dev->dev_private; if (!dev_priv->overlay) return; /* The bo's should be free'd by the generic code already. * Furthermore modesetting teardown happens beforehand so the * hardware should be off already */ BUG_ON(dev_priv->overlay->active); drm_gem_object_unreference_unlocked(&dev_priv->overlay->reg_bo->base); kfree(dev_priv->overlay); } #ifdef CONFIG_DEBUG_FS #include <linux/seq_file.h> struct intel_overlay_error_state { struct overlay_registers regs; unsigned long base; u32 dovsta; u32 isr; }; static struct overlay_registers __iomem * intel_overlay_map_regs_atomic(struct intel_overlay *overlay) { drm_i915_private_t *dev_priv = overlay->dev->dev_private; struct overlay_registers __iomem *regs; if (OVERLAY_NEEDS_PHYSICAL(overlay->dev)) /* Cast to make sparse happy, but it's wc memory anyway, so * equivalent to the wc io mapping on X86. */ regs = (struct overlay_registers __iomem *) overlay->reg_bo->phys_obj->handle->vaddr; else regs = io_mapping_map_atomic_wc(dev_priv->gtt.mappable, overlay->reg_bo->gtt_offset); return regs; } static void intel_overlay_unmap_regs_atomic(struct intel_overlay *overlay, struct overlay_registers __iomem *regs) { if (!OVERLAY_NEEDS_PHYSICAL(overlay->dev)) io_mapping_unmap_atomic(regs); } struct intel_overlay_error_state * intel_overlay_capture_error_state(struct drm_device *dev) { drm_i915_private_t *dev_priv = dev->dev_private; struct intel_overlay *overlay = dev_priv->overlay; struct intel_overlay_error_state *error; struct overlay_registers __iomem *regs; if (!overlay || !overlay->active) return NULL; error = kmalloc(sizeof(*error), GFP_ATOMIC); if (error == NULL) return NULL; error->dovsta = I915_READ(DOVSTA); error->isr = I915_READ(ISR); if (OVERLAY_NEEDS_PHYSICAL(overlay->dev)) error->base = (__force long)overlay->reg_bo->phys_obj->handle->vaddr; else error->base = overlay->reg_bo->gtt_offset; regs = intel_overlay_map_regs_atomic(overlay); if (!regs) goto err; memcpy_fromio(&error->regs, regs, sizeof(struct overlay_registers)); intel_overlay_unmap_regs_atomic(overlay, regs); return error; err: kfree(error); return NULL; } void intel_overlay_print_error_state(struct seq_file *m, struct intel_overlay_error_state *error) { seq_printf(m, "Overlay, status: 0x%08x, interrupt: 0x%08x\n", error->dovsta, error->isr); seq_printf(m, " Register file at 0x%08lx:\n", error->base); #define P(x) seq_printf(m, " " #x ": 0x%08x\n", error->regs.x) P(OBUF_0Y); P(OBUF_1Y); P(OBUF_0U); P(OBUF_0V); P(OBUF_1U); P(OBUF_1V); P(OSTRIDE); P(YRGB_VPH); P(UV_VPH); P(HORZ_PH); P(INIT_PHS); P(DWINPOS); P(DWINSZ); P(SWIDTH); P(SWIDTHSW); P(SHEIGHT); P(YRGBSCALE); P(UVSCALE); P(OCLRC0); P(OCLRC1); P(DCLRKV); P(DCLRKM); P(SCLRKVH); P(SCLRKVL); P(SCLRKEN); P(OCONFIG); P(OCMD); P(OSTART_0Y); P(OSTART_1Y); P(OSTART_0U); P(OSTART_0V); P(OSTART_1U); P(OSTART_1V); P(OTILEOFF_0Y); P(OTILEOFF_1Y); P(OTILEOFF_0U); P(OTILEOFF_0V); P(OTILEOFF_1U); P(OTILEOFF_1V); P(FASTHSCALE); P(UVSCALEV); #undef P } #endif
gpl-2.0
Cardinal97/android_kernel_msm8939
arch/mips/kernel/time.c
2063
2967
/* * Copyright 2001 MontaVista Software Inc. * Author: Jun Sun, jsun@mvista.com or jsun@junsun.net * Copyright (c) 2003, 2004 Maciej W. Rozycki * * Common time service routines for MIPS machines. * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the * Free Software Foundation; either version 2 of the License, or (at your * option) any later version. */ #include <linux/bug.h> #include <linux/clockchips.h> #include <linux/types.h> #include <linux/kernel.h> #include <linux/init.h> #include <linux/sched.h> #include <linux/param.h> #include <linux/time.h> #include <linux/timex.h> #include <linux/smp.h> #include <linux/spinlock.h> #include <linux/export.h> #include <asm/cpu-features.h> #include <asm/div64.h> #include <asm/smtc_ipi.h> #include <asm/time.h> /* * forward reference */ DEFINE_SPINLOCK(rtc_lock); EXPORT_SYMBOL(rtc_lock); int __weak rtc_mips_set_time(unsigned long sec) { return 0; } int __weak rtc_mips_set_mmss(unsigned long nowtime) { return rtc_mips_set_time(nowtime); } int update_persistent_clock(struct timespec now) { return rtc_mips_set_mmss(now.tv_sec); } static int null_perf_irq(void) { return 0; } int (*perf_irq)(void) = null_perf_irq; EXPORT_SYMBOL(perf_irq); /* * time_init() - it does the following things. * * 1) plat_time_init() - * a) (optional) set up RTC routines, * b) (optional) calibrate and set the mips_hpt_frequency * (only needed if you intended to use cpu counter as timer interrupt * source) * 2) calculate a couple of cached variables for later usage */ unsigned int mips_hpt_frequency; /* * This function exists in order to cause an error due to a duplicate * definition if platform code should have its own implementation. The hook * to use instead is plat_time_init. plat_time_init does not receive the * irqaction pointer argument anymore. This is because any function which * initializes an interrupt timer now takes care of its own request_irq rsp. * setup_irq calls and each clock_event_device should use its own * struct irqrequest. */ void __init plat_timer_setup(void) { BUG(); } static __init int cpu_has_mfc0_count_bug(void) { switch (current_cpu_type()) { case CPU_R4000PC: case CPU_R4000SC: case CPU_R4000MC: /* * V3.0 is documented as suffering from the mfc0 from count bug. * Afaik this is the last version of the R4000. Later versions * were marketed as R4400. */ return 1; case CPU_R4400PC: case CPU_R4400SC: case CPU_R4400MC: /* * The published errata for the R4400 up to 3.0 say the CPU * has the mfc0 from count bug. */ if ((current_cpu_data.processor_id & 0xff) <= 0x30) return 1; /* * we assume newer revisions are ok */ return 0; } return 0; } void __init time_init(void) { plat_time_init(); if (!mips_clockevent_init() || !cpu_has_mfc0_count_bug()) init_mips_clocksource(); }
gpl-2.0
akhilnarang/ThugLife_bullhead
drivers/staging/vt6655/power.c
2319
9959
/* * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc. * All rights reserved. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * * File: power.c * * Purpose: Handles 802.11 power management functions * * Author: Lyndon Chen * * Date: July 17, 2002 * * Functions: * PSvEnablePowerSaving - Enable Power Saving Mode * PSvDiasblePowerSaving - Disable Power Saving Mode * PSbConsiderPowerDown - Decide if we can Power Down * PSvSendPSPOLL - Send PS-POLL packet * PSbSendNullPacket - Send Null packet * PSbIsNextTBTTWakeUp - Decide if we need to wake up at next Beacon * * Revision History: * */ #include "ttype.h" #include "mac.h" #include "device.h" #include "wmgr.h" #include "power.h" #include "wcmd.h" #include "rxtx.h" #include "card.h" /*--------------------- Static Definitions -------------------------*/ /*--------------------- Static Classes ----------------------------*/ /*--------------------- Static Variables --------------------------*/ static int msglevel = MSG_LEVEL_INFO; /*--------------------- Static Functions --------------------------*/ /*--------------------- Export Variables --------------------------*/ /*--------------------- Export Functions --------------------------*/ /*+ * * Routine Description: * Enable hw power saving functions * * Return Value: * None. * -*/ void PSvEnablePowerSaving( void *hDeviceContext, unsigned short wListenInterval ) { PSDevice pDevice = (PSDevice)hDeviceContext; PSMgmtObject pMgmt = pDevice->pMgmt; unsigned short wAID = pMgmt->wCurrAID | BIT14 | BIT15; // set period of power up before TBTT VNSvOutPortW(pDevice->PortOffset + MAC_REG_PWBT, C_PWBT); if (pDevice->eOPMode != OP_MODE_ADHOC) { // set AID VNSvOutPortW(pDevice->PortOffset + MAC_REG_AIDATIM, wAID); } else { // set ATIM Window MACvWriteATIMW(pDevice->PortOffset, pMgmt->wCurrATIMWindow); } // Set AutoSleep MACvRegBitsOn(pDevice->PortOffset, MAC_REG_PSCFG, PSCFG_AUTOSLEEP); // Set HWUTSF MACvRegBitsOn(pDevice->PortOffset, MAC_REG_TFTCTL, TFTCTL_HWUTSF); if (wListenInterval >= 2) { // clear always listen beacon MACvRegBitsOff(pDevice->PortOffset, MAC_REG_PSCTL, PSCTL_ALBCN); //pDevice->wCFG &= ~CFG_ALB; // first time set listen next beacon MACvRegBitsOn(pDevice->PortOffset, MAC_REG_PSCTL, PSCTL_LNBCN); pMgmt->wCountToWakeUp = wListenInterval; } else { // always listen beacon MACvRegBitsOn(pDevice->PortOffset, MAC_REG_PSCTL, PSCTL_ALBCN); //pDevice->wCFG |= CFG_ALB; pMgmt->wCountToWakeUp = 0; } // enable power saving hw function MACvRegBitsOn(pDevice->PortOffset, MAC_REG_PSCTL, PSCTL_PSEN); pDevice->bEnablePSMode = true; if (pDevice->eOPMode == OP_MODE_ADHOC) { // bMgrPrepareBeaconToSend((void *)pDevice, pMgmt); } // We don't send null pkt in ad hoc mode since beacon will handle this. else if (pDevice->eOPMode == OP_MODE_INFRASTRUCTURE) { PSbSendNullPacket(pDevice); } pDevice->bPWBitOn = true; DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "PS:Power Saving Mode Enable... \n"); return; } /*+ * * Routine Description: * Disable hw power saving functions * * Return Value: * None. * -*/ void PSvDisablePowerSaving( void *hDeviceContext ) { PSDevice pDevice = (PSDevice)hDeviceContext; // PSMgmtObject pMgmt = pDevice->pMgmt; // disable power saving hw function MACbPSWakeup(pDevice->PortOffset); //clear AutoSleep MACvRegBitsOff(pDevice->PortOffset, MAC_REG_PSCFG, PSCFG_AUTOSLEEP); //clear HWUTSF MACvRegBitsOff(pDevice->PortOffset, MAC_REG_TFTCTL, TFTCTL_HWUTSF); // set always listen beacon MACvRegBitsOn(pDevice->PortOffset, MAC_REG_PSCTL, PSCTL_ALBCN); pDevice->bEnablePSMode = false; if (pDevice->eOPMode == OP_MODE_INFRASTRUCTURE) { PSbSendNullPacket(pDevice); } pDevice->bPWBitOn = false; return; } /*+ * * Routine Description: * Consider to power down when no more packets to tx or rx. * * Return Value: * true, if power down success * false, if fail -*/ bool PSbConsiderPowerDown( void *hDeviceContext, bool bCheckRxDMA, bool bCheckCountToWakeUp ) { PSDevice pDevice = (PSDevice)hDeviceContext; PSMgmtObject pMgmt = pDevice->pMgmt; unsigned int uIdx; // check if already in Doze mode if (MACbIsRegBitsOn(pDevice->PortOffset, MAC_REG_PSCTL, PSCTL_PS)) return true; if (pMgmt->eCurrMode != WMAC_MODE_IBSS_STA) { // check if in TIM wake period if (pMgmt->bInTIMWake) return false; } // check scan state if (pDevice->bCmdRunning) return false; // Force PSEN on MACvRegBitsOn(pDevice->PortOffset, MAC_REG_PSCTL, PSCTL_PSEN); // check if all TD are empty, for (uIdx = 0; uIdx < TYPE_MAXTD; uIdx++) { if (pDevice->iTDUsed[uIdx] != 0) return false; } // check if rx isr is clear if (bCheckRxDMA && ((pDevice->dwIsr & ISR_RXDMA0) != 0) && ((pDevice->dwIsr & ISR_RXDMA1) != 0)) { return false; } if (pMgmt->eCurrMode != WMAC_MODE_IBSS_STA) { if (bCheckCountToWakeUp && (pMgmt->wCountToWakeUp == 0 || pMgmt->wCountToWakeUp == 1)) { return false; } } // no Tx, no Rx isr, now go to Doze MACvRegBitsOn(pDevice->PortOffset, MAC_REG_PSCTL, PSCTL_GO2DOZE); DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Go to Doze ZZZZZZZZZZZZZZZ\n"); return true; } /*+ * * Routine Description: * Send PS-POLL packet * * Return Value: * None. * -*/ void PSvSendPSPOLL( void *hDeviceContext ) { PSDevice pDevice = (PSDevice)hDeviceContext; PSMgmtObject pMgmt = pDevice->pMgmt; PSTxMgmtPacket pTxPacket = NULL; memset(pMgmt->pbyPSPacketPool, 0, sizeof(STxMgmtPacket) + WLAN_HDR_ADDR2_LEN); pTxPacket = (PSTxMgmtPacket)pMgmt->pbyPSPacketPool; pTxPacket->p80211Header = (PUWLAN_80211HDR)((unsigned char *)pTxPacket + sizeof(STxMgmtPacket)); pTxPacket->p80211Header->sA2.wFrameCtl = cpu_to_le16( ( WLAN_SET_FC_FTYPE(WLAN_TYPE_CTL) | WLAN_SET_FC_FSTYPE(WLAN_FSTYPE_PSPOLL) | WLAN_SET_FC_PWRMGT(0) )); pTxPacket->p80211Header->sA2.wDurationID = pMgmt->wCurrAID | BIT14 | BIT15; memcpy(pTxPacket->p80211Header->sA2.abyAddr1, pMgmt->abyCurrBSSID, WLAN_ADDR_LEN); memcpy(pTxPacket->p80211Header->sA2.abyAddr2, pMgmt->abyMACAddr, WLAN_ADDR_LEN); pTxPacket->cbMPDULen = WLAN_HDR_ADDR2_LEN; pTxPacket->cbPayloadLen = 0; // send the frame if (csMgmt_xmit(pDevice, pTxPacket) != CMD_STATUS_PENDING) { DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Send PS-Poll packet failed..\n"); } else { // DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Send PS-Poll packet success..\n"); }; return; } /*+ * * Routine Description: * Send NULL packet to AP for notification power state of STA * * Return Value: * None. * -*/ bool PSbSendNullPacket( void *hDeviceContext ) { PSDevice pDevice = (PSDevice)hDeviceContext; PSTxMgmtPacket pTxPacket = NULL; PSMgmtObject pMgmt = pDevice->pMgmt; unsigned int uIdx; if (pDevice->bLinkPass == false) { return false; } #ifdef TxInSleep if ((pDevice->bEnablePSMode == false) && (pDevice->fTxDataInSleep == false)) { return false; } #else if (pDevice->bEnablePSMode == false) { return false; } #endif if (pDevice->bEnablePSMode) { for (uIdx = 0; uIdx < TYPE_MAXTD; uIdx++) { if (pDevice->iTDUsed[uIdx] != 0) return false; } } memset(pMgmt->pbyPSPacketPool, 0, sizeof(STxMgmtPacket) + WLAN_NULLDATA_FR_MAXLEN); pTxPacket = (PSTxMgmtPacket)pMgmt->pbyPSPacketPool; pTxPacket->p80211Header = (PUWLAN_80211HDR)((unsigned char *)pTxPacket + sizeof(STxMgmtPacket)); if (pDevice->bEnablePSMode) { pTxPacket->p80211Header->sA3.wFrameCtl = cpu_to_le16( ( WLAN_SET_FC_FTYPE(WLAN_TYPE_DATA) | WLAN_SET_FC_FSTYPE(WLAN_FSTYPE_NULL) | WLAN_SET_FC_PWRMGT(1) )); } else { pTxPacket->p80211Header->sA3.wFrameCtl = cpu_to_le16( ( WLAN_SET_FC_FTYPE(WLAN_TYPE_DATA) | WLAN_SET_FC_FSTYPE(WLAN_FSTYPE_NULL) | WLAN_SET_FC_PWRMGT(0) )); } if (pMgmt->eCurrMode != WMAC_MODE_IBSS_STA) { pTxPacket->p80211Header->sA3.wFrameCtl |= cpu_to_le16((unsigned short)WLAN_SET_FC_TODS(1)); } memcpy(pTxPacket->p80211Header->sA3.abyAddr1, pMgmt->abyCurrBSSID, WLAN_ADDR_LEN); memcpy(pTxPacket->p80211Header->sA3.abyAddr2, pMgmt->abyMACAddr, WLAN_ADDR_LEN); memcpy(pTxPacket->p80211Header->sA3.abyAddr3, pMgmt->abyCurrBSSID, WLAN_BSSID_LEN); pTxPacket->cbMPDULen = WLAN_HDR_ADDR3_LEN; pTxPacket->cbPayloadLen = 0; // send the frame if (csMgmt_xmit(pDevice, pTxPacket) != CMD_STATUS_PENDING) { DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Send Null Packet failed !\n"); return false; } else { // DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Send Null Packet success....\n"); } return true; } /*+ * * Routine Description: * Check if Next TBTT must wake up * * Return Value: * None. * -*/ bool PSbIsNextTBTTWakeUp( void *hDeviceContext ) { PSDevice pDevice = (PSDevice)hDeviceContext; PSMgmtObject pMgmt = pDevice->pMgmt; bool bWakeUp = false; if (pMgmt->wListenInterval >= 2) { if (pMgmt->wCountToWakeUp == 0) { pMgmt->wCountToWakeUp = pMgmt->wListenInterval; } pMgmt->wCountToWakeUp--; if (pMgmt->wCountToWakeUp == 1) { // Turn on wake up to listen next beacon MACvRegBitsOn(pDevice->PortOffset, MAC_REG_PSCTL, PSCTL_LNBCN); bWakeUp = true; } } return bWakeUp; }
gpl-2.0
defreez/thesis-ics-kernel
arch/arm/mach-davinci/board-da830-evm.c
2319
17320
/* * TI DA830/OMAP L137 EVM board * * Author: Mark A. Greer <mgreer@mvista.com> * Derived from: arch/arm/mach-davinci/board-dm644x-evm.c * * 2007, 2009 (c) MontaVista Software, Inc. This file is licensed under * the terms of the GNU General Public License version 2. This program * is licensed "as is" without any warranty of any kind, whether express * or implied. */ #include <linux/kernel.h> #include <linux/init.h> #include <linux/console.h> #include <linux/interrupt.h> #include <linux/gpio.h> #include <linux/platform_device.h> #include <linux/i2c.h> #include <linux/i2c/pcf857x.h> #include <linux/i2c/at24.h> #include <linux/mtd/mtd.h> #include <linux/mtd/partitions.h> #include <linux/spi/spi.h> #include <linux/spi/flash.h> #include <asm/mach-types.h> #include <asm/mach/arch.h> #include <mach/cp_intc.h> #include <mach/mux.h> #include <mach/nand.h> #include <mach/da8xx.h> #include <mach/usb.h> #include <mach/aemif.h> #include <mach/spi.h> #define DA830_EVM_PHY_ID "" /* * USB1 VBUS is controlled by GPIO1[15], over-current is reported on GPIO2[4]. */ #define ON_BD_USB_DRV GPIO_TO_PIN(1, 15) #define ON_BD_USB_OVC GPIO_TO_PIN(2, 4) static const short da830_evm_usb11_pins[] = { DA830_GPIO1_15, DA830_GPIO2_4, -1 }; static da8xx_ocic_handler_t da830_evm_usb_ocic_handler; static int da830_evm_usb_set_power(unsigned port, int on) { gpio_set_value(ON_BD_USB_DRV, on); return 0; } static int da830_evm_usb_get_power(unsigned port) { return gpio_get_value(ON_BD_USB_DRV); } static int da830_evm_usb_get_oci(unsigned port) { return !gpio_get_value(ON_BD_USB_OVC); } static irqreturn_t da830_evm_usb_ocic_irq(int, void *); static int da830_evm_usb_ocic_notify(da8xx_ocic_handler_t handler) { int irq = gpio_to_irq(ON_BD_USB_OVC); int error = 0; if (handler != NULL) { da830_evm_usb_ocic_handler = handler; error = request_irq(irq, da830_evm_usb_ocic_irq, IRQF_DISABLED | IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING, "OHCI over-current indicator", NULL); if (error) printk(KERN_ERR "%s: could not request IRQ to watch " "over-current indicator changes\n", __func__); } else free_irq(irq, NULL); return error; } static struct da8xx_ohci_root_hub da830_evm_usb11_pdata = { .set_power = da830_evm_usb_set_power, .get_power = da830_evm_usb_get_power, .get_oci = da830_evm_usb_get_oci, .ocic_notify = da830_evm_usb_ocic_notify, /* TPS2065 switch @ 5V */ .potpgt = (3 + 1) / 2, /* 3 ms max */ }; static irqreturn_t da830_evm_usb_ocic_irq(int irq, void *dev_id) { da830_evm_usb_ocic_handler(&da830_evm_usb11_pdata, 1); return IRQ_HANDLED; } static __init void da830_evm_usb_init(void) { u32 cfgchip2; int ret; /* * Set up USB clock/mode in the CFGCHIP2 register. * FYI: CFGCHIP2 is 0x0000ef00 initially. */ cfgchip2 = __raw_readl(DA8XX_SYSCFG0_VIRT(DA8XX_CFGCHIP2_REG)); /* USB2.0 PHY reference clock is 24 MHz */ cfgchip2 &= ~CFGCHIP2_REFFREQ; cfgchip2 |= CFGCHIP2_REFFREQ_24MHZ; /* * Select internal reference clock for USB 2.0 PHY * and use it as a clock source for USB 1.1 PHY * (this is the default setting anyway). */ cfgchip2 &= ~CFGCHIP2_USB1PHYCLKMUX; cfgchip2 |= CFGCHIP2_USB2PHYCLKMUX; /* * We have to override VBUS/ID signals when MUSB is configured into the * host-only mode -- ID pin will float if no cable is connected, so the * controller won't be able to drive VBUS thinking that it's a B-device. * Otherwise, we want to use the OTG mode and enable VBUS comparators. */ cfgchip2 &= ~CFGCHIP2_OTGMODE; #ifdef CONFIG_USB_MUSB_HOST cfgchip2 |= CFGCHIP2_FORCE_HOST; #else cfgchip2 |= CFGCHIP2_SESENDEN | CFGCHIP2_VBDTCTEN; #endif __raw_writel(cfgchip2, DA8XX_SYSCFG0_VIRT(DA8XX_CFGCHIP2_REG)); /* USB_REFCLKIN is not used. */ ret = davinci_cfg_reg(DA830_USB0_DRVVBUS); if (ret) pr_warning("%s: USB 2.0 PinMux setup failed: %d\n", __func__, ret); else { /* * TPS2065 switch @ 5V supplies 1 A (sustains 1.5 A), * with the power on to power good time of 3 ms. */ ret = da8xx_register_usb20(1000, 3); if (ret) pr_warning("%s: USB 2.0 registration failed: %d\n", __func__, ret); } ret = davinci_cfg_reg_list(da830_evm_usb11_pins); if (ret) { pr_warning("%s: USB 1.1 PinMux setup failed: %d\n", __func__, ret); return; } ret = gpio_request(ON_BD_USB_DRV, "ON_BD_USB_DRV"); if (ret) { printk(KERN_ERR "%s: failed to request GPIO for USB 1.1 port " "power control: %d\n", __func__, ret); return; } gpio_direction_output(ON_BD_USB_DRV, 0); ret = gpio_request(ON_BD_USB_OVC, "ON_BD_USB_OVC"); if (ret) { printk(KERN_ERR "%s: failed to request GPIO for USB 1.1 port " "over-current indicator: %d\n", __func__, ret); return; } gpio_direction_input(ON_BD_USB_OVC); ret = da8xx_register_usb11(&da830_evm_usb11_pdata); if (ret) pr_warning("%s: USB 1.1 registration failed: %d\n", __func__, ret); } static struct davinci_uart_config da830_evm_uart_config __initdata = { .enabled_uarts = 0x7, }; static const short da830_evm_mcasp1_pins[] = { DA830_AHCLKX1, DA830_ACLKX1, DA830_AFSX1, DA830_AHCLKR1, DA830_AFSR1, DA830_AMUTE1, DA830_AXR1_0, DA830_AXR1_1, DA830_AXR1_2, DA830_AXR1_5, DA830_ACLKR1, DA830_AXR1_6, DA830_AXR1_7, DA830_AXR1_8, DA830_AXR1_10, DA830_AXR1_11, -1 }; static u8 da830_iis_serializer_direction[] = { RX_MODE, INACTIVE_MODE, INACTIVE_MODE, INACTIVE_MODE, INACTIVE_MODE, TX_MODE, INACTIVE_MODE, INACTIVE_MODE, INACTIVE_MODE, INACTIVE_MODE, INACTIVE_MODE, INACTIVE_MODE, }; static struct snd_platform_data da830_evm_snd_data = { .tx_dma_offset = 0x2000, .rx_dma_offset = 0x2000, .op_mode = DAVINCI_MCASP_IIS_MODE, .num_serializer = ARRAY_SIZE(da830_iis_serializer_direction), .tdm_slots = 2, .serial_dir = da830_iis_serializer_direction, .asp_chan_q = EVENTQ_0, .version = MCASP_VERSION_2, .txnumevt = 1, .rxnumevt = 1, }; /* * GPIO2[1] is used as MMC_SD_WP and GPIO2[2] as MMC_SD_INS. */ static const short da830_evm_mmc_sd_pins[] = { DA830_MMCSD_DAT_0, DA830_MMCSD_DAT_1, DA830_MMCSD_DAT_2, DA830_MMCSD_DAT_3, DA830_MMCSD_DAT_4, DA830_MMCSD_DAT_5, DA830_MMCSD_DAT_6, DA830_MMCSD_DAT_7, DA830_MMCSD_CLK, DA830_MMCSD_CMD, DA830_GPIO2_1, DA830_GPIO2_2, -1 }; #define DA830_MMCSD_WP_PIN GPIO_TO_PIN(2, 1) #define DA830_MMCSD_CD_PIN GPIO_TO_PIN(2, 2) static int da830_evm_mmc_get_ro(int index) { return gpio_get_value(DA830_MMCSD_WP_PIN); } static int da830_evm_mmc_get_cd(int index) { return !gpio_get_value(DA830_MMCSD_CD_PIN); } static struct davinci_mmc_config da830_evm_mmc_config = { .get_ro = da830_evm_mmc_get_ro, .get_cd = da830_evm_mmc_get_cd, .wires = 8, .max_freq = 50000000, .caps = MMC_CAP_MMC_HIGHSPEED | MMC_CAP_SD_HIGHSPEED, .version = MMC_CTLR_VERSION_2, }; static inline void da830_evm_init_mmc(void) { int ret; ret = davinci_cfg_reg_list(da830_evm_mmc_sd_pins); if (ret) { pr_warning("da830_evm_init: mmc/sd mux setup failed: %d\n", ret); return; } ret = gpio_request(DA830_MMCSD_WP_PIN, "MMC WP"); if (ret) { pr_warning("da830_evm_init: can not open GPIO %d\n", DA830_MMCSD_WP_PIN); return; } gpio_direction_input(DA830_MMCSD_WP_PIN); ret = gpio_request(DA830_MMCSD_CD_PIN, "MMC CD\n"); if (ret) { pr_warning("da830_evm_init: can not open GPIO %d\n", DA830_MMCSD_CD_PIN); return; } gpio_direction_input(DA830_MMCSD_CD_PIN); ret = da8xx_register_mmcsd0(&da830_evm_mmc_config); if (ret) { pr_warning("da830_evm_init: mmc/sd registration failed: %d\n", ret); gpio_free(DA830_MMCSD_WP_PIN); } } /* * UI board NAND/NOR flashes only use 8-bit data bus. */ static const short da830_evm_emif25_pins[] = { DA830_EMA_D_0, DA830_EMA_D_1, DA830_EMA_D_2, DA830_EMA_D_3, DA830_EMA_D_4, DA830_EMA_D_5, DA830_EMA_D_6, DA830_EMA_D_7, DA830_EMA_A_0, DA830_EMA_A_1, DA830_EMA_A_2, DA830_EMA_A_3, DA830_EMA_A_4, DA830_EMA_A_5, DA830_EMA_A_6, DA830_EMA_A_7, DA830_EMA_A_8, DA830_EMA_A_9, DA830_EMA_A_10, DA830_EMA_A_11, DA830_EMA_A_12, DA830_EMA_BA_0, DA830_EMA_BA_1, DA830_NEMA_WE, DA830_NEMA_CS_2, DA830_NEMA_CS_3, DA830_NEMA_OE, DA830_EMA_WAIT_0, -1 }; #if defined(CONFIG_MMC_DAVINCI) || defined(CONFIG_MMC_DAVINCI_MODULE) #define HAS_MMC 1 #else #define HAS_MMC 0 #endif #ifdef CONFIG_DA830_UI_NAND static struct mtd_partition da830_evm_nand_partitions[] = { /* bootloader (U-Boot, etc) in first sector */ [0] = { .name = "bootloader", .offset = 0, .size = SZ_128K, .mask_flags = MTD_WRITEABLE, /* force read-only */ }, /* bootloader params in the next sector */ [1] = { .name = "params", .offset = MTDPART_OFS_APPEND, .size = SZ_128K, .mask_flags = MTD_WRITEABLE, /* force read-only */ }, /* kernel */ [2] = { .name = "kernel", .offset = MTDPART_OFS_APPEND, .size = SZ_2M, .mask_flags = 0, }, /* file system */ [3] = { .name = "filesystem", .offset = MTDPART_OFS_APPEND, .size = MTDPART_SIZ_FULL, .mask_flags = 0, } }; /* flash bbt decriptors */ static uint8_t da830_evm_nand_bbt_pattern[] = { 'B', 'b', 't', '0' }; static uint8_t da830_evm_nand_mirror_pattern[] = { '1', 't', 'b', 'B' }; static struct nand_bbt_descr da830_evm_nand_bbt_main_descr = { .options = NAND_BBT_LASTBLOCK | NAND_BBT_CREATE | NAND_BBT_WRITE | NAND_BBT_2BIT | NAND_BBT_VERSION | NAND_BBT_PERCHIP, .offs = 2, .len = 4, .veroffs = 16, .maxblocks = 4, .pattern = da830_evm_nand_bbt_pattern }; static struct nand_bbt_descr da830_evm_nand_bbt_mirror_descr = { .options = NAND_BBT_LASTBLOCK | NAND_BBT_CREATE | NAND_BBT_WRITE | NAND_BBT_2BIT | NAND_BBT_VERSION | NAND_BBT_PERCHIP, .offs = 2, .len = 4, .veroffs = 16, .maxblocks = 4, .pattern = da830_evm_nand_mirror_pattern }; static struct davinci_aemif_timing da830_evm_nandflash_timing = { .wsetup = 24, .wstrobe = 21, .whold = 14, .rsetup = 19, .rstrobe = 50, .rhold = 0, .ta = 20, }; static struct davinci_nand_pdata da830_evm_nand_pdata = { .parts = da830_evm_nand_partitions, .nr_parts = ARRAY_SIZE(da830_evm_nand_partitions), .ecc_mode = NAND_ECC_HW, .ecc_bits = 4, .options = NAND_USE_FLASH_BBT, .bbt_td = &da830_evm_nand_bbt_main_descr, .bbt_md = &da830_evm_nand_bbt_mirror_descr, .timing = &da830_evm_nandflash_timing, }; static struct resource da830_evm_nand_resources[] = { [0] = { /* First memory resource is NAND I/O window */ .start = DA8XX_AEMIF_CS3_BASE, .end = DA8XX_AEMIF_CS3_BASE + PAGE_SIZE - 1, .flags = IORESOURCE_MEM, }, [1] = { /* Second memory resource is AEMIF control registers */ .start = DA8XX_AEMIF_CTL_BASE, .end = DA8XX_AEMIF_CTL_BASE + SZ_32K - 1, .flags = IORESOURCE_MEM, }, }; static struct platform_device da830_evm_nand_device = { .name = "davinci_nand", .id = 1, .dev = { .platform_data = &da830_evm_nand_pdata, }, .num_resources = ARRAY_SIZE(da830_evm_nand_resources), .resource = da830_evm_nand_resources, }; static inline void da830_evm_init_nand(int mux_mode) { int ret; if (HAS_MMC) { pr_warning("WARNING: both MMC/SD and NAND are " "enabled, but they share AEMIF pins.\n" "\tDisable MMC/SD for NAND support.\n"); return; } ret = davinci_cfg_reg_list(da830_evm_emif25_pins); if (ret) pr_warning("da830_evm_init: emif25 mux setup failed: %d\n", ret); ret = platform_device_register(&da830_evm_nand_device); if (ret) pr_warning("da830_evm_init: NAND device not registered.\n"); gpio_direction_output(mux_mode, 1); } #else static inline void da830_evm_init_nand(int mux_mode) { } #endif #ifdef CONFIG_DA830_UI_LCD static inline void da830_evm_init_lcdc(int mux_mode) { int ret; ret = davinci_cfg_reg_list(da830_lcdcntl_pins); if (ret) pr_warning("da830_evm_init: lcdcntl mux setup failed: %d\n", ret); ret = da8xx_register_lcdc(&sharp_lcd035q3dg01_pdata); if (ret) pr_warning("da830_evm_init: lcd setup failed: %d\n", ret); gpio_direction_output(mux_mode, 0); } #else static inline void da830_evm_init_lcdc(int mux_mode) { } #endif static struct at24_platform_data da830_evm_i2c_eeprom_info = { .byte_len = SZ_256K / 8, .page_size = 64, .flags = AT24_FLAG_ADDR16, .setup = davinci_get_mac_addr, .context = (void *)0x7f00, }; static int __init da830_evm_ui_expander_setup(struct i2c_client *client, int gpio, unsigned ngpio, void *context) { gpio_request(gpio + 6, "UI MUX_MODE"); /* Drive mux mode low to match the default without UI card */ gpio_direction_output(gpio + 6, 0); da830_evm_init_lcdc(gpio + 6); da830_evm_init_nand(gpio + 6); return 0; } static int da830_evm_ui_expander_teardown(struct i2c_client *client, int gpio, unsigned ngpio, void *context) { gpio_free(gpio + 6); return 0; } static struct pcf857x_platform_data __initdata da830_evm_ui_expander_info = { .gpio_base = DAVINCI_N_GPIO, .setup = da830_evm_ui_expander_setup, .teardown = da830_evm_ui_expander_teardown, }; static struct i2c_board_info __initdata da830_evm_i2c_devices[] = { { I2C_BOARD_INFO("24c256", 0x50), .platform_data = &da830_evm_i2c_eeprom_info, }, { I2C_BOARD_INFO("tlv320aic3x", 0x18), }, { I2C_BOARD_INFO("pcf8574", 0x3f), .platform_data = &da830_evm_ui_expander_info, }, }; static struct davinci_i2c_platform_data da830_evm_i2c_0_pdata = { .bus_freq = 100, /* kHz */ .bus_delay = 0, /* usec */ }; /* * The following EDMA channels/slots are not being used by drivers (for * example: Timer, GPIO, UART events etc) on da830/omap-l137 EVM, hence * they are being reserved for codecs on the DSP side. */ static const s16 da830_dma_rsv_chans[][2] = { /* (offset, number) */ { 8, 2}, {12, 2}, {24, 4}, {30, 2}, {-1, -1} }; static const s16 da830_dma_rsv_slots[][2] = { /* (offset, number) */ { 8, 2}, {12, 2}, {24, 4}, {30, 26}, {-1, -1} }; static struct edma_rsv_info da830_edma_rsv[] = { { .rsv_chans = da830_dma_rsv_chans, .rsv_slots = da830_dma_rsv_slots, }, }; static struct mtd_partition da830evm_spiflash_part[] = { [0] = { .name = "DSP-UBL", .offset = 0, .size = SZ_8K, .mask_flags = MTD_WRITEABLE, }, [1] = { .name = "ARM-UBL", .offset = MTDPART_OFS_APPEND, .size = SZ_16K + SZ_8K, .mask_flags = MTD_WRITEABLE, }, [2] = { .name = "U-Boot", .offset = MTDPART_OFS_APPEND, .size = SZ_256K - SZ_32K, .mask_flags = MTD_WRITEABLE, }, [3] = { .name = "U-Boot-Environment", .offset = MTDPART_OFS_APPEND, .size = SZ_16K, .mask_flags = 0, }, [4] = { .name = "Kernel", .offset = MTDPART_OFS_APPEND, .size = MTDPART_SIZ_FULL, .mask_flags = 0, }, }; static struct flash_platform_data da830evm_spiflash_data = { .name = "m25p80", .parts = da830evm_spiflash_part, .nr_parts = ARRAY_SIZE(da830evm_spiflash_part), .type = "w25x32", }; static struct davinci_spi_config da830evm_spiflash_cfg = { .io_type = SPI_IO_TYPE_DMA, .c2tdelay = 8, .t2cdelay = 8, }; static struct spi_board_info da830evm_spi_info[] = { { .modalias = "m25p80", .platform_data = &da830evm_spiflash_data, .controller_data = &da830evm_spiflash_cfg, .mode = SPI_MODE_0, .max_speed_hz = 30000000, .bus_num = 0, .chip_select = 0, }, }; static __init void da830_evm_init(void) { struct davinci_soc_info *soc_info = &davinci_soc_info; int ret; ret = da830_register_edma(da830_edma_rsv); if (ret) pr_warning("da830_evm_init: edma registration failed: %d\n", ret); ret = davinci_cfg_reg_list(da830_i2c0_pins); if (ret) pr_warning("da830_evm_init: i2c0 mux setup failed: %d\n", ret); ret = da8xx_register_i2c(0, &da830_evm_i2c_0_pdata); if (ret) pr_warning("da830_evm_init: i2c0 registration failed: %d\n", ret); da830_evm_usb_init(); soc_info->emac_pdata->rmii_en = 1; soc_info->emac_pdata->phy_id = DA830_EVM_PHY_ID; ret = davinci_cfg_reg_list(da830_cpgmac_pins); if (ret) pr_warning("da830_evm_init: cpgmac mux setup failed: %d\n", ret); ret = da8xx_register_emac(); if (ret) pr_warning("da830_evm_init: emac registration failed: %d\n", ret); ret = da8xx_register_watchdog(); if (ret) pr_warning("da830_evm_init: watchdog registration failed: %d\n", ret); davinci_serial_init(&da830_evm_uart_config); i2c_register_board_info(1, da830_evm_i2c_devices, ARRAY_SIZE(da830_evm_i2c_devices)); ret = davinci_cfg_reg_list(da830_evm_mcasp1_pins); if (ret) pr_warning("da830_evm_init: mcasp1 mux setup failed: %d\n", ret); da8xx_register_mcasp(1, &da830_evm_snd_data); da830_evm_init_mmc(); ret = da8xx_register_rtc(); if (ret) pr_warning("da830_evm_init: rtc setup failed: %d\n", ret); ret = da8xx_register_spi(0, da830evm_spi_info, ARRAY_SIZE(da830evm_spi_info)); if (ret) pr_warning("da830_evm_init: spi 0 registration failed: %d\n", ret); } #ifdef CONFIG_SERIAL_8250_CONSOLE static int __init da830_evm_console_init(void) { if (!machine_is_davinci_da830_evm()) return 0; return add_preferred_console("ttyS", 2, "115200"); } console_initcall(da830_evm_console_init); #endif static void __init da830_evm_map_io(void) { da830_init(); } MACHINE_START(DAVINCI_DA830_EVM, "DaVinci DA830/OMAP-L137/AM17x EVM") .boot_params = (DA8XX_DDR_BASE + 0x100), .map_io = da830_evm_map_io, .init_irq = cp_intc_init, .timer = &davinci_timer, .init_machine = da830_evm_init, MACHINE_END
gpl-2.0
kgp700/Neok-GNexroid-JB
drivers/net/wireless/b43/xmit.c
2319
24230
/* Broadcom B43 wireless driver Transmission (TX/RX) related functions. Copyright (C) 2005 Martin Langer <martin-langer@gmx.de> Copyright (C) 2005 Stefano Brivio <stefano.brivio@polimi.it> Copyright (C) 2005, 2006 Michael Buesch <mb@bu3sch.de> Copyright (C) 2005 Danny van Dyk <kugelfang@gentoo.org> Copyright (C) 2005 Andreas Jaggi <andreas.jaggi@waterwave.ch> This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Steet, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "xmit.h" #include "phy_common.h" #include "dma.h" #include "pio.h" static const struct b43_tx_legacy_rate_phy_ctl_entry b43_tx_legacy_rate_phy_ctl[] = { { B43_CCK_RATE_1MB, 0x0, 0x0 }, { B43_CCK_RATE_2MB, 0x0, 0x1 }, { B43_CCK_RATE_5MB, 0x0, 0x2 }, { B43_CCK_RATE_11MB, 0x0, 0x3 }, { B43_OFDM_RATE_6MB, B43_TXH_PHY1_CRATE_1_2, B43_TXH_PHY1_MODUL_BPSK }, { B43_OFDM_RATE_9MB, B43_TXH_PHY1_CRATE_3_4, B43_TXH_PHY1_MODUL_BPSK }, { B43_OFDM_RATE_12MB, B43_TXH_PHY1_CRATE_1_2, B43_TXH_PHY1_MODUL_QPSK }, { B43_OFDM_RATE_18MB, B43_TXH_PHY1_CRATE_3_4, B43_TXH_PHY1_MODUL_QPSK }, { B43_OFDM_RATE_24MB, B43_TXH_PHY1_CRATE_1_2, B43_TXH_PHY1_MODUL_QAM16 }, { B43_OFDM_RATE_36MB, B43_TXH_PHY1_CRATE_3_4, B43_TXH_PHY1_MODUL_QAM16 }, { B43_OFDM_RATE_48MB, B43_TXH_PHY1_CRATE_2_3, B43_TXH_PHY1_MODUL_QAM64 }, { B43_OFDM_RATE_54MB, B43_TXH_PHY1_CRATE_3_4, B43_TXH_PHY1_MODUL_QAM64 }, }; static const struct b43_tx_legacy_rate_phy_ctl_entry * b43_tx_legacy_rate_phy_ctl_ent(u8 bitrate) { const struct b43_tx_legacy_rate_phy_ctl_entry *e; unsigned int i; for (i = 0; i < ARRAY_SIZE(b43_tx_legacy_rate_phy_ctl); i++) { e = &(b43_tx_legacy_rate_phy_ctl[i]); if (e->bitrate == bitrate) return e; } B43_WARN_ON(1); return NULL; } /* Extract the bitrate index out of a CCK PLCP header. */ static int b43_plcp_get_bitrate_idx_cck(struct b43_plcp_hdr6 *plcp) { switch (plcp->raw[0]) { case 0x0A: return 0; case 0x14: return 1; case 0x37: return 2; case 0x6E: return 3; } return -1; } /* Extract the bitrate index out of an OFDM PLCP header. */ static int b43_plcp_get_bitrate_idx_ofdm(struct b43_plcp_hdr6 *plcp, bool aphy) { int base = aphy ? 0 : 4; switch (plcp->raw[0] & 0xF) { case 0xB: return base + 0; case 0xF: return base + 1; case 0xA: return base + 2; case 0xE: return base + 3; case 0x9: return base + 4; case 0xD: return base + 5; case 0x8: return base + 6; case 0xC: return base + 7; } return -1; } u8 b43_plcp_get_ratecode_cck(const u8 bitrate) { switch (bitrate) { case B43_CCK_RATE_1MB: return 0x0A; case B43_CCK_RATE_2MB: return 0x14; case B43_CCK_RATE_5MB: return 0x37; case B43_CCK_RATE_11MB: return 0x6E; } B43_WARN_ON(1); return 0; } u8 b43_plcp_get_ratecode_ofdm(const u8 bitrate) { switch (bitrate) { case B43_OFDM_RATE_6MB: return 0xB; case B43_OFDM_RATE_9MB: return 0xF; case B43_OFDM_RATE_12MB: return 0xA; case B43_OFDM_RATE_18MB: return 0xE; case B43_OFDM_RATE_24MB: return 0x9; case B43_OFDM_RATE_36MB: return 0xD; case B43_OFDM_RATE_48MB: return 0x8; case B43_OFDM_RATE_54MB: return 0xC; } B43_WARN_ON(1); return 0; } void b43_generate_plcp_hdr(struct b43_plcp_hdr4 *plcp, const u16 octets, const u8 bitrate) { __u8 *raw = plcp->raw; if (b43_is_ofdm_rate(bitrate)) { u32 d; d = b43_plcp_get_ratecode_ofdm(bitrate); B43_WARN_ON(octets & 0xF000); d |= (octets << 5); plcp->data = cpu_to_le32(d); } else { u32 plen; plen = octets * 16 / bitrate; if ((octets * 16 % bitrate) > 0) { plen++; if ((bitrate == B43_CCK_RATE_11MB) && ((octets * 8 % 11) < 4)) { raw[1] = 0x84; } else raw[1] = 0x04; } else raw[1] = 0x04; plcp->data |= cpu_to_le32(plen << 16); raw[0] = b43_plcp_get_ratecode_cck(bitrate); } } static u16 b43_generate_tx_phy_ctl1(struct b43_wldev *dev, u8 bitrate) { const struct b43_phy *phy = &dev->phy; const struct b43_tx_legacy_rate_phy_ctl_entry *e; u16 control = 0; u16 bw; if (phy->type == B43_PHYTYPE_LP) bw = B43_TXH_PHY1_BW_20; else /* FIXME */ bw = B43_TXH_PHY1_BW_20; if (0) { /* FIXME: MIMO */ } else if (b43_is_cck_rate(bitrate) && phy->type != B43_PHYTYPE_LP) { control = bw; } else { control = bw; e = b43_tx_legacy_rate_phy_ctl_ent(bitrate); if (e) { control |= e->coding_rate; control |= e->modulation; } control |= B43_TXH_PHY1_MODE_SISO; } return control; } static u8 b43_calc_fallback_rate(u8 bitrate) { switch (bitrate) { case B43_CCK_RATE_1MB: return B43_CCK_RATE_1MB; case B43_CCK_RATE_2MB: return B43_CCK_RATE_1MB; case B43_CCK_RATE_5MB: return B43_CCK_RATE_2MB; case B43_CCK_RATE_11MB: return B43_CCK_RATE_5MB; case B43_OFDM_RATE_6MB: return B43_CCK_RATE_5MB; case B43_OFDM_RATE_9MB: return B43_OFDM_RATE_6MB; case B43_OFDM_RATE_12MB: return B43_OFDM_RATE_9MB; case B43_OFDM_RATE_18MB: return B43_OFDM_RATE_12MB; case B43_OFDM_RATE_24MB: return B43_OFDM_RATE_18MB; case B43_OFDM_RATE_36MB: return B43_OFDM_RATE_24MB; case B43_OFDM_RATE_48MB: return B43_OFDM_RATE_36MB; case B43_OFDM_RATE_54MB: return B43_OFDM_RATE_48MB; } B43_WARN_ON(1); return 0; } /* Generate a TX data header. */ int b43_generate_txhdr(struct b43_wldev *dev, u8 *_txhdr, struct sk_buff *skb_frag, struct ieee80211_tx_info *info, u16 cookie) { const unsigned char *fragment_data = skb_frag->data; unsigned int fragment_len = skb_frag->len; struct b43_txhdr *txhdr = (struct b43_txhdr *)_txhdr; const struct b43_phy *phy = &dev->phy; const struct ieee80211_hdr *wlhdr = (const struct ieee80211_hdr *)fragment_data; int use_encryption = !!info->control.hw_key; __le16 fctl = wlhdr->frame_control; struct ieee80211_rate *fbrate; u8 rate, rate_fb; int rate_ofdm, rate_fb_ofdm; unsigned int plcp_fragment_len; u32 mac_ctl = 0; u16 phy_ctl = 0; u8 extra_ft = 0; struct ieee80211_rate *txrate; struct ieee80211_tx_rate *rates; memset(txhdr, 0, sizeof(*txhdr)); txrate = ieee80211_get_tx_rate(dev->wl->hw, info); rate = txrate ? txrate->hw_value : B43_CCK_RATE_1MB; rate_ofdm = b43_is_ofdm_rate(rate); fbrate = ieee80211_get_alt_retry_rate(dev->wl->hw, info, 0) ? : txrate; rate_fb = fbrate->hw_value; rate_fb_ofdm = b43_is_ofdm_rate(rate_fb); if (rate_ofdm) txhdr->phy_rate = b43_plcp_get_ratecode_ofdm(rate); else txhdr->phy_rate = b43_plcp_get_ratecode_cck(rate); txhdr->mac_frame_ctl = wlhdr->frame_control; memcpy(txhdr->tx_receiver, wlhdr->addr1, 6); /* Calculate duration for fallback rate */ if ((rate_fb == rate) || (wlhdr->duration_id & cpu_to_le16(0x8000)) || (wlhdr->duration_id == cpu_to_le16(0))) { /* If the fallback rate equals the normal rate or the * dur_id field contains an AID, CFP magic or 0, * use the original dur_id field. */ txhdr->dur_fb = wlhdr->duration_id; } else { txhdr->dur_fb = ieee80211_generic_frame_duration( dev->wl->hw, info->control.vif, fragment_len, fbrate); } plcp_fragment_len = fragment_len + FCS_LEN; if (use_encryption) { u8 key_idx = info->control.hw_key->hw_key_idx; struct b43_key *key; int wlhdr_len; size_t iv_len; B43_WARN_ON(key_idx >= ARRAY_SIZE(dev->key)); key = &(dev->key[key_idx]); if (unlikely(!key->keyconf)) { /* This key is invalid. This might only happen * in a short timeframe after machine resume before * we were able to reconfigure keys. * Drop this packet completely. Do not transmit it * unencrypted to avoid leaking information. */ return -ENOKEY; } /* Hardware appends ICV. */ plcp_fragment_len += info->control.hw_key->icv_len; key_idx = b43_kidx_to_fw(dev, key_idx); mac_ctl |= (key_idx << B43_TXH_MAC_KEYIDX_SHIFT) & B43_TXH_MAC_KEYIDX; mac_ctl |= (key->algorithm << B43_TXH_MAC_KEYALG_SHIFT) & B43_TXH_MAC_KEYALG; wlhdr_len = ieee80211_hdrlen(fctl); if (key->algorithm == B43_SEC_ALGO_TKIP) { u16 phase1key[5]; int i; /* we give the phase1key and iv16 here, the key is stored in * shm. With that the hardware can do phase 2 and encryption. */ ieee80211_get_tkip_key(info->control.hw_key, skb_frag, IEEE80211_TKIP_P1_KEY, (u8*)phase1key); /* phase1key is in host endian. Copy to little-endian txhdr->iv. */ for (i = 0; i < 5; i++) { txhdr->iv[i * 2 + 0] = phase1key[i]; txhdr->iv[i * 2 + 1] = phase1key[i] >> 8; } /* iv16 */ memcpy(txhdr->iv + 10, ((u8 *) wlhdr) + wlhdr_len, 3); } else { iv_len = min((size_t) info->control.hw_key->iv_len, ARRAY_SIZE(txhdr->iv)); memcpy(txhdr->iv, ((u8 *) wlhdr) + wlhdr_len, iv_len); } } if (b43_is_old_txhdr_format(dev)) { b43_generate_plcp_hdr((struct b43_plcp_hdr4 *)(&txhdr->old_format.plcp), plcp_fragment_len, rate); } else { b43_generate_plcp_hdr((struct b43_plcp_hdr4 *)(&txhdr->new_format.plcp), plcp_fragment_len, rate); } b43_generate_plcp_hdr((struct b43_plcp_hdr4 *)(&txhdr->plcp_fb), plcp_fragment_len, rate_fb); /* Extra Frame Types */ if (rate_fb_ofdm) extra_ft |= B43_TXH_EFT_FB_OFDM; else extra_ft |= B43_TXH_EFT_FB_CCK; /* Set channel radio code. Note that the micrcode ORs 0x100 to * this value before comparing it to the value in SHM, if this * is a 5Ghz packet. */ txhdr->chan_radio_code = phy->channel; /* PHY TX Control word */ if (rate_ofdm) phy_ctl |= B43_TXH_PHY_ENC_OFDM; else phy_ctl |= B43_TXH_PHY_ENC_CCK; if (info->control.rates[0].flags & IEEE80211_TX_RC_USE_SHORT_PREAMBLE) phy_ctl |= B43_TXH_PHY_SHORTPRMBL; switch (b43_ieee80211_antenna_sanitize(dev, info->antenna_sel_tx)) { case 0: /* Default */ phy_ctl |= B43_TXH_PHY_ANT01AUTO; break; case 1: /* Antenna 0 */ phy_ctl |= B43_TXH_PHY_ANT0; break; case 2: /* Antenna 1 */ phy_ctl |= B43_TXH_PHY_ANT1; break; case 3: /* Antenna 2 */ phy_ctl |= B43_TXH_PHY_ANT2; break; case 4: /* Antenna 3 */ phy_ctl |= B43_TXH_PHY_ANT3; break; default: B43_WARN_ON(1); } rates = info->control.rates; /* MAC control */ if (!(info->flags & IEEE80211_TX_CTL_NO_ACK)) mac_ctl |= B43_TXH_MAC_ACK; /* use hardware sequence counter as the non-TID counter */ if (info->flags & IEEE80211_TX_CTL_ASSIGN_SEQ) mac_ctl |= B43_TXH_MAC_HWSEQ; if (info->flags & IEEE80211_TX_CTL_FIRST_FRAGMENT) mac_ctl |= B43_TXH_MAC_STMSDU; if (phy->type == B43_PHYTYPE_A) mac_ctl |= B43_TXH_MAC_5GHZ; /* Overwrite rates[0].count to make the retry calculation * in the tx status easier. need the actual retry limit to * detect whether the fallback rate was used. */ if ((rates[0].flags & IEEE80211_TX_RC_USE_RTS_CTS) || (rates[0].count <= dev->wl->hw->conf.long_frame_max_tx_count)) { rates[0].count = dev->wl->hw->conf.long_frame_max_tx_count; mac_ctl |= B43_TXH_MAC_LONGFRAME; } else { rates[0].count = dev->wl->hw->conf.short_frame_max_tx_count; } /* Generate the RTS or CTS-to-self frame */ if ((rates[0].flags & IEEE80211_TX_RC_USE_RTS_CTS) || (rates[0].flags & IEEE80211_TX_RC_USE_CTS_PROTECT)) { unsigned int len; struct ieee80211_hdr *hdr; int rts_rate, rts_rate_fb; int rts_rate_ofdm, rts_rate_fb_ofdm; struct b43_plcp_hdr6 *plcp; struct ieee80211_rate *rts_cts_rate; rts_cts_rate = ieee80211_get_rts_cts_rate(dev->wl->hw, info); rts_rate = rts_cts_rate ? rts_cts_rate->hw_value : B43_CCK_RATE_1MB; rts_rate_ofdm = b43_is_ofdm_rate(rts_rate); rts_rate_fb = b43_calc_fallback_rate(rts_rate); rts_rate_fb_ofdm = b43_is_ofdm_rate(rts_rate_fb); if (rates[0].flags & IEEE80211_TX_RC_USE_CTS_PROTECT) { struct ieee80211_cts *cts; if (b43_is_old_txhdr_format(dev)) { cts = (struct ieee80211_cts *) (txhdr->old_format.rts_frame); } else { cts = (struct ieee80211_cts *) (txhdr->new_format.rts_frame); } ieee80211_ctstoself_get(dev->wl->hw, info->control.vif, fragment_data, fragment_len, info, cts); mac_ctl |= B43_TXH_MAC_SENDCTS; len = sizeof(struct ieee80211_cts); } else { struct ieee80211_rts *rts; if (b43_is_old_txhdr_format(dev)) { rts = (struct ieee80211_rts *) (txhdr->old_format.rts_frame); } else { rts = (struct ieee80211_rts *) (txhdr->new_format.rts_frame); } ieee80211_rts_get(dev->wl->hw, info->control.vif, fragment_data, fragment_len, info, rts); mac_ctl |= B43_TXH_MAC_SENDRTS; len = sizeof(struct ieee80211_rts); } len += FCS_LEN; /* Generate the PLCP headers for the RTS/CTS frame */ if (b43_is_old_txhdr_format(dev)) plcp = &txhdr->old_format.rts_plcp; else plcp = &txhdr->new_format.rts_plcp; b43_generate_plcp_hdr((struct b43_plcp_hdr4 *)plcp, len, rts_rate); plcp = &txhdr->rts_plcp_fb; b43_generate_plcp_hdr((struct b43_plcp_hdr4 *)plcp, len, rts_rate_fb); if (b43_is_old_txhdr_format(dev)) { hdr = (struct ieee80211_hdr *) (&txhdr->old_format.rts_frame); } else { hdr = (struct ieee80211_hdr *) (&txhdr->new_format.rts_frame); } txhdr->rts_dur_fb = hdr->duration_id; if (rts_rate_ofdm) { extra_ft |= B43_TXH_EFT_RTS_OFDM; txhdr->phy_rate_rts = b43_plcp_get_ratecode_ofdm(rts_rate); } else { extra_ft |= B43_TXH_EFT_RTS_CCK; txhdr->phy_rate_rts = b43_plcp_get_ratecode_cck(rts_rate); } if (rts_rate_fb_ofdm) extra_ft |= B43_TXH_EFT_RTSFB_OFDM; else extra_ft |= B43_TXH_EFT_RTSFB_CCK; if (rates[0].flags & IEEE80211_TX_RC_USE_RTS_CTS && phy->type == B43_PHYTYPE_N) { txhdr->phy_ctl1_rts = cpu_to_le16( b43_generate_tx_phy_ctl1(dev, rts_rate)); txhdr->phy_ctl1_rts_fb = cpu_to_le16( b43_generate_tx_phy_ctl1(dev, rts_rate_fb)); } } /* Magic cookie */ if (b43_is_old_txhdr_format(dev)) txhdr->old_format.cookie = cpu_to_le16(cookie); else txhdr->new_format.cookie = cpu_to_le16(cookie); if (phy->type == B43_PHYTYPE_N) { txhdr->phy_ctl1 = cpu_to_le16(b43_generate_tx_phy_ctl1(dev, rate)); txhdr->phy_ctl1_fb = cpu_to_le16(b43_generate_tx_phy_ctl1(dev, rate_fb)); } /* Apply the bitfields */ txhdr->mac_ctl = cpu_to_le32(mac_ctl); txhdr->phy_ctl = cpu_to_le16(phy_ctl); txhdr->extra_ft = extra_ft; return 0; } static s8 b43_rssi_postprocess(struct b43_wldev *dev, u8 in_rssi, int ofdm, int adjust_2053, int adjust_2050) { struct b43_phy *phy = &dev->phy; struct b43_phy_g *gphy = phy->g; s32 tmp; switch (phy->radio_ver) { case 0x2050: if (ofdm) { tmp = in_rssi; if (tmp > 127) tmp -= 256; tmp *= 73; tmp /= 64; if (adjust_2050) tmp += 25; else tmp -= 3; } else { if (dev->sdev->bus->sprom. boardflags_lo & B43_BFL_RSSI) { if (in_rssi > 63) in_rssi = 63; B43_WARN_ON(phy->type != B43_PHYTYPE_G); tmp = gphy->nrssi_lt[in_rssi]; tmp = 31 - tmp; tmp *= -131; tmp /= 128; tmp -= 57; } else { tmp = in_rssi; tmp = 31 - tmp; tmp *= -149; tmp /= 128; tmp -= 68; } if (phy->type == B43_PHYTYPE_G && adjust_2050) tmp += 25; } break; case 0x2060: if (in_rssi > 127) tmp = in_rssi - 256; else tmp = in_rssi; break; default: tmp = in_rssi; tmp -= 11; tmp *= 103; tmp /= 64; if (adjust_2053) tmp -= 109; else tmp -= 83; } return (s8) tmp; } //TODO #if 0 static s8 b43_rssinoise_postprocess(struct b43_wldev *dev, u8 in_rssi) { struct b43_phy *phy = &dev->phy; s8 ret; if (phy->type == B43_PHYTYPE_A) { //TODO: Incomplete specs. ret = 0; } else ret = b43_rssi_postprocess(dev, in_rssi, 0, 1, 1); return ret; } #endif void b43_rx(struct b43_wldev *dev, struct sk_buff *skb, const void *_rxhdr) { struct ieee80211_rx_status status; struct b43_plcp_hdr6 *plcp; struct ieee80211_hdr *wlhdr; const struct b43_rxhdr_fw4 *rxhdr = _rxhdr; __le16 fctl; u16 phystat0, phystat3, chanstat, mactime; u32 macstat; u16 chanid; u16 phytype; int padding; memset(&status, 0, sizeof(status)); /* Get metadata about the frame from the header. */ phystat0 = le16_to_cpu(rxhdr->phy_status0); phystat3 = le16_to_cpu(rxhdr->phy_status3); macstat = le32_to_cpu(rxhdr->mac_status); mactime = le16_to_cpu(rxhdr->mac_time); chanstat = le16_to_cpu(rxhdr->channel); phytype = chanstat & B43_RX_CHAN_PHYTYPE; if (unlikely(macstat & B43_RX_MAC_FCSERR)) { dev->wl->ieee_stats.dot11FCSErrorCount++; status.flag |= RX_FLAG_FAILED_FCS_CRC; } if (unlikely(phystat0 & (B43_RX_PHYST0_PLCPHCF | B43_RX_PHYST0_PLCPFV))) status.flag |= RX_FLAG_FAILED_PLCP_CRC; if (phystat0 & B43_RX_PHYST0_SHORTPRMBL) status.flag |= RX_FLAG_SHORTPRE; if (macstat & B43_RX_MAC_DECERR) { /* Decryption with the given key failed. * Drop the packet. We also won't be able to decrypt it with * the key in software. */ goto drop; } /* Skip PLCP and padding */ padding = (macstat & B43_RX_MAC_PADDING) ? 2 : 0; if (unlikely(skb->len < (sizeof(struct b43_plcp_hdr6) + padding))) { b43dbg(dev->wl, "RX: Packet size underrun (1)\n"); goto drop; } plcp = (struct b43_plcp_hdr6 *)(skb->data + padding); skb_pull(skb, sizeof(struct b43_plcp_hdr6) + padding); /* The skb contains the Wireless Header + payload data now */ if (unlikely(skb->len < (2 + 2 + 6 /*minimum hdr */ + FCS_LEN))) { b43dbg(dev->wl, "RX: Packet size underrun (2)\n"); goto drop; } wlhdr = (struct ieee80211_hdr *)(skb->data); fctl = wlhdr->frame_control; if (macstat & B43_RX_MAC_DEC) { unsigned int keyidx; int wlhdr_len; keyidx = ((macstat & B43_RX_MAC_KEYIDX) >> B43_RX_MAC_KEYIDX_SHIFT); /* We must adjust the key index here. We want the "physical" * key index, but the ucode passed it slightly different. */ keyidx = b43_kidx_to_raw(dev, keyidx); B43_WARN_ON(keyidx >= ARRAY_SIZE(dev->key)); if (dev->key[keyidx].algorithm != B43_SEC_ALGO_NONE) { wlhdr_len = ieee80211_hdrlen(fctl); if (unlikely(skb->len < (wlhdr_len + 3))) { b43dbg(dev->wl, "RX: Packet size underrun (3)\n"); goto drop; } status.flag |= RX_FLAG_DECRYPTED; } } /* Link quality statistics */ if ((chanstat & B43_RX_CHAN_PHYTYPE) == B43_PHYTYPE_N) { // s8 rssi = max(rxhdr->power0, rxhdr->power1); //TODO: Find out what the rssi value is (dBm or percentage?) // and also find out what the maximum possible value is. // Fill status.ssi and status.signal fields. } else { status.signal = b43_rssi_postprocess(dev, rxhdr->jssi, (phystat0 & B43_RX_PHYST0_OFDM), (phystat0 & B43_RX_PHYST0_GAINCTL), (phystat3 & B43_RX_PHYST3_TRSTATE)); } if (phystat0 & B43_RX_PHYST0_OFDM) status.rate_idx = b43_plcp_get_bitrate_idx_ofdm(plcp, phytype == B43_PHYTYPE_A); else status.rate_idx = b43_plcp_get_bitrate_idx_cck(plcp); if (unlikely(status.rate_idx == -1)) { /* PLCP seems to be corrupted. * Drop the frame, if we are not interested in corrupted frames. */ if (!(dev->wl->filter_flags & FIF_PLCPFAIL)) goto drop; } status.antenna = !!(phystat0 & B43_RX_PHYST0_ANT); /* * All frames on monitor interfaces and beacons always need a full * 64-bit timestamp. Monitor interfaces need it for diagnostic * purposes and beacons for IBSS merging. * This code assumes we get to process the packet within 16 bits * of timestamp, i.e. about 65 milliseconds after the PHY received * the first symbol. */ if (ieee80211_is_beacon(fctl) || dev->wl->radiotap_enabled) { u16 low_mactime_now; b43_tsf_read(dev, &status.mactime); low_mactime_now = status.mactime; status.mactime = status.mactime & ~0xFFFFULL; status.mactime += mactime; if (low_mactime_now <= mactime) status.mactime -= 0x10000; status.flag |= RX_FLAG_MACTIME_MPDU; } chanid = (chanstat & B43_RX_CHAN_ID) >> B43_RX_CHAN_ID_SHIFT; switch (chanstat & B43_RX_CHAN_PHYTYPE) { case B43_PHYTYPE_A: status.band = IEEE80211_BAND_5GHZ; B43_WARN_ON(1); /* FIXME: We don't really know which value the "chanid" contains. * So the following assignment might be wrong. */ status.freq = b43_channel_to_freq_5ghz(chanid); break; case B43_PHYTYPE_G: status.band = IEEE80211_BAND_2GHZ; /* chanid is the radio channel cookie value as used * to tune the radio. */ status.freq = chanid + 2400; break; case B43_PHYTYPE_N: case B43_PHYTYPE_LP: /* chanid is the SHM channel cookie. Which is the plain * channel number in b43. */ if (chanstat & B43_RX_CHAN_5GHZ) { status.band = IEEE80211_BAND_5GHZ; status.freq = b43_freq_to_channel_5ghz(chanid); } else { status.band = IEEE80211_BAND_2GHZ; status.freq = b43_freq_to_channel_2ghz(chanid); } break; default: B43_WARN_ON(1); goto drop; } memcpy(IEEE80211_SKB_RXCB(skb), &status, sizeof(status)); ieee80211_rx_ni(dev->wl->hw, skb); #if B43_DEBUG dev->rx_count++; #endif return; drop: b43dbg(dev->wl, "RX: Packet dropped\n"); dev_kfree_skb_any(skb); } void b43_handle_txstatus(struct b43_wldev *dev, const struct b43_txstatus *status) { b43_debugfs_log_txstat(dev, status); if (status->intermediate) return; if (status->for_ampdu) return; if (!status->acked) dev->wl->ieee_stats.dot11ACKFailureCount++; if (status->rts_count) { if (status->rts_count == 0xF) //FIXME dev->wl->ieee_stats.dot11RTSFailureCount++; else dev->wl->ieee_stats.dot11RTSSuccessCount++; } if (b43_using_pio_transfers(dev)) b43_pio_handle_txstatus(dev, status); else b43_dma_handle_txstatus(dev, status); b43_phy_txpower_check(dev, 0); } /* Fill out the mac80211 TXstatus report based on the b43-specific * txstatus report data. This returns a boolean whether the frame was * successfully transmitted. */ bool b43_fill_txstatus_report(struct b43_wldev *dev, struct ieee80211_tx_info *report, const struct b43_txstatus *status) { bool frame_success = 1; int retry_limit; /* preserve the confiured retry limit before clearing the status * The xmit function has overwritten the rc's value with the actual * retry limit done by the hardware */ retry_limit = report->status.rates[0].count; ieee80211_tx_info_clear_status(report); if (status->acked) { /* The frame was ACKed. */ report->flags |= IEEE80211_TX_STAT_ACK; } else { /* The frame was not ACKed... */ if (!(report->flags & IEEE80211_TX_CTL_NO_ACK)) { /* ...but we expected an ACK. */ frame_success = 0; } } if (status->frame_count == 0) { /* The frame was not transmitted at all. */ report->status.rates[0].count = 0; } else if (status->rts_count > dev->wl->hw->conf.short_frame_max_tx_count) { /* * If the short retries (RTS, not data frame) have exceeded * the limit, the hw will not have tried the selected rate, * but will have used the fallback rate instead. * Don't let the rate control count attempts for the selected * rate in this case, otherwise the statistics will be off. */ report->status.rates[0].count = 0; report->status.rates[1].count = status->frame_count; } else { if (status->frame_count > retry_limit) { report->status.rates[0].count = retry_limit; report->status.rates[1].count = status->frame_count - retry_limit; } else { report->status.rates[0].count = status->frame_count; report->status.rates[1].idx = -1; } } return frame_success; } /* Stop any TX operation on the device (suspend the hardware queues) */ void b43_tx_suspend(struct b43_wldev *dev) { if (b43_using_pio_transfers(dev)) b43_pio_tx_suspend(dev); else b43_dma_tx_suspend(dev); } /* Resume any TX operation on the device (resume the hardware queues) */ void b43_tx_resume(struct b43_wldev *dev) { if (b43_using_pio_transfers(dev)) b43_pio_tx_resume(dev); else b43_dma_tx_resume(dev); }
gpl-2.0
MoKee/android_kernel_samsung_crespo
arch/powerpc/platforms/85xx/socrates_fpga_pic.c
2831
8543
/* * Copyright (C) 2008 Ilya Yanok, Emcraft Systems * * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 as * published by the Free Software Foundation. * */ #include <linux/irq.h> #include <linux/of_platform.h> #include <linux/io.h> /* * The FPGA supports 9 interrupt sources, which can be routed to 3 * interrupt request lines of the MPIC. The line to be used can be * specified through the third cell of FDT property "interrupts". */ #define SOCRATES_FPGA_NUM_IRQS 9 #define FPGA_PIC_IRQCFG (0x0) #define FPGA_PIC_IRQMASK(n) (0x4 + 0x4 * (n)) #define SOCRATES_FPGA_IRQ_MASK ((1 << SOCRATES_FPGA_NUM_IRQS) - 1) struct socrates_fpga_irq_info { unsigned int irq_line; int type; }; /* * Interrupt routing and type table * * IRQ_TYPE_NONE means the interrupt type is configurable, * otherwise it's fixed to the specified value. */ static struct socrates_fpga_irq_info fpga_irqs[SOCRATES_FPGA_NUM_IRQS] = { [0] = {0, IRQ_TYPE_NONE}, [1] = {0, IRQ_TYPE_LEVEL_HIGH}, [2] = {0, IRQ_TYPE_LEVEL_LOW}, [3] = {0, IRQ_TYPE_NONE}, [4] = {0, IRQ_TYPE_NONE}, [5] = {0, IRQ_TYPE_NONE}, [6] = {0, IRQ_TYPE_NONE}, [7] = {0, IRQ_TYPE_NONE}, [8] = {0, IRQ_TYPE_LEVEL_HIGH}, }; static DEFINE_RAW_SPINLOCK(socrates_fpga_pic_lock); static void __iomem *socrates_fpga_pic_iobase; static struct irq_host *socrates_fpga_pic_irq_host; static unsigned int socrates_fpga_irqs[3]; static inline uint32_t socrates_fpga_pic_read(int reg) { return in_be32(socrates_fpga_pic_iobase + reg); } static inline void socrates_fpga_pic_write(int reg, uint32_t val) { out_be32(socrates_fpga_pic_iobase + reg, val); } static inline unsigned int socrates_fpga_pic_get_irq(unsigned int irq) { uint32_t cause; unsigned long flags; int i; /* Check irq line routed to the MPIC */ for (i = 0; i < 3; i++) { if (irq == socrates_fpga_irqs[i]) break; } if (i == 3) return NO_IRQ; raw_spin_lock_irqsave(&socrates_fpga_pic_lock, flags); cause = socrates_fpga_pic_read(FPGA_PIC_IRQMASK(i)); raw_spin_unlock_irqrestore(&socrates_fpga_pic_lock, flags); for (i = SOCRATES_FPGA_NUM_IRQS - 1; i >= 0; i--) { if (cause >> (i + 16)) break; } return irq_linear_revmap(socrates_fpga_pic_irq_host, (irq_hw_number_t)i); } void socrates_fpga_pic_cascade(unsigned int irq, struct irq_desc *desc) { struct irq_chip *chip = irq_desc_get_chip(desc); unsigned int cascade_irq; /* * See if we actually have an interrupt, call generic handling code if * we do. */ cascade_irq = socrates_fpga_pic_get_irq(irq); if (cascade_irq != NO_IRQ) generic_handle_irq(cascade_irq); chip->irq_eoi(&desc->irq_data); } static void socrates_fpga_pic_ack(struct irq_data *d) { unsigned long flags; unsigned int irq_line, hwirq = irqd_to_hwirq(d); uint32_t mask; irq_line = fpga_irqs[hwirq].irq_line; raw_spin_lock_irqsave(&socrates_fpga_pic_lock, flags); mask = socrates_fpga_pic_read(FPGA_PIC_IRQMASK(irq_line)) & SOCRATES_FPGA_IRQ_MASK; mask |= (1 << (hwirq + 16)); socrates_fpga_pic_write(FPGA_PIC_IRQMASK(irq_line), mask); raw_spin_unlock_irqrestore(&socrates_fpga_pic_lock, flags); } static void socrates_fpga_pic_mask(struct irq_data *d) { unsigned long flags; unsigned int hwirq = irqd_to_hwirq(d); int irq_line; u32 mask; irq_line = fpga_irqs[hwirq].irq_line; raw_spin_lock_irqsave(&socrates_fpga_pic_lock, flags); mask = socrates_fpga_pic_read(FPGA_PIC_IRQMASK(irq_line)) & SOCRATES_FPGA_IRQ_MASK; mask &= ~(1 << hwirq); socrates_fpga_pic_write(FPGA_PIC_IRQMASK(irq_line), mask); raw_spin_unlock_irqrestore(&socrates_fpga_pic_lock, flags); } static void socrates_fpga_pic_mask_ack(struct irq_data *d) { unsigned long flags; unsigned int hwirq = irqd_to_hwirq(d); int irq_line; u32 mask; irq_line = fpga_irqs[hwirq].irq_line; raw_spin_lock_irqsave(&socrates_fpga_pic_lock, flags); mask = socrates_fpga_pic_read(FPGA_PIC_IRQMASK(irq_line)) & SOCRATES_FPGA_IRQ_MASK; mask &= ~(1 << hwirq); mask |= (1 << (hwirq + 16)); socrates_fpga_pic_write(FPGA_PIC_IRQMASK(irq_line), mask); raw_spin_unlock_irqrestore(&socrates_fpga_pic_lock, flags); } static void socrates_fpga_pic_unmask(struct irq_data *d) { unsigned long flags; unsigned int hwirq = irqd_to_hwirq(d); int irq_line; u32 mask; irq_line = fpga_irqs[hwirq].irq_line; raw_spin_lock_irqsave(&socrates_fpga_pic_lock, flags); mask = socrates_fpga_pic_read(FPGA_PIC_IRQMASK(irq_line)) & SOCRATES_FPGA_IRQ_MASK; mask |= (1 << hwirq); socrates_fpga_pic_write(FPGA_PIC_IRQMASK(irq_line), mask); raw_spin_unlock_irqrestore(&socrates_fpga_pic_lock, flags); } static void socrates_fpga_pic_eoi(struct irq_data *d) { unsigned long flags; unsigned int hwirq = irqd_to_hwirq(d); int irq_line; u32 mask; irq_line = fpga_irqs[hwirq].irq_line; raw_spin_lock_irqsave(&socrates_fpga_pic_lock, flags); mask = socrates_fpga_pic_read(FPGA_PIC_IRQMASK(irq_line)) & SOCRATES_FPGA_IRQ_MASK; mask |= (1 << (hwirq + 16)); socrates_fpga_pic_write(FPGA_PIC_IRQMASK(irq_line), mask); raw_spin_unlock_irqrestore(&socrates_fpga_pic_lock, flags); } static int socrates_fpga_pic_set_type(struct irq_data *d, unsigned int flow_type) { unsigned long flags; unsigned int hwirq = irqd_to_hwirq(d); int polarity; u32 mask; if (fpga_irqs[hwirq].type != IRQ_TYPE_NONE) return -EINVAL; switch (flow_type & IRQ_TYPE_SENSE_MASK) { case IRQ_TYPE_LEVEL_HIGH: polarity = 1; break; case IRQ_TYPE_LEVEL_LOW: polarity = 0; break; default: return -EINVAL; } raw_spin_lock_irqsave(&socrates_fpga_pic_lock, flags); mask = socrates_fpga_pic_read(FPGA_PIC_IRQCFG); if (polarity) mask |= (1 << hwirq); else mask &= ~(1 << hwirq); socrates_fpga_pic_write(FPGA_PIC_IRQCFG, mask); raw_spin_unlock_irqrestore(&socrates_fpga_pic_lock, flags); return 0; } static struct irq_chip socrates_fpga_pic_chip = { .name = "FPGA-PIC", .irq_ack = socrates_fpga_pic_ack, .irq_mask = socrates_fpga_pic_mask, .irq_mask_ack = socrates_fpga_pic_mask_ack, .irq_unmask = socrates_fpga_pic_unmask, .irq_eoi = socrates_fpga_pic_eoi, .irq_set_type = socrates_fpga_pic_set_type, }; static int socrates_fpga_pic_host_map(struct irq_host *h, unsigned int virq, irq_hw_number_t hwirq) { /* All interrupts are LEVEL sensitive */ irq_set_status_flags(virq, IRQ_LEVEL); irq_set_chip_and_handler(virq, &socrates_fpga_pic_chip, handle_fasteoi_irq); return 0; } static int socrates_fpga_pic_host_xlate(struct irq_host *h, struct device_node *ct, const u32 *intspec, unsigned int intsize, irq_hw_number_t *out_hwirq, unsigned int *out_flags) { struct socrates_fpga_irq_info *fpga_irq = &fpga_irqs[intspec[0]]; *out_hwirq = intspec[0]; if (fpga_irq->type == IRQ_TYPE_NONE) { /* type is configurable */ if (intspec[1] != IRQ_TYPE_LEVEL_LOW && intspec[1] != IRQ_TYPE_LEVEL_HIGH) { pr_warning("FPGA PIC: invalid irq type, " "setting default active low\n"); *out_flags = IRQ_TYPE_LEVEL_LOW; } else { *out_flags = intspec[1]; } } else { /* type is fixed */ *out_flags = fpga_irq->type; } /* Use specified interrupt routing */ if (intspec[2] <= 2) fpga_irq->irq_line = intspec[2]; else pr_warning("FPGA PIC: invalid irq routing\n"); return 0; } static struct irq_host_ops socrates_fpga_pic_host_ops = { .map = socrates_fpga_pic_host_map, .xlate = socrates_fpga_pic_host_xlate, }; void socrates_fpga_pic_init(struct device_node *pic) { unsigned long flags; int i; /* Setup an irq_host structure */ socrates_fpga_pic_irq_host = irq_alloc_host(pic, IRQ_HOST_MAP_LINEAR, SOCRATES_FPGA_NUM_IRQS, &socrates_fpga_pic_host_ops, SOCRATES_FPGA_NUM_IRQS); if (socrates_fpga_pic_irq_host == NULL) { pr_err("FPGA PIC: Unable to allocate host\n"); return; } for (i = 0; i < 3; i++) { socrates_fpga_irqs[i] = irq_of_parse_and_map(pic, i); if (socrates_fpga_irqs[i] == NO_IRQ) { pr_warning("FPGA PIC: can't get irq%d.\n", i); continue; } irq_set_chained_handler(socrates_fpga_irqs[i], socrates_fpga_pic_cascade); } socrates_fpga_pic_iobase = of_iomap(pic, 0); raw_spin_lock_irqsave(&socrates_fpga_pic_lock, flags); socrates_fpga_pic_write(FPGA_PIC_IRQMASK(0), SOCRATES_FPGA_IRQ_MASK << 16); socrates_fpga_pic_write(FPGA_PIC_IRQMASK(1), SOCRATES_FPGA_IRQ_MASK << 16); socrates_fpga_pic_write(FPGA_PIC_IRQMASK(2), SOCRATES_FPGA_IRQ_MASK << 16); raw_spin_unlock_irqrestore(&socrates_fpga_pic_lock, flags); pr_info("FPGA PIC: Setting up Socrates FPGA PIC\n"); }
gpl-2.0
RittikBhowmik/Project-Crater-Kernel-GT-i9152
drivers/input/misc/pcspkr.c
3599
3442
/* * PC Speaker beeper driver for Linux * * Copyright (c) 2002 Vojtech Pavlik * Copyright (c) 1992 Orest Zborowski * */ /* * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 as published by * the Free Software Foundation */ #include <linux/kernel.h> #include <linux/module.h> #include <linux/init.h> #include <linux/input.h> #include <linux/platform_device.h> #include <linux/timex.h> #include <asm/io.h> MODULE_AUTHOR("Vojtech Pavlik <vojtech@ucw.cz>"); MODULE_DESCRIPTION("PC Speaker beeper driver"); MODULE_LICENSE("GPL"); MODULE_ALIAS("platform:pcspkr"); #if defined(CONFIG_MIPS) || defined(CONFIG_X86) /* Use the global PIT lock ! */ #include <asm/i8253.h> #else #include <asm/8253pit.h> static DEFINE_RAW_SPINLOCK(i8253_lock); #endif static int pcspkr_event(struct input_dev *dev, unsigned int type, unsigned int code, int value) { unsigned int count = 0; unsigned long flags; if (type != EV_SND) return -1; switch (code) { case SND_BELL: if (value) value = 1000; case SND_TONE: break; default: return -1; } if (value > 20 && value < 32767) count = PIT_TICK_RATE / value; raw_spin_lock_irqsave(&i8253_lock, flags); if (count) { /* set command for counter 2, 2 byte write */ outb_p(0xB6, 0x43); /* select desired HZ */ outb_p(count & 0xff, 0x42); outb((count >> 8) & 0xff, 0x42); /* enable counter 2 */ outb_p(inb_p(0x61) | 3, 0x61); } else { /* disable counter 2 */ outb(inb_p(0x61) & 0xFC, 0x61); } raw_spin_unlock_irqrestore(&i8253_lock, flags); return 0; } static int __devinit pcspkr_probe(struct platform_device *dev) { struct input_dev *pcspkr_dev; int err; pcspkr_dev = input_allocate_device(); if (!pcspkr_dev) return -ENOMEM; pcspkr_dev->name = "PC Speaker"; pcspkr_dev->phys = "isa0061/input0"; pcspkr_dev->id.bustype = BUS_ISA; pcspkr_dev->id.vendor = 0x001f; pcspkr_dev->id.product = 0x0001; pcspkr_dev->id.version = 0x0100; pcspkr_dev->dev.parent = &dev->dev; pcspkr_dev->evbit[0] = BIT_MASK(EV_SND); pcspkr_dev->sndbit[0] = BIT_MASK(SND_BELL) | BIT_MASK(SND_TONE); pcspkr_dev->event = pcspkr_event; err = input_register_device(pcspkr_dev); if (err) { input_free_device(pcspkr_dev); return err; } platform_set_drvdata(dev, pcspkr_dev); return 0; } static int __devexit pcspkr_remove(struct platform_device *dev) { struct input_dev *pcspkr_dev = platform_get_drvdata(dev); input_unregister_device(pcspkr_dev); platform_set_drvdata(dev, NULL); /* turn off the speaker */ pcspkr_event(NULL, EV_SND, SND_BELL, 0); return 0; } static int pcspkr_suspend(struct device *dev) { pcspkr_event(NULL, EV_SND, SND_BELL, 0); return 0; } static void pcspkr_shutdown(struct platform_device *dev) { /* turn off the speaker */ pcspkr_event(NULL, EV_SND, SND_BELL, 0); } static const struct dev_pm_ops pcspkr_pm_ops = { .suspend = pcspkr_suspend, }; static struct platform_driver pcspkr_platform_driver = { .driver = { .name = "pcspkr", .owner = THIS_MODULE, .pm = &pcspkr_pm_ops, }, .probe = pcspkr_probe, .remove = __devexit_p(pcspkr_remove), .shutdown = pcspkr_shutdown, }; static int __init pcspkr_init(void) { return platform_driver_register(&pcspkr_platform_driver); } static void __exit pcspkr_exit(void) { platform_driver_unregister(&pcspkr_platform_driver); } module_init(pcspkr_init); module_exit(pcspkr_exit);
gpl-2.0
MoKee/android_kernel_google_msm
drivers/staging/iio/accel/adis16240_ring.c
4879
3445
#include <linux/export.h> #include <linux/interrupt.h> #include <linux/mutex.h> #include <linux/kernel.h> #include <linux/spi/spi.h> #include <linux/slab.h> #include "../iio.h" #include "../ring_sw.h" #include "../trigger_consumer.h" #include "adis16240.h" /** * adis16240_read_ring_data() read data registers which will be placed into ring * @dev: device associated with child of actual device (iio_dev or iio_trig) * @rx: somewhere to pass back the value read **/ static int adis16240_read_ring_data(struct device *dev, u8 *rx) { struct spi_message msg; struct iio_dev *indio_dev = dev_get_drvdata(dev); struct adis16240_state *st = iio_priv(indio_dev); struct spi_transfer xfers[ADIS16240_OUTPUTS + 1]; int ret; int i; mutex_lock(&st->buf_lock); spi_message_init(&msg); memset(xfers, 0, sizeof(xfers)); for (i = 0; i <= ADIS16240_OUTPUTS; i++) { xfers[i].bits_per_word = 8; xfers[i].cs_change = 1; xfers[i].len = 2; xfers[i].delay_usecs = 30; xfers[i].tx_buf = st->tx + 2 * i; st->tx[2 * i] = ADIS16240_READ_REG(ADIS16240_SUPPLY_OUT + 2 * i); st->tx[2 * i + 1] = 0; if (i >= 1) xfers[i].rx_buf = rx + 2 * (i - 1); spi_message_add_tail(&xfers[i], &msg); } ret = spi_sync(st->us, &msg); if (ret) dev_err(&st->us->dev, "problem when burst reading"); mutex_unlock(&st->buf_lock); return ret; } static irqreturn_t adis16240_trigger_handler(int irq, void *p) { struct iio_poll_func *pf = p; struct iio_dev *indio_dev = pf->indio_dev; struct adis16240_state *st = iio_priv(indio_dev); struct iio_buffer *ring = indio_dev->buffer; int i = 0; s16 *data; size_t datasize = ring->access->get_bytes_per_datum(ring); data = kmalloc(datasize, GFP_KERNEL); if (data == NULL) { dev_err(&st->us->dev, "memory alloc failed in ring bh"); return -ENOMEM; } if (!bitmap_empty(indio_dev->active_scan_mask, indio_dev->masklength) && adis16240_read_ring_data(&indio_dev->dev, st->rx) >= 0) for (; i < bitmap_weight(indio_dev->active_scan_mask, indio_dev->masklength); i++) data[i] = be16_to_cpup((__be16 *)&(st->rx[i*2])); /* Guaranteed to be aligned with 8 byte boundary */ if (ring->scan_timestamp) *((s64 *)(data + ((i + 3)/4)*4)) = pf->timestamp; ring->access->store_to(ring, (u8 *)data, pf->timestamp); iio_trigger_notify_done(indio_dev->trig); kfree(data); return IRQ_HANDLED; } void adis16240_unconfigure_ring(struct iio_dev *indio_dev) { iio_dealloc_pollfunc(indio_dev->pollfunc); iio_sw_rb_free(indio_dev->buffer); } static const struct iio_buffer_setup_ops adis16240_ring_setup_ops = { .preenable = &iio_sw_buffer_preenable, .postenable = &iio_triggered_buffer_postenable, .predisable = &iio_triggered_buffer_predisable, }; int adis16240_configure_ring(struct iio_dev *indio_dev) { int ret = 0; struct iio_buffer *ring; ring = iio_sw_rb_allocate(indio_dev); if (!ring) { ret = -ENOMEM; return ret; } indio_dev->buffer = ring; ring->scan_timestamp = true; indio_dev->setup_ops = &adis16240_ring_setup_ops; indio_dev->pollfunc = iio_alloc_pollfunc(&iio_pollfunc_store_time, &adis16240_trigger_handler, IRQF_ONESHOT, indio_dev, "%s_consumer%d", indio_dev->name, indio_dev->id); if (indio_dev->pollfunc == NULL) { ret = -ENOMEM; goto error_iio_sw_rb_free; } indio_dev->modes |= INDIO_BUFFER_TRIGGERED; return 0; error_iio_sw_rb_free: iio_sw_rb_free(indio_dev->buffer); return ret; }
gpl-2.0
MoKee/android_kernel_xiaomi_msm8226-common
drivers/staging/rtl8192e/rtl8192e/r8190P_rtl8256.c
7695
8615
/****************************************************************************** * Copyright(c) 2008 - 2010 Realtek Corporation. All rights reserved. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * more details. * * You should have received a copy of the GNU General Public License along with * this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA * * The full GNU General Public License is included in this distribution in the * file called LICENSE. * * Contact Information: * wlanfae <wlanfae@realtek.com> ******************************************************************************/ #include "rtl_core.h" #include "r8192E_phyreg.h" #include "r8192E_phy.h" #include "r8190P_rtl8256.h" void PHY_SetRF8256Bandwidth(struct net_device *dev, enum ht_channel_width Bandwidth) { u8 eRFPath; struct r8192_priv *priv = rtllib_priv(dev); for (eRFPath = 0; eRFPath < priv->NumTotalRFPath; eRFPath++) { if (!rtl8192_phy_CheckIsLegalRFPath(dev, eRFPath)) continue; switch (Bandwidth) { case HT_CHANNEL_WIDTH_20: if (priv->card_8192_version == VERSION_8190_BD || priv->card_8192_version == VERSION_8190_BE) { rtl8192_phy_SetRFReg(dev, (enum rf90_radio_path)eRFPath, 0x0b, bMask12Bits, 0x100); rtl8192_phy_SetRFReg(dev, (enum rf90_radio_path)eRFPath, 0x2c, bMask12Bits, 0x3d7); rtl8192_phy_SetRFReg(dev, (enum rf90_radio_path)eRFPath, 0x0e, bMask12Bits, 0x021); } else { RT_TRACE(COMP_ERR, "PHY_SetRF8256Bandwidth(): " "unknown hardware version\n"); } break; case HT_CHANNEL_WIDTH_20_40: if (priv->card_8192_version == VERSION_8190_BD || priv->card_8192_version == VERSION_8190_BE) { rtl8192_phy_SetRFReg(dev, (enum rf90_radio_path)eRFPath, 0x0b, bMask12Bits, 0x300); rtl8192_phy_SetRFReg(dev, (enum rf90_radio_path)eRFPath, 0x2c, bMask12Bits, 0x3ff); rtl8192_phy_SetRFReg(dev, (enum rf90_radio_path)eRFPath, 0x0e, bMask12Bits, 0x0e1); } else { RT_TRACE(COMP_ERR, "PHY_SetRF8256Bandwidth(): " "unknown hardware version\n"); } break; default: RT_TRACE(COMP_ERR, "PHY_SetRF8256Bandwidth(): unknown " "Bandwidth: %#X\n", Bandwidth); break; } } return; } bool PHY_RF8256_Config(struct net_device *dev) { struct r8192_priv *priv = rtllib_priv(dev); bool rtStatus = true; priv->NumTotalRFPath = RTL819X_TOTAL_RF_PATH; rtStatus = phy_RF8256_Config_ParaFile(dev); return rtStatus; } bool phy_RF8256_Config_ParaFile(struct net_device *dev) { u32 u4RegValue = 0; u8 eRFPath; bool rtStatus = true; struct bb_reg_definition *pPhyReg; struct r8192_priv *priv = rtllib_priv(dev); u32 RegOffSetToBeCheck = 0x3; u32 RegValueToBeCheck = 0x7f1; u32 RF3_Final_Value = 0; u8 ConstRetryTimes = 5, RetryTimes = 5; u8 ret = 0; for (eRFPath = (enum rf90_radio_path)RF90_PATH_A; eRFPath < priv->NumTotalRFPath; eRFPath++) { if (!rtl8192_phy_CheckIsLegalRFPath(dev, eRFPath)) continue; pPhyReg = &priv->PHYRegDef[eRFPath]; switch (eRFPath) { case RF90_PATH_A: case RF90_PATH_C: u4RegValue = rtl8192_QueryBBReg(dev, pPhyReg->rfintfs, bRFSI_RFENV); break; case RF90_PATH_B: case RF90_PATH_D: u4RegValue = rtl8192_QueryBBReg(dev, pPhyReg->rfintfs, bRFSI_RFENV<<16); break; } rtl8192_setBBreg(dev, pPhyReg->rfintfe, bRFSI_RFENV<<16, 0x1); rtl8192_setBBreg(dev, pPhyReg->rfintfo, bRFSI_RFENV, 0x1); rtl8192_setBBreg(dev, pPhyReg->rfHSSIPara2, b3WireAddressLength, 0x0); rtl8192_setBBreg(dev, pPhyReg->rfHSSIPara2, b3WireDataLength, 0x0); rtl8192_phy_SetRFReg(dev, (enum rf90_radio_path) eRFPath, 0x0, bMask12Bits, 0xbf); rtStatus = rtl8192_phy_checkBBAndRF(dev, HW90_BLOCK_RF, (enum rf90_radio_path)eRFPath); if (rtStatus != true) { RT_TRACE(COMP_ERR, "PHY_RF8256_Config():Check " "Radio[%d] Fail!!\n", eRFPath); goto phy_RF8256_Config_ParaFile_Fail; } RetryTimes = ConstRetryTimes; RF3_Final_Value = 0; switch (eRFPath) { case RF90_PATH_A: while (RF3_Final_Value != RegValueToBeCheck && RetryTimes != 0) { ret = rtl8192_phy_ConfigRFWithHeaderFile(dev, (enum rf90_radio_path)eRFPath); RF3_Final_Value = rtl8192_phy_QueryRFReg(dev, (enum rf90_radio_path)eRFPath, RegOffSetToBeCheck, bMask12Bits); RT_TRACE(COMP_RF, "RF %d %d register final " "value: %x\n", eRFPath, RegOffSetToBeCheck, RF3_Final_Value); RetryTimes--; } break; case RF90_PATH_B: while (RF3_Final_Value != RegValueToBeCheck && RetryTimes != 0) { ret = rtl8192_phy_ConfigRFWithHeaderFile(dev, (enum rf90_radio_path)eRFPath); RF3_Final_Value = rtl8192_phy_QueryRFReg(dev, (enum rf90_radio_path)eRFPath, RegOffSetToBeCheck, bMask12Bits); RT_TRACE(COMP_RF, "RF %d %d register final " "value: %x\n", eRFPath, RegOffSetToBeCheck, RF3_Final_Value); RetryTimes--; } break; case RF90_PATH_C: while (RF3_Final_Value != RegValueToBeCheck && RetryTimes != 0) { ret = rtl8192_phy_ConfigRFWithHeaderFile(dev, (enum rf90_radio_path)eRFPath); RF3_Final_Value = rtl8192_phy_QueryRFReg(dev, (enum rf90_radio_path)eRFPath, RegOffSetToBeCheck, bMask12Bits); RT_TRACE(COMP_RF, "RF %d %d register final " "value: %x\n", eRFPath, RegOffSetToBeCheck, RF3_Final_Value); RetryTimes--; } break; case RF90_PATH_D: while (RF3_Final_Value != RegValueToBeCheck && RetryTimes != 0) { ret = rtl8192_phy_ConfigRFWithHeaderFile(dev, (enum rf90_radio_path)eRFPath); RF3_Final_Value = rtl8192_phy_QueryRFReg(dev, (enum rf90_radio_path)eRFPath, RegOffSetToBeCheck, bMask12Bits); RT_TRACE(COMP_RF, "RF %d %d register final " "value: %x\n", eRFPath, RegOffSetToBeCheck, RF3_Final_Value); RetryTimes--; } break; } switch (eRFPath) { case RF90_PATH_A: case RF90_PATH_C: rtl8192_setBBreg(dev, pPhyReg->rfintfs, bRFSI_RFENV, u4RegValue); break; case RF90_PATH_B: case RF90_PATH_D: rtl8192_setBBreg(dev, pPhyReg->rfintfs, bRFSI_RFENV<<16, u4RegValue); break; } if (ret) { RT_TRACE(COMP_ERR, "phy_RF8256_Config_ParaFile():" "Radio[%d] Fail!!", eRFPath); goto phy_RF8256_Config_ParaFile_Fail; } } RT_TRACE(COMP_PHY, "PHY Initialization Success\n") ; return true; phy_RF8256_Config_ParaFile_Fail: RT_TRACE(COMP_ERR, "PHY Initialization failed\n") ; return false; } void PHY_SetRF8256CCKTxPower(struct net_device *dev, u8 powerlevel) { u32 TxAGC = 0; struct r8192_priv *priv = rtllib_priv(dev); TxAGC = powerlevel; if (priv->bDynamicTxLowPower == true) { if (priv->CustomerID == RT_CID_819x_Netcore) TxAGC = 0x22; else TxAGC += priv->CckPwEnl; } if (TxAGC > 0x24) TxAGC = 0x24; rtl8192_setBBreg(dev, rTxAGC_CCK_Mcs32, bTxAGCRateCCK, TxAGC); } void PHY_SetRF8256OFDMTxPower(struct net_device *dev, u8 powerlevel) { struct r8192_priv *priv = rtllib_priv(dev); u32 writeVal, powerBase0, powerBase1, writeVal_tmp; u8 index = 0; u16 RegOffset[6] = {0xe00, 0xe04, 0xe10, 0xe14, 0xe18, 0xe1c}; u8 byte0, byte1, byte2, byte3; powerBase0 = powerlevel + priv->LegacyHTTxPowerDiff; powerBase0 = (powerBase0 << 24) | (powerBase0 << 16) | (powerBase0 << 8) | powerBase0; powerBase1 = powerlevel; powerBase1 = (powerBase1 << 24) | (powerBase1 << 16) | (powerBase1 << 8) | powerBase1; for (index = 0; index < 6; index++) { writeVal = (u32)(priv->MCSTxPowerLevelOriginalOffset[index] + ((index < 2) ? powerBase0 : powerBase1)); byte0 = (u8)(writeVal & 0x7f); byte1 = (u8)((writeVal & 0x7f00)>>8); byte2 = (u8)((writeVal & 0x7f0000)>>16); byte3 = (u8)((writeVal & 0x7f000000)>>24); if (byte0 > 0x24) byte0 = 0x24; if (byte1 > 0x24) byte1 = 0x24; if (byte2 > 0x24) byte2 = 0x24; if (byte3 > 0x24) byte3 = 0x24; if (index == 3) { writeVal_tmp = (byte3 << 24) | (byte2 << 16) | (byte1 << 8) | byte0; priv->Pwr_Track = writeVal_tmp; } if (priv->bDynamicTxHighPower == true) writeVal = 0x03030303; else writeVal = (byte3 << 24) | (byte2 << 16) | (byte1 << 8) | byte0; rtl8192_setBBreg(dev, RegOffset[index], 0x7f7f7f7f, writeVal); } return; }
gpl-2.0
TeamRegular/android_kernel_amazon_ford
arch/ia64/sn/pci/pcibr/pcibr_dma.c
9487
11726
/* * This file is subject to the terms and conditions of the GNU General Public * License. See the file "COPYING" in the main directory of this archive * for more details. * * Copyright (C) 2001-2005 Silicon Graphics, Inc. All rights reserved. */ #include <linux/types.h> #include <linux/pci.h> #include <linux/export.h> #include <asm/sn/addrs.h> #include <asm/sn/geo.h> #include <asm/sn/pcibr_provider.h> #include <asm/sn/pcibus_provider_defs.h> #include <asm/sn/pcidev.h> #include <asm/sn/pic.h> #include <asm/sn/sn_sal.h> #include <asm/sn/tiocp.h> #include "tio.h" #include "xtalk/xwidgetdev.h" #include "xtalk/hubdev.h" extern int sn_ioif_inited; /* ===================================================================== * DMA MANAGEMENT * * The Bridge ASIC provides three methods of doing DMA: via a "direct map" * register available in 32-bit PCI space (which selects a contiguous 2G * address space on some other widget), via "direct" addressing via 64-bit * PCI space (all destination information comes from the PCI address, * including transfer attributes), and via a "mapped" region that allows * a bunch of different small mappings to be established with the PMU. * * For efficiency, we most prefer to use the 32bit direct mapping facility, * since it requires no resource allocations. The advantage of using the * PMU over the 64-bit direct is that single-cycle PCI addressing can be * used; the advantage of using 64-bit direct over PMU addressing is that * we do not have to allocate entries in the PMU. */ static dma_addr_t pcibr_dmamap_ate32(struct pcidev_info *info, u64 paddr, size_t req_size, u64 flags, int dma_flags) { struct pcidev_info *pcidev_info = info->pdi_host_pcidev_info; struct pcibus_info *pcibus_info = (struct pcibus_info *)pcidev_info-> pdi_pcibus_info; u8 internal_device = (PCI_SLOT(pcidev_info->pdi_host_pcidev_info-> pdi_linux_pcidev->devfn)) - 1; int ate_count; int ate_index; u64 ate_flags = flags | PCI32_ATE_V; u64 ate; u64 pci_addr; u64 xio_addr; u64 offset; /* PIC in PCI-X mode does not supports 32bit PageMap mode */ if (IS_PIC_SOFT(pcibus_info) && IS_PCIX(pcibus_info)) { return 0; } /* Calculate the number of ATEs needed. */ if (!(MINIMAL_ATE_FLAG(paddr, req_size))) { ate_count = IOPG((IOPGSIZE - 1) /* worst case start offset */ +req_size /* max mapping bytes */ - 1) + 1; /* round UP */ } else { /* assume requested target is page aligned */ ate_count = IOPG(req_size /* max mapping bytes */ - 1) + 1; /* round UP */ } /* Get the number of ATEs required. */ ate_index = pcibr_ate_alloc(pcibus_info, ate_count); if (ate_index < 0) return 0; /* In PCI-X mode, Prefetch not supported */ if (IS_PCIX(pcibus_info)) ate_flags &= ~(PCI32_ATE_PREF); if (SN_DMA_ADDRTYPE(dma_flags == SN_DMA_ADDR_PHYS)) xio_addr = IS_PIC_SOFT(pcibus_info) ? PHYS_TO_DMA(paddr) : PHYS_TO_TIODMA(paddr); else xio_addr = paddr; offset = IOPGOFF(xio_addr); ate = ate_flags | (xio_addr - offset); /* If PIC, put the targetid in the ATE */ if (IS_PIC_SOFT(pcibus_info)) { ate |= (pcibus_info->pbi_hub_xid << PIC_ATE_TARGETID_SHFT); } /* * If we're mapping for MSI, set the MSI bit in the ATE. If it's a * TIOCP based pci bus, we also need to set the PIO bit in the ATE. */ if (dma_flags & SN_DMA_MSI) { ate |= PCI32_ATE_MSI; if (IS_TIOCP_SOFT(pcibus_info)) ate |= PCI32_ATE_PIO; } ate_write(pcibus_info, ate_index, ate_count, ate); /* * Set up the DMA mapped Address. */ pci_addr = PCI32_MAPPED_BASE + offset + IOPGSIZE * ate_index; /* * If swap was set in device in pcibr_endian_set() * we need to turn swapping on. */ if (pcibus_info->pbi_devreg[internal_device] & PCIBR_DEV_SWAP_DIR) ATE_SWAP_ON(pci_addr); return pci_addr; } static dma_addr_t pcibr_dmatrans_direct64(struct pcidev_info * info, u64 paddr, u64 dma_attributes, int dma_flags) { struct pcibus_info *pcibus_info = (struct pcibus_info *) ((info->pdi_host_pcidev_info)->pdi_pcibus_info); u64 pci_addr; /* Translate to Crosstalk View of Physical Address */ if (SN_DMA_ADDRTYPE(dma_flags) == SN_DMA_ADDR_PHYS) pci_addr = IS_PIC_SOFT(pcibus_info) ? PHYS_TO_DMA(paddr) : PHYS_TO_TIODMA(paddr); else pci_addr = paddr; pci_addr |= dma_attributes; /* Handle Bus mode */ if (IS_PCIX(pcibus_info)) pci_addr &= ~PCI64_ATTR_PREF; /* Handle Bridge Chipset differences */ if (IS_PIC_SOFT(pcibus_info)) { pci_addr |= ((u64) pcibus_info-> pbi_hub_xid << PIC_PCI64_ATTR_TARG_SHFT); } else pci_addr |= (dma_flags & SN_DMA_MSI) ? TIOCP_PCI64_CMDTYPE_MSI : TIOCP_PCI64_CMDTYPE_MEM; /* If PCI mode, func zero uses VCHAN0, every other func uses VCHAN1 */ if (!IS_PCIX(pcibus_info) && PCI_FUNC(info->pdi_linux_pcidev->devfn)) pci_addr |= PCI64_ATTR_VIRTUAL; return pci_addr; } static dma_addr_t pcibr_dmatrans_direct32(struct pcidev_info * info, u64 paddr, size_t req_size, u64 flags, int dma_flags) { struct pcidev_info *pcidev_info = info->pdi_host_pcidev_info; struct pcibus_info *pcibus_info = (struct pcibus_info *)pcidev_info-> pdi_pcibus_info; u64 xio_addr; u64 xio_base; u64 offset; u64 endoff; if (IS_PCIX(pcibus_info)) { return 0; } if (dma_flags & SN_DMA_MSI) return 0; if (SN_DMA_ADDRTYPE(dma_flags) == SN_DMA_ADDR_PHYS) xio_addr = IS_PIC_SOFT(pcibus_info) ? PHYS_TO_DMA(paddr) : PHYS_TO_TIODMA(paddr); else xio_addr = paddr; xio_base = pcibus_info->pbi_dir_xbase; offset = xio_addr - xio_base; endoff = req_size + offset; if ((req_size > (1ULL << 31)) || /* Too Big */ (xio_addr < xio_base) || /* Out of range for mappings */ (endoff > (1ULL << 31))) { /* Too Big */ return 0; } return PCI32_DIRECT_BASE | offset; } /* * Wrapper routine for freeing DMA maps * DMA mappings for Direct 64 and 32 do not have any DMA maps. */ void pcibr_dma_unmap(struct pci_dev *hwdev, dma_addr_t dma_handle, int direction) { struct pcidev_info *pcidev_info = SN_PCIDEV_INFO(hwdev); struct pcibus_info *pcibus_info = (struct pcibus_info *)pcidev_info->pdi_pcibus_info; if (IS_PCI32_MAPPED(dma_handle)) { int ate_index; ate_index = IOPG((ATE_SWAP_OFF(dma_handle) - PCI32_MAPPED_BASE)); pcibr_ate_free(pcibus_info, ate_index); } } /* * On SN systems there is a race condition between a PIO read response and * DMA's. In rare cases, the read response may beat the DMA, causing the * driver to think that data in memory is complete and meaningful. This code * eliminates that race. This routine is called by the PIO read routines * after doing the read. For PIC this routine then forces a fake interrupt * on another line, which is logically associated with the slot that the PIO * is addressed to. It then spins while watching the memory location that * the interrupt is targeted to. When the interrupt response arrives, we * are sure that the DMA has landed in memory and it is safe for the driver * to proceed. For TIOCP use the Device(x) Write Request Buffer Flush * Bridge register since it ensures the data has entered the coherence domain, * unlike the PIC Device(x) Write Request Buffer Flush register. */ void sn_dma_flush(u64 addr) { nasid_t nasid; int is_tio; int wid_num; int i, j; unsigned long flags; u64 itte; struct hubdev_info *hubinfo; struct sn_flush_device_kernel *p; struct sn_flush_device_common *common; struct sn_flush_nasid_entry *flush_nasid_list; if (!sn_ioif_inited) return; nasid = NASID_GET(addr); if (-1 == nasid_to_cnodeid(nasid)) return; hubinfo = (NODEPDA(nasid_to_cnodeid(nasid)))->pdinfo; BUG_ON(!hubinfo); flush_nasid_list = &hubinfo->hdi_flush_nasid_list; if (flush_nasid_list->widget_p == NULL) return; is_tio = (nasid & 1); if (is_tio) { int itte_index; if (TIO_HWIN(addr)) itte_index = 0; else if (TIO_BWIN_WINDOWNUM(addr)) itte_index = TIO_BWIN_WINDOWNUM(addr); else itte_index = -1; if (itte_index >= 0) { itte = flush_nasid_list->iio_itte[itte_index]; if (! TIO_ITTE_VALID(itte)) return; wid_num = TIO_ITTE_WIDGET(itte); } else wid_num = TIO_SWIN_WIDGETNUM(addr); } else { if (BWIN_WINDOWNUM(addr)) { itte = flush_nasid_list->iio_itte[BWIN_WINDOWNUM(addr)]; wid_num = IIO_ITTE_WIDGET(itte); } else wid_num = SWIN_WIDGETNUM(addr); } if (flush_nasid_list->widget_p[wid_num] == NULL) return; p = &flush_nasid_list->widget_p[wid_num][0]; /* find a matching BAR */ for (i = 0; i < DEV_PER_WIDGET; i++,p++) { common = p->common; for (j = 0; j < PCI_ROM_RESOURCE; j++) { if (common->sfdl_bar_list[j].start == 0) break; if (addr >= common->sfdl_bar_list[j].start && addr <= common->sfdl_bar_list[j].end) break; } if (j < PCI_ROM_RESOURCE && common->sfdl_bar_list[j].start != 0) break; } /* if no matching BAR, return without doing anything. */ if (i == DEV_PER_WIDGET) return; /* * For TIOCP use the Device(x) Write Request Buffer Flush Bridge * register since it ensures the data has entered the coherence * domain, unlike PIC. */ if (is_tio) { /* * Note: devices behind TIOCE should never be matched in the * above code, and so the following code is PIC/CP centric. * If CE ever needs the sn_dma_flush mechanism, we will have * to account for that here and in tioce_bus_fixup(). */ u32 tio_id = HUB_L(TIO_IOSPACE_ADDR(nasid, TIO_NODE_ID)); u32 revnum = XWIDGET_PART_REV_NUM(tio_id); /* TIOCP BRINGUP WAR (PV907516): Don't write buffer flush reg */ if ((1 << XWIDGET_PART_REV_NUM_REV(revnum)) & PV907516) { return; } else { pcireg_wrb_flush_get(common->sfdl_pcibus_info, (common->sfdl_slot - 1)); } } else { spin_lock_irqsave(&p->sfdl_flush_lock, flags); *common->sfdl_flush_addr = 0; /* force an interrupt. */ *(volatile u32 *)(common->sfdl_force_int_addr) = 1; /* wait for the interrupt to come back. */ while (*(common->sfdl_flush_addr) != 0x10f) cpu_relax(); /* okay, everything is synched up. */ spin_unlock_irqrestore(&p->sfdl_flush_lock, flags); } return; } /* * DMA interfaces. Called from pci_dma.c routines. */ dma_addr_t pcibr_dma_map(struct pci_dev * hwdev, unsigned long phys_addr, size_t size, int dma_flags) { dma_addr_t dma_handle; struct pcidev_info *pcidev_info = SN_PCIDEV_INFO(hwdev); /* SN cannot support DMA addresses smaller than 32 bits. */ if (hwdev->dma_mask < 0x7fffffff) { return 0; } if (hwdev->dma_mask == ~0UL) { /* * Handle the most common case: 64 bit cards. This * call should always succeed. */ dma_handle = pcibr_dmatrans_direct64(pcidev_info, phys_addr, PCI64_ATTR_PREF, dma_flags); } else { /* Handle 32-63 bit cards via direct mapping */ dma_handle = pcibr_dmatrans_direct32(pcidev_info, phys_addr, size, 0, dma_flags); if (!dma_handle) { /* * It is a 32 bit card and we cannot do direct mapping, * so we use an ATE. */ dma_handle = pcibr_dmamap_ate32(pcidev_info, phys_addr, size, PCI32_ATE_PREF, dma_flags); } } return dma_handle; } dma_addr_t pcibr_dma_map_consistent(struct pci_dev * hwdev, unsigned long phys_addr, size_t size, int dma_flags) { dma_addr_t dma_handle; struct pcidev_info *pcidev_info = SN_PCIDEV_INFO(hwdev); if (hwdev->dev.coherent_dma_mask == ~0UL) { dma_handle = pcibr_dmatrans_direct64(pcidev_info, phys_addr, PCI64_ATTR_BAR, dma_flags); } else { dma_handle = (dma_addr_t) pcibr_dmamap_ate32(pcidev_info, phys_addr, size, PCI32_ATE_BAR, dma_flags); } return dma_handle; } EXPORT_SYMBOL(sn_dma_flush);
gpl-2.0
keily90/tf101-nv-linux
scripts/mod/mk_elfconfig.c
12047
1234
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <elf.h> int main(int argc, char **argv) { unsigned char ei[EI_NIDENT]; union { short s; char c[2]; } endian_test; if (fread(ei, 1, EI_NIDENT, stdin) != EI_NIDENT) { fprintf(stderr, "Error: input truncated\n"); return 1; } if (memcmp(ei, ELFMAG, SELFMAG) != 0) { fprintf(stderr, "Error: not ELF\n"); return 1; } switch (ei[EI_CLASS]) { case ELFCLASS32: printf("#define KERNEL_ELFCLASS ELFCLASS32\n"); break; case ELFCLASS64: printf("#define KERNEL_ELFCLASS ELFCLASS64\n"); break; default: exit(1); } switch (ei[EI_DATA]) { case ELFDATA2LSB: printf("#define KERNEL_ELFDATA ELFDATA2LSB\n"); break; case ELFDATA2MSB: printf("#define KERNEL_ELFDATA ELFDATA2MSB\n"); break; default: exit(1); } if (sizeof(unsigned long) == 4) { printf("#define HOST_ELFCLASS ELFCLASS32\n"); } else if (sizeof(unsigned long) == 8) { printf("#define HOST_ELFCLASS ELFCLASS64\n"); } endian_test.s = 0x0102; if (memcmp(endian_test.c, "\x01\x02", 2) == 0) printf("#define HOST_ELFDATA ELFDATA2MSB\n"); else if (memcmp(endian_test.c, "\x02\x01", 2) == 0) printf("#define HOST_ELFDATA ELFDATA2LSB\n"); else exit(1); return 0; }
gpl-2.0
ywzjackal/dmmu_linux
arch/powerpc/boot/redboot-83xx.c
14095
1446
/* * RedBoot firmware support * * Author: Scott Wood <scottwood@freescale.com> * * Copyright (c) 2007 Freescale Semiconductor, Inc. * Copyright (c) 2008 Codehermit * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 as published * by the Free Software Foundation. */ #include "ops.h" #include "stdio.h" #include "redboot.h" #include "fsl-soc.h" #include "io.h" static bd_t bd; BSS_STACK(4096); #define MHZ(x) ((x + 500000) / 1000000) static void platform_fixups(void) { void *node; dt_fixup_memory(bd.bi_memstart, bd.bi_memsize); dt_fixup_mac_addresses(bd.bi_enetaddr); dt_fixup_cpu_clocks(bd.bi_intfreq, bd.bi_busfreq / 16, bd.bi_busfreq); node = finddevice("/soc/cpm/brg"); if (node) { printf("BRG clock-frequency <- 0x%x (%dMHz)\r\n", bd.bi_busfreq, MHZ(bd.bi_busfreq)); setprop(node, "clock-frequency", &bd.bi_busfreq, 4); } } void platform_init(unsigned long r3, unsigned long r4, unsigned long r5, unsigned long r6, unsigned long r7) { memcpy(&bd, (char *)r3, sizeof(bd)); if (bd.bi_tag != 0x42444944) return; simple_alloc_init(_end, bd.bi_memstart + bd.bi_memsize - (unsigned long)_end, 32, 64); fdt_init(_dtb_start); serial_console_init(); platform_ops.fixups = platform_fixups; loader_info.cmdline = (char *)bd.bi_cmdline; loader_info.cmdline_len = strlen((char *)bd.bi_cmdline); }
gpl-2.0
jpakkane/gstreamer-plugins-base
tests/icles/test-effect-switch.c
16
6920
/* GStreamer dynamic effect change test app * Copyright (C) 2012 Tim-Philipp Müller <tim centricular net> * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public * License along with this library; if not, write to the * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, * Boston, MA 02110-1301, USA. * * Based on python script by Thiago Sousa Santos */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include <gst/gst.h> static gchar *opt_effects = NULL; #define DEFAULT_EFFECTS "identity,exclusion,navigationtest," \ "agingtv,videoflip,vertigotv,gaussianblur,shagadelictv,edgetv" static GstPad *blockpad; static GstElement *conv_before; static GstElement *conv_after; static GstElement *cur_effect; static GstElement *pipeline; static GQueue effects = G_QUEUE_INIT; static GstPadProbeReturn event_probe_cb (GstPad * pad, GstPadProbeInfo * info, gpointer user_data) { GMainLoop *loop = user_data; GstElement *next; if (GST_EVENT_TYPE (GST_PAD_PROBE_INFO_DATA (info)) != GST_EVENT_EOS) return GST_PAD_PROBE_OK; gst_pad_remove_probe (pad, GST_PAD_PROBE_INFO_ID (info)); /* push current event back into the queue */ g_queue_push_tail (&effects, gst_object_ref (cur_effect)); /* take next effect from the queue */ next = g_queue_pop_head (&effects); if (next == NULL) { GST_DEBUG_OBJECT (pad, "no more effects"); g_main_loop_quit (loop); return GST_PAD_PROBE_DROP; } g_print ("Switching from '%s' to '%s'..\n", GST_OBJECT_NAME (cur_effect), GST_OBJECT_NAME (next)); gst_element_set_state (cur_effect, GST_STATE_NULL); /* remove unlinks automatically */ GST_DEBUG_OBJECT (pipeline, "removing %" GST_PTR_FORMAT, cur_effect); gst_bin_remove (GST_BIN (pipeline), cur_effect); GST_DEBUG_OBJECT (pipeline, "adding %" GST_PTR_FORMAT, next); gst_bin_add (GST_BIN (pipeline), next); GST_DEBUG_OBJECT (pipeline, "linking.."); gst_element_link_many (conv_before, next, conv_after, NULL); gst_element_set_state (next, GST_STATE_PLAYING); cur_effect = next; GST_DEBUG_OBJECT (pipeline, "done"); return GST_PAD_PROBE_DROP; } static GstPadProbeReturn pad_probe_cb (GstPad * pad, GstPadProbeInfo * info, gpointer user_data) { GstPad *srcpad, *sinkpad; GST_DEBUG_OBJECT (pad, "pad is blocked now"); /* remove the probe first */ gst_pad_remove_probe (pad, GST_PAD_PROBE_INFO_ID (info)); /* install new probe for EOS */ srcpad = gst_element_get_static_pad (cur_effect, "src"); gst_pad_add_probe (srcpad, GST_PAD_PROBE_TYPE_BLOCK | GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM, event_probe_cb, user_data, NULL); gst_object_unref (srcpad); /* push EOS into the element, the probe will be fired when the * EOS leaves the effect and it has thus drained all of its data */ sinkpad = gst_element_get_static_pad (cur_effect, "sink"); gst_pad_send_event (sinkpad, gst_event_new_eos ()); gst_object_unref (sinkpad); return GST_PAD_PROBE_OK; } static gboolean timeout_cb (gpointer user_data) { gst_pad_add_probe (blockpad, GST_PAD_PROBE_TYPE_BLOCK_DOWNSTREAM, pad_probe_cb, user_data, NULL); return TRUE; } static gboolean bus_cb (GstBus * bus, GstMessage * msg, gpointer user_data) { GMainLoop *loop = user_data; switch (GST_MESSAGE_TYPE (msg)) { case GST_MESSAGE_ERROR:{ GError *err = NULL; gchar *dbg; gst_message_parse_error (msg, &err, &dbg); gst_object_default_error (msg->src, err, dbg); g_error_free (err); g_free (dbg); g_main_loop_quit (loop); break; } default: break; } return TRUE; } int main (int argc, char **argv) { GOptionEntry options[] = { {"effects", 'e', 0, G_OPTION_ARG_STRING, &opt_effects, "Effects to use (comma-separated list of element names)", NULL}, {NULL} }; GOptionContext *ctx; GError *err = NULL; GMainLoop *loop; GstElement *src, *q1, *q2, *effect, *filter1, *filter2, *sink; gchar **effect_names, **e; ctx = g_option_context_new (""); g_option_context_add_main_entries (ctx, options, GETTEXT_PACKAGE); g_option_context_add_group (ctx, gst_init_get_option_group ()); if (!g_option_context_parse (ctx, &argc, &argv, &err)) { g_print ("Error initializing: %s\n", err->message); return 1; } g_option_context_free (ctx); GST_FIXME ("Multiple things to check/fix, see source code"); if (opt_effects != NULL) effect_names = g_strsplit (opt_effects, ",", -1); else effect_names = g_strsplit (DEFAULT_EFFECTS, ",", -1); for (e = effect_names; e != NULL && *e != NULL; ++e) { GstElement *el; el = gst_element_factory_make (*e, NULL); if (el) { g_print ("Adding effect '%s'\n", *e); g_queue_push_tail (&effects, el); } } pipeline = gst_pipeline_new ("pipeline"); src = gst_element_factory_make ("videotestsrc", NULL); g_object_set (src, "is-live", TRUE, NULL); filter1 = gst_element_factory_make ("capsfilter", NULL); gst_util_set_object_arg (G_OBJECT (filter1), "caps", "video/x-raw, width=320, height=240, " "format={ I420, YV12, YUY2, UYVY, AYUV, Y41B, Y42B, " "YVYU, Y444, v210, v216, NV12, NV21, UYVP, A420, YUV9, YVU9, IYU1 }"); q1 = gst_element_factory_make ("queue", NULL); blockpad = gst_element_get_static_pad (q1, "src"); conv_before = gst_element_factory_make ("videoconvert", NULL); effect = g_queue_pop_head (&effects); cur_effect = effect; conv_after = gst_element_factory_make ("videoconvert", NULL); q2 = gst_element_factory_make ("queue", NULL); filter2 = gst_element_factory_make ("capsfilter", NULL); gst_util_set_object_arg (G_OBJECT (filter2), "caps", "video/x-raw, width=320, height=240, " "format={ RGBx, BGRx, xRGB, xBGR, RGBA, BGRA, ARGB, ABGR, RGB, BGR }"); sink = gst_element_factory_make ("ximagesink", NULL); gst_bin_add_many (GST_BIN (pipeline), src, filter1, q1, conv_before, effect, conv_after, q2, sink, NULL); gst_element_link_many (src, filter1, q1, conv_before, effect, conv_after, q2, sink, NULL); gst_element_set_state (pipeline, GST_STATE_PLAYING); loop = g_main_loop_new (NULL, FALSE); gst_bus_add_watch (GST_ELEMENT_BUS (pipeline), bus_cb, loop); g_timeout_add_seconds (1, timeout_cb, loop); g_main_loop_run (loop); gst_element_set_state (pipeline, GST_STATE_NULL); gst_object_unref (pipeline); return 0; }
gpl-2.0
erikvarga/gcc
libgfortran/intrinsics/eoshift0.c
16
8542
/* Generic implementation of the EOSHIFT intrinsic Copyright (C) 2002-2016 Free Software Foundation, Inc. Contributed by Paul Brook <paul@nowt.org> This file is part of the GNU Fortran runtime library (libgfortran). Libgfortran is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. Libgfortran is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. Under Section 7 of GPL version 3, you are granted additional permissions described in the GCC Runtime Library Exception, version 3.1, as published by the Free Software Foundation. You should have received a copy of the GNU General Public License and a copy of the GCC Runtime Library Exception along with this program; see the files COPYING3 and COPYING.RUNTIME respectively. If not, see <http://www.gnu.org/licenses/>. */ #include "libgfortran.h" #include <stdlib.h> #include <assert.h> #include <string.h> /* TODO: make this work for large shifts when sizeof(int) < sizeof (index_type). */ static void eoshift0 (gfc_array_char * ret, const gfc_array_char * array, int shift, const char * pbound, int which, index_type size, const char *filler, index_type filler_len) { /* r.* indicates the return array. */ index_type rstride[GFC_MAX_DIMENSIONS]; index_type rstride0; index_type roffset; char * restrict rptr; char *dest; /* s.* indicates the source array. */ index_type sstride[GFC_MAX_DIMENSIONS]; index_type sstride0; index_type soffset; const char *sptr; const char *src; index_type count[GFC_MAX_DIMENSIONS]; index_type extent[GFC_MAX_DIMENSIONS]; index_type dim; index_type len; index_type n; index_type arraysize; /* The compiler cannot figure out that these are set, initialize them to avoid warnings. */ len = 0; soffset = 0; roffset = 0; arraysize = size0 ((array_t *) array); if (ret->base_addr == NULL) { int i; ret->offset = 0; ret->dtype = array->dtype; for (i = 0; i < GFC_DESCRIPTOR_RANK (array); i++) { index_type ub, str; ub = GFC_DESCRIPTOR_EXTENT(array,i) - 1; if (i == 0) str = 1; else str = GFC_DESCRIPTOR_EXTENT(ret,i-1) * GFC_DESCRIPTOR_STRIDE(ret,i-1); GFC_DIMENSION_SET(ret->dim[i], 0, ub, str); } /* xmallocarray allocates a single byte for zero size. */ ret->base_addr = xmallocarray (arraysize, size); } else if (unlikely (compile_options.bounds_check)) { bounds_equal_extents ((array_t *) ret, (array_t *) array, "return value", "EOSHIFT"); } if (arraysize == 0) return; which = which - 1; extent[0] = 1; count[0] = 0; sstride[0] = -1; rstride[0] = -1; n = 0; for (dim = 0; dim < GFC_DESCRIPTOR_RANK (array); dim++) { if (dim == which) { roffset = GFC_DESCRIPTOR_STRIDE_BYTES(ret,dim); if (roffset == 0) roffset = size; soffset = GFC_DESCRIPTOR_STRIDE_BYTES(array,dim); if (soffset == 0) soffset = size; len = GFC_DESCRIPTOR_EXTENT(array,dim); } else { count[n] = 0; extent[n] = GFC_DESCRIPTOR_EXTENT(array,dim); rstride[n] = GFC_DESCRIPTOR_STRIDE_BYTES(ret,dim); sstride[n] = GFC_DESCRIPTOR_STRIDE_BYTES(array,dim); n++; } } if (sstride[0] == 0) sstride[0] = size; if (rstride[0] == 0) rstride[0] = size; dim = GFC_DESCRIPTOR_RANK (array); rstride0 = rstride[0]; sstride0 = sstride[0]; rptr = ret->base_addr; sptr = array->base_addr; if ((shift >= 0 ? shift : -shift) > len) { shift = len; len = 0; } else { if (shift > 0) len = len - shift; else len = len + shift; } while (rptr) { /* Do the shift for this dimension. */ if (shift > 0) { src = &sptr[shift * soffset]; dest = rptr; } else { src = sptr; dest = &rptr[-shift * roffset]; } for (n = 0; n < len; n++) { memcpy (dest, src, size); dest += roffset; src += soffset; } if (shift >= 0) { n = shift; } else { dest = rptr; n = -shift; } if (pbound) while (n--) { memcpy (dest, pbound, size); dest += roffset; } else while (n--) { index_type i; if (filler_len == 1) memset (dest, filler[0], size); else for (i = 0; i < size ; i += filler_len) memcpy (&dest[i], filler, filler_len); dest += roffset; } /* Advance to the next section. */ rptr += rstride0; sptr += sstride0; count[0]++; n = 0; while (count[n] == extent[n]) { /* When we get to the end of a dimension, reset it and increment the next dimension. */ count[n] = 0; /* We could precalculate these products, but this is a less frequently used path so probably not worth it. */ rptr -= rstride[n] * extent[n]; sptr -= sstride[n] * extent[n]; n++; if (n >= dim - 1) { /* Break out of the loop. */ rptr = NULL; break; } else { count[n]++; rptr += rstride[n]; sptr += sstride[n]; } } } } #define DEFINE_EOSHIFT(N) \ extern void eoshift0_##N (gfc_array_char *, const gfc_array_char *, \ const GFC_INTEGER_##N *, const char *, \ const GFC_INTEGER_##N *); \ export_proto(eoshift0_##N); \ \ void \ eoshift0_##N (gfc_array_char *ret, const gfc_array_char *array, \ const GFC_INTEGER_##N *pshift, const char *pbound, \ const GFC_INTEGER_##N *pdim) \ { \ eoshift0 (ret, array, *pshift, pbound, pdim ? *pdim : 1, \ GFC_DESCRIPTOR_SIZE (array), "\0", 1); \ } \ \ extern void eoshift0_##N##_char (gfc_array_char *, GFC_INTEGER_4, \ const gfc_array_char *, \ const GFC_INTEGER_##N *, const char *, \ const GFC_INTEGER_##N *, GFC_INTEGER_4, \ GFC_INTEGER_4); \ export_proto(eoshift0_##N##_char); \ \ void \ eoshift0_##N##_char (gfc_array_char *ret, \ GFC_INTEGER_4 ret_length __attribute__((unused)), \ const gfc_array_char *array, \ const GFC_INTEGER_##N *pshift, \ const char *pbound, \ const GFC_INTEGER_##N *pdim, \ GFC_INTEGER_4 array_length, \ GFC_INTEGER_4 bound_length __attribute__((unused))) \ { \ eoshift0 (ret, array, *pshift, pbound, pdim ? *pdim : 1, \ array_length, " ", 1); \ } \ \ extern void eoshift0_##N##_char4 (gfc_array_char *, GFC_INTEGER_4, \ const gfc_array_char *, \ const GFC_INTEGER_##N *, const char *, \ const GFC_INTEGER_##N *, GFC_INTEGER_4, \ GFC_INTEGER_4); \ export_proto(eoshift0_##N##_char4); \ \ void \ eoshift0_##N##_char4 (gfc_array_char *ret, \ GFC_INTEGER_4 ret_length __attribute__((unused)), \ const gfc_array_char *array, \ const GFC_INTEGER_##N *pshift, \ const char *pbound, \ const GFC_INTEGER_##N *pdim, \ GFC_INTEGER_4 array_length, \ GFC_INTEGER_4 bound_length __attribute__((unused))) \ { \ static const gfc_char4_t space = (unsigned char) ' '; \ eoshift0 (ret, array, *pshift, pbound, pdim ? *pdim : 1, \ array_length * sizeof (gfc_char4_t), (const char *) &space, \ sizeof (gfc_char4_t)); \ } DEFINE_EOSHIFT (1); DEFINE_EOSHIFT (2); DEFINE_EOSHIFT (4); DEFINE_EOSHIFT (8); #ifdef HAVE_GFC_INTEGER_16 DEFINE_EOSHIFT (16); #endif
gpl-2.0
JetBrains/jdk8u_hotspot
src/share/vm/c1/c1_ValueType.cpp
16
6122
/* * Copyright (c) 1999, 2012, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. * */ #include "precompiled.hpp" #include "c1/c1_ValueType.hpp" #include "ci/ciArray.hpp" #include "ci/ciInstance.hpp" #include "ci/ciNullObject.hpp" // predefined types VoidType* voidType = NULL; IntType* intType = NULL; LongType* longType = NULL; FloatType* floatType = NULL; DoubleType* doubleType = NULL; ObjectType* objectType = NULL; ArrayType* arrayType = NULL; InstanceType* instanceType = NULL; ClassType* classType = NULL; AddressType* addressType = NULL; IllegalType* illegalType = NULL; // predefined constants IntConstant* intZero = NULL; IntConstant* intOne = NULL; ObjectConstant* objectNull = NULL; void ValueType::initialize(Arena* arena) { // Note: Must initialize all types for each compilation // as they are allocated within a ResourceMark! // types voidType = new (arena) VoidType(); intType = new (arena) IntType(); longType = new (arena) LongType(); floatType = new (arena) FloatType(); doubleType = new (arena) DoubleType(); objectType = new (arena) ObjectType(); arrayType = new (arena) ArrayType(); instanceType = new (arena) InstanceType(); classType = new (arena) ClassType(); addressType = new (arena) AddressType(); illegalType = new (arena) IllegalType(); intZero = new (arena) IntConstant(0); intOne = new (arena) IntConstant(1); objectNull = new (arena) ObjectConstant(ciNullObject::make()); }; ValueType* ValueType::meet(ValueType* y) const { // incomplete & conservative solution for now - fix this! assert(tag() == y->tag(), "types must match"); return base(); } ValueType* ValueType::join(ValueType* y) const { Unimplemented(); return NULL; } ciType* ObjectConstant::exact_type() const { ciObject* c = constant_value(); return (c != NULL && !c->is_null_object()) ? c->klass() : NULL; } ciType* ArrayConstant::exact_type() const { ciObject* c = constant_value(); return (c != NULL && !c->is_null_object()) ? c->klass() : NULL; } ciType* InstanceConstant::exact_type() const { ciObject* c = constant_value(); return (c != NULL && !c->is_null_object()) ? c->klass() : NULL; } ciType* ClassConstant::exact_type() const { return Compilation::current()->env()->Class_klass(); } jobject ObjectType::encoding() const { assert(is_constant(), "must be"); return constant_value()->constant_encoding(); } bool ObjectType::is_loaded() const { assert(is_constant(), "must be"); return constant_value()->is_loaded(); } bool MetadataType::is_loaded() const { assert(is_constant(), "must be"); return constant_value()->is_loaded(); } ciObject* ObjectConstant::constant_value() const { return _value; } ciObject* ArrayConstant::constant_value() const { return _value; } ciObject* InstanceConstant::constant_value() const { return _value; } ValueType* as_ValueType(BasicType type) { switch (type) { case T_VOID : return voidType; case T_BYTE : // fall through case T_CHAR : // fall through case T_SHORT : // fall through case T_BOOLEAN: // fall through case T_INT : return intType; case T_LONG : return longType; case T_FLOAT : return floatType; case T_DOUBLE : return doubleType; case T_ARRAY : return arrayType; case T_OBJECT : return objectType; case T_ADDRESS: return addressType; case T_ILLEGAL: return illegalType; } ShouldNotReachHere(); return illegalType; } ValueType* as_ValueType(ciConstant value) { switch (value.basic_type()) { case T_BYTE : // fall through case T_CHAR : // fall through case T_SHORT : // fall through case T_BOOLEAN: // fall through case T_INT : return new IntConstant (value.as_int ()); case T_LONG : return new LongConstant (value.as_long ()); case T_FLOAT : return new FloatConstant (value.as_float ()); case T_DOUBLE : return new DoubleConstant(value.as_double()); case T_ARRAY : // fall through (ciConstant doesn't have an array accessor) case T_OBJECT : { // TODO: Common the code with GraphBuilder::load_constant? ciObject* obj = value.as_object(); if (obj->is_null_object()) return objectNull; if (obj->is_loaded()) { if (obj->is_array()) return new ArrayConstant(obj->as_array()); else if (obj->is_instance()) return new InstanceConstant(obj->as_instance()); } return new ObjectConstant(obj); } } ShouldNotReachHere(); return illegalType; } BasicType as_BasicType(ValueType* type) { switch (type->tag()) { case voidTag: return T_VOID; case intTag: return T_INT; case longTag: return T_LONG; case floatTag: return T_FLOAT; case doubleTag: return T_DOUBLE; case objectTag: return T_OBJECT; case metaDataTag:return T_METADATA; case addressTag: return T_ADDRESS; case illegalTag: return T_ILLEGAL; } ShouldNotReachHere(); return T_ILLEGAL; }
gpl-2.0
Krabappel2548/MSM8660_CM9.0_Pure_ICS_kernel
drivers/staging/qcache/qcache-main.c
16
36331
/* * Copyright (c) 2010,2011, Dan Magenheimer, Oracle Corp. * Copyright (c) 2010,2011, Nitin Gupta * Copyright (c) 2011-2012, Code Aurora Forum. All rights reserved. * * Qcache provides an in-kernel "host implementation" for transcendent memory * and, thus indirectly, for cleancache and frontswap. Qcache includes a * page-accessible memory [1] interface, utilizing lzo1x compression: * 1) "compression buddies" ("zbud") is used for ephemeral pages * Zbud allows pairs (and potentially, * in the future, more than a pair of) compressed pages to be closely linked * so that reclaiming can be done via the kernel's physical-page-oriented * "shrinker" interface. * * [1] For a definition of page-accessible memory (aka PAM), see: * http://marc.info/?l=linux-mm&m=127811271605009 */ #include <linux/module.h> #include <linux/cpu.h> #include <linux/highmem.h> #include <linux/list.h> #include <linux/lzo.h> #include <linux/slab.h> #include <linux/spinlock.h> #include <linux/types.h> #include <linux/atomic.h> #include <linux/math64.h> #include <linux/bitmap.h> #include <linux/fmem.h> #include "tmem.h" #if !defined(CONFIG_CLEANCACHE) #error "qcache is useless without CONFIG_CLEANCACHE" #endif #include <linux/cleancache.h> #define ZCACHE_GFP_MASK \ (__GFP_FS | __GFP_NORETRY | __GFP_NOWARN | __GFP_NOMEMALLOC) #define MAX_POOLS_PER_CLIENT 16 #define MAX_CLIENTS 16 #define LOCAL_CLIENT ((uint16_t)-1) MODULE_LICENSE("GPL"); struct zcache_client { struct tmem_pool *tmem_pools[MAX_POOLS_PER_CLIENT]; struct xv_pool *xvpool; bool allocated; atomic_t refcount; }; struct qcache_info { void *addr; unsigned long *bitmap; spinlock_t lock; unsigned pages; }; static struct qcache_info qcache_info; static unsigned long zcache_qc_allocated; static unsigned long zcache_qc_freed; static unsigned long zcache_qc_used; static unsigned long zcache_qc_max_used; static struct zcache_client zcache_host; static struct zcache_client zcache_clients[MAX_CLIENTS]; static inline uint16_t get_client_id_from_client(struct zcache_client *cli) { BUG_ON(cli == NULL); if (cli == &zcache_host) return LOCAL_CLIENT; return cli - &zcache_clients[0]; } static inline bool is_local_client(struct zcache_client *cli) { return cli == &zcache_host; } /********** * Compression buddies ("zbud") provides for packing two (or, possibly * in the future, more) compressed ephemeral pages into a single "raw" * (physical) page and tracking them with data structures so that * the raw pages can be easily reclaimed. * * A zbud page ("zbpg") is an aligned page containing a list_head, * a lock, and two "zbud headers". The remainder of the physical * page is divided up into aligned 64-byte "chunks" which contain * the compressed data for zero, one, or two zbuds. Each zbpg * resides on: (1) an "unused list" if it has no zbuds; (2) a * "buddied" list if it is fully populated with two zbuds; or * (3) one of PAGE_SIZE/64 "unbuddied" lists indexed by how many chunks * the one unbuddied zbud uses. The data inside a zbpg cannot be * read or written unless the zbpg's lock is held. */ #define ZBH_SENTINEL 0x43214321 #define ZBPG_SENTINEL 0xdeadbeef #define ZBUD_MAX_BUDS 2 struct zbud_hdr { uint16_t client_id; uint16_t pool_id; struct tmem_oid oid; uint32_t index; uint16_t size; /* compressed size in bytes, zero means unused */ DECL_SENTINEL }; struct zbud_page { struct list_head bud_list; spinlock_t lock; struct zbud_hdr buddy[ZBUD_MAX_BUDS]; DECL_SENTINEL /* followed by NUM_CHUNK aligned CHUNK_SIZE-byte chunks */ }; #define CHUNK_SHIFT 6 #define CHUNK_SIZE (1 << CHUNK_SHIFT) #define CHUNK_MASK (~(CHUNK_SIZE-1)) #define NCHUNKS (((PAGE_SIZE - sizeof(struct zbud_page)) & \ CHUNK_MASK) >> CHUNK_SHIFT) #define MAX_CHUNK (NCHUNKS-1) static struct { struct list_head list; unsigned count; } zbud_unbuddied[NCHUNKS]; /* list N contains pages with N chunks USED and NCHUNKS-N unused */ /* element 0 is never used but optimizing that isn't worth it */ static unsigned long zbud_cumul_chunk_counts[NCHUNKS]; struct list_head zbud_buddied_list; static unsigned long zcache_zbud_buddied_count; /* protects the buddied list and all unbuddied lists */ static DEFINE_SPINLOCK(zbud_budlists_spinlock); static atomic_t zcache_zbud_curr_raw_pages; static atomic_t zcache_zbud_curr_zpages; static unsigned long zcache_zbud_curr_zbytes; static unsigned long zcache_zbud_cumul_zpages; static unsigned long zcache_zbud_cumul_zbytes; static unsigned long zcache_compress_poor; static unsigned long zcache_mean_compress_poor; /* forward references */ static void *zcache_get_free_page(void); static void *qcache_alloc(void) { void *addr; unsigned long flags; int offset; struct qcache_info *qc = &qcache_info; spin_lock_irqsave(&qc->lock, flags); offset = bitmap_find_free_region(qc->bitmap, qc->pages, 0); if (offset < 0) { spin_unlock_irqrestore(&qc->lock, flags); return NULL; } zcache_qc_allocated++; zcache_qc_used++; zcache_qc_max_used = max(zcache_qc_max_used, zcache_qc_used); spin_unlock_irqrestore(&qc->lock, flags); addr = qc->addr + offset * PAGE_SIZE; return addr; } static void qcache_free(void *addr) { unsigned long flags; int offset; struct qcache_info *qc = &qcache_info; offset = (addr - qc->addr) / PAGE_SIZE; spin_lock_irqsave(&qc->lock, flags); bitmap_release_region(qc->bitmap, offset, 0); zcache_qc_freed++; zcache_qc_used--; spin_unlock_irqrestore(&qc->lock, flags); } /* * zbud helper functions */ static inline unsigned zbud_max_buddy_size(void) { return MAX_CHUNK << CHUNK_SHIFT; } static inline unsigned zbud_size_to_chunks(unsigned size) { BUG_ON(size == 0 || size > zbud_max_buddy_size()); return (size + CHUNK_SIZE - 1) >> CHUNK_SHIFT; } static inline int zbud_budnum(struct zbud_hdr *zh) { unsigned offset = (unsigned long)zh & (PAGE_SIZE - 1); struct zbud_page *zbpg = NULL; unsigned budnum = -1U; int i; for (i = 0; i < ZBUD_MAX_BUDS; i++) if (offset == offsetof(typeof(*zbpg), buddy[i])) { budnum = i; break; } BUG_ON(budnum == -1U); return budnum; } static char *zbud_data(struct zbud_hdr *zh, unsigned size) { struct zbud_page *zbpg; char *p; unsigned budnum; ASSERT_SENTINEL(zh, ZBH); budnum = zbud_budnum(zh); BUG_ON(size == 0 || size > zbud_max_buddy_size()); zbpg = container_of(zh, struct zbud_page, buddy[budnum]); p = (char *)zbpg; if (budnum == 0) p += ((sizeof(struct zbud_page) + CHUNK_SIZE - 1) & CHUNK_MASK); else if (budnum == 1) p += PAGE_SIZE - ((size + CHUNK_SIZE - 1) & CHUNK_MASK); return p; } /* * zbud raw page management */ static struct zbud_page *zbud_alloc_raw_page(void) { struct zbud_page *zbpg = NULL; struct zbud_hdr *zh0, *zh1; zbpg = zcache_get_free_page(); if (likely(zbpg != NULL)) { INIT_LIST_HEAD(&zbpg->bud_list); zh0 = &zbpg->buddy[0]; zh1 = &zbpg->buddy[1]; spin_lock_init(&zbpg->lock); atomic_inc(&zcache_zbud_curr_raw_pages); INIT_LIST_HEAD(&zbpg->bud_list); SET_SENTINEL(zbpg, ZBPG); zh0->size = 0; zh1->size = 0; tmem_oid_set_invalid(&zh0->oid); tmem_oid_set_invalid(&zh1->oid); } return zbpg; } static void zbud_free_raw_page(struct zbud_page *zbpg) { struct zbud_hdr *zh0 = &zbpg->buddy[0], *zh1 = &zbpg->buddy[1]; ASSERT_SENTINEL(zbpg, ZBPG); BUG_ON(!list_empty(&zbpg->bud_list)); BUG_ON(zh0->size != 0 || tmem_oid_valid(&zh0->oid)); BUG_ON(zh1->size != 0 || tmem_oid_valid(&zh1->oid)); INVERT_SENTINEL(zbpg, ZBPG); spin_unlock(&zbpg->lock); qcache_free(zbpg); } /* * core zbud handling routines */ static unsigned zbud_free(struct zbud_hdr *zh) { unsigned size; ASSERT_SENTINEL(zh, ZBH); BUG_ON(!tmem_oid_valid(&zh->oid)); size = zh->size; BUG_ON(zh->size == 0 || zh->size > zbud_max_buddy_size()); zh->size = 0; tmem_oid_set_invalid(&zh->oid); INVERT_SENTINEL(zh, ZBH); zcache_zbud_curr_zbytes -= size; atomic_dec(&zcache_zbud_curr_zpages); return size; } static void zbud_free_and_delist(struct zbud_hdr *zh) { unsigned chunks; struct zbud_hdr *zh_other; unsigned budnum = zbud_budnum(zh), size; struct zbud_page *zbpg = container_of(zh, struct zbud_page, buddy[budnum]); spin_lock(&zbpg->lock); if (list_empty(&zbpg->bud_list)) { spin_unlock(&zbpg->lock); return; } size = zbud_free(zh); zh_other = &zbpg->buddy[(budnum == 0) ? 1 : 0]; if (zh_other->size == 0) { /* was unbuddied: unlist and free */ chunks = zbud_size_to_chunks(size) ; spin_lock(&zbud_budlists_spinlock); BUG_ON(list_empty(&zbud_unbuddied[chunks].list)); list_del_init(&zbpg->bud_list); zbud_unbuddied[chunks].count--; spin_unlock(&zbud_budlists_spinlock); zbud_free_raw_page(zbpg); } else { /* was buddied: move remaining buddy to unbuddied list */ chunks = zbud_size_to_chunks(zh_other->size) ; spin_lock(&zbud_budlists_spinlock); list_del_init(&zbpg->bud_list); zcache_zbud_buddied_count--; list_add_tail(&zbpg->bud_list, &zbud_unbuddied[chunks].list); zbud_unbuddied[chunks].count++; spin_unlock(&zbud_budlists_spinlock); spin_unlock(&zbpg->lock); } } static struct zbud_hdr *zbud_create(uint16_t client_id, uint16_t pool_id, struct tmem_oid *oid, uint32_t index, struct page *page, void *cdata, unsigned size) { struct zbud_hdr *zh0, *zh1, *zh = NULL; struct zbud_page *zbpg = NULL, *ztmp; unsigned nchunks; char *to; int i, found_good_buddy = 0; nchunks = zbud_size_to_chunks(size) ; for (i = MAX_CHUNK - nchunks + 1; i > 0; i--) { spin_lock(&zbud_budlists_spinlock); if (!list_empty(&zbud_unbuddied[i].list)) { list_for_each_entry_safe(zbpg, ztmp, &zbud_unbuddied[i].list, bud_list) { if (spin_trylock(&zbpg->lock)) { found_good_buddy = i; goto found_unbuddied; } } } spin_unlock(&zbud_budlists_spinlock); } /* didn't find a good buddy, try allocating a new page */ zbpg = zbud_alloc_raw_page(); if (unlikely(zbpg == NULL)) goto out; /* ok, have a page, now compress the data before taking locks */ spin_lock(&zbpg->lock); spin_lock(&zbud_budlists_spinlock); list_add_tail(&zbpg->bud_list, &zbud_unbuddied[nchunks].list); zbud_unbuddied[nchunks].count++; zh = &zbpg->buddy[0]; goto init_zh; found_unbuddied: zh0 = &zbpg->buddy[0]; zh1 = &zbpg->buddy[1]; BUG_ON(!((zh0->size == 0) ^ (zh1->size == 0))); if (zh0->size != 0) { /* buddy0 in use, buddy1 is vacant */ ASSERT_SENTINEL(zh0, ZBH); zh = zh1; } else if (zh1->size != 0) { /* buddy1 in use, buddy0 is vacant */ ASSERT_SENTINEL(zh1, ZBH); zh = zh0; } else BUG(); list_del_init(&zbpg->bud_list); zbud_unbuddied[found_good_buddy].count--; list_add_tail(&zbpg->bud_list, &zbud_buddied_list); zcache_zbud_buddied_count++; init_zh: SET_SENTINEL(zh, ZBH); zh->size = size; zh->index = index; zh->oid = *oid; zh->pool_id = pool_id; zh->client_id = client_id; /* can wait to copy the data until the list locks are dropped */ spin_unlock(&zbud_budlists_spinlock); to = zbud_data(zh, size); memcpy(to, cdata, size); spin_unlock(&zbpg->lock); zbud_cumul_chunk_counts[nchunks]++; atomic_inc(&zcache_zbud_curr_zpages); zcache_zbud_cumul_zpages++; zcache_zbud_curr_zbytes += size; zcache_zbud_cumul_zbytes += size; out: return zh; } static int zbud_decompress(struct page *page, struct zbud_hdr *zh) { struct zbud_page *zbpg; unsigned budnum = zbud_budnum(zh); size_t out_len = PAGE_SIZE; char *to_va, *from_va; unsigned size; int ret = 0; zbpg = container_of(zh, struct zbud_page, buddy[budnum]); spin_lock(&zbpg->lock); if (list_empty(&zbpg->bud_list)) { ret = -EINVAL; goto out; } ASSERT_SENTINEL(zh, ZBH); BUG_ON(zh->size == 0 || zh->size > zbud_max_buddy_size()); to_va = kmap_atomic(page, KM_USER0); size = zh->size; from_va = zbud_data(zh, size); ret = lzo1x_decompress_safe(from_va, size, to_va, &out_len); BUG_ON(ret != LZO_E_OK); BUG_ON(out_len != PAGE_SIZE); kunmap_atomic(to_va, KM_USER0); out: spin_unlock(&zbpg->lock); return ret; } static struct tmem_pool *zcache_get_pool_by_id(uint16_t cli_id, uint16_t poolid); static void zcache_put_pool(struct tmem_pool *pool); static void zbud_init(void) { int i; INIT_LIST_HEAD(&zbud_buddied_list); zcache_zbud_buddied_count = 0; for (i = 0; i < NCHUNKS; i++) { INIT_LIST_HEAD(&zbud_unbuddied[i].list); zbud_unbuddied[i].count = 0; } } #ifdef CONFIG_SYSFS /* * These sysfs routines show a nice distribution of how many zbpg's are * currently (and have ever been placed) in each unbuddied list. It's fun * to watch but can probably go away before final merge. */ static int zbud_show_unbuddied_list_counts(char *buf) { int i; char *p = buf; for (i = 0; i < NCHUNKS; i++) p += sprintf(p, "%u ", zbud_unbuddied[i].count); return p - buf; } static int zbud_show_cumul_chunk_counts(char *buf) { unsigned long i, chunks = 0, total_chunks = 0, sum_total_chunks = 0; unsigned long total_chunks_lte_21 = 0, total_chunks_lte_32 = 0; unsigned long total_chunks_lte_42 = 0; char *p = buf; for (i = 0; i < NCHUNKS; i++) { p += sprintf(p, "%lu ", zbud_cumul_chunk_counts[i]); chunks += zbud_cumul_chunk_counts[i]; total_chunks += zbud_cumul_chunk_counts[i]; sum_total_chunks += i * zbud_cumul_chunk_counts[i]; if (i == 21) total_chunks_lte_21 = total_chunks; if (i == 32) total_chunks_lte_32 = total_chunks; if (i == 42) total_chunks_lte_42 = total_chunks; } p += sprintf(p, "<=21:%lu <=32:%lu <=42:%lu, mean:%lu\n", total_chunks_lte_21, total_chunks_lte_32, total_chunks_lte_42, chunks == 0 ? 0 : sum_total_chunks / chunks); return p - buf; } #endif /* * zcache core code starts here */ /* useful stats not collected by cleancache or frontswap */ static unsigned long zcache_flush_total; static unsigned long zcache_flush_found; static unsigned long zcache_flobj_total; static unsigned long zcache_flobj_found; static unsigned long zcache_failed_eph_puts; /* * Tmem operations assume the poolid implies the invoking client. * Zcache only has one client (the kernel itself): LOCAL_CLIENT. * RAMster has each client numbered by cluster node, and a KVM version * of zcache would have one client per guest and each client might * have a poolid==N. */ static struct tmem_pool *zcache_get_pool_by_id(uint16_t cli_id, uint16_t poolid) { struct tmem_pool *pool = NULL; struct zcache_client *cli = NULL; if (cli_id == LOCAL_CLIENT) cli = &zcache_host; else { if (cli_id >= MAX_CLIENTS) goto out; cli = &zcache_clients[cli_id]; if (cli == NULL) goto out; atomic_inc(&cli->refcount); } if (poolid < MAX_POOLS_PER_CLIENT) { pool = cli->tmem_pools[poolid]; if (pool != NULL) atomic_inc(&pool->refcount); } out: return pool; } static void zcache_put_pool(struct tmem_pool *pool) { struct zcache_client *cli = NULL; if (pool == NULL) BUG(); cli = pool->client; atomic_dec(&pool->refcount); atomic_dec(&cli->refcount); } int zcache_new_client(uint16_t cli_id) { struct zcache_client *cli = NULL; int ret = -1; if (cli_id == LOCAL_CLIENT) cli = &zcache_host; else if ((unsigned int)cli_id < MAX_CLIENTS) cli = &zcache_clients[cli_id]; if (cli == NULL) goto out; if (cli->allocated) goto out; cli->allocated = 1; ret = 0; out: return ret; } /* counters for debugging */ static unsigned long zcache_failed_get_free_pages; static unsigned long zcache_failed_alloc; static unsigned long zcache_put_to_flush; static unsigned long zcache_aborted_preload; static unsigned long zcache_aborted_shrink; /* * Ensure that memory allocation requests in zcache don't result * in direct reclaim requests via the shrinker, which would cause * an infinite loop. Maybe a GFP flag would be better? */ static DEFINE_SPINLOCK(zcache_direct_reclaim_lock); /* * for now, used named slabs so can easily track usage; later can * either just use kmalloc, or perhaps add a slab-like allocator * to more carefully manage total memory utilization */ static struct kmem_cache *zcache_objnode_cache; static struct kmem_cache *zcache_obj_cache; static atomic_t zcache_curr_obj_count = ATOMIC_INIT(0); static unsigned long zcache_curr_obj_count_max; static atomic_t zcache_curr_objnode_count = ATOMIC_INIT(0); static unsigned long zcache_curr_objnode_count_max; /* * to avoid memory allocation recursion (e.g. due to direct reclaim), we * preload all necessary data structures so the hostops callbacks never * actually do a malloc */ struct zcache_preload { void *page; struct tmem_obj *obj; int nr; struct tmem_objnode *objnodes[OBJNODE_TREE_MAX_PATH]; }; static DEFINE_PER_CPU(struct zcache_preload, zcache_preloads) = { 0, }; static int zcache_do_preload(struct tmem_pool *pool) { struct zcache_preload *kp; struct tmem_objnode *objnode; struct tmem_obj *obj; void *page; int ret = -ENOMEM; if (unlikely(zcache_objnode_cache == NULL)) goto out; if (unlikely(zcache_obj_cache == NULL)) goto out; if (!spin_trylock(&zcache_direct_reclaim_lock)) { zcache_aborted_preload++; goto out; } preempt_disable(); kp = &__get_cpu_var(zcache_preloads); while (kp->nr < ARRAY_SIZE(kp->objnodes)) { preempt_enable_no_resched(); objnode = kmem_cache_alloc(zcache_objnode_cache, ZCACHE_GFP_MASK); if (unlikely(objnode == NULL)) { zcache_failed_alloc++; goto unlock_out; } preempt_disable(); kp = &__get_cpu_var(zcache_preloads); if (kp->nr < ARRAY_SIZE(kp->objnodes)) kp->objnodes[kp->nr++] = objnode; else kmem_cache_free(zcache_objnode_cache, objnode); } preempt_enable_no_resched(); obj = kmem_cache_alloc(zcache_obj_cache, ZCACHE_GFP_MASK); if (unlikely(obj == NULL)) { zcache_failed_alloc++; goto unlock_out; } page = qcache_alloc(); if (unlikely(page == NULL)) { zcache_failed_get_free_pages++; kmem_cache_free(zcache_obj_cache, obj); goto unlock_out; } preempt_disable(); kp = &__get_cpu_var(zcache_preloads); if (kp->obj == NULL) kp->obj = obj; else kmem_cache_free(zcache_obj_cache, obj); if (kp->page == NULL) kp->page = page; else qcache_free(page); ret = 0; unlock_out: spin_unlock(&zcache_direct_reclaim_lock); out: return ret; } static void *zcache_get_free_page(void) { struct zcache_preload *kp; void *page; kp = &__get_cpu_var(zcache_preloads); page = kp->page; BUG_ON(page == NULL); kp->page = NULL; return page; } /* * zcache implementation for tmem host ops */ static struct tmem_objnode *zcache_objnode_alloc(struct tmem_pool *pool) { struct tmem_objnode *objnode = NULL; unsigned long count; struct zcache_preload *kp; kp = &__get_cpu_var(zcache_preloads); if (kp->nr <= 0) goto out; objnode = kp->objnodes[kp->nr - 1]; BUG_ON(objnode == NULL); kp->objnodes[kp->nr - 1] = NULL; kp->nr--; count = atomic_inc_return(&zcache_curr_objnode_count); if (count > zcache_curr_objnode_count_max) zcache_curr_objnode_count_max = count; out: return objnode; } static void zcache_objnode_free(struct tmem_objnode *objnode, struct tmem_pool *pool) { atomic_dec(&zcache_curr_objnode_count); BUG_ON(atomic_read(&zcache_curr_objnode_count) < 0); kmem_cache_free(zcache_objnode_cache, objnode); } static struct tmem_obj *zcache_obj_alloc(struct tmem_pool *pool) { struct tmem_obj *obj = NULL; unsigned long count; struct zcache_preload *kp; kp = &__get_cpu_var(zcache_preloads); obj = kp->obj; BUG_ON(obj == NULL); kp->obj = NULL; count = atomic_inc_return(&zcache_curr_obj_count); if (count > zcache_curr_obj_count_max) zcache_curr_obj_count_max = count; return obj; } static void zcache_obj_free(struct tmem_obj *obj, struct tmem_pool *pool) { atomic_dec(&zcache_curr_obj_count); BUG_ON(atomic_read(&zcache_curr_obj_count) < 0); kmem_cache_free(zcache_obj_cache, obj); } static void zcache_flush_all_obj(void) { struct tmem_pool *pool; int pool_id; struct zcache_preload *kp; kp = &__get_cpu_var(zcache_preloads); for (pool_id = 0; pool_id < MAX_POOLS_PER_CLIENT; pool_id++) { pool = zcache_get_pool_by_id(LOCAL_CLIENT, pool_id); tmem_flush_pool(pool); if (pool != NULL) zcache_put_pool(pool); } if (kp->page) { qcache_free(kp->page); kp->page = NULL; } if (zcache_qc_used) pr_warn("pages used not 0 after qcache flush all, is %ld\n", zcache_qc_used); } /* * When zcache is disabled ("frozen"), pools can be created and destroyed, * but all puts (and thus all other operations that require memory allocation) * must fail. If zcache is unfrozen, accepts puts, then frozen again, * data consistency requires all puts while frozen to be converted into * flushes. */ static bool zcache_freeze; static void zcache_control(bool freeze) { zcache_freeze = freeze; } static struct tmem_hostops zcache_hostops = { .obj_alloc = zcache_obj_alloc, .obj_free = zcache_obj_free, .objnode_alloc = zcache_objnode_alloc, .objnode_free = zcache_objnode_free, .flush_all_obj = zcache_flush_all_obj, .control = zcache_control, }; /* * zcache implementations for PAM page descriptor ops */ static atomic_t zcache_curr_eph_pampd_count = ATOMIC_INIT(0); static unsigned long zcache_curr_eph_pampd_count_max; /* forward reference */ static int zcache_compress(struct page *from, void **out_va, size_t *out_len); static void *zcache_pampd_create(char *data, size_t size, bool raw, int eph, struct tmem_pool *pool, struct tmem_oid *oid, uint32_t index) { void *pampd = NULL, *cdata; size_t clen; int ret; unsigned long count; struct page *page = (struct page *)(data); struct zcache_client *cli = pool->client; uint16_t client_id = get_client_id_from_client(cli); ret = zcache_compress(page, &cdata, &clen); if (ret == 0) goto out; if (clen == 0 || clen > zbud_max_buddy_size()) { zcache_compress_poor++; goto out; } pampd = (void *)zbud_create(client_id, pool->pool_id, oid, index, page, cdata, clen); if (pampd != NULL) { count = atomic_inc_return(&zcache_curr_eph_pampd_count); if (count > zcache_curr_eph_pampd_count_max) zcache_curr_eph_pampd_count_max = count; } out: return pampd; } /* * fill the pageframe corresponding to the struct page with the data * from the passed pampd */ static int zcache_pampd_get_data(char *data, size_t *bufsize, bool raw, void *pampd, struct tmem_pool *pool, struct tmem_oid *oid, uint32_t index) { BUG(); return 0; } /* * fill the pageframe corresponding to the struct page with the data * from the passed pampd */ static int zcache_pampd_get_data_and_free(char *data, size_t *bufsize, bool raw, void *pampd, struct tmem_pool *pool, struct tmem_oid *oid, uint32_t index) { int ret = 0; zbud_decompress((struct page *)(data), pampd); zbud_free_and_delist((struct zbud_hdr *)pampd); atomic_dec(&zcache_curr_eph_pampd_count); return ret; } /* * free the pampd and remove it from any zcache lists * pampd must no longer be pointed to from any tmem data structures! */ static void zcache_pampd_free(void *pampd, struct tmem_pool *pool, struct tmem_oid *oid, uint32_t index) { zbud_free_and_delist((struct zbud_hdr *)pampd); atomic_dec(&zcache_curr_eph_pampd_count); BUG_ON(atomic_read(&zcache_curr_eph_pampd_count) < 0); } static void zcache_pampd_free_obj(struct tmem_pool *pool, struct tmem_obj *obj) { } static void zcache_pampd_new_obj(struct tmem_obj *obj) { } static int zcache_pampd_replace_in_obj(void *pampd, struct tmem_obj *obj) { return -1; } static bool zcache_pampd_is_remote(void *pampd) { return 0; } static struct tmem_pamops zcache_pamops = { .create = zcache_pampd_create, .get_data = zcache_pampd_get_data, .get_data_and_free = zcache_pampd_get_data_and_free, .free = zcache_pampd_free, .free_obj = zcache_pampd_free_obj, .new_obj = zcache_pampd_new_obj, .replace_in_obj = zcache_pampd_replace_in_obj, .is_remote = zcache_pampd_is_remote, }; /* * zcache compression/decompression and related per-cpu stuff */ #define LZO_WORKMEM_BYTES LZO1X_1_MEM_COMPRESS #define LZO_DSTMEM_PAGE_ORDER 1 static DEFINE_PER_CPU(unsigned char *, zcache_workmem); static DEFINE_PER_CPU(unsigned char *, zcache_dstmem); static int zcache_compress(struct page *from, void **out_va, size_t *out_len) { int ret = 0; unsigned char *dmem = __get_cpu_var(zcache_dstmem); unsigned char *wmem = __get_cpu_var(zcache_workmem); char *from_va; BUG_ON(!irqs_disabled()); if (unlikely(dmem == NULL || wmem == NULL)) goto out; /* no buffer, so can't compress */ from_va = kmap_atomic(from, KM_USER0); mb(); ret = lzo1x_1_compress(from_va, PAGE_SIZE, dmem, out_len, wmem); BUG_ON(ret != LZO_E_OK); *out_va = dmem; kunmap_atomic(from_va, KM_USER0); ret = 1; out: return ret; } #ifdef CONFIG_SYSFS #define ZCACHE_SYSFS_RO(_name) \ static ssize_t zcache_##_name##_show(struct kobject *kobj, \ struct kobj_attribute *attr, char *buf) \ { \ return sprintf(buf, "%lu\n", zcache_##_name); \ } \ static struct kobj_attribute zcache_##_name##_attr = { \ .attr = { .name = __stringify(_name), .mode = 0444 }, \ .show = zcache_##_name##_show, \ } #define ZCACHE_SYSFS_RO_ATOMIC(_name) \ static ssize_t zcache_##_name##_show(struct kobject *kobj, \ struct kobj_attribute *attr, char *buf) \ { \ return sprintf(buf, "%d\n", atomic_read(&zcache_##_name)); \ } \ static struct kobj_attribute zcache_##_name##_attr = { \ .attr = { .name = __stringify(_name), .mode = 0444 }, \ .show = zcache_##_name##_show, \ } #define ZCACHE_SYSFS_RO_CUSTOM(_name, _func) \ static ssize_t zcache_##_name##_show(struct kobject *kobj, \ struct kobj_attribute *attr, char *buf) \ { \ return _func(buf); \ } \ static struct kobj_attribute zcache_##_name##_attr = { \ .attr = { .name = __stringify(_name), .mode = 0444 }, \ .show = zcache_##_name##_show, \ } ZCACHE_SYSFS_RO(curr_obj_count_max); ZCACHE_SYSFS_RO(curr_objnode_count_max); ZCACHE_SYSFS_RO(flush_total); ZCACHE_SYSFS_RO(flush_found); ZCACHE_SYSFS_RO(flobj_total); ZCACHE_SYSFS_RO(flobj_found); ZCACHE_SYSFS_RO(failed_eph_puts); ZCACHE_SYSFS_RO(zbud_curr_zbytes); ZCACHE_SYSFS_RO(zbud_cumul_zpages); ZCACHE_SYSFS_RO(zbud_cumul_zbytes); ZCACHE_SYSFS_RO(zbud_buddied_count); ZCACHE_SYSFS_RO(failed_get_free_pages); ZCACHE_SYSFS_RO(failed_alloc); ZCACHE_SYSFS_RO(put_to_flush); ZCACHE_SYSFS_RO(aborted_preload); ZCACHE_SYSFS_RO(aborted_shrink); ZCACHE_SYSFS_RO(compress_poor); ZCACHE_SYSFS_RO(mean_compress_poor); ZCACHE_SYSFS_RO(qc_allocated); ZCACHE_SYSFS_RO(qc_freed); ZCACHE_SYSFS_RO(qc_used); ZCACHE_SYSFS_RO(qc_max_used); ZCACHE_SYSFS_RO_ATOMIC(zbud_curr_raw_pages); ZCACHE_SYSFS_RO_ATOMIC(zbud_curr_zpages); ZCACHE_SYSFS_RO_ATOMIC(curr_obj_count); ZCACHE_SYSFS_RO_ATOMIC(curr_objnode_count); ZCACHE_SYSFS_RO_CUSTOM(zbud_unbuddied_list_counts, zbud_show_unbuddied_list_counts); ZCACHE_SYSFS_RO_CUSTOM(zbud_cumul_chunk_counts, zbud_show_cumul_chunk_counts); static struct attribute *qcache_attrs[] = { &zcache_curr_obj_count_attr.attr, &zcache_curr_obj_count_max_attr.attr, &zcache_curr_objnode_count_attr.attr, &zcache_curr_objnode_count_max_attr.attr, &zcache_flush_total_attr.attr, &zcache_flobj_total_attr.attr, &zcache_flush_found_attr.attr, &zcache_flobj_found_attr.attr, &zcache_failed_eph_puts_attr.attr, &zcache_compress_poor_attr.attr, &zcache_mean_compress_poor_attr.attr, &zcache_zbud_curr_raw_pages_attr.attr, &zcache_zbud_curr_zpages_attr.attr, &zcache_zbud_curr_zbytes_attr.attr, &zcache_zbud_cumul_zpages_attr.attr, &zcache_zbud_cumul_zbytes_attr.attr, &zcache_zbud_buddied_count_attr.attr, &zcache_failed_get_free_pages_attr.attr, &zcache_failed_alloc_attr.attr, &zcache_put_to_flush_attr.attr, &zcache_aborted_preload_attr.attr, &zcache_aborted_shrink_attr.attr, &zcache_zbud_unbuddied_list_counts_attr.attr, &zcache_zbud_cumul_chunk_counts_attr.attr, &zcache_qc_allocated_attr.attr, &zcache_qc_freed_attr.attr, &zcache_qc_used_attr.attr, &zcache_qc_max_used_attr.attr, NULL, }; static struct attribute_group qcache_attr_group = { .attrs = qcache_attrs, .name = "qcache", }; #endif /* CONFIG_SYSFS */ /* * zcache shims between cleancache ops and tmem */ static int zcache_put_page(int cli_id, int pool_id, struct tmem_oid *oidp, uint32_t index, struct page *page) { struct tmem_pool *pool; int ret = -1; BUG_ON(!irqs_disabled()); pool = zcache_get_pool_by_id(cli_id, pool_id); if (unlikely(pool == NULL)) goto out; if (!zcache_freeze && zcache_do_preload(pool) == 0) { /* preload does preempt_disable on success */ ret = tmem_put(pool, oidp, index, (char *)(page), PAGE_SIZE, 0, is_ephemeral(pool)); if (ret < 0) { zcache_failed_eph_puts++; } zcache_put_pool(pool); preempt_enable_no_resched(); } else { zcache_put_to_flush++; if (atomic_read(&pool->obj_count) > 0) /* the put fails whether the flush succeeds or not */ (void)tmem_flush_page(pool, oidp, index); zcache_put_pool(pool); } out: return ret; } static int zcache_get_page(int cli_id, int pool_id, struct tmem_oid *oidp, uint32_t index, struct page *page) { struct tmem_pool *pool; int ret = -1; unsigned long flags; size_t size = PAGE_SIZE; local_irq_save(flags); pool = zcache_get_pool_by_id(cli_id, pool_id); if (likely(pool != NULL)) { if (atomic_read(&pool->obj_count) > 0) ret = tmem_get(pool, oidp, index, (char *)(page), &size, 0, is_ephemeral(pool)); zcache_put_pool(pool); } local_irq_restore(flags); return ret; } static int zcache_flush_page(int cli_id, int pool_id, struct tmem_oid *oidp, uint32_t index) { struct tmem_pool *pool; int ret = -1; unsigned long flags; local_irq_save(flags); zcache_flush_total++; pool = zcache_get_pool_by_id(cli_id, pool_id); if (likely(pool != NULL)) { if (atomic_read(&pool->obj_count) > 0) ret = tmem_flush_page(pool, oidp, index); zcache_put_pool(pool); } if (ret >= 0) zcache_flush_found++; local_irq_restore(flags); return ret; } static int zcache_flush_object(int cli_id, int pool_id, struct tmem_oid *oidp) { struct tmem_pool *pool; int ret = -1; unsigned long flags; local_irq_save(flags); zcache_flobj_total++; pool = zcache_get_pool_by_id(cli_id, pool_id); if (likely(pool != NULL)) { if (atomic_read(&pool->obj_count) > 0) ret = tmem_flush_object(pool, oidp); zcache_put_pool(pool); } if (ret >= 0) zcache_flobj_found++; local_irq_restore(flags); return ret; } static int zcache_destroy_pool(int cli_id, int pool_id) { struct tmem_pool *pool = NULL; struct zcache_client *cli = NULL; int ret = -1; if (pool_id < 0) goto out; if (cli_id == LOCAL_CLIENT) cli = &zcache_host; else if ((unsigned int)cli_id < MAX_CLIENTS) cli = &zcache_clients[cli_id]; if (cli == NULL) goto out; atomic_inc(&cli->refcount); pool = cli->tmem_pools[pool_id]; if (pool == NULL) goto out; cli->tmem_pools[pool_id] = NULL; /* wait for pool activity on other cpus to quiesce */ while (atomic_read(&pool->refcount) != 0) ; atomic_dec(&cli->refcount); local_bh_disable(); ret = tmem_destroy_pool(pool); local_bh_enable(); kfree(pool); pr_info("qcache: destroyed pool id=%d, cli_id=%d\n", pool_id, cli_id); out: return ret; } static int zcache_new_pool(uint16_t cli_id, uint32_t flags) { int poolid = -1; struct tmem_pool *pool; struct zcache_client *cli = NULL; if (cli_id == LOCAL_CLIENT) cli = &zcache_host; else if ((unsigned int)cli_id < MAX_CLIENTS) cli = &zcache_clients[cli_id]; if (cli == NULL) goto out; atomic_inc(&cli->refcount); pool = kmalloc(sizeof(struct tmem_pool), GFP_KERNEL); if (pool == NULL) { pr_info("qcache: pool creation failed: out of memory\n"); goto out; } for (poolid = 0; poolid < MAX_POOLS_PER_CLIENT; poolid++) if (cli->tmem_pools[poolid] == NULL) break; if (poolid >= MAX_POOLS_PER_CLIENT) { pr_info("qcache: pool creation failed: max exceeded\n"); kfree(pool); poolid = -1; goto out; } atomic_set(&pool->refcount, 0); pool->client = cli; pool->pool_id = poolid; tmem_new_pool(pool, flags); cli->tmem_pools[poolid] = pool; pr_info("qcache: created %s tmem pool, id=%d, client=%d\n", flags & TMEM_POOL_PERSIST ? "persistent" : "ephemeral", poolid, cli_id); out: if (cli != NULL) atomic_dec(&cli->refcount); return poolid; } /********** * Two kernel functionalities currently can be layered on top of tmem. * These are "cleancache" which is used as a second-chance cache for clean * page cache pages; and "frontswap" which is used for swap pages * to avoid writes to disk. A generic "shim" is provided here for each * to translate in-kernel semantics to zcache semantics. */ static void zcache_cleancache_put_page(int pool_id, struct cleancache_filekey key, pgoff_t index, struct page *page) { u32 ind = (u32) index; struct tmem_oid oid = *(struct tmem_oid *)&key; if (likely(ind == index)) (void)zcache_put_page(LOCAL_CLIENT, pool_id, &oid, index, page); } static int zcache_cleancache_get_page(int pool_id, struct cleancache_filekey key, pgoff_t index, struct page *page) { u32 ind = (u32) index; struct tmem_oid oid = *(struct tmem_oid *)&key; int ret = -1; if (likely(ind == index)) ret = zcache_get_page(LOCAL_CLIENT, pool_id, &oid, index, page); return ret; } static void zcache_cleancache_flush_page(int pool_id, struct cleancache_filekey key, pgoff_t index) { u32 ind = (u32) index; struct tmem_oid oid = *(struct tmem_oid *)&key; if (likely(ind == index)) (void)zcache_flush_page(LOCAL_CLIENT, pool_id, &oid, ind); } static void zcache_cleancache_flush_inode(int pool_id, struct cleancache_filekey key) { struct tmem_oid oid = *(struct tmem_oid *)&key; (void)zcache_flush_object(LOCAL_CLIENT, pool_id, &oid); } static void zcache_cleancache_flush_fs(int pool_id) { if (pool_id >= 0) (void)zcache_destroy_pool(LOCAL_CLIENT, pool_id); } static int zcache_cleancache_init_fs(size_t pagesize) { BUG_ON(sizeof(struct cleancache_filekey) != sizeof(struct tmem_oid)); BUG_ON(pagesize != PAGE_SIZE); return zcache_new_pool(LOCAL_CLIENT, 0); } static int zcache_cleancache_init_shared_fs(char *uuid, size_t pagesize) { /* shared pools are unsupported and map to private */ BUG_ON(sizeof(struct cleancache_filekey) != sizeof(struct tmem_oid)); BUG_ON(pagesize != PAGE_SIZE); return zcache_new_pool(LOCAL_CLIENT, 0); } static struct cleancache_ops zcache_cleancache_ops = { .put_page = zcache_cleancache_put_page, .get_page = zcache_cleancache_get_page, .flush_page = zcache_cleancache_flush_page, .flush_inode = zcache_cleancache_flush_inode, .flush_fs = zcache_cleancache_flush_fs, .init_shared_fs = zcache_cleancache_init_shared_fs, .init_fs = zcache_cleancache_init_fs }; struct cleancache_ops zcache_cleancache_register_ops(void) { struct cleancache_ops old_ops = cleancache_register_ops(&zcache_cleancache_ops); return old_ops; } static int __init qcache_init(void) { int ret = 0; struct qcache_info *qc = &qcache_info; struct fmem_data *fdp; int bitmap_size; unsigned int cpu; struct cleancache_ops old_ops; #ifdef CONFIG_SYSFS ret = sysfs_create_group(mm_kobj, &qcache_attr_group); if (ret) { pr_err("qcache: can't create sysfs\n"); goto out; } #endif /* CONFIG_SYSFS */ fdp = fmem_get_info(); qc->addr = fdp->virt; qc->pages = fdp->size >> PAGE_SHIFT; if (!qc->pages) goto out; tmem_register_hostops(&zcache_hostops); tmem_register_pamops(&zcache_pamops); for_each_online_cpu(cpu) { per_cpu(zcache_dstmem, cpu) = (void *)__get_free_pages( GFP_KERNEL | __GFP_REPEAT, LZO_DSTMEM_PAGE_ORDER), per_cpu(zcache_workmem, cpu) = kzalloc(LZO1X_MEM_COMPRESS, GFP_KERNEL | __GFP_REPEAT); } zcache_objnode_cache = kmem_cache_create("zcache_objnode", sizeof(struct tmem_objnode), 0, 0, NULL); zcache_obj_cache = kmem_cache_create("zcache_obj", sizeof(struct tmem_obj), 0, 0, NULL); ret = zcache_new_client(LOCAL_CLIENT); if (ret) { pr_err("qcache: can't create client\n"); goto out; } zbud_init(); old_ops = zcache_cleancache_register_ops(); pr_info("qcache: cleancache enabled using kernel " "transcendent memory and compression buddies\n"); if (old_ops.init_fs != NULL) pr_warning("qcache: cleancache_ops overridden"); bitmap_size = BITS_TO_LONGS(qc->pages) * sizeof(long); qc->bitmap = kzalloc(bitmap_size, GFP_KERNEL); if (!qc->bitmap) { pr_info("can't allocate qcache bitmap!\n"); ret = -ENOMEM; goto out; } spin_lock_init(&qc->lock); fmem_set_state(FMEM_T_STATE); out: return ret; } module_init(qcache_init)
gpl-2.0
bebbo/gcc
libgfortran/generated/_dim_r16.F90
16
1458
! Copyright (C) 2002-2016 Free Software Foundation, Inc. ! Contributed by Paul Brook <paul@nowt.org> ! !This file is part of the GNU Fortran 95 runtime library (libgfortran). ! !GNU libgfortran is free software; you can redistribute it and/or !modify it under the terms of the GNU General Public !License as published by the Free Software Foundation; either !version 3 of the License, or (at your option) any later version. !GNU libgfortran is distributed in the hope that it will be useful, !but WITHOUT ANY WARRANTY; without even the implied warranty of !MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the !GNU General Public License for more details. ! !Under Section 7 of GPL version 3, you are granted additional !permissions described in the GCC Runtime Library Exception, version !3.1, as published by the Free Software Foundation. ! !You should have received a copy of the GNU General Public License and !a copy of the GCC Runtime Library Exception along with this program; !see the files COPYING3 and COPYING.RUNTIME respectively. If not, see !<http://www.gnu.org/licenses/>. ! !This file is machine generated. #include "config.h" #include "kinds.inc" #include "c99_protos.inc" #if defined (HAVE_GFC_REAL_16) elemental function _gfortran_specific__dim_r16 (p1, p2) real (kind=16), intent (in) :: p1, p2 real (kind=16) :: _gfortran_specific__dim_r16 _gfortran_specific__dim_r16 = dim (p1, p2) end function #endif
gpl-2.0
elliott10/decaf-multiOS
shared/sleuthkit.b/src/fstools/dcalc_lib.c
16
4832
/* ** dcalc ** The Sleuth Kit ** ** $Date: 2006-07-10 14:22:27 -0400 (Mon, 10 Jul 2006) $ ** ** Calculates the corresponding block number between 'dls' and 'dd' images ** when given an 'dls' block number, it determines the block number it ** had in a 'dd' image. When given a 'dd' image, it determines the ** value it would have in a 'dls' image (if the block is unallocated) ** ** Brian Carrier [carrier@sleuthkit.org] ** Copyright (c) 2006 Brian Carrier, Basis Technology. All Rights reserved ** Copyright (c) 2003-2005 Brian Carrier. All Rights reserved ** ** TASK ** Copyright (c) 2002 Brian Carrier, @stake Inc. All Rights reserved ** ** TCTUTILs ** Copyright (c) 2001 Brian Carrier. All rights reserved ** ** ** This software is distributed under the Common Public License 1.0 ** */ #include "libfstools.h" static DADDR_T count; static DADDR_T uncnt = 0; static uint8_t found = 0; /* function used when -d is given ** ** keeps a count of unallocated blocks seen thus far ** ** If the specified block is allocated, an error is given, else the ** count of unalloc blocks is given ** ** This is called for all blocks (alloc and unalloc) */ static uint8_t count_dd_act(FS_INFO * fs, DADDR_T addr, char *buf, int flags, void *ptr) { if (flags & FS_FLAG_DATA_UNALLOC) uncnt++; if (count-- == 0) { if (flags & FS_FLAG_DATA_UNALLOC) printf("%" PRIuDADDR "\n", uncnt); else printf ("ERROR: unit is allocated, it will not be in an dls image\n"); found = 1; return WALK_STOP; } return WALK_CONT; } /* ** count how many unalloc blocks there are. ** ** This is called for unalloc blocks only */ static uint8_t count_dls_act(FS_INFO * fs, DADDR_T addr, char *buf, int flags, void *ptr) { if (count-- == 0) { printf("%" PRIuDADDR "\n", addr); found = 1; return WALK_STOP; } return WALK_CONT; } /* SLACK SPACE call backs */ static OFF_T flen; static uint8_t count_slack_file_act(FS_INFO * fs, DADDR_T addr, char *buf, unsigned int size, int flags, void *ptr) { if (verbose) fprintf(stderr, "count_slack_file_act: Remaining File: %lu Buffer: %lu\n", (ULONG) flen, (ULONG) size); /* This is not the last data unit */ if (flen >= size) { flen -= size; } /* We have passed the end of the allocated space */ else if (flen == 0) { if (count-- == 0) { printf("%" PRIuDADDR "\n", addr); found = 1; return WALK_STOP; } } /* This is the last data unit and there is unused space */ else if (flen < size) { if (count-- == 0) { printf("%" PRIuDADDR "\n", addr); found = 1; return WALK_STOP; } flen = 0; } return WALK_CONT; } static uint8_t count_slack_inode_act(FS_INFO * fs, FS_INODE * fs_inode, int flags, void *ptr) { if (verbose) fprintf(stderr, "count_slack_inode_act: Processing meta data: %" PRIuINUM "\n", fs_inode->addr); /* We will now do a file walk on the content */ if ((fs->ftype & FSMASK) != NTFS_TYPE) { flen = fs_inode->size; if (fs->file_walk(fs, fs_inode, 0, 0, FS_FLAG_FILE_SLACK | FS_FLAG_FILE_NOID, count_slack_file_act, ptr)) { /* ignore any errors */ if (verbose) fprintf(stderr, "Error walking file %" PRIuINUM, fs_inode->addr); tsk_errno = 0; } } /* For NTFS we go through each non-resident attribute */ else { FS_DATA *fs_data = fs_inode->attr; while ((fs_data) && (fs_data->flags & FS_DATA_INUSE)) { if (fs_data->flags & FS_DATA_NONRES) { flen = fs_data->size; if (fs->file_walk(fs, fs_inode, fs_data->type, fs_data->id, FS_FLAG_FILE_SLACK, count_slack_file_act, ptr)) { /* ignore any errors */ if (verbose) fprintf(stderr, "Error walking file %" PRIuINUM, fs_inode->addr); tsk_errno = 0; } } fs_data = fs_data->next; } } return WALK_CONT; } /* Return 1 if block is not found, 0 if it was found, and -1 on error */ int8_t fs_dcalc(FS_INFO * fs, uint8_t lclflags, DADDR_T cnt) { count = cnt; found = 0; if (lclflags == DCALC_DLS) { if (fs->block_walk(fs, fs->first_block, fs->last_block, (FS_FLAG_DATA_UNALLOC | FS_FLAG_DATA_ALIGN | FS_FLAG_DATA_META | FS_FLAG_DATA_CONT), count_dls_act, NULL)) return -1; } else if (lclflags == DCALC_DD) { if (fs->block_walk(fs, fs->first_block, fs->last_block, (FS_FLAG_DATA_ALLOC | FS_FLAG_DATA_UNALLOC | FS_FLAG_DATA_ALIGN | FS_FLAG_DATA_META | FS_FLAG_DATA_CONT), count_dd_act, NULL)) return -1; } else if (lclflags == DCALC_SLACK) { if (fs->inode_walk(fs, fs->first_inum, fs->last_inum, (FS_FLAG_META_ALLOC | FS_FLAG_META_USED | FS_FLAG_META_LINK), count_slack_inode_act, NULL)) return -1; } if (found == 0) { printf("Block too large\n"); return 1; } else { return 0; } }
gpl-2.0
dk123546/trinity-mmaps
dep/acelite/ace/Base_Thread_Adapter.cpp
272
3775
// $Id: Base_Thread_Adapter.cpp 91286 2010-08-05 09:04:31Z johnnyw $ #include "ace/Base_Thread_Adapter.h" #if !defined (ACE_HAS_INLINED_OSCALLS) # include "ace/Base_Thread_Adapter.inl" #endif /* ACE_HAS_INLINED_OSCALLS */ #if defined (ACE_HAS_TSS_EMULATION) # include "ace/OS_NS_Thread.h" #endif /* ACE_HAS_TSS_EMULATION */ #include "ace/Service_Config.h" ACE_BEGIN_VERSIONED_NAMESPACE_DECL ACE_INIT_LOG_MSG_HOOK ACE_Base_Thread_Adapter::init_log_msg_hook_ = 0; ACE_INHERIT_LOG_MSG_HOOK ACE_Base_Thread_Adapter::inherit_log_msg_hook_ = 0; ACE_CLOSE_LOG_MSG_HOOK ACE_Base_Thread_Adapter::close_log_msg_hook_ = 0; ACE_SYNC_LOG_MSG_HOOK ACE_Base_Thread_Adapter::sync_log_msg_hook_ = 0; ACE_THR_DESC_LOG_MSG_HOOK ACE_Base_Thread_Adapter::thr_desc_log_msg_hook_ = 0; ACE_Base_Thread_Adapter::ACE_Base_Thread_Adapter ( ACE_THR_FUNC user_func, void *arg, ACE_THR_C_FUNC entry_point, ACE_OS_Thread_Descriptor *td #if defined (ACE_HAS_WIN32_STRUCTURAL_EXCEPTIONS) , ACE_SEH_EXCEPT_HANDLER selector , ACE_SEH_EXCEPT_HANDLER handler #endif /* ACE_HAS_WIN32_STRUCTURAL_EXCEPTIONS */ ) : user_func_ (user_func) , arg_ (arg) , entry_point_ (entry_point) , thr_desc_ (td) , ctx_ (ACE_Service_Config::current()) { ACE_OS_TRACE ("ACE_Base_Thread_Adapter::ACE_Base_Thread_Adapter"); if (ACE_Base_Thread_Adapter::init_log_msg_hook_ != 0) (*ACE_Base_Thread_Adapter::init_log_msg_hook_) ( this->log_msg_attributes_ # if defined (ACE_HAS_WIN32_STRUCTURAL_EXCEPTIONS) , selector , handler # endif /* ACE_HAS_WIN32_STRUCTURAL_EXCEPTIONS */ ); #ifdef ACE_USES_GPROF getitimer (ITIMER_PROF, &itimer_); #endif // ACE_USES_GPROF } ACE_Base_Thread_Adapter::~ACE_Base_Thread_Adapter (void) { } void ACE_Base_Thread_Adapter::inherit_log_msg (void) { if (ACE_Base_Thread_Adapter::inherit_log_msg_hook_ != 0) (*ACE_Base_Thread_Adapter::inherit_log_msg_hook_)( this->thr_desc_, this->log_msg_attributes_); // Initialize the proper configuration context for the new thread // Placed here since inherit_log_msg() gets called from any of our // descendants (before self-destructing) ACE_Service_Config::current (this->ctx_); } void ACE_Base_Thread_Adapter::close_log_msg (void) { if (ACE_Base_Thread_Adapter::close_log_msg_hook_ != 0) (*ACE_Base_Thread_Adapter::close_log_msg_hook_) (); } void ACE_Base_Thread_Adapter::sync_log_msg (const ACE_TCHAR *prg) { if (ACE_Base_Thread_Adapter::sync_log_msg_hook_ != 0) (*ACE_Base_Thread_Adapter::sync_log_msg_hook_) (prg); } ACE_OS_Thread_Descriptor * ACE_Base_Thread_Adapter::thr_desc_log_msg (void) { if (ACE_Base_Thread_Adapter::thr_desc_log_msg_hook_ != 0) return (*ACE_Base_Thread_Adapter::thr_desc_log_msg_hook_) (); return 0; } ACE_END_VERSIONED_NAMESPACE_DECL // Run the thread entry point for the <ACE_Thread_Adapter>. This must // be an extern "C" to make certain compilers happy... extern "C" ACE_THR_FUNC_RETURN ACE_THREAD_ADAPTER_NAME (void *args) { ACE_OS_TRACE ("ACE_THREAD_ADAPTER_NAME"); #if defined (ACE_HAS_TSS_EMULATION) // As early as we can in the execution of the new thread, allocate // its local TS storage. Allocate it on the stack, to save dynamic // allocation/dealloction. void *ts_storage[ACE_TSS_Emulation::ACE_TSS_THREAD_KEYS_MAX]; ACE_TSS_Emulation::tss_open (ts_storage); #endif /* ACE_HAS_TSS_EMULATION */ ACE_Base_Thread_Adapter * const thread_args = static_cast<ACE_Base_Thread_Adapter *> (args); #ifdef ACE_USES_GPROF setitimer (ITIMER_PROF, thread_args->timerval (), 0); #endif // ACE_USES_GPROF // Invoke the user-supplied function with the args. ACE_THR_FUNC_RETURN status = thread_args->invoke (); return status; }
gpl-2.0
ystk/linux-3.14-ltsi-work
drivers/media/radio/si470x/radio-si470x-common.c
528
21254
/* * drivers/media/radio/si470x/radio-si470x-common.c * * Driver for radios with Silicon Labs Si470x FM Radio Receivers * * Copyright (c) 2009 Tobias Lorenz <tobias.lorenz@gmx.net> * Copyright (c) 2012 Hans de Goede <hdegoede@redhat.com> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ /* * History: * 2008-01-12 Tobias Lorenz <tobias.lorenz@gmx.net> * Version 1.0.0 * - First working version * 2008-01-13 Tobias Lorenz <tobias.lorenz@gmx.net> * Version 1.0.1 * - Improved error handling, every function now returns errno * - Improved multi user access (start/mute/stop) * - Channel doesn't get lost anymore after start/mute/stop * - RDS support added (polling mode via interrupt EP 1) * - marked default module parameters with *value* * - switched from bit structs to bit masks * - header file cleaned and integrated * 2008-01-14 Tobias Lorenz <tobias.lorenz@gmx.net> * Version 1.0.2 * - hex values are now lower case * - commented USB ID for ADS/Tech moved on todo list * - blacklisted si470x in hid-quirks.c * - rds buffer handling functions integrated into *_work, *_read * - rds_command in si470x_poll exchanged against simple retval * - check for firmware version 15 * - code order and prototypes still remain the same * - spacing and bottom of band codes remain the same * 2008-01-16 Tobias Lorenz <tobias.lorenz@gmx.net> * Version 1.0.3 * - code reordered to avoid function prototypes * - switch/case defaults are now more user-friendly * - unified comment style * - applied all checkpatch.pl v1.12 suggestions * except the warning about the too long lines with bit comments * - renamed FMRADIO to RADIO to cut line length (checkpatch.pl) * 2008-01-22 Tobias Lorenz <tobias.lorenz@gmx.net> * Version 1.0.4 * - avoid poss. locking when doing copy_to_user which may sleep * - RDS is automatically activated on read now * - code cleaned of unnecessary rds_commands * - USB Vendor/Product ID for ADS/Tech FM Radio Receiver verified * (thanks to Guillaume RAMOUSSE) * 2008-01-27 Tobias Lorenz <tobias.lorenz@gmx.net> * Version 1.0.5 * - number of seek_retries changed to tune_timeout * - fixed problem with incomplete tune operations by own buffers * - optimization of variables and printf types * - improved error logging * 2008-01-31 Tobias Lorenz <tobias.lorenz@gmx.net> * Oliver Neukum <oliver@neukum.org> * Version 1.0.6 * - fixed coverity checker warnings in *_usb_driver_disconnect * - probe()/open() race by correct ordering in probe() * - DMA coherency rules by separate allocation of all buffers * - use of endianness macros * - abuse of spinlock, replaced by mutex * - racy handling of timer in disconnect, * replaced by delayed_work * - racy interruptible_sleep_on(), * replaced with wait_event_interruptible() * - handle signals in read() * 2008-02-08 Tobias Lorenz <tobias.lorenz@gmx.net> * Oliver Neukum <oliver@neukum.org> * Version 1.0.7 * - usb autosuspend support * - unplugging fixed * 2008-05-07 Tobias Lorenz <tobias.lorenz@gmx.net> * Version 1.0.8 * - hardware frequency seek support * - afc indication * - more safety checks, let si470x_get_freq return errno * - vidioc behavior corrected according to v4l2 spec * 2008-10-20 Alexey Klimov <klimov.linux@gmail.com> * - add support for KWorld USB FM Radio FM700 * - blacklisted KWorld radio in hid-core.c and hid-ids.h * 2008-12-03 Mark Lord <mlord@pobox.com> * - add support for DealExtreme USB Radio * 2009-01-31 Bob Ross <pigiron@gmx.com> * - correction of stereo detection/setting * - correction of signal strength indicator scaling * 2009-01-31 Rick Bronson <rick@efn.org> * Tobias Lorenz <tobias.lorenz@gmx.net> * - add LED status output * - get HW/SW version from scratchpad * 2009-06-16 Edouard Lafargue <edouard@lafargue.name> * Version 1.0.10 * - add support for interrupt mode for RDS endpoint, * instead of polling. * Improves RDS reception significantly */ /* kernel includes */ #include "radio-si470x.h" /************************************************************************** * Module Parameters **************************************************************************/ /* Spacing (kHz) */ /* 0: 200 kHz (USA, Australia) */ /* 1: 100 kHz (Europe, Japan) */ /* 2: 50 kHz */ static unsigned short space = 2; module_param(space, ushort, 0444); MODULE_PARM_DESC(space, "Spacing: 0=200kHz 1=100kHz *2=50kHz*"); /* De-emphasis */ /* 0: 75 us (USA) */ /* 1: 50 us (Europe, Australia, Japan) */ static unsigned short de = 1; module_param(de, ushort, 0444); MODULE_PARM_DESC(de, "De-emphasis: 0=75us *1=50us*"); /* Tune timeout */ static unsigned int tune_timeout = 3000; module_param(tune_timeout, uint, 0644); MODULE_PARM_DESC(tune_timeout, "Tune timeout: *3000*"); /* Seek timeout */ static unsigned int seek_timeout = 5000; module_param(seek_timeout, uint, 0644); MODULE_PARM_DESC(seek_timeout, "Seek timeout: *5000*"); static const struct v4l2_frequency_band bands[] = { { .type = V4L2_TUNER_RADIO, .index = 0, .capability = V4L2_TUNER_CAP_LOW | V4L2_TUNER_CAP_STEREO | V4L2_TUNER_CAP_RDS | V4L2_TUNER_CAP_RDS_BLOCK_IO | V4L2_TUNER_CAP_FREQ_BANDS | V4L2_TUNER_CAP_HWSEEK_BOUNDED | V4L2_TUNER_CAP_HWSEEK_WRAP, .rangelow = 87500 * 16, .rangehigh = 108000 * 16, .modulation = V4L2_BAND_MODULATION_FM, }, { .type = V4L2_TUNER_RADIO, .index = 1, .capability = V4L2_TUNER_CAP_LOW | V4L2_TUNER_CAP_STEREO | V4L2_TUNER_CAP_RDS | V4L2_TUNER_CAP_RDS_BLOCK_IO | V4L2_TUNER_CAP_FREQ_BANDS | V4L2_TUNER_CAP_HWSEEK_BOUNDED | V4L2_TUNER_CAP_HWSEEK_WRAP, .rangelow = 76000 * 16, .rangehigh = 108000 * 16, .modulation = V4L2_BAND_MODULATION_FM, }, { .type = V4L2_TUNER_RADIO, .index = 2, .capability = V4L2_TUNER_CAP_LOW | V4L2_TUNER_CAP_STEREO | V4L2_TUNER_CAP_RDS | V4L2_TUNER_CAP_RDS_BLOCK_IO | V4L2_TUNER_CAP_FREQ_BANDS | V4L2_TUNER_CAP_HWSEEK_BOUNDED | V4L2_TUNER_CAP_HWSEEK_WRAP, .rangelow = 76000 * 16, .rangehigh = 90000 * 16, .modulation = V4L2_BAND_MODULATION_FM, }, }; /************************************************************************** * Generic Functions **************************************************************************/ /* * si470x_set_band - set the band */ static int si470x_set_band(struct si470x_device *radio, int band) { if (radio->band == band) return 0; radio->band = band; radio->registers[SYSCONFIG2] &= ~SYSCONFIG2_BAND; radio->registers[SYSCONFIG2] |= radio->band << 6; return si470x_set_register(radio, SYSCONFIG2); } /* * si470x_set_chan - set the channel */ static int si470x_set_chan(struct si470x_device *radio, unsigned short chan) { int retval; bool timed_out = 0; /* start tuning */ radio->registers[CHANNEL] &= ~CHANNEL_CHAN; radio->registers[CHANNEL] |= CHANNEL_TUNE | chan; retval = si470x_set_register(radio, CHANNEL); if (retval < 0) goto done; /* wait till tune operation has completed */ reinit_completion(&radio->completion); retval = wait_for_completion_timeout(&radio->completion, msecs_to_jiffies(tune_timeout)); if (!retval) timed_out = true; if ((radio->registers[STATUSRSSI] & STATUSRSSI_STC) == 0) dev_warn(&radio->videodev.dev, "tune does not complete\n"); if (timed_out) dev_warn(&radio->videodev.dev, "tune timed out after %u ms\n", tune_timeout); /* stop tuning */ radio->registers[CHANNEL] &= ~CHANNEL_TUNE; retval = si470x_set_register(radio, CHANNEL); done: return retval; } /* * si470x_get_step - get channel spacing */ static unsigned int si470x_get_step(struct si470x_device *radio) { /* Spacing (kHz) */ switch ((radio->registers[SYSCONFIG2] & SYSCONFIG2_SPACE) >> 4) { /* 0: 200 kHz (USA, Australia) */ case 0: return 200 * 16; /* 1: 100 kHz (Europe, Japan) */ case 1: return 100 * 16; /* 2: 50 kHz */ default: return 50 * 16; } } /* * si470x_get_freq - get the frequency */ static int si470x_get_freq(struct si470x_device *radio, unsigned int *freq) { int chan, retval; /* read channel */ retval = si470x_get_register(radio, READCHAN); chan = radio->registers[READCHAN] & READCHAN_READCHAN; /* Frequency (MHz) = Spacing (kHz) x Channel + Bottom of Band (MHz) */ *freq = chan * si470x_get_step(radio) + bands[radio->band].rangelow; return retval; } /* * si470x_set_freq - set the frequency */ int si470x_set_freq(struct si470x_device *radio, unsigned int freq) { unsigned short chan; freq = clamp(freq, bands[radio->band].rangelow, bands[radio->band].rangehigh); /* Chan = [ Freq (Mhz) - Bottom of Band (MHz) ] / Spacing (kHz) */ chan = (freq - bands[radio->band].rangelow) / si470x_get_step(radio); return si470x_set_chan(radio, chan); } /* * si470x_set_seek - set seek */ static int si470x_set_seek(struct si470x_device *radio, const struct v4l2_hw_freq_seek *seek) { int band, retval; unsigned int freq; bool timed_out = 0; /* set band */ if (seek->rangelow || seek->rangehigh) { for (band = 0; band < ARRAY_SIZE(bands); band++) { if (bands[band].rangelow == seek->rangelow && bands[band].rangehigh == seek->rangehigh) break; } if (band == ARRAY_SIZE(bands)) return -EINVAL; /* No matching band found */ } else band = 1; /* If nothing is specified seek 76 - 108 Mhz */ if (radio->band != band) { retval = si470x_get_freq(radio, &freq); if (retval) return retval; retval = si470x_set_band(radio, band); if (retval) return retval; retval = si470x_set_freq(radio, freq); if (retval) return retval; } /* start seeking */ radio->registers[POWERCFG] |= POWERCFG_SEEK; if (seek->wrap_around) radio->registers[POWERCFG] &= ~POWERCFG_SKMODE; else radio->registers[POWERCFG] |= POWERCFG_SKMODE; if (seek->seek_upward) radio->registers[POWERCFG] |= POWERCFG_SEEKUP; else radio->registers[POWERCFG] &= ~POWERCFG_SEEKUP; retval = si470x_set_register(radio, POWERCFG); if (retval < 0) return retval; /* wait till tune operation has completed */ reinit_completion(&radio->completion); retval = wait_for_completion_timeout(&radio->completion, msecs_to_jiffies(seek_timeout)); if (!retval) timed_out = true; if ((radio->registers[STATUSRSSI] & STATUSRSSI_STC) == 0) dev_warn(&radio->videodev.dev, "seek does not complete\n"); if (radio->registers[STATUSRSSI] & STATUSRSSI_SF) dev_warn(&radio->videodev.dev, "seek failed / band limit reached\n"); /* stop seeking */ radio->registers[POWERCFG] &= ~POWERCFG_SEEK; retval = si470x_set_register(radio, POWERCFG); /* try again, if timed out */ if (retval == 0 && timed_out) return -ENODATA; return retval; } /* * si470x_start - switch on radio */ int si470x_start(struct si470x_device *radio) { int retval; /* powercfg */ radio->registers[POWERCFG] = POWERCFG_DMUTE | POWERCFG_ENABLE | POWERCFG_RDSM; retval = si470x_set_register(radio, POWERCFG); if (retval < 0) goto done; /* sysconfig 1 */ radio->registers[SYSCONFIG1] = (de << 11) & SYSCONFIG1_DE; /* DE*/ retval = si470x_set_register(radio, SYSCONFIG1); if (retval < 0) goto done; /* sysconfig 2 */ radio->registers[SYSCONFIG2] = (0x1f << 8) | /* SEEKTH */ ((radio->band << 6) & SYSCONFIG2_BAND) |/* BAND */ ((space << 4) & SYSCONFIG2_SPACE) | /* SPACE */ 15; /* VOLUME (max) */ retval = si470x_set_register(radio, SYSCONFIG2); if (retval < 0) goto done; /* reset last channel */ retval = si470x_set_chan(radio, radio->registers[CHANNEL] & CHANNEL_CHAN); done: return retval; } /* * si470x_stop - switch off radio */ int si470x_stop(struct si470x_device *radio) { int retval; /* sysconfig 1 */ radio->registers[SYSCONFIG1] &= ~SYSCONFIG1_RDS; retval = si470x_set_register(radio, SYSCONFIG1); if (retval < 0) goto done; /* powercfg */ radio->registers[POWERCFG] &= ~POWERCFG_DMUTE; /* POWERCFG_ENABLE has to automatically go low */ radio->registers[POWERCFG] |= POWERCFG_ENABLE | POWERCFG_DISABLE; retval = si470x_set_register(radio, POWERCFG); done: return retval; } /* * si470x_rds_on - switch on rds reception */ static int si470x_rds_on(struct si470x_device *radio) { int retval; /* sysconfig 1 */ radio->registers[SYSCONFIG1] |= SYSCONFIG1_RDS; retval = si470x_set_register(radio, SYSCONFIG1); if (retval < 0) radio->registers[SYSCONFIG1] &= ~SYSCONFIG1_RDS; return retval; } /************************************************************************** * File Operations Interface **************************************************************************/ /* * si470x_fops_read - read RDS data */ static ssize_t si470x_fops_read(struct file *file, char __user *buf, size_t count, loff_t *ppos) { struct si470x_device *radio = video_drvdata(file); int retval = 0; unsigned int block_count = 0; /* switch on rds reception */ if ((radio->registers[SYSCONFIG1] & SYSCONFIG1_RDS) == 0) si470x_rds_on(radio); /* block if no new data available */ while (radio->wr_index == radio->rd_index) { if (file->f_flags & O_NONBLOCK) { retval = -EWOULDBLOCK; goto done; } if (wait_event_interruptible(radio->read_queue, radio->wr_index != radio->rd_index) < 0) { retval = -EINTR; goto done; } } /* calculate block count from byte count */ count /= 3; /* copy RDS block out of internal buffer and to user buffer */ while (block_count < count) { if (radio->rd_index == radio->wr_index) break; /* always transfer rds complete blocks */ if (copy_to_user(buf, &radio->buffer[radio->rd_index], 3)) /* retval = -EFAULT; */ break; /* increment and wrap read pointer */ radio->rd_index += 3; if (radio->rd_index >= radio->buf_size) radio->rd_index = 0; /* increment counters */ block_count++; buf += 3; retval += 3; } done: return retval; } /* * si470x_fops_poll - poll RDS data */ static unsigned int si470x_fops_poll(struct file *file, struct poll_table_struct *pts) { struct si470x_device *radio = video_drvdata(file); unsigned long req_events = poll_requested_events(pts); int retval = v4l2_ctrl_poll(file, pts); if (req_events & (POLLIN | POLLRDNORM)) { /* switch on rds reception */ if ((radio->registers[SYSCONFIG1] & SYSCONFIG1_RDS) == 0) si470x_rds_on(radio); poll_wait(file, &radio->read_queue, pts); if (radio->rd_index != radio->wr_index) retval |= POLLIN | POLLRDNORM; } return retval; } /* * si470x_fops - file operations interface */ static const struct v4l2_file_operations si470x_fops = { .owner = THIS_MODULE, .read = si470x_fops_read, .poll = si470x_fops_poll, .unlocked_ioctl = video_ioctl2, .open = si470x_fops_open, .release = si470x_fops_release, }; /************************************************************************** * Video4Linux Interface **************************************************************************/ static int si470x_s_ctrl(struct v4l2_ctrl *ctrl) { struct si470x_device *radio = container_of(ctrl->handler, struct si470x_device, hdl); switch (ctrl->id) { case V4L2_CID_AUDIO_VOLUME: radio->registers[SYSCONFIG2] &= ~SYSCONFIG2_VOLUME; radio->registers[SYSCONFIG2] |= ctrl->val; return si470x_set_register(radio, SYSCONFIG2); case V4L2_CID_AUDIO_MUTE: if (ctrl->val) radio->registers[POWERCFG] &= ~POWERCFG_DMUTE; else radio->registers[POWERCFG] |= POWERCFG_DMUTE; return si470x_set_register(radio, POWERCFG); default: return -EINVAL; } } /* * si470x_vidioc_g_tuner - get tuner attributes */ static int si470x_vidioc_g_tuner(struct file *file, void *priv, struct v4l2_tuner *tuner) { struct si470x_device *radio = video_drvdata(file); int retval = 0; if (tuner->index != 0) return -EINVAL; if (!radio->status_rssi_auto_update) { retval = si470x_get_register(radio, STATUSRSSI); if (retval < 0) return retval; } /* driver constants */ strcpy(tuner->name, "FM"); tuner->type = V4L2_TUNER_RADIO; tuner->capability = V4L2_TUNER_CAP_LOW | V4L2_TUNER_CAP_STEREO | V4L2_TUNER_CAP_RDS | V4L2_TUNER_CAP_RDS_BLOCK_IO | V4L2_TUNER_CAP_HWSEEK_BOUNDED | V4L2_TUNER_CAP_HWSEEK_WRAP; tuner->rangelow = 76 * FREQ_MUL; tuner->rangehigh = 108 * FREQ_MUL; /* stereo indicator == stereo (instead of mono) */ if ((radio->registers[STATUSRSSI] & STATUSRSSI_ST) == 0) tuner->rxsubchans = V4L2_TUNER_SUB_MONO; else tuner->rxsubchans = V4L2_TUNER_SUB_STEREO; /* If there is a reliable method of detecting an RDS channel, then this code should check for that before setting this RDS subchannel. */ tuner->rxsubchans |= V4L2_TUNER_SUB_RDS; /* mono/stereo selector */ if ((radio->registers[POWERCFG] & POWERCFG_MONO) == 0) tuner->audmode = V4L2_TUNER_MODE_STEREO; else tuner->audmode = V4L2_TUNER_MODE_MONO; /* min is worst, max is best; signal:0..0xffff; rssi: 0..0xff */ /* measured in units of dbµV in 1 db increments (max at ~75 dbµV) */ tuner->signal = (radio->registers[STATUSRSSI] & STATUSRSSI_RSSI); /* the ideal factor is 0xffff/75 = 873,8 */ tuner->signal = (tuner->signal * 873) + (8 * tuner->signal / 10); if (tuner->signal > 0xffff) tuner->signal = 0xffff; /* automatic frequency control: -1: freq to low, 1 freq to high */ /* AFCRL does only indicate that freq. differs, not if too low/high */ tuner->afc = (radio->registers[STATUSRSSI] & STATUSRSSI_AFCRL) ? 1 : 0; return retval; } /* * si470x_vidioc_s_tuner - set tuner attributes */ static int si470x_vidioc_s_tuner(struct file *file, void *priv, const struct v4l2_tuner *tuner) { struct si470x_device *radio = video_drvdata(file); if (tuner->index != 0) return -EINVAL; /* mono/stereo selector */ switch (tuner->audmode) { case V4L2_TUNER_MODE_MONO: radio->registers[POWERCFG] |= POWERCFG_MONO; /* force mono */ break; case V4L2_TUNER_MODE_STEREO: default: radio->registers[POWERCFG] &= ~POWERCFG_MONO; /* try stereo */ break; } return si470x_set_register(radio, POWERCFG); } /* * si470x_vidioc_g_frequency - get tuner or modulator radio frequency */ static int si470x_vidioc_g_frequency(struct file *file, void *priv, struct v4l2_frequency *freq) { struct si470x_device *radio = video_drvdata(file); if (freq->tuner != 0) return -EINVAL; freq->type = V4L2_TUNER_RADIO; return si470x_get_freq(radio, &freq->frequency); } /* * si470x_vidioc_s_frequency - set tuner or modulator radio frequency */ static int si470x_vidioc_s_frequency(struct file *file, void *priv, const struct v4l2_frequency *freq) { struct si470x_device *radio = video_drvdata(file); int retval; if (freq->tuner != 0) return -EINVAL; if (freq->frequency < bands[radio->band].rangelow || freq->frequency > bands[radio->band].rangehigh) { /* Switch to band 1 which covers everything we support */ retval = si470x_set_band(radio, 1); if (retval) return retval; } return si470x_set_freq(radio, freq->frequency); } /* * si470x_vidioc_s_hw_freq_seek - set hardware frequency seek */ static int si470x_vidioc_s_hw_freq_seek(struct file *file, void *priv, const struct v4l2_hw_freq_seek *seek) { struct si470x_device *radio = video_drvdata(file); if (seek->tuner != 0) return -EINVAL; if (file->f_flags & O_NONBLOCK) return -EWOULDBLOCK; return si470x_set_seek(radio, seek); } /* * si470x_vidioc_enum_freq_bands - enumerate supported bands */ static int si470x_vidioc_enum_freq_bands(struct file *file, void *priv, struct v4l2_frequency_band *band) { if (band->tuner != 0) return -EINVAL; if (band->index >= ARRAY_SIZE(bands)) return -EINVAL; *band = bands[band->index]; return 0; } const struct v4l2_ctrl_ops si470x_ctrl_ops = { .s_ctrl = si470x_s_ctrl, }; /* * si470x_ioctl_ops - video device ioctl operations */ static const struct v4l2_ioctl_ops si470x_ioctl_ops = { .vidioc_querycap = si470x_vidioc_querycap, .vidioc_g_tuner = si470x_vidioc_g_tuner, .vidioc_s_tuner = si470x_vidioc_s_tuner, .vidioc_g_frequency = si470x_vidioc_g_frequency, .vidioc_s_frequency = si470x_vidioc_s_frequency, .vidioc_s_hw_freq_seek = si470x_vidioc_s_hw_freq_seek, .vidioc_enum_freq_bands = si470x_vidioc_enum_freq_bands, .vidioc_subscribe_event = v4l2_ctrl_subscribe_event, .vidioc_unsubscribe_event = v4l2_event_unsubscribe, }; /* * si470x_viddev_template - video device interface */ struct video_device si470x_viddev_template = { .fops = &si470x_fops, .name = DRIVER_NAME, .release = video_device_release_empty, .ioctl_ops = &si470x_ioctl_ops, };
gpl-2.0
LeonNardella/philips-pta-01
drivers/hv/vmbus_drv.c
528
24925
/* * Copyright (c) 2009, Microsoft Corporation. * * This program is free software; you can redistribute it and/or modify it * under the terms and conditions of the GNU General Public License, * version 2, as published by the Free Software Foundation. * * This program is distributed in the hope it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * more details. * * You should have received a copy of the GNU General Public License along with * this program; if not, write to the Free Software Foundation, Inc., 59 Temple * Place - Suite 330, Boston, MA 02111-1307 USA. * * Authors: * Haiyang Zhang <haiyangz@microsoft.com> * Hank Janssen <hjanssen@microsoft.com> * K. Y. Srinivasan <kys@microsoft.com> * */ #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt #include <linux/init.h> #include <linux/module.h> #include <linux/device.h> #include <linux/interrupt.h> #include <linux/sysctl.h> #include <linux/slab.h> #include <linux/acpi.h> #include <linux/completion.h> #include <linux/hyperv.h> #include <linux/kernel_stat.h> #include <asm/hyperv.h> #include <asm/hypervisor.h> #include <asm/mshyperv.h> #include "hyperv_vmbus.h" static struct acpi_device *hv_acpi_dev; static struct tasklet_struct msg_dpc; static struct completion probe_event; static int irq; struct resource hyperv_mmio = { .name = "hyperv mmio", .flags = IORESOURCE_MEM, }; EXPORT_SYMBOL_GPL(hyperv_mmio); static int vmbus_exists(void) { if (hv_acpi_dev == NULL) return -ENODEV; return 0; } #define VMBUS_ALIAS_LEN ((sizeof((struct hv_vmbus_device_id *)0)->guid) * 2) static void print_alias_name(struct hv_device *hv_dev, char *alias_name) { int i; for (i = 0; i < VMBUS_ALIAS_LEN; i += 2) sprintf(&alias_name[i], "%02x", hv_dev->dev_type.b[i/2]); } static u8 channel_monitor_group(struct vmbus_channel *channel) { return (u8)channel->offermsg.monitorid / 32; } static u8 channel_monitor_offset(struct vmbus_channel *channel) { return (u8)channel->offermsg.monitorid % 32; } static u32 channel_pending(struct vmbus_channel *channel, struct hv_monitor_page *monitor_page) { u8 monitor_group = channel_monitor_group(channel); return monitor_page->trigger_group[monitor_group].pending; } static u32 channel_latency(struct vmbus_channel *channel, struct hv_monitor_page *monitor_page) { u8 monitor_group = channel_monitor_group(channel); u8 monitor_offset = channel_monitor_offset(channel); return monitor_page->latency[monitor_group][monitor_offset]; } static u32 channel_conn_id(struct vmbus_channel *channel, struct hv_monitor_page *monitor_page) { u8 monitor_group = channel_monitor_group(channel); u8 monitor_offset = channel_monitor_offset(channel); return monitor_page->parameter[monitor_group][monitor_offset].connectionid.u.id; } static ssize_t id_show(struct device *dev, struct device_attribute *dev_attr, char *buf) { struct hv_device *hv_dev = device_to_hv_device(dev); if (!hv_dev->channel) return -ENODEV; return sprintf(buf, "%d\n", hv_dev->channel->offermsg.child_relid); } static DEVICE_ATTR_RO(id); static ssize_t state_show(struct device *dev, struct device_attribute *dev_attr, char *buf) { struct hv_device *hv_dev = device_to_hv_device(dev); if (!hv_dev->channel) return -ENODEV; return sprintf(buf, "%d\n", hv_dev->channel->state); } static DEVICE_ATTR_RO(state); static ssize_t monitor_id_show(struct device *dev, struct device_attribute *dev_attr, char *buf) { struct hv_device *hv_dev = device_to_hv_device(dev); if (!hv_dev->channel) return -ENODEV; return sprintf(buf, "%d\n", hv_dev->channel->offermsg.monitorid); } static DEVICE_ATTR_RO(monitor_id); static ssize_t class_id_show(struct device *dev, struct device_attribute *dev_attr, char *buf) { struct hv_device *hv_dev = device_to_hv_device(dev); if (!hv_dev->channel) return -ENODEV; return sprintf(buf, "{%pUl}\n", hv_dev->channel->offermsg.offer.if_type.b); } static DEVICE_ATTR_RO(class_id); static ssize_t device_id_show(struct device *dev, struct device_attribute *dev_attr, char *buf) { struct hv_device *hv_dev = device_to_hv_device(dev); if (!hv_dev->channel) return -ENODEV; return sprintf(buf, "{%pUl}\n", hv_dev->channel->offermsg.offer.if_instance.b); } static DEVICE_ATTR_RO(device_id); static ssize_t modalias_show(struct device *dev, struct device_attribute *dev_attr, char *buf) { struct hv_device *hv_dev = device_to_hv_device(dev); char alias_name[VMBUS_ALIAS_LEN + 1]; print_alias_name(hv_dev, alias_name); return sprintf(buf, "vmbus:%s\n", alias_name); } static DEVICE_ATTR_RO(modalias); static ssize_t server_monitor_pending_show(struct device *dev, struct device_attribute *dev_attr, char *buf) { struct hv_device *hv_dev = device_to_hv_device(dev); if (!hv_dev->channel) return -ENODEV; return sprintf(buf, "%d\n", channel_pending(hv_dev->channel, vmbus_connection.monitor_pages[1])); } static DEVICE_ATTR_RO(server_monitor_pending); static ssize_t client_monitor_pending_show(struct device *dev, struct device_attribute *dev_attr, char *buf) { struct hv_device *hv_dev = device_to_hv_device(dev); if (!hv_dev->channel) return -ENODEV; return sprintf(buf, "%d\n", channel_pending(hv_dev->channel, vmbus_connection.monitor_pages[1])); } static DEVICE_ATTR_RO(client_monitor_pending); static ssize_t server_monitor_latency_show(struct device *dev, struct device_attribute *dev_attr, char *buf) { struct hv_device *hv_dev = device_to_hv_device(dev); if (!hv_dev->channel) return -ENODEV; return sprintf(buf, "%d\n", channel_latency(hv_dev->channel, vmbus_connection.monitor_pages[0])); } static DEVICE_ATTR_RO(server_monitor_latency); static ssize_t client_monitor_latency_show(struct device *dev, struct device_attribute *dev_attr, char *buf) { struct hv_device *hv_dev = device_to_hv_device(dev); if (!hv_dev->channel) return -ENODEV; return sprintf(buf, "%d\n", channel_latency(hv_dev->channel, vmbus_connection.monitor_pages[1])); } static DEVICE_ATTR_RO(client_monitor_latency); static ssize_t server_monitor_conn_id_show(struct device *dev, struct device_attribute *dev_attr, char *buf) { struct hv_device *hv_dev = device_to_hv_device(dev); if (!hv_dev->channel) return -ENODEV; return sprintf(buf, "%d\n", channel_conn_id(hv_dev->channel, vmbus_connection.monitor_pages[0])); } static DEVICE_ATTR_RO(server_monitor_conn_id); static ssize_t client_monitor_conn_id_show(struct device *dev, struct device_attribute *dev_attr, char *buf) { struct hv_device *hv_dev = device_to_hv_device(dev); if (!hv_dev->channel) return -ENODEV; return sprintf(buf, "%d\n", channel_conn_id(hv_dev->channel, vmbus_connection.monitor_pages[1])); } static DEVICE_ATTR_RO(client_monitor_conn_id); static ssize_t out_intr_mask_show(struct device *dev, struct device_attribute *dev_attr, char *buf) { struct hv_device *hv_dev = device_to_hv_device(dev); struct hv_ring_buffer_debug_info outbound; if (!hv_dev->channel) return -ENODEV; hv_ringbuffer_get_debuginfo(&hv_dev->channel->outbound, &outbound); return sprintf(buf, "%d\n", outbound.current_interrupt_mask); } static DEVICE_ATTR_RO(out_intr_mask); static ssize_t out_read_index_show(struct device *dev, struct device_attribute *dev_attr, char *buf) { struct hv_device *hv_dev = device_to_hv_device(dev); struct hv_ring_buffer_debug_info outbound; if (!hv_dev->channel) return -ENODEV; hv_ringbuffer_get_debuginfo(&hv_dev->channel->outbound, &outbound); return sprintf(buf, "%d\n", outbound.current_read_index); } static DEVICE_ATTR_RO(out_read_index); static ssize_t out_write_index_show(struct device *dev, struct device_attribute *dev_attr, char *buf) { struct hv_device *hv_dev = device_to_hv_device(dev); struct hv_ring_buffer_debug_info outbound; if (!hv_dev->channel) return -ENODEV; hv_ringbuffer_get_debuginfo(&hv_dev->channel->outbound, &outbound); return sprintf(buf, "%d\n", outbound.current_write_index); } static DEVICE_ATTR_RO(out_write_index); static ssize_t out_read_bytes_avail_show(struct device *dev, struct device_attribute *dev_attr, char *buf) { struct hv_device *hv_dev = device_to_hv_device(dev); struct hv_ring_buffer_debug_info outbound; if (!hv_dev->channel) return -ENODEV; hv_ringbuffer_get_debuginfo(&hv_dev->channel->outbound, &outbound); return sprintf(buf, "%d\n", outbound.bytes_avail_toread); } static DEVICE_ATTR_RO(out_read_bytes_avail); static ssize_t out_write_bytes_avail_show(struct device *dev, struct device_attribute *dev_attr, char *buf) { struct hv_device *hv_dev = device_to_hv_device(dev); struct hv_ring_buffer_debug_info outbound; if (!hv_dev->channel) return -ENODEV; hv_ringbuffer_get_debuginfo(&hv_dev->channel->outbound, &outbound); return sprintf(buf, "%d\n", outbound.bytes_avail_towrite); } static DEVICE_ATTR_RO(out_write_bytes_avail); static ssize_t in_intr_mask_show(struct device *dev, struct device_attribute *dev_attr, char *buf) { struct hv_device *hv_dev = device_to_hv_device(dev); struct hv_ring_buffer_debug_info inbound; if (!hv_dev->channel) return -ENODEV; hv_ringbuffer_get_debuginfo(&hv_dev->channel->inbound, &inbound); return sprintf(buf, "%d\n", inbound.current_interrupt_mask); } static DEVICE_ATTR_RO(in_intr_mask); static ssize_t in_read_index_show(struct device *dev, struct device_attribute *dev_attr, char *buf) { struct hv_device *hv_dev = device_to_hv_device(dev); struct hv_ring_buffer_debug_info inbound; if (!hv_dev->channel) return -ENODEV; hv_ringbuffer_get_debuginfo(&hv_dev->channel->inbound, &inbound); return sprintf(buf, "%d\n", inbound.current_read_index); } static DEVICE_ATTR_RO(in_read_index); static ssize_t in_write_index_show(struct device *dev, struct device_attribute *dev_attr, char *buf) { struct hv_device *hv_dev = device_to_hv_device(dev); struct hv_ring_buffer_debug_info inbound; if (!hv_dev->channel) return -ENODEV; hv_ringbuffer_get_debuginfo(&hv_dev->channel->inbound, &inbound); return sprintf(buf, "%d\n", inbound.current_write_index); } static DEVICE_ATTR_RO(in_write_index); static ssize_t in_read_bytes_avail_show(struct device *dev, struct device_attribute *dev_attr, char *buf) { struct hv_device *hv_dev = device_to_hv_device(dev); struct hv_ring_buffer_debug_info inbound; if (!hv_dev->channel) return -ENODEV; hv_ringbuffer_get_debuginfo(&hv_dev->channel->inbound, &inbound); return sprintf(buf, "%d\n", inbound.bytes_avail_toread); } static DEVICE_ATTR_RO(in_read_bytes_avail); static ssize_t in_write_bytes_avail_show(struct device *dev, struct device_attribute *dev_attr, char *buf) { struct hv_device *hv_dev = device_to_hv_device(dev); struct hv_ring_buffer_debug_info inbound; if (!hv_dev->channel) return -ENODEV; hv_ringbuffer_get_debuginfo(&hv_dev->channel->inbound, &inbound); return sprintf(buf, "%d\n", inbound.bytes_avail_towrite); } static DEVICE_ATTR_RO(in_write_bytes_avail); /* Set up per device attributes in /sys/bus/vmbus/devices/<bus device> */ static struct attribute *vmbus_attrs[] = { &dev_attr_id.attr, &dev_attr_state.attr, &dev_attr_monitor_id.attr, &dev_attr_class_id.attr, &dev_attr_device_id.attr, &dev_attr_modalias.attr, &dev_attr_server_monitor_pending.attr, &dev_attr_client_monitor_pending.attr, &dev_attr_server_monitor_latency.attr, &dev_attr_client_monitor_latency.attr, &dev_attr_server_monitor_conn_id.attr, &dev_attr_client_monitor_conn_id.attr, &dev_attr_out_intr_mask.attr, &dev_attr_out_read_index.attr, &dev_attr_out_write_index.attr, &dev_attr_out_read_bytes_avail.attr, &dev_attr_out_write_bytes_avail.attr, &dev_attr_in_intr_mask.attr, &dev_attr_in_read_index.attr, &dev_attr_in_write_index.attr, &dev_attr_in_read_bytes_avail.attr, &dev_attr_in_write_bytes_avail.attr, NULL, }; ATTRIBUTE_GROUPS(vmbus); /* * vmbus_uevent - add uevent for our device * * This routine is invoked when a device is added or removed on the vmbus to * generate a uevent to udev in the userspace. The udev will then look at its * rule and the uevent generated here to load the appropriate driver * * The alias string will be of the form vmbus:guid where guid is the string * representation of the device guid (each byte of the guid will be * represented with two hex characters. */ static int vmbus_uevent(struct device *device, struct kobj_uevent_env *env) { struct hv_device *dev = device_to_hv_device(device); int ret; char alias_name[VMBUS_ALIAS_LEN + 1]; print_alias_name(dev, alias_name); ret = add_uevent_var(env, "MODALIAS=vmbus:%s", alias_name); return ret; } static const uuid_le null_guid; static inline bool is_null_guid(const __u8 *guid) { if (memcmp(guid, &null_guid, sizeof(uuid_le))) return false; return true; } /* * Return a matching hv_vmbus_device_id pointer. * If there is no match, return NULL. */ static const struct hv_vmbus_device_id *hv_vmbus_get_id( const struct hv_vmbus_device_id *id, const __u8 *guid) { for (; !is_null_guid(id->guid); id++) if (!memcmp(&id->guid, guid, sizeof(uuid_le))) return id; return NULL; } /* * vmbus_match - Attempt to match the specified device to the specified driver */ static int vmbus_match(struct device *device, struct device_driver *driver) { struct hv_driver *drv = drv_to_hv_drv(driver); struct hv_device *hv_dev = device_to_hv_device(device); if (hv_vmbus_get_id(drv->id_table, hv_dev->dev_type.b)) return 1; return 0; } /* * vmbus_probe - Add the new vmbus's child device */ static int vmbus_probe(struct device *child_device) { int ret = 0; struct hv_driver *drv = drv_to_hv_drv(child_device->driver); struct hv_device *dev = device_to_hv_device(child_device); const struct hv_vmbus_device_id *dev_id; dev_id = hv_vmbus_get_id(drv->id_table, dev->dev_type.b); if (drv->probe) { ret = drv->probe(dev, dev_id); if (ret != 0) pr_err("probe failed for device %s (%d)\n", dev_name(child_device), ret); } else { pr_err("probe not set for driver %s\n", dev_name(child_device)); ret = -ENODEV; } return ret; } /* * vmbus_remove - Remove a vmbus device */ static int vmbus_remove(struct device *child_device) { struct hv_driver *drv = drv_to_hv_drv(child_device->driver); struct hv_device *dev = device_to_hv_device(child_device); if (drv->remove) drv->remove(dev); else pr_err("remove not set for driver %s\n", dev_name(child_device)); return 0; } /* * vmbus_shutdown - Shutdown a vmbus device */ static void vmbus_shutdown(struct device *child_device) { struct hv_driver *drv; struct hv_device *dev = device_to_hv_device(child_device); /* The device may not be attached yet */ if (!child_device->driver) return; drv = drv_to_hv_drv(child_device->driver); if (drv->shutdown) drv->shutdown(dev); return; } /* * vmbus_device_release - Final callback release of the vmbus child device */ static void vmbus_device_release(struct device *device) { struct hv_device *hv_dev = device_to_hv_device(device); kfree(hv_dev); } /* The one and only one */ static struct bus_type hv_bus = { .name = "vmbus", .match = vmbus_match, .shutdown = vmbus_shutdown, .remove = vmbus_remove, .probe = vmbus_probe, .uevent = vmbus_uevent, .dev_groups = vmbus_groups, }; struct onmessage_work_context { struct work_struct work; struct hv_message msg; }; static void vmbus_onmessage_work(struct work_struct *work) { struct onmessage_work_context *ctx; ctx = container_of(work, struct onmessage_work_context, work); vmbus_onmessage(&ctx->msg); kfree(ctx); } static void vmbus_on_msg_dpc(unsigned long data) { int cpu = smp_processor_id(); void *page_addr = hv_context.synic_message_page[cpu]; struct hv_message *msg = (struct hv_message *)page_addr + VMBUS_MESSAGE_SINT; struct onmessage_work_context *ctx; while (1) { if (msg->header.message_type == HVMSG_NONE) { /* no msg */ break; } else { ctx = kmalloc(sizeof(*ctx), GFP_ATOMIC); if (ctx == NULL) continue; INIT_WORK(&ctx->work, vmbus_onmessage_work); memcpy(&ctx->msg, msg, sizeof(*msg)); queue_work(vmbus_connection.work_queue, &ctx->work); } msg->header.message_type = HVMSG_NONE; /* * Make sure the write to MessageType (ie set to * HVMSG_NONE) happens before we read the * MessagePending and EOMing. Otherwise, the EOMing * will not deliver any more messages since there is * no empty slot */ mb(); if (msg->header.message_flags.msg_pending) { /* * This will cause message queue rescan to * possibly deliver another msg from the * hypervisor */ wrmsrl(HV_X64_MSR_EOM, 0); } } } static void vmbus_isr(void) { int cpu = smp_processor_id(); void *page_addr; struct hv_message *msg; union hv_synic_event_flags *event; bool handled = false; page_addr = hv_context.synic_event_page[cpu]; if (page_addr == NULL) return; event = (union hv_synic_event_flags *)page_addr + VMBUS_MESSAGE_SINT; /* * Check for events before checking for messages. This is the order * in which events and messages are checked in Windows guests on * Hyper-V, and the Windows team suggested we do the same. */ if ((vmbus_proto_version == VERSION_WS2008) || (vmbus_proto_version == VERSION_WIN7)) { /* Since we are a child, we only need to check bit 0 */ if (sync_test_and_clear_bit(0, (unsigned long *) &event->flags32[0])) { handled = true; } } else { /* * Our host is win8 or above. The signaling mechanism * has changed and we can directly look at the event page. * If bit n is set then we have an interrup on the channel * whose id is n. */ handled = true; } if (handled) tasklet_schedule(hv_context.event_dpc[cpu]); page_addr = hv_context.synic_message_page[cpu]; msg = (struct hv_message *)page_addr + VMBUS_MESSAGE_SINT; /* Check if there are actual msgs to be processed */ if (msg->header.message_type != HVMSG_NONE) tasklet_schedule(&msg_dpc); } /* * vmbus_bus_init -Main vmbus driver initialization routine. * * Here, we * - initialize the vmbus driver context * - invoke the vmbus hv main init routine * - get the irq resource * - retrieve the channel offers */ static int vmbus_bus_init(int irq) { int ret; /* Hypervisor initialization...setup hypercall page..etc */ ret = hv_init(); if (ret != 0) { pr_err("Unable to initialize the hypervisor - 0x%x\n", ret); return ret; } tasklet_init(&msg_dpc, vmbus_on_msg_dpc, 0); ret = bus_register(&hv_bus); if (ret) goto err_cleanup; hv_setup_vmbus_irq(vmbus_isr); ret = hv_synic_alloc(); if (ret) goto err_alloc; /* * Initialize the per-cpu interrupt state and * connect to the host. */ on_each_cpu(hv_synic_init, NULL, 1); ret = vmbus_connect(); if (ret) goto err_alloc; vmbus_request_offers(); return 0; err_alloc: hv_synic_free(); hv_remove_vmbus_irq(); bus_unregister(&hv_bus); err_cleanup: hv_cleanup(); return ret; } /** * __vmbus_child_driver_register - Register a vmbus's driver * @drv: Pointer to driver structure you want to register * @owner: owner module of the drv * @mod_name: module name string * * Registers the given driver with Linux through the 'driver_register()' call * and sets up the hyper-v vmbus handling for this driver. * It will return the state of the 'driver_register()' call. * */ int __vmbus_driver_register(struct hv_driver *hv_driver, struct module *owner, const char *mod_name) { int ret; pr_info("registering driver %s\n", hv_driver->name); ret = vmbus_exists(); if (ret < 0) return ret; hv_driver->driver.name = hv_driver->name; hv_driver->driver.owner = owner; hv_driver->driver.mod_name = mod_name; hv_driver->driver.bus = &hv_bus; ret = driver_register(&hv_driver->driver); return ret; } EXPORT_SYMBOL_GPL(__vmbus_driver_register); /** * vmbus_driver_unregister() - Unregister a vmbus's driver * @drv: Pointer to driver structure you want to un-register * * Un-register the given driver that was previous registered with a call to * vmbus_driver_register() */ void vmbus_driver_unregister(struct hv_driver *hv_driver) { pr_info("unregistering driver %s\n", hv_driver->name); if (!vmbus_exists()) driver_unregister(&hv_driver->driver); } EXPORT_SYMBOL_GPL(vmbus_driver_unregister); /* * vmbus_device_create - Creates and registers a new child device * on the vmbus. */ struct hv_device *vmbus_device_create(const uuid_le *type, const uuid_le *instance, struct vmbus_channel *channel) { struct hv_device *child_device_obj; child_device_obj = kzalloc(sizeof(struct hv_device), GFP_KERNEL); if (!child_device_obj) { pr_err("Unable to allocate device object for child device\n"); return NULL; } child_device_obj->channel = channel; memcpy(&child_device_obj->dev_type, type, sizeof(uuid_le)); memcpy(&child_device_obj->dev_instance, instance, sizeof(uuid_le)); return child_device_obj; } /* * vmbus_device_register - Register the child device */ int vmbus_device_register(struct hv_device *child_device_obj) { int ret = 0; static atomic_t device_num = ATOMIC_INIT(0); dev_set_name(&child_device_obj->device, "vmbus_0_%d", atomic_inc_return(&device_num)); child_device_obj->device.bus = &hv_bus; child_device_obj->device.parent = &hv_acpi_dev->dev; child_device_obj->device.release = vmbus_device_release; /* * Register with the LDM. This will kick off the driver/device * binding...which will eventually call vmbus_match() and vmbus_probe() */ ret = device_register(&child_device_obj->device); if (ret) pr_err("Unable to register child device\n"); else pr_debug("child device %s registered\n", dev_name(&child_device_obj->device)); return ret; } /* * vmbus_device_unregister - Remove the specified child device * from the vmbus. */ void vmbus_device_unregister(struct hv_device *device_obj) { pr_debug("child device %s unregistered\n", dev_name(&device_obj->device)); /* * Kick off the process of unregistering the device. * This will call vmbus_remove() and eventually vmbus_device_release() */ device_unregister(&device_obj->device); } /* * VMBUS is an acpi enumerated device. Get the the information we * need from DSDT. */ static acpi_status vmbus_walk_resources(struct acpi_resource *res, void *ctx) { switch (res->type) { case ACPI_RESOURCE_TYPE_IRQ: irq = res->data.irq.interrupts[0]; break; case ACPI_RESOURCE_TYPE_ADDRESS64: hyperv_mmio.start = res->data.address64.minimum; hyperv_mmio.end = res->data.address64.maximum; break; } return AE_OK; } static int vmbus_acpi_add(struct acpi_device *device) { acpi_status result; int ret_val = -ENODEV; hv_acpi_dev = device; result = acpi_walk_resources(device->handle, METHOD_NAME__CRS, vmbus_walk_resources, NULL); if (ACPI_FAILURE(result)) goto acpi_walk_err; /* * The parent of the vmbus acpi device (Gen2 firmware) is the VMOD that * has the mmio ranges. Get that. */ if (device->parent) { result = acpi_walk_resources(device->parent->handle, METHOD_NAME__CRS, vmbus_walk_resources, NULL); if (ACPI_FAILURE(result)) goto acpi_walk_err; if (hyperv_mmio.start && hyperv_mmio.end) request_resource(&iomem_resource, &hyperv_mmio); } ret_val = 0; acpi_walk_err: complete(&probe_event); return ret_val; } static const struct acpi_device_id vmbus_acpi_device_ids[] = { {"VMBUS", 0}, {"VMBus", 0}, {"", 0}, }; MODULE_DEVICE_TABLE(acpi, vmbus_acpi_device_ids); static struct acpi_driver vmbus_acpi_driver = { .name = "vmbus", .ids = vmbus_acpi_device_ids, .ops = { .add = vmbus_acpi_add, }, }; static int __init hv_acpi_init(void) { int ret, t; if (x86_hyper != &x86_hyper_ms_hyperv) return -ENODEV; init_completion(&probe_event); /* * Get irq resources first. */ ret = acpi_bus_register_driver(&vmbus_acpi_driver); if (ret) return ret; t = wait_for_completion_timeout(&probe_event, 5*HZ); if (t == 0) { ret = -ETIMEDOUT; goto cleanup; } if (irq <= 0) { ret = -ENODEV; goto cleanup; } ret = vmbus_bus_init(irq); if (ret) goto cleanup; return 0; cleanup: acpi_bus_unregister_driver(&vmbus_acpi_driver); hv_acpi_dev = NULL; return ret; } static void __exit vmbus_exit(void) { hv_remove_vmbus_irq(); vmbus_free_channels(); bus_unregister(&hv_bus); hv_cleanup(); acpi_bus_unregister_driver(&vmbus_acpi_driver); } MODULE_LICENSE("GPL"); subsys_initcall(hv_acpi_init); module_exit(vmbus_exit);
gpl-2.0
explora26/kernel-hikey-linaro
drivers/net/wireless/libertas/debugfs.c
784
23201
#include <linux/dcache.h> #include <linux/debugfs.h> #include <linux/delay.h> #include <linux/hardirq.h> #include <linux/mm.h> #include <linux/string.h> #include <linux/slab.h> #include <linux/export.h> #include "decl.h" #include "cmd.h" #include "debugfs.h" static struct dentry *lbs_dir; static char *szStates[] = { "Connected", "Disconnected" }; #ifdef PROC_DEBUG static void lbs_debug_init(struct lbs_private *priv); #endif static ssize_t write_file_dummy(struct file *file, const char __user *buf, size_t count, loff_t *ppos) { return -EINVAL; } static const size_t len = PAGE_SIZE; static ssize_t lbs_dev_info(struct file *file, char __user *userbuf, size_t count, loff_t *ppos) { struct lbs_private *priv = file->private_data; size_t pos = 0; unsigned long addr = get_zeroed_page(GFP_KERNEL); char *buf = (char *)addr; ssize_t res; if (!buf) return -ENOMEM; pos += snprintf(buf+pos, len-pos, "state = %s\n", szStates[priv->connect_status]); pos += snprintf(buf+pos, len-pos, "region_code = %02x\n", (u32) priv->regioncode); res = simple_read_from_buffer(userbuf, count, ppos, buf, pos); free_page(addr); return res; } static ssize_t lbs_sleepparams_write(struct file *file, const char __user *user_buf, size_t count, loff_t *ppos) { struct lbs_private *priv = file->private_data; ssize_t buf_size, ret; struct sleep_params sp; int p1, p2, p3, p4, p5, p6; unsigned long addr = get_zeroed_page(GFP_KERNEL); char *buf = (char *)addr; if (!buf) return -ENOMEM; buf_size = min(count, len - 1); if (copy_from_user(buf, user_buf, buf_size)) { ret = -EFAULT; goto out_unlock; } ret = sscanf(buf, "%d %d %d %d %d %d", &p1, &p2, &p3, &p4, &p5, &p6); if (ret != 6) { ret = -EINVAL; goto out_unlock; } sp.sp_error = p1; sp.sp_offset = p2; sp.sp_stabletime = p3; sp.sp_calcontrol = p4; sp.sp_extsleepclk = p5; sp.sp_reserved = p6; ret = lbs_cmd_802_11_sleep_params(priv, CMD_ACT_SET, &sp); if (!ret) ret = count; else if (ret > 0) ret = -EINVAL; out_unlock: free_page(addr); return ret; } static ssize_t lbs_sleepparams_read(struct file *file, char __user *userbuf, size_t count, loff_t *ppos) { struct lbs_private *priv = file->private_data; ssize_t ret; size_t pos = 0; struct sleep_params sp; unsigned long addr = get_zeroed_page(GFP_KERNEL); char *buf = (char *)addr; if (!buf) return -ENOMEM; ret = lbs_cmd_802_11_sleep_params(priv, CMD_ACT_GET, &sp); if (ret) goto out_unlock; pos += snprintf(buf, len, "%d %d %d %d %d %d\n", sp.sp_error, sp.sp_offset, sp.sp_stabletime, sp.sp_calcontrol, sp.sp_extsleepclk, sp.sp_reserved); ret = simple_read_from_buffer(userbuf, count, ppos, buf, pos); out_unlock: free_page(addr); return ret; } static ssize_t lbs_host_sleep_write(struct file *file, const char __user *user_buf, size_t count, loff_t *ppos) { struct lbs_private *priv = file->private_data; ssize_t buf_size, ret; int host_sleep; unsigned long addr = get_zeroed_page(GFP_KERNEL); char *buf = (char *)addr; if (!buf) return -ENOMEM; buf_size = min(count, len - 1); if (copy_from_user(buf, user_buf, buf_size)) { ret = -EFAULT; goto out_unlock; } ret = sscanf(buf, "%d", &host_sleep); if (ret != 1) { ret = -EINVAL; goto out_unlock; } if (host_sleep == 0) ret = lbs_set_host_sleep(priv, 0); else if (host_sleep == 1) { if (priv->wol_criteria == EHS_REMOVE_WAKEUP) { netdev_info(priv->dev, "wake parameters not configured\n"); ret = -EINVAL; goto out_unlock; } ret = lbs_set_host_sleep(priv, 1); } else { netdev_err(priv->dev, "invalid option\n"); ret = -EINVAL; } if (!ret) ret = count; out_unlock: free_page(addr); return ret; } static ssize_t lbs_host_sleep_read(struct file *file, char __user *userbuf, size_t count, loff_t *ppos) { struct lbs_private *priv = file->private_data; ssize_t ret; size_t pos = 0; unsigned long addr = get_zeroed_page(GFP_KERNEL); char *buf = (char *)addr; if (!buf) return -ENOMEM; pos += snprintf(buf, len, "%d\n", priv->is_host_sleep_activated); ret = simple_read_from_buffer(userbuf, count, ppos, buf, pos); free_page(addr); return ret; } /* * When calling CMD_802_11_SUBSCRIBE_EVENT with CMD_ACT_GET, me might * get a bunch of vendor-specific TLVs (a.k.a. IEs) back from the * firmware. Here's an example: * 04 01 02 00 00 00 05 01 02 00 00 00 06 01 02 00 * 00 00 07 01 02 00 3c 00 00 00 00 00 00 00 03 03 * 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 * * The 04 01 is the TLV type (here TLV_TYPE_RSSI_LOW), 02 00 is the length, * 00 00 are the data bytes of this TLV. For this TLV, their meaning is * defined in mrvlietypes_thresholds * * This function searches in this TLV data chunk for a given TLV type * and returns a pointer to the first data byte of the TLV, or to NULL * if the TLV hasn't been found. */ static void *lbs_tlv_find(uint16_t tlv_type, const uint8_t *tlv, uint16_t size) { struct mrvl_ie_header *tlv_h; uint16_t length; ssize_t pos = 0; while (pos < size) { tlv_h = (struct mrvl_ie_header *) tlv; if (!tlv_h->len) return NULL; if (tlv_h->type == cpu_to_le16(tlv_type)) return tlv_h; length = le16_to_cpu(tlv_h->len) + sizeof(*tlv_h); pos += length; tlv += length; } return NULL; } static ssize_t lbs_threshold_read(uint16_t tlv_type, uint16_t event_mask, struct file *file, char __user *userbuf, size_t count, loff_t *ppos) { struct cmd_ds_802_11_subscribe_event *subscribed; struct mrvl_ie_thresholds *got; struct lbs_private *priv = file->private_data; ssize_t ret = 0; size_t pos = 0; char *buf; u8 value; u8 freq; int events = 0; buf = (char *)get_zeroed_page(GFP_KERNEL); if (!buf) return -ENOMEM; subscribed = kzalloc(sizeof(*subscribed), GFP_KERNEL); if (!subscribed) { ret = -ENOMEM; goto out_page; } subscribed->hdr.size = cpu_to_le16(sizeof(*subscribed)); subscribed->action = cpu_to_le16(CMD_ACT_GET); ret = lbs_cmd_with_response(priv, CMD_802_11_SUBSCRIBE_EVENT, subscribed); if (ret) goto out_cmd; got = lbs_tlv_find(tlv_type, subscribed->tlv, sizeof(subscribed->tlv)); if (got) { value = got->value; freq = got->freq; events = le16_to_cpu(subscribed->events); pos += snprintf(buf, len, "%d %d %d\n", value, freq, !!(events & event_mask)); } ret = simple_read_from_buffer(userbuf, count, ppos, buf, pos); out_cmd: kfree(subscribed); out_page: free_page((unsigned long)buf); return ret; } static ssize_t lbs_threshold_write(uint16_t tlv_type, uint16_t event_mask, struct file *file, const char __user *userbuf, size_t count, loff_t *ppos) { struct cmd_ds_802_11_subscribe_event *events; struct mrvl_ie_thresholds *tlv; struct lbs_private *priv = file->private_data; ssize_t buf_size; int value, freq, new_mask; uint16_t curr_mask; char *buf; int ret; buf = (char *)get_zeroed_page(GFP_KERNEL); if (!buf) return -ENOMEM; buf_size = min(count, len - 1); if (copy_from_user(buf, userbuf, buf_size)) { ret = -EFAULT; goto out_page; } ret = sscanf(buf, "%d %d %d", &value, &freq, &new_mask); if (ret != 3) { ret = -EINVAL; goto out_page; } events = kzalloc(sizeof(*events), GFP_KERNEL); if (!events) { ret = -ENOMEM; goto out_page; } events->hdr.size = cpu_to_le16(sizeof(*events)); events->action = cpu_to_le16(CMD_ACT_GET); ret = lbs_cmd_with_response(priv, CMD_802_11_SUBSCRIBE_EVENT, events); if (ret) goto out_events; curr_mask = le16_to_cpu(events->events); if (new_mask) new_mask = curr_mask | event_mask; else new_mask = curr_mask & ~event_mask; /* Now everything is set and we can send stuff down to the firmware */ tlv = (void *)events->tlv; events->action = cpu_to_le16(CMD_ACT_SET); events->events = cpu_to_le16(new_mask); tlv->header.type = cpu_to_le16(tlv_type); tlv->header.len = cpu_to_le16(sizeof(*tlv) - sizeof(tlv->header)); tlv->value = value; if (tlv_type != TLV_TYPE_BCNMISS) tlv->freq = freq; /* The command header, the action, the event mask, and one TLV */ events->hdr.size = cpu_to_le16(sizeof(events->hdr) + 4 + sizeof(*tlv)); ret = lbs_cmd_with_response(priv, CMD_802_11_SUBSCRIBE_EVENT, events); if (!ret) ret = count; out_events: kfree(events); out_page: free_page((unsigned long)buf); return ret; } static ssize_t lbs_lowrssi_read(struct file *file, char __user *userbuf, size_t count, loff_t *ppos) { return lbs_threshold_read(TLV_TYPE_RSSI_LOW, CMD_SUBSCRIBE_RSSI_LOW, file, userbuf, count, ppos); } static ssize_t lbs_lowrssi_write(struct file *file, const char __user *userbuf, size_t count, loff_t *ppos) { return lbs_threshold_write(TLV_TYPE_RSSI_LOW, CMD_SUBSCRIBE_RSSI_LOW, file, userbuf, count, ppos); } static ssize_t lbs_lowsnr_read(struct file *file, char __user *userbuf, size_t count, loff_t *ppos) { return lbs_threshold_read(TLV_TYPE_SNR_LOW, CMD_SUBSCRIBE_SNR_LOW, file, userbuf, count, ppos); } static ssize_t lbs_lowsnr_write(struct file *file, const char __user *userbuf, size_t count, loff_t *ppos) { return lbs_threshold_write(TLV_TYPE_SNR_LOW, CMD_SUBSCRIBE_SNR_LOW, file, userbuf, count, ppos); } static ssize_t lbs_failcount_read(struct file *file, char __user *userbuf, size_t count, loff_t *ppos) { return lbs_threshold_read(TLV_TYPE_FAILCOUNT, CMD_SUBSCRIBE_FAILCOUNT, file, userbuf, count, ppos); } static ssize_t lbs_failcount_write(struct file *file, const char __user *userbuf, size_t count, loff_t *ppos) { return lbs_threshold_write(TLV_TYPE_FAILCOUNT, CMD_SUBSCRIBE_FAILCOUNT, file, userbuf, count, ppos); } static ssize_t lbs_highrssi_read(struct file *file, char __user *userbuf, size_t count, loff_t *ppos) { return lbs_threshold_read(TLV_TYPE_RSSI_HIGH, CMD_SUBSCRIBE_RSSI_HIGH, file, userbuf, count, ppos); } static ssize_t lbs_highrssi_write(struct file *file, const char __user *userbuf, size_t count, loff_t *ppos) { return lbs_threshold_write(TLV_TYPE_RSSI_HIGH, CMD_SUBSCRIBE_RSSI_HIGH, file, userbuf, count, ppos); } static ssize_t lbs_highsnr_read(struct file *file, char __user *userbuf, size_t count, loff_t *ppos) { return lbs_threshold_read(TLV_TYPE_SNR_HIGH, CMD_SUBSCRIBE_SNR_HIGH, file, userbuf, count, ppos); } static ssize_t lbs_highsnr_write(struct file *file, const char __user *userbuf, size_t count, loff_t *ppos) { return lbs_threshold_write(TLV_TYPE_SNR_HIGH, CMD_SUBSCRIBE_SNR_HIGH, file, userbuf, count, ppos); } static ssize_t lbs_bcnmiss_read(struct file *file, char __user *userbuf, size_t count, loff_t *ppos) { return lbs_threshold_read(TLV_TYPE_BCNMISS, CMD_SUBSCRIBE_BCNMISS, file, userbuf, count, ppos); } static ssize_t lbs_bcnmiss_write(struct file *file, const char __user *userbuf, size_t count, loff_t *ppos) { return lbs_threshold_write(TLV_TYPE_BCNMISS, CMD_SUBSCRIBE_BCNMISS, file, userbuf, count, ppos); } static ssize_t lbs_rdmac_read(struct file *file, char __user *userbuf, size_t count, loff_t *ppos) { struct lbs_private *priv = file->private_data; ssize_t pos = 0; int ret; unsigned long addr = get_zeroed_page(GFP_KERNEL); char *buf = (char *)addr; u32 val = 0; if (!buf) return -ENOMEM; ret = lbs_get_reg(priv, CMD_MAC_REG_ACCESS, priv->mac_offset, &val); mdelay(10); if (!ret) { pos = snprintf(buf, len, "MAC[0x%x] = 0x%08x\n", priv->mac_offset, val); ret = simple_read_from_buffer(userbuf, count, ppos, buf, pos); } free_page(addr); return ret; } static ssize_t lbs_rdmac_write(struct file *file, const char __user *userbuf, size_t count, loff_t *ppos) { struct lbs_private *priv = file->private_data; ssize_t res, buf_size; unsigned long addr = get_zeroed_page(GFP_KERNEL); char *buf = (char *)addr; if (!buf) return -ENOMEM; buf_size = min(count, len - 1); if (copy_from_user(buf, userbuf, buf_size)) { res = -EFAULT; goto out_unlock; } priv->mac_offset = simple_strtoul(buf, NULL, 16); res = count; out_unlock: free_page(addr); return res; } static ssize_t lbs_wrmac_write(struct file *file, const char __user *userbuf, size_t count, loff_t *ppos) { struct lbs_private *priv = file->private_data; ssize_t res, buf_size; u32 offset, value; unsigned long addr = get_zeroed_page(GFP_KERNEL); char *buf = (char *)addr; if (!buf) return -ENOMEM; buf_size = min(count, len - 1); if (copy_from_user(buf, userbuf, buf_size)) { res = -EFAULT; goto out_unlock; } res = sscanf(buf, "%x %x", &offset, &value); if (res != 2) { res = -EFAULT; goto out_unlock; } res = lbs_set_reg(priv, CMD_MAC_REG_ACCESS, offset, value); mdelay(10); if (!res) res = count; out_unlock: free_page(addr); return res; } static ssize_t lbs_rdbbp_read(struct file *file, char __user *userbuf, size_t count, loff_t *ppos) { struct lbs_private *priv = file->private_data; ssize_t pos = 0; int ret; unsigned long addr = get_zeroed_page(GFP_KERNEL); char *buf = (char *)addr; u32 val; if (!buf) return -ENOMEM; ret = lbs_get_reg(priv, CMD_BBP_REG_ACCESS, priv->bbp_offset, &val); mdelay(10); if (!ret) { pos = snprintf(buf, len, "BBP[0x%x] = 0x%08x\n", priv->bbp_offset, val); ret = simple_read_from_buffer(userbuf, count, ppos, buf, pos); } free_page(addr); return ret; } static ssize_t lbs_rdbbp_write(struct file *file, const char __user *userbuf, size_t count, loff_t *ppos) { struct lbs_private *priv = file->private_data; ssize_t res, buf_size; unsigned long addr = get_zeroed_page(GFP_KERNEL); char *buf = (char *)addr; if (!buf) return -ENOMEM; buf_size = min(count, len - 1); if (copy_from_user(buf, userbuf, buf_size)) { res = -EFAULT; goto out_unlock; } priv->bbp_offset = simple_strtoul(buf, NULL, 16); res = count; out_unlock: free_page(addr); return res; } static ssize_t lbs_wrbbp_write(struct file *file, const char __user *userbuf, size_t count, loff_t *ppos) { struct lbs_private *priv = file->private_data; ssize_t res, buf_size; u32 offset, value; unsigned long addr = get_zeroed_page(GFP_KERNEL); char *buf = (char *)addr; if (!buf) return -ENOMEM; buf_size = min(count, len - 1); if (copy_from_user(buf, userbuf, buf_size)) { res = -EFAULT; goto out_unlock; } res = sscanf(buf, "%x %x", &offset, &value); if (res != 2) { res = -EFAULT; goto out_unlock; } res = lbs_set_reg(priv, CMD_BBP_REG_ACCESS, offset, value); mdelay(10); if (!res) res = count; out_unlock: free_page(addr); return res; } static ssize_t lbs_rdrf_read(struct file *file, char __user *userbuf, size_t count, loff_t *ppos) { struct lbs_private *priv = file->private_data; ssize_t pos = 0; int ret; unsigned long addr = get_zeroed_page(GFP_KERNEL); char *buf = (char *)addr; u32 val; if (!buf) return -ENOMEM; ret = lbs_get_reg(priv, CMD_RF_REG_ACCESS, priv->rf_offset, &val); mdelay(10); if (!ret) { pos = snprintf(buf, len, "RF[0x%x] = 0x%08x\n", priv->rf_offset, val); ret = simple_read_from_buffer(userbuf, count, ppos, buf, pos); } free_page(addr); return ret; } static ssize_t lbs_rdrf_write(struct file *file, const char __user *userbuf, size_t count, loff_t *ppos) { struct lbs_private *priv = file->private_data; ssize_t res, buf_size; unsigned long addr = get_zeroed_page(GFP_KERNEL); char *buf = (char *)addr; if (!buf) return -ENOMEM; buf_size = min(count, len - 1); if (copy_from_user(buf, userbuf, buf_size)) { res = -EFAULT; goto out_unlock; } priv->rf_offset = simple_strtoul(buf, NULL, 16); res = count; out_unlock: free_page(addr); return res; } static ssize_t lbs_wrrf_write(struct file *file, const char __user *userbuf, size_t count, loff_t *ppos) { struct lbs_private *priv = file->private_data; ssize_t res, buf_size; u32 offset, value; unsigned long addr = get_zeroed_page(GFP_KERNEL); char *buf = (char *)addr; if (!buf) return -ENOMEM; buf_size = min(count, len - 1); if (copy_from_user(buf, userbuf, buf_size)) { res = -EFAULT; goto out_unlock; } res = sscanf(buf, "%x %x", &offset, &value); if (res != 2) { res = -EFAULT; goto out_unlock; } res = lbs_set_reg(priv, CMD_RF_REG_ACCESS, offset, value); mdelay(10); if (!res) res = count; out_unlock: free_page(addr); return res; } #define FOPS(fread, fwrite) { \ .owner = THIS_MODULE, \ .open = simple_open, \ .read = (fread), \ .write = (fwrite), \ .llseek = generic_file_llseek, \ } struct lbs_debugfs_files { const char *name; umode_t perm; struct file_operations fops; }; static const struct lbs_debugfs_files debugfs_files[] = { { "info", 0444, FOPS(lbs_dev_info, write_file_dummy), }, { "sleepparams", 0644, FOPS(lbs_sleepparams_read, lbs_sleepparams_write), }, { "hostsleep", 0644, FOPS(lbs_host_sleep_read, lbs_host_sleep_write), }, }; static const struct lbs_debugfs_files debugfs_events_files[] = { {"low_rssi", 0644, FOPS(lbs_lowrssi_read, lbs_lowrssi_write), }, {"low_snr", 0644, FOPS(lbs_lowsnr_read, lbs_lowsnr_write), }, {"failure_count", 0644, FOPS(lbs_failcount_read, lbs_failcount_write), }, {"beacon_missed", 0644, FOPS(lbs_bcnmiss_read, lbs_bcnmiss_write), }, {"high_rssi", 0644, FOPS(lbs_highrssi_read, lbs_highrssi_write), }, {"high_snr", 0644, FOPS(lbs_highsnr_read, lbs_highsnr_write), }, }; static const struct lbs_debugfs_files debugfs_regs_files[] = { {"rdmac", 0644, FOPS(lbs_rdmac_read, lbs_rdmac_write), }, {"wrmac", 0600, FOPS(NULL, lbs_wrmac_write), }, {"rdbbp", 0644, FOPS(lbs_rdbbp_read, lbs_rdbbp_write), }, {"wrbbp", 0600, FOPS(NULL, lbs_wrbbp_write), }, {"rdrf", 0644, FOPS(lbs_rdrf_read, lbs_rdrf_write), }, {"wrrf", 0600, FOPS(NULL, lbs_wrrf_write), }, }; void lbs_debugfs_init(void) { if (!lbs_dir) lbs_dir = debugfs_create_dir("lbs_wireless", NULL); } void lbs_debugfs_remove(void) { debugfs_remove(lbs_dir); } void lbs_debugfs_init_one(struct lbs_private *priv, struct net_device *dev) { int i; const struct lbs_debugfs_files *files; if (!lbs_dir) goto exit; priv->debugfs_dir = debugfs_create_dir(dev->name, lbs_dir); if (!priv->debugfs_dir) goto exit; for (i=0; i<ARRAY_SIZE(debugfs_files); i++) { files = &debugfs_files[i]; priv->debugfs_files[i] = debugfs_create_file(files->name, files->perm, priv->debugfs_dir, priv, &files->fops); } priv->events_dir = debugfs_create_dir("subscribed_events", priv->debugfs_dir); if (!priv->events_dir) goto exit; for (i=0; i<ARRAY_SIZE(debugfs_events_files); i++) { files = &debugfs_events_files[i]; priv->debugfs_events_files[i] = debugfs_create_file(files->name, files->perm, priv->events_dir, priv, &files->fops); } priv->regs_dir = debugfs_create_dir("registers", priv->debugfs_dir); if (!priv->regs_dir) goto exit; for (i=0; i<ARRAY_SIZE(debugfs_regs_files); i++) { files = &debugfs_regs_files[i]; priv->debugfs_regs_files[i] = debugfs_create_file(files->name, files->perm, priv->regs_dir, priv, &files->fops); } #ifdef PROC_DEBUG lbs_debug_init(priv); #endif exit: return; } void lbs_debugfs_remove_one(struct lbs_private *priv) { int i; for(i=0; i<ARRAY_SIZE(debugfs_regs_files); i++) debugfs_remove(priv->debugfs_regs_files[i]); debugfs_remove(priv->regs_dir); for(i=0; i<ARRAY_SIZE(debugfs_events_files); i++) debugfs_remove(priv->debugfs_events_files[i]); debugfs_remove(priv->events_dir); #ifdef PROC_DEBUG debugfs_remove(priv->debugfs_debug); #endif for(i=0; i<ARRAY_SIZE(debugfs_files); i++) debugfs_remove(priv->debugfs_files[i]); debugfs_remove(priv->debugfs_dir); } /* debug entry */ #ifdef PROC_DEBUG #define item_size(n) (FIELD_SIZEOF(struct lbs_private, n)) #define item_addr(n) (offsetof(struct lbs_private, n)) struct debug_data { char name[32]; u32 size; size_t addr; }; /* To debug any member of struct lbs_private, simply add one line here. */ static struct debug_data items[] = { {"psmode", item_size(psmode), item_addr(psmode)}, {"psstate", item_size(psstate), item_addr(psstate)}, }; static int num_of_items = ARRAY_SIZE(items); /** * lbs_debugfs_read - proc read function * * @file: file to read * @userbuf: pointer to buffer * @count: number of bytes to read * @ppos: read data starting position * * returns: amount of data read or negative error code */ static ssize_t lbs_debugfs_read(struct file *file, char __user *userbuf, size_t count, loff_t *ppos) { int val = 0; size_t pos = 0; ssize_t res; char *p; int i; struct debug_data *d; unsigned long addr = get_zeroed_page(GFP_KERNEL); char *buf = (char *)addr; if (!buf) return -ENOMEM; p = buf; d = file->private_data; for (i = 0; i < num_of_items; i++) { if (d[i].size == 1) val = *((u8 *) d[i].addr); else if (d[i].size == 2) val = *((u16 *) d[i].addr); else if (d[i].size == 4) val = *((u32 *) d[i].addr); else if (d[i].size == 8) val = *((u64 *) d[i].addr); pos += sprintf(p + pos, "%s=%d\n", d[i].name, val); } res = simple_read_from_buffer(userbuf, count, ppos, p, pos); free_page(addr); return res; } /** * lbs_debugfs_write - proc write function * * @f: file pointer * @buf: pointer to data buffer * @cnt: data number to write * @ppos: file position * * returns: amount of data written */ static ssize_t lbs_debugfs_write(struct file *f, const char __user *buf, size_t cnt, loff_t *ppos) { int r, i; char *pdata; char *p; char *p0; char *p1; char *p2; struct debug_data *d = f->private_data; if (cnt == 0) return 0; pdata = kmalloc(cnt + 1, GFP_KERNEL); if (pdata == NULL) return 0; if (copy_from_user(pdata, buf, cnt)) { lbs_deb_debugfs("Copy from user failed\n"); kfree(pdata); return 0; } pdata[cnt] = '\0'; p0 = pdata; for (i = 0; i < num_of_items; i++) { do { p = strstr(p0, d[i].name); if (p == NULL) break; p1 = strchr(p, '\n'); if (p1 == NULL) break; p0 = p1++; p2 = strchr(p, '='); if (!p2) break; p2++; r = simple_strtoul(p2, NULL, 0); if (d[i].size == 1) *((u8 *) d[i].addr) = (u8) r; else if (d[i].size == 2) *((u16 *) d[i].addr) = (u16) r; else if (d[i].size == 4) *((u32 *) d[i].addr) = (u32) r; else if (d[i].size == 8) *((u64 *) d[i].addr) = (u64) r; break; } while (1); } kfree(pdata); return (ssize_t)cnt; } static const struct file_operations lbs_debug_fops = { .owner = THIS_MODULE, .open = simple_open, .write = lbs_debugfs_write, .read = lbs_debugfs_read, .llseek = default_llseek, }; /** * lbs_debug_init - create debug proc file * * @priv: pointer to &struct lbs_private * * returns: N/A */ static void lbs_debug_init(struct lbs_private *priv) { int i; if (!priv->debugfs_dir) return; for (i = 0; i < num_of_items; i++) items[i].addr += (size_t) priv; priv->debugfs_debug = debugfs_create_file("debug", 0644, priv->debugfs_dir, &items[0], &lbs_debug_fops); } #endif
gpl-2.0
CirrusLogic/rpi-linux
drivers/md/dm-linear.c
1296
3914
/* * Copyright (C) 2001-2003 Sistina Software (UK) Limited. * * This file is released under the GPL. */ #include "dm.h" #include <linux/module.h> #include <linux/init.h> #include <linux/blkdev.h> #include <linux/bio.h> #include <linux/slab.h> #include <linux/device-mapper.h> #define DM_MSG_PREFIX "linear" /* * Linear: maps a linear range of a device. */ struct linear_c { struct dm_dev *dev; sector_t start; }; /* * Construct a linear mapping: <dev_path> <offset> */ static int linear_ctr(struct dm_target *ti, unsigned int argc, char **argv) { struct linear_c *lc; unsigned long long tmp; char dummy; if (argc != 2) { ti->error = "Invalid argument count"; return -EINVAL; } lc = kmalloc(sizeof(*lc), GFP_KERNEL); if (lc == NULL) { ti->error = "dm-linear: Cannot allocate linear context"; return -ENOMEM; } if (sscanf(argv[1], "%llu%c", &tmp, &dummy) != 1) { ti->error = "dm-linear: Invalid device sector"; goto bad; } lc->start = tmp; if (dm_get_device(ti, argv[0], dm_table_get_mode(ti->table), &lc->dev)) { ti->error = "dm-linear: Device lookup failed"; goto bad; } ti->num_flush_bios = 1; ti->num_discard_bios = 1; ti->num_write_same_bios = 1; ti->private = lc; return 0; bad: kfree(lc); return -EINVAL; } static void linear_dtr(struct dm_target *ti) { struct linear_c *lc = (struct linear_c *) ti->private; dm_put_device(ti, lc->dev); kfree(lc); } static sector_t linear_map_sector(struct dm_target *ti, sector_t bi_sector) { struct linear_c *lc = ti->private; return lc->start + dm_target_offset(ti, bi_sector); } static void linear_map_bio(struct dm_target *ti, struct bio *bio) { struct linear_c *lc = ti->private; bio->bi_bdev = lc->dev->bdev; if (bio_sectors(bio)) bio->bi_iter.bi_sector = linear_map_sector(ti, bio->bi_iter.bi_sector); } static int linear_map(struct dm_target *ti, struct bio *bio) { linear_map_bio(ti, bio); return DM_MAPIO_REMAPPED; } static void linear_status(struct dm_target *ti, status_type_t type, unsigned status_flags, char *result, unsigned maxlen) { struct linear_c *lc = (struct linear_c *) ti->private; switch (type) { case STATUSTYPE_INFO: result[0] = '\0'; break; case STATUSTYPE_TABLE: snprintf(result, maxlen, "%s %llu", lc->dev->name, (unsigned long long)lc->start); break; } } static int linear_ioctl(struct dm_target *ti, unsigned int cmd, unsigned long arg) { struct linear_c *lc = (struct linear_c *) ti->private; struct dm_dev *dev = lc->dev; int r = 0; /* * Only pass ioctls through if the device sizes match exactly. */ if (lc->start || ti->len != i_size_read(dev->bdev->bd_inode) >> SECTOR_SHIFT) r = scsi_verify_blk_ioctl(NULL, cmd); return r ? : __blkdev_driver_ioctl(dev->bdev, dev->mode, cmd, arg); } static int linear_merge(struct dm_target *ti, struct bvec_merge_data *bvm, struct bio_vec *biovec, int max_size) { struct linear_c *lc = ti->private; struct request_queue *q = bdev_get_queue(lc->dev->bdev); if (!q->merge_bvec_fn) return max_size; bvm->bi_bdev = lc->dev->bdev; bvm->bi_sector = linear_map_sector(ti, bvm->bi_sector); return min(max_size, q->merge_bvec_fn(q, bvm, biovec)); } static int linear_iterate_devices(struct dm_target *ti, iterate_devices_callout_fn fn, void *data) { struct linear_c *lc = ti->private; return fn(ti, lc->dev, lc->start, ti->len, data); } static struct target_type linear_target = { .name = "linear", .version = {1, 2, 1}, .module = THIS_MODULE, .ctr = linear_ctr, .dtr = linear_dtr, .map = linear_map, .status = linear_status, .ioctl = linear_ioctl, .merge = linear_merge, .iterate_devices = linear_iterate_devices, }; int __init dm_linear_init(void) { int r = dm_register_target(&linear_target); if (r < 0) DMERR("register failed %d", r); return r; } void dm_linear_exit(void) { dm_unregister_target(&linear_target); }
gpl-2.0
KunYi/linux_samx6i
arch/arm/mach-omap2/prm2xxx_3xxx.c
1552
7068
/* * OMAP2/3 PRM module functions * * Copyright (C) 2010-2011 Texas Instruments, Inc. * Copyright (C) 2010 Nokia Corporation * Benoît Cousson * Paul Walmsley * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 as * published by the Free Software Foundation. */ #include <linux/kernel.h> #include <linux/errno.h> #include <linux/err.h> #include <linux/io.h> #include "powerdomain.h" #include "prm2xxx_3xxx.h" #include "prm-regbits-24xx.h" #include "clockdomain.h" /** * omap2_prm_is_hardreset_asserted - read the HW reset line state of * submodules contained in the hwmod module * @shift: register bit shift corresponding to the reset line to check * @part: PRM partition, ignored for OMAP2 * @prm_mod: PRM submodule base (e.g. CORE_MOD) * @offset: register offset, ignored for OMAP2 * * Returns 1 if the (sub)module hardreset line is currently asserted, * 0 if the (sub)module hardreset line is not currently asserted, or * -EINVAL if called while running on a non-OMAP2/3 chip. */ int omap2_prm_is_hardreset_asserted(u8 shift, u8 part, s16 prm_mod, u16 offset) { return omap2_prm_read_mod_bits_shift(prm_mod, OMAP2_RM_RSTCTRL, (1 << shift)); } /** * omap2_prm_assert_hardreset - assert the HW reset line of a submodule * @shift: register bit shift corresponding to the reset line to assert * @part: PRM partition, ignored for OMAP2 * @prm_mod: PRM submodule base (e.g. CORE_MOD) * @offset: register offset, ignored for OMAP2 * * Some IPs like dsp or iva contain processors that require an HW * reset line to be asserted / deasserted in order to fully enable the * IP. These modules may have multiple hard-reset lines that reset * different 'submodules' inside the IP block. This function will * place the submodule into reset. Returns 0 upon success or -EINVAL * upon an argument error. */ int omap2_prm_assert_hardreset(u8 shift, u8 part, s16 prm_mod, u16 offset) { u32 mask; mask = 1 << shift; omap2_prm_rmw_mod_reg_bits(mask, mask, prm_mod, OMAP2_RM_RSTCTRL); return 0; } /** * omap2_prm_deassert_hardreset - deassert a submodule hardreset line and wait * @prm_mod: PRM submodule base (e.g. CORE_MOD) * @rst_shift: register bit shift corresponding to the reset line to deassert * @st_shift: register bit shift for the status of the deasserted submodule * @part: PRM partition, not used for OMAP2 * @prm_mod: PRM submodule base (e.g. CORE_MOD) * @rst_offset: reset register offset, not used for OMAP2 * @st_offset: reset status register offset, not used for OMAP2 * * Some IPs like dsp or iva contain processors that require an HW * reset line to be asserted / deasserted in order to fully enable the * IP. These modules may have multiple hard-reset lines that reset * different 'submodules' inside the IP block. This function will * take the submodule out of reset and wait until the PRCM indicates * that the reset has completed before returning. Returns 0 upon success or * -EINVAL upon an argument error, -EEXIST if the submodule was already out * of reset, or -EBUSY if the submodule did not exit reset promptly. */ int omap2_prm_deassert_hardreset(u8 rst_shift, u8 st_shift, u8 part, s16 prm_mod, u16 rst_offset, u16 st_offset) { u32 rst, st; int c; rst = 1 << rst_shift; st = 1 << st_shift; /* Check the current status to avoid de-asserting the line twice */ if (omap2_prm_read_mod_bits_shift(prm_mod, OMAP2_RM_RSTCTRL, rst) == 0) return -EEXIST; /* Clear the reset status by writing 1 to the status bit */ omap2_prm_rmw_mod_reg_bits(0xffffffff, st, prm_mod, OMAP2_RM_RSTST); /* de-assert the reset control line */ omap2_prm_rmw_mod_reg_bits(rst, 0, prm_mod, OMAP2_RM_RSTCTRL); /* wait the status to be set */ omap_test_timeout(omap2_prm_read_mod_bits_shift(prm_mod, OMAP2_RM_RSTST, st), MAX_MODULE_HARDRESET_WAIT, c); return (c == MAX_MODULE_HARDRESET_WAIT) ? -EBUSY : 0; } /* Powerdomain low-level functions */ /* Common functions across OMAP2 and OMAP3 */ int omap2_pwrdm_set_mem_onst(struct powerdomain *pwrdm, u8 bank, u8 pwrst) { u32 m; m = omap2_pwrdm_get_mem_bank_onstate_mask(bank); omap2_prm_rmw_mod_reg_bits(m, (pwrst << __ffs(m)), pwrdm->prcm_offs, OMAP2_PM_PWSTCTRL); return 0; } int omap2_pwrdm_set_mem_retst(struct powerdomain *pwrdm, u8 bank, u8 pwrst) { u32 m; m = omap2_pwrdm_get_mem_bank_retst_mask(bank); omap2_prm_rmw_mod_reg_bits(m, (pwrst << __ffs(m)), pwrdm->prcm_offs, OMAP2_PM_PWSTCTRL); return 0; } int omap2_pwrdm_read_mem_pwrst(struct powerdomain *pwrdm, u8 bank) { u32 m; m = omap2_pwrdm_get_mem_bank_stst_mask(bank); return omap2_prm_read_mod_bits_shift(pwrdm->prcm_offs, OMAP2_PM_PWSTST, m); } int omap2_pwrdm_read_mem_retst(struct powerdomain *pwrdm, u8 bank) { u32 m; m = omap2_pwrdm_get_mem_bank_retst_mask(bank); return omap2_prm_read_mod_bits_shift(pwrdm->prcm_offs, OMAP2_PM_PWSTCTRL, m); } int omap2_pwrdm_set_logic_retst(struct powerdomain *pwrdm, u8 pwrst) { u32 v; v = pwrst << __ffs(OMAP_LOGICRETSTATE_MASK); omap2_prm_rmw_mod_reg_bits(OMAP_LOGICRETSTATE_MASK, v, pwrdm->prcm_offs, OMAP2_PM_PWSTCTRL); return 0; } int omap2_pwrdm_wait_transition(struct powerdomain *pwrdm) { u32 c = 0; /* * REVISIT: pwrdm_wait_transition() may be better implemented * via a callback and a periodic timer check -- how long do we expect * powerdomain transitions to take? */ /* XXX Is this udelay() value meaningful? */ while ((omap2_prm_read_mod_reg(pwrdm->prcm_offs, OMAP2_PM_PWSTST) & OMAP_INTRANSITION_MASK) && (c++ < PWRDM_TRANSITION_BAILOUT)) udelay(1); if (c > PWRDM_TRANSITION_BAILOUT) { pr_err("powerdomain: %s: waited too long to complete transition\n", pwrdm->name); return -EAGAIN; } pr_debug("powerdomain: completed transition in %d loops\n", c); return 0; } int omap2_clkdm_add_wkdep(struct clockdomain *clkdm1, struct clockdomain *clkdm2) { omap2_prm_set_mod_reg_bits((1 << clkdm2->dep_bit), clkdm1->pwrdm.ptr->prcm_offs, PM_WKDEP); return 0; } int omap2_clkdm_del_wkdep(struct clockdomain *clkdm1, struct clockdomain *clkdm2) { omap2_prm_clear_mod_reg_bits((1 << clkdm2->dep_bit), clkdm1->pwrdm.ptr->prcm_offs, PM_WKDEP); return 0; } int omap2_clkdm_read_wkdep(struct clockdomain *clkdm1, struct clockdomain *clkdm2) { return omap2_prm_read_mod_bits_shift(clkdm1->pwrdm.ptr->prcm_offs, PM_WKDEP, (1 << clkdm2->dep_bit)); } /* XXX Caller must hold the clkdm's powerdomain lock */ int omap2_clkdm_clear_all_wkdeps(struct clockdomain *clkdm) { struct clkdm_dep *cd; u32 mask = 0; for (cd = clkdm->wkdep_srcs; cd && cd->clkdm_name; cd++) { if (!cd->clkdm) continue; /* only happens if data is erroneous */ /* PRM accesses are slow, so minimize them */ mask |= 1 << cd->clkdm->dep_bit; cd->wkdep_usecount = 0; } omap2_prm_clear_mod_reg_bits(mask, clkdm->pwrdm.ptr->prcm_offs, PM_WKDEP); return 0; }
gpl-2.0
Dearms/android_kernel_xiaomi_dior
drivers/platform/msm/ipa/ipa_rm.c
2064
12430
/* Copyright (c) 2013, The Linux Foundation. All rights reserved. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 and * only version 2 as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. */ #include <linux/slab.h> #include <linux/workqueue.h> #include <mach/ipa.h> #include "ipa_i.h" #include "ipa_rm_dependency_graph.h" #include "ipa_rm_i.h" #include "ipa_rm_resource.h" struct ipa_rm_context_type { struct ipa_rm_dep_graph *dep_graph; struct workqueue_struct *ipa_rm_wq; rwlock_t lock; }; static struct ipa_rm_context_type *ipa_rm_ctx; /** * ipa_rm_create_resource() - create resource * @create_params: [in] parameters needed * for resource initialization * * Returns: 0 on success, negative on failure * * This function is called by IPA RM client to initialize client's resources. * This API should be called before any other IPA RM API * on given resource name. * */ int ipa_rm_create_resource(struct ipa_rm_create_params *create_params) { struct ipa_rm_resource *resource; int result; if (!create_params) return -EINVAL; write_lock(&ipa_rm_ctx->lock); if (ipa_rm_dep_graph_get_resource(ipa_rm_ctx->dep_graph, create_params->name, &resource) == 0) { result = -EEXIST; goto bail; } result = ipa_rm_resource_create(create_params, &resource); if (result) goto bail; result = ipa_rm_dep_graph_add(ipa_rm_ctx->dep_graph, resource); if (result) ipa_rm_resource_delete(resource); bail: write_unlock(&ipa_rm_ctx->lock); return result; } EXPORT_SYMBOL(ipa_rm_create_resource); /** * ipa_rm_delete_resource() - delete resource * @resource_name: name of resource to be deleted * * Returns: 0 on success, negative on failure * * This function is called by IPA RM client to delete client's resources. * */ int ipa_rm_delete_resource(enum ipa_rm_resource_name resource_name) { struct ipa_rm_resource *resource; int result; IPADBG("IPA RM ::ipa_rm_delete_resource num[%d] ENTER\n", resource_name); write_lock(&ipa_rm_ctx->lock); if (ipa_rm_dep_graph_get_resource(ipa_rm_ctx->dep_graph, resource_name, &resource) != 0) { IPADBG("ipa_rm_delete_resource param are bad********\n"); result = -EINVAL; goto bail; } result = ipa_rm_resource_delete(resource); if (result) { IPADBG("error in ipa_rm_resource_delete\n"); goto bail; } result = ipa_rm_dep_graph_remove(ipa_rm_ctx->dep_graph, resource_name); IPADBG("IPA RM ::ipa_rm_delete_resource [%d] SUCCESS\n", resource_name); bail: write_unlock(&ipa_rm_ctx->lock); return result; } EXPORT_SYMBOL(ipa_rm_delete_resource); /** * ipa_rm_add_dependency() - create dependency * between 2 resources * @resource_name: name of dependent resource * @depends_on_name: name of its dependency * * Returns: 0 on success, negative on failure * * Side effects: IPA_RM_RESORCE_GRANTED could be generated * in case client registered with IPA RM */ int ipa_rm_add_dependency(enum ipa_rm_resource_name resource_name, enum ipa_rm_resource_name depends_on_name) { int result; write_lock(&ipa_rm_ctx->lock); result = ipa_rm_dep_graph_add_dependency( ipa_rm_ctx->dep_graph, resource_name, depends_on_name); write_unlock(&ipa_rm_ctx->lock); return result; } EXPORT_SYMBOL(ipa_rm_add_dependency); /** * ipa_rm_delete_dependency() - create dependency * between 2 resources * @resource_name: name of dependent resource * @depends_on_name: name of its dependency * * Returns: 0 on success, negative on failure * * Side effects: IPA_RM_RESORCE_GRANTED could be generated * in case client registered with IPA RM */ int ipa_rm_delete_dependency(enum ipa_rm_resource_name resource_name, enum ipa_rm_resource_name depends_on_name) { int result; write_lock(&ipa_rm_ctx->lock); result = ipa_rm_dep_graph_delete_dependency( ipa_rm_ctx->dep_graph, resource_name, depends_on_name); write_unlock(&ipa_rm_ctx->lock); return result; } EXPORT_SYMBOL(ipa_rm_delete_dependency); /** * ipa_rm_request_resource() - request resource * @resource_name: [in] name of the requested resource * * Returns: 0 on success, negative on failure * * All registered callbacks are called with IPA_RM_RESOURCE_GRANTED * on successful completion of this operation. */ int ipa_rm_request_resource(enum ipa_rm_resource_name resource_name) { struct ipa_rm_resource *resource; int result; IPADBG("IPA RM ::ipa_rm_request_resource ENTER\n"); if (!IPA_RM_RESORCE_IS_PROD(resource_name)) return -EINVAL; read_lock(&ipa_rm_ctx->lock); if (ipa_rm_dep_graph_get_resource(ipa_rm_ctx->dep_graph, resource_name, &resource) != 0) { result = -EPERM; goto bail; } result = ipa_rm_resource_producer_request( (struct ipa_rm_resource_prod *)resource); bail: IPADBG("IPA RM ::ipa_rm_request_resource EXIT [%d]\n", result); read_unlock(&ipa_rm_ctx->lock); return result; } EXPORT_SYMBOL(ipa_rm_request_resource); /** * ipa_rm_release_resource() - release resource * @resource_name: [in] name of the requested resource * * Returns: 0 on success, negative on failure * * All registered callbacks are called with IPA_RM_RESOURCE_RELEASED * on successful completion of this operation. */ int ipa_rm_release_resource(enum ipa_rm_resource_name resource_name) { struct ipa_rm_resource *resource; int result; IPADBG("IPA RM ::ipa_rm_release_resource ENTER\n"); if (!IPA_RM_RESORCE_IS_PROD(resource_name)) return -EINVAL; read_lock(&ipa_rm_ctx->lock); if (ipa_rm_dep_graph_get_resource(ipa_rm_ctx->dep_graph, resource_name, &resource) != 0) { result = -EPERM; goto bail; } result = ipa_rm_resource_producer_release( (struct ipa_rm_resource_prod *)resource); bail: IPADBG("IPA RM ::ipa_rm_release_resource EXIT [%d]\n", result); read_unlock(&ipa_rm_ctx->lock); return result; } EXPORT_SYMBOL(ipa_rm_release_resource); /** * ipa_rm_register() - register for event * @resource_name: resource name * @reg_params: [in] registration parameters * * Returns: 0 on success, negative on failure * * Registration parameters provided here should be the same * as provided later in ipa_rm_deregister() call. */ int ipa_rm_register(enum ipa_rm_resource_name resource_name, struct ipa_rm_register_params *reg_params) { int result; struct ipa_rm_resource *resource; if (!IPA_RM_RESORCE_IS_PROD(resource_name)) return -EINVAL; read_lock(&ipa_rm_ctx->lock); if (ipa_rm_dep_graph_get_resource(ipa_rm_ctx->dep_graph, resource_name, &resource) != 0) { result = -EPERM; goto bail; } result = ipa_rm_resource_producer_register( (struct ipa_rm_resource_prod *)resource, reg_params, true); bail: read_unlock(&ipa_rm_ctx->lock); return result; } EXPORT_SYMBOL(ipa_rm_register); /** * ipa_rm_deregister() - cancel the registration * @resource_name: resource name * @reg_params: [in] registration parameters * * Returns: 0 on success, negative on failure * * Registration parameters provided here should be the same * as provided in ipa_rm_register() call. */ int ipa_rm_deregister(enum ipa_rm_resource_name resource_name, struct ipa_rm_register_params *reg_params) { int result; struct ipa_rm_resource *resource; if (!IPA_RM_RESORCE_IS_PROD(resource_name)) return -EINVAL; read_lock(&ipa_rm_ctx->lock); if (ipa_rm_dep_graph_get_resource(ipa_rm_ctx->dep_graph, resource_name, &resource) != 0) { result = -EPERM; goto bail; } result = ipa_rm_resource_producer_deregister( (struct ipa_rm_resource_prod *)resource, reg_params); bail: read_unlock(&ipa_rm_ctx->lock); return result; } EXPORT_SYMBOL(ipa_rm_deregister); /** * ipa_rm_notify_completion() - * consumer driver notification for * request_resource / release_resource operations * completion * @event: notified event * @resource_name: resource name * * Returns: 0 on success, negative on failure */ int ipa_rm_notify_completion(enum ipa_rm_event event, enum ipa_rm_resource_name resource_name) { int result; if (!IPA_RM_RESORCE_IS_CONS(resource_name)) { result = -EINVAL; goto bail; } ipa_rm_wq_send_cmd(IPA_RM_WQ_RESOURCE_CB, resource_name, event, false); result = 0; bail: return result; } EXPORT_SYMBOL(ipa_rm_notify_completion); static void ipa_rm_wq_handler(struct work_struct *work) { struct ipa_rm_resource *resource; struct ipa_rm_wq_work_type *ipa_rm_work = container_of(work, struct ipa_rm_wq_work_type, work); switch (ipa_rm_work->wq_cmd) { case IPA_RM_WQ_NOTIFY_PROD: if (!IPA_RM_RESORCE_IS_PROD(ipa_rm_work->resource_name)) return; read_lock(&ipa_rm_ctx->lock); if (ipa_rm_dep_graph_get_resource(ipa_rm_ctx->dep_graph, ipa_rm_work->resource_name, &resource) != 0){ read_unlock(&ipa_rm_ctx->lock); return; } ipa_rm_resource_producer_notify_clients( (struct ipa_rm_resource_prod *)resource, ipa_rm_work->event, ipa_rm_work->notify_registered_only); read_unlock(&ipa_rm_ctx->lock); break; case IPA_RM_WQ_NOTIFY_CONS: break; case IPA_RM_WQ_RESOURCE_CB: read_lock(&ipa_rm_ctx->lock); if (ipa_rm_dep_graph_get_resource(ipa_rm_ctx->dep_graph, ipa_rm_work->resource_name, &resource) != 0){ read_unlock(&ipa_rm_ctx->lock); return; } ipa_rm_resource_consumer_handle_cb( (struct ipa_rm_resource_cons *)resource, ipa_rm_work->event); read_unlock(&ipa_rm_ctx->lock); break; default: break; } kfree((void *) work); } /** * ipa_rm_wq_send_cmd() - send a command for deferred work * @wq_cmd: command that should be executed * @resource_name: resource on which command should be executed * @notify_registered_only: notify only clients registered by * ipa_rm_register() * * Returns: 0 on success, negative otherwise */ int ipa_rm_wq_send_cmd(enum ipa_rm_wq_cmd wq_cmd, enum ipa_rm_resource_name resource_name, enum ipa_rm_event event, bool notify_registered_only) { int result = -ENOMEM; struct ipa_rm_wq_work_type *work = kzalloc(sizeof(*work), GFP_KERNEL); if (work) { INIT_WORK((struct work_struct *)work, ipa_rm_wq_handler); work->wq_cmd = wq_cmd; work->resource_name = resource_name; work->event = event; work->notify_registered_only = notify_registered_only; result = queue_work(ipa_rm_ctx->ipa_rm_wq, (struct work_struct *)work); } return result; } /** * ipa_rm_initialize() - initialize IPA RM component * * Returns: 0 on success, negative otherwise */ int ipa_rm_initialize(void) { int result; ipa_rm_ctx = kzalloc(sizeof(*ipa_rm_ctx), GFP_KERNEL); if (!ipa_rm_ctx) { result = -ENOMEM; goto bail; } ipa_rm_ctx->ipa_rm_wq = create_singlethread_workqueue("ipa_rm_wq"); if (!ipa_rm_ctx->ipa_rm_wq) { result = -ENOMEM; goto create_wq_fail; } result = ipa_rm_dep_graph_create(&(ipa_rm_ctx->dep_graph)); if (result) goto graph_alloc_fail; rwlock_init(&ipa_rm_ctx->lock); IPADBG("IPA RM ipa_rm_initialize SUCCESS\n"); return 0; graph_alloc_fail: destroy_workqueue(ipa_rm_ctx->ipa_rm_wq); create_wq_fail: kfree(ipa_rm_ctx); bail: return result; } /** * ipa_rm_stat() - print RM stat * @buf: [in] The user buff used to print * @size: [in] The size of buf * Returns: number of bytes used on success, negative on failure * * This function is called by ipa_debugfs in order to receive * a full picture of the current state of the RM */ int ipa_rm_stat(char *buf, int size) { int i, cnt = 0, result = EINVAL; struct ipa_rm_resource *resource = NULL; if (!buf || size < 0) goto bail; read_lock(&ipa_rm_ctx->lock); for (i = 0; i < IPA_RM_RESOURCE_PROD_MAX; ++i) { result = ipa_rm_dep_graph_get_resource( ipa_rm_ctx->dep_graph, i, &resource); if (!result) { result = ipa_rm_resource_producer_print_stat( resource, buf + cnt, size-cnt); if (result < 0) goto bail; cnt += result; } } result = cnt; bail: read_unlock(&ipa_rm_ctx->lock); return result; } /** * ipa_rm_exit() - free all IPA RM resources */ void ipa_rm_exit(void) { ipa_rm_dep_graph_delete(ipa_rm_ctx->dep_graph); destroy_workqueue(ipa_rm_ctx->ipa_rm_wq); kfree(ipa_rm_ctx); ipa_rm_ctx = NULL; }
gpl-2.0
faux123/samsung_GS2
arch/m68k/platform/68360/config.c
3088
4720
/* * linux/arch/m68knommu/platform/68360/config.c * * Copyright (c) 2000 Michael Leslie <mleslie@lineo.com> * Copyright (C) 1993 Hamish Macdonald * Copyright (C) 1999 D. Jeff Dionne <jeff@uclinux.org> * * This file is subject to the terms and conditions of the GNU General Public * License. See the file COPYING in the main directory of this archive * for more details. */ #include <stdarg.h> #include <linux/types.h> #include <linux/kernel.h> #include <linux/mm.h> #include <linux/interrupt.h> #include <linux/irq.h> #include <asm/setup.h> #include <asm/system.h> #include <asm/pgtable.h> #include <asm/machdep.h> #include <asm/m68360.h> #ifdef CONFIG_UCQUICC #include <asm/bootstd.h> #endif extern void m360_cpm_reset(void); // Mask to select if the PLL prescaler is enabled. #define MCU_PREEN ((unsigned short)(0x0001 << 13)) #if defined(CONFIG_UCQUICC) #define OSCILLATOR (unsigned long int)33000000 #endif unsigned long int system_clock; extern QUICC *pquicc; /* TODO DON"T Hard Code this */ /* calculate properly using the right PLL and prescaller */ // unsigned int system_clock = 33000000l; extern unsigned long int system_clock; //In kernel setup.c static irqreturn_t hw_tick(int irq, void *dummy) { /* Reset Timer1 */ /* TSTAT &= 0; */ pquicc->timer_ter1 = 0x0002; /* clear timer event */ return arch_timer_interrupt(irq, dummy); } static struct irqaction m68360_timer_irq = { .name = "timer", .flags = IRQF_DISABLED | IRQF_TIMER, .handler = hw_tick, }; void hw_timer_init(void) { unsigned char prescaler; unsigned short tgcr_save; #if 0 /* Restart mode, Enable int, 32KHz, Enable timer */ TCTL = TCTL_OM | TCTL_IRQEN | TCTL_CLKSOURCE_32KHZ | TCTL_TEN; /* Set prescaler (Divide 32KHz by 32)*/ TPRER = 31; /* Set compare register 32Khz / 32 / 10 = 100 */ TCMP = 10; request_irq(IRQ_MACHSPEC | 1, timer_routine, 0, "timer", NULL); #endif /* General purpose quicc timers: MC68360UM p7-20 */ /* Set up timer 1 (in [1..4]) to do 100Hz */ tgcr_save = pquicc->timer_tgcr & 0xfff0; pquicc->timer_tgcr = tgcr_save; /* stop and reset timer 1 */ /* pquicc->timer_tgcr |= 0x4444; */ /* halt timers when FREEZE (ie bdm freeze) */ prescaler = 8; pquicc->timer_tmr1 = 0x001a | /* or=1, frr=1, iclk=01b */ (unsigned short)((prescaler - 1) << 8); pquicc->timer_tcn1 = 0x0000; /* initial count */ /* calculate interval for 100Hz based on the _system_clock: */ pquicc->timer_trr1 = (system_clock/ prescaler) / HZ; /* reference count */ pquicc->timer_ter1 = 0x0003; /* clear timer events */ /* enable timer 1 interrupt in CIMR */ setup_irq(CPMVEC_TIMER1, &m68360_timer_irq); /* Start timer 1: */ tgcr_save = (pquicc->timer_tgcr & 0xfff0) | 0x0001; pquicc->timer_tgcr = tgcr_save; } void BSP_gettod (int *yearp, int *monp, int *dayp, int *hourp, int *minp, int *secp) { } int BSP_set_clock_mmss(unsigned long nowtime) { #if 0 short real_seconds = nowtime % 60, real_minutes = (nowtime / 60) % 60; tod->second1 = real_seconds / 10; tod->second2 = real_seconds % 10; tod->minute1 = real_minutes / 10; tod->minute2 = real_minutes % 10; #endif return 0; } void BSP_reset (void) { local_irq_disable(); asm volatile ( "moveal #_start, %a0;\n" "moveb #0, 0xFFFFF300;\n" "moveal 0(%a0), %sp;\n" "moveal 4(%a0), %a0;\n" "jmp (%a0);\n" ); } unsigned char *scc1_hwaddr; static int errno; #if defined (CONFIG_UCQUICC) _bsc0(char *, getserialnum) _bsc1(unsigned char *, gethwaddr, int, a) _bsc1(char *, getbenv, char *, a) #endif void config_BSP(char *command, int len) { unsigned char *p; m360_cpm_reset(); /* Calculate the real system clock value. */ { unsigned int local_pllcr = (unsigned int)(pquicc->sim_pllcr); if( local_pllcr & MCU_PREEN ) // If the prescaler is dividing by 128 { int mf = (int)(pquicc->sim_pllcr & 0x0fff); system_clock = (OSCILLATOR / 128) * (mf + 1); } else { int mf = (int)(pquicc->sim_pllcr & 0x0fff); system_clock = (OSCILLATOR) * (mf + 1); } } printk(KERN_INFO "\n68360 QUICC support (C) 2000 Lineo Inc.\n"); #if defined(CONFIG_UCQUICC) && 0 printk(KERN_INFO "uCquicc serial string [%s]\n",getserialnum()); p = scc1_hwaddr = gethwaddr(0); printk(KERN_INFO "uCquicc hwaddr %.2x:%.2x:%.2x:%.2x:%.2x:%.2x\n", p[0], p[1], p[2], p[3], p[4], p[5]); p = getbenv("APPEND"); if (p) strcpy(p,command); else command[0] = 0; #else scc1_hwaddr = "\00\01\02\03\04\05"; #endif mach_gettod = BSP_gettod; mach_reset = BSP_reset; }
gpl-2.0
armpc/Armcore-a20-V12-kernel
fs/ocfs2/xattr.c
3600
198470
/* -*- mode: c; c-basic-offset: 8; -*- * vim: noexpandtab sw=8 ts=8 sts=0: * * xattr.c * * Copyright (C) 2004, 2008 Oracle. All rights reserved. * * CREDITS: * Lots of code in this file is copy from linux/fs/ext3/xattr.c. * Copyright (C) 2001-2003 Andreas Gruenbacher, <agruen@suse.de> * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public * License version 2 as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. */ #include <linux/capability.h> #include <linux/fs.h> #include <linux/types.h> #include <linux/slab.h> #include <linux/highmem.h> #include <linux/pagemap.h> #include <linux/uio.h> #include <linux/sched.h> #include <linux/splice.h> #include <linux/mount.h> #include <linux/writeback.h> #include <linux/falloc.h> #include <linux/sort.h> #include <linux/init.h> #include <linux/module.h> #include <linux/string.h> #include <linux/security.h> #include <cluster/masklog.h> #include "ocfs2.h" #include "alloc.h" #include "blockcheck.h" #include "dlmglue.h" #include "file.h" #include "symlink.h" #include "sysfile.h" #include "inode.h" #include "journal.h" #include "ocfs2_fs.h" #include "suballoc.h" #include "uptodate.h" #include "buffer_head_io.h" #include "super.h" #include "xattr.h" #include "refcounttree.h" #include "acl.h" #include "ocfs2_trace.h" struct ocfs2_xattr_def_value_root { struct ocfs2_xattr_value_root xv; struct ocfs2_extent_rec er; }; struct ocfs2_xattr_bucket { /* The inode these xattrs are associated with */ struct inode *bu_inode; /* The actual buffers that make up the bucket */ struct buffer_head *bu_bhs[OCFS2_XATTR_MAX_BLOCKS_PER_BUCKET]; /* How many blocks make up one bucket for this filesystem */ int bu_blocks; }; struct ocfs2_xattr_set_ctxt { handle_t *handle; struct ocfs2_alloc_context *meta_ac; struct ocfs2_alloc_context *data_ac; struct ocfs2_cached_dealloc_ctxt dealloc; int set_abort; }; #define OCFS2_XATTR_ROOT_SIZE (sizeof(struct ocfs2_xattr_def_value_root)) #define OCFS2_XATTR_INLINE_SIZE 80 #define OCFS2_XATTR_HEADER_GAP 4 #define OCFS2_XATTR_FREE_IN_IBODY (OCFS2_MIN_XATTR_INLINE_SIZE \ - sizeof(struct ocfs2_xattr_header) \ - OCFS2_XATTR_HEADER_GAP) #define OCFS2_XATTR_FREE_IN_BLOCK(ptr) ((ptr)->i_sb->s_blocksize \ - sizeof(struct ocfs2_xattr_block) \ - sizeof(struct ocfs2_xattr_header) \ - OCFS2_XATTR_HEADER_GAP) static struct ocfs2_xattr_def_value_root def_xv = { .xv.xr_list.l_count = cpu_to_le16(1), }; const struct xattr_handler *ocfs2_xattr_handlers[] = { &ocfs2_xattr_user_handler, &ocfs2_xattr_acl_access_handler, &ocfs2_xattr_acl_default_handler, &ocfs2_xattr_trusted_handler, &ocfs2_xattr_security_handler, NULL }; static const struct xattr_handler *ocfs2_xattr_handler_map[OCFS2_XATTR_MAX] = { [OCFS2_XATTR_INDEX_USER] = &ocfs2_xattr_user_handler, [OCFS2_XATTR_INDEX_POSIX_ACL_ACCESS] = &ocfs2_xattr_acl_access_handler, [OCFS2_XATTR_INDEX_POSIX_ACL_DEFAULT] = &ocfs2_xattr_acl_default_handler, [OCFS2_XATTR_INDEX_TRUSTED] = &ocfs2_xattr_trusted_handler, [OCFS2_XATTR_INDEX_SECURITY] = &ocfs2_xattr_security_handler, }; struct ocfs2_xattr_info { int xi_name_index; const char *xi_name; int xi_name_len; const void *xi_value; size_t xi_value_len; }; struct ocfs2_xattr_search { struct buffer_head *inode_bh; /* * xattr_bh point to the block buffer head which has extended attribute * when extended attribute in inode, xattr_bh is equal to inode_bh. */ struct buffer_head *xattr_bh; struct ocfs2_xattr_header *header; struct ocfs2_xattr_bucket *bucket; void *base; void *end; struct ocfs2_xattr_entry *here; int not_found; }; /* Operations on struct ocfs2_xa_entry */ struct ocfs2_xa_loc; struct ocfs2_xa_loc_operations { /* * Journal functions */ int (*xlo_journal_access)(handle_t *handle, struct ocfs2_xa_loc *loc, int type); void (*xlo_journal_dirty)(handle_t *handle, struct ocfs2_xa_loc *loc); /* * Return a pointer to the appropriate buffer in loc->xl_storage * at the given offset from loc->xl_header. */ void *(*xlo_offset_pointer)(struct ocfs2_xa_loc *loc, int offset); /* Can we reuse the existing entry for the new value? */ int (*xlo_can_reuse)(struct ocfs2_xa_loc *loc, struct ocfs2_xattr_info *xi); /* How much space is needed for the new value? */ int (*xlo_check_space)(struct ocfs2_xa_loc *loc, struct ocfs2_xattr_info *xi); /* * Return the offset of the first name+value pair. This is * the start of our downward-filling free space. */ int (*xlo_get_free_start)(struct ocfs2_xa_loc *loc); /* * Remove the name+value at this location. Do whatever is * appropriate with the remaining name+value pairs. */ void (*xlo_wipe_namevalue)(struct ocfs2_xa_loc *loc); /* Fill xl_entry with a new entry */ void (*xlo_add_entry)(struct ocfs2_xa_loc *loc, u32 name_hash); /* Add name+value storage to an entry */ void (*xlo_add_namevalue)(struct ocfs2_xa_loc *loc, int size); /* * Initialize the value buf's access and bh fields for this entry. * ocfs2_xa_fill_value_buf() will handle the xv pointer. */ void (*xlo_fill_value_buf)(struct ocfs2_xa_loc *loc, struct ocfs2_xattr_value_buf *vb); }; /* * Describes an xattr entry location. This is a memory structure * tracking the on-disk structure. */ struct ocfs2_xa_loc { /* This xattr belongs to this inode */ struct inode *xl_inode; /* The ocfs2_xattr_header inside the on-disk storage. Not NULL. */ struct ocfs2_xattr_header *xl_header; /* Bytes from xl_header to the end of the storage */ int xl_size; /* * The ocfs2_xattr_entry this location describes. If this is * NULL, this location describes the on-disk structure where it * would have been. */ struct ocfs2_xattr_entry *xl_entry; /* * Internal housekeeping */ /* Buffer(s) containing this entry */ void *xl_storage; /* Operations on the storage backing this location */ const struct ocfs2_xa_loc_operations *xl_ops; }; /* * Convenience functions to calculate how much space is needed for a * given name+value pair */ static int namevalue_size(int name_len, uint64_t value_len) { if (value_len > OCFS2_XATTR_INLINE_SIZE) return OCFS2_XATTR_SIZE(name_len) + OCFS2_XATTR_ROOT_SIZE; else return OCFS2_XATTR_SIZE(name_len) + OCFS2_XATTR_SIZE(value_len); } static int namevalue_size_xi(struct ocfs2_xattr_info *xi) { return namevalue_size(xi->xi_name_len, xi->xi_value_len); } static int namevalue_size_xe(struct ocfs2_xattr_entry *xe) { u64 value_len = le64_to_cpu(xe->xe_value_size); BUG_ON((value_len > OCFS2_XATTR_INLINE_SIZE) && ocfs2_xattr_is_local(xe)); return namevalue_size(xe->xe_name_len, value_len); } static int ocfs2_xattr_bucket_get_name_value(struct super_block *sb, struct ocfs2_xattr_header *xh, int index, int *block_off, int *new_offset); static int ocfs2_xattr_block_find(struct inode *inode, int name_index, const char *name, struct ocfs2_xattr_search *xs); static int ocfs2_xattr_index_block_find(struct inode *inode, struct buffer_head *root_bh, int name_index, const char *name, struct ocfs2_xattr_search *xs); static int ocfs2_xattr_tree_list_index_block(struct inode *inode, struct buffer_head *blk_bh, char *buffer, size_t buffer_size); static int ocfs2_xattr_create_index_block(struct inode *inode, struct ocfs2_xattr_search *xs, struct ocfs2_xattr_set_ctxt *ctxt); static int ocfs2_xattr_set_entry_index_block(struct inode *inode, struct ocfs2_xattr_info *xi, struct ocfs2_xattr_search *xs, struct ocfs2_xattr_set_ctxt *ctxt); typedef int (xattr_tree_rec_func)(struct inode *inode, struct buffer_head *root_bh, u64 blkno, u32 cpos, u32 len, void *para); static int ocfs2_iterate_xattr_index_block(struct inode *inode, struct buffer_head *root_bh, xattr_tree_rec_func *rec_func, void *para); static int ocfs2_delete_xattr_in_bucket(struct inode *inode, struct ocfs2_xattr_bucket *bucket, void *para); static int ocfs2_rm_xattr_cluster(struct inode *inode, struct buffer_head *root_bh, u64 blkno, u32 cpos, u32 len, void *para); static int ocfs2_mv_xattr_buckets(struct inode *inode, handle_t *handle, u64 src_blk, u64 last_blk, u64 to_blk, unsigned int start_bucket, u32 *first_hash); static int ocfs2_prepare_refcount_xattr(struct inode *inode, struct ocfs2_dinode *di, struct ocfs2_xattr_info *xi, struct ocfs2_xattr_search *xis, struct ocfs2_xattr_search *xbs, struct ocfs2_refcount_tree **ref_tree, int *meta_need, int *credits); static int ocfs2_get_xattr_tree_value_root(struct super_block *sb, struct ocfs2_xattr_bucket *bucket, int offset, struct ocfs2_xattr_value_root **xv, struct buffer_head **bh); static inline u16 ocfs2_xattr_buckets_per_cluster(struct ocfs2_super *osb) { return (1 << osb->s_clustersize_bits) / OCFS2_XATTR_BUCKET_SIZE; } static inline u16 ocfs2_blocks_per_xattr_bucket(struct super_block *sb) { return OCFS2_XATTR_BUCKET_SIZE / (1 << sb->s_blocksize_bits); } #define bucket_blkno(_b) ((_b)->bu_bhs[0]->b_blocknr) #define bucket_block(_b, _n) ((_b)->bu_bhs[(_n)]->b_data) #define bucket_xh(_b) ((struct ocfs2_xattr_header *)bucket_block((_b), 0)) static struct ocfs2_xattr_bucket *ocfs2_xattr_bucket_new(struct inode *inode) { struct ocfs2_xattr_bucket *bucket; int blks = ocfs2_blocks_per_xattr_bucket(inode->i_sb); BUG_ON(blks > OCFS2_XATTR_MAX_BLOCKS_PER_BUCKET); bucket = kzalloc(sizeof(struct ocfs2_xattr_bucket), GFP_NOFS); if (bucket) { bucket->bu_inode = inode; bucket->bu_blocks = blks; } return bucket; } static void ocfs2_xattr_bucket_relse(struct ocfs2_xattr_bucket *bucket) { int i; for (i = 0; i < bucket->bu_blocks; i++) { brelse(bucket->bu_bhs[i]); bucket->bu_bhs[i] = NULL; } } static void ocfs2_xattr_bucket_free(struct ocfs2_xattr_bucket *bucket) { if (bucket) { ocfs2_xattr_bucket_relse(bucket); bucket->bu_inode = NULL; kfree(bucket); } } /* * A bucket that has never been written to disk doesn't need to be * read. We just need the buffer_heads. Don't call this for * buckets that are already on disk. ocfs2_read_xattr_bucket() initializes * them fully. */ static int ocfs2_init_xattr_bucket(struct ocfs2_xattr_bucket *bucket, u64 xb_blkno) { int i, rc = 0; for (i = 0; i < bucket->bu_blocks; i++) { bucket->bu_bhs[i] = sb_getblk(bucket->bu_inode->i_sb, xb_blkno + i); if (!bucket->bu_bhs[i]) { rc = -EIO; mlog_errno(rc); break; } if (!ocfs2_buffer_uptodate(INODE_CACHE(bucket->bu_inode), bucket->bu_bhs[i])) ocfs2_set_new_buffer_uptodate(INODE_CACHE(bucket->bu_inode), bucket->bu_bhs[i]); } if (rc) ocfs2_xattr_bucket_relse(bucket); return rc; } /* Read the xattr bucket at xb_blkno */ static int ocfs2_read_xattr_bucket(struct ocfs2_xattr_bucket *bucket, u64 xb_blkno) { int rc; rc = ocfs2_read_blocks(INODE_CACHE(bucket->bu_inode), xb_blkno, bucket->bu_blocks, bucket->bu_bhs, 0, NULL); if (!rc) { spin_lock(&OCFS2_SB(bucket->bu_inode->i_sb)->osb_xattr_lock); rc = ocfs2_validate_meta_ecc_bhs(bucket->bu_inode->i_sb, bucket->bu_bhs, bucket->bu_blocks, &bucket_xh(bucket)->xh_check); spin_unlock(&OCFS2_SB(bucket->bu_inode->i_sb)->osb_xattr_lock); if (rc) mlog_errno(rc); } if (rc) ocfs2_xattr_bucket_relse(bucket); return rc; } static int ocfs2_xattr_bucket_journal_access(handle_t *handle, struct ocfs2_xattr_bucket *bucket, int type) { int i, rc = 0; for (i = 0; i < bucket->bu_blocks; i++) { rc = ocfs2_journal_access(handle, INODE_CACHE(bucket->bu_inode), bucket->bu_bhs[i], type); if (rc) { mlog_errno(rc); break; } } return rc; } static void ocfs2_xattr_bucket_journal_dirty(handle_t *handle, struct ocfs2_xattr_bucket *bucket) { int i; spin_lock(&OCFS2_SB(bucket->bu_inode->i_sb)->osb_xattr_lock); ocfs2_compute_meta_ecc_bhs(bucket->bu_inode->i_sb, bucket->bu_bhs, bucket->bu_blocks, &bucket_xh(bucket)->xh_check); spin_unlock(&OCFS2_SB(bucket->bu_inode->i_sb)->osb_xattr_lock); for (i = 0; i < bucket->bu_blocks; i++) ocfs2_journal_dirty(handle, bucket->bu_bhs[i]); } static void ocfs2_xattr_bucket_copy_data(struct ocfs2_xattr_bucket *dest, struct ocfs2_xattr_bucket *src) { int i; int blocksize = src->bu_inode->i_sb->s_blocksize; BUG_ON(dest->bu_blocks != src->bu_blocks); BUG_ON(dest->bu_inode != src->bu_inode); for (i = 0; i < src->bu_blocks; i++) { memcpy(bucket_block(dest, i), bucket_block(src, i), blocksize); } } static int ocfs2_validate_xattr_block(struct super_block *sb, struct buffer_head *bh) { int rc; struct ocfs2_xattr_block *xb = (struct ocfs2_xattr_block *)bh->b_data; trace_ocfs2_validate_xattr_block((unsigned long long)bh->b_blocknr); BUG_ON(!buffer_uptodate(bh)); /* * If the ecc fails, we return the error but otherwise * leave the filesystem running. We know any error is * local to this block. */ rc = ocfs2_validate_meta_ecc(sb, bh->b_data, &xb->xb_check); if (rc) return rc; /* * Errors after here are fatal */ if (!OCFS2_IS_VALID_XATTR_BLOCK(xb)) { ocfs2_error(sb, "Extended attribute block #%llu has bad " "signature %.*s", (unsigned long long)bh->b_blocknr, 7, xb->xb_signature); return -EINVAL; } if (le64_to_cpu(xb->xb_blkno) != bh->b_blocknr) { ocfs2_error(sb, "Extended attribute block #%llu has an " "invalid xb_blkno of %llu", (unsigned long long)bh->b_blocknr, (unsigned long long)le64_to_cpu(xb->xb_blkno)); return -EINVAL; } if (le32_to_cpu(xb->xb_fs_generation) != OCFS2_SB(sb)->fs_generation) { ocfs2_error(sb, "Extended attribute block #%llu has an invalid " "xb_fs_generation of #%u", (unsigned long long)bh->b_blocknr, le32_to_cpu(xb->xb_fs_generation)); return -EINVAL; } return 0; } static int ocfs2_read_xattr_block(struct inode *inode, u64 xb_blkno, struct buffer_head **bh) { int rc; struct buffer_head *tmp = *bh; rc = ocfs2_read_block(INODE_CACHE(inode), xb_blkno, &tmp, ocfs2_validate_xattr_block); /* If ocfs2_read_block() got us a new bh, pass it up. */ if (!rc && !*bh) *bh = tmp; return rc; } static inline const char *ocfs2_xattr_prefix(int name_index) { const struct xattr_handler *handler = NULL; if (name_index > 0 && name_index < OCFS2_XATTR_MAX) handler = ocfs2_xattr_handler_map[name_index]; return handler ? handler->prefix : NULL; } static u32 ocfs2_xattr_name_hash(struct inode *inode, const char *name, int name_len) { /* Get hash value of uuid from super block */ u32 hash = OCFS2_SB(inode->i_sb)->uuid_hash; int i; /* hash extended attribute name */ for (i = 0; i < name_len; i++) { hash = (hash << OCFS2_HASH_SHIFT) ^ (hash >> (8*sizeof(hash) - OCFS2_HASH_SHIFT)) ^ *name++; } return hash; } static int ocfs2_xattr_entry_real_size(int name_len, size_t value_len) { return namevalue_size(name_len, value_len) + sizeof(struct ocfs2_xattr_entry); } static int ocfs2_xi_entry_usage(struct ocfs2_xattr_info *xi) { return namevalue_size_xi(xi) + sizeof(struct ocfs2_xattr_entry); } static int ocfs2_xe_entry_usage(struct ocfs2_xattr_entry *xe) { return namevalue_size_xe(xe) + sizeof(struct ocfs2_xattr_entry); } int ocfs2_calc_security_init(struct inode *dir, struct ocfs2_security_xattr_info *si, int *want_clusters, int *xattr_credits, struct ocfs2_alloc_context **xattr_ac) { int ret = 0; struct ocfs2_super *osb = OCFS2_SB(dir->i_sb); int s_size = ocfs2_xattr_entry_real_size(strlen(si->name), si->value_len); /* * The max space of security xattr taken inline is * 256(name) + 80(value) + 16(entry) = 352 bytes, * So reserve one metadata block for it is ok. */ if (dir->i_sb->s_blocksize == OCFS2_MIN_BLOCKSIZE || s_size > OCFS2_XATTR_FREE_IN_IBODY) { ret = ocfs2_reserve_new_metadata_blocks(osb, 1, xattr_ac); if (ret) { mlog_errno(ret); return ret; } *xattr_credits += OCFS2_XATTR_BLOCK_CREATE_CREDITS; } /* reserve clusters for xattr value which will be set in B tree*/ if (si->value_len > OCFS2_XATTR_INLINE_SIZE) { int new_clusters = ocfs2_clusters_for_bytes(dir->i_sb, si->value_len); *xattr_credits += ocfs2_clusters_to_blocks(dir->i_sb, new_clusters); *want_clusters += new_clusters; } return ret; } int ocfs2_calc_xattr_init(struct inode *dir, struct buffer_head *dir_bh, umode_t mode, struct ocfs2_security_xattr_info *si, int *want_clusters, int *xattr_credits, int *want_meta) { int ret = 0; struct ocfs2_super *osb = OCFS2_SB(dir->i_sb); int s_size = 0, a_size = 0, acl_len = 0, new_clusters; if (si->enable) s_size = ocfs2_xattr_entry_real_size(strlen(si->name), si->value_len); if (osb->s_mount_opt & OCFS2_MOUNT_POSIX_ACL) { acl_len = ocfs2_xattr_get_nolock(dir, dir_bh, OCFS2_XATTR_INDEX_POSIX_ACL_DEFAULT, "", NULL, 0); if (acl_len > 0) { a_size = ocfs2_xattr_entry_real_size(0, acl_len); if (S_ISDIR(mode)) a_size <<= 1; } else if (acl_len != 0 && acl_len != -ENODATA) { mlog_errno(ret); return ret; } } if (!(s_size + a_size)) return ret; /* * The max space of security xattr taken inline is * 256(name) + 80(value) + 16(entry) = 352 bytes, * The max space of acl xattr taken inline is * 80(value) + 16(entry) * 2(if directory) = 192 bytes, * when blocksize = 512, may reserve one more cluser for * xattr bucket, otherwise reserve one metadata block * for them is ok. * If this is a new directory with inline data, * we choose to reserve the entire inline area for * directory contents and force an external xattr block. */ if (dir->i_sb->s_blocksize == OCFS2_MIN_BLOCKSIZE || (S_ISDIR(mode) && ocfs2_supports_inline_data(osb)) || (s_size + a_size) > OCFS2_XATTR_FREE_IN_IBODY) { *want_meta = *want_meta + 1; *xattr_credits += OCFS2_XATTR_BLOCK_CREATE_CREDITS; } if (dir->i_sb->s_blocksize == OCFS2_MIN_BLOCKSIZE && (s_size + a_size) > OCFS2_XATTR_FREE_IN_BLOCK(dir)) { *want_clusters += 1; *xattr_credits += ocfs2_blocks_per_xattr_bucket(dir->i_sb); } /* * reserve credits and clusters for xattrs which has large value * and have to be set outside */ if (si->enable && si->value_len > OCFS2_XATTR_INLINE_SIZE) { new_clusters = ocfs2_clusters_for_bytes(dir->i_sb, si->value_len); *xattr_credits += ocfs2_clusters_to_blocks(dir->i_sb, new_clusters); *want_clusters += new_clusters; } if (osb->s_mount_opt & OCFS2_MOUNT_POSIX_ACL && acl_len > OCFS2_XATTR_INLINE_SIZE) { /* for directory, it has DEFAULT and ACCESS two types of acls */ new_clusters = (S_ISDIR(mode) ? 2 : 1) * ocfs2_clusters_for_bytes(dir->i_sb, acl_len); *xattr_credits += ocfs2_clusters_to_blocks(dir->i_sb, new_clusters); *want_clusters += new_clusters; } return ret; } static int ocfs2_xattr_extend_allocation(struct inode *inode, u32 clusters_to_add, struct ocfs2_xattr_value_buf *vb, struct ocfs2_xattr_set_ctxt *ctxt) { int status = 0, credits; handle_t *handle = ctxt->handle; enum ocfs2_alloc_restarted why; u32 prev_clusters, logical_start = le32_to_cpu(vb->vb_xv->xr_clusters); struct ocfs2_extent_tree et; ocfs2_init_xattr_value_extent_tree(&et, INODE_CACHE(inode), vb); while (clusters_to_add) { trace_ocfs2_xattr_extend_allocation(clusters_to_add); status = vb->vb_access(handle, INODE_CACHE(inode), vb->vb_bh, OCFS2_JOURNAL_ACCESS_WRITE); if (status < 0) { mlog_errno(status); break; } prev_clusters = le32_to_cpu(vb->vb_xv->xr_clusters); status = ocfs2_add_clusters_in_btree(handle, &et, &logical_start, clusters_to_add, 0, ctxt->data_ac, ctxt->meta_ac, &why); if ((status < 0) && (status != -EAGAIN)) { if (status != -ENOSPC) mlog_errno(status); break; } ocfs2_journal_dirty(handle, vb->vb_bh); clusters_to_add -= le32_to_cpu(vb->vb_xv->xr_clusters) - prev_clusters; if (why != RESTART_NONE && clusters_to_add) { /* * We can only fail in case the alloc file doesn't give * up enough clusters. */ BUG_ON(why == RESTART_META); credits = ocfs2_calc_extend_credits(inode->i_sb, &vb->vb_xv->xr_list, clusters_to_add); status = ocfs2_extend_trans(handle, credits); if (status < 0) { status = -ENOMEM; mlog_errno(status); break; } } } return status; } static int __ocfs2_remove_xattr_range(struct inode *inode, struct ocfs2_xattr_value_buf *vb, u32 cpos, u32 phys_cpos, u32 len, unsigned int ext_flags, struct ocfs2_xattr_set_ctxt *ctxt) { int ret; u64 phys_blkno = ocfs2_clusters_to_blocks(inode->i_sb, phys_cpos); handle_t *handle = ctxt->handle; struct ocfs2_extent_tree et; ocfs2_init_xattr_value_extent_tree(&et, INODE_CACHE(inode), vb); ret = vb->vb_access(handle, INODE_CACHE(inode), vb->vb_bh, OCFS2_JOURNAL_ACCESS_WRITE); if (ret) { mlog_errno(ret); goto out; } ret = ocfs2_remove_extent(handle, &et, cpos, len, ctxt->meta_ac, &ctxt->dealloc); if (ret) { mlog_errno(ret); goto out; } le32_add_cpu(&vb->vb_xv->xr_clusters, -len); ocfs2_journal_dirty(handle, vb->vb_bh); if (ext_flags & OCFS2_EXT_REFCOUNTED) ret = ocfs2_decrease_refcount(inode, handle, ocfs2_blocks_to_clusters(inode->i_sb, phys_blkno), len, ctxt->meta_ac, &ctxt->dealloc, 1); else ret = ocfs2_cache_cluster_dealloc(&ctxt->dealloc, phys_blkno, len); if (ret) mlog_errno(ret); out: return ret; } static int ocfs2_xattr_shrink_size(struct inode *inode, u32 old_clusters, u32 new_clusters, struct ocfs2_xattr_value_buf *vb, struct ocfs2_xattr_set_ctxt *ctxt) { int ret = 0; unsigned int ext_flags; u32 trunc_len, cpos, phys_cpos, alloc_size; u64 block; if (old_clusters <= new_clusters) return 0; cpos = new_clusters; trunc_len = old_clusters - new_clusters; while (trunc_len) { ret = ocfs2_xattr_get_clusters(inode, cpos, &phys_cpos, &alloc_size, &vb->vb_xv->xr_list, &ext_flags); if (ret) { mlog_errno(ret); goto out; } if (alloc_size > trunc_len) alloc_size = trunc_len; ret = __ocfs2_remove_xattr_range(inode, vb, cpos, phys_cpos, alloc_size, ext_flags, ctxt); if (ret) { mlog_errno(ret); goto out; } block = ocfs2_clusters_to_blocks(inode->i_sb, phys_cpos); ocfs2_remove_xattr_clusters_from_cache(INODE_CACHE(inode), block, alloc_size); cpos += alloc_size; trunc_len -= alloc_size; } out: return ret; } static int ocfs2_xattr_value_truncate(struct inode *inode, struct ocfs2_xattr_value_buf *vb, int len, struct ocfs2_xattr_set_ctxt *ctxt) { int ret; u32 new_clusters = ocfs2_clusters_for_bytes(inode->i_sb, len); u32 old_clusters = le32_to_cpu(vb->vb_xv->xr_clusters); if (new_clusters == old_clusters) return 0; if (new_clusters > old_clusters) ret = ocfs2_xattr_extend_allocation(inode, new_clusters - old_clusters, vb, ctxt); else ret = ocfs2_xattr_shrink_size(inode, old_clusters, new_clusters, vb, ctxt); return ret; } static int ocfs2_xattr_list_entry(char *buffer, size_t size, size_t *result, const char *prefix, const char *name, int name_len) { char *p = buffer + *result; int prefix_len = strlen(prefix); int total_len = prefix_len + name_len + 1; *result += total_len; /* we are just looking for how big our buffer needs to be */ if (!size) return 0; if (*result > size) return -ERANGE; memcpy(p, prefix, prefix_len); memcpy(p + prefix_len, name, name_len); p[prefix_len + name_len] = '\0'; return 0; } static int ocfs2_xattr_list_entries(struct inode *inode, struct ocfs2_xattr_header *header, char *buffer, size_t buffer_size) { size_t result = 0; int i, type, ret; const char *prefix, *name; for (i = 0 ; i < le16_to_cpu(header->xh_count); i++) { struct ocfs2_xattr_entry *entry = &header->xh_entries[i]; type = ocfs2_xattr_get_type(entry); prefix = ocfs2_xattr_prefix(type); if (prefix) { name = (const char *)header + le16_to_cpu(entry->xe_name_offset); ret = ocfs2_xattr_list_entry(buffer, buffer_size, &result, prefix, name, entry->xe_name_len); if (ret) return ret; } } return result; } int ocfs2_has_inline_xattr_value_outside(struct inode *inode, struct ocfs2_dinode *di) { struct ocfs2_xattr_header *xh; int i; xh = (struct ocfs2_xattr_header *) ((void *)di + inode->i_sb->s_blocksize - le16_to_cpu(di->i_xattr_inline_size)); for (i = 0; i < le16_to_cpu(xh->xh_count); i++) if (!ocfs2_xattr_is_local(&xh->xh_entries[i])) return 1; return 0; } static int ocfs2_xattr_ibody_list(struct inode *inode, struct ocfs2_dinode *di, char *buffer, size_t buffer_size) { struct ocfs2_xattr_header *header = NULL; struct ocfs2_inode_info *oi = OCFS2_I(inode); int ret = 0; if (!(oi->ip_dyn_features & OCFS2_INLINE_XATTR_FL)) return ret; header = (struct ocfs2_xattr_header *) ((void *)di + inode->i_sb->s_blocksize - le16_to_cpu(di->i_xattr_inline_size)); ret = ocfs2_xattr_list_entries(inode, header, buffer, buffer_size); return ret; } static int ocfs2_xattr_block_list(struct inode *inode, struct ocfs2_dinode *di, char *buffer, size_t buffer_size) { struct buffer_head *blk_bh = NULL; struct ocfs2_xattr_block *xb; int ret = 0; if (!di->i_xattr_loc) return ret; ret = ocfs2_read_xattr_block(inode, le64_to_cpu(di->i_xattr_loc), &blk_bh); if (ret < 0) { mlog_errno(ret); return ret; } xb = (struct ocfs2_xattr_block *)blk_bh->b_data; if (!(le16_to_cpu(xb->xb_flags) & OCFS2_XATTR_INDEXED)) { struct ocfs2_xattr_header *header = &xb->xb_attrs.xb_header; ret = ocfs2_xattr_list_entries(inode, header, buffer, buffer_size); } else ret = ocfs2_xattr_tree_list_index_block(inode, blk_bh, buffer, buffer_size); brelse(blk_bh); return ret; } ssize_t ocfs2_listxattr(struct dentry *dentry, char *buffer, size_t size) { int ret = 0, i_ret = 0, b_ret = 0; struct buffer_head *di_bh = NULL; struct ocfs2_dinode *di = NULL; struct ocfs2_inode_info *oi = OCFS2_I(dentry->d_inode); if (!ocfs2_supports_xattr(OCFS2_SB(dentry->d_sb))) return -EOPNOTSUPP; if (!(oi->ip_dyn_features & OCFS2_HAS_XATTR_FL)) return ret; ret = ocfs2_inode_lock(dentry->d_inode, &di_bh, 0); if (ret < 0) { mlog_errno(ret); return ret; } di = (struct ocfs2_dinode *)di_bh->b_data; down_read(&oi->ip_xattr_sem); i_ret = ocfs2_xattr_ibody_list(dentry->d_inode, di, buffer, size); if (i_ret < 0) b_ret = 0; else { if (buffer) { buffer += i_ret; size -= i_ret; } b_ret = ocfs2_xattr_block_list(dentry->d_inode, di, buffer, size); if (b_ret < 0) i_ret = 0; } up_read(&oi->ip_xattr_sem); ocfs2_inode_unlock(dentry->d_inode, 0); brelse(di_bh); return i_ret + b_ret; } static int ocfs2_xattr_find_entry(int name_index, const char *name, struct ocfs2_xattr_search *xs) { struct ocfs2_xattr_entry *entry; size_t name_len; int i, cmp = 1; if (name == NULL) return -EINVAL; name_len = strlen(name); entry = xs->here; for (i = 0; i < le16_to_cpu(xs->header->xh_count); i++) { cmp = name_index - ocfs2_xattr_get_type(entry); if (!cmp) cmp = name_len - entry->xe_name_len; if (!cmp) cmp = memcmp(name, (xs->base + le16_to_cpu(entry->xe_name_offset)), name_len); if (cmp == 0) break; entry += 1; } xs->here = entry; return cmp ? -ENODATA : 0; } static int ocfs2_xattr_get_value_outside(struct inode *inode, struct ocfs2_xattr_value_root *xv, void *buffer, size_t len) { u32 cpos, p_cluster, num_clusters, bpc, clusters; u64 blkno; int i, ret = 0; size_t cplen, blocksize; struct buffer_head *bh = NULL; struct ocfs2_extent_list *el; el = &xv->xr_list; clusters = le32_to_cpu(xv->xr_clusters); bpc = ocfs2_clusters_to_blocks(inode->i_sb, 1); blocksize = inode->i_sb->s_blocksize; cpos = 0; while (cpos < clusters) { ret = ocfs2_xattr_get_clusters(inode, cpos, &p_cluster, &num_clusters, el, NULL); if (ret) { mlog_errno(ret); goto out; } blkno = ocfs2_clusters_to_blocks(inode->i_sb, p_cluster); /* Copy ocfs2_xattr_value */ for (i = 0; i < num_clusters * bpc; i++, blkno++) { ret = ocfs2_read_block(INODE_CACHE(inode), blkno, &bh, NULL); if (ret) { mlog_errno(ret); goto out; } cplen = len >= blocksize ? blocksize : len; memcpy(buffer, bh->b_data, cplen); len -= cplen; buffer += cplen; brelse(bh); bh = NULL; if (len == 0) break; } cpos += num_clusters; } out: return ret; } static int ocfs2_xattr_ibody_get(struct inode *inode, int name_index, const char *name, void *buffer, size_t buffer_size, struct ocfs2_xattr_search *xs) { struct ocfs2_inode_info *oi = OCFS2_I(inode); struct ocfs2_dinode *di = (struct ocfs2_dinode *)xs->inode_bh->b_data; struct ocfs2_xattr_value_root *xv; size_t size; int ret = 0; if (!(oi->ip_dyn_features & OCFS2_INLINE_XATTR_FL)) return -ENODATA; xs->end = (void *)di + inode->i_sb->s_blocksize; xs->header = (struct ocfs2_xattr_header *) (xs->end - le16_to_cpu(di->i_xattr_inline_size)); xs->base = (void *)xs->header; xs->here = xs->header->xh_entries; ret = ocfs2_xattr_find_entry(name_index, name, xs); if (ret) return ret; size = le64_to_cpu(xs->here->xe_value_size); if (buffer) { if (size > buffer_size) return -ERANGE; if (ocfs2_xattr_is_local(xs->here)) { memcpy(buffer, (void *)xs->base + le16_to_cpu(xs->here->xe_name_offset) + OCFS2_XATTR_SIZE(xs->here->xe_name_len), size); } else { xv = (struct ocfs2_xattr_value_root *) (xs->base + le16_to_cpu( xs->here->xe_name_offset) + OCFS2_XATTR_SIZE(xs->here->xe_name_len)); ret = ocfs2_xattr_get_value_outside(inode, xv, buffer, size); if (ret < 0) { mlog_errno(ret); return ret; } } } return size; } static int ocfs2_xattr_block_get(struct inode *inode, int name_index, const char *name, void *buffer, size_t buffer_size, struct ocfs2_xattr_search *xs) { struct ocfs2_xattr_block *xb; struct ocfs2_xattr_value_root *xv; size_t size; int ret = -ENODATA, name_offset, name_len, i; int uninitialized_var(block_off); xs->bucket = ocfs2_xattr_bucket_new(inode); if (!xs->bucket) { ret = -ENOMEM; mlog_errno(ret); goto cleanup; } ret = ocfs2_xattr_block_find(inode, name_index, name, xs); if (ret) { mlog_errno(ret); goto cleanup; } if (xs->not_found) { ret = -ENODATA; goto cleanup; } xb = (struct ocfs2_xattr_block *)xs->xattr_bh->b_data; size = le64_to_cpu(xs->here->xe_value_size); if (buffer) { ret = -ERANGE; if (size > buffer_size) goto cleanup; name_offset = le16_to_cpu(xs->here->xe_name_offset); name_len = OCFS2_XATTR_SIZE(xs->here->xe_name_len); i = xs->here - xs->header->xh_entries; if (le16_to_cpu(xb->xb_flags) & OCFS2_XATTR_INDEXED) { ret = ocfs2_xattr_bucket_get_name_value(inode->i_sb, bucket_xh(xs->bucket), i, &block_off, &name_offset); xs->base = bucket_block(xs->bucket, block_off); } if (ocfs2_xattr_is_local(xs->here)) { memcpy(buffer, (void *)xs->base + name_offset + name_len, size); } else { xv = (struct ocfs2_xattr_value_root *) (xs->base + name_offset + name_len); ret = ocfs2_xattr_get_value_outside(inode, xv, buffer, size); if (ret < 0) { mlog_errno(ret); goto cleanup; } } } ret = size; cleanup: ocfs2_xattr_bucket_free(xs->bucket); brelse(xs->xattr_bh); xs->xattr_bh = NULL; return ret; } int ocfs2_xattr_get_nolock(struct inode *inode, struct buffer_head *di_bh, int name_index, const char *name, void *buffer, size_t buffer_size) { int ret; struct ocfs2_dinode *di = NULL; struct ocfs2_inode_info *oi = OCFS2_I(inode); struct ocfs2_xattr_search xis = { .not_found = -ENODATA, }; struct ocfs2_xattr_search xbs = { .not_found = -ENODATA, }; if (!ocfs2_supports_xattr(OCFS2_SB(inode->i_sb))) return -EOPNOTSUPP; if (!(oi->ip_dyn_features & OCFS2_HAS_XATTR_FL)) ret = -ENODATA; xis.inode_bh = xbs.inode_bh = di_bh; di = (struct ocfs2_dinode *)di_bh->b_data; ret = ocfs2_xattr_ibody_get(inode, name_index, name, buffer, buffer_size, &xis); if (ret == -ENODATA && di->i_xattr_loc) ret = ocfs2_xattr_block_get(inode, name_index, name, buffer, buffer_size, &xbs); return ret; } /* ocfs2_xattr_get() * * Copy an extended attribute into the buffer provided. * Buffer is NULL to compute the size of buffer required. */ static int ocfs2_xattr_get(struct inode *inode, int name_index, const char *name, void *buffer, size_t buffer_size) { int ret; struct buffer_head *di_bh = NULL; ret = ocfs2_inode_lock(inode, &di_bh, 0); if (ret < 0) { mlog_errno(ret); return ret; } down_read(&OCFS2_I(inode)->ip_xattr_sem); ret = ocfs2_xattr_get_nolock(inode, di_bh, name_index, name, buffer, buffer_size); up_read(&OCFS2_I(inode)->ip_xattr_sem); ocfs2_inode_unlock(inode, 0); brelse(di_bh); return ret; } static int __ocfs2_xattr_set_value_outside(struct inode *inode, handle_t *handle, struct ocfs2_xattr_value_buf *vb, const void *value, int value_len) { int ret = 0, i, cp_len; u16 blocksize = inode->i_sb->s_blocksize; u32 p_cluster, num_clusters; u32 cpos = 0, bpc = ocfs2_clusters_to_blocks(inode->i_sb, 1); u32 clusters = ocfs2_clusters_for_bytes(inode->i_sb, value_len); u64 blkno; struct buffer_head *bh = NULL; unsigned int ext_flags; struct ocfs2_xattr_value_root *xv = vb->vb_xv; BUG_ON(clusters > le32_to_cpu(xv->xr_clusters)); while (cpos < clusters) { ret = ocfs2_xattr_get_clusters(inode, cpos, &p_cluster, &num_clusters, &xv->xr_list, &ext_flags); if (ret) { mlog_errno(ret); goto out; } BUG_ON(ext_flags & OCFS2_EXT_REFCOUNTED); blkno = ocfs2_clusters_to_blocks(inode->i_sb, p_cluster); for (i = 0; i < num_clusters * bpc; i++, blkno++) { ret = ocfs2_read_block(INODE_CACHE(inode), blkno, &bh, NULL); if (ret) { mlog_errno(ret); goto out; } ret = ocfs2_journal_access(handle, INODE_CACHE(inode), bh, OCFS2_JOURNAL_ACCESS_WRITE); if (ret < 0) { mlog_errno(ret); goto out; } cp_len = value_len > blocksize ? blocksize : value_len; memcpy(bh->b_data, value, cp_len); value_len -= cp_len; value += cp_len; if (cp_len < blocksize) memset(bh->b_data + cp_len, 0, blocksize - cp_len); ocfs2_journal_dirty(handle, bh); brelse(bh); bh = NULL; /* * XXX: do we need to empty all the following * blocks in this cluster? */ if (!value_len) break; } cpos += num_clusters; } out: brelse(bh); return ret; } static int ocfs2_xa_check_space_helper(int needed_space, int free_start, int num_entries) { int free_space; if (!needed_space) return 0; free_space = free_start - sizeof(struct ocfs2_xattr_header) - (num_entries * sizeof(struct ocfs2_xattr_entry)) - OCFS2_XATTR_HEADER_GAP; if (free_space < 0) return -EIO; if (free_space < needed_space) return -ENOSPC; return 0; } static int ocfs2_xa_journal_access(handle_t *handle, struct ocfs2_xa_loc *loc, int type) { return loc->xl_ops->xlo_journal_access(handle, loc, type); } static void ocfs2_xa_journal_dirty(handle_t *handle, struct ocfs2_xa_loc *loc) { loc->xl_ops->xlo_journal_dirty(handle, loc); } /* Give a pointer into the storage for the given offset */ static void *ocfs2_xa_offset_pointer(struct ocfs2_xa_loc *loc, int offset) { BUG_ON(offset >= loc->xl_size); return loc->xl_ops->xlo_offset_pointer(loc, offset); } /* * Wipe the name+value pair and allow the storage to reclaim it. This * must be followed by either removal of the entry or a call to * ocfs2_xa_add_namevalue(). */ static void ocfs2_xa_wipe_namevalue(struct ocfs2_xa_loc *loc) { loc->xl_ops->xlo_wipe_namevalue(loc); } /* * Find lowest offset to a name+value pair. This is the start of our * downward-growing free space. */ static int ocfs2_xa_get_free_start(struct ocfs2_xa_loc *loc) { return loc->xl_ops->xlo_get_free_start(loc); } /* Can we reuse loc->xl_entry for xi? */ static int ocfs2_xa_can_reuse_entry(struct ocfs2_xa_loc *loc, struct ocfs2_xattr_info *xi) { return loc->xl_ops->xlo_can_reuse(loc, xi); } /* How much free space is needed to set the new value */ static int ocfs2_xa_check_space(struct ocfs2_xa_loc *loc, struct ocfs2_xattr_info *xi) { return loc->xl_ops->xlo_check_space(loc, xi); } static void ocfs2_xa_add_entry(struct ocfs2_xa_loc *loc, u32 name_hash) { loc->xl_ops->xlo_add_entry(loc, name_hash); loc->xl_entry->xe_name_hash = cpu_to_le32(name_hash); /* * We can't leave the new entry's xe_name_offset at zero or * add_namevalue() will go nuts. We set it to the size of our * storage so that it can never be less than any other entry. */ loc->xl_entry->xe_name_offset = cpu_to_le16(loc->xl_size); } static void ocfs2_xa_add_namevalue(struct ocfs2_xa_loc *loc, struct ocfs2_xattr_info *xi) { int size = namevalue_size_xi(xi); int nameval_offset; char *nameval_buf; loc->xl_ops->xlo_add_namevalue(loc, size); loc->xl_entry->xe_value_size = cpu_to_le64(xi->xi_value_len); loc->xl_entry->xe_name_len = xi->xi_name_len; ocfs2_xattr_set_type(loc->xl_entry, xi->xi_name_index); ocfs2_xattr_set_local(loc->xl_entry, xi->xi_value_len <= OCFS2_XATTR_INLINE_SIZE); nameval_offset = le16_to_cpu(loc->xl_entry->xe_name_offset); nameval_buf = ocfs2_xa_offset_pointer(loc, nameval_offset); memset(nameval_buf, 0, size); memcpy(nameval_buf, xi->xi_name, xi->xi_name_len); } static void ocfs2_xa_fill_value_buf(struct ocfs2_xa_loc *loc, struct ocfs2_xattr_value_buf *vb) { int nameval_offset = le16_to_cpu(loc->xl_entry->xe_name_offset); int name_size = OCFS2_XATTR_SIZE(loc->xl_entry->xe_name_len); /* Value bufs are for value trees */ BUG_ON(ocfs2_xattr_is_local(loc->xl_entry)); BUG_ON(namevalue_size_xe(loc->xl_entry) != (name_size + OCFS2_XATTR_ROOT_SIZE)); loc->xl_ops->xlo_fill_value_buf(loc, vb); vb->vb_xv = (struct ocfs2_xattr_value_root *)ocfs2_xa_offset_pointer(loc, nameval_offset + name_size); } static int ocfs2_xa_block_journal_access(handle_t *handle, struct ocfs2_xa_loc *loc, int type) { struct buffer_head *bh = loc->xl_storage; ocfs2_journal_access_func access; if (loc->xl_size == (bh->b_size - offsetof(struct ocfs2_xattr_block, xb_attrs.xb_header))) access = ocfs2_journal_access_xb; else access = ocfs2_journal_access_di; return access(handle, INODE_CACHE(loc->xl_inode), bh, type); } static void ocfs2_xa_block_journal_dirty(handle_t *handle, struct ocfs2_xa_loc *loc) { struct buffer_head *bh = loc->xl_storage; ocfs2_journal_dirty(handle, bh); } static void *ocfs2_xa_block_offset_pointer(struct ocfs2_xa_loc *loc, int offset) { return (char *)loc->xl_header + offset; } static int ocfs2_xa_block_can_reuse(struct ocfs2_xa_loc *loc, struct ocfs2_xattr_info *xi) { /* * Block storage is strict. If the sizes aren't exact, we will * remove the old one and reinsert the new. */ return namevalue_size_xe(loc->xl_entry) == namevalue_size_xi(xi); } static int ocfs2_xa_block_get_free_start(struct ocfs2_xa_loc *loc) { struct ocfs2_xattr_header *xh = loc->xl_header; int i, count = le16_to_cpu(xh->xh_count); int offset, free_start = loc->xl_size; for (i = 0; i < count; i++) { offset = le16_to_cpu(xh->xh_entries[i].xe_name_offset); if (offset < free_start) free_start = offset; } return free_start; } static int ocfs2_xa_block_check_space(struct ocfs2_xa_loc *loc, struct ocfs2_xattr_info *xi) { int count = le16_to_cpu(loc->xl_header->xh_count); int free_start = ocfs2_xa_get_free_start(loc); int needed_space = ocfs2_xi_entry_usage(xi); /* * Block storage will reclaim the original entry before inserting * the new value, so we only need the difference. If the new * entry is smaller than the old one, we don't need anything. */ if (loc->xl_entry) { /* Don't need space if we're reusing! */ if (ocfs2_xa_can_reuse_entry(loc, xi)) needed_space = 0; else needed_space -= ocfs2_xe_entry_usage(loc->xl_entry); } if (needed_space < 0) needed_space = 0; return ocfs2_xa_check_space_helper(needed_space, free_start, count); } /* * Block storage for xattrs keeps the name+value pairs compacted. When * we remove one, we have to shift any that preceded it towards the end. */ static void ocfs2_xa_block_wipe_namevalue(struct ocfs2_xa_loc *loc) { int i, offset; int namevalue_offset, first_namevalue_offset, namevalue_size; struct ocfs2_xattr_entry *entry = loc->xl_entry; struct ocfs2_xattr_header *xh = loc->xl_header; int count = le16_to_cpu(xh->xh_count); namevalue_offset = le16_to_cpu(entry->xe_name_offset); namevalue_size = namevalue_size_xe(entry); first_namevalue_offset = ocfs2_xa_get_free_start(loc); /* Shift the name+value pairs */ memmove((char *)xh + first_namevalue_offset + namevalue_size, (char *)xh + first_namevalue_offset, namevalue_offset - first_namevalue_offset); memset((char *)xh + first_namevalue_offset, 0, namevalue_size); /* Now tell xh->xh_entries about it */ for (i = 0; i < count; i++) { offset = le16_to_cpu(xh->xh_entries[i].xe_name_offset); if (offset <= namevalue_offset) le16_add_cpu(&xh->xh_entries[i].xe_name_offset, namevalue_size); } /* * Note that we don't update xh_free_start or xh_name_value_len * because they're not used in block-stored xattrs. */ } static void ocfs2_xa_block_add_entry(struct ocfs2_xa_loc *loc, u32 name_hash) { int count = le16_to_cpu(loc->xl_header->xh_count); loc->xl_entry = &(loc->xl_header->xh_entries[count]); le16_add_cpu(&loc->xl_header->xh_count, 1); memset(loc->xl_entry, 0, sizeof(struct ocfs2_xattr_entry)); } static void ocfs2_xa_block_add_namevalue(struct ocfs2_xa_loc *loc, int size) { int free_start = ocfs2_xa_get_free_start(loc); loc->xl_entry->xe_name_offset = cpu_to_le16(free_start - size); } static void ocfs2_xa_block_fill_value_buf(struct ocfs2_xa_loc *loc, struct ocfs2_xattr_value_buf *vb) { struct buffer_head *bh = loc->xl_storage; if (loc->xl_size == (bh->b_size - offsetof(struct ocfs2_xattr_block, xb_attrs.xb_header))) vb->vb_access = ocfs2_journal_access_xb; else vb->vb_access = ocfs2_journal_access_di; vb->vb_bh = bh; } /* * Operations for xattrs stored in blocks. This includes inline inode * storage and unindexed ocfs2_xattr_blocks. */ static const struct ocfs2_xa_loc_operations ocfs2_xa_block_loc_ops = { .xlo_journal_access = ocfs2_xa_block_journal_access, .xlo_journal_dirty = ocfs2_xa_block_journal_dirty, .xlo_offset_pointer = ocfs2_xa_block_offset_pointer, .xlo_check_space = ocfs2_xa_block_check_space, .xlo_can_reuse = ocfs2_xa_block_can_reuse, .xlo_get_free_start = ocfs2_xa_block_get_free_start, .xlo_wipe_namevalue = ocfs2_xa_block_wipe_namevalue, .xlo_add_entry = ocfs2_xa_block_add_entry, .xlo_add_namevalue = ocfs2_xa_block_add_namevalue, .xlo_fill_value_buf = ocfs2_xa_block_fill_value_buf, }; static int ocfs2_xa_bucket_journal_access(handle_t *handle, struct ocfs2_xa_loc *loc, int type) { struct ocfs2_xattr_bucket *bucket = loc->xl_storage; return ocfs2_xattr_bucket_journal_access(handle, bucket, type); } static void ocfs2_xa_bucket_journal_dirty(handle_t *handle, struct ocfs2_xa_loc *loc) { struct ocfs2_xattr_bucket *bucket = loc->xl_storage; ocfs2_xattr_bucket_journal_dirty(handle, bucket); } static void *ocfs2_xa_bucket_offset_pointer(struct ocfs2_xa_loc *loc, int offset) { struct ocfs2_xattr_bucket *bucket = loc->xl_storage; int block, block_offset; /* The header is at the front of the bucket */ block = offset >> loc->xl_inode->i_sb->s_blocksize_bits; block_offset = offset % loc->xl_inode->i_sb->s_blocksize; return bucket_block(bucket, block) + block_offset; } static int ocfs2_xa_bucket_can_reuse(struct ocfs2_xa_loc *loc, struct ocfs2_xattr_info *xi) { return namevalue_size_xe(loc->xl_entry) >= namevalue_size_xi(xi); } static int ocfs2_xa_bucket_get_free_start(struct ocfs2_xa_loc *loc) { struct ocfs2_xattr_bucket *bucket = loc->xl_storage; return le16_to_cpu(bucket_xh(bucket)->xh_free_start); } static int ocfs2_bucket_align_free_start(struct super_block *sb, int free_start, int size) { /* * We need to make sure that the name+value pair fits within * one block. */ if (((free_start - size) >> sb->s_blocksize_bits) != ((free_start - 1) >> sb->s_blocksize_bits)) free_start -= free_start % sb->s_blocksize; return free_start; } static int ocfs2_xa_bucket_check_space(struct ocfs2_xa_loc *loc, struct ocfs2_xattr_info *xi) { int rc; int count = le16_to_cpu(loc->xl_header->xh_count); int free_start = ocfs2_xa_get_free_start(loc); int needed_space = ocfs2_xi_entry_usage(xi); int size = namevalue_size_xi(xi); struct super_block *sb = loc->xl_inode->i_sb; /* * Bucket storage does not reclaim name+value pairs it cannot * reuse. They live as holes until the bucket fills, and then * the bucket is defragmented. However, the bucket can reclaim * the ocfs2_xattr_entry. */ if (loc->xl_entry) { /* Don't need space if we're reusing! */ if (ocfs2_xa_can_reuse_entry(loc, xi)) needed_space = 0; else needed_space -= sizeof(struct ocfs2_xattr_entry); } BUG_ON(needed_space < 0); if (free_start < size) { if (needed_space) return -ENOSPC; } else { /* * First we check if it would fit in the first place. * Below, we align the free start to a block. This may * slide us below the minimum gap. By checking unaligned * first, we avoid that error. */ rc = ocfs2_xa_check_space_helper(needed_space, free_start, count); if (rc) return rc; free_start = ocfs2_bucket_align_free_start(sb, free_start, size); } return ocfs2_xa_check_space_helper(needed_space, free_start, count); } static void ocfs2_xa_bucket_wipe_namevalue(struct ocfs2_xa_loc *loc) { le16_add_cpu(&loc->xl_header->xh_name_value_len, -namevalue_size_xe(loc->xl_entry)); } static void ocfs2_xa_bucket_add_entry(struct ocfs2_xa_loc *loc, u32 name_hash) { struct ocfs2_xattr_header *xh = loc->xl_header; int count = le16_to_cpu(xh->xh_count); int low = 0, high = count - 1, tmp; struct ocfs2_xattr_entry *tmp_xe; /* * We keep buckets sorted by name_hash, so we need to find * our insert place. */ while (low <= high && count) { tmp = (low + high) / 2; tmp_xe = &xh->xh_entries[tmp]; if (name_hash > le32_to_cpu(tmp_xe->xe_name_hash)) low = tmp + 1; else if (name_hash < le32_to_cpu(tmp_xe->xe_name_hash)) high = tmp - 1; else { low = tmp; break; } } if (low != count) memmove(&xh->xh_entries[low + 1], &xh->xh_entries[low], ((count - low) * sizeof(struct ocfs2_xattr_entry))); le16_add_cpu(&xh->xh_count, 1); loc->xl_entry = &xh->xh_entries[low]; memset(loc->xl_entry, 0, sizeof(struct ocfs2_xattr_entry)); } static void ocfs2_xa_bucket_add_namevalue(struct ocfs2_xa_loc *loc, int size) { int free_start = ocfs2_xa_get_free_start(loc); struct ocfs2_xattr_header *xh = loc->xl_header; struct super_block *sb = loc->xl_inode->i_sb; int nameval_offset; free_start = ocfs2_bucket_align_free_start(sb, free_start, size); nameval_offset = free_start - size; loc->xl_entry->xe_name_offset = cpu_to_le16(nameval_offset); xh->xh_free_start = cpu_to_le16(nameval_offset); le16_add_cpu(&xh->xh_name_value_len, size); } static void ocfs2_xa_bucket_fill_value_buf(struct ocfs2_xa_loc *loc, struct ocfs2_xattr_value_buf *vb) { struct ocfs2_xattr_bucket *bucket = loc->xl_storage; struct super_block *sb = loc->xl_inode->i_sb; int nameval_offset = le16_to_cpu(loc->xl_entry->xe_name_offset); int size = namevalue_size_xe(loc->xl_entry); int block_offset = nameval_offset >> sb->s_blocksize_bits; /* Values are not allowed to straddle block boundaries */ BUG_ON(block_offset != ((nameval_offset + size - 1) >> sb->s_blocksize_bits)); /* We expect the bucket to be filled in */ BUG_ON(!bucket->bu_bhs[block_offset]); vb->vb_access = ocfs2_journal_access; vb->vb_bh = bucket->bu_bhs[block_offset]; } /* Operations for xattrs stored in buckets. */ static const struct ocfs2_xa_loc_operations ocfs2_xa_bucket_loc_ops = { .xlo_journal_access = ocfs2_xa_bucket_journal_access, .xlo_journal_dirty = ocfs2_xa_bucket_journal_dirty, .xlo_offset_pointer = ocfs2_xa_bucket_offset_pointer, .xlo_check_space = ocfs2_xa_bucket_check_space, .xlo_can_reuse = ocfs2_xa_bucket_can_reuse, .xlo_get_free_start = ocfs2_xa_bucket_get_free_start, .xlo_wipe_namevalue = ocfs2_xa_bucket_wipe_namevalue, .xlo_add_entry = ocfs2_xa_bucket_add_entry, .xlo_add_namevalue = ocfs2_xa_bucket_add_namevalue, .xlo_fill_value_buf = ocfs2_xa_bucket_fill_value_buf, }; static unsigned int ocfs2_xa_value_clusters(struct ocfs2_xa_loc *loc) { struct ocfs2_xattr_value_buf vb; if (ocfs2_xattr_is_local(loc->xl_entry)) return 0; ocfs2_xa_fill_value_buf(loc, &vb); return le32_to_cpu(vb.vb_xv->xr_clusters); } static int ocfs2_xa_value_truncate(struct ocfs2_xa_loc *loc, u64 bytes, struct ocfs2_xattr_set_ctxt *ctxt) { int trunc_rc, access_rc; struct ocfs2_xattr_value_buf vb; ocfs2_xa_fill_value_buf(loc, &vb); trunc_rc = ocfs2_xattr_value_truncate(loc->xl_inode, &vb, bytes, ctxt); /* * The caller of ocfs2_xa_value_truncate() has already called * ocfs2_xa_journal_access on the loc. However, The truncate code * calls ocfs2_extend_trans(). This may commit the previous * transaction and open a new one. If this is a bucket, truncate * could leave only vb->vb_bh set up for journaling. Meanwhile, * the caller is expecting to dirty the entire bucket. So we must * reset the journal work. We do this even if truncate has failed, * as it could have failed after committing the extend. */ access_rc = ocfs2_xa_journal_access(ctxt->handle, loc, OCFS2_JOURNAL_ACCESS_WRITE); /* Errors in truncate take precedence */ return trunc_rc ? trunc_rc : access_rc; } static void ocfs2_xa_remove_entry(struct ocfs2_xa_loc *loc) { int index, count; struct ocfs2_xattr_header *xh = loc->xl_header; struct ocfs2_xattr_entry *entry = loc->xl_entry; ocfs2_xa_wipe_namevalue(loc); loc->xl_entry = NULL; le16_add_cpu(&xh->xh_count, -1); count = le16_to_cpu(xh->xh_count); /* * Only zero out the entry if there are more remaining. This is * important for an empty bucket, as it keeps track of the * bucket's hash value. It doesn't hurt empty block storage. */ if (count) { index = ((char *)entry - (char *)&xh->xh_entries) / sizeof(struct ocfs2_xattr_entry); memmove(&xh->xh_entries[index], &xh->xh_entries[index + 1], (count - index) * sizeof(struct ocfs2_xattr_entry)); memset(&xh->xh_entries[count], 0, sizeof(struct ocfs2_xattr_entry)); } } /* * If we have a problem adjusting the size of an external value during * ocfs2_xa_prepare_entry() or ocfs2_xa_remove(), we may have an xattr * in an intermediate state. For example, the value may be partially * truncated. * * If the value tree hasn't changed, the extend/truncate went nowhere. * We have nothing to do. The caller can treat it as a straight error. * * If the value tree got partially truncated, we now have a corrupted * extended attribute. We're going to wipe its entry and leak the * clusters. Better to leak some storage than leave a corrupt entry. * * If the value tree grew, it obviously didn't grow enough for the * new entry. We're not going to try and reclaim those clusters either. * If there was already an external value there (orig_clusters != 0), * the new clusters are attached safely and we can just leave the old * value in place. If there was no external value there, we remove * the entry. * * This way, the xattr block we store in the journal will be consistent. * If the size change broke because of the journal, no changes will hit * disk anyway. */ static void ocfs2_xa_cleanup_value_truncate(struct ocfs2_xa_loc *loc, const char *what, unsigned int orig_clusters) { unsigned int new_clusters = ocfs2_xa_value_clusters(loc); char *nameval_buf = ocfs2_xa_offset_pointer(loc, le16_to_cpu(loc->xl_entry->xe_name_offset)); if (new_clusters < orig_clusters) { mlog(ML_ERROR, "Partial truncate while %s xattr %.*s. Leaking " "%u clusters and removing the entry\n", what, loc->xl_entry->xe_name_len, nameval_buf, orig_clusters - new_clusters); ocfs2_xa_remove_entry(loc); } else if (!orig_clusters) { mlog(ML_ERROR, "Unable to allocate an external value for xattr " "%.*s safely. Leaking %u clusters and removing the " "entry\n", loc->xl_entry->xe_name_len, nameval_buf, new_clusters - orig_clusters); ocfs2_xa_remove_entry(loc); } else if (new_clusters > orig_clusters) mlog(ML_ERROR, "Unable to grow xattr %.*s safely. %u new clusters " "have been added, but the value will not be " "modified\n", loc->xl_entry->xe_name_len, nameval_buf, new_clusters - orig_clusters); } static int ocfs2_xa_remove(struct ocfs2_xa_loc *loc, struct ocfs2_xattr_set_ctxt *ctxt) { int rc = 0; unsigned int orig_clusters; if (!ocfs2_xattr_is_local(loc->xl_entry)) { orig_clusters = ocfs2_xa_value_clusters(loc); rc = ocfs2_xa_value_truncate(loc, 0, ctxt); if (rc) { mlog_errno(rc); /* * Since this is remove, we can return 0 if * ocfs2_xa_cleanup_value_truncate() is going to * wipe the entry anyway. So we check the * cluster count as well. */ if (orig_clusters != ocfs2_xa_value_clusters(loc)) rc = 0; ocfs2_xa_cleanup_value_truncate(loc, "removing", orig_clusters); if (rc) goto out; } } ocfs2_xa_remove_entry(loc); out: return rc; } static void ocfs2_xa_install_value_root(struct ocfs2_xa_loc *loc) { int name_size = OCFS2_XATTR_SIZE(loc->xl_entry->xe_name_len); char *nameval_buf; nameval_buf = ocfs2_xa_offset_pointer(loc, le16_to_cpu(loc->xl_entry->xe_name_offset)); memcpy(nameval_buf + name_size, &def_xv, OCFS2_XATTR_ROOT_SIZE); } /* * Take an existing entry and make it ready for the new value. This * won't allocate space, but it may free space. It should be ready for * ocfs2_xa_prepare_entry() to finish the work. */ static int ocfs2_xa_reuse_entry(struct ocfs2_xa_loc *loc, struct ocfs2_xattr_info *xi, struct ocfs2_xattr_set_ctxt *ctxt) { int rc = 0; int name_size = OCFS2_XATTR_SIZE(xi->xi_name_len); unsigned int orig_clusters; char *nameval_buf; int xe_local = ocfs2_xattr_is_local(loc->xl_entry); int xi_local = xi->xi_value_len <= OCFS2_XATTR_INLINE_SIZE; BUG_ON(OCFS2_XATTR_SIZE(loc->xl_entry->xe_name_len) != name_size); nameval_buf = ocfs2_xa_offset_pointer(loc, le16_to_cpu(loc->xl_entry->xe_name_offset)); if (xe_local) { memset(nameval_buf + name_size, 0, namevalue_size_xe(loc->xl_entry) - name_size); if (!xi_local) ocfs2_xa_install_value_root(loc); } else { orig_clusters = ocfs2_xa_value_clusters(loc); if (xi_local) { rc = ocfs2_xa_value_truncate(loc, 0, ctxt); if (rc < 0) mlog_errno(rc); else memset(nameval_buf + name_size, 0, namevalue_size_xe(loc->xl_entry) - name_size); } else if (le64_to_cpu(loc->xl_entry->xe_value_size) > xi->xi_value_len) { rc = ocfs2_xa_value_truncate(loc, xi->xi_value_len, ctxt); if (rc < 0) mlog_errno(rc); } if (rc) { ocfs2_xa_cleanup_value_truncate(loc, "reusing", orig_clusters); goto out; } } loc->xl_entry->xe_value_size = cpu_to_le64(xi->xi_value_len); ocfs2_xattr_set_local(loc->xl_entry, xi_local); out: return rc; } /* * Prepares loc->xl_entry to receive the new xattr. This includes * properly setting up the name+value pair region. If loc->xl_entry * already exists, it will take care of modifying it appropriately. * * Note that this modifies the data. You did journal_access already, * right? */ static int ocfs2_xa_prepare_entry(struct ocfs2_xa_loc *loc, struct ocfs2_xattr_info *xi, u32 name_hash, struct ocfs2_xattr_set_ctxt *ctxt) { int rc = 0; unsigned int orig_clusters; __le64 orig_value_size = 0; rc = ocfs2_xa_check_space(loc, xi); if (rc) goto out; if (loc->xl_entry) { if (ocfs2_xa_can_reuse_entry(loc, xi)) { orig_value_size = loc->xl_entry->xe_value_size; rc = ocfs2_xa_reuse_entry(loc, xi, ctxt); if (rc) goto out; goto alloc_value; } if (!ocfs2_xattr_is_local(loc->xl_entry)) { orig_clusters = ocfs2_xa_value_clusters(loc); rc = ocfs2_xa_value_truncate(loc, 0, ctxt); if (rc) { mlog_errno(rc); ocfs2_xa_cleanup_value_truncate(loc, "overwriting", orig_clusters); goto out; } } ocfs2_xa_wipe_namevalue(loc); } else ocfs2_xa_add_entry(loc, name_hash); /* * If we get here, we have a blank entry. Fill it. We grow our * name+value pair back from the end. */ ocfs2_xa_add_namevalue(loc, xi); if (xi->xi_value_len > OCFS2_XATTR_INLINE_SIZE) ocfs2_xa_install_value_root(loc); alloc_value: if (xi->xi_value_len > OCFS2_XATTR_INLINE_SIZE) { orig_clusters = ocfs2_xa_value_clusters(loc); rc = ocfs2_xa_value_truncate(loc, xi->xi_value_len, ctxt); if (rc < 0) { ctxt->set_abort = 1; ocfs2_xa_cleanup_value_truncate(loc, "growing", orig_clusters); /* * If we were growing an existing value, * ocfs2_xa_cleanup_value_truncate() won't remove * the entry. We need to restore the original value * size. */ if (loc->xl_entry) { BUG_ON(!orig_value_size); loc->xl_entry->xe_value_size = orig_value_size; } mlog_errno(rc); } } out: return rc; } /* * Store the value portion of the name+value pair. This will skip * values that are stored externally. Their tree roots were set up * by ocfs2_xa_prepare_entry(). */ static int ocfs2_xa_store_value(struct ocfs2_xa_loc *loc, struct ocfs2_xattr_info *xi, struct ocfs2_xattr_set_ctxt *ctxt) { int rc = 0; int nameval_offset = le16_to_cpu(loc->xl_entry->xe_name_offset); int name_size = OCFS2_XATTR_SIZE(xi->xi_name_len); char *nameval_buf; struct ocfs2_xattr_value_buf vb; nameval_buf = ocfs2_xa_offset_pointer(loc, nameval_offset); if (xi->xi_value_len > OCFS2_XATTR_INLINE_SIZE) { ocfs2_xa_fill_value_buf(loc, &vb); rc = __ocfs2_xattr_set_value_outside(loc->xl_inode, ctxt->handle, &vb, xi->xi_value, xi->xi_value_len); } else memcpy(nameval_buf + name_size, xi->xi_value, xi->xi_value_len); return rc; } static int ocfs2_xa_set(struct ocfs2_xa_loc *loc, struct ocfs2_xattr_info *xi, struct ocfs2_xattr_set_ctxt *ctxt) { int ret; u32 name_hash = ocfs2_xattr_name_hash(loc->xl_inode, xi->xi_name, xi->xi_name_len); ret = ocfs2_xa_journal_access(ctxt->handle, loc, OCFS2_JOURNAL_ACCESS_WRITE); if (ret) { mlog_errno(ret); goto out; } /* * From here on out, everything is going to modify the buffer a * little. Errors are going to leave the xattr header in a * sane state. Thus, even with errors we dirty the sucker. */ /* Don't worry, we are never called with !xi_value and !xl_entry */ if (!xi->xi_value) { ret = ocfs2_xa_remove(loc, ctxt); goto out_dirty; } ret = ocfs2_xa_prepare_entry(loc, xi, name_hash, ctxt); if (ret) { if (ret != -ENOSPC) mlog_errno(ret); goto out_dirty; } ret = ocfs2_xa_store_value(loc, xi, ctxt); if (ret) mlog_errno(ret); out_dirty: ocfs2_xa_journal_dirty(ctxt->handle, loc); out: return ret; } static void ocfs2_init_dinode_xa_loc(struct ocfs2_xa_loc *loc, struct inode *inode, struct buffer_head *bh, struct ocfs2_xattr_entry *entry) { struct ocfs2_dinode *di = (struct ocfs2_dinode *)bh->b_data; BUG_ON(!(OCFS2_I(inode)->ip_dyn_features & OCFS2_INLINE_XATTR_FL)); loc->xl_inode = inode; loc->xl_ops = &ocfs2_xa_block_loc_ops; loc->xl_storage = bh; loc->xl_entry = entry; loc->xl_size = le16_to_cpu(di->i_xattr_inline_size); loc->xl_header = (struct ocfs2_xattr_header *)(bh->b_data + bh->b_size - loc->xl_size); } static void ocfs2_init_xattr_block_xa_loc(struct ocfs2_xa_loc *loc, struct inode *inode, struct buffer_head *bh, struct ocfs2_xattr_entry *entry) { struct ocfs2_xattr_block *xb = (struct ocfs2_xattr_block *)bh->b_data; BUG_ON(le16_to_cpu(xb->xb_flags) & OCFS2_XATTR_INDEXED); loc->xl_inode = inode; loc->xl_ops = &ocfs2_xa_block_loc_ops; loc->xl_storage = bh; loc->xl_header = &(xb->xb_attrs.xb_header); loc->xl_entry = entry; loc->xl_size = bh->b_size - offsetof(struct ocfs2_xattr_block, xb_attrs.xb_header); } static void ocfs2_init_xattr_bucket_xa_loc(struct ocfs2_xa_loc *loc, struct ocfs2_xattr_bucket *bucket, struct ocfs2_xattr_entry *entry) { loc->xl_inode = bucket->bu_inode; loc->xl_ops = &ocfs2_xa_bucket_loc_ops; loc->xl_storage = bucket; loc->xl_header = bucket_xh(bucket); loc->xl_entry = entry; loc->xl_size = OCFS2_XATTR_BUCKET_SIZE; } /* * In xattr remove, if it is stored outside and refcounted, we may have * the chance to split the refcount tree. So need the allocators. */ static int ocfs2_lock_xattr_remove_allocators(struct inode *inode, struct ocfs2_xattr_value_root *xv, struct ocfs2_caching_info *ref_ci, struct buffer_head *ref_root_bh, struct ocfs2_alloc_context **meta_ac, int *ref_credits) { int ret, meta_add = 0; u32 p_cluster, num_clusters; unsigned int ext_flags; *ref_credits = 0; ret = ocfs2_xattr_get_clusters(inode, 0, &p_cluster, &num_clusters, &xv->xr_list, &ext_flags); if (ret) { mlog_errno(ret); goto out; } if (!(ext_flags & OCFS2_EXT_REFCOUNTED)) goto out; ret = ocfs2_refcounted_xattr_delete_need(inode, ref_ci, ref_root_bh, xv, &meta_add, ref_credits); if (ret) { mlog_errno(ret); goto out; } ret = ocfs2_reserve_new_metadata_blocks(OCFS2_SB(inode->i_sb), meta_add, meta_ac); if (ret) mlog_errno(ret); out: return ret; } static int ocfs2_remove_value_outside(struct inode*inode, struct ocfs2_xattr_value_buf *vb, struct ocfs2_xattr_header *header, struct ocfs2_caching_info *ref_ci, struct buffer_head *ref_root_bh) { int ret = 0, i, ref_credits; struct ocfs2_super *osb = OCFS2_SB(inode->i_sb); struct ocfs2_xattr_set_ctxt ctxt = { NULL, NULL, }; void *val; ocfs2_init_dealloc_ctxt(&ctxt.dealloc); for (i = 0; i < le16_to_cpu(header->xh_count); i++) { struct ocfs2_xattr_entry *entry = &header->xh_entries[i]; if (ocfs2_xattr_is_local(entry)) continue; val = (void *)header + le16_to_cpu(entry->xe_name_offset); vb->vb_xv = (struct ocfs2_xattr_value_root *) (val + OCFS2_XATTR_SIZE(entry->xe_name_len)); ret = ocfs2_lock_xattr_remove_allocators(inode, vb->vb_xv, ref_ci, ref_root_bh, &ctxt.meta_ac, &ref_credits); ctxt.handle = ocfs2_start_trans(osb, ref_credits + ocfs2_remove_extent_credits(osb->sb)); if (IS_ERR(ctxt.handle)) { ret = PTR_ERR(ctxt.handle); mlog_errno(ret); break; } ret = ocfs2_xattr_value_truncate(inode, vb, 0, &ctxt); ocfs2_commit_trans(osb, ctxt.handle); if (ctxt.meta_ac) { ocfs2_free_alloc_context(ctxt.meta_ac); ctxt.meta_ac = NULL; } if (ret < 0) { mlog_errno(ret); break; } } if (ctxt.meta_ac) ocfs2_free_alloc_context(ctxt.meta_ac); ocfs2_schedule_truncate_log_flush(osb, 1); ocfs2_run_deallocs(osb, &ctxt.dealloc); return ret; } static int ocfs2_xattr_ibody_remove(struct inode *inode, struct buffer_head *di_bh, struct ocfs2_caching_info *ref_ci, struct buffer_head *ref_root_bh) { struct ocfs2_dinode *di = (struct ocfs2_dinode *)di_bh->b_data; struct ocfs2_xattr_header *header; int ret; struct ocfs2_xattr_value_buf vb = { .vb_bh = di_bh, .vb_access = ocfs2_journal_access_di, }; header = (struct ocfs2_xattr_header *) ((void *)di + inode->i_sb->s_blocksize - le16_to_cpu(di->i_xattr_inline_size)); ret = ocfs2_remove_value_outside(inode, &vb, header, ref_ci, ref_root_bh); return ret; } struct ocfs2_rm_xattr_bucket_para { struct ocfs2_caching_info *ref_ci; struct buffer_head *ref_root_bh; }; static int ocfs2_xattr_block_remove(struct inode *inode, struct buffer_head *blk_bh, struct ocfs2_caching_info *ref_ci, struct buffer_head *ref_root_bh) { struct ocfs2_xattr_block *xb; int ret = 0; struct ocfs2_xattr_value_buf vb = { .vb_bh = blk_bh, .vb_access = ocfs2_journal_access_xb, }; struct ocfs2_rm_xattr_bucket_para args = { .ref_ci = ref_ci, .ref_root_bh = ref_root_bh, }; xb = (struct ocfs2_xattr_block *)blk_bh->b_data; if (!(le16_to_cpu(xb->xb_flags) & OCFS2_XATTR_INDEXED)) { struct ocfs2_xattr_header *header = &(xb->xb_attrs.xb_header); ret = ocfs2_remove_value_outside(inode, &vb, header, ref_ci, ref_root_bh); } else ret = ocfs2_iterate_xattr_index_block(inode, blk_bh, ocfs2_rm_xattr_cluster, &args); return ret; } static int ocfs2_xattr_free_block(struct inode *inode, u64 block, struct ocfs2_caching_info *ref_ci, struct buffer_head *ref_root_bh) { struct inode *xb_alloc_inode; struct buffer_head *xb_alloc_bh = NULL; struct buffer_head *blk_bh = NULL; struct ocfs2_xattr_block *xb; struct ocfs2_super *osb = OCFS2_SB(inode->i_sb); handle_t *handle; int ret = 0; u64 blk, bg_blkno; u16 bit; ret = ocfs2_read_xattr_block(inode, block, &blk_bh); if (ret < 0) { mlog_errno(ret); goto out; } ret = ocfs2_xattr_block_remove(inode, blk_bh, ref_ci, ref_root_bh); if (ret < 0) { mlog_errno(ret); goto out; } xb = (struct ocfs2_xattr_block *)blk_bh->b_data; blk = le64_to_cpu(xb->xb_blkno); bit = le16_to_cpu(xb->xb_suballoc_bit); if (xb->xb_suballoc_loc) bg_blkno = le64_to_cpu(xb->xb_suballoc_loc); else bg_blkno = ocfs2_which_suballoc_group(blk, bit); xb_alloc_inode = ocfs2_get_system_file_inode(osb, EXTENT_ALLOC_SYSTEM_INODE, le16_to_cpu(xb->xb_suballoc_slot)); if (!xb_alloc_inode) { ret = -ENOMEM; mlog_errno(ret); goto out; } mutex_lock(&xb_alloc_inode->i_mutex); ret = ocfs2_inode_lock(xb_alloc_inode, &xb_alloc_bh, 1); if (ret < 0) { mlog_errno(ret); goto out_mutex; } handle = ocfs2_start_trans(osb, OCFS2_SUBALLOC_FREE); if (IS_ERR(handle)) { ret = PTR_ERR(handle); mlog_errno(ret); goto out_unlock; } ret = ocfs2_free_suballoc_bits(handle, xb_alloc_inode, xb_alloc_bh, bit, bg_blkno, 1); if (ret < 0) mlog_errno(ret); ocfs2_commit_trans(osb, handle); out_unlock: ocfs2_inode_unlock(xb_alloc_inode, 1); brelse(xb_alloc_bh); out_mutex: mutex_unlock(&xb_alloc_inode->i_mutex); iput(xb_alloc_inode); out: brelse(blk_bh); return ret; } /* * ocfs2_xattr_remove() * * Free extended attribute resources associated with this inode. */ int ocfs2_xattr_remove(struct inode *inode, struct buffer_head *di_bh) { struct ocfs2_inode_info *oi = OCFS2_I(inode); struct ocfs2_dinode *di = (struct ocfs2_dinode *)di_bh->b_data; struct ocfs2_refcount_tree *ref_tree = NULL; struct buffer_head *ref_root_bh = NULL; struct ocfs2_caching_info *ref_ci = NULL; handle_t *handle; int ret; if (!ocfs2_supports_xattr(OCFS2_SB(inode->i_sb))) return 0; if (!(oi->ip_dyn_features & OCFS2_HAS_XATTR_FL)) return 0; if (OCFS2_I(inode)->ip_dyn_features & OCFS2_HAS_REFCOUNT_FL) { ret = ocfs2_lock_refcount_tree(OCFS2_SB(inode->i_sb), le64_to_cpu(di->i_refcount_loc), 1, &ref_tree, &ref_root_bh); if (ret) { mlog_errno(ret); goto out; } ref_ci = &ref_tree->rf_ci; } if (oi->ip_dyn_features & OCFS2_INLINE_XATTR_FL) { ret = ocfs2_xattr_ibody_remove(inode, di_bh, ref_ci, ref_root_bh); if (ret < 0) { mlog_errno(ret); goto out; } } if (di->i_xattr_loc) { ret = ocfs2_xattr_free_block(inode, le64_to_cpu(di->i_xattr_loc), ref_ci, ref_root_bh); if (ret < 0) { mlog_errno(ret); goto out; } } handle = ocfs2_start_trans((OCFS2_SB(inode->i_sb)), OCFS2_INODE_UPDATE_CREDITS); if (IS_ERR(handle)) { ret = PTR_ERR(handle); mlog_errno(ret); goto out; } ret = ocfs2_journal_access_di(handle, INODE_CACHE(inode), di_bh, OCFS2_JOURNAL_ACCESS_WRITE); if (ret) { mlog_errno(ret); goto out_commit; } di->i_xattr_loc = 0; spin_lock(&oi->ip_lock); oi->ip_dyn_features &= ~(OCFS2_INLINE_XATTR_FL | OCFS2_HAS_XATTR_FL); di->i_dyn_features = cpu_to_le16(oi->ip_dyn_features); spin_unlock(&oi->ip_lock); ocfs2_journal_dirty(handle, di_bh); out_commit: ocfs2_commit_trans(OCFS2_SB(inode->i_sb), handle); out: if (ref_tree) ocfs2_unlock_refcount_tree(OCFS2_SB(inode->i_sb), ref_tree, 1); brelse(ref_root_bh); return ret; } static int ocfs2_xattr_has_space_inline(struct inode *inode, struct ocfs2_dinode *di) { struct ocfs2_inode_info *oi = OCFS2_I(inode); unsigned int xattrsize = OCFS2_SB(inode->i_sb)->s_xattr_inline_size; int free; if (xattrsize < OCFS2_MIN_XATTR_INLINE_SIZE) return 0; if (oi->ip_dyn_features & OCFS2_INLINE_DATA_FL) { struct ocfs2_inline_data *idata = &di->id2.i_data; free = le16_to_cpu(idata->id_count) - le64_to_cpu(di->i_size); } else if (ocfs2_inode_is_fast_symlink(inode)) { free = ocfs2_fast_symlink_chars(inode->i_sb) - le64_to_cpu(di->i_size); } else { struct ocfs2_extent_list *el = &di->id2.i_list; free = (le16_to_cpu(el->l_count) - le16_to_cpu(el->l_next_free_rec)) * sizeof(struct ocfs2_extent_rec); } if (free >= xattrsize) return 1; return 0; } /* * ocfs2_xattr_ibody_find() * * Find extended attribute in inode block and * fill search info into struct ocfs2_xattr_search. */ static int ocfs2_xattr_ibody_find(struct inode *inode, int name_index, const char *name, struct ocfs2_xattr_search *xs) { struct ocfs2_inode_info *oi = OCFS2_I(inode); struct ocfs2_dinode *di = (struct ocfs2_dinode *)xs->inode_bh->b_data; int ret; int has_space = 0; if (inode->i_sb->s_blocksize == OCFS2_MIN_BLOCKSIZE) return 0; if (!(oi->ip_dyn_features & OCFS2_INLINE_XATTR_FL)) { down_read(&oi->ip_alloc_sem); has_space = ocfs2_xattr_has_space_inline(inode, di); up_read(&oi->ip_alloc_sem); if (!has_space) return 0; } xs->xattr_bh = xs->inode_bh; xs->end = (void *)di + inode->i_sb->s_blocksize; if (oi->ip_dyn_features & OCFS2_INLINE_XATTR_FL) xs->header = (struct ocfs2_xattr_header *) (xs->end - le16_to_cpu(di->i_xattr_inline_size)); else xs->header = (struct ocfs2_xattr_header *) (xs->end - OCFS2_SB(inode->i_sb)->s_xattr_inline_size); xs->base = (void *)xs->header; xs->here = xs->header->xh_entries; /* Find the named attribute. */ if (oi->ip_dyn_features & OCFS2_INLINE_XATTR_FL) { ret = ocfs2_xattr_find_entry(name_index, name, xs); if (ret && ret != -ENODATA) return ret; xs->not_found = ret; } return 0; } static int ocfs2_xattr_ibody_init(struct inode *inode, struct buffer_head *di_bh, struct ocfs2_xattr_set_ctxt *ctxt) { int ret; struct ocfs2_inode_info *oi = OCFS2_I(inode); struct ocfs2_dinode *di = (struct ocfs2_dinode *)di_bh->b_data; struct ocfs2_super *osb = OCFS2_SB(inode->i_sb); unsigned int xattrsize = osb->s_xattr_inline_size; if (!ocfs2_xattr_has_space_inline(inode, di)) { ret = -ENOSPC; goto out; } ret = ocfs2_journal_access_di(ctxt->handle, INODE_CACHE(inode), di_bh, OCFS2_JOURNAL_ACCESS_WRITE); if (ret) { mlog_errno(ret); goto out; } /* * Adjust extent record count or inline data size * to reserve space for extended attribute. */ if (oi->ip_dyn_features & OCFS2_INLINE_DATA_FL) { struct ocfs2_inline_data *idata = &di->id2.i_data; le16_add_cpu(&idata->id_count, -xattrsize); } else if (!(ocfs2_inode_is_fast_symlink(inode))) { struct ocfs2_extent_list *el = &di->id2.i_list; le16_add_cpu(&el->l_count, -(xattrsize / sizeof(struct ocfs2_extent_rec))); } di->i_xattr_inline_size = cpu_to_le16(xattrsize); spin_lock(&oi->ip_lock); oi->ip_dyn_features |= OCFS2_INLINE_XATTR_FL|OCFS2_HAS_XATTR_FL; di->i_dyn_features = cpu_to_le16(oi->ip_dyn_features); spin_unlock(&oi->ip_lock); ocfs2_journal_dirty(ctxt->handle, di_bh); out: return ret; } /* * ocfs2_xattr_ibody_set() * * Set, replace or remove an extended attribute into inode block. * */ static int ocfs2_xattr_ibody_set(struct inode *inode, struct ocfs2_xattr_info *xi, struct ocfs2_xattr_search *xs, struct ocfs2_xattr_set_ctxt *ctxt) { int ret; struct ocfs2_inode_info *oi = OCFS2_I(inode); struct ocfs2_dinode *di = (struct ocfs2_dinode *)xs->inode_bh->b_data; struct ocfs2_xa_loc loc; if (inode->i_sb->s_blocksize == OCFS2_MIN_BLOCKSIZE) return -ENOSPC; down_write(&oi->ip_alloc_sem); if (!(oi->ip_dyn_features & OCFS2_INLINE_XATTR_FL)) { if (!ocfs2_xattr_has_space_inline(inode, di)) { ret = -ENOSPC; goto out; } } if (!(oi->ip_dyn_features & OCFS2_INLINE_XATTR_FL)) { ret = ocfs2_xattr_ibody_init(inode, xs->inode_bh, ctxt); if (ret) { if (ret != -ENOSPC) mlog_errno(ret); goto out; } } ocfs2_init_dinode_xa_loc(&loc, inode, xs->inode_bh, xs->not_found ? NULL : xs->here); ret = ocfs2_xa_set(&loc, xi, ctxt); if (ret) { if (ret != -ENOSPC) mlog_errno(ret); goto out; } xs->here = loc.xl_entry; out: up_write(&oi->ip_alloc_sem); return ret; } /* * ocfs2_xattr_block_find() * * Find extended attribute in external block and * fill search info into struct ocfs2_xattr_search. */ static int ocfs2_xattr_block_find(struct inode *inode, int name_index, const char *name, struct ocfs2_xattr_search *xs) { struct ocfs2_dinode *di = (struct ocfs2_dinode *)xs->inode_bh->b_data; struct buffer_head *blk_bh = NULL; struct ocfs2_xattr_block *xb; int ret = 0; if (!di->i_xattr_loc) return ret; ret = ocfs2_read_xattr_block(inode, le64_to_cpu(di->i_xattr_loc), &blk_bh); if (ret < 0) { mlog_errno(ret); return ret; } xs->xattr_bh = blk_bh; xb = (struct ocfs2_xattr_block *)blk_bh->b_data; if (!(le16_to_cpu(xb->xb_flags) & OCFS2_XATTR_INDEXED)) { xs->header = &xb->xb_attrs.xb_header; xs->base = (void *)xs->header; xs->end = (void *)(blk_bh->b_data) + blk_bh->b_size; xs->here = xs->header->xh_entries; ret = ocfs2_xattr_find_entry(name_index, name, xs); } else ret = ocfs2_xattr_index_block_find(inode, blk_bh, name_index, name, xs); if (ret && ret != -ENODATA) { xs->xattr_bh = NULL; goto cleanup; } xs->not_found = ret; return 0; cleanup: brelse(blk_bh); return ret; } static int ocfs2_create_xattr_block(struct inode *inode, struct buffer_head *inode_bh, struct ocfs2_xattr_set_ctxt *ctxt, int indexed, struct buffer_head **ret_bh) { int ret; u16 suballoc_bit_start; u32 num_got; u64 suballoc_loc, first_blkno; struct ocfs2_dinode *di = (struct ocfs2_dinode *)inode_bh->b_data; struct buffer_head *new_bh = NULL; struct ocfs2_xattr_block *xblk; ret = ocfs2_journal_access_di(ctxt->handle, INODE_CACHE(inode), inode_bh, OCFS2_JOURNAL_ACCESS_CREATE); if (ret < 0) { mlog_errno(ret); goto end; } ret = ocfs2_claim_metadata(ctxt->handle, ctxt->meta_ac, 1, &suballoc_loc, &suballoc_bit_start, &num_got, &first_blkno); if (ret < 0) { mlog_errno(ret); goto end; } new_bh = sb_getblk(inode->i_sb, first_blkno); ocfs2_set_new_buffer_uptodate(INODE_CACHE(inode), new_bh); ret = ocfs2_journal_access_xb(ctxt->handle, INODE_CACHE(inode), new_bh, OCFS2_JOURNAL_ACCESS_CREATE); if (ret < 0) { mlog_errno(ret); goto end; } /* Initialize ocfs2_xattr_block */ xblk = (struct ocfs2_xattr_block *)new_bh->b_data; memset(xblk, 0, inode->i_sb->s_blocksize); strcpy((void *)xblk, OCFS2_XATTR_BLOCK_SIGNATURE); xblk->xb_suballoc_slot = cpu_to_le16(ctxt->meta_ac->ac_alloc_slot); xblk->xb_suballoc_loc = cpu_to_le64(suballoc_loc); xblk->xb_suballoc_bit = cpu_to_le16(suballoc_bit_start); xblk->xb_fs_generation = cpu_to_le32(OCFS2_SB(inode->i_sb)->fs_generation); xblk->xb_blkno = cpu_to_le64(first_blkno); if (indexed) { struct ocfs2_xattr_tree_root *xr = &xblk->xb_attrs.xb_root; xr->xt_clusters = cpu_to_le32(1); xr->xt_last_eb_blk = 0; xr->xt_list.l_tree_depth = 0; xr->xt_list.l_count = cpu_to_le16( ocfs2_xattr_recs_per_xb(inode->i_sb)); xr->xt_list.l_next_free_rec = cpu_to_le16(1); xblk->xb_flags = cpu_to_le16(OCFS2_XATTR_INDEXED); } ocfs2_journal_dirty(ctxt->handle, new_bh); /* Add it to the inode */ di->i_xattr_loc = cpu_to_le64(first_blkno); spin_lock(&OCFS2_I(inode)->ip_lock); OCFS2_I(inode)->ip_dyn_features |= OCFS2_HAS_XATTR_FL; di->i_dyn_features = cpu_to_le16(OCFS2_I(inode)->ip_dyn_features); spin_unlock(&OCFS2_I(inode)->ip_lock); ocfs2_journal_dirty(ctxt->handle, inode_bh); *ret_bh = new_bh; new_bh = NULL; end: brelse(new_bh); return ret; } /* * ocfs2_xattr_block_set() * * Set, replace or remove an extended attribute into external block. * */ static int ocfs2_xattr_block_set(struct inode *inode, struct ocfs2_xattr_info *xi, struct ocfs2_xattr_search *xs, struct ocfs2_xattr_set_ctxt *ctxt) { struct buffer_head *new_bh = NULL; struct ocfs2_xattr_block *xblk = NULL; int ret; struct ocfs2_xa_loc loc; if (!xs->xattr_bh) { ret = ocfs2_create_xattr_block(inode, xs->inode_bh, ctxt, 0, &new_bh); if (ret) { mlog_errno(ret); goto end; } xs->xattr_bh = new_bh; xblk = (struct ocfs2_xattr_block *)xs->xattr_bh->b_data; xs->header = &xblk->xb_attrs.xb_header; xs->base = (void *)xs->header; xs->end = (void *)xblk + inode->i_sb->s_blocksize; xs->here = xs->header->xh_entries; } else xblk = (struct ocfs2_xattr_block *)xs->xattr_bh->b_data; if (!(le16_to_cpu(xblk->xb_flags) & OCFS2_XATTR_INDEXED)) { ocfs2_init_xattr_block_xa_loc(&loc, inode, xs->xattr_bh, xs->not_found ? NULL : xs->here); ret = ocfs2_xa_set(&loc, xi, ctxt); if (!ret) xs->here = loc.xl_entry; else if ((ret != -ENOSPC) || ctxt->set_abort) goto end; else { ret = ocfs2_xattr_create_index_block(inode, xs, ctxt); if (ret) goto end; } } if (le16_to_cpu(xblk->xb_flags) & OCFS2_XATTR_INDEXED) ret = ocfs2_xattr_set_entry_index_block(inode, xi, xs, ctxt); end: return ret; } /* Check whether the new xattr can be inserted into the inode. */ static int ocfs2_xattr_can_be_in_inode(struct inode *inode, struct ocfs2_xattr_info *xi, struct ocfs2_xattr_search *xs) { struct ocfs2_xattr_entry *last; int free, i; size_t min_offs = xs->end - xs->base; if (!xs->header) return 0; last = xs->header->xh_entries; for (i = 0; i < le16_to_cpu(xs->header->xh_count); i++) { size_t offs = le16_to_cpu(last->xe_name_offset); if (offs < min_offs) min_offs = offs; last += 1; } free = min_offs - ((void *)last - xs->base) - OCFS2_XATTR_HEADER_GAP; if (free < 0) return 0; BUG_ON(!xs->not_found); if (free >= (sizeof(struct ocfs2_xattr_entry) + namevalue_size_xi(xi))) return 1; return 0; } static int ocfs2_calc_xattr_set_need(struct inode *inode, struct ocfs2_dinode *di, struct ocfs2_xattr_info *xi, struct ocfs2_xattr_search *xis, struct ocfs2_xattr_search *xbs, int *clusters_need, int *meta_need, int *credits_need) { int ret = 0, old_in_xb = 0; int clusters_add = 0, meta_add = 0, credits = 0; struct buffer_head *bh = NULL; struct ocfs2_xattr_block *xb = NULL; struct ocfs2_xattr_entry *xe = NULL; struct ocfs2_xattr_value_root *xv = NULL; char *base = NULL; int name_offset, name_len = 0; u32 new_clusters = ocfs2_clusters_for_bytes(inode->i_sb, xi->xi_value_len); u64 value_size; /* * Calculate the clusters we need to write. * No matter whether we replace an old one or add a new one, * we need this for writing. */ if (xi->xi_value_len > OCFS2_XATTR_INLINE_SIZE) credits += new_clusters * ocfs2_clusters_to_blocks(inode->i_sb, 1); if (xis->not_found && xbs->not_found) { credits += ocfs2_blocks_per_xattr_bucket(inode->i_sb); if (xi->xi_value_len > OCFS2_XATTR_INLINE_SIZE) { clusters_add += new_clusters; credits += ocfs2_calc_extend_credits(inode->i_sb, &def_xv.xv.xr_list, new_clusters); } goto meta_guess; } if (!xis->not_found) { xe = xis->here; name_offset = le16_to_cpu(xe->xe_name_offset); name_len = OCFS2_XATTR_SIZE(xe->xe_name_len); base = xis->base; credits += OCFS2_INODE_UPDATE_CREDITS; } else { int i, block_off = 0; xb = (struct ocfs2_xattr_block *)xbs->xattr_bh->b_data; xe = xbs->here; name_offset = le16_to_cpu(xe->xe_name_offset); name_len = OCFS2_XATTR_SIZE(xe->xe_name_len); i = xbs->here - xbs->header->xh_entries; old_in_xb = 1; if (le16_to_cpu(xb->xb_flags) & OCFS2_XATTR_INDEXED) { ret = ocfs2_xattr_bucket_get_name_value(inode->i_sb, bucket_xh(xbs->bucket), i, &block_off, &name_offset); base = bucket_block(xbs->bucket, block_off); credits += ocfs2_blocks_per_xattr_bucket(inode->i_sb); } else { base = xbs->base; credits += OCFS2_XATTR_BLOCK_UPDATE_CREDITS; } } /* * delete a xattr doesn't need metadata and cluster allocation. * so just calculate the credits and return. * * The credits for removing the value tree will be extended * by ocfs2_remove_extent itself. */ if (!xi->xi_value) { if (!ocfs2_xattr_is_local(xe)) credits += ocfs2_remove_extent_credits(inode->i_sb); goto out; } /* do cluster allocation guess first. */ value_size = le64_to_cpu(xe->xe_value_size); if (old_in_xb) { /* * In xattr set, we always try to set the xe in inode first, * so if it can be inserted into inode successfully, the old * one will be removed from the xattr block, and this xattr * will be inserted into inode as a new xattr in inode. */ if (ocfs2_xattr_can_be_in_inode(inode, xi, xis)) { clusters_add += new_clusters; credits += ocfs2_remove_extent_credits(inode->i_sb) + OCFS2_INODE_UPDATE_CREDITS; if (!ocfs2_xattr_is_local(xe)) credits += ocfs2_calc_extend_credits( inode->i_sb, &def_xv.xv.xr_list, new_clusters); goto out; } } if (xi->xi_value_len > OCFS2_XATTR_INLINE_SIZE) { /* the new values will be stored outside. */ u32 old_clusters = 0; if (!ocfs2_xattr_is_local(xe)) { old_clusters = ocfs2_clusters_for_bytes(inode->i_sb, value_size); xv = (struct ocfs2_xattr_value_root *) (base + name_offset + name_len); value_size = OCFS2_XATTR_ROOT_SIZE; } else xv = &def_xv.xv; if (old_clusters >= new_clusters) { credits += ocfs2_remove_extent_credits(inode->i_sb); goto out; } else { meta_add += ocfs2_extend_meta_needed(&xv->xr_list); clusters_add += new_clusters - old_clusters; credits += ocfs2_calc_extend_credits(inode->i_sb, &xv->xr_list, new_clusters - old_clusters); if (value_size >= OCFS2_XATTR_ROOT_SIZE) goto out; } } else { /* * Now the new value will be stored inside. So if the new * value is smaller than the size of value root or the old * value, we don't need any allocation, otherwise we have * to guess metadata allocation. */ if ((ocfs2_xattr_is_local(xe) && (value_size >= xi->xi_value_len)) || (!ocfs2_xattr_is_local(xe) && OCFS2_XATTR_ROOT_SIZE >= xi->xi_value_len)) goto out; } meta_guess: /* calculate metadata allocation. */ if (di->i_xattr_loc) { if (!xbs->xattr_bh) { ret = ocfs2_read_xattr_block(inode, le64_to_cpu(di->i_xattr_loc), &bh); if (ret) { mlog_errno(ret); goto out; } xb = (struct ocfs2_xattr_block *)bh->b_data; } else xb = (struct ocfs2_xattr_block *)xbs->xattr_bh->b_data; /* * If there is already an xattr tree, good, we can calculate * like other b-trees. Otherwise we may have the chance of * create a tree, the credit calculation is borrowed from * ocfs2_calc_extend_credits with root_el = NULL. And the * new tree will be cluster based, so no meta is needed. */ if (le16_to_cpu(xb->xb_flags) & OCFS2_XATTR_INDEXED) { struct ocfs2_extent_list *el = &xb->xb_attrs.xb_root.xt_list; meta_add += ocfs2_extend_meta_needed(el); credits += ocfs2_calc_extend_credits(inode->i_sb, el, 1); } else credits += OCFS2_SUBALLOC_ALLOC + 1; /* * This cluster will be used either for new bucket or for * new xattr block. * If the cluster size is the same as the bucket size, one * more is needed since we may need to extend the bucket * also. */ clusters_add += 1; credits += ocfs2_blocks_per_xattr_bucket(inode->i_sb); if (OCFS2_XATTR_BUCKET_SIZE == OCFS2_SB(inode->i_sb)->s_clustersize) { credits += ocfs2_blocks_per_xattr_bucket(inode->i_sb); clusters_add += 1; } } else { meta_add += 1; credits += OCFS2_XATTR_BLOCK_CREATE_CREDITS; } out: if (clusters_need) *clusters_need = clusters_add; if (meta_need) *meta_need = meta_add; if (credits_need) *credits_need = credits; brelse(bh); return ret; } static int ocfs2_init_xattr_set_ctxt(struct inode *inode, struct ocfs2_dinode *di, struct ocfs2_xattr_info *xi, struct ocfs2_xattr_search *xis, struct ocfs2_xattr_search *xbs, struct ocfs2_xattr_set_ctxt *ctxt, int extra_meta, int *credits) { int clusters_add, meta_add, ret; struct ocfs2_super *osb = OCFS2_SB(inode->i_sb); memset(ctxt, 0, sizeof(struct ocfs2_xattr_set_ctxt)); ocfs2_init_dealloc_ctxt(&ctxt->dealloc); ret = ocfs2_calc_xattr_set_need(inode, di, xi, xis, xbs, &clusters_add, &meta_add, credits); if (ret) { mlog_errno(ret); return ret; } meta_add += extra_meta; trace_ocfs2_init_xattr_set_ctxt(xi->xi_name, meta_add, clusters_add, *credits); if (meta_add) { ret = ocfs2_reserve_new_metadata_blocks(osb, meta_add, &ctxt->meta_ac); if (ret) { mlog_errno(ret); goto out; } } if (clusters_add) { ret = ocfs2_reserve_clusters(osb, clusters_add, &ctxt->data_ac); if (ret) mlog_errno(ret); } out: if (ret) { if (ctxt->meta_ac) { ocfs2_free_alloc_context(ctxt->meta_ac); ctxt->meta_ac = NULL; } /* * We cannot have an error and a non null ctxt->data_ac. */ } return ret; } static int __ocfs2_xattr_set_handle(struct inode *inode, struct ocfs2_dinode *di, struct ocfs2_xattr_info *xi, struct ocfs2_xattr_search *xis, struct ocfs2_xattr_search *xbs, struct ocfs2_xattr_set_ctxt *ctxt) { int ret = 0, credits, old_found; if (!xi->xi_value) { /* Remove existing extended attribute */ if (!xis->not_found) ret = ocfs2_xattr_ibody_set(inode, xi, xis, ctxt); else if (!xbs->not_found) ret = ocfs2_xattr_block_set(inode, xi, xbs, ctxt); } else { /* We always try to set extended attribute into inode first*/ ret = ocfs2_xattr_ibody_set(inode, xi, xis, ctxt); if (!ret && !xbs->not_found) { /* * If succeed and that extended attribute existing in * external block, then we will remove it. */ xi->xi_value = NULL; xi->xi_value_len = 0; old_found = xis->not_found; xis->not_found = -ENODATA; ret = ocfs2_calc_xattr_set_need(inode, di, xi, xis, xbs, NULL, NULL, &credits); xis->not_found = old_found; if (ret) { mlog_errno(ret); goto out; } ret = ocfs2_extend_trans(ctxt->handle, credits); if (ret) { mlog_errno(ret); goto out; } ret = ocfs2_xattr_block_set(inode, xi, xbs, ctxt); } else if ((ret == -ENOSPC) && !ctxt->set_abort) { if (di->i_xattr_loc && !xbs->xattr_bh) { ret = ocfs2_xattr_block_find(inode, xi->xi_name_index, xi->xi_name, xbs); if (ret) goto out; old_found = xis->not_found; xis->not_found = -ENODATA; ret = ocfs2_calc_xattr_set_need(inode, di, xi, xis, xbs, NULL, NULL, &credits); xis->not_found = old_found; if (ret) { mlog_errno(ret); goto out; } ret = ocfs2_extend_trans(ctxt->handle, credits); if (ret) { mlog_errno(ret); goto out; } } /* * If no space in inode, we will set extended attribute * into external block. */ ret = ocfs2_xattr_block_set(inode, xi, xbs, ctxt); if (ret) goto out; if (!xis->not_found) { /* * If succeed and that extended attribute * existing in inode, we will remove it. */ xi->xi_value = NULL; xi->xi_value_len = 0; xbs->not_found = -ENODATA; ret = ocfs2_calc_xattr_set_need(inode, di, xi, xis, xbs, NULL, NULL, &credits); if (ret) { mlog_errno(ret); goto out; } ret = ocfs2_extend_trans(ctxt->handle, credits); if (ret) { mlog_errno(ret); goto out; } ret = ocfs2_xattr_ibody_set(inode, xi, xis, ctxt); } } } if (!ret) { /* Update inode ctime. */ ret = ocfs2_journal_access_di(ctxt->handle, INODE_CACHE(inode), xis->inode_bh, OCFS2_JOURNAL_ACCESS_WRITE); if (ret) { mlog_errno(ret); goto out; } inode->i_ctime = CURRENT_TIME; di->i_ctime = cpu_to_le64(inode->i_ctime.tv_sec); di->i_ctime_nsec = cpu_to_le32(inode->i_ctime.tv_nsec); ocfs2_journal_dirty(ctxt->handle, xis->inode_bh); } out: return ret; } /* * This function only called duing creating inode * for init security/acl xattrs of the new inode. * All transanction credits have been reserved in mknod. */ int ocfs2_xattr_set_handle(handle_t *handle, struct inode *inode, struct buffer_head *di_bh, int name_index, const char *name, const void *value, size_t value_len, int flags, struct ocfs2_alloc_context *meta_ac, struct ocfs2_alloc_context *data_ac) { struct ocfs2_dinode *di; int ret; struct ocfs2_xattr_info xi = { .xi_name_index = name_index, .xi_name = name, .xi_name_len = strlen(name), .xi_value = value, .xi_value_len = value_len, }; struct ocfs2_xattr_search xis = { .not_found = -ENODATA, }; struct ocfs2_xattr_search xbs = { .not_found = -ENODATA, }; struct ocfs2_xattr_set_ctxt ctxt = { .handle = handle, .meta_ac = meta_ac, .data_ac = data_ac, }; if (!ocfs2_supports_xattr(OCFS2_SB(inode->i_sb))) return -EOPNOTSUPP; /* * In extreme situation, may need xattr bucket when * block size is too small. And we have already reserved * the credits for bucket in mknod. */ if (inode->i_sb->s_blocksize == OCFS2_MIN_BLOCKSIZE) { xbs.bucket = ocfs2_xattr_bucket_new(inode); if (!xbs.bucket) { mlog_errno(-ENOMEM); return -ENOMEM; } } xis.inode_bh = xbs.inode_bh = di_bh; di = (struct ocfs2_dinode *)di_bh->b_data; down_write(&OCFS2_I(inode)->ip_xattr_sem); ret = ocfs2_xattr_ibody_find(inode, name_index, name, &xis); if (ret) goto cleanup; if (xis.not_found) { ret = ocfs2_xattr_block_find(inode, name_index, name, &xbs); if (ret) goto cleanup; } ret = __ocfs2_xattr_set_handle(inode, di, &xi, &xis, &xbs, &ctxt); cleanup: up_write(&OCFS2_I(inode)->ip_xattr_sem); brelse(xbs.xattr_bh); ocfs2_xattr_bucket_free(xbs.bucket); return ret; } /* * ocfs2_xattr_set() * * Set, replace or remove an extended attribute for this inode. * value is NULL to remove an existing extended attribute, else either * create or replace an extended attribute. */ int ocfs2_xattr_set(struct inode *inode, int name_index, const char *name, const void *value, size_t value_len, int flags) { struct buffer_head *di_bh = NULL; struct ocfs2_dinode *di; int ret, credits, ref_meta = 0, ref_credits = 0; struct ocfs2_super *osb = OCFS2_SB(inode->i_sb); struct inode *tl_inode = osb->osb_tl_inode; struct ocfs2_xattr_set_ctxt ctxt = { NULL, NULL, }; struct ocfs2_refcount_tree *ref_tree = NULL; struct ocfs2_xattr_info xi = { .xi_name_index = name_index, .xi_name = name, .xi_name_len = strlen(name), .xi_value = value, .xi_value_len = value_len, }; struct ocfs2_xattr_search xis = { .not_found = -ENODATA, }; struct ocfs2_xattr_search xbs = { .not_found = -ENODATA, }; if (!ocfs2_supports_xattr(OCFS2_SB(inode->i_sb))) return -EOPNOTSUPP; /* * Only xbs will be used on indexed trees. xis doesn't need a * bucket. */ xbs.bucket = ocfs2_xattr_bucket_new(inode); if (!xbs.bucket) { mlog_errno(-ENOMEM); return -ENOMEM; } ret = ocfs2_inode_lock(inode, &di_bh, 1); if (ret < 0) { mlog_errno(ret); goto cleanup_nolock; } xis.inode_bh = xbs.inode_bh = di_bh; di = (struct ocfs2_dinode *)di_bh->b_data; down_write(&OCFS2_I(inode)->ip_xattr_sem); /* * Scan inode and external block to find the same name * extended attribute and collect search information. */ ret = ocfs2_xattr_ibody_find(inode, name_index, name, &xis); if (ret) goto cleanup; if (xis.not_found) { ret = ocfs2_xattr_block_find(inode, name_index, name, &xbs); if (ret) goto cleanup; } if (xis.not_found && xbs.not_found) { ret = -ENODATA; if (flags & XATTR_REPLACE) goto cleanup; ret = 0; if (!value) goto cleanup; } else { ret = -EEXIST; if (flags & XATTR_CREATE) goto cleanup; } /* Check whether the value is refcounted and do some preparation. */ if (OCFS2_I(inode)->ip_dyn_features & OCFS2_HAS_REFCOUNT_FL && (!xis.not_found || !xbs.not_found)) { ret = ocfs2_prepare_refcount_xattr(inode, di, &xi, &xis, &xbs, &ref_tree, &ref_meta, &ref_credits); if (ret) { mlog_errno(ret); goto cleanup; } } mutex_lock(&tl_inode->i_mutex); if (ocfs2_truncate_log_needs_flush(osb)) { ret = __ocfs2_flush_truncate_log(osb); if (ret < 0) { mutex_unlock(&tl_inode->i_mutex); mlog_errno(ret); goto cleanup; } } mutex_unlock(&tl_inode->i_mutex); ret = ocfs2_init_xattr_set_ctxt(inode, di, &xi, &xis, &xbs, &ctxt, ref_meta, &credits); if (ret) { mlog_errno(ret); goto cleanup; } /* we need to update inode's ctime field, so add credit for it. */ credits += OCFS2_INODE_UPDATE_CREDITS; ctxt.handle = ocfs2_start_trans(osb, credits + ref_credits); if (IS_ERR(ctxt.handle)) { ret = PTR_ERR(ctxt.handle); mlog_errno(ret); goto cleanup; } ret = __ocfs2_xattr_set_handle(inode, di, &xi, &xis, &xbs, &ctxt); ocfs2_commit_trans(osb, ctxt.handle); if (ctxt.data_ac) ocfs2_free_alloc_context(ctxt.data_ac); if (ctxt.meta_ac) ocfs2_free_alloc_context(ctxt.meta_ac); if (ocfs2_dealloc_has_cluster(&ctxt.dealloc)) ocfs2_schedule_truncate_log_flush(osb, 1); ocfs2_run_deallocs(osb, &ctxt.dealloc); cleanup: if (ref_tree) ocfs2_unlock_refcount_tree(osb, ref_tree, 1); up_write(&OCFS2_I(inode)->ip_xattr_sem); if (!value && !ret) { ret = ocfs2_try_remove_refcount_tree(inode, di_bh); if (ret) mlog_errno(ret); } ocfs2_inode_unlock(inode, 1); cleanup_nolock: brelse(di_bh); brelse(xbs.xattr_bh); ocfs2_xattr_bucket_free(xbs.bucket); return ret; } /* * Find the xattr extent rec which may contains name_hash. * e_cpos will be the first name hash of the xattr rec. * el must be the ocfs2_xattr_header.xb_attrs.xb_root.xt_list. */ static int ocfs2_xattr_get_rec(struct inode *inode, u32 name_hash, u64 *p_blkno, u32 *e_cpos, u32 *num_clusters, struct ocfs2_extent_list *el) { int ret = 0, i; struct buffer_head *eb_bh = NULL; struct ocfs2_extent_block *eb; struct ocfs2_extent_rec *rec = NULL; u64 e_blkno = 0; if (el->l_tree_depth) { ret = ocfs2_find_leaf(INODE_CACHE(inode), el, name_hash, &eb_bh); if (ret) { mlog_errno(ret); goto out; } eb = (struct ocfs2_extent_block *) eb_bh->b_data; el = &eb->h_list; if (el->l_tree_depth) { ocfs2_error(inode->i_sb, "Inode %lu has non zero tree depth in " "xattr tree block %llu\n", inode->i_ino, (unsigned long long)eb_bh->b_blocknr); ret = -EROFS; goto out; } } for (i = le16_to_cpu(el->l_next_free_rec) - 1; i >= 0; i--) { rec = &el->l_recs[i]; if (le32_to_cpu(rec->e_cpos) <= name_hash) { e_blkno = le64_to_cpu(rec->e_blkno); break; } } if (!e_blkno) { ocfs2_error(inode->i_sb, "Inode %lu has bad extent " "record (%u, %u, 0) in xattr", inode->i_ino, le32_to_cpu(rec->e_cpos), ocfs2_rec_clusters(el, rec)); ret = -EROFS; goto out; } *p_blkno = le64_to_cpu(rec->e_blkno); *num_clusters = le16_to_cpu(rec->e_leaf_clusters); if (e_cpos) *e_cpos = le32_to_cpu(rec->e_cpos); out: brelse(eb_bh); return ret; } typedef int (xattr_bucket_func)(struct inode *inode, struct ocfs2_xattr_bucket *bucket, void *para); static int ocfs2_find_xe_in_bucket(struct inode *inode, struct ocfs2_xattr_bucket *bucket, int name_index, const char *name, u32 name_hash, u16 *xe_index, int *found) { int i, ret = 0, cmp = 1, block_off, new_offset; struct ocfs2_xattr_header *xh = bucket_xh(bucket); size_t name_len = strlen(name); struct ocfs2_xattr_entry *xe = NULL; char *xe_name; /* * We don't use binary search in the bucket because there * may be multiple entries with the same name hash. */ for (i = 0; i < le16_to_cpu(xh->xh_count); i++) { xe = &xh->xh_entries[i]; if (name_hash > le32_to_cpu(xe->xe_name_hash)) continue; else if (name_hash < le32_to_cpu(xe->xe_name_hash)) break; cmp = name_index - ocfs2_xattr_get_type(xe); if (!cmp) cmp = name_len - xe->xe_name_len; if (cmp) continue; ret = ocfs2_xattr_bucket_get_name_value(inode->i_sb, xh, i, &block_off, &new_offset); if (ret) { mlog_errno(ret); break; } xe_name = bucket_block(bucket, block_off) + new_offset; if (!memcmp(name, xe_name, name_len)) { *xe_index = i; *found = 1; ret = 0; break; } } return ret; } /* * Find the specified xattr entry in a series of buckets. * This series start from p_blkno and last for num_clusters. * The ocfs2_xattr_header.xh_num_buckets of the first bucket contains * the num of the valid buckets. * * Return the buffer_head this xattr should reside in. And if the xattr's * hash is in the gap of 2 buckets, return the lower bucket. */ static int ocfs2_xattr_bucket_find(struct inode *inode, int name_index, const char *name, u32 name_hash, u64 p_blkno, u32 first_hash, u32 num_clusters, struct ocfs2_xattr_search *xs) { int ret, found = 0; struct ocfs2_xattr_header *xh = NULL; struct ocfs2_xattr_entry *xe = NULL; u16 index = 0; u16 blk_per_bucket = ocfs2_blocks_per_xattr_bucket(inode->i_sb); int low_bucket = 0, bucket, high_bucket; struct ocfs2_xattr_bucket *search; u32 last_hash; u64 blkno, lower_blkno = 0; search = ocfs2_xattr_bucket_new(inode); if (!search) { ret = -ENOMEM; mlog_errno(ret); goto out; } ret = ocfs2_read_xattr_bucket(search, p_blkno); if (ret) { mlog_errno(ret); goto out; } xh = bucket_xh(search); high_bucket = le16_to_cpu(xh->xh_num_buckets) - 1; while (low_bucket <= high_bucket) { ocfs2_xattr_bucket_relse(search); bucket = (low_bucket + high_bucket) / 2; blkno = p_blkno + bucket * blk_per_bucket; ret = ocfs2_read_xattr_bucket(search, blkno); if (ret) { mlog_errno(ret); goto out; } xh = bucket_xh(search); xe = &xh->xh_entries[0]; if (name_hash < le32_to_cpu(xe->xe_name_hash)) { high_bucket = bucket - 1; continue; } /* * Check whether the hash of the last entry in our * bucket is larger than the search one. for an empty * bucket, the last one is also the first one. */ if (xh->xh_count) xe = &xh->xh_entries[le16_to_cpu(xh->xh_count) - 1]; last_hash = le32_to_cpu(xe->xe_name_hash); /* record lower_blkno which may be the insert place. */ lower_blkno = blkno; if (name_hash > le32_to_cpu(xe->xe_name_hash)) { low_bucket = bucket + 1; continue; } /* the searched xattr should reside in this bucket if exists. */ ret = ocfs2_find_xe_in_bucket(inode, search, name_index, name, name_hash, &index, &found); if (ret) { mlog_errno(ret); goto out; } break; } /* * Record the bucket we have found. * When the xattr's hash value is in the gap of 2 buckets, we will * always set it to the previous bucket. */ if (!lower_blkno) lower_blkno = p_blkno; /* This should be in cache - we just read it during the search */ ret = ocfs2_read_xattr_bucket(xs->bucket, lower_blkno); if (ret) { mlog_errno(ret); goto out; } xs->header = bucket_xh(xs->bucket); xs->base = bucket_block(xs->bucket, 0); xs->end = xs->base + inode->i_sb->s_blocksize; if (found) { xs->here = &xs->header->xh_entries[index]; trace_ocfs2_xattr_bucket_find(OCFS2_I(inode)->ip_blkno, name, name_index, name_hash, (unsigned long long)bucket_blkno(xs->bucket), index); } else ret = -ENODATA; out: ocfs2_xattr_bucket_free(search); return ret; } static int ocfs2_xattr_index_block_find(struct inode *inode, struct buffer_head *root_bh, int name_index, const char *name, struct ocfs2_xattr_search *xs) { int ret; struct ocfs2_xattr_block *xb = (struct ocfs2_xattr_block *)root_bh->b_data; struct ocfs2_xattr_tree_root *xb_root = &xb->xb_attrs.xb_root; struct ocfs2_extent_list *el = &xb_root->xt_list; u64 p_blkno = 0; u32 first_hash, num_clusters = 0; u32 name_hash = ocfs2_xattr_name_hash(inode, name, strlen(name)); if (le16_to_cpu(el->l_next_free_rec) == 0) return -ENODATA; trace_ocfs2_xattr_index_block_find(OCFS2_I(inode)->ip_blkno, name, name_index, name_hash, (unsigned long long)root_bh->b_blocknr, -1); ret = ocfs2_xattr_get_rec(inode, name_hash, &p_blkno, &first_hash, &num_clusters, el); if (ret) { mlog_errno(ret); goto out; } BUG_ON(p_blkno == 0 || num_clusters == 0 || first_hash > name_hash); trace_ocfs2_xattr_index_block_find_rec(OCFS2_I(inode)->ip_blkno, name, name_index, first_hash, (unsigned long long)p_blkno, num_clusters); ret = ocfs2_xattr_bucket_find(inode, name_index, name, name_hash, p_blkno, first_hash, num_clusters, xs); out: return ret; } static int ocfs2_iterate_xattr_buckets(struct inode *inode, u64 blkno, u32 clusters, xattr_bucket_func *func, void *para) { int i, ret = 0; u32 bpc = ocfs2_xattr_buckets_per_cluster(OCFS2_SB(inode->i_sb)); u32 num_buckets = clusters * bpc; struct ocfs2_xattr_bucket *bucket; bucket = ocfs2_xattr_bucket_new(inode); if (!bucket) { mlog_errno(-ENOMEM); return -ENOMEM; } trace_ocfs2_iterate_xattr_buckets( (unsigned long long)OCFS2_I(inode)->ip_blkno, (unsigned long long)blkno, clusters); for (i = 0; i < num_buckets; i++, blkno += bucket->bu_blocks) { ret = ocfs2_read_xattr_bucket(bucket, blkno); if (ret) { mlog_errno(ret); break; } /* * The real bucket num in this series of blocks is stored * in the 1st bucket. */ if (i == 0) num_buckets = le16_to_cpu(bucket_xh(bucket)->xh_num_buckets); trace_ocfs2_iterate_xattr_bucket((unsigned long long)blkno, le32_to_cpu(bucket_xh(bucket)->xh_entries[0].xe_name_hash)); if (func) { ret = func(inode, bucket, para); if (ret && ret != -ERANGE) mlog_errno(ret); /* Fall through to bucket_relse() */ } ocfs2_xattr_bucket_relse(bucket); if (ret) break; } ocfs2_xattr_bucket_free(bucket); return ret; } struct ocfs2_xattr_tree_list { char *buffer; size_t buffer_size; size_t result; }; static int ocfs2_xattr_bucket_get_name_value(struct super_block *sb, struct ocfs2_xattr_header *xh, int index, int *block_off, int *new_offset) { u16 name_offset; if (index < 0 || index >= le16_to_cpu(xh->xh_count)) return -EINVAL; name_offset = le16_to_cpu(xh->xh_entries[index].xe_name_offset); *block_off = name_offset >> sb->s_blocksize_bits; *new_offset = name_offset % sb->s_blocksize; return 0; } static int ocfs2_list_xattr_bucket(struct inode *inode, struct ocfs2_xattr_bucket *bucket, void *para) { int ret = 0, type; struct ocfs2_xattr_tree_list *xl = (struct ocfs2_xattr_tree_list *)para; int i, block_off, new_offset; const char *prefix, *name; for (i = 0 ; i < le16_to_cpu(bucket_xh(bucket)->xh_count); i++) { struct ocfs2_xattr_entry *entry = &bucket_xh(bucket)->xh_entries[i]; type = ocfs2_xattr_get_type(entry); prefix = ocfs2_xattr_prefix(type); if (prefix) { ret = ocfs2_xattr_bucket_get_name_value(inode->i_sb, bucket_xh(bucket), i, &block_off, &new_offset); if (ret) break; name = (const char *)bucket_block(bucket, block_off) + new_offset; ret = ocfs2_xattr_list_entry(xl->buffer, xl->buffer_size, &xl->result, prefix, name, entry->xe_name_len); if (ret) break; } } return ret; } static int ocfs2_iterate_xattr_index_block(struct inode *inode, struct buffer_head *blk_bh, xattr_tree_rec_func *rec_func, void *para) { struct ocfs2_xattr_block *xb = (struct ocfs2_xattr_block *)blk_bh->b_data; struct ocfs2_extent_list *el = &xb->xb_attrs.xb_root.xt_list; int ret = 0; u32 name_hash = UINT_MAX, e_cpos = 0, num_clusters = 0; u64 p_blkno = 0; if (!el->l_next_free_rec || !rec_func) return 0; while (name_hash > 0) { ret = ocfs2_xattr_get_rec(inode, name_hash, &p_blkno, &e_cpos, &num_clusters, el); if (ret) { mlog_errno(ret); break; } ret = rec_func(inode, blk_bh, p_blkno, e_cpos, num_clusters, para); if (ret) { if (ret != -ERANGE) mlog_errno(ret); break; } if (e_cpos == 0) break; name_hash = e_cpos - 1; } return ret; } static int ocfs2_list_xattr_tree_rec(struct inode *inode, struct buffer_head *root_bh, u64 blkno, u32 cpos, u32 len, void *para) { return ocfs2_iterate_xattr_buckets(inode, blkno, len, ocfs2_list_xattr_bucket, para); } static int ocfs2_xattr_tree_list_index_block(struct inode *inode, struct buffer_head *blk_bh, char *buffer, size_t buffer_size) { int ret; struct ocfs2_xattr_tree_list xl = { .buffer = buffer, .buffer_size = buffer_size, .result = 0, }; ret = ocfs2_iterate_xattr_index_block(inode, blk_bh, ocfs2_list_xattr_tree_rec, &xl); if (ret) { mlog_errno(ret); goto out; } ret = xl.result; out: return ret; } static int cmp_xe(const void *a, const void *b) { const struct ocfs2_xattr_entry *l = a, *r = b; u32 l_hash = le32_to_cpu(l->xe_name_hash); u32 r_hash = le32_to_cpu(r->xe_name_hash); if (l_hash > r_hash) return 1; if (l_hash < r_hash) return -1; return 0; } static void swap_xe(void *a, void *b, int size) { struct ocfs2_xattr_entry *l = a, *r = b, tmp; tmp = *l; memcpy(l, r, sizeof(struct ocfs2_xattr_entry)); memcpy(r, &tmp, sizeof(struct ocfs2_xattr_entry)); } /* * When the ocfs2_xattr_block is filled up, new bucket will be created * and all the xattr entries will be moved to the new bucket. * The header goes at the start of the bucket, and the names+values are * filled from the end. This is why *target starts as the last buffer. * Note: we need to sort the entries since they are not saved in order * in the ocfs2_xattr_block. */ static void ocfs2_cp_xattr_block_to_bucket(struct inode *inode, struct buffer_head *xb_bh, struct ocfs2_xattr_bucket *bucket) { int i, blocksize = inode->i_sb->s_blocksize; int blks = ocfs2_blocks_per_xattr_bucket(inode->i_sb); u16 offset, size, off_change; struct ocfs2_xattr_entry *xe; struct ocfs2_xattr_block *xb = (struct ocfs2_xattr_block *)xb_bh->b_data; struct ocfs2_xattr_header *xb_xh = &xb->xb_attrs.xb_header; struct ocfs2_xattr_header *xh = bucket_xh(bucket); u16 count = le16_to_cpu(xb_xh->xh_count); char *src = xb_bh->b_data; char *target = bucket_block(bucket, blks - 1); trace_ocfs2_cp_xattr_block_to_bucket_begin( (unsigned long long)xb_bh->b_blocknr, (unsigned long long)bucket_blkno(bucket)); for (i = 0; i < blks; i++) memset(bucket_block(bucket, i), 0, blocksize); /* * Since the xe_name_offset is based on ocfs2_xattr_header, * there is a offset change corresponding to the change of * ocfs2_xattr_header's position. */ off_change = offsetof(struct ocfs2_xattr_block, xb_attrs.xb_header); xe = &xb_xh->xh_entries[count - 1]; offset = le16_to_cpu(xe->xe_name_offset) + off_change; size = blocksize - offset; /* copy all the names and values. */ memcpy(target + offset, src + offset, size); /* Init new header now. */ xh->xh_count = xb_xh->xh_count; xh->xh_num_buckets = cpu_to_le16(1); xh->xh_name_value_len = cpu_to_le16(size); xh->xh_free_start = cpu_to_le16(OCFS2_XATTR_BUCKET_SIZE - size); /* copy all the entries. */ target = bucket_block(bucket, 0); offset = offsetof(struct ocfs2_xattr_header, xh_entries); size = count * sizeof(struct ocfs2_xattr_entry); memcpy(target + offset, (char *)xb_xh + offset, size); /* Change the xe offset for all the xe because of the move. */ off_change = OCFS2_XATTR_BUCKET_SIZE - blocksize + offsetof(struct ocfs2_xattr_block, xb_attrs.xb_header); for (i = 0; i < count; i++) le16_add_cpu(&xh->xh_entries[i].xe_name_offset, off_change); trace_ocfs2_cp_xattr_block_to_bucket_end(offset, size, off_change); sort(target + offset, count, sizeof(struct ocfs2_xattr_entry), cmp_xe, swap_xe); } /* * After we move xattr from block to index btree, we have to * update ocfs2_xattr_search to the new xe and base. * * When the entry is in xattr block, xattr_bh indicates the storage place. * While if the entry is in index b-tree, "bucket" indicates the * real place of the xattr. */ static void ocfs2_xattr_update_xattr_search(struct inode *inode, struct ocfs2_xattr_search *xs, struct buffer_head *old_bh) { char *buf = old_bh->b_data; struct ocfs2_xattr_block *old_xb = (struct ocfs2_xattr_block *)buf; struct ocfs2_xattr_header *old_xh = &old_xb->xb_attrs.xb_header; int i; xs->header = bucket_xh(xs->bucket); xs->base = bucket_block(xs->bucket, 0); xs->end = xs->base + inode->i_sb->s_blocksize; if (xs->not_found) return; i = xs->here - old_xh->xh_entries; xs->here = &xs->header->xh_entries[i]; } static int ocfs2_xattr_create_index_block(struct inode *inode, struct ocfs2_xattr_search *xs, struct ocfs2_xattr_set_ctxt *ctxt) { int ret; u32 bit_off, len; u64 blkno; handle_t *handle = ctxt->handle; struct ocfs2_inode_info *oi = OCFS2_I(inode); struct buffer_head *xb_bh = xs->xattr_bh; struct ocfs2_xattr_block *xb = (struct ocfs2_xattr_block *)xb_bh->b_data; struct ocfs2_xattr_tree_root *xr; u16 xb_flags = le16_to_cpu(xb->xb_flags); trace_ocfs2_xattr_create_index_block_begin( (unsigned long long)xb_bh->b_blocknr); BUG_ON(xb_flags & OCFS2_XATTR_INDEXED); BUG_ON(!xs->bucket); /* * XXX: * We can use this lock for now, and maybe move to a dedicated mutex * if performance becomes a problem later. */ down_write(&oi->ip_alloc_sem); ret = ocfs2_journal_access_xb(handle, INODE_CACHE(inode), xb_bh, OCFS2_JOURNAL_ACCESS_WRITE); if (ret) { mlog_errno(ret); goto out; } ret = __ocfs2_claim_clusters(handle, ctxt->data_ac, 1, 1, &bit_off, &len); if (ret) { mlog_errno(ret); goto out; } /* * The bucket may spread in many blocks, and * we will only touch the 1st block and the last block * in the whole bucket(one for entry and one for data). */ blkno = ocfs2_clusters_to_blocks(inode->i_sb, bit_off); trace_ocfs2_xattr_create_index_block((unsigned long long)blkno); ret = ocfs2_init_xattr_bucket(xs->bucket, blkno); if (ret) { mlog_errno(ret); goto out; } ret = ocfs2_xattr_bucket_journal_access(handle, xs->bucket, OCFS2_JOURNAL_ACCESS_CREATE); if (ret) { mlog_errno(ret); goto out; } ocfs2_cp_xattr_block_to_bucket(inode, xb_bh, xs->bucket); ocfs2_xattr_bucket_journal_dirty(handle, xs->bucket); ocfs2_xattr_update_xattr_search(inode, xs, xb_bh); /* Change from ocfs2_xattr_header to ocfs2_xattr_tree_root */ memset(&xb->xb_attrs, 0, inode->i_sb->s_blocksize - offsetof(struct ocfs2_xattr_block, xb_attrs)); xr = &xb->xb_attrs.xb_root; xr->xt_clusters = cpu_to_le32(1); xr->xt_last_eb_blk = 0; xr->xt_list.l_tree_depth = 0; xr->xt_list.l_count = cpu_to_le16(ocfs2_xattr_recs_per_xb(inode->i_sb)); xr->xt_list.l_next_free_rec = cpu_to_le16(1); xr->xt_list.l_recs[0].e_cpos = 0; xr->xt_list.l_recs[0].e_blkno = cpu_to_le64(blkno); xr->xt_list.l_recs[0].e_leaf_clusters = cpu_to_le16(1); xb->xb_flags = cpu_to_le16(xb_flags | OCFS2_XATTR_INDEXED); ocfs2_journal_dirty(handle, xb_bh); out: up_write(&oi->ip_alloc_sem); return ret; } static int cmp_xe_offset(const void *a, const void *b) { const struct ocfs2_xattr_entry *l = a, *r = b; u32 l_name_offset = le16_to_cpu(l->xe_name_offset); u32 r_name_offset = le16_to_cpu(r->xe_name_offset); if (l_name_offset < r_name_offset) return 1; if (l_name_offset > r_name_offset) return -1; return 0; } /* * defrag a xattr bucket if we find that the bucket has some * holes beteen name/value pairs. * We will move all the name/value pairs to the end of the bucket * so that we can spare some space for insertion. */ static int ocfs2_defrag_xattr_bucket(struct inode *inode, handle_t *handle, struct ocfs2_xattr_bucket *bucket) { int ret, i; size_t end, offset, len; struct ocfs2_xattr_header *xh; char *entries, *buf, *bucket_buf = NULL; u64 blkno = bucket_blkno(bucket); u16 xh_free_start; size_t blocksize = inode->i_sb->s_blocksize; struct ocfs2_xattr_entry *xe; /* * In order to make the operation more efficient and generic, * we copy all the blocks into a contiguous memory and do the * defragment there, so if anything is error, we will not touch * the real block. */ bucket_buf = kmalloc(OCFS2_XATTR_BUCKET_SIZE, GFP_NOFS); if (!bucket_buf) { ret = -EIO; goto out; } buf = bucket_buf; for (i = 0; i < bucket->bu_blocks; i++, buf += blocksize) memcpy(buf, bucket_block(bucket, i), blocksize); ret = ocfs2_xattr_bucket_journal_access(handle, bucket, OCFS2_JOURNAL_ACCESS_WRITE); if (ret < 0) { mlog_errno(ret); goto out; } xh = (struct ocfs2_xattr_header *)bucket_buf; entries = (char *)xh->xh_entries; xh_free_start = le16_to_cpu(xh->xh_free_start); trace_ocfs2_defrag_xattr_bucket( (unsigned long long)blkno, le16_to_cpu(xh->xh_count), xh_free_start, le16_to_cpu(xh->xh_name_value_len)); /* * sort all the entries by their offset. * the largest will be the first, so that we can * move them to the end one by one. */ sort(entries, le16_to_cpu(xh->xh_count), sizeof(struct ocfs2_xattr_entry), cmp_xe_offset, swap_xe); /* Move all name/values to the end of the bucket. */ xe = xh->xh_entries; end = OCFS2_XATTR_BUCKET_SIZE; for (i = 0; i < le16_to_cpu(xh->xh_count); i++, xe++) { offset = le16_to_cpu(xe->xe_name_offset); len = namevalue_size_xe(xe); /* * We must make sure that the name/value pair * exist in the same block. So adjust end to * the previous block end if needed. */ if (((end - len) / blocksize != (end - 1) / blocksize)) end = end - end % blocksize; if (end > offset + len) { memmove(bucket_buf + end - len, bucket_buf + offset, len); xe->xe_name_offset = cpu_to_le16(end - len); } mlog_bug_on_msg(end < offset + len, "Defrag check failed for " "bucket %llu\n", (unsigned long long)blkno); end -= len; } mlog_bug_on_msg(xh_free_start > end, "Defrag check failed for " "bucket %llu\n", (unsigned long long)blkno); if (xh_free_start == end) goto out; memset(bucket_buf + xh_free_start, 0, end - xh_free_start); xh->xh_free_start = cpu_to_le16(end); /* sort the entries by their name_hash. */ sort(entries, le16_to_cpu(xh->xh_count), sizeof(struct ocfs2_xattr_entry), cmp_xe, swap_xe); buf = bucket_buf; for (i = 0; i < bucket->bu_blocks; i++, buf += blocksize) memcpy(bucket_block(bucket, i), buf, blocksize); ocfs2_xattr_bucket_journal_dirty(handle, bucket); out: kfree(bucket_buf); return ret; } /* * prev_blkno points to the start of an existing extent. new_blkno * points to a newly allocated extent. Because we know each of our * clusters contains more than bucket, we can easily split one cluster * at a bucket boundary. So we take the last cluster of the existing * extent and split it down the middle. We move the last half of the * buckets in the last cluster of the existing extent over to the new * extent. * * first_bh is the buffer at prev_blkno so we can update the existing * extent's bucket count. header_bh is the bucket were we were hoping * to insert our xattr. If the bucket move places the target in the new * extent, we'll update first_bh and header_bh after modifying the old * extent. * * first_hash will be set as the 1st xe's name_hash in the new extent. */ static int ocfs2_mv_xattr_bucket_cross_cluster(struct inode *inode, handle_t *handle, struct ocfs2_xattr_bucket *first, struct ocfs2_xattr_bucket *target, u64 new_blkno, u32 num_clusters, u32 *first_hash) { int ret; struct super_block *sb = inode->i_sb; int blks_per_bucket = ocfs2_blocks_per_xattr_bucket(sb); int num_buckets = ocfs2_xattr_buckets_per_cluster(OCFS2_SB(sb)); int to_move = num_buckets / 2; u64 src_blkno; u64 last_cluster_blkno = bucket_blkno(first) + ((num_clusters - 1) * ocfs2_clusters_to_blocks(sb, 1)); BUG_ON(le16_to_cpu(bucket_xh(first)->xh_num_buckets) < num_buckets); BUG_ON(OCFS2_XATTR_BUCKET_SIZE == OCFS2_SB(sb)->s_clustersize); trace_ocfs2_mv_xattr_bucket_cross_cluster( (unsigned long long)last_cluster_blkno, (unsigned long long)new_blkno); ret = ocfs2_mv_xattr_buckets(inode, handle, bucket_blkno(first), last_cluster_blkno, new_blkno, to_move, first_hash); if (ret) { mlog_errno(ret); goto out; } /* This is the first bucket that got moved */ src_blkno = last_cluster_blkno + (to_move * blks_per_bucket); /* * If the target bucket was part of the moved buckets, we need to * update first and target. */ if (bucket_blkno(target) >= src_blkno) { /* Find the block for the new target bucket */ src_blkno = new_blkno + (bucket_blkno(target) - src_blkno); ocfs2_xattr_bucket_relse(first); ocfs2_xattr_bucket_relse(target); /* * These shouldn't fail - the buffers are in the * journal from ocfs2_cp_xattr_bucket(). */ ret = ocfs2_read_xattr_bucket(first, new_blkno); if (ret) { mlog_errno(ret); goto out; } ret = ocfs2_read_xattr_bucket(target, src_blkno); if (ret) mlog_errno(ret); } out: return ret; } /* * Find the suitable pos when we divide a bucket into 2. * We have to make sure the xattrs with the same hash value exist * in the same bucket. * * If this ocfs2_xattr_header covers more than one hash value, find a * place where the hash value changes. Try to find the most even split. * The most common case is that all entries have different hash values, * and the first check we make will find a place to split. */ static int ocfs2_xattr_find_divide_pos(struct ocfs2_xattr_header *xh) { struct ocfs2_xattr_entry *entries = xh->xh_entries; int count = le16_to_cpu(xh->xh_count); int delta, middle = count / 2; /* * We start at the middle. Each step gets farther away in both * directions. We therefore hit the change in hash value * nearest to the middle. Note that this loop does not execute for * count < 2. */ for (delta = 0; delta < middle; delta++) { /* Let's check delta earlier than middle */ if (cmp_xe(&entries[middle - delta - 1], &entries[middle - delta])) return middle - delta; /* For even counts, don't walk off the end */ if ((middle + delta + 1) == count) continue; /* Now try delta past middle */ if (cmp_xe(&entries[middle + delta], &entries[middle + delta + 1])) return middle + delta + 1; } /* Every entry had the same hash */ return count; } /* * Move some xattrs in old bucket(blk) to new bucket(new_blk). * first_hash will record the 1st hash of the new bucket. * * Normally half of the xattrs will be moved. But we have to make * sure that the xattrs with the same hash value are stored in the * same bucket. If all the xattrs in this bucket have the same hash * value, the new bucket will be initialized as an empty one and the * first_hash will be initialized as (hash_value+1). */ static int ocfs2_divide_xattr_bucket(struct inode *inode, handle_t *handle, u64 blk, u64 new_blk, u32 *first_hash, int new_bucket_head) { int ret, i; int count, start, len, name_value_len = 0, name_offset = 0; struct ocfs2_xattr_bucket *s_bucket = NULL, *t_bucket = NULL; struct ocfs2_xattr_header *xh; struct ocfs2_xattr_entry *xe; int blocksize = inode->i_sb->s_blocksize; trace_ocfs2_divide_xattr_bucket_begin((unsigned long long)blk, (unsigned long long)new_blk); s_bucket = ocfs2_xattr_bucket_new(inode); t_bucket = ocfs2_xattr_bucket_new(inode); if (!s_bucket || !t_bucket) { ret = -ENOMEM; mlog_errno(ret); goto out; } ret = ocfs2_read_xattr_bucket(s_bucket, blk); if (ret) { mlog_errno(ret); goto out; } ret = ocfs2_xattr_bucket_journal_access(handle, s_bucket, OCFS2_JOURNAL_ACCESS_WRITE); if (ret) { mlog_errno(ret); goto out; } /* * Even if !new_bucket_head, we're overwriting t_bucket. Thus, * there's no need to read it. */ ret = ocfs2_init_xattr_bucket(t_bucket, new_blk); if (ret) { mlog_errno(ret); goto out; } /* * Hey, if we're overwriting t_bucket, what difference does * ACCESS_CREATE vs ACCESS_WRITE make? See the comment in the * same part of ocfs2_cp_xattr_bucket(). */ ret = ocfs2_xattr_bucket_journal_access(handle, t_bucket, new_bucket_head ? OCFS2_JOURNAL_ACCESS_CREATE : OCFS2_JOURNAL_ACCESS_WRITE); if (ret) { mlog_errno(ret); goto out; } xh = bucket_xh(s_bucket); count = le16_to_cpu(xh->xh_count); start = ocfs2_xattr_find_divide_pos(xh); if (start == count) { xe = &xh->xh_entries[start-1]; /* * initialized a new empty bucket here. * The hash value is set as one larger than * that of the last entry in the previous bucket. */ for (i = 0; i < t_bucket->bu_blocks; i++) memset(bucket_block(t_bucket, i), 0, blocksize); xh = bucket_xh(t_bucket); xh->xh_free_start = cpu_to_le16(blocksize); xh->xh_entries[0].xe_name_hash = xe->xe_name_hash; le32_add_cpu(&xh->xh_entries[0].xe_name_hash, 1); goto set_num_buckets; } /* copy the whole bucket to the new first. */ ocfs2_xattr_bucket_copy_data(t_bucket, s_bucket); /* update the new bucket. */ xh = bucket_xh(t_bucket); /* * Calculate the total name/value len and xh_free_start for * the old bucket first. */ name_offset = OCFS2_XATTR_BUCKET_SIZE; name_value_len = 0; for (i = 0; i < start; i++) { xe = &xh->xh_entries[i]; name_value_len += namevalue_size_xe(xe); if (le16_to_cpu(xe->xe_name_offset) < name_offset) name_offset = le16_to_cpu(xe->xe_name_offset); } /* * Now begin the modification to the new bucket. * * In the new bucket, We just move the xattr entry to the beginning * and don't touch the name/value. So there will be some holes in the * bucket, and they will be removed when ocfs2_defrag_xattr_bucket is * called. */ xe = &xh->xh_entries[start]; len = sizeof(struct ocfs2_xattr_entry) * (count - start); trace_ocfs2_divide_xattr_bucket_move(len, (int)((char *)xe - (char *)xh), (int)((char *)xh->xh_entries - (char *)xh)); memmove((char *)xh->xh_entries, (char *)xe, len); xe = &xh->xh_entries[count - start]; len = sizeof(struct ocfs2_xattr_entry) * start; memset((char *)xe, 0, len); le16_add_cpu(&xh->xh_count, -start); le16_add_cpu(&xh->xh_name_value_len, -name_value_len); /* Calculate xh_free_start for the new bucket. */ xh->xh_free_start = cpu_to_le16(OCFS2_XATTR_BUCKET_SIZE); for (i = 0; i < le16_to_cpu(xh->xh_count); i++) { xe = &xh->xh_entries[i]; if (le16_to_cpu(xe->xe_name_offset) < le16_to_cpu(xh->xh_free_start)) xh->xh_free_start = xe->xe_name_offset; } set_num_buckets: /* set xh->xh_num_buckets for the new xh. */ if (new_bucket_head) xh->xh_num_buckets = cpu_to_le16(1); else xh->xh_num_buckets = 0; ocfs2_xattr_bucket_journal_dirty(handle, t_bucket); /* store the first_hash of the new bucket. */ if (first_hash) *first_hash = le32_to_cpu(xh->xh_entries[0].xe_name_hash); /* * Now only update the 1st block of the old bucket. If we * just added a new empty bucket, there is no need to modify * it. */ if (start == count) goto out; xh = bucket_xh(s_bucket); memset(&xh->xh_entries[start], 0, sizeof(struct ocfs2_xattr_entry) * (count - start)); xh->xh_count = cpu_to_le16(start); xh->xh_free_start = cpu_to_le16(name_offset); xh->xh_name_value_len = cpu_to_le16(name_value_len); ocfs2_xattr_bucket_journal_dirty(handle, s_bucket); out: ocfs2_xattr_bucket_free(s_bucket); ocfs2_xattr_bucket_free(t_bucket); return ret; } /* * Copy xattr from one bucket to another bucket. * * The caller must make sure that the journal transaction * has enough space for journaling. */ static int ocfs2_cp_xattr_bucket(struct inode *inode, handle_t *handle, u64 s_blkno, u64 t_blkno, int t_is_new) { int ret; struct ocfs2_xattr_bucket *s_bucket = NULL, *t_bucket = NULL; BUG_ON(s_blkno == t_blkno); trace_ocfs2_cp_xattr_bucket((unsigned long long)s_blkno, (unsigned long long)t_blkno, t_is_new); s_bucket = ocfs2_xattr_bucket_new(inode); t_bucket = ocfs2_xattr_bucket_new(inode); if (!s_bucket || !t_bucket) { ret = -ENOMEM; mlog_errno(ret); goto out; } ret = ocfs2_read_xattr_bucket(s_bucket, s_blkno); if (ret) goto out; /* * Even if !t_is_new, we're overwriting t_bucket. Thus, * there's no need to read it. */ ret = ocfs2_init_xattr_bucket(t_bucket, t_blkno); if (ret) goto out; /* * Hey, if we're overwriting t_bucket, what difference does * ACCESS_CREATE vs ACCESS_WRITE make? Well, if we allocated a new * cluster to fill, we came here from * ocfs2_mv_xattr_buckets(), and it is really new - * ACCESS_CREATE is required. But we also might have moved data * out of t_bucket before extending back into it. * ocfs2_add_new_xattr_bucket() can do this - its call to * ocfs2_add_new_xattr_cluster() may have created a new extent * and copied out the end of the old extent. Then it re-extends * the old extent back to create space for new xattrs. That's * how we get here, and the bucket isn't really new. */ ret = ocfs2_xattr_bucket_journal_access(handle, t_bucket, t_is_new ? OCFS2_JOURNAL_ACCESS_CREATE : OCFS2_JOURNAL_ACCESS_WRITE); if (ret) goto out; ocfs2_xattr_bucket_copy_data(t_bucket, s_bucket); ocfs2_xattr_bucket_journal_dirty(handle, t_bucket); out: ocfs2_xattr_bucket_free(t_bucket); ocfs2_xattr_bucket_free(s_bucket); return ret; } /* * src_blk points to the start of an existing extent. last_blk points to * last cluster in that extent. to_blk points to a newly allocated * extent. We copy the buckets from the cluster at last_blk to the new * extent. If start_bucket is non-zero, we skip that many buckets before * we start copying. The new extent's xh_num_buckets gets set to the * number of buckets we copied. The old extent's xh_num_buckets shrinks * by the same amount. */ static int ocfs2_mv_xattr_buckets(struct inode *inode, handle_t *handle, u64 src_blk, u64 last_blk, u64 to_blk, unsigned int start_bucket, u32 *first_hash) { int i, ret, credits; struct ocfs2_super *osb = OCFS2_SB(inode->i_sb); int blks_per_bucket = ocfs2_blocks_per_xattr_bucket(inode->i_sb); int num_buckets = ocfs2_xattr_buckets_per_cluster(osb); struct ocfs2_xattr_bucket *old_first, *new_first; trace_ocfs2_mv_xattr_buckets((unsigned long long)last_blk, (unsigned long long)to_blk); BUG_ON(start_bucket >= num_buckets); if (start_bucket) { num_buckets -= start_bucket; last_blk += (start_bucket * blks_per_bucket); } /* The first bucket of the original extent */ old_first = ocfs2_xattr_bucket_new(inode); /* The first bucket of the new extent */ new_first = ocfs2_xattr_bucket_new(inode); if (!old_first || !new_first) { ret = -ENOMEM; mlog_errno(ret); goto out; } ret = ocfs2_read_xattr_bucket(old_first, src_blk); if (ret) { mlog_errno(ret); goto out; } /* * We need to update the first bucket of the old extent and all * the buckets going to the new extent. */ credits = ((num_buckets + 1) * blks_per_bucket); ret = ocfs2_extend_trans(handle, credits); if (ret) { mlog_errno(ret); goto out; } ret = ocfs2_xattr_bucket_journal_access(handle, old_first, OCFS2_JOURNAL_ACCESS_WRITE); if (ret) { mlog_errno(ret); goto out; } for (i = 0; i < num_buckets; i++) { ret = ocfs2_cp_xattr_bucket(inode, handle, last_blk + (i * blks_per_bucket), to_blk + (i * blks_per_bucket), 1); if (ret) { mlog_errno(ret); goto out; } } /* * Get the new bucket ready before we dirty anything * (This actually shouldn't fail, because we already dirtied * it once in ocfs2_cp_xattr_bucket()). */ ret = ocfs2_read_xattr_bucket(new_first, to_blk); if (ret) { mlog_errno(ret); goto out; } ret = ocfs2_xattr_bucket_journal_access(handle, new_first, OCFS2_JOURNAL_ACCESS_WRITE); if (ret) { mlog_errno(ret); goto out; } /* Now update the headers */ le16_add_cpu(&bucket_xh(old_first)->xh_num_buckets, -num_buckets); ocfs2_xattr_bucket_journal_dirty(handle, old_first); bucket_xh(new_first)->xh_num_buckets = cpu_to_le16(num_buckets); ocfs2_xattr_bucket_journal_dirty(handle, new_first); if (first_hash) *first_hash = le32_to_cpu(bucket_xh(new_first)->xh_entries[0].xe_name_hash); out: ocfs2_xattr_bucket_free(new_first); ocfs2_xattr_bucket_free(old_first); return ret; } /* * Move some xattrs in this cluster to the new cluster. * This function should only be called when bucket size == cluster size. * Otherwise ocfs2_mv_xattr_bucket_cross_cluster should be used instead. */ static int ocfs2_divide_xattr_cluster(struct inode *inode, handle_t *handle, u64 prev_blk, u64 new_blk, u32 *first_hash) { u16 blk_per_bucket = ocfs2_blocks_per_xattr_bucket(inode->i_sb); int ret, credits = 2 * blk_per_bucket; BUG_ON(OCFS2_XATTR_BUCKET_SIZE < OCFS2_SB(inode->i_sb)->s_clustersize); ret = ocfs2_extend_trans(handle, credits); if (ret) { mlog_errno(ret); return ret; } /* Move half of the xattr in start_blk to the next bucket. */ return ocfs2_divide_xattr_bucket(inode, handle, prev_blk, new_blk, first_hash, 1); } /* * Move some xattrs from the old cluster to the new one since they are not * contiguous in ocfs2 xattr tree. * * new_blk starts a new separate cluster, and we will move some xattrs from * prev_blk to it. v_start will be set as the first name hash value in this * new cluster so that it can be used as e_cpos during tree insertion and * don't collide with our original b-tree operations. first_bh and header_bh * will also be updated since they will be used in ocfs2_extend_xattr_bucket * to extend the insert bucket. * * The problem is how much xattr should we move to the new one and when should * we update first_bh and header_bh? * 1. If cluster size > bucket size, that means the previous cluster has more * than 1 bucket, so just move half nums of bucket into the new cluster and * update the first_bh and header_bh if the insert bucket has been moved * to the new cluster. * 2. If cluster_size == bucket_size: * a) If the previous extent rec has more than one cluster and the insert * place isn't in the last cluster, copy the entire last cluster to the * new one. This time, we don't need to upate the first_bh and header_bh * since they will not be moved into the new cluster. * b) Otherwise, move the bottom half of the xattrs in the last cluster into * the new one. And we set the extend flag to zero if the insert place is * moved into the new allocated cluster since no extend is needed. */ static int ocfs2_adjust_xattr_cross_cluster(struct inode *inode, handle_t *handle, struct ocfs2_xattr_bucket *first, struct ocfs2_xattr_bucket *target, u64 new_blk, u32 prev_clusters, u32 *v_start, int *extend) { int ret; trace_ocfs2_adjust_xattr_cross_cluster( (unsigned long long)bucket_blkno(first), (unsigned long long)new_blk, prev_clusters); if (ocfs2_xattr_buckets_per_cluster(OCFS2_SB(inode->i_sb)) > 1) { ret = ocfs2_mv_xattr_bucket_cross_cluster(inode, handle, first, target, new_blk, prev_clusters, v_start); if (ret) mlog_errno(ret); } else { /* The start of the last cluster in the first extent */ u64 last_blk = bucket_blkno(first) + ((prev_clusters - 1) * ocfs2_clusters_to_blocks(inode->i_sb, 1)); if (prev_clusters > 1 && bucket_blkno(target) != last_blk) { ret = ocfs2_mv_xattr_buckets(inode, handle, bucket_blkno(first), last_blk, new_blk, 0, v_start); if (ret) mlog_errno(ret); } else { ret = ocfs2_divide_xattr_cluster(inode, handle, last_blk, new_blk, v_start); if (ret) mlog_errno(ret); if ((bucket_blkno(target) == last_blk) && extend) *extend = 0; } } return ret; } /* * Add a new cluster for xattr storage. * * If the new cluster is contiguous with the previous one, it will be * appended to the same extent record, and num_clusters will be updated. * If not, we will insert a new extent for it and move some xattrs in * the last cluster into the new allocated one. * We also need to limit the maximum size of a btree leaf, otherwise we'll * lose the benefits of hashing because we'll have to search large leaves. * So now the maximum size is OCFS2_MAX_XATTR_TREE_LEAF_SIZE(or clustersize, * if it's bigger). * * first_bh is the first block of the previous extent rec and header_bh * indicates the bucket we will insert the new xattrs. They will be updated * when the header_bh is moved into the new cluster. */ static int ocfs2_add_new_xattr_cluster(struct inode *inode, struct buffer_head *root_bh, struct ocfs2_xattr_bucket *first, struct ocfs2_xattr_bucket *target, u32 *num_clusters, u32 prev_cpos, int *extend, struct ocfs2_xattr_set_ctxt *ctxt) { int ret; u16 bpc = ocfs2_clusters_to_blocks(inode->i_sb, 1); u32 prev_clusters = *num_clusters; u32 clusters_to_add = 1, bit_off, num_bits, v_start = 0; u64 block; handle_t *handle = ctxt->handle; struct ocfs2_super *osb = OCFS2_SB(inode->i_sb); struct ocfs2_extent_tree et; trace_ocfs2_add_new_xattr_cluster_begin( (unsigned long long)OCFS2_I(inode)->ip_blkno, (unsigned long long)bucket_blkno(first), prev_cpos, prev_clusters); ocfs2_init_xattr_tree_extent_tree(&et, INODE_CACHE(inode), root_bh); ret = ocfs2_journal_access_xb(handle, INODE_CACHE(inode), root_bh, OCFS2_JOURNAL_ACCESS_WRITE); if (ret < 0) { mlog_errno(ret); goto leave; } ret = __ocfs2_claim_clusters(handle, ctxt->data_ac, 1, clusters_to_add, &bit_off, &num_bits); if (ret < 0) { if (ret != -ENOSPC) mlog_errno(ret); goto leave; } BUG_ON(num_bits > clusters_to_add); block = ocfs2_clusters_to_blocks(osb->sb, bit_off); trace_ocfs2_add_new_xattr_cluster((unsigned long long)block, num_bits); if (bucket_blkno(first) + (prev_clusters * bpc) == block && (prev_clusters + num_bits) << osb->s_clustersize_bits <= OCFS2_MAX_XATTR_TREE_LEAF_SIZE) { /* * If this cluster is contiguous with the old one and * adding this new cluster, we don't surpass the limit of * OCFS2_MAX_XATTR_TREE_LEAF_SIZE, cool. We will let it be * initialized and used like other buckets in the previous * cluster. * So add it as a contiguous one. The caller will handle * its init process. */ v_start = prev_cpos + prev_clusters; *num_clusters = prev_clusters + num_bits; } else { ret = ocfs2_adjust_xattr_cross_cluster(inode, handle, first, target, block, prev_clusters, &v_start, extend); if (ret) { mlog_errno(ret); goto leave; } } trace_ocfs2_add_new_xattr_cluster_insert((unsigned long long)block, v_start, num_bits); ret = ocfs2_insert_extent(handle, &et, v_start, block, num_bits, 0, ctxt->meta_ac); if (ret < 0) { mlog_errno(ret); goto leave; } ocfs2_journal_dirty(handle, root_bh); leave: return ret; } /* * We are given an extent. 'first' is the bucket at the very front of * the extent. The extent has space for an additional bucket past * bucket_xh(first)->xh_num_buckets. 'target_blkno' is the block number * of the target bucket. We wish to shift every bucket past the target * down one, filling in that additional space. When we get back to the * target, we split the target between itself and the now-empty bucket * at target+1 (aka, target_blkno + blks_per_bucket). */ static int ocfs2_extend_xattr_bucket(struct inode *inode, handle_t *handle, struct ocfs2_xattr_bucket *first, u64 target_blk, u32 num_clusters) { int ret, credits; struct ocfs2_super *osb = OCFS2_SB(inode->i_sb); u16 blk_per_bucket = ocfs2_blocks_per_xattr_bucket(inode->i_sb); u64 end_blk; u16 new_bucket = le16_to_cpu(bucket_xh(first)->xh_num_buckets); trace_ocfs2_extend_xattr_bucket((unsigned long long)target_blk, (unsigned long long)bucket_blkno(first), num_clusters, new_bucket); /* The extent must have room for an additional bucket */ BUG_ON(new_bucket >= (num_clusters * ocfs2_xattr_buckets_per_cluster(osb))); /* end_blk points to the last existing bucket */ end_blk = bucket_blkno(first) + ((new_bucket - 1) * blk_per_bucket); /* * end_blk is the start of the last existing bucket. * Thus, (end_blk - target_blk) covers the target bucket and * every bucket after it up to, but not including, the last * existing bucket. Then we add the last existing bucket, the * new bucket, and the first bucket (3 * blk_per_bucket). */ credits = (end_blk - target_blk) + (3 * blk_per_bucket); ret = ocfs2_extend_trans(handle, credits); if (ret) { mlog_errno(ret); goto out; } ret = ocfs2_xattr_bucket_journal_access(handle, first, OCFS2_JOURNAL_ACCESS_WRITE); if (ret) { mlog_errno(ret); goto out; } while (end_blk != target_blk) { ret = ocfs2_cp_xattr_bucket(inode, handle, end_blk, end_blk + blk_per_bucket, 0); if (ret) goto out; end_blk -= blk_per_bucket; } /* Move half of the xattr in target_blkno to the next bucket. */ ret = ocfs2_divide_xattr_bucket(inode, handle, target_blk, target_blk + blk_per_bucket, NULL, 0); le16_add_cpu(&bucket_xh(first)->xh_num_buckets, 1); ocfs2_xattr_bucket_journal_dirty(handle, first); out: return ret; } /* * Add new xattr bucket in an extent record and adjust the buckets * accordingly. xb_bh is the ocfs2_xattr_block, and target is the * bucket we want to insert into. * * In the easy case, we will move all the buckets after target down by * one. Half of target's xattrs will be moved to the next bucket. * * If current cluster is full, we'll allocate a new one. This may not * be contiguous. The underlying calls will make sure that there is * space for the insert, shifting buckets around if necessary. * 'target' may be moved by those calls. */ static int ocfs2_add_new_xattr_bucket(struct inode *inode, struct buffer_head *xb_bh, struct ocfs2_xattr_bucket *target, struct ocfs2_xattr_set_ctxt *ctxt) { struct ocfs2_xattr_block *xb = (struct ocfs2_xattr_block *)xb_bh->b_data; struct ocfs2_xattr_tree_root *xb_root = &xb->xb_attrs.xb_root; struct ocfs2_extent_list *el = &xb_root->xt_list; u32 name_hash = le32_to_cpu(bucket_xh(target)->xh_entries[0].xe_name_hash); struct ocfs2_super *osb = OCFS2_SB(inode->i_sb); int ret, num_buckets, extend = 1; u64 p_blkno; u32 e_cpos, num_clusters; /* The bucket at the front of the extent */ struct ocfs2_xattr_bucket *first; trace_ocfs2_add_new_xattr_bucket( (unsigned long long)bucket_blkno(target)); /* The first bucket of the original extent */ first = ocfs2_xattr_bucket_new(inode); if (!first) { ret = -ENOMEM; mlog_errno(ret); goto out; } ret = ocfs2_xattr_get_rec(inode, name_hash, &p_blkno, &e_cpos, &num_clusters, el); if (ret) { mlog_errno(ret); goto out; } ret = ocfs2_read_xattr_bucket(first, p_blkno); if (ret) { mlog_errno(ret); goto out; } num_buckets = ocfs2_xattr_buckets_per_cluster(osb) * num_clusters; if (num_buckets == le16_to_cpu(bucket_xh(first)->xh_num_buckets)) { /* * This can move first+target if the target bucket moves * to the new extent. */ ret = ocfs2_add_new_xattr_cluster(inode, xb_bh, first, target, &num_clusters, e_cpos, &extend, ctxt); if (ret) { mlog_errno(ret); goto out; } } if (extend) { ret = ocfs2_extend_xattr_bucket(inode, ctxt->handle, first, bucket_blkno(target), num_clusters); if (ret) mlog_errno(ret); } out: ocfs2_xattr_bucket_free(first); return ret; } static inline char *ocfs2_xattr_bucket_get_val(struct inode *inode, struct ocfs2_xattr_bucket *bucket, int offs) { int block_off = offs >> inode->i_sb->s_blocksize_bits; offs = offs % inode->i_sb->s_blocksize; return bucket_block(bucket, block_off) + offs; } /* * Truncate the specified xe_off entry in xattr bucket. * bucket is indicated by header_bh and len is the new length. * Both the ocfs2_xattr_value_root and the entry will be updated here. * * Copy the new updated xe and xe_value_root to new_xe and new_xv if needed. */ static int ocfs2_xattr_bucket_value_truncate(struct inode *inode, struct ocfs2_xattr_bucket *bucket, int xe_off, int len, struct ocfs2_xattr_set_ctxt *ctxt) { int ret, offset; u64 value_blk; struct ocfs2_xattr_entry *xe; struct ocfs2_xattr_header *xh = bucket_xh(bucket); size_t blocksize = inode->i_sb->s_blocksize; struct ocfs2_xattr_value_buf vb = { .vb_access = ocfs2_journal_access, }; xe = &xh->xh_entries[xe_off]; BUG_ON(!xe || ocfs2_xattr_is_local(xe)); offset = le16_to_cpu(xe->xe_name_offset) + OCFS2_XATTR_SIZE(xe->xe_name_len); value_blk = offset / blocksize; /* We don't allow ocfs2_xattr_value to be stored in different block. */ BUG_ON(value_blk != (offset + OCFS2_XATTR_ROOT_SIZE - 1) / blocksize); vb.vb_bh = bucket->bu_bhs[value_blk]; BUG_ON(!vb.vb_bh); vb.vb_xv = (struct ocfs2_xattr_value_root *) (vb.vb_bh->b_data + offset % blocksize); /* * From here on out we have to dirty the bucket. The generic * value calls only modify one of the bucket's bhs, but we need * to send the bucket at once. So if they error, they *could* have * modified something. We have to assume they did, and dirty * the whole bucket. This leaves us in a consistent state. */ trace_ocfs2_xattr_bucket_value_truncate( (unsigned long long)bucket_blkno(bucket), xe_off, len); ret = ocfs2_xattr_value_truncate(inode, &vb, len, ctxt); if (ret) { mlog_errno(ret); goto out; } ret = ocfs2_xattr_bucket_journal_access(ctxt->handle, bucket, OCFS2_JOURNAL_ACCESS_WRITE); if (ret) { mlog_errno(ret); goto out; } xe->xe_value_size = cpu_to_le64(len); ocfs2_xattr_bucket_journal_dirty(ctxt->handle, bucket); out: return ret; } static int ocfs2_rm_xattr_cluster(struct inode *inode, struct buffer_head *root_bh, u64 blkno, u32 cpos, u32 len, void *para) { int ret; struct ocfs2_super *osb = OCFS2_SB(inode->i_sb); struct inode *tl_inode = osb->osb_tl_inode; handle_t *handle; struct ocfs2_xattr_block *xb = (struct ocfs2_xattr_block *)root_bh->b_data; struct ocfs2_alloc_context *meta_ac = NULL; struct ocfs2_cached_dealloc_ctxt dealloc; struct ocfs2_extent_tree et; ret = ocfs2_iterate_xattr_buckets(inode, blkno, len, ocfs2_delete_xattr_in_bucket, para); if (ret) { mlog_errno(ret); return ret; } ocfs2_init_xattr_tree_extent_tree(&et, INODE_CACHE(inode), root_bh); ocfs2_init_dealloc_ctxt(&dealloc); trace_ocfs2_rm_xattr_cluster( (unsigned long long)OCFS2_I(inode)->ip_blkno, (unsigned long long)blkno, cpos, len); ocfs2_remove_xattr_clusters_from_cache(INODE_CACHE(inode), blkno, len); ret = ocfs2_lock_allocators(inode, &et, 0, 1, NULL, &meta_ac); if (ret) { mlog_errno(ret); return ret; } mutex_lock(&tl_inode->i_mutex); if (ocfs2_truncate_log_needs_flush(osb)) { ret = __ocfs2_flush_truncate_log(osb); if (ret < 0) { mlog_errno(ret); goto out; } } handle = ocfs2_start_trans(osb, ocfs2_remove_extent_credits(osb->sb)); if (IS_ERR(handle)) { ret = -ENOMEM; mlog_errno(ret); goto out; } ret = ocfs2_journal_access_xb(handle, INODE_CACHE(inode), root_bh, OCFS2_JOURNAL_ACCESS_WRITE); if (ret) { mlog_errno(ret); goto out_commit; } ret = ocfs2_remove_extent(handle, &et, cpos, len, meta_ac, &dealloc); if (ret) { mlog_errno(ret); goto out_commit; } le32_add_cpu(&xb->xb_attrs.xb_root.xt_clusters, -len); ocfs2_journal_dirty(handle, root_bh); ret = ocfs2_truncate_log_append(osb, handle, blkno, len); if (ret) mlog_errno(ret); out_commit: ocfs2_commit_trans(osb, handle); out: ocfs2_schedule_truncate_log_flush(osb, 1); mutex_unlock(&tl_inode->i_mutex); if (meta_ac) ocfs2_free_alloc_context(meta_ac); ocfs2_run_deallocs(osb, &dealloc); return ret; } /* * check whether the xattr bucket is filled up with the same hash value. * If we want to insert the xattr with the same hash, return -ENOSPC. * If we want to insert a xattr with different hash value, go ahead * and ocfs2_divide_xattr_bucket will handle this. */ static int ocfs2_check_xattr_bucket_collision(struct inode *inode, struct ocfs2_xattr_bucket *bucket, const char *name) { struct ocfs2_xattr_header *xh = bucket_xh(bucket); u32 name_hash = ocfs2_xattr_name_hash(inode, name, strlen(name)); if (name_hash != le32_to_cpu(xh->xh_entries[0].xe_name_hash)) return 0; if (xh->xh_entries[le16_to_cpu(xh->xh_count) - 1].xe_name_hash == xh->xh_entries[0].xe_name_hash) { mlog(ML_ERROR, "Too much hash collision in xattr bucket %llu, " "hash = %u\n", (unsigned long long)bucket_blkno(bucket), le32_to_cpu(xh->xh_entries[0].xe_name_hash)); return -ENOSPC; } return 0; } /* * Try to set the entry in the current bucket. If we fail, the caller * will handle getting us another bucket. */ static int ocfs2_xattr_set_entry_bucket(struct inode *inode, struct ocfs2_xattr_info *xi, struct ocfs2_xattr_search *xs, struct ocfs2_xattr_set_ctxt *ctxt) { int ret; struct ocfs2_xa_loc loc; trace_ocfs2_xattr_set_entry_bucket(xi->xi_name); ocfs2_init_xattr_bucket_xa_loc(&loc, xs->bucket, xs->not_found ? NULL : xs->here); ret = ocfs2_xa_set(&loc, xi, ctxt); if (!ret) { xs->here = loc.xl_entry; goto out; } if (ret != -ENOSPC) { mlog_errno(ret); goto out; } /* Ok, we need space. Let's try defragmenting the bucket. */ ret = ocfs2_defrag_xattr_bucket(inode, ctxt->handle, xs->bucket); if (ret) { mlog_errno(ret); goto out; } ret = ocfs2_xa_set(&loc, xi, ctxt); if (!ret) { xs->here = loc.xl_entry; goto out; } if (ret != -ENOSPC) mlog_errno(ret); out: return ret; } static int ocfs2_xattr_set_entry_index_block(struct inode *inode, struct ocfs2_xattr_info *xi, struct ocfs2_xattr_search *xs, struct ocfs2_xattr_set_ctxt *ctxt) { int ret; trace_ocfs2_xattr_set_entry_index_block(xi->xi_name); ret = ocfs2_xattr_set_entry_bucket(inode, xi, xs, ctxt); if (!ret) goto out; if (ret != -ENOSPC) { mlog_errno(ret); goto out; } /* Ack, need more space. Let's try to get another bucket! */ /* * We do not allow for overlapping ranges between buckets. And * the maximum number of collisions we will allow for then is * one bucket's worth, so check it here whether we need to * add a new bucket for the insert. */ ret = ocfs2_check_xattr_bucket_collision(inode, xs->bucket, xi->xi_name); if (ret) { mlog_errno(ret); goto out; } ret = ocfs2_add_new_xattr_bucket(inode, xs->xattr_bh, xs->bucket, ctxt); if (ret) { mlog_errno(ret); goto out; } /* * ocfs2_add_new_xattr_bucket() will have updated * xs->bucket if it moved, but it will not have updated * any of the other search fields. Thus, we drop it and * re-search. Everything should be cached, so it'll be * quick. */ ocfs2_xattr_bucket_relse(xs->bucket); ret = ocfs2_xattr_index_block_find(inode, xs->xattr_bh, xi->xi_name_index, xi->xi_name, xs); if (ret && ret != -ENODATA) goto out; xs->not_found = ret; /* Ok, we have a new bucket, let's try again */ ret = ocfs2_xattr_set_entry_bucket(inode, xi, xs, ctxt); if (ret && (ret != -ENOSPC)) mlog_errno(ret); out: return ret; } static int ocfs2_delete_xattr_in_bucket(struct inode *inode, struct ocfs2_xattr_bucket *bucket, void *para) { int ret = 0, ref_credits; struct ocfs2_xattr_header *xh = bucket_xh(bucket); u16 i; struct ocfs2_xattr_entry *xe; struct ocfs2_super *osb = OCFS2_SB(inode->i_sb); struct ocfs2_xattr_set_ctxt ctxt = {NULL, NULL,}; int credits = ocfs2_remove_extent_credits(osb->sb) + ocfs2_blocks_per_xattr_bucket(inode->i_sb); struct ocfs2_xattr_value_root *xv; struct ocfs2_rm_xattr_bucket_para *args = (struct ocfs2_rm_xattr_bucket_para *)para; ocfs2_init_dealloc_ctxt(&ctxt.dealloc); for (i = 0; i < le16_to_cpu(xh->xh_count); i++) { xe = &xh->xh_entries[i]; if (ocfs2_xattr_is_local(xe)) continue; ret = ocfs2_get_xattr_tree_value_root(inode->i_sb, bucket, i, &xv, NULL); ret = ocfs2_lock_xattr_remove_allocators(inode, xv, args->ref_ci, args->ref_root_bh, &ctxt.meta_ac, &ref_credits); ctxt.handle = ocfs2_start_trans(osb, credits + ref_credits); if (IS_ERR(ctxt.handle)) { ret = PTR_ERR(ctxt.handle); mlog_errno(ret); break; } ret = ocfs2_xattr_bucket_value_truncate(inode, bucket, i, 0, &ctxt); ocfs2_commit_trans(osb, ctxt.handle); if (ctxt.meta_ac) { ocfs2_free_alloc_context(ctxt.meta_ac); ctxt.meta_ac = NULL; } if (ret) { mlog_errno(ret); break; } } if (ctxt.meta_ac) ocfs2_free_alloc_context(ctxt.meta_ac); ocfs2_schedule_truncate_log_flush(osb, 1); ocfs2_run_deallocs(osb, &ctxt.dealloc); return ret; } /* * Whenever we modify a xattr value root in the bucket(e.g, CoW * or change the extent record flag), we need to recalculate * the metaecc for the whole bucket. So it is done here. * * Note: * We have to give the extra credits for the caller. */ static int ocfs2_xattr_bucket_post_refcount(struct inode *inode, handle_t *handle, void *para) { int ret; struct ocfs2_xattr_bucket *bucket = (struct ocfs2_xattr_bucket *)para; ret = ocfs2_xattr_bucket_journal_access(handle, bucket, OCFS2_JOURNAL_ACCESS_WRITE); if (ret) { mlog_errno(ret); return ret; } ocfs2_xattr_bucket_journal_dirty(handle, bucket); return 0; } /* * Special action we need if the xattr value is refcounted. * * 1. If the xattr is refcounted, lock the tree. * 2. CoW the xattr if we are setting the new value and the value * will be stored outside. * 3. In other case, decrease_refcount will work for us, so just * lock the refcount tree, calculate the meta and credits is OK. * * We have to do CoW before ocfs2_init_xattr_set_ctxt since * currently CoW is a completed transaction, while this function * will also lock the allocators and let us deadlock. So we will * CoW the whole xattr value. */ static int ocfs2_prepare_refcount_xattr(struct inode *inode, struct ocfs2_dinode *di, struct ocfs2_xattr_info *xi, struct ocfs2_xattr_search *xis, struct ocfs2_xattr_search *xbs, struct ocfs2_refcount_tree **ref_tree, int *meta_add, int *credits) { int ret = 0; struct ocfs2_xattr_block *xb; struct ocfs2_xattr_entry *xe; char *base; u32 p_cluster, num_clusters; unsigned int ext_flags; int name_offset, name_len; struct ocfs2_xattr_value_buf vb; struct ocfs2_xattr_bucket *bucket = NULL; struct ocfs2_super *osb = OCFS2_SB(inode->i_sb); struct ocfs2_post_refcount refcount; struct ocfs2_post_refcount *p = NULL; struct buffer_head *ref_root_bh = NULL; if (!xis->not_found) { xe = xis->here; name_offset = le16_to_cpu(xe->xe_name_offset); name_len = OCFS2_XATTR_SIZE(xe->xe_name_len); base = xis->base; vb.vb_bh = xis->inode_bh; vb.vb_access = ocfs2_journal_access_di; } else { int i, block_off = 0; xb = (struct ocfs2_xattr_block *)xbs->xattr_bh->b_data; xe = xbs->here; name_offset = le16_to_cpu(xe->xe_name_offset); name_len = OCFS2_XATTR_SIZE(xe->xe_name_len); i = xbs->here - xbs->header->xh_entries; if (le16_to_cpu(xb->xb_flags) & OCFS2_XATTR_INDEXED) { ret = ocfs2_xattr_bucket_get_name_value(inode->i_sb, bucket_xh(xbs->bucket), i, &block_off, &name_offset); if (ret) { mlog_errno(ret); goto out; } base = bucket_block(xbs->bucket, block_off); vb.vb_bh = xbs->bucket->bu_bhs[block_off]; vb.vb_access = ocfs2_journal_access; if (ocfs2_meta_ecc(osb)) { /*create parameters for ocfs2_post_refcount. */ bucket = xbs->bucket; refcount.credits = bucket->bu_blocks; refcount.para = bucket; refcount.func = ocfs2_xattr_bucket_post_refcount; p = &refcount; } } else { base = xbs->base; vb.vb_bh = xbs->xattr_bh; vb.vb_access = ocfs2_journal_access_xb; } } if (ocfs2_xattr_is_local(xe)) goto out; vb.vb_xv = (struct ocfs2_xattr_value_root *) (base + name_offset + name_len); ret = ocfs2_xattr_get_clusters(inode, 0, &p_cluster, &num_clusters, &vb.vb_xv->xr_list, &ext_flags); if (ret) { mlog_errno(ret); goto out; } /* * We just need to check the 1st extent record, since we always * CoW the whole xattr. So there shouldn't be a xattr with * some REFCOUNT extent recs after the 1st one. */ if (!(ext_flags & OCFS2_EXT_REFCOUNTED)) goto out; ret = ocfs2_lock_refcount_tree(osb, le64_to_cpu(di->i_refcount_loc), 1, ref_tree, &ref_root_bh); if (ret) { mlog_errno(ret); goto out; } /* * If we are deleting the xattr or the new size will be stored inside, * cool, leave it there, the xattr truncate process will remove them * for us(it still needs the refcount tree lock and the meta, credits). * And the worse case is that every cluster truncate will split the * refcount tree, and make the original extent become 3. So we will need * 2 * cluster more extent recs at most. */ if (!xi->xi_value || xi->xi_value_len <= OCFS2_XATTR_INLINE_SIZE) { ret = ocfs2_refcounted_xattr_delete_need(inode, &(*ref_tree)->rf_ci, ref_root_bh, vb.vb_xv, meta_add, credits); if (ret) mlog_errno(ret); goto out; } ret = ocfs2_refcount_cow_xattr(inode, di, &vb, *ref_tree, ref_root_bh, 0, le32_to_cpu(vb.vb_xv->xr_clusters), p); if (ret) mlog_errno(ret); out: brelse(ref_root_bh); return ret; } /* * Add the REFCOUNTED flags for all the extent rec in ocfs2_xattr_value_root. * The physical clusters will be added to refcount tree. */ static int ocfs2_xattr_value_attach_refcount(struct inode *inode, struct ocfs2_xattr_value_root *xv, struct ocfs2_extent_tree *value_et, struct ocfs2_caching_info *ref_ci, struct buffer_head *ref_root_bh, struct ocfs2_cached_dealloc_ctxt *dealloc, struct ocfs2_post_refcount *refcount) { int ret = 0; u32 clusters = le32_to_cpu(xv->xr_clusters); u32 cpos, p_cluster, num_clusters; struct ocfs2_extent_list *el = &xv->xr_list; unsigned int ext_flags; cpos = 0; while (cpos < clusters) { ret = ocfs2_xattr_get_clusters(inode, cpos, &p_cluster, &num_clusters, el, &ext_flags); cpos += num_clusters; if ((ext_flags & OCFS2_EXT_REFCOUNTED)) continue; BUG_ON(!p_cluster); ret = ocfs2_add_refcount_flag(inode, value_et, ref_ci, ref_root_bh, cpos - num_clusters, p_cluster, num_clusters, dealloc, refcount); if (ret) { mlog_errno(ret); break; } } return ret; } /* * Given a normal ocfs2_xattr_header, refcount all the entries which * have value stored outside. * Used for xattrs stored in inode and ocfs2_xattr_block. */ static int ocfs2_xattr_attach_refcount_normal(struct inode *inode, struct ocfs2_xattr_value_buf *vb, struct ocfs2_xattr_header *header, struct ocfs2_caching_info *ref_ci, struct buffer_head *ref_root_bh, struct ocfs2_cached_dealloc_ctxt *dealloc) { struct ocfs2_xattr_entry *xe; struct ocfs2_xattr_value_root *xv; struct ocfs2_extent_tree et; int i, ret = 0; for (i = 0; i < le16_to_cpu(header->xh_count); i++) { xe = &header->xh_entries[i]; if (ocfs2_xattr_is_local(xe)) continue; xv = (struct ocfs2_xattr_value_root *)((void *)header + le16_to_cpu(xe->xe_name_offset) + OCFS2_XATTR_SIZE(xe->xe_name_len)); vb->vb_xv = xv; ocfs2_init_xattr_value_extent_tree(&et, INODE_CACHE(inode), vb); ret = ocfs2_xattr_value_attach_refcount(inode, xv, &et, ref_ci, ref_root_bh, dealloc, NULL); if (ret) { mlog_errno(ret); break; } } return ret; } static int ocfs2_xattr_inline_attach_refcount(struct inode *inode, struct buffer_head *fe_bh, struct ocfs2_caching_info *ref_ci, struct buffer_head *ref_root_bh, struct ocfs2_cached_dealloc_ctxt *dealloc) { struct ocfs2_dinode *di = (struct ocfs2_dinode *)fe_bh->b_data; struct ocfs2_xattr_header *header = (struct ocfs2_xattr_header *) (fe_bh->b_data + inode->i_sb->s_blocksize - le16_to_cpu(di->i_xattr_inline_size)); struct ocfs2_xattr_value_buf vb = { .vb_bh = fe_bh, .vb_access = ocfs2_journal_access_di, }; return ocfs2_xattr_attach_refcount_normal(inode, &vb, header, ref_ci, ref_root_bh, dealloc); } struct ocfs2_xattr_tree_value_refcount_para { struct ocfs2_caching_info *ref_ci; struct buffer_head *ref_root_bh; struct ocfs2_cached_dealloc_ctxt *dealloc; }; static int ocfs2_get_xattr_tree_value_root(struct super_block *sb, struct ocfs2_xattr_bucket *bucket, int offset, struct ocfs2_xattr_value_root **xv, struct buffer_head **bh) { int ret, block_off, name_offset; struct ocfs2_xattr_header *xh = bucket_xh(bucket); struct ocfs2_xattr_entry *xe = &xh->xh_entries[offset]; void *base; ret = ocfs2_xattr_bucket_get_name_value(sb, bucket_xh(bucket), offset, &block_off, &name_offset); if (ret) { mlog_errno(ret); goto out; } base = bucket_block(bucket, block_off); *xv = (struct ocfs2_xattr_value_root *)(base + name_offset + OCFS2_XATTR_SIZE(xe->xe_name_len)); if (bh) *bh = bucket->bu_bhs[block_off]; out: return ret; } /* * For a given xattr bucket, refcount all the entries which * have value stored outside. */ static int ocfs2_xattr_bucket_value_refcount(struct inode *inode, struct ocfs2_xattr_bucket *bucket, void *para) { int i, ret = 0; struct ocfs2_extent_tree et; struct ocfs2_xattr_tree_value_refcount_para *ref = (struct ocfs2_xattr_tree_value_refcount_para *)para; struct ocfs2_xattr_header *xh = (struct ocfs2_xattr_header *)bucket->bu_bhs[0]->b_data; struct ocfs2_xattr_entry *xe; struct ocfs2_xattr_value_buf vb = { .vb_access = ocfs2_journal_access, }; struct ocfs2_post_refcount refcount = { .credits = bucket->bu_blocks, .para = bucket, .func = ocfs2_xattr_bucket_post_refcount, }; struct ocfs2_post_refcount *p = NULL; /* We only need post_refcount if we support metaecc. */ if (ocfs2_meta_ecc(OCFS2_SB(inode->i_sb))) p = &refcount; trace_ocfs2_xattr_bucket_value_refcount( (unsigned long long)bucket_blkno(bucket), le16_to_cpu(xh->xh_count)); for (i = 0; i < le16_to_cpu(xh->xh_count); i++) { xe = &xh->xh_entries[i]; if (ocfs2_xattr_is_local(xe)) continue; ret = ocfs2_get_xattr_tree_value_root(inode->i_sb, bucket, i, &vb.vb_xv, &vb.vb_bh); if (ret) { mlog_errno(ret); break; } ocfs2_init_xattr_value_extent_tree(&et, INODE_CACHE(inode), &vb); ret = ocfs2_xattr_value_attach_refcount(inode, vb.vb_xv, &et, ref->ref_ci, ref->ref_root_bh, ref->dealloc, p); if (ret) { mlog_errno(ret); break; } } return ret; } static int ocfs2_refcount_xattr_tree_rec(struct inode *inode, struct buffer_head *root_bh, u64 blkno, u32 cpos, u32 len, void *para) { return ocfs2_iterate_xattr_buckets(inode, blkno, len, ocfs2_xattr_bucket_value_refcount, para); } static int ocfs2_xattr_block_attach_refcount(struct inode *inode, struct buffer_head *blk_bh, struct ocfs2_caching_info *ref_ci, struct buffer_head *ref_root_bh, struct ocfs2_cached_dealloc_ctxt *dealloc) { int ret = 0; struct ocfs2_xattr_block *xb = (struct ocfs2_xattr_block *)blk_bh->b_data; if (!(le16_to_cpu(xb->xb_flags) & OCFS2_XATTR_INDEXED)) { struct ocfs2_xattr_header *header = &xb->xb_attrs.xb_header; struct ocfs2_xattr_value_buf vb = { .vb_bh = blk_bh, .vb_access = ocfs2_journal_access_xb, }; ret = ocfs2_xattr_attach_refcount_normal(inode, &vb, header, ref_ci, ref_root_bh, dealloc); } else { struct ocfs2_xattr_tree_value_refcount_para para = { .ref_ci = ref_ci, .ref_root_bh = ref_root_bh, .dealloc = dealloc, }; ret = ocfs2_iterate_xattr_index_block(inode, blk_bh, ocfs2_refcount_xattr_tree_rec, &para); } return ret; } int ocfs2_xattr_attach_refcount_tree(struct inode *inode, struct buffer_head *fe_bh, struct ocfs2_caching_info *ref_ci, struct buffer_head *ref_root_bh, struct ocfs2_cached_dealloc_ctxt *dealloc) { int ret = 0; struct ocfs2_inode_info *oi = OCFS2_I(inode); struct ocfs2_dinode *di = (struct ocfs2_dinode *)fe_bh->b_data; struct buffer_head *blk_bh = NULL; if (oi->ip_dyn_features & OCFS2_INLINE_XATTR_FL) { ret = ocfs2_xattr_inline_attach_refcount(inode, fe_bh, ref_ci, ref_root_bh, dealloc); if (ret) { mlog_errno(ret); goto out; } } if (!di->i_xattr_loc) goto out; ret = ocfs2_read_xattr_block(inode, le64_to_cpu(di->i_xattr_loc), &blk_bh); if (ret < 0) { mlog_errno(ret); goto out; } ret = ocfs2_xattr_block_attach_refcount(inode, blk_bh, ref_ci, ref_root_bh, dealloc); if (ret) mlog_errno(ret); brelse(blk_bh); out: return ret; } typedef int (should_xattr_reflinked)(struct ocfs2_xattr_entry *xe); /* * Store the information we need in xattr reflink. * old_bh and new_bh are inode bh for the old and new inode. */ struct ocfs2_xattr_reflink { struct inode *old_inode; struct inode *new_inode; struct buffer_head *old_bh; struct buffer_head *new_bh; struct ocfs2_caching_info *ref_ci; struct buffer_head *ref_root_bh; struct ocfs2_cached_dealloc_ctxt *dealloc; should_xattr_reflinked *xattr_reflinked; }; /* * Given a xattr header and xe offset, * return the proper xv and the corresponding bh. * xattr in inode, block and xattr tree have different implementaions. */ typedef int (get_xattr_value_root)(struct super_block *sb, struct buffer_head *bh, struct ocfs2_xattr_header *xh, int offset, struct ocfs2_xattr_value_root **xv, struct buffer_head **ret_bh, void *para); /* * Calculate all the xattr value root metadata stored in this xattr header and * credits we need if we create them from the scratch. * We use get_xattr_value_root so that all types of xattr container can use it. */ static int ocfs2_value_metas_in_xattr_header(struct super_block *sb, struct buffer_head *bh, struct ocfs2_xattr_header *xh, int *metas, int *credits, int *num_recs, get_xattr_value_root *func, void *para) { int i, ret = 0; struct ocfs2_xattr_value_root *xv; struct ocfs2_xattr_entry *xe; for (i = 0; i < le16_to_cpu(xh->xh_count); i++) { xe = &xh->xh_entries[i]; if (ocfs2_xattr_is_local(xe)) continue; ret = func(sb, bh, xh, i, &xv, NULL, para); if (ret) { mlog_errno(ret); break; } *metas += le16_to_cpu(xv->xr_list.l_tree_depth) * le16_to_cpu(xv->xr_list.l_next_free_rec); *credits += ocfs2_calc_extend_credits(sb, &def_xv.xv.xr_list, le32_to_cpu(xv->xr_clusters)); /* * If the value is a tree with depth > 1, We don't go deep * to the extent block, so just calculate a maximum record num. */ if (!xv->xr_list.l_tree_depth) *num_recs += le16_to_cpu(xv->xr_list.l_next_free_rec); else *num_recs += ocfs2_clusters_for_bytes(sb, XATTR_SIZE_MAX); } return ret; } /* Used by xattr inode and block to return the right xv and buffer_head. */ static int ocfs2_get_xattr_value_root(struct super_block *sb, struct buffer_head *bh, struct ocfs2_xattr_header *xh, int offset, struct ocfs2_xattr_value_root **xv, struct buffer_head **ret_bh, void *para) { struct ocfs2_xattr_entry *xe = &xh->xh_entries[offset]; *xv = (struct ocfs2_xattr_value_root *)((void *)xh + le16_to_cpu(xe->xe_name_offset) + OCFS2_XATTR_SIZE(xe->xe_name_len)); if (ret_bh) *ret_bh = bh; return 0; } /* * Lock the meta_ac and caculate how much credits we need for reflink xattrs. * It is only used for inline xattr and xattr block. */ static int ocfs2_reflink_lock_xattr_allocators(struct ocfs2_super *osb, struct ocfs2_xattr_header *xh, struct buffer_head *ref_root_bh, int *credits, struct ocfs2_alloc_context **meta_ac) { int ret, meta_add = 0, num_recs = 0; struct ocfs2_refcount_block *rb = (struct ocfs2_refcount_block *)ref_root_bh->b_data; *credits = 0; ret = ocfs2_value_metas_in_xattr_header(osb->sb, NULL, xh, &meta_add, credits, &num_recs, ocfs2_get_xattr_value_root, NULL); if (ret) { mlog_errno(ret); goto out; } /* * We need to add/modify num_recs in refcount tree, so just calculate * an approximate number we need for refcount tree change. * Sometimes we need to split the tree, and after split, half recs * will be moved to the new block, and a new block can only provide * half number of recs. So we multiple new blocks by 2. */ num_recs = num_recs / ocfs2_refcount_recs_per_rb(osb->sb) * 2; meta_add += num_recs; *credits += num_recs + num_recs * OCFS2_EXPAND_REFCOUNT_TREE_CREDITS; if (le32_to_cpu(rb->rf_flags) & OCFS2_REFCOUNT_TREE_FL) *credits += le16_to_cpu(rb->rf_list.l_tree_depth) * le16_to_cpu(rb->rf_list.l_next_free_rec) + 1; else *credits += 1; ret = ocfs2_reserve_new_metadata_blocks(osb, meta_add, meta_ac); if (ret) mlog_errno(ret); out: return ret; } /* * Given a xattr header, reflink all the xattrs in this container. * It can be used for inode, block and bucket. * * NOTE: * Before we call this function, the caller has memcpy the xattr in * old_xh to the new_xh. * * If args.xattr_reflinked is set, call it to decide whether the xe should * be reflinked or not. If not, remove it from the new xattr header. */ static int ocfs2_reflink_xattr_header(handle_t *handle, struct ocfs2_xattr_reflink *args, struct buffer_head *old_bh, struct ocfs2_xattr_header *xh, struct buffer_head *new_bh, struct ocfs2_xattr_header *new_xh, struct ocfs2_xattr_value_buf *vb, struct ocfs2_alloc_context *meta_ac, get_xattr_value_root *func, void *para) { int ret = 0, i, j; struct super_block *sb = args->old_inode->i_sb; struct buffer_head *value_bh; struct ocfs2_xattr_entry *xe, *last; struct ocfs2_xattr_value_root *xv, *new_xv; struct ocfs2_extent_tree data_et; u32 clusters, cpos, p_cluster, num_clusters; unsigned int ext_flags = 0; trace_ocfs2_reflink_xattr_header((unsigned long long)old_bh->b_blocknr, le16_to_cpu(xh->xh_count)); last = &new_xh->xh_entries[le16_to_cpu(new_xh->xh_count)]; for (i = 0, j = 0; i < le16_to_cpu(xh->xh_count); i++, j++) { xe = &xh->xh_entries[i]; if (args->xattr_reflinked && !args->xattr_reflinked(xe)) { xe = &new_xh->xh_entries[j]; le16_add_cpu(&new_xh->xh_count, -1); if (new_xh->xh_count) { memmove(xe, xe + 1, (void *)last - (void *)xe); memset(last, 0, sizeof(struct ocfs2_xattr_entry)); } /* * We don't want j to increase in the next round since * it is already moved ahead. */ j--; continue; } if (ocfs2_xattr_is_local(xe)) continue; ret = func(sb, old_bh, xh, i, &xv, NULL, para); if (ret) { mlog_errno(ret); break; } ret = func(sb, new_bh, new_xh, j, &new_xv, &value_bh, para); if (ret) { mlog_errno(ret); break; } /* * For the xattr which has l_tree_depth = 0, all the extent * recs have already be copied to the new xh with the * propriate OCFS2_EXT_REFCOUNTED flag we just need to * increase the refount count int the refcount tree. * * For the xattr which has l_tree_depth > 0, we need * to initialize it to the empty default value root, * and then insert the extents one by one. */ if (xv->xr_list.l_tree_depth) { memcpy(new_xv, &def_xv, sizeof(def_xv)); vb->vb_xv = new_xv; vb->vb_bh = value_bh; ocfs2_init_xattr_value_extent_tree(&data_et, INODE_CACHE(args->new_inode), vb); } clusters = le32_to_cpu(xv->xr_clusters); cpos = 0; while (cpos < clusters) { ret = ocfs2_xattr_get_clusters(args->old_inode, cpos, &p_cluster, &num_clusters, &xv->xr_list, &ext_flags); if (ret) { mlog_errno(ret); goto out; } BUG_ON(!p_cluster); if (xv->xr_list.l_tree_depth) { ret = ocfs2_insert_extent(handle, &data_et, cpos, ocfs2_clusters_to_blocks( args->old_inode->i_sb, p_cluster), num_clusters, ext_flags, meta_ac); if (ret) { mlog_errno(ret); goto out; } } ret = ocfs2_increase_refcount(handle, args->ref_ci, args->ref_root_bh, p_cluster, num_clusters, meta_ac, args->dealloc); if (ret) { mlog_errno(ret); goto out; } cpos += num_clusters; } } out: return ret; } static int ocfs2_reflink_xattr_inline(struct ocfs2_xattr_reflink *args) { int ret = 0, credits = 0; handle_t *handle; struct ocfs2_super *osb = OCFS2_SB(args->old_inode->i_sb); struct ocfs2_dinode *di = (struct ocfs2_dinode *)args->old_bh->b_data; int inline_size = le16_to_cpu(di->i_xattr_inline_size); int header_off = osb->sb->s_blocksize - inline_size; struct ocfs2_xattr_header *xh = (struct ocfs2_xattr_header *) (args->old_bh->b_data + header_off); struct ocfs2_xattr_header *new_xh = (struct ocfs2_xattr_header *) (args->new_bh->b_data + header_off); struct ocfs2_alloc_context *meta_ac = NULL; struct ocfs2_inode_info *new_oi; struct ocfs2_dinode *new_di; struct ocfs2_xattr_value_buf vb = { .vb_bh = args->new_bh, .vb_access = ocfs2_journal_access_di, }; ret = ocfs2_reflink_lock_xattr_allocators(osb, xh, args->ref_root_bh, &credits, &meta_ac); if (ret) { mlog_errno(ret); goto out; } handle = ocfs2_start_trans(osb, credits); if (IS_ERR(handle)) { ret = PTR_ERR(handle); mlog_errno(ret); goto out; } ret = ocfs2_journal_access_di(handle, INODE_CACHE(args->new_inode), args->new_bh, OCFS2_JOURNAL_ACCESS_WRITE); if (ret) { mlog_errno(ret); goto out_commit; } memcpy(args->new_bh->b_data + header_off, args->old_bh->b_data + header_off, inline_size); new_di = (struct ocfs2_dinode *)args->new_bh->b_data; new_di->i_xattr_inline_size = cpu_to_le16(inline_size); ret = ocfs2_reflink_xattr_header(handle, args, args->old_bh, xh, args->new_bh, new_xh, &vb, meta_ac, ocfs2_get_xattr_value_root, NULL); if (ret) { mlog_errno(ret); goto out_commit; } new_oi = OCFS2_I(args->new_inode); spin_lock(&new_oi->ip_lock); new_oi->ip_dyn_features |= OCFS2_HAS_XATTR_FL | OCFS2_INLINE_XATTR_FL; new_di->i_dyn_features = cpu_to_le16(new_oi->ip_dyn_features); spin_unlock(&new_oi->ip_lock); ocfs2_journal_dirty(handle, args->new_bh); out_commit: ocfs2_commit_trans(osb, handle); out: if (meta_ac) ocfs2_free_alloc_context(meta_ac); return ret; } static int ocfs2_create_empty_xattr_block(struct inode *inode, struct buffer_head *fe_bh, struct buffer_head **ret_bh, int indexed) { int ret; struct ocfs2_super *osb = OCFS2_SB(inode->i_sb); struct ocfs2_xattr_set_ctxt ctxt; memset(&ctxt, 0, sizeof(ctxt)); ret = ocfs2_reserve_new_metadata_blocks(osb, 1, &ctxt.meta_ac); if (ret < 0) { mlog_errno(ret); return ret; } ctxt.handle = ocfs2_start_trans(osb, OCFS2_XATTR_BLOCK_CREATE_CREDITS); if (IS_ERR(ctxt.handle)) { ret = PTR_ERR(ctxt.handle); mlog_errno(ret); goto out; } trace_ocfs2_create_empty_xattr_block( (unsigned long long)fe_bh->b_blocknr, indexed); ret = ocfs2_create_xattr_block(inode, fe_bh, &ctxt, indexed, ret_bh); if (ret) mlog_errno(ret); ocfs2_commit_trans(osb, ctxt.handle); out: ocfs2_free_alloc_context(ctxt.meta_ac); return ret; } static int ocfs2_reflink_xattr_block(struct ocfs2_xattr_reflink *args, struct buffer_head *blk_bh, struct buffer_head *new_blk_bh) { int ret = 0, credits = 0; handle_t *handle; struct ocfs2_inode_info *new_oi = OCFS2_I(args->new_inode); struct ocfs2_dinode *new_di; struct ocfs2_super *osb = OCFS2_SB(args->new_inode->i_sb); int header_off = offsetof(struct ocfs2_xattr_block, xb_attrs.xb_header); struct ocfs2_xattr_block *xb = (struct ocfs2_xattr_block *)blk_bh->b_data; struct ocfs2_xattr_header *xh = &xb->xb_attrs.xb_header; struct ocfs2_xattr_block *new_xb = (struct ocfs2_xattr_block *)new_blk_bh->b_data; struct ocfs2_xattr_header *new_xh = &new_xb->xb_attrs.xb_header; struct ocfs2_alloc_context *meta_ac; struct ocfs2_xattr_value_buf vb = { .vb_bh = new_blk_bh, .vb_access = ocfs2_journal_access_xb, }; ret = ocfs2_reflink_lock_xattr_allocators(osb, xh, args->ref_root_bh, &credits, &meta_ac); if (ret) { mlog_errno(ret); return ret; } /* One more credits in case we need to add xattr flags in new inode. */ handle = ocfs2_start_trans(osb, credits + 1); if (IS_ERR(handle)) { ret = PTR_ERR(handle); mlog_errno(ret); goto out; } if (!(new_oi->ip_dyn_features & OCFS2_HAS_XATTR_FL)) { ret = ocfs2_journal_access_di(handle, INODE_CACHE(args->new_inode), args->new_bh, OCFS2_JOURNAL_ACCESS_WRITE); if (ret) { mlog_errno(ret); goto out_commit; } } ret = ocfs2_journal_access_xb(handle, INODE_CACHE(args->new_inode), new_blk_bh, OCFS2_JOURNAL_ACCESS_WRITE); if (ret) { mlog_errno(ret); goto out_commit; } memcpy(new_blk_bh->b_data + header_off, blk_bh->b_data + header_off, osb->sb->s_blocksize - header_off); ret = ocfs2_reflink_xattr_header(handle, args, blk_bh, xh, new_blk_bh, new_xh, &vb, meta_ac, ocfs2_get_xattr_value_root, NULL); if (ret) { mlog_errno(ret); goto out_commit; } ocfs2_journal_dirty(handle, new_blk_bh); if (!(new_oi->ip_dyn_features & OCFS2_HAS_XATTR_FL)) { new_di = (struct ocfs2_dinode *)args->new_bh->b_data; spin_lock(&new_oi->ip_lock); new_oi->ip_dyn_features |= OCFS2_HAS_XATTR_FL; new_di->i_dyn_features = cpu_to_le16(new_oi->ip_dyn_features); spin_unlock(&new_oi->ip_lock); ocfs2_journal_dirty(handle, args->new_bh); } out_commit: ocfs2_commit_trans(osb, handle); out: ocfs2_free_alloc_context(meta_ac); return ret; } struct ocfs2_reflink_xattr_tree_args { struct ocfs2_xattr_reflink *reflink; struct buffer_head *old_blk_bh; struct buffer_head *new_blk_bh; struct ocfs2_xattr_bucket *old_bucket; struct ocfs2_xattr_bucket *new_bucket; }; /* * NOTE: * We have to handle the case that both old bucket and new bucket * will call this function to get the right ret_bh. * So The caller must give us the right bh. */ static int ocfs2_get_reflink_xattr_value_root(struct super_block *sb, struct buffer_head *bh, struct ocfs2_xattr_header *xh, int offset, struct ocfs2_xattr_value_root **xv, struct buffer_head **ret_bh, void *para) { struct ocfs2_reflink_xattr_tree_args *args = (struct ocfs2_reflink_xattr_tree_args *)para; struct ocfs2_xattr_bucket *bucket; if (bh == args->old_bucket->bu_bhs[0]) bucket = args->old_bucket; else bucket = args->new_bucket; return ocfs2_get_xattr_tree_value_root(sb, bucket, offset, xv, ret_bh); } struct ocfs2_value_tree_metas { int num_metas; int credits; int num_recs; }; static int ocfs2_value_tree_metas_in_bucket(struct super_block *sb, struct buffer_head *bh, struct ocfs2_xattr_header *xh, int offset, struct ocfs2_xattr_value_root **xv, struct buffer_head **ret_bh, void *para) { struct ocfs2_xattr_bucket *bucket = (struct ocfs2_xattr_bucket *)para; return ocfs2_get_xattr_tree_value_root(sb, bucket, offset, xv, ret_bh); } static int ocfs2_calc_value_tree_metas(struct inode *inode, struct ocfs2_xattr_bucket *bucket, void *para) { struct ocfs2_value_tree_metas *metas = (struct ocfs2_value_tree_metas *)para; struct ocfs2_xattr_header *xh = (struct ocfs2_xattr_header *)bucket->bu_bhs[0]->b_data; /* Add the credits for this bucket first. */ metas->credits += bucket->bu_blocks; return ocfs2_value_metas_in_xattr_header(inode->i_sb, bucket->bu_bhs[0], xh, &metas->num_metas, &metas->credits, &metas->num_recs, ocfs2_value_tree_metas_in_bucket, bucket); } /* * Given a xattr extent rec starting from blkno and having len clusters, * iterate all the buckets calculate how much metadata we need for reflinking * all the ocfs2_xattr_value_root and lock the allocators accordingly. */ static int ocfs2_lock_reflink_xattr_rec_allocators( struct ocfs2_reflink_xattr_tree_args *args, struct ocfs2_extent_tree *xt_et, u64 blkno, u32 len, int *credits, struct ocfs2_alloc_context **meta_ac, struct ocfs2_alloc_context **data_ac) { int ret, num_free_extents; struct ocfs2_value_tree_metas metas; struct ocfs2_super *osb = OCFS2_SB(args->reflink->old_inode->i_sb); struct ocfs2_refcount_block *rb; memset(&metas, 0, sizeof(metas)); ret = ocfs2_iterate_xattr_buckets(args->reflink->old_inode, blkno, len, ocfs2_calc_value_tree_metas, &metas); if (ret) { mlog_errno(ret); goto out; } *credits = metas.credits; /* * Calculate we need for refcount tree change. * * We need to add/modify num_recs in refcount tree, so just calculate * an approximate number we need for refcount tree change. * Sometimes we need to split the tree, and after split, half recs * will be moved to the new block, and a new block can only provide * half number of recs. So we multiple new blocks by 2. * In the end, we have to add credits for modifying the already * existed refcount block. */ rb = (struct ocfs2_refcount_block *)args->reflink->ref_root_bh->b_data; metas.num_recs = (metas.num_recs + ocfs2_refcount_recs_per_rb(osb->sb) - 1) / ocfs2_refcount_recs_per_rb(osb->sb) * 2; metas.num_metas += metas.num_recs; *credits += metas.num_recs + metas.num_recs * OCFS2_EXPAND_REFCOUNT_TREE_CREDITS; if (le32_to_cpu(rb->rf_flags) & OCFS2_REFCOUNT_TREE_FL) *credits += le16_to_cpu(rb->rf_list.l_tree_depth) * le16_to_cpu(rb->rf_list.l_next_free_rec) + 1; else *credits += 1; /* count in the xattr tree change. */ num_free_extents = ocfs2_num_free_extents(osb, xt_et); if (num_free_extents < 0) { ret = num_free_extents; mlog_errno(ret); goto out; } if (num_free_extents < len) metas.num_metas += ocfs2_extend_meta_needed(xt_et->et_root_el); *credits += ocfs2_calc_extend_credits(osb->sb, xt_et->et_root_el, len); if (metas.num_metas) { ret = ocfs2_reserve_new_metadata_blocks(osb, metas.num_metas, meta_ac); if (ret) { mlog_errno(ret); goto out; } } if (len) { ret = ocfs2_reserve_clusters(osb, len, data_ac); if (ret) mlog_errno(ret); } out: if (ret) { if (*meta_ac) { ocfs2_free_alloc_context(*meta_ac); meta_ac = NULL; } } return ret; } static int ocfs2_reflink_xattr_bucket(handle_t *handle, u64 blkno, u64 new_blkno, u32 clusters, u32 *cpos, int num_buckets, struct ocfs2_alloc_context *meta_ac, struct ocfs2_alloc_context *data_ac, struct ocfs2_reflink_xattr_tree_args *args) { int i, j, ret = 0; struct super_block *sb = args->reflink->old_inode->i_sb; int bpb = args->old_bucket->bu_blocks; struct ocfs2_xattr_value_buf vb = { .vb_access = ocfs2_journal_access, }; for (i = 0; i < num_buckets; i++, blkno += bpb, new_blkno += bpb) { ret = ocfs2_read_xattr_bucket(args->old_bucket, blkno); if (ret) { mlog_errno(ret); break; } ret = ocfs2_init_xattr_bucket(args->new_bucket, new_blkno); if (ret) { mlog_errno(ret); break; } ret = ocfs2_xattr_bucket_journal_access(handle, args->new_bucket, OCFS2_JOURNAL_ACCESS_CREATE); if (ret) { mlog_errno(ret); break; } for (j = 0; j < bpb; j++) memcpy(bucket_block(args->new_bucket, j), bucket_block(args->old_bucket, j), sb->s_blocksize); /* * Record the start cpos so that we can use it to initialize * our xattr tree we also set the xh_num_bucket for the new * bucket. */ if (i == 0) { *cpos = le32_to_cpu(bucket_xh(args->new_bucket)-> xh_entries[0].xe_name_hash); bucket_xh(args->new_bucket)->xh_num_buckets = cpu_to_le16(num_buckets); } ocfs2_xattr_bucket_journal_dirty(handle, args->new_bucket); ret = ocfs2_reflink_xattr_header(handle, args->reflink, args->old_bucket->bu_bhs[0], bucket_xh(args->old_bucket), args->new_bucket->bu_bhs[0], bucket_xh(args->new_bucket), &vb, meta_ac, ocfs2_get_reflink_xattr_value_root, args); if (ret) { mlog_errno(ret); break; } /* * Re-access and dirty the bucket to calculate metaecc. * Because we may extend the transaction in reflink_xattr_header * which will let the already accessed block gone. */ ret = ocfs2_xattr_bucket_journal_access(handle, args->new_bucket, OCFS2_JOURNAL_ACCESS_WRITE); if (ret) { mlog_errno(ret); break; } ocfs2_xattr_bucket_journal_dirty(handle, args->new_bucket); ocfs2_xattr_bucket_relse(args->old_bucket); ocfs2_xattr_bucket_relse(args->new_bucket); } ocfs2_xattr_bucket_relse(args->old_bucket); ocfs2_xattr_bucket_relse(args->new_bucket); return ret; } static int ocfs2_reflink_xattr_buckets(handle_t *handle, struct inode *inode, struct ocfs2_reflink_xattr_tree_args *args, struct ocfs2_extent_tree *et, struct ocfs2_alloc_context *meta_ac, struct ocfs2_alloc_context *data_ac, u64 blkno, u32 cpos, u32 len) { int ret, first_inserted = 0; u32 p_cluster, num_clusters, reflink_cpos = 0; u64 new_blkno; unsigned int num_buckets, reflink_buckets; unsigned int bpc = ocfs2_xattr_buckets_per_cluster(OCFS2_SB(inode->i_sb)); ret = ocfs2_read_xattr_bucket(args->old_bucket, blkno); if (ret) { mlog_errno(ret); goto out; } num_buckets = le16_to_cpu(bucket_xh(args->old_bucket)->xh_num_buckets); ocfs2_xattr_bucket_relse(args->old_bucket); while (len && num_buckets) { ret = ocfs2_claim_clusters(handle, data_ac, 1, &p_cluster, &num_clusters); if (ret) { mlog_errno(ret); goto out; } new_blkno = ocfs2_clusters_to_blocks(inode->i_sb, p_cluster); reflink_buckets = min(num_buckets, bpc * num_clusters); ret = ocfs2_reflink_xattr_bucket(handle, blkno, new_blkno, num_clusters, &reflink_cpos, reflink_buckets, meta_ac, data_ac, args); if (ret) { mlog_errno(ret); goto out; } /* * For the 1st allocated cluster, we make it use the same cpos * so that the xattr tree looks the same as the original one * in the most case. */ if (!first_inserted) { reflink_cpos = cpos; first_inserted = 1; } ret = ocfs2_insert_extent(handle, et, reflink_cpos, new_blkno, num_clusters, 0, meta_ac); if (ret) mlog_errno(ret); trace_ocfs2_reflink_xattr_buckets((unsigned long long)new_blkno, num_clusters, reflink_cpos); len -= num_clusters; blkno += ocfs2_clusters_to_blocks(inode->i_sb, num_clusters); num_buckets -= reflink_buckets; } out: return ret; } /* * Create the same xattr extent record in the new inode's xattr tree. */ static int ocfs2_reflink_xattr_rec(struct inode *inode, struct buffer_head *root_bh, u64 blkno, u32 cpos, u32 len, void *para) { int ret, credits = 0; handle_t *handle; struct ocfs2_reflink_xattr_tree_args *args = (struct ocfs2_reflink_xattr_tree_args *)para; struct ocfs2_super *osb = OCFS2_SB(inode->i_sb); struct ocfs2_alloc_context *meta_ac = NULL; struct ocfs2_alloc_context *data_ac = NULL; struct ocfs2_extent_tree et; trace_ocfs2_reflink_xattr_rec((unsigned long long)blkno, len); ocfs2_init_xattr_tree_extent_tree(&et, INODE_CACHE(args->reflink->new_inode), args->new_blk_bh); ret = ocfs2_lock_reflink_xattr_rec_allocators(args, &et, blkno, len, &credits, &meta_ac, &data_ac); if (ret) { mlog_errno(ret); goto out; } handle = ocfs2_start_trans(osb, credits); if (IS_ERR(handle)) { ret = PTR_ERR(handle); mlog_errno(ret); goto out; } ret = ocfs2_reflink_xattr_buckets(handle, inode, args, &et, meta_ac, data_ac, blkno, cpos, len); if (ret) mlog_errno(ret); ocfs2_commit_trans(osb, handle); out: if (meta_ac) ocfs2_free_alloc_context(meta_ac); if (data_ac) ocfs2_free_alloc_context(data_ac); return ret; } /* * Create reflinked xattr buckets. * We will add bucket one by one, and refcount all the xattrs in the bucket * if they are stored outside. */ static int ocfs2_reflink_xattr_tree(struct ocfs2_xattr_reflink *args, struct buffer_head *blk_bh, struct buffer_head *new_blk_bh) { int ret; struct ocfs2_reflink_xattr_tree_args para; memset(&para, 0, sizeof(para)); para.reflink = args; para.old_blk_bh = blk_bh; para.new_blk_bh = new_blk_bh; para.old_bucket = ocfs2_xattr_bucket_new(args->old_inode); if (!para.old_bucket) { mlog_errno(-ENOMEM); return -ENOMEM; } para.new_bucket = ocfs2_xattr_bucket_new(args->new_inode); if (!para.new_bucket) { ret = -ENOMEM; mlog_errno(ret); goto out; } ret = ocfs2_iterate_xattr_index_block(args->old_inode, blk_bh, ocfs2_reflink_xattr_rec, &para); if (ret) mlog_errno(ret); out: ocfs2_xattr_bucket_free(para.old_bucket); ocfs2_xattr_bucket_free(para.new_bucket); return ret; } static int ocfs2_reflink_xattr_in_block(struct ocfs2_xattr_reflink *args, struct buffer_head *blk_bh) { int ret, indexed = 0; struct buffer_head *new_blk_bh = NULL; struct ocfs2_xattr_block *xb = (struct ocfs2_xattr_block *)blk_bh->b_data; if (le16_to_cpu(xb->xb_flags) & OCFS2_XATTR_INDEXED) indexed = 1; ret = ocfs2_create_empty_xattr_block(args->new_inode, args->new_bh, &new_blk_bh, indexed); if (ret) { mlog_errno(ret); goto out; } if (!indexed) ret = ocfs2_reflink_xattr_block(args, blk_bh, new_blk_bh); else ret = ocfs2_reflink_xattr_tree(args, blk_bh, new_blk_bh); if (ret) mlog_errno(ret); out: brelse(new_blk_bh); return ret; } static int ocfs2_reflink_xattr_no_security(struct ocfs2_xattr_entry *xe) { int type = ocfs2_xattr_get_type(xe); return type != OCFS2_XATTR_INDEX_SECURITY && type != OCFS2_XATTR_INDEX_POSIX_ACL_ACCESS && type != OCFS2_XATTR_INDEX_POSIX_ACL_DEFAULT; } int ocfs2_reflink_xattrs(struct inode *old_inode, struct buffer_head *old_bh, struct inode *new_inode, struct buffer_head *new_bh, bool preserve_security) { int ret; struct ocfs2_xattr_reflink args; struct ocfs2_inode_info *oi = OCFS2_I(old_inode); struct ocfs2_dinode *di = (struct ocfs2_dinode *)old_bh->b_data; struct buffer_head *blk_bh = NULL; struct ocfs2_cached_dealloc_ctxt dealloc; struct ocfs2_refcount_tree *ref_tree; struct buffer_head *ref_root_bh = NULL; ret = ocfs2_lock_refcount_tree(OCFS2_SB(old_inode->i_sb), le64_to_cpu(di->i_refcount_loc), 1, &ref_tree, &ref_root_bh); if (ret) { mlog_errno(ret); goto out; } ocfs2_init_dealloc_ctxt(&dealloc); args.old_inode = old_inode; args.new_inode = new_inode; args.old_bh = old_bh; args.new_bh = new_bh; args.ref_ci = &ref_tree->rf_ci; args.ref_root_bh = ref_root_bh; args.dealloc = &dealloc; if (preserve_security) args.xattr_reflinked = NULL; else args.xattr_reflinked = ocfs2_reflink_xattr_no_security; if (oi->ip_dyn_features & OCFS2_INLINE_XATTR_FL) { ret = ocfs2_reflink_xattr_inline(&args); if (ret) { mlog_errno(ret); goto out_unlock; } } if (!di->i_xattr_loc) goto out_unlock; ret = ocfs2_read_xattr_block(old_inode, le64_to_cpu(di->i_xattr_loc), &blk_bh); if (ret < 0) { mlog_errno(ret); goto out_unlock; } ret = ocfs2_reflink_xattr_in_block(&args, blk_bh); if (ret) mlog_errno(ret); brelse(blk_bh); out_unlock: ocfs2_unlock_refcount_tree(OCFS2_SB(old_inode->i_sb), ref_tree, 1); brelse(ref_root_bh); if (ocfs2_dealloc_has_cluster(&dealloc)) { ocfs2_schedule_truncate_log_flush(OCFS2_SB(old_inode->i_sb), 1); ocfs2_run_deallocs(OCFS2_SB(old_inode->i_sb), &dealloc); } out: return ret; } /* * Initialize security and acl for a already created inode. * Used for reflink a non-preserve-security file. * * It uses common api like ocfs2_xattr_set, so the caller * must not hold any lock expect i_mutex. */ int ocfs2_init_security_and_acl(struct inode *dir, struct inode *inode, const struct qstr *qstr) { int ret = 0; struct buffer_head *dir_bh = NULL; ret = ocfs2_init_security_get(inode, dir, qstr, NULL); if (!ret) { mlog_errno(ret); goto leave; } ret = ocfs2_inode_lock(dir, &dir_bh, 0); if (ret) { mlog_errno(ret); goto leave; } ret = ocfs2_init_acl(NULL, inode, dir, NULL, dir_bh, NULL, NULL); if (ret) mlog_errno(ret); ocfs2_inode_unlock(dir, 0); brelse(dir_bh); leave: return ret; } /* * 'security' attributes support */ static size_t ocfs2_xattr_security_list(struct dentry *dentry, char *list, size_t list_size, const char *name, size_t name_len, int type) { const size_t prefix_len = XATTR_SECURITY_PREFIX_LEN; const size_t total_len = prefix_len + name_len + 1; if (list && total_len <= list_size) { memcpy(list, XATTR_SECURITY_PREFIX, prefix_len); memcpy(list + prefix_len, name, name_len); list[prefix_len + name_len] = '\0'; } return total_len; } static int ocfs2_xattr_security_get(struct dentry *dentry, const char *name, void *buffer, size_t size, int type) { if (strcmp(name, "") == 0) return -EINVAL; return ocfs2_xattr_get(dentry->d_inode, OCFS2_XATTR_INDEX_SECURITY, name, buffer, size); } static int ocfs2_xattr_security_set(struct dentry *dentry, const char *name, const void *value, size_t size, int flags, int type) { if (strcmp(name, "") == 0) return -EINVAL; return ocfs2_xattr_set(dentry->d_inode, OCFS2_XATTR_INDEX_SECURITY, name, value, size, flags); } int ocfs2_initxattrs(struct inode *inode, const struct xattr *xattr_array, void *fs_info) { const struct xattr *xattr; int err = 0; for (xattr = xattr_array; xattr->name != NULL; xattr++) { err = ocfs2_xattr_set(inode, OCFS2_XATTR_INDEX_SECURITY, xattr->name, xattr->value, xattr->value_len, XATTR_CREATE); if (err) break; } return err; } int ocfs2_init_security_get(struct inode *inode, struct inode *dir, const struct qstr *qstr, struct ocfs2_security_xattr_info *si) { /* check whether ocfs2 support feature xattr */ if (!ocfs2_supports_xattr(OCFS2_SB(dir->i_sb))) return -EOPNOTSUPP; if (si) return security_old_inode_init_security(inode, dir, qstr, &si->name, &si->value, &si->value_len); return security_inode_init_security(inode, dir, qstr, &ocfs2_initxattrs, NULL); } int ocfs2_init_security_set(handle_t *handle, struct inode *inode, struct buffer_head *di_bh, struct ocfs2_security_xattr_info *si, struct ocfs2_alloc_context *xattr_ac, struct ocfs2_alloc_context *data_ac) { return ocfs2_xattr_set_handle(handle, inode, di_bh, OCFS2_XATTR_INDEX_SECURITY, si->name, si->value, si->value_len, 0, xattr_ac, data_ac); } const struct xattr_handler ocfs2_xattr_security_handler = { .prefix = XATTR_SECURITY_PREFIX, .list = ocfs2_xattr_security_list, .get = ocfs2_xattr_security_get, .set = ocfs2_xattr_security_set, }; /* * 'trusted' attributes support */ static size_t ocfs2_xattr_trusted_list(struct dentry *dentry, char *list, size_t list_size, const char *name, size_t name_len, int type) { const size_t prefix_len = XATTR_TRUSTED_PREFIX_LEN; const size_t total_len = prefix_len + name_len + 1; if (list && total_len <= list_size) { memcpy(list, XATTR_TRUSTED_PREFIX, prefix_len); memcpy(list + prefix_len, name, name_len); list[prefix_len + name_len] = '\0'; } return total_len; } static int ocfs2_xattr_trusted_get(struct dentry *dentry, const char *name, void *buffer, size_t size, int type) { if (strcmp(name, "") == 0) return -EINVAL; return ocfs2_xattr_get(dentry->d_inode, OCFS2_XATTR_INDEX_TRUSTED, name, buffer, size); } static int ocfs2_xattr_trusted_set(struct dentry *dentry, const char *name, const void *value, size_t size, int flags, int type) { if (strcmp(name, "") == 0) return -EINVAL; return ocfs2_xattr_set(dentry->d_inode, OCFS2_XATTR_INDEX_TRUSTED, name, value, size, flags); } const struct xattr_handler ocfs2_xattr_trusted_handler = { .prefix = XATTR_TRUSTED_PREFIX, .list = ocfs2_xattr_trusted_list, .get = ocfs2_xattr_trusted_get, .set = ocfs2_xattr_trusted_set, }; /* * 'user' attributes support */ static size_t ocfs2_xattr_user_list(struct dentry *dentry, char *list, size_t list_size, const char *name, size_t name_len, int type) { const size_t prefix_len = XATTR_USER_PREFIX_LEN; const size_t total_len = prefix_len + name_len + 1; struct ocfs2_super *osb = OCFS2_SB(dentry->d_sb); if (osb->s_mount_opt & OCFS2_MOUNT_NOUSERXATTR) return 0; if (list && total_len <= list_size) { memcpy(list, XATTR_USER_PREFIX, prefix_len); memcpy(list + prefix_len, name, name_len); list[prefix_len + name_len] = '\0'; } return total_len; } static int ocfs2_xattr_user_get(struct dentry *dentry, const char *name, void *buffer, size_t size, int type) { struct ocfs2_super *osb = OCFS2_SB(dentry->d_sb); if (strcmp(name, "") == 0) return -EINVAL; if (osb->s_mount_opt & OCFS2_MOUNT_NOUSERXATTR) return -EOPNOTSUPP; return ocfs2_xattr_get(dentry->d_inode, OCFS2_XATTR_INDEX_USER, name, buffer, size); } static int ocfs2_xattr_user_set(struct dentry *dentry, const char *name, const void *value, size_t size, int flags, int type) { struct ocfs2_super *osb = OCFS2_SB(dentry->d_sb); if (strcmp(name, "") == 0) return -EINVAL; if (osb->s_mount_opt & OCFS2_MOUNT_NOUSERXATTR) return -EOPNOTSUPP; return ocfs2_xattr_set(dentry->d_inode, OCFS2_XATTR_INDEX_USER, name, value, size, flags); } const struct xattr_handler ocfs2_xattr_user_handler = { .prefix = XATTR_USER_PREFIX, .list = ocfs2_xattr_user_list, .get = ocfs2_xattr_user_get, .set = ocfs2_xattr_user_set, };
gpl-2.0
HashBang173/linux-kexec
arch/sh/kernel/cpu/sh3/serial-sh7720.c
4624
1083
#include <linux/serial_sci.h> #include <linux/serial_core.h> #include <linux/io.h> #include <cpu/serial.h> #include <cpu/gpio.h> static void sh7720_sci_init_pins(struct uart_port *port, unsigned int cflag) { unsigned short data; if (cflag & CRTSCTS) { /* enable RTS/CTS */ if (port->mapbase == 0xa4430000) { /* SCIF0 */ /* Clear PTCR bit 9-2; enable all scif pins but sck */ data = __raw_readw(PORT_PTCR); __raw_writew((data & 0xfc03), PORT_PTCR); } else if (port->mapbase == 0xa4438000) { /* SCIF1 */ /* Clear PVCR bit 9-2 */ data = __raw_readw(PORT_PVCR); __raw_writew((data & 0xfc03), PORT_PVCR); } } else { if (port->mapbase == 0xa4430000) { /* SCIF0 */ /* Clear PTCR bit 5-2; enable only tx and rx */ data = __raw_readw(PORT_PTCR); __raw_writew((data & 0xffc3), PORT_PTCR); } else if (port->mapbase == 0xa4438000) { /* SCIF1 */ /* Clear PVCR bit 5-2 */ data = __raw_readw(PORT_PVCR); __raw_writew((data & 0xffc3), PORT_PVCR); } } } struct plat_sci_port_ops sh7720_sci_port_ops = { .init_pins = sh7720_sci_init_pins, };
gpl-2.0
jmztaylor/android_kernel_htc_a3ul_old
drivers/staging/iio/cdc/ad7150.c
4880
17854
/* * AD7150 capacitive sensor driver supporting AD7150/1/6 * * Copyright 2010-2011 Analog Devices Inc. * * Licensed under the GPL-2 or later. */ #include <linux/interrupt.h> #include <linux/device.h> #include <linux/kernel.h> #include <linux/slab.h> #include <linux/i2c.h> #include <linux/module.h> #include "../iio.h" #include "../sysfs.h" #include "../events.h" /* * AD7150 registers definition */ #define AD7150_STATUS 0 #define AD7150_STATUS_OUT1 (1 << 3) #define AD7150_STATUS_OUT2 (1 << 5) #define AD7150_CH1_DATA_HIGH 1 #define AD7150_CH2_DATA_HIGH 3 #define AD7150_CH1_AVG_HIGH 5 #define AD7150_CH2_AVG_HIGH 7 #define AD7150_CH1_SENSITIVITY 9 #define AD7150_CH1_THR_HOLD_H 9 #define AD7150_CH1_TIMEOUT 10 #define AD7150_CH1_SETUP 11 #define AD7150_CH2_SENSITIVITY 12 #define AD7150_CH2_THR_HOLD_H 12 #define AD7150_CH2_TIMEOUT 13 #define AD7150_CH2_SETUP 14 #define AD7150_CFG 15 #define AD7150_CFG_FIX (1 << 7) #define AD7150_PD_TIMER 16 #define AD7150_CH1_CAPDAC 17 #define AD7150_CH2_CAPDAC 18 #define AD7150_SN3 19 #define AD7150_SN2 20 #define AD7150_SN1 21 #define AD7150_SN0 22 #define AD7150_ID 23 /** * struct ad7150_chip_info - instance specific chip data * @client: i2c client for this device * @current_event: device always has one type of event enabled. * This element stores the event code of the current one. * @threshold: thresholds for simple capacitance value events * @thresh_sensitivity: threshold for simple capacitance offset * from 'average' value. * @mag_sensitity: threshold for magnitude of capacitance offset from * from 'average' value. * @thresh_timeout: a timeout, in samples from the moment an * adaptive threshold event occurs to when the average * value jumps to current value. * @mag_timeout: a timeout, in sample from the moment an * adaptive magnitude event occurs to when the average * value jumps to the current value. * @old_state: store state from previous event, allowing confirmation * of new condition. * @conversion_mode: the current conversion mode. * @state_lock: ensure consistent state of this structure wrt the * hardware. */ struct ad7150_chip_info { struct i2c_client *client; u64 current_event; u16 threshold[2][2]; u8 thresh_sensitivity[2][2]; u8 mag_sensitivity[2][2]; u8 thresh_timeout[2][2]; u8 mag_timeout[2][2]; int old_state; char *conversion_mode; struct mutex state_lock; }; /* * sysfs nodes */ static const u8 ad7150_addresses[][6] = { { AD7150_CH1_DATA_HIGH, AD7150_CH1_AVG_HIGH, AD7150_CH1_SETUP, AD7150_CH1_THR_HOLD_H, AD7150_CH1_SENSITIVITY, AD7150_CH1_TIMEOUT }, { AD7150_CH2_DATA_HIGH, AD7150_CH2_AVG_HIGH, AD7150_CH2_SETUP, AD7150_CH2_THR_HOLD_H, AD7150_CH2_SENSITIVITY, AD7150_CH2_TIMEOUT }, }; static int ad7150_read_raw(struct iio_dev *indio_dev, struct iio_chan_spec const *chan, int *val, int *val2, long mask) { int ret; struct ad7150_chip_info *chip = iio_priv(indio_dev); switch (mask) { case 0: ret = i2c_smbus_read_word_data(chip->client, ad7150_addresses[chan->channel][0]); if (ret < 0) return ret; *val = swab16(ret); return IIO_VAL_INT; case IIO_CHAN_INFO_AVERAGE_RAW: ret = i2c_smbus_read_word_data(chip->client, ad7150_addresses[chan->channel][1]); if (ret < 0) return ret; *val = swab16(ret); return IIO_VAL_INT; default: return -EINVAL; } } static int ad7150_read_event_config(struct iio_dev *indio_dev, u64 event_code) { int ret; u8 threshtype; bool adaptive; struct ad7150_chip_info *chip = iio_priv(indio_dev); int rising = !!(IIO_EVENT_CODE_EXTRACT_DIR(event_code) == IIO_EV_DIR_RISING); ret = i2c_smbus_read_byte_data(chip->client, AD7150_CFG); if (ret < 0) return ret; threshtype = (ret >> 5) & 0x03; adaptive = !!(ret & 0x80); switch (IIO_EVENT_CODE_EXTRACT_TYPE(event_code)) { case IIO_EV_TYPE_MAG_ADAPTIVE: if (rising) return adaptive && (threshtype == 0x1); else return adaptive && (threshtype == 0x0); case IIO_EV_TYPE_THRESH_ADAPTIVE: if (rising) return adaptive && (threshtype == 0x3); else return adaptive && (threshtype == 0x2); case IIO_EV_TYPE_THRESH: if (rising) return !adaptive && (threshtype == 0x1); else return !adaptive && (threshtype == 0x0); }; return -EINVAL; } /* lock should be held */ static int ad7150_write_event_params(struct iio_dev *indio_dev, u64 event_code) { int ret; u16 value; u8 sens, timeout; struct ad7150_chip_info *chip = iio_priv(indio_dev); int chan = IIO_EVENT_CODE_EXTRACT_CHAN(event_code); int rising = !!(IIO_EVENT_CODE_EXTRACT_DIR(event_code) == IIO_EV_DIR_RISING); if (event_code != chip->current_event) return 0; switch (IIO_EVENT_CODE_EXTRACT_TYPE(event_code)) { /* Note completely different from the adaptive versions */ case IIO_EV_TYPE_THRESH: value = chip->threshold[rising][chan]; ret = i2c_smbus_write_word_data(chip->client, ad7150_addresses[chan][3], swab16(value)); if (ret < 0) return ret; return 0; case IIO_EV_TYPE_MAG_ADAPTIVE: sens = chip->mag_sensitivity[rising][chan]; timeout = chip->mag_timeout[rising][chan]; break; case IIO_EV_TYPE_THRESH_ADAPTIVE: sens = chip->thresh_sensitivity[rising][chan]; timeout = chip->thresh_timeout[rising][chan]; break; default: return -EINVAL; }; ret = i2c_smbus_write_byte_data(chip->client, ad7150_addresses[chan][4], sens); if (ret < 0) return ret; ret = i2c_smbus_write_byte_data(chip->client, ad7150_addresses[chan][5], timeout); if (ret < 0) return ret; return 0; } static int ad7150_write_event_config(struct iio_dev *indio_dev, u64 event_code, int state) { u8 thresh_type, cfg, adaptive; int ret; struct ad7150_chip_info *chip = iio_priv(indio_dev); int rising = !!(IIO_EVENT_CODE_EXTRACT_DIR(event_code) == IIO_EV_DIR_RISING); /* Something must always be turned on */ if (state == 0) return -EINVAL; if (event_code == chip->current_event) return 0; mutex_lock(&chip->state_lock); ret = i2c_smbus_read_byte_data(chip->client, AD7150_CFG); if (ret < 0) goto error_ret; cfg = ret & ~((0x03 << 5) | (0x1 << 7)); switch (IIO_EVENT_CODE_EXTRACT_TYPE(event_code)) { case IIO_EV_TYPE_MAG_ADAPTIVE: adaptive = 1; if (rising) thresh_type = 0x1; else thresh_type = 0x0; break; case IIO_EV_TYPE_THRESH_ADAPTIVE: adaptive = 1; if (rising) thresh_type = 0x3; else thresh_type = 0x2; break; case IIO_EV_TYPE_THRESH: adaptive = 0; if (rising) thresh_type = 0x1; else thresh_type = 0x0; break; default: ret = -EINVAL; goto error_ret; }; cfg |= (!adaptive << 7) | (thresh_type << 5); ret = i2c_smbus_write_byte_data(chip->client, AD7150_CFG, cfg); if (ret < 0) goto error_ret; chip->current_event = event_code; /* update control attributes */ ret = ad7150_write_event_params(indio_dev, event_code); error_ret: mutex_unlock(&chip->state_lock); return 0; } static int ad7150_read_event_value(struct iio_dev *indio_dev, u64 event_code, int *val) { int chan = IIO_EVENT_CODE_EXTRACT_CHAN(event_code); struct ad7150_chip_info *chip = iio_priv(indio_dev); int rising = !!(IIO_EVENT_CODE_EXTRACT_DIR(event_code) == IIO_EV_DIR_RISING); /* Complex register sharing going on here */ switch (IIO_EVENT_CODE_EXTRACT_TYPE(event_code)) { case IIO_EV_TYPE_MAG_ADAPTIVE: *val = chip->mag_sensitivity[rising][chan]; return 0; case IIO_EV_TYPE_THRESH_ADAPTIVE: *val = chip->thresh_sensitivity[rising][chan]; return 0; case IIO_EV_TYPE_THRESH: *val = chip->threshold[rising][chan]; return 0; default: return -EINVAL; }; } static int ad7150_write_event_value(struct iio_dev *indio_dev, u64 event_code, int val) { int ret; struct ad7150_chip_info *chip = iio_priv(indio_dev); int chan = IIO_EVENT_CODE_EXTRACT_CHAN(event_code); int rising = !!(IIO_EVENT_CODE_EXTRACT_DIR(event_code) == IIO_EV_DIR_RISING); mutex_lock(&chip->state_lock); switch (IIO_EVENT_CODE_EXTRACT_TYPE(event_code)) { case IIO_EV_TYPE_MAG_ADAPTIVE: chip->mag_sensitivity[rising][chan] = val; break; case IIO_EV_TYPE_THRESH_ADAPTIVE: chip->thresh_sensitivity[rising][chan] = val; break; case IIO_EV_TYPE_THRESH: chip->threshold[rising][chan] = val; break; default: ret = -EINVAL; goto error_ret; }; /* write back if active */ ret = ad7150_write_event_params(indio_dev, event_code); error_ret: mutex_unlock(&chip->state_lock); return ret; } static ssize_t ad7150_show_timeout(struct device *dev, struct device_attribute *attr, char *buf) { struct iio_dev *indio_dev = dev_get_drvdata(dev); struct ad7150_chip_info *chip = iio_priv(indio_dev); struct iio_dev_attr *this_attr = to_iio_dev_attr(attr); u8 value; /* use the event code for consistency reasons */ int chan = IIO_EVENT_CODE_EXTRACT_CHAN(this_attr->address); int rising = !!(IIO_EVENT_CODE_EXTRACT_DIR(this_attr->address) == IIO_EV_DIR_RISING); switch (IIO_EVENT_CODE_EXTRACT_TYPE(this_attr->address)) { case IIO_EV_TYPE_MAG_ADAPTIVE: value = chip->mag_timeout[rising][chan]; break; case IIO_EV_TYPE_THRESH_ADAPTIVE: value = chip->thresh_timeout[rising][chan]; break; default: return -EINVAL; }; return sprintf(buf, "%d\n", value); } static ssize_t ad7150_store_timeout(struct device *dev, struct device_attribute *attr, const char *buf, size_t len) { struct iio_dev *indio_dev = dev_get_drvdata(dev); struct ad7150_chip_info *chip = iio_priv(indio_dev); struct iio_dev_attr *this_attr = to_iio_dev_attr(attr); int chan = IIO_EVENT_CODE_EXTRACT_CHAN(this_attr->address); int rising = !!(IIO_EVENT_CODE_EXTRACT_DIR(this_attr->address) == IIO_EV_DIR_RISING); u8 data; int ret; ret = kstrtou8(buf, 10, &data); if (ret < 0) return ret; mutex_lock(&chip->state_lock); switch (IIO_EVENT_CODE_EXTRACT_TYPE(this_attr->address)) { case IIO_EV_TYPE_MAG_ADAPTIVE: chip->mag_timeout[rising][chan] = data; break; case IIO_EV_TYPE_THRESH_ADAPTIVE: chip->thresh_timeout[rising][chan] = data; break; default: ret = -EINVAL; goto error_ret; }; ret = ad7150_write_event_params(indio_dev, this_attr->address); error_ret: mutex_unlock(&chip->state_lock); if (ret < 0) return ret; return len; } #define AD7150_TIMEOUT(chan, type, dir, ev_type, ev_dir) \ IIO_DEVICE_ATTR(in_capacitance##chan##_##type##_##dir##_timeout, \ S_IRUGO | S_IWUSR, \ &ad7150_show_timeout, \ &ad7150_store_timeout, \ IIO_UNMOD_EVENT_CODE(IIO_CAPACITANCE, \ chan, \ IIO_EV_TYPE_##ev_type, \ IIO_EV_DIR_##ev_dir)) static AD7150_TIMEOUT(0, mag_adaptive, rising, MAG_ADAPTIVE, RISING); static AD7150_TIMEOUT(0, mag_adaptive, falling, MAG_ADAPTIVE, FALLING); static AD7150_TIMEOUT(1, mag_adaptive, rising, MAG_ADAPTIVE, RISING); static AD7150_TIMEOUT(1, mag_adaptive, falling, MAG_ADAPTIVE, FALLING); static AD7150_TIMEOUT(0, thresh_adaptive, rising, THRESH_ADAPTIVE, RISING); static AD7150_TIMEOUT(0, thresh_adaptive, falling, THRESH_ADAPTIVE, FALLING); static AD7150_TIMEOUT(1, thresh_adaptive, rising, THRESH_ADAPTIVE, RISING); static AD7150_TIMEOUT(1, thresh_adaptive, falling, THRESH_ADAPTIVE, FALLING); static const struct iio_chan_spec ad7150_channels[] = { { .type = IIO_CAPACITANCE, .indexed = 1, .channel = 0, .info_mask = IIO_CHAN_INFO_AVERAGE_RAW_SEPARATE_BIT, .event_mask = IIO_EV_BIT(IIO_EV_TYPE_THRESH, IIO_EV_DIR_RISING) | IIO_EV_BIT(IIO_EV_TYPE_THRESH, IIO_EV_DIR_FALLING) | IIO_EV_BIT(IIO_EV_TYPE_THRESH_ADAPTIVE, IIO_EV_DIR_RISING) | IIO_EV_BIT(IIO_EV_TYPE_THRESH_ADAPTIVE, IIO_EV_DIR_FALLING) | IIO_EV_BIT(IIO_EV_TYPE_MAG_ADAPTIVE, IIO_EV_DIR_RISING) | IIO_EV_BIT(IIO_EV_TYPE_MAG_ADAPTIVE, IIO_EV_DIR_FALLING) }, { .type = IIO_CAPACITANCE, .indexed = 1, .channel = 1, .info_mask = IIO_CHAN_INFO_AVERAGE_RAW_SEPARATE_BIT, .event_mask = IIO_EV_BIT(IIO_EV_TYPE_THRESH, IIO_EV_DIR_RISING) | IIO_EV_BIT(IIO_EV_TYPE_THRESH, IIO_EV_DIR_FALLING) | IIO_EV_BIT(IIO_EV_TYPE_THRESH_ADAPTIVE, IIO_EV_DIR_RISING) | IIO_EV_BIT(IIO_EV_TYPE_THRESH_ADAPTIVE, IIO_EV_DIR_FALLING) | IIO_EV_BIT(IIO_EV_TYPE_MAG_ADAPTIVE, IIO_EV_DIR_RISING) | IIO_EV_BIT(IIO_EV_TYPE_MAG_ADAPTIVE, IIO_EV_DIR_FALLING) }, }; /* * threshold events */ static irqreturn_t ad7150_event_handler(int irq, void *private) { struct iio_dev *indio_dev = private; struct ad7150_chip_info *chip = iio_priv(indio_dev); u8 int_status; s64 timestamp = iio_get_time_ns(); int ret; ret = i2c_smbus_read_byte_data(chip->client, AD7150_STATUS); if (ret < 0) return IRQ_HANDLED; int_status = ret; if ((int_status & AD7150_STATUS_OUT1) && !(chip->old_state & AD7150_STATUS_OUT1)) iio_push_event(indio_dev, IIO_UNMOD_EVENT_CODE(IIO_CAPACITANCE, 0, IIO_EV_TYPE_THRESH, IIO_EV_DIR_RISING), timestamp); else if ((!(int_status & AD7150_STATUS_OUT1)) && (chip->old_state & AD7150_STATUS_OUT1)) iio_push_event(indio_dev, IIO_UNMOD_EVENT_CODE(IIO_CAPACITANCE, 0, IIO_EV_TYPE_THRESH, IIO_EV_DIR_FALLING), timestamp); if ((int_status & AD7150_STATUS_OUT2) && !(chip->old_state & AD7150_STATUS_OUT2)) iio_push_event(indio_dev, IIO_UNMOD_EVENT_CODE(IIO_CAPACITANCE, 1, IIO_EV_TYPE_THRESH, IIO_EV_DIR_RISING), timestamp); else if ((!(int_status & AD7150_STATUS_OUT2)) && (chip->old_state & AD7150_STATUS_OUT2)) iio_push_event(indio_dev, IIO_UNMOD_EVENT_CODE(IIO_CAPACITANCE, 1, IIO_EV_TYPE_THRESH, IIO_EV_DIR_FALLING), timestamp); /* store the status to avoid repushing same events */ chip->old_state = int_status; return IRQ_HANDLED; } /* Timeouts not currently handled by core */ static struct attribute *ad7150_event_attributes[] = { &iio_dev_attr_in_capacitance0_mag_adaptive_rising_timeout .dev_attr.attr, &iio_dev_attr_in_capacitance0_mag_adaptive_falling_timeout .dev_attr.attr, &iio_dev_attr_in_capacitance1_mag_adaptive_rising_timeout .dev_attr.attr, &iio_dev_attr_in_capacitance1_mag_adaptive_falling_timeout .dev_attr.attr, &iio_dev_attr_in_capacitance0_thresh_adaptive_rising_timeout .dev_attr.attr, &iio_dev_attr_in_capacitance0_thresh_adaptive_falling_timeout .dev_attr.attr, &iio_dev_attr_in_capacitance1_thresh_adaptive_rising_timeout .dev_attr.attr, &iio_dev_attr_in_capacitance1_thresh_adaptive_falling_timeout .dev_attr.attr, NULL, }; static struct attribute_group ad7150_event_attribute_group = { .attrs = ad7150_event_attributes, .name = "events", }; static const struct iio_info ad7150_info = { .event_attrs = &ad7150_event_attribute_group, .driver_module = THIS_MODULE, .read_raw = &ad7150_read_raw, .read_event_config = &ad7150_read_event_config, .write_event_config = &ad7150_write_event_config, .read_event_value = &ad7150_read_event_value, .write_event_value = &ad7150_write_event_value, }; /* * device probe and remove */ static int __devinit ad7150_probe(struct i2c_client *client, const struct i2c_device_id *id) { int ret; struct ad7150_chip_info *chip; struct iio_dev *indio_dev; indio_dev = iio_allocate_device(sizeof(*chip)); if (indio_dev == NULL) { ret = -ENOMEM; goto error_ret; } chip = iio_priv(indio_dev); mutex_init(&chip->state_lock); /* this is only used for device removal purposes */ i2c_set_clientdata(client, indio_dev); chip->client = client; indio_dev->name = id->name; indio_dev->channels = ad7150_channels; indio_dev->num_channels = ARRAY_SIZE(ad7150_channels); /* Establish that the iio_dev is a child of the i2c device */ indio_dev->dev.parent = &client->dev; indio_dev->info = &ad7150_info; indio_dev->modes = INDIO_DIRECT_MODE; if (client->irq) { ret = request_threaded_irq(client->irq, NULL, &ad7150_event_handler, IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING, "ad7150_irq1", indio_dev); if (ret) goto error_free_dev; } if (client->dev.platform_data) { ret = request_threaded_irq(*(unsigned int *) client->dev.platform_data, NULL, &ad7150_event_handler, IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING, "ad7150_irq2", indio_dev); if (ret) goto error_free_irq; } ret = iio_device_register(indio_dev); if (ret) goto error_free_irq2; dev_info(&client->dev, "%s capacitive sensor registered,irq: %d\n", id->name, client->irq); return 0; error_free_irq2: if (client->dev.platform_data) free_irq(*(unsigned int *)client->dev.platform_data, indio_dev); error_free_irq: if (client->irq) free_irq(client->irq, indio_dev); error_free_dev: iio_free_device(indio_dev); error_ret: return ret; } static int __devexit ad7150_remove(struct i2c_client *client) { struct iio_dev *indio_dev = i2c_get_clientdata(client); iio_device_unregister(indio_dev); if (client->irq) free_irq(client->irq, indio_dev); if (client->dev.platform_data) free_irq(*(unsigned int *)client->dev.platform_data, indio_dev); iio_free_device(indio_dev); return 0; } static const struct i2c_device_id ad7150_id[] = { { "ad7150", 0 }, { "ad7151", 0 }, { "ad7156", 0 }, {} }; MODULE_DEVICE_TABLE(i2c, ad7150_id); static struct i2c_driver ad7150_driver = { .driver = { .name = "ad7150", }, .probe = ad7150_probe, .remove = __devexit_p(ad7150_remove), .id_table = ad7150_id, }; module_i2c_driver(ad7150_driver); MODULE_AUTHOR("Barry Song <21cnbao@gmail.com>"); MODULE_DESCRIPTION("Analog Devices AD7150/1/6 capacitive sensor driver"); MODULE_LICENSE("GPL v2");
gpl-2.0
Stuxnet-Kernel/kernel_g3
net/bluetooth/cmtp/sock.c
7696
5556
/* CMTP implementation for Linux Bluetooth stack (BlueZ). Copyright (C) 2002-2003 Marcel Holtmann <marcel@holtmann.org> This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License version 2 as published by the Free Software Foundation; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) AND AUTHOR(S) BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. ALL LIABILITY, INCLUDING LIABILITY FOR INFRINGEMENT OF ANY PATENTS, COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS, RELATING TO USE OF THIS SOFTWARE IS DISCLAIMED. */ #include <linux/module.h> #include <linux/types.h> #include <linux/capability.h> #include <linux/errno.h> #include <linux/kernel.h> #include <linux/poll.h> #include <linux/fcntl.h> #include <linux/skbuff.h> #include <linux/socket.h> #include <linux/ioctl.h> #include <linux/file.h> #include <linux/compat.h> #include <linux/gfp.h> #include <linux/uaccess.h> #include <net/sock.h> #include <linux/isdn/capilli.h> #include <asm/system.h> #include "cmtp.h" static int cmtp_sock_release(struct socket *sock) { struct sock *sk = sock->sk; BT_DBG("sock %p sk %p", sock, sk); if (!sk) return 0; sock_orphan(sk); sock_put(sk); return 0; } static int cmtp_sock_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg) { struct cmtp_connadd_req ca; struct cmtp_conndel_req cd; struct cmtp_connlist_req cl; struct cmtp_conninfo ci; struct socket *nsock; void __user *argp = (void __user *)arg; int err; BT_DBG("cmd %x arg %lx", cmd, arg); switch (cmd) { case CMTPCONNADD: if (!capable(CAP_NET_ADMIN)) return -EACCES; if (copy_from_user(&ca, argp, sizeof(ca))) return -EFAULT; nsock = sockfd_lookup(ca.sock, &err); if (!nsock) return err; if (nsock->sk->sk_state != BT_CONNECTED) { sockfd_put(nsock); return -EBADFD; } err = cmtp_add_connection(&ca, nsock); if (!err) { if (copy_to_user(argp, &ca, sizeof(ca))) err = -EFAULT; } else sockfd_put(nsock); return err; case CMTPCONNDEL: if (!capable(CAP_NET_ADMIN)) return -EACCES; if (copy_from_user(&cd, argp, sizeof(cd))) return -EFAULT; return cmtp_del_connection(&cd); case CMTPGETCONNLIST: if (copy_from_user(&cl, argp, sizeof(cl))) return -EFAULT; if (cl.cnum <= 0) return -EINVAL; err = cmtp_get_connlist(&cl); if (!err && copy_to_user(argp, &cl, sizeof(cl))) return -EFAULT; return err; case CMTPGETCONNINFO: if (copy_from_user(&ci, argp, sizeof(ci))) return -EFAULT; err = cmtp_get_conninfo(&ci); if (!err && copy_to_user(argp, &ci, sizeof(ci))) return -EFAULT; return err; } return -EINVAL; } #ifdef CONFIG_COMPAT static int cmtp_sock_compat_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg) { if (cmd == CMTPGETCONNLIST) { struct cmtp_connlist_req cl; uint32_t uci; int err; if (get_user(cl.cnum, (uint32_t __user *) arg) || get_user(uci, (u32 __user *) (arg + 4))) return -EFAULT; cl.ci = compat_ptr(uci); if (cl.cnum <= 0) return -EINVAL; err = cmtp_get_connlist(&cl); if (!err && put_user(cl.cnum, (uint32_t __user *) arg)) err = -EFAULT; return err; } return cmtp_sock_ioctl(sock, cmd, arg); } #endif static const struct proto_ops cmtp_sock_ops = { .family = PF_BLUETOOTH, .owner = THIS_MODULE, .release = cmtp_sock_release, .ioctl = cmtp_sock_ioctl, #ifdef CONFIG_COMPAT .compat_ioctl = cmtp_sock_compat_ioctl, #endif .bind = sock_no_bind, .getname = sock_no_getname, .sendmsg = sock_no_sendmsg, .recvmsg = sock_no_recvmsg, .poll = sock_no_poll, .listen = sock_no_listen, .shutdown = sock_no_shutdown, .setsockopt = sock_no_setsockopt, .getsockopt = sock_no_getsockopt, .connect = sock_no_connect, .socketpair = sock_no_socketpair, .accept = sock_no_accept, .mmap = sock_no_mmap }; static struct proto cmtp_proto = { .name = "CMTP", .owner = THIS_MODULE, .obj_size = sizeof(struct bt_sock) }; static int cmtp_sock_create(struct net *net, struct socket *sock, int protocol, int kern) { struct sock *sk; BT_DBG("sock %p", sock); if (sock->type != SOCK_RAW) return -ESOCKTNOSUPPORT; sk = sk_alloc(net, PF_BLUETOOTH, GFP_ATOMIC, &cmtp_proto); if (!sk) return -ENOMEM; sock_init_data(sock, sk); sock->ops = &cmtp_sock_ops; sock->state = SS_UNCONNECTED; sock_reset_flag(sk, SOCK_ZAPPED); sk->sk_protocol = protocol; sk->sk_state = BT_OPEN; return 0; } static const struct net_proto_family cmtp_sock_family_ops = { .family = PF_BLUETOOTH, .owner = THIS_MODULE, .create = cmtp_sock_create }; int cmtp_init_sockets(void) { int err; err = proto_register(&cmtp_proto, 0); if (err < 0) return err; err = bt_sock_register(BTPROTO_CMTP, &cmtp_sock_family_ops); if (err < 0) goto error; return 0; error: BT_ERR("Can't register CMTP socket"); proto_unregister(&cmtp_proto); return err; } void cmtp_cleanup_sockets(void) { if (bt_sock_unregister(BTPROTO_CMTP) < 0) BT_ERR("Can't unregister CMTP socket"); proto_unregister(&cmtp_proto); }
gpl-2.0
JellyBeanNitro/kernel-iproj-3.4
drivers/staging/rts_pstor/general.c
8208
1029
/* Driver for Realtek PCI-Express card reader * * Copyright(c) 2009 Realtek Semiconductor Corp. All rights reserved. * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the * Free Software Foundation; either version 2, or (at your option) any * later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, see <http://www.gnu.org/licenses/>. * * Author: * wwang (wei_wang@realsil.com.cn) * No. 450, Shenhu Road, Suzhou Industry Park, Suzhou, China */ #include "general.h" int bit1cnt_long(u32 data) { int i, cnt = 0; for (i = 0; i < 32; i++) { if (data & 0x01) cnt++; data >>= 1; } return cnt; }
gpl-2.0
Euphoria-OS/android_kernel_msm
drivers/usb/serial/console.c
8464
7577
/* * USB Serial Console driver * * Copyright (C) 2001 - 2002 Greg Kroah-Hartman (greg@kroah.com) * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License version * 2 as published by the Free Software Foundation. * * Thanks to Randy Dunlap for the original version of this code. * */ #include <linux/kernel.h> #include <linux/init.h> #include <linux/slab.h> #include <linux/tty.h> #include <linux/console.h> #include <linux/serial.h> #include <linux/usb.h> #include <linux/usb/serial.h> static int debug; struct usbcons_info { int magic; int break_flag; struct usb_serial_port *port; }; static struct usbcons_info usbcons_info; static struct console usbcons; /* * ------------------------------------------------------------ * USB Serial console driver * * Much of the code here is copied from drivers/char/serial.c * and implements a phony serial console in the same way that * serial.c does so that in case some software queries it, * it will get the same results. * * Things that are different from the way the serial port code * does things, is that we call the lower level usb-serial * driver code to initialize the device, and we set the initial * console speeds based on the command line arguments. * ------------------------------------------------------------ */ /* * The parsing of the command line works exactly like the * serial.c code, except that the specifier is "ttyUSB" instead * of "ttyS". */ static int usb_console_setup(struct console *co, char *options) { struct usbcons_info *info = &usbcons_info; int baud = 9600; int bits = 8; int parity = 'n'; int doflow = 0; int cflag = CREAD | HUPCL | CLOCAL; char *s; struct usb_serial *serial; struct usb_serial_port *port; int retval; struct tty_struct *tty = NULL; struct ktermios dummy; dbg("%s", __func__); if (options) { baud = simple_strtoul(options, NULL, 10); s = options; while (*s >= '0' && *s <= '9') s++; if (*s) parity = *s++; if (*s) bits = *s++ - '0'; if (*s) doflow = (*s++ == 'r'); } /* Sane default */ if (baud == 0) baud = 9600; switch (bits) { case 7: cflag |= CS7; break; default: case 8: cflag |= CS8; break; } switch (parity) { case 'o': case 'O': cflag |= PARODD; break; case 'e': case 'E': cflag |= PARENB; break; } co->cflag = cflag; /* * no need to check the index here: if the index is wrong, console * code won't call us */ serial = usb_serial_get_by_index(co->index); if (serial == NULL) { /* no device is connected yet, sorry :( */ err("No USB device connected to ttyUSB%i", co->index); return -ENODEV; } retval = usb_autopm_get_interface(serial->interface); if (retval) goto error_get_interface; port = serial->port[co->index - serial->minor]; tty_port_tty_set(&port->port, NULL); info->port = port; ++port->port.count; if (!test_bit(ASYNCB_INITIALIZED, &port->port.flags)) { if (serial->type->set_termios) { /* * allocate a fake tty so the driver can initialize * the termios structure, then later call set_termios to * configure according to command line arguments */ tty = kzalloc(sizeof(*tty), GFP_KERNEL); if (!tty) { retval = -ENOMEM; err("no more memory"); goto reset_open_count; } kref_init(&tty->kref); tty_port_tty_set(&port->port, tty); tty->driver = usb_serial_tty_driver; tty->index = co->index; if (tty_init_termios(tty)) { retval = -ENOMEM; err("no more memory"); goto free_tty; } } /* only call the device specific open if this * is the first time the port is opened */ if (serial->type->open) retval = serial->type->open(NULL, port); else retval = usb_serial_generic_open(NULL, port); if (retval) { err("could not open USB console port"); goto fail; } if (serial->type->set_termios) { tty->termios->c_cflag = cflag; tty_termios_encode_baud_rate(tty->termios, baud, baud); memset(&dummy, 0, sizeof(struct ktermios)); serial->type->set_termios(tty, port, &dummy); tty_port_tty_set(&port->port, NULL); kfree(tty); } set_bit(ASYNCB_INITIALIZED, &port->port.flags); } /* Now that any required fake tty operations are completed restore * the tty port count */ --port->port.count; /* The console is special in terms of closing the device so * indicate this port is now acting as a system console. */ port->port.console = 1; mutex_unlock(&serial->disc_mutex); return retval; fail: tty_port_tty_set(&port->port, NULL); free_tty: kfree(tty); reset_open_count: port->port.count = 0; usb_autopm_put_interface(serial->interface); error_get_interface: usb_serial_put(serial); mutex_unlock(&serial->disc_mutex); return retval; } static void usb_console_write(struct console *co, const char *buf, unsigned count) { static struct usbcons_info *info = &usbcons_info; struct usb_serial_port *port = info->port; struct usb_serial *serial; int retval = -ENODEV; if (!port || port->serial->dev->state == USB_STATE_NOTATTACHED) return; serial = port->serial; if (count == 0) return; dbg("%s - port %d, %d byte(s)", __func__, port->number, count); if (!port->port.console) { dbg("%s - port not opened", __func__); return; } while (count) { unsigned int i; unsigned int lf; /* search for LF so we can insert CR if necessary */ for (i = 0, lf = 0 ; i < count ; i++) { if (*(buf + i) == 10) { lf = 1; i++; break; } } /* pass on to the driver specific version of this function if it is available */ if (serial->type->write) retval = serial->type->write(NULL, port, buf, i); else retval = usb_serial_generic_write(NULL, port, buf, i); dbg("%s - return value : %d", __func__, retval); if (lf) { /* append CR after LF */ unsigned char cr = 13; if (serial->type->write) retval = serial->type->write(NULL, port, &cr, 1); else retval = usb_serial_generic_write(NULL, port, &cr, 1); dbg("%s - return value : %d", __func__, retval); } buf += i; count -= i; } } static struct tty_driver *usb_console_device(struct console *co, int *index) { struct tty_driver **p = (struct tty_driver **)co->data; if (!*p) return NULL; *index = co->index; return *p; } static struct console usbcons = { .name = "ttyUSB", .write = usb_console_write, .device = usb_console_device, .setup = usb_console_setup, .flags = CON_PRINTBUFFER, .index = -1, .data = &usb_serial_tty_driver, }; void usb_serial_console_disconnect(struct usb_serial *serial) { if (serial && serial->port && serial->port[0] && serial->port[0] == usbcons_info.port) { usb_serial_console_exit(); usb_serial_put(serial); } } void usb_serial_console_init(int serial_debug, int minor) { debug = serial_debug; if (minor == 0) { /* * Call register_console() if this is the first device plugged * in. If we call it earlier, then the callback to * console_setup() will fail, as there is not a device seen by * the USB subsystem yet. */ /* * Register console. * NOTES: * console_setup() is called (back) immediately (from * register_console). console_write() is called immediately * from register_console iff CON_PRINTBUFFER is set in flags. */ dbg("registering the USB serial console."); register_console(&usbcons); } } void usb_serial_console_exit(void) { if (usbcons_info.port) { unregister_console(&usbcons); usbcons_info.port->port.console = 0; usbcons_info.port = NULL; } }
gpl-2.0
Eliminater74/cm_android_kernel_g3_patched
drivers/usb/serial/console.c
8464
7577
/* * USB Serial Console driver * * Copyright (C) 2001 - 2002 Greg Kroah-Hartman (greg@kroah.com) * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License version * 2 as published by the Free Software Foundation. * * Thanks to Randy Dunlap for the original version of this code. * */ #include <linux/kernel.h> #include <linux/init.h> #include <linux/slab.h> #include <linux/tty.h> #include <linux/console.h> #include <linux/serial.h> #include <linux/usb.h> #include <linux/usb/serial.h> static int debug; struct usbcons_info { int magic; int break_flag; struct usb_serial_port *port; }; static struct usbcons_info usbcons_info; static struct console usbcons; /* * ------------------------------------------------------------ * USB Serial console driver * * Much of the code here is copied from drivers/char/serial.c * and implements a phony serial console in the same way that * serial.c does so that in case some software queries it, * it will get the same results. * * Things that are different from the way the serial port code * does things, is that we call the lower level usb-serial * driver code to initialize the device, and we set the initial * console speeds based on the command line arguments. * ------------------------------------------------------------ */ /* * The parsing of the command line works exactly like the * serial.c code, except that the specifier is "ttyUSB" instead * of "ttyS". */ static int usb_console_setup(struct console *co, char *options) { struct usbcons_info *info = &usbcons_info; int baud = 9600; int bits = 8; int parity = 'n'; int doflow = 0; int cflag = CREAD | HUPCL | CLOCAL; char *s; struct usb_serial *serial; struct usb_serial_port *port; int retval; struct tty_struct *tty = NULL; struct ktermios dummy; dbg("%s", __func__); if (options) { baud = simple_strtoul(options, NULL, 10); s = options; while (*s >= '0' && *s <= '9') s++; if (*s) parity = *s++; if (*s) bits = *s++ - '0'; if (*s) doflow = (*s++ == 'r'); } /* Sane default */ if (baud == 0) baud = 9600; switch (bits) { case 7: cflag |= CS7; break; default: case 8: cflag |= CS8; break; } switch (parity) { case 'o': case 'O': cflag |= PARODD; break; case 'e': case 'E': cflag |= PARENB; break; } co->cflag = cflag; /* * no need to check the index here: if the index is wrong, console * code won't call us */ serial = usb_serial_get_by_index(co->index); if (serial == NULL) { /* no device is connected yet, sorry :( */ err("No USB device connected to ttyUSB%i", co->index); return -ENODEV; } retval = usb_autopm_get_interface(serial->interface); if (retval) goto error_get_interface; port = serial->port[co->index - serial->minor]; tty_port_tty_set(&port->port, NULL); info->port = port; ++port->port.count; if (!test_bit(ASYNCB_INITIALIZED, &port->port.flags)) { if (serial->type->set_termios) { /* * allocate a fake tty so the driver can initialize * the termios structure, then later call set_termios to * configure according to command line arguments */ tty = kzalloc(sizeof(*tty), GFP_KERNEL); if (!tty) { retval = -ENOMEM; err("no more memory"); goto reset_open_count; } kref_init(&tty->kref); tty_port_tty_set(&port->port, tty); tty->driver = usb_serial_tty_driver; tty->index = co->index; if (tty_init_termios(tty)) { retval = -ENOMEM; err("no more memory"); goto free_tty; } } /* only call the device specific open if this * is the first time the port is opened */ if (serial->type->open) retval = serial->type->open(NULL, port); else retval = usb_serial_generic_open(NULL, port); if (retval) { err("could not open USB console port"); goto fail; } if (serial->type->set_termios) { tty->termios->c_cflag = cflag; tty_termios_encode_baud_rate(tty->termios, baud, baud); memset(&dummy, 0, sizeof(struct ktermios)); serial->type->set_termios(tty, port, &dummy); tty_port_tty_set(&port->port, NULL); kfree(tty); } set_bit(ASYNCB_INITIALIZED, &port->port.flags); } /* Now that any required fake tty operations are completed restore * the tty port count */ --port->port.count; /* The console is special in terms of closing the device so * indicate this port is now acting as a system console. */ port->port.console = 1; mutex_unlock(&serial->disc_mutex); return retval; fail: tty_port_tty_set(&port->port, NULL); free_tty: kfree(tty); reset_open_count: port->port.count = 0; usb_autopm_put_interface(serial->interface); error_get_interface: usb_serial_put(serial); mutex_unlock(&serial->disc_mutex); return retval; } static void usb_console_write(struct console *co, const char *buf, unsigned count) { static struct usbcons_info *info = &usbcons_info; struct usb_serial_port *port = info->port; struct usb_serial *serial; int retval = -ENODEV; if (!port || port->serial->dev->state == USB_STATE_NOTATTACHED) return; serial = port->serial; if (count == 0) return; dbg("%s - port %d, %d byte(s)", __func__, port->number, count); if (!port->port.console) { dbg("%s - port not opened", __func__); return; } while (count) { unsigned int i; unsigned int lf; /* search for LF so we can insert CR if necessary */ for (i = 0, lf = 0 ; i < count ; i++) { if (*(buf + i) == 10) { lf = 1; i++; break; } } /* pass on to the driver specific version of this function if it is available */ if (serial->type->write) retval = serial->type->write(NULL, port, buf, i); else retval = usb_serial_generic_write(NULL, port, buf, i); dbg("%s - return value : %d", __func__, retval); if (lf) { /* append CR after LF */ unsigned char cr = 13; if (serial->type->write) retval = serial->type->write(NULL, port, &cr, 1); else retval = usb_serial_generic_write(NULL, port, &cr, 1); dbg("%s - return value : %d", __func__, retval); } buf += i; count -= i; } } static struct tty_driver *usb_console_device(struct console *co, int *index) { struct tty_driver **p = (struct tty_driver **)co->data; if (!*p) return NULL; *index = co->index; return *p; } static struct console usbcons = { .name = "ttyUSB", .write = usb_console_write, .device = usb_console_device, .setup = usb_console_setup, .flags = CON_PRINTBUFFER, .index = -1, .data = &usb_serial_tty_driver, }; void usb_serial_console_disconnect(struct usb_serial *serial) { if (serial && serial->port && serial->port[0] && serial->port[0] == usbcons_info.port) { usb_serial_console_exit(); usb_serial_put(serial); } } void usb_serial_console_init(int serial_debug, int minor) { debug = serial_debug; if (minor == 0) { /* * Call register_console() if this is the first device plugged * in. If we call it earlier, then the callback to * console_setup() will fail, as there is not a device seen by * the USB subsystem yet. */ /* * Register console. * NOTES: * console_setup() is called (back) immediately (from * register_console). console_write() is called immediately * from register_console iff CON_PRINTBUFFER is set in flags. */ dbg("registering the USB serial console."); register_console(&usbcons); } } void usb_serial_console_exit(void) { if (usbcons_info.port) { unregister_console(&usbcons); usbcons_info.port->port.console = 0; usbcons_info.port = NULL; } }
gpl-2.0
n3ocort3x/endeavoru_3.14
drivers/uwb/i1480/dfu/phy.c
14608
6445
/* * Intel Wireless UWB Link 1480 * PHY parameters upload * * Copyright (C) 2005-2006 Intel Corporation * Inaky Perez-Gonzalez <inaky.perez-gonzalez@intel.com> * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License version * 2 as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA * 02110-1301, USA. * * * Code for uploading the PHY parameters to the PHY through the UWB * Radio Control interface. * * We just send the data through the MPI interface using HWA-like * commands and then reset the PHY to make sure it is ok. */ #include <linux/delay.h> #include <linux/device.h> #include <linux/firmware.h> #include <linux/usb/wusb.h> #include "i1480-dfu.h" /** * Write a value array to an address of the MPI interface * * @i1480: Device descriptor * @data: Data array to write * @size: Size of the data array * @returns: 0 if ok, < 0 errno code on error. * * The data array is organized into pairs: * * ADDRESS VALUE * * ADDRESS is BE 16 bit unsigned, VALUE 8 bit unsigned. Size thus has * to be a multiple of three. */ static int i1480_mpi_write(struct i1480 *i1480, const void *data, size_t size) { int result; struct i1480_cmd_mpi_write *cmd = i1480->cmd_buf; struct i1480_evt_confirm *reply = i1480->evt_buf; BUG_ON(size > 480); result = -ENOMEM; cmd->rccb.bCommandType = i1480_CET_VS1; cmd->rccb.wCommand = cpu_to_le16(i1480_CMD_MPI_WRITE); cmd->size = cpu_to_le16(size); memcpy(cmd->data, data, size); reply->rceb.bEventType = i1480_CET_VS1; reply->rceb.wEvent = i1480_CMD_MPI_WRITE; result = i1480_cmd(i1480, "MPI-WRITE", sizeof(*cmd) + size, sizeof(*reply)); if (result < 0) goto out; if (reply->bResultCode != UWB_RC_RES_SUCCESS) { dev_err(i1480->dev, "MPI-WRITE: command execution failed: %d\n", reply->bResultCode); result = -EIO; } out: return result; } /** * Read a value array to from an address of the MPI interface * * @i1480: Device descriptor * @data: where to place the read array * @srcaddr: Where to read from * @size: Size of the data read array * @returns: 0 if ok, < 0 errno code on error. * * The command data array is organized into pairs ADDR0 ADDR1..., and * the returned data in ADDR0 VALUE0 ADDR1 VALUE1... * * We generate the command array to be a sequential read and then * rearrange the result. * * We use the i1480->cmd_buf for the command, i1480->evt_buf for the reply. * * As the reply has to fit in 512 bytes (i1480->evt_buffer), the max amount * of values we can read is (512 - sizeof(*reply)) / 3 */ static int i1480_mpi_read(struct i1480 *i1480, u8 *data, u16 srcaddr, size_t size) { int result; struct i1480_cmd_mpi_read *cmd = i1480->cmd_buf; struct i1480_evt_mpi_read *reply = i1480->evt_buf; unsigned cnt; memset(i1480->cmd_buf, 0x69, 512); memset(i1480->evt_buf, 0x69, 512); BUG_ON(size > (i1480->buf_size - sizeof(*reply)) / 3); result = -ENOMEM; cmd->rccb.bCommandType = i1480_CET_VS1; cmd->rccb.wCommand = cpu_to_le16(i1480_CMD_MPI_READ); cmd->size = cpu_to_le16(3*size); for (cnt = 0; cnt < size; cnt++) { cmd->data[cnt].page = (srcaddr + cnt) >> 8; cmd->data[cnt].offset = (srcaddr + cnt) & 0xff; } reply->rceb.bEventType = i1480_CET_VS1; reply->rceb.wEvent = i1480_CMD_MPI_READ; result = i1480_cmd(i1480, "MPI-READ", sizeof(*cmd) + 2*size, sizeof(*reply) + 3*size); if (result < 0) goto out; if (reply->bResultCode != UWB_RC_RES_SUCCESS) { dev_err(i1480->dev, "MPI-READ: command execution failed: %d\n", reply->bResultCode); result = -EIO; } for (cnt = 0; cnt < size; cnt++) { if (reply->data[cnt].page != (srcaddr + cnt) >> 8) dev_err(i1480->dev, "MPI-READ: page inconsistency at " "index %u: expected 0x%02x, got 0x%02x\n", cnt, (srcaddr + cnt) >> 8, reply->data[cnt].page); if (reply->data[cnt].offset != ((srcaddr + cnt) & 0x00ff)) dev_err(i1480->dev, "MPI-READ: offset inconsistency at " "index %u: expected 0x%02x, got 0x%02x\n", cnt, (srcaddr + cnt) & 0x00ff, reply->data[cnt].offset); data[cnt] = reply->data[cnt].value; } result = 0; out: return result; } /** * Upload a PHY firmware, wait for it to start * * @i1480: Device instance * @fw_name: Name of the file that contains the firmware * * We assume the MAC fw is up and running. This means we can use the * MPI interface to write the PHY firmware. Once done, we issue an * MBOA Reset, which will force the MAC to reset and reinitialize the * PHY. If that works, we are ready to go. * * Max packet size for the MPI write is 512, so the max buffer is 480 * (which gives us 160 byte triads of MSB, LSB and VAL for the data). */ int i1480_phy_fw_upload(struct i1480 *i1480) { int result; const struct firmware *fw; const char *data_itr, *data_top; const size_t MAX_BLK_SIZE = 480; /* 160 triads */ size_t data_size; u8 phy_stat; result = request_firmware(&fw, i1480->phy_fw_name, i1480->dev); if (result < 0) goto out; /* Loop writing data in chunks as big as possible until done. */ for (data_itr = fw->data, data_top = data_itr + fw->size; data_itr < data_top; data_itr += MAX_BLK_SIZE) { data_size = min(MAX_BLK_SIZE, (size_t) (data_top - data_itr)); result = i1480_mpi_write(i1480, data_itr, data_size); if (result < 0) goto error_mpi_write; } /* Read MPI page 0, offset 6; if 0, PHY was initialized correctly. */ result = i1480_mpi_read(i1480, &phy_stat, 0x0006, 1); if (result < 0) { dev_err(i1480->dev, "PHY: can't get status: %d\n", result); goto error_mpi_status; } if (phy_stat != 0) { result = -ENODEV; dev_info(i1480->dev, "error, PHY not ready: %u\n", phy_stat); goto error_phy_status; } dev_info(i1480->dev, "PHY fw '%s': uploaded\n", i1480->phy_fw_name); error_phy_status: error_mpi_status: error_mpi_write: release_firmware(fw); if (result < 0) dev_err(i1480->dev, "PHY fw '%s': failed to upload (%d), " "power cycle device\n", i1480->phy_fw_name, result); out: return result; }
gpl-2.0
binkybear/furnace_kernel_lge_hammerhead
drivers/uwb/i1480/dfu/phy.c
14608
6445
/* * Intel Wireless UWB Link 1480 * PHY parameters upload * * Copyright (C) 2005-2006 Intel Corporation * Inaky Perez-Gonzalez <inaky.perez-gonzalez@intel.com> * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License version * 2 as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA * 02110-1301, USA. * * * Code for uploading the PHY parameters to the PHY through the UWB * Radio Control interface. * * We just send the data through the MPI interface using HWA-like * commands and then reset the PHY to make sure it is ok. */ #include <linux/delay.h> #include <linux/device.h> #include <linux/firmware.h> #include <linux/usb/wusb.h> #include "i1480-dfu.h" /** * Write a value array to an address of the MPI interface * * @i1480: Device descriptor * @data: Data array to write * @size: Size of the data array * @returns: 0 if ok, < 0 errno code on error. * * The data array is organized into pairs: * * ADDRESS VALUE * * ADDRESS is BE 16 bit unsigned, VALUE 8 bit unsigned. Size thus has * to be a multiple of three. */ static int i1480_mpi_write(struct i1480 *i1480, const void *data, size_t size) { int result; struct i1480_cmd_mpi_write *cmd = i1480->cmd_buf; struct i1480_evt_confirm *reply = i1480->evt_buf; BUG_ON(size > 480); result = -ENOMEM; cmd->rccb.bCommandType = i1480_CET_VS1; cmd->rccb.wCommand = cpu_to_le16(i1480_CMD_MPI_WRITE); cmd->size = cpu_to_le16(size); memcpy(cmd->data, data, size); reply->rceb.bEventType = i1480_CET_VS1; reply->rceb.wEvent = i1480_CMD_MPI_WRITE; result = i1480_cmd(i1480, "MPI-WRITE", sizeof(*cmd) + size, sizeof(*reply)); if (result < 0) goto out; if (reply->bResultCode != UWB_RC_RES_SUCCESS) { dev_err(i1480->dev, "MPI-WRITE: command execution failed: %d\n", reply->bResultCode); result = -EIO; } out: return result; } /** * Read a value array to from an address of the MPI interface * * @i1480: Device descriptor * @data: where to place the read array * @srcaddr: Where to read from * @size: Size of the data read array * @returns: 0 if ok, < 0 errno code on error. * * The command data array is organized into pairs ADDR0 ADDR1..., and * the returned data in ADDR0 VALUE0 ADDR1 VALUE1... * * We generate the command array to be a sequential read and then * rearrange the result. * * We use the i1480->cmd_buf for the command, i1480->evt_buf for the reply. * * As the reply has to fit in 512 bytes (i1480->evt_buffer), the max amount * of values we can read is (512 - sizeof(*reply)) / 3 */ static int i1480_mpi_read(struct i1480 *i1480, u8 *data, u16 srcaddr, size_t size) { int result; struct i1480_cmd_mpi_read *cmd = i1480->cmd_buf; struct i1480_evt_mpi_read *reply = i1480->evt_buf; unsigned cnt; memset(i1480->cmd_buf, 0x69, 512); memset(i1480->evt_buf, 0x69, 512); BUG_ON(size > (i1480->buf_size - sizeof(*reply)) / 3); result = -ENOMEM; cmd->rccb.bCommandType = i1480_CET_VS1; cmd->rccb.wCommand = cpu_to_le16(i1480_CMD_MPI_READ); cmd->size = cpu_to_le16(3*size); for (cnt = 0; cnt < size; cnt++) { cmd->data[cnt].page = (srcaddr + cnt) >> 8; cmd->data[cnt].offset = (srcaddr + cnt) & 0xff; } reply->rceb.bEventType = i1480_CET_VS1; reply->rceb.wEvent = i1480_CMD_MPI_READ; result = i1480_cmd(i1480, "MPI-READ", sizeof(*cmd) + 2*size, sizeof(*reply) + 3*size); if (result < 0) goto out; if (reply->bResultCode != UWB_RC_RES_SUCCESS) { dev_err(i1480->dev, "MPI-READ: command execution failed: %d\n", reply->bResultCode); result = -EIO; } for (cnt = 0; cnt < size; cnt++) { if (reply->data[cnt].page != (srcaddr + cnt) >> 8) dev_err(i1480->dev, "MPI-READ: page inconsistency at " "index %u: expected 0x%02x, got 0x%02x\n", cnt, (srcaddr + cnt) >> 8, reply->data[cnt].page); if (reply->data[cnt].offset != ((srcaddr + cnt) & 0x00ff)) dev_err(i1480->dev, "MPI-READ: offset inconsistency at " "index %u: expected 0x%02x, got 0x%02x\n", cnt, (srcaddr + cnt) & 0x00ff, reply->data[cnt].offset); data[cnt] = reply->data[cnt].value; } result = 0; out: return result; } /** * Upload a PHY firmware, wait for it to start * * @i1480: Device instance * @fw_name: Name of the file that contains the firmware * * We assume the MAC fw is up and running. This means we can use the * MPI interface to write the PHY firmware. Once done, we issue an * MBOA Reset, which will force the MAC to reset and reinitialize the * PHY. If that works, we are ready to go. * * Max packet size for the MPI write is 512, so the max buffer is 480 * (which gives us 160 byte triads of MSB, LSB and VAL for the data). */ int i1480_phy_fw_upload(struct i1480 *i1480) { int result; const struct firmware *fw; const char *data_itr, *data_top; const size_t MAX_BLK_SIZE = 480; /* 160 triads */ size_t data_size; u8 phy_stat; result = request_firmware(&fw, i1480->phy_fw_name, i1480->dev); if (result < 0) goto out; /* Loop writing data in chunks as big as possible until done. */ for (data_itr = fw->data, data_top = data_itr + fw->size; data_itr < data_top; data_itr += MAX_BLK_SIZE) { data_size = min(MAX_BLK_SIZE, (size_t) (data_top - data_itr)); result = i1480_mpi_write(i1480, data_itr, data_size); if (result < 0) goto error_mpi_write; } /* Read MPI page 0, offset 6; if 0, PHY was initialized correctly. */ result = i1480_mpi_read(i1480, &phy_stat, 0x0006, 1); if (result < 0) { dev_err(i1480->dev, "PHY: can't get status: %d\n", result); goto error_mpi_status; } if (phy_stat != 0) { result = -ENODEV; dev_info(i1480->dev, "error, PHY not ready: %u\n", phy_stat); goto error_phy_status; } dev_info(i1480->dev, "PHY fw '%s': uploaded\n", i1480->phy_fw_name); error_phy_status: error_mpi_status: error_mpi_write: release_firmware(fw); if (result < 0) dev_err(i1480->dev, "PHY fw '%s': failed to upload (%d), " "power cycle device\n", i1480->phy_fw_name, result); out: return result; }
gpl-2.0
atidot3/Orizon-510
src/server/game/AI/CoreAI/GuardAI.cpp
17
2318
/* * Copyright (C) 2008-2012 TrinityCore <http://www.trinitycore.org/> * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/> * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the * Free Software Foundation; either version 2 of the License, or (at your * option) any later version. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * more details. * * You should have received a copy of the GNU General Public License along * with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "GuardAI.h" #include "Errors.h" #include "Player.h" #include "ObjectAccessor.h" #include "World.h" #include "CreatureAIImpl.h" int GuardAI::Permissible(Creature const* creature) { if (creature->isGuard()) return PERMIT_BASE_SPECIAL; return PERMIT_BASE_NO; } GuardAI::GuardAI(Creature* creature) : ScriptedAI(creature) { } bool GuardAI::CanSeeAlways(WorldObject const* obj) { if (!obj->isType(TYPEMASK_UNIT)) return false; ThreatContainer::StorageType threatList = me->getThreatManager().getThreatList(); for (ThreatContainer::StorageType::const_iterator itr = threatList.begin(); itr != threatList.end(); ++itr) if ((*itr)->getUnitGuid() == obj->GetGUID()) return true; return false; } void GuardAI::EnterEvadeMode() { if (!me->isAlive()) { me->GetMotionMaster()->MoveIdle(); me->CombatStop(true); me->DeleteThreatList(); return; } sLog->outDebug(LOG_FILTER_UNITS, "Guard entry: %u enters evade mode.", me->GetEntry()); me->RemoveAllAuras(); me->DeleteThreatList(); me->CombatStop(true); // Remove ChaseMovementGenerator from MotionMaster stack list, and add HomeMovementGenerator instead if (me->GetMotionMaster()->GetCurrentMovementGeneratorType() == CHASE_MOTION_TYPE) me->GetMotionMaster()->MoveTargetedHome(); } void GuardAI::JustDied(Unit* killer) { if (Player* player = killer->GetCharmerOrOwnerPlayerOrPlayerItself()) me->SendZoneUnderAttackMessage(player); }
gpl-2.0
AndroPlus-org/kernel
sound/soc/msm/qdsp6v2/msm-compr-q6-v2.c
17
49849
/* Copyright (c) 2012-2014, The Linux Foundation. All rights reserved. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 and * only version 2 as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. */ #include <linux/init.h> #include <linux/err.h> #include <linux/module.h> #include <linux/moduleparam.h> #include <linux/time.h> #include <linux/wait.h> #include <linux/platform_device.h> #include <linux/slab.h> #include <sound/core.h> #include <sound/soc.h> #include <sound/soc-dapm.h> #include <sound/pcm.h> #include <sound/initval.h> #include <sound/control.h> #include <sound/q6asm-v2.h> #include <sound/pcm_params.h> #include <asm/dma.h> #include <linux/dma-mapping.h> #include <linux/msm_audio_ion.h> #include <sound/timer.h> #include "msm-compr-q6-v2.h" #include "msm-pcm-routing-v2.h" #include "audio_ocmem.h" #include <sound/tlv.h> #define COMPRE_CAPTURE_NUM_PERIODS 16 /* Allocate the worst case frame size for compressed audio */ #define COMPRE_CAPTURE_HEADER_SIZE (sizeof(struct snd_compr_audio_info)) /* Changing period size to 4032. 4032 will make sure COMPRE_CAPTURE_PERIOD_SIZE * is 4096 with meta data size of 64 and MAX_NUM_FRAMES_PER_BUFFER 1 */ #define COMPRE_CAPTURE_MAX_FRAME_SIZE (4032) #define COMPRE_CAPTURE_PERIOD_SIZE ((COMPRE_CAPTURE_MAX_FRAME_SIZE + \ COMPRE_CAPTURE_HEADER_SIZE) * \ MAX_NUM_FRAMES_PER_BUFFER) #define COMPRE_OUTPUT_METADATA_SIZE (sizeof(struct output_meta_data_st)) #define COMPRESSED_LR_VOL_MAX_STEPS 0x20002000 #define MAX_AC3_PARAM_SIZE (18*2*sizeof(int)) #define AMR_WB_BAND_MODE 8 #define AMR_WB_DTX_MODE 0 const DECLARE_TLV_DB_LINEAR(compr_rx_vol_gain, 0, COMPRESSED_LR_VOL_MAX_STEPS); struct snd_msm { atomic_t audio_ocmem_req; }; static struct snd_msm compressed_audio; static struct audio_locks the_locks; static struct snd_pcm_hardware msm_compr_hardware_capture = { .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_BLOCK_TRANSFER | SNDRV_PCM_INFO_MMAP_VALID | SNDRV_PCM_INFO_INTERLEAVED | SNDRV_PCM_INFO_PAUSE | SNDRV_PCM_INFO_RESUME), .formats = SNDRV_PCM_FMTBIT_S16_LE, .rates = SNDRV_PCM_RATE_8000_48000, .rate_min = 8000, .rate_max = 48000, .channels_min = 1, .channels_max = 8, .buffer_bytes_max = COMPRE_CAPTURE_PERIOD_SIZE * COMPRE_CAPTURE_NUM_PERIODS , .period_bytes_min = COMPRE_CAPTURE_PERIOD_SIZE, .period_bytes_max = COMPRE_CAPTURE_PERIOD_SIZE, .periods_min = COMPRE_CAPTURE_NUM_PERIODS, .periods_max = COMPRE_CAPTURE_NUM_PERIODS, .fifo_size = 0, }; static struct snd_pcm_hardware msm_compr_hardware_playback = { .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_BLOCK_TRANSFER | SNDRV_PCM_INFO_MMAP_VALID | SNDRV_PCM_INFO_INTERLEAVED | SNDRV_PCM_INFO_PAUSE | SNDRV_PCM_INFO_RESUME), .formats = SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S24_LE, .rates = SNDRV_PCM_RATE_8000_48000 | SNDRV_PCM_RATE_KNOT, .rate_min = 8000, .rate_max = 48000, .channels_min = 1, .channels_max = 8, .buffer_bytes_max = 1024 * 1024, .period_bytes_min = 128 * 1024, .period_bytes_max = 256 * 1024, .periods_min = 4, .periods_max = 8, .fifo_size = 0, }; /* Conventional and unconventional sample rate supported */ static unsigned int supported_sample_rates[] = { 8000, 11025, 12000, 16000, 22050, 24000, 32000, 44100, 48000 }; /* Add supported codecs for compress capture path */ static uint32_t supported_compr_capture_codecs[] = { SND_AUDIOCODEC_AMRWB }; static struct snd_pcm_hw_constraint_list constraints_sample_rates = { .count = ARRAY_SIZE(supported_sample_rates), .list = supported_sample_rates, .mask = 0, }; static bool msm_compr_capture_codecs(uint32_t req_codec) { int i; pr_debug("%s req_codec:%d\n", __func__, req_codec); if (req_codec == 0) return false; for (i = 0; i < ARRAY_SIZE(supported_compr_capture_codecs); i++) { if (req_codec == supported_compr_capture_codecs[i]) return true; } return false; } static void compr_event_handler(uint32_t opcode, uint32_t token, uint32_t *payload, void *priv) { struct compr_audio *compr = priv; struct msm_audio *prtd = &compr->prtd; struct snd_pcm_substream *substream = prtd->substream; struct snd_pcm_runtime *runtime = substream->runtime; struct audio_aio_write_param param; struct audio_aio_read_param read_param; struct audio_buffer *buf = NULL; phys_addr_t temp; struct output_meta_data_st output_meta_data; uint32_t *ptrmem = (uint32_t *)payload; int i = 0; int time_stamp_flag = 0; int buffer_length = 0; int stop_playback = 0; pr_debug("%s opcode =%08x\n", __func__, opcode); switch (opcode) { case ASM_DATA_EVENT_WRITE_DONE_V2: { uint32_t *ptrmem = (uint32_t *)&param; pr_debug("ASM_DATA_EVENT_WRITE_DONE\n"); pr_debug("Buffer Consumed = 0x%08x\n", *ptrmem); prtd->pcm_irq_pos += prtd->pcm_count; if (atomic_read(&prtd->start)) snd_pcm_period_elapsed(substream); else if (substream->timer_running) snd_timer_interrupt(substream->timer, 1); atomic_inc(&prtd->out_count); wake_up(&the_locks.write_wait); if (!atomic_read(&prtd->start)) { atomic_set(&prtd->pending_buffer, 1); break; } else atomic_set(&prtd->pending_buffer, 0); /* * check for underrun */ snd_pcm_stream_lock_irq(substream); if (runtime->status->hw_ptr >= runtime->control->appl_ptr) { runtime->render_flag |= SNDRV_RENDER_STOPPED; stop_playback = 1; } snd_pcm_stream_unlock_irq(substream); if (stop_playback) { pr_err("underrun! render stopped\n"); break; } buf = prtd->audio_client->port[IN].buf; pr_debug("%s:writing %d bytes of buffer[%d] to dsp 2\n", __func__, prtd->pcm_count, prtd->out_head); temp = buf[0].phys + (prtd->out_head * prtd->pcm_count); pr_debug("%s:writing buffer[%d] from 0x%pa\n", __func__, prtd->out_head, &temp); if (runtime->tstamp_mode == SNDRV_PCM_TSTAMP_ENABLE) time_stamp_flag = SET_TIMESTAMP; else time_stamp_flag = NO_TIMESTAMP; memcpy(&output_meta_data, (char *)(buf->data + prtd->out_head * prtd->pcm_count), COMPRE_OUTPUT_METADATA_SIZE); buffer_length = output_meta_data.frame_size; pr_debug("meta_data_length: %d, frame_length: %d\n", output_meta_data.meta_data_length, output_meta_data.frame_size); pr_debug("timestamp_msw: %d, timestamp_lsw: %d\n", output_meta_data.timestamp_msw, output_meta_data.timestamp_lsw); if (buffer_length == 0) { pr_debug("Recieved a zero length buffer-break out"); break; } param.paddr = temp + output_meta_data.meta_data_length; param.len = buffer_length; param.msw_ts = output_meta_data.timestamp_msw; param.lsw_ts = output_meta_data.timestamp_lsw; param.flags = time_stamp_flag; param.uid = prtd->session_id; for (i = 0; i < sizeof(struct audio_aio_write_param)/4; i++, ++ptrmem) pr_debug("cmd[%d]=0x%08x\n", i, *ptrmem); if (q6asm_async_write(prtd->audio_client, &param) < 0) pr_err("%s:q6asm_async_write failed\n", __func__); else prtd->out_head = (prtd->out_head + 1) & (runtime->periods - 1); break; } case ASM_DATA_EVENT_RENDERED_EOS: pr_debug("ASM_DATA_CMDRSP_EOS\n"); if (atomic_read(&prtd->eos)) { pr_debug("ASM_DATA_CMDRSP_EOS wake up\n"); prtd->cmd_ack = 1; wake_up(&the_locks.eos_wait); atomic_set(&prtd->eos, 0); } break; case ASM_DATA_EVENT_READ_DONE_V2: { pr_debug("ASM_DATA_EVENT_READ_DONE\n"); pr_debug("buf = %p, data = 0x%X, *data = %p,\n" "prtd->pcm_irq_pos = %d\n", prtd->audio_client->port[OUT].buf, *(uint32_t *)prtd->audio_client->port[OUT].buf->data, prtd->audio_client->port[OUT].buf->data, prtd->pcm_irq_pos); memcpy(prtd->audio_client->port[OUT].buf->data + prtd->pcm_irq_pos, (ptrmem + READDONE_IDX_SIZE), COMPRE_CAPTURE_HEADER_SIZE); pr_debug("buf = %p, updated data = 0x%X, *data = %p\n", prtd->audio_client->port[OUT].buf, *(uint32_t *)(prtd->audio_client->port[OUT].buf->data + prtd->pcm_irq_pos), prtd->audio_client->port[OUT].buf->data); if (!atomic_read(&prtd->start)) break; pr_debug("frame size=%d, buffer = 0x%X\n", ptrmem[READDONE_IDX_SIZE], ptrmem[READDONE_IDX_BUFADD_LSW]); if (ptrmem[READDONE_IDX_SIZE] > COMPRE_CAPTURE_MAX_FRAME_SIZE) { pr_err("Frame length exceeded the max length"); break; } buf = prtd->audio_client->port[OUT].buf; pr_debug("pcm_irq_pos=%d, buf[0].phys = 0x%pa\n", prtd->pcm_irq_pos, &buf[0].phys); read_param.len = prtd->pcm_count - COMPRE_CAPTURE_HEADER_SIZE; read_param.paddr = buf[0].phys + prtd->pcm_irq_pos + COMPRE_CAPTURE_HEADER_SIZE; prtd->pcm_irq_pos += prtd->pcm_count; if (atomic_read(&prtd->start)) snd_pcm_period_elapsed(substream); q6asm_async_read(prtd->audio_client, &read_param); break; } case APR_BASIC_RSP_RESULT: { switch (payload[0]) { case ASM_SESSION_CMD_RUN_V2: { if (substream->stream != SNDRV_PCM_STREAM_PLAYBACK) { atomic_set(&prtd->start, 1); break; } if (!atomic_read(&prtd->pending_buffer)) break; pr_debug("%s: writing %d bytes of buffer[%d] to dsp\n", __func__, prtd->pcm_count, prtd->out_head); buf = prtd->audio_client->port[IN].buf; pr_debug("%s: writing buffer[%d] from 0x%pa head %d count %d\n", __func__, prtd->out_head, &buf[0].phys, prtd->pcm_count, prtd->out_head); if (runtime->tstamp_mode == SNDRV_PCM_TSTAMP_ENABLE) time_stamp_flag = SET_TIMESTAMP; else time_stamp_flag = NO_TIMESTAMP; memcpy(&output_meta_data, (char *)(buf->data + prtd->out_head * prtd->pcm_count), COMPRE_OUTPUT_METADATA_SIZE); buffer_length = output_meta_data.frame_size; pr_debug("meta_data_length: %d, frame_length: %d\n", output_meta_data.meta_data_length, output_meta_data.frame_size); pr_debug("timestamp_msw: %d, timestamp_lsw: %d\n", output_meta_data.timestamp_msw, output_meta_data.timestamp_lsw); param.paddr = buf[prtd->out_head].phys + output_meta_data.meta_data_length; param.len = buffer_length; param.msw_ts = output_meta_data.timestamp_msw; param.lsw_ts = output_meta_data.timestamp_lsw; param.flags = time_stamp_flag; param.uid = prtd->session_id; param.metadata_len = COMPRE_OUTPUT_METADATA_SIZE; if (q6asm_async_write(prtd->audio_client, &param) < 0) pr_err("%s:q6asm_async_write failed\n", __func__); else prtd->out_head = (prtd->out_head + 1) & (runtime->periods - 1); atomic_set(&prtd->pending_buffer, 0); } break; case ASM_STREAM_CMD_FLUSH: pr_debug("ASM_STREAM_CMD_FLUSH\n"); prtd->cmd_ack = 1; wake_up(&the_locks.flush_wait); break; default: break; } break; } default: pr_debug("Not Supported Event opcode[0x%x]\n", opcode); break; } } static int msm_compr_send_ddp_cfg(struct audio_client *ac, struct snd_dec_ddp *ddp) { int i, rc; pr_debug("%s\n", __func__); for (i = 0; i < ddp->params_length/2; i++) { rc = q6asm_ds1_set_endp_params(ac, ddp->params_id[i], ddp->params_value[i]); if (rc) { pr_err("sending params_id: %d failed\n", ddp->params_id[i]); return rc; } } return 0; } static int msm_compr_playback_prepare(struct snd_pcm_substream *substream) { struct snd_pcm_runtime *runtime = substream->runtime; struct compr_audio *compr = runtime->private_data; struct snd_soc_pcm_runtime *soc_prtd = substream->private_data; struct msm_audio *prtd = &compr->prtd; struct snd_pcm_hw_params *params; struct asm_aac_cfg aac_cfg; uint16_t bits_per_sample = 16; int ret; struct asm_softpause_params softpause = { .enable = SOFT_PAUSE_ENABLE, .period = SOFT_PAUSE_PERIOD, .step = SOFT_PAUSE_STEP, .rampingcurve = SOFT_PAUSE_CURVE_LINEAR, }; struct asm_softvolume_params softvol = { .period = SOFT_VOLUME_PERIOD, .step = SOFT_VOLUME_STEP, .rampingcurve = SOFT_VOLUME_CURVE_LINEAR, }; pr_debug("%s\n", __func__); params = &soc_prtd->dpcm[substream->stream].hw_params; if (runtime->format == SNDRV_PCM_FORMAT_S24_LE) bits_per_sample = 24; ret = q6asm_open_write_v2(prtd->audio_client, compr->codec, bits_per_sample); if (ret < 0) { pr_err("%s: Session out open failed\n", __func__); return -ENOMEM; } msm_pcm_routing_reg_phy_stream( soc_prtd->dai_link->be_id, prtd->audio_client->perf_mode, prtd->session_id, substream->stream); /* * the number of channels are required to call volume api * accoridngly. So, get channels from hw params */ if ((params_channels(params) > 0) && (params_periods(params) <= runtime->hw.channels_max)) prtd->channel_mode = params_channels(params); ret = q6asm_set_softpause(prtd->audio_client, &softpause); if (ret < 0) pr_err("%s: Send SoftPause Param failed ret=%d\n", __func__, ret); ret = q6asm_set_softvolume(prtd->audio_client, &softvol); if (ret < 0) pr_err("%s: Send SoftVolume Param failed ret=%d\n", __func__, ret); ret = q6asm_set_io_mode(prtd->audio_client, (COMPRESSED_IO | ASYNC_IO_MODE)); if (ret < 0) { pr_err("%s: Set IO mode failed\n", __func__); return -ENOMEM; } prtd->pcm_size = snd_pcm_lib_buffer_bytes(substream); prtd->pcm_count = snd_pcm_lib_period_bytes(substream); prtd->pcm_irq_pos = 0; /* rate and channels are sent to audio driver */ prtd->samp_rate = runtime->rate; prtd->channel_mode = runtime->channels; prtd->out_head = 0; atomic_set(&prtd->out_count, runtime->periods); if (prtd->enabled) return 0; switch (compr->info.codec_param.codec.id) { case SND_AUDIOCODEC_MP3: /* No media format block for mp3 */ break; case SND_AUDIOCODEC_AAC: pr_debug("%s: SND_AUDIOCODEC_AAC\n", __func__); memset(&aac_cfg, 0x0, sizeof(struct asm_aac_cfg)); aac_cfg.aot = AAC_ENC_MODE_EAAC_P; aac_cfg.format = 0x03; aac_cfg.ch_cfg = runtime->channels; aac_cfg.sample_rate = runtime->rate; ret = q6asm_media_format_block_aac(prtd->audio_client, &aac_cfg); if (ret < 0) pr_err("%s: CMD Format block failed\n", __func__); break; case SND_AUDIOCODEC_AC3: { struct snd_dec_ddp *ddp = &compr->info.codec_param.codec.options.ddp; pr_debug("%s: SND_AUDIOCODEC_AC3\n", __func__); ret = msm_compr_send_ddp_cfg(prtd->audio_client, ddp); if (ret < 0) pr_err("%s: DDP CMD CFG failed\n", __func__); break; } case SND_AUDIOCODEC_EAC3: { struct snd_dec_ddp *ddp = &compr->info.codec_param.codec.options.ddp; pr_debug("%s: SND_AUDIOCODEC_EAC3\n", __func__); ret = msm_compr_send_ddp_cfg(prtd->audio_client, ddp); if (ret < 0) pr_err("%s: DDP CMD CFG failed\n", __func__); break; } default: return -EINVAL; } prtd->enabled = 1; prtd->cmd_ack = 0; prtd->cmd_interrupt = 0; return 0; } static int msm_compr_capture_prepare(struct snd_pcm_substream *substream) { struct snd_pcm_runtime *runtime = substream->runtime; struct compr_audio *compr = runtime->private_data; struct msm_audio *prtd = &compr->prtd; struct audio_buffer *buf = prtd->audio_client->port[OUT].buf; struct snd_codec *codec = &compr->info.codec_param.codec; struct snd_soc_pcm_runtime *soc_prtd = substream->private_data; struct audio_aio_read_param read_param; uint16_t bits_per_sample = 16; int ret = 0; int i; prtd->pcm_size = snd_pcm_lib_buffer_bytes(substream); prtd->pcm_count = snd_pcm_lib_period_bytes(substream); prtd->pcm_irq_pos = 0; if (runtime->format == SNDRV_PCM_FORMAT_S24_LE) bits_per_sample = 24; if (!msm_compr_capture_codecs( compr->info.codec_param.codec.id)) { /* * request codec invalid or not supported, * use default compress format */ compr->info.codec_param.codec.id = SND_AUDIOCODEC_AMRWB; } switch (compr->info.codec_param.codec.id) { case SND_AUDIOCODEC_AMRWB: pr_debug("q6asm_open_read(FORMAT_AMRWB)\n"); ret = q6asm_open_read(prtd->audio_client, FORMAT_AMRWB); if (ret < 0) { pr_err("%s: compressed Session out open failed\n", __func__); return -ENOMEM; } pr_debug("msm_pcm_routing_reg_phy_stream\n"); msm_pcm_routing_reg_phy_stream( soc_prtd->dai_link->be_id, prtd->audio_client->perf_mode, prtd->session_id, substream->stream); break; default: pr_debug("q6asm_open_read_compressed(COMPRESSED_META_DATA_MODE)\n"); /* ret = q6asm_open_read_compressed(prtd->audio_client, MAX_NUM_FRAMES_PER_BUFFER, COMPRESSED_META_DATA_MODE); */ ret = -EINVAL; break; } if (ret < 0) { pr_err("%s: compressed Session out open failed\n", __func__); return -ENOMEM; } ret = q6asm_set_io_mode(prtd->audio_client, (COMPRESSED_IO | ASYNC_IO_MODE)); if (ret < 0) { pr_err("%s: Set IO mode failed\n", __func__); return -ENOMEM; } if (!msm_compr_capture_codecs(codec->id)) { /* * request codec invalid or not supported, * use default compress format */ codec->id = SND_AUDIOCODEC_AMRWB; } /* rate and channels are sent to audio driver */ prtd->samp_rate = runtime->rate; prtd->channel_mode = runtime->channels; if (prtd->enabled) return ret; read_param.len = prtd->pcm_count; switch (codec->id) { case SND_AUDIOCODEC_AMRWB: pr_debug("SND_AUDIOCODEC_AMRWB\n"); ret = q6asm_enc_cfg_blk_amrwb(prtd->audio_client, MAX_NUM_FRAMES_PER_BUFFER, /* * use fixed band mode and dtx mode * band mode - 23.85 kbps */ AMR_WB_BAND_MODE, /* dtx mode - disable */ AMR_WB_DTX_MODE); if (ret < 0) pr_err("%s: CMD Format block" \ "failed: %d\n", __func__, ret); break; default: pr_debug("No config for codec %d\n", codec->id); } pr_debug("%s: Samp_rate = %d, Channel = %d, pcm_size = %d,\n" "pcm_count = %d, periods = %d\n", __func__, prtd->samp_rate, prtd->channel_mode, prtd->pcm_size, prtd->pcm_count, runtime->periods); for (i = 0; i < runtime->periods; i++) { read_param.uid = i; switch (codec->id) { case SND_AUDIOCODEC_AMRWB: read_param.len = prtd->pcm_count - COMPRE_CAPTURE_HEADER_SIZE; read_param.paddr = buf[i].phys + COMPRE_CAPTURE_HEADER_SIZE; pr_debug("Push buffer [%d] to DSP, "\ "paddr: %pa, vaddr: %p\n", i, &read_param.paddr, buf[i].data); q6asm_async_read(prtd->audio_client, &read_param); break; default: read_param.paddr = buf[i].phys; /*q6asm_async_read_compressed(prtd->audio_client, &read_param);*/ pr_debug("%s: To add support for read compressed\n", __func__); ret = -EINVAL; break; } } prtd->periods = runtime->periods; prtd->enabled = 1; return ret; } static int msm_compr_trigger(struct snd_pcm_substream *substream, int cmd) { int ret = 0; struct snd_pcm_runtime *runtime = substream->runtime; struct snd_soc_pcm_runtime *soc_prtd = substream->private_data; struct compr_audio *compr = runtime->private_data; struct msm_audio *prtd = &compr->prtd; pr_debug("%s\n", __func__); switch (cmd) { case SNDRV_PCM_TRIGGER_START: prtd->pcm_irq_pos = 0; if (substream->stream == SNDRV_PCM_STREAM_CAPTURE) { if (!msm_compr_capture_codecs( compr->info.codec_param.codec.id)) { /* * request codec invalid or not supported, * use default compress format */ compr->info.codec_param.codec.id = SND_AUDIOCODEC_AMRWB; } switch (compr->info.codec_param.codec.id) { case SND_AUDIOCODEC_AMRWB: break; default: msm_pcm_routing_reg_psthr_stream( soc_prtd->dai_link->be_id, prtd->session_id, substream->stream); break; } } atomic_set(&prtd->pending_buffer, 1); case SNDRV_PCM_TRIGGER_RESUME: case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: pr_debug("%s: Trigger start\n", __func__); q6asm_run_nowait(prtd->audio_client, 0, 0, 0); atomic_set(&prtd->start, 1); break; case SNDRV_PCM_TRIGGER_STOP: pr_debug("SNDRV_PCM_TRIGGER_STOP\n"); if (substream->stream == SNDRV_PCM_STREAM_CAPTURE) { switch (compr->info.codec_param.codec.id) { case SND_AUDIOCODEC_AMRWB: break; default: msm_pcm_routing_reg_psthr_stream( soc_prtd->dai_link->be_id, prtd->session_id, substream->stream); break; } } atomic_set(&prtd->start, 0); runtime->render_flag &= ~SNDRV_RENDER_STOPPED; break; case SNDRV_PCM_TRIGGER_SUSPEND: case SNDRV_PCM_TRIGGER_PAUSE_PUSH: pr_debug("SNDRV_PCM_TRIGGER_PAUSE\n"); q6asm_cmd_nowait(prtd->audio_client, CMD_PAUSE); atomic_set(&prtd->start, 0); runtime->render_flag &= ~SNDRV_RENDER_STOPPED; break; default: ret = -EINVAL; break; } return ret; } static void populate_codec_list(struct compr_audio *compr, struct snd_pcm_runtime *runtime) { pr_debug("%s\n", __func__); /* MP3 Block */ compr->info.compr_cap.num_codecs = 5; compr->info.compr_cap.min_fragment_size = runtime->hw.period_bytes_min; compr->info.compr_cap.max_fragment_size = runtime->hw.period_bytes_max; compr->info.compr_cap.min_fragments = runtime->hw.periods_min; compr->info.compr_cap.max_fragments = runtime->hw.periods_max; compr->info.compr_cap.codecs[0] = SND_AUDIOCODEC_MP3; compr->info.compr_cap.codecs[1] = SND_AUDIOCODEC_AAC; compr->info.compr_cap.codecs[2] = SND_AUDIOCODEC_AC3; compr->info.compr_cap.codecs[3] = SND_AUDIOCODEC_EAC3; compr->info.compr_cap.codecs[4] = SND_AUDIOCODEC_AMRWB; /* Add new codecs here */ } static int msm_compr_open(struct snd_pcm_substream *substream) { struct snd_pcm_runtime *runtime = substream->runtime; struct compr_audio *compr; struct msm_audio *prtd; int ret = 0; pr_debug("%s\n", __func__); compr = kzalloc(sizeof(struct compr_audio), GFP_KERNEL); if (compr == NULL) { pr_err("Failed to allocate memory for msm_audio\n"); return -ENOMEM; } prtd = &compr->prtd; prtd->substream = substream; runtime->render_flag = SNDRV_DMA_MODE; prtd->audio_client = q6asm_audio_client_alloc( (app_cb)compr_event_handler, compr); if (!prtd->audio_client) { pr_info("%s: Could not allocate memory\n", __func__); kfree(prtd); return -ENOMEM; } prtd->audio_client->perf_mode = false; pr_info("%s: session ID %d\n", __func__, prtd->audio_client->session); prtd->session_id = prtd->audio_client->session; if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { runtime->hw = msm_compr_hardware_playback; prtd->cmd_ack = 1; } else { runtime->hw = msm_compr_hardware_capture; } ret = snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, &constraints_sample_rates); if (ret < 0) pr_info("snd_pcm_hw_constraint_list failed\n"); /* Ensure that buffer size is a multiple of period size */ ret = snd_pcm_hw_constraint_integer(runtime, SNDRV_PCM_HW_PARAM_PERIODS); if (ret < 0) pr_info("snd_pcm_hw_constraint_integer failed\n"); prtd->dsp_cnt = 0; atomic_set(&prtd->pending_buffer, 1); if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) compr->codec = FORMAT_MP3; populate_codec_list(compr, runtime); runtime->private_data = compr; atomic_set(&prtd->eos, 0); if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { if (!atomic_cmpxchg(&compressed_audio.audio_ocmem_req, 0, 1)) audio_ocmem_process_req(AUDIO, true); else atomic_inc(&compressed_audio.audio_ocmem_req); pr_debug("%s: req: %d\n", __func__, atomic_read(&compressed_audio.audio_ocmem_req)); } return 0; } static int compressed_set_volume(struct msm_audio *prtd, uint32_t volume) { int rc = 0; int avg_vol = 0; int lgain = (volume >> 16) & 0xFFFF; int rgain = volume & 0xFFFF; if (prtd && prtd->audio_client) { pr_debug("%s: channels %d volume 0x%x\n", __func__, prtd->channel_mode, volume); if ((prtd->channel_mode == 2) && (lgain != rgain)) { pr_debug("%s: call q6asm_set_lrgain\n", __func__); rc = q6asm_set_lrgain(prtd->audio_client, lgain, rgain); } else { avg_vol = (lgain + rgain)/2; pr_debug("%s: call q6asm_set_volume\n", __func__); rc = q6asm_set_volume(prtd->audio_client, avg_vol); } if (rc < 0) { pr_err("%s: Send Volume command failed rc=%d\n", __func__, rc); } } return rc; } static int msm_compr_playback_close(struct snd_pcm_substream *substream) { struct snd_pcm_runtime *runtime = substream->runtime; struct snd_soc_pcm_runtime *soc_prtd = substream->private_data; struct compr_audio *compr = runtime->private_data; struct msm_audio *prtd = &compr->prtd; int dir = 0; pr_debug("%s\n", __func__); dir = IN; atomic_set(&prtd->pending_buffer, 0); if (atomic_read(&compressed_audio.audio_ocmem_req) > 1) atomic_dec(&compressed_audio.audio_ocmem_req); else if (atomic_cmpxchg(&compressed_audio.audio_ocmem_req, 1, 0)) audio_ocmem_process_req(AUDIO, false); pr_debug("%s: req: %d\n", __func__, atomic_read(&compressed_audio.audio_ocmem_req)); prtd->pcm_irq_pos = 0; q6asm_cmd(prtd->audio_client, CMD_CLOSE); q6asm_audio_client_buf_free_contiguous(dir, prtd->audio_client); msm_pcm_routing_dereg_phy_stream( soc_prtd->dai_link->be_id, SNDRV_PCM_STREAM_PLAYBACK); q6asm_audio_client_free(prtd->audio_client); kfree(prtd); return 0; } static int msm_compr_capture_close(struct snd_pcm_substream *substream) { struct snd_pcm_runtime *runtime = substream->runtime; struct snd_soc_pcm_runtime *soc_prtd = substream->private_data; struct compr_audio *compr = runtime->private_data; struct msm_audio *prtd = &compr->prtd; int dir = OUT; pr_debug("%s\n", __func__); atomic_set(&prtd->pending_buffer, 0); q6asm_cmd(prtd->audio_client, CMD_CLOSE); q6asm_audio_client_buf_free_contiguous(dir, prtd->audio_client); msm_pcm_routing_dereg_phy_stream(soc_prtd->dai_link->be_id, SNDRV_PCM_STREAM_CAPTURE); q6asm_audio_client_free(prtd->audio_client); kfree(prtd); return 0; } static int msm_compr_close(struct snd_pcm_substream *substream) { int ret = 0; if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) ret = msm_compr_playback_close(substream); else if (substream->stream == SNDRV_PCM_STREAM_CAPTURE) ret = msm_compr_capture_close(substream); return ret; } static int msm_compr_prepare(struct snd_pcm_substream *substream) { int ret = 0; if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) ret = msm_compr_playback_prepare(substream); else if (substream->stream == SNDRV_PCM_STREAM_CAPTURE) ret = msm_compr_capture_prepare(substream); return ret; } static snd_pcm_uframes_t msm_compr_pointer(struct snd_pcm_substream *substream) { struct snd_pcm_runtime *runtime = substream->runtime; struct compr_audio *compr = runtime->private_data; struct msm_audio *prtd = &compr->prtd; if (prtd->pcm_irq_pos >= prtd->pcm_size) prtd->pcm_irq_pos = 0; pr_debug("%s: pcm_irq_pos = %d, pcm_size = %d, sample_bits = %d,\n" "frame_bits = %d\n", __func__, prtd->pcm_irq_pos, prtd->pcm_size, runtime->sample_bits, runtime->frame_bits); return bytes_to_frames(runtime, (prtd->pcm_irq_pos)); } static int msm_compr_mmap(struct snd_pcm_substream *substream, struct vm_area_struct *vma) { struct snd_pcm_runtime *runtime = substream->runtime; struct msm_audio *prtd = runtime->private_data; struct audio_client *ac = prtd->audio_client; struct audio_port_data *apd = ac->port; struct audio_buffer *ab; int dir = -1; prtd->mmap_flag = 1; runtime->render_flag = SNDRV_NON_DMA_MODE; if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) dir = IN; else dir = OUT; ab = &(apd[dir].buf[0]); return msm_audio_ion_mmap(ab, vma); } static int msm_compr_hw_params(struct snd_pcm_substream *substream, struct snd_pcm_hw_params *params) { struct snd_pcm_runtime *runtime = substream->runtime; struct compr_audio *compr = runtime->private_data; struct msm_audio *prtd = &compr->prtd; struct snd_dma_buffer *dma_buf = &substream->dma_buffer; struct audio_buffer *buf; int dir, ret; if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) dir = IN; else dir = OUT; /* Modifying kernel hardware params based on userspace config */ if (params_periods(params) > 0 && (params_periods(params) != runtime->hw.periods_max)) { runtime->hw.periods_max = params_periods(params); } if (params_period_bytes(params) > 0 && (params_period_bytes(params) != runtime->hw.period_bytes_min)) { runtime->hw.period_bytes_min = params_period_bytes(params); } runtime->hw.buffer_bytes_max = runtime->hw.period_bytes_min * runtime->hw.periods_max; pr_debug("allocate %zd buffers each of size %d\n", runtime->hw.period_bytes_min, runtime->hw.periods_max); ret = q6asm_audio_client_buf_alloc_contiguous(dir, prtd->audio_client, runtime->hw.period_bytes_min, runtime->hw.periods_max); if (ret < 0) { pr_err("Audio Start: Buffer Allocation failed rc = %d\n", ret); return -ENOMEM; } buf = prtd->audio_client->port[dir].buf; dma_buf->dev.type = SNDRV_DMA_TYPE_DEV; dma_buf->dev.dev = substream->pcm->card->dev; dma_buf->private_data = NULL; dma_buf->area = buf[0].data; dma_buf->addr = buf[0].phys; dma_buf->bytes = runtime->hw.buffer_bytes_max; pr_debug("%s: buf[%p]dma_buf->area[%p]dma_buf->addr[%pa]\n" "dma_buf->bytes[%zd]\n", __func__, (void *)buf, (void *)dma_buf->area, &dma_buf->addr, dma_buf->bytes); if (!dma_buf->area) return -ENOMEM; snd_pcm_set_runtime_buffer(substream, &substream->dma_buffer); return 0; } static int msm_compr_ioctl_shared(struct snd_pcm_substream *substream, unsigned int cmd, void *arg) { int rc = 0; struct snd_pcm_runtime *runtime = substream->runtime; struct compr_audio *compr = runtime->private_data; struct msm_audio *prtd = &compr->prtd; uint64_t timestamp; uint64_t temp; switch (cmd) { case SNDRV_COMPRESS_TSTAMP: { struct snd_compr_tstamp *tstamp; pr_debug("SNDRV_COMPRESS_TSTAMP\n"); tstamp = arg; memset(tstamp, 0x0, sizeof(*tstamp)); rc = q6asm_get_session_time(prtd->audio_client, &timestamp); if (rc < 0) { pr_err("%s: Get Session Time return value =%lld\n", __func__, timestamp); return -EAGAIN; } temp = (timestamp * 2 * runtime->channels); temp = temp * (runtime->rate/1000); temp = div_u64(temp, 1000); tstamp->sampling_rate = runtime->rate; tstamp->timestamp = timestamp; pr_debug("%s: bytes_consumed:,timestamp = %lld,\n", __func__, tstamp->timestamp); return 0; } case SNDRV_COMPRESS_GET_CAPS: { struct snd_compr_caps *caps; caps = arg; memset(caps, 0, sizeof(*caps)); pr_debug("SNDRV_COMPRESS_GET_CAPS\n"); memcpy(caps, &compr->info.compr_cap, sizeof(*caps)); return 0; } case SNDRV_COMPRESS_SET_PARAMS: pr_debug("SNDRV_COMPRESS_SET_PARAMS:\n"); memcpy(&compr->info.codec_param, (void *) arg, sizeof(struct snd_compr_params)); switch (compr->info.codec_param.codec.id) { case SND_AUDIOCODEC_MP3: /* For MP3 we dont need any other parameter */ pr_debug("SND_AUDIOCODEC_MP3\n"); compr->codec = FORMAT_MP3; break; case SND_AUDIOCODEC_AAC: pr_debug("SND_AUDIOCODEC_AAC\n"); compr->codec = FORMAT_MPEG4_AAC; break; case SND_AUDIOCODEC_AC3: { char params_value[MAX_AC3_PARAM_SIZE]; int *params_value_data = (int *)params_value; /* 36 is the max param length for ddp */ int i; struct snd_dec_ddp *ddp = &compr->info.codec_param.codec.options.ddp; uint32_t params_length = 0; /* check integer overflow */ if (ddp->params_length > UINT_MAX/sizeof(int)) { pr_err("%s: Integer overflow ddp->params_length %d\n", __func__, ddp->params_length); return -EINVAL; } params_length = ddp->params_length*sizeof(int); if (params_length > MAX_AC3_PARAM_SIZE) { /*MAX is 36*sizeof(int) this should not happen*/ pr_err("%s: params_length(%d) is greater than %zd\n", __func__, params_length, MAX_AC3_PARAM_SIZE); return -EINVAL; } pr_debug("SND_AUDIOCODEC_AC3\n"); compr->codec = FORMAT_AC3; pr_debug("params_length: %d\n", ddp->params_length); for (i = 0; i < params_length/sizeof(int); i++) pr_debug("params_value[%d]: %x\n", i, params_value_data[i]); for (i = 0; i < ddp->params_length/2; i++) { ddp->params_id[i] = params_value_data[2*i]; ddp->params_value[i] = params_value_data[2*i+1]; } if (atomic_read(&prtd->start)) { rc = msm_compr_send_ddp_cfg(prtd->audio_client, ddp); if (rc < 0) pr_err("%s: DDP CMD CFG failed\n", __func__); } break; } case SND_AUDIOCODEC_EAC3: { char params_value[MAX_AC3_PARAM_SIZE]; int *params_value_data = (int *)params_value; /* 36 is the max param length for ddp */ int i; struct snd_dec_ddp *ddp = &compr->info.codec_param.codec.options.ddp; uint32_t params_length = 0; /* check integer overflow */ if (ddp->params_length > UINT_MAX/sizeof(int)) { pr_err("%s: Integer overflow ddp->params_length %d\n", __func__, ddp->params_length); return -EINVAL; } if (params_length > MAX_AC3_PARAM_SIZE) { /*MAX is 36*sizeof(int) this should not happen*/ pr_err("%s: params_length(%d) is greater than %zd\n", __func__, params_length, MAX_AC3_PARAM_SIZE); return -EINVAL; } pr_debug("SND_AUDIOCODEC_EAC3\n"); compr->codec = FORMAT_EAC3; pr_debug("params_length: %d\n", ddp->params_length); for (i = 0; i < ddp->params_length; i++) pr_debug("params_value[%d]: %x\n", i, params_value_data[i]); for (i = 0; i < ddp->params_length/2; i++) { ddp->params_id[i] = params_value_data[2*i]; ddp->params_value[i] = params_value_data[2*i+1]; } if (atomic_read(&prtd->start)) { rc = msm_compr_send_ddp_cfg(prtd->audio_client, ddp); if (rc < 0) pr_err("%s: DDP CMD CFG failed\n", __func__); } break; } default: pr_debug("FORMAT_LINEAR_PCM\n"); compr->codec = FORMAT_LINEAR_PCM; break; } return 0; case SNDRV_PCM_IOCTL1_RESET: pr_debug("SNDRV_PCM_IOCTL1_RESET\n"); /* Flush only when session is started during CAPTURE, while PLAYBACK has no such restriction. */ if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK || (substream->stream == SNDRV_PCM_STREAM_CAPTURE && atomic_read(&prtd->start))) { if (atomic_read(&prtd->eos)) { prtd->cmd_interrupt = 1; wake_up(&the_locks.eos_wait); atomic_set(&prtd->eos, 0); } /* A unlikely race condition possible with FLUSH DRAIN if ack is set by flush and reset by drain */ prtd->cmd_ack = 0; rc = q6asm_cmd(prtd->audio_client, CMD_FLUSH); if (rc < 0) { pr_err("%s: flush cmd failed rc=%d\n", __func__, rc); return rc; } rc = wait_event_timeout(the_locks.flush_wait, prtd->cmd_ack, 5 * HZ); if (!rc) pr_err("Flush cmd timeout\n"); prtd->pcm_irq_pos = 0; } break; case SNDRV_COMPRESS_DRAIN: pr_debug("%s: SNDRV_COMPRESS_DRAIN\n", __func__); if (atomic_read(&prtd->pending_buffer)) { pr_debug("%s: no pending writes, drain would block\n", __func__); return -EWOULDBLOCK; } atomic_set(&prtd->eos, 1); atomic_set(&prtd->pending_buffer, 0); prtd->cmd_ack = 0; q6asm_cmd_nowait(prtd->audio_client, CMD_EOS); /* Wait indefinitely for DRAIN. Flush can also signal this*/ rc = wait_event_interruptible(the_locks.eos_wait, (prtd->cmd_ack || prtd->cmd_interrupt)); if (rc < 0) pr_err("EOS cmd interrupted\n"); pr_debug("%s: SNDRV_COMPRESS_DRAIN out of wait\n", __func__); if (prtd->cmd_interrupt) rc = -EINTR; prtd->cmd_interrupt = 0; return rc; default: break; } return snd_pcm_lib_ioctl(substream, cmd, arg); } #ifdef CONFIG_COMPAT struct snd_enc_wma32 { u32 super_block_align; /* WMA Type-specific data */ u32 encodeopt1; u32 encodeopt2; }; struct snd_enc_vorbis32 { s32 quality; u32 managed; u32 max_bit_rate; u32 min_bit_rate; u32 downmix; }; struct snd_enc_real32 { u32 quant_bits; u32 start_region; u32 num_regions; }; struct snd_enc_flac32 { u32 num; u32 gain; }; struct snd_enc_generic32 { u32 bw; /* encoder bandwidth */ s32 reserved[15]; }; struct snd_dec_ddp32 { u32 params_length; u32 params_id[18]; u32 params_value[18]; }; union snd_codec_options32 { struct snd_enc_wma32 wma; struct snd_enc_vorbis32 vorbis; struct snd_enc_real32 real; struct snd_enc_flac32 flac; struct snd_enc_generic32 generic; struct snd_dec_ddp32 ddp; }; struct snd_codec32 { u32 id; u32 ch_in; u32 ch_out; u32 sample_rate; u32 bit_rate; u32 rate_control; u32 profile; u32 level; u32 ch_mode; u32 format; u32 align; union snd_codec_options32 options; u32 reserved[3]; }; struct snd_compressed_buffer32 { u32 fragment_size; u32 fragments; }; struct snd_compr_params32 { struct snd_compressed_buffer32 buffer; struct snd_codec32 codec; u8 no_wake_mode; }; struct snd_compr_caps32 { u32 num_codecs; u32 direction; u32 min_fragment_size; u32 max_fragment_size; u32 min_fragments; u32 max_fragments; u32 codecs[MAX_NUM_CODECS]; u32 reserved[11]; }; struct snd_compr_tstamp32 { u32 byte_offset; u32 copied_total; compat_ulong_t pcm_frames; compat_ulong_t pcm_io_frames; u32 sampling_rate; compat_u64 timestamp; }; enum { SNDRV_COMPRESS_TSTAMP32 = _IOR('C', 0x20, struct snd_compr_tstamp32), SNDRV_COMPRESS_GET_CAPS32 = _IOWR('C', 0x10, struct snd_compr_caps32), SNDRV_COMPRESS_SET_PARAMS32 = _IOW('C', 0x12, struct snd_compr_params32), }; static int msm_compr_compat_ioctl(struct snd_pcm_substream *substream, unsigned int cmd, void *arg) { int err = 0; switch (cmd) { case SNDRV_COMPRESS_TSTAMP32: { struct snd_compr_tstamp tstamp; struct snd_compr_tstamp32 tstamp32; memset(&tstamp, 0, sizeof(tstamp)); memset(&tstamp32, 0, sizeof(tstamp32)); cmd = SNDRV_COMPRESS_TSTAMP; err = msm_compr_ioctl_shared(substream, cmd, &tstamp); if (err) { pr_err("%s: COMPRESS_TSTAMP failed rc %d\n", __func__, err); goto bail_out; } tstamp32.byte_offset = tstamp.byte_offset; tstamp32.copied_total = tstamp.copied_total; tstamp32.pcm_frames = tstamp.pcm_frames; tstamp32.pcm_io_frames = tstamp.pcm_io_frames; tstamp32.sampling_rate = tstamp.sampling_rate; tstamp32.timestamp = tstamp.timestamp; if (copy_to_user(arg, &tstamp32, sizeof(tstamp32))) { pr_err("%s: copytouser failed COMPRESS_TSTAMP32\n", __func__); err = -EFAULT; } break; } case SNDRV_COMPRESS_GET_CAPS32: { struct snd_compr_caps caps; struct snd_compr_caps32 caps32; u32 i; memset(&caps, 0, sizeof(caps)); memset(&caps32, 0, sizeof(caps32)); cmd = SNDRV_COMPRESS_GET_CAPS; err = msm_compr_ioctl_shared(substream, cmd, &caps); if (err) { pr_err("%s: GET_CAPS failed rc %d\n", __func__, err); goto bail_out; } pr_debug("SNDRV_COMPRESS_GET_CAPS_32\n"); if (!err && caps.num_codecs >= MAX_NUM_CODECS) { pr_err("%s: Invalid number of codecs\n", __func__); err = -EINVAL; goto bail_out; } caps32.direction = caps.direction; caps32.max_fragment_size = caps.max_fragment_size; caps32.max_fragments = caps.max_fragments; caps32.min_fragment_size = caps.min_fragment_size; caps32.num_codecs = caps.num_codecs; for (i = 0; i < caps.num_codecs; i++) caps32.codecs[i] = caps.codecs[i]; if (copy_to_user(arg, &caps32, sizeof(caps32))) { pr_err("%s: copytouser failed COMPRESS_GETCAPS32\n", __func__); err = -EFAULT; } break; } case SNDRV_COMPRESS_SET_PARAMS32: { struct snd_compr_params32 params32; struct snd_compr_params params; memset(&params32, 0 , sizeof(params32)); memset(&params, 0 , sizeof(params)); cmd = SNDRV_COMPRESS_SET_PARAMS; if (copy_from_user(&params32, arg, sizeof(params32))) { pr_err("%s: copyfromuser failed SET_PARAMS32\n", __func__); err = -EFAULT; goto bail_out; } params.no_wake_mode = params32.no_wake_mode; params.codec.id = params32.codec.id; params.codec.ch_in = params32.codec.ch_in; params.codec.ch_out = params32.codec.ch_out; params.codec.sample_rate = params32.codec.sample_rate; params.codec.bit_rate = params32.codec.bit_rate; params.codec.rate_control = params32.codec.rate_control; params.codec.profile = params32.codec.profile; params.codec.level = params32.codec.level; params.codec.ch_mode = params32.codec.ch_mode; params.codec.format = params32.codec.format; params.codec.align = params32.codec.align; switch (params.codec.id) { case SND_AUDIOCODEC_WMA: case SND_AUDIOCODEC_WMA_PRO: params.codec.options.wma.encodeopt1 = params32.codec.options.wma.encodeopt1; params.codec.options.wma.encodeopt2 = params32.codec.options.wma.encodeopt2; params.codec.options.wma.super_block_align = params32.codec.options.wma.super_block_align; break; case SND_AUDIOCODEC_VORBIS: params.codec.options.vorbis.downmix = params32.codec.options.vorbis.downmix; params.codec.options.vorbis.managed = params32.codec.options.vorbis.managed; params.codec.options.vorbis.max_bit_rate = params32.codec.options.vorbis.max_bit_rate; params.codec.options.vorbis.min_bit_rate = params32.codec.options.vorbis.min_bit_rate; params.codec.options.vorbis.quality = params32.codec.options.vorbis.quality; break; case SND_AUDIOCODEC_REAL: params.codec.options.real.num_regions = params32.codec.options.real.num_regions; params.codec.options.real.quant_bits = params32.codec.options.real.quant_bits; params.codec.options.real.start_region = params32.codec.options.real.start_region; break; case SND_AUDIOCODEC_FLAC: params.codec.options.flac.gain = params32.codec.options.flac.gain; params.codec.options.flac.num = params32.codec.options.flac.num; break; case SND_AUDIOCODEC_DTS: case SND_AUDIOCODEC_DTS_PASS_THROUGH: case SND_AUDIOCODEC_DTS_LBR: case SND_AUDIOCODEC_DTS_LBR_PASS_THROUGH: case SND_AUDIOCODEC_DTS_TRANSCODE_LOOPBACK: break; case SND_AUDIOCODEC_AC3: case SND_AUDIOCODEC_EAC3: params.codec.options.ddp.params_length = params32.codec.options.ddp.params_length; memcpy(params.codec.options.ddp.params_value, params32.codec.options.ddp.params_value, sizeof(params32.codec.options.ddp.params_value)); memcpy(params.codec.options.ddp.params_id, params32.codec.options.ddp.params_id, sizeof(params32.codec.options.ddp.params_id)); break; default: params.codec.options.generic.bw = params32.codec.options.generic.bw; break; } if (!err) err = msm_compr_ioctl_shared(substream, cmd, &params); break; } default: err = msm_compr_ioctl_shared(substream, cmd, arg); } bail_out: return err; } #endif static int msm_compr_ioctl(struct snd_pcm_substream *substream, unsigned int cmd, void *arg) { int err = 0; if (!substream) { pr_err("%s: Invalid params\n", __func__); return -EINVAL; } pr_debug("%s called with cmd = %d\n", __func__, cmd); switch (cmd) { case SNDRV_COMPRESS_TSTAMP: { struct snd_compr_tstamp tstamp; if (!arg) { pr_err("%s: Invalid params Tstamp\n", __func__); return -EINVAL; } err = msm_compr_ioctl_shared(substream, cmd, &tstamp); if (err) pr_err("%s: COMPRESS_TSTAMP failed rc %d\n", __func__, err); if (!err && copy_to_user(arg, &tstamp, sizeof(tstamp))) { pr_err("%s: copytouser failed COMPRESS_TSTAMP\n", __func__); err = -EFAULT; } break; } case SNDRV_COMPRESS_GET_CAPS: { struct snd_compr_caps cap; if (!arg) { pr_err("%s: Invalid params getcaps\n", __func__); return -EINVAL; } pr_debug("SNDRV_COMPRESS_GET_CAPS\n"); err = msm_compr_ioctl_shared(substream, cmd, &cap); if (err) pr_err("%s: GET_CAPS failed rc %d\n", __func__, err); if (!err && copy_to_user(arg, &cap, sizeof(cap))) { pr_err("%s: copytouser failed GET_CAPS\n", __func__); err = -EFAULT; } break; } case SNDRV_COMPRESS_SET_PARAMS: { struct snd_compr_params params; if (!arg) { pr_err("%s: Invalid params setparam\n", __func__); return -EINVAL; } if (copy_from_user(&params, arg, sizeof(struct snd_compr_params))) { pr_err("%s: SET_PARAMS\n", __func__); return -EFAULT; } err = msm_compr_ioctl_shared(substream, cmd, &params); if (err) pr_err("%s: SET_PARAMS failed rc %d\n", __func__, err); break; } default: err = msm_compr_ioctl_shared(substream, cmd, arg); } return err; } static int msm_compr_restart(struct snd_pcm_substream *substream) { struct snd_pcm_runtime *runtime = substream->runtime; struct compr_audio *compr = runtime->private_data; struct msm_audio *prtd = &compr->prtd; struct audio_aio_write_param param; struct audio_buffer *buf = NULL; struct output_meta_data_st output_meta_data; int time_stamp_flag = 0; int buffer_length = 0; pr_debug("%s, trigger restart\n", __func__); if (runtime->render_flag & SNDRV_RENDER_STOPPED) { buf = prtd->audio_client->port[IN].buf; pr_debug("%s:writing %d bytes of buffer[%d] to dsp 2\n", __func__, prtd->pcm_count, prtd->out_head); pr_debug("%s:writing buffer[%d] from 0x%08x\n", __func__, prtd->out_head, ((unsigned int)buf[0].phys + (prtd->out_head * prtd->pcm_count))); if (runtime->tstamp_mode == SNDRV_PCM_TSTAMP_ENABLE) time_stamp_flag = SET_TIMESTAMP; else time_stamp_flag = NO_TIMESTAMP; memcpy(&output_meta_data, (char *)(buf->data + prtd->out_head * prtd->pcm_count), COMPRE_OUTPUT_METADATA_SIZE); buffer_length = output_meta_data.frame_size; pr_debug("meta_data_length: %d, frame_length: %d\n", output_meta_data.meta_data_length, output_meta_data.frame_size); pr_debug("timestamp_msw: %d, timestamp_lsw: %d\n", output_meta_data.timestamp_msw, output_meta_data.timestamp_lsw); param.paddr = (unsigned long)buf[0].phys + (prtd->out_head * prtd->pcm_count) + output_meta_data.meta_data_length; param.len = buffer_length; param.msw_ts = output_meta_data.timestamp_msw; param.lsw_ts = output_meta_data.timestamp_lsw; param.flags = time_stamp_flag; param.uid = prtd->session_id; if (q6asm_async_write(prtd->audio_client, &param) < 0) pr_err("%s:q6asm_async_write failed\n", __func__); else prtd->out_head = (prtd->out_head + 1) & (runtime->periods - 1); runtime->render_flag &= ~SNDRV_RENDER_STOPPED; return 0; } return 0; } static int msm_compr_volume_ctl_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { int rc = 0; struct snd_pcm_volume *vol = snd_kcontrol_chip(kcontrol); struct snd_pcm_substream *substream = vol->pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream; struct msm_audio *prtd; int volume = ucontrol->value.integer.value[0]; pr_debug("%s: volume : %x\n", __func__, volume); if (!substream) return -ENODEV; if (!substream->runtime) return 0; prtd = substream->runtime->private_data; if (prtd) rc = compressed_set_volume(prtd, volume); return rc; } static int msm_compr_volume_ctl_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct snd_pcm_volume *vol = snd_kcontrol_chip(kcontrol); struct snd_pcm_substream *substream = vol->pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream; struct msm_audio *prtd; pr_debug("%s\n", __func__); if (!substream) return -ENODEV; if (!substream->runtime) return 0; prtd = substream->runtime->private_data; if (prtd) ucontrol->value.integer.value[0] = prtd->volume; return 0; } static int msm_compr_add_controls(struct snd_soc_pcm_runtime *rtd) { int ret = 0; struct snd_pcm *pcm = rtd->pcm; struct snd_pcm_volume *volume_info; struct snd_kcontrol *kctl; dev_dbg(rtd->dev, "%s, Volume cntrl add\n", __func__); ret = snd_pcm_add_volume_ctls(pcm, SNDRV_PCM_STREAM_PLAYBACK, NULL, 1, rtd->dai_link->be_id, &volume_info); if (ret < 0) return ret; kctl = volume_info->kctl; kctl->put = msm_compr_volume_ctl_put; kctl->get = msm_compr_volume_ctl_get; kctl->tlv.p = compr_rx_vol_gain; return 0; } static struct snd_pcm_ops msm_compr_ops = { .open = msm_compr_open, .hw_params = msm_compr_hw_params, .close = msm_compr_close, .ioctl = msm_compr_ioctl, .prepare = msm_compr_prepare, .trigger = msm_compr_trigger, .pointer = msm_compr_pointer, .mmap = msm_compr_mmap, .restart = msm_compr_restart, #ifdef CONFIG_COMPAT .compat_ioctl = msm_compr_compat_ioctl, #endif }; static int msm_asoc_pcm_new(struct snd_soc_pcm_runtime *rtd) { struct snd_card *card = rtd->card->snd_card; int ret = 0; if (!card->dev->coherent_dma_mask) card->dev->coherent_dma_mask = DMA_BIT_MASK(32); ret = msm_compr_add_controls(rtd); if (ret) pr_err("%s, kctl add failed\n", __func__); return ret; } static struct snd_soc_platform_driver msm_soc_platform = { .ops = &msm_compr_ops, .pcm_new = msm_asoc_pcm_new, }; static int msm_compr_probe(struct platform_device *pdev) { if (pdev->dev.of_node) dev_set_name(&pdev->dev, "%s", "msm-compr-dsp"); dev_info(&pdev->dev, "%s: dev name %s\n", __func__, dev_name(&pdev->dev)); atomic_set(&compressed_audio.audio_ocmem_req, 0); return snd_soc_register_platform(&pdev->dev, &msm_soc_platform); } static int msm_compr_remove(struct platform_device *pdev) { snd_soc_unregister_platform(&pdev->dev); return 0; } static const struct of_device_id msm_compr_dt_match[] = { {.compatible = "qcom,msm-compr-dsp"}, {} }; MODULE_DEVICE_TABLE(of, msm_compr_dt_match); static struct platform_driver msm_compr_driver = { .driver = { .name = "msm-compr-dsp", .owner = THIS_MODULE, .of_match_table = msm_compr_dt_match, }, .probe = msm_compr_probe, .remove = msm_compr_remove, }; static int __init msm_soc_platform_init(void) { init_waitqueue_head(&the_locks.enable_wait); init_waitqueue_head(&the_locks.eos_wait); init_waitqueue_head(&the_locks.write_wait); init_waitqueue_head(&the_locks.read_wait); init_waitqueue_head(&the_locks.flush_wait); return platform_driver_register(&msm_compr_driver); } module_init(msm_soc_platform_init); static void __exit msm_soc_platform_exit(void) { platform_driver_unregister(&msm_compr_driver); } module_exit(msm_soc_platform_exit); MODULE_DESCRIPTION("PCM module platform driver"); MODULE_LICENSE("GPL v2");
gpl-2.0
tkymgr/semc_kernel
arch/arm/mach-msm/proc_comm.c
17
4098
/* arch/arm/mach-msm/proc_comm.c * * Copyright (C) 2007-2008 Google, Inc. * Copyright (c) 2009, Code Aurora Forum. All rights reserved. * Author: Brian Swetland <swetland@google.com> * * This software is licensed under the terms of the GNU General Public * License version 2, as published by the Free Software Foundation, and * may be copied, distributed, and modified under those terms. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * */ #include <linux/delay.h> #include <linux/errno.h> #include <linux/io.h> #include <linux/spinlock.h> #include <linux/module.h> #include <mach/msm_iomap.h> #include <mach/system.h> #include "proc_comm.h" #if defined(CONFIG_ARCH_MSM7X30) #define MSM_TRIG_A2M_INT(n) (writel(1 << n, MSM_GCC_BASE + 0x8)) #else #define MSM_TRIG_A2M_INT(n) (writel(1, MSM_CSR_BASE + 0x400 + (n) * 4)) #endif static inline void notify_other_proc_comm(void) { MSM_TRIG_A2M_INT(6); } #define APP_COMMAND 0x00 #define APP_STATUS 0x04 #define APP_DATA1 0x08 #define APP_DATA2 0x0C #define MDM_COMMAND 0x10 #define MDM_STATUS 0x14 #define MDM_DATA1 0x18 #define MDM_DATA2 0x1C static DEFINE_SPINLOCK(proc_comm_lock); /* The higher level SMD support will install this to * provide a way to check for and handle modem restart? */ int (*msm_check_for_modem_crash)(void); /* Poll for a state change, checking for possible * modem crashes along the way (so we don't wait * forever while the ARM9 is blowing up. * * Return an error in the event of a modem crash and * restart so the msm_proc_comm() routine can restart * the operation from the beginning. */ static int proc_comm_wait_for(unsigned addr, unsigned value) { while (1) { if (readl(addr) == value) return 0; if (msm_check_for_modem_crash) if (msm_check_for_modem_crash()) return -EAGAIN; udelay(5); } } void msm_proc_comm_reset_modem_now(void) { unsigned base = (unsigned)MSM_SHARED_RAM_BASE; unsigned long flags; spin_lock_irqsave(&proc_comm_lock, flags); again: if (proc_comm_wait_for(base + MDM_STATUS, PCOM_READY)) goto again; writel(PCOM_RESET_MODEM, base + APP_COMMAND); writel(0, base + APP_DATA1); writel(0, base + APP_DATA2); spin_unlock_irqrestore(&proc_comm_lock, flags); notify_other_proc_comm(); return; } EXPORT_SYMBOL(msm_proc_comm_reset_modem_now); #ifndef CONFIG_CAPTURE_KERNEL int msm_proc_comm(unsigned cmd, unsigned *data1, unsigned *data2) { unsigned base = (unsigned)MSM_SHARED_RAM_BASE; unsigned long flags; int ret; spin_lock_irqsave(&proc_comm_lock, flags); again: if (proc_comm_wait_for(base + MDM_STATUS, PCOM_READY)) goto again; writel(cmd, base + APP_COMMAND); writel(data1 ? *data1 : 0, base + APP_DATA1); writel(data2 ? *data2 : 0, base + APP_DATA2); notify_other_proc_comm(); if (proc_comm_wait_for(base + APP_COMMAND, PCOM_CMD_DONE)) goto again; if (readl(base + APP_STATUS) == PCOM_CMD_SUCCESS) { if (data1) *data1 = readl(base + APP_DATA1); if (data2) *data2 = readl(base + APP_DATA2); ret = 0; } else { ret = -EIO; } writel(PCOM_CMD_IDLE, base + APP_COMMAND); spin_unlock_irqrestore(&proc_comm_lock, flags); return ret; } #else int msm_proc_comm(unsigned cmd, unsigned *data1, unsigned *data2) { unsigned int base = (unsigned int)MSM_SHARED_RAM_BASE; unsigned long flags; int ret = 0; spin_lock_irqsave(&proc_comm_lock, flags); writel(data1 ? *data1 : 0, base + APP_DATA1); writel(data2 ? *data2 : 0, base + APP_DATA2); writel(cmd, base + APP_COMMAND); while (readl(base + APP_COMMAND) != PCOM_CMD_DONE) { udelay(5); } if ((readl(base + APP_STATUS)) == PCOM_CMD_SUCCESS) { if (data1) *data1 = readl(base + APP_DATA1); if (data2) *data2 = readl(base + APP_DATA2); ret = 0; } else { ret = -EIO; } writel(PCOM_CMD_IDLE, base + APP_COMMAND); spin_unlock_irqrestore(&proc_comm_lock, flags); return ret; } #endif EXPORT_SYMBOL(msm_proc_comm);
gpl-2.0
Atomicorp/clamav-devel
libclamav/c++/llvm/lib/Transforms/Hello/Hello.cpp
17
1985
//===- Hello.cpp - Example code from "Writing an LLVM Pass" ---------------===// // // The LLVM Compiler Infrastructure // // This file is distributed under the University of Illinois Open Source // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// // // This file implements two versions of the LLVM "Hello World" pass described // in docs/WritingAnLLVMPass.html // //===----------------------------------------------------------------------===// #define DEBUG_TYPE "hello" #include "llvm/Pass.h" #include "llvm/Function.h" #include "llvm/Support/raw_ostream.h" #include "llvm/ADT/Statistic.h" using namespace llvm; STATISTIC(HelloCounter, "Counts number of functions greeted"); namespace { // Hello - The first implementation, without getAnalysisUsage. struct Hello : public FunctionPass { static char ID; // Pass identification, replacement for typeid Hello() : FunctionPass(ID) {} virtual bool runOnFunction(Function &F) { ++HelloCounter; errs() << "Hello: "; errs().write_escaped(F.getName()) << '\n'; return false; } }; } char Hello::ID = 0; INITIALIZE_PASS(Hello, "hello", "Hello World Pass", false, false); namespace { // Hello2 - The second implementation with getAnalysisUsage implemented. struct Hello2 : public FunctionPass { static char ID; // Pass identification, replacement for typeid Hello2() : FunctionPass(ID) {} virtual bool runOnFunction(Function &F) { ++HelloCounter; errs() << "Hello: "; errs().write_escaped(F.getName()) << '\n'; return false; } // We don't modify the program, so we preserve all analyses virtual void getAnalysisUsage(AnalysisUsage &AU) const { AU.setPreservesAll(); } }; } char Hello2::ID = 0; INITIALIZE_PASS(Hello2, "hello2", "Hello World Pass (with getAnalysisUsage implemented)", false, false);
gpl-2.0
goldelico/letux-400
drivers/char/mem.c
17
20345
/* * linux/drivers/char/mem.c * * Copyright (C) 1991, 1992 Linus Torvalds * * Added devfs support. * Jan-11-1998, C. Scott Ananian <cananian@alumni.princeton.edu> * Shared /dev/zero mmaping support, Feb 2000, Kanoj Sarcar <kanoj@sgi.com> */ #include <linux/mm.h> #include <linux/miscdevice.h> #include <linux/slab.h> #include <linux/vmalloc.h> #include <linux/mman.h> #include <linux/random.h> #include <linux/init.h> #include <linux/raw.h> #include <linux/tty.h> #include <linux/capability.h> #include <linux/ptrace.h> #include <linux/device.h> #include <linux/highmem.h> #include <linux/crash_dump.h> #include <linux/backing-dev.h> #include <linux/bootmem.h> #include <linux/splice.h> #include <linux/pfn.h> #include <asm/uaccess.h> #include <asm/io.h> #ifdef CONFIG_IA64 # include <linux/efi.h> #endif /* * Architectures vary in how they handle caching for addresses * outside of main memory. * */ static inline int uncached_access(struct file *file, unsigned long addr) { #if defined(__i386__) && !defined(__arch_um__) /* * On the PPro and successors, the MTRRs are used to set * memory types for physical addresses outside main memory, * so blindly setting PCD or PWT on those pages is wrong. * For Pentiums and earlier, the surround logic should disable * caching for the high addresses through the KEN pin, but * we maintain the tradition of paranoia in this code. */ if (file->f_flags & O_SYNC) return 1; return !( test_bit(X86_FEATURE_MTRR, boot_cpu_data.x86_capability) || test_bit(X86_FEATURE_K6_MTRR, boot_cpu_data.x86_capability) || test_bit(X86_FEATURE_CYRIX_ARR, boot_cpu_data.x86_capability) || test_bit(X86_FEATURE_CENTAUR_MCR, boot_cpu_data.x86_capability) ) && addr >= __pa(high_memory); #elif defined(__x86_64__) && !defined(__arch_um__) /* * This is broken because it can generate memory type aliases, * which can cause cache corruptions * But it is only available for root and we have to be bug-to-bug * compatible with i386. */ if (file->f_flags & O_SYNC) return 1; /* same behaviour as i386. PAT always set to cached and MTRRs control the caching behaviour. Hopefully a full PAT implementation will fix that soon. */ return 0; #elif defined(CONFIG_IA64) /* * On ia64, we ignore O_SYNC because we cannot tolerate memory attribute aliases. */ return !(efi_mem_attributes(addr) & EFI_MEMORY_WB); #elif defined(CONFIG_MIPS) { extern int __uncached_access(struct file *file, unsigned long addr); return __uncached_access(file, addr); } #else /* * Accessing memory above the top the kernel knows about or through a file pointer * that was marked O_SYNC will be done non-cached. */ if (file->f_flags & O_SYNC) return 1; return addr >= __pa(high_memory); #endif } #ifndef ARCH_HAS_VALID_PHYS_ADDR_RANGE static inline int valid_phys_addr_range(unsigned long addr, size_t count) { if (addr + count > __pa(high_memory)) return 0; return 1; } static inline int valid_mmap_phys_addr_range(unsigned long pfn, size_t size) { return 1; } #endif /* * This funcion reads the *physical* memory. The f_pos points directly to the * memory location. */ static ssize_t read_mem(struct file * file, char __user * buf, size_t count, loff_t *ppos) { unsigned long p = *ppos; ssize_t read, sz; char *ptr; if (!valid_phys_addr_range(p, count)) return -EFAULT; read = 0; #ifdef __ARCH_HAS_NO_PAGE_ZERO_MAPPED /* we don't have page 0 mapped on sparc and m68k.. */ if (p < PAGE_SIZE) { sz = PAGE_SIZE - p; if (sz > count) sz = count; if (sz > 0) { if (clear_user(buf, sz)) return -EFAULT; buf += sz; p += sz; count -= sz; read += sz; } } #endif while (count > 0) { /* * Handle first page in case it's not aligned */ if (-p & (PAGE_SIZE - 1)) sz = -p & (PAGE_SIZE - 1); else sz = PAGE_SIZE; sz = min_t(unsigned long, sz, count); /* * On ia64 if a page has been mapped somewhere as * uncached, then it must also be accessed uncached * by the kernel or data corruption may occur */ ptr = xlate_dev_mem_ptr(p); if (copy_to_user(buf, ptr, sz)) return -EFAULT; buf += sz; p += sz; count -= sz; read += sz; } *ppos += read; return read; } static ssize_t write_mem(struct file * file, const char __user * buf, size_t count, loff_t *ppos) { unsigned long p = *ppos; ssize_t written, sz; unsigned long copied; void *ptr; if (!valid_phys_addr_range(p, count)) return -EFAULT; written = 0; #ifdef __ARCH_HAS_NO_PAGE_ZERO_MAPPED /* we don't have page 0 mapped on sparc and m68k.. */ if (p < PAGE_SIZE) { unsigned long sz = PAGE_SIZE - p; if (sz > count) sz = count; /* Hmm. Do something? */ buf += sz; p += sz; count -= sz; written += sz; } #endif while (count > 0) { /* * Handle first page in case it's not aligned */ if (-p & (PAGE_SIZE - 1)) sz = -p & (PAGE_SIZE - 1); else sz = PAGE_SIZE; sz = min_t(unsigned long, sz, count); /* * On ia64 if a page has been mapped somewhere as * uncached, then it must also be accessed uncached * by the kernel or data corruption may occur */ ptr = xlate_dev_mem_ptr(p); copied = copy_from_user(ptr, buf, sz); if (copied) { written += sz - copied; if (written) break; return -EFAULT; } buf += sz; p += sz; count -= sz; written += sz; } *ppos += written; return written; } #ifndef __HAVE_PHYS_MEM_ACCESS_PROT static pgprot_t phys_mem_access_prot(struct file *file, unsigned long pfn, unsigned long size, pgprot_t vma_prot) { #ifdef pgprot_noncached unsigned long offset = pfn << PAGE_SHIFT; if (uncached_access(file, offset)) return pgprot_noncached(vma_prot); #endif return vma_prot; } #endif #ifndef CONFIG_MMU static unsigned long get_unmapped_area_mem(struct file *file, unsigned long addr, unsigned long len, unsigned long pgoff, unsigned long flags) { if (!valid_mmap_phys_addr_range(pgoff, len)) return (unsigned long) -EINVAL; return pgoff << PAGE_SHIFT; } /* can't do an in-place private mapping if there's no MMU */ static inline int private_mapping_ok(struct vm_area_struct *vma) { return vma->vm_flags & VM_MAYSHARE; } #else #define get_unmapped_area_mem NULL static inline int private_mapping_ok(struct vm_area_struct *vma) { return 1; } #endif static int mmap_mem(struct file * file, struct vm_area_struct * vma) { size_t size = vma->vm_end - vma->vm_start; if (!valid_mmap_phys_addr_range(vma->vm_pgoff, size)) return -EINVAL; if (!private_mapping_ok(vma)) return -ENOSYS; vma->vm_page_prot = phys_mem_access_prot(file, vma->vm_pgoff, size, vma->vm_page_prot); /* Remap-pfn-range will mark the range VM_IO and VM_RESERVED */ if (remap_pfn_range(vma, vma->vm_start, vma->vm_pgoff, size, vma->vm_page_prot)) return -EAGAIN; return 0; } static int mmap_kmem(struct file * file, struct vm_area_struct * vma) { unsigned long pfn; /* Turn a kernel-virtual address into a physical page frame */ pfn = __pa((u64)vma->vm_pgoff << PAGE_SHIFT) >> PAGE_SHIFT; /* * RED-PEN: on some architectures there is more mapped memory * than available in mem_map which pfn_valid checks * for. Perhaps should add a new macro here. * * RED-PEN: vmalloc is not supported right now. */ if (!pfn_valid(pfn)) return -EIO; vma->vm_pgoff = pfn; return mmap_mem(file, vma); } #ifdef CONFIG_CRASH_DUMP /* * Read memory corresponding to the old kernel. */ static ssize_t read_oldmem(struct file *file, char __user *buf, size_t count, loff_t *ppos) { unsigned long pfn, offset; size_t read = 0, csize; int rc = 0; while (count) { pfn = *ppos / PAGE_SIZE; if (pfn > saved_max_pfn) return read; offset = (unsigned long)(*ppos % PAGE_SIZE); if (count > PAGE_SIZE - offset) csize = PAGE_SIZE - offset; else csize = count; rc = copy_oldmem_page(pfn, buf, csize, offset, 1); if (rc < 0) return rc; buf += csize; *ppos += csize; read += csize; count -= csize; } return read; } #endif extern long vread(char *buf, char *addr, unsigned long count); extern long vwrite(char *buf, char *addr, unsigned long count); /* * This function reads the *virtual* memory as seen by the kernel. */ static ssize_t read_kmem(struct file *file, char __user *buf, size_t count, loff_t *ppos) { unsigned long p = *ppos; ssize_t low_count, read, sz; char * kbuf; /* k-addr because vread() takes vmlist_lock rwlock */ read = 0; if (p < (unsigned long) high_memory) { low_count = count; if (count > (unsigned long) high_memory - p) low_count = (unsigned long) high_memory - p; #ifdef __ARCH_HAS_NO_PAGE_ZERO_MAPPED /* we don't have page 0 mapped on sparc and m68k.. */ if (p < PAGE_SIZE && low_count > 0) { size_t tmp = PAGE_SIZE - p; if (tmp > low_count) tmp = low_count; if (clear_user(buf, tmp)) return -EFAULT; buf += tmp; p += tmp; read += tmp; low_count -= tmp; count -= tmp; } #endif while (low_count > 0) { /* * Handle first page in case it's not aligned */ if (-p & (PAGE_SIZE - 1)) sz = -p & (PAGE_SIZE - 1); else sz = PAGE_SIZE; sz = min_t(unsigned long, sz, low_count); /* * On ia64 if a page has been mapped somewhere as * uncached, then it must also be accessed uncached * by the kernel or data corruption may occur */ kbuf = xlate_dev_kmem_ptr((char *)p); if (copy_to_user(buf, kbuf, sz)) return -EFAULT; buf += sz; p += sz; read += sz; low_count -= sz; count -= sz; } } if (count > 0) { kbuf = (char *)__get_free_page(GFP_KERNEL); if (!kbuf) return -ENOMEM; while (count > 0) { int len = count; if (len > PAGE_SIZE) len = PAGE_SIZE; len = vread(kbuf, (char *)p, len); if (!len) break; if (copy_to_user(buf, kbuf, len)) { free_page((unsigned long)kbuf); return -EFAULT; } count -= len; buf += len; read += len; p += len; } free_page((unsigned long)kbuf); } *ppos = p; return read; } static inline ssize_t do_write_kmem(void *p, unsigned long realp, const char __user * buf, size_t count, loff_t *ppos) { ssize_t written, sz; unsigned long copied; written = 0; #ifdef __ARCH_HAS_NO_PAGE_ZERO_MAPPED /* we don't have page 0 mapped on sparc and m68k.. */ if (realp < PAGE_SIZE) { unsigned long sz = PAGE_SIZE - realp; if (sz > count) sz = count; /* Hmm. Do something? */ buf += sz; p += sz; realp += sz; count -= sz; written += sz; } #endif while (count > 0) { char *ptr; /* * Handle first page in case it's not aligned */ if (-realp & (PAGE_SIZE - 1)) sz = -realp & (PAGE_SIZE - 1); else sz = PAGE_SIZE; sz = min_t(unsigned long, sz, count); /* * On ia64 if a page has been mapped somewhere as * uncached, then it must also be accessed uncached * by the kernel or data corruption may occur */ ptr = xlate_dev_kmem_ptr(p); copied = copy_from_user(ptr, buf, sz); if (copied) { written += sz - copied; if (written) break; return -EFAULT; } buf += sz; p += sz; realp += sz; count -= sz; written += sz; } *ppos += written; return written; } /* * This function writes to the *virtual* memory as seen by the kernel. */ static ssize_t write_kmem(struct file * file, const char __user * buf, size_t count, loff_t *ppos) { unsigned long p = *ppos; ssize_t wrote = 0; ssize_t virtr = 0; ssize_t written; char * kbuf; /* k-addr because vwrite() takes vmlist_lock rwlock */ if (p < (unsigned long) high_memory) { wrote = count; if (count > (unsigned long) high_memory - p) wrote = (unsigned long) high_memory - p; written = do_write_kmem((void*)p, p, buf, wrote, ppos); if (written != wrote) return written; wrote = written; p += wrote; buf += wrote; count -= wrote; } if (count > 0) { kbuf = (char *)__get_free_page(GFP_KERNEL); if (!kbuf) return wrote ? wrote : -ENOMEM; while (count > 0) { int len = count; if (len > PAGE_SIZE) len = PAGE_SIZE; if (len) { written = copy_from_user(kbuf, buf, len); if (written) { if (wrote + virtr) break; free_page((unsigned long)kbuf); return -EFAULT; } } len = vwrite(kbuf, (char *)p, len); count -= len; buf += len; virtr += len; p += len; } free_page((unsigned long)kbuf); } *ppos = p; return virtr + wrote; } #ifdef CONFIG_DEVPORT static ssize_t read_port(struct file * file, char __user * buf, size_t count, loff_t *ppos) { unsigned long i = *ppos; char __user *tmp = buf; if (!access_ok(VERIFY_WRITE, buf, count)) return -EFAULT; while (count-- > 0 && i < 65536) { if (__put_user(inb(i),tmp) < 0) return -EFAULT; i++; tmp++; } *ppos = i; return tmp-buf; } static ssize_t write_port(struct file * file, const char __user * buf, size_t count, loff_t *ppos) { unsigned long i = *ppos; const char __user * tmp = buf; if (!access_ok(VERIFY_READ,buf,count)) return -EFAULT; while (count-- > 0 && i < 65536) { char c; if (__get_user(c, tmp)) { if (tmp > buf) break; return -EFAULT; } outb(c,i); i++; tmp++; } *ppos = i; return tmp-buf; } #endif static ssize_t read_null(struct file * file, char __user * buf, size_t count, loff_t *ppos) { return 0; } static ssize_t write_null(struct file * file, const char __user * buf, size_t count, loff_t *ppos) { return count; } static int pipe_to_null(struct pipe_inode_info *info, struct pipe_buffer *buf, struct splice_desc *sd) { return sd->len; } static ssize_t splice_write_null(struct pipe_inode_info *pipe,struct file *out, loff_t *ppos, size_t len, unsigned int flags) { return splice_from_pipe(pipe, out, ppos, len, flags, pipe_to_null); } static ssize_t read_zero(struct file * file, char __user * buf, size_t count, loff_t *ppos) { size_t written; if (!count) return 0; if (!access_ok(VERIFY_WRITE, buf, count)) return -EFAULT; written = 0; while (count) { unsigned long unwritten; size_t chunk = count; if (chunk > PAGE_SIZE) chunk = PAGE_SIZE; /* Just for latency reasons */ unwritten = clear_user(buf, chunk); written += chunk - unwritten; if (unwritten) break; buf += chunk; count -= chunk; cond_resched(); } return written ? written : -EFAULT; } static int mmap_zero(struct file * file, struct vm_area_struct * vma) { #ifndef CONFIG_MMU return -ENOSYS; #endif if (vma->vm_flags & VM_SHARED) return shmem_zero_setup(vma); return 0; } static ssize_t write_full(struct file * file, const char __user * buf, size_t count, loff_t *ppos) { return -ENOSPC; } /* * Special lseek() function for /dev/null and /dev/zero. Most notably, you * can fopen() both devices with "a" now. This was previously impossible. * -- SRB. */ static loff_t null_lseek(struct file * file, loff_t offset, int orig) { return file->f_pos = 0; } /* * The memory devices use the full 32/64 bits of the offset, and so we cannot * check against negative addresses: they are ok. The return value is weird, * though, in that case (0). * * also note that seeking relative to the "end of file" isn't supported: * it has no meaning, so it returns -EINVAL. */ static loff_t memory_lseek(struct file * file, loff_t offset, int orig) { loff_t ret; mutex_lock(&file->f_path.dentry->d_inode->i_mutex); switch (orig) { case 0: file->f_pos = offset; ret = file->f_pos; force_successful_syscall_return(); break; case 1: file->f_pos += offset; ret = file->f_pos; force_successful_syscall_return(); break; default: ret = -EINVAL; } mutex_unlock(&file->f_path.dentry->d_inode->i_mutex); return ret; } static int open_port(struct inode * inode, struct file * filp) { return capable(CAP_SYS_RAWIO) ? 0 : -EPERM; } #define zero_lseek null_lseek #define full_lseek null_lseek #define write_zero write_null #define read_full read_zero #define open_mem open_port #define open_kmem open_mem #define open_oldmem open_mem static const struct file_operations mem_fops = { .llseek = memory_lseek, .read = read_mem, .write = write_mem, .mmap = mmap_mem, .open = open_mem, .get_unmapped_area = get_unmapped_area_mem, }; static const struct file_operations kmem_fops = { .llseek = memory_lseek, .read = read_kmem, .write = write_kmem, .mmap = mmap_kmem, .open = open_kmem, .get_unmapped_area = get_unmapped_area_mem, }; static const struct file_operations null_fops = { .llseek = null_lseek, .read = read_null, .write = write_null, .splice_write = splice_write_null, }; #ifdef CONFIG_DEVPORT static const struct file_operations port_fops = { .llseek = memory_lseek, .read = read_port, .write = write_port, .open = open_port, }; #endif static const struct file_operations zero_fops = { .llseek = zero_lseek, .read = read_zero, .write = write_zero, .mmap = mmap_zero, }; /* * capabilities for /dev/zero * - permits private mappings, "copies" are taken of the source of zeros */ static struct backing_dev_info zero_bdi = { .capabilities = BDI_CAP_MAP_COPY, }; static const struct file_operations full_fops = { .llseek = full_lseek, .read = read_full, .write = write_full, }; #ifdef CONFIG_CRASH_DUMP static const struct file_operations oldmem_fops = { .read = read_oldmem, .open = open_oldmem, }; #endif static ssize_t kmsg_write(struct file * file, const char __user * buf, size_t count, loff_t *ppos) { char *tmp; ssize_t ret; tmp = kmalloc(count + 1, GFP_KERNEL); if (tmp == NULL) return -ENOMEM; ret = -EFAULT; if (!copy_from_user(tmp, buf, count)) { tmp[count] = 0; ret = printk("%s", tmp); if (ret > count) /* printk can add a prefix */ ret = count; } kfree(tmp); return ret; } static const struct file_operations kmsg_fops = { .write = kmsg_write, }; static int memory_open(struct inode * inode, struct file * filp) { switch (iminor(inode)) { case 1: filp->f_op = &mem_fops; filp->f_mapping->backing_dev_info = &directly_mappable_cdev_bdi; break; case 2: filp->f_op = &kmem_fops; filp->f_mapping->backing_dev_info = &directly_mappable_cdev_bdi; break; case 3: filp->f_op = &null_fops; break; #ifdef CONFIG_DEVPORT case 4: filp->f_op = &port_fops; break; #endif case 5: filp->f_mapping->backing_dev_info = &zero_bdi; filp->f_op = &zero_fops; break; case 7: filp->f_op = &full_fops; break; case 8: filp->f_op = &random_fops; break; case 9: filp->f_op = &urandom_fops; break; case 11: filp->f_op = &kmsg_fops; break; #ifdef CONFIG_CRASH_DUMP case 12: filp->f_op = &oldmem_fops; break; #endif default: return -ENXIO; } if (filp->f_op && filp->f_op->open) return filp->f_op->open(inode,filp); return 0; } static const struct file_operations memory_fops = { .open = memory_open, /* just a selector for the real open */ }; static const struct { unsigned int minor; char *name; umode_t mode; const struct file_operations *fops; } devlist[] = { /* list of minor devices */ {1, "mem", S_IRUSR | S_IWUSR | S_IRGRP, &mem_fops}, {2, "kmem", S_IRUSR | S_IWUSR | S_IRGRP, &kmem_fops}, {3, "null", S_IRUGO | S_IWUGO, &null_fops}, #ifdef CONFIG_DEVPORT {4, "port", S_IRUSR | S_IWUSR | S_IRGRP, &port_fops}, #endif {5, "zero", S_IRUGO | S_IWUGO, &zero_fops}, {7, "full", S_IRUGO | S_IWUGO, &full_fops}, {8, "random", S_IRUGO | S_IWUSR, &random_fops}, {9, "urandom", S_IRUGO | S_IWUSR, &urandom_fops}, {11,"kmsg", S_IRUGO | S_IWUSR, &kmsg_fops}, #ifdef CONFIG_CRASH_DUMP {12,"oldmem", S_IRUSR | S_IWUSR | S_IRGRP, &oldmem_fops}, #endif }; static struct class *mem_class; static int __init chr_dev_init(void) { int i; int err; err = bdi_init(&zero_bdi); if (err) return err; if (register_chrdev(MEM_MAJOR,"mem",&memory_fops)) printk("unable to get major %d for memory devs\n", MEM_MAJOR); mem_class = class_create(THIS_MODULE, "mem"); for (i = 0; i < ARRAY_SIZE(devlist); i++) device_create(mem_class, NULL, MKDEV(MEM_MAJOR, devlist[i].minor), devlist[i].name); return 0; } fs_initcall(chr_dev_init);
gpl-2.0
pastcompute/openwrt-cc-ar71xx-hardened
package/system/mtd/src/fis.c
529
5572
/* * FIS table updating code for mtd * * Copyright (C) 2009 Felix Fietkau <nbd@openwrt.org> * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License v2 * as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. */ #include <sys/mman.h> #include <stdint.h> #include <stdlib.h> #include <string.h> #include <unistd.h> #include <stdio.h> #include "crc32.h" #include "mtd.h" #include "fis.h" struct fis_image_hdr { unsigned char name[16]; uint32_t flash_base; uint32_t mem_base; uint32_t size; uint32_t entry_point; uint32_t data_length; } __attribute__((packed)); struct fis_image_crc { uint32_t desc; uint32_t file; } __attribute__((packed)); struct fis_image_desc { struct fis_image_hdr hdr; char _pad[256 - sizeof(struct fis_image_hdr) - sizeof(struct fis_image_crc)]; struct fis_image_crc crc; } __attribute__((packed)); static int fis_fd = -1; static struct fis_image_desc *fis_desc; static int fis_erasesize = 0; static void fis_close(void) { if (fis_desc) munmap(fis_desc, fis_erasesize); if (fis_fd >= 0) close(fis_fd); fis_fd = -1; fis_desc = NULL; } static struct fis_image_desc * fis_open(void) { struct fis_image_desc *desc; if (fis_fd >= 0) fis_close(); fis_fd = mtd_check_open("FIS directory"); if (fis_fd < 0) goto error; close(fis_fd); fis_fd = mtd_open("FIS directory", true); if (fis_fd < 0) goto error; fis_erasesize = erasesize; desc = mmap(NULL, erasesize, PROT_READ|PROT_WRITE, MAP_SHARED|MAP_LOCKED, fis_fd, 0); if (desc == MAP_FAILED) goto error; fis_desc = desc; return desc; error: fis_close(); return NULL; } int fis_validate(struct fis_part *old, int n_old, struct fis_part *new, int n_new) { struct fis_image_desc *desc; void *end; int found = 0; int i; desc = fis_open(); if (!desc) return -1; for (i = 0; i < n_new - 1; i++) { if (!new[i].size) { fprintf(stderr, "FIS error: only the last partition can detect the size automatically\n"); i = -1; goto done; } } end = desc; end = (char *) end + fis_erasesize; while ((void *) desc < end) { if (!desc->hdr.name[0] || (desc->hdr.name[0] == 0xff)) break; for (i = 0; i < n_old; i++) { if (!strncmp((char *) desc->hdr.name, (char *) old[i].name, sizeof(desc->hdr.name))) { found++; goto next; } } next: desc++; continue; } if (found == n_old) i = 1; else i = -1; done: fis_close(); return i; } int fis_remap(struct fis_part *old, int n_old, struct fis_part *new, int n_new) { struct fis_image_desc *fisdir = NULL; struct fis_image_desc *redboot = NULL; struct fis_image_desc *first = NULL; struct fis_image_desc *last = NULL; struct fis_image_desc *first_fb = NULL; struct fis_image_desc *last_fb = NULL; struct fis_image_desc *desc; struct fis_part *part; uint32_t offset = 0, size = 0; char *start, *end, *tmp; int i; desc = fis_open(); if (!desc) return -1; if (!quiet) fprintf(stderr, "Updating FIS table... \n"); start = (char *) desc; end = (char *) desc + fis_erasesize; while ((char *) desc < end) { if (!desc->hdr.name[0] || (desc->hdr.name[0] == 0xff)) break; if (!strcmp((char *) desc->hdr.name, "FIS directory")) fisdir = desc; if (!strcmp((char *) desc->hdr.name, "RedBoot")) redboot = desc; /* update max offset */ if (offset < desc->hdr.flash_base) offset = desc->hdr.flash_base; for (i = 0; i < n_old; i++) { if (!strncmp((char *) desc->hdr.name, (char *) old[i].name, sizeof(desc->hdr.name))) { last = desc; if (!first) first = desc; break; } } desc++; } desc--; first_fb = first; last_fb = last; if (first_fb->hdr.flash_base > last_fb->hdr.flash_base) { first_fb = last; last_fb = first; } /* determine size of available space */ desc = (struct fis_image_desc *) start; while ((char *) desc < end) { if (!desc->hdr.name[0] || (desc->hdr.name[0] == 0xff)) break; if (desc->hdr.flash_base > last_fb->hdr.flash_base && desc->hdr.flash_base < offset) offset = desc->hdr.flash_base; desc++; } desc--; size = offset - first_fb->hdr.flash_base; #ifdef notyet desc = first - 1; if (redboot && (desc >= redboot)) { if (first->hdr.flash_base - desc->hdr.size > desc->hdr.flash_base) { int delta = first->hdr.flash_base - desc->hdr.size - desc->hdr.flash_base; offset -= delta; size += delta; } } #endif last++; desc = first + n_new; offset = first_fb->hdr.flash_base; if (desc != last) { if (desc > last) tmp = (char *) desc; else tmp = (char *) last; memmove(desc, last, end - tmp); if (desc < last) { tmp = end - (last - desc) * sizeof(struct fis_image_desc); memset(tmp, 0xff, tmp - end); } } for (part = new, desc = first; desc < first + n_new; desc++, part++) { memset(desc, 0, sizeof(struct fis_image_desc)); memcpy(desc->hdr.name, part->name, sizeof(desc->hdr.name)); desc->crc.desc = 0; desc->crc.file = 0; desc->hdr.flash_base = offset; desc->hdr.mem_base = part->loadaddr; desc->hdr.entry_point = part->loadaddr; desc->hdr.size = (part->size > 0) ? part->size : size; desc->hdr.data_length = desc->hdr.size; offset += desc->hdr.size; size -= desc->hdr.size; } msync(fis_desc, fis_erasesize, MS_SYNC|MS_INVALIDATE); fis_close(); return 0; }
gpl-2.0
msdx321/android_kernel_samsung_G9350
drivers/pinctrl/mvebu/pinctrl-dove.c
529
28704
/* * Marvell Dove pinctrl driver based on mvebu pinctrl core * * Author: Sebastian Hesselbarth <sebastian.hesselbarth@gmail.com> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. */ #include <linux/err.h> #include <linux/init.h> #include <linux/io.h> #include <linux/module.h> #include <linux/bitops.h> #include <linux/platform_device.h> #include <linux/clk.h> #include <linux/of.h> #include <linux/of_device.h> #include <linux/mfd/syscon.h> #include <linux/pinctrl/pinctrl.h> #include <linux/regmap.h> #include "pinctrl-mvebu.h" /* Internal registers can be configured at any 1 MiB aligned address */ #define INT_REGS_MASK ~(SZ_1M - 1) #define MPP4_REGS_OFFS 0xd0440 #define PMU_REGS_OFFS 0xd802c #define GC_REGS_OFFS 0xe802c /* MPP Base registers */ #define PMU_MPP_GENERAL_CTRL 0x10 #define AU0_AC97_SEL BIT(16) /* MPP Control 4 register */ #define SPI_GPIO_SEL BIT(5) #define UART1_GPIO_SEL BIT(4) #define AU1_GPIO_SEL BIT(3) #define CAM_GPIO_SEL BIT(2) #define SD1_GPIO_SEL BIT(1) #define SD0_GPIO_SEL BIT(0) /* PMU Signal Select registers */ #define PMU_SIGNAL_SELECT_0 0x00 #define PMU_SIGNAL_SELECT_1 0x04 /* Global Config regmap registers */ #define GLOBAL_CONFIG_1 0x00 #define TWSI_ENABLE_OPTION1 BIT(7) #define GLOBAL_CONFIG_2 0x04 #define TWSI_ENABLE_OPTION2 BIT(20) #define TWSI_ENABLE_OPTION3 BIT(21) #define TWSI_OPTION3_GPIO BIT(22) #define SSP_CTRL_STATUS_1 0x08 #define SSP_ON_AU1 BIT(0) #define MPP_GENERAL_CONFIG 0x10 #define AU1_SPDIFO_GPIO_EN BIT(1) #define NAND_GPIO_EN BIT(0) #define CONFIG_PMU BIT(4) static void __iomem *mpp_base; static void __iomem *mpp4_base; static void __iomem *pmu_base; static struct regmap *gconfmap; static int dove_mpp_ctrl_get(unsigned pid, unsigned long *config) { return default_mpp_ctrl_get(mpp_base, pid, config); } static int dove_mpp_ctrl_set(unsigned pid, unsigned long config) { return default_mpp_ctrl_set(mpp_base, pid, config); } static int dove_pmu_mpp_ctrl_get(unsigned pid, unsigned long *config) { unsigned off = (pid / MVEBU_MPPS_PER_REG) * MVEBU_MPP_BITS; unsigned shift = (pid % MVEBU_MPPS_PER_REG) * MVEBU_MPP_BITS; unsigned long pmu = readl(mpp_base + PMU_MPP_GENERAL_CTRL); unsigned long func; if ((pmu & BIT(pid)) == 0) return default_mpp_ctrl_get(mpp_base, pid, config); func = readl(pmu_base + PMU_SIGNAL_SELECT_0 + off); *config = (func >> shift) & MVEBU_MPP_MASK; *config |= CONFIG_PMU; return 0; } static int dove_pmu_mpp_ctrl_set(unsigned pid, unsigned long config) { unsigned off = (pid / MVEBU_MPPS_PER_REG) * MVEBU_MPP_BITS; unsigned shift = (pid % MVEBU_MPPS_PER_REG) * MVEBU_MPP_BITS; unsigned long pmu = readl(mpp_base + PMU_MPP_GENERAL_CTRL); unsigned long func; if ((config & CONFIG_PMU) == 0) { writel(pmu & ~BIT(pid), mpp_base + PMU_MPP_GENERAL_CTRL); return default_mpp_ctrl_set(mpp_base, pid, config); } writel(pmu | BIT(pid), mpp_base + PMU_MPP_GENERAL_CTRL); func = readl(pmu_base + PMU_SIGNAL_SELECT_0 + off); func &= ~(MVEBU_MPP_MASK << shift); func |= (config & MVEBU_MPP_MASK) << shift; writel(func, pmu_base + PMU_SIGNAL_SELECT_0 + off); return 0; } static int dove_mpp4_ctrl_get(unsigned pid, unsigned long *config) { unsigned long mpp4 = readl(mpp4_base); unsigned long mask; switch (pid) { case 24: /* mpp_camera */ mask = CAM_GPIO_SEL; break; case 40: /* mpp_sdio0 */ mask = SD0_GPIO_SEL; break; case 46: /* mpp_sdio1 */ mask = SD1_GPIO_SEL; break; case 58: /* mpp_spi0 */ mask = SPI_GPIO_SEL; break; case 62: /* mpp_uart1 */ mask = UART1_GPIO_SEL; break; default: return -EINVAL; } *config = ((mpp4 & mask) != 0); return 0; } static int dove_mpp4_ctrl_set(unsigned pid, unsigned long config) { unsigned long mpp4 = readl(mpp4_base); unsigned long mask; switch (pid) { case 24: /* mpp_camera */ mask = CAM_GPIO_SEL; break; case 40: /* mpp_sdio0 */ mask = SD0_GPIO_SEL; break; case 46: /* mpp_sdio1 */ mask = SD1_GPIO_SEL; break; case 58: /* mpp_spi0 */ mask = SPI_GPIO_SEL; break; case 62: /* mpp_uart1 */ mask = UART1_GPIO_SEL; break; default: return -EINVAL; } mpp4 &= ~mask; if (config) mpp4 |= mask; writel(mpp4, mpp4_base); return 0; } static int dove_nand_ctrl_get(unsigned pid, unsigned long *config) { unsigned int gmpp; regmap_read(gconfmap, MPP_GENERAL_CONFIG, &gmpp); *config = ((gmpp & NAND_GPIO_EN) != 0); return 0; } static int dove_nand_ctrl_set(unsigned pid, unsigned long config) { regmap_update_bits(gconfmap, MPP_GENERAL_CONFIG, NAND_GPIO_EN, (config) ? NAND_GPIO_EN : 0); return 0; } static int dove_audio0_ctrl_get(unsigned pid, unsigned long *config) { unsigned long pmu = readl(mpp_base + PMU_MPP_GENERAL_CTRL); *config = ((pmu & AU0_AC97_SEL) != 0); return 0; } static int dove_audio0_ctrl_set(unsigned pid, unsigned long config) { unsigned long pmu = readl(mpp_base + PMU_MPP_GENERAL_CTRL); pmu &= ~AU0_AC97_SEL; if (config) pmu |= AU0_AC97_SEL; writel(pmu, mpp_base + PMU_MPP_GENERAL_CTRL); return 0; } static int dove_audio1_ctrl_get(unsigned pid, unsigned long *config) { unsigned int mpp4 = readl(mpp4_base); unsigned int sspc1; unsigned int gmpp; unsigned int gcfg2; regmap_read(gconfmap, SSP_CTRL_STATUS_1, &sspc1); regmap_read(gconfmap, MPP_GENERAL_CONFIG, &gmpp); regmap_read(gconfmap, GLOBAL_CONFIG_2, &gcfg2); *config = 0; if (mpp4 & AU1_GPIO_SEL) *config |= BIT(3); if (sspc1 & SSP_ON_AU1) *config |= BIT(2); if (gmpp & AU1_SPDIFO_GPIO_EN) *config |= BIT(1); if (gcfg2 & TWSI_OPTION3_GPIO) *config |= BIT(0); /* SSP/TWSI only if I2S1 not set*/ if ((*config & BIT(3)) == 0) *config &= ~(BIT(2) | BIT(0)); /* TWSI only if SPDIFO not set*/ if ((*config & BIT(1)) == 0) *config &= ~BIT(0); return 0; } static int dove_audio1_ctrl_set(unsigned pid, unsigned long config) { unsigned int mpp4 = readl(mpp4_base); mpp4 &= ~AU1_GPIO_SEL; if (config & BIT(3)) mpp4 |= AU1_GPIO_SEL; writel(mpp4, mpp4_base); regmap_update_bits(gconfmap, SSP_CTRL_STATUS_1, SSP_ON_AU1, (config & BIT(2)) ? SSP_ON_AU1 : 0); regmap_update_bits(gconfmap, MPP_GENERAL_CONFIG, AU1_SPDIFO_GPIO_EN, (config & BIT(1)) ? AU1_SPDIFO_GPIO_EN : 0); regmap_update_bits(gconfmap, GLOBAL_CONFIG_2, TWSI_OPTION3_GPIO, (config & BIT(0)) ? TWSI_OPTION3_GPIO : 0); return 0; } /* mpp[52:57] gpio pins depend heavily on current config; * gpio_req does not try to mux in gpio capabilities to not * break other functions. If you require all mpps as gpio * enforce gpio setting by pinctrl mapping. */ static int dove_audio1_ctrl_gpio_req(unsigned pid) { unsigned long config; dove_audio1_ctrl_get(pid, &config); switch (config) { case 0x02: /* i2s1 : gpio[56:57] */ case 0x0e: /* ssp : gpio[56:57] */ if (pid >= 56) return 0; return -ENOTSUPP; case 0x08: /* spdifo : gpio[52:55] */ case 0x0b: /* twsi : gpio[52:55] */ if (pid <= 55) return 0; return -ENOTSUPP; case 0x0a: /* all gpio */ return 0; /* 0x00 : i2s1/spdifo : no gpio */ /* 0x0c : ssp/spdifo : no gpio */ /* 0x0f : ssp/twsi : no gpio */ } return -ENOTSUPP; } /* mpp[52:57] has gpio pins capable of in and out */ static int dove_audio1_ctrl_gpio_dir(unsigned pid, bool input) { if (pid < 52 || pid > 57) return -ENOTSUPP; return 0; } static int dove_twsi_ctrl_get(unsigned pid, unsigned long *config) { unsigned int gcfg1; unsigned int gcfg2; regmap_read(gconfmap, GLOBAL_CONFIG_1, &gcfg1); regmap_read(gconfmap, GLOBAL_CONFIG_2, &gcfg2); *config = 0; if (gcfg1 & TWSI_ENABLE_OPTION1) *config = 1; else if (gcfg2 & TWSI_ENABLE_OPTION2) *config = 2; else if (gcfg2 & TWSI_ENABLE_OPTION3) *config = 3; return 0; } static int dove_twsi_ctrl_set(unsigned pid, unsigned long config) { unsigned int gcfg1 = 0; unsigned int gcfg2 = 0; switch (config) { case 1: gcfg1 = TWSI_ENABLE_OPTION1; break; case 2: gcfg2 = TWSI_ENABLE_OPTION2; break; case 3: gcfg2 = TWSI_ENABLE_OPTION3; break; } regmap_update_bits(gconfmap, GLOBAL_CONFIG_1, TWSI_ENABLE_OPTION1, gcfg1); regmap_update_bits(gconfmap, GLOBAL_CONFIG_2, TWSI_ENABLE_OPTION2 | TWSI_ENABLE_OPTION3, gcfg2); return 0; } static struct mvebu_mpp_ctrl dove_mpp_controls[] = { MPP_FUNC_CTRL(0, 15, NULL, dove_pmu_mpp_ctrl), MPP_FUNC_CTRL(16, 23, NULL, dove_mpp_ctrl), MPP_FUNC_CTRL(24, 39, "mpp_camera", dove_mpp4_ctrl), MPP_FUNC_CTRL(40, 45, "mpp_sdio0", dove_mpp4_ctrl), MPP_FUNC_CTRL(46, 51, "mpp_sdio1", dove_mpp4_ctrl), MPP_FUNC_GPIO_CTRL(52, 57, "mpp_audio1", dove_audio1_ctrl), MPP_FUNC_CTRL(58, 61, "mpp_spi0", dove_mpp4_ctrl), MPP_FUNC_CTRL(62, 63, "mpp_uart1", dove_mpp4_ctrl), MPP_FUNC_CTRL(64, 71, "mpp_nand", dove_nand_ctrl), MPP_FUNC_CTRL(72, 72, "audio0", dove_audio0_ctrl), MPP_FUNC_CTRL(73, 73, "twsi", dove_twsi_ctrl), }; static struct mvebu_mpp_mode dove_mpp_modes[] = { MPP_MODE(0, MPP_FUNCTION(0x00, "gpio", NULL), MPP_FUNCTION(0x02, "uart2", "rts"), MPP_FUNCTION(0x03, "sdio0", "cd"), MPP_FUNCTION(0x0f, "lcd0", "pwm"), MPP_FUNCTION(CONFIG_PMU | 0x0, "pmu-nc", NULL), MPP_FUNCTION(CONFIG_PMU | 0x1, "pmu-low", NULL), MPP_FUNCTION(CONFIG_PMU | 0x2, "pmu-high", NULL), MPP_FUNCTION(CONFIG_PMU | 0x3, "pmic", "sdi"), MPP_FUNCTION(CONFIG_PMU | 0x4, "cpu-pwr-down", NULL), MPP_FUNCTION(CONFIG_PMU | 0x5, "standby-pwr-down", NULL), MPP_FUNCTION(CONFIG_PMU | 0x8, "core-pwr-good", NULL), MPP_FUNCTION(CONFIG_PMU | 0xa, "bat-fault", NULL), MPP_FUNCTION(CONFIG_PMU | 0xb, "ext0-wakeup", NULL), MPP_FUNCTION(CONFIG_PMU | 0xc, "ext1-wakeup", NULL), MPP_FUNCTION(CONFIG_PMU | 0xd, "ext2-wakeup", NULL), MPP_FUNCTION(CONFIG_PMU | 0xe, "pmu-blink", NULL)), MPP_MODE(1, MPP_FUNCTION(0x00, "gpio", NULL), MPP_FUNCTION(0x02, "uart2", "cts"), MPP_FUNCTION(0x03, "sdio0", "wp"), MPP_FUNCTION(0x0f, "lcd1", "pwm"), MPP_FUNCTION(CONFIG_PMU | 0x0, "pmu-nc", NULL), MPP_FUNCTION(CONFIG_PMU | 0x1, "pmu-low", NULL), MPP_FUNCTION(CONFIG_PMU | 0x2, "pmu-high", NULL), MPP_FUNCTION(CONFIG_PMU | 0x3, "pmic", "sdi"), MPP_FUNCTION(CONFIG_PMU | 0x4, "cpu-pwr-down", NULL), MPP_FUNCTION(CONFIG_PMU | 0x5, "standby-pwr-down", NULL), MPP_FUNCTION(CONFIG_PMU | 0x8, "core-pwr-good", NULL), MPP_FUNCTION(CONFIG_PMU | 0xa, "bat-fault", NULL), MPP_FUNCTION(CONFIG_PMU | 0xb, "ext0-wakeup", NULL), MPP_FUNCTION(CONFIG_PMU | 0xc, "ext1-wakeup", NULL), MPP_FUNCTION(CONFIG_PMU | 0xd, "ext2-wakeup", NULL), MPP_FUNCTION(CONFIG_PMU | 0xe, "pmu-blink", NULL)), MPP_MODE(2, MPP_FUNCTION(0x00, "gpio", NULL), MPP_FUNCTION(0x01, "sata", "prsnt"), MPP_FUNCTION(0x02, "uart2", "txd"), MPP_FUNCTION(0x03, "sdio0", "buspwr"), MPP_FUNCTION(0x04, "uart1", "rts"), MPP_FUNCTION(CONFIG_PMU | 0x0, "pmu-nc", NULL), MPP_FUNCTION(CONFIG_PMU | 0x1, "pmu-low", NULL), MPP_FUNCTION(CONFIG_PMU | 0x2, "pmu-high", NULL), MPP_FUNCTION(CONFIG_PMU | 0x3, "pmic", "sdi"), MPP_FUNCTION(CONFIG_PMU | 0x4, "cpu-pwr-down", NULL), MPP_FUNCTION(CONFIG_PMU | 0x5, "standby-pwr-down", NULL), MPP_FUNCTION(CONFIG_PMU | 0x8, "core-pwr-good", NULL), MPP_FUNCTION(CONFIG_PMU | 0xa, "bat-fault", NULL), MPP_FUNCTION(CONFIG_PMU | 0xb, "ext0-wakeup", NULL), MPP_FUNCTION(CONFIG_PMU | 0xc, "ext1-wakeup", NULL), MPP_FUNCTION(CONFIG_PMU | 0xd, "ext2-wakeup", NULL), MPP_FUNCTION(CONFIG_PMU | 0xe, "pmu-blink", NULL)), MPP_MODE(3, MPP_FUNCTION(0x00, "gpio", NULL), MPP_FUNCTION(0x01, "sata", "act"), MPP_FUNCTION(0x02, "uart2", "rxd"), MPP_FUNCTION(0x03, "sdio0", "ledctrl"), MPP_FUNCTION(0x04, "uart1", "cts"), MPP_FUNCTION(0x0f, "lcd-spi", "cs1"), MPP_FUNCTION(CONFIG_PMU | 0x0, "pmu-nc", NULL), MPP_FUNCTION(CONFIG_PMU | 0x1, "pmu-low", NULL), MPP_FUNCTION(CONFIG_PMU | 0x2, "pmu-high", NULL), MPP_FUNCTION(CONFIG_PMU | 0x3, "pmic", "sdi"), MPP_FUNCTION(CONFIG_PMU | 0x4, "cpu-pwr-down", NULL), MPP_FUNCTION(CONFIG_PMU | 0x5, "standby-pwr-down", NULL), MPP_FUNCTION(CONFIG_PMU | 0x8, "core-pwr-good", NULL), MPP_FUNCTION(CONFIG_PMU | 0xa, "bat-fault", NULL), MPP_FUNCTION(CONFIG_PMU | 0xb, "ext0-wakeup", NULL), MPP_FUNCTION(CONFIG_PMU | 0xc, "ext1-wakeup", NULL), MPP_FUNCTION(CONFIG_PMU | 0xd, "ext2-wakeup", NULL), MPP_FUNCTION(CONFIG_PMU | 0xe, "pmu-blink", NULL)), MPP_MODE(4, MPP_FUNCTION(0x00, "gpio", NULL), MPP_FUNCTION(0x02, "uart3", "rts"), MPP_FUNCTION(0x03, "sdio1", "cd"), MPP_FUNCTION(0x04, "spi1", "miso"), MPP_FUNCTION(CONFIG_PMU | 0x0, "pmu-nc", NULL), MPP_FUNCTION(CONFIG_PMU | 0x1, "pmu-low", NULL), MPP_FUNCTION(CONFIG_PMU | 0x2, "pmu-high", NULL), MPP_FUNCTION(CONFIG_PMU | 0x3, "pmic", "sdi"), MPP_FUNCTION(CONFIG_PMU | 0x4, "cpu-pwr-down", NULL), MPP_FUNCTION(CONFIG_PMU | 0x5, "standby-pwr-down", NULL), MPP_FUNCTION(CONFIG_PMU | 0x8, "core-pwr-good", NULL), MPP_FUNCTION(CONFIG_PMU | 0xa, "bat-fault", NULL), MPP_FUNCTION(CONFIG_PMU | 0xb, "ext0-wakeup", NULL), MPP_FUNCTION(CONFIG_PMU | 0xc, "ext1-wakeup", NULL), MPP_FUNCTION(CONFIG_PMU | 0xd, "ext2-wakeup", NULL), MPP_FUNCTION(CONFIG_PMU | 0xe, "pmu-blink", NULL)), MPP_MODE(5, MPP_FUNCTION(0x00, "gpio", NULL), MPP_FUNCTION(0x02, "uart3", "cts"), MPP_FUNCTION(0x03, "sdio1", "wp"), MPP_FUNCTION(0x04, "spi1", "cs"), MPP_FUNCTION(CONFIG_PMU | 0x0, "pmu-nc", NULL), MPP_FUNCTION(CONFIG_PMU | 0x1, "pmu-low", NULL), MPP_FUNCTION(CONFIG_PMU | 0x2, "pmu-high", NULL), MPP_FUNCTION(CONFIG_PMU | 0x3, "pmic", "sdi"), MPP_FUNCTION(CONFIG_PMU | 0x4, "cpu-pwr-down", NULL), MPP_FUNCTION(CONFIG_PMU | 0x5, "standby-pwr-down", NULL), MPP_FUNCTION(CONFIG_PMU | 0x8, "core-pwr-good", NULL), MPP_FUNCTION(CONFIG_PMU | 0xa, "bat-fault", NULL), MPP_FUNCTION(CONFIG_PMU | 0xb, "ext0-wakeup", NULL), MPP_FUNCTION(CONFIG_PMU | 0xc, "ext1-wakeup", NULL), MPP_FUNCTION(CONFIG_PMU | 0xd, "ext2-wakeup", NULL), MPP_FUNCTION(CONFIG_PMU | 0xe, "pmu-blink", NULL)), MPP_MODE(6, MPP_FUNCTION(0x00, "gpio", NULL), MPP_FUNCTION(0x02, "uart3", "txd"), MPP_FUNCTION(0x03, "sdio1", "buspwr"), MPP_FUNCTION(0x04, "spi1", "mosi"), MPP_FUNCTION(CONFIG_PMU | 0x0, "pmu-nc", NULL), MPP_FUNCTION(CONFIG_PMU | 0x1, "pmu-low", NULL), MPP_FUNCTION(CONFIG_PMU | 0x2, "pmu-high", NULL), MPP_FUNCTION(CONFIG_PMU | 0x3, "pmic", "sdi"), MPP_FUNCTION(CONFIG_PMU | 0x4, "cpu-pwr-down", NULL), MPP_FUNCTION(CONFIG_PMU | 0x5, "standby-pwr-down", NULL), MPP_FUNCTION(CONFIG_PMU | 0x8, "core-pwr-good", NULL), MPP_FUNCTION(CONFIG_PMU | 0xa, "bat-fault", NULL), MPP_FUNCTION(CONFIG_PMU | 0xb, "ext0-wakeup", NULL), MPP_FUNCTION(CONFIG_PMU | 0xc, "ext1-wakeup", NULL), MPP_FUNCTION(CONFIG_PMU | 0xd, "ext2-wakeup", NULL), MPP_FUNCTION(CONFIG_PMU | 0xe, "pmu-blink", NULL)), MPP_MODE(7, MPP_FUNCTION(0x00, "gpio", NULL), MPP_FUNCTION(0x02, "uart3", "rxd"), MPP_FUNCTION(0x03, "sdio1", "ledctrl"), MPP_FUNCTION(0x04, "spi1", "sck"), MPP_FUNCTION(CONFIG_PMU | 0x0, "pmu-nc", NULL), MPP_FUNCTION(CONFIG_PMU | 0x1, "pmu-low", NULL), MPP_FUNCTION(CONFIG_PMU | 0x2, "pmu-high", NULL), MPP_FUNCTION(CONFIG_PMU | 0x3, "pmic", "sdi"), MPP_FUNCTION(CONFIG_PMU | 0x4, "cpu-pwr-down", NULL), MPP_FUNCTION(CONFIG_PMU | 0x5, "standby-pwr-down", NULL), MPP_FUNCTION(CONFIG_PMU | 0x8, "core-pwr-good", NULL), MPP_FUNCTION(CONFIG_PMU | 0xa, "bat-fault", NULL), MPP_FUNCTION(CONFIG_PMU | 0xb, "ext0-wakeup", NULL), MPP_FUNCTION(CONFIG_PMU | 0xc, "ext1-wakeup", NULL), MPP_FUNCTION(CONFIG_PMU | 0xd, "ext2-wakeup", NULL), MPP_FUNCTION(CONFIG_PMU | 0xe, "pmu-blink", NULL)), MPP_MODE(8, MPP_FUNCTION(0x00, "gpio", NULL), MPP_FUNCTION(0x01, "watchdog", "rstout"), MPP_FUNCTION(CONFIG_PMU | 0x0, "pmu-nc", NULL), MPP_FUNCTION(CONFIG_PMU | 0x1, "pmu-low", NULL), MPP_FUNCTION(CONFIG_PMU | 0x2, "pmu-high", NULL), MPP_FUNCTION(CONFIG_PMU | 0x3, "pmic", "sdi"), MPP_FUNCTION(CONFIG_PMU | 0x4, "cpu-pwr-down", NULL), MPP_FUNCTION(CONFIG_PMU | 0x5, "standby-pwr-down", NULL), MPP_FUNCTION(CONFIG_PMU | 0x8, "cpu-pwr-good", NULL), MPP_FUNCTION(CONFIG_PMU | 0xa, "bat-fault", NULL), MPP_FUNCTION(CONFIG_PMU | 0xb, "ext0-wakeup", NULL), MPP_FUNCTION(CONFIG_PMU | 0xc, "ext1-wakeup", NULL), MPP_FUNCTION(CONFIG_PMU | 0xd, "ext2-wakeup", NULL), MPP_FUNCTION(CONFIG_PMU | 0xe, "pmu-blink", NULL)), MPP_MODE(9, MPP_FUNCTION(0x00, "gpio", NULL), MPP_FUNCTION(0x05, "pex1", "clkreq"), MPP_FUNCTION(CONFIG_PMU | 0x0, "pmu-nc", NULL), MPP_FUNCTION(CONFIG_PMU | 0x1, "pmu-low", NULL), MPP_FUNCTION(CONFIG_PMU | 0x2, "pmu-high", NULL), MPP_FUNCTION(CONFIG_PMU | 0x3, "pmic", "sdi"), MPP_FUNCTION(CONFIG_PMU | 0x4, "cpu-pwr-down", NULL), MPP_FUNCTION(CONFIG_PMU | 0x5, "standby-pwr-down", NULL), MPP_FUNCTION(CONFIG_PMU | 0x8, "cpu-pwr-good", NULL), MPP_FUNCTION(CONFIG_PMU | 0xa, "bat-fault", NULL), MPP_FUNCTION(CONFIG_PMU | 0xb, "ext0-wakeup", NULL), MPP_FUNCTION(CONFIG_PMU | 0xc, "ext1-wakeup", NULL), MPP_FUNCTION(CONFIG_PMU | 0xd, "ext2-wakeup", NULL), MPP_FUNCTION(CONFIG_PMU | 0xe, "pmu-blink", NULL)), MPP_MODE(10, MPP_FUNCTION(0x00, "gpio", NULL), MPP_FUNCTION(0x05, "ssp", "sclk"), MPP_FUNCTION(CONFIG_PMU | 0x0, "pmu-nc", NULL), MPP_FUNCTION(CONFIG_PMU | 0x1, "pmu-low", NULL), MPP_FUNCTION(CONFIG_PMU | 0x2, "pmu-high", NULL), MPP_FUNCTION(CONFIG_PMU | 0x3, "pmic", "sdi"), MPP_FUNCTION(CONFIG_PMU | 0x4, "cpu-pwr-down", NULL), MPP_FUNCTION(CONFIG_PMU | 0x5, "standby-pwr-down", NULL), MPP_FUNCTION(CONFIG_PMU | 0x8, "cpu-pwr-good", NULL), MPP_FUNCTION(CONFIG_PMU | 0xa, "bat-fault", NULL), MPP_FUNCTION(CONFIG_PMU | 0xb, "ext0-wakeup", NULL), MPP_FUNCTION(CONFIG_PMU | 0xc, "ext1-wakeup", NULL), MPP_FUNCTION(CONFIG_PMU | 0xd, "ext2-wakeup", NULL), MPP_FUNCTION(CONFIG_PMU | 0xe, "pmu-blink", NULL)), MPP_MODE(11, MPP_FUNCTION(0x00, "gpio", NULL), MPP_FUNCTION(0x01, "sata", "prsnt"), MPP_FUNCTION(0x02, "sata-1", "act"), MPP_FUNCTION(0x03, "sdio0", "ledctrl"), MPP_FUNCTION(0x04, "sdio1", "ledctrl"), MPP_FUNCTION(0x05, "pex0", "clkreq"), MPP_FUNCTION(CONFIG_PMU | 0x0, "pmu-nc", NULL), MPP_FUNCTION(CONFIG_PMU | 0x1, "pmu-low", NULL), MPP_FUNCTION(CONFIG_PMU | 0x2, "pmu-high", NULL), MPP_FUNCTION(CONFIG_PMU | 0x3, "pmic", "sdi"), MPP_FUNCTION(CONFIG_PMU | 0x4, "cpu-pwr-down", NULL), MPP_FUNCTION(CONFIG_PMU | 0x5, "standby-pwr-down", NULL), MPP_FUNCTION(CONFIG_PMU | 0x8, "cpu-pwr-good", NULL), MPP_FUNCTION(CONFIG_PMU | 0xa, "bat-fault", NULL), MPP_FUNCTION(CONFIG_PMU | 0xb, "ext0-wakeup", NULL), MPP_FUNCTION(CONFIG_PMU | 0xc, "ext1-wakeup", NULL), MPP_FUNCTION(CONFIG_PMU | 0xd, "ext2-wakeup", NULL), MPP_FUNCTION(CONFIG_PMU | 0xe, "pmu-blink", NULL)), MPP_MODE(12, MPP_FUNCTION(0x00, "gpio", NULL), MPP_FUNCTION(0x01, "sata", "act"), MPP_FUNCTION(0x02, "uart2", "rts"), MPP_FUNCTION(0x03, "audio0", "extclk"), MPP_FUNCTION(0x04, "sdio1", "cd"), MPP_FUNCTION(CONFIG_PMU | 0x0, "pmu-nc", NULL), MPP_FUNCTION(CONFIG_PMU | 0x1, "pmu-low", NULL), MPP_FUNCTION(CONFIG_PMU | 0x2, "pmu-high", NULL), MPP_FUNCTION(CONFIG_PMU | 0x3, "pmic", "sdi"), MPP_FUNCTION(CONFIG_PMU | 0x4, "cpu-pwr-down", NULL), MPP_FUNCTION(CONFIG_PMU | 0x5, "standby-pwr-down", NULL), MPP_FUNCTION(CONFIG_PMU | 0x8, "cpu-pwr-good", NULL), MPP_FUNCTION(CONFIG_PMU | 0xa, "bat-fault", NULL), MPP_FUNCTION(CONFIG_PMU | 0xb, "ext0-wakeup", NULL), MPP_FUNCTION(CONFIG_PMU | 0xc, "ext1-wakeup", NULL), MPP_FUNCTION(CONFIG_PMU | 0xd, "ext2-wakeup", NULL), MPP_FUNCTION(CONFIG_PMU | 0xe, "pmu-blink", NULL)), MPP_MODE(13, MPP_FUNCTION(0x00, "gpio", NULL), MPP_FUNCTION(0x02, "uart2", "cts"), MPP_FUNCTION(0x03, "audio1", "extclk"), MPP_FUNCTION(0x04, "sdio1", "wp"), MPP_FUNCTION(0x05, "ssp", "extclk"), MPP_FUNCTION(CONFIG_PMU | 0x0, "pmu-nc", NULL), MPP_FUNCTION(CONFIG_PMU | 0x1, "pmu-low", NULL), MPP_FUNCTION(CONFIG_PMU | 0x2, "pmu-high", NULL), MPP_FUNCTION(CONFIG_PMU | 0x3, "pmic", "sdi"), MPP_FUNCTION(CONFIG_PMU | 0x4, "cpu-pwr-down", NULL), MPP_FUNCTION(CONFIG_PMU | 0x5, "standby-pwr-down", NULL), MPP_FUNCTION(CONFIG_PMU | 0x8, "cpu-pwr-good", NULL), MPP_FUNCTION(CONFIG_PMU | 0xa, "bat-fault", NULL), MPP_FUNCTION(CONFIG_PMU | 0xb, "ext0-wakeup", NULL), MPP_FUNCTION(CONFIG_PMU | 0xc, "ext1-wakeup", NULL), MPP_FUNCTION(CONFIG_PMU | 0xd, "ext2-wakeup", NULL), MPP_FUNCTION(CONFIG_PMU | 0xe, "pmu-blink", NULL)), MPP_MODE(14, MPP_FUNCTION(0x00, "gpio", NULL), MPP_FUNCTION(0x02, "uart2", "txd"), MPP_FUNCTION(0x04, "sdio1", "buspwr"), MPP_FUNCTION(0x05, "ssp", "rxd"), MPP_FUNCTION(CONFIG_PMU | 0x0, "pmu-nc", NULL), MPP_FUNCTION(CONFIG_PMU | 0x1, "pmu-low", NULL), MPP_FUNCTION(CONFIG_PMU | 0x2, "pmu-high", NULL), MPP_FUNCTION(CONFIG_PMU | 0x3, "pmic", "sdi"), MPP_FUNCTION(CONFIG_PMU | 0x4, "cpu-pwr-down", NULL), MPP_FUNCTION(CONFIG_PMU | 0x5, "standby-pwr-down", NULL), MPP_FUNCTION(CONFIG_PMU | 0x8, "cpu-pwr-good", NULL), MPP_FUNCTION(CONFIG_PMU | 0xa, "bat-fault", NULL), MPP_FUNCTION(CONFIG_PMU | 0xb, "ext0-wakeup", NULL), MPP_FUNCTION(CONFIG_PMU | 0xc, "ext1-wakeup", NULL), MPP_FUNCTION(CONFIG_PMU | 0xd, "ext2-wakeup", NULL), MPP_FUNCTION(CONFIG_PMU | 0xe, "pmu-blink", NULL)), MPP_MODE(15, MPP_FUNCTION(0x00, "gpio", NULL), MPP_FUNCTION(0x02, "uart2", "rxd"), MPP_FUNCTION(0x04, "sdio1", "ledctrl"), MPP_FUNCTION(0x05, "ssp", "sfrm"), MPP_FUNCTION(CONFIG_PMU | 0x0, "pmu-nc", NULL), MPP_FUNCTION(CONFIG_PMU | 0x1, "pmu-low", NULL), MPP_FUNCTION(CONFIG_PMU | 0x2, "pmu-high", NULL), MPP_FUNCTION(CONFIG_PMU | 0x3, "pmic", "sdi"), MPP_FUNCTION(CONFIG_PMU | 0x4, "cpu-pwr-down", NULL), MPP_FUNCTION(CONFIG_PMU | 0x5, "standby-pwr-down", NULL), MPP_FUNCTION(CONFIG_PMU | 0x8, "cpu-pwr-good", NULL), MPP_FUNCTION(CONFIG_PMU | 0xa, "bat-fault", NULL), MPP_FUNCTION(CONFIG_PMU | 0xb, "ext0-wakeup", NULL), MPP_FUNCTION(CONFIG_PMU | 0xc, "ext1-wakeup", NULL), MPP_FUNCTION(CONFIG_PMU | 0xd, "ext2-wakeup", NULL), MPP_FUNCTION(CONFIG_PMU | 0xe, "pmu-blink", NULL)), MPP_MODE(16, MPP_FUNCTION(0x00, "gpio", NULL), MPP_FUNCTION(0x02, "uart3", "rts"), MPP_FUNCTION(0x03, "sdio0", "cd"), MPP_FUNCTION(0x04, "lcd-spi", "cs1"), MPP_FUNCTION(0x05, "ac97", "sdi1")), MPP_MODE(17, MPP_FUNCTION(0x00, "gpio", NULL), MPP_FUNCTION(0x01, "ac97-1", "sysclko"), MPP_FUNCTION(0x02, "uart3", "cts"), MPP_FUNCTION(0x03, "sdio0", "wp"), MPP_FUNCTION(0x04, "twsi", "sda"), MPP_FUNCTION(0x05, "ac97", "sdi2")), MPP_MODE(18, MPP_FUNCTION(0x00, "gpio", NULL), MPP_FUNCTION(0x02, "uart3", "txd"), MPP_FUNCTION(0x03, "sdio0", "buspwr"), MPP_FUNCTION(0x04, "lcd0", "pwm"), MPP_FUNCTION(0x05, "ac97", "sdi3")), MPP_MODE(19, MPP_FUNCTION(0x00, "gpio", NULL), MPP_FUNCTION(0x02, "uart3", "rxd"), MPP_FUNCTION(0x03, "sdio0", "ledctrl"), MPP_FUNCTION(0x04, "twsi", "sck")), MPP_MODE(20, MPP_FUNCTION(0x00, "gpio", NULL), MPP_FUNCTION(0x01, "ac97", "sysclko"), MPP_FUNCTION(0x02, "lcd-spi", "miso"), MPP_FUNCTION(0x03, "sdio1", "cd"), MPP_FUNCTION(0x05, "sdio0", "cd"), MPP_FUNCTION(0x06, "spi1", "miso")), MPP_MODE(21, MPP_FUNCTION(0x00, "gpio", NULL), MPP_FUNCTION(0x01, "uart1", "rts"), MPP_FUNCTION(0x02, "lcd-spi", "cs0"), MPP_FUNCTION(0x03, "sdio1", "wp"), MPP_FUNCTION(0x04, "ssp", "sfrm"), MPP_FUNCTION(0x05, "sdio0", "wp"), MPP_FUNCTION(0x06, "spi1", "cs")), MPP_MODE(22, MPP_FUNCTION(0x00, "gpio", NULL), MPP_FUNCTION(0x01, "uart1", "cts"), MPP_FUNCTION(0x02, "lcd-spi", "mosi"), MPP_FUNCTION(0x03, "sdio1", "buspwr"), MPP_FUNCTION(0x04, "ssp", "txd"), MPP_FUNCTION(0x05, "sdio0", "buspwr"), MPP_FUNCTION(0x06, "spi1", "mosi")), MPP_MODE(23, MPP_FUNCTION(0x00, "gpio", NULL), MPP_FUNCTION(0x02, "lcd-spi", "sck"), MPP_FUNCTION(0x03, "sdio1", "ledctrl"), MPP_FUNCTION(0x04, "ssp", "sclk"), MPP_FUNCTION(0x05, "sdio0", "ledctrl"), MPP_FUNCTION(0x06, "spi1", "sck")), MPP_MODE(24, MPP_FUNCTION(0x00, "camera", NULL), MPP_FUNCTION(0x01, "gpio", NULL)), MPP_MODE(40, MPP_FUNCTION(0x00, "sdio0", NULL), MPP_FUNCTION(0x01, "gpio", NULL)), MPP_MODE(46, MPP_FUNCTION(0x00, "sdio1", NULL), MPP_FUNCTION(0x01, "gpio", NULL)), MPP_MODE(52, MPP_FUNCTION(0x00, "i2s1/spdifo", NULL), MPP_FUNCTION(0x02, "i2s1", NULL), MPP_FUNCTION(0x08, "spdifo", NULL), MPP_FUNCTION(0x0a, "gpio", NULL), MPP_FUNCTION(0x0b, "twsi", NULL), MPP_FUNCTION(0x0c, "ssp/spdifo", NULL), MPP_FUNCTION(0x0e, "ssp", NULL), MPP_FUNCTION(0x0f, "ssp/twsi", NULL)), MPP_MODE(58, MPP_FUNCTION(0x00, "spi0", NULL), MPP_FUNCTION(0x01, "gpio", NULL)), MPP_MODE(62, MPP_FUNCTION(0x00, "uart1", NULL), MPP_FUNCTION(0x01, "gpio", NULL)), MPP_MODE(64, MPP_FUNCTION(0x00, "nand", NULL), MPP_FUNCTION(0x01, "gpo", NULL)), MPP_MODE(72, MPP_FUNCTION(0x00, "i2s", NULL), MPP_FUNCTION(0x01, "ac97", NULL)), MPP_MODE(73, MPP_FUNCTION(0x00, "twsi-none", NULL), MPP_FUNCTION(0x01, "twsi-opt1", NULL), MPP_FUNCTION(0x02, "twsi-opt2", NULL), MPP_FUNCTION(0x03, "twsi-opt3", NULL)), }; static struct pinctrl_gpio_range dove_mpp_gpio_ranges[] = { MPP_GPIO_RANGE(0, 0, 0, 32), MPP_GPIO_RANGE(1, 32, 32, 32), MPP_GPIO_RANGE(2, 64, 64, 8), }; static struct mvebu_pinctrl_soc_info dove_pinctrl_info = { .controls = dove_mpp_controls, .ncontrols = ARRAY_SIZE(dove_mpp_controls), .modes = dove_mpp_modes, .nmodes = ARRAY_SIZE(dove_mpp_modes), .gpioranges = dove_mpp_gpio_ranges, .ngpioranges = ARRAY_SIZE(dove_mpp_gpio_ranges), .variant = 0, }; static struct clk *clk; static struct of_device_id dove_pinctrl_of_match[] = { { .compatible = "marvell,dove-pinctrl", .data = &dove_pinctrl_info }, { } }; static struct regmap_config gc_regmap_config = { .reg_bits = 32, .val_bits = 32, .reg_stride = 4, .max_register = 5, }; static int dove_pinctrl_probe(struct platform_device *pdev) { struct resource *res, *mpp_res; struct resource fb_res; const struct of_device_id *match = of_match_device(dove_pinctrl_of_match, &pdev->dev); pdev->dev.platform_data = (void *)match->data; /* * General MPP Configuration Register is part of pdma registers. * grab clk to make sure it is ticking. */ clk = devm_clk_get(&pdev->dev, NULL); if (IS_ERR(clk)) { dev_err(&pdev->dev, "Unable to get pdma clock"); return PTR_ERR(clk); } clk_prepare_enable(clk); mpp_res = platform_get_resource(pdev, IORESOURCE_MEM, 0); mpp_base = devm_ioremap_resource(&pdev->dev, mpp_res); if (IS_ERR(mpp_base)) return PTR_ERR(mpp_base); /* prepare fallback resource */ memcpy(&fb_res, mpp_res, sizeof(struct resource)); fb_res.start = 0; res = platform_get_resource(pdev, IORESOURCE_MEM, 1); if (!res) { dev_warn(&pdev->dev, "falling back to hardcoded MPP4 resource\n"); adjust_resource(&fb_res, (mpp_res->start & INT_REGS_MASK) + MPP4_REGS_OFFS, 0x4); res = &fb_res; } mpp4_base = devm_ioremap_resource(&pdev->dev, res); if (IS_ERR(mpp4_base)) return PTR_ERR(mpp4_base); res = platform_get_resource(pdev, IORESOURCE_MEM, 2); if (!res) { dev_warn(&pdev->dev, "falling back to hardcoded PMU resource\n"); adjust_resource(&fb_res, (mpp_res->start & INT_REGS_MASK) + PMU_REGS_OFFS, 0x8); res = &fb_res; } pmu_base = devm_ioremap_resource(&pdev->dev, res); if (IS_ERR(pmu_base)) return PTR_ERR(pmu_base); gconfmap = syscon_regmap_lookup_by_compatible("marvell,dove-global-config"); if (IS_ERR(gconfmap)) { void __iomem *gc_base; dev_warn(&pdev->dev, "falling back to hardcoded global registers\n"); adjust_resource(&fb_res, (mpp_res->start & INT_REGS_MASK) + GC_REGS_OFFS, 0x14); gc_base = devm_ioremap_resource(&pdev->dev, &fb_res); if (IS_ERR(gc_base)) return PTR_ERR(gc_base); gconfmap = devm_regmap_init_mmio(&pdev->dev, gc_base, &gc_regmap_config); if (IS_ERR(gconfmap)) return PTR_ERR(gconfmap); } /* Warn on any missing DT resource */ if (fb_res.start) dev_warn(&pdev->dev, FW_BUG "Missing pinctrl regs in DTB. Please update your firmware.\n"); return mvebu_pinctrl_probe(pdev); } static int dove_pinctrl_remove(struct platform_device *pdev) { int ret; ret = mvebu_pinctrl_remove(pdev); if (!IS_ERR(clk)) clk_disable_unprepare(clk); return ret; } static struct platform_driver dove_pinctrl_driver = { .driver = { .name = "dove-pinctrl", .owner = THIS_MODULE, .of_match_table = dove_pinctrl_of_match, }, .probe = dove_pinctrl_probe, .remove = dove_pinctrl_remove, }; module_platform_driver(dove_pinctrl_driver); MODULE_AUTHOR("Sebastian Hesselbarth <sebastian.hesselbarth@gmail.com>"); MODULE_DESCRIPTION("Marvell Dove pinctrl driver"); MODULE_LICENSE("GPL v2");
gpl-2.0
masmullin2000/kernel_tp_ts_bkl
drivers/net/ethernet/intel/ixgb/ixgb_ethtool.c
1297
20416
/******************************************************************************* Intel PRO/10GbE Linux driver Copyright(c) 1999 - 2008 Intel Corporation. This program is free software; you can redistribute it and/or modify it under the terms and conditions of the GNU General Public License, version 2, as published by the Free Software Foundation. This program is distributed in the hope it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. The full GNU General Public License is included in this distribution in the file called "COPYING". Contact Information: Linux NICS <linux.nics@intel.com> e1000-devel Mailing List <e1000-devel@lists.sourceforge.net> Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 *******************************************************************************/ /* ethtool support for ixgb */ #include "ixgb.h" #include <asm/uaccess.h> #define IXGB_ALL_RAR_ENTRIES 16 enum {NETDEV_STATS, IXGB_STATS}; struct ixgb_stats { char stat_string[ETH_GSTRING_LEN]; int type; int sizeof_stat; int stat_offset; }; #define IXGB_STAT(m) IXGB_STATS, \ FIELD_SIZEOF(struct ixgb_adapter, m), \ offsetof(struct ixgb_adapter, m) #define IXGB_NETDEV_STAT(m) NETDEV_STATS, \ FIELD_SIZEOF(struct net_device, m), \ offsetof(struct net_device, m) static struct ixgb_stats ixgb_gstrings_stats[] = { {"rx_packets", IXGB_NETDEV_STAT(stats.rx_packets)}, {"tx_packets", IXGB_NETDEV_STAT(stats.tx_packets)}, {"rx_bytes", IXGB_NETDEV_STAT(stats.rx_bytes)}, {"tx_bytes", IXGB_NETDEV_STAT(stats.tx_bytes)}, {"rx_errors", IXGB_NETDEV_STAT(stats.rx_errors)}, {"tx_errors", IXGB_NETDEV_STAT(stats.tx_errors)}, {"rx_dropped", IXGB_NETDEV_STAT(stats.rx_dropped)}, {"tx_dropped", IXGB_NETDEV_STAT(stats.tx_dropped)}, {"multicast", IXGB_NETDEV_STAT(stats.multicast)}, {"collisions", IXGB_NETDEV_STAT(stats.collisions)}, /* { "rx_length_errors", IXGB_NETDEV_STAT(stats.rx_length_errors) }, */ {"rx_over_errors", IXGB_NETDEV_STAT(stats.rx_over_errors)}, {"rx_crc_errors", IXGB_NETDEV_STAT(stats.rx_crc_errors)}, {"rx_frame_errors", IXGB_NETDEV_STAT(stats.rx_frame_errors)}, {"rx_no_buffer_count", IXGB_STAT(stats.rnbc)}, {"rx_fifo_errors", IXGB_NETDEV_STAT(stats.rx_fifo_errors)}, {"rx_missed_errors", IXGB_NETDEV_STAT(stats.rx_missed_errors)}, {"tx_aborted_errors", IXGB_NETDEV_STAT(stats.tx_aborted_errors)}, {"tx_carrier_errors", IXGB_NETDEV_STAT(stats.tx_carrier_errors)}, {"tx_fifo_errors", IXGB_NETDEV_STAT(stats.tx_fifo_errors)}, {"tx_heartbeat_errors", IXGB_NETDEV_STAT(stats.tx_heartbeat_errors)}, {"tx_window_errors", IXGB_NETDEV_STAT(stats.tx_window_errors)}, {"tx_deferred_ok", IXGB_STAT(stats.dc)}, {"tx_timeout_count", IXGB_STAT(tx_timeout_count) }, {"tx_restart_queue", IXGB_STAT(restart_queue) }, {"rx_long_length_errors", IXGB_STAT(stats.roc)}, {"rx_short_length_errors", IXGB_STAT(stats.ruc)}, {"tx_tcp_seg_good", IXGB_STAT(stats.tsctc)}, {"tx_tcp_seg_failed", IXGB_STAT(stats.tsctfc)}, {"rx_flow_control_xon", IXGB_STAT(stats.xonrxc)}, {"rx_flow_control_xoff", IXGB_STAT(stats.xoffrxc)}, {"tx_flow_control_xon", IXGB_STAT(stats.xontxc)}, {"tx_flow_control_xoff", IXGB_STAT(stats.xofftxc)}, {"rx_csum_offload_good", IXGB_STAT(hw_csum_rx_good)}, {"rx_csum_offload_errors", IXGB_STAT(hw_csum_rx_error)}, {"tx_csum_offload_good", IXGB_STAT(hw_csum_tx_good)}, {"tx_csum_offload_errors", IXGB_STAT(hw_csum_tx_error)} }; #define IXGB_STATS_LEN ARRAY_SIZE(ixgb_gstrings_stats) static int ixgb_get_settings(struct net_device *netdev, struct ethtool_cmd *ecmd) { struct ixgb_adapter *adapter = netdev_priv(netdev); ecmd->supported = (SUPPORTED_10000baseT_Full | SUPPORTED_FIBRE); ecmd->advertising = (ADVERTISED_10000baseT_Full | ADVERTISED_FIBRE); ecmd->port = PORT_FIBRE; ecmd->transceiver = XCVR_EXTERNAL; if (netif_carrier_ok(adapter->netdev)) { ethtool_cmd_speed_set(ecmd, SPEED_10000); ecmd->duplex = DUPLEX_FULL; } else { ethtool_cmd_speed_set(ecmd, SPEED_UNKNOWN); ecmd->duplex = DUPLEX_UNKNOWN; } ecmd->autoneg = AUTONEG_DISABLE; return 0; } void ixgb_set_speed_duplex(struct net_device *netdev) { struct ixgb_adapter *adapter = netdev_priv(netdev); /* be optimistic about our link, since we were up before */ adapter->link_speed = 10000; adapter->link_duplex = FULL_DUPLEX; netif_carrier_on(netdev); netif_wake_queue(netdev); } static int ixgb_set_settings(struct net_device *netdev, struct ethtool_cmd *ecmd) { struct ixgb_adapter *adapter = netdev_priv(netdev); u32 speed = ethtool_cmd_speed(ecmd); if (ecmd->autoneg == AUTONEG_ENABLE || (speed + ecmd->duplex != SPEED_10000 + DUPLEX_FULL)) return -EINVAL; if (netif_running(adapter->netdev)) { ixgb_down(adapter, true); ixgb_reset(adapter); ixgb_up(adapter); ixgb_set_speed_duplex(netdev); } else ixgb_reset(adapter); return 0; } static void ixgb_get_pauseparam(struct net_device *netdev, struct ethtool_pauseparam *pause) { struct ixgb_adapter *adapter = netdev_priv(netdev); struct ixgb_hw *hw = &adapter->hw; pause->autoneg = AUTONEG_DISABLE; if (hw->fc.type == ixgb_fc_rx_pause) pause->rx_pause = 1; else if (hw->fc.type == ixgb_fc_tx_pause) pause->tx_pause = 1; else if (hw->fc.type == ixgb_fc_full) { pause->rx_pause = 1; pause->tx_pause = 1; } } static int ixgb_set_pauseparam(struct net_device *netdev, struct ethtool_pauseparam *pause) { struct ixgb_adapter *adapter = netdev_priv(netdev); struct ixgb_hw *hw = &adapter->hw; if (pause->autoneg == AUTONEG_ENABLE) return -EINVAL; if (pause->rx_pause && pause->tx_pause) hw->fc.type = ixgb_fc_full; else if (pause->rx_pause && !pause->tx_pause) hw->fc.type = ixgb_fc_rx_pause; else if (!pause->rx_pause && pause->tx_pause) hw->fc.type = ixgb_fc_tx_pause; else if (!pause->rx_pause && !pause->tx_pause) hw->fc.type = ixgb_fc_none; if (netif_running(adapter->netdev)) { ixgb_down(adapter, true); ixgb_up(adapter); ixgb_set_speed_duplex(netdev); } else ixgb_reset(adapter); return 0; } static u32 ixgb_get_msglevel(struct net_device *netdev) { struct ixgb_adapter *adapter = netdev_priv(netdev); return adapter->msg_enable; } static void ixgb_set_msglevel(struct net_device *netdev, u32 data) { struct ixgb_adapter *adapter = netdev_priv(netdev); adapter->msg_enable = data; } #define IXGB_GET_STAT(_A_, _R_) _A_->stats._R_ static int ixgb_get_regs_len(struct net_device *netdev) { #define IXGB_REG_DUMP_LEN 136*sizeof(u32) return IXGB_REG_DUMP_LEN; } static void ixgb_get_regs(struct net_device *netdev, struct ethtool_regs *regs, void *p) { struct ixgb_adapter *adapter = netdev_priv(netdev); struct ixgb_hw *hw = &adapter->hw; u32 *reg = p; u32 *reg_start = reg; u8 i; /* the 1 (one) below indicates an attempt at versioning, if the * interface in ethtool or the driver changes, this 1 should be * incremented */ regs->version = (1<<24) | hw->revision_id << 16 | hw->device_id; /* General Registers */ *reg++ = IXGB_READ_REG(hw, CTRL0); /* 0 */ *reg++ = IXGB_READ_REG(hw, CTRL1); /* 1 */ *reg++ = IXGB_READ_REG(hw, STATUS); /* 2 */ *reg++ = IXGB_READ_REG(hw, EECD); /* 3 */ *reg++ = IXGB_READ_REG(hw, MFS); /* 4 */ /* Interrupt */ *reg++ = IXGB_READ_REG(hw, ICR); /* 5 */ *reg++ = IXGB_READ_REG(hw, ICS); /* 6 */ *reg++ = IXGB_READ_REG(hw, IMS); /* 7 */ *reg++ = IXGB_READ_REG(hw, IMC); /* 8 */ /* Receive */ *reg++ = IXGB_READ_REG(hw, RCTL); /* 9 */ *reg++ = IXGB_READ_REG(hw, FCRTL); /* 10 */ *reg++ = IXGB_READ_REG(hw, FCRTH); /* 11 */ *reg++ = IXGB_READ_REG(hw, RDBAL); /* 12 */ *reg++ = IXGB_READ_REG(hw, RDBAH); /* 13 */ *reg++ = IXGB_READ_REG(hw, RDLEN); /* 14 */ *reg++ = IXGB_READ_REG(hw, RDH); /* 15 */ *reg++ = IXGB_READ_REG(hw, RDT); /* 16 */ *reg++ = IXGB_READ_REG(hw, RDTR); /* 17 */ *reg++ = IXGB_READ_REG(hw, RXDCTL); /* 18 */ *reg++ = IXGB_READ_REG(hw, RAIDC); /* 19 */ *reg++ = IXGB_READ_REG(hw, RXCSUM); /* 20 */ /* there are 16 RAR entries in hardware, we only use 3 */ for (i = 0; i < IXGB_ALL_RAR_ENTRIES; i++) { *reg++ = IXGB_READ_REG_ARRAY(hw, RAL, (i << 1)); /*21,...,51 */ *reg++ = IXGB_READ_REG_ARRAY(hw, RAH, (i << 1)); /*22,...,52 */ } /* Transmit */ *reg++ = IXGB_READ_REG(hw, TCTL); /* 53 */ *reg++ = IXGB_READ_REG(hw, TDBAL); /* 54 */ *reg++ = IXGB_READ_REG(hw, TDBAH); /* 55 */ *reg++ = IXGB_READ_REG(hw, TDLEN); /* 56 */ *reg++ = IXGB_READ_REG(hw, TDH); /* 57 */ *reg++ = IXGB_READ_REG(hw, TDT); /* 58 */ *reg++ = IXGB_READ_REG(hw, TIDV); /* 59 */ *reg++ = IXGB_READ_REG(hw, TXDCTL); /* 60 */ *reg++ = IXGB_READ_REG(hw, TSPMT); /* 61 */ *reg++ = IXGB_READ_REG(hw, PAP); /* 62 */ /* Physical */ *reg++ = IXGB_READ_REG(hw, PCSC1); /* 63 */ *reg++ = IXGB_READ_REG(hw, PCSC2); /* 64 */ *reg++ = IXGB_READ_REG(hw, PCSS1); /* 65 */ *reg++ = IXGB_READ_REG(hw, PCSS2); /* 66 */ *reg++ = IXGB_READ_REG(hw, XPCSS); /* 67 */ *reg++ = IXGB_READ_REG(hw, UCCR); /* 68 */ *reg++ = IXGB_READ_REG(hw, XPCSTC); /* 69 */ *reg++ = IXGB_READ_REG(hw, MACA); /* 70 */ *reg++ = IXGB_READ_REG(hw, APAE); /* 71 */ *reg++ = IXGB_READ_REG(hw, ARD); /* 72 */ *reg++ = IXGB_READ_REG(hw, AIS); /* 73 */ *reg++ = IXGB_READ_REG(hw, MSCA); /* 74 */ *reg++ = IXGB_READ_REG(hw, MSRWD); /* 75 */ /* Statistics */ *reg++ = IXGB_GET_STAT(adapter, tprl); /* 76 */ *reg++ = IXGB_GET_STAT(adapter, tprh); /* 77 */ *reg++ = IXGB_GET_STAT(adapter, gprcl); /* 78 */ *reg++ = IXGB_GET_STAT(adapter, gprch); /* 79 */ *reg++ = IXGB_GET_STAT(adapter, bprcl); /* 80 */ *reg++ = IXGB_GET_STAT(adapter, bprch); /* 81 */ *reg++ = IXGB_GET_STAT(adapter, mprcl); /* 82 */ *reg++ = IXGB_GET_STAT(adapter, mprch); /* 83 */ *reg++ = IXGB_GET_STAT(adapter, uprcl); /* 84 */ *reg++ = IXGB_GET_STAT(adapter, uprch); /* 85 */ *reg++ = IXGB_GET_STAT(adapter, vprcl); /* 86 */ *reg++ = IXGB_GET_STAT(adapter, vprch); /* 87 */ *reg++ = IXGB_GET_STAT(adapter, jprcl); /* 88 */ *reg++ = IXGB_GET_STAT(adapter, jprch); /* 89 */ *reg++ = IXGB_GET_STAT(adapter, gorcl); /* 90 */ *reg++ = IXGB_GET_STAT(adapter, gorch); /* 91 */ *reg++ = IXGB_GET_STAT(adapter, torl); /* 92 */ *reg++ = IXGB_GET_STAT(adapter, torh); /* 93 */ *reg++ = IXGB_GET_STAT(adapter, rnbc); /* 94 */ *reg++ = IXGB_GET_STAT(adapter, ruc); /* 95 */ *reg++ = IXGB_GET_STAT(adapter, roc); /* 96 */ *reg++ = IXGB_GET_STAT(adapter, rlec); /* 97 */ *reg++ = IXGB_GET_STAT(adapter, crcerrs); /* 98 */ *reg++ = IXGB_GET_STAT(adapter, icbc); /* 99 */ *reg++ = IXGB_GET_STAT(adapter, ecbc); /* 100 */ *reg++ = IXGB_GET_STAT(adapter, mpc); /* 101 */ *reg++ = IXGB_GET_STAT(adapter, tptl); /* 102 */ *reg++ = IXGB_GET_STAT(adapter, tpth); /* 103 */ *reg++ = IXGB_GET_STAT(adapter, gptcl); /* 104 */ *reg++ = IXGB_GET_STAT(adapter, gptch); /* 105 */ *reg++ = IXGB_GET_STAT(adapter, bptcl); /* 106 */ *reg++ = IXGB_GET_STAT(adapter, bptch); /* 107 */ *reg++ = IXGB_GET_STAT(adapter, mptcl); /* 108 */ *reg++ = IXGB_GET_STAT(adapter, mptch); /* 109 */ *reg++ = IXGB_GET_STAT(adapter, uptcl); /* 110 */ *reg++ = IXGB_GET_STAT(adapter, uptch); /* 111 */ *reg++ = IXGB_GET_STAT(adapter, vptcl); /* 112 */ *reg++ = IXGB_GET_STAT(adapter, vptch); /* 113 */ *reg++ = IXGB_GET_STAT(adapter, jptcl); /* 114 */ *reg++ = IXGB_GET_STAT(adapter, jptch); /* 115 */ *reg++ = IXGB_GET_STAT(adapter, gotcl); /* 116 */ *reg++ = IXGB_GET_STAT(adapter, gotch); /* 117 */ *reg++ = IXGB_GET_STAT(adapter, totl); /* 118 */ *reg++ = IXGB_GET_STAT(adapter, toth); /* 119 */ *reg++ = IXGB_GET_STAT(adapter, dc); /* 120 */ *reg++ = IXGB_GET_STAT(adapter, plt64c); /* 121 */ *reg++ = IXGB_GET_STAT(adapter, tsctc); /* 122 */ *reg++ = IXGB_GET_STAT(adapter, tsctfc); /* 123 */ *reg++ = IXGB_GET_STAT(adapter, ibic); /* 124 */ *reg++ = IXGB_GET_STAT(adapter, rfc); /* 125 */ *reg++ = IXGB_GET_STAT(adapter, lfc); /* 126 */ *reg++ = IXGB_GET_STAT(adapter, pfrc); /* 127 */ *reg++ = IXGB_GET_STAT(adapter, pftc); /* 128 */ *reg++ = IXGB_GET_STAT(adapter, mcfrc); /* 129 */ *reg++ = IXGB_GET_STAT(adapter, mcftc); /* 130 */ *reg++ = IXGB_GET_STAT(adapter, xonrxc); /* 131 */ *reg++ = IXGB_GET_STAT(adapter, xontxc); /* 132 */ *reg++ = IXGB_GET_STAT(adapter, xoffrxc); /* 133 */ *reg++ = IXGB_GET_STAT(adapter, xofftxc); /* 134 */ *reg++ = IXGB_GET_STAT(adapter, rjc); /* 135 */ regs->len = (reg - reg_start) * sizeof(u32); } static int ixgb_get_eeprom_len(struct net_device *netdev) { /* return size in bytes */ return IXGB_EEPROM_SIZE << 1; } static int ixgb_get_eeprom(struct net_device *netdev, struct ethtool_eeprom *eeprom, u8 *bytes) { struct ixgb_adapter *adapter = netdev_priv(netdev); struct ixgb_hw *hw = &adapter->hw; __le16 *eeprom_buff; int i, max_len, first_word, last_word; int ret_val = 0; if (eeprom->len == 0) { ret_val = -EINVAL; goto geeprom_error; } eeprom->magic = hw->vendor_id | (hw->device_id << 16); max_len = ixgb_get_eeprom_len(netdev); if (eeprom->offset > eeprom->offset + eeprom->len) { ret_val = -EINVAL; goto geeprom_error; } if ((eeprom->offset + eeprom->len) > max_len) eeprom->len = (max_len - eeprom->offset); first_word = eeprom->offset >> 1; last_word = (eeprom->offset + eeprom->len - 1) >> 1; eeprom_buff = kmalloc(sizeof(__le16) * (last_word - first_word + 1), GFP_KERNEL); if (!eeprom_buff) return -ENOMEM; /* note the eeprom was good because the driver loaded */ for (i = 0; i <= (last_word - first_word); i++) eeprom_buff[i] = ixgb_get_eeprom_word(hw, (first_word + i)); memcpy(bytes, (u8 *)eeprom_buff + (eeprom->offset & 1), eeprom->len); kfree(eeprom_buff); geeprom_error: return ret_val; } static int ixgb_set_eeprom(struct net_device *netdev, struct ethtool_eeprom *eeprom, u8 *bytes) { struct ixgb_adapter *adapter = netdev_priv(netdev); struct ixgb_hw *hw = &adapter->hw; u16 *eeprom_buff; void *ptr; int max_len, first_word, last_word; u16 i; if (eeprom->len == 0) return -EINVAL; if (eeprom->magic != (hw->vendor_id | (hw->device_id << 16))) return -EFAULT; max_len = ixgb_get_eeprom_len(netdev); if (eeprom->offset > eeprom->offset + eeprom->len) return -EINVAL; if ((eeprom->offset + eeprom->len) > max_len) eeprom->len = (max_len - eeprom->offset); first_word = eeprom->offset >> 1; last_word = (eeprom->offset + eeprom->len - 1) >> 1; eeprom_buff = kmalloc(max_len, GFP_KERNEL); if (!eeprom_buff) return -ENOMEM; ptr = (void *)eeprom_buff; if (eeprom->offset & 1) { /* need read/modify/write of first changed EEPROM word */ /* only the second byte of the word is being modified */ eeprom_buff[0] = ixgb_read_eeprom(hw, first_word); ptr++; } if ((eeprom->offset + eeprom->len) & 1) { /* need read/modify/write of last changed EEPROM word */ /* only the first byte of the word is being modified */ eeprom_buff[last_word - first_word] = ixgb_read_eeprom(hw, last_word); } memcpy(ptr, bytes, eeprom->len); for (i = 0; i <= (last_word - first_word); i++) ixgb_write_eeprom(hw, first_word + i, eeprom_buff[i]); /* Update the checksum over the first part of the EEPROM if needed */ if (first_word <= EEPROM_CHECKSUM_REG) ixgb_update_eeprom_checksum(hw); kfree(eeprom_buff); return 0; } static void ixgb_get_drvinfo(struct net_device *netdev, struct ethtool_drvinfo *drvinfo) { struct ixgb_adapter *adapter = netdev_priv(netdev); strlcpy(drvinfo->driver, ixgb_driver_name, sizeof(drvinfo->driver)); strlcpy(drvinfo->version, ixgb_driver_version, sizeof(drvinfo->version)); strlcpy(drvinfo->bus_info, pci_name(adapter->pdev), sizeof(drvinfo->bus_info)); drvinfo->n_stats = IXGB_STATS_LEN; drvinfo->regdump_len = ixgb_get_regs_len(netdev); drvinfo->eedump_len = ixgb_get_eeprom_len(netdev); } static void ixgb_get_ringparam(struct net_device *netdev, struct ethtool_ringparam *ring) { struct ixgb_adapter *adapter = netdev_priv(netdev); struct ixgb_desc_ring *txdr = &adapter->tx_ring; struct ixgb_desc_ring *rxdr = &adapter->rx_ring; ring->rx_max_pending = MAX_RXD; ring->tx_max_pending = MAX_TXD; ring->rx_pending = rxdr->count; ring->tx_pending = txdr->count; } static int ixgb_set_ringparam(struct net_device *netdev, struct ethtool_ringparam *ring) { struct ixgb_adapter *adapter = netdev_priv(netdev); struct ixgb_desc_ring *txdr = &adapter->tx_ring; struct ixgb_desc_ring *rxdr = &adapter->rx_ring; struct ixgb_desc_ring tx_old, tx_new, rx_old, rx_new; int err; tx_old = adapter->tx_ring; rx_old = adapter->rx_ring; if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending)) return -EINVAL; if (netif_running(adapter->netdev)) ixgb_down(adapter, true); rxdr->count = max(ring->rx_pending,(u32)MIN_RXD); rxdr->count = min(rxdr->count,(u32)MAX_RXD); rxdr->count = ALIGN(rxdr->count, IXGB_REQ_RX_DESCRIPTOR_MULTIPLE); txdr->count = max(ring->tx_pending,(u32)MIN_TXD); txdr->count = min(txdr->count,(u32)MAX_TXD); txdr->count = ALIGN(txdr->count, IXGB_REQ_TX_DESCRIPTOR_MULTIPLE); if (netif_running(adapter->netdev)) { /* Try to get new resources before deleting old */ if ((err = ixgb_setup_rx_resources(adapter))) goto err_setup_rx; if ((err = ixgb_setup_tx_resources(adapter))) goto err_setup_tx; /* save the new, restore the old in order to free it, * then restore the new back again */ rx_new = adapter->rx_ring; tx_new = adapter->tx_ring; adapter->rx_ring = rx_old; adapter->tx_ring = tx_old; ixgb_free_rx_resources(adapter); ixgb_free_tx_resources(adapter); adapter->rx_ring = rx_new; adapter->tx_ring = tx_new; if ((err = ixgb_up(adapter))) return err; ixgb_set_speed_duplex(netdev); } return 0; err_setup_tx: ixgb_free_rx_resources(adapter); err_setup_rx: adapter->rx_ring = rx_old; adapter->tx_ring = tx_old; ixgb_up(adapter); return err; } static int ixgb_set_phys_id(struct net_device *netdev, enum ethtool_phys_id_state state) { struct ixgb_adapter *adapter = netdev_priv(netdev); switch (state) { case ETHTOOL_ID_ACTIVE: return 2; case ETHTOOL_ID_ON: ixgb_led_on(&adapter->hw); break; case ETHTOOL_ID_OFF: case ETHTOOL_ID_INACTIVE: ixgb_led_off(&adapter->hw); } return 0; } static int ixgb_get_sset_count(struct net_device *netdev, int sset) { switch (sset) { case ETH_SS_STATS: return IXGB_STATS_LEN; default: return -EOPNOTSUPP; } } static void ixgb_get_ethtool_stats(struct net_device *netdev, struct ethtool_stats *stats, u64 *data) { struct ixgb_adapter *adapter = netdev_priv(netdev); int i; char *p = NULL; ixgb_update_stats(adapter); for (i = 0; i < IXGB_STATS_LEN; i++) { switch (ixgb_gstrings_stats[i].type) { case NETDEV_STATS: p = (char *) netdev + ixgb_gstrings_stats[i].stat_offset; break; case IXGB_STATS: p = (char *) adapter + ixgb_gstrings_stats[i].stat_offset; break; } data[i] = (ixgb_gstrings_stats[i].sizeof_stat == sizeof(u64)) ? *(u64 *)p : *(u32 *)p; } } static void ixgb_get_strings(struct net_device *netdev, u32 stringset, u8 *data) { int i; switch(stringset) { case ETH_SS_STATS: for (i = 0; i < IXGB_STATS_LEN; i++) { memcpy(data + i * ETH_GSTRING_LEN, ixgb_gstrings_stats[i].stat_string, ETH_GSTRING_LEN); } break; } } static const struct ethtool_ops ixgb_ethtool_ops = { .get_settings = ixgb_get_settings, .set_settings = ixgb_set_settings, .get_drvinfo = ixgb_get_drvinfo, .get_regs_len = ixgb_get_regs_len, .get_regs = ixgb_get_regs, .get_link = ethtool_op_get_link, .get_eeprom_len = ixgb_get_eeprom_len, .get_eeprom = ixgb_get_eeprom, .set_eeprom = ixgb_set_eeprom, .get_ringparam = ixgb_get_ringparam, .set_ringparam = ixgb_set_ringparam, .get_pauseparam = ixgb_get_pauseparam, .set_pauseparam = ixgb_set_pauseparam, .get_msglevel = ixgb_get_msglevel, .set_msglevel = ixgb_set_msglevel, .get_strings = ixgb_get_strings, .set_phys_id = ixgb_set_phys_id, .get_sset_count = ixgb_get_sset_count, .get_ethtool_stats = ixgb_get_ethtool_stats, }; void ixgb_set_ethtool_ops(struct net_device *netdev) { netdev->ethtool_ops = &ixgb_ethtool_ops; }
gpl-2.0
STS-Dev-Team/kernel_omap4_xt910s
kernel/irq/handle.c
1297
4729
/* * linux/kernel/irq/handle.c * * Copyright (C) 1992, 1998-2006 Linus Torvalds, Ingo Molnar * Copyright (C) 2005-2006, Thomas Gleixner, Russell King * * This file contains the core interrupt handling code. * * Detailed information is available in Documentation/DocBook/genericirq * */ #include <linux/irq.h> #include <linux/random.h> #include <linux/sched.h> #include <linux/interrupt.h> #include <linux/kernel_stat.h> #include <trace/events/irq.h> #include "internals.h" /** * handle_bad_irq - handle spurious and unhandled irqs * @irq: the interrupt number * @desc: description of the interrupt * * Handles spurious and unhandled IRQ's. It also prints a debugmessage. */ void handle_bad_irq(unsigned int irq, struct irq_desc *desc) { print_irq_desc(irq, desc); kstat_incr_irqs_this_cpu(irq, desc); ack_bad_irq(irq); } /* * Special, empty irq handler: */ irqreturn_t no_action(int cpl, void *dev_id) { return IRQ_NONE; } static void warn_no_thread(unsigned int irq, struct irqaction *action) { if (test_and_set_bit(IRQTF_WARNED, &action->thread_flags)) return; printk(KERN_WARNING "IRQ %d device %s returned IRQ_WAKE_THREAD " "but no thread function available.", irq, action->name); } static void irq_wake_thread(struct irq_desc *desc, struct irqaction *action) { /* * Wake up the handler thread for this action. In case the * thread crashed and was killed we just pretend that we * handled the interrupt. The hardirq handler has disabled the * device interrupt, so no irq storm is lurking. If the * RUNTHREAD bit is already set, nothing to do. */ if (test_bit(IRQTF_DIED, &action->thread_flags) || test_and_set_bit(IRQTF_RUNTHREAD, &action->thread_flags)) return; /* * It's safe to OR the mask lockless here. We have only two * places which write to threads_oneshot: This code and the * irq thread. * * This code is the hard irq context and can never run on two * cpus in parallel. If it ever does we have more serious * problems than this bitmask. * * The irq threads of this irq which clear their "running" bit * in threads_oneshot are serialized via desc->lock against * each other and they are serialized against this code by * IRQS_INPROGRESS. * * Hard irq handler: * * spin_lock(desc->lock); * desc->state |= IRQS_INPROGRESS; * spin_unlock(desc->lock); * set_bit(IRQTF_RUNTHREAD, &action->thread_flags); * desc->threads_oneshot |= mask; * spin_lock(desc->lock); * desc->state &= ~IRQS_INPROGRESS; * spin_unlock(desc->lock); * * irq thread: * * again: * spin_lock(desc->lock); * if (desc->state & IRQS_INPROGRESS) { * spin_unlock(desc->lock); * while(desc->state & IRQS_INPROGRESS) * cpu_relax(); * goto again; * } * if (!test_bit(IRQTF_RUNTHREAD, &action->thread_flags)) * desc->threads_oneshot &= ~mask; * spin_unlock(desc->lock); * * So either the thread waits for us to clear IRQS_INPROGRESS * or we are waiting in the flow handler for desc->lock to be * released before we reach this point. The thread also checks * IRQTF_RUNTHREAD under desc->lock. If set it leaves * threads_oneshot untouched and runs the thread another time. */ desc->threads_oneshot |= action->thread_mask; wake_up_process(action->thread); } irqreturn_t handle_irq_event_percpu(struct irq_desc *desc, struct irqaction *action) { irqreturn_t retval = IRQ_NONE; unsigned int random = 0, irq = desc->irq_data.irq; do { irqreturn_t res; trace_irq_handler_entry(irq, action); res = action->handler(irq, action->dev_id); trace_irq_handler_exit(irq, action, res); if (WARN_ONCE(!irqs_disabled(),"irq %u handler %pF enabled interrupts\n", irq, action->handler)) local_irq_disable(); switch (res) { case IRQ_WAKE_THREAD: /* * Catch drivers which return WAKE_THREAD but * did not set up a thread function */ if (unlikely(!action->thread_fn)) { warn_no_thread(irq, action); break; } irq_wake_thread(desc, action); /* Fall through to add to randomness */ case IRQ_HANDLED: random |= action->flags; break; default: break; } retval |= res; action = action->next; } while (action); if (random & IRQF_SAMPLE_RANDOM) add_interrupt_randomness(irq); if (!noirqdebug) note_interrupt(irq, desc, retval); return retval; } irqreturn_t handle_irq_event(struct irq_desc *desc) { struct irqaction *action = desc->action; irqreturn_t ret; desc->istate &= ~IRQS_PENDING; irqd_set(&desc->irq_data, IRQD_IRQ_INPROGRESS); raw_spin_unlock(&desc->lock); ret = handle_irq_event_percpu(desc, action); raw_spin_lock(&desc->lock); irqd_clear(&desc->irq_data, IRQD_IRQ_INPROGRESS); return ret; }
gpl-2.0
2fast4u88/Htc-Design-FastKernel
init/noinitramfs.c
1809
1426
/* * init/noinitramfs.c * * Copyright (C) 2006, NXP Semiconductors, All Rights Reserved * Author: Jean-Paul Saman <jean-paul.saman@nxp.com> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; version 2 of the License. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include <linux/init.h> #include <linux/stat.h> #include <linux/kdev_t.h> #include <linux/syscalls.h> /* * Create a simple rootfs that is similar to the default initramfs */ static int __init default_rootfs(void) { int err; err = sys_mkdir("/dev", 0755); if (err < 0) goto out; err = sys_mknod((const char __user *) "/dev/console", S_IFCHR | S_IRUSR | S_IWUSR, new_encode_dev(MKDEV(5, 1))); if (err < 0) goto out; err = sys_mkdir("/root", 0700); if (err < 0) goto out; return 0; out: printk(KERN_WARNING "Failed to create a rootfs\n"); return err; } rootfs_initcall(default_rootfs);
gpl-2.0
thicklizard/komodo_ville
drivers/net/wireless/ath/ath9k/htc_drv_main.c
2321
45146
/* * Copyright (c) 2010-2011 Atheros Communications Inc. * * Permission to use, copy, modify, and/or distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ #include "htc.h" /*************/ /* Utilities */ /*************/ /* HACK Alert: Use 11NG for 2.4, use 11NA for 5 */ static enum htc_phymode ath9k_htc_get_curmode(struct ath9k_htc_priv *priv, struct ath9k_channel *ichan) { enum htc_phymode mode; mode = -EINVAL; switch (ichan->chanmode) { case CHANNEL_G: case CHANNEL_G_HT20: case CHANNEL_G_HT40PLUS: case CHANNEL_G_HT40MINUS: mode = HTC_MODE_11NG; break; case CHANNEL_A: case CHANNEL_A_HT20: case CHANNEL_A_HT40PLUS: case CHANNEL_A_HT40MINUS: mode = HTC_MODE_11NA; break; default: break; } WARN_ON(mode < 0); return mode; } bool ath9k_htc_setpower(struct ath9k_htc_priv *priv, enum ath9k_power_mode mode) { bool ret; mutex_lock(&priv->htc_pm_lock); ret = ath9k_hw_setpower(priv->ah, mode); mutex_unlock(&priv->htc_pm_lock); return ret; } void ath9k_htc_ps_wakeup(struct ath9k_htc_priv *priv) { mutex_lock(&priv->htc_pm_lock); if (++priv->ps_usecount != 1) goto unlock; ath9k_hw_setpower(priv->ah, ATH9K_PM_AWAKE); unlock: mutex_unlock(&priv->htc_pm_lock); } void ath9k_htc_ps_restore(struct ath9k_htc_priv *priv) { mutex_lock(&priv->htc_pm_lock); if (--priv->ps_usecount != 0) goto unlock; if (priv->ps_idle) ath9k_hw_setpower(priv->ah, ATH9K_PM_FULL_SLEEP); else if (priv->ps_enabled) ath9k_hw_setpower(priv->ah, ATH9K_PM_NETWORK_SLEEP); unlock: mutex_unlock(&priv->htc_pm_lock); } void ath9k_ps_work(struct work_struct *work) { struct ath9k_htc_priv *priv = container_of(work, struct ath9k_htc_priv, ps_work); ath9k_htc_setpower(priv, ATH9K_PM_AWAKE); /* The chip wakes up after receiving the first beacon while network sleep is enabled. For the driver to be in sync with the hw, set the chip to awake and only then set it to sleep. */ ath9k_htc_setpower(priv, ATH9K_PM_NETWORK_SLEEP); } static void ath9k_htc_vif_iter(void *data, u8 *mac, struct ieee80211_vif *vif) { struct ath9k_htc_priv *priv = data; struct ieee80211_bss_conf *bss_conf = &vif->bss_conf; if ((vif->type == NL80211_IFTYPE_AP) && bss_conf->enable_beacon) priv->reconfig_beacon = true; if (bss_conf->assoc) { priv->rearm_ani = true; priv->reconfig_beacon = true; } } static void ath9k_htc_vif_reconfig(struct ath9k_htc_priv *priv) { priv->rearm_ani = false; priv->reconfig_beacon = false; ieee80211_iterate_active_interfaces_atomic(priv->hw, ath9k_htc_vif_iter, priv); if (priv->rearm_ani) ath9k_htc_start_ani(priv); if (priv->reconfig_beacon) { ath9k_htc_ps_wakeup(priv); ath9k_htc_beacon_reconfig(priv); ath9k_htc_ps_restore(priv); } } static void ath9k_htc_bssid_iter(void *data, u8 *mac, struct ieee80211_vif *vif) { struct ath9k_vif_iter_data *iter_data = data; int i; for (i = 0; i < ETH_ALEN; i++) iter_data->mask[i] &= ~(iter_data->hw_macaddr[i] ^ mac[i]); } static void ath9k_htc_set_bssid_mask(struct ath9k_htc_priv *priv, struct ieee80211_vif *vif) { struct ath_common *common = ath9k_hw_common(priv->ah); struct ath9k_vif_iter_data iter_data; /* * Use the hardware MAC address as reference, the hardware uses it * together with the BSSID mask when matching addresses. */ iter_data.hw_macaddr = common->macaddr; memset(&iter_data.mask, 0xff, ETH_ALEN); if (vif) ath9k_htc_bssid_iter(&iter_data, vif->addr, vif); /* Get list of all active MAC addresses */ ieee80211_iterate_active_interfaces_atomic(priv->hw, ath9k_htc_bssid_iter, &iter_data); memcpy(common->bssidmask, iter_data.mask, ETH_ALEN); ath_hw_setbssidmask(common); } static void ath9k_htc_set_opmode(struct ath9k_htc_priv *priv) { if (priv->num_ibss_vif) priv->ah->opmode = NL80211_IFTYPE_ADHOC; else if (priv->num_ap_vif) priv->ah->opmode = NL80211_IFTYPE_AP; else priv->ah->opmode = NL80211_IFTYPE_STATION; ath9k_hw_setopmode(priv->ah); } void ath9k_htc_reset(struct ath9k_htc_priv *priv) { struct ath_hw *ah = priv->ah; struct ath_common *common = ath9k_hw_common(ah); struct ieee80211_channel *channel = priv->hw->conf.channel; struct ath9k_hw_cal_data *caldata = NULL; enum htc_phymode mode; __be16 htc_mode; u8 cmd_rsp; int ret; mutex_lock(&priv->mutex); ath9k_htc_ps_wakeup(priv); ath9k_htc_stop_ani(priv); ieee80211_stop_queues(priv->hw); del_timer_sync(&priv->tx.cleanup_timer); ath9k_htc_tx_drain(priv); WMI_CMD(WMI_DISABLE_INTR_CMDID); WMI_CMD(WMI_DRAIN_TXQ_ALL_CMDID); WMI_CMD(WMI_STOP_RECV_CMDID); ath9k_wmi_event_drain(priv); caldata = &priv->caldata; ret = ath9k_hw_reset(ah, ah->curchan, caldata, false); if (ret) { ath_err(common, "Unable to reset device (%u Mhz) reset status %d\n", channel->center_freq, ret); } ath9k_cmn_update_txpow(ah, priv->curtxpow, priv->txpowlimit, &priv->curtxpow); WMI_CMD(WMI_START_RECV_CMDID); ath9k_host_rx_init(priv); mode = ath9k_htc_get_curmode(priv, ah->curchan); htc_mode = cpu_to_be16(mode); WMI_CMD_BUF(WMI_SET_MODE_CMDID, &htc_mode); WMI_CMD(WMI_ENABLE_INTR_CMDID); htc_start(priv->htc); ath9k_htc_vif_reconfig(priv); ieee80211_wake_queues(priv->hw); mod_timer(&priv->tx.cleanup_timer, jiffies + msecs_to_jiffies(ATH9K_HTC_TX_CLEANUP_INTERVAL)); ath9k_htc_ps_restore(priv); mutex_unlock(&priv->mutex); } static int ath9k_htc_set_channel(struct ath9k_htc_priv *priv, struct ieee80211_hw *hw, struct ath9k_channel *hchan) { struct ath_hw *ah = priv->ah; struct ath_common *common = ath9k_hw_common(ah); struct ieee80211_conf *conf = &common->hw->conf; bool fastcc; struct ieee80211_channel *channel = hw->conf.channel; struct ath9k_hw_cal_data *caldata = NULL; enum htc_phymode mode; __be16 htc_mode; u8 cmd_rsp; int ret; if (priv->op_flags & OP_INVALID) return -EIO; fastcc = !!(hw->conf.flags & IEEE80211_CONF_OFFCHANNEL); ath9k_htc_ps_wakeup(priv); del_timer_sync(&priv->tx.cleanup_timer); ath9k_htc_tx_drain(priv); WMI_CMD(WMI_DISABLE_INTR_CMDID); WMI_CMD(WMI_DRAIN_TXQ_ALL_CMDID); WMI_CMD(WMI_STOP_RECV_CMDID); ath9k_wmi_event_drain(priv); ath_dbg(common, ATH_DBG_CONFIG, "(%u MHz) -> (%u MHz), HT: %d, HT40: %d fastcc: %d\n", priv->ah->curchan->channel, channel->center_freq, conf_is_ht(conf), conf_is_ht40(conf), fastcc); if (!fastcc) caldata = &priv->caldata; ret = ath9k_hw_reset(ah, hchan, caldata, fastcc); if (ret) { ath_err(common, "Unable to reset channel (%u Mhz) reset status %d\n", channel->center_freq, ret); goto err; } ath9k_cmn_update_txpow(ah, priv->curtxpow, priv->txpowlimit, &priv->curtxpow); WMI_CMD(WMI_START_RECV_CMDID); if (ret) goto err; ath9k_host_rx_init(priv); mode = ath9k_htc_get_curmode(priv, hchan); htc_mode = cpu_to_be16(mode); WMI_CMD_BUF(WMI_SET_MODE_CMDID, &htc_mode); if (ret) goto err; WMI_CMD(WMI_ENABLE_INTR_CMDID); if (ret) goto err; htc_start(priv->htc); if (!(priv->op_flags & OP_SCANNING) && !(hw->conf.flags & IEEE80211_CONF_OFFCHANNEL)) ath9k_htc_vif_reconfig(priv); mod_timer(&priv->tx.cleanup_timer, jiffies + msecs_to_jiffies(ATH9K_HTC_TX_CLEANUP_INTERVAL)); err: ath9k_htc_ps_restore(priv); return ret; } /* * Monitor mode handling is a tad complicated because the firmware requires * an interface to be created exclusively, while mac80211 doesn't associate * an interface with the mode. * * So, for now, only one monitor interface can be configured. */ static void __ath9k_htc_remove_monitor_interface(struct ath9k_htc_priv *priv) { struct ath_common *common = ath9k_hw_common(priv->ah); struct ath9k_htc_target_vif hvif; int ret = 0; u8 cmd_rsp; memset(&hvif, 0, sizeof(struct ath9k_htc_target_vif)); memcpy(&hvif.myaddr, common->macaddr, ETH_ALEN); hvif.index = priv->mon_vif_idx; WMI_CMD_BUF(WMI_VAP_REMOVE_CMDID, &hvif); if (ret) { ath_err(common, "Unable to remove monitor interface at idx: %d\n", priv->mon_vif_idx); } priv->nvifs--; priv->vif_slot &= ~(1 << priv->mon_vif_idx); } static int ath9k_htc_add_monitor_interface(struct ath9k_htc_priv *priv) { struct ath_common *common = ath9k_hw_common(priv->ah); struct ath9k_htc_target_vif hvif; struct ath9k_htc_target_sta tsta; int ret = 0, sta_idx; u8 cmd_rsp; if ((priv->nvifs >= ATH9K_HTC_MAX_VIF) || (priv->nstations >= ATH9K_HTC_MAX_STA)) { ret = -ENOBUFS; goto err_vif; } sta_idx = ffz(priv->sta_slot); if ((sta_idx < 0) || (sta_idx > ATH9K_HTC_MAX_STA)) { ret = -ENOBUFS; goto err_vif; } /* * Add an interface. */ memset(&hvif, 0, sizeof(struct ath9k_htc_target_vif)); memcpy(&hvif.myaddr, common->macaddr, ETH_ALEN); hvif.opmode = HTC_M_MONITOR; hvif.index = ffz(priv->vif_slot); WMI_CMD_BUF(WMI_VAP_CREATE_CMDID, &hvif); if (ret) goto err_vif; /* * Assign the monitor interface index as a special case here. * This is needed when the interface is brought down. */ priv->mon_vif_idx = hvif.index; priv->vif_slot |= (1 << hvif.index); /* * Set the hardware mode to monitor only if there are no * other interfaces. */ if (!priv->nvifs) priv->ah->opmode = NL80211_IFTYPE_MONITOR; priv->nvifs++; /* * Associate a station with the interface for packet injection. */ memset(&tsta, 0, sizeof(struct ath9k_htc_target_sta)); memcpy(&tsta.macaddr, common->macaddr, ETH_ALEN); tsta.is_vif_sta = 1; tsta.sta_index = sta_idx; tsta.vif_index = hvif.index; tsta.maxampdu = cpu_to_be16(0xffff); WMI_CMD_BUF(WMI_NODE_CREATE_CMDID, &tsta); if (ret) { ath_err(common, "Unable to add station entry for monitor mode\n"); goto err_sta; } priv->sta_slot |= (1 << sta_idx); priv->nstations++; priv->vif_sta_pos[priv->mon_vif_idx] = sta_idx; priv->ah->is_monitoring = true; ath_dbg(common, ATH_DBG_CONFIG, "Attached a monitor interface at idx: %d, sta idx: %d\n", priv->mon_vif_idx, sta_idx); return 0; err_sta: /* * Remove the interface from the target. */ __ath9k_htc_remove_monitor_interface(priv); err_vif: ath_dbg(common, ATH_DBG_FATAL, "Unable to attach a monitor interface\n"); return ret; } static int ath9k_htc_remove_monitor_interface(struct ath9k_htc_priv *priv) { struct ath_common *common = ath9k_hw_common(priv->ah); int ret = 0; u8 cmd_rsp, sta_idx; __ath9k_htc_remove_monitor_interface(priv); sta_idx = priv->vif_sta_pos[priv->mon_vif_idx]; WMI_CMD_BUF(WMI_NODE_REMOVE_CMDID, &sta_idx); if (ret) { ath_err(common, "Unable to remove station entry for monitor mode\n"); return ret; } priv->sta_slot &= ~(1 << sta_idx); priv->nstations--; priv->ah->is_monitoring = false; ath_dbg(common, ATH_DBG_CONFIG, "Removed a monitor interface at idx: %d, sta idx: %d\n", priv->mon_vif_idx, sta_idx); return 0; } static int ath9k_htc_add_station(struct ath9k_htc_priv *priv, struct ieee80211_vif *vif, struct ieee80211_sta *sta) { struct ath_common *common = ath9k_hw_common(priv->ah); struct ath9k_htc_target_sta tsta; struct ath9k_htc_vif *avp = (struct ath9k_htc_vif *) vif->drv_priv; struct ath9k_htc_sta *ista; int ret, sta_idx; u8 cmd_rsp; u16 maxampdu; if (priv->nstations >= ATH9K_HTC_MAX_STA) return -ENOBUFS; sta_idx = ffz(priv->sta_slot); if ((sta_idx < 0) || (sta_idx > ATH9K_HTC_MAX_STA)) return -ENOBUFS; memset(&tsta, 0, sizeof(struct ath9k_htc_target_sta)); if (sta) { ista = (struct ath9k_htc_sta *) sta->drv_priv; memcpy(&tsta.macaddr, sta->addr, ETH_ALEN); memcpy(&tsta.bssid, common->curbssid, ETH_ALEN); tsta.is_vif_sta = 0; ista->index = sta_idx; } else { memcpy(&tsta.macaddr, vif->addr, ETH_ALEN); tsta.is_vif_sta = 1; } tsta.sta_index = sta_idx; tsta.vif_index = avp->index; if (!sta) { tsta.maxampdu = cpu_to_be16(0xffff); } else { maxampdu = 1 << (IEEE80211_HT_MAX_AMPDU_FACTOR + sta->ht_cap.ampdu_factor); tsta.maxampdu = cpu_to_be16(maxampdu); } WMI_CMD_BUF(WMI_NODE_CREATE_CMDID, &tsta); if (ret) { if (sta) ath_err(common, "Unable to add station entry for: %pM\n", sta->addr); return ret; } if (sta) { ath_dbg(common, ATH_DBG_CONFIG, "Added a station entry for: %pM (idx: %d)\n", sta->addr, tsta.sta_index); } else { ath_dbg(common, ATH_DBG_CONFIG, "Added a station entry for VIF %d (idx: %d)\n", avp->index, tsta.sta_index); } priv->sta_slot |= (1 << sta_idx); priv->nstations++; if (!sta) priv->vif_sta_pos[avp->index] = sta_idx; return 0; } static int ath9k_htc_remove_station(struct ath9k_htc_priv *priv, struct ieee80211_vif *vif, struct ieee80211_sta *sta) { struct ath_common *common = ath9k_hw_common(priv->ah); struct ath9k_htc_vif *avp = (struct ath9k_htc_vif *) vif->drv_priv; struct ath9k_htc_sta *ista; int ret; u8 cmd_rsp, sta_idx; if (sta) { ista = (struct ath9k_htc_sta *) sta->drv_priv; sta_idx = ista->index; } else { sta_idx = priv->vif_sta_pos[avp->index]; } WMI_CMD_BUF(WMI_NODE_REMOVE_CMDID, &sta_idx); if (ret) { if (sta) ath_err(common, "Unable to remove station entry for: %pM\n", sta->addr); return ret; } if (sta) { ath_dbg(common, ATH_DBG_CONFIG, "Removed a station entry for: %pM (idx: %d)\n", sta->addr, sta_idx); } else { ath_dbg(common, ATH_DBG_CONFIG, "Removed a station entry for VIF %d (idx: %d)\n", avp->index, sta_idx); } priv->sta_slot &= ~(1 << sta_idx); priv->nstations--; return 0; } int ath9k_htc_update_cap_target(struct ath9k_htc_priv *priv, u8 enable_coex) { struct ath9k_htc_cap_target tcap; int ret; u8 cmd_rsp; memset(&tcap, 0, sizeof(struct ath9k_htc_cap_target)); tcap.ampdu_limit = cpu_to_be32(0xffff); tcap.ampdu_subframes = 0xff; tcap.enable_coex = enable_coex; tcap.tx_chainmask = priv->ah->caps.tx_chainmask; WMI_CMD_BUF(WMI_TARGET_IC_UPDATE_CMDID, &tcap); return ret; } static void ath9k_htc_setup_rate(struct ath9k_htc_priv *priv, struct ieee80211_sta *sta, struct ath9k_htc_target_rate *trate) { struct ath9k_htc_sta *ista = (struct ath9k_htc_sta *) sta->drv_priv; struct ieee80211_supported_band *sband; u32 caps = 0; int i, j; sband = priv->hw->wiphy->bands[priv->hw->conf.channel->band]; for (i = 0, j = 0; i < sband->n_bitrates; i++) { if (sta->supp_rates[sband->band] & BIT(i)) { trate->rates.legacy_rates.rs_rates[j] = (sband->bitrates[i].bitrate * 2) / 10; j++; } } trate->rates.legacy_rates.rs_nrates = j; if (sta->ht_cap.ht_supported) { for (i = 0, j = 0; i < 77; i++) { if (sta->ht_cap.mcs.rx_mask[i/8] & (1<<(i%8))) trate->rates.ht_rates.rs_rates[j++] = i; if (j == ATH_HTC_RATE_MAX) break; } trate->rates.ht_rates.rs_nrates = j; caps = WLAN_RC_HT_FLAG; if (sta->ht_cap.mcs.rx_mask[1]) caps |= WLAN_RC_DS_FLAG; if ((sta->ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40) && (conf_is_ht40(&priv->hw->conf))) caps |= WLAN_RC_40_FLAG; if (conf_is_ht40(&priv->hw->conf) && (sta->ht_cap.cap & IEEE80211_HT_CAP_SGI_40)) caps |= WLAN_RC_SGI_FLAG; else if (conf_is_ht20(&priv->hw->conf) && (sta->ht_cap.cap & IEEE80211_HT_CAP_SGI_20)) caps |= WLAN_RC_SGI_FLAG; } trate->sta_index = ista->index; trate->isnew = 1; trate->capflags = cpu_to_be32(caps); } static int ath9k_htc_send_rate_cmd(struct ath9k_htc_priv *priv, struct ath9k_htc_target_rate *trate) { struct ath_common *common = ath9k_hw_common(priv->ah); int ret; u8 cmd_rsp; WMI_CMD_BUF(WMI_RC_RATE_UPDATE_CMDID, trate); if (ret) { ath_err(common, "Unable to initialize Rate information on target\n"); } return ret; } static void ath9k_htc_init_rate(struct ath9k_htc_priv *priv, struct ieee80211_sta *sta) { struct ath_common *common = ath9k_hw_common(priv->ah); struct ath9k_htc_target_rate trate; int ret; memset(&trate, 0, sizeof(struct ath9k_htc_target_rate)); ath9k_htc_setup_rate(priv, sta, &trate); ret = ath9k_htc_send_rate_cmd(priv, &trate); if (!ret) ath_dbg(common, ATH_DBG_CONFIG, "Updated target sta: %pM, rate caps: 0x%X\n", sta->addr, be32_to_cpu(trate.capflags)); } static void ath9k_htc_update_rate(struct ath9k_htc_priv *priv, struct ieee80211_vif *vif, struct ieee80211_bss_conf *bss_conf) { struct ath_common *common = ath9k_hw_common(priv->ah); struct ath9k_htc_target_rate trate; struct ieee80211_sta *sta; int ret; memset(&trate, 0, sizeof(struct ath9k_htc_target_rate)); rcu_read_lock(); sta = ieee80211_find_sta(vif, bss_conf->bssid); if (!sta) { rcu_read_unlock(); return; } ath9k_htc_setup_rate(priv, sta, &trate); rcu_read_unlock(); ret = ath9k_htc_send_rate_cmd(priv, &trate); if (!ret) ath_dbg(common, ATH_DBG_CONFIG, "Updated target sta: %pM, rate caps: 0x%X\n", bss_conf->bssid, be32_to_cpu(trate.capflags)); } static int ath9k_htc_tx_aggr_oper(struct ath9k_htc_priv *priv, struct ieee80211_vif *vif, struct ieee80211_sta *sta, enum ieee80211_ampdu_mlme_action action, u16 tid) { struct ath_common *common = ath9k_hw_common(priv->ah); struct ath9k_htc_target_aggr aggr; struct ath9k_htc_sta *ista; int ret = 0; u8 cmd_rsp; if (tid >= ATH9K_HTC_MAX_TID) return -EINVAL; memset(&aggr, 0, sizeof(struct ath9k_htc_target_aggr)); ista = (struct ath9k_htc_sta *) sta->drv_priv; aggr.sta_index = ista->index; aggr.tidno = tid & 0xf; aggr.aggr_enable = (action == IEEE80211_AMPDU_TX_START) ? true : false; WMI_CMD_BUF(WMI_TX_AGGR_ENABLE_CMDID, &aggr); if (ret) ath_dbg(common, ATH_DBG_CONFIG, "Unable to %s TX aggregation for (%pM, %d)\n", (aggr.aggr_enable) ? "start" : "stop", sta->addr, tid); else ath_dbg(common, ATH_DBG_CONFIG, "%s TX aggregation for (%pM, %d)\n", (aggr.aggr_enable) ? "Starting" : "Stopping", sta->addr, tid); spin_lock_bh(&priv->tx.tx_lock); ista->tid_state[tid] = (aggr.aggr_enable && !ret) ? AGGR_START : AGGR_STOP; spin_unlock_bh(&priv->tx.tx_lock); return ret; } /*******/ /* ANI */ /*******/ void ath9k_htc_start_ani(struct ath9k_htc_priv *priv) { struct ath_common *common = ath9k_hw_common(priv->ah); unsigned long timestamp = jiffies_to_msecs(jiffies); common->ani.longcal_timer = timestamp; common->ani.shortcal_timer = timestamp; common->ani.checkani_timer = timestamp; priv->op_flags |= OP_ANI_RUNNING; ieee80211_queue_delayed_work(common->hw, &priv->ani_work, msecs_to_jiffies(ATH_ANI_POLLINTERVAL)); } void ath9k_htc_stop_ani(struct ath9k_htc_priv *priv) { cancel_delayed_work_sync(&priv->ani_work); priv->op_flags &= ~OP_ANI_RUNNING; } void ath9k_htc_ani_work(struct work_struct *work) { struct ath9k_htc_priv *priv = container_of(work, struct ath9k_htc_priv, ani_work.work); struct ath_hw *ah = priv->ah; struct ath_common *common = ath9k_hw_common(ah); bool longcal = false; bool shortcal = false; bool aniflag = false; unsigned int timestamp = jiffies_to_msecs(jiffies); u32 cal_interval, short_cal_interval; short_cal_interval = (ah->opmode == NL80211_IFTYPE_AP) ? ATH_AP_SHORT_CALINTERVAL : ATH_STA_SHORT_CALINTERVAL; /* Only calibrate if awake */ if (ah->power_mode != ATH9K_PM_AWAKE) goto set_timer; /* Long calibration runs independently of short calibration. */ if ((timestamp - common->ani.longcal_timer) >= ATH_LONG_CALINTERVAL) { longcal = true; ath_dbg(common, ATH_DBG_ANI, "longcal @%lu\n", jiffies); common->ani.longcal_timer = timestamp; } /* Short calibration applies only while caldone is false */ if (!common->ani.caldone) { if ((timestamp - common->ani.shortcal_timer) >= short_cal_interval) { shortcal = true; ath_dbg(common, ATH_DBG_ANI, "shortcal @%lu\n", jiffies); common->ani.shortcal_timer = timestamp; common->ani.resetcal_timer = timestamp; } } else { if ((timestamp - common->ani.resetcal_timer) >= ATH_RESTART_CALINTERVAL) { common->ani.caldone = ath9k_hw_reset_calvalid(ah); if (common->ani.caldone) common->ani.resetcal_timer = timestamp; } } /* Verify whether we must check ANI */ if ((timestamp - common->ani.checkani_timer) >= ATH_ANI_POLLINTERVAL) { aniflag = true; common->ani.checkani_timer = timestamp; } /* Skip all processing if there's nothing to do. */ if (longcal || shortcal || aniflag) { ath9k_htc_ps_wakeup(priv); /* Call ANI routine if necessary */ if (aniflag) ath9k_hw_ani_monitor(ah, ah->curchan); /* Perform calibration if necessary */ if (longcal || shortcal) common->ani.caldone = ath9k_hw_calibrate(ah, ah->curchan, common->rx_chainmask, longcal); ath9k_htc_ps_restore(priv); } set_timer: /* * Set timer interval based on previous results. * The interval must be the shortest necessary to satisfy ANI, * short calibration and long calibration. */ cal_interval = ATH_LONG_CALINTERVAL; if (priv->ah->config.enable_ani) cal_interval = min(cal_interval, (u32)ATH_ANI_POLLINTERVAL); if (!common->ani.caldone) cal_interval = min(cal_interval, (u32)short_cal_interval); ieee80211_queue_delayed_work(common->hw, &priv->ani_work, msecs_to_jiffies(cal_interval)); } /**********************/ /* mac80211 Callbacks */ /**********************/ static void ath9k_htc_tx(struct ieee80211_hw *hw, struct sk_buff *skb) { struct ieee80211_hdr *hdr; struct ath9k_htc_priv *priv = hw->priv; struct ath_common *common = ath9k_hw_common(priv->ah); int padpos, padsize, ret, slot; hdr = (struct ieee80211_hdr *) skb->data; /* Add the padding after the header if this is not already done */ padpos = ath9k_cmn_padpos(hdr->frame_control); padsize = padpos & 3; if (padsize && skb->len > padpos) { if (skb_headroom(skb) < padsize) { ath_dbg(common, ATH_DBG_XMIT, "No room for padding\n"); goto fail_tx; } skb_push(skb, padsize); memmove(skb->data, skb->data + padsize, padpos); } slot = ath9k_htc_tx_get_slot(priv); if (slot < 0) { ath_dbg(common, ATH_DBG_XMIT, "No free TX slot\n"); goto fail_tx; } ret = ath9k_htc_tx_start(priv, skb, slot, false); if (ret != 0) { ath_dbg(common, ATH_DBG_XMIT, "Tx failed\n"); goto clear_slot; } ath9k_htc_check_stop_queues(priv); return; clear_slot: ath9k_htc_tx_clear_slot(priv, slot); fail_tx: dev_kfree_skb_any(skb); } static int ath9k_htc_start(struct ieee80211_hw *hw) { struct ath9k_htc_priv *priv = hw->priv; struct ath_hw *ah = priv->ah; struct ath_common *common = ath9k_hw_common(ah); struct ieee80211_channel *curchan = hw->conf.channel; struct ath9k_channel *init_channel; int ret = 0; enum htc_phymode mode; __be16 htc_mode; u8 cmd_rsp; mutex_lock(&priv->mutex); ath_dbg(common, ATH_DBG_CONFIG, "Starting driver with initial channel: %d MHz\n", curchan->center_freq); /* Ensure that HW is awake before flushing RX */ ath9k_htc_setpower(priv, ATH9K_PM_AWAKE); WMI_CMD(WMI_FLUSH_RECV_CMDID); /* setup initial channel */ init_channel = ath9k_cmn_get_curchannel(hw, ah); ath9k_hw_htc_resetinit(ah); ret = ath9k_hw_reset(ah, init_channel, ah->caldata, false); if (ret) { ath_err(common, "Unable to reset hardware; reset status %d (freq %u MHz)\n", ret, curchan->center_freq); mutex_unlock(&priv->mutex); return ret; } ath9k_cmn_update_txpow(ah, priv->curtxpow, priv->txpowlimit, &priv->curtxpow); mode = ath9k_htc_get_curmode(priv, init_channel); htc_mode = cpu_to_be16(mode); WMI_CMD_BUF(WMI_SET_MODE_CMDID, &htc_mode); WMI_CMD(WMI_ATH_INIT_CMDID); WMI_CMD(WMI_START_RECV_CMDID); ath9k_host_rx_init(priv); ret = ath9k_htc_update_cap_target(priv, 0); if (ret) ath_dbg(common, ATH_DBG_CONFIG, "Failed to update capability in target\n"); priv->op_flags &= ~OP_INVALID; htc_start(priv->htc); spin_lock_bh(&priv->tx.tx_lock); priv->tx.flags &= ~ATH9K_HTC_OP_TX_QUEUES_STOP; spin_unlock_bh(&priv->tx.tx_lock); ieee80211_wake_queues(hw); mod_timer(&priv->tx.cleanup_timer, jiffies + msecs_to_jiffies(ATH9K_HTC_TX_CLEANUP_INTERVAL)); if (ah->btcoex_hw.scheme == ATH_BTCOEX_CFG_3WIRE) { ath9k_hw_btcoex_set_weight(ah, AR_BT_COEX_WGHT, AR_STOMP_LOW_WLAN_WGHT); ath9k_hw_btcoex_enable(ah); ath_htc_resume_btcoex_work(priv); } mutex_unlock(&priv->mutex); return ret; } static void ath9k_htc_stop(struct ieee80211_hw *hw) { struct ath9k_htc_priv *priv = hw->priv; struct ath_hw *ah = priv->ah; struct ath_common *common = ath9k_hw_common(ah); int ret __attribute__ ((unused)); u8 cmd_rsp; mutex_lock(&priv->mutex); if (priv->op_flags & OP_INVALID) { ath_dbg(common, ATH_DBG_ANY, "Device not present\n"); mutex_unlock(&priv->mutex); return; } ath9k_htc_ps_wakeup(priv); WMI_CMD(WMI_DISABLE_INTR_CMDID); WMI_CMD(WMI_DRAIN_TXQ_ALL_CMDID); WMI_CMD(WMI_STOP_RECV_CMDID); tasklet_kill(&priv->rx_tasklet); del_timer_sync(&priv->tx.cleanup_timer); ath9k_htc_tx_drain(priv); ath9k_wmi_event_drain(priv); mutex_unlock(&priv->mutex); /* Cancel all the running timers/work .. */ cancel_work_sync(&priv->fatal_work); cancel_work_sync(&priv->ps_work); #ifdef CONFIG_MAC80211_LEDS cancel_work_sync(&priv->led_work); #endif ath9k_htc_stop_ani(priv); mutex_lock(&priv->mutex); if (ah->btcoex_hw.enabled) { ath9k_hw_btcoex_disable(ah); if (ah->btcoex_hw.scheme == ATH_BTCOEX_CFG_3WIRE) ath_htc_cancel_btcoex_work(priv); } /* Remove a monitor interface if it's present. */ if (priv->ah->is_monitoring) ath9k_htc_remove_monitor_interface(priv); ath9k_hw_phy_disable(ah); ath9k_hw_disable(ah); ath9k_htc_ps_restore(priv); ath9k_htc_setpower(priv, ATH9K_PM_FULL_SLEEP); priv->op_flags |= OP_INVALID; ath_dbg(common, ATH_DBG_CONFIG, "Driver halt\n"); mutex_unlock(&priv->mutex); } static int ath9k_htc_add_interface(struct ieee80211_hw *hw, struct ieee80211_vif *vif) { struct ath9k_htc_priv *priv = hw->priv; struct ath9k_htc_vif *avp = (void *)vif->drv_priv; struct ath_common *common = ath9k_hw_common(priv->ah); struct ath9k_htc_target_vif hvif; int ret = 0; u8 cmd_rsp; mutex_lock(&priv->mutex); if (priv->nvifs >= ATH9K_HTC_MAX_VIF) { mutex_unlock(&priv->mutex); return -ENOBUFS; } if (priv->num_ibss_vif || (priv->nvifs && vif->type == NL80211_IFTYPE_ADHOC)) { ath_err(common, "IBSS coexistence with other modes is not allowed\n"); mutex_unlock(&priv->mutex); return -ENOBUFS; } if (((vif->type == NL80211_IFTYPE_AP) || (vif->type == NL80211_IFTYPE_ADHOC)) && ((priv->num_ap_vif + priv->num_ibss_vif) >= ATH9K_HTC_MAX_BCN_VIF)) { ath_err(common, "Max. number of beaconing interfaces reached\n"); mutex_unlock(&priv->mutex); return -ENOBUFS; } ath9k_htc_ps_wakeup(priv); memset(&hvif, 0, sizeof(struct ath9k_htc_target_vif)); memcpy(&hvif.myaddr, vif->addr, ETH_ALEN); switch (vif->type) { case NL80211_IFTYPE_STATION: hvif.opmode = HTC_M_STA; break; case NL80211_IFTYPE_ADHOC: hvif.opmode = HTC_M_IBSS; break; case NL80211_IFTYPE_AP: hvif.opmode = HTC_M_HOSTAP; break; default: ath_err(common, "Interface type %d not yet supported\n", vif->type); ret = -EOPNOTSUPP; goto out; } /* Index starts from zero on the target */ avp->index = hvif.index = ffz(priv->vif_slot); hvif.rtsthreshold = cpu_to_be16(2304); WMI_CMD_BUF(WMI_VAP_CREATE_CMDID, &hvif); if (ret) goto out; /* * We need a node in target to tx mgmt frames * before association. */ ret = ath9k_htc_add_station(priv, vif, NULL); if (ret) { WMI_CMD_BUF(WMI_VAP_REMOVE_CMDID, &hvif); goto out; } ath9k_htc_set_bssid_mask(priv, vif); priv->vif_slot |= (1 << avp->index); priv->nvifs++; INC_VIF(priv, vif->type); if ((vif->type == NL80211_IFTYPE_AP) || (vif->type == NL80211_IFTYPE_ADHOC)) ath9k_htc_assign_bslot(priv, vif); ath9k_htc_set_opmode(priv); if ((priv->ah->opmode == NL80211_IFTYPE_AP) && !(priv->op_flags & OP_ANI_RUNNING)) { ath9k_hw_set_tsfadjust(priv->ah, 1); ath9k_htc_start_ani(priv); } ath_dbg(common, ATH_DBG_CONFIG, "Attach a VIF of type: %d at idx: %d\n", vif->type, avp->index); out: ath9k_htc_ps_restore(priv); mutex_unlock(&priv->mutex); return ret; } static void ath9k_htc_remove_interface(struct ieee80211_hw *hw, struct ieee80211_vif *vif) { struct ath9k_htc_priv *priv = hw->priv; struct ath_common *common = ath9k_hw_common(priv->ah); struct ath9k_htc_vif *avp = (void *)vif->drv_priv; struct ath9k_htc_target_vif hvif; int ret = 0; u8 cmd_rsp; mutex_lock(&priv->mutex); ath9k_htc_ps_wakeup(priv); memset(&hvif, 0, sizeof(struct ath9k_htc_target_vif)); memcpy(&hvif.myaddr, vif->addr, ETH_ALEN); hvif.index = avp->index; WMI_CMD_BUF(WMI_VAP_REMOVE_CMDID, &hvif); if (ret) { ath_err(common, "Unable to remove interface at idx: %d\n", avp->index); } priv->nvifs--; priv->vif_slot &= ~(1 << avp->index); ath9k_htc_remove_station(priv, vif, NULL); DEC_VIF(priv, vif->type); if ((vif->type == NL80211_IFTYPE_AP) || (vif->type == NL80211_IFTYPE_ADHOC)) ath9k_htc_remove_bslot(priv, vif); ath9k_htc_set_opmode(priv); ath9k_htc_set_bssid_mask(priv, vif); /* * Stop ANI only if there are no associated station interfaces. */ if ((vif->type == NL80211_IFTYPE_AP) && (priv->num_ap_vif == 0)) { priv->rearm_ani = false; ieee80211_iterate_active_interfaces_atomic(priv->hw, ath9k_htc_vif_iter, priv); if (!priv->rearm_ani) ath9k_htc_stop_ani(priv); } ath_dbg(common, ATH_DBG_CONFIG, "Detach Interface at idx: %d\n", avp->index); ath9k_htc_ps_restore(priv); mutex_unlock(&priv->mutex); } static int ath9k_htc_config(struct ieee80211_hw *hw, u32 changed) { struct ath9k_htc_priv *priv = hw->priv; struct ath_common *common = ath9k_hw_common(priv->ah); struct ieee80211_conf *conf = &hw->conf; mutex_lock(&priv->mutex); if (changed & IEEE80211_CONF_CHANGE_IDLE) { bool enable_radio = false; bool idle = !!(conf->flags & IEEE80211_CONF_IDLE); mutex_lock(&priv->htc_pm_lock); if (!idle && priv->ps_idle) enable_radio = true; priv->ps_idle = idle; mutex_unlock(&priv->htc_pm_lock); if (enable_radio) { ath_dbg(common, ATH_DBG_CONFIG, "not-idle: enabling radio\n"); ath9k_htc_setpower(priv, ATH9K_PM_AWAKE); ath9k_htc_radio_enable(hw); } } /* * Monitor interface should be added before * IEEE80211_CONF_CHANGE_CHANNEL is handled. */ if (changed & IEEE80211_CONF_CHANGE_MONITOR) { if ((conf->flags & IEEE80211_CONF_MONITOR) && !priv->ah->is_monitoring) ath9k_htc_add_monitor_interface(priv); else if (priv->ah->is_monitoring) ath9k_htc_remove_monitor_interface(priv); } if (changed & IEEE80211_CONF_CHANGE_CHANNEL) { struct ieee80211_channel *curchan = hw->conf.channel; int pos = curchan->hw_value; ath_dbg(common, ATH_DBG_CONFIG, "Set channel: %d MHz\n", curchan->center_freq); ath9k_cmn_update_ichannel(&priv->ah->channels[pos], hw->conf.channel, hw->conf.channel_type); if (ath9k_htc_set_channel(priv, hw, &priv->ah->channels[pos]) < 0) { ath_err(common, "Unable to set channel\n"); mutex_unlock(&priv->mutex); return -EINVAL; } } if (changed & IEEE80211_CONF_CHANGE_PS) { if (conf->flags & IEEE80211_CONF_PS) { ath9k_htc_setpower(priv, ATH9K_PM_NETWORK_SLEEP); priv->ps_enabled = true; } else { priv->ps_enabled = false; cancel_work_sync(&priv->ps_work); ath9k_htc_setpower(priv, ATH9K_PM_AWAKE); } } if (changed & IEEE80211_CONF_CHANGE_POWER) { priv->txpowlimit = 2 * conf->power_level; ath9k_cmn_update_txpow(priv->ah, priv->curtxpow, priv->txpowlimit, &priv->curtxpow); } if (changed & IEEE80211_CONF_CHANGE_IDLE) { mutex_lock(&priv->htc_pm_lock); if (!priv->ps_idle) { mutex_unlock(&priv->htc_pm_lock); goto out; } mutex_unlock(&priv->htc_pm_lock); ath_dbg(common, ATH_DBG_CONFIG, "idle: disabling radio\n"); ath9k_htc_radio_disable(hw); } out: mutex_unlock(&priv->mutex); return 0; } #define SUPPORTED_FILTERS \ (FIF_PROMISC_IN_BSS | \ FIF_ALLMULTI | \ FIF_CONTROL | \ FIF_PSPOLL | \ FIF_OTHER_BSS | \ FIF_BCN_PRBRESP_PROMISC | \ FIF_PROBE_REQ | \ FIF_FCSFAIL) static void ath9k_htc_configure_filter(struct ieee80211_hw *hw, unsigned int changed_flags, unsigned int *total_flags, u64 multicast) { struct ath9k_htc_priv *priv = hw->priv; u32 rfilt; mutex_lock(&priv->mutex); ath9k_htc_ps_wakeup(priv); changed_flags &= SUPPORTED_FILTERS; *total_flags &= SUPPORTED_FILTERS; priv->rxfilter = *total_flags; rfilt = ath9k_htc_calcrxfilter(priv); ath9k_hw_setrxfilter(priv->ah, rfilt); ath_dbg(ath9k_hw_common(priv->ah), ATH_DBG_CONFIG, "Set HW RX filter: 0x%x\n", rfilt); ath9k_htc_ps_restore(priv); mutex_unlock(&priv->mutex); } static int ath9k_htc_sta_add(struct ieee80211_hw *hw, struct ieee80211_vif *vif, struct ieee80211_sta *sta) { struct ath9k_htc_priv *priv = hw->priv; int ret; mutex_lock(&priv->mutex); ath9k_htc_ps_wakeup(priv); ret = ath9k_htc_add_station(priv, vif, sta); if (!ret) ath9k_htc_init_rate(priv, sta); ath9k_htc_ps_restore(priv); mutex_unlock(&priv->mutex); return ret; } static int ath9k_htc_sta_remove(struct ieee80211_hw *hw, struct ieee80211_vif *vif, struct ieee80211_sta *sta) { struct ath9k_htc_priv *priv = hw->priv; struct ath9k_htc_sta *ista; int ret; mutex_lock(&priv->mutex); ath9k_htc_ps_wakeup(priv); ista = (struct ath9k_htc_sta *) sta->drv_priv; htc_sta_drain(priv->htc, ista->index); ret = ath9k_htc_remove_station(priv, vif, sta); ath9k_htc_ps_restore(priv); mutex_unlock(&priv->mutex); return ret; } static int ath9k_htc_conf_tx(struct ieee80211_hw *hw, u16 queue, const struct ieee80211_tx_queue_params *params) { struct ath9k_htc_priv *priv = hw->priv; struct ath_common *common = ath9k_hw_common(priv->ah); struct ath9k_tx_queue_info qi; int ret = 0, qnum; if (queue >= WME_NUM_AC) return 0; mutex_lock(&priv->mutex); ath9k_htc_ps_wakeup(priv); memset(&qi, 0, sizeof(struct ath9k_tx_queue_info)); qi.tqi_aifs = params->aifs; qi.tqi_cwmin = params->cw_min; qi.tqi_cwmax = params->cw_max; qi.tqi_burstTime = params->txop; qnum = get_hw_qnum(queue, priv->hwq_map); ath_dbg(common, ATH_DBG_CONFIG, "Configure tx [queue/hwq] [%d/%d], aifs: %d, cw_min: %d, cw_max: %d, txop: %d\n", queue, qnum, params->aifs, params->cw_min, params->cw_max, params->txop); ret = ath_htc_txq_update(priv, qnum, &qi); if (ret) { ath_err(common, "TXQ Update failed\n"); goto out; } if ((priv->ah->opmode == NL80211_IFTYPE_ADHOC) && (qnum == priv->hwq_map[WME_AC_BE])) ath9k_htc_beaconq_config(priv); out: ath9k_htc_ps_restore(priv); mutex_unlock(&priv->mutex); return ret; } static int ath9k_htc_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd, struct ieee80211_vif *vif, struct ieee80211_sta *sta, struct ieee80211_key_conf *key) { struct ath9k_htc_priv *priv = hw->priv; struct ath_common *common = ath9k_hw_common(priv->ah); int ret = 0; if (htc_modparam_nohwcrypt) return -ENOSPC; mutex_lock(&priv->mutex); ath_dbg(common, ATH_DBG_CONFIG, "Set HW Key\n"); ath9k_htc_ps_wakeup(priv); switch (cmd) { case SET_KEY: ret = ath_key_config(common, vif, sta, key); if (ret >= 0) { key->hw_key_idx = ret; /* push IV and Michael MIC generation to stack */ key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV; if (key->cipher == WLAN_CIPHER_SUITE_TKIP) key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC; if (priv->ah->sw_mgmt_crypto && key->cipher == WLAN_CIPHER_SUITE_CCMP) key->flags |= IEEE80211_KEY_FLAG_SW_MGMT; ret = 0; } break; case DISABLE_KEY: ath_key_delete(common, key); break; default: ret = -EINVAL; } ath9k_htc_ps_restore(priv); mutex_unlock(&priv->mutex); return ret; } static void ath9k_htc_set_bssid(struct ath9k_htc_priv *priv) { struct ath_common *common = ath9k_hw_common(priv->ah); ath9k_hw_write_associd(priv->ah); ath_dbg(common, ATH_DBG_CONFIG, "BSSID: %pM aid: 0x%x\n", common->curbssid, common->curaid); } static void ath9k_htc_bss_iter(void *data, u8 *mac, struct ieee80211_vif *vif) { struct ath9k_htc_priv *priv = (struct ath9k_htc_priv *)data; struct ath_common *common = ath9k_hw_common(priv->ah); struct ieee80211_bss_conf *bss_conf = &vif->bss_conf; if ((vif->type == NL80211_IFTYPE_STATION) && bss_conf->assoc) { common->curaid = bss_conf->aid; memcpy(common->curbssid, bss_conf->bssid, ETH_ALEN); } } static void ath9k_htc_choose_set_bssid(struct ath9k_htc_priv *priv) { if (priv->num_sta_assoc_vif == 1) { ieee80211_iterate_active_interfaces_atomic(priv->hw, ath9k_htc_bss_iter, priv); ath9k_htc_set_bssid(priv); } } static void ath9k_htc_bss_info_changed(struct ieee80211_hw *hw, struct ieee80211_vif *vif, struct ieee80211_bss_conf *bss_conf, u32 changed) { struct ath9k_htc_priv *priv = hw->priv; struct ath_hw *ah = priv->ah; struct ath_common *common = ath9k_hw_common(ah); mutex_lock(&priv->mutex); ath9k_htc_ps_wakeup(priv); if (changed & BSS_CHANGED_ASSOC) { ath_dbg(common, ATH_DBG_CONFIG, "BSS Changed ASSOC %d\n", bss_conf->assoc); bss_conf->assoc ? priv->num_sta_assoc_vif++ : priv->num_sta_assoc_vif--; if (priv->ah->opmode == NL80211_IFTYPE_STATION) { if (bss_conf->assoc && (priv->num_sta_assoc_vif == 1)) ath9k_htc_start_ani(priv); else if (priv->num_sta_assoc_vif == 0) ath9k_htc_stop_ani(priv); } } if (changed & BSS_CHANGED_BSSID) { if (priv->ah->opmode == NL80211_IFTYPE_ADHOC) { common->curaid = bss_conf->aid; memcpy(common->curbssid, bss_conf->bssid, ETH_ALEN); ath9k_htc_set_bssid(priv); } else if (priv->ah->opmode == NL80211_IFTYPE_STATION) { ath9k_htc_choose_set_bssid(priv); } } if ((changed & BSS_CHANGED_BEACON_ENABLED) && bss_conf->enable_beacon) { ath_dbg(common, ATH_DBG_CONFIG, "Beacon enabled for BSS: %pM\n", bss_conf->bssid); ath9k_htc_set_tsfadjust(priv, vif); priv->op_flags |= OP_ENABLE_BEACON; ath9k_htc_beacon_config(priv, vif); } if ((changed & BSS_CHANGED_BEACON_ENABLED) && !bss_conf->enable_beacon) { /* * Disable SWBA interrupt only if there are no * AP/IBSS interfaces. */ if ((priv->num_ap_vif <= 1) || priv->num_ibss_vif) { ath_dbg(common, ATH_DBG_CONFIG, "Beacon disabled for BSS: %pM\n", bss_conf->bssid); priv->op_flags &= ~OP_ENABLE_BEACON; ath9k_htc_beacon_config(priv, vif); } } if (changed & BSS_CHANGED_BEACON_INT) { /* * Reset the HW TSF for the first AP interface. */ if ((priv->ah->opmode == NL80211_IFTYPE_AP) && (priv->nvifs == 1) && (priv->num_ap_vif == 1) && (vif->type == NL80211_IFTYPE_AP)) { priv->op_flags |= OP_TSF_RESET; } ath_dbg(common, ATH_DBG_CONFIG, "Beacon interval changed for BSS: %pM\n", bss_conf->bssid); ath9k_htc_beacon_config(priv, vif); } if (changed & BSS_CHANGED_ERP_SLOT) { if (bss_conf->use_short_slot) ah->slottime = 9; else ah->slottime = 20; ath9k_hw_init_global_settings(ah); } if (changed & BSS_CHANGED_HT) ath9k_htc_update_rate(priv, vif, bss_conf); ath9k_htc_ps_restore(priv); mutex_unlock(&priv->mutex); } static u64 ath9k_htc_get_tsf(struct ieee80211_hw *hw) { struct ath9k_htc_priv *priv = hw->priv; u64 tsf; mutex_lock(&priv->mutex); ath9k_htc_ps_wakeup(priv); tsf = ath9k_hw_gettsf64(priv->ah); ath9k_htc_ps_restore(priv); mutex_unlock(&priv->mutex); return tsf; } static void ath9k_htc_set_tsf(struct ieee80211_hw *hw, u64 tsf) { struct ath9k_htc_priv *priv = hw->priv; mutex_lock(&priv->mutex); ath9k_htc_ps_wakeup(priv); ath9k_hw_settsf64(priv->ah, tsf); ath9k_htc_ps_restore(priv); mutex_unlock(&priv->mutex); } static void ath9k_htc_reset_tsf(struct ieee80211_hw *hw) { struct ath9k_htc_priv *priv = hw->priv; mutex_lock(&priv->mutex); ath9k_htc_ps_wakeup(priv); ath9k_hw_reset_tsf(priv->ah); ath9k_htc_ps_restore(priv); mutex_unlock(&priv->mutex); } static int ath9k_htc_ampdu_action(struct ieee80211_hw *hw, struct ieee80211_vif *vif, enum ieee80211_ampdu_mlme_action action, struct ieee80211_sta *sta, u16 tid, u16 *ssn, u8 buf_size) { struct ath9k_htc_priv *priv = hw->priv; struct ath9k_htc_sta *ista; int ret = 0; mutex_lock(&priv->mutex); ath9k_htc_ps_wakeup(priv); switch (action) { case IEEE80211_AMPDU_RX_START: break; case IEEE80211_AMPDU_RX_STOP: break; case IEEE80211_AMPDU_TX_START: ret = ath9k_htc_tx_aggr_oper(priv, vif, sta, action, tid); if (!ret) ieee80211_start_tx_ba_cb_irqsafe(vif, sta->addr, tid); break; case IEEE80211_AMPDU_TX_STOP: ath9k_htc_tx_aggr_oper(priv, vif, sta, action, tid); ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid); break; case IEEE80211_AMPDU_TX_OPERATIONAL: ista = (struct ath9k_htc_sta *) sta->drv_priv; spin_lock_bh(&priv->tx.tx_lock); ista->tid_state[tid] = AGGR_OPERATIONAL; spin_unlock_bh(&priv->tx.tx_lock); break; default: ath_err(ath9k_hw_common(priv->ah), "Unknown AMPDU action\n"); } ath9k_htc_ps_restore(priv); mutex_unlock(&priv->mutex); return ret; } static void ath9k_htc_sw_scan_start(struct ieee80211_hw *hw) { struct ath9k_htc_priv *priv = hw->priv; mutex_lock(&priv->mutex); spin_lock_bh(&priv->beacon_lock); priv->op_flags |= OP_SCANNING; spin_unlock_bh(&priv->beacon_lock); cancel_work_sync(&priv->ps_work); ath9k_htc_stop_ani(priv); mutex_unlock(&priv->mutex); } static void ath9k_htc_sw_scan_complete(struct ieee80211_hw *hw) { struct ath9k_htc_priv *priv = hw->priv; mutex_lock(&priv->mutex); spin_lock_bh(&priv->beacon_lock); priv->op_flags &= ~OP_SCANNING; spin_unlock_bh(&priv->beacon_lock); ath9k_htc_ps_wakeup(priv); ath9k_htc_vif_reconfig(priv); ath9k_htc_ps_restore(priv); mutex_unlock(&priv->mutex); } static int ath9k_htc_set_rts_threshold(struct ieee80211_hw *hw, u32 value) { return 0; } static void ath9k_htc_set_coverage_class(struct ieee80211_hw *hw, u8 coverage_class) { struct ath9k_htc_priv *priv = hw->priv; mutex_lock(&priv->mutex); ath9k_htc_ps_wakeup(priv); priv->ah->coverage_class = coverage_class; ath9k_hw_init_global_settings(priv->ah); ath9k_htc_ps_restore(priv); mutex_unlock(&priv->mutex); } /* * Currently, this is used only for selecting the minimum rate * for management frames, rate selection for data frames remain * unaffected. */ static int ath9k_htc_set_bitrate_mask(struct ieee80211_hw *hw, struct ieee80211_vif *vif, const struct cfg80211_bitrate_mask *mask) { struct ath9k_htc_priv *priv = hw->priv; struct ath_common *common = ath9k_hw_common(priv->ah); struct ath9k_htc_target_rate_mask tmask; struct ath9k_htc_vif *avp = (void *)vif->drv_priv; int ret = 0; u8 cmd_rsp; memset(&tmask, 0, sizeof(struct ath9k_htc_target_rate_mask)); tmask.vif_index = avp->index; tmask.band = IEEE80211_BAND_2GHZ; tmask.mask = cpu_to_be32(mask->control[IEEE80211_BAND_2GHZ].legacy); WMI_CMD_BUF(WMI_BITRATE_MASK_CMDID, &tmask); if (ret) { ath_err(common, "Unable to set 2G rate mask for " "interface at idx: %d\n", avp->index); goto out; } tmask.band = IEEE80211_BAND_5GHZ; tmask.mask = cpu_to_be32(mask->control[IEEE80211_BAND_5GHZ].legacy); WMI_CMD_BUF(WMI_BITRATE_MASK_CMDID, &tmask); if (ret) { ath_err(common, "Unable to set 5G rate mask for " "interface at idx: %d\n", avp->index); goto out; } ath_dbg(common, ATH_DBG_CONFIG, "Set bitrate masks: 0x%x, 0x%x\n", mask->control[IEEE80211_BAND_2GHZ].legacy, mask->control[IEEE80211_BAND_5GHZ].legacy); out: return ret; } struct ieee80211_ops ath9k_htc_ops = { .tx = ath9k_htc_tx, .start = ath9k_htc_start, .stop = ath9k_htc_stop, .add_interface = ath9k_htc_add_interface, .remove_interface = ath9k_htc_remove_interface, .config = ath9k_htc_config, .configure_filter = ath9k_htc_configure_filter, .sta_add = ath9k_htc_sta_add, .sta_remove = ath9k_htc_sta_remove, .conf_tx = ath9k_htc_conf_tx, .bss_info_changed = ath9k_htc_bss_info_changed, .set_key = ath9k_htc_set_key, .get_tsf = ath9k_htc_get_tsf, .set_tsf = ath9k_htc_set_tsf, .reset_tsf = ath9k_htc_reset_tsf, .ampdu_action = ath9k_htc_ampdu_action, .sw_scan_start = ath9k_htc_sw_scan_start, .sw_scan_complete = ath9k_htc_sw_scan_complete, .set_rts_threshold = ath9k_htc_set_rts_threshold, .rfkill_poll = ath9k_htc_rfkill_poll_state, .set_coverage_class = ath9k_htc_set_coverage_class, .set_bitrate_mask = ath9k_htc_set_bitrate_mask, };
gpl-2.0
DecimalMan/dkp-tw
arch/arm/mach-realview/realview_pb11mp.c
2321
10759
/* * linux/arch/arm/mach-realview/realview_pb11mp.c * * Copyright (C) 2008 ARM Limited * Copyright (C) 2000 Deep Blue Solutions Ltd * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include <linux/init.h> #include <linux/platform_device.h> #include <linux/sysdev.h> #include <linux/amba/bus.h> #include <linux/amba/pl061.h> #include <linux/amba/mmci.h> #include <linux/amba/pl022.h> #include <linux/io.h> #include <mach/hardware.h> #include <asm/irq.h> #include <asm/leds.h> #include <asm/mach-types.h> #include <asm/pmu.h> #include <asm/pgtable.h> #include <asm/hardware/gic.h> #include <asm/hardware/cache-l2x0.h> #include <asm/localtimer.h> #include <asm/mach/arch.h> #include <asm/mach/flash.h> #include <asm/mach/map.h> #include <asm/mach/time.h> #include <mach/board-pb11mp.h> #include <mach/irqs.h> #include "core.h" static struct map_desc realview_pb11mp_io_desc[] __initdata = { { .virtual = IO_ADDRESS(REALVIEW_SYS_BASE), .pfn = __phys_to_pfn(REALVIEW_SYS_BASE), .length = SZ_4K, .type = MT_DEVICE, }, { .virtual = IO_ADDRESS(REALVIEW_PB11MP_GIC_CPU_BASE), .pfn = __phys_to_pfn(REALVIEW_PB11MP_GIC_CPU_BASE), .length = SZ_4K, .type = MT_DEVICE, }, { .virtual = IO_ADDRESS(REALVIEW_PB11MP_GIC_DIST_BASE), .pfn = __phys_to_pfn(REALVIEW_PB11MP_GIC_DIST_BASE), .length = SZ_4K, .type = MT_DEVICE, }, { .virtual = IO_ADDRESS(REALVIEW_TC11MP_GIC_CPU_BASE), .pfn = __phys_to_pfn(REALVIEW_TC11MP_GIC_CPU_BASE), .length = SZ_4K, .type = MT_DEVICE, }, { .virtual = IO_ADDRESS(REALVIEW_TC11MP_GIC_DIST_BASE), .pfn = __phys_to_pfn(REALVIEW_TC11MP_GIC_DIST_BASE), .length = SZ_4K, .type = MT_DEVICE, }, { .virtual = IO_ADDRESS(REALVIEW_SCTL_BASE), .pfn = __phys_to_pfn(REALVIEW_SCTL_BASE), .length = SZ_4K, .type = MT_DEVICE, }, { .virtual = IO_ADDRESS(REALVIEW_PB11MP_TIMER0_1_BASE), .pfn = __phys_to_pfn(REALVIEW_PB11MP_TIMER0_1_BASE), .length = SZ_4K, .type = MT_DEVICE, }, { .virtual = IO_ADDRESS(REALVIEW_PB11MP_TIMER2_3_BASE), .pfn = __phys_to_pfn(REALVIEW_PB11MP_TIMER2_3_BASE), .length = SZ_4K, .type = MT_DEVICE, }, { .virtual = IO_ADDRESS(REALVIEW_TC11MP_L220_BASE), .pfn = __phys_to_pfn(REALVIEW_TC11MP_L220_BASE), .length = SZ_8K, .type = MT_DEVICE, }, #ifdef CONFIG_DEBUG_LL { .virtual = IO_ADDRESS(REALVIEW_PB11MP_UART0_BASE), .pfn = __phys_to_pfn(REALVIEW_PB11MP_UART0_BASE), .length = SZ_4K, .type = MT_DEVICE, }, #endif }; static void __init realview_pb11mp_map_io(void) { iotable_init(realview_pb11mp_io_desc, ARRAY_SIZE(realview_pb11mp_io_desc)); } static struct pl061_platform_data gpio0_plat_data = { .gpio_base = 0, .irq_base = -1, }; static struct pl061_platform_data gpio1_plat_data = { .gpio_base = 8, .irq_base = -1, }; static struct pl061_platform_data gpio2_plat_data = { .gpio_base = 16, .irq_base = -1, }; static struct pl022_ssp_controller ssp0_plat_data = { .bus_id = 0, .enable_dma = 0, .num_chipselect = 1, }; /* * RealView PB11MPCore AMBA devices */ #define GPIO2_IRQ { IRQ_PB11MP_GPIO2, NO_IRQ } #define GPIO3_IRQ { IRQ_PB11MP_GPIO3, NO_IRQ } #define AACI_IRQ { IRQ_TC11MP_AACI, NO_IRQ } #define MMCI0_IRQ { IRQ_TC11MP_MMCI0A, IRQ_TC11MP_MMCI0B } #define KMI0_IRQ { IRQ_TC11MP_KMI0, NO_IRQ } #define KMI1_IRQ { IRQ_TC11MP_KMI1, NO_IRQ } #define PB11MP_SMC_IRQ { NO_IRQ, NO_IRQ } #define MPMC_IRQ { NO_IRQ, NO_IRQ } #define PB11MP_CLCD_IRQ { IRQ_PB11MP_CLCD, NO_IRQ } #define DMAC_IRQ { IRQ_PB11MP_DMAC, NO_IRQ } #define SCTL_IRQ { NO_IRQ, NO_IRQ } #define PB11MP_WATCHDOG_IRQ { IRQ_PB11MP_WATCHDOG, NO_IRQ } #define PB11MP_GPIO0_IRQ { IRQ_PB11MP_GPIO0, NO_IRQ } #define GPIO1_IRQ { IRQ_PB11MP_GPIO1, NO_IRQ } #define PB11MP_RTC_IRQ { IRQ_TC11MP_RTC, NO_IRQ } #define SCI_IRQ { IRQ_PB11MP_SCI, NO_IRQ } #define PB11MP_UART0_IRQ { IRQ_TC11MP_UART0, NO_IRQ } #define PB11MP_UART1_IRQ { IRQ_TC11MP_UART1, NO_IRQ } #define PB11MP_UART2_IRQ { IRQ_PB11MP_UART2, NO_IRQ } #define PB11MP_UART3_IRQ { IRQ_PB11MP_UART3, NO_IRQ } #define PB11MP_SSP_IRQ { IRQ_PB11MP_SSP, NO_IRQ } /* FPGA Primecells */ AMBA_DEVICE(aaci, "fpga:aaci", AACI, NULL); AMBA_DEVICE(mmc0, "fpga:mmc0", MMCI0, &realview_mmc0_plat_data); AMBA_DEVICE(kmi0, "fpga:kmi0", KMI0, NULL); AMBA_DEVICE(kmi1, "fpga:kmi1", KMI1, NULL); AMBA_DEVICE(uart3, "fpga:uart3", PB11MP_UART3, NULL); /* DevChip Primecells */ AMBA_DEVICE(smc, "dev:smc", PB11MP_SMC, NULL); AMBA_DEVICE(sctl, "dev:sctl", SCTL, NULL); AMBA_DEVICE(wdog, "dev:wdog", PB11MP_WATCHDOG, NULL); AMBA_DEVICE(gpio0, "dev:gpio0", PB11MP_GPIO0, &gpio0_plat_data); AMBA_DEVICE(gpio1, "dev:gpio1", GPIO1, &gpio1_plat_data); AMBA_DEVICE(gpio2, "dev:gpio2", GPIO2, &gpio2_plat_data); AMBA_DEVICE(rtc, "dev:rtc", PB11MP_RTC, NULL); AMBA_DEVICE(sci0, "dev:sci0", SCI, NULL); AMBA_DEVICE(uart0, "dev:uart0", PB11MP_UART0, NULL); AMBA_DEVICE(uart1, "dev:uart1", PB11MP_UART1, NULL); AMBA_DEVICE(uart2, "dev:uart2", PB11MP_UART2, NULL); AMBA_DEVICE(ssp0, "dev:ssp0", PB11MP_SSP, &ssp0_plat_data); /* Primecells on the NEC ISSP chip */ AMBA_DEVICE(clcd, "issp:clcd", PB11MP_CLCD, &clcd_plat_data); AMBA_DEVICE(dmac, "issp:dmac", DMAC, NULL); static struct amba_device *amba_devs[] __initdata = { &dmac_device, &uart0_device, &uart1_device, &uart2_device, &uart3_device, &smc_device, &clcd_device, &sctl_device, &wdog_device, &gpio0_device, &gpio1_device, &gpio2_device, &rtc_device, &sci0_device, &ssp0_device, &aaci_device, &mmc0_device, &kmi0_device, &kmi1_device, }; /* * RealView PB11MPCore platform devices */ static struct resource realview_pb11mp_flash_resource[] = { [0] = { .start = REALVIEW_PB11MP_FLASH0_BASE, .end = REALVIEW_PB11MP_FLASH0_BASE + REALVIEW_PB11MP_FLASH0_SIZE - 1, .flags = IORESOURCE_MEM, }, [1] = { .start = REALVIEW_PB11MP_FLASH1_BASE, .end = REALVIEW_PB11MP_FLASH1_BASE + REALVIEW_PB11MP_FLASH1_SIZE - 1, .flags = IORESOURCE_MEM, }, }; static struct resource realview_pb11mp_smsc911x_resources[] = { [0] = { .start = REALVIEW_PB11MP_ETH_BASE, .end = REALVIEW_PB11MP_ETH_BASE + SZ_64K - 1, .flags = IORESOURCE_MEM, }, [1] = { .start = IRQ_TC11MP_ETH, .end = IRQ_TC11MP_ETH, .flags = IORESOURCE_IRQ, }, }; static struct resource realview_pb11mp_isp1761_resources[] = { [0] = { .start = REALVIEW_PB11MP_USB_BASE, .end = REALVIEW_PB11MP_USB_BASE + SZ_128K - 1, .flags = IORESOURCE_MEM, }, [1] = { .start = IRQ_TC11MP_USB, .end = IRQ_TC11MP_USB, .flags = IORESOURCE_IRQ, }, }; static struct resource pmu_resources[] = { [0] = { .start = IRQ_TC11MP_PMU_CPU0, .end = IRQ_TC11MP_PMU_CPU0, .flags = IORESOURCE_IRQ, }, [1] = { .start = IRQ_TC11MP_PMU_CPU1, .end = IRQ_TC11MP_PMU_CPU1, .flags = IORESOURCE_IRQ, }, [2] = { .start = IRQ_TC11MP_PMU_CPU2, .end = IRQ_TC11MP_PMU_CPU2, .flags = IORESOURCE_IRQ, }, [3] = { .start = IRQ_TC11MP_PMU_CPU3, .end = IRQ_TC11MP_PMU_CPU3, .flags = IORESOURCE_IRQ, }, }; static struct platform_device pmu_device = { .name = "arm-pmu", .id = ARM_PMU_DEVICE_CPU, .num_resources = ARRAY_SIZE(pmu_resources), .resource = pmu_resources, }; static void __init gic_init_irq(void) { unsigned int pldctrl; /* new irq mode with no DCC */ writel(0x0000a05f, __io_address(REALVIEW_SYS_LOCK)); pldctrl = readl(__io_address(REALVIEW_SYS_BASE) + REALVIEW_PB11MP_SYS_PLD_CTRL1); pldctrl |= 2 << 22; writel(pldctrl, __io_address(REALVIEW_SYS_BASE) + REALVIEW_PB11MP_SYS_PLD_CTRL1); writel(0x00000000, __io_address(REALVIEW_SYS_LOCK)); /* ARM11MPCore test chip GIC, primary */ gic_init(0, 29, __io_address(REALVIEW_TC11MP_GIC_DIST_BASE), __io_address(REALVIEW_TC11MP_GIC_CPU_BASE)); /* board GIC, secondary */ gic_init(1, IRQ_PB11MP_GIC_START, __io_address(REALVIEW_PB11MP_GIC_DIST_BASE), __io_address(REALVIEW_PB11MP_GIC_CPU_BASE)); gic_cascade_irq(1, IRQ_TC11MP_PB_IRQ1); } static void __init realview_pb11mp_timer_init(void) { timer0_va_base = __io_address(REALVIEW_PB11MP_TIMER0_1_BASE); timer1_va_base = __io_address(REALVIEW_PB11MP_TIMER0_1_BASE) + 0x20; timer2_va_base = __io_address(REALVIEW_PB11MP_TIMER2_3_BASE); timer3_va_base = __io_address(REALVIEW_PB11MP_TIMER2_3_BASE) + 0x20; #ifdef CONFIG_LOCAL_TIMERS twd_base = __io_address(REALVIEW_TC11MP_TWD_BASE); #endif realview_timer_init(IRQ_TC11MP_TIMER0_1); } static struct sys_timer realview_pb11mp_timer = { .init = realview_pb11mp_timer_init, }; static void realview_pb11mp_reset(char mode) { void __iomem *reset_ctrl = __io_address(REALVIEW_SYS_RESETCTL); void __iomem *lock_ctrl = __io_address(REALVIEW_SYS_LOCK); /* * To reset, we hit the on-board reset register * in the system FPGA */ __raw_writel(REALVIEW_SYS_LOCK_VAL, lock_ctrl); __raw_writel(0x0000, reset_ctrl); __raw_writel(0x0004, reset_ctrl); } static void __init realview_pb11mp_init(void) { int i; #ifdef CONFIG_CACHE_L2X0 /* 1MB (128KB/way), 8-way associativity, evmon/parity/share enabled * Bits: .... ...0 0111 1001 0000 .... .... .... */ l2x0_init(__io_address(REALVIEW_TC11MP_L220_BASE), 0x00790000, 0xfe000fff); #endif realview_flash_register(realview_pb11mp_flash_resource, ARRAY_SIZE(realview_pb11mp_flash_resource)); realview_eth_register(NULL, realview_pb11mp_smsc911x_resources); platform_device_register(&realview_i2c_device); platform_device_register(&realview_cf_device); realview_usb_register(realview_pb11mp_isp1761_resources); platform_device_register(&pmu_device); for (i = 0; i < ARRAY_SIZE(amba_devs); i++) { struct amba_device *d = amba_devs[i]; amba_device_register(d, &iomem_resource); } #ifdef CONFIG_LEDS leds_event = realview_leds_event; #endif realview_reset = realview_pb11mp_reset; } MACHINE_START(REALVIEW_PB11MP, "ARM-RealView PB11MPCore") /* Maintainer: ARM Ltd/Deep Blue Solutions Ltd */ .boot_params = PLAT_PHYS_OFFSET + 0x00000100, .fixup = realview_fixup, .map_io = realview_pb11mp_map_io, .init_early = realview_init_early, .init_irq = gic_init_irq, .timer = &realview_pb11mp_timer, .init_machine = realview_pb11mp_init, MACHINE_END
gpl-2.0
SomeshThakur/Xeon-Kernel
arch/arm/mach-shmobile/intc-sh7372.c
2833
23866
/* * sh7372 processor support - INTC hardware block * * Copyright (C) 2010 Magnus Damm * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; version 2 of the License. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ #include <linux/kernel.h> #include <linux/init.h> #include <linux/interrupt.h> #include <linux/module.h> #include <linux/irq.h> #include <linux/io.h> #include <linux/sh_intc.h> #include <mach/intc.h> #include <mach/irqs.h> #include <asm/mach-types.h> #include <asm/mach/arch.h> enum { UNUSED_INTCA = 0, /* interrupt sources INTCA */ DIRC, CRYPT_STD, IIC1_ALI1, IIC1_TACKI1, IIC1_WAITI1, IIC1_DTEI1, AP_ARM_IRQPMU, AP_ARM_COMMTX, AP_ARM_COMMRX, MFI_MFIM, MFI_MFIS, BBIF1, BBIF2, USBHSDMAC0_USHDMI, _3DG_SGX540, CMT1_CMT10, CMT1_CMT11, CMT1_CMT12, CMT1_CMT13, CMT2, CMT3, KEYSC_KEY, SCIFA0, SCIFA1, SCIFA2, SCIFA3, MSIOF2, MSIOF1, SCIFA4, SCIFA5, SCIFB, FLCTL_FLSTEI, FLCTL_FLTENDI, FLCTL_FLTREQ0I, FLCTL_FLTREQ1I, SDHI0_SDHI0I0, SDHI0_SDHI0I1, SDHI0_SDHI0I2, SDHI0_SDHI0I3, SDHI1_SDHI1I0, SDHI1_SDHI1I1, SDHI1_SDHI1I2, IRREM, IRDA, TPU0, TTI20, DDM, SDHI2_SDHI2I0, SDHI2_SDHI2I1, SDHI2_SDHI2I2, SDHI2_SDHI2I3, RWDT0, DMAC1_1_DEI0, DMAC1_1_DEI1, DMAC1_1_DEI2, DMAC1_1_DEI3, DMAC1_2_DEI4, DMAC1_2_DEI5, DMAC1_2_DADERR, DMAC2_1_DEI0, DMAC2_1_DEI1, DMAC2_1_DEI2, DMAC2_1_DEI3, DMAC2_2_DEI4, DMAC2_2_DEI5, DMAC2_2_DADERR, DMAC3_1_DEI0, DMAC3_1_DEI1, DMAC3_1_DEI2, DMAC3_1_DEI3, DMAC3_2_DEI4, DMAC3_2_DEI5, DMAC3_2_DADERR, SHWYSTAT_RT, SHWYSTAT_HS, SHWYSTAT_COM, HDMI, SPU2_SPU0, SPU2_SPU1, FSI, FMSI, MIPI_HSI, IPMMU_IPMMUD, CEC_1, CEC_2, AP_ARM_CTIIRQ, AP_ARM_DMAEXTERRIRQ, AP_ARM_DMAIRQ, AP_ARM_DMASIRQ, MFIS2, CPORTR2S, CMT14, CMT15, MMC_MMC_ERR, MMC_MMC_NOR, IIC4_ALI4, IIC4_TACKI4, IIC4_WAITI4, IIC4_DTEI4, IIC3_ALI3, IIC3_TACKI3, IIC3_WAITI3, IIC3_DTEI3, USB0_USB0I1, USB0_USB0I0, USB1_USB1I1, USB1_USB1I0, USBHSDMAC1_USHDMI, /* interrupt groups INTCA */ DMAC1_1, DMAC1_2, DMAC2_1, DMAC2_2, DMAC3_1, DMAC3_2, SHWYSTAT, AP_ARM1, AP_ARM2, SPU2, FLCTL, IIC1, SDHI0, SDHI1, SDHI2 }; static struct intc_vect intca_vectors[] __initdata = { INTC_VECT(DIRC, 0x0560), INTC_VECT(CRYPT_STD, 0x0700), INTC_VECT(IIC1_ALI1, 0x0780), INTC_VECT(IIC1_TACKI1, 0x07a0), INTC_VECT(IIC1_WAITI1, 0x07c0), INTC_VECT(IIC1_DTEI1, 0x07e0), INTC_VECT(AP_ARM_IRQPMU, 0x0800), INTC_VECT(AP_ARM_COMMTX, 0x0840), INTC_VECT(AP_ARM_COMMRX, 0x0860), INTC_VECT(MFI_MFIM, 0x0900), INTC_VECT(MFI_MFIS, 0x0920), INTC_VECT(BBIF1, 0x0940), INTC_VECT(BBIF2, 0x0960), INTC_VECT(USBHSDMAC0_USHDMI, 0x0a00), INTC_VECT(_3DG_SGX540, 0x0a60), INTC_VECT(CMT1_CMT10, 0x0b00), INTC_VECT(CMT1_CMT11, 0x0b20), INTC_VECT(CMT1_CMT12, 0x0b40), INTC_VECT(CMT1_CMT13, 0x0b60), INTC_VECT(CMT2, 0x0b80), INTC_VECT(CMT3, 0x0ba0), INTC_VECT(KEYSC_KEY, 0x0be0), INTC_VECT(SCIFA0, 0x0c00), INTC_VECT(SCIFA1, 0x0c20), INTC_VECT(SCIFA2, 0x0c40), INTC_VECT(SCIFA3, 0x0c60), INTC_VECT(MSIOF2, 0x0c80), INTC_VECT(MSIOF1, 0x0d00), INTC_VECT(SCIFA4, 0x0d20), INTC_VECT(SCIFA5, 0x0d40), INTC_VECT(SCIFB, 0x0d60), INTC_VECT(FLCTL_FLSTEI, 0x0d80), INTC_VECT(FLCTL_FLTENDI, 0x0da0), INTC_VECT(FLCTL_FLTREQ0I, 0x0dc0), INTC_VECT(FLCTL_FLTREQ1I, 0x0de0), INTC_VECT(SDHI0_SDHI0I0, 0x0e00), INTC_VECT(SDHI0_SDHI0I1, 0x0e20), INTC_VECT(SDHI0_SDHI0I2, 0x0e40), INTC_VECT(SDHI0_SDHI0I3, 0x0e60), INTC_VECT(SDHI1_SDHI1I0, 0x0e80), INTC_VECT(SDHI1_SDHI1I1, 0x0ea0), INTC_VECT(SDHI1_SDHI1I2, 0x0ec0), INTC_VECT(IRREM, 0x0f60), INTC_VECT(IRDA, 0x0480), INTC_VECT(TPU0, 0x04a0), INTC_VECT(TTI20, 0x1100), INTC_VECT(DDM, 0x1140), INTC_VECT(SDHI2_SDHI2I0, 0x1200), INTC_VECT(SDHI2_SDHI2I1, 0x1220), INTC_VECT(SDHI2_SDHI2I2, 0x1240), INTC_VECT(SDHI2_SDHI2I3, 0x1260), INTC_VECT(RWDT0, 0x1280), INTC_VECT(DMAC1_1_DEI0, 0x2000), INTC_VECT(DMAC1_1_DEI1, 0x2020), INTC_VECT(DMAC1_1_DEI2, 0x2040), INTC_VECT(DMAC1_1_DEI3, 0x2060), INTC_VECT(DMAC1_2_DEI4, 0x2080), INTC_VECT(DMAC1_2_DEI5, 0x20a0), INTC_VECT(DMAC1_2_DADERR, 0x20c0), INTC_VECT(DMAC2_1_DEI0, 0x2100), INTC_VECT(DMAC2_1_DEI1, 0x2120), INTC_VECT(DMAC2_1_DEI2, 0x2140), INTC_VECT(DMAC2_1_DEI3, 0x2160), INTC_VECT(DMAC2_2_DEI4, 0x2180), INTC_VECT(DMAC2_2_DEI5, 0x21a0), INTC_VECT(DMAC2_2_DADERR, 0x21c0), INTC_VECT(DMAC3_1_DEI0, 0x2200), INTC_VECT(DMAC3_1_DEI1, 0x2220), INTC_VECT(DMAC3_1_DEI2, 0x2240), INTC_VECT(DMAC3_1_DEI3, 0x2260), INTC_VECT(DMAC3_2_DEI4, 0x2280), INTC_VECT(DMAC3_2_DEI5, 0x22a0), INTC_VECT(DMAC3_2_DADERR, 0x22c0), INTC_VECT(SHWYSTAT_RT, 0x1300), INTC_VECT(SHWYSTAT_HS, 0x1320), INTC_VECT(SHWYSTAT_COM, 0x1340), INTC_VECT(HDMI, 0x17e0), INTC_VECT(SPU2_SPU0, 0x1800), INTC_VECT(SPU2_SPU1, 0x1820), INTC_VECT(FSI, 0x1840), INTC_VECT(FMSI, 0x1860), INTC_VECT(MIPI_HSI, 0x18e0), INTC_VECT(IPMMU_IPMMUD, 0x1920), INTC_VECT(CEC_1, 0x1940), INTC_VECT(CEC_2, 0x1960), INTC_VECT(AP_ARM_CTIIRQ, 0x1980), INTC_VECT(AP_ARM_DMAEXTERRIRQ, 0x19a0), INTC_VECT(AP_ARM_DMAIRQ, 0x19c0), INTC_VECT(AP_ARM_DMASIRQ, 0x19e0), INTC_VECT(MFIS2, 0x1a00), INTC_VECT(CPORTR2S, 0x1a20), INTC_VECT(CMT14, 0x1a40), INTC_VECT(CMT15, 0x1a60), INTC_VECT(MMC_MMC_ERR, 0x1ac0), INTC_VECT(MMC_MMC_NOR, 0x1ae0), INTC_VECT(IIC4_ALI4, 0x1b00), INTC_VECT(IIC4_TACKI4, 0x1b20), INTC_VECT(IIC4_WAITI4, 0x1b40), INTC_VECT(IIC4_DTEI4, 0x1b60), INTC_VECT(IIC3_ALI3, 0x1b80), INTC_VECT(IIC3_TACKI3, 0x1ba0), INTC_VECT(IIC3_WAITI3, 0x1bc0), INTC_VECT(IIC3_DTEI3, 0x1be0), INTC_VECT(USB0_USB0I1, 0x1c80), INTC_VECT(USB0_USB0I0, 0x1ca0), INTC_VECT(USB1_USB1I1, 0x1cc0), INTC_VECT(USB1_USB1I0, 0x1ce0), INTC_VECT(USBHSDMAC1_USHDMI, 0x1d00), }; static struct intc_group intca_groups[] __initdata = { INTC_GROUP(DMAC1_1, DMAC1_1_DEI0, DMAC1_1_DEI1, DMAC1_1_DEI2, DMAC1_1_DEI3), INTC_GROUP(DMAC1_2, DMAC1_2_DEI4, DMAC1_2_DEI5, DMAC1_2_DADERR), INTC_GROUP(DMAC2_1, DMAC2_1_DEI0, DMAC2_1_DEI1, DMAC2_1_DEI2, DMAC2_1_DEI3), INTC_GROUP(DMAC2_2, DMAC2_2_DEI4, DMAC2_2_DEI5, DMAC2_2_DADERR), INTC_GROUP(DMAC3_1, DMAC3_1_DEI0, DMAC3_1_DEI1, DMAC3_1_DEI2, DMAC3_1_DEI3), INTC_GROUP(DMAC3_2, DMAC3_2_DEI4, DMAC3_2_DEI5, DMAC3_2_DADERR), INTC_GROUP(AP_ARM1, AP_ARM_IRQPMU, AP_ARM_COMMTX, AP_ARM_COMMRX), INTC_GROUP(AP_ARM2, AP_ARM_CTIIRQ, AP_ARM_DMAEXTERRIRQ, AP_ARM_DMAIRQ, AP_ARM_DMASIRQ), INTC_GROUP(SPU2, SPU2_SPU0, SPU2_SPU1), INTC_GROUP(FLCTL, FLCTL_FLSTEI, FLCTL_FLTENDI, FLCTL_FLTREQ0I, FLCTL_FLTREQ1I), INTC_GROUP(IIC1, IIC1_ALI1, IIC1_TACKI1, IIC1_WAITI1, IIC1_DTEI1), INTC_GROUP(SDHI0, SDHI0_SDHI0I0, SDHI0_SDHI0I1, SDHI0_SDHI0I2, SDHI0_SDHI0I3), INTC_GROUP(SDHI1, SDHI1_SDHI1I0, SDHI1_SDHI1I1, SDHI1_SDHI1I2), INTC_GROUP(SDHI2, SDHI2_SDHI2I0, SDHI2_SDHI2I1, SDHI2_SDHI2I2, SDHI2_SDHI2I3), INTC_GROUP(SHWYSTAT, SHWYSTAT_RT, SHWYSTAT_HS, SHWYSTAT_COM), }; static struct intc_mask_reg intca_mask_registers[] __initdata = { { 0xe6940080, 0xe69400c0, 8, /* IMR0A / IMCR0A */ { DMAC2_1_DEI3, DMAC2_1_DEI2, DMAC2_1_DEI1, DMAC2_1_DEI0, AP_ARM_IRQPMU, 0, AP_ARM_COMMTX, AP_ARM_COMMRX } }, { 0xe6940084, 0xe69400c4, 8, /* IMR1A / IMCR1A */ { 0, CRYPT_STD, DIRC, 0, DMAC1_1_DEI3, DMAC1_1_DEI2, DMAC1_1_DEI1, DMAC1_1_DEI0 } }, { 0xe6940088, 0xe69400c8, 8, /* IMR2A / IMCR2A */ { 0, 0, 0, 0, BBIF1, BBIF2, MFI_MFIS, MFI_MFIM } }, { 0xe694008c, 0xe69400cc, 8, /* IMR3A / IMCR3A */ { DMAC3_1_DEI3, DMAC3_1_DEI2, DMAC3_1_DEI1, DMAC3_1_DEI0, DMAC3_2_DADERR, DMAC3_2_DEI5, DMAC3_2_DEI4, IRDA } }, { 0xe6940090, 0xe69400d0, 8, /* IMR4A / IMCR4A */ { DDM, 0, 0, 0, 0, 0, 0, 0 } }, { 0xe6940094, 0xe69400d4, 8, /* IMR5A / IMCR5A */ { KEYSC_KEY, DMAC1_2_DADERR, DMAC1_2_DEI5, DMAC1_2_DEI4, SCIFA3, SCIFA2, SCIFA1, SCIFA0 } }, { 0xe6940098, 0xe69400d8, 8, /* IMR6A / IMCR6A */ { SCIFB, SCIFA5, SCIFA4, MSIOF1, 0, 0, MSIOF2, 0 } }, { 0xe694009c, 0xe69400dc, 8, /* IMR7A / IMCR7A */ { SDHI0_SDHI0I3, SDHI0_SDHI0I2, SDHI0_SDHI0I1, SDHI0_SDHI0I0, FLCTL_FLTREQ1I, FLCTL_FLTREQ0I, FLCTL_FLTENDI, FLCTL_FLSTEI } }, { 0xe69400a0, 0xe69400e0, 8, /* IMR8A / IMCR8A */ { 0, SDHI1_SDHI1I2, SDHI1_SDHI1I1, SDHI1_SDHI1I0, TTI20, USBHSDMAC0_USHDMI, 0, 0 } }, { 0xe69400a4, 0xe69400e4, 8, /* IMR9A / IMCR9A */ { CMT1_CMT13, CMT1_CMT12, CMT1_CMT11, CMT1_CMT10, CMT2, 0, 0, _3DG_SGX540 } }, { 0xe69400a8, 0xe69400e8, 8, /* IMR10A / IMCR10A */ { 0, DMAC2_2_DADERR, DMAC2_2_DEI5, DMAC2_2_DEI4, 0, 0, 0, 0 } }, { 0xe69400ac, 0xe69400ec, 8, /* IMR11A / IMCR11A */ { IIC1_DTEI1, IIC1_WAITI1, IIC1_TACKI1, IIC1_ALI1, 0, 0, IRREM, 0 } }, { 0xe69400b0, 0xe69400f0, 8, /* IMR12A / IMCR12A */ { 0, 0, TPU0, 0, 0, 0, 0, 0 } }, { 0xe69400b4, 0xe69400f4, 8, /* IMR13A / IMCR13A */ { SDHI2_SDHI2I3, SDHI2_SDHI2I2, SDHI2_SDHI2I1, SDHI2_SDHI2I0, 0, CMT3, 0, RWDT0 } }, { 0xe6950080, 0xe69500c0, 8, /* IMR0A3 / IMCR0A3 */ { SHWYSTAT_RT, SHWYSTAT_HS, SHWYSTAT_COM, 0, 0, 0, 0, 0 } }, { 0xe6950090, 0xe69500d0, 8, /* IMR4A3 / IMCR4A3 */ { 0, 0, 0, 0, 0, 0, 0, HDMI } }, { 0xe6950094, 0xe69500d4, 8, /* IMR5A3 / IMCR5A3 */ { SPU2_SPU0, SPU2_SPU1, FSI, FMSI, 0, 0, 0, MIPI_HSI } }, { 0xe6950098, 0xe69500d8, 8, /* IMR6A3 / IMCR6A3 */ { 0, IPMMU_IPMMUD, CEC_1, CEC_2, AP_ARM_CTIIRQ, AP_ARM_DMAEXTERRIRQ, AP_ARM_DMAIRQ, AP_ARM_DMASIRQ } }, { 0xe695009c, 0xe69500dc, 8, /* IMR7A3 / IMCR7A3 */ { MFIS2, CPORTR2S, CMT14, CMT15, 0, 0, MMC_MMC_ERR, MMC_MMC_NOR } }, { 0xe69500a0, 0xe69500e0, 8, /* IMR8A3 / IMCR8A3 */ { IIC4_ALI4, IIC4_TACKI4, IIC4_WAITI4, IIC4_DTEI4, IIC3_ALI3, IIC3_TACKI3, IIC3_WAITI3, IIC3_DTEI3 } }, { 0xe69500a4, 0xe69500e4, 8, /* IMR9A3 / IMCR9A3 */ { 0, 0, 0, 0, USB0_USB0I1, USB0_USB0I0, USB1_USB1I1, USB1_USB1I0 } }, { 0xe69500a8, 0xe69500e8, 8, /* IMR10A3 / IMCR10A3 */ { USBHSDMAC1_USHDMI, 0, 0, 0, 0, 0, 0, 0 } }, }; static struct intc_prio_reg intca_prio_registers[] __initdata = { { 0xe6940000, 0, 16, 4, /* IPRAA */ { DMAC3_1, DMAC3_2, CMT2, 0 } }, { 0xe6940004, 0, 16, 4, /* IPRBA */ { IRDA, 0, BBIF1, BBIF2 } }, { 0xe6940008, 0, 16, 4, /* IPRCA */ { 0, CRYPT_STD, CMT1_CMT11, AP_ARM1 } }, { 0xe694000c, 0, 16, 4, /* IPRDA */ { 0, 0, CMT1_CMT12, 0 } }, { 0xe6940010, 0, 16, 4, /* IPREA */ { DMAC1_1, MFI_MFIS, MFI_MFIM, 0 } }, { 0xe6940014, 0, 16, 4, /* IPRFA */ { KEYSC_KEY, DMAC1_2, _3DG_SGX540, CMT1_CMT10 } }, { 0xe6940018, 0, 16, 4, /* IPRGA */ { SCIFA0, SCIFA1, SCIFA2, SCIFA3 } }, { 0xe694001c, 0, 16, 4, /* IPRGH */ { MSIOF2, USBHSDMAC0_USHDMI, FLCTL, SDHI0 } }, { 0xe6940020, 0, 16, 4, /* IPRIA */ { MSIOF1, SCIFA4, 0/* MSU */, IIC1 } }, { 0xe6940024, 0, 16, 4, /* IPRJA */ { DMAC2_1, DMAC2_2, 0/* MSUG */, TTI20 } }, { 0xe6940028, 0, 16, 4, /* IPRKA */ { 0, CMT1_CMT13, IRREM, SDHI1 } }, { 0xe694002c, 0, 16, 4, /* IPRLA */ { TPU0, 0, 0, 0 } }, { 0xe6940030, 0, 16, 4, /* IPRMA */ { 0, CMT3, 0, RWDT0 } }, { 0xe6940034, 0, 16, 4, /* IPRNA */ { SCIFB, SCIFA5, 0, DDM } }, { 0xe6940038, 0, 16, 4, /* IPROA */ { 0, 0, DIRC, SDHI2 } }, { 0xe6950000, 0, 16, 4, /* IPRAA3 */ { SHWYSTAT, 0, 0, 0 } }, { 0xe6950024, 0, 16, 4, /* IPRJA3 */ { 0, 0, 0, HDMI } }, { 0xe6950028, 0, 16, 4, /* IPRKA3 */ { SPU2, 0, FSI, FMSI } }, { 0xe695002c, 0, 16, 4, /* IPRLA3 */ { 0, 0, 0, MIPI_HSI } }, { 0xe6950030, 0, 16, 4, /* IPRMA3 */ { IPMMU_IPMMUD, 0, CEC_1, CEC_2 } }, { 0xe6950034, 0, 16, 4, /* IPRNA3 */ { AP_ARM2, 0, 0, 0 } }, { 0xe6950038, 0, 16, 4, /* IPROA3 */ { MFIS2, CPORTR2S, CMT14, CMT15 } }, { 0xe695003c, 0, 16, 4, /* IPRPA3 */ { 0, 0, MMC_MMC_ERR, MMC_MMC_NOR } }, { 0xe6950040, 0, 16, 4, /* IPRQA3 */ { IIC4_ALI4, IIC4_TACKI4, IIC4_WAITI4, IIC4_DTEI4 } }, { 0xe6950044, 0, 16, 4, /* IPRRA3 */ { IIC3_ALI3, IIC3_TACKI3, IIC3_WAITI3, IIC3_DTEI3 } }, { 0xe6950048, 0, 16, 4, /* IPRSA3 */ { 0/*ERI*/, 0/*RXI*/, 0/*TXI*/, 0/*TEI*/} }, { 0xe695004c, 0, 16, 4, /* IPRTA3 */ { USB0_USB0I1, USB0_USB0I0, USB1_USB1I1, USB1_USB1I0 } }, { 0xe6950050, 0, 16, 4, /* IPRUA3 */ { USBHSDMAC1_USHDMI, 0, 0, 0 } }, }; static DECLARE_INTC_DESC(intca_desc, "sh7372-intca", intca_vectors, intca_groups, intca_mask_registers, intca_prio_registers, NULL); INTC_IRQ_PINS_16(intca_irq_pins_lo, 0xe6900000, INTC_VECT, "sh7372-intca-irq-lo"); INTC_IRQ_PINS_16H(intca_irq_pins_hi, 0xe6900000, INTC_VECT, "sh7372-intca-irq-hi"); enum { UNUSED_INTCS = 0, ENABLED_INTCS, /* interrupt sources INTCS */ /* IRQ0S - IRQ31S */ VEU_VEU0, VEU_VEU1, VEU_VEU2, VEU_VEU3, RTDMAC_1_DEI0, RTDMAC_1_DEI1, RTDMAC_1_DEI2, RTDMAC_1_DEI3, CEU, BEU_BEU0, BEU_BEU1, BEU_BEU2, /* MFI */ /* BBIF2 */ VPU, TSIF1, /* 3DG */ _2DDMAC, IIC2_ALI2, IIC2_TACKI2, IIC2_WAITI2, IIC2_DTEI2, IPMMU_IPMMUR, IPMMU_IPMMUR2, RTDMAC_2_DEI4, RTDMAC_2_DEI5, RTDMAC_2_DADERR, /* KEYSC */ /* TTI20 */ MSIOF, IIC0_ALI0, IIC0_TACKI0, IIC0_WAITI0, IIC0_DTEI0, TMU_TUNI0, TMU_TUNI1, TMU_TUNI2, CMT0, TSIF0, /* CMT2 */ LMB, CTI, /* RWDT0 */ ICB, JPU_JPEG, LCDC, LCRC, RTDMAC2_1_DEI0, RTDMAC2_1_DEI1, RTDMAC2_1_DEI2, RTDMAC2_1_DEI3, RTDMAC2_2_DEI4, RTDMAC2_2_DEI5, RTDMAC2_2_DADERR, ISP, LCDC1, CSIRX, DSITX_DSITX0, DSITX_DSITX1, /* SPU2 */ /* FSI */ /* FMSI */ /* HDMI */ TMU1_TUNI0, TMU1_TUNI1, TMU1_TUNI2, CMT4, DSITX1_DSITX1_0, DSITX1_DSITX1_1, MFIS2_INTCS, /* Priority always enabled using ENABLED_INTCS */ CPORTS2R, /* CEC */ JPU6E, /* interrupt groups INTCS */ RTDMAC_1, RTDMAC_2, VEU, BEU, IIC0, IPMMU, IIC2, RTDMAC2_1, RTDMAC2_2, TMU1, DSITX, }; static struct intc_vect intcs_vectors[] = { /* IRQ0S - IRQ31S */ INTCS_VECT(VEU_VEU0, 0x700), INTCS_VECT(VEU_VEU1, 0x720), INTCS_VECT(VEU_VEU2, 0x740), INTCS_VECT(VEU_VEU3, 0x760), INTCS_VECT(RTDMAC_1_DEI0, 0x800), INTCS_VECT(RTDMAC_1_DEI1, 0x820), INTCS_VECT(RTDMAC_1_DEI2, 0x840), INTCS_VECT(RTDMAC_1_DEI3, 0x860), INTCS_VECT(CEU, 0x880), INTCS_VECT(BEU_BEU0, 0x8a0), INTCS_VECT(BEU_BEU1, 0x8c0), INTCS_VECT(BEU_BEU2, 0x8e0), /* MFI */ /* BBIF2 */ INTCS_VECT(VPU, 0x980), INTCS_VECT(TSIF1, 0x9a0), /* 3DG */ INTCS_VECT(_2DDMAC, 0xa00), INTCS_VECT(IIC2_ALI2, 0xa80), INTCS_VECT(IIC2_TACKI2, 0xaa0), INTCS_VECT(IIC2_WAITI2, 0xac0), INTCS_VECT(IIC2_DTEI2, 0xae0), INTCS_VECT(IPMMU_IPMMUR, 0xb00), INTCS_VECT(IPMMU_IPMMUR2, 0xb20), INTCS_VECT(RTDMAC_2_DEI4, 0xb80), INTCS_VECT(RTDMAC_2_DEI5, 0xba0), INTCS_VECT(RTDMAC_2_DADERR, 0xbc0), /* KEYSC */ /* TTI20 */ INTCS_VECT(MSIOF, 0x0d20), INTCS_VECT(IIC0_ALI0, 0xe00), INTCS_VECT(IIC0_TACKI0, 0xe20), INTCS_VECT(IIC0_WAITI0, 0xe40), INTCS_VECT(IIC0_DTEI0, 0xe60), INTCS_VECT(TMU_TUNI0, 0xe80), INTCS_VECT(TMU_TUNI1, 0xea0), INTCS_VECT(TMU_TUNI2, 0xec0), INTCS_VECT(CMT0, 0xf00), INTCS_VECT(TSIF0, 0xf20), /* CMT2 */ INTCS_VECT(LMB, 0xf60), INTCS_VECT(CTI, 0x400), /* RWDT0 */ INTCS_VECT(ICB, 0x480), INTCS_VECT(JPU_JPEG, 0x560), INTCS_VECT(LCDC, 0x580), INTCS_VECT(LCRC, 0x5a0), INTCS_VECT(RTDMAC2_1_DEI0, 0x1300), INTCS_VECT(RTDMAC2_1_DEI1, 0x1320), INTCS_VECT(RTDMAC2_1_DEI2, 0x1340), INTCS_VECT(RTDMAC2_1_DEI3, 0x1360), INTCS_VECT(RTDMAC2_2_DEI4, 0x1380), INTCS_VECT(RTDMAC2_2_DEI5, 0x13a0), INTCS_VECT(RTDMAC2_2_DADERR, 0x13c0), INTCS_VECT(ISP, 0x1720), INTCS_VECT(LCDC1, 0x1780), INTCS_VECT(CSIRX, 0x17a0), INTCS_VECT(DSITX_DSITX0, 0x17c0), INTCS_VECT(DSITX_DSITX1, 0x17e0), /* SPU2 */ /* FSI */ /* FMSI */ /* HDMI */ INTCS_VECT(TMU1_TUNI0, 0x1900), INTCS_VECT(TMU1_TUNI1, 0x1920), INTCS_VECT(TMU1_TUNI2, 0x1940), INTCS_VECT(CMT4, 0x1980), INTCS_VECT(DSITX1_DSITX1_0, 0x19a0), INTCS_VECT(DSITX1_DSITX1_1, 0x19c0), INTCS_VECT(MFIS2_INTCS, 0x1a00), INTCS_VECT(CPORTS2R, 0x1a20), /* CEC */ INTCS_VECT(JPU6E, 0x1a80), }; static struct intc_group intcs_groups[] __initdata = { INTC_GROUP(RTDMAC_1, RTDMAC_1_DEI0, RTDMAC_1_DEI1, RTDMAC_1_DEI2, RTDMAC_1_DEI3), INTC_GROUP(RTDMAC_2, RTDMAC_2_DEI4, RTDMAC_2_DEI5, RTDMAC_2_DADERR), INTC_GROUP(VEU, VEU_VEU0, VEU_VEU1, VEU_VEU2, VEU_VEU3), INTC_GROUP(BEU, BEU_BEU0, BEU_BEU1, BEU_BEU2), INTC_GROUP(IIC0, IIC0_ALI0, IIC0_TACKI0, IIC0_WAITI0, IIC0_DTEI0), INTC_GROUP(IPMMU, IPMMU_IPMMUR, IPMMU_IPMMUR2), INTC_GROUP(IIC2, IIC2_ALI2, IIC2_TACKI2, IIC2_WAITI2, IIC2_DTEI2), INTC_GROUP(RTDMAC2_1, RTDMAC2_1_DEI0, RTDMAC2_1_DEI1, RTDMAC2_1_DEI2, RTDMAC2_1_DEI3), INTC_GROUP(RTDMAC2_2, RTDMAC2_2_DEI4, RTDMAC2_2_DEI5, RTDMAC2_2_DADERR), INTC_GROUP(TMU1, TMU1_TUNI2, TMU1_TUNI1, TMU1_TUNI0), INTC_GROUP(DSITX, DSITX_DSITX0, DSITX_DSITX1), }; static struct intc_mask_reg intcs_mask_registers[] = { { 0xffd20184, 0xffd201c4, 8, /* IMR1SA / IMCR1SA */ { BEU_BEU2, BEU_BEU1, BEU_BEU0, CEU, VEU_VEU3, VEU_VEU2, VEU_VEU1, VEU_VEU0 } }, { 0xffd20188, 0xffd201c8, 8, /* IMR2SA / IMCR2SA */ { 0, 0, 0, VPU, 0, 0, 0, 0 } }, { 0xffd2018c, 0xffd201cc, 8, /* IMR3SA / IMCR3SA */ { 0, 0, 0, _2DDMAC, 0, 0, 0, ICB } }, { 0xffd20190, 0xffd201d0, 8, /* IMR4SA / IMCR4SA */ { 0, 0, 0, CTI, JPU_JPEG, 0, LCRC, LCDC } }, { 0xffd20194, 0xffd201d4, 8, /* IMR5SA / IMCR5SA */ { 0, RTDMAC_2_DADERR, RTDMAC_2_DEI5, RTDMAC_2_DEI4, RTDMAC_1_DEI3, RTDMAC_1_DEI2, RTDMAC_1_DEI1, RTDMAC_1_DEI0 } }, { 0xffd20198, 0xffd201d8, 8, /* IMR6SA / IMCR6SA */ { 0, 0, MSIOF, 0, 0, 0, 0, 0 } }, { 0xffd2019c, 0xffd201dc, 8, /* IMR7SA / IMCR7SA */ { 0, TMU_TUNI2, TMU_TUNI1, TMU_TUNI0, 0, 0, 0, 0 } }, { 0xffd201a4, 0xffd201e4, 8, /* IMR9SA / IMCR9SA */ { 0, 0, 0, CMT0, IIC2_DTEI2, IIC2_WAITI2, IIC2_TACKI2, IIC2_ALI2 } }, { 0xffd201a8, 0xffd201e8, 8, /* IMR10SA / IMCR10SA */ { 0, 0, IPMMU_IPMMUR2, IPMMU_IPMMUR, 0, 0, 0, 0 } }, { 0xffd201ac, 0xffd201ec, 8, /* IMR11SA / IMCR11SA */ { IIC0_DTEI0, IIC0_WAITI0, IIC0_TACKI0, IIC0_ALI0, 0, TSIF1, LMB, TSIF0 } }, { 0xffd50180, 0xffd501c0, 8, /* IMR0SA3 / IMCR0SA3 */ { 0, RTDMAC2_2_DADERR, RTDMAC2_2_DEI5, RTDMAC2_2_DEI4, RTDMAC2_1_DEI3, RTDMAC2_1_DEI2, RTDMAC2_1_DEI1, RTDMAC2_1_DEI0 } }, { 0xffd50190, 0xffd501d0, 8, /* IMR4SA3 / IMCR4SA3 */ { 0, ISP, 0, 0, LCDC1, CSIRX, DSITX_DSITX0, DSITX_DSITX1 } }, { 0xffd50198, 0xffd501d8, 8, /* IMR6SA3 / IMCR6SA3 */ { 0, TMU1_TUNI2, TMU1_TUNI1, TMU1_TUNI0, CMT4, DSITX1_DSITX1_0, DSITX1_DSITX1_1, 0 } }, { 0xffd5019c, 0xffd501dc, 8, /* IMR7SA3 / IMCR7SA3 */ { MFIS2_INTCS, CPORTS2R, 0, 0, JPU6E, 0, 0, 0 } }, }; /* Priority is needed for INTCA to receive the INTCS interrupt */ static struct intc_prio_reg intcs_prio_registers[] = { { 0xffd20000, 0, 16, 4, /* IPRAS */ { CTI, 0, _2DDMAC, ICB } }, { 0xffd20004, 0, 16, 4, /* IPRBS */ { JPU_JPEG, LCDC, 0, LCRC } }, { 0xffd20010, 0, 16, 4, /* IPRES */ { RTDMAC_1, CEU, 0, VPU } }, { 0xffd20014, 0, 16, 4, /* IPRFS */ { 0, RTDMAC_2, 0, CMT0 } }, { 0xffd20018, 0, 16, 4, /* IPRGS */ { TMU_TUNI0, TMU_TUNI1, TMU_TUNI2, TSIF1 } }, { 0xffd2001c, 0, 16, 4, /* IPRHS */ { 0, 0, VEU, BEU } }, { 0xffd20020, 0, 16, 4, /* IPRIS */ { 0, MSIOF, TSIF0, IIC0 } }, { 0xffd20028, 0, 16, 4, /* IPRKS */ { 0, 0, LMB, 0 } }, { 0xffd2002c, 0, 16, 4, /* IPRLS */ { IPMMU, 0, 0, 0 } }, { 0xffd20030, 0, 16, 4, /* IPRMS */ { IIC2, 0, 0, 0 } }, { 0xffd50000, 0, 16, 4, /* IPRAS3 */ { RTDMAC2_1, 0, 0, 0 } }, { 0xffd50004, 0, 16, 4, /* IPRBS3 */ { RTDMAC2_2, 0, 0, 0 } }, { 0xffd50020, 0, 16, 4, /* IPRIS3 */ { 0, ISP, 0, 0 } }, { 0xffd50024, 0, 16, 4, /* IPRJS3 */ { LCDC1, CSIRX, DSITX, 0 } }, { 0xffd50030, 0, 16, 4, /* IPRMS3 */ { TMU1, 0, 0, 0 } }, { 0xffd50034, 0, 16, 4, /* IPRNS3 */ { CMT4, DSITX1_DSITX1_0, DSITX1_DSITX1_1, 0 } }, { 0xffd50038, 0, 16, 4, /* IPROS3 */ { ENABLED_INTCS, CPORTS2R, 0, 0 } }, { 0xffd5003c, 0, 16, 4, /* IPRPS3 */ { JPU6E, 0, 0, 0 } }, }; static struct resource intcs_resources[] __initdata = { [0] = { .start = 0xffd20000, .end = 0xffd201ff, .flags = IORESOURCE_MEM, }, [1] = { .start = 0xffd50000, .end = 0xffd501ff, .flags = IORESOURCE_MEM, } }; static struct intc_desc intcs_desc __initdata = { .name = "sh7372-intcs", .force_enable = ENABLED_INTCS, .skip_syscore_suspend = true, .resource = intcs_resources, .num_resources = ARRAY_SIZE(intcs_resources), .hw = INTC_HW_DESC(intcs_vectors, intcs_groups, intcs_mask_registers, intcs_prio_registers, NULL, NULL), }; static void intcs_demux(unsigned int irq, struct irq_desc *desc) { void __iomem *reg = (void *)irq_get_handler_data(irq); unsigned int evtcodeas = ioread32(reg); generic_handle_irq(intcs_evt2irq(evtcodeas)); } static void __iomem *intcs_ffd2; static void __iomem *intcs_ffd5; void __init sh7372_init_irq(void) { void __iomem *intevtsa; int n; intcs_ffd2 = ioremap_nocache(0xffd20000, PAGE_SIZE); intevtsa = intcs_ffd2 + 0x100; intcs_ffd5 = ioremap_nocache(0xffd50000, PAGE_SIZE); register_intc_controller(&intca_desc); register_intc_controller(&intca_irq_pins_lo_desc); register_intc_controller(&intca_irq_pins_hi_desc); register_intc_controller(&intcs_desc); /* setup dummy cascade chip for INTCS */ n = evt2irq(0xf80); irq_alloc_desc_at(n, numa_node_id()); irq_set_chip_and_handler_name(n, &dummy_irq_chip, handle_level_irq, "level"); set_irq_flags(n, IRQF_VALID); /* yuck */ /* demux using INTEVTSA */ irq_set_handler_data(n, (void *)intevtsa); irq_set_chained_handler(n, intcs_demux); /* unmask INTCS in INTAMASK */ iowrite16(0, intcs_ffd2 + 0x104); } static unsigned short ffd2[0x200]; static unsigned short ffd5[0x100]; void sh7372_intcs_suspend(void) { int k; for (k = 0x00; k <= 0x30; k += 4) ffd2[k] = __raw_readw(intcs_ffd2 + k); for (k = 0x80; k <= 0xb0; k += 4) ffd2[k] = __raw_readb(intcs_ffd2 + k); for (k = 0x180; k <= 0x188; k += 4) ffd2[k] = __raw_readb(intcs_ffd2 + k); for (k = 0x00; k <= 0x3c; k += 4) ffd5[k] = __raw_readw(intcs_ffd5 + k); for (k = 0x80; k <= 0x9c; k += 4) ffd5[k] = __raw_readb(intcs_ffd5 + k); } void sh7372_intcs_resume(void) { int k; for (k = 0x00; k <= 0x30; k += 4) __raw_writew(ffd2[k], intcs_ffd2 + k); for (k = 0x80; k <= 0xb0; k += 4) __raw_writeb(ffd2[k], intcs_ffd2 + k); for (k = 0x180; k <= 0x188; k += 4) __raw_writeb(ffd2[k], intcs_ffd2 + k); for (k = 0x00; k <= 0x3c; k += 4) __raw_writew(ffd5[k], intcs_ffd5 + k); for (k = 0x80; k <= 0x9c; k += 4) __raw_writeb(ffd5[k], intcs_ffd5 + k); } #define E694_BASE IOMEM(0xe6940000) #define E695_BASE IOMEM(0xe6950000) static unsigned short e694[0x200]; static unsigned short e695[0x200]; void sh7372_intca_suspend(void) { int k; for (k = 0x00; k <= 0x38; k += 4) e694[k] = __raw_readw(E694_BASE + k); for (k = 0x80; k <= 0xb4; k += 4) e694[k] = __raw_readb(E694_BASE + k); for (k = 0x180; k <= 0x1b4; k += 4) e694[k] = __raw_readb(E694_BASE + k); for (k = 0x00; k <= 0x50; k += 4) e695[k] = __raw_readw(E695_BASE + k); for (k = 0x80; k <= 0xa8; k += 4) e695[k] = __raw_readb(E695_BASE + k); for (k = 0x180; k <= 0x1a8; k += 4) e695[k] = __raw_readb(E695_BASE + k); } void sh7372_intca_resume(void) { int k; for (k = 0x00; k <= 0x38; k += 4) __raw_writew(e694[k], E694_BASE + k); for (k = 0x80; k <= 0xb4; k += 4) __raw_writeb(e694[k], E694_BASE + k); for (k = 0x180; k <= 0x1b4; k += 4) __raw_writeb(e694[k], E694_BASE + k); for (k = 0x00; k <= 0x50; k += 4) __raw_writew(e695[k], E695_BASE + k); for (k = 0x80; k <= 0xa8; k += 4) __raw_writeb(e695[k], E695_BASE + k); for (k = 0x180; k <= 0x1a8; k += 4) __raw_writeb(e695[k], E695_BASE + k); }
gpl-2.0
TeamSPR/kernel
arch/sh/drivers/pci/fixups-sdk7780.c
4625
1282
/* * arch/sh/drivers/pci/fixups-sdk7780.c * * PCI fixups for the SDK7780SE03 * * Copyright (C) 2003 Lineo uSolutions, Inc. * Copyright (C) 2004 - 2006 Paul Mundt * Copyright (C) 2006 Nobuhiro Iwamatsu * * This file is subject to the terms and conditions of the GNU General Public * License. See the file "COPYING" in the main directory of this archive * for more details. */ #include <linux/pci.h> #include <linux/io.h> #include <linux/sh_intc.h> #include "pci-sh4.h" #define IRQ_INTA evt2irq(0xa20) #define IRQ_INTB evt2irq(0xa40) #define IRQ_INTC evt2irq(0xa60) #define IRQ_INTD evt2irq(0xa80) /* IDSEL [16][17][18][19][20][21][22][23][24][25][26][27][28][29][30][31] */ static char sdk7780_irq_tab[4][16] __initdata = { /* INTA */ { IRQ_INTA, IRQ_INTD, IRQ_INTC, IRQ_INTD, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, /* INTB */ { IRQ_INTB, IRQ_INTA, -1, IRQ_INTA, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, /* INTC */ { IRQ_INTC, IRQ_INTB, -1, IRQ_INTB, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, /* INTD */ { IRQ_INTD, IRQ_INTC, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, }; int __init pcibios_map_platform_irq(const struct pci_dev *pdev, u8 slot, u8 pin) { return sdk7780_irq_tab[pin-1][slot]; }
gpl-2.0
Jackeagle/kernel_samsung_exynos5260
drivers/net/ethernet/amd/nmclan_cs.c
5137
45839
/* ---------------------------------------------------------------------------- Linux PCMCIA ethernet adapter driver for the New Media Ethernet LAN. nmclan_cs.c,v 0.16 1995/07/01 06:42:17 rpao Exp rpao The Ethernet LAN uses the Advanced Micro Devices (AMD) Am79C940 Media Access Controller for Ethernet (MACE). It is essentially the Am2150 PCMCIA Ethernet card contained in the Am2150 Demo Kit. Written by Roger C. Pao <rpao@paonet.org> Copyright 1995 Roger C. Pao Linux 2.5 cleanups Copyright Red Hat 2003 This software may be used and distributed according to the terms of the GNU General Public License. Ported to Linux 1.3.* network driver environment by Matti Aarnio <mea@utu.fi> References Am2150 Technical Reference Manual, Revision 1.0, August 17, 1993 Am79C940 (MACE) Data Sheet, 1994 Am79C90 (C-LANCE) Data Sheet, 1994 Linux PCMCIA Programmer's Guide v1.17 /usr/src/linux/net/inet/dev.c, Linux kernel 1.2.8 Eric Mears, New Media Corporation Tom Pollard, New Media Corporation Dean Siasoyco, New Media Corporation Ken Lesniak, Silicon Graphics, Inc. <lesniak@boston.sgi.com> Donald Becker <becker@scyld.com> David Hinds <dahinds@users.sourceforge.net> The Linux client driver is based on the 3c589_cs.c client driver by David Hinds. The Linux network driver outline is based on the 3c589_cs.c driver, the 8390.c driver, and the example skeleton.c kernel code, which are by Donald Becker. The Am2150 network driver hardware interface code is based on the OS/9000 driver for the New Media Ethernet LAN by Eric Mears. Special thanks for testing and help in debugging this driver goes to Ken Lesniak. ------------------------------------------------------------------------------- Driver Notes and Issues ------------------------------------------------------------------------------- 1. Developed on a Dell 320SLi PCMCIA Card Services 2.6.2 Linux dell 1.2.10 #1 Thu Jun 29 20:23:41 PDT 1995 i386 2. rc.pcmcia may require loading pcmcia_core with io_speed=300: 'insmod pcmcia_core.o io_speed=300'. This will avoid problems with fast systems which causes rx_framecnt to return random values. 3. If hot extraction does not work for you, use 'ifconfig eth0 down' before extraction. 4. There is a bad slow-down problem in this driver. 5. Future: Multicast processing. In the meantime, do _not_ compile your kernel with multicast ip enabled. ------------------------------------------------------------------------------- History ------------------------------------------------------------------------------- Log: nmclan_cs.c,v * 2.5.75-ac1 2003/07/11 Alan Cox <alan@lxorguk.ukuu.org.uk> * Fixed hang on card eject as we probe it * Cleaned up to use new style locking. * * Revision 0.16 1995/07/01 06:42:17 rpao * Bug fix: nmclan_reset() called CardServices incorrectly. * * Revision 0.15 1995/05/24 08:09:47 rpao * Re-implement MULTI_TX dev->tbusy handling. * * Revision 0.14 1995/05/23 03:19:30 rpao * Added, in nmclan_config(), "tuple.Attributes = 0;". * Modified MACE ID check to ignore chip revision level. * Avoid tx_free_frames race condition between _start_xmit and _interrupt. * * Revision 0.13 1995/05/18 05:56:34 rpao * Statistics changes. * Bug fix: nmclan_reset did not enable TX and RX: call restore_multicast_list. * Bug fix: mace_interrupt checks ~MACE_IMR_DEFAULT. Fixes driver lockup. * * Revision 0.12 1995/05/14 00:12:23 rpao * Statistics overhaul. * 95/05/13 rpao V0.10a Bug fix: MACE statistics counters used wrong I/O ports. Bug fix: mace_interrupt() needed to allow statistics to be processed without RX or TX interrupts pending. 95/05/11 rpao V0.10 Multiple transmit request processing. Modified statistics to use MACE counters where possible. 95/05/10 rpao V0.09 Bug fix: Must use IO_DATA_PATH_WIDTH_AUTO. *Released 95/05/10 rpao V0.08 Bug fix: Make all non-exported functions private by using static keyword. Bug fix: Test IntrCnt _before_ reading MACE_IR. 95/05/10 rpao V0.07 Statistics. 95/05/09 rpao V0.06 Fix rx_framecnt problem by addition of PCIC wait states. ---------------------------------------------------------------------------- */ #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt #define DRV_NAME "nmclan_cs" #define DRV_VERSION "0.16" /* ---------------------------------------------------------------------------- Conditional Compilation Options ---------------------------------------------------------------------------- */ #define MULTI_TX 0 #define RESET_ON_TIMEOUT 1 #define TX_INTERRUPTABLE 1 #define RESET_XILINX 0 /* ---------------------------------------------------------------------------- Include Files ---------------------------------------------------------------------------- */ #include <linux/module.h> #include <linux/kernel.h> #include <linux/init.h> #include <linux/ptrace.h> #include <linux/slab.h> #include <linux/string.h> #include <linux/timer.h> #include <linux/interrupt.h> #include <linux/in.h> #include <linux/delay.h> #include <linux/ethtool.h> #include <linux/netdevice.h> #include <linux/etherdevice.h> #include <linux/skbuff.h> #include <linux/if_arp.h> #include <linux/ioport.h> #include <linux/bitops.h> #include <pcmcia/cisreg.h> #include <pcmcia/cistpl.h> #include <pcmcia/ds.h> #include <asm/uaccess.h> #include <asm/io.h> /* ---------------------------------------------------------------------------- Defines ---------------------------------------------------------------------------- */ #define MACE_LADRF_LEN 8 /* 8 bytes in Logical Address Filter */ /* Loop Control Defines */ #define MACE_MAX_IR_ITERATIONS 10 #define MACE_MAX_RX_ITERATIONS 12 /* TBD: Dean brought this up, and I assumed the hardware would handle it: If MACE_MAX_RX_ITERATIONS is > 1, rx_framecnt may still be non-zero when the isr exits. We may not get another interrupt to process the remaining packets for some time. */ /* The Am2150 has a Xilinx XC3042 field programmable gate array (FPGA) which manages the interface between the MACE and the PCMCIA bus. It also includes buffer management for the 32K x 8 SRAM to control up to four transmit and 12 receive frames at a time. */ #define AM2150_MAX_TX_FRAMES 4 #define AM2150_MAX_RX_FRAMES 12 /* Am2150 Ethernet Card I/O Mapping */ #define AM2150_RCV 0x00 #define AM2150_XMT 0x04 #define AM2150_XMT_SKIP 0x09 #define AM2150_RCV_NEXT 0x0A #define AM2150_RCV_FRAME_COUNT 0x0B #define AM2150_MACE_BANK 0x0C #define AM2150_MACE_BASE 0x10 /* MACE Registers */ #define MACE_RCVFIFO 0 #define MACE_XMTFIFO 1 #define MACE_XMTFC 2 #define MACE_XMTFS 3 #define MACE_XMTRC 4 #define MACE_RCVFC 5 #define MACE_RCVFS 6 #define MACE_FIFOFC 7 #define MACE_IR 8 #define MACE_IMR 9 #define MACE_PR 10 #define MACE_BIUCC 11 #define MACE_FIFOCC 12 #define MACE_MACCC 13 #define MACE_PLSCC 14 #define MACE_PHYCC 15 #define MACE_CHIPIDL 16 #define MACE_CHIPIDH 17 #define MACE_IAC 18 /* Reserved */ #define MACE_LADRF 20 #define MACE_PADR 21 /* Reserved */ /* Reserved */ #define MACE_MPC 24 /* Reserved */ #define MACE_RNTPC 26 #define MACE_RCVCC 27 /* Reserved */ #define MACE_UTR 29 #define MACE_RTR1 30 #define MACE_RTR2 31 /* MACE Bit Masks */ #define MACE_XMTRC_EXDEF 0x80 #define MACE_XMTRC_XMTRC 0x0F #define MACE_XMTFS_XMTSV 0x80 #define MACE_XMTFS_UFLO 0x40 #define MACE_XMTFS_LCOL 0x20 #define MACE_XMTFS_MORE 0x10 #define MACE_XMTFS_ONE 0x08 #define MACE_XMTFS_DEFER 0x04 #define MACE_XMTFS_LCAR 0x02 #define MACE_XMTFS_RTRY 0x01 #define MACE_RCVFS_RCVSTS 0xF000 #define MACE_RCVFS_OFLO 0x8000 #define MACE_RCVFS_CLSN 0x4000 #define MACE_RCVFS_FRAM 0x2000 #define MACE_RCVFS_FCS 0x1000 #define MACE_FIFOFC_RCVFC 0xF0 #define MACE_FIFOFC_XMTFC 0x0F #define MACE_IR_JAB 0x80 #define MACE_IR_BABL 0x40 #define MACE_IR_CERR 0x20 #define MACE_IR_RCVCCO 0x10 #define MACE_IR_RNTPCO 0x08 #define MACE_IR_MPCO 0x04 #define MACE_IR_RCVINT 0x02 #define MACE_IR_XMTINT 0x01 #define MACE_MACCC_PROM 0x80 #define MACE_MACCC_DXMT2PD 0x40 #define MACE_MACCC_EMBA 0x20 #define MACE_MACCC_RESERVED 0x10 #define MACE_MACCC_DRCVPA 0x08 #define MACE_MACCC_DRCVBC 0x04 #define MACE_MACCC_ENXMT 0x02 #define MACE_MACCC_ENRCV 0x01 #define MACE_PHYCC_LNKFL 0x80 #define MACE_PHYCC_DLNKTST 0x40 #define MACE_PHYCC_REVPOL 0x20 #define MACE_PHYCC_DAPC 0x10 #define MACE_PHYCC_LRT 0x08 #define MACE_PHYCC_ASEL 0x04 #define MACE_PHYCC_RWAKE 0x02 #define MACE_PHYCC_AWAKE 0x01 #define MACE_IAC_ADDRCHG 0x80 #define MACE_IAC_PHYADDR 0x04 #define MACE_IAC_LOGADDR 0x02 #define MACE_UTR_RTRE 0x80 #define MACE_UTR_RTRD 0x40 #define MACE_UTR_RPA 0x20 #define MACE_UTR_FCOLL 0x10 #define MACE_UTR_RCVFCSE 0x08 #define MACE_UTR_LOOP_INCL_MENDEC 0x06 #define MACE_UTR_LOOP_NO_MENDEC 0x04 #define MACE_UTR_LOOP_EXTERNAL 0x02 #define MACE_UTR_LOOP_NONE 0x00 #define MACE_UTR_RESERVED 0x01 /* Switch MACE register bank (only 0 and 1 are valid) */ #define MACEBANK(win_num) outb((win_num), ioaddr + AM2150_MACE_BANK) #define MACE_IMR_DEFAULT \ (0xFF - \ ( \ MACE_IR_CERR | \ MACE_IR_RCVCCO | \ MACE_IR_RNTPCO | \ MACE_IR_MPCO | \ MACE_IR_RCVINT | \ MACE_IR_XMTINT \ ) \ ) #undef MACE_IMR_DEFAULT #define MACE_IMR_DEFAULT 0x00 /* New statistics handling: grab everything */ #define TX_TIMEOUT ((400*HZ)/1000) /* ---------------------------------------------------------------------------- Type Definitions ---------------------------------------------------------------------------- */ typedef struct _mace_statistics { /* MACE_XMTFS */ int xmtsv; int uflo; int lcol; int more; int one; int defer; int lcar; int rtry; /* MACE_XMTRC */ int exdef; int xmtrc; /* RFS1--Receive Status (RCVSTS) */ int oflo; int clsn; int fram; int fcs; /* RFS2--Runt Packet Count (RNTPC) */ int rfs_rntpc; /* RFS3--Receive Collision Count (RCVCC) */ int rfs_rcvcc; /* MACE_IR */ int jab; int babl; int cerr; int rcvcco; int rntpco; int mpco; /* MACE_MPC */ int mpc; /* MACE_RNTPC */ int rntpc; /* MACE_RCVCC */ int rcvcc; } mace_statistics; typedef struct _mace_private { struct pcmcia_device *p_dev; struct net_device_stats linux_stats; /* Linux statistics counters */ mace_statistics mace_stats; /* MACE chip statistics counters */ /* restore_multicast_list() state variables */ int multicast_ladrf[MACE_LADRF_LEN]; /* Logical address filter */ int multicast_num_addrs; char tx_free_frames; /* Number of free transmit frame buffers */ char tx_irq_disabled; /* MACE TX interrupt disabled */ spinlock_t bank_lock; /* Must be held if you step off bank 0 */ } mace_private; /* ---------------------------------------------------------------------------- Private Global Variables ---------------------------------------------------------------------------- */ static const char *if_names[]={ "Auto", "10baseT", "BNC", }; /* ---------------------------------------------------------------------------- Parameters These are the parameters that can be set during loading with 'insmod'. ---------------------------------------------------------------------------- */ MODULE_DESCRIPTION("New Media PCMCIA ethernet driver"); MODULE_LICENSE("GPL"); #define INT_MODULE_PARM(n, v) static int n = v; module_param(n, int, 0) /* 0=auto, 1=10baseT, 2 = 10base2, default=auto */ INT_MODULE_PARM(if_port, 0); /* ---------------------------------------------------------------------------- Function Prototypes ---------------------------------------------------------------------------- */ static int nmclan_config(struct pcmcia_device *link); static void nmclan_release(struct pcmcia_device *link); static void nmclan_reset(struct net_device *dev); static int mace_config(struct net_device *dev, struct ifmap *map); static int mace_open(struct net_device *dev); static int mace_close(struct net_device *dev); static netdev_tx_t mace_start_xmit(struct sk_buff *skb, struct net_device *dev); static void mace_tx_timeout(struct net_device *dev); static irqreturn_t mace_interrupt(int irq, void *dev_id); static struct net_device_stats *mace_get_stats(struct net_device *dev); static int mace_rx(struct net_device *dev, unsigned char RxCnt); static void restore_multicast_list(struct net_device *dev); static void set_multicast_list(struct net_device *dev); static const struct ethtool_ops netdev_ethtool_ops; static void nmclan_detach(struct pcmcia_device *p_dev); static const struct net_device_ops mace_netdev_ops = { .ndo_open = mace_open, .ndo_stop = mace_close, .ndo_start_xmit = mace_start_xmit, .ndo_tx_timeout = mace_tx_timeout, .ndo_set_config = mace_config, .ndo_get_stats = mace_get_stats, .ndo_set_rx_mode = set_multicast_list, .ndo_change_mtu = eth_change_mtu, .ndo_set_mac_address = eth_mac_addr, .ndo_validate_addr = eth_validate_addr, }; static int nmclan_probe(struct pcmcia_device *link) { mace_private *lp; struct net_device *dev; dev_dbg(&link->dev, "nmclan_attach()\n"); /* Create new ethernet device */ dev = alloc_etherdev(sizeof(mace_private)); if (!dev) return -ENOMEM; lp = netdev_priv(dev); lp->p_dev = link; link->priv = dev; spin_lock_init(&lp->bank_lock); link->resource[0]->end = 32; link->resource[0]->flags |= IO_DATA_PATH_WIDTH_AUTO; link->config_flags |= CONF_ENABLE_IRQ; link->config_index = 1; link->config_regs = PRESENT_OPTION; lp->tx_free_frames=AM2150_MAX_TX_FRAMES; dev->netdev_ops = &mace_netdev_ops; SET_ETHTOOL_OPS(dev, &netdev_ethtool_ops); dev->watchdog_timeo = TX_TIMEOUT; return nmclan_config(link); } /* nmclan_attach */ static void nmclan_detach(struct pcmcia_device *link) { struct net_device *dev = link->priv; dev_dbg(&link->dev, "nmclan_detach\n"); unregister_netdev(dev); nmclan_release(link); free_netdev(dev); } /* nmclan_detach */ /* ---------------------------------------------------------------------------- mace_read Reads a MACE register. This is bank independent; however, the caller must ensure that this call is not interruptable. We are assuming that during normal operation, the MACE is always in bank 0. ---------------------------------------------------------------------------- */ static int mace_read(mace_private *lp, unsigned int ioaddr, int reg) { int data = 0xFF; unsigned long flags; switch (reg >> 4) { case 0: /* register 0-15 */ data = inb(ioaddr + AM2150_MACE_BASE + reg); break; case 1: /* register 16-31 */ spin_lock_irqsave(&lp->bank_lock, flags); MACEBANK(1); data = inb(ioaddr + AM2150_MACE_BASE + (reg & 0x0F)); MACEBANK(0); spin_unlock_irqrestore(&lp->bank_lock, flags); break; } return data & 0xFF; } /* mace_read */ /* ---------------------------------------------------------------------------- mace_write Writes to a MACE register. This is bank independent; however, the caller must ensure that this call is not interruptable. We are assuming that during normal operation, the MACE is always in bank 0. ---------------------------------------------------------------------------- */ static void mace_write(mace_private *lp, unsigned int ioaddr, int reg, int data) { unsigned long flags; switch (reg >> 4) { case 0: /* register 0-15 */ outb(data & 0xFF, ioaddr + AM2150_MACE_BASE + reg); break; case 1: /* register 16-31 */ spin_lock_irqsave(&lp->bank_lock, flags); MACEBANK(1); outb(data & 0xFF, ioaddr + AM2150_MACE_BASE + (reg & 0x0F)); MACEBANK(0); spin_unlock_irqrestore(&lp->bank_lock, flags); break; } } /* mace_write */ /* ---------------------------------------------------------------------------- mace_init Resets the MACE chip. ---------------------------------------------------------------------------- */ static int mace_init(mace_private *lp, unsigned int ioaddr, char *enet_addr) { int i; int ct = 0; /* MACE Software reset */ mace_write(lp, ioaddr, MACE_BIUCC, 1); while (mace_read(lp, ioaddr, MACE_BIUCC) & 0x01) { /* Wait for reset bit to be cleared automatically after <= 200ns */; if(++ct > 500) { pr_err("reset failed, card removed?\n"); return -1; } udelay(1); } mace_write(lp, ioaddr, MACE_BIUCC, 0); /* The Am2150 requires that the MACE FIFOs operate in burst mode. */ mace_write(lp, ioaddr, MACE_FIFOCC, 0x0F); mace_write(lp,ioaddr, MACE_RCVFC, 0); /* Disable Auto Strip Receive */ mace_write(lp, ioaddr, MACE_IMR, 0xFF); /* Disable all interrupts until _open */ /* * Bit 2-1 PORTSEL[1-0] Port Select. * 00 AUI/10Base-2 * 01 10Base-T * 10 DAI Port (reserved in Am2150) * 11 GPSI * For this card, only the first two are valid. * So, PLSCC should be set to * 0x00 for 10Base-2 * 0x02 for 10Base-T * Or just set ASEL in PHYCC below! */ switch (if_port) { case 1: mace_write(lp, ioaddr, MACE_PLSCC, 0x02); break; case 2: mace_write(lp, ioaddr, MACE_PLSCC, 0x00); break; default: mace_write(lp, ioaddr, MACE_PHYCC, /* ASEL */ 4); /* ASEL Auto Select. When set, the PORTSEL[1-0] bits are overridden, and the MACE device will automatically select the operating media interface port. */ break; } mace_write(lp, ioaddr, MACE_IAC, MACE_IAC_ADDRCHG | MACE_IAC_PHYADDR); /* Poll ADDRCHG bit */ ct = 0; while (mace_read(lp, ioaddr, MACE_IAC) & MACE_IAC_ADDRCHG) { if(++ ct > 500) { pr_err("ADDRCHG timeout, card removed?\n"); return -1; } } /* Set PADR register */ for (i = 0; i < ETH_ALEN; i++) mace_write(lp, ioaddr, MACE_PADR, enet_addr[i]); /* MAC Configuration Control Register should be written last */ /* Let set_multicast_list set this. */ /* mace_write(lp, ioaddr, MACE_MACCC, MACE_MACCC_ENXMT | MACE_MACCC_ENRCV); */ mace_write(lp, ioaddr, MACE_MACCC, 0x00); return 0; } /* mace_init */ static int nmclan_config(struct pcmcia_device *link) { struct net_device *dev = link->priv; mace_private *lp = netdev_priv(dev); u8 *buf; size_t len; int i, ret; unsigned int ioaddr; dev_dbg(&link->dev, "nmclan_config\n"); link->io_lines = 5; ret = pcmcia_request_io(link); if (ret) goto failed; ret = pcmcia_request_exclusive_irq(link, mace_interrupt); if (ret) goto failed; ret = pcmcia_enable_device(link); if (ret) goto failed; dev->irq = link->irq; dev->base_addr = link->resource[0]->start; ioaddr = dev->base_addr; /* Read the ethernet address from the CIS. */ len = pcmcia_get_tuple(link, 0x80, &buf); if (!buf || len < ETH_ALEN) { kfree(buf); goto failed; } memcpy(dev->dev_addr, buf, ETH_ALEN); kfree(buf); /* Verify configuration by reading the MACE ID. */ { char sig[2]; sig[0] = mace_read(lp, ioaddr, MACE_CHIPIDL); sig[1] = mace_read(lp, ioaddr, MACE_CHIPIDH); if ((sig[0] == 0x40) && ((sig[1] & 0x0F) == 0x09)) { dev_dbg(&link->dev, "nmclan_cs configured: mace id=%x %x\n", sig[0], sig[1]); } else { pr_notice("mace id not found: %x %x should be 0x40 0x?9\n", sig[0], sig[1]); return -ENODEV; } } if(mace_init(lp, ioaddr, dev->dev_addr) == -1) goto failed; /* The if_port symbol can be set when the module is loaded */ if (if_port <= 2) dev->if_port = if_port; else pr_notice("invalid if_port requested\n"); SET_NETDEV_DEV(dev, &link->dev); i = register_netdev(dev); if (i != 0) { pr_notice("register_netdev() failed\n"); goto failed; } netdev_info(dev, "nmclan: port %#3lx, irq %d, %s port, hw_addr %pM\n", dev->base_addr, dev->irq, if_names[dev->if_port], dev->dev_addr); return 0; failed: nmclan_release(link); return -ENODEV; } /* nmclan_config */ static void nmclan_release(struct pcmcia_device *link) { dev_dbg(&link->dev, "nmclan_release\n"); pcmcia_disable_device(link); } static int nmclan_suspend(struct pcmcia_device *link) { struct net_device *dev = link->priv; if (link->open) netif_device_detach(dev); return 0; } static int nmclan_resume(struct pcmcia_device *link) { struct net_device *dev = link->priv; if (link->open) { nmclan_reset(dev); netif_device_attach(dev); } return 0; } /* ---------------------------------------------------------------------------- nmclan_reset Reset and restore all of the Xilinx and MACE registers. ---------------------------------------------------------------------------- */ static void nmclan_reset(struct net_device *dev) { mace_private *lp = netdev_priv(dev); #if RESET_XILINX struct pcmcia_device *link = &lp->link; u8 OrigCorValue; /* Save original COR value */ pcmcia_read_config_byte(link, CISREG_COR, &OrigCorValue); /* Reset Xilinx */ dev_dbg(&link->dev, "nmclan_reset: OrigCorValue=0x%x, resetting...\n", OrigCorValue); pcmcia_write_config_byte(link, CISREG_COR, COR_SOFT_RESET); /* Need to wait for 20 ms for PCMCIA to finish reset. */ /* Restore original COR configuration index */ pcmcia_write_config_byte(link, CISREG_COR, (COR_LEVEL_REQ | (OrigCorValue & COR_CONFIG_MASK))); /* Xilinx is now completely reset along with the MACE chip. */ lp->tx_free_frames=AM2150_MAX_TX_FRAMES; #endif /* #if RESET_XILINX */ /* Xilinx is now completely reset along with the MACE chip. */ lp->tx_free_frames=AM2150_MAX_TX_FRAMES; /* Reinitialize the MACE chip for operation. */ mace_init(lp, dev->base_addr, dev->dev_addr); mace_write(lp, dev->base_addr, MACE_IMR, MACE_IMR_DEFAULT); /* Restore the multicast list and enable TX and RX. */ restore_multicast_list(dev); } /* nmclan_reset */ /* ---------------------------------------------------------------------------- mace_config [Someone tell me what this is supposed to do? Is if_port a defined standard? If so, there should be defines to indicate 1=10Base-T, 2=10Base-2, etc. including limited automatic detection.] ---------------------------------------------------------------------------- */ static int mace_config(struct net_device *dev, struct ifmap *map) { if ((map->port != (u_char)(-1)) && (map->port != dev->if_port)) { if (map->port <= 2) { dev->if_port = map->port; netdev_info(dev, "switched to %s port\n", if_names[dev->if_port]); } else return -EINVAL; } return 0; } /* mace_config */ /* ---------------------------------------------------------------------------- mace_open Open device driver. ---------------------------------------------------------------------------- */ static int mace_open(struct net_device *dev) { unsigned int ioaddr = dev->base_addr; mace_private *lp = netdev_priv(dev); struct pcmcia_device *link = lp->p_dev; if (!pcmcia_dev_present(link)) return -ENODEV; link->open++; MACEBANK(0); netif_start_queue(dev); nmclan_reset(dev); return 0; /* Always succeed */ } /* mace_open */ /* ---------------------------------------------------------------------------- mace_close Closes device driver. ---------------------------------------------------------------------------- */ static int mace_close(struct net_device *dev) { unsigned int ioaddr = dev->base_addr; mace_private *lp = netdev_priv(dev); struct pcmcia_device *link = lp->p_dev; dev_dbg(&link->dev, "%s: shutting down ethercard.\n", dev->name); /* Mask off all interrupts from the MACE chip. */ outb(0xFF, ioaddr + AM2150_MACE_BASE + MACE_IMR); link->open--; netif_stop_queue(dev); return 0; } /* mace_close */ static void netdev_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info) { strlcpy(info->driver, DRV_NAME, sizeof(info->driver)); strlcpy(info->version, DRV_VERSION, sizeof(info->version)); snprintf(info->bus_info, sizeof(info->bus_info), "PCMCIA 0x%lx", dev->base_addr); } static const struct ethtool_ops netdev_ethtool_ops = { .get_drvinfo = netdev_get_drvinfo, }; /* ---------------------------------------------------------------------------- mace_start_xmit This routine begins the packet transmit function. When completed, it will generate a transmit interrupt. According to /usr/src/linux/net/inet/dev.c, if _start_xmit returns 0, the "packet is now solely the responsibility of the driver." If _start_xmit returns non-zero, the "transmission failed, put skb back into a list." ---------------------------------------------------------------------------- */ static void mace_tx_timeout(struct net_device *dev) { mace_private *lp = netdev_priv(dev); struct pcmcia_device *link = lp->p_dev; netdev_notice(dev, "transmit timed out -- "); #if RESET_ON_TIMEOUT pr_cont("resetting card\n"); pcmcia_reset_card(link->socket); #else /* #if RESET_ON_TIMEOUT */ pr_cont("NOT resetting card\n"); #endif /* #if RESET_ON_TIMEOUT */ dev->trans_start = jiffies; /* prevent tx timeout */ netif_wake_queue(dev); } static netdev_tx_t mace_start_xmit(struct sk_buff *skb, struct net_device *dev) { mace_private *lp = netdev_priv(dev); unsigned int ioaddr = dev->base_addr; netif_stop_queue(dev); pr_debug("%s: mace_start_xmit(length = %ld) called.\n", dev->name, (long)skb->len); #if (!TX_INTERRUPTABLE) /* Disable MACE TX interrupts. */ outb(MACE_IMR_DEFAULT | MACE_IR_XMTINT, ioaddr + AM2150_MACE_BASE + MACE_IMR); lp->tx_irq_disabled=1; #endif /* #if (!TX_INTERRUPTABLE) */ { /* This block must not be interrupted by another transmit request! mace_tx_timeout will take care of timer-based retransmissions from the upper layers. The interrupt handler is guaranteed never to service a transmit interrupt while we are in here. */ lp->linux_stats.tx_bytes += skb->len; lp->tx_free_frames--; /* WARNING: Write the _exact_ number of bytes written in the header! */ /* Put out the word header [must be an outw()] . . . */ outw(skb->len, ioaddr + AM2150_XMT); /* . . . and the packet [may be any combination of outw() and outb()] */ outsw(ioaddr + AM2150_XMT, skb->data, skb->len >> 1); if (skb->len & 1) { /* Odd byte transfer */ outb(skb->data[skb->len-1], ioaddr + AM2150_XMT); } #if MULTI_TX if (lp->tx_free_frames > 0) netif_start_queue(dev); #endif /* #if MULTI_TX */ } #if (!TX_INTERRUPTABLE) /* Re-enable MACE TX interrupts. */ lp->tx_irq_disabled=0; outb(MACE_IMR_DEFAULT, ioaddr + AM2150_MACE_BASE + MACE_IMR); #endif /* #if (!TX_INTERRUPTABLE) */ dev_kfree_skb(skb); return NETDEV_TX_OK; } /* mace_start_xmit */ /* ---------------------------------------------------------------------------- mace_interrupt The interrupt handler. ---------------------------------------------------------------------------- */ static irqreturn_t mace_interrupt(int irq, void *dev_id) { struct net_device *dev = (struct net_device *) dev_id; mace_private *lp = netdev_priv(dev); unsigned int ioaddr; int status; int IntrCnt = MACE_MAX_IR_ITERATIONS; if (dev == NULL) { pr_debug("mace_interrupt(): irq 0x%X for unknown device.\n", irq); return IRQ_NONE; } ioaddr = dev->base_addr; if (lp->tx_irq_disabled) { const char *msg; if (lp->tx_irq_disabled) msg = "Interrupt with tx_irq_disabled"; else msg = "Re-entering the interrupt handler"; netdev_notice(dev, "%s [isr=%02X, imr=%02X]\n", msg, inb(ioaddr + AM2150_MACE_BASE + MACE_IR), inb(ioaddr + AM2150_MACE_BASE + MACE_IMR)); /* WARNING: MACE_IR has been read! */ return IRQ_NONE; } if (!netif_device_present(dev)) { netdev_dbg(dev, "interrupt from dead card\n"); return IRQ_NONE; } do { /* WARNING: MACE_IR is a READ/CLEAR port! */ status = inb(ioaddr + AM2150_MACE_BASE + MACE_IR); pr_debug("mace_interrupt: irq 0x%X status 0x%X.\n", irq, status); if (status & MACE_IR_RCVINT) { mace_rx(dev, MACE_MAX_RX_ITERATIONS); } if (status & MACE_IR_XMTINT) { unsigned char fifofc; unsigned char xmtrc; unsigned char xmtfs; fifofc = inb(ioaddr + AM2150_MACE_BASE + MACE_FIFOFC); if ((fifofc & MACE_FIFOFC_XMTFC)==0) { lp->linux_stats.tx_errors++; outb(0xFF, ioaddr + AM2150_XMT_SKIP); } /* Transmit Retry Count (XMTRC, reg 4) */ xmtrc = inb(ioaddr + AM2150_MACE_BASE + MACE_XMTRC); if (xmtrc & MACE_XMTRC_EXDEF) lp->mace_stats.exdef++; lp->mace_stats.xmtrc += (xmtrc & MACE_XMTRC_XMTRC); if ( (xmtfs = inb(ioaddr + AM2150_MACE_BASE + MACE_XMTFS)) & MACE_XMTFS_XMTSV /* Transmit Status Valid */ ) { lp->mace_stats.xmtsv++; if (xmtfs & ~MACE_XMTFS_XMTSV) { if (xmtfs & MACE_XMTFS_UFLO) { /* Underflow. Indicates that the Transmit FIFO emptied before the end of frame was reached. */ lp->mace_stats.uflo++; } if (xmtfs & MACE_XMTFS_LCOL) { /* Late Collision */ lp->mace_stats.lcol++; } if (xmtfs & MACE_XMTFS_MORE) { /* MORE than one retry was needed */ lp->mace_stats.more++; } if (xmtfs & MACE_XMTFS_ONE) { /* Exactly ONE retry occurred */ lp->mace_stats.one++; } if (xmtfs & MACE_XMTFS_DEFER) { /* Transmission was defered */ lp->mace_stats.defer++; } if (xmtfs & MACE_XMTFS_LCAR) { /* Loss of carrier */ lp->mace_stats.lcar++; } if (xmtfs & MACE_XMTFS_RTRY) { /* Retry error: transmit aborted after 16 attempts */ lp->mace_stats.rtry++; } } /* if (xmtfs & ~MACE_XMTFS_XMTSV) */ } /* if (xmtfs & MACE_XMTFS_XMTSV) */ lp->linux_stats.tx_packets++; lp->tx_free_frames++; netif_wake_queue(dev); } /* if (status & MACE_IR_XMTINT) */ if (status & ~MACE_IMR_DEFAULT & ~MACE_IR_RCVINT & ~MACE_IR_XMTINT) { if (status & MACE_IR_JAB) { /* Jabber Error. Excessive transmit duration (20-150ms). */ lp->mace_stats.jab++; } if (status & MACE_IR_BABL) { /* Babble Error. >1518 bytes transmitted. */ lp->mace_stats.babl++; } if (status & MACE_IR_CERR) { /* Collision Error. CERR indicates the absence of the Signal Quality Error Test message after a packet transmission. */ lp->mace_stats.cerr++; } if (status & MACE_IR_RCVCCO) { /* Receive Collision Count Overflow; */ lp->mace_stats.rcvcco++; } if (status & MACE_IR_RNTPCO) { /* Runt Packet Count Overflow */ lp->mace_stats.rntpco++; } if (status & MACE_IR_MPCO) { /* Missed Packet Count Overflow */ lp->mace_stats.mpco++; } } /* if (status & ~MACE_IMR_DEFAULT & ~MACE_IR_RCVINT & ~MACE_IR_XMTINT) */ } while ((status & ~MACE_IMR_DEFAULT) && (--IntrCnt)); return IRQ_HANDLED; } /* mace_interrupt */ /* ---------------------------------------------------------------------------- mace_rx Receives packets. ---------------------------------------------------------------------------- */ static int mace_rx(struct net_device *dev, unsigned char RxCnt) { mace_private *lp = netdev_priv(dev); unsigned int ioaddr = dev->base_addr; unsigned char rx_framecnt; unsigned short rx_status; while ( ((rx_framecnt = inb(ioaddr + AM2150_RCV_FRAME_COUNT)) > 0) && (rx_framecnt <= 12) && /* rx_framecnt==0xFF if card is extracted. */ (RxCnt--) ) { rx_status = inw(ioaddr + AM2150_RCV); pr_debug("%s: in mace_rx(), framecnt 0x%X, rx_status" " 0x%X.\n", dev->name, rx_framecnt, rx_status); if (rx_status & MACE_RCVFS_RCVSTS) { /* Error, update stats. */ lp->linux_stats.rx_errors++; if (rx_status & MACE_RCVFS_OFLO) { lp->mace_stats.oflo++; } if (rx_status & MACE_RCVFS_CLSN) { lp->mace_stats.clsn++; } if (rx_status & MACE_RCVFS_FRAM) { lp->mace_stats.fram++; } if (rx_status & MACE_RCVFS_FCS) { lp->mace_stats.fcs++; } } else { short pkt_len = (rx_status & ~MACE_RCVFS_RCVSTS) - 4; /* Auto Strip is off, always subtract 4 */ struct sk_buff *skb; lp->mace_stats.rfs_rntpc += inb(ioaddr + AM2150_RCV); /* runt packet count */ lp->mace_stats.rfs_rcvcc += inb(ioaddr + AM2150_RCV); /* rcv collision count */ pr_debug(" receiving packet size 0x%X rx_status" " 0x%X.\n", pkt_len, rx_status); skb = netdev_alloc_skb(dev, pkt_len + 2); if (skb != NULL) { skb_reserve(skb, 2); insw(ioaddr + AM2150_RCV, skb_put(skb, pkt_len), pkt_len>>1); if (pkt_len & 1) *(skb_tail_pointer(skb) - 1) = inb(ioaddr + AM2150_RCV); skb->protocol = eth_type_trans(skb, dev); netif_rx(skb); /* Send the packet to the upper (protocol) layers. */ lp->linux_stats.rx_packets++; lp->linux_stats.rx_bytes += pkt_len; outb(0xFF, ioaddr + AM2150_RCV_NEXT); /* skip to next frame */ continue; } else { pr_debug("%s: couldn't allocate a sk_buff of size" " %d.\n", dev->name, pkt_len); lp->linux_stats.rx_dropped++; } } outb(0xFF, ioaddr + AM2150_RCV_NEXT); /* skip to next frame */ } /* while */ return 0; } /* mace_rx */ /* ---------------------------------------------------------------------------- pr_linux_stats ---------------------------------------------------------------------------- */ static void pr_linux_stats(struct net_device_stats *pstats) { pr_debug("pr_linux_stats\n"); pr_debug(" rx_packets=%-7ld tx_packets=%ld\n", (long)pstats->rx_packets, (long)pstats->tx_packets); pr_debug(" rx_errors=%-7ld tx_errors=%ld\n", (long)pstats->rx_errors, (long)pstats->tx_errors); pr_debug(" rx_dropped=%-7ld tx_dropped=%ld\n", (long)pstats->rx_dropped, (long)pstats->tx_dropped); pr_debug(" multicast=%-7ld collisions=%ld\n", (long)pstats->multicast, (long)pstats->collisions); pr_debug(" rx_length_errors=%-7ld rx_over_errors=%ld\n", (long)pstats->rx_length_errors, (long)pstats->rx_over_errors); pr_debug(" rx_crc_errors=%-7ld rx_frame_errors=%ld\n", (long)pstats->rx_crc_errors, (long)pstats->rx_frame_errors); pr_debug(" rx_fifo_errors=%-7ld rx_missed_errors=%ld\n", (long)pstats->rx_fifo_errors, (long)pstats->rx_missed_errors); pr_debug(" tx_aborted_errors=%-7ld tx_carrier_errors=%ld\n", (long)pstats->tx_aborted_errors, (long)pstats->tx_carrier_errors); pr_debug(" tx_fifo_errors=%-7ld tx_heartbeat_errors=%ld\n", (long)pstats->tx_fifo_errors, (long)pstats->tx_heartbeat_errors); pr_debug(" tx_window_errors=%ld\n", (long)pstats->tx_window_errors); } /* pr_linux_stats */ /* ---------------------------------------------------------------------------- pr_mace_stats ---------------------------------------------------------------------------- */ static void pr_mace_stats(mace_statistics *pstats) { pr_debug("pr_mace_stats\n"); pr_debug(" xmtsv=%-7d uflo=%d\n", pstats->xmtsv, pstats->uflo); pr_debug(" lcol=%-7d more=%d\n", pstats->lcol, pstats->more); pr_debug(" one=%-7d defer=%d\n", pstats->one, pstats->defer); pr_debug(" lcar=%-7d rtry=%d\n", pstats->lcar, pstats->rtry); /* MACE_XMTRC */ pr_debug(" exdef=%-7d xmtrc=%d\n", pstats->exdef, pstats->xmtrc); /* RFS1--Receive Status (RCVSTS) */ pr_debug(" oflo=%-7d clsn=%d\n", pstats->oflo, pstats->clsn); pr_debug(" fram=%-7d fcs=%d\n", pstats->fram, pstats->fcs); /* RFS2--Runt Packet Count (RNTPC) */ /* RFS3--Receive Collision Count (RCVCC) */ pr_debug(" rfs_rntpc=%-7d rfs_rcvcc=%d\n", pstats->rfs_rntpc, pstats->rfs_rcvcc); /* MACE_IR */ pr_debug(" jab=%-7d babl=%d\n", pstats->jab, pstats->babl); pr_debug(" cerr=%-7d rcvcco=%d\n", pstats->cerr, pstats->rcvcco); pr_debug(" rntpco=%-7d mpco=%d\n", pstats->rntpco, pstats->mpco); /* MACE_MPC */ pr_debug(" mpc=%d\n", pstats->mpc); /* MACE_RNTPC */ pr_debug(" rntpc=%d\n", pstats->rntpc); /* MACE_RCVCC */ pr_debug(" rcvcc=%d\n", pstats->rcvcc); } /* pr_mace_stats */ /* ---------------------------------------------------------------------------- update_stats Update statistics. We change to register window 1, so this should be run single-threaded if the device is active. This is expected to be a rare operation, and it's simpler for the rest of the driver to assume that window 0 is always valid rather than use a special window-state variable. oflo & uflo should _never_ occur since it would mean the Xilinx was not able to transfer data between the MACE FIFO and the card's SRAM fast enough. If this happens, something is seriously wrong with the hardware. ---------------------------------------------------------------------------- */ static void update_stats(unsigned int ioaddr, struct net_device *dev) { mace_private *lp = netdev_priv(dev); lp->mace_stats.rcvcc += mace_read(lp, ioaddr, MACE_RCVCC); lp->mace_stats.rntpc += mace_read(lp, ioaddr, MACE_RNTPC); lp->mace_stats.mpc += mace_read(lp, ioaddr, MACE_MPC); /* At this point, mace_stats is fully updated for this call. We may now update the linux_stats. */ /* The MACE has no equivalent for linux_stats field which are commented out. */ /* lp->linux_stats.multicast; */ lp->linux_stats.collisions = lp->mace_stats.rcvcco * 256 + lp->mace_stats.rcvcc; /* Collision: The MACE may retry sending a packet 15 times before giving up. The retry count is in XMTRC. Does each retry constitute a collision? If so, why doesn't the RCVCC record these collisions? */ /* detailed rx_errors: */ lp->linux_stats.rx_length_errors = lp->mace_stats.rntpco * 256 + lp->mace_stats.rntpc; /* lp->linux_stats.rx_over_errors */ lp->linux_stats.rx_crc_errors = lp->mace_stats.fcs; lp->linux_stats.rx_frame_errors = lp->mace_stats.fram; lp->linux_stats.rx_fifo_errors = lp->mace_stats.oflo; lp->linux_stats.rx_missed_errors = lp->mace_stats.mpco * 256 + lp->mace_stats.mpc; /* detailed tx_errors */ lp->linux_stats.tx_aborted_errors = lp->mace_stats.rtry; lp->linux_stats.tx_carrier_errors = lp->mace_stats.lcar; /* LCAR usually results from bad cabling. */ lp->linux_stats.tx_fifo_errors = lp->mace_stats.uflo; lp->linux_stats.tx_heartbeat_errors = lp->mace_stats.cerr; /* lp->linux_stats.tx_window_errors; */ } /* update_stats */ /* ---------------------------------------------------------------------------- mace_get_stats Gathers ethernet statistics from the MACE chip. ---------------------------------------------------------------------------- */ static struct net_device_stats *mace_get_stats(struct net_device *dev) { mace_private *lp = netdev_priv(dev); update_stats(dev->base_addr, dev); pr_debug("%s: updating the statistics.\n", dev->name); pr_linux_stats(&lp->linux_stats); pr_mace_stats(&lp->mace_stats); return &lp->linux_stats; } /* net_device_stats */ /* ---------------------------------------------------------------------------- updateCRC Modified from Am79C90 data sheet. ---------------------------------------------------------------------------- */ #ifdef BROKEN_MULTICAST static void updateCRC(int *CRC, int bit) { static const int poly[]={ 1,1,1,0, 1,1,0,1, 1,0,1,1, 1,0,0,0, 1,0,0,0, 0,0,1,1, 0,0,1,0, 0,0,0,0 }; /* CRC polynomial. poly[n] = coefficient of the x**n term of the CRC generator polynomial. */ int j; /* shift CRC and control bit (CRC[32]) */ for (j = 32; j > 0; j--) CRC[j] = CRC[j-1]; CRC[0] = 0; /* If bit XOR(control bit) = 1, set CRC = CRC XOR polynomial. */ if (bit ^ CRC[32]) for (j = 0; j < 32; j++) CRC[j] ^= poly[j]; } /* updateCRC */ /* ---------------------------------------------------------------------------- BuildLAF Build logical address filter. Modified from Am79C90 data sheet. Input ladrf: logical address filter (contents initialized to 0) adr: ethernet address ---------------------------------------------------------------------------- */ static void BuildLAF(int *ladrf, int *adr) { int CRC[33]={1}; /* CRC register, 1 word/bit + extra control bit */ int i, byte; /* temporary array indices */ int hashcode; /* the output object */ CRC[32]=0; for (byte = 0; byte < 6; byte++) for (i = 0; i < 8; i++) updateCRC(CRC, (adr[byte] >> i) & 1); hashcode = 0; for (i = 0; i < 6; i++) hashcode = (hashcode << 1) + CRC[i]; byte = hashcode >> 3; ladrf[byte] |= (1 << (hashcode & 7)); #ifdef PCMCIA_DEBUG if (0) printk(KERN_DEBUG " adr =%pM\n", adr); printk(KERN_DEBUG " hashcode = %d(decimal), ladrf[0:63] =", hashcode); for (i = 0; i < 8; i++) pr_cont(" %02X", ladrf[i]); pr_cont("\n"); #endif } /* BuildLAF */ /* ---------------------------------------------------------------------------- restore_multicast_list Restores the multicast filter for MACE chip to the last set_multicast_list() call. Input multicast_num_addrs multicast_ladrf[] ---------------------------------------------------------------------------- */ static void restore_multicast_list(struct net_device *dev) { mace_private *lp = netdev_priv(dev); int num_addrs = lp->multicast_num_addrs; int *ladrf = lp->multicast_ladrf; unsigned int ioaddr = dev->base_addr; int i; pr_debug("%s: restoring Rx mode to %d addresses.\n", dev->name, num_addrs); if (num_addrs > 0) { pr_debug("Attempt to restore multicast list detected.\n"); mace_write(lp, ioaddr, MACE_IAC, MACE_IAC_ADDRCHG | MACE_IAC_LOGADDR); /* Poll ADDRCHG bit */ while (mace_read(lp, ioaddr, MACE_IAC) & MACE_IAC_ADDRCHG) ; /* Set LADRF register */ for (i = 0; i < MACE_LADRF_LEN; i++) mace_write(lp, ioaddr, MACE_LADRF, ladrf[i]); mace_write(lp, ioaddr, MACE_UTR, MACE_UTR_RCVFCSE | MACE_UTR_LOOP_EXTERNAL); mace_write(lp, ioaddr, MACE_MACCC, MACE_MACCC_ENXMT | MACE_MACCC_ENRCV); } else if (num_addrs < 0) { /* Promiscuous mode: receive all packets */ mace_write(lp, ioaddr, MACE_UTR, MACE_UTR_LOOP_EXTERNAL); mace_write(lp, ioaddr, MACE_MACCC, MACE_MACCC_PROM | MACE_MACCC_ENXMT | MACE_MACCC_ENRCV ); } else { /* Normal mode */ mace_write(lp, ioaddr, MACE_UTR, MACE_UTR_LOOP_EXTERNAL); mace_write(lp, ioaddr, MACE_MACCC, MACE_MACCC_ENXMT | MACE_MACCC_ENRCV); } } /* restore_multicast_list */ /* ---------------------------------------------------------------------------- set_multicast_list Set or clear the multicast filter for this adaptor. Input num_addrs == -1 Promiscuous mode, receive all packets num_addrs == 0 Normal mode, clear multicast list num_addrs > 0 Multicast mode, receive normal and MC packets, and do best-effort filtering. Output multicast_num_addrs multicast_ladrf[] ---------------------------------------------------------------------------- */ static void set_multicast_list(struct net_device *dev) { mace_private *lp = netdev_priv(dev); int adr[ETH_ALEN] = {0}; /* Ethernet address */ struct netdev_hw_addr *ha; #ifdef PCMCIA_DEBUG { static int old; if (netdev_mc_count(dev) != old) { old = netdev_mc_count(dev); pr_debug("%s: setting Rx mode to %d addresses.\n", dev->name, old); } } #endif /* Set multicast_num_addrs. */ lp->multicast_num_addrs = netdev_mc_count(dev); /* Set multicast_ladrf. */ if (num_addrs > 0) { /* Calculate multicast logical address filter */ memset(lp->multicast_ladrf, 0, MACE_LADRF_LEN); netdev_for_each_mc_addr(ha, dev) { memcpy(adr, ha->addr, ETH_ALEN); BuildLAF(lp->multicast_ladrf, adr); } } restore_multicast_list(dev); } /* set_multicast_list */ #endif /* BROKEN_MULTICAST */ static void restore_multicast_list(struct net_device *dev) { unsigned int ioaddr = dev->base_addr; mace_private *lp = netdev_priv(dev); pr_debug("%s: restoring Rx mode to %d addresses.\n", dev->name, lp->multicast_num_addrs); if (dev->flags & IFF_PROMISC) { /* Promiscuous mode: receive all packets */ mace_write(lp,ioaddr, MACE_UTR, MACE_UTR_LOOP_EXTERNAL); mace_write(lp, ioaddr, MACE_MACCC, MACE_MACCC_PROM | MACE_MACCC_ENXMT | MACE_MACCC_ENRCV ); } else { /* Normal mode */ mace_write(lp, ioaddr, MACE_UTR, MACE_UTR_LOOP_EXTERNAL); mace_write(lp, ioaddr, MACE_MACCC, MACE_MACCC_ENXMT | MACE_MACCC_ENRCV); } } /* restore_multicast_list */ static void set_multicast_list(struct net_device *dev) { mace_private *lp = netdev_priv(dev); #ifdef PCMCIA_DEBUG { static int old; if (netdev_mc_count(dev) != old) { old = netdev_mc_count(dev); pr_debug("%s: setting Rx mode to %d addresses.\n", dev->name, old); } } #endif lp->multicast_num_addrs = netdev_mc_count(dev); restore_multicast_list(dev); } /* set_multicast_list */ static const struct pcmcia_device_id nmclan_ids[] = { PCMCIA_DEVICE_PROD_ID12("New Media Corporation", "Ethernet", 0x085a850b, 0x00b2e941), PCMCIA_DEVICE_PROD_ID12("Portable Add-ons", "Ethernet+", 0xebf1d60, 0xad673aaf), PCMCIA_DEVICE_NULL, }; MODULE_DEVICE_TABLE(pcmcia, nmclan_ids); static struct pcmcia_driver nmclan_cs_driver = { .owner = THIS_MODULE, .name = "nmclan_cs", .probe = nmclan_probe, .remove = nmclan_detach, .id_table = nmclan_ids, .suspend = nmclan_suspend, .resume = nmclan_resume, }; static int __init init_nmclan_cs(void) { return pcmcia_register_driver(&nmclan_cs_driver); } static void __exit exit_nmclan_cs(void) { pcmcia_unregister_driver(&nmclan_cs_driver); } module_init(init_nmclan_cs); module_exit(exit_nmclan_cs);
gpl-2.0