加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
qla_bsg.c 99.80 KB
一键复制 编辑 原始数据 按行查看 历史
XiaosuLi 提交于 2022-11-24 20:34 . qla2xxx 10.02.08.01 version
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614
/*
* QLogic Fibre Channel HBA Driver
* Copyright (c) 2003-2014 QLogic Corporation
*
* See LICENSE.qla2xxx for copyright and licensing details.
*/
#include "qla_def.h"
#include "qla_gbl.h"
#include <linux/kthread.h>
#include <linux/vmalloc.h>
#include <linux/delay.h>
#include <linux/bsg-lib.h>
static void qla2xxx_free_fcport_work(struct work_struct *work)
{
struct fc_port *fcport = container_of(work, typeof(*fcport),
free_work);
qla2x00_free_fcport(fcport);
}
/* BSG support for ELS/CT pass through */
void qla2x00_bsg_job_done(srb_t *sp, int res)
{
bsg_job_t *bsg_job = sp->u.bsg_job;
struct fc_bsg_reply *bsg_reply = bsg_job->reply;
ql_dbg(ql_dbg_user, sp->vha, 0x7009,
"%s: sp hdl %x, result=%x bsg ptr %px\n",
__func__, sp->handle, res, bsg_job);
/* ref: INIT */
kref_put(&sp->cmd_kref, qla2x00_sp_release);
bsg_reply->result = res;
bsg_job_done(bsg_job, bsg_reply->result,
bsg_reply->reply_payload_rcv_len);
}
void qla2x00_bsg_sp_free(srb_t *sp)
{
struct qla_hw_data *ha = sp->vha->hw;
bsg_job_t *bsg_job = sp->u.bsg_job;
struct fc_bsg_request *bsg_request = bsg_job->request;
struct qla_mt_iocb_rqst_fx00 *piocb_rqst;
if (sp->type == SRB_FXIOCB_BCMD) {
piocb_rqst = (struct qla_mt_iocb_rqst_fx00 *)
&bsg_request->rqst_data.h_vendor.vendor_cmd[1];
if (piocb_rqst->flags & SRB_FXDISC_REQ_DMA_VALID)
dma_unmap_sg(&ha->pdev->dev,
bsg_job->request_payload.sg_list,
bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
if (piocb_rqst->flags & SRB_FXDISC_RESP_DMA_VALID)
dma_unmap_sg(&ha->pdev->dev,
bsg_job->reply_payload.sg_list,
bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
} else {
if (sp->remap.remapped) {
dma_pool_free(ha->purex_dma_pool, sp->remap.rsp.buf,
sp->remap.rsp.dma);
dma_pool_free(ha->purex_dma_pool, sp->remap.req.buf,
sp->remap.req.dma);
} else {
dma_unmap_sg(&ha->pdev->dev, bsg_job->request_payload.sg_list,
bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
dma_unmap_sg(&ha->pdev->dev, bsg_job->reply_payload.sg_list,
bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
}
}
if (sp->type == SRB_CT_CMD ||
sp->type == SRB_FXIOCB_BCMD ||
sp->type == SRB_ELS_CMD_HST) {
INIT_WORK(&sp->fcport->free_work, qla2xxx_free_fcport_work);
queue_work(ha->wq, &sp->fcport->free_work);
}
qla2x00_rel_sp(sp);
}
int
qla24xx_fcp_prio_cfg_valid(scsi_qla_host_t *vha,
struct qla_fcp_prio_cfg *pri_cfg, uint8_t flag)
{
int i, ret, num_valid;
uint8_t *bcode;
struct qla_fcp_prio_entry *pri_entry;
uint32_t *bcode_val_ptr, bcode_val;
ret = 1;
num_valid = 0;
bcode = (uint8_t *)pri_cfg;
bcode_val_ptr = (uint32_t *)pri_cfg;
bcode_val = (uint32_t)(*bcode_val_ptr);
if (bcode_val == 0xFFFFFFFF) {
/* No FCP Priority config data in flash */
ql_dbg(ql_dbg_user, vha, 0x7051,
"No FCP Priority config data.\n");
return 0;
}
if (memcmp(bcode, "HQOS", 4)) {
/* Invalid FCP priority data header*/
ql_dbg(ql_dbg_user, vha, 0x7052,
"Invalid FCP Priority data header. bcode=0x%x.\n",
bcode_val);
return 0;
}
if (flag != 1)
return ret;
pri_entry = &pri_cfg->entry[0];
for (i = 0; i < pri_cfg->num_entries; i++) {
if (pri_entry->flags & FCP_PRIO_ENTRY_TAG_VALID)
num_valid++;
pri_entry++;
}
if (num_valid == 0) {
/* No valid FCP priority data entries */
ql_dbg(ql_dbg_user, vha, 0x7053,
"No valid FCP Priority data entries.\n");
ret = 0;
} else {
/* FCP priority data is valid */
ql_dbg(ql_dbg_user, vha, 0x7054,
"Valid FCP priority data. num entries = %d.\n",
num_valid);
}
return ret;
}
static int
qla24xx_proc_fcp_prio_cfg_cmd(bsg_job_t *bsg_job)
{
struct Scsi_Host *host = fc_bsg_to_shost(bsg_job);
struct fc_bsg_request *bsg_request = bsg_job->request;
struct fc_bsg_reply *bsg_reply = bsg_job->reply;
scsi_qla_host_t *vha = shost_priv(host);
struct qla_hw_data *ha = vha->hw;
int ret = 0;
uint32_t len;
uint32_t oper;
if (!(IS_QLA24XX_TYPE(ha) || IS_QLA25XX(ha) || IS_P3P_TYPE(ha))) {
ret = -EINVAL;
goto exit_fcp_prio_cfg;
}
/* Get the sub command */
oper = bsg_request->rqst_data.h_vendor.vendor_cmd[1];
/* Only set config is allowed if config memory is not allocated */
if (!ha->fcp_prio_cfg && (oper != QLFC_FCP_PRIO_SET_CONFIG)) {
ret = -EINVAL;
goto exit_fcp_prio_cfg;
}
switch (oper) {
case QLFC_FCP_PRIO_DISABLE:
if (ha->flags.fcp_prio_enabled) {
ha->flags.fcp_prio_enabled = 0;
ha->fcp_prio_cfg->attributes &=
~FCP_PRIO_ATTR_ENABLE;
qla24xx_update_all_fcp_prio(vha);
bsg_reply->result = DID_OK;
} else {
ret = -EINVAL;
bsg_reply->result = (DID_ERROR << 16);
goto exit_fcp_prio_cfg;
}
break;
case QLFC_FCP_PRIO_ENABLE:
if (!ha->flags.fcp_prio_enabled) {
if (ha->fcp_prio_cfg) {
ha->flags.fcp_prio_enabled = 1;
ha->fcp_prio_cfg->attributes |=
FCP_PRIO_ATTR_ENABLE;
qla24xx_update_all_fcp_prio(vha);
bsg_reply->result = DID_OK;
} else {
ret = -EINVAL;
bsg_reply->result = (DID_ERROR << 16);
goto exit_fcp_prio_cfg;
}
}
break;
case QLFC_FCP_PRIO_GET_CONFIG:
len = bsg_job->reply_payload.payload_len;
if (!len || len > FCP_PRIO_CFG_SIZE) {
ret = -EINVAL;
bsg_reply->result = (DID_ERROR << 16);
goto exit_fcp_prio_cfg;
}
bsg_reply->result = DID_OK;
bsg_reply->reply_payload_rcv_len =
sg_copy_from_buffer(
bsg_job->reply_payload.sg_list,
bsg_job->reply_payload.sg_cnt, ha->fcp_prio_cfg,
len);
break;
case QLFC_FCP_PRIO_SET_CONFIG:
len = bsg_job->request_payload.payload_len;
if (!len || len > FCP_PRIO_CFG_SIZE) {
bsg_reply->result = (DID_ERROR << 16);
ret = -EINVAL;
goto exit_fcp_prio_cfg;
}
if (!ha->fcp_prio_cfg) {
ha->fcp_prio_cfg = vmalloc(FCP_PRIO_CFG_SIZE);
if (!ha->fcp_prio_cfg) {
ql_log(ql_log_warn, vha, 0x7050,
"Unable to allocate memory for fcp prio "
"config data (%x).\n", FCP_PRIO_CFG_SIZE);
bsg_reply->result = (DID_ERROR << 16);
ret = -ENOMEM;
goto exit_fcp_prio_cfg;
}
}
memset(ha->fcp_prio_cfg, 0, FCP_PRIO_CFG_SIZE);
sg_copy_to_buffer(bsg_job->request_payload.sg_list,
bsg_job->request_payload.sg_cnt, ha->fcp_prio_cfg,
FCP_PRIO_CFG_SIZE);
/* validate fcp priority data */
if (!qla24xx_fcp_prio_cfg_valid(vha,
(struct qla_fcp_prio_cfg *) ha->fcp_prio_cfg, 1)) {
bsg_reply->result = (DID_ERROR << 16);
ret = -EINVAL;
/* If buffer was invalidatic int
* fcp_prio_cfg is of no use
*/
vfree(ha->fcp_prio_cfg);
ha->fcp_prio_cfg = NULL;
goto exit_fcp_prio_cfg;
}
ha->flags.fcp_prio_enabled = 0;
if (ha->fcp_prio_cfg->attributes & FCP_PRIO_ATTR_ENABLE)
ha->flags.fcp_prio_enabled = 1;
qla24xx_update_all_fcp_prio(vha);
bsg_reply->result = DID_OK;
break;
default:
ret = -EINVAL;
break;
}
exit_fcp_prio_cfg:
if (!ret)
bsg_job_done(bsg_job, bsg_reply->result,
bsg_reply->reply_payload_rcv_len);
return ret;
}
static int
qla2x00_process_els(bsg_job_t *bsg_job)
{
struct fc_bsg_request *bsg_request = bsg_job->request;
struct fc_rport *rport;
fc_port_t *fcport = NULL;
struct Scsi_Host *host;
scsi_qla_host_t *vha;
struct qla_hw_data *ha;
srb_t *sp;
const char *type;
int req_sg_cnt, rsp_sg_cnt;
int rval = (DID_ERROR << 16);
uint32_t els_cmd=0;
int qla_port_allocated = 0;
if (bsg_request->msgcode == FC_BSG_RPT_ELS) {
rport = fc_bsg_to_rport(bsg_job);
if (!rport) {
rval = -ENOMEM;
goto done;
}
fcport = *(fc_port_t **) rport->dd_data;
host = rport_to_shost(rport);
vha = shost_priv(host);
ha = vha->hw;
type = "FC_BSG_RPT_ELS";
} else {
host = fc_bsg_to_shost(bsg_job);
vha = shost_priv(host);
ha = vha->hw;
type = "FC_BSG_HST_ELS_NOLOGIN";
els_cmd=bsg_request->rqst_data.h_els.command_code;
if (els_cmd == ELS_AUTH_ELS)
return qla_edif_process_els(vha, bsg_job);
}
if (!vha->flags.online) {
ql_log(ql_log_warn, vha, 0x7005, "Host not online.\n");
rval = -EIO;
goto done;
}
/* pass through is supported only for ISP 4Gb or higher */
if (!IS_FWI2_CAPABLE(ha)) {
ql_dbg(ql_dbg_user, vha, 0x7001,
"ELS passthru not supported for ISP23xx based adapters.\n");
rval = -EPERM;
goto done;
}
/* Multiple SG's are not supported for ELS requests */
if (bsg_job->request_payload.sg_cnt > 1 ||
bsg_job->reply_payload.sg_cnt > 1) {
ql_dbg(ql_dbg_user, vha, 0x7002,
"Multiple SG's are not supported for ELS requests, "
"request_sg_cnt=%x reply_sg_cnt=%x.\n",
bsg_job->request_payload.sg_cnt,
bsg_job->reply_payload.sg_cnt);
rval = -EPERM;
goto done;
}
/* ELS request for rport */
if (bsg_request->msgcode == FC_BSG_RPT_ELS) {
/* make sure the rport is logged in,
* if not perform fabric login
*/
if (atomic_read(&fcport->state) != FCS_ONLINE) {
ql_dbg(ql_dbg_user, vha, 0x7003,
"Port %06X is not online for ELS passthru.\n",
fcport->d_id.b24);
rval = -EIO;
goto done;
}
} else {
/* Allocate a dummy fcport structure, since functions
* preparing the IOCB and mailbox command retrieves port
* specific information from fcport structure. For Host based
* ELS commands there will be no fcport structure allocated
*/
fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
if (!fcport) {
rval = -ENOMEM;
goto done;
}
qla_port_allocated = 1;
/* Initialize all required fields of fcport */
fcport->vha = vha;
fcport->d_id.b.al_pa =
bsg_request->rqst_data.h_els.port_id[0];
fcport->d_id.b.area =
bsg_request->rqst_data.h_els.port_id[1];
fcport->d_id.b.domain =
bsg_request->rqst_data.h_els.port_id[2];
fcport->loop_id =
(fcport->d_id.b.al_pa == 0xFD) ?
NPH_FABRIC_CONTROLLER : NPH_F_PORT;
}
req_sg_cnt =
dma_map_sg(&ha->pdev->dev, bsg_job->request_payload.sg_list,
bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
if (!req_sg_cnt) {
dma_unmap_sg(&ha->pdev->dev, bsg_job->request_payload.sg_list,
bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
rval = -ENOMEM;
goto done_free_fcport;
}
rsp_sg_cnt = dma_map_sg(&ha->pdev->dev, bsg_job->reply_payload.sg_list,
bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
if (!rsp_sg_cnt) {
dma_unmap_sg(&ha->pdev->dev, bsg_job->reply_payload.sg_list,
bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
rval = -ENOMEM;
goto done_free_fcport;
}
if ((req_sg_cnt != bsg_job->request_payload.sg_cnt) ||
(rsp_sg_cnt != bsg_job->reply_payload.sg_cnt)) {
ql_log(ql_log_warn, vha, 0x7008,
"dma mapping resulted in different sg counts, "
"request_sg_cnt: %x dma_request_sg_cnt:%x reply_sg_cnt:%x "
"dma_reply_sg_cnt:%x.\n", bsg_job->request_payload.sg_cnt,
req_sg_cnt, bsg_job->reply_payload.sg_cnt, rsp_sg_cnt);
rval = -EAGAIN;
goto done_unmap_sg;
}
/* Alloc SRB structure */
sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
if (!sp) {
rval = -ENOMEM;
goto done_unmap_sg;
}
sp->type =
(bsg_request->msgcode == FC_BSG_RPT_ELS ?
SRB_ELS_CMD_RPT : SRB_ELS_CMD_HST);
sp->name =
(bsg_request->msgcode == FC_BSG_RPT_ELS ?
"bsg_els_rpt" : "bsg_els_hst");
sp->u.bsg_job = bsg_job;
sp->free = qla2x00_bsg_sp_free;
sp->done = qla2x00_bsg_job_done;
ql_dbg(ql_dbg_user, vha, 0x700a,
"bsg rqst type: %s els type: %x - loop-id=%x "
"portid=%-2x%02x%02x.\n", type,
bsg_request->rqst_data.h_els.command_code, fcport->loop_id,
fcport->d_id.b.domain, fcport->d_id.b.area, fcport->d_id.b.al_pa);
rval = qla2x00_start_sp(sp);
if (rval != QLA_SUCCESS) {
ql_log(ql_log_warn, vha, 0x700e,
"qla2x00_start_sp failed = %d\n", rval);
qla2x00_rel_sp(sp);
rval = -EIO;
goto done_unmap_sg;
}
return rval;
done_unmap_sg:
dma_unmap_sg(&ha->pdev->dev, bsg_job->request_payload.sg_list,
bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
dma_unmap_sg(&ha->pdev->dev, bsg_job->reply_payload.sg_list,
bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
goto done_free_fcport;
done_free_fcport:
if (qla_port_allocated)
qla2x00_free_fcport(fcport);
done:
return rval;
}
static inline uint16_t
qla24xx_calc_ct_iocbs(uint16_t dsds)
{
uint16_t iocbs;
iocbs = 1;
if (dsds > 2) {
iocbs += (dsds - 2) / 5;
if ((dsds - 2) % 5)
iocbs++;
}
return iocbs;
}
static int
qla2x00_process_ct(bsg_job_t *bsg_job)
{
srb_t *sp;
struct fc_bsg_request *bsg_request = bsg_job->request;
struct Scsi_Host *host = fc_bsg_to_shost(bsg_job);
scsi_qla_host_t *vha = shost_priv(host);
struct qla_hw_data *ha = vha->hw;
int rval = (DID_ERROR << 16);
int req_sg_cnt, rsp_sg_cnt;
uint16_t loop_id;
struct fc_port *fcport;
char *type = "FC_BSG_HST_CT";
req_sg_cnt =
dma_map_sg(&ha->pdev->dev, bsg_job->request_payload.sg_list,
bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
if (!req_sg_cnt) {
ql_log(ql_log_warn, vha, 0x700f,
"dma_map_sg return %d for request\n", req_sg_cnt);
rval = -ENOMEM;
goto done;
}
rsp_sg_cnt = dma_map_sg(&ha->pdev->dev, bsg_job->reply_payload.sg_list,
bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
if (!rsp_sg_cnt) {
ql_log(ql_log_warn, vha, 0x7010,
"dma_map_sg return %d for reply\n", rsp_sg_cnt);
rval = -ENOMEM;
goto done;
}
if ((req_sg_cnt != bsg_job->request_payload.sg_cnt) ||
(rsp_sg_cnt != bsg_job->reply_payload.sg_cnt)) {
ql_log(ql_log_warn, vha, 0x7011,
"request_sg_cnt: %x dma_request_sg_cnt: %x reply_sg_cnt:%x "
"dma_reply_sg_cnt: %x\n", bsg_job->request_payload.sg_cnt,
req_sg_cnt, bsg_job->reply_payload.sg_cnt, rsp_sg_cnt);
rval = -EAGAIN;
goto done_unmap_sg;
}
if (!vha->flags.online) {
ql_log(ql_log_warn, vha, 0x7012,
"Host is not online.\n");
rval = -EIO;
goto done_unmap_sg;
}
loop_id =
(bsg_request->rqst_data.h_ct.preamble_word1 & 0xFF000000)
>> 24;
switch (loop_id) {
case 0xFC:
loop_id = cpu_to_le16(NPH_SNS);
break;
case 0xFA:
loop_id = vha->mgmt_svr_loop_id;
break;
default:
ql_dbg(ql_dbg_user, vha, 0x7013,
"Unknown loop id: %x.\n", loop_id);
rval = -EINVAL;
goto done_unmap_sg;
}
/* Allocate a dummy fcport structure, since functions preparing the
* IOCB and mailbox command retrieves port specific information
* from fcport structure. For Host based ELS commands there will be
* no fcport structure allocated
*/
fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
if (!fcport) {
ql_log(ql_log_warn, vha, 0x7014,
"Failed to allocate fcport.\n");
rval = -ENOMEM;
goto done_unmap_sg;
}
/* Initialize all required fields of fcport */
fcport->vha = vha;
fcport->d_id.b.al_pa = bsg_request->rqst_data.h_ct.port_id[0];
fcport->d_id.b.area = bsg_request->rqst_data.h_ct.port_id[1];
fcport->d_id.b.domain = bsg_request->rqst_data.h_ct.port_id[2];
fcport->loop_id = loop_id;
/* Alloc SRB structure */
sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
if (!sp) {
ql_log(ql_log_warn, vha, 0x7015,
"qla2x00_get_sp failed.\n");
rval = -ENOMEM;
goto done_free_fcport;
}
sp->type = SRB_CT_CMD;
sp->name = "bsg_ct";
sp->iocbs = qla24xx_calc_ct_iocbs(req_sg_cnt + rsp_sg_cnt);
sp->u.bsg_job = bsg_job;
sp->free = qla2x00_bsg_sp_free;
sp->done = qla2x00_bsg_job_done;
ql_dbg(ql_dbg_user, vha, 0x7016,
"bsg rqst type: %s else type: %x - "
"loop-id=%x portid=%02x%02x%02x.\n", type,
(bsg_request->rqst_data.h_ct.preamble_word2 >> 16),
fcport->loop_id, fcport->d_id.b.domain, fcport->d_id.b.area,
fcport->d_id.b.al_pa);
rval = qla2x00_start_sp(sp);
if (rval != QLA_SUCCESS) {
ql_log(ql_log_warn, vha, 0x7017,
"qla2x00_start_sp failed=%d.\n", rval);
qla2x00_rel_sp(sp);
rval = -EIO;
goto done_free_fcport;
}
return rval;
done_free_fcport:
qla2x00_free_fcport(fcport);
done_unmap_sg:
dma_unmap_sg(&ha->pdev->dev, bsg_job->request_payload.sg_list,
bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
dma_unmap_sg(&ha->pdev->dev, bsg_job->reply_payload.sg_list,
bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
done:
return rval;
}
/* Disable loopback mode */
static inline int
qla81xx_reset_loopback_mode(scsi_qla_host_t *vha, uint16_t *config,
int wait, int wait2)
{
int ret = 0;
int rval = 0;
uint16_t new_config[4];
struct qla_hw_data *ha = vha->hw;
if (!IS_QLA81XX(ha) && !IS_QLA8031(ha) && !IS_QLA8044(ha))
goto done_reset_internal;
memset(new_config, 0 , sizeof(new_config));
if ((config[0] & INTERNAL_LOOPBACK_MASK) >> 1 ==
ENABLE_INTERNAL_LOOPBACK ||
(config[0] & INTERNAL_LOOPBACK_MASK) >> 1 ==
ENABLE_EXTERNAL_LOOPBACK) {
new_config[0] = config[0] & ~INTERNAL_LOOPBACK_MASK;
ql_dbg(ql_dbg_user, vha, 0x70bf, "new_config[0]=%02x\n",
(new_config[0] & INTERNAL_LOOPBACK_MASK));
memcpy(&new_config[1], &config[1], sizeof(uint16_t) * 3) ;
ha->notify_dcbx_comp = wait;
ha->notify_lb_portup_comp = wait2;
ret = qla81xx_set_port_config(vha, new_config);
if (ret != QLA_SUCCESS) {
ql_log(ql_log_warn, vha, 0x7025,
"Set port config failed.\n");
ha->notify_dcbx_comp = 0;
ha->notify_lb_portup_comp = 0;
rval = -EINVAL;
goto done_reset_internal;
}
/* Wait for DCBX complete event */
if (wait && !wait_for_completion_timeout(&ha->dcbx_comp,
(DCBX_COMP_TIMEOUT * HZ))) {
ql_dbg(ql_dbg_user, vha, 0x7026,
"DCBX completion not received.\n");
ha->notify_dcbx_comp = 0;
ha->notify_lb_portup_comp = 0;
rval = -EINVAL;
goto done_reset_internal;
} else
ql_dbg(ql_dbg_user, vha, 0x7027,
"DCBX completion received.\n");
if (wait2 &&
!wait_for_completion_timeout(&ha->lb_portup_comp,
(LB_PORTUP_COMP_TIMEOUT * HZ))) {
ql_dbg(ql_dbg_user, vha, 0x70c5,
"Port up completion not received.\n");
ha->notify_lb_portup_comp = 0;
rval = -EINVAL;
goto done_reset_internal;
} else
ql_dbg(ql_dbg_user, vha, 0x70c6,
"Port up completion received.\n");
ha->notify_dcbx_comp = 0;
ha->notify_lb_portup_comp = 0;
}
done_reset_internal:
return rval;
}
/*
* Set the port configuration to enable the internal or external loopback
* depending on the loopback mode.
*/
static inline int
qla81xx_set_loopback_mode(scsi_qla_host_t *vha, uint16_t *config,
uint16_t *new_config, uint16_t mode)
{
int ret = 0;
int rval = 0;
unsigned long rem_tmo = 0, current_tmo = 0;
struct qla_hw_data *ha = vha->hw;
if (!IS_QLA81XX(ha) && !IS_QLA8031(ha) && !IS_QLA8044(ha))
goto done_set_internal;
if (mode == INTERNAL_LOOPBACK)
new_config[0] = config[0] | (ENABLE_INTERNAL_LOOPBACK << 1);
else if (mode == EXTERNAL_LOOPBACK)
new_config[0] = config[0] | (ENABLE_EXTERNAL_LOOPBACK << 1);
ql_dbg(ql_dbg_user, vha, 0x70be,
"new_config[0]=%02x\n", (new_config[0] & INTERNAL_LOOPBACK_MASK));
memcpy(&new_config[1], &config[1], sizeof(uint16_t) * 3);
ha->notify_dcbx_comp = 1;
ret = qla81xx_set_port_config(vha, new_config);
if (ret != QLA_SUCCESS) {
ql_log(ql_log_warn, vha, 0x7021,
"set port config failed.\n");
ha->notify_dcbx_comp = 0;
rval = -EINVAL;
goto done_set_internal;
}
/* Wait for DCBX complete event */
current_tmo = DCBX_COMP_TIMEOUT * HZ;
while (1) {
rem_tmo = wait_for_completion_timeout(&ha->dcbx_comp,
current_tmo);
if (!ha->idc_extend_tmo || rem_tmo) {
ha->idc_extend_tmo = 0;
break;
}
current_tmo = ha->idc_extend_tmo * HZ;
ha->idc_extend_tmo = 0;
}
if (!rem_tmo) {
ql_dbg(ql_dbg_user, vha, 0x7022,
"DCBX completion not received.\n");
ret = qla81xx_reset_loopback_mode(vha, new_config, 0, 0);
/*
* If the reset of the loopback mode doesn't work take a FCoE
* dump and reset the chip.
*/
if (ret) {
ha->isp_ops->fw_dump(vha, 0);
set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
}
rval = -EINVAL;
} else {
if (ha->flags.idc_compl_status) {
ql_dbg(ql_dbg_user, vha, 0x70c3,
"Bad status in IDC Completion AEN\n");
rval = -EINVAL;
ha->flags.idc_compl_status = 0;
} else
ql_dbg(ql_dbg_user, vha, 0x7023,
"DCBX completion received.\n");
}
ha->notify_dcbx_comp = 0;
ha->idc_extend_tmo = 0;
done_set_internal:
return rval;
}
static int
qla2x00_process_loopback(bsg_job_t *bsg_job)
{
struct fc_bsg_request *bsg_request = bsg_job->request;
struct fc_bsg_reply *bsg_reply = bsg_job->reply;
struct Scsi_Host *host = fc_bsg_to_shost(bsg_job);
scsi_qla_host_t *vha = shost_priv(host);
struct qla_hw_data *ha = vha->hw;
int rval;
uint8_t command_sent;
char *type;
struct msg_echo_lb elreq;
uint16_t response[MAILBOX_REGISTER_COUNT];
uint16_t config[4], new_config[4];
uint8_t *fw_sts_ptr;
void *req_data = NULL;
dma_addr_t req_data_dma;
uint32_t req_data_len;
uint8_t *rsp_data = NULL;
dma_addr_t rsp_data_dma;
uint32_t rsp_data_len;
if (!vha->flags.online) {
ql_log(ql_log_warn, vha, 0x7019, "Host is not online.\n");
return -EIO;
}
memset(&elreq, 0, sizeof(elreq));
elreq.req_sg_cnt = dma_map_sg(&ha->pdev->dev,
bsg_job->request_payload.sg_list, bsg_job->request_payload.sg_cnt,
DMA_TO_DEVICE);
if (!elreq.req_sg_cnt) {
ql_log(ql_log_warn, vha, 0x701a,
"dma_map_sg returned %d for request.\n", elreq.req_sg_cnt);
return -ENOMEM;
}
elreq.rsp_sg_cnt = dma_map_sg(&ha->pdev->dev,
bsg_job->reply_payload.sg_list, bsg_job->reply_payload.sg_cnt,
DMA_FROM_DEVICE);
if (!elreq.rsp_sg_cnt) {
ql_log(ql_log_warn, vha, 0x701b,
"dma_map_sg returned %d for reply.\n", elreq.rsp_sg_cnt);
rval = -ENOMEM;
goto done_unmap_req_sg;
}
if ((elreq.req_sg_cnt != bsg_job->request_payload.sg_cnt) ||
(elreq.rsp_sg_cnt != bsg_job->reply_payload.sg_cnt)) {
ql_log(ql_log_warn, vha, 0x701c,
"dma mapping resulted in different sg counts, "
"request_sg_cnt: %x dma_request_sg_cnt: %x "
"reply_sg_cnt: %x dma_reply_sg_cnt: %x.\n",
bsg_job->request_payload.sg_cnt, elreq.req_sg_cnt,
bsg_job->reply_payload.sg_cnt, elreq.rsp_sg_cnt);
rval = -EAGAIN;
goto done_unmap_sg;
}
req_data_len = rsp_data_len = bsg_job->request_payload.payload_len;
req_data = dma_alloc_coherent(&ha->pdev->dev, req_data_len,
&req_data_dma, GFP_KERNEL);
if (!req_data) {
ql_log(ql_log_warn, vha, 0x701d,
"dma alloc failed for req_data.\n");
rval = -ENOMEM;
goto done_unmap_sg;
}
rsp_data = dma_alloc_coherent(&ha->pdev->dev, rsp_data_len,
&rsp_data_dma, GFP_KERNEL);
if (!rsp_data) {
ql_log(ql_log_warn, vha, 0x7004,
"dma alloc failed for rsp_data.\n");
rval = -ENOMEM;
goto done_free_dma_req;
}
/* Copy the request buffer in req_data now */
sg_copy_to_buffer(bsg_job->request_payload.sg_list,
bsg_job->request_payload.sg_cnt, req_data, req_data_len);
elreq.send_dma = req_data_dma;
elreq.rcv_dma = rsp_data_dma;
elreq.transfer_size = req_data_len;
elreq.options = bsg_request->rqst_data.h_vendor.vendor_cmd[1];
elreq.iteration_count =
bsg_request->rqst_data.h_vendor.vendor_cmd[2];
if (atomic_read(&vha->loop_state) == LOOP_READY &&
((ha->current_topology == ISP_CFG_F && (elreq.options & 7) >= 2) ||
((IS_QLA81XX(ha) || IS_QLA8031(ha) || IS_QLA8044(ha)) &&
le32_to_cpup(req_data) == ELS_OPCODE_BYTE &&
req_data_len == MAX_ELS_FRAME_PAYLOAD &&
elreq.options == EXTERNAL_LOOPBACK))) {
type = "FC_BSG_HST_VENDOR_ECHO_DIAG";
ql_dbg(ql_dbg_user, vha, 0x701e,
"BSG request type: %s.\n", type);
command_sent = INT_DEF_LB_ECHO_CMD;
rval = qla2x00_echo_test(vha, &elreq, response);
} else {
if (IS_QLA81XX(ha) || IS_QLA8031(ha) || IS_QLA8044(ha)) {
memset(config, 0, sizeof(config));
memset(new_config, 0, sizeof(new_config));
if (qla81xx_get_port_config(vha, config)) {
ql_log(ql_log_warn, vha, 0x701f,
"Get port config failed.\n");
rval = -EPERM;
goto done_free_dma_rsp;
}
if ((config[0] & INTERNAL_LOOPBACK_MASK) != 0) {
ql_dbg(ql_dbg_user, vha, 0x70c4,
"Loopback operation already in "
"progress.\n");
rval = -EAGAIN;
goto done_free_dma_rsp;
}
ql_dbg(ql_dbg_user, vha, 0x70c0,
"elreq.options=%04x\n", elreq.options);
if (elreq.options == EXTERNAL_LOOPBACK)
if (IS_QLA8031(ha) || IS_QLA8044(ha))
rval = qla81xx_set_loopback_mode(vha,
config, new_config, elreq.options);
else
rval = qla81xx_reset_loopback_mode(vha,
config, 1, 0);
else
rval = qla81xx_set_loopback_mode(vha, config,
new_config, elreq.options);
if (rval) {
rval = -EPERM;
goto done_free_dma_rsp;
}
type = "FC_BSG_HST_VENDOR_LOOPBACK";
ql_dbg(ql_dbg_user, vha, 0x7028,
"BSG request type: %s.\n", type);
command_sent = INT_DEF_LB_LOOPBACK_CMD;
rval = qla2x00_loopback_test(vha, &elreq, response);
if (response[0] == MBS_COMMAND_ERROR &&
response[1] == MBS_LB_RESET) {
ql_log(ql_log_warn, vha, 0x7029,
"MBX command error, Aborting ISP.\n");
set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
qla2xxx_wake_dpc(vha);
qla2x00_wait_for_chip_reset(vha);
/* Also reset the MPI */
if (IS_QLA81XX(ha)) {
if (qla81xx_restart_mpi_firmware(vha) !=
QLA_SUCCESS) {
ql_log(ql_log_warn, vha, 0x702a,
"MPI reset failed.\n");
}
}
rval = -EIO;
goto done_free_dma_rsp;
}
if (new_config[0]) {
int ret;
/* Revert back to original port config
* Also clear internal loopback
*/
ret = qla81xx_reset_loopback_mode(vha,
new_config, 0, 1);
if (ret) {
/*
* If the reset of the loopback mode
* doesn't work take FCoE dump and then
* reset the chip.
*/
ha->isp_ops->fw_dump(vha, 0);
set_bit(ISP_ABORT_NEEDED,
&vha->dpc_flags);
}
}
} else {
type = "FC_BSG_HST_VENDOR_LOOPBACK";
ql_dbg(ql_dbg_user, vha, 0x702b,
"BSG request type: %s.\n", type);
command_sent = INT_DEF_LB_LOOPBACK_CMD;
rval = qla2x00_loopback_test(vha, &elreq, response);
}
}
if (rval) {
ql_log(ql_log_warn, vha, 0x702c,
"Vendor request %s failed.\n", type);
rval = 0;
bsg_reply->result = (DID_ERROR << 16);
bsg_reply->reply_payload_rcv_len = 0;
} else {
ql_dbg(ql_dbg_user, vha, 0x702d,
"Vendor request %s completed.\n", type);
bsg_reply->result = (DID_OK << 16);
sg_copy_from_buffer(bsg_job->reply_payload.sg_list,
bsg_job->reply_payload.sg_cnt, rsp_data,
rsp_data_len);
}
bsg_job->reply_len = sizeof(struct fc_bsg_reply) +
sizeof(response) + sizeof(uint8_t);
fw_sts_ptr = qla_fwsts_ptr(bsg_job);
memcpy(fw_sts_ptr, response, sizeof(response));
fw_sts_ptr += sizeof(response);
*fw_sts_ptr = command_sent;
done_free_dma_rsp:
dma_free_coherent(&ha->pdev->dev, rsp_data_len,
rsp_data, rsp_data_dma);
done_free_dma_req:
dma_free_coherent(&ha->pdev->dev, req_data_len,
req_data, req_data_dma);
done_unmap_sg:
dma_unmap_sg(&ha->pdev->dev,
bsg_job->reply_payload.sg_list,
bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
done_unmap_req_sg:
dma_unmap_sg(&ha->pdev->dev,
bsg_job->request_payload.sg_list,
bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
if (!rval)
bsg_job_done(bsg_job, bsg_reply->result,
bsg_reply->reply_payload_rcv_len);
return rval;
}
static int
qla84xx_reset(bsg_job_t *bsg_job)
{
struct fc_bsg_request *bsg_request = bsg_job->request;
struct Scsi_Host *host = fc_bsg_to_shost(bsg_job);
struct fc_bsg_reply *bsg_reply = bsg_job->reply;
scsi_qla_host_t *vha = shost_priv(host);
struct qla_hw_data *ha = vha->hw;
int rval = 0;
uint32_t flag;
if (!IS_QLA84XX(ha)) {
ql_dbg(ql_dbg_user, vha, 0x702f, "Not 84xx, exiting.\n");
return -EINVAL;
}
flag = bsg_request->rqst_data.h_vendor.vendor_cmd[1];
rval = qla84xx_reset_chip(vha, flag == A84_ISSUE_RESET_DIAG_FW);
if (rval) {
ql_log(ql_log_warn, vha, 0x7030,
"Vendor request 84xx reset failed.\n");
rval = (DID_ERROR << 16);
} else {
ql_dbg(ql_dbg_user, vha, 0x7031,
"Vendor request 84xx reset completed.\n");
bsg_reply->result = DID_OK;
bsg_job_done(bsg_job, bsg_reply->result,
bsg_reply->reply_payload_rcv_len);
}
return rval;
}
static int
qla84xx_updatefw(bsg_job_t *bsg_job)
{
struct fc_bsg_request *bsg_request = bsg_job->request;
struct fc_bsg_reply *bsg_reply = bsg_job->reply;
struct Scsi_Host *host = fc_bsg_to_shost(bsg_job);
scsi_qla_host_t *vha = shost_priv(host);
struct qla_hw_data *ha = vha->hw;
struct verify_chip_entry_84xx *mn = NULL;
dma_addr_t mn_dma, fw_dma;
void *fw_buf = NULL;
int rval = 0;
uint32_t sg_cnt;
uint32_t data_len;
uint16_t options;
uint32_t flag;
uint32_t fw_ver;
if (!IS_QLA84XX(ha)) {
ql_dbg(ql_dbg_user, vha, 0x7032,
"Not 84xx, exiting.\n");
return -EINVAL;
}
sg_cnt = dma_map_sg(&ha->pdev->dev, bsg_job->request_payload.sg_list,
bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
if (!sg_cnt) {
ql_log(ql_log_warn, vha, 0x7033,
"dma_map_sg returned %d for request.\n", sg_cnt);
return -ENOMEM;
}
if (sg_cnt != bsg_job->request_payload.sg_cnt) {
ql_log(ql_log_warn, vha, 0x7034,
"DMA mapping resulted in different sg counts, "
"request_sg_cnt: %x dma_request_sg_cnt: %x.\n",
bsg_job->request_payload.sg_cnt, sg_cnt);
rval = -EAGAIN;
goto done_unmap_sg;
}
data_len = bsg_job->request_payload.payload_len;
fw_buf = dma_alloc_coherent(&ha->pdev->dev, data_len,
&fw_dma, GFP_KERNEL);
if (!fw_buf) {
ql_log(ql_log_warn, vha, 0x7035,
"DMA alloc failed for fw_buf.\n");
rval = -ENOMEM;
goto done_unmap_sg;
}
sg_copy_to_buffer(bsg_job->request_payload.sg_list,
bsg_job->request_payload.sg_cnt, fw_buf, data_len);
mn = dma_pool_zalloc(ha->s_dma_pool, GFP_KERNEL, &mn_dma);
if (!mn) {
ql_log(ql_log_warn, vha, 0x7036,
"DMA alloc failed for fw buffer.\n");
rval = -ENOMEM;
goto done_free_fw_buf;
}
flag = bsg_request->rqst_data.h_vendor.vendor_cmd[1];
fw_ver = get_unaligned_le32((uint32_t *)fw_buf + 2);
mn->entry_type = VERIFY_CHIP_IOCB_TYPE;
mn->entry_count = 1;
options = VCO_FORCE_UPDATE | VCO_END_OF_DATA;
if (flag == A84_ISSUE_UPDATE_DIAGFW_CMD)
options |= VCO_DIAG_FW;
mn->options = cpu_to_le16(options);
mn->fw_ver = cpu_to_le32(fw_ver);
mn->fw_size = cpu_to_le32(data_len);
mn->fw_seq_size = cpu_to_le32(data_len);
put_unaligned_le64(fw_dma, &mn->dsd.address);
mn->dsd.length = cpu_to_le32(data_len);
mn->data_seg_cnt = cpu_to_le16(1);
rval = qla2x00_issue_iocb_timeout(vha, mn, mn_dma, 0, 120);
if (rval) {
ql_log(ql_log_warn, vha, 0x7037,
"Vendor request 84xx updatefw failed.\n");
rval = (DID_ERROR << 16);
} else {
ql_dbg(ql_dbg_user, vha, 0x7038,
"Vendor request 84xx updatefw completed.\n");
bsg_job->reply_len = sizeof(struct fc_bsg_reply);
bsg_reply->result = DID_OK;
}
dma_pool_free(ha->s_dma_pool, mn, mn_dma);
done_free_fw_buf:
dma_free_coherent(&ha->pdev->dev, data_len, fw_buf, fw_dma);
done_unmap_sg:
dma_unmap_sg(&ha->pdev->dev, bsg_job->request_payload.sg_list,
bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
if (!rval)
bsg_job_done(bsg_job, bsg_reply->result,
bsg_reply->reply_payload_rcv_len);
return rval;
}
static int
qla84xx_mgmt_cmd(bsg_job_t *bsg_job)
{
struct fc_bsg_request *bsg_request = bsg_job->request;
struct fc_bsg_reply *bsg_reply = bsg_job->reply;
struct Scsi_Host *host = fc_bsg_to_shost(bsg_job);
scsi_qla_host_t *vha = shost_priv(host);
struct qla_hw_data *ha = vha->hw;
struct access_chip_84xx *mn = NULL;
dma_addr_t mn_dma, mgmt_dma;
void *mgmt_b = NULL;
int rval = 0;
struct qla_bsg_a84_mgmt *ql84_mgmt;
uint32_t sg_cnt;
uint32_t data_len = 0;
uint32_t dma_direction = DMA_NONE;
if (!IS_QLA84XX(ha)) {
ql_log(ql_log_warn, vha, 0x703a,
"Not 84xx, exiting.\n");
return -EINVAL;
}
mn = dma_pool_zalloc(ha->s_dma_pool, GFP_KERNEL, &mn_dma);
if (!mn) {
ql_log(ql_log_warn, vha, 0x703c,
"DMA alloc failed for fw buffer.\n");
return -ENOMEM;
}
mn->entry_type = ACCESS_CHIP_IOCB_TYPE;
mn->entry_count = 1;
ql84_mgmt = (void *)bsg_request + sizeof(struct fc_bsg_request);
switch (ql84_mgmt->mgmt.cmd) {
case QLA84_MGMT_READ_MEM:
case QLA84_MGMT_GET_INFO:
sg_cnt = dma_map_sg(&ha->pdev->dev,
bsg_job->reply_payload.sg_list,
bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
if (!sg_cnt) {
ql_log(ql_log_warn, vha, 0x703d,
"dma_map_sg returned %d for reply.\n", sg_cnt);
rval = -ENOMEM;
goto exit_mgmt;
}
dma_direction = DMA_FROM_DEVICE;
if (sg_cnt != bsg_job->reply_payload.sg_cnt) {
ql_log(ql_log_warn, vha, 0x703e,
"DMA mapping resulted in different sg counts, "
"reply_sg_cnt: %x dma_reply_sg_cnt: %x.\n",
bsg_job->reply_payload.sg_cnt, sg_cnt);
rval = -EAGAIN;
goto done_unmap_sg;
}
data_len = bsg_job->reply_payload.payload_len;
mgmt_b = dma_alloc_coherent(&ha->pdev->dev, data_len,
&mgmt_dma, GFP_KERNEL);
if (!mgmt_b) {
ql_log(ql_log_warn, vha, 0x703f,
"DMA alloc failed for mgmt_b.\n");
rval = -ENOMEM;
goto done_unmap_sg;
}
if (ql84_mgmt->mgmt.cmd == QLA84_MGMT_READ_MEM) {
mn->options = cpu_to_le16(ACO_DUMP_MEMORY);
mn->parameter1 =
cpu_to_le32(
ql84_mgmt->mgmt.mgmtp.u.mem.start_addr);
} else if (ql84_mgmt->mgmt.cmd == QLA84_MGMT_GET_INFO) {
mn->options = cpu_to_le16(ACO_REQUEST_INFO);
mn->parameter1 =
cpu_to_le32(ql84_mgmt->mgmt.mgmtp.u.info.type);
mn->parameter2 =
cpu_to_le32(
ql84_mgmt->mgmt.mgmtp.u.info.context);
}
break;
case QLA84_MGMT_WRITE_MEM:
sg_cnt = dma_map_sg(&ha->pdev->dev,
bsg_job->request_payload.sg_list,
bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
if (!sg_cnt) {
ql_log(ql_log_warn, vha, 0x7040,
"dma_map_sg returned %d.\n", sg_cnt);
rval = -ENOMEM;
goto exit_mgmt;
}
dma_direction = DMA_TO_DEVICE;
if (sg_cnt != bsg_job->request_payload.sg_cnt) {
ql_log(ql_log_warn, vha, 0x7041,
"DMA mapping resulted in different sg counts, "
"request_sg_cnt: %x dma_request_sg_cnt: %x.\n",
bsg_job->request_payload.sg_cnt, sg_cnt);
rval = -EAGAIN;
goto done_unmap_sg;
}
data_len = bsg_job->request_payload.payload_len;
mgmt_b = dma_alloc_coherent(&ha->pdev->dev, data_len,
&mgmt_dma, GFP_KERNEL);
if (!mgmt_b) {
ql_log(ql_log_warn, vha, 0x7042,
"DMA alloc failed for mgmt_b.\n");
rval = -ENOMEM;
goto done_unmap_sg;
}
sg_copy_to_buffer(bsg_job->request_payload.sg_list,
bsg_job->request_payload.sg_cnt, mgmt_b, data_len);
mn->options = cpu_to_le16(ACO_LOAD_MEMORY);
mn->parameter1 =
cpu_to_le32(ql84_mgmt->mgmt.mgmtp.u.mem.start_addr);
break;
case QLA84_MGMT_CHNG_CONFIG:
mn->options = cpu_to_le16(ACO_CHANGE_CONFIG_PARAM);
mn->parameter1 =
cpu_to_le32(ql84_mgmt->mgmt.mgmtp.u.config.id);
mn->parameter2 =
cpu_to_le32(ql84_mgmt->mgmt.mgmtp.u.config.param0);
mn->parameter3 =
cpu_to_le32(ql84_mgmt->mgmt.mgmtp.u.config.param1);
break;
default:
rval = -EIO;
goto exit_mgmt;
}
if (ql84_mgmt->mgmt.cmd != QLA84_MGMT_CHNG_CONFIG) {
mn->total_byte_cnt = cpu_to_le32(ql84_mgmt->mgmt.len);
mn->dseg_count = cpu_to_le16(1);
put_unaligned_le64(mgmt_dma, &mn->dsd.address);
mn->dsd.length = cpu_to_le32(ql84_mgmt->mgmt.len);
}
rval = qla2x00_issue_iocb(vha, mn, mn_dma, 0);
if (rval) {
ql_log(ql_log_warn, vha, 0x7043,
"Vendor request 84xx mgmt failed.\n");
rval = (DID_ERROR << 16);
} else {
ql_dbg(ql_dbg_user, vha, 0x7044,
"Vendor request 84xx mgmt completed.\n");
bsg_job->reply_len = sizeof(struct fc_bsg_reply);
bsg_reply->result = DID_OK;
if ((ql84_mgmt->mgmt.cmd == QLA84_MGMT_READ_MEM) ||
(ql84_mgmt->mgmt.cmd == QLA84_MGMT_GET_INFO)) {
bsg_reply->reply_payload_rcv_len =
bsg_job->reply_payload.payload_len;
sg_copy_from_buffer(bsg_job->reply_payload.sg_list,
bsg_job->reply_payload.sg_cnt, mgmt_b,
data_len);
}
}
done_unmap_sg:
if (mgmt_b)
dma_free_coherent(&ha->pdev->dev, data_len, mgmt_b, mgmt_dma);
if (dma_direction == DMA_TO_DEVICE)
dma_unmap_sg(&ha->pdev->dev, bsg_job->request_payload.sg_list,
bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
else if (dma_direction == DMA_FROM_DEVICE)
dma_unmap_sg(&ha->pdev->dev, bsg_job->reply_payload.sg_list,
bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
exit_mgmt:
dma_pool_free(ha->s_dma_pool, mn, mn_dma);
if (!rval)
bsg_job_done(bsg_job, bsg_reply->result,
bsg_reply->reply_payload_rcv_len);
return rval;
}
static int
qla24xx_iidma(bsg_job_t *bsg_job)
{
struct fc_bsg_request *bsg_request = bsg_job->request;
struct fc_bsg_reply *bsg_reply = bsg_job->reply;
struct Scsi_Host *host = fc_bsg_to_shost(bsg_job);
scsi_qla_host_t *vha = shost_priv(host);
int rval = 0;
struct qla_port_param *port_param = NULL;
fc_port_t *fcport = NULL;
int found = 0;
uint16_t mb[MAILBOX_REGISTER_COUNT];
uint8_t *rsp_ptr = NULL;
if (!IS_IIDMA_CAPABLE(vha->hw)) {
ql_log(ql_log_info, vha, 0x7046, "iiDMA not supported.\n");
return -EINVAL;
}
port_param = (void *)bsg_request + sizeof(struct fc_bsg_request);
if (port_param->fc_scsi_addr.dest_type != EXT_DEF_TYPE_WWPN) {
ql_log(ql_log_warn, vha, 0x7048,
"Invalid destination type.\n");
return -EINVAL;
}
list_for_each_entry(fcport, &vha->vp_fcports, list) {
if (fcport->port_type != FCT_TARGET)
continue;
if (memcmp(port_param->fc_scsi_addr.dest_addr.wwpn,
fcport->port_name, sizeof(fcport->port_name)))
continue;
found = 1;
break;
}
if (!found) {
ql_log(ql_log_warn, vha, 0x7049,
"Failed to find port.\n");
return -EINVAL;
}
if (atomic_read(&fcport->state) != FCS_ONLINE) {
ql_log(ql_log_warn, vha, 0x704a,
"Port is not online.\n");
return -EINVAL;
}
if (fcport->flags & FCF_LOGIN_NEEDED) {
ql_log(ql_log_warn, vha, 0x704b,
"Remote port not logged in flags = 0x%x.\n", fcport->flags);
return -EINVAL;
}
if (port_param->mode)
rval = qla2x00_set_idma_speed(vha, fcport->loop_id,
port_param->speed, mb);
else
rval = qla2x00_get_idma_speed(vha, fcport->loop_id,
&port_param->speed, mb);
if (rval) {
ql_log(ql_log_warn, vha, 0x704c,
"iiDMA cmd failed for %8phN -- "
"%04x %x %04x %04x.\n", fcport->port_name,
rval, fcport->fp_speed, mb[0], mb[1]);
rval = (DID_ERROR << 16);
} else {
if (!port_param->mode) {
bsg_job->reply_len = sizeof(struct fc_bsg_reply) +
sizeof(struct qla_port_param);
rsp_ptr = ((uint8_t *)bsg_reply) +
sizeof(struct fc_bsg_reply);
memcpy(rsp_ptr, port_param,
sizeof(struct qla_port_param));
}
bsg_reply->result = DID_OK;
bsg_job_done(bsg_job, bsg_reply->result,
bsg_reply->reply_payload_rcv_len);
}
return rval;
}
static int
qla2x00_optrom_setup(bsg_job_t *bsg_job, scsi_qla_host_t *vha,
uint8_t is_update)
{
struct fc_bsg_request *bsg_request = bsg_job->request;
uint32_t start = 0;
int valid = 0;
struct qla_hw_data *ha = vha->hw;
if (unlikely(pci_channel_offline(ha->pdev)))
return -EINVAL;
start = bsg_request->rqst_data.h_vendor.vendor_cmd[1];
if (start > ha->optrom_size) {
ql_log(ql_log_warn, vha, 0x7055,
"start %d > optrom_size %d.\n", start, ha->optrom_size);
return -EINVAL;
}
if (ha->optrom_state != QLA_SWAITING) {
ql_log(ql_log_info, vha, 0x7056,
"optrom_state %d.\n", ha->optrom_state);
return -EBUSY;
}
ha->optrom_region_start = start;
ql_dbg(ql_dbg_user, vha, 0x7057, "is_update=%d.\n", is_update);
if (is_update) {
if (ha->optrom_size == OPTROM_SIZE_2300 && start == 0)
valid = 1;
else if (start == (ha->flt_region_boot * 4) ||
start == (ha->flt_region_fw * 4))
valid = 1;
else if (IS_QLA24XX_TYPE(ha) || IS_QLA25XX(ha) ||
IS_CNA_CAPABLE(ha) || IS_QLA2031(ha) || IS_QLA27XX(ha) ||
IS_QLA28XX(ha))
valid = 1;
if (!valid) {
ql_log(ql_log_warn, vha, 0x7058,
"Invalid start region 0x%x/0x%x.\n", start,
bsg_job->request_payload.payload_len);
return -EINVAL;
}
ha->optrom_region_size = start +
bsg_job->request_payload.payload_len > ha->optrom_size ?
ha->optrom_size - start :
bsg_job->request_payload.payload_len;
ha->optrom_state = QLA_SWRITING;
} else {
ha->optrom_region_size = start +
bsg_job->reply_payload.payload_len > ha->optrom_size ?
ha->optrom_size - start :
bsg_job->reply_payload.payload_len;
ha->optrom_state = QLA_SREADING;
}
ha->optrom_buffer = vzalloc(ha->optrom_region_size);
if (!ha->optrom_buffer) {
ql_log(ql_log_warn, vha, 0x7059,
"Read: Unable to allocate memory for optrom retrieval "
"(%x)\n", ha->optrom_region_size);
ha->optrom_state = QLA_SWAITING;
return -ENOMEM;
}
return 0;
}
static int
qla2x00_read_optrom(bsg_job_t *bsg_job)
{
struct fc_bsg_reply *bsg_reply = bsg_job->reply;
struct Scsi_Host *host = fc_bsg_to_shost(bsg_job);
scsi_qla_host_t *vha = shost_priv(host);
struct qla_hw_data *ha = vha->hw;
int rval = 0;
if (ha->flags.nic_core_reset_hdlr_active)
return -EBUSY;
mutex_lock(&ha->optrom_mutex);
rval = qla2x00_optrom_setup(bsg_job, vha, 0);
if (rval) {
mutex_unlock(&ha->optrom_mutex);
return rval;
}
ha->isp_ops->read_optrom(vha, ha->optrom_buffer,
ha->optrom_region_start, ha->optrom_region_size);
sg_copy_from_buffer(bsg_job->reply_payload.sg_list,
bsg_job->reply_payload.sg_cnt, ha->optrom_buffer,
ha->optrom_region_size);
bsg_reply->reply_payload_rcv_len = ha->optrom_region_size;
bsg_reply->result = DID_OK;
vfree(ha->optrom_buffer);
ha->optrom_buffer = NULL;
ha->optrom_state = QLA_SWAITING;
mutex_unlock(&ha->optrom_mutex);
bsg_job_done(bsg_job, bsg_reply->result,
bsg_reply->reply_payload_rcv_len);
return rval;
}
static int
qla2x00_update_optrom(bsg_job_t *bsg_job)
{
struct fc_bsg_reply *bsg_reply = bsg_job->reply;
struct Scsi_Host *host = fc_bsg_to_shost(bsg_job);
scsi_qla_host_t *vha = shost_priv(host);
struct qla_hw_data *ha = vha->hw;
int rval = 0;
mutex_lock(&ha->optrom_mutex);
rval = qla2x00_optrom_setup(bsg_job, vha, 1);
if (rval) {
mutex_unlock(&ha->optrom_mutex);
return rval;
}
/* Set the isp82xx_no_md_cap not to capture minidump */
ha->flags.isp82xx_no_md_cap = 1;
sg_copy_to_buffer(bsg_job->request_payload.sg_list,
bsg_job->request_payload.sg_cnt, ha->optrom_buffer,
ha->optrom_region_size);
rval = ha->isp_ops->write_optrom(vha, ha->optrom_buffer,
ha->optrom_region_start, ha->optrom_region_size);
if (rval) {
if (rval == QLA_FLASH_LOCKDOWN) {
bsg_reply->reply_data.vendor_reply.vendor_rsp[0] =
EXT_STATUS_ADAPTER_IN_LOCKDOWN_MODE;
bsg_reply->result = DID_OK;
rval = QLA_SUCCESS;
} else {
bsg_reply->result = -EINVAL;
rval = -EINVAL;
}
} else {
bsg_reply->result = DID_OK;
bsg_reply->reply_data.vendor_reply.vendor_rsp[0] =
EXT_STATUS_OK;
}
vfree(ha->optrom_buffer);
ha->optrom_buffer = NULL;
ha->optrom_state = QLA_SWAITING;
mutex_unlock(&ha->optrom_mutex);
bsg_job->reply_len = sizeof(struct fc_bsg_reply);
bsg_job_done(bsg_job, bsg_reply->result,
bsg_reply->reply_payload_rcv_len);
return rval;
}
static int
qla2x00_update_fru_versions(bsg_job_t *bsg_job)
{
struct fc_bsg_reply *bsg_reply = bsg_job->reply;
struct Scsi_Host *host = fc_bsg_to_shost(bsg_job);
scsi_qla_host_t *vha = shost_priv(host);
struct qla_hw_data *ha = vha->hw;
int rval = 0;
uint8_t bsg[DMA_POOL_SIZE];
struct qla_image_version_list *list = (void *)bsg;
struct qla_image_version *image;
uint32_t count;
dma_addr_t sfp_dma;
void *sfp = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &sfp_dma);
if (!sfp) {
bsg_reply->reply_data.vendor_reply.vendor_rsp[0] =
EXT_STATUS_NO_MEMORY;
goto done;
}
sg_copy_to_buffer(bsg_job->request_payload.sg_list,
bsg_job->request_payload.sg_cnt, list, sizeof(bsg));
image = list->version;
count = list->count;
while (count--) {
memcpy(sfp, &image->field_info, sizeof(image->field_info));
rval = qla2x00_write_sfp(vha, sfp_dma, sfp,
image->field_address.device, image->field_address.offset,
sizeof(image->field_info), image->field_address.option);
if (rval) {
bsg_reply->reply_data.vendor_reply.vendor_rsp[0] =
EXT_STATUS_MAILBOX;
goto dealloc;
}
image++;
}
bsg_reply->reply_data.vendor_reply.vendor_rsp[0] = 0;
dealloc:
dma_pool_free(ha->s_dma_pool, sfp, sfp_dma);
done:
bsg_job->reply_len = sizeof(struct fc_bsg_reply);
bsg_reply->result = DID_OK << 16;
bsg_job_done(bsg_job, bsg_reply->result,
bsg_reply->reply_payload_rcv_len);
return 0;
}
static int
qla2x00_read_fru_status(bsg_job_t *bsg_job)
{
struct fc_bsg_reply *bsg_reply = bsg_job->reply;
struct Scsi_Host *host = fc_bsg_to_shost(bsg_job);
scsi_qla_host_t *vha = shost_priv(host);
struct qla_hw_data *ha = vha->hw;
int rval = 0;
uint8_t bsg[DMA_POOL_SIZE];
struct qla_status_reg *sr = (void *)bsg;
dma_addr_t sfp_dma;
uint8_t *sfp = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &sfp_dma);
if (!sfp) {
bsg_reply->reply_data.vendor_reply.vendor_rsp[0] =
EXT_STATUS_NO_MEMORY;
goto done;
}
sg_copy_to_buffer(bsg_job->request_payload.sg_list,
bsg_job->request_payload.sg_cnt, sr, sizeof(*sr));
rval = qla2x00_read_sfp(vha, sfp_dma, sfp,
sr->field_address.device, sr->field_address.offset,
sizeof(sr->status_reg), sr->field_address.option);
sr->status_reg = *sfp;
if (rval) {
bsg_reply->reply_data.vendor_reply.vendor_rsp[0] =
EXT_STATUS_MAILBOX;
goto dealloc;
}
sg_copy_from_buffer(bsg_job->reply_payload.sg_list,
bsg_job->reply_payload.sg_cnt, sr, sizeof(*sr));
bsg_reply->reply_data.vendor_reply.vendor_rsp[0] = 0;
dealloc:
dma_pool_free(ha->s_dma_pool, sfp, sfp_dma);
done:
bsg_job->reply_len = sizeof(struct fc_bsg_reply);
bsg_reply->reply_payload_rcv_len = sizeof(*sr);
bsg_reply->result = DID_OK << 16;
bsg_job_done(bsg_job, bsg_reply->result,
bsg_reply->reply_payload_rcv_len);
return 0;
}
static int
qla2x00_write_fru_status(bsg_job_t *bsg_job)
{
struct fc_bsg_reply *bsg_reply = bsg_job->reply;
struct Scsi_Host *host = fc_bsg_to_shost(bsg_job);
scsi_qla_host_t *vha = shost_priv(host);
struct qla_hw_data *ha = vha->hw;
int rval = 0;
uint8_t bsg[DMA_POOL_SIZE];
struct qla_status_reg *sr = (void *)bsg;
dma_addr_t sfp_dma;
uint8_t *sfp = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &sfp_dma);
if (!sfp) {
bsg_reply->reply_data.vendor_reply.vendor_rsp[0] =
EXT_STATUS_NO_MEMORY;
goto done;
}
sg_copy_to_buffer(bsg_job->request_payload.sg_list,
bsg_job->request_payload.sg_cnt, sr, sizeof(*sr));
*sfp = sr->status_reg;
rval = qla2x00_write_sfp(vha, sfp_dma, sfp,
sr->field_address.device, sr->field_address.offset,
sizeof(sr->status_reg), sr->field_address.option);
if (rval) {
bsg_reply->reply_data.vendor_reply.vendor_rsp[0] =
EXT_STATUS_MAILBOX;
goto dealloc;
}
bsg_reply->reply_data.vendor_reply.vendor_rsp[0] = 0;
dealloc:
dma_pool_free(ha->s_dma_pool, sfp, sfp_dma);
done:
bsg_job->reply_len = sizeof(struct fc_bsg_reply);
bsg_reply->result = DID_OK << 16;
bsg_job_done(bsg_job, bsg_reply->result,
bsg_reply->reply_payload_rcv_len);
return 0;
}
static int
qla2x00_write_i2c(bsg_job_t *bsg_job)
{
struct fc_bsg_reply *bsg_reply = bsg_job->reply;
struct Scsi_Host *host = fc_bsg_to_shost(bsg_job);
scsi_qla_host_t *vha = shost_priv(host);
struct qla_hw_data *ha = vha->hw;
int rval = 0;
uint8_t bsg[DMA_POOL_SIZE];
struct qla_i2c_access *i2c = (void *)bsg;
dma_addr_t sfp_dma;
uint8_t *sfp = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &sfp_dma);
if (!sfp) {
bsg_reply->reply_data.vendor_reply.vendor_rsp[0] =
EXT_STATUS_NO_MEMORY;
goto done;
}
sg_copy_to_buffer(bsg_job->request_payload.sg_list,
bsg_job->request_payload.sg_cnt, i2c, sizeof(*i2c));
memcpy(sfp, i2c->buffer, i2c->length);
rval = qla2x00_write_sfp(vha, sfp_dma, sfp,
i2c->device, i2c->offset, i2c->length, i2c->option);
if (rval) {
bsg_reply->reply_data.vendor_reply.vendor_rsp[0] =
EXT_STATUS_MAILBOX;
goto dealloc;
}
bsg_reply->reply_data.vendor_reply.vendor_rsp[0] = 0;
dealloc:
dma_pool_free(ha->s_dma_pool, sfp, sfp_dma);
done:
bsg_job->reply_len = sizeof(struct fc_bsg_reply);
bsg_reply->result = DID_OK << 16;
bsg_job_done(bsg_job, bsg_reply->result,
bsg_reply->reply_payload_rcv_len);
return 0;
}
static int
qla2x00_read_i2c(bsg_job_t *bsg_job)
{
struct fc_bsg_reply *bsg_reply = bsg_job->reply;
struct Scsi_Host *host = fc_bsg_to_shost(bsg_job);
scsi_qla_host_t *vha = shost_priv(host);
struct qla_hw_data *ha = vha->hw;
int rval = 0;
uint8_t bsg[DMA_POOL_SIZE];
struct qla_i2c_access *i2c = (void *)bsg;
dma_addr_t sfp_dma;
uint8_t *sfp = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &sfp_dma);
if (!sfp) {
bsg_reply->reply_data.vendor_reply.vendor_rsp[0] =
EXT_STATUS_NO_MEMORY;
goto done;
}
sg_copy_to_buffer(bsg_job->request_payload.sg_list,
bsg_job->request_payload.sg_cnt, i2c, sizeof(*i2c));
rval = qla2x00_read_sfp(vha, sfp_dma, sfp,
i2c->device, i2c->offset, i2c->length, i2c->option);
if (rval) {
bsg_reply->reply_data.vendor_reply.vendor_rsp[0] =
EXT_STATUS_MAILBOX;
goto dealloc;
}
memcpy(i2c->buffer, sfp, i2c->length);
sg_copy_from_buffer(bsg_job->reply_payload.sg_list,
bsg_job->reply_payload.sg_cnt, i2c, sizeof(*i2c));
bsg_reply->reply_data.vendor_reply.vendor_rsp[0] = 0;
dealloc:
dma_pool_free(ha->s_dma_pool, sfp, sfp_dma);
done:
bsg_job->reply_len = sizeof(struct fc_bsg_reply);
bsg_reply->reply_payload_rcv_len = sizeof(*i2c);
bsg_reply->result = DID_OK << 16;
bsg_job_done(bsg_job, bsg_reply->result,
bsg_reply->reply_payload_rcv_len);
return 0;
}
static int
qla24xx_process_bidir_cmd(bsg_job_t *bsg_job)
{
struct fc_bsg_reply *bsg_reply = bsg_job->reply;
struct Scsi_Host *host = fc_bsg_to_shost(bsg_job);
scsi_qla_host_t *vha = shost_priv(host);
struct qla_hw_data *ha = vha->hw;
uint32_t rval = EXT_STATUS_OK;
uint16_t req_sg_cnt = 0;
uint16_t rsp_sg_cnt = 0;
uint16_t nextlid = 0;
uint32_t tot_dsds;
srb_t *sp = NULL;
uint32_t req_data_len;
uint32_t rsp_data_len;
/* Check the type of the adapter */
if (!IS_BIDI_CAPABLE(ha)) {
ql_log(ql_log_warn, vha, 0x70a0,
"This adapter is not supported\n");
rval = EXT_STATUS_NOT_SUPPORTED;
goto done;
}
if (test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags) ||
test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags) ||
test_bit(ISP_ABORT_RETRY, &vha->dpc_flags)) {
rval = EXT_STATUS_BUSY;
goto done;
}
/* Check if host is online */
if (!vha->flags.online) {
ql_log(ql_log_warn, vha, 0x70a1,
"Host is not online\n");
rval = EXT_STATUS_DEVICE_OFFLINE;
goto done;
}
/* Check if cable is plugged in or not */
if (vha->device_flags & DFLG_NO_CABLE) {
ql_log(ql_log_warn, vha, 0x70a2,
"Cable is unplugged...\n");
rval = EXT_STATUS_INVALID_CFG;
goto done;
}
/* Check if the switch is connected or not */
if (ha->current_topology != ISP_CFG_F) {
ql_log(ql_log_warn, vha, 0x70a3,
"Host is not connected to the switch\n");
rval = EXT_STATUS_INVALID_CFG;
goto done;
}
/* Check if operating mode is P2P */
if (ha->operating_mode != P2P) {
ql_log(ql_log_warn, vha, 0x70a4,
"Host operating mode is not P2p\n");
rval = EXT_STATUS_INVALID_CFG;
goto done;
}
mutex_lock(&ha->selflogin_lock);
if (vha->self_login_loop_id == 0) {
/* Initialize all required fields of fcport */
vha->bidir_fcport.vha = vha;
vha->bidir_fcport.d_id.b.al_pa = vha->d_id.b.al_pa;
vha->bidir_fcport.d_id.b.area = vha->d_id.b.area;
vha->bidir_fcport.d_id.b.domain = vha->d_id.b.domain;
vha->bidir_fcport.loop_id = vha->loop_id;
if (qla2x00_fabric_login(vha, &(vha->bidir_fcport), &nextlid)) {
ql_log(ql_log_warn, vha, 0x70a7,
"Failed to login port %06X for bidirectional IOCB\n",
vha->bidir_fcport.d_id.b24);
mutex_unlock(&ha->selflogin_lock);
rval = EXT_STATUS_MAILBOX;
goto done;
}
vha->self_login_loop_id = nextlid - 1;
}
/* Assign the self login loop id to fcport */
mutex_unlock(&ha->selflogin_lock);
vha->bidir_fcport.loop_id = vha->self_login_loop_id;
req_sg_cnt = dma_map_sg(&ha->pdev->dev,
bsg_job->request_payload.sg_list,
bsg_job->request_payload.sg_cnt,
DMA_TO_DEVICE);
if (!req_sg_cnt) {
rval = EXT_STATUS_NO_MEMORY;
goto done;
}
rsp_sg_cnt = dma_map_sg(&ha->pdev->dev,
bsg_job->reply_payload.sg_list, bsg_job->reply_payload.sg_cnt,
DMA_FROM_DEVICE);
if (!rsp_sg_cnt) {
rval = EXT_STATUS_NO_MEMORY;
goto done_unmap_req_sg;
}
if ((req_sg_cnt != bsg_job->request_payload.sg_cnt) ||
(rsp_sg_cnt != bsg_job->reply_payload.sg_cnt)) {
ql_dbg(ql_dbg_user, vha, 0x70a9,
"Dma mapping resulted in different sg counts "
"[request_sg_cnt: %x dma_request_sg_cnt: %x reply_sg_cnt: "
"%x dma_reply_sg_cnt: %x]\n",
bsg_job->request_payload.sg_cnt, req_sg_cnt,
bsg_job->reply_payload.sg_cnt, rsp_sg_cnt);
rval = EXT_STATUS_NO_MEMORY;
goto done_unmap_sg;
}
req_data_len = bsg_job->request_payload.payload_len;
rsp_data_len = bsg_job->reply_payload.payload_len;
if (req_data_len != rsp_data_len) {
rval = EXT_STATUS_BUSY;
ql_log(ql_log_warn, vha, 0x70aa,
"req_data_len != rsp_data_len\n");
goto done_unmap_sg;
}
/* Alloc SRB structure */
sp = qla2x00_get_sp(vha, &(vha->bidir_fcport), GFP_KERNEL);
if (!sp) {
ql_dbg(ql_dbg_user, vha, 0x70ac,
"Alloc SRB structure failed\n");
rval = EXT_STATUS_NO_MEMORY;
goto done_unmap_sg;
}
/*Populate srb->ctx with bidir ctx*/
sp->u.bsg_job = bsg_job;
sp->free = qla2x00_bsg_sp_free;
sp->type = SRB_BIDI_CMD;
sp->done = qla2x00_bsg_job_done;
/* Add the read and write sg count */
tot_dsds = rsp_sg_cnt + req_sg_cnt;
rval = qla2x00_start_bidir(sp, vha, tot_dsds);
if (rval != EXT_STATUS_OK)
goto done_free_srb;
/* the bsg request will be completed in the interrupt handler */
return rval;
done_free_srb:
mempool_free(sp, ha->srb_mempool);
done_unmap_sg:
dma_unmap_sg(&ha->pdev->dev,
bsg_job->reply_payload.sg_list,
bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
done_unmap_req_sg:
dma_unmap_sg(&ha->pdev->dev,
bsg_job->request_payload.sg_list,
bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
done:
/* Return an error vendor specific response
* and complete the bsg request
*/
bsg_reply->reply_data.vendor_reply.vendor_rsp[0] = rval;
bsg_job->reply_len = sizeof(struct fc_bsg_reply);
bsg_reply->reply_payload_rcv_len = 0;
bsg_reply->result = (DID_OK) << 16;
bsg_job_done(bsg_job, bsg_reply->result,
bsg_reply->reply_payload_rcv_len);
/* Always return success, vendor rsp carries correct status */
return 0;
}
static int
qlafx00_mgmt_cmd(bsg_job_t *bsg_job)
{
struct fc_bsg_request *bsg_request = bsg_job->request;
struct Scsi_Host *host = fc_bsg_to_shost(bsg_job);
scsi_qla_host_t *vha = shost_priv(host);
struct qla_hw_data *ha = vha->hw;
int rval = (DID_ERROR << 16);
struct qla_mt_iocb_rqst_fx00 *piocb_rqst;
srb_t *sp;
int req_sg_cnt = 0, rsp_sg_cnt = 0;
struct fc_port *fcport;
char *type = "FC_BSG_HST_FX_MGMT";
/* Copy the IOCB specific information */
piocb_rqst = (struct qla_mt_iocb_rqst_fx00 *)
&bsg_request->rqst_data.h_vendor.vendor_cmd[1];
/* Dump the vendor information */
ql_dump_buffer(ql_dbg_user + ql_dbg_verbose , vha, 0x70cf,
piocb_rqst, sizeof(*piocb_rqst));
if (!vha->flags.online) {
ql_log(ql_log_warn, vha, 0x70d0,
"Host is not online.\n");
rval = -EIO;
goto done;
}
if (piocb_rqst->flags & SRB_FXDISC_REQ_DMA_VALID) {
req_sg_cnt = dma_map_sg(&ha->pdev->dev,
bsg_job->request_payload.sg_list,
bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
if (!req_sg_cnt) {
ql_log(ql_log_warn, vha, 0x70c7,
"dma_map_sg return %d for request\n", req_sg_cnt);
rval = -ENOMEM;
goto done;
}
}
if (piocb_rqst->flags & SRB_FXDISC_RESP_DMA_VALID) {
rsp_sg_cnt = dma_map_sg(&ha->pdev->dev,
bsg_job->reply_payload.sg_list,
bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
if (!rsp_sg_cnt) {
ql_log(ql_log_warn, vha, 0x70c8,
"dma_map_sg return %d for reply\n", rsp_sg_cnt);
rval = -ENOMEM;
goto done_unmap_req_sg;
}
}
ql_dbg(ql_dbg_user, vha, 0x70c9,
"request_sg_cnt: %x dma_request_sg_cnt: %x reply_sg_cnt:%x "
"dma_reply_sg_cnt: %x\n", bsg_job->request_payload.sg_cnt,
req_sg_cnt, bsg_job->reply_payload.sg_cnt, rsp_sg_cnt);
/* Allocate a dummy fcport structure, since functions preparing the
* IOCB and mailbox command retrieves port specific information
* from fcport structure. For Host based ELS commands there will be
* no fcport structure allocated
*/
fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
if (!fcport) {
ql_log(ql_log_warn, vha, 0x70ca,
"Failed to allocate fcport.\n");
rval = -ENOMEM;
goto done_unmap_rsp_sg;
}
/* Alloc SRB structure */
sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
if (!sp) {
ql_log(ql_log_warn, vha, 0x70cb,
"qla2x00_get_sp failed.\n");
rval = -ENOMEM;
goto done_free_fcport;
}
/* Initialize all required fields of fcport */
fcport->vha = vha;
fcport->loop_id = piocb_rqst->dataword;
sp->type = SRB_FXIOCB_BCMD;
sp->name = "bsg_fx_mgmt";
sp->iocbs = qla24xx_calc_ct_iocbs(req_sg_cnt + rsp_sg_cnt);
sp->u.bsg_job = bsg_job;
sp->free = qla2x00_bsg_sp_free;
sp->done = qla2x00_bsg_job_done;
ql_dbg(ql_dbg_user, vha, 0x70cc,
"bsg rqst type: %s fx_mgmt_type: %x id=%x\n",
type, piocb_rqst->func_type, fcport->loop_id);
rval = qla2x00_start_sp(sp);
if (rval != QLA_SUCCESS) {
ql_log(ql_log_warn, vha, 0x70cd,
"qla2x00_start_sp failed=%d.\n", rval);
mempool_free(sp, ha->srb_mempool);
rval = -EIO;
goto done_free_fcport;
}
return rval;
done_free_fcport:
qla2x00_free_fcport(fcport);
done_unmap_rsp_sg:
if (piocb_rqst->flags & SRB_FXDISC_RESP_DMA_VALID)
dma_unmap_sg(&ha->pdev->dev,
bsg_job->reply_payload.sg_list,
bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
done_unmap_req_sg:
if (piocb_rqst->flags & SRB_FXDISC_REQ_DMA_VALID)
dma_unmap_sg(&ha->pdev->dev,
bsg_job->request_payload.sg_list,
bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
done:
return rval;
}
static int
qla26xx_serdes_op(bsg_job_t *bsg_job)
{
struct fc_bsg_reply *bsg_reply = bsg_job->reply;
struct Scsi_Host *host = fc_bsg_to_shost(bsg_job);
scsi_qla_host_t *vha = shost_priv(host);
int rval = 0;
struct qla_serdes_reg sr;
memset(&sr, 0, sizeof(sr));
sg_copy_to_buffer(bsg_job->request_payload.sg_list,
bsg_job->request_payload.sg_cnt, &sr, sizeof(sr));
switch (sr.cmd) {
case INT_SC_SERDES_WRITE_REG:
rval = qla2x00_write_serdes_word(vha, sr.addr, sr.val);
bsg_reply->reply_payload_rcv_len = 0;
break;
case INT_SC_SERDES_READ_REG:
rval = qla2x00_read_serdes_word(vha, sr.addr, &sr.val);
sg_copy_from_buffer(bsg_job->reply_payload.sg_list,
bsg_job->reply_payload.sg_cnt, &sr, sizeof(sr));
bsg_reply->reply_payload_rcv_len = sizeof(sr);
break;
default:
ql_dbg(ql_dbg_user, vha, 0x708c,
"Unknown serdes cmd %x.\n", sr.cmd);
rval = -EINVAL;
break;
}
bsg_reply->reply_data.vendor_reply.vendor_rsp[0] =
rval ? EXT_STATUS_MAILBOX : 0;
bsg_job->reply_len = sizeof(struct fc_bsg_reply);
bsg_reply->result = DID_OK << 16;
bsg_job_done(bsg_job, bsg_reply->result,
bsg_reply->reply_payload_rcv_len);
return 0;
}
static int
qla8044_serdes_op(bsg_job_t *bsg_job)
{
struct fc_bsg_reply *bsg_reply = bsg_job->reply;
struct Scsi_Host *host = fc_bsg_to_shost(bsg_job);
scsi_qla_host_t *vha = shost_priv(host);
int rval = 0;
struct qla_serdes_reg_ex sr;
memset(&sr, 0, sizeof(sr));
sg_copy_to_buffer(bsg_job->request_payload.sg_list,
bsg_job->request_payload.sg_cnt, &sr, sizeof(sr));
switch (sr.cmd) {
case INT_SC_SERDES_WRITE_REG:
rval = qla8044_write_serdes_word(vha, sr.addr, sr.val);
bsg_reply->reply_payload_rcv_len = 0;
break;
case INT_SC_SERDES_READ_REG:
rval = qla8044_read_serdes_word(vha, sr.addr, &sr.val);
sg_copy_from_buffer(bsg_job->reply_payload.sg_list,
bsg_job->reply_payload.sg_cnt, &sr, sizeof(sr));
bsg_reply->reply_payload_rcv_len = sizeof(sr);
break;
default:
ql_dbg(ql_dbg_user, vha, 0x7020,
"Unknown serdes cmd %x.\n", sr.cmd);
rval = -EINVAL;
break;
}
bsg_reply->reply_data.vendor_reply.vendor_rsp[0] =
rval ? EXT_STATUS_MAILBOX : 0;
bsg_job->reply_len = sizeof(struct fc_bsg_reply);
bsg_reply->result = DID_OK << 16;
bsg_job_done(bsg_job, bsg_reply->result,
bsg_reply->reply_payload_rcv_len);
return 0;
}
static int
qla27xx_get_flash_upd_cap(bsg_job_t *bsg_job)
{
struct fc_bsg_reply *bsg_reply = bsg_job->reply;
struct Scsi_Host *host = fc_bsg_to_shost(bsg_job);
scsi_qla_host_t *vha = shost_priv(host);
struct qla_hw_data *ha = vha->hw;
struct qla_flash_update_caps cap;
if (!(IS_QLA27XX(ha)) && !IS_QLA28XX(ha))
return -EPERM;
memset(&cap, 0, sizeof(cap));
cap.capabilities = (uint64_t)ha->fw_attributes_ext[1] << 48 |
(uint64_t)ha->fw_attributes_ext[0] << 32 |
(uint64_t)ha->fw_attributes_h << 16 |
(uint64_t)ha->fw_attributes;
sg_copy_from_buffer(bsg_job->reply_payload.sg_list,
bsg_job->reply_payload.sg_cnt, &cap, sizeof(cap));
bsg_reply->reply_payload_rcv_len = sizeof(cap);
bsg_reply->reply_data.vendor_reply.vendor_rsp[0] =
EXT_STATUS_OK;
bsg_job->reply_len = sizeof(struct fc_bsg_reply);
bsg_reply->result = DID_OK << 16;
bsg_job_done(bsg_job, bsg_reply->result,
bsg_reply->reply_payload_rcv_len);
return 0;
}
static int
qla27xx_set_flash_upd_cap(bsg_job_t *bsg_job)
{
struct fc_bsg_reply *bsg_reply = bsg_job->reply;
struct Scsi_Host *host = fc_bsg_to_shost(bsg_job);
scsi_qla_host_t *vha = shost_priv(host);
struct qla_hw_data *ha = vha->hw;
uint64_t online_fw_attr = 0;
struct qla_flash_update_caps cap;
if (!IS_QLA27XX(ha) && !IS_QLA28XX(ha))
return -EPERM;
memset(&cap, 0, sizeof(cap));
sg_copy_to_buffer(bsg_job->request_payload.sg_list,
bsg_job->request_payload.sg_cnt, &cap, sizeof(cap));
online_fw_attr = (uint64_t)ha->fw_attributes_ext[1] << 48 |
(uint64_t)ha->fw_attributes_ext[0] << 32 |
(uint64_t)ha->fw_attributes_h << 16 |
(uint64_t)ha->fw_attributes;
if (online_fw_attr != cap.capabilities) {
bsg_reply->reply_data.vendor_reply.vendor_rsp[0] =
EXT_STATUS_INVALID_PARAM;
return -EINVAL;
}
if (cap.outage_duration < MAX_LOOP_TIMEOUT) {
bsg_reply->reply_data.vendor_reply.vendor_rsp[0] =
EXT_STATUS_INVALID_PARAM;
return -EINVAL;
}
bsg_reply->reply_payload_rcv_len = 0;
bsg_reply->reply_data.vendor_reply.vendor_rsp[0] =
EXT_STATUS_OK;
bsg_job->reply_len = sizeof(struct fc_bsg_reply);
bsg_reply->result = DID_OK << 16;
bsg_job_done(bsg_job, bsg_reply->result,
bsg_reply->reply_payload_rcv_len);
return 0;
}
static int
qla27xx_get_bbcr_data(bsg_job_t *bsg_job)
{
struct fc_bsg_reply *bsg_reply = bsg_job->reply;
struct Scsi_Host *host = fc_bsg_to_shost(bsg_job);
scsi_qla_host_t *vha = shost_priv(host);
struct qla_hw_data *ha = vha->hw;
struct qla_bbcr_data bbcr;
uint16_t loop_id, topo, sw_cap;
uint8_t domain, area, al_pa, state;
int rval;
if (!IS_QLA27XX(ha) && !IS_QLA28XX(ha))
return -EPERM;
memset(&bbcr, 0, sizeof(bbcr));
if (vha->flags.bbcr_enable)
bbcr.status = QLA_BBCR_STATUS_ENABLED;
else
bbcr.status = QLA_BBCR_STATUS_DISABLED;
if (bbcr.status == QLA_BBCR_STATUS_ENABLED) {
rval = qla2x00_get_adapter_id(vha, &loop_id, &al_pa,
&area, &domain, &topo, &sw_cap);
if (rval != QLA_SUCCESS) {
bbcr.status = QLA_BBCR_STATUS_UNKNOWN;
bbcr.state = QLA_BBCR_STATE_OFFLINE;
bbcr.mbx1 = loop_id;
goto done;
}
state = (vha->bbcr >> 12) & 0x1;
if (state) {
bbcr.state = QLA_BBCR_STATE_OFFLINE;
bbcr.offline_reason_code = QLA_BBCR_REASON_LOGIN_REJECT;
} else {
bbcr.state = QLA_BBCR_STATE_ONLINE;
bbcr.negotiated_bbscn = (vha->bbcr >> 8) & 0xf;
}
bbcr.configured_bbscn = vha->bbcr & 0xf;
}
done:
sg_copy_from_buffer(bsg_job->reply_payload.sg_list,
bsg_job->reply_payload.sg_cnt, &bbcr, sizeof(bbcr));
bsg_reply->reply_payload_rcv_len = sizeof(bbcr);
bsg_reply->reply_data.vendor_reply.vendor_rsp[0] = EXT_STATUS_OK;
bsg_job->reply_len = sizeof(struct fc_bsg_reply);
bsg_reply->result = DID_OK << 16;
bsg_job_done(bsg_job, bsg_reply->result,
bsg_reply->reply_payload_rcv_len);
return 0;
}
static int
qla2x00_get_priv_stats(bsg_job_t *bsg_job)
{
struct fc_bsg_request *bsg_request = bsg_job->request;
struct fc_bsg_reply *bsg_reply = bsg_job->reply;
struct Scsi_Host *host = fc_bsg_to_shost(bsg_job);
scsi_qla_host_t *vha = shost_priv(host);
struct qla_hw_data *ha = vha->hw;
struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
struct link_statistics *stats = NULL;
dma_addr_t stats_dma;
int rval;
uint32_t *cmd = bsg_request->rqst_data.h_vendor.vendor_cmd;
uint options = cmd[0] == QL_VND_GET_PRIV_STATS_EX ? cmd[1] : 0;
if (test_bit(UNLOADING, &vha->dpc_flags))
return -ENODEV;
if (unlikely(pci_channel_offline(ha->pdev)))
return -ENODEV;
if (qla2x00_reset_active(vha))
return -EBUSY;
if (!IS_FWI2_CAPABLE(ha))
return -EPERM;
stats = dma_alloc_coherent(&ha->pdev->dev, sizeof(*stats), &stats_dma,
GFP_KERNEL);
if (!stats) {
ql_log(ql_log_warn, vha, 0x70e2,
"Failed to allocate memory for stats.\n");
return -ENOMEM;
}
rval = qla24xx_get_isp_stats(base_vha, stats, stats_dma, options);
if (rval == QLA_SUCCESS) {
ql_dump_buffer(ql_dbg_user + ql_dbg_verbose, vha, 0x70e5,
stats, sizeof(*stats));
sg_copy_from_buffer(bsg_job->reply_payload.sg_list,
bsg_job->reply_payload.sg_cnt, stats, sizeof(*stats));
}
bsg_reply->reply_payload_rcv_len = sizeof(*stats);
bsg_reply->reply_data.vendor_reply.vendor_rsp[0] =
rval ? EXT_STATUS_MAILBOX : EXT_STATUS_OK;
bsg_job->reply_len = sizeof(*bsg_reply);
bsg_reply->result = DID_OK << 16;
bsg_job_done(bsg_job, bsg_reply->result,
bsg_reply->reply_payload_rcv_len);
dma_free_coherent(&ha->pdev->dev, sizeof(*stats),
stats, stats_dma);
return 0;
}
static int
qla2x00_do_dport_diagnostics(bsg_job_t *bsg_job)
{
struct fc_bsg_reply *bsg_reply = bsg_job->reply;
struct Scsi_Host *host = fc_bsg_to_shost(bsg_job);
scsi_qla_host_t *vha = shost_priv(host);
int rval;
struct qla_dport_diag *dd;
if (!IS_QLA83XX(vha->hw) && !IS_QLA27XX(vha->hw) &&
!IS_QLA28XX(vha->hw))
return -EPERM;
dd = kmalloc(sizeof(*dd), GFP_KERNEL);
if (!dd) {
ql_log(ql_log_warn, vha, 0x70db,
"Failed to allocate memory for dport.\n");
return -ENOMEM;
}
sg_copy_to_buffer(bsg_job->request_payload.sg_list,
bsg_job->request_payload.sg_cnt, dd, sizeof(*dd));
rval = qla26xx_dport_diagnostics(
vha, dd->buf, sizeof(dd->buf), dd->options);
if (rval == QLA_SUCCESS) {
sg_copy_from_buffer(bsg_job->reply_payload.sg_list,
bsg_job->reply_payload.sg_cnt, dd, sizeof(*dd));
}
bsg_reply->reply_payload_rcv_len = sizeof(*dd);
bsg_reply->reply_data.vendor_reply.vendor_rsp[0] =
rval ? EXT_STATUS_MAILBOX : EXT_STATUS_OK;
bsg_job->reply_len = sizeof(*bsg_reply);
bsg_reply->result = DID_OK << 16;
bsg_job_done(bsg_job, bsg_reply->result,
bsg_reply->reply_payload_rcv_len);
kfree(dd);
return 0;
}
static int
qla2x00_do_dport_diagnostics_v2(bsg_job_t *bsg_job)
{
struct fc_bsg_reply *bsg_reply = bsg_job->reply;
struct Scsi_Host *host = fc_bsg_to_shost(bsg_job);
scsi_qla_host_t *vha = shost_priv(host);
int rval;
struct qla_dport_diag_v2 *dd;
mbx_cmd_t mc;
mbx_cmd_t *mcp = &mc;
uint16_t options;
if (!IS_DPORT_CAPABLE(vha->hw))
return -EPERM;
dd = kzalloc(sizeof(*dd), GFP_KERNEL);
if (!dd)
return -ENOMEM;
sg_copy_to_buffer(bsg_job->request_payload.sg_list,
bsg_job->request_payload.sg_cnt, dd, sizeof(*dd));
options = dd->options;
/* Check dport Test in progress */
if ((QLA_GET_DPORT_RESULT_V2 == options) &&
(DPORT_DIAG_IN_PROGRESS & vha->dport_status)) {
bsg_reply->reply_data.vendor_reply.vendor_rsp[0] =
EXT_STATUS_DPORT_DIAG_IN_PROCESS;
goto dportcomplete;
}
/* Check chip reset in progress and start/restart requests arrive */
if ((DPORT_DIAG_CHIP_RESET_IN_PROGRESS & vha->dport_status) &&
((QLA_START_DPORT_TEST_V2 == options) ||
(QLA_RESTART_DPORT_TEST_V2 == options))) {
vha->dport_status &= ~DPORT_DIAG_CHIP_RESET_IN_PROGRESS;
}
/* Check chip reset in progress and get result request arrive */
if ((DPORT_DIAG_CHIP_RESET_IN_PROGRESS & vha->dport_status) &&
(QLA_GET_DPORT_RESULT_V2 == options)) {
bsg_reply->reply_data.vendor_reply.vendor_rsp[0] =
EXT_STATUS_DPORT_DIAG_NOT_RUNNING;
goto dportcomplete;
}
rval = qla26xx_dport_diagnostics_v2(vha, dd, mcp);
if (QLA_SUCCESS == rval) {
bsg_reply->reply_data.vendor_reply.vendor_rsp[0] =
EXT_STATUS_OK;
if (QLA_START_DPORT_TEST_V2 == options ||
QLA_RESTART_DPORT_TEST_V2 == options) {
dd->mbx1 = mcp->mb[0];
dd->mbx2 = mcp->mb[1];
vha->dport_status |= DPORT_DIAG_IN_PROGRESS;
} else if (QLA_GET_DPORT_RESULT_V2 == options) {
dd->mbx1 = vha->dport_data[1];
dd->mbx2 = vha->dport_data[2];
}
} else {
dd->mbx1 = mcp->mb[0];
dd->mbx2 = mcp->mb[1];
bsg_reply->reply_data.vendor_reply.vendor_rsp[0] =
EXT_STATUS_DPORT_DIAG_ERR;
}
dportcomplete:
sg_copy_from_buffer(bsg_job->reply_payload.sg_list,
bsg_job->reply_payload.sg_cnt, dd, sizeof(*dd));
bsg_reply->reply_payload_rcv_len = sizeof(*dd);
bsg_job->reply_len = sizeof(*bsg_reply);
bsg_reply->result = DID_OK << 16;
bsg_job_done(bsg_job, bsg_reply->result,
bsg_reply->reply_payload_rcv_len);
kfree(dd);
return 0;
}
static int
qla2x00_get_flash_image_status(bsg_job_t *bsg_job)
{
scsi_qla_host_t *vha = shost_priv(fc_bsg_to_shost(bsg_job));
struct fc_bsg_reply *bsg_reply = bsg_job->reply;
struct qla_hw_data *ha = vha->hw;
struct qla_active_regions regions = { };
struct active_regions active_regions = { };
qla27xx_get_active_image(vha, &active_regions);
regions.global_image = active_regions.global;
if (IS_QLA27XX(ha))
regions.nvme_params = QLA27XX_PRIMARY_IMAGE;
if (IS_QLA28XX(ha)) {
qla28xx_get_aux_images(vha, &active_regions);
regions.board_config = active_regions.aux.board_config;
regions.vpd_nvram = active_regions.aux.vpd_nvram;
regions.npiv_config_0_1 = active_regions.aux.npiv_config_0_1;
regions.npiv_config_2_3 = active_regions.aux.npiv_config_2_3;
regions.nvme_params = active_regions.aux.nvme_params;
}
ql_dbg(ql_dbg_user, vha, 0x70e1,
"%s(%lu): FW=%u BCFG=%u VPDNVR=%u NPIV01=%u NPIV02=%u NVME_PARAMS=%u\n",
__func__, vha->host_no, regions.global_image,
regions.board_config, regions.vpd_nvram,
regions.npiv_config_0_1, regions.npiv_config_2_3, regions.nvme_params);
sg_copy_from_buffer(bsg_job->reply_payload.sg_list,
bsg_job->reply_payload.sg_cnt, &regions, sizeof(regions));
bsg_reply->reply_data.vendor_reply.vendor_rsp[0] = EXT_STATUS_OK;
bsg_reply->reply_payload_rcv_len = sizeof(regions);
bsg_reply->result = DID_OK << 16;
bsg_job->reply_len = sizeof(struct fc_bsg_reply);
bsg_job_done(bsg_job, bsg_reply->result,
bsg_reply->reply_payload_rcv_len);
return 0;
}
static int
qla2x00_get_drv_attr(bsg_job_t *bsg_job)
{
struct qla_drv_attr drv_attr;
struct fc_bsg_reply *bsg_reply = bsg_job->reply;
memset(&drv_attr, 0, sizeof(struct qla_drv_attr));
/* Additional check should be added if SCM is not enabled
* by default for a given driver version.
*/
drv_attr.attributes |= QLA_DRV_ATTR_SCM_SUPPORTED;
drv_attr.attributes |= QLA_DRV_ATTR_SCM_2_SUPPORTED;
drv_attr.attributes |= QLA_DRV_ATTR_LOCKDOWN_SUPPORT;
drv_attr.attributes |= QLA_DRV_ATTR_SCMR_PROFILE_SUPPORT;
drv_attr.attributes |= QLA_DRV_ATTR_DPORT_V2_SUPPORT;
drv_attr.attributes |= QLA_DRV_ATTR_VIRTUAL_LANE_SUPPORT;
drv_attr.attributes |= QLA_DRV_ATTR_IO_THROTTLING_SUPPORT;
sg_copy_from_buffer(bsg_job->reply_payload.sg_list,
bsg_job->reply_payload.sg_cnt, &drv_attr,
sizeof(struct qla_drv_attr));
bsg_reply->reply_payload_rcv_len = sizeof(struct qla_drv_attr);
bsg_reply->reply_data.vendor_reply.vendor_rsp[0] = EXT_STATUS_OK;
bsg_job->reply_len = sizeof(*bsg_job->reply);
bsg_reply->result = DID_OK << 16;
bsg_job_done(bsg_job, bsg_reply->result, bsg_reply->reply_payload_rcv_len);
return 0;
}
static int
qla2x00_get_port_scm(bsg_job_t *bsg_job)
{
struct Scsi_Host *shost = fc_bsg_to_shost(bsg_job);
scsi_qla_host_t *vha = shost_priv(shost);
struct qla_hw_data *ha = vha->hw;
struct fc_bsg_reply *bsg_reply = bsg_job->reply;
struct qla_scm_port *scm_stats;
if (!IS_QLA27XX(ha) && !IS_QLA28XX(ha))
return -EPERM;
scm_stats = kzalloc(sizeof(struct qla_scm_port), GFP_KERNEL);
if (scm_stats == NULL) {
ql_log(ql_log_warn, vha, 0x7024,
"Failed to allocate memory for host scm stats.\n");
return -ENOMEM;
}
scm_stats->current_events = ha->scm.current_events;
memcpy(&scm_stats->link_integrity, &ha->scm.link_integrity,
(sizeof(struct qla_scm_link_event)));
memcpy(&scm_stats->delivery, &ha->scm.delivery,
(sizeof(struct qla_scm_delivery_event)));
memcpy(&scm_stats->congestion, &ha->scm.congestion,
(sizeof(struct qla_scm_congestion_event)));
scm_stats->scm_congestion_alarm = ha->scm.sev.cn_alarm;
scm_stats->scm_congestion_warning = ha->scm.sev.cn_warning;
scm_stats->scm_fabric_connection_flags =
ha->scm.scm_fabric_connection_flags;
sg_copy_from_buffer(bsg_job->reply_payload.sg_list,
bsg_job->reply_payload.sg_cnt, scm_stats, sizeof(struct qla_scm_port));
bsg_reply->reply_payload_rcv_len = sizeof(struct qla_scm_port);
bsg_reply->reply_data.vendor_reply.vendor_rsp[0] = EXT_STATUS_OK;
bsg_job->reply_len = sizeof(*bsg_job->reply);
bsg_reply->result = DID_OK << 16;
bsg_job_done(bsg_job, bsg_reply->result, bsg_reply->reply_payload_rcv_len);
kfree(scm_stats);
return 0;
}
static int
qla2x00_get_port_scm_v2(bsg_job_t *bsg_job)
{
struct Scsi_Host *shost = fc_bsg_to_shost(bsg_job);
scsi_qla_host_t *vha = shost_priv(shost);
struct qla_hw_data *ha = vha->hw;
struct fc_bsg_reply *bsg_reply = bsg_job->reply;
struct qla_scm_port_v2 *scm_stats;
if (!IS_QLA27XX(ha) && !IS_QLA28XX(ha))
return -EPERM;
scm_stats = kzalloc(sizeof(struct qla_scm_port_v2), GFP_KERNEL);
if (scm_stats == NULL) {
ql_log(ql_log_warn, vha, 0x7024,
"Failed to allocate memory for host scm stats.\n");
return -ENOMEM;
}
memcpy(&scm_stats->stats, &ha->scm.stats,
(sizeof(struct qla_scm_stats)));
memcpy(&scm_stats->rstats, &ha->scm.rstats,
(sizeof(struct qla_scmr_stats)));
scm_stats->scm_fabric_connection_flags =
ha->scm.scm_fabric_connection_flags;
/* For V2 */
if (qla_scmr_is_congested(&ha->sfc)) {
scm_stats->current_state = SCM_STATE_CONGESTED;
} else {
scm_stats->current_state = SCM_STATE_HEALTHY;
}
memcpy(&scm_stats->sev, &ha->scm.sev,
(sizeof(struct qla_fpin_severity)));
scm_stats->scm_events = ha->scm.current_events;
scm_stats->secs_since_last_event = qla_get_real_seconds() -
ha->scm.last_event_timestamp;
if (ha->flags.scm_supported_vl == 0)
scm_stats->vl_mode = QLA_VL_MODE_DISABLED;
else { /* VL is enabled, check if it is negotiated */
if (ha->flags.conn_fabric_cisco_er_rdy)
scm_stats->vl_mode = QLA_VL_MODE_OPERATIONAL;
else
scm_stats->vl_mode = QLA_VL_MODE_NON_OPERATIONAL;
}
scm_stats->io_throttling = qla_get_throttling_state(&ha->sfc);
sg_copy_from_buffer(bsg_job->reply_payload.sg_list,
bsg_job->reply_payload.sg_cnt, scm_stats,
sizeof(struct qla_scm_port_v2));
bsg_reply->reply_payload_rcv_len = sizeof(struct qla_scm_port_v2);
bsg_reply->reply_data.vendor_reply.vendor_rsp[0] = EXT_STATUS_OK;
bsg_job->reply_len = sizeof(*bsg_job->reply);
bsg_reply->result = DID_OK << 16;
bsg_job_done(bsg_job, bsg_reply->result, bsg_reply->reply_payload_rcv_len);
kfree(scm_stats);
return 0;
}
static int
qla2x00_get_target_scm(bsg_job_t *bsg_job)
{
struct Scsi_Host *shost = fc_bsg_to_shost(bsg_job);
scsi_qla_host_t *vha = shost_priv(shost);
struct fc_bsg_reply *bsg_reply = bsg_job->reply;
struct qla_hw_data *ha = vha->hw;
fc_port_t *fcport = NULL;
int rval;
struct qla_scm_target *scm_stats = NULL;
if (!IS_QLA27XX(ha) && !IS_QLA28XX(ha))
return -EPERM;
scm_stats = kzalloc(sizeof(struct qla_scm_target), GFP_KERNEL);
if (scm_stats == NULL) {
ql_log(ql_log_warn, vha, 0x7024,
"Failed to allocate memory for target scm stats.\n");
return -ENOMEM;
}
sg_copy_to_buffer(bsg_job->request_payload.sg_list,
bsg_job->request_payload.sg_cnt, scm_stats,
sizeof(struct qla_scm_target));
fcport = qla2x00_find_fcport_by_wwpn(vha, scm_stats->wwpn, 0);
if (!fcport) {
rval = EXT_STATUS_ERR;
goto complete;
}
/* Copy SCM Target data to local struct, keep WWPN from user */
scm_stats->current_events = fcport->scm.current_events;
memcpy(&scm_stats->link_integrity, &fcport->scm.link_integrity,
(sizeof(struct qla_scm_link_event)));
memcpy(&scm_stats->delivery, &fcport->scm.delivery,
(sizeof(struct qla_scm_delivery_event)));
memcpy(&scm_stats->peer_congestion, &fcport->scm.peer_congestion,
(sizeof(struct qla_scm_peer_congestion_event)));
/* TODO: Destination stats are u32 */
scm_stats->link_unknown_event = fcport->scm.stats.li_failure_unknown;
scm_stats->link_failure_count = fcport->scm.stats.li_link_failure_count;
scm_stats->loss_of_sync_count =
fcport->scm.stats.li_loss_of_sync_count;
scm_stats->loss_of_signals_count =
fcport->scm.stats.li_loss_of_signals_count;
scm_stats->primitive_seq_protocol_err_count =
fcport->scm.stats.li_prim_seq_err_count;
scm_stats->invalid_transmission_word_count =
fcport->scm.stats.li_invalid_tx_word_count;
scm_stats->invalid_crc_count = fcport->scm.stats.li_invalid_crc_count;
scm_stats->link_device_specific_event =
fcport->scm.stats.li_device_specific;
scm_stats->delivery_failure_unknown = fcport->scm.stats.dn_unknown;
scm_stats->delivery_timeout = fcport->scm.stats.dn_timeout;
scm_stats->delivery_unable_to_route =
fcport->scm.stats.dn_unable_to_route;
scm_stats->delivery_failure_device_specific =
fcport->scm.stats.dn_device_specific;
scm_stats->peer_congestion_clear = fcport->scm.stats.cn_clear;
scm_stats->peer_congestion_lost_credit =
fcport->scm.stats.cn_lost_credit;
scm_stats->peer_congestion_credit_stall =
fcport->scm.stats.cn_credit_stall;
scm_stats->peer_congestion_oversubscription =
fcport->scm.stats.cn_oversubscription;
scm_stats->peer_congestion_device_specific =
fcport->scm.stats.cn_device_specific;
sg_copy_from_buffer(bsg_job->reply_payload.sg_list,
bsg_job->reply_payload.sg_cnt, scm_stats,
sizeof(struct qla_scm_target));
rval = EXT_STATUS_OK;
complete:
bsg_reply->reply_payload_rcv_len = sizeof(struct qla_scm_target);
bsg_reply->reply_data.vendor_reply.vendor_rsp[0] = rval;
bsg_job->reply_len = sizeof(*bsg_job->reply);
bsg_reply->result = DID_OK << 16;
bsg_job_done(bsg_job, bsg_reply->result,
bsg_reply->reply_payload_rcv_len);
kfree(scm_stats);
return 0;
}
static int
qla2x00_get_target_scm_v2(bsg_job_t *bsg_job)
{
struct Scsi_Host *shost = fc_bsg_to_shost(bsg_job);
scsi_qla_host_t *vha = shost_priv(shost);
struct fc_bsg_reply *bsg_reply = bsg_job->reply;
struct qla_hw_data *ha = vha->hw;
fc_port_t *fcport = NULL;
int rval;
struct qla_scm_target_v2 *scm_stats = NULL;
if (!IS_QLA27XX(ha) && !IS_QLA28XX(ha))
return -EPERM;
scm_stats = kzalloc(sizeof(struct qla_scm_target_v2), GFP_KERNEL);
if (scm_stats == NULL) {
ql_log(ql_log_warn, vha, 0x7024,
"Failed to allocate memory for target scm stats.\n");
return -ENOMEM;
}
sg_copy_to_buffer(bsg_job->request_payload.sg_list,
bsg_job->request_payload.sg_cnt, scm_stats,
sizeof(struct qla_scm_target_v2));
fcport = qla2x00_find_fcport_by_wwpn(vha, scm_stats->wwpn, 0);
if (!fcport) {
rval = EXT_STATUS_ERR;
goto complete;
}
/* Copy SCM Target data to local struct, keep WWPN from user */
memcpy(&scm_stats->stats, &fcport->scm.stats,
(sizeof(struct qla_scm_stats)));
memcpy(&scm_stats->rstats, &fcport->scm.rstats,
(sizeof(struct qla_scmr_stats)));
if (qla_scmr_is_congested(&fcport->sfc))
scm_stats->current_state = SCM_STATE_CONGESTED;
else
scm_stats->current_state = SCM_STATE_HEALTHY;
scm_stats->scm_events = fcport->scm.current_events;
scm_stats->secs_since_last_event = qla_get_real_seconds() -
fcport->scm.last_event_timestamp;
if (ha->flags.conn_fabric_cisco_er_rdy) {
switch (fcport->vl.v_lane) {
case VL_SLOW:
scm_stats->vl_state = QLA_VL_STATE_SLOW;
break;
case VL_NORMAL:
scm_stats->vl_state = QLA_VL_STATE_NORMAL;
break;
case VL_FAST:
scm_stats->vl_state = QLA_VL_STATE_FAST;
break;
}
} else
scm_stats->vl_state = QLA_VL_STATE_DISABLED;
scm_stats->io_throttling = qla_get_throttling_state(&fcport->sfc);
sg_copy_from_buffer(bsg_job->reply_payload.sg_list,
bsg_job->reply_payload.sg_cnt, scm_stats,
sizeof(struct qla_scm_target_v2));
rval = EXT_STATUS_OK;
complete:
bsg_reply->reply_payload_rcv_len = sizeof(struct qla_scm_target_v2);
bsg_reply->reply_data.vendor_reply.vendor_rsp[0] = rval;
bsg_job->reply_len = sizeof(*bsg_job->reply);
bsg_reply->result = DID_OK << 16;
bsg_job_done(bsg_job, bsg_reply->result,
bsg_reply->reply_payload_rcv_len);
kfree(scm_stats);
return 0;
}
DECLARE_ENUM2STR_LOOKUP(qla_get_profile_type, ql_scm_profile_type,
QL_SCM_PROFILE_TYPES_INIT);
static int
qla2x00_bidi_scm_mgmt(bsg_job_t *bsg_job)
{
struct Scsi_Host *shost = fc_bsg_to_shost(bsg_job);
scsi_qla_host_t *vha = shost_priv(shost);
struct fc_bsg_reply *bsg_reply = bsg_job->reply;
struct qla_hw_data *ha = vha->hw;
struct qla_scm_host_config *scm_config = NULL;
fc_port_t *fcport;
if (!IS_QLA27XX(ha) && !IS_QLA28XX(ha))
return -EPERM;
scm_config = kzalloc(sizeof(struct qla_scm_host_config), GFP_KERNEL);
if (scm_config == NULL) {
ql_log(ql_log_warn, vha, 0x7024,
"Failed to allocate memory for host scm config.\n");
return -ENOMEM;
}
sg_copy_to_buffer(bsg_job->request_payload.sg_list,
bsg_job->request_payload.sg_cnt, scm_config,
sizeof(struct qla_scm_host_config));
if (scm_config->controls & QLA_RESET_SCM_STATS) {
ql_log(ql_log_info, vha, 0x709b, "Clearing USCM stats\n");
qla2xxx_clear_scm_stats(vha);
}
if (scm_config->controls & QLA_RESET_SCMR_STATS) {
ql_log(ql_log_info, vha, 0x709c, "Clearing USCM throttling stats\n");
qla2xxx_clear_scmr_stats(vha);
}
/* Update the SCMR profile */
if (scm_config->controls & QLA_APPLY_SCMR_PROFILE) {
ql_log(ql_log_info, vha, 0x709d, "Changing SCMR profile from %s to %s\n",
qla_get_profile_type(ha->sfc.profile.scmr_profile),
qla_get_profile_type(scm_config->profile.scmr_profile));
memcpy(&ha->sfc.profile, &scm_config->profile,
(sizeof(struct qla_scmr_port_profile)));
list_for_each_entry(fcport, &vha->vp_fcports, list) {
if (!(fcport->port_type & FCT_TARGET) &&
!(fcport->port_type & FCT_NVME_TARGET))
continue;
memcpy(&fcport->sfc.profile, &scm_config->profile,
(sizeof(struct qla_scmr_port_profile)));
}
if (scm_config->profile.scmr_control_flags == 0) {
/* Restore driver defaults */
ha->sfc.profile.scmr_profile = ql2x_scmr_profile;
list_for_each_entry(fcport, &vha->vp_fcports, list) {
if (!(fcport->port_type & FCT_TARGET) &&
!(fcport->port_type & FCT_NVME_TARGET))
continue;
fcport->sfc.profile.scmr_profile = ql2x_scmr_profile;
}
ql_dbg(ql_dbg_user, vha, 0x709e,
"SCM profile restored to driver defaults, New Profile: %s\n",
qla_get_profile_type(ha->sfc.profile.scmr_profile));
}
if (ha->sfc.profile.scmr_profile == 0) {/* Monitor profile */
qla2xxx_scmr_clear_throttle(&ha->sfc);
list_for_each_entry(fcport, &vha->vp_fcports, list) {
if (!(fcport->port_type & FCT_TARGET) &&
!(fcport->port_type & FCT_NVME_TARGET))
continue;
qla2xxx_scmr_clear_throttle(&fcport->sfc);
if (vha->hw->flags.conn_fabric_cisco_er_rdy) {// VL
if (!qla_scmr_is_congested(&fcport->sfc))
qla2xxx_switch_vl(&fcport->sfc, VL_NORMAL);
}
}
}
}
/* Provide the in-use SCMR profile */
if (scm_config->controls & QLA_GET_SCMR_PROFILE) {
memcpy(&scm_config->profile, &ha->sfc.profile,
(sizeof(struct qla_scmr_port_profile)));
sg_copy_from_buffer(bsg_job->reply_payload.sg_list,
bsg_job->reply_payload.sg_cnt, scm_config,
sizeof(struct qla_scm_host_config));
bsg_reply->reply_payload_rcv_len =
sizeof(struct qla_scm_host_config);
bsg_reply->reply_data.vendor_reply.vendor_rsp[0] =
EXT_STATUS_OK;
bsg_job->reply_len = sizeof(*bsg_job->reply);
bsg_reply->result = DID_OK << 16;
bsg_job_done(bsg_job, bsg_reply->result,
bsg_reply->reply_payload_rcv_len);
return 0;
}
bsg_reply->reply_payload_rcv_len = 0;
bsg_reply->reply_data.vendor_reply.vendor_rsp[0] = EXT_STATUS_OK;
bsg_job->reply_len = sizeof(*bsg_job->reply);
bsg_reply->result = DID_OK << 16;
bsg_job_done(bsg_job, bsg_reply->result,
bsg_reply->reply_payload_rcv_len);
return 0;
}
static int
qla2x00_manage_host_stats(bsg_job_t *bsg_job)
{
scsi_qla_host_t *vha = shost_priv(fc_bsg_to_shost(bsg_job));
struct fc_bsg_reply *bsg_reply = bsg_job->reply;
struct ql_vnd_mng_host_stats_param *req_data;
struct ql_vnd_mng_host_stats_resp rsp_data;
uint32_t req_data_len;
int ret = 0;
if (!vha->flags.online) {
ql_log(ql_log_warn, vha, 0x0000, "Host is not online.\n");
return -EIO;
}
req_data_len = bsg_job->request_payload.payload_len;
if (req_data_len != sizeof(struct ql_vnd_mng_host_stats_param)) {
ql_log(ql_log_warn, vha, 0x0000, "req_data_len invalid.\n");
return -EIO;
}
req_data = kzalloc(sizeof(struct ql_vnd_mng_host_stats_param), GFP_KERNEL);
if (!req_data) {
ql_log(ql_log_warn, vha, 0x0000, "req_data memory allocation failure.\n");
return -ENOMEM;
}
/* Copy the request buffer in req_data */
sg_copy_to_buffer(bsg_job->request_payload.sg_list,
bsg_job->request_payload.sg_cnt, req_data, req_data_len);
switch (req_data->action) {
case stop:
ret = qla2xxx_stop_stats(vha->host, req_data->stat_type);
break;
case start:
ret = qla2xxx_start_stats(vha->host, req_data->stat_type);
break;
case clear:
ret = qla2xxx_reset_stats(vha->host, req_data->stat_type);
break;
default:
ql_log(ql_log_warn, vha, 0x0000, "Invalid action.\n");
ret = -EIO;
break;
}
kfree(req_data);
/* Prepare response */
rsp_data.status = ret;
bsg_job->reply_payload.payload_len = sizeof(struct ql_vnd_mng_host_stats_resp);
bsg_reply->reply_data.vendor_reply.vendor_rsp[0] = EXT_STATUS_OK;
bsg_reply->reply_payload_rcv_len = sg_copy_from_buffer(bsg_job->reply_payload.sg_list,
bsg_job->reply_payload.sg_cnt, &rsp_data,
sizeof(struct ql_vnd_mng_host_stats_resp));
bsg_reply->result = DID_OK;
bsg_job_done(bsg_job, bsg_reply->result,
bsg_reply->reply_payload_rcv_len);
return ret;
}
static int
qla2x00_get_host_stats(bsg_job_t *bsg_job)
{
scsi_qla_host_t *vha = shost_priv(fc_bsg_to_shost(bsg_job));
struct fc_bsg_reply *bsg_reply = bsg_job->reply;
struct ql_vnd_stats_param *req_data;
struct ql_vnd_host_stats_resp rsp_data;
uint32_t req_data_len;
int ret = 0;
uint64_t ini_entry_count = 0;
uint64_t entry_count = 0;
uint64_t tgt_num = 0;
uint64_t tmp_stat_type = 0;
uint64_t response_len = 0;
void *data;
req_data_len = bsg_job->request_payload.payload_len;
if (req_data_len != sizeof(struct ql_vnd_stats_param)) {
ql_log(ql_log_warn, vha, 0x0000, "req_data_len invalid.\n");
return -EIO;
}
req_data = kzalloc(sizeof(struct ql_vnd_stats_param), GFP_KERNEL);
if (!req_data) {
ql_log(ql_log_warn, vha, 0x0000, "req_data memory allocation failure.\n");
return -ENOMEM;
}
/* Copy the request buffer in req_data */
sg_copy_to_buffer(bsg_job->request_payload.sg_list,
bsg_job->request_payload.sg_cnt, req_data, req_data_len);
/* Copy stat type to work on it */
tmp_stat_type = req_data->stat_type;
if (tmp_stat_type & QLA2XX_TGT_SHT_LNK_DOWN)
{
/* Num of tgts connected to this host */
tgt_num = qla2x00_get_num_tgts(vha);
/* unset BIT_17 */
tmp_stat_type &= ~ (1 << 17);
}
/* Total ini stats */
ini_entry_count = qla2x00_count_set_bits(tmp_stat_type);
/* Total number of entries */
entry_count = ini_entry_count + tgt_num;
response_len = sizeof(struct ql_vnd_host_stats_resp) +
(sizeof(struct ql_vnd_stat_entry) * entry_count);
if (response_len > bsg_job->reply_payload.payload_len) {
rsp_data.status = EXT_STATUS_BUFFER_TOO_SMALL;
bsg_reply->reply_data.vendor_reply.vendor_rsp[0] = EXT_STATUS_BUFFER_TOO_SMALL;
bsg_job->reply_payload.payload_len = sizeof(struct ql_vnd_mng_host_stats_resp);
bsg_reply->reply_payload_rcv_len = sg_copy_from_buffer(bsg_job->reply_payload.sg_list,
bsg_job->reply_payload.sg_cnt, &rsp_data,
sizeof(struct ql_vnd_mng_host_stats_resp));
bsg_reply->result = DID_OK;
bsg_job_done(bsg_job, bsg_reply->result,
bsg_reply->reply_payload_rcv_len);
goto host_stat_out;
}
data = kzalloc(response_len, GFP_KERNEL);
ret = qla2xxx_get_ini_stats(fc_bsg_to_shost(bsg_job), req_data->stat_type,
data, response_len);
rsp_data.status = EXT_STATUS_OK;
bsg_reply->reply_data.vendor_reply.vendor_rsp[0] = EXT_STATUS_OK;
bsg_reply->reply_payload_rcv_len = sg_copy_from_buffer(bsg_job->reply_payload.sg_list,
bsg_job->reply_payload.sg_cnt, data,
response_len);
bsg_reply->result = DID_OK;
bsg_job_done(bsg_job, bsg_reply->result,
bsg_reply->reply_payload_rcv_len);
kfree(data);
host_stat_out:
kfree(req_data);
return 0;
}
static struct fc_rport *
qla2xxx_find_rport(scsi_qla_host_t *vha, uint32_t tgt_num)
{
fc_port_t *fcport = NULL;
list_for_each_entry(fcport, &vha->vp_fcports, list) {
if (fcport->rport->number == tgt_num)
return fcport->rport;
}
return NULL;
}
static int
qla2x00_get_tgt_stats(bsg_job_t *bsg_job)
{
scsi_qla_host_t *vha = shost_priv(fc_bsg_to_shost(bsg_job));
struct fc_bsg_reply *bsg_reply = bsg_job->reply;
struct ql_vnd_tgt_stats_param *req_data;
uint32_t req_data_len;
int ret = 0;
uint64_t response_len = 0;
struct ql_vnd_tgt_stats_resp *data = NULL;
struct fc_rport *rport = NULL;
if (!vha->flags.online) {
ql_log(ql_log_warn, vha, 0x0000, "Host is not online.\n");
return -EIO;
}
req_data_len = bsg_job->request_payload.payload_len;
if (req_data_len != sizeof(struct ql_vnd_stat_entry)) {
ql_log(ql_log_warn, vha, 0x0000, "req_data_len invalid.\n");
return -EIO;
}
req_data = kzalloc(sizeof(struct ql_vnd_tgt_stats_param), GFP_KERNEL);
if (!req_data) {
ql_log(ql_log_warn, vha, 0x0000, "req_data memory allocation failure.\n");
return -ENOMEM;
}
/* Copy the request buffer in req_data */
sg_copy_to_buffer(bsg_job->request_payload.sg_list,
bsg_job->request_payload.sg_cnt, req_data, req_data_len);
response_len = sizeof(struct ql_vnd_tgt_stats_resp) +
sizeof(struct ql_vnd_stat_entry);
/* structure + size for one entry */
data = kzalloc(response_len, GFP_KERNEL);
if (!data) {
kfree(req_data);
return -ENOMEM;
}
if (response_len > bsg_job->reply_payload.payload_len) {
data->status = EXT_STATUS_BUFFER_TOO_SMALL;
bsg_reply->reply_data.vendor_reply.vendor_rsp[0] = EXT_STATUS_BUFFER_TOO_SMALL;
bsg_job->reply_payload.payload_len = sizeof(struct ql_vnd_mng_host_stats_resp);
bsg_reply->reply_payload_rcv_len = sg_copy_from_buffer(bsg_job->reply_payload.sg_list,
bsg_job->reply_payload.sg_cnt, &data,
sizeof(struct ql_vnd_tgt_stats_resp));
bsg_reply->result = DID_OK;
bsg_job_done(bsg_job, bsg_reply->result,
bsg_reply->reply_payload_rcv_len);
goto tgt_stat_out;
}
rport = qla2xxx_find_rport(vha, req_data->tgt_id);
if (rport == NULL) {
ql_log(ql_log_warn, vha, 0x0000, "target %d not found.\n", req_data->tgt_id);
ret = EXT_STATUS_INVALID_PARAM;
data->status = EXT_STATUS_INVALID_PARAM;
goto reply;
}
ret = qla2xxx_get_tgt_stats(fc_bsg_to_shost(bsg_job), req_data->stat_type,
rport, (void *)data, response_len);
bsg_reply->reply_data.vendor_reply.vendor_rsp[0] = EXT_STATUS_OK;
reply:
bsg_reply->reply_payload_rcv_len = sg_copy_from_buffer(bsg_job->reply_payload.sg_list,
bsg_job->reply_payload.sg_cnt, data,
response_len);
bsg_reply->result = DID_OK;
bsg_job_done(bsg_job, bsg_reply->result,
bsg_reply->reply_payload_rcv_len);
tgt_stat_out:
kfree(data);
kfree(req_data);
return 0;
}
static int
qla2x00_manage_host_port(bsg_job_t *bsg_job)
{
scsi_qla_host_t *vha = shost_priv(fc_bsg_to_shost(bsg_job));
struct fc_bsg_reply *bsg_reply = bsg_job->reply;
struct ql_vnd_mng_host_port_param *req_data;
struct ql_vnd_mng_host_port_resp rsp_data;
uint32_t req_data_len;
int ret = 0;
req_data_len = bsg_job->request_payload.payload_len;
if (req_data_len != sizeof(struct ql_vnd_mng_host_port_param)) {
ql_log(ql_log_warn, vha, 0x0000, "req_data_len invalid.\n");
return -EIO;
}
req_data = kzalloc(sizeof(struct ql_vnd_mng_host_port_param), GFP_KERNEL);
if (!req_data) {
ql_log(ql_log_warn, vha, 0x0000, "req_data memory allocation failure.\n");
return -ENOMEM;
}
/* Copy the request buffer in req_data */
sg_copy_to_buffer(bsg_job->request_payload.sg_list,
bsg_job->request_payload.sg_cnt, req_data, req_data_len);
switch (req_data->action) {
case enable:
ret = qla2xxx_enable_port(vha->host);
break;
case disable:
ret = qla2xxx_disable_port(vha->host);
break;
default:
ql_log(ql_log_warn, vha, 0x0000, "Invalid action.\n");
ret = -EIO;
break;
}
kfree(req_data);
/* Prepare response */
rsp_data.status = ret;
bsg_reply->reply_data.vendor_reply.vendor_rsp[0] = EXT_STATUS_OK;
bsg_job->reply_payload.payload_len = sizeof(struct ql_vnd_mng_host_port_resp);
bsg_reply->reply_payload_rcv_len = sg_copy_from_buffer(bsg_job->reply_payload.sg_list,
bsg_job->reply_payload.sg_cnt, &rsp_data,
sizeof(struct ql_vnd_mng_host_port_resp));
bsg_reply->result = DID_OK;
bsg_job_done(bsg_job, bsg_reply->result,
bsg_reply->reply_payload_rcv_len);
return ret;
}
static int
qla2x00_process_vendor_specific(struct scsi_qla_host *vha, bsg_job_t *bsg_job)
{
struct fc_bsg_request *bsg_request = bsg_job->request;
switch (bsg_request->rqst_data.h_vendor.vendor_cmd[0]) {
case QL_VND_LOOPBACK:
return qla2x00_process_loopback(bsg_job);
case QL_VND_A84_RESET:
return qla84xx_reset(bsg_job);
case QL_VND_A84_UPDATE_FW:
return qla84xx_updatefw(bsg_job);
case QL_VND_A84_MGMT_CMD:
return qla84xx_mgmt_cmd(bsg_job);
case QL_VND_IIDMA:
return qla24xx_iidma(bsg_job);
case QL_VND_FCP_PRIO_CFG_CMD:
return qla24xx_proc_fcp_prio_cfg_cmd(bsg_job);
case QL_VND_READ_FLASH:
return qla2x00_read_optrom(bsg_job);
case QL_VND_UPDATE_FLASH:
return qla2x00_update_optrom(bsg_job);
case QL_VND_SET_FRU_VERSION:
return qla2x00_update_fru_versions(bsg_job);
case QL_VND_READ_FRU_STATUS:
return qla2x00_read_fru_status(bsg_job);
case QL_VND_WRITE_FRU_STATUS:
return qla2x00_write_fru_status(bsg_job);
case QL_VND_WRITE_I2C:
return qla2x00_write_i2c(bsg_job);
case QL_VND_READ_I2C:
return qla2x00_read_i2c(bsg_job);
case QL_VND_DIAG_IO_CMD:
return qla24xx_process_bidir_cmd(bsg_job);
case QL_VND_FX00_MGMT_CMD:
return qlafx00_mgmt_cmd(bsg_job);
case QL_VND_SERDES_OP:
return qla26xx_serdes_op(bsg_job);
case QL_VND_SERDES_OP_EX:
return qla8044_serdes_op(bsg_job);
case QL_VND_GET_FLASH_UPDATE_CAPS:
return qla27xx_get_flash_upd_cap(bsg_job);
case QL_VND_SET_FLASH_UPDATE_CAPS:
return qla27xx_set_flash_upd_cap(bsg_job);
case QL_VND_GET_BBCR_DATA:
return qla27xx_get_bbcr_data(bsg_job);
case QL_VND_GET_PRIV_STATS:
case QL_VND_GET_PRIV_STATS_EX:
return qla2x00_get_priv_stats(bsg_job);
case QL_VND_DPORT_DIAGNOSTICS:
return qla2x00_do_dport_diagnostics(bsg_job);
case QL_VND_DPORT_DIAGNOSTICS_V2:
return qla2x00_do_dport_diagnostics_v2(bsg_job);
case QL_VND_EDIF_MGMT:
return qla_edif_app_mgmt(bsg_job);
case QL_VND_SS_GET_FLASH_IMAGE_STATUS:
return qla2x00_get_flash_image_status(bsg_job);
case QL_VND_GET_PORT_SCM:
return qla2x00_get_port_scm(bsg_job);
case QL_VND_BIDI_SCM_MGMT:
return qla2x00_bidi_scm_mgmt(bsg_job);
case QL_VND_GET_TARGET_SCM:
return qla2x00_get_target_scm(bsg_job);
case QL_VND_GET_PORT_SCM_V2:
return qla2x00_get_port_scm_v2(bsg_job);
case QL_VND_GET_TARGET_SCM_V2:
return qla2x00_get_target_scm_v2(bsg_job);
case QL_VND_GET_DRV_ATTR:
return qla2x00_get_drv_attr(bsg_job);
case QL_VND_MANAGE_HOST_STATS:
return qla2x00_manage_host_stats(bsg_job);
case QL_VND_GET_HOST_STATS:
return qla2x00_get_host_stats(bsg_job);
case QL_VND_GET_TGT_STATS:
return qla2x00_get_tgt_stats(bsg_job);
case QL_VND_MANAGE_HOST_PORT:
return qla2x00_manage_host_port(bsg_job);
case QL_VND_SYSTEM_LOCKDOWN_INFO:
return qla2x00_sys_ld_info(bsg_job);
case QL_VND_MBX_PASSTHRU:
return qla2x00_mailbox_passthru(bsg_job);
default:
return -ENOSYS;
}
}
int
qla24xx_bsg_request(bsg_job_t *bsg_job)
{
struct fc_bsg_request *bsg_request = bsg_job->request;
struct fc_bsg_reply *bsg_reply = bsg_job->reply;
int ret = -EINVAL;
struct fc_rport *rport;
struct Scsi_Host *host;
scsi_qla_host_t *vha;
/* In case no data transferred. */
bsg_reply->reply_payload_rcv_len = 0;
if (bsg_request->msgcode == FC_BSG_RPT_ELS) {
rport = fc_bsg_to_rport(bsg_job);
if (!rport)
return ret;
host = rport_to_shost(rport);
vha = shost_priv(host);
} else {
host = fc_bsg_to_shost(bsg_job);
vha = shost_priv(host);
}
/* Disable port will bring down the chip, allow enable command */
if ((bsg_request->rqst_data.h_vendor.vendor_cmd[0] == QL_VND_MANAGE_HOST_PORT) ||
(bsg_request->rqst_data.h_vendor.vendor_cmd[0] == QL_VND_GET_HOST_STATS))
goto skip_chip_chk;
if ( test_bit(PFLG_DRIVER_REMOVING, &vha->pci_flags)) {
SET_DID_STATUS(bsg_reply->result, DID_ERROR);
return -EIO;
}
if (vha->hw->flags.port_isolated) {
SET_DID_STATUS(bsg_reply->result, DID_ERROR);
/* operation not permitted */
return -EPERM;
}
if (qla2x00_chip_is_down(vha)) {
ql_dbg(ql_dbg_user, vha, 0x709f,
"BSG: ISP abort active/needed -- cmd=%d.\n",
bsg_request->msgcode);
SET_DID_STATUS(bsg_reply->result, DID_ERROR);
return -EBUSY;
}
skip_chip_chk:
ql_dbg(ql_dbg_user + ql_dbg_verbose, vha, 0x7000,
"Entered %s msgcode=0x%x. bsg ptr %px\n",
__func__, bsg_request->msgcode, bsg_job);
switch (bsg_request->msgcode) {
case FC_BSG_RPT_ELS:
case FC_BSG_HST_ELS_NOLOGIN:
ret = qla2x00_process_els(bsg_job);
break;
case FC_BSG_HST_CT:
ret = qla2x00_process_ct(bsg_job);
break;
case FC_BSG_HST_VENDOR:
ret = qla2x00_process_vendor_specific(vha, bsg_job);
break;
case FC_BSG_HST_ADD_RPORT:
case FC_BSG_HST_DEL_RPORT:
case FC_BSG_RPT_CT:
default:
ql_log(ql_log_warn, vha, 0x705a, "Unsupported BSG request.\n");
break;
}
ql_dbg(ql_dbg_user + ql_dbg_verbose, vha, 0x7000,
"%s done with return %x\n", __func__, ret);
return ret;
}
int
qla24xx_bsg_timeout(bsg_job_t *bsg_job)
{
struct fc_bsg_reply *bsg_reply = bsg_job->reply;
scsi_qla_host_t *vha = shost_priv(fc_bsg_to_shost(bsg_job));
struct qla_hw_data *ha = vha->hw;
srb_t *sp;
int cnt, que;
unsigned long flags;
struct req_que *req;
ql_log(ql_log_info, vha, 0x708b, "%s CMD timeout. bsg ptr %px.\n",
__func__, bsg_job);
if (qla2x00_isp_reg_stat(ha)) {
ql_log(ql_log_info, vha, 0x9007,
"PCI/Register disconnect.\n");
qla_pci_set_eeh_busy(vha);
}
/* find the bsg job from the active list of commands */
spin_lock_irqsave(&ha->hardware_lock, flags);
for (que = 0; que < ha->max_req_queues; que++) {
req = ha->req_q_map[que];
if (!req)
continue;
for (cnt = 1; cnt < req->num_outstanding_cmds; cnt++) {
sp = req->outstanding_cmds[cnt];
if (sp && ((sp->type == SRB_CT_CMD) ||
(sp->type == SRB_ELS_CMD_HST) ||
(sp->type == SRB_ELS_CMD_HST_NOLOGIN) ||
(sp->type == SRB_FXIOCB_BCMD))
&& (sp->u.bsg_job == bsg_job)) {
req->outstanding_cmds[cnt] = NULL;
spin_unlock_irqrestore(&ha->hardware_lock, flags);
if (!ha->flags.eeh_busy && ha->isp_ops->abort_command(sp)) {
ql_log(ql_log_warn, vha, 0x7089,
"mbx abort_command "
"failed.\n");
bsg_reply->result = -EIO;
} else {
ql_dbg(ql_dbg_user, vha, 0x708a,
"mbx abort_command "
"success.\n");
bsg_reply->result = 0;
}
spin_lock_irqsave(&ha->hardware_lock, flags);
goto done;
}
}
}
spin_unlock_irqrestore(&ha->hardware_lock, flags);
ql_log(ql_log_info, vha, 0x708b, "SRB not found to abort.\n");
bsg_reply->result = -ENXIO;
return 0;
done:
spin_unlock_irqrestore(&ha->hardware_lock, flags);
/* ref: INIT */
kref_put(&sp->cmd_kref, qla2x00_sp_release);
return 0;
}
int qla2x00_mailbox_passthru(bsg_job_t *bsg_job)
{
struct fc_bsg_reply *bsg_reply = bsg_job->reply;
scsi_qla_host_t *vha = shost_priv(fc_bsg_to_shost(bsg_job));
int ret = -EINVAL;
int ptsize = sizeof(struct qla_mbx_passthru);
struct qla_mbx_passthru *req_data = NULL;
uint32_t req_data_len;
req_data_len = bsg_job->request_payload.payload_len;
if (req_data_len != ptsize) {
ql_log(ql_log_warn, vha, 0xf0a3, "req_data_len invalid.\n");
return -EIO;
}
req_data = kzalloc(ptsize, GFP_KERNEL);
if (!req_data) {
ql_log(ql_log_warn, vha, 0xf0a4, \
"req_data memory allocation failure.\n");
return -ENOMEM;
}
/* Copy the request buffer in req_data */
sg_copy_to_buffer(bsg_job->request_payload.sg_list,
bsg_job->request_payload.sg_cnt, req_data, ptsize);
ret = qla_mailbox_passthru(vha, req_data->mbx_in, req_data->mbx_out);
/* Copy the req_data in request buffer */
sg_copy_from_buffer(bsg_job->reply_payload.sg_list,
bsg_job->reply_payload.sg_cnt, req_data, ptsize);
bsg_reply->reply_payload_rcv_len = ptsize;
if (ret == QLA_SUCCESS)
bsg_reply->reply_data.vendor_reply.vendor_rsp[0] = EXT_STATUS_OK;
else
bsg_reply->reply_data.vendor_reply.vendor_rsp[0] = EXT_STATUS_ERR;
bsg_job->reply_len = sizeof(*bsg_job->reply);
bsg_reply->result = DID_OK << 16;
bsg_job_done(bsg_job, bsg_reply->result, bsg_reply->reply_payload_rcv_len);
kfree(req_data);
return ret;
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化