11256Syl150051 /*
21256Syl150051 * CDDL HEADER START
31256Syl150051 *
41256Syl150051 * The contents of this file are subject to the terms of the
51256Syl150051 * Common Development and Distribution License (the "License").
61256Syl150051 * You may not use this file except in compliance with the License.
71256Syl150051 *
81256Syl150051 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
91256Syl150051 * or http://www.opensolaris.org/os/licensing.
101256Syl150051 * See the License for the specific language governing permissions
111256Syl150051 * and limitations under the License.
121256Syl150051 *
131256Syl150051 * When distributing Covered Code, include this CDDL HEADER in each
141256Syl150051 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
151256Syl150051 * If applicable, add the following below this CDDL HEADER, with the
161256Syl150051 * fields enclosed by brackets "[]" replaced with your own identifying
171256Syl150051 * information: Portions Copyright [yyyy] [name of copyright owner]
181256Syl150051 *
191256Syl150051 * CDDL HEADER END
201256Syl150051 *
213115Syl150051 * Copyright (c) 2002-2006 Neterion, Inc.
221256Syl150051 */
231256Syl150051
241256Syl150051 #include "xgehal-mgmt.h"
251256Syl150051 #include "xgehal-driver.h"
261256Syl150051 #include "xgehal-device.h"
271256Syl150051
281256Syl150051 /**
291256Syl150051 * xge_hal_mgmt_about - Retrieve about info.
301256Syl150051 * @devh: HAL device handle.
311256Syl150051 * @about_info: Filled in by HAL. See xge_hal_mgmt_about_info_t{}.
321256Syl150051 * @size: Size of the @about_info buffer. HAL will return error if the
331256Syl150051 * size is smaller than sizeof(xge_hal_mgmt_about_info_t).
341256Syl150051 *
351256Syl150051 * Retrieve information such as PCI device and vendor IDs, board
361256Syl150051 * revision number, HAL version number, etc.
371256Syl150051 *
381256Syl150051 * Returns: XGE_HAL_OK - success;
391256Syl150051 * XGE_HAL_ERR_INVALID_DEVICE - Device is not valid.
401256Syl150051 * XGE_HAL_ERR_VERSION_CONFLICT - Version it not maching.
411256Syl150051 * XGE_HAL_FAIL - Failed to retrieve the information.
421256Syl150051 *
431256Syl150051 * See also: xge_hal_mgmt_about_info_t{}.
441256Syl150051 */
451256Syl150051 xge_hal_status_e
xge_hal_mgmt_about(xge_hal_device_h devh,xge_hal_mgmt_about_info_t * about_info,int size)461256Syl150051 xge_hal_mgmt_about(xge_hal_device_h devh, xge_hal_mgmt_about_info_t *about_info,
471256Syl150051 int size)
481256Syl150051 {
491256Syl150051 xge_hal_device_t *hldev = (xge_hal_device_t*)devh;
501256Syl150051
511256Syl150051 if ((hldev == NULL) || (hldev->magic != XGE_HAL_MAGIC)) {
521256Syl150051 return XGE_HAL_ERR_INVALID_DEVICE;
531256Syl150051 }
541256Syl150051
551256Syl150051 if (size != sizeof(xge_hal_mgmt_about_info_t)) {
561256Syl150051 return XGE_HAL_ERR_VERSION_CONFLICT;
571256Syl150051 }
581256Syl150051
591256Syl150051 xge_os_pci_read16(hldev->pdev, hldev->cfgh,
601256Syl150051 xge_offsetof(xge_hal_pci_config_le_t, vendor_id),
611256Syl150051 &about_info->vendor);
621256Syl150051
631256Syl150051 xge_os_pci_read16(hldev->pdev, hldev->cfgh,
641256Syl150051 xge_offsetof(xge_hal_pci_config_le_t, device_id),
651256Syl150051 &about_info->device);
661256Syl150051
671256Syl150051 xge_os_pci_read16(hldev->pdev, hldev->cfgh,
681256Syl150051 xge_offsetof(xge_hal_pci_config_le_t, subsystem_vendor_id),
691256Syl150051 &about_info->subsys_vendor);
701256Syl150051
711256Syl150051 xge_os_pci_read16(hldev->pdev, hldev->cfgh,
721256Syl150051 xge_offsetof(xge_hal_pci_config_le_t, subsystem_id),
731256Syl150051 &about_info->subsys_device);
741256Syl150051
751256Syl150051 xge_os_pci_read8(hldev->pdev, hldev->cfgh,
761256Syl150051 xge_offsetof(xge_hal_pci_config_le_t, revision),
771256Syl150051 &about_info->board_rev);
781256Syl150051
79*6937Sxw161283 xge_os_strlcpy(about_info->vendor_name, XGE_DRIVER_VENDOR,
80*6937Sxw161283 sizeof(about_info->vendor_name));
81*6937Sxw161283
82*6937Sxw161283 xge_os_strlcpy(about_info->chip_name, XGE_CHIP_FAMILY,
83*6937Sxw161283 sizeof(about_info->chip_name));
84*6937Sxw161283
85*6937Sxw161283 xge_os_strlcpy(about_info->media, XGE_SUPPORTED_MEDIA_0,
86*6937Sxw161283 sizeof(about_info->media));
87*6937Sxw161283
88*6937Sxw161283 xge_os_strlcpy(about_info->hal_major, XGE_HAL_VERSION_MAJOR,
89*6937Sxw161283 sizeof(about_info->hal_major));
90*6937Sxw161283
91*6937Sxw161283 xge_os_strlcpy(about_info->hal_minor, XGE_HAL_VERSION_MINOR,
92*6937Sxw161283 sizeof(about_info->hal_minor));
931256Syl150051
94*6937Sxw161283 xge_os_strlcpy(about_info->hal_fix, XGE_HAL_VERSION_FIX,
95*6937Sxw161283 sizeof(about_info->hal_fix));
96*6937Sxw161283
97*6937Sxw161283 xge_os_strlcpy(about_info->hal_build, XGE_HAL_VERSION_BUILD,
98*6937Sxw161283 sizeof(about_info->hal_build));
99*6937Sxw161283
100*6937Sxw161283 xge_os_strlcpy(about_info->ll_major, XGELL_VERSION_MAJOR,
101*6937Sxw161283 sizeof(about_info->ll_major));
1021256Syl150051
103*6937Sxw161283 xge_os_strlcpy(about_info->ll_minor, XGELL_VERSION_MINOR,
104*6937Sxw161283 sizeof(about_info->ll_minor));
105*6937Sxw161283
106*6937Sxw161283 xge_os_strlcpy(about_info->ll_fix, XGELL_VERSION_FIX,
107*6937Sxw161283 sizeof(about_info->ll_fix));
108*6937Sxw161283
109*6937Sxw161283 xge_os_strlcpy(about_info->ll_build, XGELL_VERSION_BUILD,
110*6937Sxw161283 sizeof(about_info->ll_build));
1111256Syl150051
1123115Syl150051 about_info->transponder_temperature =
1133115Syl150051 xge_hal_read_xfp_current_temp(devh);
1143115Syl150051
1151256Syl150051 return XGE_HAL_OK;
1161256Syl150051 }
1171256Syl150051
1181256Syl150051 /**
1191256Syl150051 * xge_hal_mgmt_reg_read - Read Xframe register.
1201256Syl150051 * @devh: HAL device handle.
1211256Syl150051 * @bar_id: 0 - for BAR0, 1- for BAR1.
1221256Syl150051 * @offset: Register offset in the Base Address Register (BAR) space.
1231256Syl150051 * @value: Register value. Returned by HAL.
1241256Syl150051 * Read Xframe register.
1251256Syl150051 *
1261256Syl150051 * Returns: XGE_HAL_OK - success.
1271256Syl150051 * XGE_HAL_ERR_INVALID_DEVICE - Device is not valid.
1281256Syl150051 * XGE_HAL_ERR_INVALID_OFFSET - Register offset in the BAR space is not
1291256Syl150051 * valid.
1301256Syl150051 * XGE_HAL_ERR_INVALID_BAR_ID - BAR id is not valid.
1311256Syl150051 *
1321256Syl150051 * See also: xge_hal_aux_bar0_read(), xge_hal_aux_bar1_read().
1331256Syl150051 */
1341256Syl150051 xge_hal_status_e
xge_hal_mgmt_reg_read(xge_hal_device_h devh,int bar_id,unsigned int offset,u64 * value)1351256Syl150051 xge_hal_mgmt_reg_read(xge_hal_device_h devh, int bar_id, unsigned int offset,
1361256Syl150051 u64 *value)
1371256Syl150051 {
1381256Syl150051 xge_hal_device_t *hldev = (xge_hal_device_t*)devh;
1391256Syl150051
1401256Syl150051 if ((hldev == NULL) || (hldev->magic != XGE_HAL_MAGIC)) {
1411256Syl150051 return XGE_HAL_ERR_INVALID_DEVICE;
1421256Syl150051 }
1431256Syl150051
1441256Syl150051 if (bar_id == 0) {
1451256Syl150051 if (offset > sizeof(xge_hal_pci_bar0_t)-8) {
1461256Syl150051 return XGE_HAL_ERR_INVALID_OFFSET;
1471256Syl150051 }
1481256Syl150051 *value = xge_os_pio_mem_read64(hldev->pdev, hldev->regh0,
1491256Syl150051 (void *)(hldev->bar0 + offset));
150*6937Sxw161283 } else if (bar_id == 1 &&
151*6937Sxw161283 (xge_hal_device_check_id(hldev) == XGE_HAL_CARD_XENA ||
152*6937Sxw161283 xge_hal_device_check_id(hldev) == XGE_HAL_CARD_HERC)) {
1531256Syl150051 int i;
154*6937Sxw161283 for (i=0; i<XGE_HAL_MAX_FIFO_NUM_HERC; i++) {
1551256Syl150051 if (offset == i*0x2000 || offset == i*0x2000+0x18) {
1561256Syl150051 break;
1571256Syl150051 }
1581256Syl150051 }
159*6937Sxw161283 if (i == XGE_HAL_MAX_FIFO_NUM_HERC) {
1601256Syl150051 return XGE_HAL_ERR_INVALID_OFFSET;
1611256Syl150051 }
1621256Syl150051 *value = xge_os_pio_mem_read64(hldev->pdev, hldev->regh1,
1631256Syl150051 (void *)(hldev->bar1 + offset));
164*6937Sxw161283 } else if (bar_id == 1) {
165*6937Sxw161283 /* FIXME: check TITAN BAR1 offsets */
166*6937Sxw161283 return XGE_HAL_ERR_INVALID_DEVICE;
1671256Syl150051 } else {
1681256Syl150051 return XGE_HAL_ERR_INVALID_BAR_ID;
1691256Syl150051 }
1701256Syl150051
1711256Syl150051 return XGE_HAL_OK;
1721256Syl150051 }
1731256Syl150051
1741256Syl150051 /**
1751256Syl150051 * xge_hal_mgmt_reg_write - Write Xframe register.
1761256Syl150051 * @devh: HAL device handle.
1771256Syl150051 * @bar_id: 0 - for BAR0, 1- for BAR1.
1781256Syl150051 * @offset: Register offset in the Base Address Register (BAR) space.
1791256Syl150051 * @value: Register value.
1801256Syl150051 *
1811256Syl150051 * Write Xframe register.
1821256Syl150051 *
1831256Syl150051 * Returns: XGE_HAL_OK - success.
1841256Syl150051 * XGE_HAL_ERR_INVALID_DEVICE - Device is not valid.
1851256Syl150051 * XGE_HAL_ERR_INVALID_OFFSET - Register offset in the BAR space is not
1861256Syl150051 * valid.
1871256Syl150051 * XGE_HAL_ERR_INVALID_BAR_ID - BAR id is not valid.
1881256Syl150051 *
1891256Syl150051 * See also: xge_hal_aux_bar0_write().
1901256Syl150051 */
1911256Syl150051 xge_hal_status_e
xge_hal_mgmt_reg_write(xge_hal_device_h devh,int bar_id,unsigned int offset,u64 value)1921256Syl150051 xge_hal_mgmt_reg_write(xge_hal_device_h devh, int bar_id, unsigned int offset,
1931256Syl150051 u64 value)
1941256Syl150051 {
1951256Syl150051 xge_hal_device_t *hldev = (xge_hal_device_t*)devh;
1961256Syl150051
1971256Syl150051 if ((hldev == NULL) || (hldev->magic != XGE_HAL_MAGIC)) {
1981256Syl150051 return XGE_HAL_ERR_INVALID_DEVICE;
1991256Syl150051 }
2001256Syl150051
2011256Syl150051 if (bar_id == 0) {
2021256Syl150051 if (offset > sizeof(xge_hal_pci_bar0_t)-8) {
2031256Syl150051 return XGE_HAL_ERR_INVALID_OFFSET;
2041256Syl150051 }
2051256Syl150051 xge_os_pio_mem_write64(hldev->pdev, hldev->regh0, value,
2061256Syl150051 (void *)(hldev->bar0 + offset));
207*6937Sxw161283 } else if (bar_id == 1 &&
208*6937Sxw161283 (xge_hal_device_check_id(hldev) == XGE_HAL_CARD_XENA ||
209*6937Sxw161283 xge_hal_device_check_id(hldev) == XGE_HAL_CARD_HERC)) {
2101256Syl150051 int i;
211*6937Sxw161283 for (i=0; i<XGE_HAL_MAX_FIFO_NUM_HERC; i++) {
2121256Syl150051 if (offset == i*0x2000 || offset == i*0x2000+0x18) {
2131256Syl150051 break;
2141256Syl150051 }
2151256Syl150051 }
216*6937Sxw161283 if (i == XGE_HAL_MAX_FIFO_NUM_HERC) {
2171256Syl150051 return XGE_HAL_ERR_INVALID_OFFSET;
2181256Syl150051 }
2191256Syl150051 xge_os_pio_mem_write64(hldev->pdev, hldev->regh1, value,
2201256Syl150051 (void *)(hldev->bar1 + offset));
221*6937Sxw161283 } else if (bar_id == 1) {
222*6937Sxw161283 /* FIXME: check TITAN BAR1 offsets */
223*6937Sxw161283 return XGE_HAL_ERR_INVALID_DEVICE;
2241256Syl150051 } else {
2251256Syl150051 return XGE_HAL_ERR_INVALID_BAR_ID;
2261256Syl150051 }
2271256Syl150051
2281256Syl150051 return XGE_HAL_OK;
2291256Syl150051 }
2301256Syl150051
2311256Syl150051 /**
2321256Syl150051 * xge_hal_mgmt_hw_stats - Get Xframe hardware statistics.
2331256Syl150051 * @devh: HAL device handle.
2341256Syl150051 * @hw_stats: Hardware statistics. Returned by HAL.
2351256Syl150051 * See xge_hal_stats_hw_info_t{}.
2361256Syl150051 * @size: Size of the @hw_stats buffer. HAL will return an error
2371256Syl150051 * if the size is smaller than sizeof(xge_hal_stats_hw_info_t).
2381256Syl150051 * Get Xframe hardware statistics.
2391256Syl150051 *
2401256Syl150051 * Returns: XGE_HAL_OK - success.
2411256Syl150051 * XGE_HAL_ERR_INVALID_DEVICE - Device is not valid.
2421256Syl150051 * XGE_HAL_ERR_VERSION_CONFLICT - Version it not maching.
2431256Syl150051 *
2441256Syl150051 * See also: xge_hal_mgmt_sw_stats().
2451256Syl150051 */
2461256Syl150051 xge_hal_status_e
xge_hal_mgmt_hw_stats(xge_hal_device_h devh,xge_hal_mgmt_hw_stats_t * hw_stats,int size)2471256Syl150051 xge_hal_mgmt_hw_stats(xge_hal_device_h devh, xge_hal_mgmt_hw_stats_t *hw_stats,
2481256Syl150051 int size)
2491256Syl150051 {
2501256Syl150051 xge_hal_status_e status;
2511256Syl150051 xge_hal_device_t *hldev = (xge_hal_device_t*)devh;
2521256Syl150051 xge_hal_stats_hw_info_t *hw_info;
2531256Syl150051
254*6937Sxw161283 xge_assert(xge_hal_device_check_id(hldev) != XGE_HAL_CARD_TITAN);
255*6937Sxw161283
2561256Syl150051 if ((hldev == NULL) || (hldev->magic != XGE_HAL_MAGIC)) {
2571256Syl150051 return XGE_HAL_ERR_INVALID_DEVICE;
2581256Syl150051 }
2591256Syl150051
2601256Syl150051 if (size != sizeof(xge_hal_stats_hw_info_t)) {
2611256Syl150051 return XGE_HAL_ERR_VERSION_CONFLICT;
2621256Syl150051 }
2631256Syl150051
2641256Syl150051 if ((status = xge_hal_stats_hw (devh, &hw_info)) != XGE_HAL_OK) {
2651256Syl150051 return status;
2661256Syl150051 }
2671256Syl150051
2681256Syl150051 xge_os_memcpy(hw_stats, hw_info, sizeof(xge_hal_stats_hw_info_t));
2691256Syl150051
2701256Syl150051 return XGE_HAL_OK;
2711256Syl150051 }
2721256Syl150051
2731256Syl150051 /**
2743115Syl150051 * xge_hal_mgmt_hw_stats_off - TBD.
2753115Syl150051 * @devh: HAL device handle.
2763115Syl150051 * @off: TBD
2773115Syl150051 * @size: TBD
2783115Syl150051 * @out: TBD
2793115Syl150051 *
2803115Syl150051 * Returns: XGE_HAL_OK - success.
2813115Syl150051 * XGE_HAL_ERR_INVALID_DEVICE - Device is not valid.
2823115Syl150051 * XGE_HAL_ERR_VERSION_CONFLICT - Version it not maching.
2833115Syl150051 *
2843115Syl150051 * See also: xge_hal_mgmt_sw_stats().
2851256Syl150051 */
2861256Syl150051 xge_hal_status_e
xge_hal_mgmt_hw_stats_off(xge_hal_device_h devh,int off,int size,char * out)2871256Syl150051 xge_hal_mgmt_hw_stats_off(xge_hal_device_h devh, int off, int size, char *out)
2881256Syl150051 {
2891256Syl150051 xge_hal_status_e status;
2901256Syl150051 xge_hal_device_t *hldev = (xge_hal_device_t*)devh;
2911256Syl150051 xge_hal_stats_hw_info_t *hw_info;
2921256Syl150051
293*6937Sxw161283 xge_assert(xge_hal_device_check_id(hldev) != XGE_HAL_CARD_TITAN);
294*6937Sxw161283
2951256Syl150051 if ((hldev == NULL) || (hldev->magic != XGE_HAL_MAGIC)) {
2961256Syl150051 return XGE_HAL_ERR_INVALID_DEVICE;
2971256Syl150051 }
2981256Syl150051
2991256Syl150051 if (off > sizeof(xge_hal_stats_hw_info_t)-4 ||
3001256Syl150051 size > 8) {
3011256Syl150051 return XGE_HAL_ERR_INVALID_OFFSET;
3021256Syl150051 }
3031256Syl150051
3041256Syl150051 if ((status = xge_hal_stats_hw (devh, &hw_info)) != XGE_HAL_OK) {
3051256Syl150051 return status;
3061256Syl150051 }
3071256Syl150051
3081256Syl150051 xge_os_memcpy(out, (char*)hw_info + off, size);
3091256Syl150051
3101256Syl150051 return XGE_HAL_OK;
3111256Syl150051 }
3121256Syl150051
3131256Syl150051 /**
314*6937Sxw161283 * xge_hal_mgmt_pcim_stats - Get Titan hardware statistics.
315*6937Sxw161283 * @devh: HAL device handle.
316*6937Sxw161283 * @pcim_stats: PCIM statistics. Returned by HAL.
317*6937Sxw161283 * See xge_hal_stats_hw_info_t{}.
318*6937Sxw161283 * @size: Size of the @hw_stats buffer. HAL will return an error
319*6937Sxw161283 * if the size is smaller than sizeof(xge_hal_stats_hw_info_t).
320*6937Sxw161283 * Get Xframe hardware statistics.
321*6937Sxw161283 *
322*6937Sxw161283 * Returns: XGE_HAL_OK - success.
323*6937Sxw161283 * XGE_HAL_ERR_INVALID_DEVICE - Device is not valid.
324*6937Sxw161283 * XGE_HAL_ERR_VERSION_CONFLICT - Version it not maching.
325*6937Sxw161283 *
326*6937Sxw161283 * See also: xge_hal_mgmt_sw_stats().
327*6937Sxw161283 */
328*6937Sxw161283 xge_hal_status_e
xge_hal_mgmt_pcim_stats(xge_hal_device_h devh,xge_hal_mgmt_pcim_stats_t * pcim_stats,int size)329*6937Sxw161283 xge_hal_mgmt_pcim_stats(xge_hal_device_h devh,
330*6937Sxw161283 xge_hal_mgmt_pcim_stats_t *pcim_stats, int size)
331*6937Sxw161283 {
332*6937Sxw161283 xge_hal_status_e status;
333*6937Sxw161283 xge_hal_device_t *hldev = (xge_hal_device_t*)devh;
334*6937Sxw161283 xge_hal_stats_pcim_info_t *pcim_info;
335*6937Sxw161283
336*6937Sxw161283 xge_assert(xge_hal_device_check_id(hldev) == XGE_HAL_CARD_TITAN);
337*6937Sxw161283
338*6937Sxw161283 if ((hldev == NULL) || (hldev->magic != XGE_HAL_MAGIC)) {
339*6937Sxw161283 return XGE_HAL_ERR_INVALID_DEVICE;
340*6937Sxw161283 }
341*6937Sxw161283
342*6937Sxw161283 if (size != sizeof(xge_hal_stats_pcim_info_t)) {
343*6937Sxw161283 return XGE_HAL_ERR_VERSION_CONFLICT;
344*6937Sxw161283 }
345*6937Sxw161283
346*6937Sxw161283 if ((status = xge_hal_stats_pcim (devh, &pcim_info)) != XGE_HAL_OK) {
347*6937Sxw161283 return status;
348*6937Sxw161283 }
349*6937Sxw161283
350*6937Sxw161283 xge_os_memcpy(pcim_stats, pcim_info,
351*6937Sxw161283 sizeof(xge_hal_stats_pcim_info_t));
352*6937Sxw161283
353*6937Sxw161283 return XGE_HAL_OK;
354*6937Sxw161283 }
355*6937Sxw161283
356*6937Sxw161283 /**
357*6937Sxw161283 * xge_hal_mgmt_pcim_stats_off - TBD.
358*6937Sxw161283 * @devh: HAL device handle.
359*6937Sxw161283 * @off: TBD
360*6937Sxw161283 * @size: TBD
361*6937Sxw161283 * @out: TBD
362*6937Sxw161283 *
363*6937Sxw161283 * Returns: XGE_HAL_OK - success.
364*6937Sxw161283 * XGE_HAL_ERR_INVALID_DEVICE - Device is not valid.
365*6937Sxw161283 * XGE_HAL_ERR_VERSION_CONFLICT - Version it not maching.
366*6937Sxw161283 *
367*6937Sxw161283 * See also: xge_hal_mgmt_sw_stats().
368*6937Sxw161283 */
369*6937Sxw161283 xge_hal_status_e
xge_hal_mgmt_pcim_stats_off(xge_hal_device_h devh,int off,int size,char * out)370*6937Sxw161283 xge_hal_mgmt_pcim_stats_off(xge_hal_device_h devh, int off, int size,
371*6937Sxw161283 char *out)
372*6937Sxw161283 {
373*6937Sxw161283 xge_hal_status_e status;
374*6937Sxw161283 xge_hal_device_t *hldev = (xge_hal_device_t*)devh;
375*6937Sxw161283 xge_hal_stats_pcim_info_t *pcim_info;
376*6937Sxw161283
377*6937Sxw161283 xge_assert(xge_hal_device_check_id(hldev) == XGE_HAL_CARD_TITAN);
378*6937Sxw161283
379*6937Sxw161283 if ((hldev == NULL) || (hldev->magic != XGE_HAL_MAGIC)) {
380*6937Sxw161283 return XGE_HAL_ERR_INVALID_DEVICE;
381*6937Sxw161283 }
382*6937Sxw161283
383*6937Sxw161283 if (off > sizeof(xge_hal_stats_pcim_info_t)-8 ||
384*6937Sxw161283 size > 8) {
385*6937Sxw161283 return XGE_HAL_ERR_INVALID_OFFSET;
386*6937Sxw161283 }
387*6937Sxw161283
388*6937Sxw161283 if ((status = xge_hal_stats_pcim (devh, &pcim_info)) != XGE_HAL_OK) {
389*6937Sxw161283 return status;
390*6937Sxw161283 }
391*6937Sxw161283
392*6937Sxw161283 xge_os_memcpy(out, (char*)pcim_info + off, size);
393*6937Sxw161283
394*6937Sxw161283 return XGE_HAL_OK;
395*6937Sxw161283 }
396*6937Sxw161283
397*6937Sxw161283 /**
3981256Syl150051 * xge_hal_mgmt_sw_stats - Get per-device software statistics.
3991256Syl150051 * @devh: HAL device handle.
4001256Syl150051 * @sw_stats: Hardware statistics. Returned by HAL.
4011256Syl150051 * See xge_hal_stats_sw_err_t{}.
4021256Syl150051 * @size: Size of the @sw_stats buffer. HAL will return an error
4031256Syl150051 * if the size is smaller than sizeof(xge_hal_stats_sw_err_t).
4041256Syl150051 * Get device software statistics, including ECC and Parity error
4051256Syl150051 * counters, etc.
4061256Syl150051 *
4071256Syl150051 * Returns: XGE_HAL_OK - success.
4081256Syl150051 * XGE_HAL_ERR_INVALID_DEVICE - Device is not valid.
4091256Syl150051 * XGE_HAL_ERR_VERSION_CONFLICT - Version it not maching.
4101256Syl150051 *
4111256Syl150051 * See also: xge_hal_stats_sw_err_t{}, xge_hal_mgmt_hw_stats().
4121256Syl150051 */
4131256Syl150051 xge_hal_status_e
xge_hal_mgmt_sw_stats(xge_hal_device_h devh,xge_hal_mgmt_sw_stats_t * sw_stats,int size)4141256Syl150051 xge_hal_mgmt_sw_stats(xge_hal_device_h devh, xge_hal_mgmt_sw_stats_t *sw_stats,
4151256Syl150051 int size)
4161256Syl150051 {
4171256Syl150051 xge_hal_device_t *hldev = (xge_hal_device_t*)devh;
4181256Syl150051
4191256Syl150051 if ((hldev == NULL) || (hldev->magic != XGE_HAL_MAGIC)) {
4201256Syl150051 return XGE_HAL_ERR_INVALID_DEVICE;
4211256Syl150051 }
4221256Syl150051
4231256Syl150051 if (size != sizeof(xge_hal_stats_sw_err_t)) {
4241256Syl150051 return XGE_HAL_ERR_VERSION_CONFLICT;
4251256Syl150051 }
4261256Syl150051
4271256Syl150051 if (!hldev->stats.is_initialized ||
4281256Syl150051 !hldev->stats.is_enabled) {
4291256Syl150051 return XGE_HAL_INF_STATS_IS_NOT_READY;
4301256Syl150051 }
4311256Syl150051
4323115Syl150051 /* Updating xpak stats value */
4333115Syl150051 __hal_updt_stats_xpak(hldev);
4343115Syl150051
4351256Syl150051 xge_os_memcpy(sw_stats, &hldev->stats.sw_dev_err_stats,
4361256Syl150051 sizeof(xge_hal_stats_sw_err_t));
4371256Syl150051
4381256Syl150051 return XGE_HAL_OK;
4391256Syl150051 }
4401256Syl150051
4411256Syl150051 /**
4421256Syl150051 * xge_hal_mgmt_device_stats - Get HAL device statistics.
4431256Syl150051 * @devh: HAL device handle.
4441256Syl150051 * @device_stats: HAL device "soft" statistics. Maintained by HAL itself.
4451256Syl150051 * (as opposed to xge_hal_mgmt_hw_stats() - those are
4461256Syl150051 * maintained by the Xframe hardware).
4471256Syl150051 * Returned by HAL.
4481256Syl150051 * See xge_hal_stats_device_info_t{}.
4491256Syl150051 * @size: Size of the @device_stats buffer. HAL will return an error
4501256Syl150051 * if the size is smaller than sizeof(xge_hal_stats_device_info_t).
4511256Syl150051 *
4521256Syl150051 * Get HAL (layer) statistic counters.
4531256Syl150051 * Returns: XGE_HAL_OK - success.
4541256Syl150051 * XGE_HAL_ERR_INVALID_DEVICE - Device is not valid.
4551256Syl150051 * XGE_HAL_ERR_VERSION_CONFLICT - Version it not maching.
4561256Syl150051 * XGE_HAL_INF_STATS_IS_NOT_READY - Statistics information is not
4571256Syl150051 * currently available.
4581256Syl150051 *
4591256Syl150051 */
4601256Syl150051 xge_hal_status_e
xge_hal_mgmt_device_stats(xge_hal_device_h devh,xge_hal_mgmt_device_stats_t * device_stats,int size)4611256Syl150051 xge_hal_mgmt_device_stats(xge_hal_device_h devh,
4621256Syl150051 xge_hal_mgmt_device_stats_t *device_stats, int size)
4631256Syl150051 {
4641256Syl150051 xge_hal_status_e status;
4651256Syl150051 xge_hal_device_t *hldev = (xge_hal_device_t*)devh;
4661256Syl150051 xge_hal_stats_device_info_t *device_info;
4671256Syl150051
4681256Syl150051 if ((hldev == NULL) || (hldev->magic != XGE_HAL_MAGIC)) {
4691256Syl150051 return XGE_HAL_ERR_INVALID_DEVICE;
4701256Syl150051 }
4711256Syl150051
4721256Syl150051 if (size != sizeof(xge_hal_stats_device_info_t)) {
4731256Syl150051 return XGE_HAL_ERR_VERSION_CONFLICT;
4741256Syl150051 }
4751256Syl150051
4761256Syl150051 if ((status = xge_hal_stats_device (devh, &device_info)) !=
4771256Syl150051 XGE_HAL_OK) {
4781256Syl150051 return status;
4791256Syl150051 }
4801256Syl150051
4811256Syl150051 xge_os_memcpy(device_stats, device_info,
4821256Syl150051 sizeof(xge_hal_stats_device_info_t));
4831256Syl150051
4841256Syl150051 return XGE_HAL_OK;
4851256Syl150051 }
4861256Syl150051
4871256Syl150051 /*
4881256Syl150051 * __hal_update_ring_bump - Update the ring bump counter for the
4891256Syl150051 * particular channel.
4901256Syl150051 * @hldev: HAL device handle.
4911256Syl150051 * @queue: the queue who's data is to be collected.
4921256Syl150051 * @chinfo: pointer to the statistics structure of the given channel.
4931256Syl150051 * Usage: See xge_hal_aux_stats_hal_read{}
4941256Syl150051 */
4951256Syl150051
4961256Syl150051 static void
__hal_update_ring_bump(xge_hal_device_t * hldev,int queue,xge_hal_stats_channel_info_t * chinfo)4971256Syl150051 __hal_update_ring_bump(xge_hal_device_t *hldev, int queue,
4981256Syl150051 xge_hal_stats_channel_info_t *chinfo)
4991256Syl150051 {
5001256Syl150051 xge_hal_pci_bar0_t *bar0 = (xge_hal_pci_bar0_t *)hldev->bar0;
5011256Syl150051 u64 rbc = 0;
5021256Syl150051 int reg = (queue / 4);
5031256Syl150051 void * addr;
5041256Syl150051
5051256Syl150051 addr = (reg == 1)? (&bar0->ring_bump_counter2) :
5061256Syl150051 (&bar0->ring_bump_counter1);
5071256Syl150051 rbc = xge_os_pio_mem_read64(hldev->pdev, hldev->regh0, addr);
5081256Syl150051 chinfo->ring_bump_cnt = XGE_HAL_RING_BUMP_CNT(queue, rbc);
5091256Syl150051 }
5101256Syl150051
5111256Syl150051 /**
5121256Syl150051 * xge_hal_mgmt_channel_stats - Get HAL channel statistics.
5131256Syl150051 * @channelh: HAL channel handle.
5141256Syl150051 * @channel_stats: HAL channel statistics. Maintained by HAL itself
5151256Syl150051 * (as opposed to xge_hal_mgmt_hw_stats() - those are
5161256Syl150051 * maintained by the Xframe hardware).
5171256Syl150051 * Returned by HAL.
5181256Syl150051 * See xge_hal_stats_channel_info_t{}.
5191256Syl150051 * @size: Size of the @channel_stats buffer. HAL will return an error
5201256Syl150051 * if the size is smaller than sizeof(xge_hal_mgmt_channel_stats_t).
5211256Syl150051 *
5221256Syl150051 * Get HAL per-channel statistic counters.
5231256Syl150051 *
5241256Syl150051 * Returns: XGE_HAL_OK - success.
5251256Syl150051 * XGE_HAL_ERR_VERSION_CONFLICT - Version it not maching.
5261256Syl150051 * XGE_HAL_INF_STATS_IS_NOT_READY - Statistics information is not
5271256Syl150051 * currently available.
5281256Syl150051 *
5291256Syl150051 */
5301256Syl150051 xge_hal_status_e
xge_hal_mgmt_channel_stats(xge_hal_channel_h channelh,xge_hal_mgmt_channel_stats_t * channel_stats,int size)5311256Syl150051 xge_hal_mgmt_channel_stats(xge_hal_channel_h channelh,
5321256Syl150051 xge_hal_mgmt_channel_stats_t *channel_stats, int size)
5331256Syl150051 {
5341256Syl150051 xge_hal_status_e status;
5351256Syl150051 xge_hal_stats_channel_info_t *channel_info;
5363115Syl150051 xge_hal_channel_t *channel = (xge_hal_channel_t* ) channelh;
5371256Syl150051
5381256Syl150051 if (size != sizeof(xge_hal_stats_channel_info_t)) {
5391256Syl150051 return XGE_HAL_ERR_VERSION_CONFLICT;
5401256Syl150051 }
5411256Syl150051
5421256Syl150051 if ((status = xge_hal_stats_channel (channelh, &channel_info)) !=
5431256Syl150051 XGE_HAL_OK) {
5441256Syl150051 return status;
5451256Syl150051 }
5461256Syl150051
5471256Syl150051 if (xge_hal_device_check_id(channel->devh) == XGE_HAL_CARD_HERC) {
5483115Syl150051 __hal_update_ring_bump( (xge_hal_device_t *) channel->devh, channel->post_qid, channel_info);
5491256Syl150051 }
5501256Syl150051
5511256Syl150051 xge_os_memcpy(channel_stats, channel_info,
5521256Syl150051 sizeof(xge_hal_stats_channel_info_t));
5531256Syl150051
5541256Syl150051 return XGE_HAL_OK;
5551256Syl150051 }
5561256Syl150051
5571256Syl150051 /**
5581256Syl150051 * xge_hal_mgmt_pcireg_read - Read PCI configuration at a specified
5591256Syl150051 * offset.
5601256Syl150051 * @devh: HAL device handle.
5611256Syl150051 * @offset: Offset in the 256 byte PCI configuration space.
5621256Syl150051 * @value_bits: 8, 16, or 32 (bits) to read.
5631256Syl150051 * @value: Value returned by HAL.
5641256Syl150051 *
5651256Syl150051 * Read PCI configuration, given device and offset in the PCI space.
5661256Syl150051 *
5671256Syl150051 * Returns: XGE_HAL_OK - success.
5681256Syl150051 * XGE_HAL_ERR_INVALID_DEVICE - Device is not valid.
5691256Syl150051 * XGE_HAL_ERR_INVALID_OFFSET - Register offset in the BAR space is not
5701256Syl150051 * valid.
5711256Syl150051 * XGE_HAL_ERR_INVALID_VALUE_BIT_SIZE - Invalid bits size. Valid
5721256Syl150051 * values(8/16/32).
5731256Syl150051 *
5741256Syl150051 */
5751256Syl150051 xge_hal_status_e
xge_hal_mgmt_pcireg_read(xge_hal_device_h devh,unsigned int offset,int value_bits,u32 * value)5761256Syl150051 xge_hal_mgmt_pcireg_read(xge_hal_device_h devh, unsigned int offset,
5771256Syl150051 int value_bits, u32 *value)
5781256Syl150051 {
5791256Syl150051 xge_hal_device_t *hldev = (xge_hal_device_t*)devh;
5801256Syl150051
5811256Syl150051 if ((hldev == NULL) || (hldev->magic != XGE_HAL_MAGIC)) {
5821256Syl150051 return XGE_HAL_ERR_INVALID_DEVICE;
5831256Syl150051 }
5841256Syl150051
5851256Syl150051 if (offset > sizeof(xge_hal_pci_config_t)-value_bits/8) {
5861256Syl150051 return XGE_HAL_ERR_INVALID_OFFSET;
5871256Syl150051 }
5881256Syl150051
5891256Syl150051 if (value_bits == 8) {
5901256Syl150051 xge_os_pci_read8(hldev->pdev, hldev->cfgh, offset, (u8*)value);
5911256Syl150051 } else if (value_bits == 16) {
5921256Syl150051 xge_os_pci_read16(hldev->pdev, hldev->cfgh, offset,
5931256Syl150051 (u16*)value);
5941256Syl150051 } else if (value_bits == 32) {
5951256Syl150051 xge_os_pci_read32(hldev->pdev, hldev->cfgh, offset, value);
5961256Syl150051 } else {
5971256Syl150051 return XGE_HAL_ERR_INVALID_VALUE_BIT_SIZE;
5981256Syl150051 }
5991256Syl150051
6001256Syl150051 return XGE_HAL_OK;
6011256Syl150051 }
6021256Syl150051
6031256Syl150051 /**
6041256Syl150051 * xge_hal_mgmt_device_config - Retrieve device configuration.
6051256Syl150051 * @devh: HAL device handle.
6061256Syl150051 * @dev_config: Device configuration, see xge_hal_device_config_t{}.
6071256Syl150051 * @size: Size of the @dev_config buffer. HAL will return an error
6081256Syl150051 * if the size is smaller than sizeof(xge_hal_mgmt_device_config_t).
6091256Syl150051 *
6101256Syl150051 * Get device configuration. Permits to retrieve at run-time configuration
6111256Syl150051 * values that were used to initialize and configure the device.
6121256Syl150051 *
6131256Syl150051 * Returns: XGE_HAL_OK - success.
6141256Syl150051 * XGE_HAL_ERR_INVALID_DEVICE - Device is not valid.
6151256Syl150051 * XGE_HAL_ERR_VERSION_CONFLICT - Version it not maching.
6161256Syl150051 *
6171256Syl150051 * See also: xge_hal_device_config_t{}, xge_hal_mgmt_driver_config().
6181256Syl150051 */
6191256Syl150051 xge_hal_status_e
xge_hal_mgmt_device_config(xge_hal_device_h devh,xge_hal_mgmt_device_config_t * dev_config,int size)6201256Syl150051 xge_hal_mgmt_device_config(xge_hal_device_h devh,
6211256Syl150051 xge_hal_mgmt_device_config_t *dev_config, int size)
6221256Syl150051 {
6231256Syl150051 xge_hal_device_t *hldev = (xge_hal_device_t*)devh;
6241256Syl150051
6251256Syl150051 if ((hldev == NULL) || (hldev->magic != XGE_HAL_MAGIC)) {
6261256Syl150051 return XGE_HAL_ERR_INVALID_DEVICE;
6271256Syl150051 }
6281256Syl150051
6291256Syl150051 if (size != sizeof(xge_hal_mgmt_device_config_t)) {
6301256Syl150051 return XGE_HAL_ERR_VERSION_CONFLICT;
6311256Syl150051 }
6321256Syl150051
6331256Syl150051 xge_os_memcpy(dev_config, &hldev->config,
6341256Syl150051 sizeof(xge_hal_device_config_t));
6351256Syl150051
6361256Syl150051 return XGE_HAL_OK;
6371256Syl150051 }
6381256Syl150051
6391256Syl150051 /**
6401256Syl150051 * xge_hal_mgmt_driver_config - Retrieve driver configuration.
6411256Syl150051 * @drv_config: Device configuration, see xge_hal_driver_config_t{}.
6421256Syl150051 * @size: Size of the @dev_config buffer. HAL will return an error
6431256Syl150051 * if the size is smaller than sizeof(xge_hal_mgmt_driver_config_t).
6441256Syl150051 *
6451256Syl150051 * Get driver configuration. Permits to retrieve at run-time configuration
6461256Syl150051 * values that were used to configure the device at load-time.
6471256Syl150051 *
6481256Syl150051 * Returns: XGE_HAL_OK - success.
6491256Syl150051 * XGE_HAL_ERR_DRIVER_NOT_INITIALIZED - HAL is not initialized.
6501256Syl150051 * XGE_HAL_ERR_VERSION_CONFLICT - Version is not maching.
6511256Syl150051 *
6521256Syl150051 * See also: xge_hal_driver_config_t{}, xge_hal_mgmt_device_config().
6531256Syl150051 */
6541256Syl150051 xge_hal_status_e
xge_hal_mgmt_driver_config(xge_hal_mgmt_driver_config_t * drv_config,int size)6551256Syl150051 xge_hal_mgmt_driver_config(xge_hal_mgmt_driver_config_t *drv_config, int size)
6561256Syl150051 {
6571256Syl150051
6581256Syl150051 if (g_xge_hal_driver == NULL) {
6591256Syl150051 return XGE_HAL_ERR_DRIVER_NOT_INITIALIZED;
6601256Syl150051 }
6611256Syl150051
6621256Syl150051 if (size != sizeof(xge_hal_mgmt_driver_config_t)) {
6631256Syl150051 return XGE_HAL_ERR_VERSION_CONFLICT;
6641256Syl150051 }
6651256Syl150051
6661256Syl150051 xge_os_memcpy(drv_config, &g_xge_hal_driver->config,
6671256Syl150051 sizeof(xge_hal_mgmt_driver_config_t));
6681256Syl150051
6691256Syl150051 return XGE_HAL_OK;
6701256Syl150051 }
6711256Syl150051
6721256Syl150051 /**
6731256Syl150051 * xge_hal_mgmt_pci_config - Retrieve PCI configuration.
6741256Syl150051 * @devh: HAL device handle.
6751256Syl150051 * @pci_config: 256 byte long buffer for PCI configuration space.
6761256Syl150051 * @size: Size of the @ buffer. HAL will return an error
6771256Syl150051 * if the size is smaller than sizeof(xge_hal_mgmt_pci_config_t).
6781256Syl150051 *
6791256Syl150051 * Get PCI configuration. Permits to retrieve at run-time configuration
6801256Syl150051 * values that were used to configure the device at load-time.
6811256Syl150051 *
6821256Syl150051 * Returns: XGE_HAL_OK - success.
6831256Syl150051 * XGE_HAL_ERR_INVALID_DEVICE - Device is not valid.
6841256Syl150051 * XGE_HAL_ERR_VERSION_CONFLICT - Version it not maching.
6851256Syl150051 *
6861256Syl150051 */
6871256Syl150051 xge_hal_status_e
xge_hal_mgmt_pci_config(xge_hal_device_h devh,xge_hal_mgmt_pci_config_t * pci_config,int size)6881256Syl150051 xge_hal_mgmt_pci_config(xge_hal_device_h devh,
6891256Syl150051 xge_hal_mgmt_pci_config_t *pci_config, int size)
6901256Syl150051 {
6911256Syl150051 int i;
6921256Syl150051 xge_hal_device_t *hldev = (xge_hal_device_t*)devh;
6931256Syl150051
6941256Syl150051 if ((hldev == NULL) || (hldev->magic != XGE_HAL_MAGIC)) {
6951256Syl150051 return XGE_HAL_ERR_INVALID_DEVICE;
6961256Syl150051 }
6971256Syl150051
6981256Syl150051 if (size != sizeof(xge_hal_mgmt_pci_config_t)) {
6991256Syl150051 return XGE_HAL_ERR_VERSION_CONFLICT;
7001256Syl150051 }
7011256Syl150051
7021256Syl150051 /* refresh PCI config space */
7031256Syl150051 for (i = 0; i < 0x68/4+1; i++) {
7041256Syl150051 xge_os_pci_read32(hldev->pdev, hldev->cfgh, i*4,
7051256Syl150051 (u32*)&hldev->pci_config_space + i);
7061256Syl150051 }
7071256Syl150051
7081256Syl150051 xge_os_memcpy(pci_config, &hldev->pci_config_space,
7091256Syl150051 sizeof(xge_hal_mgmt_pci_config_t));
7101256Syl150051
7111256Syl150051 return XGE_HAL_OK;
7121256Syl150051 }
7131256Syl150051
7141256Syl150051 #ifdef XGE_TRACE_INTO_CIRCULAR_ARR
7151256Syl150051 /**
7161256Syl150051 * xge_hal_mgmt_trace_read - Read trace buffer contents.
7171256Syl150051 * @buffer: Buffer to store the trace buffer contents.
7181256Syl150051 * @buf_size: Size of the buffer.
7191256Syl150051 * @offset: Offset in the internal trace buffer to read data.
7201256Syl150051 * @read_length: Size of the valid data in the buffer.
7211256Syl150051 *
7221256Syl150051 * Read HAL trace buffer contents starting from the offset
7231256Syl150051 * upto the size of the buffer or till EOF is reached.
7241256Syl150051 *
7251256Syl150051 * Returns: XGE_HAL_OK - success.
7261256Syl150051 * XGE_HAL_EOF_TRACE_BUF - No more data in the trace buffer.
7271256Syl150051 *
7281256Syl150051 */
7291256Syl150051 xge_hal_status_e
xge_hal_mgmt_trace_read(char * buffer,unsigned buf_size,unsigned * offset,unsigned * read_length)7301256Syl150051 xge_hal_mgmt_trace_read (char *buffer,
7311256Syl150051 unsigned buf_size,
7321256Syl150051 unsigned *offset,
7331256Syl150051 unsigned *read_length)
7341256Syl150051 {
7351256Syl150051 int data_offset;
7361256Syl150051 int start_offset;
7371256Syl150051
7381256Syl150051 if ((g_xge_os_tracebuf == NULL) ||
7391256Syl150051 (g_xge_os_tracebuf->offset == g_xge_os_tracebuf->size - 2)) {
7401256Syl150051 return XGE_HAL_EOF_TRACE_BUF;
7411256Syl150051 }
7421256Syl150051
7431256Syl150051 data_offset = g_xge_os_tracebuf->offset + 1;
7441256Syl150051
7451256Syl150051 if (*offset >= (unsigned)xge_os_strlen(g_xge_os_tracebuf->data +
7461256Syl150051 data_offset)) {
7471256Syl150051
7481256Syl150051 return XGE_HAL_EOF_TRACE_BUF;
7491256Syl150051 }
7501256Syl150051
7511256Syl150051 xge_os_memzero(buffer, buf_size);
7521256Syl150051
7531256Syl150051 start_offset = data_offset + *offset;
7541256Syl150051 *read_length = xge_os_strlen(g_xge_os_tracebuf->data +
7551256Syl150051 start_offset);
7561256Syl150051
7571256Syl150051 if (*read_length >= buf_size) {
7581256Syl150051 *read_length = buf_size - 1;
7591256Syl150051 }
7601256Syl150051
7611256Syl150051 xge_os_memcpy(buffer, g_xge_os_tracebuf->data + start_offset,
7621256Syl150051 *read_length);
7631256Syl150051
7641256Syl150051 *offset += *read_length;
7651256Syl150051 (*read_length) ++;
7661256Syl150051
7671256Syl150051 return XGE_HAL_OK;
7681256Syl150051 }
7691256Syl150051
7701256Syl150051 #endif
7711256Syl150051
7721256Syl150051 /**
7731256Syl150051 * xge_hal_restore_link_led - Restore link LED to its original state.
7741256Syl150051 * @devh: HAL device handle.
7751256Syl150051 */
7761256Syl150051 void
xge_hal_restore_link_led(xge_hal_device_h devh)7771256Syl150051 xge_hal_restore_link_led(xge_hal_device_h devh)
7781256Syl150051 {
7791256Syl150051 xge_hal_device_t *hldev = (xge_hal_device_t*)devh;
7801256Syl150051 xge_hal_pci_bar0_t *bar0 = (xge_hal_pci_bar0_t *)hldev->bar0;
7811256Syl150051 u64 val64;
7821256Syl150051
7831256Syl150051 /*
7841256Syl150051 * If the current link state is UP, switch on LED else make it
7851256Syl150051 * off.
7861256Syl150051 */
7871256Syl150051
7881256Syl150051 /*
7891256Syl150051 * For Xena 3 and lower revision cards, adapter control needs to be
7901256Syl150051 * used for making LED ON/OFF.
7911256Syl150051 */
7921256Syl150051 if ((xge_hal_device_check_id(hldev) == XGE_HAL_CARD_XENA) &&
7931256Syl150051 (xge_hal_device_rev(hldev) <= 3)) {
7941256Syl150051 val64 = xge_os_pio_mem_read64(hldev->pdev, hldev->regh0,
7951256Syl150051 &bar0->adapter_control);
7961256Syl150051 if (hldev->link_state == XGE_HAL_LINK_UP) {
7971256Syl150051 val64 |= XGE_HAL_ADAPTER_LED_ON;
7981256Syl150051 } else {
7991256Syl150051 val64 &= ~XGE_HAL_ADAPTER_LED_ON;
8001256Syl150051 }
8011256Syl150051
8021256Syl150051 xge_os_pio_mem_write64(hldev->pdev, hldev->regh0, val64,
8031256Syl150051 &bar0->adapter_control);
8041256Syl150051 return;
8051256Syl150051 }
8061256Syl150051
8071256Syl150051 /*
8081256Syl150051 * Use beacon control register to control the LED.
8091256Syl150051 * LED link output corresponds to bit 8 of the beacon control
8101256Syl150051 * register. Note that, in the case of Xena, beacon control register
8111256Syl150051 * represents the gpio control register. In the case of Herc, LED
8121256Syl150051 * handling is done by beacon control register as opposed to gpio
813*6937Sxw161283 * control register in Xena. Beacon control is used only to toggle
814*6937Sxw161283 * and the value written into it does not depend on the link state.
815*6937Sxw161283 * It is upto the ULD to toggle the LED even number of times which
816*6937Sxw161283 * brings the LED to it's original state.
8171256Syl150051 */
8181256Syl150051 val64 = xge_os_pio_mem_read64(hldev->pdev, hldev->regh0,
8191256Syl150051 &bar0->beacon_control);
820*6937Sxw161283 val64 |= 0x0000800000000000ULL;
821*6937Sxw161283 xge_os_pio_mem_write64(hldev->pdev, hldev->regh0,
822*6937Sxw161283 val64, &bar0->beacon_control);
8231256Syl150051 }
8241256Syl150051
8251256Syl150051 /**
8261256Syl150051 * xge_hal_flick_link_led - Flick (blink) link LED.
8271256Syl150051 * @devh: HAL device handle.
8281256Syl150051 *
8291256Syl150051 * Depending on the card revision flicker the link LED by using the
8301256Syl150051 * beacon control or the adapter_control register.
8311256Syl150051 */
8321256Syl150051 void
xge_hal_flick_link_led(xge_hal_device_h devh)8331256Syl150051 xge_hal_flick_link_led(xge_hal_device_h devh)
8341256Syl150051 {
8351256Syl150051 xge_hal_device_t *hldev = (xge_hal_device_t*)devh;
8361256Syl150051 xge_hal_pci_bar0_t *bar0 = (xge_hal_pci_bar0_t *)hldev->bar0;
8371256Syl150051 u64 val64 = 0;
8381256Syl150051
8391256Syl150051 /*
8401256Syl150051 * For Xena 3 and lower revision cards, adapter control needs to be
8411256Syl150051 * used for making LED ON/OFF.
8421256Syl150051 */
8431256Syl150051 if ((xge_hal_device_check_id(hldev) == XGE_HAL_CARD_XENA) &&
8441256Syl150051 (xge_hal_device_rev(hldev) <= 3)) {
8451256Syl150051 val64 = xge_os_pio_mem_read64(hldev->pdev, hldev->regh0,
8461256Syl150051 &bar0->adapter_control);
8471256Syl150051 val64 ^= XGE_HAL_ADAPTER_LED_ON;
8481256Syl150051 xge_os_pio_mem_write64(hldev->pdev, hldev->regh0, val64,
8491256Syl150051 &bar0->adapter_control);
8501256Syl150051 return;
8511256Syl150051 }
8521256Syl150051
8531256Syl150051 /*
8541256Syl150051 * Use beacon control register to control the Link LED.
8551256Syl150051 * Note that, in the case of Xena, beacon control register represents
8561256Syl150051 * the gpio control register. In the case of Herc, LED handling is
8571256Syl150051 * done by beacon control register as opposed to gpio control register
8581256Syl150051 * in Xena.
8591256Syl150051 */
8601256Syl150051 val64 = xge_os_pio_mem_read64(hldev->pdev, hldev->regh0,
8611256Syl150051 &bar0->beacon_control);
8621256Syl150051 val64 ^= XGE_HAL_GPIO_CTRL_GPIO_0;
8631256Syl150051 xge_os_pio_mem_write64(hldev->pdev, hldev->regh0, val64,
8641256Syl150051 &bar0->beacon_control);
8651256Syl150051 }
8661256Syl150051
8671256Syl150051 /**
8681256Syl150051 * xge_hal_read_eeprom - Read 4 bytes of data from user given offset.
8691256Syl150051 * @devh: HAL device handle.
8701256Syl150051 * @off: offset at which the data must be written
8711256Syl150051 * @data: output parameter where the data is stored.
8721256Syl150051 *
8731256Syl150051 * Read 4 bytes of data from the user given offset and return the
8741256Syl150051 * read data.
8751256Syl150051 * Note: will allow to read only part of the EEPROM visible through the
8761256Syl150051 * I2C bus.
8771256Syl150051 * Returns: -1 on failure, 0 on success.
8781256Syl150051 */
8791256Syl150051 xge_hal_status_e
xge_hal_read_eeprom(xge_hal_device_h devh,int off,u32 * data)8803115Syl150051 xge_hal_read_eeprom(xge_hal_device_h devh, int off, u32* data)
8811256Syl150051 {
8821256Syl150051 xge_hal_device_t *hldev = (xge_hal_device_t*)devh;
8833115Syl150051 xge_hal_status_e ret = XGE_HAL_FAIL;
8841256Syl150051 u32 exit_cnt = 0;
8851256Syl150051 u64 val64;
8861256Syl150051 xge_hal_pci_bar0_t *bar0 = (xge_hal_pci_bar0_t *)hldev->bar0;
8871256Syl150051
8881256Syl150051 val64 = XGE_HAL_I2C_CONTROL_DEV_ID(XGE_DEV_ID) |
8891256Syl150051 XGE_HAL_I2C_CONTROL_ADDR(off) |
8901256Syl150051 XGE_HAL_I2C_CONTROL_BYTE_CNT(0x3) |
8911256Syl150051 XGE_HAL_I2C_CONTROL_READ | XGE_HAL_I2C_CONTROL_CNTL_START;
8921256Syl150051
893*6937Sxw161283 __hal_serial_mem_write64(hldev, val64, &bar0->i2c_control);
8941256Syl150051
8951256Syl150051 while (exit_cnt < 5) {
896*6937Sxw161283 val64 = __hal_serial_mem_read64(hldev, &bar0->i2c_control);
8971256Syl150051 if (XGE_HAL_I2C_CONTROL_CNTL_END(val64)) {
8981256Syl150051 *data = XGE_HAL_I2C_CONTROL_GET_DATA(val64);
8991256Syl150051 ret = XGE_HAL_OK;
9001256Syl150051 break;
9011256Syl150051 }
9021256Syl150051 exit_cnt++;
9031256Syl150051 }
9041256Syl150051
9051256Syl150051 return ret;
9061256Syl150051 }
9071256Syl150051
9081256Syl150051 /*
9091256Syl150051 * xge_hal_write_eeprom - actually writes the relevant part of the data
9101256Syl150051 value.
9111256Syl150051 * @devh: HAL device handle.
9121256Syl150051 * @off: offset at which the data must be written
9131256Syl150051 * @data : The data that is to be written
9141256Syl150051 * @cnt : Number of bytes of the data that are actually to be written into
9151256Syl150051 * the Eeprom. (max of 3)
9161256Syl150051 *
9171256Syl150051 * Actually writes the relevant part of the data value into the Eeprom
9181256Syl150051 * through the I2C bus.
9191256Syl150051 * Return value:
9201256Syl150051 * 0 on success, -1 on failure.
9211256Syl150051 */
9221256Syl150051
9231256Syl150051 xge_hal_status_e
xge_hal_write_eeprom(xge_hal_device_h devh,int off,u32 data,int cnt)9241256Syl150051 xge_hal_write_eeprom(xge_hal_device_h devh, int off, u32 data, int cnt)
9251256Syl150051 {
9261256Syl150051 xge_hal_device_t *hldev = (xge_hal_device_t*)devh;
9273115Syl150051 xge_hal_status_e ret = XGE_HAL_FAIL;
9283115Syl150051 u32 exit_cnt = 0;
9291256Syl150051 u64 val64;
9301256Syl150051 xge_hal_pci_bar0_t *bar0 = (xge_hal_pci_bar0_t *)hldev->bar0;
9311256Syl150051
9321256Syl150051 val64 = XGE_HAL_I2C_CONTROL_DEV_ID(XGE_DEV_ID) |
9331256Syl150051 XGE_HAL_I2C_CONTROL_ADDR(off) |
9341256Syl150051 XGE_HAL_I2C_CONTROL_BYTE_CNT(cnt) |
9351256Syl150051 XGE_HAL_I2C_CONTROL_SET_DATA(data) |
9361256Syl150051 XGE_HAL_I2C_CONTROL_CNTL_START;
937*6937Sxw161283 __hal_serial_mem_write64(hldev, val64, &bar0->i2c_control);
9381256Syl150051
9391256Syl150051 while (exit_cnt < 5) {
940*6937Sxw161283 val64 = __hal_serial_mem_read64(hldev, &bar0->i2c_control);
9411256Syl150051 if (XGE_HAL_I2C_CONTROL_CNTL_END(val64)) {
9421256Syl150051 if (!(val64 & XGE_HAL_I2C_CONTROL_NACK))
9431256Syl150051 ret = XGE_HAL_OK;
9441256Syl150051 break;
9451256Syl150051 }
9461256Syl150051 exit_cnt++;
9471256Syl150051 }
9481256Syl150051
9491256Syl150051 return ret;
9501256Syl150051 }
9511256Syl150051
9521256Syl150051 /*
9531256Syl150051 * xge_hal_register_test - reads and writes into all clock domains.
9541256Syl150051 * @hldev : private member of the device structure.
9551256Syl150051 * xge_nic structure.
9561256Syl150051 * @data : variable that returns the result of each of the test conducted b
9571256Syl150051 * by the driver.
9581256Syl150051 *
9591256Syl150051 * Read and write into all clock domains. The NIC has 3 clock domains,
9601256Syl150051 * see that registers in all the three regions are accessible.
9611256Syl150051 * Return value:
9621256Syl150051 * 0 on success.
9631256Syl150051 */
9641256Syl150051 xge_hal_status_e
xge_hal_register_test(xge_hal_device_h devh,u64 * data)9651256Syl150051 xge_hal_register_test(xge_hal_device_h devh, u64 *data)
9661256Syl150051 {
9671256Syl150051 xge_hal_device_t *hldev = (xge_hal_device_t*)devh;
9681256Syl150051 xge_hal_pci_bar0_t *bar0 = (xge_hal_pci_bar0_t *)hldev->bar0;
9691256Syl150051 u64 val64 = 0;
9701256Syl150051 int fail = 0;
9711256Syl150051
9721256Syl150051 val64 = xge_os_pio_mem_read64(hldev->pdev, hldev->regh0,
9731256Syl150051 &bar0->pif_rd_swapper_fb);
9741256Syl150051 if (val64 != 0x123456789abcdefULL) {
9751256Syl150051 fail = 1;
976*6937Sxw161283 xge_debug_osdep(XGE_TRACE, "Read Test level 1 fails");
9771256Syl150051 }
9781256Syl150051
9791256Syl150051 val64 = xge_os_pio_mem_read64(hldev->pdev, hldev->regh0,
9801256Syl150051 &bar0->rmac_pause_cfg);
9811256Syl150051 if (val64 != 0xc000ffff00000000ULL) {
9821256Syl150051 fail = 1;
983*6937Sxw161283 xge_debug_osdep(XGE_TRACE, "Read Test level 2 fails");
9841256Syl150051 }
9851256Syl150051
9861256Syl150051 val64 = xge_os_pio_mem_read64(hldev->pdev, hldev->regh0,
9871256Syl150051 &bar0->rx_queue_cfg);
9881256Syl150051 if (val64 != 0x0808080808080808ULL) {
9891256Syl150051 fail = 1;
990*6937Sxw161283 xge_debug_osdep(XGE_TRACE, "Read Test level 3 fails");
9911256Syl150051 }
9921256Syl150051
9931256Syl150051 val64 = xge_os_pio_mem_read64(hldev->pdev, hldev->regh0,
9941256Syl150051 &bar0->xgxs_efifo_cfg);
9951256Syl150051 if (val64 != 0x000000001923141EULL) {
9961256Syl150051 fail = 1;
997*6937Sxw161283 xge_debug_osdep(XGE_TRACE, "Read Test level 4 fails");
9981256Syl150051 }
9991256Syl150051
10001256Syl150051 val64 = 0x5A5A5A5A5A5A5A5AULL;
10011256Syl150051 xge_os_pio_mem_write64(hldev->pdev, hldev->regh0, val64,
10021256Syl150051 &bar0->xmsi_data);
10031256Syl150051 val64 = xge_os_pio_mem_read64(hldev->pdev, hldev->regh0,
10041256Syl150051 &bar0->xmsi_data);
10051256Syl150051 if (val64 != 0x5A5A5A5A5A5A5A5AULL) {
10061256Syl150051 fail = 1;
1007*6937Sxw161283 xge_debug_osdep(XGE_ERR, "Write Test level 1 fails");
10081256Syl150051 }
10091256Syl150051
10101256Syl150051 val64 = 0xA5A5A5A5A5A5A5A5ULL;
10111256Syl150051 xge_os_pio_mem_write64(hldev->pdev, hldev->regh0, val64,
10121256Syl150051 &bar0->xmsi_data);
10131256Syl150051 val64 = xge_os_pio_mem_read64(hldev->pdev, hldev->regh0,
10141256Syl150051 &bar0->xmsi_data);
10151256Syl150051 if (val64 != 0xA5A5A5A5A5A5A5A5ULL) {
10161256Syl150051 fail = 1;
1017*6937Sxw161283 xge_debug_osdep(XGE_ERR, "Write Test level 2 fails");
10181256Syl150051 }
10191256Syl150051
10201256Syl150051 *data = fail;
10211256Syl150051 return XGE_HAL_OK;
10221256Syl150051 }
10231256Syl150051
10241256Syl150051 /*
10251256Syl150051 * xge_hal_rldram_test - offline test for access to the RldRam chip on
10261256Syl150051 the NIC
10271256Syl150051 * @devh: HAL device handle.
10281256Syl150051 * @data: variable that returns the result of each of the test
10291256Syl150051 * conducted by the driver.
10301256Syl150051 *
10311256Syl150051 * This is one of the offline test that tests the read and write
10321256Syl150051 * access to the RldRam chip on the NIC.
10331256Syl150051 * Return value:
10341256Syl150051 * 0 on success.
10351256Syl150051 */
10361256Syl150051 xge_hal_status_e
xge_hal_rldram_test(xge_hal_device_h devh,u64 * data)10373115Syl150051 xge_hal_rldram_test(xge_hal_device_h devh, u64 *data)
10381256Syl150051 {
10391256Syl150051 xge_hal_device_t *hldev = (xge_hal_device_t*)devh;
10401256Syl150051 xge_hal_pci_bar0_t *bar0 = (xge_hal_pci_bar0_t *)hldev->bar0;
10411256Syl150051 u64 val64;
10421256Syl150051 int cnt, iteration = 0, test_pass = 0;
10431256Syl150051
10441256Syl150051 val64 = xge_os_pio_mem_read64(hldev->pdev, hldev->regh0,
10451256Syl150051 &bar0->adapter_control);
10461256Syl150051 val64 &= ~XGE_HAL_ADAPTER_ECC_EN;
10471256Syl150051 xge_os_pio_mem_write64(hldev->pdev, hldev->regh0, val64,
10481256Syl150051 &bar0->adapter_control);
10491256Syl150051
10501256Syl150051 val64 = xge_os_pio_mem_read64(hldev->pdev, hldev->regh0,
10511256Syl150051 &bar0->mc_rldram_test_ctrl);
10521256Syl150051 val64 |= XGE_HAL_MC_RLDRAM_TEST_MODE;
10531256Syl150051 xge_os_pio_mem_write64(hldev->pdev, hldev->regh0, val64,
10541256Syl150051 &bar0->mc_rldram_test_ctrl);
10551256Syl150051
10561256Syl150051 val64 = xge_os_pio_mem_read64(hldev->pdev, hldev->regh0,
10571256Syl150051 &bar0->mc_rldram_mrs);
10581256Syl150051 val64 |= XGE_HAL_MC_RLDRAM_QUEUE_SIZE_ENABLE;
1059*6937Sxw161283 __hal_serial_mem_write64(hldev, val64, &bar0->i2c_control);
10601256Syl150051
10611256Syl150051 val64 |= XGE_HAL_MC_RLDRAM_MRS_ENABLE;
1062*6937Sxw161283 __hal_serial_mem_write64(hldev, val64, &bar0->i2c_control);
10631256Syl150051
10641256Syl150051 while (iteration < 2) {
10651256Syl150051 val64 = 0x55555555aaaa0000ULL;
10661256Syl150051 if (iteration == 1) {
10671256Syl150051 val64 ^= 0xFFFFFFFFFFFF0000ULL;
10681256Syl150051 }
10691256Syl150051 xge_os_pio_mem_write64(hldev->pdev, hldev->regh0, val64,
10701256Syl150051 &bar0->mc_rldram_test_d0);
10711256Syl150051
10721256Syl150051 val64 = 0xaaaa5a5555550000ULL;
10731256Syl150051 if (iteration == 1) {
10741256Syl150051 val64 ^= 0xFFFFFFFFFFFF0000ULL;
10751256Syl150051 }
10761256Syl150051 xge_os_pio_mem_write64(hldev->pdev, hldev->regh0, val64,
10771256Syl150051 &bar0->mc_rldram_test_d1);
10781256Syl150051
10791256Syl150051 val64 = 0x55aaaaaaaa5a0000ULL;
10801256Syl150051 if (iteration == 1) {
10811256Syl150051 val64 ^= 0xFFFFFFFFFFFF0000ULL;
10821256Syl150051 }
10831256Syl150051 xge_os_pio_mem_write64(hldev->pdev, hldev->regh0, val64,
10841256Syl150051 &bar0->mc_rldram_test_d2);
10851256Syl150051
10861256Syl150051 val64 = (u64) (0x0000003fffff0000ULL);
10871256Syl150051 xge_os_pio_mem_write64(hldev->pdev, hldev->regh0, val64,
10881256Syl150051 &bar0->mc_rldram_test_add);
10891256Syl150051
10901256Syl150051
10911256Syl150051 val64 = XGE_HAL_MC_RLDRAM_TEST_MODE;
10921256Syl150051 xge_os_pio_mem_write64(hldev->pdev, hldev->regh0, val64,
10931256Syl150051 &bar0->mc_rldram_test_ctrl);
10941256Syl150051
10951256Syl150051 val64 |=
10961256Syl150051 XGE_HAL_MC_RLDRAM_TEST_MODE | XGE_HAL_MC_RLDRAM_TEST_WRITE |
10971256Syl150051 XGE_HAL_MC_RLDRAM_TEST_GO;
10981256Syl150051 xge_os_pio_mem_write64(hldev->pdev, hldev->regh0, val64,
10991256Syl150051 &bar0->mc_rldram_test_ctrl);
11001256Syl150051
11011256Syl150051 for (cnt = 0; cnt < 5; cnt++) {
11021256Syl150051 val64 = xge_os_pio_mem_read64(hldev->pdev,
11031256Syl150051 hldev->regh0, &bar0->mc_rldram_test_ctrl);
11041256Syl150051 if (val64 & XGE_HAL_MC_RLDRAM_TEST_DONE)
11051256Syl150051 break;
11061256Syl150051 xge_os_mdelay(200);
11071256Syl150051 }
11081256Syl150051
11091256Syl150051 if (cnt == 5)
11101256Syl150051 break;
11111256Syl150051
11121256Syl150051 val64 = XGE_HAL_MC_RLDRAM_TEST_MODE;
11131256Syl150051 xge_os_pio_mem_write64(hldev->pdev, hldev->regh0, val64,
11141256Syl150051 &bar0->mc_rldram_test_ctrl);
11151256Syl150051
11161256Syl150051 val64 |= XGE_HAL_MC_RLDRAM_TEST_MODE |
11171256Syl150051 XGE_HAL_MC_RLDRAM_TEST_GO;
11181256Syl150051 xge_os_pio_mem_write64(hldev->pdev, hldev->regh0, val64,
11191256Syl150051 &bar0->mc_rldram_test_ctrl);
11201256Syl150051
11211256Syl150051 for (cnt = 0; cnt < 5; cnt++) {
11221256Syl150051 val64 = xge_os_pio_mem_read64(hldev->pdev,
11231256Syl150051 hldev->regh0, &bar0->mc_rldram_test_ctrl);
11241256Syl150051 if (val64 & XGE_HAL_MC_RLDRAM_TEST_DONE)
11251256Syl150051 break;
11261256Syl150051 xge_os_mdelay(500);
11271256Syl150051 }
11281256Syl150051
11291256Syl150051 if (cnt == 5)
11301256Syl150051 break;
11311256Syl150051
11321256Syl150051 val64 = xge_os_pio_mem_read64(hldev->pdev, hldev->regh0,
11331256Syl150051 &bar0->mc_rldram_test_ctrl);
11341256Syl150051 if (val64 & XGE_HAL_MC_RLDRAM_TEST_PASS)
11351256Syl150051 test_pass = 1;
11361256Syl150051
11371256Syl150051 iteration++;
11381256Syl150051 }
11391256Syl150051
11401256Syl150051 if (!test_pass)
11411256Syl150051 *data = 1;
11421256Syl150051 else
11431256Syl150051 *data = 0;
11441256Syl150051
11451256Syl150051 return XGE_HAL_OK;
11461256Syl150051 }
11471256Syl150051
11481256Syl150051 /*
11493115Syl150051 * xge_hal_pma_loopback - Enable or disable PMA loopback
11503115Syl150051 * @devh: HAL device handle.
11513115Syl150051 * @enable:Boolean set to 1 to enable and 0 to disable.
11523115Syl150051 *
11533115Syl150051 * Enable or disable PMA loopback.
11543115Syl150051 * Return value:
11553115Syl150051 * 0 on success.
11563115Syl150051 */
11573115Syl150051 xge_hal_status_e
xge_hal_pma_loopback(xge_hal_device_h devh,int enable)11583115Syl150051 xge_hal_pma_loopback( xge_hal_device_h devh, int enable )
11593115Syl150051 {
11603115Syl150051 xge_hal_device_t *hldev = (xge_hal_device_t*)devh;
11613115Syl150051 xge_hal_pci_bar0_t *bar0 = (xge_hal_pci_bar0_t *)hldev->bar0;
11623115Syl150051 u64 val64;
11633115Syl150051 u16 data;
11643115Syl150051
11653115Syl150051 /*
11663115Syl150051 * This code if for MAC loopbak
11673115Syl150051 * Should be enabled through another parameter
11683115Syl150051 */
11693115Syl150051 #if 0
11703115Syl150051 val64 = xge_os_pio_mem_read64(hldev->pdev, hldev->regh0,
11713115Syl150051 &bar0->mac_cfg);
11723115Syl150051 if ( enable )
11733115Syl150051 {
11743115Syl150051 val64 |= ( XGE_HAL_MAC_CFG_TMAC_LOOPBACK | XGE_HAL_MAC_CFG_RMAC_PROM_ENABLE );
11753115Syl150051 }
11763115Syl150051 __hal_pio_mem_write32_upper(hldev->pdev, hldev->regh0,
11773115Syl150051 (u32)(val64 >> 32), (char*)&bar0->mac_cfg);
11783115Syl150051 xge_os_mdelay(1);
11793115Syl150051 #endif
11803115Syl150051
11813115Syl150051 val64 = XGE_HAL_MDIO_CONTROL_MMD_INDX_ADDR(0) |
11823115Syl150051 XGE_HAL_MDIO_CONTROL_MMD_DEV_ADDR(1) |
11833115Syl150051 XGE_HAL_MDIO_CONTROL_MMD_PRT_ADDR(0) |
11843115Syl150051 XGE_HAL_MDIO_CONTROL_MMD_CTRL(0) |
11853115Syl150051 XGE_HAL_MDIO_CONTROL_MMD_OP(XGE_HAL_MDIO_OP_ADDRESS);
1186*6937Sxw161283 __hal_serial_mem_write64(hldev, val64, &bar0->mdio_control);
1187*6937Sxw161283
11883115Syl150051 val64 |= XGE_HAL_MDIO_CONTROL_MMD_CTRL(XGE_HAL_MDIO_CTRL_START);
1189*6937Sxw161283 __hal_serial_mem_write64(hldev, val64, &bar0->mdio_control);
11903115Syl150051
11913115Syl150051 val64 = XGE_HAL_MDIO_CONTROL_MMD_INDX_ADDR(0) |
11923115Syl150051 XGE_HAL_MDIO_CONTROL_MMD_DEV_ADDR(1) |
11933115Syl150051 XGE_HAL_MDIO_CONTROL_MMD_PRT_ADDR(0) |
11943115Syl150051 XGE_HAL_MDIO_CONTROL_MMD_CTRL(0) |
11953115Syl150051 XGE_HAL_MDIO_CONTROL_MMD_OP(XGE_HAL_MDIO_OP_READ);
1196*6937Sxw161283 __hal_serial_mem_write64(hldev, val64, &bar0->mdio_control);
1197*6937Sxw161283
11983115Syl150051 val64 |= XGE_HAL_MDIO_CONTROL_MMD_CTRL(XGE_HAL_MDIO_CTRL_START);
1199*6937Sxw161283 __hal_serial_mem_write64(hldev, val64, &bar0->mdio_control);
12003115Syl150051
1201*6937Sxw161283 val64 = __hal_serial_mem_read64(hldev, &bar0->mdio_control);
12023115Syl150051
12033115Syl150051 data = (u16)XGE_HAL_MDIO_CONTROL_MMD_DATA_GET(val64);
12043115Syl150051
12053115Syl150051 #define _HAL_LOOPBK_PMA 1
12063115Syl150051
12073115Syl150051 if( enable )
12083115Syl150051 data |= 1;
12093115Syl150051 else
12103115Syl150051 data &= 0xfe;
12113115Syl150051
12123115Syl150051 val64 = XGE_HAL_MDIO_CONTROL_MMD_INDX_ADDR(0) |
12133115Syl150051 XGE_HAL_MDIO_CONTROL_MMD_DEV_ADDR(1) |
12143115Syl150051 XGE_HAL_MDIO_CONTROL_MMD_PRT_ADDR(0) |
12153115Syl150051 XGE_HAL_MDIO_CONTROL_MMD_CTRL(0) |
12163115Syl150051 XGE_HAL_MDIO_CONTROL_MMD_OP(XGE_HAL_MDIO_OP_ADDRESS);
1217*6937Sxw161283 __hal_serial_mem_write64(hldev, val64, &bar0->mdio_control);
1218*6937Sxw161283
12193115Syl150051 val64 |= XGE_HAL_MDIO_CONTROL_MMD_CTRL(XGE_HAL_MDIO_CTRL_START);
1220*6937Sxw161283 __hal_serial_mem_write64(hldev, val64, &bar0->mdio_control);
12213115Syl150051
12223115Syl150051 val64 = XGE_HAL_MDIO_CONTROL_MMD_INDX_ADDR(0) |
12233115Syl150051 XGE_HAL_MDIO_CONTROL_MMD_DEV_ADDR(1) |
12243115Syl150051 XGE_HAL_MDIO_CONTROL_MMD_PRT_ADDR(0) |
12253115Syl150051 XGE_HAL_MDIO_CONTROL_MMD_DATA(data) |
12263115Syl150051 XGE_HAL_MDIO_CONTROL_MMD_CTRL(0x0) |
12273115Syl150051 XGE_HAL_MDIO_CONTROL_MMD_OP(XGE_HAL_MDIO_OP_WRITE);
1228*6937Sxw161283 __hal_serial_mem_write64(hldev, val64, &bar0->mdio_control);
1229*6937Sxw161283
12303115Syl150051 val64 |= XGE_HAL_MDIO_CONTROL_MMD_CTRL(XGE_HAL_MDIO_CTRL_START);
1231*6937Sxw161283 __hal_serial_mem_write64(hldev, val64, &bar0->mdio_control);
12323115Syl150051
12333115Syl150051 val64 = XGE_HAL_MDIO_CONTROL_MMD_INDX_ADDR(0) |
12343115Syl150051 XGE_HAL_MDIO_CONTROL_MMD_DEV_ADDR(1) |
12353115Syl150051 XGE_HAL_MDIO_CONTROL_MMD_PRT_ADDR(0) |
12363115Syl150051 XGE_HAL_MDIO_CONTROL_MMD_CTRL(0x0) |
12373115Syl150051 XGE_HAL_MDIO_CONTROL_MMD_OP(XGE_HAL_MDIO_OP_READ);
1238*6937Sxw161283 __hal_serial_mem_write64(hldev, val64, &bar0->mdio_control);
1239*6937Sxw161283
12403115Syl150051 val64 |= XGE_HAL_MDIO_CONTROL_MMD_CTRL(XGE_HAL_MDIO_CTRL_START);
1241*6937Sxw161283 __hal_serial_mem_write64(hldev, val64, &bar0->mdio_control);
12423115Syl150051
12433115Syl150051 return XGE_HAL_OK;
12443115Syl150051 }
12453115Syl150051
12463115Syl150051 u16
xge_hal_mdio_read(xge_hal_device_h devh,u32 mmd_type,u64 addr)12473115Syl150051 xge_hal_mdio_read( xge_hal_device_h devh, u32 mmd_type, u64 addr )
12483115Syl150051 {
12493115Syl150051 xge_hal_device_t *hldev = (xge_hal_device_t*)devh;
12503115Syl150051 xge_hal_pci_bar0_t *bar0 = (xge_hal_pci_bar0_t *)hldev->bar0;
12513115Syl150051 u64 val64 = 0x0;
12523115Syl150051 u16 rval16 = 0x0;
12533115Syl150051 u8 i = 0;
12543115Syl150051
12553115Syl150051 /* address transaction */
12563115Syl150051 val64 = XGE_HAL_MDIO_CONTROL_MMD_INDX_ADDR(addr) |
12573115Syl150051 XGE_HAL_MDIO_CONTROL_MMD_DEV_ADDR(mmd_type) |
12583115Syl150051 XGE_HAL_MDIO_CONTROL_MMD_PRT_ADDR(0) |
12593115Syl150051 XGE_HAL_MDIO_CONTROL_MMD_OP(XGE_HAL_MDIO_OP_ADDRESS);
1260*6937Sxw161283 __hal_serial_mem_write64(hldev, val64, &bar0->mdio_control);
12613115Syl150051
12623115Syl150051 val64 |= XGE_HAL_MDIO_CONTROL_MMD_CTRL(XGE_HAL_MDIO_CTRL_START);
1263*6937Sxw161283 __hal_serial_mem_write64(hldev, val64, &bar0->mdio_control);
12643115Syl150051 do
12653115Syl150051 {
1266*6937Sxw161283 val64 = __hal_serial_mem_read64(hldev, &bar0->mdio_control);
12673115Syl150051 if (i++ > 10)
12683115Syl150051 {
12693115Syl150051 break;
12703115Syl150051 }
12713115Syl150051 }while((val64 & XGE_HAL_MDIO_CONTROL_MMD_CTRL(0xF)) != XGE_HAL_MDIO_CONTROL_MMD_CTRL(1));
12723115Syl150051
12733115Syl150051 /* Data transaction */
12743115Syl150051 val64 = XGE_HAL_MDIO_CONTROL_MMD_INDX_ADDR(addr) |
12753115Syl150051 XGE_HAL_MDIO_CONTROL_MMD_DEV_ADDR(mmd_type) |
12763115Syl150051 XGE_HAL_MDIO_CONTROL_MMD_PRT_ADDR(0) |
12773115Syl150051 XGE_HAL_MDIO_CONTROL_MMD_OP(XGE_HAL_MDIO_OP_READ);
1278*6937Sxw161283 __hal_serial_mem_write64(hldev, val64, &bar0->mdio_control);
12793115Syl150051
12803115Syl150051 val64 |= XGE_HAL_MDIO_CONTROL_MMD_CTRL(XGE_HAL_MDIO_CTRL_START);
1281*6937Sxw161283 __hal_serial_mem_write64(hldev, val64, &bar0->mdio_control);
12823115Syl150051
12833115Syl150051 i = 0;
12843115Syl150051
12853115Syl150051 do
12863115Syl150051 {
1287*6937Sxw161283 val64 = __hal_serial_mem_read64(hldev, &bar0->mdio_control);
12883115Syl150051 if (i++ > 10)
12893115Syl150051 {
12903115Syl150051 break;
12913115Syl150051 }
12923115Syl150051 }while((val64 & XGE_HAL_MDIO_CONTROL_MMD_CTRL(0xF)) != XGE_HAL_MDIO_CONTROL_MMD_CTRL(1));
12933115Syl150051
12943115Syl150051 rval16 = (u16)XGE_HAL_MDIO_CONTROL_MMD_DATA_GET(val64);
12953115Syl150051
12963115Syl150051 return rval16;
12973115Syl150051 }
12983115Syl150051
12993115Syl150051 xge_hal_status_e
xge_hal_mdio_write(xge_hal_device_h devh,u32 mmd_type,u64 addr,u32 value)13003115Syl150051 xge_hal_mdio_write( xge_hal_device_h devh, u32 mmd_type, u64 addr, u32 value )
13013115Syl150051 {
13023115Syl150051 u64 val64 = 0x0;
13033115Syl150051 xge_hal_device_t *hldev = (xge_hal_device_t*)devh;
13043115Syl150051 xge_hal_pci_bar0_t *bar0 = (xge_hal_pci_bar0_t *)hldev->bar0;
13053115Syl150051 u8 i = 0;
13063115Syl150051 /* address transaction */
13073115Syl150051
13083115Syl150051 val64 = XGE_HAL_MDIO_CONTROL_MMD_INDX_ADDR(addr) |
13093115Syl150051 XGE_HAL_MDIO_CONTROL_MMD_DEV_ADDR(mmd_type) |
13103115Syl150051 XGE_HAL_MDIO_CONTROL_MMD_PRT_ADDR(0) |
13113115Syl150051 XGE_HAL_MDIO_CONTROL_MMD_OP(XGE_HAL_MDIO_OP_ADDRESS);
1312*6937Sxw161283 __hal_serial_mem_write64(hldev, val64, &bar0->mdio_control);
13133115Syl150051
13143115Syl150051 val64 |= XGE_HAL_MDIO_CONTROL_MMD_CTRL(XGE_HAL_MDIO_CTRL_START);
1315*6937Sxw161283 __hal_serial_mem_write64(hldev, val64, &bar0->mdio_control);
13163115Syl150051
13173115Syl150051 do
13183115Syl150051 {
1319*6937Sxw161283 val64 = __hal_serial_mem_read64(hldev, &bar0->mdio_control);
13203115Syl150051 if (i++ > 10)
13213115Syl150051 {
13223115Syl150051 break;
13233115Syl150051 }
13243115Syl150051 } while((val64 & XGE_HAL_MDIO_CONTROL_MMD_CTRL(0xF)) !=
13253115Syl150051 XGE_HAL_MDIO_CONTROL_MMD_CTRL(1));
13263115Syl150051
13273115Syl150051 /* Data transaction */
13283115Syl150051
13293115Syl150051 val64 = 0x0;
13303115Syl150051
13313115Syl150051 val64 = XGE_HAL_MDIO_CONTROL_MMD_INDX_ADDR(addr) |
13323115Syl150051 XGE_HAL_MDIO_CONTROL_MMD_DEV_ADDR(mmd_type) |
13333115Syl150051 XGE_HAL_MDIO_CONTROL_MMD_PRT_ADDR(0) |
13343115Syl150051 XGE_HAL_MDIO_CONTROL_MMD_DATA(value) |
13353115Syl150051 XGE_HAL_MDIO_CONTROL_MMD_OP(XGE_HAL_MDIO_OP_WRITE);
1336*6937Sxw161283 __hal_serial_mem_write64(hldev, val64, &bar0->mdio_control);
13373115Syl150051
13383115Syl150051 val64 |= XGE_HAL_MDIO_CONTROL_MMD_CTRL(XGE_HAL_MDIO_CTRL_START);
1339*6937Sxw161283 __hal_serial_mem_write64(hldev, val64, &bar0->mdio_control);
13403115Syl150051
13413115Syl150051 i = 0;
13423115Syl150051
13433115Syl150051 do
13443115Syl150051 {
1345*6937Sxw161283 val64 = __hal_serial_mem_read64(hldev, &bar0->mdio_control);
13463115Syl150051 if (i++ > 10)
13473115Syl150051 {
13483115Syl150051 break;
13493115Syl150051 }
13503115Syl150051 }while((val64 & XGE_HAL_MDIO_CONTROL_MMD_CTRL(0xF)) != XGE_HAL_MDIO_CONTROL_MMD_CTRL(1));
13513115Syl150051
13523115Syl150051 return XGE_HAL_OK;
13533115Syl150051 }
13543115Syl150051
13553115Syl150051 /*
13561256Syl150051 * xge_hal_eeprom_test - to verify that EEprom in the xena can be
13571256Syl150051 programmed.
13581256Syl150051 * @devh: HAL device handle.
13591256Syl150051 * @data:variable that returns the result of each of the test conducted by
13601256Syl150051 * the driver.
13611256Syl150051 *
13621256Syl150051 * Verify that EEPROM in the xena can be programmed using I2C_CONTROL
13631256Syl150051 * register.
13641256Syl150051 * Return value:
13651256Syl150051 * 0 on success.
13661256Syl150051 */
13671256Syl150051 xge_hal_status_e
xge_hal_eeprom_test(xge_hal_device_h devh,u64 * data)13681256Syl150051 xge_hal_eeprom_test(xge_hal_device_h devh, u64 *data)
13691256Syl150051 {
13701256Syl150051 xge_hal_device_t *hldev = (xge_hal_device_t*)devh;
1371*6937Sxw161283 int fail = 0;
1372*6937Sxw161283 u32 ret_data = 0;
13731256Syl150051
13741256Syl150051 /* Test Write Error at offset 0 */
13751256Syl150051 if (!xge_hal_write_eeprom(hldev, 0, 0, 3))
13761256Syl150051 fail = 1;
13771256Syl150051
13781256Syl150051 /* Test Write at offset 4f0 */
13791256Syl150051 if (xge_hal_write_eeprom(hldev, 0x4F0, 0x01234567, 3))
13801256Syl150051 fail = 1;
13811256Syl150051 if (xge_hal_read_eeprom(hldev, 0x4F0, &ret_data))
13821256Syl150051 fail = 1;
13831256Syl150051
13841256Syl150051 if (ret_data != 0x01234567)
13851256Syl150051 fail = 1;
13861256Syl150051
13871256Syl150051 /* Reset the EEPROM data go FFFF */
13881256Syl150051 (void) xge_hal_write_eeprom(hldev, 0x4F0, 0xFFFFFFFF, 3);
13891256Syl150051
13901256Syl150051 /* Test Write Request Error at offset 0x7c */
13911256Syl150051 if (!xge_hal_write_eeprom(hldev, 0x07C, 0, 3))
13921256Syl150051 fail = 1;
13931256Syl150051
13941256Syl150051 /* Test Write Request at offset 0x7fc */
13951256Syl150051 if (xge_hal_write_eeprom(hldev, 0x7FC, 0x01234567, 3))
13961256Syl150051 fail = 1;
13971256Syl150051 if (xge_hal_read_eeprom(hldev, 0x7FC, &ret_data))
13981256Syl150051 fail = 1;
13991256Syl150051
14001256Syl150051 if (ret_data != 0x01234567)
14011256Syl150051 fail = 1;
14021256Syl150051
14031256Syl150051 /* Reset the EEPROM data go FFFF */
14041256Syl150051 (void) xge_hal_write_eeprom(hldev, 0x7FC, 0xFFFFFFFF, 3);
14051256Syl150051
14061256Syl150051 /* Test Write Error at offset 0x80 */
14071256Syl150051 if (!xge_hal_write_eeprom(hldev, 0x080, 0, 3))
14081256Syl150051 fail = 1;
14091256Syl150051
14101256Syl150051 /* Test Write Error at offset 0xfc */
14111256Syl150051 if (!xge_hal_write_eeprom(hldev, 0x0FC, 0, 3))
14121256Syl150051 fail = 1;
14131256Syl150051
14141256Syl150051 /* Test Write Error at offset 0x100 */
14151256Syl150051 if (!xge_hal_write_eeprom(hldev, 0x100, 0, 3))
14161256Syl150051 fail = 1;
14171256Syl150051
14181256Syl150051 /* Test Write Error at offset 4ec */
14191256Syl150051 if (!xge_hal_write_eeprom(hldev, 0x4EC, 0, 3))
14201256Syl150051 fail = 1;
14211256Syl150051
14221256Syl150051 *data = fail;
14231256Syl150051 return XGE_HAL_OK;
14241256Syl150051 }
14251256Syl150051
14261256Syl150051 /*
14271256Syl150051 * xge_hal_bist_test - invokes the MemBist test of the card .
14281256Syl150051 * @devh: HAL device handle.
14291256Syl150051 * xge_nic structure.
14301256Syl150051 * @data:variable that returns the result of each of the test conducted by
14311256Syl150051 * the driver.
14321256Syl150051 *
14331256Syl150051 * This invokes the MemBist test of the card. We give around
14341256Syl150051 * 2 secs time for the Test to complete. If it's still not complete
14351256Syl150051 * within this peiod, we consider that the test failed.
14361256Syl150051 * Return value:
14371256Syl150051 * 0 on success and -1 on failure.
14381256Syl150051 */
14391256Syl150051 xge_hal_status_e
xge_hal_bist_test(xge_hal_device_h devh,u64 * data)14401256Syl150051 xge_hal_bist_test(xge_hal_device_h devh, u64 *data)
14411256Syl150051 {
14421256Syl150051 xge_hal_device_t *hldev = (xge_hal_device_t*)devh;
14431256Syl150051 u8 bist = 0;
14443115Syl150051 int cnt = 0;
14453115Syl150051 xge_hal_status_e ret = XGE_HAL_FAIL;
14461256Syl150051
14471256Syl150051 xge_os_pci_read8(hldev->pdev, hldev->cfgh, 0x0f, &bist);
14481256Syl150051 bist |= 0x40;
14491256Syl150051 xge_os_pci_write8(hldev->pdev, hldev->cfgh, 0x0f, bist);
14501256Syl150051
14511256Syl150051 while (cnt < 20) {
14521256Syl150051 xge_os_pci_read8(hldev->pdev, hldev->cfgh, 0x0f, &bist);
14531256Syl150051 if (!(bist & 0x40)) {
14541256Syl150051 *data = (bist & 0x0f);
14551256Syl150051 ret = XGE_HAL_OK;
14561256Syl150051 break;
14571256Syl150051 }
14581256Syl150051 xge_os_mdelay(100);
14591256Syl150051 cnt++;
14601256Syl150051 }
14611256Syl150051
14621256Syl150051 return ret;
14631256Syl150051 }
14641256Syl150051
14651256Syl150051 /*
14661256Syl150051 * xge_hal_link_test - verifies the link state of the nic
14671256Syl150051 * @devh: HAL device handle.
14681256Syl150051 * @data: variable that returns the result of each of the test conducted by
14691256Syl150051 * the driver.
14701256Syl150051 *
14711256Syl150051 * Verify the link state of the NIC and updates the input
14721256Syl150051 * argument 'data' appropriately.
14731256Syl150051 * Return value:
14741256Syl150051 * 0 on success.
14751256Syl150051 */
14761256Syl150051 xge_hal_status_e
xge_hal_link_test(xge_hal_device_h devh,u64 * data)14771256Syl150051 xge_hal_link_test(xge_hal_device_h devh, u64 *data)
14781256Syl150051 {
14791256Syl150051 xge_hal_device_t *hldev = (xge_hal_device_t*)devh;
14801256Syl150051 xge_hal_pci_bar0_t *bar0 = (xge_hal_pci_bar0_t *)hldev->bar0;
14811256Syl150051 u64 val64;
14821256Syl150051
14831256Syl150051 val64 = xge_os_pio_mem_read64(hldev->pdev, hldev->regh0,
14841256Syl150051 &bar0->adapter_status);
14851256Syl150051 if (val64 & XGE_HAL_ADAPTER_STATUS_RMAC_LOCAL_FAULT)
14861256Syl150051 *data = 1;
14871256Syl150051
14881256Syl150051 return XGE_HAL_OK;
14891256Syl150051 }
14901256Syl150051
14911256Syl150051
14921256Syl150051 /**
14931256Syl150051 * xge_hal_getpause_data -Pause frame frame generation and reception.
14941256Syl150051 * @devh: HAL device handle.
14951256Syl150051 * @tx : A field to return the pause generation capability of the NIC.
14961256Syl150051 * @rx : A field to return the pause reception capability of the NIC.
14971256Syl150051 *
14981256Syl150051 * Returns the Pause frame generation and reception capability of the NIC.
14991256Syl150051 * Return value:
15001256Syl150051 * void
15011256Syl150051 */
xge_hal_getpause_data(xge_hal_device_h devh,int * tx,int * rx)15021256Syl150051 void xge_hal_getpause_data(xge_hal_device_h devh, int *tx, int *rx)
15031256Syl150051 {
15041256Syl150051 xge_hal_device_t *hldev = (xge_hal_device_t*)devh;
15051256Syl150051 xge_hal_pci_bar0_t *bar0 = (xge_hal_pci_bar0_t *)hldev->bar0;
15061256Syl150051 u64 val64;
15071256Syl150051
15081256Syl150051 val64 = xge_os_pio_mem_read64(hldev->pdev, hldev->regh0,
15091256Syl150051 &bar0->rmac_pause_cfg);
15101256Syl150051 if (val64 & XGE_HAL_RMAC_PAUSE_GEN_EN)
15111256Syl150051 *tx = 1;
15121256Syl150051 if (val64 & XGE_HAL_RMAC_PAUSE_RCV_EN)
15131256Syl150051 *rx = 1;
15141256Syl150051 }
15151256Syl150051
15161256Syl150051 /**
15171256Syl150051 * xge_hal_setpause_data - set/reset pause frame generation.
15181256Syl150051 * @devh: HAL device handle.
15191256Syl150051 * @tx: A field that indicates the pause generation capability to be
15201256Syl150051 * set on the NIC.
15211256Syl150051 * @rx: A field that indicates the pause reception capability to be
15221256Syl150051 * set on the NIC.
15231256Syl150051 *
15241256Syl150051 * It can be used to set or reset Pause frame generation or reception
15251256Syl150051 * support of the NIC.
15261256Syl150051 * Return value:
15271256Syl150051 * int, returns 0 on Success
15281256Syl150051 */
15291256Syl150051
xge_hal_setpause_data(xge_hal_device_h devh,int tx,int rx)15301256Syl150051 int xge_hal_setpause_data(xge_hal_device_h devh, int tx, int rx)
15311256Syl150051 {
15321256Syl150051 xge_hal_device_t *hldev = (xge_hal_device_t*)devh;
15331256Syl150051 xge_hal_pci_bar0_t *bar0 = (xge_hal_pci_bar0_t *)hldev->bar0;
15341256Syl150051 u64 val64;
15351256Syl150051
15361256Syl150051 val64 = xge_os_pio_mem_read64(hldev->pdev, hldev->regh0,
15371256Syl150051 &bar0->rmac_pause_cfg);
15381256Syl150051 if (tx)
15391256Syl150051 val64 |= XGE_HAL_RMAC_PAUSE_GEN_EN;
15401256Syl150051 else
15411256Syl150051 val64 &= ~XGE_HAL_RMAC_PAUSE_GEN_EN;
15421256Syl150051 if (rx)
15431256Syl150051 val64 |= XGE_HAL_RMAC_PAUSE_RCV_EN;
15441256Syl150051 else
15451256Syl150051 val64 &= ~XGE_HAL_RMAC_PAUSE_RCV_EN;
15461256Syl150051 xge_os_pio_mem_write64(hldev->pdev, hldev->regh0,
15471256Syl150051 val64, &bar0->rmac_pause_cfg);
15481256Syl150051 return 0;
15491256Syl150051 }
15501256Syl150051
15513115Syl150051 /**
15523115Syl150051 * xge_hal_read_xfp_current_temp -
15533115Syl150051 * @hldev: HAL device handle.
15543115Syl150051 *
15553115Syl150051 * This routine only gets the temperature for XFP modules. Also, updating of the
15563115Syl150051 * NVRAM can sometimes fail and so the reading we might get may not be uptodate.
15573115Syl150051 */
xge_hal_read_xfp_current_temp(xge_hal_device_h hldev)15583115Syl150051 u32 xge_hal_read_xfp_current_temp(xge_hal_device_h hldev)
15593115Syl150051 {
15603115Syl150051 u16 val_1, val_2, i = 0;
15613115Syl150051 u32 actual;
15623115Syl150051
15633115Syl150051 /* First update the NVRAM table of XFP. */
15643115Syl150051
15653115Syl150051 (void) xge_hal_mdio_write(hldev, XGE_HAL_MDIO_MMD_PMA_DEV_ADDR, 0x8000, 0x3);
15663115Syl150051
15673115Syl150051
15683115Syl150051 /* Now wait for the transfer to complete */
15693115Syl150051 do
15703115Syl150051 {
15713115Syl150051 xge_os_mdelay( 50 ); // wait 50 milliseonds
15723115Syl150051
15733115Syl150051 val_1 = xge_hal_mdio_read(hldev, XGE_HAL_MDIO_MMD_PMA_DEV_ADDR, 0x8000);
15743115Syl150051
15753115Syl150051 if ( i++ > 10 )
15763115Syl150051 {
15773115Syl150051 // waited 500 ms which should be plenty of time.
15783115Syl150051 break;
15793115Syl150051 }
15803115Syl150051 }while (( val_1 & 0x000C ) != 0x0004);
15813115Syl150051
15823115Syl150051 /* Now NVRAM table of XFP should be updated, so read the temp */
15833115Syl150051 val_1 = (u8) xge_hal_mdio_read(hldev, XGE_HAL_MDIO_MMD_PMA_DEV_ADDR, 0x8067);
15843115Syl150051 val_2 = (u8) xge_hal_mdio_read(hldev, XGE_HAL_MDIO_MMD_PMA_DEV_ADDR, 0x8068);
15853115Syl150051
15863115Syl150051 actual = ((val_1 << 8) | val_2);
15873115Syl150051
15883115Syl150051 if (actual >= 32768)
15893115Syl150051 actual = actual- 65536;
15903115Syl150051 actual = actual/256;
15913115Syl150051
15923115Syl150051 return actual;
15933115Syl150051 }
15943115Syl150051
15953115Syl150051 /**
15963115Syl150051 * __hal_chk_xpak_counter - check the Xpak error count and log the msg.
15973115Syl150051 * @hldev: pointer to xge_hal_device_t structure
15983115Syl150051 * @type: xpak stats error type
15993115Syl150051 * @value: xpak stats value
16003115Syl150051 *
16013115Syl150051 * It is used to log the error message based on the xpak stats value
16023115Syl150051 * Return value:
16033115Syl150051 * None
16043115Syl150051 */
16053115Syl150051
__hal_chk_xpak_counter(xge_hal_device_t * hldev,int type,u32 value)16063115Syl150051 void __hal_chk_xpak_counter(xge_hal_device_t *hldev, int type, u32 value)
16073115Syl150051 {
1608*6937Sxw161283 /*
16093115Syl150051 * If the value is high for three consecutive cylce,
16103115Syl150051 * log a error message
16113115Syl150051 */
16123115Syl150051 if(value == 3)
16133115Syl150051 {
16143115Syl150051 switch(type)
16153115Syl150051 {
16163115Syl150051 case 1:
16173115Syl150051 hldev->stats.sw_dev_err_stats.xpak_counter.
16183115Syl150051 excess_temp = 0;
16193115Syl150051
16203115Syl150051 /*
16213115Syl150051 * Notify the ULD on Excess Xpak temperature alarm msg
16223115Syl150051 */
16233115Syl150051 if (g_xge_hal_driver->uld_callbacks.xpak_alarm_log) {
16243115Syl150051 g_xge_hal_driver->uld_callbacks.xpak_alarm_log(
16253115Syl150051 hldev->upper_layer_info,
16263115Syl150051 XGE_HAL_XPAK_ALARM_EXCESS_TEMP);
16273115Syl150051 }
16283115Syl150051 break;
16293115Syl150051 case 2:
16303115Syl150051 hldev->stats.sw_dev_err_stats.xpak_counter.
16313115Syl150051 excess_bias_current = 0;
16323115Syl150051
16333115Syl150051 /*
16343115Syl150051 * Notify the ULD on Excess xpak bias current alarm msg
16353115Syl150051 */
16363115Syl150051 if (g_xge_hal_driver->uld_callbacks.xpak_alarm_log) {
16373115Syl150051 g_xge_hal_driver->uld_callbacks.xpak_alarm_log(
16383115Syl150051 hldev->upper_layer_info,
16393115Syl150051 XGE_HAL_XPAK_ALARM_EXCESS_BIAS_CURRENT);
16403115Syl150051 }
16413115Syl150051 break;
16423115Syl150051 case 3:
16433115Syl150051 hldev->stats.sw_dev_err_stats.xpak_counter.
16443115Syl150051 excess_laser_output = 0;
16453115Syl150051
16463115Syl150051 /*
1647*6937Sxw161283 * Notify the ULD on Excess Xpak Laser o/p power
16483115Syl150051 * alarm msg
16493115Syl150051 */
16503115Syl150051 if (g_xge_hal_driver->uld_callbacks.xpak_alarm_log) {
16513115Syl150051 g_xge_hal_driver->uld_callbacks.xpak_alarm_log(
16523115Syl150051 hldev->upper_layer_info,
16533115Syl150051 XGE_HAL_XPAK_ALARM_EXCESS_LASER_OUTPUT);
16543115Syl150051 }
16553115Syl150051 break;
16563115Syl150051 default:
16573115Syl150051 xge_debug_osdep(XGE_TRACE, "Incorrect XPAK Alarm "
1658*6937Sxw161283 "type ");
16593115Syl150051 }
1660*6937Sxw161283 }
16613115Syl150051
16623115Syl150051 }
16633115Syl150051
16643115Syl150051 /**
16653115Syl150051 * __hal_updt_stats_xpak - update the Xpak error count.
16663115Syl150051 * @hldev: pointer to xge_hal_device_t structure
16673115Syl150051 *
16683115Syl150051 * It is used to update the xpak stats value
16693115Syl150051 * Return value:
16703115Syl150051 * None
16713115Syl150051 */
__hal_updt_stats_xpak(xge_hal_device_t * hldev)16723115Syl150051 void __hal_updt_stats_xpak(xge_hal_device_t *hldev)
16733115Syl150051 {
16743115Syl150051 u16 val_1;
16753115Syl150051 u64 addr;
16763115Syl150051
16773115Syl150051 /* Check the communication with the MDIO slave */
16783115Syl150051 addr = 0x0000;
16793115Syl150051 val_1 = 0x0;
16803115Syl150051 val_1 = xge_hal_mdio_read(hldev, XGE_HAL_MDIO_MMD_PMA_DEV_ADDR, addr);
16813115Syl150051 if((val_1 == 0xFFFF) || (val_1 == 0x0000))
16823115Syl150051 {
16833115Syl150051 xge_debug_osdep(XGE_TRACE, "ERR: MDIO slave access failed - "
1684*6937Sxw161283 "Returned %x", val_1);
16853115Syl150051 return;
16863115Syl150051 }
16873115Syl150051
16883115Syl150051 /* Check for the expected value of 2040 at PMA address 0x0000 */
16893115Syl150051 if(val_1 != 0x2040)
16903115Syl150051 {
16913115Syl150051 xge_debug_osdep(XGE_TRACE, "Incorrect value at PMA address 0x0000 - ");
1692*6937Sxw161283 xge_debug_osdep(XGE_TRACE, "Returned: %llx- Expected: 0x2040",
1693*6937Sxw161283 (unsigned long long)(unsigned long)val_1);
16943115Syl150051 return;
16953115Syl150051 }
16963115Syl150051
16973115Syl150051 /* Loading the DOM register to MDIO register */
16983115Syl150051 addr = 0xA100;
16993115Syl150051 (void) xge_hal_mdio_write(hldev, XGE_HAL_MDIO_MMD_PMA_DEV_ADDR, addr, 0x0);
17003115Syl150051 val_1 = xge_hal_mdio_read(hldev, XGE_HAL_MDIO_MMD_PMA_DEV_ADDR, addr);
17013115Syl150051
17023115Syl150051 /*
17033115Syl150051 * Reading the Alarm flags
17043115Syl150051 */
17053115Syl150051 addr = 0xA070;
17063115Syl150051 val_1 = 0x0;
17073115Syl150051 val_1 = xge_hal_mdio_read(hldev, XGE_HAL_MDIO_MMD_PMA_DEV_ADDR, addr);
17083115Syl150051 if(CHECKBIT(val_1, 0x7))
17093115Syl150051 {
17103115Syl150051 hldev->stats.sw_dev_err_stats.stats_xpak.
17113115Syl150051 alarm_transceiver_temp_high++;
17123115Syl150051 hldev->stats.sw_dev_err_stats.xpak_counter.excess_temp++;
17133115Syl150051 __hal_chk_xpak_counter(hldev, 0x1,
17143115Syl150051 hldev->stats.sw_dev_err_stats.xpak_counter.excess_temp);
17153115Syl150051 } else {
17163115Syl150051 hldev->stats.sw_dev_err_stats.xpak_counter.excess_temp = 0;
17173115Syl150051 }
17183115Syl150051 if(CHECKBIT(val_1, 0x6))
17193115Syl150051 hldev->stats.sw_dev_err_stats.stats_xpak.
17203115Syl150051 alarm_transceiver_temp_low++;
17213115Syl150051
17223115Syl150051 if(CHECKBIT(val_1, 0x3))
17233115Syl150051 {
17243115Syl150051 hldev->stats.sw_dev_err_stats.stats_xpak.
17253115Syl150051 alarm_laser_bias_current_high++;
17263115Syl150051 hldev->stats.sw_dev_err_stats.xpak_counter.
17273115Syl150051 excess_bias_current++;
17283115Syl150051 __hal_chk_xpak_counter(hldev, 0x2,
17293115Syl150051 hldev->stats.sw_dev_err_stats.xpak_counter.
17303115Syl150051 excess_bias_current);
17313115Syl150051 } else {
17323115Syl150051 hldev->stats.sw_dev_err_stats.xpak_counter.
17333115Syl150051 excess_bias_current = 0;
17343115Syl150051 }
17353115Syl150051 if(CHECKBIT(val_1, 0x2))
17363115Syl150051 hldev->stats.sw_dev_err_stats.stats_xpak.
17373115Syl150051 alarm_laser_bias_current_low++;
17383115Syl150051
17393115Syl150051 if(CHECKBIT(val_1, 0x1))
17403115Syl150051 {
17413115Syl150051 hldev->stats.sw_dev_err_stats.stats_xpak.
17423115Syl150051 alarm_laser_output_power_high++;
17433115Syl150051 hldev->stats.sw_dev_err_stats.xpak_counter.
17443115Syl150051 excess_laser_output++;
17453115Syl150051 __hal_chk_xpak_counter(hldev, 0x3,
17463115Syl150051 hldev->stats.sw_dev_err_stats.xpak_counter.
17473115Syl150051 excess_laser_output);
17483115Syl150051 } else {
17493115Syl150051 hldev->stats.sw_dev_err_stats.xpak_counter.
17503115Syl150051 excess_laser_output = 0;
17513115Syl150051 }
17523115Syl150051 if(CHECKBIT(val_1, 0x0))
17533115Syl150051 hldev->stats.sw_dev_err_stats.stats_xpak.
17543115Syl150051 alarm_laser_output_power_low++;
17553115Syl150051
17563115Syl150051 /*
17573115Syl150051 * Reading the warning flags
17583115Syl150051 */
17593115Syl150051 addr = 0xA074;
17603115Syl150051 val_1 = 0x0;
17613115Syl150051 val_1 = xge_hal_mdio_read(hldev, XGE_HAL_MDIO_MMD_PMA_DEV_ADDR, addr);
17623115Syl150051 if(CHECKBIT(val_1, 0x7))
17633115Syl150051 hldev->stats.sw_dev_err_stats.stats_xpak.
17643115Syl150051 warn_transceiver_temp_high++;
17653115Syl150051 if(CHECKBIT(val_1, 0x6))
17663115Syl150051 hldev->stats.sw_dev_err_stats.stats_xpak.
17673115Syl150051 warn_transceiver_temp_low++;
17683115Syl150051 if(CHECKBIT(val_1, 0x3))
17693115Syl150051 hldev->stats.sw_dev_err_stats.stats_xpak.
17703115Syl150051 warn_laser_bias_current_high++;
17713115Syl150051 if(CHECKBIT(val_1, 0x2))
17723115Syl150051 hldev->stats.sw_dev_err_stats.stats_xpak.
17733115Syl150051 warn_laser_bias_current_low++;
17743115Syl150051 if(CHECKBIT(val_1, 0x1))
17753115Syl150051 hldev->stats.sw_dev_err_stats.stats_xpak.
17763115Syl150051 warn_laser_output_power_high++;
17773115Syl150051 if(CHECKBIT(val_1, 0x0))
17783115Syl150051 hldev->stats.sw_dev_err_stats.stats_xpak.
17793115Syl150051 warn_laser_output_power_low++;
17803115Syl150051 }
1781