Dan Williams | d044af1 | 2011-03-08 09:52:49 -0800 | [diff] [blame] | 1 | /* |
| 2 | * This file is provided under a dual BSD/GPLv2 license. When using or |
| 3 | * redistributing this file, you may do so under either license. |
| 4 | * |
| 5 | * GPL LICENSE SUMMARY |
| 6 | * |
| 7 | * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved. |
| 8 | * |
| 9 | * This program is free software; you can redistribute it and/or modify |
| 10 | * it under the terms of version 2 of the GNU General Public License as |
| 11 | * published by the Free Software Foundation. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, but |
| 14 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 16 | * General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License |
| 19 | * along with this program; if not, write to the Free Software |
| 20 | * Foundation, Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. |
| 21 | * The full GNU General Public License is included in this distribution |
| 22 | * in the file called LICENSE.GPL. |
| 23 | */ |
| 24 | |
| 25 | /* probe_roms - scan for oem parameters */ |
| 26 | |
| 27 | #include <linux/kernel.h> |
| 28 | #include <linux/firmware.h> |
| 29 | #include <linux/uaccess.h> |
Dave Jiang | 8db37aa | 2011-02-23 00:02:24 -0800 | [diff] [blame^] | 30 | #include <linux/efi.h> |
Dan Williams | d044af1 | 2011-03-08 09:52:49 -0800 | [diff] [blame] | 31 | #include <asm/probe_roms.h> |
| 32 | |
| 33 | #include "isci.h" |
| 34 | #include "task.h" |
| 35 | #include "sci_controller_constants.h" |
| 36 | #include "scic_remote_device.h" |
| 37 | #include "sci_environment.h" |
| 38 | #include "probe_roms.h" |
| 39 | |
Dave Jiang | 8db37aa | 2011-02-23 00:02:24 -0800 | [diff] [blame^] | 40 | struct efi_variable { |
| 41 | efi_char16_t VariableName[1024/sizeof(efi_char16_t)]; |
| 42 | efi_guid_t VendorGuid; |
| 43 | unsigned long DataSize; |
| 44 | __u8 Data[1024]; |
| 45 | efi_status_t Status; |
| 46 | __u32 Attributes; |
| 47 | } __attribute__((packed)); |
| 48 | |
Dan Williams | d044af1 | 2011-03-08 09:52:49 -0800 | [diff] [blame] | 49 | struct isci_orom *isci_request_oprom(struct pci_dev *pdev) |
| 50 | { |
| 51 | void __iomem *oprom = pci_map_biosrom(pdev); |
| 52 | struct isci_orom *rom = NULL; |
| 53 | size_t len, i; |
| 54 | |
| 55 | if (!oprom) |
| 56 | return NULL; |
| 57 | |
| 58 | len = pci_biosrom_size(pdev); |
| 59 | rom = devm_kzalloc(&pdev->dev, sizeof(*rom), GFP_KERNEL); |
| 60 | |
| 61 | for (i = 0; i < len && rom; i += ISCI_ROM_SIG_SIZE) { |
| 62 | memcpy_fromio(rom->hdr.signature, oprom + i, ISCI_ROM_SIG_SIZE); |
| 63 | if (memcmp(rom->hdr.signature, ISCI_ROM_SIG, |
| 64 | ISCI_ROM_SIG_SIZE) == 0) { |
| 65 | size_t copy_len = min(len - i, sizeof(*rom)); |
| 66 | |
| 67 | memcpy_fromio(rom, oprom + i, copy_len); |
| 68 | break; |
| 69 | } |
| 70 | } |
| 71 | |
| 72 | if (i >= len) { |
| 73 | dev_err(&pdev->dev, "oprom parse error\n"); |
| 74 | devm_kfree(&pdev->dev, rom); |
| 75 | rom = NULL; |
| 76 | } |
| 77 | pci_unmap_biosrom(oprom); |
| 78 | |
| 79 | return rom; |
| 80 | } |
| 81 | |
| 82 | /** |
| 83 | * isci_parse_oem_parameters() - This method will take OEM parameters |
| 84 | * from the module init parameters and copy them to oem_params. This will |
| 85 | * only copy values that are not set to the module parameter default values |
| 86 | * @oem_parameters: This parameter specifies the controller default OEM |
| 87 | * parameters. It is expected that this has been initialized to the default |
| 88 | * parameters for the controller |
| 89 | * |
| 90 | * |
| 91 | */ |
| 92 | enum sci_status isci_parse_oem_parameters(union scic_oem_parameters *oem_params, |
| 93 | struct isci_orom *orom, int scu_index) |
| 94 | { |
| 95 | int i; |
| 96 | |
| 97 | /* check for valid inputs */ |
| 98 | if (!(scu_index >= 0 |
| 99 | && scu_index < SCI_MAX_CONTROLLERS |
| 100 | && oem_params != NULL)) |
| 101 | return -EINVAL; |
| 102 | |
| 103 | for (i = 0; i < SCI_MAX_PHYS; i++) { |
| 104 | oem_params->sds1.phys[i].sas_address.low = |
| 105 | orom->ctrl[scu_index].phys[i].sas_address.low; |
| 106 | oem_params->sds1.phys[i].sas_address.high = |
| 107 | orom->ctrl[scu_index].phys[i].sas_address.high; |
| 108 | } |
| 109 | |
| 110 | for (i = 0; i < SCI_MAX_PORTS; i++) |
| 111 | oem_params->sds1.ports[i].phy_mask = |
| 112 | orom->ctrl[scu_index].ports[i].phy_mask; |
| 113 | |
| 114 | return 0; |
| 115 | } |
| 116 | |
| 117 | struct isci_orom *isci_request_firmware(struct pci_dev *pdev, const struct firmware *fw) |
| 118 | { |
| 119 | struct isci_orom *orom = NULL, *data; |
| 120 | |
| 121 | if (request_firmware(&fw, ISCI_FW_NAME, &pdev->dev) != 0) |
| 122 | return NULL; |
| 123 | |
| 124 | if (fw->size < sizeof(*orom)) |
| 125 | goto out; |
| 126 | |
| 127 | data = (struct isci_orom *)fw->data; |
| 128 | |
| 129 | if (strncmp(ISCI_ROM_SIG, data->hdr.signature, |
| 130 | strlen(ISCI_ROM_SIG)) != 0) |
| 131 | goto out; |
| 132 | |
| 133 | orom = devm_kzalloc(&pdev->dev, fw->size, GFP_KERNEL); |
| 134 | if (!orom) |
| 135 | goto out; |
| 136 | |
| 137 | memcpy(orom, fw->data, fw->size); |
| 138 | |
| 139 | out: |
| 140 | release_firmware(fw); |
| 141 | |
| 142 | return orom; |
| 143 | } |
Dave Jiang | 8db37aa | 2011-02-23 00:02:24 -0800 | [diff] [blame^] | 144 | |
| 145 | static struct efi *get_efi(void) |
| 146 | { |
| 147 | #ifdef CONFIG_EFI |
| 148 | return &efi; |
| 149 | #else |
| 150 | return NULL; |
| 151 | #endif |
| 152 | } |
| 153 | |
| 154 | struct isci_orom *isci_get_efi_var(struct pci_dev *pdev) |
| 155 | { |
| 156 | struct efi_variable *evar; |
| 157 | efi_status_t status; |
| 158 | struct isci_orom *orom = NULL; |
| 159 | |
| 160 | evar = devm_kzalloc(&pdev->dev, |
| 161 | sizeof(struct efi_variable), |
| 162 | GFP_KERNEL); |
| 163 | if (!evar) { |
| 164 | dev_warn(&pdev->dev, |
| 165 | "Unable to allocate memory for EFI var\n"); |
| 166 | return NULL; |
| 167 | } |
| 168 | |
| 169 | evar->DataSize = 1024; |
| 170 | evar->VendorGuid = ISCI_EFI_VENDOR_GUID; |
| 171 | evar->Attributes = ISCI_EFI_ATTRIBUTES; |
| 172 | |
| 173 | if (get_efi()) |
| 174 | status = get_efi()->get_variable(evar->VariableName, |
| 175 | &evar->VendorGuid, |
| 176 | &evar->Attributes, |
| 177 | &evar->DataSize, |
| 178 | evar->Data); |
| 179 | else |
| 180 | status = EFI_NOT_FOUND; |
| 181 | |
| 182 | if (status == EFI_SUCCESS) |
| 183 | orom = (struct isci_orom *)evar->Data; |
| 184 | else |
| 185 | dev_warn(&pdev->dev, |
| 186 | "Unable to obtain EFI variable for OEM parms\n"); |
| 187 | |
| 188 | if (orom && memcmp(orom->hdr.signature, ISCI_ROM_SIG, |
| 189 | strlen(ISCI_ROM_SIG)) != 0) |
| 190 | dev_warn(&pdev->dev, |
| 191 | "Verifying OROM signature failed\n"); |
| 192 | |
| 193 | if (!orom) |
| 194 | devm_kfree(&pdev->dev, evar); |
| 195 | |
| 196 | return orom; |
| 197 | } |