staticvoid asd_propagate_sas_addr(struct asd_ha_struct *asd_ha)
{ int i;
for (i = 0; i < ASD_MAX_PHYS; i++) { if (asd_ha->hw_prof.phy_desc[i].sas_addr[0] == 0) continue; /* Set a phy's address only if it has none.
*/
ASD_DPRINTK("setting phy%d addr to %llx\n", i,
SAS_ADDR(asd_ha->hw_prof.sas_addr));
memcpy(asd_ha->hw_prof.phy_desc[i].sas_addr,
asd_ha->hw_prof.sas_addr, SAS_ADDR_SIZE);
}
}
phy->id_frm_tok = asd_alloc_coherent(asd_ha, sizeof(*phy->identify_frame),
GFP_KERNEL); if (!phy->id_frm_tok) {
asd_printk("no mem for IDENTIFY for phy%d\n", sas_phy->id); return -ENOMEM;
} else
asd_init_phy_identify(phy);
/* Now enable and initialize only the enabled phys. */
for_each_phy(phy_mask, phy_mask, i) { int err = asd_init_phy(&asd_ha->phys[i]); if (err) return err;
}
/* Unlock MBARs */
err = pci_read_config_dword(pcidev, PCI_CONF_MBAR_KEY, &v); if (err) {
asd_printk("couldn't access conf. space of %s\n",
pci_name(pcidev)); goto Err;
} if (v)
err = pci_write_config_dword(pcidev, PCI_CONF_MBAR_KEY, v); if (err) {
asd_printk("couldn't write to MBAR_KEY of %s\n",
pci_name(pcidev)); goto Err;
}
/* Set sliding windows A, B and C to point to proper internal * memory regions.
*/
pci_write_config_dword(pcidev, PCI_CONF_MBAR0_SWA, REG_BASE_ADDR);
pci_write_config_dword(pcidev, PCI_CONF_MBAR0_SWB,
REG_BASE_ADDR_CSEQCIO);
pci_write_config_dword(pcidev, PCI_CONF_MBAR0_SWC, REG_BASE_ADDR_EXSI);
asd_ha->io_handle[0].swa_base = REG_BASE_ADDR;
asd_ha->io_handle[0].swb_base = REG_BASE_ADDR_CSEQCIO;
asd_ha->io_handle[0].swc_base = REG_BASE_ADDR_EXSI;
MBAR0_SWB_SIZE = asd_ha->io_handle[0].len - 0x80; if (!asd_ha->iospace) { /* MBAR1 will point to OCM (On Chip Memory) */
pci_write_config_dword(pcidev, PCI_CONF_MBAR1, OCM_BASE_ADDR);
asd_ha->io_handle[1].swa_base = OCM_BASE_ADDR;
}
spin_lock_init(&asd_ha->iolock);
Err: return err;
}
/* ---------- 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.
*/ staticint asd_init_scbs(struct asd_ha_struct *asd_ha)
{ struct asd_seq_data *seq = &asd_ha->seq; int bitmap_bytes;
/* allocate the index array and bitmap */
asd_ha->seq.tc_index_bitmap_bits = asd_ha->hw_prof.max_scbs;
asd_ha->seq.tc_index_array = kcalloc(asd_ha->seq.tc_index_bitmap_bits, sizeof(void *),
GFP_KERNEL); if (!asd_ha->seq.tc_index_array) return -ENOMEM;
/** * 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.
*/ staticint asd_init_escbs(struct asd_ha_struct *asd_ha)
{ struct asd_seq_data *seq = &asd_ha->seq; int err = 0;
/* Allocate two empty data buffers (edb) per sequencer. */ int edbs = 2*(1+asd_ha->hw_prof.num_phys);
asd_assign_edbs2escbs(asd_ha); /* In order to insure that normal SCBs do not overfill sequencer * memory and leave no space for escbs (halting condition), * we increment pending here by the number of escbs. However, * escbs are never pending.
*/
seq->pending = seq->num_escbs;
seq->can_queue = 1 + (asd_ha->hw_prof.max_scbs - seq->pending)/2;
return 0;
}
/* ---------- 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)
{ int i; int count = 100;
u32 reg;
for (i = 0 ; i < 4 ; i++) {
asd_write_reg_dword(asd_ha, COMBIST, HARDRST);
}
do {
udelay(1);
reg = asd_read_reg_dword(asd_ha, CHIMINT); if (reg & HARDRSTDET) {
asd_write_reg_dword(asd_ha, CHIMINT,
HARDRSTDET|PORRSTDET); return 0;
}
} while (--count > 0);
return -ENODEV;
}
/** * 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).
*/ staticint asd_init_chip(struct asd_ha_struct *asd_ha)
{ int err;
err = asd_chip_hardrst(asd_ha); if (err) {
asd_printk("couldn't hard reset %s\n",
pci_name(asd_ha->pcidev)); goto out;
}
asd_disable_ints(asd_ha);
err = asd_init_seqs(asd_ha); if (err) {
asd_printk("couldn't init seqs for %s\n",
pci_name(asd_ha->pcidev)); goto out;
}
err = asd_start_seqs(asd_ha); if (err) {
asd_printk("couldn't start seqs for %s\n",
pci_name(asd_ha->pcidev)); goto out;
}
out: return err;
}
staticint max_devs = 0;
module_param_named(max_devs, max_devs, int, S_IRUGO);
MODULE_PARM_DESC(max_devs, "\n" "\tMaximum number of SAS devices to support (not LUs).\n" "\tDefault: 2176, Maximum: 65663.\n");
staticint max_cmnds = 0;
module_param_named(max_cmnds, max_cmnds, int, S_IRUGO);
MODULE_PARM_DESC(max_cmnds, "\n" "\tMaximum number of commands queuable.\n" "\tDefault: 512, Maximum: 66047.\n");
/** * 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.
*/ staticint asd_init_ctxmem(struct asd_ha_struct *asd_ha)
{ int bitmap_bytes;
/* The kernel wants bitmaps to be unsigned long sized. */
bitmap_bytes = (asd_ha->hw_prof.max_ddbs+7)/8;
bitmap_bytes = BITS_TO_LONGS(bitmap_bytes*8)*sizeof(unsignedlong);
asd_ha->hw_prof.ddb_bitmap = kzalloc(bitmap_bytes, GFP_KERNEL); if (!asd_ha->hw_prof.ddb_bitmap) return -ENOMEM;
spin_lock_init(&asd_ha->hw_prof.ddb_lock);
return 0;
}
int asd_init_hw(struct asd_ha_struct *asd_ha)
{ int err;
u32 v;
err = asd_init_sw(asd_ha); if (err) return err;
err = pci_read_config_dword(asd_ha->pcidev, PCIC_HSTPCIX_CNTRL, &v); if (err) {
asd_printk("couldn't read PCIC_HSTPCIX_CNTRL of %s\n",
pci_name(asd_ha->pcidev)); return err;
}
err = pci_write_config_dword(asd_ha->pcidev, PCIC_HSTPCIX_CNTRL,
v | SC_TMR_DIS); if (err) {
asd_printk("couldn't disable split completion timer of %s\n",
pci_name(asd_ha->pcidev)); return err;
}
err = asd_read_ocm(asd_ha); if (err) {
asd_printk("couldn't read ocm(%d)\n", err); /* While suspicios, it is not an error that we
* couldn't read the OCM. */
}
err = asd_read_flash(asd_ha); if (err) {
asd_printk("couldn't read flash(%d)\n", err); /* While suspicios, it is not an error that we * couldn't read FLASH memory.
*/
}
asd_init_ctxmem(asd_ha);
if (asd_get_user_sas_addr(asd_ha)) {
asd_printk("No SAS Address provided for %s\n",
pci_name(asd_ha->pcidev));
err = -ENODEV; goto Out;
}
asd_propagate_sas_addr(asd_ha);
err = asd_init_phys(asd_ha); if (err) {
asd_printk("couldn't initialize phys for %s\n",
pci_name(asd_ha->pcidev)); goto Out;
}
asd_init_ports(asd_ha);
err = asd_init_scbs(asd_ha); if (err) {
asd_printk("couldn't initialize scbs for %s\n",
pci_name(asd_ha->pcidev)); goto Out;
}
err = asd_init_dl(asd_ha); if (err) {
asd_printk("couldn't initialize the done list:%d\n",
err); goto Out;
}
err = asd_init_chip(asd_ha); if (err) {
asd_printk("couldn't init the chip\n"); goto Out;
}
Out: return err;
}
/* ---------- 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.
*/ staticvoid asd_chip_reset(struct asd_ha_struct *asd_ha)
{
ASD_DPRINTK("chip reset for %s\n", pci_name(asd_ha->pcidev));
asd_chip_hardrst(asd_ha);
}
if (chimint & DLAVAIL)
asd_process_donelist_isr(asd_ha); if (chimint & COMINT)
asd_com_sas_isr(asd_ha); if (chimint & DEVINT)
asd_dch_sas_isr(asd_ha); if (chimint & INITERR)
asd_rbi_exsi_isr(asd_ha); if (chimint & HOSTERR)
asd_hst_pcix_isr(asd_ha);
return ascb;
undo:
dma_pool_free(asd_ha->scb_pool, ascb->dma_scb.vaddr,
ascb->dma_scb.dma_handle);
kmem_cache_free(asd_ascb_cache, ascb);
ASD_DPRINTK("no index for ascb\n"); return NULL;
}
/** * 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)
{ struct asd_ascb *first = NULL;
/** * 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.
*/ staticvoid asd_swap_head_scb(struct asd_ha_struct *asd_ha, struct asd_ascb *ascb)
{ struct asd_seq_data *seq = &asd_ha->seq; struct asd_ascb *last = list_entry(ascb->list.prev, struct asd_ascb,
list); struct asd_dma_tok t = ascb->dma_scb;
/** * 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.
*/ staticvoid asd_start_scb_timers(struct list_head *list)
{ struct asd_ascb *ascb;
list_for_each_entry(ascb, list, list) { if (!ascb->uldd_timer) {
ascb->timer.function = asd_ascb_timedout;
ascb->timer.expires = jiffies + AIC94XX_SCB_TIMEOUT;
add_timer(&ascb->timer);
}
}
}
/** * 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)
{ unsignedlong flags;
LIST_HEAD(list); int can_queue;
/** * 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)
{ unsignedlong flags;
/** * 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)
{ if (phy_id < ASD_MAX_PHYS) {
u32 v = asd_read_reg_dword(asd_ha, LmCONTROL(phy_id)); if (op)
v |= LEDPOL; else
v &= ~LEDPOL;
asd_write_reg_dword(asd_ha, LmCONTROL(phy_id), v);
}
}
/** * 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)
{ if (phy_id < ASD_MAX_PHYS) {
u32 v;
v = asd_read_reg_dword(asd_ha, GPIOOER); if (op)
v |= (1 << phy_id); else
v &= ~(1 << phy_id);
asd_write_reg_dword(asd_ha, GPIOOER, v);
v = asd_read_reg_dword(asd_ha, GPIOCNFGR); if (op)
v |= (1 << phy_id); else
v &= ~(1 << phy_id);
asd_write_reg_dword(asd_ha, GPIOCNFGR, v);
}
}
/* Get defaults from manuf. sector */ /* XXX we need defaults for those in case MS is broken. */
asd_write_reg_byte(asd_ha, LmSEQ_OOB_REG(phy_id, PHY_CONTROL_0),
phy->phy_desc->phy_control_0);
asd_write_reg_byte(asd_ha, LmSEQ_OOB_REG(phy_id, PHY_CONTROL_1),
phy->phy_desc->phy_control_1);
asd_write_reg_byte(asd_ha, LmSEQ_OOB_REG(phy_id, PHY_CONTROL_2),
phy->phy_desc->phy_control_2);
asd_write_reg_byte(asd_ha, LmSEQ_OOB_REG(phy_id, PHY_CONTROL_3),
phy->phy_desc->phy_control_3);
k = num;
ascb_list = asd_ascb_alloc_list(asd_ha, &k, GFP_KERNEL); if (!ascb_list) {
asd_printk("no memory for control phy ascb list\n"); return -ENOMEM;
}
num -= k;
ascb = ascb_list;
for_each_phy(phy_mask, phy_m, i) {
asd_build_control_phy(ascb, i, ENABLE_PHY);
ascb = list_entry(ascb->list.next, struct asd_ascb, list);
}
ASD_DPRINTK("posting %d control phy scbs\n", num);
k = asd_post_ascb_list(asd_ha, ascb_list, num); if (k)
asd_ascb_free_list(ascb_list);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.