]>
Commit | Line | Data |
---|---|---|
6f231dda DW |
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 | * BSD LICENSE | |
25 | * | |
26 | * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved. | |
27 | * All rights reserved. | |
28 | * | |
29 | * Redistribution and use in source and binary forms, with or without | |
30 | * modification, are permitted provided that the following conditions | |
31 | * are met: | |
32 | * | |
33 | * * Redistributions of source code must retain the above copyright | |
34 | * notice, this list of conditions and the following disclaimer. | |
35 | * * Redistributions in binary form must reproduce the above copyright | |
36 | * notice, this list of conditions and the following disclaimer in | |
37 | * the documentation and/or other materials provided with the | |
38 | * distribution. | |
39 | * * Neither the name of Intel Corporation nor the names of its | |
40 | * contributors may be used to endorse or promote products derived | |
41 | * from this software without specific prior written permission. | |
42 | * | |
43 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
44 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
45 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
46 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
47 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
48 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
49 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
50 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
51 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
52 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
53 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
54 | */ | |
55 | ||
56 | #include <linux/kernel.h> | |
57 | #include <linux/init.h> | |
58 | #include <linux/module.h> | |
59 | #include <asm/string.h> | |
60 | #include "isci.h" | |
61 | #include "task.h" | |
62 | #include "sci_controller_constants.h" | |
63 | #include "scic_remote_device.h" | |
64 | #include "sci_environment.h" | |
65 | ||
66 | static struct scsi_transport_template *isci_transport_template; | |
6f231dda DW |
67 | |
68 | static DEFINE_PCI_DEVICE_TABLE(isci_id_table) = { | |
69 | { PCI_VDEVICE(INTEL, 0x1D61),}, | |
70 | { PCI_VDEVICE(INTEL, 0x1D63),}, | |
71 | { PCI_VDEVICE(INTEL, 0x1D65),}, | |
72 | { PCI_VDEVICE(INTEL, 0x1D67),}, | |
73 | { PCI_VDEVICE(INTEL, 0x1D69),}, | |
74 | { PCI_VDEVICE(INTEL, 0x1D6B),}, | |
75 | { PCI_VDEVICE(INTEL, 0x1D60),}, | |
76 | { PCI_VDEVICE(INTEL, 0x1D62),}, | |
77 | { PCI_VDEVICE(INTEL, 0x1D64),}, | |
78 | { PCI_VDEVICE(INTEL, 0x1D66),}, | |
79 | { PCI_VDEVICE(INTEL, 0x1D68),}, | |
80 | { PCI_VDEVICE(INTEL, 0x1D6A),}, | |
81 | {} | |
82 | }; | |
83 | ||
858d4aa7 DJ |
84 | struct isci_firmware *isci_firmware; |
85 | ||
6f231dda DW |
86 | static int __devinit isci_pci_probe( |
87 | struct pci_dev *pdev, | |
88 | const struct pci_device_id *device_id_p); | |
89 | ||
90 | static void __devexit isci_pci_remove(struct pci_dev *pdev); | |
91 | ||
92 | MODULE_DEVICE_TABLE(pci, isci_id_table); | |
93 | ||
94 | static struct pci_driver isci_pci_driver = { | |
95 | .name = DRV_NAME, | |
96 | .id_table = isci_id_table, | |
97 | .probe = isci_pci_probe, | |
98 | .remove = __devexit_p(isci_pci_remove), | |
99 | }; | |
100 | ||
101 | /* linux isci specific settings */ | |
6f231dda DW |
102 | |
103 | #if defined(CONFIG_PBG_HBA_A0) | |
104 | int isci_si_rev = ISCI_SI_REVA0; | |
105 | #elif defined(CONFIG_PBG_HBA_A2) | |
106 | int isci_si_rev = ISCI_SI_REVA2; | |
107 | #else | |
108 | int isci_si_rev = ISCI_SI_REVB0; | |
109 | #endif | |
110 | module_param(isci_si_rev, int, S_IRUGO | S_IWUSR); | |
111 | MODULE_PARM_DESC(isci_si_rev, "override default si rev (0: A0 1: A2 2: B0)"); | |
112 | ||
113 | static struct scsi_host_template isci_sht = { | |
114 | ||
115 | .module = THIS_MODULE, | |
116 | .name = DRV_NAME, | |
92cd5115 | 117 | .proc_name = DRV_NAME, |
6f231dda DW |
118 | .queuecommand = sas_queuecommand, |
119 | .target_alloc = sas_target_alloc, | |
120 | .slave_configure = sas_slave_configure, | |
121 | .slave_destroy = sas_slave_destroy, | |
122 | .scan_finished = isci_host_scan_finished, | |
123 | .scan_start = isci_host_scan_start, | |
124 | .change_queue_depth = sas_change_queue_depth, | |
125 | .change_queue_type = sas_change_queue_type, | |
126 | .bios_param = sas_bios_param, | |
127 | .can_queue = ISCI_CAN_QUEUE_VAL, | |
128 | .cmd_per_lun = 1, | |
129 | .this_id = -1, | |
130 | .sg_tablesize = SG_ALL, | |
131 | .max_sectors = SCSI_DEFAULT_MAX_SECTORS, | |
132 | .use_clustering = ENABLE_CLUSTERING, | |
133 | .eh_device_reset_handler = sas_eh_device_reset_handler, | |
134 | .eh_bus_reset_handler = isci_bus_reset_handler, | |
135 | .slave_alloc = sas_slave_alloc, | |
136 | .target_destroy = sas_target_destroy, | |
137 | .ioctl = sas_ioctl, | |
138 | }; | |
139 | ||
140 | static struct sas_domain_function_template isci_transport_ops = { | |
141 | ||
142 | /* The class calls these to notify the LLDD of an event. */ | |
143 | .lldd_port_formed = isci_port_formed, | |
144 | .lldd_port_deformed = isci_port_deformed, | |
145 | ||
146 | /* The class calls these when a device is found or gone. */ | |
147 | .lldd_dev_found = isci_remote_device_found, | |
148 | .lldd_dev_gone = isci_remote_device_gone, | |
149 | ||
150 | .lldd_execute_task = isci_task_execute_task, | |
151 | /* Task Management Functions. Must be called from process context. */ | |
152 | .lldd_abort_task = isci_task_abort_task, | |
153 | .lldd_abort_task_set = isci_task_abort_task_set, | |
154 | .lldd_clear_aca = isci_task_clear_aca, | |
155 | .lldd_clear_task_set = isci_task_clear_task_set, | |
156 | .lldd_I_T_nexus_reset = isci_task_I_T_nexus_reset, | |
157 | .lldd_lu_reset = isci_task_lu_reset, | |
158 | .lldd_query_task = isci_task_query_task, | |
159 | ||
160 | /* Port and Adapter management */ | |
161 | .lldd_clear_nexus_port = isci_task_clear_nexus_port, | |
162 | .lldd_clear_nexus_ha = isci_task_clear_nexus_ha, | |
163 | ||
164 | /* Phy management */ | |
165 | .lldd_control_phy = isci_phy_control, | |
166 | }; | |
167 | ||
168 | ||
169 | /****************************************************************************** | |
170 | * P R O T E C T E D M E T H O D S | |
171 | ******************************************************************************/ | |
172 | ||
173 | ||
174 | ||
175 | /** | |
176 | * isci_register_sas_ha() - This method initializes various lldd | |
177 | * specific members of the sas_ha struct and calls the libsas | |
178 | * sas_register_ha() function. | |
179 | * @isci_host: This parameter specifies the lldd specific wrapper for the | |
180 | * libsas sas_ha struct. | |
181 | * | |
182 | * This method returns an error code indicating sucess or failure. The user | |
183 | * should check for possible memory allocation error return otherwise, a zero | |
184 | * indicates success. | |
185 | */ | |
186 | static int isci_register_sas_ha(struct isci_host *isci_host) | |
187 | { | |
188 | int i; | |
189 | struct sas_ha_struct *sas_ha = &(isci_host->sas_ha); | |
190 | struct asd_sas_phy **sas_phys; | |
191 | struct asd_sas_port **sas_ports; | |
192 | ||
193 | sas_phys = devm_kzalloc(&isci_host->pdev->dev, | |
194 | SCI_MAX_PHYS * sizeof(void *), | |
195 | GFP_KERNEL); | |
196 | if (!sas_phys) | |
197 | return -ENOMEM; | |
198 | ||
199 | sas_ports = devm_kzalloc(&isci_host->pdev->dev, | |
200 | SCI_MAX_PORTS * sizeof(void *), | |
201 | GFP_KERNEL); | |
202 | if (!sas_ports) | |
203 | return -ENOMEM; | |
204 | ||
205 | /*----------------- Libsas Initialization Stuff---------------------- | |
206 | * Set various fields in the sas_ha struct: | |
207 | */ | |
208 | ||
209 | sas_ha->sas_ha_name = DRV_NAME; | |
210 | sas_ha->lldd_module = THIS_MODULE; | |
150fc6fc | 211 | sas_ha->sas_addr = &isci_host->phys[0].sas_addr[0]; |
6f231dda DW |
212 | |
213 | /* set the array of phy and port structs. */ | |
214 | for (i = 0; i < SCI_MAX_PHYS; i++) { | |
215 | sas_phys[i] = &(isci_host->phys[i].sas_phy); | |
216 | sas_ports[i] = &(isci_host->sas_ports[i]); | |
217 | } | |
218 | ||
219 | sas_ha->sas_phy = sas_phys; | |
220 | sas_ha->sas_port = sas_ports; | |
221 | sas_ha->num_phys = SCI_MAX_PHYS; | |
222 | ||
223 | sas_ha->lldd_queue_size = ISCI_CAN_QUEUE_VAL; | |
224 | sas_ha->lldd_max_execute_num = 1; | |
225 | sas_ha->strict_wide_ports = 1; | |
226 | ||
227 | sas_register_ha(sas_ha); | |
228 | ||
229 | return 0; | |
230 | } | |
231 | ||
34cad85d | 232 | static ssize_t isci_show_id(struct device *dev, struct device_attribute *attr, char *buf) |
6f231dda | 233 | { |
34cad85d DW |
234 | struct Scsi_Host *shost = container_of(dev, typeof(*shost), shost_dev); |
235 | struct sas_ha_struct *sas_ha = SHOST_TO_SAS_HA(shost); | |
236 | struct isci_host *ihost = container_of(sas_ha, typeof(*ihost), sas_ha); | |
237 | ||
238 | return snprintf(buf, PAGE_SIZE, "%d\n", ihost->id); | |
239 | } | |
240 | ||
241 | static DEVICE_ATTR(isci_id, S_IRUGO, isci_show_id, NULL); | |
242 | ||
243 | static void isci_unregister(struct isci_host *isci_host) | |
244 | { | |
245 | struct Scsi_Host *shost; | |
246 | ||
6f231dda DW |
247 | if (!isci_host) |
248 | return; | |
249 | ||
34cad85d DW |
250 | shost = isci_host->shost; |
251 | device_remove_file(&shost->shost_dev, &dev_attr_isci_id); | |
252 | ||
253 | sas_unregister_ha(&isci_host->sas_ha); | |
6f231dda DW |
254 | |
255 | sas_remove_host(isci_host->shost); | |
256 | scsi_remove_host(isci_host->shost); | |
257 | scsi_host_put(isci_host->shost); | |
258 | } | |
259 | ||
260 | static int __devinit isci_pci_init(struct pci_dev *pdev) | |
261 | { | |
262 | int err, bar_num, bar_mask; | |
263 | void __iomem * const *iomap; | |
264 | ||
265 | err = pcim_enable_device(pdev); | |
266 | if (err) { | |
267 | dev_err(&pdev->dev, | |
268 | "failed enable PCI device %s!\n", | |
269 | pci_name(pdev)); | |
270 | return err; | |
271 | } | |
272 | ||
273 | for (bar_num = 0; bar_num < SCI_PCI_BAR_COUNT; bar_num++) | |
274 | bar_mask |= 1 << (bar_num * 2); | |
275 | ||
276 | err = pcim_iomap_regions(pdev, bar_mask, DRV_NAME); | |
277 | if (err) | |
278 | return err; | |
279 | ||
280 | iomap = pcim_iomap_table(pdev); | |
281 | if (!iomap) | |
282 | return -ENOMEM; | |
283 | ||
284 | pci_set_master(pdev); | |
285 | ||
286 | err = pci_set_dma_mask(pdev, DMA_BIT_MASK(64)); | |
287 | if (err) { | |
288 | err = pci_set_dma_mask(pdev, DMA_BIT_MASK(32)); | |
289 | if (err) | |
290 | return err; | |
291 | } | |
292 | ||
293 | err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64)); | |
294 | if (err) { | |
295 | err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32)); | |
296 | if (err) | |
297 | return err; | |
298 | } | |
299 | ||
300 | return 0; | |
301 | } | |
302 | ||
6f231dda DW |
303 | static int num_controllers(struct pci_dev *pdev) |
304 | { | |
305 | /* bar size alone can tell us if we are running with a dual controller | |
306 | * part, no need to trust revision ids that might be under broken firmware | |
307 | * control | |
308 | */ | |
309 | resource_size_t scu_bar_size = pci_resource_len(pdev, SCI_SCU_BAR*2); | |
310 | resource_size_t smu_bar_size = pci_resource_len(pdev, SCI_SMU_BAR*2); | |
311 | ||
312 | if (scu_bar_size >= SCI_SCU_BAR_SIZE*SCI_MAX_CONTROLLERS && | |
313 | smu_bar_size >= SCI_SMU_BAR_SIZE*SCI_MAX_CONTROLLERS) | |
314 | return SCI_MAX_CONTROLLERS; | |
315 | else | |
316 | return 1; | |
317 | } | |
318 | ||
319 | static int isci_setup_interrupts(struct pci_dev *pdev) | |
320 | { | |
321 | int err, i, num_msix; | |
322 | struct isci_pci_info *pci_info = to_pci_info(pdev); | |
323 | ||
324 | /* | |
325 | * Determine the number of vectors associated with this | |
326 | * PCI function. | |
327 | */ | |
328 | num_msix = num_controllers(pdev) * SCI_NUM_MSI_X_INT; | |
329 | ||
330 | for (i = 0; i < num_msix; i++) | |
331 | pci_info->msix_entries[i].entry = i; | |
332 | ||
333 | err = pci_enable_msix(pdev, pci_info->msix_entries, num_msix); | |
334 | if (err) | |
335 | goto intx; | |
336 | ||
337 | for (i = 0; i < num_msix; i++) { | |
338 | int id = i / SCI_NUM_MSI_X_INT; | |
339 | struct msix_entry *msix = &pci_info->msix_entries[i]; | |
b329aff1 | 340 | struct isci_host *isci_host = pci_info->hosts[id]; |
92f4f0f5 DW |
341 | irq_handler_t isr; |
342 | ||
343 | /* odd numbered vectors are error interrupts */ | |
344 | if (i & 1) | |
345 | isr = isci_error_isr; | |
346 | else | |
347 | isr = isci_msix_isr; | |
6f231dda DW |
348 | |
349 | BUG_ON(!isci_host); | |
350 | ||
92f4f0f5 | 351 | err = devm_request_irq(&pdev->dev, msix->vector, isr, 0, |
6f231dda DW |
352 | DRV_NAME"-msix", isci_host); |
353 | if (!err) | |
354 | continue; | |
355 | ||
356 | dev_info(&pdev->dev, "msix setup failed falling back to intx\n"); | |
357 | while (i--) { | |
358 | id = i / SCI_NUM_MSI_X_INT; | |
b329aff1 | 359 | isci_host = pci_info->hosts[id]; |
6f231dda DW |
360 | msix = &pci_info->msix_entries[i]; |
361 | devm_free_irq(&pdev->dev, msix->vector, isci_host); | |
362 | } | |
363 | pci_disable_msix(pdev); | |
364 | goto intx; | |
365 | } | |
366 | ||
367 | return 0; | |
368 | ||
369 | intx: | |
c7ef4031 | 370 | err = devm_request_irq(&pdev->dev, pdev->irq, isci_intx_isr, |
6f231dda DW |
371 | IRQF_SHARED, DRV_NAME"-intx", pdev); |
372 | ||
373 | return err; | |
374 | } | |
375 | ||
376 | /** | |
377 | * isci_parse_oem_parameters() - This method will take OEM parameters | |
378 | * from the module init parameters and copy them to oem_params. This will | |
379 | * only copy values that are not set to the module parameter default values | |
380 | * @oem_parameters: This parameter specifies the controller default OEM | |
381 | * parameters. It is expected that this has been initialized to the default | |
382 | * parameters for the controller | |
383 | * | |
384 | * | |
385 | */ | |
386 | enum sci_status isci_parse_oem_parameters(union scic_oem_parameters *oem_params, | |
387 | int scu_index, | |
388 | struct isci_firmware *fw) | |
389 | { | |
390 | int i; | |
391 | ||
392 | /* check for valid inputs */ | |
393 | if (!(scu_index >= 0 | |
394 | && scu_index < SCI_MAX_CONTROLLERS | |
395 | && oem_params != NULL)) { | |
396 | return SCI_FAILURE; | |
397 | } | |
398 | ||
399 | for (i = 0; i < SCI_MAX_PHYS; i++) { | |
400 | int array_idx = i + (SCI_MAX_PHYS * scu_index); | |
401 | u64 sas_addr = fw->sas_addrs[array_idx]; | |
402 | ||
403 | if (sas_addr != 0) { | |
404 | oem_params->sds1.phys[i].sas_address.low = | |
405 | (u32)(sas_addr & 0xffffffff); | |
406 | oem_params->sds1.phys[i].sas_address.high = | |
407 | (u32)((sas_addr >> 32) & 0xffffffff); | |
408 | } | |
409 | } | |
410 | ||
411 | for (i = 0; i < SCI_MAX_PORTS; i++) { | |
412 | int array_idx = i + (SCI_MAX_PORTS * scu_index); | |
413 | u32 pmask = fw->phy_masks[array_idx]; | |
414 | ||
415 | oem_params->sds1.ports[i].phy_mask = pmask; | |
416 | } | |
417 | ||
418 | return SCI_SUCCESS; | |
419 | } | |
420 | ||
421 | /** | |
422 | * isci_parse_user_parameters() - This method will take user parameters | |
423 | * from the module init parameters and copy them to user_params. This will | |
424 | * only copy values that are not set to the module parameter default values | |
425 | * @user_parameters: This parameter specifies the controller default user | |
426 | * parameters. It is expected that this has been initialized to the default | |
427 | * parameters for the controller | |
428 | * | |
429 | * | |
430 | */ | |
431 | enum sci_status isci_parse_user_parameters( | |
432 | union scic_user_parameters *user_params, | |
433 | int scu_index, | |
434 | struct isci_firmware *fw) | |
435 | { | |
436 | int i; | |
437 | ||
438 | if (!(scu_index >= 0 | |
439 | && scu_index < SCI_MAX_CONTROLLERS | |
440 | && user_params != NULL)) { | |
441 | return SCI_FAILURE; | |
442 | } | |
443 | ||
444 | for (i = 0; i < SCI_MAX_PORTS; i++) { | |
445 | int array_idx = i + (SCI_MAX_PORTS * scu_index); | |
446 | u32 gen = fw->phy_gens[array_idx]; | |
447 | ||
448 | user_params->sds1.phys[i].max_speed_generation = gen; | |
449 | ||
450 | } | |
451 | ||
452 | return SCI_SUCCESS; | |
453 | } | |
454 | ||
455 | static struct isci_host *isci_host_alloc(struct pci_dev *pdev, int id) | |
456 | { | |
457 | struct isci_host *isci_host; | |
458 | struct Scsi_Host *shost; | |
459 | int err; | |
460 | ||
d9c37390 DW |
461 | isci_host = devm_kzalloc(&pdev->dev, sizeof(*isci_host) + |
462 | SCI_MAX_REMOTE_DEVICES * | |
463 | (sizeof(struct isci_remote_device) + | |
464 | scic_remote_device_get_object_size()), GFP_KERNEL); | |
6f231dda DW |
465 | if (!isci_host) |
466 | return NULL; | |
467 | ||
468 | isci_host->pdev = pdev; | |
469 | isci_host->id = id; | |
470 | ||
471 | shost = scsi_host_alloc(&isci_sht, sizeof(void *)); | |
472 | if (!shost) | |
473 | return NULL; | |
474 | isci_host->shost = shost; | |
475 | ||
476 | err = isci_host_init(isci_host); | |
477 | if (err) | |
478 | goto err_shost; | |
479 | ||
480 | SHOST_TO_SAS_HA(shost) = &isci_host->sas_ha; | |
481 | isci_host->sas_ha.core.shost = shost; | |
482 | shost->transportt = isci_transport_template; | |
483 | ||
484 | shost->max_id = ~0; | |
485 | shost->max_lun = ~0; | |
486 | shost->max_cmd_len = MAX_COMMAND_SIZE; | |
487 | ||
488 | err = scsi_add_host(shost, &pdev->dev); | |
489 | if (err) | |
490 | goto err_shost; | |
491 | ||
492 | err = isci_register_sas_ha(isci_host); | |
493 | if (err) | |
494 | goto err_shost_remove; | |
495 | ||
34cad85d DW |
496 | err = device_create_file(&shost->shost_dev, &dev_attr_isci_id); |
497 | if (err) | |
498 | goto err_unregister_ha; | |
499 | ||
6f231dda DW |
500 | return isci_host; |
501 | ||
34cad85d DW |
502 | err_unregister_ha: |
503 | sas_unregister_ha(&(isci_host->sas_ha)); | |
6f231dda DW |
504 | err_shost_remove: |
505 | scsi_remove_host(shost); | |
506 | err_shost: | |
507 | scsi_host_put(shost); | |
508 | ||
509 | return NULL; | |
510 | } | |
511 | ||
512 | static void check_si_rev(struct pci_dev *pdev) | |
513 | { | |
514 | if (num_controllers(pdev) > 1) | |
515 | isci_si_rev = ISCI_SI_REVB0; | |
516 | else { | |
517 | switch (pdev->revision) { | |
518 | case 0: | |
519 | case 1: | |
520 | /* if the id is ambiguous don't update isci_si_rev */ | |
521 | break; | |
522 | case 3: | |
523 | isci_si_rev = ISCI_SI_REVA2; | |
524 | break; | |
525 | default: | |
526 | case 4: | |
527 | isci_si_rev = ISCI_SI_REVB0; | |
528 | break; | |
529 | } | |
530 | } | |
531 | ||
532 | dev_info(&pdev->dev, "driver configured for %s silicon (rev: %d)\n", | |
533 | isci_si_rev == ISCI_SI_REVA0 ? "A0" : | |
534 | isci_si_rev == ISCI_SI_REVA2 ? "A2" : "B0", pdev->revision); | |
535 | ||
536 | } | |
537 | ||
858d4aa7 DJ |
538 | static int isci_verify_firmware(const struct firmware *fw, |
539 | struct isci_firmware *isci_fw) | |
540 | { | |
541 | const u8 *tmp; | |
542 | ||
543 | if (fw->size < ISCI_FIRMWARE_MIN_SIZE) | |
544 | return -EINVAL; | |
545 | ||
546 | tmp = fw->data; | |
547 | ||
548 | /* 12th char should be the NULL terminate for the ID string */ | |
549 | if (tmp[11] != '\0') | |
550 | return -EINVAL; | |
551 | ||
552 | if (strncmp("#SCU MAGIC#", tmp, 11) != 0) | |
553 | return -EINVAL; | |
554 | ||
555 | isci_fw->id = tmp; | |
556 | isci_fw->version = fw->data[ISCI_FW_VER_OFS]; | |
557 | isci_fw->subversion = fw->data[ISCI_FW_SUBVER_OFS]; | |
558 | ||
559 | tmp = fw->data + ISCI_FW_DATA_OFS; | |
560 | ||
561 | while (*tmp != ISCI_FW_HDR_EOF) { | |
562 | switch (*tmp) { | |
563 | case ISCI_FW_HDR_PHYMASK: | |
564 | tmp++; | |
565 | isci_fw->phy_masks_size = *tmp; | |
566 | tmp++; | |
567 | isci_fw->phy_masks = (const u32 *)tmp; | |
568 | tmp += sizeof(u32) * isci_fw->phy_masks_size; | |
569 | break; | |
570 | ||
571 | case ISCI_FW_HDR_PHYGEN: | |
572 | tmp++; | |
573 | isci_fw->phy_gens_size = *tmp; | |
574 | tmp++; | |
575 | isci_fw->phy_gens = (const u32 *)tmp; | |
576 | tmp += sizeof(u32) * isci_fw->phy_gens_size; | |
577 | break; | |
578 | ||
579 | case ISCI_FW_HDR_SASADDR: | |
580 | tmp++; | |
581 | isci_fw->sas_addrs_size = *tmp; | |
582 | tmp++; | |
583 | isci_fw->sas_addrs = (const u64 *)tmp; | |
584 | tmp += sizeof(u64) * isci_fw->sas_addrs_size; | |
585 | break; | |
586 | ||
587 | default: | |
588 | pr_err("bad field in firmware binary blob\n"); | |
589 | return -EINVAL; | |
590 | } | |
591 | } | |
592 | ||
593 | pr_info("isci firmware v%u.%u loaded.\n", | |
594 | isci_fw->version, isci_fw->subversion); | |
595 | ||
596 | return SCI_SUCCESS; | |
597 | } | |
598 | ||
6f231dda DW |
599 | static int __devinit isci_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id) |
600 | { | |
601 | struct isci_pci_info *pci_info; | |
602 | int err, i; | |
603 | struct isci_host *isci_host; | |
858d4aa7 | 604 | const struct firmware *fw = NULL; |
6f231dda DW |
605 | |
606 | check_si_rev(pdev); | |
607 | ||
608 | pci_info = devm_kzalloc(&pdev->dev, sizeof(*pci_info), GFP_KERNEL); | |
609 | if (!pci_info) | |
610 | return -ENOMEM; | |
611 | pci_set_drvdata(pdev, pci_info); | |
612 | ||
858d4aa7 DJ |
613 | err = request_firmware(&fw, ISCI_FW_NAME, &pdev->dev); |
614 | if (err) { | |
615 | dev_warn(&pdev->dev, | |
616 | "Loading firmware failed, using default values\n"); | |
617 | dev_warn(&pdev->dev, | |
618 | "Default OEM configuration being used:" | |
619 | " 4 narrow ports, and default SAS Addresses\n"); | |
620 | } else { | |
621 | isci_firmware = devm_kzalloc(&pdev->dev, | |
622 | sizeof(struct isci_firmware), | |
623 | GFP_KERNEL); | |
624 | if (isci_firmware) { | |
625 | err = isci_verify_firmware(fw, isci_firmware); | |
626 | if (err != SCI_SUCCESS) { | |
627 | dev_warn(&pdev->dev, | |
628 | "firmware verification failed\n"); | |
629 | dev_warn(&pdev->dev, | |
630 | "Default OEM configuration being used:" | |
631 | " 4 narrow ports, and default SAS " | |
632 | "Addresses\n"); | |
633 | devm_kfree(&pdev->dev, isci_firmware); | |
634 | isci_firmware = NULL; | |
635 | } | |
636 | } | |
637 | release_firmware(fw); | |
638 | } | |
639 | ||
6f231dda DW |
640 | err = isci_pci_init(pdev); |
641 | if (err) | |
642 | return err; | |
643 | ||
644 | for (i = 0; i < num_controllers(pdev); i++) { | |
645 | struct isci_host *h = isci_host_alloc(pdev, i); | |
646 | ||
647 | if (!h) { | |
648 | err = -ENOMEM; | |
649 | goto err_host_alloc; | |
650 | } | |
b329aff1 | 651 | pci_info->hosts[i] = h; |
6f231dda DW |
652 | } |
653 | ||
654 | err = isci_setup_interrupts(pdev); | |
655 | if (err) | |
656 | goto err_host_alloc; | |
657 | ||
b329aff1 | 658 | for_each_isci_host(i, isci_host, pdev) |
6f231dda DW |
659 | scsi_scan_host(isci_host->shost); |
660 | ||
661 | return 0; | |
662 | ||
663 | err_host_alloc: | |
b329aff1 | 664 | for_each_isci_host(i, isci_host, pdev) |
34cad85d | 665 | isci_unregister(isci_host); |
6f231dda DW |
666 | return err; |
667 | } | |
668 | ||
669 | static void __devexit isci_pci_remove(struct pci_dev *pdev) | |
670 | { | |
671 | struct isci_host *isci_host; | |
b329aff1 | 672 | int i; |
6f231dda | 673 | |
b329aff1 | 674 | for_each_isci_host(i, isci_host, pdev) { |
34cad85d | 675 | isci_unregister(isci_host); |
6f231dda DW |
676 | isci_host_deinit(isci_host); |
677 | scic_controller_disable_interrupts(isci_host->core_controller); | |
678 | } | |
679 | } | |
680 | ||
681 | static __init int isci_init(void) | |
682 | { | |
d9c37390 | 683 | int err; |
6f231dda DW |
684 | |
685 | pr_info("%s: Intel(R) C600 SAS Controller Driver\n", DRV_NAME); | |
686 | ||
6f231dda DW |
687 | isci_transport_template = sas_domain_attach_transport(&isci_transport_ops); |
688 | if (!isci_transport_template) | |
d9c37390 | 689 | return -ENOMEM; |
6f231dda DW |
690 | |
691 | err = pci_register_driver(&isci_pci_driver); | |
692 | if (err) | |
d9c37390 | 693 | sas_release_transport(isci_transport_template); |
6f231dda DW |
694 | |
695 | return err; | |
696 | } | |
697 | ||
698 | static __exit void isci_exit(void) | |
699 | { | |
700 | pci_unregister_driver(&isci_pci_driver); | |
701 | sas_release_transport(isci_transport_template); | |
6f231dda DW |
702 | } |
703 | ||
704 | MODULE_LICENSE("Dual BSD/GPL"); | |
705 | MODULE_FIRMWARE(ISCI_FW_NAME); | |
706 | module_init(isci_init); | |
707 | module_exit(isci_exit); |