qla_attr.c 55 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089
  1. /*
  2. * QLogic Fibre Channel HBA Driver
  3. * Copyright (c) 2003-2011 QLogic Corporation
  4. *
  5. * See LICENSE.qla2xxx for copyright and licensing details.
  6. */
  7. #include "qla_def.h"
  8. #include <linux/kthread.h>
  9. #include <linux/vmalloc.h>
  10. #include <linux/slab.h>
  11. #include <linux/delay.h>
  12. static int qla24xx_vport_disable(struct fc_vport *, bool);
  13. /* SYSFS attributes --------------------------------------------------------- */
  14. static ssize_t
  15. qla2x00_sysfs_read_fw_dump(struct file *filp, struct kobject *kobj,
  16. struct bin_attribute *bin_attr,
  17. char *buf, loff_t off, size_t count)
  18. {
  19. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  20. struct device, kobj)));
  21. struct qla_hw_data *ha = vha->hw;
  22. int rval = 0;
  23. if (ha->fw_dump_reading == 0)
  24. return 0;
  25. if (IS_QLA82XX(ha)) {
  26. if (off < ha->md_template_size) {
  27. rval = memory_read_from_buffer(buf, count,
  28. &off, ha->md_tmplt_hdr, ha->md_template_size);
  29. return rval;
  30. }
  31. off -= ha->md_template_size;
  32. rval = memory_read_from_buffer(buf, count,
  33. &off, ha->md_dump, ha->md_dump_size);
  34. return rval;
  35. } else
  36. return memory_read_from_buffer(buf, count, &off, ha->fw_dump,
  37. ha->fw_dump_len);
  38. }
  39. static ssize_t
  40. qla2x00_sysfs_write_fw_dump(struct file *filp, struct kobject *kobj,
  41. struct bin_attribute *bin_attr,
  42. char *buf, loff_t off, size_t count)
  43. {
  44. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  45. struct device, kobj)));
  46. struct qla_hw_data *ha = vha->hw;
  47. int reading;
  48. if (off != 0)
  49. return (0);
  50. reading = simple_strtol(buf, NULL, 10);
  51. switch (reading) {
  52. case 0:
  53. if (!ha->fw_dump_reading)
  54. break;
  55. ql_log(ql_log_info, vha, 0x705d,
  56. "Firmware dump cleared on (%ld).\n", vha->host_no);
  57. if (IS_QLA82XX(vha->hw)) {
  58. qla82xx_md_free(vha);
  59. qla82xx_md_prep(vha);
  60. }
  61. ha->fw_dump_reading = 0;
  62. ha->fw_dumped = 0;
  63. break;
  64. case 1:
  65. if (ha->fw_dumped && !ha->fw_dump_reading) {
  66. ha->fw_dump_reading = 1;
  67. ql_log(ql_log_info, vha, 0x705e,
  68. "Raw firmware dump ready for read on (%ld).\n",
  69. vha->host_no);
  70. }
  71. break;
  72. case 2:
  73. qla2x00_alloc_fw_dump(vha);
  74. break;
  75. case 3:
  76. if (IS_QLA82XX(ha)) {
  77. qla82xx_idc_lock(ha);
  78. qla82xx_set_reset_owner(vha);
  79. qla82xx_idc_unlock(ha);
  80. } else
  81. qla2x00_system_error(vha);
  82. break;
  83. case 4:
  84. if (IS_QLA82XX(ha)) {
  85. if (ha->md_tmplt_hdr)
  86. ql_dbg(ql_dbg_user, vha, 0x705b,
  87. "MiniDump supported with this firmware.\n");
  88. else
  89. ql_dbg(ql_dbg_user, vha, 0x709d,
  90. "MiniDump not supported with this firmware.\n");
  91. }
  92. break;
  93. case 5:
  94. if (IS_QLA82XX(ha))
  95. set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
  96. break;
  97. }
  98. return (count);
  99. }
  100. static struct bin_attribute sysfs_fw_dump_attr = {
  101. .attr = {
  102. .name = "fw_dump",
  103. .mode = S_IRUSR | S_IWUSR,
  104. },
  105. .size = 0,
  106. .read = qla2x00_sysfs_read_fw_dump,
  107. .write = qla2x00_sysfs_write_fw_dump,
  108. };
  109. static ssize_t
  110. qla2x00_sysfs_read_nvram(struct file *filp, struct kobject *kobj,
  111. struct bin_attribute *bin_attr,
  112. char *buf, loff_t off, size_t count)
  113. {
  114. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  115. struct device, kobj)));
  116. struct qla_hw_data *ha = vha->hw;
  117. if (!capable(CAP_SYS_ADMIN))
  118. return 0;
  119. if (IS_NOCACHE_VPD_TYPE(ha))
  120. ha->isp_ops->read_optrom(vha, ha->nvram, ha->flt_region_nvram << 2,
  121. ha->nvram_size);
  122. return memory_read_from_buffer(buf, count, &off, ha->nvram,
  123. ha->nvram_size);
  124. }
  125. static ssize_t
  126. qla2x00_sysfs_write_nvram(struct file *filp, struct kobject *kobj,
  127. struct bin_attribute *bin_attr,
  128. char *buf, loff_t off, size_t count)
  129. {
  130. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  131. struct device, kobj)));
  132. struct qla_hw_data *ha = vha->hw;
  133. uint16_t cnt;
  134. if (!capable(CAP_SYS_ADMIN) || off != 0 || count != ha->nvram_size ||
  135. !ha->isp_ops->write_nvram)
  136. return 0;
  137. /* Checksum NVRAM. */
  138. if (IS_FWI2_CAPABLE(ha)) {
  139. uint32_t *iter;
  140. uint32_t chksum;
  141. iter = (uint32_t *)buf;
  142. chksum = 0;
  143. for (cnt = 0; cnt < ((count >> 2) - 1); cnt++)
  144. chksum += le32_to_cpu(*iter++);
  145. chksum = ~chksum + 1;
  146. *iter = cpu_to_le32(chksum);
  147. } else {
  148. uint8_t *iter;
  149. uint8_t chksum;
  150. iter = (uint8_t *)buf;
  151. chksum = 0;
  152. for (cnt = 0; cnt < count - 1; cnt++)
  153. chksum += *iter++;
  154. chksum = ~chksum + 1;
  155. *iter = chksum;
  156. }
  157. if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
  158. ql_log(ql_log_warn, vha, 0x705f,
  159. "HBA not online, failing NVRAM update.\n");
  160. return -EAGAIN;
  161. }
  162. /* Write NVRAM. */
  163. ha->isp_ops->write_nvram(vha, (uint8_t *)buf, ha->nvram_base, count);
  164. ha->isp_ops->read_nvram(vha, (uint8_t *)ha->nvram, ha->nvram_base,
  165. count);
  166. ql_dbg(ql_dbg_user, vha, 0x7060,
  167. "Setting ISP_ABORT_NEEDED\n");
  168. /* NVRAM settings take effect immediately. */
  169. set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
  170. qla2xxx_wake_dpc(vha);
  171. qla2x00_wait_for_chip_reset(vha);
  172. return (count);
  173. }
  174. static struct bin_attribute sysfs_nvram_attr = {
  175. .attr = {
  176. .name = "nvram",
  177. .mode = S_IRUSR | S_IWUSR,
  178. },
  179. .size = 512,
  180. .read = qla2x00_sysfs_read_nvram,
  181. .write = qla2x00_sysfs_write_nvram,
  182. };
  183. static ssize_t
  184. qla2x00_sysfs_read_optrom(struct file *filp, struct kobject *kobj,
  185. struct bin_attribute *bin_attr,
  186. char *buf, loff_t off, size_t count)
  187. {
  188. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  189. struct device, kobj)));
  190. struct qla_hw_data *ha = vha->hw;
  191. if (ha->optrom_state != QLA_SREADING)
  192. return 0;
  193. return memory_read_from_buffer(buf, count, &off, ha->optrom_buffer,
  194. ha->optrom_region_size);
  195. }
  196. static ssize_t
  197. qla2x00_sysfs_write_optrom(struct file *filp, struct kobject *kobj,
  198. struct bin_attribute *bin_attr,
  199. char *buf, loff_t off, size_t count)
  200. {
  201. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  202. struct device, kobj)));
  203. struct qla_hw_data *ha = vha->hw;
  204. if (ha->optrom_state != QLA_SWRITING)
  205. return -EINVAL;
  206. if (off > ha->optrom_region_size)
  207. return -ERANGE;
  208. if (off + count > ha->optrom_region_size)
  209. count = ha->optrom_region_size - off;
  210. memcpy(&ha->optrom_buffer[off], buf, count);
  211. return count;
  212. }
  213. static struct bin_attribute sysfs_optrom_attr = {
  214. .attr = {
  215. .name = "optrom",
  216. .mode = S_IRUSR | S_IWUSR,
  217. },
  218. .size = 0,
  219. .read = qla2x00_sysfs_read_optrom,
  220. .write = qla2x00_sysfs_write_optrom,
  221. };
  222. static ssize_t
  223. qla2x00_sysfs_write_optrom_ctl(struct file *filp, struct kobject *kobj,
  224. struct bin_attribute *bin_attr,
  225. char *buf, loff_t off, size_t count)
  226. {
  227. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  228. struct device, kobj)));
  229. struct qla_hw_data *ha = vha->hw;
  230. uint32_t start = 0;
  231. uint32_t size = ha->optrom_size;
  232. int val, valid;
  233. if (off)
  234. return 0;
  235. if (unlikely(pci_channel_offline(ha->pdev)))
  236. return 0;
  237. if (sscanf(buf, "%d:%x:%x", &val, &start, &size) < 1)
  238. return -EINVAL;
  239. if (start > ha->optrom_size)
  240. return -EINVAL;
  241. switch (val) {
  242. case 0:
  243. if (ha->optrom_state != QLA_SREADING &&
  244. ha->optrom_state != QLA_SWRITING)
  245. break;
  246. ha->optrom_state = QLA_SWAITING;
  247. ql_dbg(ql_dbg_user, vha, 0x7061,
  248. "Freeing flash region allocation -- 0x%x bytes.\n",
  249. ha->optrom_region_size);
  250. vfree(ha->optrom_buffer);
  251. ha->optrom_buffer = NULL;
  252. break;
  253. case 1:
  254. if (ha->optrom_state != QLA_SWAITING)
  255. break;
  256. ha->optrom_region_start = start;
  257. ha->optrom_region_size = start + size > ha->optrom_size ?
  258. ha->optrom_size - start : size;
  259. ha->optrom_state = QLA_SREADING;
  260. ha->optrom_buffer = vmalloc(ha->optrom_region_size);
  261. if (ha->optrom_buffer == NULL) {
  262. ql_log(ql_log_warn, vha, 0x7062,
  263. "Unable to allocate memory for optrom retrieval "
  264. "(%x).\n", ha->optrom_region_size);
  265. ha->optrom_state = QLA_SWAITING;
  266. return count;
  267. }
  268. if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
  269. ql_log(ql_log_warn, vha, 0x7063,
  270. "HBA not online, failing NVRAM update.\n");
  271. return -EAGAIN;
  272. }
  273. ql_dbg(ql_dbg_user, vha, 0x7064,
  274. "Reading flash region -- 0x%x/0x%x.\n",
  275. ha->optrom_region_start, ha->optrom_region_size);
  276. memset(ha->optrom_buffer, 0, ha->optrom_region_size);
  277. ha->isp_ops->read_optrom(vha, ha->optrom_buffer,
  278. ha->optrom_region_start, ha->optrom_region_size);
  279. break;
  280. case 2:
  281. if (ha->optrom_state != QLA_SWAITING)
  282. break;
  283. /*
  284. * We need to be more restrictive on which FLASH regions are
  285. * allowed to be updated via user-space. Regions accessible
  286. * via this method include:
  287. *
  288. * ISP21xx/ISP22xx/ISP23xx type boards:
  289. *
  290. * 0x000000 -> 0x020000 -- Boot code.
  291. *
  292. * ISP2322/ISP24xx type boards:
  293. *
  294. * 0x000000 -> 0x07ffff -- Boot code.
  295. * 0x080000 -> 0x0fffff -- Firmware.
  296. *
  297. * ISP25xx type boards:
  298. *
  299. * 0x000000 -> 0x07ffff -- Boot code.
  300. * 0x080000 -> 0x0fffff -- Firmware.
  301. * 0x120000 -> 0x12ffff -- VPD and HBA parameters.
  302. */
  303. valid = 0;
  304. if (ha->optrom_size == OPTROM_SIZE_2300 && start == 0)
  305. valid = 1;
  306. else if (start == (ha->flt_region_boot * 4) ||
  307. start == (ha->flt_region_fw * 4))
  308. valid = 1;
  309. else if (IS_QLA25XX(ha) || IS_QLA8XXX_TYPE(ha))
  310. valid = 1;
  311. if (!valid) {
  312. ql_log(ql_log_warn, vha, 0x7065,
  313. "Invalid start region 0x%x/0x%x.\n", start, size);
  314. return -EINVAL;
  315. }
  316. ha->optrom_region_start = start;
  317. ha->optrom_region_size = start + size > ha->optrom_size ?
  318. ha->optrom_size - start : size;
  319. ha->optrom_state = QLA_SWRITING;
  320. ha->optrom_buffer = vmalloc(ha->optrom_region_size);
  321. if (ha->optrom_buffer == NULL) {
  322. ql_log(ql_log_warn, vha, 0x7066,
  323. "Unable to allocate memory for optrom update "
  324. "(%x)\n", ha->optrom_region_size);
  325. ha->optrom_state = QLA_SWAITING;
  326. return count;
  327. }
  328. ql_dbg(ql_dbg_user, vha, 0x7067,
  329. "Staging flash region write -- 0x%x/0x%x.\n",
  330. ha->optrom_region_start, ha->optrom_region_size);
  331. memset(ha->optrom_buffer, 0, ha->optrom_region_size);
  332. break;
  333. case 3:
  334. if (ha->optrom_state != QLA_SWRITING)
  335. break;
  336. if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
  337. ql_log(ql_log_warn, vha, 0x7068,
  338. "HBA not online, failing flash update.\n");
  339. return -EAGAIN;
  340. }
  341. ql_dbg(ql_dbg_user, vha, 0x7069,
  342. "Writing flash region -- 0x%x/0x%x.\n",
  343. ha->optrom_region_start, ha->optrom_region_size);
  344. ha->isp_ops->write_optrom(vha, ha->optrom_buffer,
  345. ha->optrom_region_start, ha->optrom_region_size);
  346. break;
  347. default:
  348. count = -EINVAL;
  349. }
  350. return count;
  351. }
  352. static struct bin_attribute sysfs_optrom_ctl_attr = {
  353. .attr = {
  354. .name = "optrom_ctl",
  355. .mode = S_IWUSR,
  356. },
  357. .size = 0,
  358. .write = qla2x00_sysfs_write_optrom_ctl,
  359. };
  360. static ssize_t
  361. qla2x00_sysfs_read_vpd(struct file *filp, struct kobject *kobj,
  362. struct bin_attribute *bin_attr,
  363. char *buf, loff_t off, size_t count)
  364. {
  365. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  366. struct device, kobj)));
  367. struct qla_hw_data *ha = vha->hw;
  368. if (unlikely(pci_channel_offline(ha->pdev)))
  369. return 0;
  370. if (!capable(CAP_SYS_ADMIN))
  371. return 0;
  372. if (IS_NOCACHE_VPD_TYPE(ha))
  373. ha->isp_ops->read_optrom(vha, ha->vpd, ha->flt_region_vpd << 2,
  374. ha->vpd_size);
  375. return memory_read_from_buffer(buf, count, &off, ha->vpd, ha->vpd_size);
  376. }
  377. static ssize_t
  378. qla2x00_sysfs_write_vpd(struct file *filp, struct kobject *kobj,
  379. struct bin_attribute *bin_attr,
  380. char *buf, loff_t off, size_t count)
  381. {
  382. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  383. struct device, kobj)));
  384. struct qla_hw_data *ha = vha->hw;
  385. uint8_t *tmp_data;
  386. if (unlikely(pci_channel_offline(ha->pdev)))
  387. return 0;
  388. if (!capable(CAP_SYS_ADMIN) || off != 0 || count != ha->vpd_size ||
  389. !ha->isp_ops->write_nvram)
  390. return 0;
  391. if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
  392. ql_log(ql_log_warn, vha, 0x706a,
  393. "HBA not online, failing VPD update.\n");
  394. return -EAGAIN;
  395. }
  396. /* Write NVRAM. */
  397. ha->isp_ops->write_nvram(vha, (uint8_t *)buf, ha->vpd_base, count);
  398. ha->isp_ops->read_nvram(vha, (uint8_t *)ha->vpd, ha->vpd_base, count);
  399. /* Update flash version information for 4Gb & above. */
  400. if (!IS_FWI2_CAPABLE(ha))
  401. goto done;
  402. tmp_data = vmalloc(256);
  403. if (!tmp_data) {
  404. ql_log(ql_log_warn, vha, 0x706b,
  405. "Unable to allocate memory for VPD information update.\n");
  406. goto done;
  407. }
  408. ha->isp_ops->get_flash_version(vha, tmp_data);
  409. vfree(tmp_data);
  410. done:
  411. return count;
  412. }
  413. static struct bin_attribute sysfs_vpd_attr = {
  414. .attr = {
  415. .name = "vpd",
  416. .mode = S_IRUSR | S_IWUSR,
  417. },
  418. .size = 0,
  419. .read = qla2x00_sysfs_read_vpd,
  420. .write = qla2x00_sysfs_write_vpd,
  421. };
  422. static ssize_t
  423. qla2x00_sysfs_read_sfp(struct file *filp, struct kobject *kobj,
  424. struct bin_attribute *bin_attr,
  425. char *buf, loff_t off, size_t count)
  426. {
  427. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  428. struct device, kobj)));
  429. struct qla_hw_data *ha = vha->hw;
  430. uint16_t iter, addr, offset;
  431. int rval;
  432. if (!capable(CAP_SYS_ADMIN) || off != 0 || count != SFP_DEV_SIZE * 2)
  433. return 0;
  434. if (ha->sfp_data)
  435. goto do_read;
  436. ha->sfp_data = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
  437. &ha->sfp_data_dma);
  438. if (!ha->sfp_data) {
  439. ql_log(ql_log_warn, vha, 0x706c,
  440. "Unable to allocate memory for SFP read-data.\n");
  441. return 0;
  442. }
  443. do_read:
  444. memset(ha->sfp_data, 0, SFP_BLOCK_SIZE);
  445. addr = 0xa0;
  446. for (iter = 0, offset = 0; iter < (SFP_DEV_SIZE * 2) / SFP_BLOCK_SIZE;
  447. iter++, offset += SFP_BLOCK_SIZE) {
  448. if (iter == 4) {
  449. /* Skip to next device address. */
  450. addr = 0xa2;
  451. offset = 0;
  452. }
  453. rval = qla2x00_read_sfp(vha, ha->sfp_data_dma, ha->sfp_data,
  454. addr, offset, SFP_BLOCK_SIZE, 0);
  455. if (rval != QLA_SUCCESS) {
  456. ql_log(ql_log_warn, vha, 0x706d,
  457. "Unable to read SFP data (%x/%x/%x).\n", rval,
  458. addr, offset);
  459. count = 0;
  460. break;
  461. }
  462. memcpy(buf, ha->sfp_data, SFP_BLOCK_SIZE);
  463. buf += SFP_BLOCK_SIZE;
  464. }
  465. return count;
  466. }
  467. static struct bin_attribute sysfs_sfp_attr = {
  468. .attr = {
  469. .name = "sfp",
  470. .mode = S_IRUSR | S_IWUSR,
  471. },
  472. .size = SFP_DEV_SIZE * 2,
  473. .read = qla2x00_sysfs_read_sfp,
  474. };
  475. static ssize_t
  476. qla2x00_sysfs_write_reset(struct file *filp, struct kobject *kobj,
  477. struct bin_attribute *bin_attr,
  478. char *buf, loff_t off, size_t count)
  479. {
  480. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  481. struct device, kobj)));
  482. struct qla_hw_data *ha = vha->hw;
  483. struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
  484. int type;
  485. if (off != 0)
  486. return 0;
  487. type = simple_strtol(buf, NULL, 10);
  488. switch (type) {
  489. case 0x2025c:
  490. ql_log(ql_log_info, vha, 0x706e,
  491. "Issuing ISP reset.\n");
  492. scsi_block_requests(vha->host);
  493. set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
  494. if (IS_QLA82XX(ha)) {
  495. qla82xx_idc_lock(ha);
  496. qla82xx_set_reset_owner(vha);
  497. qla82xx_idc_unlock(ha);
  498. }
  499. qla2xxx_wake_dpc(vha);
  500. qla2x00_wait_for_chip_reset(vha);
  501. scsi_unblock_requests(vha->host);
  502. break;
  503. case 0x2025d:
  504. if (!IS_QLA81XX(ha))
  505. break;
  506. ql_log(ql_log_info, vha, 0x706f,
  507. "Issuing MPI reset.\n");
  508. /* Make sure FC side is not in reset */
  509. qla2x00_wait_for_hba_online(vha);
  510. /* Issue MPI reset */
  511. scsi_block_requests(vha->host);
  512. if (qla81xx_restart_mpi_firmware(vha) != QLA_SUCCESS)
  513. ql_log(ql_log_warn, vha, 0x7070,
  514. "MPI reset failed.\n");
  515. scsi_unblock_requests(vha->host);
  516. break;
  517. case 0x2025e:
  518. if (!IS_QLA82XX(ha) || vha != base_vha) {
  519. ql_log(ql_log_info, vha, 0x7071,
  520. "FCoE ctx reset no supported.\n");
  521. return count;
  522. }
  523. ql_log(ql_log_info, vha, 0x7072,
  524. "Issuing FCoE ctx reset.\n");
  525. set_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags);
  526. qla2xxx_wake_dpc(vha);
  527. qla2x00_wait_for_fcoe_ctx_reset(vha);
  528. break;
  529. }
  530. return count;
  531. }
  532. static struct bin_attribute sysfs_reset_attr = {
  533. .attr = {
  534. .name = "reset",
  535. .mode = S_IWUSR,
  536. },
  537. .size = 0,
  538. .write = qla2x00_sysfs_write_reset,
  539. };
  540. static ssize_t
  541. qla2x00_sysfs_write_edc(struct file *filp, struct kobject *kobj,
  542. struct bin_attribute *bin_attr,
  543. char *buf, loff_t off, size_t count)
  544. {
  545. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  546. struct device, kobj)));
  547. struct qla_hw_data *ha = vha->hw;
  548. uint16_t dev, adr, opt, len;
  549. int rval;
  550. ha->edc_data_len = 0;
  551. if (!capable(CAP_SYS_ADMIN) || off != 0 || count < 8)
  552. return 0;
  553. if (!ha->edc_data) {
  554. ha->edc_data = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
  555. &ha->edc_data_dma);
  556. if (!ha->edc_data) {
  557. ql_log(ql_log_warn, vha, 0x7073,
  558. "Unable to allocate memory for EDC write.\n");
  559. return 0;
  560. }
  561. }
  562. dev = le16_to_cpup((void *)&buf[0]);
  563. adr = le16_to_cpup((void *)&buf[2]);
  564. opt = le16_to_cpup((void *)&buf[4]);
  565. len = le16_to_cpup((void *)&buf[6]);
  566. if (!(opt & BIT_0))
  567. if (len == 0 || len > DMA_POOL_SIZE || len > count - 8)
  568. return -EINVAL;
  569. memcpy(ha->edc_data, &buf[8], len);
  570. rval = qla2x00_write_sfp(vha, ha->edc_data_dma, ha->edc_data,
  571. dev, adr, len, opt);
  572. if (rval != QLA_SUCCESS) {
  573. ql_log(ql_log_warn, vha, 0x7074,
  574. "Unable to write EDC (%x) %02x:%04x:%02x:%02x\n",
  575. rval, dev, adr, opt, len, buf[8]);
  576. return 0;
  577. }
  578. return count;
  579. }
  580. static struct bin_attribute sysfs_edc_attr = {
  581. .attr = {
  582. .name = "edc",
  583. .mode = S_IWUSR,
  584. },
  585. .size = 0,
  586. .write = qla2x00_sysfs_write_edc,
  587. };
  588. static ssize_t
  589. qla2x00_sysfs_write_edc_status(struct file *filp, struct kobject *kobj,
  590. struct bin_attribute *bin_attr,
  591. char *buf, loff_t off, size_t count)
  592. {
  593. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  594. struct device, kobj)));
  595. struct qla_hw_data *ha = vha->hw;
  596. uint16_t dev, adr, opt, len;
  597. int rval;
  598. ha->edc_data_len = 0;
  599. if (!capable(CAP_SYS_ADMIN) || off != 0 || count < 8)
  600. return 0;
  601. if (!ha->edc_data) {
  602. ha->edc_data = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
  603. &ha->edc_data_dma);
  604. if (!ha->edc_data) {
  605. ql_log(ql_log_warn, vha, 0x708c,
  606. "Unable to allocate memory for EDC status.\n");
  607. return 0;
  608. }
  609. }
  610. dev = le16_to_cpup((void *)&buf[0]);
  611. adr = le16_to_cpup((void *)&buf[2]);
  612. opt = le16_to_cpup((void *)&buf[4]);
  613. len = le16_to_cpup((void *)&buf[6]);
  614. if (!(opt & BIT_0))
  615. if (len == 0 || len > DMA_POOL_SIZE)
  616. return -EINVAL;
  617. memset(ha->edc_data, 0, len);
  618. rval = qla2x00_read_sfp(vha, ha->edc_data_dma, ha->edc_data,
  619. dev, adr, len, opt);
  620. if (rval != QLA_SUCCESS) {
  621. ql_log(ql_log_info, vha, 0x7075,
  622. "Unable to write EDC status (%x) %02x:%04x:%02x.\n",
  623. rval, dev, adr, opt, len);
  624. return 0;
  625. }
  626. ha->edc_data_len = len;
  627. return count;
  628. }
  629. static ssize_t
  630. qla2x00_sysfs_read_edc_status(struct file *filp, struct kobject *kobj,
  631. struct bin_attribute *bin_attr,
  632. char *buf, loff_t off, size_t count)
  633. {
  634. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  635. struct device, kobj)));
  636. struct qla_hw_data *ha = vha->hw;
  637. if (!capable(CAP_SYS_ADMIN) || off != 0 || count == 0)
  638. return 0;
  639. if (!ha->edc_data || ha->edc_data_len == 0 || ha->edc_data_len > count)
  640. return -EINVAL;
  641. memcpy(buf, ha->edc_data, ha->edc_data_len);
  642. return ha->edc_data_len;
  643. }
  644. static struct bin_attribute sysfs_edc_status_attr = {
  645. .attr = {
  646. .name = "edc_status",
  647. .mode = S_IRUSR | S_IWUSR,
  648. },
  649. .size = 0,
  650. .write = qla2x00_sysfs_write_edc_status,
  651. .read = qla2x00_sysfs_read_edc_status,
  652. };
  653. static ssize_t
  654. qla2x00_sysfs_read_xgmac_stats(struct file *filp, struct kobject *kobj,
  655. struct bin_attribute *bin_attr,
  656. char *buf, loff_t off, size_t count)
  657. {
  658. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  659. struct device, kobj)));
  660. struct qla_hw_data *ha = vha->hw;
  661. int rval;
  662. uint16_t actual_size;
  663. if (!capable(CAP_SYS_ADMIN) || off != 0 || count > XGMAC_DATA_SIZE)
  664. return 0;
  665. if (ha->xgmac_data)
  666. goto do_read;
  667. ha->xgmac_data = dma_alloc_coherent(&ha->pdev->dev, XGMAC_DATA_SIZE,
  668. &ha->xgmac_data_dma, GFP_KERNEL);
  669. if (!ha->xgmac_data) {
  670. ql_log(ql_log_warn, vha, 0x7076,
  671. "Unable to allocate memory for XGMAC read-data.\n");
  672. return 0;
  673. }
  674. do_read:
  675. actual_size = 0;
  676. memset(ha->xgmac_data, 0, XGMAC_DATA_SIZE);
  677. rval = qla2x00_get_xgmac_stats(vha, ha->xgmac_data_dma,
  678. XGMAC_DATA_SIZE, &actual_size);
  679. if (rval != QLA_SUCCESS) {
  680. ql_log(ql_log_warn, vha, 0x7077,
  681. "Unable to read XGMAC data (%x).\n", rval);
  682. count = 0;
  683. }
  684. count = actual_size > count ? count: actual_size;
  685. memcpy(buf, ha->xgmac_data, count);
  686. return count;
  687. }
  688. static struct bin_attribute sysfs_xgmac_stats_attr = {
  689. .attr = {
  690. .name = "xgmac_stats",
  691. .mode = S_IRUSR,
  692. },
  693. .size = 0,
  694. .read = qla2x00_sysfs_read_xgmac_stats,
  695. };
  696. static ssize_t
  697. qla2x00_sysfs_read_dcbx_tlv(struct file *filp, struct kobject *kobj,
  698. struct bin_attribute *bin_attr,
  699. char *buf, loff_t off, size_t count)
  700. {
  701. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  702. struct device, kobj)));
  703. struct qla_hw_data *ha = vha->hw;
  704. int rval;
  705. uint16_t actual_size;
  706. if (!capable(CAP_SYS_ADMIN) || off != 0 || count > DCBX_TLV_DATA_SIZE)
  707. return 0;
  708. if (ha->dcbx_tlv)
  709. goto do_read;
  710. ha->dcbx_tlv = dma_alloc_coherent(&ha->pdev->dev, DCBX_TLV_DATA_SIZE,
  711. &ha->dcbx_tlv_dma, GFP_KERNEL);
  712. if (!ha->dcbx_tlv) {
  713. ql_log(ql_log_warn, vha, 0x7078,
  714. "Unable to allocate memory for DCBX TLV read-data.\n");
  715. return 0;
  716. }
  717. do_read:
  718. actual_size = 0;
  719. memset(ha->dcbx_tlv, 0, DCBX_TLV_DATA_SIZE);
  720. rval = qla2x00_get_dcbx_params(vha, ha->dcbx_tlv_dma,
  721. DCBX_TLV_DATA_SIZE);
  722. if (rval != QLA_SUCCESS) {
  723. ql_log(ql_log_warn, vha, 0x7079,
  724. "Unable to read DCBX TLV (%x).\n", rval);
  725. count = 0;
  726. }
  727. memcpy(buf, ha->dcbx_tlv, count);
  728. return count;
  729. }
  730. static struct bin_attribute sysfs_dcbx_tlv_attr = {
  731. .attr = {
  732. .name = "dcbx_tlv",
  733. .mode = S_IRUSR,
  734. },
  735. .size = 0,
  736. .read = qla2x00_sysfs_read_dcbx_tlv,
  737. };
  738. static struct sysfs_entry {
  739. char *name;
  740. struct bin_attribute *attr;
  741. int is4GBp_only;
  742. } bin_file_entries[] = {
  743. { "fw_dump", &sysfs_fw_dump_attr, },
  744. { "nvram", &sysfs_nvram_attr, },
  745. { "optrom", &sysfs_optrom_attr, },
  746. { "optrom_ctl", &sysfs_optrom_ctl_attr, },
  747. { "vpd", &sysfs_vpd_attr, 1 },
  748. { "sfp", &sysfs_sfp_attr, 1 },
  749. { "reset", &sysfs_reset_attr, },
  750. { "edc", &sysfs_edc_attr, 2 },
  751. { "edc_status", &sysfs_edc_status_attr, 2 },
  752. { "xgmac_stats", &sysfs_xgmac_stats_attr, 3 },
  753. { "dcbx_tlv", &sysfs_dcbx_tlv_attr, 3 },
  754. { NULL },
  755. };
  756. void
  757. qla2x00_alloc_sysfs_attr(scsi_qla_host_t *vha)
  758. {
  759. struct Scsi_Host *host = vha->host;
  760. struct sysfs_entry *iter;
  761. int ret;
  762. for (iter = bin_file_entries; iter->name; iter++) {
  763. if (iter->is4GBp_only && !IS_FWI2_CAPABLE(vha->hw))
  764. continue;
  765. if (iter->is4GBp_only == 2 && !IS_QLA25XX(vha->hw))
  766. continue;
  767. if (iter->is4GBp_only == 3 && !(IS_QLA8XXX_TYPE(vha->hw)))
  768. continue;
  769. ret = sysfs_create_bin_file(&host->shost_gendev.kobj,
  770. iter->attr);
  771. if (ret)
  772. ql_log(ql_log_warn, vha, 0x00f3,
  773. "Unable to create sysfs %s binary attribute (%d).\n",
  774. iter->name, ret);
  775. else
  776. ql_dbg(ql_dbg_init, vha, 0x00f4,
  777. "Successfully created sysfs %s binary attribure.\n",
  778. iter->name);
  779. }
  780. }
  781. void
  782. qla2x00_free_sysfs_attr(scsi_qla_host_t *vha)
  783. {
  784. struct Scsi_Host *host = vha->host;
  785. struct sysfs_entry *iter;
  786. struct qla_hw_data *ha = vha->hw;
  787. for (iter = bin_file_entries; iter->name; iter++) {
  788. if (iter->is4GBp_only && !IS_FWI2_CAPABLE(ha))
  789. continue;
  790. if (iter->is4GBp_only == 2 && !IS_QLA25XX(ha))
  791. continue;
  792. if (iter->is4GBp_only == 3 && !!(IS_QLA8XXX_TYPE(vha->hw)))
  793. continue;
  794. sysfs_remove_bin_file(&host->shost_gendev.kobj,
  795. iter->attr);
  796. }
  797. if (ha->beacon_blink_led == 1)
  798. ha->isp_ops->beacon_off(vha);
  799. }
  800. /* Scsi_Host attributes. */
  801. static ssize_t
  802. qla2x00_drvr_version_show(struct device *dev,
  803. struct device_attribute *attr, char *buf)
  804. {
  805. return snprintf(buf, PAGE_SIZE, "%s\n", qla2x00_version_str);
  806. }
  807. static ssize_t
  808. qla2x00_fw_version_show(struct device *dev,
  809. struct device_attribute *attr, char *buf)
  810. {
  811. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  812. struct qla_hw_data *ha = vha->hw;
  813. char fw_str[128];
  814. return snprintf(buf, PAGE_SIZE, "%s\n",
  815. ha->isp_ops->fw_version_str(vha, fw_str));
  816. }
  817. static ssize_t
  818. qla2x00_serial_num_show(struct device *dev, struct device_attribute *attr,
  819. char *buf)
  820. {
  821. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  822. struct qla_hw_data *ha = vha->hw;
  823. uint32_t sn;
  824. if (IS_FWI2_CAPABLE(ha)) {
  825. qla2xxx_get_vpd_field(vha, "SN", buf, PAGE_SIZE);
  826. return snprintf(buf, PAGE_SIZE, "%s\n", buf);
  827. }
  828. sn = ((ha->serial0 & 0x1f) << 16) | (ha->serial2 << 8) | ha->serial1;
  829. return snprintf(buf, PAGE_SIZE, "%c%05d\n", 'A' + sn / 100000,
  830. sn % 100000);
  831. }
  832. static ssize_t
  833. qla2x00_isp_name_show(struct device *dev, struct device_attribute *attr,
  834. char *buf)
  835. {
  836. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  837. return snprintf(buf, PAGE_SIZE, "ISP%04X\n", vha->hw->pdev->device);
  838. }
  839. static ssize_t
  840. qla2x00_isp_id_show(struct device *dev, struct device_attribute *attr,
  841. char *buf)
  842. {
  843. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  844. struct qla_hw_data *ha = vha->hw;
  845. return snprintf(buf, PAGE_SIZE, "%04x %04x %04x %04x\n",
  846. ha->product_id[0], ha->product_id[1], ha->product_id[2],
  847. ha->product_id[3]);
  848. }
  849. static ssize_t
  850. qla2x00_model_name_show(struct device *dev, struct device_attribute *attr,
  851. char *buf)
  852. {
  853. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  854. return snprintf(buf, PAGE_SIZE, "%s\n", vha->hw->model_number);
  855. }
  856. static ssize_t
  857. qla2x00_model_desc_show(struct device *dev, struct device_attribute *attr,
  858. char *buf)
  859. {
  860. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  861. return snprintf(buf, PAGE_SIZE, "%s\n",
  862. vha->hw->model_desc ? vha->hw->model_desc : "");
  863. }
  864. static ssize_t
  865. qla2x00_pci_info_show(struct device *dev, struct device_attribute *attr,
  866. char *buf)
  867. {
  868. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  869. char pci_info[30];
  870. return snprintf(buf, PAGE_SIZE, "%s\n",
  871. vha->hw->isp_ops->pci_info_str(vha, pci_info));
  872. }
  873. static ssize_t
  874. qla2x00_link_state_show(struct device *dev, struct device_attribute *attr,
  875. char *buf)
  876. {
  877. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  878. struct qla_hw_data *ha = vha->hw;
  879. int len = 0;
  880. if (atomic_read(&vha->loop_state) == LOOP_DOWN ||
  881. atomic_read(&vha->loop_state) == LOOP_DEAD ||
  882. vha->device_flags & DFLG_NO_CABLE)
  883. len = snprintf(buf, PAGE_SIZE, "Link Down\n");
  884. else if (atomic_read(&vha->loop_state) != LOOP_READY ||
  885. test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags) ||
  886. test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
  887. len = snprintf(buf, PAGE_SIZE, "Unknown Link State\n");
  888. else {
  889. len = snprintf(buf, PAGE_SIZE, "Link Up - ");
  890. switch (ha->current_topology) {
  891. case ISP_CFG_NL:
  892. len += snprintf(buf + len, PAGE_SIZE-len, "Loop\n");
  893. break;
  894. case ISP_CFG_FL:
  895. len += snprintf(buf + len, PAGE_SIZE-len, "FL_Port\n");
  896. break;
  897. case ISP_CFG_N:
  898. len += snprintf(buf + len, PAGE_SIZE-len,
  899. "N_Port to N_Port\n");
  900. break;
  901. case ISP_CFG_F:
  902. len += snprintf(buf + len, PAGE_SIZE-len, "F_Port\n");
  903. break;
  904. default:
  905. len += snprintf(buf + len, PAGE_SIZE-len, "Loop\n");
  906. break;
  907. }
  908. }
  909. return len;
  910. }
  911. static ssize_t
  912. qla2x00_zio_show(struct device *dev, struct device_attribute *attr,
  913. char *buf)
  914. {
  915. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  916. int len = 0;
  917. switch (vha->hw->zio_mode) {
  918. case QLA_ZIO_MODE_6:
  919. len += snprintf(buf + len, PAGE_SIZE-len, "Mode 6\n");
  920. break;
  921. case QLA_ZIO_DISABLED:
  922. len += snprintf(buf + len, PAGE_SIZE-len, "Disabled\n");
  923. break;
  924. }
  925. return len;
  926. }
  927. static ssize_t
  928. qla2x00_zio_store(struct device *dev, struct device_attribute *attr,
  929. const char *buf, size_t count)
  930. {
  931. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  932. struct qla_hw_data *ha = vha->hw;
  933. int val = 0;
  934. uint16_t zio_mode;
  935. if (!IS_ZIO_SUPPORTED(ha))
  936. return -ENOTSUPP;
  937. if (sscanf(buf, "%d", &val) != 1)
  938. return -EINVAL;
  939. if (val)
  940. zio_mode = QLA_ZIO_MODE_6;
  941. else
  942. zio_mode = QLA_ZIO_DISABLED;
  943. /* Update per-hba values and queue a reset. */
  944. if (zio_mode != QLA_ZIO_DISABLED || ha->zio_mode != QLA_ZIO_DISABLED) {
  945. ha->zio_mode = zio_mode;
  946. set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
  947. }
  948. return strlen(buf);
  949. }
  950. static ssize_t
  951. qla2x00_zio_timer_show(struct device *dev, struct device_attribute *attr,
  952. char *buf)
  953. {
  954. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  955. return snprintf(buf, PAGE_SIZE, "%d us\n", vha->hw->zio_timer * 100);
  956. }
  957. static ssize_t
  958. qla2x00_zio_timer_store(struct device *dev, struct device_attribute *attr,
  959. const char *buf, size_t count)
  960. {
  961. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  962. int val = 0;
  963. uint16_t zio_timer;
  964. if (sscanf(buf, "%d", &val) != 1)
  965. return -EINVAL;
  966. if (val > 25500 || val < 100)
  967. return -ERANGE;
  968. zio_timer = (uint16_t)(val / 100);
  969. vha->hw->zio_timer = zio_timer;
  970. return strlen(buf);
  971. }
  972. static ssize_t
  973. qla2x00_beacon_show(struct device *dev, struct device_attribute *attr,
  974. char *buf)
  975. {
  976. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  977. int len = 0;
  978. if (vha->hw->beacon_blink_led)
  979. len += snprintf(buf + len, PAGE_SIZE-len, "Enabled\n");
  980. else
  981. len += snprintf(buf + len, PAGE_SIZE-len, "Disabled\n");
  982. return len;
  983. }
  984. static ssize_t
  985. qla2x00_beacon_store(struct device *dev, struct device_attribute *attr,
  986. const char *buf, size_t count)
  987. {
  988. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  989. struct qla_hw_data *ha = vha->hw;
  990. int val = 0;
  991. int rval;
  992. if (IS_QLA2100(ha) || IS_QLA2200(ha))
  993. return -EPERM;
  994. if (test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags)) {
  995. ql_log(ql_log_warn, vha, 0x707a,
  996. "Abort ISP active -- ignoring beacon request.\n");
  997. return -EBUSY;
  998. }
  999. if (sscanf(buf, "%d", &val) != 1)
  1000. return -EINVAL;
  1001. if (val)
  1002. rval = ha->isp_ops->beacon_on(vha);
  1003. else
  1004. rval = ha->isp_ops->beacon_off(vha);
  1005. if (rval != QLA_SUCCESS)
  1006. count = 0;
  1007. return count;
  1008. }
  1009. static ssize_t
  1010. qla2x00_optrom_bios_version_show(struct device *dev,
  1011. struct device_attribute *attr, char *buf)
  1012. {
  1013. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  1014. struct qla_hw_data *ha = vha->hw;
  1015. return snprintf(buf, PAGE_SIZE, "%d.%02d\n", ha->bios_revision[1],
  1016. ha->bios_revision[0]);
  1017. }
  1018. static ssize_t
  1019. qla2x00_optrom_efi_version_show(struct device *dev,
  1020. struct device_attribute *attr, char *buf)
  1021. {
  1022. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  1023. struct qla_hw_data *ha = vha->hw;
  1024. return snprintf(buf, PAGE_SIZE, "%d.%02d\n", ha->efi_revision[1],
  1025. ha->efi_revision[0]);
  1026. }
  1027. static ssize_t
  1028. qla2x00_optrom_fcode_version_show(struct device *dev,
  1029. struct device_attribute *attr, char *buf)
  1030. {
  1031. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  1032. struct qla_hw_data *ha = vha->hw;
  1033. return snprintf(buf, PAGE_SIZE, "%d.%02d\n", ha->fcode_revision[1],
  1034. ha->fcode_revision[0]);
  1035. }
  1036. static ssize_t
  1037. qla2x00_optrom_fw_version_show(struct device *dev,
  1038. struct device_attribute *attr, char *buf)
  1039. {
  1040. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  1041. struct qla_hw_data *ha = vha->hw;
  1042. return snprintf(buf, PAGE_SIZE, "%d.%02d.%02d %d\n",
  1043. ha->fw_revision[0], ha->fw_revision[1], ha->fw_revision[2],
  1044. ha->fw_revision[3]);
  1045. }
  1046. static ssize_t
  1047. qla2x00_optrom_gold_fw_version_show(struct device *dev,
  1048. struct device_attribute *attr, char *buf)
  1049. {
  1050. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  1051. struct qla_hw_data *ha = vha->hw;
  1052. if (!IS_QLA81XX(ha))
  1053. return snprintf(buf, PAGE_SIZE, "\n");
  1054. return snprintf(buf, PAGE_SIZE, "%d.%02d.%02d (%d)\n",
  1055. ha->gold_fw_version[0], ha->gold_fw_version[1],
  1056. ha->gold_fw_version[2], ha->gold_fw_version[3]);
  1057. }
  1058. static ssize_t
  1059. qla2x00_total_isp_aborts_show(struct device *dev,
  1060. struct device_attribute *attr, char *buf)
  1061. {
  1062. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  1063. struct qla_hw_data *ha = vha->hw;
  1064. return snprintf(buf, PAGE_SIZE, "%d\n",
  1065. ha->qla_stats.total_isp_aborts);
  1066. }
  1067. static ssize_t
  1068. qla24xx_84xx_fw_version_show(struct device *dev,
  1069. struct device_attribute *attr, char *buf)
  1070. {
  1071. int rval = QLA_SUCCESS;
  1072. uint16_t status[2] = {0, 0};
  1073. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  1074. struct qla_hw_data *ha = vha->hw;
  1075. if (!IS_QLA84XX(ha))
  1076. return snprintf(buf, PAGE_SIZE, "\n");
  1077. if (ha->cs84xx->op_fw_version == 0)
  1078. rval = qla84xx_verify_chip(vha, status);
  1079. if ((rval == QLA_SUCCESS) && (status[0] == 0))
  1080. return snprintf(buf, PAGE_SIZE, "%u\n",
  1081. (uint32_t)ha->cs84xx->op_fw_version);
  1082. return snprintf(buf, PAGE_SIZE, "\n");
  1083. }
  1084. static ssize_t
  1085. qla2x00_mpi_version_show(struct device *dev, struct device_attribute *attr,
  1086. char *buf)
  1087. {
  1088. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  1089. struct qla_hw_data *ha = vha->hw;
  1090. if (!IS_QLA81XX(ha))
  1091. return snprintf(buf, PAGE_SIZE, "\n");
  1092. return snprintf(buf, PAGE_SIZE, "%d.%02d.%02d (%x)\n",
  1093. ha->mpi_version[0], ha->mpi_version[1], ha->mpi_version[2],
  1094. ha->mpi_capabilities);
  1095. }
  1096. static ssize_t
  1097. qla2x00_phy_version_show(struct device *dev, struct device_attribute *attr,
  1098. char *buf)
  1099. {
  1100. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  1101. struct qla_hw_data *ha = vha->hw;
  1102. if (!IS_QLA81XX(ha))
  1103. return snprintf(buf, PAGE_SIZE, "\n");
  1104. return snprintf(buf, PAGE_SIZE, "%d.%02d.%02d\n",
  1105. ha->phy_version[0], ha->phy_version[1], ha->phy_version[2]);
  1106. }
  1107. static ssize_t
  1108. qla2x00_flash_block_size_show(struct device *dev,
  1109. struct device_attribute *attr, char *buf)
  1110. {
  1111. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  1112. struct qla_hw_data *ha = vha->hw;
  1113. return snprintf(buf, PAGE_SIZE, "0x%x\n", ha->fdt_block_size);
  1114. }
  1115. static ssize_t
  1116. qla2x00_vlan_id_show(struct device *dev, struct device_attribute *attr,
  1117. char *buf)
  1118. {
  1119. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  1120. if (!IS_QLA8XXX_TYPE(vha->hw))
  1121. return snprintf(buf, PAGE_SIZE, "\n");
  1122. return snprintf(buf, PAGE_SIZE, "%d\n", vha->fcoe_vlan_id);
  1123. }
  1124. static ssize_t
  1125. qla2x00_vn_port_mac_address_show(struct device *dev,
  1126. struct device_attribute *attr, char *buf)
  1127. {
  1128. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  1129. if (!IS_QLA8XXX_TYPE(vha->hw))
  1130. return snprintf(buf, PAGE_SIZE, "\n");
  1131. return snprintf(buf, PAGE_SIZE, "%02x:%02x:%02x:%02x:%02x:%02x\n",
  1132. vha->fcoe_vn_port_mac[5], vha->fcoe_vn_port_mac[4],
  1133. vha->fcoe_vn_port_mac[3], vha->fcoe_vn_port_mac[2],
  1134. vha->fcoe_vn_port_mac[1], vha->fcoe_vn_port_mac[0]);
  1135. }
  1136. static ssize_t
  1137. qla2x00_fabric_param_show(struct device *dev, struct device_attribute *attr,
  1138. char *buf)
  1139. {
  1140. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  1141. return snprintf(buf, PAGE_SIZE, "%d\n", vha->hw->switch_cap);
  1142. }
  1143. static ssize_t
  1144. qla2x00_thermal_temp_show(struct device *dev,
  1145. struct device_attribute *attr, char *buf)
  1146. {
  1147. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  1148. int rval = QLA_FUNCTION_FAILED;
  1149. uint16_t temp, frac;
  1150. if (!vha->hw->flags.thermal_supported)
  1151. return snprintf(buf, PAGE_SIZE, "\n");
  1152. temp = frac = 0;
  1153. if (test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags) ||
  1154. test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
  1155. ql_log(ql_log_warn, vha, 0x707b,
  1156. "ISP reset active.\n");
  1157. else if (!vha->hw->flags.eeh_busy)
  1158. rval = qla2x00_get_thermal_temp(vha, &temp, &frac);
  1159. if (rval != QLA_SUCCESS)
  1160. temp = frac = 0;
  1161. return snprintf(buf, PAGE_SIZE, "%d.%02d\n", temp, frac);
  1162. }
  1163. static ssize_t
  1164. qla2x00_fw_state_show(struct device *dev, struct device_attribute *attr,
  1165. char *buf)
  1166. {
  1167. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  1168. int rval = QLA_FUNCTION_FAILED;
  1169. uint16_t state[5];
  1170. if (test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags) ||
  1171. test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
  1172. ql_log(ql_log_warn, vha, 0x707c,
  1173. "ISP reset active.\n");
  1174. else if (!vha->hw->flags.eeh_busy)
  1175. rval = qla2x00_get_firmware_state(vha, state);
  1176. if (rval != QLA_SUCCESS)
  1177. memset(state, -1, sizeof(state));
  1178. return snprintf(buf, PAGE_SIZE, "0x%x 0x%x 0x%x 0x%x 0x%x\n", state[0],
  1179. state[1], state[2], state[3], state[4]);
  1180. }
  1181. static DEVICE_ATTR(driver_version, S_IRUGO, qla2x00_drvr_version_show, NULL);
  1182. static DEVICE_ATTR(fw_version, S_IRUGO, qla2x00_fw_version_show, NULL);
  1183. static DEVICE_ATTR(serial_num, S_IRUGO, qla2x00_serial_num_show, NULL);
  1184. static DEVICE_ATTR(isp_name, S_IRUGO, qla2x00_isp_name_show, NULL);
  1185. static DEVICE_ATTR(isp_id, S_IRUGO, qla2x00_isp_id_show, NULL);
  1186. static DEVICE_ATTR(model_name, S_IRUGO, qla2x00_model_name_show, NULL);
  1187. static DEVICE_ATTR(model_desc, S_IRUGO, qla2x00_model_desc_show, NULL);
  1188. static DEVICE_ATTR(pci_info, S_IRUGO, qla2x00_pci_info_show, NULL);
  1189. static DEVICE_ATTR(link_state, S_IRUGO, qla2x00_link_state_show, NULL);
  1190. static DEVICE_ATTR(zio, S_IRUGO | S_IWUSR, qla2x00_zio_show, qla2x00_zio_store);
  1191. static DEVICE_ATTR(zio_timer, S_IRUGO | S_IWUSR, qla2x00_zio_timer_show,
  1192. qla2x00_zio_timer_store);
  1193. static DEVICE_ATTR(beacon, S_IRUGO | S_IWUSR, qla2x00_beacon_show,
  1194. qla2x00_beacon_store);
  1195. static DEVICE_ATTR(optrom_bios_version, S_IRUGO,
  1196. qla2x00_optrom_bios_version_show, NULL);
  1197. static DEVICE_ATTR(optrom_efi_version, S_IRUGO,
  1198. qla2x00_optrom_efi_version_show, NULL);
  1199. static DEVICE_ATTR(optrom_fcode_version, S_IRUGO,
  1200. qla2x00_optrom_fcode_version_show, NULL);
  1201. static DEVICE_ATTR(optrom_fw_version, S_IRUGO, qla2x00_optrom_fw_version_show,
  1202. NULL);
  1203. static DEVICE_ATTR(optrom_gold_fw_version, S_IRUGO,
  1204. qla2x00_optrom_gold_fw_version_show, NULL);
  1205. static DEVICE_ATTR(84xx_fw_version, S_IRUGO, qla24xx_84xx_fw_version_show,
  1206. NULL);
  1207. static DEVICE_ATTR(total_isp_aborts, S_IRUGO, qla2x00_total_isp_aborts_show,
  1208. NULL);
  1209. static DEVICE_ATTR(mpi_version, S_IRUGO, qla2x00_mpi_version_show, NULL);
  1210. static DEVICE_ATTR(phy_version, S_IRUGO, qla2x00_phy_version_show, NULL);
  1211. static DEVICE_ATTR(flash_block_size, S_IRUGO, qla2x00_flash_block_size_show,
  1212. NULL);
  1213. static DEVICE_ATTR(vlan_id, S_IRUGO, qla2x00_vlan_id_show, NULL);
  1214. static DEVICE_ATTR(vn_port_mac_address, S_IRUGO,
  1215. qla2x00_vn_port_mac_address_show, NULL);
  1216. static DEVICE_ATTR(fabric_param, S_IRUGO, qla2x00_fabric_param_show, NULL);
  1217. static DEVICE_ATTR(fw_state, S_IRUGO, qla2x00_fw_state_show, NULL);
  1218. static DEVICE_ATTR(thermal_temp, S_IRUGO, qla2x00_thermal_temp_show, NULL);
  1219. struct device_attribute *qla2x00_host_attrs[] = {
  1220. &dev_attr_driver_version,
  1221. &dev_attr_fw_version,
  1222. &dev_attr_serial_num,
  1223. &dev_attr_isp_name,
  1224. &dev_attr_isp_id,
  1225. &dev_attr_model_name,
  1226. &dev_attr_model_desc,
  1227. &dev_attr_pci_info,
  1228. &dev_attr_link_state,
  1229. &dev_attr_zio,
  1230. &dev_attr_zio_timer,
  1231. &dev_attr_beacon,
  1232. &dev_attr_optrom_bios_version,
  1233. &dev_attr_optrom_efi_version,
  1234. &dev_attr_optrom_fcode_version,
  1235. &dev_attr_optrom_fw_version,
  1236. &dev_attr_84xx_fw_version,
  1237. &dev_attr_total_isp_aborts,
  1238. &dev_attr_mpi_version,
  1239. &dev_attr_phy_version,
  1240. &dev_attr_flash_block_size,
  1241. &dev_attr_vlan_id,
  1242. &dev_attr_vn_port_mac_address,
  1243. &dev_attr_fabric_param,
  1244. &dev_attr_fw_state,
  1245. &dev_attr_optrom_gold_fw_version,
  1246. &dev_attr_thermal_temp,
  1247. NULL,
  1248. };
  1249. /* Host attributes. */
  1250. static void
  1251. qla2x00_get_host_port_id(struct Scsi_Host *shost)
  1252. {
  1253. scsi_qla_host_t *vha = shost_priv(shost);
  1254. fc_host_port_id(shost) = vha->d_id.b.domain << 16 |
  1255. vha->d_id.b.area << 8 | vha->d_id.b.al_pa;
  1256. }
  1257. static void
  1258. qla2x00_get_host_speed(struct Scsi_Host *shost)
  1259. {
  1260. struct qla_hw_data *ha = ((struct scsi_qla_host *)
  1261. (shost_priv(shost)))->hw;
  1262. u32 speed = FC_PORTSPEED_UNKNOWN;
  1263. switch (ha->link_data_rate) {
  1264. case PORT_SPEED_1GB:
  1265. speed = FC_PORTSPEED_1GBIT;
  1266. break;
  1267. case PORT_SPEED_2GB:
  1268. speed = FC_PORTSPEED_2GBIT;
  1269. break;
  1270. case PORT_SPEED_4GB:
  1271. speed = FC_PORTSPEED_4GBIT;
  1272. break;
  1273. case PORT_SPEED_8GB:
  1274. speed = FC_PORTSPEED_8GBIT;
  1275. break;
  1276. case PORT_SPEED_10GB:
  1277. speed = FC_PORTSPEED_10GBIT;
  1278. break;
  1279. }
  1280. fc_host_speed(shost) = speed;
  1281. }
  1282. static void
  1283. qla2x00_get_host_port_type(struct Scsi_Host *shost)
  1284. {
  1285. scsi_qla_host_t *vha = shost_priv(shost);
  1286. uint32_t port_type = FC_PORTTYPE_UNKNOWN;
  1287. if (vha->vp_idx) {
  1288. fc_host_port_type(shost) = FC_PORTTYPE_NPIV;
  1289. return;
  1290. }
  1291. switch (vha->hw->current_topology) {
  1292. case ISP_CFG_NL:
  1293. port_type = FC_PORTTYPE_LPORT;
  1294. break;
  1295. case ISP_CFG_FL:
  1296. port_type = FC_PORTTYPE_NLPORT;
  1297. break;
  1298. case ISP_CFG_N:
  1299. port_type = FC_PORTTYPE_PTP;
  1300. break;
  1301. case ISP_CFG_F:
  1302. port_type = FC_PORTTYPE_NPORT;
  1303. break;
  1304. }
  1305. fc_host_port_type(shost) = port_type;
  1306. }
  1307. static void
  1308. qla2x00_get_starget_node_name(struct scsi_target *starget)
  1309. {
  1310. struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
  1311. scsi_qla_host_t *vha = shost_priv(host);
  1312. fc_port_t *fcport;
  1313. u64 node_name = 0;
  1314. list_for_each_entry(fcport, &vha->vp_fcports, list) {
  1315. if (fcport->rport &&
  1316. starget->id == fcport->rport->scsi_target_id) {
  1317. node_name = wwn_to_u64(fcport->node_name);
  1318. break;
  1319. }
  1320. }
  1321. fc_starget_node_name(starget) = node_name;
  1322. }
  1323. static void
  1324. qla2x00_get_starget_port_name(struct scsi_target *starget)
  1325. {
  1326. struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
  1327. scsi_qla_host_t *vha = shost_priv(host);
  1328. fc_port_t *fcport;
  1329. u64 port_name = 0;
  1330. list_for_each_entry(fcport, &vha->vp_fcports, list) {
  1331. if (fcport->rport &&
  1332. starget->id == fcport->rport->scsi_target_id) {
  1333. port_name = wwn_to_u64(fcport->port_name);
  1334. break;
  1335. }
  1336. }
  1337. fc_starget_port_name(starget) = port_name;
  1338. }
  1339. static void
  1340. qla2x00_get_starget_port_id(struct scsi_target *starget)
  1341. {
  1342. struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
  1343. scsi_qla_host_t *vha = shost_priv(host);
  1344. fc_port_t *fcport;
  1345. uint32_t port_id = ~0U;
  1346. list_for_each_entry(fcport, &vha->vp_fcports, list) {
  1347. if (fcport->rport &&
  1348. starget->id == fcport->rport->scsi_target_id) {
  1349. port_id = fcport->d_id.b.domain << 16 |
  1350. fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa;
  1351. break;
  1352. }
  1353. }
  1354. fc_starget_port_id(starget) = port_id;
  1355. }
  1356. static void
  1357. qla2x00_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout)
  1358. {
  1359. if (timeout)
  1360. rport->dev_loss_tmo = timeout;
  1361. else
  1362. rport->dev_loss_tmo = 1;
  1363. }
  1364. static void
  1365. qla2x00_dev_loss_tmo_callbk(struct fc_rport *rport)
  1366. {
  1367. struct Scsi_Host *host = rport_to_shost(rport);
  1368. fc_port_t *fcport = *(fc_port_t **)rport->dd_data;
  1369. unsigned long flags;
  1370. if (!fcport)
  1371. return;
  1372. /* Now that the rport has been deleted, set the fcport state to
  1373. FCS_DEVICE_DEAD */
  1374. qla2x00_set_fcport_state(fcport, FCS_DEVICE_DEAD);
  1375. /*
  1376. * Transport has effectively 'deleted' the rport, clear
  1377. * all local references.
  1378. */
  1379. spin_lock_irqsave(host->host_lock, flags);
  1380. fcport->rport = fcport->drport = NULL;
  1381. *((fc_port_t **)rport->dd_data) = NULL;
  1382. spin_unlock_irqrestore(host->host_lock, flags);
  1383. if (test_bit(ABORT_ISP_ACTIVE, &fcport->vha->dpc_flags))
  1384. return;
  1385. if (unlikely(pci_channel_offline(fcport->vha->hw->pdev))) {
  1386. qla2x00_abort_all_cmds(fcport->vha, DID_NO_CONNECT << 16);
  1387. return;
  1388. }
  1389. }
  1390. static void
  1391. qla2x00_terminate_rport_io(struct fc_rport *rport)
  1392. {
  1393. fc_port_t *fcport = *(fc_port_t **)rport->dd_data;
  1394. if (!fcport)
  1395. return;
  1396. if (test_bit(ABORT_ISP_ACTIVE, &fcport->vha->dpc_flags))
  1397. return;
  1398. if (unlikely(pci_channel_offline(fcport->vha->hw->pdev))) {
  1399. qla2x00_abort_all_cmds(fcport->vha, DID_NO_CONNECT << 16);
  1400. return;
  1401. }
  1402. /*
  1403. * At this point all fcport's software-states are cleared. Perform any
  1404. * final cleanup of firmware resources (PCBs and XCBs).
  1405. */
  1406. if (fcport->loop_id != FC_NO_LOOP_ID &&
  1407. !test_bit(UNLOADING, &fcport->vha->dpc_flags))
  1408. fcport->vha->hw->isp_ops->fabric_logout(fcport->vha,
  1409. fcport->loop_id, fcport->d_id.b.domain,
  1410. fcport->d_id.b.area, fcport->d_id.b.al_pa);
  1411. }
  1412. static int
  1413. qla2x00_issue_lip(struct Scsi_Host *shost)
  1414. {
  1415. scsi_qla_host_t *vha = shost_priv(shost);
  1416. qla2x00_loop_reset(vha);
  1417. return 0;
  1418. }
  1419. static struct fc_host_statistics *
  1420. qla2x00_get_fc_host_stats(struct Scsi_Host *shost)
  1421. {
  1422. scsi_qla_host_t *vha = shost_priv(shost);
  1423. struct qla_hw_data *ha = vha->hw;
  1424. struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
  1425. int rval;
  1426. struct link_statistics *stats;
  1427. dma_addr_t stats_dma;
  1428. struct fc_host_statistics *pfc_host_stat;
  1429. pfc_host_stat = &ha->fc_host_stat;
  1430. memset(pfc_host_stat, -1, sizeof(struct fc_host_statistics));
  1431. if (test_bit(UNLOADING, &vha->dpc_flags))
  1432. goto done;
  1433. if (unlikely(pci_channel_offline(ha->pdev)))
  1434. goto done;
  1435. stats = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &stats_dma);
  1436. if (stats == NULL) {
  1437. ql_log(ql_log_warn, vha, 0x707d,
  1438. "Failed to allocate memory for stats.\n");
  1439. goto done;
  1440. }
  1441. memset(stats, 0, DMA_POOL_SIZE);
  1442. rval = QLA_FUNCTION_FAILED;
  1443. if (IS_FWI2_CAPABLE(ha)) {
  1444. rval = qla24xx_get_isp_stats(base_vha, stats, stats_dma);
  1445. } else if (atomic_read(&base_vha->loop_state) == LOOP_READY &&
  1446. !test_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags) &&
  1447. !test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags) &&
  1448. !ha->dpc_active) {
  1449. /* Must be in a 'READY' state for statistics retrieval. */
  1450. rval = qla2x00_get_link_status(base_vha, base_vha->loop_id,
  1451. stats, stats_dma);
  1452. }
  1453. if (rval != QLA_SUCCESS)
  1454. goto done_free;
  1455. pfc_host_stat->link_failure_count = stats->link_fail_cnt;
  1456. pfc_host_stat->loss_of_sync_count = stats->loss_sync_cnt;
  1457. pfc_host_stat->loss_of_signal_count = stats->loss_sig_cnt;
  1458. pfc_host_stat->prim_seq_protocol_err_count = stats->prim_seq_err_cnt;
  1459. pfc_host_stat->invalid_tx_word_count = stats->inval_xmit_word_cnt;
  1460. pfc_host_stat->invalid_crc_count = stats->inval_crc_cnt;
  1461. if (IS_FWI2_CAPABLE(ha)) {
  1462. pfc_host_stat->lip_count = stats->lip_cnt;
  1463. pfc_host_stat->tx_frames = stats->tx_frames;
  1464. pfc_host_stat->rx_frames = stats->rx_frames;
  1465. pfc_host_stat->dumped_frames = stats->dumped_frames;
  1466. pfc_host_stat->nos_count = stats->nos_rcvd;
  1467. }
  1468. pfc_host_stat->fcp_input_megabytes = ha->qla_stats.input_bytes >> 20;
  1469. pfc_host_stat->fcp_output_megabytes = ha->qla_stats.output_bytes >> 20;
  1470. done_free:
  1471. dma_pool_free(ha->s_dma_pool, stats, stats_dma);
  1472. done:
  1473. return pfc_host_stat;
  1474. }
  1475. static void
  1476. qla2x00_get_host_symbolic_name(struct Scsi_Host *shost)
  1477. {
  1478. scsi_qla_host_t *vha = shost_priv(shost);
  1479. qla2x00_get_sym_node_name(vha, fc_host_symbolic_name(shost));
  1480. }
  1481. static void
  1482. qla2x00_set_host_system_hostname(struct Scsi_Host *shost)
  1483. {
  1484. scsi_qla_host_t *vha = shost_priv(shost);
  1485. set_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags);
  1486. }
  1487. static void
  1488. qla2x00_get_host_fabric_name(struct Scsi_Host *shost)
  1489. {
  1490. scsi_qla_host_t *vha = shost_priv(shost);
  1491. uint8_t node_name[WWN_SIZE] = { 0xFF, 0xFF, 0xFF, 0xFF, \
  1492. 0xFF, 0xFF, 0xFF, 0xFF};
  1493. u64 fabric_name = wwn_to_u64(node_name);
  1494. if (vha->device_flags & SWITCH_FOUND)
  1495. fabric_name = wwn_to_u64(vha->fabric_node_name);
  1496. fc_host_fabric_name(shost) = fabric_name;
  1497. }
  1498. static void
  1499. qla2x00_get_host_port_state(struct Scsi_Host *shost)
  1500. {
  1501. scsi_qla_host_t *vha = shost_priv(shost);
  1502. struct scsi_qla_host *base_vha = pci_get_drvdata(vha->hw->pdev);
  1503. if (!base_vha->flags.online)
  1504. fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE;
  1505. else if (atomic_read(&base_vha->loop_state) == LOOP_TIMEOUT)
  1506. fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN;
  1507. else
  1508. fc_host_port_state(shost) = FC_PORTSTATE_ONLINE;
  1509. }
  1510. static int
  1511. qla24xx_vport_create(struct fc_vport *fc_vport, bool disable)
  1512. {
  1513. int ret = 0;
  1514. uint8_t qos = 0;
  1515. scsi_qla_host_t *base_vha = shost_priv(fc_vport->shost);
  1516. scsi_qla_host_t *vha = NULL;
  1517. struct qla_hw_data *ha = base_vha->hw;
  1518. uint16_t options = 0;
  1519. int cnt;
  1520. struct req_que *req = ha->req_q_map[0];
  1521. ret = qla24xx_vport_create_req_sanity_check(fc_vport);
  1522. if (ret) {
  1523. ql_log(ql_log_warn, vha, 0x707e,
  1524. "Vport sanity check failed, status %x\n", ret);
  1525. return (ret);
  1526. }
  1527. vha = qla24xx_create_vhost(fc_vport);
  1528. if (vha == NULL) {
  1529. ql_log(ql_log_warn, vha, 0x707f, "Vport create host failed.\n");
  1530. return FC_VPORT_FAILED;
  1531. }
  1532. if (disable) {
  1533. atomic_set(&vha->vp_state, VP_OFFLINE);
  1534. fc_vport_set_state(fc_vport, FC_VPORT_DISABLED);
  1535. } else
  1536. atomic_set(&vha->vp_state, VP_FAILED);
  1537. /* ready to create vport */
  1538. ql_log(ql_log_info, vha, 0x7080,
  1539. "VP entry id %d assigned.\n", vha->vp_idx);
  1540. /* initialized vport states */
  1541. atomic_set(&vha->loop_state, LOOP_DOWN);
  1542. vha->vp_err_state= VP_ERR_PORTDWN;
  1543. vha->vp_prev_err_state= VP_ERR_UNKWN;
  1544. /* Check if physical ha port is Up */
  1545. if (atomic_read(&base_vha->loop_state) == LOOP_DOWN ||
  1546. atomic_read(&base_vha->loop_state) == LOOP_DEAD) {
  1547. /* Don't retry or attempt login of this virtual port */
  1548. ql_dbg(ql_dbg_user, vha, 0x7081,
  1549. "Vport loop state is not UP.\n");
  1550. atomic_set(&vha->loop_state, LOOP_DEAD);
  1551. if (!disable)
  1552. fc_vport_set_state(fc_vport, FC_VPORT_LINKDOWN);
  1553. }
  1554. if (IS_T10_PI_CAPABLE(ha) && ql2xenabledif) {
  1555. if (ha->fw_attributes & BIT_4) {
  1556. int prot = 0;
  1557. vha->flags.difdix_supported = 1;
  1558. ql_dbg(ql_dbg_user, vha, 0x7082,
  1559. "Registered for DIF/DIX type 1 and 3 protection.\n");
  1560. if (ql2xenabledif == 1)
  1561. prot = SHOST_DIX_TYPE0_PROTECTION;
  1562. scsi_host_set_prot(vha->host,
  1563. prot | SHOST_DIF_TYPE1_PROTECTION
  1564. | SHOST_DIF_TYPE2_PROTECTION
  1565. | SHOST_DIF_TYPE3_PROTECTION
  1566. | SHOST_DIX_TYPE1_PROTECTION
  1567. | SHOST_DIX_TYPE2_PROTECTION
  1568. | SHOST_DIX_TYPE3_PROTECTION);
  1569. scsi_host_set_guard(vha->host, SHOST_DIX_GUARD_CRC);
  1570. } else
  1571. vha->flags.difdix_supported = 0;
  1572. }
  1573. if (scsi_add_host_with_dma(vha->host, &fc_vport->dev,
  1574. &ha->pdev->dev)) {
  1575. ql_dbg(ql_dbg_user, vha, 0x7083,
  1576. "scsi_add_host failure for VP[%d].\n", vha->vp_idx);
  1577. goto vport_create_failed_2;
  1578. }
  1579. /* initialize attributes */
  1580. fc_host_dev_loss_tmo(vha->host) = ha->port_down_retry_count;
  1581. fc_host_node_name(vha->host) = wwn_to_u64(vha->node_name);
  1582. fc_host_port_name(vha->host) = wwn_to_u64(vha->port_name);
  1583. fc_host_supported_classes(vha->host) =
  1584. fc_host_supported_classes(base_vha->host);
  1585. fc_host_supported_speeds(vha->host) =
  1586. fc_host_supported_speeds(base_vha->host);
  1587. qla24xx_vport_disable(fc_vport, disable);
  1588. if (ha->flags.cpu_affinity_enabled) {
  1589. req = ha->req_q_map[1];
  1590. ql_dbg(ql_dbg_multiq, vha, 0xc000,
  1591. "Request queue %p attached with "
  1592. "VP[%d], cpu affinity =%d\n",
  1593. req, vha->vp_idx, ha->flags.cpu_affinity_enabled);
  1594. goto vport_queue;
  1595. } else if (ql2xmaxqueues == 1 || !ha->npiv_info)
  1596. goto vport_queue;
  1597. /* Create a request queue in QoS mode for the vport */
  1598. for (cnt = 0; cnt < ha->nvram_npiv_size; cnt++) {
  1599. if (memcmp(ha->npiv_info[cnt].port_name, vha->port_name, 8) == 0
  1600. && memcmp(ha->npiv_info[cnt].node_name, vha->node_name,
  1601. 8) == 0) {
  1602. qos = ha->npiv_info[cnt].q_qos;
  1603. break;
  1604. }
  1605. }
  1606. if (qos) {
  1607. ret = qla25xx_create_req_que(ha, options, vha->vp_idx, 0, 0,
  1608. qos);
  1609. if (!ret)
  1610. ql_log(ql_log_warn, vha, 0x7084,
  1611. "Can't create request queue for VP[%d]\n",
  1612. vha->vp_idx);
  1613. else {
  1614. ql_dbg(ql_dbg_multiq, vha, 0xc001,
  1615. "Request Que:%d Q0s: %d) created for VP[%d]\n",
  1616. ret, qos, vha->vp_idx);
  1617. ql_dbg(ql_dbg_user, vha, 0x7085,
  1618. "Request Que:%d Q0s: %d) created for VP[%d]\n",
  1619. ret, qos, vha->vp_idx);
  1620. req = ha->req_q_map[ret];
  1621. }
  1622. }
  1623. vport_queue:
  1624. vha->req = req;
  1625. return 0;
  1626. vport_create_failed_2:
  1627. qla24xx_disable_vp(vha);
  1628. qla24xx_deallocate_vp_id(vha);
  1629. scsi_host_put(vha->host);
  1630. return FC_VPORT_FAILED;
  1631. }
  1632. static int
  1633. qla24xx_vport_delete(struct fc_vport *fc_vport)
  1634. {
  1635. scsi_qla_host_t *vha = fc_vport->dd_data;
  1636. struct qla_hw_data *ha = vha->hw;
  1637. uint16_t id = vha->vp_idx;
  1638. while (test_bit(LOOP_RESYNC_ACTIVE, &vha->dpc_flags) ||
  1639. test_bit(FCPORT_UPDATE_NEEDED, &vha->dpc_flags))
  1640. msleep(1000);
  1641. qla24xx_disable_vp(vha);
  1642. vha->flags.delete_progress = 1;
  1643. fc_remove_host(vha->host);
  1644. scsi_remove_host(vha->host);
  1645. /* Allow timer to run to drain queued items, when removing vp */
  1646. qla24xx_deallocate_vp_id(vha);
  1647. if (vha->timer_active) {
  1648. qla2x00_vp_stop_timer(vha);
  1649. ql_dbg(ql_dbg_user, vha, 0x7086,
  1650. "Timer for the VP[%d] has stopped\n", vha->vp_idx);
  1651. }
  1652. /* No pending activities shall be there on the vha now */
  1653. if (ql2xextended_error_logging & ql_dbg_user)
  1654. msleep(random32()%10); /* Just to see if something falls on
  1655. * the net we have placed below */
  1656. BUG_ON(atomic_read(&vha->vref_count));
  1657. qla2x00_free_fcports(vha);
  1658. mutex_lock(&ha->vport_lock);
  1659. ha->cur_vport_count--;
  1660. clear_bit(vha->vp_idx, ha->vp_idx_map);
  1661. mutex_unlock(&ha->vport_lock);
  1662. if (vha->req->id && !ha->flags.cpu_affinity_enabled) {
  1663. if (qla25xx_delete_req_que(vha, vha->req) != QLA_SUCCESS)
  1664. ql_log(ql_log_warn, vha, 0x7087,
  1665. "Queue delete failed.\n");
  1666. }
  1667. scsi_host_put(vha->host);
  1668. ql_log(ql_log_info, vha, 0x7088, "VP[%d] deleted.\n", id);
  1669. return 0;
  1670. }
  1671. static int
  1672. qla24xx_vport_disable(struct fc_vport *fc_vport, bool disable)
  1673. {
  1674. scsi_qla_host_t *vha = fc_vport->dd_data;
  1675. if (disable)
  1676. qla24xx_disable_vp(vha);
  1677. else
  1678. qla24xx_enable_vp(vha);
  1679. return 0;
  1680. }
  1681. struct fc_function_template qla2xxx_transport_functions = {
  1682. .show_host_node_name = 1,
  1683. .show_host_port_name = 1,
  1684. .show_host_supported_classes = 1,
  1685. .show_host_supported_speeds = 1,
  1686. .get_host_port_id = qla2x00_get_host_port_id,
  1687. .show_host_port_id = 1,
  1688. .get_host_speed = qla2x00_get_host_speed,
  1689. .show_host_speed = 1,
  1690. .get_host_port_type = qla2x00_get_host_port_type,
  1691. .show_host_port_type = 1,
  1692. .get_host_symbolic_name = qla2x00_get_host_symbolic_name,
  1693. .show_host_symbolic_name = 1,
  1694. .set_host_system_hostname = qla2x00_set_host_system_hostname,
  1695. .show_host_system_hostname = 1,
  1696. .get_host_fabric_name = qla2x00_get_host_fabric_name,
  1697. .show_host_fabric_name = 1,
  1698. .get_host_port_state = qla2x00_get_host_port_state,
  1699. .show_host_port_state = 1,
  1700. .dd_fcrport_size = sizeof(struct fc_port *),
  1701. .show_rport_supported_classes = 1,
  1702. .get_starget_node_name = qla2x00_get_starget_node_name,
  1703. .show_starget_node_name = 1,
  1704. .get_starget_port_name = qla2x00_get_starget_port_name,
  1705. .show_starget_port_name = 1,
  1706. .get_starget_port_id = qla2x00_get_starget_port_id,
  1707. .show_starget_port_id = 1,
  1708. .set_rport_dev_loss_tmo = qla2x00_set_rport_loss_tmo,
  1709. .show_rport_dev_loss_tmo = 1,
  1710. .issue_fc_host_lip = qla2x00_issue_lip,
  1711. .dev_loss_tmo_callbk = qla2x00_dev_loss_tmo_callbk,
  1712. .terminate_rport_io = qla2x00_terminate_rport_io,
  1713. .get_fc_host_stats = qla2x00_get_fc_host_stats,
  1714. .vport_create = qla24xx_vport_create,
  1715. .vport_disable = qla24xx_vport_disable,
  1716. .vport_delete = qla24xx_vport_delete,
  1717. .bsg_request = qla24xx_bsg_request,
  1718. .bsg_timeout = qla24xx_bsg_timeout,
  1719. };
  1720. struct fc_function_template qla2xxx_transport_vport_functions = {
  1721. .show_host_node_name = 1,
  1722. .show_host_port_name = 1,
  1723. .show_host_supported_classes = 1,
  1724. .get_host_port_id = qla2x00_get_host_port_id,
  1725. .show_host_port_id = 1,
  1726. .get_host_speed = qla2x00_get_host_speed,
  1727. .show_host_speed = 1,
  1728. .get_host_port_type = qla2x00_get_host_port_type,
  1729. .show_host_port_type = 1,
  1730. .get_host_symbolic_name = qla2x00_get_host_symbolic_name,
  1731. .show_host_symbolic_name = 1,
  1732. .set_host_system_hostname = qla2x00_set_host_system_hostname,
  1733. .show_host_system_hostname = 1,
  1734. .get_host_fabric_name = qla2x00_get_host_fabric_name,
  1735. .show_host_fabric_name = 1,
  1736. .get_host_port_state = qla2x00_get_host_port_state,
  1737. .show_host_port_state = 1,
  1738. .dd_fcrport_size = sizeof(struct fc_port *),
  1739. .show_rport_supported_classes = 1,
  1740. .get_starget_node_name = qla2x00_get_starget_node_name,
  1741. .show_starget_node_name = 1,
  1742. .get_starget_port_name = qla2x00_get_starget_port_name,
  1743. .show_starget_port_name = 1,
  1744. .get_starget_port_id = qla2x00_get_starget_port_id,
  1745. .show_starget_port_id = 1,
  1746. .set_rport_dev_loss_tmo = qla2x00_set_rport_loss_tmo,
  1747. .show_rport_dev_loss_tmo = 1,
  1748. .issue_fc_host_lip = qla2x00_issue_lip,
  1749. .dev_loss_tmo_callbk = qla2x00_dev_loss_tmo_callbk,
  1750. .terminate_rport_io = qla2x00_terminate_rport_io,
  1751. .get_fc_host_stats = qla2x00_get_fc_host_stats,
  1752. .bsg_request = qla24xx_bsg_request,
  1753. .bsg_timeout = qla24xx_bsg_timeout,
  1754. };
  1755. void
  1756. qla2x00_init_host_attr(scsi_qla_host_t *vha)
  1757. {
  1758. struct qla_hw_data *ha = vha->hw;
  1759. u32 speed = FC_PORTSPEED_UNKNOWN;
  1760. fc_host_dev_loss_tmo(vha->host) = ha->port_down_retry_count;
  1761. fc_host_node_name(vha->host) = wwn_to_u64(vha->node_name);
  1762. fc_host_port_name(vha->host) = wwn_to_u64(vha->port_name);
  1763. fc_host_supported_classes(vha->host) = FC_COS_CLASS3;
  1764. fc_host_max_npiv_vports(vha->host) = ha->max_npiv_vports;
  1765. fc_host_npiv_vports_inuse(vha->host) = ha->cur_vport_count;
  1766. if (IS_QLA8XXX_TYPE(ha))
  1767. speed = FC_PORTSPEED_10GBIT;
  1768. else if (IS_QLA25XX(ha))
  1769. speed = FC_PORTSPEED_8GBIT | FC_PORTSPEED_4GBIT |
  1770. FC_PORTSPEED_2GBIT | FC_PORTSPEED_1GBIT;
  1771. else if (IS_QLA24XX_TYPE(ha))
  1772. speed = FC_PORTSPEED_4GBIT | FC_PORTSPEED_2GBIT |
  1773. FC_PORTSPEED_1GBIT;
  1774. else if (IS_QLA23XX(ha))
  1775. speed = FC_PORTSPEED_2GBIT | FC_PORTSPEED_1GBIT;
  1776. else
  1777. speed = FC_PORTSPEED_1GBIT;
  1778. fc_host_supported_speeds(vha->host) = speed;
  1779. }