0001
0002
0003
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
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
0032
0033
0034
0035
0036
0037 static void add_full_mgmt_pkey(struct hfi1_pportdata *ppd)
0038 {
0039 struct hfi1_devdata *dd = ppd->dd;
0040
0041
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
0052
0053
0054
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
0065
0066
0067
0068
0069
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
0088
0089
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
0101
0102
0103
0104
0105
0106
0107
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;
0117
0118 if (linkup) {
0119
0120
0121
0122
0123
0124
0125
0126
0127
0128
0129
0130
0131
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
0156 udelay(LINK_UP_DELAY);
0157
0158
0159
0160
0161
0162 set_mgmt_allowed(ppd);
0163
0164 if (ppd->mgmt_allowed)
0165 add_full_mgmt_pkey(ppd);
0166
0167
0168 ppd->linkup = 1;
0169 ppd->offline_disabled_reason =
0170 HFI1_ODR_MASK(OPA_LINKDOWN_REASON_NONE);
0171
0172
0173 get_linkup_link_widths(ppd);
0174
0175 } else {
0176
0177 ppd->linkup = 0;
0178
0179
0180 ppd->actual_vls_operational = 0;
0181 reset_link_credits(dd);
0182
0183
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
0191 ppd->neighbor_normal = 0;
0192
0193
0194 signal_ib_event(ppd, ev);
0195 }
0196 }
0197
0198
0199
0200
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 }