1 /******************************************************************************
3 Copyright (c) 2001-2010, Intel Corporation
6 Redistribution and use in source and binary forms, with or without
7 modification, are permitted provided that the following conditions are met:
9 1. Redistributions of source code must retain the above copyright notice,
10 this list of conditions and the following disclaimer.
12 2. Redistributions in binary form must reproduce the above copyright
13 notice, this list of conditions and the following disclaimer in the
14 documentation and/or other materials provided with the distribution.
16 3. Neither the name of the Intel Corporation nor the names of its
17 contributors may be used to endorse or promote products derived from
18 this software without specific prior written permission.
20 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
24 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 POSSIBILITY OF SUCH DAMAGE.
32 ******************************************************************************/
35 #include "ixgbe_common.h"
36 #include "ixgbe_phy.h"
37 #include "ixgbe_api.h"
39 static s32 ixgbe_acquire_eeprom(struct ixgbe_hw *hw);
40 static s32 ixgbe_get_eeprom_semaphore(struct ixgbe_hw *hw);
41 static void ixgbe_release_eeprom_semaphore(struct ixgbe_hw *hw);
42 static s32 ixgbe_ready_eeprom(struct ixgbe_hw *hw);
43 static void ixgbe_standby_eeprom(struct ixgbe_hw *hw);
44 static void ixgbe_shift_out_eeprom_bits(struct ixgbe_hw *hw, u16 data,
46 static u16 ixgbe_shift_in_eeprom_bits(struct ixgbe_hw *hw, u16 count);
47 static void ixgbe_raise_eeprom_clk(struct ixgbe_hw *hw, u32 *eec);
48 static void ixgbe_lower_eeprom_clk(struct ixgbe_hw *hw, u32 *eec);
49 static void ixgbe_release_eeprom(struct ixgbe_hw *hw);
51 static s32 ixgbe_mta_vector(struct ixgbe_hw *hw, u8 *mc_addr);
52 static s32 ixgbe_get_san_mac_addr_offset(struct ixgbe_hw *hw,
54 static s32 ixgbe_fc_autoneg_fiber(struct ixgbe_hw *hw);
55 static s32 ixgbe_fc_autoneg_backplane(struct ixgbe_hw *hw);
56 static s32 ixgbe_fc_autoneg_copper(struct ixgbe_hw *hw);
57 static s32 ixgbe_device_supports_autoneg_fc(struct ixgbe_hw *hw);
58 static s32 ixgbe_negotiate_fc(struct ixgbe_hw *hw, u32 adv_reg, u32 lp_reg,
59 u32 adv_sym, u32 adv_asm, u32 lp_sym, u32 lp_asm);
60 static s32 ixgbe_setup_fc(struct ixgbe_hw *hw, s32 packetbuf_num);
61 static s32 ixgbe_read_eeprom_buffer_bit_bang(struct ixgbe_hw *hw, u16 offset,
62 u16 words, u16 *data);
63 static s32 ixgbe_write_eeprom_buffer_bit_bang(struct ixgbe_hw *hw, u16 offset,
64 u16 words, u16 *data);
65 static s32 ixgbe_detect_eeprom_page_size_generic(struct ixgbe_hw *hw,
69 s32 ixgbe_find_vlvf_slot(struct ixgbe_hw *hw, u32 vlan);
72 * ixgbe_init_ops_generic - Inits function ptrs
73 * @hw: pointer to the hardware structure
75 * Initialize the function pointers.
77 s32 ixgbe_init_ops_generic(struct ixgbe_hw *hw)
79 struct ixgbe_eeprom_info *eeprom = &hw->eeprom;
80 struct ixgbe_mac_info *mac = &hw->mac;
81 u32 eec = IXGBE_READ_REG(hw, IXGBE_EEC);
83 DEBUGFUNC("ixgbe_init_ops_generic");
86 eeprom->ops.init_params = &ixgbe_init_eeprom_params_generic;
87 /* If EEPROM is valid (bit 8 = 1), use EERD otherwise use bit bang */
88 if (eec & IXGBE_EEC_PRES) {
89 eeprom->ops.read = &ixgbe_read_eerd_generic;
90 eeprom->ops.read_buffer = &ixgbe_read_eerd_buffer_generic;
92 eeprom->ops.read = &ixgbe_read_eeprom_bit_bang_generic;
93 eeprom->ops.read_buffer =
94 &ixgbe_read_eeprom_buffer_bit_bang_generic;
96 eeprom->ops.write = &ixgbe_write_eeprom_generic;
97 eeprom->ops.write_buffer = &ixgbe_write_eeprom_buffer_bit_bang_generic;
98 eeprom->ops.validate_checksum =
99 &ixgbe_validate_eeprom_checksum_generic;
100 eeprom->ops.update_checksum = &ixgbe_update_eeprom_checksum_generic;
101 eeprom->ops.calc_checksum = &ixgbe_calc_eeprom_checksum_generic;
104 mac->ops.init_hw = &ixgbe_init_hw_generic;
105 mac->ops.reset_hw = NULL;
106 mac->ops.start_hw = &ixgbe_start_hw_generic;
107 mac->ops.clear_hw_cntrs = &ixgbe_clear_hw_cntrs_generic;
108 mac->ops.get_media_type = NULL;
109 mac->ops.get_supported_physical_layer = NULL;
110 mac->ops.enable_rx_dma = &ixgbe_enable_rx_dma_generic;
111 mac->ops.get_mac_addr = &ixgbe_get_mac_addr_generic;
112 mac->ops.stop_adapter = &ixgbe_stop_adapter_generic;
113 mac->ops.get_bus_info = &ixgbe_get_bus_info_generic;
114 mac->ops.set_lan_id = &ixgbe_set_lan_id_multi_port_pcie;
115 mac->ops.acquire_swfw_sync = &ixgbe_acquire_swfw_sync;
116 mac->ops.release_swfw_sync = &ixgbe_release_swfw_sync;
119 mac->ops.led_on = &ixgbe_led_on_generic;
120 mac->ops.led_off = &ixgbe_led_off_generic;
121 mac->ops.blink_led_start = &ixgbe_blink_led_start_generic;
122 mac->ops.blink_led_stop = &ixgbe_blink_led_stop_generic;
124 /* RAR, Multicast, VLAN */
125 mac->ops.set_rar = &ixgbe_set_rar_generic;
126 mac->ops.clear_rar = &ixgbe_clear_rar_generic;
127 mac->ops.insert_mac_addr = NULL;
128 mac->ops.set_vmdq = NULL;
129 mac->ops.clear_vmdq = NULL;
130 mac->ops.init_rx_addrs = &ixgbe_init_rx_addrs_generic;
131 mac->ops.update_uc_addr_list = &ixgbe_update_uc_addr_list_generic;
132 mac->ops.update_mc_addr_list = &ixgbe_update_mc_addr_list_generic;
133 mac->ops.enable_mc = &ixgbe_enable_mc_generic;
134 mac->ops.disable_mc = &ixgbe_disable_mc_generic;
135 mac->ops.clear_vfta = NULL;
136 mac->ops.set_vfta = NULL;
137 mac->ops.init_uta_tables = NULL;
140 mac->ops.fc_enable = &ixgbe_fc_enable_generic;
143 mac->ops.get_link_capabilities = NULL;
144 mac->ops.setup_link = NULL;
145 mac->ops.check_link = NULL;
147 return IXGBE_SUCCESS;
151 * ixgbe_start_hw_generic - Prepare hardware for Tx/Rx
152 * @hw: pointer to hardware structure
154 * Starts the hardware by filling the bus info structure and media type, clears
155 * all on chip counters, initializes receive address registers, multicast
156 * table, VLAN filter table, calls routine to set up link and flow control
157 * settings, and leaves transmit and receive units disabled and uninitialized
159 s32 ixgbe_start_hw_generic(struct ixgbe_hw *hw)
163 DEBUGFUNC("ixgbe_start_hw_generic");
165 /* Set the media type */
166 hw->phy.media_type = hw->mac.ops.get_media_type(hw);
168 /* PHY ops initialization must be done in reset_hw() */
170 /* Clear the VLAN filter table */
171 hw->mac.ops.clear_vfta(hw);
173 /* Clear statistics registers */
174 hw->mac.ops.clear_hw_cntrs(hw);
176 /* Set No Snoop Disable */
177 ctrl_ext = IXGBE_READ_REG(hw, IXGBE_CTRL_EXT);
178 ctrl_ext |= IXGBE_CTRL_EXT_NS_DIS;
179 IXGBE_WRITE_REG(hw, IXGBE_CTRL_EXT, ctrl_ext);
180 IXGBE_WRITE_FLUSH(hw);
182 /* Setup flow control */
183 ixgbe_setup_fc(hw, 0);
185 /* Clear adapter stopped flag */
186 hw->adapter_stopped = FALSE;
188 return IXGBE_SUCCESS;
192 * ixgbe_start_hw_gen2 - Init sequence for common device family
193 * @hw: pointer to hw structure
195 * Performs the init sequence common to the second generation
197 * Devices in the second generation:
201 s32 ixgbe_start_hw_gen2(struct ixgbe_hw *hw)
206 /* Clear the rate limiters */
207 for (i = 0; i < hw->mac.max_tx_queues; i++) {
208 IXGBE_WRITE_REG(hw, IXGBE_RTTDQSEL, i);
209 IXGBE_WRITE_REG(hw, IXGBE_RTTBCNRC, 0);
211 IXGBE_WRITE_FLUSH(hw);
213 /* Disable relaxed ordering */
214 for (i = 0; i < hw->mac.max_tx_queues; i++) {
215 regval = IXGBE_READ_REG(hw, IXGBE_DCA_TXCTRL_82599(i));
216 regval &= ~IXGBE_DCA_TXCTRL_TX_WB_RO_EN;
217 IXGBE_WRITE_REG(hw, IXGBE_DCA_TXCTRL_82599(i), regval);
220 for (i = 0; i < hw->mac.max_rx_queues; i++) {
221 regval = IXGBE_READ_REG(hw, IXGBE_DCA_RXCTRL(i));
222 regval &= ~(IXGBE_DCA_RXCTRL_DESC_WRO_EN |
223 IXGBE_DCA_RXCTRL_DESC_HSRO_EN);
224 IXGBE_WRITE_REG(hw, IXGBE_DCA_RXCTRL(i), regval);
227 return IXGBE_SUCCESS;
231 * ixgbe_init_hw_generic - Generic hardware initialization
232 * @hw: pointer to hardware structure
234 * Initialize the hardware by resetting the hardware, filling the bus info
235 * structure and media type, clears all on chip counters, initializes receive
236 * address registers, multicast table, VLAN filter table, calls routine to set
237 * up link and flow control settings, and leaves transmit and receive units
238 * disabled and uninitialized
240 s32 ixgbe_init_hw_generic(struct ixgbe_hw *hw)
244 DEBUGFUNC("ixgbe_init_hw_generic");
246 /* Reset the hardware */
247 status = hw->mac.ops.reset_hw(hw);
249 if (status == IXGBE_SUCCESS) {
251 status = hw->mac.ops.start_hw(hw);
258 * ixgbe_clear_hw_cntrs_generic - Generic clear hardware counters
259 * @hw: pointer to hardware structure
261 * Clears all hardware statistics counters by reading them from the hardware
262 * Statistics counters are clear on read.
264 s32 ixgbe_clear_hw_cntrs_generic(struct ixgbe_hw *hw)
268 DEBUGFUNC("ixgbe_clear_hw_cntrs_generic");
270 IXGBE_READ_REG(hw, IXGBE_CRCERRS);
271 IXGBE_READ_REG(hw, IXGBE_ILLERRC);
272 IXGBE_READ_REG(hw, IXGBE_ERRBC);
273 IXGBE_READ_REG(hw, IXGBE_MSPDC);
274 for (i = 0; i < 8; i++)
275 IXGBE_READ_REG(hw, IXGBE_MPC(i));
277 IXGBE_READ_REG(hw, IXGBE_MLFC);
278 IXGBE_READ_REG(hw, IXGBE_MRFC);
279 IXGBE_READ_REG(hw, IXGBE_RLEC);
280 IXGBE_READ_REG(hw, IXGBE_LXONTXC);
281 IXGBE_READ_REG(hw, IXGBE_LXOFFTXC);
282 if (hw->mac.type >= ixgbe_mac_82599EB) {
283 IXGBE_READ_REG(hw, IXGBE_LXONRXCNT);
284 IXGBE_READ_REG(hw, IXGBE_LXOFFRXCNT);
286 IXGBE_READ_REG(hw, IXGBE_LXONRXC);
287 IXGBE_READ_REG(hw, IXGBE_LXOFFRXC);
290 for (i = 0; i < 8; i++) {
291 IXGBE_READ_REG(hw, IXGBE_PXONTXC(i));
292 IXGBE_READ_REG(hw, IXGBE_PXOFFTXC(i));
293 if (hw->mac.type >= ixgbe_mac_82599EB) {
294 IXGBE_READ_REG(hw, IXGBE_PXONRXCNT(i));
295 IXGBE_READ_REG(hw, IXGBE_PXOFFRXCNT(i));
297 IXGBE_READ_REG(hw, IXGBE_PXONRXC(i));
298 IXGBE_READ_REG(hw, IXGBE_PXOFFRXC(i));
301 if (hw->mac.type >= ixgbe_mac_82599EB)
302 for (i = 0; i < 8; i++)
303 IXGBE_READ_REG(hw, IXGBE_PXON2OFFCNT(i));
304 IXGBE_READ_REG(hw, IXGBE_PRC64);
305 IXGBE_READ_REG(hw, IXGBE_PRC127);
306 IXGBE_READ_REG(hw, IXGBE_PRC255);
307 IXGBE_READ_REG(hw, IXGBE_PRC511);
308 IXGBE_READ_REG(hw, IXGBE_PRC1023);
309 IXGBE_READ_REG(hw, IXGBE_PRC1522);
310 IXGBE_READ_REG(hw, IXGBE_GPRC);
311 IXGBE_READ_REG(hw, IXGBE_BPRC);
312 IXGBE_READ_REG(hw, IXGBE_MPRC);
313 IXGBE_READ_REG(hw, IXGBE_GPTC);
314 IXGBE_READ_REG(hw, IXGBE_GORCL);
315 IXGBE_READ_REG(hw, IXGBE_GORCH);
316 IXGBE_READ_REG(hw, IXGBE_GOTCL);
317 IXGBE_READ_REG(hw, IXGBE_GOTCH);
318 if (hw->mac.type == ixgbe_mac_82598EB)
319 for (i = 0; i < 8; i++)
320 IXGBE_READ_REG(hw, IXGBE_RNBC(i));
321 IXGBE_READ_REG(hw, IXGBE_RUC);
322 IXGBE_READ_REG(hw, IXGBE_RFC);
323 IXGBE_READ_REG(hw, IXGBE_ROC);
324 IXGBE_READ_REG(hw, IXGBE_RJC);
325 IXGBE_READ_REG(hw, IXGBE_MNGPRC);
326 IXGBE_READ_REG(hw, IXGBE_MNGPDC);
327 IXGBE_READ_REG(hw, IXGBE_MNGPTC);
328 IXGBE_READ_REG(hw, IXGBE_TORL);
329 IXGBE_READ_REG(hw, IXGBE_TORH);
330 IXGBE_READ_REG(hw, IXGBE_TPR);
331 IXGBE_READ_REG(hw, IXGBE_TPT);
332 IXGBE_READ_REG(hw, IXGBE_PTC64);
333 IXGBE_READ_REG(hw, IXGBE_PTC127);
334 IXGBE_READ_REG(hw, IXGBE_PTC255);
335 IXGBE_READ_REG(hw, IXGBE_PTC511);
336 IXGBE_READ_REG(hw, IXGBE_PTC1023);
337 IXGBE_READ_REG(hw, IXGBE_PTC1522);
338 IXGBE_READ_REG(hw, IXGBE_MPTC);
339 IXGBE_READ_REG(hw, IXGBE_BPTC);
340 for (i = 0; i < 16; i++) {
341 IXGBE_READ_REG(hw, IXGBE_QPRC(i));
342 IXGBE_READ_REG(hw, IXGBE_QPTC(i));
343 if (hw->mac.type >= ixgbe_mac_82599EB) {
344 IXGBE_READ_REG(hw, IXGBE_QBRC_L(i));
345 IXGBE_READ_REG(hw, IXGBE_QBRC_H(i));
346 IXGBE_READ_REG(hw, IXGBE_QBTC_L(i));
347 IXGBE_READ_REG(hw, IXGBE_QBTC_H(i));
348 IXGBE_READ_REG(hw, IXGBE_QPRDC(i));
350 IXGBE_READ_REG(hw, IXGBE_QBRC(i));
351 IXGBE_READ_REG(hw, IXGBE_QBTC(i));
355 if (hw->mac.type == ixgbe_mac_X540) {
357 ixgbe_identify_phy(hw);
358 hw->phy.ops.read_reg(hw, 0x3, IXGBE_PCRC8ECL, &i);
359 hw->phy.ops.read_reg(hw, 0x3, IXGBE_PCRC8ECH, &i);
360 hw->phy.ops.read_reg(hw, 0x3, IXGBE_LDPCECL, &i);
361 hw->phy.ops.read_reg(hw, 0x3, IXGBE_LDPCECH, &i);
364 return IXGBE_SUCCESS;
368 * ixgbe_read_pba_string_generic - Reads part number string from EEPROM
369 * @hw: pointer to hardware structure
370 * @pba_num: stores the part number string from the EEPROM
371 * @pba_num_size: part number string buffer length
373 * Reads the part number string from the EEPROM.
375 s32 ixgbe_read_pba_string_generic(struct ixgbe_hw *hw, u8 *pba_num,
384 DEBUGFUNC("ixgbe_read_pba_string_generic");
386 if (pba_num == NULL) {
387 DEBUGOUT("PBA string buffer was null\n");
388 return IXGBE_ERR_INVALID_ARGUMENT;
391 ret_val = hw->eeprom.ops.read(hw, IXGBE_PBANUM0_PTR, &data);
393 DEBUGOUT("NVM Read Error\n");
397 ret_val = hw->eeprom.ops.read(hw, IXGBE_PBANUM1_PTR, &pba_ptr);
399 DEBUGOUT("NVM Read Error\n");
404 * if data is not ptr guard the PBA must be in legacy format which
405 * means pba_ptr is actually our second data word for the PBA number
406 * and we can decode it into an ascii string
408 if (data != IXGBE_PBANUM_PTR_GUARD) {
409 DEBUGOUT("NVM PBA number is not stored as string\n");
411 /* we will need 11 characters to store the PBA */
412 if (pba_num_size < 11) {
413 DEBUGOUT("PBA string buffer too small\n");
414 return IXGBE_ERR_NO_SPACE;
417 /* extract hex string from data and pba_ptr */
418 pba_num[0] = (data >> 12) & 0xF;
419 pba_num[1] = (data >> 8) & 0xF;
420 pba_num[2] = (data >> 4) & 0xF;
421 pba_num[3] = data & 0xF;
422 pba_num[4] = (pba_ptr >> 12) & 0xF;
423 pba_num[5] = (pba_ptr >> 8) & 0xF;
426 pba_num[8] = (pba_ptr >> 4) & 0xF;
427 pba_num[9] = pba_ptr & 0xF;
429 /* put a null character on the end of our string */
432 /* switch all the data but the '-' to hex char */
433 for (offset = 0; offset < 10; offset++) {
434 if (pba_num[offset] < 0xA)
435 pba_num[offset] += '0';
436 else if (pba_num[offset] < 0x10)
437 pba_num[offset] += 'A' - 0xA;
440 return IXGBE_SUCCESS;
443 ret_val = hw->eeprom.ops.read(hw, pba_ptr, &length);
445 DEBUGOUT("NVM Read Error\n");
449 if (length == 0xFFFF || length == 0) {
450 DEBUGOUT("NVM PBA number section invalid length\n");
451 return IXGBE_ERR_PBA_SECTION;
454 /* check if pba_num buffer is big enough */
455 if (pba_num_size < (((u32)length * 2) - 1)) {
456 DEBUGOUT("PBA string buffer too small\n");
457 return IXGBE_ERR_NO_SPACE;
460 /* trim pba length from start of string */
464 for (offset = 0; offset < length; offset++) {
465 ret_val = hw->eeprom.ops.read(hw, pba_ptr + offset, &data);
467 DEBUGOUT("NVM Read Error\n");
470 pba_num[offset * 2] = (u8)(data >> 8);
471 pba_num[(offset * 2) + 1] = (u8)(data & 0xFF);
473 pba_num[offset * 2] = '\0';
475 return IXGBE_SUCCESS;
479 * ixgbe_read_pba_num_generic - Reads part number from EEPROM
480 * @hw: pointer to hardware structure
481 * @pba_num: stores the part number from the EEPROM
483 * Reads the part number from the EEPROM.
485 s32 ixgbe_read_pba_num_generic(struct ixgbe_hw *hw, u32 *pba_num)
490 DEBUGFUNC("ixgbe_read_pba_num_generic");
492 ret_val = hw->eeprom.ops.read(hw, IXGBE_PBANUM0_PTR, &data);
494 DEBUGOUT("NVM Read Error\n");
496 } else if (data == IXGBE_PBANUM_PTR_GUARD) {
497 DEBUGOUT("NVM Not supported\n");
498 return IXGBE_NOT_IMPLEMENTED;
500 *pba_num = (u32)(data << 16);
502 ret_val = hw->eeprom.ops.read(hw, IXGBE_PBANUM1_PTR, &data);
504 DEBUGOUT("NVM Read Error\n");
509 return IXGBE_SUCCESS;
513 * ixgbe_get_mac_addr_generic - Generic get MAC address
514 * @hw: pointer to hardware structure
515 * @mac_addr: Adapter MAC address
517 * Reads the adapter's MAC address from first Receive Address Register (RAR0)
518 * A reset of the adapter must be performed prior to calling this function
519 * in order for the MAC address to have been loaded from the EEPROM into RAR0
521 s32 ixgbe_get_mac_addr_generic(struct ixgbe_hw *hw, u8 *mac_addr)
527 DEBUGFUNC("ixgbe_get_mac_addr_generic");
529 rar_high = IXGBE_READ_REG(hw, IXGBE_RAH(0));
530 rar_low = IXGBE_READ_REG(hw, IXGBE_RAL(0));
532 for (i = 0; i < 4; i++)
533 mac_addr[i] = (u8)(rar_low >> (i*8));
535 for (i = 0; i < 2; i++)
536 mac_addr[i+4] = (u8)(rar_high >> (i*8));
538 return IXGBE_SUCCESS;
542 * ixgbe_get_bus_info_generic - Generic set PCI bus info
543 * @hw: pointer to hardware structure
545 * Sets the PCI bus info (speed, width, type) within the ixgbe_hw structure
547 s32 ixgbe_get_bus_info_generic(struct ixgbe_hw *hw)
549 struct ixgbe_mac_info *mac = &hw->mac;
552 DEBUGFUNC("ixgbe_get_bus_info_generic");
554 hw->bus.type = ixgbe_bus_type_pci_express;
556 /* Get the negotiated link width and speed from PCI config space */
557 link_status = IXGBE_READ_PCIE_WORD(hw, IXGBE_PCI_LINK_STATUS);
559 switch (link_status & IXGBE_PCI_LINK_WIDTH) {
560 case IXGBE_PCI_LINK_WIDTH_1:
561 hw->bus.width = ixgbe_bus_width_pcie_x1;
563 case IXGBE_PCI_LINK_WIDTH_2:
564 hw->bus.width = ixgbe_bus_width_pcie_x2;
566 case IXGBE_PCI_LINK_WIDTH_4:
567 hw->bus.width = ixgbe_bus_width_pcie_x4;
569 case IXGBE_PCI_LINK_WIDTH_8:
570 hw->bus.width = ixgbe_bus_width_pcie_x8;
573 hw->bus.width = ixgbe_bus_width_unknown;
577 switch (link_status & IXGBE_PCI_LINK_SPEED) {
578 case IXGBE_PCI_LINK_SPEED_2500:
579 hw->bus.speed = ixgbe_bus_speed_2500;
581 case IXGBE_PCI_LINK_SPEED_5000:
582 hw->bus.speed = ixgbe_bus_speed_5000;
585 hw->bus.speed = ixgbe_bus_speed_unknown;
589 mac->ops.set_lan_id(hw);
591 return IXGBE_SUCCESS;
595 * ixgbe_set_lan_id_multi_port_pcie - Set LAN id for PCIe multiple port devices
596 * @hw: pointer to the HW structure
598 * Determines the LAN function id by reading memory-mapped registers
599 * and swaps the port value if requested.
601 void ixgbe_set_lan_id_multi_port_pcie(struct ixgbe_hw *hw)
603 struct ixgbe_bus_info *bus = &hw->bus;
606 DEBUGFUNC("ixgbe_set_lan_id_multi_port_pcie");
608 reg = IXGBE_READ_REG(hw, IXGBE_STATUS);
609 bus->func = (reg & IXGBE_STATUS_LAN_ID) >> IXGBE_STATUS_LAN_ID_SHIFT;
610 bus->lan_id = bus->func;
612 /* check for a port swap */
613 reg = IXGBE_READ_REG(hw, IXGBE_FACTPS);
614 if (reg & IXGBE_FACTPS_LFS)
619 * ixgbe_stop_adapter_generic - Generic stop Tx/Rx units
620 * @hw: pointer to hardware structure
622 * Sets the adapter_stopped flag within ixgbe_hw struct. Clears interrupts,
623 * disables transmit and receive units. The adapter_stopped flag is used by
624 * the shared code and drivers to determine if the adapter is in a stopped
625 * state and should not touch the hardware.
627 s32 ixgbe_stop_adapter_generic(struct ixgbe_hw *hw)
632 DEBUGFUNC("ixgbe_stop_adapter_generic");
635 * Set the adapter_stopped flag so other driver functions stop touching
638 hw->adapter_stopped = TRUE;
640 /* Disable the receive unit */
641 IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, 0);
643 /* Clear interrupt mask to stop interrupts from being generated */
644 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_IRQ_CLEAR_MASK);
646 /* Clear any pending interrupts, flush previous writes */
647 IXGBE_READ_REG(hw, IXGBE_EICR);
649 /* Disable the transmit unit. Each queue must be disabled. */
650 for (i = 0; i < hw->mac.max_tx_queues; i++)
651 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(i), IXGBE_TXDCTL_SWFLSH);
653 /* Disable the receive unit by stopping each queue */
654 for (i = 0; i < hw->mac.max_rx_queues; i++) {
655 reg_val = IXGBE_READ_REG(hw, IXGBE_RXDCTL(i));
656 reg_val &= ~IXGBE_RXDCTL_ENABLE;
657 reg_val |= IXGBE_RXDCTL_SWFLSH;
658 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(i), reg_val);
661 /* flush all queues disables */
662 IXGBE_WRITE_FLUSH(hw);
666 * Prevent the PCI-E bus from from hanging by disabling PCI-E master
667 * access and verify no pending requests
669 return ixgbe_disable_pcie_master(hw);
673 * ixgbe_led_on_generic - Turns on the software controllable LEDs.
674 * @hw: pointer to hardware structure
675 * @index: led number to turn on
677 s32 ixgbe_led_on_generic(struct ixgbe_hw *hw, u32 index)
679 u32 led_reg = IXGBE_READ_REG(hw, IXGBE_LEDCTL);
681 DEBUGFUNC("ixgbe_led_on_generic");
683 /* To turn on the LED, set mode to ON. */
684 led_reg &= ~IXGBE_LED_MODE_MASK(index);
685 led_reg |= IXGBE_LED_ON << IXGBE_LED_MODE_SHIFT(index);
686 IXGBE_WRITE_REG(hw, IXGBE_LEDCTL, led_reg);
687 IXGBE_WRITE_FLUSH(hw);
689 return IXGBE_SUCCESS;
693 * ixgbe_led_off_generic - Turns off the software controllable LEDs.
694 * @hw: pointer to hardware structure
695 * @index: led number to turn off
697 s32 ixgbe_led_off_generic(struct ixgbe_hw *hw, u32 index)
699 u32 led_reg = IXGBE_READ_REG(hw, IXGBE_LEDCTL);
701 DEBUGFUNC("ixgbe_led_off_generic");
703 /* To turn off the LED, set mode to OFF. */
704 led_reg &= ~IXGBE_LED_MODE_MASK(index);
705 led_reg |= IXGBE_LED_OFF << IXGBE_LED_MODE_SHIFT(index);
706 IXGBE_WRITE_REG(hw, IXGBE_LEDCTL, led_reg);
707 IXGBE_WRITE_FLUSH(hw);
709 return IXGBE_SUCCESS;
713 * ixgbe_init_eeprom_params_generic - Initialize EEPROM params
714 * @hw: pointer to hardware structure
716 * Initializes the EEPROM parameters ixgbe_eeprom_info within the
717 * ixgbe_hw struct in order to set up EEPROM access.
719 s32 ixgbe_init_eeprom_params_generic(struct ixgbe_hw *hw)
721 struct ixgbe_eeprom_info *eeprom = &hw->eeprom;
725 DEBUGFUNC("ixgbe_init_eeprom_params_generic");
727 if (eeprom->type == ixgbe_eeprom_uninitialized) {
728 eeprom->type = ixgbe_eeprom_none;
729 /* Set default semaphore delay to 10ms which is a well
731 eeprom->semaphore_delay = 10;
732 /* Clear EEPROM page size, it will be initialized as needed */
733 eeprom->word_page_size = 0;
736 * Check for EEPROM present first.
737 * If not present leave as none
739 eec = IXGBE_READ_REG(hw, IXGBE_EEC);
740 if (eec & IXGBE_EEC_PRES) {
741 eeprom->type = ixgbe_eeprom_spi;
744 * SPI EEPROM is assumed here. This code would need to
745 * change if a future EEPROM is not SPI.
747 eeprom_size = (u16)((eec & IXGBE_EEC_SIZE) >>
748 IXGBE_EEC_SIZE_SHIFT);
749 eeprom->word_size = 1 << (eeprom_size +
750 IXGBE_EEPROM_WORD_SIZE_SHIFT);
753 if (eec & IXGBE_EEC_ADDR_SIZE)
754 eeprom->address_bits = 16;
756 eeprom->address_bits = 8;
757 DEBUGOUT3("Eeprom params: type = %d, size = %d, address bits: "
758 "%d\n", eeprom->type, eeprom->word_size,
759 eeprom->address_bits);
762 return IXGBE_SUCCESS;
766 * ixgbe_write_eeprom_buffer_bit_bang_generic - Write EEPROM using bit-bang
767 * @hw: pointer to hardware structure
768 * @offset: offset within the EEPROM to write
769 * @words: number of word(s)
770 * @data: 16 bit word(s) to write to EEPROM
772 * Reads 16 bit word(s) from EEPROM through bit-bang method
774 s32 ixgbe_write_eeprom_buffer_bit_bang_generic(struct ixgbe_hw *hw, u16 offset,
775 u16 words, u16 *data)
777 s32 status = IXGBE_SUCCESS;
780 DEBUGFUNC("ixgbe_write_eeprom_buffer_bit_bang_generic");
782 hw->eeprom.ops.init_params(hw);
785 status = IXGBE_ERR_INVALID_ARGUMENT;
789 if (offset + words > hw->eeprom.word_size) {
790 status = IXGBE_ERR_EEPROM;
795 * The EEPROM page size cannot be queried from the chip. We do lazy
796 * initialization. It is worth to do that when we write large buffer.
798 if ((hw->eeprom.word_page_size == 0) &&
799 (words > IXGBE_EEPROM_PAGE_SIZE_MAX))
800 ixgbe_detect_eeprom_page_size_generic(hw, offset);
803 * We cannot hold synchronization semaphores for too long
804 * to avoid other entity starvation. However it is more efficient
805 * to read in bursts than synchronizing access for each word.
807 for (i = 0; i < words; i += IXGBE_EEPROM_RD_BUFFER_MAX_COUNT) {
808 count = (words - i) / IXGBE_EEPROM_RD_BUFFER_MAX_COUNT > 0 ?
809 IXGBE_EEPROM_RD_BUFFER_MAX_COUNT : (words - i);
810 status = ixgbe_write_eeprom_buffer_bit_bang(hw, offset + i,
813 if (status != IXGBE_SUCCESS)
822 * ixgbe_write_eeprom_buffer_bit_bang - Writes 16 bit word(s) to EEPROM
823 * @hw: pointer to hardware structure
824 * @offset: offset within the EEPROM to be written to
825 * @words: number of word(s)
826 * @data: 16 bit word(s) to be written to the EEPROM
828 * If ixgbe_eeprom_update_checksum is not called after this function, the
829 * EEPROM will most likely contain an invalid checksum.
831 static s32 ixgbe_write_eeprom_buffer_bit_bang(struct ixgbe_hw *hw, u16 offset,
832 u16 words, u16 *data)
838 u8 write_opcode = IXGBE_EEPROM_WRITE_OPCODE_SPI;
840 DEBUGFUNC("ixgbe_write_eeprom_buffer_bit_bang");
842 /* Prepare the EEPROM for writing */
843 status = ixgbe_acquire_eeprom(hw);
845 if (status == IXGBE_SUCCESS) {
846 if (ixgbe_ready_eeprom(hw) != IXGBE_SUCCESS) {
847 ixgbe_release_eeprom(hw);
848 status = IXGBE_ERR_EEPROM;
852 if (status == IXGBE_SUCCESS) {
853 for (i = 0; i < words; i++) {
854 ixgbe_standby_eeprom(hw);
856 /* Send the WRITE ENABLE command (8 bit opcode ) */
857 ixgbe_shift_out_eeprom_bits(hw,
858 IXGBE_EEPROM_WREN_OPCODE_SPI,
859 IXGBE_EEPROM_OPCODE_BITS);
861 ixgbe_standby_eeprom(hw);
864 * Some SPI eeproms use the 8th address bit embedded
867 if ((hw->eeprom.address_bits == 8) &&
868 ((offset + i) >= 128))
869 write_opcode |= IXGBE_EEPROM_A8_OPCODE_SPI;
871 /* Send the Write command (8-bit opcode + addr) */
872 ixgbe_shift_out_eeprom_bits(hw, write_opcode,
873 IXGBE_EEPROM_OPCODE_BITS);
874 ixgbe_shift_out_eeprom_bits(hw, (u16)((offset + i) * 2),
875 hw->eeprom.address_bits);
877 page_size = hw->eeprom.word_page_size;
879 /* Send the data in burst via SPI*/
882 word = (word >> 8) | (word << 8);
883 ixgbe_shift_out_eeprom_bits(hw, word, 16);
888 /* do not wrap around page */
889 if (((offset + i) & (page_size - 1)) ==
892 } while (++i < words);
894 ixgbe_standby_eeprom(hw);
897 /* Done with writing - release the EEPROM */
898 ixgbe_release_eeprom(hw);
905 * ixgbe_write_eeprom_generic - Writes 16 bit value to EEPROM
906 * @hw: pointer to hardware structure
907 * @offset: offset within the EEPROM to be written to
908 * @data: 16 bit word to be written to the EEPROM
910 * If ixgbe_eeprom_update_checksum is not called after this function, the
911 * EEPROM will most likely contain an invalid checksum.
913 s32 ixgbe_write_eeprom_generic(struct ixgbe_hw *hw, u16 offset, u16 data)
917 DEBUGFUNC("ixgbe_write_eeprom_generic");
919 hw->eeprom.ops.init_params(hw);
921 if (offset >= hw->eeprom.word_size) {
922 status = IXGBE_ERR_EEPROM;
926 status = ixgbe_write_eeprom_buffer_bit_bang(hw, offset, 1, &data);
933 * ixgbe_read_eeprom_buffer_bit_bang_generic - Read EEPROM using bit-bang
934 * @hw: pointer to hardware structure
935 * @offset: offset within the EEPROM to be read
936 * @data: read 16 bit words(s) from EEPROM
937 * @words: number of word(s)
939 * Reads 16 bit word(s) from EEPROM through bit-bang method
941 s32 ixgbe_read_eeprom_buffer_bit_bang_generic(struct ixgbe_hw *hw, u16 offset,
942 u16 words, u16 *data)
944 s32 status = IXGBE_SUCCESS;
947 DEBUGFUNC("ixgbe_read_eeprom_buffer_bit_bang_generic");
949 hw->eeprom.ops.init_params(hw);
952 status = IXGBE_ERR_INVALID_ARGUMENT;
956 if (offset + words > hw->eeprom.word_size) {
957 status = IXGBE_ERR_EEPROM;
962 * We cannot hold synchronization semaphores for too long
963 * to avoid other entity starvation. However it is more efficient
964 * to read in bursts than synchronizing access for each word.
966 for (i = 0; i < words; i += IXGBE_EEPROM_RD_BUFFER_MAX_COUNT) {
967 count = (words - i) / IXGBE_EEPROM_RD_BUFFER_MAX_COUNT > 0 ?
968 IXGBE_EEPROM_RD_BUFFER_MAX_COUNT : (words - i);
970 status = ixgbe_read_eeprom_buffer_bit_bang(hw, offset + i,
973 if (status != IXGBE_SUCCESS)
982 * ixgbe_read_eeprom_buffer_bit_bang - Read EEPROM using bit-bang
983 * @hw: pointer to hardware structure
984 * @offset: offset within the EEPROM to be read
985 * @words: number of word(s)
986 * @data: read 16 bit word(s) from EEPROM
988 * Reads 16 bit word(s) from EEPROM through bit-bang method
990 static s32 ixgbe_read_eeprom_buffer_bit_bang(struct ixgbe_hw *hw, u16 offset,
991 u16 words, u16 *data)
995 u8 read_opcode = IXGBE_EEPROM_READ_OPCODE_SPI;
998 DEBUGFUNC("ixgbe_read_eeprom_buffer_bit_bang");
1000 /* Prepare the EEPROM for reading */
1001 status = ixgbe_acquire_eeprom(hw);
1003 if (status == IXGBE_SUCCESS) {
1004 if (ixgbe_ready_eeprom(hw) != IXGBE_SUCCESS) {
1005 ixgbe_release_eeprom(hw);
1006 status = IXGBE_ERR_EEPROM;
1010 if (status == IXGBE_SUCCESS) {
1011 for (i = 0; i < words; i++) {
1012 ixgbe_standby_eeprom(hw);
1014 * Some SPI eeproms use the 8th address bit embedded
1017 if ((hw->eeprom.address_bits == 8) &&
1018 ((offset + i) >= 128))
1019 read_opcode |= IXGBE_EEPROM_A8_OPCODE_SPI;
1021 /* Send the READ command (opcode + addr) */
1022 ixgbe_shift_out_eeprom_bits(hw, read_opcode,
1023 IXGBE_EEPROM_OPCODE_BITS);
1024 ixgbe_shift_out_eeprom_bits(hw, (u16)((offset + i) * 2),
1025 hw->eeprom.address_bits);
1027 /* Read the data. */
1028 word_in = ixgbe_shift_in_eeprom_bits(hw, 16);
1029 data[i] = (word_in >> 8) | (word_in << 8);
1032 /* End this read operation */
1033 ixgbe_release_eeprom(hw);
1040 * ixgbe_read_eeprom_bit_bang_generic - Read EEPROM word using bit-bang
1041 * @hw: pointer to hardware structure
1042 * @offset: offset within the EEPROM to be read
1043 * @data: read 16 bit value from EEPROM
1045 * Reads 16 bit value from EEPROM through bit-bang method
1047 s32 ixgbe_read_eeprom_bit_bang_generic(struct ixgbe_hw *hw, u16 offset,
1052 DEBUGFUNC("ixgbe_read_eeprom_bit_bang_generic");
1054 hw->eeprom.ops.init_params(hw);
1056 if (offset >= hw->eeprom.word_size) {
1057 status = IXGBE_ERR_EEPROM;
1061 status = ixgbe_read_eeprom_buffer_bit_bang(hw, offset, 1, data);
1068 * ixgbe_read_eerd_buffer_generic - Read EEPROM word(s) using EERD
1069 * @hw: pointer to hardware structure
1070 * @offset: offset of word in the EEPROM to read
1071 * @words: number of word(s)
1072 * @data: 16 bit word(s) from the EEPROM
1074 * Reads a 16 bit word(s) from the EEPROM using the EERD register.
1076 s32 ixgbe_read_eerd_buffer_generic(struct ixgbe_hw *hw, u16 offset,
1077 u16 words, u16 *data)
1080 s32 status = IXGBE_SUCCESS;
1083 DEBUGFUNC("ixgbe_read_eerd_buffer_generic");
1085 hw->eeprom.ops.init_params(hw);
1088 status = IXGBE_ERR_INVALID_ARGUMENT;
1092 if (offset >= hw->eeprom.word_size) {
1093 status = IXGBE_ERR_EEPROM;
1097 for (i = 0; i < words; i++) {
1098 eerd = ((offset + i) << IXGBE_EEPROM_RW_ADDR_SHIFT) +
1099 IXGBE_EEPROM_RW_REG_START;
1101 IXGBE_WRITE_REG(hw, IXGBE_EERD, eerd);
1102 status = ixgbe_poll_eerd_eewr_done(hw, IXGBE_NVM_POLL_READ);
1104 if (status == IXGBE_SUCCESS) {
1105 data[i] = (IXGBE_READ_REG(hw, IXGBE_EERD) >>
1106 IXGBE_EEPROM_RW_REG_DATA);
1108 DEBUGOUT("Eeprom read timed out\n");
1117 * ixgbe_detect_eeprom_page_size_generic - Detect EEPROM page size
1118 * @hw: pointer to hardware structure
1119 * @offset: offset within the EEPROM to be used as a scratch pad
1121 * Discover EEPROM page size by writing marching data at given offset.
1122 * This function is called only when we are writing a new large buffer
1123 * at given offset so the data would be overwritten anyway.
1125 static s32 ixgbe_detect_eeprom_page_size_generic(struct ixgbe_hw *hw,
1128 u16 data[IXGBE_EEPROM_PAGE_SIZE_MAX];
1129 s32 status = IXGBE_SUCCESS;
1132 DEBUGFUNC("ixgbe_detect_eeprom_page_size_generic");
1134 for (i = 0; i < IXGBE_EEPROM_PAGE_SIZE_MAX; i++)
1137 hw->eeprom.word_page_size = IXGBE_EEPROM_PAGE_SIZE_MAX;
1138 status = ixgbe_write_eeprom_buffer_bit_bang(hw, offset,
1139 IXGBE_EEPROM_PAGE_SIZE_MAX, data);
1140 hw->eeprom.word_page_size = 0;
1141 if (status != IXGBE_SUCCESS)
1144 status = ixgbe_read_eeprom_buffer_bit_bang(hw, offset, 1, data);
1145 if (status != IXGBE_SUCCESS)
1149 * When writing in burst more than the actual page size
1150 * EEPROM address wraps around current page.
1152 hw->eeprom.word_page_size = IXGBE_EEPROM_PAGE_SIZE_MAX - data[0];
1154 DEBUGOUT1("Detected EEPROM page size = %d words.",
1155 hw->eeprom.word_page_size);
1161 * ixgbe_read_eerd_generic - Read EEPROM word using EERD
1162 * @hw: pointer to hardware structure
1163 * @offset: offset of word in the EEPROM to read
1164 * @data: word read from the EEPROM
1166 * Reads a 16 bit word from the EEPROM using the EERD register.
1168 s32 ixgbe_read_eerd_generic(struct ixgbe_hw *hw, u16 offset, u16 *data)
1170 return ixgbe_read_eerd_buffer_generic(hw, offset, 1, data);
1174 * ixgbe_write_eewr_buffer_generic - Write EEPROM word(s) using EEWR
1175 * @hw: pointer to hardware structure
1176 * @offset: offset of word in the EEPROM to write
1177 * @words: number of word(s)
1178 * @data: word(s) write to the EEPROM
1180 * Write a 16 bit word(s) to the EEPROM using the EEWR register.
1182 s32 ixgbe_write_eewr_buffer_generic(struct ixgbe_hw *hw, u16 offset,
1183 u16 words, u16 *data)
1186 s32 status = IXGBE_SUCCESS;
1189 DEBUGFUNC("ixgbe_write_eewr_generic");
1191 hw->eeprom.ops.init_params(hw);
1194 status = IXGBE_ERR_INVALID_ARGUMENT;
1198 if (offset >= hw->eeprom.word_size) {
1199 status = IXGBE_ERR_EEPROM;
1203 for (i = 0; i < words; i++) {
1204 eewr = ((offset + i) << IXGBE_EEPROM_RW_ADDR_SHIFT) |
1205 (data[i] << IXGBE_EEPROM_RW_REG_DATA) |
1206 IXGBE_EEPROM_RW_REG_START;
1208 status = ixgbe_poll_eerd_eewr_done(hw, IXGBE_NVM_POLL_WRITE);
1209 if (status != IXGBE_SUCCESS) {
1210 DEBUGOUT("Eeprom write EEWR timed out\n");
1214 IXGBE_WRITE_REG(hw, IXGBE_EEWR, eewr);
1216 status = ixgbe_poll_eerd_eewr_done(hw, IXGBE_NVM_POLL_WRITE);
1217 if (status != IXGBE_SUCCESS) {
1218 DEBUGOUT("Eeprom write EEWR timed out\n");
1228 * ixgbe_write_eewr_generic - Write EEPROM word using EEWR
1229 * @hw: pointer to hardware structure
1230 * @offset: offset of word in the EEPROM to write
1231 * @data: word write to the EEPROM
1233 * Write a 16 bit word to the EEPROM using the EEWR register.
1235 s32 ixgbe_write_eewr_generic(struct ixgbe_hw *hw, u16 offset, u16 data)
1237 return ixgbe_write_eewr_buffer_generic(hw, offset, 1, &data);
1241 * ixgbe_poll_eerd_eewr_done - Poll EERD read or EEWR write status
1242 * @hw: pointer to hardware structure
1243 * @ee_reg: EEPROM flag for polling
1245 * Polls the status bit (bit 1) of the EERD or EEWR to determine when the
1246 * read or write is done respectively.
1248 s32 ixgbe_poll_eerd_eewr_done(struct ixgbe_hw *hw, u32 ee_reg)
1252 s32 status = IXGBE_ERR_EEPROM;
1254 DEBUGFUNC("ixgbe_poll_eerd_eewr_done");
1256 for (i = 0; i < IXGBE_EERD_EEWR_ATTEMPTS; i++) {
1257 if (ee_reg == IXGBE_NVM_POLL_READ)
1258 reg = IXGBE_READ_REG(hw, IXGBE_EERD);
1260 reg = IXGBE_READ_REG(hw, IXGBE_EEWR);
1262 if (reg & IXGBE_EEPROM_RW_REG_DONE) {
1263 status = IXGBE_SUCCESS;
1272 * ixgbe_acquire_eeprom - Acquire EEPROM using bit-bang
1273 * @hw: pointer to hardware structure
1275 * Prepares EEPROM for access using bit-bang method. This function should
1276 * be called before issuing a command to the EEPROM.
1278 static s32 ixgbe_acquire_eeprom(struct ixgbe_hw *hw)
1280 s32 status = IXGBE_SUCCESS;
1284 DEBUGFUNC("ixgbe_acquire_eeprom");
1286 if (hw->mac.ops.acquire_swfw_sync(hw, IXGBE_GSSR_EEP_SM)
1288 status = IXGBE_ERR_SWFW_SYNC;
1290 if (status == IXGBE_SUCCESS) {
1291 eec = IXGBE_READ_REG(hw, IXGBE_EEC);
1293 /* Request EEPROM Access */
1294 eec |= IXGBE_EEC_REQ;
1295 IXGBE_WRITE_REG(hw, IXGBE_EEC, eec);
1297 for (i = 0; i < IXGBE_EEPROM_GRANT_ATTEMPTS; i++) {
1298 eec = IXGBE_READ_REG(hw, IXGBE_EEC);
1299 if (eec & IXGBE_EEC_GNT)
1304 /* Release if grant not acquired */
1305 if (!(eec & IXGBE_EEC_GNT)) {
1306 eec &= ~IXGBE_EEC_REQ;
1307 IXGBE_WRITE_REG(hw, IXGBE_EEC, eec);
1308 DEBUGOUT("Could not acquire EEPROM grant\n");
1310 hw->mac.ops.release_swfw_sync(hw, IXGBE_GSSR_EEP_SM);
1311 status = IXGBE_ERR_EEPROM;
1314 /* Setup EEPROM for Read/Write */
1315 if (status == IXGBE_SUCCESS) {
1316 /* Clear CS and SK */
1317 eec &= ~(IXGBE_EEC_CS | IXGBE_EEC_SK);
1318 IXGBE_WRITE_REG(hw, IXGBE_EEC, eec);
1319 IXGBE_WRITE_FLUSH(hw);
1327 * ixgbe_get_eeprom_semaphore - Get hardware semaphore
1328 * @hw: pointer to hardware structure
1330 * Sets the hardware semaphores so EEPROM access can occur for bit-bang method
1332 static s32 ixgbe_get_eeprom_semaphore(struct ixgbe_hw *hw)
1334 s32 status = IXGBE_ERR_EEPROM;
1339 DEBUGFUNC("ixgbe_get_eeprom_semaphore");
1342 /* Get SMBI software semaphore between device drivers first */
1343 for (i = 0; i < timeout; i++) {
1345 * If the SMBI bit is 0 when we read it, then the bit will be
1346 * set and we have the semaphore
1348 swsm = IXGBE_READ_REG(hw, IXGBE_SWSM);
1349 if (!(swsm & IXGBE_SWSM_SMBI)) {
1350 status = IXGBE_SUCCESS;
1357 DEBUGOUT("Driver can't access the Eeprom - SMBI Semaphore "
1360 * this release is particularly important because our attempts
1361 * above to get the semaphore may have succeeded, and if there
1362 * was a timeout, we should unconditionally clear the semaphore
1363 * bits to free the driver to make progress
1365 ixgbe_release_eeprom_semaphore(hw);
1370 * If the SMBI bit is 0 when we read it, then the bit will be
1371 * set and we have the semaphore
1373 swsm = IXGBE_READ_REG(hw, IXGBE_SWSM);
1374 if (!(swsm & IXGBE_SWSM_SMBI))
1375 status = IXGBE_SUCCESS;
1378 /* Now get the semaphore between SW/FW through the SWESMBI bit */
1379 if (status == IXGBE_SUCCESS) {
1380 for (i = 0; i < timeout; i++) {
1381 swsm = IXGBE_READ_REG(hw, IXGBE_SWSM);
1383 /* Set the SW EEPROM semaphore bit to request access */
1384 swsm |= IXGBE_SWSM_SWESMBI;
1385 IXGBE_WRITE_REG(hw, IXGBE_SWSM, swsm);
1388 * If we set the bit successfully then we got the
1391 swsm = IXGBE_READ_REG(hw, IXGBE_SWSM);
1392 if (swsm & IXGBE_SWSM_SWESMBI)
1399 * Release semaphores and return error if SW EEPROM semaphore
1400 * was not granted because we don't have access to the EEPROM
1403 DEBUGOUT("SWESMBI Software EEPROM semaphore "
1405 ixgbe_release_eeprom_semaphore(hw);
1406 status = IXGBE_ERR_EEPROM;
1409 DEBUGOUT("Software semaphore SMBI between device drivers "
1417 * ixgbe_release_eeprom_semaphore - Release hardware semaphore
1418 * @hw: pointer to hardware structure
1420 * This function clears hardware semaphore bits.
1422 static void ixgbe_release_eeprom_semaphore(struct ixgbe_hw *hw)
1426 DEBUGFUNC("ixgbe_release_eeprom_semaphore");
1428 swsm = IXGBE_READ_REG(hw, IXGBE_SWSM);
1430 /* Release both semaphores by writing 0 to the bits SWESMBI and SMBI */
1431 swsm &= ~(IXGBE_SWSM_SWESMBI | IXGBE_SWSM_SMBI);
1432 IXGBE_WRITE_REG(hw, IXGBE_SWSM, swsm);
1433 IXGBE_WRITE_FLUSH(hw);
1437 * ixgbe_ready_eeprom - Polls for EEPROM ready
1438 * @hw: pointer to hardware structure
1440 static s32 ixgbe_ready_eeprom(struct ixgbe_hw *hw)
1442 s32 status = IXGBE_SUCCESS;
1446 DEBUGFUNC("ixgbe_ready_eeprom");
1449 * Read "Status Register" repeatedly until the LSB is cleared. The
1450 * EEPROM will signal that the command has been completed by clearing
1451 * bit 0 of the internal status register. If it's not cleared within
1452 * 5 milliseconds, then error out.
1454 for (i = 0; i < IXGBE_EEPROM_MAX_RETRY_SPI; i += 5) {
1455 ixgbe_shift_out_eeprom_bits(hw, IXGBE_EEPROM_RDSR_OPCODE_SPI,
1456 IXGBE_EEPROM_OPCODE_BITS);
1457 spi_stat_reg = (u8)ixgbe_shift_in_eeprom_bits(hw, 8);
1458 if (!(spi_stat_reg & IXGBE_EEPROM_STATUS_RDY_SPI))
1462 ixgbe_standby_eeprom(hw);
1466 * On some parts, SPI write time could vary from 0-20mSec on 3.3V
1467 * devices (and only 0-5mSec on 5V devices)
1469 if (i >= IXGBE_EEPROM_MAX_RETRY_SPI) {
1470 DEBUGOUT("SPI EEPROM Status error\n");
1471 status = IXGBE_ERR_EEPROM;
1478 * ixgbe_standby_eeprom - Returns EEPROM to a "standby" state
1479 * @hw: pointer to hardware structure
1481 static void ixgbe_standby_eeprom(struct ixgbe_hw *hw)
1485 DEBUGFUNC("ixgbe_standby_eeprom");
1487 eec = IXGBE_READ_REG(hw, IXGBE_EEC);
1489 /* Toggle CS to flush commands */
1490 eec |= IXGBE_EEC_CS;
1491 IXGBE_WRITE_REG(hw, IXGBE_EEC, eec);
1492 IXGBE_WRITE_FLUSH(hw);
1494 eec &= ~IXGBE_EEC_CS;
1495 IXGBE_WRITE_REG(hw, IXGBE_EEC, eec);
1496 IXGBE_WRITE_FLUSH(hw);
1501 * ixgbe_shift_out_eeprom_bits - Shift data bits out to the EEPROM.
1502 * @hw: pointer to hardware structure
1503 * @data: data to send to the EEPROM
1504 * @count: number of bits to shift out
1506 static void ixgbe_shift_out_eeprom_bits(struct ixgbe_hw *hw, u16 data,
1513 DEBUGFUNC("ixgbe_shift_out_eeprom_bits");
1515 eec = IXGBE_READ_REG(hw, IXGBE_EEC);
1518 * Mask is used to shift "count" bits of "data" out to the EEPROM
1519 * one bit at a time. Determine the starting bit based on count
1521 mask = 0x01 << (count - 1);
1523 for (i = 0; i < count; i++) {
1525 * A "1" is shifted out to the EEPROM by setting bit "DI" to a
1526 * "1", and then raising and then lowering the clock (the SK
1527 * bit controls the clock input to the EEPROM). A "0" is
1528 * shifted out to the EEPROM by setting "DI" to "0" and then
1529 * raising and then lowering the clock.
1532 eec |= IXGBE_EEC_DI;
1534 eec &= ~IXGBE_EEC_DI;
1536 IXGBE_WRITE_REG(hw, IXGBE_EEC, eec);
1537 IXGBE_WRITE_FLUSH(hw);
1541 ixgbe_raise_eeprom_clk(hw, &eec);
1542 ixgbe_lower_eeprom_clk(hw, &eec);
1545 * Shift mask to signify next bit of data to shift in to the
1551 /* We leave the "DI" bit set to "0" when we leave this routine. */
1552 eec &= ~IXGBE_EEC_DI;
1553 IXGBE_WRITE_REG(hw, IXGBE_EEC, eec);
1554 IXGBE_WRITE_FLUSH(hw);
1558 * ixgbe_shift_in_eeprom_bits - Shift data bits in from the EEPROM
1559 * @hw: pointer to hardware structure
1561 static u16 ixgbe_shift_in_eeprom_bits(struct ixgbe_hw *hw, u16 count)
1567 DEBUGFUNC("ixgbe_shift_in_eeprom_bits");
1570 * In order to read a register from the EEPROM, we need to shift
1571 * 'count' bits in from the EEPROM. Bits are "shifted in" by raising
1572 * the clock input to the EEPROM (setting the SK bit), and then reading
1573 * the value of the "DO" bit. During this "shifting in" process the
1574 * "DI" bit should always be clear.
1576 eec = IXGBE_READ_REG(hw, IXGBE_EEC);
1578 eec &= ~(IXGBE_EEC_DO | IXGBE_EEC_DI);
1580 for (i = 0; i < count; i++) {
1582 ixgbe_raise_eeprom_clk(hw, &eec);
1584 eec = IXGBE_READ_REG(hw, IXGBE_EEC);
1586 eec &= ~(IXGBE_EEC_DI);
1587 if (eec & IXGBE_EEC_DO)
1590 ixgbe_lower_eeprom_clk(hw, &eec);
1597 * ixgbe_raise_eeprom_clk - Raises the EEPROM's clock input.
1598 * @hw: pointer to hardware structure
1599 * @eec: EEC register's current value
1601 static void ixgbe_raise_eeprom_clk(struct ixgbe_hw *hw, u32 *eec)
1603 DEBUGFUNC("ixgbe_raise_eeprom_clk");
1606 * Raise the clock input to the EEPROM
1607 * (setting the SK bit), then delay
1609 *eec = *eec | IXGBE_EEC_SK;
1610 IXGBE_WRITE_REG(hw, IXGBE_EEC, *eec);
1611 IXGBE_WRITE_FLUSH(hw);
1616 * ixgbe_lower_eeprom_clk - Lowers the EEPROM's clock input.
1617 * @hw: pointer to hardware structure
1618 * @eecd: EECD's current value
1620 static void ixgbe_lower_eeprom_clk(struct ixgbe_hw *hw, u32 *eec)
1622 DEBUGFUNC("ixgbe_lower_eeprom_clk");
1625 * Lower the clock input to the EEPROM (clearing the SK bit), then
1628 *eec = *eec & ~IXGBE_EEC_SK;
1629 IXGBE_WRITE_REG(hw, IXGBE_EEC, *eec);
1630 IXGBE_WRITE_FLUSH(hw);
1635 * ixgbe_release_eeprom - Release EEPROM, release semaphores
1636 * @hw: pointer to hardware structure
1638 static void ixgbe_release_eeprom(struct ixgbe_hw *hw)
1642 DEBUGFUNC("ixgbe_release_eeprom");
1644 eec = IXGBE_READ_REG(hw, IXGBE_EEC);
1646 eec |= IXGBE_EEC_CS; /* Pull CS high */
1647 eec &= ~IXGBE_EEC_SK; /* Lower SCK */
1649 IXGBE_WRITE_REG(hw, IXGBE_EEC, eec);
1650 IXGBE_WRITE_FLUSH(hw);
1654 /* Stop requesting EEPROM access */
1655 eec &= ~IXGBE_EEC_REQ;
1656 IXGBE_WRITE_REG(hw, IXGBE_EEC, eec);
1658 hw->mac.ops.release_swfw_sync(hw, IXGBE_GSSR_EEP_SM);
1660 /* Delay before attempt to obtain semaphore again to allow FW access */
1661 msec_delay(hw->eeprom.semaphore_delay);
1665 * ixgbe_calc_eeprom_checksum_generic - Calculates and returns the checksum
1666 * @hw: pointer to hardware structure
1668 u16 ixgbe_calc_eeprom_checksum_generic(struct ixgbe_hw *hw)
1677 DEBUGFUNC("ixgbe_calc_eeprom_checksum_generic");
1679 /* Include 0x0-0x3F in the checksum */
1680 for (i = 0; i < IXGBE_EEPROM_CHECKSUM; i++) {
1681 if (hw->eeprom.ops.read(hw, i, &word) != IXGBE_SUCCESS) {
1682 DEBUGOUT("EEPROM read failed\n");
1688 /* Include all data from pointers except for the fw pointer */
1689 for (i = IXGBE_PCIE_ANALOG_PTR; i < IXGBE_FW_PTR; i++) {
1690 hw->eeprom.ops.read(hw, i, &pointer);
1692 /* Make sure the pointer seems valid */
1693 if (pointer != 0xFFFF && pointer != 0) {
1694 hw->eeprom.ops.read(hw, pointer, &length);
1696 if (length != 0xFFFF && length != 0) {
1697 for (j = pointer+1; j <= pointer+length; j++) {
1698 hw->eeprom.ops.read(hw, j, &word);
1705 checksum = (u16)IXGBE_EEPROM_SUM - checksum;
1711 * ixgbe_validate_eeprom_checksum_generic - Validate EEPROM checksum
1712 * @hw: pointer to hardware structure
1713 * @checksum_val: calculated checksum
1715 * Performs checksum calculation and validates the EEPROM checksum. If the
1716 * caller does not need checksum_val, the value can be NULL.
1718 s32 ixgbe_validate_eeprom_checksum_generic(struct ixgbe_hw *hw,
1723 u16 read_checksum = 0;
1725 DEBUGFUNC("ixgbe_validate_eeprom_checksum_generic");
1728 * Read the first word from the EEPROM. If this times out or fails, do
1729 * not continue or we could be in for a very long wait while every
1732 status = hw->eeprom.ops.read(hw, 0, &checksum);
1734 if (status == IXGBE_SUCCESS) {
1735 checksum = hw->eeprom.ops.calc_checksum(hw);
1737 hw->eeprom.ops.read(hw, IXGBE_EEPROM_CHECKSUM, &read_checksum);
1740 * Verify read checksum from EEPROM is the same as
1741 * calculated checksum
1743 if (read_checksum != checksum)
1744 status = IXGBE_ERR_EEPROM_CHECKSUM;
1746 /* If the user cares, return the calculated checksum */
1748 *checksum_val = checksum;
1750 DEBUGOUT("EEPROM read failed\n");
1757 * ixgbe_update_eeprom_checksum_generic - Updates the EEPROM checksum
1758 * @hw: pointer to hardware structure
1760 s32 ixgbe_update_eeprom_checksum_generic(struct ixgbe_hw *hw)
1765 DEBUGFUNC("ixgbe_update_eeprom_checksum_generic");
1768 * Read the first word from the EEPROM. If this times out or fails, do
1769 * not continue or we could be in for a very long wait while every
1772 status = hw->eeprom.ops.read(hw, 0, &checksum);
1774 if (status == IXGBE_SUCCESS) {
1775 checksum = hw->eeprom.ops.calc_checksum(hw);
1776 status = hw->eeprom.ops.write(hw, IXGBE_EEPROM_CHECKSUM,
1779 DEBUGOUT("EEPROM read failed\n");
1786 * ixgbe_validate_mac_addr - Validate MAC address
1787 * @mac_addr: pointer to MAC address.
1789 * Tests a MAC address to ensure it is a valid Individual Address
1791 s32 ixgbe_validate_mac_addr(u8 *mac_addr)
1793 s32 status = IXGBE_SUCCESS;
1795 DEBUGFUNC("ixgbe_validate_mac_addr");
1797 /* Make sure it is not a multicast address */
1798 if (IXGBE_IS_MULTICAST(mac_addr)) {
1799 DEBUGOUT("MAC address is multicast\n");
1800 status = IXGBE_ERR_INVALID_MAC_ADDR;
1801 /* Not a broadcast address */
1802 } else if (IXGBE_IS_BROADCAST(mac_addr)) {
1803 DEBUGOUT("MAC address is broadcast\n");
1804 status = IXGBE_ERR_INVALID_MAC_ADDR;
1805 /* Reject the zero address */
1806 } else if (mac_addr[0] == 0 && mac_addr[1] == 0 && mac_addr[2] == 0 &&
1807 mac_addr[3] == 0 && mac_addr[4] == 0 && mac_addr[5] == 0) {
1808 DEBUGOUT("MAC address is all zeros\n");
1809 status = IXGBE_ERR_INVALID_MAC_ADDR;
1815 * ixgbe_set_rar_generic - Set Rx address register
1816 * @hw: pointer to hardware structure
1817 * @index: Receive address register to write
1818 * @addr: Address to put into receive address register
1819 * @vmdq: VMDq "set" or "pool" index
1820 * @enable_addr: set flag that address is active
1822 * Puts an ethernet address into a receive address register.
1824 s32 ixgbe_set_rar_generic(struct ixgbe_hw *hw, u32 index, u8 *addr, u32 vmdq,
1827 u32 rar_low, rar_high;
1828 u32 rar_entries = hw->mac.num_rar_entries;
1830 DEBUGFUNC("ixgbe_set_rar_generic");
1832 /* Make sure we are using a valid rar index range */
1833 if (index >= rar_entries) {
1834 DEBUGOUT1("RAR index %d is out of range.\n", index);
1835 return IXGBE_ERR_INVALID_ARGUMENT;
1838 /* setup VMDq pool selection before this RAR gets enabled */
1839 hw->mac.ops.set_vmdq(hw, index, vmdq);
1842 * HW expects these in little endian so we reverse the byte
1843 * order from network order (big endian) to little endian
1845 rar_low = ((u32)addr[0] |
1846 ((u32)addr[1] << 8) |
1847 ((u32)addr[2] << 16) |
1848 ((u32)addr[3] << 24));
1850 * Some parts put the VMDq setting in the extra RAH bits,
1851 * so save everything except the lower 16 bits that hold part
1852 * of the address and the address valid bit.
1854 rar_high = IXGBE_READ_REG(hw, IXGBE_RAH(index));
1855 rar_high &= ~(0x0000FFFF | IXGBE_RAH_AV);
1856 rar_high |= ((u32)addr[4] | ((u32)addr[5] << 8));
1858 if (enable_addr != 0)
1859 rar_high |= IXGBE_RAH_AV;
1861 IXGBE_WRITE_REG(hw, IXGBE_RAL(index), rar_low);
1862 IXGBE_WRITE_REG(hw, IXGBE_RAH(index), rar_high);
1864 return IXGBE_SUCCESS;
1868 * ixgbe_clear_rar_generic - Remove Rx address register
1869 * @hw: pointer to hardware structure
1870 * @index: Receive address register to write
1872 * Clears an ethernet address from a receive address register.
1874 s32 ixgbe_clear_rar_generic(struct ixgbe_hw *hw, u32 index)
1877 u32 rar_entries = hw->mac.num_rar_entries;
1879 DEBUGFUNC("ixgbe_clear_rar_generic");
1881 /* Make sure we are using a valid rar index range */
1882 if (index >= rar_entries) {
1883 DEBUGOUT1("RAR index %d is out of range.\n", index);
1884 return IXGBE_ERR_INVALID_ARGUMENT;
1888 * Some parts put the VMDq setting in the extra RAH bits,
1889 * so save everything except the lower 16 bits that hold part
1890 * of the address and the address valid bit.
1892 rar_high = IXGBE_READ_REG(hw, IXGBE_RAH(index));
1893 rar_high &= ~(0x0000FFFF | IXGBE_RAH_AV);
1895 IXGBE_WRITE_REG(hw, IXGBE_RAL(index), 0);
1896 IXGBE_WRITE_REG(hw, IXGBE_RAH(index), rar_high);
1898 /* clear VMDq pool/queue selection for this RAR */
1899 hw->mac.ops.clear_vmdq(hw, index, IXGBE_CLEAR_VMDQ_ALL);
1901 return IXGBE_SUCCESS;
1905 * ixgbe_init_rx_addrs_generic - Initializes receive address filters.
1906 * @hw: pointer to hardware structure
1908 * Places the MAC address in receive address register 0 and clears the rest
1909 * of the receive address registers. Clears the multicast table. Assumes
1910 * the receiver is in reset when the routine is called.
1912 s32 ixgbe_init_rx_addrs_generic(struct ixgbe_hw *hw)
1915 u32 rar_entries = hw->mac.num_rar_entries;
1917 DEBUGFUNC("ixgbe_init_rx_addrs_generic");
1920 * If the current mac address is valid, assume it is a software override
1921 * to the permanent address.
1922 * Otherwise, use the permanent address from the eeprom.
1924 if (ixgbe_validate_mac_addr(hw->mac.addr) ==
1925 IXGBE_ERR_INVALID_MAC_ADDR) {
1926 /* Get the MAC address from the RAR0 for later reference */
1927 hw->mac.ops.get_mac_addr(hw, hw->mac.addr);
1929 DEBUGOUT3(" Keeping Current RAR0 Addr =%.2X %.2X %.2X ",
1930 hw->mac.addr[0], hw->mac.addr[1],
1932 DEBUGOUT3("%.2X %.2X %.2X\n", hw->mac.addr[3],
1933 hw->mac.addr[4], hw->mac.addr[5]);
1935 /* Setup the receive address. */
1936 DEBUGOUT("Overriding MAC Address in RAR[0]\n");
1937 DEBUGOUT3(" New MAC Addr =%.2X %.2X %.2X ",
1938 hw->mac.addr[0], hw->mac.addr[1],
1940 DEBUGOUT3("%.2X %.2X %.2X\n", hw->mac.addr[3],
1941 hw->mac.addr[4], hw->mac.addr[5]);
1943 hw->mac.ops.set_rar(hw, 0, hw->mac.addr, 0, IXGBE_RAH_AV);
1945 /* clear VMDq pool/queue selection for RAR 0 */
1946 hw->mac.ops.clear_vmdq(hw, 0, IXGBE_CLEAR_VMDQ_ALL);
1948 hw->addr_ctrl.overflow_promisc = 0;
1950 hw->addr_ctrl.rar_used_count = 1;
1952 /* Zero out the other receive addresses. */
1953 DEBUGOUT1("Clearing RAR[1-%d]\n", rar_entries - 1);
1954 for (i = 1; i < rar_entries; i++) {
1955 IXGBE_WRITE_REG(hw, IXGBE_RAL(i), 0);
1956 IXGBE_WRITE_REG(hw, IXGBE_RAH(i), 0);
1960 hw->addr_ctrl.mta_in_use = 0;
1961 IXGBE_WRITE_REG(hw, IXGBE_MCSTCTRL, hw->mac.mc_filter_type);
1963 DEBUGOUT(" Clearing MTA\n");
1964 for (i = 0; i < hw->mac.mcft_size; i++)
1965 IXGBE_WRITE_REG(hw, IXGBE_MTA(i), 0);
1967 ixgbe_init_uta_tables(hw);
1969 return IXGBE_SUCCESS;
1973 * ixgbe_add_uc_addr - Adds a secondary unicast address.
1974 * @hw: pointer to hardware structure
1975 * @addr: new address
1977 * Adds it to unused receive address register or goes into promiscuous mode.
1979 void ixgbe_add_uc_addr(struct ixgbe_hw *hw, u8 *addr, u32 vmdq)
1981 u32 rar_entries = hw->mac.num_rar_entries;
1984 DEBUGFUNC("ixgbe_add_uc_addr");
1986 DEBUGOUT6(" UC Addr = %.2X %.2X %.2X %.2X %.2X %.2X\n",
1987 addr[0], addr[1], addr[2], addr[3], addr[4], addr[5]);
1990 * Place this address in the RAR if there is room,
1991 * else put the controller into promiscuous mode
1993 if (hw->addr_ctrl.rar_used_count < rar_entries) {
1994 rar = hw->addr_ctrl.rar_used_count;
1995 hw->mac.ops.set_rar(hw, rar, addr, vmdq, IXGBE_RAH_AV);
1996 DEBUGOUT1("Added a secondary address to RAR[%d]\n", rar);
1997 hw->addr_ctrl.rar_used_count++;
1999 hw->addr_ctrl.overflow_promisc++;
2002 DEBUGOUT("ixgbe_add_uc_addr Complete\n");
2006 * ixgbe_update_uc_addr_list_generic - Updates MAC list of secondary addresses
2007 * @hw: pointer to hardware structure
2008 * @addr_list: the list of new addresses
2009 * @addr_count: number of addresses
2010 * @next: iterator function to walk the address list
2012 * The given list replaces any existing list. Clears the secondary addrs from
2013 * receive address registers. Uses unused receive address registers for the
2014 * first secondary addresses, and falls back to promiscuous mode as needed.
2016 * Drivers using secondary unicast addresses must set user_set_promisc when
2017 * manually putting the device into promiscuous mode.
2019 s32 ixgbe_update_uc_addr_list_generic(struct ixgbe_hw *hw, u8 *addr_list,
2020 u32 addr_count, ixgbe_mc_addr_itr next)
2024 u32 old_promisc_setting = hw->addr_ctrl.overflow_promisc;
2029 DEBUGFUNC("ixgbe_update_uc_addr_list_generic");
2032 * Clear accounting of old secondary address list,
2033 * don't count RAR[0]
2035 uc_addr_in_use = hw->addr_ctrl.rar_used_count - 1;
2036 hw->addr_ctrl.rar_used_count -= uc_addr_in_use;
2037 hw->addr_ctrl.overflow_promisc = 0;
2039 /* Zero out the other receive addresses */
2040 DEBUGOUT1("Clearing RAR[1-%d]\n", uc_addr_in_use+1);
2041 for (i = 0; i < uc_addr_in_use; i++) {
2042 IXGBE_WRITE_REG(hw, IXGBE_RAL(1+i), 0);
2043 IXGBE_WRITE_REG(hw, IXGBE_RAH(1+i), 0);
2046 /* Add the new addresses */
2047 for (i = 0; i < addr_count; i++) {
2048 DEBUGOUT(" Adding the secondary addresses:\n");
2049 addr = next(hw, &addr_list, &vmdq);
2050 ixgbe_add_uc_addr(hw, addr, vmdq);
2053 if (hw->addr_ctrl.overflow_promisc) {
2054 /* enable promisc if not already in overflow or set by user */
2055 if (!old_promisc_setting && !hw->addr_ctrl.user_set_promisc) {
2056 DEBUGOUT(" Entering address overflow promisc mode\n");
2057 fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
2058 fctrl |= IXGBE_FCTRL_UPE;
2059 IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
2062 /* only disable if set by overflow, not by user */
2063 if (old_promisc_setting && !hw->addr_ctrl.user_set_promisc) {
2064 DEBUGOUT(" Leaving address overflow promisc mode\n");
2065 fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
2066 fctrl &= ~IXGBE_FCTRL_UPE;
2067 IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
2071 DEBUGOUT("ixgbe_update_uc_addr_list_generic Complete\n");
2072 return IXGBE_SUCCESS;
2076 * ixgbe_mta_vector - Determines bit-vector in multicast table to set
2077 * @hw: pointer to hardware structure
2078 * @mc_addr: the multicast address
2080 * Extracts the 12 bits, from a multicast address, to determine which
2081 * bit-vector to set in the multicast table. The hardware uses 12 bits, from
2082 * incoming rx multicast addresses, to determine the bit-vector to check in
2083 * the MTA. Which of the 4 combination, of 12-bits, the hardware uses is set
2084 * by the MO field of the MCSTCTRL. The MO field is set during initialization
2085 * to mc_filter_type.
2087 static s32 ixgbe_mta_vector(struct ixgbe_hw *hw, u8 *mc_addr)
2091 DEBUGFUNC("ixgbe_mta_vector");
2093 switch (hw->mac.mc_filter_type) {
2094 case 0: /* use bits [47:36] of the address */
2095 vector = ((mc_addr[4] >> 4) | (((u16)mc_addr[5]) << 4));
2097 case 1: /* use bits [46:35] of the address */
2098 vector = ((mc_addr[4] >> 3) | (((u16)mc_addr[5]) << 5));
2100 case 2: /* use bits [45:34] of the address */
2101 vector = ((mc_addr[4] >> 2) | (((u16)mc_addr[5]) << 6));
2103 case 3: /* use bits [43:32] of the address */
2104 vector = ((mc_addr[4]) | (((u16)mc_addr[5]) << 8));
2106 default: /* Invalid mc_filter_type */
2107 DEBUGOUT("MC filter type param set incorrectly\n");
2112 /* vector can only be 12-bits or boundary will be exceeded */
2118 * ixgbe_set_mta - Set bit-vector in multicast table
2119 * @hw: pointer to hardware structure
2120 * @hash_value: Multicast address hash value
2122 * Sets the bit-vector in the multicast table.
2124 void ixgbe_set_mta(struct ixgbe_hw *hw, u8 *mc_addr)
2130 DEBUGFUNC("ixgbe_set_mta");
2132 hw->addr_ctrl.mta_in_use++;
2134 vector = ixgbe_mta_vector(hw, mc_addr);
2135 DEBUGOUT1(" bit-vector = 0x%03X\n", vector);
2138 * The MTA is a register array of 128 32-bit registers. It is treated
2139 * like an array of 4096 bits. We want to set bit
2140 * BitArray[vector_value]. So we figure out what register the bit is
2141 * in, read it, OR in the new bit, then write back the new value. The
2142 * register is determined by the upper 7 bits of the vector value and
2143 * the bit within that register are determined by the lower 5 bits of
2146 vector_reg = (vector >> 5) & 0x7F;
2147 vector_bit = vector & 0x1F;
2148 hw->mac.mta_shadow[vector_reg] |= (1 << vector_bit);
2152 * ixgbe_update_mc_addr_list_generic - Updates MAC list of multicast addresses
2153 * @hw: pointer to hardware structure
2154 * @mc_addr_list: the list of new multicast addresses
2155 * @mc_addr_count: number of addresses
2156 * @next: iterator function to walk the multicast address list
2157 * @clear: flag, when set clears the table beforehand
2159 * When the clear flag is set, the given list replaces any existing list.
2160 * Hashes the given addresses into the multicast table.
2162 s32 ixgbe_update_mc_addr_list_generic(struct ixgbe_hw *hw, u8 *mc_addr_list,
2163 u32 mc_addr_count, ixgbe_mc_addr_itr next,
2169 DEBUGFUNC("ixgbe_update_mc_addr_list_generic");
2172 * Set the new number of MC addresses that we are being requested to
2175 hw->addr_ctrl.num_mc_addrs = mc_addr_count;
2176 hw->addr_ctrl.mta_in_use = 0;
2178 /* Clear mta_shadow */
2180 DEBUGOUT(" Clearing MTA\n");
2181 memset(&hw->mac.mta_shadow, 0, sizeof(hw->mac.mta_shadow));
2184 /* Update mta_shadow */
2185 for (i = 0; i < mc_addr_count; i++) {
2186 DEBUGOUT(" Adding the multicast addresses:\n");
2187 ixgbe_set_mta(hw, next(hw, &mc_addr_list, &vmdq));
2191 for (i = 0; i < hw->mac.mcft_size; i++)
2192 IXGBE_WRITE_REG_ARRAY(hw, IXGBE_MTA(0), i,
2193 hw->mac.mta_shadow[i]);
2195 if (hw->addr_ctrl.mta_in_use > 0)
2196 IXGBE_WRITE_REG(hw, IXGBE_MCSTCTRL,
2197 IXGBE_MCSTCTRL_MFE | hw->mac.mc_filter_type);
2199 DEBUGOUT("ixgbe_update_mc_addr_list_generic Complete\n");
2200 return IXGBE_SUCCESS;
2204 * ixgbe_enable_mc_generic - Enable multicast address in RAR
2205 * @hw: pointer to hardware structure
2207 * Enables multicast address in RAR and the use of the multicast hash table.
2209 s32 ixgbe_enable_mc_generic(struct ixgbe_hw *hw)
2211 struct ixgbe_addr_filter_info *a = &hw->addr_ctrl;
2213 DEBUGFUNC("ixgbe_enable_mc_generic");
2215 if (a->mta_in_use > 0)
2216 IXGBE_WRITE_REG(hw, IXGBE_MCSTCTRL, IXGBE_MCSTCTRL_MFE |
2217 hw->mac.mc_filter_type);
2219 return IXGBE_SUCCESS;
2223 * ixgbe_disable_mc_generic - Disable multicast address in RAR
2224 * @hw: pointer to hardware structure
2226 * Disables multicast address in RAR and the use of the multicast hash table.
2228 s32 ixgbe_disable_mc_generic(struct ixgbe_hw *hw)
2230 struct ixgbe_addr_filter_info *a = &hw->addr_ctrl;
2232 DEBUGFUNC("ixgbe_disable_mc_generic");
2234 if (a->mta_in_use > 0)
2235 IXGBE_WRITE_REG(hw, IXGBE_MCSTCTRL, hw->mac.mc_filter_type);
2237 return IXGBE_SUCCESS;
2241 * ixgbe_fc_enable_generic - Enable flow control
2242 * @hw: pointer to hardware structure
2243 * @packetbuf_num: packet buffer number (0-7)
2245 * Enable flow control according to the current settings.
2247 s32 ixgbe_fc_enable_generic(struct ixgbe_hw *hw, s32 packetbuf_num)
2249 s32 ret_val = IXGBE_SUCCESS;
2250 u32 mflcn_reg, fccfg_reg;
2254 DEBUGFUNC("ixgbe_fc_enable_generic");
2256 /* Negotiate the fc mode to use */
2257 ret_val = ixgbe_fc_autoneg(hw);
2258 if (ret_val == IXGBE_ERR_FLOW_CONTROL)
2261 /* Disable any previous flow control settings */
2262 mflcn_reg = IXGBE_READ_REG(hw, IXGBE_MFLCN);
2263 mflcn_reg &= ~(IXGBE_MFLCN_RFCE | IXGBE_MFLCN_RPFCE);
2265 fccfg_reg = IXGBE_READ_REG(hw, IXGBE_FCCFG);
2266 fccfg_reg &= ~(IXGBE_FCCFG_TFCE_802_3X | IXGBE_FCCFG_TFCE_PRIORITY);
2269 * The possible values of fc.current_mode are:
2270 * 0: Flow control is completely disabled
2271 * 1: Rx flow control is enabled (we can receive pause frames,
2272 * but not send pause frames).
2273 * 2: Tx flow control is enabled (we can send pause frames but
2274 * we do not support receiving pause frames).
2275 * 3: Both Rx and Tx flow control (symmetric) are enabled.
2278 switch (hw->fc.current_mode) {
2281 * Flow control is disabled by software override or autoneg.
2282 * The code below will actually disable it in the HW.
2285 case ixgbe_fc_rx_pause:
2287 * Rx Flow control is enabled and Tx Flow control is
2288 * disabled by software override. Since there really
2289 * isn't a way to advertise that we are capable of RX
2290 * Pause ONLY, we will advertise that we support both
2291 * symmetric and asymmetric Rx PAUSE. Later, we will
2292 * disable the adapter's ability to send PAUSE frames.
2294 mflcn_reg |= IXGBE_MFLCN_RFCE;
2296 case ixgbe_fc_tx_pause:
2298 * Tx Flow control is enabled, and Rx Flow control is
2299 * disabled by software override.
2301 fccfg_reg |= IXGBE_FCCFG_TFCE_802_3X;
2304 /* Flow control (both Rx and Tx) is enabled by SW override. */
2305 mflcn_reg |= IXGBE_MFLCN_RFCE;
2306 fccfg_reg |= IXGBE_FCCFG_TFCE_802_3X;
2309 DEBUGOUT("Flow control param set incorrectly\n");
2310 ret_val = IXGBE_ERR_CONFIG;
2315 /* Set 802.3x based flow control settings. */
2316 mflcn_reg |= IXGBE_MFLCN_DPF;
2317 IXGBE_WRITE_REG(hw, IXGBE_MFLCN, mflcn_reg);
2318 IXGBE_WRITE_REG(hw, IXGBE_FCCFG, fccfg_reg);
2320 fcrth = hw->fc.high_water[packetbuf_num] << 10;
2321 fcrtl = hw->fc.low_water << 10;
2323 if (hw->fc.current_mode & ixgbe_fc_tx_pause) {
2324 fcrth |= IXGBE_FCRTH_FCEN;
2325 if (hw->fc.send_xon)
2326 fcrtl |= IXGBE_FCRTL_XONE;
2329 IXGBE_WRITE_REG(hw, IXGBE_FCRTH_82599(packetbuf_num), fcrth);
2330 IXGBE_WRITE_REG(hw, IXGBE_FCRTL_82599(packetbuf_num), fcrtl);
2332 /* Configure pause time (2 TCs per register) */
2333 reg = IXGBE_READ_REG(hw, IXGBE_FCTTV(packetbuf_num / 2));
2334 if ((packetbuf_num & 1) == 0)
2335 reg = (reg & 0xFFFF0000) | hw->fc.pause_time;
2337 reg = (reg & 0x0000FFFF) | (hw->fc.pause_time << 16);
2338 IXGBE_WRITE_REG(hw, IXGBE_FCTTV(packetbuf_num / 2), reg);
2340 IXGBE_WRITE_REG(hw, IXGBE_FCRTV, (hw->fc.pause_time >> 1));
2347 * ixgbe_fc_autoneg - Configure flow control
2348 * @hw: pointer to hardware structure
2350 * Compares our advertised flow control capabilities to those advertised by
2351 * our link partner, and determines the proper flow control mode to use.
2353 s32 ixgbe_fc_autoneg(struct ixgbe_hw *hw)
2355 s32 ret_val = IXGBE_ERR_FC_NOT_NEGOTIATED;
2356 ixgbe_link_speed speed;
2359 DEBUGFUNC("ixgbe_fc_autoneg");
2361 if (hw->fc.disable_fc_autoneg)
2365 * AN should have completed when the cable was plugged in.
2366 * Look for reasons to bail out. Bail out if:
2367 * - FC autoneg is disabled, or if
2370 * Since we're being called from an LSC, link is already known to be up.
2371 * So use link_up_wait_to_complete=FALSE.
2373 hw->mac.ops.check_link(hw, &speed, &link_up, FALSE);
2375 ret_val = IXGBE_ERR_FLOW_CONTROL;
2379 switch (hw->phy.media_type) {
2380 /* Autoneg flow control on fiber adapters */
2381 case ixgbe_media_type_fiber:
2382 if (speed == IXGBE_LINK_SPEED_1GB_FULL)
2383 ret_val = ixgbe_fc_autoneg_fiber(hw);
2386 /* Autoneg flow control on backplane adapters */
2387 case ixgbe_media_type_backplane:
2388 ret_val = ixgbe_fc_autoneg_backplane(hw);
2391 /* Autoneg flow control on copper adapters */
2392 case ixgbe_media_type_copper:
2393 if (ixgbe_device_supports_autoneg_fc(hw) == IXGBE_SUCCESS)
2394 ret_val = ixgbe_fc_autoneg_copper(hw);
2402 if (ret_val == IXGBE_SUCCESS) {
2403 hw->fc.fc_was_autonegged = TRUE;
2405 hw->fc.fc_was_autonegged = FALSE;
2406 hw->fc.current_mode = hw->fc.requested_mode;
2412 * ixgbe_fc_autoneg_fiber - Enable flow control on 1 gig fiber
2413 * @hw: pointer to hardware structure
2415 * Enable flow control according on 1 gig fiber.
2417 static s32 ixgbe_fc_autoneg_fiber(struct ixgbe_hw *hw)
2419 u32 pcs_anadv_reg, pcs_lpab_reg, linkstat;
2423 * On multispeed fiber at 1g, bail out if
2424 * - link is up but AN did not complete, or if
2425 * - link is up and AN completed but timed out
2428 linkstat = IXGBE_READ_REG(hw, IXGBE_PCS1GLSTA);
2429 if ((!!(linkstat & IXGBE_PCS1GLSTA_AN_COMPLETE) == 0) ||
2430 (!!(linkstat & IXGBE_PCS1GLSTA_AN_TIMED_OUT) == 1)) {
2431 ret_val = IXGBE_ERR_FC_NOT_NEGOTIATED;
2435 pcs_anadv_reg = IXGBE_READ_REG(hw, IXGBE_PCS1GANA);
2436 pcs_lpab_reg = IXGBE_READ_REG(hw, IXGBE_PCS1GANLP);
2438 ret_val = ixgbe_negotiate_fc(hw, pcs_anadv_reg,
2439 pcs_lpab_reg, IXGBE_PCS1GANA_SYM_PAUSE,
2440 IXGBE_PCS1GANA_ASM_PAUSE,
2441 IXGBE_PCS1GANA_SYM_PAUSE,
2442 IXGBE_PCS1GANA_ASM_PAUSE);
2449 * ixgbe_fc_autoneg_backplane - Enable flow control IEEE clause 37
2450 * @hw: pointer to hardware structure
2452 * Enable flow control according to IEEE clause 37.
2454 static s32 ixgbe_fc_autoneg_backplane(struct ixgbe_hw *hw)
2456 u32 links2, anlp1_reg, autoc_reg, links;
2460 * On backplane, bail out if
2461 * - backplane autoneg was not completed, or if
2462 * - we are 82599 and link partner is not AN enabled
2464 links = IXGBE_READ_REG(hw, IXGBE_LINKS);
2465 if ((links & IXGBE_LINKS_KX_AN_COMP) == 0) {
2466 hw->fc.fc_was_autonegged = FALSE;
2467 hw->fc.current_mode = hw->fc.requested_mode;
2468 ret_val = IXGBE_ERR_FC_NOT_NEGOTIATED;
2472 if (hw->mac.type == ixgbe_mac_82599EB) {
2473 links2 = IXGBE_READ_REG(hw, IXGBE_LINKS2);
2474 if ((links2 & IXGBE_LINKS2_AN_SUPPORTED) == 0) {
2475 hw->fc.fc_was_autonegged = FALSE;
2476 hw->fc.current_mode = hw->fc.requested_mode;
2477 ret_val = IXGBE_ERR_FC_NOT_NEGOTIATED;
2482 * Read the 10g AN autoc and LP ability registers and resolve
2483 * local flow control settings accordingly
2485 autoc_reg = IXGBE_READ_REG(hw, IXGBE_AUTOC);
2486 anlp1_reg = IXGBE_READ_REG(hw, IXGBE_ANLP1);
2488 ret_val = ixgbe_negotiate_fc(hw, autoc_reg,
2489 anlp1_reg, IXGBE_AUTOC_SYM_PAUSE, IXGBE_AUTOC_ASM_PAUSE,
2490 IXGBE_ANLP1_SYM_PAUSE, IXGBE_ANLP1_ASM_PAUSE);
2497 * ixgbe_fc_autoneg_copper - Enable flow control IEEE clause 37
2498 * @hw: pointer to hardware structure
2500 * Enable flow control according to IEEE clause 37.
2502 static s32 ixgbe_fc_autoneg_copper(struct ixgbe_hw *hw)
2504 u16 technology_ability_reg = 0;
2505 u16 lp_technology_ability_reg = 0;
2507 hw->phy.ops.read_reg(hw, IXGBE_MDIO_AUTO_NEG_ADVT,
2508 IXGBE_MDIO_AUTO_NEG_DEV_TYPE,
2509 &technology_ability_reg);
2510 hw->phy.ops.read_reg(hw, IXGBE_MDIO_AUTO_NEG_LP,
2511 IXGBE_MDIO_AUTO_NEG_DEV_TYPE,
2512 &lp_technology_ability_reg);
2514 return ixgbe_negotiate_fc(hw, (u32)technology_ability_reg,
2515 (u32)lp_technology_ability_reg,
2516 IXGBE_TAF_SYM_PAUSE, IXGBE_TAF_ASM_PAUSE,
2517 IXGBE_TAF_SYM_PAUSE, IXGBE_TAF_ASM_PAUSE);
2521 * ixgbe_negotiate_fc - Negotiate flow control
2522 * @hw: pointer to hardware structure
2523 * @adv_reg: flow control advertised settings
2524 * @lp_reg: link partner's flow control settings
2525 * @adv_sym: symmetric pause bit in advertisement
2526 * @adv_asm: asymmetric pause bit in advertisement
2527 * @lp_sym: symmetric pause bit in link partner advertisement
2528 * @lp_asm: asymmetric pause bit in link partner advertisement
2530 * Find the intersection between advertised settings and link partner's
2531 * advertised settings
2533 static s32 ixgbe_negotiate_fc(struct ixgbe_hw *hw, u32 adv_reg, u32 lp_reg,
2534 u32 adv_sym, u32 adv_asm, u32 lp_sym, u32 lp_asm)
2536 if ((!(adv_reg)) || (!(lp_reg)))
2537 return IXGBE_ERR_FC_NOT_NEGOTIATED;
2539 if ((adv_reg & adv_sym) && (lp_reg & lp_sym)) {
2541 * Now we need to check if the user selected Rx ONLY
2542 * of pause frames. In this case, we had to advertise
2543 * FULL flow control because we could not advertise RX
2544 * ONLY. Hence, we must now check to see if we need to
2545 * turn OFF the TRANSMISSION of PAUSE frames.
2547 if (hw->fc.requested_mode == ixgbe_fc_full) {
2548 hw->fc.current_mode = ixgbe_fc_full;
2549 DEBUGOUT("Flow Control = FULL.\n");
2551 hw->fc.current_mode = ixgbe_fc_rx_pause;
2552 DEBUGOUT("Flow Control=RX PAUSE frames only\n");
2554 } else if (!(adv_reg & adv_sym) && (adv_reg & adv_asm) &&
2555 (lp_reg & lp_sym) && (lp_reg & lp_asm)) {
2556 hw->fc.current_mode = ixgbe_fc_tx_pause;
2557 DEBUGOUT("Flow Control = TX PAUSE frames only.\n");
2558 } else if ((adv_reg & adv_sym) && (adv_reg & adv_asm) &&
2559 !(lp_reg & lp_sym) && (lp_reg & lp_asm)) {
2560 hw->fc.current_mode = ixgbe_fc_rx_pause;
2561 DEBUGOUT("Flow Control = RX PAUSE frames only.\n");
2563 hw->fc.current_mode = ixgbe_fc_none;
2564 DEBUGOUT("Flow Control = NONE.\n");
2566 return IXGBE_SUCCESS;
2570 * ixgbe_setup_fc - Set up flow control
2571 * @hw: pointer to hardware structure
2573 * Called at init time to set up flow control.
2575 static s32 ixgbe_setup_fc(struct ixgbe_hw *hw, s32 packetbuf_num)
2577 s32 ret_val = IXGBE_SUCCESS;
2578 u32 reg = 0, reg_bp = 0;
2581 DEBUGFUNC("ixgbe_setup_fc");
2583 /* Validate the packetbuf configuration */
2584 if (packetbuf_num < 0 || packetbuf_num > 7) {
2585 DEBUGOUT1("Invalid packet buffer number [%d], expected range "
2586 "is 0-7\n", packetbuf_num);
2587 ret_val = IXGBE_ERR_INVALID_LINK_SETTINGS;
2592 * Validate the water mark configuration. Zero water marks are invalid
2593 * because it causes the controller to just blast out fc packets.
2595 if (!hw->fc.low_water ||
2596 !hw->fc.high_water[packetbuf_num] ||
2597 !hw->fc.pause_time) {
2598 DEBUGOUT("Invalid water mark configuration\n");
2599 ret_val = IXGBE_ERR_INVALID_LINK_SETTINGS;
2604 * Validate the requested mode. Strict IEEE mode does not allow
2605 * ixgbe_fc_rx_pause because it will cause us to fail at UNH.
2607 if (hw->fc.strict_ieee && hw->fc.requested_mode == ixgbe_fc_rx_pause) {
2608 DEBUGOUT("ixgbe_fc_rx_pause not valid in strict IEEE mode\n");
2609 ret_val = IXGBE_ERR_INVALID_LINK_SETTINGS;
2614 * 10gig parts do not have a word in the EEPROM to determine the
2615 * default flow control setting, so we explicitly set it to full.
2617 if (hw->fc.requested_mode == ixgbe_fc_default)
2618 hw->fc.requested_mode = ixgbe_fc_full;
2621 * Set up the 1G and 10G flow control advertisement registers so the
2622 * HW will be able to do fc autoneg once the cable is plugged in. If
2623 * we link at 10G, the 1G advertisement is harmless and vice versa.
2626 switch (hw->phy.media_type) {
2627 case ixgbe_media_type_fiber:
2628 case ixgbe_media_type_backplane:
2629 reg = IXGBE_READ_REG(hw, IXGBE_PCS1GANA);
2630 reg_bp = IXGBE_READ_REG(hw, IXGBE_AUTOC);
2633 case ixgbe_media_type_copper:
2634 hw->phy.ops.read_reg(hw, IXGBE_MDIO_AUTO_NEG_ADVT,
2635 IXGBE_MDIO_AUTO_NEG_DEV_TYPE, ®_cu);
2643 * The possible values of fc.requested_mode are:
2644 * 0: Flow control is completely disabled
2645 * 1: Rx flow control is enabled (we can receive pause frames,
2646 * but not send pause frames).
2647 * 2: Tx flow control is enabled (we can send pause frames but
2648 * we do not support receiving pause frames).
2649 * 3: Both Rx and Tx flow control (symmetric) are enabled.
2652 switch (hw->fc.requested_mode) {
2654 /* Flow control completely disabled by software override. */
2655 reg &= ~(IXGBE_PCS1GANA_SYM_PAUSE | IXGBE_PCS1GANA_ASM_PAUSE);
2656 if (hw->phy.media_type == ixgbe_media_type_backplane)
2657 reg_bp &= ~(IXGBE_AUTOC_SYM_PAUSE |
2658 IXGBE_AUTOC_ASM_PAUSE);
2659 else if (hw->phy.media_type == ixgbe_media_type_copper)
2660 reg_cu &= ~(IXGBE_TAF_SYM_PAUSE | IXGBE_TAF_ASM_PAUSE);
2662 case ixgbe_fc_rx_pause:
2664 * Rx Flow control is enabled and Tx Flow control is
2665 * disabled by software override. Since there really
2666 * isn't a way to advertise that we are capable of RX
2667 * Pause ONLY, we will advertise that we support both
2668 * symmetric and asymmetric Rx PAUSE. Later, we will
2669 * disable the adapter's ability to send PAUSE frames.
2671 reg |= (IXGBE_PCS1GANA_SYM_PAUSE | IXGBE_PCS1GANA_ASM_PAUSE);
2672 if (hw->phy.media_type == ixgbe_media_type_backplane)
2673 reg_bp |= (IXGBE_AUTOC_SYM_PAUSE |
2674 IXGBE_AUTOC_ASM_PAUSE);
2675 else if (hw->phy.media_type == ixgbe_media_type_copper)
2676 reg_cu |= (IXGBE_TAF_SYM_PAUSE | IXGBE_TAF_ASM_PAUSE);
2678 case ixgbe_fc_tx_pause:
2680 * Tx Flow control is enabled, and Rx Flow control is
2681 * disabled by software override.
2683 reg |= (IXGBE_PCS1GANA_ASM_PAUSE);
2684 reg &= ~(IXGBE_PCS1GANA_SYM_PAUSE);
2685 if (hw->phy.media_type == ixgbe_media_type_backplane) {
2686 reg_bp |= (IXGBE_AUTOC_ASM_PAUSE);
2687 reg_bp &= ~(IXGBE_AUTOC_SYM_PAUSE);
2688 } else if (hw->phy.media_type == ixgbe_media_type_copper) {
2689 reg_cu |= (IXGBE_TAF_ASM_PAUSE);
2690 reg_cu &= ~(IXGBE_TAF_SYM_PAUSE);
2694 /* Flow control (both Rx and Tx) is enabled by SW override. */
2695 reg |= (IXGBE_PCS1GANA_SYM_PAUSE | IXGBE_PCS1GANA_ASM_PAUSE);
2696 if (hw->phy.media_type == ixgbe_media_type_backplane)
2697 reg_bp |= (IXGBE_AUTOC_SYM_PAUSE |
2698 IXGBE_AUTOC_ASM_PAUSE);
2699 else if (hw->phy.media_type == ixgbe_media_type_copper)
2700 reg_cu |= (IXGBE_TAF_SYM_PAUSE | IXGBE_TAF_ASM_PAUSE);
2703 DEBUGOUT("Flow control param set incorrectly\n");
2704 ret_val = IXGBE_ERR_CONFIG;
2709 if (hw->mac.type != ixgbe_mac_X540) {
2711 * Enable auto-negotiation between the MAC & PHY;
2712 * the MAC will advertise clause 37 flow control.
2714 IXGBE_WRITE_REG(hw, IXGBE_PCS1GANA, reg);
2715 reg = IXGBE_READ_REG(hw, IXGBE_PCS1GLCTL);
2717 /* Disable AN timeout */
2718 if (hw->fc.strict_ieee)
2719 reg &= ~IXGBE_PCS1GLCTL_AN_1G_TIMEOUT_EN;
2721 IXGBE_WRITE_REG(hw, IXGBE_PCS1GLCTL, reg);
2722 DEBUGOUT1("Set up FC; PCS1GLCTL = 0x%08X\n", reg);
2726 * AUTOC restart handles negotiation of 1G and 10G on backplane
2727 * and copper. There is no need to set the PCS1GCTL register.
2730 if (hw->phy.media_type == ixgbe_media_type_backplane) {
2731 reg_bp |= IXGBE_AUTOC_AN_RESTART;
2732 IXGBE_WRITE_REG(hw, IXGBE_AUTOC, reg_bp);
2733 } else if ((hw->phy.media_type == ixgbe_media_type_copper) &&
2734 (ixgbe_device_supports_autoneg_fc(hw) == IXGBE_SUCCESS)) {
2735 hw->phy.ops.write_reg(hw, IXGBE_MDIO_AUTO_NEG_ADVT,
2736 IXGBE_MDIO_AUTO_NEG_DEV_TYPE, reg_cu);
2739 DEBUGOUT1("Set up FC; IXGBE_AUTOC = 0x%08X\n", reg);
2745 * ixgbe_disable_pcie_master - Disable PCI-express master access
2746 * @hw: pointer to hardware structure
2748 * Disables PCI-Express master access and verifies there are no pending
2749 * requests. IXGBE_ERR_MASTER_REQUESTS_PENDING is returned if master disable
2750 * bit hasn't caused the master requests to be disabled, else IXGBE_SUCCESS
2751 * is returned signifying master requests disabled.
2753 s32 ixgbe_disable_pcie_master(struct ixgbe_hw *hw)
2755 s32 status = IXGBE_SUCCESS;
2758 DEBUGFUNC("ixgbe_disable_pcie_master");
2760 /* Always set this bit to ensure any future transactions are blocked */
2761 IXGBE_WRITE_REG(hw, IXGBE_CTRL, IXGBE_CTRL_GIO_DIS);
2763 /* Exit if master requets are blocked */
2764 if (!(IXGBE_READ_REG(hw, IXGBE_STATUS) & IXGBE_STATUS_GIO))
2767 /* Poll for master request bit to clear */
2768 for (i = 0; i < IXGBE_PCI_MASTER_DISABLE_TIMEOUT; i++) {
2770 if (!(IXGBE_READ_REG(hw, IXGBE_STATUS) & IXGBE_STATUS_GIO))
2775 * Two consecutive resets are required via CTRL.RST per datasheet
2776 * 5.2.5.3.2 Master Disable. We set a flag to inform the reset routine
2777 * of this need. The first reset prevents new master requests from
2778 * being issued by our device. We then must wait 1usec or more for any
2779 * remaining completions from the PCIe bus to trickle in, and then reset
2780 * again to clear out any effects they may have had on our device.
2782 DEBUGOUT("GIO Master Disable bit didn't clear - requesting resets\n");
2783 hw->mac.flags |= IXGBE_FLAGS_DOUBLE_RESET_REQUIRED;
2786 * Before proceeding, make sure that the PCIe block does not have
2787 * transactions pending.
2789 for (i = 0; i < IXGBE_PCI_MASTER_DISABLE_TIMEOUT; i++) {
2791 if (!(IXGBE_READ_PCIE_WORD(hw, IXGBE_PCI_DEVICE_STATUS) &
2792 IXGBE_PCI_DEVICE_STATUS_TRANSACTION_PENDING))
2796 DEBUGOUT("PCIe transaction pending bit also did not clear.\n");
2797 status = IXGBE_ERR_MASTER_REQUESTS_PENDING;
2804 * ixgbe_acquire_swfw_sync - Acquire SWFW semaphore
2805 * @hw: pointer to hardware structure
2806 * @mask: Mask to specify which semaphore to acquire
2808 * Acquires the SWFW semaphore through the GSSR register for the specified
2809 * function (CSR, PHY0, PHY1, EEPROM, Flash)
2811 s32 ixgbe_acquire_swfw_sync(struct ixgbe_hw *hw, u16 mask)
2815 u32 fwmask = mask << 5;
2818 DEBUGFUNC("ixgbe_acquire_swfw_sync");
2822 * SW EEPROM semaphore bit is used for access to all
2823 * SW_FW_SYNC/GSSR bits (not just EEPROM)
2825 if (ixgbe_get_eeprom_semaphore(hw))
2826 return IXGBE_ERR_SWFW_SYNC;
2828 gssr = IXGBE_READ_REG(hw, IXGBE_GSSR);
2829 if (!(gssr & (fwmask | swmask)))
2833 * Firmware currently using resource (fwmask) or other software
2834 * thread currently using resource (swmask)
2836 ixgbe_release_eeprom_semaphore(hw);
2842 DEBUGOUT("Driver can't access resource, SW_FW_SYNC timeout.\n");
2843 return IXGBE_ERR_SWFW_SYNC;
2847 IXGBE_WRITE_REG(hw, IXGBE_GSSR, gssr);
2849 ixgbe_release_eeprom_semaphore(hw);
2850 return IXGBE_SUCCESS;
2854 * ixgbe_release_swfw_sync - Release SWFW semaphore
2855 * @hw: pointer to hardware structure
2856 * @mask: Mask to specify which semaphore to release
2858 * Releases the SWFW semaphore through the GSSR register for the specified
2859 * function (CSR, PHY0, PHY1, EEPROM, Flash)
2861 void ixgbe_release_swfw_sync(struct ixgbe_hw *hw, u16 mask)
2866 DEBUGFUNC("ixgbe_release_swfw_sync");
2868 ixgbe_get_eeprom_semaphore(hw);
2870 gssr = IXGBE_READ_REG(hw, IXGBE_GSSR);
2872 IXGBE_WRITE_REG(hw, IXGBE_GSSR, gssr);
2874 ixgbe_release_eeprom_semaphore(hw);
2878 * ixgbe_enable_rx_dma_generic - Enable the Rx DMA unit
2879 * @hw: pointer to hardware structure
2880 * @regval: register value to write to RXCTRL
2882 * Enables the Rx DMA unit
2884 s32 ixgbe_enable_rx_dma_generic(struct ixgbe_hw *hw, u32 regval)
2886 DEBUGFUNC("ixgbe_enable_rx_dma_generic");
2888 IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, regval);
2890 return IXGBE_SUCCESS;
2894 * ixgbe_blink_led_start_generic - Blink LED based on index.
2895 * @hw: pointer to hardware structure
2896 * @index: led number to blink
2898 s32 ixgbe_blink_led_start_generic(struct ixgbe_hw *hw, u32 index)
2900 ixgbe_link_speed speed = 0;
2902 u32 autoc_reg = IXGBE_READ_REG(hw, IXGBE_AUTOC);
2903 u32 led_reg = IXGBE_READ_REG(hw, IXGBE_LEDCTL);
2905 DEBUGFUNC("ixgbe_blink_led_start_generic");
2908 * Link must be up to auto-blink the LEDs;
2909 * Force it if link is down.
2911 hw->mac.ops.check_link(hw, &speed, &link_up, FALSE);
2914 autoc_reg |= IXGBE_AUTOC_AN_RESTART;
2915 autoc_reg |= IXGBE_AUTOC_FLU;
2916 IXGBE_WRITE_REG(hw, IXGBE_AUTOC, autoc_reg);
2917 IXGBE_WRITE_FLUSH(hw);
2921 led_reg &= ~IXGBE_LED_MODE_MASK(index);
2922 led_reg |= IXGBE_LED_BLINK(index);
2923 IXGBE_WRITE_REG(hw, IXGBE_LEDCTL, led_reg);
2924 IXGBE_WRITE_FLUSH(hw);
2926 return IXGBE_SUCCESS;
2930 * ixgbe_blink_led_stop_generic - Stop blinking LED based on index.
2931 * @hw: pointer to hardware structure
2932 * @index: led number to stop blinking
2934 s32 ixgbe_blink_led_stop_generic(struct ixgbe_hw *hw, u32 index)
2936 u32 autoc_reg = IXGBE_READ_REG(hw, IXGBE_AUTOC);
2937 u32 led_reg = IXGBE_READ_REG(hw, IXGBE_LEDCTL);
2939 DEBUGFUNC("ixgbe_blink_led_stop_generic");
2942 autoc_reg &= ~IXGBE_AUTOC_FLU;
2943 autoc_reg |= IXGBE_AUTOC_AN_RESTART;
2944 IXGBE_WRITE_REG(hw, IXGBE_AUTOC, autoc_reg);
2946 led_reg &= ~IXGBE_LED_MODE_MASK(index);
2947 led_reg &= ~IXGBE_LED_BLINK(index);
2948 led_reg |= IXGBE_LED_LINK_ACTIVE << IXGBE_LED_MODE_SHIFT(index);
2949 IXGBE_WRITE_REG(hw, IXGBE_LEDCTL, led_reg);
2950 IXGBE_WRITE_FLUSH(hw);
2952 return IXGBE_SUCCESS;
2956 * ixgbe_get_san_mac_addr_offset - Get SAN MAC address offset from the EEPROM
2957 * @hw: pointer to hardware structure
2958 * @san_mac_offset: SAN MAC address offset
2960 * This function will read the EEPROM location for the SAN MAC address
2961 * pointer, and returns the value at that location. This is used in both
2962 * get and set mac_addr routines.
2964 static s32 ixgbe_get_san_mac_addr_offset(struct ixgbe_hw *hw,
2965 u16 *san_mac_offset)
2967 DEBUGFUNC("ixgbe_get_san_mac_addr_offset");
2970 * First read the EEPROM pointer to see if the MAC addresses are
2973 hw->eeprom.ops.read(hw, IXGBE_SAN_MAC_ADDR_PTR, san_mac_offset);
2975 return IXGBE_SUCCESS;
2979 * ixgbe_get_san_mac_addr_generic - SAN MAC address retrieval from the EEPROM
2980 * @hw: pointer to hardware structure
2981 * @san_mac_addr: SAN MAC address
2983 * Reads the SAN MAC address from the EEPROM, if it's available. This is
2984 * per-port, so set_lan_id() must be called before reading the addresses.
2985 * set_lan_id() is called by identify_sfp(), but this cannot be relied
2986 * upon for non-SFP connections, so we must call it here.
2988 s32 ixgbe_get_san_mac_addr_generic(struct ixgbe_hw *hw, u8 *san_mac_addr)
2990 u16 san_mac_data, san_mac_offset;
2993 DEBUGFUNC("ixgbe_get_san_mac_addr_generic");
2996 * First read the EEPROM pointer to see if the MAC addresses are
2997 * available. If they're not, no point in calling set_lan_id() here.
2999 ixgbe_get_san_mac_addr_offset(hw, &san_mac_offset);
3001 if ((san_mac_offset == 0) || (san_mac_offset == 0xFFFF)) {
3003 * No addresses available in this EEPROM. It's not an
3004 * error though, so just wipe the local address and return.
3006 for (i = 0; i < 6; i++)
3007 san_mac_addr[i] = 0xFF;
3009 goto san_mac_addr_out;
3012 /* make sure we know which port we need to program */
3013 hw->mac.ops.set_lan_id(hw);
3014 /* apply the port offset to the address offset */
3015 (hw->bus.func) ? (san_mac_offset += IXGBE_SAN_MAC_ADDR_PORT1_OFFSET) :
3016 (san_mac_offset += IXGBE_SAN_MAC_ADDR_PORT0_OFFSET);
3017 for (i = 0; i < 3; i++) {
3018 hw->eeprom.ops.read(hw, san_mac_offset, &san_mac_data);
3019 san_mac_addr[i * 2] = (u8)(san_mac_data);
3020 san_mac_addr[i * 2 + 1] = (u8)(san_mac_data >> 8);
3025 return IXGBE_SUCCESS;
3029 * ixgbe_set_san_mac_addr_generic - Write the SAN MAC address to the EEPROM
3030 * @hw: pointer to hardware structure
3031 * @san_mac_addr: SAN MAC address
3033 * Write a SAN MAC address to the EEPROM.
3035 s32 ixgbe_set_san_mac_addr_generic(struct ixgbe_hw *hw, u8 *san_mac_addr)
3037 s32 status = IXGBE_SUCCESS;
3038 u16 san_mac_data, san_mac_offset;
3041 DEBUGFUNC("ixgbe_set_san_mac_addr_generic");
3043 /* Look for SAN mac address pointer. If not defined, return */
3044 ixgbe_get_san_mac_addr_offset(hw, &san_mac_offset);
3046 if ((san_mac_offset == 0) || (san_mac_offset == 0xFFFF)) {
3047 status = IXGBE_ERR_NO_SAN_ADDR_PTR;
3048 goto san_mac_addr_out;
3051 /* Make sure we know which port we need to write */
3052 hw->mac.ops.set_lan_id(hw);
3053 /* Apply the port offset to the address offset */
3054 (hw->bus.func) ? (san_mac_offset += IXGBE_SAN_MAC_ADDR_PORT1_OFFSET) :
3055 (san_mac_offset += IXGBE_SAN_MAC_ADDR_PORT0_OFFSET);
3057 for (i = 0; i < 3; i++) {
3058 san_mac_data = (u16)((u16)(san_mac_addr[i * 2 + 1]) << 8);
3059 san_mac_data |= (u16)(san_mac_addr[i * 2]);
3060 hw->eeprom.ops.write(hw, san_mac_offset, san_mac_data);
3069 * ixgbe_get_pcie_msix_count_generic - Gets MSI-X vector count
3070 * @hw: pointer to hardware structure
3072 * Read PCIe configuration space, and get the MSI-X vector count from
3073 * the capabilities table.
3075 u32 ixgbe_get_pcie_msix_count_generic(struct ixgbe_hw *hw)
3077 u32 msix_count = 64;
3079 DEBUGFUNC("ixgbe_get_pcie_msix_count_generic");
3080 if (hw->mac.msix_vectors_from_pcie) {
3081 msix_count = IXGBE_READ_PCIE_WORD(hw,
3082 IXGBE_PCIE_MSIX_82599_CAPS);
3083 msix_count &= IXGBE_PCIE_MSIX_TBL_SZ_MASK;
3085 /* MSI-X count is zero-based in HW, so increment to give
3094 * ixgbe_insert_mac_addr_generic - Find a RAR for this mac address
3095 * @hw: pointer to hardware structure
3096 * @addr: Address to put into receive address register
3097 * @vmdq: VMDq pool to assign
3099 * Puts an ethernet address into a receive address register, or
3100 * finds the rar that it is aleady in; adds to the pool list
3102 s32 ixgbe_insert_mac_addr_generic(struct ixgbe_hw *hw, u8 *addr, u32 vmdq)
3104 static const u32 NO_EMPTY_RAR_FOUND = 0xFFFFFFFF;
3105 u32 first_empty_rar = NO_EMPTY_RAR_FOUND;
3107 u32 rar_low, rar_high;
3108 u32 addr_low, addr_high;
3110 DEBUGFUNC("ixgbe_insert_mac_addr_generic");
3112 /* swap bytes for HW little endian */
3113 addr_low = addr[0] | (addr[1] << 8)
3116 addr_high = addr[4] | (addr[5] << 8);
3119 * Either find the mac_id in rar or find the first empty space.
3120 * rar_highwater points to just after the highest currently used
3121 * rar in order to shorten the search. It grows when we add a new
3124 for (rar = 0; rar < hw->mac.rar_highwater; rar++) {
3125 rar_high = IXGBE_READ_REG(hw, IXGBE_RAH(rar));
3127 if (((IXGBE_RAH_AV & rar_high) == 0)
3128 && first_empty_rar == NO_EMPTY_RAR_FOUND) {
3129 first_empty_rar = rar;
3130 } else if ((rar_high & 0xFFFF) == addr_high) {
3131 rar_low = IXGBE_READ_REG(hw, IXGBE_RAL(rar));
3132 if (rar_low == addr_low)
3133 break; /* found it already in the rars */
3137 if (rar < hw->mac.rar_highwater) {
3138 /* already there so just add to the pool bits */
3139 ixgbe_set_vmdq(hw, rar, vmdq);
3140 } else if (first_empty_rar != NO_EMPTY_RAR_FOUND) {
3141 /* stick it into first empty RAR slot we found */
3142 rar = first_empty_rar;
3143 ixgbe_set_rar(hw, rar, addr, vmdq, IXGBE_RAH_AV);
3144 } else if (rar == hw->mac.rar_highwater) {
3145 /* add it to the top of the list and inc the highwater mark */
3146 ixgbe_set_rar(hw, rar, addr, vmdq, IXGBE_RAH_AV);
3147 hw->mac.rar_highwater++;
3148 } else if (rar >= hw->mac.num_rar_entries) {
3149 return IXGBE_ERR_INVALID_MAC_ADDR;
3153 * If we found rar[0], make sure the default pool bit (we use pool 0)
3154 * remains cleared to be sure default pool packets will get delivered
3157 ixgbe_clear_vmdq(hw, rar, 0);
3163 * ixgbe_clear_vmdq_generic - Disassociate a VMDq pool index from a rx address
3164 * @hw: pointer to hardware struct
3165 * @rar: receive address register index to disassociate
3166 * @vmdq: VMDq pool index to remove from the rar
3168 s32 ixgbe_clear_vmdq_generic(struct ixgbe_hw *hw, u32 rar, u32 vmdq)
3170 u32 mpsar_lo, mpsar_hi;
3171 u32 rar_entries = hw->mac.num_rar_entries;
3173 DEBUGFUNC("ixgbe_clear_vmdq_generic");
3175 /* Make sure we are using a valid rar index range */
3176 if (rar >= rar_entries) {
3177 DEBUGOUT1("RAR index %d is out of range.\n", rar);
3178 return IXGBE_ERR_INVALID_ARGUMENT;
3181 mpsar_lo = IXGBE_READ_REG(hw, IXGBE_MPSAR_LO(rar));
3182 mpsar_hi = IXGBE_READ_REG(hw, IXGBE_MPSAR_HI(rar));
3184 if (!mpsar_lo && !mpsar_hi)
3187 if (vmdq == IXGBE_CLEAR_VMDQ_ALL) {
3189 IXGBE_WRITE_REG(hw, IXGBE_MPSAR_LO(rar), 0);
3193 IXGBE_WRITE_REG(hw, IXGBE_MPSAR_HI(rar), 0);
3196 } else if (vmdq < 32) {
3197 mpsar_lo &= ~(1 << vmdq);
3198 IXGBE_WRITE_REG(hw, IXGBE_MPSAR_LO(rar), mpsar_lo);
3200 mpsar_hi &= ~(1 << (vmdq - 32));
3201 IXGBE_WRITE_REG(hw, IXGBE_MPSAR_HI(rar), mpsar_hi);
3204 /* was that the last pool using this rar? */
3205 if (mpsar_lo == 0 && mpsar_hi == 0 && rar != 0)
3206 hw->mac.ops.clear_rar(hw, rar);
3208 return IXGBE_SUCCESS;
3212 * ixgbe_set_vmdq_generic - Associate a VMDq pool index with a rx address
3213 * @hw: pointer to hardware struct
3214 * @rar: receive address register index to associate with a VMDq index
3215 * @vmdq: VMDq pool index
3217 s32 ixgbe_set_vmdq_generic(struct ixgbe_hw *hw, u32 rar, u32 vmdq)
3220 u32 rar_entries = hw->mac.num_rar_entries;
3222 DEBUGFUNC("ixgbe_set_vmdq_generic");
3224 /* Make sure we are using a valid rar index range */
3225 if (rar >= rar_entries) {
3226 DEBUGOUT1("RAR index %d is out of range.\n", rar);
3227 return IXGBE_ERR_INVALID_ARGUMENT;
3231 mpsar = IXGBE_READ_REG(hw, IXGBE_MPSAR_LO(rar));
3233 IXGBE_WRITE_REG(hw, IXGBE_MPSAR_LO(rar), mpsar);
3235 mpsar = IXGBE_READ_REG(hw, IXGBE_MPSAR_HI(rar));
3236 mpsar |= 1 << (vmdq - 32);
3237 IXGBE_WRITE_REG(hw, IXGBE_MPSAR_HI(rar), mpsar);
3239 return IXGBE_SUCCESS;
3243 * ixgbe_init_uta_tables_generic - Initialize the Unicast Table Array
3244 * @hw: pointer to hardware structure
3246 s32 ixgbe_init_uta_tables_generic(struct ixgbe_hw *hw)
3250 DEBUGFUNC("ixgbe_init_uta_tables_generic");
3251 DEBUGOUT(" Clearing UTA\n");
3253 for (i = 0; i < 128; i++)
3254 IXGBE_WRITE_REG(hw, IXGBE_UTA(i), 0);
3256 return IXGBE_SUCCESS;
3260 * ixgbe_find_vlvf_slot - find the vlanid or the first empty slot
3261 * @hw: pointer to hardware structure
3262 * @vlan: VLAN id to write to VLAN filter
3264 * return the VLVF index where this VLAN id should be placed
3267 s32 ixgbe_find_vlvf_slot(struct ixgbe_hw *hw, u32 vlan)
3270 u32 first_empty_slot = 0;
3273 /* short cut the special case */
3278 * Search for the vlan id in the VLVF entries. Save off the first empty
3279 * slot found along the way
3281 for (regindex = 1; regindex < IXGBE_VLVF_ENTRIES; regindex++) {
3282 bits = IXGBE_READ_REG(hw, IXGBE_VLVF(regindex));
3283 if (!bits && !(first_empty_slot))
3284 first_empty_slot = regindex;
3285 else if ((bits & 0x0FFF) == vlan)
3290 * If regindex is less than IXGBE_VLVF_ENTRIES, then we found the vlan
3291 * in the VLVF. Else use the first empty VLVF register for this
3294 if (regindex >= IXGBE_VLVF_ENTRIES) {
3295 if (first_empty_slot)
3296 regindex = first_empty_slot;
3298 DEBUGOUT("No space in VLVF.\n");
3299 regindex = IXGBE_ERR_NO_SPACE;
3307 * ixgbe_set_vfta_generic - Set VLAN filter table
3308 * @hw: pointer to hardware structure
3309 * @vlan: VLAN id to write to VLAN filter
3310 * @vind: VMDq output index that maps queue to VLAN id in VFVFB
3311 * @vlan_on: boolean flag to turn on/off VLAN in VFVF
3313 * Turn on/off specified VLAN in the VLAN filter table.
3315 s32 ixgbe_set_vfta_generic(struct ixgbe_hw *hw, u32 vlan, u32 vind,
3324 bool vfta_changed = FALSE;
3326 DEBUGFUNC("ixgbe_set_vfta_generic");
3329 return IXGBE_ERR_PARAM;
3332 * this is a 2 part operation - first the VFTA, then the
3333 * VLVF and VLVFB if VT Mode is set
3334 * We don't write the VFTA until we know the VLVF part succeeded.
3338 * The VFTA is a bitstring made up of 128 32-bit registers
3339 * that enable the particular VLAN id, much like the MTA:
3340 * bits[11-5]: which register
3341 * bits[4-0]: which bit in the register
3343 regindex = (vlan >> 5) & 0x7F;
3344 bitindex = vlan & 0x1F;
3345 targetbit = (1 << bitindex);
3346 vfta = IXGBE_READ_REG(hw, IXGBE_VFTA(regindex));
3349 if (!(vfta & targetbit)) {
3351 vfta_changed = TRUE;
3354 if ((vfta & targetbit)) {
3356 vfta_changed = TRUE;
3363 * make sure the vlan is in VLVF
3364 * set the vind bit in the matching VLVFB
3366 * clear the pool bit and possibly the vind
3368 vt = IXGBE_READ_REG(hw, IXGBE_VT_CTL);
3369 if (vt & IXGBE_VT_CTL_VT_ENABLE) {
3372 vlvf_index = ixgbe_find_vlvf_slot(hw, vlan);
3377 /* set the pool bit */
3379 bits = IXGBE_READ_REG(hw,
3380 IXGBE_VLVFB(vlvf_index*2));
3381 bits |= (1 << vind);
3383 IXGBE_VLVFB(vlvf_index*2),
3386 bits = IXGBE_READ_REG(hw,
3387 IXGBE_VLVFB((vlvf_index*2)+1));
3388 bits |= (1 << (vind-32));
3390 IXGBE_VLVFB((vlvf_index*2)+1),
3394 /* clear the pool bit */
3396 bits = IXGBE_READ_REG(hw,
3397 IXGBE_VLVFB(vlvf_index*2));
3398 bits &= ~(1 << vind);
3400 IXGBE_VLVFB(vlvf_index*2),
3402 bits |= IXGBE_READ_REG(hw,
3403 IXGBE_VLVFB((vlvf_index*2)+1));
3405 bits = IXGBE_READ_REG(hw,
3406 IXGBE_VLVFB((vlvf_index*2)+1));
3407 bits &= ~(1 << (vind-32));
3409 IXGBE_VLVFB((vlvf_index*2)+1),
3411 bits |= IXGBE_READ_REG(hw,
3412 IXGBE_VLVFB(vlvf_index*2));
3417 * If there are still bits set in the VLVFB registers
3418 * for the VLAN ID indicated we need to see if the
3419 * caller is requesting that we clear the VFTA entry bit.
3420 * If the caller has requested that we clear the VFTA
3421 * entry bit but there are still pools/VFs using this VLAN
3422 * ID entry then ignore the request. We're not worried
3423 * about the case where we're turning the VFTA VLAN ID
3424 * entry bit on, only when requested to turn it off as
3425 * there may be multiple pools and/or VFs using the
3426 * VLAN ID entry. In that case we cannot clear the
3427 * VFTA bit until all pools/VFs using that VLAN ID have also
3428 * been cleared. This will be indicated by "bits" being
3432 IXGBE_WRITE_REG(hw, IXGBE_VLVF(vlvf_index),
3433 (IXGBE_VLVF_VIEN | vlan));
3435 /* someone wants to clear the vfta entry
3436 * but some pools/VFs are still using it.
3438 vfta_changed = FALSE;
3442 IXGBE_WRITE_REG(hw, IXGBE_VLVF(vlvf_index), 0);
3446 IXGBE_WRITE_REG(hw, IXGBE_VFTA(regindex), vfta);
3448 return IXGBE_SUCCESS;
3452 * ixgbe_clear_vfta_generic - Clear VLAN filter table
3453 * @hw: pointer to hardware structure
3455 * Clears the VLAN filer table, and the VMDq index associated with the filter
3457 s32 ixgbe_clear_vfta_generic(struct ixgbe_hw *hw)
3461 DEBUGFUNC("ixgbe_clear_vfta_generic");
3463 for (offset = 0; offset < hw->mac.vft_size; offset++)
3464 IXGBE_WRITE_REG(hw, IXGBE_VFTA(offset), 0);
3466 for (offset = 0; offset < IXGBE_VLVF_ENTRIES; offset++) {
3467 IXGBE_WRITE_REG(hw, IXGBE_VLVF(offset), 0);
3468 IXGBE_WRITE_REG(hw, IXGBE_VLVFB(offset*2), 0);
3469 IXGBE_WRITE_REG(hw, IXGBE_VLVFB((offset*2)+1), 0);
3472 return IXGBE_SUCCESS;
3476 * ixgbe_check_mac_link_generic - Determine link and speed status
3477 * @hw: pointer to hardware structure
3478 * @speed: pointer to link speed
3479 * @link_up: TRUE when link is up
3480 * @link_up_wait_to_complete: bool used to wait for link up or not
3482 * Reads the links register to determine if link is up and the current speed
3484 s32 ixgbe_check_mac_link_generic(struct ixgbe_hw *hw, ixgbe_link_speed *speed,
3485 bool *link_up, bool link_up_wait_to_complete)
3487 u32 links_reg, links_orig;
3490 DEBUGFUNC("ixgbe_check_mac_link_generic");
3492 /* clear the old state */
3493 links_orig = IXGBE_READ_REG(hw, IXGBE_LINKS);
3495 links_reg = IXGBE_READ_REG(hw, IXGBE_LINKS);
3497 if (links_orig != links_reg) {
3498 DEBUGOUT2("LINKS changed from %08X to %08X\n",
3499 links_orig, links_reg);
3502 if (link_up_wait_to_complete) {
3503 for (i = 0; i < IXGBE_LINK_UP_TIME; i++) {
3504 if (links_reg & IXGBE_LINKS_UP) {
3511 links_reg = IXGBE_READ_REG(hw, IXGBE_LINKS);
3514 if (links_reg & IXGBE_LINKS_UP)
3520 if ((links_reg & IXGBE_LINKS_SPEED_82599) ==
3521 IXGBE_LINKS_SPEED_10G_82599)
3522 *speed = IXGBE_LINK_SPEED_10GB_FULL;
3523 else if ((links_reg & IXGBE_LINKS_SPEED_82599) ==
3524 IXGBE_LINKS_SPEED_1G_82599)
3525 *speed = IXGBE_LINK_SPEED_1GB_FULL;
3526 else if ((links_reg & IXGBE_LINKS_SPEED_82599) ==
3527 IXGBE_LINKS_SPEED_100_82599)
3528 *speed = IXGBE_LINK_SPEED_100_FULL;
3530 *speed = IXGBE_LINK_SPEED_UNKNOWN;
3532 /* if link is down, zero out the current_mode */
3533 if (*link_up == FALSE) {
3534 hw->fc.current_mode = ixgbe_fc_none;
3535 hw->fc.fc_was_autonegged = FALSE;
3538 return IXGBE_SUCCESS;
3542 * ixgbe_get_wwn_prefix_generic - Get alternative WWNN/WWPN prefix from
3544 * @hw: pointer to hardware structure
3545 * @wwnn_prefix: the alternative WWNN prefix
3546 * @wwpn_prefix: the alternative WWPN prefix
3548 * This function will read the EEPROM from the alternative SAN MAC address
3549 * block to check the support for the alternative WWNN/WWPN prefix support.
3551 s32 ixgbe_get_wwn_prefix_generic(struct ixgbe_hw *hw, u16 *wwnn_prefix,
3555 u16 alt_san_mac_blk_offset;
3557 DEBUGFUNC("ixgbe_get_wwn_prefix_generic");
3559 /* clear output first */
3560 *wwnn_prefix = 0xFFFF;
3561 *wwpn_prefix = 0xFFFF;
3563 /* check if alternative SAN MAC is supported */
3564 hw->eeprom.ops.read(hw, IXGBE_ALT_SAN_MAC_ADDR_BLK_PTR,
3565 &alt_san_mac_blk_offset);
3567 if ((alt_san_mac_blk_offset == 0) ||
3568 (alt_san_mac_blk_offset == 0xFFFF))
3569 goto wwn_prefix_out;
3571 /* check capability in alternative san mac address block */
3572 offset = alt_san_mac_blk_offset + IXGBE_ALT_SAN_MAC_ADDR_CAPS_OFFSET;
3573 hw->eeprom.ops.read(hw, offset, &caps);
3574 if (!(caps & IXGBE_ALT_SAN_MAC_ADDR_CAPS_ALTWWN))
3575 goto wwn_prefix_out;
3577 /* get the corresponding prefix for WWNN/WWPN */
3578 offset = alt_san_mac_blk_offset + IXGBE_ALT_SAN_MAC_ADDR_WWNN_OFFSET;
3579 hw->eeprom.ops.read(hw, offset, wwnn_prefix);
3581 offset = alt_san_mac_blk_offset + IXGBE_ALT_SAN_MAC_ADDR_WWPN_OFFSET;
3582 hw->eeprom.ops.read(hw, offset, wwpn_prefix);
3585 return IXGBE_SUCCESS;
3589 * ixgbe_get_fcoe_boot_status_generic - Get FCOE boot status from EEPROM
3590 * @hw: pointer to hardware structure
3591 * @bs: the fcoe boot status
3593 * This function will read the FCOE boot status from the iSCSI FCOE block
3595 s32 ixgbe_get_fcoe_boot_status_generic(struct ixgbe_hw *hw, u16 *bs)
3597 u16 offset, caps, flags;
3600 DEBUGFUNC("ixgbe_get_fcoe_boot_status_generic");
3602 /* clear output first */
3603 *bs = ixgbe_fcoe_bootstatus_unavailable;
3605 /* check if FCOE IBA block is present */
3606 offset = IXGBE_FCOE_IBA_CAPS_BLK_PTR;
3607 status = hw->eeprom.ops.read(hw, offset, &caps);
3608 if (status != IXGBE_SUCCESS)
3611 if (!(caps & IXGBE_FCOE_IBA_CAPS_FCOE))
3614 /* check if iSCSI FCOE block is populated */
3615 status = hw->eeprom.ops.read(hw, IXGBE_ISCSI_FCOE_BLK_PTR, &offset);
3616 if (status != IXGBE_SUCCESS)
3619 if ((offset == 0) || (offset == 0xFFFF))
3622 /* read fcoe flags in iSCSI FCOE block */
3623 offset = offset + IXGBE_ISCSI_FCOE_FLAGS_OFFSET;
3624 status = hw->eeprom.ops.read(hw, offset, &flags);
3625 if (status != IXGBE_SUCCESS)
3628 if (flags & IXGBE_ISCSI_FCOE_FLAGS_ENABLE)
3629 *bs = ixgbe_fcoe_bootstatus_enabled;
3631 *bs = ixgbe_fcoe_bootstatus_disabled;
3638 * ixgbe_device_supports_autoneg_fc - Check if phy supports autoneg flow
3640 * @hw: pointer to hardware structure
3642 * There are several phys that do not support autoneg flow control. This
3643 * function check the device id to see if the associated phy supports
3644 * autoneg flow control.
3646 static s32 ixgbe_device_supports_autoneg_fc(struct ixgbe_hw *hw)
3649 DEBUGFUNC("ixgbe_device_supports_autoneg_fc");
3651 switch (hw->device_id) {
3652 case IXGBE_DEV_ID_X540T:
3653 return IXGBE_SUCCESS;
3654 case IXGBE_DEV_ID_82599_T3_LOM:
3655 return IXGBE_SUCCESS;
3657 return IXGBE_ERR_FC_NOT_SUPPORTED;
3662 * ixgbe_set_mac_anti_spoofing - Enable/Disable MAC anti-spoofing
3663 * @hw: pointer to hardware structure
3664 * @enable: enable or disable switch for anti-spoofing
3665 * @pf: Physical Function pool - do not enable anti-spoofing for the PF
3668 void ixgbe_set_mac_anti_spoofing(struct ixgbe_hw *hw, bool enable, int pf)
3671 int pf_target_reg = pf >> 3;
3672 int pf_target_shift = pf % 8;
3675 if (hw->mac.type == ixgbe_mac_82598EB)
3679 pfvfspoof = IXGBE_SPOOF_MACAS_MASK;
3682 * PFVFSPOOF register array is size 8 with 8 bits assigned to
3683 * MAC anti-spoof enables in each register array element.
3685 for (j = 0; j < IXGBE_PFVFSPOOF_REG_COUNT; j++)
3686 IXGBE_WRITE_REG(hw, IXGBE_PFVFSPOOF(j), pfvfspoof);
3688 /* If not enabling anti-spoofing then done */
3693 * The PF should be allowed to spoof so that it can support
3694 * emulation mode NICs. Reset the bit assigned to the PF
3696 pfvfspoof = IXGBE_READ_REG(hw, IXGBE_PFVFSPOOF(pf_target_reg));
3697 pfvfspoof ^= (1 << pf_target_shift);
3698 IXGBE_WRITE_REG(hw, IXGBE_PFVFSPOOF(pf_target_reg), pfvfspoof);
3702 * ixgbe_set_vlan_anti_spoofing - Enable/Disable VLAN anti-spoofing
3703 * @hw: pointer to hardware structure
3704 * @enable: enable or disable switch for VLAN anti-spoofing
3705 * @pf: Virtual Function pool - VF Pool to set for VLAN anti-spoofing
3708 void ixgbe_set_vlan_anti_spoofing(struct ixgbe_hw *hw, bool enable, int vf)
3710 int vf_target_reg = vf >> 3;
3711 int vf_target_shift = vf % 8 + IXGBE_SPOOF_VLANAS_SHIFT;
3714 if (hw->mac.type == ixgbe_mac_82598EB)
3717 pfvfspoof = IXGBE_READ_REG(hw, IXGBE_PFVFSPOOF(vf_target_reg));
3719 pfvfspoof |= (1 << vf_target_shift);
3721 pfvfspoof &= ~(1 << vf_target_shift);
3722 IXGBE_WRITE_REG(hw, IXGBE_PFVFSPOOF(vf_target_reg), pfvfspoof);
3726 * ixgbe_get_device_caps_generic - Get additional device capabilities
3727 * @hw: pointer to hardware structure
3728 * @device_caps: the EEPROM word with the extra device capabilities
3730 * This function will read the EEPROM location for the device capabilities,
3731 * and return the word through device_caps.
3733 s32 ixgbe_get_device_caps_generic(struct ixgbe_hw *hw, u16 *device_caps)
3735 DEBUGFUNC("ixgbe_get_device_caps_generic");
3737 hw->eeprom.ops.read(hw, IXGBE_DEVICE_CAPS, device_caps);
3739 return IXGBE_SUCCESS;
3743 * ixgbe_enable_relaxed_ordering_gen2 - Enable relaxed ordering
3744 * @hw: pointer to hardware structure
3747 void ixgbe_enable_relaxed_ordering_gen2(struct ixgbe_hw *hw)
3752 DEBUGFUNC("ixgbe_enable_relaxed_ordering_gen2");
3754 /* Enable relaxed ordering */
3755 for (i = 0; i < hw->mac.max_tx_queues; i++) {
3756 regval = IXGBE_READ_REG(hw, IXGBE_DCA_TXCTRL_82599(i));
3757 regval |= IXGBE_DCA_TXCTRL_TX_WB_RO_EN;
3758 IXGBE_WRITE_REG(hw, IXGBE_DCA_TXCTRL_82599(i), regval);
3761 for (i = 0; i < hw->mac.max_rx_queues; i++) {
3762 regval = IXGBE_READ_REG(hw, IXGBE_DCA_RXCTRL(i));
3763 regval |= (IXGBE_DCA_RXCTRL_DESC_WRO_EN |
3764 IXGBE_DCA_RXCTRL_DESC_HSRO_EN);
3765 IXGBE_WRITE_REG(hw, IXGBE_DCA_RXCTRL(i), regval);
3771 * ixgbe_calculate_checksum - Calculate checksum for buffer
3772 * @buffer: pointer to EEPROM
3773 * @length: size of EEPROM to calculate a checksum for
3774 * Calculates the checksum for some buffer on a specified length. The
3775 * checksum calculated is returned.
3777 static u8 ixgbe_calculate_checksum(u8 *buffer, u32 length)
3782 DEBUGFUNC("ixgbe_calculate_checksum");
3787 for (i = 0; i < length; i++)
3790 return (u8) (0 - sum);
3794 * ixgbe_host_interface_command - Issue command to manageability block
3795 * @hw: pointer to the HW structure
3796 * @buffer: contains the command to write and where the return status will
3798 * @lenght: lenght of buffer, must be multiple of 4 bytes
3800 * Communicates with the manageability block. On success return IXGBE_SUCCESS
3801 * else return IXGBE_ERR_HOST_INTERFACE_COMMAND.
3803 static s32 ixgbe_host_interface_command(struct ixgbe_hw *hw, u8 *buffer,
3807 u32 hdr_size = sizeof(struct ixgbe_hic_hdr);
3808 u8 buf_len, dword_len;
3810 s32 ret_val = IXGBE_SUCCESS;
3812 DEBUGFUNC("ixgbe_host_interface_command");
3814 if (length == 0 || length & 0x3 ||
3815 length > IXGBE_HI_MAX_BLOCK_BYTE_LENGTH) {
3816 DEBUGOUT("Buffer length failure.\n");
3817 ret_val = IXGBE_ERR_HOST_INTERFACE_COMMAND;
3821 /* Check that the host interface is enabled. */
3822 hicr = IXGBE_READ_REG(hw, IXGBE_HICR);
3823 if ((hicr & IXGBE_HICR_EN) == 0) {
3824 DEBUGOUT("IXGBE_HOST_EN bit disabled.\n");
3825 ret_val = IXGBE_ERR_HOST_INTERFACE_COMMAND;
3829 /* Calculate length in DWORDs */
3830 dword_len = length >> 2;
3833 * The device driver writes the relevant command block
3834 * into the ram area.
3836 for (i = 0; i < dword_len; i++)
3837 IXGBE_WRITE_REG_ARRAY(hw, IXGBE_FLEX_MNG,
3838 i, *((u32 *)buffer + i));
3840 /* Setting this bit tells the ARC that a new command is pending. */
3841 IXGBE_WRITE_REG(hw, IXGBE_HICR, hicr | IXGBE_HICR_C);
3843 for (i = 0; i < IXGBE_HI_COMMAND_TIMEOUT; i++) {
3844 hicr = IXGBE_READ_REG(hw, IXGBE_HICR);
3845 if (!(hicr & IXGBE_HICR_C))
3850 /* Check command successful completion. */
3851 if (i == IXGBE_HI_COMMAND_TIMEOUT ||
3852 (!(IXGBE_READ_REG(hw, IXGBE_HICR) & IXGBE_HICR_SV))) {
3853 DEBUGOUT("Command has failed with no status valid.\n");
3854 ret_val = IXGBE_ERR_HOST_INTERFACE_COMMAND;
3858 /* Calculate length in DWORDs */
3859 dword_len = hdr_size >> 2;
3861 /* first pull in the header so we know the buffer length */
3862 for (i = 0; i < dword_len; i++)
3863 *((u32 *)buffer + i) =
3864 IXGBE_READ_REG_ARRAY(hw, IXGBE_FLEX_MNG, i);
3866 /* If there is any thing in data position pull it in */
3867 buf_len = ((struct ixgbe_hic_hdr *)buffer)->buf_len;
3871 if (length < (buf_len + hdr_size)) {
3872 DEBUGOUT("Buffer not large enough for reply message.\n");
3873 ret_val = IXGBE_ERR_HOST_INTERFACE_COMMAND;
3877 /* Calculate length in DWORDs, add one for odd lengths */
3878 dword_len = (buf_len + 1) >> 2;
3880 /* Pull in the rest of the buffer (i is where we left off)*/
3881 for (; i < buf_len; i++)
3882 *((u32 *)buffer + i) =
3883 IXGBE_READ_REG_ARRAY(hw, IXGBE_FLEX_MNG, i);
3890 * ixgbe_set_fw_drv_ver_generic - Sends driver version to firmware
3891 * @hw: pointer to the HW structure
3892 * @maj: driver version major number
3893 * @min: driver version minor number
3894 * @build: driver version build number
3895 * @sub: driver version sub build number
3897 * Sends driver version number to firmware through the manageability
3898 * block. On success return IXGBE_SUCCESS
3899 * else returns IXGBE_ERR_SWFW_SYNC when encountering an error acquiring
3900 * semaphore or IXGBE_ERR_HOST_INTERFACE_COMMAND when command fails.
3902 s32 ixgbe_set_fw_drv_ver_generic(struct ixgbe_hw *hw, u8 maj, u8 min,
3905 struct ixgbe_hic_drv_info fw_cmd;
3907 s32 ret_val = IXGBE_SUCCESS;
3909 DEBUGFUNC("ixgbe_set_fw_drv_ver_generic");
3911 if (hw->mac.ops.acquire_swfw_sync(hw, IXGBE_GSSR_SW_MNG_SM)
3913 ret_val = IXGBE_ERR_SWFW_SYNC;
3917 fw_cmd.hdr.cmd = FW_CEM_CMD_DRIVER_INFO;
3918 fw_cmd.hdr.buf_len = FW_CEM_CMD_DRIVER_INFO_LEN;
3919 fw_cmd.hdr.cmd_or_resp.cmd_resv = FW_CEM_CMD_RESERVED;
3920 fw_cmd.port_num = (u8)hw->bus.func;
3921 fw_cmd.ver_maj = maj;
3922 fw_cmd.ver_min = min;
3923 fw_cmd.ver_build = build;
3924 fw_cmd.ver_sub = sub;
3925 fw_cmd.hdr.checksum = 0;
3926 fw_cmd.hdr.checksum = ixgbe_calculate_checksum((u8 *)&fw_cmd,
3927 (FW_CEM_HDR_LEN + fw_cmd.hdr.buf_len));
3931 for (i = 0; i <= FW_CEM_MAX_RETRIES; i++) {
3932 ret_val = ixgbe_host_interface_command(hw, (u8 *)&fw_cmd,
3934 if (ret_val != IXGBE_SUCCESS)
3937 if (fw_cmd.hdr.cmd_or_resp.ret_status ==
3938 FW_CEM_RESP_STATUS_SUCCESS)
3939 ret_val = IXGBE_SUCCESS;
3941 ret_val = IXGBE_ERR_HOST_INTERFACE_COMMAND;
3946 hw->mac.ops.release_swfw_sync(hw, IXGBE_GSSR_SW_MNG_SM);
3952 * ixgbe_set_rxpba_generic - Initialize Rx packet buffer
3953 * @hw: pointer to hardware structure
3954 * @num_pb: number of packet buffers to allocate
3955 * @headroom: reserve n KB of headroom
3956 * @strategy: packet buffer allocation strategy
3958 void ixgbe_set_rxpba_generic(struct ixgbe_hw *hw, int num_pb, u32 headroom,
3961 u32 pbsize = hw->mac.rx_pb_size;
3963 u32 rxpktsize, txpktsize, txpbthresh;
3965 /* Reserve headroom */
3971 /* Divide remaining packet buffer space amongst the number of packet
3972 * buffers requested using supplied strategy.
3975 case (PBA_STRATEGY_WEIGHTED):
3976 /* pba_80_48 strategy weight first half of packet buffer with
3977 * 5/8 of the packet buffer space.
3979 rxpktsize = (pbsize * 5 * 2) / (num_pb * 8);
3980 pbsize -= rxpktsize * (num_pb / 2);
3981 rxpktsize <<= IXGBE_RXPBSIZE_SHIFT;
3982 for (; i < (num_pb / 2); i++)
3983 IXGBE_WRITE_REG(hw, IXGBE_RXPBSIZE(i), rxpktsize);
3984 /* Fall through to configure remaining packet buffers */
3985 case (PBA_STRATEGY_EQUAL):
3986 rxpktsize = (pbsize / (num_pb - i)) << IXGBE_RXPBSIZE_SHIFT;
3987 for (; i < num_pb; i++)
3988 IXGBE_WRITE_REG(hw, IXGBE_RXPBSIZE(i), rxpktsize);
3994 /* Only support an equally distributed Tx packet buffer strategy. */
3995 txpktsize = IXGBE_TXPBSIZE_MAX / num_pb;
3996 txpbthresh = (txpktsize / 1024) - IXGBE_TXPKT_SIZE_MAX;
3997 for (i = 0; i < num_pb; i++) {
3998 IXGBE_WRITE_REG(hw, IXGBE_TXPBSIZE(i), txpktsize);
3999 IXGBE_WRITE_REG(hw, IXGBE_TXPBTHRESH(i), txpbthresh);
4002 /* Clear unused TCs, if any, to zero buffer size*/
4003 for (; i < IXGBE_MAX_PB; i++) {
4004 IXGBE_WRITE_REG(hw, IXGBE_RXPBSIZE(i), 0);
4005 IXGBE_WRITE_REG(hw, IXGBE_TXPBSIZE(i), 0);
4006 IXGBE_WRITE_REG(hw, IXGBE_TXPBTHRESH(i), 0);
4011 * ixgbe_clear_tx_pending - Clear pending TX work from the PCIe fifo
4012 * @hw: pointer to the hardware structure
4014 * The 82599 and x540 MACs can experience issues if TX work is still pending
4015 * when a reset occurs. This function prevents this by flushing the PCIe
4016 * buffers on the system.
4018 void ixgbe_clear_tx_pending(struct ixgbe_hw *hw)
4020 u32 gcr_ext, hlreg0;
4023 * If double reset is not requested then all transactions should
4024 * already be clear and as such there is no work to do
4026 if (!(hw->mac.flags & IXGBE_FLAGS_DOUBLE_RESET_REQUIRED))
4030 * Set loopback enable to prevent any transmits from being sent
4031 * should the link come up. This assumes that the RXCTRL.RXEN bit
4032 * has already been cleared.
4034 hlreg0 = IXGBE_READ_REG(hw, IXGBE_HLREG0);
4035 IXGBE_WRITE_REG(hw, IXGBE_HLREG0, hlreg0 | IXGBE_HLREG0_LPBK);
4037 /* initiate cleaning flow for buffers in the PCIe transaction layer */
4038 gcr_ext = IXGBE_READ_REG(hw, IXGBE_GCR_EXT);
4039 IXGBE_WRITE_REG(hw, IXGBE_GCR_EXT,
4040 gcr_ext | IXGBE_GCR_EXT_BUFFERS_CLEAR);
4042 /* Flush all writes and allow 20usec for all transactions to clear */
4043 IXGBE_WRITE_FLUSH(hw);
4046 /* restore previous register values */
4047 IXGBE_WRITE_REG(hw, IXGBE_GCR_EXT, gcr_ext);
4048 IXGBE_WRITE_REG(hw, IXGBE_HLREG0, hlreg0);