Path: blob/master/drivers/infiniband/hw/qib/qib_driver.c
15112 views
/*1* Copyright (c) 2006, 2007, 2008, 2009 QLogic Corporation. All rights reserved.2* Copyright (c) 2003, 2004, 2005, 2006 PathScale, Inc. All rights reserved.3*4* This software is available to you under a choice of one of two5* licenses. You may choose to be licensed under the terms of the GNU6* General Public License (GPL) Version 2, available from the file7* COPYING in the main directory of this source tree, or the8* OpenIB.org BSD license below:9*10* Redistribution and use in source and binary forms, with or11* without modification, are permitted provided that the following12* conditions are met:13*14* - Redistributions of source code must retain the above15* copyright notice, this list of conditions and the following16* disclaimer.17*18* - Redistributions in binary form must reproduce the above19* copyright notice, this list of conditions and the following20* disclaimer in the documentation and/or other materials21* provided with the distribution.22*23* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,24* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF25* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND26* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS27* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN28* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN29* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE30* SOFTWARE.31*/3233#include <linux/spinlock.h>34#include <linux/pci.h>35#include <linux/io.h>36#include <linux/delay.h>37#include <linux/netdevice.h>38#include <linux/vmalloc.h>3940#include "qib.h"4142/*43* The size has to be longer than this string, so we can append44* board/chip information to it in the init code.45*/46const char ib_qib_version[] = QIB_IDSTR "\n";4748DEFINE_SPINLOCK(qib_devs_lock);49LIST_HEAD(qib_dev_list);50DEFINE_MUTEX(qib_mutex); /* general driver use */5152unsigned qib_ibmtu;53module_param_named(ibmtu, qib_ibmtu, uint, S_IRUGO);54MODULE_PARM_DESC(ibmtu, "Set max IB MTU (0=2KB, 1=256, 2=512, ... 5=4096");5556unsigned qib_compat_ddr_negotiate = 1;57module_param_named(compat_ddr_negotiate, qib_compat_ddr_negotiate, uint,58S_IWUSR | S_IRUGO);59MODULE_PARM_DESC(compat_ddr_negotiate,60"Attempt pre-IBTA 1.2 DDR speed negotiation");6162MODULE_LICENSE("Dual BSD/GPL");63MODULE_AUTHOR("QLogic <[email protected]>");64MODULE_DESCRIPTION("QLogic IB driver");6566/*67* QIB_PIO_MAXIBHDR is the max IB header size allowed for in our68* PIO send buffers. This is well beyond anything currently69* defined in the InfiniBand spec.70*/71#define QIB_PIO_MAXIBHDR 1287273/*74* QIB_MAX_PKT_RCV is the max # if packets processed per receive interrupt.75*/76#define QIB_MAX_PKT_RECV 647778struct qlogic_ib_stats qib_stats;7980const char *qib_get_unit_name(int unit)81{82static char iname[16];8384snprintf(iname, sizeof iname, "infinipath%u", unit);85return iname;86}8788/*89* Return count of units with at least one port ACTIVE.90*/91int qib_count_active_units(void)92{93struct qib_devdata *dd;94struct qib_pportdata *ppd;95unsigned long flags;96int pidx, nunits_active = 0;9798spin_lock_irqsave(&qib_devs_lock, flags);99list_for_each_entry(dd, &qib_dev_list, list) {100if (!(dd->flags & QIB_PRESENT) || !dd->kregbase)101continue;102for (pidx = 0; pidx < dd->num_pports; ++pidx) {103ppd = dd->pport + pidx;104if (ppd->lid && (ppd->lflags & (QIBL_LINKINIT |105QIBL_LINKARMED | QIBL_LINKACTIVE))) {106nunits_active++;107break;108}109}110}111spin_unlock_irqrestore(&qib_devs_lock, flags);112return nunits_active;113}114115/*116* Return count of all units, optionally return in arguments117* the number of usable (present) units, and the number of118* ports that are up.119*/120int qib_count_units(int *npresentp, int *nupp)121{122int nunits = 0, npresent = 0, nup = 0;123struct qib_devdata *dd;124unsigned long flags;125int pidx;126struct qib_pportdata *ppd;127128spin_lock_irqsave(&qib_devs_lock, flags);129130list_for_each_entry(dd, &qib_dev_list, list) {131nunits++;132if ((dd->flags & QIB_PRESENT) && dd->kregbase)133npresent++;134for (pidx = 0; pidx < dd->num_pports; ++pidx) {135ppd = dd->pport + pidx;136if (ppd->lid && (ppd->lflags & (QIBL_LINKINIT |137QIBL_LINKARMED | QIBL_LINKACTIVE)))138nup++;139}140}141142spin_unlock_irqrestore(&qib_devs_lock, flags);143144if (npresentp)145*npresentp = npresent;146if (nupp)147*nupp = nup;148149return nunits;150}151152/**153* qib_wait_linkstate - wait for an IB link state change to occur154* @dd: the qlogic_ib device155* @state: the state to wait for156* @msecs: the number of milliseconds to wait157*158* wait up to msecs milliseconds for IB link state change to occur for159* now, take the easy polling route. Currently used only by160* qib_set_linkstate. Returns 0 if state reached, otherwise161* -ETIMEDOUT state can have multiple states set, for any of several162* transitions.163*/164int qib_wait_linkstate(struct qib_pportdata *ppd, u32 state, int msecs)165{166int ret;167unsigned long flags;168169spin_lock_irqsave(&ppd->lflags_lock, flags);170if (ppd->state_wanted) {171spin_unlock_irqrestore(&ppd->lflags_lock, flags);172ret = -EBUSY;173goto bail;174}175ppd->state_wanted = state;176spin_unlock_irqrestore(&ppd->lflags_lock, flags);177wait_event_interruptible_timeout(ppd->state_wait,178(ppd->lflags & state),179msecs_to_jiffies(msecs));180spin_lock_irqsave(&ppd->lflags_lock, flags);181ppd->state_wanted = 0;182spin_unlock_irqrestore(&ppd->lflags_lock, flags);183184if (!(ppd->lflags & state))185ret = -ETIMEDOUT;186else187ret = 0;188bail:189return ret;190}191192int qib_set_linkstate(struct qib_pportdata *ppd, u8 newstate)193{194u32 lstate;195int ret;196struct qib_devdata *dd = ppd->dd;197unsigned long flags;198199switch (newstate) {200case QIB_IB_LINKDOWN_ONLY:201dd->f_set_ib_cfg(ppd, QIB_IB_CFG_LSTATE,202IB_LINKCMD_DOWN | IB_LINKINITCMD_NOP);203/* don't wait */204ret = 0;205goto bail;206207case QIB_IB_LINKDOWN:208dd->f_set_ib_cfg(ppd, QIB_IB_CFG_LSTATE,209IB_LINKCMD_DOWN | IB_LINKINITCMD_POLL);210/* don't wait */211ret = 0;212goto bail;213214case QIB_IB_LINKDOWN_SLEEP:215dd->f_set_ib_cfg(ppd, QIB_IB_CFG_LSTATE,216IB_LINKCMD_DOWN | IB_LINKINITCMD_SLEEP);217/* don't wait */218ret = 0;219goto bail;220221case QIB_IB_LINKDOWN_DISABLE:222dd->f_set_ib_cfg(ppd, QIB_IB_CFG_LSTATE,223IB_LINKCMD_DOWN | IB_LINKINITCMD_DISABLE);224/* don't wait */225ret = 0;226goto bail;227228case QIB_IB_LINKARM:229if (ppd->lflags & QIBL_LINKARMED) {230ret = 0;231goto bail;232}233if (!(ppd->lflags & (QIBL_LINKINIT | QIBL_LINKACTIVE))) {234ret = -EINVAL;235goto bail;236}237/*238* Since the port can be ACTIVE when we ask for ARMED,239* clear QIBL_LINKV so we can wait for a transition.240* If the link isn't ARMED, then something else happened241* and there is no point waiting for ARMED.242*/243spin_lock_irqsave(&ppd->lflags_lock, flags);244ppd->lflags &= ~QIBL_LINKV;245spin_unlock_irqrestore(&ppd->lflags_lock, flags);246dd->f_set_ib_cfg(ppd, QIB_IB_CFG_LSTATE,247IB_LINKCMD_ARMED | IB_LINKINITCMD_NOP);248lstate = QIBL_LINKV;249break;250251case QIB_IB_LINKACTIVE:252if (ppd->lflags & QIBL_LINKACTIVE) {253ret = 0;254goto bail;255}256if (!(ppd->lflags & QIBL_LINKARMED)) {257ret = -EINVAL;258goto bail;259}260dd->f_set_ib_cfg(ppd, QIB_IB_CFG_LSTATE,261IB_LINKCMD_ACTIVE | IB_LINKINITCMD_NOP);262lstate = QIBL_LINKACTIVE;263break;264265default:266ret = -EINVAL;267goto bail;268}269ret = qib_wait_linkstate(ppd, lstate, 10);270271bail:272return ret;273}274275/*276* Get address of eager buffer from it's index (allocated in chunks, not277* contiguous).278*/279static inline void *qib_get_egrbuf(const struct qib_ctxtdata *rcd, u32 etail)280{281const u32 chunk = etail / rcd->rcvegrbufs_perchunk;282const u32 idx = etail % rcd->rcvegrbufs_perchunk;283284return rcd->rcvegrbuf[chunk] + idx * rcd->dd->rcvegrbufsize;285}286287/*288* Returns 1 if error was a CRC, else 0.289* Needed for some chip's synthesized error counters.290*/291static u32 qib_rcv_hdrerr(struct qib_ctxtdata *rcd, struct qib_pportdata *ppd,292u32 ctxt, u32 eflags, u32 l, u32 etail,293__le32 *rhf_addr, struct qib_message_header *rhdr)294{295u32 ret = 0;296297if (eflags & (QLOGIC_IB_RHF_H_ICRCERR | QLOGIC_IB_RHF_H_VCRCERR))298ret = 1;299else if (eflags == QLOGIC_IB_RHF_H_TIDERR) {300/* For TIDERR and RC QPs premptively schedule a NAK */301struct qib_ib_header *hdr = (struct qib_ib_header *) rhdr;302struct qib_other_headers *ohdr = NULL;303struct qib_ibport *ibp = &ppd->ibport_data;304struct qib_qp *qp = NULL;305u32 tlen = qib_hdrget_length_in_bytes(rhf_addr);306u16 lid = be16_to_cpu(hdr->lrh[1]);307int lnh = be16_to_cpu(hdr->lrh[0]) & 3;308u32 qp_num;309u32 opcode;310u32 psn;311int diff;312unsigned long flags;313314/* Sanity check packet */315if (tlen < 24)316goto drop;317318if (lid < QIB_MULTICAST_LID_BASE) {319lid &= ~((1 << ppd->lmc) - 1);320if (unlikely(lid != ppd->lid))321goto drop;322}323324/* Check for GRH */325if (lnh == QIB_LRH_BTH)326ohdr = &hdr->u.oth;327else if (lnh == QIB_LRH_GRH) {328u32 vtf;329330ohdr = &hdr->u.l.oth;331if (hdr->u.l.grh.next_hdr != IB_GRH_NEXT_HDR)332goto drop;333vtf = be32_to_cpu(hdr->u.l.grh.version_tclass_flow);334if ((vtf >> IB_GRH_VERSION_SHIFT) != IB_GRH_VERSION)335goto drop;336} else337goto drop;338339/* Get opcode and PSN from packet */340opcode = be32_to_cpu(ohdr->bth[0]);341opcode >>= 24;342psn = be32_to_cpu(ohdr->bth[2]);343344/* Get the destination QP number. */345qp_num = be32_to_cpu(ohdr->bth[1]) & QIB_QPN_MASK;346if (qp_num != QIB_MULTICAST_QPN) {347int ruc_res;348qp = qib_lookup_qpn(ibp, qp_num);349if (!qp)350goto drop;351352/*353* Handle only RC QPs - for other QP types drop error354* packet.355*/356spin_lock(&qp->r_lock);357358/* Check for valid receive state. */359if (!(ib_qib_state_ops[qp->state] &360QIB_PROCESS_RECV_OK)) {361ibp->n_pkt_drops++;362goto unlock;363}364365switch (qp->ibqp.qp_type) {366case IB_QPT_RC:367spin_lock_irqsave(&qp->s_lock, flags);368ruc_res =369qib_ruc_check_hdr(370ibp, hdr,371lnh == QIB_LRH_GRH,372qp,373be32_to_cpu(ohdr->bth[0]));374if (ruc_res) {375spin_unlock_irqrestore(&qp->s_lock,376flags);377goto unlock;378}379spin_unlock_irqrestore(&qp->s_lock, flags);380381/* Only deal with RDMA Writes for now */382if (opcode <383IB_OPCODE_RC_RDMA_READ_RESPONSE_FIRST) {384diff = qib_cmp24(psn, qp->r_psn);385if (!qp->r_nak_state && diff >= 0) {386ibp->n_rc_seqnak++;387qp->r_nak_state =388IB_NAK_PSN_ERROR;389/* Use the expected PSN. */390qp->r_ack_psn = qp->r_psn;391/*392* Wait to send the sequence393* NAK until all packets394* in the receive queue have395* been processed.396* Otherwise, we end up397* propagating congestion.398*/399if (list_empty(&qp->rspwait)) {400qp->r_flags |=401QIB_R_RSP_NAK;402atomic_inc(403&qp->refcount);404list_add_tail(405&qp->rspwait,406&rcd->qp_wait_list);407}408} /* Out of sequence NAK */409} /* QP Request NAKs */410break;411case IB_QPT_SMI:412case IB_QPT_GSI:413case IB_QPT_UD:414case IB_QPT_UC:415default:416/* For now don't handle any other QP types */417break;418}419420unlock:421spin_unlock(&qp->r_lock);422/*423* Notify qib_destroy_qp() if it is waiting424* for us to finish.425*/426if (atomic_dec_and_test(&qp->refcount))427wake_up(&qp->wait);428} /* Unicast QP */429} /* Valid packet with TIDErr */430431drop:432return ret;433}434435/*436* qib_kreceive - receive a packet437* @rcd: the qlogic_ib context438* @llic: gets count of good packets needed to clear lli,439* (used with chips that need need to track crcs for lli)440*441* called from interrupt handler for errors or receive interrupt442* Returns number of CRC error packets, needed by some chips for443* local link integrity tracking. crcs are adjusted down by following444* good packets, if any, and count of good packets is also tracked.445*/446u32 qib_kreceive(struct qib_ctxtdata *rcd, u32 *llic, u32 *npkts)447{448struct qib_devdata *dd = rcd->dd;449struct qib_pportdata *ppd = rcd->ppd;450__le32 *rhf_addr;451void *ebuf;452const u32 rsize = dd->rcvhdrentsize; /* words */453const u32 maxcnt = dd->rcvhdrcnt * rsize; /* words */454u32 etail = -1, l, hdrqtail;455struct qib_message_header *hdr;456u32 eflags, etype, tlen, i = 0, updegr = 0, crcs = 0;457int last;458u64 lval;459struct qib_qp *qp, *nqp;460461l = rcd->head;462rhf_addr = (__le32 *) rcd->rcvhdrq + l + dd->rhf_offset;463if (dd->flags & QIB_NODMA_RTAIL) {464u32 seq = qib_hdrget_seq(rhf_addr);465if (seq != rcd->seq_cnt)466goto bail;467hdrqtail = 0;468} else {469hdrqtail = qib_get_rcvhdrtail(rcd);470if (l == hdrqtail)471goto bail;472smp_rmb(); /* prevent speculative reads of dma'ed hdrq */473}474475for (last = 0, i = 1; !last; i += !last) {476hdr = dd->f_get_msgheader(dd, rhf_addr);477eflags = qib_hdrget_err_flags(rhf_addr);478etype = qib_hdrget_rcv_type(rhf_addr);479/* total length */480tlen = qib_hdrget_length_in_bytes(rhf_addr);481ebuf = NULL;482if ((dd->flags & QIB_NODMA_RTAIL) ?483qib_hdrget_use_egr_buf(rhf_addr) :484(etype != RCVHQ_RCV_TYPE_EXPECTED)) {485etail = qib_hdrget_index(rhf_addr);486updegr = 1;487if (tlen > sizeof(*hdr) ||488etype >= RCVHQ_RCV_TYPE_NON_KD)489ebuf = qib_get_egrbuf(rcd, etail);490}491if (!eflags) {492u16 lrh_len = be16_to_cpu(hdr->lrh[2]) << 2;493494if (lrh_len != tlen) {495qib_stats.sps_lenerrs++;496goto move_along;497}498}499if (etype == RCVHQ_RCV_TYPE_NON_KD && !eflags &&500ebuf == NULL &&501tlen > (dd->rcvhdrentsize - 2 + 1 -502qib_hdrget_offset(rhf_addr)) << 2) {503goto move_along;504}505506/*507* Both tiderr and qibhdrerr are set for all plain IB508* packets; only qibhdrerr should be set.509*/510if (unlikely(eflags))511crcs += qib_rcv_hdrerr(rcd, ppd, rcd->ctxt, eflags, l,512etail, rhf_addr, hdr);513else if (etype == RCVHQ_RCV_TYPE_NON_KD) {514qib_ib_rcv(rcd, hdr, ebuf, tlen);515if (crcs)516crcs--;517else if (llic && *llic)518--*llic;519}520move_along:521l += rsize;522if (l >= maxcnt)523l = 0;524if (i == QIB_MAX_PKT_RECV)525last = 1;526527rhf_addr = (__le32 *) rcd->rcvhdrq + l + dd->rhf_offset;528if (dd->flags & QIB_NODMA_RTAIL) {529u32 seq = qib_hdrget_seq(rhf_addr);530531if (++rcd->seq_cnt > 13)532rcd->seq_cnt = 1;533if (seq != rcd->seq_cnt)534last = 1;535} else if (l == hdrqtail)536last = 1;537/*538* Update head regs etc., every 16 packets, if not last pkt,539* to help prevent rcvhdrq overflows, when many packets540* are processed and queue is nearly full.541* Don't request an interrupt for intermediate updates.542*/543lval = l;544if (!last && !(i & 0xf)) {545dd->f_update_usrhead(rcd, lval, updegr, etail, i);546updegr = 0;547}548}549550rcd->head = l;551rcd->pkt_count += i;552553/*554* Iterate over all QPs waiting to respond.555* The list won't change since the IRQ is only run on one CPU.556*/557list_for_each_entry_safe(qp, nqp, &rcd->qp_wait_list, rspwait) {558list_del_init(&qp->rspwait);559if (qp->r_flags & QIB_R_RSP_NAK) {560qp->r_flags &= ~QIB_R_RSP_NAK;561qib_send_rc_ack(qp);562}563if (qp->r_flags & QIB_R_RSP_SEND) {564unsigned long flags;565566qp->r_flags &= ~QIB_R_RSP_SEND;567spin_lock_irqsave(&qp->s_lock, flags);568if (ib_qib_state_ops[qp->state] &569QIB_PROCESS_OR_FLUSH_SEND)570qib_schedule_send(qp);571spin_unlock_irqrestore(&qp->s_lock, flags);572}573if (atomic_dec_and_test(&qp->refcount))574wake_up(&qp->wait);575}576577bail:578/* Report number of packets consumed */579if (npkts)580*npkts = i;581582/*583* Always write head at end, and setup rcv interrupt, even584* if no packets were processed.585*/586lval = (u64)rcd->head | dd->rhdrhead_intr_off;587dd->f_update_usrhead(rcd, lval, updegr, etail, i);588return crcs;589}590591/**592* qib_set_mtu - set the MTU593* @ppd: the perport data594* @arg: the new MTU595*596* We can handle "any" incoming size, the issue here is whether we597* need to restrict our outgoing size. For now, we don't do any598* sanity checking on this, and we don't deal with what happens to599* programs that are already running when the size changes.600* NOTE: changing the MTU will usually cause the IBC to go back to601* link INIT state...602*/603int qib_set_mtu(struct qib_pportdata *ppd, u16 arg)604{605u32 piosize;606int ret, chk;607608if (arg != 256 && arg != 512 && arg != 1024 && arg != 2048 &&609arg != 4096) {610ret = -EINVAL;611goto bail;612}613chk = ib_mtu_enum_to_int(qib_ibmtu);614if (chk > 0 && arg > chk) {615ret = -EINVAL;616goto bail;617}618619piosize = ppd->ibmaxlen;620ppd->ibmtu = arg;621622if (arg >= (piosize - QIB_PIO_MAXIBHDR)) {623/* Only if it's not the initial value (or reset to it) */624if (piosize != ppd->init_ibmaxlen) {625if (arg > piosize && arg <= ppd->init_ibmaxlen)626piosize = ppd->init_ibmaxlen - 2 * sizeof(u32);627ppd->ibmaxlen = piosize;628}629} else if ((arg + QIB_PIO_MAXIBHDR) != ppd->ibmaxlen) {630piosize = arg + QIB_PIO_MAXIBHDR - 2 * sizeof(u32);631ppd->ibmaxlen = piosize;632}633634ppd->dd->f_set_ib_cfg(ppd, QIB_IB_CFG_MTU, 0);635636ret = 0;637638bail:639return ret;640}641642int qib_set_lid(struct qib_pportdata *ppd, u32 lid, u8 lmc)643{644struct qib_devdata *dd = ppd->dd;645ppd->lid = lid;646ppd->lmc = lmc;647648dd->f_set_ib_cfg(ppd, QIB_IB_CFG_LIDLMC,649lid | (~((1U << lmc) - 1)) << 16);650651qib_devinfo(dd->pcidev, "IB%u:%u got a lid: 0x%x\n",652dd->unit, ppd->port, lid);653654return 0;655}656657/*658* Following deal with the "obviously simple" task of overriding the state659* of the LEDS, which normally indicate link physical and logical status.660* The complications arise in dealing with different hardware mappings661* and the board-dependent routine being called from interrupts.662* and then there's the requirement to _flash_ them.663*/664#define LED_OVER_FREQ_SHIFT 8665#define LED_OVER_FREQ_MASK (0xFF<<LED_OVER_FREQ_SHIFT)666/* Below is "non-zero" to force override, but both actual LEDs are off */667#define LED_OVER_BOTH_OFF (8)668669static void qib_run_led_override(unsigned long opaque)670{671struct qib_pportdata *ppd = (struct qib_pportdata *)opaque;672struct qib_devdata *dd = ppd->dd;673int timeoff;674int ph_idx;675676if (!(dd->flags & QIB_INITTED))677return;678679ph_idx = ppd->led_override_phase++ & 1;680ppd->led_override = ppd->led_override_vals[ph_idx];681timeoff = ppd->led_override_timeoff;682683dd->f_setextled(ppd, 1);684/*685* don't re-fire the timer if user asked for it to be off; we let686* it fire one more time after they turn it off to simplify687*/688if (ppd->led_override_vals[0] || ppd->led_override_vals[1])689mod_timer(&ppd->led_override_timer, jiffies + timeoff);690}691692void qib_set_led_override(struct qib_pportdata *ppd, unsigned int val)693{694struct qib_devdata *dd = ppd->dd;695int timeoff, freq;696697if (!(dd->flags & QIB_INITTED))698return;699700/* First check if we are blinking. If not, use 1HZ polling */701timeoff = HZ;702freq = (val & LED_OVER_FREQ_MASK) >> LED_OVER_FREQ_SHIFT;703704if (freq) {705/* For blink, set each phase from one nybble of val */706ppd->led_override_vals[0] = val & 0xF;707ppd->led_override_vals[1] = (val >> 4) & 0xF;708timeoff = (HZ << 4)/freq;709} else {710/* Non-blink set both phases the same. */711ppd->led_override_vals[0] = val & 0xF;712ppd->led_override_vals[1] = val & 0xF;713}714ppd->led_override_timeoff = timeoff;715716/*717* If the timer has not already been started, do so. Use a "quick"718* timeout so the function will be called soon, to look at our request.719*/720if (atomic_inc_return(&ppd->led_override_timer_active) == 1) {721/* Need to start timer */722init_timer(&ppd->led_override_timer);723ppd->led_override_timer.function = qib_run_led_override;724ppd->led_override_timer.data = (unsigned long) ppd;725ppd->led_override_timer.expires = jiffies + 1;726add_timer(&ppd->led_override_timer);727} else {728if (ppd->led_override_vals[0] || ppd->led_override_vals[1])729mod_timer(&ppd->led_override_timer, jiffies + 1);730atomic_dec(&ppd->led_override_timer_active);731}732}733734/**735* qib_reset_device - reset the chip if possible736* @unit: the device to reset737*738* Whether or not reset is successful, we attempt to re-initialize the chip739* (that is, much like a driver unload/reload). We clear the INITTED flag740* so that the various entry points will fail until we reinitialize. For741* now, we only allow this if no user contexts are open that use chip resources742*/743int qib_reset_device(int unit)744{745int ret, i;746struct qib_devdata *dd = qib_lookup(unit);747struct qib_pportdata *ppd;748unsigned long flags;749int pidx;750751if (!dd) {752ret = -ENODEV;753goto bail;754}755756qib_devinfo(dd->pcidev, "Reset on unit %u requested\n", unit);757758if (!dd->kregbase || !(dd->flags & QIB_PRESENT)) {759qib_devinfo(dd->pcidev, "Invalid unit number %u or "760"not initialized or not present\n", unit);761ret = -ENXIO;762goto bail;763}764765spin_lock_irqsave(&dd->uctxt_lock, flags);766if (dd->rcd)767for (i = dd->first_user_ctxt; i < dd->cfgctxts; i++) {768if (!dd->rcd[i] || !dd->rcd[i]->cnt)769continue;770spin_unlock_irqrestore(&dd->uctxt_lock, flags);771ret = -EBUSY;772goto bail;773}774spin_unlock_irqrestore(&dd->uctxt_lock, flags);775776for (pidx = 0; pidx < dd->num_pports; ++pidx) {777ppd = dd->pport + pidx;778if (atomic_read(&ppd->led_override_timer_active)) {779/* Need to stop LED timer, _then_ shut off LEDs */780del_timer_sync(&ppd->led_override_timer);781atomic_set(&ppd->led_override_timer_active, 0);782}783784/* Shut off LEDs after we are sure timer is not running */785ppd->led_override = LED_OVER_BOTH_OFF;786dd->f_setextled(ppd, 0);787if (dd->flags & QIB_HAS_SEND_DMA)788qib_teardown_sdma(ppd);789}790791ret = dd->f_reset(dd);792if (ret == 1)793ret = qib_init(dd, 1);794else795ret = -EAGAIN;796if (ret)797qib_dev_err(dd, "Reinitialize unit %u after "798"reset failed with %d\n", unit, ret);799else800qib_devinfo(dd->pcidev, "Reinitialized unit %u after "801"resetting\n", unit);802803bail:804return ret;805}806807808