Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0 or BSD-3-Clause
0002 /*
0003  * Copyright(c) 2015, 2016 Intel Corporation.
0004  */
0005 
0006 #include <linux/pci.h>
0007 #include <linux/delay.h>
0008 #include <linux/bitmap.h>
0009 
0010 #include "hfi.h"
0011 #include "common.h"
0012 #include "sdma.h"
0013 
0014 #define LINK_UP_DELAY  500  /* in microseconds */
0015 
0016 static void set_mgmt_allowed(struct hfi1_pportdata *ppd)
0017 {
0018     u32 frame;
0019     struct hfi1_devdata *dd = ppd->dd;
0020 
0021     if (ppd->neighbor_type == NEIGHBOR_TYPE_HFI) {
0022         ppd->mgmt_allowed = 1;
0023     } else {
0024         read_8051_config(dd, REMOTE_LNI_INFO, GENERAL_CONFIG, &frame);
0025         ppd->mgmt_allowed = (frame >> MGMT_ALLOWED_SHIFT)
0026         & MGMT_ALLOWED_MASK;
0027     }
0028 }
0029 
0030 /*
0031  * Our neighbor has indicated that we are allowed to act as a fabric
0032  * manager, so place the full management partition key in the second
0033  * (0-based) pkey array position. Note that we should already have
0034  * the limited management partition key in array element 1, and also
0035  * that the port is not yet up when add_full_mgmt_pkey() is invoked.
0036  */
0037 static void add_full_mgmt_pkey(struct hfi1_pportdata *ppd)
0038 {
0039     struct hfi1_devdata *dd = ppd->dd;
0040 
0041     /* Sanity check - ppd->pkeys[2] should be 0, or already initialized */
0042     if (!((ppd->pkeys[2] == 0) || (ppd->pkeys[2] == FULL_MGMT_P_KEY)))
0043         dd_dev_warn(dd, "%s pkey[2] already set to 0x%x, resetting it to 0x%x\n",
0044                 __func__, ppd->pkeys[2], FULL_MGMT_P_KEY);
0045     ppd->pkeys[2] = FULL_MGMT_P_KEY;
0046     (void)hfi1_set_ib_cfg(ppd, HFI1_IB_CFG_PKEYS, 0);
0047     hfi1_event_pkey_change(ppd->dd, ppd->port);
0048 }
0049 
0050 /**
0051  * format_hwmsg - format a single hwerror message
0052  * @msg: message buffer
0053  * @msgl: length of message buffer
0054  * @hwmsg: message to add to message buffer
0055  */
0056 static void format_hwmsg(char *msg, size_t msgl, const char *hwmsg)
0057 {
0058     strlcat(msg, "[", msgl);
0059     strlcat(msg, hwmsg, msgl);
0060     strlcat(msg, "]", msgl);
0061 }
0062 
0063 /**
0064  * hfi1_format_hwerrors - format hardware error messages for display
0065  * @hwerrs: hardware errors bit vector
0066  * @hwerrmsgs: hardware error descriptions
0067  * @nhwerrmsgs: number of hwerrmsgs
0068  * @msg: message buffer
0069  * @msgl: message buffer length
0070  */
0071 void hfi1_format_hwerrors(u64 hwerrs, const struct hfi1_hwerror_msgs *hwerrmsgs,
0072               size_t nhwerrmsgs, char *msg, size_t msgl)
0073 {
0074     int i;
0075 
0076     for (i = 0; i < nhwerrmsgs; i++)
0077         if (hwerrs & hwerrmsgs[i].mask)
0078             format_hwmsg(msg, msgl, hwerrmsgs[i].msg);
0079 }
0080 
0081 static void signal_ib_event(struct hfi1_pportdata *ppd, enum ib_event_type ev)
0082 {
0083     struct ib_event event;
0084     struct hfi1_devdata *dd = ppd->dd;
0085 
0086     /*
0087      * Only call ib_dispatch_event() if the IB device has been
0088      * registered.  HFI1_INITED is set iff the driver has successfully
0089      * registered with the IB core.
0090      */
0091     if (!(dd->flags & HFI1_INITTED))
0092         return;
0093     event.device = &dd->verbs_dev.rdi.ibdev;
0094     event.element.port_num = ppd->port;
0095     event.event = ev;
0096     ib_dispatch_event(&event);
0097 }
0098 
0099 /**
0100  * handle_linkup_change - finish linkup/down state changes
0101  * @dd: valid device
0102  * @linkup: link state information
0103  *
0104  * Handle a linkup or link down notification.
0105  * The HW needs time to finish its link up state change. Give it that chance.
0106  *
0107  * This is called outside an interrupt.
0108  *
0109  */
0110 void handle_linkup_change(struct hfi1_devdata *dd, u32 linkup)
0111 {
0112     struct hfi1_pportdata *ppd = &dd->pport[0];
0113     enum ib_event_type ev;
0114 
0115     if (!(ppd->linkup ^ !!linkup))
0116         return; /* no change, nothing to do */
0117 
0118     if (linkup) {
0119         /*
0120          * Quick linkup and all link up on the simulator does not
0121          * trigger or implement:
0122          *  - VerifyCap interrupt
0123          *  - VerifyCap frames
0124          * But rather moves directly to LinkUp.
0125          *
0126          * Do the work of the VerifyCap interrupt handler,
0127          * handle_verify_cap(), but do not try moving the state to
0128          * LinkUp as we are already there.
0129          *
0130          * NOTE: This uses this device's vAU, vCU, and vl15_init for
0131          * the remote values.  Both sides must be using the values.
0132          */
0133         if (quick_linkup || dd->icode == ICODE_FUNCTIONAL_SIMULATOR) {
0134             set_up_vau(dd, dd->vau);
0135             set_up_vl15(dd, dd->vl15_init);
0136             assign_remote_cm_au_table(dd, dd->vcu);
0137         }
0138 
0139         ppd->neighbor_guid =
0140             read_csr(dd, DC_DC8051_STS_REMOTE_GUID);
0141         ppd->neighbor_type =
0142             read_csr(dd, DC_DC8051_STS_REMOTE_NODE_TYPE) &
0143                  DC_DC8051_STS_REMOTE_NODE_TYPE_VAL_MASK;
0144         ppd->neighbor_port_number =
0145             read_csr(dd, DC_DC8051_STS_REMOTE_PORT_NO) &
0146                  DC_DC8051_STS_REMOTE_PORT_NO_VAL_SMASK;
0147         ppd->neighbor_fm_security =
0148             read_csr(dd, DC_DC8051_STS_REMOTE_FM_SECURITY) &
0149                  DC_DC8051_STS_LOCAL_FM_SECURITY_DISABLED_MASK;
0150         dd_dev_info(dd,
0151                 "Neighbor Guid %llx, Type %d, Port Num %d\n",
0152                 ppd->neighbor_guid, ppd->neighbor_type,
0153                 ppd->neighbor_port_number);
0154 
0155         /* HW needs LINK_UP_DELAY to settle, give it that chance */
0156         udelay(LINK_UP_DELAY);
0157 
0158         /*
0159          * 'MgmtAllowed' information, which is exchanged during
0160          * LNI, is available at this point.
0161          */
0162         set_mgmt_allowed(ppd);
0163 
0164         if (ppd->mgmt_allowed)
0165             add_full_mgmt_pkey(ppd);
0166 
0167         /* physical link went up */
0168         ppd->linkup = 1;
0169         ppd->offline_disabled_reason =
0170             HFI1_ODR_MASK(OPA_LINKDOWN_REASON_NONE);
0171 
0172         /* link widths are not available until the link is fully up */
0173         get_linkup_link_widths(ppd);
0174 
0175     } else {
0176         /* physical link went down */
0177         ppd->linkup = 0;
0178 
0179         /* clear HW details of the previous connection */
0180         ppd->actual_vls_operational = 0;
0181         reset_link_credits(dd);
0182 
0183         /* freeze after a link down to guarantee a clean egress */
0184         start_freeze_handling(ppd, FREEZE_SELF | FREEZE_LINK_DOWN);
0185 
0186         ev = IB_EVENT_PORT_ERR;
0187 
0188         hfi1_set_uevent_bits(ppd, _HFI1_EVENT_LINKDOWN_BIT);
0189 
0190         /* if we are down, the neighbor is down */
0191         ppd->neighbor_normal = 0;
0192 
0193         /* notify IB of the link change */
0194         signal_ib_event(ppd, ev);
0195     }
0196 }
0197 
0198 /*
0199  * Handle receive or urgent interrupts for user contexts.  This means a user
0200  * process was waiting for a packet to arrive, and didn't want to poll.
0201  */
0202 void handle_user_interrupt(struct hfi1_ctxtdata *rcd)
0203 {
0204     struct hfi1_devdata *dd = rcd->dd;
0205     unsigned long flags;
0206 
0207     spin_lock_irqsave(&dd->uctxt_lock, flags);
0208     if (bitmap_empty(rcd->in_use_ctxts, HFI1_MAX_SHARED_CTXTS))
0209         goto done;
0210 
0211     if (test_and_clear_bit(HFI1_CTXT_WAITING_RCV, &rcd->event_flags)) {
0212         wake_up_interruptible(&rcd->wait);
0213         hfi1_rcvctrl(dd, HFI1_RCVCTRL_INTRAVAIL_DIS, rcd);
0214     } else if (test_and_clear_bit(HFI1_CTXT_WAITING_URG,
0215                             &rcd->event_flags)) {
0216         rcd->urgent++;
0217         wake_up_interruptible(&rcd->wait);
0218     }
0219 done:
0220     spin_unlock_irqrestore(&dd->uctxt_lock, flags);
0221 }