// SPDX-License-Identifier: GPL-2.0-only /* * Libata driver for the highpoint 37x and 30x UDMA66 ATA controllers. * * This driver is heavily based upon: * * linux/drivers/ide/pci/hpt366.c Version 0.36 April 25, 2003 * * Copyright (C) 1999-2003 Andre Hedrick <[email protected]> * Portions Copyright (C) 2001 Sun Microsystems, Inc. * Portions Copyright (C) 2003 Red Hat Inc * Portions Copyright (C) 2005-2010 MontaVista Software, Inc. * * TODO * Look into engine reset on timeout errors. Should not be required. */ #include <linux/kernel.h> #include <linux/module.h> #include <linux/pci.h> #include <linux/blkdev.h> #include <linux/delay.h> #include <scsi/scsi_host.h> #include <linux/libata.h> #define DRV_NAME … #define DRV_VERSION … struct hpt_clock { … }; struct hpt_chip { … }; /* key for bus clock timings * bit * 0:3 data_high_time. Inactive time of DIOW_/DIOR_ for PIO and MW DMA. * cycles = value + 1 * 4:8 data_low_time. Active time of DIOW_/DIOR_ for PIO and MW DMA. * cycles = value + 1 * 9:12 cmd_high_time. Inactive time of DIOW_/DIOR_ during task file * register access. * 13:17 cmd_low_time. Active time of DIOW_/DIOR_ during task file * register access. * 18:20 udma_cycle_time. Clock cycles for UDMA xfer. * 21 CLK frequency for UDMA: 0=ATA clock, 1=dual ATA clock. * 22:24 pre_high_time. Time to initialize 1st cycle for PIO and MW DMA xfer. * 25:27 cmd_pre_high_time. Time to initialize 1st PIO cycle for task file * register access. * 28 UDMA enable. * 29 DMA enable. * 30 PIO_MST enable. If set, the chip is in bus master mode during * PIO xfer. * 31 FIFO enable. Only for PIO. */ static struct hpt_clock hpt37x_timings_33[] = …; static struct hpt_clock hpt37x_timings_50[] = …; static struct hpt_clock hpt37x_timings_66[] = …; static const struct hpt_chip hpt370 = …; static const struct hpt_chip hpt370a = …; static const struct hpt_chip hpt372 = …; static const struct hpt_chip hpt302 = …; static const struct hpt_chip hpt371 = …; static const struct hpt_chip hpt372a = …; static const struct hpt_chip hpt374 = …; /** * hpt37x_find_mode - reset the hpt37x bus * @ap: ATA port * @speed: transfer mode * * Return the 32bit register programming information for this channel * that matches the speed provided. */ static u32 hpt37x_find_mode(struct ata_port *ap, int speed) { … } static int hpt_dma_blacklisted(const struct ata_device *dev, char *modestr, const char * const list[]) { … } static const char * const bad_ata33[] = …; static const char * const bad_ata100_5[] = …; /** * hpt370_filter - mode selection filter * @adev: ATA device * @mask: mode mask * * Block UDMA on devices that cause trouble with this controller. */ static unsigned int hpt370_filter(struct ata_device *adev, unsigned int mask) { … } /** * hpt370a_filter - mode selection filter * @adev: ATA device * @mask: mode mask * * Block UDMA on devices that cause trouble with this controller. */ static unsigned int hpt370a_filter(struct ata_device *adev, unsigned int mask) { … } /** * hpt372_filter - mode selection filter * @adev: ATA device * @mask: mode mask * * The Marvell bridge chips used on the HighPoint SATA cards do not seem * to support the UltraDMA modes 1, 2, and 3 as well as any MWDMA modes... */ static unsigned int hpt372_filter(struct ata_device *adev, unsigned int mask) { … } /** * hpt37x_cable_detect - Detect the cable type * @ap: ATA port to detect on * * Return the cable type attached to this port */ static int hpt37x_cable_detect(struct ata_port *ap) { … } /** * hpt374_fn1_cable_detect - Detect the cable type * @ap: ATA port to detect on * * Return the cable type attached to this port */ static int hpt374_fn1_cable_detect(struct ata_port *ap) { … } /** * hpt37x_pre_reset - reset the hpt37x bus * @link: ATA link to reset * @deadline: deadline jiffies for the operation * * Perform the initial reset handling for the HPT37x. */ static int hpt37x_pre_reset(struct ata_link *link, unsigned long deadline) { … } static void hpt37x_set_mode(struct ata_port *ap, struct ata_device *adev, u8 mode) { … } /** * hpt37x_set_piomode - PIO setup * @ap: ATA interface * @adev: device on the interface * * Perform PIO mode setup. */ static void hpt37x_set_piomode(struct ata_port *ap, struct ata_device *adev) { … } /** * hpt37x_set_dmamode - DMA timing setup * @ap: ATA interface * @adev: Device being configured * * Set up the channel for MWDMA or UDMA modes. */ static void hpt37x_set_dmamode(struct ata_port *ap, struct ata_device *adev) { … } /** * hpt370_bmdma_stop - DMA engine stop * @qc: ATA command * * Work around the HPT370 DMA engine. */ static void hpt370_bmdma_stop(struct ata_queued_cmd *qc) { … } /** * hpt37x_bmdma_stop - DMA engine stop * @qc: ATA command * * Clean up after the HPT372 and later DMA engine */ static void hpt37x_bmdma_stop(struct ata_queued_cmd *qc) { … } static const struct scsi_host_template hpt37x_sht = …; /* * Configuration for HPT370 */ static struct ata_port_operations hpt370_port_ops = …; /* * Configuration for HPT370A. Close to 370 but less filters */ static struct ata_port_operations hpt370a_port_ops = …; /* * Configuration for HPT371 and HPT302. */ static struct ata_port_operations hpt302_port_ops = …; /* * Configuration for HPT372. Mode setting works like 371 and 302 * but we have a mode filter. */ static struct ata_port_operations hpt372_port_ops = …; /* * Configuration for HPT374. Mode setting and filtering works like 372 * but we have a different cable detection procedure for function 1. */ static struct ata_port_operations hpt374_fn1_port_ops = …; /** * hpt37x_clock_slot - Turn timing to PC clock entry * @freq: Reported frequency in MHz * * Turn the timing data into a clock slot (0 for 33, 1 for 40, 2 for 50 * and 3 for 66Mhz) */ static int hpt37x_clock_slot(unsigned int freq) { … } /** * hpt37x_calibrate_dpll - Calibrate the DPLL loop * @dev: PCI device * * Perform a calibration cycle on the HPT37x DPLL. Returns 1 if this * succeeds */ static int hpt37x_calibrate_dpll(struct pci_dev *dev) { … } static int hpt37x_pci_clock(struct pci_dev *pdev, unsigned int base) { … } /** * hpt37x_init_one - Initialise an HPT37X/302 * @dev: PCI device * @id: Entry in match table * * Initialise an HPT37x device. There are some interesting complications * here. Firstly the chip may report 366 and be one of several variants. * Secondly all the timings depend on the clock for the chip which we must * detect and look up * * This is the known chip mappings. It may be missing a couple of later * releases. * * Chip version PCI Rev Notes * HPT366 4 (HPT366) 0 Other driver * HPT366 4 (HPT366) 1 Other driver * HPT368 4 (HPT366) 2 Other driver * HPT370 4 (HPT366) 3 UDMA100 * HPT370A 4 (HPT366) 4 UDMA100 * HPT372 4 (HPT366) 5 UDMA133 (1) * HPT372N 4 (HPT366) 6 Other driver * HPT372A 5 (HPT372) 1 UDMA133 (1) * HPT372N 5 (HPT372) 2 Other driver * HPT302 6 (HPT302) 1 UDMA133 * HPT302N 6 (HPT302) 2 Other driver * HPT371 7 (HPT371) * UDMA133 * HPT374 8 (HPT374) * UDMA133 4 channel * HPT372N 9 (HPT372N) * Other driver * * (1) UDMA133 support depends on the bus clock */ static int hpt37x_init_one(struct pci_dev *dev, const struct pci_device_id *id) { … } static const struct pci_device_id hpt37x[] = …; static struct pci_driver hpt37x_pci_driver = …; module_pci_driver(…) …; MODULE_AUTHOR(…) …; MODULE_DESCRIPTION(…) …; MODULE_LICENSE(…) …; MODULE_DEVICE_TABLE(pci, hpt37x); MODULE_VERSION(…);