blob: 8222405781151945c63d9ad92f485efeae448019 [file] [log] [blame]
Dan Williamsd044af12011-03-08 09:52:49 -08001/*
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 Jiang8db37aa2011-02-23 00:02:24 -080030#include <linux/efi.h>
Dan Williamsd044af12011-03-08 09:52:49 -080031#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 Jiang8db37aa2011-02-23 00:02:24 -080040struct 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 Williamsd044af12011-03-08 09:52:49 -080049struct 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 */
92enum sci_status isci_parse_oem_parameters(union scic_oem_parameters *oem_params,
93 struct isci_orom *orom, int scu_index)
94{
Dan Williamsd044af12011-03-08 09:52:49 -080095 /* check for valid inputs */
Dave Jiang02839a8b52011-02-24 17:45:57 -080096 if (scu_index < 0 || scu_index > SCI_MAX_CONTROLLERS ||
97 scu_index > orom->hdr.num_elements || !oem_params)
Dan Williamsd044af12011-03-08 09:52:49 -080098 return -EINVAL;
99
Dave Jiang02839a8b52011-02-24 17:45:57 -0800100 memcpy(oem_params,
101 &orom->ctrl[scu_index],
102 sizeof(struct scic_sds_oem_params));
Dan Williamsd044af12011-03-08 09:52:49 -0800103
104 return 0;
105}
106
107struct isci_orom *isci_request_firmware(struct pci_dev *pdev, const struct firmware *fw)
108{
109 struct isci_orom *orom = NULL, *data;
110
111 if (request_firmware(&fw, ISCI_FW_NAME, &pdev->dev) != 0)
112 return NULL;
113
114 if (fw->size < sizeof(*orom))
115 goto out;
116
117 data = (struct isci_orom *)fw->data;
118
119 if (strncmp(ISCI_ROM_SIG, data->hdr.signature,
120 strlen(ISCI_ROM_SIG)) != 0)
121 goto out;
122
123 orom = devm_kzalloc(&pdev->dev, fw->size, GFP_KERNEL);
124 if (!orom)
125 goto out;
126
127 memcpy(orom, fw->data, fw->size);
128
129 out:
130 release_firmware(fw);
131
132 return orom;
133}
Dave Jiang8db37aa2011-02-23 00:02:24 -0800134
135static struct efi *get_efi(void)
136{
137 #ifdef CONFIG_EFI
138 return &efi;
139 #else
140 return NULL;
141 #endif
142}
143
144struct isci_orom *isci_get_efi_var(struct pci_dev *pdev)
145{
146 struct efi_variable *evar;
147 efi_status_t status;
148 struct isci_orom *orom = NULL;
149
150 evar = devm_kzalloc(&pdev->dev,
151 sizeof(struct efi_variable),
152 GFP_KERNEL);
153 if (!evar) {
154 dev_warn(&pdev->dev,
155 "Unable to allocate memory for EFI var\n");
156 return NULL;
157 }
158
159 evar->DataSize = 1024;
160 evar->VendorGuid = ISCI_EFI_VENDOR_GUID;
161 evar->Attributes = ISCI_EFI_ATTRIBUTES;
162
163 if (get_efi())
164 status = get_efi()->get_variable(evar->VariableName,
165 &evar->VendorGuid,
166 &evar->Attributes,
167 &evar->DataSize,
168 evar->Data);
169 else
170 status = EFI_NOT_FOUND;
171
172 if (status == EFI_SUCCESS)
173 orom = (struct isci_orom *)evar->Data;
174 else
175 dev_warn(&pdev->dev,
176 "Unable to obtain EFI variable for OEM parms\n");
177
178 if (orom && memcmp(orom->hdr.signature, ISCI_ROM_SIG,
179 strlen(ISCI_ROM_SIG)) != 0)
180 dev_warn(&pdev->dev,
181 "Verifying OROM signature failed\n");
182
183 if (!orom)
184 devm_kfree(&pdev->dev, evar);
185
186 return orom;
187}