Commit 075c881b authored by Maksym Glubokiy's avatar Maksym Glubokiy Committed by David S. Miller

net: marvell: prestera: pci: add support for AC5X family devices

Add support for the following AC5x Marvell Prestera PP family devices:
  98DX7312M (12x25G / 8x25G + 1x100G);
  98DX3500  (24x1G + 6x25G);
  98DX3501  (16x1G + 6x10G);
  98DX3510  (48x1G + 6x25G);
  98DX3520  (24x2.5G + 6x25G);

Known issues:
- FW reload doesn't work (rmmod/modprobe sequence).
Co-developed-by: default avatarVadym Kochan <vadym.kochan@plvision.eu>
Signed-off-by: default avatarVadym Kochan <vadym.kochan@plvision.eu>
Signed-off-by: default avatarMaksym Glubokiy <maksym.glubokiy@plvision.eu>
Signed-off-by: default avatarOleksandr Mazur <oleksandr.mazur@plvision.eu>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent c334ac64
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
#define PRESTERA_PREV_FW_MIN_VER 0 #define PRESTERA_PREV_FW_MIN_VER 0
#define PRESTERA_FW_PATH_FMT "mrvl/prestera/mvsw_prestera_fw-v%u.%u.img" #define PRESTERA_FW_PATH_FMT "mrvl/prestera/mvsw_prestera_fw-v%u.%u.img"
#define PRESTERA_FW_ARM64_PATH_FMT "mrvl/prestera/mvsw_prestera_fw_arm64-v%u.%u.img"
#define PRESTERA_FW_HDR_MAGIC 0x351D9D06 #define PRESTERA_FW_HDR_MAGIC 0x351D9D06
#define PRESTERA_FW_DL_TIMEOUT_MS 50000 #define PRESTERA_FW_DL_TIMEOUT_MS 50000
...@@ -187,6 +188,11 @@ struct prestera_fw_regs { ...@@ -187,6 +188,11 @@ struct prestera_fw_regs {
#define PRESTERA_DEV_ID_AC3X_98DX_55 0xC804 #define PRESTERA_DEV_ID_AC3X_98DX_55 0xC804
#define PRESTERA_DEV_ID_AC3X_98DX_65 0xC80C #define PRESTERA_DEV_ID_AC3X_98DX_65 0xC80C
#define PRESTERA_DEV_ID_ALDRIN2 0xCC1E #define PRESTERA_DEV_ID_ALDRIN2 0xCC1E
#define PRESTERA_DEV_ID_98DX7312M 0x981F
#define PRESTERA_DEV_ID_98DX3500 0x9820
#define PRESTERA_DEV_ID_98DX3501 0x9826
#define PRESTERA_DEV_ID_98DX3510 0x9821
#define PRESTERA_DEV_ID_98DX3520 0x9822
struct prestera_fw_evtq { struct prestera_fw_evtq {
u8 __iomem *addr; u8 __iomem *addr;
...@@ -205,6 +211,7 @@ struct prestera_fw { ...@@ -205,6 +211,7 @@ struct prestera_fw {
const struct firmware *bin; const struct firmware *bin;
struct workqueue_struct *wq; struct workqueue_struct *wq;
struct prestera_device dev; struct prestera_device dev;
struct pci_dev *pci_dev;
u8 __iomem *ldr_regs; u8 __iomem *ldr_regs;
u8 __iomem *ldr_ring_buf; u8 __iomem *ldr_ring_buf;
u32 ldr_buf_len; u32 ldr_buf_len;
...@@ -693,6 +700,20 @@ static int prestera_fw_hdr_parse(struct prestera_fw *fw) ...@@ -693,6 +700,20 @@ static int prestera_fw_hdr_parse(struct prestera_fw *fw)
return prestera_fw_rev_check(fw); return prestera_fw_rev_check(fw);
} }
static const char *prestera_fw_path_fmt_get(struct prestera_fw *fw)
{
switch (fw->pci_dev->device) {
case PRESTERA_DEV_ID_98DX3500:
case PRESTERA_DEV_ID_98DX3501:
case PRESTERA_DEV_ID_98DX3510:
case PRESTERA_DEV_ID_98DX3520:
return PRESTERA_FW_ARM64_PATH_FMT;
default:
return PRESTERA_FW_PATH_FMT;
}
}
static int prestera_fw_get(struct prestera_fw *fw) static int prestera_fw_get(struct prestera_fw *fw)
{ {
int ver_maj = PRESTERA_SUPP_FW_MAJ_VER; int ver_maj = PRESTERA_SUPP_FW_MAJ_VER;
...@@ -701,7 +722,7 @@ static int prestera_fw_get(struct prestera_fw *fw) ...@@ -701,7 +722,7 @@ static int prestera_fw_get(struct prestera_fw *fw)
int err; int err;
pick_fw_ver: pick_fw_ver:
snprintf(fw_path, sizeof(fw_path), PRESTERA_FW_PATH_FMT, snprintf(fw_path, sizeof(fw_path), prestera_fw_path_fmt_get(fw),
ver_maj, ver_min); ver_maj, ver_min);
err = request_firmware_direct(&fw->bin, fw_path, fw->dev.dev); err = request_firmware_direct(&fw->bin, fw_path, fw->dev.dev);
...@@ -778,22 +799,56 @@ static int prestera_fw_load(struct prestera_fw *fw) ...@@ -778,22 +799,56 @@ static int prestera_fw_load(struct prestera_fw *fw)
return err; return err;
} }
static bool prestera_pci_pp_use_bar2(struct pci_dev *pdev)
{
switch (pdev->device) {
case PRESTERA_DEV_ID_98DX7312M:
case PRESTERA_DEV_ID_98DX3500:
case PRESTERA_DEV_ID_98DX3501:
case PRESTERA_DEV_ID_98DX3510:
case PRESTERA_DEV_ID_98DX3520:
return true;
default:
return false;
}
}
static u32 prestera_pci_pp_bar2_offs(struct pci_dev *pdev)
{
if (pci_resource_len(pdev, 2) == 0x1000000)
return 0x0;
else
return (pci_resource_len(pdev, 2) / 2);
}
static u32 prestera_pci_fw_bar2_offs(struct pci_dev *pdev)
{
if (pci_resource_len(pdev, 2) == 0x1000000)
return 0x400000;
else
return 0x0;
}
static int prestera_pci_probe(struct pci_dev *pdev, static int prestera_pci_probe(struct pci_dev *pdev,
const struct pci_device_id *id) const struct pci_device_id *id)
{ {
const char *driver_name = dev_driver_string(&pdev->dev); const char *driver_name = dev_driver_string(&pdev->dev);
u8 __iomem *mem_addr, *pp_addr = NULL;
struct prestera_fw *fw; struct prestera_fw *fw;
int err; int err;
err = pcim_enable_device(pdev); err = pcim_enable_device(pdev);
if (err) if (err) {
return err; dev_err(&pdev->dev, "pci_enable_device failed\n");
goto err_pci_enable_device;
}
err = pcim_iomap_regions(pdev, BIT(PRESTERA_PCI_BAR_FW) | err = pci_request_regions(pdev, driver_name);
BIT(PRESTERA_PCI_BAR_PP), if (err) {
pci_name(pdev)); dev_err(&pdev->dev, "pci_request_regions failed\n");
if (err) goto err_pci_request_regions;
return err; }
err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(30)); err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(30));
if (err) { if (err) {
...@@ -801,6 +856,26 @@ static int prestera_pci_probe(struct pci_dev *pdev, ...@@ -801,6 +856,26 @@ static int prestera_pci_probe(struct pci_dev *pdev,
goto err_dma_mask; goto err_dma_mask;
} }
mem_addr = pcim_iomap(pdev, 2, 0);
if (!mem_addr) {
dev_err(&pdev->dev, "pci mem ioremap failed\n");
err = -EIO;
goto err_mem_ioremap;
}
/* AC5X devices use second half of BAR2 */
if (prestera_pci_pp_use_bar2(pdev)) {
pp_addr = mem_addr + prestera_pci_pp_bar2_offs(pdev);
mem_addr = mem_addr + prestera_pci_fw_bar2_offs(pdev);
} else {
pp_addr = pcim_iomap(pdev, 4, 0);
if (!pp_addr) {
dev_err(&pdev->dev, "pp regs ioremap failed\n");
err = -EIO;
goto err_pp_ioremap;
}
}
pci_set_master(pdev); pci_set_master(pdev);
fw = devm_kzalloc(&pdev->dev, sizeof(*fw), GFP_KERNEL); fw = devm_kzalloc(&pdev->dev, sizeof(*fw), GFP_KERNEL);
...@@ -809,8 +884,9 @@ static int prestera_pci_probe(struct pci_dev *pdev, ...@@ -809,8 +884,9 @@ static int prestera_pci_probe(struct pci_dev *pdev,
goto err_pci_dev_alloc; goto err_pci_dev_alloc;
} }
fw->dev.ctl_regs = pcim_iomap_table(pdev)[PRESTERA_PCI_BAR_FW]; fw->pci_dev = pdev;
fw->dev.pp_regs = pcim_iomap_table(pdev)[PRESTERA_PCI_BAR_PP]; fw->dev.ctl_regs = mem_addr;
fw->dev.pp_regs = pp_addr;
fw->dev.dev = &pdev->dev; fw->dev.dev = &pdev->dev;
pci_set_drvdata(pdev, fw); pci_set_drvdata(pdev, fw);
...@@ -858,7 +934,12 @@ static int prestera_pci_probe(struct pci_dev *pdev, ...@@ -858,7 +934,12 @@ static int prestera_pci_probe(struct pci_dev *pdev,
prestera_fw_uninit(fw); prestera_fw_uninit(fw);
err_prestera_fw_init: err_prestera_fw_init:
err_pci_dev_alloc: err_pci_dev_alloc:
err_pp_ioremap:
err_mem_ioremap:
err_dma_mask: err_dma_mask:
pci_release_regions(pdev);
err_pci_request_regions:
err_pci_enable_device:
return err; return err;
} }
...@@ -871,12 +952,18 @@ static void prestera_pci_remove(struct pci_dev *pdev) ...@@ -871,12 +952,18 @@ static void prestera_pci_remove(struct pci_dev *pdev)
pci_free_irq_vectors(pdev); pci_free_irq_vectors(pdev);
destroy_workqueue(fw->wq); destroy_workqueue(fw->wq);
prestera_fw_uninit(fw); prestera_fw_uninit(fw);
pci_release_regions(pdev);
} }
static const struct pci_device_id prestera_pci_devices[] = { static const struct pci_device_id prestera_pci_devices[] = {
{ PCI_DEVICE(PCI_VENDOR_ID_MARVELL, PRESTERA_DEV_ID_AC3X_98DX_55) }, { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, PRESTERA_DEV_ID_AC3X_98DX_55) },
{ PCI_DEVICE(PCI_VENDOR_ID_MARVELL, PRESTERA_DEV_ID_AC3X_98DX_65) }, { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, PRESTERA_DEV_ID_AC3X_98DX_65) },
{ PCI_DEVICE(PCI_VENDOR_ID_MARVELL, PRESTERA_DEV_ID_ALDRIN2) }, { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, PRESTERA_DEV_ID_ALDRIN2) },
{ PCI_DEVICE(PCI_VENDOR_ID_MARVELL, PRESTERA_DEV_ID_98DX7312M) },
{ PCI_DEVICE(PCI_VENDOR_ID_MARVELL, PRESTERA_DEV_ID_98DX3500) },
{ PCI_DEVICE(PCI_VENDOR_ID_MARVELL, PRESTERA_DEV_ID_98DX3501) },
{ PCI_DEVICE(PCI_VENDOR_ID_MARVELL, PRESTERA_DEV_ID_98DX3510) },
{ PCI_DEVICE(PCI_VENDOR_ID_MARVELL, PRESTERA_DEV_ID_98DX3520) },
{ } { }
}; };
MODULE_DEVICE_TABLE(pci, prestera_pci_devices); MODULE_DEVICE_TABLE(pci, prestera_pci_devices);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment