Path: blob/master/drivers/infiniband/hw/qib/qib_init.c
15112 views
/*1* Copyright (c) 2006, 2007, 2008, 2009, 2010 QLogic Corporation.2* All rights reserved.3* Copyright (c) 2003, 2004, 2005, 2006 PathScale, Inc. All rights reserved.4*5* This software is available to you under a choice of one of two6* licenses. You may choose to be licensed under the terms of the GNU7* General Public License (GPL) Version 2, available from the file8* COPYING in the main directory of this source tree, or the9* OpenIB.org BSD license below:10*11* Redistribution and use in source and binary forms, with or12* without modification, are permitted provided that the following13* conditions are met:14*15* - Redistributions of source code must retain the above16* copyright notice, this list of conditions and the following17* disclaimer.18*19* - Redistributions in binary form must reproduce the above20* copyright notice, this list of conditions and the following21* disclaimer in the documentation and/or other materials22* provided with the distribution.23*24* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,25* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF26* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND27* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS28* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN29* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN30* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE31* SOFTWARE.32*/3334#include <linux/pci.h>35#include <linux/netdevice.h>36#include <linux/vmalloc.h>37#include <linux/delay.h>38#include <linux/idr.h>3940#include "qib.h"41#include "qib_common.h"4243/*44* min buffers we want to have per context, after driver45*/46#define QIB_MIN_USER_CTXT_BUFCNT 74748#define QLOGIC_IB_R_SOFTWARE_MASK 0xFF49#define QLOGIC_IB_R_SOFTWARE_SHIFT 2450#define QLOGIC_IB_R_EMULATOR_MASK (1ULL<<62)5152/*53* Number of ctxts we are configured to use (to allow for more pio54* buffers per ctxt, etc.) Zero means use chip value.55*/56ushort qib_cfgctxts;57module_param_named(cfgctxts, qib_cfgctxts, ushort, S_IRUGO);58MODULE_PARM_DESC(cfgctxts, "Set max number of contexts to use");5960/*61* If set, do not write to any regs if avoidable, hack to allow62* check for deranged default register values.63*/64ushort qib_mini_init;65module_param_named(mini_init, qib_mini_init, ushort, S_IRUGO);66MODULE_PARM_DESC(mini_init, "If set, do minimal diag init");6768unsigned qib_n_krcv_queues;69module_param_named(krcvqs, qib_n_krcv_queues, uint, S_IRUGO);70MODULE_PARM_DESC(krcvqs, "number of kernel receive queues per IB port");7172/*73* qib_wc_pat parameter:74* 0 is WC via MTRR75* 1 is WC via PAT76* If PAT initialization fails, code reverts back to MTRR77*/78unsigned qib_wc_pat = 1; /* default (1) is to use PAT, not MTRR */79module_param_named(wc_pat, qib_wc_pat, uint, S_IRUGO);80MODULE_PARM_DESC(wc_pat, "enable write-combining via PAT mechanism");8182struct workqueue_struct *qib_cq_wq;8384static void verify_interrupt(unsigned long);8586static struct idr qib_unit_table;87u32 qib_cpulist_count;88unsigned long *qib_cpulist;8990/* set number of contexts we'll actually use */91void qib_set_ctxtcnt(struct qib_devdata *dd)92{93if (!qib_cfgctxts) {94dd->cfgctxts = dd->first_user_ctxt + num_online_cpus();95if (dd->cfgctxts > dd->ctxtcnt)96dd->cfgctxts = dd->ctxtcnt;97} else if (qib_cfgctxts < dd->num_pports)98dd->cfgctxts = dd->ctxtcnt;99else if (qib_cfgctxts <= dd->ctxtcnt)100dd->cfgctxts = qib_cfgctxts;101else102dd->cfgctxts = dd->ctxtcnt;103}104105/*106* Common code for creating the receive context array.107*/108int qib_create_ctxts(struct qib_devdata *dd)109{110unsigned i;111int ret;112113/*114* Allocate full ctxtcnt array, rather than just cfgctxts, because115* cleanup iterates across all possible ctxts.116*/117dd->rcd = kzalloc(sizeof(*dd->rcd) * dd->ctxtcnt, GFP_KERNEL);118if (!dd->rcd) {119qib_dev_err(dd, "Unable to allocate ctxtdata array, "120"failing\n");121ret = -ENOMEM;122goto done;123}124125/* create (one or more) kctxt */126for (i = 0; i < dd->first_user_ctxt; ++i) {127struct qib_pportdata *ppd;128struct qib_ctxtdata *rcd;129130if (dd->skip_kctxt_mask & (1 << i))131continue;132133ppd = dd->pport + (i % dd->num_pports);134rcd = qib_create_ctxtdata(ppd, i);135if (!rcd) {136qib_dev_err(dd, "Unable to allocate ctxtdata"137" for Kernel ctxt, failing\n");138ret = -ENOMEM;139goto done;140}141rcd->pkeys[0] = QIB_DEFAULT_P_KEY;142rcd->seq_cnt = 1;143}144ret = 0;145done:146return ret;147}148149/*150* Common code for user and kernel context setup.151*/152struct qib_ctxtdata *qib_create_ctxtdata(struct qib_pportdata *ppd, u32 ctxt)153{154struct qib_devdata *dd = ppd->dd;155struct qib_ctxtdata *rcd;156157rcd = kzalloc(sizeof(*rcd), GFP_KERNEL);158if (rcd) {159INIT_LIST_HEAD(&rcd->qp_wait_list);160rcd->ppd = ppd;161rcd->dd = dd;162rcd->cnt = 1;163rcd->ctxt = ctxt;164dd->rcd[ctxt] = rcd;165166dd->f_init_ctxt(rcd);167168/*169* To avoid wasting a lot of memory, we allocate 32KB chunks170* of physically contiguous memory, advance through it until171* used up and then allocate more. Of course, we need172* memory to store those extra pointers, now. 32KB seems to173* be the most that is "safe" under memory pressure174* (creating large files and then copying them over175* NFS while doing lots of MPI jobs). The OOM killer can176* get invoked, even though we say we can sleep and this can177* cause significant system problems....178*/179rcd->rcvegrbuf_size = 0x8000;180rcd->rcvegrbufs_perchunk =181rcd->rcvegrbuf_size / dd->rcvegrbufsize;182rcd->rcvegrbuf_chunks = (rcd->rcvegrcnt +183rcd->rcvegrbufs_perchunk - 1) /184rcd->rcvegrbufs_perchunk;185}186return rcd;187}188189/*190* Common code for initializing the physical port structure.191*/192void qib_init_pportdata(struct qib_pportdata *ppd, struct qib_devdata *dd,193u8 hw_pidx, u8 port)194{195ppd->dd = dd;196ppd->hw_pidx = hw_pidx;197ppd->port = port; /* IB port number, not index */198199spin_lock_init(&ppd->sdma_lock);200spin_lock_init(&ppd->lflags_lock);201init_waitqueue_head(&ppd->state_wait);202203init_timer(&ppd->symerr_clear_timer);204ppd->symerr_clear_timer.function = qib_clear_symerror_on_linkup;205ppd->symerr_clear_timer.data = (unsigned long)ppd;206}207208static int init_pioavailregs(struct qib_devdata *dd)209{210int ret, pidx;211u64 *status_page;212213dd->pioavailregs_dma = dma_alloc_coherent(214&dd->pcidev->dev, PAGE_SIZE, &dd->pioavailregs_phys,215GFP_KERNEL);216if (!dd->pioavailregs_dma) {217qib_dev_err(dd, "failed to allocate PIOavail reg area "218"in memory\n");219ret = -ENOMEM;220goto done;221}222223/*224* We really want L2 cache aligned, but for current CPUs of225* interest, they are the same.226*/227status_page = (u64 *)228((char *) dd->pioavailregs_dma +229((2 * L1_CACHE_BYTES +230dd->pioavregs * sizeof(u64)) & ~L1_CACHE_BYTES));231/* device status comes first, for backwards compatibility */232dd->devstatusp = status_page;233*status_page++ = 0;234for (pidx = 0; pidx < dd->num_pports; ++pidx) {235dd->pport[pidx].statusp = status_page;236*status_page++ = 0;237}238239/*240* Setup buffer to hold freeze and other messages, accessible to241* apps, following statusp. This is per-unit, not per port.242*/243dd->freezemsg = (char *) status_page;244*dd->freezemsg = 0;245/* length of msg buffer is "whatever is left" */246ret = (char *) status_page - (char *) dd->pioavailregs_dma;247dd->freezelen = PAGE_SIZE - ret;248249ret = 0;250251done:252return ret;253}254255/**256* init_shadow_tids - allocate the shadow TID array257* @dd: the qlogic_ib device258*259* allocate the shadow TID array, so we can qib_munlock previous260* entries. It may make more sense to move the pageshadow to the261* ctxt data structure, so we only allocate memory for ctxts actually262* in use, since we at 8k per ctxt, now.263* We don't want failures here to prevent use of the driver/chip,264* so no return value.265*/266static void init_shadow_tids(struct qib_devdata *dd)267{268struct page **pages;269dma_addr_t *addrs;270271pages = vzalloc(dd->cfgctxts * dd->rcvtidcnt * sizeof(struct page *));272if (!pages) {273qib_dev_err(dd, "failed to allocate shadow page * "274"array, no expected sends!\n");275goto bail;276}277278addrs = vzalloc(dd->cfgctxts * dd->rcvtidcnt * sizeof(dma_addr_t));279if (!addrs) {280qib_dev_err(dd, "failed to allocate shadow dma handle "281"array, no expected sends!\n");282goto bail_free;283}284285dd->pageshadow = pages;286dd->physshadow = addrs;287return;288289bail_free:290vfree(pages);291bail:292dd->pageshadow = NULL;293}294295/*296* Do initialization for device that is only needed on297* first detect, not on resets.298*/299static int loadtime_init(struct qib_devdata *dd)300{301int ret = 0;302303if (((dd->revision >> QLOGIC_IB_R_SOFTWARE_SHIFT) &304QLOGIC_IB_R_SOFTWARE_MASK) != QIB_CHIP_SWVERSION) {305qib_dev_err(dd, "Driver only handles version %d, "306"chip swversion is %d (%llx), failng\n",307QIB_CHIP_SWVERSION,308(int)(dd->revision >>309QLOGIC_IB_R_SOFTWARE_SHIFT) &310QLOGIC_IB_R_SOFTWARE_MASK,311(unsigned long long) dd->revision);312ret = -ENOSYS;313goto done;314}315316if (dd->revision & QLOGIC_IB_R_EMULATOR_MASK)317qib_devinfo(dd->pcidev, "%s", dd->boardversion);318319spin_lock_init(&dd->pioavail_lock);320spin_lock_init(&dd->sendctrl_lock);321spin_lock_init(&dd->uctxt_lock);322spin_lock_init(&dd->qib_diag_trans_lock);323spin_lock_init(&dd->eep_st_lock);324mutex_init(&dd->eep_lock);325326if (qib_mini_init)327goto done;328329ret = init_pioavailregs(dd);330init_shadow_tids(dd);331332qib_get_eeprom_info(dd);333334/* setup time (don't start yet) to verify we got interrupt */335init_timer(&dd->intrchk_timer);336dd->intrchk_timer.function = verify_interrupt;337dd->intrchk_timer.data = (unsigned long) dd;338339done:340return ret;341}342343/**344* init_after_reset - re-initialize after a reset345* @dd: the qlogic_ib device346*347* sanity check at least some of the values after reset, and348* ensure no receive or transmit (explicitly, in case reset349* failed350*/351static int init_after_reset(struct qib_devdata *dd)352{353int i;354355/*356* Ensure chip does no sends or receives, tail updates, or357* pioavail updates while we re-initialize. This is mostly358* for the driver data structures, not chip registers.359*/360for (i = 0; i < dd->num_pports; ++i) {361/*362* ctxt == -1 means "all contexts". Only really safe for363* _dis_abling things, as here.364*/365dd->f_rcvctrl(dd->pport + i, QIB_RCVCTRL_CTXT_DIS |366QIB_RCVCTRL_INTRAVAIL_DIS |367QIB_RCVCTRL_TAILUPD_DIS, -1);368/* Redundant across ports for some, but no big deal. */369dd->f_sendctrl(dd->pport + i, QIB_SENDCTRL_SEND_DIS |370QIB_SENDCTRL_AVAIL_DIS);371}372373return 0;374}375376static void enable_chip(struct qib_devdata *dd)377{378u64 rcvmask;379int i;380381/*382* Enable PIO send, and update of PIOavail regs to memory.383*/384for (i = 0; i < dd->num_pports; ++i)385dd->f_sendctrl(dd->pport + i, QIB_SENDCTRL_SEND_ENB |386QIB_SENDCTRL_AVAIL_ENB);387/*388* Enable kernel ctxts' receive and receive interrupt.389* Other ctxts done as user opens and inits them.390*/391rcvmask = QIB_RCVCTRL_CTXT_ENB | QIB_RCVCTRL_INTRAVAIL_ENB;392rcvmask |= (dd->flags & QIB_NODMA_RTAIL) ?393QIB_RCVCTRL_TAILUPD_DIS : QIB_RCVCTRL_TAILUPD_ENB;394for (i = 0; dd->rcd && i < dd->first_user_ctxt; ++i) {395struct qib_ctxtdata *rcd = dd->rcd[i];396397if (rcd)398dd->f_rcvctrl(rcd->ppd, rcvmask, i);399}400}401402static void verify_interrupt(unsigned long opaque)403{404struct qib_devdata *dd = (struct qib_devdata *) opaque;405406if (!dd)407return; /* being torn down */408409/*410* If we don't have a lid or any interrupts, let the user know and411* don't bother checking again.412*/413if (dd->int_counter == 0) {414if (!dd->f_intr_fallback(dd))415dev_err(&dd->pcidev->dev, "No interrupts detected, "416"not usable.\n");417else /* re-arm the timer to see if fallback works */418mod_timer(&dd->intrchk_timer, jiffies + HZ/2);419}420}421422static void init_piobuf_state(struct qib_devdata *dd)423{424int i, pidx;425u32 uctxts;426427/*428* Ensure all buffers are free, and fifos empty. Buffers429* are common, so only do once for port 0.430*431* After enable and qib_chg_pioavailkernel so we can safely432* enable pioavail updates and PIOENABLE. After this, packets433* are ready and able to go out.434*/435dd->f_sendctrl(dd->pport, QIB_SENDCTRL_DISARM_ALL);436for (pidx = 0; pidx < dd->num_pports; ++pidx)437dd->f_sendctrl(dd->pport + pidx, QIB_SENDCTRL_FLUSH);438439/*440* If not all sendbufs are used, add the one to each of the lower441* numbered contexts. pbufsctxt and lastctxt_piobuf are442* calculated in chip-specific code because it may cause some443* chip-specific adjustments to be made.444*/445uctxts = dd->cfgctxts - dd->first_user_ctxt;446dd->ctxts_extrabuf = dd->pbufsctxt ?447dd->lastctxt_piobuf - (dd->pbufsctxt * uctxts) : 0;448449/*450* Set up the shadow copies of the piobufavail registers,451* which we compare against the chip registers for now, and452* the in memory DMA'ed copies of the registers.453* By now pioavail updates to memory should have occurred, so454* copy them into our working/shadow registers; this is in455* case something went wrong with abort, but mostly to get the456* initial values of the generation bit correct.457*/458for (i = 0; i < dd->pioavregs; i++) {459__le64 tmp;460461tmp = dd->pioavailregs_dma[i];462/*463* Don't need to worry about pioavailkernel here464* because we will call qib_chg_pioavailkernel() later465* in initialization, to busy out buffers as needed.466*/467dd->pioavailshadow[i] = le64_to_cpu(tmp);468}469while (i < ARRAY_SIZE(dd->pioavailshadow))470dd->pioavailshadow[i++] = 0; /* for debugging sanity */471472/* after pioavailshadow is setup */473qib_chg_pioavailkernel(dd, 0, dd->piobcnt2k + dd->piobcnt4k,474TXCHK_CHG_TYPE_KERN, NULL);475dd->f_initvl15_bufs(dd);476}477478/**479* qib_init - do the actual initialization sequence on the chip480* @dd: the qlogic_ib device481* @reinit: reinitializing, so don't allocate new memory482*483* Do the actual initialization sequence on the chip. This is done484* both from the init routine called from the PCI infrastructure, and485* when we reset the chip, or detect that it was reset internally,486* or it's administratively re-enabled.487*488* Memory allocation here and in called routines is only done in489* the first case (reinit == 0). We have to be careful, because even490* without memory allocation, we need to re-write all the chip registers491* TIDs, etc. after the reset or enable has completed.492*/493int qib_init(struct qib_devdata *dd, int reinit)494{495int ret = 0, pidx, lastfail = 0;496u32 portok = 0;497unsigned i;498struct qib_ctxtdata *rcd;499struct qib_pportdata *ppd;500unsigned long flags;501502/* Set linkstate to unknown, so we can watch for a transition. */503for (pidx = 0; pidx < dd->num_pports; ++pidx) {504ppd = dd->pport + pidx;505spin_lock_irqsave(&ppd->lflags_lock, flags);506ppd->lflags &= ~(QIBL_LINKACTIVE | QIBL_LINKARMED |507QIBL_LINKDOWN | QIBL_LINKINIT |508QIBL_LINKV);509spin_unlock_irqrestore(&ppd->lflags_lock, flags);510}511512if (reinit)513ret = init_after_reset(dd);514else515ret = loadtime_init(dd);516if (ret)517goto done;518519/* Bypass most chip-init, to get to device creation */520if (qib_mini_init)521return 0;522523ret = dd->f_late_initreg(dd);524if (ret)525goto done;526527/* dd->rcd can be NULL if early init failed */528for (i = 0; dd->rcd && i < dd->first_user_ctxt; ++i) {529/*530* Set up the (kernel) rcvhdr queue and egr TIDs. If doing531* re-init, the simplest way to handle this is to free532* existing, and re-allocate.533* Need to re-create rest of ctxt 0 ctxtdata as well.534*/535rcd = dd->rcd[i];536if (!rcd)537continue;538539lastfail = qib_create_rcvhdrq(dd, rcd);540if (!lastfail)541lastfail = qib_setup_eagerbufs(rcd);542if (lastfail) {543qib_dev_err(dd, "failed to allocate kernel ctxt's "544"rcvhdrq and/or egr bufs\n");545continue;546}547}548549for (pidx = 0; pidx < dd->num_pports; ++pidx) {550int mtu;551if (lastfail)552ret = lastfail;553ppd = dd->pport + pidx;554mtu = ib_mtu_enum_to_int(qib_ibmtu);555if (mtu == -1) {556mtu = QIB_DEFAULT_MTU;557qib_ibmtu = 0; /* don't leave invalid value */558}559/* set max we can ever have for this driver load */560ppd->init_ibmaxlen = min(mtu > 2048 ?561dd->piosize4k : dd->piosize2k,562dd->rcvegrbufsize +563(dd->rcvhdrentsize << 2));564/*565* Have to initialize ibmaxlen, but this will normally566* change immediately in qib_set_mtu().567*/568ppd->ibmaxlen = ppd->init_ibmaxlen;569qib_set_mtu(ppd, mtu);570571spin_lock_irqsave(&ppd->lflags_lock, flags);572ppd->lflags |= QIBL_IB_LINK_DISABLED;573spin_unlock_irqrestore(&ppd->lflags_lock, flags);574575lastfail = dd->f_bringup_serdes(ppd);576if (lastfail) {577qib_devinfo(dd->pcidev,578"Failed to bringup IB port %u\n", ppd->port);579lastfail = -ENETDOWN;580continue;581}582583/* let link come up, and enable IBC */584spin_lock_irqsave(&ppd->lflags_lock, flags);585ppd->lflags &= ~QIBL_IB_LINK_DISABLED;586spin_unlock_irqrestore(&ppd->lflags_lock, flags);587portok++;588}589590if (!portok) {591/* none of the ports initialized */592if (!ret && lastfail)593ret = lastfail;594else if (!ret)595ret = -ENETDOWN;596/* but continue on, so we can debug cause */597}598599enable_chip(dd);600601init_piobuf_state(dd);602603done:604if (!ret) {605/* chip is OK for user apps; mark it as initialized */606for (pidx = 0; pidx < dd->num_pports; ++pidx) {607ppd = dd->pport + pidx;608/*609* Set status even if port serdes is not initialized610* so that diags will work.611*/612*ppd->statusp |= QIB_STATUS_CHIP_PRESENT |613QIB_STATUS_INITTED;614if (!ppd->link_speed_enabled)615continue;616if (dd->flags & QIB_HAS_SEND_DMA)617ret = qib_setup_sdma(ppd);618init_timer(&ppd->hol_timer);619ppd->hol_timer.function = qib_hol_event;620ppd->hol_timer.data = (unsigned long)ppd;621ppd->hol_state = QIB_HOL_UP;622}623624/* now we can enable all interrupts from the chip */625dd->f_set_intr_state(dd, 1);626627/*628* Setup to verify we get an interrupt, and fallback629* to an alternate if necessary and possible.630*/631mod_timer(&dd->intrchk_timer, jiffies + HZ/2);632/* start stats retrieval timer */633mod_timer(&dd->stats_timer, jiffies + HZ * ACTIVITY_TIMER);634}635636/* if ret is non-zero, we probably should do some cleanup here... */637return ret;638}639640/*641* These next two routines are placeholders in case we don't have per-arch642* code for controlling write combining. If explicit control of write643* combining is not available, performance will probably be awful.644*/645646int __attribute__((weak)) qib_enable_wc(struct qib_devdata *dd)647{648return -EOPNOTSUPP;649}650651void __attribute__((weak)) qib_disable_wc(struct qib_devdata *dd)652{653}654655static inline struct qib_devdata *__qib_lookup(int unit)656{657return idr_find(&qib_unit_table, unit);658}659660struct qib_devdata *qib_lookup(int unit)661{662struct qib_devdata *dd;663unsigned long flags;664665spin_lock_irqsave(&qib_devs_lock, flags);666dd = __qib_lookup(unit);667spin_unlock_irqrestore(&qib_devs_lock, flags);668669return dd;670}671672/*673* Stop the timers during unit shutdown, or after an error late674* in initialization.675*/676static void qib_stop_timers(struct qib_devdata *dd)677{678struct qib_pportdata *ppd;679int pidx;680681if (dd->stats_timer.data) {682del_timer_sync(&dd->stats_timer);683dd->stats_timer.data = 0;684}685if (dd->intrchk_timer.data) {686del_timer_sync(&dd->intrchk_timer);687dd->intrchk_timer.data = 0;688}689for (pidx = 0; pidx < dd->num_pports; ++pidx) {690ppd = dd->pport + pidx;691if (ppd->hol_timer.data)692del_timer_sync(&ppd->hol_timer);693if (ppd->led_override_timer.data) {694del_timer_sync(&ppd->led_override_timer);695atomic_set(&ppd->led_override_timer_active, 0);696}697if (ppd->symerr_clear_timer.data)698del_timer_sync(&ppd->symerr_clear_timer);699}700}701702/**703* qib_shutdown_device - shut down a device704* @dd: the qlogic_ib device705*706* This is called to make the device quiet when we are about to707* unload the driver, and also when the device is administratively708* disabled. It does not free any data structures.709* Everything it does has to be setup again by qib_init(dd, 1)710*/711static void qib_shutdown_device(struct qib_devdata *dd)712{713struct qib_pportdata *ppd;714unsigned pidx;715716for (pidx = 0; pidx < dd->num_pports; ++pidx) {717ppd = dd->pport + pidx;718719spin_lock_irq(&ppd->lflags_lock);720ppd->lflags &= ~(QIBL_LINKDOWN | QIBL_LINKINIT |721QIBL_LINKARMED | QIBL_LINKACTIVE |722QIBL_LINKV);723spin_unlock_irq(&ppd->lflags_lock);724*ppd->statusp &= ~(QIB_STATUS_IB_CONF | QIB_STATUS_IB_READY);725}726dd->flags &= ~QIB_INITTED;727728/* mask interrupts, but not errors */729dd->f_set_intr_state(dd, 0);730731for (pidx = 0; pidx < dd->num_pports; ++pidx) {732ppd = dd->pport + pidx;733dd->f_rcvctrl(ppd, QIB_RCVCTRL_TAILUPD_DIS |734QIB_RCVCTRL_CTXT_DIS |735QIB_RCVCTRL_INTRAVAIL_DIS |736QIB_RCVCTRL_PKEY_ENB, -1);737/*738* Gracefully stop all sends allowing any in progress to739* trickle out first.740*/741dd->f_sendctrl(ppd, QIB_SENDCTRL_CLEAR);742}743744/*745* Enough for anything that's going to trickle out to have actually746* done so.747*/748udelay(20);749750for (pidx = 0; pidx < dd->num_pports; ++pidx) {751ppd = dd->pport + pidx;752dd->f_setextled(ppd, 0); /* make sure LEDs are off */753754if (dd->flags & QIB_HAS_SEND_DMA)755qib_teardown_sdma(ppd);756757dd->f_sendctrl(ppd, QIB_SENDCTRL_AVAIL_DIS |758QIB_SENDCTRL_SEND_DIS);759/*760* Clear SerdesEnable.761* We can't count on interrupts since we are stopping.762*/763dd->f_quiet_serdes(ppd);764}765766qib_update_eeprom_log(dd);767}768769/**770* qib_free_ctxtdata - free a context's allocated data771* @dd: the qlogic_ib device772* @rcd: the ctxtdata structure773*774* free up any allocated data for a context775* This should not touch anything that would affect a simultaneous776* re-allocation of context data, because it is called after qib_mutex777* is released (and can be called from reinit as well).778* It should never change any chip state, or global driver state.779*/780void qib_free_ctxtdata(struct qib_devdata *dd, struct qib_ctxtdata *rcd)781{782if (!rcd)783return;784785if (rcd->rcvhdrq) {786dma_free_coherent(&dd->pcidev->dev, rcd->rcvhdrq_size,787rcd->rcvhdrq, rcd->rcvhdrq_phys);788rcd->rcvhdrq = NULL;789if (rcd->rcvhdrtail_kvaddr) {790dma_free_coherent(&dd->pcidev->dev, PAGE_SIZE,791rcd->rcvhdrtail_kvaddr,792rcd->rcvhdrqtailaddr_phys);793rcd->rcvhdrtail_kvaddr = NULL;794}795}796if (rcd->rcvegrbuf) {797unsigned e;798799for (e = 0; e < rcd->rcvegrbuf_chunks; e++) {800void *base = rcd->rcvegrbuf[e];801size_t size = rcd->rcvegrbuf_size;802803dma_free_coherent(&dd->pcidev->dev, size,804base, rcd->rcvegrbuf_phys[e]);805}806kfree(rcd->rcvegrbuf);807rcd->rcvegrbuf = NULL;808kfree(rcd->rcvegrbuf_phys);809rcd->rcvegrbuf_phys = NULL;810rcd->rcvegrbuf_chunks = 0;811}812813kfree(rcd->tid_pg_list);814vfree(rcd->user_event_mask);815vfree(rcd->subctxt_uregbase);816vfree(rcd->subctxt_rcvegrbuf);817vfree(rcd->subctxt_rcvhdr_base);818kfree(rcd);819}820821/*822* Perform a PIO buffer bandwidth write test, to verify proper system823* configuration. Even when all the setup calls work, occasionally824* BIOS or other issues can prevent write combining from working, or825* can cause other bandwidth problems to the chip.826*827* This test simply writes the same buffer over and over again, and828* measures close to the peak bandwidth to the chip (not testing829* data bandwidth to the wire). On chips that use an address-based830* trigger to send packets to the wire, this is easy. On chips that831* use a count to trigger, we want to make sure that the packet doesn't832* go out on the wire, or trigger flow control checks.833*/834static void qib_verify_pioperf(struct qib_devdata *dd)835{836u32 pbnum, cnt, lcnt;837u32 __iomem *piobuf;838u32 *addr;839u64 msecs, emsecs;840841piobuf = dd->f_getsendbuf(dd->pport, 0ULL, &pbnum);842if (!piobuf) {843qib_devinfo(dd->pcidev,844"No PIObufs for checking perf, skipping\n");845return;846}847848/*849* Enough to give us a reasonable test, less than piobuf size, and850* likely multiple of store buffer length.851*/852cnt = 1024;853854addr = vmalloc(cnt);855if (!addr) {856qib_devinfo(dd->pcidev,857"Couldn't get memory for checking PIO perf,"858" skipping\n");859goto done;860}861862preempt_disable(); /* we want reasonably accurate elapsed time */863msecs = 1 + jiffies_to_msecs(jiffies);864for (lcnt = 0; lcnt < 10000U; lcnt++) {865/* wait until we cross msec boundary */866if (jiffies_to_msecs(jiffies) >= msecs)867break;868udelay(1);869}870871dd->f_set_armlaunch(dd, 0);872873/*874* length 0, no dwords actually sent875*/876writeq(0, piobuf);877qib_flush_wc();878879/*880* This is only roughly accurate, since even with preempt we881* still take interrupts that could take a while. Running for882* >= 5 msec seems to get us "close enough" to accurate values.883*/884msecs = jiffies_to_msecs(jiffies);885for (emsecs = lcnt = 0; emsecs <= 5UL; lcnt++) {886qib_pio_copy(piobuf + 64, addr, cnt >> 2);887emsecs = jiffies_to_msecs(jiffies) - msecs;888}889890/* 1 GiB/sec, slightly over IB SDR line rate */891if (lcnt < (emsecs * 1024U))892qib_dev_err(dd,893"Performance problem: bandwidth to PIO buffers is "894"only %u MiB/sec\n",895lcnt / (u32) emsecs);896897preempt_enable();898899vfree(addr);900901done:902/* disarm piobuf, so it's available again */903dd->f_sendctrl(dd->pport, QIB_SENDCTRL_DISARM_BUF(pbnum));904qib_sendbuf_done(dd, pbnum);905dd->f_set_armlaunch(dd, 1);906}907908909void qib_free_devdata(struct qib_devdata *dd)910{911unsigned long flags;912913spin_lock_irqsave(&qib_devs_lock, flags);914idr_remove(&qib_unit_table, dd->unit);915list_del(&dd->list);916spin_unlock_irqrestore(&qib_devs_lock, flags);917918ib_dealloc_device(&dd->verbs_dev.ibdev);919}920921/*922* Allocate our primary per-unit data structure. Must be done via verbs923* allocator, because the verbs cleanup process both does cleanup and924* free of the data structure.925* "extra" is for chip-specific data.926*927* Use the idr mechanism to get a unit number for this unit.928*/929struct qib_devdata *qib_alloc_devdata(struct pci_dev *pdev, size_t extra)930{931unsigned long flags;932struct qib_devdata *dd;933int ret;934935if (!idr_pre_get(&qib_unit_table, GFP_KERNEL)) {936dd = ERR_PTR(-ENOMEM);937goto bail;938}939940dd = (struct qib_devdata *) ib_alloc_device(sizeof(*dd) + extra);941if (!dd) {942dd = ERR_PTR(-ENOMEM);943goto bail;944}945946spin_lock_irqsave(&qib_devs_lock, flags);947ret = idr_get_new(&qib_unit_table, dd, &dd->unit);948if (ret >= 0)949list_add(&dd->list, &qib_dev_list);950spin_unlock_irqrestore(&qib_devs_lock, flags);951952if (ret < 0) {953qib_early_err(&pdev->dev,954"Could not allocate unit ID: error %d\n", -ret);955ib_dealloc_device(&dd->verbs_dev.ibdev);956dd = ERR_PTR(ret);957goto bail;958}959960if (!qib_cpulist_count) {961u32 count = num_online_cpus();962qib_cpulist = kzalloc(BITS_TO_LONGS(count) *963sizeof(long), GFP_KERNEL);964if (qib_cpulist)965qib_cpulist_count = count;966else967qib_early_err(&pdev->dev, "Could not alloc cpulist "968"info, cpu affinity might be wrong\n");969}970971bail:972return dd;973}974975/*976* Called from freeze mode handlers, and from PCI error977* reporting code. Should be paranoid about state of978* system and data structures.979*/980void qib_disable_after_error(struct qib_devdata *dd)981{982if (dd->flags & QIB_INITTED) {983u32 pidx;984985dd->flags &= ~QIB_INITTED;986if (dd->pport)987for (pidx = 0; pidx < dd->num_pports; ++pidx) {988struct qib_pportdata *ppd;989990ppd = dd->pport + pidx;991if (dd->flags & QIB_PRESENT) {992qib_set_linkstate(ppd,993QIB_IB_LINKDOWN_DISABLE);994dd->f_setextled(ppd, 0);995}996*ppd->statusp &= ~QIB_STATUS_IB_READY;997}998}9991000/*1001* Mark as having had an error for driver, and also1002* for /sys and status word mapped to user programs.1003* This marks unit as not usable, until reset.1004*/1005if (dd->devstatusp)1006*dd->devstatusp |= QIB_STATUS_HWERROR;1007}10081009static void __devexit qib_remove_one(struct pci_dev *);1010static int __devinit qib_init_one(struct pci_dev *,1011const struct pci_device_id *);10121013#define DRIVER_LOAD_MSG "QLogic " QIB_DRV_NAME " loaded: "1014#define PFX QIB_DRV_NAME ": "10151016static const struct pci_device_id qib_pci_tbl[] = {1017{ PCI_DEVICE(PCI_VENDOR_ID_PATHSCALE, PCI_DEVICE_ID_QLOGIC_IB_6120) },1018{ PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_IB_7220) },1019{ PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_IB_7322) },1020{ 0, }1021};10221023MODULE_DEVICE_TABLE(pci, qib_pci_tbl);10241025struct pci_driver qib_driver = {1026.name = QIB_DRV_NAME,1027.probe = qib_init_one,1028.remove = __devexit_p(qib_remove_one),1029.id_table = qib_pci_tbl,1030.err_handler = &qib_pci_err_handler,1031};10321033/*1034* Do all the generic driver unit- and chip-independent memory1035* allocation and initialization.1036*/1037static int __init qlogic_ib_init(void)1038{1039int ret;10401041ret = qib_dev_init();1042if (ret)1043goto bail;10441045qib_cq_wq = create_singlethread_workqueue("qib_cq");1046if (!qib_cq_wq) {1047ret = -ENOMEM;1048goto bail_dev;1049}10501051/*1052* These must be called before the driver is registered with1053* the PCI subsystem.1054*/1055idr_init(&qib_unit_table);1056if (!idr_pre_get(&qib_unit_table, GFP_KERNEL)) {1057printk(KERN_ERR QIB_DRV_NAME ": idr_pre_get() failed\n");1058ret = -ENOMEM;1059goto bail_cq_wq;1060}10611062ret = pci_register_driver(&qib_driver);1063if (ret < 0) {1064printk(KERN_ERR QIB_DRV_NAME1065": Unable to register driver: error %d\n", -ret);1066goto bail_unit;1067}10681069/* not fatal if it doesn't work */1070if (qib_init_qibfs())1071printk(KERN_ERR QIB_DRV_NAME ": Unable to register ipathfs\n");1072goto bail; /* all OK */10731074bail_unit:1075idr_destroy(&qib_unit_table);1076bail_cq_wq:1077destroy_workqueue(qib_cq_wq);1078bail_dev:1079qib_dev_cleanup();1080bail:1081return ret;1082}10831084module_init(qlogic_ib_init);10851086/*1087* Do the non-unit driver cleanup, memory free, etc. at unload.1088*/1089static void __exit qlogic_ib_cleanup(void)1090{1091int ret;10921093ret = qib_exit_qibfs();1094if (ret)1095printk(KERN_ERR QIB_DRV_NAME ": "1096"Unable to cleanup counter filesystem: "1097"error %d\n", -ret);10981099pci_unregister_driver(&qib_driver);11001101destroy_workqueue(qib_cq_wq);11021103qib_cpulist_count = 0;1104kfree(qib_cpulist);11051106idr_destroy(&qib_unit_table);1107qib_dev_cleanup();1108}11091110module_exit(qlogic_ib_cleanup);11111112/* this can only be called after a successful initialization */1113static void cleanup_device_data(struct qib_devdata *dd)1114{1115int ctxt;1116int pidx;1117struct qib_ctxtdata **tmp;1118unsigned long flags;11191120/* users can't do anything more with chip */1121for (pidx = 0; pidx < dd->num_pports; ++pidx)1122if (dd->pport[pidx].statusp)1123*dd->pport[pidx].statusp &= ~QIB_STATUS_CHIP_PRESENT;11241125if (!qib_wc_pat)1126qib_disable_wc(dd);11271128if (dd->pioavailregs_dma) {1129dma_free_coherent(&dd->pcidev->dev, PAGE_SIZE,1130(void *) dd->pioavailregs_dma,1131dd->pioavailregs_phys);1132dd->pioavailregs_dma = NULL;1133}11341135if (dd->pageshadow) {1136struct page **tmpp = dd->pageshadow;1137dma_addr_t *tmpd = dd->physshadow;1138int i, cnt = 0;11391140for (ctxt = 0; ctxt < dd->cfgctxts; ctxt++) {1141int ctxt_tidbase = ctxt * dd->rcvtidcnt;1142int maxtid = ctxt_tidbase + dd->rcvtidcnt;11431144for (i = ctxt_tidbase; i < maxtid; i++) {1145if (!tmpp[i])1146continue;1147pci_unmap_page(dd->pcidev, tmpd[i],1148PAGE_SIZE, PCI_DMA_FROMDEVICE);1149qib_release_user_pages(&tmpp[i], 1);1150tmpp[i] = NULL;1151cnt++;1152}1153}11541155tmpp = dd->pageshadow;1156dd->pageshadow = NULL;1157vfree(tmpp);1158}11591160/*1161* Free any resources still in use (usually just kernel contexts)1162* at unload; we do for ctxtcnt, because that's what we allocate.1163* We acquire lock to be really paranoid that rcd isn't being1164* accessed from some interrupt-related code (that should not happen,1165* but best to be sure).1166*/1167spin_lock_irqsave(&dd->uctxt_lock, flags);1168tmp = dd->rcd;1169dd->rcd = NULL;1170spin_unlock_irqrestore(&dd->uctxt_lock, flags);1171for (ctxt = 0; tmp && ctxt < dd->ctxtcnt; ctxt++) {1172struct qib_ctxtdata *rcd = tmp[ctxt];11731174tmp[ctxt] = NULL; /* debugging paranoia */1175qib_free_ctxtdata(dd, rcd);1176}1177kfree(tmp);1178kfree(dd->boardname);1179}11801181/*1182* Clean up on unit shutdown, or error during unit load after1183* successful initialization.1184*/1185static void qib_postinit_cleanup(struct qib_devdata *dd)1186{1187/*1188* Clean up chip-specific stuff.1189* We check for NULL here, because it's outside1190* the kregbase check, and we need to call it1191* after the free_irq. Thus it's possible that1192* the function pointers were never initialized.1193*/1194if (dd->f_cleanup)1195dd->f_cleanup(dd);11961197qib_pcie_ddcleanup(dd);11981199cleanup_device_data(dd);12001201qib_free_devdata(dd);1202}12031204static int __devinit qib_init_one(struct pci_dev *pdev,1205const struct pci_device_id *ent)1206{1207int ret, j, pidx, initfail;1208struct qib_devdata *dd = NULL;12091210ret = qib_pcie_init(pdev, ent);1211if (ret)1212goto bail;12131214/*1215* Do device-specific initialiation, function table setup, dd1216* allocation, etc.1217*/1218switch (ent->device) {1219case PCI_DEVICE_ID_QLOGIC_IB_6120:1220#ifdef CONFIG_PCI_MSI1221dd = qib_init_iba6120_funcs(pdev, ent);1222#else1223qib_early_err(&pdev->dev, "QLogic PCIE device 0x%x cannot "1224"work if CONFIG_PCI_MSI is not enabled\n",1225ent->device);1226dd = ERR_PTR(-ENODEV);1227#endif1228break;12291230case PCI_DEVICE_ID_QLOGIC_IB_7220:1231dd = qib_init_iba7220_funcs(pdev, ent);1232break;12331234case PCI_DEVICE_ID_QLOGIC_IB_7322:1235dd = qib_init_iba7322_funcs(pdev, ent);1236break;12371238default:1239qib_early_err(&pdev->dev, "Failing on unknown QLogic "1240"deviceid 0x%x\n", ent->device);1241ret = -ENODEV;1242}12431244if (IS_ERR(dd))1245ret = PTR_ERR(dd);1246if (ret)1247goto bail; /* error already printed */12481249/* do the generic initialization */1250initfail = qib_init(dd, 0);12511252ret = qib_register_ib_device(dd);12531254/*1255* Now ready for use. this should be cleared whenever we1256* detect a reset, or initiate one. If earlier failure,1257* we still create devices, so diags, etc. can be used1258* to determine cause of problem.1259*/1260if (!qib_mini_init && !initfail && !ret)1261dd->flags |= QIB_INITTED;12621263j = qib_device_create(dd);1264if (j)1265qib_dev_err(dd, "Failed to create /dev devices: %d\n", -j);1266j = qibfs_add(dd);1267if (j)1268qib_dev_err(dd, "Failed filesystem setup for counters: %d\n",1269-j);12701271if (qib_mini_init || initfail || ret) {1272qib_stop_timers(dd);1273flush_workqueue(ib_wq);1274for (pidx = 0; pidx < dd->num_pports; ++pidx)1275dd->f_quiet_serdes(dd->pport + pidx);1276if (qib_mini_init)1277goto bail;1278if (!j) {1279(void) qibfs_remove(dd);1280qib_device_remove(dd);1281}1282if (!ret)1283qib_unregister_ib_device(dd);1284qib_postinit_cleanup(dd);1285if (initfail)1286ret = initfail;1287goto bail;1288}12891290if (!qib_wc_pat) {1291ret = qib_enable_wc(dd);1292if (ret) {1293qib_dev_err(dd, "Write combining not enabled "1294"(err %d): performance may be poor\n",1295-ret);1296ret = 0;1297}1298}12991300qib_verify_pioperf(dd);1301bail:1302return ret;1303}13041305static void __devexit qib_remove_one(struct pci_dev *pdev)1306{1307struct qib_devdata *dd = pci_get_drvdata(pdev);1308int ret;13091310/* unregister from IB core */1311qib_unregister_ib_device(dd);13121313/*1314* Disable the IB link, disable interrupts on the device,1315* clear dma engines, etc.1316*/1317if (!qib_mini_init)1318qib_shutdown_device(dd);13191320qib_stop_timers(dd);13211322/* wait until all of our (qsfp) queue_work() calls complete */1323flush_workqueue(ib_wq);13241325ret = qibfs_remove(dd);1326if (ret)1327qib_dev_err(dd, "Failed counters filesystem cleanup: %d\n",1328-ret);13291330qib_device_remove(dd);13311332qib_postinit_cleanup(dd);1333}13341335/**1336* qib_create_rcvhdrq - create a receive header queue1337* @dd: the qlogic_ib device1338* @rcd: the context data1339*1340* This must be contiguous memory (from an i/o perspective), and must be1341* DMA'able (which means for some systems, it will go through an IOMMU,1342* or be forced into a low address range).1343*/1344int qib_create_rcvhdrq(struct qib_devdata *dd, struct qib_ctxtdata *rcd)1345{1346unsigned amt;13471348if (!rcd->rcvhdrq) {1349dma_addr_t phys_hdrqtail;1350gfp_t gfp_flags;13511352amt = ALIGN(dd->rcvhdrcnt * dd->rcvhdrentsize *1353sizeof(u32), PAGE_SIZE);1354gfp_flags = (rcd->ctxt >= dd->first_user_ctxt) ?1355GFP_USER : GFP_KERNEL;1356rcd->rcvhdrq = dma_alloc_coherent(1357&dd->pcidev->dev, amt, &rcd->rcvhdrq_phys,1358gfp_flags | __GFP_COMP);13591360if (!rcd->rcvhdrq) {1361qib_dev_err(dd, "attempt to allocate %d bytes "1362"for ctxt %u rcvhdrq failed\n",1363amt, rcd->ctxt);1364goto bail;1365}13661367if (rcd->ctxt >= dd->first_user_ctxt) {1368rcd->user_event_mask = vmalloc_user(PAGE_SIZE);1369if (!rcd->user_event_mask)1370goto bail_free_hdrq;1371}13721373if (!(dd->flags & QIB_NODMA_RTAIL)) {1374rcd->rcvhdrtail_kvaddr = dma_alloc_coherent(1375&dd->pcidev->dev, PAGE_SIZE, &phys_hdrqtail,1376gfp_flags);1377if (!rcd->rcvhdrtail_kvaddr)1378goto bail_free;1379rcd->rcvhdrqtailaddr_phys = phys_hdrqtail;1380}13811382rcd->rcvhdrq_size = amt;1383}13841385/* clear for security and sanity on each use */1386memset(rcd->rcvhdrq, 0, rcd->rcvhdrq_size);1387if (rcd->rcvhdrtail_kvaddr)1388memset(rcd->rcvhdrtail_kvaddr, 0, PAGE_SIZE);1389return 0;13901391bail_free:1392qib_dev_err(dd, "attempt to allocate 1 page for ctxt %u "1393"rcvhdrqtailaddr failed\n", rcd->ctxt);1394vfree(rcd->user_event_mask);1395rcd->user_event_mask = NULL;1396bail_free_hdrq:1397dma_free_coherent(&dd->pcidev->dev, amt, rcd->rcvhdrq,1398rcd->rcvhdrq_phys);1399rcd->rcvhdrq = NULL;1400bail:1401return -ENOMEM;1402}14031404/**1405* allocate eager buffers, both kernel and user contexts.1406* @rcd: the context we are setting up.1407*1408* Allocate the eager TID buffers and program them into hip.1409* They are no longer completely contiguous, we do multiple allocation1410* calls. Otherwise we get the OOM code involved, by asking for too1411* much per call, with disastrous results on some kernels.1412*/1413int qib_setup_eagerbufs(struct qib_ctxtdata *rcd)1414{1415struct qib_devdata *dd = rcd->dd;1416unsigned e, egrcnt, egrperchunk, chunk, egrsize, egroff;1417size_t size;1418gfp_t gfp_flags;14191420/*1421* GFP_USER, but without GFP_FS, so buffer cache can be1422* coalesced (we hope); otherwise, even at order 4,1423* heavy filesystem activity makes these fail, and we can1424* use compound pages.1425*/1426gfp_flags = __GFP_WAIT | __GFP_IO | __GFP_COMP;14271428egrcnt = rcd->rcvegrcnt;1429egroff = rcd->rcvegr_tid_base;1430egrsize = dd->rcvegrbufsize;14311432chunk = rcd->rcvegrbuf_chunks;1433egrperchunk = rcd->rcvegrbufs_perchunk;1434size = rcd->rcvegrbuf_size;1435if (!rcd->rcvegrbuf) {1436rcd->rcvegrbuf =1437kzalloc(chunk * sizeof(rcd->rcvegrbuf[0]),1438GFP_KERNEL);1439if (!rcd->rcvegrbuf)1440goto bail;1441}1442if (!rcd->rcvegrbuf_phys) {1443rcd->rcvegrbuf_phys =1444kmalloc(chunk * sizeof(rcd->rcvegrbuf_phys[0]),1445GFP_KERNEL);1446if (!rcd->rcvegrbuf_phys)1447goto bail_rcvegrbuf;1448}1449for (e = 0; e < rcd->rcvegrbuf_chunks; e++) {1450if (rcd->rcvegrbuf[e])1451continue;1452rcd->rcvegrbuf[e] =1453dma_alloc_coherent(&dd->pcidev->dev, size,1454&rcd->rcvegrbuf_phys[e],1455gfp_flags);1456if (!rcd->rcvegrbuf[e])1457goto bail_rcvegrbuf_phys;1458}14591460rcd->rcvegr_phys = rcd->rcvegrbuf_phys[0];14611462for (e = chunk = 0; chunk < rcd->rcvegrbuf_chunks; chunk++) {1463dma_addr_t pa = rcd->rcvegrbuf_phys[chunk];1464unsigned i;14651466/* clear for security and sanity on each use */1467memset(rcd->rcvegrbuf[chunk], 0, size);14681469for (i = 0; e < egrcnt && i < egrperchunk; e++, i++) {1470dd->f_put_tid(dd, e + egroff +1471(u64 __iomem *)1472((char __iomem *)1473dd->kregbase +1474dd->rcvegrbase),1475RCVHQ_RCV_TYPE_EAGER, pa);1476pa += egrsize;1477}1478cond_resched(); /* don't hog the cpu */1479}14801481return 0;14821483bail_rcvegrbuf_phys:1484for (e = 0; e < rcd->rcvegrbuf_chunks && rcd->rcvegrbuf[e]; e++)1485dma_free_coherent(&dd->pcidev->dev, size,1486rcd->rcvegrbuf[e], rcd->rcvegrbuf_phys[e]);1487kfree(rcd->rcvegrbuf_phys);1488rcd->rcvegrbuf_phys = NULL;1489bail_rcvegrbuf:1490kfree(rcd->rcvegrbuf);1491rcd->rcvegrbuf = NULL;1492bail:1493return -ENOMEM;1494}14951496/*1497* Note: Changes to this routine should be mirrored1498* for the diagnostics routine qib_remap_ioaddr32().1499* There is also related code for VL15 buffers in qib_init_7322_variables().1500* The teardown code that unmaps is in qib_pcie_ddcleanup()1501*/1502int init_chip_wc_pat(struct qib_devdata *dd, u32 vl15buflen)1503{1504u64 __iomem *qib_kregbase = NULL;1505void __iomem *qib_piobase = NULL;1506u64 __iomem *qib_userbase = NULL;1507u64 qib_kreglen;1508u64 qib_pio2koffset = dd->piobufbase & 0xffffffff;1509u64 qib_pio4koffset = dd->piobufbase >> 32;1510u64 qib_pio2klen = dd->piobcnt2k * dd->palign;1511u64 qib_pio4klen = dd->piobcnt4k * dd->align4k;1512u64 qib_physaddr = dd->physaddr;1513u64 qib_piolen;1514u64 qib_userlen = 0;15151516/*1517* Free the old mapping because the kernel will try to reuse the1518* old mapping and not create a new mapping with the1519* write combining attribute.1520*/1521iounmap(dd->kregbase);1522dd->kregbase = NULL;15231524/*1525* Assumes chip address space looks like:1526* - kregs + sregs + cregs + uregs (in any order)1527* - piobufs (2K and 4K bufs in either order)1528* or:1529* - kregs + sregs + cregs (in any order)1530* - piobufs (2K and 4K bufs in either order)1531* - uregs1532*/1533if (dd->piobcnt4k == 0) {1534qib_kreglen = qib_pio2koffset;1535qib_piolen = qib_pio2klen;1536} else if (qib_pio2koffset < qib_pio4koffset) {1537qib_kreglen = qib_pio2koffset;1538qib_piolen = qib_pio4koffset + qib_pio4klen - qib_kreglen;1539} else {1540qib_kreglen = qib_pio4koffset;1541qib_piolen = qib_pio2koffset + qib_pio2klen - qib_kreglen;1542}1543qib_piolen += vl15buflen;1544/* Map just the configured ports (not all hw ports) */1545if (dd->uregbase > qib_kreglen)1546qib_userlen = dd->ureg_align * dd->cfgctxts;15471548/* Sanity checks passed, now create the new mappings */1549qib_kregbase = ioremap_nocache(qib_physaddr, qib_kreglen);1550if (!qib_kregbase)1551goto bail;15521553qib_piobase = ioremap_wc(qib_physaddr + qib_kreglen, qib_piolen);1554if (!qib_piobase)1555goto bail_kregbase;15561557if (qib_userlen) {1558qib_userbase = ioremap_nocache(qib_physaddr + dd->uregbase,1559qib_userlen);1560if (!qib_userbase)1561goto bail_piobase;1562}15631564dd->kregbase = qib_kregbase;1565dd->kregend = (u64 __iomem *)1566((char __iomem *) qib_kregbase + qib_kreglen);1567dd->piobase = qib_piobase;1568dd->pio2kbase = (void __iomem *)1569(((char __iomem *) dd->piobase) +1570qib_pio2koffset - qib_kreglen);1571if (dd->piobcnt4k)1572dd->pio4kbase = (void __iomem *)1573(((char __iomem *) dd->piobase) +1574qib_pio4koffset - qib_kreglen);1575if (qib_userlen)1576/* ureg will now be accessed relative to dd->userbase */1577dd->userbase = qib_userbase;1578return 0;15791580bail_piobase:1581iounmap(qib_piobase);1582bail_kregbase:1583iounmap(qib_kregbase);1584bail:1585return -ENOMEM;1586}158715881589