qla_attr.c 55 KB

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