Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 1 | /********************************************************************** |
| 2 | * Author: Cavium, Inc. |
| 3 | * |
| 4 | * Contact: support@cavium.com |
| 5 | * Please include "LiquidIO" in the subject. |
| 6 | * |
| 7 | * Copyright (c) 2003-2015 Cavium, Inc. |
| 8 | * |
| 9 | * This file is free software; you can redistribute it and/or modify |
| 10 | * it under the terms of the GNU General Public License, Version 2, as |
| 11 | * published by the Free Software Foundation. |
| 12 | * |
| 13 | * This file is distributed in the hope that it will be useful, but |
| 14 | * AS-IS and WITHOUT ANY WARRANTY; without even the implied warranty |
| 15 | * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, TITLE, or |
| 16 | * NONINFRINGEMENT. See the GNU General Public License for more |
| 17 | * details. |
| 18 | * |
| 19 | * This file may also be available under a different license from Cavium. |
| 20 | * Contact Cavium, Inc. for more information |
| 21 | **********************************************************************/ |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 22 | #include <linux/types.h> |
| 23 | #include <linux/list.h> |
| 24 | #include <linux/interrupt.h> |
| 25 | #include <linux/pci.h> |
| 26 | #include <linux/crc32.h> |
| 27 | #include <linux/kthread.h> |
| 28 | #include <linux/netdevice.h> |
Raghu Vatsavayi | 5b173cf | 2015-06-12 18:11:50 -0700 | [diff] [blame] | 29 | #include <linux/vmalloc.h> |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 30 | #include "octeon_config.h" |
| 31 | #include "liquidio_common.h" |
| 32 | #include "octeon_droq.h" |
| 33 | #include "octeon_iq.h" |
| 34 | #include "response_manager.h" |
| 35 | #include "octeon_device.h" |
| 36 | #include "octeon_nic.h" |
| 37 | #include "octeon_main.h" |
| 38 | #include "octeon_network.h" |
| 39 | #include "cn66xx_regs.h" |
| 40 | #include "cn66xx_device.h" |
| 41 | #include "cn68xx_regs.h" |
| 42 | #include "cn68xx_device.h" |
| 43 | #include "liquidio_image.h" |
| 44 | #include "octeon_mem_ops.h" |
| 45 | |
| 46 | /** Default configuration |
| 47 | * for CN66XX OCTEON Models. |
| 48 | */ |
| 49 | static struct octeon_config default_cn66xx_conf = { |
| 50 | .card_type = LIO_210SV, |
| 51 | .card_name = LIO_210SV_NAME, |
| 52 | |
| 53 | /** IQ attributes */ |
| 54 | .iq = { |
| 55 | .max_iqs = CN6XXX_CFG_IO_QUEUES, |
| 56 | .pending_list_size = |
| 57 | (CN6XXX_MAX_IQ_DESCRIPTORS * CN6XXX_CFG_IO_QUEUES), |
| 58 | .instr_type = OCTEON_64BYTE_INSTR, |
| 59 | .db_min = CN6XXX_DB_MIN, |
| 60 | .db_timeout = CN6XXX_DB_TIMEOUT, |
| 61 | } |
| 62 | , |
| 63 | |
| 64 | /** OQ attributes */ |
| 65 | .oq = { |
| 66 | .max_oqs = CN6XXX_CFG_IO_QUEUES, |
| 67 | .info_ptr = OCTEON_OQ_INFOPTR_MODE, |
| 68 | .refill_threshold = CN6XXX_OQ_REFIL_THRESHOLD, |
| 69 | .oq_intr_pkt = CN6XXX_OQ_INTR_PKT, |
| 70 | .oq_intr_time = CN6XXX_OQ_INTR_TIME, |
| 71 | .pkts_per_intr = CN6XXX_OQ_PKTSPER_INTR, |
| 72 | } |
| 73 | , |
| 74 | |
| 75 | .num_nic_ports = DEFAULT_NUM_NIC_PORTS_66XX, |
| 76 | .num_def_rx_descs = CN6XXX_MAX_OQ_DESCRIPTORS, |
| 77 | .num_def_tx_descs = CN6XXX_MAX_IQ_DESCRIPTORS, |
| 78 | .def_rx_buf_size = CN6XXX_OQ_BUF_SIZE, |
| 79 | |
| 80 | /* For ethernet interface 0: Port cfg Attributes */ |
| 81 | .nic_if_cfg[0] = { |
| 82 | /* Max Txqs: Half for each of the two ports :max_iq/2 */ |
| 83 | .max_txqs = MAX_TXQS_PER_INTF, |
| 84 | |
| 85 | /* Actual configured value. Range could be: 1...max_txqs */ |
| 86 | .num_txqs = DEF_TXQS_PER_INTF, |
| 87 | |
| 88 | /* Max Rxqs: Half for each of the two ports :max_oq/2 */ |
| 89 | .max_rxqs = MAX_RXQS_PER_INTF, |
| 90 | |
| 91 | /* Actual configured value. Range could be: 1...max_rxqs */ |
| 92 | .num_rxqs = DEF_RXQS_PER_INTF, |
| 93 | |
| 94 | /* Num of desc for rx rings */ |
| 95 | .num_rx_descs = CN6XXX_MAX_OQ_DESCRIPTORS, |
| 96 | |
| 97 | /* Num of desc for tx rings */ |
| 98 | .num_tx_descs = CN6XXX_MAX_IQ_DESCRIPTORS, |
| 99 | |
| 100 | /* SKB size, We need not change buf size even for Jumbo frames. |
| 101 | * Octeon can send jumbo frames in 4 consecutive descriptors, |
| 102 | */ |
| 103 | .rx_buf_size = CN6XXX_OQ_BUF_SIZE, |
| 104 | |
| 105 | .base_queue = BASE_QUEUE_NOT_REQUESTED, |
| 106 | |
| 107 | .gmx_port_id = 0, |
| 108 | }, |
| 109 | |
| 110 | .nic_if_cfg[1] = { |
| 111 | /* Max Txqs: Half for each of the two ports :max_iq/2 */ |
| 112 | .max_txqs = MAX_TXQS_PER_INTF, |
| 113 | |
| 114 | /* Actual configured value. Range could be: 1...max_txqs */ |
| 115 | .num_txqs = DEF_TXQS_PER_INTF, |
| 116 | |
| 117 | /* Max Rxqs: Half for each of the two ports :max_oq/2 */ |
| 118 | .max_rxqs = MAX_RXQS_PER_INTF, |
| 119 | |
| 120 | /* Actual configured value. Range could be: 1...max_rxqs */ |
| 121 | .num_rxqs = DEF_RXQS_PER_INTF, |
| 122 | |
| 123 | /* Num of desc for rx rings */ |
| 124 | .num_rx_descs = CN6XXX_MAX_OQ_DESCRIPTORS, |
| 125 | |
| 126 | /* Num of desc for tx rings */ |
| 127 | .num_tx_descs = CN6XXX_MAX_IQ_DESCRIPTORS, |
| 128 | |
| 129 | /* SKB size, We need not change buf size even for Jumbo frames. |
| 130 | * Octeon can send jumbo frames in 4 consecutive descriptors, |
| 131 | */ |
| 132 | .rx_buf_size = CN6XXX_OQ_BUF_SIZE, |
| 133 | |
| 134 | .base_queue = BASE_QUEUE_NOT_REQUESTED, |
| 135 | |
| 136 | .gmx_port_id = 1, |
| 137 | }, |
| 138 | |
| 139 | /** Miscellaneous attributes */ |
| 140 | .misc = { |
| 141 | /* Host driver link query interval */ |
| 142 | .oct_link_query_interval = 100, |
| 143 | |
| 144 | /* Octeon link query interval */ |
| 145 | .host_link_query_interval = 500, |
| 146 | |
| 147 | .enable_sli_oq_bp = 0, |
| 148 | |
| 149 | /* Control queue group */ |
| 150 | .ctrlq_grp = 1, |
| 151 | } |
| 152 | , |
| 153 | }; |
| 154 | |
| 155 | /** Default configuration |
| 156 | * for CN68XX OCTEON Model. |
| 157 | */ |
| 158 | |
| 159 | static struct octeon_config default_cn68xx_conf = { |
| 160 | .card_type = LIO_410NV, |
| 161 | .card_name = LIO_410NV_NAME, |
| 162 | |
| 163 | /** IQ attributes */ |
| 164 | .iq = { |
| 165 | .max_iqs = CN6XXX_CFG_IO_QUEUES, |
| 166 | .pending_list_size = |
| 167 | (CN6XXX_MAX_IQ_DESCRIPTORS * CN6XXX_CFG_IO_QUEUES), |
| 168 | .instr_type = OCTEON_64BYTE_INSTR, |
| 169 | .db_min = CN6XXX_DB_MIN, |
| 170 | .db_timeout = CN6XXX_DB_TIMEOUT, |
| 171 | } |
| 172 | , |
| 173 | |
| 174 | /** OQ attributes */ |
| 175 | .oq = { |
| 176 | .max_oqs = CN6XXX_CFG_IO_QUEUES, |
| 177 | .info_ptr = OCTEON_OQ_INFOPTR_MODE, |
| 178 | .refill_threshold = CN6XXX_OQ_REFIL_THRESHOLD, |
| 179 | .oq_intr_pkt = CN6XXX_OQ_INTR_PKT, |
| 180 | .oq_intr_time = CN6XXX_OQ_INTR_TIME, |
| 181 | .pkts_per_intr = CN6XXX_OQ_PKTSPER_INTR, |
| 182 | } |
| 183 | , |
| 184 | |
| 185 | .num_nic_ports = DEFAULT_NUM_NIC_PORTS_68XX, |
| 186 | .num_def_rx_descs = CN6XXX_MAX_OQ_DESCRIPTORS, |
| 187 | .num_def_tx_descs = CN6XXX_MAX_IQ_DESCRIPTORS, |
| 188 | .def_rx_buf_size = CN6XXX_OQ_BUF_SIZE, |
| 189 | |
| 190 | .nic_if_cfg[0] = { |
| 191 | /* Max Txqs: Half for each of the two ports :max_iq/2 */ |
| 192 | .max_txqs = MAX_TXQS_PER_INTF, |
| 193 | |
| 194 | /* Actual configured value. Range could be: 1...max_txqs */ |
| 195 | .num_txqs = DEF_TXQS_PER_INTF, |
| 196 | |
| 197 | /* Max Rxqs: Half for each of the two ports :max_oq/2 */ |
| 198 | .max_rxqs = MAX_RXQS_PER_INTF, |
| 199 | |
| 200 | /* Actual configured value. Range could be: 1...max_rxqs */ |
| 201 | .num_rxqs = DEF_RXQS_PER_INTF, |
| 202 | |
| 203 | /* Num of desc for rx rings */ |
| 204 | .num_rx_descs = CN6XXX_MAX_OQ_DESCRIPTORS, |
| 205 | |
| 206 | /* Num of desc for tx rings */ |
| 207 | .num_tx_descs = CN6XXX_MAX_IQ_DESCRIPTORS, |
| 208 | |
| 209 | /* SKB size, We need not change buf size even for Jumbo frames. |
| 210 | * Octeon can send jumbo frames in 4 consecutive descriptors, |
| 211 | */ |
| 212 | .rx_buf_size = CN6XXX_OQ_BUF_SIZE, |
| 213 | |
| 214 | .base_queue = BASE_QUEUE_NOT_REQUESTED, |
| 215 | |
| 216 | .gmx_port_id = 0, |
| 217 | }, |
| 218 | |
| 219 | .nic_if_cfg[1] = { |
| 220 | /* Max Txqs: Half for each of the two ports :max_iq/2 */ |
| 221 | .max_txqs = MAX_TXQS_PER_INTF, |
| 222 | |
| 223 | /* Actual configured value. Range could be: 1...max_txqs */ |
| 224 | .num_txqs = DEF_TXQS_PER_INTF, |
| 225 | |
| 226 | /* Max Rxqs: Half for each of the two ports :max_oq/2 */ |
| 227 | .max_rxqs = MAX_RXQS_PER_INTF, |
| 228 | |
| 229 | /* Actual configured value. Range could be: 1...max_rxqs */ |
| 230 | .num_rxqs = DEF_RXQS_PER_INTF, |
| 231 | |
| 232 | /* Num of desc for rx rings */ |
| 233 | .num_rx_descs = CN6XXX_MAX_OQ_DESCRIPTORS, |
| 234 | |
| 235 | /* Num of desc for tx rings */ |
| 236 | .num_tx_descs = CN6XXX_MAX_IQ_DESCRIPTORS, |
| 237 | |
| 238 | /* SKB size, We need not change buf size even for Jumbo frames. |
| 239 | * Octeon can send jumbo frames in 4 consecutive descriptors, |
| 240 | */ |
| 241 | .rx_buf_size = CN6XXX_OQ_BUF_SIZE, |
| 242 | |
| 243 | .base_queue = BASE_QUEUE_NOT_REQUESTED, |
| 244 | |
| 245 | .gmx_port_id = 1, |
| 246 | }, |
| 247 | |
| 248 | .nic_if_cfg[2] = { |
| 249 | /* Max Txqs: Half for each of the two ports :max_iq/2 */ |
| 250 | .max_txqs = MAX_TXQS_PER_INTF, |
| 251 | |
| 252 | /* Actual configured value. Range could be: 1...max_txqs */ |
| 253 | .num_txqs = DEF_TXQS_PER_INTF, |
| 254 | |
| 255 | /* Max Rxqs: Half for each of the two ports :max_oq/2 */ |
| 256 | .max_rxqs = MAX_RXQS_PER_INTF, |
| 257 | |
| 258 | /* Actual configured value. Range could be: 1...max_rxqs */ |
| 259 | .num_rxqs = DEF_RXQS_PER_INTF, |
| 260 | |
| 261 | /* Num of desc for rx rings */ |
| 262 | .num_rx_descs = CN6XXX_MAX_OQ_DESCRIPTORS, |
| 263 | |
| 264 | /* Num of desc for tx rings */ |
| 265 | .num_tx_descs = CN6XXX_MAX_IQ_DESCRIPTORS, |
| 266 | |
| 267 | /* SKB size, We need not change buf size even for Jumbo frames. |
| 268 | * Octeon can send jumbo frames in 4 consecutive descriptors, |
| 269 | */ |
| 270 | .rx_buf_size = CN6XXX_OQ_BUF_SIZE, |
| 271 | |
| 272 | .base_queue = BASE_QUEUE_NOT_REQUESTED, |
| 273 | |
| 274 | .gmx_port_id = 2, |
| 275 | }, |
| 276 | |
| 277 | .nic_if_cfg[3] = { |
| 278 | /* Max Txqs: Half for each of the two ports :max_iq/2 */ |
| 279 | .max_txqs = MAX_TXQS_PER_INTF, |
| 280 | |
| 281 | /* Actual configured value. Range could be: 1...max_txqs */ |
| 282 | .num_txqs = DEF_TXQS_PER_INTF, |
| 283 | |
| 284 | /* Max Rxqs: Half for each of the two ports :max_oq/2 */ |
| 285 | .max_rxqs = MAX_RXQS_PER_INTF, |
| 286 | |
| 287 | /* Actual configured value. Range could be: 1...max_rxqs */ |
| 288 | .num_rxqs = DEF_RXQS_PER_INTF, |
| 289 | |
| 290 | /* Num of desc for rx rings */ |
| 291 | .num_rx_descs = CN6XXX_MAX_OQ_DESCRIPTORS, |
| 292 | |
| 293 | /* Num of desc for tx rings */ |
| 294 | .num_tx_descs = CN6XXX_MAX_IQ_DESCRIPTORS, |
| 295 | |
| 296 | /* SKB size, We need not change buf size even for Jumbo frames. |
| 297 | * Octeon can send jumbo frames in 4 consecutive descriptors, |
| 298 | */ |
| 299 | .rx_buf_size = CN6XXX_OQ_BUF_SIZE, |
| 300 | |
| 301 | .base_queue = BASE_QUEUE_NOT_REQUESTED, |
| 302 | |
| 303 | .gmx_port_id = 3, |
| 304 | }, |
| 305 | |
| 306 | /** Miscellaneous attributes */ |
| 307 | .misc = { |
| 308 | /* Host driver link query interval */ |
| 309 | .oct_link_query_interval = 100, |
| 310 | |
| 311 | /* Octeon link query interval */ |
| 312 | .host_link_query_interval = 500, |
| 313 | |
| 314 | .enable_sli_oq_bp = 0, |
| 315 | |
| 316 | /* Control queue group */ |
| 317 | .ctrlq_grp = 1, |
| 318 | } |
| 319 | , |
| 320 | }; |
| 321 | |
| 322 | /** Default configuration |
| 323 | * for CN68XX OCTEON Model. |
| 324 | */ |
| 325 | static struct octeon_config default_cn68xx_210nv_conf = { |
| 326 | .card_type = LIO_210NV, |
| 327 | .card_name = LIO_210NV_NAME, |
| 328 | |
| 329 | /** IQ attributes */ |
| 330 | |
| 331 | .iq = { |
| 332 | .max_iqs = CN6XXX_CFG_IO_QUEUES, |
| 333 | .pending_list_size = |
| 334 | (CN6XXX_MAX_IQ_DESCRIPTORS * CN6XXX_CFG_IO_QUEUES), |
| 335 | .instr_type = OCTEON_64BYTE_INSTR, |
| 336 | .db_min = CN6XXX_DB_MIN, |
| 337 | .db_timeout = CN6XXX_DB_TIMEOUT, |
| 338 | } |
| 339 | , |
| 340 | |
| 341 | /** OQ attributes */ |
| 342 | .oq = { |
| 343 | .max_oqs = CN6XXX_CFG_IO_QUEUES, |
| 344 | .info_ptr = OCTEON_OQ_INFOPTR_MODE, |
| 345 | .refill_threshold = CN6XXX_OQ_REFIL_THRESHOLD, |
| 346 | .oq_intr_pkt = CN6XXX_OQ_INTR_PKT, |
| 347 | .oq_intr_time = CN6XXX_OQ_INTR_TIME, |
| 348 | .pkts_per_intr = CN6XXX_OQ_PKTSPER_INTR, |
| 349 | } |
| 350 | , |
| 351 | |
| 352 | .num_nic_ports = DEFAULT_NUM_NIC_PORTS_68XX_210NV, |
| 353 | .num_def_rx_descs = CN6XXX_MAX_OQ_DESCRIPTORS, |
| 354 | .num_def_tx_descs = CN6XXX_MAX_IQ_DESCRIPTORS, |
| 355 | .def_rx_buf_size = CN6XXX_OQ_BUF_SIZE, |
| 356 | |
| 357 | .nic_if_cfg[0] = { |
| 358 | /* Max Txqs: Half for each of the two ports :max_iq/2 */ |
| 359 | .max_txqs = MAX_TXQS_PER_INTF, |
| 360 | |
| 361 | /* Actual configured value. Range could be: 1...max_txqs */ |
| 362 | .num_txqs = DEF_TXQS_PER_INTF, |
| 363 | |
| 364 | /* Max Rxqs: Half for each of the two ports :max_oq/2 */ |
| 365 | .max_rxqs = MAX_RXQS_PER_INTF, |
| 366 | |
| 367 | /* Actual configured value. Range could be: 1...max_rxqs */ |
| 368 | .num_rxqs = DEF_RXQS_PER_INTF, |
| 369 | |
| 370 | /* Num of desc for rx rings */ |
| 371 | .num_rx_descs = CN6XXX_MAX_OQ_DESCRIPTORS, |
| 372 | |
| 373 | /* Num of desc for tx rings */ |
| 374 | .num_tx_descs = CN6XXX_MAX_IQ_DESCRIPTORS, |
| 375 | |
| 376 | /* SKB size, We need not change buf size even for Jumbo frames. |
| 377 | * Octeon can send jumbo frames in 4 consecutive descriptors, |
| 378 | */ |
| 379 | .rx_buf_size = CN6XXX_OQ_BUF_SIZE, |
| 380 | |
| 381 | .base_queue = BASE_QUEUE_NOT_REQUESTED, |
| 382 | |
| 383 | .gmx_port_id = 0, |
| 384 | }, |
| 385 | |
| 386 | .nic_if_cfg[1] = { |
| 387 | /* Max Txqs: Half for each of the two ports :max_iq/2 */ |
| 388 | .max_txqs = MAX_TXQS_PER_INTF, |
| 389 | |
| 390 | /* Actual configured value. Range could be: 1...max_txqs */ |
| 391 | .num_txqs = DEF_TXQS_PER_INTF, |
| 392 | |
| 393 | /* Max Rxqs: Half for each of the two ports :max_oq/2 */ |
| 394 | .max_rxqs = MAX_RXQS_PER_INTF, |
| 395 | |
| 396 | /* Actual configured value. Range could be: 1...max_rxqs */ |
| 397 | .num_rxqs = DEF_RXQS_PER_INTF, |
| 398 | |
| 399 | /* Num of desc for rx rings */ |
| 400 | .num_rx_descs = CN6XXX_MAX_OQ_DESCRIPTORS, |
| 401 | |
| 402 | /* Num of desc for tx rings */ |
| 403 | .num_tx_descs = CN6XXX_MAX_IQ_DESCRIPTORS, |
| 404 | |
| 405 | /* SKB size, We need not change buf size even for Jumbo frames. |
| 406 | * Octeon can send jumbo frames in 4 consecutive descriptors, |
| 407 | */ |
| 408 | .rx_buf_size = CN6XXX_OQ_BUF_SIZE, |
| 409 | |
| 410 | .base_queue = BASE_QUEUE_NOT_REQUESTED, |
| 411 | |
| 412 | .gmx_port_id = 1, |
| 413 | }, |
| 414 | |
| 415 | /** Miscellaneous attributes */ |
| 416 | .misc = { |
| 417 | /* Host driver link query interval */ |
| 418 | .oct_link_query_interval = 100, |
| 419 | |
| 420 | /* Octeon link query interval */ |
| 421 | .host_link_query_interval = 500, |
| 422 | |
| 423 | .enable_sli_oq_bp = 0, |
| 424 | |
| 425 | /* Control queue group */ |
| 426 | .ctrlq_grp = 1, |
| 427 | } |
| 428 | , |
| 429 | }; |
| 430 | |
| 431 | enum { |
| 432 | OCTEON_CONFIG_TYPE_DEFAULT = 0, |
| 433 | NUM_OCTEON_CONFS, |
| 434 | }; |
| 435 | |
| 436 | static struct octeon_config_ptr { |
| 437 | u32 conf_type; |
| 438 | } oct_conf_info[MAX_OCTEON_DEVICES] = { |
| 439 | { |
| 440 | OCTEON_CONFIG_TYPE_DEFAULT, |
| 441 | }, { |
| 442 | OCTEON_CONFIG_TYPE_DEFAULT, |
| 443 | }, { |
| 444 | OCTEON_CONFIG_TYPE_DEFAULT, |
| 445 | }, { |
| 446 | OCTEON_CONFIG_TYPE_DEFAULT, |
| 447 | }, |
| 448 | }; |
| 449 | |
| 450 | static char oct_dev_state_str[OCT_DEV_STATES + 1][32] = { |
| 451 | "BEGIN", "PCI-MAP-DONE", "DISPATCH-INIT-DONE", |
| 452 | "IQ-INIT-DONE", "SCBUFF-POOL-INIT-DONE", "RESPLIST-INIT-DONE", |
| 453 | "DROQ-INIT-DONE", "IO-QUEUES-INIT-DONE", "CONSOLE-INIT-DONE", |
| 454 | "HOST-READY", "CORE-READY", "RUNNING", "IN-RESET", |
| 455 | "INVALID" |
| 456 | }; |
| 457 | |
| 458 | static char oct_dev_app_str[CVM_DRV_APP_COUNT + 1][32] = { |
| 459 | "BASE", "NIC", "UNKNOWN"}; |
| 460 | |
| 461 | static struct octeon_device *octeon_device[MAX_OCTEON_DEVICES]; |
| 462 | static u32 octeon_device_count; |
| 463 | |
| 464 | static struct octeon_core_setup core_setup[MAX_OCTEON_DEVICES]; |
| 465 | |
Raghu Vatsavayi | 5b173cf | 2015-06-12 18:11:50 -0700 | [diff] [blame] | 466 | static void oct_set_config_info(int oct_id, int conf_type) |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 467 | { |
| 468 | if (conf_type < 0 || conf_type > (NUM_OCTEON_CONFS - 1)) |
| 469 | conf_type = OCTEON_CONFIG_TYPE_DEFAULT; |
| 470 | oct_conf_info[oct_id].conf_type = conf_type; |
| 471 | } |
| 472 | |
| 473 | void octeon_init_device_list(int conf_type) |
| 474 | { |
| 475 | int i; |
| 476 | |
| 477 | memset(octeon_device, 0, (sizeof(void *) * MAX_OCTEON_DEVICES)); |
| 478 | for (i = 0; i < MAX_OCTEON_DEVICES; i++) |
| 479 | oct_set_config_info(i, conf_type); |
| 480 | } |
| 481 | |
| 482 | static void *__retrieve_octeon_config_info(struct octeon_device *oct, |
| 483 | u16 card_type) |
| 484 | { |
| 485 | u32 oct_id = oct->octeon_id; |
| 486 | void *ret = NULL; |
| 487 | |
| 488 | switch (oct_conf_info[oct_id].conf_type) { |
| 489 | case OCTEON_CONFIG_TYPE_DEFAULT: |
| 490 | if (oct->chip_id == OCTEON_CN66XX) { |
| 491 | ret = (void *)&default_cn66xx_conf; |
| 492 | } else if ((oct->chip_id == OCTEON_CN68XX) && |
| 493 | (card_type == LIO_210NV)) { |
| 494 | ret = (void *)&default_cn68xx_210nv_conf; |
| 495 | } else if ((oct->chip_id == OCTEON_CN68XX) && |
| 496 | (card_type == LIO_410NV)) { |
| 497 | ret = (void *)&default_cn68xx_conf; |
| 498 | } |
| 499 | break; |
| 500 | default: |
| 501 | break; |
| 502 | } |
| 503 | return ret; |
| 504 | } |
| 505 | |
| 506 | static int __verify_octeon_config_info(struct octeon_device *oct, void *conf) |
| 507 | { |
| 508 | switch (oct->chip_id) { |
| 509 | case OCTEON_CN66XX: |
| 510 | case OCTEON_CN68XX: |
| 511 | return lio_validate_cn6xxx_config_info(oct, conf); |
| 512 | |
| 513 | default: |
| 514 | break; |
| 515 | } |
| 516 | |
| 517 | return 1; |
| 518 | } |
| 519 | |
| 520 | void *oct_get_config_info(struct octeon_device *oct, u16 card_type) |
| 521 | { |
| 522 | void *conf = NULL; |
| 523 | |
| 524 | conf = __retrieve_octeon_config_info(oct, card_type); |
| 525 | if (!conf) |
| 526 | return NULL; |
| 527 | |
| 528 | if (__verify_octeon_config_info(oct, conf)) { |
| 529 | dev_err(&oct->pci_dev->dev, "Configuration verification failed\n"); |
| 530 | return NULL; |
| 531 | } |
| 532 | |
| 533 | return conf; |
| 534 | } |
| 535 | |
| 536 | char *lio_get_state_string(atomic_t *state_ptr) |
| 537 | { |
| 538 | s32 istate = (s32)atomic_read(state_ptr); |
| 539 | |
| 540 | if (istate > OCT_DEV_STATES || istate < 0) |
| 541 | return oct_dev_state_str[OCT_DEV_STATE_INVALID]; |
| 542 | return oct_dev_state_str[istate]; |
| 543 | } |
| 544 | |
| 545 | static char *get_oct_app_string(u32 app_mode) |
| 546 | { |
| 547 | if (app_mode <= CVM_DRV_APP_END) |
| 548 | return oct_dev_app_str[app_mode - CVM_DRV_APP_START]; |
| 549 | return oct_dev_app_str[CVM_DRV_INVALID_APP - CVM_DRV_APP_START]; |
| 550 | } |
| 551 | |
Raghu Vatsavayi | d3d7e6c | 2016-06-21 22:53:07 -0700 | [diff] [blame^] | 552 | u8 fbuf[4 * 1024 * 1024]; |
| 553 | |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 554 | int octeon_download_firmware(struct octeon_device *oct, const u8 *data, |
| 555 | size_t size) |
| 556 | { |
| 557 | int ret = 0; |
Raghu Vatsavayi | d3d7e6c | 2016-06-21 22:53:07 -0700 | [diff] [blame^] | 558 | u8 *p = fbuf; |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 559 | u32 crc32_result; |
| 560 | u64 load_addr; |
| 561 | u32 image_len; |
| 562 | struct octeon_firmware_file_header *h; |
Raghu Vatsavayi | d3d7e6c | 2016-06-21 22:53:07 -0700 | [diff] [blame^] | 563 | u32 i, rem, base_len = strlen(LIQUIDIO_BASE_VERSION); |
| 564 | char *base; |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 565 | |
| 566 | if (size < sizeof(struct octeon_firmware_file_header)) { |
| 567 | dev_err(&oct->pci_dev->dev, "Firmware file too small (%d < %d).\n", |
| 568 | (u32)size, |
| 569 | (u32)sizeof(struct octeon_firmware_file_header)); |
| 570 | return -EINVAL; |
| 571 | } |
| 572 | |
| 573 | h = (struct octeon_firmware_file_header *)data; |
| 574 | |
Raghu Vatsavayi | 5b173cf | 2015-06-12 18:11:50 -0700 | [diff] [blame] | 575 | if (be32_to_cpu(h->magic) != LIO_NIC_MAGIC) { |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 576 | dev_err(&oct->pci_dev->dev, "Unrecognized firmware file.\n"); |
| 577 | return -EINVAL; |
| 578 | } |
| 579 | |
Raghu Vatsavayi | d3d7e6c | 2016-06-21 22:53:07 -0700 | [diff] [blame^] | 580 | crc32_result = crc32((unsigned int)~0, data, |
| 581 | sizeof(struct octeon_firmware_file_header) - |
| 582 | sizeof(u32)) ^ ~0U; |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 583 | if (crc32_result != be32_to_cpu(h->crc32)) { |
| 584 | dev_err(&oct->pci_dev->dev, "Firmware CRC mismatch (0x%08x != 0x%08x).\n", |
| 585 | crc32_result, be32_to_cpu(h->crc32)); |
| 586 | return -EINVAL; |
| 587 | } |
| 588 | |
Raghu Vatsavayi | d3d7e6c | 2016-06-21 22:53:07 -0700 | [diff] [blame^] | 589 | if (strncmp(LIQUIDIO_PACKAGE, h->version, strlen(LIQUIDIO_PACKAGE))) { |
| 590 | dev_err(&oct->pci_dev->dev, "Unmatched firmware package type. Expected %s, got %s.\n", |
| 591 | LIQUIDIO_PACKAGE, h->version); |
| 592 | return -EINVAL; |
| 593 | } |
| 594 | |
| 595 | base = h->version + strlen(LIQUIDIO_PACKAGE); |
| 596 | ret = memcmp(LIQUIDIO_BASE_VERSION, base, base_len); |
| 597 | if (ret) { |
| 598 | dev_err(&oct->pci_dev->dev, "Unmatched firmware version. Expected %s.x, got %s.\n", |
| 599 | LIQUIDIO_BASE_VERSION, base); |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 600 | return -EINVAL; |
| 601 | } |
| 602 | |
| 603 | if (be32_to_cpu(h->num_images) > LIO_MAX_IMAGES) { |
| 604 | dev_err(&oct->pci_dev->dev, "Too many images in firmware file (%d).\n", |
| 605 | be32_to_cpu(h->num_images)); |
| 606 | return -EINVAL; |
| 607 | } |
| 608 | |
| 609 | dev_info(&oct->pci_dev->dev, "Firmware version: %s\n", h->version); |
| 610 | snprintf(oct->fw_info.liquidio_firmware_version, 32, "LIQUIDIO: %s", |
| 611 | h->version); |
| 612 | |
Raghu Vatsavayi | d3d7e6c | 2016-06-21 22:53:07 -0700 | [diff] [blame^] | 613 | data += sizeof(struct octeon_firmware_file_header); |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 614 | |
Raghu Vatsavayi | d3d7e6c | 2016-06-21 22:53:07 -0700 | [diff] [blame^] | 615 | dev_info(&oct->pci_dev->dev, "%s: Loading %d images\n", __func__, |
| 616 | be32_to_cpu(h->num_images)); |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 617 | /* load all images */ |
| 618 | for (i = 0; i < be32_to_cpu(h->num_images); i++) { |
| 619 | load_addr = be64_to_cpu(h->desc[i].addr); |
| 620 | image_len = be32_to_cpu(h->desc[i].len); |
| 621 | |
Raghu Vatsavayi | d3d7e6c | 2016-06-21 22:53:07 -0700 | [diff] [blame^] | 622 | dev_info(&oct->pci_dev->dev, "Loading firmware %d at %llx\n", |
| 623 | image_len, load_addr); |
| 624 | |
| 625 | /* Write in 4MB chunks*/ |
| 626 | rem = image_len; |
| 627 | |
| 628 | while (rem) { |
| 629 | if (rem < (4 * 1024 * 1024)) |
| 630 | size = rem; |
| 631 | else |
| 632 | size = 4 * 1024 * 1024; |
| 633 | |
| 634 | memcpy(p, data, size); |
| 635 | |
| 636 | /* download the image */ |
| 637 | octeon_pci_write_core_mem(oct, load_addr, p, (u32)size); |
| 638 | |
| 639 | data += size; |
| 640 | rem -= (u32)size; |
| 641 | load_addr += size; |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 642 | } |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 643 | } |
Raghu Vatsavayi | d3d7e6c | 2016-06-21 22:53:07 -0700 | [diff] [blame^] | 644 | dev_info(&oct->pci_dev->dev, "Writing boot command: %s\n", |
| 645 | h->bootcmd); |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 646 | |
| 647 | /* Invoke the bootcmd */ |
| 648 | ret = octeon_console_send_cmd(oct, h->bootcmd, 50); |
| 649 | |
Raghu Vatsavayi | d3d7e6c | 2016-06-21 22:53:07 -0700 | [diff] [blame^] | 650 | return 0; |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 651 | } |
| 652 | |
| 653 | void octeon_free_device_mem(struct octeon_device *oct) |
| 654 | { |
| 655 | u32 i; |
| 656 | |
Raghu Vatsavayi | 63da840 | 2016-06-21 22:53:03 -0700 | [diff] [blame] | 657 | for (i = 0; i < MAX_OCTEON_OUTPUT_QUEUES(oct); i++) { |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 658 | /* could check mask as well */ |
Markus Elfring | 9686f31 | 2015-06-29 12:22:24 +0200 | [diff] [blame] | 659 | vfree(oct->droq[i]); |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 660 | } |
| 661 | |
Raghu Vatsavayi | 63da840 | 2016-06-21 22:53:03 -0700 | [diff] [blame] | 662 | for (i = 0; i < MAX_OCTEON_INSTR_QUEUES(oct); i++) { |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 663 | /* could check mask as well */ |
Markus Elfring | 9686f31 | 2015-06-29 12:22:24 +0200 | [diff] [blame] | 664 | vfree(oct->instr_queue[i]); |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 665 | } |
| 666 | |
| 667 | i = oct->octeon_id; |
| 668 | vfree(oct); |
| 669 | |
| 670 | octeon_device[i] = NULL; |
| 671 | octeon_device_count--; |
| 672 | } |
| 673 | |
| 674 | static struct octeon_device *octeon_allocate_device_mem(u32 pci_id, |
| 675 | u32 priv_size) |
| 676 | { |
| 677 | struct octeon_device *oct; |
| 678 | u8 *buf = NULL; |
| 679 | u32 octdevsize = 0, configsize = 0, size; |
| 680 | |
| 681 | switch (pci_id) { |
| 682 | case OCTEON_CN68XX: |
| 683 | case OCTEON_CN66XX: |
| 684 | configsize = sizeof(struct octeon_cn6xxx); |
| 685 | break; |
| 686 | |
| 687 | default: |
| 688 | pr_err("%s: Unknown PCI Device: 0x%x\n", |
| 689 | __func__, |
| 690 | pci_id); |
| 691 | return NULL; |
| 692 | } |
| 693 | |
| 694 | if (configsize & 0x7) |
| 695 | configsize += (8 - (configsize & 0x7)); |
| 696 | |
| 697 | octdevsize = sizeof(struct octeon_device); |
| 698 | if (octdevsize & 0x7) |
| 699 | octdevsize += (8 - (octdevsize & 0x7)); |
| 700 | |
| 701 | if (priv_size & 0x7) |
| 702 | priv_size += (8 - (priv_size & 0x7)); |
| 703 | |
| 704 | size = octdevsize + priv_size + configsize + |
| 705 | (sizeof(struct octeon_dispatch) * DISPATCH_LIST_SIZE); |
| 706 | |
| 707 | buf = vmalloc(size); |
| 708 | if (!buf) |
| 709 | return NULL; |
| 710 | |
| 711 | memset(buf, 0, size); |
| 712 | |
| 713 | oct = (struct octeon_device *)buf; |
| 714 | oct->priv = (void *)(buf + octdevsize); |
| 715 | oct->chip = (void *)(buf + octdevsize + priv_size); |
| 716 | oct->dispatch.dlist = (struct octeon_dispatch *) |
| 717 | (buf + octdevsize + priv_size + configsize); |
| 718 | |
| 719 | return oct; |
| 720 | } |
| 721 | |
| 722 | struct octeon_device *octeon_allocate_device(u32 pci_id, |
| 723 | u32 priv_size) |
| 724 | { |
| 725 | u32 oct_idx = 0; |
| 726 | struct octeon_device *oct = NULL; |
| 727 | |
| 728 | for (oct_idx = 0; oct_idx < MAX_OCTEON_DEVICES; oct_idx++) |
| 729 | if (!octeon_device[oct_idx]) |
| 730 | break; |
| 731 | |
| 732 | if (oct_idx == MAX_OCTEON_DEVICES) |
| 733 | return NULL; |
| 734 | |
| 735 | oct = octeon_allocate_device_mem(pci_id, priv_size); |
| 736 | if (!oct) |
| 737 | return NULL; |
| 738 | |
| 739 | spin_lock_init(&oct->pci_win_lock); |
| 740 | spin_lock_init(&oct->mem_access_lock); |
| 741 | |
| 742 | octeon_device_count++; |
| 743 | octeon_device[oct_idx] = oct; |
| 744 | |
| 745 | oct->octeon_id = oct_idx; |
Raghu Vatsavayi | 63da840 | 2016-06-21 22:53:03 -0700 | [diff] [blame] | 746 | snprintf(oct->device_name, sizeof(oct->device_name), |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 747 | "LiquidIO%d", (oct->octeon_id)); |
| 748 | |
| 749 | return oct; |
| 750 | } |
| 751 | |
Raghu Vatsavayi | 26236fa | 2016-06-14 16:54:44 -0700 | [diff] [blame] | 752 | /* this function is only for setting up the first queue */ |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 753 | int octeon_setup_instr_queues(struct octeon_device *oct) |
| 754 | { |
Raghu Vatsavayi | 26236fa | 2016-06-14 16:54:44 -0700 | [diff] [blame] | 755 | u32 num_iqs = 0; |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 756 | u32 num_descs = 0; |
Raghu Vatsavayi | 26236fa | 2016-06-14 16:54:44 -0700 | [diff] [blame] | 757 | u32 iq_no = 0; |
| 758 | union oct_txpciq txpciq; |
| 759 | int numa_node = cpu_to_node(iq_no % num_online_cpus()); |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 760 | |
Raghu Vatsavayi | 26236fa | 2016-06-14 16:54:44 -0700 | [diff] [blame] | 761 | num_iqs = 1; |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 762 | /* this causes queue 0 to be default queue */ |
Raghu Vatsavayi | 26236fa | 2016-06-14 16:54:44 -0700 | [diff] [blame] | 763 | if (OCTEON_CN6XXX(oct)) |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 764 | num_descs = |
| 765 | CFG_GET_NUM_DEF_TX_DESCS(CHIP_FIELD(oct, cn6xxx, conf)); |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 766 | |
| 767 | oct->num_iqs = 0; |
| 768 | |
Raghu Vatsavayi | 26236fa | 2016-06-14 16:54:44 -0700 | [diff] [blame] | 769 | oct->instr_queue[0] = vmalloc_node(sizeof(*oct->instr_queue[0]), |
| 770 | numa_node); |
| 771 | if (!oct->instr_queue[0]) |
| 772 | oct->instr_queue[0] = |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 773 | vmalloc(sizeof(struct octeon_instr_queue)); |
Raghu Vatsavayi | 26236fa | 2016-06-14 16:54:44 -0700 | [diff] [blame] | 774 | if (!oct->instr_queue[0]) |
| 775 | return 1; |
| 776 | memset(oct->instr_queue[0], 0, sizeof(struct octeon_instr_queue)); |
Raghu Vatsavayi | 0cece6c | 2016-06-14 16:54:50 -0700 | [diff] [blame] | 777 | oct->instr_queue[0]->q_index = 0; |
Raghu Vatsavayi | 26236fa | 2016-06-14 16:54:44 -0700 | [diff] [blame] | 778 | oct->instr_queue[0]->app_ctx = (void *)(size_t)0; |
Raghu Vatsavayi | 0cece6c | 2016-06-14 16:54:50 -0700 | [diff] [blame] | 779 | oct->instr_queue[0]->ifidx = 0; |
Raghu Vatsavayi | 26236fa | 2016-06-14 16:54:44 -0700 | [diff] [blame] | 780 | txpciq.u64 = 0; |
| 781 | txpciq.s.q_no = iq_no; |
| 782 | txpciq.s.use_qpg = 0; |
| 783 | txpciq.s.qpg = 0; |
| 784 | if (octeon_init_instr_queue(oct, txpciq, num_descs)) { |
| 785 | /* prevent memory leak */ |
| 786 | vfree(oct->instr_queue[0]); |
| 787 | return 1; |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 788 | } |
| 789 | |
Raghu Vatsavayi | 26236fa | 2016-06-14 16:54:44 -0700 | [diff] [blame] | 790 | oct->num_iqs++; |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 791 | return 0; |
| 792 | } |
| 793 | |
| 794 | int octeon_setup_output_queues(struct octeon_device *oct) |
| 795 | { |
Raghu Vatsavayi | 96ae48b | 2016-06-14 16:54:46 -0700 | [diff] [blame] | 796 | u32 num_oqs = 0; |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 797 | u32 num_descs = 0; |
| 798 | u32 desc_size = 0; |
Raghu Vatsavayi | 96ae48b | 2016-06-14 16:54:46 -0700 | [diff] [blame] | 799 | u32 oq_no = 0; |
| 800 | int numa_node = cpu_to_node(oq_no % num_online_cpus()); |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 801 | |
Raghu Vatsavayi | 96ae48b | 2016-06-14 16:54:46 -0700 | [diff] [blame] | 802 | num_oqs = 1; |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 803 | /* this causes queue 0 to be default queue */ |
| 804 | if (OCTEON_CN6XXX(oct)) { |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 805 | num_descs = |
| 806 | CFG_GET_NUM_DEF_RX_DESCS(CHIP_FIELD(oct, cn6xxx, conf)); |
| 807 | desc_size = |
| 808 | CFG_GET_DEF_RX_BUF_SIZE(CHIP_FIELD(oct, cn6xxx, conf)); |
| 809 | } |
| 810 | |
| 811 | oct->num_oqs = 0; |
Raghu Vatsavayi | 96ae48b | 2016-06-14 16:54:46 -0700 | [diff] [blame] | 812 | oct->droq[0] = vmalloc_node(sizeof(*oct->droq[0]), numa_node); |
| 813 | if (!oct->droq[0]) |
| 814 | oct->droq[0] = vmalloc(sizeof(*oct->droq[0])); |
| 815 | if (!oct->droq[0]) |
| 816 | return 1; |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 817 | |
Raghu Vatsavayi | 96ae48b | 2016-06-14 16:54:46 -0700 | [diff] [blame] | 818 | if (octeon_init_droq(oct, oq_no, num_descs, desc_size, NULL)) |
| 819 | return 1; |
| 820 | oct->num_oqs++; |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 821 | |
| 822 | return 0; |
| 823 | } |
| 824 | |
| 825 | void octeon_set_io_queues_off(struct octeon_device *oct) |
| 826 | { |
| 827 | /* Disable the i/p and o/p queues for this Octeon. */ |
| 828 | |
| 829 | octeon_write_csr(oct, CN6XXX_SLI_PKT_INSTR_ENB, 0); |
| 830 | octeon_write_csr(oct, CN6XXX_SLI_PKT_OUT_ENB, 0); |
| 831 | } |
| 832 | |
| 833 | void octeon_set_droq_pkt_op(struct octeon_device *oct, |
| 834 | u32 q_no, |
| 835 | u32 enable) |
| 836 | { |
| 837 | u32 reg_val = 0; |
| 838 | |
| 839 | /* Disable the i/p and o/p queues for this Octeon. */ |
| 840 | reg_val = octeon_read_csr(oct, CN6XXX_SLI_PKT_OUT_ENB); |
| 841 | |
| 842 | if (enable) |
| 843 | reg_val = reg_val | (1 << q_no); |
| 844 | else |
| 845 | reg_val = reg_val & (~(1 << q_no)); |
| 846 | |
| 847 | octeon_write_csr(oct, CN6XXX_SLI_PKT_OUT_ENB, reg_val); |
| 848 | } |
| 849 | |
| 850 | int octeon_init_dispatch_list(struct octeon_device *oct) |
| 851 | { |
| 852 | u32 i; |
| 853 | |
| 854 | oct->dispatch.count = 0; |
| 855 | |
| 856 | for (i = 0; i < DISPATCH_LIST_SIZE; i++) { |
| 857 | oct->dispatch.dlist[i].opcode = 0; |
| 858 | INIT_LIST_HEAD(&oct->dispatch.dlist[i].list); |
| 859 | } |
| 860 | |
| 861 | for (i = 0; i <= REQTYPE_LAST; i++) |
| 862 | octeon_register_reqtype_free_fn(oct, i, NULL); |
| 863 | |
| 864 | spin_lock_init(&oct->dispatch.lock); |
| 865 | |
| 866 | return 0; |
| 867 | } |
| 868 | |
| 869 | void octeon_delete_dispatch_list(struct octeon_device *oct) |
| 870 | { |
| 871 | u32 i; |
| 872 | struct list_head freelist, *temp, *tmp2; |
| 873 | |
| 874 | INIT_LIST_HEAD(&freelist); |
| 875 | |
| 876 | spin_lock_bh(&oct->dispatch.lock); |
| 877 | |
| 878 | for (i = 0; i < DISPATCH_LIST_SIZE; i++) { |
| 879 | struct list_head *dispatch; |
| 880 | |
| 881 | dispatch = &oct->dispatch.dlist[i].list; |
| 882 | while (dispatch->next != dispatch) { |
| 883 | temp = dispatch->next; |
| 884 | list_del(temp); |
| 885 | list_add_tail(temp, &freelist); |
| 886 | } |
| 887 | |
| 888 | oct->dispatch.dlist[i].opcode = 0; |
| 889 | } |
| 890 | |
| 891 | oct->dispatch.count = 0; |
| 892 | |
| 893 | spin_unlock_bh(&oct->dispatch.lock); |
| 894 | |
| 895 | list_for_each_safe(temp, tmp2, &freelist) { |
| 896 | list_del(temp); |
| 897 | vfree(temp); |
| 898 | } |
| 899 | } |
| 900 | |
| 901 | octeon_dispatch_fn_t |
| 902 | octeon_get_dispatch(struct octeon_device *octeon_dev, u16 opcode, |
| 903 | u16 subcode) |
| 904 | { |
| 905 | u32 idx; |
| 906 | struct list_head *dispatch; |
| 907 | octeon_dispatch_fn_t fn = NULL; |
| 908 | u16 combined_opcode = OPCODE_SUBCODE(opcode, subcode); |
| 909 | |
| 910 | idx = combined_opcode & OCTEON_OPCODE_MASK; |
| 911 | |
| 912 | spin_lock_bh(&octeon_dev->dispatch.lock); |
| 913 | |
| 914 | if (octeon_dev->dispatch.count == 0) { |
| 915 | spin_unlock_bh(&octeon_dev->dispatch.lock); |
| 916 | return NULL; |
| 917 | } |
| 918 | |
| 919 | if (!(octeon_dev->dispatch.dlist[idx].opcode)) { |
| 920 | spin_unlock_bh(&octeon_dev->dispatch.lock); |
| 921 | return NULL; |
| 922 | } |
| 923 | |
| 924 | if (octeon_dev->dispatch.dlist[idx].opcode == combined_opcode) { |
| 925 | fn = octeon_dev->dispatch.dlist[idx].dispatch_fn; |
| 926 | } else { |
| 927 | list_for_each(dispatch, |
| 928 | &octeon_dev->dispatch.dlist[idx].list) { |
| 929 | if (((struct octeon_dispatch *)dispatch)->opcode == |
| 930 | combined_opcode) { |
| 931 | fn = ((struct octeon_dispatch *) |
| 932 | dispatch)->dispatch_fn; |
| 933 | break; |
| 934 | } |
| 935 | } |
| 936 | } |
| 937 | |
| 938 | spin_unlock_bh(&octeon_dev->dispatch.lock); |
| 939 | return fn; |
| 940 | } |
| 941 | |
| 942 | /* octeon_register_dispatch_fn |
| 943 | * Parameters: |
| 944 | * octeon_id - id of the octeon device. |
| 945 | * opcode - opcode for which driver should call the registered function |
| 946 | * subcode - subcode for which driver should call the registered function |
| 947 | * fn - The function to call when a packet with "opcode" arrives in |
| 948 | * octeon output queues. |
| 949 | * fn_arg - The argument to be passed when calling function "fn". |
| 950 | * Description: |
| 951 | * Registers a function and its argument to be called when a packet |
| 952 | * arrives in Octeon output queues with "opcode". |
| 953 | * Returns: |
| 954 | * Success: 0 |
| 955 | * Failure: 1 |
| 956 | * Locks: |
| 957 | * No locks are held. |
| 958 | */ |
| 959 | int |
| 960 | octeon_register_dispatch_fn(struct octeon_device *oct, |
| 961 | u16 opcode, |
| 962 | u16 subcode, |
| 963 | octeon_dispatch_fn_t fn, void *fn_arg) |
| 964 | { |
| 965 | u32 idx; |
| 966 | octeon_dispatch_fn_t pfn; |
| 967 | u16 combined_opcode = OPCODE_SUBCODE(opcode, subcode); |
| 968 | |
| 969 | idx = combined_opcode & OCTEON_OPCODE_MASK; |
| 970 | |
| 971 | spin_lock_bh(&oct->dispatch.lock); |
| 972 | /* Add dispatch function to first level of lookup table */ |
| 973 | if (oct->dispatch.dlist[idx].opcode == 0) { |
| 974 | oct->dispatch.dlist[idx].opcode = combined_opcode; |
| 975 | oct->dispatch.dlist[idx].dispatch_fn = fn; |
| 976 | oct->dispatch.dlist[idx].arg = fn_arg; |
| 977 | oct->dispatch.count++; |
| 978 | spin_unlock_bh(&oct->dispatch.lock); |
| 979 | return 0; |
| 980 | } |
| 981 | |
| 982 | spin_unlock_bh(&oct->dispatch.lock); |
| 983 | |
| 984 | /* Check if there was a function already registered for this |
| 985 | * opcode/subcode. |
| 986 | */ |
| 987 | pfn = octeon_get_dispatch(oct, opcode, subcode); |
| 988 | if (!pfn) { |
| 989 | struct octeon_dispatch *dispatch; |
| 990 | |
| 991 | dev_dbg(&oct->pci_dev->dev, |
| 992 | "Adding opcode to dispatch list linked list\n"); |
| 993 | dispatch = (struct octeon_dispatch *) |
| 994 | vmalloc(sizeof(struct octeon_dispatch)); |
| 995 | if (!dispatch) { |
| 996 | dev_err(&oct->pci_dev->dev, |
| 997 | "No memory to add dispatch function\n"); |
| 998 | return 1; |
| 999 | } |
| 1000 | dispatch->opcode = combined_opcode; |
| 1001 | dispatch->dispatch_fn = fn; |
| 1002 | dispatch->arg = fn_arg; |
| 1003 | |
| 1004 | /* Add dispatch function to linked list of fn ptrs |
| 1005 | * at the hashed index. |
| 1006 | */ |
| 1007 | spin_lock_bh(&oct->dispatch.lock); |
| 1008 | list_add(&dispatch->list, &oct->dispatch.dlist[idx].list); |
| 1009 | oct->dispatch.count++; |
| 1010 | spin_unlock_bh(&oct->dispatch.lock); |
| 1011 | |
| 1012 | } else { |
| 1013 | dev_err(&oct->pci_dev->dev, |
| 1014 | "Found previously registered dispatch fn for opcode/subcode: %x/%x\n", |
| 1015 | opcode, subcode); |
| 1016 | return 1; |
| 1017 | } |
| 1018 | |
| 1019 | return 0; |
| 1020 | } |
| 1021 | |
| 1022 | /* octeon_unregister_dispatch_fn |
| 1023 | * Parameters: |
| 1024 | * oct - octeon device |
| 1025 | * opcode - driver should unregister the function for this opcode |
| 1026 | * subcode - driver should unregister the function for this subcode |
| 1027 | * Description: |
| 1028 | * Unregister the function set for this opcode+subcode. |
| 1029 | * Returns: |
| 1030 | * Success: 0 |
| 1031 | * Failure: 1 |
| 1032 | * Locks: |
| 1033 | * No locks are held. |
| 1034 | */ |
| 1035 | int |
| 1036 | octeon_unregister_dispatch_fn(struct octeon_device *oct, u16 opcode, |
| 1037 | u16 subcode) |
| 1038 | { |
| 1039 | int retval = 0; |
| 1040 | u32 idx; |
| 1041 | struct list_head *dispatch, *dfree = NULL, *tmp2; |
| 1042 | u16 combined_opcode = OPCODE_SUBCODE(opcode, subcode); |
| 1043 | |
| 1044 | idx = combined_opcode & OCTEON_OPCODE_MASK; |
| 1045 | |
| 1046 | spin_lock_bh(&oct->dispatch.lock); |
| 1047 | |
| 1048 | if (oct->dispatch.count == 0) { |
| 1049 | spin_unlock_bh(&oct->dispatch.lock); |
| 1050 | dev_err(&oct->pci_dev->dev, |
| 1051 | "No dispatch functions registered for this device\n"); |
| 1052 | return 1; |
| 1053 | } |
| 1054 | |
| 1055 | if (oct->dispatch.dlist[idx].opcode == combined_opcode) { |
| 1056 | dispatch = &oct->dispatch.dlist[idx].list; |
| 1057 | if (dispatch->next != dispatch) { |
| 1058 | dispatch = dispatch->next; |
| 1059 | oct->dispatch.dlist[idx].opcode = |
| 1060 | ((struct octeon_dispatch *)dispatch)->opcode; |
| 1061 | oct->dispatch.dlist[idx].dispatch_fn = |
| 1062 | ((struct octeon_dispatch *) |
| 1063 | dispatch)->dispatch_fn; |
| 1064 | oct->dispatch.dlist[idx].arg = |
| 1065 | ((struct octeon_dispatch *)dispatch)->arg; |
| 1066 | list_del(dispatch); |
| 1067 | dfree = dispatch; |
| 1068 | } else { |
| 1069 | oct->dispatch.dlist[idx].opcode = 0; |
| 1070 | oct->dispatch.dlist[idx].dispatch_fn = NULL; |
| 1071 | oct->dispatch.dlist[idx].arg = NULL; |
| 1072 | } |
| 1073 | } else { |
| 1074 | retval = 1; |
| 1075 | list_for_each_safe(dispatch, tmp2, |
| 1076 | &(oct->dispatch.dlist[idx]. |
| 1077 | list)) { |
| 1078 | if (((struct octeon_dispatch *)dispatch)->opcode == |
| 1079 | combined_opcode) { |
| 1080 | list_del(dispatch); |
| 1081 | dfree = dispatch; |
| 1082 | retval = 0; |
| 1083 | } |
| 1084 | } |
| 1085 | } |
| 1086 | |
| 1087 | if (!retval) |
| 1088 | oct->dispatch.count--; |
| 1089 | |
| 1090 | spin_unlock_bh(&oct->dispatch.lock); |
Markus Elfring | 9686f31 | 2015-06-29 12:22:24 +0200 | [diff] [blame] | 1091 | vfree(dfree); |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 1092 | return retval; |
| 1093 | } |
| 1094 | |
| 1095 | int octeon_core_drv_init(struct octeon_recv_info *recv_info, void *buf) |
| 1096 | { |
| 1097 | u32 i; |
| 1098 | char app_name[16]; |
| 1099 | struct octeon_device *oct = (struct octeon_device *)buf; |
| 1100 | struct octeon_recv_pkt *recv_pkt = recv_info->recv_pkt; |
| 1101 | struct octeon_core_setup *cs = NULL; |
| 1102 | u32 num_nic_ports = 0; |
| 1103 | |
| 1104 | if (OCTEON_CN6XXX(oct)) |
| 1105 | num_nic_ports = |
| 1106 | CFG_GET_NUM_NIC_PORTS(CHIP_FIELD(oct, cn6xxx, conf)); |
| 1107 | |
| 1108 | if (atomic_read(&oct->status) >= OCT_DEV_RUNNING) { |
| 1109 | dev_err(&oct->pci_dev->dev, "Received CORE OK when device state is 0x%x\n", |
| 1110 | atomic_read(&oct->status)); |
| 1111 | goto core_drv_init_err; |
| 1112 | } |
| 1113 | |
| 1114 | strncpy(app_name, |
| 1115 | get_oct_app_string( |
| 1116 | (u32)recv_pkt->rh.r_core_drv_init.app_mode), |
| 1117 | sizeof(app_name) - 1); |
| 1118 | oct->app_mode = (u32)recv_pkt->rh.r_core_drv_init.app_mode; |
Raghu Vatsavayi | 5b173cf | 2015-06-12 18:11:50 -0700 | [diff] [blame] | 1119 | if (recv_pkt->rh.r_core_drv_init.app_mode == CVM_DRV_NIC_APP) { |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 1120 | oct->fw_info.max_nic_ports = |
| 1121 | (u32)recv_pkt->rh.r_core_drv_init.max_nic_ports; |
| 1122 | oct->fw_info.num_gmx_ports = |
| 1123 | (u32)recv_pkt->rh.r_core_drv_init.num_gmx_ports; |
Raghu Vatsavayi | 5b173cf | 2015-06-12 18:11:50 -0700 | [diff] [blame] | 1124 | } |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 1125 | |
| 1126 | if (oct->fw_info.max_nic_ports < num_nic_ports) { |
| 1127 | dev_err(&oct->pci_dev->dev, |
| 1128 | "Config has more ports than firmware allows (%d > %d).\n", |
| 1129 | num_nic_ports, oct->fw_info.max_nic_ports); |
| 1130 | goto core_drv_init_err; |
| 1131 | } |
| 1132 | oct->fw_info.app_cap_flags = recv_pkt->rh.r_core_drv_init.app_cap_flags; |
| 1133 | oct->fw_info.app_mode = (u32)recv_pkt->rh.r_core_drv_init.app_mode; |
| 1134 | |
| 1135 | atomic_set(&oct->status, OCT_DEV_CORE_OK); |
| 1136 | |
| 1137 | cs = &core_setup[oct->octeon_id]; |
| 1138 | |
| 1139 | if (recv_pkt->buffer_size[0] != sizeof(*cs)) { |
| 1140 | dev_dbg(&oct->pci_dev->dev, "Core setup bytes expected %u found %d\n", |
| 1141 | (u32)sizeof(*cs), |
| 1142 | recv_pkt->buffer_size[0]); |
| 1143 | } |
| 1144 | |
| 1145 | memcpy(cs, get_rbd(recv_pkt->buffer_ptr[0]), sizeof(*cs)); |
| 1146 | strncpy(oct->boardinfo.name, cs->boardname, OCT_BOARD_NAME); |
| 1147 | strncpy(oct->boardinfo.serial_number, cs->board_serial_number, |
| 1148 | OCT_SERIAL_LEN); |
| 1149 | |
| 1150 | octeon_swap_8B_data((u64 *)cs, (sizeof(*cs) >> 3)); |
| 1151 | |
| 1152 | oct->boardinfo.major = cs->board_rev_major; |
| 1153 | oct->boardinfo.minor = cs->board_rev_minor; |
| 1154 | |
| 1155 | dev_info(&oct->pci_dev->dev, |
| 1156 | "Running %s (%llu Hz)\n", |
| 1157 | app_name, CVM_CAST64(cs->corefreq)); |
| 1158 | |
| 1159 | core_drv_init_err: |
| 1160 | for (i = 0; i < recv_pkt->buffer_count; i++) |
| 1161 | recv_buffer_free(recv_pkt->buffer_ptr[i]); |
| 1162 | octeon_free_recv_info(recv_info); |
| 1163 | return 0; |
| 1164 | } |
| 1165 | |
| 1166 | int octeon_get_tx_qsize(struct octeon_device *oct, u32 q_no) |
| 1167 | |
| 1168 | { |
Raghu Vatsavayi | 63da840 | 2016-06-21 22:53:03 -0700 | [diff] [blame] | 1169 | if (oct && (q_no < MAX_OCTEON_INSTR_QUEUES(oct)) && |
| 1170 | (oct->io_qmask.iq & (1ULL << q_no))) |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 1171 | return oct->instr_queue[q_no]->max_count; |
| 1172 | |
| 1173 | return -1; |
| 1174 | } |
| 1175 | |
| 1176 | int octeon_get_rx_qsize(struct octeon_device *oct, u32 q_no) |
| 1177 | { |
Raghu Vatsavayi | 63da840 | 2016-06-21 22:53:03 -0700 | [diff] [blame] | 1178 | if (oct && (q_no < MAX_OCTEON_OUTPUT_QUEUES(oct)) && |
| 1179 | (oct->io_qmask.oq & (1ULL << q_no))) |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 1180 | return oct->droq[q_no]->max_count; |
| 1181 | return -1; |
| 1182 | } |
| 1183 | |
| 1184 | /* Retruns the host firmware handshake OCTEON specific configuration */ |
| 1185 | struct octeon_config *octeon_get_conf(struct octeon_device *oct) |
| 1186 | { |
| 1187 | struct octeon_config *default_oct_conf = NULL; |
| 1188 | |
| 1189 | /* check the OCTEON Device model & return the corresponding octeon |
| 1190 | * configuration |
| 1191 | */ |
| 1192 | |
| 1193 | if (OCTEON_CN6XXX(oct)) { |
| 1194 | default_oct_conf = |
| 1195 | (struct octeon_config *)(CHIP_FIELD(oct, cn6xxx, conf)); |
| 1196 | } |
| 1197 | |
| 1198 | return default_oct_conf; |
| 1199 | } |
| 1200 | |
| 1201 | /* scratch register address is same in all the OCT-II and CN70XX models */ |
| 1202 | #define CNXX_SLI_SCRATCH1 0x3C0 |
| 1203 | |
| 1204 | /** Get the octeon device pointer. |
| 1205 | * @param octeon_id - The id for which the octeon device pointer is required. |
| 1206 | * @return Success: Octeon device pointer. |
| 1207 | * @return Failure: NULL. |
| 1208 | */ |
| 1209 | struct octeon_device *lio_get_device(u32 octeon_id) |
| 1210 | { |
| 1211 | if (octeon_id >= MAX_OCTEON_DEVICES) |
| 1212 | return NULL; |
| 1213 | else |
| 1214 | return octeon_device[octeon_id]; |
| 1215 | } |
| 1216 | |
| 1217 | u64 lio_pci_readq(struct octeon_device *oct, u64 addr) |
| 1218 | { |
| 1219 | u64 val64; |
| 1220 | unsigned long flags; |
| 1221 | u32 val32, addrhi; |
| 1222 | |
| 1223 | spin_lock_irqsave(&oct->pci_win_lock, flags); |
| 1224 | |
| 1225 | /* The windowed read happens when the LSB of the addr is written. |
| 1226 | * So write MSB first |
| 1227 | */ |
| 1228 | addrhi = (addr >> 32); |
| 1229 | if ((oct->chip_id == OCTEON_CN66XX) || (oct->chip_id == OCTEON_CN68XX)) |
| 1230 | addrhi |= 0x00060000; |
| 1231 | writel(addrhi, oct->reg_list.pci_win_rd_addr_hi); |
| 1232 | |
| 1233 | /* Read back to preserve ordering of writes */ |
| 1234 | val32 = readl(oct->reg_list.pci_win_rd_addr_hi); |
| 1235 | |
| 1236 | writel(addr & 0xffffffff, oct->reg_list.pci_win_rd_addr_lo); |
| 1237 | val32 = readl(oct->reg_list.pci_win_rd_addr_lo); |
| 1238 | |
| 1239 | val64 = readq(oct->reg_list.pci_win_rd_data); |
| 1240 | |
| 1241 | spin_unlock_irqrestore(&oct->pci_win_lock, flags); |
| 1242 | |
| 1243 | return val64; |
| 1244 | } |
| 1245 | |
| 1246 | void lio_pci_writeq(struct octeon_device *oct, |
| 1247 | u64 val, |
| 1248 | u64 addr) |
| 1249 | { |
| 1250 | u32 val32; |
| 1251 | unsigned long flags; |
| 1252 | |
| 1253 | spin_lock_irqsave(&oct->pci_win_lock, flags); |
| 1254 | |
| 1255 | writeq(addr, oct->reg_list.pci_win_wr_addr); |
| 1256 | |
| 1257 | /* The write happens when the LSB is written. So write MSB first. */ |
| 1258 | writel(val >> 32, oct->reg_list.pci_win_wr_data_hi); |
| 1259 | /* Read the MSB to ensure ordering of writes. */ |
| 1260 | val32 = readl(oct->reg_list.pci_win_wr_data_hi); |
| 1261 | |
| 1262 | writel(val & 0xffffffff, oct->reg_list.pci_win_wr_data_lo); |
| 1263 | |
| 1264 | spin_unlock_irqrestore(&oct->pci_win_lock, flags); |
| 1265 | } |
| 1266 | |
| 1267 | int octeon_mem_access_ok(struct octeon_device *oct) |
| 1268 | { |
| 1269 | u64 access_okay = 0; |
Raghu Vatsavayi | 63da840 | 2016-06-21 22:53:03 -0700 | [diff] [blame] | 1270 | u64 lmc0_reset_ctl; |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 1271 | |
| 1272 | /* Check to make sure a DDR interface is enabled */ |
Raghu Vatsavayi | 63da840 | 2016-06-21 22:53:03 -0700 | [diff] [blame] | 1273 | lmc0_reset_ctl = lio_pci_readq(oct, CN6XXX_LMC0_RESET_CTL); |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 1274 | access_okay = (lmc0_reset_ctl & CN6XXX_LMC0_RESET_CTL_DDR3RST_MASK); |
| 1275 | |
| 1276 | return access_okay ? 0 : 1; |
| 1277 | } |
| 1278 | |
| 1279 | int octeon_wait_for_ddr_init(struct octeon_device *oct, u32 *timeout) |
| 1280 | { |
| 1281 | int ret = 1; |
| 1282 | u32 ms; |
| 1283 | |
| 1284 | if (!timeout) |
| 1285 | return ret; |
| 1286 | |
| 1287 | while (*timeout == 0) |
| 1288 | schedule_timeout_uninterruptible(HZ / 10); |
| 1289 | |
| 1290 | for (ms = 0; (ret != 0) && ((*timeout == 0) || (ms <= *timeout)); |
| 1291 | ms += HZ / 10) { |
| 1292 | ret = octeon_mem_access_ok(oct); |
| 1293 | |
| 1294 | /* wait 100 ms */ |
| 1295 | if (ret) |
| 1296 | schedule_timeout_uninterruptible(HZ / 10); |
| 1297 | } |
| 1298 | |
| 1299 | return ret; |
| 1300 | } |
| 1301 | |
| 1302 | /** Get the octeon id assigned to the octeon device passed as argument. |
| 1303 | * This function is exported to other modules. |
| 1304 | * @param dev - octeon device pointer passed as a void *. |
| 1305 | * @return octeon device id |
| 1306 | */ |
| 1307 | int lio_get_device_id(void *dev) |
| 1308 | { |
| 1309 | struct octeon_device *octeon_dev = (struct octeon_device *)dev; |
| 1310 | u32 i; |
| 1311 | |
| 1312 | for (i = 0; i < MAX_OCTEON_DEVICES; i++) |
| 1313 | if (octeon_device[i] == octeon_dev) |
| 1314 | return octeon_dev->octeon_id; |
| 1315 | return -1; |
| 1316 | } |