forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-12-19 9370bb92b2d16684ee45cf24e879c93c509162da
kernel/drivers/net/ethernet/chelsio/cxgb4/t4_hw.c
....@@ -198,7 +198,7 @@
198198 if (pcie_fw & PCIE_FW_ERR_F) {
199199 dev_err(adap->pdev_dev, "Firmware reports adapter error: %s\n",
200200 reason[PCIE_FW_EVAL_G(pcie_fw)]);
201
- adap->flags &= ~FW_OK;
201
+ adap->flags &= ~CXGB4_FW_OK;
202202 }
203203 }
204204
....@@ -329,7 +329,7 @@
329329 for (i = 0; ; i += ms) {
330330 /* If we've waited too long, return a busy indication. This
331331 * really ought to be based on our initial position in the
332
- * mailbox access list but this is a start. We very rearely
332
+ * mailbox access list but this is a start. We very rarely
333333 * contend on access to the mailbox ...
334334 */
335335 pcie_fw = t4_read_reg(adap, PCIE_FW_A);
....@@ -606,7 +606,7 @@
606606 *
607607 * Reads/writes an [almost] arbitrary memory region in the firmware: the
608608 * firmware memory address and host buffer must be aligned on 32-bit
609
- * boudaries; the length may be arbitrary. The memory is transferred as
609
+ * boundaries; the length may be arbitrary. The memory is transferred as
610610 * a raw byte sequence from/to the firmware's memory. If this memory
611611 * contains data structures which contain multi-byte integers, it's the
612612 * caller's responsibility to perform appropriate byte order conversions.
....@@ -1379,8 +1379,7 @@
13791379 0x9608, 0x9638,
13801380 0x9640, 0x96f4,
13811381 0x9800, 0x9808,
1382
- 0x9820, 0x983c,
1383
- 0x9850, 0x9864,
1382
+ 0x9810, 0x9864,
13841383 0x9c00, 0x9c6c,
13851384 0x9c80, 0x9cec,
13861385 0x9d00, 0x9d6c,
....@@ -1389,7 +1388,7 @@
13891388 0x9e80, 0x9eec,
13901389 0x9f00, 0x9f6c,
13911390 0x9f80, 0xa020,
1392
- 0xd004, 0xd004,
1391
+ 0xd000, 0xd004,
13931392 0xd010, 0xd03c,
13941393 0xdfc0, 0xdfe0,
13951394 0xe000, 0x1106c,
....@@ -1430,10 +1429,8 @@
14301429 0x1a0b0, 0x1a0e4,
14311430 0x1a0ec, 0x1a0f8,
14321431 0x1a100, 0x1a108,
1433
- 0x1a114, 0x1a120,
1434
- 0x1a128, 0x1a130,
1435
- 0x1a138, 0x1a138,
1436
- 0x1a190, 0x1a1c4,
1432
+ 0x1a114, 0x1a130,
1433
+ 0x1a138, 0x1a1c4,
14371434 0x1a1fc, 0x1a1fc,
14381435 0x1e008, 0x1e00c,
14391436 0x1e040, 0x1e044,
....@@ -2163,8 +2160,7 @@
21632160 0x9640, 0x9704,
21642161 0x9710, 0x971c,
21652162 0x9800, 0x9808,
2166
- 0x9820, 0x983c,
2167
- 0x9850, 0x9864,
2163
+ 0x9810, 0x9864,
21682164 0x9c00, 0x9c6c,
21692165 0x9c80, 0x9cec,
21702166 0x9d00, 0x9d6c,
....@@ -2173,7 +2169,7 @@
21732169 0x9e80, 0x9eec,
21742170 0x9f00, 0x9f6c,
21752171 0x9f80, 0xa020,
2176
- 0xd004, 0xd03c,
2172
+ 0xd000, 0xd03c,
21772173 0xd100, 0xd118,
21782174 0xd200, 0xd214,
21792175 0xd220, 0xd234,
....@@ -2241,10 +2237,8 @@
22412237 0x1a0b0, 0x1a0e4,
22422238 0x1a0ec, 0x1a0f8,
22432239 0x1a100, 0x1a108,
2244
- 0x1a114, 0x1a120,
2245
- 0x1a128, 0x1a130,
2246
- 0x1a138, 0x1a138,
2247
- 0x1a190, 0x1a1c4,
2240
+ 0x1a114, 0x1a130,
2241
+ 0x1a138, 0x1a1c4,
22482242 0x1a1fc, 0x1a1fc,
22492243 0x1e008, 0x1e00c,
22502244 0x1e040, 0x1e044,
....@@ -3073,16 +3067,19 @@
30733067 * @addr: the start address to write
30743068 * @n: length of data to write in bytes
30753069 * @data: the data to write
3070
+ * @byte_oriented: whether to store data as bytes or as words
30763071 *
30773072 * Writes up to a page of data (256 bytes) to the serial flash starting
30783073 * at the given address. All the data must be written to the same page.
3074
+ * If @byte_oriented is set the write data is stored as byte stream
3075
+ * (i.e. matches what on disk), otherwise in big-endian.
30793076 */
30803077 static int t4_write_flash(struct adapter *adapter, unsigned int addr,
3081
- unsigned int n, const u8 *data)
3078
+ unsigned int n, const u8 *data, bool byte_oriented)
30823079 {
3083
- int ret;
3084
- u32 buf[64];
30853080 unsigned int i, c, left, val, offset = addr & 0xff;
3081
+ u32 buf[64];
3082
+ int ret;
30863083
30873084 if (addr >= adapter->params.sf_size || offset + n > SF_PAGE_SIZE)
30883085 return -EINVAL;
....@@ -3093,10 +3090,14 @@
30933090 (ret = sf1_write(adapter, 4, 1, 1, val)) != 0)
30943091 goto unlock;
30953092
3096
- for (left = n; left; left -= c) {
3093
+ for (left = n; left; left -= c, data += c) {
30973094 c = min(left, 4U);
3098
- for (val = 0, i = 0; i < c; ++i)
3099
- val = (val << 8) + *data++;
3095
+ for (val = 0, i = 0; i < c; ++i) {
3096
+ if (byte_oriented)
3097
+ val = (val << 8) + data[i];
3098
+ else
3099
+ val = (val << 8) + data[c - i - 1];
3100
+ }
31003101
31013102 ret = sf1_write(adapter, c, c != left, 1, val);
31023103 if (ret)
....@@ -3109,7 +3110,8 @@
31093110 t4_write_reg(adapter, SF_OP_A, 0); /* unlock SF */
31103111
31113112 /* Read the page to verify the write succeeded */
3112
- ret = t4_read_flash(adapter, addr & ~0xff, ARRAY_SIZE(buf), buf, 1);
3113
+ ret = t4_read_flash(adapter, addr & ~0xff, ARRAY_SIZE(buf), buf,
3114
+ byte_oriented);
31133115 if (ret)
31143116 return ret;
31153117
....@@ -3170,7 +3172,7 @@
31703172
31713173 /**
31723174 * t4_get_exprom_version - return the Expansion ROM version (if any)
3173
- * @adapter: the adapter
3175
+ * @adap: the adapter
31743176 * @vers: where to place the version
31753177 *
31763178 * Reads the Expansion ROM header from FLASH and returns the version
....@@ -3705,7 +3707,7 @@
37053707 */
37063708 memcpy(first_page, fw_data, SF_PAGE_SIZE);
37073709 ((struct fw_hdr *)first_page)->fw_ver = cpu_to_be32(0xffffffff);
3708
- ret = t4_write_flash(adap, fw_start, SF_PAGE_SIZE, first_page);
3710
+ ret = t4_write_flash(adap, fw_start, SF_PAGE_SIZE, first_page, true);
37093711 if (ret)
37103712 goto out;
37113713
....@@ -3713,14 +3715,14 @@
37133715 for (size -= SF_PAGE_SIZE; size; size -= SF_PAGE_SIZE) {
37143716 addr += SF_PAGE_SIZE;
37153717 fw_data += SF_PAGE_SIZE;
3716
- ret = t4_write_flash(adap, addr, SF_PAGE_SIZE, fw_data);
3718
+ ret = t4_write_flash(adap, addr, SF_PAGE_SIZE, fw_data, true);
37173719 if (ret)
37183720 goto out;
37193721 }
37203722
3721
- ret = t4_write_flash(adap,
3722
- fw_start + offsetof(struct fw_hdr, fw_ver),
3723
- sizeof(hdr->fw_ver), (const u8 *)&hdr->fw_ver);
3723
+ ret = t4_write_flash(adap, fw_start + offsetof(struct fw_hdr, fw_ver),
3724
+ sizeof(hdr->fw_ver), (const u8 *)&hdr->fw_ver,
3725
+ true);
37243726 out:
37253727 if (ret)
37263728 dev_err(adap->pdev_dev, "firmware download failed, error %d\n",
....@@ -3759,7 +3761,6 @@
37593761 * t4_load_phy_fw - download port PHY firmware
37603762 * @adap: the adapter
37613763 * @win: the PCI-E Memory Window index to use for t4_memory_rw()
3762
- * @win_lock: the lock to use to guard the memory copy
37633764 * @phy_fw_version: function to check PHY firmware versions
37643765 * @phy_fw_data: the PHY firmware image to write
37653766 * @phy_fw_size: image size
....@@ -3768,34 +3769,31 @@
37683769 * @phy_fw_version is supplied, then it will be used to determine if
37693770 * it's necessary to perform the transfer by comparing the version
37703771 * of any existing adapter PHY firmware with that of the passed in
3771
- * PHY firmware image. If @win_lock is non-NULL then it will be used
3772
- * around the call to t4_memory_rw() which transfers the PHY firmware
3773
- * to the adapter.
3772
+ * PHY firmware image.
37743773 *
37753774 * A negative error number will be returned if an error occurs. If
37763775 * version number support is available and there's no need to upgrade
37773776 * the firmware, 0 will be returned. If firmware is successfully
3778
- * transferred to the adapter, 1 will be retured.
3777
+ * transferred to the adapter, 1 will be returned.
37793778 *
37803779 * NOTE: some adapters only have local RAM to store the PHY firmware. As
37813780 * a result, a RESET of the adapter would cause that RAM to lose its
37823781 * contents. Thus, loading PHY firmware on such adapters must happen
37833782 * after any FW_RESET_CMDs ...
37843783 */
3785
-int t4_load_phy_fw(struct adapter *adap,
3786
- int win, spinlock_t *win_lock,
3784
+int t4_load_phy_fw(struct adapter *adap, int win,
37873785 int (*phy_fw_version)(const u8 *, size_t),
37883786 const u8 *phy_fw_data, size_t phy_fw_size)
37893787 {
3788
+ int cur_phy_fw_ver = 0, new_phy_fw_vers = 0;
37903789 unsigned long mtype = 0, maddr = 0;
37913790 u32 param, val;
3792
- int cur_phy_fw_ver = 0, new_phy_fw_vers = 0;
37933791 int ret;
37943792
37953793 /* If we have version number support, then check to see if the adapter
37963794 * already has up-to-date PHY firmware loaded.
37973795 */
3798
- if (phy_fw_version) {
3796
+ if (phy_fw_version) {
37993797 new_phy_fw_vers = phy_fw_version(phy_fw_data, phy_fw_size);
38003798 ret = t4_phy_fw_ver(adap, &cur_phy_fw_ver);
38013799 if (ret < 0)
....@@ -3809,7 +3807,7 @@
38093807 }
38103808
38113809 /* Ask the firmware where it wants us to copy the PHY firmware image.
3812
- * The size of the file requires a special version of the READ coommand
3810
+ * The size of the file requires a special version of the READ command
38133811 * which will pass the file size via the values field in PARAMS_CMD and
38143812 * retrieve the return value from firmware and place it in the same
38153813 * buffer values
....@@ -3829,13 +3827,11 @@
38293827 /* Copy the supplied PHY Firmware image to the adapter memory location
38303828 * allocated by the adapter firmware.
38313829 */
3832
- if (win_lock)
3833
- spin_lock_bh(win_lock);
3830
+ spin_lock_bh(&adap->win0_lock);
38343831 ret = t4_memory_rw(adap, win, mtype, maddr,
38353832 phy_fw_size, (__be32 *)phy_fw_data,
38363833 T4_MEMORY_WRITE);
3837
- if (win_lock)
3838
- spin_unlock_bh(win_lock);
3834
+ spin_unlock_bh(&adap->win0_lock);
38393835 if (ret)
38403836 return ret;
38413837
....@@ -3965,6 +3961,14 @@
39653961 }
39663962 }
39673963
3964
+/* The ADVERT_MASK is used to mask out all of the Advertised Firmware Port
3965
+ * Capabilities which we control with separate controls -- see, for instance,
3966
+ * Pause Frames and Forward Error Correction. In order to determine what the
3967
+ * full set of Advertised Port Capabilities are, the base Advertised Port
3968
+ * Capabilities (masked by ADVERT_MASK) must be combined with the Advertised
3969
+ * Port Capabilities associated with those other controls. See
3970
+ * t4_link_acaps() for how this is done.
3971
+ */
39683972 #define ADVERT_MASK (FW_PORT_CAP32_SPEED_V(FW_PORT_CAP32_SPEED_M) | \
39693973 FW_PORT_CAP32_ANEG)
39703974
....@@ -4062,6 +4066,9 @@
40624066 /* Translate Common Code Pause specification into Firmware Port Capabilities */
40634067 static inline fw_port_cap32_t cc_to_fwcap_pause(enum cc_pause cc_pause)
40644068 {
4069
+ /* Translate orthogonal RX/TX Pause Controls for L1 Configure
4070
+ * commands, etc.
4071
+ */
40654072 fw_port_cap32_t fw_pause = 0;
40664073
40674074 if (cc_pause & PAUSE_RX)
....@@ -4070,6 +4077,20 @@
40704077 fw_pause |= FW_PORT_CAP32_FC_TX;
40714078 if (!(cc_pause & PAUSE_AUTONEG))
40724079 fw_pause |= FW_PORT_CAP32_FORCE_PAUSE;
4080
+
4081
+ /* Translate orthogonal Pause controls into IEEE 802.3 Pause,
4082
+ * Asymmetrical Pause for use in reporting to upper layer OS code, etc.
4083
+ * Note that these bits are ignored in L1 Configure commands.
4084
+ */
4085
+ if (cc_pause & PAUSE_RX) {
4086
+ if (cc_pause & PAUSE_TX)
4087
+ fw_pause |= FW_PORT_CAP32_802_3_PAUSE;
4088
+ else
4089
+ fw_pause |= FW_PORT_CAP32_802_3_ASM_DIR |
4090
+ FW_PORT_CAP32_802_3_PAUSE;
4091
+ } else if (cc_pause & PAUSE_TX) {
4092
+ fw_pause |= FW_PORT_CAP32_802_3_ASM_DIR;
4093
+ }
40734094
40744095 return fw_pause;
40754096 }
....@@ -4101,30 +4122,25 @@
41014122 }
41024123
41034124 /**
4104
- * t4_link_l1cfg - apply link configuration to MAC/PHY
4125
+ * t4_link_acaps - compute Link Advertised Port Capabilities
41054126 * @adapter: the adapter
4106
- * @mbox: the Firmware Mailbox to use
41074127 * @port: the Port ID
41084128 * @lc: the Port's Link Configuration
41094129 *
4110
- * Set up a port's MAC and PHY according to a desired link configuration.
4111
- * - If the PHY can auto-negotiate first decide what to advertise, then
4112
- * enable/disable auto-negotiation as desired, and reset.
4113
- * - If the PHY does not auto-negotiate just reset it.
4114
- * - If auto-negotiation is off set the MAC to the proper speed/duplex/FC,
4115
- * otherwise do it later based on the outcome of auto-negotiation.
4130
+ * Synthesize the Advertised Port Capabilities we'll be using based on
4131
+ * the base Advertised Port Capabilities (which have been filtered by
4132
+ * ADVERT_MASK) plus the individual controls for things like Pause
4133
+ * Frames, Forward Error Correction, MDI, etc.
41164134 */
4117
-int t4_link_l1cfg_core(struct adapter *adapter, unsigned int mbox,
4118
- unsigned int port, struct link_config *lc,
4119
- bool sleep_ok, int timeout)
4135
+fw_port_cap32_t t4_link_acaps(struct adapter *adapter, unsigned int port,
4136
+ struct link_config *lc)
41204137 {
4121
- unsigned int fw_caps = adapter->params.fw_caps_support;
4122
- fw_port_cap32_t fw_fc, cc_fec, fw_fec, rcap;
4123
- struct fw_port_cmd cmd;
4138
+ fw_port_cap32_t fw_fc, fw_fec, acaps;
41244139 unsigned int fw_mdi;
4125
- int ret;
4140
+ char cc_fec;
41264141
41274142 fw_mdi = (FW_PORT_CAP32_MDI_V(FW_PORT_CAP32_MDI_AUTO) & lc->pcaps);
4143
+
41284144 /* Convert driver coding of Pause Frame Flow Control settings into the
41294145 * Firmware's API.
41304146 */
....@@ -4133,7 +4149,7 @@
41334149 /* Convert Common Code Forward Error Control settings into the
41344150 * Firmware's API. If the current Requested FEC has "Automatic"
41354151 * (IEEE 802.3) specified, then we use whatever the Firmware
4136
- * sent us as part of it's IEEE 802.3-based interpratation of
4152
+ * sent us as part of its IEEE 802.3-based interpretation of
41374153 * the Transceiver Module EPROM FEC parameters. Otherwise we
41384154 * use whatever is in the current Requested FEC settings.
41394155 */
....@@ -4144,32 +4160,73 @@
41444160 fw_fec = cc_to_fwcap_fec(cc_fec);
41454161
41464162 /* Figure out what our Requested Port Capabilities are going to be.
4163
+ * Note parallel structure in t4_handle_get_port_info() and
4164
+ * init_link_config().
41474165 */
41484166 if (!(lc->pcaps & FW_PORT_CAP32_ANEG)) {
4149
- rcap = lc->acaps | fw_fc | fw_fec;
4167
+ acaps = lc->acaps | fw_fc | fw_fec;
41504168 lc->fc = lc->requested_fc & ~PAUSE_AUTONEG;
41514169 lc->fec = cc_fec;
41524170 } else if (lc->autoneg == AUTONEG_DISABLE) {
4153
- rcap = lc->speed_caps | fw_fc | fw_fec | fw_mdi;
4171
+ acaps = lc->speed_caps | fw_fc | fw_fec | fw_mdi;
41544172 lc->fc = lc->requested_fc & ~PAUSE_AUTONEG;
41554173 lc->fec = cc_fec;
41564174 } else {
4157
- rcap = lc->acaps | fw_fc | fw_fec | fw_mdi;
4175
+ acaps = lc->acaps | fw_fc | fw_fec | fw_mdi;
41584176 }
41594177
4160
- /* Note that older Firmware doesn't have FW_PORT_CAP32_FORCE_PAUSE, so
4178
+ /* Some Requested Port Capabilities are trivially wrong if they exceed
4179
+ * the Physical Port Capabilities. We can check that here and provide
4180
+ * moderately useful feedback in the system log.
4181
+ *
4182
+ * Note that older Firmware doesn't have FW_PORT_CAP32_FORCE_PAUSE, so
41614183 * we need to exclude this from this check in order to maintain
41624184 * compatibility ...
41634185 */
4164
- if ((rcap & ~lc->pcaps) & ~FW_PORT_CAP32_FORCE_PAUSE) {
4165
- dev_err(adapter->pdev_dev,
4166
- "Requested Port Capabilities %#x exceed Physical Port Capabilities %#x\n",
4167
- rcap, lc->pcaps);
4186
+ if ((acaps & ~lc->pcaps) & ~FW_PORT_CAP32_FORCE_PAUSE) {
4187
+ dev_err(adapter->pdev_dev, "Requested Port Capabilities %#x exceed Physical Port Capabilities %#x\n",
4188
+ acaps, lc->pcaps);
41684189 return -EINVAL;
41694190 }
41704191
4171
- /* And send that on to the Firmware ...
4192
+ return acaps;
4193
+}
4194
+
4195
+/**
4196
+ * t4_link_l1cfg_core - apply link configuration to MAC/PHY
4197
+ * @adapter: the adapter
4198
+ * @mbox: the Firmware Mailbox to use
4199
+ * @port: the Port ID
4200
+ * @lc: the Port's Link Configuration
4201
+ * @sleep_ok: if true we may sleep while awaiting command completion
4202
+ * @timeout: time to wait for command to finish before timing out
4203
+ * (negative implies @sleep_ok=false)
4204
+ *
4205
+ * Set up a port's MAC and PHY according to a desired link configuration.
4206
+ * - If the PHY can auto-negotiate first decide what to advertise, then
4207
+ * enable/disable auto-negotiation as desired, and reset.
4208
+ * - If the PHY does not auto-negotiate just reset it.
4209
+ * - If auto-negotiation is off set the MAC to the proper speed/duplex/FC,
4210
+ * otherwise do it later based on the outcome of auto-negotiation.
4211
+ */
4212
+int t4_link_l1cfg_core(struct adapter *adapter, unsigned int mbox,
4213
+ unsigned int port, struct link_config *lc,
4214
+ u8 sleep_ok, int timeout)
4215
+{
4216
+ unsigned int fw_caps = adapter->params.fw_caps_support;
4217
+ struct fw_port_cmd cmd;
4218
+ fw_port_cap32_t rcap;
4219
+ int ret;
4220
+
4221
+ if (!(lc->pcaps & FW_PORT_CAP32_ANEG) &&
4222
+ lc->autoneg == AUTONEG_ENABLE) {
4223
+ return -EINVAL;
4224
+ }
4225
+
4226
+ /* Compute our Requested Port Capabilities and send that on to the
4227
+ * Firmware.
41724228 */
4229
+ rcap = t4_link_acaps(adapter, port, lc);
41734230 memset(&cmd, 0, sizeof(cmd));
41744231 cmd.op_to_portid = cpu_to_be32(FW_CMD_OP_V(FW_PORT_CMD) |
41754232 FW_CMD_REQUEST_F | FW_CMD_EXEC_F |
....@@ -4186,13 +4243,20 @@
41864243
41874244 ret = t4_wr_mbox_meat_timeout(adapter, mbox, &cmd, sizeof(cmd), NULL,
41884245 sleep_ok, timeout);
4246
+
4247
+ /* Unfortunately, even if the Requested Port Capabilities "fit" within
4248
+ * the Physical Port Capabilities, some combinations of features may
4249
+ * still not be legal. For example, 40Gb/s and Reed-Solomon Forward
4250
+ * Error Correction. So if the Firmware rejects the L1 Configure
4251
+ * request, flag that here.
4252
+ */
41894253 if (ret) {
41904254 dev_err(adapter->pdev_dev,
41914255 "Requested Port Capabilities %#x rejected, error %d\n",
41924256 rcap, -ret);
41934257 return ret;
41944258 }
4195
- return ret;
4259
+ return 0;
41964260 }
41974261
41984262 /**
....@@ -4205,6 +4269,7 @@
42054269 */
42064270 int t4_restart_aneg(struct adapter *adap, unsigned int mbox, unsigned int port)
42074271 {
4272
+ unsigned int fw_caps = adap->params.fw_caps_support;
42084273 struct fw_port_cmd c;
42094274
42104275 memset(&c, 0, sizeof(c));
....@@ -4212,9 +4277,14 @@
42124277 FW_CMD_REQUEST_F | FW_CMD_EXEC_F |
42134278 FW_PORT_CMD_PORTID_V(port));
42144279 c.action_to_len16 =
4215
- cpu_to_be32(FW_PORT_CMD_ACTION_V(FW_PORT_ACTION_L1_CFG) |
4280
+ cpu_to_be32(FW_PORT_CMD_ACTION_V(fw_caps == FW_CAPS16
4281
+ ? FW_PORT_ACTION_L1_CFG
4282
+ : FW_PORT_ACTION_L1_CFG32) |
42164283 FW_LEN16(c));
4217
- c.u.l1cfg.rcap = cpu_to_be32(FW_PORT_CAP32_ANEG);
4284
+ if (fw_caps == FW_CAPS16)
4285
+ c.u.l1cfg.rcap = cpu_to_be32(FW_PORT_CAP_ANEG);
4286
+ else
4287
+ c.u.l1cfg32.rcap32 = cpu_to_be32(FW_PORT_CAP32_ANEG);
42184288 return t4_wr_mbox(adap, mbox, &c, sizeof(c), NULL);
42194289 }
42204290
....@@ -4407,7 +4477,7 @@
44074477 */
44084478 static void sge_intr_handler(struct adapter *adapter)
44094479 {
4410
- u64 v;
4480
+ u32 v = 0, perr;
44114481 u32 err;
44124482
44134483 static const struct intr_info sge_intr_info[] = {
....@@ -4442,13 +4512,29 @@
44424512 { 0 }
44434513 };
44444514
4445
- v = (u64)t4_read_reg(adapter, SGE_INT_CAUSE1_A) |
4446
- ((u64)t4_read_reg(adapter, SGE_INT_CAUSE2_A) << 32);
4447
- if (v) {
4448
- dev_alert(adapter->pdev_dev, "SGE parity error (%#llx)\n",
4449
- (unsigned long long)v);
4450
- t4_write_reg(adapter, SGE_INT_CAUSE1_A, v);
4451
- t4_write_reg(adapter, SGE_INT_CAUSE2_A, v >> 32);
4515
+ perr = t4_read_reg(adapter, SGE_INT_CAUSE1_A);
4516
+ if (perr) {
4517
+ v |= perr;
4518
+ dev_alert(adapter->pdev_dev, "SGE Cause1 Parity Error %#x\n",
4519
+ perr);
4520
+ }
4521
+
4522
+ perr = t4_read_reg(adapter, SGE_INT_CAUSE2_A);
4523
+ if (perr) {
4524
+ v |= perr;
4525
+ dev_alert(adapter->pdev_dev, "SGE Cause2 Parity Error %#x\n",
4526
+ perr);
4527
+ }
4528
+
4529
+ if (CHELSIO_CHIP_VERSION(adapter->params.chip) >= CHELSIO_T5) {
4530
+ perr = t4_read_reg(adapter, SGE_INT_CAUSE5_A);
4531
+ /* Parity error (CRC) for err_T_RxCRC is trivial, ignore it */
4532
+ perr &= ~ERR_T_RXCRC_F;
4533
+ if (perr) {
4534
+ v |= perr;
4535
+ dev_alert(adapter->pdev_dev,
4536
+ "SGE Cause5 Parity Error %#x\n", perr);
4537
+ }
44524538 }
44534539
44544540 v |= t4_handle_intr_status(adapter, SGE_INT_CAUSE3_A, sge_intr_info);
....@@ -4670,9 +4756,11 @@
46704756 static struct intr_info t6_le_intr_info[] = {
46714757 { T6_LIPMISS_F, "LE LIP miss", -1, 0 },
46724758 { T6_LIP0_F, "LE 0 LIP error", -1, 0 },
4759
+ { CMDTIDERR_F, "LE cmd tid error", -1, 1 },
46734760 { TCAMINTPERR_F, "LE parity error", -1, 1 },
46744761 { T6_UNKNOWNCMD_F, "LE unknown command", -1, 1 },
46754762 { SSRAMINTPERR_F, "LE request queue parity error", -1, 1 },
4763
+ { HASHTBLMEMCRCERR_F, "LE hash table mem crc error", -1, 0 },
46764764 { 0 }
46774765 };
46784766
....@@ -4937,7 +5025,13 @@
49375025 */
49385026 int t4_slow_intr_handler(struct adapter *adapter)
49395027 {
4940
- u32 cause = t4_read_reg(adapter, PL_INT_CAUSE_A);
5028
+ /* There are rare cases where a PL_INT_CAUSE bit may end up getting
5029
+ * set when the corresponding PL_INT_ENABLE bit isn't set. It's
5030
+ * easiest just to mask that case here.
5031
+ */
5032
+ u32 raw_cause = t4_read_reg(adapter, PL_INT_CAUSE_A);
5033
+ u32 enable = t4_read_reg(adapter, PL_INT_ENABLE_A);
5034
+ u32 cause = raw_cause & enable;
49415035
49425036 if (!(cause & GLBL_INTR_MASK))
49435037 return 0;
....@@ -4989,7 +5083,7 @@
49895083 ulptx_intr_handler(adapter);
49905084
49915085 /* Clear the interrupts just processed for which we are the master. */
4992
- t4_write_reg(adapter, PL_INT_CAUSE_A, cause & GLBL_INTR_MASK);
5086
+ t4_write_reg(adapter, PL_INT_CAUSE_A, raw_cause & GLBL_INTR_MASK);
49935087 (void)t4_read_reg(adapter, PL_INT_CAUSE_A); /* flush */
49945088 return 1;
49955089 }
....@@ -5212,7 +5306,7 @@
52125306
52135307 static unsigned int t4_use_ldst(struct adapter *adap)
52145308 {
5215
- return (adap->flags & FW_OK) && !adap->use_bd;
5309
+ return (adap->flags & CXGB4_FW_OK) && !adap->use_bd;
52165310 }
52175311
52185312 /**
....@@ -5221,7 +5315,7 @@
52215315 * @cmd: TP fw ldst address space type
52225316 * @vals: where the indirect register values are stored/written
52235317 * @nregs: how many indirect registers to read/write
5224
- * @start_idx: index of first indirect register to read/write
5318
+ * @start_index: index of first indirect register to read/write
52255319 * @rw: Read (1) or Write (0)
52265320 * @sleep_ok: if true we may sleep while awaiting command completion
52275321 *
....@@ -5875,7 +5969,6 @@
58755969 {
58765970 int i, ofst = idx * 4;
58775971 u32 data_reg, mask_reg, cfg;
5878
- u32 multitrc = TRCMULTIFILTER_F;
58795972
58805973 if (!enable) {
58815974 t4_write_reg(adap, MPS_TRC_FILTER_MATCH_CTL_A_A + ofst, 0);
....@@ -5895,7 +5988,6 @@
58955988 * maximum packet capture size of 9600 bytes is recommended.
58965989 * Also in this mode, only trace0 can be enabled and running.
58975990 */
5898
- multitrc = 0;
58995991 if (tp->snap_len > 9600 || idx)
59005992 return -EINVAL;
59015993 }
....@@ -6028,7 +6120,7 @@
60286120
60296121 /**
60306122 * compute_mps_bg_map - compute the MPS Buffer Group Map for a Port
6031
- * @adap: the adapter
6123
+ * @adapter: the adapter
60326124 * @pidx: the port index
60336125 *
60346126 * Computes and returns a bitmap indicating which MPS buffer groups are
....@@ -6103,7 +6195,7 @@
61036195 * ( MPSBGMAP[Port 1] << 8 ) |
61046196 * ( MPSBGMAP[Port 0] << 0 ))
61056197 */
6106
- if (adapter->flags & FW_OK) {
6198
+ if (adapter->flags & CXGB4_FW_OK) {
61076199 u32 param, val;
61086200 int ret;
61096201
....@@ -6133,8 +6225,39 @@
61336225 }
61346226
61356227 /**
6228
+ * t4_get_tp_e2c_map - return the E2C channel map associated with a port
6229
+ * @adapter: the adapter
6230
+ * @pidx: the port index
6231
+ */
6232
+static unsigned int t4_get_tp_e2c_map(struct adapter *adapter, int pidx)
6233
+{
6234
+ unsigned int nports;
6235
+ u32 param, val = 0;
6236
+ int ret;
6237
+
6238
+ nports = 1 << NUMPORTS_G(t4_read_reg(adapter, MPS_CMN_CTL_A));
6239
+ if (pidx >= nports) {
6240
+ CH_WARN(adapter, "TP E2C Channel Port Index %d >= Nports %d\n",
6241
+ pidx, nports);
6242
+ return 0;
6243
+ }
6244
+
6245
+ /* FW version >= 1.16.44.0 can determine E2C channel map using
6246
+ * FW_PARAMS_PARAM_DEV_TPCHMAP API.
6247
+ */
6248
+ param = (FW_PARAMS_MNEM_V(FW_PARAMS_MNEM_DEV) |
6249
+ FW_PARAMS_PARAM_X_V(FW_PARAMS_PARAM_DEV_TPCHMAP));
6250
+ ret = t4_query_params_ns(adapter, adapter->mbox, adapter->pf,
6251
+ 0, 1, &param, &val);
6252
+ if (!ret)
6253
+ return (val >> (8 * pidx)) & 0xff;
6254
+
6255
+ return 0;
6256
+}
6257
+
6258
+/**
61366259 * t4_get_tp_ch_map - return TP ingress channels associated with a port
6137
- * @adapter: the adapter
6260
+ * @adap: the adapter
61386261 * @pidx: the port index
61396262 *
61406263 * Returns a bitmap indicating which TP Ingress Channels are associated
....@@ -6471,7 +6594,7 @@
64716594 * @phy_addr: the PHY address
64726595 * @mmd: the PHY MMD to access (0 for clause 22 PHYs)
64736596 * @reg: the register to write
6474
- * @valp: value to write
6597
+ * @val: value to write
64756598 *
64766599 * Issues a FW command through the given mailbox to write a PHY register.
64776600 */
....@@ -6497,7 +6620,7 @@
64976620
64986621 /**
64996622 * t4_sge_decode_idma_state - decode the idma state
6500
- * @adap: the adapter
6623
+ * @adapter: the adapter
65016624 * @state: the state idma is stuck in
65026625 */
65036626 void t4_sge_decode_idma_state(struct adapter *adapter, int state)
....@@ -6664,7 +6787,7 @@
66646787 * t4_sge_ctxt_flush - flush the SGE context cache
66656788 * @adap: the adapter
66666789 * @mbox: mailbox to use for the FW command
6667
- * @ctx_type: Egress or Ingress
6790
+ * @ctxt_type: Egress or Ingress
66686791 *
66696792 * Issues a FW command through the given mailbox to flush the
66706793 * SGE context cache.
....@@ -6686,6 +6809,47 @@
66866809 c.u.idctxt.msg_ctxtflush = cpu_to_be32(FW_LDST_CMD_CTXTFLUSH_F);
66876810
66886811 ret = t4_wr_mbox(adap, mbox, &c, sizeof(c), &c);
6812
+ return ret;
6813
+}
6814
+
6815
+/**
6816
+ * t4_read_sge_dbqtimers - read SGE Doorbell Queue Timer values
6817
+ * @adap: the adapter
6818
+ * @ndbqtimers: size of the provided SGE Doorbell Queue Timer table
6819
+ * @dbqtimers: SGE Doorbell Queue Timer table
6820
+ *
6821
+ * Reads the SGE Doorbell Queue Timer values into the provided table.
6822
+ * Returns 0 on success (Firmware and Hardware support this feature),
6823
+ * an error on failure.
6824
+ */
6825
+int t4_read_sge_dbqtimers(struct adapter *adap, unsigned int ndbqtimers,
6826
+ u16 *dbqtimers)
6827
+{
6828
+ int ret, dbqtimerix;
6829
+
6830
+ ret = 0;
6831
+ dbqtimerix = 0;
6832
+ while (dbqtimerix < ndbqtimers) {
6833
+ int nparams, param;
6834
+ u32 params[7], vals[7];
6835
+
6836
+ nparams = ndbqtimers - dbqtimerix;
6837
+ if (nparams > ARRAY_SIZE(params))
6838
+ nparams = ARRAY_SIZE(params);
6839
+
6840
+ for (param = 0; param < nparams; param++)
6841
+ params[param] =
6842
+ (FW_PARAMS_MNEM_V(FW_PARAMS_MNEM_DEV) |
6843
+ FW_PARAMS_PARAM_X_V(FW_PARAMS_PARAM_DEV_DBQ_TIMER) |
6844
+ FW_PARAMS_PARAM_Y_V(dbqtimerix + param));
6845
+ ret = t4_query_params(adap, adap->mbox, adap->pf, 0,
6846
+ nparams, params, vals);
6847
+ if (ret)
6848
+ break;
6849
+
6850
+ for (param = 0; param < nparams; param++)
6851
+ dbqtimers[dbqtimerix++] = vals[param];
6852
+ }
66896853 return ret;
66906854 }
66916855
....@@ -6777,8 +6941,8 @@
67776941 waiting -= 50;
67786942
67796943 /*
6780
- * If neither Error nor Initialialized are indicated
6781
- * by the firmware keep waiting till we exaust our
6944
+ * If neither Error nor Initialized are indicated
6945
+ * by the firmware keep waiting till we exhaust our
67826946 * timeout ... and then retry if we haven't exhausted
67836947 * our retries ...
67846948 */
....@@ -6933,6 +7097,7 @@
69337097 /**
69347098 * t4_fw_restart - restart the firmware by taking the uP out of RESET
69357099 * @adap: the adapter
7100
+ * @mbox: mailbox to use for the FW command
69367101 * @reset: if we want to do a RESET to restart things
69377102 *
69387103 * Restart firmware previously halted by t4_fw_halt(). On successful
....@@ -7023,10 +7188,10 @@
70237188 if (!t4_fw_matches_chip(adap, fw_hdr))
70247189 return -EINVAL;
70257190
7026
- /* Disable FW_OK flag so that mbox commands with FW_OK flag set
7027
- * wont be sent when we are flashing FW.
7191
+ /* Disable CXGB4_FW_OK flag so that mbox commands with CXGB4_FW_OK flag
7192
+ * set wont be sent when we are flashing FW.
70287193 */
7029
- adap->flags &= ~FW_OK;
7194
+ adap->flags &= ~CXGB4_FW_OK;
70307195
70317196 ret = t4_fw_halt(adap, mbox, force);
70327197 if (ret < 0 && !force)
....@@ -7065,7 +7230,7 @@
70657230 */
70667231 (void)t4_init_devlog_params(adap);
70677232 out:
7068
- adap->flags |= FW_OK;
7233
+ adap->flags |= CXGB4_FW_OK;
70697234 return ret;
70707235 }
70717236
....@@ -7090,7 +7255,7 @@
70907255 * separately. The actual Ingress Packet Data alignment boundary
70917256 * within Packed Buffer Mode is the maximum of these two
70927257 * specifications. (Note that it makes no real practical sense to
7093
- * have the Pading Boudary be larger than the Packing Boundary but you
7258
+ * have the Padding Boundary be larger than the Packing Boundary but you
70947259 * could set the chip up that way and, in fact, legacy T4 code would
70957260 * end doing this because it would initialize the Padding Boundary and
70967261 * leave the Packing Boundary initialized to 0 (16 bytes).)
....@@ -7161,7 +7326,6 @@
71617326 } else {
71627327 unsigned int pack_align;
71637328 unsigned int ingpad, ingpack;
7164
- unsigned int pcie_cap;
71657329
71667330 /* T5 introduced the separation of the Free List Padding and
71677331 * Packing Boundaries. Thus, we can select a smaller Padding
....@@ -7186,8 +7350,7 @@
71867350 * multiple of the Maximum Payload Size.
71877351 */
71887352 pack_align = fl_align;
7189
- pcie_cap = pci_find_capability(adap->pdev, PCI_CAP_ID_EXP);
7190
- if (pcie_cap) {
7353
+ if (pci_is_pcie(adap->pdev)) {
71917354 unsigned int mps, mps_log;
71927355 u16 devctl;
71937356
....@@ -7195,9 +7358,8 @@
71957358 * [bits 7:5] encodes sizes as powers of 2 starting at
71967359 * 128 bytes.
71977360 */
7198
- pci_read_config_word(adap->pdev,
7199
- pcie_cap + PCI_EXP_DEVCTL,
7200
- &devctl);
7361
+ pcie_capability_read_word(adap->pdev, PCI_EXP_DEVCTL,
7362
+ &devctl);
72017363 mps_log = ((devctl & PCI_EXP_DEVCTL_PAYLOAD) >> 5) + 7;
72027364 mps = 1 << mps_log;
72037365 if (mps > pack_align)
....@@ -7474,6 +7636,8 @@
74747636 * @nmac: number of MAC addresses needed (1 to 5)
74757637 * @mac: the MAC addresses of the VI
74767638 * @rss_size: size of RSS table slice associated with this VI
7639
+ * @vivld: the destination to store the VI Valid value.
7640
+ * @vin: the destination to store the VIN value.
74777641 *
74787642 * Allocates a virtual interface for the given physical port. If @mac is
74797643 * not %NULL it contains the MAC addresses of the VI as assigned by FW.
....@@ -7483,7 +7647,7 @@
74837647 */
74847648 int t4_alloc_vi(struct adapter *adap, unsigned int mbox, unsigned int port,
74857649 unsigned int pf, unsigned int vf, unsigned int nmac, u8 *mac,
7486
- unsigned int *rss_size)
7650
+ unsigned int *rss_size, u8 *vivld, u8 *vin)
74877651 {
74887652 int ret;
74897653 struct fw_vi_cmd c;
....@@ -7505,19 +7669,26 @@
75057669 switch (nmac) {
75067670 case 5:
75077671 memcpy(mac + 24, c.nmac3, sizeof(c.nmac3));
7508
- /* Fall through */
7672
+ fallthrough;
75097673 case 4:
75107674 memcpy(mac + 18, c.nmac2, sizeof(c.nmac2));
7511
- /* Fall through */
7675
+ fallthrough;
75127676 case 3:
75137677 memcpy(mac + 12, c.nmac1, sizeof(c.nmac1));
7514
- /* Fall through */
7678
+ fallthrough;
75157679 case 2:
75167680 memcpy(mac + 6, c.nmac0, sizeof(c.nmac0));
75177681 }
75187682 }
75197683 if (rss_size)
75207684 *rss_size = FW_VI_CMD_RSSSIZE_G(be16_to_cpu(c.rsssize_pkd));
7685
+
7686
+ if (vivld)
7687
+ *vivld = FW_VI_CMD_VFVLD_G(be32_to_cpu(c.alloc_to_len16));
7688
+
7689
+ if (vin)
7690
+ *vin = FW_VI_CMD_VIN_G(be32_to_cpu(c.alloc_to_len16));
7691
+
75217692 return FW_VI_CMD_VIID_G(be16_to_cpu(c.type_viid));
75227693 }
75237694
....@@ -7553,6 +7724,7 @@
75537724 * @adap: the adapter
75547725 * @mbox: mailbox to use for the FW command
75557726 * @viid: the VI id
7727
+ * @viid_mirror: the mirror VI id
75567728 * @mtu: the new MTU or -1
75577729 * @promisc: 1 to enable promiscuous mode, 0 to disable it, -1 no change
75587730 * @all_multi: 1 to enable all-multi mode, 0 to disable it, -1 no change
....@@ -7563,10 +7735,11 @@
75637735 * Sets Rx properties of a virtual interface.
75647736 */
75657737 int t4_set_rxmode(struct adapter *adap, unsigned int mbox, unsigned int viid,
7566
- int mtu, int promisc, int all_multi, int bcast, int vlanex,
7567
- bool sleep_ok)
7738
+ unsigned int viid_mirror, int mtu, int promisc, int all_multi,
7739
+ int bcast, int vlanex, bool sleep_ok)
75687740 {
7569
- struct fw_vi_rxmode_cmd c;
7741
+ struct fw_vi_rxmode_cmd c, c_mirror;
7742
+ int ret;
75707743
75717744 /* convert to FW values */
75727745 if (mtu < 0)
....@@ -7591,7 +7764,24 @@
75917764 FW_VI_RXMODE_CMD_ALLMULTIEN_V(all_multi) |
75927765 FW_VI_RXMODE_CMD_BROADCASTEN_V(bcast) |
75937766 FW_VI_RXMODE_CMD_VLANEXEN_V(vlanex));
7594
- return t4_wr_mbox_meat(adap, mbox, &c, sizeof(c), NULL, sleep_ok);
7767
+
7768
+ if (viid_mirror) {
7769
+ memcpy(&c_mirror, &c, sizeof(c_mirror));
7770
+ c_mirror.op_to_viid =
7771
+ cpu_to_be32(FW_CMD_OP_V(FW_VI_RXMODE_CMD) |
7772
+ FW_CMD_REQUEST_F | FW_CMD_WRITE_F |
7773
+ FW_VI_RXMODE_CMD_VIID_V(viid_mirror));
7774
+ }
7775
+
7776
+ ret = t4_wr_mbox_meat(adap, mbox, &c, sizeof(c), NULL, sleep_ok);
7777
+ if (ret)
7778
+ return ret;
7779
+
7780
+ if (viid_mirror)
7781
+ ret = t4_wr_mbox_meat(adap, mbox, &c_mirror, sizeof(c_mirror),
7782
+ NULL, sleep_ok);
7783
+
7784
+ return ret;
75957785 }
75967786
75977787 /**
....@@ -7685,7 +7875,7 @@
76857875 * t4_alloc_encap_mac_filt - Adds a mac entry in mps tcam with VNI support
76867876 * @adap: the adapter
76877877 * @viid: the VI id
7688
- * @mac: the MAC address
7878
+ * @addr: the MAC address
76897879 * @mask: the mask
76907880 * @vni: the VNI id for the tunnel protocol
76917881 * @vni_mask: mask for the VNI id
....@@ -7734,11 +7924,11 @@
77347924 * t4_alloc_raw_mac_filt - Adds a mac entry in mps tcam
77357925 * @adap: the adapter
77367926 * @viid: the VI id
7737
- * @mac: the MAC address
7927
+ * @addr: the MAC address
77387928 * @mask: the mask
77397929 * @idx: index at which to add this entry
7740
- * @port_id: the port index
77417930 * @lookup_type: MAC address for inner (1) or outer (0) header
7931
+ * @port_id: the port index
77427932 * @sleep_ok: call is allowed to sleep
77437933 *
77447934 * Adds the mac entry at the specified index using raw mac interface.
....@@ -7963,7 +8153,7 @@
79638153 * @idx: index of existing filter for old value of MAC address, or -1
79648154 * @addr: the new MAC address value
79658155 * @persist: whether a new MAC allocation should be persistent
7966
- * @add_smt: if true also add the address to the HW SMT
8156
+ * @smt_idx: the destination to store the new SMT index.
79678157 *
79688158 * Modifies an exact-match filter and sets it to the new MAC address.
79698159 * Note that in general it is not possible to modify the value of a given
....@@ -7975,7 +8165,7 @@
79758165 * MAC value.
79768166 */
79778167 int t4_change_mac(struct adapter *adap, unsigned int mbox, unsigned int viid,
7978
- int idx, const u8 *addr, bool persist, bool add_smt)
8168
+ int idx, const u8 *addr, bool persist, u8 *smt_idx)
79798169 {
79808170 int ret, mode;
79818171 struct fw_vi_mac_cmd c;
....@@ -7984,7 +8174,7 @@
79848174
79858175 if (idx < 0) /* new allocation */
79868176 idx = persist ? FW_VI_MAC_ADD_PERSIST_MAC : FW_VI_MAC_ADD_MAC;
7987
- mode = add_smt ? FW_VI_MAC_SMT_AND_MPSTCAM : FW_VI_MAC_MPS_TCAM_ENTRY;
8177
+ mode = smt_idx ? FW_VI_MAC_SMT_AND_MPSTCAM : FW_VI_MAC_MPS_TCAM_ENTRY;
79888178
79898179 memset(&c, 0, sizeof(c));
79908180 c.op_to_viid = cpu_to_be32(FW_CMD_OP_V(FW_VI_MAC_CMD) |
....@@ -8001,6 +8191,23 @@
80018191 ret = FW_VI_MAC_CMD_IDX_G(be16_to_cpu(p->valid_to_idx));
80028192 if (ret >= max_mac_addr)
80038193 ret = -ENOMEM;
8194
+ if (smt_idx) {
8195
+ if (adap->params.viid_smt_extn_support) {
8196
+ *smt_idx = FW_VI_MAC_CMD_SMTID_G
8197
+ (be32_to_cpu(c.op_to_viid));
8198
+ } else {
8199
+ /* In T4/T5, SMT contains 256 SMAC entries
8200
+ * organized in 128 rows of 2 entries each.
8201
+ * In T6, SMT contains 256 SMAC entries in
8202
+ * 256 rows.
8203
+ */
8204
+ if (CHELSIO_CHIP_VERSION(adap->params.chip) <=
8205
+ CHELSIO_T5)
8206
+ *smt_idx = (viid & FW_VIID_VIN_M) << 1;
8207
+ else
8208
+ *smt_idx = (viid & FW_VIID_VIN_M);
8209
+ }
8210
+ }
80048211 }
80058212 return ret;
80068213 }
....@@ -8268,7 +8475,6 @@
82688475
82698476 /**
82708477 * t4_link_down_rc_str - return a string for a Link Down Reason Code
8271
- * @adap: the adapter
82728478 * @link_down_rc: Link Down Reason Code
82738479 *
82748480 * Returns a string representation of the Link Down Reason Code.
....@@ -8292,9 +8498,7 @@
82928498 return reason[link_down_rc];
82938499 }
82948500
8295
-/**
8296
- * Return the highest speed set in the port capabilities, in Mb/s.
8297
- */
8501
+/* Return the highest speed set in the port capabilities, in Mb/s. */
82988502 static unsigned int fwcap_to_speed(fw_port_cap32_t caps)
82998503 {
83008504 #define TEST_SPEED_RETURN(__caps_speed, __speed) \
....@@ -8394,17 +8598,17 @@
83948598 void t4_handle_get_port_info(struct port_info *pi, const __be64 *rpl)
83958599 {
83968600 const struct fw_port_cmd *cmd = (const void *)rpl;
8397
- int action = FW_PORT_CMD_ACTION_G(be32_to_cpu(cmd->action_to_len16));
8398
- struct adapter *adapter = pi->adapter;
8399
- struct link_config *lc = &pi->link_cfg;
8400
- int link_ok, linkdnrc;
8401
- enum fw_port_type port_type;
8402
- enum fw_port_module_type mod_type;
8403
- unsigned int speed, fc, fec;
84048601 fw_port_cap32_t pcaps, acaps, lpacaps, linkattr;
8602
+ struct link_config *lc = &pi->link_cfg;
8603
+ struct adapter *adapter = pi->adapter;
8604
+ unsigned int speed, fc, fec, adv_fc;
8605
+ enum fw_port_module_type mod_type;
8606
+ int action, link_ok, linkdnrc;
8607
+ enum fw_port_type port_type;
84058608
84068609 /* Extract the various fields from the Port Information message.
84078610 */
8611
+ action = FW_PORT_CMD_ACTION_G(be32_to_cpu(cmd->action_to_len16));
84088612 switch (action) {
84098613 case FW_PORT_ACTION_GET_PORT_INFO: {
84108614 u32 lstatus = be32_to_cpu(cmd->u.info.lstatus_to_modtype);
....@@ -8442,9 +8646,14 @@
84428646 }
84438647
84448648 fec = fwcap_to_cc_fec(acaps);
8649
+ adv_fc = fwcap_to_cc_pause(acaps);
84458650 fc = fwcap_to_cc_pause(linkattr);
84468651 speed = fwcap_to_speed(linkattr);
84478652
8653
+ /* Reset state for communicating new Transceiver Module status and
8654
+ * whether the OS-dependent layer wants us to redo the current
8655
+ * "sticky" L1 Configure Link Parameters.
8656
+ */
84488657 lc->new_module = false;
84498658 lc->redo_l1cfg = false;
84508659
....@@ -8481,27 +8690,43 @@
84818690 */
84828691 pi->port_type = port_type;
84838692
8693
+ /* Record new Module Type information.
8694
+ */
84848695 pi->mod_type = mod_type;
84858696
8697
+ /* Let the OS-dependent layer know if we have a new
8698
+ * Transceiver Module inserted.
8699
+ */
84868700 lc->new_module = t4_is_inserted_mod_type(mod_type);
8701
+
84878702 t4_os_portmod_changed(adapter, pi->port_id);
84888703 }
84898704
84908705 if (link_ok != lc->link_ok || speed != lc->speed ||
8491
- fc != lc->fc || fec != lc->fec) { /* something changed */
8706
+ fc != lc->fc || adv_fc != lc->advertised_fc ||
8707
+ fec != lc->fec) {
8708
+ /* something changed */
84928709 if (!link_ok && lc->link_ok) {
84938710 lc->link_down_rc = linkdnrc;
8494
- dev_warn(adapter->pdev_dev, "Port %d link down, reason: %s\n",
8495
- pi->tx_chan, t4_link_down_rc_str(linkdnrc));
8711
+ dev_warn_ratelimited(adapter->pdev_dev,
8712
+ "Port %d link down, reason: %s\n",
8713
+ pi->tx_chan,
8714
+ t4_link_down_rc_str(linkdnrc));
84968715 }
84978716 lc->link_ok = link_ok;
84988717 lc->speed = speed;
8718
+ lc->advertised_fc = adv_fc;
84998719 lc->fc = fc;
85008720 lc->fec = fec;
85018721
85028722 lc->lpacaps = lpacaps;
85038723 lc->acaps = acaps & ADVERT_MASK;
85048724
8725
+ /* If we're not physically capable of Auto-Negotiation, note
8726
+ * this as Auto-Negotiation disabled. Otherwise, we track
8727
+ * what Auto-Negotiation settings we have. Note parallel
8728
+ * structure in t4_link_l1cfg_core() and init_link_config().
8729
+ */
85058730 if (!(lc->acaps & FW_PORT_CAP32_ANEG)) {
85068731 lc->autoneg = AUTONEG_DISABLE;
85078732 } else if (lc->acaps & FW_PORT_CAP32_ANEG) {
....@@ -8519,6 +8744,10 @@
85198744 t4_os_link_changed(adapter, pi->port_id, link_ok);
85208745 }
85218746
8747
+ /* If we have a new Transceiver Module and the OS-dependent code has
8748
+ * told us that it wants us to redo whatever "sticky" L1 Configuration
8749
+ * Link Parameters are set, do that now.
8750
+ */
85228751 if (lc->new_module && lc->redo_l1cfg) {
85238752 struct link_config old_lc;
85248753 int ret;
....@@ -8587,8 +8816,8 @@
85878816 unsigned int *speedp, unsigned int *mtup)
85888817 {
85898818 unsigned int fw_caps = pi->adapter->params.fw_caps_support;
8819
+ unsigned int action, link_ok, mtu;
85908820 struct fw_port_cmd port_cmd;
8591
- unsigned int action, link_ok, speed, mtu;
85928821 fw_port_cap32_t linkattr;
85938822 int ret;
85948823
....@@ -8622,11 +8851,13 @@
86228851 mtu = FW_PORT_CMD_MTU32_G(
86238852 be32_to_cpu(port_cmd.u.info32.auxlinfo32_mtu32));
86248853 }
8625
- speed = fwcap_to_speed(linkattr);
86268854
8627
- *link_okp = link_ok;
8628
- *speedp = fwcap_to_speed(linkattr);
8629
- *mtup = mtu;
8855
+ if (link_okp)
8856
+ *link_okp = link_ok;
8857
+ if (speedp)
8858
+ *speedp = fwcap_to_speed(linkattr);
8859
+ if (mtup)
8860
+ *mtup = mtu;
86308861
86318862 return 0;
86328863 }
....@@ -8784,10 +9015,10 @@
87849015 goto found;
87859016 }
87869017
8787
- /* Decode Flash part size. The code below looks repetative with
9018
+ /* Decode Flash part size. The code below looks repetitive with
87889019 * common encodings, but that's not guaranteed in the JEDEC
8789
- * specification for the Read JADEC ID command. The only thing that
8790
- * we're guaranteed by the JADEC specification is where the
9020
+ * specification for the Read JEDEC ID command. The only thing that
9021
+ * we're guaranteed by the JEDEC specification is where the
87919022 * Manufacturer ID is in the returned result. After that each
87929023 * Manufacturer ~could~ encode things completely differently.
87939024 * Note, all Flash parts must have 64KB sectors.
....@@ -8903,7 +9134,6 @@
89039134 /**
89049135 * t4_prep_adapter - prepare SW and HW for operation
89059136 * @adapter: the adapter
8906
- * @reset: if true perform a HW reset
89079137 *
89089138 * Initialize adapter SW state for the various HW modules, set initial
89099139 * values for some adapter tunables, take PHYs out of reset, and
....@@ -9128,7 +9358,7 @@
91289358 struct fw_devlog_cmd devlog_cmd;
91299359 int ret;
91309360
9131
- /* If we're dealing with newer firmware, the Device Log Paramerters
9361
+ /* If we're dealing with newer firmware, the Device Log Parameters
91329362 * are stored in a designated register which allows us to access the
91339363 * Device Log even if we can't talk to the firmware.
91349364 */
....@@ -9207,8 +9437,9 @@
92079437 */
92089438 int t4_init_tp_params(struct adapter *adap, bool sleep_ok)
92099439 {
9210
- int chan;
9211
- u32 v;
9440
+ u32 param, val, v;
9441
+ int chan, ret;
9442
+
92129443
92139444 v = t4_read_reg(adap, TP_TIMER_RESOLUTION_A);
92149445 adap->params.tp.tre = TIMERRESOLUTION_G(v);
....@@ -9218,11 +9449,47 @@
92189449 for (chan = 0; chan < NCHAN; chan++)
92199450 adap->params.tp.tx_modq[chan] = chan;
92209451
9221
- /* Cache the adapter's Compressed Filter Mode and global Incress
9452
+ /* Cache the adapter's Compressed Filter Mode/Mask and global Ingress
92229453 * Configuration.
92239454 */
9224
- t4_tp_pio_read(adap, &adap->params.tp.vlan_pri_map, 1,
9225
- TP_VLAN_PRI_MAP_A, sleep_ok);
9455
+ param = (FW_PARAMS_MNEM_V(FW_PARAMS_MNEM_DEV) |
9456
+ FW_PARAMS_PARAM_X_V(FW_PARAMS_PARAM_DEV_FILTER) |
9457
+ FW_PARAMS_PARAM_Y_V(FW_PARAM_DEV_FILTER_MODE_MASK));
9458
+
9459
+ /* Read current value */
9460
+ ret = t4_query_params(adap, adap->mbox, adap->pf, 0, 1,
9461
+ &param, &val);
9462
+ if (ret == 0) {
9463
+ dev_info(adap->pdev_dev,
9464
+ "Current filter mode/mask 0x%x:0x%x\n",
9465
+ FW_PARAMS_PARAM_FILTER_MODE_G(val),
9466
+ FW_PARAMS_PARAM_FILTER_MASK_G(val));
9467
+ adap->params.tp.vlan_pri_map =
9468
+ FW_PARAMS_PARAM_FILTER_MODE_G(val);
9469
+ adap->params.tp.filter_mask =
9470
+ FW_PARAMS_PARAM_FILTER_MASK_G(val);
9471
+ } else {
9472
+ dev_info(adap->pdev_dev,
9473
+ "Failed to read filter mode/mask via fw api, using indirect-reg-read\n");
9474
+
9475
+ /* Incase of older-fw (which doesn't expose the api
9476
+ * FW_PARAM_DEV_FILTER_MODE_MASK) and newer-driver (which uses
9477
+ * the fw api) combination, fall-back to older method of reading
9478
+ * the filter mode from indirect-register
9479
+ */
9480
+ t4_tp_pio_read(adap, &adap->params.tp.vlan_pri_map, 1,
9481
+ TP_VLAN_PRI_MAP_A, sleep_ok);
9482
+
9483
+ /* With the older-fw and newer-driver combination we might run
9484
+ * into an issue when user wants to use hash filter region but
9485
+ * the filter_mask is zero, in this case filter_mask validation
9486
+ * is tough. To avoid that we set the filter_mask same as filter
9487
+ * mode, which will behave exactly as the older way of ignoring
9488
+ * the filter mask validation.
9489
+ */
9490
+ adap->params.tp.filter_mask = adap->params.tp.vlan_pri_map;
9491
+ }
9492
+
92269493 t4_tp_pio_read(adap, &adap->params.tp.ingress_config, 1,
92279494 TP_INGRESS_CONFIG_A, sleep_ok);
92289495
....@@ -9369,6 +9636,7 @@
93699636 enum fw_port_type port_type;
93709637 int mdio_addr;
93719638 fw_port_cap32_t pcaps, acaps;
9639
+ u8 vivld = 0, vin = 0;
93729640 int ret;
93739641
93749642 /* If we haven't yet determined whether we're talking to Firmware
....@@ -9423,7 +9691,8 @@
94239691 acaps = be32_to_cpu(cmd.u.info32.acaps32);
94249692 }
94259693
9426
- ret = t4_alloc_vi(pi->adapter, mbox, port, pf, vf, 1, mac, &rss_size);
9694
+ ret = t4_alloc_vi(pi->adapter, mbox, port, pf, vf, 1, mac, &rss_size,
9695
+ &vivld, &vin);
94279696 if (ret < 0)
94289697 return ret;
94299698
....@@ -9431,6 +9700,19 @@
94319700 pi->tx_chan = port;
94329701 pi->lport = port;
94339702 pi->rss_size = rss_size;
9703
+ pi->rx_cchan = t4_get_tp_e2c_map(pi->adapter, port);
9704
+
9705
+ /* If fw supports returning the VIN as part of FW_VI_CMD,
9706
+ * save the returned values.
9707
+ */
9708
+ if (adapter->params.viid_smt_extn_support) {
9709
+ pi->vivld = vivld;
9710
+ pi->vin = vin;
9711
+ } else {
9712
+ /* Retrieve the values from VIID */
9713
+ pi->vivld = FW_VIID_VIVLD_G(pi->viid);
9714
+ pi->vin = FW_VIID_VIN_G(pi->viid);
9715
+ }
94349716
94359717 pi->port_type = port_type;
94369718 pi->mdio_addr = mdio_addr;
....@@ -9458,6 +9740,22 @@
94589740 memcpy(adap->port[i]->dev_addr, addr, ETH_ALEN);
94599741 j++;
94609742 }
9743
+ return 0;
9744
+}
9745
+
9746
+int t4_init_port_mirror(struct port_info *pi, u8 mbox, u8 port, u8 pf, u8 vf,
9747
+ u16 *mirror_viid)
9748
+{
9749
+ int ret;
9750
+
9751
+ ret = t4_alloc_vi(pi->adapter, mbox, port, pf, vf, 1, NULL, NULL,
9752
+ NULL, NULL);
9753
+ if (ret < 0)
9754
+ return ret;
9755
+
9756
+ if (mirror_viid)
9757
+ *mirror_viid = ret;
9758
+
94619759 return 0;
94629760 }
94639761
....@@ -9927,7 +10225,7 @@
992710225 n = size - i;
992810226 else
992910227 n = SF_PAGE_SIZE;
9930
- ret = t4_write_flash(adap, addr, n, cfg_data);
10228
+ ret = t4_write_flash(adap, addr, n, cfg_data, true);
993110229 if (ret)
993210230 goto out;
993310231
....@@ -10102,9 +10400,10 @@
1010210400 return ret;
1010310401 }
1010410402
10105
-int t4_sched_params(struct adapter *adapter, int type, int level, int mode,
10106
- int rateunit, int ratemode, int channel, int class,
10107
- int minrate, int maxrate, int weight, int pktsize)
10403
+int t4_sched_params(struct adapter *adapter, u8 type, u8 level, u8 mode,
10404
+ u8 rateunit, u8 ratemode, u8 channel, u8 class,
10405
+ u32 minrate, u32 maxrate, u16 weight, u16 pktsize,
10406
+ u16 burstsize)
1010810407 {
1010910408 struct fw_sched_cmd cmd;
1011010409
....@@ -10126,6 +10425,7 @@
1012610425 cmd.u.params.max = cpu_to_be32(maxrate);
1012710426 cmd.u.params.weight = cpu_to_be16(weight);
1012810427 cmd.u.params.pktsize = cpu_to_be16(pktsize);
10428
+ cmd.u.params.burstsize = cpu_to_be16(burstsize);
1012910429
1013010430 return t4_wr_mbox_meat(adapter, adapter->mbox, &cmd, sizeof(cmd),
1013110431 NULL, 1);
....@@ -10134,6 +10434,7 @@
1013410434 /**
1013510435 * t4_i2c_rd - read I2C data from adapter
1013610436 * @adap: the adapter
10437
+ * @mbox: mailbox to use for the FW command
1013710438 * @port: Port number if per-port device; <0 if not
1013810439 * @devid: per-port device ID or absolute device ID
1013910440 * @offset: byte offset into device I2C space
....@@ -10189,7 +10490,7 @@
1018910490
1019010491 /**
1019110492 * t4_set_vlan_acl - Set a VLAN id for the specified VF
10192
- * @adapter: the adapter
10493
+ * @adap: the adapter
1019310494 * @mbox: mailbox to use for the FW command
1019410495 * @vf: one of the VFs instantiated by the specified PF
1019510496 * @vlan: The vlanid to be set
....@@ -10210,7 +10511,9 @@
1021010511 FW_ACL_VLAN_CMD_VFN_V(vf));
1021110512 vlan_cmd.en_to_len16 = cpu_to_be32(enable | FW_LEN16(vlan_cmd));
1021210513 /* Drop all packets that donot match vlan id */
10213
- vlan_cmd.dropnovlan_fm = FW_ACL_VLAN_CMD_FM_F;
10514
+ vlan_cmd.dropnovlan_fm = (enable
10515
+ ? (FW_ACL_VLAN_CMD_DROPNOVLAN_F |
10516
+ FW_ACL_VLAN_CMD_FM_F) : 0);
1021410517 if (enable != 0) {
1021510518 vlan_cmd.nvlan = 1;
1021610519 vlan_cmd.vlanid[0] = cpu_to_be16(vlan);
....@@ -10218,3 +10521,282 @@
1021810521
1021910522 return t4_wr_mbox(adap, adap->mbox, &vlan_cmd, sizeof(vlan_cmd), NULL);
1022010523 }
10524
+
10525
+/**
10526
+ * modify_device_id - Modifies the device ID of the Boot BIOS image
10527
+ * @device_id: the device ID to write.
10528
+ * @boot_data: the boot image to modify.
10529
+ *
10530
+ * Write the supplied device ID to the boot BIOS image.
10531
+ */
10532
+static void modify_device_id(int device_id, u8 *boot_data)
10533
+{
10534
+ struct cxgb4_pcir_data *pcir_header;
10535
+ struct legacy_pci_rom_hdr *header;
10536
+ u8 *cur_header = boot_data;
10537
+ u16 pcir_offset;
10538
+
10539
+ /* Loop through all chained images and change the device ID's */
10540
+ do {
10541
+ header = (struct legacy_pci_rom_hdr *)cur_header;
10542
+ pcir_offset = le16_to_cpu(header->pcir_offset);
10543
+ pcir_header = (struct cxgb4_pcir_data *)(cur_header +
10544
+ pcir_offset);
10545
+
10546
+ /**
10547
+ * Only modify the Device ID if code type is Legacy or HP.
10548
+ * 0x00: Okay to modify
10549
+ * 0x01: FCODE. Do not modify
10550
+ * 0x03: Okay to modify
10551
+ * 0x04-0xFF: Do not modify
10552
+ */
10553
+ if (pcir_header->code_type == CXGB4_HDR_CODE1) {
10554
+ u8 csum = 0;
10555
+ int i;
10556
+
10557
+ /**
10558
+ * Modify Device ID to match current adatper
10559
+ */
10560
+ pcir_header->device_id = cpu_to_le16(device_id);
10561
+
10562
+ /**
10563
+ * Set checksum temporarily to 0.
10564
+ * We will recalculate it later.
10565
+ */
10566
+ header->cksum = 0x0;
10567
+
10568
+ /**
10569
+ * Calculate and update checksum
10570
+ */
10571
+ for (i = 0; i < (header->size512 * 512); i++)
10572
+ csum += cur_header[i];
10573
+
10574
+ /**
10575
+ * Invert summed value to create the checksum
10576
+ * Writing new checksum value directly to the boot data
10577
+ */
10578
+ cur_header[7] = -csum;
10579
+
10580
+ } else if (pcir_header->code_type == CXGB4_HDR_CODE2) {
10581
+ /**
10582
+ * Modify Device ID to match current adatper
10583
+ */
10584
+ pcir_header->device_id = cpu_to_le16(device_id);
10585
+ }
10586
+
10587
+ /**
10588
+ * Move header pointer up to the next image in the ROM.
10589
+ */
10590
+ cur_header += header->size512 * 512;
10591
+ } while (!(pcir_header->indicator & CXGB4_HDR_INDI));
10592
+}
10593
+
10594
+/**
10595
+ * t4_load_boot - download boot flash
10596
+ * @adap: the adapter
10597
+ * @boot_data: the boot image to write
10598
+ * @boot_addr: offset in flash to write boot_data
10599
+ * @size: image size
10600
+ *
10601
+ * Write the supplied boot image to the card's serial flash.
10602
+ * The boot image has the following sections: a 28-byte header and the
10603
+ * boot image.
10604
+ */
10605
+int t4_load_boot(struct adapter *adap, u8 *boot_data,
10606
+ unsigned int boot_addr, unsigned int size)
10607
+{
10608
+ unsigned int sf_sec_size = adap->params.sf_size / adap->params.sf_nsec;
10609
+ unsigned int boot_sector = (boot_addr * 1024);
10610
+ struct cxgb4_pci_exp_rom_header *header;
10611
+ struct cxgb4_pcir_data *pcir_header;
10612
+ int pcir_offset;
10613
+ unsigned int i;
10614
+ u16 device_id;
10615
+ int ret, addr;
10616
+
10617
+ /**
10618
+ * Make sure the boot image does not encroach on the firmware region
10619
+ */
10620
+ if ((boot_sector + size) >> 16 > FLASH_FW_START_SEC) {
10621
+ dev_err(adap->pdev_dev, "boot image encroaching on firmware region\n");
10622
+ return -EFBIG;
10623
+ }
10624
+
10625
+ /* Get boot header */
10626
+ header = (struct cxgb4_pci_exp_rom_header *)boot_data;
10627
+ pcir_offset = le16_to_cpu(header->pcir_offset);
10628
+ /* PCIR Data Structure */
10629
+ pcir_header = (struct cxgb4_pcir_data *)&boot_data[pcir_offset];
10630
+
10631
+ /**
10632
+ * Perform some primitive sanity testing to avoid accidentally
10633
+ * writing garbage over the boot sectors. We ought to check for
10634
+ * more but it's not worth it for now ...
10635
+ */
10636
+ if (size < BOOT_MIN_SIZE || size > BOOT_MAX_SIZE) {
10637
+ dev_err(adap->pdev_dev, "boot image too small/large\n");
10638
+ return -EFBIG;
10639
+ }
10640
+
10641
+ if (le16_to_cpu(header->signature) != BOOT_SIGNATURE) {
10642
+ dev_err(adap->pdev_dev, "Boot image missing signature\n");
10643
+ return -EINVAL;
10644
+ }
10645
+
10646
+ /* Check PCI header signature */
10647
+ if (le32_to_cpu(pcir_header->signature) != PCIR_SIGNATURE) {
10648
+ dev_err(adap->pdev_dev, "PCI header missing signature\n");
10649
+ return -EINVAL;
10650
+ }
10651
+
10652
+ /* Check Vendor ID matches Chelsio ID*/
10653
+ if (le16_to_cpu(pcir_header->vendor_id) != PCI_VENDOR_ID_CHELSIO) {
10654
+ dev_err(adap->pdev_dev, "Vendor ID missing signature\n");
10655
+ return -EINVAL;
10656
+ }
10657
+
10658
+ /**
10659
+ * The boot sector is comprised of the Expansion-ROM boot, iSCSI boot,
10660
+ * and Boot configuration data sections. These 3 boot sections span
10661
+ * sectors 0 to 7 in flash and live right before the FW image location.
10662
+ */
10663
+ i = DIV_ROUND_UP(size ? size : FLASH_FW_START, sf_sec_size);
10664
+ ret = t4_flash_erase_sectors(adap, boot_sector >> 16,
10665
+ (boot_sector >> 16) + i - 1);
10666
+
10667
+ /**
10668
+ * If size == 0 then we're simply erasing the FLASH sectors associated
10669
+ * with the on-adapter option ROM file
10670
+ */
10671
+ if (ret || size == 0)
10672
+ goto out;
10673
+ /* Retrieve adapter's device ID */
10674
+ pci_read_config_word(adap->pdev, PCI_DEVICE_ID, &device_id);
10675
+ /* Want to deal with PF 0 so I strip off PF 4 indicator */
10676
+ device_id = device_id & 0xf0ff;
10677
+
10678
+ /* Check PCIE Device ID */
10679
+ if (le16_to_cpu(pcir_header->device_id) != device_id) {
10680
+ /**
10681
+ * Change the device ID in the Boot BIOS image to match
10682
+ * the Device ID of the current adapter.
10683
+ */
10684
+ modify_device_id(device_id, boot_data);
10685
+ }
10686
+
10687
+ /**
10688
+ * Skip over the first SF_PAGE_SIZE worth of data and write it after
10689
+ * we finish copying the rest of the boot image. This will ensure
10690
+ * that the BIOS boot header will only be written if the boot image
10691
+ * was written in full.
10692
+ */
10693
+ addr = boot_sector;
10694
+ for (size -= SF_PAGE_SIZE; size; size -= SF_PAGE_SIZE) {
10695
+ addr += SF_PAGE_SIZE;
10696
+ boot_data += SF_PAGE_SIZE;
10697
+ ret = t4_write_flash(adap, addr, SF_PAGE_SIZE, boot_data,
10698
+ false);
10699
+ if (ret)
10700
+ goto out;
10701
+ }
10702
+
10703
+ ret = t4_write_flash(adap, boot_sector, SF_PAGE_SIZE,
10704
+ (const u8 *)header, false);
10705
+
10706
+out:
10707
+ if (ret)
10708
+ dev_err(adap->pdev_dev, "boot image load failed, error %d\n",
10709
+ ret);
10710
+ return ret;
10711
+}
10712
+
10713
+/**
10714
+ * t4_flash_bootcfg_addr - return the address of the flash
10715
+ * optionrom configuration
10716
+ * @adapter: the adapter
10717
+ *
10718
+ * Return the address within the flash where the OptionROM Configuration
10719
+ * is stored, or an error if the device FLASH is too small to contain
10720
+ * a OptionROM Configuration.
10721
+ */
10722
+static int t4_flash_bootcfg_addr(struct adapter *adapter)
10723
+{
10724
+ /**
10725
+ * If the device FLASH isn't large enough to hold a Firmware
10726
+ * Configuration File, return an error.
10727
+ */
10728
+ if (adapter->params.sf_size <
10729
+ FLASH_BOOTCFG_START + FLASH_BOOTCFG_MAX_SIZE)
10730
+ return -ENOSPC;
10731
+
10732
+ return FLASH_BOOTCFG_START;
10733
+}
10734
+
10735
+int t4_load_bootcfg(struct adapter *adap, const u8 *cfg_data, unsigned int size)
10736
+{
10737
+ unsigned int sf_sec_size = adap->params.sf_size / adap->params.sf_nsec;
10738
+ struct cxgb4_bootcfg_data *header;
10739
+ unsigned int flash_cfg_start_sec;
10740
+ unsigned int addr, npad;
10741
+ int ret, i, n, cfg_addr;
10742
+
10743
+ cfg_addr = t4_flash_bootcfg_addr(adap);
10744
+ if (cfg_addr < 0)
10745
+ return cfg_addr;
10746
+
10747
+ addr = cfg_addr;
10748
+ flash_cfg_start_sec = addr / SF_SEC_SIZE;
10749
+
10750
+ if (size > FLASH_BOOTCFG_MAX_SIZE) {
10751
+ dev_err(adap->pdev_dev, "bootcfg file too large, max is %u bytes\n",
10752
+ FLASH_BOOTCFG_MAX_SIZE);
10753
+ return -EFBIG;
10754
+ }
10755
+
10756
+ header = (struct cxgb4_bootcfg_data *)cfg_data;
10757
+ if (le16_to_cpu(header->signature) != BOOT_CFG_SIG) {
10758
+ dev_err(adap->pdev_dev, "Wrong bootcfg signature\n");
10759
+ ret = -EINVAL;
10760
+ goto out;
10761
+ }
10762
+
10763
+ i = DIV_ROUND_UP(FLASH_BOOTCFG_MAX_SIZE,
10764
+ sf_sec_size);
10765
+ ret = t4_flash_erase_sectors(adap, flash_cfg_start_sec,
10766
+ flash_cfg_start_sec + i - 1);
10767
+
10768
+ /**
10769
+ * If size == 0 then we're simply erasing the FLASH sectors associated
10770
+ * with the on-adapter OptionROM Configuration File.
10771
+ */
10772
+ if (ret || size == 0)
10773
+ goto out;
10774
+
10775
+ /* this will write to the flash up to SF_PAGE_SIZE at a time */
10776
+ for (i = 0; i < size; i += SF_PAGE_SIZE) {
10777
+ n = min_t(u32, size - i, SF_PAGE_SIZE);
10778
+
10779
+ ret = t4_write_flash(adap, addr, n, cfg_data, false);
10780
+ if (ret)
10781
+ goto out;
10782
+
10783
+ addr += SF_PAGE_SIZE;
10784
+ cfg_data += SF_PAGE_SIZE;
10785
+ }
10786
+
10787
+ npad = ((size + 4 - 1) & ~3) - size;
10788
+ for (i = 0; i < npad; i++) {
10789
+ u8 data = 0;
10790
+
10791
+ ret = t4_write_flash(adap, cfg_addr + size + i, 1, &data,
10792
+ false);
10793
+ if (ret)
10794
+ goto out;
10795
+ }
10796
+
10797
+out:
10798
+ if (ret)
10799
+ dev_err(adap->pdev_dev, "boot config data %s failed %d\n",
10800
+ (size == 0 ? "clear" : "download"), ret);
10801
+ return ret;
10802
+}