// SPDX-License-Identifier: GPL-2.0-only /* * Aic94xx SAS/SATA driver hardware interface. * * Copyright (C) 2005 Adaptec, Inc. All rights reserved. * Copyright (C) 2005 Luben Tuikov <[email protected]> */ #include <linux/pci.h> #include <linux/slab.h> #include <linux/delay.h> #include <linux/module.h> #include <linux/firmware.h> #include "aic94xx.h" #include "aic94xx_reg.h" #include "aic94xx_hwi.h" #include "aic94xx_seq.h" #include "aic94xx_dump.h" u32 MBAR0_SWB_SIZE; /* ---------- Initialization ---------- */ static int asd_get_user_sas_addr(struct asd_ha_struct *asd_ha) { … } static void asd_propagate_sas_addr(struct asd_ha_struct *asd_ha) { … } /* ---------- PHY initialization ---------- */ static void asd_init_phy_identify(struct asd_phy *phy) { … } static int asd_init_phy(struct asd_phy *phy) { … } static void asd_init_ports(struct asd_ha_struct *asd_ha) { … } static int asd_init_phys(struct asd_ha_struct *asd_ha) { … } /* ---------- Sliding windows ---------- */ static int asd_init_sw(struct asd_ha_struct *asd_ha) { … } /* ---------- SCB initialization ---------- */ /** * asd_init_scbs - manually allocate the first SCB. * @asd_ha: pointer to host adapter structure * * This allocates the very first SCB which would be sent to the * sequencer for execution. Its bus address is written to * CSEQ_Q_NEW_POINTER, mode page 2, mode 8. Since the bus address of * the _next_ scb to be DMA-ed to the host adapter is read from the last * SCB DMA-ed to the host adapter, we have to always stay one step * ahead of the sequencer and keep one SCB already allocated. */ static int asd_init_scbs(struct asd_ha_struct *asd_ha) { … } static void asd_get_max_scb_ddb(struct asd_ha_struct *asd_ha) { … } /* ---------- Done List initialization ---------- */ static void asd_dl_tasklet_handler(unsigned long); static int asd_init_dl(struct asd_ha_struct *asd_ha) { … } /* ---------- EDB and ESCB init ---------- */ static int asd_alloc_edbs(struct asd_ha_struct *asd_ha, gfp_t gfp_flags) { … } static int asd_alloc_escbs(struct asd_ha_struct *asd_ha, gfp_t gfp_flags) { … } static void asd_assign_edbs2escbs(struct asd_ha_struct *asd_ha) { … } /** * asd_init_escbs -- allocate and initialize empty scbs * @asd_ha: pointer to host adapter structure * * An empty SCB has sg_elements of ASD_EDBS_PER_SCB (7) buffers. * They transport sense data, etc. */ static int asd_init_escbs(struct asd_ha_struct *asd_ha) { … } /* ---------- HW initialization ---------- */ /** * asd_chip_hardrst -- hard reset the chip * @asd_ha: pointer to host adapter structure * * This takes 16 cycles and is synchronous to CFCLK, which runs * at 200 MHz, so this should take at most 80 nanoseconds. */ int asd_chip_hardrst(struct asd_ha_struct *asd_ha) { … } /** * asd_init_chip -- initialize the chip * @asd_ha: pointer to host adapter structure * * Hard resets the chip, disables HA interrupts, downloads the sequnecer * microcode and starts the sequencers. The caller has to explicitly * enable HA interrupts with asd_enable_ints(asd_ha). */ static int asd_init_chip(struct asd_ha_struct *asd_ha) { … } #define MAX_DEVS … static int max_devs = …; module_param_named(max_devs, max_devs, int, S_IRUGO); MODULE_PARM_DESC(…) …; static int max_cmnds = …; module_param_named(max_cmnds, max_cmnds, int, S_IRUGO); MODULE_PARM_DESC(…) …; static void asd_extend_devctx_ocm(struct asd_ha_struct *asd_ha) { … } static int asd_extend_devctx(struct asd_ha_struct *asd_ha) { … } static int asd_extend_cmdctx(struct asd_ha_struct *asd_ha) { … } /** * asd_init_ctxmem -- initialize context memory * @asd_ha: pointer to host adapter structure * * This function sets the maximum number of SCBs and * DDBs which can be used by the sequencer. This is normally * 512 and 128 respectively. If support for more SCBs or more DDBs * is required then CMDCTXBASE, DEVCTXBASE and CTXDOMAIN are * initialized here to extend context memory to point to host memory, * thus allowing unlimited support for SCBs and DDBs -- only limited * by host memory. */ static int asd_init_ctxmem(struct asd_ha_struct *asd_ha) { … } int asd_init_hw(struct asd_ha_struct *asd_ha) { … } /* ---------- Chip reset ---------- */ /** * asd_chip_reset -- reset the host adapter, etc * @asd_ha: pointer to host adapter structure of interest * * Called from the ISR. Hard reset the chip. Let everything * timeout. This should be no different than hot-unplugging the * host adapter. Once everything times out we'll init the chip with * a call to asd_init_chip() and enable interrupts with asd_enable_ints(). * XXX finish. */ static void asd_chip_reset(struct asd_ha_struct *asd_ha) { … } /* ---------- Done List Routines ---------- */ static void asd_dl_tasklet_handler(unsigned long data) { … } /* ---------- Interrupt Service Routines ---------- */ /** * asd_process_donelist_isr -- schedule processing of done list entries * @asd_ha: pointer to host adapter structure */ static void asd_process_donelist_isr(struct asd_ha_struct *asd_ha) { … } /** * asd_com_sas_isr -- process device communication interrupt (COMINT) * @asd_ha: pointer to host adapter structure */ static void asd_com_sas_isr(struct asd_ha_struct *asd_ha) { … } static void asd_arp2_err(struct asd_ha_struct *asd_ha, u32 dchstatus) { … } /** * asd_dch_sas_isr -- process device channel interrupt (DEVINT) * @asd_ha: pointer to host adapter structure */ static void asd_dch_sas_isr(struct asd_ha_struct *asd_ha) { … } /** * asd_rbi_exsi_isr -- process external system interface interrupt (INITERR) * @asd_ha: pointer to host adapter structure */ static void asd_rbi_exsi_isr(struct asd_ha_struct *asd_ha) { … } /** * asd_hst_pcix_isr -- process host interface interrupts * @asd_ha: pointer to host adapter structure * * Asserted on PCIX errors: target abort, etc. */ static void asd_hst_pcix_isr(struct asd_ha_struct *asd_ha) { … } /** * asd_hw_isr -- host adapter interrupt service routine * @irq: ignored * @dev_id: pointer to host adapter structure * * The ISR processes done list entries and level 3 error handling. */ irqreturn_t asd_hw_isr(int irq, void *dev_id) { … } /* ---------- SCB handling ---------- */ static struct asd_ascb *asd_ascb_alloc(struct asd_ha_struct *asd_ha, gfp_t gfp_flags) { … } /** * asd_ascb_alloc_list -- allocate a list of aSCBs * @asd_ha: pointer to host adapter structure * @num: pointer to integer number of aSCBs * @gfp_flags: GFP_ flags. * * This is the only function which is used to allocate aSCBs. * It can allocate one or many. If more than one, then they form * a linked list in two ways: by their list field of the ascb struct * and by the next_scb field of the scb_header. * * Returns NULL if no memory was available, else pointer to a list * of ascbs. When this function returns, @num would be the number * of SCBs which were not able to be allocated, 0 if all requested * were able to be allocated. */ struct asd_ascb *asd_ascb_alloc_list(struct asd_ha_struct *asd_ha, int *num, gfp_t gfp_flags) { … } /** * asd_swap_head_scb -- swap the head scb * @asd_ha: pointer to host adapter structure * @ascb: pointer to the head of an ascb list * * The sequencer knows the DMA address of the next SCB to be DMAed to * the host adapter, from initialization or from the last list DMAed. * seq->next_scb keeps the address of this SCB. The sequencer will * DMA to the host adapter this list of SCBs. But the head (first * element) of this list is not known to the sequencer. Here we swap * the head of the list with the known SCB (memcpy()). * Only one memcpy() is required per list so it is in our interest * to keep the list of SCB as long as possible so that the ratio * of number of memcpy calls to the number of SCB DMA-ed is as small * as possible. * * LOCKING: called with the pending list lock held. */ static void asd_swap_head_scb(struct asd_ha_struct *asd_ha, struct asd_ascb *ascb) { … } /** * asd_start_scb_timers -- (add and) start timers of SCBs * @list: pointer to struct list_head of the scbs * * If an SCB in the @list has no timer function, assign the default * one, then start the timer of the SCB. This function is * intended to be called from asd_post_ascb_list(), just prior to * posting the SCBs to the sequencer. */ static void asd_start_scb_timers(struct list_head *list) { … } /** * asd_post_ascb_list -- post a list of 1 or more aSCBs to the host adapter * @asd_ha: pointer to a host adapter structure * @ascb: pointer to the first aSCB in the list * @num: number of aSCBs in the list (to be posted) * * See queueing comment in asd_post_escb_list(). * * Additional note on queuing: In order to minimize the ratio of memcpy() * to the number of ascbs sent, we try to batch-send as many ascbs as possible * in one go. * Two cases are possible: * A) can_queue >= num, * B) can_queue < num. * Case A: we can send the whole batch at once. Increment "pending" * in the beginning of this function, when it is checked, in order to * eliminate races when this function is called by multiple processes. * Case B: should never happen. */ int asd_post_ascb_list(struct asd_ha_struct *asd_ha, struct asd_ascb *ascb, int num) { … } /** * asd_post_escb_list -- post a list of 1 or more empty scb * @asd_ha: pointer to a host adapter structure * @ascb: pointer to the first empty SCB in the list * @num: number of aSCBs in the list (to be posted) * * This is essentially the same as asd_post_ascb_list, but we do not * increment pending, add those to the pending list or get indexes. * See asd_init_escbs() and asd_init_post_escbs(). * * Since sending a list of ascbs is a superset of sending a single * ascb, this function exists to generalize this. More specifically, * when sending a list of those, we want to do only a _single_ * memcpy() at swap head, as opposed to for each ascb sent (in the * case of sending them one by one). That is, we want to minimize the * ratio of memcpy() operations to the number of ascbs sent. The same * logic applies to asd_post_ascb_list(). */ int asd_post_escb_list(struct asd_ha_struct *asd_ha, struct asd_ascb *ascb, int num) { … } /* ---------- LED ---------- */ /** * asd_turn_led -- turn on/off an LED * @asd_ha: pointer to host adapter structure * @phy_id: the PHY id whose LED we want to manupulate * @op: 1 to turn on, 0 to turn off */ void asd_turn_led(struct asd_ha_struct *asd_ha, int phy_id, int op) { … } /** * asd_control_led -- enable/disable an LED on the board * @asd_ha: pointer to host adapter structure * @phy_id: integer, the phy id * @op: integer, 1 to enable, 0 to disable the LED * * First we output enable the LED, then we set the source * to be an external module. */ void asd_control_led(struct asd_ha_struct *asd_ha, int phy_id, int op) { … } /* ---------- PHY enable ---------- */ static int asd_enable_phy(struct asd_ha_struct *asd_ha, int phy_id) { … } int asd_enable_phys(struct asd_ha_struct *asd_ha, const u8 phy_mask) { … }